@tracktor/shared-module 1.0.4 → 1.0.6
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 +10 -12
- package/dist/components/Utils/GTMSendPageView.d.ts +1 -13
- package/dist/components/Utils/RequireAuth.d.ts +12 -22
- package/dist/context/InjectDependenciesProvider.d.ts +3 -42
- package/dist/{en-1o5U8jiL.js → en-QSkYj0iy.js} +1 -1
- package/dist/{fr-EMqEUav3.js → fr-TlWvAsWw.js} +1 -1
- package/dist/hooks/useAdapter/useAdapter.d.ts +2 -13
- package/dist/hooks/useAuth/useAuth.d.ts +1 -8
- package/dist/hooks/useResponseError/useResponseError.d.ts +1 -6
- package/dist/main-srWqMrqy.js +968 -0
- package/dist/main.d.ts +5 -5
- package/dist/main.js +18 -18
- package/dist/main.umd.cjs +10 -10
- package/dist/utils/adapter/dateAdapter.d.ts +2 -5
- package/package.json +1 -1
- package/dist/main-EkPM5n5x.js +0 -973
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# shared-module
|
|
2
2
|
|
|
3
3
|
> This package contains shared components, hooks and utilities for the Tracktor project.
|
|
4
|
-
> This package use dependencies only
|
|
4
|
+
> This package don't use any external dependencies, only peer dependencies.
|
|
5
5
|
> This package is not intended to be used outside the Tracktor project.
|
|
6
6
|
|
|
7
7
|
- [Installation](#Installation)
|
|
@@ -17,19 +17,17 @@ yarn add @tracktor/shared-module
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
19
19
|
```typescript jsx
|
|
20
|
-
import {
|
|
20
|
+
import { AxiosConfig } from "@tracktor/shared-module";
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Inject dependencies with provider
|
|
24
24
|
|
|
25
25
|
```typescript jsx
|
|
26
|
-
import {
|
|
26
|
+
import { AxiosConfig, InjectDependenciesProvider } from "@tracktor/shared-module";
|
|
27
27
|
|
|
28
28
|
const App = () => (
|
|
29
|
-
<InjectDependenciesProvider apiURL={import.meta.env.VITE_API_URL}
|
|
30
|
-
|
|
31
|
-
}}>
|
|
32
|
-
<InitializeAxiosConfig/>
|
|
29
|
+
<InjectDependenciesProvider apiURL={import.meta.env.VITE_API_URL}>
|
|
30
|
+
<AxiosConfig baseURL={import.meta.env.VITE_API_URL} />
|
|
33
31
|
...
|
|
34
32
|
</InjectDependenciesProvider>
|
|
35
33
|
);
|
|
@@ -38,10 +36,10 @@ export default App;
|
|
|
38
36
|
```
|
|
39
37
|
|
|
40
38
|
## Providers
|
|
41
|
-
| Module
|
|
42
|
-
|
|
43
|
-
| InjectDependenciesProvider
|
|
44
|
-
|
|
|
39
|
+
| Module | Description | Dependencies |
|
|
40
|
+
|----------------------------|------------------------------------------------|--------------|
|
|
41
|
+
| InjectDependenciesProvider | Inject dependencies for other shared component | - |
|
|
42
|
+
| QueryClientConfigProvider | React Query provider with default config | React Query |
|
|
45
43
|
|
|
46
44
|
|
|
47
45
|
## Components
|
|
@@ -1,18 +1,6 @@
|
|
|
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
|
-
}
|
|
12
1
|
/**
|
|
13
2
|
* This component send page view to Google Tag Manager
|
|
14
|
-
* @param props
|
|
15
3
|
* @constructor
|
|
16
4
|
*/
|
|
17
|
-
declare const GTMSendPageView: (
|
|
5
|
+
declare const GTMSendPageView: () => import("react/jsx-runtime").JSX.Element | null;
|
|
18
6
|
export default GTMSendPageView;
|
|
@@ -1,29 +1,10 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
|
-
import { InjectDependenciesContextProps } from '../../context/InjectDependenciesProvider';
|
|
3
2
|
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;
|
|
18
3
|
/**
|
|
19
4
|
* Login path
|
|
20
5
|
* @default /login
|
|
21
6
|
*/
|
|
22
7
|
loginPath?: string;
|
|
23
|
-
/**
|
|
24
|
-
* Fallback component for Suspense
|
|
25
|
-
*/
|
|
26
|
-
Fallback?: ReactNode;
|
|
27
8
|
/**
|
|
28
9
|
* Local storage key for user data
|
|
29
10
|
* @default user
|
|
@@ -34,16 +15,25 @@ export interface RequireAuthProps {
|
|
|
34
15
|
* @default /login
|
|
35
16
|
*/
|
|
36
17
|
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;
|
|
37
28
|
}
|
|
38
29
|
/**
|
|
39
30
|
* RequireAuth component for protected routing
|
|
40
31
|
* @param Fallback
|
|
41
|
-
* @param isLogged
|
|
42
32
|
* @param loginPath
|
|
43
33
|
* @param localStorageKey
|
|
44
34
|
* @param redirect401Path
|
|
45
|
-
* @param
|
|
35
|
+
* @param isLogged
|
|
46
36
|
* @constructor
|
|
47
37
|
*/
|
|
48
|
-
declare const RequireAuth: ({ Fallback,
|
|
38
|
+
declare const RequireAuth: ({ Fallback, loginPath, localStorageKey, redirect401Path, isLogged, }: RequireAuthProps) => import("react/jsx-runtime").JSX.Element;
|
|
49
39
|
export default RequireAuth;
|
|
@@ -8,53 +8,14 @@ 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
|
-
};
|
|
50
11
|
}
|
|
51
12
|
export declare const InjectDependenciesContext: import("react").Context<InjectDependenciesContextProps>;
|
|
52
13
|
/**
|
|
53
|
-
*
|
|
14
|
+
*
|
|
54
15
|
* @param children
|
|
55
|
-
* @param
|
|
16
|
+
* @param translate
|
|
56
17
|
* @param apiURL
|
|
57
18
|
* @constructor
|
|
58
19
|
*/
|
|
59
|
-
declare const InjectDependenciesProvider: ({ children, apiURL
|
|
20
|
+
declare const InjectDependenciesProvider: ({ children, apiURL }: InjectDependenciesContextProps) => import("react/jsx-runtime").JSX.Element;
|
|
60
21
|
export default InjectDependenciesProvider;
|
|
@@ -1,20 +1,9 @@
|
|
|
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
|
-
}
|
|
12
1
|
/**
|
|
13
2
|
* Use adapter
|
|
14
3
|
* @returns
|
|
15
4
|
*/
|
|
16
|
-
export declare const useAdapter: (
|
|
17
|
-
dateAdapter: (date: string | number | Date | null | undefined, format?: string) =>
|
|
5
|
+
export declare const useAdapter: () => {
|
|
6
|
+
dateAdapter: (date: string | number | import("dayjs").Dayjs | Date | null | undefined, format?: string) => string;
|
|
18
7
|
distanceAdapter: (distance?: string | number | null | undefined, metric?: string) => string;
|
|
19
8
|
filePathAdapter: (href?: string | null | {
|
|
20
9
|
pathname: string;
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
interface useAuthParams {
|
|
3
|
-
/**
|
|
4
|
-
* Axios library
|
|
5
|
-
*/
|
|
6
|
-
axios?: NonNullable<InjectDependenciesContextProps["libraries"]>["axios"];
|
|
7
|
-
}
|
|
8
|
-
declare const useAuth: (params?: useAuthParams) => {
|
|
1
|
+
declare const useAuth: () => {
|
|
9
2
|
clearAuthenticationToken: () => void;
|
|
10
3
|
setAuthenticationToken: ({ tokenType, accessToken }: {
|
|
11
4
|
tokenType: string;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { InjectDependenciesContextProps } from '../../context/InjectDependenciesProvider';
|
|
2
1
|
export interface ResponseError {
|
|
3
2
|
data?: {
|
|
4
3
|
code?: number;
|
|
@@ -13,10 +12,6 @@ export interface ResponseError {
|
|
|
13
12
|
};
|
|
14
13
|
}
|
|
15
14
|
export interface useResponseErrorParams {
|
|
16
|
-
/**
|
|
17
|
-
* i18 library
|
|
18
|
-
*/
|
|
19
|
-
i18?: NonNullable<InjectDependenciesContextProps["libraries"]>["i18"];
|
|
20
15
|
/**
|
|
21
16
|
* Translation key returned for the unknown error
|
|
22
17
|
*/
|
|
@@ -28,6 +23,6 @@ export interface useResponseErrorParams {
|
|
|
28
23
|
*/
|
|
29
24
|
export declare const useResponseError: <T = ResponseError>(params?: useResponseErrorParams) => {
|
|
30
25
|
getErrorCode: (error?: any) => string;
|
|
31
|
-
printError: (error?: any) =>
|
|
26
|
+
printError: (error?: any) => string;
|
|
32
27
|
};
|
|
33
28
|
export default useResponseError;
|