@tracktor/shared-module 0.23.3 → 1.0.0-beta.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.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # [Versions](https://github.com/Tracktor/shared-module/releases)
2
2
 
3
- ## v0.23.3
4
- - **[fix]** : type useInfiniteDataGrid for react query v5
3
+ ## v1.0.0-beta.0
4
+ - **[feat]** : add date adapter
5
+ - **[refactor]** : all dependencies are now peer dependencies
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 don't use any external dependencies.
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,34 +17,18 @@ yarn add @tracktor/shared-module
17
17
  ## Usage
18
18
 
19
19
  ```typescript jsx
20
- import { RequireAuth } from "@tracktor/shared-module";
20
+ import { AxiosConfig } from "@tracktor/shared-module";
21
21
  ```
22
22
 
23
23
  ## Inject dependencies with provider
24
24
 
25
- On this exemple below, dependencies are injected with the
26
- provider `InjectDependenciesProvider` for the component `RequireAuth`:
27
-
28
25
  ```typescript jsx
29
- import { InjectDependenciesProvider, RequireAuth } from "@tracktor/shared-module";
30
- import { Navigate, Outlet, Route, RouterProvider, useLocation } from "react-router-dom";
31
- import { t } from "i18next";
32
-
33
- const MyComponent = () => (
34
- <InjectDependenciesProvider t={t} Navigate={Navigate}>
35
- <RequireAuth />
36
- </InjectDependenciesProvider>
37
- )
26
+ import { AxiosConfig, InjectDependenciesProvider } from "@tracktor/shared-module";
38
27
 
39
28
  const App = () => (
40
- <InjectDependenciesProvider
41
- translate={t}
42
- useAuth={useAuth}
43
- useLocation={useLocation}
44
- Outlet={Outlet}
45
- Navigate={Navigate}
46
- >
47
- <MyComponent/>
29
+ <InjectDependenciesProvider apiURL={import.meta.env.VITE_API_URL}>
30
+ <AxiosConfig baseURL={import.meta.env.VITE_API_URL} />
31
+ ...
48
32
  </InjectDependenciesProvider>
49
33
  );
50
34
 
@@ -52,28 +36,37 @@ export default App;
52
36
  ```
53
37
 
54
38
  ## Providers
55
- | Module | Description |
56
- |----------------------------|-------------------------------------------------------------------------|
57
- | InjectDependenciesProvider | Inject dependencies for other shared component |
58
- | QueryClientConfigProvider | This provider is QueryClientProvider with custom default config options |
39
+ | Module | Description | Dependencies |
40
+ |----------------------------|------------------------------------------------|--------------|
41
+ | InjectDependenciesProvider | Inject dependencies for other shared component | - |
42
+ | QueryClientConfigProvider | React Query provider with default config | React Query |
59
43
 
60
44
 
61
45
  ## Components
62
- | Module | Type | Description |
63
- |----------------------------|-----------------|-------------------------------------------------------------------------|
64
- | RequireAuth | React Component | Component for protected routing |
65
- | GTMSendPageView | React Component | Send page view event to Google Tag Manager |
66
- | AxiosConfig | React Component | Initialize Axios instance with custom default config options |
67
- | I18nConfig | React Component | Initialize i18n instance with custom config options |
68
- | SentryConfig | React Component | Initialize Sentry |
46
+ | Module | Type | Description | Dependencies |
47
+ |-----------------|-----------------|--------------------------------------------------------------|------------------------------------------------------------|
48
+ | RequireAuth | React Component | Component for protected routing | Axios & react-router-dom |
49
+ | GTMSendPageView | React Component | Send page view event to Google Tag Manager | @tracktor/react-google-tag-manager & react-router-dom |
50
+ | AxiosConfig | React Component | Initialize Axios instance with custom default config options | Axios |
51
+ | I18nConfig | React Component | Initialize i18n instance with custom config options | i18next & react-i18next & i18next-browser-languagedetector |
52
+ | SentryConfig | React Component | Initialize Sentry | @sentry/react & react-router-dom |
53
+ | MapBoxConfig | React Component | Initialize MapBox | mapbox-gl |
69
54
 
