@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.
Files changed (251) hide show
  1. package/ai/ai-file.service.d.ts +29 -1
  2. package/ai/ai-file.service.js +66 -23
  3. package/ai/ai-session.d.ts +28 -1
  4. package/ai/ai-session.js +27 -0
  5. package/ai/ai.service.d.ts +89 -5
  6. package/ai/ai.service.js +130 -27
  7. package/ai/functions.d.ts +7 -1
  8. package/ai/functions.js +7 -1
  9. package/ai/module.d.ts +8 -0
  10. package/ai/module.js +4 -0
  11. package/ai/types.d.ts +115 -2
  12. package/ai/types.js +16 -0
  13. package/api/client/client.d.ts +1 -1
  14. package/api/client/client.js +1 -1
  15. package/api/default-error-handlers.d.ts +1 -1
  16. package/api/index.d.ts +1 -9
  17. package/api/index.js +1 -9
  18. package/api/response.d.ts +1 -1
  19. package/api/server/api-controller.d.ts +1 -1
  20. package/api/server/error-handler.d.ts +1 -1
  21. package/api/server/gateway.d.ts +1 -5
  22. package/api/server/gateway.js +0 -4
  23. package/api/server/middlewares/catch-error.middleware.d.ts +1 -1
  24. package/api/server/module.d.ts +1 -1
  25. package/api/types.d.ts +1 -1
  26. package/application/application.d.ts +1 -1
  27. package/authentication/authentication.api.d.ts +36 -1
  28. package/authentication/authentication.api.js +28 -0
  29. package/authentication/client/api.client.d.ts +14 -1
  30. package/authentication/client/api.client.js +13 -0
  31. package/authentication/client/authentication.service.d.ts +104 -1
  32. package/authentication/client/authentication.service.js +103 -0
  33. package/authentication/client/http-client.middleware.d.ts +5 -0
  34. package/authentication/client/http-client.middleware.js +6 -2
  35. package/authentication/client/module.d.ts +20 -1
  36. package/authentication/client/module.js +6 -1
  37. package/authentication/client/tokens.d.ts +6 -0
  38. package/authentication/client/tokens.js +6 -0
  39. package/authentication/models/authentication-credentials.model.d.ts +6 -0
  40. package/authentication/models/authentication-credentials.model.js +6 -0
  41. package/authentication/models/authentication-session.model.d.ts +6 -0
  42. package/authentication/models/authentication-session.model.js +6 -0
  43. package/authentication/models/init-secret-reset-data.model.d.ts +10 -1
  44. package/authentication/models/init-secret-reset-data.model.js +10 -1
  45. package/authentication/models/token-payload-base.model.d.ts +24 -4
  46. package/authentication/models/token-payload-base.model.js +24 -4
  47. package/authentication/models/token.model.d.ts +33 -2
  48. package/authentication/server/authentication-ancillary.service.d.ts +27 -4
  49. package/authentication/server/authentication-ancillary.service.js +7 -0
  50. package/authentication/server/authentication-api-request-token.provider.d.ts +3 -0
  51. package/authentication/server/authentication-api-request-token.provider.js +3 -0
  52. package/authentication/server/authentication-secret-requirements.validator.d.ts +37 -0
  53. package/authentication/server/authentication-secret-requirements.validator.js +22 -0
  54. package/authentication/server/authentication.api-controller.d.ts +66 -1
  55. package/authentication/server/authentication.api-controller.js +65 -0
  56. package/authentication/server/authentication.service.d.ts +191 -11
  57. package/authentication/server/authentication.service.js +157 -8
  58. package/authentication/server/helper.d.ts +44 -5
  59. package/authentication/server/helper.js +43 -4
  60. package/authentication/server/module.d.ts +23 -1
  61. package/authentication/server/module.js +23 -1
  62. package/browser/browser-context-controller.d.ts +1 -1
  63. package/browser/browser-controller.d.ts +1 -1
  64. package/browser/browser-controller.js +1 -1
  65. package/browser/element-controller.d.ts +1 -1
  66. package/browser/locator-controller.d.ts +1 -1
  67. package/context/context.d.ts +1 -1
  68. package/data-structures/context-data-map.d.ts +1 -1
  69. package/database/mongo/mongo-base.repository.d.ts +1 -1
  70. package/database/mongo/types.d.ts +1 -1
  71. package/database/query.d.ts +1 -1
  72. package/document-management/models/document-management-table.d.ts +1 -1
  73. package/document-management/models/document-validation-definition.model.d.ts +1 -1
  74. package/document-management/server/schemas.d.ts +1 -1
  75. package/document-management/server/services/document-collection.service.d.ts +1 -1
  76. package/document-management/server/services/document-management-observation.service.d.ts +1 -1
  77. package/document-management/server/services/document-management.service.d.ts +1 -1
  78. package/document-management/server/services/document-property.service.d.ts +3 -3
  79. package/document-management/server/services/document-request.service.d.ts +1 -1
  80. package/document-management/server/services/document-validation.service.d.ts +1 -1
  81. package/document-management/server/services/document-workflow.service.d.ts +1 -1
  82. package/document-management/server/services/document.service.d.ts +1 -1
  83. package/document-management/server/services/singleton.d.ts +1 -1
  84. package/document-management/service-models/document-management.view-model.d.ts +1 -1
  85. package/document-management/service-models/enriched/enriched-document-assignment.view.d.ts +1 -1
  86. package/document-management/service-models/enriched/enriched-document-category.view.d.ts +1 -1
  87. package/document-management/service-models/enriched/enriched-document-collection.view.d.ts +1 -1
  88. package/document-management/service-models/enriched/enriched-document-request.view.d.ts +1 -1
  89. package/document-management/service-models/enriched/enriched-document-type.view.d.ts +1 -1
  90. package/document-management/service-models/enriched/enriched-document.view.d.ts +1 -1
  91. package/document-management/service-models/enriched/enriched-requests-template-data.model.d.ts +1 -1
  92. package/dom/file-select-dialog.d.ts +1 -1
  93. package/enumeration/enumeration.d.ts +1 -1
  94. package/errors/custom.error.d.ts +3 -0
  95. package/errors/custom.error.js +0 -1
  96. package/errors/errors.localization.d.ts +1 -1
  97. package/errors/not-supported.error.d.ts +1 -1
  98. package/{formats.js → formats/formats.js} +3 -3
  99. package/formats/index.d.ts +1 -0
  100. package/formats/index.js +1 -0
  101. package/http/client/http-client-request.d.ts +1 -1
  102. package/http/client/http-client-response.d.ts +1 -1
  103. package/http/client/http-client.d.ts +1 -1
  104. package/http/client/module.d.ts +1 -1
  105. package/http/http-body.d.ts +1 -1
  106. package/http/http-value-map.d.ts +1 -1
  107. package/http/http.error.d.ts +1 -1
  108. package/http/server/http-server-request.d.ts +1 -1
  109. package/http/server/http-server-response.d.ts +1 -1
  110. package/http/types.d.ts +1 -1
  111. package/http/utils.d.ts +1 -1
  112. package/injector/decorators.d.ts +1 -1
  113. package/injector/index.d.ts +1 -1
  114. package/injector/index.js +1 -1
  115. package/injector/injector.d.ts +10 -1
  116. package/injector/injector.js +6 -0
  117. package/injector/interfaces.d.ts +1 -1
  118. package/injector/provider.d.ts +1 -1
  119. package/injector/resolution.d.ts +10 -5
  120. package/injector/resolve-chain.d.ts +2 -2
  121. package/injector/resolve-chain.js +1 -1
  122. package/injector/resolve.error.js +1 -1
  123. package/injector/token.d.ts +8 -1
  124. package/injector/token.js +7 -0
  125. package/injector/types.d.ts +1 -1
  126. package/key-value-store/key-value-store.provider.d.ts +2 -2
  127. package/key-value-store/key-value.store.d.ts +2 -2
  128. package/key-value-store/mongo/mongo-key-value-store.provider.d.ts +1 -1
  129. package/key-value-store/mongo/mongo-key-value.store.d.ts +1 -1
  130. package/key-value-store/postgres/key-value-store.service.d.ts +1 -1
  131. package/mail/mail.service.d.ts +1 -1
  132. package/mail/models/mail-data.model.d.ts +1 -1
  133. package/mail/models/mail-template.model.d.ts +1 -1
  134. package/mail/module.d.ts +1 -1
  135. package/module/index.d.ts +0 -1
  136. package/module/index.js +0 -1
  137. package/module/module-base.d.ts +1 -1
  138. package/module/module-metric-reporter.js +1 -1
  139. package/module/module.d.ts +1 -1
  140. package/module/modules/function.module.js +1 -1
  141. package/object-storage/object.d.ts +1 -1
  142. package/openid-connect/mongo-oidc-state.repository.d.ts +1 -1
  143. package/openid-connect/oidc.service.d.ts +1 -1
  144. package/orm/decorators.d.ts +2 -2
  145. package/orm/entity.d.ts +1 -1
  146. package/orm/index.d.ts +3 -3
  147. package/orm/index.js +3 -3
  148. package/orm/query.d.ts +1 -1
  149. package/orm/repository.types.d.ts +1 -1
  150. package/orm/schemas/json.d.ts +1 -1
  151. package/orm/server/database-schema.d.ts +1 -1
  152. package/orm/server/drizzle/schema-converter.d.ts +1 -1
  153. package/orm/server/repository.d.ts +1 -1
  154. package/orm/server/transaction.d.ts +1 -1
  155. package/orm/server/transactional.d.ts +3 -3
  156. package/orm/server/types.d.ts +1 -1
  157. package/orm/types.d.ts +1 -1
  158. package/package.json +23 -20
  159. package/queue/mongo/job.d.ts +1 -1
  160. package/queue/mongo/queue.js +31 -31
  161. package/queue/postgres/job.model.d.ts +1 -1
  162. package/queue/postgres/queue.d.ts +1 -1
  163. package/queue/postgres/queue.provider.d.ts +1 -1
  164. package/queue/provider.d.ts +1 -1
  165. package/reflection/decorators.d.ts +1 -1
  166. package/reflection/registry.d.ts +1 -1
  167. package/reflection/types.d.ts +1 -1
  168. package/reflection/utils.d.ts +1 -1
  169. package/rpc/model.d.ts +1 -1
  170. package/rxjs-utils/retry-backoff.js +2 -2
  171. package/schema/converters/openapi-converter.d.ts +1 -1
  172. package/schema/decorators/schema.d.ts +1 -1
  173. package/schema/decorators/utils.d.ts +1 -1
  174. package/schema/schema.d.ts +1 -1
  175. package/schema/schema.error.d.ts +1 -1
  176. package/schema/schemas/array.d.ts +1 -1
  177. package/schema/schemas/enumeration.d.ts +1 -1
  178. package/schema/schemas/function.d.ts +1 -1
  179. package/schema/schemas/instance.d.ts +1 -1
  180. package/schema/schemas/nullable.d.ts +1 -1
  181. package/schema/schemas/number.d.ts +1 -1
  182. package/schema/schemas/object.d.ts +1 -1
  183. package/schema/schemas/one-or-many.d.ts +1 -1
  184. package/schema/schemas/optional.d.ts +1 -1
  185. package/schema/schemas/simple.d.ts +1 -1
  186. package/search-index/elastic/model/index-mapping.d.ts +1 -1
  187. package/search-index/elastic/search-index.js +3 -4
  188. package/search-index/memory/memory-search-index.d.ts +1 -1
  189. package/search-index/memory/memory-search-index.js +1 -1
  190. package/serializer/handlers/binary.d.ts +1 -1
  191. package/serializer/serializable.d.ts +1 -1
  192. package/serializer/types.d.ts +1 -1
  193. package/templates/module.d.ts +1 -1
  194. package/templates/renderers/handlebars.template-renderer.d.ts +1 -1
  195. package/templates/renderers/jsx.template-renderer.d.ts +1 -1
  196. package/templates/renderers/mjml.template-renderer.d.ts +1 -1
  197. package/templates/renderers/string.template-renderer.d.ts +1 -1
  198. package/templates/resolvers/file.template-resolver.d.ts +1 -1
  199. package/templates/resolvers/jsx.template-resolver.d.ts +1 -1
  200. package/templates/resolvers/string.template-resolver.d.ts +1 -1
  201. package/templates/template.model.d.ts +1 -1
  202. package/templates/template.renderer.d.ts +1 -1
  203. package/templates/template.service.d.ts +1 -1
  204. package/text/dynamic-text.model.d.ts +1 -1
  205. package/text/localization.service.d.ts +1 -1
  206. package/types/geo-json.d.ts +1 -1
  207. package/types/index.d.ts +2 -0
  208. package/types/tagged.d.ts +1 -1
  209. package/{types.d.ts → types/types.d.ts} +2 -1
  210. package/utils/async-hook/async-hook.d.ts +109 -0
  211. package/utils/async-hook/async-hook.js +77 -3
  212. package/utils/backoff.d.ts +125 -43
  213. package/utils/backoff.js +140 -65
  214. package/utils/base64.d.ts +1 -1
  215. package/utils/base64.js +1 -2
  216. package/utils/binary.d.ts +1 -1
  217. package/utils/comparison.d.ts +5 -5
  218. package/utils/comparison.js +5 -3
  219. package/utils/cryptography.d.ts +1 -1
  220. package/utils/encoding.d.ts +1 -1
  221. package/utils/enum.d.ts +1 -1
  222. package/utils/equals.d.ts +1 -1
  223. package/utils/format-error.d.ts +1 -1
  224. package/utils/function/class.d.ts +1 -1
  225. package/utils/function/memoize.d.ts +1 -1
  226. package/utils/helpers.d.ts +1 -1
  227. package/utils/helpers.js +2 -2
  228. package/utils/jwt.d.ts +3 -3
  229. package/utils/merge.d.ts +1 -1
  230. package/utils/middleware.js +3 -3
  231. package/utils/object/decycle.d.ts +1 -1
  232. package/utils/object/forward-ref.d.ts +1 -1
  233. package/utils/object/lazy-property.d.ts +1 -1
  234. package/utils/object/object.d.ts +1 -1
  235. package/utils/object/property-name.d.ts +1 -1
  236. package/utils/patch-worker.d.ts +1 -1
  237. package/utils/reactive-value-to-signal.d.ts +1 -1
  238. package/utils/reflection.d.ts +1 -1
  239. package/utils/repl.d.ts +1 -1
  240. package/utils/singleton.d.ts +1 -1
  241. package/utils/stream/size-limited-stream.d.ts +1 -1
  242. package/utils/type/extends.d.ts +1 -1
  243. package/utils/type-guards.d.ts +1 -1
  244. package/utils/url-builder.d.ts +1 -1
  245. package/utils/z-base32.d.ts +1 -1
  246. package/module/utils.d.ts +0 -4
  247. package/module/utils.js +0 -21
  248. /package/{formats.d.ts → formats/formats.d.ts} +0 -0
  249. /package/{types.js → types/types.js} +0 -0
  250. /package/{web-types.d.ts → types/web-types.d.ts} +0 -0
  251. /package/{web-types.js → types/web-types.js} +0 -0
