@tstdl/base 0.82.6 → 0.82.8

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 (169) hide show
  1. package/api/client/client.js +2 -1
  2. package/api/client/client.js.map +1 -1
  3. package/api/types.d.ts +3 -3
  4. package/authentication/authentication.api.d.ts +98 -14
  5. package/authentication/authentication.api.js +31 -27
  6. package/authentication/authentication.api.js.map +1 -1
  7. package/authentication/client/api.client.d.ts +50 -0
  8. package/authentication/client/api.client.js +27 -0
  9. package/authentication/client/api.client.js.map +1 -0
  10. package/authentication/client/authentication.service.d.ts +39 -0
  11. package/authentication/client/authentication.service.js +176 -0
  12. package/authentication/client/authentication.service.js.map +1 -0
  13. package/authentication/client/index.d.ts +4 -0
  14. package/authentication/client/index.js +21 -0
  15. package/authentication/client/index.js.map +1 -0
  16. package/authentication/client/module.d.ts +8 -0
  17. package/authentication/client/module.js +16 -0
  18. package/authentication/client/module.js.map +1 -0
  19. package/authentication/client/tokens.d.ts +4 -0
  20. package/authentication/client/tokens.js +7 -0
  21. package/authentication/client/tokens.js.map +1 -0
  22. package/authentication/index.d.ts +2 -0
  23. package/authentication/index.js +19 -0
  24. package/authentication/index.js.map +1 -0
  25. package/authentication/models/authentication-session.model.d.ts +0 -2
  26. package/authentication/models/authentication-session.model.js +0 -10
  27. package/authentication/models/authentication-session.model.js.map +1 -1
  28. package/authentication/models/index.d.ts +1 -0
  29. package/authentication/models/index.js +1 -0
  30. package/authentication/models/index.js.map +1 -1
  31. package/authentication/models/token-payload-base.model.d.ts +7 -0
  32. package/authentication/models/token-payload-base.model.js +19 -0
  33. package/authentication/models/token-payload-base.model.js.map +1 -1
  34. package/authentication/models/token.model.d.ts +16 -0
  35. package/authentication/models/token.model.js +3 -0
  36. package/authentication/models/token.model.js.map +1 -0
  37. package/authentication/{authentication-credentials.repository.d.ts → server/authentication-credentials.repository.d.ts} +2 -2
  38. package/authentication/{authentication-credentials.repository.js → server/authentication-credentials.repository.js} +1 -1
  39. package/authentication/server/authentication-credentials.repository.js.map +1 -0
  40. package/authentication/{authentication-session.repository.d.ts → server/authentication-session.repository.d.ts} +2 -3
  41. package/authentication/{authentication-session.repository.js → server/authentication-session.repository.js} +0 -0
  42. package/authentication/server/authentication-session.repository.js.map +1 -0
  43. package/authentication/server/authentication-token-payload.provider.d.ts +3 -0
  44. package/authentication/{authentication-token-payload.provider.js → server/authentication-token-payload.provider.js} +1 -1
  45. package/authentication/server/authentication-token-payload.provider.js.map +1 -0
  46. package/authentication/server/authentication.api-controller.d.ts +13 -0
  47. package/authentication/server/authentication.api-controller.js +65 -0
  48. package/authentication/server/authentication.api-controller.js.map +1 -0
  49. package/authentication/{authentication.service.d.ts → server/authentication.service.d.ts} +23 -11
  50. package/authentication/{authentication.service.js → server/authentication.service.js} +92 -47
  51. package/authentication/server/authentication.service.js.map +1 -0
  52. package/authentication/server/helper.d.ts +13 -0
  53. package/authentication/server/helper.js +62 -0
  54. package/authentication/server/helper.js.map +1 -0
  55. package/authentication/server/index.d.ts +8 -0
  56. package/authentication/server/index.js +25 -0
  57. package/authentication/server/index.js.map +1 -0
  58. package/authentication/server/module.d.ts +12 -0
  59. package/authentication/server/module.js +19 -0
  60. package/authentication/server/module.js.map +1 -0
  61. package/authentication/server/mongo/index.d.ts +2 -0
  62. package/authentication/server/mongo/index.js +19 -0
  63. package/authentication/server/mongo/index.js.map +1 -0
  64. package/authentication/{mongo → server/mongo}/mongo-authentication-credentials.repository.d.ts +15 -18
  65. package/authentication/{mongo → server/mongo}/mongo-authentication-credentials.repository.js +36 -27
  66. package/authentication/server/mongo/mongo-authentication-credentials.repository.js.map +1 -0
  67. package/authentication/{mongo → server/mongo}/mongo-authentication-session.repository.d.ts +12 -15
  68. package/authentication/{mongo → server/mongo}/mongo-authentication-session.repository.js +27 -22
  69. package/authentication/server/mongo/mongo-authentication-session.repository.js.map +1 -0
  70. package/authentication/{tokens.d.ts → server/tokens.d.ts} +1 -1
  71. package/authentication/{tokens.js → server/tokens.js} +1 -1
  72. package/authentication/server/tokens.js.map +1 -0
  73. package/container/token.d.ts +2 -2
  74. package/container/types.d.ts +2 -1
  75. package/cookie/cookie.d.ts +14 -0
  76. package/cookie/cookie.js +58 -0
  77. package/cookie/cookie.js.map +1 -0
  78. package/cookie/index.d.ts +1 -0
  79. package/cookie/index.js +18 -0
  80. package/cookie/index.js.map +1 -0
  81. package/examples/api/authentication.d.ts +1 -0
  82. package/examples/api/authentication.js +51 -0
  83. package/examples/api/authentication.js.map +1 -0
  84. package/examples/api/basic-overview.js +4 -4
  85. package/examples/api/basic-overview.js.map +1 -1
  86. package/examples/api/custom-authentication.d.ts +1 -0
  87. package/examples/api/custom-authentication.js +89 -0
  88. package/examples/api/custom-authentication.js.map +1 -0
  89. package/examples/api/streaming.js +10 -8
  90. package/examples/api/streaming.js.map +1 -1
  91. package/http/cookie-parser.d.ts +1 -3
  92. package/http/cookie-parser.js +10 -19
  93. package/http/cookie-parser.js.map +1 -1
  94. package/http/http-headers.d.ts +2 -2
  95. package/http/http-headers.js +11 -11
  96. package/http/http-headers.js.map +1 -1
  97. package/http/http-value-map.js +13 -13
  98. package/http/http-value-map.js.map +1 -1
  99. package/http/server/http-server-response.d.ts +8 -3
  100. package/http/server/http-server-response.js +8 -0
  101. package/http/server/http-server-response.js.map +1 -1
  102. package/http/server/node/module.d.ts +2 -2
  103. package/http/server/node/module.js +3 -5
  104. package/http/server/node/module.js.map +1 -1
  105. package/mail/clients/nodemailer.mail-client.js +1 -1
  106. package/mail/clients/nodemailer.mail-client.js.map +1 -1
  107. package/message-bus/broadcast-channel/broadcast-channel-message-bus-provider.d.ts +1 -1
  108. package/message-bus/broadcast-channel/broadcast-channel-message-bus-provider.js +21 -2
  109. package/message-bus/broadcast-channel/broadcast-channel-message-bus-provider.js.map +1 -1
  110. package/message-bus/broadcast-channel/broadcast-channel-message-bus.d.ts +4 -4
  111. package/message-bus/broadcast-channel/broadcast-channel-message-bus.js +27 -4
  112. package/message-bus/broadcast-channel/broadcast-channel-message-bus.js.map +1 -1
  113. package/message-bus/broadcast-channel/index.d.ts +1 -0
  114. package/message-bus/broadcast-channel/index.js +1 -0
  115. package/message-bus/broadcast-channel/index.js.map +1 -1
  116. package/message-bus/broadcast-channel/module.d.ts +4 -0
  117. package/message-bus/broadcast-channel/module.js +17 -0
  118. package/message-bus/broadcast-channel/module.js.map +1 -0
  119. package/message-bus/local/index.d.ts +1 -0
  120. package/message-bus/local/index.js +1 -0
  121. package/message-bus/local/index.js.map +1 -1
  122. package/message-bus/local/local-message-bus-provider.d.ts +0 -5
  123. package/message-bus/local/local-message-bus-provider.js +1 -13
  124. package/message-bus/local/local-message-bus-provider.js.map +1 -1
  125. package/message-bus/local/local-message-bus.d.ts +1 -1
  126. package/message-bus/local/local-message-bus.js +2 -2
  127. package/message-bus/local/local-message-bus.js.map +1 -1
  128. package/message-bus/local/module.d.ts +4 -0
  129. package/message-bus/local/module.js +17 -0
  130. package/message-bus/local/module.js.map +1 -0
  131. package/message-bus/message-bus-base.d.ts +1 -1
  132. package/message-bus/message-bus-base.js +1 -1
  133. package/message-bus/message-bus-base.js.map +1 -1
  134. package/message-bus/message-bus.d.ts +1 -0
  135. package/message-bus/message-bus.js +3 -0
  136. package/message-bus/message-bus.js.map +1 -1
  137. package/notification/notification.service.js +2 -2
  138. package/notification/notification.service.js.map +1 -1
  139. package/object-storage/s3/s3.object.js +3 -3
  140. package/object-storage/s3/s3.object.js.map +1 -1
  141. package/package.json +4 -4
  142. package/schema/schemas/assign.js +2 -0
  143. package/schema/schemas/assign.js.map +1 -1
  144. package/schema/schemas/object.d.ts +1 -0
  145. package/schema/schemas/object.js +2 -1
  146. package/schema/schemas/object.js.map +1 -1
  147. package/schema/types/types.d.ts +1 -1
  148. package/schema/utils/schema.js.map +1 -1
  149. package/utils/array/array.js +2 -2
  150. package/utils/array/array.js.map +1 -1
  151. package/utils/string/index.d.ts +1 -0
  152. package/utils/string/index.js +1 -0
  153. package/utils/string/index.js.map +1 -1
  154. package/utils/string/title-case.d.ts +1 -0
  155. package/utils/string/title-case.js +13 -0
  156. package/utils/string/title-case.js.map +1 -0
  157. package/utils/type-guards.d.ts +1 -1
  158. package/utils/type-guards.js.map +1 -1
  159. package/utils/type-of.d.ts +1 -1
  160. package/utils/type-of.js +3 -4
  161. package/utils/type-of.js.map +1 -1
  162. package/authentication/authentication-credentials.repository.js.map +0 -1
  163. package/authentication/authentication-session.repository.js.map +0 -1
  164. package/authentication/authentication-token-payload.provider.d.ts +0 -3
  165. package/authentication/authentication-token-payload.provider.js.map +0 -1
  166. package/authentication/authentication.service.js.map +0 -1
  167. package/authentication/mongo/mongo-authentication-credentials.repository.js.map +0 -1
  168. package/authentication/mongo/mongo-authentication-session.repository.js.map +0 -1
  169. package/authentication/tokens.js.map +0 -1
