@sw-tsdk/plugin-connector 2.11.2-next.6 → 2.11.2-next.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -39
- package/lib/commands/action/add.d.ts +2 -2
- package/lib/commands/action/add.js +14 -8
- package/lib/commands/action/add.js.map +1 -1
- package/lib/commands/action/generate/data.d.ts +4 -4
- package/lib/commands/action/generate/data.js +23 -13
- package/lib/commands/action/generate/data.js.map +1 -1
- package/lib/commands/action/generate/input.d.ts +4 -4
- package/lib/commands/action/generate/input.js +19 -11
- package/lib/commands/action/generate/input.js.map +1 -1
- package/lib/commands/action/generate/output.d.ts +4 -4
- package/lib/commands/action/generate/output.js +19 -11
- package/lib/commands/action/generate/output.js.map +1 -1
- package/lib/commands/action/run/image.d.ts +9 -9
- package/lib/commands/action/run/image.js +39 -27
- package/lib/commands/action/run/image.js.map +1 -1
- package/lib/commands/action/run/local.d.ts +11 -11
- package/lib/commands/action/run/local.js +50 -34
- package/lib/commands/action/run/local.js.map +1 -1
- package/lib/commands/asset/add.d.ts +2 -2
- package/lib/commands/asset/add.js +12 -7
- package/lib/commands/asset/add.js.map +1 -1
- package/lib/commands/connector/build.d.ts +10 -10
- package/lib/commands/connector/build.js +37 -20
- package/lib/commands/connector/build.js.map +1 -1
- package/lib/commands/connector/create/openapi.d.ts +12 -11
- package/lib/commands/connector/create/openapi.js +128 -63
- package/lib/commands/connector/create/openapi.js.map +1 -1
- package/lib/commands/connector/create/source.d.ts +2 -2
- package/lib/commands/connector/create/source.js +12 -6
- package/lib/commands/connector/create/source.js.map +1 -1
- package/lib/commands/connector/create.d.ts +11 -10
- package/lib/commands/connector/create.js +46 -11
- package/lib/commands/connector/create.js.map +1 -1
- package/lib/commands/connector/logo.d.ts +2 -2
- package/lib/commands/connector/logo.js +10 -5
- package/lib/commands/connector/logo.js.map +1 -1
- package/lib/commands/connector/sign.d.ts +6 -6
- package/lib/commands/connector/sign.js +24 -13
- package/lib/commands/connector/sign.js.map +1 -1
- package/lib/commands/connector/update.d.ts +3 -3
- package/lib/commands/connector/update.js +14 -8
- package/lib/commands/connector/update.js.map +1 -1
- package/lib/commands/connector/validate.d.ts +4 -4
- package/lib/commands/connector/validate.js +22 -14
- package/lib/commands/connector/validate.js.map +1 -1
- package/lib/common.js +4 -0
- package/lib/common.js.map +1 -1
- package/lib/templates/assets/http_bearer.yaml +1 -2
- package/lib/types/connector-types.d.ts +3 -2
- package/oclif.manifest.json +1014 -1
- package/package.json +15 -15
|
@@ -34,13 +34,13 @@ class Build extends core_2.Base {
|
|
|
34
34
|
try {
|
|
35
35
|
await node_fs_1.promises.access(directory);
|
|
36
36
|
}
|
|
37
|
-
catch
|
|
37
|
+
catch {
|
|
38
38
|
this.error(`Could not access ${directory}`);
|
|
39
39
|
}
|
|
40
40
|
const docker = new docker_1.Docker();
|
|
41
|
-
core_1.
|
|
41
|
+
core_1.ux.action.start('Checking for docker...');
|
|
42
42
|
await docker.ping();
|
|
43
|
-
core_1.
|
|
43
|
+
core_1.ux.action.stop();
|
|
44
44
|
const dockerFileDir = `${directory}/Dockerfile`;
|
|
45
45
|
if ((0, node_fs_1.existsSync)(dockerFileDir)) {
|
|
46
46
|
await node_fs_1.promises.rm(dockerFileDir);
|
|
@@ -86,48 +86,65 @@ class Build extends core_2.Base {
|
|
|
86
86
|
}
|
|
87
87
|
exports.Build = Build;
|
|
88
88
|
Build.description = 'Builds a local docker image of the connector.';
|
|
89
|
-
Build.flags =
|
|
89
|
+
Build.flags = {
|
|
90
|
+
...core_2.Base.flags,
|
|
91
|
+
template: core_1.Flags.string({
|
|
90
92
|
description: 'connector language',
|
|
91
|
-
options: ['python_37_swimlane', 'node_18', 'python_39_definition', 'python_310_definition', 'python_311_definition'],
|
|
93
|
+
options: ['python_37_swimlane', 'node_18', 'node_20', 'python_39_definition', 'python_39_turbine', 'python_310_definition', 'python_311_definition'],
|
|
92
94
|
required: false,
|
|
93
|
-
}),
|
|
95
|
+
}),
|
|
96
|
+
'compile-override': core_1.Flags.string({
|
|
94
97
|
hidden: true,
|
|
95
98
|
default: 'Compile.Dockerfile',
|
|
96
|
-
}),
|
|
99
|
+
}),
|
|
100
|
+
'runner-override': core_1.Flags.string({
|
|
97
101
|
hidden: true,
|
|
98
102
|
default: 'Runner.Dockerfile',
|
|
99
|
-
}),
|
|
103
|
+
}),
|
|
104
|
+
'runtime-override': core_1.Flags.string({
|
|
100
105
|
hidden: true,
|
|
101
|
-
}),
|
|
106
|
+
}),
|
|
107
|
+
directory: core_1.Flags.string({
|
|
102
108
|
char: 'd',
|
|
103
109
|
description: 'root directory of the repository.',
|
|
104
110
|
default: './',
|
|
105
|
-
}),
|
|
111
|
+
}),
|
|
112
|
+
save: core_1.Flags.boolean({
|
|
106
113
|
description: 'saves a signed docker image as tar in local directory.',
|
|
107
|
-
}),
|
|
114
|
+
}),
|
|
115
|
+
squash: core_1.Flags.boolean({
|
|
108
116
|
description: 'squashes the docker layers.',
|
|
109
117
|
hidden: true,
|
|
110
|
-
}),
|
|
118
|
+
}),
|
|
119
|
+
'force-rebuild': core_1.Flags.boolean({
|
|
111
120
|
char: 'f',
|
|
112
121
|
description: 'forces nocache on the image build',
|
|
113
|
-
}),
|
|
122
|
+
}),
|
|
123
|
+
platform: core_1.Flags.string({
|
|
114
124
|
hidden: true,
|
|
115
125
|
default: 'linux/amd64',
|
|
116
|
-
}),
|
|
126
|
+
}),
|
|
127
|
+
'signing-password': core_1.Flags.string({
|
|
117
128
|
description: 'password used for the private key (ENV: TURBINE_SIGNING_PASSWORD)',
|
|
118
129
|
default: '',
|
|
119
130
|
env: 'TURBINE_SIGNING_PASSWORD',
|
|
120
|
-
}),
|
|
131
|
+
}),
|
|
132
|
+
'key-name': core_1.Flags.string({
|
|
121
133
|
description: 'name used for the key (default: username_yyyy-MM-dd)',
|
|
122
|
-
}),
|
|
134
|
+
}),
|
|
135
|
+
'skip-upload': core_1.Flags.boolean({
|
|
123
136
|
hidden: true,
|
|
124
|
-
}),
|
|
137
|
+
}),
|
|
138
|
+
registry: core_1.Flags.string({
|
|
125
139
|
description: 'registry to use for signing',
|
|
126
140
|
default: 'localhost:5000',
|
|
127
|
-
}),
|
|
141
|
+
}),
|
|
142
|
+
output: core_1.Flags.string({
|
|
128
143
|
char: 'o',
|
|
129
144
|
description: 'output path to where to store the image.',
|
|
130
|
-
}),
|
|
145
|
+
}),
|
|
146
|
+
help: core_1.Flags.help({
|
|
131
147
|
char: 'h',
|
|
132
|
-
})
|
|
148
|
+
}),
|
|
149
|
+
};
|
|
133
150
|
//# sourceMappingURL=build.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../../src/commands/connector/build.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../../src/commands/connector/build.ts"],"names":[],"mappings":";;;;AAAA,sCAAqC;AACrC,wCAAkC;AAClC,yCAAuC;AACvC,qCAAyD;AACzD,kDAAiD;AACjD,iCAA2B;AAC3B,4CAAsC;AACtC,6DAAyC;AACzC,uCAAkC;AAClC,+CAAwC;AACxC,wGAA6D;AAE7D,qCAAqC;AACrC,MAAa,KAAM,SAAQ,WAAI;IAiE7B,KAAK,CAAC,GAAG;QACP,MAAM,EAAC,KAAK,EAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAEvC,IAAI,EAAC,SAAS,EAAC,GAAG,KAAK,CAAA;QACvB,MAAM,EACJ,IAAI,EACJ,QAAQ,EACR,kBAAkB,EAAE,eAAe,EACnC,iBAAiB,EAAE,cAAc,EACjC,kBAAkB,EAAE,eAAe,EACnC,eAAe,EAAE,OAAO,EACxB,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,MAAM,GAEP,GAAG,KAAK,CAAA;QAET,IAAI,EACF,kBAAkB,EAAE,eAAe,EACnC,UAAU,EAAE,OAAO,GACpB,GAAG,KAAK,CAAA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CAAC;QAClB,WAAW,EAAE,wDAAwD;KACtE,CAAC;IACF,MAAM,EAAE,YAAK,CAAC,OAAO,CAAC;QACpB,WAAW,EAAE,6BAA6B;QAC1C,MAAM,EAAE,IAAI;KACb,CAAC;IACF,eAAe,EAAE,YAAK,CAAC,OAAO,CAAC;QAC7B,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,mCAAmC;KACjD,CAAC;IACF,QAAQ,EAAE,YAAK,CAAC,MAAM,CAAC;QACrB,MAAM,EAAE,IAAI;QACZ,OAAO,EAAE,aAAa;KACvB,CAAC;IACF,kBAAkB,EAAE,YAAK,CAAC,MAAM,CAAC;QAC/B,WAAW,EAAE,mEAAmE;QAChF,OAAO,EAAE,EAAE;QACX,GAAG,EAAE,0BAA0B;KAChC,CAAC;IACF,UAAU,EAAE,YAAK,CAAC,MAAM,CAAC;QACvB,WAAW,EAAE,sDAAsD;KACpE,CAAC;IACF,aAAa,EAAE,YAAK,CAAC,OAAO,CAAC;QAC3B,MAAM,EAAE,IAAI;KACb,CAAC;IACF,QAAQ,EAAE,YAAK,CAAC,MAAM,CAAC;QACrB,WAAW,EAAE,6BAA6B;QAC1C,OAAO,EAAE,gBAAgB;KAC1B,CAAC;IACF,MAAM,EAAE,YAAK,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,0CAA0C;KACxD,CAAC;IACF,IAAI,EAAE,YAAK,CAAC,IAAI,CAAC;QACf,IAAI,EAAE,GAAG;KACV,CAAC;CACH,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Base } from '@sw-tsdk/core';
|
|
2
|
-
import { Action,
|
|
2
|
+
import { Action, InnerProperty, Input, Output, Property } from '@sw-tsdk/connector';
|
|
3
3
|
export declare class OpenAPI extends Base {
|
|
4
4
|
static description: string;
|
|
5
5
|
defaultTemplate: string;
|
|
@@ -8,16 +8,16 @@ export declare class OpenAPI extends Base {
|
|
|
8
8
|
currentContext: any;
|
|
9
9
|
referenceMapped: string[];
|
|
10
10
|
static flags: {
|
|
11
|
-
directory: import("@oclif/core/lib/interfaces").OptionFlag<string>;
|
|
12
|
-
vendor: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
13
|
-
product: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
14
|
-
keywords: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
15
|
-
description: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
16
|
-
logoPath: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
17
|
-
author: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
18
|
-
authorEmail: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
19
|
-
homepage: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
20
|
-
specs: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
11
|
+
directory: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
12
|
+
vendor: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
13
|
+
product: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
14
|
+
keywords: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
15
|
+
description: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
16
|
+
logoPath: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
17
|
+
author: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
18
|
+
authorEmail: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
19
|
+
homepage: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
20
|
+
specs: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
21
21
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
22
22
|
};
|
|
23
23
|
run(): Promise<void>;
|
|
@@ -43,4 +43,5 @@ export declare class OpenAPI extends Base {
|
|
|
43
43
|
generateJsonSchema(data: any, io: Output | Input): Promise<Output | Input>;
|
|
44
44
|
generateAttachmentSchema(data: any, io: Input | Output): Promise<Input | Output>;
|
|
45
45
|
getDataBody(data: any): Promise<any>;
|
|
46
|
+
private buildRequired;
|
|
46
47
|
}
|
|
@@ -4,7 +4,7 @@ exports.OpenAPI = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
/* eslint-disable camelcase */
|
|
6
6
|
const core_1 = require("@oclif/core");
|
|
7
|
-
const node_path_1 =
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
8
|
const core_2 = require("@sw-tsdk/core");
|
|
9
9
|
const fs_extra_1 = require("fs-extra");
|
|
10
10
|
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
@@ -14,6 +14,7 @@ const fs = tslib_1.__importStar(require("node:fs"));
|
|
|
14
14
|
const common_1 = require("../../../common");
|
|
15
15
|
const connector_1 = require("@sw-tsdk/connector");
|
|
16
16
|
const json_schema_ref_parser_1 = tslib_1.__importDefault(require("@apidevtools/json-schema-ref-parser"));
|
|
17
|
+
const snake_case_1 = require("snake-case");
|
|
17
18
|
class OpenAPI extends core_2.Base {
|
|
18
19
|
constructor() {
|
|
19
20
|
super(...arguments);
|
|
@@ -21,16 +22,14 @@ class OpenAPI extends core_2.Base {
|
|
|
21
22
|
this.codeRegex = /^2\d{2}$/;
|
|
22
23
|
}
|
|
23
24
|
async run() {
|
|
24
|
-
var _a;
|
|
25
25
|
const { flags } = await this.parse(OpenAPI);
|
|
26
|
-
const {
|
|
26
|
+
const { specs } = flags;
|
|
27
27
|
if (!specs) {
|
|
28
|
-
|
|
28
|
+
throw new Error('OpenAPI Specs are required');
|
|
29
29
|
}
|
|
30
30
|
if (!(await (0, core_2.fileExists)(specs))) {
|
|
31
|
-
core_1.
|
|
31
|
+
core_1.ux.error('OpenAPI Specs does not exist');
|
|
32
32
|
}
|
|
33
|
-
const name = node_path_1.default.basename(specs).replace(/\.[^./]+$/, '');
|
|
34
33
|
const masterQuestions = [
|
|
35
34
|
{
|
|
36
35
|
type: 'input',
|
|
@@ -79,7 +78,19 @@ class OpenAPI extends core_2.Base {
|
|
|
79
78
|
];
|
|
80
79
|
const filteredQuestions = masterQuestions.filter(q => !flags[q.name]);
|
|
81
80
|
const answers = Object.assign(await inquirer_1.default.prompt(filteredQuestions), flags);
|
|
82
|
-
const
|
|
81
|
+
const vendor = answers.vendor;
|
|
82
|
+
const product = answers.product;
|
|
83
|
+
let name;
|
|
84
|
+
if (vendor.toLowerCase() === product.toLowerCase() || !product) {
|
|
85
|
+
name = answers.vendor.toLowerCase();
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const string = `${answers.vendor} ${answers.product}`;
|
|
89
|
+
name = (0, snake_case_1.snakeCase)(string.toLocaleLowerCase());
|
|
90
|
+
}
|
|
91
|
+
let { directory } = flags;
|
|
92
|
+
directory = (0, node_path_1.resolve)(directory || process.cwd());
|
|
93
|
+
const connectorDirectory = (0, node_path_1.basename)(directory) === `t_${name}` ? directory : (0, node_path_1.join)(directory, `t_${name}`);
|
|
83
94
|
await (0, fs_extra_1.ensureDir)(connectorDirectory);
|
|
84
95
|
const connector = {
|
|
85
96
|
vendor: answers.vendor,
|
|
@@ -112,9 +123,11 @@ class OpenAPI extends core_2.Base {
|
|
|
112
123
|
},
|
|
113
124
|
},
|
|
114
125
|
};
|
|
115
|
-
core_1.
|
|
126
|
+
core_1.ux.action.start('Generating data.');
|
|
116
127
|
const connectorFolder = (0, node_path_1.join)(connectorDirectory, 'connector');
|
|
117
128
|
await (0, fs_extra_1.ensureDir)(connectorFolder);
|
|
129
|
+
const docsFolder = (0, node_path_1.join)(connectorDirectory, 'docs');
|
|
130
|
+
await (0, fs_extra_1.ensureDir)(docsFolder);
|
|
118
131
|
const configFolder = (0, node_path_1.join)(connectorFolder, 'config');
|
|
119
132
|
await (0, fs_extra_1.ensureDir)(configFolder);
|
|
120
133
|
const assetsFolder = (0, node_path_1.join)(configFolder, 'assets');
|
|
@@ -123,29 +136,35 @@ class OpenAPI extends core_2.Base {
|
|
|
123
136
|
await (0, fs_extra_1.ensureDir)(actionsFolder);
|
|
124
137
|
const codeFolder = (0, node_path_1.join)(connectorFolder, 'code');
|
|
125
138
|
await (0, fs_extra_1.ensureDir)(codeFolder);
|
|
126
|
-
|
|
139
|
+
await (0, fs_extra_1.copy)((0, node_path_1.join)(__dirname, '..', '..', '..', 'templates', 'python_311_definition', 'template', 'docs'), docsFolder);
|
|
140
|
+
let spec = js_yaml_1.default.load(await fs.promises.readFile(specs, 'utf8'));
|
|
127
141
|
if (JSON.stringify(spec).includes('$ref')) {
|
|
128
142
|
spec = await json_schema_ref_parser_1.default.dereference(spec);
|
|
129
143
|
}
|
|
130
144
|
this.specData = spec;
|
|
131
|
-
if (
|
|
145
|
+
if (spec?.components?.securitySchemes && Object.keys(spec.components.securitySchemes).length > 0) {
|
|
132
146
|
await this.createAssets(spec.components.securitySchemes, assetsFolder);
|
|
133
147
|
}
|
|
134
148
|
let basePath = '/';
|
|
135
|
-
if (
|
|
136
|
-
const
|
|
137
|
-
basePath
|
|
149
|
+
if (spec?.servers && spec?.servers.length > 0) {
|
|
150
|
+
const serverUrl = spec.servers[0].url;
|
|
151
|
+
if (serverUrl !== basePath) {
|
|
152
|
+
const url = new URL(serverUrl);
|
|
153
|
+
basePath = url.pathname;
|
|
154
|
+
}
|
|
138
155
|
}
|
|
139
156
|
await this.createActionsFromPaths(spec.paths, actionsFolder, basePath);
|
|
140
157
|
// write connector.yaml from answers
|
|
141
158
|
const connectorFilePath = (0, node_path_1.join)(connectorDirectory, 'connector', 'connector.yaml');
|
|
142
159
|
await (0, fs_extra_1.writeFile)(connectorFilePath, js_yaml_1.default.dump(connector));
|
|
160
|
+
await (0, fs_extra_1.writeFile)((0, node_path_1.join)(connectorDirectory, 'requirements.txt'), '');
|
|
143
161
|
await (0, fs_extra_1.remove)((0, node_path_1.join)(connectorDirectory, 'README.md'));
|
|
144
162
|
await (0, fs_extra_1.symlink)((0, node_path_1.join)(connectorDirectory, 'docs', 'README.md'), (0, node_path_1.join)(connectorDirectory, 'README.md'));
|
|
145
163
|
}
|
|
146
164
|
async createActionsFromPaths(paths, actionFolder, basePath, index = 0) {
|
|
147
165
|
const pathsKeys = Object.keys(paths);
|
|
148
|
-
const action =
|
|
166
|
+
// const action = paths[pathsKeys[index]]
|
|
167
|
+
const action = (0, connector_1.removeCirculars)(paths[pathsKeys[index]]);
|
|
149
168
|
await this.buildActions(action, actionFolder, pathsKeys[index], basePath);
|
|
150
169
|
if (index < pathsKeys.length - 1) {
|
|
151
170
|
return this.createActionsFromPaths(paths, actionFolder, basePath, index + 1);
|
|
@@ -165,11 +184,22 @@ class OpenAPI extends core_2.Base {
|
|
|
165
184
|
}
|
|
166
185
|
}
|
|
167
186
|
async createActionData(action, endpoint, method) {
|
|
168
|
-
const actionWords = action.operationId
|
|
169
|
-
|
|
187
|
+
const actionWords = action.operationId?.split(/(?=[A-Z])/) ??
|
|
188
|
+
endpoint.split('/')
|
|
189
|
+
.map(x => x.replace(/{([^}]*)}/, 'by_$1'))
|
|
190
|
+
.filter(Boolean);
|
|
191
|
+
let name = actionWords
|
|
170
192
|
.map((item) => item.toLowerCase())
|
|
171
193
|
.join('_');
|
|
172
|
-
|
|
194
|
+
if (name.length > 50) {
|
|
195
|
+
core_1.ux.warn(`Truncated name: ${name}`);
|
|
196
|
+
name = name.slice(0, 50);
|
|
197
|
+
}
|
|
198
|
+
let title = actionWords.join(' ');
|
|
199
|
+
if (title.length > 50) {
|
|
200
|
+
core_1.ux.warn(`Truncated name: ${name}`);
|
|
201
|
+
title = title.slice(0, 50);
|
|
202
|
+
}
|
|
173
203
|
const builtAction = {
|
|
174
204
|
schema: 'action/1',
|
|
175
205
|
title,
|
|
@@ -185,7 +215,6 @@ class OpenAPI extends core_2.Base {
|
|
|
185
215
|
return builtAction;
|
|
186
216
|
}
|
|
187
217
|
async createInputs(action) {
|
|
188
|
-
var _a;
|
|
189
218
|
let input = {
|
|
190
219
|
type: 'object',
|
|
191
220
|
properties: {},
|
|
@@ -196,31 +225,34 @@ class OpenAPI extends core_2.Base {
|
|
|
196
225
|
title: 'Headers',
|
|
197
226
|
type: 'object',
|
|
198
227
|
properties: await this.buildInnerObject(headers, {}),
|
|
199
|
-
required: headers
|
|
228
|
+
required: headers?.required,
|
|
200
229
|
} : null;
|
|
230
|
+
this.buildRequired(input.properties.headers);
|
|
201
231
|
const parameters = await this.getInnerData(action.parameters, 'query', 'in');
|
|
202
232
|
parameters ? (input.properties.parameters = {
|
|
203
233
|
title: 'Parameters',
|
|
204
234
|
type: 'object',
|
|
205
235
|
properties: await this.buildInnerObject(parameters, {}),
|
|
206
|
-
required: parameters
|
|
236
|
+
required: parameters?.required,
|
|
207
237
|
}) : null;
|
|
238
|
+
this.buildRequired(input.properties.parameters);
|
|
208
239
|
const pathParameters = await this.getInnerData(action.parameters, 'path', 'in');
|
|
209
240
|
pathParameters ? (input.properties.path_parameters = {
|
|
210
241
|
title: 'Path Parameters',
|
|
211
242
|
type: 'object',
|
|
212
243
|
properties: await this.buildInnerObject(pathParameters, {}),
|
|
213
|
-
required: pathParameters
|
|
244
|
+
required: pathParameters?.required,
|
|
214
245
|
}) : null;
|
|
215
246
|
}
|
|
216
|
-
|
|
247
|
+
this.buildRequired(input.properties.path_parameters);
|
|
248
|
+
if (action?.requestBody?.content) {
|
|
217
249
|
const dataBody = await this.getDataBody(action.requestBody.content);
|
|
218
250
|
dataBody ?
|
|
219
251
|
(input.properties.data_body = {
|
|
220
252
|
title: 'Data Body',
|
|
221
253
|
type: 'object',
|
|
222
254
|
properties: await this.buildInnerObject(dataBody, {}),
|
|
223
|
-
required: dataBody
|
|
255
|
+
required: dataBody?.required,
|
|
224
256
|
}) : null;
|
|
225
257
|
input = await this.generateAttachmentSchema(action.requestBody.content, input);
|
|
226
258
|
input = await this.generateJsonSchema(action.requestBody.content, input);
|
|
@@ -228,7 +260,6 @@ class OpenAPI extends core_2.Base {
|
|
|
228
260
|
return input;
|
|
229
261
|
}
|
|
230
262
|
async createOutput(action) {
|
|
231
|
-
var _a;
|
|
232
263
|
const { data, code } = this.getStatusCodeObject(action.responses);
|
|
233
264
|
let output = {
|
|
234
265
|
type: 'object',
|
|
@@ -249,16 +280,16 @@ class OpenAPI extends core_2.Base {
|
|
|
249
280
|
title: 'Response headers',
|
|
250
281
|
type: 'object',
|
|
251
282
|
properties: await this.buildInnerObject(this.formatData(data.headers), {}),
|
|
252
|
-
required:
|
|
283
|
+
required: data.headers?.required,
|
|
253
284
|
examples: data.headers.examples,
|
|
254
285
|
} : null;
|
|
255
|
-
if (data
|
|
286
|
+
if (data?.content) {
|
|
256
287
|
const dataBody = await this.getDataBody(data.content);
|
|
257
288
|
dataBody ? (output.properties.data = {
|
|
258
289
|
title: 'Data Body',
|
|
259
290
|
type: 'object',
|
|
260
291
|
properties: await this.buildInnerObject(dataBody, {}),
|
|
261
|
-
required: dataBody
|
|
292
|
+
required: dataBody?.required,
|
|
262
293
|
}) : null;
|
|
263
294
|
const text = await this.getInnerData(data.content, 'text/plain', 'content');
|
|
264
295
|
text ? (output.properties.response_text = {
|
|
@@ -289,7 +320,7 @@ class OpenAPI extends core_2.Base {
|
|
|
289
320
|
return this.filterByList(allowed, object);
|
|
290
321
|
}
|
|
291
322
|
if (type === 'in') {
|
|
292
|
-
const allowed = Object.keys(object).filter(key =>
|
|
323
|
+
const allowed = Object.keys(object).filter(key => object[key]?.in === path);
|
|
293
324
|
return this.filterByList(allowed, object);
|
|
294
325
|
}
|
|
295
326
|
return null;
|
|
@@ -302,7 +333,7 @@ class OpenAPI extends core_2.Base {
|
|
|
302
333
|
return list;
|
|
303
334
|
}
|
|
304
335
|
filterByList(list, object) {
|
|
305
|
-
if (
|
|
336
|
+
if (list?.length > 0) {
|
|
306
337
|
return list.map((key) => {
|
|
307
338
|
return object[key];
|
|
308
339
|
});
|
|
@@ -310,28 +341,29 @@ class OpenAPI extends core_2.Base {
|
|
|
310
341
|
return null;
|
|
311
342
|
}
|
|
312
343
|
async buildObject(object, key) {
|
|
313
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
314
344
|
const currentObject = {
|
|
315
|
-
title:
|
|
316
|
-
type:
|
|
345
|
+
title: object?.name || key,
|
|
346
|
+
type: object?.schema?.type || object?.type,
|
|
317
347
|
};
|
|
318
|
-
|
|
319
|
-
if ((
|
|
348
|
+
object?.required ? currentObject.required = object?.required : null;
|
|
349
|
+
if ((object?.schema?.type === 'object' || object?.type === 'object') && object?.properties) {
|
|
320
350
|
currentObject.properties = await this.buildInnerObject(object, {});
|
|
321
351
|
}
|
|
322
|
-
if (
|
|
323
|
-
|
|
324
|
-
|
|
352
|
+
if (object?.schema?.type === 'array' || object?.type === 'array') {
|
|
353
|
+
const innerItem = object?.schema?.items || object?.items;
|
|
354
|
+
currentObject.items = await this.buildItems(innerItem);
|
|
355
|
+
const required = object?.schema?.items?.required || object?.items?.required;
|
|
325
356
|
required ? currentObject.items.required = required : null;
|
|
326
357
|
}
|
|
327
358
|
return currentObject;
|
|
328
359
|
}
|
|
329
360
|
async buildItems(items) {
|
|
330
|
-
if (
|
|
331
|
-
|
|
361
|
+
if (items?.type === 'object' && items?.properties) {
|
|
362
|
+
const innerItems = await this.buildInnerObject(items, {});
|
|
363
|
+
return { type: 'object', properties: innerItems };
|
|
332
364
|
}
|
|
333
365
|
return {
|
|
334
|
-
type: items
|
|
366
|
+
type: items?.type,
|
|
335
367
|
};
|
|
336
368
|
}
|
|
337
369
|
getStatusCodeObject(response) {
|
|
@@ -349,17 +381,18 @@ class OpenAPI extends core_2.Base {
|
|
|
349
381
|
return currentContext;
|
|
350
382
|
}
|
|
351
383
|
async buildInnerObject(object, currentObject, index = 0) {
|
|
352
|
-
|
|
353
|
-
const properties = Object.keys((object === null || object === void 0 ? void 0 : object.properties) || object);
|
|
384
|
+
const properties = Object.keys(object?.properties || object);
|
|
354
385
|
const currentProperty = properties[index];
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
386
|
+
if (properties.length > 0) {
|
|
387
|
+
currentObject[object?.properties ? currentProperty : object[currentProperty].name] = await this.buildObject(object?.properties?.[currentProperty] || object[currentProperty], currentProperty);
|
|
388
|
+
if (index < properties.length - 1) {
|
|
389
|
+
return this.buildInnerObject(object, currentObject, index + 1);
|
|
390
|
+
}
|
|
358
391
|
}
|
|
359
392
|
return currentObject;
|
|
360
393
|
}
|
|
361
394
|
existReferences(object, found = [], index = 0) {
|
|
362
|
-
const keys =
|
|
395
|
+
const keys = object?.items ? Object.keys(object.items) : Object.keys(object);
|
|
363
396
|
if (keys.length === 0) {
|
|
364
397
|
return found;
|
|
365
398
|
}
|
|
@@ -370,7 +403,7 @@ class OpenAPI extends core_2.Base {
|
|
|
370
403
|
!found.includes(currentObject)) {
|
|
371
404
|
found.push(currentObject);
|
|
372
405
|
}
|
|
373
|
-
if (
|
|
406
|
+
if (currentObject?.type === 'object' || currentObject?.type === 'array') {
|
|
374
407
|
found = this.existReferences(currentObject.properties || currentObject.items || currentObject.additionalProperties, found);
|
|
375
408
|
}
|
|
376
409
|
if (!currentObject.type && currentObject.$ref) {
|
|
@@ -387,38 +420,40 @@ class OpenAPI extends core_2.Base {
|
|
|
387
420
|
const currentScheme = securitySchemes[currentKey];
|
|
388
421
|
const schemaType = securitySchemes[currentKey].type;
|
|
389
422
|
switch (schemaType) {
|
|
390
|
-
case 'http':
|
|
423
|
+
case 'http': {
|
|
391
424
|
currentKey = securitySchemes[currentKey].scheme === 'basic' ?
|
|
392
425
|
connector_1.SecuritySchemeEnum.basicAuth : connector_1.SecuritySchemeEnum.bearerAuth;
|
|
393
426
|
break;
|
|
394
|
-
|
|
427
|
+
}
|
|
428
|
+
case 'oauth2': {
|
|
395
429
|
currentKey = currentScheme.flows.clientCredentials ?
|
|
396
430
|
connector_1.SecuritySchemeEnum.oAuth2ClientCredentials :
|
|
397
431
|
connector_1.SecuritySchemeEnum.oAuth2Password;
|
|
398
432
|
break;
|
|
399
|
-
|
|
433
|
+
}
|
|
434
|
+
case 'apiKey': {
|
|
400
435
|
currentKey = connector_1.SecuritySchemeEnum.ApiKeyAuth;
|
|
401
436
|
break;
|
|
437
|
+
}
|
|
402
438
|
}
|
|
403
|
-
await (0, fs_extra_1.copy)((0, node_path_1.join)(__dirname, '..', '..', '..', 'templates', 'assets', `${currentKey}.yaml`), (0, node_path_1.join)(assetFolder, `${currentKey}.yaml`)
|
|
439
|
+
await (0, fs_extra_1.copy)((0, node_path_1.join)(__dirname, '..', '..', '..', 'templates', 'assets', `${currentKey}.yaml`), (0, node_path_1.join)(assetFolder, `${currentKey}.yaml`));
|
|
404
440
|
if (keys.length - 1 > index) {
|
|
405
441
|
return this.createAssets(securitySchemes, assetFolder, index + 1);
|
|
406
442
|
}
|
|
407
443
|
}
|
|
408
444
|
async generateJsonSchema(data, io) {
|
|
409
|
-
|
|
410
|
-
let jsonData = await this.getInnerData((data === null || data === void 0 ? void 0 : data.content) || data, 'application/json', 'content');
|
|
445
|
+
let jsonData = await this.getInnerData(data?.content || data, 'application/json', 'content');
|
|
411
446
|
if (!jsonData) {
|
|
412
|
-
jsonData = await this.getInnerData(
|
|
447
|
+
jsonData = await this.getInnerData(data?.content || data, '*/*', 'content');
|
|
413
448
|
}
|
|
414
449
|
jsonData ? io.properties.json_body = {
|
|
415
450
|
title: 'Json Body',
|
|
416
|
-
type: jsonData
|
|
417
|
-
required: jsonData
|
|
451
|
+
type: jsonData?.type,
|
|
452
|
+
required: jsonData?.required,
|
|
418
453
|
} : null;
|
|
419
454
|
if (jsonData && !jsonData.$ref) {
|
|
420
|
-
|
|
421
|
-
(
|
|
455
|
+
io?.properties?.json_body ?
|
|
456
|
+
(jsonData?.type === 'object' ?
|
|
422
457
|
io.properties.json_body.properties = await this.buildInnerObject(jsonData, {}) :
|
|
423
458
|
io.properties.json_body.items = await this.buildItems(jsonData.items)) : null;
|
|
424
459
|
}
|
|
@@ -435,7 +470,7 @@ class OpenAPI extends core_2.Base {
|
|
|
435
470
|
additionalProperties: false,
|
|
436
471
|
properties: await this.buildInnerObject(attachments, {}),
|
|
437
472
|
},
|
|
438
|
-
required: attachments
|
|
473
|
+
required: attachments?.required,
|
|
439
474
|
} : null;
|
|
440
475
|
return io;
|
|
441
476
|
}
|
|
@@ -443,15 +478,45 @@ class OpenAPI extends core_2.Base {
|
|
|
443
478
|
const exclude = ['application/json', 'multipart/form-data'];
|
|
444
479
|
return this.getInnerData(data, exclude, 'content');
|
|
445
480
|
}
|
|
481
|
+
buildRequired(item, subitem) {
|
|
482
|
+
if (!item) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
for (const [key, value] of Object.entries(item)) {
|
|
486
|
+
if (value?.required === true && subitem) {
|
|
487
|
+
if (!Array.isArray(subitem.required)) {
|
|
488
|
+
subitem.required = [];
|
|
489
|
+
}
|
|
490
|
+
subitem.required.push(key);
|
|
491
|
+
delete value.required;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (item.properties) {
|
|
495
|
+
this.buildRequired(item.properties, item);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
446
498
|
}
|
|
447
499
|
exports.OpenAPI = OpenAPI;
|
|
448
500
|
OpenAPI.description = 'Scaffold a new connector';
|
|
449
|
-
OpenAPI.flags =
|
|
501
|
+
OpenAPI.flags = {
|
|
502
|
+
...core_2.Base.flags,
|
|
503
|
+
directory: core_1.Flags.string({
|
|
450
504
|
char: 'd',
|
|
451
505
|
description: 'root directory for where to store connectors, the connector directory will be generated.',
|
|
452
506
|
default: './',
|
|
453
|
-
}),
|
|
507
|
+
}),
|
|
508
|
+
vendor: core_1.Flags.string({ description: 'Vendor (e.g. CrowdStrike)' }),
|
|
509
|
+
product: core_1.Flags.string({ description: 'Product (e.g. Falcon)' }),
|
|
510
|
+
keywords: core_1.Flags.string({ char: 'k', description: 'Please enter keyword (Comma-Separated)' }),
|
|
511
|
+
description: core_1.Flags.string({ description: 'Description (e.g. CrowdStrike Host Query API)' }),
|
|
512
|
+
logoPath: core_1.Flags.string({ description: 'URL or absolute path to logo file' }),
|
|
513
|
+
author: core_1.Flags.string({ description: 'Connector Author' }),
|
|
514
|
+
authorEmail: core_1.Flags.string({ description: 'Connector Author Email' }),
|
|
515
|
+
homepage: core_1.Flags.string({ description: 'Connector Author Support URL' }),
|
|
516
|
+
specs: core_1.Flags.string({
|
|
454
517
|
char: 'o',
|
|
455
|
-
description: '
|
|
456
|
-
}),
|
|
518
|
+
description: 'path to the spec file',
|
|
519
|
+
}),
|
|
520
|
+
help: core_1.Flags.help({ char: 'h' }),
|
|
521
|
+
};
|
|
457
522
|
//# sourceMappingURL=openapi.js.map
|