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

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/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-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';
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-CAJr3A4H.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-CAJr3A4H.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';
@@ -1082,6 +1082,7 @@ declare function createInvitation(params: {
1082
1082
  roleId: number;
1083
1083
  invitedBy: number;
1084
1084
  expiresInDays?: number;
1085
+ expiresAt?: Date;
1085
1086
  metadata?: Record<string, any>;
1086
1087
  }): Promise<Invitation>;
1087
1088
  /**
@@ -1305,7 +1306,7 @@ declare function getAuthSessionService(userId: string | number | bigint): Promis
1305
1306
  id: number;
1306
1307
  name: string;
1307
1308
  displayName: string;
1308
- category: "custom" | "user" | "auth" | "rbac" | "system" | undefined;
1309
+ category: "auth" | "custom" | "user" | "rbac" | "system" | undefined;
1309
1310
  }[];
1310
1311
  userId: number;
1311
1312
  email: string | null;
@@ -1488,7 +1489,7 @@ declare const userProfiles: drizzle_orm_pg_core.PgTableWithColumns<{
1488
1489
  columnType: "PgText";
1489
1490
  data: string;
1490
1491
  driverParam: string;
1491
- notNull: true;
1492
+ notNull: false;
1492
1493
  hasDefault: false;
1493
1494
  isPrimaryKey: false;
1494
1495
  isAutoincrement: false;
@@ -2444,7 +2445,7 @@ declare const permissions: drizzle_orm_pg_core.PgTableWithColumns<{
2444
2445
  tableName: "permissions";
2445
2446
  dataType: "string";
2446
2447
  columnType: "PgText";
2447
- data: "custom" | "user" | "auth" | "rbac" | "system";
2448
+ data: "auth" | "custom" | "user" | "rbac" | "system";
2448
2449
  driverParam: string;
2449
2450
  notNull: false;
2450
2451
  hasDefault: false;
@@ -2944,14 +2945,14 @@ declare class UsersRepository extends BaseRepository {
2944
2945
  create(data: NewUser): Promise<{
2945
2946
  email: string | null;
2946
2947
  phone: string | null;
2947
- status: "active" | "inactive" | "suspended";
2948
- username: string | null;
2949
2948
  id: number;
2950
- createdAt: Date;
2951
- updatedAt: Date;
2949
+ username: string | null;
2952
2950
  passwordHash: string | null;
2953
2951
  passwordChangeRequired: boolean;
2954
2952
  roleId: number;
2953
+ createdAt: Date;
2954
+ updatedAt: Date;
2955
+ status: "active" | "inactive" | "suspended";
2955
2956
  emailVerifiedAt: Date | null;
2956
2957
  phoneVerifiedAt: Date | null;
2957
2958
  lastLoginAt: Date | null;
@@ -3020,14 +3021,14 @@ declare class UsersRepository extends BaseRepository {
3020
3021
  deleteById(id: number): Promise<{
3021
3022
  email: string | null;
3022
3023
  phone: string | null;
3023
- status: "active" | "inactive" | "suspended";
3024
- username: string | null;
3025
3024
  id: number;
3026
- createdAt: Date;
3027
- updatedAt: Date;
3025
+ username: string | null;
3028
3026
  passwordHash: string | null;
3029
3027
  passwordChangeRequired: boolean;
3030
3028
  roleId: number;
3029
+ createdAt: Date;
3030
+ updatedAt: Date;
3031
+ status: "active" | "inactive" | "suspended";
3031
3032
  emailVerifiedAt: Date | null;
3032
3033
  phoneVerifiedAt: Date | null;
3033
3034
  lastLoginAt: Date | null;
@@ -3050,7 +3051,7 @@ declare class UsersRepository extends BaseRepository {
3050
3051
  id: number;
3051
3052
  name: string;
3052
3053
  displayName: string;
3053
- category: "custom" | "user" | "auth" | "rbac" | "system" | undefined;
3054
+ category: "auth" | "custom" | "user" | "rbac" | "system" | undefined;
3054
3055
  }[];
3055
3056
  }>;
3056
3057
  /**
@@ -3162,16 +3163,16 @@ declare class KeysRepository extends BaseRepository {
3162
3163
  * Write primary 사용
3163
3164
  */
3164
3165
  create(data: NewUserPublicKey): Promise<{
3165
- userId: number;
3166
+ publicKey: string;
3166
3167
  keyId: string;
3168
+ fingerprint: string;
3169
+ algorithm: "ES256" | "RS256";
3170
+ userId: number;
3167
3171
  id: number;
3168
3172
  isActive: boolean;
3169
3173
  createdAt: Date;
3170
- publicKey: string;
3171
- algorithm: "ES256" | "RS256";
3172
- fingerprint: string;
3173
- lastUsedAt: Date | null;
3174
3174
  expiresAt: Date | null;
3175
+ lastUsedAt: Date | null;
3175
3176
  revokedAt: Date | null;
3176
3177
  revokedReason: string | null;
3177
3178
  }>;
