ag-common 0.0.762 → 0.0.764

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) 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 -2
  10. package/dist/ui/helpers/index.js +0 -2
  11. package/dist/ui/helpers/jwt.d.ts +0 -12
  12. package/dist/ui/helpers/routes.d.ts +0 -18
  13. package/dist/ui/helpers/useContextMenu.js +3 -0
  14. package/dist/ui/helpers/useIsInViewport.js +1 -0
  15. package/dist/ui/helpers/useOnScroll.js +2 -3
  16. package/package.json +24 -32
  17. package/dist/api/helpers/openApiHelpers.d.ts +0 -43
  18. package/dist/api/helpers/openApiHelpers.js +0 -163
  19. package/dist/api/helpers/validateOpenApi.d.ts +0 -25
  20. package/dist/api/helpers/validateOpenApi.js +0 -127
  21. package/dist/api/openapi-postfix.d.ts +0 -1
  22. package/dist/api/openapi-postfix.js +0 -42
  23. package/dist/api/openapi-prefix.d.ts +0 -1
  24. package/dist/api/openapi-prefix.js +0 -88
  25. package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.d.ts +0 -3
  26. package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.js +0 -69
  27. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.d.ts +0 -6
  28. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.js +0 -30
  29. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.d.ts +0 -2
  30. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.js +0 -31
  31. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.d.ts +0 -11
  32. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.js +0 -28
  33. package/dist/ui/components/OpenApiCodeBlock/curl/index.d.ts +0 -6
  34. package/dist/ui/components/OpenApiCodeBlock/curl/index.js +0 -35
  35. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.d.ts +0 -3
  36. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.js +0 -23
  37. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.d.ts +0 -2
  38. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.js +0 -19
  39. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.d.ts +0 -3
  40. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.js +0 -78
  41. package/dist/ui/components/OpenApiCodeBlock/fetch/index.d.ts +0 -6
  42. package/dist/ui/components/OpenApiCodeBlock/fetch/index.js +0 -24
  43. package/dist/ui/components/OpenApiCodeBlock/helpers/common.d.ts +0 -20
  44. package/dist/ui/components/OpenApiCodeBlock/helpers/common.js +0 -89
  45. package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.d.ts +0 -4
  46. package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.js +0 -25
  47. package/dist/ui/components/OpenApiCodeBlock/index.d.ts +0 -2
  48. package/dist/ui/components/OpenApiCodeBlock/index.js +0 -17
  49. package/dist/ui/components/OpenApiCodeBlock/types.d.ts +0 -60
  50. package/dist/ui/components/OpenApiCodeBlock/types.js +0 -2
  51. package/dist/ui/helpers/axiosHelper.d.ts +0 -17
  52. package/dist/ui/helpers/axiosHelper.js +0 -92
  53. package/dist/ui/helpers/callOpenApi/cached.d.ts +0 -34
  54. package/dist/ui/helpers/callOpenApi/cached.js +0 -92
  55. package/dist/ui/helpers/callOpenApi/direct.d.ts +0 -9
  56. package/dist/ui/helpers/callOpenApi/direct.js +0 -137
  57. package/dist/ui/helpers/callOpenApi/helpers.d.ts +0 -9
  58. package/dist/ui/helpers/callOpenApi/helpers.js +0 -60
  59. package/dist/ui/helpers/callOpenApi/hook.d.ts +0 -27
  60. package/dist/ui/helpers/callOpenApi/hook.js +0 -82
  61. package/dist/ui/helpers/callOpenApi/index.d.ts +0 -5
  62. package/dist/ui/helpers/callOpenApi/index.js +0 -20
  63. package/dist/ui/helpers/callOpenApi/types.d.ts +0 -19
  64. package/dist/ui/helpers/callOpenApi/types.js +0 -2
