@omnibase/core-js 0.6.0 → 0.7.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.
@@ -4,7 +4,7 @@ import {
4
4
  PaymentHandler,
5
5
  PortalManager,
6
6
  UsageManager
7
- } from "../chunk-PNP3T7XU.js";
7
+ } from "../chunk-QPW6G4PA.js";
8
8
  export {
9
9
  CheckoutManager,
10
10
  ConfigManager,
@@ -68,17 +68,6 @@ var TenantInviteManager = class {
68
68
  * @throws {Error} When the server returns an error response (4xx, 5xx status codes)
69
69
  *
70
70
  * @example
71
- * Basic invitation acceptance:
72
- * ```typescript
73
- * const result = await acceptTenantInvite('inv_secure_token_abc123');
74
- *
75
- * console.log(`Successfully joined tenant: ${result.data.tenant_id}`);
76
- * // User can now access tenant resources
77
- * await switchActiveTenant(result.data.tenant_id);
78
- * ```
79
- *
80
- * @example
81
- * Handling the invitation flow:
82
71
  * ```typescript
83
72
  * // Typically called from an invitation link like:
84
73
  * // https://app.com/accept-invite?token=inv_secure_token_abc123
@@ -88,21 +77,20 @@ var TenantInviteManager = class {
88
77
  *
89
78
  * if (inviteToken) {
90
79
  * try {
91
- * const result = await acceptTenantInvite(inviteToken);
80
+ * const result = await inviteManager.accept(inviteToken);
92
81
  *
93
82
  * // Success - redirect to tenant dashboard
83
+ * console.log(`Successfully joined tenant: ${result.data.tenant_id}`);
94
84
  * window.location.href = `/dashboard?tenant=${result.data.tenant_id}`;
95
85
  * } catch (error) {
96
86
  * console.error('Failed to accept invitation:', error.message);
97
- * // Show error to user
98
87
  * }
99
88
  * }
100
89
  * ```
101
90
  *
102
- *
103
- * @since 1.0.0
91
+ * @since 0.6.0
104
92
  * @public
105
- * @group User Management
93
+ * @group Tenant Invitations
106
94
  */
107
95
  async accept(token) {
108
96
  if (!token) {
@@ -137,67 +125,53 @@ var TenantInviteManager = class {
137
125
  }
138
126
  }
139
127
  /**
140
- * Creates a new user invitation for a specific tenant
128
+ * Creates a new user invitation for the active tenant
141
129
  *
142
- * Generates a secure invitation that allows a user to join the specified
143
- * tenant with the defined role. The invitation is sent to the provided
144
- * email address and includes a time-limited token for security.
130
+ * Generates a secure invitation that allows a user to join the currently active
131
+ * tenant with the defined role. The invitation is sent to the provided email address
132
+ * and includes a time-limited token for security. The invite URL will be automatically
133
+ * appended with ?token=XYZ when sent to the user.
145
134
  *
146
- * The function creates the invitation record in the database and can
147
- * trigger email notifications (depending on server configuration).
148
- * The invitation expires after a predefined time period and can only
135
+ * The function creates the invitation record in the database and triggers an email
136
+ * notification to the invited user. The invitation expires after 7 days and can only
149
137
  * be used once.
150
138
  *
151
- * Only existing tenant members with appropriate permissions can create
152
- * invitations. The inviter's authentication is validated via HTTP-only
153
- * cookies sent with the request.
139
+ * Only existing tenant members with appropriate permissions (invite_user permission)
140
+ * can create invitations. The inviter's authentication and tenant context are validated
141
+ * via HTTP-only cookies sent with the request.
154
142
  *
155
- * @param tenantId - Unique identifier of the tenant to invite the user to
156
143
  * @param inviteData - Configuration object for the invitation
157
144
  * @param inviteData.email - Email address of the user to invite
158
145
  * @param inviteData.role - Role the user will have after joining (e.g., 'member', 'admin')
146
+ * @param inviteData.invite_url - Base URL for the invitation link (will be appended with ?token=XYZ)
159
147
  *
160
148
  * @returns Promise resolving to the created invitation with secure token
161
149
  *
162
- * @throws {Error} When tenantId parameter is missing or empty
163
- * @throws {Error} When required fields (email, role) are missing or empty
150
+ * @throws {Error} When required fields (email, role, invite_url) are missing or empty
151
+ * @throws {Error} When the user doesn't have permission to invite users to the tenant
164
152
  * @throws {Error} When the API request fails due to network issues
165
153
  * @throws {Error} When the server returns an error response (4xx, 5xx status codes)
166
154
  *
167
155
  * @example
168
- * Basic invitation creation:
169
156
  * ```typescript
170
- * const invite = await createTenantUserInvite('tenant_123', {
157
+ * const invite = await inviteManager.create({
171
158
  * email: 'colleague@company.com',
172
- * role: 'member'
159
+ * role: 'member',
160
+ * invite_url: 'https://yourapp.com/accept-invite'
173
161
  * });
174
162
  *
175
163
  * console.log(`Invite sent to: ${invite.data.invite.email}`);
176
- * // The invite token can be used to generate invitation links
177
- * const inviteLink = `https://app.com/accept-invite?token=${invite.data.invite.token}`;
178
- * ```
179
- *
180
- * @example
181
- * Creating admin invitation:
182
- * ```typescript
183
- * const adminInvite = await createTenantUserInvite('tenant_456', {
184
- * email: 'admin@company.com',
185
- * role: 'admin'
186
- * });
187
- *
188
- * // Admin users get elevated permissions
189
- * console.log(`Admin invite created with ID: ${adminInvite.data.invite.id}`);
164
+ * console.log(`Invite token: ${invite.data.invite.token}`);
190
165
  * ```
191
166
  *
192
- *
193
- * @since 1.0.0
167
+ * @since 0.6.0
194
168
  * @public
195
- * @group User Management
169
+ * @group Tenant Invitations
196
170
  */
197
171
  async create(inviteData) {
198
172
  if (!inviteData.email || !inviteData.role || !inviteData.invite_url) {
199
173
  throw new Error(
200
- "Missing data in `create` - email, role, invite_url and tenant_id are required"
174
+ "Missing data in `create` - email, role, and invite_url are required"
201
175
  );
202
176
  }
203
177
  try {
@@ -266,17 +240,17 @@ var TenantManger = class {
266
240
  * @throws {Error} When the server returns an error response (4xx, 5xx status codes)
267
241
  *
268
242
  * @example
269
- * Basic tenant creation:
270
243
  * ```typescript
271
- * const newTenant = await createTenant({
244
+ * const newTenant = await tenantManager.createTenant({
272
245
  * name: 'Acme Corporation',
273
246
  * billing_email: 'billing@acme.com',
274
247
  * user_id: 'user_123'
275
248
  * });
276
- * ```
277
249
  *
250
+ * console.log(`Tenant created: ${newTenant.data.tenant.id}`);
251
+ * ```
278
252
  *
279
- * @since 1.0.0
253
+ * @since 0.6.0
280
254
  * @public
281
255
  * @group Tenant Management
282
256
  */
@@ -341,7 +315,6 @@ var TenantManger = class {
341
315
  * @throws {Error} When the server returns an error response (4xx, 5xx status codes)
342
316
  *
343
317
  * @example
344
- * Basic tenant deletion with confirmation:
345
318
  * ```typescript
346
319
  * const tenantToDelete = 'tenant_abc123';
347
320
  *
@@ -352,8 +325,8 @@ var TenantManger = class {
352
325
  *
353
326
  * if (userConfirmed) {
354
327
  * try {
355
- * const result = await deleteTenant(tenantToDelete);
356
- * console.log(result.data.message); // "Tenant deleted successfully"
328
+ * const result = await tenantManager.deleteTenant(tenantToDelete);
329
+ * console.log(result.data.message);
357
330
  *
358
331
  * // Redirect user away from deleted tenant
359
332
  * window.location.href = '/dashboard';
@@ -363,7 +336,7 @@ var TenantManger = class {
363
336
  * }
364
337
  * ```
365
338
  *
366
- * @since 1.0.0
339
+ * @since 0.6.0
367
340
  * @public
368
341
  * @group Tenant Management
369
342
  */
@@ -426,46 +399,17 @@ var TenantManger = class {
426
399
  * @throws {Error} When the server returns an error response (4xx, 5xx status codes)
427
400
  *
428
401
  * @example
429
- * Basic tenant switching:
430
402
  * ```typescript
431
- * const result = await switchActiveTenant('tenant_xyz789');
403
+ * const result = await tenantManager.switchActiveTenant('tenant_xyz789');
404
+ *
405
+ * // Store the new token for future requests
406
+ * console.log(`Switched to tenant. New token: ${result.data.token}`);
432
407
  *
433
408
  * // Now all API calls will be in the context of tenant_xyz789
434
409
  * const tenantData = await getCurrentTenantData();
435
410
  * ```
436
411
  *
437
- * @example
438
- * Using with tenant-aware data fetching:
439
- * ```typescript
440
- * // Switch tenant and immediately fetch tenant-specific data
441
- * const switchAndLoadTenant = async (tenantId: string) => {
442
- * try {
443
- * // Switch to new tenant context
444
- * const switchResult = await switchActiveTenant(tenantId);
445
- *
446
- * // Update authentication token
447
- * setAuthToken(switchResult.data.token);
448
- *
449
- * // Fetch data in new tenant context
450
- * const [tenantInfo, userPermissions, tenantSettings] = await Promise.all([
451
- * getTenantInfo(),
452
- * getUserPermissions(),
453
- * getTenantSettings()
454
- * ]);
455
- *
456
- * return {
457
- * tenant: tenantInfo,
458
- * permissions: userPermissions,
459
- * settings: tenantSettings
460
- * };
461
- * } catch (error) {
462
- * console.error('Failed to switch tenant and load data:', error);
463
- * throw error;
464
- * }
465
- * };
466
- * ```
467
- *
468
- * @since 1.0.0
412
+ * @since 0.6.0
469
413
  * @public
470
414
  * @group Tenant Management
471
415
  */
@@ -552,7 +496,7 @@ var TenantUserManager = class {
552
496
  * }
553
497
  * ```
554
498
  *
555
- * @since 1.0.0
499
+ * @since 0.6.0
556
500
  * @public
557
501
  * @group Tenant User Management
558
502
  */
@@ -616,7 +560,7 @@ var TenantUserManager = class {
616
560
  * }
617
561
  * ```
618
562
  *
619
- * @since 1.0.0
563
+ * @since 0.6.0
620
564
  * @public
621
565
  * @group Tenant User Management
622
566
  */
@@ -677,7 +621,7 @@ var TenantHandler = class {
677
621
  * await tenantHandler.user.remove({ user_id: 'user_123' });
678
622
  * ```
679
623
  *
680
- * @since 1.0.0
624
+ * @since 0.6.0
681
625
  * @group Tenant Management
682
626
  */
683
627
  user;
@@ -691,17 +635,17 @@ var TenantHandler = class {
691
635
  * @example
692
636
  * ```typescript
693
637
  * // Create a new tenant
694
- * const tenant = await tenantHandler.tenants.createTenant({
638
+ * const tenant = await tenantHandler.manage.createTenant({
695
639
  * name: 'New Company',
696
640
  * billing_email: 'billing@newcompany.com',
697
641
  * user_id: 'user_456'
698
642
  * });
699
643
  *
700
644
  * // Switch to the tenant
701
- * await tenantHandler.tenants.switchActiveTenant(tenant.data.tenant.id);
645
+ * await tenantHandler.manage.switchActiveTenant(tenant.data.tenant.id);
702
646
  *
703
647
  * // Delete the tenant (owner only)
704
- * await tenantHandler.tenants.deleteTenant(tenant.data.tenant.id);
648
+ * await tenantHandler.manage.deleteTenant(tenant.data.tenant.id);
705
649
  * ```
706
650
  */
707
651
  manage;
@@ -715,9 +659,10 @@ var TenantHandler = class {
715
659
  * @example
716
660
  * ```typescript
717
661
  * // Create an invitation
718
- * const invite = await tenantHandler.invites.create('tenant_123', {
662
+ * const invite = await tenantHandler.invites.create({
719
663
  * email: 'newuser@company.com',
720
- * role: 'admin'
664
+ * role: 'admin',
665
+ * invite_url: 'https://yourapp.com/accept-invite'
721
666
  * });
722
667
  *
723
668
  * // Accept an invitation (from the invited user's session)
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  TenantHandler
3
- } from "../chunk-LMDKQ6Z2.js";
3
+ } from "../chunk-6OGESVXW.js";
4
4
  export {
5
5
  TenantHandler
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnibase/core-js",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "OmniBase core Javascript SDK - framework agnostic",
5
5
  "files": [
6
6
  "dist/**/*"