@tracktor/shared-module 0.3.0 → 0.5.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,7 @@
1
1
  # [Versions](https://github.com/Tracktor/react-google-tag-manager/releases)
2
2
 
3
- ## v0.3.0
4
- - **[feat]** : Add GTMSendPageView
3
+ ## v0.5.0
4
+ - **[feat]** : add config component `AxiosConfig`
5
+ - **[feat]** : add config component `I18nConfig`
6
+ - **[feat]** : add config component `SentryConfig`
7
+ - **[feat]** : add provider `QueryClientConfigProvider`
package/README.md CHANGED
@@ -50,3 +50,17 @@ const App = () => (
50
50
 
51
51
  export default App;
52
52
  ```
53
+
54
+ ## Exported module
55
+
56
+
57
+ | Module | Type | Description |
58
+ |----------------------------|-----------------|-------------------------------------------------------------------------|
59
+ | RequireAuth | React Component | Component for protected routing |
60
+ | GTMSendPageView | React Component | Send page view event to Google Tag Manager |
61
+ | AxiosConfig | React Component | Initialize Axios instance with custom default config options |
62
+ | I18nConfig | React Component | Initialize i18n instance with custom config options |
63
+ | SentryConfig | React Component | Initialize Sentry |
64
+ | InjectDependenciesProvider | React Provider | Inject dependencies for other shared component |
65
+ | QueryClientConfigProvider | React Provider | This provider is QueryClientProvider with custom default config options |
66
+ | useResponseError | React Hook | This hook is used to print error messages from the API |
@@ -0,0 +1,40 @@
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
+ };
18
+ /**
19
+ * User local storage key
20
+ */
21
+ userLocalStorageKey?: string;
22
+ /**
23
+ * Base URL for Axios instance
24
+ */
25
+ baseURL?: string;
26
+ /**
27
+ * Post content type for Axios instance
28
+ */
29
+ postContentType?: string;
30
+ }
31
+ /**
32
+ * This component initialize Axios instance with custom default config options
33
+ * @param axios
34
+ * @param baseURL
35
+ * @param userLocalStorageKey
36
+ * @param postContentType
37
+ * @constructor
38
+ */
39
+ declare const AxiosConfig: <T extends unknown>({ axios, baseURL, userLocalStorageKey, postContentType, }: AxiosConfigProps<T>) => null;
40
+ export default AxiosConfig;
@@ -4,5 +4,10 @@ export interface GTMSendPageViewProps {
4
4
  Outlet?: InjectDependenciesContextProps["Outlet"];
5
5
  useLocation?: InjectDependenciesContextProps["useLocation"];
6
6
  }
7
+ /**
8
+ * This component send page view to Google Tag Manager
9
+ * @param props
10
+ * @constructor
11
+ */
7
12
  declare const GTMSendPageView: ({ ...props }: GTMSendPageViewProps) => JSX.Element;
8
13
  export default GTMSendPageView;
@@ -0,0 +1,26 @@
1
+ interface I18nConfigProps<I, L, R> {
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
+ };
11
+ LanguageDetector?: L;
12
+ resources?: {
13
+ [language: string]: any;
14
+ };
15
+ initReactI18next?: R;
16
+ }
17
+ /**
18
+ * This component initializes i18n instance with custom config options
19
+ * @param i18n
20
+ * @param initReactI18next
21
+ * @param resources
22
+ * @param LanguageDetector
23
+ * @constructor
24
+ */
25
+ declare const I18nConfig: <I extends unknown, L extends unknown, R extends unknown>({ i18n, initReactI18next, resources, LanguageDetector, }: I18nConfigProps<I, L, R>) => null;
26
+ export default I18nConfig;
@@ -0,0 +1,52 @@
1
+ import { ReactNode } from "react";
2
+ import { InjectDependenciesContextProps } from '../../context/InjectDependenciesProvider';
3
+ export interface RequireAuthProps {
4
+ /**
5
+ *
6
+ */
7
+ loginPath?: string;
8
+ /**
9
+ * Fallback component for Suspense
10
+ */
11
+ Fallback?: ReactNode;
12
+ /**
13
+ * Outlet dependency for RequireAuth component
14
+ */
15
+ Outlet?: InjectDependenciesContextProps["Outlet"];
16
+ /**
17
+ * Navigate dependency for RequireAuth component
18
+ */
19
+ Navigate?: InjectDependenciesContextProps["Navigate"];
20
+ /**
21
+ * useLocation dependency for RequireAuth component
22
+ */
23
+ useLocation?: InjectDependenciesContextProps["useLocation"];
24
+ /**
25
+ * useAuth dependency for RequireAuth component
26
+ */
27
+ useAuth?: InjectDependenciesContextProps["useAuth"];
28
+ /**
29
+ * Axios instance dependency is used for intercepting 401 responses
30
+ */
31
+ axios?: InjectDependenciesContextProps["axios"];
32
+ /**
33
+ * Local storage key for user data
34
+ */
35
+ localStorageKey?: string;
36
+ /**
37
+ * Redirect path for 401 responses
38
+ */
39
+ redirect401Path?: string;
40
+ }
41
+ /**
42
+ * RequireAuth component for protected routing
43
+ * @param axios
44
+ * @param Fallback
45
+ * @param loginPath
46
+ * @param localStorageKey
47
+ * @param redirect401Path
48
+ * @param props
49
+ * @constructor
50
+ */
51
+ declare const RequireAuth: ({ Fallback, loginPath, localStorageKey, redirect401Path, ...props }: RequireAuthProps) => JSX.Element;
52
+ export default RequireAuth;
@@ -0,0 +1,22 @@
1
+ interface SentryConfigProps<T> {
2
+ /**
3
+ * Sentry instance
4
+ */
5
+ sentry: T & {
6
+ init: (config: {
7
+ dsn: string;
8
+ integrations: any[];
9
+ tracesSampleRate: number;
10
+ }) => void;
11
+ BrowserTracing: any;
12
+ };
13
+ dsn: string;
14
+ }
15
+ /**
16
+ * This component is used to initialize Sentry
17
+ * @param dsn
18
+ * @param sentry
19
+ * @constructor
20
+ */
21
+ declare const SentryConfig: <T extends unknown>({ dsn, sentry }: SentryConfigProps<T>) => null;
22
+ export default SentryConfig;
@@ -4,6 +4,10 @@ export interface InjectDependenciesContextProps {
4
4
  * Children
5
5
  */
6
6
  children?: ReactNode;
7
+ /**
8
+ * Axios instance dependency
9
+ */
10
+ axios?: any;
7
11
  /**
8
12
  * Translate function dependency for useResponseError hook
9
13
  * @param str
@@ -47,5 +51,17 @@ export interface InjectDependenciesContextProps {
47
51
  };
48
52
  }
49
53
  export declare const InjectDependenciesContext: import("react").Context<InjectDependenciesContextProps>;
50
- declare const InjectDependenciesProvider: ({ children, translate, useAuth, Outlet, Navigate, useLocation, useGoogleTagManager, }: InjectDependenciesContextProps) => JSX.Element;
54
+ /**
55
+ * This provider is used to inject dependencies to components
56
+ * @param axios
57
+ * @param children
58
+ * @param translate
59
+ * @param useAuth
60
+ * @param Outlet
61
+ * @param Navigate
62
+ * @param useLocation
63
+ * @param useGoogleTagManager
64
+ * @constructor
65
+ */
66
+ declare const InjectDependenciesProvider: ({ axios, children, translate, useAuth, Outlet, Navigate, useLocation, useGoogleTagManager, }: InjectDependenciesContextProps) => JSX.Element;
51
67
  export default InjectDependenciesProvider;
@@ -0,0 +1,36 @@
1
+ import { PropsWithChildren, ReactNode } from "react";
2
+ interface QueryClientConfigProviderProps<T> extends PropsWithChildren {
3
+ /**
4
+ * QueryClient instance
5
+ */
6
+ QueryClient: {
7
+ new (config: {
8
+ defaultOptions: {
9
+ queries: {
10
+ refetchOnWindowFocus: boolean;
11
+ retry: number;
12
+ };
13
+ };
14
+ }): T;
15
+ };
16
+ /**
17
+ * QueryClientProvider component
18
+ */
19
+ QueryClientProvider: ({ client, children }: {
20
+ client: T;
21
+ children: ReactNode;
22
+ }) => any;
23
+ defaultOptions?: {
24
+ [key: string]: any;
25
+ };
26
+ }
27
+ /**
28
+ * This provider is QueryClientProvider with custom default config options
29
+ * @param children
30
+ * @param options
31
+ * @param QueryClient
32
+ * @param QueryClientProvider
33
+ * @constructor
34
+ */
35
+ declare const QueryClientConfigProvider: <T extends unknown>({ children, defaultOptions, QueryClient, QueryClientProvider, }: QueryClientConfigProviderProps<T>) => JSX.Element;
36
+ export default QueryClientConfigProvider;
package/dist/main.d.ts CHANGED
@@ -1,8 +1,16 @@
1
- export { default as RequireAuth } from './components/RequireAuth';
2
- export * from './components/RequireAuth';
3
- export { default as GTMSendPageView } from './components/GTMSendPageView';
4
- export * from './components/GTMSendPageView';
1
+ export { default as RequireAuth } from './components/utils/RequireAuth';
2
+ export * from './components/utils/RequireAuth';
3
+ export { default as GTMSendPageView } from './components/utils/GTMSendPageView';
4
+ export * from './components/utils/GTMSendPageView';
5
+ export { default as AxiosConfig } from './components/utils/AxiosConfig';
6
+ export * from './components/utils/AxiosConfig';
7
+ export { default as I18nConfig } from './components/utils/I18nConfig';
8
+ export * from './components/utils/I18nConfig';
9
+ export { default as SentryConfig } from './components/utils/SentryConfig';
10
+ export * from './components/utils/SentryConfig';
5
11
  export { default as InjectDependenciesProvider } from './context/InjectDependenciesProvider';
6
12
  export * from './context/InjectDependenciesProvider';
13
+ export { default as QueryClientProvider } from './context/QueryClientProvider';
14
+ export * from './context/QueryClientProvider';
7
15
  export { default as useResponseError } from './hooks/useResponseError';
8
16
  export * from './hooks/useResponseError';