@clicktap/state 0.12.9 → 0.12.10

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.
Files changed (3) hide show
  1. package/index.js +1 -1
  2. package/index.mjs +3 -4
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -66,4 +66,4 @@ Check the render method of \``+f+"`."}return""}}function _n(f){{if(f!==void 0){v
66
66
 
67
67
  Check your code at `+b+":"+R+"."}return""}}var Ft={};function En(f){{var b=Ye();if(!b){var R=typeof f=="string"?f:f.displayName||f.name;R&&(b=`
68
68
 
69
- Check the top-level render call using <`+R+">.")}return b}}function Nt(f,b){{if(!f._store||f._store.validated||f.key!=null)return;f._store.validated=!0;var R=En(b);if(Ft[R])return;Ft[R]=!0;var C="";f&&f._owner&&f._owner!==nt.current&&(C=" It was passed a child from "+ce(f._owner.type)+"."),Re(f),V('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',R,C),Re(null)}}function Lt(f,b){{if(typeof f!="object")return;if(et(f))for(var R=0;R<f.length;R++){var C=f[R];Ie(C)&&Nt(C,b)}else if(Ie(f))f._store&&(f._store.validated=!0);else if(f){var U=D(f);if(typeof U=="function"&&U!==f.entries)for(var H=U.call(f),F;!(F=H.next()).done;)Ie(F.value)&&Nt(F.value,b)}}}function Je(f){{var b=f.type;if(b==null||typeof b=="string")return;var R;if(typeof b=="function")R=b.propTypes;else if(typeof b=="object"&&(b.$$typeof===d||b.$$typeof===h))R=b.propTypes;else return;if(R){var C=ce(b);Se(R,f.props,"prop",C,f)}else if(b.PropTypes!==void 0&&!qe){qe=!0;var U=ce(b);V("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",U||"Unknown")}typeof b.getDefaultProps=="function"&&!b.getDefaultProps.isReactClassApproved&&V("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function mt(f){{for(var b=Object.keys(f.props),R=0;R<b.length;R++){var C=b[R];if(C!=="children"&&C!=="key"){Re(f),V("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",C),Re(null);break}}f.ref!==null&&(Re(f),V("Invalid attribute `ref` supplied to `React.Fragment`."),Re(null))}}function vt(f,b,R,C,U,H){{var F=Ne(f);if(!F){var j="";(f===void 0||typeof f=="object"&&f!==null&&Object.keys(f).length===0)&&(j+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var ie=_n(U);ie?j+=ie:j+=Ye();var Z;f===null?Z="null":et(f)?Z="array":f!==void 0&&f.$$typeof===t?(Z="<"+(ce(f.type)||"Unknown")+" />",j=" Did you accidentally export a JSX literal instead of a component?"):Z=typeof f,V("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",Z,j)}var ee=gn(f,b,R,U,H);if(ee==null)return ee;if(F){var de=b.children;if(de!==void 0)if(C)if(et(de)){for(var je=0;je<de.length;je++)Lt(de[je],f);Object.freeze&&Object.freeze(de)}else V("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 Lt(de,f)}return f===r?mt(ee):Je(ee),ee}}function bn(f,b,R){return vt(f,b,R,!0)}function Sn(f,b,R){return vt(f,b,R,!1)}var wn=Sn,Tn=bn;St.Fragment=r,St.jsx=wn,St.jsxs=Tn}()),St}process.env.NODE_ENV==="production"?Kn.exports=Qa():Kn.exports=eu();var eo=Kn.exports;const rn=Ae.createContext({}),tu=()=>{const e=Ae.useContext(rn);console.log(rn);const[t,n]=Ae.useState(e.getSnapshot().value==="loggedIn");return Ae.useEffect(()=>{const r=e.subscribe(s=>{(s.value==="loggedIn"||s.value==="loggedOut")&&n(s.value==="loggedIn")});return()=>{r==null||r.unsubscribe()}},[e]),{authActor:e,isLoggedIn:t}},nu=async(e="",t={inspect:void 0,endpoints:{login:"",logout:"",refresh:"",ssrRefresh:""}})=>typeof window<"u"?(console.warn("App.getInitialProps::getAuth should not be run on the frontend. You are probably missing getServerSideProps in your page."),ut(Jn,{inspect:t.inspect,input:{initialContext:{endpoints:t.endpoints}}}).start()):ut(Jn,{input:{initialContext:{endpoints:t.endpoints,refreshToken:e}},inspect:t.inspect}).start();function ru({actor:e,children:t}){return eo.jsx(rn.Provider,{value:e,children:t})}let su=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),"");const to=ar({actors:{tick:Ci(({sendBack:e,input:t})=>{const n=setInterval(()=>{e({type:"TICK"})},t.interval);return()=>{clearInterval(n)}})},types:{context:{},events:{},input:{}}}).createMachine({id:"timer",initial:"running",context:({input:e})=>({elapsed:0,duration:e.initialContext.duration??3e3,interval:100,intervalId:null}),states:{paused:{on:{RESUME_TIMER:{target:"running",guard:({context:e})=>e.elapsed<e.duration}}},running:{invoke:{input:({context:e})=>({interval:e.interval}),src:"tick"},always:[{target:"completed",guard:({context:e})=>e.elapsed>=e.duration}],on:{TICK:{actions:ge(({context:e,event:t})=>t.type!=="TICK"?e:{elapsed:e.elapsed+e.interval})},PAUSE_TIMER:{target:"paused"}}},completed:{type:"final"}}}),ou=ar({actors:{timer:to},types:{context:{},events:{},input:{}},actions:{addItem:ge(({context:e,event:t})=>{if(t.type!=="ADD_ITEM")return e;const n=`notification-${su()}`,r=t.duration??e.duration,s=Ae.cloneElement(t.item,{duration:r,id:n,key:t.item.key??n,...t.item.props}),i={duration:r,id:n,element:s},a=e.items;return e.order==="desc"?a.push(i):a.unshift(i),{items:a,activeItem:n}}),removeItem:ge(({context:e,event:t})=>{if(t.type!=="REMOVE_ITEM"&&t.type!=="xstate.done.actor.timer")return e;const n=e.items;return e.order==="desc"?(n.pop(),{items:n,activeItem:n.length>0?n[n.length-1].id:null}):(n.shift(),{items:n,activeItem:n.length>0?n[0].id:null})})},delays:{ITEM_TIMEOUT:({context:e})=>e.items[e.items.length-1].duration??e.duration},guards:{itemHasTimeout:({context:e})=>e.items[e.items.length-1].duration>0||e.duration>0}}).createMachine({id:"toast",context:{items:[],order:"desc",duration:0,activeItem:null},initial:"idle",states:{idle:{on:{ADD_ITEM:{target:"adding"}}},active:{invoke:{src:"timer",input:({context:e})=>({initialContext:{duration:e.items[e.items.length-1].duration??e.duration}}),onDone:{target:"removing",guard:"itemHasTimeout"}},on:{ADD_ITEM:{target:"adding"},REMOVE_ITEM:{target:"removing"},SET_IDLE:{target:"idle"},RESUME_TIMER:{actions:Xr("timer",{type:"RESUME_TIMER"})},PAUSE_TIMER:{actions:Xr("timer",{type:"PAUSE_TIMER"})}}},adding:{entry:["addItem"],on:{SET_IDLE:{target:"idle"},SET_ACTIVE:{target:"active"}}},removing:{entry:"removeItem",on:{SET_IDLE:{target:"idle"},SET_ACTIVE:{target:"active"}}}}}),pr=Ae.createContext({}),iu=()=>Ae.useContext(pr);function au({children:e,actor:t}){return eo.jsx(pr.Provider,{value:t,children:e})}exports.AuthContext=rn;exports.AuthProvider=ru;exports.ToastContext=pr;exports.ToastProvider=au;exports.authMachine=Jn;exports.getAuth=nu;exports.timerMachine=to;exports.toastMachine=ou;exports.useAuth=tu;exports.useToast=iu;
69
+ Check the top-level render call using <`+R+">.")}return b}}function Nt(f,b){{if(!f._store||f._store.validated||f.key!=null)return;f._store.validated=!0;var R=En(b);if(Ft[R])return;Ft[R]=!0;var C="";f&&f._owner&&f._owner!==nt.current&&(C=" It was passed a child from "+ce(f._owner.type)+"."),Re(f),V('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',R,C),Re(null)}}function Lt(f,b){{if(typeof f!="object")return;if(et(f))for(var R=0;R<f.length;R++){var C=f[R];Ie(C)&&Nt(C,b)}else if(Ie(f))f._store&&(f._store.validated=!0);else if(f){var U=D(f);if(typeof U=="function"&&U!==f.entries)for(var H=U.call(f),F;!(F=H.next()).done;)Ie(F.value)&&Nt(F.value,b)}}}function Je(f){{var b=f.type;if(b==null||typeof b=="string")return;var R;if(typeof b=="function")R=b.propTypes;else if(typeof b=="object"&&(b.$$typeof===d||b.$$typeof===h))R=b.propTypes;else return;if(R){var C=ce(b);Se(R,f.props,"prop",C,f)}else if(b.PropTypes!==void 0&&!qe){qe=!0;var U=ce(b);V("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",U||"Unknown")}typeof b.getDefaultProps=="function"&&!b.getDefaultProps.isReactClassApproved&&V("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function mt(f){{for(var b=Object.keys(f.props),R=0;R<b.length;R++){var C=b[R];if(C!=="children"&&C!=="key"){Re(f),V("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",C),Re(null);break}}f.ref!==null&&(Re(f),V("Invalid attribute `ref` supplied to `React.Fragment`."),Re(null))}}function vt(f,b,R,C,U,H){{var F=Ne(f);if(!F){var j="";(f===void 0||typeof f=="object"&&f!==null&&Object.keys(f).length===0)&&(j+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var ie=_n(U);ie?j+=ie:j+=Ye();var Z;f===null?Z="null":et(f)?Z="array":f!==void 0&&f.$$typeof===t?(Z="<"+(ce(f.type)||"Unknown")+" />",j=" Did you accidentally export a JSX literal instead of a component?"):Z=typeof f,V("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",Z,j)}var ee=gn(f,b,R,U,H);if(ee==null)return ee;if(F){var de=b.children;if(de!==void 0)if(C)if(et(de)){for(var je=0;je<de.length;je++)Lt(de[je],f);Object.freeze&&Object.freeze(de)}else V("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 Lt(de,f)}return f===r?mt(ee):Je(ee),ee}}function bn(f,b,R){return vt(f,b,R,!0)}function Sn(f,b,R){return vt(f,b,R,!1)}var wn=Sn,Tn=bn;St.Fragment=r,St.jsx=wn,St.jsxs=Tn}()),St}process.env.NODE_ENV==="production"?Kn.exports=Qa():Kn.exports=eu();var eo=Kn.exports;const rn=Ae.createContext({}),tu=()=>{console.log("useAuth"),console.log(typeof window),console.log(rn);const e=Ae.useContext(rn),[t,n]=Ae.useState(e.getSnapshot().value==="loggedIn");return Ae.useEffect(()=>{const r=e.subscribe(s=>{(s.value==="loggedIn"||s.value==="loggedOut")&&n(s.value==="loggedIn")});return()=>{r.unsubscribe()}},[e]),{authActor:e,isLoggedIn:t}},nu=async(e="",t={inspect:void 0,endpoints:{login:"",logout:"",refresh:"",ssrRefresh:""}})=>typeof window<"u"?(console.warn("App.getInitialProps::getAuth should not be run on the frontend. You are probably missing getServerSideProps in your page."),ut(Jn,{inspect:t.inspect,input:{initialContext:{endpoints:t.endpoints}}}).start()):ut(Jn,{input:{initialContext:{endpoints:t.endpoints,refreshToken:e}},inspect:t.inspect}).start();function ru({actor:e,children:t}){return eo.jsx(rn.Provider,{value:e,children:t})}let su=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),"");const to=ar({actors:{tick:Ci(({sendBack:e,input:t})=>{const n=setInterval(()=>{e({type:"TICK"})},t.interval);return()=>{clearInterval(n)}})},types:{context:{},events:{},input:{}}}).createMachine({id:"timer",initial:"running",context:({input:e})=>({elapsed:0,duration:e.initialContext.duration??3e3,interval:100,intervalId:null}),states:{paused:{on:{RESUME_TIMER:{target:"running",guard:({context:e})=>e.elapsed<e.duration}}},running:{invoke:{input:({context:e})=>({interval:e.interval}),src:"tick"},always:[{target:"completed",guard:({context:e})=>e.elapsed>=e.duration}],on:{TICK:{actions:ge(({context:e,event:t})=>t.type!=="TICK"?e:{elapsed:e.elapsed+e.interval})},PAUSE_TIMER:{target:"paused"}}},completed:{type:"final"}}}),ou=ar({actors:{timer:to},types:{context:{},events:{},input:{}},actions:{addItem:ge(({context:e,event:t})=>{if(t.type!=="ADD_ITEM")return e;const n=`notification-${su()}`,r=t.duration??e.duration,s=Ae.cloneElement(t.item,{duration:r,id:n,key:t.item.key??n,...t.item.props}),i={duration:r,id:n,element:s},a=e.items;return e.order==="desc"?a.push(i):a.unshift(i),{items:a,activeItem:n}}),removeItem:ge(({context:e,event:t})=>{if(t.type!=="REMOVE_ITEM"&&t.type!=="xstate.done.actor.timer")return e;const n=e.items;return e.order==="desc"?(n.pop(),{items:n,activeItem:n.length>0?n[n.length-1].id:null}):(n.shift(),{items:n,activeItem:n.length>0?n[0].id:null})})},delays:{ITEM_TIMEOUT:({context:e})=>e.items[e.items.length-1].duration??e.duration},guards:{itemHasTimeout:({context:e})=>e.items[e.items.length-1].duration>0||e.duration>0}}).createMachine({id:"toast",context:{items:[],order:"desc",duration:0,activeItem:null},initial:"idle",states:{idle:{on:{ADD_ITEM:{target:"adding"}}},active:{invoke:{src:"timer",input:({context:e})=>({initialContext:{duration:e.items[e.items.length-1].duration??e.duration}}),onDone:{target:"removing",guard:"itemHasTimeout"}},on:{ADD_ITEM:{target:"adding"},REMOVE_ITEM:{target:"removing"},SET_IDLE:{target:"idle"},RESUME_TIMER:{actions:Xr("timer",{type:"RESUME_TIMER"})},PAUSE_TIMER:{actions:Xr("timer",{type:"PAUSE_TIMER"})}}},adding:{entry:["addItem"],on:{SET_IDLE:{target:"idle"},SET_ACTIVE:{target:"active"}}},removing:{entry:"removeItem",on:{SET_IDLE:{target:"idle"},SET_ACTIVE:{target:"active"}}}}}),pr=Ae.createContext({}),iu=()=>Ae.useContext(pr);function au({children:e,actor:t}){return eo.jsx(pr.Provider,{value:t,children:e})}exports.AuthContext=rn;exports.AuthProvider=ru;exports.ToastContext=pr;exports.ToastProvider=au;exports.authMachine=Jn;exports.getAuth=nu;exports.timerMachine=to;exports.toastMachine=ou;exports.useAuth=tu;exports.useToast=iu;
package/index.mjs CHANGED
@@ -6039,9 +6039,8 @@ var Qs = Yn.exports;
6039
6039
  const Kn = Ae.createContext(
6040
6040
  {}
6041
6041
  ), nu = () => {
6042
- const e = Ae.useContext(Kn);
6043
- console.log(Kn);
6044
- const [t, n] = Ae.useState(
6042
+ console.log("useAuth"), console.log(typeof window), console.log(Kn);
6043
+ const e = Ae.useContext(Kn), [t, n] = Ae.useState(
6045
6044
  e.getSnapshot().value === "loggedIn"
6046
6045
  );
6047
6046
  return Ae.useEffect(() => {
@@ -6049,7 +6048,7 @@ const Kn = Ae.createContext(
6049
6048
  (s.value === "loggedIn" || s.value === "loggedOut") && n(s.value === "loggedIn");
6050
6049
  });
6051
6050
  return () => {
6052
- r == null || r.unsubscribe();
6051
+ r.unsubscribe();
6053
6052
  };
6054
6053
  }, [e]), { authActor: e, isLoggedIn: t };
6055
6054
  }, ru = async (e = "", t = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clicktap/state",
3
- "version": "0.12.9",
3
+ "version": "0.12.10",
4
4
  "private": false,
5
5
  "author": "Clicktap",
6
6
  "description": "A state management library for Clicktap reference frontend.",