@tstdl/base 0.83.1 → 0.83.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/.eslintrc.cjs +15 -5
- package/authentication/server/authentication.service.js +4 -5
- package/examples/mail/templates/hello-name.d.ts +1 -1
- package/examples/pdf/templates/hello-name.d.ts +1 -1
- package/examples/template/templates/hello-jsx.d.ts +1 -1
- package/examples/template/templates/hello-name.d.ts +1 -1
- package/mail/mail.service.d.ts +1 -1
- package/mail/models/mail-template.model.d.ts +4 -4
- package/package.json +1 -1
- package/pdf/pdf.service.d.ts +3 -3
- package/templates/template.model.d.ts +4 -1
- package/templates/template.model.js +3 -1
- package/templates/template.service.d.ts +2 -2
- package/types.d.ts +2 -2
- package/utils/cryptography.d.ts +11 -0
- package/utils/cryptography.js +7 -0
package/.eslintrc.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
+
root: true,
|
|
2
3
|
env: {
|
|
3
4
|
browser: true,
|
|
4
5
|
es2022: true,
|
|
@@ -34,6 +35,7 @@ module.exports = {
|
|
|
34
35
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
35
36
|
'@typescript-eslint/indent': 'off',
|
|
36
37
|
'@typescript-eslint/init-declarations': 'off',
|
|
38
|
+
'@typescript-eslint/lines-around-comment': 'off',
|
|
37
39
|
'@typescript-eslint/lines-between-class-members': ['warn', 'always', { exceptAfterSingleLine: true }],
|
|
38
40
|
'@typescript-eslint/method-signature-style': 'off',
|
|
39
41
|
'@typescript-eslint/no-confusing-void-expression': ['error', { ignoreArrowShorthand: true, ignoreVoidOperator: true }],
|
|
@@ -92,7 +94,7 @@ module.exports = {
|
|
|
92
94
|
'function-paren-newline': ['warn', 'consistent'],
|
|
93
95
|
'generator-star-spacing': ['off', { before: false, after: true }],
|
|
94
96
|
'id-length': 'off',
|
|
95
|
-
'indent':
|
|
97
|
+
'indent': 'off',
|
|
96
98
|
'init-declarations': 'off',
|
|
97
99
|
'line-comment-position': 'off',
|
|
98
100
|
'linebreak-style': ['error', 'unix'],
|
|
@@ -182,9 +184,11 @@ module.exports = {
|
|
|
182
184
|
'protected-static-field',
|
|
183
185
|
'public-static-field',
|
|
184
186
|
|
|
187
|
+
/*
|
|
185
188
|
'private-decorated-field',
|
|
186
189
|
'protected-decorated-field',
|
|
187
190
|
'public-decorated-field',
|
|
191
|
+
*/
|
|
188
192
|
|
|
189
193
|
'#private-instance-field',
|
|
190
194
|
'private-instance-field',
|
|
@@ -203,7 +207,7 @@ module.exports = {
|
|
|
203
207
|
'instance-field',
|
|
204
208
|
'abstract-field',
|
|
205
209
|
|
|
206
|
-
'decorated-field',
|
|
210
|
+
// 'decorated-field',
|
|
207
211
|
|
|
208
212
|
'field',
|
|
209
213
|
|
|
@@ -213,9 +217,11 @@ module.exports = {
|
|
|
213
217
|
'protected-static-get',
|
|
214
218
|
'public-static-get',
|
|
215
219
|
|
|
220
|
+
/*
|
|
216
221
|
'private-decorated-get',
|
|
217
222
|
'protected-decorated-get',
|
|
218
223
|
'public-decorated-get',
|
|
224
|
+
*/
|
|
219
225
|
|
|
220
226
|
'#private-instance-get',
|
|
221
227
|
'private-instance-get',
|
|
@@ -234,7 +240,7 @@ module.exports = {
|
|
|
234
240
|
'instance-get',
|
|
235
241
|
'abstract-get',
|
|
236
242
|
|
|
237
|
-
'decorated-get',
|
|
243
|
+
// 'decorated-get',
|
|
238
244
|
|
|
239
245
|
'get',
|
|
240
246
|
|
|
@@ -244,9 +250,11 @@ module.exports = {
|
|
|
244
250
|
'protected-static-set',
|
|
245
251
|
'public-static-set',
|
|
246
252
|
|
|
253
|
+
/*
|
|
247
254
|
'private-decorated-set',
|
|
248
255
|
'protected-decorated-set',
|
|
249
256
|
'public-decorated-set',
|
|
257
|
+
*/
|
|
250
258
|
|
|
251
259
|
'#private-instance-set',
|
|
252
260
|
'private-instance-set',
|
|
@@ -265,7 +273,7 @@ module.exports = {
|
|
|
265
273
|
'instance-set',
|
|
266
274
|
'abstract-set',
|
|
267
275
|
|
|
268
|
-
'decorated-set',
|
|
276
|
+
// 'decorated-set',
|
|
269
277
|
|
|
270
278
|
'set',
|
|
271
279
|
|
|
@@ -285,9 +293,11 @@ module.exports = {
|
|
|
285
293
|
'private-static-method',
|
|
286
294
|
'#private-static-method',
|
|
287
295
|
|
|
296
|
+
/*
|
|
288
297
|
'public-decorated-method',
|
|
289
298
|
'protected-decorated-method',
|
|
290
299
|
'private-decorated-method',
|
|
300
|
+
*/
|
|
291
301
|
|
|
292
302
|
'public-instance-method',
|
|
293
303
|
'protected-instance-method',
|
|
@@ -306,7 +316,7 @@ module.exports = {
|
|
|
306
316
|
'instance-method',
|
|
307
317
|
'abstract-method',
|
|
308
318
|
|
|
309
|
-
'decorated-method',
|
|
319
|
+
// 'decorated-method',
|
|
310
320
|
|
|
311
321
|
'method'
|
|
312
322
|
]
|
|
@@ -271,11 +271,10 @@ let AuthenticationService = class AuthenticationService2 {
|
|
|
271
271
|
}
|
|
272
272
|
async deriveSigningSecrets() {
|
|
273
273
|
const key = await (0, import_cryptography.importPbkdf2Key)(this.secret);
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
this.
|
|
277
|
-
this.
|
|
278
|
-
this.derivedSecretResetTokenSigningSecret = new Uint8Array(hash.slice(bufferSize * 2));
|
|
274
|
+
const [derivedTokenSigningSecret, derivedRefreshTokenSigningSecret, derivedSecretResetTokenSigningSecret] = await (0, import_cryptography.deriveBytesMultiple)(3, SIGNING_SECRETS_LENGTH / 8, { name: "PBKDF2", hash: "SHA-512", iterations: 5e5, salt: new Uint8Array() }, key);
|
|
275
|
+
this.derivedTokenSigningSecret = derivedTokenSigningSecret;
|
|
276
|
+
this.derivedRefreshTokenSigningSecret = derivedRefreshTokenSigningSecret;
|
|
277
|
+
this.derivedSecretResetTokenSigningSecret = derivedSecretResetTokenSigningSecret;
|
|
279
278
|
}
|
|
280
279
|
async getHash(secret, salt) {
|
|
281
280
|
const key = await (0, import_cryptography.importPbkdf2Key)(secret);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const template: import("../../../mail/index.js").MailTemplate
|
|
1
|
+
declare const template: import("../../../mail/index.js").MailTemplate<object>;
|
|
2
2
|
export default template;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const template: import("../../../pdf/pdf.service.js").PdfTemplate
|
|
1
|
+
declare const template: import("../../../pdf/pdf.service.js").PdfTemplate<any>;
|
|
2
2
|
export default template;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const template: import("../../../templates/template.model.js").Template<import("../../../types.js").Record<string, boolean>, any>;
|
|
1
|
+
export declare const template: import("../../../templates/template.model.js").Template<import("../../../types.js").Record<string, boolean>, any, any>;
|
|
2
2
|
export default template;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const template: import("../../../templates/template.model.js").Template<import("../../../types.js").Record<string, boolean>, any>;
|
|
1
|
+
declare const template: import("../../../templates/template.model.js").Template<import("../../../types.js").Record<string, boolean>, any, any>;
|
|
2
2
|
export default template;
|
package/mail/mail.service.d.ts
CHANGED
|
@@ -14,5 +14,5 @@ export declare class MailService {
|
|
|
14
14
|
send(mailData: MailData): Promise<MailSendResult>;
|
|
15
15
|
/** @deprecated internal */
|
|
16
16
|
send(mailData: MailData, templateName?: string): Promise<MailSendResult>;
|
|
17
|
-
sendTemplate(keyOrTemplate: string | MailTemplate
|
|
17
|
+
sendTemplate<Context extends object>(keyOrTemplate: string | MailTemplate<Context>, mailData: TypedOmit<MailData, 'content' | 'subject'>, templateContext?: Context): Promise<MailSendResult>;
|
|
18
18
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Template, TemplateField } from '../../templates/template.model.js';
|
|
2
|
-
export type MailTemplate = Template<{
|
|
2
|
+
export type MailTemplate<Context extends object = any> = Template<{
|
|
3
3
|
subject: false;
|
|
4
4
|
html: false;
|
|
5
5
|
text: false;
|
|
6
|
-
}, undefined>;
|
|
7
|
-
export declare function mailTemplate(name: string, fields: {
|
|
6
|
+
}, undefined, Context>;
|
|
7
|
+
export declare function mailTemplate<Context extends object>(name: string, fields: {
|
|
8
8
|
subject?: TemplateField;
|
|
9
9
|
html?: TemplateField;
|
|
10
10
|
text?: TemplateField;
|
|
11
|
-
}): MailTemplate
|
|
11
|
+
}): MailTemplate<Context>;
|
package/package.json
CHANGED
package/pdf/pdf.service.d.ts
CHANGED
|
@@ -45,11 +45,11 @@ export declare class PdfRenderOptions {
|
|
|
45
45
|
timeout?: number;
|
|
46
46
|
}
|
|
47
47
|
export type PdfTemplateOptions = PdfRenderOptions;
|
|
48
|
-
export declare class PdfTemplate extends Template<{
|
|
48
|
+
export declare class PdfTemplate<Context extends object = any> extends Template<{
|
|
49
49
|
header: false;
|
|
50
50
|
body: true;
|
|
51
51
|
footer: false;
|
|
52
|
-
}, PdfRenderOptions> {
|
|
52
|
+
}, PdfRenderOptions, Context> {
|
|
53
53
|
options?: PdfTemplateOptions;
|
|
54
54
|
}
|
|
55
55
|
export type PdfServiceOptions = {
|
|
@@ -101,7 +101,7 @@ export declare class PdfService implements AsyncDisposable, AfterResolve, Inject
|
|
|
101
101
|
* @param options additional options, overwrites options specified in template
|
|
102
102
|
* @returns pdf bytes
|
|
103
103
|
*/
|
|
104
|
-
renderTemplateStream(keyOrTemplate: string | PdfTemplate
|
|
104
|
+
renderTemplateStream<Context extends object>(keyOrTemplate: string | PdfTemplate<Context>, templateContext?: Context, options?: PdfRenderOptions): ReadableStream<Uint8Array>;
|
|
105
105
|
/**
|
|
106
106
|
* Renders a template to pdf
|
|
107
107
|
* @param key template key
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { PickBy, Record, SimplifyObject } from '../types.js';
|
|
2
|
+
export type TemplateContext<T extends Template> = T[typeof templateContext];
|
|
3
|
+
export declare const templateContext: unique symbol;
|
|
2
4
|
export declare class TemplateField<Resolver extends string = string, Renderer extends string = string, Options = any> {
|
|
3
5
|
resolver: Resolver;
|
|
4
6
|
renderer: Renderer;
|
|
@@ -9,7 +11,8 @@ export type TemplateFields<Fields extends Record<string, boolean>, Resolver exte
|
|
|
9
11
|
} & {
|
|
10
12
|
[P in keyof PickBy<Fields, false>]?: TemplateField<Resolver, Renderer, Options>;
|
|
11
13
|
}>;
|
|
12
|
-
export declare abstract class Template<Fields extends Record<string, boolean> = Record<string, boolean>, TemplateOptions = any> {
|
|
14
|
+
export declare abstract class Template<Fields extends Record<string, boolean> = Record<string, boolean>, TemplateOptions = any, Context extends object = any> {
|
|
15
|
+
readonly [templateContext]?: Context;
|
|
13
16
|
/** name of template */
|
|
14
17
|
name: string;
|
|
15
18
|
fields: TemplateFields<Fields>;
|
|
@@ -20,7 +20,8 @@ var template_model_exports = {};
|
|
|
20
20
|
__export(template_model_exports, {
|
|
21
21
|
Template: () => Template,
|
|
22
22
|
TemplateField: () => TemplateField,
|
|
23
|
-
simpleTemplate: () => simpleTemplate
|
|
23
|
+
simpleTemplate: () => simpleTemplate,
|
|
24
|
+
templateContext: () => templateContext
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(template_model_exports);
|
|
26
27
|
var import_schema = require("../schema/index.js");
|
|
@@ -38,6 +39,7 @@ var __metadata = function(k, v) {
|
|
|
38
39
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
39
40
|
return Reflect.metadata(k, v);
|
|
40
41
|
};
|
|
42
|
+
const templateContext = Symbol("templateData");
|
|
41
43
|
let TemplateField = class TemplateField2 {
|
|
42
44
|
resolver;
|
|
43
45
|
renderer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Record } from '../types.js';
|
|
2
2
|
import { TemplateRendererProvider } from './template-renderer.provider.js';
|
|
3
3
|
import { TemplateResolverProvider } from './template-resolver.provider.js';
|
|
4
|
-
import type { Template } from './template.model.js';
|
|
4
|
+
import type { Template, TemplateContext } from './template.model.js';
|
|
5
5
|
import { TemplateProvider } from './template.provider.js';
|
|
6
6
|
export type TemplateServiceRenderResult<T extends Template = Template> = {
|
|
7
7
|
name: string;
|
|
@@ -14,5 +14,5 @@ export declare class TemplateService {
|
|
|
14
14
|
private readonly templateResolverProvider;
|
|
15
15
|
constructor(templateProvider: TemplateProvider | undefined, templateRendererProvider: TemplateRendererProvider, templateResolverProvider: TemplateResolverProvider);
|
|
16
16
|
get<T extends Template = Template>(key: string): Promise<T>;
|
|
17
|
-
render<T extends Template = Template>(keyOrTemplate: string | T, templateContext?:
|
|
17
|
+
render<T extends Template = Template>(keyOrTemplate: string | T, templateContext?: TemplateContext<T>): Promise<TemplateServiceRenderResult<T>>;
|
|
18
18
|
}
|
package/types.d.ts
CHANGED
|
@@ -83,10 +83,10 @@ type FromEntriesEntryValue<T extends readonly (readonly [any, any])[], K> = Extr
|
|
|
83
83
|
export type FromEntries<T> = T extends readonly (readonly [infer Key, any])[] ? {
|
|
84
84
|
[K in Cast<Key, PropertyKey>]: Fallback<FromEntriesEntryValue<T, K>, T[number][1]>;
|
|
85
85
|
} : never;
|
|
86
|
-
export type Writable<T> = {
|
|
86
|
+
export type Writable<T> = T extends readonly (infer U)[] ? U[] : {
|
|
87
87
|
-readonly [P in keyof T]: T[P];
|
|
88
88
|
};
|
|
89
|
-
export type DeepWritable<T> = {
|
|
89
|
+
export type DeepWritable<T> = T extends readonly (infer U)[] ? DeepWritable<U>[] : {
|
|
90
90
|
-readonly [P in keyof T]: DeepWritable<T[P]>;
|
|
91
91
|
};
|
|
92
92
|
export type RequiredKeys<T> = {
|
package/utils/cryptography.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BinaryData, TypedExtract } from '../types.js';
|
|
2
|
+
import type { ReadonlyTuple } from 'type-fest';
|
|
2
3
|
export type AesMode = 'CBC' | 'CTR' | 'GCM' | 'KW';
|
|
3
4
|
export type EcdsaCurve = 'P-256' | 'P-384' | 'P-521';
|
|
4
5
|
export type HashAlgorithm = 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
@@ -104,3 +105,13 @@ export declare function generateEcdsaKey(curve: EcdsaCurve, extractable?: boolea
|
|
|
104
105
|
* @param extractable whether the key can be used for exportKey
|
|
105
106
|
*/
|
|
106
107
|
export declare function generatePbkdf2Key(extractable?: boolean): Promise<CryptoKey>;
|
|
108
|
+
type AlgorithmParameter = Parameters<typeof globalThis.crypto.subtle.deriveBits>['0'];
|
|
109
|
+
/**
|
|
110
|
+
* derive multiply byte arrays
|
|
111
|
+
* @param count how many Uint8Arrays to dervice
|
|
112
|
+
* @param length length of each Uint8Array in bytes
|
|
113
|
+
* @param algorithm algorithm to derive with
|
|
114
|
+
* @param baseKey key to derive from
|
|
115
|
+
*/
|
|
116
|
+
export declare function deriveBytesMultiple<C extends number>(count: C, length: number, algorithm: AlgorithmParameter, baseKey: CryptoKey): Promise<ReadonlyTuple<Uint8Array, C>>;
|
|
117
|
+
export {};
|
package/utils/cryptography.js
CHANGED
|
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var cryptography_exports = {};
|
|
20
20
|
__export(cryptography_exports, {
|
|
21
21
|
decrypt: () => decrypt,
|
|
22
|
+
deriveBytesMultiple: () => deriveBytesMultiple,
|
|
22
23
|
digest: () => digest,
|
|
23
24
|
encrypt: () => encrypt,
|
|
24
25
|
generateEcdsaKey: () => generateEcdsaKey,
|
|
@@ -31,6 +32,7 @@ __export(cryptography_exports, {
|
|
|
31
32
|
verify: () => verify
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(cryptography_exports);
|
|
35
|
+
var import_array = require("./array/array.js");
|
|
34
36
|
var import_base64 = require("./base64.js");
|
|
35
37
|
var import_encoding = require("./encoding.js");
|
|
36
38
|
var import_random = require("./random.js");
|
|
@@ -120,6 +122,11 @@ async function generatePbkdf2Key(extractable = false) {
|
|
|
120
122
|
const key = (0, import_random.getRandomBytes)(16);
|
|
121
123
|
return importPbkdf2Key(key, extractable);
|
|
122
124
|
}
|
|
125
|
+
async function deriveBytesMultiple(count, length, algorithm, baseKey) {
|
|
126
|
+
const totalBits = count * length * 8;
|
|
127
|
+
const bytes = await globalThis.crypto.subtle.deriveBits(algorithm, baseKey, totalBits);
|
|
128
|
+
return (0, import_array.createArray)(count, (index) => new Uint8Array(bytes.slice(index * length, index * length + length)));
|
|
129
|
+
}
|
|
123
130
|
function isBinaryKey(key) {
|
|
124
131
|
return (0, import_type_guards.isDefined)(key.byteLength);
|
|
125
132
|
}
|