@trackunit/react-core-hooks 1.21.22-alpha-3e7014314a8.0 → 1.21.27

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/index.cjs.js CHANGED
@@ -81,9 +81,11 @@ const useCurrentUser = () => {
81
81
  * having to observe the synchronous `loading` flag themselves.
82
82
  */
83
83
  const useValidateAccessAsync = () => {
84
- const { hasAccessTo, hasFeatureFlag, hasPermission, loading } = useValidateAccess();
84
+ const { hasAccessTo, hasAccountAction, hasFeatureFlag, hasPermission, loading } = useValidateAccess();
85
85
  const hasAccessToRef = react.useRef(hasAccessTo);
86
86
  hasAccessToRef.current = hasAccessTo;
87
+ const hasAccountActionRef = react.useRef(hasAccountAction);
88
+ hasAccountActionRef.current = hasAccountAction;
87
89
  const hasFeatureFlagRef = react.useRef(hasFeatureFlag);
88
90
  hasFeatureFlagRef.current = hasFeatureFlag;
89
91
  const hasPermissionRef = react.useRef(hasPermission);
@@ -108,6 +110,10 @@ const useValidateAccessAsync = () => {
108
110
  await waitForLoading();
109
111
  return hasAccessToRef.current(requiredAccessTo);
110
112
  },
113
+ hasAccountAction: async (action) => {
114
+ await waitForLoading();
115
+ return hasAccountActionRef.current(action);
116
+ },
111
117
  hasFeatureFlag: async (flag) => {
112
118
  await waitForLoading();
113
119
  return hasFeatureFlagRef.current(flag);
@@ -117,7 +123,7 @@ const useValidateAccessAsync = () => {
117
123
  return hasPermissionRef.current(permission);
118
124
  },
119
125
  };
120
- }, [loadingRef, hasAccessToRef, hasFeatureFlagRef, hasPermissionRef]);
126
+ }, [loadingRef, hasAccessToRef, hasAccountActionRef, hasFeatureFlagRef, hasPermissionRef]);
121
127
  };
122
128
  /**
123
129
  * Synchronously evaluates the current user's access via subscription features,
@@ -125,7 +131,7 @@ const useValidateAccessAsync = () => {
125
131
  * flag that stays true until user, subscription, and flag data are all present.
126
132
  */
127
133
  const useValidateAccess = () => {
128
- const { isAuthenticated, permissions: userPermissions } = useCurrentUser();
134
+ const { accountActions, isAuthenticated, permissions: userPermissions } = useCurrentUser();
129
135
  const { features, loading: featuresLoading } = useUserSubscription();
130
136
  const { flags: allFlags } = useFeatureFlags();
131
137
  const loading = react.useMemo(() => allFlags === null || featuresLoading || !userPermissions, [allFlags, featuresLoading, userPermissions]);
@@ -144,14 +150,23 @@ const useValidateAccess = () => {
144
150
  }
145
151
  return false;
146
152
  }, [isAuthenticated, userPermissions]);
153
+ // Actions land in the user store in the same write as `permissions`, so the `loading`
154
+ // flag above already covers them and needs no term of its own.
155
+ const hasAccountAction = react.useCallback((action) => {
156
+ if (isAuthenticated) {
157
+ return accountActions?.[action] ?? false;
158
+ }
159
+ return false;
160
+ }, [accountActions, isAuthenticated]);
147
161
  return react.useMemo(() => {
148
162
  return {
149
163
  hasAccessTo,
164
+ hasAccountAction,
150
165
  hasFeatureFlag,
151
166
  hasPermission,
152
167
  loading,
153
168
  };
154
- }, [hasAccessTo, hasFeatureFlag, hasPermission, loading]);
169
+ }, [hasAccessTo, hasAccountAction, hasFeatureFlag, hasPermission, loading]);
155
170
  };
156
171
  const hasAccessToFeature = (myFeatures, feature) => {
157
172
  return myFeatures?.some(x => x.id === feature) ?? null;
package/index.esm.js CHANGED
@@ -79,9 +79,11 @@ const useCurrentUser = () => {
79
79
  * having to observe the synchronous `loading` flag themselves.
80
80
  */
81
81
  const useValidateAccessAsync = () => {
82
- const { hasAccessTo, hasFeatureFlag, hasPermission, loading } = useValidateAccess();
82
+ const { hasAccessTo, hasAccountAction, hasFeatureFlag, hasPermission, loading } = useValidateAccess();
83
83
  const hasAccessToRef = useRef(hasAccessTo);
84
84
  hasAccessToRef.current = hasAccessTo;
85
+ const hasAccountActionRef = useRef(hasAccountAction);
86
+ hasAccountActionRef.current = hasAccountAction;
85
87
  const hasFeatureFlagRef = useRef(hasFeatureFlag);
86
88
  hasFeatureFlagRef.current = hasFeatureFlag;
87
89
  const hasPermissionRef = useRef(hasPermission);
@@ -106,6 +108,10 @@ const useValidateAccessAsync = () => {
106
108
  await waitForLoading();
107
109
  return hasAccessToRef.current(requiredAccessTo);
108
110
  },
111
+ hasAccountAction: async (action) => {
112
+ await waitForLoading();
113
+ return hasAccountActionRef.current(action);
114
+ },
109
115
  hasFeatureFlag: async (flag) => {
110
116
  await waitForLoading();
111
117
  return hasFeatureFlagRef.current(flag);
@@ -115,7 +121,7 @@ const useValidateAccessAsync = () => {
115
121
  return hasPermissionRef.current(permission);
116
122
  },
117
123
  };
118
- }, [loadingRef, hasAccessToRef, hasFeatureFlagRef, hasPermissionRef]);
124
+ }, [loadingRef, hasAccessToRef, hasAccountActionRef, hasFeatureFlagRef, hasPermissionRef]);
119
125
  };
