@omnibase/core-js 0.1.5 → 0.1.7

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.
@@ -1,124 +1,681 @@
1
1
  /**
2
- * Return type of the `acceptTenantInvite` function
2
+ * Request data for accepting a tenant invitation
3
+ *
4
+ * Contains the secure token that was provided in the invitation.
5
+ * This token is validated server-side to ensure the invitation
6
+ * is legitimate, not expired, and hasn't been used before.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const acceptData: AcceptTenantInviteRequest = {
11
+ * token: 'inv_secure_token_abc123xyz'
12
+ * };
13
+ * ```
14
+ *
15
+ * @since 1.0.0
16
+ * @public
17
+ * @group User Management
18
+ */
19
+ type AcceptTenantInviteRequest = {
20
+ /** Secure invitation token from the email invitation */
21
+ token: string;
22
+ };
23
+ /**
24
+ * Response structure for accepting a tenant invitation
25
+ *
26
+ * Contains the ID of the tenant that the user has successfully joined
27
+ * along with a confirmation message. After accepting an invitation,
28
+ * the user becomes a member of the tenant with the role specified
29
+ * in the original invitation.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const response: AcceptTenantInviteResponse = {
34
+ * data: {
35
+ * tenant_id: 'tenant_abc123',
36
+ * message: 'Successfully joined tenant'
37
+ * },
38
+ * status: 200
39
+ * };
40
+ * ```
41
+ *
42
+ * @since 1.0.0
43
+ * @public
44
+ * @group User Management
3
45
  */
4
46
  type AcceptTenantInviteResponse = ApiResponse<{
47
+ /** ID of the tenant the user has joined */
5
48
  tenant_id: string;
49
+ /** Success message confirming the invitation acceptance */
6
50
  message: string;
51
+ /** JWT token for postgrest RLS */
52
+ token: string;
7
53
  }>;
8
54
  /**
9
- * Accept a tenant invite using token
10
- * Calls PUT /api/v1/tenants/invites/accept
55
+ * Accepts a tenant invitation using a secure token
56
+ *
57
+ * Processes a tenant invitation by validating the provided token and
58
+ * adding the authenticated user to the specified tenant. The invitation
59
+ * token is consumed during this process and cannot be used again.
60
+ *
61
+ * The function performs several validations:
62
+ * - Verifies the token exists and is valid
63
+ * - Checks that the invitation hasn't expired
64
+ * - Ensures the invitation hasn't already been used
65
+ * - Confirms the user is authenticated via session cookies
66
+ *
67
+ * Upon successful acceptance, the user is granted access to the tenant
68
+ * with the role specified in the original invitation. The invitation
69
+ * record is marked as used and cannot be accepted again.
70
+ *
71
+ * @param token - The secure invitation token from the email invitation
72
+ *
73
+ * @returns Promise resolving to the tenant ID and success confirmation
74
+ *
75
+ * @throws {Error} When OMNIBASE_API_URL environment variable is not configured
76
+ * @throws {Error} When the token parameter is missing or empty
77
+ * @throws {Error} When the invitation token is invalid or expired
78
+ * @throws {Error} When the invitation has already been accepted
79
+ * @throws {Error} When the user is not authenticated
80
+ * @throws {Error} When the API request fails due to network issues
81
+ * @throws {Error} When the server returns an error response (4xx, 5xx status codes)
82
+ *
83
+ * @example
84
+ * Basic invitation acceptance:
85
+ * ```typescript
86
+ * const result = await acceptTenantInvite('inv_secure_token_abc123');
87
+ *
88
+ * console.log(`Successfully joined tenant: ${result.data.tenant_id}`);
89
+ * // User can now access tenant resources
90
+ * await switchActiveTenant(result.data.tenant_id);
91
+ * ```
92
+ *
93
+ * @example
94
+ * Handling the invitation flow:
95
+ * ```typescript
96
+ * // Typically called from an invitation link like:
97
+ * // https://app.com/accept-invite?token=inv_secure_token_abc123
98
+ *
99
+ * const urlParams = new URLSearchParams(window.location.search);
100
+ * const inviteToken = urlParams.get('token');
101
+ *
102
+ * if (inviteToken) {
103
+ * try {
104
+ * const result = await acceptTenantInvite(inviteToken);
105
+ *
106
+ * // Success - redirect to tenant dashboard
107
+ * window.location.href = `/dashboard?tenant=${result.data.tenant_id}`;
108
+ * } catch (error) {
109
+ * console.error('Failed to accept invitation:', error.message);
110
+ * // Show error to user
111
+ * }
112
+ * }
113
+ * ```
114
+ *
115
+ *
116
+ * @since 1.0.0
117
+ * @public
118
+ * @group User Management
11
119
  */
