ag-common 0.0.80 → 0.0.83
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/helpers/callOpenApi.d.ts +3 -13
- package/dist/ui/helpers/callOpenApi.js +1 -0
- package/dist/ui/helpers/index.d.ts +2 -0
- package/dist/ui/helpers/index.js +2 -0
- package/dist/ui/helpers/types.d.ts +13 -0
- package/dist/ui/helpers/types.js +2 -0
- package/dist/ui/helpers/useCallOpenApi.d.ts +10 -0
- package/dist/ui/helpers/useCallOpenApi.js +47 -0
- package/dist/ui/helpers/useOpenApiStore.d.ts +1 -1
- package/dist/ui/helpers/useOpenApiStore.js +10 -13
- package/package.json +4 -4
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
id_token?: string;
|
|
5
|
-
}
|
|
6
|
-
export declare const callOpenApi: <T, TDefaultApi>({ func, apiUrl, overrideAuth, refreshToken, logout, newDefaultApi, }: {
|
|
7
|
-
func: (f: TDefaultApi) => Promise<AxiosResponse<T, any>>;
|
|
8
|
-
apiUrl: string;
|
|
9
|
-
overrideAuth?: OverrideAuth | undefined;
|
|
10
|
-
logout: () => void;
|
|
11
|
-
refreshToken: () => Promise<User | undefined>;
|
|
12
|
-
newDefaultApi: (config: any) => TDefaultApi;
|
|
13
|
-
}) => Promise<AxiosWrapper<T | undefined>>;
|
|
1
|
+
import { AxiosWrapper } from './jwt';
|
|
2
|
+
import { ICallOpenApi } from './types';
|
|
3
|
+
export declare const callOpenApi: <T, TDefaultApi>({ func, apiUrl, overrideAuth, refreshToken, logout, newDefaultApi, }: ICallOpenApi<T, TDefaultApi>) => Promise<AxiosWrapper<T | undefined>>;
|
|
@@ -51,6 +51,7 @@ const callOpenApi = ({ func, apiUrl, overrideAuth, refreshToken, logout, newDefa
|
|
|
51
51
|
const ae = e;
|
|
52
52
|
const status = (_c = ae.response) === null || _c === void 0 ? void 0 : _c.status;
|
|
53
53
|
const errorMessage = [
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
55
|
(_f = (_e = (_d = ae.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.toString()) !== null && _f !== void 0 ? _f : '',
|
|
55
56
|
(_j = (_h = (_g = ae.response) === null || _g === void 0 ? void 0 : _g.statusText) === null || _h === void 0 ? void 0 : _h.toString()) !== null && _j !== void 0 ? _j : '',
|
|
56
57
|
(_m = (_l = (_k = ae.response) === null || _k === void 0 ? void 0 : _k.status) === null || _l === void 0 ? void 0 : _l.toString()) !== null && _m !== void 0 ? _m : '',
|
|
@@ -13,6 +13,8 @@ export * from './mutex';
|
|
|
13
13
|
export * from './mutexData';
|
|
14
14
|
export * from './plural';
|
|
15
15
|
export * from './routes';
|
|
16
|
+
export * from './types';
|
|
17
|
+
export * from './useCallOpenApi';
|
|
16
18
|
export * from './useContextMenu';
|
|
17
19
|
export * from './useLocalStorage';
|
|
18
20
|
export * from './useLockBodyScroll';
|
package/dist/ui/helpers/index.js
CHANGED
|
@@ -25,6 +25,8 @@ __exportStar(require("./mutex"), exports);
|
|
|
25
25
|
__exportStar(require("./mutexData"), exports);
|
|
26
26
|
__exportStar(require("./plural"), exports);
|
|
27
27
|
__exportStar(require("./routes"), exports);
|
|
28
|
+
__exportStar(require("./types"), exports);
|
|
29
|
+
__exportStar(require("./useCallOpenApi"), exports);
|
|
28
30
|
__exportStar(require("./useContextMenu"), exports);
|
|
29
31
|
__exportStar(require("./useLocalStorage"), exports);
|
|
30
32
|
__exportStar(require("./useLockBodyScroll"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { User } from './jwt';
|
|
3
|
+
export interface OverrideAuth {
|
|
4
|
+
id_token?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ICallOpenApi<T, TDefaultApi> {
|
|
7
|
+
func: (f: TDefaultApi) => Promise<AxiosResponse<T>>;
|
|
8
|
+
apiUrl: string;
|
|
9
|
+
overrideAuth?: OverrideAuth;
|
|
10
|
+
logout: () => void;
|
|
11
|
+
refreshToken: () => Promise<User | undefined>;
|
|
12
|
+
newDefaultApi: (config: any) => TDefaultApi;
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AxiosWrapper } from './jwt';
|
|
2
|
+
import { ICallOpenApi } from './types';
|
|
3
|
+
declare type AxiosWrapperWrap<T> = AxiosWrapper<T | undefined> & {
|
|
4
|
+
loaded: boolean;
|
|
5
|
+
loadcount: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const useCallOpenApi: <T, TDefaultApi>(p: ICallOpenApi<T, TDefaultApi> & {
|
|
8
|
+
cacheKey: string;
|
|
9
|
+
}) => AxiosWrapperWrap<T>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.useCallOpenApi = void 0;
|
|
13
|
+
const react_1 = require("react");
|
|
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
|
+
const useCallOpenApi = (p) => {
|
|
28
|
+
const [data, setData] = (0, react_1.useState)(defaultV(undefined));
|
|
29
|
+
(0, react_1.useEffect)(() => {
|
|
30
|
+
function run() {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const res = yield (0, callOpenApi_1.callOpenApi)(p);
|
|
33
|
+
setData((d) => (Object.assign(Object.assign({}, res), { loaded: true, loading: false, loadcount: d.loadcount + 1 })));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const { error, loaded, loading, loadcount } = data;
|
|
37
|
+
if (loaded || loading || (error && loadcount < 2)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
setData((d) => (Object.assign(Object.assign({}, d), { loading: true })));
|
|
41
|
+
void run();
|
|
42
|
+
}, [data, p, setData]);
|
|
43
|
+
return Object.assign(Object.assign({}, data), { reFetch: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
setData(defaultV(undefined));
|
|
45
|
+
}) });
|
|
46
|
+
};
|
|
47
|
+
exports.useCallOpenApi = useCallOpenApi;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
|
-
import { OverrideAuth } from './callOpenApi';
|
|
3
2
|
import { CacheItems } from './routes';
|
|
4
3
|
import { AxiosWrapper, User } from './jwt';
|
|
4
|
+
import { OverrideAuth } from './types';
|
|
5
5
|
export declare const deleteMutexData: (key: string) => void;
|
|
6
6
|
export declare const setMutexData: ({ key, data, ttlSeconds, }: {
|
|
7
7
|
key: string;
|
|
@@ -42,22 +42,15 @@ exports.setMutexData = setMutexData;
|
|
|
42
42
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
43
|
const getMutexData = (key) => mutexData.getData(key);
|
|
44
44
|
exports.getMutexData = getMutexData;
|
|
45
|
-
function mLock(
|
|
45
|
+
function mLock(p) {
|
|
46
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
47
|
let unlock;
|
|
48
48
|
try {
|
|
49
|
-
unlock = yield mutex.capture(key);
|
|
50
|
-
if (mutexData.getData(key)) {
|
|
49
|
+
unlock = yield mutex.capture(p.key);
|
|
50
|
+
if (mutexData.getData(p.key)) {
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
|
-
const newData = yield (0, callOpenApi_1.callOpenApi)(
|
|
54
|
-
apiUrl,
|
|
55
|
-
func,
|
|
56
|
-
logout,
|
|
57
|
-
refreshToken,
|
|
58
|
-
newDefaultApi,
|
|
59
|
-
overrideAuth,
|
|
60
|
-
});
|
|
53
|
+
const newData = yield (0, callOpenApi_1.callOpenApi)(p);
|
|
61
54
|
if (!newData) {
|
|
62
55
|
return;
|
|
63
56
|
}
|
|
@@ -65,9 +58,13 @@ function mLock({ key, func, ttlSeconds = 3600, logout, refreshToken, apiUrl, new
|
|
|
65
58
|
(0, log_1.error)('api error:', newData.error);
|
|
66
59
|
}
|
|
67
60
|
else {
|
|
68
|
-
mutexData.setData({
|
|
61
|
+
mutexData.setData({
|
|
62
|
+
key: p.key,
|
|
63
|
+
data: newData,
|
|
64
|
+
ttlSeconds: p.ttlSeconds,
|
|
65
|
+
});
|
|
69
66
|
}
|
|
70
|
-
mutexData.pingSubscribers(key);
|
|
67
|
+
mutexData.pingSubscribers(p.key);
|
|
71
68
|
}
|
|
72
69
|
catch (e) {
|
|
73
70
|
(0, log_1.error)('mutex error:', e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.83",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
@@ -13,10 +13,8 @@
|
|
|
13
13
|
"start": "tsc --watch"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"aws-cdk-lib": "2.8.0",
|
|
17
16
|
"aws-sdk": "2.1060.0",
|
|
18
17
|
"axios": "0.25.0",
|
|
19
|
-
"constructs": "10.0.39",
|
|
20
18
|
"jsonwebtoken": "8.5.1",
|
|
21
19
|
"jwks-rsa": "2.0.5",
|
|
22
20
|
"openapi-request-validator": "10.0.0",
|
|
@@ -24,7 +22,9 @@
|
|
|
24
22
|
"react-dom": "17.0.2",
|
|
25
23
|
"react-hot-toast": "2.2.0",
|
|
26
24
|
"styled-components": "5.3.3",
|
|
27
|
-
"typescript": "4.5.5"
|
|
25
|
+
"typescript": "4.5.5",
|
|
26
|
+
"aws-cdk-lib": "2.x",
|
|
27
|
+
"constructs": "10.x"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/jsonwebtoken": "8.5.8",
|