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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/README.md +1385 -1199
  2. package/dist/config.d.ts +405 -0
  3. package/dist/config.js +240 -0
  4. package/dist/config.js.map +1 -0
  5. package/dist/dto-81uR9gzF.d.ts +630 -0
  6. package/dist/errors.d.ts +196 -0
  7. package/dist/errors.js +173 -0
  8. package/dist/errors.js.map +1 -0
  9. package/dist/index.d.ts +273 -14
  10. package/dist/index.js +511 -6665
  11. package/dist/index.js.map +1 -1
  12. package/dist/nextjs/api.js +345 -0
  13. package/dist/nextjs/api.js.map +1 -0
  14. package/dist/{adapters/nextjs → nextjs}/server.d.ts +47 -65
  15. package/dist/nextjs/server.js +179 -0
  16. package/dist/nextjs/server.js.map +1 -0
  17. package/dist/server.d.ts +4328 -529
  18. package/dist/server.js +7841 -1247
  19. package/dist/server.js.map +1 -1
  20. package/migrations/{0000_skinny_christian_walker.sql → 0000_mysterious_colossus.sql} +53 -23
  21. package/migrations/meta/0000_snapshot.json +281 -46
  22. package/migrations/meta/_journal.json +2 -2
  23. package/package.json +31 -31
  24. package/dist/adapters/nextjs/api.d.ts +0 -446
  25. package/dist/adapters/nextjs/api.js +0 -3279
  26. package/dist/adapters/nextjs/api.js.map +0 -1
  27. package/dist/adapters/nextjs/server.js +0 -3645
  28. package/dist/adapters/nextjs/server.js.map +0 -1
  29. package/dist/lib/api/auth-codes-verify.d.ts +0 -37
  30. package/dist/lib/api/auth-codes-verify.js +0 -2949
  31. package/dist/lib/api/auth-codes-verify.js.map +0 -1
  32. package/dist/lib/api/auth-codes.d.ts +0 -37
  33. package/dist/lib/api/auth-codes.js +0 -2949
  34. package/dist/lib/api/auth-codes.js.map +0 -1
  35. package/dist/lib/api/auth-exists.d.ts +0 -38
  36. package/dist/lib/api/auth-exists.js +0 -2949
  37. package/dist/lib/api/auth-exists.js.map +0 -1
  38. package/dist/lib/api/auth-invitations-accept.d.ts +0 -38
  39. package/dist/lib/api/auth-invitations-accept.js +0 -2883
  40. package/dist/lib/api/auth-invitations-accept.js.map +0 -1
  41. package/dist/lib/api/auth-invitations-cancel.d.ts +0 -37
  42. package/dist/lib/api/auth-invitations-cancel.js +0 -2883
  43. package/dist/lib/api/auth-invitations-cancel.js.map +0 -1
  44. package/dist/lib/api/auth-invitations-delete.d.ts +0 -36
  45. package/dist/lib/api/auth-invitations-delete.js +0 -2883
  46. package/dist/lib/api/auth-invitations-delete.js.map +0 -1
  47. package/dist/lib/api/auth-invitations-resend.d.ts +0 -37
  48. package/dist/lib/api/auth-invitations-resend.js +0 -2883
  49. package/dist/lib/api/auth-invitations-resend.js.map +0 -1
  50. package/dist/lib/api/auth-invitations.d.ts +0 -109
  51. package/dist/lib/api/auth-invitations.js +0 -2887
  52. package/dist/lib/api/auth-invitations.js.map +0 -1
  53. package/dist/lib/api/auth-keys-rotate.d.ts +0 -37
  54. package/dist/lib/api/auth-keys-rotate.js +0 -2949
  55. package/dist/lib/api/auth-keys-rotate.js.map +0 -1
  56. package/dist/lib/api/auth-login.d.ts +0 -39
  57. package/dist/lib/api/auth-login.js +0 -2949
  58. package/dist/lib/api/auth-login.js.map +0 -1
  59. package/dist/lib/api/auth-logout.d.ts +0 -36
  60. package/dist/lib/api/auth-logout.js +0 -2949
  61. package/dist/lib/api/auth-logout.js.map +0 -1
  62. package/dist/lib/api/auth-me.d.ts +0 -50
  63. package/dist/lib/api/auth-me.js +0 -2949
  64. package/dist/lib/api/auth-me.js.map +0 -1
  65. package/dist/lib/api/auth-password.d.ts +0 -36
  66. package/dist/lib/api/auth-password.js +0 -2949
  67. package/dist/lib/api/auth-password.js.map +0 -1
  68. package/dist/lib/api/auth-register.d.ts +0 -38
  69. package/dist/lib/api/auth-register.js +0 -2949
  70. package/dist/lib/api/auth-register.js.map +0 -1
  71. package/dist/lib/api/index.d.ts +0 -356
  72. package/dist/lib/api/index.js +0 -3261
  73. package/dist/lib/api/index.js.map +0 -1
  74. package/dist/lib/config.d.ts +0 -70
  75. package/dist/lib/config.js +0 -64
  76. package/dist/lib/config.js.map +0 -1
  77. package/dist/lib/contracts/auth.d.ts +0 -302
  78. package/dist/lib/contracts/auth.js +0 -2951
  79. package/dist/lib/contracts/auth.js.map +0 -1
  80. package/dist/lib/contracts/index.d.ts +0 -3
  81. package/dist/lib/contracts/index.js +0 -3190
  82. package/dist/lib/contracts/index.js.map +0 -1
  83. package/dist/lib/contracts/invitation.d.ts +0 -243
  84. package/dist/lib/contracts/invitation.js +0 -2883
  85. package/dist/lib/contracts/invitation.js.map +0 -1
  86. package/dist/lib/crypto.d.ts +0 -76
  87. package/dist/lib/crypto.js +0 -127
  88. package/dist/lib/crypto.js.map +0 -1
  89. package/dist/lib/index.d.ts +0 -4
  90. package/dist/lib/index.js +0 -313
  91. package/dist/lib/index.js.map +0 -1
  92. package/dist/lib/session.d.ts +0 -68
  93. package/dist/lib/session.js +0 -126
  94. package/dist/lib/session.js.map +0 -1
  95. package/dist/lib/types/api.d.ts +0 -45
  96. package/dist/lib/types/api.js +0 -1
  97. package/dist/lib/types/api.js.map +0 -1
  98. package/dist/lib/types/index.d.ts +0 -3
  99. package/dist/lib/types/index.js +0 -2647
  100. package/dist/lib/types/index.js.map +0 -1
  101. package/dist/lib/types/schemas.d.ts +0 -45
  102. package/dist/lib/types/schemas.js +0 -2647
  103. package/dist/lib/types/schemas.js.map +0 -1
  104. package/dist/lib.js +0 -1
  105. package/dist/lib.js.map +0 -1
  106. package/dist/plugin.d.ts +0 -12
  107. package/dist/plugin.js +0 -9083
  108. package/dist/plugin.js.map +0 -1
  109. package/dist/server/entities/index.d.ts +0 -11
  110. package/dist/server/entities/index.js +0 -395
  111. package/dist/server/entities/index.js.map +0 -1
  112. package/dist/server/entities/invitations.d.ts +0 -241
  113. package/dist/server/entities/invitations.js +0 -184
  114. package/dist/server/entities/invitations.js.map +0 -1
  115. package/dist/server/entities/permissions.d.ts +0 -196
  116. package/dist/server/entities/permissions.js +0 -49
  117. package/dist/server/entities/permissions.js.map +0 -1
  118. package/dist/server/entities/role-permissions.d.ts +0 -107
  119. package/dist/server/entities/role-permissions.js +0 -115
  120. package/dist/server/entities/role-permissions.js.map +0 -1
  121. package/dist/server/entities/roles.d.ts +0 -196
  122. package/dist/server/entities/roles.js +0 -50
  123. package/dist/server/entities/roles.js.map +0 -1
  124. package/dist/server/entities/schema.d.ts +0 -14
  125. package/dist/server/entities/schema.js +0 -7
  126. package/dist/server/entities/schema.js.map +0 -1
  127. package/dist/server/entities/user-permissions.d.ts +0 -163
  128. package/dist/server/entities/user-permissions.js +0 -193
  129. package/dist/server/entities/user-permissions.js.map +0 -1
  130. package/dist/server/entities/user-public-keys.d.ts +0 -227
  131. package/dist/server/entities/user-public-keys.js +0 -156
  132. package/dist/server/entities/user-public-keys.js.map +0 -1
  133. package/dist/server/entities/user-social-accounts.d.ts +0 -189
  134. package/dist/server/entities/user-social-accounts.js +0 -149
  135. package/dist/server/entities/user-social-accounts.js.map +0 -1
  136. package/dist/server/entities/users.d.ts +0 -235
  137. package/dist/server/entities/users.js +0 -117
  138. package/dist/server/entities/users.js.map +0 -1
  139. package/dist/server/entities/verification-codes.d.ts +0 -191
  140. package/dist/server/entities/verification-codes.js +0 -49
  141. package/dist/server/entities/verification-codes.js.map +0 -1
  142. package/dist/server/routes/auth/index.d.ts +0 -10
  143. package/dist/server/routes/auth/index.js +0 -4460
  144. package/dist/server/routes/auth/index.js.map +0 -1
  145. package/dist/server/routes/index.d.ts +0 -6
  146. package/dist/server/routes/index.js +0 -6584
  147. package/dist/server/routes/index.js.map +0 -1
  148. package/dist/server/routes/invitations/index.d.ts +0 -10
  149. package/dist/server/routes/invitations/index.js +0 -4395
  150. package/dist/server/routes/invitations/index.js.map +0 -1
  151. /package/dist/{lib.d.ts → nextjs/api.d.ts} +0 -0
