@venizia/ignis-helpers 0.4.2 → 0.4.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/cjs/common/types/field-mapping.d.ts +13 -1
- package/dist/cjs/common/types/field-mapping.d.ts.map +1 -1
- package/dist/cjs/common/types/field-mapping.js +20 -0
- package/dist/cjs/common/types/field-mapping.js.map +1 -1
- package/dist/cjs/core.d.ts +2 -1
- package/dist/cjs/core.d.ts.map +1 -1
- package/dist/cjs/core.js +6 -1
- package/dist/cjs/core.js.map +1 -1
- package/dist/cjs/modules/crypto/algorithms/aes.algorithm.d.ts +2 -2
- package/dist/cjs/modules/crypto/algorithms/aes.algorithm.d.ts.map +1 -1
- package/dist/cjs/modules/crypto/algorithms/aes.algorithm.js +3 -1
- package/dist/cjs/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
- package/dist/cjs/modules/crypto/algorithms/aes.constants.d.ts +11 -0
- package/dist/cjs/modules/crypto/algorithms/aes.constants.d.ts.map +1 -0
- package/dist/cjs/modules/crypto/algorithms/aes.constants.js +14 -0
- package/dist/cjs/modules/crypto/algorithms/aes.constants.js.map +1 -0
- package/dist/cjs/modules/error/index.d.ts +1 -1
- package/dist/cjs/modules/error/index.d.ts.map +1 -1
- package/dist/cjs/modules/error/index.js +2 -1
- package/dist/cjs/modules/error/index.js.map +1 -1
- package/dist/cjs/modules/logger/hf/common/types.d.ts +3 -1
- package/dist/cjs/modules/logger/hf/common/types.d.ts.map +1 -1
- package/dist/cjs/modules/logger/hf/common/types.js.map +1 -1
- package/dist/cjs/modules/logger/pino/common/constants.d.ts +10 -1
- package/dist/cjs/modules/logger/pino/common/constants.d.ts.map +1 -1
- package/dist/cjs/modules/logger/pino/common/constants.js +11 -1
- package/dist/cjs/modules/logger/pino/common/constants.js.map +1 -1
- package/dist/cjs/modules/logger/pino/destination.d.ts.map +1 -1
- package/dist/cjs/modules/logger/pino/destination.js +4 -3
- package/dist/cjs/modules/logger/pino/destination.js.map +1 -1
- package/dist/cjs/modules/network/http-request/common/constants.d.ts +11 -0
- package/dist/cjs/modules/network/http-request/common/constants.d.ts.map +1 -0
- package/dist/cjs/modules/network/http-request/common/constants.js +14 -0
- package/dist/cjs/modules/network/http-request/common/constants.js.map +1 -0
- package/dist/cjs/modules/network/http-request/common/index.d.ts +1 -0
- package/dist/cjs/modules/network/http-request/common/index.d.ts.map +1 -1
- package/dist/cjs/modules/network/http-request/common/index.js +1 -0
- package/dist/cjs/modules/network/http-request/common/index.js.map +1 -1
- package/dist/cjs/modules/network/http-request/common/types.d.ts +1 -1
- package/dist/cjs/modules/network/http-request/common/types.d.ts.map +1 -1
- package/dist/cjs/modules/network/http-request/common/types.js.map +1 -1
- package/dist/cjs/modules/network/tcp-socket/base-tcp-server.helper.d.ts +13 -2
- package/dist/cjs/modules/network/tcp-socket/base-tcp-server.helper.d.ts.map +1 -1
- package/dist/cjs/modules/network/tcp-socket/base-tcp-server.helper.js +23 -6
- package/dist/cjs/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
- package/dist/cjs/modules/queue/common/constants.d.ts +11 -0
- package/dist/cjs/modules/queue/common/constants.d.ts.map +1 -0
- package/dist/cjs/modules/queue/common/constants.js +14 -0
- package/dist/cjs/modules/queue/common/constants.js.map +1 -0
- package/dist/cjs/modules/queue/common/index.d.ts +1 -0
- package/dist/cjs/modules/queue/common/index.d.ts.map +1 -1
- package/dist/cjs/modules/queue/common/index.js +1 -0
- package/dist/cjs/modules/queue/common/index.js.map +1 -1
- package/dist/cjs/modules/queue/common/types.d.ts +1 -1
- package/dist/cjs/modules/queue/common/types.d.ts.map +1 -1
- package/dist/cjs/modules/queue/common/types.js.map +1 -1
- package/dist/cjs/modules/queue/kafka/common/constants.d.ts +9 -0
- package/dist/cjs/modules/queue/kafka/common/constants.d.ts.map +1 -1
- package/dist/cjs/modules/queue/kafka/common/constants.js +11 -1
- package/dist/cjs/modules/queue/kafka/common/constants.js.map +1 -1
- package/dist/cjs/modules/queue/kafka/consumer.d.ts +2 -1
- package/dist/cjs/modules/queue/kafka/consumer.d.ts.map +1 -1
- package/dist/cjs/modules/queue/kafka/consumer.js +2 -2
- package/dist/cjs/modules/queue/kafka/consumer.js.map +1 -1
- package/dist/cjs/modules/temporal/common/constants.d.ts +21 -0
- package/dist/cjs/modules/temporal/common/constants.d.ts.map +1 -1
- package/dist/cjs/modules/temporal/common/constants.js +22 -1
- package/dist/cjs/modules/temporal/common/constants.js.map +1 -1
- package/dist/cjs/modules/temporal/locale/locale.d.ts +4 -3
- package/dist/cjs/modules/temporal/locale/locale.d.ts.map +1 -1
- package/dist/cjs/modules/temporal/locale/locale.js +2 -1
- package/dist/cjs/modules/temporal/locale/locale.js.map +1 -1
- package/dist/cjs/modules/temporal/pattern/common/constants.d.ts +43 -0
- package/dist/cjs/modules/temporal/pattern/common/constants.d.ts.map +1 -0
- package/dist/cjs/modules/temporal/pattern/common/constants.js +74 -0
- package/dist/cjs/modules/temporal/pattern/common/constants.js.map +1 -0
- package/dist/cjs/modules/temporal/pattern/common/index.d.ts +1 -0
- package/dist/cjs/modules/temporal/pattern/common/index.d.ts.map +1 -1
- package/dist/cjs/modules/temporal/pattern/common/index.js +1 -0
- package/dist/cjs/modules/temporal/pattern/common/index.js.map +1 -1
- package/dist/cjs/modules/temporal/pattern/common/types.d.ts +2 -11
- package/dist/cjs/modules/temporal/pattern/common/types.d.ts.map +1 -1
- package/dist/cjs/modules/temporal/pattern/common/types.js.map +1 -1
- package/dist/cjs/modules/temporal/pattern/tokens.d.ts +2 -1
- package/dist/cjs/modules/temporal/pattern/tokens.d.ts.map +1 -1
- package/dist/cjs/modules/temporal/pattern/tokens.js +2 -14
- package/dist/cjs/modules/temporal/pattern/tokens.js.map +1 -1
- package/dist/cjs/utilities/request.utility.d.ts +21 -2
- package/dist/cjs/utilities/request.utility.d.ts.map +1 -1
- package/dist/cjs/utilities/request.utility.js +25 -5
- package/dist/cjs/utilities/request.utility.js.map +1 -1
- package/dist/esm/common/types/field-mapping.d.ts +13 -1
- package/dist/esm/common/types/field-mapping.d.ts.map +1 -1
- package/dist/esm/common/types/field-mapping.js +18 -1
- package/dist/esm/common/types/field-mapping.js.map +1 -1
- package/dist/esm/core.d.ts +2 -1
- package/dist/esm/core.d.ts.map +1 -1
- package/dist/esm/core.js +4 -0
- package/dist/esm/core.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.d.ts +2 -2
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.js +2 -0
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.constants.d.ts +11 -0
- package/dist/esm/modules/crypto/algorithms/aes.constants.d.ts.map +1 -0
- package/dist/esm/modules/crypto/algorithms/aes.constants.js +10 -0
- package/dist/esm/modules/crypto/algorithms/aes.constants.js.map +1 -0
- package/dist/esm/modules/error/index.d.ts +1 -1
- package/dist/esm/modules/error/index.d.ts.map +1 -1
- package/dist/esm/modules/error/index.js +1 -1
- package/dist/esm/modules/error/index.js.map +1 -1
- package/dist/esm/modules/logger/hf/common/types.d.ts +3 -1
- package/dist/esm/modules/logger/hf/common/types.d.ts.map +1 -1
- package/dist/esm/modules/logger/hf/common/types.js.map +1 -1
- package/dist/esm/modules/logger/pino/common/constants.d.ts +10 -1
- package/dist/esm/modules/logger/pino/common/constants.d.ts.map +1 -1
- package/dist/esm/modules/logger/pino/common/constants.js +9 -0
- package/dist/esm/modules/logger/pino/common/constants.js.map +1 -1
- package/dist/esm/modules/logger/pino/destination.d.ts.map +1 -1
- package/dist/esm/modules/logger/pino/destination.js +4 -3
- package/dist/esm/modules/logger/pino/destination.js.map +1 -1
- package/dist/esm/modules/network/http-request/common/constants.d.ts +11 -0
- package/dist/esm/modules/network/http-request/common/constants.d.ts.map +1 -0
- package/dist/esm/modules/network/http-request/common/constants.js +10 -0
- package/dist/esm/modules/network/http-request/common/constants.js.map +1 -0
- package/dist/esm/modules/network/http-request/common/index.d.ts +1 -0
- package/dist/esm/modules/network/http-request/common/index.d.ts.map +1 -1
- package/dist/esm/modules/network/http-request/common/index.js +1 -0
- package/dist/esm/modules/network/http-request/common/index.js.map +1 -1
- package/dist/esm/modules/network/http-request/common/types.d.ts +1 -1
- package/dist/esm/modules/network/http-request/common/types.d.ts.map +1 -1
- package/dist/esm/modules/network/http-request/common/types.js.map +1 -1
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.d.ts +13 -2
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.d.ts.map +1 -1
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js +21 -5
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
- package/dist/esm/modules/queue/common/constants.d.ts +11 -0
- package/dist/esm/modules/queue/common/constants.d.ts.map +1 -0
- package/dist/esm/modules/queue/common/constants.js +10 -0
- package/dist/esm/modules/queue/common/constants.js.map +1 -0
- package/dist/esm/modules/queue/common/index.d.ts +1 -0
- package/dist/esm/modules/queue/common/index.d.ts.map +1 -1
- package/dist/esm/modules/queue/common/index.js +1 -0
- package/dist/esm/modules/queue/common/index.js.map +1 -1
- package/dist/esm/modules/queue/common/types.d.ts +1 -1
- package/dist/esm/modules/queue/common/types.d.ts.map +1 -1
- package/dist/esm/modules/queue/common/types.js.map +1 -1
- package/dist/esm/modules/queue/kafka/common/constants.d.ts +9 -0
- package/dist/esm/modules/queue/kafka/common/constants.d.ts.map +1 -1
- package/dist/esm/modules/queue/kafka/common/constants.js +9 -0
- package/dist/esm/modules/queue/kafka/common/constants.js.map +1 -1
- package/dist/esm/modules/queue/kafka/consumer.d.ts +2 -1
- package/dist/esm/modules/queue/kafka/consumer.d.ts.map +1 -1
- package/dist/esm/modules/queue/kafka/consumer.js +3 -3
- package/dist/esm/modules/queue/kafka/consumer.js.map +1 -1
- package/dist/esm/modules/temporal/common/constants.d.ts +21 -0
- package/dist/esm/modules/temporal/common/constants.d.ts.map +1 -1
- package/dist/esm/modules/temporal/common/constants.js +19 -0
- package/dist/esm/modules/temporal/common/constants.js.map +1 -1
- package/dist/esm/modules/temporal/locale/locale.d.ts +4 -3
- package/dist/esm/modules/temporal/locale/locale.d.ts.map +1 -1
- package/dist/esm/modules/temporal/locale/locale.js +2 -1
- package/dist/esm/modules/temporal/locale/locale.js.map +1 -1
- package/dist/esm/modules/temporal/pattern/common/constants.d.ts +43 -0
- package/dist/esm/modules/temporal/pattern/common/constants.d.ts.map +1 -0
- package/dist/esm/modules/temporal/pattern/common/constants.js +70 -0
- package/dist/esm/modules/temporal/pattern/common/constants.js.map +1 -0
- package/dist/esm/modules/temporal/pattern/common/index.d.ts +1 -0
- package/dist/esm/modules/temporal/pattern/common/index.d.ts.map +1 -1
- package/dist/esm/modules/temporal/pattern/common/index.js +1 -0
- package/dist/esm/modules/temporal/pattern/common/index.js.map +1 -1
- package/dist/esm/modules/temporal/pattern/common/types.d.ts +2 -11
- package/dist/esm/modules/temporal/pattern/common/types.d.ts.map +1 -1
- package/dist/esm/modules/temporal/pattern/common/types.js.map +1 -1
- package/dist/esm/modules/temporal/pattern/tokens.d.ts +2 -1
- package/dist/esm/modules/temporal/pattern/tokens.d.ts.map +1 -1
- package/dist/esm/modules/temporal/pattern/tokens.js +2 -14
- package/dist/esm/modules/temporal/pattern/tokens.js.map +1 -1
- package/dist/esm/utilities/request.utility.d.ts +21 -2
- package/dist/esm/utilities/request.utility.d.ts.map +1 -1
- package/dist/esm/utilities/request.utility.js +22 -4
- package/dist/esm/utilities/request.utility.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/modules/temporal/pattern/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/modules/temporal/pattern/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { PatternTokens, TPatternToken, TWriteOnlyToken } from './constants';\nimport type { ITemporalLocaleNames, IZonedTemporalParts } from '../../common/types';\nimport type { TemporalLocale } from '../../locale';\n\nexport type TPatternSegment = { token: TPatternToken } | { literal: string };\n\nexport type TNumericToken = Exclude<\n TPatternToken,\n | typeof PatternTokens.OFFSET_COLON\n | typeof PatternTokens.OFFSET\n | typeof PatternTokens.YEAR_2\n | TWriteOnlyToken\n>;\n\n/** What a writer reads: the wall clock, and the locale - resolved only when a locale token asks for it. */\nexport interface ITokenWriterInput {\n parts: IZonedTemporalParts;\n locale: () => TemporalLocale;\n /** The helper's own wording for this locale, over `Intl`'s. */\n names?: ITemporalLocaleNames;\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ITemporalParts } from '../common/types';
|
|
2
|
-
import
|
|
2
|
+
import { type TPatternToken, type TWriteOnlyToken } from './common/constants';
|
|
3
|
+
import type { ITokenWriterInput, TNumericToken } from './common/types';
|
|
3
4
|
/** The pattern dialect's tokens: what each one writes, and how a parse reads digits and offsets. */
|
|
4
5
|
export declare class TemporalTokens {
|
|
5
6
|
static readonly SUPPORTED = "YYYY YY MM M DD D HH H mm m ss s SSS Z ZZ, and for writing only MMMM MMM dddd ddd dd A a hh h LL L Q";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../../../../src/modules/temporal/pattern/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../../../../src/modules/temporal/pattern/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAiB,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;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d,QAAQ,EAAE,MAAM,CAAC;QACjB,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;KACb,GAAG;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS;IAehD,sFAAsF;IACtF,OAAO,CAAC,MAAM,CAAC,eAAe;IAiB9B;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE;QACtB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,OAAO,CAAC;KACpB,GAAG;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS;IA4BtD,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,CAA0C;IAE1F,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,IAAI,aAAa;CAGlD"}
|
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TemporalTokens = void 0;
|
|
4
|
+
const constants_1 = require("./common/constants");
|
|
4
5
|
/** The pattern dialect's tokens: what each one writes, and how a parse reads digits and offsets. */
|
|
5
6
|
class TemporalTokens {
|
|
6
7
|
static { this.SUPPORTED = 'YYYY YY MM M DD D HH H mm m ss s SSS Z ZZ, and for writing only MMMM MMM dddd ddd dd A a hh h LL L Q'; }
|
|
7
|
-
static { this.WRITE_ONLY_TOKENS =
|
|
8
|
-
'MMMM',
|
|
9
|
-
'MMM',
|
|
10
|
-
'dddd',
|
|
11
|
-
'ddd',
|
|
12
|
-
'dd',
|
|
13
|
-
'A',
|
|
14
|
-
'a',
|
|
15
|
-
'hh',
|
|
16
|
-
'h',
|
|
17
|
-
'LL',
|
|
18
|
-
'L',
|
|
19
|
-
'Q',
|
|
20
|
-
]); }
|
|
8
|
+
static { this.WRITE_ONLY_TOKENS = constants_1.PatternTokens.WRITE_ONLY_SET; }
|
|
21
9
|
static isWriteOnlyToken(token) {
|
|
22
10
|
return TemporalTokens.WRITE_ONLY_TOKENS.has(token);
|
|
23
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../../../../src/modules/temporal/pattern/tokens.ts"],"names":[],"mappings":";;;AAQA,oGAAoG;AACpG,MAAa,cAAc;aACT,cAAS,GACvB,sGAAsG,CAAC;aAEzF,sBAAiB,GAA+B,IAAI,GAAG,CAAkB;QACvF,MAAM;QACN,KAAK;QACL,MAAM;QACN,KAAK;QACL,IAAI;QACJ,GAAG;QACH,GAAG;QACH,IAAI;QACJ,GAAG;QACH,IAAI;QACJ,GAAG;QACH,GAAG;KACJ,CAAC,CAAC;IAEH,MAAM,CAAC,gBAAgB,CAAC,KAAoB;QAC1C,OAAO,cAAc,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC;aAEe,0BAAqB,GAAG,EAAE,CAAC;IAE3C,4FAA4F;aAC5E,yBAAoB,GAAG,EAAE,CAAC;IAE1C,wFAAwF;aACxE,mBAAc,GAAkE;QAC9F,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;QACpB,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC;QACnB,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC;QAClB,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC;QACjB,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC;QAChB,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;QAClB,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;QACjB,EAAE,EAAE,CAAC,CAAC,EA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QACD,MAAM,OAAO,GAAG,cAAc,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QAC3F,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,OAAO,GAAG,cAAc,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QAE7F,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,IAAI,OAAO,CAAC,MAAM,GAAG,EAAE,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,CAAC;YACjF,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;QAC1F,OAAO,EAAE,YAAY,EAAE,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,OAAO,IAAI,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1F,CAAC;aAEe,gBAAW,GAAwB,IAAI,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAE1F,MAAM,CAAC,OAAO,CAAC,GAAW;QACxB,OAAO,cAAc,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7C,CAAC;;AA1OH,wCA2OC","sourcesContent":["import type { ITemporalParts } from '../common/types';\nimport type {\n ITokenWriterInput,\n TNumericToken,\n TPatternToken,\n TWriteOnlyToken,\n} from './common/types';\n\n/** The pattern dialect's tokens: what each one writes, and how a parse reads digits and offsets. */\nexport class TemporalTokens {\n static readonly SUPPORTED =\n 'YYYY YY MM M DD D HH H mm m ss s SSS Z ZZ, and for writing only MMMM MMM dddd ddd dd A a hh h LL L Q';\n\n static readonly WRITE_ONLY_TOKENS: ReadonlySet<TPatternToken> = new Set<TWriteOnlyToken>([\n 'MMMM',\n 'MMM',\n 'dddd',\n 'ddd',\n 'dd',\n 'A',\n 'a',\n 'hh',\n 'h',\n 'LL',\n 'L',\n 'Q',\n ]);\n\n static isWriteOnlyToken(token: TPatternToken): token is TWriteOnlyToken {\n return TemporalTokens.WRITE_ONLY_TOKENS.has(token);\n }\n\n static readonly MAX_COMPILED_PATTERNS = 64;\n\n /** Two-digit years pivot as dayjs and moment do: 00-68 is 2000-2068, 69-99 is 1969-1999. */\n static readonly TWO_DIGIT_YEAR_PIVOT = 68;\n\n /** `[min digits, max digits, field]` for every numeric token a parse reads directly. */\n static readonly NUMERIC_TOKENS: Record<TNumericToken, [number, number, keyof ITemporalParts]> = {\n YYYY: [4, 4, 'year'],\n MM: [2, 2, 'month'],\n M: [1, 2, 'month'],\n DD: [2, 2, 'day'],\n D: [1, 2, 'day'],\n HH: [2, 2, 'hour'],\n H: [1, 2, 'hour'],\n mm: [2, 2, 'minute'],\n m: [1, 2, 'minute'],\n ss: [2, 2, 'second'],\n s: [1, 2, 'second'],\n SSS: [3, 3, 'millisecond'],\n };\n\n static pad(opts: { value: number; width: number }): string {\n return String(opts.value).padStart(opts.width, '0');\n }\n\n /** `+07:00`, or `+07:06:40` for an offset with seconds - historic local mean time has them. */\n static formatOffset(opts: { offsetMinutes: number; separator: string }): string {\n const { offsetMinutes, separator } = opts;\n const sign = offsetMinutes < 0 ? '-' : '+';\n const totalSeconds = Math.round(Math.abs(offsetMinutes) * 60);\n const seconds = totalSeconds % 60;\n\n const text =\n sign +\n TemporalTokens.pad({ value: Math.floor(totalSeconds / 3600), width: 2 }) +\n separator +\n TemporalTokens.pad({ value: Math.floor((totalSeconds % 3600) / 60), width: 2 });\n return seconds === 0\n ? text\n : text + separator + TemporalTokens.pad({ value: seconds, width: 2 });\n }\n\n /** The hour on a 12-hour clock: 12, 1, ... 11. */\n private static twelveHour(opts: { hour: number }): number {\n return opts.hour % 12 || 12;\n }\n\n /** One writer per token - a lookup rather than a branch per token on every format. */\n static readonly WRITERS = new Map<TPatternToken, (input: ITokenWriterInput) => string>([\n ['YYYY', ({ parts }) => TemporalTokens.pad({ value: parts.year, width: 4 })],\n ['YY', ({ parts }) => TemporalTokens.pad({ value: parts.year % 100, width: 2 })],\n [\n 'MMMM',\n ({ parts, locale, names }) =>\n names?.months?.[parts.month - 1] ??\n locale().monthName({ month: parts.month, width: 'long' }),\n ],\n [\n 'MMM',\n ({ parts, locale, names }) =>\n names?.monthsShort?.[parts.month - 1] ??\n locale().monthName({ month: parts.month, width: 'short' }),\n ],\n ['MM', ({ parts }) => TemporalTokens.pad({ value: parts.month, width: 2 })],\n ['M', ({ parts }) => String(parts.month)],\n ['DD', ({ parts }) => TemporalTokens.pad({ value: parts.day, width: 2 })],\n ['D', ({ parts }) => String(parts.day)],\n [\n 'dddd',\n ({ parts, locale, names }) =>\n names?.weekdays?.[parts.dayOfWeek - 1] ??\n locale().weekdayName({ dayOfWeek: parts.dayOfWeek, width: 'long' }),\n ],\n [\n 'ddd',\n ({ parts, locale, names }) =>\n names?.weekdaysShort?.[parts.dayOfWeek - 1] ??\n locale().weekdayName({ dayOfWeek: parts.dayOfWeek, width: 'short' }),\n ],\n [\n 'dd',\n ({ parts, locale, names }) =>\n names?.weekdaysMin?.[parts.dayOfWeek - 1] ??\n locale().weekdayName({ dayOfWeek: parts.dayOfWeek, width: 'narrow' }),\n ],\n ['HH', ({ parts }) => TemporalTokens.pad({ value: parts.hour, width: 2 })],\n ['H', ({ parts }) => String(parts.hour)],\n [\n 'hh',\n ({ parts }) =>\n TemporalTokens.pad({ value: TemporalTokens.twelveHour({ hour: parts.hour }), width: 2 }),\n ],\n ['h', ({ parts }) => String(TemporalTokens.twelveHour({ hour: parts.hour }))],\n [\n 'A',\n ({ parts, locale, names }) =>\n locale().dayPeriod({ hour: parts.hour, meridiem: names?.meridiem }),\n ],\n [\n 'a',\n ({ parts, locale, names }) =>\n locale().dayPeriod({ hour: parts.hour, meridiem: names?.meridiem, isLowerCase: true }),\n ],\n ['mm', ({ parts }) => TemporalTokens.pad({ value: parts.minute, width: 2 })],\n ['m', ({ parts }) => String(parts.minute)],\n ['ss', ({ parts }) => TemporalTokens.pad({ value: parts.second, width: 2 })],\n ['s', ({ parts }) => String(parts.second)],\n ['SSS', ({ parts }) => TemporalTokens.pad({ value: parts.millisecond, width: 3 })],\n [\n 'Z',\n ({ parts }) =>\n TemporalTokens.formatOffset({ offsetMinutes: parts.offsetMinutes, separator: ':' }),\n ],\n [\n 'ZZ',\n ({ parts }) =>\n TemporalTokens.formatOffset({ offsetMinutes: parts.offsetMinutes, separator: '' }),\n ],\n ['LL', ({ parts, locale }) => locale().writtenDate({ parts, style: 'long' })],\n ['L', ({ parts, locale }) => locale().writtenDate({ parts, style: 'numeric' })],\n ['Q', ({ parts }) => String(Math.floor((parts.month - 1) / 3) + 1)],\n ]);\n\n static isLetter(opts: { code: number }): boolean {\n const { code } = opts;\n return (code >= 65 && code <= 90) || (code >= 97 && code <= 122);\n }\n\n static isDigit(opts: { code: number }): boolean {\n return opts.code >= 48 && opts.code <= 57;\n }\n\n /** Reads `min`..`max` digits at `position`, greedily; undefined when fewer than `min` are there. */\n static readDigits(opts: {\n value: string;\n position: number;\n min: number;\n max: number;\n }): { number: number; next: number } | undefined {\n const { value, position, min, max } = opts;\n let next = position;\n let number = 0;\n while (\n next < value.length &&\n next - position < max &&\n TemporalTokens.isDigit({ code: value.charCodeAt(next) })\n ) {\n number = number * 10 + (value.charCodeAt(next) - 48);\n next += 1;\n }\n return next - position < min ? undefined : { number, next };\n }\n\n /** Reads two digits after an optional separator; undefined when either is missing. */\n private static readOffsetField(opts: {\n value: string;\n position: number;\n separator: boolean;\n }): { number: number; next: number } | undefined {\n const { value, position, separator } = opts;\n if (separator && value[position] !== ':') {\n return undefined;\n }\n return TemporalTokens.readDigits({\n value,\n position: separator ? position + 1 : position,\n min: 2,\n max: 2,\n });\n }\n\n /**\n * `Z`, `+07:00` (`Z` token) or `+0700` (`ZZ` token), seconds optional, as milliseconds east\n * of UTC. Hours past 23 and minutes or seconds past 59 are refused rather than rolled over.\n */\n static readOffset(opts: {\n value: string;\n position: number;\n separator: boolean;\n }): { milliseconds: number; next: number } | undefined {\n const { value, position, separator } = opts;\n const sign = value[position];\n if (sign === 'Z') {\n return { milliseconds: 0, next: position + 1 };\n }\n if (sign !== '+' && sign !== '-') {\n return undefined;\n }\n\n const hours = TemporalTokens.readDigits({ value, position: position + 1, min: 2, max: 2 });\n if (!hours) {\n return undefined;\n }\n const minutes = TemporalTokens.readOffsetField({ value, position: hours.next, separator });\n if (!minutes) {\n return undefined;\n }\n const seconds = TemporalTokens.readOffsetField({ value, position: minutes.next, separator });\n\n if (hours.number > 23 || minutes.number > 59 || (seconds && seconds.number > 59)) {\n return undefined;\n }\n\n const total = ((hours.number * 60 + minutes.number) * 60 + (seconds?.number ?? 0)) * 1000;\n return { milliseconds: sign === '-' ? -total : total, next: (seconds ?? minutes).next };\n }\n\n static readonly TOKEN_NAMES: ReadonlySet<string> = new Set(TemporalTokens.WRITERS.keys());\n\n static isToken(run: string): run is TPatternToken {\n return TemporalTokens.TOKEN_NAMES.has(run);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../../../../src/modules/temporal/pattern/tokens.ts"],"names":[],"mappings":";;;AACA,kDAA6F;AAG7F,oGAAoG;AACpG,MAAa,cAAc;aACT,cAAS,GACvB,sGAAsG,CAAC;aAEzF,sBAAiB,GAA+B,yBAAa,CAAC,cAAc,CAAC;IAE7F,MAAM,CAAC,gBAAgB,CAAC,KAAoB;QAC1C,OAAO,cAAc,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK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AO,EAAE,MAAM,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;QAC1F,OAAO,EAAE,YAAY,EAAE,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,OAAO,IAAI,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1F,CAAC;aAEe,gBAAW,GAAwB,IAAI,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAE1F,MAAM,CAAC,OAAO,CAAC,GAAW;QACxB,OAAO,cAAc,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7C,CAAC;;AA7NH,wCA8NC","sourcesContent":["import type { ITemporalParts } from '../common/types';\nimport { PatternTokens, type TPatternToken, type TWriteOnlyToken } from './common/constants';\nimport type { ITokenWriterInput, TNumericToken } from './common/types';\n\n/** The pattern dialect's tokens: what each one writes, and how a parse reads digits and offsets. */\nexport class TemporalTokens {\n static readonly SUPPORTED =\n 'YYYY YY MM M DD D HH H mm m ss s SSS Z ZZ, and for writing only MMMM MMM dddd ddd dd A a hh h LL L Q';\n\n static readonly WRITE_ONLY_TOKENS: ReadonlySet<TPatternToken> = PatternTokens.WRITE_ONLY_SET;\n\n static isWriteOnlyToken(token: TPatternToken): token is TWriteOnlyToken {\n return TemporalTokens.WRITE_ONLY_TOKENS.has(token);\n }\n\n static readonly MAX_COMPILED_PATTERNS = 64;\n\n /** Two-digit years pivot as dayjs and moment do: 00-68 is 2000-2068, 69-99 is 1969-1999. */\n static readonly TWO_DIGIT_YEAR_PIVOT = 68;\n\n /** `[min digits, max digits, field]` for every numeric token a parse reads directly. */\n static readonly NUMERIC_TOKENS: Record<TNumericToken, [number, number, keyof ITemporalParts]> = {\n YYYY: [4, 4, 'year'],\n MM: [2, 2, 'month'],\n M: [1, 2, 'month'],\n DD: [2, 2, 'day'],\n D: [1, 2, 'day'],\n HH: [2, 2, 'hour'],\n H: [1, 2, 'hour'],\n mm: [2, 2, 'minute'],\n m: [1, 2, 'minute'],\n ss: [2, 2, 'second'],\n s: [1, 2, 'second'],\n SSS: [3, 3, 'millisecond'],\n };\n\n static pad(opts: { value: number; width: number }): string {\n return String(opts.value).padStart(opts.width, '0');\n }\n\n /** `+07:00`, or `+07:06:40` for an offset with seconds - historic local mean time has them. */\n static formatOffset(opts: { offsetMinutes: number; separator: string }): string {\n const { offsetMinutes, separator } = opts;\n const sign = offsetMinutes < 0 ? '-' : '+';\n const totalSeconds = Math.round(Math.abs(offsetMinutes) * 60);\n const seconds = totalSeconds % 60;\n\n const text =\n sign +\n TemporalTokens.pad({ value: Math.floor(totalSeconds / 3600), width: 2 }) +\n separator +\n TemporalTokens.pad({ value: Math.floor((totalSeconds % 3600) / 60), width: 2 });\n return seconds === 0\n ? text\n : text + separator + TemporalTokens.pad({ value: seconds, width: 2 });\n }\n\n /** The hour on a 12-hour clock: 12, 1, ... 11. */\n private static twelveHour(opts: { hour: number }): number {\n return opts.hour % 12 || 12;\n }\n\n /** One writer per token - a lookup rather than a branch per token on every format. */\n static readonly WRITERS = new Map<TPatternToken, (input: ITokenWriterInput) => string>([\n ['YYYY', ({ parts }) => TemporalTokens.pad({ value: parts.year, width: 4 })],\n ['YY', ({ parts }) => TemporalTokens.pad({ value: parts.year % 100, width: 2 })],\n [\n 'MMMM',\n ({ parts, locale, names }) =>\n names?.months?.[parts.month - 1] ??\n locale().monthName({ month: parts.month, width: 'long' }),\n ],\n [\n 'MMM',\n ({ parts, locale, names }) =>\n names?.monthsShort?.[parts.month - 1] ??\n locale().monthName({ month: parts.month, width: 'short' }),\n ],\n ['MM', ({ parts }) => TemporalTokens.pad({ value: parts.month, width: 2 })],\n ['M', ({ parts }) => String(parts.month)],\n ['DD', ({ parts }) => TemporalTokens.pad({ value: parts.day, width: 2 })],\n ['D', ({ parts }) => String(parts.day)],\n [\n 'dddd',\n ({ parts, locale, names }) =>\n names?.weekdays?.[parts.dayOfWeek - 1] ??\n locale().weekdayName({ dayOfWeek: parts.dayOfWeek, width: 'long' }),\n ],\n [\n 'ddd',\n ({ parts, locale, names }) =>\n names?.weekdaysShort?.[parts.dayOfWeek - 1] ??\n locale().weekdayName({ dayOfWeek: parts.dayOfWeek, width: 'short' }),\n ],\n [\n 'dd',\n ({ parts, locale, names }) =>\n names?.weekdaysMin?.[parts.dayOfWeek - 1] ??\n locale().weekdayName({ dayOfWeek: parts.dayOfWeek, width: 'narrow' }),\n ],\n ['HH', ({ parts }) => TemporalTokens.pad({ value: parts.hour, width: 2 })],\n ['H', ({ parts }) => String(parts.hour)],\n [\n 'hh',\n ({ parts }) =>\n TemporalTokens.pad({ value: TemporalTokens.twelveHour({ hour: parts.hour }), width: 2 }),\n ],\n ['h', ({ parts }) => String(TemporalTokens.twelveHour({ hour: parts.hour }))],\n [\n 'A',\n ({ parts, locale, names }) =>\n locale().dayPeriod({ hour: parts.hour, meridiem: names?.meridiem }),\n ],\n [\n 'a',\n ({ parts, locale, names }) =>\n locale().dayPeriod({ hour: parts.hour, meridiem: names?.meridiem, isLowerCase: true }),\n ],\n ['mm', ({ parts }) => TemporalTokens.pad({ value: parts.minute, width: 2 })],\n ['m', ({ parts }) => String(parts.minute)],\n ['ss', ({ parts }) => TemporalTokens.pad({ value: parts.second, width: 2 })],\n ['s', ({ parts }) => String(parts.second)],\n ['SSS', ({ parts }) => TemporalTokens.pad({ value: parts.millisecond, width: 3 })],\n [\n 'Z',\n ({ parts }) =>\n TemporalTokens.formatOffset({ offsetMinutes: parts.offsetMinutes, separator: ':' }),\n ],\n [\n 'ZZ',\n ({ parts }) =>\n TemporalTokens.formatOffset({ offsetMinutes: parts.offsetMinutes, separator: '' }),\n ],\n ['LL', ({ parts, locale }) => locale().writtenDate({ parts, style: 'long' })],\n ['L', ({ parts, locale }) => locale().writtenDate({ parts, style: 'numeric' })],\n ['Q', ({ parts }) => String(Math.floor((parts.month - 1) / 3) + 1)],\n ]);\n\n static isLetter(opts: { code: number }): boolean {\n const { code } = opts;\n return (code >= 65 && code <= 90) || (code >= 97 && code <= 122);\n }\n\n static isDigit(opts: { code: number }): boolean {\n return opts.code >= 48 && opts.code <= 57;\n }\n\n /** Reads `min`..`max` digits at `position`, greedily; undefined when fewer than `min` are there. */\n static readDigits(opts: {\n value: string;\n position: number;\n min: number;\n max: number;\n }): { number: number; next: number } | undefined {\n const { value, position, min, max } = opts;\n let next = position;\n let number = 0;\n while (\n next < value.length &&\n next - position < max &&\n TemporalTokens.isDigit({ code: value.charCodeAt(next) })\n ) {\n number = number * 10 + (value.charCodeAt(next) - 48);\n next += 1;\n }\n return next - position < min ? undefined : { number, next };\n }\n\n /** Reads two digits after an optional separator; undefined when either is missing. */\n private static readOffsetField(opts: {\n value: string;\n position: number;\n separator: boolean;\n }): { number: number; next: number } | undefined {\n const { value, position, separator } = opts;\n if (separator && value[position] !== ':') {\n return undefined;\n }\n return TemporalTokens.readDigits({\n value,\n position: separator ? position + 1 : position,\n min: 2,\n max: 2,\n });\n }\n\n /**\n * `Z`, `+07:00` (`Z` token) or `+0700` (`ZZ` token), seconds optional, as milliseconds east\n * of UTC. Hours past 23 and minutes or seconds past 59 are refused rather than rolled over.\n */\n static readOffset(opts: {\n value: string;\n position: number;\n separator: boolean;\n }): { milliseconds: number; next: number } | undefined {\n const { value, position, separator } = opts;\n const sign = value[position];\n if (sign === 'Z') {\n return { milliseconds: 0, next: position + 1 };\n }\n if (sign !== '+' && sign !== '-') {\n return undefined;\n }\n\n const hours = TemporalTokens.readDigits({ value, position: position + 1, min: 2, max: 2 });\n if (!hours) {\n return undefined;\n }\n const minutes = TemporalTokens.readOffsetField({ value, position: hours.next, separator });\n if (!minutes) {\n return undefined;\n }\n const seconds = TemporalTokens.readOffsetField({ value, position: minutes.next, separator });\n\n if (hours.number > 23 || minutes.number > 59 || (seconds && seconds.number > 59)) {\n return undefined;\n }\n\n const total = ((hours.number * 60 + minutes.number) * 60 + (seconds?.number ?? 0)) * 1000;\n return { milliseconds: sign === '-' ? -total : total, next: (seconds ?? minutes).next };\n }\n\n static readonly TOKEN_NAMES: ReadonlySet<string> = new Set(TemporalTokens.WRITERS.keys());\n\n static isToken(run: string): run is TPatternToken {\n return TemporalTokens.TOKEN_NAMES.has(run);\n }\n}\n"]}
|
|
@@ -1,15 +1,25 @@
|
|
|
1
|
+
import type { TConstValue } from '../common/types';
|
|
1
2
|
export interface IRequestedRemark {
|
|
2
3
|
id: string;
|
|
3
4
|
url: string;
|
|
4
5
|
method: string;
|
|
5
6
|
[extra: string | symbol]: any;
|
|
6
7
|
}
|
|
8
|
+
/** Where `parseMultipartBody` keeps an uploaded file: MEMORY (a buffer) or DISK (spooled to `uploadDir`). */
|
|
9
|
+
export declare class MultipartStorages {
|
|
10
|
+
static readonly MEMORY = "memory";
|
|
11
|
+
static readonly DISK = "disk";
|
|
12
|
+
static readonly SCHEME_SET: Set<string>;
|
|
13
|
+
static isValid(value: string): boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Valid multipart storage values. */
|
|
16
|
+
export type TMultipartStorage = TConstValue<typeof MultipartStorages>;
|
|
7
17
|
interface IParseMultipartOptions<C extends {
|
|
8
18
|
req: any;
|
|
9
19
|
} = {
|
|
10
20
|
req: any;
|
|
11
21
|
}> {
|
|
12
|
-
storage?:
|
|
22
|
+
storage?: TMultipartStorage;
|
|
13
23
|
uploadDir?: string;
|
|
14
24
|
context: C;
|
|
15
25
|
}
|
|
@@ -36,9 +46,18 @@ export declare const parseMultipartBody: <C extends {
|
|
|
36
46
|
/** Sanitizes a filename by removing path components and dangerous characters. The result is printable ASCII. */
|
|
37
47
|
export declare const sanitizeFilename: (filename: string) => string;
|
|
38
48
|
export declare const encodeRFC5987: (filename: string) => string;
|
|
49
|
+
/** How a client treats a download: ATTACHMENT saves it, INLINE shows it. */
|
|
50
|
+
export declare class ContentDispositionTypes {
|
|
51
|
+
static readonly ATTACHMENT = "attachment";
|
|
52
|
+
static readonly INLINE = "inline";
|
|
53
|
+
static readonly SCHEME_SET: Set<string>;
|
|
54
|
+
static isValid(value: string): boolean;
|
|
55
|
+
}
|
|
56
|
+
/** Valid Content-Disposition type values. */
|
|
57
|
+
export type TContentDispositionType = TConstValue<typeof ContentDispositionTypes>;
|
|
39
58
|
export declare const createContentDispositionHeader: (opts: {
|
|
40
59
|
filename: string;
|
|
41
|
-
type:
|
|
60
|
+
type: TContentDispositionType;
|
|
42
61
|
}) => string;
|
|
43
62
|
/**
|
|
44
63
|
* Reads a filename out of a `Content-Disposition` value.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.utility.d.ts","sourceRoot":"","sources":["../../../src/utilities/request.utility.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"request.utility.d.ts","sourceRoot":"","sources":["../../../src/utilities/request.utility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAMlD,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;CAC/B;AAED,6GAA6G;AAC7G,qBAAa,iBAAiB;IAC5B,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAClC,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;IAE9B,MAAM,CAAC,QAAQ,CAAC,UAAU,cAA6C;IAEvE,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAGvC;AAED,sCAAsC;AACtC,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEtE,UAAU,sBAAsB,CAAC,CAAC,SAAS;IAAE,GAAG,EAAE,GAAG,CAAA;CAAE,GAAG;IAAE,GAAG,EAAE,GAAG,CAAA;CAAE;IACpE,OAAO,CAAC,EAAE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Q,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,uBAAuB,CAAC;CAC/B,KAAG,MAWH,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,GAAI,MAAM;IAC5C,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACnC,KAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CA8BrC,CAAC"}
|
|
@@ -3,14 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parseContentDisposition = exports.createContentDispositionHeader = exports.encodeRFC5987 = exports.sanitizeFilename = exports.parseMultipartBody = void 0;
|
|
6
|
+
exports.parseContentDisposition = exports.createContentDispositionHeader = exports.ContentDispositionTypes = exports.encodeRFC5987 = exports.sanitizeFilename = exports.parseMultipartBody = exports.MultipartStorages = void 0;
|
|
7
7
|
const error_1 = require("../modules/error");
|
|
8
8
|
const form_body_utility_1 = require("./form-body.utility");
|
|
9
9
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
10
10
|
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
/** Where `parseMultipartBody` keeps an uploaded file: MEMORY (a buffer) or DISK (spooled to `uploadDir`). */
|
|
12
|
+
class MultipartStorages {
|
|
13
|
+
static { this.MEMORY = 'memory'; }
|
|
14
|
+
static { this.DISK = 'disk'; }
|
|
15
|
+
static { this.SCHEME_SET = new Set([this.MEMORY, this.DISK]); }
|
|
16
|
+
static isValid(value) {
|
|
17
|
+
return this.SCHEME_SET.has(value);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.MultipartStorages = MultipartStorages;
|
|
11
21
|
const parseMultipartBody = async (opts) => {
|
|
12
|
-
const { storage =
|
|
13
|
-
if (storage ===
|
|
22
|
+
const { storage = MultipartStorages.MEMORY, uploadDir = './uploads', context } = opts;
|
|
23
|
+
if (storage === MultipartStorages.DISK && !node_fs_1.default.existsSync(uploadDir)) {
|
|
14
24
|
node_fs_1.default.mkdirSync(uploadDir, { recursive: true });
|
|
15
25
|
}
|
|
16
26
|
const formData = await (0, form_body_utility_1.readFormBody)({ req: context.req });
|
|
@@ -34,11 +44,11 @@ const parseMultipartBody = async (opts) => {
|
|
|
34
44
|
size: file.size,
|
|
35
45
|
};
|
|
36
46
|
switch (storage) {
|
|
37
|
-
case
|
|
47
|
+
case MultipartStorages.MEMORY: {
|
|
38
48
|
parsedFile.buffer = buffer;
|
|
39
49
|
break;
|
|
40
50
|
}
|
|
41
|
-
case
|
|
51
|
+
case MultipartStorages.DISK: {
|
|
42
52
|
const timestamp = Date.now();
|
|
43
53
|
const randomString = Math.random().toString(36).substring(7);
|
|
44
54
|
// Sanitize filename to prevent path traversal
|
|
@@ -83,6 +93,16 @@ exports.encodeRFC5987 = encodeRFC5987;
|
|
|
83
93
|
/** Control, format (bidi overrides, zero-width space) and lone surrogate characters: a format character reorders the name a client shows, a lone surrogate makes `encodeURIComponent` throw. The zero-width joiner and non-joiner stay: they build emoji sequences and Persian words, and reorder nothing. */
|
|
84
94
|
const UNENCODABLE_FILENAME_CHARACTERS = /(?![\u200C\u200D])[\p{Cc}\p{Cf}\p{Cs}]/gu;
|
|
85
95
|
const LEADING_DOTS = /^\.+/;
|
|
96
|
+
/** How a client treats a download: ATTACHMENT saves it, INLINE shows it. */
|
|
97
|
+
class ContentDispositionTypes {
|
|
98
|
+
static { this.ATTACHMENT = 'attachment'; }
|
|
99
|
+
static { this.INLINE = 'inline'; }
|
|
100
|
+
static { this.SCHEME_SET = new Set([this.ATTACHMENT, this.INLINE]); }
|
|
101
|
+
static isValid(value) {
|
|
102
|
+
return this.SCHEME_SET.has(value);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.ContentDispositionTypes = ContentDispositionTypes;
|
|
86
106
|
const createContentDispositionHeader = (opts) => {
|
|
87
107
|
const { filename, type } = opts;
|
|
88
108
|
const sanitized = (0, exports.sanitizeFilename)(filename);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.utility.js","sourceRoot":"","sources":["../../../src/utilities/request.utility.ts"],"names":[],"mappings":";;;;;;AAAA,2CAA2C;AAC3C,2DAAmD;AACnD,sDAAyB;AACzB,0DAA6B;AAgCtB,MAAM,kBAAkB,GAAG,KAAK,EACrC,IAA+B,EACA,EAAE;IACjC,MAAM,EAAE,OAAO,GAAG,QAAQ,EAAE,SAAS,GAAG,WAAW,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEtE,IAAI,OAAO,KAAK,MAAM,IAAI,CAAC,iBAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACpD,iBAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,IAAA,gCAAY,EAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC1D,MAAM,KAAK,GAAkB,EAAE,CAAC;IAChC,MAAM,MAAM,GAA2B,EAAE,CAAC;IAE1C,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC;IACnC,KAAK,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;QACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,kDAAkD;YAClD,MAAM,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;YAC1B,SAAS;QACX,CAAC;QAED,MAAM,IAAI,GAAG,KAAa,CAAC;QAC3B,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAC7C,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC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,0FAA0F;QAC5F,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;IACzD,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACvC,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACrD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAC/D,CAAC,CAAC;AAhCW,QAAA,uBAAuB,2BAgClC","sourcesContent":["import { getError } from '@/modules/error';\nimport { readFormBody } from './form-body.utility';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nexport interface IRequestedRemark {\n id: string;\n url: string;\n method: string;\n [extra: string | symbol]: any;\n}\n\ninterface IParseMultipartOptions<C extends { req: any } = { req: any }> {\n storage?: 'memory' | 'disk';\n uploadDir?: string;\n context: C;\n}\n\ninterface IParsedFile {\n fieldname: string;\n originalname: string;\n encoding: string;\n mimetype: string;\n size: number;\n buffer?: Buffer;\n filename?: string;\n path?: string;\n}\n\n/** Files and the text fields posted beside them - dropping the second silently loses what the client sent. */\nexport interface IParsedMultipartBody {\n files: IParsedFile[];\n fields: Record<string, string>;\n}\n\nexport const parseMultipartBody = async <C extends { req: any } = { req: any }>(\n opts: IParseMultipartOptions<C>,\n): Promise<IParsedMultipartBody> => {\n const { storage = 'memory', uploadDir = './uploads', context } = opts;\n\n if (storage === 'disk' && !fs.existsSync(uploadDir)) {\n fs.mkdirSync(uploadDir, { recursive: true });\n }\n\n const formData = await readFormBody({ req: context.req });\n const files: IParsedFile[] = [];\n const fields: Record<string, string> = {};\n\n const entries = formData.entries();\n for (const [fieldname, value] of entries) {\n if (typeof value === 'string') {\n // Last one wins, like a repeated query parameter.\n fields[fieldname] = value;\n continue;\n }\n\n const file = value as File;\n const arrayBuffer = await file.arrayBuffer();\n const buffer = Buffer.from(arrayBuffer);\n\n const parsedFile: IParsedFile = {\n fieldname,\n originalname: file.name,\n encoding: 'utf8',\n mimetype: file.type,\n size: file.size,\n };\n\n switch (storage) {\n case 'memory': {\n parsedFile.buffer = buffer;\n break;\n }\n case 'disk': {\n const timestamp = Date.now();\n const randomString = Math.random().toString(36).substring(7);\n // Sanitize filename to prevent path traversal\n const sanitizedName = path.basename(file.name).replace(/[^a-zA-Z0-9._-]/g, '_');\n const filename = `${timestamp}-${randomString}-${sanitizedName}`;\n const filepath = path.join(uploadDir, filename);\n\n fs.writeFileSync(filepath, buffer);\n\n parsedFile.filename = filename;\n parsedFile.path = filepath;\n break;\n }\n default: {\n throw getError({\n message: `[parseMultipartBody] storage: ${storage} | Invalid storage type | Valids: ['memory', 'disk']`,\n });\n }\n }\n\n files.push(parsedFile);\n }\n\n return { files, fields };\n};\n\n/** Sanitizes a filename by removing path components and dangerous characters. The result is printable ASCII. */\nexport const sanitizeFilename = (filename: string): string => {\n const basename = path.basename(filename);\n let sanitized = basename.replace(/[^\\w .-]/g, '_');\n sanitized = sanitized.replace(/^\\.+/, '');\n sanitized = sanitized.replace(/\\.{2,}/g, '.');\n sanitized = sanitized.replace(/\\.\\./g, '.');\n if (!sanitized || sanitized === '.' || sanitized.includes('..')) {\n sanitized = 'download';\n }\n return sanitized;\n};\n\nexport const encodeRFC5987 = (filename: string): string => {\n return encodeURIComponent(filename)\n .replace(/['()]/g, (c) => '%' + c.charCodeAt(0).toString(16).toUpperCase())\n .replace(/\\*/g, '%2A');\n};\n\n/** Control, format (bidi overrides, zero-width space) and lone surrogate characters: a format character reorders the name a client shows, a lone surrogate makes `encodeURIComponent` throw. The zero-width joiner and non-joiner stay: they build emoji sequences and Persian words, and reorder nothing. */\nconst UNENCODABLE_FILENAME_CHARACTERS = /(?![\\u200C\\u200D])[\\p{Cc}\\p{Cf}\\p{Cs}]/gu;\nconst LEADING_DOTS = /^\\.+/;\n\nexport const createContentDispositionHeader = (opts: {\n filename: string;\n type: 'attachment' | 'inline';\n}): string => {\n const { filename, type } = opts;\n const sanitized = sanitizeFilename(filename);\n const extendedName = path\n .basename(filename)\n .replace(UNENCODABLE_FILENAME_CHARACTERS, '_')\n .replace(LEADING_DOTS, '');\n const encoded = encodeRFC5987(extendedName || sanitized);\n\n // filename= is the ASCII fallback for old browsers, filename*= the UTF-8 form for modern ones.\n return `${type}; filename=\"${sanitized}\"; filename*=UTF-8''${encoded}`;\n};\n\n/**\n * Reads a filename out of a `Content-Disposition` value.\n *\n * Three forms, in the order the RFC gives them precedence: `filename*=UTF-8''...` (percent-encoded,\n * and the one hand-rolled parsers miss), a quoted `filename=\"...\"`, and a bare `filename=...`.\n * Splitting on `filename=` alone returns the percent-encoded bytes for any non-ASCII name, which in\n * a product with non-English filenames is most of them.\n *\n * The pair of {@link createContentDispositionHeader}: one writes the header, this one reads it.\n */\nexport const parseContentDisposition = (opts: {\n header: string | null | undefined;\n}): { type?: string; filename?: string } => {\n const { header } = opts;\n\n if (!header) {\n return {};\n }\n\n const type = header.split(';')[0]?.trim() || undefined;\n\n // `filename*` wins when both are present - it is the one that can carry a non-ASCII name.\n const extended = header.match(/filename\\*\\s*=\\s*([^;]+)/i);\n if (extended) {\n const value = extended[1].trim();\n // `UTF-8''name` or `UTF-8'lang'name`; anything before the last quote is charset and language.\n const encoded = value.slice(value.lastIndexOf(\"'\") + 1);\n\n try {\n return { type, filename: decodeURIComponent(encoded) };\n } catch {\n // A malformed sequence is not worth failing a download over - fall through to `filename`.\n }\n }\n\n const quoted = header.match(/filename\\s*=\\s*\"([^\"]*)\"/i);\n if (quoted) {\n return { type, filename: quoted[1] };\n }\n\n const bare = header.match(/filename\\s*=\\s*([^;]+)/i);\n return { type, filename: bare ? bare[1].trim() : undefined };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"request.utility.js","sourceRoot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AAI,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,SAAS,CAAC;IAEvD,0FAA0F;IAC1F,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC3D,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACjC,8FAA8F;QAC9F,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QAExD,IAAI,CAAC;YACH,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;QACzD,CAAC;QAAC,MAAM,CAAC;YACP,0FAA0F;QAC5F,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;IACzD,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACvC,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACrD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AAC/D,CAAC,CAAC;AAhCW,QAAA,uBAAuB,2BAgClC","sourcesContent":["import type { TConstValue } from '@/common/types';\nimport { getError } from '@/modules/error';\nimport { readFormBody } from './form-body.utility';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nexport interface IRequestedRemark {\n id: string;\n url: string;\n method: string;\n [extra: string | symbol]: any;\n}\n\n/** Where `parseMultipartBody` keeps an uploaded file: MEMORY (a buffer) or DISK (spooled to `uploadDir`). */\nexport class MultipartStorages {\n static readonly MEMORY = 'memory';\n static readonly DISK = 'disk';\n\n static readonly SCHEME_SET = new Set<string>([this.MEMORY, this.DISK]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid multipart storage values. */\nexport type TMultipartStorage = TConstValue<typeof MultipartStorages>;\n\ninterface IParseMultipartOptions<C extends { req: any } = { req: any }> {\n storage?: TMultipartStorage;\n uploadDir?: string;\n context: C;\n}\n\ninterface IParsedFile {\n fieldname: string;\n originalname: string;\n encoding: string;\n mimetype: string;\n size: number;\n buffer?: Buffer;\n filename?: string;\n path?: string;\n}\n\n/** Files and the text fields posted beside them - dropping the second silently loses what the client sent. */\nexport interface IParsedMultipartBody {\n files: IParsedFile[];\n fields: Record<string, string>;\n}\n\nexport const parseMultipartBody = async <C extends { req: any } = { req: any }>(\n opts: IParseMultipartOptions<C>,\n): Promise<IParsedMultipartBody> => {\n const { storage = MultipartStorages.MEMORY, uploadDir = './uploads', context } = opts;\n\n if (storage === MultipartStorages.DISK && !fs.existsSync(uploadDir)) {\n fs.mkdirSync(uploadDir, { recursive: true });\n }\n\n const formData = await readFormBody({ req: context.req });\n const files: IParsedFile[] = [];\n const fields: Record<string, string> = {};\n\n const entries = formData.entries();\n for (const [fieldname, value] of entries) {\n if (typeof value === 'string') {\n // Last one wins, like a repeated query parameter.\n fields[fieldname] = value;\n continue;\n }\n\n const file = value as File;\n const arrayBuffer = await file.arrayBuffer();\n const buffer = Buffer.from(arrayBuffer);\n\n const parsedFile: IParsedFile = {\n fieldname,\n originalname: file.name,\n encoding: 'utf8',\n mimetype: file.type,\n size: file.size,\n };\n\n switch (storage) {\n case MultipartStorages.MEMORY: {\n parsedFile.buffer = buffer;\n break;\n }\n case MultipartStorages.DISK: {\n const timestamp = Date.now();\n const randomString = Math.random().toString(36).substring(7);\n // Sanitize filename to prevent path traversal\n const sanitizedName = path.basename(file.name).replace(/[^a-zA-Z0-9._-]/g, '_');\n const filename = `${timestamp}-${randomString}-${sanitizedName}`;\n const filepath = path.join(uploadDir, filename);\n\n fs.writeFileSync(filepath, buffer);\n\n parsedFile.filename = filename;\n parsedFile.path = filepath;\n break;\n }\n default: {\n throw getError({\n message: `[parseMultipartBody] storage: ${storage} | Invalid storage type | Valids: ['memory', 'disk']`,\n });\n }\n }\n\n files.push(parsedFile);\n }\n\n return { files, fields };\n};\n\n/** Sanitizes a filename by removing path components and dangerous characters. The result is printable ASCII. */\nexport const sanitizeFilename = (filename: string): string => {\n const basename = path.basename(filename);\n let sanitized = basename.replace(/[^\\w .-]/g, '_');\n sanitized = sanitized.replace(/^\\.+/, '');\n sanitized = sanitized.replace(/\\.{2,}/g, '.');\n sanitized = sanitized.replace(/\\.\\./g, '.');\n if (!sanitized || sanitized === '.' || sanitized.includes('..')) {\n sanitized = 'download';\n }\n return sanitized;\n};\n\nexport const encodeRFC5987 = (filename: string): string => {\n return encodeURIComponent(filename)\n .replace(/['()]/g, (c) => '%' + c.charCodeAt(0).toString(16).toUpperCase())\n .replace(/\\*/g, '%2A');\n};\n\n/** Control, format (bidi overrides, zero-width space) and lone surrogate characters: a format character reorders the name a client shows, a lone surrogate makes `encodeURIComponent` throw. The zero-width joiner and non-joiner stay: they build emoji sequences and Persian words, and reorder nothing. */\nconst UNENCODABLE_FILENAME_CHARACTERS = /(?![\\u200C\\u200D])[\\p{Cc}\\p{Cf}\\p{Cs}]/gu;\nconst LEADING_DOTS = /^\\.+/;\n\n/** How a client treats a download: ATTACHMENT saves it, INLINE shows it. */\nexport class ContentDispositionTypes {\n static readonly ATTACHMENT = 'attachment';\n static readonly INLINE = 'inline';\n\n static readonly SCHEME_SET = new Set<string>([this.ATTACHMENT, this.INLINE]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid Content-Disposition type values. */\nexport type TContentDispositionType = TConstValue<typeof ContentDispositionTypes>;\n\nexport const createContentDispositionHeader = (opts: {\n filename: string;\n type: TContentDispositionType;\n}): string => {\n const { filename, type } = opts;\n const sanitized = sanitizeFilename(filename);\n const extendedName = path\n .basename(filename)\n .replace(UNENCODABLE_FILENAME_CHARACTERS, '_')\n .replace(LEADING_DOTS, '');\n const encoded = encodeRFC5987(extendedName || sanitized);\n\n // filename= is the ASCII fallback for old browsers, filename*= the UTF-8 form for modern ones.\n return `${type}; filename=\"${sanitized}\"; filename*=UTF-8''${encoded}`;\n};\n\n/**\n * Reads a filename out of a `Content-Disposition` value.\n *\n * Three forms, in the order the RFC gives them precedence: `filename*=UTF-8''...` (percent-encoded,\n * and the one hand-rolled parsers miss), a quoted `filename=\"...\"`, and a bare `filename=...`.\n * Splitting on `filename=` alone returns the percent-encoded bytes for any non-ASCII name, which in\n * a product with non-English filenames is most of them.\n *\n * The pair of {@link createContentDispositionHeader}: one writes the header, this one reads it.\n */\nexport const parseContentDisposition = (opts: {\n header: string | null | undefined;\n}): { type?: string; filename?: string } => {\n const { header } = opts;\n\n if (!header) {\n return {};\n }\n\n const type = header.split(';')[0]?.trim() || undefined;\n\n // `filename*` wins when both are present - it is the one that can carry a non-ASCII name.\n const extended = header.match(/filename\\*\\s*=\\s*([^;]+)/i);\n if (extended) {\n const value = extended[1].trim();\n // `UTF-8''name` or `UTF-8'lang'name`; anything before the last quote is charset and language.\n const encoded = value.slice(value.lastIndexOf(\"'\") + 1);\n\n try {\n return { type, filename: decodeURIComponent(encoded) };\n } catch {\n // A malformed sequence is not worth failing a download over - fall through to `filename`.\n }\n }\n\n const quoted = header.match(/filename\\s*=\\s*\"([^\"]*)\"/i);\n if (quoted) {\n return { type, filename: quoted[1] };\n }\n\n const bare = header.match(/filename\\s*=\\s*([^;]+)/i);\n return { type, filename: bare ? bare[1].trim() : undefined };\n};\n"]}
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import type { TConstValue } from './const-value.js';
|
|
2
|
+
/** The value kinds a field mapping reads. */
|
|
3
|
+
export declare class FieldMappingDataTypes {
|
|
4
|
+
static readonly STRING = "string";
|
|
5
|
+
static readonly NUMBER = "number";
|
|
6
|
+
static readonly STRINGS = "strings";
|
|
7
|
+
static readonly NUMBERS = "numbers";
|
|
8
|
+
static readonly BOOLEAN = "boolean";
|
|
9
|
+
static readonly SCHEME_SET: Set<string>;
|
|
10
|
+
static isValid(value: string): boolean;
|
|
11
|
+
}
|
|
12
|
+
/** Valid field mapping data type values. */
|
|
13
|
+
export type TFieldMappingDataType = TConstValue<typeof FieldMappingDataTypes>;
|
|
2
14
|
export interface IFieldMapping {
|
|
3
15
|
name: string;
|
|
4
16
|
type: TFieldMappingDataType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-mapping.d.ts","sourceRoot":"","sources":["../../../../src/common/types/field-mapping.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"field-mapping.d.ts","sourceRoot":"","sources":["../../../../src/common/types/field-mapping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,6CAA6C;AAC7C,qBAAa,qBAAqB;IAChC,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAClC,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAClC,MAAM,CAAC,QAAQ,CAAC,OAAO,aAAa;IACpC,MAAM,CAAC,QAAQ,CAAC,OAAO,aAAa;IACpC,MAAM,CAAC,QAAQ,CAAC,OAAO,aAAa;IAEpC,MAAM,CAAC,QAAQ,CAAC,UAAU,cAMvB;IAEH,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAGvC;AAED,4CAA4C;AAC5C,MAAM,MAAM,qBAAqB,GAAG,WAAW,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAE9E,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,qBAAqB,CAAC;IAC5B,OAAO,CAA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ACR,CAAC,SAAS;QACN,IAAI,EAAE,CAAC,CAAC;QACR,IAAI,EAAE,SAAS,CAAC;QAChB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KAC/B,GACD,MAAM,EAAE,GACR,KAAK;CAClB,CAAC"}
|
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/** The value kinds a field mapping reads. */
|
|
2
|
+
export class FieldMappingDataTypes {
|
|
3
|
+
static { this.STRING = 'string'; }
|
|
4
|
+
static { this.NUMBER = 'number'; }
|
|
5
|
+
static { this.STRINGS = 'strings'; }
|
|
6
|
+
static { this.NUMBERS = 'numbers'; }
|
|
7
|
+
static { this.BOOLEAN = 'boolean'; }
|
|
8
|
+
static { this.SCHEME_SET = new Set([
|
|
9
|
+
this.STRING,
|
|
10
|
+
this.NUMBER,
|
|
11
|
+
this.STRINGS,
|
|
12
|
+
this.NUMBERS,
|
|
13
|
+
this.BOOLEAN,
|
|
14
|
+
]); }
|
|
15
|
+
static isValid(value) {
|
|
16
|
+
return this.SCHEME_SET.has(value);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
2
19
|
//# sourceMappingURL=field-mapping.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-mapping.js","sourceRoot":"","sources":["../../../../src/common/types/field-mapping.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"field-mapping.js","sourceRoot":"","sources":["../../../../src/common/types/field-mapping.ts"],"names":[],"mappings":"AAEA,6CAA6C;AAC7C,MAAM,OAAO,qBAAqB;aAChB,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,YAAO,GAAG,SAAS,CAAC;aACpB,YAAO,GAAG,SAAS,CAAC;aACpB,YAAO,GAAG,SAAS,CAAC;aAEpB,eAAU,GAAG,IAAI,GAAG,CAAS;QAC3C,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,OAAO;QACZ,IAAI,CAAC,OAAO;KACb,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC","sourcesContent":["import type { TConstValue } from './const-value';\n\n/** The value kinds a field mapping reads. */\nexport class FieldMappingDataTypes {\n static readonly STRING = 'string';\n static readonly NUMBER = 'number';\n static readonly STRINGS = 'strings';\n static readonly NUMBERS = 'numbers';\n static readonly BOOLEAN = 'boolean';\n\n static readonly SCHEME_SET = new Set<string>([\n this.STRING,\n this.NUMBER,\n this.STRINGS,\n this.NUMBERS,\n this.BOOLEAN,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid field mapping data type values. */\nexport type TFieldMappingDataType = TConstValue<typeof FieldMappingDataTypes>;\n\nexport interface IFieldMapping {\n name: string;\n type: TFieldMappingDataType;\n default?: string | number | Array<string> | Array<number> | boolean;\n}\n\nexport type TFieldMappingNames<T extends Array<IFieldMapping>> = Extract<\n T[number],\n { type: Exclude<T[number]['type'], undefined> }\n>['name'];\n\nexport type TObjectFromFieldMappings<\n T extends readonly {\n name: string;\n type: string;\n [extra: string | symbol]: any;\n }[],\n> = {\n [K in T[number]['name']]: T extends {\n name: K;\n type: 'string';\n [extra: string | symbol]: any;\n }\n ? string\n : T extends { name: K; type: 'number'; [extra: string | symbol]: any }\n ? number\n : T extends { name: K; type: 'boolean'; [extra: string | symbol]: any }\n ? boolean\n : T extends { name: K; type: 'strings'; [extra: string | symbol]: any }\n ? string[]\n : T extends {\n name: K;\n type: 'numbers';\n [extra: string | symbol]: any;\n }\n ? number[]\n : never;\n};\n"]}
|
package/dist/esm/core.d.ts
CHANGED
|
@@ -28,7 +28,8 @@ export { blankToUndefined, int, keysToCamel, toBoolean, toCamel } from './utilit
|
|
|
28
28
|
export { executeWithPerformanceMeasure } from './utilities/performance.utility.js';
|
|
29
29
|
export { readFormBody, RequestBodyErrors } from './utilities/form-body.utility.js';
|
|
30
30
|
export { ProjectRootRegistry } from './utilities/project-root.utility.js';
|
|
31
|
-
export
|
|
31
|
+
export { AESAlgorithms } from './modules/crypto/algorithms/aes.constants.js';
|
|
32
|
+
export type { AESAlgorithmType } from './modules/crypto/algorithms/aes.constants.js';
|
|
32
33
|
export type { IPayloadCipher } from './modules/crypto/common/types.js';
|
|
33
34
|
export type { IRedisHelper } from './modules/redis/common/interfaces.js';
|
|
34
35
|
//# sourceMappingURL=core.d.ts.map
|
package/dist/esm/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,YAAY,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AACzF,cAAc,qDAAqD,CAAC;AAIpE,cAAc,qDAAqD,CAAC;AACpE,cAAc,4DAA4D,CAAC;AAC3E,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAG9B,cAAc,yDAAyD,CAAC;AACxE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qDAAqD,CAAC;AAC5F,cAAc,+CAA+C,CAAC;AAC9D,cAAc,0CAA0C,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAC5F,YAAY,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAChG,YAAY,EAA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AChF,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAKvE,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAC1E,YAAY,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAClF,YAAY,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,YAAY,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC"}
|
package/dist/esm/core.js
CHANGED
|
@@ -33,4 +33,8 @@ export { blankToUndefined, int, keysToCamel, toBoolean, toCamel } from './utilit
|
|
|
33
33
|
export { executeWithPerformanceMeasure } from './utilities/performance.utility.js';
|
|
34
34
|
export { readFormBody, RequestBodyErrors } from './utilities/form-body.utility.js';
|
|
35
35
|
export { ProjectRootRegistry } from './utilities/project-root.utility.js';
|
|
36
|
+
// Type-only: erased at compile time, so re-exporting these carries no runtime/bundle cost even
|
|
37
|
+
// though the concrete classes they describe (crypto algorithms, the ioredis-backed helper) are not
|
|
38
|
+
// themselves part of this pure surface.
|
|
39
|
+
export { AESAlgorithms } from './modules/crypto/algorithms/aes.constants.js';
|
|
36
40
|
//# sourceMappingURL=core.js.map
|
package/dist/esm/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,6FAA6F;AAC7F,8DAA8D;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,cAAc,qDAAqD,CAAC;AACpE,qGAAqG;AACrG,4FAA4F;AAC5F,oBAAoB;AACpB,cAAc,qDAAqD,CAAC;AACpE,cAAc,4DAA4D,CAAC;AAC3E,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,iGAAiG;AACjG,yFAAyF;AACzF,cAAc,yDAAyD,CAAC;AAExE,cAAc,+CAA+C,CAAC;AAC9D,cAAc,0CAA0C,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAG5F,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAcrD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,gGAAgG;AAChG,6FAA6F;AAC7F,iGAAiG;AACjG,0DAA0D;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACnG,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC","sourcesContent":["export { BaseHelper } from './modules/base';\n// By name, never `export *` from `./modules/env`: that barrel also carries `Environment` and\n// `applicationEnvironment`, both of which read `process.env`.\nexport { EnvironmentNames } from './modules/env/names';\nexport * from './modules/error';\nexport { LogLevels } from './modules/logger/common/types';\nexport type { ILogger, ILoggerProvider, TLogLevel } from './modules/logger/common/types';\nexport * from './modules/network/http-request/fetcher/base-fetcher';\n// The node fetcher carries no node builtin - its one `querystring.stringify` is written out - so the\n// framework HTTP layer is reachable from a browser bundle, and a connector on HTTP need not\n// re-implement one.\nexport * from './modules/network/http-request/fetcher/node-fetcher';\nexport * from './modules/network/http-request/base-network-request.helper';\nexport * from './modules/pool';\nexport * from './modules/queue/internal/hf';\nexport * from './modules/temporal';\nexport * from './modules/uid';\n// The url guard, pure half only: `UrlPolicy` decides a url and a literal address with string and\n// number work. Its sibling `UrlIngest` reaches `node:dns` and stays out of this subpath.\nexport * from './modules/network/utilities/url-safety/common/constants';\nexport type { IUrlSafetyPolicy } from './modules/network/utilities/url-safety/common/types';\nexport * from './modules/network/utilities/url-safety/policy';\nexport * from './modules/network/utilities/query-string';\nexport { RetryBackoffStrategies, RetryJitterModes } from './modules/retry/common/constants';\nexport type { TRetryBackoffStrategy, TRetryJitterMode } from './modules/retry/common/constants';\nexport type { IRetryBackoffOptions, IRetryContext } from './modules/retry/common/types';\nexport { RetryHelper } from './modules/retry/helper';\nexport { SlugHelper } from './modules/slug/helper';\nexport { TreeBuilder } from './modules/tree/builder';\nexport type {\n IBuildOptions,\n IHeightWhereOptions,\n ILeavesOptions,\n INodeWithPath,\n IPrintOptions,\n ITreeNode,\n IWalkAsyncOptions,\n IWalkOptions,\n TNodePredicate,\n TOnVisit,\n TOnVisitAsync,\n} from './modules/tree/common/types';\nexport { TreeWalker } from './modules/tree/walk';\n\n// Pure value/type utilities that already live under the root barrel's `./utilities` re-export -\n// that barrel also carries node-only siblings (module.utility.ts, request.utility.ts), so it\n// cannot itself become a subpath. Named one at a time here instead of widening the barrel: every\n// symbol below is verified free of node builtins/globals.\nexport { BuildInfoRegistry } from './utilities/build-info.utility';\nexport type { IBuildInfo, TBuildInfoRecord } from './utilities/build-info.utility';\nexport { blankToUndefined, int, keysToCamel, toBoolean, toCamel } from './utilities/parse.utility';\nexport { executeWithPerformanceMeasure } from './utilities/performance.utility';\nexport { readFormBody, RequestBodyErrors } from './utilities/form-body.utility';\nexport { ProjectRootRegistry } from './utilities/project-root.utility';\n\n// Type-only: erased at compile time, so re-exporting these carries no runtime/bundle cost even\n// though the concrete classes they describe (crypto algorithms, the ioredis-backed helper) are not\n// themselves part of this pure surface.\nexport type { AESAlgorithmType } from './modules/crypto/algorithms/aes.
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,6FAA6F;AAC7F,8DAA8D;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,cAAc,qDAAqD,CAAC;AACpE,qGAAqG;AACrG,4FAA4F;AAC5F,oBAAoB;AACpB,cAAc,qDAAqD,CAAC;AACpE,cAAc,4DAA4D,CAAC;AAC3E,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,iGAAiG;AACjG,yFAAyF;AACzF,cAAc,yDAAyD,CAAC;AAExE,cAAc,+CAA+C,CAAC;AAC9D,cAAc,0CAA0C,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAG5F,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAcrD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,gGAAgG;AAChG,6FAA6F;AAC7F,iGAAiG;AACjG,0DAA0D;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACnG,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,+FAA+F;AAC/F,mGAAmG;AACnG,wCAAwC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC","sourcesContent":["export { BaseHelper } from './modules/base';\n// By name, never `export *` from `./modules/env`: that barrel also carries `Environment` and\n// `applicationEnvironment`, both of which read `process.env`.\nexport { EnvironmentNames } from './modules/env/names';\nexport * from './modules/error';\nexport { LogLevels } from './modules/logger/common/types';\nexport type { ILogger, ILoggerProvider, TLogLevel } from './modules/logger/common/types';\nexport * from './modules/network/http-request/fetcher/base-fetcher';\n// The node fetcher carries no node builtin - its one `querystring.stringify` is written out - so the\n// framework HTTP layer is reachable from a browser bundle, and a connector on HTTP need not\n// re-implement one.\nexport * from './modules/network/http-request/fetcher/node-fetcher';\nexport * from './modules/network/http-request/base-network-request.helper';\nexport * from './modules/pool';\nexport * from './modules/queue/internal/hf';\nexport * from './modules/temporal';\nexport * from './modules/uid';\n// The url guard, pure half only: `UrlPolicy` decides a url and a literal address with string and\n// number work. Its sibling `UrlIngest` reaches `node:dns` and stays out of this subpath.\nexport * from './modules/network/utilities/url-safety/common/constants';\nexport type { IUrlSafetyPolicy } from './modules/network/utilities/url-safety/common/types';\nexport * from './modules/network/utilities/url-safety/policy';\nexport * from './modules/network/utilities/query-string';\nexport { RetryBackoffStrategies, RetryJitterModes } from './modules/retry/common/constants';\nexport type { TRetryBackoffStrategy, TRetryJitterMode } from './modules/retry/common/constants';\nexport type { IRetryBackoffOptions, IRetryContext } from './modules/retry/common/types';\nexport { RetryHelper } from './modules/retry/helper';\nexport { SlugHelper } from './modules/slug/helper';\nexport { TreeBuilder } from './modules/tree/builder';\nexport type {\n IBuildOptions,\n IHeightWhereOptions,\n ILeavesOptions,\n INodeWithPath,\n IPrintOptions,\n ITreeNode,\n IWalkAsyncOptions,\n IWalkOptions,\n TNodePredicate,\n TOnVisit,\n TOnVisitAsync,\n} from './modules/tree/common/types';\nexport { TreeWalker } from './modules/tree/walk';\n\n// Pure value/type utilities that already live under the root barrel's `./utilities` re-export -\n// that barrel also carries node-only siblings (module.utility.ts, request.utility.ts), so it\n// cannot itself become a subpath. Named one at a time here instead of widening the barrel: every\n// symbol below is verified free of node builtins/globals.\nexport { BuildInfoRegistry } from './utilities/build-info.utility';\nexport type { IBuildInfo, TBuildInfoRecord } from './utilities/build-info.utility';\nexport { blankToUndefined, int, keysToCamel, toBoolean, toCamel } from './utilities/parse.utility';\nexport { executeWithPerformanceMeasure } from './utilities/performance.utility';\nexport { readFormBody, RequestBodyErrors } from './utilities/form-body.utility';\nexport { ProjectRootRegistry } from './utilities/project-root.utility';\n\n// Type-only: erased at compile time, so re-exporting these carries no runtime/bundle cost even\n// though the concrete classes they describe (crypto algorithms, the ioredis-backed helper) are not\n// themselves part of this pure surface.\nexport { AESAlgorithms } from './modules/crypto/algorithms/aes.constants';\nexport type { AESAlgorithmType } from './modules/crypto/algorithms/aes.constants';\nexport type { IPayloadCipher } from './modules/crypto/common/types';\nexport type { IRedisHelper } from './modules/redis/common/interfaces';\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AESAlgorithms, type AESAlgorithmType } from './aes.constants.js';
|
|
1
2
|
import { BaseCryptoAlgorithm } from './base.algorithm.js';
|
|
2
3
|
interface IAESDecryptOptions {
|
|
3
4
|
inputEncoding?: BufferEncoding;
|
|
@@ -17,7 +18,7 @@ export interface IAESKeyringEntry {
|
|
|
17
18
|
secret: string;
|
|
18
19
|
}
|
|
19
20
|
export type TAESSecret = string | IAESKeyringEntry[];
|
|
20
|
-
export type AESAlgorithmType
|
|
21
|
+
export { AESAlgorithms, type AESAlgorithmType };
|
|
21
22
|
export declare class AES extends BaseCryptoAlgorithm<AESAlgorithmType, string, string, TAESSecret, string, string, IAESExtraOptions> {
|
|
22
23
|
constructor(opts: {
|
|
23
24
|
algorithm: AESAlgorithmType;
|
|
@@ -56,5 +57,4 @@ export declare class AES extends BaseCryptoAlgorithm<AESAlgorithmType, string, s
|
|
|
56
57
|
secret: TAESSecret;
|
|
57
58
|
}): string;
|
|
58
59
|
}
|
|
59
|
-
export {};
|
|
60
60
|
//# sourceMappingURL=aes.algorithm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aes.algorithm.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes.algorithm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aes.algorithm.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAKvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAMvD,UAAU,kBAAkB;IAC1B,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8HAA8H;IAC9H,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0HAA0H;IAC1H,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,sIAAsI;AACtI,UAAU,gBAAiB,SAAQ,kBAAkB;IACnD,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,gBAAgB,EAAE,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,KAAK,gBAAgB,EAAE,CAAC;AAEhD,qBAAa,GAAI,SAAQ,mBAAmB,CAC1C,gBAAgB,EAChB,MAAM,EACN,MAAM,EACN,UAAU,EACV,MAAM,EACN,MAAM,EACN,gBAAgB,CACjB;gBACa,IAAI,EAAE;QAAE,SAAS,EAAE,gBAAgB,CAAA;KAAE;IAIjD,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,gBAAgB;IAIhD,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE;QAChC,MAAM,EAAE,UAAU,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,GAAG;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE;IAiB/B,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE;QAChC,MAAM,EAAE,UAAU,CAAC;QACnB,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,GAAG,MAAM;IAyBV,OAAO,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,CAAC;QAAC,IAAI,CAAC,EAAE,gBAAgB,CAAA;KAAE;IAiD9E,WAAW,CAAC,IAAI,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,CAAA;KAAE,GAAG,MAAM;IAavE,OAAO,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,CAAC;QAAC,IAAI,CAAC,EAAE,kBAAkB,CAAA;KAAE;IAuDhF,WAAW,CAAC,IAAI,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,CAAA;KAAE;CAY/D"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AESAlgorithms } from './aes.constants.js';
|
|
1
2
|
import { isEmpty } from '@venizia/ignis-inversion';
|
|
2
3
|
import C from 'node:crypto';
|
|
3
4
|
import fs from 'node:fs';
|
|
@@ -6,6 +7,7 @@ import { BaseCryptoAlgorithm } from './base.algorithm.js';
|
|
|
6
7
|
const DEFAULT_LENGTH = 16;
|
|
7
8
|
const CIPHERTEXT_VERSION = 0x01;
|
|
8
9
|
const DEFAULT_KEY_ID = '0';
|
|
10
|
+
export { AESAlgorithms };
|
|
9
11
|
export class AES extends BaseCryptoAlgorithm {
|
|
10
12
|
constructor(opts) {
|
|
11
13
|
super({ scope: AES.name, ...opts });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aes.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,CAAC,MAAM,aAAa,CAAC;AAC5B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,MAAM,cAAc,GAAG,GAAG,CAAC;AA0B3B,MAAM,OAAO,GAAI,SAAQ,mBAQxB;IACC,YAAY,IAAqC;QAC/C,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,SAA2B;QAC9C,OAAO,IAAI,GAAG,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;IAChC,CAAC;IAES,iBAAiB,CAAC,IAI3B;QACC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;QAChD,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,cAA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MAAM,IAAI,cAAc,CAAC;oBACxB,QAA0B,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;oBAChD,MAAM;gBACR,CAAC;YACH,CAAC;YAED,MAAM,UAAU,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YACxC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAC5E,cAAc,CACf,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,KAAK,CAAC;YACd,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;IACH,CAAC;IAED,WAAW,CAAC,IAAkD;QAC5D,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAEtC,IAAI,CAAC,YAAY,IAAI,OAAO,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;YACtD,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAC7C,MAAM,WAAW,GAAG,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;QACjE,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import { isEmpty } from '@venizia/ignis-inversion';\nimport C from 'node:crypto';\nimport fs from 'node:fs';\nimport { getError } from '@/modules/error';\nimport { BaseCryptoAlgorithm } from './base.algorithm';\n\nconst DEFAULT_LENGTH = 16;\nconst CIPHERTEXT_VERSION = 0x01;\nconst DEFAULT_KEY_ID = '0';\n\ninterface IAESDecryptOptions {\n inputEncoding?: BufferEncoding;\n outputEncoding?: BufferEncoding;\n doThrow?: boolean;\n /** Per-deployment PBKDF2 salt override. Must be supplied identically on encrypt and decrypt; omit for the shipped default. */\n kdfSalt?: string;\n /** PBKDF2 iteration count override. Must be supplied identically on encrypt and decrypt; omit for the shipped default. */\n kdfIterations?: number;\n}\n\n/** `iv` is encrypt-only: the envelope carries the IV, so decrypt reads it from there and a supplied one would be silently ignored. */\ninterface IAESExtraOptions extends IAESDecryptOptions {\n iv?: Buffer;\n}\n\nexport interface IAESKeyringEntry {\n id: string;\n secret: string;\n}\n\nexport type TAESSecret = string | IAESKeyringEntry[];\n\nexport type AESAlgorithmType = 'aes-256-cbc' | 'aes-256-gcm';\n\nexport class AES extends BaseCryptoAlgorithm<\n AESAlgorithmType,\n string,\n string,\n TAESSecret,\n string,\n string,\n IAESExtraOptions\n> {\n constructor(opts: { algorithm: AESAlgorithmType }) {\n super({ scope: AES.name, ...opts });\n }\n\n static withAlgorithm(algorithm: AESAlgorithmType) {\n return new AES({ algorithm });\n }\n\n protected resolveEncryptKey(opts: {\n secret: TAESSecret;\n kdfSalt?: string;\n kdfIterations?: number;\n }): { id: string; key: Buffer } {\n const { secret, kdfSalt, kdfIterations } = opts;\n const entry = Array.isArray(secret) ? secret[0] : { id: DEFAULT_KEY_ID, secret };\n\n if (!entry || isEmpty({ value: entry.secret })) {\n throw getError({ message: '[AES][resolveEncryptKey] Missing secret or empty keyring' });\n }\n\n const key = this.normalizeSecretKey({\n secret: entry.secret,\n length: this.getAlgorithmKeySize(),\n kdfSalt,\n kdfIterations,\n });\n return { id: entry.id, key };\n }\n\n protected resolveDecryptKey(opts: {\n secret: TAESSecret;\n id: string;\n kdfSalt?: string;\n kdfIterations?: number;\n }): Buffer {\n const { secret, id, kdfSalt, kdfIterations } = opts;\n const length = this.getAlgorithmKeySize();\n\n if (!Array.isArray(secret)) {\n return this.normalizeSecretKey({ secret, length, kdfSalt, kdfIterations });\n }\n\n const entry = secret.find((e) => e.id === id);\n if (!entry) {\n throw getError({\n message: `[AES][resolveDecryptKey] No key in keyring matches ciphertext key id \"${id}\"`,\n });\n }\n\n // Without this the empty secret derives a key from '' and fails as an opaque OpenSSL error, hiding a plain configuration mistake.\n if (isEmpty({ value: entry.secret })) {\n throw getError({\n message: `[AES][resolveDecryptKey] Keyring entry for key id \"${id}\" has an empty secret`,\n });\n }\n\n return this.normalizeSecretKey({ secret: entry.secret, length, kdfSalt, kdfIterations });\n }\n\n encrypt(opts: { message: string; secret: TAESSecret; opts?: IAESExtraOptions }) {\n const { message, secret } = opts;\n const {\n iv = C.randomBytes(DEFAULT_LENGTH),\n inputEncoding = 'utf-8',\n outputEncoding = 'base64',\n doThrow = true,\n kdfSalt,\n kdfIterations,\n } = opts.opts ?? {};\n\n try {\n const { id, key } = this.resolveEncryptKey({ secret, kdfSalt, kdfIterations });\n const idBuffer = Buffer.from(id, 'utf-8');\n if (idBuffer.length > 0xff) {\n throw getError({ message: '[AES][encrypt] Key id too long (max 255 bytes)' });\n }\n\n const cipher = C.createCipheriv(this.algorithm, key, iv);\n\n // Envelope: [version(1)][idLen(1)][id(idLen)][iv(16)][authTag(16, gcm only)][cipher]\n const header = Buffer.from([CIPHERTEXT_VERSION, idBuffer.length]);\n const parts = [header, idBuffer, iv];\n\n const cipherText = cipher.update(message, inputEncoding);\n const cipherFinal = cipher.final();\n\n switch (this.algorithm) {\n case 'aes-256-cbc': {\n break;\n }\n case 'aes-256-gcm': {\n parts.push((cipher as C.CipherGCM).getAuthTag());\n break;\n }\n }\n parts.push(cipherText);\n parts.push(cipherFinal);\n\n return Buffer.concat(parts).toString(outputEncoding);\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n encryptFile(opts: { absolutePath: string; secret: TAESSecret }): string {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n const encrypted = this.encrypt({ message: fileContent, secret });\n return encrypted;\n }\n\n decrypt(opts: { message: string; secret: TAESSecret; opts?: IAESDecryptOptions }) {\n const { message, secret } = opts;\n const {\n inputEncoding = 'base64',\n outputEncoding = 'utf-8',\n doThrow = true,\n kdfSalt,\n kdfIterations,\n } = opts.opts ?? {};\n\n try {\n const raw = Buffer.from(message, inputEncoding);\n\n const version = raw[0];\n if (version !== CIPHERTEXT_VERSION) {\n throw getError({ message: `[AES][decrypt] Unsupported ciphertext version: ${version}` });\n }\n\n const idLength = raw[1];\n let cursor = 2;\n\n const id = raw.subarray(cursor, cursor + idLength).toString('utf-8');\n cursor += idLength;\n\n const iv = raw.subarray(cursor, cursor + DEFAULT_LENGTH);\n cursor += DEFAULT_LENGTH;\n\n const key = this.resolveDecryptKey({ secret, id, kdfSalt, kdfIterations });\n const decipher = C.createDecipheriv(this.algorithm, key, iv);\n\n switch (this.algorithm) {\n case 'aes-256-cbc': {\n break;\n }\n case 'aes-256-gcm': {\n const authTag = raw.subarray(cursor, cursor + DEFAULT_LENGTH);\n cursor += DEFAULT_LENGTH;\n (decipher as C.DecipherGCM).setAuthTag(authTag);\n break;\n }\n }\n\n const cipherText = raw.subarray(cursor);\n return Buffer.concat([decipher.update(cipherText), decipher.final()]).toString(\n outputEncoding,\n );\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n decryptFile(opts: { absolutePath: string; secret: TAESSecret }) {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n const decrypted = this.decrypt({ message: fileContent, secret });\n return decrypted;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"aes.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAyB,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE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EAAE,CAAC;YACf,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,KAAK,CAAC;YACd,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;IACH,CAAC;IAED,WAAW,CAAC,IAAkD;QAC5D,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAEtC,IAAI,CAAC,YAAY,IAAI,OAAO,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;YACtD,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAC7C,MAAM,WAAW,GAAG,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;QACjE,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import { AESAlgorithms, type AESAlgorithmType } from './aes.constants';\nimport { isEmpty } from '@venizia/ignis-inversion';\nimport C from 'node:crypto';\nimport fs from 'node:fs';\nimport { getError } from '@/modules/error';\nimport { BaseCryptoAlgorithm } from './base.algorithm';\n\nconst DEFAULT_LENGTH = 16;\nconst CIPHERTEXT_VERSION = 0x01;\nconst DEFAULT_KEY_ID = '0';\n\ninterface IAESDecryptOptions {\n inputEncoding?: BufferEncoding;\n outputEncoding?: BufferEncoding;\n doThrow?: boolean;\n /** Per-deployment PBKDF2 salt override. Must be supplied identically on encrypt and decrypt; omit for the shipped default. */\n kdfSalt?: string;\n /** PBKDF2 iteration count override. Must be supplied identically on encrypt and decrypt; omit for the shipped default. */\n kdfIterations?: number;\n}\n\n/** `iv` is encrypt-only: the envelope carries the IV, so decrypt reads it from there and a supplied one would be silently ignored. */\ninterface IAESExtraOptions extends IAESDecryptOptions {\n iv?: Buffer;\n}\n\nexport interface IAESKeyringEntry {\n id: string;\n secret: string;\n}\n\nexport type TAESSecret = string | IAESKeyringEntry[];\n\nexport { AESAlgorithms, type AESAlgorithmType };\n\nexport class AES extends BaseCryptoAlgorithm<\n AESAlgorithmType,\n string,\n string,\n TAESSecret,\n string,\n string,\n IAESExtraOptions\n> {\n constructor(opts: { algorithm: AESAlgorithmType }) {\n super({ scope: AES.name, ...opts });\n }\n\n static withAlgorithm(algorithm: AESAlgorithmType) {\n return new AES({ algorithm });\n }\n\n protected resolveEncryptKey(opts: {\n secret: TAESSecret;\n kdfSalt?: string;\n kdfIterations?: number;\n }): { id: string; key: Buffer } {\n const { secret, kdfSalt, kdfIterations } = opts;\n const entry = Array.isArray(secret) ? secret[0] : { id: DEFAULT_KEY_ID, secret };\n\n if (!entry || isEmpty({ value: entry.secret })) {\n throw getError({ message: '[AES][resolveEncryptKey] Missing secret or empty keyring' });\n }\n\n const key = this.normalizeSecretKey({\n secret: entry.secret,\n length: this.getAlgorithmKeySize(),\n kdfSalt,\n kdfIterations,\n });\n return { id: entry.id, key };\n }\n\n protected resolveDecryptKey(opts: {\n secret: TAESSecret;\n id: string;\n kdfSalt?: string;\n kdfIterations?: number;\n }): Buffer {\n const { secret, id, kdfSalt, kdfIterations } = opts;\n const length = this.getAlgorithmKeySize();\n\n if (!Array.isArray(secret)) {\n return this.normalizeSecretKey({ secret, length, kdfSalt, kdfIterations });\n }\n\n const entry = secret.find((e) => e.id === id);\n if (!entry) {\n throw getError({\n message: `[AES][resolveDecryptKey] No key in keyring matches ciphertext key id \"${id}\"`,\n });\n }\n\n // Without this the empty secret derives a key from '' and fails as an opaque OpenSSL error, hiding a plain configuration mistake.\n if (isEmpty({ value: entry.secret })) {\n throw getError({\n message: `[AES][resolveDecryptKey] Keyring entry for key id \"${id}\" has an empty secret`,\n });\n }\n\n return this.normalizeSecretKey({ secret: entry.secret, length, kdfSalt, kdfIterations });\n }\n\n encrypt(opts: { message: string; secret: TAESSecret; opts?: IAESExtraOptions }) {\n const { message, secret } = opts;\n const {\n iv = C.randomBytes(DEFAULT_LENGTH),\n inputEncoding = 'utf-8',\n outputEncoding = 'base64',\n doThrow = true,\n kdfSalt,\n kdfIterations,\n } = opts.opts ?? {};\n\n try {\n const { id, key } = this.resolveEncryptKey({ secret, kdfSalt, kdfIterations });\n const idBuffer = Buffer.from(id, 'utf-8');\n if (idBuffer.length > 0xff) {\n throw getError({ message: '[AES][encrypt] Key id too long (max 255 bytes)' });\n }\n\n const cipher = C.createCipheriv(this.algorithm, key, iv);\n\n // Envelope: [version(1)][idLen(1)][id(idLen)][iv(16)][authTag(16, gcm only)][cipher]\n const header = Buffer.from([CIPHERTEXT_VERSION, idBuffer.length]);\n const parts = [header, idBuffer, iv];\n\n const cipherText = cipher.update(message, inputEncoding);\n const cipherFinal = cipher.final();\n\n switch (this.algorithm) {\n case 'aes-256-cbc': {\n break;\n }\n case 'aes-256-gcm': {\n parts.push((cipher as C.CipherGCM).getAuthTag());\n break;\n }\n }\n parts.push(cipherText);\n parts.push(cipherFinal);\n\n return Buffer.concat(parts).toString(outputEncoding);\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n encryptFile(opts: { absolutePath: string; secret: TAESSecret }): string {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n const encrypted = this.encrypt({ message: fileContent, secret });\n return encrypted;\n }\n\n decrypt(opts: { message: string; secret: TAESSecret; opts?: IAESDecryptOptions }) {\n const { message, secret } = opts;\n const {\n inputEncoding = 'base64',\n outputEncoding = 'utf-8',\n doThrow = true,\n kdfSalt,\n kdfIterations,\n } = opts.opts ?? {};\n\n try {\n const raw = Buffer.from(message, inputEncoding);\n\n const version = raw[0];\n if (version !== CIPHERTEXT_VERSION) {\n throw getError({ message: `[AES][decrypt] Unsupported ciphertext version: ${version}` });\n }\n\n const idLength = raw[1];\n let cursor = 2;\n\n const id = raw.subarray(cursor, cursor + idLength).toString('utf-8');\n cursor += idLength;\n\n const iv = raw.subarray(cursor, cursor + DEFAULT_LENGTH);\n cursor += DEFAULT_LENGTH;\n\n const key = this.resolveDecryptKey({ secret, id, kdfSalt, kdfIterations });\n const decipher = C.createDecipheriv(this.algorithm, key, iv);\n\n switch (this.algorithm) {\n case 'aes-256-cbc': {\n break;\n }\n case 'aes-256-gcm': {\n const authTag = raw.subarray(cursor, cursor + DEFAULT_LENGTH);\n cursor += DEFAULT_LENGTH;\n (decipher as C.DecipherGCM).setAuthTag(authTag);\n break;\n }\n }\n\n const cipherText = raw.subarray(cursor);\n return Buffer.concat([decipher.update(cipherText), decipher.final()]).toString(\n outputEncoding,\n );\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n decryptFile(opts: { absolutePath: string; secret: TAESSecret }) {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n const decrypted = this.decrypt({ message: fileContent, secret });\n return decrypted;\n }\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TConstValue } from '../../../common/types/index.js';
|
|
2
|
+
/** The ciphers `AES` supports. */
|
|
3
|
+
export declare class AESAlgorithms {
|
|
4
|
+
static readonly AES_256_CBC = "aes-256-cbc";
|
|
5
|
+
static readonly AES_256_GCM = "aes-256-gcm";
|
|
6
|
+
static readonly SCHEME_SET: Set<string>;
|
|
7
|
+
static isValid(value: string): boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Valid AES algorithm values. */
|
|
10
|
+
export type AESAlgorithmType = TConstValue<typeof AESAlgorithms>;
|
|
11
|
+
//# sourceMappingURL=aes.constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aes.constants.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes.constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,kCAAkC;AAClC,qBAAa,aAAa;IACxB,MAAM,CAAC,QAAQ,CAAC,WAAW,iBAAiB;IAC5C,MAAM,CAAC,QAAQ,CAAC,WAAW,iBAAiB;IAE5C,MAAM,CAAC,QAAQ,CAAC,UAAU,cAAyD;IAEnF,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAGvC;AAED,kCAAkC;AAClC,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC,OAAO,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The ciphers `AES` supports. */
|
|
2
|
+
export class AESAlgorithms {
|
|
3
|
+
static { this.AES_256_CBC = 'aes-256-cbc'; }
|
|
4
|
+
static { this.AES_256_GCM = 'aes-256-gcm'; }
|
|
5
|
+
static { this.SCHEME_SET = new Set([this.AES_256_CBC, this.AES_256_GCM]); }
|
|
6
|
+
static isValid(value) {
|
|
7
|
+
return this.SCHEME_SET.has(value);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=aes.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aes.constants.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes.constants.ts"],"names":[],"mappings":"AAEA,kCAAkC;AAClC,MAAM,OAAO,aAAa;aACR,gBAAW,GAAG,aAAa,CAAC;aAC5B,gBAAW,GAAG,aAAa,CAAC;aAE5B,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAEnF,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC","sourcesContent":["import type { TConstValue } from '@/common/types';\n\n/** The ciphers `AES` supports. */\nexport class AESAlgorithms {\n static readonly AES_256_CBC = 'aes-256-cbc';\n static readonly AES_256_GCM = 'aes-256-gcm';\n\n static readonly SCHEME_SET = new Set<string>([this.AES_256_CBC, this.AES_256_GCM]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid AES algorithm values. */\nexport type AESAlgorithmType = TConstValue<typeof AESAlgorithms>;\n"]}
|