@spfn/auth 0.1.0-alpha.87 → 0.2.0-beta.1

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 (151) hide show
  1. package/README.md +1385 -1199
  2. package/dist/config.d.ts +405 -0
  3. package/dist/config.js +240 -0
  4. package/dist/config.js.map +1 -0
  5. package/dist/dto-81uR9gzF.d.ts +630 -0
  6. package/dist/errors.d.ts +196 -0
  7. package/dist/errors.js +173 -0
  8. package/dist/errors.js.map +1 -0
  9. package/dist/index.d.ts +273 -14
  10. package/dist/index.js +511 -6665
  11. package/dist/index.js.map +1 -1
  12. package/dist/nextjs/api.js +345 -0
  13. package/dist/nextjs/api.js.map +1 -0
  14. package/dist/{adapters/nextjs → nextjs}/server.d.ts +47 -65
  15. package/dist/nextjs/server.js +179 -0
  16. package/dist/nextjs/server.js.map +1 -0
  17. package/dist/server.d.ts +4328 -529
  18. package/dist/server.js +7841 -1247
  19. package/dist/server.js.map +1 -1
  20. package/migrations/{0000_familiar_firebrand.sql → 0000_mysterious_colossus.sql} +53 -23
  21. package/migrations/meta/0000_snapshot.json +281 -46
  22. package/migrations/meta/_journal.json +2 -2
  23. package/package.json +33 -33
  24. package/dist/adapters/nextjs/api.d.ts +0 -446
  25. package/dist/adapters/nextjs/api.js +0 -3279
  26. package/dist/adapters/nextjs/api.js.map +0 -1
  27. package/dist/adapters/nextjs/server.js +0 -3645
  28. package/dist/adapters/nextjs/server.js.map +0 -1
  29. package/dist/lib/api/auth-codes-verify.d.ts +0 -37
  30. package/dist/lib/api/auth-codes-verify.js +0 -2949
  31. package/dist/lib/api/auth-codes-verify.js.map +0 -1
  32. package/dist/lib/api/auth-codes.d.ts +0 -37
  33. package/dist/lib/api/auth-codes.js +0 -2949
  34. package/dist/lib/api/auth-codes.js.map +0 -1
  35. package/dist/lib/api/auth-exists.d.ts +0 -38
  36. package/dist/lib/api/auth-exists.js +0 -2949
  37. package/dist/lib/api/auth-exists.js.map +0 -1
  38. package/dist/lib/api/auth-invitations-accept.d.ts +0 -38
  39. package/dist/lib/api/auth-invitations-accept.js +0 -2883
  40. package/dist/lib/api/auth-invitations-accept.js.map +0 -1
  41. package/dist/lib/api/auth-invitations-cancel.d.ts +0 -37
  42. package/dist/lib/api/auth-invitations-cancel.js +0 -2883
  43. package/dist/lib/api/auth-invitations-cancel.js.map +0 -1
  44. package/dist/lib/api/auth-invitations-delete.d.ts +0 -36
  45. package/dist/lib/api/auth-invitations-delete.js +0 -2883
  46. package/dist/lib/api/auth-invitations-delete.js.map +0 -1
  47. package/dist/lib/api/auth-invitations-resend.d.ts +0 -37
  48. package/dist/lib/api/auth-invitations-resend.js +0 -2883
  49. package/dist/lib/api/auth-invitations-resend.js.map +0 -1
  50. package/dist/lib/api/auth-invitations.d.ts +0 -109
  51. package/dist/lib/api/auth-invitations.js +0 -2887
  52. package/dist/lib/api/auth-invitations.js.map +0 -1
  53. package/dist/lib/api/auth-keys-rotate.d.ts +0 -37
  54. package/dist/lib/api/auth-keys-rotate.js +0 -2949
  55. package/dist/lib/api/auth-keys-rotate.js.map +0 -1
  56. package/dist/lib/api/auth-login.d.ts +0 -39
  57. package/dist/lib/api/auth-login.js +0 -2949
  58. package/dist/lib/api/auth-login.js.map +0 -1
  59. package/dist/lib/api/auth-logout.d.ts +0 -36
  60. package/dist/lib/api/auth-logout.js +0 -2949
  61. package/dist/lib/api/auth-logout.js.map +0 -1
  62. package/dist/lib/api/auth-me.d.ts +0 -50
  63. package/dist/lib/api/auth-me.js +0 -2949
  64. package/dist/lib/api/auth-me.js.map +0 -1
  65. package/dist/lib/api/auth-password.d.ts +0 -36
  66. package/dist/lib/api/auth-password.js +0 -2949
  67. package/dist/lib/api/auth-password.js.map +0 -1
  68. package/dist/lib/api/auth-register.d.ts +0 -38
  69. package/dist/lib/api/auth-register.js +0 -2949
  70. package/dist/lib/api/auth-register.js.map +0 -1
  71. package/dist/lib/api/index.d.ts +0 -356
  72. package/dist/lib/api/index.js +0 -3261
  73. package/dist/lib/api/index.js.map +0 -1
  74. package/dist/lib/config.d.ts +0 -70
  75. package/dist/lib/config.js +0 -64
  76. package/dist/lib/config.js.map +0 -1
  77. package/dist/lib/contracts/auth.d.ts +0 -302
  78. package/dist/lib/contracts/auth.js +0 -2951
  79. package/dist/lib/contracts/auth.js.map +0 -1
  80. package/dist/lib/contracts/index.d.ts +0 -3
  81. package/dist/lib/contracts/index.js +0 -3190
  82. package/dist/lib/contracts/index.js.map +0 -1
  83. package/dist/lib/contracts/invitation.d.ts +0 -243
  84. package/dist/lib/contracts/invitation.js +0 -2883
  85. package/dist/lib/contracts/invitation.js.map +0 -1
  86. package/dist/lib/crypto.d.ts +0 -76
  87. package/dist/lib/crypto.js +0 -127
  88. package/dist/lib/crypto.js.map +0 -1
  89. package/dist/lib/index.d.ts +0 -4
  90. package/dist/lib/index.js +0 -313
  91. package/dist/lib/index.js.map +0 -1
  92. package/dist/lib/session.d.ts +0 -68
  93. package/dist/lib/session.js +0 -126
  94. package/dist/lib/session.js.map +0 -1
  95. package/dist/lib/types/api.d.ts +0 -45
  96. package/dist/lib/types/api.js +0 -1
  97. package/dist/lib/types/api.js.map +0 -1
  98. package/dist/lib/types/index.d.ts +0 -3
  99. package/dist/lib/types/index.js +0 -2647
  100. package/dist/lib/types/index.js.map +0 -1
  101. package/dist/lib/types/schemas.d.ts +0 -45
  102. package/dist/lib/types/schemas.js +0 -2647
  103. package/dist/lib/types/schemas.js.map +0 -1
  104. package/dist/lib.js +0 -1
  105. package/dist/lib.js.map +0 -1
  106. package/dist/plugin.d.ts +0 -12
  107. package/dist/plugin.js +0 -9083
  108. package/dist/plugin.js.map +0 -1
  109. package/dist/server/entities/index.d.ts +0 -11
  110. package/dist/server/entities/index.js +0 -395
  111. package/dist/server/entities/index.js.map +0 -1
  112. package/dist/server/entities/invitations.d.ts +0 -241
  113. package/dist/server/entities/invitations.js +0 -184
  114. package/dist/server/entities/invitations.js.map +0 -1
  115. package/dist/server/entities/permissions.d.ts +0 -196
  116. package/dist/server/entities/permissions.js +0 -49
  117. package/dist/server/entities/permissions.js.map +0 -1
  118. package/dist/server/entities/role-permissions.d.ts +0 -107
  119. package/dist/server/entities/role-permissions.js +0 -115
  120. package/dist/server/entities/role-permissions.js.map +0 -1
  121. package/dist/server/entities/roles.d.ts +0 -196
  122. package/dist/server/entities/roles.js +0 -50
  123. package/dist/server/entities/roles.js.map +0 -1
  124. package/dist/server/entities/schema.d.ts +0 -14
  125. package/dist/server/entities/schema.js +0 -7
  126. package/dist/server/entities/schema.js.map +0 -1
  127. package/dist/server/entities/user-permissions.d.ts +0 -163
  128. package/dist/server/entities/user-permissions.js +0 -193
  129. package/dist/server/entities/user-permissions.js.map +0 -1
  130. package/dist/server/entities/user-public-keys.d.ts +0 -227
  131. package/dist/server/entities/user-public-keys.js +0 -156
  132. package/dist/server/entities/user-public-keys.js.map +0 -1
  133. package/dist/server/entities/user-social-accounts.d.ts +0 -189
  134. package/dist/server/entities/user-social-accounts.js +0 -149
  135. package/dist/server/entities/user-social-accounts.js.map +0 -1
  136. package/dist/server/entities/users.d.ts +0 -235
  137. package/dist/server/entities/users.js +0 -117
  138. package/dist/server/entities/users.js.map +0 -1
  139. package/dist/server/entities/verification-codes.d.ts +0 -191
  140. package/dist/server/entities/verification-codes.js +0 -49
  141. package/dist/server/entities/verification-codes.js.map +0 -1
  142. package/dist/server/routes/auth/index.d.ts +0 -10
  143. package/dist/server/routes/auth/index.js +0 -4460
  144. package/dist/server/routes/auth/index.js.map +0 -1
  145. package/dist/server/routes/index.d.ts +0 -6
  146. package/dist/server/routes/index.js +0 -6584
  147. package/dist/server/routes/index.js.map +0 -1
  148. package/dist/server/routes/invitations/index.d.ts +0 -10
  149. package/dist/server/routes/invitations/index.js +0 -4395
  150. package/dist/server/routes/invitations/index.js.map +0 -1
  151. /package/dist/{lib.d.ts → nextjs/api.d.ts} +0 -0
