ag-common 0.0.240 → 0.0.243

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.
Files changed (37) hide show
  1. package/dist/ui/components/KebabDots/index.js +1 -0
  2. package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.d.ts +3 -0
  3. package/dist/ui/components/{CodeBlock/CodeBlock.js → OpenApiCodeBlock/OpenApiCodeBlock.js} +15 -26
  4. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.d.ts +6 -0
  5. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.js +29 -0
  6. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.d.ts +2 -0
  7. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.js +32 -0
  8. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.d.ts +11 -0
  9. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.js +30 -0
  10. package/dist/ui/components/OpenApiCodeBlock/curl/index.d.ts +6 -0
  11. package/dist/ui/components/OpenApiCodeBlock/curl/index.js +34 -0
  12. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.d.ts +3 -0
  13. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.js +23 -0
  14. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.d.ts +2 -0
  15. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.js +19 -0
  16. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.d.ts +3 -0
  17. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.js +77 -0
  18. package/dist/ui/components/OpenApiCodeBlock/fetch/index.d.ts +6 -0
  19. package/dist/ui/components/OpenApiCodeBlock/fetch/index.js +23 -0
  20. package/dist/ui/components/OpenApiCodeBlock/helpers/common.d.ts +14 -0
  21. package/dist/ui/components/OpenApiCodeBlock/helpers/common.js +79 -0
  22. package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.d.ts +4 -0
  23. package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.js +25 -0
  24. package/dist/ui/components/OpenApiCodeBlock/index.d.ts +2 -0
  25. package/dist/ui/components/{CodeBlock → OpenApiCodeBlock}/index.js +1 -1
  26. package/dist/ui/components/OpenApiCodeBlock/types.d.ts +60 -0
  27. package/dist/ui/components/{CodeBlock → OpenApiCodeBlock}/types.js +0 -0
  28. package/dist/ui/components/index.d.ts +1 -1
  29. package/dist/ui/components/index.js +1 -1
  30. package/package.json +1 -1
  31. package/dist/ui/components/CodeBlock/CodeBlock.d.ts +0 -3
  32. package/dist/ui/components/CodeBlock/helpers/common.d.ts +0 -21
  33. package/dist/ui/components/CodeBlock/helpers/common.js +0 -107
  34. package/dist/ui/components/CodeBlock/helpers/security.d.ts +0 -8
  35. package/dist/ui/components/CodeBlock/helpers/security.js +0 -37
  36. package/dist/ui/components/CodeBlock/index.d.ts +0 -2
  37. package/dist/ui/components/CodeBlock/types.d.ts +0 -9
