@tracktor/shared-module 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
1
  # [Versions](https://github.com/Tracktor/shared-module/releases)
2
2
 
3
- ## v2.2.0
4
- - **[feat]** - add handleImportModuleError
3
+ ## v2.2.1
4
+ - **[fix]** - required auth redirect from state
package/dist/main.js CHANGED
@@ -644,7 +644,14 @@ const A = dt({}), Ot = ({ children: t, apiURL: n, libraries: i }) => {
644
644
  return typeof b == "object" && b && "response" in b && b.response && typeof b.response == "object" && "status" in b.response && b.response && typeof b.response == "object" && "status" in b.response && ((z = b == null ? void 0 : b.response) == null ? void 0 : z.status) === 401 && (s.defaults.headers.common.Authorization = null, localStorage.removeItem(c), E(a)), Promise.reject(b);
645
645
  }
646
646
  ));
647
- }, [s.defaults.headers.common, s.interceptors.response, c, a]), k && !y ? /* @__PURE__ */ F.jsx(mt, { fallback: t, children: (Y = (_ = j.state) == null ? void 0 : _.from) != null && Y.state && ((W = (N = j.state) == null ? void 0 : N.from) == null ? void 0 : W.pathname) === i ? /* @__PURE__ */ F.jsx(R, { to: j.state.from.state.from.pathname + j.state.from.state.from.search, replace: !0 }) : /* @__PURE__ */ F.jsx(u, {}) }) : /* @__PURE__ */ F.jsx(R, { to: i, state: { from: j }, replace: !0 });
647
+ }, [s.defaults.headers.common, s.interceptors.response, c, a]), k && !y ? /* @__PURE__ */ F.jsx(mt, { fallback: t, children: (Y = (_ = j.state) == null ? void 0 : _.from) != null && Y.state && ((W = (N = j.state) == null ? void 0 : N.from) == null ? void 0 : W.pathname) === i ? /* @__PURE__ */ F.jsx(
648
+ R,
649
+ {
650
+ to: j.state.from.state.from.pathname + j.state.from.state.from.search,
651
+ state: { from: j },
652
+ replace: !0
653
+ }
654
+ ) : /* @__PURE__ */ F.jsx(u, {}) }) : /* @__PURE__ */ F.jsx(R, { to: i, state: { from: j }, replace: !0 });
648
655
  }, kt = ({ ...t }) => {
649
656
  const { libraries: n } = D(A), i = (t == null ? void 0 : t.reactRouter) || (n == null ? void 0 : n.reactRouter), c = (t == null ? void 0 : t.gtm) || (n == null ? void 0 : n.gtm);
650
657
  if (!i)
package/dist/main.umd.cjs CHANGED
@@ -22,4 +22,4 @@
22
22
 
23
23
  Check the render method of \``+e+"`."}return""}}function Ot(e){return""}var ke={};function At(e){{var r=Ie();if(!r){var o=typeof e=="string"?e:e.displayName||e.name;o&&(r=`
24
24
 
25
- Check the top-level render call using <`+o+">.")}return r}}function De(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var o=At(r);if(ke[o])return;ke[o]=!0;var f="";e&&e._owner&&e._owner!==ae.current&&(f=" It was passed a child from "+W(e._owner.type)+"."),V(e),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',o,f),V(null)}}function Fe(e,r){{if(typeof e!="object")return;if(oe(e))for(var o=0;o<e.length;o++){var f=e[o];se(f)&&De(f,r)}else if(se(e))e._store&&(e._store.validated=!0);else if(e){var E=x(e);if(typeof E=="function"&&E!==e.entries)for(var p=E.call(e),m;!(m=p.next()).done;)se(m.value)&&De(m.value,r)}}}function It(e){{var r=e.type;if(r==null||typeof r=="string")return;var o;if(typeof r=="function")o=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===u||r.$$typeof===_))o=r.propTypes;else return;if(o){var f=W(r);Et(o,e.props,"prop",f,e)}else if(r.PropTypes!==void 0&&!ce){ce=!0;var E=W(r);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",E||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function kt(e){{for(var r=Object.keys(e.props),o=0;o<r.length;o++){var f=r[o];if(f!=="children"&&f!=="key"){V(e),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",f),V(null);break}}e.ref!==null&&(V(e),b("Invalid attribute `ref` supplied to `React.Fragment`."),V(null))}}function We(e,r,o,f,E,p){{var m=ft(e);if(!m){var g="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(g+=" 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 O=Ot();O?g+=O:g+=Ie();var P;e===null?P="null":oe(e)?P="array":e!==void 0&&e.$$typeof===n?(P="<"+(W(e.type)||"Unknown")+" />",g=" Did you accidentally export a JSX literal instead of a component?"):P=typeof e,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",P,g)}var T=xt(e,r,o,E,p);if(T==null)return T;if(m){var k=r.children;if(k!==void 0)if(f)if(oe(k)){for(var U=0;U<k.length;U++)Fe(k[U],e);Object.freeze&&Object.freeze(k)}else b("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 Fe(k,e)}return e===c?kt(T):It(T),T}}function Dt(e,r,o){return We(e,r,o,!0)}function Ft(e,r,o){return We(e,r,o,!1)}var Wt=Ft,Yt=Dt;G.Fragment=c,G.jsx=Wt,G.jsxs=Yt}()),G}process.env.NODE_ENV==="production"?ee.exports=Ne():ee.exports=Me();var F=ee.exports;const A=h.createContext({}),Le=({children:t,apiURL:n,libraries:i})=>{const c=h.useMemo(()=>({apiURL:n,libraries:i}),[n,i]);return F.jsx(A.Provider,{value:c,children:t})},ze=({Fallback:t,isLogged:n,loginPath:i="/login",localStorageKey:c="user",redirect401Path:a="/login",...l})=>{var b,N,M,L;const{libraries:v}=h.useContext(A),d=(l==null?void 0:l.reactRouter)||(v==null?void 0:v.reactRouter),u=(l==null?void 0:l.axios)||(v==null?void 0:v.axios);if(!d)throw new Error("React Router is not provided. You can provide it with InjectDependenciesProvider or directly in props.");const[y,R]=h.useState(null),{useLocation:_,Navigate:C,Outlet:s}=d,S=_(),I=h.useRef(!1),x=typeof n=="function"?n():!!n,D=typeof x=="boolean"?x:x==null?void 0:x.isLogged;return h.useEffect(()=>{I.current||(I.current=!0,u.interceptors.response.use(j=>j,async j=>{var Q;return typeof j=="object"&&j&&"response"in j&&j.response&&typeof j.response=="object"&&"status"in j.response&&j.response&&typeof j.response=="object"&&"status"in j.response&&((Q=j==null?void 0:j.response)==null?void 0:Q.status)===401&&(u.defaults.headers.common.Authorization=null,localStorage.removeItem(c),R(a)),Promise.reject(j)}))},[u.defaults.headers.common,u.interceptors.response,c,a]),D&&!y?F.jsx(h.Suspense,{fallback:t,children:(N=(b=S.state)==null?void 0:b.from)!=null&&N.state&&((L=(M=S.state)==null?void 0:M.from)==null?void 0:L.pathname)===i?F.jsx(C,{to:S.state.from.state.from.pathname+S.state.from.state.from.search,replace:!0}):F.jsx(s,{})}):F.jsx(C,{to:i,state:{from:S},replace:!0})},Ve=({...t})=>{const{libraries:n}=h.useContext(A),i=(t==null?void 0:t.reactRouter)||(n==null?void 0:n.reactRouter),c=(t==null?void 0:t.gtm)||(n==null?void 0:n.gtm);if(!i)throw new Error("React Router is not provided. You can provide it with InjectDependenciesProvider or directly in props of GTMSendPageView.");if(!c)throw new Error("GTM is not provided. You can provide it with InjectDependenciesProvider or directly in props of GTMSendPageView.");const{useGoogleTagManager:a}=c,{useLocation:l,Outlet:v}=i,{pathname:d}=l(),{sendEvent:u}=a();return h.useEffect(()=>{u({event:"pageView",pathname:d})},[d,u]),F.jsx(v,{})},Ue=({tokenTypeKey:t="tokenType",userLocalStorageKey:n="user",tokenKey:i="accessToken",postContentType:c="application/json",...a})=>{const{apiURL:l=a.apiURL,libraries:v}=h.useContext(A),d=(a==null?void 0:a.axios)||(v==null?void 0:v.axios);if(!d)throw new Error("Axios is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(!(d!=null&&d.defaults))return null;const u=localStorage.getItem(n),y=u?JSON.parse(u):null,R=y!=null&&y[t]?y[t]:null,_=y!=null&&y[i]?y[i]:null,C=u?`${R} ${_}`:null;return d.defaults.baseURL=l,d.defaults.headers.post["Content-Type"]=c,C&&(d.defaults.headers.common.Authorization=C),null},Be=({debug:t,resources:n,...i})=>{const{libraries:c}=h.useContext(A),a=(i==null?void 0:i.i18)||(c==null?void 0:c.i18),{i18next:l,initReactI18next:v,languageDetector:d}=a||{};if(!a)throw new Error("i18 is not provided. You can provide it with InjectDependenciesProvider or directly in props.");return l!=null&&l.isInitialized||(l.use(d).use(v).init({debug:t,fallbackLng:"en",interpolation:{escapeValue:!1},load:"languageOnly",react:{bindI18n:"languageChanged loaded",useSuspense:!0},resources:n,returnNull:!1}).then(()=>{document.documentElement.lang!==l.resolvedLanguage&&l.resolvedLanguage&&document.documentElement.setAttribute("lang",l.resolvedLanguage)}),l.on("languageChanged",u=>{document.documentElement.setAttribute("lang",u)})),null},Ge=({dsn:t,integrations:n,tracesSampleRate:i,replaysSessionSampleRate:c,replaysOnErrorSampleRate:a,tracePropagationTargets:l,ignoreErrors:v,debug:d,environment:u,...y})=>{const{libraries:R}=h.useContext(A),_=(y==null?void 0:y.sentry)||(R==null?void 0:R.sentry),C=(y==null?void 0:y.reactRouter)||(R==null?void 0:R.reactRouter);if(!_)throw new Error("Sentry is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(!C)throw new Error("React Router is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(_.isInitialized())return null;const{createRoutesFromChildren:s,matchRoutes:S,useLocation:I,useNavigationType:x}=C;return(d||process.env.NODE_ENV==="prod"||process.env.NODE_ENV==="production")&&_.init({debug:d,dsn:t,environment:u||"production",ignoreErrors:[...v||[],/dynamically imported module/],integrations:[_.reactRouterV6BrowserTracingIntegration({createRoutesFromChildren:s,matchRoutes:S,useEffect:h.useEffect,useLocation:I,useNavigationType:x}),...n||[]],replaysOnErrorSampleRate:a||1,replaysSessionSampleRate:c||.1,tracePropagationTargets:l,tracesSampleRate:i||1}),null},Qe=({IMaskMixin:t,...n})=>{const i=h.useMemo(()=>t(({TextField:c,...a})=>F.jsx(c,{...a})),[t]);return F.jsx(i,{...n})},Je=({accessToken:t,...n})=>{const{libraries:i}=h.useContext(A),c=(n==null?void 0:n.mapbox)||(i==null?void 0:i.mapbox);if(!c)throw new Error("Mapbox is not provided. You can provide it with InjectDependenciesProvider or directly in props.");return t&&(c.accessToken=t),null},Xe=({language:t,...n})=>{const{libraries:i}=h.useContext(A),c=(n==null?void 0:n.dayjs)||(i==null?void 0:i.dayjs),a=(n==null?void 0:n.plugin)||(i==null?void 0:i.dayjsPlugin);if(!c)throw new Error("Dayjs is not provided. You can provide it with InjectDependenciesProvider or directly in props of InitializeDaysJSConfig.");return h.useEffect(()=>{(async()=>{var d;const v=t||((d=navigator.language)==null?void 0:d.slice(0,2))||"en";a&&a.forEach(u=>{u&&c.extend(u)}),await import("dayjs/locale/en"),await import("dayjs/locale/fr"),c.locale(v)})().then()},[c,a,t]),null},He=t=>t&&typeof t=="function",Ke=t=>t&&typeof t=="function",$e=({children:t,defaultQueriesOptions:n,defaultMutationsOptions:i,...c})=>{var u,y;const{libraries:a}=h.useContext(A),l=(c==null?void 0:c.QueryClient)||((u=a==null?void 0:a.reactQuery)==null?void 0:u.QueryClient),v=(c==null?void 0:c.QueryClientProvider)||((y=a==null?void 0:a.reactQuery)==null?void 0:y.QueryClientProvider);if(!l)throw new Error("QueryClient is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(!v)throw new Error("QueryClientProvider is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(!He(v))throw new Error("Provided QueryClientProvider dependencies are not valid.");if(!Ke(l))throw new Error("Provided QueryClient dependencies are not valid.");const d=new l({defaultOptions:{mutations:{...i},queries:{getNextPageParam:(R,_,C)=>R.length+(C||0),refetchOnWindowFocus:!1,retry:3,...n}}});return F.jsx(v,{client:d,children:t})},Ze=t=>{var y,R,_;const{libraries:n}=h.useContext(A),i=(t==null?void 0:t.i18)||(n==null?void 0:n.i18),c=((y=t==null?void 0:t.i18)==null?void 0:y.translateFunction)||((R=n==null?void 0:n.i18)==null?void 0:R.translateFunction),a=((_=i==null?void 0:i.i18next)==null?void 0:_.t)||c||(C=>C),{unknownErrorTranslationKey:l="error.unknownError"}=t||{},v=a(l),d=h.useCallback(C=>{var S,I,x,D,b,N,M,L,j;const{response:s}=C||{};return s!=null&&s.reason?String(s.reason):(S=s==null?void 0:s.data)!=null&&S.reason?String(s.data.reason):(I=s==null?void 0:s.data)!=null&&I.message?String(s.data.message):(D=(x=s==null?void 0:s.data)==null?void 0:x.detail)!=null&&D.length&&Array.isArray((b=s==null?void 0:s.data)==null?void 0:b.detail)&&((M=(N=s==null?void 0:s.data)==null?void 0:N.detail[0])!=null&&M.msg)&&typeof((j=(L=s==null?void 0:s.data)==null?void 0:L.detail[0])==null?void 0:j.msg)=="string"?String(s.data.detail[0].msg):v},[v]);return{getErrorCode:h.useCallback(C=>{var S,I,x;const{response:s}=C||{};return s!=null&&s.error_code?String(s==null?void 0:s.error_code):(S=s==null?void 0:s.data)!=null&&S.error_code?String((I=s==null?void 0:s.data)==null?void 0:I.error_code):s!=null&&s.error_code?String(s==null?void 0:s.error_code):(x=s==null?void 0:s.data)!=null&&x.error_code?String(s.data.error_code):"unknown_error_code"},[]),printError:d}},qe=({data:t,fetchNextPage:n,isFetchingNextPage:i,isInitialLoading:c,isLoading:a,enabled:l=!0})=>{const v=h.useCallback(async u=>{i||!l||await n({pageParam:(u==null?void 0:u.pageParam)||u.visibleRowsCount})},[l,n,i]),d=h.useMemo(()=>{if(t)return t.pages.reduce((u,y)=>[...u,...y],[])},[t]);return{fetchNextPageOnRowsScrollEnd:v,isLoading:i||a,loadingVariant:c?"skeleton":"linear",rows:d}},et=t=>{const{libraries:n}=h.useContext(A),i=(t==null?void 0:t.axios)||(n==null?void 0:n.axios);if(!i)throw new Error("Axios is not provided. You can provide it with InjectDependenciesProvider or directly in params of useAuth.");return{clearAuthenticationToken:()=>{i.defaults.headers.common.Authorization=null},setAuthenticationToken:({tokenType:l,accessToken:v})=>{i.defaults.headers.common.Authorization=`${l} ${v}`}}},fe=({library:t,date:n,format:i="ll"})=>t(n).format(i),de=(t,n="km")=>{const i=Number(t);return Number.isNaN(i)?`0 ${n}`:`${i.toFixed(2)} ${n}`},tt=t=>t!=null&&t.startsWith("/")?t!=null&&t.startsWith("/files")?t:`/files${t}`:t!=null&&t.startsWith("files")?`/${t}`:t!=null&&t.startsWith("files")?`/${t}`:`/files/${t}`,rt=({path:t,size:n,apiURL:i})=>{if(!t)return"";const c=tt(t),a=`${i}${c}`,l=a.match(/\.(jpeg|jpg|png|gif|bmp|webp|svg|avif)$/)!==null;return typeof n=="number"&&l?`${a.replace("/files",`/thumbs/${n}`)}`:a},nt=t=>{const{apiURL:n,libraries:i}=h.useContext(A),c=(t==null?void 0:t.dayjs)||(i==null?void 0:i.dayjs);return{dateAdapter:(v,d)=>{if(!c)throw new Error("Dayjs is not provided. You can provide it with InjectDependenciesProvider or directly in props.");return fe({date:v,format:d,library:c})},distanceAdapter:de,filePathAdapter:(v,d)=>{if(!n)throw new Error("API URL is not provided. You can provide it with InjectDependenciesProvider or directly in props to filePathAdapter.");return rt({apiURL:n,path:v,size:d})}}},ot=t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase(),it=t=>{const c=t.split("/").filter(a=>a.length>0).map(a=>a.replace(/\${([^}]*)}/g,"$1").split(/[_-]/).map(u=>u.charAt(0).toUpperCase()+u.slice(1)).join("")).join("");return c.charAt(0).toLowerCase()+c.slice(1)},at=t=>(t.split("/").pop()||t).replace(/\.json$/,"").replace(/^openapi\./,""),ct=(t,n,i)=>{const c=it(n),a=ot(i);return`${c}${a}`},st=t=>{if(t)return(t==null?void 0:t.reduce((n,i)=>(n[i]={query:{useInfinite:!0,useInfiniteQueryParam:"offset",useQuery:!0}},n),{}))||{}},ut=t=>(Array.isArray(t)?t:[t]).reduce((i,c)=>{const{output:a,operationsToGenerateInfiniteQueryHook:l,input:v="./openapi.json"}=c||{},d=at(v);return{...i,[d]:{hooks:{afterAllFilesWrite:"prettier src/api/ --write"},input:v,output:{baseUrl:a==null?void 0:a.baseUrl,client:"react-query",mode:"tags-split",override:{...(l==null?void 0:l.length)&&{operations:st(l)},header:u=>["Generated by orval 🍺",...u.title?[u.title]:[],...u.description?[u.description]:[]],mutator:{name:"axiosCustomInstance",path:`${__dirname}/axiosCustomInstance.ts`},operationName:ct,query:{useQuery:!0}},schemas:(a==null?void 0:a.schemas)||`src/api/${d}/model`,target:(a==null?void 0:a.target)||`src/api/${d}/services/api.ts`,...a}}}},{}),lt=t=>{const n="moduleFetchError";throw t.message.includes("Failed to fetch dynamically imported module")&&(document.cookie.split(";").some(c=>c.trim().startsWith(`${n}=`))||(document.cookie=`${n}=true; max-age=60; path=/`,window.location.reload())),t};w.GTMSendPageView=Ve,w.InitializeAxiosConfig=Ue,w.InitializeDaysJSConfig=Xe,w.InitializeI18nConfig=Be,w.InitializeMapBoxConfig=Je,w.InitializeSentryConfig=Ge,w.InjectDependenciesContext=A,w.InjectDependenciesProvider=Le,w.MaskTextField=Qe,w.QueryClientProviderWithConfig=$e,w.RequireAuth=ze,w.dateAdapter=fe,w.distanceAdapter=de,w.getOrvalConfig=ut,w.handleImportModuleError=lt,w.useAdapter=nt,w.useAuth=et,w.useInfiniteDataGrid=qe,w.useResponseError=Ze,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
25
+ Check the top-level render call using <`+o+">.")}return r}}function De(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var o=At(r);if(ke[o])return;ke[o]=!0;var f="";e&&e._owner&&e._owner!==ae.current&&(f=" It was passed a child from "+W(e._owner.type)+"."),V(e),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',o,f),V(null)}}function Fe(e,r){{if(typeof e!="object")return;if(oe(e))for(var o=0;o<e.length;o++){var f=e[o];se(f)&&De(f,r)}else if(se(e))e._store&&(e._store.validated=!0);else if(e){var E=x(e);if(typeof E=="function"&&E!==e.entries)for(var p=E.call(e),m;!(m=p.next()).done;)se(m.value)&&De(m.value,r)}}}function It(e){{var r=e.type;if(r==null||typeof r=="string")return;var o;if(typeof r=="function")o=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===u||r.$$typeof===_))o=r.propTypes;else return;if(o){var f=W(r);Et(o,e.props,"prop",f,e)}else if(r.PropTypes!==void 0&&!ce){ce=!0;var E=W(r);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",E||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function kt(e){{for(var r=Object.keys(e.props),o=0;o<r.length;o++){var f=r[o];if(f!=="children"&&f!=="key"){V(e),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",f),V(null);break}}e.ref!==null&&(V(e),b("Invalid attribute `ref` supplied to `React.Fragment`."),V(null))}}function We(e,r,o,f,E,p){{var m=ft(e);if(!m){var g="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(g+=" 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 O=Ot();O?g+=O:g+=Ie();var P;e===null?P="null":oe(e)?P="array":e!==void 0&&e.$$typeof===n?(P="<"+(W(e.type)||"Unknown")+" />",g=" Did you accidentally export a JSX literal instead of a component?"):P=typeof e,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",P,g)}var T=xt(e,r,o,E,p);if(T==null)return T;if(m){var k=r.children;if(k!==void 0)if(f)if(oe(k)){for(var U=0;U<k.length;U++)Fe(k[U],e);Object.freeze&&Object.freeze(k)}else b("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 Fe(k,e)}return e===c?kt(T):It(T),T}}function Dt(e,r,o){return We(e,r,o,!0)}function Ft(e,r,o){return We(e,r,o,!1)}var Wt=Ft,Yt=Dt;G.Fragment=c,G.jsx=Wt,G.jsxs=Yt}()),G}process.env.NODE_ENV==="production"?ee.exports=Ne():ee.exports=Me();var F=ee.exports;const A=h.createContext({}),Le=({children:t,apiURL:n,libraries:i})=>{const c=h.useMemo(()=>({apiURL:n,libraries:i}),[n,i]);return F.jsx(A.Provider,{value:c,children:t})},ze=({Fallback:t,isLogged:n,loginPath:i="/login",localStorageKey:c="user",redirect401Path:a="/login",...l})=>{var b,N,M,L;const{libraries:v}=h.useContext(A),d=(l==null?void 0:l.reactRouter)||(v==null?void 0:v.reactRouter),u=(l==null?void 0:l.axios)||(v==null?void 0:v.axios);if(!d)throw new Error("React Router is not provided. You can provide it with InjectDependenciesProvider or directly in props.");const[y,R]=h.useState(null),{useLocation:_,Navigate:C,Outlet:s}=d,S=_(),I=h.useRef(!1),x=typeof n=="function"?n():!!n,D=typeof x=="boolean"?x:x==null?void 0:x.isLogged;return h.useEffect(()=>{I.current||(I.current=!0,u.interceptors.response.use(j=>j,async j=>{var Q;return typeof j=="object"&&j&&"response"in j&&j.response&&typeof j.response=="object"&&"status"in j.response&&j.response&&typeof j.response=="object"&&"status"in j.response&&((Q=j==null?void 0:j.response)==null?void 0:Q.status)===401&&(u.defaults.headers.common.Authorization=null,localStorage.removeItem(c),R(a)),Promise.reject(j)}))},[u.defaults.headers.common,u.interceptors.response,c,a]),D&&!y?F.jsx(h.Suspense,{fallback:t,children:(N=(b=S.state)==null?void 0:b.from)!=null&&N.state&&((L=(M=S.state)==null?void 0:M.from)==null?void 0:L.pathname)===i?F.jsx(C,{to:S.state.from.state.from.pathname+S.state.from.state.from.search,state:{from:S},replace:!0}):F.jsx(s,{})}):F.jsx(C,{to:i,state:{from:S},replace:!0})},Ve=({...t})=>{const{libraries:n}=h.useContext(A),i=(t==null?void 0:t.reactRouter)||(n==null?void 0:n.reactRouter),c=(t==null?void 0:t.gtm)||(n==null?void 0:n.gtm);if(!i)throw new Error("React Router is not provided. You can provide it with InjectDependenciesProvider or directly in props of GTMSendPageView.");if(!c)throw new Error("GTM is not provided. You can provide it with InjectDependenciesProvider or directly in props of GTMSendPageView.");const{useGoogleTagManager:a}=c,{useLocation:l,Outlet:v}=i,{pathname:d}=l(),{sendEvent:u}=a();return h.useEffect(()=>{u({event:"pageView",pathname:d})},[d,u]),F.jsx(v,{})},Ue=({tokenTypeKey:t="tokenType",userLocalStorageKey:n="user",tokenKey:i="accessToken",postContentType:c="application/json",...a})=>{const{apiURL:l=a.apiURL,libraries:v}=h.useContext(A),d=(a==null?void 0:a.axios)||(v==null?void 0:v.axios);if(!d)throw new Error("Axios is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(!(d!=null&&d.defaults))return null;const u=localStorage.getItem(n),y=u?JSON.parse(u):null,R=y!=null&&y[t]?y[t]:null,_=y!=null&&y[i]?y[i]:null,C=u?`${R} ${_}`:null;return d.defaults.baseURL=l,d.defaults.headers.post["Content-Type"]=c,C&&(d.defaults.headers.common.Authorization=C),null},Be=({debug:t,resources:n,...i})=>{const{libraries:c}=h.useContext(A),a=(i==null?void 0:i.i18)||(c==null?void 0:c.i18),{i18next:l,initReactI18next:v,languageDetector:d}=a||{};if(!a)throw new Error("i18 is not provided. You can provide it with InjectDependenciesProvider or directly in props.");return l!=null&&l.isInitialized||(l.use(d).use(v).init({debug:t,fallbackLng:"en",interpolation:{escapeValue:!1},load:"languageOnly",react:{bindI18n:"languageChanged loaded",useSuspense:!0},resources:n,returnNull:!1}).then(()=>{document.documentElement.lang!==l.resolvedLanguage&&l.resolvedLanguage&&document.documentElement.setAttribute("lang",l.resolvedLanguage)}),l.on("languageChanged",u=>{document.documentElement.setAttribute("lang",u)})),null},Ge=({dsn:t,integrations:n,tracesSampleRate:i,replaysSessionSampleRate:c,replaysOnErrorSampleRate:a,tracePropagationTargets:l,ignoreErrors:v,debug:d,environment:u,...y})=>{const{libraries:R}=h.useContext(A),_=(y==null?void 0:y.sentry)||(R==null?void 0:R.sentry),C=(y==null?void 0:y.reactRouter)||(R==null?void 0:R.reactRouter);if(!_)throw new Error("Sentry is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(!C)throw new Error("React Router is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(_.isInitialized())return null;const{createRoutesFromChildren:s,matchRoutes:S,useLocation:I,useNavigationType:x}=C;return(d||process.env.NODE_ENV==="prod"||process.env.NODE_ENV==="production")&&_.init({debug:d,dsn:t,environment:u||"production",ignoreErrors:[...v||[],/dynamically imported module/],integrations:[_.reactRouterV6BrowserTracingIntegration({createRoutesFromChildren:s,matchRoutes:S,useEffect:h.useEffect,useLocation:I,useNavigationType:x}),...n||[]],replaysOnErrorSampleRate:a||1,replaysSessionSampleRate:c||.1,tracePropagationTargets:l,tracesSampleRate:i||1}),null},Qe=({IMaskMixin:t,...n})=>{const i=h.useMemo(()=>t(({TextField:c,...a})=>F.jsx(c,{...a})),[t]);return F.jsx(i,{...n})},Je=({accessToken:t,...n})=>{const{libraries:i}=h.useContext(A),c=(n==null?void 0:n.mapbox)||(i==null?void 0:i.mapbox);if(!c)throw new Error("Mapbox is not provided. You can provide it with InjectDependenciesProvider or directly in props.");return t&&(c.accessToken=t),null},Xe=({language:t,...n})=>{const{libraries:i}=h.useContext(A),c=(n==null?void 0:n.dayjs)||(i==null?void 0:i.dayjs),a=(n==null?void 0:n.plugin)||(i==null?void 0:i.dayjsPlugin);if(!c)throw new Error("Dayjs is not provided. You can provide it with InjectDependenciesProvider or directly in props of InitializeDaysJSConfig.");return h.useEffect(()=>{(async()=>{var d;const v=t||((d=navigator.language)==null?void 0:d.slice(0,2))||"en";a&&a.forEach(u=>{u&&c.extend(u)}),await import("dayjs/locale/en"),await import("dayjs/locale/fr"),c.locale(v)})().then()},[c,a,t]),null},He=t=>t&&typeof t=="function",Ke=t=>t&&typeof t=="function",$e=({children:t,defaultQueriesOptions:n,defaultMutationsOptions:i,...c})=>{var u,y;const{libraries:a}=h.useContext(A),l=(c==null?void 0:c.QueryClient)||((u=a==null?void 0:a.reactQuery)==null?void 0:u.QueryClient),v=(c==null?void 0:c.QueryClientProvider)||((y=a==null?void 0:a.reactQuery)==null?void 0:y.QueryClientProvider);if(!l)throw new Error("QueryClient is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(!v)throw new Error("QueryClientProvider is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(!He(v))throw new Error("Provided QueryClientProvider dependencies are not valid.");if(!Ke(l))throw new Error("Provided QueryClient dependencies are not valid.");const d=new l({defaultOptions:{mutations:{...i},queries:{getNextPageParam:(R,_,C)=>R.length+(C||0),refetchOnWindowFocus:!1,retry:3,...n}}});return F.jsx(v,{client:d,children:t})},Ze=t=>{var y,R,_;const{libraries:n}=h.useContext(A),i=(t==null?void 0:t.i18)||(n==null?void 0:n.i18),c=((y=t==null?void 0:t.i18)==null?void 0:y.translateFunction)||((R=n==null?void 0:n.i18)==null?void 0:R.translateFunction),a=((_=i==null?void 0:i.i18next)==null?void 0:_.t)||c||(C=>C),{unknownErrorTranslationKey:l="error.unknownError"}=t||{},v=a(l),d=h.useCallback(C=>{var S,I,x,D,b,N,M,L,j;const{response:s}=C||{};return s!=null&&s.reason?String(s.reason):(S=s==null?void 0:s.data)!=null&&S.reason?String(s.data.reason):(I=s==null?void 0:s.data)!=null&&I.message?String(s.data.message):(D=(x=s==null?void 0:s.data)==null?void 0:x.detail)!=null&&D.length&&Array.isArray((b=s==null?void 0:s.data)==null?void 0:b.detail)&&((M=(N=s==null?void 0:s.data)==null?void 0:N.detail[0])!=null&&M.msg)&&typeof((j=(L=s==null?void 0:s.data)==null?void 0:L.detail[0])==null?void 0:j.msg)=="string"?String(s.data.detail[0].msg):v},[v]);return{getErrorCode:h.useCallback(C=>{var S,I,x;const{response:s}=C||{};return s!=null&&s.error_code?String(s==null?void 0:s.error_code):(S=s==null?void 0:s.data)!=null&&S.error_code?String((I=s==null?void 0:s.data)==null?void 0:I.error_code):s!=null&&s.error_code?String(s==null?void 0:s.error_code):(x=s==null?void 0:s.data)!=null&&x.error_code?String(s.data.error_code):"unknown_error_code"},[]),printError:d}},qe=({data:t,fetchNextPage:n,isFetchingNextPage:i,isInitialLoading:c,isLoading:a,enabled:l=!0})=>{const v=h.useCallback(async u=>{i||!l||await n({pageParam:(u==null?void 0:u.pageParam)||u.visibleRowsCount})},[l,n,i]),d=h.useMemo(()=>{if(t)return t.pages.reduce((u,y)=>[...u,...y],[])},[t]);return{fetchNextPageOnRowsScrollEnd:v,isLoading:i||a,loadingVariant:c?"skeleton":"linear",rows:d}},et=t=>{const{libraries:n}=h.useContext(A),i=(t==null?void 0:t.axios)||(n==null?void 0:n.axios);if(!i)throw new Error("Axios is not provided. You can provide it with InjectDependenciesProvider or directly in params of useAuth.");return{clearAuthenticationToken:()=>{i.defaults.headers.common.Authorization=null},setAuthenticationToken:({tokenType:l,accessToken:v})=>{i.defaults.headers.common.Authorization=`${l} ${v}`}}},fe=({library:t,date:n,format:i="ll"})=>t(n).format(i),de=(t,n="km")=>{const i=Number(t);return Number.isNaN(i)?`0 ${n}`:`${i.toFixed(2)} ${n}`},tt=t=>t!=null&&t.startsWith("/")?t!=null&&t.startsWith("/files")?t:`/files${t}`:t!=null&&t.startsWith("files")?`/${t}`:t!=null&&t.startsWith("files")?`/${t}`:`/files/${t}`,rt=({path:t,size:n,apiURL:i})=>{if(!t)return"";const c=tt(t),a=`${i}${c}`,l=a.match(/\.(jpeg|jpg|png|gif|bmp|webp|svg|avif)$/)!==null;return typeof n=="number"&&l?`${a.replace("/files",`/thumbs/${n}`)}`:a},nt=t=>{const{apiURL:n,libraries:i}=h.useContext(A),c=(t==null?void 0:t.dayjs)||(i==null?void 0:i.dayjs);return{dateAdapter:(v,d)=>{if(!c)throw new Error("Dayjs is not provided. You can provide it with InjectDependenciesProvider or directly in props.");return fe({date:v,format:d,library:c})},distanceAdapter:de,filePathAdapter:(v,d)=>{if(!n)throw new Error("API URL is not provided. You can provide it with InjectDependenciesProvider or directly in props to filePathAdapter.");return rt({apiURL:n,path:v,size:d})}}},ot=t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase(),it=t=>{const c=t.split("/").filter(a=>a.length>0).map(a=>a.replace(/\${([^}]*)}/g,"$1").split(/[_-]/).map(u=>u.charAt(0).toUpperCase()+u.slice(1)).join("")).join("");return c.charAt(0).toLowerCase()+c.slice(1)},at=t=>(t.split("/").pop()||t).replace(/\.json$/,"").replace(/^openapi\./,""),ct=(t,n,i)=>{const c=it(n),a=ot(i);return`${c}${a}`},st=t=>{if(t)return(t==null?void 0:t.reduce((n,i)=>(n[i]={query:{useInfinite:!0,useInfiniteQueryParam:"offset",useQuery:!0}},n),{}))||{}},ut=t=>(Array.isArray(t)?t:[t]).reduce((i,c)=>{const{output:a,operationsToGenerateInfiniteQueryHook:l,input:v="./openapi.json"}=c||{},d=at(v);return{...i,[d]:{hooks:{afterAllFilesWrite:"prettier src/api/ --write"},input:v,output:{baseUrl:a==null?void 0:a.baseUrl,client:"react-query",mode:"tags-split",override:{...(l==null?void 0:l.length)&&{operations:st(l)},header:u=>["Generated by orval 🍺",...u.title?[u.title]:[],...u.description?[u.description]:[]],mutator:{name:"axiosCustomInstance",path:`${__dirname}/axiosCustomInstance.ts`},operationName:ct,query:{useQuery:!0}},schemas:(a==null?void 0:a.schemas)||`src/api/${d}/model`,target:(a==null?void 0:a.target)||`src/api/${d}/services/api.ts`,...a}}}},{}),lt=t=>{const n="moduleFetchError";throw t.message.includes("Failed to fetch dynamically imported module")&&(document.cookie.split(";").some(c=>c.trim().startsWith(`${n}=`))||(document.cookie=`${n}=true; max-age=60; path=/`,window.location.reload())),t};w.GTMSendPageView=Ve,w.InitializeAxiosConfig=Ue,w.InitializeDaysJSConfig=Xe,w.InitializeI18nConfig=Be,w.InitializeMapBoxConfig=Je,w.InitializeSentryConfig=Ge,w.InjectDependenciesContext=A,w.InjectDependenciesProvider=Le,w.MaskTextField=Qe,w.QueryClientProviderWithConfig=$e,w.RequireAuth=ze,w.dateAdapter=fe,w.distanceAdapter=de,w.getOrvalConfig=ut,w.handleImportModuleError=lt,w.useAdapter=nt,w.useAuth=et,w.useInfiniteDataGrid=qe,w.useResponseError=Ze,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tracktor/shared-module",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "types": "./dist/main.d.ts",