ag-common 0.0.241 → 0.0.244
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/KebabDots/index.js +1 -0
- package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.d.ts +2 -2
- package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.js +12 -23
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.d.ts +6 -0
- package/dist/ui/components/OpenApiCodeBlock/{helpers → curl/helpers}/body.js +3 -9
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.d.ts +2 -0
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.js +32 -0
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.d.ts +11 -0
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.js +30 -0
- package/dist/ui/components/OpenApiCodeBlock/curl/index.d.ts +6 -0
- package/dist/ui/components/OpenApiCodeBlock/curl/index.js +34 -0
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.d.ts +3 -0
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.js +23 -0
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.d.ts +2 -0
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.js +19 -0
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.d.ts +3 -0
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.js +77 -0
- package/dist/ui/components/OpenApiCodeBlock/fetch/index.d.ts +6 -0
- package/dist/ui/components/OpenApiCodeBlock/fetch/index.js +23 -0
- package/dist/ui/components/OpenApiCodeBlock/helpers/common.d.ts +12 -19
- package/dist/ui/components/OpenApiCodeBlock/helpers/common.js +40 -40
- package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.d.ts +4 -0
- package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.js +25 -0
- package/dist/ui/components/OpenApiCodeBlock/types.d.ts +27 -2
- package/package.json +5 -5
- package/dist/ui/components/OpenApiCodeBlock/helpers/body.d.ts +0 -6
- package/dist/ui/components/OpenApiCodeBlock/helpers/security.d.ts +0 -8
- package/dist/ui/components/OpenApiCodeBlock/helpers/security.js +0 -35
|
@@ -11,6 +11,7 @@ const Dots = (react_1.default.createElement("svg", { viewBox: "0 0 24 24", xmlns
|
|
|
11
11
|
react_1.default.createElement("path", { d: "M16 12a3.001 3.001 0 016 0 3.001 3.001 0 01-6 0zm1 0a2 2 0 114.001.001A2 2 0 0117 12zm-8 0a3.001 3.001 0 016 0 3.001 3.001 0 01-6 0zm1 0a2 2 0 114.001.001A2 2 0 0110 12zm-8 0a3.001 3.001 0 016 0 3.001 3.001 0 01-6 0zm1 0a2 2 0 114.001.001A2 2 0 013 12z" })));
|
|
12
12
|
const IconStyled = (0, styled_components_1.default)(Icon_1.Icon) `
|
|
13
13
|
position: absolute;
|
|
14
|
+
background-color: white;
|
|
14
15
|
`;
|
|
15
16
|
const KebabDots = ({ onClick }) => (react_1.default.createElement(IconStyled, { width: "2rem", height: "2rem", onClick: () => onClick === null || onClick === void 0 ? void 0 : onClick() }, Dots));
|
|
16
17
|
exports.KebabDots = KebabDots;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
export declare const OpenApiCodeBlock: <TDefaultApi>(p:
|
|
2
|
+
import { IOpenApiCodeBlock } from './types';
|
|
3
|
+
export declare const OpenApiCodeBlock: <TDefaultApi>(p: IOpenApiCodeBlock<TDefaultApi>) => JSX.Element;
|
|
@@ -5,13 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.OpenApiCodeBlock = void 0;
|
|
7
7
|
const common_1 = require("./helpers/common");
|
|
8
|
+
const curl_1 = require("./curl");
|
|
9
|
+
const fetch_1 = require("./fetch");
|
|
8
10
|
const FlexRow_1 = require("../FlexRow");
|
|
9
11
|
const react_1 = __importDefault(require("react"));
|
|
10
12
|
const styled_components_1 = __importDefault(require("styled-components"));
|
|
11
13
|
const Base = styled_components_1.default.div `
|
|
12
14
|
display: flex;
|
|
13
15
|
flex-flow: column;
|
|
14
|
-
width: 100
|
|
16
|
+
width: calc(100% - 4rem);
|
|
15
17
|
flex-grow: 1;
|
|
16
18
|
border: solid 1px #333;
|
|
17
19
|
margin: 1rem;
|
|
@@ -38,15 +40,13 @@ const Block = styled_components_1.default.div `
|
|
|
38
40
|
padding: 1rem;
|
|
39
41
|
margin-top: 0.5rem;
|
|
40
42
|
`;
|
|
41
|
-
const Curl = styled_components_1.default.div `
|
|
42
|
-
white-space: pre;
|
|
43
|
-
`;
|
|
44
43
|
const OpenApiCodeBlock = (p) => {
|
|
45
44
|
var _a;
|
|
46
|
-
const
|
|
47
|
-
if (error || !verb || !operation) {
|
|
48
|
-
return react_1.default.createElement(Base, null, error);
|
|
45
|
+
const ops = (0, common_1.getOperation)(p);
|
|
46
|
+
if (ops.error || !ops.verb || !ops.operation) {
|
|
47
|
+
return react_1.default.createElement(Base, null, ops.error);
|
|
49
48
|
}
|
|
49
|
+
const { verb, operation, path } = ops;
|
|
50
50
|
return (react_1.default.createElement(Base, null,
|
|
51
51
|
react_1.default.createElement(FlexRow_1.FlexRow, { center: true },
|
|
52
52
|
react_1.default.createElement(Verb, null, verb),
|
|
@@ -56,22 +56,11 @@ const OpenApiCodeBlock = (p) => {
|
|
|
56
56
|
verb.toUpperCase(),
|
|
57
57
|
" ",
|
|
58
58
|
path),
|
|
59
|
-
react_1.default.createElement(BlockTitle, null, "Example Request"),
|
|
59
|
+
react_1.default.createElement(BlockTitle, null, "Example curl Request"),
|
|
60
|
+
react_1.default.createElement(Block, null,
|
|
61
|
+
react_1.default.createElement(curl_1.Curl, { ops: ops, p: p })),
|
|
62
|
+
react_1.default.createElement(BlockTitle, null, "Example fetch Request"),
|
|
60
63
|
react_1.default.createElement(Block, null,
|
|
61
|
-
react_1.default.createElement(
|
|
62
|
-
"curl --request ",
|
|
63
|
-
verb.toUpperCase(),
|
|
64
|
-
"\u00A0\\",
|
|
65
|
-
react_1.default.createElement("br", null),
|
|
66
|
-
"--url ",
|
|
67
|
-
react_1.default.createElement(common_1.Highlight, null,
|
|
68
|
-
"'",
|
|
69
|
-
fullApiUrl,
|
|
70
|
-
"'"),
|
|
71
|
-
"\u00A0\\",
|
|
72
|
-
react_1.default.createElement("br", null),
|
|
73
|
-
react_1.default.createElement(react_1.default.Fragment, null, headerLines),
|
|
74
|
-
react_1.default.createElement("br", null),
|
|
75
|
-
bodyLine))));
|
|
64
|
+
react_1.default.createElement(fetch_1.Fetch, { ops: ops, p: p }))));
|
|
76
65
|
};
|
|
77
66
|
exports.OpenApiCodeBlock = OpenApiCodeBlock;
|
|
@@ -4,19 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getBody = void 0;
|
|
7
|
-
const common_1 = require("
|
|
8
|
-
const common_2 = require("../../../../common");
|
|
7
|
+
const common_1 = require("../../helpers/common");
|
|
9
8
|
const react_1 = __importDefault(require("react"));
|
|
10
9
|
const getBody = (p) => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const bend = !bstart ? undefined : body.lastIndexOf(')');
|
|
14
|
-
if (!bstart || !bend) {
|
|
10
|
+
const { nice } = (0, common_1.getBodyJson)(p) || {};
|
|
11
|
+
if (!nice) {
|
|
15
12
|
return { content: undefined, header: undefined };
|
|
16
13
|
}
|
|
17
|
-
const slice = body.substring(bstart + 1, bend);
|
|
18
|
-
const json = slice.replace(/([a-zA-Z0-9-]+[^"]):/gim, '"$1":');
|
|
19
|
-
const nice = JSON.stringify(JSON.parse(json), null, 2);
|
|
20
14
|
const content = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
21
15
|
"-d @- <<'EOF'",
|
|
22
16
|
react_1.default.createElement("br", null),
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCurlLines = void 0;
|
|
4
|
+
const body_1 = require("./body");
|
|
5
|
+
const security_1 = require("./security");
|
|
6
|
+
const getCurlLines = (ops, p) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const { operation, path, verb, fullApiUrl } = ops;
|
|
9
|
+
const withPath = fullApiUrl + path;
|
|
10
|
+
const secline = (0, security_1.getSecurityLine)(p, { operation });
|
|
11
|
+
if (secline.error) {
|
|
12
|
+
return { error: secline.error };
|
|
13
|
+
}
|
|
14
|
+
const bodyLines = (_a = (0, body_1.getBody)(p)) !== null && _a !== void 0 ? _a : undefined;
|
|
15
|
+
const headerLines = [];
|
|
16
|
+
if (secline.content) {
|
|
17
|
+
headerLines.push(secline.content);
|
|
18
|
+
}
|
|
19
|
+
if (bodyLines.header) {
|
|
20
|
+
headerLines.push(bodyLines.header);
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
verb,
|
|
24
|
+
path,
|
|
25
|
+
error: undefined,
|
|
26
|
+
headerLines: headerLines,
|
|
27
|
+
fullApiUrl: withPath,
|
|
28
|
+
bodyLine: bodyLines === null || bodyLines === void 0 ? void 0 : bodyLines.content,
|
|
29
|
+
operation,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
exports.getCurlLines = getCurlLines;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { IOpenApi, IOpenApiOperation } from '../../types';
|
|
3
|
+
export declare const getSecurityLine: (p: {
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
schema: IOpenApi;
|
|
6
|
+
}, { operation }: {
|
|
7
|
+
operation: IOpenApiOperation;
|
|
8
|
+
}) => {
|
|
9
|
+
error?: string;
|
|
10
|
+
content: JSX.Element | undefined;
|
|
11
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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.getSecurityLine = void 0;
|
|
7
|
+
const string_1 = require("../../../../../common/helpers/string");
|
|
8
|
+
const common_1 = require("../../helpers/common");
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
const getSecurityLine = (p, { operation }) => {
|
|
11
|
+
const sec = (0, common_1.getSecurity)(p, { operation });
|
|
12
|
+
if (sec === null) {
|
|
13
|
+
return { error: 'not supported sec in', content: undefined };
|
|
14
|
+
}
|
|
15
|
+
if (!sec) {
|
|
16
|
+
return { content: undefined };
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
content: (react_1.default.createElement(react_1.default.Fragment, null,
|
|
20
|
+
react_1.default.createElement("span", null, "--header "),
|
|
21
|
+
react_1.default.createElement(common_1.Highlight, null,
|
|
22
|
+
"'",
|
|
23
|
+
(0, string_1.toTitleCase)(sec.name),
|
|
24
|
+
":",
|
|
25
|
+
' ',
|
|
26
|
+
react_1.default.createElement(common_1.Highlight2, null, p.apiKey || '(API KEY)'),
|
|
27
|
+
"'"))),
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
exports.getSecurityLine = getSecurityLine;
|
|
@@ -0,0 +1,34 @@
|
|
|
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.Curl = void 0;
|
|
7
|
+
const getCurlLines_1 = require("./helpers/getCurlLines");
|
|
8
|
+
const common_1 = require("../helpers/common");
|
|
9
|
+
const common_2 = require("../../../../common");
|
|
10
|
+
const joinJsx_1 = require("../helpers/joinJsx");
|
|
11
|
+
const react_1 = __importDefault(require("react"));
|
|
12
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
13
|
+
const Base = styled_components_1.default.div `
|
|
14
|
+
white-space: pre;
|
|
15
|
+
`;
|
|
16
|
+
const Curl = ({ ops, p, }) => {
|
|
17
|
+
const { fullApiUrl, headerLines, bodyLine } = (0, getCurlLines_1.getCurlLines)(ops, p);
|
|
18
|
+
const { verb } = ops;
|
|
19
|
+
const rows = [
|
|
20
|
+
react_1.default.createElement(react_1.default.Fragment, null,
|
|
21
|
+
"curl --request ",
|
|
22
|
+
verb.toUpperCase()),
|
|
23
|
+
react_1.default.createElement(react_1.default.Fragment, null,
|
|
24
|
+
"--url ",
|
|
25
|
+
react_1.default.createElement(common_1.Highlight, null,
|
|
26
|
+
"'",
|
|
27
|
+
fullApiUrl,
|
|
28
|
+
"'")),
|
|
29
|
+
...(headerLines || []),
|
|
30
|
+
bodyLine,
|
|
31
|
+
].filter(common_2.notEmpty);
|
|
32
|
+
return react_1.default.createElement(Base, null, (0, joinJsx_1.joinJsxWithSlash)(rows));
|
|
33
|
+
};
|
|
34
|
+
exports.Curl = Curl;
|
|
@@ -0,0 +1,23 @@
|
|
|
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.getFetchCall = void 0;
|
|
7
|
+
const common_1 = require("../../helpers/common");
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
10
|
+
const rb = react_1.default.createElement(react_1.default.Fragment, null, "}");
|
|
11
|
+
const lb = react_1.default.createElement(react_1.default.Fragment, null, "{");
|
|
12
|
+
const Lpad = styled_components_1.default.div `
|
|
13
|
+
padding-left: 0.5rem;
|
|
14
|
+
`;
|
|
15
|
+
const getFetchCall = (p, ops) => {
|
|
16
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
17
|
+
react_1.default.createElement(common_1.Highlight, null, "const"),
|
|
18
|
+
"\u00A0response = ",
|
|
19
|
+
react_1.default.createElement(common_1.Highlight, null, "await"),
|
|
20
|
+
' ',
|
|
21
|
+
react_1.default.createElement(common_1.Highlight2, null, "fetch")));
|
|
22
|
+
};
|
|
23
|
+
exports.getFetchCall = getFetchCall;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFetchLines = void 0;
|
|
4
|
+
const req_1 = require("./req");
|
|
5
|
+
const getFetchLines = (ops, p) => {
|
|
6
|
+
var _a;
|
|
7
|
+
const { operation, path, verb, fullApiUrl } = ops;
|
|
8
|
+
const withPath = fullApiUrl + path;
|
|
9
|
+
const reqContent = (_a = (0, req_1.getRequestOptions)(p, ops)) !== null && _a !== void 0 ? _a : undefined;
|
|
10
|
+
return {
|
|
11
|
+
verb,
|
|
12
|
+
path,
|
|
13
|
+
error: undefined,
|
|
14
|
+
fullApiUrl: withPath,
|
|
15
|
+
reqContent,
|
|
16
|
+
operation,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
exports.getFetchLines = getFetchLines;
|
|
@@ -0,0 +1,77 @@
|
|
|
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.getRequestOptions = void 0;
|
|
7
|
+
const common_1 = require("../../helpers/common");
|
|
8
|
+
const joinJsx_1 = require("../../helpers/joinJsx");
|
|
9
|
+
const common_2 = require("../../../../../common");
|
|
10
|
+
const react_1 = __importDefault(require("react"));
|
|
11
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
12
|
+
const rb = react_1.default.createElement(react_1.default.Fragment, null, "}");
|
|
13
|
+
const lb = react_1.default.createElement(react_1.default.Fragment, null, "{");
|
|
14
|
+
const Lpad = styled_components_1.default.div `
|
|
15
|
+
padding-left: 0.5rem;
|
|
16
|
+
`;
|
|
17
|
+
const getRequestOptions = (p, ops) => {
|
|
18
|
+
const { nice } = (0, common_1.getBodyJson)(p) || {};
|
|
19
|
+
if (!nice) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const sec = (0, common_1.getSecurity)(p, ops);
|
|
23
|
+
const h1 = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
24
|
+
' ',
|
|
25
|
+
react_1.default.createElement(common_1.Highlight, null, "'Content-Type'"),
|
|
26
|
+
":",
|
|
27
|
+
' ',
|
|
28
|
+
react_1.default.createElement(common_1.Highlight, null, "'application/json'")));
|
|
29
|
+
let h2;
|
|
30
|
+
if (sec) {
|
|
31
|
+
h2 = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
32
|
+
' ',
|
|
33
|
+
react_1.default.createElement(common_1.Highlight, null,
|
|
34
|
+
"'",
|
|
35
|
+
(0, common_2.toTitleCase)(sec.name),
|
|
36
|
+
"'"),
|
|
37
|
+
":",
|
|
38
|
+
' ',
|
|
39
|
+
react_1.default.createElement(common_1.Highlight, null,
|
|
40
|
+
"'",
|
|
41
|
+
p.apiKey || '(API KEY)',
|
|
42
|
+
"'")));
|
|
43
|
+
}
|
|
44
|
+
const header = !sec ? (react_1.default.createElement(react_1.default.Fragment, null)) : (react_1.default.createElement(react_1.default.Fragment, null,
|
|
45
|
+
"headers: ",
|
|
46
|
+
lb,
|
|
47
|
+
react_1.default.createElement(Lpad, null, (0, joinJsx_1.joinJsxWithComma)([h1, h2])),
|
|
48
|
+
rb,
|
|
49
|
+
","));
|
|
50
|
+
const body = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
51
|
+
"body: ",
|
|
52
|
+
react_1.default.createElement(common_1.Highlight2, null, "JSON"),
|
|
53
|
+
".",
|
|
54
|
+
react_1.default.createElement(common_1.Highlight, null, "stringify"),
|
|
55
|
+
"(",
|
|
56
|
+
nice,
|
|
57
|
+
")"));
|
|
58
|
+
const content = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
59
|
+
"const requestOptions = ",
|
|
60
|
+
lb,
|
|
61
|
+
react_1.default.createElement(Lpad, null,
|
|
62
|
+
"method: ",
|
|
63
|
+
react_1.default.createElement(common_1.Highlight, null,
|
|
64
|
+
"'",
|
|
65
|
+
ops.verb.toUpperCase(),
|
|
66
|
+
"'"),
|
|
67
|
+
",",
|
|
68
|
+
react_1.default.createElement("br", null),
|
|
69
|
+
header,
|
|
70
|
+
react_1.default.createElement("br", null),
|
|
71
|
+
body,
|
|
72
|
+
react_1.default.createElement("br", null)),
|
|
73
|
+
rb,
|
|
74
|
+
";"));
|
|
75
|
+
return content;
|
|
76
|
+
};
|
|
77
|
+
exports.getRequestOptions = getRequestOptions;
|
|
@@ -0,0 +1,23 @@
|
|
|
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.Fetch = void 0;
|
|
7
|
+
const getFetchLines_1 = require("./helpers/getFetchLines");
|
|
8
|
+
const call_1 = require("./helpers/call");
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
11
|
+
const Base = styled_components_1.default.div `
|
|
12
|
+
white-space: pre;
|
|
13
|
+
`;
|
|
14
|
+
const Fetch = ({ ops, p, }) => {
|
|
15
|
+
const { reqContent } = (0, getFetchLines_1.getFetchLines)(ops, p);
|
|
16
|
+
const x = (0, call_1.getFetchCall)(p, ops);
|
|
17
|
+
return (react_1.default.createElement(Base, null,
|
|
18
|
+
reqContent,
|
|
19
|
+
react_1.default.createElement("br", null),
|
|
20
|
+
react_1.default.createElement("br", null),
|
|
21
|
+
x));
|
|
22
|
+
};
|
|
23
|
+
exports.Fetch = Fetch;
|
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import { ICodeBlock } from '../types';
|
|
1
|
+
import { IOpenApi, IOpenApiCodeBlock, IOpenApiOperation, IOpenApiOperationBlock } from '../types';
|
|
3
2
|
export declare const Highlight: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
4
3
|
export declare const Highlight2: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
5
|
-
export declare const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
error: undefined;
|
|
17
|
-
headerLines: JSX.Element[];
|
|
18
|
-
fullApiUrl: string;
|
|
19
|
-
bodyLine: JSX.Element | undefined;
|
|
20
|
-
operation: import("../types").IOpenApiOperation;
|
|
21
|
-
};
|
|
4
|
+
export declare const getOperation: <TDefaultApi>(p: IOpenApiCodeBlock<TDefaultApi>) => IOpenApiOperationBlock;
|
|
5
|
+
export declare const getBodyJson: <TDefaultApi>(p: IOpenApiCodeBlock<TDefaultApi>) => {
|
|
6
|
+
nice: string;
|
|
7
|
+
raw: string;
|
|
8
|
+
} | undefined;
|
|
9
|
+
export declare const getSecurity: (p: {
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
schema: IOpenApi;
|
|
12
|
+
}, { operation }: {
|
|
13
|
+
operation: IOpenApiOperation;
|
|
14
|
+
}) => import("../types").IOpenApiSecurityScheme | null | undefined;
|
|
@@ -3,12 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
8
|
-
const body_1 = require("./body");
|
|
9
|
-
const string_1 = require("../../../../common/helpers/string");
|
|
6
|
+
exports.getSecurity = exports.getBodyJson = exports.getOperation = exports.Highlight2 = exports.Highlight = void 0;
|
|
7
|
+
const common_1 = require("../../../../common");
|
|
10
8
|
const styled_components_1 = __importDefault(require("styled-components"));
|
|
11
|
-
const react_1 = __importDefault(require("react"));
|
|
12
9
|
exports.Highlight = styled_components_1.default.span `
|
|
13
10
|
color: green;
|
|
14
11
|
`;
|
|
@@ -21,7 +18,7 @@ const getApiUrl = (p) => {
|
|
|
21
18
|
const getFunctionName = (p) => {
|
|
22
19
|
let ret = p.funcF.toString();
|
|
23
20
|
const i1 = ret.indexOf('.') + 1;
|
|
24
|
-
const i2 = (0,
|
|
21
|
+
const i2 = (0, common_1.indexOfNumber)(ret, '(', 1);
|
|
25
22
|
ret = ret.substring(i1, i2);
|
|
26
23
|
return ret;
|
|
27
24
|
};
|
|
@@ -36,44 +33,47 @@ const getOperation = (p) => {
|
|
|
36
33
|
}
|
|
37
34
|
}));
|
|
38
35
|
if (!path || !verb) {
|
|
39
|
-
return {
|
|
36
|
+
return {
|
|
37
|
+
error: 'operation not found',
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
};
|
|
40
40
|
}
|
|
41
41
|
const operation = p.schema.paths[path][verb];
|
|
42
|
-
return { operation, verb, path };
|
|
42
|
+
return { operation, verb, path, fullApiUrl: getApiUrl(p) };
|
|
43
43
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const apiUrl = getApiUrl(p);
|
|
52
|
-
const fullApiUrl = apiUrl + path;
|
|
53
|
-
const secline = (0, security_1.getSecurityLine)(p, { operation });
|
|
54
|
-
if (secline.error) {
|
|
55
|
-
return { error: secline.error };
|
|
44
|
+
exports.getOperation = getOperation;
|
|
45
|
+
const getBodyJson = (p) => {
|
|
46
|
+
const body = p.funcF.toString();
|
|
47
|
+
const bstart = (0, common_1.indexOfNumber)(body, '(', 1);
|
|
48
|
+
const bend = !bstart ? undefined : body.lastIndexOf(')');
|
|
49
|
+
if (!bstart || !bend) {
|
|
50
|
+
return undefined;
|
|
56
51
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
headerLines.push(secline.content);
|
|
61
|
-
headerLines.push(react_1.default.createElement(react_1.default.Fragment, null,
|
|
62
|
-
"\u00A0\\",
|
|
63
|
-
react_1.default.createElement("br", null)));
|
|
52
|
+
//no body required
|
|
53
|
+
if (bend - bstart === 1) {
|
|
54
|
+
return undefined;
|
|
64
55
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
56
|
+
const raw = body.substring(bstart + 1, bend);
|
|
57
|
+
const cleaned = raw
|
|
58
|
+
.replace(/([a-zA-Z0-9-]+[^"]):/gim, '"$1":')
|
|
59
|
+
.replace(/'/gim, '"');
|
|
60
|
+
const nice = JSON.stringify(JSON.parse(cleaned), null, 2);
|
|
61
|
+
return { nice, raw };
|
|
62
|
+
};
|
|
63
|
+
exports.getBodyJson = getBodyJson;
|
|
64
|
+
const getSecurity = (p, { operation }) => {
|
|
65
|
+
var _a;
|
|
66
|
+
const security1 = (_a = operation.security) === null || _a === void 0 ? void 0 : _a[0];
|
|
67
|
+
const security2 = !security1 ? undefined : Object.keys(security1)[0];
|
|
68
|
+
const security = !security2
|
|
69
|
+
? undefined
|
|
70
|
+
: p.schema.components.securitySchemes[security2];
|
|
71
|
+
if (security) {
|
|
72
|
+
if (security.in !== 'header') {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return security;
|
|
68
76
|
}
|
|
69
|
-
return
|
|
70
|
-
verb,
|
|
71
|
-
path,
|
|
72
|
-
error: undefined,
|
|
73
|
-
headerLines,
|
|
74
|
-
fullApiUrl,
|
|
75
|
-
bodyLine: bodyLines === null || bodyLines === void 0 ? void 0 : bodyLines.content,
|
|
76
|
-
operation,
|
|
77
|
-
};
|
|
77
|
+
return undefined;
|
|
78
78
|
};
|
|
79
|
-
exports.
|
|
79
|
+
exports.getSecurity = getSecurity;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="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[];
|
|
@@ -0,0 +1,25 @@
|
|
|
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 common_1 = require("../../../../common");
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const joinJsx = (items, sep) => {
|
|
10
|
+
const ret = [];
|
|
11
|
+
items.filter(common_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,9 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
export interface IOpenApiOperation {
|
|
2
3
|
description: string;
|
|
3
4
|
operationId: string;
|
|
4
5
|
security?: {
|
|
5
6
|
[name: string]: string;
|
|
6
|
-
};
|
|
7
|
+
}[];
|
|
7
8
|
}
|
|
8
9
|
export interface IOpenApiSecurityScheme {
|
|
9
10
|
in: string;
|
|
@@ -24,7 +25,7 @@ export interface IOpenApi {
|
|
|
24
25
|
};
|
|
25
26
|
};
|
|
26
27
|
}
|
|
27
|
-
export interface
|
|
28
|
+
export interface IOpenApiCodeBlock<TDefaultApi> {
|
|
28
29
|
/**
|
|
29
30
|
* openapi schema. eg
|
|
30
31
|
* const schema: any = require('common/openapi.generated').default;
|
|
@@ -33,3 +34,27 @@ export interface ICodeBlock<TDefaultApi> {
|
|
|
33
34
|
apiKey?: string;
|
|
34
35
|
funcF: (f: TDefaultApi) => Promise<any>;
|
|
35
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.244",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"typescript": "4.x"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@babel/core": "7.17.
|
|
33
|
+
"@babel/core": "7.17.10",
|
|
34
34
|
"@storybook/addon-actions": "6.4.22",
|
|
35
35
|
"@storybook/addon-docs": "6.4.22",
|
|
36
36
|
"@storybook/addon-essentials": "6.4.22",
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"@storybook/react": "6.4.22",
|
|
41
41
|
"@storybook/theming": "6.4.22",
|
|
42
42
|
"@types/jsonwebtoken": "8.5.8",
|
|
43
|
-
"@types/node": "17.0.
|
|
43
|
+
"@types/node": "17.0.31",
|
|
44
44
|
"@types/react": "17.0.43",
|
|
45
45
|
"@types/react-dom": "17.0.14",
|
|
46
46
|
"@types/styled-components": "5.1.25",
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
48
|
-
"@typescript-eslint/parser": "5.
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "5.22.0",
|
|
48
|
+
"@typescript-eslint/parser": "5.22.0",
|
|
49
49
|
"cross-env": "7.0.3",
|
|
50
50
|
"eslint": "8.14.0",
|
|
51
51
|
"eslint-config-airbnb-typescript": "17.0.0",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { ICodeBlock, IOpenApiOperation } from '../types';
|
|
3
|
-
export declare const getSecurityLine: <TDefaultApi>(p: ICodeBlock<TDefaultApi>, { operation }: {
|
|
4
|
-
operation: IOpenApiOperation;
|
|
5
|
-
}) => {
|
|
6
|
-
error?: string;
|
|
7
|
-
content: JSX.Element;
|
|
8
|
-
};
|
|
@@ -1,35 +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.getSecurityLine = void 0;
|
|
7
|
-
const common_1 = require("./common");
|
|
8
|
-
const string_1 = require("../../../../common/helpers/string");
|
|
9
|
-
const react_1 = __importDefault(require("react"));
|
|
10
|
-
const getSecurityLine = (p, { operation }) => {
|
|
11
|
-
var _a;
|
|
12
|
-
const security1 = (_a = operation.security) === null || _a === void 0 ? void 0 : _a[0];
|
|
13
|
-
const security2 = !security1 ? undefined : Object.keys(security1)[0];
|
|
14
|
-
const security = !security2
|
|
15
|
-
? undefined
|
|
16
|
-
: p.schema.components.securitySchemes[security2];
|
|
17
|
-
if (security) {
|
|
18
|
-
if (security.in !== 'header') {
|
|
19
|
-
return { error: 'not supported sec in', content: react_1.default.createElement(react_1.default.Fragment, null) };
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
content: (react_1.default.createElement(react_1.default.Fragment, null,
|
|
23
|
-
react_1.default.createElement("span", null, "--header "),
|
|
24
|
-
react_1.default.createElement(common_1.Highlight, null,
|
|
25
|
-
"'",
|
|
26
|
-
(0, string_1.toTitleCase)(security.name),
|
|
27
|
-
":",
|
|
28
|
-
' ',
|
|
29
|
-
react_1.default.createElement(common_1.Highlight2, null, p.apiKey || '(API KEY)'),
|
|
30
|
-
"'"))),
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
return { content: react_1.default.createElement(react_1.default.Fragment, null) };
|
|
34
|
-
};
|
|
35
|
-
exports.getSecurityLine = getSecurityLine;
|