@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.
- package/dist/access-control/index.d.mts +8 -14
- package/dist/access-control/index.d.mts.map +1 -1
- package/dist/access-control/index.mjs +2 -2
- package/dist/{access.service-Cb99esfz.mjs → access.service-DWRsDLJq.mjs} +5 -11
- package/dist/access.service-DWRsDLJq.mjs.map +1 -0
- package/dist/auth/index.d.mts +60 -133
- package/dist/auth/index.d.mts.map +1 -1
- package/dist/auth/index.mjs +119 -199
- package/dist/auth/index.mjs.map +1 -1
- package/dist/{auth-context-HLwuOl51.mjs → auth-context-CObJcW0t.mjs} +7 -6
- package/dist/auth-context-CObJcW0t.mjs.map +1 -0
- package/dist/{auth-context-DXSTlnQH.d.mts → auth-context-D70ktWUf.d.mts} +1 -1
- package/dist/{auth-context-DXSTlnQH.d.mts.map → auth-context-D70ktWUf.d.mts.map} +1 -1
- package/dist/context/index.d.mts +5 -10
- package/dist/context/index.d.mts.map +1 -1
- package/dist/context/index.mjs +3 -3
- package/dist/database/index.d.mts +3 -3
- package/dist/database/index.mjs +44 -179
- package/dist/database/index.mjs.map +1 -1
- package/dist/errors-MCyrn_V2.mjs +18 -0
- package/dist/errors-MCyrn_V2.mjs.map +1 -0
- package/dist/factory/index.d.mts +1 -1
- package/dist/guards/index.d.mts.map +1 -1
- package/dist/guards/index.mjs +8 -15
- package/dist/guards/index.mjs.map +1 -1
- package/dist/{index-CCDPF-1Y.d.mts → index-DJ_DCIul.d.mts} +11 -93
- package/dist/index-DJ_DCIul.d.mts.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/insufficient-permissions.error-GwrkWnEM.mjs +16 -0
- package/dist/insufficient-permissions.error-GwrkWnEM.mjs.map +1 -0
- package/dist/{types-BZlcRR2M.d.mts → types-4uX3XKRM.d.mts} +1 -1
- package/dist/{types-BZlcRR2M.d.mts.map → types-4uX3XKRM.d.mts.map} +1 -1
- package/dist/{types-BLyu9dAd.d.mts → types-tu9pTehB.d.mts} +1 -1
- package/dist/{types-BLyu9dAd.d.mts.map → types-tu9pTehB.d.mts.map} +1 -1
- package/package.json +12 -9
- package/dist/access.service-Cb99esfz.mjs.map +0 -1
- package/dist/auth-context-HLwuOl51.mjs.map +0 -1
- package/dist/decorateMetadata-D5WUsc6Y.mjs +0 -6
- package/dist/errors-B1vVXc1T.mjs +0 -25
- package/dist/errors-B1vVXc1T.mjs.map +0 -1
- package/dist/index-CCDPF-1Y.d.mts.map +0 -1
- package/dist/insufficient-permissions.error-CRnOHYvq.mjs +0 -23
- package/dist/insufficient-permissions.error-CRnOHYvq.mjs.map +0 -1
- /package/dist/{decorate-DViXs-0l.mjs → decorate-7CAoTBu4.mjs} +0 -0
package/dist/auth/index.mjs
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { n as createStratalAcPlugin, t as AccessService } from "../access.service-
|
|
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
|
|
4
|
-
import { t as
|
|
5
|
-
import {
|
|
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 {
|
|
8
|
+
import { AuthError, HttpException } from "stratal/errors";
|
|
11
9
|
import { LOGGER_TOKENS } from "stratal/logger";
|
|
12
|
-
import {
|
|
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
|
|
103
|
-
__decorateParam(1, inject
|
|
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
|
|
137
|
+
var UserNotFoundError = class extends HttpException {
|
|
138
|
+
email;
|
|
192
139
|
constructor(email) {
|
|
193
|
-
super(
|
|
140
|
+
super(404, "User not found");
|
|
141
|
+
this.email = email;
|
|
194
142
|
}
|
|
195
143
|
};
|
|
196
|
-
var InvalidCredentialsError = class extends
|
|
144
|
+
var InvalidCredentialsError = class extends HttpException {
|
|
197
145
|
constructor() {
|
|
198
|
-
super("
|
|
146
|
+
super(401, "Invalid email or password");
|
|
199
147
|
}
|
|
200
148
|
};
|
|
201
|
-
var InvalidPasswordError = class extends
|
|
149
|
+
var InvalidPasswordError = class extends HttpException {
|
|
202
150
|
constructor() {
|
|
203
|
-
super("
|
|
151
|
+
super(401, "Invalid password");
|
|
204
152
|
}
|
|
205
153
|
};
|
|
206
|
-
var InvalidEmailError = class extends
|
|
154
|
+
var InvalidEmailError = class extends HttpException {
|
|
155
|
+
email;
|
|
207
156
|
constructor(email) {
|
|
208
|
-
super(
|
|
157
|
+
super(422, "Invalid email address");
|
|
158
|
+
this.email = email;
|
|
209
159
|
}
|
|
210
160
|
};
|
|
211
|
-
var SessionExpiredError = class extends
|
|
161
|
+
var SessionExpiredError = class extends HttpException {
|
|
212
162
|
constructor() {
|
|
213
|
-
super("
|
|
163
|
+
super(401, "Session expired");
|
|
214
164
|
}
|
|
215
165
|
};
|
|
216
|
-
var EmailNotVerifiedError = class extends
|
|
166
|
+
var EmailNotVerifiedError = class extends HttpException {
|
|
167
|
+
email;
|
|
217
168
|
constructor(email) {
|
|
218
|
-
super(
|
|
169
|
+
super(403, "Email not verified");
|
|
170
|
+
this.email = email;
|
|
219
171
|
}
|
|
220
172
|
};
|
|
221
|
-
var PasswordTooShortError = class extends
|
|
173
|
+
var PasswordTooShortError = class extends HttpException {
|
|
174
|
+
minLength;
|
|
222
175
|
constructor(minLength) {
|
|
223
|
-
super(
|
|
176
|
+
super(422, "Password too short");
|
|
177
|
+
this.minLength = minLength;
|
|
224
178
|
}
|
|
225
179
|
};
|
|
226
|
-
var PasswordTooLongError = class extends
|
|
180
|
+
var PasswordTooLongError = class extends HttpException {
|
|
181
|
+
maxLength;
|
|
227
182
|
constructor(maxLength) {
|
|
228
|
-
super(
|
|
183
|
+
super(422, "Password too long");
|
|
184
|
+
this.maxLength = maxLength;
|
|
229
185
|
}
|
|
230
186
|
};
|
|
231
|
-
var AccountAlreadyExistsError = class extends
|
|
187
|
+
var AccountAlreadyExistsError = class extends HttpException {
|
|
188
|
+
email;
|
|
232
189
|
constructor(email) {
|
|
233
|
-
super(
|
|
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
|
|
247
|
-
|
|
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(
|
|
197
|
+
super(409, "Social account already linked");
|
|
198
|
+
this.provider = provider;
|
|
254
199
|
}
|
|
255
200
|
};
|
|
256
|
-
var CannotUnlinkLastAccountError = class extends
|
|
201
|
+
var CannotUnlinkLastAccountError = class extends HttpException {
|
|
257
202
|
constructor() {
|
|
258
|
-
super("
|
|
203
|
+
super(409, "Cannot unlink last account");
|
|
259
204
|
}
|
|
260
205
|
};
|
|
261
|
-
var ProviderNotFoundError = class extends
|
|
206
|
+
var ProviderNotFoundError = class extends HttpException {
|
|
207
|
+
provider;
|
|
262
208
|
constructor(provider) {
|
|
263
|
-
super(
|
|
209
|
+
super(404, "Authentication provider not found");
|
|
210
|
+
this.provider = provider;
|
|
264
211
|
}
|
|
265
212
|
};
|
|
266
|
-
var UserEmailNotFoundError = class extends
|
|
213
|
+
var UserEmailNotFoundError = class extends HttpException {
|
|
267
214
|
constructor() {
|
|
268
|
-
super("
|
|
215
|
+
super(404, "User email not found");
|
|
269
216
|
}
|
|
270
217
|
};
|
|
271
|
-
var AccountNotFoundError = class extends
|
|
218
|
+
var AccountNotFoundError = class extends HttpException {
|
|
272
219
|
constructor() {
|
|
273
|
-
super("
|
|
220
|
+
super(404, "Account not found");
|
|
274
221
|
}
|
|
275
222
|
};
|
|
276
|
-
var CredentialAccountNotFoundError = class extends
|
|
223
|
+
var CredentialAccountNotFoundError = class extends HttpException {
|
|
277
224
|
constructor() {
|
|
278
|
-
super("
|
|
225
|
+
super(404, "Credential account not found");
|
|
279
226
|
}
|
|
280
227
|
};
|
|
281
|
-
var UserAlreadyHasPasswordError = class extends
|
|
228
|
+
var UserAlreadyHasPasswordError = class extends HttpException {
|
|
282
229
|
constructor() {
|
|
283
|
-
super("
|
|
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
|
|
233
|
+
var EmailCannotBeUpdatedError = class extends HttpException {
|
|
234
|
+
reason;
|
|
297
235
|
constructor(reason) {
|
|
298
|
-
super(
|
|
236
|
+
super(422, "Email cannot be updated");
|
|
237
|
+
this.reason = reason;
|
|
299
238
|
}
|
|
300
239
|
};
|
|
301
|
-
var IdTokenNotSupportedError = class extends
|
|
240
|
+
var IdTokenNotSupportedError = class extends HttpException {
|
|
302
241
|
constructor() {
|
|
303
|
-
super("
|
|
242
|
+
super(422, "ID token not supported");
|
|
304
243
|
}
|
|
305
244
|
};
|
|
306
|
-
var TokenExpiredError = class extends
|
|
245
|
+
var TokenExpiredError = class extends HttpException {
|
|
307
246
|
constructor() {
|
|
308
|
-
super("
|
|
247
|
+
super(401, "Token expired");
|
|
309
248
|
}
|
|
310
249
|
};
|
|
311
|
-
var InvalidCallbackUrlError = class extends
|
|
250
|
+
var InvalidCallbackUrlError = class extends HttpException {
|
|
312
251
|
constructor() {
|
|
313
|
-
super("
|
|
252
|
+
super(422, "Invalid callback URL");
|
|
314
253
|
}
|
|
315
254
|
};
|
|
316
|
-
var InvalidOriginError = class extends
|
|
255
|
+
var InvalidOriginError = class extends HttpException {
|
|
317
256
|
constructor() {
|
|
318
|
-
super("
|
|
257
|
+
super(403, "Invalid request origin");
|
|
319
258
|
}
|
|
320
259
|
};
|
|
321
|
-
var AuthValidationFailedError = class extends
|
|
260
|
+
var AuthValidationFailedError = class extends HttpException {
|
|
322
261
|
constructor() {
|
|
323
|
-
super("
|
|
262
|
+
super(422, "Authentication validation failed");
|
|
324
263
|
}
|
|
325
264
|
};
|
|
326
|
-
var EmailAlreadyVerifiedError = class extends
|
|
265
|
+
var EmailAlreadyVerifiedError = class extends HttpException {
|
|
327
266
|
constructor() {
|
|
328
|
-
super("
|
|
267
|
+
super(409, "Email already verified");
|
|
329
268
|
}
|
|
330
269
|
};
|
|
331
|
-
var EmailMismatchError = class extends
|
|
270
|
+
var EmailMismatchError = class extends HttpException {
|
|
332
271
|
constructor() {
|
|
333
|
-
super("
|
|
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
|
|
277
|
+
var InvalidTokenError = class extends HttpException {
|
|
344
278
|
constructor() {
|
|
345
|
-
super("
|
|
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
|
|
284
|
+
var OrganizationNotFoundError = class extends HttpException {
|
|
351
285
|
constructor() {
|
|
352
|
-
super("
|
|
286
|
+
super(404, "Organization not found");
|
|
353
287
|
}
|
|
354
288
|
};
|
|
355
|
-
var OrganizationMemberNotFoundError = class extends
|
|
289
|
+
var OrganizationMemberNotFoundError = class extends HttpException {
|
|
356
290
|
constructor() {
|
|
357
|
-
super("
|
|
291
|
+
super(404, "Organization member not found");
|
|
358
292
|
}
|
|
359
293
|
};
|
|
360
|
-
var OrganizationInvitationNotFoundError = class extends
|
|
294
|
+
var OrganizationInvitationNotFoundError = class extends HttpException {
|
|
361
295
|
constructor() {
|
|
362
|
-
super("
|
|
296
|
+
super(404, "Invitation not found");
|
|
363
297
|
}
|
|
364
298
|
};
|
|
365
|
-
var OrganizationPermissionDeniedError = class extends
|
|
299
|
+
var OrganizationPermissionDeniedError = class extends HttpException {
|
|
366
300
|
constructor() {
|
|
367
|
-
super("
|
|
301
|
+
super(403, "Organization permission denied");
|
|
368
302
|
}
|
|
369
303
|
};
|
|
370
|
-
var OrganizationInvitationRecipientMismatchError = class extends
|
|
304
|
+
var OrganizationInvitationRecipientMismatchError = class extends HttpException {
|
|
371
305
|
constructor() {
|
|
372
|
-
super("
|
|
306
|
+
super(403, "Invitation recipient mismatch");
|
|
373
307
|
}
|
|
374
308
|
};
|
|
375
|
-
var OrganizationConflictError = class extends
|
|
309
|
+
var OrganizationConflictError = class extends HttpException {
|
|
376
310
|
constructor() {
|
|
377
|
-
super("
|
|
311
|
+
super(409, "Organization resource conflict");
|
|
378
312
|
}
|
|
379
313
|
};
|
|
380
|
-
var OrganizationLimitReachedError = class extends
|
|
314
|
+
var OrganizationLimitReachedError = class extends HttpException {
|
|
381
315
|
constructor() {
|
|
382
|
-
super("
|
|
316
|
+
super(422, "Organization limit reached");
|
|
383
317
|
}
|
|
384
318
|
};
|
|
385
|
-
var OrganizationMembershipError = class extends
|
|
319
|
+
var OrganizationMembershipError = class extends HttpException {
|
|
386
320
|
constructor() {
|
|
387
|
-
super("
|
|
321
|
+
super(422, "Organization membership constraint violated");
|
|
388
322
|
}
|
|
389
323
|
};
|
|
390
|
-
var OrganizationTeamNotFoundError = class extends
|
|
324
|
+
var OrganizationTeamNotFoundError = class extends HttpException {
|
|
391
325
|
constructor() {
|
|
392
|
-
super("
|
|
326
|
+
super(404, "Team not found");
|
|
393
327
|
}
|
|
394
328
|
};
|
|
395
|
-
var OrganizationRoleNotFoundError = class extends
|
|
329
|
+
var OrganizationRoleNotFoundError = class extends HttpException {
|
|
396
330
|
constructor() {
|
|
397
|
-
super("
|
|
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
|
|
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("
|
|
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
|
|
428
|
-
if (location.includes("failed_to_create_session")) return new
|
|
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
|
|
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
|
|
438
|
-
if (errorCode === "FAILED_TO_GET_SESSION") return new
|
|
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
|
|
450
|
-
if (errorCode === "FAILED_TO_UPDATE_USER") return new
|
|
451
|
-
if (errorCode === "FAILED_TO_GET_USER_INFO") return new
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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,
|
|
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
|