cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v6.0.0-beta.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/cache/cache.ts

303lines · modecode

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