ag-common 0.0.762 → 0.0.763

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 (61) hide show
  1. package/dist/api/helpers/apigw.d.ts +1 -1
  2. package/dist/api/helpers/apigw.js +6 -8
  3. package/dist/api/helpers/index.d.ts +0 -2
  4. package/dist/api/helpers/index.js +0 -2
  5. package/dist/api/types/index.d.ts +0 -32
  6. package/dist/ui/components/index.d.ts +0 -1
  7. package/dist/ui/components/index.js +0 -1
  8. package/dist/ui/helpers/dom.js +2 -0
  9. package/dist/ui/helpers/index.d.ts +0 -1
  10. package/dist/ui/helpers/index.js +0 -1
  11. package/dist/ui/helpers/routes.d.ts +0 -11
  12. package/dist/ui/helpers/useContextMenu.js +3 -0
  13. package/dist/ui/helpers/useIsInViewport.js +1 -0
  14. package/dist/ui/helpers/useOnScroll.js +2 -3
  15. package/package.json +1 -2
  16. package/dist/api/helpers/openApiHelpers.d.ts +0 -43
  17. package/dist/api/helpers/openApiHelpers.js +0 -163
  18. package/dist/api/helpers/validateOpenApi.d.ts +0 -25
  19. package/dist/api/helpers/validateOpenApi.js +0 -127
  20. package/dist/api/openapi-postfix.d.ts +0 -1
  21. package/dist/api/openapi-postfix.js +0 -42
  22. package/dist/api/openapi-prefix.d.ts +0 -1
  23. package/dist/api/openapi-prefix.js +0 -88
  24. package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.d.ts +0 -3
  25. package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.js +0 -69
  26. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.d.ts +0 -6
  27. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.js +0 -30
  28. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.d.ts +0 -2
  29. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.js +0 -31
  30. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.d.ts +0 -11
  31. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.js +0 -28
  32. package/dist/ui/components/OpenApiCodeBlock/curl/index.d.ts +0 -6
  33. package/dist/ui/components/OpenApiCodeBlock/curl/index.js +0 -35
  34. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.d.ts +0 -3
  35. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.js +0 -23
  36. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.d.ts +0 -2
  37. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.js +0 -19
  38. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.d.ts +0 -3
  39. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.js +0 -78
  40. package/dist/ui/components/OpenApiCodeBlock/fetch/index.d.ts +0 -6
  41. package/dist/ui/components/OpenApiCodeBlock/fetch/index.js +0 -24
  42. package/dist/ui/components/OpenApiCodeBlock/helpers/common.d.ts +0 -20
  43. package/dist/ui/components/OpenApiCodeBlock/helpers/common.js +0 -89
  44. package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.d.ts +0 -4
  45. package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.js +0 -25
  46. package/dist/ui/components/OpenApiCodeBlock/index.d.ts +0 -2
  47. package/dist/ui/components/OpenApiCodeBlock/index.js +0 -17
  48. package/dist/ui/components/OpenApiCodeBlock/types.d.ts +0 -60
  49. package/dist/ui/components/OpenApiCodeBlock/types.js +0 -2
  50. package/dist/ui/helpers/callOpenApi/cached.d.ts +0 -34
  51. package/dist/ui/helpers/callOpenApi/cached.js +0 -92
  52. package/dist/ui/helpers/callOpenApi/direct.d.ts +0 -9
  53. package/dist/ui/helpers/callOpenApi/direct.js +0 -137
  54. package/dist/ui/helpers/callOpenApi/helpers.d.ts +0 -9
  55. package/dist/ui/helpers/callOpenApi/helpers.js +0 -60
  56. package/dist/ui/helpers/callOpenApi/hook.d.ts +0 -27
  57. package/dist/ui/helpers/callOpenApi/hook.js +0 -82
  58. package/dist/ui/helpers/callOpenApi/index.d.ts +0 -5
  59. package/dist/ui/helpers/callOpenApi/index.js +0 -20
  60. package/dist/ui/helpers/callOpenApi/types.d.ts +0 -19
  61. package/dist/ui/helpers/callOpenApi/types.js +0 -2
