@mablhq/mabl-cli 1.18.3 → 1.20.9

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 (51) hide show
  1. package/api/basicApiClient.js +17 -13
  2. package/api/mablApiClient.js +11 -7
  3. package/api/mablApiClientFactory.js +20 -19
  4. package/api/types.js +8 -0
  5. package/auth/AuthClient.js +1 -0
  6. package/auth/OktaClient.js +66 -21
  7. package/browserLauncher/playwrightBrowserLauncher/playwrightBrowser.js +12 -0
  8. package/browserLauncher/playwrightBrowserLauncher/playwrightBrowserLauncher.js +2 -6
  9. package/browserLauncher/playwrightBrowserLauncher/playwrightDom.js +11 -4
  10. package/browserLauncher/playwrightBrowserLauncher/playwrightFrame.js +1 -1
  11. package/browserLauncher/playwrightBrowserLauncher/playwrightPage.js +0 -2
  12. package/browserLauncher/types.js +3 -2
  13. package/cli.js +1 -3
  14. package/commands/applications/applications_cmds/list.js +1 -1
  15. package/commands/auth/auth_cmds/activate-key.js +2 -2
  16. package/commands/auth/auth_cmds/clear.js +1 -1
  17. package/commands/auth/auth_cmds/info.js +1 -1
  18. package/commands/branches/branches_cmds/create.js +1 -1
  19. package/commands/branches/branches_cmds/describe.js +1 -1
  20. package/commands/branches/branches_cmds/list.js +1 -1
  21. package/commands/branches/branches_cmds/merge.js +1 -1
  22. package/commands/commandUtil/util.js +3 -3
  23. package/commands/config/config_cmds/configKeys.js +11 -0
  24. package/commands/config/config_cmds/delete.js +6 -5
  25. package/commands/config/config_cmds/get.js +6 -5
  26. package/commands/config/config_cmds/list.js +7 -7
  27. package/commands/config/config_cmds/set.js +14 -21
  28. package/commands/credentials/credentials_cmds/list.js +1 -1
  29. package/commands/deploy/deploy_cmds/create.js +2 -2
  30. package/commands/deploy/deploy_cmds/list.js +1 -1
  31. package/commands/environments/environments_cmds/create.js +8 -4
  32. package/commands/environments/environments_cmds/list.js +1 -1
  33. package/commands/flows/flows_cmds/list.js +1 -1
  34. package/commands/link-agents/link-agents_cmds/delete.js +1 -6
  35. package/commands/plans/plans_cmds/list.js +1 -1
  36. package/commands/tests/testsUtil.js +8 -8
  37. package/commands/tests/tests_cmds/create.js +1 -1
  38. package/commands/tests/tests_cmds/import.js +2 -2
  39. package/commands/tests/tests_cmds/list.js +1 -1
  40. package/commands/tests/tests_cmds/run-cloud.js +3 -7
  41. package/commands/tests/tests_cmds/run.js +8 -4
  42. package/commands/tests/tests_cmds/trainer_cmds/trainerUtil.js +2 -2
  43. package/execution/index.js +1 -1
  44. package/mablscript/diffing/diffingUtil.js +9 -9
  45. package/package.json +3 -2
  46. package/providers/authenticationProvider.js +106 -60
  47. package/providers/cliConfigProvider.js +159 -61
  48. package/providers/types.js +9 -0
  49. package/util/analytics.js +8 -8
  50. package/util/httpUtil.js +6 -9
  51. package/utilities.js +7 -0
@@ -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 = exports.AuthType = void 0;
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;
@@ -47,30 +48,27 @@ const RETRYABLE_NODEJS_ERRORS = [
47
48
  'ENOTFOUND',
48
49
  'ENETUNREACH',
49
50
  'ETIMEOUT',
51
+ 'ETIMEDOUT',
50
52
  'ECONNABORTED',
51
53
  ];
