@veap/auth 0.1.0 → 0.1.2

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 (103) hide show
  1. package/README.md +3 -2
  2. package/dist/actions/auth.actions.d.ts +2 -2
  3. package/dist/actions/auth.actions.js +1 -1
  4. package/dist/actions/index.d.ts +1 -1
  5. package/dist/actions/index.js +1 -1
  6. package/dist/client/auth.context.d.ts +2 -2
  7. package/dist/client/auth.context.js +1 -1
  8. package/dist/client/index.d.ts +1 -1
  9. package/dist/client/index.js +1 -1
  10. package/dist/common/augment.d.ts +2 -2
  11. package/dist/common/augment.js +1 -1
  12. package/dist/common/context.d.ts +6 -5
  13. package/dist/common/context.js +7 -5
  14. package/dist/common/index.d.ts +7 -6
  15. package/dist/common/index.js +7 -6
  16. package/dist/common/logic.d.ts +3 -3
  17. package/dist/common/logic.js +3 -3
  18. package/dist/common/routes.d.ts +3 -2
  19. package/dist/common/routes.js +2 -1
  20. package/dist/common/tokens.d.ts +10 -0
  21. package/dist/common/tokens.js +8 -0
  22. package/dist/crypto/aes-cipher.d.ts +1 -1
  23. package/dist/crypto/aes-cipher.js +1 -1
  24. package/dist/crypto/bcrypt-hasher.d.ts +1 -1
  25. package/dist/crypto/index.d.ts +6 -6
  26. package/dist/crypto/index.js +6 -6
  27. package/dist/crypto/token-generator.d.ts +1 -1
  28. package/dist/index.d.ts +11 -11
  29. package/dist/index.js +11 -11
  30. package/dist/migrations/index.d.ts +1 -1
  31. package/dist/migrations/index.js +1 -1
  32. package/dist/models/EmailVerification.d.ts +1 -1
  33. package/dist/models/EmailVerification.js +1 -1
  34. package/dist/models/PasswordResetSession.d.ts +1 -1
  35. package/dist/models/PasswordResetSession.js +1 -1
  36. package/dist/models/Permission.d.ts +2 -2
  37. package/dist/models/Permission.js +2 -2
  38. package/dist/models/Role.d.ts +2 -2
  39. package/dist/models/Role.js +2 -2
  40. package/dist/models/Session.d.ts +1 -1
  41. package/dist/models/Session.js +1 -1
  42. package/dist/models/User.d.ts +3 -3
  43. package/dist/models/User.js +3 -3
  44. package/dist/models/index.d.ts +6 -6
  45. package/dist/models/index.js +6 -6
  46. package/dist/models.d.ts +1 -1
  47. package/dist/models.js +1 -1
  48. package/dist/passwords/contracts.d.ts +1 -1
  49. package/dist/passwords/index.d.ts +4 -4
  50. package/dist/passwords/index.js +4 -4
  51. package/dist/passwords/password-reset.facade.d.ts +1 -1
  52. package/dist/passwords/password-reset.facade.js +9 -2
  53. package/dist/passwords/password-reset.repository.d.ts +2 -2
  54. package/dist/passwords/password-reset.repository.js +1 -1
  55. package/dist/passwords/password-reset.service.d.ts +3 -3
  56. package/dist/passwords/password-reset.service.js +4 -4
  57. package/dist/providers/auth.provider.d.ts +1 -1
  58. package/dist/providers/auth.provider.js +32 -29
  59. package/dist/providers/index.d.ts +2 -2
  60. package/dist/providers/index.js +2 -2
  61. package/dist/providers/setup.js +1 -1
  62. package/dist/rbac/contracts.d.ts +1 -1
  63. package/dist/rbac/index.d.ts +4 -4
  64. package/dist/rbac/index.js +4 -4
  65. package/dist/rbac/rbac.facade.d.ts +9 -9
  66. package/dist/rbac/rbac.facade.js +9 -2
  67. package/dist/rbac/rbac.repository.d.ts +1 -1
  68. package/dist/rbac/rbac.repository.js +3 -3
  69. package/dist/rbac/rbac.service.d.ts +2 -2
  70. package/dist/rbac/rbac.service.js +1 -1
  71. package/dist/server.d.ts +3 -3
  72. package/dist/server.js +3 -3
  73. package/dist/session/auth.service.d.ts +6 -6
  74. package/dist/session/auth.service.js +7 -8
  75. package/dist/session/contracts.d.ts +1 -1
  76. package/dist/session/index.d.ts +5 -5
  77. package/dist/session/index.js +5 -5
  78. package/dist/session/session.facade.d.ts +1 -1
  79. package/dist/session/session.facade.js +2 -2
  80. package/dist/session/session.repository.d.ts +2 -2
  81. package/dist/session/session.repository.js +1 -1
  82. package/dist/session/session.service.d.ts +3 -3
  83. package/dist/session/session.service.js +7 -5
  84. package/dist/users/contracts.d.ts +2 -1
  85. package/dist/users/index.d.ts +4 -4
  86. package/dist/users/index.js +4 -4
  87. package/dist/users/user.facade.d.ts +15 -1
  88. package/dist/users/user.facade.js +36 -6
  89. package/dist/users/user.repository.d.ts +3 -2
  90. package/dist/users/user.repository.js +6 -1
  91. package/dist/users/user.service.d.ts +17 -5
  92. package/dist/users/user.service.js +24 -6
  93. package/dist/validation/index.d.ts +0 -5
  94. package/dist/validation/index.js +0 -9
  95. package/dist/verification/index.d.ts +4 -4
  96. package/dist/verification/index.js +4 -4
  97. package/dist/verification/verification.facade.d.ts +4 -4
  98. package/dist/verification/verification.facade.js +9 -2
  99. package/dist/verification/verification.repository.d.ts +1 -1
  100. package/dist/verification/verification.repository.js +1 -1
  101. package/dist/verification/verification.service.d.ts +3 -3
  102. package/dist/verification/verification.service.js +7 -5
  103. package/package.json +9 -9