@@ -1,127 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.validateOpenApi = validateOpenApi;
16
- const openapi_request_validator_1 = __importDefault(require("openapi-request-validator"));
17
- const i18n_1 = require("../../common/helpers/i18n");
18
- const log_1 = require("../../common/helpers/log");
19
- const object_1 = require("../../common/helpers/object");
20
- const api_1 = require("./api");
21
- const validations_1 = require("./validations");
22
- //
23
- const getOperation = ({ path, method, resource, schema, }) => {
24
- var _a;
25
- const resourcePath = Object.keys(schema.paths).find((rp) => rp === resource);
26
- if (!resourcePath) {
27
- throw new Error('incorrect path');
28
- }
29
- const operation = (_a = schema.paths[resourcePath]) === null || _a === void 0 ? void 0 : _a[method];
30
- if (!operation) {
31
- const msg = `no operation found for ${method}/${path}`;
32
- (0, log_1.warn)(`${msg} ${Object.keys(schema.paths)}`);
33
- throw new Error(msg);
34
- }
35
- /*
36
- var path= '/events/12345/topics/2216026039415263/like'
37
- var resourcePath ='/events/{eventCode}/topics/{topicId}/like'
38
- */
39
- const re = new RegExp(resourcePath
40
- .replace(/\//gim, `\\/`)
41
- .replace(/\{(.+?)\}/gim, '(?<$1>[^\\\\]+)'), 'i').exec(path);
42
- const pathParams = (re === null || re === void 0 ? void 0 : re.groups) && (0, object_1.copy)(re.groups);
43
- return { operation, pathParams };
44
- };
45
- function validateOpenApi(_a) {
46
- return __awaiter(this, arguments, void 0, function* ({ event, next, authorized, schema, COGNITO_USER_POOL_ID, jwksRegion = 'ap-southeast-2', getAndValidateTokenOverride, }) {
47
- var _b, _c, _d, _e, _f, _g, _h;
48
- if (!schema) {
49
- throw new Error('schema undefined!');
50
- }
51
- if (!COGNITO_USER_POOL_ID) {
52
- throw new Error('COGNITO_USER_POOL_ID undefined');
53
- }
54
- const request = {
55
- method: event.httpMethod,
56
- path: event.path,
57
- params: undefined,
58
- query: event.queryStringParameters,
59
- body: (0, object_1.tryJsonParse)(event.body, event.body),
60
- headers: (0, object_1.objectKeysToLowerCase)(event.headers),
61
- };
62
- const method = event.requestContext.httpMethod.toLowerCase();
63
- const pathParameters = (_b = event.pathParameters) !== null && _b !== void 0 ? _b : {};
64
- const queryStringParameters = (_c = event.queryStringParameters) !== null && _c !== void 0 ? _c : {};
65
- //
66
- const opm = getOperation({
67
- path: event.path,
68
- method,
69
- resource: event.resource,
70
- schema,
71
- });
72
- if (!opm.operation) {
73
- const msg = `no request handler found! for ${method} ${event.path} - cant validate`;
74
- (0, log_1.error)(msg);
75
- return (0, api_1.returnCode)(400, msg);
76
- }
77
- if (!opm.operation.requestBody && !opm.operation.parameters) {
78
- if (!!event.body || Object.keys(pathParameters).length > 0) {
79
- (0, log_1.warn)(`bad req, unexpected params`);
80
- return (0, api_1.returnCode)(400, 'bad data');
81
- }
82
- // no validation necessary
83
- }
84
- else {
85
- try {
86
- request.params = opm.pathParams;
87
- (0, log_1.debug)('req=', JSON.stringify(Object.assign(Object.assign({}, request), { body: ((_e = (_d = request.body) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0) > 2000
88
- ? '(truncating long body)'
89
- : request.body }), null, 2));
90
- const resp = new openapi_request_validator_1.default(Object.assign(Object.assign({}, opm.operation), { schemas: schema.components.schemas })).validateRequest(request);
91
- if (resp) {
92
- (0, log_1.warn)('bad request');
93
- (0, log_1.debug)('opm=', JSON.stringify(opm, null, 2));
94
- (0, log_1.debug)('resp=', JSON.stringify(resp, null, 2));
95
- return (0, api_1.returnCode)(400, `error:${(_g = (_f = resp === null || resp === void 0 ? void 0 : resp.errors) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.message}`);
96
- }
97
- (0, log_1.debug)(`validated request:`, event.path);
98
- }
99
- catch (e) {
100
- (0, log_1.error)('e=', e, JSON.stringify(opm));
101
- }
102
- }
103
- let userProfile;
104
- let error;
105
- const authHeader = event.headers.Authorization || event.headers.authorization;
106
- if (authorized === true || (authorized === 'optional' && authHeader)) {
107
- const vf = getAndValidateTokenOverride !== null && getAndValidateTokenOverride !== void 0 ? getAndValidateTokenOverride : validations_1.getAndValidateToken;
108
- ({ error, userProfile } = yield vf({
109
- tokenRaw: authHeader,
110
- COGNITO_USER_POOL_ID,
111
- jwksRegion,
112
- }));
113
- if (error) {
114
- return error;
115
- }
116
- }
117
- const params = Object.assign(Object.assign({}, (pathParameters || {})), (queryStringParameters || {}));
118
- const res = yield next({
119
- params,
120
- event,
121
- body: (0, object_1.tryJsonParse)(event.body, event.body),
122
- userProfile,
123
- lang: (0, i18n_1.getValidatedLang)((_h = event.headers['x-lang']) !== null && _h !== void 0 ? _h : ''),
124
- });
125
- return res;
126
- });
127
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,42 +0,0 @@
1
- "use strict";
2
- const fs = require('fs');
3
- const process = require('process');
4
- const pathV = require('path');
5
- const cwd = process.cwd();
6
- const resolvePath = (p) => pathV.resolve(cwd, p);
7
- function run() {
8
- if (!fs.existsSync('./dist') || !fs.existsSync('./dist/api')) {
9
- console.log('no dist/api directory, cant run openapi postfix');
10
- return;
11
- }
12
- console.log('running openapi postfixes');
13
- const files = fs
14
- .readdirSync(resolvePath('./dist/api'))
15
- .filter((r) => r.endsWith('.js') || r.endsWith('.d.ts'))
16
- .map((s) => `./dist/api/${s}`)
17
- .filter(fs.existsSync)
18
- .map((file) => ({ file, content: fs.readFileSync(file).toString() }));
19
- let found = false;
20
- files.forEach(({ file, content }) => {
21
- if (content.includes('url_1')) {
22
- console.log('removing url_1 from ' + file);
23
- content = content.replace(/url_1\./gim, '');
24
- found = true;
25
- }
26
- if (content.includes('this.configuration.queryParamsStringify(')) {
27
- console.log('fixing queryparams default from ' + file);
28
- content = content.replace(/this.configuration.queryParamsStringify\(/gim, '(this.configuration.queryParamsStringify||querystring)(');
29
- found = true;
30
- }
31
- if (content.includes(`import("axios").`)) {
32
- console.log('fixing axios import from ' + file);
33
- content = content.replace(/import\("axios"\)\./gim, '');
34
- found = true;
35
- }
36
- fs.writeFileSync(file, content);
37
- });
38
- if (!found) {
39
- console.log('error: no files were fixed');
40
- }
41
- }
42
- run();
@@ -1 +0,0 @@
1
- export {};
@@ -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;