@volter/tabnode 0.5.48 → 0.5.50
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.
- package/dist/assets/{runtime-worker-B-BP9mj-.js → runtime-worker-Cu2mr9G9.js} +1253 -89
- package/dist/fetch-transport.d.ts +0 -1
- package/dist/index.mjs +1250 -100
- package/dist/node-body.d.ts +9 -0
- package/dist/shims/crypto-cipher.d.ts +203 -0
- package/dist/shims/crypto.d.ts +465 -1
- package/package.json +2 -1
- package/src/fetch-transport.ts +7 -3
- package/src/node-body.ts +88 -0
- package/src/node-response.ts +5 -2
- package/src/runtime.ts +3 -0
- package/src/shims/child_process.ts +49 -6
- package/src/shims/crypto-cipher.ts +354 -0
- package/src/shims/crypto.ts +27 -2
- package/src/shims/shell-jobs.ts +72 -0
package/dist/shims/crypto.d.ts
CHANGED
|
@@ -15,6 +15,162 @@ interface DigestState {
|
|
|
15
15
|
}
|
|
16
16
|
/** Native crypto allocates guest results and classes in the caller's graph. */
|
|
17
17
|
export declare function createCryptoModule(require?: (name: string) => any): {
|
|
18
|
+
Cipheriv: {
|
|
19
|
+
new (algorithm: unknown, key: unknown, iv: unknown, options?: {
|
|
20
|
+
authTagLength?: number;
|
|
21
|
+
}): {
|
|
22
|
+
getAuthTag(): Uint8Array;
|
|
23
|
+
readonly "__#private@#decrypt": boolean;
|
|
24
|
+
readonly "__#private@#mode": "gcm" | "cbc" | "ctr" | "ecb";
|
|
25
|
+
readonly "__#private@#xk": Uint32Array;
|
|
26
|
+
readonly "__#private@#xkDec": Uint32Array | undefined;
|
|
27
|
+
"__#private@#padding": boolean;
|
|
28
|
+
"__#private@#finished": boolean;
|
|
29
|
+
"__#private@#started": boolean;
|
|
30
|
+
"__#private@#pending": Uint8Array<ArrayBufferLike>;
|
|
31
|
+
"__#private@#chain": Uint8Array<ArrayBufferLike> | undefined;
|
|
32
|
+
"__#private@#counter": Uint8Array<ArrayBufferLike> | undefined;
|
|
33
|
+
"__#private@#keystream": Uint8Array<ArrayBufferLike>;
|
|
34
|
+
"__#private@#ghash": import("@noble/ciphers/_polyval.js").GHASH | undefined;
|
|
35
|
+
"__#private@#tagMask": Uint8Array<ArrayBufferLike> | undefined;
|
|
36
|
+
"__#private@#ghashPending": Uint8Array<ArrayBufferLike>;
|
|
37
|
+
"__#private@#aadLength": number;
|
|
38
|
+
"__#private@#dataLength": number;
|
|
39
|
+
"__#private@#authTagLength": number | undefined;
|
|
40
|
+
"__#private@#authTag": Uint8Array<ArrayBufferLike> | undefined;
|
|
41
|
+
setAutoPadding(autoPadding?: boolean): /*elided*/ any;
|
|
42
|
+
setAAD(buffer: unknown, _options?: {
|
|
43
|
+
plaintextLength?: number;
|
|
44
|
+
}): /*elided*/ any;
|
|
45
|
+
"__#private@#getTag"(): Uint8Array<ArrayBufferLike>;
|
|
46
|
+
"__#private@#setTag"(tag: unknown, encoding?: string): void;
|
|
47
|
+
update(data: unknown, inputEncoding?: string, outputEncoding?: string): unknown;
|
|
48
|
+
final(outputEncoding?: string): unknown;
|
|
49
|
+
"__#private@#process"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
50
|
+
"__#private@#stream"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
51
|
+
"__#private@#absorb"(ciphertext: Uint8Array<ArrayBufferLike>): void;
|
|
52
|
+
"__#private@#blocks"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
53
|
+
"__#private@#block"(block: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
54
|
+
"__#private@#finish"(): Uint8Array<ArrayBufferLike>;
|
|
55
|
+
"__#private@#finishGcm"(): Uint8Array<ArrayBufferLike>;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
Decipheriv: {
|
|
59
|
+
new (algorithm: unknown, key: unknown, iv: unknown, options?: {
|
|
60
|
+
authTagLength?: number;
|
|
61
|
+
}): {
|
|
62
|
+
setAuthTag(tag: unknown, encoding?: string): /*elided*/ any;
|
|
63
|
+
readonly "__#private@#decrypt": boolean;
|
|
64
|
+
readonly "__#private@#mode": "gcm" | "cbc" | "ctr" | "ecb";
|
|
65
|
+
readonly "__#private@#xk": Uint32Array;
|
|
66
|
+
readonly "__#private@#xkDec": Uint32Array | undefined;
|
|
67
|
+
"__#private@#padding": boolean;
|
|
68
|
+
"__#private@#finished": boolean;
|
|
69
|
+
"__#private@#started": boolean;
|
|
70
|
+
"__#private@#pending": Uint8Array<ArrayBufferLike>;
|
|
71
|
+
"__#private@#chain": Uint8Array<ArrayBufferLike> | undefined;
|
|
72
|
+
"__#private@#counter": Uint8Array<ArrayBufferLike> | undefined;
|
|
73
|
+
"__#private@#keystream": Uint8Array<ArrayBufferLike>;
|
|
74
|
+
"__#private@#ghash": import("@noble/ciphers/_polyval.js").GHASH | undefined;
|
|
75
|
+
"__#private@#tagMask": Uint8Array<ArrayBufferLike> | undefined;
|
|
76
|
+
"__#private@#ghashPending": Uint8Array<ArrayBufferLike>;
|
|
77
|
+
"__#private@#aadLength": number;
|
|
78
|
+
"__#private@#dataLength": number;
|
|
79
|
+
"__#private@#authTagLength": number | undefined;
|
|
80
|
+
"__#private@#authTag": Uint8Array<ArrayBufferLike> | undefined;
|
|
81
|
+
setAutoPadding(autoPadding?: boolean): /*elided*/ any;
|
|
82
|
+
setAAD(buffer: unknown, _options?: {
|
|
83
|
+
plaintextLength?: number;
|
|
84
|
+
}): /*elided*/ any;
|
|
85
|
+
"__#private@#getTag"(): Uint8Array<ArrayBufferLike>;
|
|
86
|
+
"__#private@#setTag"(tag: unknown, encoding?: string): void;
|
|
87
|
+
update(data: unknown, inputEncoding?: string, outputEncoding?: string): unknown;
|
|
88
|
+
final(outputEncoding?: string): unknown;
|
|
89
|
+
"__#private@#process"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
90
|
+
"__#private@#stream"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
91
|
+
"__#private@#absorb"(ciphertext: Uint8Array<ArrayBufferLike>): void;
|
|
92
|
+
"__#private@#blocks"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
93
|
+
"__#private@#block"(block: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
94
|
+
"__#private@#finish"(): Uint8Array<ArrayBufferLike>;
|
|
95
|
+
"__#private@#finishGcm"(): Uint8Array<ArrayBufferLike>;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
createCipheriv: (algorithm: unknown, key: unknown, iv: unknown, options?: {
|
|
99
|
+
authTagLength?: number;
|
|
100
|
+
}) => {
|
|
101
|
+
getAuthTag(): Uint8Array;
|
|
102
|
+
readonly "__#private@#decrypt": boolean;
|
|
103
|
+
readonly "__#private@#mode": "gcm" | "cbc" | "ctr" | "ecb";
|
|
104
|
+
readonly "__#private@#xk": Uint32Array;
|
|
105
|
+
readonly "__#private@#xkDec": Uint32Array | undefined;
|
|
106
|
+
"__#private@#padding": boolean;
|
|
107
|
+
"__#private@#finished": boolean;
|
|
108
|
+
"__#private@#started": boolean;
|
|
109
|
+
"__#private@#pending": Uint8Array<ArrayBufferLike>;
|
|
110
|
+
"__#private@#chain": Uint8Array<ArrayBufferLike> | undefined;
|
|
111
|
+
"__#private@#counter": Uint8Array<ArrayBufferLike> | undefined;
|
|
112
|
+
"__#private@#keystream": Uint8Array<ArrayBufferLike>;
|
|
113
|
+
"__#private@#ghash": import("@noble/ciphers/_polyval.js").GHASH | undefined;
|
|
114
|
+
"__#private@#tagMask": Uint8Array<ArrayBufferLike> | undefined;
|
|
115
|
+
"__#private@#ghashPending": Uint8Array<ArrayBufferLike>;
|
|
116
|
+
"__#private@#aadLength": number;
|
|
117
|
+
"__#private@#dataLength": number;
|
|
118
|
+
"__#private@#authTagLength": number | undefined;
|
|
119
|
+
"__#private@#authTag": Uint8Array<ArrayBufferLike> | undefined;
|
|
120
|
+
setAutoPadding(autoPadding?: boolean): /*elided*/ any;
|
|
121
|
+
setAAD(buffer: unknown, _options?: {
|
|
122
|
+
plaintextLength?: number;
|
|
123
|
+
}): /*elided*/ any;
|
|
124
|
+
"__#private@#getTag"(): Uint8Array<ArrayBufferLike>;
|
|
125
|
+
"__#private@#setTag"(tag: unknown, encoding?: string): void;
|
|
126
|
+
update(data: unknown, inputEncoding?: string, outputEncoding?: string): unknown;
|
|
127
|
+
final(outputEncoding?: string): unknown;
|
|
128
|
+
"__#private@#process"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
129
|
+
"__#private@#stream"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
130
|
+
"__#private@#absorb"(ciphertext: Uint8Array<ArrayBufferLike>): void;
|
|
131
|
+
"__#private@#blocks"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
132
|
+
"__#private@#block"(block: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
133
|
+
"__#private@#finish"(): Uint8Array<ArrayBufferLike>;
|
|
134
|
+
"__#private@#finishGcm"(): Uint8Array<ArrayBufferLike>;
|
|
135
|
+
};
|
|
136
|
+
createDecipheriv: (algorithm: unknown, key: unknown, iv: unknown, options?: {
|
|
137
|
+
authTagLength?: number;
|
|
138
|
+
}) => {
|
|
139
|
+
setAuthTag(tag: unknown, encoding?: string): /*elided*/ any;
|
|
140
|
+
readonly "__#private@#decrypt": boolean;
|
|
141
|
+
readonly "__#private@#mode": "gcm" | "cbc" | "ctr" | "ecb";
|
|
142
|
+
readonly "__#private@#xk": Uint32Array;
|
|
143
|
+
readonly "__#private@#xkDec": Uint32Array | undefined;
|
|
144
|
+
"__#private@#padding": boolean;
|
|
145
|
+
"__#private@#finished": boolean;
|
|
146
|
+
"__#private@#started": boolean;
|
|
147
|
+
"__#private@#pending": Uint8Array<ArrayBufferLike>;
|
|
148
|
+
"__#private@#chain": Uint8Array<ArrayBufferLike> | undefined;
|
|
149
|
+
"__#private@#counter": Uint8Array<ArrayBufferLike> | undefined;
|
|
150
|
+
"__#private@#keystream": Uint8Array<ArrayBufferLike>;
|
|
151
|
+
"__#private@#ghash": import("@noble/ciphers/_polyval.js").GHASH | undefined;
|
|
152
|
+
"__#private@#tagMask": Uint8Array<ArrayBufferLike> | undefined;
|
|
153
|
+
"__#private@#ghashPending": Uint8Array<ArrayBufferLike>;
|
|
154
|
+
"__#private@#aadLength": number;
|
|
155
|
+
"__#private@#dataLength": number;
|
|
156
|
+
"__#private@#authTagLength": number | undefined;
|
|
157
|
+
"__#private@#authTag": Uint8Array<ArrayBufferLike> | undefined;
|
|
158
|
+
setAutoPadding(autoPadding?: boolean): /*elided*/ any;
|
|
159
|
+
setAAD(buffer: unknown, _options?: {
|
|
160
|
+
plaintextLength?: number;
|
|
161
|
+
}): /*elided*/ any;
|
|
162
|
+
"__#private@#getTag"(): Uint8Array<ArrayBufferLike>;
|
|
163
|
+
"__#private@#setTag"(tag: unknown, encoding?: string): void;
|
|
164
|
+
update(data: unknown, inputEncoding?: string, outputEncoding?: string): unknown;
|
|
165
|
+
final(outputEncoding?: string): unknown;
|
|
166
|
+
"__#private@#process"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
167
|
+
"__#private@#stream"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
168
|
+
"__#private@#absorb"(ciphertext: Uint8Array<ArrayBufferLike>): void;
|
|
169
|
+
"__#private@#blocks"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
170
|
+
"__#private@#block"(block: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
171
|
+
"__#private@#finish"(): Uint8Array<ArrayBufferLike>;
|
|
172
|
+
"__#private@#finishGcm"(): Uint8Array<ArrayBufferLike>;
|
|
173
|
+
};
|
|
18
174
|
unsupported: (operation: string) => never;
|
|
19
175
|
randomBytes: {
|
|
20
176
|
(size: number): Buffer;
|
|
@@ -260,6 +416,162 @@ export declare function createCryptoModule(require?: (name: string) => any): {
|
|
|
260
416
|
} | ((error: Error | null, publicKey?: unknown, privateKey?: unknown) => void), callback?: (error: Error | null, publicKey?: unknown, privateKey?: unknown) => void) => void;
|
|
261
417
|
};
|
|
262
418
|
declare const cryptoModule: {
|
|
419
|
+
Cipheriv: {
|
|
420
|
+
new (algorithm: unknown, key: unknown, iv: unknown, options?: {
|
|
421
|
+
authTagLength?: number;
|
|
422
|
+
}): {
|
|
423
|
+
getAuthTag(): Uint8Array;
|
|
424
|
+
readonly "__#private@#decrypt": boolean;
|
|
425
|
+
readonly "__#private@#mode": "gcm" | "cbc" | "ctr" | "ecb";
|
|
426
|
+
readonly "__#private@#xk": Uint32Array;
|
|
427
|
+
readonly "__#private@#xkDec": Uint32Array | undefined;
|
|
428
|
+
"__#private@#padding": boolean;
|
|
429
|
+
"__#private@#finished": boolean;
|
|
430
|
+
"__#private@#started": boolean;
|
|
431
|
+
"__#private@#pending": Uint8Array<ArrayBufferLike>;
|
|
432
|
+
"__#private@#chain": Uint8Array<ArrayBufferLike> | undefined;
|
|
433
|
+
"__#private@#counter": Uint8Array<ArrayBufferLike> | undefined;
|
|
434
|
+
"__#private@#keystream": Uint8Array<ArrayBufferLike>;
|
|
435
|
+
"__#private@#ghash": import("@noble/ciphers/_polyval.js").GHASH | undefined;
|
|
436
|
+
"__#private@#tagMask": Uint8Array<ArrayBufferLike> | undefined;
|
|
437
|
+
"__#private@#ghashPending": Uint8Array<ArrayBufferLike>;
|
|
438
|
+
"__#private@#aadLength": number;
|
|
439
|
+
"__#private@#dataLength": number;
|
|
440
|
+
"__#private@#authTagLength": number | undefined;
|
|
441
|
+
"__#private@#authTag": Uint8Array<ArrayBufferLike> | undefined;
|
|
442
|
+
setAutoPadding(autoPadding?: boolean): /*elided*/ any;
|
|
443
|
+
setAAD(buffer: unknown, _options?: {
|
|
444
|
+
plaintextLength?: number;
|
|
445
|
+
}): /*elided*/ any;
|
|
446
|
+
"__#private@#getTag"(): Uint8Array<ArrayBufferLike>;
|
|
447
|
+
"__#private@#setTag"(tag: unknown, encoding?: string): void;
|
|
448
|
+
update(data: unknown, inputEncoding?: string, outputEncoding?: string): unknown;
|
|
449
|
+
final(outputEncoding?: string): unknown;
|
|
450
|
+
"__#private@#process"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
451
|
+
"__#private@#stream"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
452
|
+
"__#private@#absorb"(ciphertext: Uint8Array<ArrayBufferLike>): void;
|
|
453
|
+
"__#private@#blocks"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
454
|
+
"__#private@#block"(block: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
455
|
+
"__#private@#finish"(): Uint8Array<ArrayBufferLike>;
|
|
456
|
+
"__#private@#finishGcm"(): Uint8Array<ArrayBufferLike>;
|
|
457
|
+
};
|
|
458
|
+
};
|
|
459
|
+
Decipheriv: {
|
|
460
|
+
new (algorithm: unknown, key: unknown, iv: unknown, options?: {
|
|
461
|
+
authTagLength?: number;
|
|
462
|
+
}): {
|
|
463
|
+
setAuthTag(tag: unknown, encoding?: string): /*elided*/ any;
|
|
464
|
+
readonly "__#private@#decrypt": boolean;
|
|
465
|
+
readonly "__#private@#mode": "gcm" | "cbc" | "ctr" | "ecb";
|
|
466
|
+
readonly "__#private@#xk": Uint32Array;
|
|
467
|
+
readonly "__#private@#xkDec": Uint32Array | undefined;
|
|
468
|
+
"__#private@#padding": boolean;
|
|
469
|
+
"__#private@#finished": boolean;
|
|
470
|
+
"__#private@#started": boolean;
|
|
471
|
+
"__#private@#pending": Uint8Array<ArrayBufferLike>;
|
|
472
|
+
"__#private@#chain": Uint8Array<ArrayBufferLike> | undefined;
|
|
473
|
+
"__#private@#counter": Uint8Array<ArrayBufferLike> | undefined;
|
|
474
|
+
"__#private@#keystream": Uint8Array<ArrayBufferLike>;
|
|
475
|
+
"__#private@#ghash": import("@noble/ciphers/_polyval.js").GHASH | undefined;
|
|
476
|
+
"__#private@#tagMask": Uint8Array<ArrayBufferLike> | undefined;
|
|
477
|
+
"__#private@#ghashPending": Uint8Array<ArrayBufferLike>;
|
|
478
|
+
"__#private@#aadLength": number;
|
|
479
|
+
"__#private@#dataLength": number;
|
|
480
|
+
"__#private@#authTagLength": number | undefined;
|
|
481
|
+
"__#private@#authTag": Uint8Array<ArrayBufferLike> | undefined;
|
|
482
|
+
setAutoPadding(autoPadding?: boolean): /*elided*/ any;
|
|
483
|
+
setAAD(buffer: unknown, _options?: {
|
|
484
|
+
plaintextLength?: number;
|
|
485
|
+
}): /*elided*/ any;
|
|
486
|
+
"__#private@#getTag"(): Uint8Array<ArrayBufferLike>;
|
|
487
|
+
"__#private@#setTag"(tag: unknown, encoding?: string): void;
|
|
488
|
+
update(data: unknown, inputEncoding?: string, outputEncoding?: string): unknown;
|
|
489
|
+
final(outputEncoding?: string): unknown;
|
|
490
|
+
"__#private@#process"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
491
|
+
"__#private@#stream"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
492
|
+
"__#private@#absorb"(ciphertext: Uint8Array<ArrayBufferLike>): void;
|
|
493
|
+
"__#private@#blocks"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
494
|
+
"__#private@#block"(block: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
495
|
+
"__#private@#finish"(): Uint8Array<ArrayBufferLike>;
|
|
496
|
+
"__#private@#finishGcm"(): Uint8Array<ArrayBufferLike>;
|
|
497
|
+
};
|
|
498
|
+
};
|
|
499
|
+
createCipheriv: (algorithm: unknown, key: unknown, iv: unknown, options?: {
|
|
500
|
+
authTagLength?: number;
|
|
501
|
+
}) => {
|
|
502
|
+
getAuthTag(): Uint8Array;
|
|
503
|
+
readonly "__#private@#decrypt": boolean;
|
|
504
|
+
readonly "__#private@#mode": "gcm" | "cbc" | "ctr" | "ecb";
|
|
505
|
+
readonly "__#private@#xk": Uint32Array;
|
|
506
|
+
readonly "__#private@#xkDec": Uint32Array | undefined;
|
|
507
|
+
"__#private@#padding": boolean;
|
|
508
|
+
"__#private@#finished": boolean;
|
|
509
|
+
"__#private@#started": boolean;
|
|
510
|
+
"__#private@#pending": Uint8Array<ArrayBufferLike>;
|
|
511
|
+
"__#private@#chain": Uint8Array<ArrayBufferLike> | undefined;
|
|
512
|
+
"__#private@#counter": Uint8Array<ArrayBufferLike> | undefined;
|
|
513
|
+
"__#private@#keystream": Uint8Array<ArrayBufferLike>;
|
|
514
|
+
"__#private@#ghash": import("@noble/ciphers/_polyval.js").GHASH | undefined;
|
|
515
|
+
"__#private@#tagMask": Uint8Array<ArrayBufferLike> | undefined;
|
|
516
|
+
"__#private@#ghashPending": Uint8Array<ArrayBufferLike>;
|
|
517
|
+
"__#private@#aadLength": number;
|
|
518
|
+
"__#private@#dataLength": number;
|
|
519
|
+
"__#private@#authTagLength": number | undefined;
|
|
520
|
+
"__#private@#authTag": Uint8Array<ArrayBufferLike> | undefined;
|
|
521
|
+
setAutoPadding(autoPadding?: boolean): /*elided*/ any;
|
|
522
|
+
setAAD(buffer: unknown, _options?: {
|
|
523
|
+
plaintextLength?: number;
|
|
524
|
+
}): /*elided*/ any;
|
|
525
|
+
"__#private@#getTag"(): Uint8Array<ArrayBufferLike>;
|
|
526
|
+
"__#private@#setTag"(tag: unknown, encoding?: string): void;
|
|
527
|
+
update(data: unknown, inputEncoding?: string, outputEncoding?: string): unknown;
|
|
528
|
+
final(outputEncoding?: string): unknown;
|
|
529
|
+
"__#private@#process"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
530
|
+
"__#private@#stream"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
531
|
+
"__#private@#absorb"(ciphertext: Uint8Array<ArrayBufferLike>): void;
|
|
532
|
+
"__#private@#blocks"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
533
|
+
"__#private@#block"(block: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
534
|
+
"__#private@#finish"(): Uint8Array<ArrayBufferLike>;
|
|
535
|
+
"__#private@#finishGcm"(): Uint8Array<ArrayBufferLike>;
|
|
536
|
+
};
|
|
537
|
+
createDecipheriv: (algorithm: unknown, key: unknown, iv: unknown, options?: {
|
|
538
|
+
authTagLength?: number;
|
|
539
|
+
}) => {
|
|
540
|
+
setAuthTag(tag: unknown, encoding?: string): /*elided*/ any;
|
|
541
|
+
readonly "__#private@#decrypt": boolean;
|
|
542
|
+
readonly "__#private@#mode": "gcm" | "cbc" | "ctr" | "ecb";
|
|
543
|
+
readonly "__#private@#xk": Uint32Array;
|
|
544
|
+
readonly "__#private@#xkDec": Uint32Array | undefined;
|
|
545
|
+
"__#private@#padding": boolean;
|
|
546
|
+
"__#private@#finished": boolean;
|
|
547
|
+
"__#private@#started": boolean;
|
|
548
|
+
"__#private@#pending": Uint8Array<ArrayBufferLike>;
|
|
549
|
+
"__#private@#chain": Uint8Array<ArrayBufferLike> | undefined;
|
|
550
|
+
"__#private@#counter": Uint8Array<ArrayBufferLike> | undefined;
|
|
551
|
+
"__#private@#keystream": Uint8Array<ArrayBufferLike>;
|
|
552
|
+
"__#private@#ghash": import("@noble/ciphers/_polyval.js").GHASH | undefined;
|
|
553
|
+
"__#private@#tagMask": Uint8Array<ArrayBufferLike> | undefined;
|
|
554
|
+
"__#private@#ghashPending": Uint8Array<ArrayBufferLike>;
|
|
555
|
+
"__#private@#aadLength": number;
|
|
556
|
+
"__#private@#dataLength": number;
|
|
557
|
+
"__#private@#authTagLength": number | undefined;
|
|
558
|
+
"__#private@#authTag": Uint8Array<ArrayBufferLike> | undefined;
|
|
559
|
+
setAutoPadding(autoPadding?: boolean): /*elided*/ any;
|
|
560
|
+
setAAD(buffer: unknown, _options?: {
|
|
561
|
+
plaintextLength?: number;
|
|
562
|
+
}): /*elided*/ any;
|
|
563
|
+
"__#private@#getTag"(): Uint8Array<ArrayBufferLike>;
|
|
564
|
+
"__#private@#setTag"(tag: unknown, encoding?: string): void;
|
|
565
|
+
update(data: unknown, inputEncoding?: string, outputEncoding?: string): unknown;
|
|
566
|
+
final(outputEncoding?: string): unknown;
|
|
567
|
+
"__#private@#process"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
568
|
+
"__#private@#stream"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
569
|
+
"__#private@#absorb"(ciphertext: Uint8Array<ArrayBufferLike>): void;
|
|
570
|
+
"__#private@#blocks"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
571
|
+
"__#private@#block"(block: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
572
|
+
"__#private@#finish"(): Uint8Array<ArrayBufferLike>;
|
|
573
|
+
"__#private@#finishGcm"(): Uint8Array<ArrayBufferLike>;
|
|
574
|
+
};
|
|
263
575
|
unsupported: (operation: string) => never;
|
|
264
576
|
randomBytes: {
|
|
265
577
|
(size: number): Buffer;
|
|
@@ -504,7 +816,159 @@ declare const cryptoModule: {
|
|
|
504
816
|
};
|
|
505
817
|
} | ((error: Error | null, publicKey?: unknown, privateKey?: unknown) => void), callback?: (error: Error | null, publicKey?: unknown, privateKey?: unknown) => void) => void;
|
|
506
818
|
};
|
|
507
|
-
export declare const
|
|
819
|
+
export declare const Cipheriv: {
|
|
820
|
+
new (algorithm: unknown, key: unknown, iv: unknown, options?: {
|
|
821
|
+
authTagLength?: number;
|
|
822
|
+
}): {
|
|
823
|
+
getAuthTag(): Uint8Array;
|
|
824
|
+
readonly "__#private@#decrypt": boolean;
|
|
825
|
+
readonly "__#private@#mode": "gcm" | "cbc" | "ctr" | "ecb";
|
|
826
|
+
readonly "__#private@#xk": Uint32Array;
|
|
827
|
+
readonly "__#private@#xkDec": Uint32Array | undefined;
|
|
828
|
+
"__#private@#padding": boolean;
|
|
829
|
+
"__#private@#finished": boolean;
|
|
830
|
+
"__#private@#started": boolean;
|
|
831
|
+
"__#private@#pending": Uint8Array<ArrayBufferLike>;
|
|
832
|
+
"__#private@#chain": Uint8Array<ArrayBufferLike> | undefined;
|
|
833
|
+
"__#private@#counter": Uint8Array<ArrayBufferLike> | undefined;
|
|
834
|
+
"__#private@#keystream": Uint8Array<ArrayBufferLike>;
|
|
835
|
+
"__#private@#ghash": import("@noble/ciphers/_polyval.js").GHASH | undefined;
|
|
836
|
+
"__#private@#tagMask": Uint8Array<ArrayBufferLike> | undefined;
|
|
837
|
+
"__#private@#ghashPending": Uint8Array<ArrayBufferLike>;
|
|
838
|
+
"__#private@#aadLength": number;
|
|
839
|
+
"__#private@#dataLength": number;
|
|
840
|
+
"__#private@#authTagLength": number | undefined;
|
|
841
|
+
"__#private@#authTag": Uint8Array<ArrayBufferLike> | undefined;
|
|
842
|
+
setAutoPadding(autoPadding?: boolean): /*elided*/ any;
|
|
843
|
+
setAAD(buffer: unknown, _options?: {
|
|
844
|
+
plaintextLength?: number;
|
|
845
|
+
}): /*elided*/ any;
|
|
846
|
+
"__#private@#getTag"(): Uint8Array<ArrayBufferLike>;
|
|
847
|
+
"__#private@#setTag"(tag: unknown, encoding?: string): void;
|
|
848
|
+
update(data: unknown, inputEncoding?: string, outputEncoding?: string): unknown;
|
|
849
|
+
final(outputEncoding?: string): unknown;
|
|
850
|
+
"__#private@#process"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
851
|
+
"__#private@#stream"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
852
|
+
"__#private@#absorb"(ciphertext: Uint8Array<ArrayBufferLike>): void;
|
|
853
|
+
"__#private@#blocks"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
854
|
+
"__#private@#block"(block: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
855
|
+
"__#private@#finish"(): Uint8Array<ArrayBufferLike>;
|
|
856
|
+
"__#private@#finishGcm"(): Uint8Array<ArrayBufferLike>;
|
|
857
|
+
};
|
|
858
|
+
}, Decipheriv: {
|
|
859
|
+
new (algorithm: unknown, key: unknown, iv: unknown, options?: {
|
|
860
|
+
authTagLength?: number;
|
|
861
|
+
}): {
|
|
862
|
+
setAuthTag(tag: unknown, encoding?: string): /*elided*/ any;
|
|
863
|
+
readonly "__#private@#decrypt": boolean;
|
|
864
|
+
readonly "__#private@#mode": "gcm" | "cbc" | "ctr" | "ecb";
|
|
865
|
+
readonly "__#private@#xk": Uint32Array;
|
|
866
|
+
readonly "__#private@#xkDec": Uint32Array | undefined;
|
|
867
|
+
"__#private@#padding": boolean;
|
|
868
|
+
"__#private@#finished": boolean;
|
|
869
|
+
"__#private@#started": boolean;
|
|
870
|
+
"__#private@#pending": Uint8Array<ArrayBufferLike>;
|
|
871
|
+
"__#private@#chain": Uint8Array<ArrayBufferLike> | undefined;
|
|
872
|
+
"__#private@#counter": Uint8Array<ArrayBufferLike> | undefined;
|
|
873
|
+
"__#private@#keystream": Uint8Array<ArrayBufferLike>;
|
|
874
|
+
"__#private@#ghash": import("@noble/ciphers/_polyval.js").GHASH | undefined;
|
|
875
|
+
"__#private@#tagMask": Uint8Array<ArrayBufferLike> | undefined;
|
|
876
|
+
"__#private@#ghashPending": Uint8Array<ArrayBufferLike>;
|
|
877
|
+
"__#private@#aadLength": number;
|
|
878
|
+
"__#private@#dataLength": number;
|
|
879
|
+
"__#private@#authTagLength": number | undefined;
|
|
880
|
+
"__#private@#authTag": Uint8Array<ArrayBufferLike> | undefined;
|
|
881
|
+
setAutoPadding(autoPadding?: boolean): /*elided*/ any;
|
|
882
|
+
setAAD(buffer: unknown, _options?: {
|
|
883
|
+
plaintextLength?: number;
|
|
884
|
+
}): /*elided*/ any;
|
|
885
|
+
"__#private@#getTag"(): Uint8Array<ArrayBufferLike>;
|
|
886
|
+
"__#private@#setTag"(tag: unknown, encoding?: string): void;
|
|
887
|
+
update(data: unknown, inputEncoding?: string, outputEncoding?: string): unknown;
|
|
888
|
+
final(outputEncoding?: string): unknown;
|
|
889
|
+
"__#private@#process"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
890
|
+
"__#private@#stream"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
891
|
+
"__#private@#absorb"(ciphertext: Uint8Array<ArrayBufferLike>): void;
|
|
892
|
+
"__#private@#blocks"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
893
|
+
"__#private@#block"(block: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
894
|
+
"__#private@#finish"(): Uint8Array<ArrayBufferLike>;
|
|
895
|
+
"__#private@#finishGcm"(): Uint8Array<ArrayBufferLike>;
|
|
896
|
+
};
|
|
897
|
+
}, createCipheriv: (algorithm: unknown, key: unknown, iv: unknown, options?: {
|
|
898
|
+
authTagLength?: number;
|
|
899
|
+
}) => {
|
|
900
|
+
getAuthTag(): Uint8Array;
|
|
901
|
+
readonly "__#private@#decrypt": boolean;
|
|
902
|
+
readonly "__#private@#mode": "gcm" | "cbc" | "ctr" | "ecb";
|
|
903
|
+
readonly "__#private@#xk": Uint32Array;
|
|
904
|
+
readonly "__#private@#xkDec": Uint32Array | undefined;
|
|
905
|
+
"__#private@#padding": boolean;
|
|
906
|
+
"__#private@#finished": boolean;
|
|
907
|
+
"__#private@#started": boolean;
|
|
908
|
+
"__#private@#pending": Uint8Array<ArrayBufferLike>;
|
|
909
|
+
"__#private@#chain": Uint8Array<ArrayBufferLike> | undefined;
|
|
910
|
+
"__#private@#counter": Uint8Array<ArrayBufferLike> | undefined;
|
|
911
|
+
"__#private@#keystream": Uint8Array<ArrayBufferLike>;
|
|
912
|
+
"__#private@#ghash": import("@noble/ciphers/_polyval.js").GHASH | undefined;
|
|
913
|
+
"__#private@#tagMask": Uint8Array<ArrayBufferLike> | undefined;
|
|
914
|
+
"__#private@#ghashPending": Uint8Array<ArrayBufferLike>;
|
|
915
|
+
"__#private@#aadLength": number;
|
|
916
|
+
"__#private@#dataLength": number;
|
|
917
|
+
"__#private@#authTagLength": number | undefined;
|
|
918
|
+
"__#private@#authTag": Uint8Array<ArrayBufferLike> | undefined;
|
|
919
|
+
setAutoPadding(autoPadding?: boolean): /*elided*/ any;
|
|
920
|
+
setAAD(buffer: unknown, _options?: {
|
|
921
|
+
plaintextLength?: number;
|
|
922
|
+
}): /*elided*/ any;
|
|
923
|
+
"__#private@#getTag"(): Uint8Array<ArrayBufferLike>;
|
|
924
|
+
"__#private@#setTag"(tag: unknown, encoding?: string): void;
|
|
925
|
+
update(data: unknown, inputEncoding?: string, outputEncoding?: string): unknown;
|
|
926
|
+
final(outputEncoding?: string): unknown;
|
|
927
|
+
"__#private@#process"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
928
|
+
"__#private@#stream"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
929
|
+
"__#private@#absorb"(ciphertext: Uint8Array<ArrayBufferLike>): void;
|
|
930
|
+
"__#private@#blocks"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
931
|
+
"__#private@#block"(block: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
932
|
+
"__#private@#finish"(): Uint8Array<ArrayBufferLike>;
|
|
933
|
+
"__#private@#finishGcm"(): Uint8Array<ArrayBufferLike>;
|
|
934
|
+
}, createDecipheriv: (algorithm: unknown, key: unknown, iv: unknown, options?: {
|
|
935
|
+
authTagLength?: number;
|
|
936
|
+
}) => {
|
|
937
|
+
setAuthTag(tag: unknown, encoding?: string): /*elided*/ any;
|
|
938
|
+
readonly "__#private@#decrypt": boolean;
|
|
939
|
+
readonly "__#private@#mode": "gcm" | "cbc" | "ctr" | "ecb";
|
|
940
|
+
readonly "__#private@#xk": Uint32Array;
|
|
941
|
+
readonly "__#private@#xkDec": Uint32Array | undefined;
|
|
942
|
+
"__#private@#padding": boolean;
|
|
943
|
+
"__#private@#finished": boolean;
|
|
944
|
+
"__#private@#started": boolean;
|
|
945
|
+
"__#private@#pending": Uint8Array<ArrayBufferLike>;
|
|
946
|
+
"__#private@#chain": Uint8Array<ArrayBufferLike> | undefined;
|
|
947
|
+
"__#private@#counter": Uint8Array<ArrayBufferLike> | undefined;
|
|
948
|
+
"__#private@#keystream": Uint8Array<ArrayBufferLike>;
|
|
949
|
+
"__#private@#ghash": import("@noble/ciphers/_polyval.js").GHASH | undefined;
|
|
950
|
+
"__#private@#tagMask": Uint8Array<ArrayBufferLike> | undefined;
|
|
951
|
+
"__#private@#ghashPending": Uint8Array<ArrayBufferLike>;
|
|
952
|
+
"__#private@#aadLength": number;
|
|
953
|
+
"__#private@#dataLength": number;
|
|
954
|
+
"__#private@#authTagLength": number | undefined;
|
|
955
|
+
"__#private@#authTag": Uint8Array<ArrayBufferLike> | undefined;
|
|
956
|
+
setAutoPadding(autoPadding?: boolean): /*elided*/ any;
|
|
957
|
+
setAAD(buffer: unknown, _options?: {
|
|
958
|
+
plaintextLength?: number;
|
|
959
|
+
}): /*elided*/ any;
|
|
960
|
+
"__#private@#getTag"(): Uint8Array<ArrayBufferLike>;
|
|
961
|
+
"__#private@#setTag"(tag: unknown, encoding?: string): void;
|
|
962
|
+
update(data: unknown, inputEncoding?: string, outputEncoding?: string): unknown;
|
|
963
|
+
final(outputEncoding?: string): unknown;
|
|
964
|
+
"__#private@#process"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
965
|
+
"__#private@#stream"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
966
|
+
"__#private@#absorb"(ciphertext: Uint8Array<ArrayBufferLike>): void;
|
|
967
|
+
"__#private@#blocks"(input: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
968
|
+
"__#private@#block"(block: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike>;
|
|
969
|
+
"__#private@#finish"(): Uint8Array<ArrayBufferLike>;
|
|
970
|
+
"__#private@#finishGcm"(): Uint8Array<ArrayBufferLike>;
|
|
971
|
+
}, randomBytes: {
|
|
508
972
|
(size: number): Buffer;
|
|
509
973
|
(size: number, callback: (error: Error | null, buffer: Buffer) => void): void;
|
|
510
974
|
}, randomFillSync: <T extends ArrayBufferView | ArrayBufferLike>(buffer: T, offset?: number, size?: number) => T, randomFill: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/tabnode",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.50",
|
|
4
4
|
"description": "Node's own library, in a browser tab.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"type-check": "tsc --noEmit"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
+
"@noble/ciphers": "2.4.0",
|
|
58
59
|
"@noble/hashes": "2.3.0",
|
|
59
60
|
"acorn": "^8.15.0",
|
|
60
61
|
"amaro": "1.1.0",
|
package/src/fetch-transport.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** Host Fetch I/O uses the same process-owned liveness registry as sockets. */
|
|
2
|
+
import { withNodeRequestBody } from './node-body';
|
|
2
3
|
import type { Process } from './shims/process';
|
|
3
4
|
import { __tokenForProcess, __runFor, enterRun, type ProcessToken } from './process-tokens';
|
|
4
5
|
import { registerHandle, __adoptHandle, refHandle, unrefHandle, releaseHandle } from './node-lib/binding/handles';
|
|
@@ -83,11 +84,14 @@ function activity(owner: ProcessToken | null, cancel: () => void): FetchActivity
|
|
|
83
84
|
export function guestFetch(process: Process, fallback: typeof globalThis.fetch): typeof globalThis.fetch {
|
|
84
85
|
return function fetch(input, init) {
|
|
85
86
|
const adapter = transport;
|
|
86
|
-
|
|
87
|
-
const owner = __tokenForProcess(process);
|
|
87
|
+
const owner = adapter ? __tokenForProcess(process) : null;
|
|
88
88
|
const ended = () => owner !== null && __runFor(owner)?.process !== process;
|
|
89
89
|
const stopped = () => new DOMException('The requesting process has ended.', 'AbortError');
|
|
90
|
-
if (ended()) return Promise.reject(stopped());
|
|
90
|
+
if (adapter && ended()) return Promise.reject(stopped());
|
|
91
|
+
// A stream body is read as undici reads it, whichever door the fetch
|
|
92
|
+
// leaves by; a body undici refuses rejects the fetch, as Node's does.
|
|
93
|
+
try { init = withNodeRequestBody(init); } catch (error) { return Promise.reject(error); }
|
|
94
|
+
if (!adapter) return fallback.call(globalThis, input, init);
|
|
91
95
|
const context: FetchTransportContext = { begin(cancel) {
|
|
92
96
|
if (ended()) throw stopped();
|
|
93
97
|
return activity(owner, cancel);
|
package/src/node-body.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A body as Node's fetch (undici's `extractBody`) accepts it: besides what a
|
|
3
|
+
* browser takes, any async iterable (a Node `Readable`, an `http.IncomingMessage`,
|
|
4
|
+
* an async generator) is read as a stream of its chunks, each a `Buffer`,
|
|
5
|
+
* a typed array or a string (UTF-8). A browser's `Request` and `Response` take
|
|
6
|
+
* such an object for a string: `new Request(url, { method: 'POST', body:
|
|
7
|
+
* incomingMessage, duplex: 'half' })` has the body "[object Object]". Next's
|
|
8
|
+
* App Router builds every route handler's request exactly that way (its
|
|
9
|
+
* request adapter passes the Node request as the body, "handled by undici"),
|
|
10
|
+
* so every POST a route handler read was that string, and NextAuth's
|
|
11
|
+
* credentials callback found no CSRF token in it.
|
|
12
|
+
*
|
|
13
|
+
* Only such a body is changed; every other init is handed on untouched.
|
|
14
|
+
*/
|
|
15
|
+
import { Buffer } from './node-lib/buffer-module';
|
|
16
|
+
|
|
17
|
+
/** The mark Node's streams carry once read (`internal/streams/utils`, `kIsDisturbed`). */
|
|
18
|
+
const kIsDisturbed = Symbol.for('nodejs.stream.disturbed');
|
|
19
|
+
|
|
20
|
+
function isAsyncIterableBody(body: unknown): body is AsyncIterable<unknown> {
|
|
21
|
+
if (body === null || typeof body !== 'object') return false;
|
|
22
|
+
if (typeof ReadableStream === 'function' && body instanceof ReadableStream) return false;
|
|
23
|
+
if (typeof Blob === 'function' && body instanceof Blob) return false;
|
|
24
|
+
if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) return false;
|
|
25
|
+
if (typeof FormData === 'function' && body instanceof FormData) return false;
|
|
26
|
+
if (body instanceof URLSearchParams) return false;
|
|
27
|
+
return typeof (body as { [Symbol.asyncIterator]?: unknown })[Symbol.asyncIterator] === 'function';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Node's `isDisturbed`, and undici's refusal of a body already read or locked. */
|
|
31
|
+
function refuseDisturbed(body: object): void {
|
|
32
|
+
const stream = body as { locked?: unknown; readableDidRead?: unknown; readableAborted?: unknown; [kIsDisturbed]?: unknown };
|
|
33
|
+
const disturbed = stream[kIsDisturbed] !== undefined ? Boolean(stream[kIsDisturbed]) : Boolean(stream.readableDidRead || stream.readableAborted);
|
|
34
|
+
if (disturbed || stream.locked === true) throw new TypeError('Response body object should not be disturbed or locked');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* undici's `ReadableStreamFrom`: the iterator made when the stream starts,
|
|
39
|
+
* each chunk `Buffer.from`'d as Node's is (a chunk `Buffer.from` refuses
|
|
40
|
+
* errors the stream), an empty chunk passed over for the next, and the
|
|
41
|
+
* iterator returned, with no argument, on cancel.
|
|
42
|
+
*/
|
|
43
|
+
function streamFrom(iterable: AsyncIterable<unknown>): ReadableStream<Uint8Array> {
|
|
44
|
+
let iterator: AsyncIterator<unknown> | undefined;
|
|
45
|
+
return new ReadableStream<Uint8Array>({
|
|
46
|
+
async start() { iterator = iterable[Symbol.asyncIterator](); },
|
|
47
|
+
async pull(controller) {
|
|
48
|
+
for (;;) {
|
|
49
|
+
const { done, value } = await iterator!.next();
|
|
50
|
+
if (done) { controller.close(); return; }
|
|
51
|
+
const bytes = (Buffer.isBuffer(value) ? value : (Buffer.from as (chunk: unknown) => Uint8Array)(value)) as Uint8Array;
|
|
52
|
+
if (bytes.byteLength) { controller.enqueue(new Uint8Array(bytes)); return; }
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
async cancel() { await iterator?.return?.(); },
|
|
56
|
+
}, { highWaterMark: 0 });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const REQUEST_INIT_MEMBERS = ['method', 'headers', 'referrer', 'referrerPolicy', 'mode', 'credentials', 'cache', 'redirect', 'integrity', 'keepalive', 'signal', 'window', 'duplex', 'priority'] as const;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The init with an async-iterable body read as a stream, or the init itself.
|
|
63
|
+
* The body is read once; the replacement is built member by member (an init
|
|
64
|
+
* may carry its members on getters of its prototype, as a `Request` passed as
|
|
65
|
+
* an init does), with the init's own other members as they are.
|
|
66
|
+
*/
|
|
67
|
+
export function withNodeRequestBody<T extends RequestInit | undefined>(init: T): T {
|
|
68
|
+
if (!init) return init;
|
|
69
|
+
const body = (init as RequestInit).body as unknown;
|
|
70
|
+
if (!isAsyncIterableBody(body)) return init;
|
|
71
|
+
refuseDisturbed(body);
|
|
72
|
+
const copy: Record<string, unknown> = {};
|
|
73
|
+
for (const member of Object.keys(init)) if (member !== 'body') copy[member] = (init as Record<string, unknown>)[member];
|
|
74
|
+
for (const member of REQUEST_INIT_MEMBERS) {
|
|
75
|
+
if (member in copy) continue;
|
|
76
|
+
const value = (init as Record<string, unknown>)[member];
|
|
77
|
+
if (value !== undefined) copy[member] = value;
|
|
78
|
+
}
|
|
79
|
+
copy.body = streamFrom(body);
|
|
80
|
+
return copy as T;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** A response body as undici takes it: an async iterable read as a stream, anything else as given. */
|
|
84
|
+
export function nodeResponseBody(body: unknown): unknown {
|
|
85
|
+
if (!isAsyncIterableBody(body)) return body;
|
|
86
|
+
refuseDisturbed(body);
|
|
87
|
+
return streamFrom(body);
|
|
88
|
+
}
|
package/src/node-response.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defineOnHost, takeFromHost } from './host-globals';
|
|
2
|
+
import { nodeResponseBody } from './node-body';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* A web `Response` that keeps its `Set-Cookie` headers, as Node's does.
|
|
@@ -76,7 +77,9 @@ export function installNodeResponse(target: { Response?: typeof Response }): voi
|
|
|
76
77
|
const Native = target.Response as ResponseConstructor | undefined;
|
|
77
78
|
if (typeof Native !== 'function' || Native[INSTALLED]) return;
|
|
78
79
|
const proto = Native.prototype;
|
|
79
|
-
|
|
80
|
+
// The getter is the prototype's own in a browser; found up the chain wherever it is.
|
|
81
|
+
let nativeHeaders: (() => unknown) | undefined;
|
|
82
|
+
for (let at: object | null = proto; at && !nativeHeaders; at = Object.getPrototypeOf(at)) nativeHeaders = Object.getOwnPropertyDescriptor(at, 'headers')?.get;
|
|
80
83
|
const nativeFormData = proto.formData;
|
|
81
84
|
const nativeBlob = proto.blob;
|
|
82
85
|
const nativeArrayBuffer = proto.arrayBuffer;
|
|
@@ -87,7 +90,7 @@ export function installNodeResponse(target: { Response?: typeof Response }): voi
|
|
|
87
90
|
const NodeResponse = function Response(this: unknown, body?: BodyInit | null, init?: ResponseInit): Response {
|
|
88
91
|
if (!new.target) throw new TypeError("Class constructor Response cannot be invoked without 'new'");
|
|
89
92
|
const given = givenHeaders(init);
|
|
90
|
-
const response = Reflect.construct(Native, [body, given ? withHeaders(init, given) : init], (new.target as unknown) === NodeResponse ? Native : new.target) as Response;
|
|
93
|
+
const response = Reflect.construct(Native, [nodeResponseBody(body) as BodyInit | null | undefined, given ? withHeaders(init, given) : init], (new.target as unknown) === NodeResponse ? Native : new.target) as Response;
|
|
91
94
|
kept.set(response, withCookies(nativeHeaders.call(response) as Headers, given));
|
|
92
95
|
return response;
|
|
93
96
|
} as unknown as ResponseConstructor;
|