120
126
  /**
121
127
  * Synchronously evaluates the current user's access via subscription features,
@@ -123,7 +129,7 @@ const useValidateAccessAsync = () => {
123
129
  * flag that stays true until user, subscription, and flag data are all present.
124
130
  */
125
131
  const useValidateAccess = () => {
126
- const { isAuthenticated, permissions: userPermissions } = useCurrentUser();
132
+ const { accountActions, isAuthenticated, permissions: userPermissions } = useCurrentUser();
127
133
  const { features, loading: featuresLoading } = useUserSubscription();
128
134
  const { flags: allFlags } = useFeatureFlags();
129
135
  const loading = useMemo(() => allFlags === null || featuresLoading || !userPermissions, [allFlags, featuresLoading, userPermissions]);
@@ -142,14 +148,23 @@ const useValidateAccess = () => {
142
148
  }
143
149
  return false;
144
150
  }, [isAuthenticated, userPermissions]);
151
+ // Actions land in the user store in the same write as `permissions`, so the `loading`
152
+ // flag above already covers them and needs no term of its own.
153
+ const hasAccountAction = useCallback((action) => {
154
+ if (isAuthenticated) {
155
+ return accountActions?.[action] ?? false;
156
+ }
157
+ return false;
158
+ }, [accountActions, isAuthenticated]);
145
159
  return useMemo(() => {
146
160
  return {
147
161
  hasAccessTo,
162
+ hasAccountAction,
148
163
  hasFeatureFlag,
149
164
  hasPermission,
150
165
  loading,
151
166
  };
152
- }, [hasAccessTo, hasFeatureFlag, hasPermission, loading]);
167
+ }, [hasAccessTo, hasAccountAction, hasFeatureFlag, hasPermission, loading]);
153
168
  };
154
169
  const hasAccessToFeature = (myFeatures, feature) => {
155
170
  return myFeatures?.some(x => x.id === feature) ?? null;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.js","sourceRoot":"","sources":["../../../../../libs/react/core-hooks/migrations/entry.ts"],"names":[],"mappings":"","sourcesContent":["export {};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-hooks",
3
- "version": "1.21.22-alpha-3e7014314a8.0",
3
+ "version": "1.21.27",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -8,9 +8,9 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "es-toolkit": "^1.39.10",
11
- "@trackunit/iris-app-runtime-core": "1.18.28-alpha-3e7014314a8.0",
12
- "@trackunit/iris-app-runtime-core-api": "1.17.28-alpha-3e7014314a8.0",
13
- "@trackunit/react-core-contexts-api": "1.18.28-alpha-3e7014314a8.0",
11
+ "@trackunit/iris-app-runtime-core": "1.18.28",
12
+ "@trackunit/iris-app-runtime-core-api": "1.17.28",
13
+ "@trackunit/react-core-contexts-api": "1.18.28",
14
14
  "zod": "^3.25.76"
15
15
  },
16
16
  "peerDependencies": {
@@ -1,4 +1,4 @@
1
- import { LegacyFeature } from "@trackunit/iris-app-runtime-core-api";
1
+ import { AccountActionName, LegacyFeature } from "@trackunit/iris-app-runtime-core-api";
2
2
  export type HasAccess = boolean | null;
3
3
  export type ValidateAccess = LegacyFeature;
4
4
  /**
@@ -9,6 +9,7 @@ export type ValidateAccess = LegacyFeature;
9
9
  */
10
10
  export declare const useValidateAccessAsync: () => {
11
11
  hasAccessTo: (requiredAccessTo: ValidateAccess) => Promise<HasAccess>;
12
+ hasAccountAction: (action: AccountActionName) => Promise<HasAccess>;
12
13
  hasFeatureFlag: (flag: string) => Promise<HasAccess>;
13
14
  hasPermission: (permission: string) => Promise<HasAccess>;
14
15
  };
@@ -19,6 +20,7 @@ export declare const useValidateAccessAsync: () => {
19
20
  */
20
21
  export declare const useValidateAccess: () => {
21
22
  hasAccessTo: (requiredAccessTo: ValidateAccess) => HasAccess;
23
+ hasAccountAction: (action: AccountActionName) => HasAccess;
22
24
  hasFeatureFlag: (flag: string) => HasAccess;
23
25
  hasPermission: (permission: string) => HasAccess;
24
26
  loading: boolean;
@@ -1,4 +1,5 @@
1
- export type AccountAction = "manageUsers";
1
+ import { AccountActionName } from "@trackunit/iris-app-runtime-core-api";
2
+ export type AccountAction = AccountActionName;
2
3
  /**
3
4
  * Hook that checks whether the current user is allowed to perform a per-account,
4
5
  * FGA-backed `Account.actions` action for the active account.