@@ -13,21 +13,22 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.AuthenticationService = void 0;
16
- const container_1 = require("../container");
17
- const error_1 = require("../error");
18
- const invalid_token_error_1 = require("../error/invalid-token.error");
19
- const alphabet_1 = require("../utils/alphabet");
20
- const cryptography_1 = require("../utils/cryptography");
21
- const date_time_1 = require("../utils/date-time");
22
- const equals_1 = require("../utils/equals");
23
- const jwt_1 = require("../utils/jwt");
24
- const random_1 = require("../utils/random");
25
- const type_guards_1 = require("../utils/type-guards");
26
- const units_1 = require("../utils/units");
16
+ const container_1 = require("../../container");
17
+ const invalid_token_error_1 = require("../../error/invalid-token.error");
18
+ const alphabet_1 = require("../../utils/alphabet");
19
+ const cryptography_1 = require("../../utils/cryptography");
20
+ const date_time_1 = require("../../utils/date-time");
21
+ const equals_1 = require("../../utils/equals");
22
+ const jwt_1 = require("../../utils/jwt");
23
+ const random_1 = require("../../utils/random");
24
+ const type_guards_1 = require("../../utils/type-guards");
25
+ const units_1 = require("../../utils/units");
27
26
  const authentication_credentials_repository_1 = require("./authentication-credentials.repository");