52
- var AuthType;
53
- (function (AuthType) {
54
- AuthType[AuthType["Bearer"] = 0] = "Bearer";
55
- AuthType[AuthType["ApiKey"] = 1] = "ApiKey";
56
- })(AuthType = exports.AuthType || (exports.AuthType = {}));
54
+ const DEFAULT_SSL_VERIFY = false;
57
55
  class BasicApiClient {
58
56
  constructor(options) {
59
- var _a, _b, _c, _d;
57
+ var _a, _b, _c, _d, _e;
60
58
  const config = (0, httpUtil_1.axiosProxyConfig)({
61
- sslVerify: options.sslVerify,
59
+ sslVerify: (_a = options.sslVerify) !== null && _a !== void 0 ? _a : DEFAULT_SSL_VERIFY,
62
60
  proxyHost: options.proxyUrl,
63
61
  });
64
62
  config.timeout =
65
- (_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;
63
+ (_d = (_b = options.requestTimeoutMillis) !== null && _b !== void 0 ? _b : (_c = options.retryConfig) === null || _c === void 0 ? void 0 : _c.requestTimeoutMillis) !== null && _d !== void 0 ? _d : DEFAULT_RETRYABLE_REQUEST_TIMEOUT_MILLISECONDS;
66
64
  switch (options.authType) {
67
- case AuthType.ApiKey:
65
+ case types_1.AuthType.ApiKey:
68
66
  config.auth = {
69
67
  username: 'key',
70
68
  password: options.token,
71
69
  };
72
70
  break;
73
- case AuthType.Bearer:
71
+ case types_1.AuthType.Bearer:
74
72
  config.headers.authorization = `Bearer ${options.token}`;
75
73
  break;
76
74
  default:
@@ -90,7 +88,7 @@ class BasicApiClient {
90
88
  this.httpRequestConfig = config;
91
89
  this.httpClient = axios_1.default.create(config);
92
90
  this.retryConfig = options.retryConfig;
93
- this.debugLogger = (_d = options.debugLogger) !== null && _d !== void 0 ? _d : logUtils_1.logInternal;
91
+ this.debugLogger = (_e = options.debugLogger) !== null && _e !== void 0 ? _e : logUtils_1.logInternal;
94
92
  }
95
93
  getNonRetryableRequestConfig(override) {
96
94
  const overrideWithTimeout = { ...(override !== null && override !== void 0 ? override : {}) };
@@ -130,7 +128,13 @@ class BasicApiClient {
130
128
  return { ...result, entity_version: versionHeader };
131
129
  }
132
130
  async makePostRequest(path, requestBody, requestConfig) {
133
- const response = await this.debugRequest('POST', path, () => this.httpClient.post(path, requestBody, this.getNonRetryableRequestConfig(requestConfig)));
131
+ return this.postRequest(path, requestBody, this.getNonRetryableRequestConfig(requestConfig));
132
+ }
133
+ async makePostRequestWithRetries(path, requestBody, config) {
134
+ return this.retryWrappedRequest(`makePostRequestWithRetries('${path}')`, () => this.postRequest(path, requestBody, this.getRetryableRequestConfig(config)), config);
135
+ }
136
+ async postRequest(path, requestBody, config) {
137
+ const response = await this.debugRequest('POST', path, () => this.httpClient.post(path, requestBody, config));
134
138
  BasicApiClient.checkResponseStatusCode(response);
135
139
  return response.data;
136
140
  }
@@ -31,6 +31,10 @@ const cliConfigProvider_1 = require("../providers/cliConfigProvider");
31
31
  const basicApiClient_1 = require("./basicApiClient");
32
32
  const queryString = __importStar(require("query-string"));
33
33
  const featureSet_1 = require("./featureSet");
34
+ const DEPLOYMENT_EVENT_RETRY_CONFIG = {
35
+ requestTimeoutMillis: 0,
36
+ maxRetryTimeMillis: 1000 * 60 * 60,
37
+ };
34
38
  class MablApiClient extends basicApiClient_1.BasicApiClient {
35
39
  constructor(options) {
36
40
  super(options);
@@ -129,7 +133,7 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
129
133
  }
130
134
  async createDeployment(deployment) {
131
135
  try {
132
- return await this.makePostRequest(`${env_1.BASE_API_URL}/deployments`, deployment, { timeout: 0 });
136
+ return await this.makePostRequest(`${env_1.BASE_API_URL}/deployments`, deployment);
133
137
  }
134
138
  catch (error) {
135
139
  throw toApiError(`Failed to create deployment`, error);
@@ -231,7 +235,7 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
231
235
  }
232
236
  async getDeploymentResults(deploymentEventId) {
233
237
  try {
234
- return await this.makeGetRequest(`${env_1.BASE_API_URL}/execution/result/event/${deploymentEventId}`, { requestTimeoutMillis: 600000, maxRetryTimeMillis: 900000 });
238
+ return await this.makeGetRequest(`${env_1.BASE_API_URL}/execution/result/event/${deploymentEventId}`, DEPLOYMENT_EVENT_RETRY_CONFIG);
235
239
  }
236
240
  catch (error) {
237
241
  throw toApiError(`Failed to get deployment results`, error);
@@ -319,13 +323,13 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
319
323
  try {
320
324
  const selfInfo = await this.makeGetRequest(`${env_1.BASE_API_URL}/self`);
321
325
  if (((_a = selfInfo.preferences) === null || _a === void 0 ? void 0 : _a.default_workspace_id) &&
322
- !cliConfigProvider_1.CliConfigProvider.getWorkspace()) {
326
+ !(await cliConfigProvider_1.CliConfigProvider.getWorkspace())) {
323
327
  const workspace = await this.getWorkspace(selfInfo.preferences.default_workspace_id);
324
- cliConfigProvider_1.CliConfigProvider.setWorkspace(workspace);
328
+ await cliConfigProvider_1.CliConfigProvider.setWorkspace(workspace);
325
329
  }
326
330
  else if (((_b = selfInfo.roles) === null || _b === void 0 ? void 0 : _b.length) === 1) {
327
331
  const workspace = await this.getWorkspace(selfInfo.roles[0].organization_id);
328
- cliConfigProvider_1.CliConfigProvider.setWorkspace(workspace);
332
+ await cliConfigProvider_1.CliConfigProvider.setWorkspace(workspace);
329
333
  }
330
334
  return selfInfo;
331
335
  }
@@ -454,7 +458,7 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
454
458
  context_id: contextId,
455
459
  workspace_id: workspaceId,
456
460
  };
457
- return await this.makePostRequest(`${env_1.BASE_API_URL}/mailbox/address`, body);
461
+ return await this.makePostRequestWithRetries(`${env_1.BASE_API_URL}/mailbox/address`, body);
458
462
  }
459
463
  catch (error) {
460
464
  throw toApiError('Failed to create mailbox email address', error);
@@ -501,7 +505,7 @@ class MablApiClient extends basicApiClient_1.BasicApiClient {
501
505
  async postDeploymentEvent(options) {
502
506
  try {
503
507
  const requestBody = this.buildDeploymentRequestBody(options);
504
- return await this.makePostRequest(`${env_1.BASE_API_URL}/events/deployment/`, requestBody);
508
+ return await this.makePostRequestWithRetries(`${env_1.BASE_API_URL}/events/deployment/`, requestBody, DEPLOYMENT_EVENT_RETRY_CONFIG);
505
509
  }
506
510
  catch (error) {
507
511
  throw toApiError(`Failed to create deployment`, error);
@@ -7,63 +7,64 @@ 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 basicApiClient_1 = require("./basicApiClient");
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: basicApiClient_1.AuthType.ApiKey,
17
- authToken: apiKey,
16
+ authType: types_1.AuthType.ApiKey,
17
+ token: apiKey,
18
18
  });
19
19
  }
20
20
  return MablApiClientFactory.createApiClient();
21
21
  }
22
22
  static createApiClientFromApiKey(apiKey) {
23
23
  return MablApiClientFactory.createApiClient({
24
- authType: basicApiClient_1.AuthType.ApiKey,
25
- authToken: apiKey,
24
+ authType: types_1.AuthType.ApiKey,
25
+ token: apiKey,
26
26
  });
27
27
  }
28
28
  static createApiClientFromBearerToken(bearerToken) {
29
29
  return MablApiClientFactory.createApiClient({
30
- authType: basicApiClient_1.AuthType.Bearer,
31
- authToken: bearerToken,
30
+ authType: types_1.AuthType.Bearer,
31
+ token: bearerToken,
32
32
  });
33
33
  }
34
34
  static async createApiClient(opts) {
35
- const httpConfig = cliConfigProvider_1.CliConfigProvider.getCliConfig().http;
35
+ const { proxyHost, sslVerify } = (await cliConfigProvider_1.CliConfigProvider.getCliConfig())
36
+ .http;
37
+ const optsFromCliHttpConfig = {
38
+ proxyUrl: proxyHost,
39
+ sslVerify,
40
+ };
36
41
  if (opts) {
37
42
  return new mablApiClient_1.MablApiClient({
38
- authType: opts.authType,
39
- token: opts.authToken,
40
- proxyUrl: httpConfig.proxyHost,
41
- sslVerify: httpConfig.sslVerify,
42
- userAgentOverride: opts.userAgentOverride,
43
+ ...optsFromCliHttpConfig,
44
+ ...opts,
43
45
  });
44
46
  }
45
47
  const authProvider = new authenticationProvider_1.AuthenticationProvider();
46
48
  const authConfig = await authProvider.getAuthConfigWithAutoRenew();
47
49
  if (authConfig === null || authConfig === void 0 ? void 0 : authConfig.accessToken) {
48
50
  return new mablApiClient_1.MablApiClient({
51
+ ...optsFromCliHttpConfig,
49
52
  authType: authConfig.authType,
50
53
  token: authConfig.accessToken,
51
- proxyUrl: httpConfig.proxyHost,
52
- sslVerify: httpConfig.sslVerify,
53
54
  });
54
55
  }
55
56
  throw new Error('Please supply an API key or authenticate the mabl CLI tool');
56
57
  }
57
58
  static async createUserApiClient() {
58
- if (authenticationProvider_1.AuthenticationProvider.getAuthType() !== basicApiClient_1.AuthType.Bearer) {
59
+ if ((await authenticationProvider_1.AuthenticationProvider.getAuthType()) !== types_1.AuthType.Bearer) {
59
60
  MablApiClientFactory.throwUserAuthTypeError();
60
61
  }
61
62
  return MablApiClientFactory.createApiClient();
62
63
  }
63
- static createApiClientForAccessToken(accessToken) {
64
- const httpConfig = cliConfigProvider_1.CliConfigProvider.getCliConfig().http;
64
+ static async createApiClientForAccessToken(accessToken) {
65
+ const httpConfig = (await cliConfigProvider_1.CliConfigProvider.getCliConfig()).http;
65
66
  return new mablApiClient_1.MablApiClient({
66
- authType: basicApiClient_1.AuthType.Bearer,
67
+ authType: types_1.AuthType.Bearer,
67
68
  token: accessToken,
68
69
  proxyUrl: httpConfig.proxyHost,
69
70
  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 = {}));
@@ -28,6 +28,7 @@ class AuthClient {
28
28
  const loginQueryString = query_string_1.default.stringify({
29
29
  codeChallenge,
30
30
  redirectUri,
31
+ includeRefreshToken: true,
31
32
  });
32
33
  return idpType
33
34
  ? `${env_1.BASE_APP_URL}/authorize/social/${idpType.toLowerCase()}?${loginQueryString}`
@@ -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 basicApiClient_1 = require("../api/basicApiClient");
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
- const url = `${env_1.OKTA_URL}/oauth2/default/v1/token`;
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 exchangeRefreshTokenForAccessToken(refreshToken) {
34
- const url = `${env_1.OKTA_URL}/oauth2/default/v1/token`;
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
- refresh_token: refreshToken,
43
- scope: 'openid profile email offline_access',
40
+ token_type_hint: 'refresh_token',
41
+ token: refreshToken,
44
42
  });
45
- const response = await this.httpClient.post(url, data, requestOptions);
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
- authInfo.auth_provider = authenticationProvider_1.AuthProviderType.Okta;
48
- authInfo.auth_type = basicApiClient_1.AuthType.Bearer;
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;
@@ -54,6 +54,11 @@ class PlaywrightBrowser extends events_1.default {
54
54
  fs_extra_1.default.mkdirSync(path_1.default.join(this.downloadDirectory));
55
55
  }
56
56
  }
57
+ static async create(defaultContext, downloadDirectory, browserWSEndpoint) {
58
+ const browser = new PlaywrightBrowser(defaultContext, downloadDirectory, browserWSEndpoint);
59
+ await browser.setDownloadBehavior();
60
+ return browser;
61
+ }
57
62
  getRunnerType() {
58
63
  return runnerType_1.RunnerType.Playwright;
59
64
  }
@@ -114,6 +119,13 @@ class PlaywrightBrowser extends events_1.default {
114
119
  getDefaultContext() {
115
120
  return this.defaultContext;
116
121
  }
122
+ async setDownloadBehavior() {
123
+ await this.cdpSession.send('Browser.setDownloadBehavior', {
124
+ behavior: 'allow',
125
+ downloadPath: this.downloadDirectory,
126
+ eventsEnabled: true,
127
+ });
128
+ }
117
129
  onPageClose(page) {
118
130
  this.playwrightPages.delete(page.getPageId());
119
131
  this.emit(browserLauncher_1.BrowserEvent.PageDestroyed, page);
@@ -1,17 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.PlaywrightBrowserLauncher = void 0;
7
4
  const test_1 = require("@playwright/test");
8
- const path_1 = __importDefault(require("path"));
9
5
  const playwrightBrowser_1 = require("./playwrightBrowser");
10
6
  const BROWSER_LAUNCH_TIMEOUT_MS = 60000;
11
7
  class PlaywrightBrowserLauncher {
12
8
  async connect(options, currentDownloadPath) {
13
9
  const browser = await test_1.chromium.connect(options.browserWSEndpoint);
14
- return new playwrightBrowser_1.PlaywrightBrowser(browser.contexts()[0], currentDownloadPath, options.browserWSEndpoint);
10
+ return playwrightBrowser_1.PlaywrightBrowser.create(browser.contexts()[0], currentDownloadPath, options.browserWSEndpoint);
15
11
  }
16
12
  async launch(options) {
17
13
  var _a, _b, _c;
@@ -40,7 +36,7 @@ class PlaywrightBrowserLauncher {
40
36
  userAgent: options.userAgent,
41
37
  viewport,
42
38
  });
43
- return new playwrightBrowser_1.PlaywrightBrowser(defaultContext, path_1.default.join(options.downloadPath, 'final'), '');
39
+ return playwrightBrowser_1.PlaywrightBrowser.create(defaultContext, options.downloadPath, '');
44
40
  }
45
41
  }
46
42
  exports.PlaywrightBrowserLauncher = PlaywrightBrowserLauncher;
@@ -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, _d;
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: (_d = options === null || options === void 0 ? void 0 : options.timeout) !== null && _d !== void 0 ? _d : types_1.DefaultTimeouts.quickActionTimeoutMs,
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, _c;
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: (_c = options === null || options === void 0 ? void 0 : options.timeout) !== null && _c !== void 0 ? _c : types_1.DefaultTimeouts.quickActionTimeoutMs,
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.quickActionTimeoutMs,
132
+ timeout: types_1.DefaultTimeouts.defaultWaitTimeoutMs,
133
133
  });
134
134
  }
135
135
  return (0, utils_1.mapIfNotNull)(response, (response) => new playwrightHttpResponse_1.PlaywrightHttpResponse(this.parentPage, response));
@@ -36,7 +36,6 @@ const playwrightFrame_1 = require("./playwrightFrame");
36
36
  const playwrightDom_1 = require("./playwrightDom");
37
37
  const utils_1 = require("../utils");
38
38
  const wrappers_1 = require("./wrappers");
39
- const path_1 = __importDefault(require("path"));
40
39
  const logUtils_1 = require("../../util/logUtils");
41
40
  const uuid = __importStar(require("uuid"));
42
41
  class PlaywrightPage extends events_1.default {
@@ -57,7 +56,6 @@ class PlaywrightPage extends events_1.default {
57
56
  var _a, _b;
58
57
  const guid = uuid.v4();
59
58
  const downloadSize = (_b = (_a = (await download.createReadStream())) === null || _a === void 0 ? void 0 : _a.readableLength) !== null && _b !== void 0 ? _b : 0;
60
- await download.saveAs(path_1.default.join(this.browser.getDownloadDirectory(), download.suggestedFilename()));
61
59
  browser.emit(browserLauncher_1.BrowserEvent.DownloadWillBegin, {
62
60
  guid,
63
61
  suggestedFilename: download.suggestedFilename(),
@@ -4,8 +4,9 @@ exports.WaitForOptions = exports.LifecycleEvent = exports.DefaultTimeouts = void
4
4
  class DefaultTimeouts {
5
5
  }
6
6
  exports.DefaultTimeouts = DefaultTimeouts;
7
- DefaultTimeouts.quickActionTimeoutMs = 5000;
8
- DefaultTimeouts.defaultTextInputTimeoutMs = 30000;
7
+ DefaultTimeouts.defaultTrialTimeoutMs = 5000;
8
+ DefaultTimeouts.defaultWaitTimeoutMs = 5000;
9
+ DefaultTimeouts.defaultActionTimeoutMs = 0;
9
10
  var LifecycleEvent;
10
11
  (function (LifecycleEvent) {
11
12
  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
  }
@@ -6,5 +6,5 @@ exports.describe = 'Clear logged in user';
6
6
  exports.builder = {};
7
7
  exports.handler = exports.handler = () => {
8
8
  const auth = new authenticationProvider_1.AuthenticationProvider();
9
- auth.clearAuthentication();
9
+ return auth.clearAuthentication();
10
10
  };
@@ -6,5 +6,5 @@ exports.describe = 'Display logged in user';
6
6
  exports.builder = {};
7
7
  exports.handler = () => {
8
8
  const auth = new authenticationProvider_1.AuthenticationProvider();
9
- auth.displayInfo();
9
+ return auth.displayInfo();
10
10
  };
@@ -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['workspace-id'];
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);