@grantjs/client 1.0.0 → 1.0.1
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/grant-client-BoAtVV3u.js +249 -0
- package/dist/grant-client-BoAtVV3u.js.map +1 -0
- package/dist/grant-client-zE-9zy3m.cjs +254 -0
- package/dist/grant-client-zE-9zy3m.cjs.map +1 -0
- package/dist/grant-client.d.ts +2 -1
- package/dist/grant-client.d.ts.map +1 -1
- package/dist/index.cjs +2 -227
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +2 -228
- package/dist/react/context.d.ts.map +1 -1
- package/dist/react/hooks/useGrant.d.ts.map +1 -1
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react.cjs +232 -122
- package/dist/react.cjs.map +1 -1
- package/dist/react.mjs +231 -127
- package/dist/react.mjs.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/react.cjs
CHANGED
|
@@ -1,139 +1,249 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
const require_grant_client = require("./grant-client-zE-9zy3m.cjs");
|
|
3
|
+
let react = require("react");
|
|
4
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
+
//#region src/react/context.tsx
|
|
6
|
+
/**
|
|
7
|
+
* Context for the Grant client
|
|
8
|
+
*/
|
|
9
|
+
var GrantContext = (0, react.createContext)(null);
|
|
10
|
+
/**
|
|
11
|
+
* Provider component that makes the Grant client available to child components
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* // Option 1: Pass config (cookie-based refresh)
|
|
16
|
+
* <GrantProvider
|
|
17
|
+
* config={{
|
|
18
|
+
* apiUrl: 'https://api.grant.com',
|
|
19
|
+
* getAccessToken: () => localStorage.getItem('accessToken'),
|
|
20
|
+
* onRefreshWithCredentials: async () => {
|
|
21
|
+
* const res = await fetch('https://api.grant.com/api/auth/refresh', { method: 'POST', credentials: 'include' });
|
|
22
|
+
* if (!res.ok) return false;
|
|
23
|
+
* const { data } = await res.json();
|
|
24
|
+
* if (data?.accessToken) { localStorage.setItem('accessToken', data.accessToken); return true; }
|
|
25
|
+
* return false;
|
|
26
|
+
* },
|
|
27
|
+
* onTokenRefresh: (tokens) => { localStorage.setItem('accessToken', tokens.accessToken); },
|
|
28
|
+
* onUnauthorized: () => { window.location.href = '/login'; },
|
|
29
|
+
* }}
|
|
30
|
+
* >
|
|
31
|
+
* <App />
|
|
32
|
+
* </GrantProvider>
|
|
33
|
+
*
|
|
34
|
+
* // Option 2: Pass pre-configured client
|
|
35
|
+
* const grant = new GrantClient({ ... });
|
|
36
|
+
* <GrantProvider client={grant}>
|
|
37
|
+
* <App />
|
|
38
|
+
* </GrantProvider>
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
7
41
|
function GrantProvider({ config, client, children }) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
42
|
+
const grantClient = (0, react.useMemo)(() => {
|
|
43
|
+
if (client) return client;
|
|
44
|
+
return new require_grant_client.GrantClient(config);
|
|
45
|
+
}, [client, config]);
|
|
46
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GrantContext.Provider, {
|
|
47
|
+
value: grantClient,
|
|
48
|
+
children
|
|
49
|
+
});
|
|
13
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Hook to access the Grant client from context
|
|
53
|
+
*
|
|
54
|
+
* @throws Error if used outside of GrantProvider
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```tsx
|
|
58
|
+
* const grant = useGrantClient();
|
|
59
|
+
* const hasPermission = await grant.can('resource', 'action');
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
14
62
|
function useGrantClient() {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"useGrantClient must be used within a GrantProvider. Wrap your app with <GrantProvider config={...}> to fix this error."
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
return client;
|
|
63
|
+
const client = (0, react.useContext)(GrantContext);
|
|
64
|
+
if (!client) throw new Error("useGrantClient must be used within a GrantProvider. Wrap your app with <GrantProvider config={...}> to fix this error.");
|
|
65
|
+
return client;
|
|
22
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Hook to optionally access the Grant client
|
|
69
|
+
* Returns null if not in a GrantProvider context
|
|
70
|
+
*
|
|
71
|
+
* Use this when you want to gracefully handle missing provider
|
|
72
|
+
*/
|
|
23
73
|
function useGrantClientOptional() {
|
|
24
|
-
|
|
74
|
+
return (0, react.useContext)(GrantContext);
|
|
25
75
|
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/react/hooks/useGrant.ts
|
|
78
|
+
/**
|
|
79
|
+
* Serialize scope for stable dependency comparison
|
|
80
|
+
* This prevents re-fetching when scope object reference changes but values are the same
|
|
81
|
+
*/
|
|
26
82
|
function serializeScope(scope) {
|
|
27
|
-
|
|
28
|
-
|
|
83
|
+
if (!scope) return "";
|
|
84
|
+
return `${scope.tenant}:${scope.id}`;
|
|
29
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Hook to check if a user is granted permission for a specific resource and action
|
|
88
|
+
*
|
|
89
|
+
* By default, returns a simple boolean, defaulting to false while loading.
|
|
90
|
+
* Set `returnLoading: true` to get an object with `isGranted` and `isLoading`.
|
|
91
|
+
*
|
|
92
|
+
* @param resource - The resource slug to check
|
|
93
|
+
* @param action - The action to check
|
|
94
|
+
* @param options - Additional options
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```tsx
|
|
98
|
+
* // Simple boolean (default)
|
|
99
|
+
* const canEdit = useGrant('document', 'update');
|
|
100
|
+
*
|
|
101
|
+
* return (
|
|
102
|
+
* <div>
|
|
103
|
+
* {canEdit && <EditButton />}
|
|
104
|
+
* </div>
|
|
105
|
+
* );
|
|
106
|
+
*
|
|
107
|
+
* // With loading state
|
|
108
|
+
* const { isGranted, isLoading } = useGrant('document', 'update', {
|
|
109
|
+
* returnLoading: true,
|
|
110
|
+
* });
|
|
111
|
+
*
|
|
112
|
+
* if (isLoading) return <Spinner />;
|
|
113
|
+
* if (!isGranted) return null;
|
|
114
|
+
*
|
|
115
|
+
* return <EditButton />;
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
30
118
|
function useGrant(resource, action, options = {}) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const isGranted = data?.authorized ?? false;
|
|
99
|
-
if (returnLoading) {
|
|
100
|
-
return { isGranted, isLoading };
|
|
101
|
-
}
|
|
102
|
-
return isGranted;
|
|
119
|
+
const { scope, enabled = true, useCache = true, returnLoading = false, context } = options;
|
|
120
|
+
const client = useGrantClient();
|
|
121
|
+
const scopeWasProvidedRef = (0, react.useRef)("scope" in options);
|
|
122
|
+
const isEffectivelyEnabled = (0, react.useMemo)(() => {
|
|
123
|
+
const hasValidScope = scope && typeof scope === "object" && "tenant" in scope && "id" in scope && scope.id;
|
|
124
|
+
const shouldWaitForScope = scopeWasProvidedRef.current && !hasValidScope;
|
|
125
|
+
return enabled && !shouldWaitForScope;
|
|
126
|
+
}, [scope, enabled]);
|
|
127
|
+
const [data, setData] = (0, react.useState)(null);
|
|
128
|
+
const [isLoading, setIsLoading] = (0, react.useState)(isEffectivelyEnabled);
|
|
129
|
+
const [prevEffectivelyEnabled, setPrevEffectivelyEnabled] = (0, react.useState)(isEffectivelyEnabled);
|
|
130
|
+
if (isEffectivelyEnabled !== prevEffectivelyEnabled) {
|
|
131
|
+
setPrevEffectivelyEnabled(isEffectivelyEnabled);
|
|
132
|
+
if (isEffectivelyEnabled) setIsLoading(true);
|
|
133
|
+
else {
|
|
134
|
+
setIsLoading(false);
|
|
135
|
+
setData(null);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const isMounted = (0, react.useRef)(true);
|
|
139
|
+
const scopeRef = (0, react.useRef)(scope);
|
|
140
|
+
scopeRef.current = scope;
|
|
141
|
+
const contextRef = (0, react.useRef)(context);
|
|
142
|
+
contextRef.current = context;
|
|
143
|
+
const fetchPermission = (0, react.useCallback)(async () => {
|
|
144
|
+
if (!isEffectivelyEnabled) {
|
|
145
|
+
setIsLoading(false);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
setIsLoading(true);
|
|
149
|
+
try {
|
|
150
|
+
const result = await client.isAuthorized(resource, action, {
|
|
151
|
+
scope: scopeRef.current ?? void 0,
|
|
152
|
+
useCache,
|
|
153
|
+
context: contextRef.current
|
|
154
|
+
});
|
|
155
|
+
if (isMounted.current) setData(result);
|
|
156
|
+
} catch {
|
|
157
|
+
if (isMounted.current) setData(null);
|
|
158
|
+
} finally {
|
|
159
|
+
if (isMounted.current) setIsLoading(false);
|
|
160
|
+
}
|
|
161
|
+
}, [
|
|
162
|
+
client,
|
|
163
|
+
resource,
|
|
164
|
+
action,
|
|
165
|
+
serializeScope(scope),
|
|
166
|
+
isEffectivelyEnabled,
|
|
167
|
+
useCache,
|
|
168
|
+
(0, react.useMemo)(() => context?.resource != null ? JSON.stringify(context.resource) : "", [context?.resource])
|
|
169
|
+
]);
|
|
170
|
+
(0, react.useEffect)(() => {
|
|
171
|
+
isMounted.current = true;
|
|
172
|
+
if (!isEffectivelyEnabled && scopeWasProvidedRef.current) {
|
|
173
|
+
setData(null);
|
|
174
|
+
setIsLoading(false);
|
|
175
|
+
} else fetchPermission();
|
|
176
|
+
return () => {
|
|
177
|
+
isMounted.current = false;
|
|
178
|
+
};
|
|
179
|
+
}, [fetchPermission, isEffectivelyEnabled]);
|
|
180
|
+
const isGranted = data?.authorized ?? false;
|
|
181
|
+
if (returnLoading) return {
|
|
182
|
+
isGranted,
|
|
183
|
+
isLoading
|
|
184
|
+
};
|
|
185
|
+
return isGranted;
|
|
103
186
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/react/components/GrantGate.tsx
|
|
189
|
+
/**
|
|
190
|
+
* Component that conditionally renders children based on permissions
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```tsx
|
|
194
|
+
* // Basic usage - hide element if no permission
|
|
195
|
+
* <GrantGate resource="document" action="update">
|
|
196
|
+
* <EditButton />
|
|
197
|
+
* </GrantGate>
|
|
198
|
+
*
|
|
199
|
+
* // With fallback for denied access
|
|
200
|
+
* <GrantGate
|
|
201
|
+
* resource="admin"
|
|
202
|
+
* action="access"
|
|
203
|
+
* fallback={<p>You don't have admin access</p>}
|
|
204
|
+
* >
|
|
205
|
+
* <AdminPanel />
|
|
206
|
+
* </GrantGate>
|
|
207
|
+
*
|
|
208
|
+
* // With loading state
|
|
209
|
+
* <GrantGate
|
|
210
|
+
* resource="report"
|
|
211
|
+
* action="view"
|
|
212
|
+
* loading={<Spinner />}
|
|
213
|
+
* fallback={<AccessDenied />}
|
|
214
|
+
* >
|
|
215
|
+
* <ReportViewer />
|
|
216
|
+
* </GrantGate>
|
|
217
|
+
*
|
|
218
|
+
* // With scope for multi-tenant
|
|
219
|
+
* <GrantGate
|
|
220
|
+
* resource="project"
|
|
221
|
+
* action="delete"
|
|
222
|
+
* scope={{ tenant: 'project', id: projectId }}
|
|
223
|
+
* >
|
|
224
|
+
* <DeleteProjectButton />
|
|
225
|
+
* </GrantGate>
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
function GrantGate({ resource, action, scope, enabled, useCache, children, fallback = null, loading = null }) {
|
|
229
|
+
const options = {
|
|
230
|
+
enabled,
|
|
231
|
+
useCache,
|
|
232
|
+
returnLoading: loading !== null
|
|
233
|
+
};
|
|
234
|
+
if (scope !== void 0) options.scope = scope;
|
|
235
|
+
const result = useGrant(resource, action, options);
|
|
236
|
+
const isGranted = typeof result === "boolean" ? result : result.isGranted;
|
|
237
|
+
if ((typeof result === "boolean" ? false : result.isLoading) && loading !== null) return loading;
|
|
238
|
+
if (isGranted) return children;
|
|
239
|
+
return fallback;
|
|
132
240
|
}
|
|
133
|
-
|
|
241
|
+
//#endregion
|
|
242
|
+
exports.GrantClient = require_grant_client.GrantClient;
|
|
134
243
|
exports.GrantGate = GrantGate;
|
|
135
244
|
exports.GrantProvider = GrantProvider;
|
|
136
245
|
exports.useGrant = useGrant;
|
|
137
246
|
exports.useGrantClient = useGrantClient;
|
|
138
247
|
exports.useGrantClientOptional = useGrantClientOptional;
|
|
139
|
-
|
|
248
|
+
|
|
249
|
+
//# sourceMappingURL=react.cjs.map
|
package/dist/react.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.cjs","sources":["../src/react/context.tsx","../src/react/hooks/useGrant.ts","../src/react/components/GrantGate.tsx"],"sourcesContent":["'use client';\n\nimport { createContext, useContext, useMemo, type ReactNode } from 'react';\n\nimport { GrantClient } from '../grant-client';\n\nimport type { GrantClientConfig } from '../types';\n\n/**\n * Context for the Grant client\n */\nconst GrantContext = createContext<GrantClient | null>(null);\n\n/**\n * Props for the GrantProvider component\n */\nexport interface GrantProviderProps {\n /**\n * Grant client configuration\n */\n config: GrantClientConfig;\n\n /**\n * Pre-configured GrantClient instance (alternative to config)\n * If provided, config is ignored\n */\n client?: GrantClient;\n\n /**\n * Child components\n */\n children: ReactNode;\n}\n\n/**\n * Provider component that makes the Grant client available to child components\n *\n * @example\n * ```tsx\n * // Option 1: Pass config (cookie-based refresh)\n * <GrantProvider\n * config={{\n * apiUrl: 'https://api.grant.com',\n * getAccessToken: () => localStorage.getItem('accessToken'),\n * onRefreshWithCredentials: async () => {\n * const res = await fetch('https://api.grant.com/api/auth/refresh', { method: 'POST', credentials: 'include' });\n * if (!res.ok) return false;\n * const { data } = await res.json();\n * if (data?.accessToken) { localStorage.setItem('accessToken', data.accessToken); return true; }\n * return false;\n * },\n * onTokenRefresh: (tokens) => { localStorage.setItem('accessToken', tokens.accessToken); },\n * onUnauthorized: () => { window.location.href = '/login'; },\n * }}\n * >\n * <App />\n * </GrantProvider>\n *\n * // Option 2: Pass pre-configured client\n * const grant = new GrantClient({ ... });\n * <GrantProvider client={grant}>\n * <App />\n * </GrantProvider>\n * ```\n */\nexport function GrantProvider({ config, client, children }: GrantProviderProps) {\n const grantClient = useMemo(() => {\n if (client) return client;\n return new GrantClient(config);\n }, [client, config]);\n\n return <GrantContext.Provider value={grantClient}>{children}</GrantContext.Provider>;\n}\n\n/**\n * Hook to access the Grant client from context\n *\n * @throws Error if used outside of GrantProvider\n *\n * @example\n * ```tsx\n * const grant = useGrantClient();\n * const hasPermission = await grant.can('resource', 'action');\n * ```\n */\nexport function useGrantClient(): GrantClient {\n const client = useContext(GrantContext);\n\n if (!client) {\n throw new Error(\n 'useGrantClient must be used within a GrantProvider. ' +\n 'Wrap your app with <GrantProvider config={...}> to fix this error.'\n );\n }\n\n return client;\n}\n\n/**\n * Hook to optionally access the Grant client\n * Returns null if not in a GrantProvider context\n *\n * Use this when you want to gracefully handle missing provider\n */\nexport function useGrantClientOptional(): GrantClient | null {\n return useContext(GrantContext);\n}\n","'use client';\n\nimport { useState, useEffect, useCallback, useRef, useMemo } from 'react';\n\nimport { useGrantClient } from '../context';\n\nimport type { AuthorizationResult, Scope } from '../../types';\n\n/**\n * Options for the useGrant hook\n */\nexport interface UseGrantOptions {\n /** Scope to check the permission in. If provided but null/undefined, hook waits for it to become valid. */\n scope?: Scope | null;\n /** Whether to skip the permission check */\n enabled?: boolean;\n /** Whether to use cached results (default: true) */\n useCache?: boolean;\n /** Whether to return loading state (default: false) */\n returnLoading?: boolean;\n /** Context to check permissions for */\n context?: {\n resource?: Record<string, unknown> | null;\n };\n}\n\n/**\n * Result when returnLoading is true\n */\nexport interface UseGrantResult {\n /** Whether the user is granted permission */\n isGranted: boolean;\n /** Whether the permission check is loading */\n isLoading: boolean;\n}\n\n/**\n * Serialize scope for stable dependency comparison\n * This prevents re-fetching when scope object reference changes but values are the same\n */\nfunction serializeScope(scope?: Scope | null): string {\n if (!scope) return '';\n return `${scope.tenant}:${scope.id}`;\n}\n\n/**\n * Hook to check if a user is granted permission for a specific resource and action\n *\n * By default, returns a simple boolean, defaulting to false while loading.\n * Set `returnLoading: true` to get an object with `isGranted` and `isLoading`.\n *\n * @param resource - The resource slug to check\n * @param action - The action to check\n * @param options - Additional options\n *\n * @example\n * ```tsx\n * // Simple boolean (default)\n * const canEdit = useGrant('document', 'update');\n *\n * return (\n * <div>\n * {canEdit && <EditButton />}\n * </div>\n * );\n *\n * // With loading state\n * const { isGranted, isLoading } = useGrant('document', 'update', {\n * returnLoading: true,\n * });\n *\n * if (isLoading) return <Spinner />;\n * if (!isGranted) return null;\n *\n * return <EditButton />;\n * ```\n */\nexport function useGrant(\n resource: string,\n action: string,\n options: UseGrantOptions = {}\n): boolean | UseGrantResult {\n const { scope, enabled = true, useCache = true, returnLoading = false, context } = options;\n const client = useGrantClient();\n\n // Track if scope was explicitly provided (even if null/undefined)\n // This allows us to distinguish between \"scope not provided\" (optional) vs \"scope provided but falsy\" (wait for it)\n // Check this once at the start - if scope key exists in options, it was provided\n // Note: { scope: undefined } has the key, { } does not have the key\n const scopeWasProvidedRef = useRef('scope' in options);\n\n // Determine if we should wait for scope to become valid\n // If scope was provided but is falsy or invalid, wait for it to become truthy\n // Recalculate when scope changes\n const isEffectivelyEnabled = useMemo(() => {\n const hasValidScope =\n scope && typeof scope === 'object' && 'tenant' in scope && 'id' in scope && scope.id;\n const shouldWaitForScope = scopeWasProvidedRef.current && !hasValidScope;\n return enabled && !shouldWaitForScope;\n }, [scope, enabled]);\n\n const [data, setData] = useState<AuthorizationResult | null>(null);\n const [isLoading, setIsLoading] = useState(isEffectivelyEnabled);\n\n // Synchronously correct isLoading when isEffectivelyEnabled transitions.\n // useState only uses its initializer on first render, so subsequent transitions\n // leave isLoading stale for one render cycle (the effect hasn't run yet).\n // This uses React's \"storing information from previous renders\" pattern to\n // immediately set isLoading before the render completes.\n // See: https://react.dev/reference/react/useState#storing-information-from-previous-renders\n const [prevEffectivelyEnabled, setPrevEffectivelyEnabled] = useState(isEffectivelyEnabled);\n if (isEffectivelyEnabled !== prevEffectivelyEnabled) {\n setPrevEffectivelyEnabled(isEffectivelyEnabled);\n if (isEffectivelyEnabled) {\n setIsLoading(true);\n } else {\n setIsLoading(false);\n setData(null);\n }\n }\n\n // Track mounted state to prevent state updates after unmount\n const isMounted = useRef(true);\n\n // Store scope in a ref so we always have the latest value without triggering re-renders\n const scopeRef = useRef(scope);\n scopeRef.current = scope;\n\n // Store context in a ref so the callback always sends the latest context\n const contextRef = useRef(context);\n contextRef.current = context;\n\n // Serialize scope to get a stable string for dependency comparison\n const scopeKey = serializeScope(scope);\n\n // Serialize context so we re-create the callback when context meaningfully changes\n const contextKey = useMemo(\n () => (context?.resource != null ? JSON.stringify(context.resource) : ''),\n [context?.resource]\n );\n\n const fetchPermission = useCallback(async () => {\n if (!isEffectivelyEnabled) {\n setIsLoading(false);\n return;\n }\n\n setIsLoading(true);\n\n try {\n // Use scopeRef.current and contextRef.current to get the latest values\n // Convert null to undefined for the client (which expects Scope | undefined)\n const result = await client.isAuthorized(resource, action, {\n scope: scopeRef.current ?? undefined,\n useCache,\n context: contextRef.current,\n });\n if (isMounted.current) {\n setData(result);\n }\n } catch {\n // On error, set data to null (will return false)\n if (isMounted.current) {\n setData(null);\n }\n } finally {\n if (isMounted.current) {\n setIsLoading(false);\n }\n }\n // contextKey ensures we re-run when context (e.g. resource) changes so the request gets the latest context\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [client, resource, action, scopeKey, isEffectivelyEnabled, useCache, contextKey]);\n\n useEffect(() => {\n isMounted.current = true;\n\n // Clear data when scope becomes invalid (waiting for valid scope)\n if (!isEffectivelyEnabled && scopeWasProvidedRef.current) {\n setData(null);\n setIsLoading(false);\n } else {\n fetchPermission();\n }\n\n return () => {\n isMounted.current = false;\n };\n }, [fetchPermission, isEffectivelyEnabled]);\n\n const isGranted = data?.authorized ?? false;\n\n // Return object with loading state if requested, otherwise just boolean\n if (returnLoading) {\n return { isGranted, isLoading };\n }\n\n return isGranted;\n}\n","'use client';\n\nimport type { ReactNode } from 'react';\n\nimport { useGrant, type UseGrantOptions } from '../hooks/useGrant';\n\n/**\n * Props for the GrantGate component\n */\nexport interface GrantGateProps extends UseGrantOptions {\n /** The resource slug to check permission for */\n resource: string;\n /** The action to check */\n action: string;\n /** Content to render if permission is granted */\n children: ReactNode;\n /** Content to render if permission is denied (optional) */\n fallback?: ReactNode;\n /** Content to render while loading (optional) */\n loading?: ReactNode;\n}\n\n/**\n * Component that conditionally renders children based on permissions\n *\n * @example\n * ```tsx\n * // Basic usage - hide element if no permission\n * <GrantGate resource=\"document\" action=\"update\">\n * <EditButton />\n * </GrantGate>\n *\n * // With fallback for denied access\n * <GrantGate\n * resource=\"admin\"\n * action=\"access\"\n * fallback={<p>You don't have admin access</p>}\n * >\n * <AdminPanel />\n * </GrantGate>\n *\n * // With loading state\n * <GrantGate\n * resource=\"report\"\n * action=\"view\"\n * loading={<Spinner />}\n * fallback={<AccessDenied />}\n * >\n * <ReportViewer />\n * </GrantGate>\n *\n * // With scope for multi-tenant\n * <GrantGate\n * resource=\"project\"\n * action=\"delete\"\n * scope={{ tenant: 'project', id: projectId }}\n * >\n * <DeleteProjectButton />\n * </GrantGate>\n * ```\n */\nexport function GrantGate({\n resource,\n action,\n scope,\n enabled,\n useCache,\n children,\n fallback = null,\n loading = null,\n}: GrantGateProps): ReactNode {\n // Build options object conditionally\n // Only include scope in options if it's not undefined (null is valid and means \"wait for it\")\n // This allows the hook to distinguish between \"scope not provided\" (undefined) vs \"scope provided but null\"\n const options: Parameters<typeof useGrant>[2] = {\n enabled,\n useCache,\n returnLoading: loading !== null,\n };\n\n // Only add scope to options if it's explicitly null or a valid object\n // If scope is undefined, don't include it so hook treats it as optional\n if (scope !== undefined) {\n options.scope = scope;\n }\n\n // Use loading state if loading prop is provided\n const result = useGrant(resource, action, options);\n\n const isGranted = typeof result === 'boolean' ? result : result.isGranted;\n const isLoading = typeof result === 'boolean' ? false : result.isLoading;\n\n if (isLoading && loading !== null) {\n return loading;\n }\n\n if (isGranted) {\n return children;\n }\n\n return fallback;\n}\n"],"names":["createContext","useMemo","GrantClient","useContext","useRef","useState","useCallback","useEffect"],"mappings":";;;;;AAWA,MAAM,eAAeA,MAAAA,cAAkC,IAAI;AAsDpD,SAAS,cAAc,EAAE,QAAQ,QAAQ,YAAgC;AAC9E,QAAM,cAAcC,MAAAA,QAAQ,MAAM;AAChC,QAAI,OAAQ,QAAO;AACnB,WAAO,IAAIC,MAAAA,YAAY,MAAM;AAAA,EAC/B,GAAG,CAAC,QAAQ,MAAM,CAAC;AAEnB,wCAAQ,aAAa,UAAb,EAAsB,OAAO,aAAc,UAAS;AAC9D;AAaO,SAAS,iBAA8B;AAC5C,QAAM,SAASC,MAAAA,WAAW,YAAY;AAEtC,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAGJ;AAEA,SAAO;AACT;AAQO,SAAS,yBAA6C;AAC3D,SAAOA,MAAAA,WAAW,YAAY;AAChC;AClEA,SAAS,eAAe,OAA8B;AACpD,MAAI,CAAC,MAAO,QAAO;AACnB,SAAO,GAAG,MAAM,MAAM,IAAI,MAAM,EAAE;AACpC;AAkCO,SAAS,SACd,UACA,QACA,UAA2B,CAAA,GACD;AAC1B,QAAM,EAAE,OAAO,UAAU,MAAM,WAAW,MAAM,gBAAgB,OAAO,QAAA,IAAY;AACnF,QAAM,SAAS,eAAA;AAMf,QAAM,sBAAsBC,MAAAA,OAAO,WAAW,OAAO;AAKrD,QAAM,uBAAuBH,MAAAA,QAAQ,MAAM;AACzC,UAAM,gBACJ,SAAS,OAAO,UAAU,YAAY,YAAY,SAAS,QAAQ,SAAS,MAAM;AACpF,UAAM,qBAAqB,oBAAoB,WAAW,CAAC;AAC3D,WAAO,WAAW,CAAC;AAAA,EACrB,GAAG,CAAC,OAAO,OAAO,CAAC;AAEnB,QAAM,C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,QAAAA,UAAU,MAAM;AACd,cAAU,UAAU;AAGpB,QAAI,CAAC,wBAAwB,oBAAoB,SAAS;AACxD,cAAQ,IAAI;AACZ,mBAAa,KAAK;AAAA,IACpB,OAAO;AACL,sBAAA;AAAA,IACF;AAEA,WAAO,MAAM;AACX,gBAAU,UAAU;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,iBAAiB,oBAAoB,CAAC;AAE1C,QAAM,YAAY,MAAM,cAAc;AAGtC,MAAI,eAAe;AACjB,WAAO,EAAE,WAAW,UAAA;AAAA,EACtB;AAEA,SAAO;AACT;ACzIO,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX,UAAU;AACZ,GAA8B;AAI5B,QAAM,UAA0C;AAAA,IAC9C;AAAA,IACA;AAAA,IACA,eAAe,YAAY;AAAA,EAAA;AAK7B,MAAI,UAAU,QAAW;AACvB,YAAQ,QAAQ;AAAA,EAClB;AAGA,QAAM,SAAS,SAAS,UAAU,QAAQ,OAAO;AAEjD,QAAM,YAAY,OAAO,WAAW,YAAY,SAAS,OAAO;AAChE,QAAM,YAAY,OAAO,WAAW,YAAY,QAAQ,OAAO;AAE/D,MAAI,aAAa,YAAY,MAAM;AACjC,WAAO;AAAA,EACT;AAEA,MAAI,WAAW;AACb,WAAO;AAAA,EACT;AAEA,SAAO;AACT;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"react.cjs","names":[],"sources":["../src/react/context.tsx","../src/react/hooks/useGrant.ts","../src/react/components/GrantGate.tsx"],"sourcesContent":["'use client';\n\nimport { createContext, type ReactNode, useContext, useMemo } from 'react';\n\nimport { GrantClient } from '../grant-client';\nimport type { GrantClientConfig } from '../types';\n\n/**\n * Context for the Grant client\n */\nconst GrantContext = createContext<GrantClient | null>(null);\n\n/**\n * Props for the GrantProvider component\n */\nexport interface GrantProviderProps {\n /**\n * Grant client configuration\n */\n config: GrantClientConfig;\n\n /**\n * Pre-configured GrantClient instance (alternative to config)\n * If provided, config is ignored\n */\n client?: GrantClient;\n\n /**\n * Child components\n */\n children: ReactNode;\n}\n\n/**\n * Provider component that makes the Grant client available to child components\n *\n * @example\n * ```tsx\n * // Option 1: Pass config (cookie-based refresh)\n * <GrantProvider\n * config={{\n * apiUrl: 'https://api.grant.com',\n * getAccessToken: () => localStorage.getItem('accessToken'),\n * onRefreshWithCredentials: async () => {\n * const res = await fetch('https://api.grant.com/api/auth/refresh', { method: 'POST', credentials: 'include' });\n * if (!res.ok) return false;\n * const { data } = await res.json();\n * if (data?.accessToken) { localStorage.setItem('accessToken', data.accessToken); return true; }\n * return false;\n * },\n * onTokenRefresh: (tokens) => { localStorage.setItem('accessToken', tokens.accessToken); },\n * onUnauthorized: () => { window.location.href = '/login'; },\n * }}\n * >\n * <App />\n * </GrantProvider>\n *\n * // Option 2: Pass pre-configured client\n * const grant = new GrantClient({ ... });\n * <GrantProvider client={grant}>\n * <App />\n * </GrantProvider>\n * ```\n */\nexport function GrantProvider({ config, client, children }: GrantProviderProps) {\n const grantClient = useMemo(() => {\n if (client) return client;\n return new GrantClient(config);\n }, [client, config]);\n\n return <GrantContext.Provider value={grantClient}>{children}</GrantContext.Provider>;\n}\n\n/**\n * Hook to access the Grant client from context\n *\n * @throws Error if used outside of GrantProvider\n *\n * @example\n * ```tsx\n * const grant = useGrantClient();\n * const hasPermission = await grant.can('resource', 'action');\n * ```\n */\nexport function useGrantClient(): GrantClient {\n const client = useContext(GrantContext);\n\n if (!client) {\n throw new Error(\n 'useGrantClient must be used within a GrantProvider. ' +\n 'Wrap your app with <GrantProvider config={...}> to fix this error.'\n );\n }\n\n return client;\n}\n\n/**\n * Hook to optionally access the Grant client\n * Returns null if not in a GrantProvider context\n *\n * Use this when you want to gracefully handle missing provider\n */\nexport function useGrantClientOptional(): GrantClient | null {\n return useContext(GrantContext);\n}\n","'use client';\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nimport type { AuthorizationResult, Scope } from '../../types';\nimport { useGrantClient } from '../context';\n\n/**\n * Options for the useGrant hook\n */\nexport interface UseGrantOptions {\n /** Scope to check the permission in. If provided but null/undefined, hook waits for it to become valid. */\n scope?: Scope | null;\n /** Whether to skip the permission check */\n enabled?: boolean;\n /** Whether to use cached results (default: true) */\n useCache?: boolean;\n /** Whether to return loading state (default: false) */\n returnLoading?: boolean;\n /** Context to check permissions for */\n context?: {\n resource?: Record<string, unknown> | null;\n };\n}\n\n/**\n * Result when returnLoading is true\n */\nexport interface UseGrantResult {\n /** Whether the user is granted permission */\n isGranted: boolean;\n /** Whether the permission check is loading */\n isLoading: boolean;\n}\n\n/**\n * Serialize scope for stable dependency comparison\n * This prevents re-fetching when scope object reference changes but values are the same\n */\nfunction serializeScope(scope?: Scope | null): string {\n if (!scope) return '';\n return `${scope.tenant}:${scope.id}`;\n}\n\n/**\n * Hook to check if a user is granted permission for a specific resource and action\n *\n * By default, returns a simple boolean, defaulting to false while loading.\n * Set `returnLoading: true` to get an object with `isGranted` and `isLoading`.\n *\n * @param resource - The resource slug to check\n * @param action - The action to check\n * @param options - Additional options\n *\n * @example\n * ```tsx\n * // Simple boolean (default)\n * const canEdit = useGrant('document', 'update');\n *\n * return (\n * <div>\n * {canEdit && <EditButton />}\n * </div>\n * );\n *\n * // With loading state\n * const { isGranted, isLoading } = useGrant('document', 'update', {\n * returnLoading: true,\n * });\n *\n * if (isLoading) return <Spinner />;\n * if (!isGranted) return null;\n *\n * return <EditButton />;\n * ```\n */\nexport function useGrant(\n resource: string,\n action: string,\n options: UseGrantOptions = {}\n): boolean | UseGrantResult {\n const { scope, enabled = true, useCache = true, returnLoading = false, context } = options;\n const client = useGrantClient();\n\n // Track if scope was explicitly provided (even if null/undefined)\n // This allows us to distinguish between \"scope not provided\" (optional) vs \"scope provided but falsy\" (wait for it)\n // Check this once at the start - if scope key exists in options, it was provided\n // Note: { scope: undefined } has the key, { } does not have the key\n const scopeWasProvidedRef = useRef('scope' in options);\n\n // Determine if we should wait for scope to become valid\n // If scope was provided but is falsy or invalid, wait for it to become truthy\n // Recalculate when scope changes\n const isEffectivelyEnabled = useMemo(() => {\n const hasValidScope =\n scope && typeof scope === 'object' && 'tenant' in scope && 'id' in scope && scope.id;\n const shouldWaitForScope = scopeWasProvidedRef.current && !hasValidScope;\n return enabled && !shouldWaitForScope;\n }, [scope, enabled]);\n\n const [data, setData] = useState<AuthorizationResult | null>(null);\n const [isLoading, setIsLoading] = useState(isEffectivelyEnabled);\n\n // Synchronously correct isLoading when isEffectivelyEnabled transitions.\n // useState only uses its initializer on first render, so subsequent transitions\n // leave isLoading stale for one render cycle (the effect hasn't run yet).\n // This uses React's \"storing information from previous renders\" pattern to\n // immediately set isLoading before the render completes.\n // See: https://react.dev/reference/react/useState#storing-information-from-previous-renders\n const [prevEffectivelyEnabled, setPrevEffectivelyEnabled] = useState(isEffectivelyEnabled);\n if (isEffectivelyEnabled !== prevEffectivelyEnabled) {\n setPrevEffectivelyEnabled(isEffectivelyEnabled);\n if (isEffectivelyEnabled) {\n setIsLoading(true);\n } else {\n setIsLoading(false);\n setData(null);\n }\n }\n\n // Track mounted state to prevent state updates after unmount\n const isMounted = useRef(true);\n\n // Store scope in a ref so we always have the latest value without triggering re-renders\n const scopeRef = useRef(scope);\n scopeRef.current = scope;\n\n // Store context in a ref so the callback always sends the latest context\n const contextRef = useRef(context);\n contextRef.current = context;\n\n // Serialize scope to get a stable string for dependency comparison\n const scopeKey = serializeScope(scope);\n\n // Serialize context so we re-create the callback when context meaningfully changes\n const contextKey = useMemo(\n () => (context?.resource != null ? JSON.stringify(context.resource) : ''),\n [context?.resource]\n );\n\n const fetchPermission = useCallback(async () => {\n if (!isEffectivelyEnabled) {\n setIsLoading(false);\n return;\n }\n\n setIsLoading(true);\n\n try {\n // Use scopeRef.current and contextRef.current to get the latest values\n // Convert null to undefined for the client (which expects Scope | undefined)\n const result = await client.isAuthorized(resource, action, {\n scope: scopeRef.current ?? undefined,\n useCache,\n context: contextRef.current,\n });\n if (isMounted.current) {\n setData(result);\n }\n } catch {\n // On error, set data to null (will return false)\n if (isMounted.current) {\n setData(null);\n }\n } finally {\n if (isMounted.current) {\n setIsLoading(false);\n }\n }\n // contextKey ensures we re-run when context (e.g. resource) changes so the request gets the latest context\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [client, resource, action, scopeKey, isEffectivelyEnabled, useCache, contextKey]);\n\n useEffect(() => {\n isMounted.current = true;\n\n // Clear data when scope becomes invalid (waiting for valid scope)\n if (!isEffectivelyEnabled && scopeWasProvidedRef.current) {\n setData(null);\n setIsLoading(false);\n } else {\n fetchPermission();\n }\n\n return () => {\n isMounted.current = false;\n };\n }, [fetchPermission, isEffectivelyEnabled]);\n\n const isGranted = data?.authorized ?? false;\n\n // Return object with loading state if requested, otherwise just boolean\n if (returnLoading) {\n return { isGranted, isLoading };\n }\n\n return isGranted;\n}\n","'use client';\n\nimport type { ReactNode } from 'react';\n\nimport { useGrant, type UseGrantOptions } from '../hooks/useGrant';\n\n/**\n * Props for the GrantGate component\n */\nexport interface GrantGateProps extends UseGrantOptions {\n /** The resource slug to check permission for */\n resource: string;\n /** The action to check */\n action: string;\n /** Content to render if permission is granted */\n children: ReactNode;\n /** Content to render if permission is denied (optional) */\n fallback?: ReactNode;\n /** Content to render while loading (optional) */\n loading?: ReactNode;\n}\n\n/**\n * Component that conditionally renders children based on permissions\n *\n * @example\n * ```tsx\n * // Basic usage - hide element if no permission\n * <GrantGate resource=\"document\" action=\"update\">\n * <EditButton />\n * </GrantGate>\n *\n * // With fallback for denied access\n * <GrantGate\n * resource=\"admin\"\n * action=\"access\"\n * fallback={<p>You don't have admin access</p>}\n * >\n * <AdminPanel />\n * </GrantGate>\n *\n * // With loading state\n * <GrantGate\n * resource=\"report\"\n * action=\"view\"\n * loading={<Spinner />}\n * fallback={<AccessDenied />}\n * >\n * <ReportViewer />\n * </GrantGate>\n *\n * // With scope for multi-tenant\n * <GrantGate\n * resource=\"project\"\n * action=\"delete\"\n * scope={{ tenant: 'project', id: projectId }}\n * >\n * <DeleteProjectButton />\n * </GrantGate>\n * ```\n */\nexport function GrantGate({\n resource,\n action,\n scope,\n enabled,\n useCache,\n children,\n fallback = null,\n loading = null,\n}: GrantGateProps): ReactNode {\n // Build options object conditionally\n // Only include scope in options if it's not undefined (null is valid and means \"wait for it\")\n // This allows the hook to distinguish between \"scope not provided\" (undefined) vs \"scope provided but null\"\n const options: Parameters<typeof useGrant>[2] = {\n enabled,\n useCache,\n returnLoading: loading !== null,\n };\n\n // Only add scope to options if it's explicitly null or a valid object\n // If scope is undefined, don't include it so hook treats it as optional\n if (scope !== undefined) {\n options.scope = scope;\n }\n\n // Use loading state if loading prop is provided\n const result = useGrant(resource, action, options);\n\n const isGranted = typeof result === 'boolean' ? result : result.isGranted;\n const isLoading = typeof result === 'boolean' ? false : result.isLoading;\n\n if (isLoading && loading !== null) {\n return loading;\n }\n\n if (isGranted) {\n return children;\n }\n\n return fallback;\n}\n"],"mappings":";;;;;;;;AAUA,IAAM,gBAAA,GAAA,MAAA,eAAiD,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsD5D,SAAgB,cAAc,EAAE,QAAQ,QAAQ,YAAgC;CAC9E,MAAM,eAAA,GAAA,MAAA,eAA4B;AAChC,MAAI,OAAQ,QAAO;AACnB,SAAO,IAAI,qBAAA,YAAY,OAAO;IAC7B,CAAC,QAAQ,OAAO,CAAC;AAEpB,QAAO,iBAAA,GAAA,kBAAA,KAAC,aAAa,UAAd;EAAuB,OAAO;EAAc;EAAiC,CAAA;;;;;;;;;;;;;AActF,SAAgB,iBAA8B;CAC5C,MAAM,UAAA,GAAA,MAAA,YAAoB,aAAa;AAEvC,KAAI,CAAC,OACH,OAAM,IAAI,MACR,yHAED;AAGH,QAAO;;;;;;;;AAST,SAAgB,yBAA6C;AAC3D,SAAA,GAAA,MAAA,YAAkB,aAAa;;;;;;;;ACjEjC,SAAS,eAAe,OAA8B;AACpD,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