@omnibase/core-js 0.7.2 → 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.
@@ -0,0 +1,378 @@
1
+ // src/permissions/handler.ts
2
+ import { RelationshipApi, PermissionApi } from "@ory/client";
3
+
4
+ // src/permissions/roles.ts
5
+ var RolesHandler = class {
6
+ constructor(client) {
7
+ this.client = client;
8
+ }
9
+ /**
10
+ * Get available namespace definitions for UI
11
+ *
12
+ * Returns all namespaces and their available relations/permissions.
13
+ * Useful for building role configuration UIs.
14
+ *
15
+ * @returns List of namespace definitions
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const definitions = await omnibase.permissions.roles.getDefinitions();
20
+ *
21
+ * // Output: [{ namespace: 'Tenant', relations: ['invite_user', 'delete_tenant', ...] }]
22
+ * definitions.forEach(def => {
23
+ * console.log(`${def.namespace} supports: ${def.relations.join(', ')}`);
24
+ * });
25
+ * ```
26
+ */
27
+ async getDefinitions() {
28
+ const response = await this.client.fetch(
29
+ "/api/v1/permissions/definitions",
30
+ {
31
+ method: "GET"
32
+ }
33
+ );
34
+ const data = await response.json();
35
+ if (!response.ok || data.error) {
36
+ throw new Error(data.error || "Failed to fetch definitions");
37
+ }
38
+ return data.data.definitions;
39
+ }
40
+ /**
41
+ * List all roles for the current tenant
42
+ *
43
+ * Returns both system roles (defined in roles.config.json) and
44
+ * custom roles created via the API. System roles have `tenant_id = null`.
45
+ *
46
+ * @returns List of roles
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const roles = await omnibase.permissions.roles.list();
51
+ *
52
+ * const systemRoles = roles.filter(r => r.tenant_id === null);
53
+ * const customRoles = roles.filter(r => r.tenant_id !== null);
54
+ *
55
+ * console.log(`System roles: ${systemRoles.map(r => r.role_name).join(', ')}`);
56
+ * console.log(`Custom roles: ${customRoles.map(r => r.role_name).join(', ')}`);
57
+ * ```
58
+ */
59
+ async list() {
60
+ const response = await this.client.fetch("/api/v1/permissions/roles", {
61
+ method: "GET"
62
+ });
63
+ const data = await response.json();
64
+ if (!response.ok || data.error) {
65
+ throw new Error(data.error || "Failed to list roles");
66
+ }
67
+ return data.data.roles;
68
+ }
69
+ /**
70
+ * Create a new custom role
71
+ *
72
+ * Creates a tenant-specific role with the specified permissions.
73
+ * Permissions use the format `namespace#relation` or `namespace:id#relation`.
74
+ *
75
+ * @param request - Role creation request
76
+ * @returns Created role
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const role = await omnibase.permissions.roles.create({
81
+ * role_name: 'billing_manager',
82
+ * permissions: [
83
+ * 'tenant#manage_billing',
84
+ * 'tenant#view_invoices',
85
+ * 'tenant#update_payment_methods'
86
+ * ]
87
+ * });
88
+ *
89
+ * console.log(`Created role: ${role.id}`);
90
+ * ```
91
+ *
92
+ * @example
93
+ * Resource-specific permissions:
94
+ * ```typescript
95
+ * const devRole = await omnibase.permissions.roles.create({
96
+ * role_name: 'project_developer',
97
+ * permissions: [
98
+ * 'project:proj_abc123#deploy',
99
+ * 'project:proj_abc123#view_logs',
100
+ * 'tenant#invite_user'
101
+ * ]
102
+ * });
103
+ * ```
104
+ */
105
+ async create(request) {
106
+ const response = await this.client.fetch("/api/v1/permissions/roles", {
107
+ method: "POST",
108
+ headers: { "Content-Type": "application/json" },
109
+ body: JSON.stringify(request)
110
+ });
111
+ const data = await response.json();
112
+ if (!response.ok || data.error) {
113
+ throw new Error(data.error || "Failed to create role");
114
+ }
115
+ return data.data;
116
+ }
117
+ /**
118
+ * Update an existing role's permissions
119
+ *
120
+ * Updates the permissions for a role and automatically updates all
121
+ * Keto relationships for users assigned to this role. Old permissions
122
+ * are removed and new ones are created.
123
+ *
124
+ * @param roleId - ID of role to update
125
+ * @param request - Update request with new permissions
126
+ * @returns Updated role
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * const updatedRole = await omnibase.permissions.roles.update('role_123', {
131
+ * permissions: [
132
+ * 'tenant#manage_billing',
133
+ * 'tenant#view_invoices',
134
+ * 'tenant#manage_users' // Added new permission
135
+ * ]
136
+ * });
137
+ *
138
+ * console.log(`Updated role with ${updatedRole.permissions.length} permissions`);
139
+ * ```
140
+ */
141
+ async update(roleId, request) {
142
+ const response = await this.client.fetch(
143
+ `/api/v1/permissions/roles/${roleId}`,
144
+ {
145
+ method: "PUT",
146
+ headers: { "Content-Type": "application/json" },
147
+ body: JSON.stringify(request)
148
+ }
149
+ );
150
+ const data = await response.json();
151
+ if (!response.ok || data.error) {
152
+ throw new Error(data.error || "Failed to update role");
153
+ }
154
+ return data.data;
155
+ }
156
+ /**
157
+ * Delete a role
158
+ *
159
+ * Deletes the role and automatically removes all Keto relationships
160
+ * for users assigned to this role. Cannot delete system roles.
161
+ *
162
+ * @param roleId - ID of role to delete
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * await omnibase.permissions.roles.delete('role_123');
167
+ * console.log('Role deleted successfully');
168
+ * ```
169
+ */
170
+ async delete(roleId) {
171
+ const response = await this.client.fetch(
172
+ `/api/v1/permissions/roles/${roleId}`,
173
+ {
174
+ method: "DELETE"
175
+ }
176
+ );
177
+ const data = await response.json();
178
+ if (!response.ok || data.error) {
179
+ throw new Error(data.error || "Failed to delete role");
180
+ }
181
+ }
182
+ /**
183
+ * Assign a role to a user
184
+ *
185
+ * Assigns a role to a user and automatically creates all necessary
186
+ * Keto relationship tuples based on the role's permissions. The user
187
+ * immediately gains all permissions defined in the role.
188
+ *
189
+ * Supports assignment by either role ID or role name for flexibility.
190
+ *
191
+ * @param userId - ID of user to assign role to
192
+ * @param request - Assignment request with either role_id or role_name
193
+ *
194
+ * @example
195
+ * Assign by role ID:
196
+ * ```typescript
197
+ * await omnibase.permissions.roles.assign('user_123', {
198
+ * role_id: 'role_456'
199
+ * });
200
+ * ```
201
+ *
202
+ * @example
203
+ * Assign by role name (system or custom role):
204
+ * ```typescript
205
+ * // Assign system role
206
+ * await omnibase.permissions.roles.assign('user_123', {
207
+ * role_name: 'owner'
208
+ * });
209
+ *
210
+ * // Assign custom role
211
+ * await omnibase.permissions.roles.assign('user_456', {
212
+ * role_name: 'billing_manager'
213
+ * });
214
+ * ```
215
+ *
216
+ * @example
217
+ * Verify permissions after assignment:
218
+ * ```typescript
219
+ * await omnibase.permissions.roles.assign('user_123', {
220
+ * role_name: 'admin'
221
+ * });
222
+ *
223
+ * // User now has all permissions from the admin role
224
+ * const canManage = await omnibase.permissions.permissions.checkPermission(
225
+ * undefined,
226
+ * {
227
+ * namespace: 'Tenant',
228
+ * object: 'tenant_789',
229
+ * relation: 'manage_billing',
230
+ * subjectId: 'user_123'
231
+ * }
232
+ * );
233
+ * // canManage.data.allowed === true
234
+ * ```
235
+ */
236
+ async assign(userId, request) {
237
+ const response = await this.client.fetch(
238
+ `/api/v1/permissions/users/${userId}/roles`,
239
+ {
240
+ method: "POST",
241
+ headers: { "Content-Type": "application/json" },
242
+ body: JSON.stringify(request)
243
+ }
244
+ );
245
+ const data = await response.json();
246
+ if (!response.ok || data.error) {
247
+ throw new Error(data.error || "Failed to assign role");
248
+ }
249
+ }
250
+ };
251
+
252
+ // src/permissions/handler.ts
253
+ var PermissionsClient = class {
254
+ /**
255
+ * Ory Keto RelationshipApi for managing subject-object relationships
256
+ *
257
+ * Provides methods for creating, updating, and deleting relationships between
258
+ * subjects (users, groups) and objects (tenants, resources). This API handles
259
+ * write operations and is used to establish permission structures.
260
+ *
261
+ * Key methods:
262
+ * - `createRelationship()` - Creates a new relationship tuple
263
+ * - `deleteRelationships()` - Removes existing relationship tuples
264
+ * - `getRelationships()` - Queries existing relationships
265
+ * - `patchRelationships()` - Updates multiple relationships atomically
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * // Create a relationship
270
+ * await client.relationships.createRelationship(
271
+ * undefined,
272
+ * {
273
+ * namespace: 'Tenant',
274
+ * object: 'tenant_123',
275
+ * relation: 'members',
276
+ * subjectId: 'user_456'
277
+ * }
278
+ * );
279
+ * ```
280
+ *
281
+ * @since 1.0.0
282
+ * @group Relationships
283
+ */
284
+ relationships;
285
+ /**
286
+ * Ory Keto PermissionApi for checking permissions
287
+ *
288
+ * Provides methods for querying whether a subject has a specific permission
289
+ * on an object. This API handles read operations and is optimized for fast
290
+ * permission checks in your application logic.
291
+ *
292
+ * Key methods:
293
+ * - `checkPermission()` - Checks if a subject has permission on an object
294
+ * - `checkPermissionOrError()` - Same as above but throws error if denied
295
+ * - `expandPermissions()` - Expands relationships to show all granted permissions
296
+ *
297
+ * @example
298
+ * ```typescript
299
+ * // Check permission
300
+ * const result = await client.permissions.checkPermission(
301
+ * undefined,
302
+ * {
303
+ * namespace: 'Tenant',
304
+ * object: 'tenant_123',
305
+ * relation: 'view',
306
+ * subjectId: 'user_456'
307
+ * }
308
+ * );
309
+ *
310
+ * console.log('Has permission:', result.data.allowed);
311
+ * ```
312
+ *
313
+ * @since 1.0.0
314
+ * @group Permissions
315
+ */
316
+ permissions;
317
+ /**
318
+ * Handler for managing roles and role-based permissions
319
+ *
320
+ * Provides methods for creating custom roles, assigning permissions,
321
+ * and managing role assignments. Works alongside the Keto-based
322
+ * permissions system to provide dynamic RBAC capabilities.
323
+ *
324
+ * @example
325
+ * ```typescript
326
+ * // Create a custom role
327
+ * const role = await omnibase.permissions.roles.create({
328
+ * role_name: 'billing_manager',
329
+ * permissions: ['tenant#manage_billing', 'tenant#view_invoices']
330
+ * });
331
+ *
332
+ * // Assign role to user
333
+ * await omnibase.permissions.roles.assign('user_123', {
334
+ * role_id: role.id
335
+ * });
336
+ * ```
337
+ *
338
+ * @since 0.7.0
339
+ * @group Roles
340
+ */
341
+ roles;
342
+ /**
343
+ * Creates a new PermissionsClient instance
344
+ *
345
+ * Initializes the client with separate endpoints for read and write operations.
346
+ * The client automatically appends the appropriate Keto API paths to the base URL
347
+ * for optimal performance and security separation.
348
+ *
349
+ * @param apiBaseUrl - The base URL for your Omnibase API instance
350
+ * @param client - The main OmnibaseClient instance (for roles handler)
351
+ *
352
+ * @throws {Error} When the base URL is invalid or cannot be reached
353
+ *
354
+ * @example
355
+ * ```typescript
356
+ * const client = new PermissionsClient('https://api.example.com', omnibaseClient);
357
+ * ```
358
+ *
359
+ * @since 1.0.0
360
+ * @group Client
361
+ */
362
+ constructor(apiBaseUrl, client) {
363
+ this.relationships = new RelationshipApi(
364
+ void 0,
365
+ `${apiBaseUrl}/api/v1/permissions/write`
366
+ );
367
+ this.permissions = new PermissionApi(
368
+ void 0,
369
+ `${apiBaseUrl}/api/v1/permissions/read`
370
+ );
371
+ this.roles = new RolesHandler(client);
372
+ }
373
+ };
374
+
375
+ export {
376
+ RolesHandler,
377
+ PermissionsClient
378
+ };
package/dist/index.cjs CHANGED
@@ -537,9 +537,12 @@ var RolesHandler = class {
537
537
  * ```
538
538
  */
539
539
  async getDefinitions() {
540
- const response = await this.client.fetch("/api/v1/roles/definitions", {
541
- method: "GET"
542
- });
540
+ const response = await this.client.fetch(
541
+ "/api/v1/permissions/definitions",
542
+ {
543
+ method: "GET"
544
+ }
545
+ );
543
546
  const data = await response.json();
544
547
  if (!response.ok || data.error) {
545
548
  throw new Error(data.error || "Failed to fetch definitions");
@@ -566,7 +569,7 @@ var RolesHandler = class {
566
569
  * ```
567
570
  */
568
571
  async list() {
569
- const response = await this.client.fetch("/api/v1/roles/roles", {
572
+ const response = await this.client.fetch("/api/v1/permissions/roles", {
570
573
  method: "GET"
571
574
  });
572
575
  const data = await response.json();
@@ -612,7 +615,7 @@ var RolesHandler = class {
612
615
  * ```
613
616
  */
614
617
  async create(request) {
615
- const response = await this.client.fetch("/api/v1/roles/roles", {
618
+ const response = await this.client.fetch("/api/v1/permissions/roles", {
616
619
  method: "POST",
617
620
  headers: { "Content-Type": "application/json" },
618
621
  body: JSON.stringify(request)
@@ -648,11 +651,14 @@ var RolesHandler = class {
648
651
  * ```
649
652
  */
650
653
  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
- });
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
+ );
656
662
  const data = await response.json();
657
663
  if (!response.ok || data.error) {
658
664
  throw new Error(data.error || "Failed to update role");
@@ -674,9 +680,12 @@ var RolesHandler = class {
674
680
  * ```
675
681
  */
676
682
  async delete(roleId) {
677
- const response = await this.client.fetch(`/api/v1/roles/roles/${roleId}`, {
678
- method: "DELETE"
679
- });
683
+ const response = await this.client.fetch(
684
+ `/api/v1/permissions/roles/${roleId}`,
685
+ {
686
+ method: "DELETE"
687
+ }
688
+ );
680
689
  const data = await response.json();
681
690
  if (!response.ok || data.error) {
682
691
  throw new Error(data.error || "Failed to delete role");
@@ -689,18 +698,42 @@ var RolesHandler = class {
689
698
  * Keto relationship tuples based on the role's permissions. The user
690
699
  * immediately gains all permissions defined in the role.
691
700
  *
701
+ * Supports assignment by either role ID or role name for flexibility.
702
+ *
692
703
  * @param userId - ID of user to assign role to
693
- * @param request - Assignment request with role ID
704
+ * @param request - Assignment request with either role_id or role_name
694
705
  *
695
706
  * @example
707
+ * Assign by role ID:
696
708
  * ```typescript
697
- * // Assign billing manager role to user
698
709
  * await omnibase.permissions.roles.assign('user_123', {
699
710
  * role_id: 'role_456'
700
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
+ * });
701
734
  *
702
- * // User now has all permissions from the role
703
- * const canManageBilling = await omnibase.permissions.permissions.checkPermission(
735
+ * // User now has all permissions from the admin role
736
+ * const canManage = await omnibase.permissions.permissions.checkPermission(
704
737
  * undefined,
705
738
  * {
706
739
  * namespace: 'Tenant',
@@ -709,12 +742,12 @@ var RolesHandler = class {
709
742
  * subjectId: 'user_123'
710
743
  * }
711
744
  * );
712
- * // canManageBilling.data.allowed === true
745
+ * // canManage.data.allowed === true
713
746
  * ```
714
747
  */
715
748
  async assign(userId, request) {
716
749
  const response = await this.client.fetch(
717
- `/api/v1/roles/users/${userId}/roles`,
750
+ `/api/v1/permissions/users/${userId}/roles`,
718
751
  {
719
752
  method: "POST",
720
753
  headers: { "Content-Type": "application/json" },
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  PermissionsClient,
3
3
  RolesHandler
4
- } from "./chunk-JNM7XP7L.js";
5
- import {
6
- PaymentHandler
7
- } from "./chunk-QPW6G4PA.js";
4
+ } from "./chunk-V4FWENQQ.js";
8
5
  import {
9
6
  StorageClient
10
7
  } from "./chunk-I6DMWC32.js";
8
+ import {
9
+ PaymentHandler
10
+ } from "./chunk-QPW6G4PA.js";
11
11
  import {
12
12
  TenantHandler
13
13
  } from "./chunk-6OGESVXW.js";
@@ -1211,21 +1211,41 @@ interface UpdateRoleRequest {
1211
1211
  /**
1212
1212
  * Request body for assigning a role to a user
1213
1213
  *
1214
+ * Supports assigning by either role ID or role name for flexibility.
1215
+ * When using role_name, the system will find the role by name within
1216
+ * the current tenant's scope (including system roles).
1217
+ *
1214
1218
  * @example
1219
+ * By role ID:
1215
1220
  * ```typescript
1216
1221
  * {
1217
1222
  * role_id: 'role_456'
1218
1223
  * }
1219
1224
  * ```
1220
1225
  *
1226
+ * @example
1227
+ * By role name:
1228
+ * ```typescript
1229
+ * {
1230
+ * role_name: 'owner'
1231
+ * }
1232
+ * ```
1233
+ *
1221
1234
  * @since 0.7.0
1222
1235
  * @public
1223
1236
  */
1224
1237
  interface AssignRoleRequest {
1225
1238
  /**
1226
1239
  * ID of the role to assign to the user
1240
+ * Use either role_id or role_name, not both
1241
+ */
1242
+ role_id?: string;
1243
+ /**
1244
+ * Name of the role to assign to the user
1245
+ * Use either role_id or role_name, not both
1246
+ * @example 'owner', 'admin', 'billing_manager'
1227
1247
  */
1228
- role_id: string;
1248
+ role_name?: string;
1229
1249
  }
1230
1250
 
1231
1251
  /**
@@ -1378,18 +1398,42 @@ declare class RolesHandler {
1378
1398
  * Keto relationship tuples based on the role's permissions. The user
1379
1399
  * immediately gains all permissions defined in the role.
1380
1400
  *
1401
+ * Supports assignment by either role ID or role name for flexibility.
1402
+ *
1381
1403
  * @param userId - ID of user to assign role to
1382
- * @param request - Assignment request with role ID
1404
+ * @param request - Assignment request with either role_id or role_name
1383
1405
  *
1384
1406
  * @example
1407
+ * Assign by role ID:
1385
1408
  * ```typescript
1386
- * // Assign billing manager role to user
1387
1409
  * await omnibase.permissions.roles.assign('user_123', {
1388
1410
  * role_id: 'role_456'
1389
1411
  * });
1412
+ * ```
1413
+ *
1414
+ * @example
1415
+ * Assign by role name (system or custom role):
1416
+ * ```typescript
1417
+ * // Assign system role
1418
+ * await omnibase.permissions.roles.assign('user_123', {
1419
+ * role_name: 'owner'
1420
+ * });
1421
+ *
1422
+ * // Assign custom role
1423
+ * await omnibase.permissions.roles.assign('user_456', {
1424
+ * role_name: 'billing_manager'
1425
+ * });
1426
+ * ```
1427
+ *
1428
+ * @example
1429
+ * Verify permissions after assignment:
1430
+ * ```typescript
1431
+ * await omnibase.permissions.roles.assign('user_123', {
1432
+ * role_name: 'admin'
1433
+ * });
1390
1434
  *
1391
- * // User now has all permissions from the role
1392
- * const canManageBilling = await omnibase.permissions.permissions.checkPermission(
1435
+ * // User now has all permissions from the admin role
1436
+ * const canManage = await omnibase.permissions.permissions.checkPermission(
1393
1437
  * undefined,
1394
1438
  * {
1395
1439
  * namespace: 'Tenant',
@@ -1398,7 +1442,7 @@ declare class RolesHandler {
1398
1442
  * subjectId: 'user_123'
1399
1443
  * }
1400
1444
  * );
1401
- * // canManageBilling.data.allowed === true
1445
+ * // canManage.data.allowed === true
1402
1446
  * ```
1403
1447
  */
1404
1448
  assign(userId: string, request: AssignRoleRequest): Promise<void>;
@@ -1211,21 +1211,41 @@ interface UpdateRoleRequest {
1211
1211
  /**
1212
1212
  * Request body for assigning a role to a user
1213
1213
  *
1214
+ * Supports assigning by either role ID or role name for flexibility.
1215
+ * When using role_name, the system will find the role by name within
1216
+ * the current tenant's scope (including system roles).
1217
+ *
1214
1218
  * @example
1219
+ * By role ID:
1215
1220
  * ```typescript
1216
1221
  * {
1217
1222
  * role_id: 'role_456'
1218
1223
  * }
1219
1224
  * ```
1220
1225
  *
1226
+ * @example
1227
+ * By role name:
1228
+ * ```typescript
1229
+ * {
1230
+ * role_name: 'owner'
1231
+ * }
1232
+ * ```
1233
+ *
1221
1234
  * @since 0.7.0
1222
1235
  * @public
1223
1236
  */
1224
1237
  interface AssignRoleRequest {
1225
1238
  /**
1226
1239
  * ID of the role to assign to the user
1240
+ * Use either role_id or role_name, not both
1241
+ */
1242
+ role_id?: string;
1243
+ /**
1244
+ * Name of the role to assign to the user
1245
+ * Use either role_id or role_name, not both
1246
+ * @example 'owner', 'admin', 'billing_manager'
1227
1247
  */
1228
- role_id: string;
1248
+ role_name?: string;
1229
1249
  }
1230
1250
 
1231
1251
  /**
@@ -1378,18 +1398,42 @@ declare class RolesHandler {
1378
1398
  * Keto relationship tuples based on the role's permissions. The user
1379
1399
  * immediately gains all permissions defined in the role.
1380
1400
  *
1401
+ * Supports assignment by either role ID or role name for flexibility.
1402
+ *
1381
1403
  * @param userId - ID of user to assign role to
1382
- * @param request - Assignment request with role ID
1404
+ * @param request - Assignment request with either role_id or role_name
1383
1405
  *
1384
1406
  * @example
1407
+ * Assign by role ID:
1385
1408
  * ```typescript
1386
- * // Assign billing manager role to user
1387
1409
  * await omnibase.permissions.roles.assign('user_123', {
1388
1410
  * role_id: 'role_456'
1389
1411
  * });
1412
+ * ```
1413
+ *
1414
+ * @example
1415
+ * Assign by role name (system or custom role):
1416
+ * ```typescript
1417
+ * // Assign system role
1418
+ * await omnibase.permissions.roles.assign('user_123', {
1419
+ * role_name: 'owner'
1420
+ * });
1421
+ *
1422
+ * // Assign custom role
1423
+ * await omnibase.permissions.roles.assign('user_456', {
1424
+ * role_name: 'billing_manager'
1425
+ * });
1426
+ * ```
1427
+ *
1428
+ * @example
1429
+ * Verify permissions after assignment:
1430
+ * ```typescript
1431
+ * await omnibase.permissions.roles.assign('user_123', {
1432
+ * role_name: 'admin'
1433
+ * });
1390
1434
  *
1391
- * // User now has all permissions from the role
1392
- * const canManageBilling = await omnibase.permissions.permissions.checkPermission(
1435
+ * // User now has all permissions from the admin role
1436
+ * const canManage = await omnibase.permissions.permissions.checkPermission(
1393
1437
  * undefined,
1394
1438
  * {
1395
1439
  * namespace: 'Tenant',
@@ -1398,7 +1442,7 @@ declare class RolesHandler {
1398
1442
  * subjectId: 'user_123'
1399
1443
  * }
1400
1444
  * );
1401
- * // canManageBilling.data.allowed === true
1445
+ * // canManage.data.allowed === true
1402
1446
  * ```
1403
1447
  */
1404
1448
  assign(userId: string, request: AssignRoleRequest): Promise<void>;
@@ -52,9 +52,12 @@ var RolesHandler = class {
52
52
  * ```
53
53
  */
54
54
  async getDefinitions() {
55
- const response = await this.client.fetch("/api/v1/roles/definitions", {
56
- method: "GET"
57
- });
55
+ const response = await this.client.fetch(
56
+ "/api/v1/permissions/definitions",
57
+ {
58
+ method: "GET"
59
+ }
60
+ );
58
61
  const data = await response.json();
59
62
  if (!response.ok || data.error) {
60
63
  throw new Error(data.error || "Failed to fetch definitions");
@@ -81,7 +84,7 @@ var RolesHandler = class {
81
84
  * ```
82
85
  */
83
86
  async list() {
84
- const response = await this.client.fetch("/api/v1/roles/roles", {
87
+ const response = await this.client.fetch("/api/v1/permissions/roles", {
85
88
  method: "GET"
86
89
  });
87
90
  const data = await response.json();
@@ -127,7 +130,7 @@ var RolesHandler = class {
127
130
  * ```
128
131
  */
129
132
  async create(request) {
130
- const response = await this.client.fetch("/api/v1/roles/roles", {
133
+ const response = await this.client.fetch("/api/v1/permissions/roles", {
131
134
  method: "POST",
132
135
  headers: { "Content-Type": "application/json" },
133
136
  body: JSON.stringify(request)
@@ -163,11 +166,14 @@ var RolesHandler = class {
163
166
  * ```
164
167
  */
165
168
  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
- });
169
+ const response = await this.client.fetch(
170
+ `/api/v1/permissions/roles/${roleId}`,
171
+ {
172
+ method: "PUT",
173
+ headers: { "Content-Type": "application/json" },
174
+ body: JSON.stringify(request)
175
+ }
176
+ );
171
177
  const data = await response.json();
172
178
  if (!response.ok || data.error) {
173
179
  throw new Error(data.error || "Failed to update role");
@@ -189,9 +195,12 @@ var RolesHandler = class {
189
195
  * ```
190
196
  */
191
197
  async delete(roleId) {
192
- const response = await this.client.fetch(`/api/v1/roles/roles/${roleId}`, {
193
- method: "DELETE"
194
- });
198
+ const response = await this.client.fetch(
199
+ `/api/v1/permissions/roles/${roleId}`,
200
+ {
201
+ method: "DELETE"
202
+ }
203
+ );
195
204
  const data = await response.json();
196
205
  if (!response.ok || data.error) {
197
206
  throw new Error(data.error || "Failed to delete role");
@@ -204,18 +213,42 @@ var RolesHandler = class {
204
213
  * Keto relationship tuples based on the role's permissions. The user
205
214
  * immediately gains all permissions defined in the role.
206
215
  *
216
+ * Supports assignment by either role ID or role name for flexibility.
217
+ *
207
218
  * @param userId - ID of user to assign role to
208
- * @param request - Assignment request with role ID
219
+ * @param request - Assignment request with either role_id or role_name
209
220
  *
210
221
  * @example
222
+ * Assign by role ID:
211
223
  * ```typescript
212
- * // Assign billing manager role to user
213
224
  * await omnibase.permissions.roles.assign('user_123', {
214
225
  * role_id: 'role_456'
215
226
  * });
227
+ * ```
228
+ *
229
+ * @example
230
+ * Assign by role name (system or custom role):
231
+ * ```typescript
232
+ * // Assign system role
233
+ * await omnibase.permissions.roles.assign('user_123', {
234
+ * role_name: 'owner'
235
+ * });
236
+ *
237
+ * // Assign custom role
238
+ * await omnibase.permissions.roles.assign('user_456', {
239
+ * role_name: 'billing_manager'
240
+ * });
241
+ * ```
242
+ *
243
+ * @example
244
+ * Verify permissions after assignment:
245
+ * ```typescript
246
+ * await omnibase.permissions.roles.assign('user_123', {
247
+ * role_name: 'admin'
248
+ * });
216
249
  *
217
- * // User now has all permissions from the role
218
- * const canManageBilling = await omnibase.permissions.permissions.checkPermission(
250
+ * // User now has all permissions from the admin role
251
+ * const canManage = await omnibase.permissions.permissions.checkPermission(
219
252
  * undefined,
220
253
  * {
221
254
  * namespace: 'Tenant',
@@ -224,12 +257,12 @@ var RolesHandler = class {
224
257
  * subjectId: 'user_123'
225
258
  * }
226
259
  * );
227
- * // canManageBilling.data.allowed === true
260
+ * // canManage.data.allowed === true
228
261
  * ```
229
262
  */
230
263
  async assign(userId, request) {
231
264
  const response = await this.client.fetch(
232
- `/api/v1/roles/users/${userId}/roles`,
265
+ `/api/v1/permissions/users/${userId}/roles`,
233
266
  {
234
267
  method: "POST",
235
268
  headers: { "Content-Type": "application/json" },
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PermissionsClient,
3
3
  RolesHandler
4
- } from "../chunk-JNM7XP7L.js";
4
+ } from "../chunk-V4FWENQQ.js";
5
5
  export {
6
6
  PermissionsClient,
7
7
  RolesHandler
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnibase/core-js",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "description": "OmniBase core Javascript SDK - framework agnostic",
5
5
  "files": [
6
6
  "dist/**/*"