@mosano-product-framework/sdk 0.2.0

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 (74) hide show
  1. package/README.md +827 -0
  2. package/README.react.md +348 -0
  3. package/dist/auth/claims-types.d.ts +89 -0
  4. package/dist/auth/claims.d.ts +125 -0
  5. package/dist/auth/cross-tab.d.ts +114 -0
  6. package/dist/auth/errors.d.ts +40 -0
  7. package/dist/auth/index.d.ts +18 -0
  8. package/dist/auth/index.js +5 -0
  9. package/dist/auth/index.js.map +1 -0
  10. package/dist/auth/oauth-state.d.ts +93 -0
  11. package/dist/auth/session-manager.d.ts +253 -0
  12. package/dist/auth/storage.d.ts +36 -0
  13. package/dist/auth/tenant-directory.d.ts +59 -0
  14. package/dist/auth/tenant-selection.d.ts +92 -0
  15. package/dist/chunk-7WAV52EO.js +621 -0
  16. package/dist/chunk-7WAV52EO.js.map +1 -0
  17. package/dist/chunk-AJWM5MDZ.js +410 -0
  18. package/dist/chunk-AJWM5MDZ.js.map +1 -0
  19. package/dist/chunk-EXPYHNPV.js +212 -0
  20. package/dist/chunk-EXPYHNPV.js.map +1 -0
  21. package/dist/chunk-GPWGOYCA.js +85 -0
  22. package/dist/chunk-GPWGOYCA.js.map +1 -0
  23. package/dist/chunk-GQJ3QQPH.js +339 -0
  24. package/dist/chunk-GQJ3QQPH.js.map +1 -0
  25. package/dist/chunk-K2ELAI2X.js +64 -0
  26. package/dist/chunk-K2ELAI2X.js.map +1 -0
  27. package/dist/chunk-LRM6JJ63.js +616 -0
  28. package/dist/chunk-LRM6JJ63.js.map +1 -0
  29. package/dist/chunk-XAXFIIRT.js +959 -0
  30. package/dist/chunk-XAXFIIRT.js.map +1 -0
  31. package/dist/client/core/client-factory.d.ts +61 -0
  32. package/dist/client/core/client.d.ts +144 -0
  33. package/dist/client/core/errors.d.ts +105 -0
  34. package/dist/client/core/index.d.ts +9 -0
  35. package/dist/client/core/middleware.d.ts +67 -0
  36. package/dist/client/core/types.d.ts +99 -0
  37. package/dist/client/graphql/client.d.ts +66 -0
  38. package/dist/client/graphql/factory.d.ts +84 -0
  39. package/dist/client/graphql/operation.d.ts +24 -0
  40. package/dist/client/graphql/types.d.ts +60 -0
  41. package/dist/client/graphql/ws-client.d.ts +116 -0
  42. package/dist/client/index.d.ts +17 -0
  43. package/dist/client/index.js +227 -0
  44. package/dist/client/index.js.map +1 -0
  45. package/dist/client/middlewares/admin-auth.d.ts +90 -0
  46. package/dist/client/middlewares/auth.d.ts +81 -0
  47. package/dist/client/middlewares/index.d.ts +12 -0
  48. package/dist/client/middlewares/logging.d.ts +102 -0
  49. package/dist/client/middlewares/retry.d.ts +138 -0
  50. package/dist/client/middlewares/tenant.d.ts +60 -0
  51. package/dist/client/middlewares/turnstile.d.ts +41 -0
  52. package/dist/client/peer-free.d.ts +25 -0
  53. package/dist/client/utils/url.d.ts +19 -0
  54. package/dist/identity/index.d.ts +85 -0
  55. package/dist/identity/index.js +6 -0
  56. package/dist/identity/index.js.map +1 -0
  57. package/dist/identity/types.d.ts +690 -0
  58. package/dist/identity/v0.d.ts +594 -0
  59. package/dist/index.d.ts +50 -0
  60. package/dist/index.js +24 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/react/context.d.ts +47 -0
  63. package/dist/react/hooks.d.ts +120 -0
  64. package/dist/react/index.d.ts +19 -0
  65. package/dist/react/index.js +308 -0
  66. package/dist/react/index.js.map +1 -0
  67. package/dist/react/provider.d.ts +68 -0
  68. package/dist/react/store.d.ts +85 -0
  69. package/dist/storage/index.d.ts +31 -0
  70. package/dist/storage/index.js +5 -0
  71. package/dist/storage/index.js.map +1 -0
  72. package/dist/storage/types.d.ts +107 -0
  73. package/dist/storage/v0.d.ts +120 -0
  74. package/package.json +99 -0