@@ -1,88 +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 { load } = require('js-yaml');
12
- const SwaggerParser = require('swagger-parser');
13
- const fs = require('fs');
14
- const process = require('process');
15
- var pathV = require('path');
16
- var cwd = process.cwd();
17
- var resolvePath = (p) => pathV.resolve(cwd, p);
18
- //
19
- function cleanSrc() {
20
- console.log('fixing colons in field names');
21
- let files = fs
22
- .readdirSync(resolvePath('./src/api'))
23
- .filter((r) => r.endsWith('.ts'))
24
- .map((s) => `./src/api/${s}`);
25
- files.forEach((f) => {
26
- let c = fs.readFileSync(f).toString();
27
- c = c.replace(/cognitopreferred_role/, "'cognito:preferred_role'");
28
- c = c.replace(/cognitousername/, "'cognito:username'");
29
- c = c.replace(/cognitogroups/, "'cognito:groups'");
30
- c = c.replace(/this\.configuration\.queryParamsStringify\(/, '(this.configuration.queryParamsStringify||querystring)(');
31
- fs.writeFileSync(f, c);
32
- });
33
- //disable all errors
34
- console.log('disable all api ts errors');
35
- files = fs
36
- .readdirSync(resolvePath('./src/api'))
37
- .filter((r) => r.endsWith('.ts'))
38
- .map((s) => `./src/api/${s}`);
39
- files.forEach((f) => {
40
- var c = fs.readFileSync(f);
41
- c = '/* eslint-disable */\n// @ts-nocheck\n' + c;
42
- fs.writeFileSync(f, c);
43
- });
44
- [resolvePath('./src/api/runtime.ts')].forEach((f) => {
45
- if (fs.existsSync(f)) {
46
- console.log('fix middleware');
47
- let c = fs.readFileSync(f).toString();
48
- c = c.replace('= configuration.middleware;', '= configuration.middleware || [];');
49
- fs.writeFileSync(f, c);
50
- }
51
- else {
52
- console.warn('no middleware to fix (src/api/runtime)');
53
- }
54
- });
55
- }
56
- //
57
- function generateJs() {
58
- return __awaiter(this, void 0, void 0, function* () {
59
- try {
60
- console.log('generating openapi ts');
61
- var p = resolvePath('./openapi.yml');
62
- if (!fs.existsSync(p)) {
63
- p = resolvePath('./openapi/index.yml');
64
- process.chdir(resolvePath('./openapi'));
65
- }
66
- if (!fs.existsSync(p)) {
67
- console.error('cant generate swagger, expecting openapi.yml or openapi/index.yml');
68
- return;
69
- }
70
- const yml = load(fs.readFileSync(p, 'utf8'));
71
- const schema = yield SwaggerParser.validate(yml);
72
- const content = `var ret=${JSON.stringify(schema)};\nmodule.exports.default=ret`;
73
- fs.writeFileSync(resolvePath('./openapi.generated.js'), content);
74
- console.log('generated');
75
- }
76
- catch (e) {
77
- console.log('err=', e);
78
- }
79
- });
80
- }
81
- function run() {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- console.log('start openapi fix in ' + cwd);
84
- cleanSrc();
85
- yield generateJs();
86
- });
87
- }
88
- void run();
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- import type { IOpenApiCodeBlock } from './types';
3
- export declare const OpenApiCodeBlock: <TDefaultApi>(p: IOpenApiCodeBlock<TDefaultApi>) => React.JSX.Element;
@@ -1,69 +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.OpenApiCodeBlock = void 0;
8
- const styled_1 = __importDefault(require("@emotion/styled"));
9
- const react_1 = __importDefault(require("react"));
10
- const FlexRow_1 = require("../FlexRow");
11
- const curl_1 = require("./curl");
12
- const fetch_1 = require("./fetch");
13
- const common_1 = require("./helpers/common");
14
- const Base = styled_1.default.div `
15
- display: flex;
16
- flex-flow: column;
17
- width: calc(100% - 2rem);
18
- flex-grow: 1;
19
- border: solid 1px #333;
20
- padding: 1rem;
21
- overflow-y: auto;
22
- max-height: calc(100% - 2rem);
23
- `;
24
- const Verb = styled_1.default.div `
25
- background-color: #333;
26
- color: white;
27
- margin-right: 0.5rem;
28
- padding: 0.25rem;
29
- font-size: 0.8rem;
30
- `;
31
- const ApiName = styled_1.default.div `
32
- font-weight: bold;
33
- font-size: 1.5rem;
34
- `;
35
- const BlockTitle = styled_1.default.div `
36
- color: #333;
37
- font-size: 1.2rem;
38
- margin-top: 2rem;
39
- `;
40
- const Block = styled_1.default.div `
41
- background-color: rgba(0, 0, 0, 0.1);
42
- padding: 1rem;
43
- margin-top: 0.5rem;
44
- `;
45
- const OpenApiCodeBlock = (p) => {
46
- var _a;
47
- const ops = (0, common_1.getOperation)(p);
48
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
49
- if (ops.error || !ops.verb || !ops.operation) {
50
- return react_1.default.createElement(Base, null, ops.error);
51
- }
52
- const { verb, operation, path } = ops;
53
- return (react_1.default.createElement(Base, null,
54
- react_1.default.createElement(FlexRow_1.FlexRow, { center: true, noGrow: true },
55
- react_1.default.createElement(Verb, null, verb),
56
- react_1.default.createElement(ApiName, null, (_a = operation.description) !== null && _a !== void 0 ? _a : path)),
57
- react_1.default.createElement(BlockTitle, null, "Definition"),
58
- react_1.default.createElement(Block, null,
59
- verb.toUpperCase(),
60
- " ",
61
- path),
62
- react_1.default.createElement(BlockTitle, null, "Example curl Request"),
63
- react_1.default.createElement(Block, null,
64
- react_1.default.createElement(curl_1.Curl, { ops: ops, p: p })),
65
- react_1.default.createElement(BlockTitle, null, "Example fetch Request"),
66
- react_1.default.createElement(Block, null,
67
- react_1.default.createElement(fetch_1.Fetch, { ops: ops, p: p }))));
68
- };
69
- exports.OpenApiCodeBlock = OpenApiCodeBlock;
@@ -1,6 +0,0 @@
1
- import type { JSX } from 'react';
2
- import type { IOpenApiCodeBlock } from '../../types';
3
- export declare const getBody: <TDefaultApi>(p: IOpenApiCodeBlock<TDefaultApi>) => {
4
- content: JSX.Element | undefined;
5
- header: JSX.Element | undefined;
6
- };
@@ -1,30 +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.getBody = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const common_1 = require("../../helpers/common");
9
- const getBody = (p) => {
10
- var _a;
11
- const { nice } = (_a = (0, common_1.getBodyJson)(p)) !== null && _a !== void 0 ? _a : {};
12
- if (!nice) {
13
- return { content: undefined, header: undefined };
14
- }
15
- const content = (react_1.default.createElement(react_1.default.Fragment, null,
16
- "-d @- <<'EOF'",
17
- react_1.default.createElement("br", null),
18
- react_1.default.createElement(common_1.Highlight2, null, nice),
19
- react_1.default.createElement("br", null),
20
- "EOF"));
21
- const header = (react_1.default.createElement(react_1.default.Fragment, null,
22
- react_1.default.createElement("span", null, "--header "),
23
- react_1.default.createElement(common_1.Highlight, null,
24
- react_1.default.createElement(common_1.Highlight, null, "'Content-Type: application/json'"))));
25
- return {
26
- content,
27
- header,
28
- };
29
- };
30
- exports.getBody = getBody;
@@ -1,2 +0,0 @@
1
- import type { ICurlLines, IOpenApiCodeBlock, IOpenApiOperationBlock } from '../../types';
2
- export declare const getCurlLines: <TDefaultApi>(ops: IOpenApiOperationBlock, p: IOpenApiCodeBlock<TDefaultApi>) => ICurlLines;
@@ -1,31 +0,0 @@
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
- const { operation, path, verb, fullApiUrl } = ops;
8
- const withPath = fullApiUrl + path;
9
- const secline = (0, security_1.getSecurityLine)(p, { operation });
10
- if (secline.error) {
11
- return { error: secline.error };
12
- }
13
- const bodyLines = (0, body_1.getBody)(p);
14
- const headerLines = [];
15
- if (secline.content) {
16
- headerLines.push(secline.content);
17
- }
18
- if (bodyLines.header) {
19
- headerLines.push(bodyLines.header);
20
- }
21
- return {
22
- verb,
23
- path,
24
- error: undefined,
25
- headerLines,
26
- fullApiUrl: withPath,
27
- bodyLine: bodyLines.content,
28
- operation,
29
- };
30
- };
31
- exports.getCurlLines = getCurlLines;
@@ -1,11 +0,0 @@
1
- import type { JSX } from 'react';
2
- import type { 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
- };
@@ -1,28 +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 react_1 = __importDefault(require("react"));
8
- const common_1 = require("../../helpers/common");
9
- const getSecurityLine = (p, { operation }) => {
10
- const sec = (0, common_1.getSecurity)(p, { operation });
11
- if (sec === null) {
12
- return { error: 'not supported sec in', content: undefined };
13
- }
14
- if (!sec) {
15
- return { content: undefined };
16
- }
17
- return {
18
- content: (react_1.default.createElement(react_1.default.Fragment, null,
19
- react_1.default.createElement("span", null, "--header "),
20
- react_1.default.createElement(common_1.Highlight, null,
21
- "'",
22
- sec.name,
23
- ": ",
24
- react_1.default.createElement(common_1.Highlight2, null, p.apiKey || '(API KEY)'),
25
- "'"))),
26
- };
27
- };
28
- exports.getSecurityLine = getSecurityLine;
@@ -1,6 +0,0 @@
1
- import type { JSX } from 'react';
2
- import type { IOpenApiCodeBlock, IOpenApiOperationBlock } from '../types';
3
- export declare const Curl: <TDefaultApi>({ ops, p, }: {
4
- p: IOpenApiCodeBlock<TDefaultApi>;
5
- ops: IOpenApiOperationBlock;
6
- }) => JSX.Element;
@@ -1,35 +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.Curl = void 0;
8
- const styled_1 = __importDefault(require("@emotion/styled"));
9
- const react_1 = __importDefault(require("react"));
10
- const array_1 = require("../../../../common/helpers/array");
11
- const common_1 = require("../helpers/common");
12
- const joinJsx_1 = require("../helpers/joinJsx");
13
- const getCurlLines_1 = require("./helpers/getCurlLines");
14
- const Base = styled_1.default.div `
15
- white-space: pre;
16
- `;
17
- const Curl = ({ ops, p, }) => {
18
- const { fullApiUrl, headerLines, bodyLine } = (0, getCurlLines_1.getCurlLines)(ops, p);
19
- const { verb } = ops;
20
- const rows = [
21
- react_1.default.createElement(react_1.default.Fragment, null,
22
- "curl --request ",
23
- verb.toUpperCase()),
24
- react_1.default.createElement(react_1.default.Fragment, null,
25
- "--url ",
26
- react_1.default.createElement(common_1.Highlight, null,
27
- "'",
28
- fullApiUrl,
29
- "'")),
30
- ...(headerLines !== null && headerLines !== void 0 ? headerLines : []),
31
- bodyLine,
32
- ].filter(array_1.notEmpty);
33
- return react_1.default.createElement(Base, null, (0, joinJsx_1.joinJsxWithSlash)(rows));
34
- };
35
- exports.Curl = Curl;
@@ -1,3 +0,0 @@
1
- import type { JSX } from 'react';
2
- import type { IOpenApiCodeBlock, IOpenApiOperationBlock } from '../../types';
3
- export declare const getFetchCall: <TDefaultApi>(p: IOpenApiCodeBlock<TDefaultApi>, ops: IOpenApiOperationBlock) => JSX.Element | undefined;
@@ -1,23 +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.getFetchCall = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const common_1 = require("../../helpers/common");
9
- const getFetchCall = (p, ops) => {
10
- return (react_1.default.createElement(react_1.default.Fragment, null,
11
- react_1.default.createElement(common_1.Highlight, null, "const"),
12
- "\u00A0response = ",
13
- react_1.default.createElement(common_1.Highlight, null, "await"),
14
- ' ',
15
- react_1.default.createElement(common_1.Highlight2, null, "fetch"),
16
- "(",
17
- react_1.default.createElement(common_1.Highlight, null,
18
- "'",
19
- ops.fullApiUrl,
20
- "'"),
21
- ",\u00A0 requestOptions);"));
22
- };
23
- exports.getFetchCall = getFetchCall;
@@ -1,2 +0,0 @@
1
- import type { IFetchLines, IOpenApiCodeBlock, IOpenApiOperationBlock } from '../../types';
2
- export declare const getFetchLines: <TDefaultApi>(ops: IOpenApiOperationBlock, p: IOpenApiCodeBlock<TDefaultApi>) => IFetchLines;
@@ -1,19 +0,0 @@
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;
@@ -1,3 +0,0 @@
1
- import type { JSX } from 'react';
2
- import type { IOpenApiCodeBlock, IOpenApiOperationBlock } from '../../types';
3
- export declare const getRequestOptions: <TDefaultApi>(p: IOpenApiCodeBlock<TDefaultApi>, ops: IOpenApiOperationBlock) => JSX.Element | undefined;
@@ -1,78 +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.getRequestOptions = void 0;
8
- const styled_1 = __importDefault(require("@emotion/styled"));
9
- const react_1 = __importDefault(require("react"));
10
- const common_1 = require("../../helpers/common");
11
- const joinJsx_1 = require("../../helpers/joinJsx");
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_1.default.div `
15
- padding-left: 0.5rem;
16
- `;
17
- const getRequestOptions = (p, ops) => {
18
- var _a;
19
- const { nice } = (_a = (0, common_1.getBodyJson)(p)) !== null && _a !== void 0 ? _a : {};
20
- if (!nice) {
21
- return undefined;
22
- }
23
- const sec = (0, common_1.getSecurity)(p, ops);
24
- const h1 = (react_1.default.createElement(react_1.default.Fragment, null,
25
- ' ',
26
- react_1.default.createElement(common_1.Highlight, null, "'Content-Type'"),
27
- ":",
28
- ' ',
29
- react_1.default.createElement(common_1.Highlight, null, "'application/json'")));
30
- let h2;
31
- if (sec) {
32
- h2 = (react_1.default.createElement(react_1.default.Fragment, null,
33
- ' ',
34
- react_1.default.createElement(common_1.Highlight, null,
35
- "'",
36
- sec.name,
37
- "'"),
38
- ":",
39
- ' ',
40
- react_1.default.createElement(common_1.Highlight, null,
41
- "'",
42
- p.apiKey || '(API KEY)',
43
- "'")));
44
- }
45
- const header = !sec ? (react_1.default.createElement(react_1.default.Fragment, null)) : (react_1.default.createElement(react_1.default.Fragment, null,
46
- "headers: ",
47
- lb,
48
- react_1.default.createElement(Lpad, null, (0, joinJsx_1.joinJsxWithComma)([h1, h2])),
49
- rb,
50
- ","));
51
- const body = (react_1.default.createElement(react_1.default.Fragment, null,
52
- "body: ",
53
- react_1.default.createElement(common_1.Highlight2, null, "JSON"),
54
- ".",
55
- react_1.default.createElement(common_1.Highlight, null, "stringify"),
56
- "(",
57
- nice,
58
- ")"));
59
- const content = (react_1.default.createElement(react_1.default.Fragment, null,
60
- "const requestOptions = ",
61
- lb,
62
- react_1.default.createElement(Lpad, null,
63
- "method: ",
64
- react_1.default.createElement(common_1.Highlight, null,
65
- "'",
66
- ops.verb.toUpperCase(),
67
- "'"),
68
- ",",
69
- react_1.default.createElement("br", null),
70
- header,
71
- react_1.default.createElement("br", null),
72
- body,
73
- react_1.default.createElement("br", null)),
74
- rb,
75
- ";"));
76
- return content;
77
- };
78
- exports.getRequestOptions = getRequestOptions;
@@ -1,6 +0,0 @@
1
- import React from 'react';
2
- import type { IOpenApiCodeBlock, IOpenApiOperationBlock } from '../types';
3
- export declare const Fetch: <TDefaultApi>({ ops, p, }: {
4
- p: IOpenApiCodeBlock<TDefaultApi>;
5
- ops: IOpenApiOperationBlock;
6
- }) => React.JSX.Element;
@@ -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,2 +0,0 @@
1
- export * from './OpenApiCodeBlock';
2
- export type * from './types';
@@ -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);