@spfn/auth 0.2.0-beta.40 → 0.2.0-beta.41

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.
@@ -545,7 +545,7 @@ declare const mainAuthRouter: _spfn_core_route.Router<{
545
545
  id: number;
546
546
  name: string;
547
547
  displayName: string;
548
- category: "auth" | "custom" | "user" | "rbac" | "system" | undefined;
548
+ category: "custom" | "user" | "auth" | "rbac" | "system" | undefined;
549
549
  }[];
550
550
  userId: number;
551
551
  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, C as CheckAccountExistsResult, S as SendVerificationCodeResult, a as RegisterResult, L as LoginResult, b as RotateKeyResult, O as OAuthStartResult, U as UserProfile, c as ProfileInfo, m as mainAuthRouter } from './authenticate-BbugF32w.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, 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 './authenticate-BbugF32w.js';
2
+ import { R as RoleConfig, P as PermissionConfig, C as CheckAccountExistsResult, S as SendVerificationCodeResult, a as RegisterResult, L as LoginResult, b as RotateKeyResult, O as OAuthStartResult, U as UserProfile, c as ProfileInfo, m as mainAuthRouter } from './authenticate-2953PCm8.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, 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 './authenticate-2953PCm8.js';
4
4
  import * as _spfn_core_route from '@spfn/core/route';
5
5
  import { HttpMethod } from '@spfn/core/route';
6
6
  import * as _sinclair_typebox from '@sinclair/typebox';
@@ -169,7 +169,7 @@ declare const authApi: _spfn_core_nextjs.Client<_spfn_core_route.Router<{
169
169
  id: number;
170
170
  name: string;
171
171
  displayName: string;
172
- category: "auth" | "custom" | "user" | "rbac" | "system" | undefined;
172
+ category: "custom" | "user" | "auth" | "rbac" | "system" | undefined;
173
173
  }[];
174
174
  userId: number;
175
175
  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, p as SocialProvider, q as AuthContext } from './authenticate-BbugF32w.js';
2
- export { B as ChangePasswordParams, w as CheckAccountExistsParams, C as CheckAccountExistsResult, a6 as EmailSchema, I as INVITATION_STATUSES, K as KEY_ALGORITHM, y as LoginParams, L as LoginResult, z as LogoutParams, a2 as OAuthCallbackParams, a3 as OAuthCallbackResult, a1 as OAuthStartParams, O as OAuthStartResult, a8 as PasswordSchema, a7 as PhoneSchema, x as RegisterParams, Q as RegisterPublicKeyParams, a as RegisterResult, W as RevokeKeyParams, T as RotateKeyParams, b as RotateKeyResult, e as SOCIAL_PROVIDERS, F as SendVerificationCodeParams, S as SendVerificationCodeResult, a9 as TargetTypeSchema, d as USER_STATUSES, o as UserStatus, h as VERIFICATION_PURPOSES, g as VERIFICATION_TARGET_TYPES, aa as VerificationPurposeSchema, V as VerificationTargetType, G as VerifyCodeParams, H as VerifyCodeResult, m as authRouter, a4 as authenticate, Z as buildOAuthErrorUrl, v as changePasswordService, r as checkAccountExistsService, $ as getEnabledOAuthProviders, a0 as getGoogleAccessToken, _ as isOAuthProviderEnabled, t as loginService, u as logoutService, Y as oauthCallbackService, X as oauthStartService, a5 as optionalAuth, J as registerPublicKeyService, s as registerService, N as revokeKeyService, M as rotateKeyService, D as sendVerificationCodeService, E as verifyCodeService } from './authenticate-BbugF32w.js';
1
+ import { k as AuthInitOptions, l as KeyAlgorithmType, n as InvitationStatus, f as VerificationPurpose, j as PermissionCategory, p as SocialProvider, q as AuthContext } from './authenticate-2953PCm8.js';
2
+ export { B as ChangePasswordParams, w as CheckAccountExistsParams, C as CheckAccountExistsResult, a6 as EmailSchema, I as INVITATION_STATUSES, K as KEY_ALGORITHM, y as LoginParams, L as LoginResult, z as LogoutParams, a2 as OAuthCallbackParams, a3 as OAuthCallbackResult, a1 as OAuthStartParams, O as OAuthStartResult, a8 as PasswordSchema, a7 as PhoneSchema, x as RegisterParams, Q as RegisterPublicKeyParams, a as RegisterResult, W as RevokeKeyParams, T as RotateKeyParams, b as RotateKeyResult, e as SOCIAL_PROVIDERS, F as SendVerificationCodeParams, S as SendVerificationCodeResult, a9 as TargetTypeSchema, d as USER_STATUSES, o as UserStatus, h as VERIFICATION_PURPOSES, g as VERIFICATION_TARGET_TYPES, aa as VerificationPurposeSchema, V as VerificationTargetType, G as VerifyCodeParams, H as VerifyCodeResult, m as authRouter, a4 as authenticate, Z as buildOAuthErrorUrl, v as changePasswordService, r as checkAccountExistsService, $ as getEnabledOAuthProviders, a0 as getGoogleAccessToken, _ as isOAuthProviderEnabled, t as loginService, u as logoutService, Y as oauthCallbackService, X as oauthStartService, a5 as optionalAuth, J as registerPublicKeyService, s as registerService, N as revokeKeyService, M as rotateKeyService, D as sendVerificationCodeService, E as verifyCodeService } from './authenticate-2953PCm8.js';
3
3
  import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
