@omnibase/core-js 0.4.2 → 0.5.1

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