@stratal/framework 0.0.20 → 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 +3 -3
- package/dist/access-control/index.mjs.map +1 -1
- package/dist/{access.service-BjYVtUJw.mjs → access.service-DWRsDLJq.mjs} +9 -12
- 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 +123 -200
- package/dist/auth/index.mjs.map +1 -1
- package/dist/{auth-context-6Li1JkIq.mjs → auth-context-CObJcW0t.mjs} +7 -6
- package/dist/auth-context-CObJcW0t.mjs.map +1 -0
- package/dist/{auth-context-B44CDZCt.d.mts → auth-context-D70ktWUf.d.mts} +8 -9
- package/dist/auth-context-D70ktWUf.d.mts.map +1 -0
- 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 +45 -179
- package/dist/database/index.mjs.map +1 -1
- package/dist/{decorate-CdfCRvAc.mjs → decorate-7CAoTBu4.mjs} +1 -1
- package/dist/{decorateParam-Dc5DGEpb.mjs → decorateParam-C_dJ_dIO.mjs} +2 -2
- package/dist/{decorateParam-Dc5DGEpb.mjs.map → decorateParam-C_dJ_dIO.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/factory/index.mjs +1 -0
- package/dist/factory/index.mjs.map +1 -1
- package/dist/guards/index.d.mts.map +1 -1
- package/dist/guards/index.mjs +12 -16
- 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 +16 -14
- package/dist/access.service-BjYVtUJw.mjs.map +0 -1
- package/dist/auth-context-6Li1JkIq.mjs.map +0 -1
- package/dist/auth-context-B44CDZCt.d.mts.map +0 -1
- package/dist/decorateMetadata-CqtSx3_1.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/auth/index.mjs
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { n as createStratalAcPlugin, t as AccessService } from "../access.service-
|
|
2
|
-
import { n as AC_TOKENS, t as __decorateParam } from "../decorateParam-
|
|
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";
|
|
1
|
+
import { n as createStratalAcPlugin, t as AccessService } from "../access.service-DWRsDLJq.mjs";
|
|
2
|
+
import { n as AC_TOKENS, t as __decorateParam } from "../decorateParam-C_dJ_dIO.mjs";
|
|
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) {
|
|
@@ -81,6 +28,8 @@ AuthContextMiddleware = __decorate([Transient()], AuthContextMiddleware);
|
|
|
81
28
|
//#endregion
|
|
82
29
|
//#region src/auth/middleware/session-verification.middleware.ts
|
|
83
30
|
let SessionVerificationMiddleware = class SessionVerificationMiddleware {
|
|
31
|
+
authService;
|
|
32
|
+
logger;
|
|
84
33
|
constructor(authService, logger) {
|
|
85
34
|
this.authService = authService;
|
|
86
35
|
this.logger = logger;
|
|
@@ -97,9 +46,8 @@ let SessionVerificationMiddleware = class SessionVerificationMiddleware {
|
|
|
97
46
|
};
|
|
98
47
|
SessionVerificationMiddleware = __decorate([
|
|
99
48
|
Transient(),
|
|
100
|
-
__decorateParam(0, inject
|
|
101
|
-
__decorateParam(1, inject
|
|
102
|
-
__decorateMetadata("design:paramtypes", [Object, Object])
|
|
49
|
+
__decorateParam(0, inject(AUTH_SERVICE)),
|
|
50
|
+
__decorateParam(1, inject(LOGGER_TOKENS.LoggerService))
|
|
103
51
|
], SessionVerificationMiddleware);
|
|
104
52
|
//#endregion
|
|
105
53
|
//#region src/auth/rate-limit-bridge.ts
|
|
@@ -186,227 +134,208 @@ function projectCustomRules(registry) {
|
|
|
186
134
|
}
|
|
187
135
|
//#endregion
|
|
188
136
|
//#region src/auth/errors/auth-errors.ts
|
|
189
|
-
var UserNotFoundError = class extends
|
|
137
|
+
var UserNotFoundError = class extends HttpException {
|
|
138
|
+
email;
|
|
190
139
|
constructor(email) {
|
|
191
|
-
super(
|
|
140
|
+
super(404, "User not found");
|
|
141
|
+
this.email = email;
|
|
192
142
|
}
|
|
193
143
|
};
|
|
194
|
-
var InvalidCredentialsError = class extends
|
|
144
|
+
var InvalidCredentialsError = class extends HttpException {
|
|
195
145
|
constructor() {
|
|
196
|
-
super("
|
|
146
|
+
super(401, "Invalid email or password");
|
|
197
147
|
}
|
|
198
148
|
};
|
|
199
|
-
var InvalidPasswordError = class extends
|
|
149
|
+
var InvalidPasswordError = class extends HttpException {
|
|
200
150
|
constructor() {
|
|
201
|
-
super("
|
|
151
|
+
super(401, "Invalid password");
|
|
202
152
|
}
|
|
203
153
|
};
|
|
204
|
-
var InvalidEmailError = class extends
|
|
154
|
+
var InvalidEmailError = class extends HttpException {
|
|
155
|
+
email;
|
|
205
156
|
constructor(email) {
|
|
206
|
-
super(
|
|
157
|
+
super(422, "Invalid email address");
|
|
158
|
+
this.email = email;
|
|
207
159
|
}
|
|
208
160
|
};
|
|
209
|
-
var SessionExpiredError = class extends
|
|
161
|
+
var SessionExpiredError = class extends HttpException {
|
|
210
162
|
constructor() {
|
|
211
|
-
super("
|
|
163
|
+
super(401, "Session expired");
|
|
212
164
|
}
|
|
213
165
|
};
|
|
214
|
-
var EmailNotVerifiedError = class extends
|
|
166
|
+
var EmailNotVerifiedError = class extends HttpException {
|
|
167
|
+
email;
|
|
215
168
|
constructor(email) {
|
|
216
|
-
super(
|
|
169
|
+
super(403, "Email not verified");
|
|
170
|
+
this.email = email;
|
|
217
171
|
}
|
|
218
172
|
};
|
|
219
|
-
var PasswordTooShortError = class extends
|
|
173
|
+
var PasswordTooShortError = class extends HttpException {
|
|
174
|
+
minLength;
|
|
220
175
|
constructor(minLength) {
|
|
221
|
-
super(
|
|
176
|
+
super(422, "Password too short");
|
|
177
|
+
this.minLength = minLength;
|
|
222
178
|
}
|
|
223
179
|
};
|
|
224
|
-
var PasswordTooLongError = class extends
|
|
180
|
+
var PasswordTooLongError = class extends HttpException {
|
|
181
|
+
maxLength;
|
|
225
182
|
constructor(maxLength) {
|
|
226
|
-
super(
|
|
183
|
+
super(422, "Password too long");
|
|
184
|
+
this.maxLength = maxLength;
|
|
227
185
|
}
|
|
228
186
|
};
|
|
229
|
-
var AccountAlreadyExistsError = class extends
|
|
187
|
+
var AccountAlreadyExistsError = class extends HttpException {
|
|
188
|
+
email;
|
|
230
189
|
constructor(email) {
|
|
231
|
-
super(
|
|
232
|
-
|
|
233
|
-
};
|
|
234
|
-
var FailedToCreateUserError = class extends ApplicationError {
|
|
235
|
-
constructor(reason) {
|
|
236
|
-
super("auth.errors.failedToCreateUser", ERROR_CODES.AUTH.FAILED_TO_CREATE_USER, reason ? { reason } : void 0);
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
var FailedToCreateSessionError = class extends ApplicationError {
|
|
240
|
-
constructor(reason) {
|
|
241
|
-
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;
|
|
242
192
|
}
|
|
243
193
|
};
|
|
244
|
-
var
|
|
245
|
-
|
|
246
|
-
super("auth.errors.failedToUpdateUser", ERROR_CODES.AUTH.FAILED_TO_UPDATE_USER, reason ? { reason } : void 0);
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
var SocialAccountLinkedError = class extends ApplicationError {
|
|
194
|
+
var SocialAccountLinkedError = class extends HttpException {
|
|
195
|
+
provider;
|
|
250
196
|
constructor(provider) {
|
|
251
|
-
super(
|
|
197
|
+
super(409, "Social account already linked");
|
|
198
|
+
this.provider = provider;
|
|
252
199
|
}
|
|
253
200
|
};
|
|
254
|
-
var CannotUnlinkLastAccountError = class extends
|
|
201
|
+
var CannotUnlinkLastAccountError = class extends HttpException {
|
|
255
202
|
constructor() {
|
|
256
|
-
super("
|
|
203
|
+
super(409, "Cannot unlink last account");
|
|
257
204
|
}
|
|
258
205
|
};
|
|
259
|
-
var ProviderNotFoundError = class extends
|
|
206
|
+
var ProviderNotFoundError = class extends HttpException {
|
|
207
|
+
provider;
|
|
260
208
|
constructor(provider) {
|
|
261
|
-
super(
|
|
209
|
+
super(404, "Authentication provider not found");
|
|
210
|
+
this.provider = provider;
|
|
262
211
|
}
|
|
263
212
|
};
|
|
264
|
-
var UserEmailNotFoundError = class extends
|
|
213
|
+
var UserEmailNotFoundError = class extends HttpException {
|
|
265
214
|
constructor() {
|
|
266
|
-
super("
|
|
215
|
+
super(404, "User email not found");
|
|
267
216
|
}
|
|
268
217
|
};
|
|
269
|
-
var AccountNotFoundError = class extends
|
|
218
|
+
var AccountNotFoundError = class extends HttpException {
|
|
270
219
|
constructor() {
|
|
271
|
-
super("
|
|
220
|
+
super(404, "Account not found");
|
|
272
221
|
}
|
|
273
222
|
};
|
|
274
|
-
var CredentialAccountNotFoundError = class extends
|
|
223
|
+
var CredentialAccountNotFoundError = class extends HttpException {
|
|
275
224
|
constructor() {
|
|
276
|
-
super("
|
|
225
|
+
super(404, "Credential account not found");
|
|
277
226
|
}
|
|
278
227
|
};
|
|
279
|
-
var UserAlreadyHasPasswordError = class extends
|
|
228
|
+
var UserAlreadyHasPasswordError = class extends HttpException {
|
|
280
229
|
constructor() {
|
|
281
|
-
super("
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
var EmailCannotBeUpdatedError = class extends ApplicationError {
|
|
285
|
-
constructor(reason) {
|
|
286
|
-
super("auth.errors.emailCannotBeUpdated", ERROR_CODES.VALIDATION.GENERIC, reason ? { reason } : void 0);
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
var FailedToGetSessionError = class extends ApplicationError {
|
|
290
|
-
constructor(reason) {
|
|
291
|
-
super("auth.errors.failedToGetSession", ERROR_CODES.SYSTEM.INTERNAL_ERROR, reason ? { reason } : void 0);
|
|
230
|
+
super(409, "User already has a password");
|
|
292
231
|
}
|
|
293
232
|
};
|
|
294
|
-
var
|
|
233
|
+
var EmailCannotBeUpdatedError = class extends HttpException {
|
|
234
|
+
reason;
|
|
295
235
|
constructor(reason) {
|
|
296
|
-
super(
|
|
236
|
+
super(422, "Email cannot be updated");
|
|
237
|
+
this.reason = reason;
|
|
297
238
|
}
|
|
298
239
|
};
|
|
299
|
-
var IdTokenNotSupportedError = class extends
|
|
240
|
+
var IdTokenNotSupportedError = class extends HttpException {
|
|
300
241
|
constructor() {
|
|
301
|
-
super("
|
|
242
|
+
super(422, "ID token not supported");
|
|
302
243
|
}
|
|
303
244
|
};
|
|
304
|
-
var TokenExpiredError = class extends
|
|
245
|
+
var TokenExpiredError = class extends HttpException {
|
|
305
246
|
constructor() {
|
|
306
|
-
super("
|
|
247
|
+
super(401, "Token expired");
|
|
307
248
|
}
|
|
308
249
|
};
|
|
309
|
-
var InvalidCallbackUrlError = class extends
|
|
250
|
+
var InvalidCallbackUrlError = class extends HttpException {
|
|
310
251
|
constructor() {
|
|
311
|
-
super("
|
|
252
|
+
super(422, "Invalid callback URL");
|
|
312
253
|
}
|
|
313
254
|
};
|
|
314
|
-
var InvalidOriginError = class extends
|
|
255
|
+
var InvalidOriginError = class extends HttpException {
|
|
315
256
|
constructor() {
|
|
316
|
-
super("
|
|
257
|
+
super(403, "Invalid request origin");
|
|
317
258
|
}
|
|
318
259
|
};
|
|
319
|
-
var AuthValidationFailedError = class extends
|
|
260
|
+
var AuthValidationFailedError = class extends HttpException {
|
|
320
261
|
constructor() {
|
|
321
|
-
super("
|
|
262
|
+
super(422, "Authentication validation failed");
|
|
322
263
|
}
|
|
323
264
|
};
|
|
324
|
-
var EmailAlreadyVerifiedError = class extends
|
|
265
|
+
var EmailAlreadyVerifiedError = class extends HttpException {
|
|
325
266
|
constructor() {
|
|
326
|
-
super("
|
|
267
|
+
super(409, "Email already verified");
|
|
327
268
|
}
|
|
328
269
|
};
|
|
329
|
-
var EmailMismatchError = class extends
|
|
270
|
+
var EmailMismatchError = class extends HttpException {
|
|
330
271
|
constructor() {
|
|
331
|
-
super("
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
var BetterAuthUnknownError = class extends ApplicationError {
|
|
335
|
-
constructor(errorCode) {
|
|
336
|
-
super("auth.errors.unknownError", ERROR_CODES.SYSTEM.INTERNAL_ERROR, errorCode ? { errorCode } : void 0);
|
|
272
|
+
super(422, "Email mismatch");
|
|
337
273
|
}
|
|
338
274
|
};
|
|
339
275
|
//#endregion
|
|
340
276
|
//#region src/auth/errors/invalid-token.error.ts
|
|
341
|
-
var InvalidTokenError = class extends
|
|
277
|
+
var InvalidTokenError = class extends HttpException {
|
|
342
278
|
constructor() {
|
|
343
|
-
super("
|
|
279
|
+
super(401, "Invalid or expired token");
|
|
344
280
|
}
|
|
345
281
|
};
|
|
346
282
|
//#endregion
|
|
347
283
|
//#region src/auth/errors/organization-errors.ts
|
|
348
|
-
var OrganizationNotFoundError = class extends
|
|
284
|
+
var OrganizationNotFoundError = class extends HttpException {
|
|
349
285
|
constructor() {
|
|
350
|
-
super("
|
|
286
|
+
super(404, "Organization not found");
|
|
351
287
|
}
|
|
352
288
|
};
|
|
353
|
-
var OrganizationMemberNotFoundError = class extends
|
|
289
|
+
var OrganizationMemberNotFoundError = class extends HttpException {
|
|
354
290
|
constructor() {
|
|
355
|
-
super("
|
|
291
|
+
super(404, "Organization member not found");
|
|
356
292
|
}
|
|
357
293
|
};
|
|
358
|
-
var OrganizationInvitationNotFoundError = class extends
|
|
294
|
+
var OrganizationInvitationNotFoundError = class extends HttpException {
|
|
359
295
|
constructor() {
|
|
360
|
-
super("
|
|
296
|
+
super(404, "Invitation not found");
|
|
361
297
|
}
|
|
362
298
|
};
|
|
363
|
-
var OrganizationPermissionDeniedError = class extends
|
|
299
|
+
var OrganizationPermissionDeniedError = class extends HttpException {
|
|
364
300
|
constructor() {
|
|
365
|
-
super("
|
|
301
|
+
super(403, "Organization permission denied");
|
|
366
302
|
}
|
|
367
303
|
};
|
|
368
|
-
var OrganizationInvitationRecipientMismatchError = class extends
|
|
304
|
+
var OrganizationInvitationRecipientMismatchError = class extends HttpException {
|
|
369
305
|
constructor() {
|
|
370
|
-
super("
|
|
306
|
+
super(403, "Invitation recipient mismatch");
|
|
371
307
|
}
|
|
372
308
|
};
|
|
373
|
-
var OrganizationConflictError = class extends
|
|
309
|
+
var OrganizationConflictError = class extends HttpException {
|
|
374
310
|
constructor() {
|
|
375
|
-
super("
|
|
311
|
+
super(409, "Organization resource conflict");
|
|
376
312
|
}
|
|
377
313
|
};
|
|
378
|
-
var OrganizationLimitReachedError = class extends
|
|
314
|
+
var OrganizationLimitReachedError = class extends HttpException {
|
|
379
315
|
constructor() {
|
|
380
|
-
super("
|
|
316
|
+
super(422, "Organization limit reached");
|
|
381
317
|
}
|
|
382
318
|
};
|
|
383
|
-
var OrganizationMembershipError = class extends
|
|
319
|
+
var OrganizationMembershipError = class extends HttpException {
|
|
384
320
|
constructor() {
|
|
385
|
-
super("
|
|
321
|
+
super(422, "Organization membership constraint violated");
|
|
386
322
|
}
|
|
387
323
|
};
|
|
388
|
-
var OrganizationTeamNotFoundError = class extends
|
|
324
|
+
var OrganizationTeamNotFoundError = class extends HttpException {
|
|
389
325
|
constructor() {
|
|
390
|
-
super("
|
|
326
|
+
super(404, "Team not found");
|
|
391
327
|
}
|
|
392
328
|
};
|
|
393
|
-
var OrganizationRoleNotFoundError = class extends
|
|
329
|
+
var OrganizationRoleNotFoundError = class extends HttpException {
|
|
394
330
|
constructor() {
|
|
395
|
-
super("
|
|
331
|
+
super(404, "Role not found");
|
|
396
332
|
}
|
|
397
333
|
};
|
|
398
334
|
//#endregion
|
|
399
335
|
//#region src/auth/errors/token-required.error.ts
|
|
400
|
-
var TokenRequiredError = class extends
|
|
401
|
-
constructor() {
|
|
402
|
-
super("auth.errors.tokenRequired", ERROR_CODES.VALIDATION.REQUIRED_FIELD, { field: "token" });
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
//#endregion
|
|
406
|
-
//#region src/auth/errors/verification-failed.error.ts
|
|
407
|
-
var VerificationFailedError = class extends ApplicationError {
|
|
336
|
+
var TokenRequiredError = class extends HttpException {
|
|
408
337
|
constructor() {
|
|
409
|
-
super("
|
|
338
|
+
super(401, "Verification token is required");
|
|
410
339
|
}
|
|
411
340
|
};
|
|
412
341
|
//#endregion
|
|
@@ -422,18 +351,18 @@ function mapBetterAuthError(error) {
|
|
|
422
351
|
if (location.includes("EXPIRED_TOKEN")) return new TokenExpiredError();
|
|
423
352
|
if (location.includes("ATTEMPTS_EXCEEDED")) return new InvalidTokenError();
|
|
424
353
|
if (location.includes("new_user_signup_disabled")) return new UserNotFoundError();
|
|
425
|
-
if (location.includes("failed_to_create_user")) return new
|
|
426
|
-
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");
|
|
427
356
|
}
|
|
428
|
-
if (!errorCode) return new
|
|
357
|
+
if (!errorCode) return new AuthError("An authentication error occurred");
|
|
429
358
|
if (errorCode === "USER_NOT_FOUND" || errorCode === "INVALID_USER") return new UserNotFoundError();
|
|
430
359
|
if (errorCode === "USER_EMAIL_NOT_FOUND") return new UserEmailNotFoundError();
|
|
431
360
|
if (errorCode === "INVALID_EMAIL_OR_PASSWORD") return new InvalidCredentialsError();
|
|
432
361
|
if (errorCode === "INVALID_PASSWORD") return new InvalidPasswordError();
|
|
433
362
|
if (errorCode === "INVALID_EMAIL") return new InvalidEmailError();
|
|
434
363
|
if (errorCode === "SESSION_EXPIRED" || errorCode === "SESSION_NOT_FRESH") return new SessionExpiredError();
|
|
435
|
-
if (errorCode === "FAILED_TO_CREATE_SESSION") return new
|
|
436
|
-
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");
|
|
437
366
|
if (errorCode === "EMAIL_NOT_VERIFIED") return new EmailNotVerifiedError();
|
|
438
367
|
if (errorCode === "EMAIL_CAN_NOT_BE_UPDATED") return new EmailCannotBeUpdatedError();
|
|
439
368
|
if (errorCode === "EMAIL_ALREADY_VERIFIED") return new EmailAlreadyVerifiedError();
|
|
@@ -444,9 +373,9 @@ function mapBetterAuthError(error) {
|
|
|
444
373
|
if (errorCode === "ACCOUNT_NOT_FOUND") return new AccountNotFoundError();
|
|
445
374
|
if (errorCode === "CREDENTIAL_ACCOUNT_NOT_FOUND") return new CredentialAccountNotFoundError();
|
|
446
375
|
if (errorCode === "FAILED_TO_UNLINK_LAST_ACCOUNT") return new CannotUnlinkLastAccountError();
|
|
447
|
-
if (errorCode === "FAILED_TO_CREATE_USER") return new
|
|
448
|
-
if (errorCode === "FAILED_TO_UPDATE_USER") return new
|
|
449
|
-
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");
|
|
450
379
|
if (errorCode === "SOCIAL_ACCOUNT_ALREADY_LINKED" || errorCode === "LINKED_ACCOUNT_ALREADY_EXISTS") return new SocialAccountLinkedError();
|
|
451
380
|
if (errorCode === "PROVIDER_NOT_FOUND") return new ProviderNotFoundError();
|
|
452
381
|
if (errorCode === "ID_TOKEN_NOT_SUPPORTED") return new IdTokenNotSupportedError();
|
|
@@ -456,7 +385,7 @@ function mapBetterAuthError(error) {
|
|
|
456
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();
|
|
457
386
|
if (errorCode === "INVALID_ORIGIN" || errorCode === "MISSING_OR_NULL_ORIGIN" || errorCode === "CROSS_SITE_NAVIGATION_LOGIN_BLOCKED") return new InvalidOriginError();
|
|
458
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();
|
|
459
|
-
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");
|
|
460
389
|
if (errorCode === "ORGANIZATION_NOT_FOUND" || errorCode === "NO_ACTIVE_ORGANIZATION") return new OrganizationNotFoundError();
|
|
461
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();
|
|
462
391
|
if (errorCode === "INVITATION_NOT_FOUND" || errorCode === "FAILED_TO_RETRIEVE_INVITATION") return new OrganizationInvitationNotFoundError();
|
|
@@ -467,7 +396,7 @@ function mapBetterAuthError(error) {
|
|
|
467
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();
|
|
468
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();
|
|
469
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();
|
|
470
|
-
return new
|
|
399
|
+
return new AuthError("An authentication error occurred");
|
|
471
400
|
}
|
|
472
401
|
/**
|
|
473
402
|
* Type guard to check if an error is a Better Auth APIError.
|
|
@@ -507,26 +436,23 @@ const wrapBetterAuth = async (fn) => {
|
|
|
507
436
|
//#endregion
|
|
508
437
|
//#region src/auth/services/auth.service.ts
|
|
509
438
|
let AuthService = class AuthService {
|
|
510
|
-
|
|
439
|
+
options;
|
|
440
|
+
_authInstance;
|
|
511
441
|
constructor(options) {
|
|
512
442
|
this.options = options;
|
|
513
|
-
this.authInstance = betterAuth({
|
|
514
|
-
...this.options,
|
|
515
|
-
onAPIError: getErrorHandlerConfig()
|
|
516
|
-
});
|
|
517
443
|
}
|
|
518
444
|
/**
|
|
519
|
-
* Get the Better Auth instance
|
|
445
|
+
* Get the Better Auth instance.
|
|
520
446
|
*/
|
|
521
447
|
get auth() {
|
|
522
|
-
|
|
448
|
+
this._authInstance ??= betterAuth({
|
|
449
|
+
...this.options,
|
|
450
|
+
onAPIError: getErrorHandlerConfig()
|
|
451
|
+
});
|
|
452
|
+
return this._authInstance;
|
|
523
453
|
}
|
|
524
454
|
};
|
|
525
|
-
AuthService = __decorate([
|
|
526
|
-
Transient(AUTH_SERVICE),
|
|
527
|
-
__decorateParam(0, inject$1(AUTH_OPTIONS)),
|
|
528
|
-
__decorateMetadata("design:paramtypes", [Object])
|
|
529
|
-
], AuthService);
|
|
455
|
+
AuthService = __decorate([Request(AUTH_SERVICE), __decorateParam(0, inject(AUTH_OPTIONS))], AuthService);
|
|
530
456
|
//#endregion
|
|
531
457
|
//#region src/auth/auth.module.ts
|
|
532
458
|
var _AuthModule;
|
|
@@ -563,7 +489,7 @@ let AuthModule = _AuthModule = class AuthModule {
|
|
|
563
489
|
...raw,
|
|
564
490
|
plugins: [createStratalAcPlugin(accessControl), ...raw.plugins ?? []]
|
|
565
491
|
};
|
|
566
|
-
if (container.
|
|
492
|
+
if (container.isRegistered(RATE_LIMITER_TOKENS.ModuleMarker)) {
|
|
567
493
|
const store = container.resolve(RATE_LIMITER_TOKENS.Store);
|
|
568
494
|
const registry = container.resolve(RATE_LIMITER_TOKENS.Registry);
|
|
569
495
|
raw = {
|
|
@@ -602,11 +528,8 @@ let AuthModule = _AuthModule = class AuthModule {
|
|
|
602
528
|
};
|
|
603
529
|
}
|
|
604
530
|
};
|
|
605
|
-
AuthModule = _AuthModule = __decorate([Module({
|
|
606
|
-
imports: [I18nModule.registerMessages(authMessages)],
|
|
607
|
-
providers: []
|
|
608
|
-
})], AuthModule);
|
|
531
|
+
AuthModule = _AuthModule = __decorate([Module({ providers: [AuthContext] })], AuthModule);
|
|
609
532
|
//#endregion
|
|
610
|
-
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 };
|
|
611
534
|
|
|
612
535
|
//# sourceMappingURL=index.mjs.map
|