@omnibase/core-js 0.5.10 → 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.
package/dist/index.cjs CHANGED
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- OmnibaseClient: () => OmnibaseClient
23
+ OmnibaseClient: () => OmnibaseClient,
24
+ StorageClient: () => StorageClient
24
25
  });
25
26
  module.exports = __toCommonJS(index_exports);
26
27
 
@@ -662,6 +663,132 @@ var PermissionsClient = class {
662
663
  }
663
664
  };
664
665
 
666
+ // src/storage/index.ts
667
+ var StorageClient = class {
668
+ constructor(client) {
669
+ this.client = client;
670
+ }
671
+ /**
672
+ * Upload a file to storage
673
+ *
674
+ * @param path - Full path for the file (e.g., "public/images/avatar.png", "users/123/private/doc.pdf")
675
+ * @param file - File or Blob to upload
676
+ * @param options - Upload options including custom metadata
677
+ *
678
+ * @example
679
+ * ```typescript
680
+ * const result = await storage.upload(
681
+ * 'public/avatars/user-123.png',
682
+ * file,
683
+ * {
684
+ * metadata: {
685
+ * userId: '123',
686
+ * uploadedBy: 'john@example.com',
687
+ * tags: ['profile', 'avatar']
688
+ * }
689
+ * }
690
+ * );
691
+ *
692
+ * // File is automatically uploaded to S3 via the presigned URL
693
+ * console.log('File uploaded to:', result.path);
694
+ * ```
695
+ */
696
+ async upload(path, file, options) {
697
+ const metadata = {
698
+ // File metadata
699
+ filename: file instanceof File ? file.name : "blob",
700
+ size: file.size,
701
+ mime_type: file.type,
702
+ uploaded_at: (/* @__PURE__ */ new Date()).toISOString(),
703
+ // Merge custom metadata
704
+ ...options?.metadata || {}
705
+ };
706
+ const response = await this.client.fetch("/api/v1/storage/upload", {
707
+ method: "POST",
708
+ headers: {
709
+ "Content-Type": "application/json"
710
+ },
711
+ body: JSON.stringify({
712
+ path,
713
+ metadata
714
+ })
715
+ });
716
+ if (!response.ok) {
717
+ const error = await response.json().catch(() => ({ error: "Upload failed" }));
718
+ throw new Error(error.error || "Failed to get upload URL");
719
+ }
720
+ const responseData = await response.json();
721
+ const result = responseData.data;
722
+ const uploadResponse = await fetch(result.upload_url, {
723
+ method: "PUT",
724
+ body: file,
725
+ headers: {
726
+ "Content-Type": file.type
727
+ }
728
+ });
729
+ if (!uploadResponse.ok) {
730
+ throw new Error("Failed to upload file to storage");
731
+ }
732
+ return result;
733
+ }
734
+ /**
735
+ * Download a file from storage
736
+ *
737
+ * @param path - Full path to the file
738
+ *
739
+ * @example
740
+ * ```typescript
741
+ * const { download_url } = await storage.download('public/images/logo.png');
742
+ *
743
+ * // Download the file
744
+ * const response = await fetch(download_url);
745
+ * const blob = await response.blob();
746
+ * ```
747
+ */
748
+ async download(path) {
749
+ const response = await this.client.fetch("/api/v1/storage/download", {
750
+ method: "POST",
751
+ headers: {
752
+ "Content-Type": "application/json"
753
+ },
754
+ body: JSON.stringify({
755
+ path
756
+ })
757
+ });
758
+ if (!response.ok) {
759
+ const error = await response.json().catch(() => ({ error: "Download failed" }));
760
+ throw new Error(error.error || "Failed to get download URL");
761
+ }
762
+ const responseData = await response.json();
763
+ return responseData.data;
764
+ }
765
+ /**
766
+ * Delete a file from storage
767
+ *
768
+ * @param path - Full path to the file
769
+ *
770
+ * @example
771
+ * ```typescript
772
+ * await storage.delete('users/123/documents/old-report.pdf');
773
+ * ```
774
+ */
775
+ async delete(path) {
776
+ const response = await this.client.fetch("/api/v1/storage/object", {
777
+ method: "DELETE",
778
+ headers: {
779
+ "Content-Type": "application/json"
780
+ },
781
+ body: JSON.stringify({
782
+ path
783
+ })
784
+ });
785
+ if (!response.ok) {
786
+ const error = await response.json().catch(() => ({ error: "Delete failed" }));
787
+ throw new Error(error.error || "Failed to delete file");
788
+ }
789
+ }
790
+ };
791
+
665
792
  // src/tenants/invites.ts