@@ -3198,16 +3199,16 @@ declare class KeysRepository extends BaseRepository {
3198
3199
  * Write primary 사용
3199
3200
  */
3200
3201
  deleteByKeyIdAndUserId(keyId: string, userId: number): Promise<{
3201
- userId: number;
3202
+ publicKey: string;
3202
3203
  keyId: string;
3204
+ fingerprint: string;
3205
+ algorithm: "ES256" | "RS256";
3206
+ userId: number;
3203
3207
  id: number;
3204
3208
  isActive: boolean;
3205
3209
  createdAt: Date;
3206
- publicKey: string;
3207
- algorithm: "ES256" | "RS256";
3208
- fingerprint: string;
3209
- lastUsedAt: Date | null;
3210
3210
  expiresAt: Date | null;
3211
+ lastUsedAt: Date | null;
3211
3212
  revokedAt: Date | null;
3212
3213
  revokedReason: string | null;
3213
3214
  }>;
@@ -3322,14 +3323,14 @@ declare class VerificationCodesRepository extends BaseRepository {
3322
3323
  * Write primary 사용
3323
3324
  */
3324
3325
  create(data: NewVerificationCode): Promise<{
3326
+ target: string;
3327
+ targetType: "email" | "phone";
3328
+ purpose: "registration" | "login" | "password_reset" | "email_change" | "phone_change";
3329
+ code: string;
3325
3330
  id: number;
3326
3331
  createdAt: Date;
3327
3332
  updatedAt: Date;
3328
3333
  expiresAt: Date;
3329
- target: string;
3330
- targetType: "email" | "phone";
3331
- code: string;
3332
- purpose: "registration" | "login" | "password_reset" | "email_change" | "phone_change";
3333
3334
  usedAt: Date | null;
3334
3335
  attempts: number;
3335
3336
  }>;
@@ -3518,7 +3519,7 @@ declare class PermissionsRepository extends BaseRepository {
3518
3519
  name: string;
3519
3520
  displayName: string;
3520
3521
  description: string | null;
3521
- category: "custom" | "user" | "auth" | "rbac" | "system" | null;
3522
+ category: "auth" | "custom" | "user" | "rbac" | "system" | null;
3522
3523
  isBuiltin: boolean;
3523
3524
  isSystem: boolean;
3524
3525
  isActive: boolean;
@@ -3534,7 +3535,7 @@ declare class PermissionsRepository extends BaseRepository {
3534
3535
  name: string;
3535
3536
  displayName: string;
3536
3537
  description: string | null;
3537
- category: "custom" | "user" | "auth" | "rbac" | "system" | null;
3538
+ category: "auth" | "custom" | "user" | "rbac" | "system" | null;
3538
3539
  isBuiltin: boolean;
3539
3540
  isSystem: boolean;
3540
3541
  isActive: boolean;
@@ -3574,7 +3575,7 @@ declare class PermissionsRepository extends BaseRepository {
3574
3575
  name: string;
3575
3576
  displayName: string;
3576
3577
  description: string | null;
3577
- category: "custom" | "user" | "auth" | "rbac" | "system" | null;
3578
+ category: "auth" | "custom" | "user" | "rbac" | "system" | null;
3578
3579
  isBuiltin: boolean;
3579
3580
  isSystem: boolean;
3580
3581
  isActive: boolean;
@@ -3585,6 +3586,7 @@ declare class PermissionsRepository extends BaseRepository {
3585
3586
  */
3586
3587
  deleteById(id: number): Promise<{
3587
3588
  description: string | null;
3589
+ metadata: Record<string, any> | null;
3588
3590
  id: number;
3589
3591
  name: string;
3590
3592
  displayName: string;
@@ -3593,8 +3595,7 @@ declare class PermissionsRepository extends BaseRepository {
3593
3595
  isActive: boolean;
3594
3596
  createdAt: Date;
3595
3597
  updatedAt: Date;
3596
- metadata: Record<string, any> | null;
3597
- category: "custom" | "user" | "auth" | "rbac" | "system" | null;
3598
+ category: "auth" | "custom" | "user" | "rbac" | "system" | null;
3598
3599
  }>;
3599
3600
  }
3600
3601
  declare const permissionsRepository: PermissionsRepository;
@@ -3639,9 +3640,9 @@ declare class RolePermissionsRepository extends BaseRepository {
3639
3640
  */
3640
3641
  createMany(data: NewRolePermission[]): Promise<{
3641
3642
  id: number;
3643
+ roleId: number;
3642
3644
  createdAt: Date;
3643
3645
  updatedAt: Date;
3644
- roleId: number;
3645
3646
  permissionId: number;
3646
3647
  }[]>;
3647
3648
  /**
@@ -3657,9 +3658,9 @@ declare class RolePermissionsRepository extends BaseRepository {
3657
3658
  */
3658
3659
  setPermissionsForRole(roleId: number, permissionIds: number[]): Promise<{
3659
3660
  id: number;
3661
+ roleId: number;
3660
3662
  createdAt: Date;
3661
3663
  updatedAt: Date;
3662
- roleId: number;
3663
3664
  permissionId: number;
3664
3665
  }[]>;
3665
3666
  }
@@ -3724,10 +3725,10 @@ declare class UserPermissionsRepository extends BaseRepository {
3724
3725
  id: number;
3725
3726
  createdAt: Date;
3726
3727
  updatedAt: Date;
3727
- expiresAt: Date | null;
3728
3728
  permissionId: number;
3729
- granted: boolean;
3729
+ expiresAt: Date | null;
3730
3730
  reason: string | null;
3731
+ granted: boolean;
3731
3732
  }>;
3732
3733
  /**
3733
3734
  * 사용자 권한 오버라이드 업데이트
@@ -3750,10 +3751,10 @@ declare class UserPermissionsRepository extends BaseRepository {
3750
3751
  id: number;
3751
3752
  createdAt: Date;
3752
3753
  updatedAt: Date;
3753
- expiresAt: Date | null;
3754
3754
  permissionId: number;
3755
- granted: boolean;
3755
+ expiresAt: Date | null;
3756
3756
  reason: string | null;
3757
+ granted: boolean;
3757
3758
  }>;
3758
3759
  /**
3759
3760
  * 사용자의 모든 권한 오버라이드 삭제
@@ -3785,7 +3786,7 @@ declare class UserProfilesRepository extends BaseRepository {
3785
3786
  updatedAt: Date;
3786
3787
  id: number;
3787
3788
  userId: number;
3788
- displayName: string;
3789
+ displayName: string | null;
3789
3790
  firstName: string | null;
3790
3791
  lastName: string | null;
3791
3792
  avatarUrl: string | null;
@@ -3812,7 +3813,7 @@ declare class UserProfilesRepository extends BaseRepository {
3812
3813
  updatedAt: Date;
3813
3814
  id: number;
3814
3815
  userId: number;
3815
- displayName: string;
3816
+ displayName: string | null;
3816
3817
  firstName: string | null;
3817
3818
  lastName: string | null;
3818
3819
  avatarUrl: string | null;
@@ -3831,9 +3832,10 @@ declare class UserProfilesRepository extends BaseRepository {
3831
3832
  * 프로필 생성
3832
3833
  */
3833
3834
  create(data: NewUserProfile): Promise<{
3835
+ metadata: Record<string, any> | null;
3834
3836
  userId: number;
3835
3837
  id: number;
3836
- displayName: string;
3838
+ displayName: string | null;
3837
3839
  createdAt: Date;
3838
3840
  updatedAt: Date;
3839
3841
  firstName: string | null;
@@ -3848,7 +3850,6 @@ declare class UserProfilesRepository extends BaseRepository {
3848
3850
  location: string | null;
3849
3851
  company: string | null;
3850
3852
  jobTitle: string | null;
3851
- metadata: Record<string, any> | null;
3852
3853
  }>;
3853
3854
  /**
3854
3855
  * 프로필 업데이트 (by ID)
@@ -3858,7 +3859,7 @@ declare class UserProfilesRepository extends BaseRepository {
3858
3859
  updatedAt: Date;
3859
3860
  id: number;
3860
3861
  userId: number;
3861
- displayName: string;
3862
+ displayName: string | null;
3862
3863
  firstName: string | null;
3863
3864
  lastName: string | null;
3864
3865
  avatarUrl: string | null;
@@ -3881,7 +3882,7 @@ declare class UserProfilesRepository extends BaseRepository {
3881
3882
  updatedAt: Date;
3882
3883
  id: number;
3883
3884
  userId: number;
3884
- displayName: string;
3885
+ displayName: string | null;
3885
3886
  firstName: string | null;
3886
3887
  lastName: string | null;
3887
3888
  avatarUrl: string | null;
@@ -3900,9 +3901,10 @@ declare class UserProfilesRepository extends BaseRepository {
3900
3901
  * 프로필 삭제 (by ID)
3901
3902
  */
3902
3903
  deleteById(id: number): Promise<{
3904
+ metadata: Record<string, any> | null;
3903
3905
  userId: number;
3904
3906
  id: number;
3905
- displayName: string;
3907
+ displayName: string | null;
3906
3908
  createdAt: Date;
3907
3909
  updatedAt: Date;
3908
3910
  firstName: string | null;
@@ -3917,15 +3919,15 @@ declare class UserProfilesRepository extends BaseRepository {
3917
3919
  location: string | null;
3918
3920
  company: string | null;
3919
3921
  jobTitle: string | null;
3920
- metadata: Record<string, any> | null;
3921
3922
  }>;
3922
3923
  /**
3923
3924
  * 프로필 삭제 (by User ID)
3924
3925
  */
3925
3926
  deleteByUserId(userId: number): Promise<{
3927
+ metadata: Record<string, any> | null;
3926
3928
  userId: number;
3927
3929
  id: number;
3928
- displayName: string;
3930
+ displayName: string | null;
3929
3931
  createdAt: Date;
3930
3932
  updatedAt: Date;
3931
3933
  firstName: string | null;
@@ -3940,7 +3942,6 @@ declare class UserProfilesRepository extends BaseRepository {
3940
3942
  location: string | null;
3941
3943
  company: string | null;
3942
3944
  jobTitle: string | null;
3943
- metadata: Record<string, any> | null;
3944
3945
  }>;
3945
3946
  /**
3946
3947
  * 프로필 Upsert (by User ID)
@@ -3949,9 +3950,10 @@ declare class UserProfilesRepository extends BaseRepository {
3949
3950
  * 새로 생성 시 displayName은 필수 (없으면 'User'로 설정)
3950
3951
  */
3951
3952
  upsertByUserId(userId: number, data: Partial<Omit<NewUserProfile, 'userId'>>): Promise<{
3953
+ metadata: Record<string, any> | null;
3952
3954
  userId: number;
3953
3955
  id: number;
3954
- displayName: string;
3956
+ displayName: string | null;
3955
3957
  createdAt: Date;
3956
3958
  updatedAt: Date;
3957
3959
  firstName: string | null;
@@ -3966,7 +3968,6 @@ declare class UserProfilesRepository extends BaseRepository {
3966
3968
  location: string | null;
3967
3969
  company: string | null;
3968
3970
  jobTitle: string | null;
3969
- metadata: Record<string, any> | null;
3970
3971
  }>;
3971
3972
  /**
3972
3973
  * User ID로 프로필 데이터 조회 (formatted)
@@ -3975,7 +3976,7 @@ declare class UserProfilesRepository extends BaseRepository {
3975
3976
  */
3976
3977
  fetchProfileData(userId: number): Promise<{
3977
3978
  profileId: number;
3978
- displayName: string;
3979
+ displayName: string | null;
3979
3980
  firstName: string | null;
3980
3981
  lastName: string | null;
3981
3982
  avatarUrl: string | null;
@@ -4094,15 +4095,15 @@ declare class InvitationsRepository extends BaseRepository {
4094
4095
  */
4095
4096
  create(data: NewInvitation): Promise<{
4096
4097
  email: string;
4097
- status: "pending" | "accepted" | "expired" | "cancelled";
4098
+ metadata: Record<string, any> | null;
4098
4099
  id: number;
4100
+ roleId: number;
4099
4101
  createdAt: Date;
4100
4102
  updatedAt: Date;
4101
- roleId: number;
4102
- metadata: Record<string, any> | null;
4103
- expiresAt: Date;
4103
+ status: "pending" | "accepted" | "expired" | "cancelled";
4104
4104
  token: string;
4105
4105
  invitedBy: number;
4106
+ expiresAt: Date;
4106
4107
  acceptedAt: Date | null;
4107
4108
  cancelledAt: Date | null;
4108
4109
  }>;
@@ -4128,15 +4129,15 @@ declare class InvitationsRepository extends BaseRepository {
4128
4129
  */
4129
4130
  deleteById(id: number): Promise<{
4130
4131
  email: string;
4131
- status: "pending" | "accepted" | "expired" | "cancelled";
4132
+ metadata: Record<string, any> | null;
4132
4133
  id: number;
4134
+ roleId: number;
4133
4135
  createdAt: Date;
4134
4136
  updatedAt: Date;
4135
- roleId: number;
4136
- metadata: Record<string, any> | null;
4137
- expiresAt: Date;
4137
+ status: "pending" | "accepted" | "expired" | "cancelled";
4138
4138
  token: string;
4139
4139
  invitedBy: number;
4140
+ expiresAt: Date;
4140
4141
  acceptedAt: Date | null;
4141
4142
  cancelledAt: Date | null;
4142
4143
  }>;
@@ -4803,14 +4804,14 @@ declare function getUser(c: Context | {
4803
4804
  }): {
4804
4805
  email: string | null;
4805
4806
  phone: string | null;
4806
- status: "active" | "inactive" | "suspended";
4807
- username: string | null;
4808
4807
  id: number;
4809
- createdAt: Date;
4810
- updatedAt: Date;
4808
+ username: string | null;
4811
4809
  passwordHash: string | null;
4812
4810
  passwordChangeRequired: boolean;
4813
4811
  roleId: number;
4812
+ createdAt: Date;
4813
+ updatedAt: Date;
4814
+ status: "active" | "inactive" | "suspended";
4814
4815
  emailVerifiedAt: Date | null;
4815
4816
  phoneVerifiedAt: Date | null;
4816
4817
  lastLoginAt: Date | null;
@@ -5314,10 +5315,67 @@ declare const authRegisterEvent: _spfn_core_event.EventDef<{
5314
5315
  userId: string;
5315
5316
  provider: "email" | "phone" | "google";
5316
5317
  }>;
5318
+ /**
5319
+ * auth.invitation.created - 초대 생성 이벤트
5320
+ *
5321
+ * 발행 시점:
5322
+ * - createInvitation() 성공 시
5323
+ * - resendInvitation() 성공 시
5324
+ *
5325
+ * @example
5326
+ * ```typescript
5327
+ * invitationCreatedEvent.subscribe(async (payload) => {
5328
+ * const inviteUrl = `${APP_URL}/invite/${payload.token}`;
5329
+ * await notificationService.send({
5330
+ * channel: 'email',
5331
+ * to: payload.email,
5332
+ * subject: 'You are invited!',
5333
+ * html: renderInviteEmail({ inviteUrl, ...payload.metadata }),
5334
+ * });
5335
+ * });
5336
+ * ```
5337
+ */
5338
+ declare const invitationCreatedEvent: _spfn_core_event.EventDef<{
5339
+ metadata?: {
5340
+ [x: string]: unknown;
5341
+ } | undefined;
5342
+ email: string;
5343
+ roleId: number;
5344
+ token: string;
5345
+ invitedBy: string;
5346
+ expiresAt: string;
5347
+ invitationId: string;
5348
+ isResend: boolean;
5349
+ }>;
5350
+ /**
5351
+ * auth.invitation.accepted - 초대 수락 이벤트
5352
+ *
5353
+ * 발행 시점:
5354
+ * - acceptInvitation() 성공 시
5355
+ *
5356
+ * @example
5357
+ * ```typescript
5358
+ * invitationAcceptedEvent.subscribe(async (payload) => {
5359
+ * await onboardingService.start(payload.userId);
5360
+ * });
5361
+ * ```
5362
+ */
5363
+ declare const invitationAcceptedEvent: _spfn_core_event.EventDef<{
5364
+ metadata?: {
5365
+ [x: string]: unknown;
5366
+ } | undefined;
5367
+ email: string;
5368
+ userId: string;
5369
+ roleId: number;
5370
+ invitedBy: string;
5371
+ invitationId: string;
5372
+ }>;
5317
5373
  /**
5318
5374
  * Auth event payload types
5319
5375
  */
5320
5376
  type AuthLoginPayload = typeof authLoginEvent._payload;
5321
5377
  type AuthRegisterPayload = typeof authRegisterEvent._payload;
5378
+ type InvitationCreatedPayload = typeof invitationCreatedEvent._payload;
5379
+ type InvitationAcceptedPayload = typeof invitationAcceptedEvent._payload;
5322
5380
 
5323
- export { type AuthConfig, AuthContext, type AuthLoginPayload, AuthProviderSchema, type AuthRegisterPayload, COOKIE_NAMES, type CreateOAuthStateParams, type GoogleTokenResponse, type GoogleUserInfo, type Invitation, InvitationStatus, InvitationsRepository, KeyAlgorithmType, type KeyPair, KeysRepository, type NewInvitation, type NewPermission, type NewPermissionEntity, type NewRole, type NewRoleEntity, type NewRolePermission, type NewUser, type NewUserPermission, type NewUserProfile, type NewUserPublicKey, type NewUserSocialAccount, type NewVerificationCode, type OAuthState, type Permission, type PermissionEntity, PermissionsRepository, type Role, type RoleEntity, type RoleGuardOptions, type RolePermission, RolePermissionsRepository, RolesRepository, type SessionData, type SessionPayload, SocialAccountsRepository, SocialProvider, type TokenPayload, type UpdateProfileParams, type User, type UserPermission, UserPermissionsRepository, type UserProfile, UserProfilesRepository, type UserPublicKey, type UserSocialAccount, UsersRepository, type VerificationCode, VerificationCodesRepository, VerificationPurpose, acceptInvitation, addPermissionToRole, authLogger, authLoginEvent, authRegisterEvent, authSchema, cancelInvitation, checkUsernameAvailableService, configureAuth, createAuthLifecycle, createInvitation, createOAuthState, createRole, decodeToken, deleteInvitation, deleteRole, exchangeCodeForTokens, expireOldInvitations, generateClientToken, generateKeyPair, generateKeyPairES256, generateKeyPairRS256, generateToken, getAllRoles, getAuth, getAuthConfig, getAuthSessionService, getGoogleAuthUrl, getGoogleOAuthConfig, getGoogleUserInfo, getInvitationByToken, getInvitationWithDetails, getKeyId, getKeySize, getLocale, getOptionalAuth, getRole, getRoleByName, getRolePermissions, getSessionInfo, getSessionTtl, getUser, getUserByEmailService, getUserByIdService, getUserByPhoneService, getUserId, getUserPermissions, getUserProfileService, getUserRole, hasAllPermissions, hasAnyPermission, hasAnyRole, hasPermission, hasRole, hashPassword, initializeAuth, invitationsRepository, isGoogleOAuthEnabled, keysRepository, listInvitations, parseDuration, permissions, permissionsRepository, refreshAccessToken, removePermissionFromRole, requireAnyPermission, requirePermissions, requireRole, resendInvitation, roleGuard, rolePermissions, rolePermissionsRepository, roles, rolesRepository, sealSession, setRolePermissions, shouldRefreshSession, shouldRotateKey, socialAccountsRepository, unsealSession, updateLastLoginService, updateLocaleService, updateRole, updateUserProfileService, updateUserService, updateUsernameService, userInvitations, userPermissions, userPermissionsRepository, userProfiles, userProfilesRepository, userPublicKeys, userSocialAccounts, users, usersRepository, validateInvitation, validatePasswordStrength, verificationCodes, verificationCodesRepository, verifyClientToken, verifyKeyFingerprint, verifyOAuthState, verifyPassword, verifyToken };
5381
+ export { type AuthConfig, AuthContext, type AuthLoginPayload, AuthProviderSchema, type AuthRegisterPayload, COOKIE_NAMES, type CreateOAuthStateParams, type GoogleTokenResponse, type GoogleUserInfo, type Invitation, type InvitationAcceptedPayload, type InvitationCreatedPayload, InvitationStatus, InvitationsRepository, KeyAlgorithmType, type KeyPair, KeysRepository, type NewInvitation, type NewPermission, type NewPermissionEntity, type NewRole, type NewRoleEntity, type NewRolePermission, type NewUser, type NewUserPermission, type NewUserProfile, type NewUserPublicKey, type NewUserSocialAccount, type NewVerificationCode, type OAuthState, type Permission, type PermissionEntity, PermissionsRepository, type Role, type RoleEntity, type RoleGuardOptions, type RolePermission, RolePermissionsRepository, RolesRepository, type SessionData, type SessionPayload, SocialAccountsRepository, SocialProvider, type TokenPayload, type UpdateProfileParams, type User, type UserPermission, UserPermissionsRepository, type UserProfile, UserProfilesRepository, type UserPublicKey, type UserSocialAccount, UsersRepository, type VerificationCode, VerificationCodesRepository, VerificationPurpose, acceptInvitation, addPermissionToRole, authLogger, authLoginEvent, authRegisterEvent, authSchema, cancelInvitation, checkUsernameAvailableService, configureAuth, createAuthLifecycle, createInvitation, createOAuthState, createRole, decodeToken, deleteInvitation, deleteRole, exchangeCodeForTokens, expireOldInvitations, generateClientToken, generateKeyPair, generateKeyPairES256, generateKeyPairRS256, generateToken, getAllRoles, getAuth, getAuthConfig, getAuthSessionService, getGoogleAuthUrl, getGoogleOAuthConfig, getGoogleUserInfo, getInvitationByToken, getInvitationWithDetails, getKeyId, getKeySize, getLocale, getOptionalAuth, getRole, getRoleByName, getRolePermissions, getSessionInfo, getSessionTtl, getUser, getUserByEmailService, getUserByIdService, getUserByPhoneService, getUserId, getUserPermissions, getUserProfileService, getUserRole, hasAllPermissions, hasAnyPermission, hasAnyRole, hasPermission, hasRole, hashPassword, initializeAuth, invitationAcceptedEvent, invitationCreatedEvent, invitationsRepository, isGoogleOAuthEnabled, keysRepository, listInvitations, parseDuration, permissions, permissionsRepository, refreshAccessToken, removePermissionFromRole, requireAnyPermission, requirePermissions, requireRole, resendInvitation, roleGuard, rolePermissions, rolePermissionsRepository, roles, rolesRepository, sealSession, setRolePermissions, shouldRefreshSession, shouldRotateKey, socialAccountsRepository, unsealSession, updateLastLoginService, updateLocaleService, updateRole, updateUserProfileService, updateUserService, updateUsernameService, userInvitations, userPermissions, userPermissionsRepository, userProfiles, userProfilesRepository, userPublicKeys, userSocialAccounts, users, usersRepository, validateInvitation, validatePasswordStrength, verificationCodes, verificationCodesRepository, verifyClientToken, verifyKeyFingerprint, verifyOAuthState, verifyPassword, verifyToken };
package/dist/server.js CHANGED
@@ -4653,8 +4653,8 @@ var init_user_profiles = __esm({
4653
4653
  // Foreign key to users table
4654
4654
  userId: foreignKey2("user", () => users.id).unique(),
4655
4655
  // Display Information
4656
- // Display name shown in UI (required)
4657
- displayName: text3("display_name").notNull(),
4656
+ // Display name shown in UI (optional)
4657
+ displayName: text3("display_name"),
4658
4658
  // First name (optional)
4659
4659
  firstName: text3("first_name"),
4660
4660
  // Last name (optional)
@@ -7153,6 +7153,30 @@ var authRegisterEvent = defineEvent(
7153
7153
  metadata: Type.Optional(Type.Record(Type.String(), Type.Unknown()))
7154
7154
  })
7155
7155
  );
7156
+ var invitationCreatedEvent = defineEvent(
7157
+ "auth.invitation.created",
7158
+ Type.Object({
7159
+ invitationId: Type.String(),
7160
+ email: Type.String(),
7161
+ token: Type.String(),
7162
+ roleId: Type.Number(),
7163
+ invitedBy: Type.String(),
7164
+ expiresAt: Type.String(),
7165
+ isResend: Type.Boolean(),
7166
+ metadata: Type.Optional(Type.Record(Type.String(), Type.Unknown()))
7167
+ })
7168
+ );
7169
+ var invitationAcceptedEvent = defineEvent(
7170
+ "auth.invitation.accepted",
7171
+ Type.Object({
7172
+ invitationId: Type.String(),
7173
+ email: Type.String(),
7174
+ userId: Type.String(),
7175
+ roleId: Type.Number(),
7176
+ invitedBy: Type.String(),
7177
+ metadata: Type.Optional(Type.Record(Type.String(), Type.Unknown()))
7178
+ })
7179
+ );
7156
7180
 
7157
7181
  // src/server/services/auth.service.ts
7158
7182
  async function checkAccountExistsService(params) {
@@ -7566,7 +7590,7 @@ function calculateExpiresAt(days = 7) {
7566
7590
  return expiresAt;
7567
7591
  }
7568
7592
  async function createInvitation(params) {
7569
- const { email, roleId, invitedBy, expiresInDays = 7, metadata } = params;
7593
+ const { email, roleId, invitedBy, expiresInDays = 7, expiresAt: expiresAtParam, metadata } = params;
7570
7594
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
7571
7595
  if (!emailRegex.test(email)) {
7572
7596
  throw new Error("Invalid email format");
@@ -7588,7 +7612,7 @@ async function createInvitation(params) {
7588
7612
  throw new Error(`User with id ${invitedBy} not found`);
7589
7613
  }
7590
7614
  const token = generateInvitationToken();
7591
- const expiresAt = calculateExpiresAt(expiresInDays);
7615
+ const expiresAt = expiresAtParam ?? calculateExpiresAt(expiresInDays);
7592
7616
  const invitation = await invitationsRepository.create({
7593
7617
  email,
7594
7618
  token,
@@ -7598,7 +7622,16 @@ async function createInvitation(params) {
7598
7622
  expiresAt,
7599
7623
  metadata: metadata || null
7600
7624
  });
7601
- console.log(`[Auth] \u2705 Created invitation: ${email} as ${role.name} (expires: ${expiresAt.toISOString()})`);
7625
+ await invitationCreatedEvent.emit({
7626
+ invitationId: String(invitation.id),
7627
+ email,
7628
+ token,
7629
+ roleId,
7630
+ invitedBy: String(invitedBy),
7631
+ expiresAt: expiresAt.toISOString(),
7632
+ isResend: false,
7633
+ metadata
7634
+ });
7602
7635
  return invitation;
7603
7636
  }
7604
7637
  async function getInvitationByToken(token) {
@@ -7662,7 +7695,14 @@ async function acceptInvitation(params) {
7662
7695
  "accepted",
7663
7696
  /* @__PURE__ */ new Date()
7664
7697
  );
7665
- console.log(`[Auth] \u2705 Invitation accepted: ${invitation.email} as ${role.name}`);
7698
+ await invitationAcceptedEvent.emit({
7699
+ invitationId: String(invitation.id),
7700
+ email: invitation.email,
7701
+ userId: String(newUser.id),
7702
+ roleId: Number(invitation.roleId),
7703
+ invitedBy: String(invitation.invitedBy),
7704
+ metadata: invitation.metadata
7705
+ });
7666
7706
  return {
7667
7707
  userId: newUser.id,
7668
7708
  email: newUser.email,
@@ -7707,7 +7747,16 @@ async function resendInvitation(id11, expiresInDays = 7) {
7707
7747
  if (!updated) {
7708
7748
  throw new Error("Failed to update invitation");
7709
7749
  }
7710
- console.log(`[Auth] \u{1F4E7} Invitation resent: ${invitation.email} (new expiry: ${newExpiresAt.toISOString()})`);
7750
+ await invitationCreatedEvent.emit({
7751
+ invitationId: String(invitation.id),
7752
+ email: invitation.email,
7753
+ token: invitation.token,
7754
+ roleId: Number(invitation.roleId),
7755
+ invitedBy: String(invitation.invitedBy),
7756
+ expiresAt: newExpiresAt.toISOString(),
7757
+ isResend: true,
7758
+ metadata: invitation.metadata
7759
+ });
7711
7760
  return updated;
7712
7761
  }
7713
7762
 
@@ -7764,7 +7813,7 @@ async function updateUserProfileService(userId, params) {
7764
7813
  const userIdNum = typeof userId === "string" ? Number(userId) : Number(userId);
7765
7814
  const updateData = {};
7766
7815
  if (params.displayName !== void 0) {
7767
- updateData.displayName = emptyToNull(params.displayName) || "User";
7816
+ updateData.displayName = emptyToNull(params.displayName);
7768
7817
  }
7769
7818
  if (params.firstName !== void 0) {
7770
7819
  updateData.firstName = emptyToNull(params.firstName);
@@ -7805,10 +7854,6 @@ async function updateUserProfileService(userId, params) {
7805
7854
  if (params.metadata !== void 0) {
7806
7855
  updateData.metadata = params.metadata;
7807
7856
  }
7808
- const existing = await userProfilesRepository.findByUserId(userIdNum);
7809
- if (!existing && !updateData.displayName) {
7810
- updateData.displayName = "User";
7811
- }
7812
7857
  await userProfilesRepository.upsertByUserId(userIdNum, updateData);
7813
7858
  const profile = await userProfilesRepository.fetchProfileData(userIdNum);
7814
7859
  return profile;
@@ -8675,6 +8720,10 @@ var createInvitation2 = route2.post("/_auth/invitations").input({
8675
8720
  maximum: 30,
8676
8721
  description: "Days until invitation expires (default: 7)"
8677
8722
  })),
8723
+ expiresAt: Type.Optional(Type.String({
8724
+ format: "date-time",
8725
+ description: "Exact expiration timestamp (ISO 8601). Takes precedence over expiresInDays."
8726
+ })),
8678
8727
  metadata: Type.Optional(Type.Any({
8679
8728
  description: "Custom metadata (welcome message, department, etc.)"
8680
8729
  }))
@@ -8687,6 +8736,7 @@ var createInvitation2 = route2.post("/_auth/invitations").input({
8687
8736
  roleId: body.roleId,
8688
8737
  invitedBy: Number(userId),
8689
8738
  expiresInDays: body.expiresInDays,
8739
+ expiresAt: body.expiresAt ? new Date(body.expiresAt) : void 0,
8690
8740
  metadata: body.metadata
8691
8741
  });
8692
8742
  const baseUrl = process.env.SPFN_API_URL || "http://localhost:8790";
@@ -9507,6 +9557,8 @@ export {
9507
9557
  hasRole,
9508
9558
  hashPassword,
9509
9559
  initializeAuth,
9560
+ invitationAcceptedEvent,
9561
+ invitationCreatedEvent,
9510
9562
  invitationsRepository,
9511
9563
  isGoogleOAuthEnabled,
9512
9564
  isOAuthProviderEnabled,