@omnibase/core-js 0.7.1 → 0.7.3
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/chunk-JNM7XP7L.js +345 -0
- package/dist/chunk-V4FWENQQ.js +378 -0
- package/dist/index.cjs +284 -9
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +9 -6
- package/dist/payments/index.d.cts +647 -3
- package/dist/payments/index.d.ts +647 -3
- package/dist/permissions/index.cjs +283 -10
- package/dist/permissions/index.d.cts +2 -195
- package/dist/permissions/index.d.ts +2 -195
- package/dist/permissions/index.js +5 -3
- package/dist/storage/index.d.cts +1 -2
- package/dist/storage/index.d.ts +1 -2
- package/dist/tenants/index.d.cts +1 -2
- package/dist/tenants/index.d.ts +1 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
OmnibaseClient: () => OmnibaseClient,
|
|
24
|
+
PermissionsClient: () => PermissionsClient,
|
|
25
|
+
RolesHandler: () => RolesHandler,
|
|
24
26
|
StorageClient: () => StorageClient
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -510,6 +512,256 @@ var PaymentHandler = class {
|
|
|
510
512
|
|
|
511
513
|
// src/permissions/handler.ts
|
|
512
514
|
var import_client = require("@ory/client");
|
|
515
|
+
|
|
516
|
+
// src/permissions/roles.ts
|
|
517
|
+
var RolesHandler = class {
|
|
518
|
+
constructor(client) {
|
|
519
|
+
this.client = client;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Get available namespace definitions for UI
|
|
523
|
+
*
|
|
524
|
+
* Returns all namespaces and their available relations/permissions.
|
|
525
|
+
* Useful for building role configuration UIs.
|
|
526
|
+
*
|
|
527
|
+
* @returns List of namespace definitions
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
* ```typescript
|
|
531
|
+
* const definitions = await omnibase.permissions.roles.getDefinitions();
|
|
532
|
+
*
|
|
533
|
+
* // Output: [{ namespace: 'Tenant', relations: ['invite_user', 'delete_tenant', ...] }]
|
|
534
|
+
* definitions.forEach(def => {
|
|
535
|
+
* console.log(`${def.namespace} supports: ${def.relations.join(', ')}`);
|
|
536
|
+
* });
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
async getDefinitions() {
|
|
540
|
+
const response = await this.client.fetch(
|
|
541
|
+
"/api/v1/permissions/definitions",
|
|
542
|
+
{
|
|
543
|
+
method: "GET"
|
|
544
|
+
}
|
|
545
|
+
);
|
|
546
|
+
const data = await response.json();
|
|
547
|
+
if (!response.ok || data.error) {
|
|
548
|
+
throw new Error(data.error || "Failed to fetch definitions");
|
|
549
|
+
}
|
|
550
|
+
return data.data.definitions;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* List all roles for the current tenant
|
|
554
|
+
*
|
|
555
|
+
* Returns both system roles (defined in roles.config.json) and
|
|
556
|
+
* custom roles created via the API. System roles have `tenant_id = null`.
|
|
557
|
+
*
|
|
558
|
+
* @returns List of roles
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
* ```typescript
|
|
562
|
+
* const roles = await omnibase.permissions.roles.list();
|
|
563
|
+
*
|
|
564
|
+
* const systemRoles = roles.filter(r => r.tenant_id === null);
|
|
565
|
+
* const customRoles = roles.filter(r => r.tenant_id !== null);
|
|
566
|
+
*
|
|
567
|
+
* console.log(`System roles: ${systemRoles.map(r => r.role_name).join(', ')}`);
|
|
568
|
+
* console.log(`Custom roles: ${customRoles.map(r => r.role_name).join(', ')}`);
|
|
569
|
+
* ```
|
|
570
|
+
*/
|
|
571
|
+
async list() {
|
|
572
|
+
const response = await this.client.fetch("/api/v1/permissions/roles", {
|
|
573
|
+
method: "GET"
|
|
574
|
+
});
|
|
575
|
+
const data = await response.json();
|
|
576
|
+
if (!response.ok || data.error) {
|
|
577
|
+
throw new Error(data.error || "Failed to list roles");
|
|
578
|
+
}
|
|
579
|
+
return data.data.roles;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Create a new custom role
|
|
583
|
+
*
|
|
584
|
+
* Creates a tenant-specific role with the specified permissions.
|
|
585
|
+
* Permissions use the format `namespace#relation` or `namespace:id#relation`.
|
|
586
|
+
*
|
|
587
|
+
* @param request - Role creation request
|
|
588
|
+
* @returns Created role
|
|
589
|
+
*
|
|
590
|
+
* @example
|
|
591
|
+
* ```typescript
|
|
592
|
+
* const role = await omnibase.permissions.roles.create({
|
|
593
|
+
* role_name: 'billing_manager',
|
|
594
|
+
* permissions: [
|
|
595
|
+
* 'tenant#manage_billing',
|
|
596
|
+
* 'tenant#view_invoices',
|
|
597
|
+
* 'tenant#update_payment_methods'
|
|
598
|
+
* ]
|
|
599
|
+
* });
|
|
600
|
+
*
|
|
601
|
+
* console.log(`Created role: ${role.id}`);
|
|
602
|
+
* ```
|
|
603
|
+
*
|
|
604
|
+
* @example
|
|
605
|
+
* Resource-specific permissions:
|
|
606
|
+
* ```typescript
|
|
607
|
+
* const devRole = await omnibase.permissions.roles.create({
|
|
608
|
+
* role_name: 'project_developer',
|
|
609
|
+
* permissions: [
|
|
610
|
+
* 'project:proj_abc123#deploy',
|
|
611
|
+
* 'project:proj_abc123#view_logs',
|
|
612
|
+
* 'tenant#invite_user'
|
|
613
|
+
* ]
|
|
614
|
+
* });
|
|
615
|
+
* ```
|
|
616
|
+
*/
|
|
617
|
+
async create(request) {
|
|
618
|
+
const response = await this.client.fetch("/api/v1/permissions/roles", {
|
|
619
|
+
method: "POST",
|
|
620
|
+
headers: { "Content-Type": "application/json" },
|
|
621
|
+
body: JSON.stringify(request)
|
|
622
|
+
});
|
|
623
|
+
const data = await response.json();
|
|
624
|
+
if (!response.ok || data.error) {
|
|
625
|
+
throw new Error(data.error || "Failed to create role");
|
|
626
|
+
}
|
|
627
|
+
return data.data;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Update an existing role's permissions
|
|
631
|
+
*
|
|
632
|
+
* Updates the permissions for a role and automatically updates all
|
|
633
|
+
* Keto relationships for users assigned to this role. Old permissions
|
|
634
|
+
* are removed and new ones are created.
|
|
635
|
+
*
|
|
636
|
+
* @param roleId - ID of role to update
|
|
637
|
+
* @param request - Update request with new permissions
|
|
638
|
+
* @returns Updated role
|
|
639
|
+
*
|
|
640
|
+
* @example
|
|
641
|
+
* ```typescript
|
|
642
|
+
* const updatedRole = await omnibase.permissions.roles.update('role_123', {
|
|
643
|
+
* permissions: [
|
|
644
|
+
* 'tenant#manage_billing',
|
|
645
|
+
* 'tenant#view_invoices',
|
|
646
|
+
* 'tenant#manage_users' // Added new permission
|
|
647
|
+
* ]
|
|
648
|
+
* });
|
|
649
|
+
*
|
|
650
|
+
* console.log(`Updated role with ${updatedRole.permissions.length} permissions`);
|
|
651
|
+
* ```
|
|
652
|
+
*/
|
|
653
|
+
async update(roleId, request) {
|
|
654
|
+
const response = await this.client.fetch(
|
|
655
|
+
`/api/v1/permissions/roles/${roleId}`,
|
|
656
|
+
{
|
|
657
|
+
method: "PUT",
|
|
658
|
+
headers: { "Content-Type": "application/json" },
|
|
659
|
+
body: JSON.stringify(request)
|
|
660
|
+
}
|
|
661
|
+
);
|
|
662
|
+
const data = await response.json();
|
|
663
|
+
if (!response.ok || data.error) {
|
|
664
|
+
throw new Error(data.error || "Failed to update role");
|
|
665
|
+
}
|
|
666
|
+
return data.data;
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Delete a role
|
|
670
|
+
*
|
|
671
|
+
* Deletes the role and automatically removes all Keto relationships
|
|
672
|
+
* for users assigned to this role. Cannot delete system roles.
|
|
673
|
+
*
|
|
674
|
+
* @param roleId - ID of role to delete
|
|
675
|
+
*
|
|
676
|
+
* @example
|
|
677
|
+
* ```typescript
|
|
678
|
+
* await omnibase.permissions.roles.delete('role_123');
|
|
679
|
+
* console.log('Role deleted successfully');
|
|
680
|
+
* ```
|
|
681
|
+
*/
|
|
682
|
+
async delete(roleId) {
|
|
683
|
+
const response = await this.client.fetch(
|
|
684
|
+
`/api/v1/permissions/roles/${roleId}`,
|
|
685
|
+
{
|
|
686
|
+
method: "DELETE"
|
|
687
|
+
}
|
|
688
|
+
);
|
|
689
|
+
const data = await response.json();
|
|
690
|
+
if (!response.ok || data.error) {
|
|
691
|
+
throw new Error(data.error || "Failed to delete role");
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Assign a role to a user
|
|
696
|
+
*
|
|
697
|
+
* Assigns a role to a user and automatically creates all necessary
|
|
698
|
+
* Keto relationship tuples based on the role's permissions. The user
|
|
699
|
+
* immediately gains all permissions defined in the role.
|
|
700
|
+
*
|
|
701
|
+
* Supports assignment by either role ID or role name for flexibility.
|
|
702
|
+
*
|
|
703
|
+
* @param userId - ID of user to assign role to
|
|
704
|
+
* @param request - Assignment request with either role_id or role_name
|
|
705
|
+
*
|
|
706
|
+
* @example
|
|
707
|
+
* Assign by role ID:
|
|
708
|
+
* ```typescript
|
|
709
|
+
* await omnibase.permissions.roles.assign('user_123', {
|
|
710
|
+
* role_id: 'role_456'
|
|
711
|
+
* });
|
|
712
|
+
* ```
|
|
713
|
+
*
|
|
714
|
+
* @example
|
|
715
|
+
* Assign by role name (system or custom role):
|
|
716
|
+
* ```typescript
|
|
717
|
+
* // Assign system role
|
|
718
|
+
* await omnibase.permissions.roles.assign('user_123', {
|
|
719
|
+
* role_name: 'owner'
|
|
720
|
+
* });
|
|
721
|
+
*
|
|
722
|
+
* // Assign custom role
|
|
723
|
+
* await omnibase.permissions.roles.assign('user_456', {
|
|
724
|
+
* role_name: 'billing_manager'
|
|
725
|
+
* });
|
|
726
|
+
* ```
|
|
727
|
+
*
|
|
728
|
+
* @example
|
|
729
|
+
* Verify permissions after assignment:
|
|
730
|
+
* ```typescript
|
|
731
|
+
* await omnibase.permissions.roles.assign('user_123', {
|
|
732
|
+
* role_name: 'admin'
|
|
733
|
+
* });
|
|
734
|
+
*
|
|
735
|
+
* // User now has all permissions from the admin role
|
|
736
|
+
* const canManage = await omnibase.permissions.permissions.checkPermission(
|
|
737
|
+
* undefined,
|
|
738
|
+
* {
|
|
739
|
+
* namespace: 'Tenant',
|
|
740
|
+
* object: 'tenant_789',
|
|
741
|
+
* relation: 'manage_billing',
|
|
742
|
+
* subjectId: 'user_123'
|
|
743
|
+
* }
|
|
744
|
+
* );
|
|
745
|
+
* // canManage.data.allowed === true
|
|
746
|
+
* ```
|
|
747
|
+
*/
|
|
748
|
+
async assign(userId, request) {
|
|
749
|
+
const response = await this.client.fetch(
|
|
750
|
+
`/api/v1/permissions/users/${userId}/roles`,
|
|
751
|
+
{
|
|
752
|
+
method: "POST",
|
|
753
|
+
headers: { "Content-Type": "application/json" },
|
|
754
|
+
body: JSON.stringify(request)
|
|
755
|
+
}
|
|
756
|
+
);
|
|
757
|
+
const data = await response.json();
|
|
758
|
+
if (!response.ok || data.error) {
|
|
759
|
+
throw new Error(data.error || "Failed to assign role");
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
// src/permissions/handler.ts
|
|
513
765
|
var PermissionsClient = class {
|
|
514
766
|
/**
|
|
515
767
|
* Ory Keto RelationshipApi for managing subject-object relationships
|
|
@@ -574,6 +826,31 @@ var PermissionsClient = class {
|
|
|
574
826
|
* @group Permissions
|
|
575
827
|
*/
|
|
576
828
|
permissions;
|
|
829
|
+
/**
|
|
830
|
+
* Handler for managing roles and role-based permissions
|
|
831
|
+
*
|
|
832
|
+
* Provides methods for creating custom roles, assigning permissions,
|
|
833
|
+
* and managing role assignments. Works alongside the Keto-based
|
|
834
|
+
* permissions system to provide dynamic RBAC capabilities.
|
|
835
|
+
*
|
|
836
|
+
* @example
|
|
837
|
+
* ```typescript
|
|
838
|
+
* // Create a custom role
|
|
839
|
+
* const role = await omnibase.permissions.roles.create({
|
|
840
|
+
* role_name: 'billing_manager',
|
|
841
|
+
* permissions: ['tenant#manage_billing', 'tenant#view_invoices']
|
|
842
|
+
* });
|
|
843
|
+
*
|
|
844
|
+
* // Assign role to user
|
|
845
|
+
* await omnibase.permissions.roles.assign('user_123', {
|
|
846
|
+
* role_id: role.id
|
|
847
|
+
* });
|
|
848
|
+
* ```
|
|
849
|
+
*
|
|
850
|
+
* @since 0.7.0
|
|
851
|
+
* @group Roles
|
|
852
|
+
*/
|
|
853
|
+
roles;
|
|
577
854
|
/**
|
|
578
855
|
* Creates a new PermissionsClient instance
|
|
579
856
|
*
|
|
@@ -582,24 +859,19 @@ var PermissionsClient = class {
|
|
|
582
859
|
* for optimal performance and security separation.
|
|
583
860
|
*
|
|
584
861
|
* @param apiBaseUrl - The base URL for your Omnibase API instance
|
|
862
|
+
* @param client - The main OmnibaseClient instance (for roles handler)
|
|
585
863
|
*
|
|
586
864
|
* @throws {Error} When the base URL is invalid or cannot be reached
|
|
587
865
|
*
|
|
588
866
|
* @example
|
|
589
867
|
* ```typescript
|
|
590
|
-
* const client = new PermissionsClient('https://api.example.com');
|
|
591
|
-
* ```
|
|
592
|
-
*
|
|
593
|
-
* @example
|
|
594
|
-
* Local development:
|
|
595
|
-
* ```typescript
|
|
596
|
-
* const client = new PermissionsClient('http://localhost:8080');
|
|
868
|
+
* const client = new PermissionsClient('https://api.example.com', omnibaseClient);
|
|
597
869
|
* ```
|
|
598
870
|
*
|
|
599
871
|
* @since 1.0.0
|
|
600
872
|
* @group Client
|
|
601
873
|
*/
|
|
602
|
-
constructor(apiBaseUrl) {
|
|
874
|
+
constructor(apiBaseUrl, client) {
|
|
603
875
|
this.relationships = new import_client.RelationshipApi(
|
|
604
876
|
void 0,
|
|
605
877
|
`${apiBaseUrl}/api/v1/permissions/write`
|
|
@@ -608,6 +880,7 @@ var PermissionsClient = class {
|
|
|
608
880
|
void 0,
|
|
609
881
|
`${apiBaseUrl}/api/v1/permissions/read`
|
|
610
882
|
);
|
|
883
|
+
this.roles = new RolesHandler(client);
|
|
611
884
|
}
|
|
612
885
|
};
|
|
613
886
|
|
|
@@ -1389,7 +1662,7 @@ var TenantHandler = class {
|
|
|
1389
1662
|
var OmnibaseClient = class {
|
|
1390
1663
|
constructor(config) {
|
|
1391
1664
|
this.config = config;
|
|
1392
|
-
this.permissions = new PermissionsClient(this.config.api_url);
|
|
1665
|
+
this.permissions = new PermissionsClient(this.config.api_url, this);
|
|
1393
1666
|
}
|
|
1394
1667
|
/**
|
|
1395
1668
|
* Main payment handler for all payment-related operations
|
|
@@ -1527,5 +1800,7 @@ var OmnibaseClient = class {
|
|
|
1527
1800
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1528
1801
|
0 && (module.exports = {
|
|
1529
1802
|
OmnibaseClient,
|
|
1803
|
+
PermissionsClient,
|
|
1804
|
+
RolesHandler,
|
|
1530
1805
|
StorageClient
|
|
1531
1806
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import './permissions/index.cjs';
|
|
1
|
+
export { q as ApiResponse, A as AssignRoleRequest, C as CreateRoleRequest, D as DownloadResult, N as NamespaceDefinition, p as OmnibaseClient, O as OmnibaseClientConfig, P as PermissionsClient, a as Role, R as RolesHandler, S as StorageClient, U as UpdateRoleRequest, b as UploadOptions, c as UploadResult } from './payments/index.cjs';
|
|
3
2
|
import '@ory/client';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import './permissions/index.js';
|
|
1
|
+
export { q as ApiResponse, A as AssignRoleRequest, C as CreateRoleRequest, D as DownloadResult, N as NamespaceDefinition, p as OmnibaseClient, O as OmnibaseClientConfig, P as PermissionsClient, a as Role, R as RolesHandler, S as StorageClient, U as UpdateRoleRequest, b as UploadOptions, c as UploadResult } from './payments/index.js';
|
|
3
2
|
import '@ory/client';
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
PermissionsClient
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
PaymentHandler
|
|
6
|
-
} from "./chunk-QPW6G4PA.js";
|
|
2
|
+
PermissionsClient,
|
|
3
|
+
RolesHandler
|
|
4
|
+
} from "./chunk-V4FWENQQ.js";
|
|
7
5
|
import {
|
|
8
6
|
StorageClient
|
|
9
7
|
} from "./chunk-I6DMWC32.js";
|
|
8
|
+
import {
|
|
9
|
+
PaymentHandler
|
|
10
|
+
} from "./chunk-QPW6G4PA.js";
|
|
10
11
|
import {
|
|
11
12
|
TenantHandler
|
|
12
13
|
} from "./chunk-6OGESVXW.js";
|
|
@@ -15,7 +16,7 @@ import {
|
|
|
15
16
|
var OmnibaseClient = class {
|
|
16
17
|
constructor(config) {
|
|
17
18
|
this.config = config;
|
|
18
|
-
this.permissions = new PermissionsClient(this.config.api_url);
|
|
19
|
+
this.permissions = new PermissionsClient(this.config.api_url, this);
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
22
|
* Main payment handler for all payment-related operations
|
|
@@ -152,5 +153,7 @@ var OmnibaseClient = class {
|
|
|
152
153
|
};
|
|
153
154
|
export {
|
|
154
155
|
OmnibaseClient,
|
|
156
|
+
PermissionsClient,
|
|
157
|
+
RolesHandler,
|
|
155
158
|
StorageClient
|
|
156
159
|
};
|