cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
src/resources/cache/cache.ts
236lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | import { APIResource } from '../../resource'; |
| 4 | import * as Core from '../../core'; |
| 5 | import * as CacheReserveAPI from './cache-reserve'; |
| 6 | import * as RegionalTieredCacheAPI from './regional-tiered-cache'; |
| 7 | import * as SmartTieredCacheAPI from './smart-tiered-cache'; |
| 8 | import * as VariantsAPI from './variants'; |
| 9 | |
| 10 | export class Cache extends APIResource { |
| 11 | cacheReserve: CacheReserveAPI.CacheReserveResource = new CacheReserveAPI.CacheReserveResource(this._client); |
| 12 | smartTieredCache: SmartTieredCacheAPI.SmartTieredCache = new SmartTieredCacheAPI.SmartTieredCache( |
| 13 | this._client, |
| 14 | ); |
| 15 | variants: VariantsAPI.Variants = new VariantsAPI.Variants(this._client); |
| 16 | regionalTieredCache: RegionalTieredCacheAPI.RegionalTieredCacheResource = |
| 17 | new RegionalTieredCacheAPI.RegionalTieredCacheResource(this._client); |
| 18 | |
| 19 | /** |
| 20 | * ### Purge All Cached Content |
| 21 | * |
| 22 | * Removes ALL files from Cloudflare's cache. All tiers can purge everything. |
| 23 | * |
| 24 | * ``` |
| 25 | * {"purge_everything": true} |
| 26 | * ``` |
| 27 | * |
| 28 | * ### Purge Cached Content by URL |
| 29 | * |
| 30 | * Granularly removes one or more files from Cloudflare's cache by specifying URLs. |
| 31 | * All tiers can purge by URL. |
| 32 | * |
| 33 | * To purge files with custom cache keys, include the headers used to compute the |
| 34 | * cache key as in the example. If you have a device type or geo in your cache key, |
| 35 | * you will need to include the CF-Device-Type or CF-IPCountry headers. If you have |
| 36 | * lang in your cache key, you will need to include the Accept-Language header. |
| 37 | * |
| 38 | * **NB:** When including the Origin header, be sure to include the **scheme** and |
| 39 | * **hostname**. The port number can be omitted if it is the default port (80 for |
| 40 | * http, 443 for https), but must be included otherwise. |
| 41 | * |
| 42 | * **NB:** For Zones on Free/Pro/Business plan, you may purge up to 30 URLs in one |
| 43 | * API call. For Zones on Enterprise plan, you may purge up to 500 URLs in one API |
| 44 | * call. |
| 45 | * |
| 46 | * Single file purge example with files: |
| 47 | * |
| 48 | * ``` |
| 49 | * {"files": ["http://www.example.com/css/styles.css", "http://www.example.com/js/index.js"]} |
| 50 | * ``` |
| 51 | * |
| 52 | * Single file purge example with url and header pairs: |
| 53 | * |
| 54 | * ``` |
| 55 | * {"files": [{url: "http://www.example.com/cat_picture.jpg", headers: { "CF-IPCountry": "US", "CF-Device-Type": "desktop", "Accept-Language": "zh-CN" }}, {url: "http://www.example.com/dog_picture.jpg", headers: { "CF-IPCountry": "EU", "CF-Device-Type": "mobile", "Accept-Language": "en-US" }}]} |
| 56 | * ``` |
| 57 | * |
| 58 | * ### Purge Cached Content by Tag, Host or Prefix |
| 59 | * |
| 60 | * Granularly removes one or more files from Cloudflare's cache either by |
| 61 | * specifying the host, the associated Cache-Tag, or a Prefix. Only Enterprise |
| 62 | * customers are permitted to purge by Tag, Host or Prefix. |
| 63 | * |
| 64 | * **NB:** Cache-Tag, host, and prefix purging each have a rate limit of 30,000 |
| 65 | * purge API calls in every 24 hour period. You may purge up to 30 tags, hosts, or |
| 66 | * prefixes in one API call. This rate limit can be raised for customers who need |
| 67 | * to purge at higher volume. |
| 68 | * |
| 69 | * Flex purge with tags: |
| 70 | * |
| 71 | * ``` |
| 72 | * {"tags": ["a-cache-tag", "another-cache-tag"]} |
| 73 | * ``` |
| 74 | * |
| 75 | * Flex purge with hosts: |
| 76 | * |
| 77 | * ``` |
| 78 | * {"hosts": ["www.example.com", "images.example.com"]} |
| 79 | * ``` |
| 80 | * |
| 81 | * Flex purge with prefixes: |
| 82 | * |
| 83 | * ``` |
| 84 | * {"prefixes": ["www.example.com/foo", "images.example.com/bar/baz"]} |
| 85 | * ``` |
| 86 | */ |
| 87 | purge(params: CachePurgeParams, options?: Core.RequestOptions): Core.APIPromise<CachePurgeResponse | null> { |
| 88 | const { zone_id, ...body } = params; |
| 89 | return ( |
| 90 | this._client.post(`/zones/${zone_id}/purge_cache`, { body, ...options }) as Core.APIPromise<{ |
| 91 | result: CachePurgeResponse | null; |
| 92 | }> |
| 93 | )._thenUnwrap((obj) => obj.result); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | export interface CachePurgeResponse { |
| 98 | /** |
| 99 | * Identifier |
| 100 | */ |
| 101 | id: string; |
| 102 | } |
| 103 | |
| 104 | export type CachePurgeParams = |
| 105 | | CachePurgeParams.CachePurgeFlexPurgeByTags |
| 106 | | CachePurgeParams.CachePurgeFlexPurgeByHostnames |
| 107 | | CachePurgeParams.CachePurgeFlexPurgeByPrefixes |
| 108 | | CachePurgeParams.CachePurgeEverything |
| 109 | | CachePurgeParams.CachePurgeSingleFile |
| 110 | | CachePurgeParams.CachePurgeSingleFileWithURLAndHeaders; |
| 111 | |
| 112 | export namespace CachePurgeParams { |
| 113 | export interface CachePurgeFlexPurgeByTags { |
| 114 | /** |
| 115 | * Path param: |
| 116 | */ |
| 117 | zone_id: string; |
| 118 | |
| 119 | /** |
| 120 | * Body param: For more information on cache tags and purging by tags, please refer |
| 121 | * to |
| 122 | * [purge by cache-tags documentation page](https://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-tags/#purge-cache-by-cache-tags-enterprise-only). |
| 123 | */ |
| 124 | tags?: Array<string>; |
| 125 | } |
| 126 | |
| 127 | export interface CachePurgeFlexPurgeByHostnames { |
| 128 | /** |
| 129 | * Path param: |
| 130 | */ |
| 131 | zone_id: string; |
| 132 | |
| 133 | /** |
| 134 | * Body param: For more information purging by hostnames, please refer to |
| 135 | * [purge by hostname documentation page](https://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-hostname/). |
| 136 | */ |
| 137 | hosts?: Array<string>; |
| 138 | } |
| 139 | |
| 140 | export interface CachePurgeFlexPurgeByPrefixes { |
| 141 | /** |
| 142 | * Path param: |
| 143 | */ |
| 144 | zone_id: string; |
| 145 | |
| 146 | /** |
| 147 | * Body param: For more information on purging by prefixes, please refer to |
| 148 | * [purge by prefix documentation page](https://developers.cloudflare.com/cache/how-to/purge-cache/purge_by_prefix/). |
| 149 | */ |
| 150 | prefixes?: Array<string>; |
| 151 | } |
| 152 | |
| 153 | export interface CachePurgeEverything { |
| 154 | /** |
| 155 | * Path param: |
| 156 | */ |
| 157 | zone_id: string; |
| 158 | |
| 159 | /** |
| 160 | * Body param: For more information, please refer to |
| 161 | * [purge everything documentation page](https://developers.cloudflare.com/cache/how-to/purge-cache/purge-everything/). |
| 162 | */ |
| 163 | purge_everything?: boolean; |
| 164 | } |
| 165 | |
| 166 | export interface CachePurgeSingleFile { |
| 167 | /** |
| 168 | * Path param: |
| 169 | */ |
| 170 | zone_id: string; |
| 171 | |
| 172 | /** |
| 173 | * Body param: For more information on purging files, please refer to |
| 174 | * [purge by single-file documentation page](https://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-single-file/). |
| 175 | */ |
| 176 | files?: Array<string>; |
| 177 | } |
| 178 | |
| 179 | export interface CachePurgeSingleFileWithURLAndHeaders { |
| 180 | /** |
| 181 | * Path param: |
| 182 | */ |
| 183 | zone_id: string; |
| 184 | |
| 185 | /** |
| 186 | * Body param: For more information on purging files with URL and headers, please |
| 187 | * refer to |
| 188 | * [purge by single-file documentation page](https://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-single-file/). |
| 189 | */ |
| 190 | files?: Array<CachePurgeParams.CachePurgeSingleFileWithURLAndHeaders.File>; |
| 191 | } |
| 192 | |
| 193 | export namespace CachePurgeSingleFileWithURLAndHeaders { |
| 194 | export interface File { |
| 195 | headers?: unknown; |
| 196 | |
| 197 | url?: string; |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | export namespace Cache { |
| 203 | export import CacheReserveResource = CacheReserveAPI.CacheReserveResource; |
| 204 | export import CacheReserve = CacheReserveAPI.CacheReserve; |
| 205 | export import CacheReserveClear = CacheReserveAPI.CacheReserveClear; |
| 206 | export import State = CacheReserveAPI.State; |
| 207 | export import CacheReserveClearResponse = CacheReserveAPI.CacheReserveClearResponse; |
| 208 | export import CacheReserveEditResponse = CacheReserveAPI.CacheReserveEditResponse; |
| 209 | export import CacheReserveGetResponse = CacheReserveAPI.CacheReserveGetResponse; |
| 210 | export import CacheReserveStatusResponse = CacheReserveAPI.CacheReserveStatusResponse; |
| 211 | export import CacheReserveClearParams = CacheReserveAPI.CacheReserveClearParams; |
| 212 | export import CacheReserveEditParams = CacheReserveAPI.CacheReserveEditParams; |
| 213 | export import CacheReserveGetParams = CacheReserveAPI.CacheReserveGetParams; |
| 214 | export import CacheReserveStatusParams = CacheReserveAPI.CacheReserveStatusParams; |
| 215 | export import SmartTieredCache = SmartTieredCacheAPI.SmartTieredCache; |
| 216 | export import SmartTieredCacheDeleteResponse = SmartTieredCacheAPI.SmartTieredCacheDeleteResponse; |
| 217 | export import SmartTieredCacheEditResponse = SmartTieredCacheAPI.SmartTieredCacheEditResponse; |
| 218 | export import SmartTieredCacheGetResponse = SmartTieredCacheAPI.SmartTieredCacheGetResponse; |
| 219 | export import SmartTieredCacheDeleteParams = SmartTieredCacheAPI.SmartTieredCacheDeleteParams; |
| 220 | export import SmartTieredCacheEditParams = SmartTieredCacheAPI.SmartTieredCacheEditParams; |
| 221 | export import SmartTieredCacheGetParams = SmartTieredCacheAPI.SmartTieredCacheGetParams; |
| 222 | export import Variants = VariantsAPI.Variants; |
| 223 | export import CacheVariant = VariantsAPI.CacheVariant; |
| 224 | export import CacheVariantIdentifier = VariantsAPI.CacheVariantIdentifier; |
| 225 | export import VariantEditResponse = VariantsAPI.VariantEditResponse; |
| 226 | export import VariantGetResponse = VariantsAPI.VariantGetResponse; |
| 227 | export import VariantDeleteParams = VariantsAPI.VariantDeleteParams; |
| 228 | export import VariantEditParams = VariantsAPI.VariantEditParams; |
| 229 | export import VariantGetParams = VariantsAPI.VariantGetParams; |
| 230 | export import RegionalTieredCacheResource = RegionalTieredCacheAPI.RegionalTieredCacheResource; |
| 231 | export import RegionalTieredCache = RegionalTieredCacheAPI.RegionalTieredCache; |
| 232 | export import RegionalTieredCacheEditResponse = RegionalTieredCacheAPI.RegionalTieredCacheEditResponse; |
| 233 | export import RegionalTieredCacheGetResponse = RegionalTieredCacheAPI.RegionalTieredCacheGetResponse; |
| 234 | export import RegionalTieredCacheEditParams = RegionalTieredCacheAPI.RegionalTieredCacheEditParams; |
| 235 | export import RegionalTieredCacheGetParams = RegionalTieredCacheAPI.RegionalTieredCacheGetParams; |
| 236 | } |