@omnibase/core-js 0.1.5 → 0.1.6

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