@ix-xs/node-comfort 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +150 -0
- package/README.md +32 -30
- package/index.js +3 -3
- package/package.json +8 -7
- package/src/Arr.js +222 -58
- package/src/Async.js +322 -90
- package/src/Cache.js +148 -44
- package/src/Checker.js +257 -26
- package/src/Cli.js +404 -145
- package/src/Color.js +224 -83
- package/src/Crypto.js +481 -106
- package/src/Emitter.js +104 -37
- package/src/Env.js +176 -42
- package/src/FS.js +203 -60
- package/src/Func.js +226 -76
- package/src/Http.js +311 -149
- package/src/Id.js +281 -96
- package/src/Logger.js +302 -78
- package/src/Num.js +182 -60
- package/src/Obj.js +340 -125
- package/src/SQLite.js +426 -105
- package/src/Schema.js +602 -87
- package/src/Str.js +316 -86
- package/src/Sys.js +197 -54
- package/src/Time.js +572 -317
- package/src/Utils.js +62 -41
- package/src/errors.js +54 -11
- package/src/internal/shared.js +415 -0
- package/types/index.d.ts +59 -17
- package/types/src/Arr.d.ts +78 -0
- package/types/src/Arr.d.ts.map +1 -1
- package/types/src/Async.d.ts +52 -1
- package/types/src/Async.d.ts.map +1 -1
- package/types/src/Cache.d.ts +33 -7
- package/types/src/Cache.d.ts.map +1 -1
- package/types/src/Checker.d.ts +155 -2
- package/types/src/Checker.d.ts.map +1 -1
- package/types/src/Cli.d.ts +97 -15
- package/types/src/Cli.d.ts.map +1 -1
- package/types/src/Color.d.ts +7 -1
- package/types/src/Color.d.ts.map +1 -1
- package/types/src/Crypto.d.ts +99 -13
- package/types/src/Crypto.d.ts.map +1 -1
- package/types/src/Emitter.d.ts +36 -17
- package/types/src/Emitter.d.ts.map +1 -1
- package/types/src/Env.d.ts +31 -1
- package/types/src/Env.d.ts.map +1 -1
- package/types/src/FS.d.ts +36 -5
- package/types/src/FS.d.ts.map +1 -1
- package/types/src/Func.d.ts +147 -19
- package/types/src/Func.d.ts.map +1 -1
- package/types/src/Http.d.ts +113 -43
- package/types/src/Http.d.ts.map +1 -1
- package/types/src/Id.d.ts +60 -8
- package/types/src/Id.d.ts.map +1 -1
- package/types/src/Logger.d.ts +53 -2
- package/types/src/Logger.d.ts.map +1 -1
- package/types/src/Num.d.ts +48 -7
- package/types/src/Num.d.ts.map +1 -1
- package/types/src/Obj.d.ts +67 -4
- package/types/src/Obj.d.ts.map +1 -1
- package/types/src/SQLite.d.ts +123 -14
- package/types/src/SQLite.d.ts.map +1 -1
- package/types/src/Schema.d.ts +256 -7
- package/types/src/Schema.d.ts.map +1 -1
- package/types/src/Str.d.ts +49 -1
- package/types/src/Str.d.ts.map +1 -1
- package/types/src/Sys.d.ts +51 -6
- package/types/src/Sys.d.ts.map +1 -1
- package/types/src/Time.d.ts +130 -34
- package/types/src/Time.d.ts.map +1 -1
- package/types/src/Utils.d.ts +15 -11
- package/types/src/Utils.d.ts.map +1 -1
- package/types/src/errors.d.ts +27 -3
- package/types/src/errors.d.ts.map +1 -1
- package/types/src/internal/shared.d.ts +123 -0
- package/types/src/internal/shared.d.ts.map +1 -0
package/types/src/Cli.d.ts
CHANGED
|
@@ -300,9 +300,13 @@ export type FlagSpec = {
|
|
|
300
300
|
*/
|
|
301
301
|
required?: boolean | undefined;
|
|
302
302
|
/**
|
|
303
|
-
* Allowed values
|
|
303
|
+
* Allowed values.
|
|
304
304
|
*/
|
|
305
|
-
choices?: readonly string[] | undefined;
|
|
305
|
+
choices?: readonly string[] | readonly number[] | undefined;
|
|
306
|
+
/**
|
|
307
|
+
* An environment variable to read when the flag isn't given, like `"PORT"`. The command line wins, then the variable, then `default`.
|
|
308
|
+
*/
|
|
309
|
+
env?: string | undefined;
|
|
306
310
|
/**
|
|
307
311
|
* Shown in `--help`.
|
|
308
312
|
*/
|
|
@@ -311,9 +315,9 @@ export type FlagSpec = {
|
|
|
311
315
|
/**
|
|
312
316
|
* The type of a flag's value.
|
|
313
317
|
*/
|
|
314
|
-
export type FlagValue<F extends FlagSpec> = F["type"] extends "
|
|
318
|
+
export type FlagValue<F extends FlagSpec> = F["type"] extends "boolean" ? boolean : F extends {
|
|
315
319
|
choices: readonly (infer C)[];
|
|
316
|
-
} ? C : string;
|
|
320
|
+
} ? C : F["type"] extends "number" ? number : string;
|
|
317
321
|
/**
|
|
318
322
|
* The parsed flags, typed from the schema.
|
|
319
323
|
*/
|
|
@@ -346,6 +350,14 @@ export type ArgsOptions = {
|
|
|
346
350
|
* A usage line, like `"<file> [options]"`.
|
|
347
351
|
*/
|
|
348
352
|
usage?: string | undefined;
|
|
353
|
+
/**
|
|
354
|
+
* Subcommands and what they do, like `{ build: "Build the project" }`. The first argument, when there is one, must be one of them and comes back as `command`. They share the flags of the program.
|
|
355
|
+
*/
|
|
356
|
+
commands?: Record<string, string> | undefined;
|
|
357
|
+
/**
|
|
358
|
+
* Command lines shown at the end of the help.
|
|
359
|
+
*/
|
|
360
|
+
examples?: string[] | undefined;
|
|
349
361
|
/**
|
|
350
362
|
* Answer `--help` and `-h` by printing the help and exiting. Defaults to `true`.
|
|
351
363
|
*/
|
|
@@ -358,6 +370,10 @@ export type ArgsOptions = {
|
|
|
358
370
|
* Reject unknown flags, with a suggestion. Defaults to `true`.
|
|
359
371
|
*/
|
|
360
372
|
strict?: boolean | undefined;
|
|
373
|
+
/**
|
|
374
|
+
* Where `env` flags are read from. Defaults to `process.env`.
|
|
375
|
+
*/
|
|
376
|
+
env?: Record<string, string | undefined> | undefined;
|
|
361
377
|
};
|
|
362
378
|
/**
|
|
363
379
|
* What `args()` returns.
|
|
@@ -368,17 +384,37 @@ export type ParsedArgs<S extends Record<string, FlagSpec>> = {
|
|
|
368
384
|
* Arguments that aren't flags.
|
|
369
385
|
*/
|
|
370
386
|
positionals: string[];
|
|
387
|
+
/**
|
|
388
|
+
* The subcommand, when `commands` was given.
|
|
389
|
+
*/
|
|
390
|
+
command: string | undefined;
|
|
371
391
|
/**
|
|
372
392
|
* The generated help text.
|
|
373
393
|
*/
|
|
374
394
|
help: () => string;
|
|
375
395
|
};
|
|
396
|
+
/**
|
|
397
|
+
* Options for `spin()`: the spinner's, plus what to say at the end.
|
|
398
|
+
*/
|
|
399
|
+
export type SpinOptions<T> = SpinnerOptions & {
|
|
400
|
+
success?: string | ((result: T) => string);
|
|
401
|
+
fail?: string | ((error: unknown) => string);
|
|
402
|
+
};
|
|
403
|
+
/**
|
|
404
|
+
* Options for `tree()`.
|
|
405
|
+
*/
|
|
406
|
+
export type TreeOptions = {
|
|
407
|
+
/**
|
|
408
|
+
* Draw with `|`, `+` and `-` instead of box characters.
|
|
409
|
+
*/
|
|
410
|
+
ascii?: boolean | undefined;
|
|
411
|
+
};
|
|
376
412
|
/**
|
|
377
413
|
* One line reader per input stream, shared by every prompt, so piped lines
|
|
378
414
|
* that arrive early are queued instead of lost.
|
|
379
415
|
*/
|
|
380
|
-
export type
|
|
381
|
-
rl: readline.Interface;
|
|
416
|
+
export type _LineReader = {
|
|
417
|
+
rl: import("node:readline").Interface;
|
|
382
418
|
lines: string[];
|
|
383
419
|
waiting: Array<{
|
|
384
420
|
resolve: (line: string) => void;
|
|
@@ -412,16 +448,38 @@ export function table(rows: Array<Record<string, unknown>> | unknown[][], option
|
|
|
412
448
|
*
|
|
413
449
|
* @example
|
|
414
450
|
* console.log(cli.box("Server ready\nhttp://localhost:3000", { title: "my-app", borderColor: "green" }));
|
|
415
|
-
* // ╭─ my-app
|
|
416
|
-
* // │ Server ready
|
|
417
|
-
* // │ http://localhost:3000
|
|
418
|
-
* //
|
|
451
|
+
* // ╭─ my-app ────────────────╮
|
|
452
|
+
* // │ Server ready │
|
|
453
|
+
* // │ http://localhost:3000 │
|
|
454
|
+
* // ╰─────────────────────────╯
|
|
419
455
|
*
|
|
420
456
|
* @param {string} text
|
|
421
457
|
* @param {BoxOptions} [options]
|
|
422
458
|
* @returns {string}
|
|
423
459
|
*/
|
|
424
460
|
export function box(text: string, options?: BoxOptions): string;
|
|
461
|
+
/**
|
|
462
|
+
* Draws nested data as a tree, like the `tree` command does for folders.
|
|
463
|
+
* Keys are branches. A value that is an object or an array opens a level,
|
|
464
|
+
* `null` or `true` makes a plain leaf, anything else is shown after the key.
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* console.log(cli.tree({
|
|
468
|
+
* src: { "index.js": null, lib: ["a.js", "b.js"] },
|
|
469
|
+
* "package.json": "1.2 kB",
|
|
470
|
+
* }));
|
|
471
|
+
* // ├── src
|
|
472
|
+
* // │ ├── index.js
|
|
473
|
+
* // │ └── lib
|
|
474
|
+
* // │ ├── a.js
|
|
475
|
+
* // │ └── b.js
|
|
476
|
+
* // └── package.json: 1.2 kB
|
|
477
|
+
*
|
|
478
|
+
* @param {Record<string, unknown> | unknown[]} data
|
|
479
|
+
* @param {TreeOptions} [options]
|
|
480
|
+
* @returns {string}
|
|
481
|
+
*/
|
|
482
|
+
export function tree(data: Record<string, unknown> | unknown[], options?: TreeOptions): string;
|
|
425
483
|
/**
|
|
426
484
|
* A spinner for work in progress. Call `.start()`, then finish with
|
|
427
485
|
* `.succeed()`, `.fail()`, `.warn()`, `.info()` or `.stop()`.
|
|
@@ -440,6 +498,24 @@ export function box(text: string, options?: BoxOptions): string;
|
|
|
440
498
|
* @returns {Spinner} Not started yet.
|
|
441
499
|
*/
|
|
442
500
|
export function spinner(text?: string, options?: SpinnerOptions): Spinner;
|
|
501
|
+
/**
|
|
502
|
+
* Shows a spinner while some work runs, then `✔` or `✖` depending on how it
|
|
503
|
+
* ended. Resolves with the result of the work, or rejects with its error.
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
* const users = await cli.spin("Loading users", () => db.getAll("users"));
|
|
507
|
+
* await cli.spin("Deploying", deploy(), {
|
|
508
|
+
* success: (url) => `Deployed to ${url}`,
|
|
509
|
+
* fail: (error) => `Deploy failed: ${error.message}`,
|
|
510
|
+
* });
|
|
511
|
+
*
|
|
512
|
+
* @template T
|
|
513
|
+
* @param {string} text
|
|
514
|
+
* @param {Promise<T> | ((spinner: Spinner) => T | Promise<T>)} task A promise, or a function that gets the spinner so it can update the text.
|
|
515
|
+
* @param {SpinOptions<T>} [options]
|
|
516
|
+
* @returns {Promise<T>}
|
|
517
|
+
*/
|
|
518
|
+
export function spin<T>(text: string, task: Promise<T> | ((spinner: Spinner) => T | Promise<T>), options?: SpinOptions<T>): Promise<T>;
|
|
443
519
|
/**
|
|
444
520
|
* A progress bar with percentage, ETA and speed. It redraws at most every
|
|
445
521
|
* 50 ms, so calling `tick()` in a tight loop is fine.
|
|
@@ -533,24 +609,31 @@ export function multiselect<V = string>(question: string, choices: Array<Choice<
|
|
|
533
609
|
/**
|
|
534
610
|
* Parses command-line arguments from a schema, and types the result:
|
|
535
611
|
* `flags.port` is a `number`. Handles short aliases, defaults, required
|
|
536
|
-
* flags, allowed values, repeated flags
|
|
537
|
-
* `--help`. A typo gets a
|
|
612
|
+
* flags, allowed values, repeated flags, `--no-flag`, environment variables
|
|
613
|
+
* as a fallback and subcommands, and generates `--help`. A typo gets a
|
|
614
|
+
* "Did you mean...?" suggestion.
|
|
538
615
|
*
|
|
539
616
|
* @example
|
|
540
617
|
* // node server.js --port 8080 -v --tag api --tag web public/
|
|
541
618
|
* const { flags, positionals } = cli.args({
|
|
542
|
-
* port: { type: "number", short: "p", default: 3000, description: "Port to listen on" },
|
|
619
|
+
* port: { type: "number", short: "p", default: 3000, env: "PORT", description: "Port to listen on" },
|
|
543
620
|
* verbose: { type: "boolean", short: "v" },
|
|
544
621
|
* tag: { type: "string", multiple: true },
|
|
545
622
|
* env: { type: "string", choices: ["dev", "prod"], default: "dev" },
|
|
546
623
|
* }, { description: "Start the web server", version: "1.0.0" });
|
|
547
624
|
* // flags: { port: 8080, verbose: true, tag: ["api", "web"], env: "dev" }
|
|
548
625
|
*
|
|
626
|
+
* // node tool.js build --watch
|
|
627
|
+
* const { command, flags: buildFlags } = cli.args({ watch: { type: "boolean" } }, {
|
|
628
|
+
* commands: { build: "Build the project", serve: "Start the dev server" },
|
|
629
|
+
* });
|
|
630
|
+
* // command: "build"
|
|
631
|
+
*
|
|
549
632
|
* @template {Record<string, FlagSpec>} S
|
|
550
633
|
* @param {S} schema
|
|
551
634
|
* @param {ArgsOptions} [options]
|
|
552
635
|
* @returns {ParsedArgs<S>}
|
|
553
|
-
* @throws {TypeError} For unknown flags, bad numbers, missing required flags or values not in `choices`. The message is ready to show.
|
|
636
|
+
* @throws {TypeError} For unknown flags or commands, bad numbers, missing required flags or values not in `choices`. The message is ready to show.
|
|
554
637
|
*/
|
|
555
638
|
export function args<S extends Record<string, FlagSpec>>(schema: S, options?: ArgsOptions): ParsedArgs<S>;
|
|
556
639
|
/**
|
|
@@ -578,5 +661,4 @@ export function size(): {
|
|
|
578
661
|
* @returns {void}
|
|
579
662
|
*/
|
|
580
663
|
export function clear(): void;
|
|
581
|
-
import readline = require("node:readline");
|
|
582
664
|
//# sourceMappingURL=Cli.d.ts.map
|
package/types/src/Cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cli.d.ts","sourceRoot":"","sources":["../../src/Cli.js"],"names":[],"mappings":";;;0BAuBa,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM;;;;;;;;SAM3D,MAAM,GAAG,MAAM;;;;;;;;;;;;;;;;sBAIP,OAAO,OAAO,GAAG,KAAK,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAkBtB,MAAM;YAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAmBjC,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,OAAO;;;;UAC1B,MAAM,OAAO;;;;aACb,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,OAAO;;;;UAC1B,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,OAAO;;;;UAC1B,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,OAAO;;;;UAC1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a,GACX,OAAO,CAAC,CAAC,CAAC,CAkBtB;AAED;;;;;;;;;;;;GAYG;AACH,4BANc,CAAC,qBACJ,MAAM,WACN,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,YAChB,aAAa,GACX,OAAO,CAAC,CAAC,EAAE,CAAC,CAmBxB;AAeD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBANwC,CAAC,SAA3B,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAE,UAC5B,CAAC,YACD,WAAW,GACT,UAAU,CAAC,CAAC,CAAC,CAyHzB;AAED;;;;;;;;GAQG;AACH,iCAFa,OAAO,CAInB;AAED;;;;GAIG;AACH,wBAFa;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAM7C;AAED;;;;GAIG;AACH,yBAFa,IAAI,CAIhB"}
|
package/types/src/Color.d.ts
CHANGED
|
@@ -244,7 +244,7 @@ type ColorModule = ColorStyles & ColorMethods & ColorHelpers;
|
|
|
244
244
|
*/
|
|
245
245
|
type ColorHelpers = {
|
|
246
246
|
/**
|
|
247
|
-
* The current color level. Set it to force one
|
|
247
|
+
* The current color level. Set it to force one: `0` turns colors off, `undefined` goes back to what the terminal supports.
|
|
248
248
|
*/
|
|
249
249
|
level: ColorLevel;
|
|
250
250
|
/**
|
|
@@ -269,6 +269,12 @@ type ColorHelpers = {
|
|
|
269
269
|
* How many columns the text takes, ignoring colors and counting emoji and CJK as 2.
|
|
270
270
|
*/
|
|
271
271
|
width: (text: string) => number;
|
|
272
|
+
/**
|
|
273
|
+
* Cuts text to a number of columns and adds `…`. Colors are kept and still closed properly.
|
|
274
|
+
*/
|
|
275
|
+
truncate: (text: string, columns: number, options?: {
|
|
276
|
+
ellipsis?: string;
|
|
277
|
+
}) => string;
|
|
272
278
|
/**
|
|
273
279
|
* A clickable link in terminals that support it, `"text (url)"` elsewhere.
|
|
274
280
|
*/
|
package/types/src/Color.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Color.d.ts","sourceRoot":"","sources":["../../src/Color.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"Color.d.ts","sourceRoot":"","sources":["../../src/Color.js"],"names":[],"mappings":";AAwiBA,0BAA0B;AAC1B,qBADW,WAAW,CACiB;;;;;;;iBAvhB1B,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,WAAW,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,eAAe,GAC7G,OAAO,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAC9F,aAAa,GAAG,WAAW,GAAG,aAAa,GAAG,cAAc,GAAG,YAAY,GAAG,eAAe,GAAG,YAAY,GAAG,aAAa,GAC5H,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAClH,eAAe,GAAG,aAAa,GAAG,eAAe,GAAG,gBAAgB,GAAG,cAAc,GAAG,iBAAiB,GAAG,cAAc,GAAG,eAAe;;;;kBAKtI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;;;;;;;;;WAOZ,UAAU;;;;UACV,UAAU;;;;SACV,UAAU;;;;YACV,UAAU;;;;eACV,UAAU;;;;cACV,UAAU;;;;aACV,UAAU;;;;YACV,UAAU;;;;mBACV,UAAU;;;;WACV,UAAU;;;;SACV,UAAU;;;;WACV,UAAU;;;;YACV,UAAU;;;;UACV,UAAU;;;;aACV,UAAU;;;;UACV,UAAU;;;;WACV,UAAU;;;;UACV,UAAU;;;;UACV,UAAU;;;;iBACV,UAAU;;;;eACV,UAAU;;;;iBACV,UAAU;;;;kBACV,UAAU;;;;gBACV,UAAU;;;;mBACV,UAAU;;;;gBACV,UAAU;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AC,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM;;;;UAC1E,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,MAAM;;;;cACrC,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,MAAM;;;;;kBAqB3C;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,EAAE,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,OAAO,CAAA;CAAE"}
|
package/types/src/Crypto.d.ts
CHANGED
|
@@ -62,6 +62,25 @@ export type DecryptOptions = {
|
|
|
62
62
|
*/
|
|
63
63
|
output?: "utf8" | "buffer" | undefined;
|
|
64
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* A key for `signJWT()` and `verifyJWT()`. For the HS algorithms it's a
|
|
67
|
+
* shared secret. For the others it's a key pair: a PEM string, a
|
|
68
|
+
* `KeyObject` or a JWK, private to sign and public to verify.
|
|
69
|
+
*/
|
|
70
|
+
export type JWTKey = string | Buffer | Uint8Array | import("node:crypto").KeyObject | import("node:crypto").JsonWebKey;
|
|
71
|
+
/**
|
|
72
|
+
* A pair of keys in PEM, as made by `generateKeyPair()`.
|
|
73
|
+
*/
|
|
74
|
+
export type KeyPair = {
|
|
75
|
+
/**
|
|
76
|
+
* Give this one away: it only checks signatures.
|
|
77
|
+
*/
|
|
78
|
+
publicKey: string;
|
|
79
|
+
/**
|
|
80
|
+
* Keep this one secret: it signs.
|
|
81
|
+
*/
|
|
82
|
+
privateKey: string;
|
|
83
|
+
};
|
|
65
84
|
/**
|
|
66
85
|
* Standard JWT claims.
|
|
67
86
|
*/
|
|
@@ -96,15 +115,17 @@ export type JWTClaims = {
|
|
|
96
115
|
jti?: string | undefined;
|
|
97
116
|
};
|
|
98
117
|
/**
|
|
99
|
-
* Supported JWT algorithms.
|
|
118
|
+
* Supported JWT algorithms. HS signs and verifies with one shared secret.
|
|
119
|
+
* RS, PS, ES and EdDSA sign with a private key and verify with the public
|
|
120
|
+
* one, so services that only check tokens never hold the signing key.
|
|
100
121
|
*/
|
|
101
|
-
export type JWTAlgorithm = "HS256" | "HS384" | "HS512";
|
|
122
|
+
export type JWTAlgorithm = "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512" | "PS256" | "PS384" | "PS512" | "ES256" | "ES384" | "ES512" | "EdDSA";
|
|
102
123
|
/**
|
|
103
124
|
* Options for `signJWT()`.
|
|
104
125
|
*/
|
|
105
126
|
export type SignJWTOptions = {
|
|
106
127
|
/**
|
|
107
|
-
* Defaults to `"HS256"
|
|
128
|
+
* Defaults to what fits the key: `"HS256"` for a secret, `"RS256"` for an RSA key, `"ES256"` for a P-256 key, `"EdDSA"` for an Ed25519 key.
|
|
108
129
|
*/
|
|
109
130
|
algorithm?: JWTAlgorithm | undefined;
|
|
110
131
|
/**
|
|
@@ -145,7 +166,7 @@ export type SignJWTOptions = {
|
|
|
145
166
|
*/
|
|
146
167
|
export type VerifyJWTOptions = {
|
|
147
168
|
/**
|
|
148
|
-
* Accepted algorithms. Defaults to
|
|
169
|
+
* Accepted algorithms. Defaults to the ones that fit the key, so a token can't pick a weaker one.
|
|
149
170
|
*/
|
|
150
171
|
algorithms?: JWTAlgorithm[] | undefined;
|
|
151
172
|
/**
|
|
@@ -173,7 +194,7 @@ export type VerifyJWTOptions = {
|
|
|
173
194
|
*/
|
|
174
195
|
ignoreExpiration?: boolean | undefined;
|
|
175
196
|
/**
|
|
176
|
-
* What time it is. Defaults to now.
|
|
197
|
+
* What time it is. Defaults to now. Handy in tests.
|
|
177
198
|
*/
|
|
178
199
|
now?: number | Date | undefined;
|
|
179
200
|
};
|
|
@@ -245,6 +266,18 @@ export type TOTPURIOptions = {
|
|
|
245
266
|
*/
|
|
246
267
|
algorithm?: "SHA1" | "SHA256" | "SHA512" | undefined;
|
|
247
268
|
};
|
|
269
|
+
/**
|
|
270
|
+
* A key, ready to use, with the algorithms it may be used with.
|
|
271
|
+
*/
|
|
272
|
+
export type _ResolvedKey = {
|
|
273
|
+
secret: Buffer;
|
|
274
|
+
key?: undefined;
|
|
275
|
+
algorithms: readonly JWTAlgorithm[];
|
|
276
|
+
} | {
|
|
277
|
+
secret?: undefined;
|
|
278
|
+
key: import("node:crypto").KeyObject;
|
|
279
|
+
algorithms: readonly JWTAlgorithm[];
|
|
280
|
+
};
|
|
248
281
|
/**
|
|
249
282
|
* Hashes data, SHA-256 in hex by default.
|
|
250
283
|
*
|
|
@@ -271,10 +304,28 @@ export function hash(data: string | Buffer | Uint8Array, options?: HashOptions):
|
|
|
271
304
|
* @returns {string}
|
|
272
305
|
*/
|
|
273
306
|
export function hmac(data: string | Buffer | Uint8Array, secret: string | Buffer | Uint8Array, options?: HashOptions): string;
|
|
307
|
+
/**
|
|
308
|
+
* Checks an HMAC signature you received, in constant time. A leading
|
|
309
|
+
* `sha256=`, as GitHub and others send, is ignored.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* // an Express webhook route: sign the raw body, not the parsed JSON
|
|
313
|
+
* if (!crypto.verifyHmac(req.rawBody, req.headers["x-hub-signature-256"], process.env.WEBHOOK_SECRET)) {
|
|
314
|
+
* return res.status(401).end();
|
|
315
|
+
* }
|
|
316
|
+
*
|
|
317
|
+
* @param {string | Buffer | Uint8Array} data
|
|
318
|
+
* @param {unknown} signature What the sender computed. Anything but a matching string gives `false`.
|
|
319
|
+
* @param {string | Buffer | Uint8Array} secret
|
|
320
|
+
* @param {HashOptions} [options] Must match what the sender used.
|
|
321
|
+
* @returns {boolean}
|
|
322
|
+
*/
|
|
323
|
+
export function verifyHmac(data: string | Buffer | Uint8Array, signature: unknown, secret: string | Buffer | Uint8Array, options?: HashOptions): boolean;
|
|
274
324
|
/**
|
|
275
325
|
* Compares two secrets in constant time, so the comparison can't leak
|
|
276
|
-
* anything through timing. Use it instead of `===`
|
|
277
|
-
* and API keys.
|
|
326
|
+
* anything through timing, not even their lengths. Use it instead of `===`
|
|
327
|
+
* for tokens, signatures and API keys. A missing value (`undefined`, `null`)
|
|
328
|
+
* never equals anything.
|
|
278
329
|
*
|
|
279
330
|
* @example
|
|
280
331
|
* if (!crypto.safeEqual(providedKey, process.env.API_KEY)) throw new Error("Forbidden");
|
|
@@ -296,6 +347,7 @@ export function safeEqual(a: string | Buffer | Uint8Array, b: string | Buffer |
|
|
|
296
347
|
* @param {string} password
|
|
297
348
|
* @param {HashPasswordOptions} [options]
|
|
298
349
|
* @returns {Promise<string>}
|
|
350
|
+
* @throws {RangeError} If the settings are out of bounds, like a cost that needs more than 1 GiB of memory.
|
|
299
351
|
*/
|
|
300
352
|
export function hashPassword(password: string, options?: HashPasswordOptions): Promise<string>;
|
|
301
353
|
/**
|
|
@@ -350,8 +402,8 @@ export function generateKey(): string;
|
|
|
350
402
|
*/
|
|
351
403
|
export function encrypt(data: string | Buffer | Uint8Array, secret: string | Buffer | Uint8Array, options?: EncryptOptions): string;
|
|
352
404
|
/**
|
|
353
|
-
* Decrypts what `encrypt()` produced. Throws
|
|
354
|
-
* data was changed.
|
|
405
|
+
* Decrypts what `encrypt()` produced. Throws an error with code
|
|
406
|
+
* `ERR_DECRYPT` if the secret is wrong or the data was changed.
|
|
355
407
|
*
|
|
356
408
|
* @example
|
|
357
409
|
* const text = crypto.decrypt(box, SECRET);
|
|
@@ -379,18 +431,28 @@ export function decrypt(payload: string, secret: string | Buffer | Uint8Array, o
|
|
|
379
431
|
/**
|
|
380
432
|
* Creates a signed JSON Web Token. `iat` is added for you.
|
|
381
433
|
*
|
|
434
|
+
* With a secret, the token is signed with HMAC. With a private key, it's
|
|
435
|
+
* signed with that key, and anyone holding the public key can verify it
|
|
436
|
+
* without being able to issue tokens.
|
|
437
|
+
*
|
|
382
438
|
* @example
|
|
383
439
|
* const token = crypto.signJWT({ sub: String(user.id), role: user.role }, process.env.JWT_SECRET, {
|
|
384
440
|
* expiresIn: "15m",
|
|
385
441
|
* issuer: "api.example.com",
|
|
386
442
|
* });
|
|
387
443
|
*
|
|
444
|
+
* // key pair: the auth service signs, every other service verifies
|
|
445
|
+
* const { publicKey, privateKey } = await crypto.generateKeyPair("ES256");
|
|
446
|
+
* const signed = crypto.signJWT({ sub: "42" }, privateKey, { expiresIn: "15m" });
|
|
447
|
+
* crypto.verifyJWT(signed, publicKey);
|
|
448
|
+
*
|
|
388
449
|
* @param {Record<string, unknown>} payload
|
|
389
|
-
* @param {
|
|
450
|
+
* @param {JWTKey} secret For HS algorithms, at least 32 random bytes. Otherwise a private key.
|
|
390
451
|
* @param {SignJWTOptions} [options]
|
|
391
452
|
* @returns {string}
|
|
453
|
+
* @throws {TypeError} If the key can't be used, or doesn't fit the algorithm.
|
|
392
454
|
*/
|
|
393
|
-
export function signJWT(payload: Record<string, unknown>, secret:
|
|
455
|
+
export function signJWT(payload: Record<string, unknown>, secret: JWTKey, options?: SignJWTOptions): string;
|
|
394
456
|
/**
|
|
395
457
|
* Reads a JWT without checking it. Fine for display; call `verifyJWT()`
|
|
396
458
|
* before trusting anything in it.
|
|
@@ -409,6 +471,9 @@ export function decodeJWT<P = Record<string, unknown>>(token: string): DecodedJW
|
|
|
409
471
|
* require. Returns the payload, or throws a `JWTError` whose `code` says
|
|
410
472
|
* what's wrong.
|
|
411
473
|
*
|
|
474
|
+
* The accepted algorithms follow from the key you pass, so a token signed
|
|
475
|
+
* with HMAC is never accepted where a public key is expected.
|
|
476
|
+
*
|
|
412
477
|
* @example
|
|
413
478
|
* try {
|
|
414
479
|
* const { sub } = crypto.verifyJWT(token, process.env.JWT_SECRET, { issuer: "api.example.com" });
|
|
@@ -418,12 +483,33 @@ export function decodeJWT<P = Record<string, unknown>>(token: string): DecodedJW
|
|
|
418
483
|
*
|
|
419
484
|
* @template [P=Record<string, unknown>]
|
|
420
485
|
* @param {string} token
|
|
421
|
-
* @param {
|
|
486
|
+
* @param {JWTKey} secret The shared secret, or the public key for RS, PS, ES and EdDSA tokens.
|
|
422
487
|
* @param {VerifyJWTOptions} [options]
|
|
423
488
|
* @returns {P & JWTClaims}
|
|
424
489
|
* @throws {JWTError}
|
|
425
490
|
*/
|
|
426
|
-
export function verifyJWT<P = Record<string, unknown>>(token: string, secret:
|
|
491
|
+
export function verifyJWT<P = Record<string, unknown>>(token: string, secret: JWTKey, options?: VerifyJWTOptions): P & JWTClaims;
|
|
492
|
+
/**
|
|
493
|
+
* Makes a pair of keys for signing JWTs: the private one signs, the public
|
|
494
|
+
* one verifies. Both come as PEM text, ready for an environment variable or
|
|
495
|
+
* a file.
|
|
496
|
+
*
|
|
497
|
+
* `"EdDSA"` (Ed25519) is the fastest with the shortest keys and signatures.
|
|
498
|
+
* `"ES256"` is the most widely supported after RSA. Pick `"RS256"` when the
|
|
499
|
+
* other side asks for it.
|
|
500
|
+
*
|
|
501
|
+
* @example
|
|
502
|
+
* const { publicKey, privateKey } = await crypto.generateKeyPair();
|
|
503
|
+
* const token = crypto.signJWT({ sub: "42" }, privateKey);
|
|
504
|
+
* crypto.verifyJWT(token, publicKey);
|
|
505
|
+
*
|
|
506
|
+
* @param {Exclude<JWTAlgorithm, "HS256" | "HS384" | "HS512">} [algorithm="EdDSA"] The JWT algorithm the keys are for.
|
|
507
|
+
* @param {{ modulusLength?: number }} [options] RSA key size in bits. Defaults to `2048`.
|
|
508
|
+
* @returns {Promise<KeyPair>}
|
|
509
|
+
*/
|
|
510
|
+
export function generateKeyPair(algorithm?: Exclude<JWTAlgorithm, "HS256" | "HS384" | "HS512">, options?: {
|
|
511
|
+
modulusLength?: number;
|
|
512
|
+
}): Promise<KeyPair>;
|
|
427
513
|
/**
|
|
428
514
|
* A new two-factor secret, in the Base32 format authenticator apps expect.
|
|
429
515
|
* Store it encrypted.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Crypto.d.ts","sourceRoot":"","s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
|
|
|
1
1
|
export = Emitter;
|
|
2
|
-
/**
|
|
3
|
-
* Event names mapped to their arguments, like
|
|
4
|
-
* `{ ready: [], data: [chunk: Buffer], error: [error: Error] }`.
|
|
5
|
-
* @typedef {Record<string, any[]>} EventMap
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Options for `waitFor()`.
|
|
9
|
-
* @template {any[]} A
|
|
10
|
-
* @typedef {object} WaitForOptions
|
|
11
|
-
* @property {number | string} [timeout] Reject with a `TimeoutError` after this long.
|
|
12
|
-
* @property {AbortSignal} [signal] Reject with an `AbortError` when aborted.
|
|
13
|
-
* @property {(...args: A) => boolean} [filter] Only resolve for events that pass this test.
|
|
14
|
-
*/
|
|
15
2
|
/**
|
|
16
3
|
* A typed event emitter. In JavaScript, give the variable a JSDoc type such
|
|
17
4
|
* as `import("@ix-xs/node-comfort").Emitter<{ ready: [port: number] }>`.
|
|
@@ -26,21 +13,28 @@ declare class Emitter<Events extends EventMap = EventMap> {
|
|
|
26
13
|
* const off = emitter.on("data", (chunk) => chunks.push(chunk));
|
|
27
14
|
* off(); // stop listening
|
|
28
15
|
*
|
|
16
|
+
* const controller = new AbortController();
|
|
17
|
+
* emitter.on("data", onData, { signal: controller.signal });
|
|
18
|
+
* emitter.on("end", onEnd, { signal: controller.signal });
|
|
19
|
+
* controller.abort(); // removes both
|
|
20
|
+
*
|
|
29
21
|
* @template {keyof Events & string} K
|
|
30
22
|
* @param {K} event
|
|
31
23
|
* @param {(...args: Events[K]) => unknown} listener
|
|
24
|
+
* @param {ListenOptions} [options]
|
|
32
25
|
* @returns {() => void} Removes the listener.
|
|
33
26
|
*/
|
|
34
|
-
on<K extends keyof Events & string>(event: K, listener: (...args: Events[K]) => unknown): () => void;
|
|
27
|
+
on<K extends keyof Events & string>(event: K, listener: (...args: Events[K]) => unknown, options?: ListenOptions): () => void;
|
|
35
28
|
/**
|
|
36
29
|
* Listens to an event once.
|
|
37
30
|
*
|
|
38
31
|
* @template {keyof Events & string} K
|
|
39
32
|
* @param {K} event
|
|
40
33
|
* @param {(...args: Events[K]) => unknown} listener
|
|
34
|
+
* @param {ListenOptions} [options]
|
|
41
35
|
* @returns {() => void} Removes the listener if it hasn't run yet.
|
|
42
36
|
*/
|
|
43
|
-
once<K extends keyof Events & string>(event: K, listener: (...args: Events[K]) => unknown): () => void;
|
|
37
|
+
once<K extends keyof Events & string>(event: K, listener: (...args: Events[K]) => unknown, options?: ListenOptions): () => void;
|
|
44
38
|
/**
|
|
45
39
|
* Listens to every event; the listener gets the event name first. Handy for
|
|
46
40
|
* logging.
|
|
@@ -57,7 +51,7 @@ declare class Emitter<Events extends EventMap = EventMap> {
|
|
|
57
51
|
*
|
|
58
52
|
* @template {keyof Events & string} K
|
|
59
53
|
* @param {K} event
|
|
60
|
-
* @param {(...args: Events[K]) => unknown} [listener]
|
|
54
|
+
* @param {(...args: Events[K]) => unknown} [listener] The function given to `on()` or `once()`.
|
|
61
55
|
* @returns {this}
|
|
62
56
|
*/
|
|
63
57
|
off<K extends keyof Events & string>(event: K, listener?: (...args: Events[K]) => unknown): this;
|
|
@@ -127,6 +121,15 @@ declare class Emitter<Events extends EventMap = EventMap> {
|
|
|
127
121
|
* @returns {number}
|
|
128
122
|
*/
|
|
129
123
|
listenerCount(event?: keyof Events & string): number;
|
|
124
|
+
/**
|
|
125
|
+
* The listeners of an event, in the order they run. For `once()`, you get
|
|
126
|
+
* the function you passed, not its wrapper.
|
|
127
|
+
*
|
|
128
|
+
* @template {keyof Events & string} K
|
|
129
|
+
* @param {K} event
|
|
130
|
+
* @returns {Array<(...args: Events[K]) => unknown>}
|
|
131
|
+
*/
|
|
132
|
+
listeners<K extends keyof Events & string>(event: K): Array<(...args: Events[K]) => unknown>;
|
|
130
133
|
/**
|
|
131
134
|
* The events that have listeners.
|
|
132
135
|
*
|
|
@@ -143,13 +146,22 @@ declare class Emitter<Events extends EventMap = EventMap> {
|
|
|
143
146
|
#private;
|
|
144
147
|
}
|
|
145
148
|
declare namespace Emitter {
|
|
146
|
-
export { EventMap, WaitForOptions };
|
|
149
|
+
export { EventMap, ListenOptions, WaitForOptions, _StoredListener };
|
|
147
150
|
}
|
|
148
151
|
/**
|
|
149
152
|
* Event names mapped to their arguments, like
|
|
150
153
|
* `{ ready: [], data: [chunk: Buffer], error: [error: Error] }`.
|
|
151
154
|
*/
|
|
152
155
|
type EventMap = Record<string, any[]>;
|
|
156
|
+
/**
|
|
157
|
+
* Options for `on()` and `once()`.
|
|
158
|
+
*/
|
|
159
|
+
type ListenOptions = {
|
|
160
|
+
/**
|
|
161
|
+
* Removes the listener when aborted. One signal can clean up many listeners at once.
|
|
162
|
+
*/
|
|
163
|
+
signal?: AbortSignal | undefined;
|
|
164
|
+
};
|
|
153
165
|
/**
|
|
154
166
|
* Options for `waitFor()`.
|
|
155
167
|
*/
|
|
@@ -167,4 +179,11 @@ type WaitForOptions<A extends any[]> = {
|
|
|
167
179
|
*/
|
|
168
180
|
filter?: ((...args: A) => boolean) | undefined;
|
|
169
181
|
};
|
|
182
|
+
/**
|
|
183
|
+
* A listener as stored: `once()` wraps the function it was given and keeps
|
|
184
|
+
* it as `listener`, so `off()` can find it.
|
|
185
|
+
*/
|
|
186
|
+
type _StoredListener = ((...args: any[]) => unknown) & {
|
|
187
|
+
listener?: Function;
|
|
188
|
+
};
|
|
170
189
|
//# sourceMappingURL=Emitter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Emitter.d.ts","sourceRoot":"","sources":["../../src/Emitter.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"Emitter.d.ts","sourceRoot":"","sources":["../../src/Emitter.js"],"names":[],"mappings":";AAiDA;;;;;GAKG;AACH,sBAFyB,MAAM,SAAjB,QAAS;IA0CrB;;;;;;;;;;;;;;;;;OAiBG;IACH,GANqC,CAAC,SAAxB,MAAM,MAAM,GAAG,MAAO,SACzB,CAAC,YACD,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,CAA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