@omnibase/core-js 0.7.0 → 0.7.2
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/database/index.cjs +1 -28
- package/dist/database/index.d.cts +3 -3
- package/dist/database/index.d.ts +3 -3
- package/dist/database/index.js +1 -28
- package/dist/index.cjs +251 -9
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +7 -4
- package/dist/payments/index.d.cts +603 -3
- package/dist/payments/index.d.ts +603 -3
- package/dist/permissions/index.cjs +250 -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,223 @@ 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("/api/v1/roles/definitions", {
|
|
541
|
+
method: "GET"
|
|
542
|
+
});
|
|
543
|
+
const data = await response.json();
|
|
544
|
+
if (!response.ok || data.error) {
|
|
545
|
+
throw new Error(data.error || "Failed to fetch definitions");
|
|
546
|
+
}
|
|
547
|
+
return data.data.definitions;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* List all roles for the current tenant
|
|
551
|
+
*
|
|
552
|
+
* Returns both system roles (defined in roles.config.json) and
|
|
553
|
+
* custom roles created via the API. System roles have `tenant_id = null`.
|
|
554
|
+
*
|
|
555
|
+
* @returns List of roles
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* ```typescript
|
|
559
|
+
* const roles = await omnibase.permissions.roles.list();
|
|
560
|
+
*
|
|
561
|
+
* const systemRoles = roles.filter(r => r.tenant_id === null);
|
|
562
|
+
* const customRoles = roles.filter(r => r.tenant_id !== null);
|
|
563
|
+
*
|
|
564
|
+
* console.log(`System roles: ${systemRoles.map(r => r.role_name).join(', ')}`);
|
|
565
|
+
* console.log(`Custom roles: ${customRoles.map(r => r.role_name).join(', ')}`);
|
|
566
|
+
* ```
|
|
567
|
+
*/
|
|
568
|
+
async list() {
|
|
569
|
+
const response = await this.client.fetch("/api/v1/roles/roles", {
|
|
570
|
+
method: "GET"
|
|
571
|
+
});
|
|
572
|
+
const data = await response.json();
|
|
573
|
+
if (!response.ok || data.error) {
|
|
574
|
+
throw new Error(data.error || "Failed to list roles");
|
|
575
|
+
}
|
|
576
|
+
return data.data.roles;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Create a new custom role
|
|
580
|
+
*
|
|
581
|
+
* Creates a tenant-specific role with the specified permissions.
|
|
582
|
+
* Permissions use the format `namespace#relation` or `namespace:id#relation`.
|
|
583
|
+
*
|
|
584
|
+
* @param request - Role creation request
|
|
585
|
+
* @returns Created role
|
|
586
|
+
*
|
|
587
|
+
* @example
|
|
588
|
+
* ```typescript
|
|
589
|
+
* const role = await omnibase.permissions.roles.create({
|
|
590
|
+
* role_name: 'billing_manager',
|
|
591
|
+
* permissions: [
|
|
592
|
+
* 'tenant#manage_billing',
|
|
593
|
+
* 'tenant#view_invoices',
|
|
594
|
+
* 'tenant#update_payment_methods'
|
|
595
|
+
* ]
|
|
596
|
+
* });
|
|
597
|
+
*
|
|
598
|
+
* console.log(`Created role: ${role.id}`);
|
|
599
|
+
* ```
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* Resource-specific permissions:
|
|
603
|
+
* ```typescript
|
|
604
|
+
* const devRole = await omnibase.permissions.roles.create({
|
|
605
|
+
* role_name: 'project_developer',
|
|
606
|
+
* permissions: [
|
|
607
|
+
* 'project:proj_abc123#deploy',
|
|
608
|
+
* 'project:proj_abc123#view_logs',
|
|
609
|
+
* 'tenant#invite_user'
|
|
610
|
+
* ]
|
|
611
|
+
* });
|
|
612
|
+
* ```
|
|
613
|
+
*/
|
|
614
|
+
async create(request) {
|
|
615
|
+
const response = await this.client.fetch("/api/v1/roles/roles", {
|
|
616
|
+
method: "POST",
|
|
617
|
+
headers: { "Content-Type": "application/json" },
|
|
618
|
+
body: JSON.stringify(request)
|
|
619
|
+
});
|
|
620
|
+
const data = await response.json();
|
|
621
|
+
if (!response.ok || data.error) {
|
|
622
|
+
throw new Error(data.error || "Failed to create role");
|
|
623
|
+
}
|
|
624
|
+
return data.data;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Update an existing role's permissions
|
|
628
|
+
*
|
|
629
|
+
* Updates the permissions for a role and automatically updates all
|
|
630
|
+
* Keto relationships for users assigned to this role. Old permissions
|
|
631
|
+
* are removed and new ones are created.
|
|
632
|
+
*
|
|
633
|
+
* @param roleId - ID of role to update
|
|
634
|
+
* @param request - Update request with new permissions
|
|
635
|
+
* @returns Updated role
|
|
636
|
+
*
|
|
637
|
+
* @example
|
|
638
|
+
* ```typescript
|
|
639
|
+
* const updatedRole = await omnibase.permissions.roles.update('role_123', {
|
|
640
|
+
* permissions: [
|
|
641
|
+
* 'tenant#manage_billing',
|
|
642
|
+
* 'tenant#view_invoices',
|
|
643
|
+
* 'tenant#manage_users' // Added new permission
|
|
644
|
+
* ]
|
|
645
|
+
* });
|
|
646
|
+
*
|
|
647
|
+
* console.log(`Updated role with ${updatedRole.permissions.length} permissions`);
|
|
648
|
+
* ```
|
|
649
|
+
*/
|
|
650
|
+
async update(roleId, request) {
|
|
651
|
+
const response = await this.client.fetch(`/api/v1/roles/roles/${roleId}`, {
|
|
652
|
+
method: "PUT",
|
|
653
|
+
headers: { "Content-Type": "application/json" },
|
|
654
|
+
body: JSON.stringify(request)
|
|
655
|
+
});
|
|
656
|
+
const data = await response.json();
|
|
657
|
+
if (!response.ok || data.error) {
|
|
658
|
+
throw new Error(data.error || "Failed to update role");
|
|
659
|
+
}
|
|
660
|
+
return data.data;
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Delete a role
|
|
664
|
+
*
|
|
665
|
+
* Deletes the role and automatically removes all Keto relationships
|
|
666
|
+
* for users assigned to this role. Cannot delete system roles.
|
|
667
|
+
*
|
|
668
|
+
* @param roleId - ID of role to delete
|
|
669
|
+
*
|
|
670
|
+
* @example
|
|
671
|
+
* ```typescript
|
|
672
|
+
* await omnibase.permissions.roles.delete('role_123');
|
|
673
|
+
* console.log('Role deleted successfully');
|
|
674
|
+
* ```
|
|
675
|
+
*/
|
|
676
|
+
async delete(roleId) {
|
|
677
|
+
const response = await this.client.fetch(`/api/v1/roles/roles/${roleId}`, {
|
|
678
|
+
method: "DELETE"
|
|
679
|
+
});
|
|
680
|
+
const data = await response.json();
|
|
681
|
+
if (!response.ok || data.error) {
|
|
682
|
+
throw new Error(data.error || "Failed to delete role");
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* Assign a role to a user
|
|
687
|
+
*
|
|
688
|
+
* Assigns a role to a user and automatically creates all necessary
|
|
689
|
+
* Keto relationship tuples based on the role's permissions. The user
|
|
690
|
+
* immediately gains all permissions defined in the role.
|
|
691
|
+
*
|
|
692
|
+
* @param userId - ID of user to assign role to
|
|
693
|
+
* @param request - Assignment request with role ID
|
|
694
|
+
*
|
|
695
|
+
* @example
|
|
696
|
+
* ```typescript
|
|
697
|
+
* // Assign billing manager role to user
|
|
698
|
+
* await omnibase.permissions.roles.assign('user_123', {
|
|
699
|
+
* role_id: 'role_456'
|
|
700
|
+
* });
|
|
701
|
+
*
|
|
702
|
+
* // User now has all permissions from the role
|
|
703
|
+
* const canManageBilling = await omnibase.permissions.permissions.checkPermission(
|
|
704
|
+
* undefined,
|
|
705
|
+
* {
|
|
706
|
+
* namespace: 'Tenant',
|
|
707
|
+
* object: 'tenant_789',
|
|
708
|
+
* relation: 'manage_billing',
|
|
709
|
+
* subjectId: 'user_123'
|
|
710
|
+
* }
|
|
711
|
+
* );
|
|
712
|
+
* // canManageBilling.data.allowed === true
|
|
713
|
+
* ```
|
|
714
|
+
*/
|
|
715
|
+
async assign(userId, request) {
|
|
716
|
+
const response = await this.client.fetch(
|
|
717
|
+
`/api/v1/roles/users/${userId}/roles`,
|
|
718
|
+
{
|
|
719
|
+
method: "POST",
|
|
720
|
+
headers: { "Content-Type": "application/json" },
|
|
721
|
+
body: JSON.stringify(request)
|
|
722
|
+
}
|
|
723
|
+
);
|
|
724
|
+
const data = await response.json();
|
|
725
|
+
if (!response.ok || data.error) {
|
|
726
|
+
throw new Error(data.error || "Failed to assign role");
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
// src/permissions/handler.ts
|
|
513
732
|
var PermissionsClient = class {
|
|
514
733
|
/**
|
|
515
734
|
* Ory Keto RelationshipApi for managing subject-object relationships
|
|
@@ -574,6 +793,31 @@ var PermissionsClient = class {
|
|
|
574
793
|
* @group Permissions
|
|
575
794
|
*/
|
|
576
795
|
permissions;
|
|
796
|
+
/**
|
|
797
|
+
* Handler for managing roles and role-based permissions
|
|
798
|
+
*
|
|
799
|
+
* Provides methods for creating custom roles, assigning permissions,
|
|
800
|
+
* and managing role assignments. Works alongside the Keto-based
|
|
801
|
+
* permissions system to provide dynamic RBAC capabilities.
|
|
802
|
+
*
|
|
803
|
+
* @example
|
|
804
|
+
* ```typescript
|
|
805
|
+
* // Create a custom role
|
|
806
|
+
* const role = await omnibase.permissions.roles.create({
|
|
807
|
+
* role_name: 'billing_manager',
|
|
808
|
+
* permissions: ['tenant#manage_billing', 'tenant#view_invoices']
|
|
809
|
+
* });
|
|
810
|
+
*
|
|
811
|
+
* // Assign role to user
|
|
812
|
+
* await omnibase.permissions.roles.assign('user_123', {
|
|
813
|
+
* role_id: role.id
|
|
814
|
+
* });
|
|
815
|
+
* ```
|
|
816
|
+
*
|
|
817
|
+
* @since 0.7.0
|
|
818
|
+
* @group Roles
|
|
819
|
+
*/
|
|
820
|
+
roles;
|
|
577
821
|
/**
|
|
578
822
|
* Creates a new PermissionsClient instance
|
|
579
823
|
*
|
|
@@ -582,24 +826,19 @@ var PermissionsClient = class {
|
|
|
582
826
|
* for optimal performance and security separation.
|
|
583
827
|
*
|
|
584
828
|
* @param apiBaseUrl - The base URL for your Omnibase API instance
|
|
829
|
+
* @param client - The main OmnibaseClient instance (for roles handler)
|
|
585
830
|
*
|
|
586
831
|
* @throws {Error} When the base URL is invalid or cannot be reached
|
|
587
832
|
*
|
|
588
833
|
* @example
|
|
589
834
|
* ```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');
|
|
835
|
+
* const client = new PermissionsClient('https://api.example.com', omnibaseClient);
|
|
597
836
|
* ```
|
|
598
837
|
*
|
|
599
838
|
* @since 1.0.0
|
|
600
839
|
* @group Client
|
|
601
840
|
*/
|
|
602
|
-
constructor(apiBaseUrl) {
|
|
841
|
+
constructor(apiBaseUrl, client) {
|
|
603
842
|
this.relationships = new import_client.RelationshipApi(
|
|
604
843
|
void 0,
|
|
605
844
|
`${apiBaseUrl}/api/v1/permissions/write`
|
|
@@ -608,6 +847,7 @@ var PermissionsClient = class {
|
|
|
608
847
|
void 0,
|
|
609
848
|
`${apiBaseUrl}/api/v1/permissions/read`
|
|
610
849
|
);
|
|
850
|
+
this.roles = new RolesHandler(client);
|
|
611
851
|
}
|
|
612
852
|
};
|
|
613
853
|
|
|
@@ -1389,7 +1629,7 @@ var TenantHandler = class {
|
|
|
1389
1629
|
var OmnibaseClient = class {
|
|
1390
1630
|
constructor(config) {
|
|
1391
1631
|
this.config = config;
|
|
1392
|
-
this.permissions = new PermissionsClient(this.config.api_url);
|
|
1632
|
+
this.permissions = new PermissionsClient(this.config.api_url, this);
|
|
1393
1633
|
}
|
|
1394
1634
|
/**
|
|
1395
1635
|
* Main payment handler for all payment-related operations
|
|
@@ -1527,5 +1767,7 @@ var OmnibaseClient = class {
|
|
|
1527
1767
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1528
1768
|
0 && (module.exports = {
|
|
1529
1769
|
OmnibaseClient,
|
|
1770
|
+
PermissionsClient,
|
|
1771
|
+
RolesHandler,
|
|
1530
1772
|
StorageClient
|
|
1531
1773
|
});
|
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,9 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PermissionsClient,
|
|
3
|
+
RolesHandler
|
|
4
|
+
} from "./chunk-JNM7XP7L.js";
|
|
1
5
|
import {
|
|
2
6
|
PaymentHandler
|
|
3
7
|
} from "./chunk-QPW6G4PA.js";
|
|
4
|
-
import {
|
|
5
|
-
PermissionsClient
|
|
6
|
-
} from "./chunk-DDFBRGMG.js";
|
|
7
8
|
import {
|
|
8
9
|
StorageClient
|
|
9
10
|
} from "./chunk-I6DMWC32.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
|
};
|