@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.cjs
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] = _react.useState.call(void 0, null);
|
|
4257
4272
|
const [roleUsers, setRoleUsers] = _react.useState.call(void 0, null);
|
|
4258
4273
|
const [permissionDomains, setPermissionDomains] = _react.useState.call(void 0, null);
|
|
4274
|
+
const [myPermissions, setMyPermissions] = _react.useState.call(void 0, []);
|
|
4259
4275
|
const [loading, setLoading] = _react.useState.call(void 0, false);
|
|
4260
4276
|
const listRoles = _react.useCallback.call(void 0,
|
|
4261
4277
|
async (tenantId) => {
|
|
@@ -4338,6 +4354,22 @@ function useRoles() {
|
|
|
4338
4354
|
},
|
|
4339
4355
|
[api, getAccessToken]
|
|
4340
4356
|
);
|
|
4357
|
+
const getMyRoles = _react.useCallback.call(void 0,
|
|
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(_nullishCoalesce(data.permissions, () => ( [])));
|
|
4366
|
+
return data;
|
|
4367
|
+
} finally {
|
|
4368
|
+
setLoading(false);
|
|
4369
|
+
}
|
|
4370
|
+
},
|
|
4371
|
+
[api, getAccessToken]
|
|
4372
|
+
);
|
|
4341
4373
|
const getUserRoles = _react.useCallback.call(void 0,
|
|
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
|