@omnibase/core-js 0.5.9 → 0.6.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.
@@ -194,16 +194,15 @@ var TenantInviteManager = class {
194
194
  * @public
195
195
  * @group User Management
196
196
  */
197
- async create(tenantId, inviteData) {
198
- if (!tenantId) {
199
- throw new Error("Tenant ID is required");
200
- }
201
- if (!inviteData.email || !inviteData.role) {
202
- throw new Error("Email and role are required");
197
+ async create(inviteData) {
198
+ if (!inviteData.email || !inviteData.role || !inviteData.invite_url) {
199
+ throw new Error(
200
+ "Missing data in `create` - email, role, invite_url and tenant_id are required"
201
+ );
203
202
  }
204
203
  try {
205
204
  const response = await this.omnibaseClient.fetch(
206
- `/api/v1/tenants/${tenantId}/invites`,
205
+ `/api/v1/tenants/invites`,
207
206
  {
208
207
  method: "POST",
209
208
  headers: {
@@ -274,10 +273,6 @@ var TenantManger = class {
274
273
  * billing_email: 'billing@acme.com',
275
274
  * user_id: 'user_123'
276
275
  * });
277
- *
278
- * console.log(`Created tenant: ${newTenant.data.tenant.name}`);
279
- * // Store the token for authenticated requests
280
- * localStorage.setItem('tenant_token', newTenant.data.token);
281
276
  * ```
282
277
  *
283
278
  *
@@ -508,6 +503,140 @@ var TenantManger = class {
508
503
  }
509
504
  };
510
505
 
506
+ // src/tenants/user.ts
507
+ var TenantUserManager = class {
508
+ /**
509
+ * Creates a new tenant user manager
510
+ *
511
+ * @param omnibaseClient - Configured OmnibaseClient instance for API communication
512
+ *
513
+ * @group Tenant User Management
514
+ */
515
+ constructor(omnibaseClient) {
516
+ this.omnibaseClient = omnibaseClient;
517
+ }
518
+ /**
519
+ * Removes a user from the active tenant
520
+ *
521
+ * This method removes a specified user from the current active tenant. The operation
522
+ * requires the requesting user to have appropriate permissions (admin or owner role).
523
+ * The user being removed will lose access to the tenant and all its resources.
524
+ *
525
+ * Note: You cannot remove yourself from a tenant using this method. To leave a tenant,
526
+ * use the appropriate leave or delete tenant operations instead.
527
+ *
528
+ * @param data - Request data containing the user ID to remove
529
+ * @param data.user_id - ID of the user to remove from the tenant
530
+ *
531
+ * @returns Promise resolving to an API response confirming the removal
532
+ *
533
+ * @throws {Error} When user_id is not provided
534
+ * @throws {Error} When the API request fails (includes status code and error details)
535
+ * @throws {Error} When the user doesn't have permission to remove users
536
+ * @throws {Error} When the specified user is not a member of the tenant
537
+ *
538
+ * @example
539
+ * ```typescript
540
+ * // Remove a user from the active tenant
541
+ * try {
542
+ * await userManager.remove({ user_id: 'user_abc123' });
543
+ * console.log('User removed successfully');
544
+ * } catch (error) {
545
+ * if (error.message.includes('403')) {
546
+ * console.error('Insufficient permissions to remove user');
547
+ * } else if (error.message.includes('404')) {
548
+ * console.error('User not found in tenant');
549
+ * } else {
550
+ * console.error('Failed to remove user:', error);
551
+ * }
552
+ * }
553
+ * ```
554
+ *
555
+ * @since 1.0.0
556
+ * @public
557
+ * @group Tenant User Management
558
+ */
559
+ async remove(data) {
560
+ if (!data.user_id) {
561
+ throw new Error("user_id is required");
562
+ }
563
+ const response = await this.omnibaseClient.fetch("/api/v1/tenants/users", {
564
+ method: "DELETE",
565
+ body: JSON.stringify(data)
566
+ });
567
+ if (!response.ok) {
568
+ const errorData = await response.text();
569
+ throw new Error(
570
+ `Failed to delete user from tenant: ${response.status} - ${errorData}`
571
+ );
572
+ }
573
+ return await response.json();
574
+ }
575
+ /**
576
+ * Updates a user's role within the active tenant
577
+ *
578
+ * This method changes the role of a specified user in the current active tenant. The operation
579
+ * requires the requesting user to have appropriate permissions (typically admin or owner role).
580
+ * Role updates take effect immediately and affect the user's permissions and access rights
581
+ * within the tenant.
582
+ *
583
+ * Common roles include 'admin', 'member', and 'viewer', but the exact roles available depend
584
+ * on your tenant's configuration. Changing a user's role will modify their ability to perform
585
+ * various operations within the tenant.
586
+ *
587
+ * @param data - Request data containing the user ID and new role
588
+ * @param data.user_id - ID of the user whose role is being updated
589
+ * @param data.role - New role to assign to the user
590
+ *
591
+ * @returns Promise resolving to an API response confirming the role update
592
+ *
593
+ * @throws {Error} When user_id or role is not provided
594
+ * @throws {Error} When the API request fails (includes status code and error details)
595
+ * @throws {Error} When the user doesn't have permission to update roles
596
+ * @throws {Error} When the specified user is not a member of the tenant
597
+ * @throws {Error} When the specified role is invalid or not allowed
598
+ *
599
+ * @example
600
+ * ```typescript
601
+ * // Update a user's role to admin
602
+ * try {
603
+ * const result = await userManager.updateRole({
604
+ * user_id: 'user_abc123',
605
+ * role: 'admin'
606
+ * });
607
+ * console.log('Role updated successfully:', result.data.message);
608
+ * } catch (error) {
609
+ * if (error.message.includes('403')) {
610
+ * console.error('Insufficient permissions to update roles');
611
+ * } else if (error.message.includes('404')) {
612
+ * console.error('User not found in tenant');
613
+ * } else {
614
+ * console.error('Failed to update role:', error);
615
+ * }
616
+ * }
617
+ * ```
618
+ *
619
+ * @since 1.0.0
620
+ * @public
621
+ * @group Tenant User Management
622
+ */
623
+ async updateRole(data) {
624
+ if (!data.role || !data.user_id)
625
+ throw new Error("user_id and role is required");
626
+ const response = await this.omnibaseClient.fetch("/api/v1/tenants/users", {
627
+ method: "PUT",
628
+ body: JSON.stringify(data)
629
+ });
630
+ if (!response.ok) {
631
+ const errorData = await response.text();
632
+ throw new Error(
633
+ `Failed to update users role: ${response.status} - ${errorData}`
634
+ );
635
+ }
636
+ return await response.json();
637
+ }
638
+ };
639
+
511
640
  // src/tenants/handler.ts
512
641
  var TenantHandler = class {
513
642
  /**
@@ -531,10 +660,27 @@ var TenantHandler = class {
531
660
  * @group Tenant Management
532
661
  */
533
662
  constructor(omnibaseClient) {
534
- this.omnibaseClient = omnibaseClient;
535
- this.invites = new TenantInviteManager(this.omnibaseClient);
536
- this.manage = new TenantManger(this.omnibaseClient);
663
+ this.invites = new TenantInviteManager(omnibaseClient);
664
+ this.manage = new TenantManger(omnibaseClient);
665
+ this.user = new TenantUserManager(omnibaseClient);
537
666
  }
667
+ /**
668
+ * Tenant user management operations
669
+ *
670
+ * Provides access to operations for managing users within tenants, including
671
+ * removing users from the active tenant. All operations respect user permissions
672
+ * and tenant ownership rules.
673
+ *
674
+ * @example
675
+ * ```typescript
676
+ * // Remove a user from the active tenant
677
+ * await tenantHandler.user.remove({ user_id: 'user_123' });
678
+ * ```
679
+ *
680
+ * @since 1.0.0
681
+ * @group Tenant Management
682
+ */
683
+ user;
538
684
  /**
539
685
  * Core tenant management operations
540
686
  *
@@ -1,3 +1,3 @@
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.cjs';
1
+ export { A as AcceptTenantInviteRequest, b as AcceptTenantInviteResponse, j as CreateTenantRequest, h as CreateTenantResponse, d as CreateTenantUserInviteRequest, C as CreateTenantUserInviteResponse, g as DeleteTenantResponse, f as SwitchActiveTenantResponse, i as Tenant, T as TenantHandler, c as TenantInvite, e as TenantInviteManager, k as TenantManger } from '../payments/index.cjs';
2
2
  import '../permissions/index.cjs';
3
3
  import '@ory/client';
@@ -1,3 +1,3 @@
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';
1
+ export { A as AcceptTenantInviteRequest, b as AcceptTenantInviteResponse, j as CreateTenantRequest, h as CreateTenantResponse, d as CreateTenantUserInviteRequest, C as CreateTenantUserInviteResponse, g as DeleteTenantResponse, f as SwitchActiveTenantResponse, i as Tenant, T as TenantHandler, c as TenantInvite, e as TenantInviteManager, k as TenantManger } from '../payments/index.js';
2
2
  import '../permissions/index.js';
3
3
  import '@ory/client';
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  TenantHandler
3
- } from "../chunk-L7EZC6WP.js";
3
+ } from "../chunk-LMDKQ6Z2.js";
4
4
  export {
5
5
  TenantHandler
6
6
  };
package/package.json CHANGED
@@ -1,43 +1,48 @@
1
1
  {
2
2
  "name": "@omnibase/core-js",
3
- "version": "0.5.9",
3
+ "version": "0.6.0",
4
4
  "description": "OmniBase core Javascript SDK - framework agnostic",
5
5
  "files": [
6
6
  "dist/**/*"
7
7
  ],
8
8
  "type": "module",
9
9
  "scripts": {
10
- "build": "tsup src/index.ts src/permissions/index.ts src/database/index.ts src/tenants/index.ts src/auth/index.ts src/payments/index.ts --format cjs,esm --dts",
10
+ "build": "tsup src/index.ts src/permissions/index.ts src/database/index.ts src/tenants/index.ts src/auth/index.ts src/payments/index.ts src/storage/index.ts --format cjs,esm --dts",
11
11
  "prepublishOnly": "npm run build"
12
12
  },
13
13
  "exports": {
14
14
  ".": {
15
+ "types": "./dist/index.d.ts",
15
16
  "import": "./dist/index.js",
16
- "require": "./dist/index.cjs",
17
- "types": "./dist/index.d.ts"
17
+ "require": "./dist/index.cjs"
18
18
  },
19
19
  "./auth": {
20
20
  "types": "./dist/auth/index.d.ts"
21
21
  },
22
22
  "./permissions": {
23
+ "types": "./dist/permissions/index.d.ts",
23
24
  "import": "./dist/permissions/index.js",
24
- "require": "./dist/permissions/index.cjs",
25
- "types": "./dist/permissions/index.d.ts"
25
+ "require": "./dist/permissions/index.cjs"
26
26
  },
27
27
  "./database": {
28
+ "types": "./dist/database/index.d.ts",
28
29
  "import": "./dist/database/index.js",
29
- "require": "./dist/database/index.cjs",
30
- "types": "./dist/database/index.d.ts"
30
+ "require": "./dist/database/index.cjs"
31
31
  },
32
32
  "./tenants": {
33
+ "types": "./dist/tenants/index.d.ts",
33
34
  "import": "./dist/tenants/index.js",
34
- "require": "./dist/tenants/index.cjs",
35
- "types": "./dist/tenants/index.d.ts"
35
+ "require": "./dist/tenants/index.cjs"
36
36
  },
37
37
  "./payments": {
38
+ "types": "./dist/payments/index.d.ts",
38
39
  "import": "./dist/payments/index.js",
39
- "require": "./dist/payments/index.cjs",
40
- "types": "./dist/payments/index.d.ts"
40
+ "require": "./dist/payments/index.cjs"
41
+ },
42
+ "./storage": {
43
+ "types": "./dist/storage/index.d.ts",
44
+ "import": "./dist/storage/index.js",
45
+ "require": "./dist/storage/index.cjs"
41
46
  }
42
47
  },
43
48
  "keywords": [