@react-protected/react-router 0.1.1-beta.1 → 0.2.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const K=require("react"),j=require("@react-protected/react"),b=require("react-router-dom"),ae=require("@react-protected/core");var q={exports:{}},N={};/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("react"),N=require("@react-protected/react"),v=require("react-router-dom"),se=require("@react-protected/core");var z={exports:{}},Y={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.js
4
4
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var Z;function se(){if(Z)return N;Z=1;var r=Symbol.for("react.transitional.element"),n=Symbol.for("react.fragment");function s(u,a,o){var i=null;if(o!==void 0&&(i=""+o),a.key!==void 0&&(i=""+a.key),"key"in a){o={};for(var m in a)m!=="key"&&(o[m]=a[m])}else o=a;return a=o.ref,{$$typeof:r,type:u,key:i,ref:a!==void 0?a:null,props:o}}return N.Fragment=n,N.jsx=s,N.jsxs=s,N}var $={};/**
9
+ */var K;function ue(){if(K)return Y;K=1;var r=Symbol.for("react.transitional.element"),a=Symbol.for("react.fragment");function n(s,u,o){var i=null;if(o!==void 0&&(i=""+o),u.key!==void 0&&(i=""+u.key),"key"in u){o={};for(var m in u)m!=="key"&&(o[m]=u[m])}else o=u;return u=o.ref,{$$typeof:r,type:s,key:i,ref:u!==void 0?u:null,props:o}}return Y.Fragment=a,Y.jsx=n,Y.jsxs=n,Y}var x={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,9 +14,9 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var Q;function ue(){return Q||(Q=1,process.env.NODE_ENV!=="production"&&function(){function r(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===te?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case g:return"Fragment";case y:return"Profiler";case T:return"StrictMode";case x:return"Suspense";case W:return"SuspenseList";case re: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 k:return"Portal";case U:return e.displayName||"Context";case C:return(e._context.displayName||"Context")+".Consumer";case w:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case A:return t=e.displayName||null,t!==null?t:r(e.type)||"Memo";case S:t=e._payload,e=e._init;try{return r(e(t))}catch{}}return null}function n(e){return""+e}function s(e){try{n(e);var t=!1}catch{t=!0}if(t){t=console;var c=t.error,l=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return c.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",l),n(e)}}function u(e){if(e===g)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===S)return"<...>";try{var t=r(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function a(){var e=L.A;return e===null?null:e.getOwner()}function o(){return Error("react-stack-top-frame")}function i(e){if(z.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function m(e,t){function c(){V||(V=!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)",t))}c.isReactWarning=!0,Object.defineProperty(e,"key",{get:c,configurable:!0})}function P(){var e=r(this.type);return H[e]||(H[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,t,c,l,Y,F){var f=c.ref;return e={$$typeof:_,type:e,key:t,props:c,_owner:l},(f!==void 0?f:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:P}):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:Y}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:F}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function E(e,t,c,l,Y,F){var f=t.children;if(f!==void 0)if(l)if(ne(f)){for(l=0;l<f.length;l++)h(f[l]);Object.freeze&&Object.freeze(f)}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 h(f);if(z.call(t,"key")){f=r(e);var O=Object.keys(t).filter(function(oe){return oe!=="key"});l=0<O.length?"{key: someKey, "+O.join(": ..., ")+": ...}":"{key: someKey}",X[f+l]||(O=0<O.length?"{"+O.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
17
+ */var ee;function ce(){return ee||(ee=1,process.env.NODE_ENV!=="production"&&function(){function r(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===h?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case A:return"Fragment";case O:return"Profiler";case I:return"StrictMode";case L:return"Suspense";case $:return"SuspenseList";case k: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 T:return"Portal";case C:return e.displayName||"Context";case j:return(e._context.displayName||"Context")+".Consumer";case F:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case D:return t=e.displayName||null,t!==null?t:r(e.type)||"Memo";case y:t=e._payload,e=e._init;try{return r(e(t))}catch{}}return null}function a(e){return""+e}function n(e){try{a(e);var t=!1}catch{t=!0}if(t){t=console;var c=t.error,l=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return c.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",l),a(e)}}function s(e){if(e===A)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===y)return"<...>";try{var t=r(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function u(){var e=U.A;return e===null?null:e.getOwner()}function o(){return Error("react-stack-top-frame")}function i(e){if(H.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function m(e,t){function c(){J||(J=!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)",t))}c.isReactWarning=!0,Object.defineProperty(e,"key",{get:c,configurable:!0})}function P(){var e=r(this.type);return B[e]||(B[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 R(e,t,c,l,G,q){var f=c.ref;return e={$$typeof:_,type:e,key:t,props:c,_owner:l},(f!==void 0?f:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:P}):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:G}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:q}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,t,c,l,G,q){var f=t.children;if(f!==void 0)if(l)if(oe(f)){for(l=0;l<f.length;l++)E(f[l]);Object.freeze&&Object.freeze(f)}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 E(f);if(H.call(t,"key")){f=r(e);var w=Object.keys(t).filter(function(ae){return ae!=="key"});l=0<w.length?"{key: someKey, "+w.join(": ..., ")+": ...}":"{key: someKey}",Q[f+l]||(w=0<w.length?"{"+w.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
18
  let props = %s;
19
19
  <%s {...props} />
20
20
  React keys must be passed directly to JSX without using spread:
21
21
  let props = %s;
22
- <%s key={someKey} {...props} />`,l,f,O,f),X[f+l]=!0)}if(f=null,c!==void 0&&(s(c),f=""+c),i(t)&&(s(t.key),f=""+t.key),"key"in t){c={};for(var M in t)M!=="key"&&(c[M]=t[M])}else c=t;return f&&m(c,typeof e=="function"?e.displayName||e.name||"Unknown":e),p(e,f,c,a(),Y,F)}function h(e){R(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===S&&(e._payload.status==="fulfilled"?R(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function R(e){return typeof e=="object"&&e!==null&&e.$$typeof===_}var d=K,_=Symbol.for("react.transitional.element"),k=Symbol.for("react.portal"),g=Symbol.for("react.fragment"),T=Symbol.for("react.strict_mode"),y=Symbol.for("react.profiler"),C=Symbol.for("react.consumer"),U=Symbol.for("react.context"),w=Symbol.for("react.forward_ref"),x=Symbol.for("react.suspense"),W=Symbol.for("react.suspense_list"),A=Symbol.for("react.memo"),S=Symbol.for("react.lazy"),re=Symbol.for("react.activity"),te=Symbol.for("react.client.reference"),L=d.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,z=Object.prototype.hasOwnProperty,ne=Array.isArray,D=console.createTask?console.createTask:function(){return null};d={react_stack_bottom_frame:function(e){return e()}};var V,H={},J=d.react_stack_bottom_frame.bind(d,o)(),B=D(u(o)),X={};$.Fragment=g,$.jsx=function(e,t,c){var l=1e4>L.recentlyCreatedOwnerStacks++;return E(e,t,c,!1,l?Error("react-stack-top-frame"):J,l?D(u(e)):B)},$.jsxs=function(e,t,c){var l=1e4>L.recentlyCreatedOwnerStacks++;return E(e,t,c,!0,l?Error("react-stack-top-frame"):J,l?D(u(e)):B)}}()),$}process.env.NODE_ENV==="production"?q.exports=se():q.exports=ue();var v=q.exports;function ce(r){const{guard:n}=j.useAccess();return n.check(r)}const ie=K.memo(({access:r,roles:n,permissions:s,meta:u,children:a})=>{const{guard:o,loginPath:i,forbiddenPath:m,defaultPath:P,callbackUrlParam:p}=j.useAccess(),E=b.useLocation();if(r==="guest-only"){const R=o.options.getUser();return o.options.isAuthenticated(R)?v.jsx(b.Navigate,{to:P,replace:!0}):a??v.jsx(b.Outlet,{})}const h=o.check({access:r,roles:n,permissions:s,meta:u});if(!h.allowed){if(h.reason==="unauthenticated"){const R=`${E.pathname}${E.search}${E.hash}`,d=p?`${i}?${p}=${encodeURIComponent(R)}`:i;return v.jsx(b.Navigate,{to:d,replace:!0})}return v.jsx(b.Navigate,{to:m,replace:!0})}return a??v.jsx(b.Outlet,{})});function ee(r,n,s,u,a,o){return r==="unauthenticated"?o?`${s}?${o}=${encodeURIComponent(n)}`:s:r==="forbidden"?u:a}function le({access:r,roles:n,permissions:s,meta:u,guard:a,routeElement:o,RouteComponent:i,loginPath:m,forbiddenPath:P,defaultPath:p,callbackUrlParam:E}){const h=b.useLocation(),R=`${h.pathname}${h.search}${h.hash}`;if(r==="guest-only"){const _=a.options.getUser();return a.options.isAuthenticated(_)?v.jsx(b.Navigate,{to:p,replace:!0}):i?v.jsx(i,{}):o??v.jsx(b.Outlet,{})}const d=a.check({access:r,roles:n,permissions:s,meta:u});if(!d.allowed){const _=ee(d.reason,R,m,P,p,E);return v.jsx(b.Navigate,{to:_,replace:!0})}return i?v.jsx(i,{}):o??v.jsx(b.Outlet,{})}function G(r,n,s){return v.jsx(le,{access:r.protection.access,roles:r.protection.roles,permissions:r.protection.permissions,meta:r.protection.meta,guard:r.guard,routeElement:n,RouteComponent:s??null,loginPath:r.loginPath,forbiddenPath:r.forbiddenPath,defaultPath:r.defaultPath,callbackUrlParam:r.callbackUrlParam})}function I(r,n){return r===void 0||typeof r=="boolean"?r:s=>{const u=new URL(s.request.url),a=`${u.pathname}${u.search}`;if(n.protection.access==="guest-only"){const i=n.guard.options.getUser();return n.guard.options.isAuthenticated(i)?b.redirect(n.defaultPath):r(s)}const o=n.guard.check(n.protection);if(!o.allowed){const i=ee(o.reason,a,n.loginPath,n.forbiddenPath,n.defaultPath,n.callbackUrlParam);return b.redirect(i)}return r(s)}}async function fe(r){const n=await Promise.all(Object.entries(r).map(async([s,u])=>[s,await(u==null?void 0:u())]));return Object.fromEntries(n)}function de(r,n){if(!r)return;const s=typeof r=="function"?r:()=>fe(r);return async()=>{const u=await s();if(!u)return n.hasStaticUi?{}:{element:G(n)};const{element:a,Component:o,loader:i,action:m,...P}=u,p={...P,loader:I(i,n),action:I(m,n)};return n.hasStaticUi||(p.element=G(n,a,o??null)),p}}function me(r,n,s){const{loginPath:u="/login",forbiddenPath:a="/403",defaultPath:o="/",callbackUrlParam:i,...m}=n,P=ae.createGuard(m),p=E=>E.map(h=>{const{access:R,roles:d,permissions:_,meta:k,children:g,element:T,Component:y,loader:C,action:U,lazy:w,...x}=h;if(!(R!==void 0||!!(d!=null&&d.length)||!!(_!=null&&_.length)||k!==void 0))return{...x,element:T,Component:y,loader:C,action:U,lazy:w,children:g?p(g):void 0};const A={guard:P,protection:{access:R,roles:d,permissions:_,meta:k},hasStaticUi:T!=null||y!=null,loginPath:u,forbiddenPath:a,defaultPath:o,callbackUrlParam:i},S=A.hasStaticUi||!w?G(A,T,y??null):void 0;return{...x,element:S,Component:void 0,loader:I(C,A),action:I(U,A),lazy:de(w,A),children:g?p(g):void 0}});return b.createBrowserRouter(p(r),s)}Object.defineProperty(exports,"AccessProvider",{enumerable:!0,get:()=>j.AccessProvider});Object.defineProperty(exports,"HasAccess",{enumerable:!0,get:()=>j.HasAccess});Object.defineProperty(exports,"useAccess",{enumerable:!0,get:()=>j.useAccess});Object.defineProperty(exports,"useHasAccess",{enumerable:!0,get:()=>j.useHasAccess});exports.AccessRoute=ie;exports.createAccessRouter=me;exports.useRouteAccess=ce;
22
+ <%s key={someKey} {...props} />`,l,f,w,f),Q[f+l]=!0)}if(f=null,c!==void 0&&(n(c),f=""+c),i(t)&&(n(t.key),f=""+t.key),"key"in t){c={};for(var W in t)W!=="key"&&(c[W]=t[W])}else c=t;return f&&m(c,typeof e=="function"?e.displayName||e.name||"Unknown":e),R(e,f,c,u(),G,q)}function E(e){p(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===y&&(e._payload.status==="fulfilled"?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e=="object"&&e!==null&&e.$$typeof===_}var b=te,_=Symbol.for("react.transitional.element"),T=Symbol.for("react.portal"),A=Symbol.for("react.fragment"),I=Symbol.for("react.strict_mode"),O=Symbol.for("react.profiler"),j=Symbol.for("react.consumer"),C=Symbol.for("react.context"),F=Symbol.for("react.forward_ref"),L=Symbol.for("react.suspense"),$=Symbol.for("react.suspense_list"),D=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),k=Symbol.for("react.activity"),h=Symbol.for("react.client.reference"),U=b.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,H=Object.prototype.hasOwnProperty,oe=Array.isArray,M=console.createTask?console.createTask:function(){return null};b={react_stack_bottom_frame:function(e){return e()}};var J,B={},X=b.react_stack_bottom_frame.bind(b,o)(),Z=M(s(o)),Q={};x.Fragment=A,x.jsx=function(e,t,c){var l=1e4>U.recentlyCreatedOwnerStacks++;return d(e,t,c,!1,l?Error("react-stack-top-frame"):X,l?M(s(e)):Z)},x.jsxs=function(e,t,c){var l=1e4>U.recentlyCreatedOwnerStacks++;return d(e,t,c,!0,l?Error("react-stack-top-frame"):X,l?M(s(e)):Z)}}()),x}process.env.NODE_ENV==="production"?z.exports=ue():z.exports=ce();var g=z.exports;function ie(r){const{guard:a}=N.useAccess();return a.check(r)}const le=te.memo(({access:r,roles:a,permissions:n,meta:s,children:u})=>{const{guard:o,loginPath:i,forbiddenPath:m,defaultPath:P,callbackUrlParam:R,shouldAddCallbackUrl:d}=N.useAccess(),E=v.useLocation();if(r==="guest-only"){const b=o.options.getUser();return o.options.isAuthenticated(b)?g.jsx(v.Navigate,{to:P,replace:!0}):u??g.jsx(v.Outlet,{})}const p=o.check({access:r,roles:a,permissions:n,meta:s});if(!p.allowed){if(p.reason==="unauthenticated"){const b=`${E.pathname}${E.search}${E.hash}`,T=R&&((d==null?void 0:d())??!0)?`${i}?${R}=${encodeURIComponent(b)}`:i;return g.jsx(v.Navigate,{to:T,replace:!0})}return g.jsx(v.Navigate,{to:m,replace:!0})}return u??g.jsx(v.Outlet,{})});function fe(r,a,n,s,u,o,i){return r==="unauthenticated"?o&&((i==null?void 0:i())??!0)?`${n}?${o}=${encodeURIComponent(a)}`:n:r==="forbidden"?s:u}function ne(r,a){if(r.protection.access==="guest-only"){const s=r.guard.options.getUser();return r.guard.options.isAuthenticated(s)?r.defaultPath:null}const n=r.guard.check(r.protection);return n.allowed?null:fe(n.reason,a,r.loginPath,r.forbiddenPath,r.defaultPath,r.callbackUrlParam,r.shouldAddCallbackUrl)}function de(r,a){return r.reduce((n,s)=>n??ne(s,a),null)}function me({access:r,roles:a,permissions:n,meta:s,guard:u,routeElement:o,RouteComponent:i,loginPath:m,forbiddenPath:P,defaultPath:R,callbackUrlParam:d,shouldAddCallbackUrl:E}){const p=v.useLocation(),b=`${p.pathname}${p.search}${p.hash}`,_=ne({guard:u,protection:{access:r,roles:a,permissions:n,meta:s},loginPath:m,forbiddenPath:P,defaultPath:R,callbackUrlParam:d,shouldAddCallbackUrl:E},b);return _?g.jsx(v.Navigate,{to:_,replace:!0}):i?g.jsx(i,{}):o??g.jsx(v.Outlet,{})}function V(r,a,n){return g.jsx(me,{access:r.protection.access,roles:r.protection.roles,permissions:r.protection.permissions,meta:r.protection.meta,guard:r.guard,routeElement:a,RouteComponent:n??null,loginPath:r.loginPath,forbiddenPath:r.forbiddenPath,defaultPath:r.defaultPath,callbackUrlParam:r.callbackUrlParam,shouldAddCallbackUrl:r.shouldAddCallbackUrl})}function S(r,a){return r===void 0||typeof r=="boolean"||a.length===0?r:n=>{const s=new URL(n.request.url),u=`${s.pathname}${s.search}`,o=de(a,u);return o?v.redirect(o):r(n)}}async function pe(r){const a=await Promise.all(Object.entries(r).map(async([n,s])=>[n,await(s==null?void 0:s())]));return Object.fromEntries(a)}function re(r,a,n){if(!r)return;const s=typeof r=="function"?r:()=>pe(r);return async()=>{const u=await s();if(!u)return n?n.hasStaticUi?{}:{element:V(n)}:{};const{element:o,Component:i,loader:m,action:P,...R}=u,d={...R,loader:S(m,a),action:S(P,a)};return n?(n.hasStaticUi||(d.element=V(n,o,i??null)),d):(d.element=o,d.Component=i,d)}}function be(r,a,n){const{loginPath:s="/login",forbiddenPath:u="/403",defaultPath:o="/",callbackUrlParam:i,shouldAddCallbackUrl:m,...P}=a,R=se.createGuard(P),d=(E,p=[])=>E.map(b=>{const{access:_,roles:T,permissions:A,meta:I,children:O,element:j,Component:C,loader:F,action:L,lazy:$,...D}=b,y=_!==void 0||!!(T!=null&&T.length)||!!(A!=null&&A.length)||I!==void 0,k=y?{guard:R,protection:{access:_,roles:T,permissions:A,meta:I},hasStaticUi:j!=null||C!=null,loginPath:s,forbiddenPath:u,defaultPath:o,callbackUrlParam:i,shouldAddCallbackUrl:m}:void 0,h=k?[...p,k]:p;if(!y)return{...D,element:j,Component:C,loader:S(F,h),action:S(L,h),lazy:re($,h),children:O?d(O,h):void 0};if(!k)throw new Error("Guard context must exist for guarded routes");const U=k.hasStaticUi||!$?V(k,j,C??null):void 0;return{...D,element:U,Component:void 0,loader:S(F,h),action:S(L,h),lazy:re($,h,k),children:O?d(O,h):void 0}});return v.createBrowserRouter(d(r),n)}Object.defineProperty(exports,"AccessProvider",{enumerable:!0,get:()=>N.AccessProvider});Object.defineProperty(exports,"HasAccess",{enumerable:!0,get:()=>N.HasAccess});Object.defineProperty(exports,"useAccess",{enumerable:!0,get:()=>N.useAccess});Object.defineProperty(exports,"useHasAccess",{enumerable:!0,get:()=>N.useHasAccess});exports.AccessRoute=le;exports.createAccessRouter=be;exports.useRouteAccess=ie;
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import ue, { memo as ce } from "react";
2
- import { useAccess as ee } from "@react-protected/react";
3
- import { AccessProvider as ke, HasAccess as je, useAccess as we, useHasAccess as Oe } from "@react-protected/react";
4
- import { useLocation as re, Navigate as $, Outlet as Y, createBrowserRouter as ie, redirect as Z } from "react-router-dom";
5
- import { createGuard as le } from "@react-protected/core";
6
- var M = { exports: {} }, y = {};
2
+ import { useAccess as te } from "@react-protected/react";
3
+ import { AccessProvider as Oe, HasAccess as je, useAccess as ye, useHasAccess as Se } from "@react-protected/react";
4
+ import { useLocation as ne, Navigate as D, Outlet as z, createBrowserRouter as ie, redirect as le } from "react-router-dom";
5
+ import { createGuard as fe } from "@react-protected/core";
6
+ var V = { exports: {} }, N = {};
7
7
  /**
8
8
  * @license React
9
9
  * react-jsx-runtime.production.js
@@ -13,29 +13,29 @@ var M = { exports: {} }, y = {};
13
13
  * This source code is licensed under the MIT license found in the
14
14
  * LICENSE file in the root directory of this source tree.
15
15
  */
16
- var Q;
17
- function fe() {
18
- if (Q) return y;
19
- Q = 1;
20
- var r = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
21
- function s(u, a, o) {
16
+ var K;
17
+ function de() {
18
+ if (K) return N;
19
+ K = 1;
20
+ var r = Symbol.for("react.transitional.element"), a = Symbol.for("react.fragment");
21
+ function n(s, u, o) {
22
22
  var i = null;
23
- if (o !== void 0 && (i = "" + o), a.key !== void 0 && (i = "" + a.key), "key" in a) {
23
+ if (o !== void 0 && (i = "" + o), u.key !== void 0 && (i = "" + u.key), "key" in u) {
24
24
  o = {};
25
- for (var m in a)
26
- m !== "key" && (o[m] = a[m]);
27
- } else o = a;
28
- return a = o.ref, {
25
+ for (var m in u)
26
+ m !== "key" && (o[m] = u[m]);
27
+ } else o = u;
28
+ return u = o.ref, {
29
29
  $$typeof: r,
30
- type: u,
30
+ type: s,
31
31
  key: i,
32
- ref: a !== void 0 ? a : null,
32
+ ref: u !== void 0 ? u : null,
33
33
  props: o
34
34
  };
35
35
  }
36
- return y.Fragment = n, y.jsx = s, y.jsxs = s, y;
36
+ return N.Fragment = a, N.jsx = n, N.jsxs = n, N;
37
37
  }
38
- var S = {};
38
+ var U = {};
39
39
  /**
40
40
  * @license React
41
41
  * react-jsx-runtime.development.js
@@ -45,42 +45,42 @@ var S = {};
45
45
  * This source code is licensed under the MIT license found in the
46
46
  * LICENSE file in the root directory of this source tree.
47
47
  */
48
- var K;
49
- function de() {
50
- return K || (K = 1, process.env.NODE_ENV !== "production" && function() {
48
+ var ee;
49
+ function me() {
50
+ return ee || (ee = 1, process.env.NODE_ENV !== "production" && function() {
51
51
  function r(e) {
52
52
  if (e == null) return null;
53
53
  if (typeof e == "function")
54
- return e.$$typeof === oe ? null : e.displayName || e.name || null;
54
+ return e.$$typeof === _ ? null : e.displayName || e.name || null;
55
55
  if (typeof e == "string") return e;
56
56
  switch (e) {
57
- case P:
57
+ case g:
58
58
  return "Fragment";
59
- case j:
60
- return "Profiler";
61
59
  case A:
62
- return "StrictMode";
60
+ return "Profiler";
63
61
  case x:
62
+ return "StrictMode";
63
+ case I:
64
64
  return "Suspense";
65
- case z:
65
+ case C:
66
66
  return "SuspenseList";
67
- case ne:
67
+ case k:
68
68
  return "Activity";
69
69
  }
70
70
  if (typeof e == "object")
71
71
  switch (typeof e.tag == "number" && console.error(
72
72
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
73
73
  ), e.$$typeof) {
74
- case k:
74
+ case T:
75
75
  return "Portal";
76
- case C:
76
+ case S:
77
77
  return e.displayName || "Context";
78
- case N:
79
- return (e._context.displayName || "Context") + ".Consumer";
80
78
  case w:
79
+ return (e._context.displayName || "Context") + ".Consumer";
80
+ case Y:
81
81
  var t = e.render;
82
82
  return e = e.displayName, e || (e = t.displayName || t.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
83
- case T:
83
+ case F:
84
84
  return t = e.displayName || null, t !== null ? t : r(e.type) || "Memo";
85
85
  case O:
86
86
  t = e._payload, e = e._init;
@@ -91,12 +91,12 @@ function de() {
91
91
  }
92
92
  return null;
93
93
  }
94
- function n(e) {
94
+ function a(e) {
95
95
  return "" + e;
96
96
  }
97
- function s(e) {
97
+ function n(e) {
98
98
  try {
99
- n(e);
99
+ a(e);
100
100
  var t = !1;
101
101
  } catch {
102
102
  t = !0;
@@ -108,11 +108,11 @@ function de() {
108
108
  t,
109
109
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
110
110
  l
111
- ), n(e);
111
+ ), a(e);
112
112
  }
113
113
  }
114
- function u(e) {
115
- if (e === P) return "<>";
114
+ function s(e) {
115
+ if (e === g) return "<>";
116
116
  if (typeof e == "object" && e !== null && e.$$typeof === O)
117
117
  return "<...>";
118
118
  try {
@@ -122,15 +122,15 @@ function de() {
122
122
  return "<...>";
123
123
  }
124
124
  }
125
- function a() {
126
- var e = F.A;
125
+ function u() {
126
+ var e = $.A;
127
127
  return e === null ? null : e.getOwner();
128
128
  }
129
129
  function o() {
130
130
  return Error("react-stack-top-frame");
131
131
  }
132
132
  function i(e) {
133
- if (V.call(e, "key")) {
133
+ if (J.call(e, "key")) {
134
134
  var t = Object.getOwnPropertyDescriptor(e, "key").get;
135
135
  if (t && t.isReactWarning) return !1;
136
136
  }
@@ -138,7 +138,7 @@ function de() {
138
138
  }
139
139
  function m(e, t) {
140
140
  function c() {
141
- q || (q = !0, console.error(
141
+ B || (B = !0, console.error(
142
142
  "%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)",
143
143
  t
144
144
  ));
@@ -148,23 +148,23 @@ function de() {
148
148
  configurable: !0
149
149
  });
150
150
  }
151
- function R() {
151
+ function h() {
152
152
  var e = r(this.type);
153
- return J[e] || (J[e] = !0, console.error(
153
+ return X[e] || (X[e] = !0, console.error(
154
154
  "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."
155
155
  )), e = this.props.ref, e !== void 0 ? e : null;
156
156
  }
157
- function p(e, t, c, l, U, D) {
157
+ function E(e, t, c, l, L, M) {
158
158
  var f = c.ref;
159
159
  return e = {
160
- $$typeof: _,
160
+ $$typeof: R,
161
161
  type: e,
162
162
  key: t,
163
163
  props: c,
164
164
  _owner: l
165
165
  }, (f !== void 0 ? f : null) !== null ? Object.defineProperty(e, "ref", {
166
166
  enumerable: !1,
167
- get: R
167
+ get: h
168
168
  }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
169
169
  configurable: !1,
170
170
  enumerable: !1,
@@ -179,33 +179,33 @@ function de() {
179
179
  configurable: !1,
180
180
  enumerable: !1,
181
181
  writable: !0,
182
- value: U
182
+ value: L
183
183
  }), Object.defineProperty(e, "_debugTask", {
184
184
  configurable: !1,
185
185
  enumerable: !1,
186
186
  writable: !0,
187
- value: D
187
+ value: M
188
188
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
189
189
  }
190
- function E(e, t, c, l, U, D) {
190
+ function d(e, t, c, l, L, M) {
191
191
  var f = t.children;
192
192
  if (f !== void 0)
193
193
  if (l)
194
194
  if (ae(f)) {
195
195
  for (l = 0; l < f.length; l++)
196
- b(f[l]);
196
+ v(f[l]);
197
197
  Object.freeze && Object.freeze(f);
198
198
  } else
199
199
  console.error(
200
200
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
201
201
  );
202
- else b(f);
203
- if (V.call(t, "key")) {
202
+ else v(f);
203
+ if (J.call(t, "key")) {
204
204
  f = r(e);
205
- var g = Object.keys(t).filter(function(se) {
205
+ var j = Object.keys(t).filter(function(se) {
206
206
  return se !== "key";
207
207
  });
208
- l = 0 < g.length ? "{key: someKey, " + g.join(": ..., ") + ": ...}" : "{key: someKey}", H[f + l] || (g = 0 < g.length ? "{" + g.join(": ..., ") + ": ...}" : "{}", console.error(
208
+ l = 0 < j.length ? "{key: someKey, " + j.join(": ..., ") + ": ...}" : "{key: someKey}", Q[f + l] || (j = 0 < j.length ? "{" + j.join(": ..., ") + ": ...}" : "{}", console.error(
209
209
  `A props object containing a "key" prop is being spread into JSX:
210
210
  let props = %s;
211
211
  <%s {...props} />
@@ -214,250 +214,257 @@ React keys must be passed directly to JSX without using spread:
214
214
  <%s key={someKey} {...props} />`,
215
215
  l,
216
216
  f,
217
- g,
217
+ j,
218
218
  f
219
- ), H[f + l] = !0);
219
+ ), Q[f + l] = !0);
220
220
  }
221
- if (f = null, c !== void 0 && (s(c), f = "" + c), i(t) && (s(t.key), f = "" + t.key), "key" in t) {
221
+ if (f = null, c !== void 0 && (n(c), f = "" + c), i(t) && (n(t.key), f = "" + t.key), "key" in t) {
222
222
  c = {};
223
- for (var G in t)
224
- G !== "key" && (c[G] = t[G]);
223
+ for (var W in t)
224
+ W !== "key" && (c[W] = t[W]);
225
225
  } else c = t;
226
226
  return f && m(
227
227
  c,
228
228
  typeof e == "function" ? e.displayName || e.name || "Unknown" : e
229
- ), p(
229
+ ), E(
230
230
  e,
231
231
  f,
232
232
  c,
233
- a(),
234
- U,
235
- D
233
+ u(),
234
+ L,
235
+ M
236
236
  );
237
237
  }
238
- function b(e) {
239
- v(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === O && (e._payload.status === "fulfilled" ? v(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
240
- }
241
238
  function v(e) {
242
- return typeof e == "object" && e !== null && e.$$typeof === _;
239
+ 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));
243
240
  }
244
- var d = ue, _ = Symbol.for("react.transitional.element"), k = Symbol.for("react.portal"), P = Symbol.for("react.fragment"), A = Symbol.for("react.strict_mode"), j = Symbol.for("react.profiler"), N = Symbol.for("react.consumer"), C = Symbol.for("react.context"), w = Symbol.for("react.forward_ref"), x = Symbol.for("react.suspense"), z = Symbol.for("react.suspense_list"), T = Symbol.for("react.memo"), O = Symbol.for("react.lazy"), ne = Symbol.for("react.activity"), oe = Symbol.for("react.client.reference"), F = d.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, V = Object.prototype.hasOwnProperty, ae = Array.isArray, L = console.createTask ? console.createTask : function() {
241
+ function p(e) {
242
+ return typeof e == "object" && e !== null && e.$$typeof === R;
243
+ }
244
+ var b = ue, R = Symbol.for("react.transitional.element"), T = Symbol.for("react.portal"), g = Symbol.for("react.fragment"), x = Symbol.for("react.strict_mode"), A = Symbol.for("react.profiler"), w = Symbol.for("react.consumer"), S = Symbol.for("react.context"), Y = Symbol.for("react.forward_ref"), I = Symbol.for("react.suspense"), C = Symbol.for("react.suspense_list"), F = Symbol.for("react.memo"), O = Symbol.for("react.lazy"), k = Symbol.for("react.activity"), _ = Symbol.for("react.client.reference"), $ = b.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, J = Object.prototype.hasOwnProperty, ae = Array.isArray, G = console.createTask ? console.createTask : function() {
245
245
  return null;
246
246
  };
247
- d = {
247
+ b = {
248
248
  react_stack_bottom_frame: function(e) {
249
249
  return e();
250
250
  }
251
251
  };
252
- var q, J = {}, B = d.react_stack_bottom_frame.bind(
253
- d,
252
+ var B, X = {}, H = b.react_stack_bottom_frame.bind(
253
+ b,
254
254
  o
255
- )(), X = L(u(o)), H = {};
256
- S.Fragment = P, S.jsx = function(e, t, c) {
257
- var l = 1e4 > F.recentlyCreatedOwnerStacks++;
258
- return E(
255
+ )(), Z = G(s(o)), Q = {};
256
+ U.Fragment = g, U.jsx = function(e, t, c) {
257
+ var l = 1e4 > $.recentlyCreatedOwnerStacks++;
258
+ return d(
259
259
  e,
260
260
  t,
261
261
  c,
262
262
  !1,
263
- l ? Error("react-stack-top-frame") : B,
264
- l ? L(u(e)) : X
263
+ l ? Error("react-stack-top-frame") : H,
264
+ l ? G(s(e)) : Z
265
265
  );
266
- }, S.jsxs = function(e, t, c) {
267
- var l = 1e4 > F.recentlyCreatedOwnerStacks++;
268
- return E(
266
+ }, U.jsxs = function(e, t, c) {
267
+ var l = 1e4 > $.recentlyCreatedOwnerStacks++;
268
+ return d(
269
269
  e,
270
270
  t,
271
271
  c,
272
272
  !0,
273
- l ? Error("react-stack-top-frame") : B,
274
- l ? L(u(e)) : X
273
+ l ? Error("react-stack-top-frame") : H,
274
+ l ? G(s(e)) : Z
275
275
  );
276
276
  };
277
- }()), S;
277
+ }()), U;
278
278
  }
279
- process.env.NODE_ENV === "production" ? M.exports = fe() : M.exports = de();
280
- var h = M.exports;
281
- function Re(r) {
282
- const { guard: n } = ee();
283
- return n.check(r);
279
+ process.env.NODE_ENV === "production" ? V.exports = de() : V.exports = me();
280
+ var P = V.exports;
281
+ function Te(r) {
282
+ const { guard: a } = te();
283
+ return a.check(r);
284
284
  }
285
- const Pe = ce(({
285
+ const ge = ce(({
286
286
  access: r,
287
- roles: n,
288
- permissions: s,
289
- meta: u,
290
- children: a
287
+ roles: a,
288
+ permissions: n,
289
+ meta: s,
290
+ children: u
291
291
  }) => {
292
- const { guard: o, loginPath: i, forbiddenPath: m, defaultPath: R, callbackUrlParam: p } = ee(), E = re();
292
+ const { guard: o, loginPath: i, forbiddenPath: m, defaultPath: h, callbackUrlParam: E, shouldAddCallbackUrl: d } = te(), v = ne();
293
293
  if (r === "guest-only") {
294
- const v = o.options.getUser();
295
- return o.options.isAuthenticated(v) ? /* @__PURE__ */ h.jsx($, { to: R, replace: !0 }) : a ?? /* @__PURE__ */ h.jsx(Y, {});
294
+ const b = o.options.getUser();
295
+ return o.options.isAuthenticated(b) ? /* @__PURE__ */ P.jsx(D, { to: h, replace: !0 }) : u ?? /* @__PURE__ */ P.jsx(z, {});
296
296
  }
297
- const b = o.check({ access: r, roles: n, permissions: s, meta: u });
298
- if (!b.allowed) {
299
- if (b.reason === "unauthenticated") {
300
- const v = `${E.pathname}${E.search}${E.hash}`, d = p ? `${i}?${p}=${encodeURIComponent(v)}` : i;
301
- return /* @__PURE__ */ h.jsx($, { to: d, replace: !0 });
297
+ const p = o.check({ access: r, roles: a, permissions: n, meta: s });
298
+ if (!p.allowed) {
299
+ if (p.reason === "unauthenticated") {
300
+ const b = `${v.pathname}${v.search}${v.hash}`, T = E && ((d == null ? void 0 : d()) ?? !0) ? `${i}?${E}=${encodeURIComponent(b)}` : i;
301
+ return /* @__PURE__ */ P.jsx(D, { to: T, replace: !0 });
302
302
  }
303
- return /* @__PURE__ */ h.jsx($, { to: m, replace: !0 });
303
+ return /* @__PURE__ */ P.jsx(D, { to: m, replace: !0 });
304
304
  }
305
- return a ?? /* @__PURE__ */ h.jsx(Y, {});
305
+ return u ?? /* @__PURE__ */ P.jsx(z, {});
306
306
  });
307
- function te(r, n, s, u, a, o) {
308
- return r === "unauthenticated" ? o ? `${s}?${o}=${encodeURIComponent(n)}` : s : r === "forbidden" ? u : a;
307
+ function pe(r, a, n, s, u, o, i) {
308
+ return r === "unauthenticated" ? o && ((i == null ? void 0 : i()) ?? !0) ? `${n}?${o}=${encodeURIComponent(a)}` : n : r === "forbidden" ? s : u;
309
+ }
310
+ function oe(r, a) {
311
+ if (r.protection.access === "guest-only") {
312
+ const s = r.guard.options.getUser();
313
+ return r.guard.options.isAuthenticated(s) ? r.defaultPath : null;
314
+ }
315
+ const n = r.guard.check(r.protection);
316
+ return n.allowed ? null : pe(
317
+ n.reason,
318
+ a,
319
+ r.loginPath,
320
+ r.forbiddenPath,
321
+ r.defaultPath,
322
+ r.callbackUrlParam,
323
+ r.shouldAddCallbackUrl
324
+ );
309
325
  }
310
- function me({
326
+ function be(r, a) {
327
+ return r.reduce(
328
+ (n, s) => n ?? oe(s, a),
329
+ null
330
+ );
331
+ }
332
+ function Ee({
311
333
  access: r,
312
- roles: n,
313
- permissions: s,
314
- meta: u,
315
- guard: a,
334
+ roles: a,
335
+ permissions: n,
336
+ meta: s,
337
+ guard: u,
316
338
  routeElement: o,
317
339
  RouteComponent: i,
318
340
  loginPath: m,
319
- forbiddenPath: R,
320
- defaultPath: p,
321
- callbackUrlParam: E
341
+ forbiddenPath: h,
342
+ defaultPath: E,
343
+ callbackUrlParam: d,
344
+ shouldAddCallbackUrl: v
322
345
  }) {
323
- const b = re(), v = `${b.pathname}${b.search}${b.hash}`;
324
- if (r === "guest-only") {
325
- const _ = a.options.getUser();
326
- return a.options.isAuthenticated(_) ? /* @__PURE__ */ h.jsx($, { to: p, replace: !0 }) : i ? /* @__PURE__ */ h.jsx(i, {}) : o ?? /* @__PURE__ */ h.jsx(Y, {});
327
- }
328
- const d = a.check({ access: r, roles: n, permissions: s, meta: u });
329
- if (!d.allowed) {
330
- const _ = te(
331
- d.reason,
332
- v,
333
- m,
334
- R,
335
- p,
336
- E
337
- );
338
- return /* @__PURE__ */ h.jsx($, { to: _, replace: !0 });
339
- }
340
- return i ? /* @__PURE__ */ h.jsx(i, {}) : o ?? /* @__PURE__ */ h.jsx(Y, {});
346
+ const p = ne(), b = `${p.pathname}${p.search}${p.hash}`, R = oe(
347
+ {
348
+ guard: u,
349
+ protection: { access: r, roles: a, permissions: n, meta: s },
350
+ loginPath: m,
351
+ forbiddenPath: h,
352
+ defaultPath: E,
353
+ callbackUrlParam: d,
354
+ shouldAddCallbackUrl: v
355
+ },
356
+ b
357
+ );
358
+ return R ? /* @__PURE__ */ P.jsx(D, { to: R, replace: !0 }) : i ? /* @__PURE__ */ P.jsx(i, {}) : o ?? /* @__PURE__ */ P.jsx(z, {});
341
359
  }
342
- function W(r, n, s) {
343
- return /* @__PURE__ */ h.jsx(
344
- me,
360
+ function q(r, a, n) {
361
+ return /* @__PURE__ */ P.jsx(
362
+ Ee,
345
363
  {
346
364
  access: r.protection.access,
347
365
  roles: r.protection.roles,
348
366
  permissions: r.protection.permissions,
349
367
  meta: r.protection.meta,
350
368
  guard: r.guard,
351
- routeElement: n,
352
- RouteComponent: s ?? null,
369
+ routeElement: a,
370
+ RouteComponent: n ?? null,
353
371
  loginPath: r.loginPath,
354
372
  forbiddenPath: r.forbiddenPath,
355
373
  defaultPath: r.defaultPath,
356
- callbackUrlParam: r.callbackUrlParam
374
+ callbackUrlParam: r.callbackUrlParam,
375
+ shouldAddCallbackUrl: r.shouldAddCallbackUrl
357
376
  }
358
377
  );
359
378
  }
360
- function I(r, n) {
361
- return r === void 0 || typeof r == "boolean" ? r : (s) => {
362
- const u = new URL(s.request.url), a = `${u.pathname}${u.search}`;
363
- if (n.protection.access === "guest-only") {
364
- const i = n.guard.options.getUser();
365
- return n.guard.options.isAuthenticated(i) ? Z(n.defaultPath) : r(s);
366
- }
367
- const o = n.guard.check(n.protection);
368
- if (!o.allowed) {
369
- const i = te(
370
- o.reason,
371
- a,
372
- n.loginPath,
373
- n.forbiddenPath,
374
- n.defaultPath,
375
- n.callbackUrlParam
376
- );
377
- return Z(i);
378
- }
379
- return r(s);
379
+ function y(r, a) {
380
+ return r === void 0 || typeof r == "boolean" || a.length === 0 ? r : (n) => {
381
+ const s = new URL(n.request.url), u = `${s.pathname}${s.search}`, o = be(a, u);
382
+ return o ? le(o) : r(n);
380
383
  };
381
384
  }
382
- async function pe(r) {
383
- const n = await Promise.all(
384
- Object.entries(r).map(async ([s, u]) => [s, await (u == null ? void 0 : u())])
385
+ async function ve(r) {
386
+ const a = await Promise.all(
387
+ Object.entries(r).map(async ([n, s]) => [n, await (s == null ? void 0 : s())])
385
388
  );
386
- return Object.fromEntries(n);
389
+ return Object.fromEntries(a);
387
390
  }
388
- function he(r, n) {
391
+ function re(r, a, n) {
389
392
  if (!r) return;
390
- const s = typeof r == "function" ? r : () => pe(r);
393
+ const s = typeof r == "function" ? r : () => ve(r);
391
394
  return async () => {
392
395
  const u = await s();
393
396
  if (!u)
394
- return n.hasStaticUi ? {} : { element: W(n) };
395
- const { element: a, Component: o, loader: i, action: m, ...R } = u, p = {
396
- ...R,
397
- loader: I(i, n),
398
- action: I(m, n)
397
+ return n ? n.hasStaticUi ? {} : { element: q(n) } : {};
398
+ const { element: o, Component: i, loader: m, action: h, ...E } = u, d = {
399
+ ...E,
400
+ loader: y(m, a),
401
+ action: y(h, a)
399
402
  };
400
- return n.hasStaticUi || (p.element = W(n, a, o ?? null)), p;
403
+ return n ? (n.hasStaticUi || (d.element = q(n, o, i ?? null)), d) : (d.element = o, d.Component = i, d);
401
404
  };
402
405
  }
403
- function Te(r, n, s) {
406
+ function ke(r, a, n) {
404
407
  const {
405
- loginPath: u = "/login",
406
- forbiddenPath: a = "/403",
408
+ loginPath: s = "/login",
409
+ forbiddenPath: u = "/403",
407
410
  defaultPath: o = "/",
408
411
  callbackUrlParam: i,
409
- ...m
410
- } = n, R = le(m), p = (E) => E.map((b) => {
412
+ shouldAddCallbackUrl: m,
413
+ ...h
414
+ } = a, E = fe(h), d = (v, p = []) => v.map((b) => {
411
415
  const {
412
- access: v,
413
- roles: d,
414
- permissions: _,
415
- meta: k,
416
- children: P,
417
- element: A,
418
- Component: j,
419
- loader: N,
420
- action: C,
421
- lazy: w,
422
- ...x
423
- } = b;
424
- if (!(v !== void 0 || !!(d != null && d.length) || !!(_ != null && _.length) || k !== void 0))
416
+ access: R,
417
+ roles: T,
418
+ permissions: g,
419
+ meta: x,
420
+ children: A,
421
+ element: w,
422
+ Component: S,
423
+ loader: Y,
424
+ action: I,
425
+ lazy: C,
426
+ ...F
427
+ } = b, O = R !== void 0 || !!(T != null && T.length) || !!(g != null && g.length) || x !== void 0, k = O ? {
428
+ guard: E,
429
+ protection: { access: R, roles: T, permissions: g, meta: x },
430
+ hasStaticUi: w != null || S != null,
431
+ loginPath: s,
432
+ forbiddenPath: u,
433
+ defaultPath: o,
434
+ callbackUrlParam: i,
435
+ shouldAddCallbackUrl: m
436
+ } : void 0, _ = k ? [...p, k] : p;
437
+ if (!O)
425
438
  return {
426
- ...x,
427
- element: A,
428
- Component: j,
429
- loader: N,
430
- action: C,
431
- lazy: w,
432
- children: P ? p(P) : void 0
439
+ ...F,
440
+ element: w,
441
+ Component: S,
442
+ loader: y(Y, _),
443
+ action: y(I, _),
444
+ lazy: re(C, _),
445
+ children: A ? d(A, _) : void 0
433
446
  };
434
- const T = {
435
- guard: R,
436
- protection: { access: v, roles: d, permissions: _, meta: k },
437
- hasStaticUi: A != null || j != null,
438
- loginPath: u,
439
- forbiddenPath: a,
440
- defaultPath: o,
441
- callbackUrlParam: i
442
- }, O = T.hasStaticUi || !w ? W(T, A, j ?? null) : void 0;
447
+ if (!k)
448
+ throw new Error("Guard context must exist for guarded routes");
449
+ const $ = k.hasStaticUi || !C ? q(k, w, S ?? null) : void 0;
443
450
  return {
444
- ...x,
445
- element: O,
451
+ ...F,
452
+ element: $,
446
453
  Component: void 0,
447
- loader: I(N, T),
448
- action: I(C, T),
449
- lazy: he(w, T),
450
- children: P ? p(P) : void 0
454
+ loader: y(Y, _),
455
+ action: y(I, _),
456
+ lazy: re(C, _, k),
457
+ children: A ? d(A, _) : void 0
451
458
  };
452
459
  });
453
- return ie(p(r), s);
460
+ return ie(d(r), n);
454
461
  }
455
462
  export {
456
- ke as AccessProvider,
457
- Pe as AccessRoute,
463
+ Oe as AccessProvider,
464
+ ge as AccessRoute,
458
465
  je as HasAccess,
459
- Te as createAccessRouter,
460
- we as useAccess,
461
- Oe as useHasAccess,
462
- Re as useRouteAccess
466
+ ke as createAccessRouter,
467
+ ye as useAccess,
468
+ Se as useHasAccess,
469
+ Te as useRouteAccess
463
470
  };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@react-protected/react/testing");Object.defineProperty(exports,"MockAccessProvider",{enumerable:!0,get:()=>e.MockAccessProvider});
@@ -0,0 +1,2 @@
1
+ export type { MockAccessProviderProps } from '@react-protected/react/testing';
2
+ export { MockAccessProvider } from '@react-protected/react/testing';
@@ -0,0 +1,4 @@
1
+ import { MockAccessProvider as c } from "@react-protected/react/testing";
2
+ export {
3
+ c as MockAccessProvider
4
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-protected/react-router",
3
- "version": "0.1.1-beta.1",
3
+ "version": "0.2.0-beta.3",
4
4
  "license": "MIT",
5
5
  "description": "React Router data router adapter for react-protected",
6
6
  "main": "./dist/index.cjs",
@@ -19,14 +19,19 @@
19
19
  "import": "./dist/index.js",
20
20
  "require": "./dist/index.cjs",
21
21
  "types": "./dist/index.d.ts"
22
+ },
23
+ "./testing": {
24
+ "import": "./dist/testing.js",
25
+ "require": "./dist/testing.cjs",
26
+ "types": "./dist/testing.d.ts"
22
27
  }
23
28
  },
24
29
  "files": [
25
30
  "dist"
26
31
  ],
27
32
  "dependencies": {
28
- "@react-protected/core": "0.1.1-beta.1",
29
- "@react-protected/react": "0.1.1-beta.1"
33
+ "@react-protected/react": "0.2.0-beta.2",
34
+ "@react-protected/core": "0.2.0-beta.2"
30
35
  },
31
36
  "peerDependencies": {
32
37
  "react": ">=18.0.0",