12
- declare function acceptTenantInvite(token: string): Promise<ApiResponse<{
13
- tenant_id: string;
14
- message: string;
15
- }>>;
120
+ declare function acceptTenantInvite(token: string): Promise<AcceptTenantInviteResponse>;
16
121
 
17
122
  /**
18
- * Return type of the `createTenantUserInvite` function
123
+ * Response structure for tenant user invite creation
124
+ *
125
+ * Contains the newly created invite information including the secure token
126
+ * that will be sent to the invitee. The invite has an expiration time and
127
+ * can only be used once to join the specified tenant.
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * const response: CreateTenantUserInviteResponse = {
132
+ * data: {
133
+ * invite: {
134
+ * id: 'invite_123',
135
+ * tenant_id: 'tenant_abc',
136
+ * email: 'colleague@company.com',
137
+ * role: 'member',
138
+ * token: 'inv_secure_token_xyz',
139
+ * expires_at: '2024-02-15T10:30:00Z'
140
+ * },
141
+ * message: 'Invite created successfully'
142
+ * },
143
+ * status: 201
144
+ * };
145
+ * ```
146
+ *
147
+ * @since 1.0.0
148
+ * @public
149
+ * @group User Management
19
150
  */
20
151
  type CreateTenantUserInviteResponse = ApiResponse<{
152
+ /** The newly created tenant invite */
21
153
  invite: TenantInvite;
154
+ /** Success message confirming invite creation */
22
155
  message: string;
23
156
  }>;
24
157
  /**
25
- * The TenantInvite Schema that maps directly to `auth.tenant_invites`
158
+ * Tenant invitation entity structure
159
+ *
160
+ * Represents a pending invitation for a user to join a specific tenant
161
+ * with a defined role. The invite contains a secure token that expires
162
+ * after a certain time period and can only be used once.
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * const invite: TenantInvite = {
167
+ * id: 'invite_abc123',
168
+ * tenant_id: 'tenant_xyz789',
169
+ * email: 'newuser@company.com',
170
+ * role: 'member',
171
+ * token: 'inv_secure_abc123xyz',
172
+ * inviter_id: 'user_owner123',
173
+ * expires_at: '2024-02-01T12:00:00Z',
174
+ * created_at: '2024-01-25T12:00:00Z',
175
+ * used_at: undefined // null until invite is accepted
176
+ * };
177
+ * ```
178
+ *
179
+ * @since 1.0.0
180
+ * @public
181
+ * @group User Management
26
182
  */
27
183
  interface TenantInvite {
184
+ /** Unique identifier for the invitation */
28
185
  id: string;
186
+ /** ID of the tenant the user is being invited to */
29
187
  tenant_id: string;
188
+ /** Email address of the invited user */
30
189
  email: string;
190
+ /** Role the user will have in the tenant (e.g., 'owner', 'admin', 'member') */
31
191
  role: string;
192
+ /** Secure token used to accept the invitation */
32
193
  token: string;
194
+ /** ID of the user who created this invitation */
33
195
  inviter_id: string;
196
+ /** ISO 8601 timestamp when the invitation expires */
34
197
  expires_at: string;
198
+ /** ISO 8601 timestamp when the invitation was created */
35
199
  created_at: string;
200
+ /** ISO 8601 timestamp when the invitation was accepted (null if unused) */
36
201
  used_at?: string;
37
202
  }