@@ -1,10 +1,29 @@
1
1
  import type { ApiClientImplementation } from '../../api/index.js';
2
2
  import { Injector } from '../../injector/injector.js';
3
- import type { Type } from '../../types.js';
3
+ import type { Type } from '../../types/index.js';
4
4
  import type { AuthenticationApiDefinition } from '../authentication.api.js';
5
+ /**
6
+ * Configuration for {@link configureAuthenticationClient}
7
+ */
5
8
  export type AuthenticationClientModuleConfig = {
9
+ /**
10
+ * Optional custom authentication api client
11
+ */
6
12
  authenticationApiClient?: Type<ApiClientImplementation<AuthenticationApiDefinition<any, any, any>>>;
13
+ /**
14
+ * Optional initial authentication data
15
+ */
7
16
  initialAuthenticationData?: unknown;
17
+ /**
18
+ * Whether to register the {@link waitForAuthenticationCredentialsMiddleware} for all http clients.
19
+ *
20
+ * @default false
21
+ */
8
22
  registerMiddleware?: boolean;
9
23
  };
24
+ /**
25
+ * Configures authentication client services.
26
+ * @param config Configuration
27
+ * @param injector The injector to use. If not provided, the current injector is used.
28
+ */
10
29
  export declare function configureAuthenticationClient(config: AuthenticationClientModuleConfig, injector?: Injector | null): void;
