cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v4.3.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/resources/cache/cache.ts

297lines · 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: 'zone_id',
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 /**
142 * Identifier.
143 */
144 id: string;
145}
146
147export type CachePurgeParams =
148 | CachePurgeParams.CachePurgeFlexPurgeByTags
149 | CachePurgeParams.CachePurgeFlexPurgeByHostnames
150 | CachePurgeParams.CachePurgeFlexPurgeByPrefixes
151 | CachePurgeParams.CachePurgeEverything
152 | CachePurgeParams.CachePurgeSingleFile
153 | CachePurgeParams.CachePurgeSingleFileWithURLAndHeaders;
154
155export declare namespace CachePurgeParams {
156 export interface CachePurgeFlexPurgeByTags {
157 /**
158 * Path param:
159 */
160 zone_id: string;
161
162 /**
163 * Body param: For more information on cache tags and purging by tags, please refer
164 * to
165 * [purge by cache-tags documentation page](https://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-tags/).
166 */
167 tags?: Array<string>;
168 }
169
170 export interface CachePurgeFlexPurgeByHostnames {
171 /**
172 * Path param:
173 */
174 zone_id: string;
175
176 /**
177 * Body param: For more information purging by hostnames, please refer to
178 * [purge by hostname documentation page](https://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-hostname/).
179 */
180 hosts?: Array<string>;
181 }
182
183 export interface CachePurgeFlexPurgeByPrefixes {
184 /**
185 * Path param:
186 */
187 zone_id: string;
188
189 /**
190 * Body param: For more information on purging by prefixes, please refer to
191 * [purge by prefix documentation page](https://developers.cloudflare.com/cache/how-to/purge-cache/purge_by_prefix/).
192 */
193 prefixes?: Array<string>;
194 }
195
196 export interface CachePurgeEverything {
197 /**
198 * Path param:
199 */
200 zone_id: string;
201
202 /**
203 * Body param: For more information, please refer to
204 * [purge everything documentation page](https://developers.cloudflare.com/cache/how-to/purge-cache/purge-everything/).
205 */
206 purge_everything?: boolean;
207 }
208
209 export interface CachePurgeSingleFile {
210 /**
211 * Path param:
212 */
213 zone_id: string;
214
215 /**
216 * Body param: For more information on purging files, please refer to
217 * [purge by single-file documentation page](https://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-single-file/).
218 */
219 files?: Array<string>;
220 }
221
222 export interface CachePurgeSingleFileWithURLAndHeaders {
223 /**
224 * Path param:
225 */
226 zone_id: string;
227
228 /**
229 * Body param: For more information on purging files with URL and headers, please
230 * refer to
231 * [purge by single-file documentation page](https://developers.cloudflare.com/cache/how-to/purge-cache/purge-by-single-file/).
232 */
233 files?: Array<CachePurgeSingleFileWithURLAndHeaders.File>;
234 }
235
236 export namespace CachePurgeSingleFileWithURLAndHeaders {
237 export interface File {
238 headers?: Record<string, string>;
239
240 url?: string;
241 }
242 }
243}
244
245Cache.CacheReserveResource = CacheReserveResource;
246Cache.SmartTieredCache = SmartTieredCache;
247Cache.Variants = Variants;
248Cache.RegionalTieredCacheResource = RegionalTieredCacheResource;
249
250export declare namespace Cache {
251 export { type CachePurgeResponse as CachePurgeResponse, type CachePurgeParams as CachePurgeParams };
252
253 export {
254 CacheReserveResource as CacheReserveResource,
255 type CacheReserve as CacheReserve,
256 type CacheReserveClear as CacheReserveClear,
257 type State as State,
258 type CacheReserveClearResponse as CacheReserveClearResponse,
259 type CacheReserveEditResponse as CacheReserveEditResponse,
260 type CacheReserveGetResponse as CacheReserveGetResponse,
261 type CacheReserveStatusResponse as CacheReserveStatusResponse,
262 type CacheReserveClearParams as CacheReserveClearParams,
263 type CacheReserveEditParams as CacheReserveEditParams,
264 type CacheReserveGetParams as CacheReserveGetParams,
265 type CacheReserveStatusParams as CacheReserveStatusParams,
266 };
267
268 export {
269 SmartTieredCache as SmartTieredCache,
270 type SmartTieredCacheDeleteResponse as SmartTieredCacheDeleteResponse,
271 type SmartTieredCacheEditResponse as SmartTieredCacheEditResponse,
272 type SmartTieredCacheGetResponse as SmartTieredCacheGetResponse,
273 type SmartTieredCacheDeleteParams as SmartTieredCacheDeleteParams,
274 type SmartTieredCacheEditParams as SmartTieredCacheEditParams,
275 type SmartTieredCacheGetParams as SmartTieredCacheGetParams,
276 };
277
278 export {
279 Variants as Variants,
280 type CacheVariant as CacheVariant,
281 type VariantDeleteResponse as VariantDeleteResponse,
282 type VariantEditResponse as VariantEditResponse,
283 type VariantGetResponse as VariantGetResponse,
284 type VariantDeleteParams as VariantDeleteParams,
285 type VariantEditParams as VariantEditParams,
286 type VariantGetParams as VariantGetParams,
287 };
288
289 export {
290 RegionalTieredCacheResource as RegionalTieredCacheResource,
291 type RegionalTieredCache as RegionalTieredCache,
292 type RegionalTieredCacheEditResponse as RegionalTieredCacheEditResponse,
293 type RegionalTieredCacheGetResponse as RegionalTieredCacheGetResponse,
294 type RegionalTieredCacheEditParams as RegionalTieredCacheEditParams,
295 type RegionalTieredCacheGetParams as RegionalTieredCacheGetParams,
296 };
297}
298