UNPKG

14.4 kBTypeScriptView Raw
1declare namespace console {
2 export function log(...args: any[]): void;
3 export function trace(...args: any[]): void;
4 export function debug(...args: any[]): void;
5 export function info(...args: any[]): void;
6 export function warn(...args: any[]): void;
7 export function error(...args: any[]): void;
8 export function assert(condition: boolean, message?: string, ...args: any[]): void;
9 export function count(label?: any): void;
10 export function countReset(label?: any): void;
11 export function time(label?: any): void;
12 export function timeLog(label?: any): void;
13 export function timeEnd(label?: any): void;
14 export function group(...args: any[]): void;
15 export function groupCollapsed(...args: any[]): void;
16 export function groupEnd(): void;
17}
18
19declare const crypto: Crypto;
20
21declare const window: {
22 crypto: Crypto;
23};
24
25declare namespace performance {
26 export function now(): number;
27}
28
29declare function btoa(text: string): string;
30declare function atob(text: string): string;
31declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): number;
32declare function clearTimeout(timeoutId: number): void;
33declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): number;
34declare function clearInterval(intervalId: number): void;
35declare function fetch<T = any>(url: string, options?: RequestInit): Promise<Response<T>>;
36
37declare class ServiceError extends Error {
38 public name: string;
39 public errorCode?: number;
40 public service?: string;
41
42 constructor(errorCode?: number, message?: string, service?: string);
43
44 public set(errorCode: number, message: string): void;
45 public setService(service: string): void;
46}
47
48interface Crypto {
49 getRandomValues<T extends Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray>(array: T): T;
50 subtle: CryptoSubtle;
51}
52
53interface CryptoSubtle {
54 generateKey(algorithm: RsaHashedKeyGenParams | EcKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair>;
55 generateKey(algorithm: AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>;
56 generateKey(algorithm: AlgorithmIdentifier, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKeyPair | CryptoKey>;
57 exportKey(format: "jwk", key: CryptoKey): Promise<JsonWebKey>;
58 exportKey(format: "raw" | "pkcs8" | "spki", key: CryptoKey): Promise<ArrayBuffer>;
59 importKey(format: "jwk", keyData: JsonWebKey, algorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>;
60 importKey(format: "raw" | "pkcs8" | "spki", keyData: ArrayBufferView | ArrayBuffer, algorithm: AlgorithmIdentifier | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | AesKeyAlgorithm, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey>;
61 sign(algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams | Ed448Params, key: CryptoKey, data: ArrayBufferView | ArrayBuffer): Promise<ArrayBuffer>;
62 verify(algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams | Ed448Params, key: CryptoKey, signature: ArrayBufferView | ArrayBuffer, data: ArrayBufferView | ArrayBuffer): Promise<boolean>;
63}
64
65declare class Body<T = any> {
66 body: Blob | ArrayBuffer | FormData | string | null;
67 bodyUsed: boolean;
68
69 constructor(body?: Blob | ArrayBuffer | FormData | string | null);
70 arrayBuffer(): Promise<ArrayBuffer>;
71 blob(): Promise<Blob>;
72 formData(): Promise<FormData>;
73 text(): Promise<string>;
74 json<J = T>(): Promise<J>;
75}
76
77interface RequestOptions {
78 body?: Blob | ArrayBuffer | FormData | string | null;
79 headers?: Headers;
80 method?: string;
81}
82
83declare class Request<T = any> extends Body<T> {
84 headers: Headers;
85 method: string;
86 url: string;
87
88 constructor(input: Request | string, options?: RequestOptions)
89
90 clone(): Request<T>;
91}
92
93interface ResponseOptions {
94 status?: number;
95 statusText?: string;
96 headers?: Headers | Record<string, string>;
97}
98
99declare class Response<T = any> extends Body<T> {
100 headers: Headers;
101 ok: boolean;
102 redirected: boolean;
103 status: number;
104 statusText: string;
105 type: string;
106 url: string;
107
108 constructor(body?: Blob | ArrayBuffer | FormData | string | null, options?: ResponseOptions);
109
110 clone(): Response<T>;
111}
112
113interface RequestInit {
114 method?: string;
115 headers?: FetchHeadersInit;
116 body?: FetchBodyInit;
117 agent?: FetchAgentInit;
118}
119
120interface FetchError {
121 message: string;
122}
123
124interface BlobOptions {
125 type: string;
126 endings: string;
127}
128
129declare class Headers implements Iterable<[string, string]> {
130 constructor(init?: FetchHeadersInit);
131 forEach(callback: (value: string, name: string) => void): void;
132 append(name: string, value: string): void;
133 delete(name: string): void;
134 get(name: string): string | null;
135 getAll(name: string): string[];
136 has(name: string): boolean;
137 raw(): { [k: string]: string[]; };
138 set(name: string, value: string): void;
139
140 entries(): Iterator<[string, string]>;
141 keys(): Iterator<string>;
142 values(): Iterator<string>;
143 [Symbol.iterator](): Iterator<[string, string]>;
144}
145
146declare class Blob {
147 constructor(chunks: Array<string | ArrayBuffer | ArrayBufferView | Blob>, options?: BlobOptions);
148 arrayBuffer(): Promise<ArrayBuffer>;
149 arrayBufferSync(): ArrayBuffer;
150 text(): Promise<string>;
151 textSync(): string;
152 slice(start: number, end: number, type: string): Blob;
153}
154
155declare class FormData {
156 append(name: string, value: string | Blob, filename?: string): void;
157 delete(name: string): void;
158 entries(): Iterator<any[]>;
159 getBlob(): Blob;
160 get(name: string): string | Blob; // Per spec it should return File instead of Blob, but currently we don't have a polyfill for File
161 getAll(): Array<string | Blob>; // Same where with the Blob
162 has(name: string): boolean;
163 keys(): Iterator<string>;
164 set(name: string, value: string | Blob, filename?: string): void;
165 values(): Iterator<string | Blob>;
166}
167
168declare class URL {
169 constructor(input: string | URL, base?: string | URL);
170 hash: string;
171 host: string;
172 hostname: string;
173 href: string;
174 readonly origin: string;
175 password: string;
176 pathname: string;
177 port: string;
178 protocol: string;
179 search: string;
180 readonly searchParams: URLSearchParams;
181 username: string;
182 toString(): string;
183 toJSON(): string;
184 static canParse(url: string | URL, base?: string): boolean;
185}
186
187declare class URLSearchParams implements Iterable<[string, string]> {
188 constructor(init?: URLSearchParams | string | { [key: string]: string | string[] | undefined; } | Iterable<[string, string]> | Array<[string, string]>);
189 append(name: string, value: string): void;
190 delete(name: string): void;
191 entries(): IterableIterator<[string, string]>;
192 forEach(callback: (value: string, name: string, searchParams: this) => void): void;
193 get(name: string): string | null;
194 getAll(name: string): string[];
195 has(name: string): boolean;
196 keys(): IterableIterator<string>;
197 set(name: string, value: string): void;
198 sort(): void;
199 toString(): string;
200 values(): IterableIterator<string>;
201 [Symbol.iterator](): IterableIterator<[string, string]>;
202}
203
204type FetchHeadersInit = Headers | string[][] | { [key: string]: string; };
205type FetchBodyInit = FormData | ArrayBuffer | ArrayBufferView | string; // TODO: add URLSearchParams
206type FetchAgentInit = {
207 /**
208 * If true the server will reject any connection which is not
209 * authorized with the list of supplied CAs.
210 */
211 rejectUnauthorized?: boolean;
212 /**
213 * Private keys in PEM format. PEM allows the option of private keys
214 * being encrypted. Encrypted keys will be decrypted with passphrase.
215 */
216 key?: string | ArrayBuffer | (string | ArrayBuffer)[];
217 /**
218 * Cert chains in PEM format. One cert chain should be provided per
219 * private key. Each cert chain should consist of the PEM formatted
220 * certificate for a provided private key, followed by the PEM
221 * formatted intermediate certificates (if any), in order, and not
222 * including the root CA (the root CA must be pre-known to the peer,
223 * see ca). When providing multiple cert chains, they do not have to
224 * be in the same order as their private keys in key. If the
225 * intermediate certificates are not provided, the peer will not be
226 * able to validate the certificate, and the handshake will fail.
227 */
228 cert?: string | ArrayBuffer | (string | ArrayBuffer)[];
229 /**
230 * Optionally override the trusted CA certificates. Default is to trust
231 * the well-known CAs curated by Mozilla. Mozilla's CAs are completely
232 * replaced when CAs are explicitly specified using this option.
233 */
234 ca?: string | ArrayBuffer | (string | ArrayBuffer)[];
235 /**
236 * Shared passphrase used for a single private key.
237 */
238 passphrase?: string;
239};
240
241interface Context {
242 /**
243 * Start time in UNIX time (milliseconds) indicating when the invocation started.
244 */
245 readonly startTime: number;
246
247 /**
248 * Timeout in milliseconds for how long the invocation can run.
249 */
250 readonly timeout: number;
251
252 /**
253 * Memory in MBs that is available for the invocation.
254 */
255 readonly availableMemory: number;
256
257 /**
258 * Unique identifier of the invocation.
259 */
260 readonly invocationId: string;
261
262 /**
263 * * Environment information where the invocation is running.
264 */
265 readonly environment: {
266 /**
267 * Environment unique ID.
268 */
269 readonly uid: string;
270 /**
271 * Environment name.
272 */
273 readonly name: string;
274 };
275
276 /**
277 * Deployment version and label of the invocation.
278 */
279 readonly deployment?: {
280 /**
281 * Deployment unique ID.
282 */
283 readonly uid: string;
284
285 /**
286 * Deployment version.
287 */
288 readonly version: string;
289
290 /**
291 * Deployment label, if available.
292 */
293 readonly label?: string;
294 };
295
296 /**
297 * How the original invocation was triggered. Original invocation in this context means if the script was programmatically triggered, then this property indicates the trigger type of the original invocation.
298 * If the script was not programmatically triggered then this value remains the same as the `triggerType` property.
299 *
300 * * EXTERNAL - Script was triggered via Event Listener in a response to external event.
301 * * MANUAL - Script was triggered manually.
302 * * SCHEDULED - Script was triggered via Scheduled Trigger.
303 * * MANUAL_EVENT_LISTENER - Script was triggered manually via Event Listener with a test payload.
304 */
305 readonly rootTriggerType: 'EXTERNAL' | 'MANUAL' | 'SCHEDULED' | 'MANUAL_EVENT_LISTENER';
306
307 /**
308 * How the script was triggered:
309 *
310 * * EXTERNAL - Script was triggered via Event Listener as a response to external event being emitted.
311 * * MANUAL - Script was triggered manually.
312 * * SCHEDULED - Script was triggered via Scheduled Trigger.
313 * * MANUAL_EVENT_LISTENER - Script was triggered manually via Event Listener with a test payload.
314 * * CHAINED - Script was triggered programmatically from another script, to figure out the original trigger type, read the `rootTriggerType` property.
315 */
316 readonly triggerType: 'EXTERNAL' | 'MANUAL' | 'SCHEDULED' | 'MANUAL_EVENT_LISTENER' | 'CHAINED';
317}
318
319interface TextEncoderOptions {
320 stream?: boolean;
321}
322
323interface TextDecoderOptions {
324 stream?: boolean;
325}
326
327declare class TextEncoder {
328 encode(input: string, options?: TextEncoderOptions): Uint8Array;
329}
330
331declare class TextDecoder {
332 decode(input: Uint8Array, options?: TextDecoderOptions): string;
333}
334
335interface Algorithm {
336 name: string;
337}
338
339type AlgorithmIdentifier = string | Algorithm;
340type BigInteger = Uint8Array;
341type HashAlgorithmIdentifier = AlgorithmIdentifier;
342type NamedCurve = string;
343type KeyUsage = "decrypt" | "deriveBits" | "deriveKey" | "encrypt" | "sign" | "unwrapKey" | "verify" | "wrapKey";
344type KeyType = "private" | "public" | "secret";
345
346interface RsaKeyGenParams extends Algorithm {
347 modulusLength: number;
348 publicExponent: BigInteger;
349}
350
351interface RsaHashedKeyGenParams extends RsaKeyGenParams {
352 hash: HashAlgorithmIdentifier;
353}
354
355interface EcKeyGenParams extends Algorithm {
356 namedCurve: NamedCurve;
357}
358
359interface DhKeyGenParams extends Algorithm {
360 generator: Uint8Array;
361 prime: Uint8Array;
362}
363
364interface KeyAlgorithm {
365 name: string;
366}
367
368interface AesKeyGenParams extends Algorithm {
369 length: number;
370}
371
372interface HmacKeyGenParams extends Algorithm {
373 hash: HashAlgorithmIdentifier;
374 length?: number;
375}
376
377interface Pbkdf2Params extends Algorithm {
378 hash: HashAlgorithmIdentifier;
379 iterations: number;
380 salt: ArrayBufferView | ArrayBuffer;
381}
382
383interface JsonWebKey {
384 alg?: string;
385 crv?: string;
386 d?: string;
387 dp?: string;
388 dq?: string;
389 e?: string;
390 ext?: boolean;
391 k?: string;
392 key_ops?: string[];
393 kty?: string;
394 n?: string;
395 oth?: RsaOtherPrimesInfo[];
396 p?: string;
397 q?: string;
398 qi?: string;
399 use?: string;
400 x?: string;
401 y?: string;
402}
403
404interface RsaOtherPrimesInfo {
405 d?: string;
406 r?: string;
407 t?: string;
408}
409
410interface RsaHashedImportParams extends Algorithm {
411 hash: HashAlgorithmIdentifier;
412}
413
414interface HmacImportParams extends Algorithm {
415 hash: HashAlgorithmIdentifier;
416 length?: number;
417}
418
419interface EcKeyImportParams extends Algorithm {
420 namedCurve: NamedCurve;
421}
422
423interface AesKeyAlgorithm extends KeyAlgorithm {
424 length: number;
425}
426
427interface RsaPssParams extends Algorithm {
428 saltLength: number;
429}
430
431interface EcdsaParams extends Algorithm {
432 hash: HashAlgorithmIdentifier;
433}
434
435interface Ed448Params extends Algorithm {
436 context?: ArrayBufferView | ArrayBuffer;
437}
438
439declare class CryptoKey {
440 readonly algorithm: KeyAlgorithm;
441 readonly extractable: boolean;
442 readonly type: KeyType;
443 readonly usages: KeyUsage[];
444}
445
446declare class CryptoKeyPair {
447 privateKey: CryptoKey;
448 publicKey: CryptoKey;
449}
\No newline at end of file