@@ -5,6 +5,11 @@ import { isDefined } from '../../utils/type-guards.js';
5
5
  import { AuthenticationClientService } from './authentication.service.js';
6
6
  import { waitForAuthenticationCredentialsMiddleware } from './http-client.middleware.js';
7
7
  import { AUTHENTICATION_API_CLIENT, INITIAL_AUTHENTICATION_DATA } from './tokens.js';
8
+ /**
9
+ * Configures authentication client services.
10
+ * @param config Configuration
11
+ * @param injector The injector to use. If not provided, the current injector is used.
12
+ */
8
13
  export function configureAuthenticationClient(config, injector = getCurrentInjector()) {
9
14
  if (isDefined(config.authenticationApiClient)) {
10
15
  (injector ?? Injector).registerSingleton(AUTHENTICATION_API_CLIENT, { useToken: config.authenticationApiClient });
@@ -17,7 +22,7 @@ export function configureAuthenticationClient(config, injector = getCurrentInjec
17
22
  useFactory(_, context) {
18
23
  const authenticationService = context.resolve(AuthenticationClientService, undefined, { forwardRef: true, forwardRefTypeHint: 'object' });
19
24
  return waitForAuthenticationCredentialsMiddleware(authenticationService);
20
- }
25
+ },
21
26
  }, { multi: true });
