-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathglobals.d.ts
2187 lines (2002 loc) · 72 KB
/
globals.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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @group Web APIs
*/
declare var self: typeof globalThis;
/**
* @group DOM Events
*/
interface EventMap {
fetch: FetchEvent;
}
/**
* @group DOM Events
*/
interface EventListenerMap {
fetch: FetchEventListener;
}
/**
* @group DOM Events
*/
interface FetchEventListener {
(this: typeof globalThis, event: FetchEvent): any;
}
/**
* @group DOM Events
*/
declare var onfetch: FetchEventListener;
/**
* This is a fetch specific implementation of [addEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener), and is very similar to [handling FetchEvent from a Service Worker](https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/request).
*
* For Fastly Compute, this will be the entrypoint in handling your downstream request from your client.
* @group DOM Events
*/
declare function addEventListener<K extends keyof EventMap>(
type: K,
listener: EventListenerMap[K],
): void;
/**
* @deprecated This has moved to {@link "fastly:backend".BackendConfiguration} - This global variable will be removed in the next major version.
* @hidden
*/
declare interface BackendConfiguration {
/**
* The name of the backend.
* @deprecated to avoid name collisions it is recommended to use auto-generated names by omitting this property.
*/
name?: string;
/**
* A hostname, IPv4, or IPv6 address for the backend as well as an optional port.
* E.G. "hostname", "ip address", "hostname:port", or "ip address:port"
*/
target: string;
/**
* If set, will force the HTTP Host header on connections to this backend to be the supplied value.
*/
hostOverride?: string;
/**
* Maximum duration in milliseconds to wait for a connection to this backend to be established.
* If exceeded, the connection is aborted and a 503 response will be presented instead.
* Defaults to 1,000 milliseconds.
*/
connectTimeout?: number;
/**
* Maximum duration in milliseconds to wait for the server response to begin after a TCP connection is established and the request has been sent.
* If exceeded, the connection is aborted and a 503 response will be presented instead.
* Defaults to 15,000 milliseconds.
*/
firstByteTimeout?: number;
/**
* Maximum duration in milliseconds that Fastly will wait while receiving no data on a download from a backend.
* If exceeded, the response received so far will be considered complete and the fetch will end.
* Defaults to 10,000 milliseconds.
*/
betweenBytesTimeout?: number;
/**
* Whether or not to require TLS for connections to this backend.
*/
useSSL?: boolean;
/**
* Minimum allowed TLS version on SSL connections to this backend.
* If the backend server is not able to negotiate a connection meeting this constraint, a 503 response will be presented instead.
*/
tlsMinVersion?: number;
/**
* Maximum allowed TLS version on SSL connections to this backend.
* If the backend server is not able to negotiate a connection meeting this constraint, a 503 response will be presented instead.
*/
tlsMaxVersion?: number;
/**
* Define the hostname that the server certificate should declare.
*/
certificateHostname?: string;
/**
* The CA certificate to use when checking the validity of the backend.
*/
caCertificate?: string;
/**
* List of OpenSSL ciphers to support for connections to this origin.
* If the backend server is not able to negotiate a connection meeting this constraint, a 503 response will be presented instead.
*/
ciphers?: string;
/**
* The SNI hostname to use on connections to this backend.
*/
sniHostname?: string;
/**
* @experimental
*
* When enabled, sets that this backend is to be used for gRPC traffic.
*
* Warning: When using this experimental feature, no guarantees are provided for behaviours for
* backends that do not provide gRPC traffic.
*/
grpc?: boolean;
/**
* Set the client certificate to be provided to the server during the initial TLS handshake.
*
* @throws {TypeError} Throws a TypeError if the value is not an object of the correct type.
*/
clientCertificate?: {
certificate: string;
key: import('fastly:secret-store').SecretStoreEntry;
};
/**
* Enables and sets the HTTP keepalive time in milliseconds for the backend.
*/
httpKeepalive?: number;
/**
* Enables and sets the TCP keep alive options for the backend.
* Setting to boolean true enables keepalive with the default options.
*/
tcpKeepalive?:
| boolean
| {
/**
* Configure how long to wait after the last sent data over the TCP connection before
* starting to send TCP keepalive probes.
*/
timeSecs?: number;
/**
* Configure how long to wait between each TCP keepalive probe sent to the backend to determine if it is still active.
*/
intervalSecs?: number;
/**
* Number of probes to send to the backend before it is considered dead.
*/
probes?: number;
};
}
/**
* Class for creating new [Fastly Backends](https://developer.fastly.com/reference/api/services/backend/).
*
* **Note**: Can only be used when processing requests, not during build-time initialization.
* @deprecated This has moved to {@link "fastly:backend".Backend} - This global variable will be removed in the next major version.
@hidden
*/
declare class Backend {
/**
* Creates a new Backend instance
*
* @example
* Construct a new backend with all properties set to their default values:
* ```js
* const myBackend = new Backend({ name: 'fastly', target: 'www.fastly.com'});
* ```
*/
constructor(configuration: BackendConfiguration);
/**
* The name of the backend
*/
readonly name: string;
/**
* Whether this backend was dynamically created by the running service.
*/
readonly isDynamic: boolean;
/**
* The host target for the backend
*/
readonly target: string;
/**
* The host header override defined for the backend.
*
* See https://docs.fastly.com/en/guides/specifying-an-override-host for more information.
*/
readonly hostOverride: string;
/**
* The backend port
*/
readonly port: number;
/**
* The connect timeout for the backend in milliseconds, if available.
*/
readonly connectTimeout: number | null;
/**
* The first byte timeout for the backend in milliseconds, if available.
*/
readonly firstByteTimeout: number | null;
/**
* The between bytes timeout for the backend in milliseconds, if available.
*/
readonly betweenBytesTimeout: number | null;
/**
* The HTTP keepalive time for the backend in milliseconds.
*/
readonly httpKeepaliveTime: number;
/**
* The TCP keepalive configuration, if TCP keepalive is enabled.
*/
readonly tcpKeepalive: null | {
/**
* The keepalive time in seconds.
*/
timeSecs: number;
/**
* The interval in seconds between probes.
*/
intervalSecs: number;
/**
* The number of probes to send before terminating the keepalive.
*/
probes: number;
};
/**
* Whether the backend is configured to use SSL.
*/
readonly isSSL: boolean;
/**
* The minimum SSL version number this backend will use, if available.
*/
readonly tlsMinVersion: 1 | 1.1 | 1.2 | 1.3 | null;
/**
* The maximum SSL version number this backend will use, if available.
*/
readonly tlsMaxversion: 1 | 1.1 | 1.2 | 1.3 | null;
/**
* Get the health of this backend.
*/
health(): 'healthy' | 'unhealthy' | 'unknown';
/**
* Returns the name associated with the Backend instance.
* @deprecated Use `backend.name` instead.
*/
toName(): string;
/**
* Returns the name associated with the Backend instance.
*
* @deprecated Use `backend.name` instead.
*/
toString(): string;
/**
* Returns a boolean indicating if a Backend with the given name exists or not.
*/
static exists(name: string): boolean;
/**
* Returns the Backend instance with the given name, if one exists. If one does not exist, an error is thrown.
*/
static fromName(name: string): Backend;
/**
* Returns a string representing the health of the given Backend instance.
* Possible values are:
*
* "healthy" - The backend's health check has succeeded, indicating the backend is working as expected and should receive requests.
* "unhealthy" - The backend's health check has failed, indicating the backend is not working as expected and should not receive requests.
* "unknown" - The backend does not have a health check configured.
*
* @deprecated Use `backend.health()` ({@link Backend.prototype.health}) instead.
*/
static health(backend: Backend): 'healthy' | 'unhealthy' | 'unknown';
}
/**
* A Fastly Compute specific implementation of [FetchEvent](https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/FetchEvent).
* @group DOM Events
*/
declare interface FetchEvent {
/**
* Information about the downstream client that made the request
*/
readonly client: ClientInfo;
/**
* Information about the server which received the request.
*/
readonly server: ServerInfo;
/**
* The downstream request that came from the client
*/
readonly request: Request;
/**
* Send a response back to the client.
*
* **Note**: The service will be kept alive until the response has been fully sent.
*
* If the response contains a streaming body created by the service itself, then the service
* will be kept alive until the body {@link ReadableStream} has been closed or errored.
*
* However, if the body is a stream originating in a request to a backend, i.e. if a backend
* response's {@link Response.body} is passed as input to the {@link Response} constructor, the
* service will not be kept alive until sending the body has finished.
*
* **Note**: If `response` is a `Promise`, the service will be kept alive until the
* response has been resolved or rejected, and the {@link Response} it resolved to has been
* fully sent.
*
* **Note**: Use {@link FetchEvent.waitUntil} to extend the service's lifetime further if
* necessary.
*
* @param response - Response to send back down to the client
*/
respondWith(response: Response | PromiseLike<Response>): void;
/**
* Extend the service's lifetime to ensure asynchronous operations succeed.
*
* By default, a service will shut down as soon as the response passed to
* {@link FetchEvent.respondWith | respondWith} has been sent. `waitUntil` can be used to
* ensure that the service will stay alive until additional asynchronous operations have
* completed, such as sending telemetry data to a separate backend after the response has
* been sent.
*
* @param promise - The `Promise` to wait for
*/
waitUntil(promise: Promise<any>): void;
}
/**
* Set the cache override mode on a request
*
* None
* Do not override the behavior specified in the origin response’s cache control headers.
* Pass
* Do not cache the response to this request, regardless of the origin response’s headers.
* Override
* Override particular cache control settings using a {@linkcode CacheOverride} object.
*
* The origin response’s cache control headers will be used for ttl and stale_while_revalidate if None.
*
* @deprecated This has moved to {@link "fastly:cache-override".CacheOverrideMode} - This global type will be removed in the next major version.
* @hidden
*/
declare type CacheOverrideMode = 'none' | 'pass' | 'override';
/**
* Base class for Cache Override, which is used to configure caching behavior.
* @deprecated This has moved to {@link "fastly:cache-override".CacheOverrideInit} - This global interface will be removed in the next major version.
* @hidden
*/
declare interface CacheOverrideInit {
/**
* Override the caching behavior of this request to use the given Time to Live (TTL), in seconds.
*/
ttl?: number;
/**
* Override the caching behavior of this request to use the given `stale-while-revalidate` time,
* in seconds
*/
swr?: number;
/**
* Override the caching behavior of this request to include the given surrogate key, provided as
* a header value.
*
* See the [Fastly surrogate keys guide](https://docs.fastly.com/en/guides/purging-api-cache-with-surrogate-keys)
* for details.
*/
surrogateKey?: string;
/**
* Override the caching behavior of this request to enable or disable PCI/HIPAA-compliant
* non-volatile caching.
*
* By default, this is false, which means the request may not be PCI/HIPAA-compliant. Set it to
* true to enable compliant caching.
*
* See the [Fastly PCI-Compliant Caching and Delivery documentation](https://docs.fastly.com/products/pci-compliant-caching-and-delivery)
* for details.
*/
pci?: boolean;
}
/**
* Configures the caching behavior of a {@linkcode Response}.
*
* Normally, the HTTP Headers on a Response would control how the Response is cached,
* but CacheOverride can be set on a {@linkcode Request}, to define custom caching behavior.
*
* @deprecated This has moved to {@link "fastly:cache-override".CacheOverride} - This global interface will be removed in the next major version.
* @hidden
*/
declare interface CacheOverride extends CacheOverrideInit {
mode: CacheOverrideMode;
}
/**
* @deprecated This has moved to {@link "fastly:cache-override".CacheOverride} - This global variable will be removed in the next major version.
* @hidden
*/
declare var CacheOverride: {
prototype: CacheOverride;
new (mode: CacheOverrideMode, init?: CacheOverrideInit): CacheOverride;
};
/**
* Information about the downstream client making the request to the Fastly Compute service.
*/
declare interface ClientInfo {
/**
* A string representation of the IPv4 or IPv6 address of the downstream client.
*
* While always defined on Fastly compute, on environments where these fields are unavailable,
* such as Viceroy, these fields may return *null*.
*/
readonly address: string;
readonly geo: import('fastly:geolocation').Geolocation | null;
readonly tlsJA3MD5: string | null;
readonly tlsCipherOpensslName: string | null;
readonly tlsProtocol: string | null;
readonly tlsClientCertificate: ArrayBuffer | null;
readonly tlsClientHello: ArrayBuffer | null;
}
/**
* Information about the server receiving the request for the Fastly Compute service.
*/
declare interface ServerInfo {
/**
* A string representation of the IPv4 or IPv6 address of the server which received the request.
*/
readonly address: string;
}
/**
* Class for accessing [Fastly Edge Dictionaries](https://docs.fastly.com/en/guides/about-edge-dictionaries).
*
* **Note**: Can only be used when processing requests, not during build-time initialization.
*
* @deprecated This has moved to {@link "fastly:config-store".ConfigStore} - This global class will be removed in the next major version.
* @hidden
*/
declare class ConfigStore {
/**
* Creates a new ConfigStore object
*/
constructor(name: string);
/**
* Get a value for a key in the config-store.
*/
get(key: string): string;
}
/**
* Class for accessing [Fastly Edge Dictionaries](https://docs.fastly.com/en/guides/about-edge-dictionaries).
*
* **Note**: Can only be used when processing requests, not during build-time initialization.
* @deprecated This has moved to {@link "fastly:dictionary".Dictionary} - This global class will be removed in the next major version.
* @hidden
*/
declare class Dictionary {
/**
* Creates a new Dictionary object, and opens an edge dictionary to query
*/
constructor(name: string);
/**
* Get a value for a key in the dictionary
*/
get(key: string): string;
}
/**
* [Fastly Geolocation](https://developer.fastly.com/reference/vcl/variables/geolocation/)
* information about an IP address
*
* Can be retrieved for the incoming request's client IP address using the
* {@linkcode ClientInfo#geo} accessor, and for arbitrary addresses using
* {@linkcode Fastly.getGeolocationForIpAddress}.
* @deprecated This has moved to {@link "fastly:geolocation".Geolocation} - This global interface will be removed in the next major version.
* @hidden
*/
declare interface Geolocation {
/**
* The name of the organization associated with as_number.
*
* For example, fastly is the value given for IP addresses under AS-54113.
*/
as_name: string | null;
/**
* [Autonomous system](https://en.wikipedia.org/wiki/Autonomous_system_(Internet)) (AS) number.
*/
as_number: number | null;
/**
* The telephone area code associated with an IP address.
*
* These are only available for IP addresses in the United States, its territories, and Canada.
*/
area_code: number | null;
/**
* City or town name.
*/
city: string | null;
/**
* Connection speed.
*/
conn_speed: string | null;
/**
* Connection type.
*/
conn_type: string | null;
/**
* Continent.
*/
continent: string | null;
/**
* A two-character [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) country code for the country associated with an IP address.
*
* The US country code is returned for IP addresses associated with overseas United States military bases.
*
* These values include subdivisions that are assigned their own country codes in ISO 3166-1. For example, subdivisions NO-21 and NO-22 are presented with the country code SJ for Svalbard and the Jan Mayen Islands.
*/
country_code: string | null;
/**
* A three-character [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3) country code for the country associated with the IP address.
*
* The USA country code is returned for IP addresses associated with overseas United States military bases.
*/
country_code3: string | null;
/**
* Country name.
*
* This field is the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) English short name for a country.
*/
country_name: string | null;
/**
* Time zone offset from Greenwich Mean Time (GMT) for `city`.
*/
gmt_offset: string | null;
/**
* Latitude, in units of degrees from the equator.
*
* Values range from -90.0 to +90.0 inclusive, and are based on the [WGS 84](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinate reference system.
*/
latitude: number | null;
/**
* Longitude, in units of degrees from the [IERS Reference Meridian](https://en.wikipedia.org/wiki/IERS_Reference_Meridian).
*
* Values range from -180.0 to +180.0 inclusive, and are based on the [WGS 84](https://en.wikipedia.org/wiki/World_Geodetic_System) coordinate reference system.
*/
longitude: number | null;
/**
* Metro code, representing designated market areas (DMAs) in the United States.
*/
metro_code: number | null;
/**
* The postal code associated with the IP address.
*
* These are available for some IP addresses in Australia, Canada, France, Germany, Italy, Spain, Switzerland, the United Kingdom, and the United States.
*
* For Canadian postal codes, this is the first 3 characters. For the United Kingdom, this is the first 2-4 characters (outward code). For countries with alphanumeric postal codes, this field is a lowercase transliteration.
*/
postal_code: string | null;
/**
* Client proxy description.
*/
proxy_description: string | null;
/**
* Client proxy type.
*/
proxy_type: string | null;
/**
* [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2) country subdivision code.
*
* For countries with multiple levels of subdivision (for example, nations within the United Kingdom), this variable gives the more specific subdivision.
*
* This field can be None for countries that do not have ISO country subdivision codes. For example, None is given for IP addresses assigned to the Åland Islands (country code AX, illustrated below).
*/
region: string | null;
/**
* Time zone offset from coordinated universal time (UTC) for `city`.
*/
utc_offset: number | null;
}
/**
* Class for accessing a [Fastly KV Store](https://developer.fastly.com/reference/api/kv-store/).
*
* A KV Store is a persistent, globally consistent key-value store.
*
* **Note**: Can only be used when processing requests, not during build-time initialization.
* @deprecated This has moved to {@link "fastly:kv-store".KVStore} - This global class will be removed in the next major version.
* @hidden
*/
declare class KVStore {
/**
* Creates a new JavaScript KVStore object which interacts with the Fastly KV Store named `name`.
*
* @param name Name of the Fastly KV Store to interact with. A name cannot be empty, contain Control characters, or be longer than 255 characters.
*/
constructor(name: string);
/**
* Gets the value associated with the key `key` in the KV Store.
* When the key is present, a resolved Promise containing an KVStoreEntry will be returned which contains the associated value.
* When the key is absent, a resolved Promise containing null is returned.
* @param key The key to retrieve from within the KV Store. A key cannot:
* - Be any of the strings "", ".", or ".."
* - Start with the string ".well-known/acme-challenge/""
* - Contain any of the characters "#?*[]\n\r"
* - Be longer than 1024 characters
*/
get(key: string): Promise<KVStoreEntry | null>;
/**
* Write the value of `value` into the KV Store under the key `key`.
*
* Note: KV Store is eventually consistent, this means that the updated contents associated with the key `key` may not be available to read from all
* edge locations immediately and some edge locations may continue returning the previous contents associated with the key.
*
* @param key The key to associate with the value. A key cannot:
* - Be any of the strings "", ".", or ".."
* - Start with the string ".well-known/acme-challenge/""
* - Contain any of the characters "#?*[]\n\r"
* - Be longer than 1024 characters
* @param value The value to store within the KV Store.
*/
put(key: string, value: BodyInit): Promise<undefined>;
}
/**
* Class for interacting with a [Fastly KV Store](https://developer.fastly.com/reference/api/kv-store/) entry.
*
* @deprecated This has moved to {@link "fastly:kv-store".KVStoreEntry} - This global interface will be removed in the next major version.
* @hidden
*/
declare interface KVStoreEntry {
/**
* A ReadableStream with the contents of the entry.
*/
get body(): ReadableStream;
/**
* A boolean value that indicates whether the body has been read from already.
*/
get bodyUsed(): boolean;
/**
* Reads the body and returns it as a promise that resolves with a string.
* The response is always decoded using UTF-8.
*/
text(): Promise<string>;
/**
* Reads the body and returns it as a promise that resolves with the result of parsing the body text as JSON.
*/
json(): Promise<object>;
/**
* Reads the body and returns it as a promise that resolves with an ArrayBuffer.
*/
arrayBuffer(): Promise<ArrayBuffer>;
// And eventually formData and blob once we support them on Request and Response, too.
}
/**
* The URL class as [specified by WHATWG](https://url.spec.whatwg.org/#url-class)
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/URL | URL on MDN}
* @group Web APIs
*/
declare class URL {
constructor(url: string, base?: string | URL);
get href(): string;
set href(V: string);
get origin(): string;
get protocol(): string;
set protocol(V: string);
get username(): string;
set username(V: string);
get password(): string;
set password(V: string);
get host(): string;
set host(V: string);
get hostname(): string;
set hostname(V: string);
get port(): string;
set port(V: string);
get pathname(): string;
set pathname(V: string);
get search(): string;
set search(V: string);
get searchParams(): URLSearchParams;
get hash(): string;
set hash(V: string);
toJSON(): string;
readonly [Symbol.toStringTag]: 'URL';
}
/**
* The URLSearchParams class as [specified by WHATWG](https://url.spec.whatwg.org/#interface-urlsearchparams)
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams | URLSearchParams on MDN}
* @group Web APIs
*/
declare class URLSearchParams {
constructor(
init?:
| ReadonlyArray<readonly [name: string, value: string]>
| Iterable<readonly [name: string, value: string]>
| { readonly [name: string]: string }
| string,
);
append(name: string, value: string): void;
delete(name: string): void;
get(name: string): string | null;
getAll(name: string): string[];
has(name: string): boolean;
set(name: string, value: string): void;
sort(): void;
keys(): IterableIterator<string>;
values(): IterableIterator<string>;
entries(): IterableIterator<[name: string, value: string]>;
forEach<THIS_ARG = void>(
callback: (
this: THIS_ARG,
value: string,
name: string,
searchParams: this,
) => void,
thisArg?: THIS_ARG,
): void;
readonly [Symbol.toStringTag]: 'URLSearchParams';
[Symbol.iterator](): IterableIterator<[name: string, value: string]>;
}
/**
* Interface for logging to stdout for
* [live log monitoring](https://developer.fastly.com/learning/compute/testing/#live-log-monitoring-in-your-console).
*
* **Note**: This implementation accepts any number of arguments. String representations of each object are appended
* together in the order listed and output. Unlike the `Console` built-in in browsers and Node.js, this implementation
* does not perform string substitution.
*
* **Note**: Messages are prefixed with the respective log level, starting with an upper-case letter, e.g. `"Log: "`.
* @group Console API
*/
interface Console {
assert(condition?: boolean, ...data: any[]): void;
clear(): void;
count(label?: string): void;
countReset(label?: string): void;
debug(...data: any[]): void;
dir(item?: any, options?: any): void;
dirxml(...data: any[]): void;
error(...data: any[]): void;
group(...data: any[]): void;
groupCollapsed(...data: any[]): void;
groupEnd(): void;
info(...data: any[]): void;
log(...data: any[]): void;
table(tabularData?: any, properties?: string[]): void;
time(label?: string): void;
timeEnd(label?: string): void;
timeLog(label?: string, ...data: any[]): void;
trace(...data: any[]): void;
warn(...data: any[]): void;
}
/**
* The global {@linkcode Console} instance
* @group Console API
*/
declare var console: Console;
/**
* An implementation of the [WHATWG Encoding Standard](https://encoding.spec.whatwg.org/) `TextEncoder` API. All
* instances of `TextEncoder` only support UTF-8 encoding.
*
* TextEncoder takes a stream of code points as input and emits a stream of UTF-8 bytes.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder | TextEncoder on MDN}
* @example
* ```js
* const encoder = new TextEncoder();
* const uint8array = encoder.encode('a string to encode');
* ```
* @group Encoding API
*/
declare class TextEncoder {
/**
* Returns a newly constructed TextEncoder that will generate a byte stream with UTF-8 encoding.
*/
constructor();
/**
* The TextEncoder.encoding read-only property returns a string containing the name of the encoding algorithm used by the specific encoder.
* It is always set to the value "utf-8".
*/
readonly encoding: 'utf-8';
/**
* UTF-8 encodes the `input` string and returns a `Uint8Array` containing the encoded bytes.
* @param [input='an empty string'] The text to encode.
*/
encode(input?: string): Uint8Array;
// /**
// * UTF-8 encodes the `src` string to the `dest` Uint8Array and returns an object
// * containing the read Unicode code units and written UTF-8 bytes.
// *
// * ```js
// * const encoder = new TextEncoder();
// * const src = 'this is some data';
// * const dest = new Uint8Array(10);
// * const { read, written } = encoder.encodeInto(src, dest);
// * ```
// * @param src The text to encode.
// * @param dest The array to hold the encode result.
// */
// encodeInto(src: string, dest: Uint8Array): TextEncoderEncodeIntoResult;
}
// https://encoding.spec.whatwg.org/#dictdef-textencoderencodeintoresult
// declare interface TextEncoderEncodeIntoResult {
// read: number;
// written: number;
// }
/**
* TextDecoder takes a stream UTF-8 bytes as input and emits a stream of code points
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder | TextDecoder on MDN}
*
* **Note**: On Fastly Compute, TextDecoder only supports UTF-8 bytes as input, and always operates
* in non-fatal mode.
* @group Encoding API
*/
declare class TextDecoder {
// TODO: We should throw a RangeError if supplied a `label` that we do not support
constructor(label?: 'unicode-1-1-utf-8' | 'utf-8' | 'utf8');
decode(input?: ArrayBuffer | ArrayBufferView): string;
get encoding(): 'utf-8';
}
/**
* Simple interface for logging to
* [third party logging providers](https://developer.fastly.com/learning/integrations/logging)
*
* Instances of Logger for specific endpoints can be created using {@linkcode Fastly.getLogger}.
* @deprecated This has moved to {@link "fastly:logger".Logger} - This global class will be removed in the next major version.
* @hidden
*/
declare interface Logger {
/**
* Send the given message, converted to a string, to this Logger instance's endpoint
*/
log(message: any): void;
}
/**
* Fastly-specific APIs available to Fastly Compute JS services
* @deprecated
* @hidden
*/
declare interface Fastly {
/**
* @deprecated This has moved to {@link "fastly:experimental".setBaseURL} - This will be removed in the next major version.
* @hidden
* @experimental
*/
set baseURL(base: URL | null | undefined);
/**
* @deprecated This will be removed in the next major version.
* @hidden
* @experimental
*/
get baseURL(): URL | null;
/**
* @deprecated This has moved to {@link "fastly:experimental".setDefaultBackend} - This will be removed in the next major version.
* @hidden
* @experimental
*/
set defaultBackend(backend: string);
/**
* @deprecated This will be removed in the next major version.
* @hidden
* @experimental
*/
get defaultBackend(): string;
/**
* Property to access the environment variables for the Fastly Compute service.
* @hidden
* @experimental
*/
env: {
/**
* Function to get the environment variable value, for the provided environment variable name.
*
* For additional references, see the [Fastly Developer Hub for Compute Environment Variables](https://developer.fastly.com/reference/compute/ecp-env/)
*
* @param name The name of the environment variable
* @returns the value of the environemnt variable
* @deprecated This has moved to {@link "fastly:env".env} - This function will be removed in the next major version.
* @hidden
*/
get(name: string): string;
};
/**
* JavaScript SDK version string for the JS runtime build.
* @hidden
*/
sdkVersion: string;
/**
* Creates a new {@linkcode Logger} instance for the given
* [named log endpoint](https://developer.fastly.com/learning/integrations/logging).
*
* **Note**: Can only be used when processing requests, not during build-time initialization.
* @deprecated This function will be removed in the next major version. Use of this function can be replaced with the fastly logger class {@link "fastly:logger".Logger}
* @hidden
*/
getLogger(endpoint: string): Logger;
/**
* Causes the Fastly Compute JS runtime environment to log debug information to stdout.
*
* **Note**: This is mostly for internal debugging purposes and will generate highly unstable
* output.
*
* @deprecated This has moved to {@link "fastly:experimental".enableDebugLogging} - This function will be removed in the next major version.
* @hidden
* @experimental
*/
enableDebugLogging(enabled: boolean): void;
/**
* Retrieve geolocation information about the given IP address.
*
* @param address - the IPv4 or IPv6 address to query
*
* **Note**: Can only be used when processing requests, not during build-time initialization.
* @deprecated This has moved to {@link "fastly:geolocation".getGeolocationForIpAddress} - This function will be removed in the next major version.
* @hidden
*/
getGeolocationForIpAddress(
address: string,
): import('fastly:geolocation').Geolocation;
/**
* Embed a file as a Uint8Array.
*
* @param path - The path to include, relative to the project's top-level directory
*
* **Note**: Can only be used during build-time initialization, not when processing requests.
*
* @deprecated This has moved to {@link "fastly:experimental".includeBytes} - This function will be removed in the next major version.
* @hidden
* @experimental
*/