cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v5.2.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/cache/cache.ts

294lines · 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 CacheVariant,
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 * Single file purge example with files:
84 *
85 * ```
86 * {"files": ["http://www.example.com/css/styles.css", "http://www.example.com/js/index.js"]}
87 * ```
88 *
89 * Single file purge example with url and header pairs:
90 *
91 * ```
92 * {"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" }}]}
93 * ```
94 *
95 * ### Purge Cached Content by Tag, Host or Prefix
96 *
97 * Granularly removes one or more files from Cloudflare's cache either by
98 * specifying the host, the associated Cache-Tag, or a Prefix.
99 *
100 * Flex purge with tags:
101 *
102 * ```
103 * {"tags": ["a-cache-tag", "another-cache-tag"]}
104 * ```
105 *
106 * Flex purge with hosts:
107 *
108 * ```
109 * {"hosts": ["www.example.com", "images.example.com"]}
110 * ```
111 *
112 * Flex purge with prefixes:
113 *
114 * ```
115 * {"prefixes": ["www.example.com/foo", "images.example.com/bar/baz"]}
116 * ```
117 *
118 * ### Availability and limits
119 *
120 * please refer to
121 * [purge cache availability and limits documentation page](https://developers.cloudflare.com/cache/how-to/purge-cache/#availability-and-limits).
122 *
123 * @example
124 * ```ts
125 * const response = await client.cache.purge({
126 * zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
127 * });
128 * ```
129 */
130 purge(params: CachePurgeParams, options?: Core.RequestOptions): Core.APIPromise<CachePurgeResponse | null> {
131 const { zone_id, ...body } = params;
132 return (
133 this._client.post(`/zones/${zone_id}/purge_cache`, { body, ...options }) as Core.APIPromise<{
134 result: CachePurgeResponse | null;
135 }>
136 )._thenUnwrap((obj) => obj.result);
137 }
138}
139
140export interface CachePurgeResponse {
141 id: string;
142}
143
144export type CachePurgeParams =
145 | CachePurgeParams.CachePurgeFlexPurgeByTags
146 | CachePurgeParams.CachePurgeFlexPurgeByHostnames
147 | CachePurgeParams.CachePurgeFlexPurgeByPrefixes
148 | CachePurgeParams.CachePurgeEverything
149 | CachePurgeParams.CachePurgeSingleFile
150 | CachePurgeParams.CachePurgeSingleFileWithURLAndHeaders;
151
152export declare 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/).
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<CachePurgeSingleFileWithURLAndHeaders.File>;
231 }
232
233 export namespace CachePurgeSingleFileWithURLAndHeaders {
234 export interface File {
235 headers?: { [key: string]: string };
236
237 url?: string;
238 }
239 }
240}
241
242Cache.CacheReserveResource = CacheReserveResource;
243Cache.SmartTieredCache = SmartTieredCache;
244Cache.Variants = Variants;
245Cache.RegionalTieredCacheResource = RegionalTieredCacheResource;
246
247export declare namespace Cache {
248 export { type CachePurgeResponse as CachePurgeResponse, type CachePurgeParams as CachePurgeParams };
249
250 export {
251 CacheReserveResource as CacheReserveResource,
252 type CacheReserve as CacheReserve,
253 type CacheReserveClear as CacheReserveClear,
254 type State as State,
255 type CacheReserveClearResponse as CacheReserveClearResponse,
256 type CacheReserveEditResponse as CacheReserveEditResponse,
257 type CacheReserveGetResponse as CacheReserveGetResponse,
258 type CacheReserveStatusResponse as CacheReserveStatusResponse,
259 type CacheReserveClearParams as CacheReserveClearParams,
260 type CacheReserveEditParams as CacheReserveEditParams,
261 type CacheReserveGetParams as CacheReserveGetParams,
262 type CacheReserveStatusParams as CacheReserveStatusParams,
263 };
264
265 export {
266 SmartTieredCache as SmartTieredCache,
267 type SmartTieredCacheDeleteResponse as SmartTieredCacheDeleteResponse,
268 type SmartTieredCacheEditResponse as SmartTieredCacheEditResponse,
269 type SmartTieredCacheGetResponse as SmartTieredCacheGetResponse,
270 type SmartTieredCacheDeleteParams as SmartTieredCacheDeleteParams,
271 type SmartTieredCacheEditParams as SmartTieredCacheEditParams,
272 type SmartTieredCacheGetParams as SmartTieredCacheGetParams,
273 };
274
275 export {
276 Variants as Variants,
277 type CacheVariant as CacheVariant,
278 type VariantDeleteResponse as VariantDeleteResponse,
279 type VariantEditResponse as VariantEditResponse,
280 type VariantGetResponse as VariantGetResponse,
281 type VariantDeleteParams as VariantDeleteParams,
282 type VariantEditParams as VariantEditParams,
283 type VariantGetParams as VariantGetParams,
284 };
285
286 export {
287 RegionalTieredCacheResource as RegionalTieredCacheResource,
288 type RegionalTieredCache as RegionalTieredCache,
289 type RegionalTieredCacheEditResponse as RegionalTieredCacheEditResponse,
290 type RegionalTieredCacheGetResponse as RegionalTieredCacheGetResponse,
291 type RegionalTieredCacheEditParams as RegionalTieredCacheEditParams,
292 type RegionalTieredCacheGetParams as RegionalTieredCacheGetParams,
293 };
294}
295