@apimatic/cli 1.0.1-alpha.6 → 1.0.2-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 CHANGED
@@ -1,10 +1,13 @@
1
1
  @apimatic/cli
2
2
  =============
3
+
3
4
  The official CLI for APIMatic.
5
+
4
6
  [![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
5
7
  [![Version](https://img.shields.io/npm/v/@apimatic/cli.svg)](https://npmjs.org/package/@apimatic/cli)
6
8
  [![Downloads/week](https://img.shields.io/npm/dw/@apimatic/cli.svg)](https://npmjs.org/package/@apimatic/cli)
7
9
  [![License](https://img.shields.io/npm/l/@apimatic/cli.svg)](https://github.com/apimatic/apimatic-cli/blob/master/package.json)
10
+
8
11
  <!-- toc -->
9
12
  * [Usage](#usage)
10
13
  * [Commands](#commands)
@@ -16,43 +19,26 @@ $ npm install -g @apimatic/cli
16
19
  $ apimatic COMMAND
17
20
  running command...
18
21
  $ apimatic (-v|--version|version)
19
- @apimatic/cli/1.0.1-alpha.6 linux-x64 node-v16.13.0
22
+ @apimatic/cli/0.0.0-alpha.3 linux-x64 node-v16.13.0
20
23
  $ apimatic --help [COMMAND]
21
24
  USAGE
22
25
  $ apimatic COMMAND
23
26
  ...
24
27
  ```
25
28
  <!-- usagestop -->
29
+
26
30
  # Commands
27
31
  <!-- commands -->
28
- * [`apimatic api`](#apimatic-api)
29
32
  * [`apimatic api:transform`](#apimatic-apitransform)
30
33
  * [`apimatic api:validate`](#apimatic-apivalidate)
31
- * [`apimatic auth`](#apimatic-auth)
32
34
  * [`apimatic auth:login`](#apimatic-authlogin)
33
35
  * [`apimatic auth:logout`](#apimatic-authlogout)
34
36
  * [`apimatic auth:status`](#apimatic-authstatus)
35
37
  * [`apimatic autocomplete [SHELL]`](#apimatic-autocomplete-shell)
36
38
  * [`apimatic help [COMMAND]`](#apimatic-help-command)
37
- * [`apimatic portal`](#apimatic-portal)
38
39
  * [`apimatic portal:generate`](#apimatic-portalgenerate)
39
- * [`apimatic sdk`](#apimatic-sdk)
40
40
  * [`apimatic sdk:generate`](#apimatic-sdkgenerate)
41
41
 
42
- ## `apimatic api`
43
-
44
- Manage APIs
45
-
46
- ```
47
- USAGE
48
- $ apimatic api
49
-
50
- EXAMPLE
51
- $ apimatic api --help
52
- ```
53
-
54
- _See code: [src/commands/api/index.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.6/src/commands/api/index.ts)_
55
-
56
42
  ## `apimatic api:transform`
57
43
 
58
44
  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.
@@ -71,8 +57,8 @@ OPTIONS
71
57
  --file=file path to the API specification file to transform
72
58
 
73
59
  --format=format (required) specification format to transform API specification into
74
- (OpenApi3Json|OpenApi3Yaml|APIMATIC|WADL2009|WADL2006|WSDL|
75
- Swagger10|Swagger20|SwaggerYaml|RAML|RAML10|Postman10|Postman20)
60
+ APIMATIC|WADL2009|WSDL|SWAGGER10|SWAGGER20|SWAGGERYAML|OAS3|OPENAPI3YAML|APIBLUEPRINT|RAML|
61
+ RAML10|POSTMAN10|POSTMAN20|GRAPHQLSCHEMA
76
62
 
77
63
  --url=url URL to the API specification file to transform. Can be used in place of the --file option
78
64
  if the API specification is publicly available.
@@ -85,7 +71,7 @@ EXAMPLES
85
71
  Success! Your transformed file is located at D:/swagger_raml.yaml
86
72
  ```
87
73
 
88
- _See code: [src/commands/api/transform.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.6/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)_
89
75
 
90
76
  ## `apimatic api:validate`
91
77
 
@@ -110,21 +96,7 @@ EXAMPLES
110
96
  Specification file provided is valid
111
97
  ```
112
98
 
113
- _See code: [src/commands/api/validate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.6/src/commands/api/validate.ts)_
114
-
115
- ## `apimatic auth`
116
-
117
- Manage this CLI's authentication state.
118
-
119
- ```
120
- USAGE
121
- $ apimatic auth
122
-
123
- EXAMPLE
124
- $ apimatic auth --help
125
- ```
126
-
127
- _See code: [src/commands/auth/index.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.6/src/commands/auth/index.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)_
128
100
 
129
101
  ## `apimatic auth:login`
130
102
 
@@ -148,7 +120,7 @@ EXAMPLES
148
120
  Authentication key successfully set
149
121
  ```
150
122
 
151
- _See code: [src/commands/auth/login.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.6/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)_
152
124
 
153
125
  ## `apimatic auth:logout`
154
126
 
@@ -163,7 +135,7 @@ EXAMPLE
163
135
  Logged out
164
136
  ```
165
137
 
166
- _See code: [src/commands/auth/logout.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.6/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)_
167
139
 
168
140
  ## `apimatic auth:status`
169
141
 
@@ -178,7 +150,7 @@ EXAMPLE
178
150
  Currently logged in as apimatic-client@gmail.com
179
151
  ```
180
152
 
181
- _See code: [src/commands/auth/status.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.6/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)_
182
154
 
183
155
  ## `apimatic autocomplete [SHELL]`
184
156
 
@@ -218,21 +190,7 @@ OPTIONS
218
190
  --all see all commands in CLI
219
191
  ```
220
192
 
221
- _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.10/src/commands/help.ts)_
222
-
223
- ## `apimatic portal`
224
-
225
- Manage API documentation portals
226
-
227
- ```
228
- USAGE
229
- $ apimatic portal
230
-
231
- EXAMPLE
232
- $apimatic portal --help
233
- ```
234
-
235
- _See code: [src/commands/portal/index.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.6/src/commands/portal/index.ts)_
193
+ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.14/src/commands/help.ts)_
236
194
 
237
195
  ## `apimatic portal:generate`
238
196
 
@@ -246,7 +204,7 @@ OPTIONS
246
204
  -f, --force overwrite if a portal exists in the destination
247
205
  --auth-key=auth-key override current authentication state with an authentication key
248
206
  --destination=destination [default: /home/runner/work/apimatic-cli/apimatic-cli/cli] path to the downloaded portal
249
- --folder=folder path to the input directory containing API specifications and config files
207
+ --folder=folder [default: ./] path to the input directory containing API specifications and config files
250
208
  --zip download the generated portal as a .zip archive
251
209
 
252
210
  EXAMPLE
@@ -254,21 +212,7 @@ EXAMPLE
254
212
  Your portal has been generated at D:/
255
213
  ```
256
214
 
257
- _See code: [src/commands/portal/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.6/src/commands/portal/generate.ts)_
258
-
259
- ## `apimatic sdk`
260
-
261
- Generate and manage SDKs for APIs
262
-
263
- ```
264
- USAGE
265
- $ apimatic sdk
266
-
267
- EXAMPLE
268
- $apimatic sdk --help
269
- ```
270
-
271
- _See code: [src/commands/sdk/index.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.6/src/commands/sdk/index.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)_
272
216
 
273
217
  ## `apimatic sdk:generate`
274
218
 
@@ -303,11 +247,12 @@ EXAMPLES
303
247
  Generating SDK... done
304
248
  Downloading SDK... done
305
249
  Success! Your SDK is located at swagger_sdk_csharp
250
+
306
251
  $ apimatic sdk:generate --platform="CSHARP" --url=https://petstore.swagger.io/v2/swagger.json
307
252
  Generating SDK... done
308
253
  Downloading SDK... done
309
254
  Success! Your SDK is located at swagger_sdk_csharp
310
255
  ```
311
256
 
312
- _See code: [src/commands/sdk/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.6/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)_
313
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 cli_ux_1 = require("cli-ux");
6
- const sdk_1 = require("@apimatic/sdk");
4
+ const fs = require("fs-extra");
7
5
  const command_1 = require("@oclif/command");
6
+ const sdk_1 = require("@apimatic/sdk");
8
7
  const sdk_client_1 = require("../../client-utils/sdk-client");
9
8
  const utils_1 = require("../../utils/utils");
9
+ const utils_2 = require("../../utils/utils");
10
10
  const transform_1 = require("../../types/api/transform");
11
11
  const transform_2 = require("../../controllers/api/transform");
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,
@@ -40,14 +46,13 @@ class Transform extends command_1.Command {
40
46
  this.log(`Success! Your transformed file is located at ${savedTransformationFile}`);
41
47
  }
42
48
  catch (error) {
43
- cli_ux_1.default.action.stop();
44
49
  if (error.result) {
45
50
  const apiError = error;
46
51
  // TODO: Hopefully, this type-cast won't be necessary when the SDK is
47
52
  // updated to throw the right exception type for this status code.
48
53
  const result = apiError.result;
49
54
  if (apiError.statusCode === 422 && result && "errors" in result && Array.isArray(result.errors)) {
50
- this.error(utils_1.replaceHTML(`${result.errors}`));
55
+ this.error(utils_2.replaceHTML(`${result.errors}`));
51
56
  }
52
57
  else if (apiError.statusCode === 422 && apiError.body && typeof apiError.body === "string") {
53
58
  this.error(JSON.parse(apiError.body)["dto.FileUrl"][0]);
@@ -85,8 +90,7 @@ Transform.flags = {
85
90
  parse: (format) => transform_2.getValidFormat(format.toUpperCase()),
86
91
  required: true,
87
92
  description: `specification format to transform API specification into
88
- (OpenApi3Json|OpenApi3Yaml|APIMATIC|WADL2009|WADL2006|WSDL|
89
- Swagger10|Swagger20|SwaggerYaml|RAML|RAML10|Postman10|Postman20)`
93
+ ${formats}`
90
94
  }),
91
95
  file: command_1.flags.string({
92
96
  parse: (input) => path.resolve(input),
@@ -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");
@@ -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,8 +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");
5
- const cli_ux_1 = require("cli-ux");
4
+ const fs = require("fs-extra");
6
5
  const command_1 = require("@oclif/command");
7
6
  const sdk_1 = require("@apimatic/sdk");
8
7
  const sdk_client_1 = require("../../client-utils/sdk-client");
@@ -45,7 +44,6 @@ class PortalGenerate extends command_1.Command {
45
44
  this.log(`Your portal has been generated at ${generatedPortalPath}`);
46
45
  }
47
46
  catch (error) {
48
- cli_ux_1.default.action.stop();
49
47
  if (error && error.response) {
50
48
  const apiError = error;
51
49
  const apiResponse = apiError.response;
@@ -60,7 +58,7 @@ class PortalGenerate extends command_1.Command {
60
58
  return this.error(utils_1.replaceHTML(nestedErrors.message));
61
59
  }
62
60
  }
63
- else if (apiResponse.status === 401 && responseData.length > 0 && utils_1.isJSONParsable(responseData)) {
61
+ else if (apiResponse.status === 401 && responseData.length > 0) {
64
62
  this.error(utils_1.replaceHTML(responseData));
65
63
  }
66
64
  else if (apiResponse.status === 403 && apiResponse.statusText) {
@@ -82,7 +80,7 @@ PortalGenerate.description = "Generate and download a static API Documentation p
82
80
  PortalGenerate.flags = {
83
81
  folder: command_1.flags.string({
84
82
  parse: (input) => path.resolve(input),
85
- default: "",
83
+ default: "./",
86
84
  description: "path to the input directory containing API specifications and config files"
87
85
  }),
88
86
  destination: command_1.flags.string({
@@ -1,11 +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 cli_ux_1 = require("cli-ux");
6
- const sdk_1 = require("@apimatic/sdk");
4
+ const fs = require("fs-extra");
7
5
  const command_1 = require("@oclif/command");
8
6
  const sdk_client_1 = require("../../client-utils/sdk-client");
7
+ const sdk_1 = require("@apimatic/sdk");
9
8
  const utils_1 = require("../../utils/utils");
10
9
  const generate_1 = require("../../controllers/sdk/generate");
11
10
  class SdkGenerate extends command_1.Command {
@@ -45,7 +44,6 @@ class SdkGenerate extends command_1.Command {
45
44
  this.log(`Success! Your SDK is located at ${sdkPath}`);
46
45
  }
47
46
  catch (error) {
48
- cli_ux_1.default.action.stop();
49
47
  if (error.result) {
50
48
  const apiError = error;
51
49
  const result = apiError.result;
@@ -122,7 +120,8 @@ SdkGenerate.examples = [
122
120
  Generating SDK... done
123
121
  Downloading SDK... done
124
122
  Success! Your SDK is located at swagger_sdk_csharp`,
125
- `$ apimatic sdk:generate --platform="CSHARP" --url=https://petstore.swagger.io/v2/swagger.json
123
+ `
124
+ $ apimatic sdk:generate --platform="CSHARP" --url=https://petstore.swagger.io/v2/swagger.json
126
125
  Generating SDK... done
127
126
  Downloading SDK... done
128
127
  Success! Your SDK is located at swagger_sdk_csharp
@@ -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}` : "" }, formData.getHeaders()),
18
18
  responseType: "arraybuffer"
19
19
  };
20
20
  const { data } = await axios_1.default.post(`${env_1.baseURL}/portal`, formData, config);
@@ -30,4 +30,5 @@ export declare const DestinationFormats: {
30
30
  RAML10: string;
31
31
  Postman10: string;
32
32
  Postman20: string;
33
+ GraphQlSchema: string;
33
34
  };
@@ -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,10 @@
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
+ };
@@ -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.6",
4
+ "version": "1.0.2-alpha.2",
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.0.1-alpha.8",
49
47
  "@oclif/command": "^1.8.0",
50
48
  "@oclif/config": "^1.17.0",
51
49
  "@oclif/plugin-autocomplete": "^0.3.0",
@@ -1,6 +0,0 @@
1
- import { Command } from "@oclif/command";
2
- export default class Api extends Command {
3
- static description: string;
4
- static examples: string[];
5
- run(): Promise<void>;
6
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const command_1 = require("@oclif/command");
4
- class Api extends command_1.Command {
5
- async run() {
6
- this.log(`Manage APIs
7
-
8
- USAGE
9
- $ apimatic api
10
-
11
- EXAMPLE
12
- $ apimatic api --help
13
-
14
- COMMANDS
15
- api:transform 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.
16
- api:validate Validate the syntactic and semantic correctness of an API specification`);
17
- }
18
- }
19
- exports.default = Api;
20
- Api.description = "Manage APIs";
21
- Api.examples = ["$ apimatic api --help"];
@@ -1,6 +0,0 @@
1
- import { Command } from "@oclif/command";
2
- export default class Auth extends Command {
3
- static description: string;
4
- static examples: string[];
5
- run: () => Promise<void>;
6
- }
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const command_1 = require("@oclif/command");
4
- class Auth extends command_1.Command {
5
- constructor() {
6
- super(...arguments);
7
- this.run = async () => {
8
- this.log(`Manage this CLI's authentication state.
9
-
10
- USAGE
11
- $ apimatic auth
12
-
13
- EXAMPLE
14
- $ apimatic auth --help
15
-
16
- COMMANDS
17
- auth:login Login using your APIMatic credentials or an API Key
18
- auth:logout Clear local login credentials
19
- auth:status View current authentication state`);
20
- };
21
- }
22
- }
23
- exports.default = Auth;
24
- Auth.description = "Manage this CLI's authentication state.";
25
- Auth.examples = ["$ apimatic auth --help"];
@@ -1,6 +0,0 @@
1
- import { Command } from "@oclif/command";
2
- export default class SDK extends Command {
3
- static description: string;
4
- static examples: string[];
5
- run(): Promise<void>;
6
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const command_1 = require("@oclif/command");
4
- class SDK extends command_1.Command {
5
- async run() {
6
- this.log(`Manage API documentation portals
7
-
8
- USAGE
9
- $ apimatic portal
10
-
11
- EXAMPLE
12
- $apimatic portal --help
13
-
14
- COMMANDS
15
- portal:generate 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)`);
16
- }
17
- }
18
- exports.default = SDK;
19
- SDK.description = "Manage API documentation portals";
20
- SDK.examples = ["$apimatic portal --help"];
@@ -1,6 +0,0 @@
1
- import { Command } from "@oclif/command";
2
- export default class SDK extends Command {
3
- static description: string;
4
- static examples: string[];
5
- run(): Promise<void>;
6
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const command_1 = require("@oclif/command");
4
- class SDK extends command_1.Command {
5
- // eslint-disable-next-line @typescript-eslint/no-empty-function
6
- async run() {
7
- this.log(`Generate and manage SDKs for APIs
8
-
9
- USAGE
10
- $ apimatic sdk
11
-
12
- EXAMPLE
13
- $apimatic sdk --help
14
-
15
- COMMANDS
16
- sdk:generate Generate SDK for your APIs`);
17
- }
18
- }
19
- exports.default = SDK;
20
- SDK.description = "Generate and manage SDKs for APIs";
21
- SDK.examples = ["$apimatic sdk --help"];
@@ -1 +0,0 @@
1
- {"version":"1.0.1-alpha.6","commands":{"api":{"id":"api","description":"Manage APIs","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$ apimatic api --help"],"flags":{},"args":[]},"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\n(OpenApi3Json|OpenApi3Yaml|APIMATIC|WADL2009|WADL2006|WSDL|\nSwagger10|Swagger20|SwaggerYaml|RAML|RAML10|Postman10|Postman20)","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":{"id":"auth","description":"Manage this CLI's authentication state.","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$ apimatic auth --help"],"flags":{},"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":[]},"portal":{"id":"portal","description":"Manage API documentation portals","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$apimatic portal --help"],"flags":{},"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","$ 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":[]},"sdk":{"id":"sdk","description":"Generate and manage SDKs for APIs","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$apimatic sdk --help"],"flags":{},"args":[]}}}