@tracktor/shared-module 2.28.0 → 2.30.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.
@@ -74,12 +74,16 @@ export interface PresenceEvent {
74
74
  userId: string;
75
75
  online: boolean;
76
76
  }
77
+ export interface ThreadArchivedEvent {
78
+ type: "thread_archived";
79
+ threadId: string;
80
+ }
77
81
  export interface ErrorEvent {
78
82
  type: "error";
79
83
  code: string;
80
84
  message: string;
81
85
  }
82
- export type ServerEvent = ReadyEvent | JoinedThread | LeftThread | NewMessageEvent | NewMessageNotification | MarkedRead | ThreadsListEvent | PresenceEvent | ErrorEvent;
86
+ export type ServerEvent = ReadyEvent | JoinedThread | LeftThread | NewMessageEvent | NewMessageNotification | MarkedRead | ThreadsListEvent | PresenceEvent | ThreadArchivedEvent | ErrorEvent;
83
87
  export interface ChatClientOptions {
84
88
  url: string;
85
89
  getToken: () => string | null;
@@ -98,5 +102,6 @@ export interface UseChatParams {
98
102
  onJoinedThread?: (event: JoinedThread) => void;
99
103
  onLeftThread?: (event: LeftThread) => void;
100
104
  onMarkedRead?: (event: MarkedRead) => void;
105
+ onThreadArchived?: (event: ThreadArchivedEvent) => void;
101
106
  onThreadsList?: (event: ThreadsListEvent) => void;
102
107
  }
package/dist/main.js CHANGED
@@ -413,13 +413,13 @@ const qe = ({ IMaskMixin: e, ...t }) => {
413
413
  } catch {
414
414
  return !1;
415
415
  }
416
- })(), Se = "user", Xe = ({
416
+ })(), Ae = "user", Xe = ({
417
417
  tokenTypeKey: e = "tokenType",
418
418
  tokenKey: t = "accessToken",
419
419
  postContentType: n = "application/json",
420
420
  ...s
421
421
  }) => {
422
- const { apiURL: o = s.apiURL, libraries: a, localStorageKeys: c } = C(j), u = s?.userLocalStorageKey || c?.user || Se, l = s?.axios || a?.axios;
422
+ const { apiURL: o = s.apiURL, libraries: a, localStorageKeys: c } = C(j), u = s?.userLocalStorageKey || c?.user || Ae, l = s?.axios || a?.axios;
423
423
  if (!l)
424
424
  throw new Error("Axios is not provided. You can provide it with InjectDependenciesProvider or directly in props.");
425
425
  if (!l?.defaults || z)
@@ -529,8 +529,8 @@ const qe = ({ IMaskMixin: e, ...t }) => {
529
529
  return window.addEventListener("vite:preloadError", e), () => {
530
530
  window.removeEventListener("vite:preloadError", e);
531
531
  };
532
- }, []), null), fe = /* @__PURE__ */ new WeakMap(), Ae = "user", nt = ({ Fallback: e, isLogged: t, loginPath: n = "/login", redirect401Path: s = "/login", ...o }) => {
533
- const { libraries: a, localStorageKeys: c } = C(j), u = o?.reactRouter || a?.reactRouter, l = o?.axios || a?.axios, f = o?.localStorageKey || c?.user || Ae;
532
+ }, []), null), fe = /* @__PURE__ */ new WeakMap(), Se = "user", nt = ({ Fallback: e, isLogged: t, loginPath: n = "/login", redirect401Path: s = "/login", ...o }) => {
533
+ const { libraries: a, localStorageKeys: c } = C(j), u = o?.reactRouter || a?.reactRouter, l = o?.axios || a?.axios, f = o?.localStorageKey || c?.user || Se;
534
534
  if (!u)
535
535
  throw new Error("React Router is not provided. You can provide it with InjectDependenciesProvider or directly in props.");
536
536
  const [i, h] = D(null), { useLocation: m, Navigate: y, Outlet: v } = u, A = m(), k = typeof t == "function" ? t() : !!t, g = typeof k == "boolean" ? k : k?.isLogged;
@@ -619,14 +619,7 @@ const qe = ({ IMaskMixin: e, ...t }) => {
619
619
  if (!w)
620
620
  return;
621
621
  const x = () => o ?? Le(y), K = (N) => {
622
- switch (N.type) {
623
- case "ready":
624
- l(!0), i(N.unreadCount ?? 0);
625
- break;
626
- case "new_message_notification":
627
- i(($) => $ + 1);
628
- break;
629
- }
622
+ N.type === "ready" && (l(!0), i(N.unreadCount ?? 0));
630
623
  for (const $ of A.current)
631
624
  $(N);
632
625
  }, Y = setTimeout(() => {
@@ -784,7 +777,8 @@ const qe = ({ IMaskMixin: e, ...t }) => {
784
777
  onJoinedThread: h,
785
778
  onLeftThread: m,
786
779
  onMarkedRead: y,
787
- onThreadsList: v
780
+ onThreadArchived: v,
781
+ onThreadsList: A
788
782
  } = o.current ?? {};
789
783
  switch (a.type) {
790
784
  case "ready":
@@ -811,9 +805,12 @@ const qe = ({ IMaskMixin: e, ...t }) => {
811
805
  case "marked_read":
812
806
  y?.(a);
813
807
  break;
814
- case "threads_list":
808
+ case "thread_archived":
815
809
  v?.(a);
816
810
  break;
811
+ case "threads_list":
812
+ A?.(a);
813
+ break;
817
814
  }
818
815
  }), [n]), s;
819
816
  }, Q = (e, t) => t === "short" ? e.split("-")[0] : e, ut = (e, t = "full") => {
package/dist/main.umd.cjs CHANGED
@@ -1,6 +1,6 @@
1
- (function(g,F){typeof exports=="object"&&typeof module<"u"?F(exports,require("axios"),require("react")):typeof define=="function"&&define.amd?define(["exports","axios","react"],F):(g=typeof globalThis<"u"?globalThis:g||self,F(g["@tracktor/shared-module"]={},g.axios,g.React))})(this,(function(g,F,l){"use strict";const ge=(e,t)=>{const r=F.CancelToken.source(),s=F({...e,...t,cancelToken:r.token}).then(({data:o})=>o);return s.cancel=()=>{r.cancel("Query was cancelled")},s},Q=e=>Array.isArray(e)?e.map(Q):e!==null&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([t,r])=>[t.replace(/_([a-z])/g,(s,o)=>o.toUpperCase()),Q(r)])):e,J=e=>Array.isArray(e)?e.map(J):e!==null&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([t,r])=>[t.replace(/[A-Z]/g,s=>`_${s.toLowerCase()}`),J(r)])):e;class ee{url;getToken;onEvent;onConnectionChange;shouldReconnect;maxReconnectAttempts;reconnectBaseDelay;ws=null;reconnectAttempt=0;reconnectTimer=null;intentionalClose=!1;joinedThreads=new Set;pendingMessages=[];_connected=!1;_ready=!1;constructor(t){this.url=t.url,this.getToken=t.getToken,this.onEvent=t.onEvent,this.onConnectionChange=t.onConnectionChange,this.shouldReconnect=t.reconnect??!0,this.maxReconnectAttempts=t.maxReconnectAttempts??Number.POSITIVE_INFINITY,this.reconnectBaseDelay=t.reconnectBaseDelay??1e3}get connected(){return this._connected}get ready(){return this._ready}connect(){const t=this.getToken();if(!t)return;this.intentionalClose=!1;const r=this.url.includes("?")?"&":"?",s=`${this.url}${r}token=${t}`;this.ws=new WebSocket(s),this.ws.onopen=()=>{this._connected=!0,this.reconnectAttempt=0,this.onConnectionChange?.(!0),this.rejoinThreads(),this.flushPendingMessages()},this.ws.onmessage=o=>{try{const a=JSON.parse(o.data),c=Q(a);c.type==="ready"&&(this._ready=!0),this.onEvent?.(c)}catch{}},this.ws.onclose=()=>{this._connected=!1,this._ready=!1,this.onConnectionChange?.(!1),!this.intentionalClose&&this.shouldReconnect&&this.reconnectAttempt<this.maxReconnectAttempts&&this.scheduleReconnect()},this.ws.onerror=()=>{}}disconnect(){this.intentionalClose=!0,this.pendingMessages=[],this.clearReconnectTimer(),this.ws&&(this.ws.close(),this.ws=null)}joinThread(t){this.joinedThreads.add(t),this.send({threadId:t,type:"join_thread"})}leaveThread(t){this.joinedThreads.delete(t),this.send({threadId:t,type:"leave_thread"})}sendMessage(t,r){if(r.length>1e3)throw new Error("Message body exceeds maximum length of 1000 characters");this.send({body:r,threadId:t,type:"send_message"})}markRead(t){this.send({threadId:t,type:"mark_read"})}listThreads(t,r){this.send({limit:t,offset:r,type:"list_threads"})}send(t){if(!this.ws||this.ws.readyState!==WebSocket.OPEN){this.pendingMessages.push(t);return}this.ws.send(JSON.stringify(J(t)))}flushPendingMessages(){const t=[...this.pendingMessages];this.pendingMessages=[];for(const r of t)this.send(r)}rejoinThreads(){for(const t of this.joinedThreads)this.send({threadId:t,type:"join_thread"})}scheduleReconnect(){this.clearReconnectTimer();const t=Math.min(this.reconnectBaseDelay*2**this.reconnectAttempt,3e4);this.reconnectAttempt++,this.reconnectTimer=setTimeout(()=>{this.connect()},t)}clearReconnectTimer(){this.reconnectTimer!==null&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}}var W={exports:{}},M={};var te;function me(){if(te)return M;te=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function r(s,o,a){var c=null;if(a!==void 0&&(c=""+a),o.key!==void 0&&(c=""+o.key),"key"in o){a={};for(var d in o)d!=="key"&&(a[d]=o[d])}else a=o;return o=a.ref,{$$typeof:e,type:s,key:c,ref:o!==void 0?o:null,props:a}}return M.Fragment=t,M.jsx=r,M.jsxs=r,M}var Y={};var ne;function ye(){return ne||(ne=1,process.env.NODE_ENV!=="production"&&(function(){function e(n){if(n==null)return null;if(typeof n=="function")return n.$$typeof===X?null:n.displayName||n.name||null;if(typeof n=="string")return n;switch(n){case P:return"Fragment";case f:return"Profiler";case y:return"StrictMode";case N:return"Suspense";case B:return"SuspenseList";case O:return"Activity"}if(typeof n=="object")switch(typeof n.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),n.$$typeof){case k:return"Portal";case R:return n.displayName||"Context";case S:return(n._context.displayName||"Context")+".Consumer";case A:var p=n.render;return n=n.displayName,n||(n=p.displayName||p.name||"",n=n!==""?"ForwardRef("+n+")":"ForwardRef"),n;case H:return p=n.displayName||null,p!==null?p:e(n.type)||"Memo";case v:p=n._payload,n=n._init;try{return e(n(p))}catch{}}return null}function t(n){return""+n}function r(n){try{t(n);var p=!1}catch{p=!0}if(p){p=console;var C=p.error,b=typeof Symbol=="function"&&Symbol.toStringTag&&n[Symbol.toStringTag]||n.constructor.name||"Object";return C.call(p,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",b),t(n)}}function s(n){if(n===P)return"<>";if(typeof n=="object"&&n!==null&&n.$$typeof===v)return"<...>";try{var p=e(n);return p?"<"+p+">":"<...>"}catch{return"<...>"}}function o(){var n=z.A;return n===null?null:n.getOwner()}function a(){return Error("react-stack-top-frame")}function c(n){if(x.call(n,"key")){var p=Object.getOwnPropertyDescriptor(n,"key").get;if(p&&p.isReactWarning)return!1}return n.key!==void 0}function d(n,p){function C(){ue||(ue=!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)",p))}C.isReactWarning=!0,Object.defineProperty(n,"key",{get:C,configurable:!0})}function u(){var n=e(this.type);return de[n]||(de[n]=!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.")),n=this.props.ref,n!==void 0?n:null}function h(n,p,C,b,V,q){var T=C.ref;return n={$$typeof:_,type:n,key:p,props:C,_owner:b},(T!==void 0?T:null)!==null?Object.defineProperty(n,"ref",{enumerable:!1,get:u}):Object.defineProperty(n,"ref",{enumerable:!1,value:null}),n._store={},Object.defineProperty(n._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(n,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(n,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:V}),Object.defineProperty(n,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:q}),Object.freeze&&(Object.freeze(n.props),Object.freeze(n)),n}function i(n,p,C,b,V,q){var T=p.children;if(T!==void 0)if(b)if(L(T)){for(b=0;b<T.length;b++)m(T[b]);Object.freeze&&Object.freeze(T)}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 m(T);if(x.call(p,"key")){T=e(n);var D=Object.keys(p).filter(function(nt){return nt!=="key"});b=0<D.length?"{key: someKey, "+D.join(": ..., ")+": ...}":"{key: someKey}",pe[T+b]||(D=0<D.length?"{"+D.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
1
+ (function(g,L){typeof exports=="object"&&typeof module<"u"?L(exports,require("axios"),require("react")):typeof define=="function"&&define.amd?define(["exports","axios","react"],L):(g=typeof globalThis<"u"?globalThis:g||self,L(g["@tracktor/shared-module"]={},g.axios,g.React))})(this,(function(g,L,l){"use strict";const ge=(e,t)=>{const r=L.CancelToken.source(),s=L({...e,...t,cancelToken:r.token}).then(({data:o})=>o);return s.cancel=()=>{r.cancel("Query was cancelled")},s},Q=e=>Array.isArray(e)?e.map(Q):e!==null&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([t,r])=>[t.replace(/_([a-z])/g,(s,o)=>o.toUpperCase()),Q(r)])):e,J=e=>Array.isArray(e)?e.map(J):e!==null&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([t,r])=>[t.replace(/[A-Z]/g,s=>`_${s.toLowerCase()}`),J(r)])):e;class ee{url;getToken;onEvent;onConnectionChange;shouldReconnect;maxReconnectAttempts;reconnectBaseDelay;ws=null;reconnectAttempt=0;reconnectTimer=null;intentionalClose=!1;joinedThreads=new Set;pendingMessages=[];_connected=!1;_ready=!1;constructor(t){this.url=t.url,this.getToken=t.getToken,this.onEvent=t.onEvent,this.onConnectionChange=t.onConnectionChange,this.shouldReconnect=t.reconnect??!0,this.maxReconnectAttempts=t.maxReconnectAttempts??Number.POSITIVE_INFINITY,this.reconnectBaseDelay=t.reconnectBaseDelay??1e3}get connected(){return this._connected}get ready(){return this._ready}connect(){const t=this.getToken();if(!t)return;this.intentionalClose=!1;const r=this.url.includes("?")?"&":"?",s=`${this.url}${r}token=${t}`;this.ws=new WebSocket(s),this.ws.onopen=()=>{this._connected=!0,this.reconnectAttempt=0,this.onConnectionChange?.(!0),this.rejoinThreads(),this.flushPendingMessages()},this.ws.onmessage=o=>{try{const a=JSON.parse(o.data),c=Q(a);c.type==="ready"&&(this._ready=!0),this.onEvent?.(c)}catch{}},this.ws.onclose=()=>{this._connected=!1,this._ready=!1,this.onConnectionChange?.(!1),!this.intentionalClose&&this.shouldReconnect&&this.reconnectAttempt<this.maxReconnectAttempts&&this.scheduleReconnect()},this.ws.onerror=()=>{}}disconnect(){this.intentionalClose=!0,this.pendingMessages=[],this.clearReconnectTimer(),this.ws&&(this.ws.close(),this.ws=null)}joinThread(t){this.joinedThreads.add(t),this.send({threadId:t,type:"join_thread"})}leaveThread(t){this.joinedThreads.delete(t),this.send({threadId:t,type:"leave_thread"})}sendMessage(t,r){if(r.length>1e3)throw new Error("Message body exceeds maximum length of 1000 characters");this.send({body:r,threadId:t,type:"send_message"})}markRead(t){this.send({threadId:t,type:"mark_read"})}listThreads(t,r){this.send({limit:t,offset:r,type:"list_threads"})}send(t){if(!this.ws||this.ws.readyState!==WebSocket.OPEN){this.pendingMessages.push(t);return}this.ws.send(JSON.stringify(J(t)))}flushPendingMessages(){const t=[...this.pendingMessages];this.pendingMessages=[];for(const r of t)this.send(r)}rejoinThreads(){for(const t of this.joinedThreads)this.send({threadId:t,type:"join_thread"})}scheduleReconnect(){this.clearReconnectTimer();const t=Math.min(this.reconnectBaseDelay*2**this.reconnectAttempt,3e4);this.reconnectAttempt++,this.reconnectTimer=setTimeout(()=>{this.connect()},t)}clearReconnectTimer(){this.reconnectTimer!==null&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}}var W={exports:{}},M={};var te;function me(){if(te)return M;te=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function r(s,o,a){var c=null;if(a!==void 0&&(c=""+a),o.key!==void 0&&(c=""+o.key),"key"in o){a={};for(var d in o)d!=="key"&&(a[d]=o[d])}else a=o;return o=a.ref,{$$typeof:e,type:s,key:c,ref:o!==void 0?o:null,props:a}}return M.Fragment=t,M.jsx=r,M.jsxs=r,M}var Y={};var ne;function ye(){return ne||(ne=1,process.env.NODE_ENV!=="production"&&(function(){function e(n){if(n==null)return null;if(typeof n=="function")return n.$$typeof===X?null:n.displayName||n.name||null;if(typeof n=="string")return n;switch(n){case P:return"Fragment";case f:return"Profiler";case y:return"StrictMode";case N:return"Suspense";case B:return"SuspenseList";case O:return"Activity"}if(typeof n=="object")switch(typeof n.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),n.$$typeof){case A:return"Portal";case R:return n.displayName||"Context";case S:return(n._context.displayName||"Context")+".Consumer";case k:var p=n.render;return n=n.displayName,n||(n=p.displayName||p.name||"",n=n!==""?"ForwardRef("+n+")":"ForwardRef"),n;case H:return p=n.displayName||null,p!==null?p:e(n.type)||"Memo";case w:p=n._payload,n=n._init;try{return e(n(p))}catch{}}return null}function t(n){return""+n}function r(n){try{t(n);var p=!1}catch{p=!0}if(p){p=console;var C=p.error,b=typeof Symbol=="function"&&Symbol.toStringTag&&n[Symbol.toStringTag]||n.constructor.name||"Object";return C.call(p,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",b),t(n)}}function s(n){if(n===P)return"<>";if(typeof n=="object"&&n!==null&&n.$$typeof===w)return"<...>";try{var p=e(n);return p?"<"+p+">":"<...>"}catch{return"<...>"}}function o(){var n=z.A;return n===null?null:n.getOwner()}function a(){return Error("react-stack-top-frame")}function c(n){if(x.call(n,"key")){var p=Object.getOwnPropertyDescriptor(n,"key").get;if(p&&p.isReactWarning)return!1}return n.key!==void 0}function d(n,p){function C(){ue||(ue=!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)",p))}C.isReactWarning=!0,Object.defineProperty(n,"key",{get:C,configurable:!0})}function u(){var n=e(this.type);return de[n]||(de[n]=!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.")),n=this.props.ref,n!==void 0?n:null}function h(n,p,C,b,V,q){var T=C.ref;return n={$$typeof:_,type:n,key:p,props:C,_owner:b},(T!==void 0?T:null)!==null?Object.defineProperty(n,"ref",{enumerable:!1,get:u}):Object.defineProperty(n,"ref",{enumerable:!1,value:null}),n._store={},Object.defineProperty(n._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(n,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(n,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:V}),Object.defineProperty(n,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:q}),Object.freeze&&(Object.freeze(n.props),Object.freeze(n)),n}function i(n,p,C,b,V,q){var T=p.children;if(T!==void 0)if(b)if(F(T)){for(b=0;b<T.length;b++)m(T[b]);Object.freeze&&Object.freeze(T)}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 m(T);if(x.call(p,"key")){T=e(n);var D=Object.keys(p).filter(function(nt){return nt!=="key"});b=0<D.length?"{key: someKey, "+D.join(": ..., ")+": ...}":"{key: someKey}",pe[T+b]||(D=0<D.length?"{"+D.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
2
2
  let props = %s;
3
3
  <%s {...props} />
4
4
  React keys must be passed directly to JSX without using spread:
5
5
  let props = %s;
6
- <%s key={someKey} {...props} />`,b,T,D,T),pe[T+b]=!0)}if(T=null,C!==void 0&&(r(C),T=""+C),c(p)&&(r(p.key),T=""+p.key),"key"in p){C={};for(var $ in p)$!=="key"&&(C[$]=p[$])}else C=p;return T&&d(C,typeof n=="function"?n.displayName||n.name||"Unknown":n),h(n,T,C,o(),V,q)}function m(n){E(n)?n._store&&(n._store.validated=1):typeof n=="object"&&n!==null&&n.$$typeof===v&&(n._payload.status==="fulfilled"?E(n._payload.value)&&n._payload.value._store&&(n._payload.value._store.validated=1):n._store&&(n._store.validated=1))}function E(n){return typeof n=="object"&&n!==null&&n.$$typeof===_}var w=l,_=Symbol.for("react.transitional.element"),k=Symbol.for("react.portal"),P=Symbol.for("react.fragment"),y=Symbol.for("react.strict_mode"),f=Symbol.for("react.profiler"),S=Symbol.for("react.consumer"),R=Symbol.for("react.context"),A=Symbol.for("react.forward_ref"),N=Symbol.for("react.suspense"),B=Symbol.for("react.suspense_list"),H=Symbol.for("react.memo"),v=Symbol.for("react.lazy"),O=Symbol.for("react.activity"),X=Symbol.for("react.client.reference"),z=w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,x=Object.prototype.hasOwnProperty,L=Array.isArray,Z=console.createTask?console.createTask:function(){return null};w={react_stack_bottom_frame:function(n){return n()}};var ue,de={},fe=w.react_stack_bottom_frame.bind(w,a)(),he=Z(s(a)),pe={};Y.Fragment=P,Y.jsx=function(n,p,C){var b=1e4>z.recentlyCreatedOwnerStacks++;return i(n,p,C,!1,b?Error("react-stack-top-frame"):fe,b?Z(s(n)):he)},Y.jsxs=function(n,p,C){var b=1e4>z.recentlyCreatedOwnerStacks++;return i(n,p,C,!0,b?Error("react-stack-top-frame"):fe,b?Z(s(n)):he)}})()),Y}var re;function Ee(){return re||(re=1,process.env.NODE_ENV==="production"?W.exports=me():W.exports=ye()),W.exports}var I=Ee();const we=({IMaskMixin:e,...t})=>{const r=l.useMemo(()=>e(({TextField:s,...o})=>I.jsx(s,{...o})),[e]);return I.jsx(r,{...t})},j=l.createContext({}),ve=({children:e,apiURL:t,libraries:r,localStorageKeys:s})=>{const o=l.useMemo(()=>({apiURL:t,libraries:r,localStorageKeys:s}),[t,r,s]);return I.jsx(j.Provider,{value:o,children:e})},Ce=({data:e,...t})=>{const{libraries:r}=l.useContext(j),s=t?.reactRouter||r?.reactRouter,o=t?.gtm||r?.gtm;if(!s)throw new Error("React Router is not provided. You can provide it with InjectDependenciesProvider or directly in props of GTMSendPageView.");if(!o)throw new Error("GTM is not provided. You can provide it with InjectDependenciesProvider or directly in props of GTMSendPageView.");const{useGoogleTagManager:a}=o,{useLocation:c,Outlet:d}=s,{pathname:u}=c(),{sendEvent:h}=a();return l.useEffect(()=>{h({event:"pageView",pathname:u,...e})},[e,u,h]),I.jsx(d,{})},U=(()=>{try{return typeof global=="object"&&global!==null&&("HermesInternal"in global||"__fbBatchedBridge"in global||"__metro"in global)||typeof window>"u"&&typeof global<"u"?!0:typeof navigator<"u"&&navigator.userAgent?/react.native|ReactNative/i.test(navigator.userAgent):!1}catch{return!1}})(),_e="user",Re=({tokenTypeKey:e="tokenType",tokenKey:t="accessToken",postContentType:r="application/json",...s})=>{const{apiURL:o=s.apiURL,libraries:a,localStorageKeys:c}=l.useContext(j),d=s?.userLocalStorageKey||c?.user||_e,u=s?.axios||a?.axios;if(!u)throw new Error("Axios is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(!u?.defaults||U)return null;if(typeof window<"u"&&window.localStorage){const h=localStorage.getItem(d),i=h?JSON.parse(h):null,m=i?.[e]?i[e]:null,E=i?.[t]?i[t]:null,w=h?`${m} ${E}`:null;w&&(u.defaults.headers.common.Authorization=w)}return u.defaults.baseURL=o,u.defaults.headers.post["Content-Type"]=r,null},be=({language:e,...t})=>{const{libraries:r}=l.useContext(j),s=t?.dayjs||r?.dayjs,o=t?.plugin||r?.dayjsPlugin;if(!s)throw new Error("Dayjs is not provided. You can provide it with InjectDependenciesProvider or directly in props of InitializeDaysJSConfig.");return l.useEffect(()=>{(async()=>{const c=e||navigator.language?.slice(0,2)||"en";o&&o.forEach(d=>{d&&s.extend(d)}),await import("dayjs/locale/en"),await import("dayjs/locale/fr"),s.locale(c)})().then()},[s,o,e]),null},Te=({debug:e,resources:t,...r})=>{const{libraries:s}=l.useContext(j),o=r?.i18||s?.i18,{i18next:a,initReactI18next:c,languageDetector:d}=o||{};if(U)return null;if(!o)throw new Error("i18 is not provided. You can provide it with InjectDependenciesProvider or directly in props.");return a?.isInitialized||(a.use(d).use(c).init({debug:e,fallbackLng:"en",interpolation:{escapeValue:!1},load:"languageOnly",react:{bindI18n:"languageChanged loaded",useSuspense:!0},resources:t,returnNull:!1}).then(()=>{document.documentElement.lang!==a.resolvedLanguage&&a.resolvedLanguage&&document.documentElement.setAttribute("lang",a.resolvedLanguage)}),a.on("languageChanged",u=>{document.documentElement.setAttribute("lang",u)})),null},Se=({dsn:e,integrations:t,tracesSampleRate:r,replaysSessionSampleRate:s,replaysOnErrorSampleRate:o,tracePropagationTargets:a,ignoreErrors:c,debug:d,environment:u,release:h,...i})=>{const{libraries:m}=l.useContext(j),E=i?.sentry||m?.sentry,w=i?.reactRouter||m?.reactRouter;if(!E)throw new Error("Sentry is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(!w)throw new Error("React Router is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(E.isInitialized())return null;const{createRoutesFromChildren:_,matchRoutes:k,useLocation:P,useNavigationType:y}=w;return(d||process.env.NODE_ENV==="prod"||process.env.NODE_ENV==="production")&&E.init({debug:d,dsn:e,environment:u||"production",ignoreErrors:[...c||[],/dynamically imported module/,/Cannot read properties of undefined \(reading 'default'\)/,/Loading chunk \d+ failed/,/ChunkLoadError/,/Failed to fetch dynamically imported module/,/vite:preloadError/],integrations:[E.reactRouterV6BrowserTracingIntegration({createRoutesFromChildren:_,matchRoutes:k,useEffect:l.useEffect,useLocation:P,useNavigationType:y}),...t||[]],release:h,replaysOnErrorSampleRate:o||1,replaysSessionSampleRate:s||.1,tracePropagationTargets:a,tracesSampleRate:r||1}),null},Ae=()=>(l.useEffect(()=>{if(U)return;const e=t=>{try{t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),window.location.reload()}catch{}};return window.addEventListener("vite:preloadError",e),()=>{window.removeEventListener("vite:preloadError",e)}},[]),null),oe=new WeakMap,ke="user",je=({Fallback:e,isLogged:t,loginPath:r="/login",redirect401Path:s="/login",...o})=>{const{libraries:a,localStorageKeys:c}=l.useContext(j),d=o?.reactRouter||a?.reactRouter,u=o?.axios||a?.axios,h=o?.localStorageKey||c?.user||ke;if(!d)throw new Error("React Router is not provided. You can provide it with InjectDependenciesProvider or directly in props.");const[i,m]=l.useState(null),{useLocation:E,Navigate:w,Outlet:_}=d,k=E(),P=typeof t=="function"?t():!!t,y=typeof P=="boolean"?P:P?.isLogged;return l.useEffect(()=>{oe.has(u)||(oe.set(u,!0),u.interceptors.response.use(f=>f,f=>(typeof f=="object"&&f&&"response"in f&&f.response&&typeof f.response=="object"&&"status"in f.response&&f.response&&typeof f.response=="object"&&"status"in f.response&&f?.response?.status===401&&(typeof f=="object"&&f&&"config"in f&&f.config&&typeof f.config=="object"&&"headers"in f.config&&f.config.headers&&typeof f.config.headers=="object"&&"Authorization"in f.config.headers&&f.config.headers.Authorization&&(u.defaults.headers.common.Authorization=null,typeof window<"u"&&window.localStorage&&localStorage.removeItem(h)),m(s)),Promise.reject(f))))},[u,h,s]),y&&!i?I.jsx(l.Suspense,{fallback:e,children:k.state?.from?.state&&k.state?.from?.pathname===r?I.jsx(w,{to:k.state.from.state.from.pathname+k.state.from.state.from.search,replace:!0}):I.jsx(_,{})}):I.jsx(w,{to:r+k.search,state:{from:k},replace:!0})},Pe=e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase(),Oe=e=>{const t=e.split(/[/\\]/).pop()||"";return t.substring(0,t.lastIndexOf("."))},Ie=e=>{const s=e.split("/").filter(o=>o.length>0).map(o=>o.replace(/\${([^}]*)}/g,"$1").split(/[_-]/).map(u=>u.charAt(0).toUpperCase()+u.slice(1)).join("")).join("");return s.charAt(0).toLowerCase()+s.slice(1)},Ne=e=>(e.split("/").pop()||e).replace(/\.json$/,"").replace(/^openapi\./,""),xe=(e,t,r,s)=>{const o=Ie(t),a=Pe(r),c=`${o}${a}`;return e&&typeof e=="object"&&"operationId"in e&&s?.includes(String(e.operationId))?`${c}AsQuery`:c},Le=(e,t)=>{const r={};return e?.forEach(s=>{r[s]={query:{useInfinite:!0,useInfiniteQueryParam:"offset",useQuery:!0}}}),t?.filter(s=>!r[s]).forEach(s=>{r[s]={query:{useQuery:!0}}}),Object.keys(r).length?r:void 0},Fe=e=>(Array.isArray(e)?e:[e]).reduce((r,s)=>{const{output:o,useInfiniteIds:a,useQueryIds:c,input:d="./openapi.json",customAxiosInstancePath:u,overrideApiName:h}=s||{},i=h||Ne(d),m=u||"./node_modules/@tracktor/shared-module/dist/axiosCustomInstance.ts";return{...r,[i]:{input:d,output:{baseUrl:o?.baseUrl,client:"react-query",mode:"tags-split",override:{...(a?.length||c?.length)&&{operations:Le(a,c)},header:E=>["Generated by orval 🍺",...E.title?[E.title]:[],...E.description?[E.description]:[]],mutator:{name:Oe(m),path:m},operationName:(E,w,_)=>xe(E,w,_,c),query:{useQuery:!0}},schemas:o?.schemas||`src/api/${i}/model`,target:o?.target||`src/api/${i}/services/api.ts`,...o}}}},{}),De="user",Me=e=>{const t=e.startsWith("https")?"wss":"ws",r=e.replace(/^https?:\/\//,"");return`${t}://${r}/v2/threads/ws`},Ye=e=>{try{const t=localStorage.getItem(e);return t?JSON.parse(t)?.accessToken??null:null}catch{return null}},K=l.createContext(null),Ue=({children:e,reconnect:t=!0,enabled:r=!0,url:s,token:o})=>{const[a,c]=l.useState(!1),[d,u]=l.useState(!1),[h,i]=l.useState(0),{apiURL:m,localStorageKeys:E}=l.useContext(j),w=E?.user||De,_=l.useRef(null),k=l.useRef(new Set);l.useEffect(()=>{if(!r)return;const v=s||(m?Me(m):null);if(!v)return;const O=()=>o??Ye(w),X=x=>{switch(x.type){case"ready":u(!0),i(x.unreadCount??0);break;case"new_message_notification":i(L=>L+1);break}for(const L of k.current)L(x)},z=setTimeout(()=>{const x=new ee({getToken:O,onConnectionChange:L=>{c(L),L||u(!1)},onEvent:X,reconnect:t,url:v});_.current=x,x.connect()},0);return()=>{clearTimeout(z),_.current?.disconnect(),_.current=null}},[r,s,o,m,t,w]);const P=l.useCallback(v=>{_.current?.joinThread(v)},[]),y=l.useCallback(v=>{_.current?.leaveThread(v)},[]),f=l.useCallback((v,O)=>{_.current?.sendMessage(v,O)},[]),S=l.useCallback(v=>{_.current?.markRead(v)},[]),R=l.useCallback((v,O)=>{_.current?.listThreads(v,O)},[]),A=l.useCallback((v=1)=>{i(O=>O+v)},[]),N=l.useCallback((v=1)=>{i(O=>Math.max(0,O-v))},[]),B=l.useCallback(v=>(k.current.add(v),()=>{k.current.delete(v)}),[]),H={decrementUnreadCount:N,incrementUnreadCount:A,isConnected:a,isReady:d,joinThread:P,leaveThread:y,listThreads:R,markRead:S,sendMessage:f,subscribe:B,unreadCount:h};return I.jsx(K.Provider,{value:H,children:e})},ze=e=>e&&typeof e=="function",We=e=>e&&typeof e=="function",Ge=({children:e,defaultQueriesOptions:t,defaultMutationsOptions:r,...s})=>{const{libraries:o}=l.useContext(j),a=s?.QueryClient||o?.reactQuery?.QueryClient,c=s?.QueryClientProvider||o?.reactQuery?.QueryClientProvider;if(!a)throw new Error("QueryClient is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(!c)throw new Error("QueryClientProvider is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(!ze(c))throw new Error("Provided QueryClientProvider dependencies are not valid.");if(!We(a))throw new Error("Provided QueryClient dependencies are not valid.");const d=new a({defaultOptions:{mutations:{...r},queries:{getNextPageParam:(u,h,i)=>u.length+(i||0),refetchOnWindowFocus:!1,retry:3,...t}}});return I.jsx(c,{client:d,children:e})},se=({library:e,date:t,format:r="ll"})=>e(t).format(r),ae=(e,t)=>{const{fractionDigits:r=0,metric:s="km",spacingBetween:o=!0}=t||{},a=Number(e),c=o?" ":"";return Number.isNaN(a)?`0${c}${s}`:`${a.toFixed(r)}${c}${s}`},ie=e=>!e||typeof e!="string"?"":e.replace(/_/g," ").toLowerCase().split(" ").map(r=>r.length>0?r.charAt(0).toUpperCase()+r.slice(1):r).join(" "),Ve=e=>e?.startsWith("/")?e?.startsWith("/files")?e:`/files${e}`:e?.startsWith("files")?`/${e}`:`/files/${e}`,Qe=({path:e,size:t,apiURL:r})=>{if(!e)return"";const s=Ve(e),o=`${r}${s}`,a=o.match(/\.(jpeg|jpg|png|gif|bmp|webp|svg|avif)$/)!==null;return typeof t=="number"&&a?`${o.replace("/files",`/thumbs/${t}`)}`:o},Je=e=>{const{apiURL:t,libraries:r}=l.useContext(j),s=e?.dayjs||r?.dayjs;return{dateAdapter:(c,d)=>{if(!s)throw new Error("Dayjs is not provided. You can provide it with InjectDependenciesProvider or directly in props.");return se({date:c,format:d,library:s})},distanceAdapter:ae,filePathAdapter:(c,d)=>{if(!t)throw new Error("API URL is not provided. You can provide it with InjectDependenciesProvider or directly in props to filePathAdapter.");return typeof c=="string"&&/^https?:\/\//.test(c)?c:Qe({apiURL:t,path:c,size:d})},worksiteNameAdapter:ie}},Ke=e=>{const{libraries:t,localStorageKeys:r}=l.useContext(j),s=e?.axios||t?.axios,o=e?.localStorageKey||r?.user||"user";if(!s)throw new Error("Axios is not provided. You can provide it with InjectDependenciesProvider or directly in params of useAuth.");const a=l.useCallback(({tokenType:d,accessToken:u})=>{s.defaults.headers.common.Authorization=`${d} ${u}`},[s.defaults.headers.common]),c=()=>{s.defaults.headers.common.Authorization=null};return l.useEffect(()=>{if(U)return;const d=({newValue:u,key:h})=>{if(h===o&&u)try{const{accessToken:i,tokenType:m}=JSON.parse(u);a({accessToken:i,tokenType:m})}catch(i){console.error("Failed to parse newValue from localStorage:",i)}};return window.addEventListener("storage",d),()=>{window.removeEventListener("storage",d)}},[o,a]),{clearAuthenticationToken:c,setAuthenticationToken:a}},Be=e=>{const t=l.useContext(K);if(!t)throw new Error("useChat must be used within ChatProvider");const{subscribe:r,...s}=t,o=l.useRef(e);return o.current=e,l.useEffect(()=>r(a=>{const{onReady:c,onNewMessage:d,onNewMessageNotification:u,onPresence:h,onError:i,onJoinedThread:m,onLeftThread:E,onMarkedRead:w,onThreadsList:_}=o.current??{};switch(a.type){case"ready":c?.(a);break;case"new_message":d?.(a);break;case"new_message_notification":u?.(a);break;case"presence":h?.(a);break;case"error":i?.(a);break;case"joined_thread":m?.(a);break;case"left_thread":E?.(a);break;case"marked_read":w?.(a);break;case"threads_list":_?.(a);break}}),[r]),s},G=(e,t)=>t==="short"?e.split("-")[0]:e,He=(e,t="full")=>{const[r,s]=l.useState(()=>{const o=e?.language||navigator.language;return e&&"isInitialized"in e&&e.isInitialized,G(o,t)});return l.useEffect(()=>{e&&"isInitialized"in e&&e.isInitialized&&e.language&&s(G(e.language,t));const o=a=>{s(G(a,t))};return e?.on?.("languageChanged",o),()=>{e?.off?.("languageChanged",o)}},[e,t]),r},Xe="tracktor.filter",Ze={getFilter:()=>{},getFilters:()=>({}),handleFilter:()=>()=>{},setFilter:()=>{}},ce=e=>{try{return JSON.parse(e)}catch{return e}},le=(e,t,r)=>`${r}_${e}=>${t}`,qe=e=>e.reduce((t,r)=>{const s=localStorage.getItem(r);if(s)try{const o=JSON.parse(s),a=Object.keys(o)?.[0];a&&(t[a]=Object.values(o)?.[0])}catch{}return t},{}),$e=e=>{const{libraries:t,localStorageKeys:r}=l.useContext(j),s=e?.reactRouter||t?.reactRouter,{pathname:o}=s?.useLocation?.()??{pathname:"/"},[a,c]=s?.useSearchParams?.()??[new URLSearchParams,()=>{}],[d,u]=l.useState({}),h=r?.filter||Xe,i=e?.syncWithUrl===void 0?!0:e?.syncWithUrl,m=e?.persistToLocalStorage===void 0?!0:e?.persistToLocalStorage;if(U)return Ze;if(!s)throw new Error("React Router is not provided. You can provide it with InjectDependenciesProvider or directly in props of reactRouter.");const E=()=>Object.keys(localStorage).filter(y=>y.startsWith(h)&&y.endsWith(e?.pathname||o)),w=(y,f,S=!0)=>{const R=le(y,e?.pathname||o,h);if(!f||Array.isArray(f)&&!f.length){i?(a.delete(y),c(a)):u(A=>{const N={...A};return delete N[y],N}),m&&localStorage.removeItem(R);return}m&&S&&f&&localStorage.setItem(R,JSON.stringify({...a,[y]:f})),i&&f?(a.set(y,JSON.stringify(f)),c(a)):!i&&f&&u(A=>({...A,[y]:f}))};return{getFilter:(y,f)=>{if(i){const S=a.get(y);if(S)return ce(S)}else{const S=d[y];if(S!==void 0)return S}if(m){const S=le(y,e?.pathname||o,h),R=localStorage.getItem(S);if(R)try{const A=JSON.parse(R)[y];return!i&&A!==void 0&&u(N=>({...N,[y]:A})),A}catch{}}return f},getFilters:()=>{const y=m?qe(E()):{};if(i){const f=Array.from(a.entries()).reduce((S,[R,A])=>(S[R]=ce(A),S),{});return{...y,...f}}return{...y,...d}},handleFilter:(y,f)=>(S,R)=>{if(R||Array.isArray(R)&&R.length===0){const A=f||"value",N=typeof R=="object"&&A in R?R[A]:R;w(y,N);return}w(y,void 0)},setFilter:w}},et=({data:e,fetchNextPage:t,isFetchingNextPage:r,isInitialLoading:s,isLoading:o,enabled:a=!0})=>{const c=l.useCallback(async u=>{r||!a||await t({pageParam:u?.pageParam||u.visibleRowsCount})},[a,t,r]),d=l.useMemo(()=>{if(e)return e.pages.reduce((u,h)=>[...u,...h],[])},[e]);return{fetchNextPageOnRowsScrollEnd:c,isLoading:r||o,loadingVariant:s?"skeleton":"linear-progress",rows:d}},tt=e=>{const{libraries:t}=l.useContext(j),r=e?.i18||t?.i18,s=e?.i18?.translateFunction||t?.i18?.translateFunction,o=r?.i18next?.t||s||(h=>h),{unknownErrorTranslationKey:a="error.unknownError"}=e||{},c=o(a),d=l.useCallback(h=>{if(h&&typeof h=="object"&&"response"in h){const{response:i}=h||{};if(i&&typeof i=="object"&&"reason"in i&&i.reason)return String(i.reason);if(i&&typeof i=="object"&&"data"in i&&i.data&&typeof i.data=="object"&&"reason"in i.data&&i.data.reason)return String(i.data.reason);if(i&&typeof i=="object"&&"data"in i&&i.data&&typeof i.data=="object"&&"message"in i.data&&i.data.message)return String(i.data.message);if(i&&typeof i=="object"&&"data"in i&&i.data&&typeof i.data=="object"&&"detail"in i.data){const{detail:m}=i.data;if(Array.isArray(m)&&m.length>0&&typeof m[0]=="object"&&m[0]!==null&&"msg"in m[0]){const{msg:E}=m[0];if(typeof E=="string")return String(E)}}}return h instanceof Error?h.message:c},[c]);return{getErrorCode:l.useCallback(h=>{const{response:i}=h||{};return i?.error_code?String(i?.error_code):i?.data?.error_code?String(i?.data?.error_code):i?.error_code?String(i?.error_code):i?.data?.error_code?String(i.data.error_code):"unknown_error_code"},[]),printError:d}};g.ChatClient=ee,g.ChatContext=K,g.ChatProvider=Ue,g.GTMSendPageView=Ce,g.InitializeAxiosConfig=Re,g.InitializeDaysJSConfig=be,g.InitializeI18nConfig=Te,g.InitializeSentryConfig=Se,g.InjectDependenciesContext=j,g.InjectDependenciesProvider=ve,g.MaskTextField=we,g.PreloadErrorHandler=Ae,g.QueryClientProviderWithConfig=Ge,g.RequireAuth=je,g.axiosCustomInstance=ge,g.dateAdapter=se,g.distanceAdapter=ae,g.getOrvalConfig=Fe,g.useAdapter=Je,g.useAuth=Ke,g.useChat=Be,g.useCurrentLanguage=He,g.useFilters=$e,g.useInfiniteDataGrid=et,g.useResponseError=tt,g.worksiteNameAdapter=ie,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
6
+ <%s key={someKey} {...props} />`,b,T,D,T),pe[T+b]=!0)}if(T=null,C!==void 0&&(r(C),T=""+C),c(p)&&(r(p.key),T=""+p.key),"key"in p){C={};for(var $ in p)$!=="key"&&(C[$]=p[$])}else C=p;return T&&d(C,typeof n=="function"?n.displayName||n.name||"Unknown":n),h(n,T,C,o(),V,q)}function m(n){E(n)?n._store&&(n._store.validated=1):typeof n=="object"&&n!==null&&n.$$typeof===w&&(n._payload.status==="fulfilled"?E(n._payload.value)&&n._payload.value._store&&(n._payload.value._store.validated=1):n._store&&(n._store.validated=1))}function E(n){return typeof n=="object"&&n!==null&&n.$$typeof===_}var v=l,_=Symbol.for("react.transitional.element"),A=Symbol.for("react.portal"),P=Symbol.for("react.fragment"),y=Symbol.for("react.strict_mode"),f=Symbol.for("react.profiler"),S=Symbol.for("react.consumer"),R=Symbol.for("react.context"),k=Symbol.for("react.forward_ref"),N=Symbol.for("react.suspense"),B=Symbol.for("react.suspense_list"),H=Symbol.for("react.memo"),w=Symbol.for("react.lazy"),O=Symbol.for("react.activity"),X=Symbol.for("react.client.reference"),z=v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,x=Object.prototype.hasOwnProperty,F=Array.isArray,Z=console.createTask?console.createTask:function(){return null};v={react_stack_bottom_frame:function(n){return n()}};var ue,de={},fe=v.react_stack_bottom_frame.bind(v,a)(),he=Z(s(a)),pe={};Y.Fragment=P,Y.jsx=function(n,p,C){var b=1e4>z.recentlyCreatedOwnerStacks++;return i(n,p,C,!1,b?Error("react-stack-top-frame"):fe,b?Z(s(n)):he)},Y.jsxs=function(n,p,C){var b=1e4>z.recentlyCreatedOwnerStacks++;return i(n,p,C,!0,b?Error("react-stack-top-frame"):fe,b?Z(s(n)):he)}})()),Y}var re;function Ee(){return re||(re=1,process.env.NODE_ENV==="production"?W.exports=me():W.exports=ye()),W.exports}var I=Ee();const ve=({IMaskMixin:e,...t})=>{const r=l.useMemo(()=>e(({TextField:s,...o})=>I.jsx(s,{...o})),[e]);return I.jsx(r,{...t})},j=l.createContext({}),we=({children:e,apiURL:t,libraries:r,localStorageKeys:s})=>{const o=l.useMemo(()=>({apiURL:t,libraries:r,localStorageKeys:s}),[t,r,s]);return I.jsx(j.Provider,{value:o,children:e})},Ce=({data:e,...t})=>{const{libraries:r}=l.useContext(j),s=t?.reactRouter||r?.reactRouter,o=t?.gtm||r?.gtm;if(!s)throw new Error("React Router is not provided. You can provide it with InjectDependenciesProvider or directly in props of GTMSendPageView.");if(!o)throw new Error("GTM is not provided. You can provide it with InjectDependenciesProvider or directly in props of GTMSendPageView.");const{useGoogleTagManager:a}=o,{useLocation:c,Outlet:d}=s,{pathname:u}=c(),{sendEvent:h}=a();return l.useEffect(()=>{h({event:"pageView",pathname:u,...e})},[e,u,h]),I.jsx(d,{})},U=(()=>{try{return typeof global=="object"&&global!==null&&("HermesInternal"in global||"__fbBatchedBridge"in global||"__metro"in global)||typeof window>"u"&&typeof global<"u"?!0:typeof navigator<"u"&&navigator.userAgent?/react.native|ReactNative/i.test(navigator.userAgent):!1}catch{return!1}})(),_e="user",Re=({tokenTypeKey:e="tokenType",tokenKey:t="accessToken",postContentType:r="application/json",...s})=>{const{apiURL:o=s.apiURL,libraries:a,localStorageKeys:c}=l.useContext(j),d=s?.userLocalStorageKey||c?.user||_e,u=s?.axios||a?.axios;if(!u)throw new Error("Axios is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(!u?.defaults||U)return null;if(typeof window<"u"&&window.localStorage){const h=localStorage.getItem(d),i=h?JSON.parse(h):null,m=i?.[e]?i[e]:null,E=i?.[t]?i[t]:null,v=h?`${m} ${E}`:null;v&&(u.defaults.headers.common.Authorization=v)}return u.defaults.baseURL=o,u.defaults.headers.post["Content-Type"]=r,null},be=({language:e,...t})=>{const{libraries:r}=l.useContext(j),s=t?.dayjs||r?.dayjs,o=t?.plugin||r?.dayjsPlugin;if(!s)throw new Error("Dayjs is not provided. You can provide it with InjectDependenciesProvider or directly in props of InitializeDaysJSConfig.");return l.useEffect(()=>{(async()=>{const c=e||navigator.language?.slice(0,2)||"en";o&&o.forEach(d=>{d&&s.extend(d)}),await import("dayjs/locale/en"),await import("dayjs/locale/fr"),s.locale(c)})().then()},[s,o,e]),null},Te=({debug:e,resources:t,...r})=>{const{libraries:s}=l.useContext(j),o=r?.i18||s?.i18,{i18next:a,initReactI18next:c,languageDetector:d}=o||{};if(U)return null;if(!o)throw new Error("i18 is not provided. You can provide it with InjectDependenciesProvider or directly in props.");return a?.isInitialized||(a.use(d).use(c).init({debug:e,fallbackLng:"en",interpolation:{escapeValue:!1},load:"languageOnly",react:{bindI18n:"languageChanged loaded",useSuspense:!0},resources:t,returnNull:!1}).then(()=>{document.documentElement.lang!==a.resolvedLanguage&&a.resolvedLanguage&&document.documentElement.setAttribute("lang",a.resolvedLanguage)}),a.on("languageChanged",u=>{document.documentElement.setAttribute("lang",u)})),null},Se=({dsn:e,integrations:t,tracesSampleRate:r,replaysSessionSampleRate:s,replaysOnErrorSampleRate:o,tracePropagationTargets:a,ignoreErrors:c,debug:d,environment:u,release:h,...i})=>{const{libraries:m}=l.useContext(j),E=i?.sentry||m?.sentry,v=i?.reactRouter||m?.reactRouter;if(!E)throw new Error("Sentry is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(!v)throw new Error("React Router is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(E.isInitialized())return null;const{createRoutesFromChildren:_,matchRoutes:A,useLocation:P,useNavigationType:y}=v;return(d||process.env.NODE_ENV==="prod"||process.env.NODE_ENV==="production")&&E.init({debug:d,dsn:e,environment:u||"production",ignoreErrors:[...c||[],/dynamically imported module/,/Cannot read properties of undefined \(reading 'default'\)/,/Loading chunk \d+ failed/,/ChunkLoadError/,/Failed to fetch dynamically imported module/,/vite:preloadError/],integrations:[E.reactRouterV6BrowserTracingIntegration({createRoutesFromChildren:_,matchRoutes:A,useEffect:l.useEffect,useLocation:P,useNavigationType:y}),...t||[]],release:h,replaysOnErrorSampleRate:o||1,replaysSessionSampleRate:s||.1,tracePropagationTargets:a,tracesSampleRate:r||1}),null},Ae=()=>(l.useEffect(()=>{if(U)return;const e=t=>{try{t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),window.location.reload()}catch{}};return window.addEventListener("vite:preloadError",e),()=>{window.removeEventListener("vite:preloadError",e)}},[]),null),oe=new WeakMap,ke="user",je=({Fallback:e,isLogged:t,loginPath:r="/login",redirect401Path:s="/login",...o})=>{const{libraries:a,localStorageKeys:c}=l.useContext(j),d=o?.reactRouter||a?.reactRouter,u=o?.axios||a?.axios,h=o?.localStorageKey||c?.user||ke;if(!d)throw new Error("React Router is not provided. You can provide it with InjectDependenciesProvider or directly in props.");const[i,m]=l.useState(null),{useLocation:E,Navigate:v,Outlet:_}=d,A=E(),P=typeof t=="function"?t():!!t,y=typeof P=="boolean"?P:P?.isLogged;return l.useEffect(()=>{oe.has(u)||(oe.set(u,!0),u.interceptors.response.use(f=>f,f=>(typeof f=="object"&&f&&"response"in f&&f.response&&typeof f.response=="object"&&"status"in f.response&&f.response&&typeof f.response=="object"&&"status"in f.response&&f?.response?.status===401&&(typeof f=="object"&&f&&"config"in f&&f.config&&typeof f.config=="object"&&"headers"in f.config&&f.config.headers&&typeof f.config.headers=="object"&&"Authorization"in f.config.headers&&f.config.headers.Authorization&&(u.defaults.headers.common.Authorization=null,typeof window<"u"&&window.localStorage&&localStorage.removeItem(h)),m(s)),Promise.reject(f))))},[u,h,s]),y&&!i?I.jsx(l.Suspense,{fallback:e,children:A.state?.from?.state&&A.state?.from?.pathname===r?I.jsx(v,{to:A.state.from.state.from.pathname+A.state.from.state.from.search,replace:!0}):I.jsx(_,{})}):I.jsx(v,{to:r+A.search,state:{from:A},replace:!0})},Pe=e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase(),Oe=e=>{const t=e.split(/[/\\]/).pop()||"";return t.substring(0,t.lastIndexOf("."))},Ie=e=>{const s=e.split("/").filter(o=>o.length>0).map(o=>o.replace(/\${([^}]*)}/g,"$1").split(/[_-]/).map(u=>u.charAt(0).toUpperCase()+u.slice(1)).join("")).join("");return s.charAt(0).toLowerCase()+s.slice(1)},Ne=e=>(e.split("/").pop()||e).replace(/\.json$/,"").replace(/^openapi\./,""),xe=(e,t,r,s)=>{const o=Ie(t),a=Pe(r),c=`${o}${a}`;return e&&typeof e=="object"&&"operationId"in e&&s?.includes(String(e.operationId))?`${c}AsQuery`:c},Le=(e,t)=>{const r={};return e?.forEach(s=>{r[s]={query:{useInfinite:!0,useInfiniteQueryParam:"offset",useQuery:!0}}}),t?.filter(s=>!r[s]).forEach(s=>{r[s]={query:{useQuery:!0}}}),Object.keys(r).length?r:void 0},Fe=e=>(Array.isArray(e)?e:[e]).reduce((r,s)=>{const{output:o,useInfiniteIds:a,useQueryIds:c,input:d="./openapi.json",customAxiosInstancePath:u,overrideApiName:h}=s||{},i=h||Ne(d),m=u||"./node_modules/@tracktor/shared-module/dist/axiosCustomInstance.ts";return{...r,[i]:{input:d,output:{baseUrl:o?.baseUrl,client:"react-query",mode:"tags-split",override:{...(a?.length||c?.length)&&{operations:Le(a,c)},header:E=>["Generated by orval 🍺",...E.title?[E.title]:[],...E.description?[E.description]:[]],mutator:{name:Oe(m),path:m},operationName:(E,v,_)=>xe(E,v,_,c),query:{useQuery:!0}},schemas:o?.schemas||`src/api/${i}/model`,target:o?.target||`src/api/${i}/services/api.ts`,...o}}}},{}),De="user",Me=e=>{const t=e.startsWith("https")?"wss":"ws",r=e.replace(/^https?:\/\//,"");return`${t}://${r}/v2/threads/ws`},Ye=e=>{try{const t=localStorage.getItem(e);return t?JSON.parse(t)?.accessToken??null:null}catch{return null}},K=l.createContext(null),Ue=({children:e,reconnect:t=!0,enabled:r=!0,url:s,token:o})=>{const[a,c]=l.useState(!1),[d,u]=l.useState(!1),[h,i]=l.useState(0),{apiURL:m,localStorageKeys:E}=l.useContext(j),v=E?.user||De,_=l.useRef(null),A=l.useRef(new Set);l.useEffect(()=>{if(!r)return;const w=s||(m?Me(m):null);if(!w)return;const O=()=>o??Ye(v),X=x=>{x.type==="ready"&&(u(!0),i(x.unreadCount??0));for(const F of A.current)F(x)},z=setTimeout(()=>{const x=new ee({getToken:O,onConnectionChange:F=>{c(F),F||u(!1)},onEvent:X,reconnect:t,url:w});_.current=x,x.connect()},0);return()=>{clearTimeout(z),_.current?.disconnect(),_.current=null}},[r,s,o,m,t,v]);const P=l.useCallback(w=>{_.current?.joinThread(w)},[]),y=l.useCallback(w=>{_.current?.leaveThread(w)},[]),f=l.useCallback((w,O)=>{_.current?.sendMessage(w,O)},[]),S=l.useCallback(w=>{_.current?.markRead(w)},[]),R=l.useCallback((w,O)=>{_.current?.listThreads(w,O)},[]),k=l.useCallback((w=1)=>{i(O=>O+w)},[]),N=l.useCallback((w=1)=>{i(O=>Math.max(0,O-w))},[]),B=l.useCallback(w=>(A.current.add(w),()=>{A.current.delete(w)}),[]),H={decrementUnreadCount:N,incrementUnreadCount:k,isConnected:a,isReady:d,joinThread:P,leaveThread:y,listThreads:R,markRead:S,sendMessage:f,subscribe:B,unreadCount:h};return I.jsx(K.Provider,{value:H,children:e})},ze=e=>e&&typeof e=="function",We=e=>e&&typeof e=="function",Ge=({children:e,defaultQueriesOptions:t,defaultMutationsOptions:r,...s})=>{const{libraries:o}=l.useContext(j),a=s?.QueryClient||o?.reactQuery?.QueryClient,c=s?.QueryClientProvider||o?.reactQuery?.QueryClientProvider;if(!a)throw new Error("QueryClient is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(!c)throw new Error("QueryClientProvider is not provided. You can provide it with InjectDependenciesProvider or directly in props.");if(!ze(c))throw new Error("Provided QueryClientProvider dependencies are not valid.");if(!We(a))throw new Error("Provided QueryClient dependencies are not valid.");const d=new a({defaultOptions:{mutations:{...r},queries:{getNextPageParam:(u,h,i)=>u.length+(i||0),refetchOnWindowFocus:!1,retry:3,...t}}});return I.jsx(c,{client:d,children:e})},se=({library:e,date:t,format:r="ll"})=>e(t).format(r),ae=(e,t)=>{const{fractionDigits:r=0,metric:s="km",spacingBetween:o=!0}=t||{},a=Number(e),c=o?" ":"";return Number.isNaN(a)?`0${c}${s}`:`${a.toFixed(r)}${c}${s}`},ie=e=>!e||typeof e!="string"?"":e.replace(/_/g," ").toLowerCase().split(" ").map(r=>r.length>0?r.charAt(0).toUpperCase()+r.slice(1):r).join(" "),Ve=e=>e?.startsWith("/")?e?.startsWith("/files")?e:`/files${e}`:e?.startsWith("files")?`/${e}`:`/files/${e}`,Qe=({path:e,size:t,apiURL:r})=>{if(!e)return"";const s=Ve(e),o=`${r}${s}`,a=o.match(/\.(jpeg|jpg|png|gif|bmp|webp|svg|avif)$/)!==null;return typeof t=="number"&&a?`${o.replace("/files",`/thumbs/${t}`)}`:o},Je=e=>{const{apiURL:t,libraries:r}=l.useContext(j),s=e?.dayjs||r?.dayjs;return{dateAdapter:(c,d)=>{if(!s)throw new Error("Dayjs is not provided. You can provide it with InjectDependenciesProvider or directly in props.");return se({date:c,format:d,library:s})},distanceAdapter:ae,filePathAdapter:(c,d)=>{if(!t)throw new Error("API URL is not provided. You can provide it with InjectDependenciesProvider or directly in props to filePathAdapter.");return typeof c=="string"&&/^https?:\/\//.test(c)?c:Qe({apiURL:t,path:c,size:d})},worksiteNameAdapter:ie}},Ke=e=>{const{libraries:t,localStorageKeys:r}=l.useContext(j),s=e?.axios||t?.axios,o=e?.localStorageKey||r?.user||"user";if(!s)throw new Error("Axios is not provided. You can provide it with InjectDependenciesProvider or directly in params of useAuth.");const a=l.useCallback(({tokenType:d,accessToken:u})=>{s.defaults.headers.common.Authorization=`${d} ${u}`},[s.defaults.headers.common]),c=()=>{s.defaults.headers.common.Authorization=null};return l.useEffect(()=>{if(U)return;const d=({newValue:u,key:h})=>{if(h===o&&u)try{const{accessToken:i,tokenType:m}=JSON.parse(u);a({accessToken:i,tokenType:m})}catch(i){console.error("Failed to parse newValue from localStorage:",i)}};return window.addEventListener("storage",d),()=>{window.removeEventListener("storage",d)}},[o,a]),{clearAuthenticationToken:c,setAuthenticationToken:a}},Be=e=>{const t=l.useContext(K);if(!t)throw new Error("useChat must be used within ChatProvider");const{subscribe:r,...s}=t,o=l.useRef(e);return o.current=e,l.useEffect(()=>r(a=>{const{onReady:c,onNewMessage:d,onNewMessageNotification:u,onPresence:h,onError:i,onJoinedThread:m,onLeftThread:E,onMarkedRead:v,onThreadArchived:_,onThreadsList:A}=o.current??{};switch(a.type){case"ready":c?.(a);break;case"new_message":d?.(a);break;case"new_message_notification":u?.(a);break;case"presence":h?.(a);break;case"error":i?.(a);break;case"joined_thread":m?.(a);break;case"left_thread":E?.(a);break;case"marked_read":v?.(a);break;case"thread_archived":_?.(a);break;case"threads_list":A?.(a);break}}),[r]),s},G=(e,t)=>t==="short"?e.split("-")[0]:e,He=(e,t="full")=>{const[r,s]=l.useState(()=>{const o=e?.language||navigator.language;return e&&"isInitialized"in e&&e.isInitialized,G(o,t)});return l.useEffect(()=>{e&&"isInitialized"in e&&e.isInitialized&&e.language&&s(G(e.language,t));const o=a=>{s(G(a,t))};return e?.on?.("languageChanged",o),()=>{e?.off?.("languageChanged",o)}},[e,t]),r},Xe="tracktor.filter",Ze={getFilter:()=>{},getFilters:()=>({}),handleFilter:()=>()=>{},setFilter:()=>{}},ce=e=>{try{return JSON.parse(e)}catch{return e}},le=(e,t,r)=>`${r}_${e}=>${t}`,qe=e=>e.reduce((t,r)=>{const s=localStorage.getItem(r);if(s)try{const o=JSON.parse(s),a=Object.keys(o)?.[0];a&&(t[a]=Object.values(o)?.[0])}catch{}return t},{}),$e=e=>{const{libraries:t,localStorageKeys:r}=l.useContext(j),s=e?.reactRouter||t?.reactRouter,{pathname:o}=s?.useLocation?.()??{pathname:"/"},[a,c]=s?.useSearchParams?.()??[new URLSearchParams,()=>{}],[d,u]=l.useState({}),h=r?.filter||Xe,i=e?.syncWithUrl===void 0?!0:e?.syncWithUrl,m=e?.persistToLocalStorage===void 0?!0:e?.persistToLocalStorage;if(U)return Ze;if(!s)throw new Error("React Router is not provided. You can provide it with InjectDependenciesProvider or directly in props of reactRouter.");const E=()=>Object.keys(localStorage).filter(y=>y.startsWith(h)&&y.endsWith(e?.pathname||o)),v=(y,f,S=!0)=>{const R=le(y,e?.pathname||o,h);if(!f||Array.isArray(f)&&!f.length){i?(a.delete(y),c(a)):u(k=>{const N={...k};return delete N[y],N}),m&&localStorage.removeItem(R);return}m&&S&&f&&localStorage.setItem(R,JSON.stringify({...a,[y]:f})),i&&f?(a.set(y,JSON.stringify(f)),c(a)):!i&&f&&u(k=>({...k,[y]:f}))};return{getFilter:(y,f)=>{if(i){const S=a.get(y);if(S)return ce(S)}else{const S=d[y];if(S!==void 0)return S}if(m){const S=le(y,e?.pathname||o,h),R=localStorage.getItem(S);if(R)try{const k=JSON.parse(R)[y];return!i&&k!==void 0&&u(N=>({...N,[y]:k})),k}catch{}}return f},getFilters:()=>{const y=m?qe(E()):{};if(i){const f=Array.from(a.entries()).reduce((S,[R,k])=>(S[R]=ce(k),S),{});return{...y,...f}}return{...y,...d}},handleFilter:(y,f)=>(S,R)=>{if(R||Array.isArray(R)&&R.length===0){const k=f||"value",N=typeof R=="object"&&k in R?R[k]:R;v(y,N);return}v(y,void 0)},setFilter:v}},et=({data:e,fetchNextPage:t,isFetchingNextPage:r,isInitialLoading:s,isLoading:o,enabled:a=!0})=>{const c=l.useCallback(async u=>{r||!a||await t({pageParam:u?.pageParam||u.visibleRowsCount})},[a,t,r]),d=l.useMemo(()=>{if(e)return e.pages.reduce((u,h)=>[...u,...h],[])},[e]);return{fetchNextPageOnRowsScrollEnd:c,isLoading:r||o,loadingVariant:s?"skeleton":"linear-progress",rows:d}},tt=e=>{const{libraries:t}=l.useContext(j),r=e?.i18||t?.i18,s=e?.i18?.translateFunction||t?.i18?.translateFunction,o=r?.i18next?.t||s||(h=>h),{unknownErrorTranslationKey:a="error.unknownError"}=e||{},c=o(a),d=l.useCallback(h=>{if(h&&typeof h=="object"&&"response"in h){const{response:i}=h||{};if(i&&typeof i=="object"&&"reason"in i&&i.reason)return String(i.reason);if(i&&typeof i=="object"&&"data"in i&&i.data&&typeof i.data=="object"&&"reason"in i.data&&i.data.reason)return String(i.data.reason);if(i&&typeof i=="object"&&"data"in i&&i.data&&typeof i.data=="object"&&"message"in i.data&&i.data.message)return String(i.data.message);if(i&&typeof i=="object"&&"data"in i&&i.data&&typeof i.data=="object"&&"detail"in i.data){const{detail:m}=i.data;if(Array.isArray(m)&&m.length>0&&typeof m[0]=="object"&&m[0]!==null&&"msg"in m[0]){const{msg:E}=m[0];if(typeof E=="string")return String(E)}}}return h instanceof Error?h.message:c},[c]);return{getErrorCode:l.useCallback(h=>{const{response:i}=h||{};return i?.error_code?String(i?.error_code):i?.data?.error_code?String(i?.data?.error_code):i?.error_code?String(i?.error_code):i?.data?.error_code?String(i.data.error_code):"unknown_error_code"},[]),printError:d}};g.ChatClient=ee,g.ChatContext=K,g.ChatProvider=Ue,g.GTMSendPageView=Ce,g.InitializeAxiosConfig=Re,g.InitializeDaysJSConfig=be,g.InitializeI18nConfig=Te,g.InitializeSentryConfig=Se,g.InjectDependenciesContext=j,g.InjectDependenciesProvider=we,g.MaskTextField=ve,g.PreloadErrorHandler=Ae,g.QueryClientProviderWithConfig=Ge,g.RequireAuth=je,g.axiosCustomInstance=ge,g.dateAdapter=se,g.distanceAdapter=ae,g.getOrvalConfig=Fe,g.useAdapter=Je,g.useAuth=Ke,g.useChat=Be,g.useCurrentLanguage=He,g.useFilters=$e,g.useInfiniteDataGrid=et,g.useResponseError=tt,g.worksiteNameAdapter=ie,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tracktor/shared-module",
3
- "version": "2.28.0",
3
+ "version": "2.30.0",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "types": "./dist/main.d.ts",