@@ -12,9 +12,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  };
13
13
  import { AppError, Inject, Injectable } from "@veap/kernel";
14
14
  import { sendRecoveryCode } from "@veap/mail";
15
- import { PASSWORD_HASHER, SECRET_CIPHER, TOKEN_GENERATOR, } from "../crypto/contracts";
16
- import { ROLE_REPOSITORY } from "../rbac/contracts";
17
- import { USER_REPOSITORY } from "./contracts";
15
+ import { PASSWORD_HASHER, SECRET_CIPHER, TOKEN_GENERATOR, } from "../crypto/contracts.js";
16
+ import { ROLE_REPOSITORY } from "../rbac/contracts.js";
17
+ import { USER_REPOSITORY } from "./contracts.js";
18
18
  const DEFAULT_ROLE = "user";
19
19
  let UserService = class UserService {
20
20
  users;
@@ -37,6 +37,12 @@ let UserService = class UserService {
37
37
  username.length < 32 &&
38
38
  username.trim() === username);
39
39
  }
40
+ /**
41
+ * Checks whether the specified email is available for registration.
42
+ */
43
+ async isEmailAvailable(email) {
44
+ return await this.users.isEmailAvailable(email);
45
+ }
40
46
  /**
41
47
  * Creates a new user with an initial recovery code and default 'user' role.
42
48
  */
