@stratal/framework 0.0.21 → 0.0.22

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 (44) hide show
  1. package/dist/access-control/index.d.mts +8 -14
  2. package/dist/access-control/index.d.mts.map +1 -1
  3. package/dist/access-control/index.mjs +2 -2
  4. package/dist/{access.service-Cb99esfz.mjs → access.service-DWRsDLJq.mjs} +5 -11
  5. package/dist/access.service-DWRsDLJq.mjs.map +1 -0
  6. package/dist/auth/index.d.mts +60 -133
  7. package/dist/auth/index.d.mts.map +1 -1
  8. package/dist/auth/index.mjs +119 -199
  9. package/dist/auth/index.mjs.map +1 -1
  10. package/dist/{auth-context-HLwuOl51.mjs → auth-context-CObJcW0t.mjs} +7 -6
  11. package/dist/auth-context-CObJcW0t.mjs.map +1 -0
  12. package/dist/{auth-context-DXSTlnQH.d.mts → auth-context-D70ktWUf.d.mts} +1 -1
  13. package/dist/{auth-context-DXSTlnQH.d.mts.map → auth-context-D70ktWUf.d.mts.map} +1 -1
  14. package/dist/context/index.d.mts +5 -10
  15. package/dist/context/index.d.mts.map +1 -1
  16. package/dist/context/index.mjs +3 -3
  17. package/dist/database/index.d.mts +3 -3
  18. package/dist/database/index.mjs +44 -179
  19. package/dist/database/index.mjs.map +1 -1
  20. package/dist/errors-MCyrn_V2.mjs +18 -0
  21. package/dist/errors-MCyrn_V2.mjs.map +1 -0
  22. package/dist/factory/index.d.mts +1 -1
  23. package/dist/guards/index.d.mts.map +1 -1
  24. package/dist/guards/index.mjs +8 -15
  25. package/dist/guards/index.mjs.map +1 -1
  26. package/dist/{index-CCDPF-1Y.d.mts → index-DJ_DCIul.d.mts} +11 -93
  27. package/dist/index-DJ_DCIul.d.mts.map +1 -0
  28. package/dist/index.d.mts +1 -1
  29. package/dist/insufficient-permissions.error-GwrkWnEM.mjs +16 -0
  30. package/dist/insufficient-permissions.error-GwrkWnEM.mjs.map +1 -0
  31. package/dist/{types-BZlcRR2M.d.mts → types-4uX3XKRM.d.mts} +1 -1
  32. package/dist/{types-BZlcRR2M.d.mts.map → types-4uX3XKRM.d.mts.map} +1 -1
  33. package/dist/{types-BLyu9dAd.d.mts → types-tu9pTehB.d.mts} +1 -1
  34. package/dist/{types-BLyu9dAd.d.mts.map → types-tu9pTehB.d.mts.map} +1 -1
  35. package/package.json +12 -9
  36. package/dist/access.service-Cb99esfz.mjs.map +0 -1
  37. package/dist/auth-context-HLwuOl51.mjs.map +0 -1
  38. package/dist/decorateMetadata-D5WUsc6Y.mjs +0 -6
  39. package/dist/errors-B1vVXc1T.mjs +0 -25
  40. package/dist/errors-B1vVXc1T.mjs.map +0 -1
  41. package/dist/index-CCDPF-1Y.d.mts.map +0 -1
  42. package/dist/insufficient-permissions.error-CRnOHYvq.mjs +0 -23
  43. package/dist/insufficient-permissions.error-CRnOHYvq.mjs.map +0 -1
  44. /package/dist/{decorate-DViXs-0l.mjs → decorate-7CAoTBu4.mjs} +0 -0
@@ -1,16 +1,13 @@
1
- import { n as createStratalAcPlugin, t as AccessService } from "../access.service-Cb99esfz.mjs";
1
+ import { n as createStratalAcPlugin, t as AccessService } from "../access.service-DWRsDLJq.mjs";
2
2
  import { n as AC_TOKENS, t as __decorateParam } from "../decorateParam-C_dJ_dIO.mjs";
3
- import { t as __decorateMetadata } from "../decorateMetadata-D5WUsc6Y.mjs";
4
- import { t as __decorate } from "../decorate-DViXs-0l.mjs";
5
- import { t as AuthContext } from "../auth-context-HLwuOl51.mjs";
6
- import { CONTAINER_TOKEN, DI_TOKENS, Transient } from "stratal/di";
7
- import { I18nModule } from "stratal/i18n";
3
+ import { t as __decorate } from "../decorate-7CAoTBu4.mjs";
4
+ import { t as AuthContext } from "../auth-context-CObJcW0t.mjs";
5
+ import { CONTAINER_TOKEN, DI_TOKENS, Request, Transient, inject } from "stratal/di";
8
6
  import { Module } from "stratal/module";
9
7
  import { RATE_LIMITER_TOKENS, RateLimiterRegistry } from "stratal/rate-limiter";
