@tracktor/shared-module 1.0.3 → 1.0.5

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.3
4
- - **[fix]** : `MapBoxConfig` & `GTMSendPageView`
3
+ ## v1.0.5
4
+ - **[fix]** : name export
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # shared-module
1
+ # @tracktor/shared-module
2
2
 
3
3
  > This package contains shared components, hooks and utilities for the Tracktor project.
4
- > This package don't use any external dependencies, only peer dependencies.
4
+ > This package use dependencies only with injection.
5
5
  > This package is not intended to be used outside the Tracktor project.
6
6
 
7
7
  - [Installation](#Installation)
@@ -17,17 +17,19 @@ yarn add @tracktor/shared-module
17
17
  ## Usage
18
18
 
19
19
  ```typescript jsx
20
- import { AxiosConfig } from "@tracktor/shared-module";
20
+ import { InitializeAxiosConfig } from "@tracktor/shared-module";
21
21
  ```
22
22
 
23
23
  ## Inject dependencies with provider
24
24
 
25
25
  ```typescript jsx
26
- import { AxiosConfig, InjectDependenciesProvider } from "@tracktor/shared-module";
26
+ import { InjectDependenciesProvider, InitializeAxiosConfig } from "@tracktor/shared-module";
27
27
 
28
28
  const App = () => (
29
- <InjectDependenciesProvider apiURL={import.meta.env.VITE_API_URL}>
30
- <AxiosConfig baseURL={import.meta.env.VITE_API_URL} />
29
+ <InjectDependenciesProvider apiURL={import.meta.env.VITE_API_URL} libraries={{
30
+ axios,
31
+ }}>
32
+ <InitializeAxiosConfig/>
31
33
  ...
32
34
  </InjectDependenciesProvider>
33
35
  );
@@ -36,10 +38,10 @@ export default App;
36
38
  ```
37
39
 
38
40
  ## Providers
39
- | Module | Description | Dependencies |
40
- |----------------------------|------------------------------------------------|--------------|
41
- | InjectDependenciesProvider | Inject dependencies for other shared component | - |
42
- | 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 |
43
45
 
44
46
 
45
47
  ## Components
@@ -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 | null;
17
+ declare const GTMSendPageView: ({ ...props }: GTMSendPageViewProps) => import("react/jsx-runtime").JSX.Element;
6
18
  export default GTMSendPageView;
@@ -1,4 +1,4 @@
1
- interface AxiosConfigProps {
1
+ interface InitializeAxiosConfigProps {
2
2
  /**
3
3
  * User local storage key
4
4
  * @default user
@@ -7,7 +7,7 @@ interface AxiosConfigProps {
7
7
  /**
8
8
  * Base URL for Axios instance
9
9
  */
10
- baseURL?: string;
10
+ apiURL?: string;
11
11
  /**
12
12
  * Post content type for Axios instance
13
13
  * @default application/json
@@ -33,5 +33,5 @@ interface AxiosConfigProps {
33
33
  * @param postContentType
34
34
  * @constructor
35
35
  */
36
- declare const AxiosConfig: ({ tokenTypeKey, userLocalStorageKey, tokenKey, postContentType, ...props }: AxiosConfigProps) => null;
37
- export default AxiosConfig;
36
+ declare const InitializeAxiosConfig: ({ tokenTypeKey, userLocalStorageKey, tokenKey, postContentType, ...props }: InitializeAxiosConfigProps) => null;
37
+ export default InitializeAxiosConfig;
@@ -0,0 +1,10 @@
1
+ interface InitializeDaysJSConfigProps {
2
+ language?: "fr" | "en";
3
+ }
4
+ /**
5
+ * Initialize dayjs
6
+ * @param language
7
+ * @constructor
8
+ */
9
+ declare const InitializeDaysJSConfig: ({ language }: InitializeDaysJSConfigProps) => null;
10
+ export default InitializeDaysJSConfig;
@@ -1,4 +1,4 @@
1
- interface I18nConfigProps {
1
+ interface InitializeI18nConfigProps {
2
2
  /**
3
3
  * Resources to initialize with (if not using loading or not appending using addResourceBundle)
4
4
  */
@@ -17,5 +17,5 @@ interface I18nConfigProps {
17
17
  * @param resources
18
18
  * @constructor
19
19
  */
20
- declare const I18nConfig: ({ debug, resources }: I18nConfigProps) => null;
21
- export default I18nConfig;
20
+ declare const InitializeI18nConfig: ({ debug, resources }: InitializeI18nConfigProps) => null;
21
+ export default InitializeI18nConfig;
@@ -1,4 +1,4 @@
1
- interface MapBoxConfigProps {
1
+ interface InitializeMapBoxConfigProps {
2
2
  /**
3
3
  * MapBox access token
4
4
  */
@@ -10,5 +10,5 @@ interface MapBoxConfigProps {
10
10
  * @param accessToken
11
11
  * @constructor
12
12
  */
13
- declare const MapBoxConfig: ({ accessToken }: MapBoxConfigProps) => null;
14
- export default MapBoxConfig;
13
+ declare const InitializeMapBoxConfig: ({ accessToken }: InitializeMapBoxConfigProps) => null;
14
+ export default InitializeMapBoxConfig;
@@ -1,4 +1,4 @@
1
- interface SentryConfigProps {
1
+ interface InitializeSentryConfigProps {
2
2
  /**
3
3
  * Sentry DSN
4
4
  */
@@ -63,5 +63,5 @@ interface SentryConfigProps {
63
63
  * @param environment
64
64
  * @constructor
65
65
  */
66
- declare const SentryConfig: ({ dsn, integrations, tracesSampleRate, replaysSessionSampleRate, replaysOnErrorSampleRate, tracePropagationTargets, ignoreErrors, debug, environment, }: SentryConfigProps) => null;
67
- export default SentryConfig;
66
+ declare const InitializeSentryConfig: ({ dsn, integrations, tracesSampleRate, replaysSessionSampleRate, replaysOnErrorSampleRate, tracePropagationTargets, ignoreErrors, debug, environment, }: InitializeSentryConfigProps) => null;
67
+ 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;
@@ -8,14 +8,53 @@ export interface InjectDependenciesContextProps {
8
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
+ dayjsPlugin?: any[];
18
+ gtm?: {
19
+ useGoogleTagManager: () => any;
20
+ };
21
+ mapbox?: any;
22
+ reactRouter?: any;
23
+ sentry?: any;
24
+ i18?: {
25
+ i18next?: any;
26
+ initReactI18next?: any;
27
+ languageDetector?: any;
28
+ };
29
+ reactQuery?: {
30
+ QueryClientProvider: ({ client, children }: {
31
+ client: any;
32
+ children: ReactNode;
33
+ }) => any;
34
+ QueryClient: {
35
+ new (config: {
36
+ defaultOptions: {
37
+ queries: {
38
+ refetchOnWindowFocus: boolean;
39
+ retry: number;
40
+ getNextPageParam: (lastPage: [], allPages: [], lastPageParam: number) => number;
41
+ };
42
+ mutations: {
43
+ [key: string]: any;
44
+ };
45
+ };
46
+ }): any;
47
+ };
48
+ };
49
+ };
11
50
  }
12
51
  export declare const InjectDependenciesContext: import("react").Context<InjectDependenciesContextProps>;
13
52
  /**
14
- *
53
+ * This provider is used to inject major dependencies
15
54
  * @param children
16
- * @param translate
55
+ * @param librariesDependencies
17
56
  * @param apiURL
18
57
  * @constructor
19
58
  */
20
- declare const InjectDependenciesProvider: ({ children, apiURL }: InjectDependenciesContextProps) => import("react/jsx-runtime").JSX.Element;
59
+ declare const InjectDependenciesProvider: ({ children, apiURL, libraries }: InjectDependenciesContextProps) => import("react/jsx-runtime").JSX.Element;
21
60
  export default InjectDependenciesProvider;
@@ -1,5 +1,5 @@
1
1
  import { PropsWithChildren } from "react";
2
- interface QueryClientConfigProviderProps extends PropsWithChildren {
2
+ interface QueryClientProviderWithConfigProps extends PropsWithChildren {
3
3
  /**
4
4
  * Default options for queries
5
5
  */
@@ -17,5 +17,5 @@ interface QueryClientConfigProviderProps extends PropsWithChildren {
17
17
  * @param defaultMutationsOptions
18
18
  * @constructor
19
19
  */
20
- declare const QueryClientConfigProvider: ({ children, defaultQueriesOptions, defaultMutationsOptions }: QueryClientConfigProviderProps) => import("react/jsx-runtime").JSX.Element;
21
- export default QueryClientConfigProvider;
20
+ declare const QueryClientProviderWithConfig: ({ children, defaultQueriesOptions, defaultMutationsOptions, }: QueryClientProviderWithConfigProps) => import("react/jsx-runtime").JSX.Element;
21
+ export default QueryClientProviderWithConfig;
@@ -1,4 +1,4 @@
1
- import { c as o } from "./main-PeA08MpJ.js";
1
+ import { c as o } from "./main-EkPM5n5x.js";
2
2
  var a = { exports: {} };
3
3
  (function(t, _) {
4
4
  (function(r, e) {
@@ -1,4 +1,4 @@
1
- import { c as m } from "./main-PeA08MpJ.js";
1
+ import { c as m } from "./main-EkPM5n5x.js";
2
2
  import o from "dayjs";
3
3
  var i = { exports: {} };
4
4
  (function(n, s) {
@@ -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;