@turinhub/tale-js-sdk 1.3.0 → 2.1.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/README.md +90 -13
- package/dist/acl/index.d.ts +62 -49
- package/dist/acl/index.js +262 -67
- package/dist/acl/types.d.ts +63 -98
- package/dist/app/index.d.ts +10 -0
- package/dist/app/index.js +198 -0
- package/dist/app/types.d.ts +101 -0
- package/dist/app/types.js +1 -0
- package/dist/app-token/index.d.ts +7 -0
- package/dist/app-token/index.js +58 -0
- package/dist/app-token/types.d.ts +25 -0
- package/dist/app-token/types.js +1 -0
- package/dist/attachment/index.d.ts +17 -0
- package/dist/attachment/index.js +247 -0
- package/dist/attachment/types.d.ts +82 -0
- package/dist/attachment/types.js +1 -0
- package/dist/attachment-type/index.d.ts +15 -0
- package/dist/attachment-type/index.js +203 -0
- package/dist/attachment-type/types.d.ts +60 -0
- package/dist/attachment-type/types.js +1 -0
- package/dist/auth/index.d.ts +21 -21
- package/dist/auth/index.js +66 -66
- package/dist/auth/types.d.ts +51 -51
- package/dist/cms/file.d.ts +88 -70
- package/dist/cms/file.js +228 -77
- package/dist/cms/folder.d.ts +9 -9
- package/dist/cms/folder.js +18 -18
- package/dist/cms/types.d.ts +58 -38
- package/dist/common/http.d.ts +17 -0
- package/dist/common/http.js +141 -0
- package/dist/common/types.d.ts +58 -63
- package/dist/index.d.ts +6 -1
- package/dist/index.js +4 -0
- package/dist/rbac/index.d.ts +37 -42
- package/dist/rbac/index.js +96 -98
- package/dist/rbac/types.d.ts +38 -40
- package/dist/status.d.ts +11 -11
- package/dist/status.js +30 -3
- package/dist/task/index.d.ts +15 -147
- package/dist/task/index.js +170 -161
- package/dist/task/types.d.ts +57 -81
- package/dist/task-type/index.d.ts +7 -7
- package/dist/task-type/index.js +12 -12
- package/dist/task-type/types.d.ts +18 -34
- package/dist/token.d.ts +3 -3
- package/dist/token.js +4 -4
- package/dist/user/index.d.ts +28 -29
- package/dist/user/index.js +69 -74
- package/dist/user/types.d.ts +32 -33
- package/dist/user-attribute/index.d.ts +4 -7
- package/dist/user-attribute/index.js +19 -22
- package/dist/user-attribute/types.d.ts +29 -29
- package/dist/user-group/index.d.ts +4 -223
- package/dist/user-group/index.js +61 -479
- package/dist/user-group/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/rbac/index.js
CHANGED
|
@@ -16,8 +16,8 @@ import { ApiError, ConfigurationError, NetworkError } from "../errors.js";
|
|
|
16
16
|
* import { getRole } from '@tale/client';
|
|
17
17
|
*
|
|
18
18
|
* try {
|
|
19
|
-
* const role = await getRole('
|
|
20
|
-
* console.log('Role name:', role.
|
|
19
|
+
* const role = await getRole('roleId_here');
|
|
20
|
+
* console.log('Role name:', role.roleName);
|
|
21
21
|
* } catch (error) {
|
|
22
22
|
* console.error('Failed to get role:', error.message);
|
|
23
23
|
* }
|
|
@@ -25,7 +25,7 @@ import { ApiError, ConfigurationError, NetworkError } from "../errors.js";
|
|
|
25
25
|
*/
|
|
26
26
|
export async function getRole(roleId, options) {
|
|
27
27
|
if (!roleId || roleId.trim() === "") {
|
|
28
|
-
throw new ApiError("
|
|
28
|
+
throw new ApiError("roleId is required", 400, "9400");
|
|
29
29
|
}
|
|
30
30
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
31
31
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
@@ -34,7 +34,7 @@ export async function getRole(roleId, options) {
|
|
|
34
34
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
35
35
|
}
|
|
36
36
|
const url = String(base).replace(/\/+$/, "") +
|
|
37
|
-
`/rbac/
|
|
37
|
+
`/rbac/v2/roles/${encodeURIComponent(roleId)}`;
|
|
38
38
|
let response;
|
|
39
39
|
try {
|
|
40
40
|
response = await globalThis.fetch(url, {
|
|
@@ -75,9 +75,9 @@ export async function getRole(roleId, options) {
|
|
|
75
75
|
* const result = await listRoles({
|
|
76
76
|
* page: 0,
|
|
77
77
|
* size: 20,
|
|
78
|
-
*
|
|
78
|
+
* roleType: 'admin'
|
|
79
79
|
* });
|
|
80
|
-
* console.log(`Found ${result.
|
|
80
|
+
* console.log(`Found ${result.total} roles`);
|
|
81
81
|
* } catch (error) {
|
|
82
82
|
* console.error('Failed to list roles:', error.message);
|
|
83
83
|
* }
|
|
@@ -90,12 +90,11 @@ export async function listRoles(options) {
|
|
|
90
90
|
if (!base) {
|
|
91
91
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
92
92
|
}
|
|
93
|
-
const url = new URL(String(base).replace(/\/+$/, "") + "/rbac/
|
|
93
|
+
const url = new URL(String(base).replace(/\/+$/, "") + "/rbac/v2/roles");
|
|
94
94
|
const queryParams = {
|
|
95
95
|
page: 0,
|
|
96
96
|
size: 20,
|
|
97
|
-
|
|
98
|
-
sort_direction: "desc",
|
|
97
|
+
sort: "createdAt,desc",
|
|
99
98
|
...options,
|
|
100
99
|
};
|
|
101
100
|
Object.entries(queryParams).forEach(([key, value]) => {
|
|
@@ -143,18 +142,18 @@ export async function listRoles(options) {
|
|
|
143
142
|
* try {
|
|
144
143
|
* const role = await createRole({
|
|
145
144
|
* roleName: 'Administrator',
|
|
146
|
-
*
|
|
147
|
-
*
|
|
145
|
+
* roleType: 'admin',
|
|
146
|
+
* privilegeIds: ['priv1', 'priv2']
|
|
148
147
|
* });
|
|
149
|
-
* console.log('Role created:', role.
|
|
148
|
+
* console.log('Role created:', role.roleId);
|
|
150
149
|
* } catch (error) {
|
|
151
150
|
* console.error('Failed to create role:', error.message);
|
|
152
151
|
* }
|
|
153
152
|
* ```
|
|
154
153
|
*/
|
|
155
154
|
export async function createRole(request, options) {
|
|
156
|
-
if (!request.
|
|
157
|
-
throw new ApiError("
|
|
155
|
+
if (!request.roleName || request.roleName.trim() === "") {
|
|
156
|
+
throw new ApiError("roleName is required", 400, "9400");
|
|
158
157
|
}
|
|
159
158
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
160
159
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
@@ -162,7 +161,7 @@ export async function createRole(request, options) {
|
|
|
162
161
|
if (!base) {
|
|
163
162
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
164
163
|
}
|
|
165
|
-
const url = String(base).replace(/\/+$/, "") + "/rbac/
|
|
164
|
+
const url = String(base).replace(/\/+$/, "") + "/rbac/v2/roles";
|
|
166
165
|
let response;
|
|
167
166
|
try {
|
|
168
167
|
response = await globalThis.fetch(url, {
|
|
@@ -203,11 +202,11 @@ export async function createRole(request, options) {
|
|
|
203
202
|
* import { updateRole } from '@tale/client';
|
|
204
203
|
*
|
|
205
204
|
* try {
|
|
206
|
-
* const role = await updateRole('
|
|
205
|
+
* const role = await updateRole('roleId_here', {
|
|
207
206
|
* roleName: 'Updated Role Name',
|
|
208
207
|
* remark: 'Updated description'
|
|
209
208
|
* });
|
|
210
|
-
* console.log('Role updated:', role.
|
|
209
|
+
* console.log('Role updated:', role.roleName);
|
|
211
210
|
* } catch (error) {
|
|
212
211
|
* console.error('Failed to update role:', error.message);
|
|
213
212
|
* }
|
|
@@ -215,7 +214,7 @@ export async function createRole(request, options) {
|
|
|
215
214
|
*/
|
|
216
215
|
export async function updateRole(roleId, request, options) {
|
|
217
216
|
if (!roleId || roleId.trim() === "") {
|
|
218
|
-
throw new ApiError("
|
|
217
|
+
throw new ApiError("roleId is required", 400, "9400");
|
|
219
218
|
}
|
|
220
219
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
221
220
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
@@ -224,7 +223,7 @@ export async function updateRole(roleId, request, options) {
|
|
|
224
223
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
225
224
|
}
|
|
226
225
|
const url = String(base).replace(/\/+$/, "") +
|
|
227
|
-
`/rbac/
|
|
226
|
+
`/rbac/v2/roles/${encodeURIComponent(roleId)}`;
|
|
228
227
|
let response;
|
|
229
228
|
try {
|
|
230
229
|
response = await globalThis.fetch(url, {
|
|
@@ -264,7 +263,7 @@ export async function updateRole(roleId, request, options) {
|
|
|
264
263
|
* import { deleteRole } from '@tale/client';
|
|
265
264
|
*
|
|
266
265
|
* try {
|
|
267
|
-
* await deleteRole('
|
|
266
|
+
* await deleteRole('roleId_here');
|
|
268
267
|
* console.log('Role deleted successfully');
|
|
269
268
|
* } catch (error) {
|
|
270
269
|
* console.error('Failed to delete role:', error.message);
|
|
@@ -273,7 +272,7 @@ export async function updateRole(roleId, request, options) {
|
|
|
273
272
|
*/
|
|
274
273
|
export async function deleteRole(roleId, options) {
|
|
275
274
|
if (!roleId || roleId.trim() === "") {
|
|
276
|
-
throw new ApiError("
|
|
275
|
+
throw new ApiError("roleId is required", 400, "9400");
|
|
277
276
|
}
|
|
278
277
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
279
278
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
@@ -282,7 +281,7 @@ export async function deleteRole(roleId, options) {
|
|
|
282
281
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
283
282
|
}
|
|
284
283
|
const url = String(base).replace(/\/+$/, "") +
|
|
285
|
-
`/rbac/
|
|
284
|
+
`/rbac/v2/roles/${encodeURIComponent(roleId)}`;
|
|
286
285
|
let response;
|
|
287
286
|
try {
|
|
288
287
|
response = await globalThis.fetch(url, {
|
|
@@ -318,8 +317,8 @@ export async function deleteRole(roleId, options) {
|
|
|
318
317
|
* import { getPrivilege } from '@tale/client';
|
|
319
318
|
*
|
|
320
319
|
* try {
|
|
321
|
-
* const privilege = await getPrivilege('
|
|
322
|
-
* console.log('Privilege name:', privilege.
|
|
320
|
+
* const privilege = await getPrivilege('privilegeId_here');
|
|
321
|
+
* console.log('Privilege name:', privilege.privilegeName);
|
|
323
322
|
* } catch (error) {
|
|
324
323
|
* console.error('Failed to get privilege:', error.message);
|
|
325
324
|
* }
|
|
@@ -327,7 +326,7 @@ export async function deleteRole(roleId, options) {
|
|
|
327
326
|
*/
|
|
328
327
|
export async function getPrivilege(privilegeId, options) {
|
|
329
328
|
if (!privilegeId || privilegeId.trim() === "") {
|
|
330
|
-
throw new ApiError("
|
|
329
|
+
throw new ApiError("privilegeId is required", 400, "9400");
|
|
331
330
|
}
|
|
332
331
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
333
332
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
@@ -336,7 +335,7 @@ export async function getPrivilege(privilegeId, options) {
|
|
|
336
335
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
337
336
|
}
|
|
338
337
|
const url = String(base).replace(/\/+$/, "") +
|
|
339
|
-
`/rbac/
|
|
338
|
+
`/rbac/v2/privileges/${encodeURIComponent(privilegeId)}`;
|
|
340
339
|
let response;
|
|
341
340
|
try {
|
|
342
341
|
response = await globalThis.fetch(url, {
|
|
@@ -377,9 +376,9 @@ export async function getPrivilege(privilegeId, options) {
|
|
|
377
376
|
* const result = await listPrivileges({
|
|
378
377
|
* page: 0,
|
|
379
378
|
* size: 20,
|
|
380
|
-
*
|
|
379
|
+
* privilegeType: 'read'
|
|
381
380
|
* });
|
|
382
|
-
* console.log(`Found ${result.
|
|
381
|
+
* console.log(`Found ${result.total} privileges`);
|
|
383
382
|
* } catch (error) {
|
|
384
383
|
* console.error('Failed to list privileges:', error.message);
|
|
385
384
|
* }
|
|
@@ -392,12 +391,11 @@ export async function listPrivileges(options) {
|
|
|
392
391
|
if (!base) {
|
|
393
392
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
394
393
|
}
|
|
395
|
-
const url = new URL(String(base).replace(/\/+$/, "") + "/rbac/
|
|
394
|
+
const url = new URL(String(base).replace(/\/+$/, "") + "/rbac/v2/privileges");
|
|
396
395
|
const queryParams = {
|
|
397
396
|
page: 0,
|
|
398
397
|
size: 20,
|
|
399
|
-
|
|
400
|
-
sort_direction: "desc",
|
|
398
|
+
sort: "createdAt,desc",
|
|
401
399
|
...options,
|
|
402
400
|
};
|
|
403
401
|
Object.entries(queryParams).forEach(([key, value]) => {
|
|
@@ -445,18 +443,18 @@ export async function listPrivileges(options) {
|
|
|
445
443
|
* try {
|
|
446
444
|
* const privilege = await createPrivilege({
|
|
447
445
|
* privilegeName: 'read_posts',
|
|
448
|
-
*
|
|
446
|
+
* privilegeType: 'read',
|
|
449
447
|
* resourceIds: ['posts']
|
|
450
448
|
* });
|
|
451
|
-
* console.log('Privilege created:', privilege.
|
|
449
|
+
* console.log('Privilege created:', privilege.privilegeId);
|
|
452
450
|
* } catch (error) {
|
|
453
451
|
* console.error('Failed to create privilege:', error.message);
|
|
454
452
|
* }
|
|
455
453
|
* ```
|
|
456
454
|
*/
|
|
457
455
|
export async function createPrivilege(request, options) {
|
|
458
|
-
if (!request.
|
|
459
|
-
throw new ApiError("
|
|
456
|
+
if (!request.privilegeName || request.privilegeName.trim() === "") {
|
|
457
|
+
throw new ApiError("privilegeName is required", 400, "9400");
|
|
460
458
|
}
|
|
461
459
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
462
460
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
@@ -464,7 +462,7 @@ export async function createPrivilege(request, options) {
|
|
|
464
462
|
if (!base) {
|
|
465
463
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
466
464
|
}
|
|
467
|
-
const url = String(base).replace(/\/+$/, "") + "/rbac/
|
|
465
|
+
const url = String(base).replace(/\/+$/, "") + "/rbac/v2/privileges";
|
|
468
466
|
let response;
|
|
469
467
|
try {
|
|
470
468
|
response = await globalThis.fetch(url, {
|
|
@@ -505,11 +503,11 @@ export async function createPrivilege(request, options) {
|
|
|
505
503
|
* import { updatePrivilege } from '@tale/client';
|
|
506
504
|
*
|
|
507
505
|
* try {
|
|
508
|
-
* const privilege = await updatePrivilege('
|
|
506
|
+
* const privilege = await updatePrivilege('privilegeId_here', {
|
|
509
507
|
* privilegeName: 'updated_name',
|
|
510
508
|
* remark: 'Updated description'
|
|
511
509
|
* });
|
|
512
|
-
* console.log('Privilege updated:', privilege.
|
|
510
|
+
* console.log('Privilege updated:', privilege.privilegeName);
|
|
513
511
|
* } catch (error) {
|
|
514
512
|
* console.error('Failed to update privilege:', error.message);
|
|
515
513
|
* }
|
|
@@ -517,7 +515,7 @@ export async function createPrivilege(request, options) {
|
|
|
517
515
|
*/
|
|
518
516
|
export async function updatePrivilege(privilegeId, request, options) {
|
|
519
517
|
if (!privilegeId || privilegeId.trim() === "") {
|
|
520
|
-
throw new ApiError("
|
|
518
|
+
throw new ApiError("privilegeId is required", 400, "9400");
|
|
521
519
|
}
|
|
522
520
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
523
521
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
@@ -526,7 +524,7 @@ export async function updatePrivilege(privilegeId, request, options) {
|
|
|
526
524
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
527
525
|
}
|
|
528
526
|
const url = String(base).replace(/\/+$/, "") +
|
|
529
|
-
`/rbac/
|
|
527
|
+
`/rbac/v2/privileges/${encodeURIComponent(privilegeId)}`;
|
|
530
528
|
let response;
|
|
531
529
|
try {
|
|
532
530
|
response = await globalThis.fetch(url, {
|
|
@@ -566,7 +564,7 @@ export async function updatePrivilege(privilegeId, request, options) {
|
|
|
566
564
|
* import { deletePrivilege } from '@tale/client';
|
|
567
565
|
*
|
|
568
566
|
* try {
|
|
569
|
-
* await deletePrivilege('
|
|
567
|
+
* await deletePrivilege('privilegeId_here');
|
|
570
568
|
* console.log('Privilege deleted successfully');
|
|
571
569
|
* } catch (error) {
|
|
572
570
|
* console.error('Failed to delete privilege:', error.message);
|
|
@@ -575,7 +573,7 @@ export async function updatePrivilege(privilegeId, request, options) {
|
|
|
575
573
|
*/
|
|
576
574
|
export async function deletePrivilege(privilegeId, options) {
|
|
577
575
|
if (!privilegeId || privilegeId.trim() === "") {
|
|
578
|
-
throw new ApiError("
|
|
576
|
+
throw new ApiError("privilegeId is required", 400, "9400");
|
|
579
577
|
}
|
|
580
578
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
581
579
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
@@ -584,7 +582,7 @@ export async function deletePrivilege(privilegeId, options) {
|
|
|
584
582
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
585
583
|
}
|
|
586
584
|
const url = String(base).replace(/\/+$/, "") +
|
|
587
|
-
`/rbac/
|
|
585
|
+
`/rbac/v2/privileges/${encodeURIComponent(privilegeId)}`;
|
|
588
586
|
let response;
|
|
589
587
|
try {
|
|
590
588
|
response = await globalThis.fetch(url, {
|
|
@@ -620,9 +618,9 @@ export async function deletePrivilege(privilegeId, options) {
|
|
|
620
618
|
* import { getUserRoles } from '@tale/client';
|
|
621
619
|
*
|
|
622
620
|
* try {
|
|
623
|
-
* const roles = await getUserRoles('
|
|
621
|
+
* const roles = await getUserRoles('userId_here');
|
|
624
622
|
* console.log(`User has ${roles.length} roles`);
|
|
625
|
-
* roles.forEach(role => console.log('-', role.
|
|
623
|
+
* roles.forEach(role => console.log('-', role.roleName));
|
|
626
624
|
* } catch (error) {
|
|
627
625
|
* console.error('Failed to get user roles:', error.message);
|
|
628
626
|
* }
|
|
@@ -630,7 +628,7 @@ export async function deletePrivilege(privilegeId, options) {
|
|
|
630
628
|
*/
|
|
631
629
|
export async function getUserRoles(userId, options) {
|
|
632
630
|
if (!userId || userId.trim() === "") {
|
|
633
|
-
throw new ApiError("
|
|
631
|
+
throw new ApiError("userId is required", 400, "9400");
|
|
634
632
|
}
|
|
635
633
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
636
634
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
@@ -639,7 +637,7 @@ export async function getUserRoles(userId, options) {
|
|
|
639
637
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
640
638
|
}
|
|
641
639
|
const url = String(base).replace(/\/+$/, "") +
|
|
642
|
-
`/rbac/
|
|
640
|
+
`/rbac/v2/user/${encodeURIComponent(userId)}/roles`;
|
|
643
641
|
let response;
|
|
644
642
|
try {
|
|
645
643
|
response = await globalThis.fetch(url, {
|
|
@@ -679,8 +677,8 @@ export async function getUserRoles(userId, options) {
|
|
|
679
677
|
* import { assignRolesToUser } from '@tale/client';
|
|
680
678
|
*
|
|
681
679
|
* try {
|
|
682
|
-
* const roles = await assignRolesToUser('
|
|
683
|
-
*
|
|
680
|
+
* const roles = await assignRolesToUser('userId_here', {
|
|
681
|
+
* roleIds: ['role1', 'role2']
|
|
684
682
|
* });
|
|
685
683
|
* console.log('Roles assigned successfully');
|
|
686
684
|
* } catch (error) {
|
|
@@ -690,12 +688,12 @@ export async function getUserRoles(userId, options) {
|
|
|
690
688
|
*/
|
|
691
689
|
export async function assignRolesToUser(userId, request, options) {
|
|
692
690
|
if (!userId || userId.trim() === "") {
|
|
693
|
-
throw new ApiError("
|
|
691
|
+
throw new ApiError("userId is required", 400, "9400");
|
|
694
692
|
}
|
|
695
|
-
if (!request.
|
|
696
|
-
!Array.isArray(request.
|
|
697
|
-
request.
|
|
698
|
-
throw new ApiError("
|
|
693
|
+
if (!request.roleIds ||
|
|
694
|
+
!Array.isArray(request.roleIds) ||
|
|
695
|
+
request.roleIds.length === 0) {
|
|
696
|
+
throw new ApiError("roleIds is required and must be a non-empty array", 400, "9400");
|
|
699
697
|
}
|
|
700
698
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
701
699
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
@@ -704,7 +702,7 @@ export async function assignRolesToUser(userId, request, options) {
|
|
|
704
702
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
705
703
|
}
|
|
706
704
|
const url = String(base).replace(/\/+$/, "") +
|
|
707
|
-
`/rbac/
|
|
705
|
+
`/rbac/v2/user/${encodeURIComponent(userId)}/roles`;
|
|
708
706
|
let response;
|
|
709
707
|
try {
|
|
710
708
|
response = await globalThis.fetch(url, {
|
|
@@ -747,8 +745,8 @@ export async function assignRolesToUser(userId, request, options) {
|
|
|
747
745
|
* import { unassignRolesFromUser } from '@tale/client';
|
|
748
746
|
*
|
|
749
747
|
* try {
|
|
750
|
-
* await unassignRolesFromUser('
|
|
751
|
-
*
|
|
748
|
+
* await unassignRolesFromUser('userId_here', {
|
|
749
|
+
* roleIds: ['role1', 'role2']
|
|
752
750
|
* });
|
|
753
751
|
* console.log('Roles unassigned successfully');
|
|
754
752
|
* } catch (error) {
|
|
@@ -758,12 +756,12 @@ export async function assignRolesToUser(userId, request, options) {
|
|
|
758
756
|
*/
|
|
759
757
|
export async function unassignRolesFromUser(userId, request, options) {
|
|
760
758
|
if (!userId || userId.trim() === "") {
|
|
761
|
-
throw new ApiError("
|
|
759
|
+
throw new ApiError("userId is required", 400, "9400");
|
|
762
760
|
}
|
|
763
|
-
if (!request.
|
|
764
|
-
!Array.isArray(request.
|
|
765
|
-
request.
|
|
766
|
-
throw new ApiError("
|
|
761
|
+
if (!request.roleIds ||
|
|
762
|
+
!Array.isArray(request.roleIds) ||
|
|
763
|
+
request.roleIds.length === 0) {
|
|
764
|
+
throw new ApiError("roleIds is required and must be a non-empty array", 400, "9400");
|
|
767
765
|
}
|
|
768
766
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
769
767
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
@@ -772,7 +770,7 @@ export async function unassignRolesFromUser(userId, request, options) {
|
|
|
772
770
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
773
771
|
}
|
|
774
772
|
const url = String(base).replace(/\/+$/, "") +
|
|
775
|
-
`/rbac/
|
|
773
|
+
`/rbac/v2/user/${encodeURIComponent(userId)}/roles`;
|
|
776
774
|
let response;
|
|
777
775
|
try {
|
|
778
776
|
response = await globalThis.fetch(url, {
|
|
@@ -811,7 +809,7 @@ export async function unassignRolesFromUser(userId, request, options) {
|
|
|
811
809
|
* import { getUserPrivileges } from '@tale/client';
|
|
812
810
|
*
|
|
813
811
|
* try {
|
|
814
|
-
* const privileges = await getUserPrivileges('
|
|
812
|
+
* const privileges = await getUserPrivileges('userId_here');
|
|
815
813
|
* console.log(`User has ${privileges.length} privileges`);
|
|
816
814
|
* privileges.forEach(priv => console.log('-', priv.privilegeName));
|
|
817
815
|
* } catch (error) {
|
|
@@ -821,7 +819,7 @@ export async function unassignRolesFromUser(userId, request, options) {
|
|
|
821
819
|
*/
|
|
822
820
|
export async function getUserPrivileges(userId, options) {
|
|
823
821
|
if (!userId || userId.trim() === "") {
|
|
824
|
-
throw new ApiError("
|
|
822
|
+
throw new ApiError("userId is required", 400, "9400");
|
|
825
823
|
}
|
|
826
824
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
827
825
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
@@ -830,7 +828,7 @@ export async function getUserPrivileges(userId, options) {
|
|
|
830
828
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
831
829
|
}
|
|
832
830
|
const url = String(base).replace(/\/+$/, "") +
|
|
833
|
-
`/rbac/
|
|
831
|
+
`/rbac/v2/user/${encodeURIComponent(userId)}/privileges`;
|
|
834
832
|
let response;
|
|
835
833
|
try {
|
|
836
834
|
response = await globalThis.fetch(url, {
|
|
@@ -870,8 +868,8 @@ export async function getUserPrivileges(userId, options) {
|
|
|
870
868
|
* import { assignPrivilegesToUser } from '@tale/client';
|
|
871
869
|
*
|
|
872
870
|
* try {
|
|
873
|
-
* const privileges = await assignPrivilegesToUser('
|
|
874
|
-
*
|
|
871
|
+
* const privileges = await assignPrivilegesToUser('userId_here', {
|
|
872
|
+
* privilegeIds: ['priv1', 'priv2']
|
|
875
873
|
* });
|
|
876
874
|
* console.log('Privileges assigned successfully');
|
|
877
875
|
* } catch (error) {
|
|
@@ -881,12 +879,12 @@ export async function getUserPrivileges(userId, options) {
|
|
|
881
879
|
*/
|
|
882
880
|
export async function assignPrivilegesToUser(userId, request, options) {
|
|
883
881
|
if (!userId || userId.trim() === "") {
|
|
884
|
-
throw new ApiError("
|
|
882
|
+
throw new ApiError("userId is required", 400, "9400");
|
|
885
883
|
}
|
|
886
|
-
if (!request.
|
|
887
|
-
!Array.isArray(request.
|
|
888
|
-
request.
|
|
889
|
-
throw new ApiError("
|
|
884
|
+
if (!request.privilegeIds ||
|
|
885
|
+
!Array.isArray(request.privilegeIds) ||
|
|
886
|
+
request.privilegeIds.length === 0) {
|
|
887
|
+
throw new ApiError("privilegeIds is required and must be a non-empty array", 400, "9400");
|
|
890
888
|
}
|
|
891
889
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
892
890
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
@@ -895,7 +893,7 @@ export async function assignPrivilegesToUser(userId, request, options) {
|
|
|
895
893
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
896
894
|
}
|
|
897
895
|
const url = String(base).replace(/\/+$/, "") +
|
|
898
|
-
`/rbac/
|
|
896
|
+
`/rbac/v2/user/${encodeURIComponent(userId)}/privileges`;
|
|
899
897
|
let response;
|
|
900
898
|
try {
|
|
901
899
|
response = await globalThis.fetch(url, {
|
|
@@ -938,8 +936,8 @@ export async function assignPrivilegesToUser(userId, request, options) {
|
|
|
938
936
|
* import { unassignPrivilegesFromUser } from '@tale/client';
|
|
939
937
|
*
|
|
940
938
|
* try {
|
|
941
|
-
* await unassignPrivilegesFromUser('
|
|
942
|
-
*
|
|
939
|
+
* await unassignPrivilegesFromUser('userId_here', {
|
|
940
|
+
* privilegeIds: ['priv1', 'priv2']
|
|
943
941
|
* });
|
|
944
942
|
* console.log('Privileges unassigned successfully');
|
|
945
943
|
* } catch (error) {
|
|
@@ -949,12 +947,12 @@ export async function assignPrivilegesToUser(userId, request, options) {
|
|
|
949
947
|
*/
|
|
950
948
|
export async function unassignPrivilegesFromUser(userId, request, options) {
|
|
951
949
|
if (!userId || userId.trim() === "") {
|
|
952
|
-
throw new ApiError("
|
|
950
|
+
throw new ApiError("userId is required", 400, "9400");
|
|
953
951
|
}
|
|
954
|
-
if (!request.
|
|
955
|
-
!Array.isArray(request.
|
|
956
|
-
request.
|
|
957
|
-
throw new ApiError("
|
|
952
|
+
if (!request.privilegeIds ||
|
|
953
|
+
!Array.isArray(request.privilegeIds) ||
|
|
954
|
+
request.privilegeIds.length === 0) {
|
|
955
|
+
throw new ApiError("privilegeIds is required and must be a non-empty array", 400, "9400");
|
|
958
956
|
}
|
|
959
957
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
960
958
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
@@ -963,7 +961,7 @@ export async function unassignPrivilegesFromUser(userId, request, options) {
|
|
|
963
961
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
964
962
|
}
|
|
965
963
|
const url = String(base).replace(/\/+$/, "") +
|
|
966
|
-
`/rbac/
|
|
964
|
+
`/rbac/v2/user/${encodeURIComponent(userId)}/privileges`;
|
|
967
965
|
let response;
|
|
968
966
|
try {
|
|
969
967
|
response = await globalThis.fetch(url, {
|
|
@@ -1003,8 +1001,8 @@ export async function unassignPrivilegesFromUser(userId, request, options) {
|
|
|
1003
1001
|
* import { assignPrivilegesToRole } from '@tale/client';
|
|
1004
1002
|
*
|
|
1005
1003
|
* try {
|
|
1006
|
-
* const privileges = await assignPrivilegesToRole('
|
|
1007
|
-
*
|
|
1004
|
+
* const privileges = await assignPrivilegesToRole('roleId_here', {
|
|
1005
|
+
* privilegeIds: ['priv1', 'priv2']
|
|
1008
1006
|
* });
|
|
1009
1007
|
* console.log('Privileges assigned successfully');
|
|
1010
1008
|
* } catch (error) {
|
|
@@ -1014,12 +1012,12 @@ export async function unassignPrivilegesFromUser(userId, request, options) {
|
|
|
1014
1012
|
*/
|
|
1015
1013
|
export async function assignPrivilegesToRole(roleId, request, options) {
|
|
1016
1014
|
if (!roleId || roleId.trim() === "") {
|
|
1017
|
-
throw new ApiError("
|
|
1015
|
+
throw new ApiError("roleId is required", 400, "9400");
|
|
1018
1016
|
}
|
|
1019
|
-
if (!request.
|
|
1020
|
-
!Array.isArray(request.
|
|
1021
|
-
request.
|
|
1022
|
-
throw new ApiError("
|
|
1017
|
+
if (!request.privilegeIds ||
|
|
1018
|
+
!Array.isArray(request.privilegeIds) ||
|
|
1019
|
+
request.privilegeIds.length === 0) {
|
|
1020
|
+
throw new ApiError("privilegeIds is required and must be a non-empty array", 400, "9400");
|
|
1023
1021
|
}
|
|
1024
1022
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
1025
1023
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
@@ -1028,7 +1026,7 @@ export async function assignPrivilegesToRole(roleId, request, options) {
|
|
|
1028
1026
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
1029
1027
|
}
|
|
1030
1028
|
const url = String(base).replace(/\/+$/, "") +
|
|
1031
|
-
`/rbac/
|
|
1029
|
+
`/rbac/v2/roles/${encodeURIComponent(roleId)}/privileges`;
|
|
1032
1030
|
let response;
|
|
1033
1031
|
try {
|
|
1034
1032
|
response = await globalThis.fetch(url, {
|
|
@@ -1071,8 +1069,8 @@ export async function assignPrivilegesToRole(roleId, request, options) {
|
|
|
1071
1069
|
* import { unassignPrivilegesFromRole } from '@tale/client';
|
|
1072
1070
|
*
|
|
1073
1071
|
* try {
|
|
1074
|
-
* await unassignPrivilegesFromRole('
|
|
1075
|
-
*
|
|
1072
|
+
* await unassignPrivilegesFromRole('roleId_here', {
|
|
1073
|
+
* privilegeIds: ['priv1', 'priv2']
|
|
1076
1074
|
* });
|
|
1077
1075
|
* console.log('Privileges unassigned successfully');
|
|
1078
1076
|
* } catch (error) {
|
|
@@ -1082,12 +1080,12 @@ export async function assignPrivilegesToRole(roleId, request, options) {
|
|
|
1082
1080
|
*/
|
|
1083
1081
|
export async function unassignPrivilegesFromRole(roleId, request, options) {
|
|
1084
1082
|
if (!roleId || roleId.trim() === "") {
|
|
1085
|
-
throw new ApiError("
|
|
1083
|
+
throw new ApiError("roleId is required", 400, "9400");
|
|
1086
1084
|
}
|
|
1087
|
-
if (!request.
|
|
1088
|
-
!Array.isArray(request.
|
|
1089
|
-
request.
|
|
1090
|
-
throw new ApiError("
|
|
1085
|
+
if (!request.privilegeIds ||
|
|
1086
|
+
!Array.isArray(request.privilegeIds) ||
|
|
1087
|
+
request.privilegeIds.length === 0) {
|
|
1088
|
+
throw new ApiError("privilegeIds is required and must be a non-empty array", 400, "9400");
|
|
1091
1089
|
}
|
|
1092
1090
|
const token = options?.appToken ?? (await getAppToken(options));
|
|
1093
1091
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
@@ -1096,7 +1094,7 @@ export async function unassignPrivilegesFromRole(roleId, request, options) {
|
|
|
1096
1094
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
1097
1095
|
}
|
|
1098
1096
|
const url = String(base).replace(/\/+$/, "") +
|
|
1099
|
-
`/rbac/
|
|
1097
|
+
`/rbac/v2/roles/${encodeURIComponent(roleId)}/privileges`;
|
|
1100
1098
|
let response;
|
|
1101
1099
|
try {
|
|
1102
1100
|
response = await globalThis.fetch(url, {
|