38
203
  /**
39
- * Invite Data describing who the invite is going to `email` and their
40
- * role `role`
204
+ * Required data for creating a tenant user invitation
205
+ *
206
+ * Specifies the email address of the user to invite and their intended
207
+ * role within the tenant. The role determines what permissions the user
208
+ * will have once they accept the invitation.
209
+ *
210
+ * @example
211
+ * ```typescript
212
+ * const inviteData: CreateTenantUserInviteRequest = {
213
+ * email: 'developer@company.com',
214
+ * role: 'admin'
215
+ * };
216
+ * ```
217
+ *
218
+ * @since 1.0.0
219
+ * @public
220
+ * @group User Management
41
221
  */
42
222
  type CreateTenantUserInviteRequest = {
223
+ /** Email address of the user to invite */
43
224
  email: string;
225
+ /** Role the invited user will have in the tenant */
44
226
  role: string;
45
227
  };
46
228
  /**
47
- * Create a tenant user invite
48
- * Calls POST /api/v1/tenants/{id}/invites
229
+ * Creates a new user invitation for a specific tenant
230
+ *
231
+ * Generates a secure invitation that allows a user to join the specified
232
+ * tenant with the defined role. The invitation is sent to the provided
233
+ * email address and includes a time-limited token for security.
234
+ *
235
+ * The function creates the invitation record in the database and can
236
+ * trigger email notifications (depending on server configuration).
237
+ * The invitation expires after a predefined time period and can only
238
+ * be used once.
239
+ *
240
+ * Only existing tenant members with appropriate permissions can create
241
+ * invitations. The inviter's authentication is validated via HTTP-only
242
+ * cookies sent with the request.
243
+ *
244
+ * @param tenantId - Unique identifier of the tenant to invite the user to
245
+ * @param inviteData - Configuration object for the invitation
246
+ * @param inviteData.email - Email address of the user to invite
247
+ * @param inviteData.role - Role the user will have after joining (e.g., 'member', 'admin')
248
+ *
249
+ * @returns Promise resolving to the created invitation with secure token
250
+ *
251
+ * @throws {Error} When OMNIBASE_API_URL environment variable is not configured
252
+ * @throws {Error} When tenantId parameter is missing or empty
253
+ * @throws {Error} When required fields (email, role) are missing or empty
254
+ * @throws {Error} When the API request fails due to network issues
255
+ * @throws {Error} When the server returns an error response (4xx, 5xx status codes)
256
+ *
257
+ * @example
258
+ * Basic invitation creation:
259
+ * ```typescript
260
+ * const invite = await createTenantUserInvite('tenant_123', {
261
+ * email: 'colleague@company.com',
262
+ * role: 'member'
263
+ * });
264
+ *
265
+ * console.log(`Invite sent to: ${invite.data.invite.email}`);
266
+ * // The invite token can be used to generate invitation links
267
+ * const inviteLink = `https://app.com/accept-invite?token=${invite.data.invite.token}`;
268
+ * ```
269
+ *
270
+ * @example
271
+ * Creating admin invitation:
272
+ * ```typescript
273
+ * const adminInvite = await createTenantUserInvite('tenant_456', {
274
+ * email: 'admin@company.com',
275
+ * role: 'admin'
276
+ * });
277
+ *
278
+ * // Admin users get elevated permissions
279
+ * console.log(`Admin invite created with ID: ${adminInvite.data.invite.id}`);
280
+ * ```
281
+ *
282
+ *
283
+ * @since 1.0.0
284
+ * @public
285
+ * @group User Management
49
286
  */
50
287
  declare function createTenantUserInvite(tenantId: string, inviteData: CreateTenantUserInviteRequest): Promise<CreateTenantUserInviteResponse>;
51
288
 
