@spfn/auth 0.2.0-beta.1 → 0.2.0-beta.3

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.
@@ -500,7 +500,7 @@ declare const mainAuthRouter: _spfn_core_route.Router<{
500
500
  id: number;
501
501
  name: string;
502
502
  displayName: string;
503
- category: "custom" | "user" | "auth" | "rbac" | "system" | undefined;
503
+ category: "auth" | "custom" | "user" | "rbac" | "system" | undefined;
504
504
  }[];
505
505
  userId: number;
506
506
  email: string | null;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _spfn_core_nextjs from '@spfn/core/nextjs';
2
- import { R as RoleConfig, P as PermissionConfig, U as UserProfile, C as CheckAccountExistsResult, S as SendVerificationCodeResult, a as RegisterResult, L as LoginResult, b as RotateKeyResult, m as mainAuthRouter } from './dto-81uR9gzF.js';
3
- export { k as AuthInitOptions, A as AuthSession, I as INVITATION_STATUSES, n as InvitationStatus, K as KEY_ALGORITHM, l as KeyAlgorithmType, i as PERMISSION_CATEGORIES, j as PermissionCategory, c as ProfileInfo, e as SOCIAL_PROVIDERS, p as SocialProvider, d as USER_STATUSES, o as UserStatus, h as VERIFICATION_PURPOSES, g as VERIFICATION_TARGET_TYPES, f as VerificationPurpose, V as VerificationTargetType } from './dto-81uR9gzF.js';
2
+ import { R as RoleConfig, P as PermissionConfig, U as UserProfile, C as CheckAccountExistsResult, S as SendVerificationCodeResult, a as RegisterResult, L as LoginResult, b as RotateKeyResult, m as mainAuthRouter } from './dto-CLYtuAom.js';
3
+ export { k as AuthInitOptions, A as AuthSession, I as INVITATION_STATUSES, n as InvitationStatus, K as KEY_ALGORITHM, l as KeyAlgorithmType, i as PERMISSION_CATEGORIES, j as PermissionCategory, c as ProfileInfo, e as SOCIAL_PROVIDERS, p as SocialProvider, d as USER_STATUSES, o as UserStatus, h as VERIFICATION_PURPOSES, g as VERIFICATION_TARGET_TYPES, f as VerificationPurpose, V as VerificationTargetType } from './dto-CLYtuAom.js';
4
4
  import * as _spfn_core_route from '@spfn/core/route';
5
5
  import * as _sinclair_typebox from '@sinclair/typebox';
6
6
  import '@spfn/auth/server';
@@ -260,7 +260,7 @@ declare const authApi: _spfn_core_nextjs.Client<_spfn_core_route.Router<{
260
260
  id: number;
261
261
  name: string;
262
262
  displayName: string;
263
- category: "custom" | "user" | "auth" | "rbac" | "system" | undefined;
263
+ category: "auth" | "custom" | "user" | "rbac" | "system" | undefined;
264
264
  }[];
265
265
  userId: number;
266
266
  email: string | null;
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { k as AuthInitOptions, l as KeyAlgorithmType, n as InvitationStatus, f as VerificationPurpose, j as PermissionCategory, q as AuthContext } from './dto-81uR9gzF.js';
2
- export { B as ChangePasswordParams, w as CheckAccountExistsParams, C as CheckAccountExistsResult, X as EmailSchema, I as INVITATION_STATUSES, K as KEY_ALGORITHM, y as LoginParams, L as LoginResult, z as LogoutParams, Z as PasswordSchema, Y as PhoneSchema, x as RegisterParams, O as RegisterPublicKeyParams, a as RegisterResult, T as RevokeKeyParams, Q as RotateKeyParams, b as RotateKeyResult, e as SOCIAL_PROVIDERS, F as SendVerificationCodeParams, S as SendVerificationCodeResult, p as SocialProvider, _ as TargetTypeSchema, d as USER_STATUSES, o as UserStatus, h as VERIFICATION_PURPOSES, g as VERIFICATION_TARGET_TYPES, $ as VerificationPurposeSchema, V as VerificationTargetType, G as VerifyCodeParams, H as VerifyCodeResult, m as authRouter, W as authenticate, v as changePasswordService, r as checkAccountExistsService, t as loginService, u as logoutService, J as registerPublicKeyService, s as registerService, N as revokeKeyService, M as rotateKeyService, D as sendVerificationCodeService, E as verifyCodeService } from './dto-81uR9gzF.js';
1
+ import { k as AuthInitOptions, l as KeyAlgorithmType, n as InvitationStatus, f as VerificationPurpose, j as PermissionCategory, q as AuthContext } from './dto-CLYtuAom.js';
2
+ export { B as ChangePasswordParams, w as CheckAccountExistsParams, C as CheckAccountExistsResult, X as EmailSchema, I as INVITATION_STATUSES, K as KEY_ALGORITHM, y as LoginParams, L as LoginResult, z as LogoutParams, Z as PasswordSchema, Y as PhoneSchema, x as RegisterParams, O as RegisterPublicKeyParams, a as RegisterResult, T as RevokeKeyParams, Q as RotateKeyParams, b as RotateKeyResult, e as SOCIAL_PROVIDERS, F as SendVerificationCodeParams, S as SendVerificationCodeResult, p as SocialProvider, _ as TargetTypeSchema, d as USER_STATUSES, o as UserStatus, h as VERIFICATION_PURPOSES, g as VERIFICATION_TARGET_TYPES, $ as VerificationPurposeSchema, V as VerificationTargetType, G as VerifyCodeParams, H as VerifyCodeResult, m as authRouter, W as authenticate, v as changePasswordService, r as checkAccountExistsService, t as loginService, u as logoutService, J as registerPublicKeyService, s as registerService, N as revokeKeyService, M as rotateKeyService, D as sendVerificationCodeService, E as verifyCodeService } from './dto-CLYtuAom.js';
3
3
  import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
4
4
  import { UserProfile as UserProfile$1 } from '@spfn/auth';
5
5
  import { BaseRepository } from '@spfn/core/db';
@@ -1242,7 +1242,7 @@ declare function getAuthSessionService(userId: string | number | bigint): Promis
1242
1242
  id: number;
1243
1243
  name: string;
1244
1244
  displayName: string;
1245
- category: "custom" | "user" | "auth" | "rbac" | "system" | undefined;
1245
+ category: "auth" | "custom" | "user" | "rbac" | "system" | undefined;
1246
1246
  }[];
1247
1247
  userId: number;
1248
1248
  email: string | null;
