ag-common 0.0.762 → 0.0.764
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/api/helpers/apigw.d.ts +1 -1
- package/dist/api/helpers/apigw.js +6 -8
- package/dist/api/helpers/index.d.ts +0 -2
- package/dist/api/helpers/index.js +0 -2
- package/dist/api/types/index.d.ts +0 -32
- package/dist/ui/components/index.d.ts +0 -1
- package/dist/ui/components/index.js +0 -1
- package/dist/ui/helpers/dom.js +2 -0
- package/dist/ui/helpers/index.d.ts +0 -2
- package/dist/ui/helpers/index.js +0 -2
- package/dist/ui/helpers/jwt.d.ts +0 -12
- package/dist/ui/helpers/routes.d.ts +0 -18
- package/dist/ui/helpers/useContextMenu.js +3 -0
- package/dist/ui/helpers/useIsInViewport.js +1 -0
- package/dist/ui/helpers/useOnScroll.js +2 -3
- package/package.json +24 -32
- package/dist/api/helpers/openApiHelpers.d.ts +0 -43
- package/dist/api/helpers/openApiHelpers.js +0 -163
- package/dist/api/helpers/validateOpenApi.d.ts +0 -25
- package/dist/api/helpers/validateOpenApi.js +0 -127
- package/dist/api/openapi-postfix.d.ts +0 -1
- package/dist/api/openapi-postfix.js +0 -42
- package/dist/api/openapi-prefix.d.ts +0 -1
- package/dist/api/openapi-prefix.js +0 -88
- package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.d.ts +0 -3
- package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.js +0 -69
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.d.ts +0 -6
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.js +0 -30
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.d.ts +0 -2
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.js +0 -31
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.d.ts +0 -11
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.js +0 -28
- package/dist/ui/components/OpenApiCodeBlock/curl/index.d.ts +0 -6
- package/dist/ui/components/OpenApiCodeBlock/curl/index.js +0 -35
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.d.ts +0 -3
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.js +0 -23
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.d.ts +0 -2
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.js +0 -19
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.d.ts +0 -3
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.js +0 -78
- package/dist/ui/components/OpenApiCodeBlock/fetch/index.d.ts +0 -6
- package/dist/ui/components/OpenApiCodeBlock/fetch/index.js +0 -24
- package/dist/ui/components/OpenApiCodeBlock/helpers/common.d.ts +0 -20
- package/dist/ui/components/OpenApiCodeBlock/helpers/common.js +0 -89
- package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.d.ts +0 -4
- package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.js +0 -25
- package/dist/ui/components/OpenApiCodeBlock/index.d.ts +0 -2
- package/dist/ui/components/OpenApiCodeBlock/index.js +0 -17
- package/dist/ui/components/OpenApiCodeBlock/types.d.ts +0 -60
- package/dist/ui/components/OpenApiCodeBlock/types.js +0 -2
- package/dist/ui/helpers/axiosHelper.d.ts +0 -17
- package/dist/ui/helpers/axiosHelper.js +0 -92
- package/dist/ui/helpers/callOpenApi/cached.d.ts +0 -34
- package/dist/ui/helpers/callOpenApi/cached.js +0 -92
- package/dist/ui/helpers/callOpenApi/direct.d.ts +0 -9
- package/dist/ui/helpers/callOpenApi/direct.js +0 -137
- package/dist/ui/helpers/callOpenApi/helpers.d.ts +0 -9
- package/dist/ui/helpers/callOpenApi/helpers.js +0 -60
- package/dist/ui/helpers/callOpenApi/hook.d.ts +0 -27
- package/dist/ui/helpers/callOpenApi/hook.js +0 -82
- package/dist/ui/helpers/callOpenApi/index.d.ts +0 -5
- package/dist/ui/helpers/callOpenApi/index.js +0 -20
- package/dist/ui/helpers/callOpenApi/types.d.ts +0 -19
- package/dist/ui/helpers/callOpenApi/types.js +0 -2
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
'use client';
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.Fetch = void 0;
|
|
8
|
-
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
9
|
-
const react_1 = __importDefault(require("react"));
|
|
10
|
-
const call_1 = require("./helpers/call");
|
|
11
|
-
const getFetchLines_1 = require("./helpers/getFetchLines");
|
|
12
|
-
const Base = styled_1.default.div `
|
|
13
|
-
white-space: pre;
|
|
14
|
-
`;
|
|
15
|
-
const Fetch = ({ ops, p, }) => {
|
|
16
|
-
const { reqContent } = (0, getFetchLines_1.getFetchLines)(ops, p);
|
|
17
|
-
const x = (0, call_1.getFetchCall)(p, ops);
|
|
18
|
-
return (react_1.default.createElement(Base, null,
|
|
19
|
-
reqContent,
|
|
20
|
-
react_1.default.createElement("br", null),
|
|
21
|
-
react_1.default.createElement("br", null),
|
|
22
|
-
x));
|
|
23
|
-
};
|
|
24
|
-
exports.Fetch = Fetch;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { IOpenApi, IOpenApiCodeBlock, IOpenApiOperation, IOpenApiOperationBlock } from '../types';
|
|
2
|
-
export declare const Highlight: import("@emotion/styled").StyledComponent<{
|
|
3
|
-
theme?: import("@emotion/react").Theme;
|
|
4
|
-
as?: React.ElementType;
|
|
5
|
-
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, {}>;
|
|
6
|
-
export declare const Highlight2: import("@emotion/styled").StyledComponent<{
|
|
7
|
-
theme?: import("@emotion/react").Theme;
|
|
8
|
-
as?: React.ElementType;
|
|
9
|
-
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, {}>;
|
|
10
|
-
export declare const getOperation: <TDefaultApi>(p: IOpenApiCodeBlock<TDefaultApi>) => IOpenApiOperationBlock;
|
|
11
|
-
export declare const getBodyJson: <TDefaultApi>(p: IOpenApiCodeBlock<TDefaultApi>) => {
|
|
12
|
-
nice: string;
|
|
13
|
-
raw: string;
|
|
14
|
-
} | undefined;
|
|
15
|
-
export declare const getSecurity: (p: {
|
|
16
|
-
apiKey?: string;
|
|
17
|
-
schema: IOpenApi;
|
|
18
|
-
}, { operation }: {
|
|
19
|
-
operation: IOpenApiOperation;
|
|
20
|
-
}) => import("../types").IOpenApiSecurityScheme | null | undefined;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
'use client';
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.getSecurity = exports.getBodyJson = exports.getOperation = exports.Highlight2 = exports.Highlight = void 0;
|
|
8
|
-
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
9
|
-
exports.Highlight = styled_1.default.span `
|
|
10
|
-
color: green;
|
|
11
|
-
`;
|
|
12
|
-
exports.Highlight2 = styled_1.default.span `
|
|
13
|
-
color: indianred;
|
|
14
|
-
`;
|
|
15
|
-
const indexOfNumber = (str, char, num = 0) => {
|
|
16
|
-
let ret = -1;
|
|
17
|
-
for (let c = 0; c <= num; c += 1) {
|
|
18
|
-
ret = str.indexOf(char, ret + 1);
|
|
19
|
-
}
|
|
20
|
-
if (ret === -1) {
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
return ret;
|
|
24
|
-
};
|
|
25
|
-
const getApiUrl = (p) => {
|
|
26
|
-
return p.schema.servers[0].url;
|
|
27
|
-
};
|
|
28
|
-
const getFunctionName = (p) => {
|
|
29
|
-
let ret = p.funcF.toString();
|
|
30
|
-
const i1 = ret.indexOf('.') + 1;
|
|
31
|
-
const i2 = ret.indexOf('(', i1);
|
|
32
|
-
ret = ret.substring(i1, i2);
|
|
33
|
-
return ret;
|
|
34
|
-
};
|
|
35
|
-
const getOperation = (p) => {
|
|
36
|
-
let path;
|
|
37
|
-
let verb;
|
|
38
|
-
const func = getFunctionName(p);
|
|
39
|
-
Object.entries(p.schema.paths).forEach(([pathN, ops]) => Object.entries(ops).forEach(([verbN, op]) => {
|
|
40
|
-
//openapi codegen gives raw fn, match that as well
|
|
41
|
-
if (op.operationId === func || op.operationId + 'Raw' === func) {
|
|
42
|
-
path = pathN;
|
|
43
|
-
verb = verbN;
|
|
44
|
-
}
|
|
45
|
-
}));
|
|
46
|
-
if (!path || !verb) {
|
|
47
|
-
return {
|
|
48
|
-
error: 'operation not found',
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
const operation = p.schema.paths[path][verb];
|
|
52
|
-
return { operation, verb, path, fullApiUrl: getApiUrl(p) };
|
|
53
|
-
};
|
|
54
|
-
exports.getOperation = getOperation;
|
|
55
|
-
const getBodyJson = (p) => {
|
|
56
|
-
const body = p.funcF.toString();
|
|
57
|
-
const bstart = indexOfNumber(body, '(', 1);
|
|
58
|
-
const bend = !bstart ? undefined : body.lastIndexOf(')');
|
|
59
|
-
if (!bstart || !bend) {
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
//no body required
|
|
63
|
-
if (bend - bstart === 1) {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
const raw = body.substring(bstart + 1, bend);
|
|
67
|
-
const cleaned = raw
|
|
68
|
-
.replace(/([a-zA-Z0-9-]+[^"]):/gim, '"$1":')
|
|
69
|
-
.replace(/'/gim, '"');
|
|
70
|
-
const nice = JSON.stringify(JSON.parse(cleaned), null, 2);
|
|
71
|
-
return { nice, raw };
|
|
72
|
-
};
|
|
73
|
-
exports.getBodyJson = getBodyJson;
|
|
74
|
-
const getSecurity = (p, { operation }) => {
|
|
75
|
-
var _a;
|
|
76
|
-
const security1 = (_a = operation.security) === null || _a === void 0 ? void 0 : _a[0];
|
|
77
|
-
const security2 = !security1 ? undefined : Object.keys(security1)[0];
|
|
78
|
-
const security = !security2
|
|
79
|
-
? undefined
|
|
80
|
-
: p.schema.components.securitySchemes[security2];
|
|
81
|
-
if (security) {
|
|
82
|
-
if (security.in !== 'header') {
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
return security;
|
|
86
|
-
}
|
|
87
|
-
return undefined;
|
|
88
|
-
};
|
|
89
|
-
exports.getSecurity = getSecurity;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { JSX } from 'react';
|
|
2
|
-
export declare const joinJsx: (items: (JSX.Element | undefined)[], sep: JSX.Element[]) => JSX.Element[];
|
|
3
|
-
export declare const joinJsxWithSlash: (items: (JSX.Element | undefined)[]) => JSX.Element[];
|
|
4
|
-
export declare const joinJsxWithComma: (items: (JSX.Element | undefined)[]) => JSX.Element[];
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.joinJsxWithComma = exports.joinJsxWithSlash = exports.joinJsx = void 0;
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const array_1 = require("../../../../common/helpers/array");
|
|
9
|
-
const joinJsx = (items, sep) => {
|
|
10
|
-
const ret = [];
|
|
11
|
-
items.filter(array_1.notEmpty).forEach((i, index) => {
|
|
12
|
-
ret.push(i);
|
|
13
|
-
if (index !== items.length - 1) {
|
|
14
|
-
for (const s of sep) {
|
|
15
|
-
ret.push(s);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return ret;
|
|
20
|
-
};
|
|
21
|
-
exports.joinJsx = joinJsx;
|
|
22
|
-
const joinJsxWithSlash = (items) => (0, exports.joinJsx)(items, [react_1.default.createElement(react_1.default.Fragment, null, "\u00A0\\"), react_1.default.createElement("br", { key: "br1" })]);
|
|
23
|
-
exports.joinJsxWithSlash = joinJsxWithSlash;
|
|
24
|
-
const joinJsxWithComma = (items) => (0, exports.joinJsx)(items, [react_1.default.createElement(react_1.default.Fragment, null, ","), react_1.default.createElement("br", { key: "br1" })]);
|
|
25
|
-
exports.joinJsxWithComma = joinJsxWithComma;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./OpenApiCodeBlock"), exports);
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { JSX } from 'react';
|
|
2
|
-
export interface IOpenApiOperation {
|
|
3
|
-
description?: string;
|
|
4
|
-
operationId: string;
|
|
5
|
-
security?: {
|
|
6
|
-
[name: string]: string;
|
|
7
|
-
}[];
|
|
8
|
-
}
|
|
9
|
-
export interface IOpenApiSecurityScheme {
|
|
10
|
-
in: string;
|
|
11
|
-
name: string;
|
|
12
|
-
}
|
|
13
|
-
export interface IOpenApi {
|
|
14
|
-
paths: {
|
|
15
|
-
[pathname: string]: {
|
|
16
|
-
[verb: string]: IOpenApiOperation;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
servers: {
|
|
20
|
-
url: string;
|
|
21
|
-
}[];
|
|
22
|
-
components: {
|
|
23
|
-
securitySchemes: {
|
|
24
|
-
[name: string]: IOpenApiSecurityScheme;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
export interface IOpenApiCodeBlock<TDefaultApi> {
|
|
29
|
-
/**
|
|
30
|
-
* openapi schema. eg
|
|
31
|
-
* const schema: any = require('common/openapi.generated').default;
|
|
32
|
-
*/
|
|
33
|
-
schema: IOpenApi;
|
|
34
|
-
apiKey?: string;
|
|
35
|
-
funcF: (f: TDefaultApi) => Promise<any>;
|
|
36
|
-
}
|
|
37
|
-
export interface ICurlLines {
|
|
38
|
-
error?: string;
|
|
39
|
-
verb?: string;
|
|
40
|
-
path?: string;
|
|
41
|
-
headerLines?: JSX.Element[];
|
|
42
|
-
fullApiUrl?: string;
|
|
43
|
-
bodyLine?: JSX.Element;
|
|
44
|
-
operation?: IOpenApiOperation;
|
|
45
|
-
}
|
|
46
|
-
export interface IFetchLines {
|
|
47
|
-
error?: string;
|
|
48
|
-
verb?: string;
|
|
49
|
-
path?: string;
|
|
50
|
-
fullApiUrl?: string;
|
|
51
|
-
reqContent?: JSX.Element;
|
|
52
|
-
operation?: IOpenApiOperation;
|
|
53
|
-
}
|
|
54
|
-
export interface IOpenApiOperationBlock {
|
|
55
|
-
error?: string;
|
|
56
|
-
operation: IOpenApiOperation;
|
|
57
|
-
verb: string;
|
|
58
|
-
path: string;
|
|
59
|
-
fullApiUrl: string;
|
|
60
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { AxiosResponse } from 'axios';
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param body accepts object or json, and passes as-is
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
|
-
export declare const axiosHelper: <TOut>({ verb, url, body, headers, timeout, retryMax, onStaleAuth, }: {
|
|
8
|
-
headers?: {
|
|
9
|
-
[a: string]: string;
|
|
10
|
-
};
|
|
11
|
-
verb: "put" | "post" | "get" | "patch" | "delete";
|
|
12
|
-
url: string;
|
|
13
|
-
body?: unknown;
|
|
14
|
-
timeout?: number;
|
|
15
|
-
retryMax?: number;
|
|
16
|
-
onStaleAuth?: () => void;
|
|
17
|
-
}) => Promise<AxiosResponse<TOut>>;
|
|
@@ -1,92 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.axiosHelper = void 0;
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
17
|
-
const const_1 = require("../../common/const");
|
|
18
|
-
const log_1 = require("../../common/helpers/log");
|
|
19
|
-
const object_1 = require("../../common/helpers/object");
|
|
20
|
-
const sleep_1 = require("../../common/helpers/sleep");
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
|
-
* @param body accepts object or json, and passes as-is
|
|
24
|
-
* @returns
|
|
25
|
-
*/
|
|
26
|
-
const axiosHelper = (_a) => __awaiter(void 0, [_a], void 0, function* ({ verb, url, body, headers, timeout = 30000, retryMax = 0, onStaleAuth, }) {
|
|
27
|
-
var _b;
|
|
28
|
-
let retry = 0;
|
|
29
|
-
let ret;
|
|
30
|
-
do {
|
|
31
|
-
try {
|
|
32
|
-
const setHeaders = Object.assign({ Accept: 'application/json' }, headers);
|
|
33
|
-
if (verb === 'get') {
|
|
34
|
-
ret = yield axios_1.default.get(url, {
|
|
35
|
-
headers: setHeaders,
|
|
36
|
-
timeout,
|
|
37
|
-
timeoutErrorMessage: `${url} timeout`,
|
|
38
|
-
});
|
|
39
|
-
return ret;
|
|
40
|
-
}
|
|
41
|
-
let noBody = false;
|
|
42
|
-
let axiosV = axios_1.default.post;
|
|
43
|
-
if (verb === 'put') {
|
|
44
|
-
axiosV = axios_1.default.put;
|
|
45
|
-
}
|
|
46
|
-
else if (verb === 'post') {
|
|
47
|
-
axiosV = axios_1.default.post;
|
|
48
|
-
}
|
|
49
|
-
else if (verb === 'patch') {
|
|
50
|
-
axiosV = axios_1.default.patch;
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
52
|
-
}
|
|
53
|
-
else if (verb === 'delete') {
|
|
54
|
-
axiosV = axios_1.default.delete;
|
|
55
|
-
noBody = true;
|
|
56
|
-
}
|
|
57
|
-
if (noBody) {
|
|
58
|
-
ret = yield axiosV(url, {
|
|
59
|
-
headers: setHeaders,
|
|
60
|
-
timeout,
|
|
61
|
-
timeoutErrorMessage: `${url} timeout`,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
if (body && (0, object_1.isJson)(body)) {
|
|
66
|
-
setHeaders['Content-Type'] =
|
|
67
|
-
setHeaders['Content-Type'] || 'application/json';
|
|
68
|
-
}
|
|
69
|
-
ret = yield axiosV(url, body, { headers: setHeaders });
|
|
70
|
-
}
|
|
71
|
-
return ret;
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
const em = e;
|
|
75
|
-
const c = Number((_b = em.code) !== null && _b !== void 0 ? _b : '500');
|
|
76
|
-
// jwt expired or bad response
|
|
77
|
-
// 403 returned for old token - will be refreshed
|
|
78
|
-
if (c === 401 || c === 403) {
|
|
79
|
-
(0, log_1.debug)('auth expired');
|
|
80
|
-
onStaleAuth === null || onStaleAuth === void 0 ? void 0 : onStaleAuth();
|
|
81
|
-
retry = retryMax;
|
|
82
|
-
}
|
|
83
|
-
if (!const_1.retryHttpCodes.includes(c) || retry >= retryMax) {
|
|
84
|
-
throw em;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
retry += 1;
|
|
88
|
-
yield (0, sleep_1.sleep)(const_1.retryHttpMs);
|
|
89
|
-
} while (retry <= retryMax);
|
|
90
|
-
throw new Error('unexpected');
|
|
91
|
-
});
|
|
92
|
-
exports.axiosHelper = axiosHelper;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { AxiosWrapperLite } from '../jwt';
|
|
2
|
-
import type { CacheItems } from '../routes';
|
|
3
|
-
import type { ICallOpenApi, OverrideAuth } from './types';
|
|
4
|
-
export type TCallOpenApiCached<T, TDefaultApi> = ICallOpenApi<T, TDefaultApi> & {
|
|
5
|
-
/**
|
|
6
|
-
* if falsey, will run callOpenApi directly
|
|
7
|
-
*/
|
|
8
|
-
cacheKey: string;
|
|
9
|
-
/**
|
|
10
|
-
* will shortcut and return the appropriate axioswrapper data if cachekey is found
|
|
11
|
-
*/
|
|
12
|
-
ssrCacheItems?: CacheItems;
|
|
13
|
-
/**
|
|
14
|
-
* default ttl in seconds for cache - default 120s
|
|
15
|
-
*/
|
|
16
|
-
cacheTtl?: number;
|
|
17
|
-
/**
|
|
18
|
-
* (ssr) if true, wont run callopenapi if data is not cached
|
|
19
|
-
*/
|
|
20
|
-
onlyCached?: boolean;
|
|
21
|
-
};
|
|
22
|
-
export declare const setOpenApiCacheRaw: <T>(p: {
|
|
23
|
-
cacheKey: string;
|
|
24
|
-
overrideAuth?: OverrideAuth | undefined;
|
|
25
|
-
ssrCacheItems?: any;
|
|
26
|
-
cacheTtl?: number;
|
|
27
|
-
}, data: T) => Promise<void>;
|
|
28
|
-
/**
|
|
29
|
-
* sync call to callOpenApiCache.
|
|
30
|
-
* @param p
|
|
31
|
-
* @returns undefined if no cache item
|
|
32
|
-
*/
|
|
33
|
-
export declare const callOpenApiCachedRaw: <T, TDefaultApi>(p: TCallOpenApiCached<T, TDefaultApi>) => AxiosWrapperLite<T> | undefined;
|
|
34
|
-
export declare const callOpenApiCached: <T, TDefaultApi>(p: TCallOpenApiCached<T, TDefaultApi>) => Promise<AxiosWrapperLite<T | undefined>>;
|
|
@@ -1,92 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.callOpenApiCached = exports.callOpenApiCachedRaw = exports.setOpenApiCacheRaw = void 0;
|
|
16
|
-
const node_cache_1 = __importDefault(require("node-cache"));
|
|
17
|
-
const hashCode_1 = require("../../../common/helpers/hashCode");
|
|
18
|
-
const base64_1 = require("../../../common/helpers/string/base64");
|
|
19
|
-
const direct_1 = require("./direct");
|
|
20
|
-
let callOpenApiCache;
|
|
21
|
-
/**
|
|
22
|
-
* cache differs per user and per SSR provided data
|
|
23
|
-
* @param param0
|
|
24
|
-
* @returns
|
|
25
|
-
*/
|
|
26
|
-
function getCacheKey({ cacheKey, overrideAuth, ssrCacheItems, }) {
|
|
27
|
-
const authkeyPrefix1 = (0, direct_1.getIdTokenAuthHeaderRaw)({
|
|
28
|
-
overrideAuth,
|
|
29
|
-
});
|
|
30
|
-
const authPref = !authkeyPrefix1 ? '' : (0, hashCode_1.hashCode)((0, base64_1.toBase64)(authkeyPrefix1));
|
|
31
|
-
const ssrCachePref = !ssrCacheItems
|
|
32
|
-
? ''
|
|
33
|
-
: (0, hashCode_1.hashCode)((0, base64_1.toBase64)(JSON.stringify(ssrCacheItems)));
|
|
34
|
-
let cacheKeyRet;
|
|
35
|
-
if (cacheKey) {
|
|
36
|
-
cacheKeyRet = `${cacheKey}||${authPref}||${ssrCachePref}`;
|
|
37
|
-
}
|
|
38
|
-
return cacheKeyRet;
|
|
39
|
-
}
|
|
40
|
-
const setOpenApiCacheRaw = (p, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
-
var _a;
|
|
42
|
-
const userPrefixedCacheKey = getCacheKey(p);
|
|
43
|
-
if (!userPrefixedCacheKey) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
if (!callOpenApiCache) {
|
|
47
|
-
callOpenApiCache = new node_cache_1.default({ stdTTL: (_a = p.cacheTtl) !== null && _a !== void 0 ? _a : 120 });
|
|
48
|
-
}
|
|
49
|
-
callOpenApiCache.set(userPrefixedCacheKey, data);
|
|
50
|
-
});
|
|
51
|
-
exports.setOpenApiCacheRaw = setOpenApiCacheRaw;
|
|
52
|
-
/**
|
|
53
|
-
* sync call to callOpenApiCache.
|
|
54
|
-
* @param p
|
|
55
|
-
* @returns undefined if no cache item
|
|
56
|
-
*/
|
|
57
|
-
const callOpenApiCachedRaw = (p) => {
|
|
58
|
-
var _a, _b, _c, _d;
|
|
59
|
-
const userPrefixedCacheKey = getCacheKey(p);
|
|
60
|
-
if (!userPrefixedCacheKey) {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
if (!callOpenApiCache) {
|
|
64
|
-
callOpenApiCache = new node_cache_1.default({ stdTTL: (_a = p.cacheTtl) !== null && _a !== void 0 ? _a : 120 });
|
|
65
|
-
}
|
|
66
|
-
//get ssr cache value
|
|
67
|
-
const ssrCached = (_c = (_b = p.ssrCacheItems) === null || _b === void 0 ? void 0 : _b.find((s) => s.cacheKey === p.cacheKey)) === null || _c === void 0 ? void 0 : _c.prefillData.data;
|
|
68
|
-
//if we have ssr cache and there is no existing cache then set
|
|
69
|
-
if (!callOpenApiCache.get(userPrefixedCacheKey) && ssrCached) {
|
|
70
|
-
callOpenApiCache.set(userPrefixedCacheKey, ssrCached);
|
|
71
|
-
}
|
|
72
|
-
//return cached data, or ssr data if that has already expired (ttl <=0)
|
|
73
|
-
const data = (_d = callOpenApiCache.get(userPrefixedCacheKey)) !== null && _d !== void 0 ? _d : ssrCached;
|
|
74
|
-
if (!data) {
|
|
75
|
-
return undefined;
|
|
76
|
-
}
|
|
77
|
-
return { data };
|
|
78
|
-
};
|
|
79
|
-
exports.callOpenApiCachedRaw = callOpenApiCachedRaw;
|
|
80
|
-
const callOpenApiCached = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
-
const raw = (0, exports.callOpenApiCachedRaw)(p);
|
|
82
|
-
if (raw) {
|
|
83
|
-
return raw;
|
|
84
|
-
}
|
|
85
|
-
const resp = yield (0, direct_1.callOpenApi)(p);
|
|
86
|
-
if (resp.error) {
|
|
87
|
-
return { error: resp.error, data: undefined };
|
|
88
|
-
}
|
|
89
|
-
yield (0, exports.setOpenApiCacheRaw)(p, resp.data);
|
|
90
|
-
return resp;
|
|
91
|
-
});
|
|
92
|
-
exports.callOpenApiCached = callOpenApiCached;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { AxiosWrapperLite } from '../jwt';
|
|
2
|
-
import type { ICallOpenApi, OverrideAuth } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* get the id_token from provided value, or cookie, or LS
|
|
5
|
-
*/
|
|
6
|
-
export declare function getIdTokenAuthHeaderRaw({ overrideAuth, }: {
|
|
7
|
-
overrideAuth?: OverrideAuth;
|
|
8
|
-
}): string;
|
|
9
|
-
export declare const callOpenApi: <T, TDefaultApi>(p: ICallOpenApi<T, TDefaultApi>) => Promise<AxiosWrapperLite<T>>;
|
|
@@ -1,137 +0,0 @@
|
|
|
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.callOpenApi = void 0;
|
|
13
|
-
exports.getIdTokenAuthHeaderRaw = getIdTokenAuthHeaderRaw;
|
|
14
|
-
const const_1 = require("../../../common/const");
|
|
15
|
-
const array_1 = require("../../../common/helpers/array");
|
|
16
|
-
const log_1 = require("../../../common/helpers/log");
|
|
17
|
-
const sleep_1 = require("../../../common/helpers/sleep");
|
|
18
|
-
const cookie_1 = require("../cookie");
|
|
19
|
-
const useLocalStorage_1 = require("../useLocalStorage");
|
|
20
|
-
/**
|
|
21
|
-
* get the id_token from provided value, or cookie, or LS
|
|
22
|
-
*/
|
|
23
|
-
function getIdTokenAuthHeaderRaw({ overrideAuth, }) {
|
|
24
|
-
var _a;
|
|
25
|
-
let idToken;
|
|
26
|
-
//if override supplied will only use that and not refresh
|
|
27
|
-
if (overrideAuth === null || overrideAuth === void 0 ? void 0 : overrideAuth.id_token) {
|
|
28
|
-
idToken = overrideAuth.id_token;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
idToken = (0, cookie_1.getCookieString)({
|
|
32
|
-
name: 'id_token',
|
|
33
|
-
defaultValue: '',
|
|
34
|
-
});
|
|
35
|
-
if (!idToken) {
|
|
36
|
-
const userLs = (0, useLocalStorage_1.getLocalStorageItem)('user', undefined);
|
|
37
|
-
if ((_a = userLs === null || userLs === void 0 ? void 0 : userLs.jwt) === null || _a === void 0 ? void 0 : _a.id_token) {
|
|
38
|
-
idToken = userLs.jwt.id_token;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return idToken;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* get id_token, and then refresh
|
|
46
|
-
*/
|
|
47
|
-
function getIdTokenAuthHeader(_a) {
|
|
48
|
-
return __awaiter(this, arguments, void 0, function* ({ overrideAuth, refreshToken, }) {
|
|
49
|
-
var _b;
|
|
50
|
-
let idToken = getIdTokenAuthHeaderRaw({ overrideAuth });
|
|
51
|
-
//if we have a cookie token, can try to refresh
|
|
52
|
-
if (idToken) {
|
|
53
|
-
const updated = yield refreshToken();
|
|
54
|
-
if ((_b = updated === null || updated === void 0 ? void 0 : updated.jwt) === null || _b === void 0 ? void 0 : _b.id_token) {
|
|
55
|
-
idToken = updated.jwt.id_token;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return idToken;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
const callOpenApi = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
63
|
-
const { func, apiUrl, logout, newDefaultApi, headers } = p;
|
|
64
|
-
let error;
|
|
65
|
-
let data = undefined;
|
|
66
|
-
const config = {
|
|
67
|
-
basePath: apiUrl,
|
|
68
|
-
baseOptions: { headers: headers !== null && headers !== void 0 ? headers : {} },
|
|
69
|
-
middleware: [],
|
|
70
|
-
};
|
|
71
|
-
//comes from either id_token cookie OR auth override param
|
|
72
|
-
const idToken = yield getIdTokenAuthHeader(p);
|
|
73
|
-
if (headers === null || headers === void 0 ? void 0 : headers.authorization) {
|
|
74
|
-
config.baseOptions.headers.authorization = headers.authorization.toString();
|
|
75
|
-
}
|
|
76
|
-
else if ((headers === null || headers === void 0 ? void 0 : headers.authorization) === undefined && idToken) {
|
|
77
|
-
config.baseOptions.headers.authorization = `Bearer ${idToken}`;
|
|
78
|
-
}
|
|
79
|
-
if (config.baseOptions.headers.authorization) {
|
|
80
|
-
config.middleware = [
|
|
81
|
-
{
|
|
82
|
-
pre: (oldFetchParams) => {
|
|
83
|
-
var _a, _b, _c;
|
|
84
|
-
const url = (_a = oldFetchParams === null || oldFetchParams === void 0 ? void 0 : oldFetchParams.url) !== null && _a !== void 0 ? _a : '(url)';
|
|
85
|
-
const verb = (_c = (_b = oldFetchParams === null || oldFetchParams === void 0 ? void 0 : oldFetchParams.init) === null || _b === void 0 ? void 0 : _b.method) !== null && _c !== void 0 ? _c : '(verb)';
|
|
86
|
-
(0, log_1.debug)(`callOpenApi: making ${verb} call to ${url}`);
|
|
87
|
-
oldFetchParams.init.headers = Object.assign({ authorization: config.baseOptions.headers.authorization }, oldFetchParams.init.headers);
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
];
|
|
91
|
-
}
|
|
92
|
-
const cl = newDefaultApi(config);
|
|
93
|
-
let errorCount = 0;
|
|
94
|
-
const errorMax = 3;
|
|
95
|
-
while (errorCount <= errorMax) {
|
|
96
|
-
errorCount += 1;
|
|
97
|
-
try {
|
|
98
|
-
const response = yield func(cl);
|
|
99
|
-
if (response.status < 400) {
|
|
100
|
-
data = response.data;
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
throw { response };
|
|
104
|
-
}
|
|
105
|
-
catch (e) {
|
|
106
|
-
const ae = e;
|
|
107
|
-
const status = Number((_c = (_a = ae.code) !== null && _a !== void 0 ? _a : (_b = ae.response) === null || _b === void 0 ? void 0 : _b.status) !== null && _c !== void 0 ? _c : 500);
|
|
108
|
-
const errorMessage = [
|
|
109
|
-
(_d = ae.status) !== null && _d !== void 0 ? _d : '',
|
|
110
|
-
(_g = (_f = (_e = ae.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.toString()) !== null && _g !== void 0 ? _g : '',
|
|
111
|
-
(_j = (_h = ae.response) === null || _h === void 0 ? void 0 : _h.statusText.toString()) !== null && _j !== void 0 ? _j : '',
|
|
112
|
-
(_l = (_k = ae.response) === null || _k === void 0 ? void 0 : _k.status.toString()) !== null && _l !== void 0 ? _l : '',
|
|
113
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
114
|
-
(_o = (_m = ae.message) === null || _m === void 0 ? void 0 : _m.toString()) !== null && _o !== void 0 ? _o : '',
|
|
115
|
-
]
|
|
116
|
-
.filter(array_1.notEmpty)
|
|
117
|
-
.sort((a, b) => (a.length < b.length ? -1 : 1))
|
|
118
|
-
.join('\n');
|
|
119
|
-
//if auth fail, then quick exit
|
|
120
|
-
if (status === 403 || status === 401) {
|
|
121
|
-
logout();
|
|
122
|
-
return {
|
|
123
|
-
error: ae,
|
|
124
|
-
data: undefined,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
//if not a potential retriable error, or have retried enough, then exit
|
|
128
|
-
if (!const_1.retryHttpCodes.includes(status) || errorCount === errorMax) {
|
|
129
|
-
error = Object.assign(Object.assign({}, ae), { message: errorMessage });
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
yield (0, sleep_1.sleep)(const_1.retryHttpMs);
|
|
134
|
-
}
|
|
135
|
-
return Object.assign({ data }, (error && { error }));
|
|
136
|
-
});
|
|
137
|
-
exports.callOpenApi = callOpenApi;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { AxiosResponse } from 'axios';
|
|
2
|
-
import type { ApiResponse } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* shim to convert raw response to an axios style response.
|
|
5
|
-
* must convert all DefaultClass requests to the Raw equivalent
|
|
6
|
-
* @param p
|
|
7
|
-
* @returns
|
|
8
|
-
*/
|
|
9
|
-
export declare const apiResponseToAxiosResponse: <T>(p: () => Promise<ApiResponse<T>>) => Promise<AxiosResponse<T>>;
|