52
289
  /**
53
- * Return type of the `createTenant` function
290
+ * Response structure for tenant creation operations
291
+ *
292
+ * Contains the newly created tenant information along with an authentication
293
+ * token that provides Row-Level Security (RLS) access to the tenant's data.
294
+ * The token should be stored securely and used for subsequent API calls
295
+ * that require tenant-specific access.
54
296
  *
55
- * The `token` is the authenticated users `postgrest_jwt` cookie for RLS policies specific to the active tenant
297
+ * @example
298
+ * ```typescript
299
+ * const response: CreateTenantResponse = {
300
+ * data: {
301
+ * tenant: {
302
+ * id: 'tenant_123',
303
+ * name: 'My Company',
304
+ * stripe_customer_id: 'cus_abc123'
305
+ * },
306
+ * message: 'Tenant created successfully',
307
+ * token: 'eyJhbGciOiJIUzI1NiIs...'
308
+ * },
309
+ * status: 201
310
+ * };
311
+ * ```
312
+ *
313
+ * @since 1.0.0
314
+ * @public
315
+ * @group Tenant Management
56
316
  */
57
317
  type CreateTenantResponse = ApiResponse<{
318
+ /** The newly created tenant object */
58
319
  tenant: Tenant;
320
+ /** Success message confirming tenant creation */
59
321
  message: string;
322
+ /** JWT token for RLS policies specific to the active tenant */
60
323
  token: string;
61
324
  }>;
62
325
  /**
63
- * The Tenant Schema that maps directly to `auth.tenants`
326
+ * Tenant entity structure that maps to the database schema
327
+ *
328
+ * Represents a tenant in the multi-tenant system with billing integration
329
+ * via Stripe. Each tenant can have multiple users with different roles
330
+ * and maintains its own isolated data through RLS policies.
331
+ *
332
+ * @example
333
+ * ```typescript
334
+ * const tenant: Tenant = {
335
+ * id: 'tenant_abc123',
336
+ * name: 'Acme Corporation',
337
+ * stripe_customer_id: 'cus_stripe123',
338
+ * type: 'business',
339
+ * created_at: '2024-01-15T10:30:00Z',
340
+ * updated_at: '2024-01-15T10:30:00Z'
341
+ * };
342
+ * ```
343
+ *
344
+ * @since 1.0.0
345
+ * @public
346
+ * @group Tenant Management
64
347
  */
65
348
  type Tenant = {
349
+ /** Unique identifier for the tenant */
66
350
  id: string;
351
+ /** Display name of the tenant organization */
67
352
  name: string;
353
+ /** Associated Stripe customer ID for billing */
68
354
  stripe_customer_id: string;
355
+ /** Type of tenant (e.g., 'individual', 'organization') */
69
356
  type: string;
357
+ /** ISO 8601 timestamp when the tenant was created */
70
358
  created_at: string;
359
+ /** ISO 8601 timestamp when the tenant was last updated */
71
360
  updated_at: string;
72
361
  };
73
362
  /**
74
- * The data required to create a tenant.
363
+ * Required data for creating a new tenant
364
+ *
365
+ * Contains the essential information needed to establish a new tenant
366
+ * in the system, including billing setup and initial user assignment.
367
+ *
368
+ * @example
369
+ * ```typescript
370
+ * const tenantData: CreateTenantRequest = {
371
+ * name: 'My New Company',
372
+ * billing_email: 'billing@mynewcompany.com',
373
+ * user_id: 'user_abc123'
374
+ * };
375
+ * ```
376
+ *
377
+ * @since 1.0.0
378
+ * @public
379
+ * @group Tenant Management
75
380
  */
76
381
  type CreateTenantRequest = {
382
+ /** Name of the tenant organization */
77
383
  name: string;
384
+ /** Email address for billing notifications */
78
385
  billing_email: string;
386
+ /** ID of the user who will own the tenant */
79
387
  user_id: string;
80
388
  };