22
27
  }
23
28
  }
@@ -1,4 +1,10 @@
1
1
  import type { ApiClientImplementation } from '../../api/index.js';
2
2
  import type { AuthenticationApiDefinition } from '../authentication.api.js';
3
+ /**
4
+ * Injection token for {@link AuthenticationApiClient}
5
+ */
3
6
  export declare const AUTHENTICATION_API_CLIENT: import("../../injector/token.js").InjectionToken<ApiClientImplementation<AuthenticationApiDefinition<any, any, any>>, never>;
7
+ /**
8
+ * Injection token for initial authentication data
9
+ */
4
10
  export declare const INITIAL_AUTHENTICATION_DATA: import("../../injector/token.js").InjectionToken<unknown, never>;
@@ -1,6 +1,12 @@
1
1
  import { Injector } from '../../injector/injector.js';
2
2
  import { injectionToken } from '../../injector/token.js';
3
3
  import { AuthenticationApiClient } from './api.client.js';
4
+ /**
5
+ * Injection token for {@link AuthenticationApiClient}
6
+ */
4
7
  export const AUTHENTICATION_API_CLIENT = injectionToken('ApiClientImplementation');
8
+ /**
9
+ * Injection token for initial authentication data
10
+ */
5
11
  export const INITIAL_AUTHENTICATION_DATA = injectionToken('initial authentication data');
6
12
  Injector.registerSingleton(AUTHENTICATION_API_CLIENT, { useToken: AuthenticationApiClient });
@@ -2,6 +2,12 @@ import { Entity } from '../../orm/index.js';
2
2
  export declare class AuthenticationCredentials extends Entity {
3
3
  subject: string;
4
4
  hashVersion: number;
5
+ /**
6
+ * The salt used to hash the secret.
7
+ */
5
8
  salt: Uint8Array;
9
+ /**
10
+ * The hashed secret.
11
+ */
6
12
  hash: Uint8Array;
7
13
  }
@@ -13,7 +13,13 @@ import { Integer, StringProperty, Uint8ArrayProperty } from '../../schema/index.
13
13
  let AuthenticationCredentials = class AuthenticationCredentials extends Entity {
14
14
  subject;
15
15
  hashVersion;
16
+ /**
17
+ * The salt used to hash the secret.
18
+ */
16
19
  salt;
20
+ /**
21
+ * The hashed secret.
22
+ */
17
23
  hash;
18
24
  };