@@ -2694,7 +2694,7 @@ declare const permissions: drizzle_orm_pg_core.PgTableWithColumns<{
2694
2694
  tableName: "permissions";
2695
2695
  dataType: "string";
2696
2696
  columnType: "PgText";
2697
- data: "custom" | "user" | "auth" | "rbac" | "system";
2697
+ data: "auth" | "custom" | "user" | "rbac" | "system";
2698
2698
  driverParam: string;
2699
2699
  notNull: false;
2700
2700
  hasDefault: false;
@@ -3143,13 +3143,13 @@ declare class UsersRepository extends BaseRepository {
3143
3143
  create(data: NewUser): Promise<{
3144
3144
  email: string | null;
3145
3145
  phone: string | null;
3146
- status: "active" | "inactive" | "suspended";
3147
3146
  id: number;
3148
- createdAt: Date;
3149
- updatedAt: Date;
3150
3147
  passwordHash: string | null;
3151
3148
  passwordChangeRequired: boolean;
3152
3149
  roleId: number;
3150
+ createdAt: Date;
3151
+ updatedAt: Date;
3152
+ status: "active" | "inactive" | "suspended";
3153
3153
  emailVerifiedAt: Date | null;
3154
3154
  phoneVerifiedAt: Date | null;
3155
3155
  lastLoginAt: Date | null;
@@ -3215,13 +3215,13 @@ declare class UsersRepository extends BaseRepository {
3215
3215
  deleteById(id: number): Promise<{
3216
3216
  email: string | null;
3217
3217
  phone: string | null;
3218
- status: "active" | "inactive" | "suspended";
3219
3218
  id: number;
3220
- createdAt: Date;
3221
- updatedAt: Date;
3222
3219
  passwordHash: string | null;
3223
3220
  passwordChangeRequired: boolean;
3224
3221
  roleId: number;
3222
+ createdAt: Date;
3223
+ updatedAt: Date;
3224
+ status: "active" | "inactive" | "suspended";
3225
3225
  emailVerifiedAt: Date | null;
3226
3226
  phoneVerifiedAt: Date | null;
3227
3227
  lastLoginAt: Date | null;
@@ -3244,7 +3244,7 @@ declare class UsersRepository extends BaseRepository {
3244
3244
  id: number;
3245
3245
  name: string;
3246
3246
  displayName: string;
3247
- category: "custom" | "user" | "auth" | "rbac" | "system" | undefined;
3247
+ category: "auth" | "custom" | "user" | "rbac" | "system" | undefined;
3248
3248
  }[];
3249
3249
  }>;
3250
3250
  /**
@@ -3354,16 +3354,16 @@ declare class KeysRepository extends BaseRepository {
3354
3354
  * Write primary 사용
3355
3355
  */
3356
3356
  create(data: NewUserPublicKey): Promise<{
3357
- userId: number;
3357
+ publicKey: string;
3358
3358
  keyId: string;
3359
+ fingerprint: string;
3360
+ algorithm: "ES256" | "RS256";
3361
+ userId: number;
3359
3362
  id: number;
3360
3363
  isActive: boolean;
3361
3364
  createdAt: Date;
3362
- publicKey: string;
3363
- algorithm: "ES256" | "RS256";
3364
- fingerprint: string;
3365
- lastUsedAt: Date | null;
3366
3365
  expiresAt: Date | null;
3366
+ lastUsedAt: Date | null;
3367
3367
  revokedAt: Date | null;
3368
3368
  revokedReason: string | null;
3369
3369
  }>;
@@ -3390,16 +3390,16 @@ declare class KeysRepository extends BaseRepository {
3390
3390
  * Write primary 사용
3391
3391
  */
3392
3392
  deleteByKeyIdAndUserId(keyId: string, userId: number): Promise<{
3393
- userId: number;
3393
+ publicKey: string;
3394
3394
  keyId: string;
3395
+ fingerprint: string;
3396
+ algorithm: "ES256" | "RS256";
3397
+ userId: number;
3395
3398
  id: number;
3396
3399
  isActive: boolean;
3397
3400
  createdAt: Date;
3398
- publicKey: string;
3399
- algorithm: "ES256" | "RS256";
3400
- fingerprint: string;
3401
- lastUsedAt: Date | null;
3402
3401
  expiresAt: Date | null;
3402
+ lastUsedAt: Date | null;
3403
3403
  revokedAt: Date | null;
3404
3404
  revokedReason: string | null;
3405
3405
  }>;
@@ -3514,14 +3514,14 @@ declare class VerificationCodesRepository extends BaseRepository {
3514
3514
  * Write primary 사용
3515
3515
  */
3516
3516
  create(data: NewVerificationCode): Promise<{
3517
+ target: string;
3518
+ targetType: "email" | "phone";
3519
+ purpose: "registration" | "login" | "password_reset" | "email_change" | "phone_change";
3520
+ code: string;
3517
3521
  id: number;
3518
3522
  createdAt: Date;
3519
3523
  updatedAt: Date;
3520
3524
  expiresAt: Date;
3521
- target: string;
3522
- targetType: "email" | "phone";
3523
- code: string;
3524
- purpose: "registration" | "login" | "password_reset" | "email_change" | "phone_change";
3525
3525
  usedAt: Date | null;
3526
3526
  attempts: number;
3527
3527
  }>;
@@ -3710,7 +3710,7 @@ declare class PermissionsRepository extends BaseRepository {
3710
3710
  name: string;
3711
3711
  displayName: string;
3712
3712
  description: string | null;
3713
- category: "custom" | "user" | "auth" | "rbac" | "system" | null;
3713
+ category: "auth" | "custom" | "user" | "rbac" | "system" | null;
3714
3714
  isBuiltin: boolean;
3715
3715
  isSystem: boolean;
3716
3716
  isActive: boolean;
@@ -3726,7 +3726,7 @@ declare class PermissionsRepository extends BaseRepository {
3726
3726
  name: string;
3727
3727
  displayName: string;
3728
3728
  description: string | null;
3729
- category: "custom" | "user" | "auth" | "rbac" | "system" | null;
3729
+ category: "auth" | "custom" | "user" | "rbac" | "system" | null;
3730
3730
  isBuiltin: boolean;
3731
3731
  isSystem: boolean;
3732
3732
  isActive: boolean;
@@ -3766,7 +3766,7 @@ declare class PermissionsRepository extends BaseRepository {
3766
3766
  name: string;
3767
3767
  displayName: string;
3768
3768
  description: string | null;
3769
- category: "custom" | "user" | "auth" | "rbac" | "system" | null;
3769
+ category: "auth" | "custom" | "user" | "rbac" | "system" | null;
3770
3770
  isBuiltin: boolean;
3771
3771
  isSystem: boolean;
3772
3772
  isActive: boolean;
@@ -3785,8 +3785,8 @@ declare class PermissionsRepository extends BaseRepository {
3785
3785
  isActive: boolean;
3786
3786
  createdAt: Date;
3787
3787
  updatedAt: Date;
3788
+ category: "auth" | "custom" | "user" | "rbac" | "system" | null;
3788
3789
  metadata: Record<string, any> | null;
3789
- category: "custom" | "user" | "auth" | "rbac" | "system" | null;
3790
3790
  }>;
3791
3791
  }
3792
3792
  declare const permissionsRepository: PermissionsRepository;
@@ -3831,9 +3831,9 @@ declare class RolePermissionsRepository extends BaseRepository {
3831
3831
  */
3832
3832
  createMany(data: NewRolePermission[]): Promise<{
3833
3833
  id: number;
3834
+ roleId: number;
3834
3835
  createdAt: Date;
3835
3836
  updatedAt: Date;
3836
- roleId: number;
3837
3837
  permissionId: number;
3838
3838
  }[]>;
3839
3839
  /**
@@ -3849,9 +3849,9 @@ declare class RolePermissionsRepository extends BaseRepository {
3849
3849
  */
3850
3850
  setPermissionsForRole(roleId: number, permissionIds: number[]): Promise<{
3851
3851
  id: number;
3852
+ roleId: number;
3852
3853
  createdAt: Date;
3853
3854
  updatedAt: Date;
3854
- roleId: number;
3855
3855
  permissionId: number;
3856
3856
  }[]>;
3857
3857
  }
@@ -3916,10 +3916,10 @@ declare class UserPermissionsRepository extends BaseRepository {
3916
3916
  id: number;
3917
3917
  createdAt: Date;
3918
3918
  updatedAt: Date;
3919
- expiresAt: Date | null;
3920
3919
  permissionId: number;
3921
- granted: boolean;
3920
+ expiresAt: Date | null;
3922
3921
  reason: string | null;
3922
+ granted: boolean;
3923
3923
  }>;
3924
3924
  /**
3925
3925
  * 사용자 권한 오버라이드 업데이트
@@ -3942,10 +3942,10 @@ declare class UserPermissionsRepository extends BaseRepository {
3942
3942
  id: number;
3943
3943
  createdAt: Date;
3944
3944
  updatedAt: Date;
3945
- expiresAt: Date | null;
3946
3945
  permissionId: number;
3947
- granted: boolean;
3946
+ expiresAt: Date | null;
3948
3947
  reason: string | null;
3948
+ granted: boolean;
3949
3949
  }>;
3950
3950
  /**
3951
3951
  * 사용자의 모든 권한 오버라이드 삭제
@@ -4024,6 +4024,7 @@ declare class UserProfilesRepository extends BaseRepository {
4024
4024
  displayName: string;
4025
4025
  createdAt: Date;
4026
4026
  updatedAt: Date;
4027
+ metadata: Record<string, any> | null;
4027
4028
  firstName: string | null;
4028
4029
  lastName: string | null;
4029
4030
  avatarUrl: string | null;
@@ -4036,7 +4037,6 @@ declare class UserProfilesRepository extends BaseRepository {
4036
4037
  location: string | null;
4037
4038
  company: string | null;
4038
4039
  jobTitle: string | null;
4039
- metadata: Record<string, any> | null;
4040
4040
  }>;
4041
4041
  /**
4042
4042
  * 프로필 업데이트 (by ID)
@@ -4093,6 +4093,7 @@ declare class UserProfilesRepository extends BaseRepository {
4093
4093
  displayName: string;
4094
4094
  createdAt: Date;
4095
4095
  updatedAt: Date;
4096
+ metadata: Record<string, any> | null;
4096
4097
  firstName: string | null;
4097
4098
  lastName: string | null;
4098
4099
  avatarUrl: string | null;
@@ -4105,7 +4106,6 @@ declare class UserProfilesRepository extends BaseRepository {
4105
4106
  location: string | null;
4106
4107
  company: string | null;
4107
4108
  jobTitle: string | null;
4108
- metadata: Record<string, any> | null;
4109
4109
  }>;
4110
4110
  /**
4111
4111
  * 프로필 삭제 (by User ID)
@@ -4116,6 +4116,7 @@ declare class UserProfilesRepository extends BaseRepository {
4116
4116
  displayName: string;
4117
4117
  createdAt: Date;
4118
4118
  updatedAt: Date;
4119
+ metadata: Record<string, any> | null;
4119
4120
  firstName: string | null;
4120
4121
  lastName: string | null;
4121
4122
  avatarUrl: string | null;
@@ -4128,7 +4129,6 @@ declare class UserProfilesRepository extends BaseRepository {
4128
4129
  location: string | null;
4129
4130
  company: string | null;
4130
4131
  jobTitle: string | null;
4131
- metadata: Record<string, any> | null;
4132
4132
  }>;
4133
4133
  /**
4134
4134
  * User ID로 프로필 데이터 조회 (formatted)
@@ -4255,15 +4255,15 @@ declare class InvitationsRepository extends BaseRepository {
4255
4255
  */
4256
4256
  create(data: NewInvitation): Promise<{
4257
4257
  email: string;
4258
- status: "pending" | "accepted" | "expired" | "cancelled";
4259
4258
  id: number;
4259
+ roleId: number;
4260
4260
  createdAt: Date;
4261
4261
  updatedAt: Date;
4262
- roleId: number;
4262
+ status: "pending" | "accepted" | "expired" | "cancelled";
4263
4263
  metadata: Record<string, any> | null;
4264
- expiresAt: Date;
4265
4264
  token: string;
4266
4265
  invitedBy: number;
4266
+ expiresAt: Date;
4267
4267
  acceptedAt: Date | null;
4268
4268
  cancelledAt: Date | null;
4269
4269
  }>;
@@ -4289,15 +4289,15 @@ declare class InvitationsRepository extends BaseRepository {
4289
4289
  */
4290
4290
  deleteById(id: number): Promise<{
4291
4291
  email: string;
4292
- status: "pending" | "accepted" | "expired" | "cancelled";
4293
4292
  id: number;
4293
+ roleId: number;
4294
4294
  createdAt: Date;
4295
4295
  updatedAt: Date;
4296
- roleId: number;
4296
+ status: "pending" | "accepted" | "expired" | "cancelled";
4297
4297
  metadata: Record<string, any> | null;
4298
- expiresAt: Date;
4299
4298
  token: string;
4300
4299
  invitedBy: number;
4300
+ expiresAt: Date;
4301
4301
  acceptedAt: Date | null;
4302
4302
  cancelledAt: Date | null;
4303
4303
  }>;
@@ -4757,13 +4757,13 @@ declare function getUser(c: Context | {
4757
4757
  }): {
4758
4758
  email: string | null;
4759
4759
  phone: string | null;
4760
- status: "active" | "inactive" | "suspended";
4761
4760
  id: number;
4762
- createdAt: Date;
4763
- updatedAt: Date;
4764
4761
  passwordHash: string | null;
4765
4762
  passwordChangeRequired: boolean;
4766
4763
  roleId: number;
4764
+ createdAt: Date;
4765
+ updatedAt: Date;
4766
+ status: "active" | "inactive" | "suspended";
4767
4767
  emailVerifiedAt: Date | null;
4768
4768
  phoneVerifiedAt: Date | null;
4769
4769
  lastLoginAt: Date | null;
@@ -0,0 +1,292 @@
1
+ CREATE SCHEMA IF NOT EXISTS "spfn_auth";
2
+ --> statement-breakpoint
3
+ CREATE TABLE IF NOT EXISTS "spfn_auth"."users" (
4
+ "id" bigserial PRIMARY KEY NOT NULL,
5
+ "email" text,
6
+ "phone" text,
7
+ "password_hash" text,
8
+ "password_change_required" boolean DEFAULT false NOT NULL,
9
+ "role_id" bigserial NOT NULL,
10
+ "status" text DEFAULT 'active' NOT NULL,
11
+ "email_verified_at" timestamp with time zone,
12
+ "phone_verified_at" timestamp with time zone,
13
+ "last_login_at" timestamp with time zone,
14
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
15
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
16
+ CONSTRAINT "users_email_unique" UNIQUE("email"),
17
+ CONSTRAINT "users_phone_unique" UNIQUE("phone"),
18
+ CONSTRAINT "email_or_phone_check" CHECK ("spfn_auth"."users"."email" IS NOT NULL OR "spfn_auth"."users"."phone" IS NOT NULL)
19
+ );
20
+ --> statement-breakpoint
21
+ CREATE TABLE IF NOT EXISTS "spfn_auth"."user_profiles" (
22
+ "id" bigserial PRIMARY KEY NOT NULL,
23
+ "user_id" bigserial NOT NULL,
24
+ "display_name" text NOT NULL,
25
+ "first_name" text,
26
+ "last_name" text,
27
+ "avatar_url" text,
28
+ "bio" text,
29
+ "locale" text DEFAULT 'en',
30
+ "timezone" text DEFAULT 'UTC',
31
+ "date_of_birth" text,
32
+ "gender" text,
33
+ "website" text,
34
+ "location" text,
35
+ "company" text,
36
+ "job_title" text,
37
+ "metadata" jsonb,
38
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
39
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
40
+ CONSTRAINT "user_profiles_user_id_unique" UNIQUE("user_id")
41
+ );
42
+ --> statement-breakpoint
43
+ CREATE TABLE IF NOT EXISTS "spfn_auth"."user_public_keys" (
44
+ "id" bigserial PRIMARY KEY NOT NULL,
45
+ "user_id" bigserial NOT NULL,
46
+ "key_id" text NOT NULL,
47
+ "public_key" text NOT NULL,
48
+ "algorithm" text DEFAULT 'ES256' NOT NULL,
49
+ "fingerprint" text NOT NULL,
50
+ "is_active" boolean DEFAULT true NOT NULL,
51
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
52
+ "last_used_at" timestamp with time zone,
53
+ "expires_at" timestamp with time zone,
54
+ "revoked_at" timestamp with time zone,
55
+ "revoked_reason" text,
56
+ CONSTRAINT "user_public_keys_key_id_unique" UNIQUE("key_id")
57
+ );
58
+ --> statement-breakpoint
59
+ CREATE TABLE IF NOT EXISTS "spfn_auth"."user_social_accounts" (
60
+ "id" bigserial PRIMARY KEY NOT NULL,
61
+ "user_id" bigserial NOT NULL,
62
+ "provider" text NOT NULL,
63
+ "provider_user_id" text NOT NULL,
64
+ "provider_email" text,
65
+ "access_token" text,
66
+ "refresh_token" text,
67
+ "token_expires_at" timestamp with time zone,
68
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
69
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
70
+ );
71
+ --> statement-breakpoint
72
+ CREATE TABLE IF NOT EXISTS "spfn_auth"."verification_codes" (
73
+ "id" bigserial PRIMARY KEY NOT NULL,
74
+ "target" text NOT NULL,
75
+ "target_type" text NOT NULL,
76
+ "code" text NOT NULL,
77
+ "purpose" text NOT NULL,
78
+ "expires_at" timestamp with time zone NOT NULL,
79
+ "used_at" timestamp with time zone,
80
+ "attempts" integer DEFAULT 0 NOT NULL,
81
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
82
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
83
+ CONSTRAINT "attempts_limit_check" CHECK ("spfn_auth"."verification_codes"."attempts" >= 0 AND "spfn_auth"."verification_codes"."attempts" <= 10)
84
+ );
85
+ --> statement-breakpoint
86
+ CREATE TABLE IF NOT EXISTS "spfn_auth"."user_invitations" (
87
+ "id" bigserial PRIMARY KEY NOT NULL,
88
+ "email" text NOT NULL,
89
+ "token" text NOT NULL,
90
+ "role_id" bigserial NOT NULL,
91
+ "invited_by_id" bigserial NOT NULL,
92
+ "status" text DEFAULT 'pending' NOT NULL,
93
+ "expires_at" timestamp with time zone NOT NULL,
94
+ "accepted_at" timestamp with time zone,
95
+ "cancelled_at" timestamp with time zone,
96
+ "metadata" jsonb,
97
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
98
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
99
+ CONSTRAINT "user_invitations_token_unique" UNIQUE("token")
100
+ );
101
+ --> statement-breakpoint
102
+ CREATE TABLE IF NOT EXISTS "spfn_auth"."roles" (
103
+ "id" bigserial PRIMARY KEY NOT NULL,
104
+ "name" text NOT NULL,
105
+ "display_name" text NOT NULL,
106
+ "description" text,
107
+ "is_builtin" boolean DEFAULT false NOT NULL,
108
+ "is_system" boolean DEFAULT false NOT NULL,
109
+ "is_active" boolean DEFAULT true NOT NULL,
110
+ "priority" integer DEFAULT 10 NOT NULL,
111
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
112
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
113
+ CONSTRAINT "roles_name_unique" UNIQUE("name")
114
+ );
115
+ --> statement-breakpoint
116
+ CREATE TABLE IF NOT EXISTS "spfn_auth"."permissions" (
117
+ "id" bigserial PRIMARY KEY NOT NULL,
118
+ "name" text NOT NULL,
119
+ "display_name" text NOT NULL,
120
+ "description" text,
121
+ "category" text,
122
+ "is_builtin" boolean DEFAULT false NOT NULL,
123
+ "is_system" boolean DEFAULT false NOT NULL,
124
+ "is_active" boolean DEFAULT true NOT NULL,
125
+ "metadata" jsonb,
126
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
127
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
128
+ CONSTRAINT "permissions_name_unique" UNIQUE("name")
129
+ );
130
+ --> statement-breakpoint
131
+ CREATE TABLE IF NOT EXISTS "spfn_auth"."role_permissions" (
132
+ "id" bigserial PRIMARY KEY NOT NULL,
133
+ "role_id" bigserial NOT NULL,
134
+ "permission_id" bigserial NOT NULL,
135
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
136
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
137
+ CONSTRAINT "role_permissions_unique" UNIQUE("role_id","permission_id")
138
+ );
139
+ --> statement-breakpoint
140
+ CREATE TABLE IF NOT EXISTS "spfn_auth"."user_permissions" (
141
+ "id" bigserial PRIMARY KEY NOT NULL,
142
+ "user_id" bigserial NOT NULL,
143
+ "permission_id" bigserial NOT NULL,
144
+ "granted" boolean DEFAULT true NOT NULL,
145
+ "reason" text,
146
+ "expires_at" timestamp with time zone,
147
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
148
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
149
+ CONSTRAINT "user_permissions_unique" UNIQUE("user_id","permission_id")
150
+ );
151
+ --> statement-breakpoint
152
+ DO $$
153
+ BEGIN
154
+ IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'users_role_id_roles_id_fk') THEN
155
+ ALTER TABLE "spfn_auth"."users" ADD CONSTRAINT "users_role_id_roles_id_fk" FOREIGN KEY ("role_id") REFERENCES "spfn_auth"."roles"("id") ON DELETE cascade ON UPDATE no action;
156
+ END IF;
157
+ END $$;
158
+ --> statement-breakpoint
159
+ DO $$
160
+ BEGIN
161
+ IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'user_profiles_user_id_users_id_fk') THEN
162
+ ALTER TABLE "spfn_auth"."user_profiles" ADD CONSTRAINT "user_profiles_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "spfn_auth"."users"("id") ON DELETE cascade ON UPDATE no action;
163
+ END IF;
164
+ END $$;
165
+ --> statement-breakpoint
166
+ DO $$
167
+ BEGIN
168
+ IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'user_public_keys_user_id_users_id_fk') THEN
169
+ ALTER TABLE "spfn_auth"."user_public_keys" ADD CONSTRAINT "user_public_keys_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "spfn_auth"."users"("id") ON DELETE cascade ON UPDATE no action;
170
+ END IF;
171
+ END $$;
172
+ --> statement-breakpoint
173
+ DO $$
174
+ BEGIN
175
+ IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'user_social_accounts_user_id_users_id_fk') THEN
176
+ ALTER TABLE "spfn_auth"."user_social_accounts" ADD CONSTRAINT "user_social_accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "spfn_auth"."users"("id") ON DELETE cascade ON UPDATE no action;
177
+ END IF;
178
+ END $$;
179
+ --> statement-breakpoint
180
+ DO $$
181
+ BEGIN
182
+ IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'user_invitations_role_id_roles_id_fk') THEN
183
+ ALTER TABLE "spfn_auth"."user_invitations" ADD CONSTRAINT "user_invitations_role_id_roles_id_fk" FOREIGN KEY ("role_id") REFERENCES "spfn_auth"."roles"("id") ON DELETE cascade ON UPDATE no action;
184
+ END IF;
185
+ END $$;
186
+ --> statement-breakpoint
187
+ DO $$
188
+ BEGIN
189
+ IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'user_invitations_invited_by_id_users_id_fk') THEN
190
+ ALTER TABLE "spfn_auth"."user_invitations" ADD CONSTRAINT "user_invitations_invited_by_id_users_id_fk" FOREIGN KEY ("invited_by_id") REFERENCES "spfn_auth"."users"("id") ON DELETE cascade ON UPDATE no action;
191
+ END IF;
192
+ END $$;
193
+ --> statement-breakpoint
194
+ DO $$
195
+ BEGIN
196
+ IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'role_permissions_role_id_roles_id_fk') THEN
197
+ ALTER TABLE "spfn_auth"."role_permissions" ADD CONSTRAINT "role_permissions_role_id_roles_id_fk" FOREIGN KEY ("role_id") REFERENCES "spfn_auth"."roles"("id") ON DELETE cascade ON UPDATE no action;
198
+ END IF;
199
+ END $$;
200
+ --> statement-breakpoint
201
+ DO $$
202
+ BEGIN
203
+ IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'role_permissions_permission_id_permissions_id_fk') THEN
204
+ ALTER TABLE "spfn_auth"."role_permissions" ADD CONSTRAINT "role_permissions_permission_id_permissions_id_fk" FOREIGN KEY ("permission_id") REFERENCES "spfn_auth"."permissions"("id") ON DELETE cascade ON UPDATE no action;
205
+ END IF;
206
+ END $$;
207
+ --> statement-breakpoint
208
+ DO $$
209
+ BEGIN
210
+ IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'user_permissions_user_id_users_id_fk') THEN
211
+ ALTER TABLE "spfn_auth"."user_permissions" ADD CONSTRAINT "user_permissions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "spfn_auth"."users"("id") ON DELETE cascade ON UPDATE no action;
212
+ END IF;
213
+ END $$;
214
+ --> statement-breakpoint
215
+ DO $$
216
+ BEGIN
217
+ IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'user_permissions_permission_id_permissions_id_fk') THEN
218
+ ALTER TABLE "spfn_auth"."user_permissions" ADD CONSTRAINT "user_permissions_permission_id_permissions_id_fk" FOREIGN KEY ("permission_id") REFERENCES "spfn_auth"."permissions"("id") ON DELETE cascade ON UPDATE no action;
219
+ END IF;
220
+ END $$;
221
+ --> statement-breakpoint
222
+ CREATE INDEX IF NOT EXISTS "users_email_idx" ON "spfn_auth"."users" USING btree ("email");
223
+ --> statement-breakpoint
224
+ CREATE INDEX IF NOT EXISTS "users_phone_idx" ON "spfn_auth"."users" USING btree ("phone");
225
+ --> statement-breakpoint
226
+ CREATE INDEX IF NOT EXISTS "users_status_idx" ON "spfn_auth"."users" USING btree ("status");
227
+ --> statement-breakpoint
228
+ CREATE INDEX IF NOT EXISTS "users_role_id_idx" ON "spfn_auth"."users" USING btree ("role_id");
229
+ --> statement-breakpoint
230
+ CREATE INDEX IF NOT EXISTS "user_profiles_user_id_idx" ON "spfn_auth"."user_profiles" USING btree ("user_id");
231
+ --> statement-breakpoint
232
+ CREATE INDEX IF NOT EXISTS "user_profiles_display_name_idx" ON "spfn_auth"."user_profiles" USING btree ("display_name");
233
+ --> statement-breakpoint
234
+ CREATE INDEX IF NOT EXISTS "user_profiles_locale_idx" ON "spfn_auth"."user_profiles" USING btree ("locale");
235
+ --> statement-breakpoint
236
+ CREATE INDEX IF NOT EXISTS "user_public_keys_user_id_idx" ON "spfn_auth"."user_public_keys" USING btree ("user_id");
237
+ --> statement-breakpoint
238
+ CREATE INDEX IF NOT EXISTS "user_public_keys_key_id_idx" ON "spfn_auth"."user_public_keys" USING btree ("key_id");
239
+ --> statement-breakpoint
240
+ CREATE INDEX IF NOT EXISTS "user_public_keys_active_idx" ON "spfn_auth"."user_public_keys" USING btree ("is_active");
241
+ --> statement-breakpoint
242
+ CREATE INDEX IF NOT EXISTS "user_public_keys_fingerprint_idx" ON "spfn_auth"."user_public_keys" USING btree ("fingerprint");
243
+ --> statement-breakpoint
244
+ CREATE INDEX IF NOT EXISTS "user_social_accounts_user_id_idx" ON "spfn_auth"."user_social_accounts" USING btree ("user_id");
245
+ --> statement-breakpoint
246
+ CREATE INDEX IF NOT EXISTS "user_social_accounts_provider_idx" ON "spfn_auth"."user_social_accounts" USING btree ("provider");
247
+ --> statement-breakpoint
248
+ CREATE UNIQUE INDEX IF NOT EXISTS "provider_user_unique_idx" ON "spfn_auth"."user_social_accounts" USING btree ("provider","provider_user_id");
249
+ --> statement-breakpoint
250
+ CREATE INDEX IF NOT EXISTS "target_purpose_idx" ON "spfn_auth"."verification_codes" USING btree ("target","purpose","expires_at");
251
+ --> statement-breakpoint
252
+ CREATE INDEX IF NOT EXISTS "invitations_token_idx" ON "spfn_auth"."user_invitations" USING btree ("token");
253
+ --> statement-breakpoint
254
+ CREATE INDEX IF NOT EXISTS "invitations_email_idx" ON "spfn_auth"."user_invitations" USING btree ("email");
255
+ --> statement-breakpoint
256
+ CREATE INDEX IF NOT EXISTS "invitations_status_idx" ON "spfn_auth"."user_invitations" USING btree ("status");
257
+ --> statement-breakpoint
258
+ CREATE INDEX IF NOT EXISTS "invitations_invited_by_idx" ON "spfn_auth"."user_invitations" USING btree ("invited_by_id");
259
+ --> statement-breakpoint
260
+ CREATE INDEX IF NOT EXISTS "invitations_expires_at_idx" ON "spfn_auth"."user_invitations" USING btree ("expires_at");
261
+ --> statement-breakpoint
262
+ CREATE INDEX IF NOT EXISTS "invitations_role_id_idx" ON "spfn_auth"."user_invitations" USING btree ("role_id");
263
+ --> statement-breakpoint
264
+ CREATE INDEX IF NOT EXISTS "roles_name_idx" ON "spfn_auth"."roles" USING btree ("name");
265
+ --> statement-breakpoint
266
+ CREATE INDEX IF NOT EXISTS "roles_is_system_idx" ON "spfn_auth"."roles" USING btree ("is_system");
267
+ --> statement-breakpoint
268
+ CREATE INDEX IF NOT EXISTS "roles_is_active_idx" ON "spfn_auth"."roles" USING btree ("is_active");
269
+ --> statement-breakpoint
270
+ CREATE INDEX IF NOT EXISTS "roles_is_builtin_idx" ON "spfn_auth"."roles" USING btree ("is_builtin");
271
+ --> statement-breakpoint
272
+ CREATE INDEX IF NOT EXISTS "roles_priority_idx" ON "spfn_auth"."roles" USING btree ("priority");
273
+ --> statement-breakpoint
274
+ CREATE INDEX IF NOT EXISTS "permissions_name_idx" ON "spfn_auth"."permissions" USING btree ("name");
275
+ --> statement-breakpoint
276
+ CREATE INDEX IF NOT EXISTS "permissions_category_idx" ON "spfn_auth"."permissions" USING btree ("category");
277
+ --> statement-breakpoint
278
+ CREATE INDEX IF NOT EXISTS "permissions_is_system_idx" ON "spfn_auth"."permissions" USING btree ("is_system");
279
+ --> statement-breakpoint
280
+ CREATE INDEX IF NOT EXISTS "permissions_is_active_idx" ON "spfn_auth"."permissions" USING btree ("is_active");
281
+ --> statement-breakpoint
282
+ CREATE INDEX IF NOT EXISTS "permissions_is_builtin_idx" ON "spfn_auth"."permissions" USING btree ("is_builtin");
283
+ --> statement-breakpoint
284
+ CREATE INDEX IF NOT EXISTS "role_permissions_role_id_idx" ON "spfn_auth"."role_permissions" USING btree ("role_id");
285
+ --> statement-breakpoint
286
+ CREATE INDEX IF NOT EXISTS "role_permissions_permission_id_idx" ON "spfn_auth"."role_permissions" USING btree ("permission_id");
287
+ --> statement-breakpoint
288
+ CREATE INDEX IF NOT EXISTS "user_permissions_user_id_idx" ON "spfn_auth"."user_permissions" USING btree ("user_id");
289
+ --> statement-breakpoint
290
+ CREATE INDEX IF NOT EXISTS "user_permissions_permission_id_idx" ON "spfn_auth"."user_permissions" USING btree ("permission_id");
291
+ --> statement-breakpoint
292
+ CREATE INDEX IF NOT EXISTS "user_permissions_expires_at_idx" ON "spfn_auth"."user_permissions" USING btree ("expires_at");
@@ -1,5 +1,5 @@
1
1
  {
2
- "id": "7dedce95-7ceb-4691-aaad-0989041d8828",
2
+ "id": "e610afd0-f072-4f82-92cd-2bb8c156f284",
3
3
  "prevId": "00000000-0000-0000-0000-000000000000",
4
4
  "version": "7",
5
5
  "dialect": "postgresql",
@@ -5,8 +5,8 @@
5
5
  {
6
6
  "idx": 0,
7
7
  "version": "7",
8
- "when": 1765167910869,
9
- "tag": "0000_mysterious_colossus",
8
+ "when": 1764036749408,
9
+ "tag": "0000_premium_famine",
10
10
  "breakpoints": true
11
11
  }
12
12
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spfn/auth",
3
- "version": "0.2.0-beta.1",
3
+ "version": "0.2.0-beta.3",
4
4
  "type": "module",
5
5
  "description": "Authentication, authorization, and RBAC module for SPFN",
6
6
  "main": "./dist/index.js",
@@ -112,11 +112,11 @@
112
112
  }
