@apimatic/cli 1.1.0-alpha.2 → 1.1.0-alpha.4

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.
@@ -1,4 +1,4 @@
1
- export declare type AuthInfo = {
1
+ export type AuthInfo = {
2
2
  email: string;
3
3
  authKey: string;
4
4
  };
@@ -9,7 +9,7 @@ const auth_manager_1 = require("./auth-manager");
9
9
  class SDKClient {
10
10
  constructor() {
11
11
  this.setAuthKey = (authKey, configDir) => {
12
- auth_manager_1.setAuthInfo({
12
+ (0, auth_manager_1.setAuthInfo)({
13
13
  email: "",
14
14
  authKey
15
15
  }, configDir);
@@ -33,7 +33,7 @@ class SDKClient {
33
33
  * executed on its instance.
34
34
  */
35
35
  async login(email, password, configDir) {
36
- let storedAuthInfo = await auth_manager_1.getAuthInfo(configDir);
36
+ let storedAuthInfo = await (0, auth_manager_1.getAuthInfo)(configDir);
37
37
  // If no config file or no credentials exist in the config file
38
38
  if (!storedAuthInfo) {
39
39
  storedAuthInfo = { email: "", authKey: "" };
@@ -41,7 +41,7 @@ class SDKClient {
41
41
  const credentials = { email, password };
42
42
  const authKey = await this.getAuthKey(credentials);
43
43
  if (storedAuthInfo.email !== email) {
44
- auth_manager_1.setAuthInfo({
44
+ (0, auth_manager_1.setAuthInfo)({
45
45
  email,
46
46
  authKey
47
47
  }, configDir);
@@ -51,7 +51,7 @@ class SDKClient {
51
51
  return "Already logged in";
52
52
  }
53
53
  else {
54
- auth_manager_1.setAuthInfo({
54
+ (0, auth_manager_1.setAuthInfo)({
55
55
  email,
56
56
  authKey
57
57
  }, configDir);
@@ -59,7 +59,7 @@ class SDKClient {
59
59
  }
60
60
  }
61
61
  async logout(configDir) {
62
- auth_manager_1.setAuthInfo({
62
+ (0, auth_manager_1.setAuthInfo)({
63
63
  email: "",
64
64
  authKey: ""
65
65
  }, configDir);
@@ -67,7 +67,7 @@ class SDKClient {
67
67
  }
68
68
  async status(configDir) {
69
69
  try {
70
- let storedAuthInfo = await auth_manager_1.getAuthInfo(configDir);
70
+ let storedAuthInfo = await (0, auth_manager_1.getAuthInfo)(configDir);
71
71
  if (!storedAuthInfo) {
72
72
  // If no config file or no credentials exist in the config file
73
73
  storedAuthInfo = { email: "", authKey: "" };
@@ -89,7 +89,7 @@ class SDKClient {
89
89
  authorization: `X-Auth-Key ${overrideAuthKey}`
90
90
  });
91
91
  }
92
- let storedAuthInfo = await auth_manager_1.getAuthInfo(configDir);
92
+ let storedAuthInfo = await (0, auth_manager_1.getAuthInfo)(configDir);
93
93
  if (!storedAuthInfo) {
94
94
  // If no config file or no credentials exist in the config file
95
95
  storedAuthInfo = { email: "", authKey: "" };
@@ -13,7 +13,7 @@ const formats = Object.keys(sdk_1.ExportFormats).join("|");
13
13
  class Transform extends command_1.Command {
14
14
  async run() {
15
15
  const { flags } = this.parse(Transform);
16
- const fileName = flags.file ? utils_2.getFileNameFromPath(flags.file) : utils_2.getFileNameFromPath(flags.url);
16
+ const fileName = flags.file ? (0, utils_2.getFileNameFromPath)(flags.file) : (0, utils_2.getFileNameFromPath)(flags.url);
17
17
  const destinationFormat = transform_1.DestinationFormats[flags.format];
18
18
  const destinationFilePath = path.join(flags.destination, `${fileName}_${flags.format}.${destinationFormat}`.toLowerCase());
19
19
  // Check if destination file already exist and throw error if force flag is not set
@@ -31,14 +31,14 @@ class Transform extends command_1.Command {
31
31
  const overrideAuthKey = flags["auth-key"] ? flags["auth-key"] : null;
32
32
  const client = await sdk_client_1.SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
33
33
  const transformationController = new sdk_1.TransformationController(client);
34
- const { id, apiValidationSummary } = await transform_2.getTransformationId(flags, transformationController);
34
+ const { id, apiValidationSummary } = await (0, transform_2.getTransformationId)(flags, transformationController);
35
35
  const logFunctions = {
36
36
  log: this.log,
37
37
  warn: this.warn,
38
38
  error: this.error
39
39
  };
40
- utils_1.printValidationMessages(apiValidationSummary, logFunctions);
41
- const savedTransformationFile = await transform_2.downloadTransformationFile({
40
+ (0, utils_1.printValidationMessages)(apiValidationSummary, logFunctions);
41
+ const savedTransformationFile = await (0, transform_2.downloadTransformationFile)({
42
42
  id,
43
43
  destinationFilePath,
44
44
  transformationController
@@ -52,7 +52,7 @@ class Transform extends command_1.Command {
52
52
  // updated to throw the right exception type for this status code.
53
53
  const result = apiError.result;
54
54
  if (apiError.statusCode === 422 && result && "errors" in result && Array.isArray(result.errors)) {
55
- this.error(utils_2.replaceHTML(`${result.errors}`));
55
+ this.error((0, utils_2.replaceHTML)(`${result.errors}`));
56
56
  }
57
57
  else if (apiError.statusCode === 422 && apiError.body && typeof apiError.body === "string") {
58
58
  this.error(JSON.parse(apiError.body)["dto.FileUrl"][0]);
@@ -78,7 +78,6 @@ class Transform extends command_1.Command {
78
78
  }
79
79
  }
80
80
  }
81
- exports.default = Transform;
82
81
  Transform.description = `Transform API specifications from one format to another. Supports [10+ different formats](https://www.apimatic.io/transformer/#supported-formats) including OpenApi/Swagger, RAML, WSDL and Postman Collections.`;
83
82
  Transform.examples = [
84
83
  `$ apimatic api:transform --format="OpenApi3Json" --file="./specs/sample.json" --destination="D:/"
@@ -90,7 +89,7 @@ Success! Your transformed file is located at D:/swagger_raml.yaml
90
89
  ];
91
90
  Transform.flags = {
92
91
  format: command_1.flags.string({
93
- parse: (format) => transform_2.getValidFormat(format.toUpperCase()),
92
+ parse: (format) => (0, transform_2.getValidFormat)(format.toUpperCase()),
94
93
  required: true,
95
94
  description: `specification format to transform API specification into
96
95
  ${formats}`
@@ -112,3 +111,4 @@ ${formats}`
112
111
  force: command_1.flags.boolean({ char: "f", default: false, description: "overwrite if same file exist in the destination" }),
113
112
  "auth-key": command_1.flags.string({ description: "override current authentication state with an authentication key" })
114
113
  };
114
+ exports.default = Transform;
@@ -16,13 +16,13 @@ class Validate extends command_1.Command {
16
16
  const overrideAuthKey = flags["auth-key"] ? flags["auth-key"] : null;
17
17
  const client = await sdk_client_1.SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
18
18
  const apiValidationController = new sdk_1.APIValidationExternalApisController(client);
19
- const validationSummary = await validate_1.getValidation(flags, apiValidationController);
19
+ const validationSummary = await (0, validate_1.getValidation)(flags, apiValidationController);
20
20
  const logFunctions = {
21
21
  log: this.log,
22
22
  warn: this.warn,
23
23
  error: this.error
24
24
  };
25
- utils_1.printValidationMessages(validationSummary, logFunctions);
25
+ (0, utils_1.printValidationMessages)(validationSummary, logFunctions);
26
26
  validationSummary.success
27
27
  ? this.log("Specification file provided is valid")
28
28
  : this.error("Specification file provided is invalid");
@@ -32,7 +32,7 @@ class Validate extends command_1.Command {
32
32
  const apiError = error;
33
33
  const result = apiError.result;
34
34
  if (result.modelState["exception Error"] && apiError.statusCode === 400) {
35
- this.error(utils_1.replaceHTML(result.modelState["exception Error"][0]));
35
+ this.error((0, utils_1.replaceHTML)(result.modelState["exception Error"][0]));
36
36
  }
37
37
  else if (error.body && apiError.statusCode === 401) {
38
38
  this.error("You are not authorized to perform this action");
@@ -55,7 +55,6 @@ class Validate extends command_1.Command {
55
55
  }
56
56
  }
57
57
  }
58
- exports.default = Validate;
59
58
  Validate.description = "Validate the syntactic and semantic correctness of an API specification";
60
59
  Validate.examples = [
61
60
  `$ apimatic api:validate --file="./specs/sample.json"
@@ -74,3 +73,4 @@ Validate.flags = {
74
73
  // docs: flags.boolean({ default: false, description: "Validate specification for docs generation" }), // Next tier, not included in API spec
75
74
  "auth-key": command_1.flags.string({ description: "override current authentication state with an authentication key" })
76
75
  };
76
+ exports.default = Validate;
@@ -32,7 +32,7 @@ class Login extends command_1.Command {
32
32
  if (apiResponse) {
33
33
  const responseData = apiResponse.data;
34
34
  if (apiResponse.status === 403 && responseData) {
35
- return this.error(utils_1.replaceHTML(responseData));
35
+ return this.error((0, utils_1.replaceHTML)(responseData));
36
36
  }
37
37
  else {
38
38
  return this.error(apiError.message);
@@ -43,7 +43,6 @@ class Login extends command_1.Command {
43
43
  }
44
44
  }
45
45
  }
46
- exports.default = Login;
47
46
  Login.description = "Login using your APIMatic credentials or an API Key";
48
47
  Login.examples = [
49
48
  `$ apimatic auth:login
@@ -58,3 +57,4 @@ Authentication key successfully set`
58
57
  Login.flags = {
59
58
  "auth-key": command_1.flags.string({ default: "", description: "Set authentication key for all commands" })
60
59
  };
60
+ exports.default = Login;
@@ -14,10 +14,10 @@ class Login extends command_1.Command {
14
14
  }
15
15
  }
16
16
  }
17
- exports.default = Login;
18
17
  Login.description = "Clear local login credentials";
19
18
  Login.examples = [
20
19
  `$ apimatic auth:logout
21
20
  Logged out
22
21
  `
23
22
  ];
23
+ exports.default = Login;
@@ -14,10 +14,10 @@ class Status extends command_1.Command {
14
14
  }
15
15
  }
16
16
  }
17
- exports.default = Status;
18
17
  Status.description = "View current authentication state";
19
18
  Status.examples = [
20
19
  `$ apimatic auth:status
21
20
  Currently logged in as apimatic-client@gmail.com
22
21
  `
23
22
  ];
23
+ exports.default = Status;
@@ -31,7 +31,7 @@ class PortalGenerate extends command_1.Command {
31
31
  }
32
32
  const client = await sdk_client_1.SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
33
33
  const docsPortalController = new sdk_1.DocsPortalManagementController(client);
34
- const zippedBuildFilePath = await utils_1.zipDirectory(sourceFolderPath, flags.destination);
34
+ const zippedBuildFilePath = await (0, utils_1.zipDirectory)(sourceFolderPath, flags.destination);
35
35
  const generatePortalParams = {
36
36
  zippedBuildFilePath,
37
37
  portalFolderPath,
@@ -40,7 +40,7 @@ class PortalGenerate extends command_1.Command {
40
40
  overrideAuthKey,
41
41
  zip
42
42
  };
43
- const generatedPortalPath = await generate_1.downloadDocsPortal(generatePortalParams, this.config.configDir);
43
+ const generatedPortalPath = await (0, generate_1.downloadDocsPortal)(generatePortalParams, this.config.configDir);
44
44
  this.log(`Your portal has been generated at ${generatedPortalPath}`);
45
45
  }
46
46
  catch (error) {
@@ -49,13 +49,13 @@ class PortalGenerate extends command_1.Command {
49
49
  const apiResponse = apiError.response;
50
50
  if (apiResponse) {
51
51
  const responseData = apiResponse.data.toString();
52
- if (apiResponse.status === 422 && responseData.length > 0 && utils_1.isJSONParsable(responseData)) {
52
+ if (apiResponse.status === 422 && responseData.length > 0 && (0, utils_1.isJSONParsable)(responseData)) {
53
53
  const nestedErrors = JSON.parse(responseData);
54
54
  if (nestedErrors.error) {
55
- return this.error(utils_1.replaceHTML(nestedErrors.error));
55
+ return this.error((0, utils_1.replaceHTML)(nestedErrors.error));
56
56
  }
57
57
  else if (nestedErrors.message) {
58
- return this.error(utils_1.replaceHTML(nestedErrors.message));
58
+ return this.error((0, utils_1.replaceHTML)(nestedErrors.message));
59
59
  }
60
60
  }
61
61
  else if (apiResponse.status === 401 && responseData.length > 0) {
@@ -83,7 +83,6 @@ class PortalGenerate extends command_1.Command {
83
83
  }
84
84
  }
85
85
  }
86
- exports.default = PortalGenerate;
87
86
  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)";
88
87
  PortalGenerate.flags = {
89
88
  folder: command_1.flags.string({
@@ -108,3 +107,4 @@ PortalGenerate.examples = [
108
107
  Your portal has been generated at D:/
109
108
  `
110
109
  ];
110
+ exports.default = PortalGenerate;
@@ -11,7 +11,7 @@ class SdkGenerate extends command_1.Command {
11
11
  async run() {
12
12
  const { flags } = this.parse(SdkGenerate);
13
13
  const zip = flags.zip;
14
- const fileName = flags.file ? utils_1.getFileNameFromPath(flags.file) : utils_1.getFileNameFromPath(flags.url);
14
+ const fileName = flags.file ? (0, utils_1.getFileNameFromPath)(flags.file) : (0, utils_1.getFileNameFromPath)(flags.url);
15
15
  const sdkFolderPath = path.join(flags.destination, `${fileName}_sdk_${flags.platform}`.toLowerCase());
16
16
  const zippedSDKPath = path.join(flags.destination, `${fileName}_sdk_${flags.platform}.zip`.toLowerCase());
17
17
  // Check if at destination, SDK already exists and throw error if force flag is not set for both zip and extracted
@@ -32,7 +32,7 @@ class SdkGenerate extends command_1.Command {
32
32
  const client = await sdk_client_1.SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
33
33
  const sdkGenerationController = new sdk_1.CodeGenerationExternalApisController(client);
34
34
  // Get generation id for the specification and platform
35
- const codeGenId = await generate_1.getSDKGenerationId(flags, sdkGenerationController);
35
+ const codeGenId = await (0, generate_1.getSDKGenerationId)(flags, sdkGenerationController);
36
36
  // If user wanted to download the SDK as well
37
37
  const sdkDownloadParams = {
38
38
  codeGenId,
@@ -40,17 +40,17 @@ class SdkGenerate extends command_1.Command {
40
40
  sdkFolderPath,
41
41
  zip
42
42
  };
43
- const sdkPath = await generate_1.downloadGeneratedSDK(sdkDownloadParams, sdkGenerationController);
43
+ const sdkPath = await (0, generate_1.downloadGeneratedSDK)(sdkDownloadParams, sdkGenerationController);
44
44
  this.log(`Success! Your SDK is located at ${sdkPath}`);
45
45
  }
46
46
  catch (error) {
47
47
  if (error.result) {
48
48
  const apiError = error;
49
49
  const result = apiError.result;
50
- if (apiError.statusCode === 400 && utils_1.isJSONParsable(result.message)) {
50
+ if (apiError.statusCode === 400 && (0, utils_1.isJSONParsable)(result.message)) {
51
51
  const errors = JSON.parse(result.message);
52
52
  if (Array.isArray(errors.Errors) && apiError.statusCode === 400) {
53
- this.error(utils_1.replaceHTML(`${JSON.parse(result.message).Errors[0]}`));
53
+ this.error((0, utils_1.replaceHTML)(`${JSON.parse(result.message).Errors[0]}`));
54
54
  }
55
55
  }
56
56
  else if (apiError.statusCode === 401 && apiError.body && typeof apiError.body === "string") {
@@ -59,17 +59,17 @@ class SdkGenerate extends command_1.Command {
59
59
  else if (apiError.statusCode === 500 &&
60
60
  apiError.body &&
61
61
  typeof apiError.body === "string" &&
62
- utils_1.isJSONParsable(apiError.body)) {
62
+ (0, utils_1.isJSONParsable)(apiError.body)) {
63
63
  this.error(JSON.parse(apiError.body).message);
64
64
  }
65
65
  else if (apiError.statusCode === 422 &&
66
66
  apiError.body &&
67
67
  typeof apiError.body === "string" &&
68
- utils_1.isJSONParsable(apiError.body)) {
68
+ (0, utils_1.isJSONParsable)(apiError.body)) {
69
69
  this.error(JSON.parse(apiError.body)["dto.Url"][0]);
70
70
  }
71
71
  else {
72
- this.error(utils_1.replaceHTML(result.message));
72
+ this.error((0, utils_1.replaceHTML)(result.message));
73
73
  }
74
74
  }
75
75
  else if (error.statusCode === 401) {
@@ -78,7 +78,7 @@ class SdkGenerate extends command_1.Command {
78
78
  else if (error.statusCode === 402 &&
79
79
  error.body &&
80
80
  typeof error.body === "string") {
81
- this.error(utils_1.replaceHTML(error.body));
81
+ this.error((0, utils_1.replaceHTML)(error.body));
82
82
  }
83
83
  else {
84
84
  this.error(`${error.message}`);
@@ -86,7 +86,6 @@ class SdkGenerate extends command_1.Command {
86
86
  }
87
87
  }
88
88
  }
89
- exports.default = SdkGenerate;
90
89
  SdkGenerate.description = "Generate SDK for your APIs";
91
90
  SdkGenerate.flags = {
92
91
  platform: command_1.flags.string({
@@ -133,3 +132,4 @@ Downloading SDK... done
133
132
  Success! Your SDK is located at swagger_sdk_csharp
134
133
  `
135
134
  ];
135
+ exports.default = SdkGenerate;
@@ -1 +1 @@
1
- export declare const baseURL = "https://www.apimatic.io/api";
1
+ export declare const baseURL = "https://api.apimatic.io";
package/lib/config/env.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.baseURL = void 0;
4
- exports.baseURL = "https://www.apimatic.io/api";
4
+ exports.baseURL = "https://api.apimatic.io";
@@ -5,12 +5,12 @@ const cli_ux_1 = require("cli-ux");
5
5
  const fs = require("fs-extra");
6
6
  const utils_1 = require("../../utils/utils");
7
7
  const sdk_1 = require("@apimatic/sdk");
8
- exports.getTransformationId = async ({ file, url, format }, transformationController) => {
8
+ const getTransformationId = async ({ file, url, format }, transformationController) => {
9
9
  cli_ux_1.default.action.start("Transforming API specification");
10
10
  let generation;
11
11
  if (file) {
12
12
  const fileDescriptor = new sdk_1.FileWrapper(fs.createReadStream(file));
13
- generation = await transformationController.transformViaFile(fileDescriptor, format);
13
+ generation = await transformationController.transformViaFile(sdk_1.ContentType.EnumMultipartformdata, fileDescriptor, format);
14
14
  }
15
15
  else if (url) {
16
16
  const body = {
@@ -25,11 +25,12 @@ exports.getTransformationId = async ({ file, url, format }, transformationContro
25
25
  cli_ux_1.default.action.stop();
26
26
  return generation.result;
27
27
  };
28
- exports.downloadTransformationFile = async ({ id, destinationFilePath, transformationController }) => {
28
+ exports.getTransformationId = getTransformationId;
29
+ const downloadTransformationFile = async ({ id, destinationFilePath, transformationController }) => {
29
30
  cli_ux_1.default.action.start("Downloading Transformed file");
30
31
  const { result } = await transformationController.downloadTransformedFile(id);
31
32
  if (result.readable) {
32
- await utils_1.writeFileUsingReadableStream(result, destinationFilePath);
33
+ await (0, utils_1.writeFileUsingReadableStream)(result, destinationFilePath);
33
34
  }
34
35
  else {
35
36
  throw new Error("Couldn't save transformation file");
@@ -37,8 +38,9 @@ exports.downloadTransformationFile = async ({ id, destinationFilePath, transform
37
38
  cli_ux_1.default.action.stop();
38
39
  return destinationFilePath;
39
40
  };
41
+ exports.downloadTransformationFile = downloadTransformationFile;
40
42
  // Get valid platform from user's input, convert simple platform to valid Platforms enum value
41
- exports.getValidFormat = (format) => {
43
+ const getValidFormat = (format) => {
42
44
  if (Object.keys(sdk_1.ExportFormats).find((exportFormat) => exportFormat === format)) {
43
45
  return sdk_1.ExportFormats[format];
44
46
  }
@@ -47,3 +49,4 @@ exports.getValidFormat = (format) => {
47
49
  throw new Error(`Please provide a valid platform i.e. ${formats}`);
48
50
  }
49
51
  };
52
+ exports.getValidFormat = getValidFormat;
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getValidation = void 0;
4
4
  const cli_ux_1 = require("cli-ux");
5
5
  const fs = require("fs-extra");
6
- const core_1 = require("@apimatic/core");
7
- exports.getValidation = async ({ file, url }, apiValidationController) => {
6
+ const sdk_1 = require("@apimatic/sdk");
7
+ const sdk_2 = require("@apimatic/sdk");
8
+ const getValidation = async ({ file, url }, apiValidationController) => {
8
9
  let validation;
9
10
  cli_ux_1.default.action.start("Validating specification file");
10
11
  if (file) {
11
- const fileDescriptor = new core_1.FileWrapper(fs.createReadStream(file));
12
- validation = await apiValidationController.validateAPIViaFile(fileDescriptor);
12
+ const fileDescriptor = new sdk_1.FileWrapper(fs.createReadStream(file));
13
+ validation = await apiValidationController.validateAPIViaFile(sdk_2.ContentType.EnumMultipartformdata, fileDescriptor);
13
14
  }
14
15
  else if (url) {
15
16
  validation = await apiValidationController.validateAPIViaURL(url);
@@ -20,3 +21,4 @@ exports.getValidation = async ({ file, url }, apiValidationController) => {
20
21
  cli_ux_1.default.action.stop();
21
22
  return validation.result;
22
23
  };
24
+ exports.getValidation = getValidation;
@@ -11,17 +11,17 @@ const axios_1 = require("axios");
11
11
  // TODO: Remove after SDK is patched
12
12
  const downloadPortalAxios = async (zippedBuildFilePath, overrideAuthKey, configDir) => {
13
13
  const formData = new FormData();
14
- const authInfo = await auth_manager_1.getAuthInfo(configDir);
14
+ const authInfo = await (0, auth_manager_1.getAuthInfo)(configDir);
15
15
  formData.append("file", fs.createReadStream(zippedBuildFilePath));
16
16
  const config = {
17
- headers: Object.assign({ Authorization: authInfo || overrideAuthKey ? `X-Auth-Key ${(authInfo === null || authInfo === void 0 ? void 0 : authInfo.authKey.trim()) || overrideAuthKey}` : "" }, formData.getHeaders()),
17
+ headers: Object.assign({ Authorization: authInfo || overrideAuthKey ? `X-Auth-Key ${(authInfo === null || authInfo === void 0 ? void 0 : authInfo.authKey.trim()) || overrideAuthKey}` : "", "User-Agent": "APIMatic CLI" }, formData.getHeaders()),
18
18
  responseType: "arraybuffer"
19
19
  };
20
20
  const { data } = await axios_1.default.post(`${env_1.baseURL}/portal`, formData, config);
21
21
  return data;
22
22
  };
23
23
  // Download Docs Portal
24
- exports.downloadDocsPortal = async ({ zippedBuildFilePath, portalFolderPath, zippedPortalPath, overrideAuthKey, zip }, configDir) => {
24
+ const downloadDocsPortal = async ({ zippedBuildFilePath, portalFolderPath, zippedPortalPath, overrideAuthKey, zip }, configDir) => {
25
25
  cli_ux_1.default.action.start("Downloading portal");
26
26
  // Check if the build file exists for the user or not
27
27
  if (!(await fs.pathExists(zippedBuildFilePath))) {
@@ -29,7 +29,7 @@ exports.downloadDocsPortal = async ({ zippedBuildFilePath, portalFolderPath, zip
29
29
  }
30
30
  // TODO: ***CRITICAL*** Remove this call once the SDK is patched
31
31
  const data = await downloadPortalAxios(zippedBuildFilePath, overrideAuthKey, configDir);
32
- await utils_1.deleteFile(zippedBuildFilePath);
32
+ await (0, utils_1.deleteFile)(zippedBuildFilePath);
33
33
  await fs.writeFile(zippedPortalPath, data);
34
34
  // TODO: Uncomment this code block when the SDK is patched
35
35
  // const file: FileWrapper = new FileWrapper(fs.createReadStream(zippedBuildFilePath));
@@ -38,8 +38,8 @@ exports.downloadDocsPortal = async ({ zippedBuildFilePath, portalFolderPath, zip
38
38
  // if ((data as NodeJS.ReadableStream).readable) {
39
39
  // await writeFileUsingReadableStream(data as NodeJS.ReadableStream, zippedPortalPath);
40
40
  if (!zip) {
41
- await utils_1.unzipFile(fs.createReadStream(zippedPortalPath), portalFolderPath);
42
- await utils_1.deleteFile(zippedPortalPath);
41
+ await (0, utils_1.unzipFile)(fs.createReadStream(zippedPortalPath), portalFolderPath);
42
+ await (0, utils_1.deleteFile)(zippedPortalPath);
43
43
  }
44
44
  cli_ux_1.default.action.stop();
45
45
  return zip ? zippedPortalPath : portalFolderPath;
@@ -47,3 +47,4 @@ exports.downloadDocsPortal = async ({ zippedBuildFilePath, portalFolderPath, zip
47
47
  // throw new Error("Couldn't download the portal");
48
48
  // }
49
49
  };
50
+ exports.downloadDocsPortal = downloadDocsPortal;
@@ -4,15 +4,15 @@ exports.downloadGeneratedSDK = exports.getSDKGenerationId = void 0;
4
4
  const fs = require("fs-extra");
5
5
  const cli_ux_1 = require("cli-ux");
6
6
  const sdk_1 = require("@apimatic/sdk");
7
- const core_1 = require("@apimatic/core");
7
+ const sdk_2 = require("@apimatic/sdk");
8
8
  const generate_1 = require("../../types/sdk/generate");
9
9
  const utils_1 = require("../../utils/utils");
10
- exports.getSDKGenerationId = async ({ file, url, platform }, sdkGenerationController) => {
10
+ const getSDKGenerationId = async ({ file, url, platform }, sdkGenerationController) => {
11
11
  cli_ux_1.default.action.start("Generating SDK");
12
12
  let generation;
13
13
  const sdkPlatform = getSDKPlatform(platform);
14
14
  if (file) {
15
- const fileDescriptor = new core_1.FileWrapper(fs.createReadStream(file));
15
+ const fileDescriptor = new sdk_2.FileWrapper(fs.createReadStream(file));
16
16
  generation = await sdkGenerationController.generateSDKViaFile(fileDescriptor, sdkPlatform);
17
17
  }
18
18
  else if (url) {
@@ -29,6 +29,7 @@ exports.getSDKGenerationId = async ({ file, url, platform }, sdkGenerationContro
29
29
  cli_ux_1.default.action.stop();
30
30
  return generation.result.id;
31
31
  };
32
+ exports.getSDKGenerationId = getSDKGenerationId;
32
33
  // Get valid platform from user's input, convert simple platform to valid Platforms enum value
33
34
  const getSDKPlatform = (platform) => {
34
35
  if (Object.keys(generate_1.SimplePlatforms).includes(platform)) {
@@ -43,17 +44,17 @@ const getSDKPlatform = (platform) => {
43
44
  }
44
45
  };
45
46
  // Download Platform
46
- exports.downloadGeneratedSDK = async ({ codeGenId, zippedSDKPath, sdkFolderPath, zip }, sdkGenerationController) => {
47
+ const downloadGeneratedSDK = async ({ codeGenId, zippedSDKPath, sdkFolderPath, zip }, sdkGenerationController) => {
47
48
  cli_ux_1.default.action.start("Downloading SDK");
48
49
  const { result } = await sdkGenerationController.downloadSDK(codeGenId);
49
50
  if (result.readable) {
50
51
  if (!zip) {
51
- await utils_1.unzipFile(result, sdkFolderPath);
52
+ await (0, utils_1.unzipFile)(result, sdkFolderPath);
52
53
  cli_ux_1.default.action.stop();
53
54
  return sdkFolderPath;
54
55
  }
55
56
  else {
56
- await utils_1.writeFileUsingReadableStream(result, zippedSDKPath);
57
+ await (0, utils_1.writeFileUsingReadableStream)(result, zippedSDKPath);
57
58
  cli_ux_1.default.action.stop();
58
59
  return zippedSDKPath;
59
60
  }
@@ -62,3 +63,4 @@ exports.downloadGeneratedSDK = async ({ codeGenId, zippedSDKPath, sdkFolderPath,
62
63
  throw new Error("Couldn't download the SDK");
63
64
  }
64
65
  };
66
+ exports.downloadGeneratedSDK = downloadGeneratedSDK;
package/lib/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.run = void 0;
3
4
  var command_1 = require("@oclif/command");
4
5
  Object.defineProperty(exports, "run", { enumerable: true, get: function () { return command_1.run; } });
@@ -1,16 +1,16 @@
1
1
  /// <reference types="node" />
2
2
  import { TransformationController } from "@apimatic/sdk";
3
- export declare type TransformationIdParams = {
3
+ export type TransformationIdParams = {
4
4
  file: string;
5
5
  url: string;
6
6
  format: string;
7
7
  };
8
- export declare type DownloadTransformationParams = {
8
+ export type DownloadTransformationParams = {
9
9
  id: string;
10
10
  destinationFilePath: string;
11
11
  transformationController: TransformationController;
12
12
  };
13
- export declare type TransformationData = {
13
+ export type TransformationData = {
14
14
  result: NodeJS.ReadableStream | Blob;
15
15
  };
16
16
  export declare const DestinationFormats: {
@@ -1,12 +1,12 @@
1
- export declare type GetValidationParams = {
1
+ export type GetValidationParams = {
2
2
  file: string;
3
3
  url: string;
4
4
  };
5
- export declare type APIValidateError = {
5
+ export type APIValidateError = {
6
6
  modelState: {
7
7
  "exception Error": string[];
8
8
  };
9
9
  };
10
- export declare type AuthorizationError = {
10
+ export type AuthorizationError = {
11
11
  body: string;
12
12
  };
@@ -1,5 +1,5 @@
1
1
  import { DocsPortalManagementController } from "@apimatic/sdk";
2
- export declare type GeneratePortalParams = {
2
+ export type GeneratePortalParams = {
3
3
  zippedBuildFilePath: string;
4
4
  portalFolderPath: string;
5
5
  zippedPortalPath: string;
@@ -1,15 +1,15 @@
1
- export declare type GenerationIdParams = {
1
+ export type GenerationIdParams = {
2
2
  file: string;
3
3
  url: string;
4
4
  platform: string;
5
5
  };
6
- export declare type DownloadSDKParams = {
6
+ export type DownloadSDKParams = {
7
7
  codeGenId: string;
8
8
  zip: boolean;
9
9
  zippedSDKPath: string;
10
10
  sdkFolderPath: string;
11
11
  };
12
- export declare type SDKGenerateUnprocessableError = {
12
+ export type SDKGenerateUnprocessableError = {
13
13
  message: string;
14
14
  };
15
15
  export declare enum SimplePlatforms {
@@ -9,4 +9,4 @@ var SimplePlatforms;
9
9
  SimplePlatforms["PYTHON"] = "PYTHON_GENERIC_LIB";
10
10
  SimplePlatforms["RUBY"] = "RUBY_GENERIC_LIB";
11
11
  SimplePlatforms["TYPESCRIPT"] = "TS_GENERIC_LIB";
12
- })(SimplePlatforms = exports.SimplePlatforms || (exports.SimplePlatforms = {}));
12
+ })(SimplePlatforms || (exports.SimplePlatforms = SimplePlatforms = {}));
@@ -1,14 +1,14 @@
1
- export declare type ValidationMessages = {
1
+ export type ValidationMessages = {
2
2
  messages: string[];
3
3
  warnings: string[];
4
4
  errors: string[];
5
5
  };
6
- export declare type loggers = {
6
+ export type loggers = {
7
7
  log: (message: string) => void;
8
8
  warn: (message: string) => void;
9
9
  error: (message: string) => void;
10
10
  };
11
- export declare type AuthenticationError = {
11
+ export type AuthenticationError = {
12
12
  statusCode: number;
13
13
  body: string;
14
14
  };
@@ -7,7 +7,7 @@ const fs = require("fs-extra");
7
7
  const archiver = require("archiver");
8
8
  const unzipper = require("unzipper");
9
9
  const stripTags = require("striptags");
10
- exports.unzipFile = (stream, destination) => {
10
+ const unzipFile = (stream, destination) => {
11
11
  return new Promise((resolve, reject) => {
12
12
  stream.pipe(unzipper.Extract({ path: destination }));
13
13
  stream.on("close", (error) => {
@@ -18,10 +18,12 @@ exports.unzipFile = (stream, destination) => {
18
18
  });
19
19
  });
20
20
  };
21
- exports.deleteFile = async (filePath) => {
21
+ exports.unzipFile = unzipFile;
22
+ const deleteFile = async (filePath) => {
22
23
  return await fs.remove(filePath);
23
24
  };
24
- exports.writeFileUsingReadableStream = (stream, destinationPath) => {
25
+ exports.deleteFile = deleteFile;
26
+ const writeFileUsingReadableStream = (stream, destinationPath) => {
25
27
  return new Promise((resolve, reject) => {
26
28
  const writeStream = fs.createWriteStream(destinationPath);
27
29
  stream.pipe(writeStream);
@@ -33,6 +35,7 @@ exports.writeFileUsingReadableStream = (stream, destinationPath) => {
33
35
  });
34
36
  });
35
37
  };
38
+ exports.writeFileUsingReadableStream = writeFileUsingReadableStream;
36
39
  /**
37
40
  * Packages local files into a ZIP archive
38
41
  *
@@ -40,7 +43,7 @@ exports.writeFileUsingReadableStream = (stream, destinationPath) => {
40
43
  * @param {destinationZipPath} path to generated zip
41
44
  * return {string}
42
45
  */
43
- exports.zipDirectory = async (sourcePath, destinationPath) => {
46
+ const zipDirectory = async (sourcePath, destinationPath) => {
44
47
  // Check if the directory exists for the user or not
45
48
  await fs.ensureDir(sourcePath);
46
49
  const zipPath = path.join(destinationPath, "target.zip");
@@ -55,6 +58,7 @@ exports.zipDirectory = async (sourcePath, destinationPath) => {
55
58
  await archive.finalize();
56
59
  return zipPath;
57
60
  };
61
+ exports.zipDirectory = zipDirectory;
58
62
  // TODO: Instead of making progressBar a static, you should have "startProgress"
59
63
  // return the instance of the progress bar created, the same way "cli.progress"
60
64
  // method does.
@@ -66,7 +70,7 @@ let progressBar;
66
70
  // get size from the file size and in case of download, you get it from the
67
71
  // content-type header). In case the progress can not be calculated, show a
68
72
  // spinner.
69
- exports.startProgress = (title) => {
73
+ const startProgress = (title) => {
70
74
  progressBar = cli_ux_1.default.progress({
71
75
  format: `${title} | {bar}`,
72
76
  barCompleteChar: "\u2588",
@@ -83,17 +87,20 @@ exports.startProgress = (title) => {
83
87
  }
84
88
  }, 50);
85
89
  };
86
- exports.stopProgress = (isError = false) => {
90
+ exports.startProgress = startProgress;
91
+ const stopProgress = (isError = false) => {
87
92
  if (isError) {
88
93
  return progressBar ? progressBar.stop() : null;
89
94
  }
90
95
  progressBar.update(100);
91
96
  return progressBar.stop();
92
97
  };
93
- exports.replaceHTML = (string) => {
98
+ exports.stopProgress = stopProgress;
99
+ const replaceHTML = (string) => {
94
100
  return stripTags(string);
95
101
  };
96
- exports.isJSONParsable = (json) => {
102
+ exports.replaceHTML = replaceHTML;
103
+ const isJSONParsable = (json) => {
97
104
  try {
98
105
  JSON.parse(json);
99
106
  return true;
@@ -102,20 +109,23 @@ exports.isJSONParsable = (json) => {
102
109
  return false;
103
110
  }
104
111
  };
105
- exports.getFileNameFromPath = (filePath) => {
112
+ exports.isJSONParsable = isJSONParsable;
113
+ const getFileNameFromPath = (filePath) => {
106
114
  return path.basename(filePath).split(".")[0];
107
115
  };
108
- exports.printValidationMessages = ({ warnings, errors, messages }, { log, warn, error }) => {
116
+ exports.getFileNameFromPath = getFileNameFromPath;
117
+ const printValidationMessages = ({ warnings, errors, messages }, { log, warn, error }) => {
109
118
  warnings = warnings || [];
110
119
  messages = messages || [];
111
120
  const singleError = errors.join("\n") || "";
112
121
  messages.forEach((message) => {
113
- log(`Info: ${exports.replaceHTML(message)}`);
122
+ log(`Info: ${(0, exports.replaceHTML)(message)}`);
114
123
  });
115
124
  warnings.forEach((warning) => {
116
- warn(exports.replaceHTML(warning));
125
+ warn((0, exports.replaceHTML)(warning));
117
126
  });
118
127
  if (errors.length > 0) {
119
- error(exports.replaceHTML(singleError));
128
+ error((0, exports.replaceHTML)(singleError));
120
129
  }
121
130
  };
131
+ exports.printValidationMessages = printValidationMessages;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@apimatic/cli",
3
3
  "description": "The official CLI for APIMatic.",
4
- "version": "1.1.0-alpha.2",
4
+ "version": "1.1.0-alpha.4",
5
5
  "author": "APIMatic",
6
6
  "bin": {
7
7
  "apimatic": "./bin/run"
@@ -43,7 +43,7 @@
43
43
  "lint:fix": "eslint --fix \"src/**/*.{js,ts}\" --quiet"
44
44
  },
45
45
  "dependencies": {
46
- "@apimatic/sdk": "^0.0.1-alpha.10",
46
+ "@apimatic/sdk": "^0.1.0-alpha.2",
47
47
  "@oclif/command": "^1.8.0",
48
48
  "@oclif/config": "^1.17.0",
49
49
  "@oclif/plugin-autocomplete": "^0.3.0",
@@ -63,7 +63,7 @@
63
63
  "@commitlint/config-conventional": "^15.0.0",
64
64
  "@oclif/dev-cli": "^1.26.0",
65
65
  "@oclif/test": "^1.2.8",
66
- "@semantic-release/changelog": "^6.0.1",
66
+ "@semantic-release/changelog": "^6.0.3",
67
67
  "@semantic-release/git": "^10.0.1",
68
68
  "@types/archiver": "^5.1.1",
69
69
  "@types/axios": "^0.14.0",
@@ -87,7 +87,7 @@
87
87
  "prettier": "^2.4.1",
88
88
  "rimraf": "^3.0.2",
89
89
  "ts-node": "^8.10.2",
90
- "typescript": "^3.9.10"
90
+ "typescript": "^5.2.2"
91
91
  },
92
92
  "oclif": {
93
93
  "commands": "./lib/commands",