19
25
  __decorate([
@@ -5,6 +5,12 @@ export declare class AuthenticationSession extends Entity {
5
5
  begin: Timestamp;
6
6
  end: Timestamp;
7
7
  refreshTokenHashVersion: number;
8
+ /**
9
+ * The salt used to hash the refresh token.
10
+ */
8
11
  refreshTokenSalt: Uint8Array;
12
+ /**
13
+ * The hashed refresh token.
14
+ */
9
15
  refreshTokenHash: Uint8Array;
10
16
  }
@@ -16,7 +16,13 @@ let AuthenticationSession = class AuthenticationSession extends Entity {
16
16
  begin;
17
17
  end;
18
18
  refreshTokenHashVersion;
19
+ /**
20
+ * The salt used to hash the refresh token.
21
+ */
19
22
  refreshTokenSalt;
23
+ /**
24
+ * The hashed refresh token.
25
+ */
20
26
  refreshTokenHash;
21
27
  };
22
28
  __decorate([
@@ -1,5 +1,14 @@
1
+ /**
2
+ * Data for initializing a secret reset.
3
+ */
1
4
  export declare class InitSecretResetData {
2
- /** Subject is not checked for existence. */
5
+ /**
6
+ * The subject for which to reset the secret.
7
+ * Note: The existence of the subject is not checked to avoid data leaks.
8
+ */
3
9
  subject: string;
10
+ /**
11
+ * The secret reset token.
12
+ */
4
13
  token: string;
5
14
  }
@@ -8,9 +8,18 @@ var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
10
  import { StringProperty } from '../../schema/index.js';
11
+ /**
12
+ * Data for initializing a secret reset.
13
+ */
11
14
  export class InitSecretResetData {
12
- /** Subject is not checked for existence. */
15
+ /**
16
+ * The subject for which to reset the secret.
17
+ * Note: The existence of the subject is not checked to avoid data leaks.
18
+ */
13
19
  subject;
20
+ /**
21
+ * The secret reset token.
22
+ */
14
23
  token;
15
24
  }
16
25
  __decorate([
@@ -1,13 +1,33 @@
1
+ /**
2
+ * Base for token payloads.
3
+ */
1
4
  export declare class TokenPayloadBase {
2
- /** Token id */
5
+ /**
6
+ * Token id.
7
+ */
3
8
  jti: string;
4
- /** Issue timestamp in seconds */
9
+ /**
10
+ * Issue timestamp in seconds.
11
+ */
5
12
  iat: number;
6
- /** Expiration timestamp in seconds */
13
+ /**
14
+ * Expiration timestamp in seconds.
15
+ */
7
16
  exp: number;
8
- /** Refresh token expiration timestamp in seconds */
17
+ /**
18
+ * Refresh token expiration timestamp in seconds.
19
+ */
9
20
  refreshTokenExp: number;
21
+ /**
22
+ * The id of the session.
23
+ */
10
24
  sessionId: string;
25
+ /**
26
+ * The subject of the token.
27
+ */
11
28
  subject: string;
29
+ /**
30
+ * The subject of the impersonator, if any.
31
+ */
12
32
  impersonator?: string;
13
33
  }
@@ -8,17 +8,37 @@ var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
10
  import { NumberProperty, StringProperty } from '../../schema/index.js';
11
+ /**
12
+ * Base for token payloads.
13
+ */
11
14
  export class TokenPayloadBase {
12
- /** Token id */
15
+ /**
16
+ * Token id.
17
+ */
13
18
  jti;
14
- /** Issue timestamp in seconds */
19
+ /**
20
+ * Issue timestamp in seconds.
21
+ */
15
22
  iat;
16
- /** Expiration timestamp in seconds */
23
+ /**
24
+ * Expiration timestamp in seconds.
25
+ */
17
26
  exp;
18
- /** Refresh token expiration timestamp in seconds */
27
+ /**
28
+ * Refresh token expiration timestamp in seconds.
29
+ */
19
30
  refreshTokenExp;
31
+ /**
32
+ * The id of the session.
33
+ */
20
34
  sessionId;
35
+ /**
36
+ * The subject of the token.
37
+ */
21
38
  subject;
39
+ /**
40
+ * The subject of the impersonator, if any.
41
+ */
22
42
  impersonator;
23
43
  }
24
44
  __decorate([
@@ -1,20 +1,51 @@
1
- import type { Record } from '../../types.js';
1
+ import type { Record } from '../../types/index.js';
2
2
  import type { JwtToken, JwtTokenHeader } from '../../utils/jwt.js';
3
3
  import type { TokenPayloadBase } from './token-payload-base.model.js';
4
4
  export type TokenHeader = {
5
+ /**
6
+ * Token version.
7
+ */
5
8
  v: number;
6
9
  };
10
+ /**
11
+ * JWT token with custom header.
12
+ * @template AdditionalTokenPayload The type of the additional token payload.
13
+ */
7
14
  export type Token<AdditionalTokenPayload extends Record = Record<never>> = JwtToken<TokenPayload<AdditionalTokenPayload>, JwtTokenHeader<TokenHeader>>;
15
+ /**
16
+ * Token payload.
17
+ * @template T The type of the additional token payload.
18
+ */
8
19
  export type TokenPayload<T extends Record = Record<never>> = T & TokenPayloadBase;
9
20
  export type RefreshToken = JwtToken<{
10
- /** expiration timestamp in seconds */
21
+ /**
22
+ * Expiration timestamp in seconds.
23
+ */
11
24
  exp: number;
25
+ /**
26
+ * The subject of the token.
27
+ */
12
28
  subject: string;
29
+ /**
30
+ * The subject of the impersonator, if any.
31
+ */
13
32
  impersonator?: string;
33
+ /**
34
+ * The id of the session.
35
+ */
14
36
  sessionId: string;
37
+ /**
38
+ * The secret to use for refreshing the token.
39
+ */
15
40
  secret: string;
16
41
  }>;
17
42
  export type SecretResetToken = JwtToken<{
43
+ /**
44
+ * Expiration timestamp in seconds.
45
+ */
18
46
  exp: number;
47
+ /**
48
+ * The subject for which to reset the secret.
49
+ */
19
50
  subject: string;
20
51
  }>;
@@ -1,5 +1,5 @@
1
1
  import { type EnumType } from '../../enumeration/enumeration.js';
2
- import type { Record } from '../../types.js';
2
+ import type { Record } from '../../types/index.js';
3
3
  import type { TokenPayload } from '../index.js';
4
4
  import type { InitSecretResetData } from '../models/init-secret-reset-data.model.js';
5
5
  export declare const GetTokenPayloadContextAction: {
@@ -8,6 +8,9 @@ export declare const GetTokenPayloadContextAction: {
8
8
  };
9
9
  export type GetTokenPayloadContextAction = EnumType<typeof GetTokenPayloadContextAction>;
10
10
  export type GetTokenPayloadContext = {
11
+ /**
12
+ * The action that triggered the token payload retrieval.
13
+ */
11
14
  action: GetTokenPayloadContextAction;
12
15
  };
13
16
  export type ResolveSubjectResult = {
@@ -17,6 +20,13 @@ export type ResolveSubjectResult = {
17
20
  success: false;
18
21
  subject?: undefined;
19
22
  };
23
+ /**
24
+ * Ancillary service for authentication to hook into the authentication process.
25
+ *
26
+ * @param AdditionalTokenPayload Type of additional token payload
27
+ * @param AuthenticationData Type of additional authentication data
28
+ * @param AdditionalInitSecretResetData Type of additional secret reset data
29
+ */
20
30
  export declare abstract class AuthenticationAncillaryService<AdditionalTokenPayload extends Record = Record<never>, AuthenticationData = void, AdditionalInitSecretResetData = void> {
21
31
  /**
22
32
  * Resolve a provided subject to the actual subject used for authentication.
@@ -26,12 +36,25 @@ export declare abstract class AuthenticationAncillaryService<AdditionalTokenPayl
26
36
  * If the subject cannot be resolved, return an object with success set to false.
27
37
  */
28
38
  abstract resolveSubject(providedSubject: string): ResolveSubjectResult | Promise<ResolveSubjectResult>;
39
+ /**
40
+ * Get the additional token payload for a subject.
41
+ * @param subject The subject for which to get the payload.
42
+ * @param authenticationData Additional authentication data.
43
+ * @param context Context for getting the token payload.
44
+ * @returns The additional token payload.
45
+ */
29
46
  abstract getTokenPayload(subject: string, authenticationData: AuthenticationData, context: GetTokenPayloadContext): AdditionalTokenPayload | Promise<AdditionalTokenPayload>;
47
+ /**
48
+ * Handle the initialization of a secret reset.
49
+ * @param data Data for initializing the secret reset.
50
+ */
30
51
  abstract handleInitSecretReset(data: InitSecretResetData & AdditionalInitSecretResetData): void | Promise<void>;
31
52
  /**
32
- * Check if token is allowed to impersonate subject
33
- * @param token Token which tries to impersonate
34
- * @param subject Subject to impersonate
53
+ * Check if token is allowed to impersonate subject.
54
+ * @param token Token which tries to impersonate.
55
+ * @param subject Subject to impersonate.
56
+ * @param authenticationData Additional authentication data.
57
+ * @returns Whether impersonation is allowed.
35
58
  */
36
59
  abstract canImpersonate(token: TokenPayload<AdditionalTokenPayload>, subject: string, authenticationData: AuthenticationData): boolean | Promise<boolean>;
37
60
  }
@@ -3,5 +3,12 @@ export const GetTokenPayloadContextAction = defineEnum('GetTokenPayloadContextAc
3
3
  GetToken: 'get-token',
4
4
  Refresh: 'refresh',
5
5
  });
6
+ /**
7
+ * Ancillary service for authentication to hook into the authentication process.
8
+ *
9
+ * @param AdditionalTokenPayload Type of additional token payload
10
+ * @param AuthenticationData Type of additional authentication data
11
+ * @param AdditionalInitSecretResetData Type of additional secret reset data
12
+ */
6
13
  export class AuthenticationAncillaryService {
7
14
  }
@@ -1,6 +1,9 @@
1
1
  import type { ApiRequestData } from '../../api/index.js';
2
2
  import { ApiRequestTokenProvider } from '../../api/server/api-request-token.provider.js';
3
3
  import { AuthenticationService } from './authentication.service.js';
4
+ /**
5
+ * Provides the token for an API request from the authorization header.
6
+ */
4
7
  export declare class AuthenticationApiRequestTokenProvider extends ApiRequestTokenProvider {
5
8
  private readonly authenticationService;
6
9
  constructor(authenticationService: AuthenticationService);
@@ -11,6 +11,9 @@ import { ApiRequestTokenProvider } from '../../api/server/api-request-token.prov
11
11
  import { Singleton } from '../../injector/decorators.js';
12
12
  import { AuthenticationService } from './authentication.service.js';
13
13
  import { tryGetAuthorizationTokenStringFromRequest } from './helper.js';
14
+ /**
15
+ * Provides the token for an API request from the authorization header.
16
+ */
14
17
  let AuthenticationApiRequestTokenProvider = class AuthenticationApiRequestTokenProvider extends ApiRequestTokenProvider {
15
18
  authenticationService;
16
19
  constructor(authenticationService) {
@@ -7,12 +7,49 @@ export type SecretTestResult = {
7
7
  reason: string;
8
8
  };
9
9
  export declare abstract class AuthenticationSecretRequirementsValidator {
10
+ /**
11
+ * Checks the secret against the requirements.
12
+ * @param secret The secret to check.
13
+ * @returns The result of the check.
14
+ */
10
15
  abstract checkSecretRequirements(secret: string): Promise<SecretCheckResult>;
16
+ /**
17
+ * Tests the secret against the requirements.
18
+ * @param secret The secret to test.
19
+ * @returns The result of the test.
20
+ */
11
21
  abstract testSecretRequirements(secret: string): Promise<SecretTestResult>;
22
+ /**
23
+ * Validates the secret against the requirements. Throws an error if the requirements are not met.
24
+ * @param secret The secret to validate.
25
+ * @throws {SecretRequirementsError} If the secret does not meet the requirements.
26
+ */
12
27
  abstract validateSecretRequirements(secret: string): Promise<void>;
13
28
  }
29
+ /**
30
+ * Default validator for secret requirements.
31
+ *
32
+ * Checks for pwned passwords and password strength.
33
+ * - Pwned passwords are not allowed.
34
+ * - Password strength must be at least 'medium'.
35
+ */
14
36
  export declare class DefaultAuthenticationSecretRequirementsValidator extends AuthenticationSecretRequirementsValidator {
37
+ /**
38
+ * Checks the secret against the requirements.
39
+ * @param secret The secret to check.
40
+ * @returns The result of the check.
41
+ */
15
42
  checkSecretRequirements(secret: string): Promise<SecretCheckResult>;
43
+ /**
44
+ * Tests the secret against the requirements.
45
+ * @param secret The secret to test.
46
+ * @returns The result of the test.
47
+ */
16
48
  testSecretRequirements(secret: string): Promise<SecretTestResult>;
49
+ /**
50
+ * Validates the secret against the requirements. Throws an error if the requirements are not met.
51
+ * @param secret The secret to validate.
52
+ * @throws {SecretRequirementsError} If the secret does not meet the requirements.
53
+ */
17
54
  validateSecretRequirements(secret: string): Promise<void>;
18
55
  }
@@ -11,10 +11,27 @@ import { isNumber } from '../../utils/type-guards.js';
11
11
  import { SecretRequirementsError } from '../errors/secret-requirements.error.js';
12
12
  export class AuthenticationSecretRequirementsValidator {
13
13
  }
14
+ /**
15
+ * Default validator for secret requirements.
16
+ *
17
+ * Checks for pwned passwords and password strength.
18
+ * - Pwned passwords are not allowed.
19
+ * - Password strength must be at least 'medium'.
20
+ */
14
21
  let DefaultAuthenticationSecretRequirementsValidator = class DefaultAuthenticationSecretRequirementsValidator extends AuthenticationSecretRequirementsValidator {
22
+ /**
23
+ * Checks the secret against the requirements.
24
+ * @param secret The secret to check.
25
+ * @returns The result of the check.
26
+ */
15
27
  async checkSecretRequirements(secret) {
16
28
  return await checkPassword(secret, { checkForPwned: true });
17
29
  }
30
+ /**
31
+ * Tests the secret against the requirements.
32
+ * @param secret The secret to test.
33
+ * @returns The result of the test.
34
+ */
18
35
  async testSecretRequirements(secret) {
19
36
  const result = await this.checkSecretRequirements(secret);
20
37
  if (isNumber(result.pwned) && (result.pwned > 0)) {
@@ -25,6 +42,11 @@ let DefaultAuthenticationSecretRequirementsValidator = class DefaultAuthenticati
25
42
  }
26
43
  return { success: true };
27
44
  }
45
+ /**
46
+ * Validates the secret against the requirements. Throws an error if the requirements are not met.
47
+ * @param secret The secret to validate.
48
+ * @throws {SecretRequirementsError} If the secret does not meet the requirements.
49
+ */
28
50
  async validateSecretRequirements(secret) {
29
51
  const result = await this.testSecretRequirements(secret);
30
52
  if (!result.success) {
@@ -1,23 +1,88 @@
1
1
  import type { ApiController, ApiRequestContext, ApiServerResult } from '../../api/types.js';
2
2
  import { HttpServerResponse } from '../../http/server/index.js';
3
3
  import type { ObjectSchemaOrType, SchemaTestable } from '../../schema/index.js';
4
- import type { Record, Type } from '../../types.js';
4
+ import type { Record, Type } from '../../types/index.js';
5
5
  import type { AuthenticationApiDefinition } from '../authentication.api.js';
6
6
  import type { TokenResult } from './authentication.service.js';
7
7
  import { AuthenticationService } from './authentication.service.js';
8
+ /**
9
+ * API controller for authentication.
10
+ *
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
+ */
8
15
  export declare class AuthenticationApiController<AdditionalTokenPayload extends Record, AuthenticationData, AdditionalInitSecretResetData = void> implements ApiController<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>> {
9
16
  readonly authenticationService: AuthenticationService<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>;
10
17
  constructor(authenticationService: AuthenticationService<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>);
18
+ /**
19
+ * Get a token for a subject and secret.
20
+ * @param parameters The parameters for the request.
21
+ * @returns The token result.
22
+ * @throws {InvalidCredentialsError} If the credentials are invalid.
23
+ */
11
24
  getToken({ parameters }: ApiRequestContext<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'getToken'>): Promise<ApiServerResult<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'getToken'>>;
25
+ /**
26
+ * Refresh a token.
27
+ * @param request The request context.
28
+ * @param parameters The parameters for the request.
29
+ * @returns The token result.
30
+ */
12
31
  refresh({ request, parameters }: ApiRequestContext<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'refresh'>): Promise<ApiServerResult<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'refresh'>>;
32
+ /**
33
+ * Impersonate a subject.
34
+ * @param request The request context.
35
+ * @param parameters The parameters for the request.
36
+ * @returns The token result.
37
+ */
13
38
  impersonate({ request, parameters }: ApiRequestContext<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'impersonate'>): Promise<ApiServerResult<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'impersonate'>>;
39
+ /**
40
+ * Unimpersonate a subject.
41
+ * @param request The request context.
42
+ * @param parameters The parameters for the request.
43
+ * @returns The token result.
44
+ */
14
45
  unimpersonate({ request, parameters }: ApiRequestContext<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'unimpersonate'>): Promise<ApiServerResult<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'unimpersonate'>>;
46
+ /**
47
+ * End a session.
48
+ * @param request The request context.
49
+ * @returns 'ok' if the session was ended.
50
+ */
15
51
  endSession({ request }: ApiRequestContext<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'endSession'>): Promise<ApiServerResult<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'endSession'>>;
52
+ /**
53
+ * Initialize a secret reset.
54
+ * @param parameters The parameters for the request.
55
+ * @returns 'ok' if the secret reset was initialized.
56
+ */
16
57
  initSecretReset({ parameters }: ApiRequestContext<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'initSecretReset'>): Promise<ApiServerResult<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'initSecretReset'>>;
58
+ /**
59
+ * Reset a secret.
60
+ * @param parameters The parameters for the request.
61
+ * @returns 'ok' if the secret was reset.
62
+ */
17
63
  resetSecret({ parameters }: ApiRequestContext<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'resetSecret'>): Promise<ApiServerResult<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'resetSecret'>>;
64
+ /**
65
+ * Check a secret.
66
+ * @param parameters The parameters for the request.
67
+ * @returns The result of the secret check.
68
+ */
18
69
  checkSecret({ parameters }: ApiRequestContext<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'checkSecret'>): Promise<ApiServerResult<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'checkSecret'>>;
70
+ /**
71
+ * Get the current server timestamp.
72
+ * @returns The current server timestamp.
73
+ */
19
74
  timestamp(): ApiServerResult<AuthenticationApiDefinition<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>, 'timestamp'>;
20
75
  protected getTokenResponse({ token, jsonToken, refreshToken, omitImpersonatorRefreshToken, impersonatorRefreshToken, impersonatorRefreshTokenExpiration }: TokenResult<AdditionalTokenPayload>): HttpServerResponse;
21
76
  }
77
+ /**
78
+ * Get an authentication API controller.
79
+ * @param additionalTokenPayloadSchema Schema for additional token payload.
80
+ * @param authenticationDataSchema Schema for additional authentication data.
81
+ * @param additionalInitSecretResetData Schema for additional secret reset data.
82
+ * @returns An authentication API controller.
83
+ * @template AdditionalTokenPayload Type of additional token payload.
84
+ * @template AuthenticationData Type of additional authentication data.
85
+ * @template AdditionalInitSecretResetData Type of additional secret reset data.
86
+ */
22
87
  export declare function getAuthenticationApiController<AdditionalTokenPayload extends Record, AuthenticationData, AdditionalInitSecretResetData = void>(// eslint-disable-line @typescript-eslint/explicit-function-return-type
23
88
  additionalTokenPayloadSchema: ObjectSchemaOrType<AdditionalTokenPayload>, authenticationDataSchema: SchemaTestable<AuthenticationData>, additionalInitSecretResetData: SchemaTestable<AdditionalInitSecretResetData>): Type<AuthenticationApiController<AdditionalTokenPayload, AuthenticationData, AdditionalInitSecretResetData>>;