81
389
  /**
82
- * Create a new tenant
390
+ * Creates a new tenant in the multi-tenant system
391
+ *
392
+ * Establishes a new tenant with integrated Stripe billing setup and assigns
393
+ * the specified user as the tenant owner. The operation creates the necessary
394
+ * database records and returns a JWT token that enables Row-Level Security
395
+ * access to the tenant's isolated data.
396
+ *
397
+ * The function automatically handles Stripe customer creation for billing
398
+ * integration and sets up the initial tenant configuration. The returned
399
+ * token should be stored securely for subsequent API calls.
400
+ *
401
+ * @param tenantData - Configuration object for the new tenant
402
+ * @param tenantData.name - Display name for the tenant organization
403
+ * @param tenantData.billing_email - Email address for Stripe billing notifications
404
+ * @param tenantData.user_id - Unique identifier of the user who will own this tenant
405
+ *
406
+ * @returns Promise resolving to the created tenant with authentication token
407
+ *
408
+ * @throws {Error} When OMNIBASE_API_URL environment variable is not configured
409
+ * @throws {Error} When required fields (name, user_id) are missing or empty
410
+ * @throws {Error} When the API request fails due to network issues
411
+ * @throws {Error} When the server returns an error response (4xx, 5xx status codes)
412
+ *
413
+ * @example
414
+ * Basic tenant creation:
415
+ * ```typescript
416
+ * const newTenant = await createTenant({
417
+ * name: 'Acme Corporation',
418
+ * billing_email: 'billing@acme.com',
419
+ * user_id: 'user_123'
420
+ * });
83
421
  *
84
- * Calls POST /api/v1/tenants
422
+ * console.log(`Created tenant: ${newTenant.data.tenant.name}`);
423
+ * // Store the token for authenticated requests
424
+ * localStorage.setItem('tenant_token', newTenant.data.token);
425
+ * ```
426
+ *
427
+ *
428
+ * @since 1.0.0
429
+ * @public
430
+ * @group Tenant Management
85
431
  */
86
432
  declare function createTenant(tenantData: CreateTenantRequest): Promise<CreateTenantResponse>;
87
433
 
88
434
  /**
89
- * Return type of the `deleteTenant` function
435
+ * Response structure for deleting a tenant
436
+ *
437
+ * Contains a confirmation message indicating successful tenant deletion.
438
+ * This response is only returned after the tenant and all associated data
439
+ * have been permanently removed from the system.
440
+ *
441
+ * @example
442
+ * ```typescript
443
+ * const response: DeleteTenantResponse = {
444
+ * data: {
445
+ * message: 'Tenant deleted successfully'
446
+ * },
447
+ * status: 200
448
+ * };
449
+ * ```
450
+ *
451
+ * @since 1.0.0
452
+ * @public
453
+ * @group Tenant Management
90
454
  */
91
455
  type DeleteTenantResponse = ApiResponse<{
456
+ /** Confirmation message indicating successful deletion */
92
457
  message: string;
93
458
  }>;
94
459
  /**
95
- * Delete a tenant (only owners can delete)
460
+ * Permanently deletes a tenant and all associated data
461
+ *
462
+ * ⚠️ **WARNING: This operation is irreversible and will permanently delete:**
463
+ * - The tenant record and all metadata
464
+ * - All user memberships and invitations for this tenant
465
+ * - All tenant-specific data protected by row-level security
466
+ * - Any tenant-related billing information
467
+ * - All tenant configuration and settings
468
+ *
469
+ * **Access Control:**
470
+ * Only tenant owners can delete a tenant. This operation requires:
471
+ * - User must be authenticated
472
+ * - User must have 'owner' role for the specified tenant
473
+ * - Tenant must exist and be accessible to the user
474
+ *
475
+ * **Security Considerations:**
476
+ * - All tenant data is immediately and permanently removed
477
+ * - Other tenant members lose access immediately
478
+ * - Any active sessions for this tenant are invalidated
479
+ * - Billing subscriptions are cancelled (if applicable)
480
+ * - Audit logs for deletion are maintained for compliance
481
+ *
482
+ * @param tenantId - The unique identifier of the tenant to delete
483
+ *
484
+ * @returns Promise resolving to a confirmation message
485
+ *
486
+ * @throws {Error} When OMNIBASE_API_URL environment variable is not configured
487
+ * @throws {Error} When the tenantId parameter is missing or empty
488
+ * @throws {Error} When the user is not authenticated
489
+ * @throws {Error} When the user is not an owner of the specified tenant
490
+ * @throws {Error} When the tenant doesn't exist or is not accessible
491
+ * @throws {Error} When the API request fails due to network issues
492
+ * @throws {Error} When the server returns an error response (4xx, 5xx status codes)
493
+ *
494
+ * @example
495
+ * Basic tenant deletion with confirmation:
496
+ * ```typescript
497
+ * const tenantToDelete = 'tenant_abc123';
96
498
  *
97
- * Calls DELETE /api/v1/tenants/{id}
499
+ * // Always confirm before deleting
500
+ * const userConfirmed = confirm(
501
+ * 'Are you sure you want to delete this tenant? This action cannot be undone.'
502
+ * );
503
+ *
504
+ * if (userConfirmed) {
505
+ * try {
506
+ * const result = await deleteTenant(tenantToDelete);
507
+ * console.log(result.data.message); // "Tenant deleted successfully"
508
+ *
509
+ * // Redirect user away from deleted tenant
510
+ * window.location.href = '/dashboard';
511
+ * } catch (error) {
512
+ * console.error('Failed to delete tenant:', error);
513
+ * }
514
+ * }
515
+ * ```
516
+ *
517
+ * @since 1.0.0
518
+ * @public
519
+ * @group Tenant Management
98
520
  */
