@apimatic/cli 0.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +258 -0
  2. package/bin/run +5 -0
  3. package/bin/run.cmd +3 -0
  4. package/lib/client-utils/auth-manager.d.ts +17 -0
  5. package/lib/client-utils/auth-manager.js +33 -0
  6. package/lib/client-utils/sdk-client.d.ts +23 -0
  7. package/lib/client-utils/sdk-client.js +119 -0
  8. package/lib/commands/api/transform.d.ts +14 -0
  9. package/lib/commands/api/transform.js +105 -0
  10. package/lib/commands/api/validate.d.ts +11 -0
  11. package/lib/commands/api/validate.js +64 -0
  12. package/lib/commands/auth/login.d.ts +9 -0
  13. package/lib/commands/auth/login.js +60 -0
  14. package/lib/commands/auth/logout.d.ts +6 -0
  15. package/lib/commands/auth/logout.js +23 -0
  16. package/lib/commands/auth/status.d.ts +6 -0
  17. package/lib/commands/auth/status.js +23 -0
  18. package/lib/commands/portal/generate.d.ts +13 -0
  19. package/lib/commands/portal/generate.js +102 -0
  20. package/lib/commands/sdk/generate.d.ts +15 -0
  21. package/lib/commands/sdk/generate.js +129 -0
  22. package/lib/config/env.d.ts +1 -0
  23. package/lib/config/env.js +4 -0
  24. package/lib/controllers/api/transform.d.ts +7 -0
  25. package/lib/controllers/api/transform.js +59 -0
  26. package/lib/controllers/api/validate.d.ts +5 -0
  27. package/lib/controllers/api/validate.js +32 -0
  28. package/lib/controllers/portal/generate.d.ts +2 -0
  29. package/lib/controllers/portal/generate.js +49 -0
  30. package/lib/controllers/sdk/generate.d.ts +4 -0
  31. package/lib/controllers/sdk/generate.js +64 -0
  32. package/lib/index.d.ts +1 -0
  33. package/lib/index.js +4 -0
  34. package/lib/types/api/transform.d.ts +34 -0
  35. package/lib/types/api/transform.js +18 -0
  36. package/lib/types/api/validate.d.ts +12 -0
  37. package/lib/types/api/validate.js +2 -0
  38. package/lib/types/portal/generate.d.ts +9 -0
  39. package/lib/types/portal/generate.js +2 -0
  40. package/lib/types/sdk/generate.d.ts +22 -0
  41. package/lib/types/sdk/generate.js +12 -0
  42. package/lib/utils/utils.d.ts +18 -0
  43. package/lib/utils/utils.js +107 -0
  44. package/oclif.manifest.json +1 -0
  45. package/package.json +107 -0