@@ -1,235 +0,0 @@
1
- import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
2
-
3
- /**
4
- * @spfn/auth - Users Entity
5
- *
6
- * Main user table supporting multiple authentication methods
7
- *
8
- * Features:
9
- * - Email or phone-based registration
10
- * - Password authentication (bcrypt)
11
- * - OAuth support (nullable passwordHash)
12
- * - Role-based access control (RBAC)
13
- * - Account status management
14
- * - Email/phone verification
15
- */
16
- declare const users: drizzle_orm_pg_core.PgTableWithColumns<{
17
- name: "users";
18
- schema: string;
19
- columns: {
20
- createdAt: drizzle_orm_pg_core.PgColumn<{
21
- name: "created_at";
22
- tableName: "users";
23
- dataType: "date";
24
- columnType: "PgTimestamp";
25
- data: Date;
26
- driverParam: string;
27
- notNull: true;
28
- hasDefault: true;
29
- isPrimaryKey: false;
30
- isAutoincrement: false;
31
- hasRuntimeDefault: false;
32
- enumValues: undefined;
33
- baseColumn: never;
34
- identity: undefined;
35
- generated: undefined;
36
- }, {}, {}>;
37
- updatedAt: drizzle_orm_pg_core.PgColumn<{
38
- name: "updated_at";
39
- tableName: "users";
40
- dataType: "date";
41
- columnType: "PgTimestamp";
42
- data: Date;
43
- driverParam: string;
44
- notNull: true;
45
- hasDefault: true;
46
- isPrimaryKey: false;
47
- isAutoincrement: false;
48
- hasRuntimeDefault: false;
49
- enumValues: undefined;
50
- baseColumn: never;
51
- identity: undefined;
52
- generated: undefined;
53
- }, {}, {}>;
54
- id: drizzle_orm_pg_core.PgColumn<{
55
- name: "id";
56
- tableName: "users";
57
- dataType: "number";
58
- columnType: "PgBigSerial53";
59
- data: number;
60
- driverParam: number;
61
- notNull: true;
62
- hasDefault: true;
63
- isPrimaryKey: true;
64
- isAutoincrement: false;
65
- hasRuntimeDefault: false;
66
- enumValues: undefined;
67
- baseColumn: never;
68
- identity: undefined;
69
- generated: undefined;
70
- }, {}, {}>;
71
- email: drizzle_orm_pg_core.PgColumn<{
72
- name: "email";
73
- tableName: "users";
74
- dataType: "string";
75
- columnType: "PgText";
76
- data: string;
77
- driverParam: string;
78
- notNull: false;
79
- hasDefault: false;
80
- isPrimaryKey: false;
81
- isAutoincrement: false;
82
- hasRuntimeDefault: false;
83
- enumValues: [string, ...string[]];
84
- baseColumn: never;
85
- identity: undefined;
86
- generated: undefined;
87
- }, {}, {}>;
88
- phone: drizzle_orm_pg_core.PgColumn<{
89
- name: "phone";
90
- tableName: "users";
91
- dataType: "string";
92
- columnType: "PgText";
93
- data: string;
94
- driverParam: string;
95
- notNull: false;
96
- hasDefault: false;
97
- isPrimaryKey: false;
98
- isAutoincrement: false;
99
- hasRuntimeDefault: false;
100
- enumValues: [string, ...string[]];
101
- baseColumn: never;
102
- identity: undefined;
103
- generated: undefined;
104
- }, {}, {}>;
105
- passwordHash: drizzle_orm_pg_core.PgColumn<{
106
- name: "password_hash";
107
- tableName: "users";
108
- dataType: "string";
109
- columnType: "PgText";
110
- data: string;
111
- driverParam: string;
112
- notNull: false;
113
- hasDefault: false;
114
- isPrimaryKey: false;
115
- isAutoincrement: false;
116
- hasRuntimeDefault: false;
117
- enumValues: [string, ...string[]];
118
- baseColumn: never;
119
- identity: undefined;
120
- generated: undefined;
121
- }, {}, {}>;
122
- passwordChangeRequired: drizzle_orm_pg_core.PgColumn<{
123
- name: "password_change_required";
124
- tableName: "users";
125
- dataType: "boolean";
126
- columnType: "PgBoolean";
127
- data: boolean;
128
- driverParam: boolean;
129
- notNull: true;
130
- hasDefault: true;
131
- isPrimaryKey: false;
132
- isAutoincrement: false;
133
- hasRuntimeDefault: false;
134
- enumValues: undefined;
135
- baseColumn: never;
136
- identity: undefined;
137
- generated: undefined;
138
- }, {}, {}>;
139
- roleId: drizzle_orm_pg_core.PgColumn<{
140
- name: "role_id";
141
- tableName: "users";
142
- dataType: "number";
143
- columnType: "PgBigInt53";
144
- data: number;
145
- driverParam: string | number;
146
- notNull: true;
147
- hasDefault: false;
148
- isPrimaryKey: false;
149
- isAutoincrement: false;
150
- hasRuntimeDefault: false;
151
- enumValues: undefined;
152
- baseColumn: never;
153
- identity: undefined;
154
- generated: undefined;
155
- }, {}, {}>;
156
- status: drizzle_orm_pg_core.PgColumn<{
157
- name: "status";
158
- tableName: "users";
159
- dataType: "string";
160
- columnType: "PgText";
161
- data: "active" | "inactive" | "suspended";
162
- driverParam: string;
163
- notNull: true;
164
- hasDefault: true;
165
- isPrimaryKey: false;
166
- isAutoincrement: false;
167
- hasRuntimeDefault: false;
168
- enumValues: ["active", "inactive", "suspended"];
169
- baseColumn: never;
170
- identity: undefined;
171
- generated: undefined;
172
- }, {}, {}>;
173
- emailVerifiedAt: drizzle_orm_pg_core.PgColumn<{
174
- name: "email_verified_at";
175
- tableName: "users";
176
- dataType: "date";
177
- columnType: "PgTimestamp";
178
- data: Date;
179
- driverParam: string;
180
- notNull: false;
181
- hasDefault: false;
182
- isPrimaryKey: false;
183
- isAutoincrement: false;
184
- hasRuntimeDefault: false;
185
- enumValues: undefined;
186
- baseColumn: never;
187
- identity: undefined;
188
- generated: undefined;
189
- }, {}, {}>;
190
- phoneVerifiedAt: drizzle_orm_pg_core.PgColumn<{
191
- name: "phone_verified_at";
192
- tableName: "users";
193
- dataType: "date";
194
- columnType: "PgTimestamp";
195
- data: Date;
196
- driverParam: string;
197
- notNull: false;
198
- hasDefault: false;
199
- isPrimaryKey: false;
200
- isAutoincrement: false;
201
- hasRuntimeDefault: false;
202
- enumValues: undefined;
203
- baseColumn: never;
204
- identity: undefined;
205
- generated: undefined;
206
- }, {}, {}>;
207
- lastLoginAt: drizzle_orm_pg_core.PgColumn<{
208
- name: "last_login_at";
209
- tableName: "users";
210
- dataType: "date";
211
- columnType: "PgTimestamp";
212
- data: Date;
213
- driverParam: string;
214
- notNull: false;
215
- hasDefault: false;
216
- isPrimaryKey: false;
217
- isAutoincrement: false;
218
- hasRuntimeDefault: false;
219
- enumValues: undefined;
220
- baseColumn: never;
221
- identity: undefined;
222
- generated: undefined;
223
- }, {}, {}>;
224
- };
225
- dialect: "pg";
226
- }>;
227
- type User = typeof users.$inferSelect;
228
- type NewUser = typeof users.$inferInsert;
229
- type UserStatus = 'active' | 'inactive' | 'suspended';
230
- type UserWithVerification = User & {
231
- isEmailVerified: boolean;
232
- isPhoneVerified: boolean;
233
- };
234
-
235
- export { type NewUser, type User, type UserStatus, type UserWithVerification, users };
@@ -1,117 +0,0 @@
1
- // src/server/entities/users.ts
2
- import { text as text2, timestamp, check, boolean as boolean2, bigint, index as index2 } from "drizzle-orm/pg-core";
3
- import { id as id2, timestamps as timestamps2 } from "@spfn/core/db";
4
- import { sql } from "drizzle-orm";
5
-
6
- // src/server/entities/roles.ts
7
- import { text, boolean, integer, index } from "drizzle-orm/pg-core";
8
- import { id, timestamps } from "@spfn/core/db";
9
-
10
- // src/server/entities/schema.ts
11
- import { createFunctionSchema } from "@spfn/core/db";
12
- var authSchema = createFunctionSchema("@spfn/auth");
13
-
14
- // src/server/entities/roles.ts
15
- var roles = authSchema.table(
16
- "roles",
17
- {
18
- // Primary key
19
- id: id(),
20
- // Role identifier (used in code, e.g., 'admin', 'editor')
21
- // Must be unique, lowercase, kebab-case recommended
22
- name: text("name").notNull().unique(),
23
- // Display name for UI (e.g., 'Administrator', 'Content Editor')
24
- displayName: text("display_name").notNull(),
25
- // Role description
26
- description: text("description"),
27
- // Built-in role flag
28
- // true: Core package roles (user, admin, superadmin) - cannot be deleted
29
- // false: Custom or preset roles - can be deleted
30
- isBuiltin: boolean("is_builtin").notNull().default(false),
31
- // System role flag
32
- // true: Defined in code (builtin or preset) - deletion restricted
33
- // false: Runtime created custom role - fully manageable
34
- isSystem: boolean("is_system").notNull().default(false),
35
- // Active status
36
- // false: Deactivated role (users cannot be assigned)
37
- isActive: boolean("is_active").notNull().default(true),
38
- // Priority level (higher = more privileged)
39
- // superadmin: 100, admin: 80, user: 10
40
- // Used for role hierarchy and conflict resolution
41
- priority: integer("priority").notNull().default(10),
42
- ...timestamps()
43
- },
44
- (table) => [
45
- index("roles_name_idx").on(table.name),
46
- index("roles_is_system_idx").on(table.isSystem),
47
- index("roles_is_active_idx").on(table.isActive),
48
- index("roles_is_builtin_idx").on(table.isBuiltin),
49
- index("roles_priority_idx").on(table.priority)
50
- ]
51
- );
52
-
53
- // src/server/entities/users.ts
54
- var users = authSchema.table(
55
- "users",
56
- {
57
- // Identity
58
- id: id2(),
59
- // Email address (unique identifier)
60
- // Used for: login, password reset, notifications
61
- email: text2("email").unique(),
62
- // Phone number in E.164 international format
63
- // Format: +[country code][number] (e.g., +821012345678)
64
- // Used for: SMS login, 2FA, notifications
65
- phone: text2("phone").unique(),
66
- // Authentication
67
- // Bcrypt password hash ($2b$10$[salt][hash], 60 chars)
68
- // Nullable to support OAuth-only accounts
69
- passwordHash: text2("password_hash"),
70
- // Force password change on next login
71
- // Use cases: initial setup, security breach, policy violation
72
- passwordChangeRequired: boolean2("password_change_required").notNull().default(false),
73
- // Authorization (Role-Based Access Control)
74
- // Foreign key to roles table
75
- // References built-in roles: user (default), admin, superadmin
76
- // Can also reference custom roles created at runtime
77
- roleId: bigint("role_id", { mode: "number" }).references(() => roles.id).notNull(),
78
- // Account status
79
- // - active: Normal operation (default)
80
- // - inactive: Deactivated (user request, dormant)
81
- // - suspended: Locked (security incident, ToS violation)
82
- status: text2(
83
- "status",
84
- {
85
- enum: ["active", "inactive", "suspended"]
86
- }
87
- ).notNull().default("active"),
88
- // Verification timestamps
89
- // null = unverified, timestamp = verified at this time
90
- // Email verification (via verification code or magic link)
91
- emailVerifiedAt: timestamp("email_verified_at", { withTimezone: true }),
92
- // Phone verification (via SMS OTP)
93
- phoneVerifiedAt: timestamp("phone_verified_at", { withTimezone: true }),
94
- // Metadata
95
- // Last successful login timestamp
96
- // Used for: security auditing, dormant account detection
97
- lastLoginAt: timestamp("last_login_at", { withTimezone: true }),
98
- ...timestamps2()
99
- },
100
- (table) => [
101
- // Database constraints
102
- // Ensure at least one identifier exists (email OR phone)
103
- check(
104
- "email_or_phone_check",
105
- sql`${table.email} IS NOT NULL OR ${table.phone} IS NOT NULL`
106
- ),
107
- // Indexes for query optimization
108
- index2("users_email_idx").on(table.email),
109
- index2("users_phone_idx").on(table.phone),
110
- index2("users_status_idx").on(table.status),
111
- index2("users_role_id_idx").on(table.roleId)
112
- ]
113
- );
114
- export {
115
- users
116
- };
117
- //# sourceMappingURL=users.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/server/entities/users.ts","../../../src/server/entities/roles.ts","../../../src/server/entities/schema.ts"],"sourcesContent":["/**\n * @spfn/auth - Users Entity\n *\n * Main user table supporting multiple authentication methods\n *\n * Features:\n * - Email or phone-based registration\n * - Password authentication (bcrypt)\n * - OAuth support (nullable passwordHash)\n * - Role-based access control (RBAC)\n * - Account status management\n * - Email/phone verification\n */\n\nimport { text, timestamp, check, boolean, bigint, index } from 'drizzle-orm/pg-core';\nimport { id, timestamps } from '@spfn/core/db';\nimport { sql } from 'drizzle-orm';\nimport { roles } from './roles';\nimport { authSchema } from './schema';\n\nexport const users = authSchema.table('users',\n {\n // Identity\n id: id(),\n\n // Email address (unique identifier)\n // Used for: login, password reset, notifications\n email: text('email').unique(),\n\n // Phone number in E.164 international format\n // Format: +[country code][number] (e.g., +821012345678)\n // Used for: SMS login, 2FA, notifications\n phone: text('phone').unique(),\n\n // Authentication\n // Bcrypt password hash ($2b$10$[salt][hash], 60 chars)\n // Nullable to support OAuth-only accounts\n passwordHash: text('password_hash'),\n\n // Force password change on next login\n // Use cases: initial setup, security breach, policy violation\n passwordChangeRequired: boolean('password_change_required').notNull().default(false),\n\n // Authorization (Role-Based Access Control)\n // Foreign key to roles table\n // References built-in roles: user (default), admin, superadmin\n // Can also reference custom roles created at runtime\n roleId: bigint('role_id', { mode: 'number' })\n .references(() => roles.id)\n .notNull(),\n\n // Account status\n // - active: Normal operation (default)\n // - inactive: Deactivated (user request, dormant)\n // - suspended: Locked (security incident, ToS violation)\n status: text(\n 'status',\n {\n enum: ['active', 'inactive', 'suspended']\n }\n ).notNull().default('active'),\n\n // Verification timestamps\n // null = unverified, timestamp = verified at this time\n // Email verification (via verification code or magic link)\n emailVerifiedAt: timestamp('email_verified_at', { withTimezone: true }),\n\n // Phone verification (via SMS OTP)\n phoneVerifiedAt: timestamp('phone_verified_at', { withTimezone: true }),\n\n // Metadata\n // Last successful login timestamp\n // Used for: security auditing, dormant account detection\n lastLoginAt: timestamp('last_login_at', { withTimezone: true }),\n\n ...timestamps(),\n },\n (table) => [\n // Database constraints\n // Ensure at least one identifier exists (email OR phone)\n check(\n 'email_or_phone_check',\n sql`${table.email} IS NOT NULL OR ${table.phone} IS NOT NULL`\n ),\n\n // Indexes for query optimization\n index('users_email_idx').on(table.email),\n index('users_phone_idx').on(table.phone),\n index('users_status_idx').on(table.status),\n index('users_role_id_idx').on(table.roleId),\n ]\n);\n\n// Type exports\nexport type User = typeof users.$inferSelect;\nexport type NewUser = typeof users.$inferInsert;\nexport type UserStatus = 'active' | 'inactive' | 'suspended';\n\n// Helper type with computed verification status\nexport type UserWithVerification = User &\n{\n isEmailVerified: boolean;\n isPhoneVerified: boolean;\n};","/**\n * @spfn/auth - Roles Entity\n *\n * Role-based access control (RBAC) roles table\n *\n * Features:\n * - Built-in roles (user, admin, superadmin) - cannot be deleted\n * - System roles (preset roles) - can be deactivated\n * - Custom roles (runtime created) - fully manageable\n * - Priority-based hierarchy\n */\n\nimport { text, boolean, integer, index } from 'drizzle-orm/pg-core';\nimport { id, timestamps } from '@spfn/core/db';\nimport { authSchema } from './schema';\n\nexport const roles = authSchema.table('roles',\n {\n // Primary key\n id: id(),\n\n // Role identifier (used in code, e.g., 'admin', 'editor')\n // Must be unique, lowercase, kebab-case recommended\n name: text('name').notNull().unique(),\n\n // Display name for UI (e.g., 'Administrator', 'Content Editor')\n displayName: text('display_name').notNull(),\n\n // Role description\n description: text('description'),\n\n // Built-in role flag\n // true: Core package roles (user, admin, superadmin) - cannot be deleted\n // false: Custom or preset roles - can be deleted\n isBuiltin: boolean('is_builtin').notNull().default(false),\n\n // System role flag\n // true: Defined in code (builtin or preset) - deletion restricted\n // false: Runtime created custom role - fully manageable\n isSystem: boolean('is_system').notNull().default(false),\n\n // Active status\n // false: Deactivated role (users cannot be assigned)\n isActive: boolean('is_active').notNull().default(true),\n\n // Priority level (higher = more privileged)\n // superadmin: 100, admin: 80, user: 10\n // Used for role hierarchy and conflict resolution\n priority: integer('priority').notNull().default(10),\n\n ...timestamps(),\n },\n (table) => [\n index('roles_name_idx').on(table.name),\n index('roles_is_system_idx').on(table.isSystem),\n index('roles_is_active_idx').on(table.isActive),\n index('roles_is_builtin_idx').on(table.isBuiltin),\n index('roles_priority_idx').on(table.priority),\n ]\n);\n\n// Type exports\nexport type RoleEntity = typeof roles.$inferSelect;\nexport type NewRoleEntity = typeof roles.$inferInsert;\n\n// Legacy alias for backward compatibility\nexport type Role = RoleEntity;\nexport type NewRole = NewRoleEntity;","/**\n * @spfn/auth - Database Schema Definition\n *\n * Defines the 'spfn_auth' PostgreSQL schema for all auth-related tables\n */\n\nimport { createFunctionSchema } from '@spfn/core/db';\n\n/**\n * Auth schema for all authentication and authorization tables\n * Tables: users, roles, permissions, user_invitations, etc.\n */\nexport const authSchema = createFunctionSchema('@spfn/auth');"],"mappings":";AAcA,SAAS,QAAAA,OAAM,WAAW,OAAO,WAAAC,UAAS,QAAQ,SAAAC,cAAa;AAC/D,SAAS,MAAAC,KAAI,cAAAC,mBAAkB;AAC/B,SAAS,WAAW;;;ACJpB,SAAS,MAAM,SAAS,SAAS,aAAa;AAC9C,SAAS,IAAI,kBAAkB;;;ACP/B,SAAS,4BAA4B;AAM9B,IAAM,aAAa,qBAAqB,YAAY;;;ADIpD,IAAM,QAAQ,WAAW;AAAA,EAAM;AAAA,EAClC;AAAA;AAAA,IAEI,IAAI,GAAG;AAAA;AAAA;AAAA,IAIP,MAAM,KAAK,MAAM,EAAE,QAAQ,EAAE,OAAO;AAAA;AAAA,IAGpC,aAAa,KAAK,cAAc,EAAE,QAAQ;AAAA;AAAA,IAG1C,aAAa,KAAK,aAAa;AAAA;AAAA;AAAA;AAAA,IAK/B,WAAW,QAAQ,YAAY,EAAE,QAAQ,EAAE,QAAQ,KAAK;AAAA;AAAA;AAAA;AAAA,IAKxD,UAAU,QAAQ,WAAW,EAAE,QAAQ,EAAE,QAAQ,KAAK;AAAA;AAAA;AAAA,IAItD,UAAU,QAAQ,WAAW,EAAE,QAAQ,EAAE,QAAQ,IAAI;AAAA;AAAA;AAAA;AAAA,IAKrD,UAAU,QAAQ,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE;AAAA,IAElD,GAAG,WAAW;AAAA,EAClB;AAAA,EACA,CAAC,UAAU;AAAA,IACP,MAAM,gBAAgB,EAAE,GAAG,MAAM,IAAI;AAAA,IACrC,MAAM,qBAAqB,EAAE,GAAG,MAAM,QAAQ;AAAA,IAC9C,MAAM,qBAAqB,EAAE,GAAG,MAAM,QAAQ;AAAA,IAC9C,MAAM,sBAAsB,EAAE,GAAG,MAAM,SAAS;AAAA,IAChD,MAAM,oBAAoB,EAAE,GAAG,MAAM,QAAQ;AAAA,EACjD;AACJ;;;ADvCO,IAAM,QAAQ,WAAW;AAAA,EAAM;AAAA,EAClC;AAAA;AAAA,IAEI,IAAIC,IAAG;AAAA;AAAA;AAAA,IAIP,OAAOC,MAAK,OAAO,EAAE,OAAO;AAAA;AAAA;AAAA;AAAA,IAK5B,OAAOA,MAAK,OAAO,EAAE,OAAO;AAAA;AAAA;AAAA;AAAA,IAK5B,cAAcA,MAAK,eAAe;AAAA;AAAA;AAAA,IAIlC,wBAAwBC,SAAQ,0BAA0B,EAAE,QAAQ,EAAE,QAAQ,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA,IAMnF,QAAQ,OAAO,WAAW,EAAE,MAAM,SAAS,CAAC,EACvC,WAAW,MAAM,MAAM,EAAE,EACzB,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA,IAMb,QAAQD;AAAA,MACJ;AAAA,MACA;AAAA,QACI,MAAM,CAAC,UAAU,YAAY,WAAW;AAAA,MAC5C;AAAA,IACJ,EAAE,QAAQ,EAAE,QAAQ,QAAQ;AAAA;AAAA;AAAA;AAAA,IAK5B,iBAAiB,UAAU,qBAAqB,EAAE,cAAc,KAAK,CAAC;AAAA;AAAA,IAGtE,iBAAiB,UAAU,qBAAqB,EAAE,cAAc,KAAK,CAAC;AAAA;AAAA;AAAA;AAAA,IAKtE,aAAa,UAAU,iBAAiB,EAAE,cAAc,KAAK,CAAC;AAAA,IAE9D,GAAGE,YAAW;AAAA,EAClB;AAAA,EACA,CAAC,UAAU;AAAA;AAAA;AAAA,IAGP;AAAA,MACI;AAAA,MACA,MAAM,MAAM,KAAK,mBAAmB,MAAM,KAAK;AAAA,IACnD;AAAA;AAAA,IAGAC,OAAM,iBAAiB,EAAE,GAAG,MAAM,KAAK;AAAA,IACvCA,OAAM,iBAAiB,EAAE,GAAG,MAAM,KAAK;AAAA,IACvCA,OAAM,kBAAkB,EAAE,GAAG,MAAM,MAAM;AAAA,IACzCA,OAAM,mBAAmB,EAAE,GAAG,MAAM,MAAM;AAAA,EAC9C;AACJ;","names":["text","boolean","index","id","timestamps","id","text","boolean","timestamps","index"]}
@@ -1,191 +0,0 @@
1
- import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
2
-
3
- /**
4
- * @spfn/auth - Verification Codes Entity
5
- *
6
- * Stores verification codes for email and phone verification
7
- * Codes expire after a configurable time period
8
- */
9
- declare const verificationCodes: drizzle_orm_pg_core.PgTableWithColumns<{
10
- name: "verification_codes";
11
- schema: string;
12
- columns: {
13
- createdAt: drizzle_orm_pg_core.PgColumn<{
14
- name: "created_at";
15
- tableName: "verification_codes";
16
- dataType: "date";
17
- columnType: "PgTimestamp";
18
- data: Date;
19
- driverParam: string;
20
- notNull: true;
21
- hasDefault: true;
22
- isPrimaryKey: false;
23
- isAutoincrement: false;
24
- hasRuntimeDefault: false;
25
- enumValues: undefined;
26
- baseColumn: never;
27
- identity: undefined;
28
- generated: undefined;
29
- }, {}, {}>;
30
- updatedAt: drizzle_orm_pg_core.PgColumn<{
31
- name: "updated_at";
32
- tableName: "verification_codes";
33
- dataType: "date";
34
- columnType: "PgTimestamp";
35
- data: Date;
36
- driverParam: string;
37
- notNull: true;
38
- hasDefault: true;
39
- isPrimaryKey: false;
40
- isAutoincrement: false;
41
- hasRuntimeDefault: false;
42
- enumValues: undefined;
43
- baseColumn: never;
44
- identity: undefined;
45
- generated: undefined;
46
- }, {}, {}>;
47
- id: drizzle_orm_pg_core.PgColumn<{
48
- name: "id";
49
- tableName: "verification_codes";
50
- dataType: "number";
51
- columnType: "PgBigSerial53";
52
- data: number;
53
- driverParam: number;
54
- notNull: true;
55
- hasDefault: true;
56
- isPrimaryKey: true;
57
- isAutoincrement: false;
58
- hasRuntimeDefault: false;
59
- enumValues: undefined;
60
- baseColumn: never;
61
- identity: undefined;
62
- generated: undefined;
63
- }, {}, {}>;
64
- target: drizzle_orm_pg_core.PgColumn<{
65
- name: "target";
66
- tableName: "verification_codes";
67
- dataType: "string";
68
- columnType: "PgText";
69
- data: string;
70
- driverParam: string;
71
- notNull: true;
72
- hasDefault: false;
73
- isPrimaryKey: false;
74
- isAutoincrement: false;
75
- hasRuntimeDefault: false;
76
- enumValues: [string, ...string[]];
77
- baseColumn: never;
78
- identity: undefined;
79
- generated: undefined;
80
- }, {}, {}>;
81
- targetType: drizzle_orm_pg_core.PgColumn<{
82
- name: "target_type";
83
- tableName: "verification_codes";
84
- dataType: "string";
85
- columnType: "PgText";
86
- data: "email" | "phone";
87
- driverParam: string;
88
- notNull: true;
89
- hasDefault: false;
90
- isPrimaryKey: false;
91
- isAutoincrement: false;
92
- hasRuntimeDefault: false;
93
- enumValues: ["email", "phone"];
94
- baseColumn: never;
95
- identity: undefined;
96
- generated: undefined;
97
- }, {}, {}>;
98
- code: drizzle_orm_pg_core.PgColumn<{
99
- name: "code";
100
- tableName: "verification_codes";
101
- dataType: "string";
102
- columnType: "PgText";
103
- data: string;
104
- driverParam: string;
105
- notNull: true;
106
- hasDefault: false;
107
- isPrimaryKey: false;
108
- isAutoincrement: false;
109
- hasRuntimeDefault: false;
110
- enumValues: [string, ...string[]];
111
- baseColumn: never;
112
- identity: undefined;
113
- generated: undefined;
114
- }, {}, {}>;
115
- purpose: drizzle_orm_pg_core.PgColumn<{
116
- name: "purpose";
117
- tableName: "verification_codes";
118
- dataType: "string";
119
- columnType: "PgText";
120
- data: "registration" | "login" | "password_reset" | "email_change" | "phone_change";
121
- driverParam: string;
122
- notNull: true;
123
- hasDefault: false;
124
- isPrimaryKey: false;
125
- isAutoincrement: false;
126
- hasRuntimeDefault: false;
127
- enumValues: ["registration", "login", "password_reset", "email_change", "phone_change"];
128
- baseColumn: never;
129
- identity: undefined;
130
- generated: undefined;
131
- }, {}, {}>;
132
- expiresAt: drizzle_orm_pg_core.PgColumn<{
133
- name: "expires_at";
134
- tableName: "verification_codes";
135
- dataType: "date";
136
- columnType: "PgTimestamp";
137
- data: Date;
138
- driverParam: string;
139
- notNull: true;
140
- hasDefault: false;
141
- isPrimaryKey: false;
142
- isAutoincrement: false;
143
- hasRuntimeDefault: false;
144
- enumValues: undefined;
145
- baseColumn: never;
146
- identity: undefined;
147
- generated: undefined;
148
- }, {}, {}>;
149
- usedAt: drizzle_orm_pg_core.PgColumn<{
150
- name: "used_at";
151
- tableName: "verification_codes";
152
- dataType: "date";
153
- columnType: "PgTimestamp";
154
- data: Date;
155
- driverParam: string;
156
- notNull: false;
157
- hasDefault: false;
158
- isPrimaryKey: false;
159
- isAutoincrement: false;
160
- hasRuntimeDefault: false;
161
- enumValues: undefined;
162
- baseColumn: never;
163
- identity: undefined;
164
- generated: undefined;
165
- }, {}, {}>;
166
- attempts: drizzle_orm_pg_core.PgColumn<{
167
- name: "attempts";
168
- tableName: "verification_codes";
169
- dataType: "string";
170
- columnType: "PgText";
171
- data: string;
172
- driverParam: string;
173
- notNull: true;
174
- hasDefault: true;
175
- isPrimaryKey: false;
176
- isAutoincrement: false;
177
- hasRuntimeDefault: false;
178
- enumValues: [string, ...string[]];
179
- baseColumn: never;
180
- identity: undefined;
181
- generated: undefined;
182
- }, {}, {}>;
183
- };
184
- dialect: "pg";
185
- }>;
186
- type VerificationCode = typeof verificationCodes.$inferSelect;
187
- type NewVerificationCode = typeof verificationCodes.$inferInsert;
188
- type VerificationTargetType = 'email' | 'phone';
189
- type VerificationPurpose = 'registration' | 'login' | 'password_reset' | 'email_change' | 'phone_change';
190
-
191
- export { type NewVerificationCode, type VerificationCode, type VerificationPurpose, type VerificationTargetType, verificationCodes };
@@ -1,49 +0,0 @@
1
- // src/server/entities/verification-codes.ts
2
- import { text, timestamp, index } from "drizzle-orm/pg-core";
3
- import { id, timestamps } from "@spfn/core/db";
4
-
5
- // src/server/entities/schema.ts
6
- import { createFunctionSchema } from "@spfn/core/db";
7
- var authSchema = createFunctionSchema("@spfn/auth");
8
-
9
- // src/server/entities/verification-codes.ts
10
- var verificationCodes = authSchema.table(
11
- "verification_codes",
12
- {
13
- id: id(),
14
- // Target (email or phone)
15
- target: text("target").notNull(),
16
- // Email address or E.164 phone number
17
- targetType: text(
18
- "target_type",
19
- {
20
- enum: ["email", "phone"]
21
- }
22
- ).notNull(),
23
- // Code
24
- code: text("code").notNull(),
25
- // 6-digit code by default (configurable)
26
- // Purpose
27
- purpose: text(
28
- "purpose",
29
- {
30
- enum: ["registration", "login", "password_reset", "email_change", "phone_change"]
31
- }
32
- ).notNull(),
33
- // Expiry
34
- expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
35
- // Usage tracking
36
- usedAt: timestamp("used_at", { withTimezone: true }),
37
- attempts: text("attempts").notNull().default("0"),
38
- // Track failed verification attempts
39
- ...timestamps()
40
- },
41
- (table) => [
42
- // Index for quick lookup by target and purpose
43
- index("target_purpose_idx").on(table.target, table.purpose, table.expiresAt)
44
- ]
45
- );
46
- export {
47
- verificationCodes
48
- };
49
- //# sourceMappingURL=verification-codes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/server/entities/verification-codes.ts","../../../src/server/entities/schema.ts"],"sourcesContent":["/**\n * @spfn/auth - Verification Codes Entity\n *\n * Stores verification codes for email and phone verification\n * Codes expire after a configurable time period\n */\n\nimport { text, timestamp, index } from 'drizzle-orm/pg-core';\nimport { id, timestamps } from '@spfn/core/db';\nimport { authSchema } from './schema';\n\nexport const verificationCodes = authSchema.table('verification_codes',\n {\n id: id(),\n\n // Target (email or phone)\n target: text('target').notNull(), // Email address or E.164 phone number\n targetType: text(\n 'target_type',\n {\n enum: ['email', 'phone']\n }\n ).notNull(),\n\n // Code\n code: text('code').notNull(), // 6-digit code by default (configurable)\n\n // Purpose\n purpose: text(\n 'purpose',\n {\n enum: ['registration', 'login', 'password_reset', 'email_change', 'phone_change']\n }\n ).notNull(),\n\n // Expiry\n expiresAt: timestamp('expires_at', { withTimezone: true }).notNull(),\n\n // Usage tracking\n usedAt: timestamp('used_at', { withTimezone: true }),\n attempts: text('attempts').notNull().default('0'), // Track failed verification attempts\n\n ...timestamps(),\n },\n (table) => [\n // Index for quick lookup by target and purpose\n index('target_purpose_idx')\n .on(table.target, table.purpose, table.expiresAt),\n ]\n);\n\n// Type exports\nexport type VerificationCode = typeof verificationCodes.$inferSelect;\nexport type NewVerificationCode = typeof verificationCodes.$inferInsert;\nexport type VerificationTargetType = 'email' | 'phone';\nexport type VerificationPurpose = 'registration' | 'login' | 'password_reset' | 'email_change' | 'phone_change';","/**\n * @spfn/auth - Database Schema Definition\n *\n * Defines the 'spfn_auth' PostgreSQL schema for all auth-related tables\n */\n\nimport { createFunctionSchema } from '@spfn/core/db';\n\n/**\n * Auth schema for all authentication and authorization tables\n * Tables: users, roles, permissions, user_invitations, etc.\n */\nexport const authSchema = createFunctionSchema('@spfn/auth');"],"mappings":";AAOA,SAAS,MAAM,WAAW,aAAa;AACvC,SAAS,IAAI,kBAAkB;;;ACF/B,SAAS,4BAA4B;AAM9B,IAAM,aAAa,qBAAqB,YAAY;;;ADDpD,IAAM,oBAAoB,WAAW;AAAA,EAAM;AAAA,EAC9C;AAAA,IACI,IAAI,GAAG;AAAA;AAAA,IAGP,QAAQ,KAAK,QAAQ,EAAE,QAAQ;AAAA;AAAA,IAC/B,YAAY;AAAA,MACR;AAAA,MACA;AAAA,QACI,MAAM,CAAC,SAAS,OAAO;AAAA,MAC3B;AAAA,IACJ,EAAE,QAAQ;AAAA;AAAA,IAGV,MAAM,KAAK,MAAM,EAAE,QAAQ;AAAA;AAAA;AAAA,IAG3B,SAAS;AAAA,MACL;AAAA,MACA;AAAA,QACI,MAAM,CAAC,gBAAgB,SAAS,kBAAkB,gBAAgB,cAAc;AAAA,MACpF;AAAA,IACJ,EAAE,QAAQ;AAAA;AAAA,IAGV,WAAW,UAAU,cAAc,EAAE,cAAc,KAAK,CAAC,EAAE,QAAQ;AAAA;AAAA,IAGnE,QAAQ,UAAU,WAAW,EAAE,cAAc,KAAK,CAAC;AAAA,IACnD,UAAU,KAAK,UAAU,EAAE,QAAQ,EAAE,QAAQ,GAAG;AAAA;AAAA,IAEhD,GAAG,WAAW;AAAA,EAClB;AAAA,EACA,CAAC,UAAU;AAAA;AAAA,IAEP,MAAM,oBAAoB,EACrB,GAAG,MAAM,QAAQ,MAAM,SAAS,MAAM,SAAS;AAAA,EACxD;AACJ;","names":[]}
@@ -1,10 +0,0 @@
1
- import * as _spfn_core_route from '@spfn/core/route';
2
-
3
- /**
4
- * @spfn/auth - Auth Routes
5
- *
6
- * Thin route handlers that delegate to services
7
- */
8
- declare const app: _spfn_core_route.SPFNApp;
9
-
10
- export { app as default };