@tracktor/shared-module 2.3.4 → 2.4.0

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