4
4
  import { UserProfile as UserProfile$1, ProfileInfo } from '@spfn/auth';
5
5
  import { BaseRepository } from '@spfn/core/db';
@@ -1305,7 +1305,7 @@ declare function getAuthSessionService(userId: string | number | bigint): Promis
1305
1305
  id: number;
1306
1306
  name: string;
1307
1307
  displayName: string;
1308
- category: "auth" | "custom" | "user" | "rbac" | "system" | undefined;
1308
+ category: "custom" | "user" | "auth" | "rbac" | "system" | undefined;
1309
1309
  }[];
1310
1310
  userId: number;
1311
1311
  email: string | null;
@@ -2444,7 +2444,7 @@ declare const permissions: drizzle_orm_pg_core.PgTableWithColumns<{
2444
2444
  tableName: "permissions";
2445
2445
  dataType: "string";
2446
2446
  columnType: "PgText";
2447
- data: "auth" | "custom" | "user" | "rbac" | "system";
2447
+ data: "custom" | "user" | "auth" | "rbac" | "system";
2448
2448
  driverParam: string;
2449
2449
  notNull: false;
2450
2450
  hasDefault: false;
@@ -2944,14 +2944,14 @@ declare class UsersRepository extends BaseRepository {
2944
2944
  create(data: NewUser): Promise<{
2945
2945
  email: string | null;
2946
2946
  phone: string | null;
2947
- id: number;
2947
+ status: "active" | "inactive" | "suspended";
2948
2948
  username: string | null;
2949
+ id: number;
2950
+ createdAt: Date;
2951
+ updatedAt: Date;
2949
2952
  passwordHash: string | null;
2950
2953
  passwordChangeRequired: boolean;
2951
2954
  roleId: number;
2952
- createdAt: Date;
2953
- updatedAt: Date;
2954
- status: "active" | "inactive" | "suspended";
2955
2955
  emailVerifiedAt: Date | null;
2956
2956
  phoneVerifiedAt: Date | null;
2957
2957
  lastLoginAt: Date | null;
@@ -3020,14 +3020,14 @@ declare class UsersRepository extends BaseRepository {
3020
3020
  deleteById(id: number): Promise<{
3021
3021
  email: string | null;
3022
3022
  phone: string | null;
3023
- id: number;
3023
+ status: "active" | "inactive" | "suspended";
3024
3024
  username: string | null;
3025
+ id: number;
3026
+ createdAt: Date;
3027
+ updatedAt: Date;
3025
3028
  passwordHash: string | null;
3026
3029
  passwordChangeRequired: boolean;
3027
3030
  roleId: number;
3028
- createdAt: Date;
3029
- updatedAt: Date;
3030
- status: "active" | "inactive" | "suspended";
3031
3031
  emailVerifiedAt: Date | null;
3032
3032
  phoneVerifiedAt: Date | null;
3033
3033
  lastLoginAt: Date | null;
@@ -3050,7 +3050,7 @@ declare class UsersRepository extends BaseRepository {
3050
3050
  id: number;
3051
3051
  name: string;
3052
3052
  displayName: string;
3053
- category: "auth" | "custom" | "user" | "rbac" | "system" | undefined;
3053
+ category: "custom" | "user" | "auth" | "rbac" | "system" | undefined;
3054
3054
  }[];
3055
3055
  }>;
3056
3056
  /**
@@ -3162,16 +3162,16 @@ declare class KeysRepository extends BaseRepository {
3162
3162
  * Write primary 사용
3163
3163
  */
3164
3164
  create(data: NewUserPublicKey): Promise<{
3165
- publicKey: string;
3166
- keyId: string;
3167
- fingerprint: string;
3168
- algorithm: "ES256" | "RS256";
3169
3165
  userId: number;
3166
+ keyId: string;
3170
3167
  id: number;
3171
3168
  isActive: boolean;
3172
3169
  createdAt: Date;
3173
- expiresAt: Date | null;
3170
+ publicKey: string;
3171
+ algorithm: "ES256" | "RS256";
3172
+ fingerprint: string;
3174
3173
  lastUsedAt: Date | null;
3174
+ expiresAt: Date | null;
3175
3175
  revokedAt: Date | null;
3176
3176
  revokedReason: string | null;
3177
3177
  }>;
@@ -3198,16 +3198,16 @@ declare class KeysRepository extends BaseRepository {
3198
3198
  * Write primary 사용
3199
3199
  */
3200
3200
  deleteByKeyIdAndUserId(keyId: string, userId: number): Promise<{
3201
- publicKey: string;
3202
- keyId: string;
3203
- fingerprint: string;
3204
- algorithm: "ES256" | "RS256";
3205
3201
  userId: number;
3202
+ keyId: string;
3206
3203
  id: number;
3207
3204
  isActive: boolean;
3208
3205
  createdAt: Date;
3209
- expiresAt: Date | null;
3206
+ publicKey: string;
3207
+ algorithm: "ES256" | "RS256";
3208
+ fingerprint: string;
3210
3209
  lastUsedAt: Date | null;
3210
+ expiresAt: Date | null;
3211
3211
  revokedAt: Date | null;
3212
3212
  revokedReason: string | null;
3213
3213
  }>;
@@ -3322,14 +3322,14 @@ declare class VerificationCodesRepository extends BaseRepository {
3322
3322
  * Write primary 사용
3323
3323
  */
3324
3324
  create(data: NewVerificationCode): Promise<{
3325
- target: string;
3326
- targetType: "email" | "phone";
3327
- purpose: "registration" | "login" | "password_reset" | "email_change" | "phone_change";
3328
- code: string;
3329
3325
  id: number;
3330
3326
  createdAt: Date;
3331
3327
  updatedAt: Date;
3332
3328
  expiresAt: Date;
3329
+ target: string;
3330
+ targetType: "email" | "phone";
3331
+ code: string;
3332
+ purpose: "registration" | "login" | "password_reset" | "email_change" | "phone_change";
3333
3333
  usedAt: Date | null;
3334
3334
  attempts: number;
3335
3335
  }>;
@@ -3518,7 +3518,7 @@ declare class PermissionsRepository extends BaseRepository {
3518
3518
  name: string;
3519
3519
  displayName: string;
3520
3520
  description: string | null;
3521
- category: "auth" | "custom" | "user" | "rbac" | "system" | null;
3521
+ category: "custom" | "user" | "auth" | "rbac" | "system" | null;
3522
3522
  isBuiltin: boolean;
3523
3523
  isSystem: boolean;
3524
3524
  isActive: boolean;
@@ -3534,7 +3534,7 @@ declare class PermissionsRepository extends BaseRepository {
3534
3534
  name: string;
3535
3535
  displayName: string;
3536
3536
  description: string | null;
3537
- category: "auth" | "custom" | "user" | "rbac" | "system" | null;
3537
+ category: "custom" | "user" | "auth" | "rbac" | "system" | null;
3538
3538
  isBuiltin: boolean;
3539
3539
  isSystem: boolean;
3540
3540
  isActive: boolean;
@@ -3574,7 +3574,7 @@ declare class PermissionsRepository extends BaseRepository {
3574
3574
  name: string;
3575
3575
  displayName: string;
3576
3576
  description: string | null;
3577
- category: "auth" | "custom" | "user" | "rbac" | "system" | null;
3577
+ category: "custom" | "user" | "auth" | "rbac" | "system" | null;
3578
3578
  isBuiltin: boolean;
3579
3579
  isSystem: boolean;
3580
3580
  isActive: boolean;
@@ -3585,7 +3585,6 @@ declare class PermissionsRepository extends BaseRepository {
3585
3585
  */
3586
3586
  deleteById(id: number): Promise<{
3587
3587
  description: string | null;
3588
- metadata: Record<string, any> | null;
3589
3588
  id: number;
3590
3589
  name: string;
3591
3590
  displayName: string;
@@ -3594,7 +3593,8 @@ declare class PermissionsRepository extends BaseRepository {
3594
3593
  isActive: boolean;
3595
3594
  createdAt: Date;
3596
3595
  updatedAt: Date;
3597
- category: "auth" | "custom" | "user" | "rbac" | "system" | null;
3596
+ metadata: Record<string, any> | null;
3597
+ category: "custom" | "user" | "auth" | "rbac" | "system" | null;
3598
3598
  }>;
3599
3599
  }
3600
3600
  declare const permissionsRepository: PermissionsRepository;
@@ -3639,9 +3639,9 @@ declare class RolePermissionsRepository extends BaseRepository {
3639
3639
  */
3640
3640
  createMany(data: NewRolePermission[]): Promise<{
3641
3641
  id: number;
3642
- roleId: number;
3643
3642
  createdAt: Date;
3644
3643
  updatedAt: Date;
3644
+ roleId: number;
3645
3645
  permissionId: number;
3646
3646
  }[]>;
3647
3647
  /**
@@ -3657,9 +3657,9 @@ declare class RolePermissionsRepository extends BaseRepository {
3657
3657
  */
3658
3658
  setPermissionsForRole(roleId: number, permissionIds: number[]): Promise<{
3659
3659
  id: number;
3660
- roleId: number;
3661
3660
  createdAt: Date;
3662
3661
  updatedAt: Date;
3662
+ roleId: number;
3663
3663
  permissionId: number;
3664
3664
  }[]>;
3665
3665
  }
@@ -3724,10 +3724,10 @@ declare class UserPermissionsRepository extends BaseRepository {
3724
3724
  id: number;
3725
3725
  createdAt: Date;
3726
3726
  updatedAt: Date;
3727
- permissionId: number;
3728
3727
  expiresAt: Date | null;
3729
- reason: string | null;
3728
+ permissionId: number;
3730
3729
  granted: boolean;
3730
+ reason: string | null;
3731
3731
  }>;
3732
3732
  /**
3733
3733
  * 사용자 권한 오버라이드 업데이트
@@ -3750,10 +3750,10 @@ declare class UserPermissionsRepository extends BaseRepository {
3750
3750
  id: number;
3751
3751
  createdAt: Date;
3752
3752
  updatedAt: Date;
3753
- permissionId: number;
3754
3753
  expiresAt: Date | null;
3755
- reason: string | null;
3754
+ permissionId: number;
3756
3755
  granted: boolean;
3756
+ reason: string | null;
3757
3757
  }>;
3758
3758
  /**
3759
3759
  * 사용자의 모든 권한 오버라이드 삭제
@@ -3831,7 +3831,6 @@ declare class UserProfilesRepository extends BaseRepository {
3831
3831
  * 프로필 생성
3832
3832
  */
3833
3833
  create(data: NewUserProfile): Promise<{
3834
- metadata: Record<string, any> | null;
3835
3834
  userId: number;
3836
3835
  id: number;
3837
3836
  displayName: string;
@@ -3849,6 +3848,7 @@ declare class UserProfilesRepository extends BaseRepository {
3849
3848
  location: string | null;
3850
3849
  company: string | null;
3851
3850
  jobTitle: string | null;
3851
+ metadata: Record<string, any> | null;
3852
3852
  }>;
3853
3853
  /**
3854
3854
  * 프로필 업데이트 (by ID)
@@ -3900,7 +3900,6 @@ declare class UserProfilesRepository extends BaseRepository {
3900
3900
  * 프로필 삭제 (by ID)
3901
3901
  */
3902
3902
  deleteById(id: number): Promise<{
3903
- metadata: Record<string, any> | null;
3904
3903
  userId: number;
3905
3904
  id: number;
3906
3905
  displayName: string;
@@ -3918,12 +3917,12 @@ declare class UserProfilesRepository extends BaseRepository {
3918
3917
  location: string | null;
3919
3918
  company: string | null;
3920
3919
  jobTitle: string | null;
3920
+ metadata: Record<string, any> | null;
3921
3921
  }>;
3922
3922
  /**
3923
3923
  * 프로필 삭제 (by User ID)
3924
3924
  */
3925
3925
  deleteByUserId(userId: number): Promise<{
3926
- metadata: Record<string, any> | null;
3927
3926
  userId: number;
3928
3927
  id: number;
3929
3928
  displayName: string;
@@ -3941,6 +3940,7 @@ declare class UserProfilesRepository extends BaseRepository {
3941
3940
  location: string | null;
3942
3941
  company: string | null;
3943
3942
  jobTitle: string | null;
3943
+ metadata: Record<string, any> | null;
3944
3944
  }>;
3945
3945
  /**
3946
3946
  * 프로필 Upsert (by User ID)
@@ -3949,7 +3949,6 @@ declare class UserProfilesRepository extends BaseRepository {
3949
3949
  * 새로 생성 시 displayName은 필수 (없으면 'User'로 설정)
3950
3950
  */
3951
3951
  upsertByUserId(userId: number, data: Partial<Omit<NewUserProfile, 'userId'>>): Promise<{
3952
- metadata: Record<string, any> | null;
3953
3952
  userId: number;
3954
3953
  id: number;
3955
3954
  displayName: string;
@@ -3967,6 +3966,7 @@ declare class UserProfilesRepository extends BaseRepository {
3967
3966
  location: string | null;
3968
3967
  company: string | null;
3969
3968
  jobTitle: string | null;
3969
+ metadata: Record<string, any> | null;
3970
3970
  }>;
3971
3971
  /**
3972
3972
  * User ID로 프로필 데이터 조회 (formatted)
@@ -4094,15 +4094,15 @@ declare class InvitationsRepository extends BaseRepository {
4094
4094
  */
4095
4095
  create(data: NewInvitation): Promise<{
4096
4096
  email: string;
4097
- metadata: Record<string, any> | null;
4097
+ status: "pending" | "accepted" | "expired" | "cancelled";
4098
4098
  id: number;
4099
- roleId: number;
4100
4099
  createdAt: Date;
4101
4100
  updatedAt: Date;
4102
- status: "pending" | "accepted" | "expired" | "cancelled";
4101
+ roleId: number;
4102
+ metadata: Record<string, any> | null;
4103
+ expiresAt: Date;
4103
4104
  token: string;
4104
4105
  invitedBy: number;
4105
- expiresAt: Date;
4106
4106
  acceptedAt: Date | null;
4107
4107
  cancelledAt: Date | null;
4108
4108
  }>;
@@ -4128,15 +4128,15 @@ declare class InvitationsRepository extends BaseRepository {
4128
4128
  */
4129
4129
  deleteById(id: number): Promise<{
4130
4130
  email: string;
4131
- metadata: Record<string, any> | null;
4131
+ status: "pending" | "accepted" | "expired" | "cancelled";
4132
4132
  id: number;
4133
- roleId: number;
4134
4133
  createdAt: Date;
4135
4134
  updatedAt: Date;
4136
- status: "pending" | "accepted" | "expired" | "cancelled";
4135
+ roleId: number;
4136
+ metadata: Record<string, any> | null;
4137
+ expiresAt: Date;
4137
4138
  token: string;
4138
4139
  invitedBy: number;
4139
- expiresAt: Date;
4140
4140
  acceptedAt: Date | null;
4141
4141
  cancelledAt: Date | null;
4142
4142
  }>;
@@ -4803,14 +4803,14 @@ declare function getUser(c: Context | {
4803
4803
  }): {
4804
4804
  email: string | null;
4805
4805
  phone: string | null;
4806
- id: number;
4806
+ status: "active" | "inactive" | "suspended";
4807
4807
  username: string | null;
4808
+ id: number;
4809
+ createdAt: Date;
4810
+ updatedAt: Date;
4808
4811
  passwordHash: string | null;
4809
4812
  passwordChangeRequired: boolean;
4810
4813
  roleId: number;
4811
- createdAt: Date;
4812
- updatedAt: Date;
4813
- status: "active" | "inactive" | "suspended";
4814
4814
  emailVerifiedAt: Date | null;
4815
4815
  phoneVerifiedAt: Date | null;
4816
4816
  lastLoginAt: Date | null;
package/dist/server.js CHANGED
@@ -8992,6 +8992,7 @@ var oauthRouter = defineRouter4({
8992
8992
 
8993
8993
  // src/server/routes/admin/index.ts
8994
8994
  init_esm();
8995
+ import { ForbiddenError as ForbiddenError4 } from "@spfn/core/errors";
8995
8996
  import { route as route5 } from "@spfn/core/route";
8996
8997
  var listRoles = route5.get("/_auth/admin/roles").input({
8997
8998
  query: Type.Object({
@@ -9059,6 +9060,14 @@ var updateUserRole = route5.patch("/_auth/admin/users/:userId/role").input({
9059
9060
  })
9060
9061
  }).use([authenticate, requireRole("superadmin")]).handler(async (c) => {
9061
9062
  const { params, body } = await c.data();
9063
+ const auth = getAuth(c);
9064
+ if (params.userId === Number(auth.userId)) {
9065
+ throw new ForbiddenError4({ message: "Cannot change your own role" });
9066
+ }
9067
+ const targetRole = await getUserRole(params.userId);
9068
+ if (targetRole === "superadmin") {
9069
+ throw new ForbiddenError4({ message: "Cannot modify superadmin role" });
9070
+ }
9062
9071
  await updateUserService(params.userId, { roleId: body.roleId });
9063
9072
  return { userId: params.userId, roleId: body.roleId };
9064
9073
  });