ag-common 0.0.111 → 0.0.115
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/dist/ui/components/Confirm/index.d.ts +1 -1
- package/dist/ui/helpers/callOpenApi.d.ts +1 -1
- package/dist/ui/helpers/callOpenApi.js +1 -1
- package/dist/ui/helpers/useCallOpenApi.d.ts +8 -1
- package/dist/ui/helpers/useCallOpenApi.js +15 -15
- package/dist/ui/helpers/useOpenApiStore.d.ts +3 -11
- package/package.json +3 -3
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { AxiosWrapper } from './jwt';
|
|
2
2
|
import { ICallOpenApi } from './types';
|
|
3
|
-
export declare const callOpenApi: <T, TDefaultApi>({ func, apiUrl, overrideAuth, refreshToken, logout, newDefaultApi, }: ICallOpenApi<T, TDefaultApi>) => Promise<AxiosWrapper<T
|
|
3
|
+
export declare const callOpenApi: <T, TDefaultApi>({ func, apiUrl, overrideAuth, refreshToken, logout, newDefaultApi, }: ICallOpenApi<T, TDefaultApi>) => Promise<AxiosWrapper<T>>;
|
|
@@ -17,7 +17,7 @@ const callOpenApi = ({ func, apiUrl, overrideAuth, refreshToken, logout, newDefa
|
|
|
17
17
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
18
18
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
19
|
let error;
|
|
20
|
-
let data;
|
|
20
|
+
let data = undefined;
|
|
21
21
|
const config = {
|
|
22
22
|
basePath: apiUrl,
|
|
23
23
|
baseOptions: { headers: { authorization: '' } },
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { AxiosWrapper } from './jwt';
|
|
2
2
|
import { ICallOpenApi } from './types';
|
|
3
|
+
import { CacheItems } from './routes';
|
|
3
4
|
declare type AxiosWrapperWrap<T> = AxiosWrapper<T | undefined> & {
|
|
4
5
|
loaded: boolean;
|
|
5
6
|
loadcount: number;
|
|
6
7
|
};
|
|
7
|
-
export declare const useCallOpenApi: <T, TDefaultApi>(p: ICallOpenApi<T, TDefaultApi>
|
|
8
|
+
export declare const useCallOpenApi: <T, TDefaultApi>(p: ICallOpenApi<T, TDefaultApi> & {
|
|
9
|
+
cacheKey: string;
|
|
10
|
+
/**
|
|
11
|
+
* will shortcut and return the appropriate axioswrapper data if cachekey is found
|
|
12
|
+
*/
|
|
13
|
+
ssrCacheItems?: CacheItems | undefined;
|
|
14
|
+
}) => AxiosWrapperWrap<T>;
|
|
8
15
|
export {};
|
|
@@ -12,20 +12,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.useCallOpenApi = void 0;
|
|
13
13
|
const react_1 = require("react");
|
|
14
14
|
const callOpenApi_1 = require("./callOpenApi");
|
|
15
|
-
const defaultV = (def) => ({
|
|
16
|
-
loading: false,
|
|
17
|
-
data: def,
|
|
18
|
-
datetime: new Date().getTime(),
|
|
19
|
-
reFetch: () => __awaiter(void 0, void 0, void 0, function* () { }),
|
|
20
|
-
error: undefined,
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
-
url: undefined,
|
|
23
|
-
//
|
|
24
|
-
loaded: false,
|
|
25
|
-
loadcount: 0,
|
|
26
|
-
});
|
|
27
15
|
const useCallOpenApi = (p) => {
|
|
28
|
-
|
|
16
|
+
var _a, _b;
|
|
17
|
+
const ssrCached = (_a = p.ssrCacheItems) === null || _a === void 0 ? void 0 : _a.find((s) => s.cacheKey === p.cacheKey);
|
|
18
|
+
const defv = {
|
|
19
|
+
data: undefined,
|
|
20
|
+
url: '',
|
|
21
|
+
datetime: 0,
|
|
22
|
+
loadcount: 0,
|
|
23
|
+
loading: false,
|
|
24
|
+
loaded: false,
|
|
25
|
+
reFetch: () => __awaiter(void 0, void 0, void 0, function* () { }),
|
|
26
|
+
};
|
|
27
|
+
const [data, setData] = (0, react_1.useState)(Object.assign(Object.assign({}, defv), { data: ssrCached ? (_b = ssrCached.prefillData) === null || _b === void 0 ? void 0 : _b.data : undefined, loaded: !!ssrCached }));
|
|
29
28
|
(0, react_1.useEffect)(() => {
|
|
30
29
|
function run() {
|
|
31
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -34,14 +33,15 @@ const useCallOpenApi = (p) => {
|
|
|
34
33
|
});
|
|
35
34
|
}
|
|
36
35
|
const { error, loaded, loading, loadcount } = data;
|
|
37
|
-
|
|
36
|
+
const ng = p.disabled || loaded || loading || (error && loadcount > 2);
|
|
37
|
+
if (ng) {
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
setData((d) => (Object.assign(Object.assign({}, d), { loading: true })));
|
|
41
41
|
void run();
|
|
42
42
|
}, [data, p, setData]);
|
|
43
43
|
return Object.assign(Object.assign({}, data), { reFetch: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
-
setData(
|
|
44
|
+
setData(defv);
|
|
45
45
|
}) });
|
|
46
46
|
};
|
|
47
47
|
exports.useCallOpenApi = useCallOpenApi;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { AxiosResponse } from 'axios';
|
|
2
1
|
import { CacheItems } from './routes';
|
|
3
|
-
import { AxiosWrapper
|
|
4
|
-
import {
|
|
2
|
+
import { AxiosWrapper } from './jwt';
|
|
3
|
+
import { ICallOpenApi } from './types';
|
|
5
4
|
export declare const deleteMutexData: (key: string) => void;
|
|
6
5
|
export declare const setMutexData: ({ key, data, ttlSeconds, }: {
|
|
7
6
|
key: string;
|
|
@@ -14,16 +13,9 @@ export declare const getMutexData: <T>(key: string) => AxiosWrapper<T>;
|
|
|
14
13
|
* @param overrideAuth - auth automatically picked up from id_token cookie, can override value here, but not required
|
|
15
14
|
* @returns
|
|
16
15
|
*/
|
|
17
|
-
export declare const useOpenApiStore: <T, TDefaultApi>(p: {
|
|
16
|
+
export declare const useOpenApiStore: <T, TDefaultApi>(p: ICallOpenApi<T, TDefaultApi> & {
|
|
18
17
|
ttlSeconds?: number | undefined;
|
|
19
|
-
func: (f: TDefaultApi) => Promise<AxiosResponse<T, any>>;
|
|
20
18
|
cacheKey: string;
|
|
21
|
-
logout: () => void;
|
|
22
|
-
refreshToken: () => Promise<User | undefined>;
|
|
23
|
-
disabled?: boolean | undefined;
|
|
24
|
-
apiUrl: string;
|
|
25
|
-
newDefaultApi: (config: any) => TDefaultApi;
|
|
26
|
-
overrideAuth?: OverrideAuth | undefined;
|
|
27
19
|
/**
|
|
28
20
|
* will shortcut and return the appropriate axioswrapper data if cachekey is found
|
|
29
21
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.115",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"start": "tsc --watch"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"aws-sdk": "2.
|
|
16
|
+
"aws-sdk": "2.1066.0",
|
|
17
17
|
"axios": "0.25.0",
|
|
18
18
|
"jsonwebtoken": "8.5.1",
|
|
19
19
|
"jwks-rsa": "2.0.5",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/jsonwebtoken": "8.5.8",
|
|
31
|
-
"@types/node": "17.0.
|
|
31
|
+
"@types/node": "17.0.13",
|
|
32
32
|
"@types/react": "17.0.38",
|
|
33
33
|
"@types/react-dom": "17.0.11",
|
|
34
34
|
"@types/styled-components": "5.1.21",
|