@tracktor/shared-module 1.0.9 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
1
  # [Versions](https://github.com/Tracktor/shared-module/releases)
2
2
 
3
- ## v1.0.9
4
- - **[fix]** : fix and improvement
3
+ ## v2.0.0-beta.1
4
+ - **[chore]** : refactor module injection
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
- # shared-module
1
+ # @tracktor/shared-module
2
2
 
3
- > This package contains shared components, hooks and utilities for the Tracktor project.
3
+ > This package contains shared components, hooks and utilities for the Tracktor project.
4
+ > This package use dependencies only with injection.
4
5
  > This package is not intended to be used outside the Tracktor project.
5
6
 
6
7
  - [Installation](#Installation)
@@ -16,17 +17,19 @@ yarn add @tracktor/shared-module
16
17
  ## Usage
17
18
 
18
19
  ```typescript jsx
19
- import { AxiosConfig } from "@tracktor/shared-module";
20
+ import { InitializeAxiosConfig } from "@tracktor/shared-module";
20
21
  ```
21
22
 
22
23
  ## Inject dependencies with provider
23
24
 
24
25
  ```typescript jsx
25
- import { InitializeAxiosConfig, InjectDependenciesProvider } from "@tracktor/shared-module";
26
+ import { InjectDependenciesProvider, InitializeAxiosConfig } from "@tracktor/shared-module";
26
27
 
27
28
  const App = () => (
28
- <InjectDependenciesProvider apiURL={import.meta.env.VITE_API_URL}>
29
- <InitializeAxiosConfig />
29
+ <InjectDependenciesProvider apiURL={import.meta.env.VITE_API_URL} libraries={{
30
+ axios,
31
+ }}>
32
+ <InitializeAxiosConfig/>
30
33
  ...
31
34
  </InjectDependenciesProvider>
32
35
  );
@@ -35,10 +38,10 @@ export default App;
35
38
  ```
36
39
 
37
40
  ## Providers
38
- | Module | Description | Dependencies |
39
- |----------------------------|------------------------------------------------|--------------|
40
- | InjectDependenciesProvider | Inject dependencies for other shared component | - |
41
- | QueryClientConfigProvider | React Query provider with default config | React Query |
41
+ | Module | Description | Dependencies |
42
+ |-------------------------------|------------------------------------------------|--------------|
43
+ | InjectDependenciesProvider | Inject dependencies for other shared component | - |
44
+ | QueryClientProviderWithConfig | React Query provider with default config | React Query |
42
45
 
43
46
 
44
47
  ## Components
@@ -0,0 +1,8 @@
1
+ var o = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
2
+ function l(e) {
3
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
4
+ }
5
+ export {
6
+ o as c,
7
+ l as g
8
+ };
@@ -1,6 +1,18 @@
1
+ import { InjectDependenciesContextProps } from '../../context/InjectDependenciesProvider';
2
+ export interface GTMSendPageViewProps {
3
+ /**
4
+ * GTM library from @tracktor
5
+ */
6
+ gtm?: NonNullable<InjectDependenciesContextProps["libraries"]>["gtm"];
7
+ /**
8
+ * React Router library
9
+ */
10
+ reactRouter?: NonNullable<InjectDependenciesContextProps["libraries"]>["reactRouter"];
11
+ }
1
12
  /**
2
13
  * This component send page view to Google Tag Manager
14
+ * @param props
3
15
  * @constructor
4
16
  */
5
- declare const GTMSendPageView: () => import("react/jsx-runtime").JSX.Element;
17
+ declare const GTMSendPageView: ({ ...props }: GTMSendPageViewProps) => import("react/jsx-runtime").JSX.Element;
6
18
  export default GTMSendPageView;
@@ -1,4 +1,9 @@
1
+ import { InjectDependenciesContextProps } from '../../context/InjectDependenciesProvider';
1
2
  interface InitializeAxiosConfigProps {
3
+ /**
4
+ * Axios library
5
+ */
6
+ axios?: NonNullable<InjectDependenciesContextProps["libraries"]>["axios"];
2
7
  /**
3
8
  * User local storage key
4
9
  * @default user
@@ -1,10 +1,19 @@
1
+ import { InjectDependenciesContextProps } from '../../context/InjectDependenciesProvider';
1
2
  interface InitializeDaysJSConfigProps {
3
+ /**
4
+ * Dayjs library
5
+ */
6
+ dayjs?: NonNullable<InjectDependenciesContextProps["libraries"]>["dayjs"];
7
+ /**
8
+ * Language
9
+ */
2
10
  language?: "fr" | "en";
3
11
  }
4
12
  /**
5
13
  * Initialize dayjs
6
14
  * @param language
15
+ * @param props
7
16
  * @constructor
8
17
  */
9
- declare const InitializeDaysJSConfig: ({ language }: InitializeDaysJSConfigProps) => null;
18
+ declare const InitializeDaysJSConfig: ({ language, ...props }: InitializeDaysJSConfigProps) => null;
10
19
  export default InitializeDaysJSConfig;
@@ -1,4 +1,9 @@
1
+ import { InjectDependenciesContextProps } from '../../context/InjectDependenciesProvider';
1
2
  interface InitializeI18nConfigProps {
3
+ /**
4
+ * i18 library
5
+ */
6
+ i18?: NonNullable<InjectDependenciesContextProps["libraries"]>["i18"];
2
7
  /**
3
8
  * Resources to initialize with (if not using loading or not appending using addResourceBundle)
4
9
  */
@@ -17,5 +22,5 @@ interface InitializeI18nConfigProps {
17
22
  * @param resources
18
23
  * @constructor
19
24
  */
20
- declare const InitializeI18nConfig: ({ debug, resources }: InitializeI18nConfigProps) => null;
25
+ declare const InitializeI18nConfig: ({ debug, resources, ...props }: InitializeI18nConfigProps) => null;
21
26
  export default InitializeI18nConfig;
@@ -1,4 +1,9 @@
1
+ import { InjectDependenciesContextProps } from '../../context/InjectDependenciesProvider';
1
2
  interface InitializeMapBoxConfigProps {
3
+ /**
4
+ * MapBox library
5
+ */
6
+ mapbox?: NonNullable<InjectDependenciesContextProps["libraries"]>["mapbox"];
2
7
  /**
3
8
  * MapBox access token
4
9
  */
@@ -6,8 +11,9 @@ interface InitializeMapBoxConfigProps {
6
11
  }
7
12
  /**
8
13
  * This component is used to initialize MapBox
14
+ * @param mapbox
9
15
  * @param accessToken
10
16
  * @constructor
11
17
  */
12
- declare const InitializeMapBoxConfig: ({ accessToken }: InitializeMapBoxConfigProps) => null;
18
+ declare const InitializeMapBoxConfig: ({ accessToken, ...props }: InitializeMapBoxConfigProps) => null;
13
19
  export default InitializeMapBoxConfig;
@@ -1,4 +1,13 @@
1
+ import { InjectDependenciesContextProps } from '../../context/InjectDependenciesProvider';
1
2
  interface InitializeSentryConfigProps {
3
+ /**
4
+ * Sentry library
5
+ */
6
+ sentry?: NonNullable<InjectDependenciesContextProps["libraries"]>["mapbox"];
7
+ /**
8
+ * React Router library
9
+ */
10
+ reactRouter?: NonNullable<InjectDependenciesContextProps["libraries"]>["reactRouter"];
2
11
  /**
3
12
  * Sentry DSN
4
13
  */
@@ -63,5 +72,5 @@ interface InitializeSentryConfigProps {
63
72
  * @param environment
64
73
  * @constructor
65
74
  */
66
- declare const InitializeSentryConfig: ({ dsn, integrations, tracesSampleRate, replaysSessionSampleRate, replaysOnErrorSampleRate, tracePropagationTargets, ignoreErrors, debug, environment, }: InitializeSentryConfigProps) => null;
75
+ declare const InitializeSentryConfig: ({ dsn, integrations, tracesSampleRate, replaysSessionSampleRate, replaysOnErrorSampleRate, tracePropagationTargets, ignoreErrors, debug, environment, ...props }: InitializeSentryConfigProps) => null;
67
76
  export default InitializeSentryConfig;
@@ -1,10 +1,29 @@
1
1
  import { ReactNode } from "react";
2
+ import { InjectDependenciesContextProps } from '../../context/InjectDependenciesProvider';
2
3
  export interface RequireAuthProps {
4
+ /**
5
+ * React router is a libraries dependencies
6
+ */
7
+ reactRouter?: NonNullable<InjectDependenciesContextProps["libraries"]>["reactRouter"];
8
+ /**
9
+ * Axios is a libraries dependencies
10
+ */
11
+ axios?: NonNullable<InjectDependenciesContextProps["libraries"]>["axios"];
12
+ /**
13
+ * Is user logged in
14
+ */
15
+ isLogged?: () => {
16
+ isLogged: boolean;
17
+ } | boolean;
3
18
  /**
4
19
  * Login path
5
20
  * @default /login
6
21
  */
7
22
  loginPath?: string;
23
+ /**
24
+ * Fallback component for Suspense
25
+ */
26
+ Fallback?: ReactNode;
8
27
  /**
9
28
  * Local storage key for user data
10
29
  * @default user
@@ -15,25 +34,16 @@ export interface RequireAuthProps {
15
34
  * @default /login
16
35
  */
17
36
  redirect401Path?: string;
18
- /**
19
- * Is user logged in
20
- */
21
- isLogged?: () => {
22
- isLogged: boolean;
23
- } | boolean;
24
- /**
25
- * Fallback component for Suspense
26
- */
27
- Fallback?: ReactNode;
28
37
  }
29
38
  /**
30
39
  * RequireAuth component for protected routing
31
40
  * @param Fallback
41
+ * @param isLogged
32
42
  * @param loginPath
33
43
  * @param localStorageKey
34
44
  * @param redirect401Path
35
- * @param isLogged
45
+ * @param props
36
46
  * @constructor
37
47
  */
38
- declare const RequireAuth: ({ Fallback, loginPath, localStorageKey, redirect401Path, isLogged, }: RequireAuthProps) => import("react/jsx-runtime").JSX.Element;
48
+ declare const RequireAuth: ({ Fallback, isLogged, loginPath, localStorageKey, redirect401Path, ...props }: RequireAuthProps) => import("react/jsx-runtime").JSX.Element;
39
49
  export default RequireAuth;
@@ -5,17 +5,55 @@ export interface InjectDependenciesContextProps {
5
5
  */
6
6
  children?: ReactNode;
7
7
  /**
8
- * API URL dependency for apiURL
8
+ * API URL dependency for useAdapter hook
9
9
  */
10
10
  apiURL?: string;
11
+ /**
12
+ * List of dependencies for libraries
13
+ */
14
+ libraries?: {
15
+ axios?: any;
16
+ dayjs?: any;
17
+ gtm?: {
18
+ useGoogleTagManager: () => any;
19
+ };
20
+ mapbox?: any;
21
+ reactRouter?: any;
22
+ sentry?: any;
23
+ i18?: {
24
+ i18next?: any;
25
+ initReactI18next?: any;
26
+ languageDetector?: any;
27
+ };
28
+ reactQuery?: {
29
+ QueryClientProvider: ({ client, children }: {
30
+ client: any;
31
+ children: ReactNode;
32
+ }) => any;
33
+ QueryClient: {
34
+ new (config: {
35
+ defaultOptions: {
36
+ queries: {
37
+ refetchOnWindowFocus: boolean;
38
+ retry: number;
39
+ getNextPageParam: (lastPage: [], allPages: [], lastPageParam: number) => number;
40
+ };
41
+ mutations: {
42
+ [key: string]: any;
43
+ };
44
+ };
45
+ }): any;
46
+ };
47
+ };
48
+ };
11
49
  }
12
50
  export declare const InjectDependenciesContext: import("react").Context<InjectDependenciesContextProps>;
13
51
  /**
14
- *
52
+ * This provider is used to inject major dependencies
15
53
  * @param children
16
- * @param translate
54
+ * @param librariesDependencies
17
55
  * @param apiURL
18
56
  * @constructor
19
57
  */
20
- declare const InjectDependenciesProvider: ({ children, apiURL }: InjectDependenciesContextProps) => import("react/jsx-runtime").JSX.Element;
58
+ declare const InjectDependenciesProvider: ({ children, apiURL, libraries }: InjectDependenciesContextProps) => import("react/jsx-runtime").JSX.Element;
21
59
  export default InjectDependenciesProvider;
@@ -1,5 +1,14 @@
1
1
  import { PropsWithChildren } from "react";
2
+ import { InjectDependenciesContextProps } from './InjectDependenciesProvider';
2
3
  interface QueryClientProviderWithConfigProps extends PropsWithChildren {
4
+ /**
5
+ * QueryClientProvider from react-query
6
+ */
7
+ QueryClientProvider?: NonNullable<NonNullable<InjectDependenciesContextProps["libraries"]>["reactQuery"]>["QueryClientProvider"];
8
+ /**
9
+ * QueryClient from react-query
10
+ */
11
+ QueryClient?: NonNullable<NonNullable<InjectDependenciesContextProps["libraries"]>["reactQuery"]>["QueryClient"];
3
12
  /**
4
13
  * Default options for queries
5
14
  */
@@ -14,11 +23,10 @@ interface QueryClientProviderWithConfigProps extends PropsWithChildren {
14
23
  };
15
24
  }
16
25
  /**
17
- * This provider is QueryClientProvider with custom default config options
26
+ * This provider is QueryClientProviderWithConfig with custom default config options
18
27
  * @param children
19
- * @param defaultQueriesOptions
20
- * @param defaultMutationsOptions
28
+ * @param options
21
29
  * @constructor
22
30
  */
23
- declare const QueryClientProviderWithConfig: ({ children, defaultQueriesOptions, defaultMutationsOptions, }: QueryClientProviderWithConfigProps) => import("react/jsx-runtime").JSX.Element;
31
+ declare const QueryClientProviderWithConfig: ({ children, defaultQueriesOptions, defaultMutationsOptions, ...props }: QueryClientProviderWithConfigProps) => import("react/jsx-runtime").JSX.Element;
24
32
  export default QueryClientProviderWithConfig;
@@ -1,4 +1,4 @@
1
- import { c as o } from "./main-YTkqJNOe.js";
1
+ import { c as o } from "./_commonjsHelpers-f3sTPFkQ.js";
2
2
  var a = { exports: {} };
3
3
  (function(t, _) {
4
4
  (function(r, e) {
@@ -1,6 +1,6 @@
1
- import { c as m } from "./main-YTkqJNOe.js";
1
+ import { c as m } from "./_commonjsHelpers-f3sTPFkQ.js";
2
2
  import o from "dayjs";
3
- var i = { exports: {} };
3
+ var a = { exports: {} };
4
4
  (function(n, s) {
5
5
  (function(t, r) {
6
6
  n.exports = r(o);
@@ -8,12 +8,12 @@ var i = { exports: {} };
8
8
  function r(e) {
9
9
  return e && typeof e == "object" && "default" in e ? e : { default: e };
10
10
  }
11
- var a = r(t), _ = { name: "fr", weekdays: "dimanche_lundi_mardi_mercredi_jeudi_vendredi_samedi".split("_"), weekdaysShort: "dim._lun._mar._mer._jeu._ven._sam.".split("_"), weekdaysMin: "di_lu_ma_me_je_ve_sa".split("_"), months: "janvier_février_mars_avril_mai_juin_juillet_août_septembre_octobre_novembre_décembre".split("_"), monthsShort: "janv._févr._mars_avr._mai_juin_juil._août_sept._oct._nov._déc.".split("_"), weekStart: 1, yearStart: 4, formats: { LT: "HH:mm", LTS: "HH:mm:ss", L: "DD/MM/YYYY", LL: "D MMMM YYYY", LLL: "D MMMM YYYY HH:mm", LLLL: "dddd D MMMM YYYY HH:mm" }, relativeTime: { future: "dans %s", past: "il y a %s", s: "quelques secondes", m: "une minute", mm: "%d minutes", h: "une heure", hh: "%d heures", d: "un jour", dd: "%d jours", M: "un mois", MM: "%d mois", y: "un an", yy: "%d ans" }, ordinal: function(e) {
11
+ var i = r(t), _ = { name: "fr", weekdays: "dimanche_lundi_mardi_mercredi_jeudi_vendredi_samedi".split("_"), weekdaysShort: "dim._lun._mar._mer._jeu._ven._sam.".split("_"), weekdaysMin: "di_lu_ma_me_je_ve_sa".split("_"), months: "janvier_février_mars_avril_mai_juin_juillet_août_septembre_octobre_novembre_décembre".split("_"), monthsShort: "janv._févr._mars_avr._mai_juin_juil._août_sept._oct._nov._déc.".split("_"), weekStart: 1, yearStart: 4, formats: { LT: "HH:mm", LTS: "HH:mm:ss", L: "DD/MM/YYYY", LL: "D MMMM YYYY", LLL: "D MMMM YYYY HH:mm", LLLL: "dddd D MMMM YYYY HH:mm" }, relativeTime: { future: "dans %s", past: "il y a %s", s: "quelques secondes", m: "une minute", mm: "%d minutes", h: "une heure", hh: "%d heures", d: "un jour", dd: "%d jours", M: "un mois", MM: "%d mois", y: "un an", yy: "%d ans" }, ordinal: function(e) {
12
12
  return "" + e + (e === 1 ? "er" : "");
13
13
  } };
14
- return a.default.locale(_, null, !0), _;
14
+ return i.default.locale(_, null, !0), _;
15
15
  });
16
- })(i);
16
+ })(a);
17
17
  const l = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
18
18
  __proto__: null
19
19
  }, Symbol.toStringTag, { value: "Module" }));
@@ -1,9 +1,20 @@
1
+ import { InjectDependenciesContextProps } from '../../context/InjectDependenciesProvider';
2
+ export interface useAdapterParams {
3
+ /**
4
+ * Dayjs library
5
+ */
6
+ dayjs?: NonNullable<InjectDependenciesContextProps["libraries"]>["dayjs"];
7
+ /**
8
+ * Translation key returned for the unknown error
9
+ */
10
+ unknownErrorTranslationKey?: string;
11
+ }
1
12
  /**
2
13
  * Use adapter
3
14
  * @returns
4
15
  */
5
- export declare const useAdapter: () => {
6
- dateAdapter: (date: string | number | import("dayjs").Dayjs | Date | null | undefined, format?: string) => string;
16
+ export declare const useAdapter: (params?: useAdapterParams) => {
17
+ dateAdapter: (date: string | number | Date | null | undefined, format?: string) => any;
7
18
  distanceAdapter: (distance?: string | number | null | undefined, metric?: string) => string;
8
19
  filePathAdapter: (href?: string | null | {
9
20
  pathname: string;
@@ -1,4 +1,11 @@
1
- declare const useAuth: () => {
1
+ import { InjectDependenciesContextProps } from '../../context/InjectDependenciesProvider';
2
+ interface useAuthParams {
3
+ /**
4
+ * Axios library
5
+ */
6
+ axios?: NonNullable<InjectDependenciesContextProps["libraries"]>["axios"];
7
+ }
8
+ declare const useAuth: (params?: useAuthParams) => {
2
9
  clearAuthenticationToken: () => void;
3
10
  setAuthenticationToken: ({ tokenType, accessToken }: {
4
11
  tokenType: string;
@@ -1,3 +1,4 @@
1
+ import { InjectDependenciesContextProps } from '../../context/InjectDependenciesProvider';
1
2
  export interface ResponseError {
2
3
  data?: {
3
4
  code?: number;
@@ -12,6 +13,10 @@ export interface ResponseError {
12
13
  };
13
14
  }
14
15
  export interface useResponseErrorParams {
16
+ /**
17
+ * i18 library
18
+ */
19
+ i18?: NonNullable<InjectDependenciesContextProps["libraries"]>["i18"];
15
20
  /**
16
21
  * Translation key returned for the unknown error
17
22
  */
@@ -23,6 +28,6 @@ export interface useResponseErrorParams {
23
28
  */
24
29
  export declare const useResponseError: <T = ResponseError>(params?: useResponseErrorParams) => {
25
30
  getErrorCode: (error?: any) => string;
26
- printError: (error?: any) => string;
31
+ printError: (error?: any) => any;
27
32
  };
28
33
  export default useResponseError;
@@ -0,0 +1,48 @@
1
+ import { g as v, c as y } from "./_commonjsHelpers-f3sTPFkQ.js";
2
+ function b(o, c) {
3
+ for (var t = 0; t < c.length; t++) {
4
+ const e = c[t];
5
+ if (typeof e != "string" && !Array.isArray(e)) {
6
+ for (const r in e)
7
+ if (r !== "default" && !(r in o)) {
8
+ const n = Object.getOwnPropertyDescriptor(e, r);
9
+ n && Object.defineProperty(o, r, n.get ? n : {
10
+ enumerable: !0,
11
+ get: () => e[r]
12
+ });
13
+ }
14
+ }
15
+ }
16
+ return Object.freeze(Object.defineProperty(o, Symbol.toStringTag, { value: "Module" }));
17
+ }
18
+ var m = { exports: {} };
19
+ (function(o, c) {
20
+ (function(t, e) {
21
+ o.exports = e();
22
+ })(y, function() {
23
+ var t = { LTS: "h:mm:ss A", LT: "h:mm A", L: "MM/DD/YYYY", LL: "MMMM D, YYYY", LLL: "MMMM D, YYYY h:mm A", LLLL: "dddd, MMMM D, YYYY h:mm A" };
24
+ return function(e, r, n) {
25
+ var s = r.prototype, M = s.format;
26
+ n.en.formats = t, s.format = function(i) {
27
+ i === void 0 && (i = "YYYY-MM-DDTHH:mm:ssZ");
28
+ var l = this.$locale().formats, p = function(d, f) {
29
+ return d.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, function(x, Y, a) {
30
+ var L = a && a.toUpperCase();
31
+ return Y || f[a] || t[a] || f[L].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, function(j, g, D) {
32
+ return g || D.slice(1);
33
+ });
34
+ });
35
+ }(i, l === void 0 ? {} : l);
36
+ return M.call(this, p);
37
+ };
38
+ };
39
+ });
40
+ })(m);
41
+ var u = m.exports;
42
+ const h = /* @__PURE__ */ v(u), z = /* @__PURE__ */ b({
43
+ __proto__: null,
44
+ default: h
45
+ }, [u]);
46
+ export {
47
+ z as l
48
+ };