@acrool/react-fetcher 0.0.5 → 0.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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Acrool React Fetcher is a solution for API integration and Auth state management in React projects. It helps you easily manage tokens, make API requests, perform GraphQL queries, and handle authentication flows.
4
4
 
5
5
  <a href="https://acrool-react-fetcher.pages.dev/" title="Acrool React Fetcher - This is a block function for React development loading block">
6
- <img src="https://raw.githubusercontent.com/acrool/acrool-react-fetcher/main/example/graphQL/public/og.png" alt="Acrool React Fetcher Logo"/>
6
+ <img src="https://raw.githubusercontent.com/acrool/acrool-react-fetcher/main/example/public/og.png" alt="Acrool React Fetcher Logo"/>
7
7
  </a>
8
8
 
9
9
  <p align="center">
@@ -57,7 +57,7 @@ import "@acrool/react-fetcher/dist/index.css";
57
57
  Wrap your app with `AuthStateProvider` and `AxiosClientProvider`. It is recommended to use `AppFetcherProvider` to automatically wrap all necessary providers:
58
58
 
59
59
  ```tsx
60
- import AppFetcherProvider from '@/library/acrool-react-fetcher';
60
+ import AppFetcherProvider from '@/library/react-fetcher';
61
61
 
62
62
  ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
63
63
  <AppFetcherProvider>
@@ -73,7 +73,7 @@ For Redux Toolkit Query, create `baseApi.ts`:
73
73
  ```ts
74
74
  import { createGraphQLFetcher } from '@acrool/react-fetcher';
75
75
  import { createApi } from '@reduxjs/toolkit/query/react';
76
- import { axiosInstance } from '@/library/acrool-react-fetcher';
76
+ import { axiosInstance } from '@/library/react-fetcher';
77
77
 
78
78
  export const baseApi = createApi({
79
79
  reducerPath: 'api',
@@ -1,2 +1,2 @@
1
1
  export { default as AuthStateProvider, useAuthState } from './AuthStateProvider';
2
- export type { IAuthTokens } from './types';
2
+ export type { IAuthTokens, TOnForceLogout, TOnGetTokens, TOnRefreshToken, TOnSetTokens } from './types';
@@ -1,18 +1,16 @@
1
1
  import { AxiosInstance } from 'axios';
2
2
  import { default as React } from 'react';
3
- import { IInternalRequestConfig } from '../fetchers/types';
4
- import { IFormatResponseErrorReturn, TGetResponseFormatError } from './types';
3
+ import { TCheckIsRefreshTokenRequest, TGetResponseFormatError, TResponseOnErrorCallback } from './types';
5
4
  export declare const AxiosClientContext: React.Context<AxiosInstance | null>;
6
5
  export declare const useAxiosClient: () => null;
7
6
  interface IProps {
8
7
  children: React.ReactNode;
9
8
  axiosInstance: AxiosInstance;
10
- checkIsRefreshTokenRequest?: (config: IInternalRequestConfig) => boolean;
9
+ checkIsRefreshTokenRequest?: TCheckIsRefreshTokenRequest;
11
10
  locale?: string;
12
11
  getResponseFormatError?: TGetResponseFormatError;
13
- onError?: (error: IFormatResponseErrorReturn) => void;
12
+ onError?: TResponseOnErrorCallback;
14
13
  authorizationPrefix?: string;
15
- i18nDict?: Record<string, Record<number, string>>;
16
14
  isDebug?: boolean;
17
15
  }
18
16
  /**
@@ -22,5 +20,5 @@ interface IProps {
22
20
  * @param locale
23
21
  * @param onError
24
22
  */
25
- declare const FetcherProvider: ({ children, axiosInstance, locale, getResponseFormatError, onError, checkIsRefreshTokenRequest, authorizationPrefix, i18nDict, isDebug, }: IProps) => import("react/jsx-runtime").JSX.Element;
23
+ declare const FetcherProvider: ({ children, axiosInstance, locale, getResponseFormatError, onError, checkIsRefreshTokenRequest, authorizationPrefix, isDebug, }: IProps) => import("react/jsx-runtime").JSX.Element;
26
24
  export default FetcherProvider;
@@ -1,3 +1,3 @@
1
1
  export { default as FetcherProvider } from './FetcherProvider';
2
2
  export { getGraphQLResponseFormatError, getRestFulResponseFormatError } from './utils';
3
- export type { TGetResponseFormatError } from './types';
3
+ export type { TGetResponseFormatError, IFormatResponseErrorReturn, TResponseOnErrorCallback, TCheckIsRefreshTokenRequest } from './types';
@@ -1,11 +1,14 @@
1
1
  import { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
2
+ import { IInternalRequestConfig } from '../fetchers/types';
2
3
  export type TInterceptorRequest = (value: InternalAxiosRequestConfig<any>) => InternalAxiosRequestConfig<any> | Promise<InternalAxiosRequestConfig<any>>;
3
4
  export type TInterceptorResponseSuccess = (value: AxiosResponse<any>) => AxiosResponse<any> | Promise<AxiosResponse<any>>;
4
5
  export type TInterceptorResponseError = (error: AxiosError<any>) => AxiosResponse<any> | Promise<AxiosResponse<any>>;
5
6
  export interface IFormatResponseErrorReturn {
6
7
  message: string;
7
- code: string;
8
+ code?: string;
8
9
  path?: string;
9
10
  args?: any;
10
11
  }
11
- export type TGetResponseFormatError = (response?: AxiosResponse) => IFormatResponseErrorReturn;
12
+ export type TGetResponseFormatError = (axiosError?: AxiosError) => IFormatResponseErrorReturn;
13
+ export type TCheckIsRefreshTokenRequest = (config: IInternalRequestConfig) => boolean;
14
+ export type TResponseOnErrorCallback = (error: IFormatResponseErrorReturn) => void;
@@ -2,11 +2,11 @@ import { TGetResponseFormatError } from './types';
2
2
  /**
3
3
  * 返回 Axios 格式錯誤 With GraphQL
4
4
  * 針對 GraphQL多錯誤格式
5
- * @param response
5
+ * @param axiosError
6
6
  */
7
7
  export declare const getGraphQLResponseFormatError: TGetResponseFormatError;
8
8
  /**
9
9
  * 返回 Axios 格式錯誤 with RestFul
10
- * @param response
10
+ * @param axiosError
11
11
  */
12
12
  export declare const getRestFulResponseFormatError: TGetResponseFormatError;