@tstdl/base 0.84.15 → 0.84.17
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.
|
@@ -7,8 +7,7 @@ export declare class Application {
|
|
|
7
7
|
private static _instance;
|
|
8
8
|
private static get instance();
|
|
9
9
|
private readonly logger;
|
|
10
|
-
private readonly
|
|
11
|
-
private readonly moduleInstances;
|
|
10
|
+
private readonly moduleTypesAndInstances;
|
|
12
11
|
private readonly shutdownPromise;
|
|
13
12
|
private readonly _shutdownToken;
|
|
14
13
|
get shutdownToken(): ReadonlyCancellationToken;
|
|
@@ -16,14 +15,12 @@ export declare class Application {
|
|
|
16
15
|
constructor(logger: Logger);
|
|
17
16
|
static registerModule(moduleType: Type<Module>): void;
|
|
18
17
|
static registerModuleFunction(fn: FunctionModuleFunction): void;
|
|
19
|
-
static registerModuleInstance(module: Module): void;
|
|
20
18
|
static run(...functionsAndModules: OneOrMany<FunctionModuleFunction | Type<Module>>[]): void;
|
|
21
19
|
static waitForShutdown(): Promise<void>;
|
|
22
20
|
static shutdown(): Promise<void>;
|
|
23
21
|
static requestShutdown(): void;
|
|
24
|
-
registerModule(moduleType: Type<Module>): void;
|
|
22
|
+
registerModule(moduleType: Module | Type<Module>): void;
|
|
25
23
|
registerModuleFunction(fn: FunctionModuleFunction): void;
|
|
26
|
-
registerModuleInstance(module: Module): void;
|
|
27
24
|
run(...functionsAndModules: OneOrMany<FunctionModuleFunction | Type<Module>>[]): void;
|
|
28
25
|
shutdown(): Promise<void>;
|
|
29
26
|
requestShutdown(): void;
|
|
@@ -63,8 +63,7 @@ let Application = Application_1 = class Application2 {
|
|
|
63
63
|
return this._instance;
|
|
64
64
|
}
|
|
65
65
|
logger;
|
|
66
|
-
|
|
67
|
-
moduleInstances;
|
|
66
|
+
moduleTypesAndInstances;
|
|
68
67
|
shutdownPromise;
|
|
69
68
|
_shutdownToken;
|
|
70
69
|
get shutdownToken() {
|
|
@@ -75,8 +74,7 @@ let Application = Application_1 = class Application2 {
|
|
|
75
74
|
}
|
|
76
75
|
constructor(logger) {
|
|
77
76
|
this.logger = logger;
|
|
78
|
-
this.
|
|
79
|
-
this.moduleInstances = /* @__PURE__ */ new Set();
|
|
77
|
+
this.moduleTypesAndInstances = /* @__PURE__ */ new Set();
|
|
80
78
|
this.shutdownPromise = new import_deferred_promise.DeferredPromise();
|
|
81
79
|
this._shutdownToken = import_process_shutdown.shutdownToken.createChild();
|
|
82
80
|
}
|
|
@@ -86,9 +84,6 @@ let Application = Application_1 = class Application2 {
|
|
|
86
84
|
static registerModuleFunction(fn) {
|
|
87
85
|
Application_1.instance.registerModuleFunction(fn);
|
|
88
86
|
}
|
|
89
|
-
static registerModuleInstance(module2) {
|
|
90
|
-
Application_1.instance.registerModuleInstance(module2);
|
|
91
|
-
}
|
|
92
87
|
static run(...functionsAndModules) {
|
|
93
88
|
Application_1.instance.run(...functionsAndModules);
|
|
94
89
|
}
|
|
@@ -102,14 +97,11 @@ let Application = Application_1 = class Application2 {
|
|
|
102
97
|
Application_1.instance.requestShutdown();
|
|
103
98
|
}
|
|
104
99
|
registerModule(moduleType) {
|
|
105
|
-
this.
|
|
100
|
+
this.moduleTypesAndInstances.add(moduleType);
|
|
106
101
|
}
|
|
107
102
|
registerModuleFunction(fn) {
|
|
108
103
|
const module2 = new import_function_module.FunctionModule(fn);
|
|
109
|
-
this.
|
|
110
|
-
}
|
|
111
|
-
registerModuleInstance(module2) {
|
|
112
|
-
this.moduleInstances.add(module2);
|
|
104
|
+
this.registerModule(module2);
|
|
113
105
|
}
|
|
114
106
|
run(...functionsAndModules) {
|
|
115
107
|
void this._run(...functionsAndModules);
|
|
@@ -135,8 +127,7 @@ let Application = Application_1 = class Application2 {
|
|
|
135
127
|
this.registerModuleFunction(fnOrModule);
|
|
136
128
|
}
|
|
137
129
|
}
|
|
138
|
-
const
|
|
139
|
-
const modules = [...this.moduleInstances, ...resolvedModules];
|
|
130
|
+
const modules = await (0, import_to_array.toArrayAsync)((0, import_map.mapAsync)(this.moduleTypesAndInstances, async (instanceOrType) => (0, import_type_guards.isFunction)(instanceOrType) ? import_container.container.resolveAsync(instanceOrType) : instanceOrType));
|
|
140
131
|
try {
|
|
141
132
|
await Promise.race([
|
|
142
133
|
this.runModules(modules),
|
|
@@ -8,6 +8,17 @@ import { AuthenticationSecretResetHandler } from './authentication-secret-reset.
|
|
|
8
8
|
import { AuthenticationSessionRepository } from './authentication-session.repository.js';
|
|
9
9
|
import { AuthenticationSubjectResolver } from './authentication-subject.resolver.js';
|
|
10
10
|
import { AuthenticationTokenPayloadProvider } from './authentication-token-payload.provider.js';
|
|
11
|
+
export type CreateTokenData<AdditionalTokenPayload extends Record> = {
|
|
12
|
+
tokenVersion?: number;
|
|
13
|
+
jti?: string;
|
|
14
|
+
iat?: number;
|
|
15
|
+
exp?: number;
|
|
16
|
+
additionalTokenPayload: AdditionalTokenPayload;
|
|
17
|
+
subject: string;
|
|
18
|
+
sessionId: string;
|
|
19
|
+
refreshTokenExpiration: number;
|
|
20
|
+
timestamp: number;
|
|
21
|
+
};
|
|
11
22
|
export declare class AuthenticationServiceOptions {
|
|
12
23
|
/**
|
|
13
24
|
* Secrets used for signing tokens and refreshTokens
|
|
@@ -81,7 +92,7 @@ export declare class AuthenticationService<AdditionalTokenPayload extends Record
|
|
|
81
92
|
validateSecretResetToken(token: string): Promise<SecretResetToken>;
|
|
82
93
|
resolveSubject(subject: string): Promise<string>;
|
|
83
94
|
/** Creates a token without session or refresh token and is not saved in database */
|
|
84
|
-
createToken(
|
|
95
|
+
createToken({ tokenVersion, jti, iat, exp, additionalTokenPayload, subject, sessionId, refreshTokenExpiration, timestamp }: CreateTokenData<AdditionalTokenPayload>): Promise<CreateTokenResult<AdditionalTokenPayload>>;
|
|
85
96
|
/** Creates a refresh token without session or something else. */
|
|
86
97
|
createRefreshToken(subject: string, sessionId: string, expirationTimestamp: number): Promise<CreateRefreshTokenResult>;
|
|
87
98
|
private createSecretResetToken;
|
|
@@ -155,7 +155,7 @@ let AuthenticationService = class AuthenticationService2 {
|
|
|
155
155
|
refreshTokenHash: new Uint8Array()
|
|
156
156
|
});
|
|
157
157
|
const tokenPayload = await this.tokenPayloadProvider?.getTokenPayload(actualSubject, authenticationData, { action: import_authentication_token_payload_provider.GetTokenPayloadContextAction.GetToken });
|
|
158
|
-
const { token, jsonToken } = await this.createToken(tokenPayload, actualSubject, session.id, end, now);
|
|
158
|
+
const { token, jsonToken } = await this.createToken({ additionalTokenPayload: tokenPayload, subject: actualSubject, sessionId: session.id, refreshTokenExpiration: end, timestamp: now });
|
|
159
159
|
const refreshToken = await this.createRefreshToken(actualSubject, session.id, end);
|
|
160
160
|
await this.sessionRepository.extend(session.id, {
|
|
161
161
|
end,
|
|
@@ -183,7 +183,7 @@ let AuthenticationService = class AuthenticationService2 {
|
|
|
183
183
|
const now = (0, import_date_time.currentTimestamp)();
|
|
184
184
|
const newEnd = now + this.refreshTokenTimeToLive;
|
|
185
185
|
const tokenPayload = await this.tokenPayloadProvider?.getTokenPayload(session.subject, authenticationData, { action: import_authentication_token_payload_provider.GetTokenPayloadContextAction.Refresh });
|
|
186
|
-
const { token, jsonToken } = await this.createToken(tokenPayload, session.subject, sessionId, newEnd, now);
|
|
186
|
+
const { token, jsonToken } = await this.createToken({ additionalTokenPayload: tokenPayload, subject: session.subject, sessionId, refreshTokenExpiration: newEnd, timestamp: now });
|
|
187
187
|
const newRefreshToken = await this.createRefreshToken(validatedToken.payload.subject, sessionId, newEnd);
|
|
188
188
|
await this.sessionRepository.extend(sessionId, {
|
|
189
189
|
end: newEnd,
|
|
@@ -225,16 +225,16 @@ let AuthenticationService = class AuthenticationService2 {
|
|
|
225
225
|
return this.subjectResolver?.resolveSubject(subject) ?? subject;
|
|
226
226
|
}
|
|
227
227
|
/** Creates a token without session or refresh token and is not saved in database */
|
|
228
|
-
async createToken(additionalTokenPayload, subject, sessionId, refreshTokenExpiration, timestamp) {
|
|
228
|
+
async createToken({ tokenVersion, jti, iat, exp, additionalTokenPayload, subject, sessionId, refreshTokenExpiration, timestamp }) {
|
|
229
229
|
const header = {
|
|
230
|
-
v: this.tokenVersion,
|
|
230
|
+
v: tokenVersion ?? this.tokenVersion,
|
|
231
231
|
alg: "HS256",
|
|
232
232
|
typ: "JWT"
|
|
233
233
|
};
|
|
234
234
|
const payload = {
|
|
235
|
-
jti: (0, import_random.getRandomString)(24, import_alphabet.Alphabet.LowerUpperCaseNumbers),
|
|
236
|
-
iat: (0, import_date_time.timestampToTimestampSeconds)(timestamp),
|
|
237
|
-
exp: (0, import_date_time.timestampToTimestampSeconds)(timestamp + this.tokenTimeToLive),
|
|
235
|
+
jti: jti ?? (0, import_random.getRandomString)(24, import_alphabet.Alphabet.LowerUpperCaseNumbers),
|
|
236
|
+
iat: iat ?? (0, import_date_time.timestampToTimestampSeconds)(timestamp),
|
|
237
|
+
exp: exp ?? (0, import_date_time.timestampToTimestampSeconds)(timestamp + this.tokenTimeToLive),
|
|
238
238
|
refreshTokenExp: (0, import_date_time.timestampToTimestampSeconds)(refreshTokenExpiration),
|
|
239
239
|
sessionId,
|
|
240
240
|
subject,
|