forked from cloudflare/workers-types
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcf.d.ts
377 lines (363 loc) · 12.8 KB
/
cf.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
// TODO: add Response cf object too
declare class Request extends Body {
readonly cf?: IncomingRequestCfProperties;
}
interface RequestInit {
/**
* cf is a union of these two types because there are multiple
* scenarios in which it might be one or the other.
*
* IncomingRequestCfProperties is required to allow
* new Request(someUrl, event.request)
*
* RequestInitCfProperties is required to allow
* new Request(event.request, {cf: { ... } })
* fetch(someUrl, {cf: { ... } })
*/
cf?: IncomingRequestCfProperties | RequestInitCfProperties;
}
interface CfRequestInit extends Omit<RequestInit, "cf"> {
cf?: RequestInitCfProperties;
}
/**
* Back compat support with older types.
* @deprecated Use CfRequestInit instead.
*/
type CfRequestInitializerDict = CfRequestInit;
interface BasicImageTransformations {
/**
* Maximum width in image pixels. The value must be an integer.
*/
width?: number;
/**
* Maximum height in image pixels. The value must be an integer.
*/
height?: number;
/**
* Resizing mode as a string. It affects interpretation of width and height
* options:
* - scale-down: Similar to contain, but the image is never enlarged. If
* the image is larger than given width or height, it will be resized.
* Otherwise its original size will be kept.
* - contain: Resizes to maximum size that fits within the given width and
* height. If only a single dimension is given (e.g. only width), the
* image will be shrunk or enlarged to exactly match that dimension.
* Aspect ratio is always preserved.
* - cover: Resizes (shrinks or enlarges) to fill the entire area of width
* and height. If the image has an aspect ratio different from the ratio
* of width and height, it will be cropped to fit.
* - crop: The image will be shrunk and cropped to fit within the area
* specified by width and height. The image will not be enlarged. For images
* smaller than the given dimensions it's the same as scale-down. For
* images larger than the given dimensions, it's the same as cover.
* See also trim.
* - pad: Resizes to the maximum size that fits within the given width and
* height, and then fills the remaining area with a background color
* (white by default). Use of this mode is not recommended, as the same
* effect can be more efficiently achieved with the contain mode and the
* CSS object-fit: contain property.
*/
fit?: "scale-down" | "contain" | "cover" | "crop" | "pad";
/**
* When cropping with fit: "cover", this defines the side or point that should
* be left uncropped. The value is either a string
* "left", "right", "top", "bottom", "auto", or "center" (the default),
* or an object {x, y} containing focal point coordinates in the original
* image expressed as fractions ranging from 0.0 (top or left) to 1.0
* (bottom or right), 0.5 being the center. {fit: "cover", gravity: "top"} will
* crop bottom or left and right sides as necessary, but won’t crop anything
* from the top. {fit: "cover", gravity: {x:0.5, y:0.2}} will crop each side to
* preserve as much as possible around a point at 20% of the height of the
* source image.
*/
gravity?:
| "left"
| "right"
| "top"
| "bottom"
| "center"
| "auto"
| BasicImageTransformationsGravityCoordinates;
/**
* Background color to add underneath the image. Applies only to images with
* transparency (such as PNG). Accepts any CSS color (#RRGGBB, rgba(…),
* hsl(…), etc.)
*/
background?: string;
/**
* Number of degrees (90, 180, 270) to rotate the image by. width and height
* options refer to axes after rotation.
*/
rotate?: 0 | 90 | 180 | 270 | 360;
}
interface BasicImageTransformationsGravityCoordinates {
x: number;
y: number;
}
/**
* In addition to the properties you can set in the RequestInit dict
* that you pass as an argument to the Request constructor, you can
* set certain properties of a `cf` object to control how Cloudflare
* features are applied to that new Request.
*
* Note: Currently, these properties cannot be tested in the
* playground.
*/
interface RequestInitCfProperties {
cacheEverything?: boolean;
/**
* A request's cache key is what determines if two requests are
* "the same" for caching purposes. If a request has the same cache key
* as some previous request, then we can serve the same cached response for
* both. (e.g. 'some-key')
*
* Only available for Enterprise customers.
*/
cacheKey?: string;
/**
* This allows you to append additional Cache-Tag response headers
* to the origin response without modifications to the origin server.
* This will allow for greater control over the Purge by Cache Tag feature
* utilizing changes only in the Workers process.
*
* Only available for Enterprise customers.
*/
cacheTags?: string[];
/**
* Force response to be cached for a given number of seconds. (e.g. 300)
*/
cacheTtl?: number;
/**
* Force response to be cached for a given number of seconds based on the Origin status code.
* (e.g. { '200-299': 86400, '404': 1, '500-599': 0 })
*/
cacheTtlByStatus?: Record<string, number>;
scrapeShield?: boolean;
apps?: boolean;
image?: RequestInitCfPropertiesImage;
minify?: RequestInitCfPropertiesImageMinify;
mirage?: boolean;
polish?: "lossy" | "lossless" | "off";
/**
* Redirects the request to an alternate origin server. You can use this,
* for example, to implement load balancing across several origins.
* (e.g.us-east.example.com)
*
* Note - For security reasons, the hostname set in resolveOverride must
* be proxied on the same Cloudflare zone of the incoming request.
* Otherwise, the setting is ignored. CNAME hosts are allowed, so to
* resolve to a host under a different domain or a DNS only domain first
* declare a CNAME record within your own zone’s DNS mapping to the
* external hostname, set proxy on Cloudflare, then set resolveOverride
* to point to that CNAME record.
*/
resolveOverride?: string;
}
interface RequestInitCfPropertiesImageDraw extends BasicImageTransformations {
/**
* Absolute URL of the image file to use for the drawing. It can be any of
* the supported file formats. For drawing of watermarks or non-rectangular
* overlays we recommend using PNG or WebP images.
*/
url: string;
/**
* Floating-point number between 0 (transparent) and 1 (opaque).
* For example, opacity: 0.5 makes overlay semitransparent.
*/
opacity?: number;
/**
* - If set to true, the overlay image will be tiled to cover the entire
* area. This is useful for stock-photo-like watermarks.
* - If set to "x", the overlay image will be tiled horizontally only
* (form a line).
* - If set to "y", the overlay image will be tiled vertically only
* (form a line).
*/
repeat?: true | "x" | "y";
/**
* Position of the overlay image relative to a given edge. Each property is
* an offset in pixels. 0 aligns exactly to the edge. For example, left: 10
* positions left side of the overlay 10 pixels from the left edge of the
* image it's drawn over. bottom: 0 aligns bottom of the overlay with bottom
* of the background image.
*
* Setting both left & right, or both top & bottom is an error.
*
* If no position is specified, the image will be centered.
*/
top?: number;
left?: number;
bottom?: number;
right?: number;
}
interface RequestInitCfPropertiesImage extends BasicImageTransformations {
/**
* Device Pixel Ratio. Default 1. Multiplier for width/height that makes it
* easier to specify higher-DPI sizes in <img srcset>.
*/
dpr?: number;
/**
* An object with four properties {left, top, right, bottom} that specify
* a number of pixels to cut off on each side. Allows removal of borders
* or cutting out a specific fragment of an image. Trimming is performed
* before resizing or rotation. Takes dpr into account.
*/
trim?: {
left?: number;
top?: number;
right?: number;
bottom?: number;
};
/**
* Quality setting from 1-100 (useful values are in 60-90 range). Lower values
* make images look worse, but load faster. The default is 85. It applies only
* to JPEG and WebP images. It doesn’t have any effect on PNG.
*/
quality?: number;
/**
* Output format to generate. It can be:
* - avif: generate images in AVIF format.
* - webp: generate images in Google WebP format. Set quality to 100 to get
* the WebP-lossless format.
* - json: instead of generating an image, outputs information about the
* image, in JSON format. The JSON object will contain image size
* (before and after resizing), source image’s MIME type, file size, etc.
*/
format?: "avif" | "webp" | "json";
/**
* Whether to preserve animation frames from input files. Default is true.
* Setting it to false reduces animations to still images. This setting is
* recommended when enlarging images or processing arbitrary user content,
* because large GIF animations can weigh tens or even hundreds of megabytes.
* It is also useful to set anim:false when using format:"json" to get the
* response quicker without the number of frames.
*/
anim?: boolean;
/**
* What EXIF data should be preserved in the output image. Note that EXIF
* rotation and embedded color profiles are always applied ("baked in" into
* the image), and aren't affected by this option. Note that if the Polish
* feature is enabled, all metadata may have been removed already and this
* option may have no effect.
* - keep: Preserve most of EXIF metadata, including GPS location if there's
* any.
* - copyright: Only keep the copyright tag, and discard everything else.
* This is the default behavior for JPEG files.
* - none: Discard all invisible EXIF metadata. Currently WebP and PNG
* output formats always discard metadata.
*/
metadata?: "keep" | "copyright" | "none";
/**
* Strength of sharpening filter to apply to the image. Floating-point
* number between 0 (no sharpening, default) and 10 (maximum). 1.0 is a
* recommended value for downscaled images.
*/
sharpen?: number;
/**
* Radius of a blur filter (approximate gaussian). Maximum supported radius
* is 250.
*/
blur?: number;
/**
* Overlays are drawn in the order they appear in the array (last array
* entry is the topmost layer).
*/
draw?: RequestInitCfPropertiesImageDraw[];
}
interface RequestInitCfPropertiesImageMinify {
javascript?: boolean;
css?: boolean;
html?: boolean;
}
/**
* In addition to the properties on the standard Request object,
* the cf object contains extra information about the request provided
* by Cloudflare's edge.
*
* Note: Currently, settings in the cf object cannot be accessed in the
* playground.
*/
interface IncomingRequestCfProperties {
/**
* (e.g. 395747)
*/
asn: number;
/**
* The organisation which owns the ASN of the incoming request.
* (e.g. Google Cloud)
*/
asOrganization: string;
botManagement?: IncomingRequestCfPropertiesBotManagement;
city?: string;
clientAcceptEncoding?: string;
clientTcpRtt: number;
clientTrustScore?: number;
/**
* The three-letter airport code of the data center that the request
* hit. (e.g. "DFW")
*/
colo: string;
continent?: string;
/**
* The two-letter country code in the request. This is the same value
* as that provided in the CF-IPCountry header. (e.g. "US")
*/
country: string;
httpProtocol: string;
isEUCountry?: string;
latitude?: string;
longitude?: string;
/**
* DMA metro code from which the request was issued, e.g. "635"
*/
metroCode?: string;
postalCode?: string;
/**
* e.g. "Texas"
*/
region?: string;
/**
* e.g. "TX"
*/
regionCode?: string;
/**
* e.g. "weight=256;exclusive=1"
*/
requestPriority: string;
/**
* e.g. "America/Chicago"
*/
timezone?: string;
tlsVersion: string;
tlsCipher: string;
tlsClientAuth: IncomingRequestCfPropertiesTLSClientAuth;
}
interface IncomingRequestCfPropertiesBotManagement {
score: number;
staticResource: boolean;
verifiedBot: boolean;
ja3Hash: string;
corporateProxy: boolean;
}
interface IncomingRequestCfPropertiesTLSClientAuth {
certIssuerDNLegacy: string;
certIssuerDN: string;
certIssuerDNRFC2253: string;
certIssuerSKI: string;
certIssuerSerial: string;
certPresented: "0" | "1";
certSubjectDNLegacy: string;
certSubjectDN: string;
certSubjectDNRFC2253: string;
/** In format "Dec 22 19:39:00 2018 GMT" */
certNotBefore: string;
/** In format "Dec 22 19:39:00 2018 GMT" */
certNotAfter: string;
certSerial: string;
certFingerprintSHA1: string;
/** "SUCCESS", "FAILED:reason", "NONE" */
certVerified: string;
certRevoked: string;
certSKI: string;
}
export {};