cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
ff1339ab00fd4a5bd6993cd10aa0eabc11ae7da7

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/resources/cache/cache.ts

293lines · modecode

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