@ix-xs/node-comfort 2.1.1 → 2.2.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 +135 -0
- package/README.md +2 -2
- package/package.json +2 -2
- package/src/Arr.js +13 -5
- package/src/Checker.js +56 -8
- package/src/Cli.js +60 -18
- package/src/Color.js +32 -6
- package/src/Crypto.js +429 -78
- package/src/Emitter.js +9 -9
- package/src/Env.js +90 -8
- package/src/FS.js +366 -56
- package/src/Http.js +263 -72
- package/src/Id.js +53 -15
- package/src/Logger.js +100 -22
- package/src/Num.js +2 -1
- package/src/Obj.js +225 -36
- package/src/SQLite.js +154 -97
- package/src/Schema.js +281 -40
- package/src/Str.js +77 -29
- package/src/Sys.js +123 -22
- package/src/Time.js +96 -22
- package/src/Utils.js +18 -3
- package/src/errors.js +75 -4
- package/src/internal/shared.js +68 -14
- package/src/internal/terminal.js +49 -0
- package/types/index.d.ts +28 -5
- package/types/src/Arr.d.ts +4 -2
- package/types/src/Arr.d.ts.map +1 -1
- package/types/src/Checker.d.ts +29 -3
- package/types/src/Checker.d.ts.map +1 -1
- package/types/src/Cli.d.ts +6 -4
- package/types/src/Cli.d.ts.map +1 -1
- package/types/src/Color.d.ts +2 -2
- package/types/src/Color.d.ts.map +1 -1
- package/types/src/Crypto.d.ts +126 -28
- package/types/src/Crypto.d.ts.map +1 -1
- package/types/src/Emitter.d.ts +6 -6
- package/types/src/Emitter.d.ts.map +1 -1
- package/types/src/Env.d.ts +19 -1
- package/types/src/Env.d.ts.map +1 -1
- package/types/src/FS.d.ts +27 -20
- package/types/src/FS.d.ts.map +1 -1
- package/types/src/Http.d.ts +42 -5
- package/types/src/Http.d.ts.map +1 -1
- package/types/src/Id.d.ts.map +1 -1
- package/types/src/Logger.d.ts +11 -3
- package/types/src/Logger.d.ts.map +1 -1
- package/types/src/Num.d.ts.map +1 -1
- package/types/src/Obj.d.ts +15 -2
- package/types/src/Obj.d.ts.map +1 -1
- package/types/src/SQLite.d.ts +104 -12
- package/types/src/SQLite.d.ts.map +1 -1
- package/types/src/Schema.d.ts +61 -5
- package/types/src/Schema.d.ts.map +1 -1
- package/types/src/Str.d.ts +32 -7
- package/types/src/Str.d.ts.map +1 -1
- package/types/src/Sys.d.ts +42 -9
- package/types/src/Sys.d.ts.map +1 -1
- package/types/src/Time.d.ts +10 -5
- package/types/src/Time.d.ts.map +1 -1
- package/types/src/Utils.d.ts +16 -6
- package/types/src/Utils.d.ts.map +1 -1
- package/types/src/errors.d.ts +6 -2
- package/types/src/errors.d.ts.map +1 -1
- package/types/src/internal/shared.d.ts +7 -0
- package/types/src/internal/shared.d.ts.map +1 -1
- package/types/src/internal/terminal.d.ts +13 -0
- package/types/src/internal/terminal.d.ts.map +1 -0
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Generated by scripts/build-types.js. Do not edit by hand.
|
|
2
|
-
// @ix-xs/node-comfort v2.
|
|
2
|
+
// @ix-xs/node-comfort v2.2.0
|
|
3
3
|
|
|
4
4
|
import _Arr = require("./src/Arr");
|
|
5
5
|
import _Async = require("./src/Async");
|
|
@@ -46,7 +46,15 @@ declare namespace nodeComfort {
|
|
|
46
46
|
* files if you need to.
|
|
47
47
|
*
|
|
48
48
|
* Markup: `<% red bold Error:%> disk is full`. Any style name works, plus
|
|
49
|
-
* `#ff8800`, `bg#1e1e2e`, `rgb(255, 128, 0)` and `bgRgb(...)`.
|
|
49
|
+
* `#ff8800`, `bg#1e1e2e`, `rgb(255, 128, 0)` and `bgRgb(...)`. Only the
|
|
50
|
+
* first argument, the message, is read as markup: the values after it are
|
|
51
|
+
* printed as they are.
|
|
52
|
+
*
|
|
53
|
+
* What a terminal could act on is shown as text (`\x1b`, `\r`), so a logged
|
|
54
|
+
* value can't move the cursor, change the title or forge a log line. Colors
|
|
55
|
+
* from `nc.color`, links from `color.link()`, new lines and tabs still work,
|
|
56
|
+
* and the lines of a message after its first one are indented, except with
|
|
57
|
+
* `log()` when there is no scope and no timestamp.
|
|
50
58
|
*
|
|
51
59
|
* Levels, from chatty to severe: `trace`, `debug`, `info`, `warn`, `error`,
|
|
52
60
|
* `fatal`. The default is `info`; `LOG_LEVEL` changes it. `DEBUG=1` shows
|
|
@@ -184,8 +192,8 @@ declare namespace nodeComfort {
|
|
|
184
192
|
export import id = _Id;
|
|
185
193
|
/**
|
|
186
194
|
* Crypto without the footguns, built on `node:crypto`: hashes, HMAC,
|
|
187
|
-
* password hashing (scrypt), encryption (AES-256-GCM), JWT,
|
|
188
|
-
* codes (TOTP) and secure random values.
|
|
195
|
+
* password hashing (scrypt or Argon2id), encryption (AES-256-GCM), JWT,
|
|
196
|
+
* two-factor codes (TOTP) and secure random values.
|
|
189
197
|
*
|
|
190
198
|
* @example
|
|
191
199
|
* const stored = await crypto.hashPassword("hunter2");
|
|
@@ -213,6 +221,10 @@ declare namespace nodeComfort {
|
|
|
213
221
|
* boxes. When nobody's at the keyboard (CI, pipes), prompts read plain lines
|
|
214
222
|
* and animations print only their final state.
|
|
215
223
|
*
|
|
224
|
+
* Tables, boxes, trees and menus show what a terminal could act on as text
|
|
225
|
+
* (`\x1b`, `\r`), so a value can't move the cursor or break the layout.
|
|
226
|
+
* Colors and links in them still work.
|
|
227
|
+
*
|
|
216
228
|
* @example
|
|
217
229
|
* const { flags } = cli.args({
|
|
218
230
|
* port: { type: "number", short: "p", default: 3000, description: "Port to listen on" },
|
|
@@ -317,7 +329,7 @@ declare namespace nodeComfort {
|
|
|
317
329
|
*/
|
|
318
330
|
export import errors = _errors;
|
|
319
331
|
/**
|
|
320
|
-
* SQLite made pleasant, on the engine built into Node.js
|
|
332
|
+
* SQLite made pleasant, on the engine built into Node.js: CRUD with
|
|
321
333
|
* rich filters, JSON and boolean columns, transactions, migrations and
|
|
322
334
|
* backups. Methods are synchronous, like the engine, but `await` still
|
|
323
335
|
* works. Errors are `SQLiteError`s. Values are always bound as parameters
|
|
@@ -335,6 +347,10 @@ declare namespace nodeComfort {
|
|
|
335
347
|
* });
|
|
336
348
|
* db.insert("users", { email: "ada@example.com", settings: { theme: "dark" } });
|
|
337
349
|
* db.getAll("users", { email: { like: "%@example.com" } }, { orderBy: "email", limit: 20 });
|
|
350
|
+
*
|
|
351
|
+
* // Values from a request can't turn into operators:
|
|
352
|
+
* const safe = new nc.SQLite("data/app.sqlite", { operators: "tagged" });
|
|
353
|
+
* safe.getAll("users", { age: nc.SQLite.op.gte(18), role: nc.SQLite.op.in(["admin", "editor"]) });
|
|
338
354
|
*/
|
|
339
355
|
export import SQLite = _SQLite;
|
|
340
356
|
/**
|
|
@@ -598,6 +614,7 @@ declare namespace nodeComfort {
|
|
|
598
614
|
export import InsertOptions = _SQLite.InsertOptions;
|
|
599
615
|
export import InsertResult = _SQLite.InsertResult;
|
|
600
616
|
export import IsBase64Options = _Checker.IsBase64Options;
|
|
617
|
+
export import IsDataURLOptions = _Checker.IsDataURLOptions;
|
|
601
618
|
export import IsHostnameOptions = _Checker.IsHostnameOptions;
|
|
602
619
|
export import IsURLOptions = _Checker.IsURLOptions;
|
|
603
620
|
export import IsUUIDOptions = _Checker.IsUUIDOptions;
|
|
@@ -607,6 +624,7 @@ declare namespace nodeComfort {
|
|
|
607
624
|
export import JWTClaims = _Crypto.JWTClaims;
|
|
608
625
|
export import JWTKey = _Crypto.JWTKey;
|
|
609
626
|
export import KeyPair = _Crypto.KeyPair;
|
|
627
|
+
export import LevenshteinOptions = _Str.LevenshteinOptions;
|
|
610
628
|
export import Limiter = _Async.Limiter;
|
|
611
629
|
export import ListenOptions = _Emitter.ListenOptions;
|
|
612
630
|
export import ListOptions = _FS.ListOptions;
|
|
@@ -627,6 +645,8 @@ declare namespace nodeComfort {
|
|
|
627
645
|
export import NodeComfortErrorOptions = _errors.NodeComfortErrorOptions;
|
|
628
646
|
export import NullishToUndefined = _Obj.NullishToUndefined;
|
|
629
647
|
export import ObjectOutput = _Schema.ObjectOutput;
|
|
648
|
+
export import OpenOptions = _Sys.OpenOptions;
|
|
649
|
+
export import OperatorHelpers = _SQLite.OperatorHelpers;
|
|
630
650
|
export import OrdinalOptions = _Num.OrdinalOptions;
|
|
631
651
|
export import Page = _Arr.Page;
|
|
632
652
|
export import PaginateOptions = _SQLite.PaginateOptions;
|
|
@@ -636,6 +656,7 @@ declare namespace nodeComfort {
|
|
|
636
656
|
export import ParseDateOptions = _Time.ParseDateOptions;
|
|
637
657
|
export import ParsedFlags = _Cli.ParsedFlags;
|
|
638
658
|
export import ParsedSnowflake = _Id.ParsedSnowflake;
|
|
659
|
+
export import ParseOptions = _Schema.ParseOptions;
|
|
639
660
|
export import PathInput = _Obj.PathInput;
|
|
640
661
|
export import PathLeaf = _Obj.PathLeaf;
|
|
641
662
|
export import Paths = _Obj.Paths;
|
|
@@ -692,6 +713,7 @@ declare namespace nodeComfort {
|
|
|
692
713
|
export import TableDefinition = _SQLite.TableDefinition;
|
|
693
714
|
export import TableHandle = _SQLite.TableHandle;
|
|
694
715
|
export import TableOptions = _Cli.TableOptions;
|
|
716
|
+
export import TaggedOperator = _SQLite.TaggedOperator;
|
|
695
717
|
export import TemplateOptions = _Str.TemplateOptions;
|
|
696
718
|
export import ThrottledFunction = _Func.ThrottledFunction;
|
|
697
719
|
export import ThrottleOptions = _Func.ThrottleOptions;
|
|
@@ -718,6 +740,7 @@ declare namespace nodeComfort {
|
|
|
718
740
|
export import Where = _SQLite.Where;
|
|
719
741
|
export import WhereOperators = _SQLite.WhereOperators;
|
|
720
742
|
export import WhereValue = _SQLite.WhereValue;
|
|
743
|
+
export import WhichOptions = _Sys.WhichOptions;
|
|
721
744
|
export import WrapOptions = _Str.WrapOptions;
|
|
722
745
|
export import WriteFileOptions = _FS.WriteFileOptions;
|
|
723
746
|
export import WriteJSONOptions = _FS.WriteJSONOptions;
|
package/types/src/Arr.d.ts
CHANGED
|
@@ -470,7 +470,8 @@ export function insert<T>(array: readonly T[], index: number, ...items: T[]): T[
|
|
|
470
470
|
*/
|
|
471
471
|
export function flatten<T, D extends number = 1>(array: readonly T[], depth?: D): FlatArray<T[], D>[];
|
|
472
472
|
/**
|
|
473
|
-
* Pairs items by position. Shorter arrays leave `undefined` holes
|
|
473
|
+
* Pairs items by position. Shorter arrays leave `undefined` holes, and
|
|
474
|
+
* values that are not arrays count as empty ones.
|
|
474
475
|
*
|
|
475
476
|
* @example
|
|
476
477
|
* arr.zip(["a", "b"], [1, 2]); // [["a", 1], ["b", 2]]
|
|
@@ -481,7 +482,8 @@ export function flatten<T, D extends number = 1>(array: readonly T[], depth?: D)
|
|
|
481
482
|
*/
|
|
482
483
|
export function zip<T>(...arrays: ReadonlyArray<T>[]): Array<Array<T | undefined>>;
|
|
483
484
|
/**
|
|
484
|
-
* The opposite of `zip()`: rows become columns.
|
|
485
|
+
* The opposite of `zip()`: rows become columns. Rows that are not arrays
|
|
486
|
+
* count as empty ones.
|
|
485
487
|
*
|
|
486
488
|
* @example
|
|
487
489
|
* arr.unzip([["a", 1], ["b", 2]]); // [["a", "b"], [1, 2]]
|
package/types/src/Arr.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Arr.d.ts","sourceRoot":"","sources":["../../src/Arr.js"],"names":[],"mappings":";;;;qBAiBa,CAAC,IACD,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;;;;;oBAOhG,CAAC,IACD,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;iBAa3C,CAAC;;;;WAEA,CAAC,EAAE;;;;UACH,MAAM;aACN,MAAM;;;;WACN,MAAM;;;;WACN,MAAM;aACN,OAAO;aACP,OAAO;;;;;;;;;;;;;;;;;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,OAAO,GACjC,CAAC,EAAE,CAMf;AAED;;;;;;;;;;;GAWG;AACH,kCAJW,QAAQ,CAAC,OAAO,CAAC,YACjB,iBAAiB,GACf,MAAM,CAKlB"}
|
package/types/src/Checker.d.ts
CHANGED
|
@@ -46,6 +46,15 @@ export type IsBase64Options = {
|
|
|
46
46
|
*/
|
|
47
47
|
urlSafe?: boolean | undefined;
|
|
48
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Options for `isDataURL()`.
|
|
51
|
+
*/
|
|
52
|
+
export type IsDataURLOptions = {
|
|
53
|
+
/**
|
|
54
|
+
* Accepted media types, like `["image/png", "image/jpeg"]`, case ignored. A URL without a type, like `data:,Hello`, counts as `text/plain`. Without this option, any type passes.
|
|
55
|
+
*/
|
|
56
|
+
types?: string[] | undefined;
|
|
57
|
+
};
|
|
49
58
|
/**
|
|
50
59
|
* Any built-in typed array.
|
|
51
60
|
* @typedef {Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array} AnyTypedArray
|
|
@@ -75,6 +84,11 @@ export type IsBase64Options = {
|
|
|
75
84
|
* @typedef {object} IsBase64Options
|
|
76
85
|
* @property {boolean} [urlSafe] Expect the URL-safe alphabet (`-` and `_`), padding optional.
|
|
77
86
|
*/
|
|
87
|
+
/**
|
|
88
|
+
* Options for `isDataURL()`.
|
|
89
|
+
* @typedef {object} IsDataURLOptions
|
|
90
|
+
* @property {string[]} [types] Accepted media types, like `["image/png", "image/jpeg"]`, case ignored. A URL without a type, like `data:,Hello`, counts as `text/plain`. Without this option, any type passes.
|
|
91
|
+
*/
|
|
78
92
|
/**
|
|
79
93
|
* Is it an array?
|
|
80
94
|
*
|
|
@@ -462,7 +476,10 @@ export function isOneOf<L extends readonly unknown[]>(value: unknown, allowed: L
|
|
|
462
476
|
/**
|
|
463
477
|
* Does it look like an email address? The rules are practical rather than
|
|
464
478
|
* the full RFC: one `@`, no stray dots, a real top-level domain.
|
|
465
|
-
* International addresses are accepted
|
|
479
|
+
* International addresses are accepted, but not look-alike characters such
|
|
480
|
+
* as the Kelvin sign in the domain. A valid address can still contain
|
|
481
|
+
* quotes, `&`, `|` or backticks: it is not safe to put unescaped into HTML
|
|
482
|
+
* or a shell command.
|
|
466
483
|
*
|
|
467
484
|
* @example
|
|
468
485
|
* nc.isEmail("jose@exemple.fr"); // true
|
|
@@ -475,6 +492,9 @@ export function isOneOf<L extends readonly unknown[]>(value: unknown, allowed: L
|
|
|
475
492
|
export function isEmail(value: unknown): value is string;
|
|
476
493
|
/**
|
|
477
494
|
* Is it an absolute URL with an allowed protocol (http and https by default)?
|
|
495
|
+
* The text must already be clean: spaces, control characters, double
|
|
496
|
+
* quotes, backticks, `<`, `>` and backslashes are refused, even where the URL
|
|
497
|
+
* parser would quietly fix them. An apostrophe is fine.
|
|
478
498
|
*
|
|
479
499
|
* @example
|
|
480
500
|
* nc.isURL("https://example.com/a?b=1"); // true
|
|
@@ -658,6 +678,8 @@ export function isJWT(value: unknown): value is string;
|
|
|
658
678
|
/**
|
|
659
679
|
* Is it a host name, like `example.com`, `api.internal` or `localhost`?
|
|
660
680
|
* International names are accepted. IP addresses aren't: see `isIP`.
|
|
681
|
+
* Lengths are counted the way DNS sees them, once converted to ASCII
|
|
682
|
+
* (`xn--`): 63 bytes per label, 253 in all.
|
|
661
683
|
*
|
|
662
684
|
* @example
|
|
663
685
|
* nc.isHostname("api.example.com"); // true
|
|
@@ -726,16 +748,20 @@ export function isObjectId(value: unknown): value is string;
|
|
|
726
748
|
*/
|
|
727
749
|
export function isULID(value: unknown): value is string;
|
|
728
750
|
/**
|
|
729
|
-
* Is it a `data:` URL, like an inline image?
|
|
751
|
+
* Is it a `data:` URL, like an inline image? Only the header is checked,
|
|
752
|
+
* not the data. Without `types`, any media type passes, `text/html` and
|
|
753
|
+
* `image/svg+xml` included, and both can run scripts.
|
|
730
754
|
*
|
|
731
755
|
* @example
|
|
732
756
|
* nc.isDataURL("data:image/png;base64,iVBORw0KGgo="); // true
|
|
733
757
|
* nc.isDataURL("data:,Hello"); // true
|
|
758
|
+
* nc.isDataURL("data:text/html,<p>Hi</p>", { types: ["image/png"] }); // false
|
|
734
759
|
*
|
|
735
760
|
* @param {unknown} value
|
|
761
|
+
* @param {IsDataURLOptions} [options]
|
|
736
762
|
* @returns {value is string}
|
|
737
763
|
*/
|
|
738
|
-
export function isDataURL(value: unknown): value is string;
|
|
764
|
+
export function isDataURL(value: unknown, options?: IsDataURLOptions): value is string;
|
|
739
765
|
/**
|
|
740
766
|
* Is it a media type, like `application/json` or
|
|
741
767
|
* `text/html; charset=utf-8`?
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checker.d.ts","sourceRoot":"","sources":["../../src/Checker.js"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Checker.d.ts","sourceRoot":"","sources":["../../src/Checker.js"],"names":[],"mappings":";;;4BAuCa,SAAS,GAAG,UAAU,GAAG,iBAAiB,GAAG,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,GAAG,YAAY,GAAG,YAAY,GAAG,aAAa,GAAG,cAAc;;;;wBAK/J,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAP3E;;;GAGG;AAEH;;;GAGG;AAEH;;;;;GAKG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,+BAHW,OAAO,GACL,KAAK,IAAI,GAAG,EAAE,CAI1B;AAED;;;;;;;;;;GAUG;AACH,gCAHW,OAAO,GACL,KAAK,IAAI,MAAM,CAI3B;AAED;;;;;;;;;;GAUG;AACH,gCAHW,OAAO,GACL,KAAK,IAAI,MAAM,CAI3B;AAED;;;;;;;;;GASG;AACH,iCAHW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AAED;;;;;;;;;GASG;AACH,kCAHW,OAAO,GACL,KAAK,IAAI,MAAM,CAU3B;AAED;;;;;;;;;GASG;AACH,gCAHW,OAAO,GACL,KAAK,IAAI,MAAM,CAS3B;AAED;;;;;;;;;;GAUG;AACH,8BAHW,OAAO,GACL,KAAK,IAAI,MAAM,CAe3B;AAED;;;;;;;;;GASG;AACH,+BAHW,OAAO,GACL,KAAK,IAAI,MAAM,CAI3B;AAED;;;;;;;;;;;;;GAaG;AACH,kCALW,OAAO,YACP,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GACrB,QAAQ,SAAS,CAK7B;AAED;;;;;;;;;;;;;GAaG;AACH,2BAPa,CAAC,SACH,OAAO,SACP,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,YAC9B,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GACrB,QAAQ,KAAK,IAAI,CAAC,CAQ9B"}
|
package/types/src/Cli.d.ts
CHANGED
|
@@ -110,9 +110,10 @@ export type SpinnerOptions = {
|
|
|
110
110
|
stream?: NodeJS.WriteStream | undefined;
|
|
111
111
|
};
|
|
112
112
|
/**
|
|
113
|
-
* A spinner. Every method returns it.
|
|
113
|
+
* A spinner. Every method returns it. With `using`, it stops at the end of the block.
|
|
114
114
|
*/
|
|
115
|
-
export type Spinner =
|
|
115
|
+
export type Spinner = _SpinnerMethods & Disposable;
|
|
116
|
+
export type _SpinnerMethods = {
|
|
116
117
|
/**
|
|
117
118
|
* Starts spinning, optionally with new text.
|
|
118
119
|
*/
|
|
@@ -177,9 +178,10 @@ export type ProgressOptions = {
|
|
|
177
178
|
stream?: NodeJS.WriteStream | undefined;
|
|
178
179
|
};
|
|
179
180
|
/**
|
|
180
|
-
* A progress bar.
|
|
181
|
+
* A progress bar. With `using`, it stops at the end of the block.
|
|
181
182
|
*/
|
|
182
|
-
export type ProgressBar =
|
|
183
|
+
export type ProgressBar = _ProgressBarMethods & Disposable;
|
|
184
|
+
export type _ProgressBarMethods = {
|
|
183
185
|
/**
|
|
184
186
|
* Adds to the value, 1 by default.
|
|
185
187
|
*/
|
package/types/src/Cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cli.d.ts","sourceRoot":"","sources":["../../src/Cli.js"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Cli.d.ts","sourceRoot":"","sources":["../../src/Cli.js"],"names":[],"mappings":";;;0BA2Ba,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAkBlC,eAAe,GAAG,UAAU;;;;;WAK3B,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;;;;UAC1B,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,OAAO;;;;UAC1B,MAAM;gBACN,OAAO;;;;;;;;;WAMP,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAWP,mBAAmB,GAAG,UAAU;;;;;UAK/B,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,WAAW;;;;YAChD,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,WAAW;;;;UAC9C,MAAM,WAAW;WACjB,MAAM;;;;WACN,MAAM;;;;aACN,MAAM;;;;;;;;;;;;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AM7C;AAED;;;;GAIG;AACH,yBAFa,IAAI,CAIhB"}
|
package/types/src/Color.d.ts
CHANGED
|
@@ -262,7 +262,7 @@ type ColorHelpers = {
|
|
|
262
262
|
isTTY?: boolean;
|
|
263
263
|
}) => ColorLevel;
|
|
264
264
|
/**
|
|
265
|
-
* Removes colors
|
|
265
|
+
* Removes colors, every other terminal escape code and every control character but tabs and new lines (so `\r` and `\b` go too).
|
|
266
266
|
*/
|
|
267
267
|
strip: (text: string) => string;
|
|
268
268
|
/**
|
|
@@ -276,7 +276,7 @@ type ColorHelpers = {
|
|
|
276
276
|
ellipsis?: string;
|
|
277
277
|
}) => string;
|
|
278
278
|
/**
|
|
279
|
-
* A clickable link in terminals that support it, `"text (url)"` elsewhere.
|
|
279
|
+
* A clickable link in terminals that support it, `"text (url)"` elsewhere. Control characters are removed from both, so they can't end the link early; the text keeps its colors.
|
|
280
280
|
*/
|
|
281
281
|
link: (text: string, url: string) => string;
|
|
282
282
|
/**
|
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":";AAkkBA,0BAA0B;AAC1B,qBADW,WAAW,CACiB;;;;;;;iBAjjB1B,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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assword()`.
|
|
19
|
+
* Options for `hashPassword()` and `needsRehash()`.
|
|
20
20
|
*/
|
|
21
21
|
export type HashPasswordOptions = {
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Defaults to `"scrypt"`, which every supported Node.js version can verify. `"argon2id"` needs Node.js 24.7 or later, to hash and to verify.
|
|
24
|
+
*/
|
|
25
|
+
algorithm?: "argon2id" | "scrypt" | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* scrypt work factor as a power of two; each +1 doubles the time. Defaults to `15`.
|
|
24
28
|
*/
|
|
25
29
|
cost?: number | undefined;
|
|
26
30
|
/**
|
|
@@ -28,15 +32,27 @@ export type HashPasswordOptions = {
|
|
|
28
32
|
*/
|
|
29
33
|
blockSize?: number | undefined;
|
|
30
34
|
/**
|
|
31
|
-
* scrypt `p`. Defaults to `1`.
|
|
35
|
+
* scrypt `p`, at most `16`. Defaults to `1`.
|
|
32
36
|
*/
|
|
33
37
|
parallelization?: number | undefined;
|
|
34
38
|
/**
|
|
35
|
-
*
|
|
39
|
+
* Argon2id memory, in KiB, at most `1048576` (1 GiB). Defaults to `19456` (19 MiB), as OWASP recommends.
|
|
40
|
+
*/
|
|
41
|
+
memory?: number | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Argon2id passes over the memory (`t`), from `1` to `10`. Defaults to `2`.
|
|
44
|
+
*/
|
|
45
|
+
passes?: number | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Argon2id lanes (`p`), from `1` to `16`. Defaults to `1`.
|
|
48
|
+
*/
|
|
49
|
+
parallelism?: number | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* In bytes, at least `8`. Defaults to `16`.
|
|
36
52
|
*/
|
|
37
53
|
saltLength?: number | undefined;
|
|
38
54
|
/**
|
|
39
|
-
* In bytes
|
|
55
|
+
* In bytes, from `16` to `128`. Defaults to `32`.
|
|
40
56
|
*/
|
|
41
57
|
keyLength?: number | undefined;
|
|
42
58
|
};
|
|
@@ -182,9 +198,9 @@ export type VerifyJWTOptions = {
|
|
|
182
198
|
*/
|
|
183
199
|
subject?: string | undefined;
|
|
184
200
|
/**
|
|
185
|
-
*
|
|
201
|
+
* Slack for `exp` and `nbf` when server clocks differ: seconds (`0` or more) or a duration like `"30s"`. Defaults to `0`.
|
|
186
202
|
*/
|
|
187
|
-
clockTolerance?: number | undefined;
|
|
203
|
+
clockTolerance?: string | number | undefined;
|
|
188
204
|
/**
|
|
189
205
|
* Reject tokens issued longer ago than this.
|
|
190
206
|
*/
|
|
@@ -194,9 +210,17 @@ export type VerifyJWTOptions = {
|
|
|
194
210
|
*/
|
|
195
211
|
ignoreExpiration?: boolean | undefined;
|
|
196
212
|
/**
|
|
197
|
-
* What time it is. Defaults to now. Handy in tests.
|
|
213
|
+
* What time it is, as a `Date` or Unix milliseconds. Defaults to now. Handy in tests.
|
|
198
214
|
*/
|
|
199
215
|
now?: number | Date | undefined;
|
|
216
|
+
/**
|
|
217
|
+
* Required `typ` header, like `"at+jwt"` for OAuth access tokens. Compared ignoring case, with or without `application/`. A token with another `typ`, or none, is refused.
|
|
218
|
+
*/
|
|
219
|
+
typ?: string | undefined;
|
|
220
|
+
/**
|
|
221
|
+
* Header extensions your code understands. A token whose `crit` header lists anything else is refused, as RFC 7515 requires.
|
|
222
|
+
*/
|
|
223
|
+
crit?: string[] | undefined;
|
|
200
224
|
};
|
|
201
225
|
/**
|
|
202
226
|
* A decoded JWT.
|
|
@@ -230,16 +254,38 @@ export type TOTPOptions = {
|
|
|
230
254
|
*/
|
|
231
255
|
algorithm?: "SHA1" | "SHA256" | "SHA512" | undefined;
|
|
232
256
|
/**
|
|
233
|
-
* Compute the code for this moment. Defaults to now.
|
|
257
|
+
* Compute the code for this moment, as a `Date` or Unix milliseconds. Defaults to now.
|
|
234
258
|
*/
|
|
235
259
|
time?: number | Date | undefined;
|
|
236
260
|
};
|
|
237
261
|
/**
|
|
238
|
-
* Options for `verifyTOTP()
|
|
239
|
-
* now are accepted (defaults to `1`).
|
|
262
|
+
* Options for `verifyTOTP()` and `totpStep()`.
|
|
240
263
|
*/
|
|
241
|
-
export type VerifyTOTPOptions =
|
|
242
|
-
|
|
264
|
+
export type VerifyTOTPOptions = {
|
|
265
|
+
/**
|
|
266
|
+
* Defaults to `6`.
|
|
267
|
+
*/
|
|
268
|
+
digits?: number | undefined;
|
|
269
|
+
/**
|
|
270
|
+
* How long a code lasts, in seconds. Defaults to `30`.
|
|
271
|
+
*/
|
|
272
|
+
period?: number | undefined;
|
|
273
|
+
/**
|
|
274
|
+
* Defaults to `"SHA1"`, which is what authenticator apps expect.
|
|
275
|
+
*/
|
|
276
|
+
algorithm?: "SHA1" | "SHA256" | "SHA512" | undefined;
|
|
277
|
+
/**
|
|
278
|
+
* Check the code at this moment, as a `Date` or Unix milliseconds. Defaults to now.
|
|
279
|
+
*/
|
|
280
|
+
time?: number | Date | undefined;
|
|
281
|
+
/**
|
|
282
|
+
* How many periods before and after now are accepted, from `0` to `10`. Defaults to `1`.
|
|
283
|
+
*/
|
|
284
|
+
window?: number | undefined;
|
|
285
|
+
/**
|
|
286
|
+
* The time step of the last code you accepted, from `totpStep()`. Codes from that step or an earlier one are refused, so a code can't be used twice.
|
|
287
|
+
*/
|
|
288
|
+
after?: number | undefined;
|
|
243
289
|
};
|
|
244
290
|
/**
|
|
245
291
|
* Options for `totpURI()`.
|
|
@@ -325,34 +371,48 @@ export function verifyHmac(data: string | Buffer | Uint8Array, signature: unknow
|
|
|
325
371
|
* Compares two secrets in constant time, so the comparison can't leak
|
|
326
372
|
* anything through timing, not even their lengths. Use it instead of `===`
|
|
327
373
|
* for tokens, signatures and API keys. A missing value (`undefined`, `null`)
|
|
328
|
-
* never equals anything
|
|
374
|
+
* or an empty one (`""`) never equals anything, not even another empty
|
|
375
|
+
* value, so an unset secret can't match an empty header.
|
|
329
376
|
*
|
|
330
377
|
* @example
|
|
331
378
|
* if (!crypto.safeEqual(providedKey, process.env.API_KEY)) throw new Error("Forbidden");
|
|
332
379
|
*
|
|
333
380
|
* @param {string | Buffer | Uint8Array} a
|
|
334
381
|
* @param {string | Buffer | Uint8Array} b
|
|
335
|
-
* @returns {boolean}
|
|
382
|
+
* @returns {boolean} `false` when either side is missing or empty.
|
|
336
383
|
*/
|
|
337
384
|
export function safeEqual(a: string | Buffer | Uint8Array, b: string | Buffer | Uint8Array): boolean;
|
|
338
385
|
/**
|
|
339
|
-
* Hashes a password with
|
|
340
|
-
* own settings, so you can raise the cost
|
|
341
|
-
* hashes.
|
|
386
|
+
* Hashes a password with a random salt: scrypt by default, or Argon2id. The
|
|
387
|
+
* result records its own settings, so you can raise the cost, or move to
|
|
388
|
+
* Argon2id, later without breaking old hashes.
|
|
389
|
+
*
|
|
390
|
+
* Argon2id hashes are standard PHC strings, readable by the other Argon2
|
|
391
|
+
* libraries. Hashing and verifying them needs Node.js 24.7 or later; scrypt
|
|
392
|
+
* works on every supported version.
|
|
342
393
|
*
|
|
343
394
|
* @example
|
|
344
395
|
* const stored = await crypto.hashPassword(password);
|
|
345
396
|
* // "$scrypt$ln=15,r=8,p=1$4xY...$kq9...", store this
|
|
346
397
|
*
|
|
398
|
+
* const modern = await crypto.hashPassword(password, { algorithm: "argon2id" });
|
|
399
|
+
* // "$argon2id$v=19$m=19456,t=2,p=1$Zm9v...$YmFy..."
|
|
400
|
+
*
|
|
347
401
|
* @param {string} password
|
|
348
402
|
* @param {HashPasswordOptions} [options]
|
|
349
403
|
* @returns {Promise<string>}
|
|
350
404
|
* @throws {RangeError} If the settings are out of bounds, like a cost that needs more than 1 GiB of memory.
|
|
405
|
+
* @throws {NodeComfortError} With code `ERR_ARGON2_UNAVAILABLE` for `"argon2id"` on a Node.js older than 24.7.
|
|
351
406
|
*/
|
|
352
407
|
export function hashPassword(password: string, options?: HashPasswordOptions): Promise<string>;
|
|
353
408
|
/**
|
|
354
|
-
* Checks a password against a stored hash, in constant time
|
|
355
|
-
*
|
|
409
|
+
* Checks a password against a stored hash, in constant time: scrypt hashes
|
|
410
|
+
* from `hashPassword()`, and Argon2 PHC strings (`$argon2id$`, `$argon2i$`,
|
|
411
|
+
* `$argon2d$`) from here or from another library. A wrong password or a
|
|
412
|
+
* broken hash gives `false`. A hash asking for more work than allowed (more
|
|
413
|
+
* than 1 GiB of memory, for instance) throws instead, without doing that
|
|
414
|
+
* work: a doctored hash would stall the server that way, and a genuine one
|
|
415
|
+
* isn't a wrong password but a hash to replace.
|
|
356
416
|
*
|
|
357
417
|
* @example
|
|
358
418
|
* if (!(await crypto.verifyPassword(input, user.passwordHash))) throw new Error("Invalid credentials");
|
|
@@ -360,19 +420,27 @@ export function hashPassword(password: string, options?: HashPasswordOptions): P
|
|
|
360
420
|
* @param {string} password
|
|
361
421
|
* @param {string} stored
|
|
362
422
|
* @returns {Promise<boolean>}
|
|
423
|
+
* @throws {RangeError} If the hash asks for more work than allowed: scrypt with `p` over 16 or `128 * N * r * p` over 2**30 bytes (up to what version 2.1 accepted: past that, the hash is broken and gives `false`), Argon2 with more than 1 GiB of memory, 10 passes or 16 lanes. Rehash such passwords with settings within these limits.
|
|
424
|
+
* @throws {NodeComfortError} With code `ERR_ARGON2_UNAVAILABLE` if the hash is Argon2 and this Node.js is older than 24.7. That is a deployment problem, not a wrong password, so it isn't hidden behind `false`.
|
|
363
425
|
*/
|
|
364
426
|
export function verifyPassword(password: string, stored: string): Promise<boolean>;
|
|
365
427
|
/**
|
|
366
|
-
* Was this hash made with
|
|
367
|
-
*
|
|
428
|
+
* Was this hash made with another algorithm, or with weaker settings than
|
|
429
|
+
* yours (lower cost, a key under 32 bytes, a salt under 16)? If so, re-hash
|
|
430
|
+
* the password right after a successful login.
|
|
368
431
|
*
|
|
369
432
|
* @example
|
|
370
433
|
* if (await crypto.verifyPassword(input, user.hash) && crypto.needsRehash(user.hash, { cost: 16 })) {
|
|
371
434
|
* user.hash = await crypto.hashPassword(input, { cost: 16 });
|
|
372
435
|
* }
|
|
373
436
|
*
|
|
437
|
+
* // moving everyone to Argon2id, one login at a time
|
|
438
|
+
* if (await crypto.verifyPassword(input, user.hash) && crypto.needsRehash(user.hash, { algorithm: "argon2id" })) {
|
|
439
|
+
* user.hash = await crypto.hashPassword(input, { algorithm: "argon2id" });
|
|
440
|
+
* }
|
|
441
|
+
*
|
|
374
442
|
* @param {string} stored
|
|
375
|
-
* @param {HashPasswordOptions} [options] The settings you use today.
|
|
443
|
+
* @param {HashPasswordOptions} [options] The settings you use today. `algorithm` defaults to `"scrypt"`.
|
|
376
444
|
* @returns {boolean}
|
|
377
445
|
*/
|
|
378
446
|
export function needsRehash(stored: string, options?: HashPasswordOptions): boolean;
|
|
@@ -483,10 +551,11 @@ export function decodeJWT<P = Record<string, unknown>>(token: string): DecodedJW
|
|
|
483
551
|
*
|
|
484
552
|
* @template [P=Record<string, unknown>]
|
|
485
553
|
* @param {string} token
|
|
486
|
-
* @param {JWTKey} secret The shared secret, or the public key for RS, PS, ES and EdDSA tokens.
|
|
554
|
+
* @param {JWTKey} secret The shared secret (at least 32 bytes), or the public key for RS, PS, ES and EdDSA tokens.
|
|
487
555
|
* @param {VerifyJWTOptions} [options]
|
|
488
556
|
* @returns {P & JWTClaims}
|
|
489
|
-
* @throws {JWTError}
|
|
557
|
+
* @throws {JWTError} If the token is malformed, badly signed, expired or doesn't meet your options.
|
|
558
|
+
* @throws {TypeError} If the key can't be used (a secret under 32 bytes, a public key passed as raw bytes...) or an option is invalid.
|
|
490
559
|
*/
|
|
491
560
|
export function verifyJWT<P = Record<string, unknown>>(token: string, secret: JWTKey, options?: VerifyJWTOptions): P & JWTClaims;
|
|
492
561
|
/**
|
|
@@ -517,8 +586,9 @@ export function generateKeyPair(algorithm?: Exclude<JWTAlgorithm, "HS256" | "HS3
|
|
|
517
586
|
* @example
|
|
518
587
|
* user.totpSecret = crypto.totpSecret();
|
|
519
588
|
*
|
|
520
|
-
* @param {number} [bytes=20]
|
|
589
|
+
* @param {number} [bytes=20] At least `16` (128 bits, the minimum of RFC 4226). `20` is what most apps use.
|
|
521
590
|
* @returns {string}
|
|
591
|
+
* @throws {RangeError} If `bytes` is under 16.
|
|
522
592
|
*/
|
|
523
593
|
export function totpSecret(bytes?: number): string;
|
|
524
594
|
/**
|
|
@@ -528,24 +598,52 @@ export function totpSecret(bytes?: number): string;
|
|
|
528
598
|
* @example
|
|
529
599
|
* crypto.totp(user.totpSecret); // "492039"
|
|
530
600
|
*
|
|
531
|
-
* @param {string} secret
|
|
601
|
+
* @param {string} secret Base32, at least 10 bytes once decoded (16 characters), so older 80-bit secrets keep working. Make new ones with `totpSecret()`, which gives 20 bytes.
|
|
532
602
|
* @param {TOTPOptions} [options]
|
|
533
603
|
* @returns {string}
|
|
604
|
+
* @throws {TypeError} If the secret isn't Base32 or is too short.
|
|
534
605
|
*/
|
|
535
606
|
export function totp(secret: string, options?: TOTPOptions): string;
|
|
536
607
|
/**
|
|
537
608
|
* Checks a code typed by a user. Codes from the neighbouring periods are
|
|
538
609
|
* accepted too, to cope with clock drift.
|
|
539
610
|
*
|
|
611
|
+
* On its own it accepts the same code again until it expires. To refuse
|
|
612
|
+
* reuse, keep the step of the last accepted code from `totpStep()` and
|
|
613
|
+
* pass it as `after`.
|
|
614
|
+
*
|
|
540
615
|
* @example
|
|
541
616
|
* if (!crypto.verifyTOTP(req.body.code, user.totpSecret)) throw new Error("Invalid code");
|
|
542
617
|
*
|
|
543
618
|
* @param {string} token Spaces are ignored.
|
|
544
|
-
* @param {string} secret
|
|
619
|
+
* @param {string} secret Base32, at least 10 bytes once decoded (16 characters), so older 80-bit secrets keep working. Make new ones with `totpSecret()`, which gives 20 bytes.
|
|
545
620
|
* @param {VerifyTOTPOptions} [options]
|
|
546
621
|
* @returns {boolean}
|
|
622
|
+
* @throws {RangeError} If `window` isn't an integer from 0 to 10.
|
|
623
|
+
* @throws {TypeError} If the secret isn't Base32 or is too short.
|
|
547
624
|
*/
|
|
548
625
|
export function verifyTOTP(token: string, secret: string, options?: VerifyTOTPOptions): boolean;
|
|
626
|
+
/**
|
|
627
|
+
* Finds which time step a code typed by a user belongs to. Codes from the
|
|
628
|
+
* neighbouring periods are accepted too, to cope with clock drift.
|
|
629
|
+
*
|
|
630
|
+
* Store the step of the last code you accepted and pass it as `after` next
|
|
631
|
+
* time: the same code, or an older one, is then refused, so a code seen
|
|
632
|
+
* over someone's shoulder can't be used again.
|
|
633
|
+
*
|
|
634
|
+
* @example
|
|
635
|
+
* const step = crypto.totpStep(req.body.code, user.totpSecret, { after: user.totpLastStep });
|
|
636
|
+
* if (step === undefined) throw new Error("Invalid code");
|
|
637
|
+
* user.totpLastStep = step; // save it with the user
|
|
638
|
+
*
|
|
639
|
+
* @param {string} code Spaces are ignored.
|
|
640
|
+
* @param {string} secret Base32, at least 10 bytes once decoded (16 characters), so older 80-bit secrets keep working. Make new ones with `totpSecret()`, which gives 20 bytes.
|
|
641
|
+
* @param {VerifyTOTPOptions} [options]
|
|
642
|
+
* @returns {number | undefined} The time step of the code (Unix time divided by the period), or `undefined` if it doesn't match.
|
|
643
|
+
* @throws {RangeError} If `window` isn't an integer from 0 to 10.
|
|
644
|
+
* @throws {TypeError} If the secret isn't Base32 or is too short, or `after` isn't an integer.
|
|
645
|
+
*/
|
|
646
|
+
export function totpStep(code: string, secret: string, options?: VerifyTOTPOptions): number | undefined;
|
|
549
647
|
/**
|
|
550
648
|
* The `otpauth://` link to show as a QR code when a user turns on 2FA.
|
|
551
649
|
*
|