@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
package/README.md
CHANGED
|
@@ -203,6 +203,256 @@ app.bind(myProtectedRoute, [authenticate], async (c) => {
|
|
|
203
203
|
|
|
204
204
|
---
|
|
205
205
|
|
|
206
|
+
## Next.js Integration
|
|
207
|
+
|
|
208
|
+
The `@spfn/auth/nextjs` adapter provides seamless authentication integration for Next.js applications with automatic JWT injection and session management.
|
|
209
|
+
|
|
210
|
+
### Features
|
|
211
|
+
|
|
212
|
+
- **Automatic JWT Generation** - Generates JWT from HttpOnly cookie sessions
|
|
213
|
+
- **Server-Side Interceptor** - Auto-inject JWT in server components and API routes
|
|
214
|
+
- **Client-Side Proxy** - Auto-inject JWT for browser requests via `/api/actions`
|
|
215
|
+
- **High-Level Auth API** - Simple wrappers with automatic key generation
|
|
216
|
+
- **Session Helpers** - Server-side session management utilities
|
|
217
|
+
|
|
218
|
+
### Installation
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
import { authApi } from '@spfn/auth/nextjs';
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### 1. High-Level Auth API
|
|
225
|
+
|
|
226
|
+
The `authApi` object provides simplified authentication functions with automatic key generation and session management:
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
import { authApi } from '@spfn/auth/nextjs';
|
|
230
|
+
|
|
231
|
+
// ✅ Register (automatic key generation + session)
|
|
232
|
+
const result = await authApi.register({
|
|
233
|
+
email: 'user@example.com',
|
|
234
|
+
password: 'SecurePass123!',
|
|
235
|
+
verificationToken: '...' // from verification code
|
|
236
|
+
});
|
|
237
|
+
// → Automatically generates keypair, stores in session cookie
|
|
238
|
+
|
|
239
|
+
// ✅ Login (automatic key generation + rotation)
|
|
240
|
+
const result = await authApi.login({
|
|
241
|
+
email: 'user@example.com',
|
|
242
|
+
password: 'SecurePass123!'
|
|
243
|
+
});
|
|
244
|
+
// → Automatically generates new keypair, rotates old key
|
|
245
|
+
|
|
246
|
+
// ✅ Logout (revokes current key)
|
|
247
|
+
await authApi.logout();
|
|
248
|
+
|
|
249
|
+
// ✅ Rotate Key (before 90-day expiry)
|
|
250
|
+
await authApi.rotateKey();
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
**No manual key generation needed!** The `authApi` handles:
|
|
254
|
+
- ES256 keypair generation
|
|
255
|
+
- Public key registration with server
|
|
256
|
+
- Private key storage in encrypted HttpOnly cookies
|
|
257
|
+
- Automatic key rotation on login
|
|
258
|
+
|
|
259
|
+
### 2. Server-Side JWT Injection
|
|
260
|
+
|
|
261
|
+
For server components and API routes, use the `createAuthInterceptor`:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
// app/api/protected/route.ts
|
|
265
|
+
import { UniversalClient } from '@spfn/core/client';
|
|
266
|
+
import { createAuthInterceptor } from '@spfn/auth/nextjs';
|
|
267
|
+
|
|
268
|
+
// Create client with auth interceptor
|
|
269
|
+
const client = new UniversalClient({
|
|
270
|
+
baseURL: process.env.SPFN_API_URL!,
|
|
271
|
+
requestInterceptor: createAuthInterceptor()
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
export async function GET() {
|
|
275
|
+
// JWT is automatically injected from session cookie
|
|
276
|
+
const data = await client.call(someContract);
|
|
277
|
+
return Response.json(data);
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
**How it works:**
|
|
282
|
+
1. Reads `session` HttpOnly cookie
|
|
283
|
+
2. Unseals session to get `privateKey`, `keyId`, `userId`
|
|
284
|
+
3. Generates JWT signed with `privateKey`
|
|
285
|
+
4. Adds `Authorization: Bearer <jwt>` header automatically
|
|
286
|
+
|
|
287
|
+
### 3. Client-Side Proxy Setup
|
|
288
|
+
|
|
289
|
+
For browser requests, set up the Next.js API Route proxy:
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
// app/api/actions/[...path]/route.ts
|
|
293
|
+
export {
|
|
294
|
+
GET,
|
|
295
|
+
POST,
|
|
296
|
+
PUT,
|
|
297
|
+
DELETE,
|
|
298
|
+
PATCH
|
|
299
|
+
} from '@spfn/auth/nextjs/proxy';
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Then use `UniversalClient` from browser:
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
'use client';
|
|
306
|
+
import { UniversalClient } from '@spfn/core/client';
|
|
307
|
+
|
|
308
|
+
const client = new UniversalClient({
|
|
309
|
+
baseURL: '/api/actions' // Proxy endpoint
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
// Browser → /api/actions/user/profile → SPFN API (with JWT injected)
|
|
313
|
+
const user = await client.call(getUserContract);
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
**How it works:**
|
|
317
|
+
1. Browser makes request to `/api/actions/*`
|
|
318
|
+
2. Proxy reads `session` cookie (server-side only)
|
|
319
|
+
3. Generates JWT from session
|
|
320
|
+
4. Forwards request to SPFN API with `Authorization` header
|
|
321
|
+
5. Returns response to browser
|
|
322
|
+
|
|
323
|
+
### 4. Session Helpers
|
|
324
|
+
|
|
325
|
+
Direct session management utilities:
|
|
326
|
+
|
|
327
|
+
```typescript
|
|
328
|
+
import {
|
|
329
|
+
saveSession,
|
|
330
|
+
getSession,
|
|
331
|
+
clearSession
|
|
332
|
+
} from '@spfn/auth/nextjs';
|
|
333
|
+
|
|
334
|
+
// Save session data (encrypted HttpOnly cookie)
|
|
335
|
+
await saveSession({
|
|
336
|
+
userId: '123',
|
|
337
|
+
privateKey: '...',
|
|
338
|
+
keyId: 'uuid',
|
|
339
|
+
algorithm: 'ES256'
|
|
340
|
+
}, 60 * 60 * 24 * 7); // 7 days
|
|
341
|
+
|
|
342
|
+
// Get current session
|
|
343
|
+
const session = await getSession();
|
|
344
|
+
console.log(session?.userId);
|
|
345
|
+
|
|
346
|
+
// Clear session
|
|
347
|
+
await clearSession();
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### 5. JWT Helper (Manual Usage)
|
|
351
|
+
|
|
352
|
+
Generate JWT from session manually if needed:
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
import { generateJWTFromSession } from '@spfn/auth/nextjs';
|
|
356
|
+
|
|
357
|
+
const jwt = await generateJWTFromSession();
|
|
358
|
+
// → Returns signed JWT or null if no session
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### Updated Middleware (No X-Key-Id Required)
|
|
362
|
+
|
|
363
|
+
The authenticate middleware now extracts `keyId` from the JWT payload, so you **no longer need** to send the `X-Key-Id` header:
|
|
364
|
+
|
|
365
|
+
```typescript
|
|
366
|
+
// ❌ Old way (deprecated)
|
|
367
|
+
fetch('/api/protected', {
|
|
368
|
+
headers: {
|
|
369
|
+
'Authorization': `Bearer ${jwt}`,
|
|
370
|
+
'X-Key-Id': keyId // ← No longer needed!
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
// ✅ New way
|
|
375
|
+
fetch('/api/protected', {
|
|
376
|
+
headers: {
|
|
377
|
+
'Authorization': `Bearer ${jwt}` // keyId extracted from JWT
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
The middleware flow:
|
|
383
|
+
1. Decode JWT to extract `keyId` (without verification)
|
|
384
|
+
2. Fetch public key from database using `keyId`
|
|
385
|
+
3. Verify JWT signature with public key
|
|
386
|
+
4. Validate user and attach to context
|
|
387
|
+
|
|
388
|
+
### Complete Next.js Example
|
|
389
|
+
|
|
390
|
+
```typescript
|
|
391
|
+
// app/auth/login/route.ts
|
|
392
|
+
import { authApi } from '@spfn/auth/nextjs';
|
|
393
|
+
|
|
394
|
+
export async function POST(request: Request) {
|
|
395
|
+
const { email, password } = await request.json();
|
|
396
|
+
|
|
397
|
+
try {
|
|
398
|
+
const result = await authApi.login({ email, password });
|
|
399
|
+
return Response.json({ success: true, userId: result.userId });
|
|
400
|
+
} catch (error) {
|
|
401
|
+
return Response.json({ success: false, error: error.message }, { status: 401 });
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// app/dashboard/page.tsx (Server Component)
|
|
406
|
+
import { UniversalClient } from '@spfn/core/client';
|
|
407
|
+
import { createAuthInterceptor } from '@spfn/auth/nextjs';
|
|
408
|
+
|
|
409
|
+
const client = new UniversalClient({
|
|
410
|
+
baseURL: process.env.SPFN_API_URL!,
|
|
411
|
+
requestInterceptor: createAuthInterceptor()
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
export default async function Dashboard() {
|
|
415
|
+
// JWT automatically injected
|
|
416
|
+
const user = await client.call(getUserContract);
|
|
417
|
+
|
|
418
|
+
return <div>Welcome {user.email}</div>;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// app/profile/page.tsx (Client Component)
|
|
422
|
+
'use client';
|
|
423
|
+
import { UniversalClient } from '@spfn/core/client';
|
|
424
|
+
|
|
425
|
+
const client = new UniversalClient({
|
|
426
|
+
baseURL: '/api/actions'
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
export default function Profile() {
|
|
430
|
+
const [user, setUser] = useState(null);
|
|
431
|
+
|
|
432
|
+
useEffect(() => {
|
|
433
|
+
// Browser → Proxy → SPFN API (JWT auto-injected)
|
|
434
|
+
client.call(getUserContract).then(setUser);
|
|
435
|
+
}, []);
|
|
436
|
+
|
|
437
|
+
return <div>{user?.email}</div>;
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
### Environment Variables
|
|
442
|
+
|
|
443
|
+
```bash
|
|
444
|
+
# Required for session encryption
|
|
445
|
+
SPFN_AUTH_SESSION_SECRET=your-32-char-secret-key
|
|
446
|
+
|
|
447
|
+
# SPFN API URL (server-side)
|
|
448
|
+
SPFN_API_URL=http://localhost:8790
|
|
449
|
+
|
|
450
|
+
# Public API URL (optional, for client-side)
|
|
451
|
+
NEXT_PUBLIC_API_URL=http://localhost:8790
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
---
|
|
455
|
+
|
|
206
456
|
## Service Layer (Reusable Business Logic)
|
|
207
457
|
|
|
208
458
|
The `@spfn/auth` package provides **service functions** that encapsulate all business logic, making it easy to create custom authentication flows while reusing the same secure logic.
|
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import { DeleteInvitationBody } from '../../lib/api/auth-invitations-delete.js';
|
|
2
|
+
export { DeleteInvitationResponse } from '../../lib/api/auth-invitations-delete.js';
|
|
3
|
+
import { ResendInvitationBody } from '../../lib/api/auth-invitations-resend.js';
|
|
4
|
+
export { ResendInvitationResponse } from '../../lib/api/auth-invitations-resend.js';
|
|
5
|
+
import { CancelInvitationBody } from '../../lib/api/auth-invitations-cancel.js';
|
|
6
|
+
export { CancelInvitationResponse } from '../../lib/api/auth-invitations-cancel.js';
|
|
7
|
+
import { AcceptInvitationBody } from '../../lib/api/auth-invitations-accept.js';
|
|
8
|
+
export { AcceptInvitationResponse } from '../../lib/api/auth-invitations-accept.js';
|
|
9
|
+
import { GetInvitationParams, CreateInvitationBody, ListInvitationsQuery } from '../../lib/api/auth-invitations.js';
|
|
10
|
+
export { CreateInvitationResponse, GetInvitationResponse, ListInvitationsResponse } from '../../lib/api/auth-invitations.js';
|
|
11
|
+
import { GetMeBody } from '../../lib/api/auth-me.js';
|
|
12
|
+
import { ChangePasswordBody } from '../../lib/api/auth-password.js';
|
|
13
|
+
export { ChangePasswordResponse } from '../../lib/api/auth-password.js';
|
|
14
|
+
export { RotateKeyResponse } from '../../lib/api/auth-keys-rotate.js';
|
|
15
|
+
export { LogoutResponse } from '../../lib/api/auth-logout.js';
|
|
16
|
+
export { LoginResponse } from '../../lib/api/auth-login.js';
|
|
17
|
+
export { RegisterResponse } from '../../lib/api/auth-register.js';
|
|
18
|
+
import { CheckAccountExistsBody } from '../../lib/api/auth-exists.js';
|
|
19
|
+
export { CheckAccountExistsResponse } from '../../lib/api/auth-exists.js';
|
|
20
|
+
import { VerifyCodeBody } from '../../lib/api/auth-codes-verify.js';
|
|
21
|
+
export { VerifyCodeResponse } from '../../lib/api/auth-codes-verify.js';
|
|
22
|
+
import { SendVerificationCodeBody } from '../../lib/api/auth-codes.js';
|
|
23
|
+
export { SendVerificationCodeResponse } from '../../lib/api/auth-codes.js';
|
|
24
|
+
export { client } from '@spfn/core/client';
|
|
25
|
+
import '@spfn/core';
|
|
26
|
+
import '../../lib/contracts/invitation.js';
|
|
27
|
+
import '@sinclair/typebox';
|
|
28
|
+
import '../../lib/contracts/auth.js';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Client-side login types (without key fields)
|
|
32
|
+
*/
|
|
33
|
+
type ClientLoginParams = {
|
|
34
|
+
body: {
|
|
35
|
+
email?: string;
|
|
36
|
+
phone?: string;
|
|
37
|
+
password: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Client-side register types (without key fields)
|
|
42
|
+
*/
|
|
43
|
+
type ClientRegisterParams = {
|
|
44
|
+
body: {
|
|
45
|
+
email?: string;
|
|
46
|
+
phone?: string;
|
|
47
|
+
password: string;
|
|
48
|
+
verificationToken: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Login with email/password
|
|
53
|
+
*
|
|
54
|
+
* Interceptor automatically generates and injects publicKey fields
|
|
55
|
+
*/
|
|
56
|
+
declare const login: (params: ClientLoginParams) => Promise<{
|
|
57
|
+
message?: string | undefined;
|
|
58
|
+
success: true;
|
|
59
|
+
data: {
|
|
60
|
+
email?: string | undefined;
|
|
61
|
+
phone?: string | undefined;
|
|
62
|
+
userId: string;
|
|
63
|
+
passwordChangeRequired: boolean;
|
|
64
|
+
};
|
|
65
|
+
} | {
|
|
66
|
+
success: false;
|
|
67
|
+
error: {
|
|
68
|
+
details?: any;
|
|
69
|
+
message: string;
|
|
70
|
+
code: string;
|
|
71
|
+
};
|
|
72
|
+
}>;
|
|
73
|
+
/**
|
|
74
|
+
* Register new account
|
|
75
|
+
*
|
|
76
|
+
* Interceptor automatically generates and injects publicKey fields
|
|
77
|
+
*/
|
|
78
|
+
declare const register: (params: ClientRegisterParams) => Promise<{
|
|
79
|
+
success: false;
|
|
80
|
+
error: {
|
|
81
|
+
details?: any;
|
|
82
|
+
message: string;
|
|
83
|
+
code: string;
|
|
84
|
+
};
|
|
85
|
+
} | {
|
|
86
|
+
message?: string | undefined;
|
|
87
|
+
success: true;
|
|
88
|
+
data: {
|
|
89
|
+
email?: string | undefined;
|
|
90
|
+
phone?: string | undefined;
|
|
91
|
+
userId: string;
|
|
92
|
+
};
|
|
93
|
+
}>;
|
|
94
|
+
/**
|
|
95
|
+
* Logout current session
|
|
96
|
+
*
|
|
97
|
+
* Interceptor automatically adds JWT authentication
|
|
98
|
+
*/
|
|
99
|
+
declare const logout: () => Promise<{
|
|
100
|
+
success: false;
|
|
101
|
+
error: {
|
|
102
|
+
details?: any;
|
|
103
|
+
message: string;
|
|
104
|
+
code: string;
|
|
105
|
+
};
|
|
106
|
+
} | {
|
|
107
|
+
message?: string | undefined;
|
|
108
|
+
success: true;
|
|
109
|
+
data: {
|
|
110
|
+
success: boolean;
|
|
111
|
+
};
|
|
112
|
+
}>;
|
|
113
|
+
/**
|
|
114
|
+
* Rotate encryption keys
|
|
115
|
+
*
|
|
116
|
+
* Interceptor automatically generates new key pair and adds JWT authentication
|
|
117
|
+
*/
|
|
118
|
+
declare const rotateKey: () => Promise<{
|
|
119
|
+
success: false;
|
|
120
|
+
error: {
|
|
121
|
+
details?: any;
|
|
122
|
+
message: string;
|
|
123
|
+
code: string;
|
|
124
|
+
};
|
|
125
|
+
} | {
|
|
126
|
+
message?: string | undefined;
|
|
127
|
+
success: true;
|
|
128
|
+
data: {
|
|
129
|
+
success: boolean;
|
|
130
|
+
keyId: string;
|
|
131
|
+
};
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Auth API collection
|
|
135
|
+
*/
|
|
136
|
+
declare const authApi: {
|
|
137
|
+
readonly login: (params: ClientLoginParams) => Promise<{
|
|
138
|
+
message?: string | undefined;
|
|
139
|
+
success: true;
|
|
140
|
+
data: {
|
|
141
|
+
email?: string | undefined;
|
|
142
|
+
phone?: string | undefined;
|
|
143
|
+
userId: string;
|
|
144
|
+
passwordChangeRequired: boolean;
|
|
145
|
+
};
|
|
146
|
+
} | {
|
|
147
|
+
success: false;
|
|
148
|
+
error: {
|
|
149
|
+
details?: any;
|
|
150
|
+
message: string;
|
|
151
|
+
code: string;
|
|
152
|
+
};
|
|
153
|
+
}>;
|
|
154
|
+
readonly register: (params: ClientRegisterParams) => Promise<{
|
|
155
|
+
success: false;
|
|
156
|
+
error: {
|
|
157
|
+
details?: any;
|
|
158
|
+
message: string;
|
|
159
|
+
code: string;
|
|
160
|
+
};
|
|
161
|
+
} | {
|
|
162
|
+
message?: string | undefined;
|
|
163
|
+
success: true;
|
|
164
|
+
data: {
|
|
165
|
+
email?: string | undefined;
|
|
166
|
+
phone?: string | undefined;
|
|
167
|
+
userId: string;
|
|
168
|
+
};
|
|
169
|
+
}>;
|
|
170
|
+
readonly logout: () => Promise<{
|
|
171
|
+
success: false;
|
|
172
|
+
error: {
|
|
173
|
+
details?: any;
|
|
174
|
+
message: string;
|
|
175
|
+
code: string;
|
|
176
|
+
};
|
|
177
|
+
} | {
|
|
178
|
+
message?: string | undefined;
|
|
179
|
+
success: true;
|
|
180
|
+
data: {
|
|
181
|
+
success: boolean;
|
|
182
|
+
};
|
|
183
|
+
}>;
|
|
184
|
+
readonly rotateKey: () => Promise<{
|
|
185
|
+
success: false;
|
|
186
|
+
error: {
|
|
187
|
+
details?: any;
|
|
188
|
+
message: string;
|
|
189
|
+
code: string;
|
|
190
|
+
};
|
|
191
|
+
} | {
|
|
192
|
+
message?: string | undefined;
|
|
193
|
+
success: true;
|
|
194
|
+
data: {
|
|
195
|
+
success: boolean;
|
|
196
|
+
keyId: string;
|
|
197
|
+
};
|
|
198
|
+
}>;
|
|
199
|
+
readonly sendVerificationCode: (options: {
|
|
200
|
+
body: SendVerificationCodeBody;
|
|
201
|
+
}) => Promise<{
|
|
202
|
+
success: false;
|
|
203
|
+
error: {
|
|
204
|
+
details?: any;
|
|
205
|
+
message: string;
|
|
206
|
+
code: string;
|
|
207
|
+
};
|
|
208
|
+
} | {
|
|
209
|
+
message?: string | undefined;
|
|
210
|
+
success: true;
|
|
211
|
+
data: {
|
|
212
|
+
success: boolean;
|
|
213
|
+
expiresAt: string;
|
|
214
|
+
};
|
|
215
|
+
}>;
|
|
216
|
+
readonly verifyCode: (options: {
|
|
217
|
+
body: VerifyCodeBody;
|
|
218
|
+
}) => Promise<{
|
|
219
|
+
success: false;
|
|
220
|
+
error: {
|
|
221
|
+
details?: any;
|
|
222
|
+
message: string;
|
|
223
|
+
code: string;
|
|
224
|
+
};
|
|
225
|
+
} | {
|
|
226
|
+
message?: string | undefined;
|
|
227
|
+
success: true;
|
|
228
|
+
data: {
|
|
229
|
+
verificationToken?: string | undefined;
|
|
230
|
+
valid: boolean;
|
|
231
|
+
};
|
|
232
|
+
}>;
|
|
233
|
+
readonly checkAccountExists: (options: {
|
|
234
|
+
body: CheckAccountExistsBody;
|
|
235
|
+
}) => Promise<{
|
|
236
|
+
success: false;
|
|
237
|
+
error: {
|
|
238
|
+
details?: any;
|
|
239
|
+
message: string;
|
|
240
|
+
code: string;
|
|
241
|
+
};
|
|
242
|
+
} | {
|
|
243
|
+
message?: string | undefined;
|
|
244
|
+
success: true;
|
|
245
|
+
data: {
|
|
246
|
+
exists: boolean;
|
|
247
|
+
identifier: string;
|
|
248
|
+
identifierType: "email" | "phone";
|
|
249
|
+
};
|
|
250
|
+
}>;
|
|
251
|
+
readonly changePassword: (options: {
|
|
252
|
+
body: ChangePasswordBody;
|
|
253
|
+
}) => Promise<{
|
|
254
|
+
success: false;
|
|
255
|
+
error: {
|
|
256
|
+
details?: any;
|
|
257
|
+
message: string;
|
|
258
|
+
code: string;
|
|
259
|
+
};
|
|
260
|
+
} | {
|
|
261
|
+
message?: string | undefined;
|
|
262
|
+
success: true;
|
|
263
|
+
data: {
|
|
264
|
+
success: boolean;
|
|
265
|
+
};
|
|
266
|
+
}>;
|
|
267
|
+
readonly getMe: (options: {
|
|
268
|
+
body: GetMeBody;
|
|
269
|
+
}) => Promise<{
|
|
270
|
+
success: false;
|
|
271
|
+
error: {
|
|
272
|
+
details?: any;
|
|
273
|
+
message: string;
|
|
274
|
+
code: string;
|
|
275
|
+
};
|
|
276
|
+
} | {
|
|
277
|
+
message?: string | undefined;
|
|
278
|
+
success: true;
|
|
279
|
+
data: {
|
|
280
|
+
email?: string | undefined;
|
|
281
|
+
phone?: string | undefined;
|
|
282
|
+
userId: string;
|
|
283
|
+
role: {
|
|
284
|
+
id: number;
|
|
285
|
+
name: string;
|
|
286
|
+
displayName: string;
|
|
287
|
+
priority: number;
|
|
288
|
+
};
|
|
289
|
+
permissions: {
|
|
290
|
+
category?: string | undefined;
|
|
291
|
+
id: number;
|
|
292
|
+
name: string;
|
|
293
|
+
displayName: string;
|
|
294
|
+
}[];
|
|
295
|
+
};
|
|
296
|
+
}>;
|
|
297
|
+
readonly getInvitation: (options: {
|
|
298
|
+
params: GetInvitationParams;
|
|
299
|
+
}) => Promise<{
|
|
300
|
+
success: false;
|
|
301
|
+
error: {
|
|
302
|
+
details?: any;
|
|
303
|
+
message: string;
|
|
304
|
+
code: string;
|
|
305
|
+
};
|
|
306
|
+
} | {
|
|
307
|
+
message?: string | undefined;
|
|
308
|
+
success: true;
|
|
309
|
+
data: {
|
|
310
|
+
metadata?: any;
|
|
311
|
+
email: string;
|
|
312
|
+
expiresAt: string;
|
|
313
|
+
role: string;
|
|
314
|
+
roleDisplayName: string;
|
|
315
|
+
invitedBy: string;
|
|
316
|
+
};
|
|
317
|
+
}>;
|
|
318
|
+
readonly createInvitation: (options: {
|
|
319
|
+
body: CreateInvitationBody;
|
|
320
|
+
}) => Promise<{
|
|
321
|
+
success: false;
|
|
322
|
+
error: {
|
|
323
|
+
details?: any;
|
|
324
|
+
message: string;
|
|
325
|
+
code: string;
|
|
326
|
+
};
|
|
327
|
+
} | {
|
|
328
|
+
message?: string | undefined;
|
|
329
|
+
success: true;
|
|
330
|
+
data: {
|
|
331
|
+
email: string;
|
|
332
|
+
expiresAt: string;
|
|
333
|
+
id: number;
|
|
334
|
+
token: string;
|
|
335
|
+
roleId: number;
|
|
336
|
+
invitationUrl: string;
|
|
337
|
+
};
|
|
338
|
+
}>;
|
|
339
|
+
readonly listInvitations: (options: {
|
|
340
|
+
query?: ListInvitationsQuery;
|
|
341
|
+
}) => Promise<{
|
|
342
|
+
success: false;
|
|
343
|
+
error: {
|
|
344
|
+
details?: any;
|
|
345
|
+
message: string;
|
|
346
|
+
code: string;
|
|
347
|
+
};
|
|
348
|
+
} | {
|
|
349
|
+
message?: string | undefined;
|
|
350
|
+
success: true;
|
|
351
|
+
data: {
|
|
352
|
+
page: number;
|
|
353
|
+
limit: number;
|
|
354
|
+
invitations: {
|
|
355
|
+
acceptedAt?: string | undefined;
|
|
356
|
+
cancelledAt?: string | undefined;
|
|
357
|
+
email: string;
|
|
358
|
+
expiresAt: string;
|
|
359
|
+
role: {
|
|
360
|
+
id: number;
|
|
361
|
+
name: string;
|
|
362
|
+
displayName: string;
|
|
363
|
+
};
|
|
364
|
+
id: number;
|
|
365
|
+
status: string;
|
|
366
|
+
inviter: {
|
|
367
|
+
email: string;
|
|
368
|
+
id: number;
|
|
369
|
+
};
|
|
370
|
+
createdAt: string;
|
|
371
|
+
}[];
|
|
372
|
+
total: number;
|
|
373
|
+
totalPages: number;
|
|
374
|
+
};
|
|
375
|
+
}>;
|
|
376
|
+
readonly acceptInvitation: (options: {
|
|
377
|
+
body: AcceptInvitationBody;
|
|
378
|
+
}) => Promise<{
|
|
379
|
+
success: false;
|
|
380
|
+
error: {
|
|
381
|
+
details?: any;
|
|
382
|
+
message: string;
|
|
383
|
+
code: string;
|
|
384
|
+
};
|
|
385
|
+
} | {
|
|
386
|
+
message?: string | undefined;
|
|
387
|
+
success: true;
|
|
388
|
+
data: {
|
|
389
|
+
email: string;
|
|
390
|
+
userId: number;
|
|
391
|
+
role: string;
|
|
392
|
+
};
|
|
393
|
+
}>;
|
|
394
|
+
readonly cancelInvitation: (options: {
|
|
395
|
+
body: CancelInvitationBody;
|
|
396
|
+
}) => Promise<{
|
|
397
|
+
success: false;
|
|
398
|
+
error: {
|
|
399
|
+
details?: any;
|
|
400
|
+
message: string;
|
|
401
|
+
code: string;
|
|
402
|
+
};
|
|
403
|
+
} | {
|
|
404
|
+
message?: string | undefined;
|
|
405
|
+
success: true;
|
|
406
|
+
data: {
|
|
407
|
+
success: boolean;
|
|
408
|
+
cancelledAt: string;
|
|
409
|
+
};
|
|
410
|
+
}>;
|
|
411
|
+
readonly resendInvitation: (options: {
|
|
412
|
+
body: ResendInvitationBody;
|
|
413
|
+
}) => Promise<{
|
|
414
|
+
success: false;
|
|
415
|
+
error: {
|
|
416
|
+
details?: any;
|
|
417
|
+
message: string;
|
|
418
|
+
code: string;
|
|
419
|
+
};
|
|
420
|
+
} | {
|
|
421
|
+
message?: string | undefined;
|
|
422
|
+
success: true;
|
|
423
|
+
data: {
|
|
424
|
+
success: boolean;
|
|
425
|
+
expiresAt: string;
|
|
426
|
+
};
|
|
427
|
+
}>;
|
|
428
|
+
readonly deleteInvitation: (options: {
|
|
429
|
+
body: DeleteInvitationBody;
|
|
430
|
+
}) => Promise<{
|
|
431
|
+
success: false;
|
|
432
|
+
error: {
|
|
433
|
+
details?: any;
|
|
434
|
+
message: string;
|
|
435
|
+
code: string;
|
|
436
|
+
};
|
|
437
|
+
} | {
|
|
438
|
+
message?: string | undefined;
|
|
439
|
+
success: true;
|
|
440
|
+
data: {
|
|
441
|
+
success: boolean;
|
|
442
|
+
};
|
|
443
|
+
}>;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
export { AcceptInvitationBody, CancelInvitationBody, ChangePasswordBody, CheckAccountExistsBody, type ClientLoginParams, type ClientRegisterParams, CreateInvitationBody, DeleteInvitationBody, GetInvitationParams, ListInvitationsQuery, ResendInvitationBody, SendVerificationCodeBody, VerifyCodeBody, authApi, login, logout, register, rotateKey };
|