@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.
@@ -286,8 +286,11 @@ export interface ExecutionContext {
286
286
  waitUntil(promise: Promise<any>): void;
287
287
  passThroughOnException(): void;
288
288
  }
289
- export type ExportedHandlerFetchHandler<Env = unknown> = (
290
- request: Request,
289
+ export type ExportedHandlerFetchHandler<
290
+ Env = unknown,
291
+ CfHostMetadata = unknown
292
+ > = (
293
+ request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>,
291
294
  env: Env,
292
295
  ctx: ExecutionContext
293
296
  ) => Response | Promise<Response>;
@@ -311,8 +314,12 @@ export type ExportedHandlerTestHandler<Env = unknown> = (
311
314
  env: Env,
312
315
  ctx: ExecutionContext
313
316
  ) => void | Promise<void>;
314
- export interface ExportedHandler<Env = unknown, QueueMessage = unknown> {
315
- fetch?: ExportedHandlerFetchHandler<Env>;
317
+ export interface ExportedHandler<
318
+ Env = unknown,
319
+ QueueMessage = unknown,
320
+ CfHostMetadata = unknown
321
+ > {
322
+ fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>;
316
323
  trace?: ExportedHandlerTraceHandler<Env>;
317
324
  scheduled?: ExportedHandlerScheduledHandler<Env>;
318
325
  test?: ExportedHandlerTestHandler<Env>;
@@ -348,13 +355,24 @@ export interface DurableObjectNamespace {
348
355
  id: DurableObjectId,
349
356
  options?: DurableObjectNamespaceGetDurableObjectOptions
350
357
  ): DurableObjectStub;
351
- jurisdiction(jurisdiction: string): DurableObjectNamespace;
358
+ jurisdiction(jurisdiction: DurableObjectJurisdiction): DurableObjectNamespace;
352
359
  }
360
+ export type DurableObjectJurisdiction = "eu" | "fedramp";
353
361
  export interface DurableObjectNamespaceNewUniqueIdOptions {
354
- jurisdiction?: string;
355
- }
362
+ jurisdiction?: DurableObjectJurisdiction;
363
+ }
364
+ export type DurableObjectLocationHint =
365
+ | "wnam"
366
+ | "enam"
367
+ | "sam"
368
+ | "weur"
369
+ | "eeur"
370
+ | "apac"
371
+ | "oc"
372
+ | "afr"
373
+ | "me";
356
374
  export interface DurableObjectNamespaceGetDurableObjectOptions {
357
- locationHint?: string;
375
+ locationHint?: DurableObjectLocationHint;
358
376
  }
359
377
  export interface DurableObjectState {
360
378
  waitUntil(promise: Promise<any>): void;
@@ -997,10 +1015,16 @@ export interface ResponseInit {
997
1015
  webSocket?: WebSocket | null;
998
1016
  encodeBody?: "automatic" | "manual";
999
1017
  }
1000
- export type RequestInfo = Request | string | URL;
1001
- export declare class Request<CfHostMetadata = unknown> extends Body {
1002
- constructor(input: RequestInfo, init?: RequestInit);
1003
- clone(): Request<CfHostMetadata>;
1018
+ export type RequestInfo<
1019
+ CfHostMetadata = unknown,
1020
+ Cf = CfProperties<CfHostMetadata>
1021
+ > = Request<CfHostMetadata, Cf> | string | URL;
1022
+ export declare class Request<
1023
+ CfHostMetadata = unknown,
1024
+ Cf = CfProperties<CfHostMetadata>
1025
+ > extends Body {
1026
+ constructor(input: RequestInfo<CfProperties>, init?: RequestInit<Cf>);
1027
+ clone(): Request<CfHostMetadata, Cf>;
1004
1028
  /** Returns request's HTTP method, which is "GET" by default. */
1005
1029
  readonly method: string;
1006
1030
  /** Returns the URL of request as a string. */
@@ -1012,15 +1036,13 @@ export declare class Request<CfHostMetadata = unknown> extends Body {
1012
1036
  readonly fetcher: Fetcher | null;
1013
1037
  /** Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler. */
1014
1038
  readonly signal: AbortSignal;
1015
- readonly cf?: IncomingRequestCfProperties<CfHostMetadata>;
1039
+ readonly cf?: Cf;
1016
1040
  /** Returns request's subresource integrity metadata, which is a cryptographic hash of the resource being fetched. Its value consists of multiple hashes separated by whitespace. [SRI] */
1017
1041
  readonly integrity: string;
1018
1042
  /** Returns a boolean indicating whether or not request can outlive the global in which it was created. */
1019
1043
  readonly keepalive: boolean;
1020
1044
  }
1021
- export interface RequestInit<
1022
- CfType = IncomingRequestCfProperties | RequestInitCfProperties
1023
- > {
1045
+ export interface RequestInit<Cf = CfProperties> {
1024
1046
  /** A string to set request's method. */
1025
1047
  method?: string;
1026
1048
  /** A Headers object, an object literal, or an array of two-item arrays to set request's headers. */
@@ -1030,17 +1052,14 @@ export interface RequestInit<
1030
1052
  /** 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. */
1031
1053
  redirect?: string;
1032
1054
  fetcher?: Fetcher | null;
1033
- cf?: CfType;
1055
+ cf?: Cf;
1034
1056
  /** A cryptographic hash of the resource to be fetched by request. Sets request's integrity. */
1035
1057
  integrity?: string;
1036
1058
  /** An AbortSignal to set request's signal. */
1037
1059
  signal?: AbortSignal | null;
1038
1060
  }
1039
1061
  export declare abstract class Fetcher {
1040
- fetch(
1041
- input: RequestInfo,
1042
- init?: RequestInit<RequestInitCfProperties>
1043
- ): Promise<Response>;
1062
+ fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
1044
1063
  }
1045
1064
  export interface FetcherPutOptions {
1046
1065
  expiration?: number;
@@ -1303,12 +1322,18 @@ export interface R2HTTPMetadata {
1303
1322
  cacheControl?: string;
1304
1323
  cacheExpiry?: Date;
1305
1324
  }
1306
- export interface R2Objects {
1325
+ export type R2Objects = {
1307
1326
  objects: R2Object[];
1308
- truncated: boolean;
1309
- cursor?: string;
1310
1327
  delimitedPrefixes: string[];
1311
- }
1328
+ } & (
1329
+ | {
1330
+ truncated: true;
1331
+ cursor: string;
1332
+ }
1333
+ | {
1334
+ truncated: false;
1335
+ }
1336
+ );
1312
1337
  export declare abstract class ScheduledEvent extends ExtendableEvent {
1313
1338
  readonly scheduledTime: number;
1314
1339
  readonly cron: string;
@@ -1519,13 +1544,19 @@ export declare class TransformStream<I = any, O = any> {
1519
1544
  readonly writable: WritableStream<I>;
1520
1545
  }
1521
1546
  export declare class FixedLengthStream extends IdentityTransformStream {
1522
- constructor(expectedLength: number | bigint);
1547
+ constructor(
1548
+ expectedLength: number | bigint,
1549
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy
1550
+ );
1523
1551
  }
1524
1552
  export declare class IdentityTransformStream extends TransformStream<
1525
1553
  ArrayBuffer | ArrayBufferView,
1526
1554
  Uint8Array
1527
1555
  > {
1528
- constructor();
1556
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
1557
+ }
1558
+ export interface IdentityTransformStreamQueuingStrategy {
1559
+ highWaterMark?: number | bigint;
1529
1560
  }
1530
1561
  export interface ReadableStreamValuesOptions {
1531
1562
  preventCancel?: boolean;
@@ -1875,7 +1906,7 @@ export interface BasicImageTransformationsGravityCoordinates {
1875
1906
  * Note: Currently, these properties cannot be tested in the
1876
1907
  * playground.
1877
1908
  */
1878
- export interface RequestInitCfProperties {
1909
+ export interface RequestInitCfProperties extends Record<string, unknown> {
1879
1910
  cacheEverything?: boolean;
1880
1911
  /**
1881
1912
  * A request's cache key is what determines if two requests are
@@ -2045,6 +2076,49 @@ export interface RequestInitCfPropertiesImage
2045
2076
  * the origin.
2046
2077
  */
2047
2078
  "origin-auth"?: "share-publicly";
2079
+ /**
2080
+ * Adds a border around the image. The border is added after resizing. Border
2081
+ * width takes dpr into account, and can be specified either using a single
2082
+ * width property, or individually for each side.
2083
+ */
2084
+ border?:
2085
+ | {
2086
+ color: string;
2087
+ width: number;
2088
+ }
2089
+ | {
2090
+ color: string;
2091
+ top: number;
2092
+ right: number;
2093
+ bottom: number;
2094
+ left: number;
2095
+ };
2096
+ /**
2097
+ * Increase brightness by a factor. A value of 1.0 equals no change, a value
2098
+ * of 0.5 equals half brightness, and a value of 2.0 equals twice as bright.
2099
+ * 0 is ignored.
2100
+ */
2101
+ brightness?: number;
2102
+ /**
2103
+ * Increase contrast by a factor. A value of 1.0 equals no change, a value of
2104
+ * 0.5 equals low contrast, and a value of 2.0 equals high contrast. 0 is
2105
+ * ignored.
2106
+ */
2107
+ contrast?: number;
2108
+ /**
2109
+ * Increase exposure by a factor. A value of 1.0 equals no change, a value of
2110
+ * 0.5 darkens the image, and a value of 2.0 lightens the image. 0 is ignored.
2111
+ */
2112
+ gamma?: number;
2113
+ /**
2114
+ * Slightly reduces latency on a cache miss by selecting a
2115
+ * quickest-to-compress file format, at a cost of increased file size and
2116
+ * lower image quality. It will usually override the format option and choose
2117
+ * JPEG over WebP or AVIF. We do not recommend using this option, except in
2118
+ * unusual circumstances like resizing uncacheable dynamically-generated
2119
+ * images.
2120
+ */
2121
+ compression?: "fast";
2048
2122
  }
2049
2123
  export interface RequestInitCfPropertiesImageMinify {
2050
2124
  javascript?: boolean;
@@ -2060,7 +2134,8 @@ export type IncomingRequestCfProperties<HostMetadata = unknown> =
2060
2134
  IncomingRequestCfPropertiesCloudflareForSaaSEnterprise<HostMetadata> &
2061
2135
  IncomingRequestCfPropertiesGeographicInformation &
2062
2136
  IncomingRequestCfPropertiesCloudflareAccessOrApiShield;
2063
- export interface IncomingRequestCfPropertiesBase {
2137
+ export interface IncomingRequestCfPropertiesBase
2138
+ extends Record<string, unknown> {
2064
2139
  /**
2065
2140
  * [ASN](https://www.iana.org/assignments/as-numbers/as-numbers.xhtml) of the incoming request.
2066
2141
  *
@@ -2253,86 +2328,82 @@ export interface IncomingRequestCfPropertiesExportedAuthenticatorMetadata {
2253
2328
  /**
2254
2329
  * Geographic data about the request's origin.
2255
2330
  */
2256
- export type IncomingRequestCfPropertiesGeographicInformation =
2257
- | {}
2258
- | {
2259
- /** The country code `"T1"` is used for requests originating on TOR */
2260
- country: "T1";
2261
- }
2262
- | {
2263
- /**
2264
- * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from.
2265
- *
2266
- * 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.
2267
- *
2268
- * If Cloudflare is unable to determine where the request originated this property is omitted.
2269
- *
2270
- * @example "GB"
2271
- */
2272
- country: Iso3166Alpha2Code;
2273
- /**
2274
- * If present, this property indicates that the request originated in the EU
2275
- *
2276
- * @example "1"
2277
- */
2278
- isEUCountry?: "1";
2279
- /**
2280
- * A two-letter code indicating the continent the request originated from.
2281
- *
2282
- * @example "AN"
2283
- */
2284
- continent: ContinentCode;
2285
- /**
2286
- * The city the request originated from
2287
- *
2288
- * @example "Austin"
2289
- */
2290
- city?: string;
2291
- /**
2292
- * Postal code of the incoming request
2293
- *
2294
- * @example "78701"
2295
- */
2296
- postalCode?: string;
2297
- /**
2298
- * Latitude of the incoming request
2299
- *
2300
- * @example "30.27130"
2301
- */
2302
- latitude?: string;
2303
- /**
2304
- * Longitude of the incoming request
2305
- *
2306
- * @example "-97.74260"
2307
- */
2308
- longitude?: string;
2309
- /**
2310
- * Timezone of the incoming request
2311
- *
2312
- * @example "America/Chicago"
2313
- */
2314
- timezone?: string;
2315
- /**
2316
- * If known, the ISO 3166-2 name for the first level region associated with
2317
- * the IP address of the incoming request
2318
- *
2319
- * @example "Texas"
2320
- */
2321
- region?: string;
2322
- /**
2323
- * If known, the ISO 3166-2 code for the first-level region associated with
2324
- * the IP address of the incoming request
2325
- *
2326
- * @example "TX"
2327
- */
2328
- regionCode?: string;
2329
- /**
2330
- * Metro code (DMA) of the incoming request
2331
- *
2332
- * @example "635"
2333
- */
2334
- metroCode?: string;
2335
- };
2331
+ export interface IncomingRequestCfPropertiesGeographicInformation {
2332
+ /**
2333
+ * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from.
2334
+ *
2335
+ * 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.
2336
+ *
2337
+ * If Cloudflare is unable to determine where the request originated this property is omitted.
2338
+ *
2339
+ * The country code `"T1"` is used for requests originating on TOR.
2340
+ *
2341
+ * @example "GB"
2342
+ */
2343
+ country?: Iso3166Alpha2Code | "T1";
2344
+ /**
2345
+ * If present, this property indicates that the request originated in the EU
2346
+ *
2347
+ * @example "1"
2348
+ */
2349
+ isEUCountry?: "1";
2350
+ /**
2351
+ * A two-letter code indicating the continent the request originated from.
2352
+ *
2353
+ * @example "AN"
2354
+ */
2355
+ continent?: ContinentCode;
2356
+ /**
2357
+ * The city the request originated from
2358
+ *
2359
+ * @example "Austin"
2360
+ */
2361
+ city?: string;
2362
+ /**
2363
+ * Postal code of the incoming request
2364
+ *
2365
+ * @example "78701"
2366
+ */
2367
+ postalCode?: string;
2368
+ /**
2369
+ * Latitude of the incoming request
2370
+ *
2371
+ * @example "30.27130"
2372
+ */
2373
+ latitude?: string;
2374
+ /**
2375
+ * Longitude of the incoming request
2376
+ *
2377
+ * @example "-97.74260"
2378
+ */
2379
+ longitude?: string;
2380
+ /**
2381
+ * Timezone of the incoming request
2382
+ *
2383
+ * @example "America/Chicago"
2384
+ */
2385
+ timezone?: string;
2386
+ /**
2387
+ * If known, the ISO 3166-2 name for the first level region associated with
2388
+ * the IP address of the incoming request
2389
+ *
2390
+ * @example "Texas"
2391
+ */
2392
+ region?: string;
2393
+ /**
2394
+ * If known, the ISO 3166-2 code for the first-level region associated with
2395
+ * the IP address of the incoming request
2396
+ *
2397
+ * @example "TX"
2398
+ */
2399
+ regionCode?: string;
2400
+ /**
2401
+ * Metro code (DMA) of the incoming request
2402
+ *
2403
+ * @example "635"
2404
+ */
2405
+ metroCode?: string;
2406
+ }
2336
2407
  /** Data about the incoming request's TLS certificate */
2337
2408
  export interface IncomingRequestCfPropertiesTLSClientAuth {
2338
2409
  /** Always `"1"`, indicating that the certificate was presented */
@@ -2725,6 +2796,9 @@ export type Iso3166Alpha2Code =
2725
2796
  | "ZW";
2726
2797
  /** The 2-letter continent codes Cloudflare uses */
2727
2798
  export type ContinentCode = "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA";
2799
+ export type CfProperties<HostMetadata = unknown> =
2800
+ | IncomingRequestCfProperties<HostMetadata>
2801
+ | RequestInitCfProperties;
2728
2802
  export interface D1Result<T = unknown> {
2729
2803
  results?: T[];
2730
2804
  success: boolean;
@@ -2745,9 +2819,9 @@ export declare abstract class D1PreparedStatement {
2745
2819
  raw<T = unknown>(): Promise<T[]>;
2746
2820
  }
2747
2821
  /**
2748
- * A email message that is sent to a consumer Worker.
2822
+ * An email message that can be sent from a Worker.
2749
2823
  */
2750
- export interface EmailMessage<Body = unknown> {
2824
+ export interface EmailMessage {
2751
2825
  /**
2752
2826
  * Envelope From attribute of the email message.
2753
2827
  */
@@ -2756,14 +2830,19 @@ export interface EmailMessage<Body = unknown> {
2756
2830
  * Envelope To attribute of the email message.
2757
2831
  */
2758
2832
  readonly to: string;
2759
- /**
2760
- * A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2761
- */
2762
- readonly headers: Headers;
2833
+ }
2834
+ /**
2835
+ * An email message that is sent to a consumer Worker and can be rejected/forwarded.
2836
+ */
2837
+ export interface ForwardableEmailMessage extends EmailMessage {
2763
2838
  /**
2764
2839
  * Stream of the email message content.
2765
2840
  */
2766
2841
  readonly raw: ReadableStream;
2842
+ /**
2843
+ * An [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2844
+ */
2845
+ readonly headers: Headers;
2767
2846
  /**
2768
2847
  * Size of the email message content.
2769
2848
  */
@@ -2782,11 +2861,17 @@ export interface EmailMessage<Body = unknown> {
2782
2861
  */
2783
2862
  forward(rcptTo: string, headers?: Headers): Promise<void>;
2784
2863
  }
2864
+ /**
2865
+ * A binding that allows a Worker to send email messages.
2866
+ */
2867
+ export interface SendEmail {
2868
+ send(message: EmailMessage): Promise<void>;
2869
+ }
2785
2870
  export declare abstract class EmailEvent extends ExtendableEvent {
2786
- readonly message: EmailMessage;
2871
+ readonly message: ForwardableEmailMessage;
2787
2872
  }
2788
2873
  export type EmailExportedHandler<Env = unknown> = (
2789
- message: EmailMessage,
2874
+ message: ForwardableEmailMessage,
2790
2875
  env: Env,
2791
2876
  ctx: ExecutionContext
2792
2877
  ) => void | Promise<void>;