@apimatic/cli 1.0.1-alpha.9 → 1.1.0-alpha.3

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 CHANGED
@@ -15,11 +15,11 @@ The official CLI for APIMatic.
15
15
  # Usage
16
16
  <!-- usage -->
17
17
  ```sh-session
18
- $ npm install -g @apimatic/cli
18
+ $ npm install -g @apimatic/cli@1.0.1-alpha.3
19
19
  $ apimatic COMMAND
20
20
  running command...
21
21
  $ apimatic (-v|--version|version)
22
- @apimatic/cli/1.0.1-alpha.9 linux-x64 node-v16.13.0
22
+ @apimatic/cli/0.0.0-alpha.3 linux-x64 node-v16.13.0
23
23
  $ apimatic --help [COMMAND]
24
24
  USAGE
25
25
  $ apimatic COMMAND
@@ -71,7 +71,7 @@ EXAMPLES
71
71
  Success! Your transformed file is located at D:/swagger_raml.yaml
72
72
  ```
73
73
 
74
- _See code: [src/commands/api/transform.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.9/src/commands/api/transform.ts)_
74
+ _See code: [src/commands/api/transform.ts](https://github.com/apimatic/apimatic-cli/blob/v0.0.0-alpha.3/src/commands/api/transform.ts)_
75
75
 
76
76
  ## `apimatic api:validate`
77
77
 
@@ -96,7 +96,7 @@ EXAMPLES
96
96
  Specification file provided is valid
97
97
  ```
98
98
 
99
- _See code: [src/commands/api/validate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.9/src/commands/api/validate.ts)_
99
+ _See code: [src/commands/api/validate.ts](https://github.com/apimatic/apimatic-cli/blob/v0.0.0-alpha.3/src/commands/api/validate.ts)_
100
100
 
101
101
  ## `apimatic auth:login`
102
102
 
@@ -120,7 +120,7 @@ EXAMPLES
120
120
  Authentication key successfully set
121
121
  ```
122
122
 
123
- _See code: [src/commands/auth/login.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.9/src/commands/auth/login.ts)_
123
+ _See code: [src/commands/auth/login.ts](https://github.com/apimatic/apimatic-cli/blob/v0.0.0-alpha.3/src/commands/auth/login.ts)_
124
124
 
125
125
  ## `apimatic auth:logout`
126
126
 
@@ -135,7 +135,7 @@ EXAMPLE
135
135
  Logged out
136
136
  ```
137
137
 
138
- _See code: [src/commands/auth/logout.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.9/src/commands/auth/logout.ts)_
138
+ _See code: [src/commands/auth/logout.ts](https://github.com/apimatic/apimatic-cli/blob/v0.0.0-alpha.3/src/commands/auth/logout.ts)_
139
139
 
140
140
  ## `apimatic auth:status`
141
141
 
@@ -150,7 +150,7 @@ EXAMPLE
150
150
  Currently logged in as apimatic-client@gmail.com
151
151
  ```
152
152
 
153
- _See code: [src/commands/auth/status.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.9/src/commands/auth/status.ts)_
153
+ _See code: [src/commands/auth/status.ts](https://github.com/apimatic/apimatic-cli/blob/v0.0.0-alpha.3/src/commands/auth/status.ts)_
154
154
 
155
155
  ## `apimatic autocomplete [SHELL]`
156
156
 
@@ -190,7 +190,7 @@ OPTIONS
190
190
  --all see all commands in CLI
191
191
  ```
192
192
 
193
- _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.12/src/commands/help.ts)_
193
+ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.14/src/commands/help.ts)_
194
194
 
195
195
  ## `apimatic portal:generate`
196
196
 
@@ -212,7 +212,7 @@ EXAMPLE
212
212
  Your portal has been generated at D:/
213
213
  ```
214
214
 
215
- _See code: [src/commands/portal/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.9/src/commands/portal/generate.ts)_
215
+ _See code: [src/commands/portal/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v0.0.0-alpha.3/src/commands/portal/generate.ts)_
216
216
 
217
217
  ## `apimatic sdk:generate`
218
218
 
@@ -254,5 +254,5 @@ EXAMPLES
254
254
  Success! Your SDK is located at swagger_sdk_csharp
255
255
  ```
256
256
 
257
- _See code: [src/commands/sdk/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.9/src/commands/sdk/generate.ts)_
257
+ _See code: [src/commands/sdk/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v0.0.0-alpha.3/src/commands/sdk/generate.ts)_
258
258
  <!-- commandsstop -->
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setAuthInfo = exports.getAuthInfo = void 0;
4
- const fs = require("fs-extra");
5
4
  const path = require("path");
5
+ const fs = require("fs-extra");
6
6
  /**
7
7
  *
8
8
  * @param {string} configDir <- Directory with user configuration
@@ -1,8 +1,8 @@
1
1
  import { Client } from "@apimatic/sdk";
2
2
  export declare class SDKClient {
3
+ static client: Client;
3
4
  private static instance;
4
5
  private static authAPI;
5
- static client: Client;
6
6
  /**
7
7
  * The static method that controls the access to the SDKClient instance.
8
8
  *
@@ -4,8 +4,8 @@ exports.SDKClient = void 0;
4
4
  const base64 = require("base-64");
5
5
  const axios_1 = require("axios");
6
6
  const sdk_1 = require("@apimatic/sdk");
7
- const auth_manager_1 = require("./auth-manager");
8
7
  const env_1 = require("../config/env");
8
+ const auth_manager_1 = require("./auth-manager");
9
9
  class SDKClient {
10
10
  constructor() {
11
11
  this.setAuthKey = (authKey, configDir) => {
@@ -1,18 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const fs = require("fs-extra");
4
3
  const path = require("path");
5
- const sdk_1 = require("@apimatic/sdk");
4
+ const fs = require("fs-extra");
6
5
  const command_1 = require("@oclif/command");
6
+ const sdk_1 = require("@apimatic/sdk");
7
7
  const sdk_client_1 = require("../../client-utils/sdk-client");
8
8
  const utils_1 = require("../../utils/utils");
9
+ const utils_2 = require("../../utils/utils");
9
10
  const transform_1 = require("../../types/api/transform");
10
11
  const transform_2 = require("../../controllers/api/transform");
11
12
  const formats = Object.keys(sdk_1.ExportFormats).join("|");
12
13
  class Transform extends command_1.Command {
13
14
  async run() {
14
15
  const { flags } = this.parse(Transform);
15
- const fileName = flags.file ? utils_1.getFileNameFromPath(flags.file) : utils_1.getFileNameFromPath(flags.url);
16
+ const fileName = flags.file ? utils_2.getFileNameFromPath(flags.file) : utils_2.getFileNameFromPath(flags.url);
16
17
  const destinationFormat = transform_1.DestinationFormats[flags.format];
17
18
  const destinationFilePath = path.join(flags.destination, `${fileName}_${flags.format}.${destinationFormat}`.toLowerCase());
18
19
  // Check if destination file already exist and throw error if force flag is not set
@@ -31,7 +32,12 @@ class Transform extends command_1.Command {
31
32
  const client = await sdk_client_1.SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
32
33
  const transformationController = new sdk_1.TransformationController(client);
33
34
  const { id, apiValidationSummary } = await transform_2.getTransformationId(flags, transformationController);
34
- transform_2.printValidationMessages(apiValidationSummary, this.warn, this.error);
35
+ const logFunctions = {
36
+ log: this.log,
37
+ warn: this.warn,
38
+ error: this.error
39
+ };
40
+ utils_1.printValidationMessages(apiValidationSummary, logFunctions);
35
41
  const savedTransformationFile = await transform_2.downloadTransformationFile({
36
42
  id,
37
43
  destinationFilePath,
@@ -46,19 +52,22 @@ class Transform extends command_1.Command {
46
52
  // updated to throw the right exception type for this status code.
47
53
  const result = apiError.result;
48
54
  if (apiError.statusCode === 422 && result && "errors" in result && Array.isArray(result.errors)) {
49
- this.error(utils_1.replaceHTML(`${result.errors}`));
55
+ this.error(utils_2.replaceHTML(`${result.errors}`));
50
56
  }
51
57
  else if (apiError.statusCode === 422 && apiError.body && typeof apiError.body === "string") {
52
58
  this.error(JSON.parse(apiError.body)["dto.FileUrl"][0]);
53
59
  }
54
60
  else if (apiError.statusCode === 401 && apiError.body && typeof apiError.body === "string") {
55
- this.error(apiError.body);
61
+ this.error("You are not authorized to perform this action");
56
62
  }
57
63
  else if (apiError.statusCode === 500) {
58
64
  this.error(apiError.message);
59
65
  }
60
66
  }
61
- else if (error.statusCode === 401 &&
67
+ else if (error.statusCode === 401) {
68
+ this.error("You are not authorized to perform this action");
69
+ }
70
+ else if (error.statusCode === 402 &&
62
71
  error.body &&
63
72
  typeof error.body === "string") {
64
73
  this.error(error.body);
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const fs = require("fs-extra");
4
- const sdk_1 = require("@apimatic/sdk");
5
4
  const command_1 = require("@oclif/command");
5
+ const sdk_1 = require("@apimatic/sdk");
6
6
  const sdk_client_1 = require("../../client-utils/sdk-client");
7
- const utils_1 = require("../../utils/utils");
8
- const transform_1 = require("../../controllers/api/transform");
9
7
  const validate_1 = require("../../controllers/api/validate");
8
+ const utils_1 = require("../../utils/utils");
10
9
  class Validate extends command_1.Command {
11
10
  async run() {
12
11
  const { flags } = this.parse(Validate);
@@ -18,7 +17,12 @@ class Validate extends command_1.Command {
18
17
  const client = await sdk_client_1.SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
19
18
  const apiValidationController = new sdk_1.APIValidationExternalApisController(client);
20
19
  const validationSummary = await validate_1.getValidation(flags, apiValidationController);
21
- transform_1.printValidationMessages(validationSummary, this.warn, this.error);
20
+ const logFunctions = {
21
+ log: this.log,
22
+ warn: this.warn,
23
+ error: this.error
24
+ };
25
+ utils_1.printValidationMessages(validationSummary, logFunctions);
22
26
  validationSummary.success
23
27
  ? this.log("Specification file provided is valid")
24
28
  : this.error("Specification file provided is invalid");
@@ -31,12 +35,20 @@ class Validate extends command_1.Command {
31
35
  this.error(utils_1.replaceHTML(result.modelState["exception Error"][0]));
32
36
  }
33
37
  else if (error.body && apiError.statusCode === 401) {
34
- this.error(error.body);
38
+ this.error("You are not authorized to perform this action");
35
39
  }
36
40
  else {
37
41
  this.error(error.message);
38
42
  }
39
43
  }
44
+ else if (error.statusCode === 401) {
45
+ this.error("You are not authorized to perform this action");
46
+ }
47
+ else if (error.statusCode === 402 &&
48
+ error.body &&
49
+ typeof error.body === "string") {
50
+ this.error(error.body);
51
+ }
40
52
  else {
41
53
  this.error(`${error.message}`);
42
54
  }
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const command_1 = require("@oclif/command");
4
3
  const cli_ux_1 = require("cli-ux");
5
- const sdk_client_1 = require("../../client-utils/sdk-client");
4
+ const command_1 = require("@oclif/command");
6
5
  const utils_1 = require("../../utils/utils");
6
+ const sdk_client_1 = require("../../client-utils/sdk-client");
7
7
  class Login extends command_1.Command {
8
8
  async run() {
9
9
  const { flags } = this.parse(Login);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const fs = require("fs-extra");
4
3
  const path = require("path");
4
+ const fs = require("fs-extra");
5
5
  const command_1 = require("@oclif/command");
6
6
  const sdk_1 = require("@apimatic/sdk");
7
7
  const sdk_client_1 = require("../../client-utils/sdk-client");
@@ -59,16 +59,24 @@ class PortalGenerate extends command_1.Command {
59
59
  }
60
60
  }
61
61
  else if (apiResponse.status === 401 && responseData.length > 0) {
62
- this.error(utils_1.replaceHTML(responseData));
62
+ this.error("You are not authorized to perform this action");
63
63
  }
64
64
  else if (apiResponse.status === 403 && apiResponse.statusText) {
65
- return this.error(utils_1.replaceHTML(apiResponse.statusText));
65
+ return this.error("Your subscription does not allow on premise portal generation");
66
66
  }
67
67
  else {
68
68
  return this.error(apiError.message);
69
69
  }
70
70
  }
71
71
  }
72
+ else if (error.statusCode === 401) {
73
+ this.error("You are not authorized to perform this action");
74
+ }
75
+ else if (error.statusCode === 402 &&
76
+ error.body &&
77
+ typeof error.body === "string") {
78
+ this.error(error.body);
79
+ }
72
80
  else {
73
81
  this.error(`${error.message}`);
74
82
  }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const fs = require("fs-extra");
4
3
  const path = require("path");
5
- const sdk_1 = require("@apimatic/sdk");
4
+ const fs = require("fs-extra");
6
5
  const command_1 = require("@oclif/command");
7
6
  const sdk_client_1 = require("../../client-utils/sdk-client");
7
+ const sdk_1 = require("@apimatic/sdk");
8
8
  const utils_1 = require("../../utils/utils");
9
9
  const generate_1 = require("../../controllers/sdk/generate");
10
10
  class SdkGenerate extends command_1.Command {
@@ -54,7 +54,7 @@ class SdkGenerate extends command_1.Command {
54
54
  }
55
55
  }
56
56
  else if (apiError.statusCode === 401 && apiError.body && typeof apiError.body === "string") {
57
- this.error(apiError.body);
57
+ this.error("You are not authorized to perform this action");
58
58
  }
59
59
  else if (apiError.statusCode === 500 &&
60
60
  apiError.body &&
@@ -72,6 +72,14 @@ class SdkGenerate extends command_1.Command {
72
72
  this.error(utils_1.replaceHTML(result.message));
73
73
  }
74
74
  }
75
+ else if (error.statusCode === 401) {
76
+ this.error("You are not authorized to perform this action");
77
+ }
78
+ else if (error.statusCode === 402 &&
79
+ error.body &&
80
+ typeof error.body === "string") {
81
+ this.error(utils_1.replaceHTML(error.body));
82
+ }
75
83
  else {
76
84
  this.error(`${error.message}`);
77
85
  }
@@ -86,9 +94,7 @@ SdkGenerate.flags = {
86
94
  required: true,
87
95
  description: `language platform for sdk
88
96
  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`
97
+ Legacy: CS_NET_STANDARD_LIB|JAVA_ECLIPSE_JRE_LIB|PHP_GENERIC_LIB|PYTHON_GENERIC_LIB|RUBY_GENERIC_LIB|TS_GENERIC_LIB`
92
98
  }),
93
99
  file: command_1.flags.string({
94
100
  parse: (input) => path.resolve(input),
@@ -1 +1 @@
1
- export declare const baseURL = "https://apimaticio-test.azurewebsites.net/api";
1
+ export declare const baseURL = "https://www.apimatic.io/api";
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://apimaticio-test.azurewebsites.net/api";
4
+ exports.baseURL = "https://www.apimatic.io/api";
@@ -1,7 +1,5 @@
1
- import Command from "@oclif/command";
2
- import { ApiValidationSummary, ExportFormats, Transformation, TransformationController } from "@apimatic/sdk";
3
1
  import { DownloadTransformationParams, TransformationIdParams } from "../../types/api/transform";
2
+ import { ExportFormats, Transformation, TransformationController } from "@apimatic/sdk";
4
3
  export declare const getTransformationId: ({ file, url, format }: TransformationIdParams, transformationController: TransformationController) => Promise<Transformation>;
5
4
  export declare const downloadTransformationFile: ({ id, destinationFilePath, transformationController }: DownloadTransformationParams) => Promise<string>;
6
5
  export declare const getValidFormat: (format: string) => ExportFormats;
7
- export declare const printValidationMessages: (apiValidationSummary: ApiValidationSummary | undefined, warn: Command["warn"], error: Command["error"]) => void;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.printValidationMessages = exports.getValidFormat = exports.downloadTransformationFile = exports.getTransformationId = void 0;
3
+ exports.getValidFormat = exports.downloadTransformationFile = exports.getTransformationId = void 0;
4
4
  const cli_ux_1 = require("cli-ux");
5
5
  const fs = require("fs-extra");
6
- const sdk_1 = require("@apimatic/sdk");
7
6
  const utils_1 = require("../../utils/utils");
7
+ const sdk_1 = require("@apimatic/sdk");
8
8
  exports.getTransformationId = async ({ file, url, format }, transformationController) => {
9
9
  cli_ux_1.default.action.start("Transforming API specification");
10
10
  let generation;
@@ -47,13 +47,3 @@ exports.getValidFormat = (format) => {
47
47
  throw new Error(`Please provide a valid platform i.e. ${formats}`);
48
48
  }
49
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
- };
@@ -1,5 +1,3 @@
1
- import Command from "@oclif/command";
2
- import { APIValidationExternalApisController, ApiValidationSummary } from "@apimatic/sdk";
3
1
  import { GetValidationParams } from "../../types/api/validate";
2
+ import { APIValidationExternalApisController, ApiValidationSummary } from "@apimatic/sdk";
4
3
  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;
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.printValidationMessages = exports.getValidation = void 0;
3
+ exports.getValidation = void 0;
4
4
  const cli_ux_1 = require("cli-ux");
5
5
  const fs = require("fs-extra");
6
6
  const core_1 = require("@apimatic/core");
7
- const utils_1 = require("../../utils/utils");
8
7
  exports.getValidation = async ({ file, url }, apiValidationController) => {
9
8
  let validation;
10
9
  cli_ux_1.default.action.start("Validating specification file");
@@ -21,12 +20,3 @@ exports.getValidation = async ({ file, url }, apiValidationController) => {
21
20
  cli_ux_1.default.action.stop();
22
21
  return validation.result;
23
22
  };
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
- };
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.downloadDocsPortal = void 0;
4
+ const cli_ux_1 = require("cli-ux");
4
5
  const fs = require("fs-extra");
5
6
  const FormData = require("form-data");
6
- const cli_ux_1 = require("cli-ux");
7
- const auth_manager_1 = require("../../client-utils/auth-manager");
8
7
  const env_1 = require("../../config/env");
9
8
  const utils_1 = require("../../utils/utils");
9
+ const auth_manager_1 = require("../../client-utils/auth-manager");
10
10
  const axios_1 = require("axios");
11
11
  // TODO: Remove after SDK is patched
12
12
  const downloadPortalAxios = async (zippedBuildFilePath, overrideAuthKey, configDir) => {
@@ -14,7 +14,7 @@ const downloadPortalAxios = async (zippedBuildFilePath, overrideAuthKey, configD
14
14
  const authInfo = await auth_manager_1.getAuthInfo(configDir);
15
15
  formData.append("file", fs.createReadStream(zippedBuildFilePath));
16
16
  const config = {
17
- headers: Object.assign({ Authorization: authInfo ? `X-Auth-Key ${overrideAuthKey || authInfo.authKey.trim()}` : "", "Content-Type": "multipart/form-data" }, 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);
@@ -1,9 +1,5 @@
1
1
  /// <reference types="node" />
2
2
  import { TransformationController } from "@apimatic/sdk";
3
- export declare type AuthenticationError = {
4
- statusCode: number;
5
- body: string;
6
- };
7
3
  export declare type TransformationIdParams = {
8
4
  file: string;
9
5
  url: string;
@@ -30,4 +26,5 @@ export declare const DestinationFormats: {
30
26
  RAML10: string;
31
27
  Postman10: string;
32
28
  Postman20: string;
29
+ GraphQlSchema: string;
33
30
  };
@@ -13,5 +13,6 @@ exports.DestinationFormats = {
13
13
  RAML: "yaml",
14
14
  RAML10: "yaml",
15
15
  Postman10: "json",
16
- Postman20: "json"
16
+ Postman20: "json",
17
+ GraphQlSchema: "json"
17
18
  };
@@ -0,0 +1,14 @@
1
+ export declare type ValidationMessages = {
2
+ messages: string[];
3
+ warnings: string[];
4
+ errors: string[];
5
+ };
6
+ export declare type loggers = {
7
+ log: (message: string) => void;
8
+ warn: (message: string) => void;
9
+ error: (message: string) => void;
10
+ };
11
+ export declare type AuthenticationError = {
12
+ statusCode: number;
13
+ body: string;
14
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="mocha" />
3
+ import { loggers, ValidationMessages } from "../types/utils";
3
4
  export declare const unzipFile: (stream: NodeJS.ReadableStream, destination: string) => Promise<unknown>;
4
5
  export declare const deleteFile: (filePath: string) => Promise<void>;
5
6
  export declare const writeFileUsingReadableStream: (stream: NodeJS.ReadableStream, destinationPath: string) => Promise<unknown>;
@@ -16,3 +17,4 @@ export declare const stopProgress: (isError?: boolean) => void | null;
16
17
  export declare const replaceHTML: (string: string) => string;
17
18
  export declare const isJSONParsable: (json: string) => boolean;
18
19
  export declare const getFileNameFromPath: (filePath: string) => string;
20
+ export declare const printValidationMessages: ({ warnings, errors, messages }: ValidationMessages, { log, warn, error }: loggers) => void;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFileNameFromPath = exports.isJSONParsable = exports.replaceHTML = exports.stopProgress = exports.startProgress = exports.zipDirectory = exports.writeFileUsingReadableStream = exports.deleteFile = exports.unzipFile = void 0;
4
- const fs = require("fs-extra");
3
+ exports.printValidationMessages = exports.getFileNameFromPath = exports.isJSONParsable = exports.replaceHTML = exports.stopProgress = exports.startProgress = exports.zipDirectory = exports.writeFileUsingReadableStream = exports.deleteFile = exports.unzipFile = void 0;
4
+ const cli_ux_1 = require("cli-ux");
5
5
  const path = require("path");
6
+ const fs = require("fs-extra");
6
7
  const archiver = require("archiver");
7
8
  const unzipper = require("unzipper");
8
9
  const stripTags = require("striptags");
9
- const cli_ux_1 = require("cli-ux");
10
10
  exports.unzipFile = (stream, destination) => {
11
11
  return new Promise((resolve, reject) => {
12
12
  stream.pipe(unzipper.Extract({ path: destination }));
@@ -105,3 +105,17 @@ exports.isJSONParsable = (json) => {
105
105
  exports.getFileNameFromPath = (filePath) => {
106
106
  return path.basename(filePath).split(".")[0];
107
107
  };
108
+ exports.printValidationMessages = ({ warnings, errors, messages }, { log, warn, error }) => {
109
+ warnings = warnings || [];
110
+ messages = messages || [];
111
+ const singleError = errors.join("\n") || "";
112
+ messages.forEach((message) => {
113
+ log(`Info: ${exports.replaceHTML(message)}`);
114
+ });
115
+ warnings.forEach((warning) => {
116
+ warn(exports.replaceHTML(warning));
117
+ });
118
+ if (errors.length > 0) {
119
+ error(exports.replaceHTML(singleError));
120
+ }
121
+ };
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.0.1-alpha.9",
4
+ "version": "1.1.0-alpha.3",
5
5
  "author": "APIMatic",
6
6
  "bin": {
7
7
  "apimatic": "./bin/run"
@@ -36,16 +36,14 @@
36
36
  "build": "tsc -b",
37
37
  "postpack": "rimraf oclif.manifest.json",
38
38
  "posttest": "eslint . --ext .ts --config .eslintrc",
39
- "prepack": "rimraf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
40
39
  "test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
41
- "version": "oclif-dev readme && git add README.md",
42
40
  "prettier": "prettier \"src/**/*.{js,ts}\"",
43
41
  "format": "prettier --write \"src/**/*.{js,ts}\"",
44
42
  "lint": "eslint \"src/**/*.{js,ts}\"",
45
43
  "lint:fix": "eslint --fix \"src/**/*.{js,ts}\" --quiet"
46
44
  },
47
45
  "dependencies": {
48
- "@apimatic/sdk": "^0.0.1-alpha.1",
46
+ "@apimatic/sdk": "^0.1.0-alpha.1",
49
47
  "@oclif/command": "^1.8.0",
50
48
  "@oclif/config": "^1.17.0",
51
49
  "@oclif/plugin-autocomplete": "^0.3.0",
@@ -1 +0,0 @@
1
- {"version":"1.0.1-alpha.9","commands":{"api:transform":{"id":"api: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.","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$ apimatic api:transform --format=\"OpenApi3Json\" --file=\"./specs/sample.json\" --destination=\"D:/\"\nSuccess! Your transformed file is located at D:/Transformed_OpenApi3Json.json\n","$ apimatic api:transform --format=RAML --url=\"https://petstore.swagger.io/v2/swagger.json\" --destination=\"D:/\"\nSuccess! Your transformed file is located at D:/swagger_raml.yaml\n"],"flags":{"format":{"name":"format","type":"option","description":"specification format to transform API specification into\nAPIMATIC|WADL2009|WSDL|SWAGGER10|SWAGGER20|SWAGGERYAML|OAS3|OPENAPI3YAML|APIBLUEPRINT|RAML|RAML10|POSTMAN10|POSTMAN20|GRAPHQLSCHEMA","required":true},"file":{"name":"file","type":"option","description":"path to the API specification file to transform","default":""},"url":{"name":"url","type":"option","description":"URL to the API specification file to transform. Can be used in place of the --file option if the API specification is publicly available.","default":""},"destination":{"name":"destination","type":"option","description":"directory to download transformed file to","default":"/home/runner/work/apimatic-cli/apimatic-cli/cli"},"force":{"name":"force","type":"boolean","char":"f","description":"overwrite if same file exist in the destination","allowNo":false},"auth-key":{"name":"auth-key","type":"option","description":"override current authentication state with an authentication key"}},"args":[]},"api:validate":{"id":"api:validate","description":"Validate the syntactic and semantic correctness of an API specification","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$ apimatic api:validate --file=\"./specs/sample.json\"\nSpecification file provided is valid\n","$ apimatic api:validate --url=https://petstore.swagger.io/v2/swagger.json\nSpecification file provided is valid\n"],"flags":{"file":{"name":"file","type":"option","description":"Path to the API specification file to validate","default":""},"url":{"name":"url","type":"option","description":"URL to the specification file to validate. Can be used in place of the --file option if the API specification is publicly available.","default":""},"auth-key":{"name":"auth-key","type":"option","description":"override current authentication state with an authentication key"}},"args":[]},"auth:login":{"id":"auth:login","description":"Login using your APIMatic credentials or an API Key","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$ apimatic auth:login\nPlease enter your registered email: apimatic-user@gmail.com\nPlease enter your password: *********\n\nYou have successfully logged into APIMatic\n","$ apimatic auth:login --auth-key=xxxxxx\nAuthentication key successfully set"],"flags":{"auth-key":{"name":"auth-key","type":"option","description":"Set authentication key for all commands","default":""}},"args":[]},"auth:logout":{"id":"auth:logout","description":"Clear local login credentials","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$ apimatic auth:logout\nLogged out\n"],"flags":{},"args":[]},"auth:status":{"id":"auth:status","description":"View current authentication state","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$ apimatic auth:status\nCurrently logged in as apimatic-client@gmail.com\n"],"flags":{},"args":[]},"portal:generate":{"id":"portal:generate","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)","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$ apimatic portal:generate --folder=\"./portal/\" --destination=\"D:/\"\nYour portal has been generated at D:/\n"],"flags":{"folder":{"name":"folder","type":"option","description":"path to the input directory containing API specifications and config files","default":"./"},"destination":{"name":"destination","type":"option","description":"path to the downloaded portal","default":"/home/runner/work/apimatic-cli/apimatic-cli/cli"},"force":{"name":"force","type":"boolean","char":"f","description":"overwrite if a portal exists in the destination","allowNo":false},"zip":{"name":"zip","type":"boolean","description":"download the generated portal as a .zip archive","allowNo":false},"auth-key":{"name":"auth-key","type":"option","description":"override current authentication state with an authentication key","default":""}},"args":[]},"sdk:generate":{"id":"sdk:generate","description":"Generate SDK for your APIs","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$ apimatic sdk:generate --platform=\"CSHARP\" --file=\"./specs/sample.json\"\nGenerating SDK... done\nDownloading SDK... done\nSuccess! Your SDK is located at swagger_sdk_csharp","\n$ apimatic sdk:generate --platform=\"CSHARP\" --url=https://petstore.swagger.io/v2/swagger.json\nGenerating SDK... done\nDownloading SDK... done\nSuccess! Your SDK is located at swagger_sdk_csharp\n"],"flags":{"platform":{"name":"platform","type":"option","description":"language platform for sdk\nSimple: CSHARP|JAVA|PYTHON|RUBY|PHP|TYPESCRIPT\nLegacy: CS_NET_STANDARD_LIB|CS_PORTABLE_NET_LIB|CS_UNIVERSAL_WINDOWS_PLATFORM_LIB|\n JAVA_ECLIPSE_JRE_LIB|PHP_GENERIC_LIB|PYTHON_GENERIC_LIB|RUBY_GENERIC_LIB|\n TS_GENERIC_LIB","required":true},"file":{"name":"file","type":"option","description":"path to the API specification to generate SDKs for","default":""},"url":{"name":"url","type":"option","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.","default":""},"destination":{"name":"destination","type":"option","description":"directory to download the generated SDK to","default":"/home/runner/work/apimatic-cli/apimatic-cli/cli"},"force":{"name":"force","type":"boolean","char":"f","description":"overwrite if an SDK already exists in the destination","allowNo":false},"zip":{"name":"zip","type":"boolean","description":"download the generated SDK as a .zip archive","allowNo":false},"auth-key":{"name":"auth-key","type":"option","description":"override current authentication state with an authentication key","default":""}},"args":[]}}}