@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;
@@ -995,10 +1013,16 @@ declare interface ResponseInit {
995
1013
  webSocket?: WebSocket | null;
996
1014
  encodeBody?: "automatic" | "manual";
997
1015
  }
998
- declare type RequestInfo = Request | string | URL;
999
- declare class Request<CfHostMetadata = unknown> extends Body {
1000
- constructor(input: RequestInfo, init?: RequestInit);
1001
- clone(): Request<CfHostMetadata>;
1016
+ declare type RequestInfo<
1017
+ CfHostMetadata = unknown,
1018
+ Cf = CfProperties<CfHostMetadata>
1019
+ > = Request<CfHostMetadata, Cf> | string | URL;
1020
+ declare class Request<
1021
+ CfHostMetadata = unknown,
1022
+ Cf = CfProperties<CfHostMetadata>
1023
+ > extends Body {
1024
+ constructor(input: RequestInfo<CfProperties>, init?: RequestInit<Cf>);
1025
+ clone(): Request<CfHostMetadata, Cf>;
1002
1026
  /** Returns request's HTTP method, which is "GET" by default. */
1003
1027
  readonly method: string;
1004
1028
  /** Returns the URL of request as a string. */
@@ -1010,15 +1034,13 @@ declare class Request<CfHostMetadata = unknown> extends Body {
1010
1034
  readonly fetcher: Fetcher | null;
1011
1035
  /** Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler. */
1012
1036
  readonly signal: AbortSignal;
1013
- readonly cf?: IncomingRequestCfProperties<CfHostMetadata>;
1037
+ readonly cf?: Cf;
1014
1038
  /** 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] */
1015
1039
  readonly integrity: string;
1016
1040
  /** Returns a boolean indicating whether or not request can outlive the global in which it was created. */
1017
1041
  readonly keepalive: boolean;
1018
1042
  }
1019
- declare interface RequestInit<
1020
- CfType = IncomingRequestCfProperties | RequestInitCfProperties
1021
- > {
1043
+ declare interface RequestInit<Cf = CfProperties> {
1022
1044
  /** A string to set request's method. */
1023
1045
  method?: string;
1024
1046
  /** A Headers object, an object literal, or an array of two-item arrays to set request's headers. */
@@ -1028,17 +1050,14 @@ declare interface RequestInit<
1028
1050
  /** 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. */
1029
1051
  redirect?: string;
1030
1052
  fetcher?: Fetcher | null;
1031
- cf?: CfType;
1053
+ cf?: Cf;
1032
1054
  /** A cryptographic hash of the resource to be fetched by request. Sets request's integrity. */
1033
1055
  integrity?: string;
1034
1056
  /** An AbortSignal to set request's signal. */
1035
1057
  signal?: AbortSignal | null;
1036
1058
  }
1037
1059
  declare abstract class Fetcher {
1038
- fetch(
1039
- input: RequestInfo,
1040
- init?: RequestInit<RequestInitCfProperties>
1041
- ): Promise<Response>;
1060
+ fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
1042
1061
  }
1043
1062
  declare interface FetcherPutOptions {
1044
1063
  expiration?: number;
@@ -1301,12 +1320,18 @@ declare interface R2HTTPMetadata {
1301
1320
  cacheControl?: string;
1302
1321
  cacheExpiry?: Date;
1303
1322
  }
1304
- declare interface R2Objects {
1323
+ declare type R2Objects = {
1305
1324
  objects: R2Object[];
1306
- truncated: boolean;
1307
- cursor?: string;
1308
1325
  delimitedPrefixes: string[];
1309
- }
1326
+ } & (
1327
+ | {
1328
+ truncated: true;
1329
+ cursor: string;
1330
+ }
1331
+ | {
1332
+ truncated: false;
1333
+ }
1334
+ );
1310
1335
  declare abstract class ScheduledEvent extends ExtendableEvent {
1311
1336
  readonly scheduledTime: number;
1312
1337
  readonly cron: string;
@@ -1517,13 +1542,19 @@ declare class TransformStream<I = any, O = any> {
1517
1542
  readonly writable: WritableStream<I>;
1518
1543
  }
1519
1544
  declare class FixedLengthStream extends IdentityTransformStream {
1520
- constructor(expectedLength: number | bigint);
1545
+ constructor(
1546
+ expectedLength: number | bigint,
1547
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy
1548
+ );
1521
1549
  }
1522
1550
  declare class IdentityTransformStream extends TransformStream<
1523
1551
  ArrayBuffer | ArrayBufferView,
1524
1552
  Uint8Array
1525
1553
  > {
1526
- constructor();
1554
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
1555
+ }
1556
+ declare interface IdentityTransformStreamQueuingStrategy {
1557
+ highWaterMark?: number | bigint;
1527
1558
  }
1528
1559
  declare interface ReadableStreamValuesOptions {
1529
1560
  preventCancel?: boolean;
@@ -1870,7 +1901,7 @@ declare interface BasicImageTransformationsGravityCoordinates {
1870
1901
  * Note: Currently, these properties cannot be tested in the
1871
1902
  * playground.
1872
1903
  */
1873
- declare interface RequestInitCfProperties {
1904
+ declare interface RequestInitCfProperties extends Record<string, unknown> {
1874
1905
  cacheEverything?: boolean;
1875
1906
  /**
1876
1907
  * A request's cache key is what determines if two requests are
@@ -2040,6 +2071,49 @@ declare interface RequestInitCfPropertiesImage
2040
2071
  * the origin.
2041
2072
  */
2042
2073
  "origin-auth"?: "share-publicly";
2074
+ /**
2075
+ * Adds a border around the image. The border is added after resizing. Border
2076
+ * width takes dpr into account, and can be specified either using a single
2077
+ * width property, or individually for each side.
2078
+ */
2079
+ border?:
2080
+ | {
2081
+ color: string;
2082
+ width: number;
2083
+ }
2084
+ | {
2085
+ color: string;
2086
+ top: number;
2087
+ right: number;
2088
+ bottom: number;
2089
+ left: number;
2090
+ };
2091
+ /**
2092
+ * Increase brightness by a factor. A value of 1.0 equals no change, a value
2093
+ * of 0.5 equals half brightness, and a value of 2.0 equals twice as bright.
2094
+ * 0 is ignored.
2095
+ */
2096
+ brightness?: number;
2097
+ /**
2098
+ * Increase contrast by a factor. A value of 1.0 equals no change, a value of
2099
+ * 0.5 equals low contrast, and a value of 2.0 equals high contrast. 0 is
2100
+ * ignored.
2101
+ */
2102
+ contrast?: number;
2103
+ /**
2104
+ * Increase exposure by a factor. A value of 1.0 equals no change, a value of
2105
+ * 0.5 darkens the image, and a value of 2.0 lightens the image. 0 is ignored.
2106
+ */
2107
+ gamma?: number;
2108
+ /**
2109
+ * Slightly reduces latency on a cache miss by selecting a
2110
+ * quickest-to-compress file format, at a cost of increased file size and
2111
+ * lower image quality. It will usually override the format option and choose
2112
+ * JPEG over WebP or AVIF. We do not recommend using this option, except in
2113
+ * unusual circumstances like resizing uncacheable dynamically-generated
2114
+ * images.
2115
+ */
2116
+ compression?: "fast";
2043
2117
  }
2044
2118
  declare interface RequestInitCfPropertiesImageMinify {
2045
2119
  javascript?: boolean;
@@ -2055,7 +2129,8 @@ declare type IncomingRequestCfProperties<HostMetadata = unknown> =
2055
2129
  IncomingRequestCfPropertiesCloudflareForSaaSEnterprise<HostMetadata> &
2056
2130
  IncomingRequestCfPropertiesGeographicInformation &
2057
2131
  IncomingRequestCfPropertiesCloudflareAccessOrApiShield;
2058
- declare interface IncomingRequestCfPropertiesBase {
2132
+ declare interface IncomingRequestCfPropertiesBase
2133
+ extends Record<string, unknown> {
2059
2134
  /**
2060
2135
  * [ASN](https://www.iana.org/assignments/as-numbers/as-numbers.xhtml) of the incoming request.
2061
2136
  *
@@ -2248,86 +2323,82 @@ declare interface IncomingRequestCfPropertiesExportedAuthenticatorMetadata {
2248
2323
  /**
2249
2324
  * Geographic data about the request's origin.
2250
2325
  */
2251
- declare type IncomingRequestCfPropertiesGeographicInformation =
2252
- | {}
2253
- | {
2254
- /** The country code `"T1"` is used for requests originating on TOR */
2255
- country: "T1";
2256
- }
2257
- | {
2258
- /**
2259
- * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from.
2260
- *
2261
- * 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.
2262
- *
2263
- * If Cloudflare is unable to determine where the request originated this property is omitted.
2264
- *
2265
- * @example "GB"
2266
- */
2267
- country: Iso3166Alpha2Code;
2268
- /**
2269
- * If present, this property indicates that the request originated in the EU
2270
- *
2271
- * @example "1"
2272
- */
2273
- isEUCountry?: "1";
2274
- /**
2275
- * A two-letter code indicating the continent the request originated from.
2276
- *
2277
- * @example "AN"
2278
- */
2279
- continent: ContinentCode;
2280
- /**
2281
- * The city the request originated from
2282
- *
2283
- * @example "Austin"
2284
- */
2285
- city?: string;
2286
- /**
2287
- * Postal code of the incoming request
2288
- *
2289
- * @example "78701"
2290
- */
2291
- postalCode?: string;
2292
- /**
2293
- * Latitude of the incoming request
2294
- *
2295
- * @example "30.27130"
2296
- */
2297
- latitude?: string;
2298
- /**
2299
- * Longitude of the incoming request
2300
- *
2301
- * @example "-97.74260"
2302
- */
2303
- longitude?: string;
2304
- /**
2305
- * Timezone of the incoming request
2306
- *
2307
- * @example "America/Chicago"
2308
- */
2309
- timezone?: string;
2310
- /**
2311
- * If known, the ISO 3166-2 name for the first level region associated with
2312
- * the IP address of the incoming request
2313
- *
2314
- * @example "Texas"
2315
- */
2316
- region?: string;
2317
- /**
2318
- * If known, the ISO 3166-2 code for the first-level region associated with
2319
- * the IP address of the incoming request
2320
- *
2321
- * @example "TX"
2322
- */
2323
- regionCode?: string;
2324
- /**
2325
- * Metro code (DMA) of the incoming request
2326
- *
2327
- * @example "635"
2328
- */
2329
- metroCode?: string;
2330
- };
2326
+ declare interface IncomingRequestCfPropertiesGeographicInformation {
2327
+ /**
2328
+ * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from.
2329
+ *
2330
+ * 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.
2331
+ *
2332
+ * If Cloudflare is unable to determine where the request originated this property is omitted.
2333
+ *
2334
+ * The country code `"T1"` is used for requests originating on TOR.
2335
+ *
2336
+ * @example "GB"
2337
+ */
2338
+ country?: Iso3166Alpha2Code | "T1";
2339
+ /**
2340
+ * If present, this property indicates that the request originated in the EU
2341
+ *
2342
+ * @example "1"
2343
+ */
2344
+ isEUCountry?: "1";
2345
+ /**
2346
+ * A two-letter code indicating the continent the request originated from.
2347
+ *
2348
+ * @example "AN"
2349
+ */
2350
+ continent?: ContinentCode;
2351
+ /**
2352
+ * The city the request originated from
2353
+ *
2354
+ * @example "Austin"
2355
+ */
2356
+ city?: string;
2357
+ /**
2358
+ * Postal code of the incoming request
2359
+ *
2360
+ * @example "78701"
2361
+ */
2362
+ postalCode?: string;
2363
+ /**
2364
+ * Latitude of the incoming request
2365
+ *
2366
+ * @example "30.27130"
2367
+ */
2368
+ latitude?: string;
2369
+ /**
2370
+ * Longitude of the incoming request
2371
+ *
2372
+ * @example "-97.74260"
2373
+ */
2374
+ longitude?: string;
2375
+ /**
2376
+ * Timezone of the incoming request
2377
+ *
2378
+ * @example "America/Chicago"
2379
+ */
2380
+ timezone?: string;
2381
+ /**
2382
+ * If known, the ISO 3166-2 name for the first level region associated with
2383
+ * the IP address of the incoming request
2384
+ *
2385
+ * @example "Texas"
2386
+ */
2387
+ region?: string;
2388
+ /**
2389
+ * If known, the ISO 3166-2 code for the first-level region associated with
2390
+ * the IP address of the incoming request
2391
+ *
2392
+ * @example "TX"
2393
+ */
2394
+ regionCode?: string;
2395
+ /**
2396
+ * Metro code (DMA) of the incoming request
2397
+ *
2398
+ * @example "635"
2399
+ */
2400
+ metroCode?: string;
2401
+ }
2331
2402
  /** Data about the incoming request's TLS certificate */
2332
2403
  declare interface IncomingRequestCfPropertiesTLSClientAuth {
2333
2404
  /** Always `"1"`, indicating that the certificate was presented */
@@ -2720,6 +2791,9 @@ declare type Iso3166Alpha2Code =
2720
2791
  | "ZW";
2721
2792
  /** The 2-letter continent codes Cloudflare uses */
2722
2793
  declare type ContinentCode = "AF" | "AN" | "AS" | "EU" | "NA" | "OC" | "SA";
2794
+ declare type CfProperties<HostMetadata = unknown> =
2795
+ | IncomingRequestCfProperties<HostMetadata>
2796
+ | RequestInitCfProperties;
2723
2797
  declare interface D1Result<T = unknown> {
2724
2798
  results?: T[];
2725
2799
  success: boolean;
@@ -2740,9 +2814,9 @@ declare abstract class D1PreparedStatement {
2740
2814
  raw<T = unknown>(): Promise<T[]>;
2741
2815
  }
2742
2816
  /**
2743
- * A email message that is sent to a consumer Worker.
2817
+ * An email message that can be sent from a Worker.
2744
2818
  */
2745
- declare interface EmailMessage<Body = unknown> {
2819
+ declare interface EmailMessage {
2746
2820
  /**
2747
2821
  * Envelope From attribute of the email message.
2748
2822
  */
@@ -2751,14 +2825,19 @@ declare interface EmailMessage<Body = unknown> {
2751
2825
  * Envelope To attribute of the email message.
2752
2826
  */
2753
2827
  readonly to: string;
2754
- /**
2755
- * A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2756
- */
2757
- readonly headers: Headers;
2828
+ }
2829
+ /**
2830
+ * An email message that is sent to a consumer Worker and can be rejected/forwarded.
2831
+ */
2832
+ declare interface ForwardableEmailMessage extends EmailMessage {
2758
2833
  /**
2759
2834
  * Stream of the email message content.
2760
2835
  */
2761
2836
  readonly raw: ReadableStream;
2837
+ /**
2838
+ * An [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers).
2839
+ */
2840
+ readonly headers: Headers;
2762
2841
  /**
2763
2842
  * Size of the email message content.
2764
2843
  */
@@ -2777,14 +2856,27 @@ declare interface EmailMessage<Body = unknown> {
2777
2856
  */
2778
2857
  forward(rcptTo: string, headers?: Headers): Promise<void>;
2779
2858
  }
2859
+ /**
2860
+ * A binding that allows a Worker to send email messages.
2861
+ */
2862
+ declare interface SendEmail {
2863
+ send(message: EmailMessage): Promise<void>;
2864
+ }
2780
2865
  declare abstract class EmailEvent extends ExtendableEvent {
2781
- readonly message: EmailMessage;
2866
+ readonly message: ForwardableEmailMessage;
2782
2867
  }
2783
2868
  declare type EmailExportedHandler<Env = unknown> = (
2784
- message: EmailMessage,
2869
+ message: ForwardableEmailMessage,
2785
2870
  env: Env,
2786
2871
  ctx: ExecutionContext
2787
2872
  ) => void | Promise<void>;
2873
+ declare module "cloudflare:email" {
2874
+ let _EmailMessage: {
2875
+ prototype: EmailMessage;
2876
+ new (from: string, to: string, raw: ReadableStream | string): EmailMessage;
2877
+ };
2878
+ export { _EmailMessage as EmailMessage };
2879
+ }
2788
2880
  declare type Params<P extends string = any> = Record<P, string | string[]>;
2789
2881
  declare type EventContext<Env, P extends string, Data> = {
2790
2882
  request: Request;