@tstdl/base 0.92.145 → 0.92.147
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/ai-file.service.d.ts +29 -1
- package/ai/ai-file.service.js +66 -23
- package/ai/ai-session.d.ts +28 -1
- package/ai/ai-session.js +27 -0
- package/ai/ai.service.d.ts +89 -5
- package/ai/ai.service.js +130 -27
- package/ai/functions.d.ts +7 -1
- package/ai/functions.js +7 -1
- package/ai/module.d.ts +8 -0
- package/ai/module.js +4 -0
- package/ai/types.d.ts +115 -2
- package/ai/types.js +16 -0
- package/api/client/client.d.ts +1 -1
- package/api/client/client.js +1 -1
- package/api/default-error-handlers.d.ts +1 -1
- package/api/index.d.ts +1 -9
- package/api/index.js +1 -9
- package/api/response.d.ts +1 -1
- package/api/server/api-controller.d.ts +1 -1
- package/api/server/error-handler.d.ts +1 -1
- package/api/server/gateway.d.ts +1 -5
- package/api/server/gateway.js +0 -4
- package/api/server/middlewares/catch-error.middleware.d.ts +1 -1
- package/api/server/module.d.ts +1 -1
- package/api/types.d.ts +1 -1
- package/application/application.d.ts +1 -1
- package/authentication/authentication.api.d.ts +36 -1
- package/authentication/authentication.api.js +28 -0
- package/authentication/client/api.client.d.ts +14 -1
- package/authentication/client/api.client.js +13 -0
- package/authentication/client/authentication.service.d.ts +104 -1
- package/authentication/client/authentication.service.js +103 -0
- package/authentication/client/http-client.middleware.d.ts +5 -0
- package/authentication/client/http-client.middleware.js +6 -2
- package/authentication/client/module.d.ts +20 -1
- package/authentication/client/module.js +6 -1
- package/authentication/client/tokens.d.ts +6 -0
- package/authentication/client/tokens.js +6 -0
- package/authentication/models/authentication-credentials.model.d.ts +6 -0
- package/authentication/models/authentication-credentials.model.js +6 -0
- package/authentication/models/authentication-session.model.d.ts +6 -0
- package/authentication/models/authentication-session.model.js +6 -0
- package/authentication/models/init-secret-reset-data.model.d.ts +10 -1
- package/authentication/models/init-secret-reset-data.model.js +10 -1
- package/authentication/models/token-payload-base.model.d.ts +24 -4
- package/authentication/models/token-payload-base.model.js +24 -4
- package/authentication/models/token.model.d.ts +33 -2
- package/authentication/server/authentication-ancillary.service.d.ts +27 -4
- package/authentication/server/authentication-ancillary.service.js +7 -0
- package/authentication/server/authentication-api-request-token.provider.d.ts +3 -0
- package/authentication/server/authentication-api-request-token.provider.js +3 -0
- package/authentication/server/authentication-secret-requirements.validator.d.ts +37 -0
- package/authentication/server/authentication-secret-requirements.validator.js +22 -0
- package/authentication/server/authentication.api-controller.d.ts +66 -1
- package/authentication/server/authentication.api-controller.js +65 -0
- package/authentication/server/authentication.service.d.ts +191 -11
- package/authentication/server/authentication.service.js +157 -8
- package/authentication/server/helper.d.ts +44 -5
- package/authentication/server/helper.js +43 -4
- package/authentication/server/module.d.ts +23 -1
- package/authentication/server/module.js +23 -1
- package/browser/browser-context-controller.d.ts +1 -1
- package/browser/browser-controller.d.ts +1 -1
- package/browser/browser-controller.js +1 -1
- package/browser/element-controller.d.ts +1 -1
- package/browser/locator-controller.d.ts +1 -1
- package/context/context.d.ts +1 -1
- package/data-structures/context-data-map.d.ts +1 -1
- package/database/mongo/mongo-base.repository.d.ts +1 -1
- package/database/mongo/types.d.ts +1 -1
- package/database/query.d.ts +1 -1
- package/document-management/models/document-management-table.d.ts +1 -1
- package/document-management/models/document-validation-definition.model.d.ts +1 -1
- package/document-management/server/schemas.d.ts +1 -1
- package/document-management/server/services/document-collection.service.d.ts +1 -1
- package/document-management/server/services/document-management-observation.service.d.ts +1 -1
- package/document-management/server/services/document-management.service.d.ts +1 -1
- package/document-management/server/services/document-property.service.d.ts +3 -3
- package/document-management/server/services/document-request.service.d.ts +1 -1
- package/document-management/server/services/document-validation.service.d.ts +1 -1
- package/document-management/server/services/document-workflow.service.d.ts +1 -1
- package/document-management/server/services/document.service.d.ts +1 -1
- package/document-management/server/services/singleton.d.ts +1 -1
- package/document-management/service-models/document-management.view-model.d.ts +1 -1
- package/document-management/service-models/enriched/enriched-document-assignment.view.d.ts +1 -1
- package/document-management/service-models/enriched/enriched-document-category.view.d.ts +1 -1
- package/document-management/service-models/enriched/enriched-document-collection.view.d.ts +1 -1
- package/document-management/service-models/enriched/enriched-document-request.view.d.ts +1 -1
- package/document-management/service-models/enriched/enriched-document-type.view.d.ts +1 -1
- package/document-management/service-models/enriched/enriched-document.view.d.ts +1 -1
- package/document-management/service-models/enriched/enriched-requests-template-data.model.d.ts +1 -1
- package/dom/file-select-dialog.d.ts +1 -1
- package/enumeration/enumeration.d.ts +1 -1
- package/errors/custom.error.d.ts +3 -0
- package/errors/custom.error.js +0 -1
- package/errors/errors.localization.d.ts +1 -1
- package/errors/not-supported.error.d.ts +1 -1
- package/{formats.js → formats/formats.js} +3 -3
- package/formats/index.d.ts +1 -0
- package/formats/index.js +1 -0
- package/http/client/http-client-request.d.ts +1 -1
- package/http/client/http-client-response.d.ts +1 -1
- package/http/client/http-client.d.ts +1 -1
- package/http/client/module.d.ts +1 -1
- package/http/http-body.d.ts +1 -1
- package/http/http-value-map.d.ts +1 -1
- package/http/http.error.d.ts +1 -1
- package/http/server/http-server-request.d.ts +1 -1
- package/http/server/http-server-response.d.ts +1 -1
- package/http/types.d.ts +1 -1
- package/http/utils.d.ts +1 -1
- package/injector/decorators.d.ts +1 -1
- package/injector/index.d.ts +1 -1
- package/injector/index.js +1 -1
- package/injector/injector.d.ts +10 -1
- package/injector/injector.js +6 -0
- package/injector/interfaces.d.ts +1 -1
- package/injector/provider.d.ts +1 -1
- package/injector/resolution.d.ts +10 -5
- package/injector/resolve-chain.d.ts +2 -2
- package/injector/resolve-chain.js +1 -1
- package/injector/resolve.error.js +1 -1
- package/injector/token.d.ts +8 -1
- package/injector/token.js +7 -0
- package/injector/types.d.ts +1 -1
- package/key-value-store/key-value-store.provider.d.ts +2 -2
- package/key-value-store/key-value.store.d.ts +2 -2
- package/key-value-store/mongo/mongo-key-value-store.provider.d.ts +1 -1
- package/key-value-store/mongo/mongo-key-value.store.d.ts +1 -1
- package/key-value-store/postgres/key-value-store.service.d.ts +1 -1
- package/mail/mail.service.d.ts +1 -1
- package/mail/models/mail-data.model.d.ts +1 -1
- package/mail/models/mail-template.model.d.ts +1 -1
- package/mail/module.d.ts +1 -1
- package/module/index.d.ts +0 -1
- package/module/index.js +0 -1
- package/module/module-base.d.ts +1 -1
- package/module/module-metric-reporter.js +1 -1
- package/module/module.d.ts +1 -1
- package/module/modules/function.module.js +1 -1
- package/object-storage/object.d.ts +1 -1
- package/openid-connect/mongo-oidc-state.repository.d.ts +1 -1
- package/openid-connect/oidc.service.d.ts +1 -1
- package/orm/decorators.d.ts +2 -2
- package/orm/entity.d.ts +1 -1
- package/orm/index.d.ts +3 -3
- package/orm/index.js +3 -3
- package/orm/query.d.ts +1 -1
- package/orm/repository.types.d.ts +1 -1
- package/orm/schemas/json.d.ts +1 -1
- package/orm/server/database-schema.d.ts +1 -1
- package/orm/server/drizzle/schema-converter.d.ts +1 -1
- package/orm/server/repository.d.ts +1 -1
- package/orm/server/transaction.d.ts +1 -1
- package/orm/server/transactional.d.ts +3 -3
- package/orm/server/types.d.ts +1 -1
- package/orm/types.d.ts +1 -1
- package/package.json +23 -20
- package/queue/mongo/job.d.ts +1 -1
- package/queue/mongo/queue.js +31 -31
- package/queue/postgres/job.model.d.ts +1 -1
- package/queue/postgres/queue.d.ts +1 -1
- package/queue/postgres/queue.provider.d.ts +1 -1
- package/queue/provider.d.ts +1 -1
- package/reflection/decorators.d.ts +1 -1
- package/reflection/registry.d.ts +1 -1
- package/reflection/types.d.ts +1 -1
- package/reflection/utils.d.ts +1 -1
- package/rpc/model.d.ts +1 -1
- package/rxjs-utils/retry-backoff.js +2 -2
- package/schema/converters/openapi-converter.d.ts +1 -1
- package/schema/decorators/schema.d.ts +1 -1
- package/schema/decorators/utils.d.ts +1 -1
- package/schema/schema.d.ts +1 -1
- package/schema/schema.error.d.ts +1 -1
- package/schema/schemas/array.d.ts +1 -1
- package/schema/schemas/enumeration.d.ts +1 -1
- package/schema/schemas/function.d.ts +1 -1
- package/schema/schemas/instance.d.ts +1 -1
- package/schema/schemas/nullable.d.ts +1 -1
- package/schema/schemas/number.d.ts +1 -1
- package/schema/schemas/object.d.ts +1 -1
- package/schema/schemas/one-or-many.d.ts +1 -1
- package/schema/schemas/optional.d.ts +1 -1
- package/schema/schemas/simple.d.ts +1 -1
- package/search-index/elastic/model/index-mapping.d.ts +1 -1
- package/search-index/elastic/search-index.js +3 -4
- package/search-index/memory/memory-search-index.d.ts +1 -1
- package/search-index/memory/memory-search-index.js +1 -1
- package/serializer/handlers/binary.d.ts +1 -1
- package/serializer/serializable.d.ts +1 -1
- package/serializer/types.d.ts +1 -1
- package/templates/module.d.ts +1 -1
- package/templates/renderers/handlebars.template-renderer.d.ts +1 -1
- package/templates/renderers/jsx.template-renderer.d.ts +1 -1
- package/templates/renderers/mjml.template-renderer.d.ts +1 -1
- package/templates/renderers/string.template-renderer.d.ts +1 -1
- package/templates/resolvers/file.template-resolver.d.ts +1 -1
- package/templates/resolvers/jsx.template-resolver.d.ts +1 -1
- package/templates/resolvers/string.template-resolver.d.ts +1 -1
- package/templates/template.model.d.ts +1 -1
- package/templates/template.renderer.d.ts +1 -1
- package/templates/template.service.d.ts +1 -1
- package/text/dynamic-text.model.d.ts +1 -1
- package/text/localization.service.d.ts +1 -1
- package/types/geo-json.d.ts +1 -1
- package/types/index.d.ts +2 -0
- package/types/tagged.d.ts +1 -1
- package/{types.d.ts → types/types.d.ts} +2 -1
- package/utils/async-hook/async-hook.d.ts +109 -0
- package/utils/async-hook/async-hook.js +77 -3
- package/utils/backoff.d.ts +125 -43
- package/utils/backoff.js +140 -65
- package/utils/base64.d.ts +1 -1
- package/utils/base64.js +1 -2
- package/utils/binary.d.ts +1 -1
- package/utils/comparison.d.ts +5 -5
- package/utils/comparison.js +5 -3
- package/utils/cryptography.d.ts +1 -1
- package/utils/encoding.d.ts +1 -1
- package/utils/enum.d.ts +1 -1
- package/utils/equals.d.ts +1 -1
- package/utils/format-error.d.ts +1 -1
- package/utils/function/class.d.ts +1 -1
- package/utils/function/memoize.d.ts +1 -1
- package/utils/helpers.d.ts +1 -1
- package/utils/helpers.js +2 -2
- package/utils/jwt.d.ts +3 -3
- package/utils/merge.d.ts +1 -1
- package/utils/middleware.js +3 -3
- package/utils/object/decycle.d.ts +1 -1
- package/utils/object/forward-ref.d.ts +1 -1
- package/utils/object/lazy-property.d.ts +1 -1
- package/utils/object/object.d.ts +1 -1
- package/utils/object/property-name.d.ts +1 -1
- package/utils/patch-worker.d.ts +1 -1
- package/utils/reactive-value-to-signal.d.ts +1 -1
- package/utils/reflection.d.ts +1 -1
- package/utils/repl.d.ts +1 -1
- package/utils/singleton.d.ts +1 -1
- package/utils/stream/size-limited-stream.d.ts +1 -1
- package/utils/type/extends.d.ts +1 -1
- package/utils/type-guards.d.ts +1 -1
- package/utils/url-builder.d.ts +1 -1
- package/utils/z-base32.d.ts +1 -1
- package/module/utils.d.ts +0 -4
- package/module/utils.js +0 -21
- /package/{formats.d.ts → formats/formats.d.ts} +0 -0
- /package/{types.js → types/types.js} +0 -0
- /package/{web-types.d.ts → types/web-types.d.ts} +0 -0
- /package/{web-types.js → types/web-types.js} +0 -0
package/api/server/gateway.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { HttpServerRequestContext } from '../../http/server/http-server.js'
|
|
|
3
3
|
import { HttpServerResponse, type HttpServerRequest } from '../../http/server/index.js';
|
|
4
4
|
import { resolveArgumentType, type Resolvable } from '../../injector/index.js';
|
|
5
5
|
import { Logger } from '../../logger/index.js';
|
|
6
|
-
import type { Type } from '../../types.js';
|
|
6
|
+
import type { Type } from '../../types/index.js';
|
|
7
7
|
import { type AsyncMiddleware, type AsyncMiddlewareNext } from '../../utils/middleware.js';
|
|
8
8
|
import { type ApiController, type ApiDefinition, type ApiEndpointDefinition, type ApiEndpointMethod, type ApiEndpointServerImplementation } from '../types.js';
|
|
9
9
|
import { ApiRequestTokenProvider } from './api-request-token.provider.js';
|
|
@@ -51,10 +51,6 @@ export type ApiMetadata = {
|
|
|
51
51
|
api: ApiItem;
|
|
52
52
|
patternResult: URLPatternResult;
|
|
53
53
|
};
|
|
54
|
-
/**
|
|
55
|
-
* router for {@link ApiTransport} requests to {@link ApiImplementation}
|
|
56
|
-
* @todo error handling (standardized format, serialization etc.)
|
|
57
|
-
*/
|
|
58
54
|
export declare class ApiGateway implements Resolvable<ApiGatewayOptions> {
|
|
59
55
|
private readonly requestTokenProvider;
|
|
60
56
|
private readonly logger;
|
package/api/server/gateway.js
CHANGED
|
@@ -50,10 +50,6 @@ export class ApiGatewayOptions {
|
|
|
50
50
|
*/
|
|
51
51
|
defaultMaxBytes;
|
|
52
52
|
}
|
|
53
|
-
/**
|
|
54
|
-
* router for {@link ApiTransport} requests to {@link ApiImplementation}
|
|
55
|
-
* @todo error handling (standardized format, serialization etc.)
|
|
56
|
-
*/
|
|
57
53
|
let ApiGateway = class ApiGateway {
|
|
58
54
|
requestTokenProvider;
|
|
59
55
|
logger;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Logger } from '../../../logger/index.js';
|
|
2
|
-
import type { Type } from '../../../types.js';
|
|
2
|
+
import type { Type } from '../../../types/index.js';
|
|
3
3
|
import type { ApiGatewayMiddleware } from '../gateway.js';
|
|
4
4
|
export declare function getCatchErrorMiddleware(supressedErrors: Set<Type<Error>>, logger: Logger): ApiGatewayMiddleware;
|
package/api/server/module.d.ts
CHANGED
package/api/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { HttpMethod } from '../http/types.js';
|
|
|
3
3
|
import type { SchemaOutput, SchemaTestable } from '../schema/index.js';
|
|
4
4
|
import type { ServerSentEventsSource } from '../sse/server-sent-events-source.js';
|
|
5
5
|
import type { ServerSentEvents } from '../sse/server-sent-events.js';
|
|
6
|
-
import type { NonUndefinable, OneOrMany, Record, ReturnTypeOrT } from '../types.js';
|
|
6
|
+
import type { NonUndefinable, OneOrMany, Record, ReturnTypeOrT } from '../types/index.js';
|
|
7
7
|
import { type ValueOrProvider } from '../utils/value-or-provider.js';
|
|
8
8
|
import type { ApiGatewayMiddlewareContext } from './server/index.js';
|
|
9
9
|
export type ApiRegistrationOptions = {
|
|
@@ -3,7 +3,7 @@ import type { Resolvable, resolveArgumentType } from '../injector/interfaces.js'
|
|
|
3
3
|
import type { LoggerArgument } from '../logger/index.js';
|
|
4
4
|
import type { Module } from '../module/module.js';
|
|
5
5
|
import type { FunctionModuleFunction } from '../module/modules/function.module.js';
|
|
6
|
-
import type { OneOrMany, Type } from '../types.js';
|
|
6
|
+
import type { OneOrMany, Type } from '../types/index.js';
|
|
7
7
|
export type BootstrapFn = () => void | Promise<void>;
|
|
8
8
|
export type RunOptions = {
|
|
9
9
|
bootstrap?: OneOrMany<BootstrapFn>;
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
import { type ApiDefinition, type ApiEndpointsDefinition } from '../api/types.js';
|
|
2
2
|
import { type ObjectSchema, type ObjectSchemaOrType } from '../schema/index.js';
|
|
3
3
|
import type { SchemaTestable } from '../schema/schema.js';
|
|
4
|
-
import type { Record } from '../types.js';
|
|
4
|
+
import type { Record } from '../types/index.js';
|
|
5
5
|
import type { TokenPayload } from './index.js';
|
|
6
6
|
import { SecretCheckResult } from './models/secret-check-result.model.js';
|
|
7
|
+
/**
|
|
8
|
+
* Can be provided in {@link ApiEndpointDefinition} data property to signal that the request does not need a valid token.
|
|
9
|
+
* Useful for login, refresh, etc. endpoints.
|
|
10
|
+
*/
|
|
7
11
|
export declare const dontWaitForValidToken: unique symbol;
|
|
8
12
|
type GetAuthenticationApiEndpointsDefinition<AdditionalTokenPayload extends Record = Record<never>, AuthenticationData = void, AdditionalInitSecretResetData = void> = typeof getAuthenticationApiEndpointsDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>;
|
|
9
13
|
type AuthenticationApiEndpointsDefinition<AdditionalTokenPayload extends Record = Record<never>, AuthenticationData = void, AdditionalInitSecretResetData = void> = ReturnType<GetAuthenticationApiEndpointsDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>>;
|
|
14
|
+
/**
|
|
15
|
+
* Authentication REST API definition
|
|
16
|
+
*
|
|
17
|
+
* @template AdditionalTokenPayload Type of additional token payload
|
|
18
|
+
* @template AuthenticationData Type of additional authentication data
|
|
19
|
+
* @template AdditionalInitSecretResetData Type of additional secret reset data
|
|
20
|
+
*/
|
|
10
21
|
export type AuthenticationApiDefinition<AdditionalTokenPayload extends Record = Record<never>, AuthenticationData = void, AdditionalInitSecretResetData = void> = ApiDefinition<string, AuthenticationApiEndpointsDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>>;
|
|
22
|
+
/** Default authentication API definition */
|
|
11
23
|
export declare const authenticationApiDefinition: {
|
|
12
24
|
resource: string;
|
|
13
25
|
endpoints: {
|
|
@@ -103,6 +115,19 @@ export declare const authenticationApiDefinition: {
|
|
|
103
115
|
};
|
|
104
116
|
};
|
|
105
117
|
};
|
|
118
|
+
/**
|
|
119
|
+
* Get authentication REST API definition
|
|
120
|
+
* @param additionalTokenPayloadSchema Schema for additional token payload
|
|
121
|
+
* @param authenticationDataSchema Schema for additional authentication data
|
|
122
|
+
* @param initSecretResetDataSchema Schema for additional secret reset data
|
|
123
|
+
* @param resource Resource name (default: 'auth')
|
|
124
|
+
* @param additionalEndpoints Additional endpoints to add to the API definition
|
|
125
|
+
* @returns Authentication REST API definition
|
|
126
|
+
* @template AdditionalTokenPayload Type of additional token payload
|
|
127
|
+
* @template AuthenticationData Type of additional authentication data
|
|
128
|
+
* @template AdditionalInitSecretResetData Type of additional secret reset data
|
|
129
|
+
* @template AdditionalEndpoints Type of additional endpoints
|
|
130
|
+
*/
|
|
106
131
|
export declare function getAuthenticationApiDefinition<AdditionalTokenPayload extends Record, AuthenticationData, AdditionalInitSecretResetData, AdditionalEndpoints extends ApiEndpointsDefinition>(additionalTokenPayloadSchema: ObjectSchemaOrType<AdditionalTokenPayload>, authenticationDataSchema: SchemaTestable<AuthenticationData>, initSecretResetDataSchema: SchemaTestable<AdditionalInitSecretResetData>, resource?: string, additionalEndpoints?: AdditionalEndpoints): {
|
|
107
132
|
resource: string;
|
|
108
133
|
endpoints: {
|
|
@@ -198,6 +223,16 @@ export declare function getAuthenticationApiDefinition<AdditionalTokenPayload ex
|
|
|
198
223
|
};
|
|
199
224
|
};
|
|
200
225
|
};
|
|
226
|
+
/**
|
|
227
|
+
* Get authentication REST API endpoints definition
|
|
228
|
+
* @param additionalTokenPayloadSchema Schema for additional token payload
|
|
229
|
+
* @param authenticationDataSchema Schema for additional authentication data
|
|
230
|
+
* @param additionalInitSecretResetDataSchema Schema for additional secret reset data
|
|
231
|
+
* @returns Authentication REST API endpoints definition
|
|
232
|
+
* @template AdditionalTokenPayload Type of additional token payload
|
|
233
|
+
* @template AuthenticationData Type of additional authentication data
|
|
234
|
+
* @template AdditionalInitSecretResetData Type of additional secret reset data
|
|
235
|
+
*/
|
|
201
236
|
export declare function getAuthenticationApiEndpointsDefinition<AdditionalTokenPayload extends Record, AuthenticationData, AdditionalInitSecretResetData>(additionalTokenPayloadSchema: ObjectSchemaOrType<AdditionalTokenPayload>, authenticationDataSchema: SchemaTestable<AuthenticationData>, additionalInitSecretResetDataSchema: SchemaTestable<AdditionalInitSecretResetData>): {
|
|
202
237
|
getToken: {
|
|
203
238
|
resource: string;
|
|
@@ -2,8 +2,26 @@ import { defineApi } from '../api/types.js';
|
|
|
2
2
|
import { assign, emptyObjectSchema, explicitObject, literal, never, number, object, optional, string } from '../schema/index.js';
|
|
3
3
|
import { SecretCheckResult } from './models/secret-check-result.model.js';
|
|
4
4
|
import { TokenPayloadBase } from './models/token-payload-base.model.js';
|
|
5
|
+
/**
|
|
6
|
+
* Can be provided in {@link ApiEndpointDefinition} data property to signal that the request does not need a valid token.
|
|
7
|
+
* Useful for login, refresh, etc. endpoints.
|
|
8
|
+
*/
|
|
5
9
|
export const dontWaitForValidToken = Symbol('dontWaitForValidToken');
|
|
10
|
+
/** Default authentication API definition */
|
|
6
11
|
export const authenticationApiDefinition = getAuthenticationApiDefinition(emptyObjectSchema, optional(never()), optional(never()));
|
|
12
|
+
/**
|
|
13
|
+
* Get authentication REST API definition
|
|
14
|
+
* @param additionalTokenPayloadSchema Schema for additional token payload
|
|
15
|
+
* @param authenticationDataSchema Schema for additional authentication data
|
|
16
|
+
* @param initSecretResetDataSchema Schema for additional secret reset data
|
|
17
|
+
* @param resource Resource name (default: 'auth')
|
|
18
|
+
* @param additionalEndpoints Additional endpoints to add to the API definition
|
|
19
|
+
* @returns Authentication REST API definition
|
|
20
|
+
* @template AdditionalTokenPayload Type of additional token payload
|
|
21
|
+
* @template AuthenticationData Type of additional authentication data
|
|
22
|
+
* @template AdditionalInitSecretResetData Type of additional secret reset data
|
|
23
|
+
* @template AdditionalEndpoints Type of additional endpoints
|
|
24
|
+
*/
|
|
7
25
|
export function getAuthenticationApiDefinition(additionalTokenPayloadSchema, authenticationDataSchema, initSecretResetDataSchema, resource, additionalEndpoints) {
|
|
8
26
|
return defineApi({
|
|
9
27
|
resource: resource ?? 'auth',
|
|
@@ -13,6 +31,16 @@ export function getAuthenticationApiDefinition(additionalTokenPayloadSchema, aut
|
|
|
13
31
|
},
|
|
14
32
|
});
|
|
15
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Get authentication REST API endpoints definition
|
|
36
|
+
* @param additionalTokenPayloadSchema Schema for additional token payload
|
|
37
|
+
* @param authenticationDataSchema Schema for additional authentication data
|
|
38
|
+
* @param additionalInitSecretResetDataSchema Schema for additional secret reset data
|
|
39
|
+
* @returns Authentication REST API endpoints definition
|
|
40
|
+
* @template AdditionalTokenPayload Type of additional token payload
|
|
41
|
+
* @template AuthenticationData Type of additional authentication data
|
|
42
|
+
* @template AdditionalInitSecretResetData Type of additional secret reset data
|
|
43
|
+
*/
|
|
16
44
|
export function getAuthenticationApiEndpointsDefinition(additionalTokenPayloadSchema, authenticationDataSchema, additionalInitSecretResetDataSchema) {
|
|
17
45
|
const tokenResultSchema = assign(TokenPayloadBase, additionalTokenPayloadSchema);
|
|
18
46
|
return {
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import { type ApiClient } from '../../api/client/index.js';
|
|
2
2
|
import { type ObjectSchemaOrType, type SchemaTestable } from '../../schema/index.js';
|
|
3
|
-
import type { Record } from '../../types.js';
|
|
3
|
+
import type { Record } from '../../types/index.js';
|
|
4
4
|
import { type AuthenticationApiDefinition } from '../authentication.api.js';
|
|
5
|
+
/**
|
|
6
|
+
* Get an authentication API client
|
|
7
|
+
* @param additionalTokenPayloadSchema Schema for additional token payload
|
|
8
|
+
* @param authenticationDataSchema Schema for additional authentication data
|
|
9
|
+
* @param additionalInitSecretResetData Schema for additional secret reset data
|
|
10
|
+
* @returns Authentication API client
|
|
11
|
+
* @template AdditionalTokenPayload Type of additional token payload
|
|
12
|
+
* @template AuthenticationData Type of additional authentication data
|
|
13
|
+
* @template AdditionalInitSecretResetData Type of additional secret reset data
|
|
14
|
+
*/
|
|
5
15
|
export declare function getAuthenticationApiClient<AdditionalTokenPayload extends Record, AuthenticationData, AdditionalInitSecretResetData>(additionalTokenPayloadSchema: ObjectSchemaOrType<AdditionalTokenPayload>, authenticationDataSchema: SchemaTestable<AuthenticationData>, additionalInitSecretResetData: SchemaTestable<AdditionalInitSecretResetData>): ApiClient<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>>;
|
|
6
16
|
declare const defaultAuthenticationApiClient: ApiClient<AuthenticationApiDefinition<import("type-fest").EmptyObject, unknown, import("type-fest").EmptyObject>>;
|
|
17
|
+
/**
|
|
18
|
+
* Default authentication API client
|
|
19
|
+
*/
|
|
7
20
|
export declare class AuthenticationApiClient extends defaultAuthenticationApiClient {
|
|
8
21
|
}
|
|
9
22
|
export {};
|
|
@@ -8,6 +8,16 @@ import { compileClient } from '../../api/client/index.js';
|
|
|
8
8
|
import { ReplaceClass, Singleton } from '../../injector/index.js';
|
|
9
9
|
import { emptyObjectSchema, unknown } from '../../schema/index.js';
|
|
10
10
|
import { getAuthenticationApiDefinition } from '../authentication.api.js';
|
|
11
|
+
/**
|
|
12
|
+
* Get an authentication API client
|
|
13
|
+
* @param additionalTokenPayloadSchema Schema for additional token payload
|
|
14
|
+
* @param authenticationDataSchema Schema for additional authentication data
|
|
15
|
+
* @param additionalInitSecretResetData Schema for additional secret reset data
|
|
16
|
+
* @returns Authentication API client
|
|
17
|
+
* @template AdditionalTokenPayload Type of additional token payload
|
|
18
|
+
* @template AuthenticationData Type of additional authentication data
|
|
19
|
+
* @template AdditionalInitSecretResetData Type of additional secret reset data
|
|
20
|
+
*/
|
|
11
21
|
export function getAuthenticationApiClient(additionalTokenPayloadSchema, authenticationDataSchema, additionalInitSecretResetData) {
|
|
12
22
|
const definition = getAuthenticationApiDefinition(additionalTokenPayloadSchema, authenticationDataSchema, additionalInitSecretResetData);
|
|
13
23
|
let AuthenticationApiClient = class AuthenticationApiClient extends compileClient(definition) {
|
|
@@ -18,6 +28,9 @@ export function getAuthenticationApiClient(additionalTokenPayloadSchema, authent
|
|
|
18
28
|
return AuthenticationApiClient;
|
|
19
29
|
}
|
|
20
30
|
const defaultAuthenticationApiClient = getAuthenticationApiClient(emptyObjectSchema, unknown(), emptyObjectSchema);
|
|
31
|
+
/**
|
|
32
|
+
* Default authentication API client
|
|
33
|
+
*/
|
|
21
34
|
let AuthenticationApiClient = class AuthenticationApiClient extends defaultAuthenticationApiClient {
|
|
22
35
|
};
|
|
23
36
|
AuthenticationApiClient = __decorate([
|
|
@@ -2,8 +2,22 @@ import type { AsyncDisposable } from '../../disposable/index.js';
|
|
|
2
2
|
import { disposeAsync } from '../../disposable/index.js';
|
|
3
3
|
import type { AfterResolve } from '../../injector/index.js';
|
|
4
4
|
import { afterResolve } from '../../injector/index.js';
|
|
5
|
-
import type { Record } from '../../types.js';
|
|
5
|
+
import type { Record } from '../../types/index.js';
|
|
6
6
|
import type { SecretCheckResult, TokenPayload } from '../models/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Handles authentication on client side.
|
|
9
|
+
*
|
|
10
|
+
* Can be used to:
|
|
11
|
+
* - Login/logout
|
|
12
|
+
* - Refresh token
|
|
13
|
+
* - Impersonate/unimpersonate
|
|
14
|
+
* - Reset secret
|
|
15
|
+
* - Check secret
|
|
16
|
+
*
|
|
17
|
+
* @template AdditionalTokenPayload Type of additional token payload
|
|
18
|
+
* @template AuthenticationData Type of additional authentication data
|
|
19
|
+
* @template AdditionalInitSecretResetData Type of additional secret reset data
|
|
20
|
+
*/
|
|
7
21
|
export declare class AuthenticationClientService<AdditionalTokenPayload extends Record = Record, AuthenticationData = any, AdditionalInitSecretResetData = void> implements AfterResolve, AsyncDisposable {
|
|
8
22
|
private readonly client;
|
|
9
23
|
private readonly errorSubject;
|
|
@@ -13,44 +27,133 @@ export declare class AuthenticationClientService<AdditionalTokenPayload extends
|
|
|
13
27
|
private readonly lock;
|
|
14
28
|
private readonly logger;
|
|
15
29
|
private readonly disposeToken;
|
|
30
|
+
/**
|
|
31
|
+
* Observable for authentication errors.
|
|
32
|
+
* Emits when a refresh fails.
|
|
33
|
+
*/
|
|
16
34
|
readonly error$: import("rxjs").Observable<Error>;
|
|
35
|
+
/** Current token */
|
|
17
36
|
readonly token: import("../../signals/api.js").WritableSignal<TokenPayload<AdditionalTokenPayload> | undefined>;
|
|
37
|
+
/** Whether the user is logged in */
|
|
18
38
|
readonly isLoggedIn: import("../../signals/api.js").Signal<boolean>;
|
|
39
|
+
/** Current subject */
|
|
19
40
|
readonly subject: import("../../signals/api.js").Signal<string | undefined>;
|
|
41
|
+
/** Current session id */
|
|
20
42
|
readonly sessionId: import("../../signals/api.js").Signal<string | undefined>;
|
|
43
|
+
/** Current impersonator */
|
|
21
44
|
readonly impersonator: import("../../signals/api.js").Signal<string | undefined>;
|
|
45
|
+
/** Whether the user is impersonated */
|
|
22
46
|
readonly impersonated: import("../../signals/api.js").Signal<boolean>;
|
|
47
|
+
/** Current token */
|
|
23
48
|
readonly token$: import("rxjs").Observable<TokenPayload<AdditionalTokenPayload> | undefined>;
|
|
49
|
+
/** Emits when token is available (not undefined) */
|
|
24
50
|
readonly definedToken$: import("rxjs").Observable<Exclude<TokenPayload<AdditionalTokenPayload>, void | undefined>>;
|
|
51
|
+
/** Emits when a valid token is available (not undefined and not expired) */
|
|
25
52
|
readonly validToken$: import("rxjs").Observable<Exclude<TokenPayload<AdditionalTokenPayload>, void | undefined>>;
|
|
53
|
+
/** Current subject */
|
|
26
54
|
readonly subject$: import("rxjs").Observable<string | undefined>;
|
|
55
|
+
/** Emits when subject is available */
|
|
27
56
|
readonly definedSubject$: import("rxjs").Observable<string>;
|
|
57
|
+
/** Current session id */
|
|
28
58
|
readonly sessionId$: import("rxjs").Observable<string | undefined>;
|
|
59
|
+
/** Emits when session id is available */
|
|
29
60
|
readonly definedSessionId$: import("rxjs").Observable<string>;
|
|
61
|
+
/** Whether the user is logged in */
|
|
30
62
|
readonly isLoggedIn$: import("rxjs").Observable<boolean>;
|
|
63
|
+
/** Emits when the user logs out */
|
|
31
64
|
readonly loggedOut$: import("rxjs").Observable<void>;
|
|
32
65
|
private get authenticationData();
|
|
33
66
|
private set authenticationData(value);
|
|
34
67
|
private get impersonatorAuthenticationData();
|
|
35
68
|
private set impersonatorAuthenticationData(value);
|
|
69
|
+
/**
|
|
70
|
+
* Get current token or throw if not available
|
|
71
|
+
* @throws Will throw if token is not available
|
|
72
|
+
*/
|
|
36
73
|
get definedToken(): TokenPayload<AdditionalTokenPayload>;
|
|
74
|
+
/**
|
|
75
|
+
* Get current subject or throw if not available
|
|
76
|
+
* @throws Will throw if subject is not available
|
|
77
|
+
*/
|
|
37
78
|
get definedSubject(): string;
|
|
79
|
+
/**
|
|
80
|
+
* Get current session id or throw if not available
|
|
81
|
+
* @throws Will throw if session id is not available
|
|
82
|
+
*/
|
|
38
83
|
get definedSessionId(): string;
|
|
84
|
+
/** Whether a valid token is available (not undefined and not expired) */
|
|
39
85
|
get hasValidToken(): boolean;
|
|
40
86
|
constructor(initialAuthenticationData: AuthenticationData | undefined);
|
|
87
|
+
/** @internal */
|
|
41
88
|
[afterResolve](): void;
|
|
89
|
+
/**
|
|
90
|
+
* Initializes the service.
|
|
91
|
+
* Loads token from storage and starts refresh loop.
|
|
92
|
+
*
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
42
95
|
initialize(): void;
|
|
96
|
+
/** @internal */
|
|
43
97
|
[disposeAsync](): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Disposes the service.
|
|
100
|
+
* Stops refresh loop and completes subjects.
|
|
101
|
+
*/
|
|
44
102
|
dispose(): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Set additional authentication data
|
|
105
|
+
* @param data The data to set
|
|
106
|
+
*/
|
|
45
107
|
setAdditionalData(data: AuthenticationData): void;
|
|
108
|
+
/**
|
|
109
|
+
* Login with subject and secret
|
|
110
|
+
* @param subject The subject to login with
|
|
111
|
+
* @param secret The secret to login with
|
|
112
|
+
* @param data Additional authentication data
|
|
113
|
+
*/
|
|
46
114
|
login(subject: string, secret: string, data?: AuthenticationData): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Logout
|
|
117
|
+
*/
|
|
47
118
|
logout(): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Force a refresh of the token
|
|
121
|
+
* @param data Additional authentication data
|
|
122
|
+
*/
|
|
48
123
|
requestRefresh(data?: AuthenticationData): void;
|
|
124
|
+
/**
|
|
125
|
+
* Refresh the token
|
|
126
|
+
* @param data Additional authentication data
|
|
127
|
+
*/
|
|
49
128
|
refresh(data?: AuthenticationData): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Impersonate a subject
|
|
131
|
+
* @param subject The subject to impersonate
|
|
132
|
+
* @param data Additional authentication data
|
|
133
|
+
*/
|
|
50
134
|
impersonate(subject: string, data?: AuthenticationData): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Unimpersonate
|
|
137
|
+
* @param data Additional authentication data. If not provided, the data from before impersonation is used.
|
|
138
|
+
*/
|
|
51
139
|
unimpersonate(data?: AuthenticationData): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Initialize a secret reset
|
|
142
|
+
* @param subject The subject to reset the secret for
|
|
143
|
+
* @param data Additional data for secret reset
|
|
144
|
+
*/
|
|
52
145
|
initResetSecret(subject: string, data: AdditionalInitSecretResetData): Promise<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Reset a secret
|
|
148
|
+
* @param token The secret reset token
|
|
149
|
+
* @param newSecret The new secret
|
|
150
|
+
*/
|
|
53
151
|
resetSecret(token: string, newSecret: string): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* Check a secret for requirements
|
|
154
|
+
* @param secret The secret to check
|
|
155
|
+
* @returns The result of the check
|
|
156
|
+
*/
|
|
54
157
|
checkSecret(secret: string): Promise<SecretCheckResult>;
|
|
55
158
|
private saveToken;
|
|
56
159
|
private loadToken;
|
|
@@ -35,6 +35,20 @@ const tokenUpdateBusName = 'AuthenticationService:tokenUpdate';
|
|
|
35
35
|
const loggedOutBusName = 'AuthenticationService:loggedOut';
|
|
36
36
|
const refreshLockResource = 'AuthenticationService:refresh';
|
|
37
37
|
const localStorage = globalThis.localStorage;
|
|
38
|
+
/**
|
|
39
|
+
* Handles authentication on client side.
|
|
40
|
+
*
|
|
41
|
+
* Can be used to:
|
|
42
|
+
* - Login/logout
|
|
43
|
+
* - Refresh token
|
|
44
|
+
* - Impersonate/unimpersonate
|
|
45
|
+
* - Reset secret
|
|
46
|
+
* - Check secret
|
|
47
|
+
*
|
|
48
|
+
* @template AdditionalTokenPayload Type of additional token payload
|
|
49
|
+
* @template AuthenticationData Type of additional authentication data
|
|
50
|
+
* @template AdditionalInitSecretResetData Type of additional secret reset data
|
|
51
|
+
*/
|
|
38
52
|
let AuthenticationClientService = class AuthenticationClientService {
|
|
39
53
|
client = inject(AUTHENTICATION_API_CLIENT);
|
|
40
54
|
errorSubject = new Subject();
|
|
@@ -44,21 +58,40 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
44
58
|
lock = inject(Lock, refreshLockResource);
|
|
45
59
|
logger = inject(Logger, 'AuthenticationService');
|
|
46
60
|
disposeToken = new CancellationToken();
|
|
61
|
+
/**
|
|
62
|
+
* Observable for authentication errors.
|
|
63
|
+
* Emits when a refresh fails.
|
|
64
|
+
*/
|
|
47
65
|
error$ = this.errorSubject.asObservable();
|
|
66
|
+
/** Current token */
|
|
48
67
|
token = signal(undefined);
|
|
68
|
+
/** Whether the user is logged in */
|
|
49
69
|
isLoggedIn = computed(() => isDefined(this.token()));
|
|
70
|
+
/** Current subject */
|
|
50
71
|
subject = computed(() => this.token()?.subject);
|
|
72
|
+
/** Current session id */
|
|
51
73
|
sessionId = computed(() => this.token()?.sessionId);
|
|
74
|
+
/** Current impersonator */
|
|
52
75
|
impersonator = computed(() => this.token()?.impersonator);
|
|
76
|
+
/** Whether the user is impersonated */
|
|
53
77
|
impersonated = computed(() => isDefined(this.impersonator()));
|
|
78
|
+
/** Current token */
|
|
54
79
|
token$ = toObservable(this.token);
|
|
80
|
+
/** Emits when token is available (not undefined) */
|
|
55
81
|
definedToken$ = this.token$.pipe(filter(isDefined));
|
|
82
|
+
/** Emits when a valid token is available (not undefined and not expired) */
|
|
56
83
|
validToken$ = this.definedToken$.pipe(filter((token) => token.exp > currentTimestampSeconds()));
|
|
84
|
+
/** Current subject */
|
|
57
85
|
subject$ = toObservable(this.subject);
|
|
86
|
+
/** Emits when subject is available */
|
|
58
87
|
definedSubject$ = this.subject$.pipe(filter(isDefined));
|
|
88
|
+
/** Current session id */
|
|
59
89
|
sessionId$ = toObservable(this.sessionId);
|
|
90
|
+
/** Emits when session id is available */
|
|
60
91
|
definedSessionId$ = this.sessionId$.pipe(filter(isDefined));
|
|
92
|
+
/** Whether the user is logged in */
|
|
61
93
|
isLoggedIn$ = toObservable(this.isLoggedIn);
|
|
94
|
+
/** Emits when the user logs out */
|
|
62
95
|
loggedOut$ = this.loggedOutBus.allMessages$;
|
|
63
96
|
get authenticationData() {
|
|
64
97
|
const data = localStorage?.getItem(authenticationDataStorageKey);
|
|
@@ -86,15 +119,28 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
86
119
|
localStorage?.setItem(impersonatorAuthenticationDataStorageKey, json);
|
|
87
120
|
}
|
|
88
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Get current token or throw if not available
|
|
124
|
+
* @throws Will throw if token is not available
|
|
125
|
+
*/
|
|
89
126
|
get definedToken() {
|
|
90
127
|
return assertDefinedPass(this.token(), 'No token available.');
|
|
91
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Get current subject or throw if not available
|
|
131
|
+
* @throws Will throw if subject is not available
|
|
132
|
+
*/
|
|
92
133
|
get definedSubject() {
|
|
93
134
|
return this.definedToken.subject;
|
|
94
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Get current session id or throw if not available
|
|
138
|
+
* @throws Will throw if session id is not available
|
|
139
|
+
*/
|
|
95
140
|
get definedSessionId() {
|
|
96
141
|
return this.definedToken.sessionId;
|
|
97
142
|
}
|
|
143
|
+
/** Whether a valid token is available (not undefined and not expired) */
|
|
98
144
|
get hasValidToken() {
|
|
99
145
|
return (this.token()?.exp ?? 0) > currentTimestampSeconds();
|
|
100
146
|
}
|
|
@@ -103,26 +149,48 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
103
149
|
this.authenticationData = initialAuthenticationData;
|
|
104
150
|
}
|
|
105
151
|
}
|
|
152
|
+
/** @internal */
|
|
106
153
|
[afterResolve]() {
|
|
107
154
|
this.initialize();
|
|
108
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Initializes the service.
|
|
158
|
+
* Loads token from storage and starts refresh loop.
|
|
159
|
+
*
|
|
160
|
+
* @internal
|
|
161
|
+
*/
|
|
109
162
|
initialize() {
|
|
110
163
|
this.loadToken();
|
|
111
164
|
this.tokenUpdateBus.messages$.subscribe((token) => this.token.set(token));
|
|
112
165
|
void this.refreshLoop();
|
|
113
166
|
}
|
|
167
|
+
/** @internal */
|
|
114
168
|
async [disposeAsync]() {
|
|
115
169
|
await this.dispose();
|
|
116
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Disposes the service.
|
|
173
|
+
* Stops refresh loop and completes subjects.
|
|
174
|
+
*/
|
|
117
175
|
async dispose() {
|
|
118
176
|
this.disposeToken.set();
|
|
119
177
|
this.errorSubject.complete();
|
|
120
178
|
await this.loggedOutBus.dispose();
|
|
121
179
|
await this.tokenUpdateBus.dispose();
|
|
122
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Set additional authentication data
|
|
183
|
+
* @param data The data to set
|
|
184
|
+
*/
|
|
123
185
|
setAdditionalData(data) {
|
|
124
186
|
this.authenticationData = data;
|
|
125
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Login with subject and secret
|
|
190
|
+
* @param subject The subject to login with
|
|
191
|
+
* @param secret The secret to login with
|
|
192
|
+
* @param data Additional authentication data
|
|
193
|
+
*/
|
|
126
194
|
async login(subject, secret, data) {
|
|
127
195
|
if (isDefined(data)) {
|
|
128
196
|
this.setAdditionalData(data);
|
|
@@ -130,6 +198,9 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
130
198
|
const token = await this.client.getToken({ subject, secret, data: this.authenticationData });
|
|
131
199
|
this.setNewToken(token);
|
|
132
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Logout
|
|
203
|
+
*/
|
|
133
204
|
async logout() {
|
|
134
205
|
try {
|
|
135
206
|
await Promise.race([
|
|
@@ -142,12 +213,20 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
142
213
|
this.loggedOutBus.publishAndForget();
|
|
143
214
|
}
|
|
144
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Force a refresh of the token
|
|
218
|
+
* @param data Additional authentication data
|
|
219
|
+
*/
|
|
145
220
|
requestRefresh(data) {
|
|
146
221
|
if (isDefined(data)) {
|
|
147
222
|
this.setAdditionalData(data);
|
|
148
223
|
}
|
|
149
224
|
this.forceRefreshToken.set();
|
|
150
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Refresh the token
|
|
228
|
+
* @param data Additional authentication data
|
|
229
|
+
*/
|
|
151
230
|
async refresh(data) {
|
|
152
231
|
if (isDefined(data)) {
|
|
153
232
|
this.setAdditionalData(data);
|
|
@@ -161,6 +240,11 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
161
240
|
throw error;
|
|
162
241
|
}
|
|
163
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* Impersonate a subject
|
|
245
|
+
* @param subject The subject to impersonate
|
|
246
|
+
* @param data Additional authentication data
|
|
247
|
+
*/
|
|
164
248
|
async impersonate(subject, data) {
|
|
165
249
|
await this.lock.use(10000, true, async () => {
|
|
166
250
|
this.impersonatorAuthenticationData = this.authenticationData;
|
|
@@ -175,6 +259,10 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
175
259
|
}
|
|
176
260
|
});
|
|
177
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* Unimpersonate
|
|
264
|
+
* @param data Additional authentication data. If not provided, the data from before impersonation is used.
|
|
265
|
+
*/
|
|
178
266
|
async unimpersonate(data) {
|
|
179
267
|
await this.lock.use(10000, true, async () => {
|
|
180
268
|
const newData = data ?? this.impersonatorAuthenticationData;
|
|
@@ -190,12 +278,27 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
190
278
|
}
|
|
191
279
|
});
|
|
192
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* Initialize a secret reset
|
|
283
|
+
* @param subject The subject to reset the secret for
|
|
284
|
+
* @param data Additional data for secret reset
|
|
285
|
+
*/
|
|
193
286
|
async initResetSecret(subject, data) {
|
|
194
287
|
await this.client.initSecretReset({ subject, data });
|
|
195
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* Reset a secret
|
|
291
|
+
* @param token The secret reset token
|
|
292
|
+
* @param newSecret The new secret
|
|
293
|
+
*/
|
|
196
294
|
async resetSecret(token, newSecret) {
|
|
197
295
|
await this.client.resetSecret({ token, newSecret });
|
|
198
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Check a secret for requirements
|
|
299
|
+
* @param secret The secret to check
|
|
300
|
+
* @returns The result of the check
|
|
301
|
+
*/
|
|
199
302
|
async checkSecret(secret) {
|
|
200
303
|
return await this.client.checkSecret({ secret });
|
|
201
304
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { HttpClientMiddleware } from '../../http/client/middleware.js';
|
|
2
2
|
import { type ValueOrAsyncProvider } from '../../utils/value-or-provider.js';
|
|
3
3
|
import type { AuthenticationClientService } from './authentication.service.js';
|
|
4
|
+
/**
|
|
5
|
+
* A http client middleware that waits for a valid token before sending a request if the endpoint requires credentials.
|
|
6
|
+
* @param authenticationServiceOrProvider The authentication service or a provider for it.
|
|
7
|
+
* @returns A http client middleware.
|
|
8
|
+
*/
|
|
4
9
|
export declare function waitForAuthenticationCredentialsMiddleware(authenticationServiceOrProvider: ValueOrAsyncProvider<AuthenticationClientService>): HttpClientMiddleware;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { firstValueFrom } from 'rxjs';
|
|
2
2
|
import { cacheValueOrAsyncProvider } from '../../utils/value-or-provider.js';
|
|
3
3
|
import { dontWaitForValidToken } from '../authentication.api.js';
|
|
4
|
+
/**
|
|
5
|
+
* A http client middleware that waits for a valid token before sending a request if the endpoint requires credentials.
|
|
6
|
+
* @param authenticationServiceOrProvider The authentication service or a provider for it.
|
|
7
|
+
* @returns A http client middleware.
|
|
8
|
+
*/
|
|
4
9
|
export function waitForAuthenticationCredentialsMiddleware(authenticationServiceOrProvider) {
|
|
5
10
|
const getAuthenticationService = cacheValueOrAsyncProvider(authenticationServiceOrProvider);
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
7
11
|
async function waitForAuthenticationCredentialsMiddleware({ request }, next) {
|
|
8
12
|
const endpoint = request.context?.endpoint;
|
|
9
13
|
if ((endpoint?.credentials == true) && (endpoint.data?.[dontWaitForValidToken] != true)) {
|
|
@@ -12,7 +16,7 @@ export function waitForAuthenticationCredentialsMiddleware(authenticationService
|
|
|
12
16
|
await firstValueFrom(authenticationService.validToken$);
|
|
13
17
|
}
|
|
14
18
|
}
|
|
15
|
-
|
|
19
|
+
await next();
|
|
16
20
|
}
|
|
17
21
|
return waitForAuthenticationCredentialsMiddleware;
|
|
18
22
|
}
|