10
- import { ApplicationError, ERROR_CODES } from "stratal/errors";
8
+ import { AuthError, HttpException } from "stratal/errors";
11
9
  import { LOGGER_TOKENS } from "stratal/logger";
12
- import { inject as inject$1 } from "tsyringe";
13
- import { betterAuth } from "better-auth";
10
+ import { betterAuth } from "better-auth/minimal";
14
11
  import { APIError } from "better-auth/api";
15
12
  //#region src/auth/auth.tokens.ts
16
13
  /** Token for AuthService - core authentication service */
@@ -18,56 +15,6 @@ const AUTH_SERVICE = Symbol.for("stratal:auth:service");
18
15
  /** Token for Better Auth options configuration */
19
16
  const AUTH_OPTIONS = Symbol.for("stratal:auth:options");
20
17
  //#endregion
21
- //#region src/auth/i18n/en.ts
22
- const authMessages = { en: { auth: {
23
- errors: {
24
- tokenRequired: "Verification token is required",
25
- invalidToken: "Invalid or expired verification token",
26
- verificationFailed: "Verification failed. Please try again.",
27
- userNotFound: "User not found. Please check your credentials.",
28
- invalidCredentials: "Invalid email or password",
29
- invalidPassword: "Invalid password",
30
- invalidEmail: "Invalid email address",
31
- sessionExpired: "Your session has expired. Please sign in again.",
32
- emailNotVerified: "Please verify your email address before signing in",
33
- passwordTooShort: "Password must be at least {minLength} characters",
34
- passwordTooLong: "Password must be at most {maxLength} characters",
35
- accountAlreadyExists: "An account with this email already exists",
36
- failedToCreateUser: "Failed to create user account. Please try again.",
37
- failedToCreateSession: "Failed to create session. Please try again.",
38
- failedToGetSession: "Failed to retrieve session. Please try again.",
39
- failedToUpdateUser: "Failed to update user information. Please try again.",
40
- failedToGetUserInfo: "Failed to retrieve user information. Please try again.",
41
- socialAccountLinked: "This social account is already linked to another user",
42
- providerNotFound: "Authentication provider not found",
43
- userEmailNotFound: "User email address not found",
44
- accountNotFound: "Account not found",
45
- credentialAccountNotFound: "Credential account not found",
46
- cannotUnlinkLastAccount: "Cannot unlink your last account",
47
- userAlreadyHasPassword: "User already has a password set",
48
- emailCannotBeUpdated: "Email address cannot be updated at this time",
49
- tokenExpired: "The verification token has expired. Please request a new verification email.",
50
- invalidCallbackUrl: "Invalid callback URL",
51
- invalidOrigin: "Request origin is not allowed",
52
- validationFailed: "Authentication validation failed",
53
- emailAlreadyVerified: "Email address is already verified",
54
- emailMismatch: "Email address does not match",
55
- unknownError: "An authentication error occurred"
56
- },
57
- org: {
58
- organizationNotFound: "Organization not found",
59
- memberNotFound: "Member not found",
60
- invitationNotFound: "Invitation not found",
61
- permissionDenied: "You do not have permission to perform this action",
62
- invitationRecipientMismatch: "You are not the recipient of this invitation",
63
- conflict: "A resource with this identifier already exists",
64
- limitReached: "The maximum limit has been reached",
65
- membershipError: "This action cannot be performed due to membership constraints",
66
- teamNotFound: "Team not found",
67
- roleNotFound: "Role not found"
68
- }
69
- } } };
70
- //#endregion
71
18
  //#region src/auth/middleware/auth-context.middleware.ts