28
27
  const authentication_session_repository_1 = require("./authentication-session.repository");
29
28
  const authentication_token_payload_provider_1 = require("./authentication-token-payload.provider");
29
+ const helper_1 = require("./helper");
30
30
  const tokens_1 = require("./tokens");
31
+ const SIGNING_SECRETS_LENGTH = 512;
31
32
  let AuthenticationService = class AuthenticationService {
32
33
  credentialsRepository;
33
34
  sessionRepository;
@@ -36,6 +37,8 @@ let AuthenticationService = class AuthenticationService {
36
37
  tokenVersion;
37
38
  tokenTimeToLive;
38
39
  sessionTimeToLive;
40
+ derivedTokenSigningSecret;
41
+ derivedRefreshTokenSigningSecret;
39
42
  constructor(credentialsService, sessionRepository, tokenPayloadProviderService, options) {
40
43
  this.credentialsRepository = credentialsService;
41
44
  this.sessionRepository = sessionRepository;
@@ -45,6 +48,12 @@ let AuthenticationService = class AuthenticationService {
45
48
  this.tokenTimeToLive = options.tokenTimeToLive ?? (5 * units_1.millisecondsPerMinute);
46
49
  this.sessionTimeToLive = options.sessionTimeToLive ?? (5 * units_1.millisecondsPerDay);
47
50
  }
51
+ async [container_1.afterResolve]() {
52
+ await this.initialize();
53
+ }
54
+ async initialize() {
55
+ await this.deriveSigningSecrets();
56
+ }
48
57
  async setCredentials(subject, secret) {
49
58
  const salt = (0, random_1.getRandomBytes)(32);
50
59
  const hash = await this.getHash(secret, salt);
@@ -57,67 +66,78 @@ let AuthenticationService = class AuthenticationService {
57
66
  await this.credentialsRepository.save(credentials);
58
67
  }
59
68
  async authenticate(subject, secret) {
60
- const credentials = await this.credentialsRepository.tryLoad(subject);
69
+ const credentials = await this.credentialsRepository.tryLoadBySubject(subject);
61
70
  if ((0, type_guards_1.isUndefined)(credentials)) {
62
- return false;
71
+ return { success: false };
63
72
  }
64
73
  const hash = await this.getHash(secret, credentials.salt);
65
- return (0, equals_1.binaryEquals)(hash, credentials.hash);
66
- }
67
- async getToken(subject, secret, additionalAuthenticationData) {
68
- const isAuthenticated = await this.authenticate(subject, secret);
69
- if (!isAuthenticated) {
70
- throw new error_1.UnauthorizedError('Invalid credentials.');
74
+ const valid = (0, equals_1.binaryEquals)(hash, credentials.hash);
75
+ if (valid) {
76
+ return { success: true, subject: credentials.subject };
71
77
  }
78
+ return { success: false };
79
+ }
80
+ async getToken(subject, additionalAuthenticationData) {
72
81
  const now = (0, date_time_1.currentTimestamp)();
73
- const tokenPayload = await this.tokenPayloadProviderService.getTokenPayload(subject, additionalAuthenticationData);
74
- const { token, payload } = await this.createToken(tokenPayload, now);
75
- const refreshToken = await this.createRefreshToken();
76
- await this.sessionRepository.insert({
82
+ const end = now + this.sessionTimeToLive;
83
+ const session = await this.sessionRepository.insert({
77
84
  subject,
78
85
  begin: now,
79
- end: now + this.sessionTimeToLive,
80
- tokenId: payload.jti,
86
+ end,
87
+ refreshTokenHashVersion: 0,
88
+ refreshTokenSalt: new Uint8Array(),
89
+ refreshTokenHash: new Uint8Array()
90
+ });
91
+ const tokenPayload = await this.tokenPayloadProviderService?.getTokenPayload(subject, additionalAuthenticationData);
92
+ const { token, jsonToken } = await this.createToken(tokenPayload, subject, session.id, end, now);
93
+ const refreshToken = await this.createRefreshToken(subject, session.id, end);
94
+ await this.sessionRepository.extend(session.id, {
95
+ end,
81
96
  refreshTokenHashVersion: 1,
82
97
  refreshTokenSalt: refreshToken.salt,
83
98
  refreshTokenHash: refreshToken.hash
84
99
  });
85
- return { token, refreshToken: refreshToken.token };
100
+ return { token, jsonToken, refreshToken: refreshToken.token };
86
101
  }
87
102
  async endSession(sessionId) {
88
103
  const now = (0, date_time_1.currentTimestamp)();
89
104
  await this.sessionRepository.end(sessionId, now);
90
105
  }
91
- async refresh(sessionId, refreshToken, additionalAuthenticationData) {
106
+ async refresh(refreshToken, additionalAuthenticationData) {
107
+ const validatedToken = await this.validateRefreshToken(refreshToken);
108
+ const sessionId = validatedToken.payload.sessionId;
92
109
  const session = await this.sessionRepository.load(sessionId);
93
- const hash = await this.getHash(refreshToken, session.refreshTokenSalt);
110
+ const hash = await this.getHash(validatedToken.payload.secret, session.refreshTokenSalt);
94
111
  if (session.end <= (0, date_time_1.currentTimestamp)()) {
95
- throw new error_1.UnauthorizedError('Session is ended.');
112
+ throw new invalid_token_error_1.InvalidTokenError('Session is expired.');
96
113
  }
97
114
  if (!(0, equals_1.binaryEquals)(hash, session.refreshTokenHash)) {
98
- throw new error_1.UnauthorizedError('Invalid refresh token.');
115
+ throw new invalid_token_error_1.InvalidTokenError('Invalid refresh token.');
99
116
  }
100
117
  const now = (0, date_time_1.currentTimestamp)();
101
- const tokenPayload = await this.tokenPayloadProviderService.getTokenPayload(session.subject, additionalAuthenticationData);
102
- const { token, payload } = await this.createToken(tokenPayload, now);
103
- const newRefreshToken = await this.createRefreshToken();
118
+ const newEnd = now + this.sessionTimeToLive;
119
+ const tokenPayload = await this.tokenPayloadProviderService?.getTokenPayload(session.subject, additionalAuthenticationData);
120
+ const { token, jsonToken } = await this.createToken(tokenPayload, session.subject, sessionId, newEnd, now);
121
+ const newRefreshToken = await this.createRefreshToken(validatedToken.payload.subject, sessionId, newEnd);
104
122
  await this.sessionRepository.extend(sessionId, {
105
- end: now + this.sessionTimeToLive,
106
- tokenId: payload.jti,
123
+ end: newEnd,
107
124
  refreshTokenHashVersion: 1,
108
125
  refreshTokenSalt: newRefreshToken.salt,
109
126
  refreshTokenHash: newRefreshToken.hash
110
127
  });
111
- return { token, refreshToken: newRefreshToken.token };
128
+ return { token, jsonToken, refreshToken: newRefreshToken.token };
112
129
  }
113
130
  async validateToken(token) {
114
- const validatedToken = await (0, jwt_1.parseAndValidateJwtTokenString)(token, 'HS256', this.secret);
115
- if (validatedToken.header.v != this.tokenVersion) {
116
- throw new invalid_token_error_1.InvalidTokenError('Invalid token version.');
131
+ return (0, helper_1.getTokenFromString)(token, this.tokenVersion, this.derivedTokenSigningSecret);
132
+ }
133
+ async validateRefreshToken(token) {
134
+ const validatedToken = await (0, jwt_1.parseAndValidateJwtTokenString)(token, 'HS256', this.derivedRefreshTokenSigningSecret);
135
+ if (validatedToken.payload.exp <= (0, date_time_1.currentTimestampSeconds)()) {
136
+ throw new invalid_token_error_1.InvalidTokenError('Token expired.');
117
137
  }
118
138
  return validatedToken;
119
139
  }
120
- async createToken(additionalTokenPayload, timestamp = (0, date_time_1.currentTimestamp)()) {
140
+ async createToken(additionalTokenPayload, subject, sessionId, refreshTokenExpiration, timestamp) {
121
141
  const header = {
122
142
  v: this.tokenVersion,
123
143
  alg: 'HS256',
@@ -127,19 +147,43 @@ let AuthenticationService = class AuthenticationService {
127
147
  jti: (0, random_1.getRandomString)(24, alphabet_1.Alphabet.LowerUpperCaseNumbers),
128
148
  iat: (0, date_time_1.timestampToTimestampSeconds)(timestamp),
129
149
  exp: (0, date_time_1.timestampToTimestampSeconds)(timestamp + this.tokenTimeToLive),
150
+ refreshTokenExp: (0, date_time_1.timestampToTimestampSeconds)(refreshTokenExpiration),
151
+ sessionId,
152
+ subject,
130
153
  ...additionalTokenPayload
131
154
  };
132
- const token = await (0, jwt_1.createJwtTokenString)({
155
+ const jsonToken = {
133
156
  header,
134
157
  payload
135
- }, this.secret);
136
- return { header, payload, token };
158
+ };
159
+ const token = await (0, jwt_1.createJwtTokenString)(jsonToken, this.derivedTokenSigningSecret);
160
+ return { token, jsonToken };
137
161
  }
138
- async createRefreshToken() {
139
- const token = (0, random_1.getRandomString)(64, alphabet_1.Alphabet.LowerUpperCaseNumbers);
162
+ async createRefreshToken(subject, sessionId, expirationTimestamp) {
163
+ const secret = (0, random_1.getRandomString)(64, alphabet_1.Alphabet.LowerUpperCaseNumbers);
140
164
  const salt = (0, random_1.getRandomBytes)(32);
141
- const hash = await this.getHash(token, salt);
142
- return { token, salt, hash: new Uint8Array(hash) };
165
+ const hash = await this.getHash(secret, salt);
166
+ const jsonToken = {
167
+ header: {
168
+ alg: 'HS256',
169
+ typ: 'JWT'
170
+ },
171
+ payload: {
172
+ exp: (0, date_time_1.timestampToTimestampSeconds)(expirationTimestamp),
173
+ subject,
174
+ sessionId,
175
+ secret
176
+ }
177
+ };
178
+ const token = await (0, jwt_1.createJwtTokenString)(jsonToken, this.derivedRefreshTokenSigningSecret);
179
+ return { token, jsonToken, salt, hash: new Uint8Array(hash) };
180
+ }
181
+ async deriveSigningSecrets() {
182
+ const key = await (0, cryptography_1.importPbkdf2Key)(this.secret);
183
+ const hash = await globalThis.crypto.subtle.deriveBits({ name: 'PBKDF2', hash: 'SHA-512', iterations: 500000, salt: new Uint8Array() }, key, SIGNING_SECRETS_LENGTH * 2);
184
+ const bufferSize = SIGNING_SECRETS_LENGTH / 8;
185
+ this.derivedTokenSigningSecret = new Uint8Array(hash.slice(0, bufferSize));
186
+ this.derivedRefreshTokenSigningSecret = new Uint8Array(hash.slice(bufferSize));
143
187
  }
144
188
  async getHash(secret, salt) {
145
189
  const key = await (0, cryptography_1.importPbkdf2Key)(secret);
@@ -149,6 +193,7 @@ let AuthenticationService = class AuthenticationService {
149
193
  };
150
194
  AuthenticationService = __decorate([
151
195
  (0, container_1.singleton)(),
196
+ __param(2, (0, container_1.optional)()),
152
197
  __param(3, (0, container_1.inject)(tokens_1.AUTHENTICATION_SERVICE_OPTIONS)),
153
198
  __metadata("design:paramtypes", [authentication_credentials_repository_1.AuthenticationCredentialsRepository,
154
199
  authentication_session_repository_1.AuthenticationSessionRepository,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.service.js","sourceRoot":"","sources":["../../../source/authentication/server/authentication.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,+CAAwE;AACxE,yEAAgE;AAEhE,mDAA4C;AAC5C,2DAAuD;AACvD,qDAA2G;AAC3G,+CAA8C;AAC9C,yCAAmF;AACnF,+CAAiE;AACjE,yDAAkD;AAClD,6CAA0E;AAE1E,mGAA8F;AAC9F,2FAAsF;AACtF,mGAA6F;AAC7F,qCAA8C;AAC9C,qCAA0D;AAsC1D,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAG5B,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IACf,qBAAqB,CAAsC;IAC3D,iBAAiB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AAS,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QAEhI,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;CACF,CAAA;AAlNY,qBAAqB;IADjC,IAAA,qBAAS,GAAE;IAiBP,WAAA,IAAA,oBAAQ,GAAE,CAAA;IACV,WAAA,IAAA,kBAAM,EAAC,uCAA8B,CAAC,CAAA;qCAHnB,2EAAmC;QACpC,mEAA+B;QACT,0EAAkC;GAhBlE,qBAAqB,CAkNjC;AAlNY,sDAAqB"}
@@ -0,0 +1,13 @@
1
+ import type { HttpServerRequest } from "../../http/server";
2
+ import type { Record } from "../../types";
3
+ import type { Token } from '../models';
4
+ /**
5
+ *
6
+ * @param request
7
+ * @param cookieName (default "authorization")
8
+ * @returns token string
9
+ */
10
+ export declare function tryGetAuthorizationTokenStringFromRequest(request: HttpServerRequest, cookieName?: string): string | undefined;
11
+ export declare function tryGetTokenFromRequest<AdditionalTokenPayload = Record<never>>(request: HttpServerRequest, tokenVersion: number, secret: string | BinaryData): Promise<Token<AdditionalTokenPayload> | undefined>;
12
+ export declare function getTokenFromRequest<AdditionalTokenPayload = Record<never>>(request: HttpServerRequest, tokenVersion: number, secret: string | BinaryData): Promise<Token<AdditionalTokenPayload>>;
13
+ export declare function getTokenFromString<AdditionalTokenPayload = Record<never>>(tokenString: string, tokenVersion: number, secret: string | BinaryData): Promise<Token<AdditionalTokenPayload>>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTokenFromString = exports.getTokenFromRequest = exports.tryGetTokenFromRequest = exports.tryGetAuthorizationTokenStringFromRequest = void 0;
4
+ const bad_request_error_1 = require("../../error/bad-request.error");
5
+ const invalid_token_error_1 = require("../../error/invalid-token.error");
6
+ const unauthorized_error_1 = require("../../error/unauthorized.error");
7
+ const date_time_1 = require("../../utils/date-time");
8
+ const jwt_1 = require("../../utils/jwt");
9
+ const type_guards_1 = require("../../utils/type-guards");
10
+ /**
11
+ *
12
+ * @param request
13
+ * @param cookieName (default "authorization")
14
+ * @returns token string
15
+ */
16
+ function tryGetAuthorizationTokenStringFromRequest(request, cookieName = 'authorization') {
17
+ const authorizationHeaders = request.headers.tryGet('Authorization');
18
+ const authorizationString = ((0, type_guards_1.isArray)(authorizationHeaders) ? authorizationHeaders[0] : authorizationHeaders)
19
+ ?? request.cookies.tryGet(cookieName);
20
+ if ((0, type_guards_1.isDefined)(authorizationString)) {
21
+ const authorizationSchemeEnd = authorizationString.indexOf(' ');
22
+ const authorizationScheme = authorizationString.slice(0, authorizationSchemeEnd).trim().toLowerCase();
23
+ if (authorizationScheme == 'bearer') {
24
+ throw new bad_request_error_1.BadRequestError(`Unsupported authorization scheme "${authorizationScheme}".`);
25
+ }
26
+ const authorization = authorizationString.slice(authorizationSchemeEnd).trim();
27
+ return authorization;
28
+ }
29
+ return undefined;
30
+ }
31
+ exports.tryGetAuthorizationTokenStringFromRequest = tryGetAuthorizationTokenStringFromRequest;
32
+ async function tryGetTokenFromRequest(request, tokenVersion, secret) {
33
+ const tokenString = tryGetAuthorizationTokenStringFromRequest(request);
34
+ if ((0, type_guards_1.isUndefined)(tokenString)) {
35
+ return undefined;
36
+ }
37
+ return getTokenFromString(tokenString, tokenVersion, secret);
38
+ }
39
+ exports.tryGetTokenFromRequest = tryGetTokenFromRequest;
40
+ async function getTokenFromRequest(request, tokenVersion, secret) {
41
+ const token = await tryGetTokenFromRequest(request, tokenVersion, secret);
42
+ if ((0, type_guards_1.isUndefined)(token)) {
43
+ throw new unauthorized_error_1.UnauthorizedError('Missing authorization.');
44
+ }
45
+ return token;
46
+ }
47
+ exports.getTokenFromRequest = getTokenFromRequest;
48
+ async function getTokenFromString(tokenString, tokenVersion, secret) {
49
+ if ((0, type_guards_1.isUndefined)(tokenString)) {
50
+ throw new unauthorized_error_1.UnauthorizedError('Missing authorization.');
51
+ }
52
+ const validatedToken = await (0, jwt_1.parseAndValidateJwtTokenString)(tokenString, 'HS256', secret);
53
+ if (validatedToken.header.v != tokenVersion) {
54
+ throw new invalid_token_error_1.InvalidTokenError('Invalid token version.');
55
+ }
56
+ if (validatedToken.payload.exp <= (0, date_time_1.currentTimestampSeconds)()) {
57
+ throw new invalid_token_error_1.InvalidTokenError('Token expired.');
58
+ }
59
+ return validatedToken;
60
+ }
61
+ exports.getTokenFromString = getTokenFromString;
62
+ //# sourceMappingURL=helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../source/authentication/server/helper.ts"],"names":[],"mappings":";;;AAAA,qEAA4D;AAC5D,yEAAgE;AAChE,uEAA+D;AAG/D,qDAA4D;AAC5D,yCAA6D;AAC7D,yDAAsE;AAGtE;;;;;GAKG;AACH,SAAgB,yCAAyC,CAAC,OAA0B,EAAE,aAAqB,eAAe;IACxH,MAAM,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAkC,CAAC;IAEtG,MAAM,mBAAmB,GAAG,CAAC,IAAA,qBAAO,EAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC;WACvG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAExC,IAAI,IAAA,uBAAS,EAAC,mBAAmB,CAAC,EAAE;QAClC,MAAM,sBAAsB,GAAG,mBAAmB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAChE,MAAM,mBAAmB,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE,sBAAsB,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAEtG,IAAI,mBAAmB,IAAI,QAAQ,EAAE;YACnC,MAAM,IAAI,mCAAe,CAAC,qCAAqC,mBAAmB,IAAI,CAAC,CAAC;SACzF;QAED,MAAM,aAAa,GAAG,mBA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AAI,uCAAiB,CAAC,gBAAgB,CAAC,CAAC;KAC/C;IAED,OAAO,cAAc,CAAC;AACxB,CAAC;AAhBD,gDAgBC"}
@@ -0,0 +1,8 @@
1
+ export * from './authentication-credentials.repository';
2
+ export * from './authentication-session.repository';
3
+ export * from './authentication-token-payload.provider';
4
+ export * from './authentication.api-controller';
5
+ export * from './authentication.service';
6
+ export * from './helper';
7
+ export * from './module';
8
+ export * from './tokens';
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./authentication-credentials.repository"), exports);
18
+ __exportStar(require("./authentication-session.repository"), exports);
19
+ __exportStar(require("./authentication-token-payload.provider"), exports);
20
+ __exportStar(require("./authentication.api-controller"), exports);
21
+ __exportStar(require("./authentication.service"), exports);
22
+ __exportStar(require("./helper"), exports);
23
+ __exportStar(require("./module"), exports);
24
+ __exportStar(require("./tokens"), exports);
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/authentication/server/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0EAAwD;AACxD,sEAAoD;AACpD,0EAAwD;AACxD,kEAAgD;AAChD,2DAAyC;AACzC,2CAAyB;AACzB,2CAAyB;AACzB,2CAAyB"}
@@ -0,0 +1,12 @@
1
+ import type { Type } from "../../types";
2
+ import { AuthenticationCredentialsRepository } from './authentication-credentials.repository';
3
+ import { AuthenticationSessionRepository } from './authentication-session.repository';
4
+ import { AuthenticationTokenPayloadProvider } from './authentication-token-payload.provider';
5
+ import type { AuthenticationServiceOptions } from './authentication.service';
6
+ export type AuthenticationModuleConfig = {
7
+ serviceOptions: AuthenticationServiceOptions;
8
+ credentialsRepository: Type<AuthenticationCredentialsRepository>;
9
+ sessionRepository: Type<AuthenticationSessionRepository>;
10
+ tokenPayloadProvider?: Type<AuthenticationTokenPayloadProvider>;
11
+ };
12
+ export declare function configureAuthenticationServer(config: AuthenticationModuleConfig): void;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureAuthenticationServer = void 0;
4
+ const container_1 = require("../../container");
5
+ const type_guards_1 = require("../../utils/type-guards");
6
+ const authentication_credentials_repository_1 = require("./authentication-credentials.repository");
7
+ const authentication_session_repository_1 = require("./authentication-session.repository");
8
+ const authentication_token_payload_provider_1 = require("./authentication-token-payload.provider");
9
+ const tokens_1 = require("./tokens");
10
+ function configureAuthenticationServer(config) {
11
+ container_1.container.register(tokens_1.AUTHENTICATION_SERVICE_OPTIONS, { useValue: config.serviceOptions });
12
+ container_1.container.registerSingleton(authentication_credentials_repository_1.AuthenticationCredentialsRepository, { useToken: config.credentialsRepository });
13
+ container_1.container.registerSingleton(authentication_session_repository_1.AuthenticationSessionRepository, { useToken: config.sessionRepository });
14
+ if ((0, type_guards_1.isDefined)(config.tokenPayloadProvider)) {
15
+ container_1.container.registerSingleton(authentication_token_payload_provider_1.AuthenticationTokenPayloadProvider, { useToken: config.tokenPayloadProvider });
16
+ }
17
+ }
18
+ exports.configureAuthenticationServer = configureAuthenticationServer;
19
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../../../source/authentication/server/module.ts"],"names":[],"mappings":";;;AAAA,+CAAwC;AAExC,yDAAgD;AAChD,mGAA8F;AAC9F,2FAAsF;AACtF,mGAA6F;AAE7F,qCAA0D;AAS1D,SAAgB,6BAA6B,CAAC,MAAkC;IAC9E,qBAAS,CAAC,QAAQ,CAAC,uCAA8B,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC;IACxF,qBAAS,CAAC,iBAAiB,CAAC,2EAAmC,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,qBAAqB,EAAE,CAAC,CAAC;IAC7G,qBAAS,CAAC,iBAAiB,CAAC,mEAA+B,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAErG,IAAI,IAAA,uBAAS,EAAC,MAAM,CAAC,oBAAoB,CAAC,EAAE;QAC1C,qBAAS,CAAC,iBAAiB,CAAC,0EAAkC,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,oBAAoB,EAAE,CAAC,CAAC;KAC5G;AACH,CAAC;AARD,sEAQC"}
@@ -0,0 +1,2 @@
1
+ export * from './mongo-authentication-credentials.repository';
2
+ export * from './mongo-authentication-session.repository';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./mongo-authentication-credentials.repository"), exports);
18
+ __exportStar(require("./mongo-authentication-session.repository"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../source/authentication/server/mongo/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gFAA8D;AAC9D,4EAA0D"}
@@ -1,25 +1,22 @@
1
- import type { Injectable } from "../../container";
2
- import { resolveArgumentType } from "../../container";
3
- import { MaybeNewEntity } from "../../database";
4
- import type { CollectionArgument } from "../../database/mongo";
5
- import { Collection, MongoEntityRepository } from "../../database/mongo";
6
- import { Logger } from "../../logger";
1
+ import type { Injectable } from "../../../container";
2
+ import { resolveArgumentType } from "../../../container";
3
+ import type { MaybeNewEntity } from "../../../database";
4
+ import type { CollectionArgument } from "../../../database/mongo";
5
+ import { Collection, MongoEntityRepository } from "../../../database/mongo";
6
+ import { Logger } from "../../../logger";
7
+ import type { AuthenticationCredentials, NewAuthenticationCredentials } from '../../models';
7
8
  import { AuthenticationCredentialsRepository } from '../authentication-credentials.repository';
8
- import type { AuthenticationCredentials, NewAuthenticationCredentials } from '../models';
9
- export type MongoAuthenticationCredentialsRepositoryConfig = {
10
- config?: MongoAuthenticationCredentialsRepositoryArgument;
11
- };
12
9
  export type MongoAuthenticationCredentialsRepositoryArgument = CollectionArgument<AuthenticationCredentials>;
13
- export declare const mongoAuthenticationCredentialsRepositoryConfig: MongoAuthenticationCredentialsRepositoryConfig;
14
- export declare class MongoAuthenticationCredentialsRepository extends AuthenticationCredentialsRepository {
15
- private readonly repository;
16
- constructor(repository: InternalMongoAuthenticationCredentialsRepository);
17
- tryLoad(id: string): Promise<AuthenticationCredentials | undefined>;
18
- save(credentials: AuthenticationCredentials | NewAuthenticationCredentials): Promise<void>;
19
- }
10
+ export type MongoAuthenticationCredentialsRepositoryConfig = MongoAuthenticationCredentialsRepositoryArgument;
20
11
  export declare class InternalMongoAuthenticationCredentialsRepository extends MongoEntityRepository<AuthenticationCredentials> implements Injectable<MongoAuthenticationCredentialsRepositoryArgument> {
21
12
  readonly [resolveArgumentType]: MongoAuthenticationCredentialsRepositoryArgument;
22
13
  constructor(collection: Collection<AuthenticationCredentials>, logger: Logger);
23
14
  upsert(credentials: MaybeNewEntity<AuthenticationCredentials>): Promise<void>;
24
15
  }
25
- export declare function configureMongoAuthenticationCredentialsRepository(config?: Partial<MongoAuthenticationCredentialsRepositoryConfig>): void;
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;
@@ -12,34 +12,17 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.configureMongoAuthenticationCredentialsRepository = exports.InternalMongoAuthenticationCredentialsRepository = exports.MongoAuthenticationCredentialsRepository = exports.mongoAuthenticationCredentialsRepositoryConfig = void 0;
16
- const container_1 = require("../../container");
17
- const database_1 = require("../../database");
18
- const mongo_1 = require("../../database/mongo");
19
- const logger_1 = require("../../logger");
15
+ exports.configureMongoAuthenticationCredentialsRepository = exports.MongoAuthenticationCredentialsRepository = exports.InternalMongoAuthenticationCredentialsRepository = void 0;
16
+ const container_1 = require("../../../container");
17
+ const database_1 = require("../../../database");
18
+ const mongo_1 = require("../../../database/mongo");
19
+ const logger_1 = require("../../../logger");
20
+ const type_guards_1 = require("../../../utils/type-guards");
20
21
  const authentication_credentials_repository_1 = require("../authentication-credentials.repository");
21
- exports.mongoAuthenticationCredentialsRepositoryConfig = {};
22
+ let defaultArgument;
22
23
  const indexes = [
23
24
  { key: { subject: 1 }, unique: true }
24
25
  ];
25
- let MongoAuthenticationCredentialsRepository = class MongoAuthenticationCredentialsRepository extends authentication_credentials_repository_1.AuthenticationCredentialsRepository {
26
- repository;
27
- constructor(repository) {
28
- super();
29
- this.repository = repository;
30
- }
31
- async tryLoad(id) {
32
- return this.repository.tryLoad(id);
33
- }
34
- async save(credentials) {
35
- await this.repository.upsert(credentials);
36
- }
37
- };
38
- MongoAuthenticationCredentialsRepository = __decorate([
39
- (0, container_1.singleton)(),
40
- __metadata("design:paramtypes", [InternalMongoAuthenticationCredentialsRepository])
41
- ], MongoAuthenticationCredentialsRepository);
42
- exports.MongoAuthenticationCredentialsRepository = MongoAuthenticationCredentialsRepository;
43
26
  let InternalMongoAuthenticationCredentialsRepository = class InternalMongoAuthenticationCredentialsRepository extends mongo_1.MongoEntityRepository {
44
27
  [container_1.resolveArgumentType];
45
28
  constructor(collection, logger) {
@@ -52,14 +35,40 @@ let InternalMongoAuthenticationCredentialsRepository = class InternalMongoAuthen
52
35
  };
53
36
  InternalMongoAuthenticationCredentialsRepository = __decorate([
54
37
  (0, container_1.singleton)({
55
- defaultArgumentProvider: () => exports.mongoAuthenticationCredentialsRepositoryConfig.config
38
+ defaultArgumentProvider: () => defaultArgument
56
39
  }),
57
40
  __param(0, (0, container_1.forwardArg)()),
58
41
  __metadata("design:paramtypes", [mongo_1.Collection, logger_1.Logger])
59
42
  ], InternalMongoAuthenticationCredentialsRepository);
60
43
  exports.InternalMongoAuthenticationCredentialsRepository = InternalMongoAuthenticationCredentialsRepository;
61
- function configureMongoAuthenticationCredentialsRepository(config = {}) {
62
- exports.mongoAuthenticationCredentialsRepositoryConfig.config = config.config ?? exports.mongoAuthenticationCredentialsRepositoryConfig.config;
44
+ let MongoAuthenticationCredentialsRepository = class MongoAuthenticationCredentialsRepository extends authentication_credentials_repository_1.AuthenticationCredentialsRepository {
45
+ repository;
46
+ constructor(repository) {
47
+ super();
48
+ this.repository = repository;
49
+ }
50
+ async tryLoadBySubject(subject) {
51
+ const credentials = await this.repository.tryLoadByFilter({ subject });
52
+ if ((0, type_guards_1.isUndefined)(credentials)) {
53
+ return credentials;
54
+ }
55
+ return {
56
+ ...credentials,
57
+ salt: credentials.salt.buffer,
58
+ hash: credentials.hash.buffer
59
+ };
60
+ }
61
+ async save(credentials) {
62
+ await this.repository.upsert(credentials);
63
+ }
64
+ };
65
+ MongoAuthenticationCredentialsRepository = __decorate([
66
+ (0, container_1.singleton)(),
67
+ __metadata("design:paramtypes", [InternalMongoAuthenticationCredentialsRepository])
68
+ ], MongoAuthenticationCredentialsRepository);
69
+ exports.MongoAuthenticationCredentialsRepository = MongoAuthenticationCredentialsRepository;
70
+ function configureMongoAuthenticationCredentialsRepository(config) {
71
+ defaultArgument = config;
63
72
  }
64
73
  exports.configureMongoAuthenticationCredentialsRepository = configureMongoAuthenticationCredentialsRepository;
65
74
  //# sourceMappingURL=mongo-authentication-credentials.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo-authentication-credentials.repository.js","sourceRoot":"","sources":["../../../../source/authentication/server/mongo/mongo-authentication-credentials.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,kDAAyE;AAEzE,gDAAsC;AAEtC,mDAAsF;AACtF,4CAAkC;AAClC,4DAAkD;AAGlD,oGAA+F;AAM/F,IAAI,eAA2E,CAAC;AAEhF,MAAM,OAAO,GAAuD;IAClE,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;CACtC,CAAC;AAKK,IAAM,gDAAgD,GAAtD,MAAM,gDAAiD,SAAQ,6BAAgD;IAC3G,CAAC,+BAAmB,CAAC,CAAmD;IAEjF,YAA0B,UAAiD,EAAE,MAAc;QACzF,KAAK,CAAC,UAAU,EAAE,uBAAe,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,K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;CACF,CAAA;AAzBY,wCAAwC;IADpD,IAAA,qBAAS,GAAE;qCAIc,gDAAgD;GAH7D,wCAAwC,CAyBpD;AAzBY,4FAAwC;AA2BrD,SAAgB,iDAAiD,CAAC,MAAsD;IACtH,eAAe,GAAG,MAAM,CAAC;AAC3B,CAAC;AAFD,8GAEC"}
@@ -1,16 +1,17 @@
1
- import type { Injectable } from "../../container";
2
- import { resolveArgumentType } from "../../container";
3
- import type { CollectionArgument } from "../../database/mongo";
4
- import { Collection, MongoEntityRepository } from "../../database/mongo";
5
- import { Logger } from "../../logger";
1
+ import type { Injectable } from "../../../container";
2
+ import { resolveArgumentType } from "../../../container";
3
+ import type { CollectionArgument } from "../../../database/mongo";
4
+ import { Collection, MongoEntityRepository } from "../../../database/mongo";
5
+ import { Logger } from "../../../logger";
6
+ import type { AuthenticationSession, NewAuthenticationSession } from '../../models';
6
7
  import type { AuthenticationSessionExtendData } from '../authentication-session.repository';
7
8
  import { AuthenticationSessionRepository } from '../authentication-session.repository';
8
- import type { AuthenticationSession, NewAuthenticationSession } from '../models';
9
- export type MongoAuthenticationSessionRepositoryConfig = {
10
- config?: MongoAuthenticationSessionRepositoryArgument;
11
- };
9
+ export type MongoAuthenticationSessionRepositoryConfig = MongoAuthenticationSessionRepositoryArgument;
12
10
  export type MongoAuthenticationSessionRepositoryArgument = CollectionArgument<AuthenticationSession>;
13
- export declare const mongoAuthenticationSessionRepositoryConfig: MongoAuthenticationSessionRepositoryConfig;
11
+ export declare class InternalMongoAuthenticationSessionRepository extends MongoEntityRepository<AuthenticationSession> implements Injectable<MongoAuthenticationSessionRepositoryArgument> {
12
+ readonly [resolveArgumentType]: MongoAuthenticationSessionRepositoryArgument;
13
+ constructor(collection: Collection<AuthenticationSession>, logger: Logger);
14
+ }
14
15
  export declare class MongoAuthenticationSessionRepository extends AuthenticationSessionRepository {
15
16
  private readonly repository;
16
17
  constructor(repository: InternalMongoAuthenticationSessionRepository);
@@ -19,8 +20,4 @@ export declare class MongoAuthenticationSessionRepository extends Authentication
19
20
  extend(id: string, data: AuthenticationSessionExtendData): Promise<void>;
20
21
  end(id: string, timestamp: number): Promise<void>;
21
22
  }
22
- export declare class InternalMongoAuthenticationSessionRepository extends MongoEntityRepository<AuthenticationSession> implements Injectable<MongoAuthenticationSessionRepositoryArgument> {
23
- readonly [resolveArgumentType]: MongoAuthenticationSessionRepositoryArgument;
24
- constructor(collection: Collection<AuthenticationSession>, logger: Logger);
25
- }
26
- export declare function configureMongoAuthenticationSessionRepository(config?: Partial<MongoAuthenticationSessionRepositoryConfig>): void;
23
+ export declare function configureMongoAuthenticationSessionRepository(config: MongoAuthenticationSessionRepositoryConfig): void;