99
521
  declare function deleteTenant(tenantId: string): Promise<DeleteTenantResponse>;
100
522
 
101
523
  /**
102
- * Base API Response structure for API
524
+ * Base API Response structure for all tenant operations
525
+ *
526
+ * This generic type defines the standard response format returned by all
527
+ * tenant-related API endpoints. It provides a consistent structure for
528
+ * handling both successful responses and error conditions across the SDK.
529
+ *
530
+ * @template T - The type of the response data payload
531
+ *
532
+ * @example
533
+ * Successful response:
534
+ * ```typescript
535
+ * const response: ApiResponse<{ tenant: Tenant }> = {
536
+ * data: { tenant: { id: '123', name: 'My Company' } },
537
+ * status: 200
538
+ * };
539
+ * ```
540
+ *
541
+ * @example
542
+ * Error response:
543
+ * ```typescript
544
+ * const response: ApiResponse<never> = {
545
+ * status: 400,
546
+ * error: 'Invalid tenant name provided'
547
+ * };
548
+ * ```
549
+ *
550
+ * @since 1.0.0
551
+ * @public
103
552
  */
104
553
  type ApiResponse<T> = {
554
+ /**
555
+ * Response data payload (present only on successful operations)
556
+ * Contains the actual data returned by the API endpoint
557
+ */
105
558
  data?: T;
559
+ /**
560
+ * HTTP status code indicating the result of the operation
561
+ * @example 200 for success, 400 for client errors, 500 for server errors
562
+ */
106
563
  status: number;
564
+ /**
565
+ * Error message (present only when operation fails)
566
+ * Provides human-readable description of what went wrong
567
+ */
107
568
  error?: string;
108
569
  };
109
570
 
110
571
  /**
111
- * Return type of the `switchActiveTenant` function
572
+ * Response structure for switching the active tenant
573
+ *
574
+ * Contains a new JWT token that includes the updated tenant context
575
+ * and a confirmation message. The new token should replace the previous
576
+ * token for all subsequent API calls to ensure requests are made within
577
+ * the context of the newly active tenant.
578
+ *
579
+ * The token includes updated tenant-specific claims and permissions,
580
+ * ensuring that row-level security policies are enforced correctly
581
+ * for the new active tenant context.
582
+ *
583
+ * @example
584
+ * ```typescript
585
+ * const response: SwitchActiveTenantResponse = {
586
+ * data: {
587
+ * token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
588
+ * message: 'Active tenant switched successfully'
589
+ * },
590
+ * status: 200
591
+ * };
592
+ * ```
593
+ *
594
+ * @since 1.0.0
595
+ * @public
596
+ * @group Tenant Management
112
597
  */
113
598
  type SwitchActiveTenantResponse = ApiResponse<{
599
+ /** New JWT token with updated tenant context */
114
600
  token: string;
601
+ /** Success message confirming the tenant switch */
115
602
  message: string;
116
603
  }>;