@@ -0,0 +1,34 @@
1
+ /// <reference types="node" />
2
+ import { TransformationController } from "@apimatic/sdk";
3
+ export declare type AuthenticationError = {
4
+ statusCode: number;
5
+ body: string;
6
+ };
7
+ export declare type TransformationIdParams = {
8
+ file: string;
9
+ url: string;
10
+ format: string;
11
+ };
12
+ export declare type DownloadTransformationParams = {
13
+ id: string;
14
+ destinationFilePath: string;
15
+ transformationController: TransformationController;
16
+ };
17
+ export declare type TransformationData = {
18
+ result: NodeJS.ReadableStream | Blob;
19
+ };
20
+ export declare const DestinationFormats: {
21
+ OpenApi3Json: string;
22
+ OpenApi3Yaml: string;
23
+ APIMATIC: string;
24
+ WADL2009: string;
25
+ WSDL: string;
26
+ Swagger10: string;
27
+ Swagger20: string;
28
+ SwaggerYaml: string;
29
+ RAML: string;
30
+ RAML10: string;
31
+ Postman10: string;
32
+ Postman20: string;
33
+ GraphQlSchema: string;
34
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DestinationFormats = void 0;
4
+ exports.DestinationFormats = {
5
+ OpenApi3Json: "json",
6
+ OpenApi3Yaml: "yaml",
7
+ APIMATIC: "json",
8
+ WADL2009: "xml",
9
+ WSDL: "xml",
10
+ Swagger10: "json",
11
+ Swagger20: "json",
12
+ SwaggerYaml: "yaml",
13
+ RAML: "yaml",
14
+ RAML10: "yaml",
15
+ Postman10: "json",
16
+ Postman20: "json",
17
+ GraphQlSchema: "json"
18
+ };
@@ -0,0 +1,12 @@
1
+ export declare type GetValidationParams = {
2
+ file: string;
3
+ url: string;
4
+ };
5
+ export declare type APIValidateError = {
6
+ modelState: {
7
+ "exception Error": string[];
8
+ };
9
+ };
10
+ export declare type AuthorizationError = {
11
+ body: string;
12
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { DocsPortalManagementController } from "@apimatic/sdk";
2
+ export declare type GeneratePortalParams = {
3
+ zippedBuildFilePath: string;
4
+ portalFolderPath: string;
5
+ zippedPortalPath: string;
6
+ docsPortalController: DocsPortalManagementController;
7
+ overrideAuthKey: string | null;
8
+ zip: boolean;
9
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,22 @@
1
+ export declare type GenerationIdParams = {
2
+ file: string;
3
+ url: string;
4
+ platform: string;
5
+ };
6
+ export declare type DownloadSDKParams = {
7
+ codeGenId: string;
8
+ zip: boolean;
9
+ zippedSDKPath: string;
10
+ sdkFolderPath: string;
11
+ };
12
+ export declare type SDKGenerateUnprocessableError = {
13
+ message: string;
14
+ };
15
+ export declare enum SimplePlatforms {
16
+ CSHARP = "CS_NET_STANDARD_LIB",
17
+ JAVA = "JAVA_ECLIPSE_JRE_LIB",
18
+ PHP = "PHP_GENERIC_LIB",
19
+ PYTHON = "PYTHON_GENERIC_LIB",
20
+ RUBY = "RUBY_GENERIC_LIB",
21
+ TYPESCRIPT = "TS_GENERIC_LIB"
22
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SimplePlatforms = void 0;
4
+ var SimplePlatforms;
5
+ (function (SimplePlatforms) {
6
+ SimplePlatforms["CSHARP"] = "CS_NET_STANDARD_LIB";
7
+ SimplePlatforms["JAVA"] = "JAVA_ECLIPSE_JRE_LIB";
8
+ SimplePlatforms["PHP"] = "PHP_GENERIC_LIB";
9
+ SimplePlatforms["PYTHON"] = "PYTHON_GENERIC_LIB";
10
+ SimplePlatforms["RUBY"] = "RUBY_GENERIC_LIB";
11
+ SimplePlatforms["TYPESCRIPT"] = "TS_GENERIC_LIB";
12
+ })(SimplePlatforms = exports.SimplePlatforms || (exports.SimplePlatforms = {}));
@@ -0,0 +1,18 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="mocha" />
3
+ export declare const unzipFile: (stream: NodeJS.ReadableStream, destination: string) => Promise<unknown>;
4
+ export declare const deleteFile: (filePath: string) => Promise<void>;
5
+ export declare const writeFileUsingReadableStream: (stream: NodeJS.ReadableStream, destinationPath: string) => Promise<unknown>;
6
+ /**
7
+ * Packages local files into a ZIP archive
8
+ *
9
+ * @param {docsPortalFolderPath} path to portal directory.
10
+ * @param {destinationZipPath} path to generated zip
11
+ * return {string}
12
+ */
13
+ export declare const zipDirectory: (sourcePath: string, destinationPath: string) => Promise<string>;
14
+ export declare const startProgress: (title: string) => void;
15
+ export declare const stopProgress: (isError?: boolean) => void | null;
16
+ export declare const replaceHTML: (string: string) => string;
17
+ export declare const isJSONParsable: (json: string) => boolean;
18
+ export declare const getFileNameFromPath: (filePath: string) => string;
@@ -0,0 +1,107 @@
1
+ "use strict";
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");
5
+ const path = require("path");
6
+ const archiver = require("archiver");
7
+ const unzipper = require("unzipper");
8
+ const stripTags = require("striptags");
9
+ const cli_ux_1 = require("cli-ux");
10
+ exports.unzipFile = (stream, destination) => {
11
+ return new Promise((resolve, reject) => {
12
+ stream.pipe(unzipper.Extract({ path: destination }));
13
+ stream.on("close", (error) => {
14
+ if (error) {
15
+ reject(new Error("Couldn't extract the zip"));
16
+ }
17
+ resolve("Extracted");
18
+ });
19
+ });
20
+ };
21
+ exports.deleteFile = async (filePath) => {
22
+ return await fs.remove(filePath);
23
+ };
24
+ exports.writeFileUsingReadableStream = (stream, destinationPath) => {
25
+ return new Promise((resolve, reject) => {
26
+ const writeStream = fs.createWriteStream(destinationPath);
27
+ stream.pipe(writeStream);
28
+ writeStream.on("close", (error) => {
29
+ if (error) {
30
+ return reject(new Error("Couldn't zip the stream"));
31
+ }
32
+ resolve("Zipped");
33
+ });
34
+ });
35
+ };
36
+ /**
37
+ * Packages local files into a ZIP archive
38
+ *
39
+ * @param {docsPortalFolderPath} path to portal directory.
40
+ * @param {destinationZipPath} path to generated zip
41
+ * return {string}
42
+ */
43
+ exports.zipDirectory = async (sourcePath, destinationPath) => {
44
+ // Check if the directory exists for the user or not
45
+ await fs.ensureDir(sourcePath);
46
+ const zipPath = path.join(destinationPath, "target.zip");
47
+ const output = fs.createWriteStream(zipPath);
48
+ const archive = archiver("zip");
49
+ archive.on("error", (err) => {
50
+ throw err;
51
+ });
52
+ archive.pipe(output);
53
+ // append files from a sub-directory, putting its contents at the root of archive
54
+ archive.directory(sourcePath, false);
55
+ await archive.finalize();
56
+ return zipPath;
57
+ };
58
+ // TODO: Instead of making progressBar a static, you should have "startProgress"
59
+ // return the instance of the progress bar created, the same way "cli.progress"
60
+ // method does.
61
+ let progressBar;
62
+ // TODO: I didn't mean to say that we should create a fake progress bar when we
63
+ // set the requirements to include progress bar. You should get the download or
64
+ // upload progress by tracking how much of the steam has been read/written and
65
+ // compare that with the remaining size of the stream (in case of upload, you
66
+ // get size from the file size and in case of download, you get it from the
67
+ // content-type header). In case the progress can not be calculated, show a
68
+ // spinner.
69
+ exports.startProgress = (title) => {
70
+ progressBar = cli_ux_1.default.progress({
71
+ format: `${title} | {bar}`,
72
+ barCompleteChar: "\u2588",
73
+ barIncompleteChar: "\u2591"
74
+ });
75
+ progressBar.start();
76
+ const total = 100;
77
+ let count = 0;
78
+ const iv = setInterval(() => {
79
+ count++;
80
+ progressBar.update(count);
81
+ if (count === total - 1) {
82
+ clearInterval(iv);
83
+ }
84
+ }, 50);
85
+ };
86
+ exports.stopProgress = (isError = false) => {
87
+ if (isError) {
88
+ return progressBar ? progressBar.stop() : null;
89
+ }
90
+ progressBar.update(100);
91
+ return progressBar.stop();
92
+ };
93
+ exports.replaceHTML = (string) => {
94
+ return stripTags(string);
95
+ };
96
+ exports.isJSONParsable = (json) => {
97
+ try {
98
+ JSON.parse(json);
99
+ return true;
100
+ }
101
+ catch (e) {
102
+ return false;
103
+ }
104
+ };
105
+ exports.getFileNameFromPath = (filePath) => {
106
+ return path.basename(filePath).split(".")[0];
107
+ };
@@ -0,0 +1 @@
1
+ {"version":"0.0.0-alpha.2","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":[]}}}
package/package.json ADDED
@@ -0,0 +1,107 @@
1
+ {
2
+ "name": "@apimatic/cli",
3
+ "description": "The official CLI for APIMatic.",
4
+ "version": "0.0.0-alpha.2",
5
+ "author": "APIMatic",
6
+ "bin": {
7
+ "apimatic": "./bin/run"
8
+ },
9
+ "bugs": "https://github.com/apimatic/apimatic-cli/issues",
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "engines": {
14
+ "node": ">=12.0.0"
15
+ },
16
+ "files": [
17
+ "/bin",
18
+ "/lib",
19
+ "/npm-shrinkwrap.json",
20
+ "/oclif.manifest.json"
21
+ ],
22
+ "repository": "git://github.com/apimatic/apimatic-cli.git",
23
+ "homepage": "https://github.com/apimatic/apimatic-cli",
24
+ "keywords": [
25
+ "apimatic",
26
+ "cli",
27
+ "sdk generation",
28
+ "openapi",
29
+ "api",
30
+ "automation"
31
+ ],
32
+ "license": "MIT",
33
+ "main": "lib/index.js",
34
+ "types": "lib/index.d.ts",
35
+ "scripts": {
36
+ "build": "tsc -b",
37
+ "postpack": "rimraf oclif.manifest.json",
38
+ "posttest": "eslint . --ext .ts --config .eslintrc",
39
+ "prepack": "rimraf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
40
+ "test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
41
+ "version": "oclif-dev readme && git add README.md",
42
+ "prettier": "prettier \"src/**/*.{js,ts}\"",
43
+ "format": "prettier --write \"src/**/*.{js,ts}\"",
44
+ "lint": "eslint \"src/**/*.{js,ts}\"",
45
+ "lint:fix": "eslint --fix \"src/**/*.{js,ts}\" --quiet"
46
+ },
47
+ "dependencies": {
48
+ "@apimatic/sdk": "^0.0.1-alpha.6",
49
+ "@oclif/command": "^1.8.0",
50
+ "@oclif/config": "^1.17.0",
51
+ "@oclif/plugin-autocomplete": "^0.3.0",
52
+ "@oclif/plugin-help": "^3.2.3",
53
+ "@oclif/plugin-not-found": "^1.2.4",
54
+ "archiver": "^5.3.0",
55
+ "axios": "^0.24.0",
56
+ "base-64": "^1.0.0",
57
+ "form-data": "^4.0.0",
58
+ "fs-extra": "^10.0.0",
59
+ "striptags": "^3.2.0",
60
+ "tslib": "^1.14.1",
61
+ "unzipper": "^0.10.11"
62
+ },
63
+ "devDependencies": {
64
+ "@commitlint/cli": "^15.0.0",
65
+ "@commitlint/config-conventional": "^15.0.0",
66
+ "@oclif/dev-cli": "^1.26.0",
67
+ "@oclif/test": "^1.2.8",
68
+ "@semantic-release/changelog": "^6.0.1",
69
+ "@semantic-release/git": "^10.0.1",
70
+ "@types/archiver": "^5.1.1",
71
+ "@types/axios": "^0.14.0",
72
+ "@types/base-64": "^1.0.0",
73
+ "@types/chai": "^4.2.22",
74
+ "@types/fs-extra": "^9.0.13",
75
+ "@types/mocha": "^5.2.7",
76
+ "@types/node": "^10.17.60",
77
+ "@types/unzipper": "^0.10.4",
78
+ "@typescript-eslint/eslint-plugin": "^5.0.0",
79
+ "@typescript-eslint/parser": "^5.0.0",
80
+ "chai": "^4.3.4",
81
+ "eslint": "^7.32.0",
82
+ "eslint-config-prettier": "^8.3.0",
83
+ "eslint-plugin-import": "^2.25.2",
84
+ "globby": "^10.0.2",
85
+ "husky": "^7.0.4",
86
+ "lint-staged": "^11.2.6",
87
+ "mocha": "^5.2.0",
88
+ "nyc": "^14.1.1",
89
+ "prettier": "^2.4.1",
90
+ "rimraf": "^3.0.2",
91
+ "ts-node": "^8.10.2",
92
+ "typescript": "^3.9.10"
93
+ },
94
+ "oclif": {
95
+ "commands": "./lib/commands",
96
+ "bin": "apimatic",
97
+ "plugins": [
98
+ "@oclif/plugin-autocomplete",
99
+ "@oclif/plugin-help",
100
+ "@oclif/plugin-not-found"
101
+ ]
102
+ },
103
+ "lint-staged": {
104
+ "*.js": "eslint --cache --fix",
105
+ "*.{js,ts}": "prettier --write"
106
+ }
107
+ }