@apimatic/cli 1.0.1-alpha.1
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/CHANGELOG.md +6 -0
- package/README.md +292 -0
- package/bin/run +5 -0
- package/bin/run.cmd +3 -0
- package/lib/client-utils/auth-manager.d.ts +17 -0
- package/lib/client-utils/auth-manager.js +33 -0
- package/lib/client-utils/sdk-client.d.ts +23 -0
- package/lib/client-utils/sdk-client.js +119 -0
- package/lib/commands/api/index.d.ts +6 -0
- package/lib/commands/api/index.js +22 -0
- package/lib/commands/api/transform.d.ts +15 -0
- package/lib/commands/api/transform.js +157 -0
- package/lib/commands/api/validate.d.ts +13 -0
- package/lib/commands/api/validate.js +85 -0
- package/lib/commands/auth/index.d.ts +6 -0
- package/lib/commands/auth/index.js +25 -0
- package/lib/commands/auth/login.d.ts +9 -0
- package/lib/commands/auth/login.js +58 -0
- package/lib/commands/auth/logout.d.ts +6 -0
- package/lib/commands/auth/logout.js +23 -0
- package/lib/commands/auth/status.d.ts +6 -0
- package/lib/commands/auth/status.js +23 -0
- package/lib/commands/portal/generate.d.ts +23 -0
- package/lib/commands/portal/generate.js +141 -0
- package/lib/commands/portal/index.d.ts +6 -0
- package/lib/commands/portal/index.js +20 -0
- package/lib/commands/sdk/generate.d.ts +14 -0
- package/lib/commands/sdk/generate.js +178 -0
- package/lib/commands/sdk/index.d.ts +6 -0
- package/lib/commands/sdk/index.js +21 -0
- package/lib/config/env.d.ts +1 -0
- package/lib/config/env.js +4 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +4 -0
- package/lib/utils/utils.d.ts +18 -0
- package/lib/utils/utils.js +107 -0
- package/oclif.manifest.json +1 -0
- package/package.json +107 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
## [1.0.1-alpha.1](https://github.com/apimatic/apimatic-cli/compare/v1.0.0...v1.0.1-alpha.1) (2021-11-26)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **release:** add lock file to gitignore restore check_build workflow ([2eb959a](https://github.com/apimatic/apimatic-cli/commit/2eb959afc2a7ee2317959fc8525930acde2989dc))
|
package/README.md
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
@apimatic/cli
|
|
2
|
+
=============
|
|
3
|
+
|
|
4
|
+
The official CLI for APIMatic.
|
|
5
|
+
|
|
6
|
+
[](https://oclif.io)
|
|
7
|
+
[](https://npmjs.org/package/@apimatic/cli)
|
|
8
|
+
[](https://npmjs.org/package/@apimatic/cli)
|
|
9
|
+
[](https://github.com/apimatic/apimatic-cli/blob/master/package.json)
|
|
10
|
+
|
|
11
|
+
<!-- toc -->
|
|
12
|
+
* [Usage](#usage)
|
|
13
|
+
* [Commands](#commands)
|
|
14
|
+
<!-- tocstop -->
|
|
15
|
+
# Usage
|
|
16
|
+
<!-- usage -->
|
|
17
|
+
```sh-session
|
|
18
|
+
$ npm install -g @apimatic/cli
|
|
19
|
+
$ apimatic COMMAND
|
|
20
|
+
running command...
|
|
21
|
+
$ apimatic (-v|--version|version)
|
|
22
|
+
@apimatic/cli/1.0.1-alpha.1 linux-x64 node-v14.18.1
|
|
23
|
+
$ apimatic --help [COMMAND]
|
|
24
|
+
USAGE
|
|
25
|
+
$ apimatic COMMAND
|
|
26
|
+
...
|
|
27
|
+
```
|
|
28
|
+
<!-- usagestop -->
|
|
29
|
+
|
|
30
|
+
# Commands
|
|
31
|
+
<!-- commands -->
|
|
32
|
+
* [`apimatic api`](#apimatic-api)
|
|
33
|
+
* [`apimatic api:transform`](#apimatic-apitransform)
|
|
34
|
+
* [`apimatic api:validate`](#apimatic-apivalidate)
|
|
35
|
+
* [`apimatic auth`](#apimatic-auth)
|
|
36
|
+
* [`apimatic auth:login`](#apimatic-authlogin)
|
|
37
|
+
* [`apimatic auth:logout`](#apimatic-authlogout)
|
|
38
|
+
* [`apimatic auth:status`](#apimatic-authstatus)
|
|
39
|
+
* [`apimatic autocomplete [SHELL]`](#apimatic-autocomplete-shell)
|
|
40
|
+
* [`apimatic help [COMMAND]`](#apimatic-help-command)
|
|
41
|
+
* [`apimatic portal`](#apimatic-portal)
|
|
42
|
+
* [`apimatic portal:generate`](#apimatic-portalgenerate)
|
|
43
|
+
* [`apimatic sdk`](#apimatic-sdk)
|
|
44
|
+
* [`apimatic sdk:generate`](#apimatic-sdkgenerate)
|
|
45
|
+
|
|
46
|
+
## `apimatic api`
|
|
47
|
+
|
|
48
|
+
lists all commands related to the APIMatic API.
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
USAGE
|
|
52
|
+
$ apimatic api
|
|
53
|
+
|
|
54
|
+
EXAMPLE
|
|
55
|
+
$ apimatic api --help
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
_See code: [src/commands/api/index.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/api/index.ts)_
|
|
59
|
+
|
|
60
|
+
## `apimatic api:transform`
|
|
61
|
+
|
|
62
|
+
Transforms your API specification to any supported format of your choice from amongst[10+ different formats](https://www.apimatic.io/transformer/#supported-formats).
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
USAGE
|
|
66
|
+
$ apimatic api:transform
|
|
67
|
+
|
|
68
|
+
OPTIONS
|
|
69
|
+
--auth-key=auth-key override current auth-key
|
|
70
|
+
|
|
71
|
+
--destination=destination [default: /home/runner/work/apimatic-cli/apimatic-cli/cli/src/commands/api] path to
|
|
72
|
+
transformed file
|
|
73
|
+
|
|
74
|
+
--file=file path to the API specification file to transform
|
|
75
|
+
|
|
76
|
+
--format=format (required) specification format to transform API specification into
|
|
77
|
+
(OpenApi3Json|OpenApi3Yaml|APIMATIC|WADL2009|WADL2006|WSDL|
|
|
78
|
+
Swagger10|Swagger20|SwaggerYaml|RAML|RAML10|Postman10|Postman20)
|
|
79
|
+
|
|
80
|
+
--url=url URL to the API specification file to transform
|
|
81
|
+
|
|
82
|
+
EXAMPLE
|
|
83
|
+
$ apimatic api:transform --format="OpenApi3Json" --file="./specs/sample.json" --destination="D:/"
|
|
84
|
+
Success! Your transformed file is located at D:/Transformed_OpenApi3Json.json
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
_See code: [src/commands/api/transform.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/api/transform.ts)_
|
|
88
|
+
|
|
89
|
+
## `apimatic api:validate`
|
|
90
|
+
|
|
91
|
+
Validates the provided API specification file for any syntactical and semantic errors
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
USAGE
|
|
95
|
+
$ apimatic api:validate
|
|
96
|
+
|
|
97
|
+
OPTIONS
|
|
98
|
+
--auth-key=auth-key override current auth-key
|
|
99
|
+
--file=file path to the API specification file to validate
|
|
100
|
+
--url=url URL to the specification file to validate
|
|
101
|
+
|
|
102
|
+
EXAMPLE
|
|
103
|
+
$ apimatic api:validate --file="./specs/sample.json"
|
|
104
|
+
Specification file provided is valid
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
_See code: [src/commands/api/validate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/api/validate.ts)_
|
|
108
|
+
|
|
109
|
+
## `apimatic auth`
|
|
110
|
+
|
|
111
|
+
invokes subcommands related to authentication.
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
USAGE
|
|
115
|
+
$ apimatic auth
|
|
116
|
+
|
|
117
|
+
EXAMPLE
|
|
118
|
+
$ apimatic auth --help
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
_See code: [src/commands/auth/index.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/auth/index.ts)_
|
|
122
|
+
|
|
123
|
+
## `apimatic auth:login`
|
|
124
|
+
|
|
125
|
+
login to your APIMatic account
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
USAGE
|
|
129
|
+
$ apimatic auth:login
|
|
130
|
+
|
|
131
|
+
OPTIONS
|
|
132
|
+
--auth-key=auth-key Set authentication key for all commands
|
|
133
|
+
|
|
134
|
+
EXAMPLE
|
|
135
|
+
$ apimatic auth:login
|
|
136
|
+
Please enter your registered email: apimatic-user@gmail.com
|
|
137
|
+
Please enter your password: *********
|
|
138
|
+
|
|
139
|
+
You have successfully logged into APIMatic
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
_See code: [src/commands/auth/login.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/auth/login.ts)_
|
|
143
|
+
|
|
144
|
+
## `apimatic auth:logout`
|
|
145
|
+
|
|
146
|
+
logout of APIMatic
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
USAGE
|
|
150
|
+
$ apimatic auth:logout
|
|
151
|
+
|
|
152
|
+
EXAMPLE
|
|
153
|
+
$ apimatic auth:logout
|
|
154
|
+
Logged out
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
_See code: [src/commands/auth/logout.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/auth/logout.ts)_
|
|
158
|
+
|
|
159
|
+
## `apimatic auth:status`
|
|
160
|
+
|
|
161
|
+
checks current logged-in account
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
USAGE
|
|
165
|
+
$ apimatic auth:status
|
|
166
|
+
|
|
167
|
+
EXAMPLE
|
|
168
|
+
$ apimatic auth:status
|
|
169
|
+
Currently logged in as apimatic-client@gmail.com
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
_See code: [src/commands/auth/status.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/auth/status.ts)_
|
|
173
|
+
|
|
174
|
+
## `apimatic autocomplete [SHELL]`
|
|
175
|
+
|
|
176
|
+
display autocomplete installation instructions
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
USAGE
|
|
180
|
+
$ apimatic autocomplete [SHELL]
|
|
181
|
+
|
|
182
|
+
ARGUMENTS
|
|
183
|
+
SHELL shell type
|
|
184
|
+
|
|
185
|
+
OPTIONS
|
|
186
|
+
-r, --refresh-cache Refresh cache (ignores displaying instructions)
|
|
187
|
+
|
|
188
|
+
EXAMPLES
|
|
189
|
+
$ apimatic autocomplete
|
|
190
|
+
$ apimatic autocomplete bash
|
|
191
|
+
$ apimatic autocomplete zsh
|
|
192
|
+
$ apimatic autocomplete --refresh-cache
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
_See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v0.3.0/src/commands/autocomplete/index.ts)_
|
|
196
|
+
|
|
197
|
+
## `apimatic help [COMMAND]`
|
|
198
|
+
|
|
199
|
+
display help for apimatic
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
USAGE
|
|
203
|
+
$ apimatic help [COMMAND]
|
|
204
|
+
|
|
205
|
+
ARGUMENTS
|
|
206
|
+
COMMAND command to show help for
|
|
207
|
+
|
|
208
|
+
OPTIONS
|
|
209
|
+
--all see all commands in CLI
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.7/src/commands/help.ts)_
|
|
213
|
+
|
|
214
|
+
## `apimatic portal`
|
|
215
|
+
|
|
216
|
+
invokes subcommands related to the API Portal.
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
USAGE
|
|
220
|
+
$ apimatic portal
|
|
221
|
+
|
|
222
|
+
EXAMPLE
|
|
223
|
+
$apimatic portal --help
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
_See code: [src/commands/portal/index.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/portal/index.ts)_
|
|
227
|
+
|
|
228
|
+
## `apimatic portal:generate`
|
|
229
|
+
|
|
230
|
+
Generate static docs portal on premise
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
USAGE
|
|
234
|
+
$ apimatic portal:generate
|
|
235
|
+
|
|
236
|
+
OPTIONS
|
|
237
|
+
--auth-key=auth-key override current auth-key
|
|
238
|
+
--destination=destination [default: ./] path to the downloaded portal
|
|
239
|
+
--folder=folder folder to generate the portal with
|
|
240
|
+
--zip zip the portal
|
|
241
|
+
|
|
242
|
+
EXAMPLE
|
|
243
|
+
$ apimatic portal:generate --folder="./portal/" --destination="D:/"
|
|
244
|
+
Your portal has been generated at D:/
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
_See code: [src/commands/portal/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/portal/generate.ts)_
|
|
248
|
+
|
|
249
|
+
## `apimatic sdk`
|
|
250
|
+
|
|
251
|
+
invokes subcommands related to your SDKs.
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
USAGE
|
|
255
|
+
$ apimatic sdk
|
|
256
|
+
|
|
257
|
+
EXAMPLE
|
|
258
|
+
$apimatic sdk --help
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
_See code: [src/commands/sdk/index.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/sdk/index.ts)_
|
|
262
|
+
|
|
263
|
+
## `apimatic sdk:generate`
|
|
264
|
+
|
|
265
|
+
Generate SDK for your APIs
|
|
266
|
+
|
|
267
|
+
```
|
|
268
|
+
USAGE
|
|
269
|
+
$ apimatic sdk:generate
|
|
270
|
+
|
|
271
|
+
OPTIONS
|
|
272
|
+
--auth-key=auth-key override current auth-key
|
|
273
|
+
--destination=destination [default: ./] path to downloaded SDK (used with download flag)
|
|
274
|
+
--file=file path to the API specification to generate SDK
|
|
275
|
+
|
|
276
|
+
--platform=platform (required) language platform for sdk
|
|
277
|
+
Simple: CSHARP|JAVA|PYTHON|RUBY|PHP|TYPESCRIPT
|
|
278
|
+
Legacy: CS_NET_STANDARD_LIB|CS_PORTABLE_NET_LIB|CS_UNIVERSAL_WINDOWS_PLATFORM_LIB|
|
|
279
|
+
JAVA_ECLIPSE_JRE_LIB|PHP_GENERIC_LIB|PYTHON_GENERIC_LIB|RUBY_GENERIC_LIB|
|
|
280
|
+
TS_GENERIC_LIB
|
|
281
|
+
|
|
282
|
+
--url=url URL to the API specification to generate SDK
|
|
283
|
+
|
|
284
|
+
--zip zip the SDK (used with download flag)
|
|
285
|
+
|
|
286
|
+
EXAMPLE
|
|
287
|
+
$ apimatic sdk:generate --platform="CSHARP" --file="./specs/sample.json"
|
|
288
|
+
SDK generated successfully
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
_See code: [src/commands/sdk/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/sdk/generate.ts)_
|
|
292
|
+
<!-- commandsstop -->
|
package/bin/run
ADDED
package/bin/run.cmd
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare type AuthInfo = {
|
|
2
|
+
email: string;
|
|
3
|
+
authKey: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {string} configDir <- Directory with user configuration
|
|
8
|
+
* //Function to get credentials
|
|
9
|
+
*/
|
|
10
|
+
export declare function getAuthInfo(configDir: string): Promise<AuthInfo | null>;
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param {AuthInfo} credentials
|
|
14
|
+
* @param {string} configDir <- Directory with user configuration
|
|
15
|
+
* //Function to set credentials.
|
|
16
|
+
*/
|
|
17
|
+
export declare function setAuthInfo(credentials: AuthInfo, configDir: string): Promise<void>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setAuthInfo = exports.getAuthInfo = void 0;
|
|
4
|
+
const fs = require("fs-extra");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {string} configDir <- Directory with user configuration
|
|
9
|
+
* //Function to get credentials
|
|
10
|
+
*/
|
|
11
|
+
async function getAuthInfo(configDir) {
|
|
12
|
+
try {
|
|
13
|
+
const data = JSON.parse(await fs.readFile(path.join(configDir, "config.json"), "utf8"));
|
|
14
|
+
return data;
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.getAuthInfo = getAuthInfo;
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {AuthInfo} credentials
|
|
24
|
+
* @param {string} configDir <- Directory with user configuration
|
|
25
|
+
* //Function to set credentials.
|
|
26
|
+
*/
|
|
27
|
+
async function setAuthInfo(credentials, configDir) {
|
|
28
|
+
const configFilePath = path.join(configDir, "config.json");
|
|
29
|
+
if (!fs.existsSync(configFilePath))
|
|
30
|
+
fs.createFileSync(configFilePath);
|
|
31
|
+
return await fs.writeFile(configFilePath, JSON.stringify(credentials));
|
|
32
|
+
}
|
|
33
|
+
exports.setAuthInfo = setAuthInfo;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Client } from "@apimatic/apimatic-sdk-for-js";
|
|
2
|
+
export declare class SDKClient {
|
|
3
|
+
private static instance;
|
|
4
|
+
private static authAPI;
|
|
5
|
+
static client: Client;
|
|
6
|
+
/**
|
|
7
|
+
* The static method that controls the access to the SDKClient instance.
|
|
8
|
+
*
|
|
9
|
+
* This implementation let you subclass the SDKClient class while keeping
|
|
10
|
+
* just one instance of each subclass around.
|
|
11
|
+
*/
|
|
12
|
+
static getInstance(): SDKClient;
|
|
13
|
+
/**
|
|
14
|
+
* Finally, any SDKClient should define some business logic, which can be
|
|
15
|
+
* executed on its instance.
|
|
16
|
+
*/
|
|
17
|
+
login(email: string, password: string, configDir: string): Promise<string>;
|
|
18
|
+
logout(configDir: string): Promise<string>;
|
|
19
|
+
status(configDir: string): Promise<string>;
|
|
20
|
+
getClient(overrideAuthKey: string | null, configDir: string): Promise<Client>;
|
|
21
|
+
private getAuthKey;
|
|
22
|
+
setAuthKey: (authKey: string, configDir: string) => string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SDKClient = void 0;
|
|
4
|
+
const base64 = require("base-64");
|
|
5
|
+
const axios_1 = require("axios");
|
|
6
|
+
const apimatic_sdk_for_js_1 = require("@apimatic/apimatic-sdk-for-js");
|
|
7
|
+
const auth_manager_1 = require("./auth-manager");
|
|
8
|
+
const env_1 = require("../config/env");
|
|
9
|
+
class SDKClient {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.setAuthKey = (authKey, configDir) => {
|
|
12
|
+
auth_manager_1.setAuthInfo({
|
|
13
|
+
email: "",
|
|
14
|
+
authKey
|
|
15
|
+
}, configDir);
|
|
16
|
+
return "Authentication key successfully set";
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The static method that controls the access to the SDKClient instance.
|
|
21
|
+
*
|
|
22
|
+
* This implementation let you subclass the SDKClient class while keeping
|
|
23
|
+
* just one instance of each subclass around.
|
|
24
|
+
*/
|
|
25
|
+
static getInstance() {
|
|
26
|
+
if (!SDKClient.instance) {
|
|
27
|
+
SDKClient.instance = new SDKClient();
|
|
28
|
+
}
|
|
29
|
+
return SDKClient.instance;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Finally, any SDKClient should define some business logic, which can be
|
|
33
|
+
* executed on its instance.
|
|
34
|
+
*/
|
|
35
|
+
async login(email, password, configDir) {
|
|
36
|
+
let storedAuthInfo = await auth_manager_1.getAuthInfo(configDir);
|
|
37
|
+
// If no config file or no credentials exist in the config file
|
|
38
|
+
if (!storedAuthInfo) {
|
|
39
|
+
storedAuthInfo = { email: "", authKey: "" };
|
|
40
|
+
}
|
|
41
|
+
const credentials = { email, password };
|
|
42
|
+
const authKey = await this.getAuthKey(credentials);
|
|
43
|
+
if (storedAuthInfo.email !== email) {
|
|
44
|
+
auth_manager_1.setAuthInfo({
|
|
45
|
+
email,
|
|
46
|
+
authKey
|
|
47
|
+
}, configDir);
|
|
48
|
+
return "Logged in";
|
|
49
|
+
}
|
|
50
|
+
else if (authKey === storedAuthInfo.authKey) {
|
|
51
|
+
return "Already logged in";
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
auth_manager_1.setAuthInfo({
|
|
55
|
+
email,
|
|
56
|
+
authKey
|
|
57
|
+
}, configDir);
|
|
58
|
+
return "Logged in";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async logout(configDir) {
|
|
62
|
+
auth_manager_1.setAuthInfo({
|
|
63
|
+
email: "",
|
|
64
|
+
authKey: ""
|
|
65
|
+
}, configDir);
|
|
66
|
+
return "Logged out";
|
|
67
|
+
}
|
|
68
|
+
async status(configDir) {
|
|
69
|
+
try {
|
|
70
|
+
let storedAuthInfo = await auth_manager_1.getAuthInfo(configDir);
|
|
71
|
+
if (!storedAuthInfo) {
|
|
72
|
+
// If no config file or no credentials exist in the config file
|
|
73
|
+
storedAuthInfo = { email: "", authKey: "" };
|
|
74
|
+
}
|
|
75
|
+
return storedAuthInfo.email === "" && storedAuthInfo.authKey === ""
|
|
76
|
+
? "Not logged in"
|
|
77
|
+
: storedAuthInfo.email === "" && storedAuthInfo.authKey !== ""
|
|
78
|
+
? "Logged in with authentication key"
|
|
79
|
+
: `Currently logged in as ${storedAuthInfo.email}`;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async getClient(overrideAuthKey, configDir) {
|
|
86
|
+
if (overrideAuthKey) {
|
|
87
|
+
return new apimatic_sdk_for_js_1.Client({
|
|
88
|
+
timeout: 0,
|
|
89
|
+
authorization: `X-Auth-Key ${overrideAuthKey}`
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
let storedAuthInfo = await auth_manager_1.getAuthInfo(configDir);
|
|
93
|
+
if (!storedAuthInfo) {
|
|
94
|
+
// If no config file or no credentials exist in the config file
|
|
95
|
+
storedAuthInfo = { email: "", authKey: "" };
|
|
96
|
+
}
|
|
97
|
+
if (storedAuthInfo.authKey !== "") {
|
|
98
|
+
return new apimatic_sdk_for_js_1.Client({
|
|
99
|
+
timeout: 0,
|
|
100
|
+
authorization: `X-Auth-Key ${storedAuthInfo.authKey}`
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
throw new Error("Please login first or provide an authKey");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async getAuthKey(credentials) {
|
|
108
|
+
const config = {
|
|
109
|
+
headers: {
|
|
110
|
+
Authorization: `Basic ${base64.encode(`${credentials.email}:${credentials.password}`)}`
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const response = await axios_1.default.get(SDKClient.authAPI, config);
|
|
114
|
+
const authKey = response.data.EncryptedValue;
|
|
115
|
+
return authKey;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.SDKClient = SDKClient;
|
|
119
|
+
SDKClient.authAPI = `${env_1.baseURL}/account/authkey`;
|
|
@@ -0,0 +1,22 @@
|
|
|
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(`lists all commands related to the APIMatic API.
|
|
7
|
+
|
|
8
|
+
USAGE
|
|
9
|
+
$ apimatic api
|
|
10
|
+
|
|
11
|
+
EXAMPLE
|
|
12
|
+
$ apimatic api --help
|
|
13
|
+
|
|
14
|
+
COMMANDS
|
|
15
|
+
api:transform Transforms your API specification to any supported format of your choice from amongst[10+ different
|
|
16
|
+
formats](https://www.apimatic.io/transformer/#supported-formats).
|
|
17
|
+
api:validate Validates the provided API specification file for any syntactical and semantic errors`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.default = Api;
|
|
21
|
+
Api.description = "lists all commands related to the APIMatic API.";
|
|
22
|
+
Api.examples = ["$ apimatic api --help"];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ApiValidationSummary } from "@apimatic/apimatic-sdk-for-js";
|
|
2
|
+
import { flags, Command } from "@oclif/command";
|
|
3
|
+
export default class Transform extends Command {
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
format: flags.IOptionFlag<string>;
|
|
8
|
+
file: flags.IOptionFlag<string>;
|
|
9
|
+
url: flags.IOptionFlag<string>;
|
|
10
|
+
destination: flags.IOptionFlag<string>;
|
|
11
|
+
"auth-key": flags.IOptionFlag<string | undefined>;
|
|
12
|
+
};
|
|
13
|
+
printValidationMessages: (apiValidationSummary: ApiValidationSummary | undefined) => void;
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
}
|