@mablhq/mabl-cli 1.19.3 → 1.20.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/api/basicApiClient.js +4 -8
- package/api/mablApiClient.js +3 -3
- package/api/mablApiClientFactory.js +9 -9
- package/api/types.js +8 -0
- package/auth/AuthClient.js +1 -0
- package/auth/OktaClient.js +66 -21
- package/browserLauncher/playwrightBrowserLauncher/playwrightDom.js +11 -4
- package/browserLauncher/playwrightBrowserLauncher/playwrightFrame.js +1 -1
- package/browserLauncher/types.js +2 -2
- package/cli.js +1 -3
- package/commands/applications/applications_cmds/list.js +1 -1
- package/commands/auth/auth_cmds/activate-key.js +2 -2
- package/commands/auth/auth_cmds/clear.js +1 -1
- package/commands/auth/auth_cmds/info.js +1 -1
- package/commands/branches/branches_cmds/create.js +1 -1
- package/commands/branches/branches_cmds/describe.js +1 -1
- package/commands/branches/branches_cmds/list.js +1 -1
- package/commands/branches/branches_cmds/merge.js +1 -1
- package/commands/commandUtil/util.js +3 -3
- package/commands/config/config_cmds/configKeys.js +11 -0
- package/commands/config/config_cmds/delete.js +6 -5
- package/commands/config/config_cmds/get.js +6 -5
- package/commands/config/config_cmds/list.js +7 -7
- package/commands/config/config_cmds/set.js +14 -21
- package/commands/credentials/credentials_cmds/list.js +1 -1
- package/commands/deploy/deploy_cmds/create.js +2 -2
- package/commands/deploy/deploy_cmds/list.js +1 -1
- package/commands/environments/environments_cmds/create.js +8 -4
- package/commands/environments/environments_cmds/list.js +1 -1
- package/commands/flows/flows_cmds/list.js +1 -1
- package/commands/link-agents/link-agents_cmds/delete.js +1 -6
- package/commands/plans/plans_cmds/list.js +1 -1
- package/commands/tests/testsUtil.js +8 -8
- package/commands/tests/tests_cmds/create.js +1 -1
- package/commands/tests/tests_cmds/import.js +2 -2
- package/commands/tests/tests_cmds/list.js +1 -1
- package/commands/tests/tests_cmds/run-cloud.js +3 -7
- package/commands/tests/tests_cmds/run.js +8 -4
- package/commands/tests/tests_cmds/trainer_cmds/trainerUtil.js +2 -2
- package/execution/index.js +1 -1
- package/package.json +2 -1
- package/providers/authenticationProvider.js +106 -60
- package/providers/cliConfigProvider.js +159 -61
- package/providers/types.js +9 -0
- package/util/analytics.js +8 -8
- package/util/httpUtil.js +2 -2
- package/utilities.js +7 -0
package/api/basicApiClient.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.BasicApiClient =
|
|
29
|
+
exports.BasicApiClient = void 0;
|
|
30
30
|
const ApiError_1 = require("./ApiError");
|
|
31
31
|
const httpUtil_1 = require("../util/httpUtil");
|
|
32
32
|
const axios_1 = __importDefault(require("axios"));
|
|
@@ -34,6 +34,7 @@ const os = __importStar(require("os"));
|
|
|
34
34
|
const async_retry_1 = __importDefault(require("async-retry"));
|
|
35
35
|
const logUtils_1 = require("../util/logUtils");
|
|
36
36
|
const asyncUtil_1 = require("../util/asyncUtil");
|
|
37
|
+
const types_1 = require("./types");
|
|
37
38
|
const MABL_ENTITY_VERSION_HEADER = 'x-mabl-entity-version';
|
|
38
39
|
const DEFAULT_RETRYABLE_REQUEST_TIMEOUT_MILLISECONDS = 60000;
|
|
39
40
|
const DEFAULT_RETRIES = 10;
|
|
@@ -49,11 +50,6 @@ const RETRYABLE_NODEJS_ERRORS = [
|
|
|
49
50
|
'ETIMEOUT',
|
|
50
51
|
'ECONNABORTED',
|
|
51
52
|
];
|
|
52
|
-
var AuthType;
|
|
53
|
-
(function (AuthType) {
|
|
54
|
-
AuthType[AuthType["Bearer"] = 0] = "Bearer";
|
|
55
|
-
AuthType[AuthType["ApiKey"] = 1] = "ApiKey";
|
|
56
|
-
})(AuthType = exports.AuthType || (exports.AuthType = {}));
|
|
57
53
|
class BasicApiClient {
|
|
58
54
|
constructor(options) {
|
|
59
55
|
var _a, _b, _c, _d;
|
|
@@ -64,13 +60,13 @@ class BasicApiClient {
|
|
|
64
60
|
config.timeout =
|
|
65
61
|
(_c = (_a = options.requestTimeoutMillis) !== null && _a !== void 0 ? _a : (_b = options.retryConfig) === null || _b === void 0 ? void 0 : _b.requestTimeoutMillis) !== null && _c !== void 0 ? _c : DEFAULT_RETRYABLE_REQUEST_TIMEOUT_MILLISECONDS;
|
|
66
62
|
switch (options.authType) {
|
|
67
|
-
case AuthType.ApiKey:
|
|
63
|
+
case types_1.AuthType.ApiKey:
|
|
68
64
|
config.auth = {
|
|
69
65
|
username: 'key',
|
|
70
66
|
password: options.token,
|
|
71
67
|
};
|
|
72
68
|
break;
|
|
73
|
-
case AuthType.Bearer:
|
|
69
|
+
case types_1.AuthType.Bearer:
|
|
74
70
|
config.headers.authorization = `Bearer ${options.token}`;
|
|
75
71
|
break;
|
|
76
72
|
default:
|
package/api/mablApiClient.js
CHANGED
|
@@ -319,13 +319,13 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
|
|
|
319
319
|
try {
|
|
320
320
|
const selfInfo = await this.makeGetRequest(`${env_1.BASE_API_URL}/self`);
|
|
321
321
|
if (((_a = selfInfo.preferences) === null || _a === void 0 ? void 0 : _a.default_workspace_id) &&
|
|
322
|
-
!cliConfigProvider_1.CliConfigProvider.getWorkspace()) {
|
|
322
|
+
!(await cliConfigProvider_1.CliConfigProvider.getWorkspace())) {
|
|
323
323
|
const workspace = await this.getWorkspace(selfInfo.preferences.default_workspace_id);
|
|
324
|
-
cliConfigProvider_1.CliConfigProvider.setWorkspace(workspace);
|
|
324
|
+
await cliConfigProvider_1.CliConfigProvider.setWorkspace(workspace);
|
|
325
325
|
}
|
|
326
326
|
else if (((_b = selfInfo.roles) === null || _b === void 0 ? void 0 : _b.length) === 1) {
|
|
327
327
|
const workspace = await this.getWorkspace(selfInfo.roles[0].organization_id);
|
|
328
|
-
cliConfigProvider_1.CliConfigProvider.setWorkspace(workspace);
|
|
328
|
+
await cliConfigProvider_1.CliConfigProvider.setWorkspace(workspace);
|
|
329
329
|
}
|
|
330
330
|
return selfInfo;
|
|
331
331
|
}
|
|
@@ -7,13 +7,13 @@ exports.MablApiClientFactory = void 0;
|
|
|
7
7
|
const mablApiClient_1 = require("./mablApiClient");
|
|
8
8
|
const authenticationProvider_1 = require("../providers/authenticationProvider");
|
|
9
9
|
const cliConfigProvider_1 = require("../providers/cliConfigProvider");
|
|
10
|
-
const
|
|
10
|
+
const types_1 = require("./types");
|
|
11
11
|
const chalk_1 = __importDefault(require("chalk"));
|
|
12
12
|
class MablApiClientFactory {
|
|
13
13
|
static createApiClientFromOptionalApiKey(apiKey) {
|
|
14
14
|
if (apiKey) {
|
|
15
15
|
return MablApiClientFactory.createApiClient({
|
|
16
|
-
authType:
|
|
16
|
+
authType: types_1.AuthType.ApiKey,
|
|
17
17
|
authToken: apiKey,
|
|
18
18
|
});
|
|
19
19
|
}
|
|
@@ -21,18 +21,18 @@ class MablApiClientFactory {
|
|
|
21
21
|
}
|
|
22
22
|
static createApiClientFromApiKey(apiKey) {
|
|
23
23
|
return MablApiClientFactory.createApiClient({
|
|
24
|
-
authType:
|
|
24
|
+
authType: types_1.AuthType.ApiKey,
|
|
25
25
|
authToken: apiKey,
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
static createApiClientFromBearerToken(bearerToken) {
|
|
29
29
|
return MablApiClientFactory.createApiClient({
|
|
30
|
-
authType:
|
|
30
|
+
authType: types_1.AuthType.Bearer,
|
|
31
31
|
authToken: bearerToken,
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
static async createApiClient(opts) {
|
|
35
|
-
const httpConfig = cliConfigProvider_1.CliConfigProvider.getCliConfig().http;
|
|
35
|
+
const httpConfig = (await cliConfigProvider_1.CliConfigProvider.getCliConfig()).http;
|
|
36
36
|
if (opts) {
|
|
37
37
|
return new mablApiClient_1.MablApiClient({
|
|
38
38
|
authType: opts.authType,
|
|
@@ -55,15 +55,15 @@ class MablApiClientFactory {
|
|
|
55
55
|
throw new Error('Please supply an API key or authenticate the mabl CLI tool');
|
|
56
56
|
}
|
|
57
57
|
static async createUserApiClient() {
|
|
58
|
-
if (authenticationProvider_1.AuthenticationProvider.getAuthType() !==
|
|
58
|
+
if ((await authenticationProvider_1.AuthenticationProvider.getAuthType()) !== types_1.AuthType.Bearer) {
|
|
59
59
|
MablApiClientFactory.throwUserAuthTypeError();
|
|
60
60
|
}
|
|
61
61
|
return MablApiClientFactory.createApiClient();
|
|
62
62
|
}
|
|
63
|
-
static createApiClientForAccessToken(accessToken) {
|
|
64
|
-
const httpConfig = cliConfigProvider_1.CliConfigProvider.getCliConfig().http;
|
|
63
|
+
static async createApiClientForAccessToken(accessToken) {
|
|
64
|
+
const httpConfig = (await cliConfigProvider_1.CliConfigProvider.getCliConfig()).http;
|
|
65
65
|
return new mablApiClient_1.MablApiClient({
|
|
66
|
-
authType:
|
|
66
|
+
authType: types_1.AuthType.Bearer,
|
|
67
67
|
token: accessToken,
|
|
68
68
|
proxyUrl: httpConfig.proxyHost,
|
|
69
69
|
sslVerify: httpConfig.sslVerify,
|
package/api/types.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthType = void 0;
|
|
4
|
+
var AuthType;
|
|
5
|
+
(function (AuthType) {
|
|
6
|
+
AuthType[AuthType["Bearer"] = 0] = "Bearer";
|
|
7
|
+
AuthType[AuthType["ApiKey"] = 1] = "ApiKey";
|
|
8
|
+
})(AuthType = exports.AuthType || (exports.AuthType = {}));
|
package/auth/AuthClient.js
CHANGED
package/auth/OktaClient.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.OktaClient = void 0;
|
|
4
7
|
const env_1 = require("../env/env");
|
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
|
5
9
|
const authenticationProvider_1 = require("../providers/authenticationProvider");
|
|
6
|
-
const
|
|
10
|
+
const types_1 = require("../providers/types");
|
|
11
|
+
const types_2 = require("../api/types");
|
|
7
12
|
const AuthClient_1 = require("./AuthClient");
|
|
13
|
+
const loggingProvider_1 = require("../providers/logging/loggingProvider");
|
|
8
14
|
const queryString = require('query-string');
|
|
9
15
|
class OktaClient extends AuthClient_1.AuthClient {
|
|
10
16
|
constructor(httpClient) {
|
|
@@ -12,41 +18,80 @@ class OktaClient extends AuthClient_1.AuthClient {
|
|
|
12
18
|
this.httpClient = httpClient;
|
|
13
19
|
}
|
|
14
20
|
async validateAuthCode(code, codeVerifier, redirectUri) {
|
|
15
|
-
|
|
16
|
-
const requestOptions = {
|
|
17
|
-
method: 'POST',
|
|
18
|
-
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
19
|
-
};
|
|
20
|
-
const data = queryString.stringify({
|
|
21
|
+
return this.getBearerAuthInfo(queryString.stringify({
|
|
21
22
|
grant_type: 'authorization_code',
|
|
22
23
|
client_id: env_1.OKTA_CLIENT_ID,
|
|
23
24
|
code_verifier: codeVerifier,
|
|
24
25
|
code,
|
|
25
26
|
redirect_uri: redirectUri,
|
|
26
|
-
});
|
|
27
|
-
const response = await this.httpClient.post(url, data, requestOptions);
|
|
28
|
-
const authInfo = response.data;
|
|
29
|
-
authInfo.auth_provider = authenticationProvider_1.AuthProviderType.Okta;
|
|
30
|
-
authInfo.auth_type = basicApiClient_1.AuthType.Bearer;
|
|
31
|
-
return authInfo;
|
|
27
|
+
}));
|
|
32
28
|
}
|
|
33
|
-
async
|
|
34
|
-
|
|
29
|
+
async getRefreshTokenExpiration(refreshToken) {
|
|
30
|
+
if (!refreshToken) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const url = `${env_1.OKTA_URL}/oauth2/v1/introspect`;
|
|
35
34
|
const requestOptions = {
|
|
36
35
|
method: 'POST',
|
|
37
36
|
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
38
37
|
};
|
|
39
38
|
const data = queryString.stringify({
|
|
40
|
-
grant_type: 'refresh_token',
|
|
41
39
|
client_id: env_1.OKTA_CLIENT_ID,
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
token_type_hint: 'refresh_token',
|
|
41
|
+
token: refreshToken,
|
|
44
42
|
});
|
|
45
|
-
|
|
43
|
+
try {
|
|
44
|
+
const response = await this.httpClient.post(url, data, requestOptions);
|
|
45
|
+
return response.data.exp;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
loggingProvider_1.logger.info(`Couldn't get refresh token expiration. Will re-use previous lifetime.`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async getBearerAuthInfo(queryStringData) {
|
|
53
|
+
const url = `${env_1.OKTA_URL}/oauth2/default/v1/token`;
|
|
54
|
+
const requestOptions = {
|
|
55
|
+
method: 'POST',
|
|
56
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
57
|
+
};
|
|
58
|
+
const response = await this.httpClient.post(url, queryStringData, requestOptions);
|
|
46
59
|
const authInfo = response.data;
|
|
47
|
-
|
|
48
|
-
authInfo.
|
|
60
|
+
const refreshTokenExpiresAt = await this.getRefreshTokenExpiration(authInfo.refresh_token);
|
|
61
|
+
authInfo.auth_provider = types_1.AuthProviderType.Okta;
|
|
62
|
+
authInfo.auth_type = types_2.AuthType.Bearer;
|
|
63
|
+
authInfo.refresh_token_expires_at = refreshTokenExpiresAt;
|
|
49
64
|
return authInfo;
|
|
50
65
|
}
|
|
66
|
+
exchangeRefreshTokenForAccessToken(refreshToken) {
|
|
67
|
+
var _a;
|
|
68
|
+
try {
|
|
69
|
+
return this.getBearerAuthInfo(queryString.stringify({
|
|
70
|
+
grant_type: 'refresh_token',
|
|
71
|
+
client_id: env_1.OKTA_CLIENT_ID,
|
|
72
|
+
refresh_token: refreshToken,
|
|
73
|
+
scope: 'openid profile email offline_access',
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (!axios_1.default.isAxiosError(error)) {
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
const data = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
|
|
81
|
+
if (!(0, authenticationProvider_1.isOidcError)(data)) {
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
return Promise.resolve({
|
|
85
|
+
auth_provider: types_1.AuthProviderType.Okta,
|
|
86
|
+
auth_type: types_2.AuthType.Bearer,
|
|
87
|
+
access_token: '',
|
|
88
|
+
id_token: '',
|
|
89
|
+
token_type: '',
|
|
90
|
+
expires_in: 0,
|
|
91
|
+
error: data.error,
|
|
92
|
+
error_description: data.error_description,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
51
96
|
}
|
|
52
97
|
exports.OktaClient = OktaClient;
|
|
@@ -132,13 +132,13 @@ class PlaywrightElementHandle extends PlaywrightJsHandle {
|
|
|
132
132
|
return (0, utils_1.mapIfNotNull)(await this.element.boundingBox(), (boundingBox) => boundingBox);
|
|
133
133
|
}
|
|
134
134
|
async click(options) {
|
|
135
|
-
var _a, _b, _c
|
|
135
|
+
var _a, _b, _c;
|
|
136
136
|
const trial = (_a = options === null || options === void 0 ? void 0 : options.trial) !== null && _a !== void 0 ? _a : false;
|
|
137
137
|
try {
|
|
138
138
|
await this.element.click({
|
|
139
139
|
clickCount: (_b = options === null || options === void 0 ? void 0 : options.clickCount) !== null && _b !== void 0 ? _b : 1,
|
|
140
140
|
force: (_c = options === null || options === void 0 ? void 0 : options.force) !== null && _c !== void 0 ? _c : !trial,
|
|
141
|
-
timeout: (
|
|
141
|
+
timeout: this.getActionTimeout(options),
|
|
142
142
|
trial,
|
|
143
143
|
});
|
|
144
144
|
}
|
|
@@ -151,12 +151,12 @@ class PlaywrightElementHandle extends PlaywrightJsHandle {
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
async doubleClick(options) {
|
|
154
|
-
var _a, _b
|
|
154
|
+
var _a, _b;
|
|
155
155
|
try {
|
|
156
156
|
const trial = (_a = options === null || options === void 0 ? void 0 : options.trial) !== null && _a !== void 0 ? _a : false;
|
|
157
157
|
return this.element.dblclick({
|
|
158
158
|
force: (_b = options === null || options === void 0 ? void 0 : options.force) !== null && _b !== void 0 ? _b : !trial,
|
|
159
|
-
timeout: (
|
|
159
|
+
timeout: this.getActionTimeout(options),
|
|
160
160
|
trial,
|
|
161
161
|
});
|
|
162
162
|
}
|
|
@@ -273,5 +273,12 @@ class PlaywrightElementHandle extends PlaywrightJsHandle {
|
|
|
273
273
|
const result = await this.element.evaluate((el) => el.innerText);
|
|
274
274
|
return (0, pureUtil_1.isNullish)(result) ? undefined : result;
|
|
275
275
|
}
|
|
276
|
+
getActionTimeout(options) {
|
|
277
|
+
var _a;
|
|
278
|
+
const defaultTimeout = (options === null || options === void 0 ? void 0 : options.trial)
|
|
279
|
+
? types_1.DefaultTimeouts.defaultTrialTimeoutMs
|
|
280
|
+
: types_1.DefaultTimeouts.defaultActionTimeoutMs;
|
|
281
|
+
return (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : defaultTimeout;
|
|
282
|
+
}
|
|
276
283
|
}
|
|
277
284
|
exports.PlaywrightElementHandle = PlaywrightElementHandle;
|
|
@@ -129,7 +129,7 @@ class PlaywrightFrame extends browserLauncher_1.Frame {
|
|
|
129
129
|
const response = await this.frame.goto(url, options);
|
|
130
130
|
if (waitForNetworkIdle) {
|
|
131
131
|
await this.frame.waitForLoadState('networkidle', {
|
|
132
|
-
timeout: types_1.DefaultTimeouts.
|
|
132
|
+
timeout: types_1.DefaultTimeouts.defaultActionTimeoutMs,
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
return (0, utils_1.mapIfNotNull)(response, (response) => new playwrightHttpResponse_1.PlaywrightHttpResponse(this.parentPage, response));
|
package/browserLauncher/types.js
CHANGED
|
@@ -4,8 +4,8 @@ exports.WaitForOptions = exports.LifecycleEvent = exports.DefaultTimeouts = void
|
|
|
4
4
|
class DefaultTimeouts {
|
|
5
5
|
}
|
|
6
6
|
exports.DefaultTimeouts = DefaultTimeouts;
|
|
7
|
-
DefaultTimeouts.
|
|
8
|
-
DefaultTimeouts.
|
|
7
|
+
DefaultTimeouts.defaultTrialTimeoutMs = 5000;
|
|
8
|
+
DefaultTimeouts.defaultActionTimeoutMs = 0;
|
|
9
9
|
var LifecycleEvent;
|
|
10
10
|
(function (LifecycleEvent) {
|
|
11
11
|
LifecycleEvent["DomContentLoaded"] = "domcontentloaded";
|
package/cli.js
CHANGED
|
@@ -85,9 +85,7 @@ yargs
|
|
|
85
85
|
catch (_) {
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
|
-
(argv) =>
|
|
89
|
-
(0, analytics_1.trackCliEvent)(argv._, (0, pureUtil_1.extractKeyCountsFromArgs)(argv));
|
|
90
|
-
},
|
|
88
|
+
async (argv) => (0, analytics_1.trackCliEvent)(argv._, (0, pureUtil_1.extractKeyCountsFromArgs)(argv)),
|
|
91
89
|
() => {
|
|
92
90
|
updateNotifier({
|
|
93
91
|
pkg: cliPackage,
|
|
@@ -18,7 +18,7 @@ exports.handler = (0, util_1.failWrapper)(listApplications);
|
|
|
18
18
|
async function listApplications(parsed) {
|
|
19
19
|
const output = parsed.output;
|
|
20
20
|
const limit = parsed.limit;
|
|
21
|
-
const workspaceId = (0, util_1.getWorkspaceId)(parsed);
|
|
21
|
+
const workspaceId = await (0, util_1.getWorkspaceId)(parsed);
|
|
22
22
|
const apiClient = await mablApiClientFactory_1.MablApiClientFactory.createApiClient();
|
|
23
23
|
const applications = await apiClient.getApplications(workspaceId, limit);
|
|
24
24
|
printApplications(applications, output);
|
|
@@ -24,6 +24,6 @@ async function activateApiKey(parsed) {
|
|
|
24
24
|
const mablApi = await mablApiClientFactory_1.MablApiClientFactory.createApiClientFromApiKey(cleanApiKey);
|
|
25
25
|
const apiKeyDetails = await mablApi.getApiKeyDetails();
|
|
26
26
|
const apiKeyWorkspace = await mablApi.getWorkspace(apiKeyDetails.workspace_id);
|
|
27
|
-
cliConfigProvider_1.CliConfigProvider.setWorkspace(apiKeyWorkspace);
|
|
28
|
-
auth.activateApiKey(cleanApiKey);
|
|
27
|
+
await cliConfigProvider_1.CliConfigProvider.setWorkspace(apiKeyWorkspace);
|
|
28
|
+
return auth.activateApiKey(cleanApiKey);
|
|
29
29
|
}
|
|
@@ -39,7 +39,7 @@ exports.builder = (yargs) => {
|
|
|
39
39
|
exports.handler = (0, util_1.failWrapper)(createBranch);
|
|
40
40
|
async function createBranch(parsed) {
|
|
41
41
|
const apiClient = await mablApiClientFactory_1.MablApiClientFactory.createApiClient();
|
|
42
|
-
const workspaceId = (0, util_1.getWorkspaceId)(parsed);
|
|
42
|
+
const workspaceId = await (0, util_1.getWorkspaceId)(parsed);
|
|
43
43
|
const branchName = parsed.name;
|
|
44
44
|
loggingProvider_1.logger.info(`Creating Branch [${branchName}]`);
|
|
45
45
|
try {
|
|
@@ -39,7 +39,7 @@ async function getBranch(parsed) {
|
|
|
39
39
|
const apiClient = await mablApiClientFactory_1.MablApiClientFactory.createApiClient();
|
|
40
40
|
let branch;
|
|
41
41
|
if (lookupByName) {
|
|
42
|
-
const workspaceId = (0, util_1.getWorkspaceId)(parsed);
|
|
42
|
+
const workspaceId = await (0, util_1.getWorkspaceId)(parsed);
|
|
43
43
|
branch = await apiClient.getBranchByName(workspaceId, branchIdentifier);
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
@@ -43,7 +43,7 @@ async function listBranches(parsed) {
|
|
|
43
43
|
const output = parsed.output;
|
|
44
44
|
const limit = parsed.limit;
|
|
45
45
|
const statusFilter = parsed.status;
|
|
46
|
-
const workspaceId = (0, util_1.getWorkspaceId)(parsed);
|
|
46
|
+
const workspaceId = await (0, util_1.getWorkspaceId)(parsed);
|
|
47
47
|
const apiClient = await mablApiClientFactory_1.MablApiClientFactory.createApiClient();
|
|
48
48
|
const branches = await apiClient.getBranches(workspaceId, limit, statusFilter);
|
|
49
49
|
printBranches(branches, output);
|
|
@@ -47,7 +47,7 @@ exports.builder = (yargs) => {
|
|
|
47
47
|
exports.handler = (0, util_1.failWrapper)(mergeBranch);
|
|
48
48
|
async function mergeBranch(parsed) {
|
|
49
49
|
const apiClient = await mablApiClientFactory_1.MablApiClientFactory.createApiClient();
|
|
50
|
-
const workspaceId = (0, util_1.getWorkspaceId)(parsed);
|
|
50
|
+
const workspaceId = await (0, util_1.getWorkspaceId)(parsed);
|
|
51
51
|
const fromBranchName = parsed.from;
|
|
52
52
|
const toBranchName = parsed.to;
|
|
53
53
|
const branch = await apiClient.mergeBranch(workspaceId, fromBranchName, toBranchName);
|
|
@@ -24,12 +24,12 @@ function failWrapper(func, exitCodeOnError = 1) {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
exports.failWrapper = failWrapper;
|
|
27
|
-
function getWorkspaceId(parsed) {
|
|
28
|
-
const workspaceId = parsed[
|
|
27
|
+
async function getWorkspaceId(parsed) {
|
|
28
|
+
const workspaceId = parsed[constants_1.CommandArgWorkspaceId];
|
|
29
29
|
if (workspaceId) {
|
|
30
30
|
return workspaceId;
|
|
31
31
|
}
|
|
32
|
-
const configuredWorkspace = cliConfigProvider_1.CliConfigProvider.getWorkspace();
|
|
32
|
+
const configuredWorkspace = await cliConfigProvider_1.CliConfigProvider.getWorkspace();
|
|
33
33
|
if (configuredWorkspace === null || configuredWorkspace === void 0 ? void 0 : configuredWorkspace.id) {
|
|
34
34
|
return configuredWorkspace.id;
|
|
35
35
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validConfigKeyChoices = exports.configKeys = void 0;
|
|
4
|
+
exports.configKeys = Object.freeze({
|
|
5
|
+
browserPath: 'browser.path',
|
|
6
|
+
enableSourceControlMetadataCollection: 'alpha.scm_metadata.enable',
|
|
7
|
+
defaultWorkspaceId: 'workspace',
|
|
8
|
+
proxy: 'http.proxy',
|
|
9
|
+
sslVerify: 'http.sslVerify',
|
|
10
|
+
});
|
|
11
|
+
exports.validConfigKeyChoices = Object.values(exports.configKeys);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const cliConfigProvider_1 = require("../../../providers/cliConfigProvider");
|
|
4
4
|
const set_1 = require("./set");
|
|
5
|
+
const configKeys_1 = require("./configKeys");
|
|
5
6
|
const list_1 = require("./list");
|
|
6
7
|
const loggingProvider_1 = require("../../../providers/logging/loggingProvider");
|
|
7
8
|
exports.command = `delete <${set_1.configKeyCommandArg}>`;
|
|
@@ -10,18 +11,18 @@ exports.builder = (yargs) => {
|
|
|
10
11
|
yargs.positional(set_1.configKeyCommandArg, {
|
|
11
12
|
describe: 'configuration key to delete',
|
|
12
13
|
type: 'string',
|
|
13
|
-
choices:
|
|
14
|
+
choices: configKeys_1.validConfigKeyChoices,
|
|
14
15
|
});
|
|
15
16
|
};
|
|
16
17
|
exports.handler = deleteConfig;
|
|
17
|
-
function deleteConfig(parsed) {
|
|
18
|
+
async function deleteConfig(parsed) {
|
|
18
19
|
const key = parsed['config-key'];
|
|
19
20
|
switch (key) {
|
|
20
|
-
case
|
|
21
|
-
cliConfigProvider_1.CliConfigProvider.clearWorkspace();
|
|
21
|
+
case configKeys_1.configKeys.defaultWorkspaceId:
|
|
22
|
+
await cliConfigProvider_1.CliConfigProvider.clearWorkspace();
|
|
22
23
|
break;
|
|
23
24
|
default:
|
|
24
|
-
cliConfigProvider_1.CliConfigProvider.clearConfigProperty(key);
|
|
25
|
+
await cliConfigProvider_1.CliConfigProvider.clearConfigProperty(key);
|
|
25
26
|
}
|
|
26
27
|
loggingProvider_1.logger.info(`Deleted config for [${key}]`);
|
|
27
28
|
return (0, list_1.listConfig)();
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const cliConfigProvider_1 = require("../../../providers/cliConfigProvider");
|
|
7
7
|
const set_1 = require("./set");
|
|
8
|
+
const configKeys_1 = require("./configKeys");
|
|
8
9
|
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
9
10
|
const list_1 = require("./list");
|
|
10
11
|
const loggingProvider_1 = require("../../../providers/logging/loggingProvider");
|
|
@@ -17,15 +18,15 @@ exports.builder = (yargs) => {
|
|
|
17
18
|
});
|
|
18
19
|
};
|
|
19
20
|
exports.handler = getConfig;
|
|
20
|
-
function getConfig(parsed) {
|
|
21
|
+
async function getConfig(parsed) {
|
|
21
22
|
const key = parsed['config-key'];
|
|
22
23
|
const table = new cli_table3_1.default({
|
|
23
24
|
head: ['Config', 'Value', 'Details'],
|
|
24
25
|
});
|
|
25
26
|
let value;
|
|
26
27
|
switch (key) {
|
|
27
|
-
case
|
|
28
|
-
const workspace = cliConfigProvider_1.CliConfigProvider.getWorkspace();
|
|
28
|
+
case configKeys_1.configKeys.defaultWorkspaceId:
|
|
29
|
+
const workspace = await cliConfigProvider_1.CliConfigProvider.getWorkspace();
|
|
29
30
|
if (workspace) {
|
|
30
31
|
table.push([key, workspace.id, workspace.name]);
|
|
31
32
|
value = workspace.id;
|
|
@@ -35,10 +36,10 @@ function getConfig(parsed) {
|
|
|
35
36
|
}
|
|
36
37
|
break;
|
|
37
38
|
default:
|
|
38
|
-
if (!Object.values(
|
|
39
|
+
if (!Object.values(configKeys_1.configKeys).includes(key)) {
|
|
39
40
|
throw new Error(`Unknown key [${key}]`);
|
|
40
41
|
}
|
|
41
|
-
const propertyValue = cliConfigProvider_1.CliConfigProvider.getConfigProperty(key);
|
|
42
|
+
const propertyValue = await cliConfigProvider_1.CliConfigProvider.getConfigProperty(key);
|
|
42
43
|
if (propertyValue !== undefined) {
|
|
43
44
|
table.push([key, propertyValue, list_1.defaultTupleValue]);
|
|
44
45
|
}
|
|
@@ -6,33 +6,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.listConfig = exports.defaultTupleValue = void 0;
|
|
7
7
|
const cliConfigProvider_1 = require("../../../providers/cliConfigProvider");
|
|
8
8
|
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
9
|
-
const
|
|
9
|
+
const configKeys_1 = require("./configKeys");
|
|
10
10
|
const loggingProvider_1 = require("../../../providers/logging/loggingProvider");
|
|
11
11
|
exports.command = `list`;
|
|
12
12
|
exports.describe = 'List all user config values';
|
|
13
13
|
exports.handler = listConfig;
|
|
14
14
|
exports.defaultTupleValue = '---';
|
|
15
|
-
function listConfig() {
|
|
15
|
+
async function listConfig() {
|
|
16
16
|
const table = new cli_table3_1.default({
|
|
17
17
|
head: ['Config', 'Value', 'Details'],
|
|
18
18
|
colWidths: [null, 60],
|
|
19
19
|
});
|
|
20
|
-
|
|
20
|
+
for (const propertyKey of configKeys_1.validConfigKeyChoices) {
|
|
21
21
|
let value;
|
|
22
22
|
let details;
|
|
23
23
|
switch (propertyKey) {
|
|
24
|
-
case
|
|
25
|
-
const maybeWorkspace = cliConfigProvider_1.CliConfigProvider.getWorkspace();
|
|
24
|
+
case configKeys_1.configKeys.defaultWorkspaceId:
|
|
25
|
+
const maybeWorkspace = await cliConfigProvider_1.CliConfigProvider.getWorkspace();
|
|
26
26
|
value = maybeWorkspace === null || maybeWorkspace === void 0 ? void 0 : maybeWorkspace.id;
|
|
27
27
|
details = maybeWorkspace === null || maybeWorkspace === void 0 ? void 0 : maybeWorkspace.name;
|
|
28
28
|
break;
|
|
29
29
|
default:
|
|
30
|
-
value = cliConfigProvider_1.CliConfigProvider.getConfigProperty(propertyKey);
|
|
30
|
+
value = await cliConfigProvider_1.CliConfigProvider.getConfigProperty(propertyKey);
|
|
31
31
|
}
|
|
32
32
|
const displayValue = value !== undefined ? value : exports.defaultTupleValue;
|
|
33
33
|
const displayDetails = details !== undefined ? details : exports.defaultTupleValue;
|
|
34
34
|
table.push([propertyKey, displayValue, displayDetails]);
|
|
35
|
-
}
|
|
35
|
+
}
|
|
36
36
|
loggingProvider_1.logger.info(table.toString());
|
|
37
37
|
return table;
|
|
38
38
|
}
|
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.configKeyCommandArg = void 0;
|
|
4
4
|
const cliConfigProvider_1 = require("../../../providers/cliConfigProvider");
|
|
5
5
|
const mablApiClientFactory_1 = require("../../../api/mablApiClientFactory");
|
|
6
6
|
const list_1 = require("./list");
|
|
7
7
|
const loggingProvider_1 = require("../../../providers/logging/loggingProvider");
|
|
8
|
+
const configKeys_1 = require("./configKeys");
|
|
8
9
|
exports.configKeyCommandArg = 'config-key';
|
|
9
10
|
const configValue = 'config-value';
|
|
10
|
-
exports.configKeys = Object.freeze({
|
|
11
|
-
browserPath: 'browser.path',
|
|
12
|
-
enableSourceControlMetadataCollection: 'alpha.scm_metadata.enable',
|
|
13
|
-
defaultWorkspaceId: 'workspace',
|
|
14
|
-
proxy: 'http.proxy',
|
|
15
|
-
sslVerify: 'http.sslVerify',
|
|
16
|
-
});
|
|
17
|
-
exports.validConfigKeyChoices = Object.values(exports.configKeys);
|
|
18
11
|
exports.command = `set <${exports.configKeyCommandArg}> <${configValue}>`;
|
|
19
12
|
exports.describe = 'Set a default configuration key';
|
|
20
13
|
exports.builder = (yargs) => {
|
|
@@ -22,7 +15,7 @@ exports.builder = (yargs) => {
|
|
|
22
15
|
.positional(exports.configKeyCommandArg, {
|
|
23
16
|
describe: 'The configuration key to set',
|
|
24
17
|
type: 'string',
|
|
25
|
-
choices:
|
|
18
|
+
choices: configKeys_1.validConfigKeyChoices,
|
|
26
19
|
})
|
|
27
20
|
.positional(configValue, {
|
|
28
21
|
describe: 'The value to configure for the config',
|
|
@@ -34,33 +27,33 @@ async function setConfig(parsed) {
|
|
|
34
27
|
const key = parsed['config-key'];
|
|
35
28
|
const value = parsed['config-value'];
|
|
36
29
|
switch (key) {
|
|
37
|
-
case
|
|
38
|
-
cliConfigProvider_1.CliConfigProvider.setConfigProperty(
|
|
30
|
+
case configKeys_1.configKeys.browserPath:
|
|
31
|
+
await cliConfigProvider_1.CliConfigProvider.setConfigProperty(configKeys_1.configKeys.browserPath, value);
|
|
39
32
|
break;
|
|
40
|
-
case
|
|
33
|
+
case configKeys_1.configKeys.defaultWorkspaceId:
|
|
41
34
|
const apiClient = await mablApiClientFactory_1.MablApiClientFactory.createApiClient();
|
|
42
35
|
const workspace = await apiClient.getWorkspace(value);
|
|
43
|
-
cliConfigProvider_1.CliConfigProvider.setWorkspace(workspace);
|
|
36
|
+
await cliConfigProvider_1.CliConfigProvider.setWorkspace(workspace);
|
|
44
37
|
break;
|
|
45
|
-
case
|
|
46
|
-
case
|
|
38
|
+
case configKeys_1.configKeys.enableSourceControlMetadataCollection:
|
|
39
|
+
case configKeys_1.configKeys.sslVerify:
|
|
47
40
|
if (!['true', 'false'].includes(value)) {
|
|
48
41
|
throw new Error("Valid values are 'true' and 'false'");
|
|
49
42
|
}
|
|
50
43
|
const booleanValue = value === 'true';
|
|
51
|
-
cliConfigProvider_1.CliConfigProvider.setConfigProperty(key, booleanValue);
|
|
44
|
+
await cliConfigProvider_1.CliConfigProvider.setConfigProperty(key, booleanValue);
|
|
52
45
|
break;
|
|
53
|
-
case
|
|
46
|
+
case configKeys_1.configKeys.proxy:
|
|
54
47
|
if (!isValidUrl(value)) {
|
|
55
48
|
throw new Error(`Invalid URL specified. The value must be a fully specified URL with a valid protocol and domain: ${value}`);
|
|
56
49
|
}
|
|
57
|
-
cliConfigProvider_1.CliConfigProvider.setConfigProperty(key, value);
|
|
50
|
+
await cliConfigProvider_1.CliConfigProvider.setConfigProperty(key, value);
|
|
58
51
|
break;
|
|
59
52
|
default:
|
|
60
|
-
throw new Error(`<${exports.configKeyCommandArg}> value not one of supported types: ${JSON.stringify(
|
|
53
|
+
throw new Error(`<${exports.configKeyCommandArg}> value not one of supported types: ${JSON.stringify(configKeys_1.validConfigKeyChoices)}`);
|
|
61
54
|
}
|
|
62
55
|
loggingProvider_1.logger.info(`Configured [${key}] = [${value}]`);
|
|
63
|
-
(0, list_1.listConfig)();
|
|
56
|
+
await (0, list_1.listConfig)();
|
|
64
57
|
return key;
|
|
65
58
|
}
|
|
66
59
|
function isValidUrl(value) {
|