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