@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.
@@ -289,8 +289,11 @@ export interface ExecutionContext {
289
289
  waitUntil(promise: Promise<any>): void;
290
290
  passThroughOnException(): void;
291
291
  }
292
- export type ExportedHandlerFetchHandler<Env = unknown> = (
293
- request: Request,
292
+ export type ExportedHandlerFetchHandler<
293
+ Env = unknown,
294
+ CfHostMetadata = unknown
295
+ > = (
296
+ request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>,
294
297
  env: Env,
295
298
  ctx: ExecutionContext
296
299
  ) => Response | Promise<Response>;
@@ -314,8 +317,12 @@ export type ExportedHandlerTestHandler<Env = unknown> = (
314
317
  env: Env,
315
318
  ctx: ExecutionContext
316
319
  ) => void | Promise<void>;
317
- export interface ExportedHandler<Env = unknown, QueueMessage = unknown> {
318
- fetch?: ExportedHandlerFetchHandler<Env>;
320
+ export interface ExportedHandler<
321
+ Env = unknown,
322
+ QueueMessage = unknown,
323
+ CfHostMetadata = unknown
324
+ > {
325
+ fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>;
319
326
  trace?: ExportedHandlerTraceHandler<Env>;
320
327
  scheduled?: ExportedHandlerScheduledHandler<Env>;
321
328
  test?: ExportedHandlerTestHandler<Env>;
@@ -354,13 +361,24 @@ export interface DurableObjectNamespace {
354
361
  id: DurableObjectId,
355
362
  options?: DurableObjectNamespaceGetDurableObjectOptions
356
363
  ): DurableObjectStub;
357
- jurisdiction(jurisdiction: string): DurableObjectNamespace;
364
+ jurisdiction(jurisdiction: DurableObjectJurisdiction): DurableObjectNamespace;
358
365
  }
366
+ export type DurableObjectJurisdiction = "eu" | "fedramp";
359
367
  export interface DurableObjectNamespaceNewUniqueIdOptions {
360
- jurisdiction?: string;
361
- }
368
+ jurisdiction?: DurableObjectJurisdiction;
369
+ }
370
+ export type DurableObjectLocationHint =
371
+ | "wnam"
372
+ | "enam"
373
+ | "sam"
374
+ | "weur"
375
+ | "eeur"
376
+ | "apac"
377
+ | "oc"
378
+ | "afr"
379
+ | "me";
362
380
  export interface DurableObjectNamespaceGetDurableObjectOptions {
363
- locationHint?: string;
381
+ locationHint?: DurableObjectLocationHint;
364
382
  }
365
383
  export interface DurableObjectState {
366
384
  waitUntil(promise: Promise<any>): void;
@@ -990,23 +1008,27 @@ export interface ResponseInit {
990
1008
  webSocket?: WebSocket | null;
991
1009
  encodeBody?: "automatic" | "manual";
992
1010
  }
993
- export type RequestInfo = Request | string | URL;
994
- export declare class Request<CfHostMetadata = unknown> extends Body {
995
- constructor(input: RequestInfo, init?: RequestInit);
996
- clone(): Request<CfHostMetadata>;
1011
+ export type RequestInfo<
1012
+ CfHostMetadata = unknown,
1013
+ Cf = CfProperties<CfHostMetadata>
1014
+ > = Request<CfHostMetadata, Cf> | string | URL;
1015
+ export declare class Request<
1016
+ CfHostMetadata = unknown,
1017
+ Cf = CfProperties<CfHostMetadata>
1018
+ > extends Body {
1019
+ constructor(input: RequestInfo<CfProperties>, init?: RequestInit<Cf>);
1020
+ clone(): Request<CfHostMetadata, Cf>;
997
1021
  get method(): string;
998
1022
  get url(): string;
999
1023
  get headers(): Headers;
1000
1024
  get redirect(): string;
1001
1025
  get fetcher(): Fetcher | null;
1002
1026
  get signal(): AbortSignal;
1003
- get cf(): IncomingRequestCfProperties<CfHostMetadata> | undefined;
1027
+ get cf(): Cf | undefined;
1004
1028
  get integrity(): string;
1005
1029
  get keepalive(): boolean;
1006
1030
  }
1007
- export interface RequestInit<
1008
- CfType = IncomingRequestCfProperties | RequestInitCfProperties
1009
- > {
1031
+ export interface RequestInit<Cf = CfProperties> {
1010
1032
  /** A string to set request's method. */
1011
1033
  method?: string;
1012
1034
  /** A Headers object, an object literal, or an array of two-item arrays to set request's headers. */
@@ -1016,17 +1038,14 @@ export interface RequestInit<
1016
1038
  /** 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. */
1017
1039
  redirect?: string;
1018
1040
  fetcher?: Fetcher | null;
1019
- cf?: CfType;
1041
+ cf?: Cf;
1020
1042
  /** A cryptographic hash of the resource to be fetched by request. Sets request's integrity. */
1021
1043
  integrity?: string;
1022
1044
  /** An AbortSignal to set request's signal. */
1023
1045
  signal?: AbortSignal | null;
1024
1046
  }
1025
1047
  export declare abstract class Fetcher {
1026
- fetch(
1027
- input: RequestInfo,
1028
- init?: RequestInit<RequestInitCfProperties>
1029
- ): Promise<Response>;
1048
+ fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
1030
1049
  }
1031
1050
  export interface FetcherPutOptions {
1032
1051
  expiration?: number;
@@ -1289,12 +1308,18 @@ export interface R2HTTPMetadata {
1289
1308
  cacheControl?: string;
1290
1309
  cacheExpiry?: Date;
1291
1310
  }
1292
- export interface R2Objects {
1311
+ export type R2Objects = {
1293
1312
  objects: R2Object[];
1294
- truncated: boolean;
1295
- cursor?: string;
1296
1313
  delimitedPrefixes: string[];
1297
- }
1314
+ } & (
1315
+ | {
1316
+ truncated: true;
1317
+ cursor: string;
1318
+ }
1319
+ | {
1320
+ truncated: false;
1321
+ }
1322
+ );
1298
1323
  export declare abstract class ScheduledEvent extends ExtendableEvent {
1299
1324
  readonly scheduledTime: number;
1300
1325
  readonly cron: string;
@@ -1505,13 +1530,19 @@ export declare class TransformStream<I = any, O = any> {
1505
1530
  get writable(): WritableStream<I>;
1506
1531
  }
1507
1532
  export declare class FixedLengthStream extends IdentityTransformStream {
1508
- constructor(expectedLength: number | bigint);
1533
+ constructor(
1534
+ expectedLength: number | bigint,
1535
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy
1536
+ );
1509
1537
  }
1510
1538
  export declare class IdentityTransformStream extends TransformStream<
1511
1539
  ArrayBuffer | ArrayBufferView,
1512
1540
  Uint8Array
1513
1541
  > {
1514
- constructor();
1542
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
1543
+ }
1544
+ export interface IdentityTransformStreamQueuingStrategy {
1545
+ highWaterMark?: number | bigint;
1515
1546
  }
1516
1547
  export interface ReadableStreamValuesOptions {
1517
1548
  preventCancel?: boolean;
@@ -1867,7 +1898,7 @@ export interface BasicImageTransformationsGravityCoordinates {
1867
1898
  * Note: Currently, these properties cannot be tested in the
1868
1899
  * playground.
1869
1900
  */
1870
- export interface RequestInitCfProperties {
1901
+ export interface RequestInitCfProperties extends Record<string, unknown> {
1871
1902
  cacheEverything?: boolean;
1872
1903
  /**
1873
1904
  * A request's cache key is what determines if two requests are
@@ -2037,6 +2068,49 @@ export interface RequestInitCfPropertiesImage
2037
2068
  * the origin.
2038
2069
  */
2039
2070
  "origin-auth"?: "share-publicly";
2071
+ /**
2072
+ * Adds a border around the image. The border is added after resizing. Border
2073
+ * width takes dpr into account, and can be specified either using a single
2074
+ * width property, or individually for each side.
2075
+ */
2076
+ border?:
2077
+ | {
2078
+ color: string;
2079
+ width: number;
2080
+ }
2081
+ | {
2082
+ color: string;
2083
+ top: number;
2084
+ right: number;
2085
+ bottom: number;
2086
+ left: number;
2087
+ };
2088
+ /**
2089
+ * Increase brightness by a factor. A value of 1.0 equals no change, a value
2090
+ * of 0.5 equals half brightness, and a value of 2.0 equals twice as bright.
2091
+ * 0 is ignored.
2092
+ */
2093
+ brightness?: number;
2094
+ /**
2095
+ * Increase contrast by a factor. A value of 1.0 equals no change, a value of
2096
+ * 0.5 equals low contrast, and a value of 2.0 equals high contrast. 0 is
2097
+ * ignored.
2098
+ */
2099
+ contrast?: number;
2100
+ /**
2101
+ * Increase exposure by a factor. A value of 1.0 equals no change, a value of
2102
+ * 0.5 darkens the image, and a value of 2.0 lightens the image. 0 is ignored.
2103
+ */
2104
+ gamma?: number;
2105
+ /**
2106
+ * Slightly reduces latency on a cache miss by selecting a
2107
+ * quickest-to-compress file format, at a cost of increased file size and
2108
+ * lower image quality. It will usually override the format option and choose
2109
+ * JPEG over WebP or AVIF. We do not recommend using this option, except in
2110
+ * unusual circumstances like resizing uncacheable dynamically-generated
2111
+ * images.
2112
+ */
2113
+ compression?: "fast";
2040
2114
  }
2041
2115
  export interface RequestInitCfPropertiesImageMinify {
2042
2116
  javascript?: boolean;
@@ -2052,7 +2126,8 @@ export type IncomingRequestCfProperties<HostMetadata = unknown> =
2052
2126
  IncomingRequestCfPropertiesCloudflareForSaaSEnterprise<HostMetadata> &
2053
2127
  IncomingRequestCfPropertiesGeographicInformation &
2054
2128
  IncomingRequestCfPropertiesCloudflareAccessOrApiShield;
2055
- export interface IncomingRequestCfPropertiesBase {
2129
+ export interface IncomingRequestCfPropertiesBase
2130
+ extends Record<string, unknown> {
2056
2131
  /**
2057
2132
  * [ASN](https://www.iana.org/assignments/as-numbers/as-numbers.xhtml) of the incoming request.
2058
2133
  *
@@ -2245,86 +2320,82 @@ export interface IncomingRequestCfPropertiesExportedAuthenticatorMetadata {
2245
2320
  /**
2246
2321
  * Geographic data about the request's origin.
2247
2322
  */
2248
- export type IncomingRequestCfPropertiesGeographicInformation =
2249
- | {}
2250
- | {
2251
- /** The country code `"T1"` is used for requests originating on TOR */
2252
- country: "T1";
2253
- }
2254
- | {
2255
- /**
2256
- * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from.
2257
- *
2258
- * 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.
2259
- *
2260
- * If Cloudflare is unable to determine where the request originated this property is omitted.
2261
- *
2262
- * @example "GB"
2263
- */
2264
- country: Iso3166Alpha2Code;
2265
- /**
2266
- * If present, this property indicates that the request originated in the EU
2267
- *
2268
- * @example "1"
2269
- */
2270
- isEUCountry?: "1";
2271
- /**
2272
- * A two-letter code indicating the continent the request originated from.
2273
- *
2274
- * @example "AN"
2275
- */
2276
- continent: ContinentCode;
2277
- /**
2278
- * The city the request originated from
2279
- *
2280
- * @example "Austin"
2281
- */
2282
- city?: string;
2283
- /**
2284
- * Postal code of the incoming request
2285
- *
2286
- * @example "78701"
2287
- */
2288
- postalCode?: string;
2289
- /**
2290
- * Latitude of the incoming request
2291
- *
2292
- * @example "30.27130"
2293
- */
2294
- latitude?: string;
2295
- /**
2296
- * Longitude of the incoming request
2297
- *
2298
- * @example "-97.74260"
2299
- */
2300
- longitude?: string;
2301
- /**
2302
- * Timezone of the incoming request
2303
- *
2304
- * @example "America/Chicago"
2305
- */
2306
- timezone?: string;
2307
- /**
2308
- * If known, the ISO 3166-2 name for the first level region associated with
2309
- * the IP address of the incoming request
2310
- *
2311
- * @example "Texas"
2312
- */
2313
- region?: string;
2314
- /**
2315
- * If known, the ISO 3166-2 code for the first-level region associated with
2316
- * the IP address of the incoming request
2317
- *
2318
- * @example "TX"
2319
- */
2320
- regionCode?: string;
2321
- /**
2322
- * Metro code (DMA) of the incoming request
2323
- *
2324
- * @example "635"
2325
- */
2326
- metroCode?: string;
2327
- };
2323
+ export interface IncomingRequestCfPropertiesGeographicInformation {
2324
+ /**
2325
+ * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from.
2326
+ *
2327
+ * 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.
2328
+ *
2329
+ * If Cloudflare is unable to determine where the request originated this property is omitted.
2330
+ *
2331
+ * The country code `"T1"` is used for requests originating on TOR.
2332
+ *
2333
+ * @example "GB"
2334
+ */
2335
+ country?: Iso3166Alpha2Code | "T1";
2336
+ /**
2337
+ * If present, this property indicates that the request originated in the EU
2338
+ *
2339
+ * @example "1"
2340
+ */
2341
+ isEUCountry?: "1";
2342
+ /**
2343
+ * A two-letter code indicating the continent the request originated from.
2344
+ *
2345
+ * @example "AN"
2346
+ */
2347
+ continent?: ContinentCode;
2348
+ /**
2349
+ * The city the request originated from
2350
+ *
2351
+ * @example "Austin"
2352
+ */
2353
+ city?: string;
2354
+ /**
2355
+ * Postal code of the incoming request
2356
+ *
2357
+ * @example "78701"
2358
+ */
2359
+ postalCode?: string;
2360
+ /**
2361
+ * Latitude of the incoming request
2362
+ *
2363
+ * @example "30.27130"
2364
+ */
2365
+ latitude?: string;
2366
+ /**
2367
+ * Longitude of the incoming request
2368
+ *
2369
+ * @example "-97.74260"
2370
+ */
2371
+ longitude?: string;
2372
+ /**
2373
+ * Timezone of the incoming request
2374
+ *
2375
+ * @example "America/Chicago"
2376
+ */
2377
+ timezone?: string;
2378
+ /**
2379
+ * If known, the ISO 3166-2 name for the first level region associated with
2380
+ * the IP address of the incoming request
2381
+ *
2382
+ * @example "Texas"
2383
+ */
2384
+ region?: string;
2385
+ /**
2386
+ * If known, the ISO 3166-2 code for the first-level region associated with
2387
+ * the IP address of the incoming request
2388
+ *
2389
+ * @example "TX"
2390
+ */
2391
+ regionCode?: string;
2392
+ /**
2393
+ * Metro code (DMA) of the incoming request
2394
+ *
2395
+ * @example "635"
2396
+ */
2397
+ metroCode?: string;
2398
+ }
2328
2399
  /** Data about the incoming request's TLS certificate */
2329
2400
  export interface IncomingRequestCfPropertiesTLSClientAuth {
2330
2401
  /** Always `"1"`, indicating that the certificate was presented */
@@ -2717,6 +2788,9 @@ export type Iso3166Alpha2Code =
2717
2788
  | "ZW";
2718
2789
  /** The 2-letter continent codes Cloudflare uses */
2719
2790
  export type ContinentCode = "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA";
2791
+ export type CfProperties<HostMetadata = unknown> =
2792
+ | IncomingRequestCfProperties<HostMetadata>
2793
+ | RequestInitCfProperties;
2720
2794
  export interface D1Result<T = unknown> {
2721
2795
  results?: T[];
2722
2796
  success: boolean;
@@ -2737,9 +2811,9 @@ export declare abstract class D1PreparedStatement {
2737
2811
  raw<T = unknown>(): Promise<T[]>;
2738
2812
  }
2739
2813
  /**
2740
- * A email message that is sent to a consumer Worker.
2814
+ * An email message that can be sent from a Worker.
2741
2815
  */
2742
- export interface EmailMessage<Body = unknown> {
2816
+ export interface EmailMessage {
2743
2817
  /**
2744
2818
  * Envelope From attribute of the email message.
2745
2819
  */
@@ -2748,14 +2822,19 @@ export interface EmailMessage<Body = unknown> {
2748
2822
  * Envelope To attribute of the email message.
2749
2823
  */
2750
2824
  readonly to: string;
2751
- /**
2752
- * A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2753
- */
2754
- readonly headers: Headers;
2825
+ }
2826
+ /**
2827
+ * An email message that is sent to a consumer Worker and can be rejected/forwarded.
2828
+ */
2829
+ export interface ForwardableEmailMessage extends EmailMessage {
2755
2830
  /**
2756
2831
  * Stream of the email message content.
2757
2832
  */
2758
2833
  readonly raw: ReadableStream;
2834
+ /**
2835
+ * An [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2836
+ */
2837
+ readonly headers: Headers;
2759
2838
  /**
2760
2839
  * Size of the email message content.
2761
2840
  */
@@ -2774,11 +2853,17 @@ export interface EmailMessage<Body = unknown> {
2774
2853
  */
2775
2854
  forward(rcptTo: string, headers?: Headers): Promise<void>;
2776
2855
  }
2856
+ /**
2857
+ * A binding that allows a Worker to send email messages.
2858
+ */
2859
+ export interface SendEmail {
2860
+ send(message: EmailMessage): Promise<void>;
2861
+ }
2777
2862
  export declare abstract class EmailEvent extends ExtendableEvent {
2778
- readonly message: EmailMessage;
2863
+ readonly message: ForwardableEmailMessage;
2779
2864
  }
2780
2865
  export type EmailExportedHandler<Env = unknown> = (
2781
- message: EmailMessage,
2866
+ message: ForwardableEmailMessage,
2782
2867
  env: Env,
2783
2868
  ctx: ExecutionContext
2784
2869
  ) => void | Promise<void>;