666
793
  var TenantInviteManager = class {
667
794
  /**
@@ -832,16 +959,15 @@ var TenantInviteManager = class {
832
959
  * @public
833
960
  * @group User Management
834
961
  */
835
- async create(tenantId, inviteData) {
836
- if (!tenantId) {
837
- throw new Error("Tenant ID is required");
838
- }
839
- if (!inviteData.email || !inviteData.role) {
840
- throw new Error("Email and role are required");
962
+ async create(inviteData) {
963
+ if (!inviteData.email || !inviteData.role || !inviteData.invite_url) {
964
+ throw new Error(
965
+ "Missing data in `create` - email, role, invite_url and tenant_id are required"
966
+ );
841
967
  }
842
968
  try {
843
969
  const response = await this.omnibaseClient.fetch(
844
- `/api/v1/tenants/${tenantId}/invites`,
970
+ `/api/v1/tenants/invites`,
845
971
  {
846
972
  method: "POST",
847
973
  headers: {
@@ -912,10 +1038,6 @@ var TenantManger = class {
912
1038
  * billing_email: 'billing@acme.com',
913
1039
  * user_id: 'user_123'
914
1040
  * });
915
- *
916
- * console.log(`Created tenant: ${newTenant.data.tenant.name}`);
917
- * // Store the token for authenticated requests
918
- * localStorage.setItem('tenant_token', newTenant.data.token);
919
1041
  * ```
920
1042
  *
921
1043
  *
@@ -1146,6 +1268,140 @@ var TenantManger = class {
1146
1268
  }
1147
1269
  };
1148
1270
 
1271
+ // src/tenants/user.ts
1272
+ var TenantUserManager = class {
1273
+ /**
1274
+ * Creates a new tenant user manager
1275
+ *
1276
+ * @param omnibaseClient - Configured OmnibaseClient instance for API communication
1277
+ *
1278
+ * @group Tenant User Management
1279
+ */
1280
+ constructor(omnibaseClient) {
1281
+ this.omnibaseClient = omnibaseClient;
1282
+ }
1283
+ /**
1284
+ * Removes a user from the active tenant
1285
+ *
1286
+ * This method removes a specified user from the current active tenant. The operation
1287
+ * requires the requesting user to have appropriate permissions (admin or owner role).
1288
+ * The user being removed will lose access to the tenant and all its resources.
1289
+ *
1290
+ * Note: You cannot remove yourself from a tenant using this method. To leave a tenant,
1291
+ * use the appropriate leave or delete tenant operations instead.
1292
+ *
1293
+ * @param data - Request data containing the user ID to remove
1294
+ * @param data.user_id - ID of the user to remove from the tenant
1295
+ *
1296
+ * @returns Promise resolving to an API response confirming the removal
1297
+ *
1298
+ * @throws {Error} When user_id is not provided
1299
+ * @throws {Error} When the API request fails (includes status code and error details)
1300
+ * @throws {Error} When the user doesn't have permission to remove users
1301
+ * @throws {Error} When the specified user is not a member of the tenant
1302
+ *
1303
+ * @example
1304
+ * ```typescript
1305
+ * // Remove a user from the active tenant
1306
+ * try {
1307
+ * await userManager.remove({ user_id: 'user_abc123' });
1308
+ * console.log('User removed successfully');
1309
+ * } catch (error) {
1310
+ * if (error.message.includes('403')) {
1311
+ * console.error('Insufficient permissions to remove user');
1312
+ * } else if (error.message.includes('404')) {
1313
+ * console.error('User not found in tenant');
1314
+ * } else {
1315
+ * console.error('Failed to remove user:', error);
1316
+ * }
1317
+ * }
1318
+ * ```
1319
+ *
1320
+ * @since 1.0.0
1321
+ * @public
1322
+ * @group Tenant User Management
1323
+ */
1324
+ async remove(data) {
1325
+ if (!data.user_id) {
1326
+ throw new Error("user_id is required");
1327
+ }
1328
+ const response = await this.omnibaseClient.fetch("/api/v1/tenants/users", {
1329
+ method: "DELETE",
1330
+ body: JSON.stringify(data)
1331
+ });
1332
+ if (!response.ok) {
1333
+ const errorData = await response.text();
1334
+ throw new Error(
1335
+ `Failed to delete user from tenant: ${response.status} - ${errorData}`
1336
+ );
1337
+ }
1338
+ return await response.json();
1339
+ }
1340
+ /**
1341
+ * Updates a user's role within the active tenant
1342
+ *
1343
+ * This method changes the role of a specified user in the current active tenant. The operation
1344
+ * requires the requesting user to have appropriate permissions (typically admin or owner role).
1345
+ * Role updates take effect immediately and affect the user's permissions and access rights
1346
+ * within the tenant.
1347
+ *
1348
+ * Common roles include 'admin', 'member', and 'viewer', but the exact roles available depend
1349
+ * on your tenant's configuration. Changing a user's role will modify their ability to perform
1350
+ * various operations within the tenant.
1351
+ *
1352
+ * @param data - Request data containing the user ID and new role
1353
+ * @param data.user_id - ID of the user whose role is being updated
1354
+ * @param data.role - New role to assign to the user
1355
+ *
1356
+ * @returns Promise resolving to an API response confirming the role update
1357
+ *
1358
+ * @throws {Error} When user_id or role is not provided
1359
+ * @throws {Error} When the API request fails (includes status code and error details)
1360
+ * @throws {Error} When the user doesn't have permission to update roles
1361
+ * @throws {Error} When the specified user is not a member of the tenant
1362
+ * @throws {Error} When the specified role is invalid or not allowed
1363
+ *
1364
+ * @example
1365
+ * ```typescript
1366
+ * // Update a user's role to admin
1367
+ * try {
1368
+ * const result = await userManager.updateRole({
1369
+ * user_id: 'user_abc123',
1370
+ * role: 'admin'
1371
+ * });
1372
+ * console.log('Role updated successfully:', result.data.message);
1373
+ * } catch (error) {
1374
+ * if (error.message.includes('403')) {
1375
+ * console.error('Insufficient permissions to update roles');
1376
+ * } else if (error.message.includes('404')) {
1377
+ * console.error('User not found in tenant');
1378
+ * } else {
1379
+ * console.error('Failed to update role:', error);
1380
+ * }
1381
+ * }
1382
+ * ```
1383
+ *
1384
+ * @since 1.0.0
1385
+ * @public
1386
+ * @group Tenant User Management
1387
+ */
1388
+ async updateRole(data) {
1389
+ if (!data.role || !data.user_id)
1390
+ throw new Error("user_id and role is required");
1391
+ const response = await this.omnibaseClient.fetch("/api/v1/tenants/users", {
1392
+ method: "PUT",
1393
+ body: JSON.stringify(data)
1394
+ });
1395
+ if (!response.ok) {
1396
+ const errorData = await response.text();
1397
+ throw new Error(
1398
+ `Failed to update users role: ${response.status} - ${errorData}`
1399
+ );
1400
+ }
1401
+ return await response.json();
1402
+ }
1403
+ };
1404
+
1149
1405
  // src/tenants/handler.ts
1150
1406
  var TenantHandler = class {
1151
1407
  /**
@@ -1169,10 +1425,27 @@ var TenantHandler = class {
1169
1425
  * @group Tenant Management
1170
1426
  */
1171
1427
  constructor(omnibaseClient) {
1172
- this.omnibaseClient = omnibaseClient;
1173
- this.invites = new TenantInviteManager(this.omnibaseClient);
1174
- this.manage = new TenantManger(this.omnibaseClient);
1428
+ this.invites = new TenantInviteManager(omnibaseClient);
1429
+ this.manage = new TenantManger(omnibaseClient);
1430
+ this.user = new TenantUserManager(omnibaseClient);
1175
1431
  }
1432
+ /**
1433
+ * Tenant user management operations
1434
+ *
1435
+ * Provides access to operations for managing users within tenants, including
1436
+ * removing users from the active tenant. All operations respect user permissions
1437
+ * and tenant ownership rules.
1438
+ *
1439
+ * @example
1440
+ * ```typescript
1441
+ * // Remove a user from the active tenant
1442
+ * await tenantHandler.user.remove({ user_id: 'user_123' });
1443
+ * ```
1444
+ *
1445
+ * @since 1.0.0
1446
+ * @group Tenant Management
1447
+ */
1448
+ user;
1176
1449
  /**
1177
1450
  * Core tenant management operations
1178
1451
  *
@@ -1252,6 +1525,20 @@ var OmnibaseClient = class {
1252
1525
  payments = new PaymentHandler(this);
1253
1526
  tenants = new TenantHandler(this);
1254
1527
  permissions;
1528
+ /**
1529
+ * Storage client for file upload/download operations
1530
+ *
1531
+ * @example
1532
+ * ```typescript
1533
+ * // Upload with metadata
1534
+ * await omnibase.storage.bucket('documents').upload(
1535
+ * 'report.pdf',
1536
+ * file,
1537
+ * { metadata: { department: 'engineering' } }
1538
+ * );
1539
+ * ```
1540
+ */
1541
+ storage = new StorageClient(this);
1255
1542
  async fetch(endpoint, options = {}) {
1256
1543
  if (this.config.fetch)
1257
1544
  return this.config.fetch(this.config.api_url + endpoint, options);
@@ -1263,5 +1550,6 @@ var OmnibaseClient = class {
1263
1550
  };
1264
1551
  // Annotate the CommonJS export names for ESM import in node:
1265
1552
  0 && (module.exports = {
1266
- OmnibaseClient
1553
+ OmnibaseClient,
1554
+ StorageClient
1267
1555
  });
package/dist/index.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- export { j as ApiResponse, i as OmnibaseClient, O as OmnibaseClientConfig } from './payments/index.cjs';
1
+ export { m as ApiResponse, D as DownloadResult, l as OmnibaseClient, O as OmnibaseClientConfig, S as StorageClient, U as UploadOptions, a as UploadResult } from './payments/index.cjs';
2
2
  import './permissions/index.cjs';
3
3
  import '@ory/client';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { j as ApiResponse, i as OmnibaseClient, O as OmnibaseClientConfig } from './payments/index.js';
1
+ export { m as ApiResponse, D as DownloadResult, l as OmnibaseClient, O as OmnibaseClientConfig, S as StorageClient, U as UploadOptions, a as UploadResult } from './payments/index.js';
2
2
  import './permissions/index.js';
3
3
  import '@ory/client';
package/dist/index.js CHANGED
@@ -1,12 +1,15 @@
1
+ import {
2
+ PaymentHandler
3
+ } from "./chunk-PNP3T7XU.js";
1
4
  import {
2
5
  PermissionsClient
3
6
  } from "./chunk-DDFBRGMG.js";
4
7
  import {
5
- PaymentHandler
6
- } from "./chunk-PNP3T7XU.js";
8
+ StorageClient
9
+ } from "./chunk-I6DMWC32.js";
7
10
  import {
8
11
  TenantHandler
9
- } from "./chunk-L7EZC6WP.js";
12
+ } from "./chunk-LMDKQ6Z2.js";
10
13
 
11
14
  // src/client.ts
12
15
  var OmnibaseClient = class {
@@ -41,6 +44,20 @@ var OmnibaseClient = class {
41
44
  payments = new PaymentHandler(this);
42
45
  tenants = new TenantHandler(this);
43
46
  permissions;
47
+ /**
48
+ * Storage client for file upload/download operations
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * // Upload with metadata
53
+ * await omnibase.storage.bucket('documents').upload(
54
+ * 'report.pdf',
55
+ * file,
56
+ * { metadata: { department: 'engineering' } }
57
+ * );
58
+ * ```
59
+ */
60
+ storage = new StorageClient(this);
44
61
  async fetch(endpoint, options = {}) {
45
62
  if (this.config.fetch)
46
63
  return this.config.fetch(this.config.api_url + endpoint, options);
@@ -51,5 +68,6 @@ var OmnibaseClient = class {
51
68
  }
52
69
  };
53
70
  export {
54
- OmnibaseClient
71
+ OmnibaseClient,
72
+ StorageClient
55
73
  };