113
113
  },
114
114
  "scripts": {
115
- "build": "pnpm check:circular && npm run db:generate && tsup",
115
+ "build": "pnpm check:circular && tsup",
116
116
  "watch": "tsup --watch",
117
117
  "dev": "tsup --watch",
118
118
  "type-check": "tsc --noEmit",
119
- "clean": "rm -rf dist migrations",
119
+ "clean": "rm -rf dist",
120
120
  "db:generate": "drizzle-kit generate",
121
121
  "codegen": "spfn codegen run",
122
122
  "test": "vitest run",
@@ -1,197 +0,0 @@
1
- CREATE SCHEMA "spfn_auth";
2
- --> statement-breakpoint
3
- CREATE TABLE "spfn_auth"."users" (
4
- "id" bigserial PRIMARY KEY NOT NULL,
5
- "email" text,
6
- "phone" text,
7
- "password_hash" text,
8
- "password_change_required" boolean DEFAULT false NOT NULL,
9
- "role_id" bigserial NOT NULL,
10
- "status" text DEFAULT 'active' NOT NULL,
11
- "email_verified_at" timestamp with time zone,
12
- "phone_verified_at" timestamp with time zone,
13
- "last_login_at" timestamp with time zone,
14
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
15
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
16
- CONSTRAINT "users_email_unique" UNIQUE("email"),
17
- CONSTRAINT "users_phone_unique" UNIQUE("phone"),
18
- CONSTRAINT "email_or_phone_check" CHECK ("spfn_auth"."users"."email" IS NOT NULL OR "spfn_auth"."users"."phone" IS NOT NULL)
19
- );
20
- --> statement-breakpoint
21
- CREATE TABLE "spfn_auth"."user_profiles" (
22
- "id" bigserial PRIMARY KEY NOT NULL,
23
- "user_id" bigserial NOT NULL,
24
- "display_name" text NOT NULL,
25
- "first_name" text,
26
- "last_name" text,
27
- "avatar_url" text,
28
- "bio" text,
29
- "locale" text DEFAULT 'en',
30
- "timezone" text DEFAULT 'UTC',
31
- "date_of_birth" text,
32
- "gender" text,
33
- "website" text,
34
- "location" text,
35
- "company" text,
36
- "job_title" text,
37
- "metadata" jsonb,
38
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
39
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
40
- CONSTRAINT "user_profiles_user_id_unique" UNIQUE("user_id")
41
- );
42
- --> statement-breakpoint
43
- CREATE TABLE "spfn_auth"."user_public_keys" (
44
- "id" bigserial PRIMARY KEY NOT NULL,
45
- "user_id" bigserial NOT NULL,
46
- "key_id" text NOT NULL,
47
- "public_key" text NOT NULL,
48
- "algorithm" text DEFAULT 'ES256' NOT NULL,
49
- "fingerprint" text NOT NULL,
50
- "is_active" boolean DEFAULT true NOT NULL,
51
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
52
- "last_used_at" timestamp with time zone,
53
- "expires_at" timestamp with time zone,
54
- "revoked_at" timestamp with time zone,
55
- "revoked_reason" text,
56
- CONSTRAINT "user_public_keys_key_id_unique" UNIQUE("key_id")
57
- );
58
- --> statement-breakpoint
59
- CREATE TABLE "spfn_auth"."user_social_accounts" (
60
- "id" bigserial PRIMARY KEY NOT NULL,
61
- "user_id" bigserial NOT NULL,
62
- "provider" text NOT NULL,
63
- "provider_user_id" text NOT NULL,
64
- "provider_email" text,
65
- "access_token" text,
66
- "refresh_token" text,
67
- "token_expires_at" timestamp with time zone,
68
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
69
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
70
- );
71
- --> statement-breakpoint
72
- CREATE TABLE "spfn_auth"."verification_codes" (
73
- "id" bigserial PRIMARY KEY NOT NULL,
74
- "target" text NOT NULL,
75
- "target_type" text NOT NULL,
76
- "code" text NOT NULL,
77
- "purpose" text NOT NULL,
78
- "expires_at" timestamp with time zone NOT NULL,
79
- "used_at" timestamp with time zone,
80
- "attempts" integer DEFAULT 0 NOT NULL,
81
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
82
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
83
- CONSTRAINT "attempts_limit_check" CHECK ("spfn_auth"."verification_codes"."attempts" >= 0 AND "spfn_auth"."verification_codes"."attempts" <= 10)
84
- );
85
- --> statement-breakpoint
86
- CREATE TABLE "spfn_auth"."user_invitations" (
87
- "id" bigserial PRIMARY KEY NOT NULL,
88
- "email" text NOT NULL,
89
- "token" text NOT NULL,
90
- "role_id" bigserial NOT NULL,
91
- "invited_by_id" bigserial NOT NULL,
92
- "status" text DEFAULT 'pending' NOT NULL,
93
- "expires_at" timestamp with time zone NOT NULL,
94
- "accepted_at" timestamp with time zone,
95
- "cancelled_at" timestamp with time zone,
96
- "metadata" jsonb,
97
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
98
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
99
- CONSTRAINT "user_invitations_token_unique" UNIQUE("token")
100
- );
101
- --> statement-breakpoint
102
- CREATE TABLE "spfn_auth"."roles" (
103
- "id" bigserial PRIMARY KEY NOT NULL,
104
- "name" text NOT NULL,
105
- "display_name" text NOT NULL,
106
- "description" text,
107
- "is_builtin" boolean DEFAULT false NOT NULL,
108
- "is_system" boolean DEFAULT false NOT NULL,
109
- "is_active" boolean DEFAULT true NOT NULL,
110
- "priority" integer DEFAULT 10 NOT NULL,
111
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
112
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
113
- CONSTRAINT "roles_name_unique" UNIQUE("name")
114
- );
115
- --> statement-breakpoint
116
- CREATE TABLE "spfn_auth"."permissions" (
117
- "id" bigserial PRIMARY KEY NOT NULL,
118
- "name" text NOT NULL,
119
- "display_name" text NOT NULL,
120
- "description" text,
121
- "category" text,
122
- "is_builtin" boolean DEFAULT false NOT NULL,
123
- "is_system" boolean DEFAULT false NOT NULL,
124
- "is_active" boolean DEFAULT true NOT NULL,
125
- "metadata" jsonb,
126
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
127
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
128
- CONSTRAINT "permissions_name_unique" UNIQUE("name")
129
- );
130
- --> statement-breakpoint
131
- CREATE TABLE "spfn_auth"."role_permissions" (
132
- "id" bigserial PRIMARY KEY NOT NULL,
133
- "role_id" bigserial NOT NULL,
134
- "permission_id" bigserial NOT NULL,
135
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
136
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
137
- CONSTRAINT "role_permissions_unique" UNIQUE("role_id","permission_id")
138
- );
139
- --> statement-breakpoint
140
- CREATE TABLE "spfn_auth"."user_permissions" (
141
- "id" bigserial PRIMARY KEY NOT NULL,
142
- "user_id" bigserial NOT NULL,
143
- "permission_id" bigserial NOT NULL,
144
- "granted" boolean DEFAULT true NOT NULL,
145
- "reason" text,
146
- "expires_at" timestamp with time zone,
147
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
148
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
149
- CONSTRAINT "user_permissions_unique" UNIQUE("user_id","permission_id")
150
- );
151
- --> statement-breakpoint
152
- ALTER TABLE "spfn_auth"."users" ADD CONSTRAINT "users_role_id_roles_id_fk" FOREIGN KEY ("role_id") REFERENCES "spfn_auth"."roles"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
153
- ALTER TABLE "spfn_auth"."user_profiles" ADD CONSTRAINT "user_profiles_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "spfn_auth"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
154
- ALTER TABLE "spfn_auth"."user_public_keys" ADD CONSTRAINT "user_public_keys_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "spfn_auth"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
155
- ALTER TABLE "spfn_auth"."user_social_accounts" ADD CONSTRAINT "user_social_accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "spfn_auth"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
156
- ALTER TABLE "spfn_auth"."user_invitations" ADD CONSTRAINT "user_invitations_role_id_roles_id_fk" FOREIGN KEY ("role_id") REFERENCES "spfn_auth"."roles"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
157
- ALTER TABLE "spfn_auth"."user_invitations" ADD CONSTRAINT "user_invitations_invited_by_id_users_id_fk" FOREIGN KEY ("invited_by_id") REFERENCES "spfn_auth"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
158
- ALTER TABLE "spfn_auth"."role_permissions" ADD CONSTRAINT "role_permissions_role_id_roles_id_fk" FOREIGN KEY ("role_id") REFERENCES "spfn_auth"."roles"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
159
- ALTER TABLE "spfn_auth"."role_permissions" ADD CONSTRAINT "role_permissions_permission_id_permissions_id_fk" FOREIGN KEY ("permission_id") REFERENCES "spfn_auth"."permissions"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
160
- ALTER TABLE "spfn_auth"."user_permissions" ADD CONSTRAINT "user_permissions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "spfn_auth"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
161
- ALTER TABLE "spfn_auth"."user_permissions" ADD CONSTRAINT "user_permissions_permission_id_permissions_id_fk" FOREIGN KEY ("permission_id") REFERENCES "spfn_auth"."permissions"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
162
- CREATE INDEX "users_email_idx" ON "spfn_auth"."users" USING btree ("email");--> statement-breakpoint
163
- CREATE INDEX "users_phone_idx" ON "spfn_auth"."users" USING btree ("phone");--> statement-breakpoint
164
- CREATE INDEX "users_status_idx" ON "spfn_auth"."users" USING btree ("status");--> statement-breakpoint
165
- CREATE INDEX "users_role_id_idx" ON "spfn_auth"."users" USING btree ("role_id");--> statement-breakpoint
166
- CREATE INDEX "user_profiles_user_id_idx" ON "spfn_auth"."user_profiles" USING btree ("user_id");--> statement-breakpoint
167
- CREATE INDEX "user_profiles_display_name_idx" ON "spfn_auth"."user_profiles" USING btree ("display_name");--> statement-breakpoint
168
- CREATE INDEX "user_profiles_locale_idx" ON "spfn_auth"."user_profiles" USING btree ("locale");--> statement-breakpoint
169
- CREATE INDEX "user_public_keys_user_id_idx" ON "spfn_auth"."user_public_keys" USING btree ("user_id");--> statement-breakpoint
170
- CREATE INDEX "user_public_keys_key_id_idx" ON "spfn_auth"."user_public_keys" USING btree ("key_id");--> statement-breakpoint
171
- CREATE INDEX "user_public_keys_active_idx" ON "spfn_auth"."user_public_keys" USING btree ("is_active");--> statement-breakpoint
172
- CREATE INDEX "user_public_keys_fingerprint_idx" ON "spfn_auth"."user_public_keys" USING btree ("fingerprint");--> statement-breakpoint
173
- CREATE INDEX "user_social_accounts_user_id_idx" ON "spfn_auth"."user_social_accounts" USING btree ("user_id");--> statement-breakpoint
174
- CREATE INDEX "user_social_accounts_provider_idx" ON "spfn_auth"."user_social_accounts" USING btree ("provider");--> statement-breakpoint
175
- CREATE UNIQUE INDEX "provider_user_unique_idx" ON "spfn_auth"."user_social_accounts" USING btree ("provider","provider_user_id");--> statement-breakpoint
176
- CREATE INDEX "target_purpose_idx" ON "spfn_auth"."verification_codes" USING btree ("target","purpose","expires_at");--> statement-breakpoint
177
- CREATE INDEX "invitations_token_idx" ON "spfn_auth"."user_invitations" USING btree ("token");--> statement-breakpoint
178
- CREATE INDEX "invitations_email_idx" ON "spfn_auth"."user_invitations" USING btree ("email");--> statement-breakpoint
179
- CREATE INDEX "invitations_status_idx" ON "spfn_auth"."user_invitations" USING btree ("status");--> statement-breakpoint
180
- CREATE INDEX "invitations_invited_by_idx" ON "spfn_auth"."user_invitations" USING btree ("invited_by_id");--> statement-breakpoint
181
- CREATE INDEX "invitations_expires_at_idx" ON "spfn_auth"."user_invitations" USING btree ("expires_at");--> statement-breakpoint
182
- CREATE INDEX "invitations_role_id_idx" ON "spfn_auth"."user_invitations" USING btree ("role_id");--> statement-breakpoint
183
- CREATE INDEX "roles_name_idx" ON "spfn_auth"."roles" USING btree ("name");--> statement-breakpoint
184
- CREATE INDEX "roles_is_system_idx" ON "spfn_auth"."roles" USING btree ("is_system");--> statement-breakpoint
185
- CREATE INDEX "roles_is_active_idx" ON "spfn_auth"."roles" USING btree ("is_active");--> statement-breakpoint
186
- CREATE INDEX "roles_is_builtin_idx" ON "spfn_auth"."roles" USING btree ("is_builtin");--> statement-breakpoint
187
- CREATE INDEX "roles_priority_idx" ON "spfn_auth"."roles" USING btree ("priority");--> statement-breakpoint
188
- CREATE INDEX "permissions_name_idx" ON "spfn_auth"."permissions" USING btree ("name");--> statement-breakpoint
189
- CREATE INDEX "permissions_category_idx" ON "spfn_auth"."permissions" USING btree ("category");--> statement-breakpoint
190
- CREATE INDEX "permissions_is_system_idx" ON "spfn_auth"."permissions" USING btree ("is_system");--> statement-breakpoint
191
- CREATE INDEX "permissions_is_active_idx" ON "spfn_auth"."permissions" USING btree ("is_active");--> statement-breakpoint
192
- CREATE INDEX "permissions_is_builtin_idx" ON "spfn_auth"."permissions" USING btree ("is_builtin");--> statement-breakpoint
193
- CREATE INDEX "role_permissions_role_id_idx" ON "spfn_auth"."role_permissions" USING btree ("role_id");--> statement-breakpoint
194
- CREATE INDEX "role_permissions_permission_id_idx" ON "spfn_auth"."role_permissions" USING btree ("permission_id");--> statement-breakpoint
195
- CREATE INDEX "user_permissions_user_id_idx" ON "spfn_auth"."user_permissions" USING btree ("user_id");--> statement-breakpoint
196
- CREATE INDEX "user_permissions_permission_id_idx" ON "spfn_auth"."user_permissions" USING btree ("permission_id");--> statement-breakpoint
197
- CREATE INDEX "user_permissions_expires_at_idx" ON "spfn_auth"."user_permissions" USING btree ("expires_at");