@orkestrel/server 0.0.1 → 0.0.3
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/src/core/index.cjs +1695 -0
- package/dist/src/core/index.cjs.map +1 -0
- package/dist/src/core/{helpers.d.ts → index.d.cts} +1538 -890
- package/dist/src/core/index.d.ts +1538 -6
- package/dist/src/core/index.js +32 -119
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +44 -964
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +334 -0
- package/dist/src/server/index.d.ts +334 -4
- package/dist/src/server/index.js +406 -0
- package/dist/src/server/index.js.map +1 -0
- package/package.json +28 -16
- package/dist/src/core/Negotiator.d.ts +0 -32
- package/dist/src/core/constants.d.ts +0 -68
- package/dist/src/core/errors.d.ts +0 -73
- package/dist/src/core/factories.d.ts +0 -21
- package/dist/src/core/types.d.ts +0 -362
- package/dist/src/server/Server.d.ts +0 -63
- package/dist/src/server/factories.d.ts +0 -26
- package/dist/src/server/helpers.d.ts +0 -45
- package/dist/src/server/types.d.ts +0 -163
|
@@ -1,890 +1,1538 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @remarks
|
|
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
|
-
* @param
|
|
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
|
-
export declare function
|
|
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
|
-
* @param
|
|
270
|
-
* @
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
* @
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*/
|
|
278
|
-
export declare
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
* @returns
|
|
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
|
-
* @remarks
|
|
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
|
-
* @param
|
|
423
|
-
* @returns The
|
|
424
|
-
*
|
|
425
|
-
* @example
|
|
426
|
-
* ```ts
|
|
427
|
-
*
|
|
428
|
-
* ```
|
|
429
|
-
*/
|
|
430
|
-
export declare function
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
* @remarks
|
|
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
|
-
* header +
|
|
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
|
-
|
|
1
|
+
/**
|
|
2
|
+
* One parsed entry of a weighted `Accept` / `Accept-Encoding` / `Accept-Language`
|
|
3
|
+
* header — a value and its quality weight, the element type `parseAcceptHeader`
|
|
4
|
+
* returns (sorted by `q` descending).
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* `value` is the lower-cased token (`text/html`, `gzip`, `en-us`, or a
|
|
8
|
+
* wildcard). `q` is the quality weight in `[0, 1]` (the `;q=` parameter,
|
|
9
|
+
* default `1` when absent); a `;q=0` entry explicitly REJECTS that token — a
|
|
10
|
+
* parser keeps it (so a caller can honor the rejection) rather than
|
|
11
|
+
* dropping it.
|
|
12
|
+
*/
|
|
13
|
+
export declare interface AcceptEntry {
|
|
14
|
+
readonly value: string;
|
|
15
|
+
readonly q: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Append a `Set-Cookie` header onto a fetch-standard `Headers` WITHOUT
|
|
20
|
+
* clobbering a prior one.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* `Headers.append` already accumulates repeated headers (unlike node's
|
|
24
|
+
* `setHeader`), so this is a thin, self-documenting wrapper naming the
|
|
25
|
+
* cookie-append intent — the primitive {@link writeSignedCookie} /
|
|
26
|
+
* {@link clearCookie} use.
|
|
27
|
+
*
|
|
28
|
+
* @param headers - The response `Headers` to write into
|
|
29
|
+
* @param cookie - The fully-serialized `Set-Cookie` value (from {@link serializeCookie})
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const headers = new Headers()
|
|
34
|
+
* appendCookie(headers, serializeCookie('a', '1'))
|
|
35
|
+
* appendCookie(headers, serializeCookie('b', '2'))
|
|
36
|
+
* headers.get('set-cookie') // 'a=1; Path=/; HttpOnly; SameSite=Lax, b=2; …'
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function appendCookie(headers: Headers, cookie: string): void;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Options for `readBody` — how the shared body-collection pipeline caps and
|
|
43
|
+
* decompresses a request body.
|
|
44
|
+
*
|
|
45
|
+
* @param limit - The maximum request body size in bytes; a larger body
|
|
46
|
+
* throws a {@link import('./errors.js').ContentTooLargeError} (413).
|
|
47
|
+
* Defaults to {@link DEFAULT_BODY_LIMIT}.
|
|
48
|
+
* @param decompression - The maximum DECOMPRESSED body size in bytes (the
|
|
49
|
+
* zip-bomb cap) for a `Content-Encoding: gzip` / `deflate` request body. A
|
|
50
|
+
* highly-compressible payload small ON THE WIRE (under `limit`) can inflate
|
|
51
|
+
* enormously, so a byte-counting `TransformStream` aborts the pipe the
|
|
52
|
+
* instant decompressed output would exceed this. Defaults to {@link
|
|
53
|
+
* import('./constants.js').DEFAULT_DECOMPRESSED_LIMIT} (16 MiB) —
|
|
54
|
+
* INDEPENDENT of `limit`, not aligned with it; a non-positive value means
|
|
55
|
+
* UNCAPPED decompressed output — use only when `limit` already bounds the
|
|
56
|
+
* compressed input.
|
|
57
|
+
*/
|
|
58
|
+
export declare interface BodyOptions {
|
|
59
|
+
readonly limit?: number;
|
|
60
|
+
readonly decompression?: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Clear a cookie — append a `Set-Cookie` that expires it immediately (`Max-Age=0`).
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* Writes an empty-valued cookie of the same `name` with `Max-Age=0` plus the
|
|
68
|
+
* same `path`/`domain`/`sameSite`/`secure` attributes (the browser only drops
|
|
69
|
+
* a cookie when those MATCH the one it set).
|
|
70
|
+
*
|
|
71
|
+
* @param headers - The response `Headers` to write into
|
|
72
|
+
* @param name - The cookie name to clear
|
|
73
|
+
* @param options - The {@link CookieOptions} that must match the original cookie
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const headers = new Headers()
|
|
78
|
+
* clearCookie(headers, 'session')
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function clearCookie(headers: Headers, name: string, options?: CookieOptions): void;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Collapse a client IP into its rate-limit BUCKET key — an IPv6 address to
|
|
85
|
+
* its `/64` network, an IPv4 (or IPv4-mapped) address unchanged.
|
|
86
|
+
*
|
|
87
|
+
* @remarks
|
|
88
|
+
* A residential/mobile IPv6 user is routinely handed a WHOLE `/64`, so a
|
|
89
|
+
* per-`/128` rate limit is trivially bypassed by rotating host bits — the
|
|
90
|
+
* real identity is the `/64` network. Delegates the IPv6 collapse to
|
|
91
|
+
* {@link ipv6Network}; anything it returns `undefined` for (an IPv4 address,
|
|
92
|
+
* a malformed string) is kept unchanged.
|
|
93
|
+
*
|
|
94
|
+
* @param address - The raw connection peer address ({@link import('./types.js').ConnectionInfo.ip})
|
|
95
|
+
* @returns The bucket key — the `/64` network for an IPv6 address, else the address unchanged
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* clientRateKey('2001:db8:1:2:dead:beef:0:9') // '2001:db8:1:2::/64'
|
|
100
|
+
* clientRateKey('192.0.2.1') // '192.0.2.1'
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function clientRateKey(address: string): string;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The client's quality (q) for one content-coding from the parsed
|
|
107
|
+
* `Accept-Encoding` entries — backs {@link negotiateEncoding}'s
|
|
108
|
+
* server-preference selection.
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
* Prefers an EXACT named match (including an explicit `;q=0` rejection);
|
|
112
|
+
* failing that, a bare `*` wildcard's q applies. A coding that is neither
|
|
113
|
+
* named nor covered by `*` scores `0` (not acceptable). A named `;q=0` wins
|
|
114
|
+
* over a `*` (a specific rejection beats the wildcard), so it scores `0`.
|
|
115
|
+
*
|
|
116
|
+
* @param entries - The parsed {@link AcceptEntry} list
|
|
117
|
+
* @param coding - The candidate coding to score
|
|
118
|
+
* @returns The client's quality for `coding` in `[0, 1]` (`0` ⇒ not acceptable)
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* codingQuality(parseAcceptHeader('gzip;q=0.5, *;q=0.1'), 'gzip') // 0.5
|
|
123
|
+
* codingQuality(parseAcceptHeader('gzip;q=0.5, *;q=0.1'), 'br') // 0.1
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare function codingQuality(entries: readonly AcceptEntry[], coding: string): number;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Collect a `Request` body into a single `Uint8Array`, enforcing a size limit.
|
|
130
|
+
*
|
|
131
|
+
* @remarks
|
|
132
|
+
* Reads `request.body` (a `ReadableStream<Uint8Array>`) chunk by chunk,
|
|
133
|
+
* throwing a {@link ContentTooLargeError} (413) the instant the running total
|
|
134
|
+
* exceeds `limit` — BEFORE the rest of the stream is buffered — rather than
|
|
135
|
+
* collecting an unbounded body. A bodyless request (`request.body === null`)
|
|
136
|
+
* resolves an empty array. A non-positive `limit` means unbounded.
|
|
137
|
+
*
|
|
138
|
+
* @param request - The `Request` to drain
|
|
139
|
+
* @param limit - The maximum total bytes before a 413; a non-positive value means unbounded
|
|
140
|
+
* @returns The full request body as one `Uint8Array`
|
|
141
|
+
* @throws {ContentTooLargeError} When the body exceeds `limit`
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const bytes = await collectRequestBody(request, 1_048_576)
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export declare function collectRequestBody(request: Request, limit: number): Promise<Uint8Array<ArrayBuffer>>;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Compose an ordered chain of {@link MiddlewareHandler}s around a `terminal`
|
|
152
|
+
* handler into one request handler — the frozen middleware seam (§5.1).
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* `middleware[0]` runs OUTERMOST: it is invoked first, and its call to `next`
|
|
156
|
+
* runs `middleware[1]`, and so on until the LAST middleware's `next` invokes
|
|
157
|
+
* `terminal`. Each middleware's `next` may be called with a substituted
|
|
158
|
+
* `Request` (the downstream chain then sees that request instead of the
|
|
159
|
+
* original), called with no argument (the original request continues
|
|
160
|
+
* downstream), or NOT called at all (a short-circuit — the middleware's own
|
|
161
|
+
* returned `Response` is sent, and everything downstream never runs). A
|
|
162
|
+
* SECOND call to the same `next` within one middleware invocation REJECTS —
|
|
163
|
+
* each link runs the chain at most once, so a middleware cannot fork the
|
|
164
|
+
* request into two divergent downstream runs.
|
|
165
|
+
*
|
|
166
|
+
* @typeParam TState - The consumer's opaque per-request state type
|
|
167
|
+
* @param middleware - The ordered chain, outermost first
|
|
168
|
+
* @param terminal - The innermost handler the chain ultimately reaches
|
|
169
|
+
* @returns A single `(request, context) => Promise<Response>` handler running the whole onion
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* const withHeader: MiddlewareHandler<{}> = async (request, context, next) => {
|
|
174
|
+
* const response = await next()
|
|
175
|
+
* response.headers.set('X-Powered-By', 'orkestrel')
|
|
176
|
+
* return response
|
|
177
|
+
* }
|
|
178
|
+
*
|
|
179
|
+
* const handle = compose([withHeader], async () => new Response('ok'))
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export declare function compose<TState>(middleware: readonly MiddlewareHandler<TState>[], terminal: (request: Request, context: MiddlewareContext<TState>) => Promise<Response>): (request: Request, context: MiddlewareContext<TState>) => Promise<Response>;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* The set of bare `Content-Type`s `isCompressibleType` treats as
|
|
186
|
+
* COMPRESSIBLE, beyond the `text/*` prefix + structured-suffix (`+json` /
|
|
187
|
+
* `+xml`) rules that helper also applies.
|
|
188
|
+
*
|
|
189
|
+
* @remarks
|
|
190
|
+
* The text-shaped application types worth compressing (JSON / JavaScript /
|
|
191
|
+
* XML / SVG / WASM / a few document formats) — NOT already-compressed
|
|
192
|
+
* binaries (`image/png`, `image/jpeg`, `video/*`, `application/zip`, a font's
|
|
193
|
+
* `woff2`), which gzip/deflate would only bloat. Frozen so a consumer reads
|
|
194
|
+
* but never mutates the shared default.
|
|
195
|
+
*/
|
|
196
|
+
export declare const COMPRESSIBLE_TYPES: ReadonlySet<string>;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Compute a CONTENT `ETag` over a fully-buffered response body via WebCrypto.
|
|
200
|
+
*
|
|
201
|
+
* @remarks
|
|
202
|
+
* Hashes `body` with SHA-256 (`crypto.subtle.digest`) and wraps the hex
|
|
203
|
+
* digest as a WEAK validator (`W/"<hash>"`) when `weak` is `true` — the
|
|
204
|
+
* default, encoding-AGNOSTIC, so the tag survives a downstream content
|
|
205
|
+
* re-encoding (gzip) and still matches on revalidation — or a STRONG one
|
|
206
|
+
* (`"<hash>"`, byte-identity) when `weak` is `false`.
|
|
207
|
+
*
|
|
208
|
+
* @param body - The full (uncompressed) response body to hash
|
|
209
|
+
* @param weak - `true` for a weak `W/"…"` validator (the default), `false` for a strong `"…"` one
|
|
210
|
+
* @returns The `ETag` header value
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```ts
|
|
214
|
+
* await computeBodyETag(new TextEncoder().encode('hello')) // 'W/"…sha256-hex…"'
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
export declare function computeBodyETag(body: Uint8Array<ArrayBuffer>, weak?: boolean): Promise<string>;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The per-request connection facts the server face injects — the ONLY data
|
|
221
|
+
* that genuinely exists solely on the socket, surfaced so middleware and a
|
|
222
|
+
* consumer's `state` factory stay core-pure.
|
|
223
|
+
*
|
|
224
|
+
* @remarks
|
|
225
|
+
* - `ip` — the socket peer address, for a spoof-proof rate-limit key. Never
|
|
226
|
+
* derived from `X-Forwarded-For` (a client-controlled header) — a
|
|
227
|
+
* deployment behind a trusted proxy derives its own client key explicitly.
|
|
228
|
+
* - `encrypted` — whether the connection is TLS, for an auto-`Secure` cookie
|
|
229
|
+
* decision ({@link CookieOptions.secure} left `undefined`).
|
|
230
|
+
*/
|
|
231
|
+
export declare interface ConnectionInfo {
|
|
232
|
+
readonly ip?: string;
|
|
233
|
+
readonly encrypted: boolean;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* The {@link HTTPError} thrown when a request body exceeds the body
|
|
238
|
+
* pipeline's size limit — a `413 Content Too Large`.
|
|
239
|
+
*
|
|
240
|
+
* @remarks
|
|
241
|
+
* Thrown by `readBody` (and the middleware context's cached `body()`) when
|
|
242
|
+
* the received bytes exceed the configured {@link
|
|
243
|
+
* import('./types.js').BodyOptions.limit}, carrying the `limit` in its
|
|
244
|
+
* `context`. The server's error boundary renders it as a 413.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```ts
|
|
248
|
+
* import { ContentTooLargeError, isHTTPError } from '@src/core'
|
|
249
|
+
*
|
|
250
|
+
* try {
|
|
251
|
+
* await readBody(request, { limit: 1024 })
|
|
252
|
+
* } catch (error) {
|
|
253
|
+
* if (isHTTPError(error)) console.log(error.status) // 413
|
|
254
|
+
* }
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
export declare class ContentTooLargeError extends HTTPError {
|
|
258
|
+
constructor(limit: number);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* The `Set-Cookie` attributes for `serializeCookie` (and any signed-cookie
|
|
263
|
+
* transport built over it).
|
|
264
|
+
*
|
|
265
|
+
* @param path - The `Path` directive; defaults to `'/'`.
|
|
266
|
+
* @param domain - The `Domain` directive; omitted ⇒ a host-only cookie.
|
|
267
|
+
* @param maxAge - The `Max-Age` directive in SECONDS (the wire unit, not a
|
|
268
|
+
* millisecond `ttl`); `0` expires the cookie immediately.
|
|
269
|
+
* @param httpOnly - The `HttpOnly` directive; defaults to `true`.
|
|
270
|
+
* @param secure - The `Secure` directive: `true` forces it, `false`
|
|
271
|
+
* suppresses it, and omitted/`undefined` (the default) derives it from the
|
|
272
|
+
* connection via {@link import('./helpers.js').resolveSecure} — `Secure` on
|
|
273
|
+
* a TLS connection, off over plaintext HTTP ({@link
|
|
274
|
+
* ConnectionInfo.encrypted}). A `sameSite: 'None'` cookie is ALWAYS
|
|
275
|
+
* `Secure` regardless (the spec requires it).
|
|
276
|
+
* @param sameSite - The `SameSite` directive; defaults to `'Lax'`.
|
|
277
|
+
*/
|
|
278
|
+
export declare interface CookieOptions {
|
|
279
|
+
readonly path?: string;
|
|
280
|
+
readonly domain?: string;
|
|
281
|
+
readonly maxAge?: number;
|
|
282
|
+
readonly httpOnly?: boolean;
|
|
283
|
+
readonly secure?: boolean;
|
|
284
|
+
readonly sameSite?: 'Strict' | 'Lax' | 'None';
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Create a {@link NegotiatorInterface} — the reusable content-negotiation
|
|
289
|
+
* machine over the weighted `Accept` family.
|
|
290
|
+
*
|
|
291
|
+
* @remarks
|
|
292
|
+
* Prefer this over `new Negotiator()` at call sites that only need the
|
|
293
|
+
* interface.
|
|
294
|
+
*
|
|
295
|
+
* @returns A {@link NegotiatorInterface}
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```ts
|
|
299
|
+
* import { createNegotiator } from '@src/core'
|
|
300
|
+
*
|
|
301
|
+
* const negotiator = createNegotiator()
|
|
302
|
+
* negotiator.negotiate('text/html, application/json;q=0.9', ['application/json', 'text/html'])
|
|
303
|
+
* // 'text/html'
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
export declare function createNegotiator(): NegotiatorInterface;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Decode a base64url string back into its bytes — the inverse of
|
|
310
|
+
* {@link encodeBase64Url}.
|
|
311
|
+
*
|
|
312
|
+
* @remarks
|
|
313
|
+
* Restores the standard base64 alphabet + padding before decoding with
|
|
314
|
+
* `atob`. THROWS `DOMException` on a malformed input — callers on the
|
|
315
|
+
* untrusted-token path (`verifyToken`) catch it to stay total (AGENTS §14).
|
|
316
|
+
*
|
|
317
|
+
* @param value - The base64url string to decode
|
|
318
|
+
* @returns The decoded bytes
|
|
319
|
+
* @throws {DOMException} When `value` is not valid base64url
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```ts
|
|
323
|
+
* new TextDecoder().decode(decodeBase64Url('aGk')) // 'hi'
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
326
|
+
export declare function decodeBase64Url(value: string): Uint8Array<ArrayBuffer>;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Decode a cookie value with `decodeURIComponent`, falling back to the raw
|
|
330
|
+
* text when the value is not valid percent-encoding.
|
|
331
|
+
*
|
|
332
|
+
* @param raw - The raw (trimmed) cookie value
|
|
333
|
+
* @returns The URL-decoded value, or the raw value when decoding would throw
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* ```ts
|
|
337
|
+
* decodeCookieValue('a%20b') // 'a b'
|
|
338
|
+
* decodeCookieValue('%') // '%' — malformed escape stays literal
|
|
339
|
+
* ```
|
|
340
|
+
*/
|
|
341
|
+
export declare function decodeCookieValue(raw: string): string;
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Decode + narrow a signed token's base64url JSON payload, honoring its
|
|
345
|
+
* expiry — the shared decode step {@link verifyToken} applies after a
|
|
346
|
+
* signature match.
|
|
347
|
+
*
|
|
348
|
+
* @remarks
|
|
349
|
+
* Decodes the base64url payload to UTF-8 JSON, narrows it to a record with a
|
|
350
|
+
* string `value` (AGENTS §14 — never `as`), and rejects an expired `exp`.
|
|
351
|
+
* TOTAL — any decode/shape/expiry failure yields `undefined`.
|
|
352
|
+
*
|
|
353
|
+
* @param encoded - The base64url-encoded payload segment (before the last `.`)
|
|
354
|
+
* @returns The embedded value when the payload is well-shaped + unexpired, else `undefined`
|
|
355
|
+
*/
|
|
356
|
+
export declare function decodeTokenPayload(encoded: string): string | undefined;
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Transparently decompress an already-collected, `gzip`/`deflate`-encoded
|
|
360
|
+
* byte sequence via `DecompressionStream`, capping the DECOMPRESSED output —
|
|
361
|
+
* the zip-bomb defense.
|
|
362
|
+
*
|
|
363
|
+
* @remarks
|
|
364
|
+
* Pipes `bytes` through `DecompressionStream(encoding)` and a byte-counting
|
|
365
|
+
* `TransformStream` that ABORTS the pipe the INSTANT the running decompressed
|
|
366
|
+
* total exceeds `cap` — fail-before-materialize, since `DecompressionStream`
|
|
367
|
+
* has no `maxOutputLength` knob (§3 of the proposal). A cap breach surfaces
|
|
368
|
+
* as a {@link ContentTooLargeError} (413); a genuinely corrupt/truncated
|
|
369
|
+
* compressed stream surfaces as a distinct `400`-mappable {@link HTTPError}
|
|
370
|
+
* (never conflated with the cap). A non-positive `cap` means uncapped.
|
|
371
|
+
*
|
|
372
|
+
* @param bytes - The compressed bytes to decompress
|
|
373
|
+
* @param encoding - The {@link Encoding} the bytes are compressed with
|
|
374
|
+
* @param cap - The maximum decompressed byte count; a non-positive value means uncapped
|
|
375
|
+
* @returns The decompressed bytes
|
|
376
|
+
* @throws {ContentTooLargeError} When decompressed output would exceed `cap`
|
|
377
|
+
* @throws {HTTPError} When the compressed stream is corrupt/truncated (400)
|
|
378
|
+
*/
|
|
379
|
+
export declare function decompressRequestBody(bytes: Uint8Array<ArrayBuffer>, encoding: Exclude<Encoding, 'identity'>, cap: number): Promise<Uint8Array<ArrayBuffer>>;
|
|
380
|
+
|
|
381
|
+
/** Default maximum request body size (bytes) `readBody` accepts before a 413. */
|
|
382
|
+
export declare const DEFAULT_BODY_LIMIT = 1048576;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Default maximum DECOMPRESSED request body size (bytes) — the zip-bomb cap
|
|
386
|
+
* the body pipeline's byte-counting `TransformStream` enforces when
|
|
387
|
+
* transparently decompressing a `Content-Encoding` request body.
|
|
388
|
+
*
|
|
389
|
+
* @remarks
|
|
390
|
+
* A small compressed payload (under {@link DEFAULT_BODY_LIMIT} on the wire)
|
|
391
|
+
* can inflate by many orders of magnitude — a classic decompression bomb.
|
|
392
|
+
* Capping the decompressed byte count makes the pipe ABORT the moment the
|
|
393
|
+
* output would exceed this, BEFORE the full bomb is materialized, so the
|
|
394
|
+
* inflation can never exhaust memory. Defaults to `16 MiB` — a generous
|
|
395
|
+
* ceiling for a legitimate compressed JSON / form body, far below an OOM. A
|
|
396
|
+
* consumer raises it via {@link import('./types.js').BodyOptions}
|
|
397
|
+
* `decompression` for a workload that genuinely ships larger decompressed
|
|
398
|
+
* bodies.
|
|
399
|
+
*/
|
|
400
|
+
export declare const DEFAULT_DECOMPRESSED_LIMIT = 16777216;
|
|
401
|
+
|
|
402
|
+
/** Default graceful-stop deadline (ms) the server gives in-flight requests on `stop()`. */
|
|
403
|
+
export declare const DEFAULT_DRAIN_MS = 10000;
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* The default {@link Encoding} content-codings the substrate offers, in
|
|
407
|
+
* PREFERENCE order — `gzip` / `deflate`.
|
|
408
|
+
*
|
|
409
|
+
* @remarks
|
|
410
|
+
* `identity` (no compression) is always implicitly acceptable and is NOT
|
|
411
|
+
* listed here — it is the fall-through when a client accepts none of these.
|
|
412
|
+
* Brotli is omitted per the core's `CompressionStream`-only decision (see
|
|
413
|
+
* {@link Encoding}). Frozen so a consumer can read but never mutate the
|
|
414
|
+
* shared default.
|
|
415
|
+
*/
|
|
416
|
+
export declare const DEFAULT_ENCODINGS: readonly Encoding[];
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Base64url-encode a byte sequence — the payload encoding {@link signToken} /
|
|
420
|
+
* {@link verifyToken} use, and the signature encoding for the HMAC.
|
|
421
|
+
*
|
|
422
|
+
* @param bytes - The bytes to encode
|
|
423
|
+
* @returns The base64url string (no padding)
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```ts
|
|
427
|
+
* encodeBase64Url(new TextEncoder().encode('hi')) // 'aGk'
|
|
428
|
+
* ```
|
|
429
|
+
*/
|
|
430
|
+
export declare function encodeBase64Url(bytes: Uint8Array): string;
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* A content-coding the substrate compresses / decompresses with — the
|
|
434
|
+
* `Content-Encoding` / `Accept-Encoding` token vocabulary it understands.
|
|
435
|
+
*
|
|
436
|
+
* @remarks
|
|
437
|
+
* `gzip` / `deflate` map to `CompressionStream` / `DecompressionStream`
|
|
438
|
+
* (web-standard, no external codec); `identity` is the no-op "uncompressed"
|
|
439
|
+
* coding. Brotli (`br`) has no `CompressionStream` implementation yet, so it
|
|
440
|
+
* is deliberately OMITTED here — Brotli parity is the future middleware
|
|
441
|
+
* package's node-entry decision (§3 of the proposal), not this core's. A
|
|
442
|
+
* constrained set of external-spec literals, so it stays a union, not a
|
|
443
|
+
* behavioral toggle (AGENTS §4.4).
|
|
444
|
+
*/
|
|
445
|
+
export declare type Encoding = 'gzip' | 'deflate' | 'identity';
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* A map of media type → handler for {@link NegotiatorInterface.format} — the
|
|
449
|
+
* content-negotiation dispatch table.
|
|
450
|
+
*
|
|
451
|
+
* @typeParam TState - The consumer's opaque per-request state type
|
|
452
|
+
*
|
|
453
|
+
* @remarks
|
|
454
|
+
* Each key is a media type the route can PRODUCE (`application/json`,
|
|
455
|
+
* `text/html`, …) and each value the responder that returns that
|
|
456
|
+
* representation as a `Response`. `format` negotiates the client's preferred
|
|
457
|
+
* key from the request `Accept` header and invokes the matching handler, or
|
|
458
|
+
* answers `406 Not Acceptable` when none of the offered types is acceptable.
|
|
459
|
+
* The keys are the `available` set negotiation chooses from, so their order
|
|
460
|
+
* is the server's tie-break preference (a client accepting the any-media-
|
|
461
|
+
* range gets the first key).
|
|
462
|
+
*/
|
|
463
|
+
export declare type FormatHandlerMap<TState> = Readonly<Record<string, (request: Request, context: MiddlewareContext<TState>) => Response | Promise<Response>>>;
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* The `Symbol.for`-keyed brand `HTTPError` carries so `isHTTPError` recognizes
|
|
467
|
+
* an instance thrown by ANOTHER copy of this package (the dual-package
|
|
468
|
+
* hazard — a version-skewed or workspace-linked duplicate install), where
|
|
469
|
+
* `instanceof` alone fails because the two copies' `HTTPError` constructors
|
|
470
|
+
* are distinct objects.
|
|
471
|
+
*
|
|
472
|
+
* @remarks
|
|
473
|
+
* `Symbol.for` interns the symbol on the GLOBAL symbol registry, so every
|
|
474
|
+
* copy of this package that evaluates this key resolves the SAME symbol
|
|
475
|
+
* instance — unlike a locally-scoped `Symbol()`, which would mint a fresh,
|
|
476
|
+
* unequal symbol per copy and defeat the whole point of a cross-copy brand.
|
|
477
|
+
*/
|
|
478
|
+
export declare const HTTP_ERROR_BRAND: unique symbol;
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* An error a handler (or middleware) throws to produce an HTTP response of a
|
|
482
|
+
* specific status.
|
|
483
|
+
*
|
|
484
|
+
* @remarks
|
|
485
|
+
* Carries the HTTP `status` to send and an optional `context` record (the
|
|
486
|
+
* offending field / value). The server's built-in error boundary catches it
|
|
487
|
+
* and renders a response of `status` with the error's `message` as the body
|
|
488
|
+
* — so an `HTTPError`'s message is ALWAYS client-facing (it is the handler's
|
|
489
|
+
* deliberate signal), unlike a generic throw whose message is hidden unless
|
|
490
|
+
* `expose` is set. Subclass it (as {@link ContentTooLargeError} does) for
|
|
491
|
+
* specific statuses, or throw it directly. Narrow a caught value with
|
|
492
|
+
* {@link isHTTPError}.
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* ```ts
|
|
496
|
+
* import { HTTPError } from '@src/core'
|
|
497
|
+
*
|
|
498
|
+
* const handler = async (request: Request): Promise<Response> => {
|
|
499
|
+
* const user = await find(new URL(request.url).searchParams.get('id'))
|
|
500
|
+
* if (user === undefined) throw new HTTPError(404, 'user not found')
|
|
501
|
+
* return Response.json(user)
|
|
502
|
+
* }
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
505
|
+
export declare class HTTPError extends Error {
|
|
506
|
+
readonly status: number;
|
|
507
|
+
readonly context?: Readonly<Record<string, unknown>>;
|
|
508
|
+
readonly [HTTP_ERROR_BRAND] = true;
|
|
509
|
+
constructor(status: number, message: string, context?: Readonly<Record<string, unknown>>);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Compute the `/64` network of a full IPv6 address, or `undefined` when the
|
|
514
|
+
* input is not a plain IPv6 address to collapse.
|
|
515
|
+
*
|
|
516
|
+
* @remarks
|
|
517
|
+
* Returns `undefined` for an IPv4-mapped `::ffff:a.b.c.d` (the embedded IPv4
|
|
518
|
+
* is the identity) or any string that does not expand to exactly eight
|
|
519
|
+
* hextets. Expands a single `::` into the missing zero hextets, takes the
|
|
520
|
+
* first FOUR (the `/64` prefix), normalizes each (lower-case, no leading
|
|
521
|
+
* zeros), and joins with a trailing `::/64`. A zone id (`%eth0`) is stripped
|
|
522
|
+
* first. Total — a malformed address returns `undefined`.
|
|
523
|
+
*
|
|
524
|
+
* @param address - The candidate IPv6 address
|
|
525
|
+
* @returns The `/64` network string, or `undefined` when not a plain IPv6 address
|
|
526
|
+
*
|
|
527
|
+
* @example
|
|
528
|
+
* ```ts
|
|
529
|
+
* ipv6Network('2001:db8:1:2::1') // '2001:db8:1:2::/64'
|
|
530
|
+
* ipv6Network('192.0.2.1') // undefined — IPv4, not collapsed
|
|
531
|
+
* ```
|
|
532
|
+
*/
|
|
533
|
+
export declare function ipv6Network(address: string): string | undefined;
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Whether a `Content-Type` is worth compressing.
|
|
537
|
+
*
|
|
538
|
+
* @remarks
|
|
539
|
+
* Strips any `; charset=…` parameter (lower-cased), then accepts a `text/*`
|
|
540
|
+
* type, a `+json`/`+xml` structured suffix, or one of the explicit
|
|
541
|
+
* {@link import('./constants.js').COMPRESSIBLE_TYPES}. An already-compressed
|
|
542
|
+
* binary (`image/png`, `application/zip`) is NOT compressible. An
|
|
543
|
+
* absent/empty type is not compressible. TOTAL.
|
|
544
|
+
*
|
|
545
|
+
* @param type - The response `Content-Type` header value (with or without parameters)
|
|
546
|
+
* @returns `true` when the type is text-shaped and worth compressing
|
|
547
|
+
*
|
|
548
|
+
* @example
|
|
549
|
+
* ```ts
|
|
550
|
+
* isCompressibleType('application/json; charset=utf-8') // true
|
|
551
|
+
* isCompressibleType('image/png') // false
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
export declare function isCompressibleType(type: string): boolean;
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Whether a string is safe to interpolate as a `Set-Cookie` attribute VALUE
|
|
558
|
+
* (a `Domain` / `Path`) — the guard {@link serializeCookie} screens those two
|
|
559
|
+
* attributes with before emitting them.
|
|
560
|
+
*
|
|
561
|
+
* @remarks
|
|
562
|
+
* Rejects a value carrying a `;` (splits attributes), a `,` (can split a
|
|
563
|
+
* folded header), ASCII/Unicode whitespace, or a C0/DEL control char
|
|
564
|
+
* (`< 0x20` or `0x7f`) — the chars that could inject another `Set-Cookie`
|
|
565
|
+
* directive. Total — never throws (a bad value returns `false`).
|
|
566
|
+
*
|
|
567
|
+
* @param value - The candidate attribute value (a `Domain` or `Path`)
|
|
568
|
+
* @returns `true` when `value` carries no separator / whitespace / control char
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```ts
|
|
572
|
+
* isCookieAttribute('/app') // true
|
|
573
|
+
* isCookieAttribute('/a\r\nSet-Cookie: x=y') // false
|
|
574
|
+
* ```
|
|
575
|
+
*/
|
|
576
|
+
export declare function isCookieAttribute(value: string): boolean;
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Whether a string is a valid RFC 6265 cookie NAME — a non-empty run of
|
|
580
|
+
* cookie-token chars with NO surrounding (or interior) whitespace.
|
|
581
|
+
*
|
|
582
|
+
* @remarks
|
|
583
|
+
* A cookie name is an RFC 7230 `token`: `^[!#$%&'*+\-.0-9A-Z^_`a-z|~]+$` —
|
|
584
|
+
* which excludes every whitespace char (ASCII and Unicode) plus controls,
|
|
585
|
+
* separators, and `=`. The {@link parseCookies} hardening that stops a
|
|
586
|
+
* `' __Host-x'` from reconciling into `__Host-x`. Total — never throws.
|
|
587
|
+
*
|
|
588
|
+
* @param value - The candidate cookie name
|
|
589
|
+
* @returns `true` when `value` is a valid, whitespace-free cookie token
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```ts
|
|
593
|
+
* isCookieName('__Host-session') // true
|
|
594
|
+
* isCookieName(' __Host-session') // false — whitespace-padded
|
|
595
|
+
* ```
|
|
596
|
+
*/
|
|
597
|
+
export declare function isCookieName(value: string): boolean;
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Whether a key is a PROTOTYPE-POLLUTION vector — `__proto__`, `constructor`,
|
|
601
|
+
* or `prototype` — the three keys that, assigned onto a normal object, can
|
|
602
|
+
* reach and mutate `Object.prototype`.
|
|
603
|
+
*
|
|
604
|
+
* @param key - The candidate object key
|
|
605
|
+
* @returns `true` when `key` is one of the three prototype-pollution keys
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
* ```ts
|
|
609
|
+
* isDangerousKey('__proto__') // true
|
|
610
|
+
* isDangerousKey('name') // false
|
|
611
|
+
* ```
|
|
612
|
+
*/
|
|
613
|
+
export declare function isDangerousKey(key: string): boolean;
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Narrow an unknown caught value to an {@link HTTPError} (including its
|
|
617
|
+
* subclasses, e.g. {@link ContentTooLargeError}).
|
|
618
|
+
*
|
|
619
|
+
* @param value - The value to test (typically a `catch` binding)
|
|
620
|
+
* @returns `true` when `value` is an {@link HTTPError}
|
|
621
|
+
*
|
|
622
|
+
* @remarks
|
|
623
|
+
* Tries `instanceof` first, then falls back to a total structural check for
|
|
624
|
+
* an instance built by a DIFFERENT copy of this package (the dual-package
|
|
625
|
+
* hazard — version skew, a linked workspace duplicate) whose `HTTPError`
|
|
626
|
+
* constructor is a distinct object from this copy's: the value must carry
|
|
627
|
+
* the cross-copy brand (interned via `Symbol.for`, so every copy resolves the
|
|
628
|
+
* same key) AND expose the exact fields the server's error boundary reads off
|
|
629
|
+
* a recognized `HTTPError` — a numeric `status` and a string `message`. A
|
|
630
|
+
* plain object that merely carries a `status` WITHOUT the brand is rejected.
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* ```ts
|
|
634
|
+
* import { isHTTPError } from '@src/core'
|
|
635
|
+
*
|
|
636
|
+
* try {
|
|
637
|
+
* await handle(request)
|
|
638
|
+
* } catch (error) {
|
|
639
|
+
* if (isHTTPError(error)) console.log(error.status, error.message)
|
|
640
|
+
* }
|
|
641
|
+
* ```
|
|
642
|
+
*/
|
|
643
|
+
export declare function isHTTPError(value: unknown): value is HTTPError;
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Whether a client-supplied `X-Request-ID` is SAFE to echo into a response
|
|
647
|
+
* header + `context.state`.
|
|
648
|
+
*
|
|
649
|
+
* @remarks
|
|
650
|
+
* A request id is echoed RAW into a response header and log lines, so an
|
|
651
|
+
* untrusted one is a header-injection + log-injection + DoS vector. This
|
|
652
|
+
* refuses anything off {@link import('./constants.js').REQUEST_ID_PATTERN}
|
|
653
|
+
* (`^[A-Za-z0-9_-]{1,200}$` — no whitespace, no control chars, no CR/LF).
|
|
654
|
+
* TOTAL — never throws.
|
|
655
|
+
*
|
|
656
|
+
* @param value - The candidate incoming request id
|
|
657
|
+
* @returns `true` when `value` is a safe, bounded, charset-clean correlation id
|
|
658
|
+
*
|
|
659
|
+
* @example
|
|
660
|
+
* ```ts
|
|
661
|
+
* isValidRequestId('req_abc-123') // true
|
|
662
|
+
* isValidRequestId('bad\r\nheader') // false
|
|
663
|
+
* ```
|
|
664
|
+
*/
|
|
665
|
+
export declare function isValidRequestId(value: string): boolean;
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* The client's quality for one `candidate` language from the parsed
|
|
669
|
+
* `Accept-Language` entries — backs the `Negotiator`'s `language` axis.
|
|
670
|
+
*
|
|
671
|
+
* @remarks
|
|
672
|
+
* Prefers an exact match, then a primary-tag prefix match (`en` accepts
|
|
673
|
+
* `en-US`), then the `*` wildcard; `0` when nothing matches (a `;q=0` entry
|
|
674
|
+
* is an explicit rejection).
|
|
675
|
+
*
|
|
676
|
+
* @param entries - The parsed {@link AcceptEntry} list
|
|
677
|
+
* @param candidate - The candidate language tag to score (e.g. `'en-US'`)
|
|
678
|
+
* @returns The client's quality for `candidate` in `[0, 1]` (`0` ⇒ not acceptable)
|
|
679
|
+
*
|
|
680
|
+
* @example
|
|
681
|
+
* ```ts
|
|
682
|
+
* languageQuality(parseAcceptHeader('en-US, en;q=0.8'), 'en-US') // 1
|
|
683
|
+
* languageQuality(parseAcceptHeader('en;q=0.8'), 'en-US') // 0.8 — primary-tag prefix
|
|
684
|
+
* languageQuality(parseAcceptHeader('*;q=0.5'), 'fr') // 0.5 — wildcard
|
|
685
|
+
* ```
|
|
686
|
+
*/
|
|
687
|
+
export declare function languageQuality(entries: readonly AcceptEntry[], candidate: string): number;
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Whether a request's `If-None-Match` header matches a resource's current
|
|
691
|
+
* `ETag` — the RFC 7232 §2.3.2 WEAK comparison.
|
|
692
|
+
*
|
|
693
|
+
* @remarks
|
|
694
|
+
* `If-None-Match` is a COMMA-separated LIST of entity-tags (matches if ANY
|
|
695
|
+
* listed tag matches), or the `*` wildcard (matches ANY current
|
|
696
|
+
* representation — only a list of exactly `*` is the wildcard). Comparison is
|
|
697
|
+
* WEAK: `W/"abc"` and `"abc"` are equal (both sides' weak prefix is stripped
|
|
698
|
+
* via {@link unwrapETag} before comparing the opaque body). TOTAL — a
|
|
699
|
+
* malformed/empty header matches nothing, never throws.
|
|
700
|
+
*
|
|
701
|
+
* @param header - The raw `If-None-Match` header value
|
|
702
|
+
* @param etag - The resource's current `ETag`
|
|
703
|
+
* @returns `true` when the conditional matches (the caller answers `304`)
|
|
704
|
+
*
|
|
705
|
+
* @example
|
|
706
|
+
* ```ts
|
|
707
|
+
* matchesETag('"abc", W/"def"', 'W/"abc"') // true — weak comparison
|
|
708
|
+
* matchesETag('*', 'W/"anything"') // true — wildcard
|
|
709
|
+
* ```
|
|
710
|
+
*/
|
|
711
|
+
export declare function matchesETag(header: string, etag: string): boolean;
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Rank + quality of one `candidate` media type against the parsed `Accept`
|
|
715
|
+
* entries — the generic media-type primitive the `Negotiator`'s `negotiate`
|
|
716
|
+
* uses to score each `available` candidate.
|
|
717
|
+
*
|
|
718
|
+
* @remarks
|
|
719
|
+
* An exact match ranks `0`, a subtype wildcard (`type/*`) ranks `1`, the
|
|
720
|
+
* any-range (`* / *`) ranks `2`; `undefined` when nothing matches. An exact
|
|
721
|
+
* `;q=0` entry explicitly rejects the candidate outright (returns
|
|
722
|
+
* `undefined` immediately); a wildcard `;q=0` only rejects the wildcard's own
|
|
723
|
+
* (less specific) coverage, so a later more-specific match can still allow
|
|
724
|
+
* it. Among multiple matching entries, the lowest `rank` wins, and among a
|
|
725
|
+
* rank tie the highest `q` wins.
|
|
726
|
+
*
|
|
727
|
+
* @param entries - The parsed {@link AcceptEntry} list
|
|
728
|
+
* @param candidate - The candidate media type to score (e.g. `'text/html'`)
|
|
729
|
+
* @returns The `{ q, rank }` of the best matching entry, or `undefined` when nothing matches
|
|
730
|
+
*
|
|
731
|
+
* @example
|
|
732
|
+
* ```ts
|
|
733
|
+
* matchMediaType(parseAcceptHeader('text/html, application/json;q=0.9'), 'text/html')
|
|
734
|
+
* // { q: 1, rank: 0 }
|
|
735
|
+
* matchMediaType(parseAcceptHeader('text/*;q=0.8'), 'text/plain') // { q: 0.8, rank: 1 }
|
|
736
|
+
* matchMediaType(parseAcceptHeader('text/html;q=0'), 'text/html') // undefined
|
|
737
|
+
* ```
|
|
738
|
+
*/
|
|
739
|
+
export declare function matchMediaType(entries: readonly AcceptEntry[], candidate: string): {
|
|
740
|
+
readonly q: number;
|
|
741
|
+
readonly rank: number;
|
|
742
|
+
} | undefined;
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Merge a `Vary` value into an existing `Vary` header without duplication.
|
|
746
|
+
*
|
|
747
|
+
* @remarks
|
|
748
|
+
* Splits `existing` on `,`, trims each member, and appends `value` only when
|
|
749
|
+
* no existing member already matches it case-insensitively (`Vary` header
|
|
750
|
+
* names are case-insensitive). Preserves the existing members' order and
|
|
751
|
+
* appends the new one last.
|
|
752
|
+
*
|
|
753
|
+
* @param existing - The current `Vary` header value, if any
|
|
754
|
+
* @param value - The header name to ensure is listed
|
|
755
|
+
* @returns The merged `Vary` value
|
|
756
|
+
*
|
|
757
|
+
* @example
|
|
758
|
+
* ```ts
|
|
759
|
+
* mergeVary(undefined, 'Origin') // 'Origin'
|
|
760
|
+
* mergeVary('Origin', 'origin') // 'Origin' — no duplicate (case-insensitive)
|
|
761
|
+
* mergeVary('Accept-Encoding', 'Origin') // 'Accept-Encoding, Origin'
|
|
762
|
+
* ```
|
|
763
|
+
*/
|
|
764
|
+
export declare function mergeVary(existing: string | undefined, value: string): string;
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* The composition context — plain data, one per request, shared by every
|
|
768
|
+
* middleware AND (as `state`) by the route handlers behind the dispatcher.
|
|
769
|
+
*
|
|
770
|
+
* @typeParam TState - The consumer's opaque per-request state type
|
|
771
|
+
*
|
|
772
|
+
* @remarks
|
|
773
|
+
* - `url` — the parsed request {@link URL} (mirrors the router's own parse, so
|
|
774
|
+
* a middleware never re-parses it).
|
|
775
|
+
* - `method` — the raw request verb; the dispatcher (not this seam) narrows it
|
|
776
|
+
* to a known {@link import('@orkestrel/router').Method}.
|
|
777
|
+
* - `state` — THE shared bag threaded from the adapter's `state` factory,
|
|
778
|
+
* through every middleware, into `dispatcher.handle`'s `state` — the same
|
|
779
|
+
* object a route handler reads as `context.state`.
|
|
780
|
+
* - `body()` — lazily collect the request body (byte-limited, transparently
|
|
781
|
+
* decompressed, prototype-scrubbed for JSON), cached so repeated calls (a
|
|
782
|
+
* body-parsing middleware, then the handler) read the underlying stream
|
|
783
|
+
* exactly once.
|
|
784
|
+
*
|
|
785
|
+
* @example
|
|
786
|
+
* ```ts
|
|
787
|
+
* const middleware: MiddlewareHandler<{ readonly userId?: string }> = async (request, context, next) => {
|
|
788
|
+
* const body = await context.body()
|
|
789
|
+
* return next(request)
|
|
790
|
+
* }
|
|
791
|
+
* ```
|
|
792
|
+
*/
|
|
793
|
+
export declare interface MiddlewareContext<TState> {
|
|
794
|
+
readonly url: URL;
|
|
795
|
+
readonly method: string;
|
|
796
|
+
readonly state: TState;
|
|
797
|
+
body(): Promise<unknown>;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* One link in the middleware onion — runs around the rest of the chain.
|
|
802
|
+
*
|
|
803
|
+
* @typeParam TState - The consumer's opaque per-request state type
|
|
804
|
+
*
|
|
805
|
+
* @remarks
|
|
806
|
+
* Transform the request (call `next(newRequest)`), transform the response
|
|
807
|
+
* (`await next()` then modify the result), short-circuit (return a `Response`
|
|
808
|
+
* without calling `next`), or thread data via `context.state` — no mutable
|
|
809
|
+
* framework object anywhere, only fetch-standard `Request`/`Response`.
|
|
810
|
+
*
|
|
811
|
+
* @example
|
|
812
|
+
* ```ts
|
|
813
|
+
* const withRequestId: MiddlewareHandler<{ readonly requestId: string }> = async (request, context, next) => {
|
|
814
|
+
* const response = await next()
|
|
815
|
+
* response.headers.set('X-Request-ID', context.state.requestId)
|
|
816
|
+
* return response
|
|
817
|
+
* }
|
|
818
|
+
* ```
|
|
819
|
+
*/
|
|
820
|
+
export declare type MiddlewareHandler<TState> = (request: Request, context: MiddlewareContext<TState>, next: NextFunction) => Response | Promise<Response>;
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Select the best content-coding for an `Accept-Encoding` header from the
|
|
824
|
+
* codings the server offers.
|
|
825
|
+
*
|
|
826
|
+
* @remarks
|
|
827
|
+
* Parses the header ({@link parseAcceptHeader}) and scores each `available`
|
|
828
|
+
* coding in the SERVER's preference order ({@link codingQuality}), keeping
|
|
829
|
+
* the highest-scoring one (a strict `>` keeps the earlier-offered coding on a
|
|
830
|
+
* client-side tie). Returns `undefined` when the client accepts none of
|
|
831
|
+
* `available` (identity — no compression). TOTAL on hostile input.
|
|
832
|
+
*
|
|
833
|
+
* @typeParam T - The coding string type (so a `readonly Encoding[]` returns an `Encoding`)
|
|
834
|
+
* @param header - The raw `Accept-Encoding` header value
|
|
835
|
+
* @param available - The codings the server offers, in preference (tie-break) order
|
|
836
|
+
* @returns The negotiated coding, or `undefined` when none of `available` is acceptable
|
|
837
|
+
*
|
|
838
|
+
* @example
|
|
839
|
+
* ```ts
|
|
840
|
+
* negotiateEncoding('gzip;q=1.0, deflate;q=0.8', ['gzip', 'deflate']) // 'gzip'
|
|
841
|
+
* ```
|
|
842
|
+
*/
|
|
843
|
+
export declare function negotiateEncoding<T extends string>(header: string, available: readonly T[]): T | undefined;
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* The content-negotiation machine over the weighted `Accept` family — a
|
|
847
|
+
* reusable, cross-middleware ENTITY (not a middleware). Implements exactly
|
|
848
|
+
* {@link NegotiatorInterface}.
|
|
849
|
+
*
|
|
850
|
+
* @remarks
|
|
851
|
+
* `negotiate` is the generic media-type primitive (exact / subtype-wildcard /
|
|
852
|
+
* any-range, q-sorted, `;q=0` rejected); `encoding` / `language` are its
|
|
853
|
+
* sibling axes and REUSE the same {@link parseAcceptHeader} q-value parser the
|
|
854
|
+
* rest of the substrate uses — one parser, never two. `format` reads the
|
|
855
|
+
* request `Accept`, negotiates a {@link FormatHandlerMap}'s keys, and invokes
|
|
856
|
+
* the winner — or answers `406 Not Acceptable`.
|
|
857
|
+
*
|
|
858
|
+
* @example
|
|
859
|
+
* ```ts
|
|
860
|
+
* const negotiator = new Negotiator()
|
|
861
|
+
* negotiator.negotiate('text/html, application/json;q=0.9', ['application/json', 'text/html'])
|
|
862
|
+
* // 'text/html'
|
|
863
|
+
* ```
|
|
864
|
+
*/
|
|
865
|
+
export declare class Negotiator implements NegotiatorInterface {
|
|
866
|
+
negotiate(header: string, available: readonly string[]): string | undefined;
|
|
867
|
+
encoding(header: string, available: readonly Encoding[]): Encoding | undefined;
|
|
868
|
+
language(header: string, available: readonly string[]): string | undefined;
|
|
869
|
+
/**
|
|
870
|
+
* @remarks
|
|
871
|
+
* Errors thrown by the negotiated handler propagate UNMODIFIED — the
|
|
872
|
+
* server boundary classifies them, never this negotiator.
|
|
873
|
+
*/
|
|
874
|
+
format<TState>(request: Request, context: MiddlewareContext<TState>, handlers: FormatHandlerMap<TState>): Promise<Response>;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* Content negotiation over the weighted `Accept` family — a reusable,
|
|
879
|
+
* cross-middleware machine (not itself a middleware).
|
|
880
|
+
*
|
|
881
|
+
* @remarks
|
|
882
|
+
* Parses a weighted `Accept` / `Accept-Encoding` / `Accept-Language` header
|
|
883
|
+
* (q-values honored, `*` wildcards honored, a `;q=0` rejection respected) and
|
|
884
|
+
* picks the client's most-preferred value the server also offers. `negotiate`
|
|
885
|
+
* is the generic primitive (media types); `encoding` / `language` are its
|
|
886
|
+
* sibling axes. `format` is the dispatcher — it reads the request `Accept`,
|
|
887
|
+
* negotiates against a {@link FormatHandlerMap}'s keys, and invokes the
|
|
888
|
+
* winning handler, resolving `406 Not Acceptable` when none is acceptable.
|
|
889
|
+
*
|
|
890
|
+
* @example
|
|
891
|
+
* ```ts
|
|
892
|
+
* const response = await negotiator.format(request, context, {
|
|
893
|
+
* 'application/json': (request, context) => Response.json({ ok: true }),
|
|
894
|
+
* 'text/html': (request, context) => new Response('<p>ok</p>', { headers: { 'Content-Type': 'text/html' } }),
|
|
895
|
+
* })
|
|
896
|
+
* ```
|
|
897
|
+
*/
|
|
898
|
+
export declare interface NegotiatorInterface {
|
|
899
|
+
/**
|
|
900
|
+
* Pick the best `available` value for a weighted `Accept`-style `header` —
|
|
901
|
+
* the generic media-type primitive (`encoding` / `language` build on it).
|
|
902
|
+
*
|
|
903
|
+
* @param header - The raw weighted header value (e.g. `text/html, application/json;q=0.9`)
|
|
904
|
+
* @param available - The values the server can produce, in preference (tie-break) order
|
|
905
|
+
* @returns The best acceptable value, or `undefined` when none is
|
|
906
|
+
*/
|
|
907
|
+
negotiate(header: string, available: readonly string[]): string | undefined;
|
|
908
|
+
/**
|
|
909
|
+
* Pick the best `available` content-coding for an `Accept-Encoding` header
|
|
910
|
+
* — `negotiate` scoped to codings (a bare `*` wildcard ⇒ the first `available`).
|
|
911
|
+
*
|
|
912
|
+
* @param header - The raw `Accept-Encoding` header value (e.g. `gzip;q=1.0, deflate;q=0.8`)
|
|
913
|
+
* @param available - The codings the server offers, in preference order
|
|
914
|
+
* @returns The best acceptable coding, or `undefined` when none is
|
|
915
|
+
*/
|
|
916
|
+
encoding(header: string, available: readonly Encoding[]): Encoding | undefined;
|
|
917
|
+
/**
|
|
918
|
+
* Pick the best `available` language for an `Accept-Language` header —
|
|
919
|
+
* `negotiate` with a language-prefix match (`en` accepts `en-US`) and a
|
|
920
|
+
* bare `*` wildcard.
|
|
921
|
+
*
|
|
922
|
+
* @param header - The raw `Accept-Language` header value (e.g. `en-US, en;q=0.8, fr;q=0.5`)
|
|
923
|
+
* @param available - The languages the server offers, in preference order
|
|
924
|
+
* @returns The best acceptable language, or `undefined` when none is
|
|
925
|
+
*/
|
|
926
|
+
language(header: string, available: readonly string[]): string | undefined;
|
|
927
|
+
/**
|
|
928
|
+
* Dispatch to the handler whose media type the client most prefers — read
|
|
929
|
+
* the request `Accept`, negotiate against `handlers`' keys, and invoke the
|
|
930
|
+
* winner; `406` when none is acceptable.
|
|
931
|
+
*
|
|
932
|
+
* @typeParam TState - The consumer's opaque per-request state type
|
|
933
|
+
* @param request - The in-flight `Request`
|
|
934
|
+
* @param context - The request's {@link MiddlewareContext}
|
|
935
|
+
* @param handlers - The media type → responder {@link FormatHandlerMap} the route offers
|
|
936
|
+
* @returns The winning handler's `Response`, or a `406 Not Acceptable` `Response`
|
|
937
|
+
*/
|
|
938
|
+
format<TState>(request: Request, context: MiddlewareContext<TState>, handlers: FormatHandlerMap<TState>): Promise<Response>;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* The downstream continuation a {@link MiddlewareHandler} invokes to run the
|
|
943
|
+
* rest of the onion.
|
|
944
|
+
*
|
|
945
|
+
* @remarks
|
|
946
|
+
* Call it (optionally with a substituted `Request`) to run the downstream
|
|
947
|
+
* chain and receive its `Response`; omit the call entirely to short-circuit
|
|
948
|
+
* with a `Response` built by this middleware instead. A SECOND call rejects
|
|
949
|
+
* (the double-`next` guard) — each middleware runs the chain at most once.
|
|
950
|
+
*
|
|
951
|
+
* @param request - An optional replacement `Request` to hand downstream
|
|
952
|
+
* (omitted ⇒ the original request continues)
|
|
953
|
+
* @returns The downstream chain's resolved `Response`
|
|
954
|
+
*/
|
|
955
|
+
export declare type NextFunction = (request?: Request) => Promise<Response>;
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* Normalize a {@link TokenSecret} to a concrete list of USABLE secrets —
|
|
959
|
+
* backs both {@link signToken} and {@link verifyToken}.
|
|
960
|
+
*
|
|
961
|
+
* @remarks
|
|
962
|
+
* A single string becomes a one-element list; a rotation list is copied. Any
|
|
963
|
+
* blank/whitespace-only entry is DROPPED (`.trim()` is used only for that
|
|
964
|
+
* emptiness test; each kept secret is stored VERBATIM). The first kept
|
|
965
|
+
* element is the signing secret; all kept are accepted on verify.
|
|
966
|
+
*
|
|
967
|
+
* @param secret - The {@link TokenSecret} (a single string, or a rotation list)
|
|
968
|
+
* @returns The kept (non-blank) secrets, in order — empty when none is usable
|
|
969
|
+
*
|
|
970
|
+
* @example
|
|
971
|
+
* ```ts
|
|
972
|
+
* normalizeSecret(['new', '', ' ', 'old']) // ['new', 'old']
|
|
973
|
+
* ```
|
|
974
|
+
*/
|
|
975
|
+
export declare function normalizeSecret(secret: TokenSecret): readonly string[];
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* Open a generic Server-Sent-Events stream — a fetch-standard `Response`
|
|
979
|
+
* whose body is a `ReadableStream` a caller writes {@link SSEMessage}s into.
|
|
980
|
+
*
|
|
981
|
+
* @remarks
|
|
982
|
+
* Builds the `Response` immediately with {@link import('./constants.js').SSE_HEADERS}
|
|
983
|
+
* merged under any `options.headers` (a seam-owned key is never overridden),
|
|
984
|
+
* at `options.status` (default `200`). The returned {@link StreamInterface}'s
|
|
985
|
+
* `write` serializes one message ({@link serializeEvent}) and enqueues it;
|
|
986
|
+
* `comment` writes a `: text` keep-alive line a conforming parser ignores;
|
|
987
|
+
* `end` closes the stream. Every method is a SAFE NO-OP once `closed` (ended
|
|
988
|
+
* by `end()`, or the consumer cancelled the stream), so a late write never
|
|
989
|
+
* throws.
|
|
990
|
+
*
|
|
991
|
+
* @param options - Optional `status` + extra `headers`; see {@link StreamOptions}
|
|
992
|
+
* @returns The {@link StreamInterface} handle
|
|
993
|
+
*
|
|
994
|
+
* @example
|
|
995
|
+
* ```ts
|
|
996
|
+
* const stream = openStream()
|
|
997
|
+
* stream.write({ event: 'token', data: 'hello' })
|
|
998
|
+
* stream.end()
|
|
999
|
+
* // return stream.response from the route handler
|
|
1000
|
+
* ```
|
|
1001
|
+
*/
|
|
1002
|
+
export declare function openStream(options?: StreamOptions): StreamInterface;
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* Parse a weighted `Accept` / `Accept-Encoding` / `Accept-Language` header
|
|
1006
|
+
* into its q-sorted entries.
|
|
1007
|
+
*
|
|
1008
|
+
* @remarks
|
|
1009
|
+
* Splits on `,`; for each part takes the token before the first `;`
|
|
1010
|
+
* (lower-cased + trimmed) as `value`, and reads a `;q=<n>` parameter as the
|
|
1011
|
+
* quality (default `1`, clamped to `[0, 1]`; a non-finite/malformed `q` falls
|
|
1012
|
+
* back to `1`). A `;q=0` entry is KEPT (an explicit rejection a caller must
|
|
1013
|
+
* honor). The result is sorted by `q` DESCENDING, a STABLE sort preserving
|
|
1014
|
+
* the header's own order within a tie — a single pass with no backtracking,
|
|
1015
|
+
* so parsing stays linear in the header length (ReDoS-safe). TOTAL — an
|
|
1016
|
+
* empty/malformed header yields `[]`/best-effort entries, never throws.
|
|
1017
|
+
*
|
|
1018
|
+
* @param header - The raw weighted header value
|
|
1019
|
+
* @returns The parsed {@link AcceptEntry} list, sorted by `q` descending
|
|
1020
|
+
*
|
|
1021
|
+
* @example
|
|
1022
|
+
* ```ts
|
|
1023
|
+
* parseAcceptHeader('br;q=1.0, gzip;q=0.8, identity;q=0')
|
|
1024
|
+
* // [{ value: 'br', q: 1 }, { value: 'gzip', q: 0.8 }, { value: 'identity', q: 0 }]
|
|
1025
|
+
* ```
|
|
1026
|
+
*/
|
|
1027
|
+
export declare function parseAcceptHeader(header: string): readonly AcceptEntry[];
|
|
1028
|
+
|
|
1029
|
+
/**
|
|
1030
|
+
* Parse a raw `Cookie:` request header into a `name → value` lookup.
|
|
1031
|
+
*
|
|
1032
|
+
* @remarks
|
|
1033
|
+
* Splits on `;`; the FIRST segment keeps any leading whitespace (a genuine
|
|
1034
|
+
* cookie-pair separator never precedes it), while every later segment has its
|
|
1035
|
+
* inter-pair separator (ASCII space/tab) stripped before parsing — so a
|
|
1036
|
+
* whitespace-PADDED name (`' __Host-x=evil'`) is rejected by
|
|
1037
|
+
* {@link isCookieName} rather than silently reconciling into a
|
|
1038
|
+
* prefix-protected `__Host-` name. A pair without `=`, or with an invalid
|
|
1039
|
+
* name, is skipped; a later duplicate name wins. TOTAL — an absent/empty/
|
|
1040
|
+
* malformed header yields an empty record, never throws (AGENTS §14).
|
|
1041
|
+
*
|
|
1042
|
+
* @param header - The raw `Cookie` header value (possibly `undefined`)
|
|
1043
|
+
* @returns A record of every parsed cookie, `name → decoded value`
|
|
1044
|
+
*
|
|
1045
|
+
* @example
|
|
1046
|
+
* ```ts
|
|
1047
|
+
* parseCookies('session=abc; theme=dark') // { session: 'abc', theme: 'dark' }
|
|
1048
|
+
* ```
|
|
1049
|
+
*/
|
|
1050
|
+
export declare function parseCookies(header: string | undefined): Record<string, string>;
|
|
1051
|
+
|
|
1052
|
+
/**
|
|
1053
|
+
* Parse an HTTP `Range` request header against a known resource `size` —
|
|
1054
|
+
* TOTAL, returning a {@link RangeSpec} or `undefined`.
|
|
1055
|
+
*
|
|
1056
|
+
* @remarks
|
|
1057
|
+
* Handles the three single-range `bytes=` forms — closed (`start-end`), open
|
|
1058
|
+
* (`start-`), and suffix (`-suffixLength`) — clamping the window to
|
|
1059
|
+
* `[0, size - 1]` (the HTTP INCLUSIVE-end convention). Returns
|
|
1060
|
+
* `{ satisfiable: true, start, end }` for an overlapping range,
|
|
1061
|
+
* `{ satisfiable: false }` for a range wholly past the resource, and
|
|
1062
|
+
* `undefined` for the "serve the whole resource" case: an ABSENT header, a
|
|
1063
|
+
* non-`bytes` unit, a MULTI-range header (`a-b, c-d` — refused outright, not
|
|
1064
|
+
* supported), or any malformed/non-finite bound. NEVER throws on a hostile
|
|
1065
|
+
* header.
|
|
1066
|
+
*
|
|
1067
|
+
* @param header - The raw `Range` header value
|
|
1068
|
+
* @param size - The resource's total byte length
|
|
1069
|
+
* @returns The {@link RangeSpec}, or `undefined` to serve the whole resource
|
|
1070
|
+
*
|
|
1071
|
+
* @example
|
|
1072
|
+
* ```ts
|
|
1073
|
+
* parseRange('bytes=0-99', 1000) // { satisfiable: true, start: 0, end: 99 }
|
|
1074
|
+
* parseRange('bytes=0-1, 2-3', 1000) // undefined — multi-range refused
|
|
1075
|
+
* ```
|
|
1076
|
+
*/
|
|
1077
|
+
export declare function parseRange(header: string | undefined, size: number): RangeSpec | undefined;
|
|
1078
|
+
|
|
1079
|
+
/**
|
|
1080
|
+
* The parsed outcome of an HTTP `Range` request header.
|
|
1081
|
+
*
|
|
1082
|
+
* @remarks
|
|
1083
|
+
* A `Range: bytes=start-end` against a known resource `size` resolves to ONE
|
|
1084
|
+
* of two shapes, discriminated by `satisfiable` (the axis is whether the
|
|
1085
|
+
* requested span overlaps the resource):
|
|
1086
|
+
*
|
|
1087
|
+
* - **`satisfiable: true`** — a concrete, clamped byte window `[start, end]`
|
|
1088
|
+
* (INCLUSIVE, the HTTP wire convention), normalized from the header's
|
|
1089
|
+
* open / suffix / closed forms against `size`.
|
|
1090
|
+
* - **`satisfiable: false`** — the range lies wholly outside the resource.
|
|
1091
|
+
*
|
|
1092
|
+
* `parseRange` returns `undefined` for an ABSENT / unparseable / multi-range
|
|
1093
|
+
* / non-`bytes` header — the "no range, serve the whole resource" case — so
|
|
1094
|
+
* the three outcomes (full / partial / unsatisfiable) are distinguished
|
|
1095
|
+
* without a separate flag. It is TOTAL — a hostile header never throws.
|
|
1096
|
+
*/
|
|
1097
|
+
export declare type RangeSpec = {
|
|
1098
|
+
readonly satisfiable: true;
|
|
1099
|
+
readonly start: number;
|
|
1100
|
+
readonly end: number;
|
|
1101
|
+
} | {
|
|
1102
|
+
readonly satisfiable: false;
|
|
1103
|
+
};
|
|
1104
|
+
|
|
1105
|
+
/**
|
|
1106
|
+
* Collect + decode a `Request` body — the shared body-collection pipeline
|
|
1107
|
+
* surfaced to middleware and handlers as the middleware context's cached
|
|
1108
|
+
* `body()`.
|
|
1109
|
+
*
|
|
1110
|
+
* @remarks
|
|
1111
|
+
* Collects the wire body capped at `options.limit` bytes ({@link
|
|
1112
|
+
* import('./constants.js').DEFAULT_BODY_LIMIT} by default — a 413 over),
|
|
1113
|
+
* transparently decompresses a `gzip`/`deflate` `Content-Encoding` body
|
|
1114
|
+
* through the zip-bomb-capped pipe ({@link decompressRequestBody}, capped at
|
|
1115
|
+
* `options.decompression`, default {@link
|
|
1116
|
+
* import('./constants.js').DEFAULT_DECOMPRESSED_LIMIT}), then decodes by
|
|
1117
|
+
* content type: `application/json` is parsed via `@orkestrel/contract`'s
|
|
1118
|
+
* `parseJSON` and scrubbed of prototype-pollution keys ({@link
|
|
1119
|
+
* scrubPrototype}); any other type decodes as UTF-8 text; an empty body
|
|
1120
|
+
* decodes to `undefined`.
|
|
1121
|
+
*
|
|
1122
|
+
* @param request - The `Request` to read the body from
|
|
1123
|
+
* @param options - The {@link BodyOptions} `limit` + `decompression` caps
|
|
1124
|
+
* @returns The parsed JSON value, the raw text, or `undefined` for an empty body
|
|
1125
|
+
* @throws {ContentTooLargeError} When the wire body or decompressed output exceeds its cap
|
|
1126
|
+
* @throws {HTTPError} When the compressed body is corrupt (400)
|
|
1127
|
+
*
|
|
1128
|
+
* @example
|
|
1129
|
+
* ```ts
|
|
1130
|
+
* const body = await readBody(request, { limit: 1_048_576 })
|
|
1131
|
+
* ```
|
|
1132
|
+
*/
|
|
1133
|
+
export declare function readBody(request: Request, options?: BodyOptions): Promise<unknown>;
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* Read + verify a SIGNED cookie off a request — TOTAL, returning the
|
|
1137
|
+
* embedded value or `undefined` (the inverse of {@link writeSignedCookie}).
|
|
1138
|
+
*
|
|
1139
|
+
* @remarks
|
|
1140
|
+
* Parses the `Cookie` header ({@link parseCookies}), takes the named cookie,
|
|
1141
|
+
* and verifies it with {@link verifyToken} against `secret` (a rotation list
|
|
1142
|
+
* accepts a cookie signed by any of its secrets). ANY failure — an absent
|
|
1143
|
+
* cookie, a tampered value, a wrong secret — yields `undefined`, never throws.
|
|
1144
|
+
*
|
|
1145
|
+
* @param request - The `Request` to read the `Cookie` header from
|
|
1146
|
+
* @param name - The cookie name to read
|
|
1147
|
+
* @param secret - The {@link TokenSecret} (or rotation list) to verify against
|
|
1148
|
+
* @returns The embedded value when the cookie is present + valid, else `undefined`
|
|
1149
|
+
*
|
|
1150
|
+
* @example
|
|
1151
|
+
* ```ts
|
|
1152
|
+
* const value = await readSignedCookie(request, 'session', 'secret')
|
|
1153
|
+
* ```
|
|
1154
|
+
*/
|
|
1155
|
+
export declare function readSignedCookie(request: Request, name: string, secret: TokenSecret): Promise<string | undefined>;
|
|
1156
|
+
|
|
1157
|
+
/**
|
|
1158
|
+
* The strict charset `isValidRequestId` requires an incoming `X-Request-ID`
|
|
1159
|
+
* to match — `^[A-Za-z0-9_-]{1,200}$` — so a CRLF / log-injection / oversized
|
|
1160
|
+
* / control-char-bearing incoming id is REJECTED (a fresh id is minted
|
|
1161
|
+
* instead) rather than ever riding into a response header or `context.state`
|
|
1162
|
+
* (AGENTS §14 totality). Frozen so a consumer can read but never mutate the
|
|
1163
|
+
* shared default.
|
|
1164
|
+
*/
|
|
1165
|
+
export declare const REQUEST_ID_PATTERN: Readonly<RegExp>;
|
|
1166
|
+
|
|
1167
|
+
/**
|
|
1168
|
+
* Narrow a raw `Content-Encoding` header value to a decompressible
|
|
1169
|
+
* {@link Encoding} — the boundary guard {@link readBody} uses to decide
|
|
1170
|
+
* whether a request body needs transparent decompression.
|
|
1171
|
+
*
|
|
1172
|
+
* @remarks
|
|
1173
|
+
* Lower-cases + trims and returns the matching {@link Encoding} ONLY for
|
|
1174
|
+
* `gzip` / `deflate` (the two `DecompressionStream`-supported codings, §3 of
|
|
1175
|
+
* the proposal). An absent header, `identity`, an unknown value, or a
|
|
1176
|
+
* comma-joined multi-coding all yield `undefined` (the body is read as-is).
|
|
1177
|
+
* TOTAL — never asserts the loose `string | null` header.
|
|
1178
|
+
*
|
|
1179
|
+
* @param header - The raw `Content-Encoding` header value
|
|
1180
|
+
* @returns The single decompressible {@link Encoding}, or `undefined` when none applies
|
|
1181
|
+
*
|
|
1182
|
+
* @example
|
|
1183
|
+
* ```ts
|
|
1184
|
+
* requestEncoding('gzip') // 'gzip'
|
|
1185
|
+
* requestEncoding('br') // undefined — unsupported by DecompressionStream
|
|
1186
|
+
* ```
|
|
1187
|
+
*/
|
|
1188
|
+
export declare function requestEncoding(header: string | null): Exclude<Encoding, 'identity'> | undefined;
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* Resolve the `Access-Control-Allow-Origin` value for a request.
|
|
1192
|
+
*
|
|
1193
|
+
* @remarks
|
|
1194
|
+
* `'*'` and a single origin string pass straight through. An allow-list
|
|
1195
|
+
* echoes the request's `Origin` only when it is present in the list, else
|
|
1196
|
+
* `undefined` (no header set). SECURITY: the literal `'null'` origin — sent
|
|
1197
|
+
* by a sandboxed iframe, a `file://` document, an opaque-origin redirect — is
|
|
1198
|
+
* NEVER reflected even if `'null'` were listed, closing the hostile-context
|
|
1199
|
+
* cross-origin-access hole.
|
|
1200
|
+
*
|
|
1201
|
+
* @param origin - The configured origin policy — `'*'`, a single origin, or an allow-list
|
|
1202
|
+
* @param requestOrigin - The request's `Origin` header value, if present
|
|
1203
|
+
* @returns The allow-origin value to send, or `undefined` to set no header
|
|
1204
|
+
*
|
|
1205
|
+
* @example
|
|
1206
|
+
* ```ts
|
|
1207
|
+
* resolveOrigin(['https://app.example'], 'https://app.example') // 'https://app.example'
|
|
1208
|
+
* resolveOrigin(['https://app.example'], 'null') // undefined — never reflected
|
|
1209
|
+
* ```
|
|
1210
|
+
*/
|
|
1211
|
+
export declare function resolveOrigin(origin: string | readonly string[], requestOrigin: string | undefined): string | undefined;
|
|
1212
|
+
|
|
1213
|
+
/**
|
|
1214
|
+
* Resolve a cookie's effective `Secure` flag from its {@link CookieOptions}
|
|
1215
|
+
* `secure` setting and whether the request arrived over TLS.
|
|
1216
|
+
*
|
|
1217
|
+
* @remarks
|
|
1218
|
+
* `true` / `false` are explicit overrides. `undefined` (the secure default —
|
|
1219
|
+
* the option omitted) resolves to `encrypted` — `Secure` on a TLS
|
|
1220
|
+
* connection, off over plaintext HTTP — so a production HTTPS deployment
|
|
1221
|
+
* gets `Secure` automatically while local-dev HTTP still works.
|
|
1222
|
+
*
|
|
1223
|
+
* @param secure - The {@link CookieOptions} `secure` setting
|
|
1224
|
+
* @param encrypted - The connection's TLS flag ({@link import('./types.js').ConnectionInfo.encrypted})
|
|
1225
|
+
* @returns The concrete `Secure` flag to emit
|
|
1226
|
+
*
|
|
1227
|
+
* @example
|
|
1228
|
+
* ```ts
|
|
1229
|
+
* resolveSecure(undefined, true) // true
|
|
1230
|
+
* resolveSecure(undefined, false) // false
|
|
1231
|
+
* resolveSecure(false, true) // false — explicit override wins
|
|
1232
|
+
* ```
|
|
1233
|
+
*/
|
|
1234
|
+
export declare function resolveSecure(secure: boolean | undefined, encrypted: boolean): boolean;
|
|
1235
|
+
|
|
1236
|
+
/**
|
|
1237
|
+
* Resolve one opt-out, value-bearing security header.
|
|
1238
|
+
*
|
|
1239
|
+
* @remarks
|
|
1240
|
+
* The shared "a `string` value, or `false` to omit, or a default when unset"
|
|
1241
|
+
* resolution (AGENTS §4.4 — a value-or-off union, not a behavioral toggle):
|
|
1242
|
+
* `false` ⇒ `undefined` (omit the header), an explicit `string` ⇒ that
|
|
1243
|
+
* override, `undefined` (unset) ⇒ `fallback` (the secure default).
|
|
1244
|
+
*
|
|
1245
|
+
* @param value - The option value — a `string` override, `false` to omit, or `undefined` for the default
|
|
1246
|
+
* @param fallback - The secure-default value used when `value` is unset
|
|
1247
|
+
* @returns The header value to set, or `undefined` to omit the header
|
|
1248
|
+
*
|
|
1249
|
+
* @example
|
|
1250
|
+
* ```ts
|
|
1251
|
+
* resolveSecurityHeader(undefined, 'DENY') // 'DENY'
|
|
1252
|
+
* resolveSecurityHeader(false, 'DENY') // undefined — omitted
|
|
1253
|
+
* resolveSecurityHeader('SAMEORIGIN', 'DENY') // 'SAMEORIGIN' — override
|
|
1254
|
+
* ```
|
|
1255
|
+
*/
|
|
1256
|
+
export declare function resolveSecurityHeader(value: string | false | undefined, fallback: string): string | undefined;
|
|
1257
|
+
|
|
1258
|
+
/**
|
|
1259
|
+
* Recursively STRIP the prototype-pollution keys from a parsed value IN
|
|
1260
|
+
* PLACE.
|
|
1261
|
+
*
|
|
1262
|
+
* @remarks
|
|
1263
|
+
* `JSON.parse('{"__proto__":{…}}')` is benign on its own — it produces an OWN,
|
|
1264
|
+
* enumerable `__proto__` DATA property — but that own key becomes a
|
|
1265
|
+
* pollution gadget the moment a downstream deep-merge copies it onto a live
|
|
1266
|
+
* object. This walks the value and `delete`s any own {@link isDangerousKey}
|
|
1267
|
+
* key at every depth, recursing into nested objects + array elements.
|
|
1268
|
+
* Primitives/`null` pass through untouched. Total — never throws. Mutates the
|
|
1269
|
+
* freshly-parsed value (which nothing else holds yet).
|
|
1270
|
+
*
|
|
1271
|
+
* @param value - The freshly `JSON.parse`d value to scrub (mutated in place)
|
|
1272
|
+
* @returns The same `value`, with every dangerous key removed at every depth
|
|
1273
|
+
*
|
|
1274
|
+
* @example
|
|
1275
|
+
* ```ts
|
|
1276
|
+
* scrubPrototype(JSON.parse('{"__proto__":{"polluted":true},"name":"ok"}'))
|
|
1277
|
+
* // { name: 'ok' } — the __proto__ key is gone
|
|
1278
|
+
* ```
|
|
1279
|
+
*/
|
|
1280
|
+
export declare function scrubPrototype(value: unknown): unknown;
|
|
1281
|
+
|
|
1282
|
+
/**
|
|
1283
|
+
* Serialize a cookie into a `Set-Cookie` header value — `name=value` plus its attributes.
|
|
1284
|
+
*
|
|
1285
|
+
* @remarks
|
|
1286
|
+
* URL-encodes the value (the inverse of {@link parseCookies}'s decode) and
|
|
1287
|
+
* appends the present {@link CookieOptions} attributes in canonical order:
|
|
1288
|
+
* `Domain`, `Path` (default `/`), `Max-Age`, `HttpOnly` (default ON), `Secure`
|
|
1289
|
+
* (default OFF), `SameSite` (default `Lax`). `Domain` / `Path` are validated
|
|
1290
|
+
* with {@link isCookieAttribute} and THROW an {@link HTTPError} on an
|
|
1291
|
+
* injection attempt (a programmer misconfiguration, AGENTS §12 — never a
|
|
1292
|
+
* silent drop). A `sameSite: 'None'` cookie is ALWAYS `Secure` regardless of
|
|
1293
|
+
* the `secure` option (the spec requires it); an un-resolved `undefined`
|
|
1294
|
+
* `secure` here falls to OFF — request-aware callers resolve it first via
|
|
1295
|
+
* {@link resolveSecure}.
|
|
1296
|
+
*
|
|
1297
|
+
* @param name - The cookie name
|
|
1298
|
+
* @param value - The cookie value (URL-encoded into the output)
|
|
1299
|
+
* @param options - The {@link CookieOptions} attributes; see its fields for defaults
|
|
1300
|
+
* @returns The `Set-Cookie` header value
|
|
1301
|
+
* @throws {HTTPError} When `domain` or `path` carries an injection char
|
|
1302
|
+
*
|
|
1303
|
+
* @example
|
|
1304
|
+
* ```ts
|
|
1305
|
+
* serializeCookie('session', 'abc') // 'session=abc; Path=/; HttpOnly; SameSite=Lax'
|
|
1306
|
+
* ```
|
|
1307
|
+
*/
|
|
1308
|
+
export declare function serializeCookie(name: string, value: string, options?: CookieOptions): string;
|
|
1309
|
+
|
|
1310
|
+
/**
|
|
1311
|
+
* Serialize one {@link SSEMessage} to the SSE wire.
|
|
1312
|
+
*
|
|
1313
|
+
* @remarks
|
|
1314
|
+
* Emits an `event:`/`id:`/`retry:` line for each present field, then ONE
|
|
1315
|
+
* `data:` line per CRLF-aware-split (`\r\n` / `\r` / `\n`) segment of `data`
|
|
1316
|
+
* (so a consuming parser's multi-`data` concat reproduces the original
|
|
1317
|
+
* `data` exactly, and no raw `\r` or `\n` can ever ride onto the wire inside
|
|
1318
|
+
* a `data:` line), then the terminating blank line.
|
|
1319
|
+
*
|
|
1320
|
+
* @param message - The event to serialize
|
|
1321
|
+
* @returns The SSE wire text for the event (terminated by a blank line)
|
|
1322
|
+
*
|
|
1323
|
+
* @example
|
|
1324
|
+
* ```ts
|
|
1325
|
+
* serializeEvent({ event: 'token', data: 'hello' }) // 'event: token\ndata: hello\n\n'
|
|
1326
|
+
* serializeEvent({ data: 'multi\nline' }) // 'data: multi\ndata: line\n\n'
|
|
1327
|
+
* ```
|
|
1328
|
+
*/
|
|
1329
|
+
export declare function serializeEvent(message: SSEMessage): string;
|
|
1330
|
+
|
|
1331
|
+
/**
|
|
1332
|
+
* Sign a value into a stateless, HMAC-SHA256 token — `<payload>.<signature>`.
|
|
1333
|
+
*
|
|
1334
|
+
* @remarks
|
|
1335
|
+
* The payload is a base64url-encoded JSON `{ value, exp }` (`exp` is the
|
|
1336
|
+
* absolute expiry instant `Date.now() + ttl` when `options.ttl` is set, so
|
|
1337
|
+
* the expiry is HMAC-COVERED — a client cannot extend it without invalidating
|
|
1338
|
+
* the signature), signed via `crypto.subtle.sign('HMAC', …)` under the FIRST
|
|
1339
|
+
* {@link TokenSecret} (the current secret, or the head of a rotation list).
|
|
1340
|
+
* Blank/whitespace-only secrets are IGNORED ({@link normalizeSecret}); a
|
|
1341
|
+
* misconfigured secret with no usable entry THROWS an {@link HTTPError}
|
|
1342
|
+
* (`500`) — fail-closed, a programmer error (AGENTS §12). Verify with
|
|
1343
|
+
* {@link verifyToken}. Omitting `ttl` mints a token that never expires.
|
|
1344
|
+
*
|
|
1345
|
+
* @param value - The opaque value to embed (a session id, a deployment marker)
|
|
1346
|
+
* @param options - The signing `secret` and optional `ttl` (ms); see {@link TokenOptions}
|
|
1347
|
+
* @returns The signed `<payload>.<signature>` token string
|
|
1348
|
+
* @throws {HTTPError} When `options.secret` has no usable (non-blank) entry
|
|
1349
|
+
*
|
|
1350
|
+
* @example
|
|
1351
|
+
* ```ts
|
|
1352
|
+
* const token = await signToken('client', { secret: 'shh', ttl: 60_000 })
|
|
1353
|
+
* await verifyToken(token, 'shh') // 'client' (within 60s), else undefined
|
|
1354
|
+
* ```
|
|
1355
|
+
*/
|
|
1356
|
+
export declare function signToken(value: string, options: TokenOptions): Promise<string>;
|
|
1357
|
+
|
|
1358
|
+
/**
|
|
1359
|
+
* The SSE response headers the `openStream` seam always sets.
|
|
1360
|
+
*
|
|
1361
|
+
* @remarks
|
|
1362
|
+
* `text/event-stream` is the media type browsers dispatch as SSE; `no-cache`
|
|
1363
|
+
* keeps a proxy from caching the stream; `keep-alive` holds the connection
|
|
1364
|
+
* open; `X-Accel-Buffering: no` opts a buffering reverse proxy (nginx) out so
|
|
1365
|
+
* events flush promptly rather than batching. Frozen so a consumer can read
|
|
1366
|
+
* but never mutate the shared default; `openStream` merges any
|
|
1367
|
+
* {@link import('./types.js').StreamOptions.headers} UNDER these.
|
|
1368
|
+
*/
|
|
1369
|
+
export declare const SSE_HEADERS: Readonly<Record<string, string>>;
|
|
1370
|
+
|
|
1371
|
+
/**
|
|
1372
|
+
* One Server-Sent Event to serialize to the wire.
|
|
1373
|
+
*
|
|
1374
|
+
* @remarks
|
|
1375
|
+
* - `data` — the event payload (required). Serialized as one or more `data:`
|
|
1376
|
+
* lines: the value is split on `\n` into a `data:` line PER segment, so it
|
|
1377
|
+
* round-trips through a consumer's multi-`data` concat.
|
|
1378
|
+
* - `event` — the optional event TYPE, emitted as an `event:` line; omitted
|
|
1379
|
+
* ⇒ the consumer's default (`message`).
|
|
1380
|
+
* - `id` — the optional last-event-id, emitted as an `id:` line.
|
|
1381
|
+
* - `retry` — the optional reconnection time in milliseconds, emitted as a
|
|
1382
|
+
* `retry:` line.
|
|
1383
|
+
*/
|
|
1384
|
+
export declare interface SSEMessage {
|
|
1385
|
+
readonly data: string;
|
|
1386
|
+
/** Must be a SINGLE-LINE value — an embedded newline would corrupt the SSE wire format. */
|
|
1387
|
+
readonly event?: string;
|
|
1388
|
+
/** Must be a SINGLE-LINE value — an embedded newline would corrupt the SSE wire format. */
|
|
1389
|
+
readonly id?: string;
|
|
1390
|
+
readonly retry?: number;
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* A handle to write Server-Sent Events to an open, fetch-standard streaming
|
|
1395
|
+
* `Response` — the generic streaming surface `openStream` returns over a
|
|
1396
|
+
* `ReadableStream`.
|
|
1397
|
+
*
|
|
1398
|
+
* @remarks
|
|
1399
|
+
* Agent-agnostic by design: it speaks only the SSE wire vocabulary ({@link
|
|
1400
|
+
* SSEMessage}), so any streaming consumer maps its own events onto `write`.
|
|
1401
|
+
* `response` is the `Response` to return from the route handler (its body is
|
|
1402
|
+
* the `ReadableStream` this handle writes into). Each `write` serializes the
|
|
1403
|
+
* message to the wire and enqueues it; `comment` writes a `: text` keep-alive
|
|
1404
|
+
* line (ignored by a conforming SSE parser — no spurious event); `end` closes
|
|
1405
|
+
* the stream. Every method is a SAFE NO-OP once `closed` is `true`, so a late
|
|
1406
|
+
* `write` never throws.
|
|
1407
|
+
*/
|
|
1408
|
+
export declare interface StreamInterface {
|
|
1409
|
+
/** The streaming `Response` to return from the route handler. */
|
|
1410
|
+
readonly response: Response;
|
|
1411
|
+
/** Whether the underlying stream is done (ended, or the consumer disconnected). */
|
|
1412
|
+
readonly closed: boolean;
|
|
1413
|
+
/**
|
|
1414
|
+
* Serialize + enqueue one {@link SSEMessage} to the wire (a no-op once `closed`).
|
|
1415
|
+
*
|
|
1416
|
+
* @param message - The event to send (its `data` split on `\n` into `data:` lines)
|
|
1417
|
+
*/
|
|
1418
|
+
write(message: SSEMessage): void;
|
|
1419
|
+
/**
|
|
1420
|
+
* Write a `: text` SSE comment line — a keep-alive a conforming parser ignores.
|
|
1421
|
+
*
|
|
1422
|
+
* @param text - The comment text (sent after the `: ` prefix)
|
|
1423
|
+
*/
|
|
1424
|
+
comment(text: string): void;
|
|
1425
|
+
/** End the stream, completing the response (a no-op once already `closed`). */
|
|
1426
|
+
end(): void;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
/**
|
|
1430
|
+
* Options for the `openStream` seam.
|
|
1431
|
+
*
|
|
1432
|
+
* @param status - The HTTP status the streaming response is opened with;
|
|
1433
|
+
* defaults to `200`.
|
|
1434
|
+
* @param headers - Extra response headers merged with the SSE headers the
|
|
1435
|
+
* seam always sets ({@link SSE_HEADERS}) — a key the seam owns is never
|
|
1436
|
+
* overridden.
|
|
1437
|
+
*/
|
|
1438
|
+
export declare interface StreamOptions {
|
|
1439
|
+
readonly status?: number;
|
|
1440
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
/**
|
|
1444
|
+
* Options for `signToken` — how a stateless, HMAC-signed token is minted.
|
|
1445
|
+
*
|
|
1446
|
+
* @param secret - The {@link TokenSecret} to sign with; `signToken` always
|
|
1447
|
+
* uses the FIRST secret (a single string, or the current head of a
|
|
1448
|
+
* rotation list). An empty rotation list is a misconfiguration and throws.
|
|
1449
|
+
* @param ttl - An optional lifetime in milliseconds. When set, the expiry
|
|
1450
|
+
* timestamp is bound INTO the signed payload (HMAC-covered, tamper-proof);
|
|
1451
|
+
* `verifyToken` rejects the token once that instant has passed. Omitted ⇒
|
|
1452
|
+
* the token never expires.
|
|
1453
|
+
*/
|
|
1454
|
+
export declare interface TokenOptions {
|
|
1455
|
+
readonly secret: TokenSecret;
|
|
1456
|
+
readonly ttl?: number;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
/**
|
|
1460
|
+
* A secret (or rotation list) for signing + verifying a stateless, HMAC-signed
|
|
1461
|
+
* token.
|
|
1462
|
+
*
|
|
1463
|
+
* @remarks
|
|
1464
|
+
* A single `string` is the lone secret. A `readonly string[]` is a rotation
|
|
1465
|
+
* list in `[current, ...older]` order: `signToken` always signs with the
|
|
1466
|
+
* FIRST (current) secret, while `verifyToken` accepts a token signed by ANY
|
|
1467
|
+
* secret in the list — so a key rotates by prepending the new one and keeping
|
|
1468
|
+
* the old until every outstanding token has expired, with zero downtime.
|
|
1469
|
+
*/
|
|
1470
|
+
export declare type TokenSecret = string | readonly string[];
|
|
1471
|
+
|
|
1472
|
+
/**
|
|
1473
|
+
* Strip the WEAK indicator (`W/`) from an entity-tag, returning its opaque
|
|
1474
|
+
* comparison body — the reduction {@link matchesETag} applies to both sides
|
|
1475
|
+
* before the RFC 7232 §2.3.2 weak comparison.
|
|
1476
|
+
*
|
|
1477
|
+
* @param tag - One entity-tag (`W/"<body>"` or `"<body>"`)
|
|
1478
|
+
* @returns The tag with any leading `W/` removed (the quotes preserved)
|
|
1479
|
+
*
|
|
1480
|
+
* @example
|
|
1481
|
+
* ```ts
|
|
1482
|
+
* unwrapETag('W/"abc"') // '"abc"'
|
|
1483
|
+
* ```
|
|
1484
|
+
*/
|
|
1485
|
+
export declare function unwrapETag(tag: string): string;
|
|
1486
|
+
|
|
1487
|
+
/**
|
|
1488
|
+
* Verify a stateless token and return its embedded value — TOTAL, never throws.
|
|
1489
|
+
*
|
|
1490
|
+
* @remarks
|
|
1491
|
+
* The inverse of {@link signToken}: splits the token on its LAST `.` (so a
|
|
1492
|
+
* value containing dots survives), and checks the payload's HMAC-SHA256
|
|
1493
|
+
* signature against EACH {@link TokenSecret} candidate via
|
|
1494
|
+
* `crypto.subtle.verify` (constant-time internally — the old `safeCompare` is
|
|
1495
|
+
* retired, §3 of the proposal), accepting the token on the first match (the
|
|
1496
|
+
* rotation path). It then decodes + narrows the payload (`isRecord` +
|
|
1497
|
+
* `typeof`, never `as` — AGENTS §14) and, when an expiry was bound in,
|
|
1498
|
+
* rejects an expired token. ANY failure — a malformed token, a bad signature,
|
|
1499
|
+
* a hostile/non-JSON payload, an empty secret list, or an elapsed expiry —
|
|
1500
|
+
* yields `undefined` rather than throwing.
|
|
1501
|
+
*
|
|
1502
|
+
* @param token - The candidate token string (from a request header/cookie)
|
|
1503
|
+
* @param secret - The {@link TokenSecret} (or rotation list) to verify against
|
|
1504
|
+
* @returns The embedded value when the token is valid + unexpired, else `undefined`
|
|
1505
|
+
*
|
|
1506
|
+
* @example
|
|
1507
|
+
* ```ts
|
|
1508
|
+
* await verifyToken('bad.token', 'shh') // undefined — never throws
|
|
1509
|
+
* ```
|
|
1510
|
+
*/
|
|
1511
|
+
export declare function verifyToken(token: string, secret: TokenSecret): Promise<string | undefined>;
|
|
1512
|
+
|
|
1513
|
+
/**
|
|
1514
|
+
* Write a SIGNED cookie — HMAC-sign `value` with {@link signToken} and append
|
|
1515
|
+
* it as a `Set-Cookie` (the inverse of {@link readSignedCookie}).
|
|
1516
|
+
*
|
|
1517
|
+
* @remarks
|
|
1518
|
+
* The cookie value is `await signToken(value, { secret })`
|
|
1519
|
+
* (`<payload>.<signature>`), so a signed cookie is a stateless token in a
|
|
1520
|
+
* cookie — the same secret rotation and tamper rejection, no second HMAC
|
|
1521
|
+
* scheme. Appends (never clobbers) via {@link appendCookie}. Async — WebCrypto
|
|
1522
|
+
* signing is asynchronous (§3 of the proposal).
|
|
1523
|
+
*
|
|
1524
|
+
* @param headers - The response `Headers` to write into
|
|
1525
|
+
* @param name - The cookie name
|
|
1526
|
+
* @param value - The opaque value to sign into the cookie
|
|
1527
|
+
* @param secret - The {@link TokenSecret} to sign with (the first secret signs)
|
|
1528
|
+
* @param options - The {@link CookieOptions} attributes for the `Set-Cookie`
|
|
1529
|
+
*
|
|
1530
|
+
* @example
|
|
1531
|
+
* ```ts
|
|
1532
|
+
* const headers = new Headers()
|
|
1533
|
+
* await writeSignedCookie(headers, 'session', 'user-1', 'secret')
|
|
1534
|
+
* ```
|
|
1535
|
+
*/
|
|
1536
|
+
export declare function writeSignedCookie(headers: Headers, name: string, value: string, secret: TokenSecret, options?: CookieOptions): Promise<void>;
|
|
1537
|
+
|
|
1538
|
+
export { }
|