@spfn/auth 0.1.0-alpha.88 → 0.2.0-beta.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.
- package/README.md +1385 -1199
- package/dist/config.d.ts +405 -0
- package/dist/config.js +240 -0
- package/dist/config.js.map +1 -0
- package/dist/dto-CLYtuAom.d.ts +630 -0
- package/dist/errors.d.ts +196 -0
- package/dist/errors.js +173 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +273 -14
- package/dist/index.js +511 -6665
- package/dist/index.js.map +1 -1
- package/dist/nextjs/api.js +345 -0
- package/dist/nextjs/api.js.map +1 -0
- package/dist/{adapters/nextjs → nextjs}/server.d.ts +47 -65
- package/dist/nextjs/server.js +179 -0
- package/dist/nextjs/server.js.map +1 -0
- package/dist/server.d.ts +4328 -529
- package/dist/server.js +7841 -1247
- package/dist/server.js.map +1 -1
- package/migrations/{0000_skinny_christian_walker.sql → 0000_marvelous_justice.sql} +53 -23
- package/migrations/meta/0000_snapshot.json +281 -46
- package/migrations/meta/_journal.json +2 -2
- package/package.json +31 -31
- package/dist/adapters/nextjs/api.d.ts +0 -446
- package/dist/adapters/nextjs/api.js +0 -3279
- package/dist/adapters/nextjs/api.js.map +0 -1
- package/dist/adapters/nextjs/server.js +0 -3645
- package/dist/adapters/nextjs/server.js.map +0 -1
- package/dist/lib/api/auth-codes-verify.d.ts +0 -37
- package/dist/lib/api/auth-codes-verify.js +0 -2949
- package/dist/lib/api/auth-codes-verify.js.map +0 -1
- package/dist/lib/api/auth-codes.d.ts +0 -37
- package/dist/lib/api/auth-codes.js +0 -2949
- package/dist/lib/api/auth-codes.js.map +0 -1
- package/dist/lib/api/auth-exists.d.ts +0 -38
- package/dist/lib/api/auth-exists.js +0 -2949
- package/dist/lib/api/auth-exists.js.map +0 -1
- package/dist/lib/api/auth-invitations-accept.d.ts +0 -38
- package/dist/lib/api/auth-invitations-accept.js +0 -2883
- package/dist/lib/api/auth-invitations-accept.js.map +0 -1
- package/dist/lib/api/auth-invitations-cancel.d.ts +0 -37
- package/dist/lib/api/auth-invitations-cancel.js +0 -2883
- package/dist/lib/api/auth-invitations-cancel.js.map +0 -1
- package/dist/lib/api/auth-invitations-delete.d.ts +0 -36
- package/dist/lib/api/auth-invitations-delete.js +0 -2883
- package/dist/lib/api/auth-invitations-delete.js.map +0 -1
- package/dist/lib/api/auth-invitations-resend.d.ts +0 -37
- package/dist/lib/api/auth-invitations-resend.js +0 -2883
- package/dist/lib/api/auth-invitations-resend.js.map +0 -1
- package/dist/lib/api/auth-invitations.d.ts +0 -109
- package/dist/lib/api/auth-invitations.js +0 -2887
- package/dist/lib/api/auth-invitations.js.map +0 -1
- package/dist/lib/api/auth-keys-rotate.d.ts +0 -37
- package/dist/lib/api/auth-keys-rotate.js +0 -2949
- package/dist/lib/api/auth-keys-rotate.js.map +0 -1
- package/dist/lib/api/auth-login.d.ts +0 -39
- package/dist/lib/api/auth-login.js +0 -2949
- package/dist/lib/api/auth-login.js.map +0 -1
- package/dist/lib/api/auth-logout.d.ts +0 -36
- package/dist/lib/api/auth-logout.js +0 -2949
- package/dist/lib/api/auth-logout.js.map +0 -1
- package/dist/lib/api/auth-me.d.ts +0 -50
- package/dist/lib/api/auth-me.js +0 -2949
- package/dist/lib/api/auth-me.js.map +0 -1
- package/dist/lib/api/auth-password.d.ts +0 -36
- package/dist/lib/api/auth-password.js +0 -2949
- package/dist/lib/api/auth-password.js.map +0 -1
- package/dist/lib/api/auth-register.d.ts +0 -38
- package/dist/lib/api/auth-register.js +0 -2949
- package/dist/lib/api/auth-register.js.map +0 -1
- package/dist/lib/api/index.d.ts +0 -356
- package/dist/lib/api/index.js +0 -3261
- package/dist/lib/api/index.js.map +0 -1
- package/dist/lib/config.d.ts +0 -70
- package/dist/lib/config.js +0 -64
- package/dist/lib/config.js.map +0 -1
- package/dist/lib/contracts/auth.d.ts +0 -302
- package/dist/lib/contracts/auth.js +0 -2951
- package/dist/lib/contracts/auth.js.map +0 -1
- package/dist/lib/contracts/index.d.ts +0 -3
- package/dist/lib/contracts/index.js +0 -3190
- package/dist/lib/contracts/index.js.map +0 -1
- package/dist/lib/contracts/invitation.d.ts +0 -243
- package/dist/lib/contracts/invitation.js +0 -2883
- package/dist/lib/contracts/invitation.js.map +0 -1
- package/dist/lib/crypto.d.ts +0 -76
- package/dist/lib/crypto.js +0 -127
- package/dist/lib/crypto.js.map +0 -1
- package/dist/lib/index.d.ts +0 -4
- package/dist/lib/index.js +0 -313
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/session.d.ts +0 -68
- package/dist/lib/session.js +0 -126
- package/dist/lib/session.js.map +0 -1
- package/dist/lib/types/api.d.ts +0 -45
- package/dist/lib/types/api.js +0 -1
- package/dist/lib/types/api.js.map +0 -1
- package/dist/lib/types/index.d.ts +0 -3
- package/dist/lib/types/index.js +0 -2647
- package/dist/lib/types/index.js.map +0 -1
- package/dist/lib/types/schemas.d.ts +0 -45
- package/dist/lib/types/schemas.js +0 -2647
- package/dist/lib/types/schemas.js.map +0 -1
- package/dist/lib.js +0 -1
- package/dist/lib.js.map +0 -1
- package/dist/plugin.d.ts +0 -12
- package/dist/plugin.js +0 -9083
- package/dist/plugin.js.map +0 -1
- package/dist/server/entities/index.d.ts +0 -11
- package/dist/server/entities/index.js +0 -395
- package/dist/server/entities/index.js.map +0 -1
- package/dist/server/entities/invitations.d.ts +0 -241
- package/dist/server/entities/invitations.js +0 -184
- package/dist/server/entities/invitations.js.map +0 -1
- package/dist/server/entities/permissions.d.ts +0 -196
- package/dist/server/entities/permissions.js +0 -49
- package/dist/server/entities/permissions.js.map +0 -1
- package/dist/server/entities/role-permissions.d.ts +0 -107
- package/dist/server/entities/role-permissions.js +0 -115
- package/dist/server/entities/role-permissions.js.map +0 -1
- package/dist/server/entities/roles.d.ts +0 -196
- package/dist/server/entities/roles.js +0 -50
- package/dist/server/entities/roles.js.map +0 -1
- package/dist/server/entities/schema.d.ts +0 -14
- package/dist/server/entities/schema.js +0 -7
- package/dist/server/entities/schema.js.map +0 -1
- package/dist/server/entities/user-permissions.d.ts +0 -163
- package/dist/server/entities/user-permissions.js +0 -193
- package/dist/server/entities/user-permissions.js.map +0 -1
- package/dist/server/entities/user-public-keys.d.ts +0 -227
- package/dist/server/entities/user-public-keys.js +0 -156
- package/dist/server/entities/user-public-keys.js.map +0 -1
- package/dist/server/entities/user-social-accounts.d.ts +0 -189
- package/dist/server/entities/user-social-accounts.js +0 -149
- package/dist/server/entities/user-social-accounts.js.map +0 -1
- package/dist/server/entities/users.d.ts +0 -235
- package/dist/server/entities/users.js +0 -117
- package/dist/server/entities/users.js.map +0 -1
- package/dist/server/entities/verification-codes.d.ts +0 -191
- package/dist/server/entities/verification-codes.js +0 -49
- package/dist/server/entities/verification-codes.js.map +0 -1
- package/dist/server/routes/auth/index.d.ts +0 -10
- package/dist/server/routes/auth/index.js +0 -4460
- package/dist/server/routes/auth/index.js.map +0 -1
- package/dist/server/routes/index.d.ts +0 -6
- package/dist/server/routes/index.js +0 -6584
- package/dist/server/routes/index.js.map +0 -1
- package/dist/server/routes/invitations/index.d.ts +0 -10
- package/dist/server/routes/invitations/index.js +0 -4395
- package/dist/server/routes/invitations/index.js.map +0 -1
- /package/dist/{lib.d.ts → nextjs/api.d.ts} +0 -0
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
// src/server/entities/user-public-keys.ts
|
|
2
|
-
import { text as text3, timestamp as timestamp2, boolean as boolean3, index as index3 } from "drizzle-orm/pg-core";
|
|
3
|
-
import { id as id3, foreignKey } from "@spfn/core/db";
|
|
4
|
-
|
|
5
|
-
// src/server/entities/users.ts
|
|
6
|
-
import { text as text2, timestamp, check, boolean as boolean2, bigint, index as index2 } from "drizzle-orm/pg-core";
|
|
7
|
-
import { id as id2, timestamps as timestamps2 } from "@spfn/core/db";
|
|
8
|
-
import { sql } from "drizzle-orm";
|
|
9
|
-
|
|
10
|
-
// src/server/entities/roles.ts
|
|
11
|
-
import { text, boolean, integer, index } from "drizzle-orm/pg-core";
|
|
12
|
-
import { id, timestamps } from "@spfn/core/db";
|
|
13
|
-
|
|
14
|
-
// src/server/entities/schema.ts
|
|
15
|
-
import { createFunctionSchema } from "@spfn/core/db";
|
|
16
|
-
var authSchema = createFunctionSchema("@spfn/auth");
|
|
17
|
-
|
|
18
|
-
// src/server/entities/roles.ts
|
|
19
|
-
var roles = authSchema.table(
|
|
20
|
-
"roles",
|
|
21
|
-
{
|
|
22
|
-
// Primary key
|
|
23
|
-
id: id(),
|
|
24
|
-
// Role identifier (used in code, e.g., 'admin', 'editor')
|
|
25
|
-
// Must be unique, lowercase, kebab-case recommended
|
|
26
|
-
name: text("name").notNull().unique(),
|
|
27
|
-
// Display name for UI (e.g., 'Administrator', 'Content Editor')
|
|
28
|
-
displayName: text("display_name").notNull(),
|
|
29
|
-
// Role description
|
|
30
|
-
description: text("description"),
|
|
31
|
-
// Built-in role flag
|
|
32
|
-
// true: Core package roles (user, admin, superadmin) - cannot be deleted
|
|
33
|
-
// false: Custom or preset roles - can be deleted
|
|
34
|
-
isBuiltin: boolean("is_builtin").notNull().default(false),
|
|
35
|
-
// System role flag
|
|
36
|
-
// true: Defined in code (builtin or preset) - deletion restricted
|
|
37
|
-
// false: Runtime created custom role - fully manageable
|
|
38
|
-
isSystem: boolean("is_system").notNull().default(false),
|
|
39
|
-
// Active status
|
|
40
|
-
// false: Deactivated role (users cannot be assigned)
|
|
41
|
-
isActive: boolean("is_active").notNull().default(true),
|
|
42
|
-
// Priority level (higher = more privileged)
|
|
43
|
-
// superadmin: 100, admin: 80, user: 10
|
|
44
|
-
// Used for role hierarchy and conflict resolution
|
|
45
|
-
priority: integer("priority").notNull().default(10),
|
|
46
|
-
...timestamps()
|
|
47
|
-
},
|
|
48
|
-
(table) => [
|
|
49
|
-
index("roles_name_idx").on(table.name),
|
|
50
|
-
index("roles_is_system_idx").on(table.isSystem),
|
|
51
|
-
index("roles_is_active_idx").on(table.isActive),
|
|
52
|
-
index("roles_is_builtin_idx").on(table.isBuiltin),
|
|
53
|
-
index("roles_priority_idx").on(table.priority)
|
|
54
|
-
]
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
// src/server/entities/users.ts
|
|
58
|
-
var users = authSchema.table(
|
|
59
|
-
"users",
|
|
60
|
-
{
|
|
61
|
-
// Identity
|
|
62
|
-
id: id2(),
|
|
63
|
-
// Email address (unique identifier)
|
|
64
|
-
// Used for: login, password reset, notifications
|
|
65
|
-
email: text2("email").unique(),
|
|
66
|
-
// Phone number in E.164 international format
|
|
67
|
-
// Format: +[country code][number] (e.g., +821012345678)
|
|
68
|
-
// Used for: SMS login, 2FA, notifications
|
|
69
|
-
phone: text2("phone").unique(),
|
|
70
|
-
// Authentication
|
|
71
|
-
// Bcrypt password hash ($2b$10$[salt][hash], 60 chars)
|
|
72
|
-
// Nullable to support OAuth-only accounts
|
|
73
|
-
passwordHash: text2("password_hash"),
|
|
74
|
-
// Force password change on next login
|
|
75
|
-
// Use cases: initial setup, security breach, policy violation
|
|
76
|
-
passwordChangeRequired: boolean2("password_change_required").notNull().default(false),
|
|
77
|
-
// Authorization (Role-Based Access Control)
|
|
78
|
-
// Foreign key to roles table
|
|
79
|
-
// References built-in roles: user (default), admin, superadmin
|
|
80
|
-
// Can also reference custom roles created at runtime
|
|
81
|
-
roleId: bigint("role_id", { mode: "number" }).references(() => roles.id).notNull(),
|
|
82
|
-
// Account status
|
|
83
|
-
// - active: Normal operation (default)
|
|
84
|
-
// - inactive: Deactivated (user request, dormant)
|
|
85
|
-
// - suspended: Locked (security incident, ToS violation)
|
|
86
|
-
status: text2(
|
|
87
|
-
"status",
|
|
88
|
-
{
|
|
89
|
-
enum: ["active", "inactive", "suspended"]
|
|
90
|
-
}
|
|
91
|
-
).notNull().default("active"),
|
|
92
|
-
// Verification timestamps
|
|
93
|
-
// null = unverified, timestamp = verified at this time
|
|
94
|
-
// Email verification (via verification code or magic link)
|
|
95
|
-
emailVerifiedAt: timestamp("email_verified_at", { withTimezone: true }),
|
|
96
|
-
// Phone verification (via SMS OTP)
|
|
97
|
-
phoneVerifiedAt: timestamp("phone_verified_at", { withTimezone: true }),
|
|
98
|
-
// Metadata
|
|
99
|
-
// Last successful login timestamp
|
|
100
|
-
// Used for: security auditing, dormant account detection
|
|
101
|
-
lastLoginAt: timestamp("last_login_at", { withTimezone: true }),
|
|
102
|
-
...timestamps2()
|
|
103
|
-
},
|
|
104
|
-
(table) => [
|
|
105
|
-
// Database constraints
|
|
106
|
-
// Ensure at least one identifier exists (email OR phone)
|
|
107
|
-
check(
|
|
108
|
-
"email_or_phone_check",
|
|
109
|
-
sql`${table.email} IS NOT NULL OR ${table.phone} IS NOT NULL`
|
|
110
|
-
),
|
|
111
|
-
// Indexes for query optimization
|
|
112
|
-
index2("users_email_idx").on(table.email),
|
|
113
|
-
index2("users_phone_idx").on(table.phone),
|
|
114
|
-
index2("users_status_idx").on(table.status),
|
|
115
|
-
index2("users_role_id_idx").on(table.roleId)
|
|
116
|
-
]
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
// src/server/entities/user-public-keys.ts
|
|
120
|
-
var userPublicKeys = authSchema.table(
|
|
121
|
-
"user_public_keys",
|
|
122
|
-
{
|
|
123
|
-
id: id3(),
|
|
124
|
-
// User reference
|
|
125
|
-
userId: foreignKey("user", () => users.id),
|
|
126
|
-
// Key identification (client-generated UUID)
|
|
127
|
-
keyId: text3("key_id").notNull().unique(),
|
|
128
|
-
// Public key in Base64-encoded DER format (SPKI)
|
|
129
|
-
publicKey: text3("public_key").notNull(),
|
|
130
|
-
// Algorithm used (ES256 recommended, RS256 fallback)
|
|
131
|
-
algorithm: text3("algorithm", {
|
|
132
|
-
enum: ["ES256", "RS256"]
|
|
133
|
-
}).notNull().default("ES256"),
|
|
134
|
-
// Key fingerprint (SHA-256 hash for quick identification)
|
|
135
|
-
fingerprint: text3("fingerprint").notNull(),
|
|
136
|
-
// Key status
|
|
137
|
-
isActive: boolean3("is_active").notNull().default(true),
|
|
138
|
-
// Timestamps
|
|
139
|
-
createdAt: timestamp2("created_at", { mode: "date", withTimezone: true }).notNull().defaultNow(),
|
|
140
|
-
lastUsedAt: timestamp2("last_used_at", { mode: "date", withTimezone: true }),
|
|
141
|
-
expiresAt: timestamp2("expires_at", { mode: "date", withTimezone: true }),
|
|
142
|
-
// Revocation
|
|
143
|
-
revokedAt: timestamp2("revoked_at", { mode: "date", withTimezone: true }),
|
|
144
|
-
revokedReason: text3("revoked_reason")
|
|
145
|
-
},
|
|
146
|
-
(table) => [
|
|
147
|
-
index3("user_public_keys_user_id_idx").on(table.userId),
|
|
148
|
-
index3("user_public_keys_key_id_idx").on(table.keyId),
|
|
149
|
-
index3("user_public_keys_active_idx").on(table.isActive),
|
|
150
|
-
index3("user_public_keys_fingerprint_idx").on(table.fingerprint)
|
|
151
|
-
]
|
|
152
|
-
);
|
|
153
|
-
export {
|
|
154
|
-
userPublicKeys
|
|
155
|
-
};
|
|
156
|
-
//# sourceMappingURL=user-public-keys.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/entities/user-public-keys.ts","../../../src/server/entities/users.ts","../../../src/server/entities/roles.ts","../../../src/server/entities/schema.ts"],"sourcesContent":["/**\n * @spfn/auth - User Public Keys Entity\n *\n * Stores client-generated public keys for JWT verification\n * Supports key rotation and multi-key management per user\n */\n\nimport { text, timestamp, boolean, index } from 'drizzle-orm/pg-core';\nimport { id, foreignKey } from '@spfn/core/db';\nimport { users } from './users';\nimport { authSchema } from './schema';\n\n/**\n * User Public Keys Table\n * Each user can have multiple public keys (for rotation)\n */\nexport const userPublicKeys = authSchema.table(\n 'user_public_keys',\n {\n id: id(),\n\n // User reference\n userId: foreignKey('user', () => users.id),\n\n // Key identification (client-generated UUID)\n keyId: text('key_id').notNull().unique(),\n\n // Public key in Base64-encoded DER format (SPKI)\n publicKey: text('public_key').notNull(),\n\n // Algorithm used (ES256 recommended, RS256 fallback)\n algorithm: text('algorithm', {\n enum: ['ES256', 'RS256']\n }).notNull().default('ES256'),\n\n // Key fingerprint (SHA-256 hash for quick identification)\n fingerprint: text('fingerprint').notNull(),\n\n // Key status\n isActive: boolean('is_active').notNull().default(true),\n\n // Timestamps\n createdAt: timestamp('created_at', { mode: 'date', withTimezone: true })\n .notNull()\n .defaultNow(),\n\n lastUsedAt: timestamp('last_used_at', { mode: 'date', withTimezone: true }),\n\n expiresAt: timestamp('expires_at', { mode: 'date', withTimezone: true }),\n\n // Revocation\n revokedAt: timestamp('revoked_at', { mode: 'date', withTimezone: true }),\n revokedReason: text('revoked_reason'),\n },\n (table) => [\n index('user_public_keys_user_id_idx').on(table.userId),\n index('user_public_keys_key_id_idx').on(table.keyId),\n index('user_public_keys_active_idx').on(table.isActive),\n index('user_public_keys_fingerprint_idx').on(table.fingerprint),\n ]\n);\n\nexport type UserPublicKey = typeof userPublicKeys.$inferSelect;\nexport type NewUserPublicKey = typeof userPublicKeys.$inferInsert;","/**\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":";AAOA,SAAS,QAAAA,OAAM,aAAAC,YAAW,WAAAC,UAAS,SAAAC,cAAa;AAChD,SAAS,MAAAC,KAAI,kBAAkB;;;ACM/B,SAAS,QAAAC,OAAM,WAAW,OAAO,WAAAC,UAAS,QAAQ,SAAAC,cAAa;AAC/D,SAAS,MAAAC,KAAI,cA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EAAE,QAAQ,EAAE,OAAO;AAAA;AAAA,IAGvC,WAAWA,MAAK,YAAY,EAAE,QAAQ;AAAA;AAAA,IAGtC,WAAWA,MAAK,aAAa;AAAA,MACzB,MAAM,CAAC,SAAS,OAAO;AAAA,IAC3B,CAAC,EAAE,QAAQ,EAAE,QAAQ,OAAO;AAAA;AAAA,IAG5B,aAAaA,MAAK,aAAa,EAAE,QAAQ;AAAA;AAAA,IAGzC,UAAUC,SAAQ,WAAW,EAAE,QAAQ,EAAE,QAAQ,IAAI;AAAA;AAAA,IAGrD,WAAWC,WAAU,cAAc,EAAE,MAAM,QAAQ,cAAc,KAAK,CAAC,EAClE,QAAQ,EACR,WAAW;AAAA,IAEhB,YAAYA,WAAU,gBAAgB,EAAE,MAAM,QAAQ,cAAc,KAAK,CAAC;AAAA,IAE1E,WAAWA,WAAU,cAAc,EAAE,MAAM,QAAQ,cAAc,KAAK,CAAC;AAAA;AAAA,IAGvE,WAAWA,WAAU,cAAc,EAAE,MAAM,QAAQ,cAAc,KAAK,CAAC;AAAA,IACvE,eAAeF,MAAK,gBAAgB;AAAA,EACxC;AAAA,EACA,CAAC,UAAU;AAAA,IACPG,OAAM,8BAA8B,EAAE,GAAG,MAAM,MAAM;AAAA,IACrDA,OAAM,6BAA6B,EAAE,GAAG,MAAM,KAAK;AAAA,IACnDA,OAAM,6BAA6B,EAAE,GAAG,MAAM,QAAQ;AAAA,IACtDA,OAAM,kCAAkC,EAAE,GAAG,MAAM,WAAW;AAAA,EAClE;AACJ;","names":["text","timestamp","boolean","index","id","text","boolean","index","id","timestamps","id","text","boolean","timestamps","index","id","text","boolean","timestamp","index"]}
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @spfn/auth - User Social Accounts Entity
|
|
5
|
-
*
|
|
6
|
-
* Stores OAuth connections for social login providers
|
|
7
|
-
*/
|
|
8
|
-
declare const userSocialAccounts: drizzle_orm_pg_core.PgTableWithColumns<{
|
|
9
|
-
name: "user_social_accounts";
|
|
10
|
-
schema: string;
|
|
11
|
-
columns: {
|
|
12
|
-
createdAt: drizzle_orm_pg_core.PgColumn<{
|
|
13
|
-
name: "created_at";
|
|
14
|
-
tableName: "user_social_accounts";
|
|
15
|
-
dataType: "date";
|
|
16
|
-
columnType: "PgTimestamp";
|
|
17
|
-
data: Date;
|
|
18
|
-
driverParam: string;
|
|
19
|
-
notNull: true;
|
|
20
|
-
hasDefault: true;
|
|
21
|
-
isPrimaryKey: false;
|
|
22
|
-
isAutoincrement: false;
|
|
23
|
-
hasRuntimeDefault: false;
|
|
24
|
-
enumValues: undefined;
|
|
25
|
-
baseColumn: never;
|
|
26
|
-
identity: undefined;
|
|
27
|
-
generated: undefined;
|
|
28
|
-
}, {}, {}>;
|
|
29
|
-
updatedAt: drizzle_orm_pg_core.PgColumn<{
|
|
30
|
-
name: "updated_at";
|
|
31
|
-
tableName: "user_social_accounts";
|
|
32
|
-
dataType: "date";
|
|
33
|
-
columnType: "PgTimestamp";
|
|
34
|
-
data: Date;
|
|
35
|
-
driverParam: string;
|
|
36
|
-
notNull: true;
|
|
37
|
-
hasDefault: true;
|
|
38
|
-
isPrimaryKey: false;
|
|
39
|
-
isAutoincrement: false;
|
|
40
|
-
hasRuntimeDefault: false;
|
|
41
|
-
enumValues: undefined;
|
|
42
|
-
baseColumn: never;
|
|
43
|
-
identity: undefined;
|
|
44
|
-
generated: undefined;
|
|
45
|
-
}, {}, {}>;
|
|
46
|
-
id: drizzle_orm_pg_core.PgColumn<{
|
|
47
|
-
name: "id";
|
|
48
|
-
tableName: "user_social_accounts";
|
|
49
|
-
dataType: "number";
|
|
50
|
-
columnType: "PgBigSerial53";
|
|
51
|
-
data: number;
|
|
52
|
-
driverParam: number;
|
|
53
|
-
notNull: true;
|
|
54
|
-
hasDefault: true;
|
|
55
|
-
isPrimaryKey: true;
|
|
56
|
-
isAutoincrement: false;
|
|
57
|
-
hasRuntimeDefault: false;
|
|
58
|
-
enumValues: undefined;
|
|
59
|
-
baseColumn: never;
|
|
60
|
-
identity: undefined;
|
|
61
|
-
generated: undefined;
|
|
62
|
-
}, {}, {}>;
|
|
63
|
-
userId: drizzle_orm_pg_core.PgColumn<{
|
|
64
|
-
name: `${string}_id`;
|
|
65
|
-
tableName: "user_social_accounts";
|
|
66
|
-
dataType: "number";
|
|
67
|
-
columnType: "PgBigSerial53";
|
|
68
|
-
data: number;
|
|
69
|
-
driverParam: number;
|
|
70
|
-
notNull: true;
|
|
71
|
-
hasDefault: true;
|
|
72
|
-
isPrimaryKey: false;
|
|
73
|
-
isAutoincrement: false;
|
|
74
|
-
hasRuntimeDefault: false;
|
|
75
|
-
enumValues: undefined;
|
|
76
|
-
baseColumn: never;
|
|
77
|
-
identity: undefined;
|
|
78
|
-
generated: undefined;
|
|
79
|
-
}, {}, {}>;
|
|
80
|
-
provider: drizzle_orm_pg_core.PgColumn<{
|
|
81
|
-
name: "provider";
|
|
82
|
-
tableName: "user_social_accounts";
|
|
83
|
-
dataType: "string";
|
|
84
|
-
columnType: "PgText";
|
|
85
|
-
data: "google" | "github" | "kakao" | "naver";
|
|
86
|
-
driverParam: string;
|
|
87
|
-
notNull: true;
|
|
88
|
-
hasDefault: false;
|
|
89
|
-
isPrimaryKey: false;
|
|
90
|
-
isAutoincrement: false;
|
|
91
|
-
hasRuntimeDefault: false;
|
|
92
|
-
enumValues: ["google", "github", "kakao", "naver"];
|
|
93
|
-
baseColumn: never;
|
|
94
|
-
identity: undefined;
|
|
95
|
-
generated: undefined;
|
|
96
|
-
}, {}, {}>;
|
|
97
|
-
providerUserId: drizzle_orm_pg_core.PgColumn<{
|
|
98
|
-
name: "provider_user_id";
|
|
99
|
-
tableName: "user_social_accounts";
|
|
100
|
-
dataType: "string";
|
|
101
|
-
columnType: "PgText";
|
|
102
|
-
data: string;
|
|
103
|
-
driverParam: string;
|
|
104
|
-
notNull: true;
|
|
105
|
-
hasDefault: false;
|
|
106
|
-
isPrimaryKey: false;
|
|
107
|
-
isAutoincrement: false;
|
|
108
|
-
hasRuntimeDefault: false;
|
|
109
|
-
enumValues: [string, ...string[]];
|
|
110
|
-
baseColumn: never;
|
|
111
|
-
identity: undefined;
|
|
112
|
-
generated: undefined;
|
|
113
|
-
}, {}, {}>;
|
|
114
|
-
providerEmail: drizzle_orm_pg_core.PgColumn<{
|
|
115
|
-
name: "provider_email";
|
|
116
|
-
tableName: "user_social_accounts";
|
|
117
|
-
dataType: "string";
|
|
118
|
-
columnType: "PgText";
|
|
119
|
-
data: string;
|
|
120
|
-
driverParam: string;
|
|
121
|
-
notNull: false;
|
|
122
|
-
hasDefault: false;
|
|
123
|
-
isPrimaryKey: false;
|
|
124
|
-
isAutoincrement: false;
|
|
125
|
-
hasRuntimeDefault: false;
|
|
126
|
-
enumValues: [string, ...string[]];
|
|
127
|
-
baseColumn: never;
|
|
128
|
-
identity: undefined;
|
|
129
|
-
generated: undefined;
|
|
130
|
-
}, {}, {}>;
|
|
131
|
-
accessToken: drizzle_orm_pg_core.PgColumn<{
|
|
132
|
-
name: "access_token";
|
|
133
|
-
tableName: "user_social_accounts";
|
|
134
|
-
dataType: "string";
|
|
135
|
-
columnType: "PgText";
|
|
136
|
-
data: string;
|
|
137
|
-
driverParam: string;
|
|
138
|
-
notNull: false;
|
|
139
|
-
hasDefault: false;
|
|
140
|
-
isPrimaryKey: false;
|
|
141
|
-
isAutoincrement: false;
|
|
142
|
-
hasRuntimeDefault: false;
|
|
143
|
-
enumValues: [string, ...string[]];
|
|
144
|
-
baseColumn: never;
|
|
145
|
-
identity: undefined;
|
|
146
|
-
generated: undefined;
|
|
147
|
-
}, {}, {}>;
|
|
148
|
-
refreshToken: drizzle_orm_pg_core.PgColumn<{
|
|
149
|
-
name: "refresh_token";
|
|
150
|
-
tableName: "user_social_accounts";
|
|
151
|
-
dataType: "string";
|
|
152
|
-
columnType: "PgText";
|
|
153
|
-
data: string;
|
|
154
|
-
driverParam: string;
|
|
155
|
-
notNull: false;
|
|
156
|
-
hasDefault: false;
|
|
157
|
-
isPrimaryKey: false;
|
|
158
|
-
isAutoincrement: false;
|
|
159
|
-
hasRuntimeDefault: false;
|
|
160
|
-
enumValues: [string, ...string[]];
|
|
161
|
-
baseColumn: never;
|
|
162
|
-
identity: undefined;
|
|
163
|
-
generated: undefined;
|
|
164
|
-
}, {}, {}>;
|
|
165
|
-
tokenExpiresAt: drizzle_orm_pg_core.PgColumn<{
|
|
166
|
-
name: "token_expires_at";
|
|
167
|
-
tableName: "user_social_accounts";
|
|
168
|
-
dataType: "date";
|
|
169
|
-
columnType: "PgTimestamp";
|
|
170
|
-
data: Date;
|
|
171
|
-
driverParam: string;
|
|
172
|
-
notNull: false;
|
|
173
|
-
hasDefault: false;
|
|
174
|
-
isPrimaryKey: false;
|
|
175
|
-
isAutoincrement: false;
|
|
176
|
-
hasRuntimeDefault: false;
|
|
177
|
-
enumValues: undefined;
|
|
178
|
-
baseColumn: never;
|
|
179
|
-
identity: undefined;
|
|
180
|
-
generated: undefined;
|
|
181
|
-
}, {}, {}>;
|
|
182
|
-
};
|
|
183
|
-
dialect: "pg";
|
|
184
|
-
}>;
|
|
185
|
-
type UserSocialAccount = typeof userSocialAccounts.$inferSelect;
|
|
186
|
-
type NewUserSocialAccount = typeof userSocialAccounts.$inferInsert;
|
|
187
|
-
type SocialProvider = 'google' | 'github' | 'kakao' | 'naver';
|
|
188
|
-
|
|
189
|
-
export { type NewUserSocialAccount, type SocialProvider, type UserSocialAccount, userSocialAccounts };
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
// src/server/entities/user-social-accounts.ts
|
|
2
|
-
import { text as text3, timestamp as timestamp2, uniqueIndex } from "drizzle-orm/pg-core";
|
|
3
|
-
import { id as id3, timestamps as timestamps3, foreignKey } from "@spfn/core/db";
|
|
4
|
-
|
|
5
|
-
// src/server/entities/users.ts
|
|
6
|
-
import { text as text2, timestamp, check, boolean as boolean2, bigint, index as index2 } from "drizzle-orm/pg-core";
|
|
7
|
-
import { id as id2, timestamps as timestamps2 } from "@spfn/core/db";
|
|
8
|
-
import { sql } from "drizzle-orm";
|
|
9
|
-
|
|
10
|
-
// src/server/entities/roles.ts
|
|
11
|
-
import { text, boolean, integer, index } from "drizzle-orm/pg-core";
|
|
12
|
-
import { id, timestamps } from "@spfn/core/db";
|
|
13
|
-
|
|
14
|
-
// src/server/entities/schema.ts
|
|
15
|
-
import { createFunctionSchema } from "@spfn/core/db";
|
|
16
|
-
var authSchema = createFunctionSchema("@spfn/auth");
|
|
17
|
-
|
|
18
|
-
// src/server/entities/roles.ts
|
|
19
|
-
var roles = authSchema.table(
|
|
20
|
-
"roles",
|
|
21
|
-
{
|
|
22
|
-
// Primary key
|
|
23
|
-
id: id(),
|
|
24
|
-
// Role identifier (used in code, e.g., 'admin', 'editor')
|
|
25
|
-
// Must be unique, lowercase, kebab-case recommended
|
|
26
|
-
name: text("name").notNull().unique(),
|
|
27
|
-
// Display name for UI (e.g., 'Administrator', 'Content Editor')
|
|
28
|
-
displayName: text("display_name").notNull(),
|
|
29
|
-
// Role description
|
|
30
|
-
description: text("description"),
|
|
31
|
-
// Built-in role flag
|
|
32
|
-
// true: Core package roles (user, admin, superadmin) - cannot be deleted
|
|
33
|
-
// false: Custom or preset roles - can be deleted
|
|
34
|
-
isBuiltin: boolean("is_builtin").notNull().default(false),
|
|
35
|
-
// System role flag
|
|
36
|
-
// true: Defined in code (builtin or preset) - deletion restricted
|
|
37
|
-
// false: Runtime created custom role - fully manageable
|
|
38
|
-
isSystem: boolean("is_system").notNull().default(false),
|
|
39
|
-
// Active status
|
|
40
|
-
// false: Deactivated role (users cannot be assigned)
|
|
41
|
-
isActive: boolean("is_active").notNull().default(true),
|
|
42
|
-
// Priority level (higher = more privileged)
|
|
43
|
-
// superadmin: 100, admin: 80, user: 10
|
|
44
|
-
// Used for role hierarchy and conflict resolution
|
|
45
|
-
priority: integer("priority").notNull().default(10),
|
|
46
|
-
...timestamps()
|
|
47
|
-
},
|
|
48
|
-
(table) => [
|
|
49
|
-
index("roles_name_idx").on(table.name),
|
|
50
|
-
index("roles_is_system_idx").on(table.isSystem),
|
|
51
|
-
index("roles_is_active_idx").on(table.isActive),
|
|
52
|
-
index("roles_is_builtin_idx").on(table.isBuiltin),
|
|
53
|
-
index("roles_priority_idx").on(table.priority)
|
|
54
|
-
]
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
// src/server/entities/users.ts
|
|
58
|
-
var users = authSchema.table(
|
|
59
|
-
"users",
|
|
60
|
-
{
|
|
61
|
-
// Identity
|
|
62
|
-
id: id2(),
|
|
63
|
-
// Email address (unique identifier)
|
|
64
|
-
// Used for: login, password reset, notifications
|
|
65
|
-
email: text2("email").unique(),
|
|
66
|
-
// Phone number in E.164 international format
|
|
67
|
-
// Format: +[country code][number] (e.g., +821012345678)
|
|
68
|
-
// Used for: SMS login, 2FA, notifications
|
|
69
|
-
phone: text2("phone").unique(),
|
|
70
|
-
// Authentication
|
|
71
|
-
// Bcrypt password hash ($2b$10$[salt][hash], 60 chars)
|
|
72
|
-
// Nullable to support OAuth-only accounts
|
|
73
|
-
passwordHash: text2("password_hash"),
|
|
74
|
-
// Force password change on next login
|
|
75
|
-
// Use cases: initial setup, security breach, policy violation
|
|
76
|
-
passwordChangeRequired: boolean2("password_change_required").notNull().default(false),
|
|
77
|
-
// Authorization (Role-Based Access Control)
|
|
78
|
-
// Foreign key to roles table
|
|
79
|
-
// References built-in roles: user (default), admin, superadmin
|
|
80
|
-
// Can also reference custom roles created at runtime
|
|
81
|
-
roleId: bigint("role_id", { mode: "number" }).references(() => roles.id).notNull(),
|
|
82
|
-
// Account status
|
|
83
|
-
// - active: Normal operation (default)
|
|
84
|
-
// - inactive: Deactivated (user request, dormant)
|
|
85
|
-
// - suspended: Locked (security incident, ToS violation)
|
|
86
|
-
status: text2(
|
|
87
|
-
"status",
|
|
88
|
-
{
|
|
89
|
-
enum: ["active", "inactive", "suspended"]
|
|
90
|
-
}
|
|
91
|
-
).notNull().default("active"),
|
|
92
|
-
// Verification timestamps
|
|
93
|
-
// null = unverified, timestamp = verified at this time
|
|
94
|
-
// Email verification (via verification code or magic link)
|
|
95
|
-
emailVerifiedAt: timestamp("email_verified_at", { withTimezone: true }),
|
|
96
|
-
// Phone verification (via SMS OTP)
|
|
97
|
-
phoneVerifiedAt: timestamp("phone_verified_at", { withTimezone: true }),
|
|
98
|
-
// Metadata
|
|
99
|
-
// Last successful login timestamp
|
|
100
|
-
// Used for: security auditing, dormant account detection
|
|
101
|
-
lastLoginAt: timestamp("last_login_at", { withTimezone: true }),
|
|
102
|
-
...timestamps2()
|
|
103
|
-
},
|
|
104
|
-
(table) => [
|
|
105
|
-
// Database constraints
|
|
106
|
-
// Ensure at least one identifier exists (email OR phone)
|
|
107
|
-
check(
|
|
108
|
-
"email_or_phone_check",
|
|
109
|
-
sql`${table.email} IS NOT NULL OR ${table.phone} IS NOT NULL`
|
|
110
|
-
),
|
|
111
|
-
// Indexes for query optimization
|
|
112
|
-
index2("users_email_idx").on(table.email),
|
|
113
|
-
index2("users_phone_idx").on(table.phone),
|
|
114
|
-
index2("users_status_idx").on(table.status),
|
|
115
|
-
index2("users_role_id_idx").on(table.roleId)
|
|
116
|
-
]
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
// src/server/entities/user-social-accounts.ts
|
|
120
|
-
var userSocialAccounts = authSchema.table(
|
|
121
|
-
"user_social_accounts",
|
|
122
|
-
{
|
|
123
|
-
id: id3(),
|
|
124
|
-
// Foreign key to users
|
|
125
|
-
userId: foreignKey("user", () => users.id),
|
|
126
|
-
// Provider info
|
|
127
|
-
provider: text3(
|
|
128
|
-
"provider",
|
|
129
|
-
{
|
|
130
|
-
enum: ["google", "github", "kakao", "naver"]
|
|
131
|
-
}
|
|
132
|
-
).notNull(),
|
|
133
|
-
providerUserId: text3("provider_user_id").notNull(),
|
|
134
|
-
providerEmail: text3("provider_email"),
|
|
135
|
-
// OAuth tokens (encrypted in production)
|
|
136
|
-
accessToken: text3("access_token"),
|
|
137
|
-
refreshToken: text3("refresh_token"),
|
|
138
|
-
tokenExpiresAt: timestamp2("token_expires_at", { withTimezone: true }),
|
|
139
|
-
...timestamps3()
|
|
140
|
-
},
|
|
141
|
-
(table) => [
|
|
142
|
-
// Unique constraint: one provider account per provider
|
|
143
|
-
uniqueIndex("provider_user_unique_idx").on(table.provider, table.providerUserId)
|
|
144
|
-
]
|
|
145
|
-
);
|
|
146
|
-
export {
|
|
147
|
-
userSocialAccounts
|
|
148
|
-
};
|
|
149
|
-
//# sourceMappingURL=user-social-accounts.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/entities/user-social-accounts.ts","../../../src/server/entities/users.ts","../../../src/server/entities/roles.ts","../../../src/server/entities/schema.ts"],"sourcesContent":["/**\n * @spfn/auth - User Social Accounts Entity\n *\n * Stores OAuth connections for social login providers\n */\n\nimport { text, timestamp, uniqueIndex } from 'drizzle-orm/pg-core';\nimport { id, timestamps, foreignKey } from '@spfn/core/db';\nimport { users } from './users';\nimport { authSchema } from './schema';\n\nexport const userSocialAccounts = authSchema.table('user_social_accounts',\n {\n id: id(),\n\n // Foreign key to users\n userId: foreignKey('user', () => users.id),\n\n // Provider info\n provider: text(\n 'provider',\n {\n enum: ['google', 'github', 'kakao', 'naver']\n }\n ).notNull(),\n\n providerUserId: text('provider_user_id').notNull(),\n providerEmail: text('provider_email'),\n\n // OAuth tokens (encrypted in production)\n accessToken: text('access_token'),\n refreshToken: text('refresh_token'),\n tokenExpiresAt: timestamp('token_expires_at', { withTimezone: true }),\n\n ...timestamps(),\n },\n (table) => [\n // Unique constraint: one provider account per provider\n uniqueIndex('provider_user_unique_idx')\n .on(table.provider, table.providerUserId),\n ]\n);\n\n// Type exports\nexport type UserSocialAccount = typeof userSocialAccounts.$inferSelect;\nexport type NewUserSocialAccount = typeof userSocialAccounts.$inferInsert;\nexport type SocialProvider = 'google' | 'github' | 'kakao' | 'naver';","/**\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":";AAMA,SAAS,QAAAA,OAAM,aAAAC,YAAW,mBAAmB;AAC7C,SAAS,MAAAC,KAAI,cAAAC,aAAY,kBAAkB;;;ACO3C,SAAS,QAAAC,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;AA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AAE,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;;;ADhFO,IAAM,qBAAqB,WAAW;AAAA,EAAM;AAAA,EAC/C;AAAA,IACI,IAAIC,IAAG;AAAA;AAAA,IAGP,QAAQ,WAAW,QAAQ,MAAM,MAAM,EAAE;AAAA;AAAA,IAGzC,UAAUC;AAAA,MACN;AAAA,MACA;AAAA,QACI,MAAM,CAAC,UAAU,UAAU,SAAS,OAAO;AAAA,MAC/C;AAAA,IACJ,EAAE,QAAQ;AAAA,IAEV,gBAAgBA,MAAK,kBAAkB,EAAE,QAAQ;AAAA,IACjD,eAAeA,MAAK,gBAAgB;AAAA;AAAA,IAGpC,aAAaA,MAAK,cAAc;AAAA,IAChC,cAAcA,MAAK,eAAe;AAAA,IAClC,gBAAgBC,WAAU,oBAAoB,EAAE,cAAc,KAAK,CAAC;AAAA,IAEpE,GAAGC,YAAW;AAAA,EAClB;AAAA,EACA,CAAC,UAAU;AAAA;AAAA,IAEP,YAAY,0BAA0B,EACjC,GAAG,MAAM,UAAU,MAAM,cAAc;AAAA,EAChD;AACJ;","names":["text","timestamp","id","timestamps","text","boolean","index","id","timestamps","id","text","boolean","timestamps","index","id","text","timestamp","timestamps"]}
|