@apimatic/cli 0.0.0-alpha.2
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 +258 -0
- package/bin/run +5 -0
- package/bin/run.cmd +3 -0
- package/lib/client-utils/auth-manager.d.ts +17 -0
- package/lib/client-utils/auth-manager.js +33 -0
- package/lib/client-utils/sdk-client.d.ts +23 -0
- package/lib/client-utils/sdk-client.js +119 -0
- package/lib/commands/api/transform.d.ts +14 -0
- package/lib/commands/api/transform.js +105 -0
- package/lib/commands/api/validate.d.ts +11 -0
- package/lib/commands/api/validate.js +64 -0
- package/lib/commands/auth/login.d.ts +9 -0
- package/lib/commands/auth/login.js +60 -0
- package/lib/commands/auth/logout.d.ts +6 -0
- package/lib/commands/auth/logout.js +23 -0
- package/lib/commands/auth/status.d.ts +6 -0
- package/lib/commands/auth/status.js +23 -0
- package/lib/commands/portal/generate.d.ts +13 -0
- package/lib/commands/portal/generate.js +102 -0
- package/lib/commands/sdk/generate.d.ts +15 -0
- package/lib/commands/sdk/generate.js +129 -0
- package/lib/config/env.d.ts +1 -0
- package/lib/config/env.js +4 -0
- package/lib/controllers/api/transform.d.ts +7 -0
- package/lib/controllers/api/transform.js +59 -0
- package/lib/controllers/api/validate.d.ts +5 -0
- package/lib/controllers/api/validate.js +32 -0
- package/lib/controllers/portal/generate.d.ts +2 -0
- package/lib/controllers/portal/generate.js +49 -0
- package/lib/controllers/sdk/generate.d.ts +4 -0
- package/lib/controllers/sdk/generate.js +64 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -0
- package/lib/types/api/transform.d.ts +34 -0
- package/lib/types/api/transform.js +18 -0
- package/lib/types/api/validate.d.ts +12 -0
- package/lib/types/api/validate.js +2 -0
- package/lib/types/portal/generate.d.ts +9 -0
- package/lib/types/portal/generate.js +2 -0
- package/lib/types/sdk/generate.d.ts +22 -0
- package/lib/types/sdk/generate.js +12 -0
- package/lib/utils/utils.d.ts +18 -0
- package/lib/utils/utils.js +107 -0
- package/oclif.manifest.json +1 -0
- package/package.json +107 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const command_1 = require("@oclif/command");
|
|
4
|
+
const cli_ux_1 = require("cli-ux");
|
|
5
|
+
const sdk_client_1 = require("../../client-utils/sdk-client");
|
|
6
|
+
const utils_1 = require("../../utils/utils");
|
|
7
|
+
class Login extends command_1.Command {
|
|
8
|
+
async run() {
|
|
9
|
+
const { flags } = this.parse(Login);
|
|
10
|
+
const configDir = this.config.configDir;
|
|
11
|
+
try {
|
|
12
|
+
const client = sdk_client_1.SDKClient.getInstance();
|
|
13
|
+
// If user is setting auth key
|
|
14
|
+
if (flags["auth-key"]) {
|
|
15
|
+
const response = client.setAuthKey(flags["auth-key"], configDir);
|
|
16
|
+
return this.log(response);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
// If user logs in with email and password
|
|
20
|
+
const email = await cli_ux_1.cli.prompt("Please enter your registered email");
|
|
21
|
+
const password = await cli_ux_1.cli.prompt("Please enter your password", {
|
|
22
|
+
type: "hide"
|
|
23
|
+
});
|
|
24
|
+
const response = await client.login(email, password, configDir);
|
|
25
|
+
this.log(response);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (error && error.response) {
|
|
30
|
+
const apiError = error;
|
|
31
|
+
const apiResponse = apiError.response;
|
|
32
|
+
if (apiResponse) {
|
|
33
|
+
const responseData = apiResponse.data;
|
|
34
|
+
if (apiResponse.status === 403 && responseData) {
|
|
35
|
+
return this.error(utils_1.replaceHTML(responseData));
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return this.error(apiError.message);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
this.error(error.message);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.default = Login;
|
|
47
|
+
Login.description = "Login using your APIMatic credentials or an API Key";
|
|
48
|
+
Login.examples = [
|
|
49
|
+
`$ apimatic auth:login
|
|
50
|
+
Please enter your registered email: apimatic-user@gmail.com
|
|
51
|
+
Please enter your password: *********
|
|
52
|
+
|
|
53
|
+
You have successfully logged into APIMatic
|
|
54
|
+
`,
|
|
55
|
+
`$ apimatic auth:login --auth-key=xxxxxx
|
|
56
|
+
Authentication key successfully set`
|
|
57
|
+
];
|
|
58
|
+
Login.flags = {
|
|
59
|
+
"auth-key": command_1.flags.string({ default: "", description: "Set authentication key for all commands" })
|
|
60
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const command_1 = require("@oclif/command");
|
|
4
|
+
const sdk_client_1 = require("../../client-utils/sdk-client");
|
|
5
|
+
class Login extends command_1.Command {
|
|
6
|
+
async run() {
|
|
7
|
+
try {
|
|
8
|
+
const client = sdk_client_1.SDKClient.getInstance();
|
|
9
|
+
const response = await client.logout(this.config.configDir);
|
|
10
|
+
this.log(response);
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
this.error(error);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.default = Login;
|
|
18
|
+
Login.description = "Clear local login credentials";
|
|
19
|
+
Login.examples = [
|
|
20
|
+
`$ apimatic auth:logout
|
|
21
|
+
Logged out
|
|
22
|
+
`
|
|
23
|
+
];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const command_1 = require("@oclif/command");
|
|
4
|
+
const sdk_client_1 = require("../../client-utils/sdk-client");
|
|
5
|
+
class Status extends command_1.Command {
|
|
6
|
+
async run() {
|
|
7
|
+
try {
|
|
8
|
+
const client = sdk_client_1.SDKClient.getInstance();
|
|
9
|
+
const response = await client.status(this.config.configDir);
|
|
10
|
+
this.log(response);
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
this.error(error);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.default = Status;
|
|
18
|
+
Status.description = "View current authentication state";
|
|
19
|
+
Status.examples = [
|
|
20
|
+
`$ apimatic auth:status
|
|
21
|
+
Currently logged in as apimatic-client@gmail.com
|
|
22
|
+
`
|
|
23
|
+
];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command, flags } from "@oclif/command";
|
|
2
|
+
export default class PortalGenerate extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
folder: flags.IOptionFlag<string>;
|
|
6
|
+
destination: flags.IOptionFlag<string>;
|
|
7
|
+
force: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
8
|
+
zip: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
9
|
+
"auth-key": flags.IOptionFlag<string>;
|
|
10
|
+
};
|
|
11
|
+
static examples: string[];
|
|
12
|
+
run(): Promise<undefined>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs = require("fs-extra");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const command_1 = require("@oclif/command");
|
|
6
|
+
const sdk_1 = require("@apimatic/sdk");
|
|
7
|
+
const sdk_client_1 = require("../../client-utils/sdk-client");
|
|
8
|
+
const generate_1 = require("../../controllers/portal/generate");
|
|
9
|
+
const utils_1 = require("../../utils/utils");
|
|
10
|
+
class PortalGenerate extends command_1.Command {
|
|
11
|
+
async run() {
|
|
12
|
+
const { flags } = this.parse(PortalGenerate);
|
|
13
|
+
const zip = flags.zip;
|
|
14
|
+
const sourceFolderPath = flags.folder;
|
|
15
|
+
const portalFolderPath = path.join(flags.destination, "generated_portal");
|
|
16
|
+
const zippedPortalPath = path.join(flags.destination, "generated_portal.zip");
|
|
17
|
+
const overrideAuthKey = flags["auth-key"] ? flags["auth-key"] : null;
|
|
18
|
+
// Check if at destination, portal already exists and throw error if force flag is not set for both zip and extracted
|
|
19
|
+
if (fs.existsSync(portalFolderPath) && !flags.force && !zip) {
|
|
20
|
+
throw new Error(`Can't download portal to path ${portalFolderPath}, because it already exists`);
|
|
21
|
+
}
|
|
22
|
+
else if (fs.existsSync(zippedPortalPath) && !flags.force && zip) {
|
|
23
|
+
throw new Error(`Can't download portal to path ${zippedPortalPath}, because it already exists`);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
if (!(await fs.pathExists(flags.destination))) {
|
|
27
|
+
throw new Error(`Destination path ${flags.destination} does not exist`);
|
|
28
|
+
}
|
|
29
|
+
else if (!(await fs.pathExists(flags.folder))) {
|
|
30
|
+
throw new Error(`Portal build folder ${flags.folder} does not exist`);
|
|
31
|
+
}
|
|
32
|
+
const client = await sdk_client_1.SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
|
|
33
|
+
const docsPortalController = new sdk_1.DocsPortalManagementController(client);
|
|
34
|
+
const zippedBuildFilePath = await utils_1.zipDirectory(sourceFolderPath, flags.destination);
|
|
35
|
+
const generatePortalParams = {
|
|
36
|
+
zippedBuildFilePath,
|
|
37
|
+
portalFolderPath,
|
|
38
|
+
zippedPortalPath,
|
|
39
|
+
docsPortalController,
|
|
40
|
+
overrideAuthKey,
|
|
41
|
+
zip
|
|
42
|
+
};
|
|
43
|
+
const generatedPortalPath = await generate_1.downloadDocsPortal(generatePortalParams, this.config.configDir);
|
|
44
|
+
this.log(`Your portal has been generated at ${generatedPortalPath}`);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error && error.response) {
|
|
48
|
+
const apiError = error;
|
|
49
|
+
const apiResponse = apiError.response;
|
|
50
|
+
if (apiResponse) {
|
|
51
|
+
const responseData = apiResponse.data.toString();
|
|
52
|
+
if (apiResponse.status === 422 && responseData.length > 0 && utils_1.isJSONParsable(responseData)) {
|
|
53
|
+
const nestedErrors = JSON.parse(responseData);
|
|
54
|
+
if (nestedErrors.error) {
|
|
55
|
+
return this.error(utils_1.replaceHTML(nestedErrors.error));
|
|
56
|
+
}
|
|
57
|
+
else if (nestedErrors.message) {
|
|
58
|
+
return this.error(utils_1.replaceHTML(nestedErrors.message));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else if (apiResponse.status === 401 && responseData.length > 0) {
|
|
62
|
+
this.error(utils_1.replaceHTML(responseData));
|
|
63
|
+
}
|
|
64
|
+
else if (apiResponse.status === 403 && apiResponse.statusText) {
|
|
65
|
+
return this.error(utils_1.replaceHTML(apiResponse.statusText));
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return this.error(apiError.message);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.error(`${error.message}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.default = PortalGenerate;
|
|
79
|
+
PortalGenerate.description = "Generate and download a static API Documentation portal. Requires an input directory containing API specifications, a config file and optionally, markdown guides. For details, refer to the [documentation](https://portal-api-docs.apimatic.io/#/http/generating-api-portal/build-file)";
|
|
80
|
+
PortalGenerate.flags = {
|
|
81
|
+
folder: command_1.flags.string({
|
|
82
|
+
parse: (input) => path.resolve(input),
|
|
83
|
+
default: "./",
|
|
84
|
+
description: "path to the input directory containing API specifications and config files"
|
|
85
|
+
}),
|
|
86
|
+
destination: command_1.flags.string({
|
|
87
|
+
parse: (input) => path.resolve(input),
|
|
88
|
+
default: path.resolve("./"),
|
|
89
|
+
description: "path to the downloaded portal"
|
|
90
|
+
}),
|
|
91
|
+
force: command_1.flags.boolean({ char: "f", default: false, description: "overwrite if a portal exists in the destination" }),
|
|
92
|
+
zip: command_1.flags.boolean({ default: false, description: "download the generated portal as a .zip archive" }),
|
|
93
|
+
"auth-key": command_1.flags.string({
|
|
94
|
+
default: "",
|
|
95
|
+
description: "override current authentication state with an authentication key"
|
|
96
|
+
})
|
|
97
|
+
};
|
|
98
|
+
PortalGenerate.examples = [
|
|
99
|
+
`$ apimatic portal:generate --folder="./portal/" --destination="D:/"
|
|
100
|
+
Your portal has been generated at D:/
|
|
101
|
+
`
|
|
102
|
+
];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Command, flags } from "@oclif/command";
|
|
2
|
+
export default class SdkGenerate extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static flags: {
|
|
5
|
+
platform: flags.IOptionFlag<string>;
|
|
6
|
+
file: flags.IOptionFlag<string>;
|
|
7
|
+
url: flags.IOptionFlag<string>;
|
|
8
|
+
destination: flags.IOptionFlag<string>;
|
|
9
|
+
force: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
10
|
+
zip: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
11
|
+
"auth-key": flags.IOptionFlag<string>;
|
|
12
|
+
};
|
|
13
|
+
static examples: string[];
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs = require("fs-extra");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const sdk_1 = require("@apimatic/sdk");
|
|
6
|
+
const command_1 = require("@oclif/command");
|
|
7
|
+
const sdk_client_1 = require("../../client-utils/sdk-client");
|
|
8
|
+
const utils_1 = require("../../utils/utils");
|
|
9
|
+
const generate_1 = require("../../controllers/sdk/generate");
|
|
10
|
+
class SdkGenerate extends command_1.Command {
|
|
11
|
+
async run() {
|
|
12
|
+
const { flags } = this.parse(SdkGenerate);
|
|
13
|
+
const zip = flags.zip;
|
|
14
|
+
const fileName = flags.file ? utils_1.getFileNameFromPath(flags.file) : utils_1.getFileNameFromPath(flags.url);
|
|
15
|
+
const sdkFolderPath = path.join(flags.destination, `${fileName}_sdk_${flags.platform}`.toLowerCase());
|
|
16
|
+
const zippedSDKPath = path.join(flags.destination, `${fileName}_sdk_${flags.platform}.zip`.toLowerCase());
|
|
17
|
+
// Check if at destination, SDK already exists and throw error if force flag is not set for both zip and extracted
|
|
18
|
+
if (fs.existsSync(sdkFolderPath) && !flags.force && !zip) {
|
|
19
|
+
throw new Error(`Can't download SDK to path ${sdkFolderPath}, because it already exists`);
|
|
20
|
+
}
|
|
21
|
+
else if (fs.existsSync(zippedSDKPath) && !flags.force && zip) {
|
|
22
|
+
throw new Error(`Can't download SDK to path ${zippedSDKPath}, because it already exists`);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
if (!(await fs.pathExists(path.resolve(flags.destination)))) {
|
|
26
|
+
throw new Error(`Destination path ${flags.destination} does not exist`);
|
|
27
|
+
}
|
|
28
|
+
else if (!(await fs.pathExists(path.resolve(flags.file)))) {
|
|
29
|
+
throw new Error(`Specification file ${flags.file} does not exist`);
|
|
30
|
+
}
|
|
31
|
+
const overrideAuthKey = flags["auth-key"] ? flags["auth-key"] : null;
|
|
32
|
+
const client = await sdk_client_1.SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
|
|
33
|
+
const sdkGenerationController = new sdk_1.CodeGenerationExternalApisController(client);
|
|
34
|
+
// Get generation id for the specification and platform
|
|
35
|
+
const codeGenId = await generate_1.getSDKGenerationId(flags, sdkGenerationController);
|
|
36
|
+
// If user wanted to download the SDK as well
|
|
37
|
+
const sdkDownloadParams = {
|
|
38
|
+
codeGenId,
|
|
39
|
+
zippedSDKPath,
|
|
40
|
+
sdkFolderPath,
|
|
41
|
+
zip
|
|
42
|
+
};
|
|
43
|
+
const sdkPath = await generate_1.downloadGeneratedSDK(sdkDownloadParams, sdkGenerationController);
|
|
44
|
+
this.log(`Success! Your SDK is located at ${sdkPath}`);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error.result) {
|
|
48
|
+
const apiError = error;
|
|
49
|
+
const result = apiError.result;
|
|
50
|
+
if (apiError.statusCode === 400 && utils_1.isJSONParsable(result.message)) {
|
|
51
|
+
const errors = JSON.parse(result.message);
|
|
52
|
+
if (Array.isArray(errors.Errors) && apiError.statusCode === 400) {
|
|
53
|
+
this.error(utils_1.replaceHTML(`${JSON.parse(result.message).Errors[0]}`));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else if (apiError.statusCode === 401 && apiError.body && typeof apiError.body === "string") {
|
|
57
|
+
this.error(apiError.body);
|
|
58
|
+
}
|
|
59
|
+
else if (apiError.statusCode === 500 &&
|
|
60
|
+
apiError.body &&
|
|
61
|
+
typeof apiError.body === "string" &&
|
|
62
|
+
utils_1.isJSONParsable(apiError.body)) {
|
|
63
|
+
this.error(JSON.parse(apiError.body).message);
|
|
64
|
+
}
|
|
65
|
+
else if (apiError.statusCode === 422 &&
|
|
66
|
+
apiError.body &&
|
|
67
|
+
typeof apiError.body === "string" &&
|
|
68
|
+
utils_1.isJSONParsable(apiError.body)) {
|
|
69
|
+
this.error(JSON.parse(apiError.body)["dto.Url"][0]);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this.error(utils_1.replaceHTML(result.message));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
this.error(`${error.message}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.default = SdkGenerate;
|
|
82
|
+
SdkGenerate.description = "Generate SDK for your APIs";
|
|
83
|
+
SdkGenerate.flags = {
|
|
84
|
+
platform: command_1.flags.string({
|
|
85
|
+
parse: (input) => input.toUpperCase(),
|
|
86
|
+
required: true,
|
|
87
|
+
description: `language platform for sdk
|
|
88
|
+
Simple: CSHARP|JAVA|PYTHON|RUBY|PHP|TYPESCRIPT
|
|
89
|
+
Legacy: CS_NET_STANDARD_LIB|CS_PORTABLE_NET_LIB|CS_UNIVERSAL_WINDOWS_PLATFORM_LIB|
|
|
90
|
+
JAVA_ECLIPSE_JRE_LIB|PHP_GENERIC_LIB|PYTHON_GENERIC_LIB|RUBY_GENERIC_LIB|
|
|
91
|
+
TS_GENERIC_LIB`
|
|
92
|
+
}),
|
|
93
|
+
file: command_1.flags.string({
|
|
94
|
+
parse: (input) => path.resolve(input),
|
|
95
|
+
default: "",
|
|
96
|
+
description: "path to the API specification to generate SDKs for"
|
|
97
|
+
}),
|
|
98
|
+
url: command_1.flags.string({
|
|
99
|
+
default: "",
|
|
100
|
+
description: "URL to the API specification to generate SDKs for. Can be used in place of the --file option if the API specification is publicly available."
|
|
101
|
+
}),
|
|
102
|
+
destination: command_1.flags.string({
|
|
103
|
+
parse: (input) => path.resolve(input),
|
|
104
|
+
default: path.resolve("./"),
|
|
105
|
+
description: "directory to download the generated SDK to"
|
|
106
|
+
}),
|
|
107
|
+
force: command_1.flags.boolean({
|
|
108
|
+
char: "f",
|
|
109
|
+
default: false,
|
|
110
|
+
description: "overwrite if an SDK already exists in the destination"
|
|
111
|
+
}),
|
|
112
|
+
zip: command_1.flags.boolean({ default: false, description: "download the generated SDK as a .zip archive" }),
|
|
113
|
+
"auth-key": command_1.flags.string({
|
|
114
|
+
default: "",
|
|
115
|
+
description: "override current authentication state with an authentication key"
|
|
116
|
+
})
|
|
117
|
+
};
|
|
118
|
+
SdkGenerate.examples = [
|
|
119
|
+
`$ apimatic sdk:generate --platform="CSHARP" --file="./specs/sample.json"
|
|
120
|
+
Generating SDK... done
|
|
121
|
+
Downloading SDK... done
|
|
122
|
+
Success! Your SDK is located at swagger_sdk_csharp`,
|
|
123
|
+
`
|
|
124
|
+
$ apimatic sdk:generate --platform="CSHARP" --url=https://petstore.swagger.io/v2/swagger.json
|
|
125
|
+
Generating SDK... done
|
|
126
|
+
Downloading SDK... done
|
|
127
|
+
Success! Your SDK is located at swagger_sdk_csharp
|
|
128
|
+
`
|
|
129
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const baseURL = "https://apimaticio-test.azurewebsites.net/api";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Command from "@oclif/command";
|
|
2
|
+
import { ApiValidationSummary, ExportFormats, Transformation, TransformationController } from "@apimatic/sdk";
|
|
3
|
+
import { DownloadTransformationParams, TransformationIdParams } from "../../types/api/transform";
|
|
4
|
+
export declare const getTransformationId: ({ file, url, format }: TransformationIdParams, transformationController: TransformationController) => Promise<Transformation>;
|
|
5
|
+
export declare const downloadTransformationFile: ({ id, destinationFilePath, transformationController }: DownloadTransformationParams) => Promise<string>;
|
|
6
|
+
export declare const getValidFormat: (format: string) => ExportFormats;
|
|
7
|
+
export declare const printValidationMessages: (apiValidationSummary: ApiValidationSummary | undefined, warn: Command["warn"], error: Command["error"]) => void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printValidationMessages = exports.getValidFormat = exports.downloadTransformationFile = exports.getTransformationId = void 0;
|
|
4
|
+
const cli_ux_1 = require("cli-ux");
|
|
5
|
+
const fs = require("fs-extra");
|
|
6
|
+
const sdk_1 = require("@apimatic/sdk");
|
|
7
|
+
const utils_1 = require("../../utils/utils");
|
|
8
|
+
exports.getTransformationId = async ({ file, url, format }, transformationController) => {
|
|
9
|
+
cli_ux_1.default.action.start("Transforming API specification");
|
|
10
|
+
let generation;
|
|
11
|
+
if (file) {
|
|
12
|
+
const fileDescriptor = new sdk_1.FileWrapper(fs.createReadStream(file));
|
|
13
|
+
generation = await transformationController.transformViaFile(fileDescriptor, format);
|
|
14
|
+
}
|
|
15
|
+
else if (url) {
|
|
16
|
+
const body = {
|
|
17
|
+
url: url,
|
|
18
|
+
exportFormat: format
|
|
19
|
+
};
|
|
20
|
+
generation = await transformationController.transformViaURL(body);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw new Error("Please provide a specification file");
|
|
24
|
+
}
|
|
25
|
+
cli_ux_1.default.action.stop();
|
|
26
|
+
return generation.result;
|
|
27
|
+
};
|
|
28
|
+
exports.downloadTransformationFile = async ({ id, destinationFilePath, transformationController }) => {
|
|
29
|
+
cli_ux_1.default.action.start("Downloading Transformed file");
|
|
30
|
+
const { result } = await transformationController.downloadTransformedFile(id);
|
|
31
|
+
if (result.readable) {
|
|
32
|
+
await utils_1.writeFileUsingReadableStream(result, destinationFilePath);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new Error("Couldn't save transformation file");
|
|
36
|
+
}
|
|
37
|
+
cli_ux_1.default.action.stop();
|
|
38
|
+
return destinationFilePath;
|
|
39
|
+
};
|
|
40
|
+
// Get valid platform from user's input, convert simple platform to valid Platforms enum value
|
|
41
|
+
exports.getValidFormat = (format) => {
|
|
42
|
+
if (Object.keys(sdk_1.ExportFormats).find((exportFormat) => exportFormat === format)) {
|
|
43
|
+
return sdk_1.ExportFormats[format];
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const formats = Object.keys(sdk_1.ExportFormats).join("|");
|
|
47
|
+
throw new Error(`Please provide a valid platform i.e. ${formats}`);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.printValidationMessages = (apiValidationSummary, warn, error) => {
|
|
51
|
+
const warnings = (apiValidationSummary === null || apiValidationSummary === void 0 ? void 0 : apiValidationSummary.warnings) || [];
|
|
52
|
+
const errors = (apiValidationSummary === null || apiValidationSummary === void 0 ? void 0 : apiValidationSummary.errors.join("\n")) || "";
|
|
53
|
+
warnings.forEach((warning) => {
|
|
54
|
+
warn(utils_1.replaceHTML(warning));
|
|
55
|
+
});
|
|
56
|
+
if (apiValidationSummary && apiValidationSummary.errors.length > 0) {
|
|
57
|
+
error(utils_1.replaceHTML(errors));
|
|
58
|
+
}
|
|
59
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import Command from "@oclif/command";
|
|
2
|
+
import { APIValidationExternalApisController, ApiValidationSummary } from "@apimatic/sdk";
|
|
3
|
+
import { GetValidationParams } from "../../types/api/validate";
|
|
4
|
+
export declare const getValidation: ({ file, url }: GetValidationParams, apiValidationController: APIValidationExternalApisController) => Promise<ApiValidationSummary>;
|
|
5
|
+
export declare const printValidationMessages: ({ warnings, errors }: ApiValidationSummary, warn: Command["warn"], error: Command["error"]) => void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printValidationMessages = exports.getValidation = void 0;
|
|
4
|
+
const cli_ux_1 = require("cli-ux");
|
|
5
|
+
const fs = require("fs-extra");
|
|
6
|
+
const core_1 = require("@apimatic/core");
|
|
7
|
+
const utils_1 = require("../../utils/utils");
|
|
8
|
+
exports.getValidation = async ({ file, url }, apiValidationController) => {
|
|
9
|
+
let validation;
|
|
10
|
+
cli_ux_1.default.action.start("Validating specification file");
|
|
11
|
+
if (file) {
|
|
12
|
+
const fileDescriptor = new core_1.FileWrapper(fs.createReadStream(file));
|
|
13
|
+
validation = await apiValidationController.validateAPIViaFile(fileDescriptor);
|
|
14
|
+
}
|
|
15
|
+
else if (url) {
|
|
16
|
+
validation = await apiValidationController.validateAPIViaURL(url);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
throw new Error("Please provide a specification file");
|
|
20
|
+
}
|
|
21
|
+
cli_ux_1.default.action.stop();
|
|
22
|
+
return validation.result;
|
|
23
|
+
};
|
|
24
|
+
exports.printValidationMessages = ({ warnings, errors }, warn, error) => {
|
|
25
|
+
warnings.forEach((warning) => {
|
|
26
|
+
warn(`${utils_1.replaceHTML(warning)}`);
|
|
27
|
+
});
|
|
28
|
+
if (errors.length > 0) {
|
|
29
|
+
const singleLineError = errors.join("\n");
|
|
30
|
+
error(utils_1.replaceHTML(singleLineError));
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.downloadDocsPortal = void 0;
|
|
4
|
+
const fs = require("fs-extra");
|
|
5
|
+
const FormData = require("form-data");
|
|
6
|
+
const cli_ux_1 = require("cli-ux");
|
|
7
|
+
const auth_manager_1 = require("../../client-utils/auth-manager");
|
|
8
|
+
const env_1 = require("../../config/env");
|
|
9
|
+
const utils_1 = require("../../utils/utils");
|
|
10
|
+
const axios_1 = require("axios");
|
|
11
|
+
// TODO: Remove after SDK is patched
|
|
12
|
+
const downloadPortalAxios = async (zippedBuildFilePath, overrideAuthKey, configDir) => {
|
|
13
|
+
const formData = new FormData();
|
|
14
|
+
const authInfo = await auth_manager_1.getAuthInfo(configDir);
|
|
15
|
+
formData.append("file", fs.createReadStream(zippedBuildFilePath));
|
|
16
|
+
const config = {
|
|
17
|
+
headers: Object.assign({ Authorization: authInfo ? `X-Auth-Key ${overrideAuthKey || authInfo.authKey.trim()}` : "", "Content-Type": "multipart/form-data" }, formData.getHeaders()),
|
|
18
|
+
responseType: "arraybuffer"
|
|
19
|
+
};
|
|
20
|
+
const { data } = await axios_1.default.post(`${env_1.baseURL}/portal`, formData, config);
|
|
21
|
+
return data;
|
|
22
|
+
};
|
|
23
|
+
// Download Docs Portal
|
|
24
|
+
exports.downloadDocsPortal = async ({ zippedBuildFilePath, portalFolderPath, zippedPortalPath, overrideAuthKey, zip }, configDir) => {
|
|
25
|
+
cli_ux_1.default.action.start("Downloading portal");
|
|
26
|
+
// Check if the build file exists for the user or not
|
|
27
|
+
if (!(await fs.pathExists(zippedBuildFilePath))) {
|
|
28
|
+
throw new Error("Build file doesn't exist");
|
|
29
|
+
}
|
|
30
|
+
// TODO: ***CRITICAL*** Remove this call once the SDK is patched
|
|
31
|
+
const data = await downloadPortalAxios(zippedBuildFilePath, overrideAuthKey, configDir);
|
|
32
|
+
await utils_1.deleteFile(zippedBuildFilePath);
|
|
33
|
+
await fs.writeFile(zippedPortalPath, data);
|
|
34
|
+
// TODO: Uncomment this code block when the SDK is patched
|
|
35
|
+
// const file: FileWrapper = new FileWrapper(fs.createReadStream(zippedBuildFilePath));
|
|
36
|
+
// const { result }: ApiResponse<NodeJS.ReadableStream | Blob> =
|
|
37
|
+
// await docsPortalController.generateOnPremPortalViaBuildInput(file);
|
|
38
|
+
// if ((data as NodeJS.ReadableStream).readable) {
|
|
39
|
+
// await writeFileUsingReadableStream(data as NodeJS.ReadableStream, zippedPortalPath);
|
|
40
|
+
if (!zip) {
|
|
41
|
+
await utils_1.unzipFile(fs.createReadStream(zippedPortalPath), portalFolderPath);
|
|
42
|
+
await utils_1.deleteFile(zippedPortalPath);
|
|
43
|
+
}
|
|
44
|
+
cli_ux_1.default.action.stop();
|
|
45
|
+
return zip ? zippedPortalPath : portalFolderPath;
|
|
46
|
+
// } else {
|
|
47
|
+
// throw new Error("Couldn't download the portal");
|
|
48
|
+
// }
|
|
49
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CodeGenerationExternalApisController } from "@apimatic/sdk";
|
|
2
|
+
import { GenerationIdParams, DownloadSDKParams } from "../../types/sdk/generate";
|
|
3
|
+
export declare const getSDKGenerationId: ({ file, url, platform }: GenerationIdParams, sdkGenerationController: CodeGenerationExternalApisController) => Promise<string>;
|
|
4
|
+
export declare const downloadGeneratedSDK: ({ codeGenId, zippedSDKPath, sdkFolderPath, zip }: DownloadSDKParams, sdkGenerationController: CodeGenerationExternalApisController) => Promise<string>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.downloadGeneratedSDK = exports.getSDKGenerationId = void 0;
|
|
4
|
+
const fs = require("fs-extra");
|
|
5
|
+
const cli_ux_1 = require("cli-ux");
|
|
6
|
+
const sdk_1 = require("@apimatic/sdk");
|
|
7
|
+
const core_1 = require("@apimatic/core");
|
|
8
|
+
const generate_1 = require("../../types/sdk/generate");
|
|
9
|
+
const utils_1 = require("../../utils/utils");
|
|
10
|
+
exports.getSDKGenerationId = async ({ file, url, platform }, sdkGenerationController) => {
|
|
11
|
+
cli_ux_1.default.action.start("Generating SDK");
|
|
12
|
+
let generation;
|
|
13
|
+
const sdkPlatform = getSDKPlatform(platform);
|
|
14
|
+
if (file) {
|
|
15
|
+
const fileDescriptor = new core_1.FileWrapper(fs.createReadStream(file));
|
|
16
|
+
generation = await sdkGenerationController.generateSDKViaFile(fileDescriptor, sdkPlatform);
|
|
17
|
+
}
|
|
18
|
+
else if (url) {
|
|
19
|
+
// If url to spec file is provided
|
|
20
|
+
const body = {
|
|
21
|
+
url: url,
|
|
22
|
+
template: sdkPlatform
|
|
23
|
+
};
|
|
24
|
+
generation = await sdkGenerationController.generateSDKViaURL(body);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
throw new Error("Please provide a specification file");
|
|
28
|
+
}
|
|
29
|
+
cli_ux_1.default.action.stop();
|
|
30
|
+
return generation.result.id;
|
|
31
|
+
};
|
|
32
|
+
// Get valid platform from user's input, convert simple platform to valid Platforms enum value
|
|
33
|
+
const getSDKPlatform = (platform) => {
|
|
34
|
+
if (Object.keys(generate_1.SimplePlatforms).includes(platform)) {
|
|
35
|
+
return generate_1.SimplePlatforms[platform];
|
|
36
|
+
}
|
|
37
|
+
else if (Object.values(sdk_1.Platforms).includes(platform)) {
|
|
38
|
+
return platform;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const platforms = Object.keys(generate_1.SimplePlatforms).concat(Object.values(sdk_1.Platforms)).join("|");
|
|
42
|
+
throw new Error(`Please provide a valid platform i.e. ${platforms}`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
// Download Platform
|
|
46
|
+
exports.downloadGeneratedSDK = async ({ codeGenId, zippedSDKPath, sdkFolderPath, zip }, sdkGenerationController) => {
|
|
47
|
+
cli_ux_1.default.action.start("Downloading SDK");
|
|
48
|
+
const { result } = await sdkGenerationController.downloadSDK(codeGenId);
|
|
49
|
+
if (result.readable) {
|
|
50
|
+
if (!zip) {
|
|
51
|
+
await utils_1.unzipFile(result, sdkFolderPath);
|
|
52
|
+
cli_ux_1.default.action.stop();
|
|
53
|
+
return sdkFolderPath;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
await utils_1.writeFileUsingReadableStream(result, zippedSDKPath);
|
|
57
|
+
cli_ux_1.default.action.stop();
|
|
58
|
+
return zippedSDKPath;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
throw new Error("Couldn't download the SDK");
|
|
63
|
+
}
|
|
64
|
+
};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { run } from "@oclif/command";
|
package/lib/index.js
ADDED