@tstdl/base 0.92.50 → 0.92.51

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 (41) hide show
  1. package/authentication/models/authentication-credentials.model.d.ts +2 -8
  2. package/authentication/models/authentication-credentials.model.js +5 -30
  3. package/authentication/models/authentication-session.model.d.ts +5 -14
  4. package/authentication/models/authentication-session.model.js +7 -44
  5. package/authentication/models/schemas.d.ts +5 -0
  6. package/authentication/models/schemas.js +6 -0
  7. package/authentication/server/authentication.service.d.ts +1 -1
  8. package/authentication/server/authentication.service.js +10 -11
  9. package/authentication/server/drizzle/0000_known_proemial_gods.sql +28 -0
  10. package/authentication/server/drizzle/meta/0000_snapshot.json +189 -0
  11. package/authentication/server/drizzle/meta/_journal.json +13 -0
  12. package/authentication/server/drizzle.config.d.ts +2 -0
  13. package/authentication/server/drizzle.config.js +11 -0
  14. package/authentication/server/index.d.ts +0 -2
  15. package/authentication/server/index.js +0 -2
  16. package/authentication/server/module.d.ts +5 -6
  17. package/authentication/server/module.js +19 -4
  18. package/document-management/server/drizzle.config.js +2 -2
  19. package/document-management/server/module.d.ts +1 -1
  20. package/document-management/server/module.js +3 -4
  21. package/examples/api/authentication.js +1 -7
  22. package/examples/api/custom-authentication.js +0 -6
  23. package/orm/server/data-types/bytea.d.ts +10 -0
  24. package/orm/server/data-types/bytea.js +12 -0
  25. package/orm/server/data-types/index.d.ts +1 -0
  26. package/orm/server/data-types/index.js +1 -0
  27. package/orm/server/database.d.ts +2 -0
  28. package/orm/server/database.js +2 -0
  29. package/orm/server/drizzle/schema-converter.js +5 -1
  30. package/orm/types.d.ts +3 -1
  31. package/package.json +9 -5
  32. package/authentication/server/authentication-credentials.repository.d.ts +0 -5
  33. package/authentication/server/authentication-credentials.repository.js +0 -2
  34. package/authentication/server/authentication-session.repository.d.ts +0 -14
  35. package/authentication/server/authentication-session.repository.js +0 -2
  36. package/authentication/server/mongo/index.d.ts +0 -2
  37. package/authentication/server/mongo/index.js +0 -2
  38. package/authentication/server/mongo/mongo-authentication-credentials.repository.d.ts +0 -22
  39. package/authentication/server/mongo/mongo-authentication-credentials.repository.js +0 -68
  40. package/authentication/server/mongo/mongo-authentication-session.repository.d.ts +0 -23
  41. package/authentication/server/mongo/mongo-authentication-session.repository.js +0 -63