@@ -82,13 +88,19 @@ let UserService = class UserService {
82
88
  /**
83
89
  * Decrypts and returns the user's recovery code.
84
90
  */
85
- async getUserRecoverCode(userId) {
91
+ async getUserRecoveryCode(userId) {
86
92
  const stored = await this.users.findRecoveryCode(userId);
87
93
  if (!stored) {
88
94
  throw AppError.BadRequest("Recovery code not found for user");
89
95
  }
90
96
  return this.cipher.decryptToString(stored);
91
97
  }
98
+ /**
99
+ * @deprecated Use `getUserRecoveryCode` instead.
100
+ */
101
+ async getUserRecoverCode(userId) {
102
+ return this.getUserRecoveryCode(userId);
103
+ }
92
104
  /**
93
105
  * Generates and sets a new recovery code for the user.
94
106
  */
@@ -121,11 +133,17 @@ let UserService = class UserService {
121
133
  await this.users.update(userId, { name });
122
134
  }
123
135
  /**
124
- * Updates the user's image.
136
+ * Updates the user's avatar image.
125
137
  */
126
- async updateUserAwatar(userId, image) {
138
+ async updateUserAvatar(userId, image) {
127
139
  await this.users.update(userId, { image });
128
140
  }
141
+ /**
142
+ * @deprecated Use `updateUserAvatar` instead.
143
+ */
144
+ async updateUserAwatar(userId, image) {
145
+ return this.updateUserAvatar(userId, image);
146
+ }
129
147
  /**
130
148
  * Updates the user's email and marks it as verified.
131
149
  */
@@ -3,11 +3,6 @@ import { z } from "zod";
3
3
  * Validates the email format and length.
4
4
  */
5
5
  export declare function verifyEmailInput(email: string): boolean;
6
- /**
7
- * Checks if an email address is already in use.
8
- * @returns True if the email is available, false otherwise.
9
- */
10
- export declare function checkEmailAvailability(email: string): Promise<boolean>;
11
6
  export declare const loginSchema: z.ZodObject<{
12
7
  email: z.ZodString;
13
8
  password: z.ZodString;
@@ -1,19 +1,10 @@
1
1
  import { z } from "zod";
2
- import { User } from "../models";
3
2
  /**
4
3
  * Validates the email format and length.
5
4
  */
6
5
  export function verifyEmailInput(email) {
7
6
  return /^.+@.+\..+$/.test(email) && email.length < 256 && email.length > 0;
8
7
  }
9
- /**
10
- * Checks if an email address is already in use.
11
- * @returns True if the email is available, false otherwise.
12
- */
13
- export async function checkEmailAvailability(email) {
14
- const exists = await User.where("email", email).exists();
15
- return !exists;
16
- }
17
8
  // Auth validation schemas - CLEAN (No DB dependencies for client-side)
18
9
  export const loginSchema = z.object({
19
10
  email: z.string().email("Invalid email address"),
@@ -1,4 +1,4 @@
1
- export * from "./contracts";
2
- export * from "./verification.facade";
3
- export * from "./verification.repository";
4
- export * from "./verification.service";
1
+ export * from "./contracts.js";
2
+ export * from "./verification.facade.js";
3
+ export * from "./verification.repository.js";
4
+ export * from "./verification.service.js";
@@ -1,4 +1,4 @@
1
- export * from "./contracts";
2
- export * from "./verification.facade";
3
- export * from "./verification.repository";
4
- export * from "./verification.service";
1
+ export * from "./contracts.js";
2
+ export * from "./verification.facade.js";
3
+ export * from "./verification.repository.js";
4
+ export * from "./verification.service.js";
@@ -1,10 +1,10 @@
1
- import { type EmailVerificationRequestType } from "./verification.service";
1
+ import { type EmailVerificationRequestType } from "./verification.service.js";
2
2
  export type { EmailVerificationRequestType };
3
3
  export declare function initEmailVerification(): Promise<void>;
4
- export declare function getUserEmailVerificationRequest(userId: string, id: string): Promise<import("./contracts").EmailVerificationRecord | null>;
5
- export declare function createEmailVerificationRequest(userId: string, email: string): Promise<import("./contracts").EmailVerificationRecord>;
4
+ export declare function getUserEmailVerificationRequest(userId: string, id: string): Promise<import("./contracts.js").EmailVerificationRecord | null>;
5
+ export declare function createEmailVerificationRequest(userId: string, email: string): Promise<import("./contracts.js").EmailVerificationRecord>;
6
6
  export declare function deleteUserEmailVerificationRequest(userId: string): Promise<void>;
7
7
  export declare function sendVerificationEmail(email: string, code: string): Promise<void>;
8
8
  export declare function setEmailVerificationRequestCookie(request: EmailVerificationRequestType): Promise<void>;
9
9
  export declare function deleteEmailVerificationRequestCookie(): Promise<void>;
10
- export declare function getUserEmailVerificationRequestFromRequest(): Promise<import("./contracts").EmailVerificationRecord | null>;
10
+ export declare function getUserEmailVerificationRequestFromRequest(): Promise<import("./contracts.js").EmailVerificationRecord | null>;
@@ -1,8 +1,15 @@
1
1
  "use server";
2
2
  import { app } from "@veap/kernel";
3
- import { authContext, isAuthContextBound } from "../common/context";
4
- import { EmailVerificationService, } from "./verification.service";
3
+ import { authContext, isAuthContextBound } from "../common/context.js";
4
+ import { EmailVerificationService, } from "./verification.service.js";
5
5
  async function resolveVerificationService() {
6
+ const g = globalThis;
7
+ if (g.__VEAP_BOOTSTRAPPING_PROMISE__) {
8
+ try {
9
+ await g.__VEAP_BOOTSTRAPPING_PROMISE__;
10
+ }
11
+ catch { }
12
+ }
6
13
  if (isAuthContextBound()) {
7
14
  return authContext().emailVerification;
8
15
  }
@@ -1,4 +1,4 @@
1
- import type { CreateEmailVerificationRecord, EmailVerificationRecord, IEmailVerificationRepository } from "./contracts";
1
+ import type { CreateEmailVerificationRecord, EmailVerificationRecord, IEmailVerificationRepository } from "./contracts.js";
2
2
  /** `IEmailVerificationRepository` adapter backed by `EmailVerification`. */
3
3
  export declare class ActiveRecordEmailVerificationRepository implements IEmailVerificationRepository {
4
4
  create(record: CreateEmailVerificationRecord): Promise<EmailVerificationRecord>;
@@ -1,4 +1,4 @@
1
- import { EmailVerification } from "../models/EmailVerification";
1
+ import { EmailVerification } from "../models/EmailVerification.js";
2
2
  /** `IEmailVerificationRepository` adapter backed by `EmailVerification`. */
3
3
  export class ActiveRecordEmailVerificationRepository {
4
4
  async create(record) {
@@ -1,7 +1,7 @@
1
1
  import { type ICookieStore } from "@veap/kernel";
2
- import { type ITokenGenerator } from "../crypto/contracts";
3
- import { SessionService } from "../session/session.service";
4
- import { type EmailVerificationRecord, type IEmailVerificationRepository } from "./contracts";
2
+ import { type ITokenGenerator } from "../crypto/contracts.js";
3
+ import { SessionService } from "../session/session.service.js";
4
+ import { type EmailVerificationRecord, type IEmailVerificationRepository } from "./contracts.js";
5
5
  export type EmailVerificationRequestType = EmailVerificationRecord;
6
6
  export declare class EmailVerificationService {
7
7
  private readonly verifications;
@@ -13,10 +13,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
13
13
  import { COOKIE_STORE, Inject, Injectable, } from "@veap/kernel";
14
14
  import { sendVerifyEmail } from "@veap/mail";
15
15
  import { addMinutes } from "date-fns";
16
- import { registerSecurityRequirement } from "../common/logic";
17
- import { TOKEN_GENERATOR } from "../crypto/contracts";
18
- import { SessionService } from "../session/session.service";
19
- import { EMAIL_VERIFICATION_REPOSITORY, } from "./contracts";
16
+ import { getAuthRoutes } from "../common/context.js";
17
+ import { registerSecurityRequirement } from "../common/logic.js";
18
+ import { TOKEN_GENERATOR } from "../crypto/contracts.js";
19
+ import { SessionService } from "../session/session.service.js";
20
+ import { EMAIL_VERIFICATION_REPOSITORY, } from "./contracts.js";
20
21
  let EmailVerificationService = class EmailVerificationService {
21
22
  verifications;
22
23
  tokens;
@@ -34,9 +35,10 @@ let EmailVerificationService = class EmailVerificationService {
34
35
  async initEmailVerification() {
35
36
  registerSecurityRequirement(async (_session, user) => {
36
37
  if (!user.emailVerifiedAt) {
38
+ const routes = getAuthRoutes();
37
39
  return {
38
40
  satisfied: false,
39
- redirect: "/verify-email?unverified",
41
+ redirect: `${routes.verifyEmail}?unverified`,
40
42
  };
41
43
  }
42
44
  return { satisfied: true };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veap/auth",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Authentication, session management, RBAC, and crypto adapters for Veap",
5
5
  "bugs": "https://github.com/veapjs/veap-auth/issues",
6
6
  "repository": {
@@ -28,6 +28,10 @@
28
28
  "types": "./dist/actions/index.d.ts",
29
29
  "default": "./dist/actions/index.js"
30
30
  },
31
+ "./validation": {
32
+ "types": "./dist/validation/index.d.ts",
33
+ "default": "./dist/validation/index.js"
34
+ },
31
35
  "./models": {
32
36
  "types": "./dist/models.d.ts",
33
37
  "default": "./dist/models.js"
@@ -51,17 +55,16 @@
51
55
  "@oslojs/binary": "^1.0.0",
52
56
  "@oslojs/crypto": "^1.0.1",
53
57
  "@oslojs/encoding": "^1.1.0",
54
- "@veap/database": "^0.1.0",
55
- "@veap/kernel": "^0.1.0",
56
- "@veap/mail": "^0.1.0",
58
+ "@veap/database": "0.1.2",
59
+ "@veap/kernel": "0.1.2",
60
+ "@veap/mail": "0.1.2",
57
61
  "bcryptjs": "^3.0.3",
58
62
  "date-fns": "^4.4.0",
59
63
  "zod": "^3.24.2"
60
64
  },
61
65
  "peerDependencies": {
62
66
  "react": "^19",
63
- "react-dom": "^19",
64
- "swr": "^2.2.5"
67
+ "react-dom": "^19"
65
68
  },
66
69
  "peerDependenciesMeta": {
67
70
  "react": {
@@ -69,9 +72,6 @@
69
72
  },
70
73
  "react-dom": {
71
74
  "optional": true
72
- },
73
- "swr": {
74
- "optional": true
75
75
  }
76
76
  },
77
77
  "devDependencies": {