@acrool/react-fetcher 0.0.2-alpha.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/LICENSE +21 -0
- package/README.md +100 -0
- package/dist/AuthStateProvider/AuthStateProvider.d.ts +20 -0
- package/dist/AuthStateProvider/index.d.ts +2 -0
- package/dist/AuthStateProvider/types.d.ts +12 -0
- package/dist/FetcherProvider/AxiosCancelException.d.ts +17 -0
- package/dist/FetcherProvider/FetcherProvider.d.ts +21 -0
- package/dist/FetcherProvider/config.d.ts +2 -0
- package/dist/FetcherProvider/index.d.ts +2 -0
- package/dist/FetcherProvider/types.d.ts +10 -0
- package/dist/FetcherProvider/utils.d.ts +7 -0
- package/dist/acrool-react-fetcher.es.js +2327 -0
- package/dist/exception/SystemException.d.ts +17 -0
- package/dist/exception/index.d.ts +1 -0
- package/dist/fetchers/graphqlFetcher.d.ts +4 -0
- package/dist/fetchers/index.d.ts +2 -0
- package/dist/fetchers/types.d.ts +11 -0
- package/dist/fetchers/utils.d.ts +13 -0
- package/dist/index.d.ts +3 -0
- package/package.json +106 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Acrool
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Acrool React Fetcher
|
|
2
|
+
|
|
3
|
+
<a href="https://acrool-react-fetcher.pages.dev/" title="Acrool React Fetcher - This is a block function for React development loading block">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/acrool/acrool-react-fetcher/main/example/public/og.webp" alt="Acrool React Fetcher Logo"/>
|
|
5
|
+
</a>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
This is a toast message function for React development notifications
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<div align="center">
|
|
12
|
+
|
|
13
|
+
[](https://www.npmjs.com/package/@acrool/react-fetcher)
|
|
14
|
+
[](https://github.com/acrool/@acrool/react-fetcher/blob/main/LICENSE)
|
|
15
|
+
[](https://github.com/acrool/react-fetcher/blob/main/LICENSE)
|
|
16
|
+
|
|
17
|
+
[](https://www.npmjs.com/package/@acrool/react-fetcher)
|
|
18
|
+
[](https://www.npmjs.com/package/@acrool/react-fetcher)
|
|
19
|
+
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
`^1.1.0 support react >=18.0.0 <20.0.0`
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
- Supports queue block list
|
|
30
|
+
- Plug and unplug using `@acrool/react-portal` and `framer-motion`
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
yarn add @acrool/react-fetcher
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
add in your index.tsx
|
|
42
|
+
```tst
|
|
43
|
+
import "@acrool/react-fetcher/dist/index.css";
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
add in your App.tsx
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import {BlockPortal} from "@acrool/react-fetcher";
|
|
50
|
+
|
|
51
|
+
const App = () => {
|
|
52
|
+
return (
|
|
53
|
+
<div>
|
|
54
|
+
<BaseUsed/>
|
|
55
|
+
<BlockPortal
|
|
56
|
+
isVisibleQueueKey={false}
|
|
57
|
+
loader={<Loader/>}
|
|
58
|
+
defaultMessage="Loading..."
|
|
59
|
+
/>
|
|
60
|
+
</div>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
then in your page
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
import {block} from '@acrool/react-fetcher';
|
|
69
|
+
import {useEffect} from "react";
|
|
70
|
+
|
|
71
|
+
const Example = () => {
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
block.show();
|
|
75
|
+
|
|
76
|
+
setTimeout(() => {
|
|
77
|
+
block.hide();
|
|
78
|
+
}, 3000)
|
|
79
|
+
}, []);
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<div>
|
|
83
|
+
sample page
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- block.show
|
|
90
|
+
- block.hide
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
There is also a example that you can play with it:
|
|
94
|
+
|
|
95
|
+
[](https://acrool-react-fetcher.pages.dev)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
MIT © [Acrool](https://github.com/acrool) & [Imagine](https://github.com/imagine10255)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { TAuthTokensUpdater, TForceLogout, TGetTokens, TOnForceLogout, TOnGetTokens, TOnRefreshToken, TOnSetTokens, TRefreshToken } from './types';
|
|
3
|
+
interface AuthState {
|
|
4
|
+
lastUpdateTimestamp: number;
|
|
5
|
+
getTokens: TGetTokens;
|
|
6
|
+
updateTokens: TAuthTokensUpdater;
|
|
7
|
+
refreshTokens: TRefreshToken;
|
|
8
|
+
forceLogout: TForceLogout;
|
|
9
|
+
isAuth: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const useAuthState: () => AuthState;
|
|
12
|
+
interface AuthStateProviderProps {
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
onSetTokens: TOnSetTokens;
|
|
15
|
+
onGetTokens: TOnGetTokens;
|
|
16
|
+
onRefreshTokens: TOnRefreshToken;
|
|
17
|
+
onForceLogout: TOnForceLogout;
|
|
18
|
+
}
|
|
19
|
+
declare const AuthStateProvider: ({ children, onGetTokens, onSetTokens, onRefreshTokens, onForceLogout }: AuthStateProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export default AuthStateProvider;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface IAuthTokens {
|
|
2
|
+
accessToken?: string;
|
|
3
|
+
refreshToken?: string;
|
|
4
|
+
}
|
|
5
|
+
export type TAuthTokensUpdater = (tokensOrUpdater: IAuthTokens | null | ((curr: IAuthTokens | null) => IAuthTokens | null)) => void;
|
|
6
|
+
export type TOnRefreshToken = (refreshToken: string) => Promise<IAuthTokens | undefined>;
|
|
7
|
+
export type TRefreshToken = () => Promise<void>;
|
|
8
|
+
export type TOnForceLogout = () => void;
|
|
9
|
+
export type TForceLogout = () => void;
|
|
10
|
+
export type TOnSetTokens = TAuthTokensUpdater;
|
|
11
|
+
export type TOnGetTokens = () => IAuthTokens | null;
|
|
12
|
+
export type TGetTokens = () => IAuthTokens | null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface IResponse {
|
|
2
|
+
message: string;
|
|
3
|
+
code?: string | undefined;
|
|
4
|
+
args?: unknown;
|
|
5
|
+
path?: string;
|
|
6
|
+
}
|
|
7
|
+
export default class AxiosCancelException extends Error {
|
|
8
|
+
private readonly response;
|
|
9
|
+
readonly code: any;
|
|
10
|
+
readonly devInfo: any;
|
|
11
|
+
readonly args: any;
|
|
12
|
+
readonly path: any;
|
|
13
|
+
constructor(response: IResponse);
|
|
14
|
+
initName(): void;
|
|
15
|
+
getInfo(): IResponse;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AxiosInstance, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
import { IResponseFirstError } from './types';
|
|
4
|
+
export declare const AxiosClientContext: React.Context<AxiosInstance>;
|
|
5
|
+
export declare const useAxiosClient: () => AxiosInstance;
|
|
6
|
+
interface IProps {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
i18nDict?: Record<string, Record<number, string>>;
|
|
9
|
+
checkIsRefreshTokenRequest?: (config: InternalAxiosRequestConfig) => boolean;
|
|
10
|
+
getLocale: () => string;
|
|
11
|
+
onError?: (error: IResponseFirstError) => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Axios Client 提供者
|
|
15
|
+
* @param children
|
|
16
|
+
* @param authTokensManager
|
|
17
|
+
* @param getLocale
|
|
18
|
+
* @param onError
|
|
19
|
+
*/
|
|
20
|
+
declare const FetcherProvider: ({ children, getLocale, onError, i18nDict, checkIsRefreshTokenRequest, }: IProps) => import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export default FetcherProvider;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
+
export type TInterceptorRequest = (value: InternalAxiosRequestConfig<any>) => InternalAxiosRequestConfig<any> | Promise<InternalAxiosRequestConfig<any>>;
|
|
3
|
+
export type TInterceptorResponseSuccess = (value: AxiosResponse<any>) => AxiosResponse<any> | Promise<AxiosResponse<any>>;
|
|
4
|
+
export type TInterceptorResponseError = (error: AxiosError<any>) => AxiosResponse<any> | Promise<AxiosResponse<any>>;
|
|
5
|
+
export interface IResponseFirstError {
|
|
6
|
+
message: string;
|
|
7
|
+
code: string;
|
|
8
|
+
path?: string;
|
|
9
|
+
args?: any;
|
|
10
|
+
}
|