@tracktor/shared-module 1.0.10 → 2.0.0-beta.10
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 +2 -2
- package/README.md +13 -10
- package/dist/components/Utils/GTMSendPageView.d.ts +13 -1
- package/dist/components/Utils/InitializeAxiosConfig.d.ts +5 -0
- package/dist/components/Utils/InitializeDaysJSConfig.d.ts +14 -1
- package/dist/components/Utils/InitializeI18nConfig.d.ts +6 -1
- package/dist/components/Utils/InitializeMapBoxConfig.d.ts +7 -1
- package/dist/components/Utils/InitializeSentryConfig.d.ts +10 -1
- package/dist/components/Utils/RequireAuth.d.ts +22 -12
- package/dist/context/InjectDependenciesProvider.d.ts +26 -4
- package/dist/context/QueryClientProviderWithConfig.d.ts +12 -4
- package/dist/hooks/useAdapter/useAdapter.d.ts +13 -2
- package/dist/hooks/useAuth/useAuth.d.ts +8 -1
- package/dist/hooks/useResponseError/useResponseError.d.ts +14 -2
- package/dist/main.js +950 -19
- package/dist/main.umd.cjs +10 -10
- package/dist/utils/adapter/dateAdapter.d.ts +8 -2
- package/package.json +3 -22
- package/dist/en-E8ST0UOq.js +0 -18
- package/dist/fr-Iii0rxc-.js +0 -22
- package/dist/main-Kjk_MFFV.js +0 -944
package/CHANGELOG.md
CHANGED
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 {
|
|
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 {
|
|
26
|
+
import { InjectDependenciesProvider, InitializeAxiosConfig } from "@tracktor/shared-module";
|
|
26
27
|
|
|
27
28
|
const App = () => (
|
|
28
|
-
<InjectDependenciesProvider apiURL={import.meta.env.VITE_API_URL}
|
|
29
|
-
|
|
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
|
|
39
|
-
|
|
40
|
-
| InjectDependenciesProvider
|
|
41
|
-
|
|
|
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
|
|
@@ -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,23 @@
|
|
|
1
|
+
import { InjectDependenciesContextProps } from '../../context/InjectDependenciesProvider';
|
|
1
2
|
interface InitializeDaysJSConfigProps {
|
|
3
|
+
/**
|
|
4
|
+
* Dayjs library
|
|
5
|
+
*/
|
|
6
|
+
dayjs?: NonNullable<InjectDependenciesContextProps["libraries"]>["dayjs"];
|
|
7
|
+
/**
|
|
8
|
+
* Dayjs plugin
|
|
9
|
+
*/
|
|
10
|
+
dayjsPlugin?: NonNullable<InjectDependenciesContextProps["libraries"]>["dayjsPlugin"];
|
|
11
|
+
/**
|
|
12
|
+
* Language
|
|
13
|
+
*/
|
|
2
14
|
language?: "fr" | "en";
|
|
3
15
|
}
|
|
4
16
|
/**
|
|
5
17
|
* Initialize dayjs
|
|
6
18
|
* @param language
|
|
19
|
+
* @param props
|
|
7
20
|
* @constructor
|
|
8
21
|
*/
|
|
9
|
-
declare const InitializeDaysJSConfig: ({ language }: InitializeDaysJSConfigProps) => null;
|
|
22
|
+
declare const InitializeDaysJSConfig: ({ language, ...props }: InitializeDaysJSConfigProps) => null;
|
|
10
23
|
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
|
|
45
|
+
* @param props
|
|
36
46
|
* @constructor
|
|
37
47
|
*/
|
|
38
|
-
declare const RequireAuth: ({ Fallback, loginPath, localStorageKey, redirect401Path,
|
|
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,39 @@ export interface InjectDependenciesContextProps {
|
|
|
5
5
|
*/
|
|
6
6
|
children?: ReactNode;
|
|
7
7
|
/**
|
|
8
|
-
* API URL dependency for
|
|
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?: any;
|
|
19
|
+
mapbox?: any;
|
|
20
|
+
reactRouter?: any;
|
|
21
|
+
sentry?: any;
|
|
22
|
+
i18?: {
|
|
23
|
+
i18next?: any;
|
|
24
|
+
initReactI18next?: any;
|
|
25
|
+
languageDetector?: any;
|
|
26
|
+
translateFunction?: any;
|
|
27
|
+
};
|
|
28
|
+
reactQuery?: {
|
|
29
|
+
QueryClientProvider: any;
|
|
30
|
+
QueryClient: any;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
11
33
|
}
|
|
12
34
|
export declare const InjectDependenciesContext: import("react").Context<InjectDependenciesContextProps>;
|
|
13
35
|
/**
|
|
14
|
-
*
|
|
36
|
+
* This provider is used to inject major dependencies
|
|
15
37
|
* @param children
|
|
16
|
-
* @param
|
|
38
|
+
* @param librariesDependencies
|
|
17
39
|
* @param apiURL
|
|
18
40
|
* @constructor
|
|
19
41
|
*/
|
|
20
|
-
declare const InjectDependenciesProvider: ({ children, apiURL }: InjectDependenciesContextProps) => import("react/jsx-runtime").JSX.Element;
|
|
42
|
+
declare const InjectDependenciesProvider: ({ children, apiURL, libraries }: InjectDependenciesContextProps) => import("react/jsx-runtime").JSX.Element;
|
|
21
43
|
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
|
|
26
|
+
* This provider is QueryClientProviderWithConfig with custom default config options
|
|
18
27
|
* @param children
|
|
19
|
-
* @param
|
|
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,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 |
|
|
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
|
-
|
|
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;
|
|
@@ -11,11 +12,22 @@ export interface ResponseError {
|
|
|
11
12
|
}[];
|
|
12
13
|
};
|
|
13
14
|
}
|
|
15
|
+
export interface useResponseErrorParams {
|
|
16
|
+
/**
|
|
17
|
+
* i18 library
|
|
18
|
+
*/
|
|
19
|
+
i18?: NonNullable<InjectDependenciesContextProps["libraries"]>["i18"];
|
|
20
|
+
/**
|
|
21
|
+
* Translation key returned for the unknown error
|
|
22
|
+
*/
|
|
23
|
+
unknownErrorTranslationKey?: string;
|
|
24
|
+
}
|
|
14
25
|
/**
|
|
15
26
|
* This hook is used to print error messages from the API
|
|
27
|
+
* @param params
|
|
16
28
|
*/
|
|
17
|
-
export declare const useResponseError: <T = ResponseError>() => {
|
|
29
|
+
export declare const useResponseError: <T = ResponseError>(params?: useResponseErrorParams) => {
|
|
18
30
|
getErrorCode: (error?: any) => string;
|
|
19
|
-
printError: (error?: any) =>
|
|
31
|
+
printError: (error?: any) => any;
|
|
20
32
|
};
|
|
21
33
|
export default useResponseError;
|