@omnibase/core-js 0.7.1 → 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/index.cjs +251 -9
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +6 -3
- 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
|
@@ -20,12 +20,230 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/permissions/index.ts
|
|
21
21
|
var permissions_exports = {};
|
|
22
22
|
__export(permissions_exports, {
|
|
23
|
-
PermissionsClient: () => PermissionsClient
|
|
23
|
+
PermissionsClient: () => PermissionsClient,
|
|
24
|
+
RolesHandler: () => RolesHandler
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(permissions_exports);
|
|
26
27
|
|
|
27
28
|
// src/permissions/handler.ts
|
|
28
29
|
var import_client = require("@ory/client");
|
|
30
|
+
|
|
31
|
+
// src/permissions/roles.ts
|
|
32
|
+
var RolesHandler = class {
|
|
33
|
+
constructor(client) {
|
|
34
|
+
this.client = client;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get available namespace definitions for UI
|
|
38
|
+
*
|
|
39
|
+
* Returns all namespaces and their available relations/permissions.
|
|
40
|
+
* Useful for building role configuration UIs.
|
|
41
|
+
*
|
|
42
|
+
* @returns List of namespace definitions
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const definitions = await omnibase.permissions.roles.getDefinitions();
|
|
47
|
+
*
|
|
48
|
+
* // Output: [{ namespace: 'Tenant', relations: ['invite_user', 'delete_tenant', ...] }]
|
|
49
|
+
* definitions.forEach(def => {
|
|
50
|
+
* console.log(`${def.namespace} supports: ${def.relations.join(', ')}`);
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
async getDefinitions() {
|
|
55
|
+
const response = await this.client.fetch("/api/v1/roles/definitions", {
|
|
56
|
+
method: "GET"
|
|
57
|
+
});
|
|
58
|
+
const data = await response.json();
|
|
59
|
+
if (!response.ok || data.error) {
|
|
60
|
+
throw new Error(data.error || "Failed to fetch definitions");
|
|
61
|
+
}
|
|
62
|
+
return data.data.definitions;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* List all roles for the current tenant
|
|
66
|
+
*
|
|
67
|
+
* Returns both system roles (defined in roles.config.json) and
|
|
68
|
+
* custom roles created via the API. System roles have `tenant_id = null`.
|
|
69
|
+
*
|
|
70
|
+
* @returns List of roles
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const roles = await omnibase.permissions.roles.list();
|
|
75
|
+
*
|
|
76
|
+
* const systemRoles = roles.filter(r => r.tenant_id === null);
|
|
77
|
+
* const customRoles = roles.filter(r => r.tenant_id !== null);
|
|
78
|
+
*
|
|
79
|
+
* console.log(`System roles: ${systemRoles.map(r => r.role_name).join(', ')}`);
|
|
80
|
+
* console.log(`Custom roles: ${customRoles.map(r => r.role_name).join(', ')}`);
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
async list() {
|
|
84
|
+
const response = await this.client.fetch("/api/v1/roles/roles", {
|
|
85
|
+
method: "GET"
|
|
86
|
+
});
|
|
87
|
+
const data = await response.json();
|
|
88
|
+
if (!response.ok || data.error) {
|
|
89
|
+
throw new Error(data.error || "Failed to list roles");
|
|
90
|
+
}
|
|
91
|
+
return data.data.roles;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Create a new custom role
|
|
95
|
+
*
|
|
96
|
+
* Creates a tenant-specific role with the specified permissions.
|
|
97
|
+
* Permissions use the format `namespace#relation` or `namespace:id#relation`.
|
|
98
|
+
*
|
|
99
|
+
* @param request - Role creation request
|
|
100
|
+
* @returns Created role
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const role = await omnibase.permissions.roles.create({
|
|
105
|
+
* role_name: 'billing_manager',
|
|
106
|
+
* permissions: [
|
|
107
|
+
* 'tenant#manage_billing',
|
|
108
|
+
* 'tenant#view_invoices',
|
|
109
|
+
* 'tenant#update_payment_methods'
|
|
110
|
+
* ]
|
|
111
|
+
* });
|
|
112
|
+
*
|
|
113
|
+
* console.log(`Created role: ${role.id}`);
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* Resource-specific permissions:
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const devRole = await omnibase.permissions.roles.create({
|
|
120
|
+
* role_name: 'project_developer',
|
|
121
|
+
* permissions: [
|
|
122
|
+
* 'project:proj_abc123#deploy',
|
|
123
|
+
* 'project:proj_abc123#view_logs',
|
|
124
|
+
* 'tenant#invite_user'
|
|
125
|
+
* ]
|
|
126
|
+
* });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
async create(request) {
|
|
130
|
+
const response = await this.client.fetch("/api/v1/roles/roles", {
|
|
131
|
+
method: "POST",
|
|
132
|
+
headers: { "Content-Type": "application/json" },
|
|
133
|
+
body: JSON.stringify(request)
|
|
134
|
+
});
|
|
135
|
+
const data = await response.json();
|
|
136
|
+
if (!response.ok || data.error) {
|
|
137
|
+
throw new Error(data.error || "Failed to create role");
|
|
138
|
+
}
|
|
139
|
+
return data.data;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Update an existing role's permissions
|
|
143
|
+
*
|
|
144
|
+
* Updates the permissions for a role and automatically updates all
|
|
145
|
+
* Keto relationships for users assigned to this role. Old permissions
|
|
146
|
+
* are removed and new ones are created.
|
|
147
|
+
*
|
|
148
|
+
* @param roleId - ID of role to update
|
|
149
|
+
* @param request - Update request with new permissions
|
|
150
|
+
* @returns Updated role
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const updatedRole = await omnibase.permissions.roles.update('role_123', {
|
|
155
|
+
* permissions: [
|
|
156
|
+
* 'tenant#manage_billing',
|
|
157
|
+
* 'tenant#view_invoices',
|
|
158
|
+
* 'tenant#manage_users' // Added new permission
|
|
159
|
+
* ]
|
|
160
|
+
* });
|
|
161
|
+
*
|
|
162
|
+
* console.log(`Updated role with ${updatedRole.permissions.length} permissions`);
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
async update(roleId, request) {
|
|
166
|
+
const response = await this.client.fetch(`/api/v1/roles/roles/${roleId}`, {
|
|
167
|
+
method: "PUT",
|
|
168
|
+
headers: { "Content-Type": "application/json" },
|
|
169
|
+
body: JSON.stringify(request)
|
|
170
|
+
});
|
|
171
|
+
const data = await response.json();
|
|
172
|
+
if (!response.ok || data.error) {
|
|
173
|
+
throw new Error(data.error || "Failed to update role");
|
|
174
|
+
}
|
|
175
|
+
return data.data;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Delete a role
|
|
179
|
+
*
|
|
180
|
+
* Deletes the role and automatically removes all Keto relationships
|
|
181
|
+
* for users assigned to this role. Cannot delete system roles.
|
|
182
|
+
*
|
|
183
|
+
* @param roleId - ID of role to delete
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* await omnibase.permissions.roles.delete('role_123');
|
|
188
|
+
* console.log('Role deleted successfully');
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
async delete(roleId) {
|
|
192
|
+
const response = await this.client.fetch(`/api/v1/roles/roles/${roleId}`, {
|
|
193
|
+
method: "DELETE"
|
|
194
|
+
});
|
|
195
|
+
const data = await response.json();
|
|
196
|
+
if (!response.ok || data.error) {
|
|
197
|
+
throw new Error(data.error || "Failed to delete role");
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Assign a role to a user
|
|
202
|
+
*
|
|
203
|
+
* Assigns a role to a user and automatically creates all necessary
|
|
204
|
+
* Keto relationship tuples based on the role's permissions. The user
|
|
205
|
+
* immediately gains all permissions defined in the role.
|
|
206
|
+
*
|
|
207
|
+
* @param userId - ID of user to assign role to
|
|
208
|
+
* @param request - Assignment request with role ID
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* // Assign billing manager role to user
|
|
213
|
+
* await omnibase.permissions.roles.assign('user_123', {
|
|
214
|
+
* role_id: 'role_456'
|
|
215
|
+
* });
|
|
216
|
+
*
|
|
217
|
+
* // User now has all permissions from the role
|
|
218
|
+
* const canManageBilling = await omnibase.permissions.permissions.checkPermission(
|
|
219
|
+
* undefined,
|
|
220
|
+
* {
|
|
221
|
+
* namespace: 'Tenant',
|
|
222
|
+
* object: 'tenant_789',
|
|
223
|
+
* relation: 'manage_billing',
|
|
224
|
+
* subjectId: 'user_123'
|
|
225
|
+
* }
|
|
226
|
+
* );
|
|
227
|
+
* // canManageBilling.data.allowed === true
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
async assign(userId, request) {
|
|
231
|
+
const response = await this.client.fetch(
|
|
232
|
+
`/api/v1/roles/users/${userId}/roles`,
|
|
233
|
+
{
|
|
234
|
+
method: "POST",
|
|
235
|
+
headers: { "Content-Type": "application/json" },
|
|
236
|
+
body: JSON.stringify(request)
|
|
237
|
+
}
|
|
238
|
+
);
|
|
239
|
+
const data = await response.json();
|
|
240
|
+
if (!response.ok || data.error) {
|
|
241
|
+
throw new Error(data.error || "Failed to assign role");
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
// src/permissions/handler.ts
|
|
29
247
|
var PermissionsClient = class {
|
|
30
248
|
/**
|
|
31
249
|
* Ory Keto RelationshipApi for managing subject-object relationships
|
|
@@ -90,6 +308,31 @@ var PermissionsClient = class {
|
|
|
90
308
|
* @group Permissions
|
|
91
309
|
*/
|
|
92
310
|
permissions;
|
|
311
|
+
/**
|
|
312
|
+
* Handler for managing roles and role-based permissions
|
|
313
|
+
*
|
|
314
|
+
* Provides methods for creating custom roles, assigning permissions,
|
|
315
|
+
* and managing role assignments. Works alongside the Keto-based
|
|
316
|
+
* permissions system to provide dynamic RBAC capabilities.
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```typescript
|
|
320
|
+
* // Create a custom role
|
|
321
|
+
* const role = await omnibase.permissions.roles.create({
|
|
322
|
+
* role_name: 'billing_manager',
|
|
323
|
+
* permissions: ['tenant#manage_billing', 'tenant#view_invoices']
|
|
324
|
+
* });
|
|
325
|
+
*
|
|
326
|
+
* // Assign role to user
|
|
327
|
+
* await omnibase.permissions.roles.assign('user_123', {
|
|
328
|
+
* role_id: role.id
|
|
329
|
+
* });
|
|
330
|
+
* ```
|
|
331
|
+
*
|
|
332
|
+
* @since 0.7.0
|
|
333
|
+
* @group Roles
|
|
334
|
+
*/
|
|
335
|
+
roles;
|
|
93
336
|
/**
|
|
94
337
|
* Creates a new PermissionsClient instance
|
|
95
338
|
*
|
|
@@ -98,24 +341,19 @@ var PermissionsClient = class {
|
|
|
98
341
|
* for optimal performance and security separation.
|
|
99
342
|
*
|
|
100
343
|
* @param apiBaseUrl - The base URL for your Omnibase API instance
|
|
344
|
+
* @param client - The main OmnibaseClient instance (for roles handler)
|
|
101
345
|
*
|
|
102
346
|
* @throws {Error} When the base URL is invalid or cannot be reached
|
|
103
347
|
*
|
|
104
348
|
* @example
|
|
105
349
|
* ```typescript
|
|
106
|
-
* const client = new PermissionsClient('https://api.example.com');
|
|
107
|
-
* ```
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* Local development:
|
|
111
|
-
* ```typescript
|
|
112
|
-
* const client = new PermissionsClient('http://localhost:8080');
|
|
350
|
+
* const client = new PermissionsClient('https://api.example.com', omnibaseClient);
|
|
113
351
|
* ```
|
|
114
352
|
*
|
|
115
353
|
* @since 1.0.0
|
|
116
354
|
* @group Client
|
|
117
355
|
*/
|
|
118
|
-
constructor(apiBaseUrl) {
|
|
356
|
+
constructor(apiBaseUrl, client) {
|
|
119
357
|
this.relationships = new import_client.RelationshipApi(
|
|
120
358
|
void 0,
|
|
121
359
|
`${apiBaseUrl}/api/v1/permissions/write`
|
|
@@ -124,9 +362,11 @@ var PermissionsClient = class {
|
|
|
124
362
|
void 0,
|
|
125
363
|
`${apiBaseUrl}/api/v1/permissions/read`
|
|
126
364
|
);
|
|
365
|
+
this.roles = new RolesHandler(client);
|
|
127
366
|
}
|
|
128
367
|
};
|
|
129
368
|
// Annotate the CommonJS export names for ESM import in node:
|
|
130
369
|
0 && (module.exports = {
|
|
131
|
-
PermissionsClient
|
|
370
|
+
PermissionsClient,
|
|
371
|
+
RolesHandler
|
|
132
372
|
});
|
|
@@ -1,195 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Client for managing permissions and relationships using Ory Keto
|
|
5
|
-
*
|
|
6
|
-
* This client provides access to Ory Keto's permission system, allowing you to
|
|
7
|
-
* create, manage, and check relationships between subjects and objects. It handles
|
|
8
|
-
* both read operations (permission checks) and write operations (relationship management).
|
|
9
|
-
*
|
|
10
|
-
* The client automatically configures separate endpoints for read and write operations
|
|
11
|
-
* to optimize performance and security by following Ory Keto's recommended architecture.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* Basic permission checking:
|
|
15
|
-
* ```typescript
|
|
16
|
-
* import { PermissionsClient } from '@omnibase/core-js/permissions';
|
|
17
|
-
*
|
|
18
|
-
* const permissionsClient = new PermissionsClient('https://api.example.com');
|
|
19
|
-
*
|
|
20
|
-
* // Check if a user can view a tenant
|
|
21
|
-
* const canView = await permissionsClient.permissions.checkPermission(
|
|
22
|
-
* undefined,
|
|
23
|
-
* {
|
|
24
|
-
* namespace: 'Tenant',
|
|
25
|
-
* object: 'tenant_123',
|
|
26
|
-
* relation: 'view',
|
|
27
|
-
* subjectId: 'user_456'
|
|
28
|
-
* }
|
|
29
|
-
* );
|
|
30
|
-
*
|
|
31
|
-
* if (canView.data.allowed) {
|
|
32
|
-
* console.log('User can view the tenant');
|
|
33
|
-
* }
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* Creating tenant relationships:
|
|
38
|
-
* ```typescript
|
|
39
|
-
* // Create a relationship making a user an owner of a tenant
|
|
40
|
-
* await permissionsClient.relationships.createRelationship(
|
|
41
|
-
* undefined,
|
|
42
|
-
* {
|
|
43
|
-
* namespace: 'Tenant',
|
|
44
|
-
* object: 'tenant_123',
|
|
45
|
-
* relation: 'owners',
|
|
46
|
-
* subjectId: 'user_456'
|
|
47
|
-
* }
|
|
48
|
-
* );
|
|
49
|
-
*
|
|
50
|
-
* // Now the user has owner permissions on the tenant
|
|
51
|
-
* console.log('User is now an owner of the tenant');
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* Complex tenant permission management:
|
|
56
|
-
* ```typescript
|
|
57
|
-
* const tenantId = 'tenant_123';
|
|
58
|
-
* const userId = 'user_456';
|
|
59
|
-
*
|
|
60
|
-
* // Grant admin permissions to a user
|
|
61
|
-
* await permissionsClient.relationships.createRelationship(
|
|
62
|
-
* undefined,
|
|
63
|
-
* {
|
|
64
|
-
* namespace: 'Tenant',
|
|
65
|
-
* object: tenantId,
|
|
66
|
-
* relation: 'admins',
|
|
67
|
-
* subjectId: userId
|
|
68
|
-
* }
|
|
69
|
-
* );
|
|
70
|
-
*
|
|
71
|
-
* // Check if user can manage members (admins and owners can)
|
|
72
|
-
* const canManageMembers = await permissionsClient.permissions.checkPermission(
|
|
73
|
-
* undefined,
|
|
74
|
-
* {
|
|
75
|
-
* namespace: 'Tenant',
|
|
76
|
-
* object: tenantId,
|
|
77
|
-
* relation: 'manage_members',
|
|
78
|
-
* subjectId: userId
|
|
79
|
-
* }
|
|
80
|
-
* );
|
|
81
|
-
*
|
|
82
|
-
* if (canManageMembers.data.allowed) {
|
|
83
|
-
* // User can invite/remove members
|
|
84
|
-
* console.log('User can manage tenant members');
|
|
85
|
-
* }
|
|
86
|
-
*
|
|
87
|
-
* // Later, remove admin permissions
|
|
88
|
-
* await permissionsClient.relationships.deleteRelationships(
|
|
89
|
-
* undefined,
|
|
90
|
-
* {
|
|
91
|
-
* namespace: 'Tenant',
|
|
92
|
-
* object: tenantId,
|
|
93
|
-
* relation: 'admins',
|
|
94
|
-
* subjectId: userId
|
|
95
|
-
* }
|
|
96
|
-
* );
|
|
97
|
-
* ```
|
|
98
|
-
*
|
|
99
|
-
* @since 1.0.0
|
|
100
|
-
* @public
|
|
101
|
-
* @group Client
|
|
102
|
-
*/
|
|
103
|
-
declare class PermissionsClient {
|
|
104
|
-
/**
|
|
105
|
-
* Ory Keto RelationshipApi for managing subject-object relationships
|
|
106
|
-
*
|
|
107
|
-
* Provides methods for creating, updating, and deleting relationships between
|
|
108
|
-
* subjects (users, groups) and objects (tenants, resources). This API handles
|
|
109
|
-
* write operations and is used to establish permission structures.
|
|
110
|
-
*
|
|
111
|
-
* Key methods:
|
|
112
|
-
* - `createRelationship()` - Creates a new relationship tuple
|
|
113
|
-
* - `deleteRelationships()` - Removes existing relationship tuples
|
|
114
|
-
* - `getRelationships()` - Queries existing relationships
|
|
115
|
-
* - `patchRelationships()` - Updates multiple relationships atomically
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```typescript
|
|
119
|
-
* // Create a relationship
|
|
120
|
-
* await client.relationships.createRelationship(
|
|
121
|
-
* undefined,
|
|
122
|
-
* {
|
|
123
|
-
* namespace: 'Tenant',
|
|
124
|
-
* object: 'tenant_123',
|
|
125
|
-
* relation: 'members',
|
|
126
|
-
* subjectId: 'user_456'
|
|
127
|
-
* }
|
|
128
|
-
* );
|
|
129
|
-
* ```
|
|
130
|
-
*
|
|
131
|
-
* @since 1.0.0
|
|
132
|
-
* @group Relationships
|
|
133
|
-
*/
|
|
134
|
-
relationships: RelationshipApi;
|
|
135
|
-
/**
|
|
136
|
-
* Ory Keto PermissionApi for checking permissions
|
|
137
|
-
*
|
|
138
|
-
* Provides methods for querying whether a subject has a specific permission
|
|
139
|
-
* on an object. This API handles read operations and is optimized for fast
|
|
140
|
-
* permission checks in your application logic.
|
|
141
|
-
*
|
|
142
|
-
* Key methods:
|
|
143
|
-
* - `checkPermission()` - Checks if a subject has permission on an object
|
|
144
|
-
* - `checkPermissionOrError()` - Same as above but throws error if denied
|
|
145
|
-
* - `expandPermissions()` - Expands relationships to show all granted permissions
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```typescript
|
|
149
|
-
* // Check permission
|
|
150
|
-
* const result = await client.permissions.checkPermission(
|
|
151
|
-
* undefined,
|
|
152
|
-
* {
|
|
153
|
-
* namespace: 'Tenant',
|
|
154
|
-
* object: 'tenant_123',
|
|
155
|
-
* relation: 'view',
|
|
156
|
-
* subjectId: 'user_456'
|
|
157
|
-
* }
|
|
158
|
-
* );
|
|
159
|
-
*
|
|
160
|
-
* console.log('Has permission:', result.data.allowed);
|
|
161
|
-
* ```
|
|
162
|
-
*
|
|
163
|
-
* @since 1.0.0
|
|
164
|
-
* @group Permissions
|
|
165
|
-
*/
|
|
166
|
-
permissions: PermissionApi;
|
|
167
|
-
/**
|
|
168
|
-
* Creates a new PermissionsClient instance
|
|
169
|
-
*
|
|
170
|
-
* Initializes the client with separate endpoints for read and write operations.
|
|
171
|
-
* The client automatically appends the appropriate Keto API paths to the base URL
|
|
172
|
-
* for optimal performance and security separation.
|
|
173
|
-
*
|
|
174
|
-
* @param apiBaseUrl - The base URL for your Omnibase API instance
|
|
175
|
-
*
|
|
176
|
-
* @throws {Error} When the base URL is invalid or cannot be reached
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* ```typescript
|
|
180
|
-
* const client = new PermissionsClient('https://api.example.com');
|
|
181
|
-
* ```
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* Local development:
|
|
185
|
-
* ```typescript
|
|
186
|
-
* const client = new PermissionsClient('http://localhost:8080');
|
|
187
|
-
* ```
|
|
188
|
-
*
|
|
189
|
-
* @since 1.0.0
|
|
190
|
-
* @group Client
|
|
191
|
-
*/
|
|
192
|
-
constructor(apiBaseUrl: string);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
export { PermissionsClient };
|
|
1
|
+
export { A as AssignRoleRequest, C as CreateRoleRequest, N as NamespaceDefinition, P as PermissionsClient, a as Role, R as RolesHandler, U as UpdateRoleRequest } from '../payments/index.cjs';
|
|
2
|
+
import '@ory/client';
|
|
@@ -1,195 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Client for managing permissions and relationships using Ory Keto
|
|
5
|
-
*
|
|
6
|
-
* This client provides access to Ory Keto's permission system, allowing you to
|
|
7
|
-
* create, manage, and check relationships between subjects and objects. It handles
|
|
8
|
-
* both read operations (permission checks) and write operations (relationship management).
|
|
9
|
-
*
|
|
10
|
-
* The client automatically configures separate endpoints for read and write operations
|
|
11
|
-
* to optimize performance and security by following Ory Keto's recommended architecture.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* Basic permission checking:
|
|
15
|
-
* ```typescript
|
|
16
|
-
* import { PermissionsClient } from '@omnibase/core-js/permissions';
|
|
17
|
-
*
|
|
18
|
-
* const permissionsClient = new PermissionsClient('https://api.example.com');
|
|
19
|
-
*
|
|
20
|
-
* // Check if a user can view a tenant
|
|
21
|
-
* const canView = await permissionsClient.permissions.checkPermission(
|
|
22
|
-
* undefined,
|
|
23
|
-
* {
|
|
24
|
-
* namespace: 'Tenant',
|
|
25
|
-
* object: 'tenant_123',
|
|
26
|
-
* relation: 'view',
|
|
27
|
-
* subjectId: 'user_456'
|
|
28
|
-
* }
|
|
29
|
-
* );
|
|
30
|
-
*
|
|
31
|
-
* if (canView.data.allowed) {
|
|
32
|
-
* console.log('User can view the tenant');
|
|
33
|
-
* }
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* Creating tenant relationships:
|
|
38
|
-
* ```typescript
|
|
39
|
-
* // Create a relationship making a user an owner of a tenant
|
|
40
|
-
* await permissionsClient.relationships.createRelationship(
|
|
41
|
-
* undefined,
|
|
42
|
-
* {
|
|
43
|
-
* namespace: 'Tenant',
|
|
44
|
-
* object: 'tenant_123',
|
|
45
|
-
* relation: 'owners',
|
|
46
|
-
* subjectId: 'user_456'
|
|
47
|
-
* }
|
|
48
|
-
* );
|
|
49
|
-
*
|
|
50
|
-
* // Now the user has owner permissions on the tenant
|
|
51
|
-
* console.log('User is now an owner of the tenant');
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* Complex tenant permission management:
|
|
56
|
-
* ```typescript
|
|
57
|
-
* const tenantId = 'tenant_123';
|
|
58
|
-
* const userId = 'user_456';
|
|
59
|
-
*
|
|
60
|
-
* // Grant admin permissions to a user
|
|
61
|
-
* await permissionsClient.relationships.createRelationship(
|
|
62
|
-
* undefined,
|
|
63
|
-
* {
|
|
64
|
-
* namespace: 'Tenant',
|
|
65
|
-
* object: tenantId,
|
|
66
|
-
* relation: 'admins',
|
|
67
|
-
* subjectId: userId
|
|
68
|
-
* }
|
|
69
|
-
* );
|
|
70
|
-
*
|
|
71
|
-
* // Check if user can manage members (admins and owners can)
|
|
72
|
-
* const canManageMembers = await permissionsClient.permissions.checkPermission(
|
|
73
|
-
* undefined,
|
|
74
|
-
* {
|
|
75
|
-
* namespace: 'Tenant',
|
|
76
|
-
* object: tenantId,
|
|
77
|
-
* relation: 'manage_members',
|
|
78
|
-
* subjectId: userId
|
|
79
|
-
* }
|
|
80
|
-
* );
|
|
81
|
-
*
|
|
82
|
-
* if (canManageMembers.data.allowed) {
|
|
83
|
-
* // User can invite/remove members
|
|
84
|
-
* console.log('User can manage tenant members');
|
|
85
|
-
* }
|
|
86
|
-
*
|
|
87
|
-
* // Later, remove admin permissions
|
|
88
|
-
* await permissionsClient.relationships.deleteRelationships(
|
|
89
|
-
* undefined,
|
|
90
|
-
* {
|
|
91
|
-
* namespace: 'Tenant',
|
|
92
|
-
* object: tenantId,
|
|
93
|
-
* relation: 'admins',
|
|
94
|
-
* subjectId: userId
|
|
95
|
-
* }
|
|
96
|
-
* );
|
|
97
|
-
* ```
|
|
98
|
-
*
|
|
99
|
-
* @since 1.0.0
|
|
100
|
-
* @public
|
|
101
|
-
* @group Client
|
|
102
|
-
*/
|
|
103
|
-
declare class PermissionsClient {
|
|
104
|
-
/**
|
|
105
|
-
* Ory Keto RelationshipApi for managing subject-object relationships
|
|
106
|
-
*
|
|
107
|
-
* Provides methods for creating, updating, and deleting relationships between
|
|
108
|
-
* subjects (users, groups) and objects (tenants, resources). This API handles
|
|
109
|
-
* write operations and is used to establish permission structures.
|
|
110
|
-
*
|
|
111
|
-
* Key methods:
|
|
112
|
-
* - `createRelationship()` - Creates a new relationship tuple
|
|
113
|
-
* - `deleteRelationships()` - Removes existing relationship tuples
|
|
114
|
-
* - `getRelationships()` - Queries existing relationships
|
|
115
|
-
* - `patchRelationships()` - Updates multiple relationships atomically
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```typescript
|
|
119
|
-
* // Create a relationship
|
|
120
|
-
* await client.relationships.createRelationship(
|
|
121
|
-
* undefined,
|
|
122
|
-
* {
|
|
123
|
-
* namespace: 'Tenant',
|
|
124
|
-
* object: 'tenant_123',
|
|
125
|
-
* relation: 'members',
|
|
126
|
-
* subjectId: 'user_456'
|
|
127
|
-
* }
|
|
128
|
-
* );
|
|
129
|
-
* ```
|
|
130
|
-
*
|
|
131
|
-
* @since 1.0.0
|
|
132
|
-
* @group Relationships
|
|
133
|
-
*/
|
|
134
|
-
relationships: RelationshipApi;
|
|
135
|
-
/**
|
|
136
|
-
* Ory Keto PermissionApi for checking permissions
|
|
137
|
-
*
|
|
138
|
-
* Provides methods for querying whether a subject has a specific permission
|
|
139
|
-
* on an object. This API handles read operations and is optimized for fast
|
|
140
|
-
* permission checks in your application logic.
|
|
141
|
-
*
|
|
142
|
-
* Key methods:
|
|
143
|
-
* - `checkPermission()` - Checks if a subject has permission on an object
|
|
144
|
-
* - `checkPermissionOrError()` - Same as above but throws error if denied
|
|
145
|
-
* - `expandPermissions()` - Expands relationships to show all granted permissions
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```typescript
|
|
149
|
-
* // Check permission
|
|
150
|
-
* const result = await client.permissions.checkPermission(
|
|
151
|
-
* undefined,
|
|
152
|
-
* {
|
|
153
|
-
* namespace: 'Tenant',
|
|
154
|
-
* object: 'tenant_123',
|
|
155
|
-
* relation: 'view',
|
|
156
|
-
* subjectId: 'user_456'
|
|
157
|
-
* }
|
|
158
|
-
* );
|
|
159
|
-
*
|
|
160
|
-
* console.log('Has permission:', result.data.allowed);
|
|
161
|
-
* ```
|
|
162
|
-
*
|
|
163
|
-
* @since 1.0.0
|
|
164
|
-
* @group Permissions
|
|
165
|
-
*/
|
|
166
|
-
permissions: PermissionApi;
|
|
167
|
-
/**
|
|
168
|
-
* Creates a new PermissionsClient instance
|
|
169
|
-
*
|
|
170
|
-
* Initializes the client with separate endpoints for read and write operations.
|
|
171
|
-
* The client automatically appends the appropriate Keto API paths to the base URL
|
|
172
|
-
* for optimal performance and security separation.
|
|
173
|
-
*
|
|
174
|
-
* @param apiBaseUrl - The base URL for your Omnibase API instance
|
|
175
|
-
*
|
|
176
|
-
* @throws {Error} When the base URL is invalid or cannot be reached
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* ```typescript
|
|
180
|
-
* const client = new PermissionsClient('https://api.example.com');
|
|
181
|
-
* ```
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* Local development:
|
|
185
|
-
* ```typescript
|
|
186
|
-
* const client = new PermissionsClient('http://localhost:8080');
|
|
187
|
-
* ```
|
|
188
|
-
*
|
|
189
|
-
* @since 1.0.0
|
|
190
|
-
* @group Client
|
|
191
|
-
*/
|
|
192
|
-
constructor(apiBaseUrl: string);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
export { PermissionsClient };
|
|
1
|
+
export { A as AssignRoleRequest, C as CreateRoleRequest, N as NamespaceDefinition, P as PermissionsClient, a as Role, R as RolesHandler, U as UpdateRoleRequest } from '../payments/index.js';
|
|
2
|
+
import '@ory/client';
|