@forge-connect/react 1.0.6 → 1.0.9
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/index.cjs +34 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -467,6 +467,11 @@ declare function createApiClient(apiUrl: string): {
|
|
|
467
467
|
adminGetPermissions(token: string): Promise<{
|
|
468
468
|
domains: PermissionDomains;
|
|
469
469
|
}>;
|
|
470
|
+
/** Get the current user's own roles (no admin privileges needed). */
|
|
471
|
+
getMyRoles(token: string, tenantId?: string): Promise<{
|
|
472
|
+
data: UserRoleAssignment[];
|
|
473
|
+
permissions: string[];
|
|
474
|
+
}>;
|
|
470
475
|
adminGetUserRoles(token: string, userId: string, tenantId?: string): Promise<{
|
|
471
476
|
data: UserRoleAssignment[];
|
|
472
477
|
}>;
|
|
@@ -699,6 +704,7 @@ declare function useRoles(): {
|
|
|
699
704
|
selectedRole: Role | null;
|
|
700
705
|
roleUsers: RoleUser[] | null;
|
|
701
706
|
userRoleAssignments: UserRoleAssignment[] | null;
|
|
707
|
+
myPermissions: string[];
|
|
702
708
|
permissionDomains: PermissionDomains | null;
|
|
703
709
|
loading: boolean;
|
|
704
710
|
listRoles: (tenantId?: string) => Promise<Role[]>;
|
|
@@ -717,6 +723,10 @@ declare function useRoles(): {
|
|
|
717
723
|
}) => Promise<Role>;
|
|
718
724
|
deleteRole: (id: string) => Promise<void>;
|
|
719
725
|
getPermissions: () => Promise<PermissionDomains>;
|
|
726
|
+
getMyRoles: (tenantId?: string) => Promise<{
|
|
727
|
+
data: UserRoleAssignment[];
|
|
728
|
+
permissions: string[];
|
|
729
|
+
}>;
|
|
720
730
|
getUserRoles: (userId: string, tenantId?: string) => Promise<UserRoleAssignment[]>;
|
|
721
731
|
assignRole: (userId: string, roleId: string, tenantId?: string) => Promise<void>;
|
|
722
732
|
revokeRole: (userId: string, roleId: string, tenantId?: string) => Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -467,6 +467,11 @@ declare function createApiClient(apiUrl: string): {
|
|
|
467
467
|
adminGetPermissions(token: string): Promise<{
|
|
468
468
|
domains: PermissionDomains;
|
|
469
469
|
}>;
|
|
470
|
+
/** Get the current user's own roles (no admin privileges needed). */
|
|
471
|
+
getMyRoles(token: string, tenantId?: string): Promise<{
|
|
472
|
+
data: UserRoleAssignment[];
|
|
473
|
+
permissions: string[];
|
|
474
|
+
}>;
|
|
470
475
|
adminGetUserRoles(token: string, userId: string, tenantId?: string): Promise<{
|
|
471
476
|
data: UserRoleAssignment[];
|
|
472
477
|
}>;
|
|
@@ -699,6 +704,7 @@ declare function useRoles(): {
|
|
|
699
704
|
selectedRole: Role | null;
|
|
700
705
|
roleUsers: RoleUser[] | null;
|
|
701
706
|
userRoleAssignments: UserRoleAssignment[] | null;
|
|
707
|
+
myPermissions: string[];
|
|
702
708
|
permissionDomains: PermissionDomains | null;
|
|
703
709
|
loading: boolean;
|
|
704
710
|
listRoles: (tenantId?: string) => Promise<Role[]>;
|
|
@@ -717,6 +723,10 @@ declare function useRoles(): {
|
|
|
717
723
|
}) => Promise<Role>;
|
|
718
724
|
deleteRole: (id: string) => Promise<void>;
|
|
719
725
|
getPermissions: () => Promise<PermissionDomains>;
|
|
726
|
+
getMyRoles: (tenantId?: string) => Promise<{
|
|
727
|
+
data: UserRoleAssignment[];
|
|
728
|
+
permissions: string[];
|
|
729
|
+
}>;
|
|
720
730
|
getUserRoles: (userId: string, tenantId?: string) => Promise<UserRoleAssignment[]>;
|
|
721
731
|
assignRole: (userId: string, roleId: string, tenantId?: string) => Promise<void>;
|
|
722
732
|
revokeRole: (userId: string, roleId: string, tenantId?: string) => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -19,8 +19,16 @@ var ForgeConnectApiError = class extends Error {
|
|
|
19
19
|
function createApiClient(apiUrl) {
|
|
20
20
|
const base = apiUrl.replace(/\/+$/, "");
|
|
21
21
|
const inflightRequests = /* @__PURE__ */ new Map();
|
|
22
|
+
let inflightRefresh = null;
|
|
22
23
|
async function request(path, options = {}) {
|
|
23
24
|
const { method = "GET", body, token } = options;
|
|
25
|
+
if (method === "POST" && path === "/auth/refresh") {
|
|
26
|
+
if (inflightRefresh) return inflightRefresh;
|
|
27
|
+
inflightRefresh = doRequest(path, options).finally(() => {
|
|
28
|
+
inflightRefresh = null;
|
|
29
|
+
});
|
|
30
|
+
return inflightRefresh;
|
|
31
|
+
}
|
|
24
32
|
if (method === "GET" && token) {
|
|
25
33
|
const dedupKey = `${path}:${token}`;
|
|
26
34
|
const inflight = inflightRequests.get(dedupKey);
|
|
@@ -361,6 +369,13 @@ function createApiClient(apiUrl) {
|
|
|
361
369
|
adminGetPermissions(token) {
|
|
362
370
|
return request("/admin/roles/permissions", { token });
|
|
363
371
|
},
|
|
372
|
+
/** Get the current user's own roles (no admin privileges needed). */
|
|
373
|
+
getMyRoles(token, tenantId) {
|
|
374
|
+
const query = new URLSearchParams();
|
|
375
|
+
if (tenantId) query.set("tenantId", tenantId);
|
|
376
|
+
const qs = query.toString();
|
|
377
|
+
return request(`/users/me/roles${qs ? `?${qs}` : ""}`, { token });
|
|
378
|
+
},
|
|
364
379
|
adminGetUserRoles(token, userId, tenantId) {
|
|
365
380
|
const query = new URLSearchParams();
|
|
366
381
|
if (tenantId) query.set("tenantId", tenantId);
|
|
@@ -4256,6 +4271,7 @@ function useRoles() {
|
|
|
4256
4271
|
const [userRoleAssignments, setUserRoleAssignments] = useState18(null);
|
|
4257
4272
|
const [roleUsers, setRoleUsers] = useState18(null);
|
|
4258
4273
|
const [permissionDomains, setPermissionDomains] = useState18(null);
|
|
4274
|
+
const [myPermissions, setMyPermissions] = useState18([]);
|
|
4259
4275
|
const [loading, setLoading] = useState18(false);
|
|
4260
4276
|
const listRoles = useCallback11(
|
|
4261
4277
|
async (tenantId) => {
|
|
@@ -4338,6 +4354,22 @@ function useRoles() {
|
|
|
4338
4354
|
},
|
|
4339
4355
|
[api, getAccessToken]
|
|
4340
4356
|
);
|
|
4357
|
+
const getMyRoles = useCallback11(
|
|
4358
|
+
async (tenantId) => {
|
|
4359
|
+
const token = getAccessToken();
|
|
4360
|
+
if (!token) throw new Error("Please sign in to continue.");
|
|
4361
|
+
setLoading(true);
|
|
4362
|
+
try {
|
|
4363
|
+
const data = await api.getMyRoles(token, tenantId);
|
|
4364
|
+
setUserRoleAssignments(data.data);
|
|
4365
|
+
setMyPermissions(data.permissions ?? []);
|
|
4366
|
+
return data;
|
|
4367
|
+
} finally {
|
|
4368
|
+
setLoading(false);
|
|
4369
|
+
}
|
|
4370
|
+
},
|
|
4371
|
+
[api, getAccessToken]
|
|
4372
|
+
);
|
|
4341
4373
|
const getUserRoles = useCallback11(
|
|
4342
4374
|
async (userId, tenantId) => {
|
|
4343
4375
|
const token = getAccessToken();
|
|
@@ -4374,6 +4406,7 @@ function useRoles() {
|
|
|
4374
4406
|
selectedRole,
|
|
4375
4407
|
roleUsers,
|
|
4376
4408
|
userRoleAssignments,
|
|
4409
|
+
myPermissions,
|
|
4377
4410
|
permissionDomains,
|
|
4378
4411
|
loading,
|
|
4379
4412
|
listRoles,
|
|
@@ -4383,6 +4416,7 @@ function useRoles() {
|
|
|
4383
4416
|
updateRole,
|
|
4384
4417
|
deleteRole,
|
|
4385
4418
|
getPermissions,
|
|
4419
|
+
getMyRoles,
|
|
4386
4420
|
getUserRoles,
|
|
4387
4421
|
assignRole,
|
|
4388
4422
|
revokeRole
|