@tstdl/base 0.93.194 → 0.93.196
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/api/server/error-handler.d.ts +1 -1
- package/api/server/error-handler.js +0 -1
- package/api/types.d.ts +4 -4
- package/authentication/authentication.api.d.ts +6 -15
- package/authentication/authentication.api.js +0 -1
- package/authentication/client/authentication.service.d.ts +0 -2
- package/authentication/client/authentication.service.js +0 -5
- package/authentication/server/authentication.api-controller.d.ts +1 -1
- package/authentication/server/authentication.api-controller.js +0 -1
- package/authentication/server/authentication.service.d.ts +0 -1
- package/authentication/server/authentication.service.js +4 -9
- package/http/server/http-server-response.d.ts +12 -12
- package/package.json +3 -3
- package/schema/schema.d.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { HttpServerResponse } from '../../http/server/index.js';
|
|
2
2
|
import type { Logger } from '../../logger/index.js';
|
|
3
3
|
import type { Type } from '../../types/index.js';
|
|
4
|
-
export declare function handleApiError(error: unknown, response: HttpServerResponse, supressedErrors: Set<Type<Error>>, logger: Logger):
|
|
4
|
+
export declare function handleApiError(error: unknown, response: HttpServerResponse, supressedErrors: Set<Type<Error>>, logger: Logger): void;
|
package/api/types.d.ts
CHANGED
|
@@ -109,12 +109,12 @@ export type ApiEndpointParametersSchema<T extends ApiDefinition, K extends ApiEn
|
|
|
109
109
|
export type ApiEndpointBodySchema<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = NonUndefinable<ApiEndpoint<T, K>['body']>;
|
|
110
110
|
export type ApiEndpointResultSchema<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = NonUndefinable<ApiEndpoint<T, K>['result']>;
|
|
111
111
|
export type ApiBinaryType = typeof Uint8Array | typeof Blob | typeof ReadableStream;
|
|
112
|
-
export type ApiInputType<T extends SchemaTestable> = T extends ApiBinaryType ? InstanceType<Exclude<ApiBinaryType, typeof ReadableStream> | typeof ReadableStream<Uint8Array<ArrayBuffer>>> : T extends typeof ServerSentEvents ? ServerSentEventsSource : T extends typeof DataStream<infer U> ? AsyncIterable<U> | DataStreamSource<U> :
|
|
113
|
-
export type ApiOutputType<T extends SchemaTestable> = T extends typeof ReadableStream ? ReadableStream<Uint8Array<ArrayBuffer>> : T extends typeof DataStream<infer U> ? Observable<U> :
|
|
112
|
+
export type ApiInputType<T extends SchemaTestable> = T extends ApiBinaryType ? InstanceType<Exclude<ApiBinaryType, typeof ReadableStream> | typeof ReadableStream<Uint8Array<ArrayBuffer>>> : T extends typeof ServerSentEvents ? ServerSentEventsSource : T extends typeof DataStream<infer U> ? AsyncIterable<U> | DataStreamSource<U> : SchemaOutput<T>;
|
|
113
|
+
export type ApiOutputType<T extends SchemaTestable> = T extends typeof ReadableStream ? ReadableStream<Uint8Array<ArrayBuffer>> : T extends typeof DataStream<infer U> ? Observable<U> : SchemaOutput<T>;
|
|
114
114
|
export type ApiParameters<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = ApiInputType<ApiEndpointParametersSchema<T, K>>;
|
|
115
115
|
export type ApiClientBody<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = ApiInputType<ApiEndpointBodySchema<T, K>>;
|
|
116
|
-
export type ApiServerBody<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = ApiOutputType<
|
|
117
|
-
export type ApiServerResult<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = ApiInputType<ApiEndpointResultSchema<T, K>> | HttpServerResponse
|
|
116
|
+
export type ApiServerBody<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = ApiOutputType<ApiEndpointResultSchema<T, K>>;
|
|
117
|
+
export type ApiServerResult<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = ApiInputType<ApiEndpointResultSchema<T, K>> | HttpServerResponse<ApiServerBody<T, K>>;
|
|
118
118
|
export type ApiClientResult<T extends ApiDefinition, K extends ApiEndpointKeys<T>> = ApiOutputType<ApiEndpointResultSchema<T, K>>;
|
|
119
119
|
export type ApiRequestData<T extends ApiDefinition = ApiDefinition, K extends ApiEndpointKeys<T> = ApiEndpointKeys<T>> = {
|
|
120
120
|
parameters: ApiParameters<T, K>;
|
|
@@ -36,7 +36,6 @@ export declare const authenticationApiDefinition: {
|
|
|
36
36
|
result: import("../schema/index.js").UnionSchema<[ObjectSchema<{
|
|
37
37
|
type: "success";
|
|
38
38
|
result: TokenPayload<import("type-fest").EmptyObject>;
|
|
39
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
40
39
|
}>, ObjectSchema<{
|
|
41
40
|
type: "totp";
|
|
42
41
|
challengeToken: string;
|
|
@@ -56,7 +55,6 @@ export declare const authenticationApiDefinition: {
|
|
|
56
55
|
result: ObjectSchema<{
|
|
57
56
|
type: "success";
|
|
58
57
|
result: TokenPayload<import("type-fest").EmptyObject>;
|
|
59
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
60
58
|
}>;
|
|
61
59
|
credentials: true;
|
|
62
60
|
data: {
|
|
@@ -73,7 +71,6 @@ export declare const authenticationApiDefinition: {
|
|
|
73
71
|
result: ObjectSchema<{
|
|
74
72
|
type: "success";
|
|
75
73
|
result: TokenPayload<import("type-fest").EmptyObject>;
|
|
76
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
77
74
|
}>;
|
|
78
75
|
credentials: true;
|
|
79
76
|
data: {
|
|
@@ -265,8 +262,7 @@ export declare function getAuthenticationApiDefinition<AdditionalTokenPayload ex
|
|
|
265
262
|
}>;
|
|
266
263
|
result: import("../schema/index.js").UnionSchema<[ObjectSchema<{
|
|
267
264
|
type: "success";
|
|
268
|
-
result:
|
|
269
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
265
|
+
result: TokenPayload<AdditionalTokenPayload>;
|
|
270
266
|
}>, ObjectSchema<{
|
|
271
267
|
type: "totp";
|
|
272
268
|
challengeToken: string;
|
|
@@ -285,8 +281,7 @@ export declare function getAuthenticationApiDefinition<AdditionalTokenPayload ex
|
|
|
285
281
|
}>;
|
|
286
282
|
result: ObjectSchema<{
|
|
287
283
|
type: "success";
|
|
288
|
-
result:
|
|
289
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
284
|
+
result: TokenPayload<AdditionalTokenPayload>;
|
|
290
285
|
}>;
|
|
291
286
|
credentials: true;
|
|
292
287
|
data: {
|
|
@@ -302,8 +297,7 @@ export declare function getAuthenticationApiDefinition<AdditionalTokenPayload ex
|
|
|
302
297
|
}>;
|
|
303
298
|
result: ObjectSchema<{
|
|
304
299
|
type: "success";
|
|
305
|
-
result:
|
|
306
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
300
|
+
result: TokenPayload<AdditionalTokenPayload>;
|
|
307
301
|
}>;
|
|
308
302
|
credentials: true;
|
|
309
303
|
data: {
|
|
@@ -490,8 +484,7 @@ export declare function getAuthenticationApiEndpointsDefinition<AdditionalTokenP
|
|
|
490
484
|
}>;
|
|
491
485
|
result: import("../schema/index.js").UnionSchema<[ObjectSchema<{
|
|
492
486
|
type: "success";
|
|
493
|
-
result:
|
|
494
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
487
|
+
result: TokenPayload<AdditionalTokenPayload>;
|
|
495
488
|
}>, ObjectSchema<{
|
|
496
489
|
type: "totp";
|
|
497
490
|
challengeToken: string;
|
|
@@ -510,8 +503,7 @@ export declare function getAuthenticationApiEndpointsDefinition<AdditionalTokenP
|
|
|
510
503
|
}>;
|
|
511
504
|
result: ObjectSchema<{
|
|
512
505
|
type: "success";
|
|
513
|
-
result:
|
|
514
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
506
|
+
result: TokenPayload<AdditionalTokenPayload>;
|
|
515
507
|
}>;
|
|
516
508
|
credentials: true;
|
|
517
509
|
data: {
|
|
@@ -527,8 +519,7 @@ export declare function getAuthenticationApiEndpointsDefinition<AdditionalTokenP
|
|
|
527
519
|
}>;
|
|
528
520
|
result: ObjectSchema<{
|
|
529
521
|
type: "success";
|
|
530
|
-
result:
|
|
531
|
-
lowRecoveryCodesWarning?: boolean | undefined;
|
|
522
|
+
result: TokenPayload<AdditionalTokenPayload>;
|
|
532
523
|
}>;
|
|
533
524
|
credentials: true;
|
|
534
525
|
data: {
|
|
@@ -47,7 +47,6 @@ export function getAuthenticationApiEndpointsDefinition(additionalTokenPayloadSc
|
|
|
47
47
|
const loginSuccessResultSchema = object({
|
|
48
48
|
type: literal('success'),
|
|
49
49
|
result: tokenResultSchema,
|
|
50
|
-
lowRecoveryCodesWarning: optional(boolean()),
|
|
51
50
|
});
|
|
52
51
|
const loginTotpResultSchema = object({
|
|
53
52
|
type: literal('totp'),
|
|
@@ -46,8 +46,6 @@ export declare class AuthenticationClientService<AdditionalTokenPayload extends
|
|
|
46
46
|
readonly rawRefreshToken: import("../../signals/api.js").WritableSignal<string | undefined>;
|
|
47
47
|
/** Current raw impersonator refresh token */
|
|
48
48
|
readonly rawImpersonatorRefreshToken: import("../../signals/api.js").WritableSignal<string | undefined>;
|
|
49
|
-
/** Whether the remaining recovery codes are low */
|
|
50
|
-
readonly lowRecoveryCodesWarning: import("../../signals/api.js").WritableSignal<boolean | undefined>;
|
|
51
49
|
/** Whether the user is logged in */
|
|
52
50
|
readonly isLoggedIn: import("../../signals/api.js").Signal<boolean>;
|
|
53
51
|
/** Current session id */
|
|
@@ -93,8 +93,6 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
93
93
|
rawRefreshToken = signal(undefined);
|
|
94
94
|
/** Current raw impersonator refresh token */
|
|
95
95
|
rawImpersonatorRefreshToken = signal(undefined);
|
|
96
|
-
/** Whether the remaining recovery codes are low */
|
|
97
|
-
lowRecoveryCodesWarning = signal(undefined);
|
|
98
96
|
/** Whether the user is logged in */
|
|
99
97
|
isLoggedIn = computed(() => isDefined(this.token()));
|
|
100
98
|
/** Current session id */
|
|
@@ -253,7 +251,6 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
253
251
|
if (result.type == 'totp') {
|
|
254
252
|
return result;
|
|
255
253
|
}
|
|
256
|
-
this.lowRecoveryCodesWarning.set(result.lowRecoveryCodesWarning);
|
|
257
254
|
this.setNewToken(result.result);
|
|
258
255
|
return { type: 'success' };
|
|
259
256
|
}
|
|
@@ -264,7 +261,6 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
264
261
|
*/
|
|
265
262
|
async verifyTotpLogin(challengeToken, token) {
|
|
266
263
|
const result = await this.client.loginVerifyTotp({ challengeToken, token });
|
|
267
|
-
this.lowRecoveryCodesWarning.set(result.lowRecoveryCodesWarning);
|
|
268
264
|
this.setNewToken(result.result);
|
|
269
265
|
}
|
|
270
266
|
/**
|
|
@@ -274,7 +270,6 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
274
270
|
*/
|
|
275
271
|
async loginRecovery(challengeToken, recoveryCode) {
|
|
276
272
|
const result = await this.client.loginRecovery({ challengeToken, recoveryCode });
|
|
277
|
-
this.lowRecoveryCodesWarning.set(result.lowRecoveryCodesWarning);
|
|
278
273
|
this.setNewToken(result.result);
|
|
279
274
|
}
|
|
280
275
|
/**
|
|
@@ -100,7 +100,7 @@ export declare class AuthenticationApiController<AdditionalTokenPayload extends
|
|
|
100
100
|
invalidateAllOtherSessions({ getToken, getAuditor }: ApiRequestContext<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitPasswordResetData>, 'invalidateAllOtherSessions'>): Promise<ApiServerResult<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitPasswordResetData>, 'invalidateAllOtherSessions'>>;
|
|
101
101
|
protected enforceRateLimit(ip: string, subjectResource: string, auditor: Auditor, targetId: string, action: string): Promise<void>;
|
|
102
102
|
protected refundRateLimit(ip: string, subjectResource: string): Promise<void>;
|
|
103
|
-
protected getTokenResponse<T>(result: TokenResult<AdditionalTokenPayload>, body:
|
|
103
|
+
protected getTokenResponse<T>(result: TokenResult<AdditionalTokenPayload>, body: T): HttpServerResponse<T>;
|
|
104
104
|
protected getLoginResponse(result: LoginResult<AdditionalTokenPayload>): ApiServerResult<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitPasswordResetData>, 'login'>;
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
@@ -381,7 +381,6 @@ let AuthenticationApiController = AuthenticationApiController_1 = class Authenti
|
|
|
381
381
|
return this.getTokenResponse(result.result, {
|
|
382
382
|
type: 'success',
|
|
383
383
|
result: result.result.jsonToken.payload,
|
|
384
|
-
lowRecoveryCodesWarning: result.lowRecoveryCodesWarning,
|
|
385
384
|
});
|
|
386
385
|
}
|
|
387
386
|
return result;
|
|
@@ -158,7 +158,6 @@ export type TokenResult<AdditionalTokenPayload extends Record> = {
|
|
|
158
158
|
export type LoginSuccessResult<AdditionalTokenPayload extends Record> = {
|
|
159
159
|
type: 'success';
|
|
160
160
|
result: TokenResult<AdditionalTokenPayload>;
|
|
161
|
-
lowRecoveryCodesWarning?: boolean;
|
|
162
161
|
};
|
|
163
162
|
export type LoginTotpResult = {
|
|
164
163
|
type: 'totp';
|
|
@@ -1105,9 +1105,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
1105
1105
|
throw new ForbiddenError('Invalid recovery code');
|
|
1106
1106
|
}
|
|
1107
1107
|
const subject = await this.#subjectRepository.loadByQuery({ tenantId: tenant, id: subjectId });
|
|
1108
|
-
|
|
1109
|
-
const unusedRecoveryCodesCount = await this.#totpRecoveryCodeRepository.withTransaction(tx).countByQuery({ tenantId: tenant, totpId: totp.id, usedTimestamp: null });
|
|
1110
|
-
return { loginResult, unusedRecoveryCodesCount };
|
|
1108
|
+
return await this.#loginAlreadyValidatedSubject(subject, data, authAuditor, remember);
|
|
1111
1109
|
});
|
|
1112
1110
|
await authAuditor.info('recovery-login-success', {
|
|
1113
1111
|
tenantId: tenant,
|
|
@@ -1115,16 +1113,13 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
1115
1113
|
actorType: ActorType.Subject,
|
|
1116
1114
|
targetId: subjectId,
|
|
1117
1115
|
targetType: 'Subject',
|
|
1118
|
-
network: { sessionId: result.
|
|
1116
|
+
network: { sessionId: result.result.jsonToken.payload.session },
|
|
1119
1117
|
details: {
|
|
1120
|
-
sessionId: result.
|
|
1118
|
+
sessionId: result.result.jsonToken.payload.session,
|
|
1121
1119
|
remember,
|
|
1122
1120
|
},
|
|
1123
1121
|
});
|
|
1124
|
-
return
|
|
1125
|
-
...result.loginResult,
|
|
1126
|
-
lowRecoveryCodesWarning: result.unusedRecoveryCodesCount <= 3,
|
|
1127
|
-
};
|
|
1122
|
+
return result;
|
|
1128
1123
|
}
|
|
1129
1124
|
async #loginVerifyTotp(challengeTokenString, token, authAuditor) {
|
|
1130
1125
|
const challengeToken = await this.validateTotpChallengeToken(challengeTokenString);
|
|
@@ -7,33 +7,33 @@ import { ServerTiming } from '../server-timing.js';
|
|
|
7
7
|
export type SetCookieObject = SetCookieOptions & {
|
|
8
8
|
value: string;
|
|
9
9
|
};
|
|
10
|
-
export type HttpServerResponseBody = {
|
|
10
|
+
export type HttpServerResponseBody<out T = unknown> = {
|
|
11
11
|
stream?: ReadableStream<Uint8Array>;
|
|
12
12
|
buffer?: Uint8Array;
|
|
13
13
|
text?: string;
|
|
14
|
-
json?:
|
|
14
|
+
json?: T;
|
|
15
15
|
events?: ServerSentEventsSource;
|
|
16
16
|
};
|
|
17
17
|
export type HttpServerResponseBodyType = 'stream' | 'buffer' | 'text' | 'json' | 'events' | 'none';
|
|
18
|
-
export type HttpServerResponseOptions = {
|
|
18
|
+
export type HttpServerResponseOptions<out T = unknown> = {
|
|
19
19
|
statusCode?: number | undefined;
|
|
20
20
|
statusMessage?: string | undefined;
|
|
21
21
|
headers?: HttpHeadersInput | HttpHeaders;
|
|
22
22
|
cookies?: Record<string, SetCookieObject>;
|
|
23
|
-
body?: HttpServerResponseBody
|
|
23
|
+
body?: HttpServerResponseBody<T>;
|
|
24
24
|
};
|
|
25
|
-
export declare class HttpServerResponse {
|
|
25
|
+
export declare class HttpServerResponse<out T = unknown> {
|
|
26
26
|
#private;
|
|
27
27
|
readonly headers: HttpHeaders;
|
|
28
28
|
readonly serverTiming: ServerTiming;
|
|
29
29
|
statusCode: number | undefined;
|
|
30
30
|
statusMessage: string | undefined;
|
|
31
|
-
get body(): HttpServerResponseBody | undefined;
|
|
32
|
-
set body(value: HttpServerResponseBody | undefined);
|
|
31
|
+
get body(): HttpServerResponseBody<T> | undefined;
|
|
32
|
+
set body(value: HttpServerResponseBody<T> | undefined);
|
|
33
33
|
get bodyType(): HttpServerResponseBodyType;
|
|
34
|
-
constructor(response?: HttpServerResponseOptions);
|
|
35
|
-
static fromObject(options?: HttpServerResponseOptions): HttpServerResponse
|
|
36
|
-
static redirect(url: string, options?: HttpServerResponseOptions): HttpServerResponse
|
|
37
|
-
update(options: HttpServerResponseOptions): void;
|
|
34
|
+
constructor(response?: HttpServerResponseOptions<T>);
|
|
35
|
+
static fromObject<T>(options?: HttpServerResponseOptions<T>): HttpServerResponse<T>;
|
|
36
|
+
static redirect<T>(url: string, options?: HttpServerResponseOptions<T>): HttpServerResponse<T>;
|
|
37
|
+
update(options: HttpServerResponseOptions<T>): void;
|
|
38
38
|
}
|
|
39
|
-
export declare function redirect(url: string, options?: HttpServerResponseOptions): HttpServerResponse
|
|
39
|
+
export declare function redirect<T>(url: string, options?: HttpServerResponseOptions<T>): HttpServerResponse<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.93.
|
|
3
|
+
"version": "0.93.196",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -153,8 +153,8 @@
|
|
|
153
153
|
"type-fest": "^5.5"
|
|
154
154
|
},
|
|
155
155
|
"peerDependencies": {
|
|
156
|
-
"@aws-sdk/client-s3": "^3.
|
|
157
|
-
"@aws-sdk/s3-request-presigner": "^3.
|
|
156
|
+
"@aws-sdk/client-s3": "^3.1025",
|
|
157
|
+
"@aws-sdk/s3-request-presigner": "^3.1025",
|
|
158
158
|
"@genkit-ai/google-genai": "^1.31",
|
|
159
159
|
"@google-cloud/storage": "^7.19",
|
|
160
160
|
"@toon-format/toon": "^2.1.0",
|
package/schema/schema.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type SchemaTestResult<T> = {
|
|
|
20
20
|
};
|
|
21
21
|
type NormalizePrimitiveToConstructor<T> = Or<IsEqual<T, string>, IsEqual<T, String>> extends true ? typeof String : Or<IsEqual<T, number>, IsEqual<T, Number>> extends true ? typeof Number : Or<IsEqual<T, boolean>, IsEqual<T, Boolean>> extends true ? typeof Boolean : Or<IsEqual<T, bigint>, IsEqual<T, BigInt>> extends true ? typeof BigInt : Or<IsEqual<T, symbol>, IsEqual<T, Symbol>> extends true ? typeof Symbol : never;
|
|
22
22
|
export type SchemaTestable<T = any> = Schema<T> | AbstractConstructor<T> | NormalizePrimitiveToConstructor<T>;
|
|
23
|
-
export type SchemaOutput<T extends SchemaTestable> = T extends SchemaTestable<infer U> ? U : never;
|
|
23
|
+
export type SchemaOutput<T extends SchemaTestable> = T extends Schema<infer U> ? U : T extends SchemaTestable<infer U> ? U : never;
|
|
24
24
|
export declare const OPTIONAL: unique symbol;
|
|
25
25
|
export type SchemaOptions<_T> = {
|
|
26
26
|
description?: string | null;
|