@cloudflare/workers-types 4.20230307.0 → 4.20230404.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -284,8 +284,11 @@ declare interface ExecutionContext {
284
284
  waitUntil(promise: Promise<any>): void;
285
285
  passThroughOnException(): void;
286
286
  }
287
- declare type ExportedHandlerFetchHandler<Env = unknown> = (
288
- request: Request,
287
+ declare type ExportedHandlerFetchHandler<
288
+ Env = unknown,
289
+ CfHostMetadata = unknown
290
+ > = (
291
+ request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>,
289
292
  env: Env,
290
293
  ctx: ExecutionContext
291
294
  ) => Response | Promise<Response>;
@@ -309,8 +312,12 @@ declare type ExportedHandlerTestHandler<Env = unknown> = (
309
312
  env: Env,
310
313
  ctx: ExecutionContext
311
314
  ) => void | Promise<void>;
312
- declare interface ExportedHandler<Env = unknown, QueueMessage = unknown> {
313
- fetch?: ExportedHandlerFetchHandler<Env>;
315
+ declare interface ExportedHandler<
316
+ Env = unknown,
317
+ QueueMessage = unknown,
318
+ CfHostMetadata = unknown
319
+ > {
320
+ fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>;
314
321
  trace?: ExportedHandlerTraceHandler<Env>;
315
322
  scheduled?: ExportedHandlerScheduledHandler<Env>;
316
323
  test?: ExportedHandlerTestHandler<Env>;
@@ -346,13 +353,24 @@ declare interface DurableObjectNamespace {
346
353
  id: DurableObjectId,
347
354
  options?: DurableObjectNamespaceGetDurableObjectOptions
348
355
  ): DurableObjectStub;
349
- jurisdiction(jurisdiction: string): DurableObjectNamespace;
356
+ jurisdiction(jurisdiction: DurableObjectJurisdiction): DurableObjectNamespace;
350
357
  }
358
+ declare type DurableObjectJurisdiction = "eu" | "fedramp";
351
359
  declare interface DurableObjectNamespaceNewUniqueIdOptions {
352
- jurisdiction?: string;
353
- }
360
+ jurisdiction?: DurableObjectJurisdiction;
361
+ }
362
+ declare type DurableObjectLocationHint =
363
+ | "wnam"
364
+ | "enam"
365
+ | "sam"
366
+ | "weur"
367
+ | "eeur"
368
+ | "apac"
369
+ | "oc"
370
+ | "afr"
371
+ | "me";
354
372
  declare interface DurableObjectNamespaceGetDurableObjectOptions {
355
- locationHint?: string;
373
+ locationHint?: DurableObjectLocationHint;
356
374
  }
357
375
  declare interface DurableObjectState {
358
376
  waitUntil(promise: Promise<any>): void;
@@ -982,23 +1000,27 @@ declare interface ResponseInit {
982
1000
  webSocket?: WebSocket | null;
983
1001
  encodeBody?: "automatic" | "manual";
984
1002
  }
985
- declare type RequestInfo = Request | string | URL;
986
- declare class Request<CfHostMetadata = unknown> extends Body {
987
- constructor(input: RequestInfo, init?: RequestInit);
988
- clone(): Request<CfHostMetadata>;
1003
+ declare type RequestInfo<
1004
+ CfHostMetadata = unknown,
1005
+ Cf = CfProperties<CfHostMetadata>
1006
+ > = Request<CfHostMetadata, Cf> | string | URL;
1007
+ declare class Request<
1008
+ CfHostMetadata = unknown,
1009
+ Cf = CfProperties<CfHostMetadata>
1010
+ > extends Body {
1011
+ constructor(input: RequestInfo<CfProperties>, init?: RequestInit<Cf>);
1012
+ clone(): Request<CfHostMetadata, Cf>;
989
1013
  get method(): string;
990
1014
  get url(): string;
991
1015
  get headers(): Headers;
992
1016
  get redirect(): string;
993
1017
  get fetcher(): Fetcher | null;
994
1018
  get signal(): AbortSignal;
995
- get cf(): IncomingRequestCfProperties<CfHostMetadata> | undefined;
1019
+ get cf(): Cf | undefined;
996
1020
  get integrity(): string;
997
1021
  get keepalive(): boolean;
998
1022
  }
999
- declare interface RequestInit<
1000
- CfType = IncomingRequestCfProperties | RequestInitCfProperties
1001
- > {
1023
+ declare interface RequestInit<Cf = CfProperties> {
1002
1024
  /** A string to set request's method. */
1003
1025
  method?: string;
1004
1026
  /** A Headers object, an object literal, or an array of two-item arrays to set request's headers. */
@@ -1008,17 +1030,14 @@ declare interface RequestInit<
1008
1030
  /** A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect. */
1009
1031
  redirect?: string;
1010
1032
  fetcher?: Fetcher | null;
1011
- cf?: CfType;
1033
+ cf?: Cf;
1012
1034
  /** A cryptographic hash of the resource to be fetched by request. Sets request's integrity. */
1013
1035
  integrity?: string;
1014
1036
  /** An AbortSignal to set request's signal. */
1015
1037
  signal?: AbortSignal | null;
1016
1038
  }
1017
1039
  declare abstract class Fetcher {
1018
- fetch(
1019
- input: RequestInfo,
1020
- init?: RequestInit<RequestInitCfProperties>
1021
- ): Promise<Response>;
1040
+ fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
1022
1041
  }
1023
1042
  declare interface FetcherPutOptions {
1024
1043
  expiration?: number;
@@ -1281,12 +1300,18 @@ declare interface R2HTTPMetadata {
1281
1300
  cacheControl?: string;
1282
1301
  cacheExpiry?: Date;
1283
1302
  }
1284
- declare interface R2Objects {
1303
+ declare type R2Objects = {
1285
1304
  objects: R2Object[];
1286
- truncated: boolean;
1287
- cursor?: string;
1288
1305
  delimitedPrefixes: string[];
1289
- }
1306
+ } & (
1307
+ | {
1308
+ truncated: true;
1309
+ cursor: string;
1310
+ }
1311
+ | {
1312
+ truncated: false;
1313
+ }
1314
+ );
1290
1315
  declare abstract class ScheduledEvent extends ExtendableEvent {
1291
1316
  readonly scheduledTime: number;
1292
1317
  readonly cron: string;
@@ -1497,13 +1522,19 @@ declare class TransformStream<I = any, O = any> {
1497
1522
  get writable(): WritableStream<I>;
1498
1523
  }
1499
1524
  declare class FixedLengthStream extends IdentityTransformStream {
1500
- constructor(expectedLength: number | bigint);
1525
+ constructor(
1526
+ expectedLength: number | bigint,
1527
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy
1528
+ );
1501
1529
  }
1502
1530
  declare class IdentityTransformStream extends TransformStream<
1503
1531
  ArrayBuffer | ArrayBufferView,
1504
1532
  Uint8Array
1505
1533
  > {
1506
- constructor();
1534
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
1535
+ }
1536
+ declare interface IdentityTransformStreamQueuingStrategy {
1537
+ highWaterMark?: number | bigint;
1507
1538
  }
1508
1539
  declare interface ReadableStreamValuesOptions {
1509
1540
  preventCancel?: boolean;
@@ -1856,7 +1887,7 @@ declare interface BasicImageTransformationsGravityCoordinates {
1856
1887
  * Note: Currently, these properties cannot be tested in the
1857
1888
  * playground.
1858
1889
  */
1859
- declare interface RequestInitCfProperties {
1890
+ declare interface RequestInitCfProperties extends Record<string, unknown> {
1860
1891
  cacheEverything?: boolean;
1861
1892
  /**
1862
1893
  * A request's cache key is what determines if two requests are
@@ -2026,6 +2057,49 @@ declare interface RequestInitCfPropertiesImage
2026
2057
  * the origin.
2027
2058
  */
2028
2059
  "origin-auth"?: "share-publicly";
2060
+ /**
2061
+ * Adds a border around the image. The border is added after resizing. Border
2062
+ * width takes dpr into account, and can be specified either using a single
2063
+ * width property, or individually for each side.
2064
+ */
2065
+ border?:
2066
+ | {
2067
+ color: string;
2068
+ width: number;
2069
+ }
2070
+ | {
2071
+ color: string;
2072
+ top: number;
2073
+ right: number;
2074
+ bottom: number;
2075
+ left: number;
2076
+ };
2077
+ /**
2078
+ * Increase brightness by a factor. A value of 1.0 equals no change, a value
2079
+ * of 0.5 equals half brightness, and a value of 2.0 equals twice as bright.
2080
+ * 0 is ignored.
2081
+ */
2082
+ brightness?: number;
2083
+ /**
2084
+ * Increase contrast by a factor. A value of 1.0 equals no change, a value of
2085
+ * 0.5 equals low contrast, and a value of 2.0 equals high contrast. 0 is
2086
+ * ignored.
2087
+ */
2088
+ contrast?: number;
2089
+ /**
2090
+ * Increase exposure by a factor. A value of 1.0 equals no change, a value of
2091
+ * 0.5 darkens the image, and a value of 2.0 lightens the image. 0 is ignored.
2092
+ */
2093
+ gamma?: number;
2094
+ /**
2095
+ * Slightly reduces latency on a cache miss by selecting a
2096
+ * quickest-to-compress file format, at a cost of increased file size and
2097
+ * lower image quality. It will usually override the format option and choose
2098
+ * JPEG over WebP or AVIF. We do not recommend using this option, except in
2099
+ * unusual circumstances like resizing uncacheable dynamically-generated
2100
+ * images.
2101
+ */
2102
+ compression?: "fast";
2029
2103
  }
2030
2104
  declare interface RequestInitCfPropertiesImageMinify {
2031
2105
  javascript?: boolean;
@@ -2041,7 +2115,8 @@ declare type IncomingRequestCfProperties<HostMetadata = unknown> =
2041
2115
  IncomingRequestCfPropertiesCloudflareForSaaSEnterprise<HostMetadata> &
2042
2116
  IncomingRequestCfPropertiesGeographicInformation &
2043
2117
  IncomingRequestCfPropertiesCloudflareAccessOrApiShield;
2044
- declare interface IncomingRequestCfPropertiesBase {
2118
+ declare interface IncomingRequestCfPropertiesBase
2119
+ extends Record<string, unknown> {
2045
2120
  /**
2046
2121
  * [ASN](https://www.iana.org/assignments/as-numbers/as-numbers.xhtml) of the incoming request.
2047
2122
  *
@@ -2234,86 +2309,82 @@ declare interface IncomingRequestCfPropertiesExportedAuthenticatorMetadata {
2234
2309
  /**
2235
2310
  * Geographic data about the request's origin.
2236
2311
  */
2237
- declare type IncomingRequestCfPropertiesGeographicInformation =
2238
- | {}
2239
- | {
2240
- /** The country code `"T1"` is used for requests originating on TOR */
2241
- country: "T1";
2242
- }
2243
- | {
2244
- /**
2245
- * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from.
2246
- *
2247
- * If your worker is [configured to accept TOR connections](https://support.cloudflare.com/hc/en-us/articles/203306930-Understanding-Cloudflare-Tor-support-and-Onion-Routing), this may also be `"T1"`, indicating a request that originated over TOR.
2248
- *
2249
- * If Cloudflare is unable to determine where the request originated this property is omitted.
2250
- *
2251
- * @example "GB"
2252
- */
2253
- country: Iso3166Alpha2Code;
2254
- /**
2255
- * If present, this property indicates that the request originated in the EU
2256
- *
2257
- * @example "1"
2258
- */
2259
- isEUCountry?: "1";
2260
- /**
2261
- * A two-letter code indicating the continent the request originated from.
2262
- *
2263
- * @example "AN"
2264
- */
2265
- continent: ContinentCode;
2266
- /**
2267
- * The city the request originated from
2268
- *
2269
- * @example "Austin"
2270
- */
2271
- city?: string;
2272
- /**
2273
- * Postal code of the incoming request
2274
- *
2275
- * @example "78701"
2276
- */
2277
- postalCode?: string;
2278
- /**
2279
- * Latitude of the incoming request
2280
- *
2281
- * @example "30.27130"
2282
- */
2283
- latitude?: string;
2284
- /**
2285
- * Longitude of the incoming request
2286
- *
2287
- * @example "-97.74260"
2288
- */
2289
- longitude?: string;
2290
- /**
2291
- * Timezone of the incoming request
2292
- *
2293
- * @example "America/Chicago"
2294
- */
2295
- timezone?: string;
2296
- /**
2297
- * If known, the ISO 3166-2 name for the first level region associated with
2298
- * the IP address of the incoming request
2299
- *
2300
- * @example "Texas"
2301
- */
2302
- region?: string;
2303
- /**
2304
- * If known, the ISO 3166-2 code for the first-level region associated with
2305
- * the IP address of the incoming request
2306
- *
2307
- * @example "TX"
2308
- */
2309
- regionCode?: string;
2310
- /**
2311
- * Metro code (DMA) of the incoming request
2312
- *
2313
- * @example "635"
2314
- */
2315
- metroCode?: string;
2316
- };
2312
+ declare interface IncomingRequestCfPropertiesGeographicInformation {
2313
+ /**
2314
+ * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from.
2315
+ *
2316
+ * If your worker is [configured to accept TOR connections](https://support.cloudflare.com/hc/en-us/articles/203306930-Understanding-Cloudflare-Tor-support-and-Onion-Routing), this may also be `"T1"`, indicating a request that originated over TOR.
2317
+ *
2318
+ * If Cloudflare is unable to determine where the request originated this property is omitted.
2319
+ *
2320
+ * The country code `"T1"` is used for requests originating on TOR.
2321
+ *
2322
+ * @example "GB"
2323
+ */
2324
+ country?: Iso3166Alpha2Code | "T1";
2325
+ /**
2326
+ * If present, this property indicates that the request originated in the EU
2327
+ *
2328
+ * @example "1"
2329
+ */
2330
+ isEUCountry?: "1";
2331
+ /**
2332
+ * A two-letter code indicating the continent the request originated from.
2333
+ *
2334
+ * @example "AN"
2335
+ */
2336
+ continent?: ContinentCode;
2337
+ /**
2338
+ * The city the request originated from
2339
+ *
2340
+ * @example "Austin"
2341
+ */
2342
+ city?: string;
2343
+ /**
2344
+ * Postal code of the incoming request
2345
+ *
2346
+ * @example "78701"
2347
+ */
2348
+ postalCode?: string;
2349
+ /**
2350
+ * Latitude of the incoming request
2351
+ *
2352
+ * @example "30.27130"
2353
+ */
2354
+ latitude?: string;
2355
+ /**
2356
+ * Longitude of the incoming request
2357
+ *
2358
+ * @example "-97.74260"
2359
+ */
2360
+ longitude?: string;
2361
+ /**
2362
+ * Timezone of the incoming request
2363
+ *
2364
+ * @example "America/Chicago"
2365
+ */
2366
+ timezone?: string;
2367
+ /**
2368
+ * If known, the ISO 3166-2 name for the first level region associated with
2369
+ * the IP address of the incoming request
2370
+ *
2371
+ * @example "Texas"
2372
+ */
2373
+ region?: string;
2374
+ /**
2375
+ * If known, the ISO 3166-2 code for the first-level region associated with
2376
+ * the IP address of the incoming request
2377
+ *
2378
+ * @example "TX"
2379
+ */
2380
+ regionCode?: string;
2381
+ /**
2382
+ * Metro code (DMA) of the incoming request
2383
+ *
2384
+ * @example "635"
2385
+ */
2386
+ metroCode?: string;
2387
+ }
2317
2388
  /** Data about the incoming request's TLS certificate */
2318
2389
  declare interface IncomingRequestCfPropertiesTLSClientAuth {
2319
2390
  /** Always `"1"`, indicating that the certificate was presented */
@@ -2706,6 +2777,9 @@ declare type Iso3166Alpha2Code =
2706
2777
  | "ZW";
2707
2778
  /** The 2-letter continent codes Cloudflare uses */
2708
2779
  declare type ContinentCode = "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA";
2780
+ declare type CfProperties<HostMetadata = unknown> =
2781
+ | IncomingRequestCfProperties<HostMetadata>
2782
+ | RequestInitCfProperties;
2709
2783
  declare interface D1Result<T = unknown> {
2710
2784
  results?: T[];
2711
2785
  success: boolean;
@@ -2726,9 +2800,9 @@ declare abstract class D1PreparedStatement {
2726
2800
  raw<T = unknown>(): Promise<T[]>;
2727
2801
  }
2728
2802
  /**
2729
- * A email message that is sent to a consumer Worker.
2803
+ * An email message that can be sent from a Worker.
2730
2804
  */
2731
- declare interface EmailMessage<Body = unknown> {
2805
+ declare interface EmailMessage {
2732
2806
  /**
2733
2807
  * Envelope From attribute of the email message.
2734
2808
  */
@@ -2737,14 +2811,19 @@ declare interface EmailMessage<Body = unknown> {
2737
2811
  * Envelope To attribute of the email message.
2738
2812
  */
2739
2813
  readonly to: string;
2740
- /**
2741
- * A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2742
- */
2743
- readonly headers: Headers;
2814
+ }
2815
+ /**
2816
+ * An email message that is sent to a consumer Worker and can be rejected/forwarded.
2817
+ */
2818
+ declare interface ForwardableEmailMessage extends EmailMessage {
2744
2819
  /**
2745
2820
  * Stream of the email message content.
2746
2821
  */
2747
2822
  readonly raw: ReadableStream;
2823
+ /**
2824
+ * An [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2825
+ */
2826
+ readonly headers: Headers;
2748
2827
  /**
2749
2828
  * Size of the email message content.
2750
2829
  */
@@ -2763,14 +2842,27 @@ declare interface EmailMessage<Body = unknown> {
2763
2842
  */
2764
2843
  forward(rcptTo: string, headers?: Headers): Promise<void>;
2765
2844
  }
2845
+ /**
2846
+ * A binding that allows a Worker to send email messages.
2847
+ */
2848
+ declare interface SendEmail {
2849
+ send(message: EmailMessage): Promise<void>;
2850
+ }
2766
2851
  declare abstract class EmailEvent extends ExtendableEvent {
2767
- readonly message: EmailMessage;
2852
+ readonly message: ForwardableEmailMessage;
2768
2853
  }
2769
2854
  declare type EmailExportedHandler<Env = unknown> = (
2770
- message: EmailMessage,
2855
+ message: ForwardableEmailMessage,
2771
2856
  env: Env,
2772
2857
  ctx: ExecutionContext
2773
2858
  ) => void | Promise<void>;
2859
+ declare module "cloudflare:email" {
2860
+ let _EmailMessage: {
2861
+ prototype: EmailMessage;
2862
+ new (from: string, to: string, raw: ReadableStream | string): EmailMessage;
2863
+ };
2864
+ export { _EmailMessage as EmailMessage };
2865
+ }
2774
2866
  declare type Params<P extends string = any> = Record<P, string | string[]>;
2775
2867
  declare type EventContext<Env, P extends string, Data> = {
2776
2868
  request: Request;