70
55
  ## Hooks
71
- | Module | Description |
72
- |----------------------|---------------------------------------------------------------------------|
73
- | useResponseError | This hook is used to print error messages from the API |
74
- | useInfiniteDataGrid | his hook is used to handle the infinite scroll of the DataGrid component. |
56
+ | Module | Description | Dependencies |
57
+ |---------------------|---------------------------------------------------------------------------|--------------|
58
+ | useAdapter | Hook with several adapter | - |
59
+ | useAuth | Hook for authentification management | Axios |
60
+ | useResponseError | This hook is used to print error messages from the API | i18next |
61
+ | useInfiniteDataGrid | his hook is used to handle the infinite scroll of the DataGrid component. | - |
75
62
 
76
63
  ## Config
77
64
  | Module | Description |
78
65
  |-----------------------|------------------------------------|
79
66
  | getOrvalOperationName | Get config for orval operationName |
67
+
68
+ ## Utils
69
+ | Module | Description |
70
+ |-----------------|----------------------|
71
+ | dateAdapter | Adapt given date |
72
+ | distanceAdapter | Adapt given distance |
@@ -1,20 +1,4 @@
1
- interface AxiosConfigProps<T> {
2
- /**
3
- * Axios instance
4
- */
5
- axios: T & {
6
- defaults: {
7
- baseURL?: string;
8
- headers: {
9
- common: {
10
- Authorization?: any;
11
- };
12
- post: {
13
- "Content-Type"?: any;
14
- };
15
- };
16
- };
17
- };
1
+ interface AxiosConfigProps {
18
2
  /**
19
3
  * User local storage key
20
4
  * @default user
@@ -43,12 +27,11 @@ interface AxiosConfigProps<T> {
43
27
  /**
44
28
  * This component initialize Axios instance with custom default config options
45
29
  * @param axios
46
- * @param baseURL
47
30
  * @param tokenTypeKey
48
31
  * @param userLocalStorageKey
49
32
  * @param tokenKey
50
33
  * @param postContentType
51
34
  * @constructor
52
35
  */
53
- declare const AxiosConfig: <T extends unknown>({ axios, baseURL, tokenTypeKey, userLocalStorageKey, tokenKey, postContentType, }: AxiosConfigProps<T>) => null;
36
+ declare const AxiosConfig: ({ tokenTypeKey, userLocalStorageKey, tokenKey, postContentType, ...props }: AxiosConfigProps) => null;
54
37
  export default AxiosConfig;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Initialize dayjs
3
+ * @constructor
4
+ */
5
+ declare const DaysJSConfig: () => null;
6
+ export default DaysJSConfig;
@@ -1,22 +1,6 @@
1
- import { InjectDependenciesContextProps } from '../../context/InjectDependenciesProvider';
2
- export interface GTMSendPageViewProps {
3
- /**
4
- * useGoogleTagManager is the hook that will be used to send page view
5
- */
6
- useGoogleTagManager?: InjectDependenciesContextProps["useGoogleTagManager"];
7
- /**
8
- * Outlet is the component that will be rendered
9
- */
10
- Outlet?: InjectDependenciesContextProps["Outlet"];
11
- /**
12
- * useLocation is the hook that will be used to get current pathname
13
- */
14
- useLocation?: InjectDependenciesContextProps["useLocation"];
15
- }
16
1
  /**
17
2
  * This component send page view to Google Tag Manager
18
- * @param props
19
3
  * @constructor
20
4
  */
21
- declare const GTMSendPageView: ({ ...props }: GTMSendPageViewProps) => import("react/jsx-runtime").JSX.Element;
5
+ declare const GTMSendPageView: () => import("react/jsx-runtime").JSX.Element;
22
6
  export default GTMSendPageView;
@@ -1,45 +1,21 @@
1
- interface I18nConfigProps<I, L, R> {
1
+ interface I18nConfigProps {
2
2
  /**
3
- * i18n instance
4
- */
5
- i18n: I & {
6
- use: (plugin: any) => any;
7
- init: (options: any) => any;
8
- on: (event: string, callback: (lng: string) => void) => void;
9
- resolvedLanguage?: string;
10
- isInitialized?: boolean;
11
- };
12
- /**
13
- * i18next language detector dependency
14
- */
15
- LanguageDetector?: L;
16
- /**
17
- * i18next ressources
18
- * exemple
19
- * {
20
- * en: {
21
- * roles: {...},
22
- * translation: {...},
23
- * },
24
- * }
3
+ * Resources to initialize with (if not using loading or not appending using addResourceBundle)
25
4
  */
26
5
  resources?: {
27
6
  [language: string]: any;
28
7
  };
29
8
  /**
30
- * i18next innit react plugin dependency
9
+ * Enable debug mode
31
10
  */
32
- initReactI18next?: R;
33
11
  debug?: boolean;
34
12
  }
35
13
  /**
36
14
  * This component initializes i18n instance with custom config options
37
15
  * @param i18n
38
16
  * @param debug
39
- * @param initReactI18next
40
17
  * @param resources
41
- * @param LanguageDetector
42
18
  * @constructor
43
19
  */
44
- declare const I18nConfig: <I extends unknown, L extends unknown, R extends unknown>({ i18n, debug, initReactI18next, resources, LanguageDetector, }: I18nConfigProps<I, L, R>) => null;
20
+ declare const I18nConfig: ({ debug, resources }: I18nConfigProps) => null;
45
21
  export default I18nConfig;
@@ -1,10 +1,4 @@
1
- interface MapBoxConfigProps<T> {
2
- /**
3
- * Mapbox instance
4
- */
5
- mapbox: T & {
6
- accessToken: string;
7
- };
1
+ interface MapBoxConfigProps {
8
2
  /**
9
3
  * MapBox access token
10
4
  */
@@ -16,5 +10,5 @@ interface MapBoxConfigProps<T> {
16
10
  * @param accessToken
17
11
  * @constructor
18
12
  */
19
- declare const MapBoxConfig: <T extends unknown>({ mapbox, accessToken }: MapBoxConfigProps<T>) => null;
13
+ declare const MapBoxConfig: ({ accessToken }: MapBoxConfigProps) => null;
20
14
  export default MapBoxConfig;
@@ -1,35 +1,10 @@
1
1
  import { ReactNode } from "react";
2
- import { InjectDependenciesContextProps } from '../../context/InjectDependenciesProvider';
3
2
  export interface RequireAuthProps {
4
3
  /**
5
4
  * Login path
6
5
  * @default /login
7
6
  */
8
7
  loginPath?: string;
9
- /**
10
- * Fallback component for Suspense
11
- */
12
- Fallback?: ReactNode;
13
- /**
14
- * Outlet dependency for RequireAuth component
15
- */
16
- Outlet?: InjectDependenciesContextProps["Outlet"];
17
- /**
18
- * Navigate dependency for RequireAuth component
19
- */
20
- Navigate?: InjectDependenciesContextProps["Navigate"];
21
- /**
22
- * useLocation dependency for RequireAuth component
23
- */
24
- useLocation?: InjectDependenciesContextProps["useLocation"];
25
- /**
26
- * useAuth dependency for RequireAuth component
27
- */
28
- useAuth?: InjectDependenciesContextProps["useAuth"];
29
- /**
30
- * Axios instance dependency is used for intercepting 401 responses
31
- */
32
- axios?: InjectDependenciesContextProps["axios"];
33
8
  /**
34
9
  * Local storage key for user data
35
10
  * @default user
@@ -40,16 +15,23 @@ export interface RequireAuthProps {
40
15
  * @default /login
41
16
  */
42
17
  redirect401Path?: string;
18
+ /**
19
+ * Is user logged in
20
+ */
21
+ isLogged?: boolean;
22
+ /**
23
+ * Fallback component for Suspense
24
+ */
25
+ Fallback?: ReactNode;
43
26
  }
44
27
  /**
45
28
  * RequireAuth component for protected routing
46
- * @param axios
47
29
  * @param Fallback
48
30
  * @param loginPath
49
31
  * @param localStorageKey
50
32
  * @param redirect401Path
51
- * @param props
33
+ * @param isLogged
52
34
  * @constructor
53
35
  */
54
- declare const RequireAuth: ({ Fallback, loginPath, localStorageKey, redirect401Path, ...props }: RequireAuthProps) => import("react/jsx-runtime").JSX.Element;
36
+ declare const RequireAuth: ({ Fallback, loginPath, localStorageKey, redirect401Path, isLogged, }: RequireAuthProps) => import("react/jsx-runtime").JSX.Element;
55
37
  export default RequireAuth;
@@ -1,67 +1,4 @@
1
- interface SentryConfigProps<T> {
2
- /**
3
- * Sentry instance
4
- */
5
- sentry: T & {
6
- init: (config: {
7
- /**
8
- * Enable debug mode.
9
- */
10
- debug?: boolean;
11
- /**
12
- * The Dsn used to connect to Sentry and identify the project. If omitted, the SDK will not send any data to Sentry.
13
- */
14
- dsn: string;
15
- /**
16
- * List of integrations that should be installed after SDK was initialized.
17
- */
18
- integrations: any[];
19
- /**
20
- * Sample rate to determine trace sampling.
21
- *
22
- * 0.0 = 0% chance of a given trace being sent (send no traces) 1.0 = 100% chance of a given trace being sent (send
23
- * all traces)
24
- *
25
- * Tracing is enabled if either this or `tracesSampler` is defined. If both are defined, `tracesSampleRate` is
26
- * ignored.
27
- */
28
- tracesSampleRate: number;
29
- /**
30
- * Sample rate to determine session sampling.
31
- */
32
- replaysOnErrorSampleRate: number;
33
- /**
34
- * Sample rate to determine session sampling.
35
- */
36
- replaysSessionSampleRate: number;
37
- /**
38
- * List of strings/regex controlling to which outgoing requests the SDK will attach tracing headers.
39
- */
40
- tracePropagationTargets?: (string | RegExp)[];
41
- /**
42
- * A pattern for error messages which should not be sent to Sentry.
43
- * By default, all errors will be sent.
44
- */
45
- ignoreErrors?: Array<string | RegExp>;
46
- /**
47
- * The current environment of your application (e.g. "production").
48
- */
49
- environment?: string;
50
- }) => void;
51
- BrowserTracing: any;
52
- /**
53
- * This function is used to instrument React Router v6.
54
- */
55
- replayIntegration: any;
56
- /**
57
- * This function is used to instrument React Router v6.
58
- */
59
- reactRouterV6Instrumentation: any;
60
- /**
61
- * Returns true if the SDK is already initialized.
62
- */
63
- isInitialized: () => boolean;
64
- };
1
+ interface SentryConfigProps {
65
2
  /**
66
3
  * Sentry DSN
67
4
  */
@@ -69,13 +6,6 @@ interface SentryConfigProps<T> {
69
6
  /**
70
7
  * List of integrations that should be installed after SDK was initialized.
71
8
  */
72
- routingInstrumentationDependencies: {
73
- useEffect: any;
74
- useLocation: any;
75
- useNavigationType: any;
76
- createRoutesFromChildren: any;
77
- matchRoutes: any;
78
- };
79
9
  /**
80
10
  * List of integrations that should be installed after SDK was initialized.
81
11
  */
@@ -125,7 +55,6 @@ interface SentryConfigProps<T> {
125
55
  * @param sentry
126
56
  * @param integrations
127
57
  * @param tracesSampleRate
128
- * @param routingInstrumentationDependencies
129
58
  * @param replaysSessionSampleRate
130
59
  * @param replaysOnErrorSampleRate
131
60
  * @param tracePropagationTargets
@@ -134,5 +63,5 @@ interface SentryConfigProps<T> {
134
63
  * @param environment
135
64
  * @constructor
136
65
  */
137
- declare const SentryConfig: <T extends unknown>({ dsn, sentry, integrations, tracesSampleRate, routingInstrumentationDependencies, replaysSessionSampleRate, replaysOnErrorSampleRate, tracePropagationTargets, ignoreErrors, debug, environment, }: SentryConfigProps<T>) => null;
66
+ declare const SentryConfig: ({ dsn, integrations, tracesSampleRate, replaysSessionSampleRate, replaysOnErrorSampleRate, tracePropagationTargets, ignoreErrors, debug, environment, }: SentryConfigProps) => null;
138
67
  export default SentryConfig;
@@ -1,4 +1,4 @@
1
- import { AxiosError } from "axios";
1
+ import { AxiosError, AxiosRequestConfig } from "axios";
2
2
  export declare const axiosCustomInstance: <T>(config: AxiosRequestConfig) => Promise<T>;
3
3
  export default axiosCustomInstance;
4
4
  export interface ErrorType<Error> extends AxiosError<Error> {
@@ -1,4 +1,3 @@
1
- // @ts-ignore
2
1
  import axios, { AxiosError, AxiosRequestConfig } from "axios";
3
2
 
4
3
  axios.create();
@@ -1,72 +1,21 @@
1
- import { ReactElement, ReactNode } from "react";
1
+ import { ReactNode } from "react";
2
2
  export interface InjectDependenciesContextProps {
3
3
  /**
4
4
  * Children
5
5
  */
6
6
  children?: ReactNode;
7
- /**
8
- * Axios instance dependency
9
- */
10
- axios?: any;
11
7
  /**
12
8
  * API URL dependency for useAdapter hook
13
9
  */
14
10
  apiURL?: string;
15
- /**
16
- * Translate function dependency for useResponseError hook
17
- * @param key
18
- */
19
- translate?(key: any): string;
20
- /**
21
- * Outlet dependency for RequireAuth component
22
- */
23
- Outlet?(props: {
24
- context?: unknown;
25
- }): ReactElement | null;
26
- /**
27
- * Navigate dependency for RequireAuth component
28
- */
29
- Navigate?(props: {
30
- to: string;
31
- replace?: boolean;
32
- state?: any;
33
- }): null;
34
- /**
35
- * useLocation dependency for RequireAuth component
36
- */
37
- useLocation?(): {
38
- state: any;
39
- pathname: string;
40
- };
41
- /**
42
- * useAuth dependency for RequireAuth component
43
- */
44
- useAuth?(): {
45
- isLogged: boolean;
46
- };
47
- /**
48
- * useGoogleTagManager dependency for GTMSendPageView component
49
- */
50
- useGoogleTagManager?(): {
51
- sendEvent: (event: {
52
- event: string;
53
- pathname: string;
54
- }) => void;
55
- };
56
11
  }
57
12
  export declare const InjectDependenciesContext: import("react").Context<InjectDependenciesContextProps>;
58
13
  /**
59
- * This provider is used to inject major dependencies
60
- * @param axios
14
+ *
61
15
  * @param children
62
16
  * @param translate
63
- * @param useAuth
64
- * @param Outlet
65
- * @param Navigate
66
- * @param useLocation
67
- * @param useGoogleTagManager
68
17
  * @param apiURL
69
18
  * @constructor
70
19
  */
71
- declare const InjectDependenciesProvider: ({ axios, children, translate, useAuth, Outlet, Navigate, useLocation, useGoogleTagManager, apiURL, }: InjectDependenciesContextProps) => import("react/jsx-runtime").JSX.Element;
20
+ declare const InjectDependenciesProvider: ({ children, apiURL }: InjectDependenciesContextProps) => import("react/jsx-runtime").JSX.Element;
72
21
  export default InjectDependenciesProvider;
@@ -1,4 +1,4 @@
1
- import { PropsWithChildren, ReactNode } from "react";
1
+ import { PropsWithChildren } from "react";
2
2
  interface QueryClientConfigProviderProps<T> extends PropsWithChildren {
3
3
  /**
4
4
  * QueryClient instance
@@ -9,31 +9,31 @@ interface QueryClientConfigProviderProps<T> extends PropsWithChildren {
9
9
  queries: {
10
10
  refetchOnWindowFocus: boolean;
11
11
  retry: number;
12
+ getNextPageParam: (lastPage: [], allPages: [], lastPageParam: number) => number;
13
+ };
14
+ mutations: {
15
+ [key: string]: any;
12
16
  };
13
17
  };
14
18
  }): T;
15
19
  };
16
- /**
17
- * QueryClientProvider component
18
- */
19
- QueryClientProvider: ({ client, children }: {
20
- client: T;
21
- children: ReactNode;
22
- }) => any;
23
20
  /**
24
21
  * Default options for queries
25
22
  */
26
- defaultOptions?: {
23
+ defaultQueriesOptions?: {
24
+ [key: string]: any;
25
+ };
26
+ defaultMutationsOptions?: {
27
27
  [key: string]: any;
28
28
  };
29
29
  }
30
30
  /**
31
31
  * This provider is QueryClientProvider with custom default config options
32
32
  * @param children
33
- * @param options
33
+ * @param defaultQueriesOptions
34
+ * @param defaultMutationsOptions
34
35
  * @param QueryClient
35
- * @param QueryClientProvider
36
36
  * @constructor
37
37
  */
38
- declare const QueryClientConfigProvider: <T extends unknown>({ children, defaultOptions, QueryClient, QueryClientProvider, }: QueryClientConfigProviderProps<T>) => import("react/jsx-runtime").JSX.Element;
38
+ declare const QueryClientConfigProvider: <T extends unknown>({ children, defaultQueriesOptions, defaultMutationsOptions, QueryClient, }: QueryClientConfigProviderProps<T>) => import("react/jsx-runtime").JSX.Element;
39
39
  export default QueryClientConfigProvider;
@@ -1,4 +1,9 @@
1
+ /**
2
+ * Use adapter
3
+ * @returns
4
+ */
1
5
  export declare const useAdapter: () => {
6
+ dateAdapter: (date: string | number | Date | import("dayjs").Dayjs | null | undefined, format?: string) => string;
2
7
  distanceAdapter: (distance?: string | number | null | undefined, metric?: string) => string;
3
8
  filePathAdapter: (href?: string | null | {
4
9
  pathname: string;
@@ -1,17 +1,4 @@
1
- export interface useAuthParams {
2
- /**
3
- * Axios instance
4
- */
5
- defaults: {
6
- baseURL?: string;
7
- headers: {
8
- common: {
9
- Authorization?: any;
10
- };
11
- };
12
- };
13
- }
14
- declare const useAuth: <T>(axios: useAuthParams & T) => {
1
+ declare const useAuth: () => {
15
2
  clearAuthenticationToken: () => void;
16
3
  setAuthenticationToken: ({ tokenType, accessToken }: {
17
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,11 +12,6 @@ export interface ResponseError {
13
12
  };
14
13
  }
15
14
  export interface useResponseErrorParams {
16
- /**
17
- * Translation function if you want to use your own translation function
18
- * @param str
19
- */
20
- translate?: InjectDependenciesContextProps["translate"];
21
15
  /**
22
16
  * Translation key returned for the unknown error
23
17
  */
package/dist/main.d.ts CHANGED
@@ -26,3 +26,5 @@ export { default as useAdapter } from './hooks/useAdapter';
26
26
  export * from './hooks/useAdapter';
27
27
  export { default as getOrvalConfig } from './config/orval';
28
28
  export * from './config/orval';
29
+ export { default as dateAdapter } from './utils/adapter/dateAdapter';
30
+ export { default as distanceAdapter } from './utils/adapter/distanceAdapter';