@spfn/auth 0.1.0-alpha.1 → 0.1.0-alpha.86
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +250 -0
- package/dist/adapters/nextjs/api.d.ts +446 -0
- package/dist/adapters/nextjs/api.js +3279 -0
- package/dist/adapters/nextjs/api.js.map +1 -0
- package/dist/adapters/nextjs/server.d.ts +246 -0
- package/dist/adapters/nextjs/server.js +3645 -0
- package/dist/adapters/nextjs/server.js.map +1 -0
- package/dist/index.d.ts +3 -46
- package/dist/index.js +777 -645
- package/dist/index.js.map +1 -1
- package/dist/lib/api/auth-codes-verify.d.ts +37 -0
- package/dist/lib/api/auth-codes-verify.js +2949 -0
- package/dist/lib/api/auth-codes-verify.js.map +1 -0
- package/dist/lib/api/auth-codes.d.ts +37 -0
- package/dist/lib/api/auth-codes.js +2949 -0
- package/dist/lib/api/auth-codes.js.map +1 -0
- package/dist/lib/api/auth-exists.d.ts +38 -0
- package/dist/lib/api/auth-exists.js +2949 -0
- package/dist/lib/api/auth-exists.js.map +1 -0
- package/dist/lib/api/auth-invitations-accept.d.ts +38 -0
- package/dist/lib/api/auth-invitations-accept.js +2883 -0
- package/dist/lib/api/auth-invitations-accept.js.map +1 -0
- package/dist/lib/api/auth-invitations-cancel.d.ts +37 -0
- package/dist/lib/api/auth-invitations-cancel.js +2883 -0
- package/dist/lib/api/auth-invitations-cancel.js.map +1 -0
- package/dist/lib/api/auth-invitations-delete.d.ts +36 -0
- package/dist/lib/api/auth-invitations-delete.js +2883 -0
- package/dist/lib/api/auth-invitations-delete.js.map +1 -0
- package/dist/lib/api/auth-invitations-resend.d.ts +37 -0
- package/dist/lib/api/auth-invitations-resend.js +2883 -0
- package/dist/lib/api/auth-invitations-resend.js.map +1 -0
- package/dist/lib/api/auth-invitations.d.ts +109 -0
- package/dist/lib/api/auth-invitations.js +2887 -0
- package/dist/lib/api/auth-invitations.js.map +1 -0
- package/dist/lib/api/auth-keys-rotate.d.ts +37 -0
- package/dist/lib/api/auth-keys-rotate.js +2949 -0
- package/dist/lib/api/auth-keys-rotate.js.map +1 -0
- package/dist/lib/api/auth-login.d.ts +39 -0
- package/dist/lib/api/auth-login.js +2949 -0
- package/dist/lib/api/auth-login.js.map +1 -0
- package/dist/lib/api/auth-logout.d.ts +36 -0
- package/dist/lib/api/auth-logout.js +2949 -0
- package/dist/lib/api/auth-logout.js.map +1 -0
- package/dist/lib/api/auth-me.d.ts +50 -0
- package/dist/lib/api/auth-me.js +2949 -0
- package/dist/lib/api/auth-me.js.map +1 -0
- package/dist/lib/api/auth-password.d.ts +36 -0
- package/dist/lib/api/auth-password.js +2949 -0
- package/dist/lib/api/auth-password.js.map +1 -0
- package/dist/lib/api/auth-register.d.ts +38 -0
- package/dist/lib/api/auth-register.js +2949 -0
- package/dist/lib/api/auth-register.js.map +1 -0
- package/dist/lib/api/index.d.ts +356 -0
- package/dist/lib/api/index.js +3261 -0
- package/dist/lib/api/index.js.map +1 -0
- package/dist/lib/config.d.ts +70 -0
- package/dist/lib/config.js +64 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/contracts/auth.d.ts +41 -1
- package/dist/lib/contracts/auth.js +28 -0
- package/dist/lib/contracts/auth.js.map +1 -1
- package/dist/lib/contracts/index.d.ts +1 -1
- package/dist/lib/contracts/index.js +28 -0
- package/dist/lib/contracts/index.js.map +1 -1
- package/dist/lib/crypto.d.ts +76 -0
- package/dist/lib/crypto.js +127 -0
- package/dist/lib/crypto.js.map +1 -0
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/index.js +313 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/session.d.ts +68 -0
- package/dist/lib/session.js +126 -0
- package/dist/lib/session.js.map +1 -0
- package/dist/{api-BcQM4WKb.d.ts → lib/types/api.d.ts} +2 -2
- package/dist/lib/types/api.js +1 -0
- package/dist/lib/types/api.js.map +1 -0
- package/dist/lib/types/index.d.ts +3 -0
- package/dist/lib/types/index.js +2647 -0
- package/dist/lib/types/index.js.map +1 -0
- package/dist/lib/types/schemas.d.ts +45 -0
- package/dist/lib/types/schemas.js +2647 -0
- package/dist/lib/types/schemas.js.map +1 -0
- package/dist/lib.d.ts +2 -0
- package/dist/lib.js +1 -0
- package/dist/lib.js.map +1 -0
- package/dist/plugin.js +777 -645
- package/dist/plugin.js.map +1 -1
- package/dist/server/entities/index.d.ts +1 -0
- package/dist/server/entities/index.js +23 -27
- package/dist/server/entities/index.js.map +1 -1
- package/dist/server/entities/invitations.js +12 -9
- package/dist/server/entities/invitations.js.map +1 -1
- package/dist/server/entities/permissions.js +8 -3
- package/dist/server/entities/permissions.js.map +1 -1
- package/dist/server/entities/role-permissions.js +12 -9
- package/dist/server/entities/role-permissions.js.map +1 -1
- package/dist/server/entities/roles.js +8 -3
- package/dist/server/entities/roles.js.map +1 -1
- package/dist/server/entities/schema.d.ts +14 -0
- package/dist/server/entities/schema.js +7 -0
- package/dist/server/entities/schema.js.map +1 -0
- package/dist/server/entities/user-permissions.js +14 -12
- package/dist/server/entities/user-permissions.js.map +1 -1
- package/dist/server/entities/user-public-keys.js +12 -9
- package/dist/server/entities/user-public-keys.js.map +1 -1
- package/dist/server/entities/user-social-accounts.js +12 -9
- package/dist/server/entities/user-social-accounts.js.map +1 -1
- package/dist/server/entities/users.js +10 -6
- package/dist/server/entities/users.js.map +1 -1
- package/dist/server/entities/verification-codes.js +8 -3
- package/dist/server/entities/verification-codes.js.map +1 -1
- package/dist/server/routes/auth/index.js +495 -512
- package/dist/server/routes/auth/index.js.map +1 -1
- package/dist/server/routes/index.js +775 -545
- package/dist/server/routes/index.js.map +1 -1
- package/dist/server/routes/invitations/index.js +416 -230
- package/dist/server/routes/invitations/index.js.map +1 -1
- package/dist/server.d.ts +91 -62
- package/dist/server.js +320 -327
- package/dist/server.js.map +1 -1
- package/migrations/{0000_tired_gambit.sql → 0000_complex_swordsman.sql} +2 -0
- package/migrations/meta/0000_snapshot.json +4 -2
- package/migrations/meta/_journal.json +2 -2
- package/package.json +30 -3
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import * as _spfn_core_client_nextjs from '@spfn/core/client/nextjs';
|
|
2
|
+
import { InterceptorRule } from '@spfn/core/client/nextjs';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
import { SessionData } from '../../lib/session.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* General Authentication Interceptor
|
|
9
|
+
*
|
|
10
|
+
* Handles authentication for all API requests except login/register
|
|
11
|
+
* - Session validation and renewal
|
|
12
|
+
* - JWT generation and signing
|
|
13
|
+
* - Expired session cleanup
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* General Authentication Interceptor
|
|
18
|
+
*
|
|
19
|
+
* Applies to all /_auth/* paths except login/register/codes
|
|
20
|
+
* - Validates session
|
|
21
|
+
* - Generates JWT token
|
|
22
|
+
* - Refreshes session if needed
|
|
23
|
+
* - Clears expired sessions
|
|
24
|
+
*/
|
|
25
|
+
declare const generalAuthInterceptor: InterceptorRule;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Login/Register Interceptor
|
|
29
|
+
*
|
|
30
|
+
* Automatically handles key generation and session management
|
|
31
|
+
* for login and register endpoints
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Login and Register Interceptor
|
|
36
|
+
*
|
|
37
|
+
* Request: Generates key pair and adds publicKey to request body
|
|
38
|
+
* Response: Saves privateKey to HttpOnly cookie
|
|
39
|
+
*/
|
|
40
|
+
declare const loginRegisterInterceptor: InterceptorRule;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Key Rotation Interceptor
|
|
44
|
+
*
|
|
45
|
+
* Handles key rotation with new key generation and session update
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Key Rotation Interceptor
|
|
50
|
+
*
|
|
51
|
+
* Request: Generates new key pair and adds to body, authenticates with current key
|
|
52
|
+
* Response: Updates session with new privateKey
|
|
53
|
+
*/
|
|
54
|
+
declare const keyRotationInterceptor: InterceptorRule;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* All auth interceptors
|
|
58
|
+
*
|
|
59
|
+
* Execution order:
|
|
60
|
+
* 1. loginRegisterInterceptor - Handles login/register (key generation + session save)
|
|
61
|
+
* 2. keyRotationInterceptor - Handles key rotation (new key generation + session update)
|
|
62
|
+
* 3. generalAuthInterceptor - Handles all authenticated requests (session validation + JWT injection + session renewal)
|
|
63
|
+
*/
|
|
64
|
+
declare const authInterceptors: _spfn_core_client_nextjs.InterceptorRule[];
|
|
65
|
+
|
|
66
|
+
interface RequireAuthProps {
|
|
67
|
+
/**
|
|
68
|
+
* Children to render if authenticated
|
|
69
|
+
*/
|
|
70
|
+
children: ReactNode;
|
|
71
|
+
/**
|
|
72
|
+
* Path to redirect to if not authenticated
|
|
73
|
+
* @default '/login'
|
|
74
|
+
*/
|
|
75
|
+
redirectTo?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Fallback UI to show instead of redirecting
|
|
78
|
+
*/
|
|
79
|
+
fallback?: ReactNode;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Require Authentication Guard
|
|
83
|
+
*
|
|
84
|
+
* Ensures user is logged in before rendering children
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```tsx
|
|
88
|
+
* <RequireAuth redirectTo="/login">
|
|
89
|
+
* <DashboardContent />
|
|
90
|
+
* </RequireAuth>
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @example With fallback
|
|
94
|
+
* ```tsx
|
|
95
|
+
* <RequireAuth fallback={<LoginPrompt />}>
|
|
96
|
+
* <PrivateContent />
|
|
97
|
+
* </RequireAuth>
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
declare function RequireAuth({ children, redirectTo, fallback, }: RequireAuthProps): Promise<react_jsx_runtime.JSX.Element>;
|
|
101
|
+
|
|
102
|
+
interface RequireRoleProps {
|
|
103
|
+
/**
|
|
104
|
+
* Required role(s) - user must have at least one
|
|
105
|
+
*/
|
|
106
|
+
roles: string | string[];
|
|
107
|
+
/**
|
|
108
|
+
* Children to render if user has required role
|
|
109
|
+
*/
|
|
110
|
+
children: ReactNode;
|
|
111
|
+
/**
|
|
112
|
+
* Path to redirect to if user doesn't have role
|
|
113
|
+
* @default '/unauthorized'
|
|
114
|
+
*/
|
|
115
|
+
redirectTo?: string;
|
|
116
|
+
/**
|
|
117
|
+
* Fallback UI to show instead of redirecting
|
|
118
|
+
*/
|
|
119
|
+
fallback?: ReactNode;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Require Role Guard
|
|
123
|
+
*
|
|
124
|
+
* Ensures user has at least one of the specified roles
|
|
125
|
+
*
|
|
126
|
+
* @example Single role
|
|
127
|
+
* ```tsx
|
|
128
|
+
* <RequireRole roles="admin">
|
|
129
|
+
* <AdminPanel />
|
|
130
|
+
* </RequireRole>
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @example Multiple roles (OR condition)
|
|
134
|
+
* ```tsx
|
|
135
|
+
* <RequireRole roles={['admin', 'manager']}>
|
|
136
|
+
* <ManagementDashboard />
|
|
137
|
+
* </RequireRole>
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @example With fallback
|
|
141
|
+
* ```tsx
|
|
142
|
+
* <RequireRole roles="admin" fallback={<AccessDenied />}>
|
|
143
|
+
* <AdminContent />
|
|
144
|
+
* </RequireRole>
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
declare function RequireRole({ roles, children, redirectTo, fallback, }: RequireRoleProps): Promise<react_jsx_runtime.JSX.Element>;
|
|
148
|
+
|
|
149
|
+
interface RequirePermissionProps {
|
|
150
|
+
/**
|
|
151
|
+
* Required permission(s) - user must have at least one
|
|
152
|
+
*/
|
|
153
|
+
permissions: string | string[];
|
|
154
|
+
/**
|
|
155
|
+
* Children to render if user has required permission
|
|
156
|
+
*/
|
|
157
|
+
children: ReactNode;
|
|
158
|
+
/**
|
|
159
|
+
* Path to redirect to if user doesn't have permission
|
|
160
|
+
* @default '/unauthorized'
|
|
161
|
+
*/
|
|
162
|
+
redirectTo?: string;
|
|
163
|
+
/**
|
|
164
|
+
* Fallback UI to show instead of redirecting
|
|
165
|
+
*/
|
|
166
|
+
fallback?: ReactNode;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Require Permission Guard
|
|
170
|
+
*
|
|
171
|
+
* Ensures user has at least one of the specified permissions
|
|
172
|
+
*
|
|
173
|
+
* @example Single permission
|
|
174
|
+
* ```tsx
|
|
175
|
+
* <RequirePermission permissions="user:delete">
|
|
176
|
+
* <DeleteUserButton />
|
|
177
|
+
* </RequirePermission>
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* @example Multiple permissions (OR condition)
|
|
181
|
+
* ```tsx
|
|
182
|
+
* <RequirePermission permissions={['user:delete', 'user:update']}>
|
|
183
|
+
* <UserManagement />
|
|
184
|
+
* </RequirePermission>
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @example With fallback
|
|
188
|
+
* ```tsx
|
|
189
|
+
* <RequirePermission permissions="project:create" fallback={<UpgradePrompt />}>
|
|
190
|
+
* <CreateProject />
|
|
191
|
+
* </RequirePermission>
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
declare function RequirePermission({ permissions, children, redirectTo, fallback, }: RequirePermissionProps): Promise<react_jsx_runtime.JSX.Element>;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Server-side auth utilities for guards
|
|
198
|
+
*
|
|
199
|
+
* Uses API to check permissions in real-time
|
|
200
|
+
*/
|
|
201
|
+
/**
|
|
202
|
+
* Get user role
|
|
203
|
+
*/
|
|
204
|
+
declare function getUserRole(): Promise<string | null>;
|
|
205
|
+
/**
|
|
206
|
+
* Get user permissions
|
|
207
|
+
*/
|
|
208
|
+
declare function getUserPermissions(): Promise<string[]>;
|
|
209
|
+
/**
|
|
210
|
+
* Check if user has any of the specified roles
|
|
211
|
+
*/
|
|
212
|
+
declare function hasAnyRole(requiredRoles: string[]): Promise<boolean>;
|
|
213
|
+
/**
|
|
214
|
+
* Check if user has any of the specified permissions
|
|
215
|
+
*/
|
|
216
|
+
declare function hasAnyPermission(requiredPermissions: string[]): Promise<boolean>;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Session helpers for Next.js
|
|
220
|
+
*
|
|
221
|
+
* Server-side only (uses next/headers)
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Public session information (excludes sensitive data)
|
|
226
|
+
*/
|
|
227
|
+
interface PublicSession {
|
|
228
|
+
/** User ID */
|
|
229
|
+
userId: string;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Save session to HttpOnly cookie
|
|
233
|
+
*/
|
|
234
|
+
declare function saveSession(data: SessionData, maxAge?: number): Promise<void>;
|
|
235
|
+
/**
|
|
236
|
+
* Get session from HttpOnly cookie
|
|
237
|
+
*
|
|
238
|
+
* Returns public session info only (excludes privateKey, algorithm, keyId)
|
|
239
|
+
*/
|
|
240
|
+
declare function getSession(): Promise<PublicSession | null>;
|
|
241
|
+
/**
|
|
242
|
+
* Clear session cookie
|
|
243
|
+
*/
|
|
244
|
+
declare function clearSession(): Promise<void>;
|
|
245
|
+
|
|
246
|
+
export { type PublicSession, RequireAuth, type RequireAuthProps, RequirePermission, type RequirePermissionProps, RequireRole, type RequireRoleProps, SessionData, authInterceptors, generalAuthInterceptor as authenticationInterceptor, clearSession, generalAuthInterceptor, getSession, getUserPermissions, getUserRole, hasAnyPermission, hasAnyRole, keyRotationInterceptor, loginRegisterInterceptor, saveSession };
|