@equinor/fusion-framework-react-app 14.2.1 → 14.3.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.
@@ -4,4 +4,5 @@
4
4
  * @packageDocumentation
5
5
  */
6
6
  export { useAccessRole, } from './useAccessRole';
7
+ export { useHasAccessRole, } from './useHasAccessRole';
7
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/roles/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,OAAO,EACL,aAAa,GAGd,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/roles/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,OAAO,EACL,aAAa,GAGd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,gBAAgB,GAGjB,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { useEffect, useMemo, useSyncExternalStore } from 'react';
2
+ import { createAccessRoleCheck } from '@equinor/fusion-framework-module-roles';
3
+ import { useAppModule } from '../useAppModule';
4
+ /**
5
+ * Checks whether any or all requested Roles V2 access roles are currently active.
6
+ *
7
+ * The hook calls only {@link IRolesProvider.hasAccessRole}; it does not load claimable-role
8
+ * assignments or expose activation actions. Use `useAccessRole` when the UI also needs to discover
9
+ * and activate a claimable role assignment.
10
+ *
11
+ * Role names follow the provider's exact, case-sensitive matching semantics. Set `required` to
12
+ * `true` to require every role, or leave it `false` to accept any role. Empty lists preserve the
13
+ * provider identities: all-role checks resolve to `true`, while any-role checks resolve to `false`.
14
+ *
15
+ * @param accessRoleNames - Exact Roles V2 access-role names to check.
16
+ * @param options - Selects all-role (`required: true`) or any-role (`required: false`) matching.
17
+ * @returns Active access state with initial loading, refresh, and error handling.
18
+ * @throws The function returned as `refresh` rethrows Roles V2 failures after updating `error`.
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * const access = useHasAccessRole(['Reports.Read', 'Reports.Export'], { required: false });
23
+ *
24
+ * if (access.isLoading) return <Spinner />;
25
+ * if (access.error) return <ErrorMessage error={access.error} />;
26
+ * return access.hasAccessRole ? <Reports /> : <NoAccess />;
27
+ * ```
28
+ */
29
+ export const useHasAccessRole = (accessRoleNames, options = {}) => {
30
+ const roles = useAppModule('roles');
31
+ const required = options.required === true;
32
+ // Array identity is unstable for inline hook arguments; content controls the request lifecycle.
33
+ const inputKey = JSON.stringify([accessRoleNames, required]);
34
+ // inputKey captures the role-name contents so inline arrays do not recreate the flow.
35
+ // biome-ignore lint/correctness/useExhaustiveDependencies: inputKey is the semantic identity of accessRoleNames and required.
36
+ const check = useMemo(() => createAccessRoleCheck(roles, accessRoleNames, { required }), [inputKey, roles]);
37
+ const state = useSyncExternalStore(check.subscribe, check.getSnapshot, check.getSnapshot);
38
+ useEffect(() => {
39
+ // The flow owns request state; effects only start the render-committed resource.
40
+ void check.load().catch(() => undefined);
41
+ // Subscription cleanup detaches React; keeping the immutable resource alive makes retained
42
+ // refresh callbacks harmless across StrictMode replays and input changes.
43
+ }, [check]);
44
+ return {
45
+ hasAccessRole: state.hasAccessRole,
46
+ isLoading: state.isLoading,
47
+ error: state.error,
48
+ refresh: check.refresh,
49
+ };
50
+ };
51
+ //# sourceMappingURL=useHasAccessRole.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHasAccessRole.js","sourceRoot":"","sources":["../../../src/roles/useHasAccessRole.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAGjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAE/E,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAmB/C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,eAAkC,EAClC,OAAO,GAA4B,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