@@ -1,11 +1,5 @@
1
- export declare class AuthenticationCredentials {
2
- id: string;
3
- subject: string;
4
- hashVersion: number;
5
- salt: Uint8Array;
6
- hash: Uint8Array;
7
- }
8
- export declare class NewAuthenticationCredentials {
1
+ import { Entity } from '../../orm/index.js';
2
+ export declare class AuthenticationCredentials extends Entity {
9
3
  subject: string;
10
4
  hashVersion: number;
11
5
  salt: Uint8Array;
@@ -7,9 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { NumberProperty, StringProperty, Uint8ArrayProperty } from '../../schema/index.js';
11
- export class AuthenticationCredentials {
12
- id;
10
+ import { Entity, Unique } from '../../orm/index.js';
11
+ import { Integer, StringProperty, Uint8ArrayProperty } from '../../schema/index.js';
12
+ export class AuthenticationCredentials extends Entity {
13
13
  subject;
14
14
  hashVersion;
15
15
  salt;
@@ -17,14 +17,11 @@ export class AuthenticationCredentials {
17
17
  }
18
18
  __decorate([
19
19
  StringProperty(),
20
- __metadata("design:type", String)
21
- ], AuthenticationCredentials.prototype, "id", void 0);
22
- __decorate([
23
- StringProperty(),
20
+ Unique(),
24
21
  __metadata("design:type", String)
25
22
  ], AuthenticationCredentials.prototype, "subject", void 0);
26
23
  __decorate([
27
- NumberProperty(),
24
+ Integer(),
28
25
  __metadata("design:type", Number)
29
26
  ], AuthenticationCredentials.prototype, "hashVersion", void 0);
30
27
  __decorate([
@@ -35,25 +32,3 @@ __decorate([
35
32
  Uint8ArrayProperty(),
36
33
  __metadata("design:type", Uint8Array)
37
34
  ], AuthenticationCredentials.prototype, "hash", void 0);
38
- export class NewAuthenticationCredentials {
39
- subject;
40
- hashVersion;
41
- salt;
42
- hash;
43
- }
44
- __decorate([
45
- StringProperty(),
46
- __metadata("design:type", String)
47
- ], NewAuthenticationCredentials.prototype, "subject", void 0);
48
- __decorate([
49
- NumberProperty(),
50
- __metadata("design:type", Number)
51
- ], NewAuthenticationCredentials.prototype, "hashVersion", void 0);
52
- __decorate([
53
- Uint8ArrayProperty(),
54
- __metadata("design:type", Uint8Array)
55
- ], NewAuthenticationCredentials.prototype, "salt", void 0);
56
- __decorate([
57
- Uint8ArrayProperty(),
58
- __metadata("design:type", Uint8Array)
59
- ], NewAuthenticationCredentials.prototype, "hash", void 0);
@@ -1,18 +1,9 @@
1
- export declare class AuthenticationSession {
2
- id: string;
1
+ import { Entity } from '../../orm/entity.js';
2
+ import { Timestamp } from '../../orm/types.js';
3
+ export declare class AuthenticationSession extends Entity {
3
4
  subject: string;
4
- /** Timestamp */
5
- begin: number;
6
- /** Timestamp */
7
- end: number;
8
- refreshTokenHashVersion: number;
9
- refreshTokenSalt: Uint8Array;
10
- refreshTokenHash: Uint8Array;
11
- }
12
- export declare class NewAuthenticationSession {
13
- subject: string;
14
- begin: number;
15
- end: number;
5
+ begin: Timestamp;
6
+ end: Timestamp;
16
7
  refreshTokenHashVersion: number;
17
8
  refreshTokenSalt: Uint8Array;
18
9
  refreshTokenHash: Uint8Array;
@@ -7,36 +7,31 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { NumberProperty, StringProperty, Uint8ArrayProperty } from '../../schema/index.js';
11
- export class AuthenticationSession {
12
- id;
10
+ import { Entity } from '../../orm/entity.js';
11
+ import { Timestamp } from '../../orm/types.js';
12
+ import { Integer, StringProperty, Uint8ArrayProperty } from '../../schema/index.js';
13
+ export class AuthenticationSession extends Entity {
13
14
  subject;
14
- /** Timestamp */
15
15
  begin;
16
- /** Timestamp */
17
16
  end;
18
17
  refreshTokenHashVersion;
19
18
  refreshTokenSalt;
20
19
  refreshTokenHash;
21
20
  }
22
- __decorate([
23
- StringProperty(),
24
- __metadata("design:type", String)
25
- ], AuthenticationSession.prototype, "id", void 0);
26
21
  __decorate([
27
22
  StringProperty(),
28
23
  __metadata("design:type", String)
29
24
  ], AuthenticationSession.prototype, "subject", void 0);
30
25
  __decorate([
31
- NumberProperty(),
26
+ Timestamp(),
32
27
  __metadata("design:type", Number)
33
28
  ], AuthenticationSession.prototype, "begin", void 0);
34
29
  __decorate([
35
- NumberProperty(),
30
+ Timestamp(),
36
31
  __metadata("design:type", Number)
37
32
  ], AuthenticationSession.prototype, "end", void 0);
38
33
  __decorate([
39
- NumberProperty(),
34
+ Integer(),
40
35
  __metadata("design:type", Number)
41
36
  ], AuthenticationSession.prototype, "refreshTokenHashVersion", void 0);
42
37
  __decorate([
@@ -47,35 +42,3 @@ __decorate([
47
42
  Uint8ArrayProperty(),
48
43
  __metadata("design:type", Uint8Array)
49
44
  ], AuthenticationSession.prototype, "refreshTokenHash", void 0);
50
- export class NewAuthenticationSession {
51
- subject;
52
- begin;
53
- end;
54
- refreshTokenHashVersion;
55
- refreshTokenSalt;
56
- refreshTokenHash;
57
- }
58
- __decorate([
59
- StringProperty(),
60
- __metadata("design:type", String)
61
- ], NewAuthenticationSession.prototype, "subject", void 0);
62
- __decorate([
63
- NumberProperty(),
64
- __metadata("design:type", Number)
65
- ], NewAuthenticationSession.prototype, "begin", void 0);
66
- __decorate([
67
- NumberProperty(),
68
- __metadata("design:type", Number)
69
- ], NewAuthenticationSession.prototype, "end", void 0);
70
- __decorate([
71
- NumberProperty(),
72
- __metadata("design:type", Number)
73
- ], NewAuthenticationSession.prototype, "refreshTokenHashVersion", void 0);
74
- __decorate([
75
- Uint8ArrayProperty(),
76
- __metadata("design:type", Uint8Array)
77
- ], NewAuthenticationSession.prototype, "refreshTokenSalt", void 0);
78
- __decorate([
79
- Uint8ArrayProperty(),
80
- __metadata("design:type", Uint8Array)
81
- ], NewAuthenticationSession.prototype, "refreshTokenHash", void 0);
@@ -0,0 +1,5 @@
1
+ import { AuthenticationCredentials } from './authentication-credentials.model.js';
2
+ import { AuthenticationSession } from './authentication-session.model.js';
3
+ export declare const authenticationSchema: import("../../orm/server/database-schema.js").DatabaseSchema<"authentication">;
4
+ export declare const authenticationCredentials: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"authentication", typeof AuthenticationCredentials>;
5
+ export declare const authenticationSession: import("../../orm/server/drizzle/schema-converter.js").PgTableFromType<"authentication", typeof AuthenticationSession>;
@@ -0,0 +1,6 @@
1
+ import { databaseSchema } from '../../orm/server/database-schema.js';
2
+ import { AuthenticationCredentials } from './authentication-credentials.model.js';
3
+ import { AuthenticationSession } from './authentication-session.model.js';
4
+ export const authenticationSchema = databaseSchema('authentication');
5
+ export const authenticationCredentials = authenticationSchema.getTable(AuthenticationCredentials);
6
+ export const authenticationSession = authenticationSchema.getTable(AuthenticationSession);
@@ -1,6 +1,6 @@
1
1
  import { type AfterResolve, afterResolve } from '../../injector/index.js';
2
2
  import type { BinaryData, Record } from '../../types.js';
3
- import type { RefreshToken, SecretCheckResult, SecretResetToken, Token } from '../models/index.js';
3
+ import { type RefreshToken, type SecretCheckResult, type SecretResetToken, type Token } from '../models/index.js';
4
4
  import { type SecretTestResult } from './authentication-secret-requirements.validator.js';
5
5
  export type CreateTokenData<AdditionalTokenPayload extends Record> = {
6
6
  tokenVersion?: number;
@@ -8,6 +8,7 @@ import { ForbiddenError } from '../../errors/forbidden.error.js';
8
8
  import { InvalidTokenError } from '../../errors/invalid-token.error.js';
9
9
  import { NotImplementedError } from '../../errors/not-implemented.error.js';
10
10
  import { Singleton, afterResolve, inject } from '../../injector/index.js';
11
+ import { injectRepository } from '../../orm/server/repository.js';
11
12
  import { Alphabet } from '../../utils/alphabet.js';
12
13
  import { deriveBytesMultiple, importPbkdf2Key } from '../../utils/cryptography.js';
13
14
  import { currentTimestamp, timestampToTimestampSeconds } from '../../utils/date-time.js';
@@ -16,10 +17,9 @@ import { createJwtTokenString } from '../../utils/jwt.js';
16
17
  import { getRandomBytes, getRandomString } from '../../utils/random.js';
17
18
  import { isBinaryData, isString, isUndefined } from '../../utils/type-guards.js';
18
19
  import { millisecondsPerDay, millisecondsPerMinute } from '../../utils/units.js';
20
+ import { AuthenticationCredentials, AuthenticationSession } from '../models/index.js';
19
21
  import { AuthenticationAncillaryService, GetTokenPayloadContextAction } from './authentication-ancillary.service.js';
20
- import { AuthenticationCredentialsRepository } from './authentication-credentials.repository.js';
21
22
  import { AuthenticationSecretRequirementsValidator } from './authentication-secret-requirements.validator.js';
22
- import { AuthenticationSessionRepository } from './authentication-session.repository.js';
23
23
  import { getRefreshTokenFromString, getSecretResetTokenFromString, getTokenFromString } from './helper.js';
24
24
  export class AuthenticationServiceOptions {
25
25
  /**
@@ -38,8 +38,8 @@ export class AuthenticationServiceOptions {
38
38
  }
39
39
  const SIGNING_SECRETS_LENGTH = 64;
40
40
  let AuthenticationService = class AuthenticationService {
41
- credentialsRepository = inject(AuthenticationCredentialsRepository);
42
- sessionRepository = inject(AuthenticationSessionRepository);
41
+ credentialsRepository = injectRepository(AuthenticationCredentials);
42
+ sessionRepository = injectRepository(AuthenticationSession);
43
43
  authenticationSecretRequirementsValidator = inject(AuthenticationSecretRequirementsValidator);
44
44
  authenticationAncillaryService = inject(AuthenticationAncillaryService, undefined, { optional: true });
45
45
  options = inject(AuthenticationServiceOptions);
@@ -70,17 +70,16 @@ let AuthenticationService = class AuthenticationService {
70
70
  }
71
71
  const salt = getRandomBytes(32);
72
72
  const hash = await this.getHash(secret, salt);
73
- const credentials = {
73
+ await this.credentialsRepository.upsert('subject', {
74
74
  subject: actualSubject,
75
75
  hashVersion: 1,
76
76
  salt,
77
77
  hash
78
- };
79
- await this.credentialsRepository.save(credentials);
78
+ });
80
79
  }
81
80
  async authenticate(subject, secret) {
82
81
  const actualSubject = await this.resolveSubject(subject);
83
- const credentials = await this.credentialsRepository.tryLoadBySubject(actualSubject);
82
+ const credentials = await this.credentialsRepository.tryLoadByQuery({ subject: actualSubject });
84
83
  if (isUndefined(credentials)) {
85
84
  return { success: false };
86
85
  }
@@ -106,7 +105,7 @@ let AuthenticationService = class AuthenticationService {
106
105
  const tokenPayload = await this.authenticationAncillaryService?.getTokenPayload(actualSubject, authenticationData, { action: GetTokenPayloadContextAction.GetToken });
107
106
  const { token, jsonToken } = await this.createToken({ additionalTokenPayload: tokenPayload, subject: actualSubject, impersonator, sessionId: session.id, refreshTokenExpiration: end, timestamp: now });
108
107
  const refreshToken = await this.createRefreshToken(actualSubject, session.id, end, { impersonator });
109
- await this.sessionRepository.extend(session.id, {
108
+ await this.sessionRepository.update(session.id, {
110
109
  end,
111
110
  refreshTokenHashVersion: 1,
112
111
  refreshTokenSalt: refreshToken.salt,
@@ -116,7 +115,7 @@ let AuthenticationService = class AuthenticationService {
116
115
  }
117
116
  async endSession(sessionId) {
118
117
  const now = currentTimestamp();
119
- await this.sessionRepository.end(sessionId, now);
118
+ await this.sessionRepository.update(sessionId, { end: now });
120
119
  }
121
120
  async refresh(refreshToken, authenticationData, { omitImpersonator = false } = {}) {
122
121
  const validatedRefreshToken = await this.validateRefreshToken(refreshToken);
@@ -135,7 +134,7 @@ let AuthenticationService = class AuthenticationService {
135
134
  const tokenPayload = await this.authenticationAncillaryService?.getTokenPayload(session.subject, authenticationData, { action: GetTokenPayloadContextAction.Refresh });
136
135
  const { token, jsonToken } = await this.createToken({ additionalTokenPayload: tokenPayload, subject: session.subject, sessionId, refreshTokenExpiration: newEnd, impersonator, timestamp: now });
137
136
  const newRefreshToken = await this.createRefreshToken(validatedRefreshToken.payload.subject, sessionId, newEnd, { impersonator });
138
- await this.sessionRepository.extend(sessionId, {
137
+ await this.sessionRepository.update(sessionId, {
139
138
  end: newEnd,
140
139
  refreshTokenHashVersion: 1,
141
140
  refreshTokenSalt: newRefreshToken.salt,
@@ -0,0 +1,28 @@
1
+ CREATE TABLE "authentication"."authentication_credentials" (
2
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
+ "subject" text NOT NULL,
4
+ "hash_version" integer NOT NULL,
5
+ "salt" "bytea" NOT NULL,
6
+ "hash" "bytea" NOT NULL,
7
+ "revision" integer NOT NULL,
8
+ "revision_timestamp" timestamp with time zone NOT NULL,
9
+ "create_timestamp" timestamp with time zone NOT NULL,
10
+ "delete_timestamp" timestamp with time zone,
11
+ "attributes" jsonb DEFAULT '{}'::jsonb NOT NULL,
12
+ CONSTRAINT "authentication_credentials_subject_unique" UNIQUE("subject")
13
+ );
14
+ --> statement-breakpoint
15
+ CREATE TABLE "authentication"."authentication_session" (
16
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
17
+ "subject" text NOT NULL,
18
+ "begin" timestamp with time zone NOT NULL,
19
+ "end" timestamp with time zone NOT NULL,
20
+ "refresh_token_hash_version" integer NOT NULL,
21
+ "refresh_token_salt" "bytea" NOT NULL,
22
+ "refresh_token_hash" "bytea" NOT NULL,
23
+ "revision" integer NOT NULL,
24
+ "revision_timestamp" timestamp with time zone NOT NULL,
25
+ "create_timestamp" timestamp with time zone NOT NULL,
26
+ "delete_timestamp" timestamp with time zone,
27
+ "attributes" jsonb DEFAULT '{}'::jsonb NOT NULL
28
+ );
@@ -0,0 +1,189 @@
1
+ {
2
+ "id": "ffcce2f4-34e6-4887-8c9c-0c1a9e07a3b8",
3
+ "prevId": "00000000-0000-0000-0000-000000000000",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "authentication.authentication_credentials": {
8
+ "name": "authentication_credentials",
9
+ "schema": "authentication",
10
+ "columns": {
11
+ "id": {
12
+ "name": "id",
13
+ "type": "uuid",
14
+ "primaryKey": true,
15
+ "notNull": true,
16
+ "default": "gen_random_uuid()"
17
+ },
18
+ "subject": {
19
+ "name": "subject",
20
+ "type": "text",
21
+ "primaryKey": false,
22
+ "notNull": true
23
+ },
24
+ "hash_version": {
25
+ "name": "hash_version",
26
+ "type": "integer",
27
+ "primaryKey": false,
28
+ "notNull": true
29
+ },
30
+ "salt": {
31
+ "name": "salt",
32
+ "type": "bytea",
33
+ "primaryKey": false,
34
+ "notNull": true
35
+ },
36
+ "hash": {
37
+ "name": "hash",
38
+ "type": "bytea",
39
+ "primaryKey": false,
40
+ "notNull": true
41
+ },
42
+ "revision": {
43
+ "name": "revision",
44
+ "type": "integer",
45
+ "primaryKey": false,
46
+ "notNull": true
47
+ },
48
+ "revision_timestamp": {
49
+ "name": "revision_timestamp",
50
+ "type": "timestamp with time zone",
51
+ "primaryKey": false,
52
+ "notNull": true
53
+ },
54
+ "create_timestamp": {
55
+ "name": "create_timestamp",
56
+ "type": "timestamp with time zone",
57
+ "primaryKey": false,
58
+ "notNull": true
59
+ },
60
+ "delete_timestamp": {
61
+ "name": "delete_timestamp",
62
+ "type": "timestamp with time zone",
63
+ "primaryKey": false,
64
+ "notNull": false
65
+ },
66
+ "attributes": {
67
+ "name": "attributes",
68
+ "type": "jsonb",
69
+ "primaryKey": false,
70
+ "notNull": true,
71
+ "default": "'{}'::jsonb"
72
+ }
73
+ },
74
+ "indexes": {},
75
+ "foreignKeys": {},
76
+ "compositePrimaryKeys": {},
77
+ "uniqueConstraints": {
78
+ "authentication_credentials_subject_unique": {
79
+ "name": "authentication_credentials_subject_unique",
80
+ "nullsNotDistinct": false,
81
+ "columns": [
82
+ "subject"
83
+ ]
84
+ }
85
+ },
86
+ "policies": {},
87
+ "checkConstraints": {},
88
+ "isRLSEnabled": false
89
+ },
90
+ "authentication.authentication_session": {
91
+ "name": "authentication_session",
92
+ "schema": "authentication",
93
+ "columns": {
94
+ "id": {
95
+ "name": "id",
96
+ "type": "uuid",
97
+ "primaryKey": true,
98
+ "notNull": true,
99
+ "default": "gen_random_uuid()"
100
+ },
101
+ "subject": {
102
+ "name": "subject",
103
+ "type": "text",
104
+ "primaryKey": false,
105
+ "notNull": true
106
+ },
107
+ "begin": {
108
+ "name": "begin",
109
+ "type": "timestamp with time zone",
110
+ "primaryKey": false,
111
+ "notNull": true
112
+ },
113
+ "end": {
114
+ "name": "end",
115
+ "type": "timestamp with time zone",
116
+ "primaryKey": false,
117
+ "notNull": true
118
+ },
119
+ "refresh_token_hash_version": {
120
+ "name": "refresh_token_hash_version",
121
+ "type": "integer",
122
+ "primaryKey": false,
123
+ "notNull": true
124
+ },
125
+ "refresh_token_salt": {
126
+ "name": "refresh_token_salt",
127
+ "type": "bytea",
128
+ "primaryKey": false,
129
+ "notNull": true
130
+ },
131
+ "refresh_token_hash": {
132
+ "name": "refresh_token_hash",
133
+ "type": "bytea",
134
+ "primaryKey": false,
135
+ "notNull": true
136
+ },
137
+ "revision": {
138
+ "name": "revision",
139
+ "type": "integer",
140
+ "primaryKey": false,
141
+ "notNull": true
142
+ },
143
+ "revision_timestamp": {
144
+ "name": "revision_timestamp",
145
+ "type": "timestamp with time zone",
146
+ "primaryKey": false,
147
+ "notNull": true
148
+ },
149
+ "create_timestamp": {
150
+ "name": "create_timestamp",
151
+ "type": "timestamp with time zone",
152
+ "primaryKey": false,
153
+ "notNull": true
154
+ },
155
+ "delete_timestamp": {
156
+ "name": "delete_timestamp",
157
+ "type": "timestamp with time zone",
158
+ "primaryKey": false,
159
+ "notNull": false
160
+ },
161
+ "attributes": {
162
+ "name": "attributes",
163
+ "type": "jsonb",
164
+ "primaryKey": false,
165
+ "notNull": true,
166
+ "default": "'{}'::jsonb"
167
+ }
168
+ },
169
+ "indexes": {},
170
+ "foreignKeys": {},
171
+ "compositePrimaryKeys": {},
172
+ "uniqueConstraints": {},
173
+ "policies": {},
174
+ "checkConstraints": {},
175
+ "isRLSEnabled": false
176
+ }
177
+ },
178
+ "enums": {},
179
+ "schemas": {},
180
+ "sequences": {},
181
+ "roles": {},
182
+ "policies": {},
183
+ "views": {},
184
+ "_meta": {
185
+ "columns": {},
186
+ "schemas": {},
187
+ "tables": {}
188
+ }
189
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": "7",
3
+ "dialect": "postgresql",
4
+ "entries": [
5
+ {
6
+ "idx": 0,
7
+ "version": "7",
8
+ "when": 1739980255921,
9
+ "tag": "0000_known_proemial_gods",
10
+ "breakpoints": true
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("drizzle-kit").Config;
2
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import { relative, resolve } from 'node:path';
2
+ import { defineConfig } from 'drizzle-kit';
3
+ export default defineConfig({
4
+ dialect: 'postgresql',
5
+ out: relative('./', resolve(__dirname, './drizzle/').replace('dist', 'source')),
6
+ schema: resolve(__dirname, '../models/schemas.js'),
7
+ migrations: {
8
+ schema: 'authentication',
9
+ table: '_migrations'
10
+ }
11
+ });
@@ -1,8 +1,6 @@
1
1
  export * from './authentication-ancillary.service.js';
2
2
  export * from './authentication-api-request-token.provider.js';
3
- export * from './authentication-credentials.repository.js';
4
3
  export * from './authentication-secret-requirements.validator.js';
5
- export * from './authentication-session.repository.js';
6
4
  export * from './authentication.api-controller.js';
7
5
  export * from './authentication.service.js';
8
6
  export * from './helper.js';
@@ -1,8 +1,6 @@
1
1
  export * from './authentication-ancillary.service.js';
2
2
  export * from './authentication-api-request-token.provider.js';
3
- export * from './authentication-credentials.repository.js';
4
3
  export * from './authentication-secret-requirements.validator.js';
5
- export * from './authentication-session.repository.js';
6
4
  export * from './authentication.api-controller.js';
7
5
  export * from './authentication.service.js';
8
6
  export * from './helper.js';
@@ -1,15 +1,14 @@
1
1
  import type { Provider } from '../../injector/provider.js';
2
2
  import type { InjectionToken } from '../../injector/token.js';
3
+ import type { DatabaseConfig } from '../../orm/server/module.js';
3
4
  import { AuthenticationAncillaryService } from './authentication-ancillary.service.js';
4
- import { AuthenticationCredentialsRepository } from './authentication-credentials.repository.js';
5
- import { AuthenticationSessionRepository } from './authentication-session.repository.js';
6
5
  import { AuthenticationService, AuthenticationServiceOptions } from './authentication.service.js';
7
- export type AuthenticationModuleConfig = {
6
+ export declare class AuthenticationModuleConfig {
7
+ database?: DatabaseConfig;
8
8
  serviceOptions?: AuthenticationServiceOptions | Provider<AuthenticationServiceOptions>;
9
- credentialsRepository: InjectionToken<AuthenticationCredentialsRepository>;
10
- sessionRepository: InjectionToken<AuthenticationSessionRepository>;
11
9
  /** override default AuthenticationService */
12
10
  authenticationService?: InjectionToken<AuthenticationService<any, any, any>>;
13
11
  authenticationAncillaryService?: InjectionToken<AuthenticationAncillaryService<any, any, any>>;
14
- };
12
+ }
15
13
  export declare function configureAuthenticationServer(config: AuthenticationModuleConfig): void;
14
+ export declare function migrateAuthenticationSchema(): Promise<void>;
@@ -1,19 +1,25 @@
1
+ import { inject } from '../../injector/index.js';
1
2
  import { Injector } from '../../injector/injector.js';
2
3
  import { isProvider } from '../../injector/provider.js';
4
+ import { Database, migrate } from '../../orm/server/index.js';
3
5
  import { isDefined } from '../../utils/type-guards.js';
4
6
  import { AuthenticationAncillaryService } from './authentication-ancillary.service.js';
5
- import { AuthenticationCredentialsRepository } from './authentication-credentials.repository.js';
6
- import { AuthenticationSessionRepository } from './authentication-session.repository.js';
7
7
  import { AuthenticationService, AuthenticationServiceOptions } from './authentication.service.js';
8
+ export class AuthenticationModuleConfig {
9
+ database;
10
+ serviceOptions;
11
+ /** override default AuthenticationService */
12
+ authenticationService;
13
+ authenticationAncillaryService;
14
+ }
8
15
  export function configureAuthenticationServer(config) {
16
+ Injector.register(AuthenticationModuleConfig, { useValue: config });
9
17
  if (isDefined(config.serviceOptions)) {
10
18
  Injector.register(AuthenticationServiceOptions, isProvider(config.serviceOptions) ? config.serviceOptions : { useValue: config.serviceOptions });
11
19
  }
12
20
  else {
13
21
  throw new Error('Either serviceOptions or serviceOptionsToken must be provided.');
14
22
  }
15
- Injector.registerSingleton(AuthenticationCredentialsRepository, { useToken: config.credentialsRepository });
16
- Injector.registerSingleton(AuthenticationSessionRepository, { useToken: config.sessionRepository });
17
23
  if (isDefined(config.authenticationService)) {
18
24
  Injector.registerSingleton(AuthenticationService, { useToken: config.authenticationService });
19
25
  }
@@ -21,3 +27,12 @@ export function configureAuthenticationServer(config) {
21
27
  Injector.registerSingleton(AuthenticationAncillaryService, { useToken: config.authenticationAncillaryService });
22
28
  }
23
29
  }
30
+ export async function migrateAuthenticationSchema() {
31
+ const connection = inject(AuthenticationModuleConfig, undefined, { optional: true })?.database?.connection;
32
+ const database = inject(Database, connection);
33
+ await migrate(database, {
34
+ migrationsSchema: 'authentication',
35
+ migrationsTable: '_migrations',
36
+ migrationsFolder: import.meta.resolve('./drizzle').replace('file://', '')
37
+ });
38
+ }
@@ -3,9 +3,9 @@ import { defineConfig } from 'drizzle-kit';
3
3
  export default defineConfig({
4
4
  dialect: 'postgresql',
5
5
  out: relative('./', resolve(__dirname, './drizzle/').replace('dist', 'source')),
6
- schema: resolve(__dirname, './models/schemas.js'),
6
+ schema: resolve(__dirname, '../models/schemas.js'),
7
7
  migrations: {
8
8
  schema: 'document_management',
9
- table: '_orm_migrations'
9
+ table: '_migrations'
10
10
  }
11
11
  });
@@ -4,7 +4,7 @@ import type { DatabaseConfig } from '../../orm/server/module.js';
4
4
  import { DocumentManagementService } from './services/document-management.service.js';
5
5
  export declare class DocumentManagementConfig {
6
6
  fileObjectStorageModule: string;
7
- database: DatabaseConfig;
7
+ database?: DatabaseConfig;
8
8
  customService?: InjectionToken<DocumentManagementService>;
9
9
  }
10
10
  export declare function configureDocumentManagement(config: DocumentManagementConfig): void;
@@ -1,7 +1,6 @@
1
1
  import '../models/schemas.js';
2
- import { migrate } from 'drizzle-orm/node-postgres/migrator';
3
2
  import { inject, Injector } from '../../injector/index.js';
4
- import { Database } from '../../orm/server/database.js';
3
+ import { Database, migrate } from '../../orm/server/database.js';
5
4
  import { isDefined } from '../../utils/type-guards.js';
6
5
  import { DocumentManagementService } from './services/document-management.service.js';
7
6
  export class DocumentManagementConfig {
@@ -17,8 +16,8 @@ export function configureDocumentManagement(config) {
17
16
  }
18
17
  }
19
18
  export async function migrateDocumentManagementSchema() {
20
- const config = inject(DocumentManagementConfig);
21
- const database = inject(Database, config.database.connection);
19
+ const connection = inject(DocumentManagementConfig, undefined, { optional: true })?.database?.connection;
20
+ const database = inject(Database, connection);
22
21
  await migrate(database, {
23
22
  migrationsSchema: 'document_management',
24
23
  migrationsTable: '_migrations',
@@ -5,8 +5,6 @@ import { Application } from '../../application/application.js';
5
5
  import { AuthenticationApiClient } from '../../authentication/client/api.client.js';
6
6
  import { AuthenticationClientService, configureAuthenticationClient } from '../../authentication/client/index.js';
7
7
  import { AuthenticationApiController, AuthenticationService as AuthenticationServerService, configureAuthenticationServer } from '../../authentication/server/index.js';
8
- import { MongoAuthenticationCredentialsRepository, configureMongoAuthenticationCredentialsRepository } from '../../authentication/server/mongo/mongo-authentication-credentials.repository.js';
9
- import { MongoAuthenticationSessionRepository, configureMongoAuthenticationSessionRepository } from '../../authentication/server/mongo/mongo-authentication-session.repository.js';
10
8
  import { configureUndiciHttpClientAdapter } from '../../http/client/adapters/undici.adapter.js';
11
9
  import { configureHttpClient } from '../../http/client/module.js';
12
10
  import { configureNodeHttpServer } from '../../http/server/node/module.js';
@@ -39,12 +37,8 @@ async function test() {
39
37
  function bootstrap() {
40
38
  configureDefaultSignalsImplementation();
41
39
  configureAuthenticationServer({
42
- serviceOptions: { secret: 'djp0fq23576aq' },
43
- credentialsRepository: MongoAuthenticationCredentialsRepository,
44
- sessionRepository: MongoAuthenticationSessionRepository
40
+ serviceOptions: { secret: 'djp0fq23576aq' }
45
41
  });
46
- configureMongoAuthenticationCredentialsRepository({ collection: 'credentials' });
47
- configureMongoAuthenticationSessionRepository({ collection: 'sessions' });
48
42
  configureLocalMessageBus();
49
43
  configureAuthenticationClient({
50
44
  authenticationApiClient: AuthenticationApiClient
@@ -17,8 +17,6 @@ import { AuthenticationAncillaryService } from '../../authentication/index.js';
17
17
  import { AuthenticationApiController } from '../../authentication/server/authentication.api-controller.js';
18
18
  import { AuthenticationService as AuthenticationServerService } from '../../authentication/server/authentication.service.js';
19
19
  import { configureAuthenticationServer } from '../../authentication/server/module.js';
20
- import { MongoAuthenticationCredentialsRepository, configureMongoAuthenticationCredentialsRepository } from '../../authentication/server/mongo/mongo-authentication-credentials.repository.js';
21
- import { MongoAuthenticationSessionRepository, configureMongoAuthenticationSessionRepository } from '../../authentication/server/mongo/mongo-authentication-session.repository.js';
22
20
  import { configureUndiciHttpClientAdapter } from '../../http/client/adapters/undici.adapter.js';
23
21
  import { configureHttpClient } from '../../http/client/module.js';
24
22
  import { configureNodeHttpServer } from '../../http/server/node/module.js';
@@ -108,12 +106,8 @@ function bootstrap() {
108
106
  configureDefaultSignalsImplementation();
109
107
  configureAuthenticationServer({
110
108
  serviceOptions: { secret: 'djp0fq23576aq' },
111
- credentialsRepository: MongoAuthenticationCredentialsRepository,
112
- sessionRepository: MongoAuthenticationSessionRepository,
113
109
  authenticationAncillaryService: CustomAuthenticationAncillaryService
114
110
  });
115
- configureMongoAuthenticationCredentialsRepository({ collection: 'credentials' });
116
- configureMongoAuthenticationSessionRepository({ collection: 'sessions' });
117
111
  configureLocalMessageBus();
118
112
  configureAuthenticationClient({
119
113
  authenticationApiClient: CustomAuthenticationApiClient,
@@ -0,0 +1,10 @@
1
+ import { type ConvertCustomConfig, type PgCustomColumnBuilder } from 'drizzle-orm/pg-core';
2
+ type Config = {
3
+ data: Uint8Array;
4
+ driverData: Uint8Array;
5
+ };
6
+ export declare const bytea: {
7
+ (): PgCustomColumnBuilder<ConvertCustomConfig<"", Config>>;
8
+ <TName extends string>(dbName: TName): PgCustomColumnBuilder<ConvertCustomConfig<TName, Config>>;
9
+ };
10
+ export {};
@@ -0,0 +1,12 @@
1
+ import { customType } from 'drizzle-orm/pg-core';
2
+ export const bytea = customType({
3
+ dataType() {
4
+ return 'bytea';
5
+ },
6
+ toDriver(value) {
7
+ return value;
8
+ },
9
+ fromDriver(value) {
10
+ return value;
11
+ }
12
+ });
@@ -0,0 +1 @@
1
+ export * from './bytea.js';
@@ -0,0 +1 @@
1
+ export * from './bytea.js';
@@ -1,7 +1,9 @@
1
1
  import { NodePgDatabase } from 'drizzle-orm/node-postgres';
2
+ import { migrate } from 'drizzle-orm/node-postgres/migrator';
2
3
  import type { PoolConfig } from 'pg';
3
4
  import type { Resolvable, resolveArgumentType } from '../../injector/interfaces.js';
4
5
  export type DatabaseArgument = string | PoolConfig;
5
6
  export declare class Database extends NodePgDatabase<any> implements Resolvable<DatabaseArgument> {
6
7
  readonly [resolveArgumentType]?: DatabaseArgument;
7
8
  }
9
+ export { migrate };
@@ -5,6 +5,7 @@ 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
  import { drizzle, NodePgDatabase } from 'drizzle-orm/node-postgres';
8
+ import { migrate } from 'drizzle-orm/node-postgres/migrator';
8
9
  import { inject, Injector, ReplaceClass } from '../../injector/index.js';
9
10
  import { isUndefined } from '../../utils/type-guards.js';
10
11
  import { DatabaseConfig } from './module.js';
@@ -23,3 +24,4 @@ Injector.registerSingleton(Database, {
23
24
  return drizzle({ connection });
24
25
  }
25
26
  });
27
+ export { migrate };
@@ -4,7 +4,7 @@ import { MultiKeyMap } from '../../../data-structures/multi-key-map.js';
4
4
  import { NotSupportedError } from '../../../errors/not-supported.error.js';
5
5
  import { JsonPath } from '../../../json-path/json-path.js';
6
6
  import { reflectionRegistry } from '../../../reflection/registry.js';
7
- import { ArraySchema, BooleanSchema, DefaultSchema, EnumerationSchema, getObjectSchema, NullableSchema, NumberSchema, ObjectSchema, OptionalSchema, StringSchema } from '../../../schema/index.js';
7
+ import { ArraySchema, BooleanSchema, DefaultSchema, EnumerationSchema, getObjectSchema, NullableSchema, NumberSchema, ObjectSchema, OptionalSchema, StringSchema, Uint8ArraySchema } from '../../../schema/index.js';
8
8
  import { compareByValueSelectionToOrder, orderRest } from '../../../utils/comparison.js';
9
9
  import { enumValues } from '../../../utils/enum.js';
10
10
  import { memoize, memoizeSingle } from '../../../utils/function/memoize.js';
@@ -15,6 +15,7 @@ import { JsonSchema } from '../../schemas/json.js';
15
15
  import { NumericDateSchema } from '../../schemas/numeric-date.js';
16
16
  import { TimestampSchema } from '../../schemas/timestamp.js';
17
17
  import { UuidSchema } from '../../schemas/uuid.js';
18
+ import { bytea } from '../data-types/bytea.js';
18
19
  const getDbSchema = memoizeSingle(pgSchema);
19
20
  export const getDrizzleTableFromType = memoize(_getDrizzleTableFromType);
20
21
  const columnDefinitionsSymbol = Symbol('columnDefinitions');
@@ -168,6 +169,9 @@ function getPostgresBaseColumn(columnName, dbSchema, schema, context) {
168
169
  if (schema instanceof JsonSchema) {
169
170
  return jsonb(columnName);
170
171
  }
172
+ if (schema instanceof Uint8ArraySchema) {
173
+ return bytea(columnName);
174
+ }
171
175
  throw new NotSupportedError(`Schema "${schema.constructor.name}" not supported on type "${context.type.name}" for property "${context.property}"`);
172
176
  }
173
177
  const enumNames = new Map();
package/orm/types.d.ts CHANGED
@@ -5,12 +5,13 @@ import type { AbstractConstructor, EnumerationObject, EnumerationValue, ObjectLi
5
5
  import type { GetTagMetadata, HasTag, Tagged, UnwrapTagged } from '../types/index.js';
6
6
  import { Column, Embedded, Index, PrimaryKey, References, Unique } from './decorators.js';
7
7
  import { Json, NumericDate, Timestamp, Uuid } from './schemas/index.js';
8
+ import type { bytea } from './server/data-types/index.js';
8
9
  export type ColumnTypeTag = 'column';
9
10
  export type EmbeddedConfigTag = 'embedded';
10
11
  export type IsPrimaryKey<T> = T extends Tagged<unknown, ColumnTypeTag, PgColumnBuilderBase> ? Tagged<UnwrapTagged<T>, ColumnTypeTag, DrizzleIsPrimaryKey<GetTagMetadata<T, ColumnTypeTag>>> : Tagged<T, ColumnTypeTag, DrizzleIsPrimaryKey<ColumnBuilder<T>>>;
11
12
  export type HasDefault<T> = T extends Tagged<unknown, ColumnTypeTag, PgColumnBuilderBase> ? Tagged<UnwrapTagged<T>, ColumnTypeTag, DrizzleHasDefault<GetTagMetadata<T, ColumnTypeTag>>> : Tagged<T, ColumnTypeTag, DrizzleHasDefault<ColumnBuilder<T>>>;
12
13
  type EnumColumn<T extends EnumerationObject, ColumnName extends string = ''> = PgEnumColumnBuilderInitial<ColumnName, UnionToTuple<`${EnumerationValue<T>}`> extends [string, ...string[]] ? UnionToTuple<`${EnumerationValue<T>}`> : ['NO_VALUES_PROVIDED']>;
13
- export type ColumnBuilder<T, ColumnName extends string = never> = HasTag<T> extends true ? T extends Tagged<T, ColumnTypeTag, any> ? GetTagMetadata<T, ColumnTypeTag> : never : T extends string ? string extends ColumnName ? ReturnType<typeof text<ColumnName, string, [string, ...string[]]>> : ReturnType<typeof text<string, [string, ...string[]]>> : T extends number ? string extends ColumnName ? ReturnType<typeof doublePrecision<ColumnName>> : ReturnType<typeof doublePrecision> : T extends boolean ? string extends ColumnName ? ReturnType<typeof boolean<ColumnName>> : ReturnType<typeof boolean> : T extends EnumerationObject ? string extends ColumnName ? EnumColumn<T, ColumnName> : EnumColumn<T> : T extends (infer U)[] ? string extends ColumnName ? ReturnType<ColumnBuilder<U, ColumnName>['array']> : ReturnType<ColumnBuilder<U>['array']> : never;
14
+ export type ColumnBuilder<T, ColumnName extends string = never> = HasTag<T> extends true ? T extends Tagged<T, ColumnTypeTag, any> ? GetTagMetadata<T, ColumnTypeTag> : never : T extends string ? string extends ColumnName ? ReturnType<typeof text<ColumnName, string, [string, ...string[]]>> : ReturnType<typeof text<string, [string, ...string[]]>> : T extends number ? string extends ColumnName ? ReturnType<typeof doublePrecision<ColumnName>> : ReturnType<typeof doublePrecision> : T extends boolean ? string extends ColumnName ? ReturnType<typeof boolean<ColumnName>> : ReturnType<typeof boolean> : T extends Uint8Array ? string extends ColumnName ? ReturnType<typeof bytea<ColumnName>> : ReturnType<typeof bytea> : T extends EnumerationObject ? string extends ColumnName ? EnumColumn<T, ColumnName> : EnumColumn<T> : T extends (infer U)[] ? string extends ColumnName ? ReturnType<ColumnBuilder<U, ColumnName>['array']> : ReturnType<ColumnBuilder<U>['array']> : never;
14
15
  export type Embedded<T = AbstractConstructor, P extends string = ''> = Tagged<T, EmbeddedConfigTag, {
15
16
  prefix: P;
16
17
  }>;
@@ -24,4 +25,5 @@ export type DoublePrecision = Tagged<number, ColumnTypeTag, ReturnType<typeof do
24
25
  export type Boolean = Tagged<number, ColumnTypeTag, ReturnType<typeof boolean>>;
25
26
  export type NumericDate = Tagged<number, ColumnTypeTag, ReturnType<typeof date>>;
26
27
  export type Timestamp = Tagged<number, ColumnTypeTag, ReturnType<typeof timestamp>>;
28
+ export type Bytea = Tagged<number, ColumnTypeTag, ReturnType<typeof bytea>>;
27
29
  export { Array, Column, Embedded, Index, Integer, Json, NumericDate, PrimaryKey, References, Timestamp, Unique, Uuid };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.92.50",
3
+ "version": "0.92.51",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -10,15 +10,19 @@
10
10
  "build": "tsc && tsc-alias",
11
11
  "build:watch": "concurrently --raw --kill-others npm:tsc:watch npm:tsc-alias:watch",
12
12
  "build:production": "rm -rf dist && npm run build && npm run build:production:copy-files",
13
- "build:production:copy-files": "cp package.json eslint.config.js tsconfig.server.json dist/ && cp tsconfig.base.json dist/tsconfig.json && npm run copy:document-management",
13
+ "build:production:copy-files": "cp package.json eslint.config.js tsconfig.server.json dist/ && cp tsconfig.base.json dist/tsconfig.json && npm run copy:orm",
14
14
  "build:docs": "typedoc",
15
15
  "build:docs:watch": "typedoc --watch",
16
- "generate:drizzle": "drizzle-kit generate --config dist/document-management/server/drizzle.config.js",
17
- "copy:document-management": "rm -rf ./dist/document-management/server/drizzle && cp -r ./source/document-management/server/drizzle ./dist/document-management/server/",
18
16
  "lint": "eslint --cache source/",
19
17
  "pub": "npm run build:production && rm -vf dist/test* && rm -vrf dist/tools/ && npm publish dist/",
20
18
  "tsc:watch": "tsc --watch",
21
- "tsc-alias:watch": "tsc-alias --watch"
19
+ "tsc-alias:watch": "tsc-alias --watch",
20
+ "generate:orm": "npm run generate:drizzle:document-management && npm run generate:drizzle:authentication",
21
+ "generate:drizzle:document-management": "drizzle-kit generate --config dist/document-management/server/drizzle.config.js",
22
+ "generate:drizzle:authentication": "drizzle-kit generate --config dist/authentication/server/drizzle.config.js",
23
+ "copy:orm": "npm run copy:document-management && npm run copy:authentication",
24
+ "copy:document-management": "rm -rf ./dist/document-management/server/drizzle && cp -r ./source/document-management/server/drizzle ./dist/document-management/server/",
25
+ "copy:authentication": "rm -rf ./dist/authentication/server/drizzle && cp -r ./source/authentication/server/drizzle ./dist/authentication/server/"
22
26
  },
23
27
  "exports": {
24
28
  "./tsconfig.json": "./tsconfig.json",
@@ -1,5 +0,0 @@
1
- import type { AuthenticationCredentials, NewAuthenticationCredentials } from '../models/index.js';
2
- export declare abstract class AuthenticationCredentialsRepository {
3
- abstract tryLoadBySubject(subject: string): Promise<AuthenticationCredentials | undefined>;
4
- abstract save(credentials: NewAuthenticationCredentials | AuthenticationCredentials): Promise<void>;
5
- }
@@ -1,2 +0,0 @@
1
- export class AuthenticationCredentialsRepository {
2
- }
@@ -1,14 +0,0 @@
1
- import type { NewEntity } from '../../database/index.js';
2
- import type { AuthenticationSession } from '../models/authentication-session.model.js';
3
- export type AuthenticationSessionExtendData = {
4
- end: number;
5
- refreshTokenHashVersion: number;
6
- refreshTokenSalt: Uint8Array;
7
- refreshTokenHash: Uint8Array;
8
- };
9
- export declare abstract class AuthenticationSessionRepository {
10
- abstract insert(authenticationSession: NewEntity<AuthenticationSession>): Promise<AuthenticationSession>;
11
- abstract load(id: string): Promise<AuthenticationSession>;
12
- abstract extend(id: string, data: AuthenticationSessionExtendData): Promise<void>;
13
- abstract end(id: string, timestamp: number): Promise<void>;
14
- }
@@ -1,2 +0,0 @@
1
- export class AuthenticationSessionRepository {
2
- }
@@ -1,2 +0,0 @@
1
- export * from './mongo-authentication-credentials.repository.js';
2
- export * from './mongo-authentication-session.repository.js';
@@ -1,2 +0,0 @@
1
- export * from './mongo-authentication-credentials.repository.js';
2
- export * from './mongo-authentication-session.repository.js';
@@ -1,22 +0,0 @@
1
- import type { MaybeNewEntity } from '../../../database/index.js';
2
- import type { CollectionArgument } from '../../../database/mongo/index.js';
3
- import { Collection, MongoEntityRepository } from '../../../database/mongo/index.js';
4
- import { resolveArgumentType } from '../../../injector/index.js';
5
- import type { Resolvable } from '../../../injector/interfaces.js';
6
- import { Logger } from '../../../logger/index.js';
7
- import type { AuthenticationCredentials, NewAuthenticationCredentials } from '../../models/index.js';
8
- import { AuthenticationCredentialsRepository } from '../authentication-credentials.repository.js';
9
- export type MongoAuthenticationCredentialsRepositoryArgument = CollectionArgument<AuthenticationCredentials>;
10
- export type MongoAuthenticationCredentialsRepositoryConfig = MongoAuthenticationCredentialsRepositoryArgument;
11
- export declare class InternalMongoAuthenticationCredentialsRepository extends MongoEntityRepository<AuthenticationCredentials> implements Resolvable<MongoAuthenticationCredentialsRepositoryArgument> {
12
- readonly [resolveArgumentType]: MongoAuthenticationCredentialsRepositoryArgument;
13
- constructor(collection: Collection<AuthenticationCredentials>, logger: Logger);
14
- upsert(credentials: MaybeNewEntity<AuthenticationCredentials>): Promise<void>;
15
- }
16
- export declare class MongoAuthenticationCredentialsRepository extends AuthenticationCredentialsRepository {
17
- private readonly repository;
18
- constructor(repository: InternalMongoAuthenticationCredentialsRepository);
19
- tryLoadBySubject(subject: string): Promise<AuthenticationCredentials | undefined>;
20
- save(credentials: AuthenticationCredentials | NewAuthenticationCredentials): Promise<void>;
21
- }
22
- export declare function configureMongoAuthenticationCredentialsRepository(config: MongoAuthenticationCredentialsRepositoryConfig): void;
@@ -1,68 +0,0 @@
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 __param = (this && this.__param) || function (paramIndex, decorator) {
11
- return function (target, key) { decorator(target, key, paramIndex); }
12
- };
13
- import { getNewId } from '../../../database/index.js';
14
- import { Collection, MongoEntityRepository, noopTransformer } from '../../../database/mongo/index.js';
15
- import { ForwardArg, Singleton, resolveArgumentType } from '../../../injector/index.js';
16
- import { Logger } from '../../../logger/index.js';
17
- import { isUndefined } from '../../../utils/type-guards.js';
18
- import { AuthenticationCredentialsRepository } from '../authentication-credentials.repository.js';
19
- let defaultArgument;
20
- const indexes = [
21
- { key: { subject: 1 }, unique: true }
22
- ];
23
- let InternalMongoAuthenticationCredentialsRepository = class InternalMongoAuthenticationCredentialsRepository extends MongoEntityRepository {
24
- constructor(collection, logger) {
25
- super(collection, noopTransformer, { logger, indexes });
26
- }
27
- async upsert(credentials) {
28
- const { id: _, ...credentialsWithoutId } = credentials;
29
- await this.baseRepository.update({ subject: credentials.subject }, { $setOnInsert: { _id: getNewId() }, $set: credentialsWithoutId }, { upsert: true });
30
- }
31
- };
32
- InternalMongoAuthenticationCredentialsRepository = __decorate([
33
- Singleton({
34
- defaultArgumentProvider: () => defaultArgument
35
- }),
36
- __param(0, ForwardArg()),
37
- __metadata("design:paramtypes", [Collection, Logger])
38
- ], InternalMongoAuthenticationCredentialsRepository);
39
- export { InternalMongoAuthenticationCredentialsRepository };
40
- let MongoAuthenticationCredentialsRepository = class MongoAuthenticationCredentialsRepository extends AuthenticationCredentialsRepository {
41
- repository;
42
- constructor(repository) {
43
- super();
44
- this.repository = repository;
45
- }
46
- async tryLoadBySubject(subject) {
47
- const credentials = await this.repository.tryLoadByFilter({ subject });
48
- if (isUndefined(credentials)) {
49
- return credentials;
50
- }
51
- return {
52
- ...credentials,
53
- salt: credentials.salt.buffer,
54
- hash: credentials.hash.buffer
55
- };
56
- }
57
- async save(credentials) {
58
- await this.repository.upsert(credentials);
59
- }
60
- };
61
- MongoAuthenticationCredentialsRepository = __decorate([
62
- Singleton(),
63
- __metadata("design:paramtypes", [InternalMongoAuthenticationCredentialsRepository])
64
- ], MongoAuthenticationCredentialsRepository);
65
- export { MongoAuthenticationCredentialsRepository };
66
- export function configureMongoAuthenticationCredentialsRepository(config) {
67
- defaultArgument = config;
68
- }
@@ -1,23 +0,0 @@
1
- import type { CollectionArgument } from '../../../database/mongo/index.js';
2
- import { Collection, MongoEntityRepository } from '../../../database/mongo/index.js';
3
- import { resolveArgumentType } from '../../../injector/index.js';
4
- import type { Resolvable } from '../../../injector/interfaces.js';
5
- import { Logger } from '../../../logger/index.js';
6
- import type { AuthenticationSession, NewAuthenticationSession } from '../../models/index.js';
7
- import type { AuthenticationSessionExtendData } from '../authentication-session.repository.js';
8
- import { AuthenticationSessionRepository } from '../authentication-session.repository.js';
9
- export type MongoAuthenticationSessionRepositoryConfig = MongoAuthenticationSessionRepositoryArgument;
10
- export type MongoAuthenticationSessionRepositoryArgument = CollectionArgument<AuthenticationSession>;
11
- export declare class InternalMongoAuthenticationSessionRepository extends MongoEntityRepository<AuthenticationSession> implements Resolvable<MongoAuthenticationSessionRepositoryArgument> {
12
- readonly [resolveArgumentType]: MongoAuthenticationSessionRepositoryArgument;
13
- constructor(collection: Collection<AuthenticationSession>, logger: Logger);
14
- }
15
- export declare class MongoAuthenticationSessionRepository extends AuthenticationSessionRepository {
16
- private readonly repository;
17
- constructor(repository: InternalMongoAuthenticationSessionRepository);
18
- insert(authenticationSession: NewAuthenticationSession): Promise<AuthenticationSession>;
19
- load(id: string): Promise<AuthenticationSession>;
20
- extend(id: string, data: AuthenticationSessionExtendData): Promise<void>;
21
- end(id: string, timestamp: number): Promise<void>;
22
- }
23
- export declare function configureMongoAuthenticationSessionRepository(config: MongoAuthenticationSessionRepositoryConfig): void;
@@ -1,63 +0,0 @@
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 __param = (this && this.__param) || function (paramIndex, decorator) {
11
- return function (target, key) { decorator(target, key, paramIndex); }
12
- };
13
- import { Collection, MongoEntityRepository, noopTransformer } from '../../../database/mongo/index.js';
14
- import { ForwardArg, Singleton, resolveArgumentType } from '../../../injector/index.js';
15
- import { Logger } from '../../../logger/index.js';
16
- import { AuthenticationSessionRepository } from '../authentication-session.repository.js';
17
- let defaultArgument;
18
- const indexes = [];
19
- let InternalMongoAuthenticationSessionRepository = class InternalMongoAuthenticationSessionRepository extends MongoEntityRepository {
20
- constructor(collection, logger) {
21
- super(collection, noopTransformer, { logger, indexes });
22
- }
23
- };
24
- InternalMongoAuthenticationSessionRepository = __decorate([
25
- Singleton({
26
- defaultArgumentProvider: () => defaultArgument
27
- }),
28
- __param(0, ForwardArg()),
29
- __metadata("design:paramtypes", [Collection, Logger])
30
- ], InternalMongoAuthenticationSessionRepository);
31
- export { InternalMongoAuthenticationSessionRepository };
32
- let MongoAuthenticationSessionRepository = class MongoAuthenticationSessionRepository extends AuthenticationSessionRepository {
33
- repository;
34
- constructor(repository) {
35
- super();
36
- this.repository = repository;
37
- }
38
- async insert(authenticationSession) {
39
- return this.repository.insert(authenticationSession);
40
- }
41
- async load(id) {
42
- const session = await this.repository.load(id);
43
- return {
44
- ...session,
45
- refreshTokenSalt: session.refreshTokenSalt.buffer,
46
- refreshTokenHash: session.refreshTokenHash.buffer
47
- };
48
- }
49
- async extend(id, data) {
50
- await this.repository.patchByFilter({ id }, data);
51
- }
52
- async end(id, timestamp) {
53
- await this.repository.patchByFilter({ id }, { end: timestamp });
54
- }
55
- };
56
- MongoAuthenticationSessionRepository = __decorate([
57
- Singleton(),
58
- __metadata("design:paramtypes", [InternalMongoAuthenticationSessionRepository])
59
- ], MongoAuthenticationSessionRepository);
60
- export { MongoAuthenticationSessionRepository };
61
- export function configureMongoAuthenticationSessionRepository(config) {
62
- defaultArgument = config;
63
- }