117
604
  /**
118
- * Switch the user's active tenant
605
+ * Switches the user's active tenant context
606
+ *
607
+ * Changes the user's active tenant to the specified tenant ID, updating
608
+ * their authentication context and permissions. This function is essential
609
+ * for multi-tenant applications where users belong to multiple tenants
610
+ * and need to switch between them.
611
+ *
612
+ * The function performs several operations:
613
+ * - Validates that the user has access to the specified tenant
614
+ * - Updates the user's active tenant in their session
615
+ * - Generates a new JWT token with updated tenant claims
616
+ * - Updates any cached tenant-specific data
617
+ *
618
+ * After switching tenants, all subsequent API calls will be made within
619
+ * the context of the new active tenant, with row-level security policies
620
+ * applied accordingly. The new JWT token should be used for all future
621
+ * authenticated requests.
622
+ *
623
+ * @param tenantId - The ID of the tenant to switch to (must be a tenant the user belongs to)
624
+ *
625
+ * @returns Promise resolving to a new JWT token and success confirmation
626
+ *
627
+ * @throws {Error} When OMNIBASE_API_URL environment variable is not configured
628
+ * @throws {Error} When the tenantId parameter is missing or empty
629
+ * @throws {Error} When the user doesn't have access to the specified tenant
630
+ * @throws {Error} When the user is not authenticated
631
+ * @throws {Error} When the specified tenant doesn't exist
632
+ * @throws {Error} When the API request fails due to network issues
633
+ * @throws {Error} When the server returns an error response (4xx, 5xx status codes)
634
+ *
635
+ * @example
636
+ * Basic tenant switching:
637
+ * ```typescript
638
+ * const result = await switchActiveTenant('tenant_xyz789');
639
+ *
640
+ * // Now all API calls will be in the context of tenant_xyz789
641
+ * const tenantData = await getCurrentTenantData();
642
+ * ```
643
+ *
644
+ * @example
645
+ * Using with tenant-aware data fetching:
646
+ * ```typescript
647
+ * // Switch tenant and immediately fetch tenant-specific data
648
+ * const switchAndLoadTenant = async (tenantId: string) => {
649
+ * try {
650
+ * // Switch to new tenant context
651
+ * const switchResult = await switchActiveTenant(tenantId);
652
+ *
653
+ * // Update authentication token
654
+ * setAuthToken(switchResult.data.token);
655
+ *
656
+ * // Fetch data in new tenant context
657
+ * const [tenantInfo, userPermissions, tenantSettings] = await Promise.all([
658
+ * getTenantInfo(),
659
+ * getUserPermissions(),
660
+ * getTenantSettings()
661
+ * ]);
662
+ *
663
+ * return {
664
+ * tenant: tenantInfo,
665
+ * permissions: userPermissions,
666
+ * settings: tenantSettings
667
+ * };
668
+ * } catch (error) {
669
+ * console.error('Failed to switch tenant and load data:', error);
670
+ * throw error;
671
+ * }
672
+ * };
673
+ * ```
119
674
  *
120
- * Calls PUT /api/v1/tenants/switch-active
675
+ * @since 1.0.0
676
+ * @public
677
+ * @group Tenant Management
121
678
  */
122
679
  declare function switchActiveTenant(tenantId: string): Promise<SwitchActiveTenantResponse>;
123
680
 
124
- export { type AcceptTenantInviteResponse, type ApiResponse, type CreateTenantRequest, type CreateTenantResponse, type CreateTenantUserInviteRequest, type CreateTenantUserInviteResponse, type DeleteTenantResponse, type SwitchActiveTenantResponse, type Tenant, type TenantInvite, acceptTenantInvite, createTenant, createTenantUserInvite, deleteTenant, switchActiveTenant };
681
+ export { type AcceptTenantInviteRequest, type AcceptTenantInviteResponse, type ApiResponse, type CreateTenantRequest, type CreateTenantResponse, type CreateTenantUserInviteRequest, type CreateTenantUserInviteResponse, type DeleteTenantResponse, type SwitchActiveTenantResponse, type Tenant, type TenantInvite, acceptTenantInvite, createTenant, createTenantUserInvite, deleteTenant, switchActiveTenant };