72
19
  let AuthContextMiddleware = class AuthContextMiddleware {
73
20
  async handle(ctx, next) {
@@ -99,9 +46,8 @@ let SessionVerificationMiddleware = class SessionVerificationMiddleware {
99
46
  };
100
47
  SessionVerificationMiddleware = __decorate([
101
48
  Transient(),
102
- __decorateParam(0, inject$1(AUTH_SERVICE)),
103
- __decorateParam(1, inject$1(LOGGER_TOKENS.LoggerService)),
104
- __decorateMetadata("design:paramtypes", [Object, Object])
49
+ __decorateParam(0, inject(AUTH_SERVICE)),
50
+ __decorateParam(1, inject(LOGGER_TOKENS.LoggerService))
105
51
  ], SessionVerificationMiddleware);
106
52
  //#endregion
107
53
  //#region src/auth/rate-limit-bridge.ts
@@ -188,227 +134,208 @@ function projectCustomRules(registry) {
188
134
  }
189
135
  //#endregion
190
136
  //#region src/auth/errors/auth-errors.ts
191
- var UserNotFoundError = class extends ApplicationError {
137
+ var UserNotFoundError = class extends HttpException {
138
+ email;
192
139
  constructor(email) {
193
- super("auth.errors.userNotFound", ERROR_CODES.RESOURCE.NOT_FOUND, email ? { email } : void 0);
140
+ super(404, "User not found");
141
+ this.email = email;
194
142
  }
195
143
  };
196
- var InvalidCredentialsError = class extends ApplicationError {
144
+ var InvalidCredentialsError = class extends HttpException {
197
145
  constructor() {
198
- super("auth.errors.invalidCredentials", ERROR_CODES.AUTH.INVALID_CREDENTIALS);
146
+ super(401, "Invalid email or password");
199
147
  }
200
148
  };
201
- var InvalidPasswordError = class extends ApplicationError {
149
+ var InvalidPasswordError = class extends HttpException {
202
150
  constructor() {
203
- super("auth.errors.invalidPassword", ERROR_CODES.AUTH.INVALID_CREDENTIALS);
151
+ super(401, "Invalid password");
204
152
  }
205
153
  };
206
- var InvalidEmailError = class extends ApplicationError {
154
+ var InvalidEmailError = class extends HttpException {
155
+ email;
207
156
  constructor(email) {
208
- super("auth.errors.invalidEmail", ERROR_CODES.VALIDATION.INVALID_FORMAT, email ? { email } : void 0);
157
+ super(422, "Invalid email address");
158
+ this.email = email;
209
159
  }
210
160
  };
211
- var SessionExpiredError = class extends ApplicationError {
161
+ var SessionExpiredError = class extends HttpException {
212
162
  constructor() {
213
- super("auth.errors.sessionExpired", ERROR_CODES.AUTH.SESSION_EXPIRED);
163
+ super(401, "Session expired");
214
164
  }
215
165
  };
216
- var EmailNotVerifiedError = class extends ApplicationError {
166
+ var EmailNotVerifiedError = class extends HttpException {
167
+ email;
217
168
  constructor(email) {
218
- super("auth.errors.emailNotVerified", ERROR_CODES.AUTH.EMAIL_NOT_VERIFIED, email ? { email } : void 0);
169
+ super(403, "Email not verified");
170
+ this.email = email;
219
171
  }
220
172
  };
221
- var PasswordTooShortError = class extends ApplicationError {
173
+ var PasswordTooShortError = class extends HttpException {
174
+ minLength;
222
175
  constructor(minLength) {
223
- super("auth.errors.passwordTooShort", ERROR_CODES.AUTH.PASSWORD_TOO_SHORT, { minLength });
176
+ super(422, "Password too short");
177
+ this.minLength = minLength;
224
178
  }
225
179
  };
226
- var PasswordTooLongError = class extends ApplicationError {
180
+ var PasswordTooLongError = class extends HttpException {
181
+ maxLength;
227
182
  constructor(maxLength) {
228
- super("auth.errors.passwordTooLong", ERROR_CODES.AUTH.PASSWORD_TOO_LONG, { maxLength });
183
+ super(422, "Password too long");
184
+ this.maxLength = maxLength;
229
185
  }
230
186
  };
231
- var AccountAlreadyExistsError = class extends ApplicationError {
187
+ var AccountAlreadyExistsError = class extends HttpException {
188
+ email;
232
189
  constructor(email) {
233
- super("auth.errors.accountAlreadyExists", ERROR_CODES.AUTH.ACCOUNT_ALREADY_EXISTS, email ? { email } : void 0);
234
- }
235
- };
236
- var FailedToCreateUserError = class extends ApplicationError {
237
- constructor(reason) {
238
- super("auth.errors.failedToCreateUser", ERROR_CODES.AUTH.FAILED_TO_CREATE_USER, reason ? { reason } : void 0);
239
- }
240
- };
241
- var FailedToCreateSessionError = class extends ApplicationError {
242
- constructor(reason) {
243
- super("auth.errors.failedToCreateSession", ERROR_CODES.AUTH.FAILED_TO_CREATE_SESSION, reason ? { reason } : void 0);
190
+ super(409, "Account already exists");
191
+ this.email = email;
244
192
  }
245
193
  };
246
- var FailedToUpdateUserError = class extends ApplicationError {
247
- constructor(reason) {
248
- super("auth.errors.failedToUpdateUser", ERROR_CODES.AUTH.FAILED_TO_UPDATE_USER, reason ? { reason } : void 0);
249
- }
250
- };
251
- var SocialAccountLinkedError = class extends ApplicationError {
194
+ var SocialAccountLinkedError = class extends HttpException {
195
+ provider;
252
196
  constructor(provider) {
253
- super("auth.errors.socialAccountLinked", ERROR_CODES.AUTH.SOCIAL_ACCOUNT_LINKED, provider ? { provider } : void 0);
197
+ super(409, "Social account already linked");
198
+ this.provider = provider;
254
199
  }
255
200
  };
256
- var CannotUnlinkLastAccountError = class extends ApplicationError {
201
+ var CannotUnlinkLastAccountError = class extends HttpException {
257
202
  constructor() {
258
- super("auth.errors.cannotUnlinkLastAccount", ERROR_CODES.AUTH.CANNOT_UNLINK_LAST_ACCOUNT);
203
+ super(409, "Cannot unlink last account");
259
204
  }
260
205
  };
261
- var ProviderNotFoundError = class extends ApplicationError {
206
+ var ProviderNotFoundError = class extends HttpException {
207
+ provider;
262
208
  constructor(provider) {
263
- super("auth.errors.providerNotFound", ERROR_CODES.RESOURCE.NOT_FOUND, provider ? { provider } : void 0);
209
+ super(404, "Authentication provider not found");
210
+ this.provider = provider;
264
211
  }
265
212
  };
266
- var UserEmailNotFoundError = class extends ApplicationError {
213
+ var UserEmailNotFoundError = class extends HttpException {
267
214
  constructor() {
268
- super("auth.errors.userEmailNotFound", ERROR_CODES.RESOURCE.NOT_FOUND);
215
+ super(404, "User email not found");
269
216
  }
270
217
  };
271
- var AccountNotFoundError = class extends ApplicationError {
218
+ var AccountNotFoundError = class extends HttpException {
272
219
  constructor() {
273
- super("auth.errors.accountNotFound", ERROR_CODES.RESOURCE.NOT_FOUND);
220
+ super(404, "Account not found");
274
221
  }
275
222
  };
276
- var CredentialAccountNotFoundError = class extends ApplicationError {
223
+ var CredentialAccountNotFoundError = class extends HttpException {
277
224
  constructor() {
278
- super("auth.errors.credentialAccountNotFound", ERROR_CODES.RESOURCE.NOT_FOUND);
225
+ super(404, "Credential account not found");
279
226
  }
280
227
  };
281
- var UserAlreadyHasPasswordError = class extends ApplicationError {
228
+ var UserAlreadyHasPasswordError = class extends HttpException {
282
229
  constructor() {
283
- super("auth.errors.userAlreadyHasPassword", ERROR_CODES.RESOURCE.CONFLICT);
284
- }
285
- };
286
- var EmailCannotBeUpdatedError = class extends ApplicationError {
287
- constructor(reason) {
288
- super("auth.errors.emailCannotBeUpdated", ERROR_CODES.VALIDATION.GENERIC, reason ? { reason } : void 0);
289
- }
290
- };
291
- var FailedToGetSessionError = class extends ApplicationError {
292
- constructor(reason) {
293
- super("auth.errors.failedToGetSession", ERROR_CODES.SYSTEM.INTERNAL_ERROR, reason ? { reason } : void 0);
230
+ super(409, "User already has a password");
294
231
  }
295
232
  };
296
- var FailedToGetUserInfoError = class extends ApplicationError {
233
+ var EmailCannotBeUpdatedError = class extends HttpException {
234
+ reason;
297
235
  constructor(reason) {
298
- super("auth.errors.failedToGetUserInfo", ERROR_CODES.SYSTEM.INTERNAL_ERROR, reason ? { reason } : void 0);
236
+ super(422, "Email cannot be updated");
237
+ this.reason = reason;
299
238
  }
300
239
  };
301
- var IdTokenNotSupportedError = class extends ApplicationError {
240
+ var IdTokenNotSupportedError = class extends HttpException {
302
241
  constructor() {
303
- super("auth.errors.invalidToken", ERROR_CODES.VALIDATION.GENERIC);
242
+ super(422, "ID token not supported");
304
243
  }
305
244
  };
306
- var TokenExpiredError = class extends ApplicationError {
245
+ var TokenExpiredError = class extends HttpException {
307
246
  constructor() {
308
- super("auth.errors.tokenExpired", ERROR_CODES.VALIDATION.GENERIC);
247
+ super(401, "Token expired");
309
248
  }
310
249
  };
311
- var InvalidCallbackUrlError = class extends ApplicationError {
250
+ var InvalidCallbackUrlError = class extends HttpException {
312
251
  constructor() {
313
- super("auth.errors.invalidCallbackUrl", ERROR_CODES.VALIDATION.INVALID_FORMAT);
252
+ super(422, "Invalid callback URL");
314
253
  }
315
254
  };
316
- var InvalidOriginError = class extends ApplicationError {
255
+ var InvalidOriginError = class extends HttpException {
317
256
  constructor() {
318
- super("auth.errors.invalidOrigin", ERROR_CODES.AUTHZ.FORBIDDEN);
257
+ super(403, "Invalid request origin");
319
258
  }
320
259
  };
321
- var AuthValidationFailedError = class extends ApplicationError {
260
+ var AuthValidationFailedError = class extends HttpException {
322
261
  constructor() {
323
- super("auth.errors.validationFailed", ERROR_CODES.VALIDATION.GENERIC);
262
+ super(422, "Authentication validation failed");
324
263
  }
325
264
  };
326
- var EmailAlreadyVerifiedError = class extends ApplicationError {
265
+ var EmailAlreadyVerifiedError = class extends HttpException {
327
266
  constructor() {
328
- super("auth.errors.emailAlreadyVerified", ERROR_CODES.RESOURCE.CONFLICT);
267
+ super(409, "Email already verified");
329
268
  }
330
269
  };
331
- var EmailMismatchError = class extends ApplicationError {
270
+ var EmailMismatchError = class extends HttpException {
332
271
  constructor() {
333
- super("auth.errors.emailMismatch", ERROR_CODES.VALIDATION.INVALID_FORMAT);
334
- }
335
- };
336
- var BetterAuthUnknownError = class extends ApplicationError {
337
- constructor(errorCode) {
338
- super("auth.errors.unknownError", ERROR_CODES.SYSTEM.INTERNAL_ERROR, errorCode ? { errorCode } : void 0);
272
+ super(422, "Email mismatch");
339
273
  }
340
274
  };
341
275
  //#endregion
342
276
  //#region src/auth/errors/invalid-token.error.ts
343
- var InvalidTokenError = class extends ApplicationError {
277
+ var InvalidTokenError = class extends HttpException {
344
278
  constructor() {
345
- super("auth.errors.invalidToken", ERROR_CODES.AUTH.INVALID_TOKEN);
279
+ super(401, "Invalid or expired token");
346
280
  }
347
281
  };
348
282
  //#endregion
349
283
  //#region src/auth/errors/organization-errors.ts
350
- var OrganizationNotFoundError = class extends ApplicationError {
284
+ var OrganizationNotFoundError = class extends HttpException {
351
285
  constructor() {
352
- super("auth.org.organizationNotFound", ERROR_CODES.AUTH.ORGANIZATION_NOT_FOUND);
286
+ super(404, "Organization not found");
353
287
  }
354
288
  };
355
- var OrganizationMemberNotFoundError = class extends ApplicationError {
289
+ var OrganizationMemberNotFoundError = class extends HttpException {
356
290
  constructor() {
357
- super("auth.org.memberNotFound", ERROR_CODES.AUTH.MEMBER_NOT_FOUND);
291
+ super(404, "Organization member not found");
358
292
  }
359
293
  };
360
- var OrganizationInvitationNotFoundError = class extends ApplicationError {
294
+ var OrganizationInvitationNotFoundError = class extends HttpException {
361
295
  constructor() {
362
- super("auth.org.invitationNotFound", ERROR_CODES.AUTH.INVITATION_NOT_FOUND);
296
+ super(404, "Invitation not found");
363
297
  }
364
298
  };
365
- var OrganizationPermissionDeniedError = class extends ApplicationError {
299
+ var OrganizationPermissionDeniedError = class extends HttpException {
366
300
  constructor() {
367
- super("auth.org.permissionDenied", ERROR_CODES.AUTHZ.FORBIDDEN);
301
+ super(403, "Organization permission denied");
368
302
  }
369
303
  };
370
- var OrganizationInvitationRecipientMismatchError = class extends ApplicationError {
304
+ var OrganizationInvitationRecipientMismatchError = class extends HttpException {
371
305
  constructor() {
372
- super("auth.org.invitationRecipientMismatch", ERROR_CODES.AUTH.INVITATION_RECIPIENT_MISMATCH);
306
+ super(403, "Invitation recipient mismatch");
373
307
  }
374
308
  };
375
- var OrganizationConflictError = class extends ApplicationError {
309
+ var OrganizationConflictError = class extends HttpException {
376
310
  constructor() {
377
- super("auth.org.conflict", ERROR_CODES.RESOURCE.CONFLICT);
311
+ super(409, "Organization resource conflict");
378
312
  }
379
313
  };
380
- var OrganizationLimitReachedError = class extends ApplicationError {
314
+ var OrganizationLimitReachedError = class extends HttpException {
381
315
  constructor() {
382
- super("auth.org.limitReached", ERROR_CODES.AUTH.ORGANIZATION_LIMIT_REACHED);
316
+ super(422, "Organization limit reached");
383
317
  }
384
318
  };
385
- var OrganizationMembershipError = class extends ApplicationError {
319
+ var OrganizationMembershipError = class extends HttpException {
386
320
  constructor() {
387
- super("auth.org.membershipError", ERROR_CODES.AUTH.ORGANIZATION_MEMBERSHIP_REQUIRED);
321
+ super(422, "Organization membership constraint violated");
388
322
  }
389
323
  };
390
- var OrganizationTeamNotFoundError = class extends ApplicationError {
324
+ var OrganizationTeamNotFoundError = class extends HttpException {
391
325
  constructor() {
392
- super("auth.org.teamNotFound", ERROR_CODES.RESOURCE.NOT_FOUND);
326
+ super(404, "Team not found");
393
327
  }
394
328
  };
395
- var OrganizationRoleNotFoundError = class extends ApplicationError {
329
+ var OrganizationRoleNotFoundError = class extends HttpException {
396
330
  constructor() {
397
- super("auth.org.roleNotFound", ERROR_CODES.RESOURCE.NOT_FOUND);
331
+ super(404, "Role not found");
398
332
  }
399
333
  };
400
334
  //#endregion
401
335
  //#region src/auth/errors/token-required.error.ts
402
- var TokenRequiredError = class extends ApplicationError {
403
- constructor() {
404
- super("auth.errors.tokenRequired", ERROR_CODES.VALIDATION.REQUIRED_FIELD, { field: "token" });
405
- }
406
- };
407
- //#endregion
408
- //#region src/auth/errors/verification-failed.error.ts
409
- var VerificationFailedError = class extends ApplicationError {
336
+ var TokenRequiredError = class extends HttpException {
410
337
  constructor() {
411
- super("auth.errors.verificationFailed", ERROR_CODES.AUTH.INVALID_CREDENTIALS);
338
+ super(401, "Verification token is required");
412
339
  }
413
340
  };
414
341
  //#endregion
@@ -424,18 +351,18 @@ function mapBetterAuthError(error) {
424
351
  if (location.includes("EXPIRED_TOKEN")) return new TokenExpiredError();
425
352
  if (location.includes("ATTEMPTS_EXCEEDED")) return new InvalidTokenError();
426
353
  if (location.includes("new_user_signup_disabled")) return new UserNotFoundError();
427
- if (location.includes("failed_to_create_user")) return new FailedToCreateUserError();
428
- if (location.includes("failed_to_create_session")) return new FailedToCreateSessionError();
354
+ if (location.includes("failed_to_create_user")) return new AuthError("Failed to create user");
355
+ if (location.includes("failed_to_create_session")) return new AuthError("Failed to create session");
429
356
  }
430
- if (!errorCode) return new BetterAuthUnknownError();
357
+ if (!errorCode) return new AuthError("An authentication error occurred");
431
358
  if (errorCode === "USER_NOT_FOUND" || errorCode === "INVALID_USER") return new UserNotFoundError();
432
359
  if (errorCode === "USER_EMAIL_NOT_FOUND") return new UserEmailNotFoundError();
433
360
  if (errorCode === "INVALID_EMAIL_OR_PASSWORD") return new InvalidCredentialsError();
434
361
  if (errorCode === "INVALID_PASSWORD") return new InvalidPasswordError();
435
362
  if (errorCode === "INVALID_EMAIL") return new InvalidEmailError();
436
363
  if (errorCode === "SESSION_EXPIRED" || errorCode === "SESSION_NOT_FRESH") return new SessionExpiredError();
437
- if (errorCode === "FAILED_TO_CREATE_SESSION") return new FailedToCreateSessionError();
438
- if (errorCode === "FAILED_TO_GET_SESSION") return new FailedToGetSessionError();
364
+ if (errorCode === "FAILED_TO_CREATE_SESSION") return new AuthError("Failed to create session");
365
+ if (errorCode === "FAILED_TO_GET_SESSION") return new AuthError("Failed to retrieve session");
439
366
  if (errorCode === "EMAIL_NOT_VERIFIED") return new EmailNotVerifiedError();
440
367
  if (errorCode === "EMAIL_CAN_NOT_BE_UPDATED") return new EmailCannotBeUpdatedError();
441
368
  if (errorCode === "EMAIL_ALREADY_VERIFIED") return new EmailAlreadyVerifiedError();
@@ -446,9 +373,9 @@ function mapBetterAuthError(error) {
446
373
  if (errorCode === "ACCOUNT_NOT_FOUND") return new AccountNotFoundError();
447
374
  if (errorCode === "CREDENTIAL_ACCOUNT_NOT_FOUND") return new CredentialAccountNotFoundError();
448
375
  if (errorCode === "FAILED_TO_UNLINK_LAST_ACCOUNT") return new CannotUnlinkLastAccountError();
449
- if (errorCode === "FAILED_TO_CREATE_USER") return new FailedToCreateUserError();
450
- if (errorCode === "FAILED_TO_UPDATE_USER") return new FailedToUpdateUserError();
451
- if (errorCode === "FAILED_TO_GET_USER_INFO") return new FailedToGetUserInfoError();
376
+ if (errorCode === "FAILED_TO_CREATE_USER") return new AuthError("Failed to create user");
377
+ if (errorCode === "FAILED_TO_UPDATE_USER") return new AuthError("Failed to update user");
378
+ if (errorCode === "FAILED_TO_GET_USER_INFO") return new AuthError("Failed to retrieve user info");
452
379
  if (errorCode === "SOCIAL_ACCOUNT_ALREADY_LINKED" || errorCode === "LINKED_ACCOUNT_ALREADY_EXISTS") return new SocialAccountLinkedError();
453
380
  if (errorCode === "PROVIDER_NOT_FOUND") return new ProviderNotFoundError();
454
381
  if (errorCode === "ID_TOKEN_NOT_SUPPORTED") return new IdTokenNotSupportedError();
@@ -458,7 +385,7 @@ function mapBetterAuthError(error) {
458
385
  if (errorCode === "INVALID_CALLBACK_URL" || errorCode === "INVALID_REDIRECT_URL" || errorCode === "INVALID_NEW_USER_CALLBACK_URL" || errorCode === "INVALID_ERROR_CALLBACK_URL" || errorCode === "CALLBACK_URL_REQUIRED") return new InvalidCallbackUrlError();
459
386
  if (errorCode === "INVALID_ORIGIN" || errorCode === "MISSING_OR_NULL_ORIGIN" || errorCode === "CROSS_SITE_NAVIGATION_LOGIN_BLOCKED") return new InvalidOriginError();
460
387
  if (errorCode === "VALIDATION_ERROR" || errorCode === "MISSING_FIELD" || errorCode === "FIELD_NOT_ALLOWED" || errorCode === "BODY_MUST_BE_AN_OBJECT" || errorCode === "ASYNC_VALIDATION_NOT_SUPPORTED" || errorCode === "METHOD_NOT_ALLOWED_DEFER_SESSION_REQUIRED") return new AuthValidationFailedError();
461
- if (errorCode === "FAILED_TO_CREATE_VERIFICATION" || errorCode === "VERIFICATION_EMAIL_NOT_ENABLED") return new FailedToCreateSessionError();
388
+ if (errorCode === "FAILED_TO_CREATE_VERIFICATION" || errorCode === "VERIFICATION_EMAIL_NOT_ENABLED") return new AuthError("Failed to create session");
462
389
  if (errorCode === "ORGANIZATION_NOT_FOUND" || errorCode === "NO_ACTIVE_ORGANIZATION") return new OrganizationNotFoundError();
463
390
  if (errorCode === "MEMBER_NOT_FOUND" || errorCode === "USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION" || errorCode === "USER_IS_NOT_A_MEMBER_OF_THE_TEAM") return new OrganizationMemberNotFoundError();
464
391
  if (errorCode === "INVITATION_NOT_FOUND" || errorCode === "FAILED_TO_RETRIEVE_INVITATION") return new OrganizationInvitationNotFoundError();
@@ -469,7 +396,7 @@ function mapBetterAuthError(error) {
469
396
  if (errorCode === "YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_ORGANIZATIONS" || errorCode === "YOU_HAVE_REACHED_THE_MAXIMUM_NUMBER_OF_TEAMS" || errorCode === "ORGANIZATION_MEMBERSHIP_LIMIT_REACHED" || errorCode === "INVITATION_LIMIT_REACHED" || errorCode === "TEAM_MEMBER_LIMIT_REACHED" || errorCode === "TOO_MANY_ROLES") return new OrganizationLimitReachedError();
470
397
  if (errorCode === "YOU_CANNOT_LEAVE_THE_ORGANIZATION_AS_THE_ONLY_OWNER" || errorCode === "YOU_CANNOT_LEAVE_THE_ORGANIZATION_WITHOUT_AN_OWNER" || errorCode === "UNABLE_TO_REMOVE_LAST_TEAM" || errorCode === "CANNOT_DELETE_A_PRE_DEFINED_ROLE" || errorCode === "ROLE_IS_ASSIGNED_TO_MEMBERS" || errorCode === "YOU_CANNOT_IMPERSONATE_ADMINS" || errorCode === "YOU_CANNOT_BAN_YOURSELF" || errorCode === "YOU_CANNOT_REMOVE_YOURSELF" || errorCode === "INVITER_IS_NO_LONGER_A_MEMBER_OF_THE_ORGANIZATION") return new OrganizationMembershipError();
471
398
  if (errorCode.startsWith("YOU_ARE_NOT_ALLOWED_TO_") || errorCode === "YOU_ARE_NOT_A_MEMBER_OF_THIS_ORGANIZATION" || errorCode === "YOU_CAN_NOT_ACCESS_THE_MEMBERS_OF_THIS_TEAM" || errorCode === "YOU_MUST_BE_IN_AN_ORGANIZATION_TO_CREATE_A_ROLE" || errorCode === "MISSING_AC_INSTANCE") return new OrganizationPermissionDeniedError();
472
- return new BetterAuthUnknownError(errorCode);
399
+ return new AuthError("An authentication error occurred");
473
400
  }
474
401
  /**
475
402
  * Type guard to check if an error is a Better Auth APIError.
@@ -510,26 +437,22 @@ const wrapBetterAuth = async (fn) => {
510
437
  //#region src/auth/services/auth.service.ts
511
438
  let AuthService = class AuthService {
512
439
  options;
513
- authInstance;
440
+ _authInstance;
514
441
  constructor(options) {
515
442
  this.options = options;
516
- this.authInstance = betterAuth({
517
- ...this.options,
518
- onAPIError: getErrorHandlerConfig()
519
- });
520
443
  }
521
444
  /**
522
- * Get the Better Auth instance
445
+ * Get the Better Auth instance.
523
446
  */
524
447
  get auth() {
525
- return this.authInstance;
448
+ this._authInstance ??= betterAuth({
449
+ ...this.options,
450
+ onAPIError: getErrorHandlerConfig()
451
+ });
452
+ return this._authInstance;
526
453
  }
527
454
  };
528
- AuthService = __decorate([
529
- Transient(AUTH_SERVICE),
530
- __decorateParam(0, inject$1(AUTH_OPTIONS)),
531
- __decorateMetadata("design:paramtypes", [Object])
532
- ], AuthService);
455
+ AuthService = __decorate([Request(AUTH_SERVICE), __decorateParam(0, inject(AUTH_OPTIONS))], AuthService);
533
456
  //#endregion
534
457
  //#region src/auth/auth.module.ts
535
458
  var _AuthModule;
@@ -566,7 +489,7 @@ let AuthModule = _AuthModule = class AuthModule {
566
489
  ...raw,
567
490
  plugins: [createStratalAcPlugin(accessControl), ...raw.plugins ?? []]
568
491
  };
569
- if (container.getTsyringeContainer().isRegistered(RATE_LIMITER_TOKENS.ModuleMarker, true)) {
492
+ if (container.isRegistered(RATE_LIMITER_TOKENS.ModuleMarker)) {
570
493
  const store = container.resolve(RATE_LIMITER_TOKENS.Store);
571
494
  const registry = container.resolve(RATE_LIMITER_TOKENS.Registry);
572
495
  raw = {
@@ -605,11 +528,8 @@ let AuthModule = _AuthModule = class AuthModule {
605
528
  };
606
529
  }
607
530
  };
608
- AuthModule = _AuthModule = __decorate([Module({
609
- imports: [I18nModule.registerMessages(authMessages)],
610
- providers: []
611
- })], AuthModule);
531
+ AuthModule = _AuthModule = __decorate([Module({ providers: [AuthContext] })], AuthModule);
612
532
  //#endregion
613
- export { AUTH_OPTIONS, AUTH_SERVICE, AccountAlreadyExistsError, AccountNotFoundError, AuthContextMiddleware, AuthModule, AuthService, AuthValidationFailedError, BetterAuthUnknownError, CannotUnlinkLastAccountError, CredentialAccountNotFoundError, EmailAlreadyVerifiedError, EmailCannotBeUpdatedError, EmailMismatchError, EmailNotVerifiedError, FailedToCreateSessionError, FailedToCreateUserError, FailedToGetSessionError, FailedToGetUserInfoError, FailedToUpdateUserError, IdTokenNotSupportedError, InvalidCallbackUrlError, InvalidCredentialsError, InvalidEmailError, InvalidOriginError, InvalidPasswordError, InvalidTokenError, OrganizationConflictError, OrganizationInvitationNotFoundError, OrganizationInvitationRecipientMismatchError, OrganizationLimitReachedError, OrganizationMemberNotFoundError, OrganizationMembershipError, OrganizationNotFoundError, OrganizationPermissionDeniedError, OrganizationRoleNotFoundError, OrganizationTeamNotFoundError, PasswordTooLongError, PasswordTooShortError, ProviderNotFoundError, SessionExpiredError, SessionVerificationMiddleware, SocialAccountLinkedError, TokenExpiredError, TokenRequiredError, UserAlreadyHasPasswordError, UserEmailNotFoundError, UserNotFoundError, VerificationFailedError, authMessages, getErrorHandlerConfig, isAPIError, mapBetterAuthError, wrapBetterAuth };
533
+ export { AUTH_OPTIONS, AUTH_SERVICE, AccountAlreadyExistsError, AccountNotFoundError, AuthContextMiddleware, AuthModule, AuthService, AuthValidationFailedError, CannotUnlinkLastAccountError, CredentialAccountNotFoundError, EmailAlreadyVerifiedError, EmailCannotBeUpdatedError, EmailMismatchError, EmailNotVerifiedError, IdTokenNotSupportedError, InvalidCallbackUrlError, InvalidCredentialsError, InvalidEmailError, InvalidOriginError, InvalidPasswordError, InvalidTokenError, OrganizationConflictError, OrganizationInvitationNotFoundError, OrganizationInvitationRecipientMismatchError, OrganizationLimitReachedError, OrganizationMemberNotFoundError, OrganizationMembershipError, OrganizationNotFoundError, OrganizationPermissionDeniedError, OrganizationRoleNotFoundError, OrganizationTeamNotFoundError, PasswordTooLongError, PasswordTooShortError, ProviderNotFoundError, SessionExpiredError, SessionVerificationMiddleware, SocialAccountLinkedError, TokenExpiredError, TokenRequiredError, UserAlreadyHasPasswordError, UserEmailNotFoundError, UserNotFoundError, getErrorHandlerConfig, isAPIError, mapBetterAuthError, wrapBetterAuth };
614
534
 
615
535
  //# sourceMappingURL=index.mjs.map