@@ -0,0 +1,630 @@
1
+ import * as _sinclair_typebox from '@sinclair/typebox';
2
+ import { Static } from '@sinclair/typebox';
3
+ import * as _spfn_core_route from '@spfn/core/route';
4
+ import { User } from '@spfn/auth/server';
5
+
6
+ /**
7
+ * @spfn/auth - Shared Types
8
+ *
9
+ * Common types and constants used across the auth package
10
+ */
11
+ /**
12
+ * Supported JWT signature algorithms
13
+ *
14
+ * - ES256: ECDSA with P-256 and SHA-256 (recommended, smaller keys)
15
+ * - RS256: RSA with SHA-256 (fallback, larger keys)
16
+ */
17
+ declare const KEY_ALGORITHM: readonly ["ES256", "RS256"];
18
+ /**
19
+ * Key algorithm type derived from the const array
20
+ */
21
+ type KeyAlgorithmType = typeof KEY_ALGORITHM[number];
22
+ /**
23
+ * Invitation status enum values
24
+ * Single source of truth for all invitation statuses
25
+ */
26
+ declare const INVITATION_STATUSES: readonly ["pending", "accepted", "expired", "cancelled"];
27
+ /**
28
+ * Invitation status type derived from the const array
29
+ */
30
+ type InvitationStatus = typeof INVITATION_STATUSES[number];
31
+ /**
32
+ * User status enum values
33
+ * Single source of truth for all user statuses
34
+ */
35
+ declare const USER_STATUSES: readonly ["active", "inactive", "suspended"];
36
+ /**
37
+ * User status type derived from the const array
38
+ */
39
+ type UserStatus = typeof USER_STATUSES[number];
40
+ /**
41
+ * Social provider enum values
42
+ * Single source of truth for supported OAuth providers
43
+ */
44
+ declare const SOCIAL_PROVIDERS: readonly ["google", "github", "kakao", "naver"];
45
+ /**
46
+ * Social provider type derived from the const array
47
+ */
48
+ type SocialProvider = typeof SOCIAL_PROVIDERS[number];
49
+
50
+ /**
51
+ * @spfn/auth - Auth Service
52
+ *
53
+ * Core authentication logic: registration, login, logout, password management
54
+ */
55
+
56
+ interface CheckAccountExistsParams {
57
+ email?: string;
58
+ phone?: string;
59
+ }
60
+ interface CheckAccountExistsResult {
61
+ exists: boolean;
62
+ identifier: string;
63
+ identifierType: 'email' | 'phone';
64
+ }
65
+ interface RegisterParams {
66
+ email?: string;
67
+ phone?: string;
68
+ verificationToken: string;
69
+ password: string;
70
+ publicKey: string;
71
+ keyId: string;
72
+ fingerprint: string;
73
+ algorithm?: KeyAlgorithmType;
74
+ }
75
+ interface RegisterResult {
76
+ userId: string;
77
+ email?: string;
78
+ phone?: string;
79
+ }
80
+ interface LoginParams {
81
+ email?: string;
82
+ phone?: string;
83
+ password: string;
84
+ publicKey: string;
85
+ keyId: string;
86
+ fingerprint: string;
87
+ oldKeyId?: string;
88
+ algorithm?: KeyAlgorithmType;
89
+ }
90
+ interface LoginResult {
91
+ userId: string;
92
+ email?: string;
93
+ phone?: string;
94
+ passwordChangeRequired: boolean;
95
+ }
96
+ interface LogoutParams {
97
+ userId: number;
98
+ keyId: string;
99
+ }
100
+ interface ChangePasswordParams {
101
+ userId: number;
102
+ currentPassword: string;
103
+ newPassword: string;
104
+ passwordHash?: string;
105
+ }
106
+ /**
107
+ * Check if an account exists by email or phone
108
+ */
109
+ declare function checkAccountExistsService(params: CheckAccountExistsParams): Promise<CheckAccountExistsResult>;
110
+ /**
111
+ * Register a new user account
112
+ */
113
+ declare function registerService(params: RegisterParams): Promise<RegisterResult>;
114
+ /**
115
+ * Authenticate user and create session
116
+ */
117
+ declare function loginService(params: LoginParams): Promise<LoginResult>;
118
+ /**
119
+ * Logout user (revoke current key)
120
+ */
121
+ declare function logoutService(params: LogoutParams): Promise<void>;
122
+ /**
123
+ * Change user password
124
+ */
125
+ declare function changePasswordService(params: ChangePasswordParams): Promise<void>;
126
+
127
+ declare const EmailSchema: _sinclair_typebox.TString;
128
+ declare const PhoneSchema: _sinclair_typebox.TString;
129
+ declare const PasswordSchema: _sinclair_typebox.TString;
130
+ declare const TargetTypeSchema: _sinclair_typebox.TUnion<[_sinclair_typebox.TLiteral<"email">, _sinclair_typebox.TLiteral<"phone">]>;
131
+ type VerificationTargetType = Static<typeof TargetTypeSchema>;
132
+ declare const VERIFICATION_TARGET_TYPES: readonly ["email", "phone"];
133
+ declare const VerificationPurposeSchema: _sinclair_typebox.TUnion<[_sinclair_typebox.TLiteral<"registration">, _sinclair_typebox.TLiteral<"login">, _sinclair_typebox.TLiteral<"password_reset">, _sinclair_typebox.TLiteral<"email_change">, _sinclair_typebox.TLiteral<"phone_change">]>;
134
+ type VerificationPurpose = Static<typeof VerificationPurposeSchema>;
135
+ declare const VERIFICATION_PURPOSES: readonly ["registration", "login", "password_reset", "email_change", "phone_change"];
136
+
137
+ /**
138
+ * @spfn/auth - Verification Service
139
+ *
140
+ * Handles OTP code generation, validation, and delivery
141
+ */
142
+
143
+ interface SendVerificationCodeParams {
144
+ target: string;
145
+ targetType: VerificationTargetType;
146
+ purpose: VerificationPurpose;
147
+ }
148
+ interface SendVerificationCodeResult {
149
+ success: boolean;
150
+ expiresAt: string;
151
+ }
152
+ interface VerifyCodeParams {
153
+ target: string;
154
+ targetType: VerificationTargetType;
155
+ code: string;
156
+ purpose: VerificationPurpose;
157
+ }
158
+ interface VerifyCodeResult {
159
+ valid: boolean;
160
+ verificationToken: string;
161
+ }
162
+ /**
163
+ * Send verification code via email or SMS
164
+ */
165
+ declare function sendVerificationCodeService(params: SendVerificationCodeParams): Promise<SendVerificationCodeResult>;
166
+ /**
167
+ * Verify OTP code and return verification token
168
+ */
169
+ declare function verifyCodeService(params: VerifyCodeParams): Promise<{
170
+ valid: boolean;
171
+ verificationToken: string;
172
+ }>;
173
+
174
+ /**
175
+ * @spfn/auth - Key Service
176
+ *
177
+ * Handles public key registration, rotation, and revocation
178
+ */
179
+
180
+ interface RegisterPublicKeyParams {
181
+ userId: number;
182
+ keyId: string;
183
+ publicKey: string;
184
+ fingerprint: string;
185
+ algorithm?: KeyAlgorithmType;
186
+ }
187
+ interface RotateKeyParams {
188
+ userId: number;
189
+ oldKeyId: string;
190
+ newKeyId: string;
191
+ newPublicKey: string;
192
+ fingerprint: string;
193
+ algorithm?: KeyAlgorithmType;
194
+ }
195
+ interface RotateKeyResult {
196
+ success: boolean;
197
+ keyId: string;
198
+ }
199
+ interface RevokeKeyParams {
200
+ userId: number;
201
+ keyId: string;
202
+ reason: string;
203
+ }
204
+ /**
205
+ * Register a new public key for a user
206
+ */
207
+ declare function registerPublicKeyService(params: RegisterPublicKeyParams): Promise<void>;
208
+ /**
209
+ * Rotate user's public key (revoke old, register new)
210
+ */
211
+ declare function rotateKeyService(params: RotateKeyParams): Promise<RotateKeyResult>;
212
+ /**
213
+ * Revoke a user's public key
214
+ */
215
+ declare function revokeKeyService(params: RevokeKeyParams): Promise<void>;
216
+
217
+ /**
218
+ * @spfn/auth - RBAC Type Definitions
219
+ *
220
+ * Type definitions for role and permission configuration
221
+ */
222
+ /**
223
+ * Permission category enum values
224
+ * Single source of truth for permission categories
225
+ */
226
+ declare const PERMISSION_CATEGORIES: readonly ["auth", "user", "rbac", "system", "custom"];
227
+ /**
228
+ * Permission category type derived from the const array
229
+ */
230
+ type PermissionCategory = typeof PERMISSION_CATEGORIES[number];
231
+ interface RoleConfig {
232
+ name: string;
233
+ displayName: string;
234
+ description?: string;
235
+ priority?: number;
236
+ isSystem?: boolean;
237
+ isBuiltin?: boolean;
238
+ }
239
+ interface PermissionConfig {
240
+ name: string;
241
+ displayName: string;
242
+ description?: string;
243
+ category?: PermissionCategory;
244
+ isSystem?: boolean;
245
+ isBuiltin?: boolean;
246
+ }
247
+ interface AuthInitOptions {
248
+ /**
249
+ * Additional roles to create
250
+ * Built-in roles (user, admin, superadmin) are automatically included
251
+ */
252
+ roles?: RoleConfig[];
253
+ /**
254
+ * Additional permissions to create
255
+ * Built-in permissions are automatically included
256
+ */
257
+ permissions?: PermissionConfig[];
258
+ /**
259
+ * Role-Permission mappings
260
+ * Built-in mappings are automatically included
261
+ * You can extend built-in roles or define mappings for custom roles
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * {
266
+ * // Extend built-in admin role
267
+ * admin: ['project:create', 'project:delete'],
268
+ *
269
+ * // Define custom role permissions
270
+ * 'project-manager': ['project:create', 'task:assign'],
271
+ * }
272
+ * ```
273
+ */
274
+ rolePermissions?: Record<string, string[]>;
275
+ /**
276
+ * Default role name for new users
277
+ * Must be a valid role name that exists after initialization
278
+ * @default 'user'
279
+ */
280
+ defaultRole?: string;
281
+ /**
282
+ * Default session TTL (Time To Live)
283
+ *
284
+ * Supports:
285
+ * - Number: seconds (e.g., 2592000)
286
+ * - String: duration format ('30d', '12h', '45m', '3600s')
287
+ *
288
+ * Can be overridden at runtime with `remember` parameter.
289
+ *
290
+ * @default '7d' (7 days)
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * {
295
+ * sessionTtl: '30d', // 30 days
296
+ * }
297
+ * ```
298
+ */
299
+ sessionTtl?: string | number;
300
+ }
301
+
302
+ /**
303
+ * @spfn/auth - Main Router
304
+ *
305
+ * Combines all auth-related routes into a single router
306
+ */
307
+ /**
308
+ * Main auth router
309
+ * Exports all authentication-related routes
310
+ *
311
+ * Routes:
312
+ * - Auth: /_auth/exists, /_auth/codes, /_auth/login, /_auth/logout, etc.
313
+ * - Invitations: /_auth/invitations/*
314
+ * - Users: /_auth/users/*
315
+ */
316
+ declare const mainAuthRouter: _spfn_core_route.Router<{
317
+ getUserProfile: _spfn_core_route.RouteDef<{}, {}, UserProfile>;
318
+ getInvitation: _spfn_core_route.RouteDef<{
319
+ params: _sinclair_typebox.TObject<{
320
+ token: _sinclair_typebox.TString;
321
+ }>;
322
+ }, {}, {
323
+ email: string;
324
+ role: string;
325
+ roleDisplayName: string;
326
+ invitedBy: string;
327
+ expiresAt: string;
328
+ metadata: Record<string, any> | undefined;
329
+ }>;
330
+ acceptInvitation: _spfn_core_route.RouteDef<{
331
+ body: _sinclair_typebox.TObject<{
332
+ token: _sinclair_typebox.TString;
333
+ password: _sinclair_typebox.TString;
334
+ }>;
335
+ }, {
336
+ body: _sinclair_typebox.TObject<{
337
+ publicKey: _sinclair_typebox.TString;
338
+ keyId: _sinclair_typebox.TString;
339
+ fingerprint: _sinclair_typebox.TString;
340
+ algorithm: _sinclair_typebox.TUnion<_sinclair_typebox.TLiteral<"ES256" | "RS256">[]>;
341
+ }>;
342
+ }, {
343
+ userId: number;
344
+ email: string;
345
+ role: string;
346
+ }>;
347
+ createInvitation: _spfn_core_route.RouteDef<{
348
+ body: _sinclair_typebox.TObject<{
349
+ email: _sinclair_typebox.TString;
350
+ roleId: _sinclair_typebox.TNumber;
351
+ expiresInDays: _sinclair_typebox.TOptional<_sinclair_typebox.TNumber>;
352
+ metadata: _sinclair_typebox.TOptional<_sinclair_typebox.TAny>;
353
+ }>;
354
+ }, {}, {
355
+ id: number;
356
+ email: string;
357
+ token: string;
358
+ roleId: number;
359
+ expiresAt: string;
360
+ invitationUrl: string;
361
+ }>;
362
+ listInvitations: _spfn_core_route.RouteDef<{
363
+ query: _sinclair_typebox.TObject<{
364
+ status: _sinclair_typebox.TOptional<_sinclair_typebox.TUnion<_sinclair_typebox.TLiteral<"pending" | "accepted" | "expired" | "cancelled">[]>>;
365
+ page: _sinclair_typebox.TOptional<_sinclair_typebox.TNumber>;
366
+ limit: _sinclair_typebox.TOptional<_sinclair_typebox.TNumber>;
367
+ }>;
368
+ }, {}, {
369
+ invitations: {
370
+ id: number;
371
+ email: string;
372
+ token: string;
373
+ roleId: number;
374
+ invitedBy: number;
375
+ status: "pending" | "accepted" | "expired" | "cancelled";
376
+ expiresAt: Date;
377
+ acceptedAt: Date | null;
378
+ cancelledAt: Date | null;
379
+ metadata: Record<string, any> | null;
380
+ createdAt: Date;
381
+ updatedAt: Date;
382
+ role: {
383
+ id: number;
384
+ name: string;
385
+ displayName: string;
386
+ };
387
+ inviter: {
388
+ id: number;
389
+ email: string | null;
390
+ };
391
+ }[];
392
+ total: number;
393
+ page: number;
394
+ limit: number;
395
+ totalPages: number;
396
+ }>;
397
+ cancelInvitation: _spfn_core_route.RouteDef<{
398
+ body: _sinclair_typebox.TObject<{
399
+ id: _sinclair_typebox.TNumber;
400
+ reason: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
401
+ }>;
402
+ }, {}, {
403
+ cancelledAt: string;
404
+ }>;
405
+ resendInvitation: _spfn_core_route.RouteDef<{
406
+ body: _sinclair_typebox.TObject<{
407
+ id: _sinclair_typebox.TNumber;
408
+ expiresInDays: _sinclair_typebox.TOptional<_sinclair_typebox.TNumber>;
409
+ }>;
410
+ }, {}, {
411
+ expiresAt: string;
412
+ }>;
413
+ deleteInvitation: _spfn_core_route.RouteDef<{
414
+ body: _sinclair_typebox.TObject<{
415
+ id: _sinclair_typebox.TNumber;
416
+ }>;
417
+ }, {}, Response>;
418
+ checkAccountExists: _spfn_core_route.RouteDef<{
419
+ body: _sinclair_typebox.TUnion<[_sinclair_typebox.TObject<{
420
+ email: _sinclair_typebox.TString;
421
+ }>, _sinclair_typebox.TObject<{
422
+ phone: _sinclair_typebox.TString;
423
+ }>]>;
424
+ }, {}, CheckAccountExistsResult>;
425
+ sendVerificationCode: _spfn_core_route.RouteDef<{
426
+ body: _sinclair_typebox.TObject<{
427
+ target: _sinclair_typebox.TString;
428
+ targetType: _sinclair_typebox.TUnion<[_sinclair_typebox.TLiteral<"email">, _sinclair_typebox.TLiteral<"phone">]>;
429
+ purpose: _sinclair_typebox.TUnion<[_sinclair_typebox.TLiteral<"registration">, _sinclair_typebox.TLiteral<"login">, _sinclair_typebox.TLiteral<"password_reset">, _sinclair_typebox.TLiteral<"email_change">, _sinclair_typebox.TLiteral<"phone_change">]>;
430
+ }>;
431
+ }, {}, SendVerificationCodeResult>;
432
+ verifyCode: _spfn_core_route.RouteDef<{
433
+ body: _sinclair_typebox.TObject<{
434
+ target: _sinclair_typebox.TString;
435
+ targetType: _sinclair_typebox.TUnion<[_sinclair_typebox.TLiteral<"email">, _sinclair_typebox.TLiteral<"phone">]>;
436
+ code: _sinclair_typebox.TString;
437
+ purpose: _sinclair_typebox.TUnion<[_sinclair_typebox.TLiteral<"registration">, _sinclair_typebox.TLiteral<"login">, _sinclair_typebox.TLiteral<"password_reset">, _sinclair_typebox.TLiteral<"email_change">, _sinclair_typebox.TLiteral<"phone_change">]>;
438
+ }>;
439
+ }, {}, {
440
+ valid: boolean;
441
+ verificationToken: string;
442
+ }>;
443
+ register: _spfn_core_route.RouteDef<{
444
+ body: _sinclair_typebox.TObject<{
445
+ email: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
446
+ phone: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
447
+ verificationToken: _sinclair_typebox.TString;
448
+ password: _sinclair_typebox.TString;
449
+ }>;
450
+ }, {
451
+ body: _sinclair_typebox.TObject<{
452
+ publicKey: _sinclair_typebox.TString;
453
+ keyId: _sinclair_typebox.TString;
454
+ fingerprint: _sinclair_typebox.TString;
455
+ algorithm: _sinclair_typebox.TUnion<_sinclair_typebox.TLiteral<"ES256" | "RS256">[]>;
456
+ }>;
457
+ }, RegisterResult>;
458
+ login: _spfn_core_route.RouteDef<{
459
+ body: _sinclair_typebox.TObject<{
460
+ email: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
461
+ phone: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
462
+ password: _sinclair_typebox.TString;
463
+ }>;
464
+ }, {
465
+ body: _sinclair_typebox.TObject<{
466
+ publicKey: _sinclair_typebox.TString;
467
+ keyId: _sinclair_typebox.TString;
468
+ fingerprint: _sinclair_typebox.TString;
469
+ algorithm: _sinclair_typebox.TUnion<_sinclair_typebox.TLiteral<"ES256" | "RS256">[]>;
470
+ oldKeyId: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
471
+ }>;
472
+ }, LoginResult>;
473
+ logout: _spfn_core_route.RouteDef<{
474
+ body: _sinclair_typebox.TObject<{}>;
475
+ }, {}, Response>;
476
+ rotateKey: _spfn_core_route.RouteDef<{
477
+ body: _sinclair_typebox.TObject<{}>;
478
+ }, {
479
+ body: _sinclair_typebox.TObject<{
480
+ publicKey: _sinclair_typebox.TString;
481
+ keyId: _sinclair_typebox.TString;
482
+ fingerprint: _sinclair_typebox.TString;
483
+ algorithm: _sinclair_typebox.TUnion<_sinclair_typebox.TLiteral<"ES256" | "RS256">[]>;
484
+ }>;
485
+ }, RotateKeyResult>;
486
+ changePassword: _spfn_core_route.RouteDef<{
487
+ body: _sinclair_typebox.TObject<{
488
+ currentPassword: _sinclair_typebox.TString;
489
+ newPassword: _sinclair_typebox.TString;
490
+ }>;
491
+ }, {}, Response>;
492
+ getAuthSession: _spfn_core_route.RouteDef<{}, {}, {
493
+ role: {
494
+ id: number;
495
+ name: string;
496
+ displayName: string;
497
+ priority: number;
498
+ };
499
+ permissions: {
500
+ id: number;
501
+ name: string;
502
+ displayName: string;
503
+ category: "custom" | "user" | "auth" | "rbac" | "system" | undefined;
504
+ }[];
505
+ userId: number;
506
+ email: string | null;
507
+ emailVerified: boolean;
508
+ phoneVerified: boolean;
509
+ }>;
510
+ }>;
511
+
512
+ interface AuthContext {
513
+ user: User;
514
+ userId: string;
515
+ keyId: string;
516
+ }
517
+ declare module 'hono' {
518
+ interface ContextVariableMap {
519
+ auth: AuthContext;
520
+ }
521
+ }
522
+ /**
523
+ * Authentication middleware
524
+ *
525
+ * Verifies client-signed JWT token using stored public key
526
+ * Must be applied to routes that require authentication
527
+ *
528
+ * @example
529
+ * ```typescript
530
+ * // In server.config.ts
531
+ * import { authenticate } from '@spfn/auth/server/middleware';
532
+ *
533
+ * export default defineServerConfig()
534
+ * .middlewares([authenticate])
535
+ * .routes(appRouter)
536
+ * .build();
537
+ *
538
+ * // In route file - skip auth for public routes
539
+ * export const publicRoute = route.get('/health')
540
+ * .skip(['auth']) // Type-safe skip
541
+ * .handler(async (c) => c.success({ status: 'ok' }));
542
+ *
543
+ * // Protected route - auth applied automatically
544
+ * export const protectedRoute = route.get('/profile')
545
+ * .handler(async (c) => {
546
+ * const auth = c.get('auth'); // Get auth context
547
+ * const { user, userId, keyId } = auth;
548
+ * // Or access directly: c.get('auth').user
549
+ * });
550
+ * ```
551
+ */
552
+ declare const authenticate: _spfn_core_route.NamedMiddleware<"auth">;
553
+
554
+ /**
555
+ * Role information for client/API responses
556
+ */
557
+ interface Role {
558
+ id: number;
559
+ name: string;
560
+ displayName: string;
561
+ description: string | null;
562
+ isBuiltin: boolean;
563
+ isSystem: boolean;
564
+ isActive: boolean;
565
+ priority: number;
566
+ createdAt: Date;
567
+ updatedAt: Date;
568
+ }
569
+ /**
570
+ * Permission information for client/API responses
571
+ */
572
+ interface Permission {
573
+ id: number;
574
+ name: string;
575
+ displayName: string;
576
+ description: string | null;
577
+ category: string | null;
578
+ isBuiltin: boolean;
579
+ isSystem: boolean;
580
+ isActive: boolean;
581
+ metadata: Record<string, any> | null;
582
+ createdAt: Date;
583
+ updatedAt: Date;
584
+ }
585
+ interface AuthSession {
586
+ userId: number;
587
+ email: string | null;
588
+ emailVerified: boolean;
589
+ phoneVerified: boolean;
590
+ role: Role;
591
+ permissions: Permission[];
592
+ }
593
+ interface ProfileInfo {
594
+ profileId: number;
595
+ displayName: string;
596
+ firstName: string | null;
597
+ lastName: string | null;
598
+ avatarUrl: string | null;
599
+ bio: string | null;
600
+ locale: string;
601
+ timezone: string;
602
+ website: string | null;
603
+ location: string | null;
604
+ company: string | null;
605
+ jobTitle: string | null;
606
+ createdAt: Date;
607
+ updatedAt: Date;
608
+ }
609
+ /**
610
+ * User Profile Response
611
+ *
612
+ * Complete user data including:
613
+ * - User fields at top level (userId, email, etc.)
614
+ * - Profile data as nested field (optional)
615
+ *
616
+ * Excludes:
617
+ * - Role and permissions (use auth session API)
618
+ */
619
+ interface UserProfile {
620
+ userId: number;
621
+ email: string | null;
622
+ emailVerified: boolean;
623
+ phoneVerified: boolean;
624
+ lastLoginAt: Date | null;
625
+ createdAt: Date;
626
+ updatedAt: Date;
627
+ profile: ProfileInfo | null;
628
+ }
629
+
630
+ export { VerificationPurposeSchema as $, type AuthSession as A, type ChangePasswordParams as B, type CheckAccountExistsResult as C, sendVerificationCodeService as D, verifyCodeService as E, type SendVerificationCodeParams as F, type VerifyCodeParams as G, type VerifyCodeResult as H, INVITATION_STATUSES as I, registerPublicKeyService as J, KEY_ALGORITHM as K, type LoginResult as L, rotateKeyService as M, revokeKeyService as N, type RegisterPublicKeyParams as O, type PermissionConfig as P, type RotateKeyParams as Q, type RoleConfig as R, type SendVerificationCodeResult as S, type RevokeKeyParams as T, type UserProfile as U, type VerificationTargetType as V, authenticate as W, EmailSchema as X, PhoneSchema as Y, PasswordSchema as Z, TargetTypeSchema as _, type RegisterResult as a, type RotateKeyResult as b, type ProfileInfo as c, USER_STATUSES as d, SOCIAL_PROVIDERS as e, type VerificationPurpose as f, VERIFICATION_TARGET_TYPES as g, VERIFICATION_PURPOSES as h, PERMISSION_CATEGORIES as i, type PermissionCategory as j, type AuthInitOptions as k, type KeyAlgorithmType as l, mainAuthRouter as m, type InvitationStatus as n, type UserStatus as o, type SocialProvider as p, type AuthContext as q, checkAccountExistsService as r, registerService as s, loginService as t, logoutService as u, changePasswordService as v, type CheckAccountExistsParams as w, type RegisterParams as x, type LoginParams as y, type LogoutParams as z };