@tstdl/base 0.92.167 → 0.93.0
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/application/application.d.ts +12 -18
- package/application/application.js +48 -69
- package/application/index.d.ts +1 -5
- package/application/index.js +1 -5
- package/application/providers.d.ts +10 -0
- package/application/providers.js +54 -0
- package/audit/audit.model.d.ts +15 -0
- package/audit/audit.model.js +73 -0
- package/audit/auditor.d.ts +42 -0
- package/audit/auditor.js +111 -0
- package/audit/index.d.ts +3 -0
- package/audit/index.js +3 -0
- package/audit/types.d.ts +22 -0
- package/audit/types.js +19 -0
- package/authentication/client/authentication.service.d.ts +1 -3
- package/authentication/client/authentication.service.js +4 -5
- package/browser/browser-context-controller.d.ts +2 -4
- package/browser/browser-context-controller.js +5 -6
- package/browser/browser-controller.d.ts +2 -4
- package/browser/browser-controller.js +3 -4
- package/browser/browser.service.d.ts +1 -3
- package/browser/browser.service.js +1 -2
- package/browser/page-controller.d.ts +2 -4
- package/browser/page-controller.js +7 -8
- package/browser/utils.js +3 -3
- package/cancellation/token.d.ts +104 -41
- package/cancellation/token.js +125 -54
- package/core.d.ts +1 -13
- package/core.js +1 -46
- package/disposable/disposable.d.ts +0 -8
- package/disposable/disposable.js +1 -3
- package/disposable/index.d.ts +0 -6
- package/disposable/index.js +0 -6
- package/disposable/using.d.ts +0 -1
- package/disposable/using.js +2 -3
- package/distributed-loop/distributed-loop.js +2 -2
- package/errors/utils.js +4 -1
- package/examples/api/authentication.js +11 -5
- package/examples/api/basic-overview.js +17 -12
- package/examples/api/custom-authentication.js +13 -7
- package/examples/api/streaming.js +15 -12
- package/examples/browser/basic.js +6 -3
- package/examples/document-management/main.js +6 -3
- package/examples/http/client.js +7 -3
- package/examples/mail/basic.js +9 -7
- package/examples/pdf/basic.js +8 -6
- package/examples/template/basic.js +7 -5
- package/http/client/http-client-request.d.ts +1 -2
- package/http/client/http-client-request.js +1 -2
- package/http/server/http-server.d.ts +1 -3
- package/http/server/http-server.js +0 -1
- package/http/server/node/node-http-server.d.ts +1 -2
- package/http/server/node/node-http-server.js +1 -2
- package/import.js +1 -1
- package/injector/injector.d.ts +1 -1
- package/injector/types.d.ts +3 -4
- package/lock/lock.d.ts +40 -21
- package/lock/lock.js +74 -1
- package/lock/postgres/drizzle/0000_busy_tattoo.sql +7 -0
- package/lock/postgres/drizzle/meta/0000_snapshot.json +65 -0
- package/lock/postgres/drizzle/meta/_journal.json +13 -0
- package/lock/postgres/drizzle.config.js +11 -0
- package/lock/postgres/index.d.ts +2 -0
- package/lock/postgres/index.js +2 -0
- package/lock/postgres/lock.d.ts +14 -0
- package/lock/postgres/lock.js +127 -0
- package/lock/postgres/models/index.d.ts +2 -0
- package/lock/postgres/models/index.js +2 -0
- package/lock/postgres/models/lock.model.d.ts +7 -0
- package/{examples/orm/user.model.js → lock/postgres/models/lock.model.js} +22 -30
- package/lock/postgres/models/schemas.d.ts +3 -0
- package/lock/postgres/models/schemas.js +4 -0
- package/lock/postgres/module.d.ts +6 -0
- package/lock/postgres/module.js +26 -0
- package/lock/postgres/provider.d.ts +6 -0
- package/lock/postgres/provider.js +29 -0
- package/lock/provider.d.ts +12 -2
- package/lock/provider.js +24 -1
- package/lock/web/web-lock.d.ts +4 -3
- package/lock/web/web-lock.js +49 -42
- package/lock/web/web-lock.provider.d.ts +0 -3
- package/lock/web/web-lock.provider.js +5 -22
- package/logger/formatter.d.ts +13 -0
- package/logger/formatter.js +3 -0
- package/logger/formatters/index.d.ts +2 -0
- package/logger/formatters/index.js +2 -0
- package/logger/formatters/json.d.ts +5 -0
- package/logger/formatters/json.js +33 -0
- package/logger/formatters/pretty-print.d.ts +5 -0
- package/logger/formatters/pretty-print.js +55 -0
- package/logger/index.d.ts +5 -2
- package/logger/index.js +5 -2
- package/logger/level.d.ts +10 -8
- package/logger/level.js +9 -9
- package/logger/logger.d.ts +21 -30
- package/logger/logger.js +98 -26
- package/logger/manager.d.ts +20 -0
- package/logger/manager.js +86 -0
- package/logger/tokens.d.ts +1 -1
- package/logger/tokens.js +1 -1
- package/logger/transport.d.ts +14 -0
- package/logger/transport.js +16 -0
- package/logger/transports/console.d.ts +14 -0
- package/logger/transports/console.js +36 -0
- package/logger/transports/index.d.ts +1 -0
- package/logger/transports/index.js +1 -0
- package/mail/clients/nodemailer.mail-client.d.ts +0 -1
- package/mail/clients/nodemailer.mail-client.js +9 -7
- package/message-bus/local/local-message-bus.js +2 -2
- package/message-bus/message-bus-base.d.ts +2 -3
- package/message-bus/message-bus-base.js +5 -6
- package/message-bus/message-bus.d.ts +1 -2
- package/message-bus/message-bus.js +1 -2
- package/module/index.d.ts +0 -2
- package/module/index.js +0 -2
- package/module/module.d.ts +17 -18
- package/module/module.js +47 -12
- package/module/modules/function.module.d.ts +6 -6
- package/module/modules/function.module.js +25 -9
- package/module/modules/web-server.module.d.ts +2 -10
- package/module/modules/web-server.module.js +3 -11
- package/openid-connect/index.d.ts +0 -2
- package/openid-connect/index.js +0 -2
- package/openid-connect/oidc-state.model.d.ts +4 -5
- package/openid-connect/oidc-state.model.js +51 -1
- package/openid-connect/oidc.service-model.d.ts +1 -1
- package/openid-connect/oidc.service.d.ts +2 -6
- package/openid-connect/oidc.service.js +24 -37
- package/orm/decorators.d.ts +10 -1
- package/orm/decorators.js +8 -0
- package/orm/server/repository.d.ts +3 -1
- package/orm/server/repository.js +32 -3
- package/package.json +19 -29
- package/pdf/pdf.service.js +9 -9
- package/pool/pool.d.ts +1 -3
- package/pool/pool.js +3 -4
- package/queue/postgres/job.model.d.ts +1 -2
- package/queue/postgres/job.model.js +1 -2
- package/queue/postgres/module.js +1 -1
- package/threading/thread-pool.d.ts +1 -3
- package/threading/thread-pool.js +7 -8
- package/utils/format-error.d.ts +7 -0
- package/utils/format-error.js +59 -17
- package/utils/function/memoize.d.ts +22 -7
- package/utils/function/memoize.js +82 -23
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/object/dereference.d.ts +51 -19
- package/utils/object/dereference.js +52 -43
- package/utils/timing.js +2 -2
- package/utils/try-chain.d.ts +22 -0
- package/utils/try-chain.js +46 -0
- package/database/entity-repository.d.ts +0 -50
- package/database/entity-repository.js +0 -3
- package/database/entity.d.ts +0 -7
- package/database/entity.js +0 -1
- package/database/id.d.ts +0 -1
- package/database/id.js +0 -9
- package/database/index.d.ts +0 -11
- package/database/index.js +0 -11
- package/database/module.d.ts +0 -8
- package/database/module.js +0 -11
- package/database/mongo/classes.d.ts +0 -21
- package/database/mongo/classes.js +0 -26
- package/database/mongo/index.d.ts +0 -15
- package/database/mongo/index.js +0 -15
- package/database/mongo/model/document.d.ts +0 -29
- package/database/mongo/model/document.js +0 -63
- package/database/mongo/model/index.d.ts +0 -1
- package/database/mongo/model/index.js +0 -1
- package/database/mongo/module.d.ts +0 -8
- package/database/mongo/module.js +0 -68
- package/database/mongo/mongo-base.repository.d.ts +0 -103
- package/database/mongo/mongo-base.repository.js +0 -263
- package/database/mongo/mongo-bulk.d.ts +0 -35
- package/database/mongo/mongo-bulk.js +0 -90
- package/database/mongo/mongo-entity-repository.d.ts +0 -98
- package/database/mongo/mongo-entity-repository.js +0 -278
- package/database/mongo/operations.d.ts +0 -10
- package/database/mongo/operations.js +0 -54
- package/database/mongo/query-converter.d.ts +0 -6
- package/database/mongo/query-converter.js +0 -83
- package/database/mongo/simple-entity-repository.d.ts +0 -7
- package/database/mongo/simple-entity-repository.js +0 -6
- package/database/mongo/types.d.ts +0 -50
- package/database/mongo/types.js +0 -3
- package/database/query.d.ts +0 -121
- package/database/query.js +0 -7
- package/database/utils.d.ts +0 -2
- package/database/utils.js +0 -3
- package/disposable/async-disposer.d.ts +0 -35
- package/disposable/async-disposer.js +0 -125
- package/examples/orm/drizzle.config.js +0 -6
- package/examples/orm/schemas.d.ts +0 -3
- package/examples/orm/schemas.js +0 -4
- package/examples/orm/test.d.ts +0 -1
- package/examples/orm/test.js +0 -11
- package/examples/orm/user.model.d.ts +0 -13
- package/key-value-store/mongo/index.d.ts +0 -6
- package/key-value-store/mongo/index.js +0 -6
- package/key-value-store/mongo/module.d.ts +0 -8
- package/key-value-store/mongo/module.js +0 -18
- package/key-value-store/mongo/mongo-key-value-store.provider.d.ts +0 -8
- package/key-value-store/mongo/mongo-key-value-store.provider.js +0 -26
- package/key-value-store/mongo/mongo-key-value.model.d.ts +0 -7
- package/key-value-store/mongo/mongo-key-value.model.js +0 -1
- package/key-value-store/mongo/mongo-key-value.repository.d.ts +0 -10
- package/key-value-store/mongo/mongo-key-value.repository.js +0 -31
- package/key-value-store/mongo/mongo-key-value.store.d.ts +0 -15
- package/key-value-store/mongo/mongo-key-value.store.js +0 -82
- package/key-value-store/mongo/tokens.d.ts +0 -3
- package/key-value-store/mongo/tokens.js +0 -2
- package/lock/mongo/index.d.ts +0 -5
- package/lock/mongo/index.js +0 -5
- package/lock/mongo/lock.d.ts +0 -14
- package/lock/mongo/lock.js +0 -125
- package/lock/mongo/model.d.ts +0 -6
- package/lock/mongo/model.js +0 -1
- package/lock/mongo/module.d.ts +0 -12
- package/lock/mongo/module.js +0 -20
- package/lock/mongo/mongo-lock-repository.d.ts +0 -14
- package/lock/mongo/mongo-lock-repository.js +0 -67
- package/lock/mongo/provider.d.ts +0 -8
- package/lock/mongo/provider.js +0 -36
- package/logger/console/index.d.ts +0 -1
- package/logger/console/index.js +0 -1
- package/logger/console/logger.d.ts +0 -11
- package/logger/console/logger.js +0 -64
- package/logger/noop/index.d.ts +0 -1
- package/logger/noop/index.js +0 -1
- package/logger/noop/logger.d.ts +0 -9
- package/logger/noop/logger.js +0 -21
- package/migration/index.d.ts +0 -9
- package/migration/index.js +0 -9
- package/migration/migration-state-repository.d.ts +0 -4
- package/migration/migration-state-repository.js +0 -3
- package/migration/migration-state.d.ts +0 -6
- package/migration/migration-state.js +0 -1
- package/migration/migrator.d.ts +0 -23
- package/migration/migrator.js +0 -76
- package/migration/mongo/index.d.ts +0 -2
- package/migration/mongo/index.js +0 -2
- package/migration/mongo/migration-state-repository.d.ts +0 -11
- package/migration/mongo/migration-state-repository.js +0 -32
- package/migration/mongo/module.d.ts +0 -12
- package/migration/mongo/module.js +0 -17
- package/module/module-base.d.ts +0 -18
- package/module/module-base.js +0 -40
- package/module/module-metric-reporter.d.ts +0 -29
- package/module/module-metric-reporter.js +0 -62
- package/openid-connect/mongo-oidc-state.repository.d.ts +0 -21
- package/openid-connect/mongo-oidc-state.repository.js +0 -52
- package/openid-connect/oidc-state.repository.d.ts +0 -4
- package/openid-connect/oidc-state.repository.js +0 -3
- package/process-shutdown.d.ts +0 -9
- package/process-shutdown.js +0 -65
- package/queue/mongo/index.d.ts +0 -4
- package/queue/mongo/index.js +0 -4
- package/queue/mongo/job.d.ts +0 -12
- package/queue/mongo/job.js +0 -1
- package/queue/mongo/mongo-job.repository.d.ts +0 -13
- package/queue/mongo/mongo-job.repository.js +0 -54
- package/queue/mongo/queue.d.ts +0 -38
- package/queue/mongo/queue.js +0 -266
- package/queue/mongo/queue.provider.d.ts +0 -18
- package/queue/mongo/queue.provider.js +0 -38
- package/search-index/elastic/config.d.ts +0 -8
- package/search-index/elastic/config.js +0 -26
- package/search-index/elastic/index.d.ts +0 -8
- package/search-index/elastic/index.js +0 -8
- package/search-index/elastic/keyword-rewriter.d.ts +0 -8
- package/search-index/elastic/keyword-rewriter.js +0 -18
- package/search-index/elastic/model/elastic-query.d.ts +0 -16
- package/search-index/elastic/model/elastic-query.js +0 -1
- package/search-index/elastic/model/index-mapping.d.ts +0 -26
- package/search-index/elastic/model/index-mapping.js +0 -4
- package/search-index/elastic/model/index.d.ts +0 -3
- package/search-index/elastic/model/index.js +0 -3
- package/search-index/elastic/model/sort.d.ts +0 -8
- package/search-index/elastic/model/sort.js +0 -1
- package/search-index/elastic/module.d.ts +0 -10
- package/search-index/elastic/module.js +0 -49
- package/search-index/elastic/query-builder/boolean-query-builder.d.ts +0 -11
- package/search-index/elastic/query-builder/boolean-query-builder.js +0 -52
- package/search-index/elastic/query-builder/index.d.ts +0 -1
- package/search-index/elastic/query-builder/index.js +0 -1
- package/search-index/elastic/query-converter.d.ts +0 -9
- package/search-index/elastic/query-converter.js +0 -183
- package/search-index/elastic/search-index.d.ts +0 -30
- package/search-index/elastic/search-index.js +0 -144
- package/search-index/elastic/sort-converter.d.ts +0 -4
- package/search-index/elastic/sort-converter.js +0 -14
- package/search-index/elastic/types.d.ts +0 -5
- package/search-index/elastic/types.js +0 -1
- package/search-index/error.d.ts +0 -10
- package/search-index/error.js +0 -14
- package/search-index/index.d.ts +0 -3
- package/search-index/index.js +0 -3
- package/search-index/memory/index.d.ts +0 -1
- package/search-index/memory/index.js +0 -1
- package/search-index/memory/memory-search-index.d.ts +0 -19
- package/search-index/memory/memory-search-index.js +0 -144
- package/search-index/search-index.d.ts +0 -46
- package/search-index/search-index.js +0 -31
- package/search-index/search-result.d.ts +0 -12
- package/search-index/search-result.js +0 -1
- package/theme/adapters/css-adapter.d.ts +0 -5
- package/theme/adapters/css-adapter.js +0 -29
- package/theme/adapters/index.d.ts +0 -2
- package/theme/adapters/index.js +0 -2
- package/theme/adapters/tailwind-adapter.d.ts +0 -18
- package/theme/adapters/tailwind-adapter.js +0 -32
- package/theme/index.d.ts +0 -1
- package/theme/index.js +0 -1
- package/theme/theme-service.d.ts +0 -43
- package/theme/theme-service.js +0 -128
- /package/{examples/orm → lock/postgres}/drizzle.config.d.ts +0 -0
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CancellationSignal } from '../cancellation/token.js';
|
|
2
|
+
import { type ProvidersItem } from '../injector/injector.js';
|
|
2
3
|
import type { Resolvable, resolveArgumentType } from '../injector/interfaces.js';
|
|
3
4
|
import type { LoggerArgument } from '../logger/index.js';
|
|
4
|
-
import
|
|
5
|
-
import type { FunctionModuleFunction } from '../module/modules/function.module.js';
|
|
5
|
+
import { Module } from '../module/index.js';
|
|
6
6
|
import type { OneOrMany, Type } from '../types/index.js';
|
|
7
|
-
export type
|
|
8
|
-
export type
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export type InitializerFn = () => void | Promise<void>;
|
|
8
|
+
export type DestructorFn = () => void | Promise<void>;
|
|
9
|
+
export declare const APPLICATION_MODULE: import("../injector/token.js").InjectionToken<Module, never>;
|
|
10
|
+
export declare const APPLICATION_INITIALIZER: import("../injector/token.js").InjectionToken<InitializerFn, never>;
|
|
11
|
+
export declare const APPLICATION_DESTRUCTOR: import("../injector/token.js").InjectionToken<DestructorFn, never>;
|
|
11
12
|
export type ApplicationArgument = LoggerArgument;
|
|
12
13
|
export declare class Application implements Resolvable<ApplicationArgument> {
|
|
13
14
|
#private;
|
|
14
|
-
static _instance: Application | undefined;
|
|
15
|
-
private static get instance();
|
|
16
15
|
readonly [resolveArgumentType]: string;
|
|
16
|
+
static create(name: string, providers?: OneOrMany<ProvidersItem>[]): Application;
|
|
17
|
+
static run(name: string, providers?: OneOrMany<ProvidersItem>[]): Application;
|
|
17
18
|
get shutdownSignal(): CancellationSignal;
|
|
18
|
-
static get shutdownSignal(): CancellationSignal;
|
|
19
|
-
static registerModule(moduleType: Type<Module>): void;
|
|
20
|
-
static registerModuleFunction(fn: FunctionModuleFunction): void;
|
|
21
|
-
static run(...functionsAndModules: [RunOptions | OneOrMany<FunctionModuleFunction | Type<Module>>, ...OneOrMany<FunctionModuleFunction | Type<Module>>[]]): void;
|
|
22
|
-
static waitForShutdown(): Promise<void>;
|
|
23
|
-
static shutdown(): Promise<void>;
|
|
24
|
-
static requestShutdown(): void;
|
|
25
19
|
registerModule(moduleType: Module | Type<Module>): void;
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
run(): void;
|
|
21
|
+
runAndWait(): Promise<void>;
|
|
28
22
|
shutdown(): Promise<void>;
|
|
29
23
|
requestShutdown(): void;
|
|
30
24
|
waitForShutdown(): Promise<void>;
|
|
@@ -5,75 +5,54 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
var Application_1;
|
|
8
|
-
import {
|
|
8
|
+
import { CancellationSignal, CancellationToken } from '../cancellation/token.js';
|
|
9
9
|
import { Singleton } from '../injector/decorators.js';
|
|
10
|
-
import { inject, injectArgument, runInInjectionContext } from '../injector/inject.js';
|
|
10
|
+
import { inject, injectAll, injectArgument, runInInjectionContext } from '../injector/inject.js';
|
|
11
11
|
import { Injector } from '../injector/injector.js';
|
|
12
|
+
import { injectionToken } from '../injector/token.js';
|
|
12
13
|
import { Logger } from '../logger/index.js';
|
|
13
|
-
import {
|
|
14
|
-
import { ModuleState } from '../module/module.js';
|
|
15
|
-
import { FunctionModule } from '../module/modules/function.module.js';
|
|
16
|
-
import { getShutdownSignal, getShutdownToken } from '../process-shutdown.js';
|
|
14
|
+
import { Module, ModuleState } from '../module/index.js';
|
|
17
15
|
import { DeferredPromise } from '../promise/deferred-promise.js';
|
|
18
|
-
import { toArray } from '../utils/array/array.js';
|
|
19
16
|
import { mapAsync } from '../utils/async-iterable-helpers/map.js';
|
|
20
17
|
import { toArrayAsync } from '../utils/async-iterable-helpers/to-array.js';
|
|
21
|
-
import { isDefined, isFunction
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (isUndefined(this._instance)) {
|
|
27
|
-
this._instance = getGlobalInjector().resolve(Application_1, 'App');
|
|
28
|
-
// @ts-expect-error readonly
|
|
29
|
-
this._instance.#shutdownToken = getShutdownToken();
|
|
30
|
-
}
|
|
31
|
-
return this._instance;
|
|
32
|
-
}
|
|
18
|
+
import { isDefined, isFunction } from '../utils/type-guards.js';
|
|
19
|
+
export const APPLICATION_MODULE = injectionToken('ApplicationModule');
|
|
20
|
+
export const APPLICATION_INITIALIZER = injectionToken('ApplicationInitializer');
|
|
21
|
+
export const APPLICATION_DESTRUCTOR = injectionToken('ApplicationDestructor');
|
|
22
|
+
let Application = Application_1 = class Application {
|
|
33
23
|
#name = injectArgument(this);
|
|
34
|
-
#injector = inject(Injector)
|
|
35
|
-
#logger =
|
|
36
|
-
#moduleTypesAndInstances = new Set();
|
|
24
|
+
#injector = inject(Injector);
|
|
25
|
+
#logger = inject(Logger, this.#name);
|
|
26
|
+
#moduleTypesAndInstances = new Set(injectAll(APPLICATION_MODULE, undefined, { optional: true }));
|
|
37
27
|
#shutdownPromise = new DeferredPromise();
|
|
38
|
-
#shutdownToken =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
static registerModule(moduleType) {
|
|
46
|
-
Application_1.instance.registerModule(moduleType);
|
|
47
|
-
}
|
|
48
|
-
static registerModuleFunction(fn) {
|
|
49
|
-
Application_1.instance.registerModuleFunction(fn);
|
|
50
|
-
}
|
|
51
|
-
static run(...functionsAndModules) {
|
|
52
|
-
Application_1.instance.run(...functionsAndModules);
|
|
53
|
-
}
|
|
54
|
-
static async waitForShutdown() {
|
|
55
|
-
return Application_1.instance.waitForShutdown();
|
|
28
|
+
#shutdownToken = inject(CancellationSignal, undefined, { optional: true })?.createChild() ?? new CancellationToken();
|
|
29
|
+
static create(name, providers = []) {
|
|
30
|
+
const injector = new Injector(`${name}Injector`);
|
|
31
|
+
for (const providersItem of providers.flat()) {
|
|
32
|
+
injector.register(providersItem.provide, providersItem, { multi: providersItem.multi });
|
|
33
|
+
}
|
|
34
|
+
return injector.resolve(Application_1, name);
|
|
56
35
|
}
|
|
57
|
-
static
|
|
58
|
-
|
|
36
|
+
static run(name, providers = []) {
|
|
37
|
+
const app = Application_1.create(name, providers);
|
|
38
|
+
app.run();
|
|
39
|
+
return app;
|
|
59
40
|
}
|
|
60
|
-
|
|
61
|
-
|
|
41
|
+
get shutdownSignal() {
|
|
42
|
+
return this.#shutdownToken.signal;
|
|
62
43
|
}
|
|
63
44
|
registerModule(moduleType) {
|
|
64
45
|
this.#moduleTypesAndInstances.add(moduleType);
|
|
65
46
|
}
|
|
66
|
-
|
|
67
|
-
const module = new FunctionModule(fn);
|
|
68
|
-
this.registerModule(module);
|
|
69
|
-
}
|
|
70
|
-
run(...optionsFunctionsAndModules) {
|
|
47
|
+
run() {
|
|
71
48
|
if (this.#shutdownToken.isSet) {
|
|
72
49
|
throw new Error('Application was shut down.');
|
|
73
50
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
51
|
+
void this._run();
|
|
52
|
+
}
|
|
53
|
+
async runAndWait() {
|
|
54
|
+
this.run();
|
|
55
|
+
await this.waitForShutdown();
|
|
77
56
|
}
|
|
78
57
|
async shutdown() {
|
|
79
58
|
this.requestShutdown();
|
|
@@ -86,28 +65,19 @@ let Application = class Application {
|
|
|
86
65
|
this.#shutdownToken.set();
|
|
87
66
|
}
|
|
88
67
|
async waitForShutdown() {
|
|
89
|
-
|
|
68
|
+
await this.#shutdownPromise;
|
|
90
69
|
}
|
|
91
|
-
async _run(
|
|
70
|
+
async _run() {
|
|
92
71
|
let modules;
|
|
93
72
|
try {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
this.registerModuleFunction(fnOrModule);
|
|
100
|
-
}
|
|
73
|
+
const initializers = await this.#injector.resolveAllAsync(APPLICATION_INITIALIZER, undefined, { optional: true });
|
|
74
|
+
for (const initializer of initializers) {
|
|
75
|
+
await runInInjectionContext(this.#injector, initializer);
|
|
101
76
|
}
|
|
102
|
-
|
|
103
|
-
for (const fn of toArray(options.bootstrap)) {
|
|
104
|
-
await runInInjectionContext(this.#injector, fn);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
modules = await toArrayAsync(mapAsync(this.#moduleTypesAndInstances, async (instanceOrType) => (isFunction(instanceOrType) ? this.#injector.resolveAsync(instanceOrType) : instanceOrType)));
|
|
77
|
+
modules = await toArrayAsync(mapAsync(this.#moduleTypesAndInstances, async (instanceOrType) => (isFunction(instanceOrType) ? await this.#injector.resolveAsync(instanceOrType) : instanceOrType)));
|
|
108
78
|
await Promise.race([
|
|
109
79
|
this.runModules(modules),
|
|
110
|
-
this.shutdownSignal
|
|
80
|
+
this.shutdownSignal,
|
|
111
81
|
]);
|
|
112
82
|
}
|
|
113
83
|
catch (error) {
|
|
@@ -119,6 +89,15 @@ let Application = class Application {
|
|
|
119
89
|
if (isDefined(modules)) {
|
|
120
90
|
await this.stopModules(modules);
|
|
121
91
|
}
|
|
92
|
+
const destructors = await this.#injector.resolveAllAsync(APPLICATION_DESTRUCTOR, undefined, { optional: true });
|
|
93
|
+
for (const destructor of destructors) {
|
|
94
|
+
try {
|
|
95
|
+
await runInInjectionContext(this.#injector, destructor);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
this.#logger.error(error, { message: 'An error occurred during application destruction.' });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
122
101
|
await this.#injector.dispose();
|
|
123
102
|
this.#logger.info('Bye');
|
|
124
103
|
}
|
|
@@ -128,7 +107,7 @@ let Application = class Application {
|
|
|
128
107
|
const promises = modules.map(async (module) => {
|
|
129
108
|
try {
|
|
130
109
|
this.#logger.info(`Starting module ${module.name}`);
|
|
131
|
-
await runInInjectionContext(this.#injector, async () => module.run());
|
|
110
|
+
await runInInjectionContext(this.#injector, async () => await module.run());
|
|
132
111
|
this.#logger.info(`Module ${module.name} stopped.`);
|
|
133
112
|
}
|
|
134
113
|
catch (error) {
|
package/application/index.d.ts
CHANGED
package/application/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CancellationSignal } from '../cancellation/index.js';
|
|
2
|
+
import { type ProvidersItem } from '../injector/index.js';
|
|
3
|
+
import { Module, type FunctionModuleFunction } from '../module/index.js';
|
|
4
|
+
import type { OneOrMany, Type } from '../types/index.js';
|
|
5
|
+
import { type DestructorFn, type InitializerFn } from './application.js';
|
|
6
|
+
export declare function provideModules(...functionsAndModules: OneOrMany<FunctionModuleFunction | Type<Module>>[]): ProvidersItem[];
|
|
7
|
+
export declare function provideInitializer(fn: InitializerFn): ProvidersItem;
|
|
8
|
+
export declare function provideDestructor(fn: DestructorFn): ProvidersItem;
|
|
9
|
+
export declare function provideShutdownSignal(signal: CancellationSignal): ProvidersItem;
|
|
10
|
+
export declare function provideSignalHandler(): ProvidersItem;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { CancellationSignal } from '../cancellation/index.js';
|
|
2
|
+
import { inject } from '../injector/index.js';
|
|
3
|
+
import { Logger } from '../logger/index.js';
|
|
4
|
+
import { FunctionModule, Module } from '../module/index.js';
|
|
5
|
+
import { isFunction } from '../utils/type-guards.js';
|
|
6
|
+
import { typeExtends } from '../utils/type/index.js';
|
|
7
|
+
import { Application, APPLICATION_DESTRUCTOR, APPLICATION_INITIALIZER, APPLICATION_MODULE } from './application.js';
|
|
8
|
+
const quitSignals = ['SIGTERM', 'SIGINT', 'SIGHUP', 'SIGBREAK'];
|
|
9
|
+
const quitEvents = ['uncaughtException', 'unhandledRejection', 'rejectionHandled'];
|
|
10
|
+
export function provideModules(...functionsAndModules) {
|
|
11
|
+
return functionsAndModules.flat().map((fnOrModule) => {
|
|
12
|
+
if (typeExtends(fnOrModule, Module)) {
|
|
13
|
+
return { provide: APPLICATION_MODULE, useValue: fnOrModule, multi: true };
|
|
14
|
+
}
|
|
15
|
+
else if (isFunction(fnOrModule)) {
|
|
16
|
+
return { provide: APPLICATION_MODULE, useToken: FunctionModule, defaultArgument: fnOrModule, multi: true };
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
throw new TypeError('Invalid module or function provided to provideModules');
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export function provideInitializer(fn) {
|
|
24
|
+
return { provide: APPLICATION_INITIALIZER, useValue: fn, multi: true };
|
|
25
|
+
}
|
|
26
|
+
export function provideDestructor(fn) {
|
|
27
|
+
return { provide: APPLICATION_DESTRUCTOR, useValue: fn, multi: true };
|
|
28
|
+
}
|
|
29
|
+
export function provideShutdownSignal(signal) {
|
|
30
|
+
return { provide: CancellationSignal, useValue: signal };
|
|
31
|
+
}
|
|
32
|
+
export function provideSignalHandler() {
|
|
33
|
+
let signalCounter = 0;
|
|
34
|
+
return provideInitializer(() => {
|
|
35
|
+
const application = inject(Application);
|
|
36
|
+
const logger = inject(Logger);
|
|
37
|
+
for (const event of quitEvents) {
|
|
38
|
+
process.on(event, (...args) => {
|
|
39
|
+
logger.error(`QuitEvent occurred: ${event}`, { details: args });
|
|
40
|
+
application.requestShutdown();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
for (const quitSignal of quitSignals) {
|
|
44
|
+
process.on(quitSignal, (signal) => {
|
|
45
|
+
logger.info(`${signal} received, quitting.`);
|
|
46
|
+
application.requestShutdown();
|
|
47
|
+
if (++signalCounter > 1) {
|
|
48
|
+
logger.warn('Forcefully quitting due to multiple signals...');
|
|
49
|
+
setTimeout(() => process.exit(1), 1);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EntityWithoutMetadata, Json, Timestamp, Uuid } from '../orm/index.js';
|
|
2
|
+
import { ActorType, AuditOutcome, AuditSeverity } from './types.js';
|
|
3
|
+
export declare class AuditEvent extends EntityWithoutMetadata {
|
|
4
|
+
timestamp: Timestamp;
|
|
5
|
+
correlationId?: Uuid;
|
|
6
|
+
module: string;
|
|
7
|
+
action: string;
|
|
8
|
+
outcome: AuditOutcome;
|
|
9
|
+
severity: AuditSeverity;
|
|
10
|
+
actorId: string;
|
|
11
|
+
actorType: ActorType;
|
|
12
|
+
targetId: string;
|
|
13
|
+
targetType: string;
|
|
14
|
+
details?: Json<unknown>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
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
|
+
import { EntityWithoutMetadata, Json, Table, Timestamp, Uuid } from '../orm/index.js';
|
|
11
|
+
import { Enumeration, StringProperty } from '../schema/index.js';
|
|
12
|
+
import { ActorType, AuditOutcome, AuditSeverity } from './types.js';
|
|
13
|
+
let AuditEvent = class AuditEvent extends EntityWithoutMetadata {
|
|
14
|
+
timestamp;
|
|
15
|
+
correlationId;
|
|
16
|
+
module;
|
|
17
|
+
action;
|
|
18
|
+
outcome;
|
|
19
|
+
severity;
|
|
20
|
+
actorId;
|
|
21
|
+
actorType;
|
|
22
|
+
targetId;
|
|
23
|
+
targetType;
|
|
24
|
+
details;
|
|
25
|
+
};
|
|
26
|
+
__decorate([
|
|
27
|
+
Timestamp(),
|
|
28
|
+
__metadata("design:type", Number)
|
|
29
|
+
], AuditEvent.prototype, "timestamp", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
Uuid({ nullable: true }),
|
|
32
|
+
__metadata("design:type", String)
|
|
33
|
+
], AuditEvent.prototype, "correlationId", void 0);
|
|
34
|
+
__decorate([
|
|
35
|
+
StringProperty(),
|
|
36
|
+
__metadata("design:type", String)
|
|
37
|
+
], AuditEvent.prototype, "module", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
StringProperty(),
|
|
40
|
+
__metadata("design:type", String)
|
|
41
|
+
], AuditEvent.prototype, "action", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
Enumeration(AuditOutcome),
|
|
44
|
+
__metadata("design:type", String)
|
|
45
|
+
], AuditEvent.prototype, "outcome", void 0);
|
|
46
|
+
__decorate([
|
|
47
|
+
Enumeration(AuditSeverity),
|
|
48
|
+
__metadata("design:type", String)
|
|
49
|
+
], AuditEvent.prototype, "severity", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
StringProperty(),
|
|
52
|
+
__metadata("design:type", String)
|
|
53
|
+
], AuditEvent.prototype, "actorId", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
Enumeration(ActorType),
|
|
56
|
+
__metadata("design:type", String)
|
|
57
|
+
], AuditEvent.prototype, "actorType", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
StringProperty(),
|
|
60
|
+
__metadata("design:type", String)
|
|
61
|
+
], AuditEvent.prototype, "targetId", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
StringProperty(),
|
|
64
|
+
__metadata("design:type", String)
|
|
65
|
+
], AuditEvent.prototype, "targetType", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
Json({ nullable: true }),
|
|
68
|
+
__metadata("design:type", Object)
|
|
69
|
+
], AuditEvent.prototype, "details", void 0);
|
|
70
|
+
AuditEvent = __decorate([
|
|
71
|
+
Table({ name: 'event' })
|
|
72
|
+
], AuditEvent);
|
|
73
|
+
export { AuditEvent };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Resolvable, type resolveArgumentType } from '../injector/index.js';
|
|
2
|
+
import type { UndefinableJsonObject } from '../types/index.js';
|
|
3
|
+
import type { ActorType } from './types.js';
|
|
4
|
+
import { AuditOutcome, AuditSeverity } from './types.js';
|
|
5
|
+
export type AuditPayload = Partial<{
|
|
6
|
+
correlationId?: string;
|
|
7
|
+
outcome?: AuditOutcome;
|
|
8
|
+
severity?: AuditSeverity;
|
|
9
|
+
actorId?: string;
|
|
10
|
+
actorType?: ActorType;
|
|
11
|
+
targetId?: string;
|
|
12
|
+
targetType?: string;
|
|
13
|
+
details?: UndefinableJsonObject;
|
|
14
|
+
}>;
|
|
15
|
+
export type AuditorArgument = string | string[] | {
|
|
16
|
+
module?: string | string[];
|
|
17
|
+
context?: Partial<AuditPayload>;
|
|
18
|
+
};
|
|
19
|
+
export declare class Auditor implements Resolvable<AuditorArgument> {
|
|
20
|
+
#private;
|
|
21
|
+
readonly module: string[];
|
|
22
|
+
readonly context: Partial<Partial<{
|
|
23
|
+
correlationId?: string;
|
|
24
|
+
outcome?: AuditOutcome;
|
|
25
|
+
severity?: AuditSeverity;
|
|
26
|
+
actorId?: string;
|
|
27
|
+
actorType?: ActorType;
|
|
28
|
+
targetId?: string;
|
|
29
|
+
targetType?: string;
|
|
30
|
+
details?: UndefinableJsonObject;
|
|
31
|
+
}>>;
|
|
32
|
+
get moduleString(): string;
|
|
33
|
+
readonly [resolveArgumentType]: AuditorArgument;
|
|
34
|
+
fork(subModule: string | string[]): Auditor;
|
|
35
|
+
with(context: Partial<AuditPayload>): Auditor;
|
|
36
|
+
withCorrelation(): Auditor;
|
|
37
|
+
log(action: string, data?: AuditPayload): Promise<void>;
|
|
38
|
+
info(action: string, data: AuditPayload): Promise<void>;
|
|
39
|
+
warn(action: string, data: AuditPayload): Promise<void>;
|
|
40
|
+
error(action: string, data: AuditPayload): Promise<void>;
|
|
41
|
+
critical(action: string, data: AuditPayload): Promise<void>;
|
|
42
|
+
}
|
package/audit/auditor.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
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
|
+
var Auditor_1;
|
|
11
|
+
import { createContextProvider } from '../context/index.js';
|
|
12
|
+
import { Injectable, injectArgument } from '../injector/index.js';
|
|
13
|
+
import { injectRepository } from '../orm/server/index.js';
|
|
14
|
+
import { TRANSACTION_TIMESTAMP } from '../orm/sqls.js';
|
|
15
|
+
import { toArray } from '../utils/array/index.js';
|
|
16
|
+
import { Memoize } from '../utils/function/memoize.js';
|
|
17
|
+
import { filterUndefinedFromRecord, objectKeys } from '../utils/object/object.js';
|
|
18
|
+
import { assertDefinedPass, isArray, isNotArray, isObject, isString } from '../utils/type-guards.js';
|
|
19
|
+
import { AuditEvent } from './audit.model.js';
|
|
20
|
+
import { AuditOutcome, AuditSeverity } from './types.js';
|
|
21
|
+
const { runInAuditorCreationContext, getCurrentAuditorCreationContext, isInAuditorCreationContext } = createContextProvider('AuditorCreation');
|
|
22
|
+
let Auditor = Auditor_1 = class Auditor {
|
|
23
|
+
#repository = injectRepository(AuditEvent);
|
|
24
|
+
#argument = isInAuditorCreationContext() ? injectArgument(this, { optional: true }) : undefined;
|
|
25
|
+
#creationContext = getCurrentAuditorCreationContext();
|
|
26
|
+
module = this.#creationContext?.module ?? moduleFromArgument(this.#argument);
|
|
27
|
+
context = this.#creationContext?.context ?? ((isObject(this.#argument) && isNotArray(this.#argument)) ? (this.#argument.context ?? {}) : {});
|
|
28
|
+
get moduleString() {
|
|
29
|
+
return this.module.join('.');
|
|
30
|
+
}
|
|
31
|
+
fork(subModule) {
|
|
32
|
+
return runInAuditorCreationContext({
|
|
33
|
+
module: [...this.module, ...toArray(subModule)],
|
|
34
|
+
context: this.context,
|
|
35
|
+
}, () => new Auditor_1());
|
|
36
|
+
}
|
|
37
|
+
with(context) {
|
|
38
|
+
return runInAuditorCreationContext({
|
|
39
|
+
module: this.module,
|
|
40
|
+
context: { ...this.context, ...context, details: { ...this.context.details, ...context.details } },
|
|
41
|
+
}, () => new Auditor_1());
|
|
42
|
+
}
|
|
43
|
+
withCorrelation() {
|
|
44
|
+
return this.with({ correlationId: this.context.correlationId ?? crypto.randomUUID() });
|
|
45
|
+
}
|
|
46
|
+
async log(action, data) {
|
|
47
|
+
const mergedData = { ...this.context, ...data, details: filterUndefinedFromRecord({ ...this.context.details, ...data?.details }) };
|
|
48
|
+
await this.#repository.insert({
|
|
49
|
+
timestamp: TRANSACTION_TIMESTAMP,
|
|
50
|
+
correlationId: mergedData.correlationId,
|
|
51
|
+
module: this.moduleString,
|
|
52
|
+
action: action,
|
|
53
|
+
outcome: assertDefinedPass(mergedData.outcome, 'Audit outcome is required'),
|
|
54
|
+
severity: assertDefinedPass(mergedData.severity, 'Audit severity is required'),
|
|
55
|
+
actorId: assertDefinedPass(mergedData.actorId, 'Audit actorId is required'),
|
|
56
|
+
actorType: assertDefinedPass(mergedData.actorType, 'Audit actorType is required'),
|
|
57
|
+
targetId: assertDefinedPass(mergedData.targetId, 'Audit targetId is required'),
|
|
58
|
+
targetType: assertDefinedPass(mergedData.targetType, 'Audit targetType is required'),
|
|
59
|
+
details: (objectKeys(mergedData.details).length > 0) ? mergedData.details : undefined,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async info(action, data) {
|
|
63
|
+
await this.log(action, {
|
|
64
|
+
...data,
|
|
65
|
+
severity: AuditSeverity.Info,
|
|
66
|
+
outcome: data.outcome ?? AuditOutcome.Success,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async warn(action, data) {
|
|
70
|
+
await this.log(action, {
|
|
71
|
+
...data,
|
|
72
|
+
severity: AuditSeverity.Warn,
|
|
73
|
+
outcome: data.outcome ?? AuditOutcome.Failure,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async error(action, data) {
|
|
77
|
+
await this.log(action, {
|
|
78
|
+
...data,
|
|
79
|
+
severity: AuditSeverity.Error,
|
|
80
|
+
outcome: data.outcome ?? AuditOutcome.Failure,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async critical(action, data) {
|
|
84
|
+
await this.log(action, {
|
|
85
|
+
...data,
|
|
86
|
+
severity: AuditSeverity.Critical,
|
|
87
|
+
outcome: data.outcome ?? AuditOutcome.Failure,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
__decorate([
|
|
92
|
+
Memoize(),
|
|
93
|
+
__metadata("design:type", String),
|
|
94
|
+
__metadata("design:paramtypes", [])
|
|
95
|
+
], Auditor.prototype, "moduleString", null);
|
|
96
|
+
Auditor = Auditor_1 = __decorate([
|
|
97
|
+
Injectable()
|
|
98
|
+
], Auditor);
|
|
99
|
+
export { Auditor };
|
|
100
|
+
function moduleFromArgument(argument) {
|
|
101
|
+
if (isString(argument)) {
|
|
102
|
+
return [argument];
|
|
103
|
+
}
|
|
104
|
+
if (isArray(argument)) {
|
|
105
|
+
return argument;
|
|
106
|
+
}
|
|
107
|
+
if (isObject(argument)) {
|
|
108
|
+
return moduleFromArgument(argument.module);
|
|
109
|
+
}
|
|
110
|
+
return [];
|
|
111
|
+
}
|
package/audit/index.d.ts
ADDED
package/audit/index.js
ADDED
package/audit/types.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type EnumType } from '../enumeration/index.js';
|
|
2
|
+
export declare const AuditSeverity: {
|
|
3
|
+
readonly Info: "info";
|
|
4
|
+
readonly Warn: "warn";
|
|
5
|
+
readonly Error: "error";
|
|
6
|
+
readonly Critical: "critical";
|
|
7
|
+
};
|
|
8
|
+
export type AuditSeverity = EnumType<typeof AuditSeverity>;
|
|
9
|
+
export declare const AuditOutcome: {
|
|
10
|
+
readonly Pending: "pending";
|
|
11
|
+
readonly Success: "success";
|
|
12
|
+
readonly Cancelled: "cancelled";
|
|
13
|
+
readonly Failure: "failure";
|
|
14
|
+
readonly Denied: "denied";
|
|
15
|
+
};
|
|
16
|
+
export type AuditOutcome = EnumType<typeof AuditOutcome>;
|
|
17
|
+
export declare const ActorType: {
|
|
18
|
+
readonly User: "user";
|
|
19
|
+
readonly System: "system";
|
|
20
|
+
readonly ApiKey: "api-key";
|
|
21
|
+
};
|
|
22
|
+
export type ActorType = EnumType<typeof ActorType>;
|
package/audit/types.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineEnum } from '../enumeration/index.js';
|
|
2
|
+
export const AuditSeverity = defineEnum('AuditSeverity', {
|
|
3
|
+
Info: 'info',
|
|
4
|
+
Warn: 'warn',
|
|
5
|
+
Error: 'error',
|
|
6
|
+
Critical: 'critical',
|
|
7
|
+
});
|
|
8
|
+
export const AuditOutcome = defineEnum('AuditOutcome', {
|
|
9
|
+
Pending: 'pending',
|
|
10
|
+
Success: 'success',
|
|
11
|
+
Cancelled: 'cancelled',
|
|
12
|
+
Failure: 'failure',
|
|
13
|
+
Denied: 'denied',
|
|
14
|
+
});
|
|
15
|
+
export const ActorType = defineEnum('ActorType', {
|
|
16
|
+
User: 'user',
|
|
17
|
+
System: 'system',
|
|
18
|
+
ApiKey: 'api-key',
|
|
19
|
+
});
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { AsyncDisposable } from '../../disposable/index.js';
|
|
2
|
-
import { disposeAsync } from '../../disposable/index.js';
|
|
3
1
|
import type { AfterResolve } from '../../injector/index.js';
|
|
4
2
|
import { afterResolve } from '../../injector/index.js';
|
|
5
3
|
import type { Record } from '../../types/index.js';
|
|
@@ -95,7 +93,7 @@ export declare class AuthenticationClientService<AdditionalTokenPayload extends
|
|
|
95
93
|
*/
|
|
96
94
|
initialize(): void;
|
|
97
95
|
/** @internal */
|
|
98
|
-
[
|
|
96
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
99
97
|
/**
|
|
100
98
|
* Disposes the service.
|
|
101
99
|
* Stops refresh loop and completes subjects.
|
|
@@ -9,7 +9,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
import { Subject, filter, firstValueFrom, race, timer } from 'rxjs';
|
|
11
11
|
import { CancellationToken } from '../../cancellation/token.js';
|
|
12
|
-
import { disposeAsync } from '../../disposable/index.js';
|
|
13
12
|
import { BadRequestError } from '../../errors/bad-request.error.js';
|
|
14
13
|
import { ForbiddenError } from '../../errors/forbidden.error.js';
|
|
15
14
|
import { InvalidTokenError } from '../../errors/invalid-token.error.js';
|
|
@@ -162,7 +161,7 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
162
161
|
void this.refreshLoop();
|
|
163
162
|
}
|
|
164
163
|
/** @internal */
|
|
165
|
-
async [
|
|
164
|
+
async [Symbol.asyncDispose]() {
|
|
166
165
|
await this.dispose();
|
|
167
166
|
}
|
|
168
167
|
/**
|
|
@@ -254,7 +253,7 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
254
253
|
if (this.impersonated()) {
|
|
255
254
|
throw new Error('Already impersonating. Please unimpersonate first.');
|
|
256
255
|
}
|
|
257
|
-
await this.lock.use(lockTimeout,
|
|
256
|
+
await this.lock.use(lockTimeout, async () => {
|
|
258
257
|
this.impersonatorAuthenticationData = this.authenticationData;
|
|
259
258
|
this.authenticationData = data;
|
|
260
259
|
try {
|
|
@@ -275,7 +274,7 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
275
274
|
* @param data Additional authentication data. If not provided, the data from before impersonation is used.
|
|
276
275
|
*/
|
|
277
276
|
async unimpersonate(data) {
|
|
278
|
-
await this.lock.use(lockTimeout,
|
|
277
|
+
await this.lock.use(lockTimeout, async () => {
|
|
279
278
|
const newData = data ?? this.impersonatorAuthenticationData;
|
|
280
279
|
try {
|
|
281
280
|
const token = await this.client.unimpersonate({ data: newData });
|
|
@@ -334,7 +333,7 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
334
333
|
while (this.disposeToken.isUnset) {
|
|
335
334
|
try {
|
|
336
335
|
// Use a non-blocking lock to ensure only one tab/instance runs the refresh logic at a time.
|
|
337
|
-
await this.lock.
|
|
336
|
+
await this.lock.tryUse(undefined, async () => await this.refreshLoopIteration());
|
|
338
337
|
// Calculate delay until the next refresh check.
|
|
339
338
|
// The buffer ensures we refresh *before* the token actually expires.
|
|
340
339
|
const delay = ((this.token()?.exp ?? 0) - this.estimatedServerTimestampSeconds() - refreshBufferSeconds) * millisecondsPerSecond;
|