@react-protected/react 0.2.0 → 0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @react-protected/react
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - cb262d3: loader, action and middleware support
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [cb262d3]
12
+ - @react-protected/core@0.3.0
13
+
3
14
  ## 0.2.0
4
15
 
5
16
  ### Minor Changes
package/README.md CHANGED
@@ -1,82 +1,33 @@
1
1
  # @react-protected/react
2
2
 
3
- React context, hooks, and `HasAccess` component for [react-protected](https://github.com/astakhovaskold/react-protected).
4
-
5
- > **Using React Router?** Install [`@react-protected/react-router`](https://www.npmjs.com/package/@react-protected/react-router) instead — it includes this package.
6
-
7
- ---
8
-
9
- ## Installation
10
-
11
- ```bash
12
- npm install @react-protected/core @react-protected/react
13
- ```
14
-
15
- ```bash
16
- yarn add @react-protected/core @react-protected/react
17
- ```
18
-
19
- ```bash
20
- pnpm add @react-protected/core @react-protected/react
21
- ```
3
+ React context, hooks, and `HasAccess` component for `react-protected`.
22
4
 
23
5
  ## Usage
24
6
 
25
- ### AccessProvider
26
-
27
- Wrap your app with `AccessProvider` to provide the guard to the component tree:
28
-
29
7
  ```tsx
30
- import { AccessProvider } from '@react-protected/react'
8
+ import { AccessProvider, HasAccess, useHasAccess } from '@react-protected/react'
31
9
 
32
10
  const App = () => (
33
11
  <AccessProvider
34
12
  getUser={() => authStore.user}
35
13
  hasRole={(user, roles) => roles.some((role) => user.roles.includes(role))}
36
- loginPath="/login"
37
- forbiddenPath="/403"
38
- defaultPath="/dashboard"
39
14
  >
40
- <Router />
15
+ <Toolbar />
41
16
  </AccessProvider>
42
17
  )
43
- ```
44
-
45
- ### HasAccess
46
-
47
- Conditionally render UI elements based on access:
48
-
49
- ```tsx
50
- import { HasAccess } from '@react-protected/react'
51
-
52
- const Toolbar = () => (
53
- <nav>
54
- <HasAccess roles={['admin']}>
55
- <button>Delete</button>
56
- </HasAccess>
57
- </nav>
58
- )
59
- ```
60
-
61
- ### useHasAccess
62
18
 
63
- Hook version of `HasAccess`:
64
-
65
- ```tsx
66
- import { useHasAccess } from '@react-protected/react'
67
-
68
- const canDelete = useHasAccess({ roles: ['admin'] })
19
+ const Toolbar = () => {
20
+ const canDelete = useHasAccess({ roles: ['admin'] })
21
+
22
+ return (
23
+ <nav>
24
+ <HasAccess roles={['admin']}>
25
+ <button>Delete</button>
26
+ </HasAccess>
27
+ {canDelete ? <button>Danger zone</button> : null}
28
+ </nav>
29
+ )
30
+ }
69
31
  ```
70
32
 
71
- ## Packages
72
-
73
- | Package | Description |
74
- | --- | --- |
75
- | `@react-protected/core` | Pure access-control logic — no React, no router |
76
- | `@react-protected/react` | This package — React context, hooks, and `HasAccess` |
77
- | `@react-protected/react-router` | Adapter for React Router |
78
-
79
- ## Documentation
80
-
81
- - [Full documentation](https://github.com/astakhovaskold/react-protected/blob/main/docs/en/README.md)
82
- - [Examples](https://github.com/astakhovaskold/react-protected/blob/main/docs/en/examples/basic.md)
33
+ `AccessProvider` only provides the guard. It does not store redirect paths or route policy.
@@ -1,6 +1,6 @@
1
- import ee, { createContext as re, useMemo as F, useContext as te } from "react";
1
+ import ee, { createContext as re, useMemo as $, useContext as te } from "react";
2
2
  import { createGuard as ne } from "@react-protected/core";
3
- var y = { exports: {} }, _ = {};
3
+ var P = { exports: {} }, E = {};
4
4
  /**
5
5
  * @license React
6
6
  * react-jsx-runtime.production.js
@@ -10,29 +10,29 @@ var y = { exports: {} }, _ = {};
10
10
  * This source code is licensed under the MIT license found in the
11
11
  * LICENSE file in the root directory of this source tree.
12
12
  */
13
- var D;
14
- function oe() {
15
- if (D) return _;
16
- D = 1;
17
- var u = Symbol.for("react.transitional.element"), m = Symbol.for("react.fragment");
18
- function c(l, a, s) {
19
- var i = null;
20
- if (s !== void 0 && (i = "" + s), a.key !== void 0 && (i = "" + a.key), "key" in a) {
13
+ var I;
14
+ function ae() {
15
+ if (I) return E;
16
+ I = 1;
17
+ var u = Symbol.for("react.transitional.element"), i = Symbol.for("react.fragment");
18
+ function l(c, o, s) {
19
+ var f = null;
20
+ if (s !== void 0 && (f = "" + s), o.key !== void 0 && (f = "" + o.key), "key" in o) {
21
21
  s = {};
22
- for (var f in a)
23
- f !== "key" && (s[f] = a[f]);
24
- } else s = a;
25
- return a = s.ref, {
22
+ for (var m in o)
23
+ m !== "key" && (s[m] = o[m]);
24
+ } else s = o;
25
+ return o = s.ref, {
26
26
  $$typeof: u,
27
- type: l,
28
- key: i,
29
- ref: a !== void 0 ? a : null,
27
+ type: c,
28
+ key: f,
29
+ ref: o !== void 0 ? o : null,
30
30
  props: s
31
31
  };
32
32
  }
33
- return _.Fragment = m, _.jsx = c, _.jsxs = c, _;
33
+ return E.Fragment = i, E.jsx = l, E.jsxs = l, E;
34
34
  }
35
- var v = {};
35
+ var _ = {};
36
36
  /**
37
37
  * @license React
38
38
  * react-jsx-runtime.development.js
@@ -42,20 +42,20 @@ var v = {};
42
42
  * This source code is licensed under the MIT license found in the
43
43
  * LICENSE file in the root directory of this source tree.
44
44
  */
45
- var M;
46
- function ae() {
47
- return M || (M = 1, process.env.NODE_ENV !== "production" && function() {
45
+ var F;
46
+ function oe() {
47
+ return F || (F = 1, process.env.NODE_ENV !== "production" && function() {
48
48
  function u(e) {
49
49
  if (e == null) return null;
50
50
  if (typeof e == "function")
51
51
  return e.$$typeof === Z ? null : e.displayName || e.name || null;
52
52
  if (typeof e == "string") return e;
53
53
  switch (e) {
54
- case A:
54
+ case R:
55
55
  return "Fragment";
56
- case z:
57
- return "Profiler";
58
56
  case V:
57
+ return "Profiler";
58
+ case U:
59
59
  return "StrictMode";
60
60
  case J:
61
61
  return "Suspense";
@@ -70,16 +70,16 @@ function ae() {
70
70
  ), e.$$typeof) {
71
71
  case W:
72
72
  return "Portal";
73
- case U:
74
- return e.displayName || "Context";
75
73
  case G:
74
+ return e.displayName || "Context";
75
+ case z:
76
76
  return (e._context.displayName || "Context") + ".Consumer";
77
77
  case q:
78
78
  var r = e.render;
79
79
  return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
80
80
  case B:
81
81
  return r = e.displayName || null, r !== null ? r : u(e.type) || "Memo";
82
- case O:
82
+ case p:
83
83
  r = e._payload, e = e._init;
84
84
  try {
85
85
  return u(e(r));
@@ -88,12 +88,12 @@ function ae() {
88
88
  }
89
89
  return null;
90
90
  }
91
- function m(e) {
91
+ function i(e) {
92
92
  return "" + e;
93
93
  }
94
- function c(e) {
94
+ function l(e) {
95
95
  try {
96
- m(e);
96
+ i(e);
97
97
  var r = !1;
98
98
  } catch {
99
99
  r = !0;
@@ -105,12 +105,12 @@ function ae() {
105
105
  r,
106
106
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
107
107
  n
108
- ), m(e);
108
+ ), i(e);
109
109
  }
110
110
  }
111
- function l(e) {
112
- if (e === A) return "<>";
113
- if (typeof e == "object" && e !== null && e.$$typeof === O)
111
+ function c(e) {
112
+ if (e === R) return "<>";
113
+ if (typeof e == "object" && e !== null && e.$$typeof === p)
114
114
  return "<...>";
115
115
  try {
116
116
  var r = u(e);
@@ -119,23 +119,23 @@ function ae() {
119
119
  return "<...>";
120
120
  }
121
121
  }
122
- function a() {
123
- var e = w.A;
122
+ function o() {
123
+ var e = T.A;
124
124
  return e === null ? null : e.getOwner();
125
125
  }
126
126
  function s() {
127
127
  return Error("react-stack-top-frame");
128
128
  }
129
- function i(e) {
130
- if (N.call(e, "key")) {
129
+ function f(e) {
130
+ if (y.call(e, "key")) {
131
131
  var r = Object.getOwnPropertyDescriptor(e, "key").get;
132
132
  if (r && r.isReactWarning) return !1;
133
133
  }
134
134
  return e.key !== void 0;
135
135
  }
136
- function f(e, r) {
136
+ function m(e, r) {
137
137
  function t() {
138
- h || (h = !0, console.error(
138
+ g || (g = !0, console.error(
139
139
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
140
140
  r
141
141
  ));
@@ -145,23 +145,23 @@ function ae() {
145
145
  configurable: !0
146
146
  });
147
147
  }
148
- function R() {
148
+ function M() {
149
149
  var e = u(this.type);
150
- return C[e] || (C[e] = !0, console.error(
150
+ return h[e] || (h[e] = !0, console.error(
151
151
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
152
152
  )), e = this.props.ref, e !== void 0 ? e : null;
153
153
  }
154
- function b(e, r, t, n, k, x) {
155
- var o = t.ref;
154
+ function L(e, r, t, n, b, A) {
155
+ var a = t.ref;
156
156
  return e = {
157
- $$typeof: g,
157
+ $$typeof: j,
158
158
  type: e,
159
159
  key: r,
160
160
  props: t,
161
161
  _owner: n
162
- }, (o !== void 0 ? o : null) !== null ? Object.defineProperty(e, "ref", {
162
+ }, (a !== void 0 ? a : null) !== null ? Object.defineProperty(e, "ref", {
163
163
  enumerable: !1,
164
- get: R
164
+ get: M
165
165
  }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
166
166
  configurable: !1,
167
167
  enumerable: !1,
@@ -176,33 +176,33 @@ function ae() {
176
176
  configurable: !1,
177
177
  enumerable: !1,
178
178
  writable: !0,
179
- value: k
179
+ value: b
180
180
  }), Object.defineProperty(e, "_debugTask", {
181
181
  configurable: !1,
182
182
  enumerable: !1,
183
183
  writable: !0,
184
- value: x
184
+ value: A
185
185
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
186
186
  }
187
- function E(e, r, t, n, k, x) {
188
- var o = r.children;
189
- if (o !== void 0)
187
+ function w(e, r, t, n, b, A) {
188
+ var a = r.children;
189
+ if (a !== void 0)
190
190
  if (n)
191
- if (Q(o)) {
192
- for (n = 0; n < o.length; n++)
193
- p(o[n]);
194
- Object.freeze && Object.freeze(o);
191
+ if (Q(a)) {
192
+ for (n = 0; n < a.length; n++)
193
+ S(a[n]);
194
+ Object.freeze && Object.freeze(a);
195
195
  } else
196
196
  console.error(
197
197
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
198
198
  );
199
- else p(o);
200
- if (N.call(r, "key")) {
201
- o = u(e);
199
+ else S(a);
200
+ if (y.call(r, "key")) {
201
+ a = u(e);
202
202
  var d = Object.keys(r).filter(function(K) {
203
203
  return K !== "key";
204
204
  });
205
- n = 0 < d.length ? "{key: someKey, " + d.join(": ..., ") + ": ...}" : "{key: someKey}", I[o + n] || (d = 0 < d.length ? "{" + d.join(": ..., ") + ": ...}" : "{}", console.error(
205
+ n = 0 < d.length ? "{key: someKey, " + d.join(": ..., ") + ": ...}" : "{key: someKey}", Y[a + n] || (d = 0 < d.length ? "{" + d.join(": ..., ") + ": ...}" : "{}", console.error(
206
206
  `A props object containing a "key" prop is being spread into JSX:
207
207
  let props = %s;
208
208
  <%s {...props} />
@@ -210,108 +210,98 @@ React keys must be passed directly to JSX without using spread:
210
210
  let props = %s;
211
211
  <%s key={someKey} {...props} />`,
212
212
  n,
213
- o,
213
+ a,
214
214
  d,
215
- o
216
- ), I[o + n] = !0);
215
+ a
216
+ ), Y[a + n] = !0);
217
217
  }
218
- if (o = null, t !== void 0 && (c(t), o = "" + t), i(r) && (c(r.key), o = "" + r.key), "key" in r) {
218
+ if (a = null, t !== void 0 && (l(t), a = "" + t), f(r) && (l(r.key), a = "" + r.key), "key" in r) {
219
219
  t = {};
220
- for (var j in r)
221
- j !== "key" && (t[j] = r[j]);
220
+ for (var O in r)
221
+ O !== "key" && (t[O] = r[O]);
222
222
  } else t = r;
223
- return o && f(
223
+ return a && m(
224
224
  t,
225
225
  typeof e == "function" ? e.displayName || e.name || "Unknown" : e
226
- ), b(
226
+ ), L(
227
227
  e,
228
- o,
228
+ a,
229
229
  t,
230
- a(),
231
- k,
232
- x
230
+ o(),
231
+ b,
232
+ A
233
233
  );
234
234
  }
235
- function p(e) {
236
- P(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === O && (e._payload.status === "fulfilled" ? P(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
235
+ function S(e) {
236
+ x(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === p && (e._payload.status === "fulfilled" ? x(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
237
237
  }
238
- function P(e) {
239
- return typeof e == "object" && e !== null && e.$$typeof === g;
238
+ function x(e) {
239
+ return typeof e == "object" && e !== null && e.$$typeof === j;
240
240
  }
241
- var T = ee, g = Symbol.for("react.transitional.element"), W = Symbol.for("react.portal"), A = Symbol.for("react.fragment"), V = Symbol.for("react.strict_mode"), z = Symbol.for("react.profiler"), G = Symbol.for("react.consumer"), U = Symbol.for("react.context"), q = Symbol.for("react.forward_ref"), J = Symbol.for("react.suspense"), X = Symbol.for("react.suspense_list"), B = Symbol.for("react.memo"), O = Symbol.for("react.lazy"), H = Symbol.for("react.activity"), Z = Symbol.for("react.client.reference"), w = T.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, N = Object.prototype.hasOwnProperty, Q = Array.isArray, S = console.createTask ? console.createTask : function() {
241
+ var v = ee, j = Symbol.for("react.transitional.element"), W = Symbol.for("react.portal"), R = Symbol.for("react.fragment"), U = Symbol.for("react.strict_mode"), V = Symbol.for("react.profiler"), z = Symbol.for("react.consumer"), G = Symbol.for("react.context"), q = Symbol.for("react.forward_ref"), J = Symbol.for("react.suspense"), X = Symbol.for("react.suspense_list"), B = Symbol.for("react.memo"), p = Symbol.for("react.lazy"), H = Symbol.for("react.activity"), Z = Symbol.for("react.client.reference"), T = v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, y = Object.prototype.hasOwnProperty, Q = Array.isArray, k = console.createTask ? console.createTask : function() {
242
242
  return null;
243
243
  };
244
- T = {
244
+ v = {
245
245
  react_stack_bottom_frame: function(e) {
246
246
  return e();
247
247
  }
248
248
  };
249
- var h, C = {}, Y = T.react_stack_bottom_frame.bind(
250
- T,
249
+ var g, h = {}, N = v.react_stack_bottom_frame.bind(
250
+ v,
251
251
  s
252
- )(), $ = S(l(s)), I = {};
253
- v.Fragment = A, v.jsx = function(e, r, t) {
254
- var n = 1e4 > w.recentlyCreatedOwnerStacks++;
255
- return E(
252
+ )(), C = k(c(s)), Y = {};
253
+ _.Fragment = R, _.jsx = function(e, r, t) {
254
+ var n = 1e4 > T.recentlyCreatedOwnerStacks++;
255
+ return w(
256
256
  e,
257
257
  r,
258
258
  t,
259
259
  !1,
260
- n ? Error("react-stack-top-frame") : Y,
261
- n ? S(l(e)) : $
260
+ n ? Error("react-stack-top-frame") : N,
261
+ n ? k(c(e)) : C
262
262
  );
263
- }, v.jsxs = function(e, r, t) {
264
- var n = 1e4 > w.recentlyCreatedOwnerStacks++;
265
- return E(
263
+ }, _.jsxs = function(e, r, t) {
264
+ var n = 1e4 > T.recentlyCreatedOwnerStacks++;
265
+ return w(
266
266
  e,
267
267
  r,
268
268
  t,
269
269
  !0,
270
- n ? Error("react-stack-top-frame") : Y,
271
- n ? S(l(e)) : $
270
+ n ? Error("react-stack-top-frame") : N,
271
+ n ? k(c(e)) : C
272
272
  );
273
273
  };
274
- }()), v;
274
+ }()), _;
275
275
  }
276
- process.env.NODE_ENV === "production" ? y.exports = oe() : y.exports = ae();
277
- var se = y.exports;
278
- const L = re(null);
279
- function le({
276
+ process.env.NODE_ENV === "production" ? P.exports = ae() : P.exports = oe();
277
+ var se = P.exports;
278
+ const D = re(null);
279
+ function ce({
280
280
  children: u,
281
- loginPath: m = "/login",
282
- forbiddenPath: c = "/403",
283
- defaultPath: l = "/",
284
- callbackUrlParam: a,
285
- shouldAddCallbackUrl: s,
286
281
  getUser: i,
287
- isAuthenticated: f,
288
- hasRole: R,
289
- hasPermission: b
282
+ isAuthenticated: l,
283
+ hasRole: c,
284
+ hasPermission: o
290
285
  }) {
291
- const E = F(
292
- () => ne({ getUser: i, isAuthenticated: f, hasRole: R, hasPermission: b }),
293
- [i, f, R, b]
294
- ), p = F(
286
+ const s = $(
287
+ () => ne({ getUser: i, isAuthenticated: l, hasRole: c, hasPermission: o }),
288
+ [i, l, c, o]
289
+ ), f = $(
295
290
  () => ({
296
- guard: E,
297
- loginPath: m,
298
- forbiddenPath: c,
299
- defaultPath: l,
300
- callbackUrlParam: a,
301
- shouldAddCallbackUrl: s
291
+ guard: s
302
292
  }),
303
- [E, m, c, l, a, s]
293
+ [s]
304
294
  );
305
- return /* @__PURE__ */ se.jsx(L.Provider, { value: p, children: u });
295
+ return /* @__PURE__ */ se.jsx(D.Provider, { value: f, children: u });
306
296
  }
307
297
  function ie() {
308
- const u = te(L);
298
+ const u = te(D);
309
299
  if (!u)
310
300
  throw new Error("useAccess must be used within <AccessProvider>");
311
301
  return u;
312
302
  }
313
303
  export {
314
- le as A,
304
+ ce as A,
315
305
  se as j,
316
306
  ie as u
317
307
  };
@@ -0,0 +1,22 @@
1
+ "use strict";const v=require("react"),re=require("@react-protected/core");var w={exports:{}},E={};/**
2
+ * @license React
3
+ * react-jsx-runtime.production.js
4
+ *
5
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */var I;function te(){if(I)return E;I=1;var u=Symbol.for("react.transitional.element"),i=Symbol.for("react.fragment");function c(l,a,s){var f=null;if(s!==void 0&&(f=""+s),a.key!==void 0&&(f=""+a.key),"key"in a){s={};for(var m in a)m!=="key"&&(s[m]=a[m])}else s=a;return a=s.ref,{$$typeof:u,type:l,key:f,ref:a!==void 0?a:null,props:s}}return E.Fragment=i,E.jsx=c,E.jsxs=c,E}var _={};/**
10
+ * @license React
11
+ * react-jsx-runtime.development.js
12
+ *
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ */var F;function ne(){return F||(F=1,process.env.NODE_ENV!=="production"&&function(){function u(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===Q?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case p:return"Fragment";case V:return"Profiler";case q:return"StrictMode";case X:return"Suspense";case B:return"SuspenseList";case Z:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case U:return"Portal";case G:return e.displayName||"Context";case z:return(e._context.displayName||"Context")+".Consumer";case J:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case H:return r=e.displayName||null,r!==null?r:u(e.type)||"Memo";case T:r=e._payload,e=e._init;try{return u(e(r))}catch{}}return null}function i(e){return""+e}function c(e){try{i(e);var r=!1}catch{r=!0}if(r){r=console;var t=r.error,n=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",n),i(e)}}function l(e){if(e===p)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===T)return"<...>";try{var r=u(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function a(){var e=k.A;return e===null?null:e.getOwner()}function s(){return Error("react-stack-top-frame")}function f(e){if(g.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function m(e,r){function t(){h||(h=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}function L(){var e=u(this.type);return N[e]||(N[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function W(e,r,t,n,R,O){var o=t.ref;return e={$$typeof:y,type:e,key:r,props:t,_owner:n},(o!==void 0?o:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:L}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:R}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:O}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function S(e,r,t,n,R,O){var o=r.children;if(o!==void 0)if(n)if(K(o)){for(n=0;n<o.length;n++)x(o[n]);Object.freeze&&Object.freeze(o)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else x(o);if(g.call(r,"key")){o=u(e);var d=Object.keys(r).filter(function(ee){return ee!=="key"});n=0<d.length?"{key: someKey, "+d.join(": ..., ")+": ...}":"{key: someKey}",$[o+n]||(d=0<d.length?"{"+d.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
+ let props = %s;
19
+ <%s {...props} />
20
+ React keys must be passed directly to JSX without using spread:
21
+ let props = %s;
22
+ <%s key={someKey} {...props} />`,n,o,d,o),$[o+n]=!0)}if(o=null,t!==void 0&&(c(t),o=""+t),f(r)&&(c(r.key),o=""+r.key),"key"in r){t={};for(var P in r)P!=="key"&&(t[P]=r[P])}else t=r;return o&&m(t,typeof e=="function"?e.displayName||e.name||"Unknown":e),W(e,o,t,a(),R,O)}function x(e){j(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===T&&(e._payload.status==="fulfilled"?j(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function j(e){return typeof e=="object"&&e!==null&&e.$$typeof===y}var b=v,y=Symbol.for("react.transitional.element"),U=Symbol.for("react.portal"),p=Symbol.for("react.fragment"),q=Symbol.for("react.strict_mode"),V=Symbol.for("react.profiler"),z=Symbol.for("react.consumer"),G=Symbol.for("react.context"),J=Symbol.for("react.forward_ref"),X=Symbol.for("react.suspense"),B=Symbol.for("react.suspense_list"),H=Symbol.for("react.memo"),T=Symbol.for("react.lazy"),Z=Symbol.for("react.activity"),Q=Symbol.for("react.client.reference"),k=b.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,g=Object.prototype.hasOwnProperty,K=Array.isArray,A=console.createTask?console.createTask:function(){return null};b={react_stack_bottom_frame:function(e){return e()}};var h,N={},C=b.react_stack_bottom_frame.bind(b,s)(),Y=A(l(s)),$={};_.Fragment=p,_.jsx=function(e,r,t){var n=1e4>k.recentlyCreatedOwnerStacks++;return S(e,r,t,!1,n?Error("react-stack-top-frame"):C,n?A(l(e)):Y)},_.jsxs=function(e,r,t){var n=1e4>k.recentlyCreatedOwnerStacks++;return S(e,r,t,!0,n?Error("react-stack-top-frame"):C,n?A(l(e)):Y)}}()),_}process.env.NODE_ENV==="production"?w.exports=te():w.exports=ne();var D=w.exports;const M=v.createContext(null);function oe({children:u,getUser:i,isAuthenticated:c,hasRole:l,hasPermission:a}){const s=v.useMemo(()=>re.createGuard({getUser:i,isAuthenticated:c,hasRole:l,hasPermission:a}),[i,c,l,a]),f=v.useMemo(()=>({guard:s}),[s]);return D.jsx(M.Provider,{value:f,children:u})}function ae(){const u=v.useContext(M);if(!u)throw new Error("useAccess must be used within <AccessProvider>");return u}exports.AccessProvider=oe;exports.jsxRuntimeExports=D;exports.useAccess=ae;
@@ -6,12 +6,12 @@ import { AccessContextValue, AccessProviderProps } from './types';
6
6
  * @param props - Guard callbacks, navigation settings, and descendant elements.
7
7
  * @returns A context provider that enables access-aware hooks and components.
8
8
  */
9
- export declare function AccessProvider<TUser = unknown>({ children, loginPath, forbiddenPath, defaultPath, callbackUrlParam, shouldAddCallbackUrl, getUser, isAuthenticated, hasRole, hasPermission, }: AccessProviderProps<TUser>): import("react/jsx-runtime").JSX.Element;
9
+ export declare function AccessProvider<TUser = unknown>({ children, getUser, isAuthenticated, hasRole, hasPermission, }: AccessProviderProps<TUser>): import("react/jsx-runtime").JSX.Element;
10
10
  /**
11
11
  * Returns the active access context from `AccessProvider`.
12
12
  *
13
13
  * @typeParam TUser - User shape stored in the access context.
14
- * @returns The guard instance and navigation settings for the current subtree.
14
+ * @returns The guard instance for the current subtree.
15
15
  * @throws {Error} When called outside an `AccessProvider`.
16
16
  */
17
17
  export declare function useAccess<TUser = unknown>(): AccessContextValue<TUser>;
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./AccessProvider-sHL1A3i9.js");function r(s){const{guard:e}=c.useAccess();return e.check(s).allowed}function n({access:s,roles:e,permissions:u,meta:o,children:l}){return r({access:s,roles:e,permissions:u,meta:o})?l??null:null}exports.AccessProvider=c.AccessProvider;exports.useAccess=c.useAccess;exports.HasAccess=n;exports.useHasAccess=r;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./AccessProvider-PIwX6Nec.js");function r(s){const{guard:e}=c.useAccess();return e.check(s).allowed}function n({access:s,roles:e,permissions:u,meta:o,children:l}){return r({access:s,roles:e,permissions:u,meta:o})?l??null:null}exports.AccessProvider=c.AccessProvider;exports.useAccess=c.useAccess;exports.HasAccess=n;exports.useHasAccess=r;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { AccessProvider, useAccess } from './AccessProvider';
2
2
  export { HasAccess, useHasAccess } from './HasAccess';
3
- export type { AccessContextValue, AccessProviderProps, AccessRouteProps, NavigationConfig, RouteProtection, } from './types';
3
+ export type { AccessContextValue, AccessProviderProps, AccessRouteProps, RouteProtection, } from './types';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { u as l } from "./AccessProvider-DTsMa_Df.mjs";
2
- import { A as f } from "./AccessProvider-DTsMa_Df.mjs";
1
+ import { u as l } from "./AccessProvider-DIHb6g-h.mjs";
2
+ import { A as f } from "./AccessProvider-DIHb6g-h.mjs";
3
3
  function n(s) {
4
4
  const { guard: e } = l();
5
5
  return e.check(s).allowed;
package/dist/testing.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./AccessProvider-sHL1A3i9.js");function a({user:s=null,allowed:e=!0,children:t,getUser:c,isAuthenticated:i,hasRole:o,hasPermission:n,loginPath:u,forbiddenPath:P,defaultPath:d,callbackUrlParam:v,shouldAddCallbackUrl:A}){return r.jsxRuntimeExports.jsx(r.AccessProvider,{getUser:c??(()=>s),isAuthenticated:i??(()=>e),hasRole:o??(()=>e),hasPermission:n??(()=>e),loginPath:u,forbiddenPath:P,defaultPath:d,callbackUrlParam:v,shouldAddCallbackUrl:A,children:t})}exports.MockAccessProvider=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./AccessProvider-PIwX6Nec.js");function u({user:s=null,allowed:e=!0,children:t,getUser:c,isAuthenticated:i,hasRole:o,hasPermission:n}){return r.jsxRuntimeExports.jsx(r.AccessProvider,{getUser:c??(()=>s),isAuthenticated:i??(()=>e),hasRole:o??(()=>e),hasPermission:n??(()=>e),children:t})}exports.MockAccessProvider=u;
package/dist/testing.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import { GuardOptions } from '@react-protected/core';
2
2
  import { ReactNode } from 'react';
3
- import { NavigationConfig } from './types';
4
3
  /**
5
4
  * Props accepted by `MockAccessProvider`.
6
5
  */
7
- export type MockAccessProviderProps<TUser = unknown> = Partial<GuardOptions<TUser>> & NavigationConfig & {
6
+ export type MockAccessProviderProps<TUser = unknown> = Partial<GuardOptions<TUser>> & {
8
7
  /**
9
8
  * User returned by the default `getUser` implementation.
10
9
  */
@@ -23,8 +22,9 @@ export type MockAccessProviderProps<TUser = unknown> = Partial<GuardOptions<TUse
23
22
  *
24
23
  * @typeParam TUser - User shape returned by the mocked `getUser`.
25
24
  * @param props - Mocked user, optional callback overrides, navigation settings, and children.
25
+ * @param props - Mocked user, optional callback overrides, and children.
26
26
  * @returns An `AccessProvider` configured for deterministic tests.
27
27
  * @remarks When explicit callbacks are omitted, authentication, role, and permission checks all
28
28
  * resolve to the `allowed` flag.
29
29
  */
30
- export declare function MockAccessProvider<TUser = unknown>({ user, allowed, children, getUser, isAuthenticated, hasRole, hasPermission, loginPath, forbiddenPath, defaultPath, callbackUrlParam, shouldAddCallbackUrl, }: MockAccessProviderProps<TUser>): import("react/jsx-runtime").JSX.Element;
30
+ export declare function MockAccessProvider<TUser = unknown>({ user, allowed, children, getUser, isAuthenticated, hasRole, hasPermission, }: MockAccessProviderProps<TUser>): import("react/jsx-runtime").JSX.Element;
package/dist/testing.js CHANGED
@@ -1,34 +1,24 @@
1
- import { j as a, A as h } from "./AccessProvider-DTsMa_Df.mjs";
2
- function p({
1
+ import { j as n, A as u } from "./AccessProvider-DIHb6g-h.mjs";
2
+ function x({
3
3
  user: r = null,
4
4
  allowed: s = !0,
5
5
  children: e,
6
6
  getUser: t,
7
7
  isAuthenticated: i,
8
8
  hasRole: o,
9
- hasPermission: c,
10
- loginPath: n,
11
- forbiddenPath: u,
12
- defaultPath: m,
13
- callbackUrlParam: x,
14
- shouldAddCallbackUrl: A
9
+ hasPermission: c
15
10
  }) {
16
- return /* @__PURE__ */ a.jsx(
17
- h,
11
+ return /* @__PURE__ */ n.jsx(
12
+ u,
18
13
  {
19
14
  getUser: t ?? (() => r),
20
15
  isAuthenticated: i ?? (() => s),
21
16
  hasRole: o ?? (() => s),
22
17
  hasPermission: c ?? (() => s),
23
- loginPath: n,
24
- forbiddenPath: u,
25
- defaultPath: m,
26
- callbackUrlParam: x,
27
- shouldAddCallbackUrl: A,
28
18
  children: e
29
19
  }
30
20
  );
31
21
  }
32
22
  export {
33
- p as MockAccessProvider
23
+ x as MockAccessProvider
34
24
  };
package/dist/types.d.ts CHANGED
@@ -4,31 +4,6 @@ import { ReactNode } from 'react';
4
4
  * Access requirements consumed by React hooks and components in this package.
5
5
  */
6
6
  export type RouteProtection = CoreAccessConfig;
7
- /**
8
- * Navigation paths used when access-aware components need to redirect.
9
- */
10
- export type NavigationConfig = {
11
- /**
12
- * Redirect target for unauthenticated users.
13
- */
14
- loginPath?: string;
15
- /**
16
- * Redirect target when the user is authenticated but lacks access.
17
- */
18
- forbiddenPath?: string;
19
- /**
20
- * Redirect target for authenticated users visiting guest-only screens.
21
- */
22
- defaultPath?: string;
23
- /**
24
- * Query parameter name used to preserve the current location during login redirects.
25
- */
26
- callbackUrlParam?: string;
27
- /**
28
- * Decides whether the callback URL should be attached to an unauthenticated redirect.
29
- */
30
- shouldAddCallbackUrl?: () => boolean;
31
- };
32
7
  /**
33
8
  * Access context exposed by `useAccess()`.
34
9
  */
@@ -37,31 +12,11 @@ export type AccessContextValue<TUser = unknown> = {
37
12
  * Guard instance used to evaluate access rules.
38
13
  */
39
14
  guard: Guard<TUser>;
40
- /**
41
- * Redirect target for unauthenticated users.
42
- */
43
- loginPath: string;
44
- /**
45
- * Redirect target when the user is authenticated but forbidden.
46
- */
47
- forbiddenPath: string;
48
- /**
49
- * Redirect target for authenticated users on guest-only screens.
50
- */
51
- defaultPath: string;
52
- /**
53
- * Query parameter name used to preserve the current location during login redirects.
54
- */
55
- callbackUrlParam?: string;
56
- /**
57
- * Decides whether the callback URL should be attached to an unauthenticated redirect.
58
- */
59
- shouldAddCallbackUrl?: () => boolean;
60
15
  };
61
16
  /**
62
17
  * Props accepted by `AccessProvider`.
63
18
  */
64
- export type AccessProviderProps<TUser = unknown> = GuardOptions<TUser> & NavigationConfig & {
19
+ export type AccessProviderProps<TUser = unknown> = GuardOptions<TUser> & {
65
20
  /**
66
21
  * React subtree that consumes the access context.
67
22
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-protected/react",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "license": "MIT",
5
5
  "description": "React context and hooks for react-protected",
6
6
  "main": "./dist/index.cjs",
@@ -31,7 +31,7 @@
31
31
  "CHANGELOG.md"
32
32
  ],
33
33
  "dependencies": {
34
- "@react-protected/core": "0.2.0"
34
+ "@react-protected/core": "0.3.0"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "react": ">=18.0.0",
@@ -1,22 +0,0 @@
1
- "use strict";const R=require("react"),re=require("@react-protected/core");var y={exports:{}},_={};/**
2
- * @license React
3
- * react-jsx-runtime.production.js
4
- *
5
- * Copyright (c) Meta Platforms, Inc. and affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var D;function te(){if(D)return _;D=1;var u=Symbol.for("react.transitional.element"),d=Symbol.for("react.fragment");function c(l,a,s){var i=null;if(s!==void 0&&(i=""+s),a.key!==void 0&&(i=""+a.key),"key"in a){s={};for(var f in a)f!=="key"&&(s[f]=a[f])}else s=a;return a=s.ref,{$$typeof:u,type:l,key:i,ref:a!==void 0?a:null,props:s}}return _.Fragment=d,_.jsx=c,_.jsxs=c,_}var v={};/**
10
- * @license React
11
- * react-jsx-runtime.development.js
12
- *
13
- * Copyright (c) Meta Platforms, Inc. and affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- */var M;function ne(){return M||(M=1,process.env.NODE_ENV!=="production"&&function(){function u(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===Q?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case O:return"Fragment";case z:return"Profiler";case V:return"StrictMode";case X:return"Suspense";case B:return"SuspenseList";case Z:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case q:return"Portal";case U:return e.displayName||"Context";case G:return(e._context.displayName||"Context")+".Consumer";case J:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case H:return r=e.displayName||null,r!==null?r:u(e.type)||"Memo";case w:r=e._payload,e=e._init;try{return u(e(r))}catch{}}return null}function d(e){return""+e}function c(e){try{d(e);var r=!1}catch{r=!0}if(r){r=console;var t=r.error,n=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",n),d(e)}}function l(e){if(e===O)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===w)return"<...>";try{var r=u(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function a(){var e=S.A;return e===null?null:e.getOwner()}function s(){return Error("react-stack-top-frame")}function i(e){if(h.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function f(e,r){function t(){C||(C=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}function b(){var e=u(this.type);return Y[e]||(Y[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function p(e,r,t,n,k,P){var o=t.ref;return e={$$typeof:N,type:e,key:r,props:t,_owner:n},(o!==void 0?o:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:b}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:k}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:P}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function E(e,r,t,n,k,P){var o=r.children;if(o!==void 0)if(n)if(K(o)){for(n=0;n<o.length;n++)T(o[n]);Object.freeze&&Object.freeze(o)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else T(o);if(h.call(r,"key")){o=u(e);var m=Object.keys(r).filter(function(ee){return ee!=="key"});n=0<m.length?"{key: someKey, "+m.join(": ..., ")+": ...}":"{key: someKey}",F[o+n]||(m=0<m.length?"{"+m.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
- let props = %s;
19
- <%s {...props} />
20
- React keys must be passed directly to JSX without using spread:
21
- let props = %s;
22
- <%s key={someKey} {...props} />`,n,o,m,o),F[o+n]=!0)}if(o=null,t!==void 0&&(c(t),o=""+t),i(r)&&(c(r.key),o=""+r.key),"key"in r){t={};for(var j in r)j!=="key"&&(t[j]=r[j])}else t=r;return o&&f(t,typeof e=="function"?e.displayName||e.name||"Unknown":e),p(e,o,t,a(),k,P)}function T(e){g(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===w&&(e._payload.status==="fulfilled"?g(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function g(e){return typeof e=="object"&&e!==null&&e.$$typeof===N}var A=R,N=Symbol.for("react.transitional.element"),q=Symbol.for("react.portal"),O=Symbol.for("react.fragment"),V=Symbol.for("react.strict_mode"),z=Symbol.for("react.profiler"),G=Symbol.for("react.consumer"),U=Symbol.for("react.context"),J=Symbol.for("react.forward_ref"),X=Symbol.for("react.suspense"),B=Symbol.for("react.suspense_list"),H=Symbol.for("react.memo"),w=Symbol.for("react.lazy"),Z=Symbol.for("react.activity"),Q=Symbol.for("react.client.reference"),S=A.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,h=Object.prototype.hasOwnProperty,K=Array.isArray,x=console.createTask?console.createTask:function(){return null};A={react_stack_bottom_frame:function(e){return e()}};var C,Y={},$=A.react_stack_bottom_frame.bind(A,s)(),I=x(l(s)),F={};v.Fragment=O,v.jsx=function(e,r,t){var n=1e4>S.recentlyCreatedOwnerStacks++;return E(e,r,t,!1,n?Error("react-stack-top-frame"):$,n?x(l(e)):I)},v.jsxs=function(e,r,t){var n=1e4>S.recentlyCreatedOwnerStacks++;return E(e,r,t,!0,n?Error("react-stack-top-frame"):$,n?x(l(e)):I)}}()),v}process.env.NODE_ENV==="production"?y.exports=te():y.exports=ne();var L=y.exports;const W=R.createContext(null);function oe({children:u,loginPath:d="/login",forbiddenPath:c="/403",defaultPath:l="/",callbackUrlParam:a,shouldAddCallbackUrl:s,getUser:i,isAuthenticated:f,hasRole:b,hasPermission:p}){const E=R.useMemo(()=>re.createGuard({getUser:i,isAuthenticated:f,hasRole:b,hasPermission:p}),[i,f,b,p]),T=R.useMemo(()=>({guard:E,loginPath:d,forbiddenPath:c,defaultPath:l,callbackUrlParam:a,shouldAddCallbackUrl:s}),[E,d,c,l,a,s]);return L.jsx(W.Provider,{value:T,children:u})}function ae(){const u=R.useContext(W);if(!u)throw new Error("useAccess must be used within <AccessProvider>");return u}exports.AccessProvider=oe;exports.jsxRuntimeExports=L;exports.useAccess=ae;