@@ -0,0 +1,959 @@
1
+ import { createTurnstileMiddleware, createAdminAuthMiddleware } from './chunk-K2ELAI2X.js';
2
+ import { MPFClient, attachStandardMiddlewares } from './chunk-LRM6JJ63.js';
3
+ import { __export, MPFValidationError } from './chunk-AJWM5MDZ.js';
4
+
5
+ // src/identity/index.ts
6
+ var identity_exports = {};
7
+ __export(identity_exports, {
8
+ AuthClientV0: () => AuthClientV0,
9
+ createAdminClient: () => createAdminClient,
10
+ createAuthClient: () => createAuthClient,
11
+ isMFARequired: () => isMFARequired,
12
+ isMFASetupRequired: () => isMFASetupRequired
13
+ });
14
+
15
+ // src/identity/v0.ts
16
+ var AuthClientV0 = class extends MPFClient {
17
+ /** Optional OAuth state store; see {@link AuthClientV0Config.oauthStateStore}. */
18
+ oauthStateStore;
19
+ constructor(config) {
20
+ const { oauthStateStore, ...clientConfig } = config;
21
+ super({
22
+ ...clientConfig,
23
+ baseUrl: `${clientConfig.baseUrl}/v0`
24
+ });
25
+ this.oauthStateStore = oauthStateStore;
26
+ }
27
+ /**
28
+ * Wraps request options with skipAuth: true for public endpoints
29
+ * that do not require authentication headers.
30
+ */
31
+ publicOptions(options) {
32
+ return { ...options, skipAuth: true };
33
+ }
34
+ // ============================================================================
35
+ // Public Endpoints - Authentication
36
+ // ============================================================================
37
+ /**
38
+ * Register a new user with email and password
39
+ *
40
+ * Creates a new user account and returns access and refresh tokens.
41
+ *
42
+ * @param data - User registration data
43
+ * @param options - Optional request options
44
+ * @returns Access and refresh tokens
45
+ */
46
+ async signUpEmailPassword(data, options) {
47
+ const cleanedData = {
48
+ email: data.email,
49
+ password: data.password,
50
+ ...data.first_name ? { first_name: data.first_name } : {},
51
+ ...data.last_name ? { last_name: data.last_name } : {},
52
+ ...data.display_name ? { display_name: data.display_name } : {}
53
+ };
54
+ return this.post(
55
+ "/sign-up-email-password",
56
+ cleanedData,
57
+ this.publicOptions(options)
58
+ );
59
+ }
60
+ /**
61
+ * Login with email and password
62
+ *
63
+ * Authenticates a user and returns access and refresh tokens.
64
+ *
65
+ * @param data - Login credentials
66
+ * @param options - Optional request options
67
+ * @returns Access and refresh tokens
68
+ */
69
+ async signInEmailPassword(data, options) {
70
+ return this.post(
71
+ "/sign-in-email-password",
72
+ data,
73
+ this.publicOptions(options)
74
+ );
75
+ }
76
+ /**
77
+ * Verify MFA code to complete login
78
+ *
79
+ * After a login attempt returns mfa_required, submit the TOTP code
80
+ * along with the MFA ticket to complete authentication.
81
+ *
82
+ * @param data - MFA ticket and TOTP code
83
+ * @param options - Optional request options
84
+ * @returns Access and refresh tokens
85
+ */
86
+ async verifyMFA(data, options) {
87
+ return this.post(
88
+ "/mfa/verify",
89
+ data,
90
+ this.publicOptions(options)
91
+ );
92
+ }
93
+ /**
94
+ * Verify MFA setup to complete first-time enrollment and login
95
+ *
96
+ * After a login attempt returns mfa_setup_required, verify the TOTP
97
+ * setup by submitting a code from the authenticator app.
98
+ *
99
+ * @param data - MFA ticket and verification code
100
+ * @param options - Optional request options
101
+ * @returns Access and refresh tokens
102
+ */
103
+ async verifyMFASetup(data, options) {
104
+ return this.post(
105
+ "/mfa/setup/verify",
106
+ data,
107
+ this.publicOptions(options)
108
+ );
109
+ }
110
+ // ============================================================================
111
+ // Public Endpoints - Password Recovery
112
+ // ============================================================================
113
+ /**
114
+ * Send password recovery code to email
115
+ *
116
+ * Initiates the password recovery process by sending a verification code.
117
+ *
118
+ * @param data - Email address for recovery
119
+ * @param options - Optional request options
120
+ * @returns Success response
121
+ */
122
+ async forgotPasswordWithEmail(data, options) {
123
+ return this.post(
124
+ "/forgot-password-with-email",
125
+ data,
126
+ this.publicOptions(options)
127
+ );
128
+ }
129
+ /**
130
+ * Verify password recovery code
131
+ *
132
+ * Verifies the recovery code and returns a recovery token for password reset.
133
+ *
134
+ * @param data - Email and verification code
135
+ * @param options - Optional request options
136
+ * @returns Recovery token for password reset
137
+ */
138
+ async verifyRecoveryCode(data, options) {
139
+ return this.post(
140
+ "/password/recovery/verify",
141
+ data,
142
+ this.publicOptions(options)
143
+ );
144
+ }
145
+ /**
146
+ * Reset password with recovery token
147
+ *
148
+ * Resets the user's password and returns new access and refresh tokens.
149
+ *
150
+ * @param data - Recovery token and new password
151
+ * @param options - Optional request options
152
+ * @returns Access and refresh tokens
153
+ */
154
+ async resetPassword(data, options) {
155
+ return this.post(
156
+ "/password/reset",
157
+ data,
158
+ this.publicOptions(options)
159
+ );
160
+ }
161
+ // ============================================================================
162
+ // Public Endpoints - Sessions
163
+ // ============================================================================
164
+ /**
165
+ * Renew session with refresh token
166
+ *
167
+ * Exchanges a valid refresh token for new access and refresh tokens.
168
+ *
169
+ * Tenant is selected per request via the `X-MPF-Tenant` header, so a renewal
170
+ * neither takes nor changes a tenant.
171
+ *
172
+ * @param data - Refresh token
173
+ * @param options - Optional request options
174
+ * @returns Access and refresh tokens
175
+ */
176
+ async renewSession(data, options) {
177
+ return this.post(
178
+ "/sessions/renew",
179
+ data,
180
+ this.publicOptions(options)
181
+ );
182
+ }
183
+ /**
184
+ * Revoke session (logout)
185
+ *
186
+ * Revokes the session associated with the provided refresh token.
187
+ * Requires authentication.
188
+ *
189
+ * @param data - Refresh token to revoke
190
+ * @param options - Optional request options
191
+ * @returns Success response
192
+ */
193
+ async revokeSession(data, options) {
194
+ return this.post(
195
+ "/sessions/revoke",
196
+ data,
197
+ options
198
+ );
199
+ }
200
+ // ============================================================================
201
+ // Public Endpoints - Invitations
202
+ // ============================================================================
203
+ /**
204
+ * List pending invitations for the authenticated user
205
+ *
206
+ * Returns all pending invitations for the currently authenticated user.
207
+ * Requires authentication.
208
+ *
209
+ * @param options - Optional request options
210
+ * @returns Array of pending invitations
211
+ */
212
+ async listMyInvitations(options) {
213
+ return this.get(
214
+ "/users/me/invitations",
215
+ options
216
+ );
217
+ }
218
+ /**
219
+ * Preview an invitation (public, pre-auth).
220
+ *
221
+ * Returns the tenant, role, and inviter display name for the
222
+ * invitation-acceptance page. Email is intentionally omitted. Use this
223
+ * to render the accept page before the user signs in.
224
+ *
225
+ * @param token - Invitation token
226
+ * @param options - Optional request options
227
+ * @returns Public-safe invitation preview
228
+ */
229
+ async previewInvitation(token, options) {
230
+ return this.get(
231
+ `/invitations/${encodeURIComponent(token)}`,
232
+ this.publicOptions(options)
233
+ );
234
+ }
235
+ /**
236
+ * Accept an invitation.
237
+ *
238
+ * Requires the user to be authenticated. The user's primary verified
239
+ * email must match the invitation. Creates the membership row.
240
+ *
241
+ * @param token - Invitation token
242
+ * @param options - Optional request options
243
+ * @returns Acceptance result (invitation + new membership)
244
+ */
245
+ async acceptInvitation(token, options) {
246
+ return this.post(
247
+ `/invitations/${encodeURIComponent(token)}/accept`,
248
+ void 0,
249
+ options
250
+ );
251
+ }
252
+ /**
253
+ * Revoke a pending invitation. Caller must be a manager of the tenant
254
+ * that issued the invitation.
255
+ *
256
+ * @param invitationId - Invitation ID (not the token)
257
+ * @param options - Optional request options
258
+ */
259
+ async revokeInvitation(invitationId, options) {
260
+ return this.delete(
261
+ `/invitations/${encodeURIComponent(invitationId)}`,
262
+ options
263
+ );
264
+ }
265
+ // ============================================================================
266
+ // Public Endpoints - Health
267
+ // ============================================================================
268
+ /**
269
+ * Health check endpoint
270
+ *
271
+ * Returns the health status of the service.
272
+ *
273
+ * @param options - Optional request options
274
+ * @returns Health status
275
+ */
276
+ async healthCheck(options) {
277
+ return this.get("/healthz", this.publicOptions(options));
278
+ }
279
+ // ============================================================================
280
+ // Protected Endpoints - User Profile
281
+ // ============================================================================
282
+ /**
283
+ * Get current user profile
284
+ *
285
+ * Returns the authenticated user's profile information.
286
+ * Requires authentication.
287
+ *
288
+ * @param options - Optional request options
289
+ * @returns User profile
290
+ */
291
+ async getMe(options) {
292
+ return this.get("/users/me", options);
293
+ }
294
+ /**
295
+ * Update current user profile
296
+ *
297
+ * Updates the authenticated user's profile information.
298
+ * Requires authentication.
299
+ *
300
+ * @param data - Profile update data
301
+ * @param options - Optional request options
302
+ * @returns Updated user profile
303
+ */
304
+ async updateMe(data, options) {
305
+ return this.patch("/users/me", data, options);
306
+ }
307
+ // ============================================================================
308
+ // Protected Endpoints - Emails
309
+ // ============================================================================
310
+ /**
311
+ * List user emails
312
+ *
313
+ * Returns all email addresses associated with the authenticated user.
314
+ * Requires authentication.
315
+ *
316
+ * @param options - Optional request options
317
+ * @returns Array of email addresses
318
+ */
319
+ async listEmails(options) {
320
+ const response = await this.get("/users/me/emails", options);
321
+ return response.emails;
322
+ }
323
+ /**
324
+ * Add a new email address
325
+ *
326
+ * Adds a new email address to the authenticated user's account.
327
+ * A verification code will be sent to the email.
328
+ * Requires authentication.
329
+ *
330
+ * @param data - Email address to add
331
+ * @param options - Optional request options
332
+ * @returns Added email information
333
+ */
334
+ async addEmail(data, options) {
335
+ return this.post("/users/me/emails", data, options);
336
+ }
337
+ /**
338
+ * Verify an email address
339
+ *
340
+ * Verifies an email address using a verification code.
341
+ * Requires authentication.
342
+ *
343
+ * @param emailId - Email ID to verify
344
+ * @param data - Verification code
345
+ * @param options - Optional request options
346
+ * @returns Success response
347
+ */
348
+ async verifyEmail(emailId, data, options) {
349
+ return this.post(
350
+ `/users/me/emails/${encodeURIComponent(emailId)}/verify`,
351
+ data,
352
+ options
353
+ );
354
+ }
355
+ /**
356
+ * Delete an email address
357
+ *
358
+ * Removes an email address from the authenticated user's account.
359
+ * Cannot delete the primary email.
360
+ * Requires authentication.
361
+ *
362
+ * @param emailId - Email ID to delete
363
+ * @param options - Optional request options
364
+ * @returns Success response
365
+ */
366
+ async deleteEmail(emailId, options) {
367
+ return this.delete(
368
+ `/users/me/emails/${encodeURIComponent(emailId)}`,
369
+ void 0,
370
+ options
371
+ );
372
+ }
373
+ /**
374
+ * Set email as primary
375
+ *
376
+ * Sets the specified email address as the primary email for the user.
377
+ * Email must be verified before it can be set as primary.
378
+ * Requires authentication.
379
+ *
380
+ * @param emailId - Email ID to set as primary
381
+ * @param options - Optional request options
382
+ * @returns Success response
383
+ */
384
+ async setPrimaryEmail(emailId, options) {
385
+ return this.post(
386
+ `/users/me/emails/${encodeURIComponent(emailId)}/set-primary`,
387
+ void 0,
388
+ options
389
+ );
390
+ }
391
+ /**
392
+ * Send email verification code
393
+ *
394
+ * Sends a verification code to the authenticated user's primary email address.
395
+ * Use verifyEmail() to complete the verification.
396
+ * Requires authentication.
397
+ *
398
+ * @param options - Optional request options
399
+ * @returns Success response
400
+ */
401
+ async sendEmailVerification(options) {
402
+ return this.post(
403
+ "/email/send-verification",
404
+ void 0,
405
+ options
406
+ );
407
+ }
408
+ // ============================================================================
409
+ // Protected Endpoints - Phones
410
+ // ============================================================================
411
+ /**
412
+ * List user phones
413
+ *
414
+ * Returns all phone numbers associated with the authenticated user.
415
+ * Requires authentication.
416
+ *
417
+ * @param options - Optional request options
418
+ * @returns Array of phone numbers
419
+ */
420
+ async listPhones(options) {
421
+ const response = await this.get("/users/me/phones", options);
422
+ return response.phones;
423
+ }
424
+ /**
425
+ * Add a new phone number
426
+ *
427
+ * Adds a new phone number to the authenticated user's account.
428
+ * A verification code will be sent to the phone.
429
+ * Requires authentication.
430
+ *
431
+ * @param data - Phone number to add (E.164 format)
432
+ * @param options - Optional request options
433
+ * @returns Added phone information
434
+ */
435
+ async addPhone(data, options) {
436
+ return this.post("/users/me/phones", data, options);
437
+ }
438
+ /**
439
+ * Verify a phone number
440
+ *
441
+ * Verifies a phone number using a verification code.
442
+ * Requires authentication.
443
+ *
444
+ * @param phoneId - Phone ID to verify
445
+ * @param data - Verification code
446
+ * @param options - Optional request options
447
+ * @returns Success response
448
+ */
449
+ async verifyPhone(phoneId, data, options) {
450
+ return this.post(
451
+ `/users/me/phones/${encodeURIComponent(phoneId)}/verify`,
452
+ data,
453
+ options
454
+ );
455
+ }
456
+ /**
457
+ * Delete a phone number
458
+ *
459
+ * Removes a phone number from the authenticated user's account.
460
+ * Cannot delete the primary phone.
461
+ * Requires authentication.
462
+ *
463
+ * @param phoneId - Phone ID to delete
464
+ * @param options - Optional request options
465
+ * @returns Success response
466
+ */
467
+ async deletePhone(phoneId, options) {
468
+ return this.delete(
469
+ `/users/me/phones/${encodeURIComponent(phoneId)}`,
470
+ void 0,
471
+ options
472
+ );
473
+ }
474
+ /**
475
+ * Set phone as primary
476
+ *
477
+ * Sets the specified phone number as the primary phone for the user.
478
+ * Phone must be verified before it can be set as primary.
479
+ * Requires authentication.
480
+ *
481
+ * @param phoneId - Phone ID to set as primary
482
+ * @param options - Optional request options
483
+ * @returns Success response
484
+ */
485
+ async setPrimaryPhone(phoneId, options) {
486
+ return this.post(
487
+ `/users/me/phones/${encodeURIComponent(phoneId)}/set-primary`,
488
+ void 0,
489
+ options
490
+ );
491
+ }
492
+ // ============================================================================
493
+ // Protected Endpoints - Sessions
494
+ // ============================================================================
495
+ /**
496
+ * List user sessions
497
+ *
498
+ * Returns all active sessions for the authenticated user.
499
+ * Requires authentication.
500
+ *
501
+ * @param options - Optional request options
502
+ * @returns Array of sessions
503
+ */
504
+ async listSessions(options) {
505
+ const response = await this.get("/users/me/sessions", options);
506
+ return response.sessions;
507
+ }
508
+ /**
509
+ * Delete a session
510
+ *
511
+ * Revokes a specific session for the authenticated user.
512
+ * Requires authentication.
513
+ *
514
+ * @param sessionId - Session ID to delete
515
+ * @param options - Optional request options
516
+ * @returns Success response
517
+ */
518
+ async deleteSession(sessionId, options) {
519
+ return this.delete(
520
+ `/users/me/sessions/${encodeURIComponent(sessionId)}`,
521
+ void 0,
522
+ options
523
+ );
524
+ }
525
+ // ============================================================================
526
+ // Protected Endpoints - Clients
527
+ // ============================================================================
528
+ /**
529
+ * List authorized OAuth clients
530
+ *
531
+ * Returns all OAuth clients authorized by the authenticated user.
532
+ * Requires authentication.
533
+ *
534
+ * @param options - Optional request options
535
+ * @returns Array of OAuth clients
536
+ */
537
+ async listClients(options) {
538
+ const response = await this.get("/users/me/clients", options);
539
+ return response.clients;
540
+ }
541
+ /**
542
+ * Revoke OAuth client authorization
543
+ *
544
+ * Revokes authorization for a specific OAuth client.
545
+ * Requires authentication.
546
+ *
547
+ * @param clientId - Client ID to revoke
548
+ * @param options - Optional request options
549
+ * @returns Success response
550
+ */
551
+ async deleteClient(clientId, options) {
552
+ return this.delete(
553
+ `/users/me/clients/${encodeURIComponent(clientId)}`,
554
+ void 0,
555
+ options
556
+ );
557
+ }
558
+ // ============================================================================
559
+ // Protected Endpoints - Password
560
+ // ============================================================================
561
+ /**
562
+ * Update password (authenticated)
563
+ *
564
+ * Updates the authenticated user's password.
565
+ * Requires authentication.
566
+ *
567
+ * @param data - Current and new password
568
+ * @param options - Optional request options
569
+ * @returns Success response
570
+ */
571
+ async updatePassword(data, options) {
572
+ return this.post(
573
+ "/password/update",
574
+ data,
575
+ options
576
+ );
577
+ }
578
+ // ============================================================================
579
+ // Protected Endpoints - Tenants
580
+ // ============================================================================
581
+ /**
582
+ * Create a new tenant
583
+ *
584
+ * Creates a new tenant organization. The authenticated user becomes the owner.
585
+ * Requires authentication.
586
+ *
587
+ * @param data - Tenant creation data
588
+ * @param options - Optional request options
589
+ * @returns Created tenant information
590
+ */
591
+ async createTenant(data, options) {
592
+ return this.post("/tenants", data, options);
593
+ }
594
+ /**
595
+ * List current user's tenants
596
+ *
597
+ * Returns all tenants the authenticated user is a member of.
598
+ * Requires authentication.
599
+ *
600
+ * @param options - Optional request options
601
+ * @returns Array of tenant information
602
+ */
603
+ async listMyTenants(options) {
604
+ return this.get("/users/me/tenants", options);
605
+ }
606
+ // ============================================================================
607
+ // Protected Endpoints - Tenant Members
608
+ // ============================================================================
609
+ /**
610
+ * List tenant members
611
+ *
612
+ * Returns all members of the specified tenant.
613
+ * Requires authentication and membership in the tenant.
614
+ *
615
+ * @param tenantId - Tenant ID
616
+ * @param options - Optional request options
617
+ * @returns Array of tenant members
618
+ */
619
+ async listTenantMembers(tenantId, options) {
620
+ const response = await this.get(
621
+ `/tenants/${encodeURIComponent(tenantId)}/members`,
622
+ options
623
+ );
624
+ return response.members;
625
+ }
626
+ /**
627
+ * Invite a member to tenant
628
+ *
629
+ * Sends an invitation to join the tenant. Requires authentication and
630
+ * owner/admin role on the tenant.
631
+ *
632
+ * @param tenantId - Target tenant ID
633
+ * @param data - Invitation data
634
+ * @param options - Optional request options
635
+ * @returns Invitation result, including a copyable accept_url
636
+ */
637
+ async inviteTenantMember(tenantId, data, options) {
638
+ return this.post(
639
+ `/tenants/${encodeURIComponent(tenantId)}/members/invite`,
640
+ data,
641
+ options
642
+ );
643
+ }
644
+ /**
645
+ * List pending invitations issued by the authenticated caller for a tenant.
646
+ *
647
+ * Returns only invitations whose `invited_by` matches the caller. Lets the
648
+ * caller copy the `accept_url` of an invite they previously sent (for
649
+ * example, to re-share if email delivery failed). Callers without a
650
+ * membership, and members who never issued an invite for this tenant,
651
+ * get an empty array.
652
+ *
653
+ * @param tenantId - Tenant ID
654
+ * @param options - Optional request options
655
+ * @returns Array of invitations issued by the caller
656
+ */
657
+ async listTenantInvitationsIssuedByMe(tenantId, options) {
658
+ const response = await this.get(
659
+ `/tenants/${encodeURIComponent(tenantId)}/invitations`,
660
+ options
661
+ );
662
+ return response.invitations;
663
+ }
664
+ /**
665
+ * Update member role
666
+ *
667
+ * Updates the role of a tenant member.
668
+ * Requires authentication and owner role in the tenant.
669
+ *
670
+ * @param tenantId - Tenant ID
671
+ * @param userId - User ID of the member
672
+ * @param data - New role
673
+ * @param options - Optional request options
674
+ * @returns Updated membership information
675
+ */
676
+ async updateTenantMemberRole(tenantId, userId, data, options) {
677
+ return this.patch(
678
+ `/tenants/${encodeURIComponent(tenantId)}/members/${encodeURIComponent(userId)}`,
679
+ data,
680
+ options
681
+ );
682
+ }
683
+ /**
684
+ * Remove member from tenant
685
+ *
686
+ * Removes a member from the tenant.
687
+ * Cannot remove the last owner.
688
+ * Requires authentication and admin/owner role in the tenant.
689
+ *
690
+ * @param tenantId - Tenant ID
691
+ * @param userId - User ID of the member to remove
692
+ * @param options - Optional request options
693
+ * @returns Success response
694
+ */
695
+ async removeTenantMember(tenantId, userId, options) {
696
+ return this.delete(
697
+ `/tenants/${encodeURIComponent(tenantId)}/members/${encodeURIComponent(userId)}`,
698
+ void 0,
699
+ options
700
+ );
701
+ }
702
+ // ============================================================================
703
+ // Protected Endpoints - TOTP (Two-Factor Authentication)
704
+ // ============================================================================
705
+ /**
706
+ * Setup TOTP two-factor authentication
707
+ *
708
+ * Initializes TOTP setup and returns the secret, QR code URL, and backup codes.
709
+ * The setup must be verified with verifyTOTP() before it becomes active.
710
+ * Requires authentication.
711
+ *
712
+ * @param options - Optional request options
713
+ * @returns TOTP setup data including secret and backup codes
714
+ */
715
+ async setupTOTP(options) {
716
+ return this.post(
717
+ "/totp/setup",
718
+ void 0,
719
+ options
720
+ );
721
+ }
722
+ /**
723
+ * Verify TOTP setup
724
+ *
725
+ * Verifies a TOTP code to complete the 2FA setup process.
726
+ * After verification, TOTP will be required on future logins.
727
+ * Requires authentication.
728
+ *
729
+ * @param data - TOTP verification code
730
+ * @param options - Optional request options
731
+ * @returns Success response
732
+ */
733
+ async verifyTOTP(data, options) {
734
+ return this.post("/totp/verify", data, options);
735
+ }
736
+ /**
737
+ * Disable TOTP two-factor authentication
738
+ *
739
+ * Disables TOTP 2FA. Requires a valid TOTP code to confirm.
740
+ * Requires authentication.
741
+ *
742
+ * @param data - TOTP code to confirm disable
743
+ * @param options - Optional request options
744
+ * @returns Success response
745
+ */
746
+ async disableTOTP(data, options) {
747
+ return this.post("/totp/disable", data, options);
748
+ }
749
+ // ============================================================================
750
+ // Passkey / WebAuthn - Public Endpoints
751
+ // ============================================================================
752
+ /**
753
+ * Begin passkey login
754
+ *
755
+ * Starts the WebAuthn authentication process.
756
+ * Returns options to pass to navigator.credentials.get().
757
+ *
758
+ * @param options - Optional request options
759
+ * @returns WebAuthn request options
760
+ */
761
+ async beginPasskeyLogin(options) {
762
+ const response = await this.post(
763
+ "/passkey/login/begin",
764
+ void 0,
765
+ this.publicOptions(options)
766
+ );
767
+ const raw = response.options;
768
+ const opts = "publicKey" in raw ? raw.publicKey : raw;
769
+ return { options: opts, session_key: response.session_key ?? "" };
770
+ }
771
+ /**
772
+ * Complete passkey login
773
+ *
774
+ * Completes the WebAuthn authentication and returns access tokens.
775
+ *
776
+ * @param data - WebAuthn assertion result from navigator.credentials.get()
777
+ * @param options - Optional request options
778
+ * @returns Access and refresh tokens
779
+ */
780
+ async finishPasskeyLogin(data, options) {
781
+ return this.post(
782
+ "/passkey/login/finish",
783
+ data,
784
+ this.publicOptions(options)
785
+ );
786
+ }
787
+ // ============================================================================
788
+ // Passkey / WebAuthn - Protected Endpoints
789
+ // ============================================================================
790
+ /**
791
+ * Begin passkey registration
792
+ *
793
+ * Starts the WebAuthn registration process for the authenticated user.
794
+ * Returns options to pass to navigator.credentials.create().
795
+ * Requires authentication.
796
+ *
797
+ * @param options - Optional request options
798
+ * @returns WebAuthn creation options
799
+ */
800
+ async beginPasskeyRegistration(options) {
801
+ const response = await this.post(
802
+ "/passkeys/register/begin",
803
+ void 0,
804
+ options
805
+ );
806
+ const raw = response.options;
807
+ const opts = "publicKey" in raw ? raw.publicKey : raw;
808
+ return { options: opts };
809
+ }
810
+ /**
811
+ * Complete passkey registration
812
+ *
813
+ * Completes the WebAuthn registration with the attestation result.
814
+ * Requires authentication.
815
+ *
816
+ * @param data - WebAuthn attestation result and optional passkey name
817
+ * @param options - Optional request options
818
+ * @returns Success response
819
+ */
820
+ async finishPasskeyRegistration(data, options) {
821
+ return this.post(
822
+ "/passkeys/register/finish",
823
+ data,
824
+ options
825
+ );
826
+ }
827
+ /**
828
+ * List registered passkeys
829
+ *
830
+ * Returns all passkeys registered by the authenticated user.
831
+ * Requires authentication.
832
+ *
833
+ * @param options - Optional request options
834
+ * @returns Array of passkey information
835
+ */
836
+ async listPasskeys(options) {
837
+ const response = await this.get("/passkeys", options);
838
+ return response.passkeys;
839
+ }
840
+ /**
841
+ * Delete a passkey
842
+ *
843
+ * Removes a registered passkey from the authenticated user's account.
844
+ * If the user has TOTP 2FA enabled, a valid TOTP code must be provided.
845
+ * Requires authentication.
846
+ *
847
+ * @param passkeyId - Passkey ID to delete
848
+ * @param data - Optional request body with TOTP code for 2FA verification
849
+ * @param options - Optional request options
850
+ * @returns Success response
851
+ */
852
+ async deletePasskey(passkeyId, data, options) {
853
+ return this.delete(
854
+ `/passkeys/${encodeURIComponent(passkeyId)}`,
855
+ data,
856
+ options
857
+ );
858
+ }
859
+ // ============================================================================
860
+ // Google OAuth - Public Endpoints
861
+ // ============================================================================
862
+ /**
863
+ * Get Google OAuth authorization URL and its CSRF state.
864
+ *
865
+ * Returns `{ url, state }`. Redirect the user to `url`, and keep `state` —
866
+ * `handleGoogleOAuthCallback` requires it. When the client was constructed
867
+ * with an `oauthStateStore`, the state is persisted here automatically.
868
+ *
869
+ * @param params - Query parameters including redirect_uri
870
+ * @param options - Optional request options
871
+ * @returns The authorization URL and the single-use state to round-trip
872
+ */
873
+ async getGoogleOAuthURL(params, options) {
874
+ const queryParams = new URLSearchParams({ redirect_uri: params.redirect_uri });
875
+ const response = await this.get(
876
+ `/oauth/google/url?${queryParams.toString()}`,
877
+ this.publicOptions(options)
878
+ );
879
+ if (this.oauthStateStore && response.state) {
880
+ this.oauthStateStore.save(response.state);
881
+ }
882
+ return response;
883
+ }
884
+ /**
885
+ * Handle Google OAuth callback
886
+ *
887
+ * Exchanges the Google OAuth authorization code for access tokens.
888
+ * Creates a new user if one doesn't exist with the Google email.
889
+ *
890
+ * The `state` from `getGoogleOAuthURL` is **required**: the server validates
891
+ * it before exchanging the code, and rejects a mismatch, absence, expiry or
892
+ * reuse. See {@link Types.GoogleOAuthCallbackRequest.state}.
893
+ *
894
+ * @param data - OAuth callback data: code, redirect_uri and state
895
+ * @param options - Optional request options
896
+ * @returns Access and refresh tokens
897
+ * @throws {MPFValidationError} If `state` is missing or empty (client-side).
898
+ */
899
+ async handleGoogleOAuthCallback(data, options) {
900
+ if (typeof data.state !== "string" || data.state === "") {
901
+ throw new MPFValidationError(
902
+ "OAuth callback requires the `state` returned by getGoogleOAuthURL. It is the CSRF defence for this flow: without it a callback carrying an attacker's authorization code would be accepted. Persist it across the redirect with createOAuthStateStore().",
903
+ { field: "state" },
904
+ { state: ["state is required"] }
905
+ );
906
+ }
907
+ return this.post(
908
+ "/oauth/google/callback",
909
+ data,
910
+ this.publicOptions(options)
911
+ );
912
+ }
913
+ };
914
+
915
+ // src/identity/types.ts
916
+ function isMFARequired(response) {
917
+ return "mfa_required" in response && response.mfa_required === true;
918
+ }
919
+ function isMFASetupRequired(response) {
920
+ return "mfa_setup_required" in response && response.mfa_setup_required === true;
921
+ }
922
+
923
+ // src/identity/index.ts
924
+ var TURNSTILE_PROTECTED_PATHS = [
925
+ "/sign-up-email-password",
926
+ "/sign-in-email-password",
927
+ "/forgot-password-with-email",
928
+ "/password/recovery/verify",
929
+ "/password/reset",
930
+ "/passkey/login/begin",
931
+ "/passkey/login/finish",
932
+ "/oauth/google/callback",
933
+ "/accept",
934
+ // matches /invitations/{token}/accept
935
+ "/invite"
936
+ // matches /tenants/{id}/members/invite
937
+ ];
938
+ function createAuthClient(options) {
939
+ const { tokenProvider, turnstileProvider, tenantProvider, ...clientConfig } = options;
940
+ const client = new AuthClientV0(clientConfig);
941
+ attachStandardMiddlewares(client, { tokenProvider, tenantProvider });
942
+ if (turnstileProvider) {
943
+ client.use(createTurnstileMiddleware({
944
+ getToken: turnstileProvider.getToken,
945
+ protectedPaths: TURNSTILE_PROTECTED_PATHS
946
+ }));
947
+ }
948
+ return client;
949
+ }
950
+ function createAdminClient(options) {
951
+ const { admin, ...clientConfig } = options;
952
+ const client = new AuthClientV0(clientConfig);
953
+ client.use(createAdminAuthMiddleware(admin));
954
+ return client;
955
+ }
956
+
957
+ export { AuthClientV0, createAdminClient, createAuthClient, identity_exports, isMFARequired, isMFASetupRequired };
958
+ //# sourceMappingURL=chunk-XAXFIIRT.js.map
959
+ //# sourceMappingURL=chunk-XAXFIIRT.js.map