@tstdl/base 0.93.87 → 0.93.89
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/ai/genkit/helpers.d.ts +3 -1
- package/ai/genkit/helpers.js +3 -3
- package/api/server/gateway.d.ts +3 -0
- package/api/server/gateway.js +15 -4
- package/api/server/middlewares/catch-error.middleware.js +2 -4
- package/api/server/middlewares/cors.middleware.js +2 -3
- package/api/server/middlewares/csrf.middleware.d.ts +41 -0
- package/api/server/middlewares/csrf.middleware.js +108 -0
- package/api/server/middlewares/index.d.ts +1 -0
- package/api/server/middlewares/index.js +1 -0
- package/api/server/module.d.ts +8 -2
- package/api/server/module.js +14 -8
- package/api/server/tests/csrf.middleware.test.js +91 -0
- package/audit/drizzle/{0000_bored_stick.sql → 0000_lumpy_thunderball.sql} +3 -3
- package/audit/drizzle/meta/0000_snapshot.json +4 -4
- package/audit/drizzle/meta/_journal.json +2 -9
- package/audit/module.d.ts +4 -1
- package/audit/module.js +3 -2
- package/audit/schemas.d.ts +1 -1
- package/audit/types.d.ts +1 -1
- package/audit/types.js +1 -1
- package/authentication/client/authentication.service.d.ts +14 -1
- package/authentication/client/authentication.service.js +82 -23
- package/authentication/client/http-client.middleware.d.ts +6 -0
- package/authentication/client/http-client.middleware.js +36 -0
- package/authentication/client/module.js +8 -2
- package/authentication/models/service-account.model.d.ts +2 -2
- package/authentication/models/service-account.model.js +10 -5
- package/authentication/models/subject.model.d.ts +19 -5
- package/authentication/models/subject.model.js +25 -29
- package/authentication/models/system-account.model.d.ts +3 -2
- package/authentication/models/system-account.model.js +11 -5
- package/authentication/models/user.model.d.ts +2 -11
- package/authentication/models/user.model.js +5 -16
- package/authentication/server/authentication-api-request-token.provider.d.ts +0 -2
- package/authentication/server/authentication-api-request-token.provider.js +3 -11
- package/authentication/server/authentication.api-controller.d.ts +1 -2
- package/authentication/server/authentication.api-controller.js +8 -9
- package/authentication/server/authentication.audit.d.ts +3 -2
- package/authentication/server/authentication.service.d.ts +27 -1
- package/authentication/server/authentication.service.js +67 -18
- package/authentication/server/drizzle/{0000_normal_paper_doll.sql → 0000_soft_tag.sql} +25 -32
- package/authentication/server/drizzle/meta/0000_snapshot.json +180 -205
- package/authentication/server/drizzle/meta/_journal.json +2 -2
- package/authentication/server/helper.js +9 -2
- package/authentication/server/module.d.ts +4 -1
- package/authentication/server/module.js +9 -5
- package/authentication/server/schemas.d.ts +2 -1
- package/authentication/server/schemas.js +2 -2
- package/authentication/server/subject.service.d.ts +14 -8
- package/authentication/server/subject.service.js +86 -84
- package/authentication/tests/authentication-ancillary.service.test.d.ts +1 -0
- package/authentication/tests/authentication-ancillary.service.test.js +13 -0
- package/authentication/tests/authentication-secret-requirements.validator.test.d.ts +1 -0
- package/authentication/tests/authentication-secret-requirements.validator.test.js +29 -0
- package/authentication/tests/authentication.api-controller.test.d.ts +1 -0
- package/authentication/tests/authentication.api-controller.test.js +88 -0
- package/authentication/tests/authentication.api-request-token.provider.test.d.ts +1 -0
- package/authentication/tests/authentication.api-request-token.provider.test.js +48 -0
- package/authentication/tests/authentication.client-middleware.test.d.ts +1 -0
- package/authentication/tests/authentication.client-middleware.test.js +23 -0
- package/authentication/tests/authentication.client-service.test.d.ts +1 -0
- package/authentication/tests/authentication.client-service.test.js +70 -0
- package/authentication/tests/authentication.service.test.d.ts +1 -0
- package/authentication/tests/authentication.service.test.js +186 -0
- package/authentication/tests/authentication.test-ancillary-service.d.ts +9 -0
- package/authentication/tests/authentication.test-ancillary-service.js +27 -0
- package/authentication/tests/helper.test.d.ts +1 -0
- package/authentication/tests/helper.test.js +107 -0
- package/authentication/tests/secret-requirements.error.test.d.ts +1 -0
- package/authentication/tests/secret-requirements.error.test.js +14 -0
- package/authentication/tests/subject.service.test.d.ts +1 -0
- package/authentication/tests/subject.service.test.js +140 -0
- package/circuit-breaker/postgres/drizzle/meta/0000_snapshot.json +1 -1
- package/circuit-breaker/postgres/drizzle/meta/_journal.json +2 -2
- package/circuit-breaker/postgres/module.d.ts +7 -1
- package/circuit-breaker/postgres/module.js +8 -6
- package/circuit-breaker/tests/circuit-breaker.test.js +2 -22
- package/document-management/api/document-management.api.js +2 -6
- package/document-management/server/services/document-validation.service.js +6 -5
- package/document-management/server/services/document-workflow.service.js +5 -5
- package/document-management/service-models/document-folders.view-model.d.ts +5 -2
- package/document-management/service-models/document-folders.view-model.js +42 -9
- package/document-management/service-models/enriched/enriched-document-management-data.view.js +1 -1
- package/examples/document-management/main.js +4 -4
- package/http/client/adapters/undici.adapter.d.ts +7 -5
- package/http/client/adapters/undici.adapter.js +13 -10
- package/http/client/module.d.ts +3 -1
- package/http/client/module.js +8 -9
- package/http/server/http-server.d.ts +2 -0
- package/http/server/node/module.d.ts +6 -2
- package/http/server/node/module.js +6 -4
- package/http/server/node/node-http-server.d.ts +2 -0
- package/http/server/node/node-http-server.js +7 -0
- package/http/types.d.ts +1 -1
- package/key-value-store/postgres/module.d.ts +7 -1
- package/key-value-store/postgres/module.js +7 -3
- package/lock/postgres/lock.js +0 -1
- package/lock/postgres/module.d.ts +7 -1
- package/lock/postgres/module.js +9 -5
- package/logger/formatter.d.ts +2 -0
- package/logger/formatters/json.js +2 -2
- package/logger/formatters/pretty-print.js +8 -10
- package/logger/logger.d.ts +1 -1
- package/logger/logger.js +15 -12
- package/message-bus/local/module.d.ts +5 -2
- package/message-bus/local/module.js +5 -4
- package/module/module.d.ts +2 -1
- package/module/module.js +3 -0
- package/module/modules/web-server.module.d.ts +11 -6
- package/module/modules/web-server.module.js +15 -10
- package/orm/decorators.d.ts +24 -1
- package/orm/decorators.js +40 -4
- package/orm/query/base.d.ts +17 -17
- package/orm/query/base.js +1 -1
- package/orm/repository.types.d.ts +45 -1
- package/orm/schemas/tsvector.js +1 -1
- package/orm/server/drizzle/schema-converter.d.ts +3 -1
- package/orm/server/drizzle/schema-converter.js +120 -14
- package/orm/server/index.d.ts +1 -0
- package/orm/server/index.js +1 -0
- package/orm/server/module.d.ts +4 -2
- package/orm/server/module.js +6 -5
- package/orm/server/query-converter.d.ts +6 -3
- package/orm/server/query-converter.js +32 -20
- package/orm/server/repository-config.d.ts +8 -0
- package/orm/server/repository-config.js +8 -0
- package/orm/server/repository.d.ts +117 -43
- package/orm/server/repository.js +757 -253
- package/orm/server/transaction.d.ts +4 -2
- package/orm/server/transaction.js +14 -5
- package/orm/server/transactional.d.ts +6 -2
- package/orm/server/transactional.js +39 -9
- package/orm/server/types.d.ts +2 -0
- package/orm/sqls/case-when.d.ts +3 -3
- package/orm/sqls/case-when.js +2 -2
- package/orm/sqls/sqls.d.ts +31 -5
- package/orm/sqls/sqls.js +69 -6
- package/orm/tests/data-types.test.d.ts +1 -0
- package/orm/tests/data-types.test.js +39 -0
- package/orm/tests/decorators.test.d.ts +1 -0
- package/orm/tests/decorators.test.js +77 -0
- package/orm/tests/encryption.test.d.ts +1 -0
- package/orm/tests/encryption.test.js +34 -0
- package/orm/tests/query-complex.test.d.ts +1 -0
- package/orm/tests/query-complex.test.js +203 -0
- package/orm/tests/query-converter-complex.test.d.ts +1 -0
- package/orm/tests/query-converter-complex.test.js +126 -0
- package/orm/tests/query-converter.test.d.ts +1 -0
- package/orm/tests/query-converter.test.js +123 -0
- package/orm/tests/repository-advanced.test.d.ts +1 -0
- package/orm/tests/repository-advanced.test.js +232 -0
- package/orm/tests/repository-attributes.test.d.ts +1 -0
- package/orm/tests/repository-attributes.test.js +99 -0
- package/orm/tests/repository-comprehensive.test.d.ts +1 -0
- package/orm/tests/repository-comprehensive.test.js +187 -0
- package/orm/tests/repository-coverage.test.d.ts +1 -0
- package/orm/tests/repository-coverage.test.js +303 -0
- package/orm/tests/repository-cti-complex.test.d.ts +1 -0
- package/orm/tests/repository-cti-complex.test.js +170 -0
- package/orm/tests/repository-cti-embedded.test.d.ts +1 -0
- package/orm/tests/repository-cti-embedded.test.js +188 -0
- package/orm/tests/repository-cti-extensive.test.d.ts +1 -0
- package/orm/tests/repository-cti-extensive.test.js +308 -0
- package/orm/tests/repository-cti-mapping.test.d.ts +1 -0
- package/orm/tests/repository-cti-mapping.test.js +121 -0
- package/orm/tests/repository-cti-search.test.d.ts +1 -0
- package/orm/tests/repository-cti-search.test.js +152 -0
- package/orm/tests/repository-cti-soft-delete.test.d.ts +1 -0
- package/orm/tests/repository-cti-soft-delete.test.js +115 -0
- package/orm/tests/repository-cti-transactions.test.d.ts +1 -0
- package/orm/tests/repository-cti-transactions.test.js +126 -0
- package/orm/tests/repository-cti-upsert-many.test.d.ts +1 -0
- package/orm/tests/repository-cti-upsert-many.test.js +127 -0
- package/orm/tests/repository-cti.test.d.ts +1 -0
- package/orm/tests/repository-cti.test.js +456 -0
- package/orm/tests/repository-edge-cases.test.d.ts +1 -0
- package/orm/tests/repository-edge-cases.test.js +216 -0
- package/orm/tests/repository-expiration.test.d.ts +1 -0
- package/orm/tests/repository-expiration.test.js +153 -0
- package/orm/tests/repository-extra-coverage.test.d.ts +1 -0
- package/orm/tests/repository-extra-coverage.test.js +546 -0
- package/orm/tests/repository-mapping.test.d.ts +1 -0
- package/orm/tests/repository-mapping.test.js +71 -0
- package/orm/tests/repository-regression.test.d.ts +1 -0
- package/orm/tests/repository-regression.test.js +330 -0
- package/orm/tests/repository-search-coverage.test.d.ts +1 -0
- package/orm/tests/repository-search-coverage.test.js +129 -0
- package/orm/tests/repository-search.test.d.ts +1 -0
- package/orm/tests/repository-search.test.js +116 -0
- package/orm/tests/repository-soft-delete.test.d.ts +1 -0
- package/orm/tests/repository-soft-delete.test.js +143 -0
- package/orm/tests/repository-transactions-nested.test.d.ts +1 -0
- package/orm/tests/repository-transactions-nested.test.js +202 -0
- package/orm/tests/repository-types.test.d.ts +1 -0
- package/orm/tests/repository-types.test.js +218 -0
- package/orm/tests/schema-converter.test.d.ts +1 -0
- package/orm/tests/schema-converter.test.js +81 -0
- package/orm/tests/schema-generation.test.d.ts +1 -0
- package/orm/tests/schema-generation.test.js +127 -0
- package/orm/tests/sql-helpers.test.d.ts +1 -0
- package/orm/tests/sql-helpers.test.js +67 -0
- package/orm/tests/transaction-safety.test.d.ts +1 -0
- package/orm/tests/transaction-safety.test.js +81 -0
- package/orm/tests/transactional.test.d.ts +1 -0
- package/orm/tests/transactional.test.js +224 -0
- package/orm/tests/utils.test.d.ts +1 -0
- package/orm/tests/utils.test.js +70 -0
- package/orm/utils.d.ts +7 -0
- package/orm/utils.js +26 -6
- package/package.json +12 -7
- package/pool/pool.js +1 -1
- package/rate-limit/index.d.ts +2 -0
- package/rate-limit/index.js +2 -0
- package/rate-limit/postgres/drizzle/0000_watery_rage.sql +7 -0
- package/{queue → rate-limit}/postgres/drizzle/meta/0000_snapshot.json +14 -39
- package/rate-limit/postgres/drizzle/meta/_journal.json +13 -0
- package/{queue → rate-limit}/postgres/drizzle.config.js +1 -1
- package/rate-limit/postgres/index.d.ts +4 -0
- package/rate-limit/postgres/index.js +4 -0
- package/rate-limit/postgres/module.d.ts +12 -0
- package/rate-limit/postgres/module.js +28 -0
- package/rate-limit/postgres/postgres-rate-limiter.d.ts +9 -0
- package/rate-limit/postgres/postgres-rate-limiter.js +56 -0
- package/rate-limit/postgres/rate-limit.model.d.ts +8 -0
- package/rate-limit/postgres/rate-limit.model.js +35 -0
- package/rate-limit/postgres/rate-limiter.provider.d.ts +6 -0
- package/rate-limit/postgres/rate-limiter.provider.js +21 -0
- package/rate-limit/postgres/schemas.d.ts +3 -0
- package/rate-limit/postgres/schemas.js +4 -0
- package/rate-limit/provider.d.ts +9 -0
- package/rate-limit/provider.js +2 -0
- package/rate-limit/rate-limiter.d.ts +35 -0
- package/rate-limit/rate-limiter.js +3 -0
- package/rate-limit/tests/postgres-rate-limiter.test.d.ts +1 -0
- package/rate-limit/tests/postgres-rate-limiter.test.js +92 -0
- package/signals/implementation/configure.d.ts +3 -0
- package/signals/implementation/configure.js +3 -0
- package/sse/data-stream-source.d.ts +1 -1
- package/sse/data-stream-source.js +6 -6
- package/task-queue/enqueue-batch.d.ts +17 -0
- package/task-queue/enqueue-batch.js +24 -0
- package/{queue → task-queue}/index.d.ts +1 -1
- package/{queue → task-queue}/index.js +1 -1
- package/task-queue/postgres/drizzle/0000_thin_black_panther.sql +74 -0
- package/task-queue/postgres/drizzle/meta/0000_snapshot.json +592 -0
- package/task-queue/postgres/drizzle/meta/_journal.json +13 -0
- package/task-queue/postgres/drizzle.config.d.ts +2 -0
- package/task-queue/postgres/drizzle.config.js +11 -0
- package/task-queue/postgres/index.d.ts +4 -0
- package/task-queue/postgres/index.js +4 -0
- package/task-queue/postgres/module.d.ts +12 -0
- package/task-queue/postgres/module.js +28 -0
- package/task-queue/postgres/schemas.d.ts +16 -0
- package/task-queue/postgres/schemas.js +8 -0
- package/task-queue/postgres/task-queue.d.ts +83 -0
- package/task-queue/postgres/task-queue.js +1054 -0
- package/task-queue/postgres/task-queue.provider.d.ts +7 -0
- package/{queue/postgres/queue.provider.js → task-queue/postgres/task-queue.provider.js} +8 -8
- package/task-queue/postgres/task.model.d.ts +39 -0
- package/task-queue/postgres/task.model.js +178 -0
- package/{queue → task-queue}/provider.d.ts +3 -3
- package/task-queue/provider.js +2 -0
- package/{queue → task-queue}/task-context.d.ts +7 -7
- package/{queue → task-queue}/task-context.js +8 -8
- package/{queue/queue.d.ts → task-queue/task-queue.d.ts} +128 -59
- package/task-queue/task-queue.js +200 -0
- package/task-queue/tests/complex.test.d.ts +1 -0
- package/task-queue/tests/complex.test.js +299 -0
- package/task-queue/tests/dependencies.test.d.ts +1 -0
- package/task-queue/tests/dependencies.test.js +174 -0
- package/task-queue/tests/queue.test.d.ts +1 -0
- package/task-queue/tests/queue.test.js +334 -0
- package/task-queue/tests/worker.test.d.ts +1 -0
- package/task-queue/tests/worker.test.js +163 -0
- package/test1.js +1 -1
- package/test4.js +2 -2
- package/unit-test/index.d.ts +1 -0
- package/unit-test/index.js +1 -0
- package/unit-test/integration-setup.d.ts +55 -0
- package/unit-test/integration-setup.js +182 -0
- package/utils/patterns.d.ts +3 -0
- package/utils/patterns.js +6 -1
- package/audit/drizzle/0001_previous_network.sql +0 -2
- package/audit/drizzle/meta/0001_snapshot.json +0 -195
- package/queue/enqueue-batch.d.ts +0 -17
- package/queue/enqueue-batch.js +0 -18
- package/queue/postgres/drizzle/0000_zippy_moondragon.sql +0 -11
- package/queue/postgres/drizzle/0001_certain_wild_pack.sql +0 -2
- package/queue/postgres/drizzle/0002_dear_meggan.sql +0 -2
- package/queue/postgres/drizzle/0003_tricky_venom.sql +0 -30
- package/queue/postgres/drizzle/meta/0001_snapshot.json +0 -103
- package/queue/postgres/drizzle/meta/0002_snapshot.json +0 -90
- package/queue/postgres/drizzle/meta/0003_snapshot.json +0 -288
- package/queue/postgres/drizzle/meta/_journal.json +0 -34
- package/queue/postgres/index.d.ts +0 -4
- package/queue/postgres/index.js +0 -4
- package/queue/postgres/module.d.ts +0 -9
- package/queue/postgres/module.js +0 -29
- package/queue/postgres/queue.d.ts +0 -60
- package/queue/postgres/queue.js +0 -681
- package/queue/postgres/queue.provider.d.ts +0 -7
- package/queue/postgres/schemas.d.ts +0 -14
- package/queue/postgres/schemas.js +0 -6
- package/queue/postgres/task.model.d.ts +0 -24
- package/queue/postgres/task.model.js +0 -115
- package/queue/provider.js +0 -2
- package/queue/queue.js +0 -131
- package/queue/tests/queue.test.js +0 -623
- package/test3.d.ts +0 -1
- package/test3.js +0 -47
- /package/{queue/tests/queue.test.d.ts → api/server/tests/csrf.middleware.test.d.ts} +0 -0
- /package/circuit-breaker/postgres/drizzle/{0000_hard_shocker.sql → 0000_cooing_korath.sql} +0 -0
- /package/{queue → rate-limit}/postgres/drizzle.config.d.ts +0 -0
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { Subject, filter, firstValueFrom, race, timer } from 'rxjs';
|
|
11
|
-
import { CancellationToken } from '../../cancellation/token.js';
|
|
11
|
+
import { CancellationSignal, CancellationToken } from '../../cancellation/token.js';
|
|
12
12
|
import { isNode } from '../../environment.js';
|
|
13
13
|
import { BadRequestError } from '../../errors/bad-request.error.js';
|
|
14
14
|
import { ForbiddenError } from '../../errors/forbidden.error.js';
|
|
@@ -28,6 +28,9 @@ import { assertDefinedPass, isDefined, isNullOrUndefined, isUndefined } from '..
|
|
|
28
28
|
import { millisecondsPerSecond } from '../../utils/units.js';
|
|
29
29
|
import { AUTHENTICATION_API_CLIENT, INITIAL_AUTHENTICATION_DATA } from './tokens.js';
|
|
30
30
|
const tokenStorageKey = 'AuthenticationService:token';
|
|
31
|
+
const rawTokenStorageKey = 'AuthenticationService:raw-token';
|
|
32
|
+
const rawRefreshTokenStorageKey = 'AuthenticationService:raw-refresh-token';
|
|
33
|
+
const rawImpersonatorRefreshTokenStorageKey = 'AuthenticationService:raw-impersonator-refresh-token';
|
|
31
34
|
const authenticationDataStorageKey = 'AuthenticationService:authentication-data';
|
|
32
35
|
const impersonatorAuthenticationDataStorageKey = 'AuthenticationService:impersonator-authentication-data';
|
|
33
36
|
const tokenUpdateBusName = 'AuthenticationService:tokenUpdate';
|
|
@@ -67,8 +70,9 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
67
70
|
forceRefreshToken = new CancellationToken();
|
|
68
71
|
lock = inject(Lock, refreshLockResource);
|
|
69
72
|
logger = inject(Logger, 'AuthenticationService');
|
|
70
|
-
disposeToken =
|
|
73
|
+
disposeToken = inject(CancellationSignal).createChild();
|
|
71
74
|
clockOffset = 0;
|
|
75
|
+
refreshLoopPromise;
|
|
72
76
|
/**
|
|
73
77
|
* Observable for authentication errors.
|
|
74
78
|
* Emits when a refresh fails.
|
|
@@ -76,6 +80,12 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
76
80
|
error$ = this.errorSubject.asObservable();
|
|
77
81
|
/** Current token */
|
|
78
82
|
token = signal(undefined);
|
|
83
|
+
/** Current raw token */
|
|
84
|
+
rawToken = signal(undefined);
|
|
85
|
+
/** Current raw refresh token */
|
|
86
|
+
rawRefreshToken = signal(undefined);
|
|
87
|
+
/** Current raw impersonator refresh token */
|
|
88
|
+
rawImpersonatorRefreshToken = signal(undefined);
|
|
79
89
|
/** Whether the user is logged in */
|
|
80
90
|
isLoggedIn = computed(() => isDefined(this.token()));
|
|
81
91
|
/** Current session id */
|
|
@@ -168,7 +178,7 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
168
178
|
initialize() {
|
|
169
179
|
this.loadToken();
|
|
170
180
|
this.tokenUpdateBus.messages$.subscribe((token) => this.token.set(token));
|
|
171
|
-
|
|
181
|
+
this.refreshLoopPromise = this.refreshLoop();
|
|
172
182
|
}
|
|
173
183
|
/** @internal */
|
|
174
184
|
async [Symbol.asyncDispose]() {
|
|
@@ -180,6 +190,7 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
180
190
|
*/
|
|
181
191
|
async dispose() {
|
|
182
192
|
this.disposeToken.set();
|
|
193
|
+
await this.refreshLoopPromise;
|
|
183
194
|
this.errorSubject.complete();
|
|
184
195
|
await this.loggedOutBus.dispose();
|
|
185
196
|
await this.tokenUpdateBus.dispose();
|
|
@@ -331,8 +342,33 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
331
342
|
async checkSecret(secret) {
|
|
332
343
|
return await this.client.checkSecret({ secret });
|
|
333
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* Update raw tokens.
|
|
347
|
+
* @param token Raw token
|
|
348
|
+
* @param refreshToken Raw refresh token
|
|
349
|
+
* @param impersonatorRefreshToken Raw impersonator refresh token
|
|
350
|
+
*/
|
|
351
|
+
updateRawTokens(token, refreshToken, impersonatorRefreshToken) {
|
|
352
|
+
if (isDefined(token)) {
|
|
353
|
+
this.rawToken.set(token);
|
|
354
|
+
}
|
|
355
|
+
if (isDefined(refreshToken)) {
|
|
356
|
+
this.rawRefreshToken.set(refreshToken);
|
|
357
|
+
}
|
|
358
|
+
if (isDefined(impersonatorRefreshToken)) {
|
|
359
|
+
this.rawImpersonatorRefreshToken.set(impersonatorRefreshToken);
|
|
360
|
+
}
|
|
361
|
+
if (isDefined(token) || isDefined(refreshToken) || isDefined(impersonatorRefreshToken)) {
|
|
362
|
+
this.saveToken(this.token(), this.rawToken(), this.rawRefreshToken(), this.rawImpersonatorRefreshToken());
|
|
363
|
+
}
|
|
364
|
+
}
|
|
334
365
|
setNewToken(token) {
|
|
335
|
-
|
|
366
|
+
if (isUndefined(token)) {
|
|
367
|
+
this.rawToken.set(undefined);
|
|
368
|
+
this.rawRefreshToken.set(undefined);
|
|
369
|
+
this.rawImpersonatorRefreshToken.set(undefined);
|
|
370
|
+
}
|
|
371
|
+
this.saveToken(token, this.rawToken(), this.rawRefreshToken(), this.rawImpersonatorRefreshToken());
|
|
336
372
|
this.token.set(token);
|
|
337
373
|
this.tokenUpdateBus.publishAndForget(token);
|
|
338
374
|
}
|
|
@@ -342,30 +378,44 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
342
378
|
}
|
|
343
379
|
while (this.disposeToken.isUnset) {
|
|
344
380
|
try {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
381
|
+
const token = this.token();
|
|
382
|
+
if (isUndefined(token)) {
|
|
383
|
+
// Wait for login, dispose, or forced refresh
|
|
384
|
+
await firstValueFrom(race([this.definedToken$, this.disposeToken, this.forceRefreshToken]));
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
const now = this.estimatedServerTimestampSeconds();
|
|
388
|
+
const needsRefresh = this.forceRefreshToken.isSet || (now >= (token.exp - refreshBufferSeconds));
|
|
389
|
+
if (needsRefresh) {
|
|
390
|
+
// Only take the lock when we actually intend to refresh.
|
|
391
|
+
// Using tryUse(undefined, ...) ensures we try once and don't block if another instance is already refreshing.
|
|
392
|
+
await this.lock.tryUse(undefined, async () => {
|
|
393
|
+
// Re-check conditions inside the lock to avoid redundant refreshes if another instance just did it.
|
|
394
|
+
const currentToken = this.token();
|
|
395
|
+
const currentNow = this.estimatedServerTimestampSeconds();
|
|
396
|
+
const stillNeedsRefresh = isDefined(currentToken) && (this.forceRefreshToken.isSet || (currentNow >= (currentToken.exp - refreshBufferSeconds)));
|
|
397
|
+
if (stillNeedsRefresh) {
|
|
398
|
+
this.forceRefreshToken.unset();
|
|
399
|
+
await this.refresh();
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
}
|
|
349
403
|
const delay = ((this.token()?.exp ?? 0) - this.estimatedServerTimestampSeconds() - refreshBufferSeconds) * millisecondsPerSecond;
|
|
350
|
-
|
|
404
|
+
// Ensure delay is at least 0 to avoid tight loop, or wait longer if not logged in.
|
|
405
|
+
// If not logged in after refresh attempt (e.g. session invalidated), we wait for login.
|
|
406
|
+
if (isUndefined(this.token()) || (delay < 0)) {
|
|
407
|
+
await firstValueFrom(race([this.definedToken$, this.disposeToken, this.forceRefreshToken, timer(5000)]));
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
await firstValueFrom(race([timer(delay), this.disposeToken, this.forceRefreshToken]));
|
|
411
|
+
}
|
|
351
412
|
}
|
|
352
|
-
catch {
|
|
413
|
+
catch (error) {
|
|
414
|
+
this.logger.error(error);
|
|
353
415
|
await firstValueFrom(race([timer(5000), this.disposeToken, this.forceRefreshToken]));
|
|
354
416
|
}
|
|
355
417
|
}
|
|
356
418
|
}
|
|
357
|
-
async refreshLoopIteration() {
|
|
358
|
-
// Wait for a token to be available or for the service to be disposed.
|
|
359
|
-
const token = await firstValueFrom(race([this.definedToken$, this.disposeToken]));
|
|
360
|
-
if (isUndefined(token)) {
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
const needsRefresh = this.estimatedServerTimestampSeconds() >= (token.exp - refreshBufferSeconds);
|
|
364
|
-
if (this.forceRefreshToken.isSet || needsRefresh) {
|
|
365
|
-
this.forceRefreshToken.unset();
|
|
366
|
-
await this.refresh(); // Errors are caught by the outer loop
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
419
|
async handleRefreshError(error) {
|
|
370
420
|
this.logger.error(error);
|
|
371
421
|
this.errorSubject.next(error);
|
|
@@ -386,12 +436,21 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
386
436
|
this.clockOffset = 0;
|
|
387
437
|
}
|
|
388
438
|
}
|
|
389
|
-
saveToken(token) {
|
|
439
|
+
saveToken(token, rawToken, rawRefreshToken, rawImpersonatorRefreshToken) {
|
|
390
440
|
this.writeToStorage(tokenStorageKey, token);
|
|
441
|
+
this.writeToStorage(rawTokenStorageKey, rawToken);
|
|
442
|
+
this.writeToStorage(rawRefreshTokenStorageKey, rawRefreshToken);
|
|
443
|
+
this.writeToStorage(rawImpersonatorRefreshTokenStorageKey, rawImpersonatorRefreshToken);
|
|
391
444
|
}
|
|
392
445
|
loadToken() {
|
|
393
446
|
const token = this.readFromStorage(tokenStorageKey);
|
|
447
|
+
const rawToken = this.readFromStorage(rawTokenStorageKey);
|
|
448
|
+
const rawRefreshToken = this.readFromStorage(rawRefreshTokenStorageKey);
|
|
449
|
+
const rawImpersonatorRefreshToken = this.readFromStorage(rawImpersonatorRefreshTokenStorageKey);
|
|
394
450
|
this.token.set(token);
|
|
451
|
+
this.rawToken.set(rawToken);
|
|
452
|
+
this.rawRefreshToken.set(rawRefreshToken);
|
|
453
|
+
this.rawImpersonatorRefreshToken.set(rawImpersonatorRefreshToken);
|
|
395
454
|
}
|
|
396
455
|
readFromStorage(key) {
|
|
397
456
|
try {
|
|
@@ -7,3 +7,9 @@ import type { AuthenticationClientService } from './authentication.service.js';
|
|
|
7
7
|
* @returns A http client middleware.
|
|
8
8
|
*/
|
|
9
9
|
export declare function waitForAuthenticationCredentialsMiddleware(authenticationServiceOrProvider: ValueOrAsyncProvider<AuthenticationClientService>): HttpClientMiddleware;
|
|
10
|
+
/**
|
|
11
|
+
* A http client middleware that adds authentication tokens to outgoing requests and extracts them from incoming responses.
|
|
12
|
+
* @param authenticationServiceOrProvider The authentication service or a provider for it.
|
|
13
|
+
* @returns A http client middleware.
|
|
14
|
+
*/
|
|
15
|
+
export declare function authenticationMiddleware(authenticationServiceOrProvider: ValueOrAsyncProvider<AuthenticationClientService>): HttpClientMiddleware;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { firstValueFrom, timeout } from 'rxjs';
|
|
2
|
+
import { isDefined } from '../../utils/type-guards.js';
|
|
2
3
|
import { cacheValueOrAsyncProvider } from '../../utils/value-or-provider.js';
|
|
3
4
|
import { dontWaitForValidToken } from '../authentication.api.js';
|
|
4
5
|
/**
|
|
@@ -20,3 +21,38 @@ export function waitForAuthenticationCredentialsMiddleware(authenticationService
|
|
|
20
21
|
}
|
|
21
22
|
return waitForAuthenticationCredentialsMiddleware;
|
|
22
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* A http client middleware that adds authentication tokens to outgoing requests and extracts them from incoming responses.
|
|
26
|
+
* @param authenticationServiceOrProvider The authentication service or a provider for it.
|
|
27
|
+
* @returns A http client middleware.
|
|
28
|
+
*/
|
|
29
|
+
export function authenticationMiddleware(authenticationServiceOrProvider) {
|
|
30
|
+
const getAuthenticationService = cacheValueOrAsyncProvider(authenticationServiceOrProvider);
|
|
31
|
+
async function authenticationMiddleware(context, next) {
|
|
32
|
+
const { request } = context;
|
|
33
|
+
const authenticationService = await getAuthenticationService();
|
|
34
|
+
const rawToken = authenticationService.rawToken();
|
|
35
|
+
const rawRefreshToken = authenticationService.rawRefreshToken();
|
|
36
|
+
const rawImpersonatorRefreshToken = authenticationService.rawImpersonatorRefreshToken();
|
|
37
|
+
if (isDefined(rawToken)) {
|
|
38
|
+
request.headers.setIfMissing('Authorization', rawToken);
|
|
39
|
+
}
|
|
40
|
+
if (isDefined(rawRefreshToken)) {
|
|
41
|
+
request.headers.setIfMissing('X-Refresh-Token', rawRefreshToken);
|
|
42
|
+
}
|
|
43
|
+
if (isDefined(rawImpersonatorRefreshToken)) {
|
|
44
|
+
request.headers.setIfMissing('X-Impersonator-Refresh-Token', rawImpersonatorRefreshToken);
|
|
45
|
+
}
|
|
46
|
+
await next();
|
|
47
|
+
if (isDefined(context.response)) {
|
|
48
|
+
const { response } = context;
|
|
49
|
+
const responseToken = response.headers.tryGetSingle('X-Authorization');
|
|
50
|
+
const responseRefreshToken = response.headers.tryGetSingle('X-Refresh-Token');
|
|
51
|
+
const responseImpersonatorRefreshToken = response.headers.tryGetSingle('X-Impersonator-Refresh-Token');
|
|
52
|
+
if (isDefined(responseToken) || isDefined(responseRefreshToken) || isDefined(responseImpersonatorRefreshToken)) {
|
|
53
|
+
authenticationService.updateRawTokens(responseToken, responseRefreshToken, responseImpersonatorRefreshToken);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return authenticationMiddleware;
|
|
58
|
+
}
|
|
@@ -3,7 +3,7 @@ import { getCurrentInjector } from '../../injector/inject.js';
|
|
|
3
3
|
import { Injector } from '../../injector/injector.js';
|
|
4
4
|
import { isDefined } from '../../utils/type-guards.js';
|
|
5
5
|
import { AuthenticationClientService } from './authentication.service.js';
|
|
6
|
-
import { waitForAuthenticationCredentialsMiddleware } from './http-client.middleware.js';
|
|
6
|
+
import { authenticationMiddleware, waitForAuthenticationCredentialsMiddleware } from './http-client.middleware.js';
|
|
7
7
|
import { AUTHENTICATION_API_CLIENT, INITIAL_AUTHENTICATION_DATA } from './tokens.js';
|
|
8
8
|
/**
|
|
9
9
|
* Configures authentication client services.
|
|
@@ -17,12 +17,18 @@ export function configureAuthenticationClient(config, injector = getCurrentInjec
|
|
|
17
17
|
if (isDefined(config.initialAuthenticationData)) {
|
|
18
18
|
(injector ?? Injector).register(INITIAL_AUTHENTICATION_DATA, { useValue: config.initialAuthenticationData });
|
|
19
19
|
}
|
|
20
|
-
if (
|
|
20
|
+
if (config.registerMiddleware == true) {
|
|
21
21
|
(injector ?? Injector).register(HTTP_CLIENT_MIDDLEWARE, {
|
|
22
22
|
useFactory(_, context) {
|
|
23
23
|
const authenticationService = context.resolve(AuthenticationClientService, undefined, { forwardRef: true, forwardRefTypeHint: 'object' });
|
|
24
24
|
return waitForAuthenticationCredentialsMiddleware(authenticationService);
|
|
25
25
|
},
|
|
26
26
|
}, { multi: true });
|
|
27
|
+
(injector ?? Injector).register(HTTP_CLIENT_MIDDLEWARE, {
|
|
28
|
+
useFactory(_, context) {
|
|
29
|
+
const authenticationService = context.resolve(AuthenticationClientService, undefined, { forwardRef: true, forwardRefTypeHint: 'object' });
|
|
30
|
+
return authenticationMiddleware(authenticationService);
|
|
31
|
+
},
|
|
32
|
+
}, { multi: true });
|
|
27
33
|
}
|
|
28
34
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { TenantEntity } from '../../orm/entity.js';
|
|
2
1
|
import { Subject } from './subject.model.js';
|
|
3
|
-
export declare class ServiceAccount extends
|
|
2
|
+
export declare class ServiceAccount extends Subject {
|
|
3
|
+
displayName: string;
|
|
4
4
|
description: string;
|
|
5
5
|
/** Who owns this service account? If null, it is a tenant-wide service account. */
|
|
6
6
|
parent: Subject | null;
|
|
@@ -7,15 +7,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
11
|
-
import { Table, TenantReference, UuidProperty } from '../../orm/index.js';
|
|
10
|
+
import { ChildEntity, Table, TenantReference, UuidProperty } from '../../orm/index.js';
|
|
12
11
|
import { StringProperty } from '../../schema/index.js';
|
|
13
|
-
import { Subject } from './subject.model.js';
|
|
14
|
-
let ServiceAccount = class ServiceAccount extends
|
|
12
|
+
import { Subject, SubjectType } from './subject.model.js';
|
|
13
|
+
let ServiceAccount = class ServiceAccount extends Subject {
|
|
14
|
+
displayName;
|
|
15
15
|
description;
|
|
16
16
|
/** Who owns this service account? If null, it is a tenant-wide service account. */
|
|
17
17
|
parent;
|
|
18
18
|
};
|
|
19
|
+
__decorate([
|
|
20
|
+
StringProperty(),
|
|
21
|
+
__metadata("design:type", String)
|
|
22
|
+
], ServiceAccount.prototype, "displayName", void 0);
|
|
19
23
|
__decorate([
|
|
20
24
|
StringProperty(),
|
|
21
25
|
__metadata("design:type", String)
|
|
@@ -26,6 +30,7 @@ __decorate([
|
|
|
26
30
|
__metadata("design:type", Object)
|
|
27
31
|
], ServiceAccount.prototype, "parent", void 0);
|
|
28
32
|
ServiceAccount = __decorate([
|
|
29
|
-
Table('service_account', { schema: 'authentication' })
|
|
33
|
+
Table('service_account', { schema: 'authentication' }),
|
|
34
|
+
ChildEntity(SubjectType.ServiceAccount)
|
|
30
35
|
], ServiceAccount);
|
|
31
36
|
export { ServiceAccount };
|
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
import { type EnumType } from '../../enumeration/enumeration.js';
|
|
2
2
|
import { TenantEntity } from '../../orm/entity.js';
|
|
3
|
-
import {
|
|
3
|
+
import type { Timestamp } from '../../orm/types.js';
|
|
4
4
|
export declare const SubjectType: {
|
|
5
5
|
readonly System: "system";
|
|
6
6
|
readonly User: "user";
|
|
7
7
|
readonly ServiceAccount: "service-account";
|
|
8
8
|
};
|
|
9
9
|
export type SubjectType = EnumType<typeof SubjectType>;
|
|
10
|
+
/**
|
|
11
|
+
* Status of a subject.
|
|
12
|
+
*/
|
|
13
|
+
export declare const SubjectStatus: {
|
|
14
|
+
/** Subject is active and can perform actions. */
|
|
15
|
+
readonly Active: "active";
|
|
16
|
+
/** Subject is inactive and cannot perform actions. Usually set by the user or a default state. */
|
|
17
|
+
readonly Inactive: "inactive";
|
|
18
|
+
/** Subject is suspended and cannot perform actions. Usually set by an administrator for security or policy reasons. */
|
|
19
|
+
readonly Suspended: "suspended";
|
|
20
|
+
/** Subject is pending approval from an administrator. */
|
|
21
|
+
readonly PendingApproval: "pending-approval";
|
|
22
|
+
/** Subject has been invited but has not yet accepted or completed setup. */
|
|
23
|
+
readonly Invited: "invited";
|
|
24
|
+
};
|
|
25
|
+
export type SubjectStatus = EnumType<typeof SubjectStatus>;
|
|
10
26
|
export declare class Subject extends TenantEntity {
|
|
11
27
|
type: SubjectType;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
userId: Uuid | null;
|
|
15
|
-
serviceAccountId: Uuid | null;
|
|
28
|
+
status: SubjectStatus;
|
|
29
|
+
lastActivityTimestamp: Timestamp | null;
|
|
16
30
|
}
|
|
@@ -9,53 +9,49 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
import { defineEnum } from '../../enumeration/enumeration.js';
|
|
11
11
|
import { TenantEntity } from '../../orm/entity.js';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { SystemAccount } from './system-account.model.js';
|
|
16
|
-
import { User } from './user.model.js';
|
|
12
|
+
import { Inheritance, Table, Unique } from '../../orm/index.js';
|
|
13
|
+
import { TimestampProperty } from '../../orm/schemas/timestamp.js';
|
|
14
|
+
import { Enumeration } from '../../schema/index.js';
|
|
17
15
|
export const SubjectType = defineEnum('SubjectType', {
|
|
18
16
|
System: 'system',
|
|
19
17
|
User: 'user',
|
|
20
18
|
ServiceAccount: 'service-account',
|
|
21
19
|
});
|
|
20
|
+
/**
|
|
21
|
+
* Status of a subject.
|
|
22
|
+
*/
|
|
23
|
+
export const SubjectStatus = defineEnum('SubjectStatus', {
|
|
24
|
+
/** Subject is active and can perform actions. */
|
|
25
|
+
Active: 'active',
|
|
26
|
+
/** Subject is inactive and cannot perform actions. Usually set by the user or a default state. */
|
|
27
|
+
Inactive: 'inactive',
|
|
28
|
+
/** Subject is suspended and cannot perform actions. Usually set by an administrator for security or policy reasons. */
|
|
29
|
+
Suspended: 'suspended',
|
|
30
|
+
/** Subject is pending approval from an administrator. */
|
|
31
|
+
PendingApproval: 'pending-approval',
|
|
32
|
+
/** Subject has been invited but has not yet accepted or completed setup. */
|
|
33
|
+
Invited: 'invited',
|
|
34
|
+
});
|
|
22
35
|
let Subject = class Subject extends TenantEntity {
|
|
23
36
|
type;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
userId;
|
|
27
|
-
serviceAccountId;
|
|
37
|
+
status;
|
|
38
|
+
lastActivityTimestamp;
|
|
28
39
|
};
|
|
29
40
|
__decorate([
|
|
30
41
|
Enumeration(SubjectType),
|
|
31
42
|
__metadata("design:type", String)
|
|
32
43
|
], Subject.prototype, "type", void 0);
|
|
33
44
|
__decorate([
|
|
34
|
-
|
|
45
|
+
Enumeration(SubjectStatus),
|
|
35
46
|
__metadata("design:type", String)
|
|
36
|
-
], Subject.prototype, "
|
|
37
|
-
__decorate([
|
|
38
|
-
TenantReference(() => SystemAccount),
|
|
39
|
-
UuidProperty({ nullable: true }),
|
|
40
|
-
__metadata("design:type", Object)
|
|
41
|
-
], Subject.prototype, "systemAccountId", void 0);
|
|
42
|
-
__decorate([
|
|
43
|
-
TenantReference(() => User),
|
|
44
|
-
UuidProperty({ nullable: true }),
|
|
45
|
-
__metadata("design:type", Object)
|
|
46
|
-
], Subject.prototype, "userId", void 0);
|
|
47
|
+
], Subject.prototype, "status", void 0);
|
|
47
48
|
__decorate([
|
|
48
|
-
|
|
49
|
-
UuidProperty({ nullable: true }),
|
|
49
|
+
TimestampProperty({ nullable: true }),
|
|
50
50
|
__metadata("design:type", Object)
|
|
51
|
-
], Subject.prototype, "
|
|
51
|
+
], Subject.prototype, "lastActivityTimestamp", void 0);
|
|
52
52
|
Subject = __decorate([
|
|
53
53
|
Table('subject', { schema: 'authentication' }),
|
|
54
|
+
Inheritance({ strategy: 'joined', discriminatorColumn: 'type' }),
|
|
54
55
|
Unique(['id']) // for external systems that might not support composite identities
|
|
55
|
-
,
|
|
56
|
-
Unique(['tenantId', 'systemAccountId']),
|
|
57
|
-
Unique(['tenantId', 'userId']),
|
|
58
|
-
Unique(['tenantId', 'serviceAccountId']),
|
|
59
|
-
Check('authentication_subject_reference_check', (table) => exclusiveNotNull(table.systemAccountId, table.userId, table.serviceAccountId))
|
|
60
56
|
], Subject);
|
|
61
57
|
export { Subject };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class SystemAccount extends
|
|
1
|
+
import { Subject } from './subject.model.js';
|
|
2
|
+
export declare class SystemAccount extends Subject {
|
|
3
3
|
/** Programmatic name: 'cleanup-task', 'ai-agent' */
|
|
4
4
|
identifier: string;
|
|
5
|
+
displayName: string;
|
|
5
6
|
}
|
|
@@ -7,19 +7,25 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
11
|
-
import { Table, Unique } from '../../orm/index.js';
|
|
10
|
+
import { ChildEntity, Table, Unique } from '../../orm/index.js';
|
|
12
11
|
import { StringProperty } from '../../schema/index.js';
|
|
13
|
-
|
|
12
|
+
import { Subject, SubjectType } from './subject.model.js';
|
|
13
|
+
let SystemAccount = class SystemAccount extends Subject {
|
|
14
14
|
/** Programmatic name: 'cleanup-task', 'ai-agent' */
|
|
15
15
|
identifier;
|
|
16
|
+
displayName;
|
|
16
17
|
};
|
|
17
18
|
__decorate([
|
|
18
|
-
Unique(),
|
|
19
19
|
StringProperty(),
|
|
20
20
|
__metadata("design:type", String)
|
|
21
21
|
], SystemAccount.prototype, "identifier", void 0);
|
|
22
|
+
__decorate([
|
|
23
|
+
StringProperty(),
|
|
24
|
+
__metadata("design:type", String)
|
|
25
|
+
], SystemAccount.prototype, "displayName", void 0);
|
|
22
26
|
SystemAccount = __decorate([
|
|
23
|
-
Table('system_account', { schema: 'authentication' })
|
|
27
|
+
Table('system_account', { schema: 'authentication' }),
|
|
28
|
+
ChildEntity(SubjectType.System),
|
|
29
|
+
Unique(['tenantId', 'identifier'])
|
|
24
30
|
], SystemAccount);
|
|
25
31
|
export { SystemAccount };
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const UserStatus: {
|
|
4
|
-
readonly Active: "active";
|
|
5
|
-
readonly Suspended: "suspended";
|
|
6
|
-
readonly PendingApproval: "pending-approval";
|
|
7
|
-
readonly Invited: "invited";
|
|
8
|
-
};
|
|
9
|
-
export type UserStatus = EnumType<typeof UserStatus>;
|
|
10
|
-
export declare class User extends TenantEntity {
|
|
11
|
-
status: UserStatus;
|
|
1
|
+
import { Subject } from './subject.model.js';
|
|
2
|
+
export declare class User extends Subject {
|
|
12
3
|
email: string;
|
|
13
4
|
firstName: string;
|
|
14
5
|
lastName: string;
|
|
@@ -7,27 +7,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { Table, Unique } from '../../orm/index.js';
|
|
13
|
-
import { Enumeration, StringProperty } from '../../schema/index.js';
|
|
10
|
+
import { ChildEntity, Table, Unique } from '../../orm/index.js';
|
|
11
|
+
import { StringProperty } from '../../schema/index.js';
|
|
14
12
|
import { mailPattern } from '../../utils/patterns.js';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Suspended: 'suspended',
|
|
18
|
-
PendingApproval: 'pending-approval',
|
|
19
|
-
Invited: 'invited',
|
|
20
|
-
});
|
|
21
|
-
let User = class User extends TenantEntity {
|
|
22
|
-
status;
|
|
13
|
+
import { Subject, SubjectType } from './subject.model.js';
|
|
14
|
+
let User = class User extends Subject {
|
|
23
15
|
email;
|
|
24
16
|
firstName;
|
|
25
17
|
lastName;
|
|
26
18
|
};
|
|
27
|
-
__decorate([
|
|
28
|
-
Enumeration(UserStatus),
|
|
29
|
-
__metadata("design:type", String)
|
|
30
|
-
], User.prototype, "status", void 0);
|
|
31
19
|
__decorate([
|
|
32
20
|
StringProperty({ pattern: mailPattern }),
|
|
33
21
|
__metadata("design:type", String)
|
|
@@ -42,6 +30,7 @@ __decorate([
|
|
|
42
30
|
], User.prototype, "lastName", void 0);
|
|
43
31
|
User = __decorate([
|
|
44
32
|
Table('user', { schema: 'authentication' }),
|
|
33
|
+
ChildEntity(SubjectType.User),
|
|
45
34
|
Unique(['tenantId', 'email'])
|
|
46
35
|
], User);
|
|
47
36
|
export { User };
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { ApiRequestData } from '../../api/index.js';
|
|
2
2
|
import { ApiRequestTokenProvider } from '../../api/server/api-request-token.provider.js';
|
|
3
|
-
import { AuthenticationService } from './authentication.service.js';
|
|
4
3
|
/**
|
|
5
4
|
* Provides the info for an API request from the authorization header.
|
|
6
5
|
*/
|
|
7
6
|
export declare class AuthenticationApiRequestTokenProvider extends ApiRequestTokenProvider {
|
|
8
7
|
private readonly authenticationService;
|
|
9
|
-
constructor(authenticationService: AuthenticationService);
|
|
10
8
|
tryGetToken<T>(data: ApiRequestData): Promise<T | null>;
|
|
11
9
|
}
|
|
@@ -4,11 +4,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
7
|
import { ApiRequestTokenProvider } from '../../api/server/api-request-token.provider.js';
|
|
11
|
-
import { Singleton } from '../../injector/
|
|
8
|
+
import { inject, Singleton } from '../../injector/index.js';
|
|
12
9
|
import { isUndefined } from '../../utils/type-guards.js';
|
|
13
10
|
import { AuthenticationService } from './authentication.service.js';
|
|
14
11
|
import { tryGetAuthorizationTokenStringFromRequest } from './helper.js';
|
|
@@ -16,11 +13,7 @@ import { tryGetAuthorizationTokenStringFromRequest } from './helper.js';
|
|
|
16
13
|
* Provides the info for an API request from the authorization header.
|
|
17
14
|
*/
|
|
18
15
|
let AuthenticationApiRequestTokenProvider = class AuthenticationApiRequestTokenProvider extends ApiRequestTokenProvider {
|
|
19
|
-
authenticationService;
|
|
20
|
-
constructor(authenticationService) {
|
|
21
|
-
super();
|
|
22
|
-
this.authenticationService = authenticationService;
|
|
23
|
-
}
|
|
16
|
+
authenticationService = inject(AuthenticationService);
|
|
24
17
|
async tryGetToken(data) {
|
|
25
18
|
const tokenString = tryGetAuthorizationTokenStringFromRequest(data.request);
|
|
26
19
|
if (isUndefined(tokenString)) {
|
|
@@ -30,7 +23,6 @@ let AuthenticationApiRequestTokenProvider = class AuthenticationApiRequestTokenP
|
|
|
30
23
|
}
|
|
31
24
|
};
|
|
32
25
|
AuthenticationApiRequestTokenProvider = __decorate([
|
|
33
|
-
Singleton()
|
|
34
|
-
__metadata("design:paramtypes", [AuthenticationService])
|
|
26
|
+
Singleton()
|
|
35
27
|
], AuthenticationApiRequestTokenProvider);
|
|
36
28
|
export { AuthenticationApiRequestTokenProvider };
|
|
@@ -13,8 +13,7 @@ import { AuthenticationService } from './authentication.service.js';
|
|
|
13
13
|
* @template AdditionalInitSecretResetData Type of additional secret reset data
|
|
14
14
|
*/
|
|
15
15
|
export declare class AuthenticationApiController<AdditionalTokenPayload extends Record, AuthenticationData, AdditionalInitSecretResetData = void> implements ApiController<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>> {
|
|
16
|
-
readonly authenticationService: AuthenticationService<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>;
|
|
17
|
-
constructor(authenticationService: AuthenticationService<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>);
|
|
16
|
+
protected readonly authenticationService: AuthenticationService<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>;
|
|
18
17
|
/**
|
|
19
18
|
* Get a token for a subject and secret.
|
|
20
19
|
* @param parameters The parameters for the request.
|
|
@@ -4,11 +4,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
7
|
import { apiController } from '../../api/server/index.js';
|
|
11
8
|
import { HttpServerResponse } from '../../http/server/index.js';
|
|
9
|
+
import { inject } from '../../injector/index.js';
|
|
12
10
|
import { currentTimestampSeconds } from '../../utils/date-time.js';
|
|
13
11
|
import { assertDefinedPass, isDefined } from '../../utils/type-guards.js';
|
|
14
12
|
import { authenticationApiDefinition, getAuthenticationApiDefinition } from '../authentication.api.js';
|
|
@@ -24,10 +22,7 @@ const deleteCookie = { value: '', ...cookieBaseOptions, maxAge: -1 };
|
|
|
24
22
|
* @template AdditionalInitSecretResetData Type of additional secret reset data
|
|
25
23
|
*/
|
|
26
24
|
let AuthenticationApiController = class AuthenticationApiController {
|
|
27
|
-
authenticationService;
|
|
28
|
-
constructor(authenticationService) {
|
|
29
|
-
this.authenticationService = authenticationService;
|
|
30
|
-
}
|
|
25
|
+
authenticationService = inject((AuthenticationService));
|
|
31
26
|
/**
|
|
32
27
|
* Get a token for a subject and secret.
|
|
33
28
|
* @param parameters The parameters for the request.
|
|
@@ -146,6 +141,10 @@ let AuthenticationApiController = class AuthenticationApiController {
|
|
|
146
141
|
getTokenResponse({ token, jsonToken, refreshToken, omitImpersonatorRefreshToken, impersonatorRefreshToken, impersonatorRefreshTokenExpiration }) {
|
|
147
142
|
const result = jsonToken.payload;
|
|
148
143
|
const options = {
|
|
144
|
+
headers: {
|
|
145
|
+
'X-Authorization': `Bearer ${token}`,
|
|
146
|
+
'X-Refresh-Token': `Bearer ${refreshToken}`,
|
|
147
|
+
},
|
|
149
148
|
cookies: {
|
|
150
149
|
authorization: {
|
|
151
150
|
value: `Bearer ${token}`,
|
|
@@ -163,6 +162,7 @@ let AuthenticationApiController = class AuthenticationApiController {
|
|
|
163
162
|
},
|
|
164
163
|
};
|
|
165
164
|
if (isDefined(impersonatorRefreshToken)) {
|
|
165
|
+
options.headers['X-Impersonator-Refresh-Token'] = `Bearer ${impersonatorRefreshToken}`;
|
|
166
166
|
options.cookies['impersonatorRefreshToken'] = {
|
|
167
167
|
value: `Bearer ${impersonatorRefreshToken}`,
|
|
168
168
|
...cookieBaseOptions,
|
|
@@ -176,8 +176,7 @@ let AuthenticationApiController = class AuthenticationApiController {
|
|
|
176
176
|
}
|
|
177
177
|
};
|
|
178
178
|
AuthenticationApiController = __decorate([
|
|
179
|
-
apiController(authenticationApiDefinition)
|
|
180
|
-
__metadata("design:paramtypes", [AuthenticationService])
|
|
179
|
+
apiController(authenticationApiDefinition)
|
|
181
180
|
], AuthenticationApiController);
|
|
182
181
|
export { AuthenticationApiController };
|
|
183
182
|
/**
|