@@ -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;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { IOpenApiCodeBlock } from './types';
3
+ export declare const OpenApiCodeBlock: <TDefaultApi>(p: IOpenApiCodeBlock<TDefaultApi>) => JSX.Element;
@@ -3,15 +3,17 @@ 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.CodeBlock = void 0;
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
- const CodeBlock = (p) => {
43
+ const OpenApiCodeBlock = (p) => {
45
44
  var _a;
46
- const { path, verb, error, headerLines, fullApiUrl, bodyLine, operation } = (0, common_1.getLines)(p);
47
- if (error || !verb) {
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 CodeBlock = (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(Curl, null,
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
- exports.CodeBlock = CodeBlock;
66
+ exports.OpenApiCodeBlock = OpenApiCodeBlock;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { IOpenApiCodeBlock } from '../../types';
3
+ export declare const getBody: <TDefaultApi>(p: IOpenApiCodeBlock<TDefaultApi>) => {
4
+ content: JSX.Element | undefined;
5
+ header: JSX.Element | undefined;
6
+ };
@@ -0,0 +1,29 @@
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.getBody = void 0;
7
+ const common_1 = require("../../helpers/common");
8
+ const react_1 = __importDefault(require("react"));
9
+ const getBody = (p) => {
10
+ const { nice } = (0, common_1.getBodyJson)(p) || {};
11
+ if (!nice) {
12
+ return { content: undefined, header: undefined };
13
+ }
14
+ const content = (react_1.default.createElement(react_1.default.Fragment, null,
15
+ "-d @- <<'EOF'",
16
+ react_1.default.createElement("br", null),
17
+ react_1.default.createElement(common_1.Highlight2, null, nice),
18
+ react_1.default.createElement("br", null),
19
+ "EOF"));
20
+ const header = (react_1.default.createElement(react_1.default.Fragment, null,
21
+ react_1.default.createElement("span", null, "--header "),
22
+ react_1.default.createElement(common_1.Highlight, null,
23
+ react_1.default.createElement(common_1.Highlight, null, "'Content-Type: application/json'"))));
24
+ return {
25
+ content,
26
+ header,
27
+ };
28
+ };
29
+ exports.getBody = getBody;
@@ -0,0 +1,2 @@
1
+ import { ICurlLines, IOpenApiCodeBlock, IOpenApiOperationBlock } from '../../types';
2
+ export declare const getCurlLines: <TDefaultApi>(ops: IOpenApiOperationBlock, p: IOpenApiCodeBlock<TDefaultApi>) => ICurlLines;
@@ -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,6 @@
1
+ /// <reference types="react" />
2
+ import { IOpenApiCodeBlock, IOpenApiOperationBlock } from '../types';
3
+ export declare const Curl: <TDefaultApi>({ ops, p, }: {
4
+ p: IOpenApiCodeBlock<TDefaultApi>;
5
+ ops: IOpenApiOperationBlock;
6
+ }) => JSX.Element;
@@ -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,3 @@
1
+ /// <reference types="react" />
2
+ import { IOpenApiCodeBlock, IOpenApiOperationBlock } from '../../types';
3
+ export declare const getFetchCall: <TDefaultApi>(p: IOpenApiCodeBlock<TDefaultApi>, ops: IOpenApiOperationBlock) => JSX.Element | undefined;
@@ -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,2 @@
1
+ import { IFetchLines, IOpenApiCodeBlock, IOpenApiOperationBlock } from '../../types';
2
+ export declare const getFetchLines: <TDefaultApi>(ops: IOpenApiOperationBlock, p: IOpenApiCodeBlock<TDefaultApi>) => IFetchLines;
@@ -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,3 @@
1
+ /// <reference types="react" />
2
+ import { IOpenApiCodeBlock, IOpenApiOperationBlock } from '../../types';
3
+ export declare const getRequestOptions: <TDefaultApi>(p: IOpenApiCodeBlock<TDefaultApi>, ops: IOpenApiOperationBlock) => JSX.Element | undefined;
@@ -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,6 @@
1
+ /// <reference types="react" />
2
+ import { IOpenApiCodeBlock, IOpenApiOperationBlock } from '../types';
3
+ export declare const Fetch: <TDefaultApi>({ ops, p, }: {
4
+ p: IOpenApiCodeBlock<TDefaultApi>;
5
+ ops: IOpenApiOperationBlock;
6
+ }) => JSX.Element;
@@ -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;
@@ -0,0 +1,14 @@
1
+ import { IOpenApi, IOpenApiCodeBlock, IOpenApiOperation, IOpenApiOperationBlock } from '../types';
2
+ export declare const Highlight: import("styled-components").StyledComponent<"span", any, {}, never>;
3
+ export declare const Highlight2: import("styled-components").StyledComponent<"span", any, {}, never>;
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;
@@ -0,0 +1,79 @@
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.getSecurity = exports.getBodyJson = exports.getOperation = exports.Highlight2 = exports.Highlight = void 0;
7
+ const common_1 = require("../../../../common");
8
+ const styled_components_1 = __importDefault(require("styled-components"));
9
+ exports.Highlight = styled_components_1.default.span `
10
+ color: green;
11
+ `;
12
+ exports.Highlight2 = styled_components_1.default.span `
13
+ color: indianred;
14
+ `;
15
+ const getApiUrl = (p) => {
16
+ return p.schema.servers[0].url;
17
+ };
18
+ const getFunctionName = (p) => {
19
+ let ret = p.funcF.toString();
20
+ const i1 = ret.indexOf('.') + 1;
21
+ const i2 = (0, common_1.indexOfNumber)(ret, '(', 1);
22
+ ret = ret.substring(i1, i2);
23
+ return ret;
24
+ };
25
+ const getOperation = (p) => {
26
+ let path;
27
+ let verb;
28
+ const func = getFunctionName(p);
29
+ Object.entries(p.schema.paths).forEach(([pathN, ops]) => Object.entries(ops).forEach(([verbN, op]) => {
30
+ if (op.operationId === func) {
31
+ path = pathN;
32
+ verb = verbN;
33
+ }
34
+ }));
35
+ if (!path || !verb) {
36
+ return {
37
+ error: 'operation not found',
38
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
+ };
40
+ }
41
+ const operation = p.schema.paths[path][verb];
42
+ return { operation, verb, path, fullApiUrl: getApiUrl(p) };
43
+ };
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;
51
+ }
52
+ //no body required
53
+ if (bend - bstart === 1) {
54
+ return undefined;
55
+ }
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;
76
+ }
77
+ return undefined;
78
+ };
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;
@@ -0,0 +1,2 @@
1
+ export * from './OpenApiCodeBlock';
2
+ export * from './types';
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./CodeBlock"), exports);
17
+ __exportStar(require("./OpenApiCodeBlock"), exports);
18
18
  __exportStar(require("./types"), exports);
@@ -0,0 +1,60 @@
1
+ /// <reference types="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
+ }
@@ -2,7 +2,7 @@ export * from './BorderGradient';
2
2
  export * from './Button';
3
3
  export * from './Chevron';
4
4
  export * from './Close';
5
- export * from './CodeBlock';
5
+ export * from './OpenApiCodeBlock';
6
6
  export * from './Confirm/Dialog';
7
7
  export * from './DropdownList';
8
8
  export * from './FlexColumn';
@@ -18,7 +18,7 @@ __exportStar(require("./BorderGradient"), exports);
18
18
  __exportStar(require("./Button"), exports);
19
19
  __exportStar(require("./Chevron"), exports);
20
20
  __exportStar(require("./Close"), exports);
21
- __exportStar(require("./CodeBlock"), exports);
21
+ __exportStar(require("./OpenApiCodeBlock"), exports);
22
22
  __exportStar(require("./Confirm/Dialog"), exports);
23
23
  __exportStar(require("./DropdownList"), exports);
24
24
  __exportStar(require("./FlexColumn"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.240",
3
+ "version": "0.0.243",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",
@@ -1,3 +0,0 @@
1
- /// <reference types="react" />
2
- import { ICodeBlock } from './types';
3
- export declare const CodeBlock: <TDefaultApi>(p: ICodeBlock<TDefaultApi>) => JSX.Element;
@@ -1,21 +0,0 @@
1
- /// <reference types="react" />
2
- import { ICodeBlock } from '../types';
3
- export declare const Highlight: import("styled-components").StyledComponent<"span", any, {}, never>;
4
- export declare const Highlight2: import("styled-components").StyledComponent<"span", any, {}, never>;
5
- export declare const getLines: <TDefaultApi>(p: ICodeBlock<TDefaultApi>) => {
6
- error: string;
7
- verb?: undefined;
8
- path?: undefined;
9
- headerLines?: undefined;
10
- fullApiUrl?: undefined;
11
- bodyLine?: undefined;
12
- operation?: undefined;
13
- } | {
14
- verb: string | undefined;
15
- path: string | undefined;
16
- error: undefined;
17
- headerLines: JSX.Element[];
18
- fullApiUrl: any;
19
- bodyLine: JSX.Element;
20
- operation: any;
21
- };
@@ -1,107 +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.getLines = exports.Highlight2 = exports.Highlight = void 0;
7
- const security_1 = require("./security");
8
- const string_1 = require("../../../../common/helpers/string");
9
- const styled_components_1 = __importDefault(require("styled-components"));
10
- const react_1 = __importDefault(require("react"));
11
- exports.Highlight = styled_components_1.default.span `
12
- color: green;
13
- `;
14
- exports.Highlight2 = styled_components_1.default.span `
15
- color: indianred;
16
- `;
17
- const getApiUrl = (p) => {
18
- return p.schema.servers[0].url;
19
- };
20
- const getFunctionName = (p) => {
21
- let ret = p.funcF.toString();
22
- const i1 = ret.indexOf('.') + 1;
23
- const i2 = (0, string_1.indexOfNumber)(ret, '(', 1);
24
- ret = ret.substring(i1, i2);
25
- return ret;
26
- };
27
- const getOperation = (p) => {
28
- let path;
29
- let verb;
30
- const func = getFunctionName(p);
31
- Object.entries(p.schema.paths).forEach(([pathN, ops]) =>
32
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
- Object.entries(ops).forEach(([verbN, op]) => {
34
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
- if (op.operationId === func) {
36
- path = pathN;
37
- verb = verbN;
38
- }
39
- }));
40
- if (!path || !verb) {
41
- return { error: 'operation not found' };
42
- }
43
- const operation = p.schema.paths[path][verb];
44
- return { operation, verb, path };
45
- };
46
- const getBody = (p) => {
47
- const body = p.funcF.toString();
48
- const bstart = (0, string_1.indexOfNumber)(body, '(', 1);
49
- const bend = !bstart ? undefined : body.lastIndexOf(')');
50
- if (!bstart || !bend) {
51
- return { content: react_1.default.createElement(react_1.default.Fragment, null), header: react_1.default.createElement(react_1.default.Fragment, null) };
52
- }
53
- const slice = body.substring(bstart + 1, bend);
54
- const json = slice.replace(/([a-zA-Z0-9-]+[^"]):/gim, '"$1":');
55
- const nice = JSON.stringify(JSON.parse(json), null, 2);
56
- const content = (react_1.default.createElement(react_1.default.Fragment, null,
57
- "-d @- <<'EOF'",
58
- react_1.default.createElement("br", null),
59
- react_1.default.createElement(exports.Highlight2, null, nice),
60
- react_1.default.createElement("br", null),
61
- "EOF"));
62
- const header = (react_1.default.createElement(react_1.default.Fragment, null,
63
- react_1.default.createElement("span", null, "--header "),
64
- react_1.default.createElement(exports.Highlight, null,
65
- react_1.default.createElement(exports.Highlight, null, "'Content-Type: application/json'"))));
66
- return {
67
- content,
68
- header,
69
- };
70
- };
71
- const getLines = (p) => {
72
- var _a, _b;
73
- const ops = getOperation(p);
74
- if (ops.error) {
75
- return { error: ops.error };
76
- }
77
- const { operation, path, verb } = ops;
78
- const apiUrl = getApiUrl(p);
79
- const fullApiUrl = apiUrl + path;
80
- const secline = (0, security_1.getSecurityLine)(p, { operation });
81
- if (secline.error) {
82
- return { error: secline.error };
83
- }
84
- const bodyLines = (_a = getBody(p)) !== null && _a !== void 0 ? _a : undefined;
85
- const headerLines = [];
86
- if (secline.content) {
87
- headerLines.push(secline.content);
88
- headerLines.push(react_1.default.createElement(react_1.default.Fragment, null,
89
- ' ',
90
- "\\",
91
- react_1.default.createElement("br", null)));
92
- }
93
- if (bodyLines.header) {
94
- headerLines.push(bodyLines.header);
95
- headerLines.push(react_1.default.createElement(react_1.default.Fragment, null, " \\"));
96
- }
97
- return {
98
- verb,
99
- path,
100
- error: undefined,
101
- headerLines,
102
- fullApiUrl,
103
- bodyLine: (_b = bodyLines === null || bodyLines === void 0 ? void 0 : bodyLines.content) !== null && _b !== void 0 ? _b : undefined,
104
- operation,
105
- };
106
- };
107
- exports.getLines = getLines;
@@ -1,8 +0,0 @@
1
- /// <reference types="react" />
2
- import { ICodeBlock } from '../types';
3
- export declare const getSecurityLine: <TDefaultApi>(p: ICodeBlock<TDefaultApi>, { operation }: {
4
- operation: any;
5
- }) => {
6
- error?: string;
7
- content: JSX.Element;
8
- };
@@ -1,37 +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,
11
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
- { operation }) => {
13
- var _a;
14
- const security1 = (_a = operation.security) === null || _a === void 0 ? void 0 : _a[0];
15
- const security2 = !security1 ? undefined : Object.keys(security1)[0];
16
- const security = !security2
17
- ? undefined
18
- : p.schema.components.securitySchemes[security2];
19
- if (security) {
20
- if (security.in !== 'header') {
21
- return { error: 'not supported sec in', content: react_1.default.createElement(react_1.default.Fragment, null) };
22
- }
23
- return {
24
- content: (react_1.default.createElement(react_1.default.Fragment, null,
25
- react_1.default.createElement("span", null, "--header "),
26
- react_1.default.createElement(common_1.Highlight, null,
27
- "'",
28
- (0, string_1.toTitleCase)(security.name),
29
- ":",
30
- ' ',
31
- react_1.default.createElement(common_1.Highlight2, null, p.apiKey || '(API KEY)'),
32
- "'"))),
33
- };
34
- }
35
- return { content: react_1.default.createElement(react_1.default.Fragment, null) };
36
- };
37
- exports.getSecurityLine = getSecurityLine;
@@ -1,2 +0,0 @@
1
- export * from './CodeBlock';
2
- export * from './types';
@@ -1,9 +0,0 @@
1
- export interface ICodeBlock<TDefaultApi> {
2
- /**
3
- * openapi schema. eg
4
- * const schema: any = require('common/openapi.generated').default;
5
- */
6
- schema: any;
7
- apiKey?: string;
8
- funcF: (f: TDefaultApi) => Promise<any>;
9
- }