@automattic/vip 2.30.0-dev1 → 2.31.0-dev1

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 (63) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/assets/dev-env.lando.template.yml.ejs +7 -2
  3. package/dist/bin/vip-dev-env-create.js +4 -1
  4. package/dist/bin/vip-dev-env-sync-sql.js +11 -18
  5. package/dist/bin/vip-export-sql.js +12 -11
  6. package/dist/bin/vip-import-sql.js +2 -2
  7. package/dist/bin/vip-import-validate-sql.js +2 -2
  8. package/dist/bin/vip-whoami.js +7 -10
  9. package/dist/bin/vip-wp.js +7 -5
  10. package/dist/bin/vip.js +9 -6
  11. package/dist/commands/dev-env-sync-sql.js +29 -15
  12. package/dist/commands/export-sql.js +1 -1
  13. package/dist/lib/analytics/clients/pendo.js +11 -20
  14. package/dist/lib/analytics/clients/tracks.js +12 -12
  15. package/dist/lib/analytics/index.js +9 -12
  16. package/dist/lib/api/app.js +10 -13
  17. package/dist/lib/api/cache-purge.js +3 -10
  18. package/dist/lib/api/feature-flags.js +6 -3
  19. package/dist/lib/api/http.js +10 -18
  20. package/dist/lib/api/user.js +3 -8
  21. package/dist/lib/api.js +13 -16
  22. package/dist/lib/app-logs/app-logs.js +3 -6
  23. package/dist/lib/app.js +2 -0
  24. package/dist/lib/cli/apiConfig.js +10 -7
  25. package/dist/lib/cli/config.js +2 -3
  26. package/dist/lib/cli/envAlias.js +11 -9
  27. package/dist/lib/cli/exit.js +4 -7
  28. package/dist/lib/cli/format.js +25 -26
  29. package/dist/lib/cli/progress.js +7 -3
  30. package/dist/lib/cli/prompt.js +3 -2
  31. package/dist/lib/client-file-uploader.js +86 -87
  32. package/dist/lib/config/software.js +18 -12
  33. package/dist/lib/dev-environment/dev-environment-cli.js +47 -3
  34. package/dist/lib/dev-environment/dev-environment-lando.js +2 -2
  35. package/dist/lib/env.js +16 -13
  36. package/dist/lib/envvar/api-delete.js +2 -0
  37. package/dist/lib/envvar/api-get-all.js +4 -1
  38. package/dist/lib/envvar/api-get.js +3 -1
  39. package/dist/lib/envvar/api-list.js +8 -3
  40. package/dist/lib/envvar/api-set.js +2 -0
  41. package/dist/lib/envvar/api.js +2 -5
  42. package/dist/lib/envvar/input.js +7 -8
  43. package/dist/lib/envvar/read-file.js +4 -7
  44. package/dist/lib/http/proxy-agent.js +5 -4
  45. package/dist/lib/keychain/insecure.js +25 -26
  46. package/dist/lib/keychain/secure.js +5 -2
  47. package/dist/lib/keychain.js +11 -18
  48. package/dist/lib/media-import/status.js +2 -2
  49. package/dist/lib/read-file.js +13 -14
  50. package/dist/lib/search-and-replace.js +17 -26
  51. package/dist/lib/site-import/status.js +4 -3
  52. package/dist/lib/token.js +17 -6
  53. package/dist/lib/tracker.js +13 -14
  54. package/dist/lib/user-error.js +6 -5
  55. package/dist/lib/utils.js +18 -22
  56. package/dist/lib/validations/sql.js +3 -3
  57. package/dist/lib/vip-import-validate-files.js +23 -22
  58. package/npm-shrinkwrap.json +1041 -1230
  59. package/package.json +30 -8
  60. package/tsconfig.json +37 -0
  61. package/dist/lib/analytics/clients/stub.js +0 -16
  62. package/dist/lib/cli/repo.js +0 -61
  63. package/dist/lib/keychain/browser.js +0 -31
@@ -10,9 +10,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
10
10
  /**
11
11
  * External dependencies
12
12
  */
13
+
13
14
  /**
14
15
  * Internal dependencies
15
16
  */
17
+
16
18
  const query = (0, _graphqlTag.default)`
17
19
  query GetEnvironmentVariablesWithValues(
18
20
  $appId: Int!
@@ -38,6 +40,7 @@ const query = (0, _graphqlTag.default)`
38
40
  }
39
41
  `;
40
42
  async function getEnvVars(appId, envId) {
43
+ var _ref, _data$app, _data$app$environment, _data$app$environment2, _data$app$environment3;
41
44
  const api = await (0, _api.default)();
42
45
  const variables = {
43
46
  appId,
@@ -49,5 +52,5 @@ async function getEnvVars(appId, envId) {
49
52
  query,
50
53
  variables
51
54
  });
52
- return data.app.environments[0].environmentVariables.nodes;
55
+ return (_ref = (_data$app = data.app) === null || _data$app === void 0 ? void 0 : (_data$app$environment = _data$app.environments) === null || _data$app$environment === void 0 ? void 0 : (_data$app$environment2 = _data$app$environment[0]) === null || _data$app$environment2 === void 0 ? void 0 : (_data$app$environment3 = _data$app$environment2.environmentVariables) === null || _data$app$environment3 === void 0 ? void 0 : _data$app$environment3.nodes) !== null && _ref !== void 0 ? _ref : null;
53
56
  }
@@ -9,12 +9,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
9
9
  /**
10
10
  * External dependencies
11
11
  */
12
+
12
13
  /**
13
14
  * Internal dependencies
14
15
  */
16
+
15
17
  async function getEnvVar(appId, envId, name) {
16
18
  const envvars = await (0, _apiGetAll.default)(appId, envId);
17
- return envvars.find(({
19
+ return envvars === null || envvars === void 0 ? void 0 : envvars.find(({
18
20
  name: foundName
19
21
  }) => name === foundName);
20
22
  }
@@ -10,9 +10,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
10
10
  /**
11
11
  * External dependencies
12
12
  */
13
+
13
14
  /**
14
15
  * Internal dependencies
15
16
  */
17
+
16
18
  const query = (0, _graphqlTag.default)`
17
19
  query GetEnvironmentVariables(
18
20
  $appId: Int!
@@ -39,6 +41,7 @@ const query = (0, _graphqlTag.default)`
39
41
 
40
42
  // List the names (but not values) of environment variables.
41
43
  async function listEnvVars(appId, envId) {
44
+ var _data$app$environment, _data$app, _data$app$environment2, _data$app$environment3, _data$app$environment4;
42
45
  const api = await (0, _api.default)();
43
46
  const variables = {
44
47
  appId,
@@ -50,7 +53,9 @@ async function listEnvVars(appId, envId) {
50
53
  query,
51
54
  variables
52
55
  });
53
- return data.app.environments[0].environmentVariables.nodes.map(({
54
- name
55
- }) => name);
56
+ const nodes = (_data$app$environment = (_data$app = data.app) === null || _data$app === void 0 ? void 0 : (_data$app$environment2 = _data$app.environments) === null || _data$app$environment2 === void 0 ? void 0 : (_data$app$environment3 = _data$app$environment2[0]) === null || _data$app$environment3 === void 0 ? void 0 : (_data$app$environment4 = _data$app$environment3.environmentVariables) === null || _data$app$environment4 === void 0 ? void 0 : _data$app$environment4.nodes) !== null && _data$app$environment !== void 0 ? _data$app$environment : [];
57
+ return nodes.map(entry => {
58
+ var _entry$name;
59
+ return (_entry$name = entry === null || entry === void 0 ? void 0 : entry.name) !== null && _entry$name !== void 0 ? _entry$name : '';
60
+ });
56
61
  }
@@ -10,9 +10,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
10
10
  /**
11
11
  * External dependencies
12
12
  */
13
+
13
14
  /**
14
15
  * Internal dependencies
15
16
  */
17
+
16
18
  const mutation = (0, _graphqlTag.default)`
17
19
  mutation AddEnvironmentVariable(
18
20
  $appId: Int!
@@ -44,10 +44,7 @@ var _apiGetAll = _interopRequireDefault(require("./api-get-all"));
44
44
  var _apiList = _interopRequireDefault(require("./api-list"));
45
45
  var _apiSet = _interopRequireDefault(require("./api-set"));
46
46
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
47
- /**
48
- *
49
- * @format
50
- */
47
+ // @format
51
48
 
52
49
  /**
53
50
  * External dependencies
@@ -83,7 +80,7 @@ function validateName(name) {
83
80
  return name === sanitizedName && /^[A-Z]/.test(sanitizedName);
84
81
  }
85
82
  function validateNameWithMessage(name) {
86
- (0, _logging.debug)(`Validating environment variable name ${JSON.stringify(name)}`);
83
+ (0, _logging.debug)(`Validating environment variable name "${name}"`);
87
84
  if (!validateName(name)) {
88
85
  const message = ['Environment variable name must consist of A-Z, 0-9, or _,', 'and must start with an uppercase letter.'].join('\n');
89
86
  console.log(_chalk.default.bold.red(message));
@@ -9,10 +9,7 @@ exports.promptForValue = promptForValue;
9
9
  var _chalk = _interopRequireDefault(require("chalk"));
10
10
  var _enquirer = require("enquirer");
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- /**
13
- *
14
- * @format
15
- */
12
+ // @format
16
13
 
17
14
  /**
18
15
  * External dependencies
@@ -27,13 +24,15 @@ function cancel() {
27
24
  process.exit();
28
25
  }
29
26
  function confirm(message) {
30
- return new _enquirer.BooleanPrompt({
27
+ return new _enquirer.Confirm({
31
28
  message
32
29
  }).run().catch(() => false);
33
30
  }
34
31
  async function promptForValue(message, mustMatch) {
35
- var _response$str;
36
- const response = await (0, _enquirer.prompt)({
32
+ var _str$trim;
33
+ const {
34
+ str
35
+ } = await (0, _enquirer.prompt)({
37
36
  message,
38
37
  name: 'str',
39
38
  type: 'input',
@@ -44,5 +43,5 @@ async function promptForValue(message, mustMatch) {
44
43
  return true;
45
44
  }
46
45
  });
47
- return ((_response$str = response.str) === null || _response$str === void 0 ? void 0 : _response$str.trim()) || '';
46
+ return (_str$trim = str === null || str === void 0 ? void 0 : str.trim()) !== null && _str$trim !== void 0 ? _str$trim : '';
48
47
  }
@@ -6,10 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.readVariableFromFile = readVariableFromFile;
7
7
  var _logging = require("../../lib/envvar/logging");
8
8
  var _readFile = require("../read-file");
9
- /**
10
- *
11
- * @format
12
- */
9
+ // @format
13
10
 
14
11
  /**
15
12
  * External dependencies
@@ -19,7 +16,7 @@ var _readFile = require("../read-file");
19
16
  * Internal dependencies
20
17
  */
21
18
 
22
- async function readVariableFromFile(path) {
23
- (0, _logging.debug)(`Loading variable value from file ${JSON.stringify(path)}`);
24
- return await (0, _readFile.readFromFile)(path);
19
+ function readVariableFromFile(path) {
20
+ (0, _logging.debug)(`Loading variable value from file "${path}"`);
21
+ return (0, _readFile.readFromFile)(path);
25
22
  }
@@ -9,6 +9,7 @@ var _httpsProxyAgent = require("https-proxy-agent");
9
9
  var _proxyFromEnv = require("proxy-from-env");
10
10
  var _debug = _interopRequireDefault(require("debug"));
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
12
13
  /**
13
14
  * External dependencies
14
15
  */
@@ -31,10 +32,10 @@ const debug = (0, _debug.default)('vip:proxy-agent');
31
32
  // 5. NO_PROXY is set along with VIP_USE_SYSTEM_PROXY and any system proxy: null is returned if the no proxy applies, otherwise the first active proxy is used
32
33
  // This allows near full customization by the client of what proxy should be used, instead of making assumptions based on the URL string
33
34
  function createProxyAgent(url) {
34
- const VIP_PROXY = process.env.VIP_PROXY || process.env.vip_proxy || null;
35
- const SOCKS_PROXY = process.env.SOCKS_PROXY || process.env.socks_proxy || null;
36
- const HTTPS_PROXY = process.env.HTTPS_PROXY || process.env.https_proxy || null;
37
- const NO_PROXY = process.env.NO_PROXY || process.env.no_proxy || null;
35
+ const VIP_PROXY = process.env.VIP_PROXY || process.env.vip_proxy || null; // NOSONAR
36
+ const SOCKS_PROXY = process.env.SOCKS_PROXY || process.env.socks_proxy || null; // NOSONAR
37
+ const HTTPS_PROXY = process.env.HTTPS_PROXY || process.env.https_proxy || null; // NOSONAR
38
+ const NO_PROXY = process.env.NO_PROXY || process.env.no_proxy || null; // NOSONAR
38
39
 
39
40
  // VIP Socks Proxy should take precedence and should be fully backward compatible
40
41
  if (VIP_PROXY) {
@@ -4,10 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _configstore = _interopRequireDefault(require("configstore"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
9
  /**
8
10
  * External dependencies
9
11
  */
10
- const Configstore = require('configstore');
11
12
 
12
13
  /**
13
14
  * Internal dependencies
@@ -16,38 +17,36 @@ const Configstore = require('configstore');
16
17
  class Insecure {
17
18
  constructor(file) {
18
19
  this.file = file;
19
- this.configstore = new Configstore(this.file);
20
+ this.configstore = new _configstore.default(this.file);
20
21
  }
21
22
  getPassword(service) {
22
- return new Promise((resolve, reject) => {
23
- let password = null;
24
- try {
25
- password = this.configstore.get(service);
26
- } catch (err) {
27
- return reject(err);
23
+ try {
24
+ const value = this.configstore.get(service);
25
+ if (null === value || undefined === value) {
26
+ return Promise.resolve(null);
28
27
  }
29
- return resolve(password);
30
- });
28
+
29
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
30
+ return Promise.resolve(value.toString()); // NOSONAR
31
+ } catch (err) {
32
+ return Promise.reject(err);
33
+ }
31
34
  }
32
35
  setPassword(service, password) {
33
- return new Promise((resolve, reject) => {
34
- try {
35
- this.configstore.set(service, password);
36
- } catch (err) {
37
- return reject(err);
38
- }
39
- resolve(true);
40
- });
36
+ try {
37
+ this.configstore.set(service, password);
38
+ return Promise.resolve(true);
39
+ } catch (err) {
40
+ return Promise.reject(err);
41
+ }
41
42
  }
42
43
  deletePassword(service) {
43
- return new Promise((resolve, reject) => {
44
- try {
45
- this.configstore.delete(service);
46
- } catch (err) {
47
- return reject(err);
48
- }
49
- resolve(true);
50
- });
44
+ try {
45
+ this.configstore.delete(service);
46
+ return Promise.resolve(true);
47
+ } catch (err) {
48
+ return Promise.reject(err);
49
+ }
51
50
  }
52
51
  }
53
52
  exports.default = Insecure;
@@ -9,15 +9,18 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
9
9
  /**
10
10
  * External dependencies
11
11
  */
12
+
12
13
  /**
13
14
  * Internal dependencies
14
15
  */
16
+
15
17
  class Secure {
16
18
  getPassword(service) {
17
19
  return _keytar.default.getPassword(service, service);
18
20
  }
19
- setPassword(service, password) {
20
- return _keytar.default.setPassword(service, service, password);
21
+ async setPassword(service, password) {
22
+ await _keytar.default.setPassword(service, service, password);
23
+ return true;
21
24
  }
22
25
  deletePassword(service) {
23
26
  return _keytar.default.deletePassword(service, service);
@@ -4,35 +4,28 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _debug = _interopRequireDefault(require("debug"));
7
8
  var _insecure = _interopRequireDefault(require("./keychain/insecure"));
8
- var _browser = _interopRequireDefault(require("./keychain/browser"));
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- /* global window */
11
10
  /**
12
11
  * External dependencies
13
12
  */
14
- const debug = require('debug')('@automattic/vip:keychain');
15
13
 
16
14
  /**
17
15
  * Internal dependencies
18
16
  */
19
17
 
20
- let exportValue = {};
21
- if (typeof window === 'undefined' || typeof window.localStorage === 'undefined') {
22
- // node
18
+ let exportValue;
19
+ const debug = (0, _debug.default)('@automattic/vip:keychain');
20
+ try {
21
+ // Try using Secure keychain ("keytar") first
22
+ const Secure = require("./keychain/secure");
23
+ exportValue = new Secure();
24
+ } catch (error) {
25
+ debug('Cannot use Secure keychain; falling back to Insecure keychain (Details: %o)', error);
23
26
 
24
- try {
25
- // Try using Secure keychain ("keytar") first
26
- const Secure = require("./keychain/secure");
27
- exportValue = new Secure();
28
- } catch (error) {
29
- debug('Cannot use Secure keychain; falling back to Insecure keychain (Details: %o)', error);
30
-
31
- // Fallback to Insecure keychain if we can't
32
- exportValue = new _insecure.default('vip-go-cli');
33
- }
34
- } else {
35
- exportValue = new _browser.default();
27
+ // Fallback to Insecure keychain if we can't
28
+ exportValue = new _insecure.default('vip-go-cli');
36
29
  }
37
30
  var _default = exportValue;
38
31
  exports.default = _default;
@@ -234,12 +234,12 @@ ${maybeExitPrompt}
234
234
  startDate = Date.now();
235
235
  }
236
236
  setTimeout(() => {
237
- checkStatus(pollInterval);
237
+ void checkStatus(pollInterval);
238
238
  }, pollInterval);
239
239
  };
240
240
 
241
241
  // Kick off the check
242
- checkStatus(IMPORT_MEDIA_PROGRESS_POLL_INTERVAL);
242
+ void checkStatus(IMPORT_MEDIA_PROGRESS_POLL_INTERVAL);
243
243
  });
244
244
  try {
245
245
  var _results$failureDetai;
@@ -4,14 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.readFromFile = readFromFile;
7
- var _fs = require("fs");
7
+ var _promises = require("node:fs/promises");
8
8
  var exit = _interopRequireWildcard(require("../lib/cli/exit"));
9
9
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
10
10
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
11
- /**
12
- *
13
- * @format
14
- */
11
+ // @format
15
12
 
16
13
  /**
17
14
  * External dependencies
@@ -22,14 +19,16 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
22
19
  */
23
20
 
24
21
  async function readFromFile(path) {
25
- const data = await _fs.promises.readFile(path, 'binary').catch(({
26
- message
27
- }) => {
28
- // Provide friendly version of common error.
29
- if (message.startsWith('ENOENT: no such file or directory')) {
30
- exit.withError(`Could not load file ${JSON.stringify(path)}.`);
22
+ try {
23
+ const data = await (0, _promises.readFile)(path, 'utf-8');
24
+ return data.trim();
25
+ } catch (error) {
26
+ if (!(error instanceof Error)) {
27
+ exit.withError('Unknown error');
28
+ }
29
+ if ('code' in error && error.code === 'ENOENT') {
30
+ exit.withError(`Could not load file "${path}".`);
31
31
  }
32
- exit.withError(message);
33
- });
34
- return Buffer.from(data).toString().trim();
32
+ exit.withError(error.message);
33
+ }
35
34
  }
@@ -7,8 +7,9 @@ exports.getReadAndWriteStreams = getReadAndWriteStreams;
7
7
  exports.searchAndReplace = void 0;
8
8
  var _fs = _interopRequireDefault(require("fs"));
9
9
  var _path = _interopRequireDefault(require("path"));
10
- var _chalk = _interopRequireDefault(require("chalk"));
10
+ var _chalk = require("chalk");
11
11
  var _debug = _interopRequireDefault(require("debug"));
12
+ var _promises = require("node:stream/promises");
12
13
  var _vipSearchReplace = require("@automattic/vip-search-replace");
13
14
  var _tracker = require("../lib/tracker");
14
15
  var _prompt = require("../lib/cli/prompt");
@@ -18,10 +19,7 @@ var _utils = require("./utils");
18
19
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
20
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
- /**
22
- *
23
- * @format
24
- */
22
+ // @format
25
23
 
26
24
  /**
27
25
  * External dependencies
@@ -32,11 +30,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
32
30
  */
33
31
 
34
32
  const debug = (0, _debug.default)('@automattic/vip:lib:search-and-replace');
35
- const flatten = arr => {
36
- return arr.reduce((flat, toFlatten) => {
37
- return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
38
- }, []);
39
- };
40
33
  function getReadAndWriteStreams({
41
34
  fileName,
42
35
  inPlace,
@@ -103,7 +96,7 @@ const searchAndReplace = async (fileName, pairs, {
103
96
  const fileSize = (0, _clientFileUploader.getFileSize)(fileName);
104
97
 
105
98
  // if we don't have any pairs to replace with, return the input file
106
- if (!pairs || !pairs.length) {
99
+ if (!pairs.length) {
107
100
  throw new Error('No search and replace parameters provided.');
108
101
  }
109
102
 
@@ -113,8 +106,7 @@ const searchAndReplace = async (fileName, pairs, {
113
106
  }
114
107
 
115
108
  // determine all the replacements required
116
- const replacementsArr = pairs.map(pair => pair.split(',').map(str => str.trim()));
117
- const replacements = flatten(replacementsArr);
109
+ const replacements = pairs.flatMap(pair => pair.split(',').map(str => str.trim()));
118
110
  debug('Pairs: ', pairs, 'Replacements: ', replacements);
119
111
  if (inPlace) {
120
112
  const approved = await (0, _prompt.confirm)([], 'Are you sure you want to run search and replace on your input file? This operation is not reversible.');
@@ -142,20 +134,15 @@ const searchAndReplace = async (fileName, pairs, {
142
134
  try {
143
135
  replacedStream = await (0, _vipSearchReplace.replace)(readStream, replacements, binary);
144
136
  } catch (replaceError) {
137
+ // replace() throws strings... OMG
145
138
  exit.withError(replaceError);
146
139
  }
147
- const result = await new Promise((resolve, reject) => {
148
- replacedStream.pipe(writeStream).on('finish', () => {
149
- resolve({
150
- inputFileName: fileName,
151
- outputFileName,
152
- usingStdOut
153
- });
154
- }).on('error', () => {
155
- console.log(_chalk.default.red("Oh no! We couldn't write to the output file. Please check your available disk space and file/folder permissions."));
156
- reject();
157
- });
158
- });
140
+ try {
141
+ await (0, _promises.pipeline)(replacedStream, writeStream);
142
+ } catch (error) {
143
+ console.log((0, _chalk.red)("Oh no! We couldn't write to the output file. Please check your available disk space and file/folder permissions."));
144
+ throw error;
145
+ }
159
146
  const endTime = process.hrtime(startTime);
160
147
  const end = endTime[1] / 1000000; // time in ms
161
148
 
@@ -163,6 +150,10 @@ const searchAndReplace = async (fileName, pairs, {
163
150
  time_to_run: end,
164
151
  file_size: fileSize
165
152
  });
166
- return result;
153
+ return {
154
+ inputFileName: fileName,
155
+ outputFileName,
156
+ usingStdOut
157
+ };
167
158
  };
168
159
  exports.searchAndReplace = searchAndReplace;
@@ -246,8 +246,9 @@ ${maybeExitPrompt}
246
246
 
247
247
  // if the progress meta isn't filled out yet, wait until it is.
248
248
  if (!statusSteps) {
249
- return setTimeout(checkStatus, IMPORT_SQL_PROGRESS_POLL_INTERVAL);
249
+ return setTimeout(checkStatus, IMPORT_SQL_PROGRESS_POLL_INTERVAL); // NOSONAR
250
250
  }
251
+
251
252
  jobSteps = statusSteps.map(step => {
252
253
  return {
253
254
  id: step.name,
@@ -348,11 +349,11 @@ ${maybeExitPrompt}
348
349
  return resolve(importJob);
349
350
  }
350
351
  overallStatus = 'running';
351
- setTimeout(checkStatus, IMPORT_SQL_PROGRESS_POLL_INTERVAL);
352
+ setTimeout(checkStatus, IMPORT_SQL_PROGRESS_POLL_INTERVAL); // NOSONAR
352
353
  };
353
354
 
354
355
  // Kick off the check
355
- checkStatus();
356
+ void checkStatus();
356
357
  });
357
358
  try {
358
359
  const results = await getResults();
package/dist/lib/token.js CHANGED
@@ -12,9 +12,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
12
12
  /**
13
13
  * External dependencies
14
14
  */
15
+
15
16
  /**
16
17
  * Internal dependencies
17
18
  */
19
+
18
20
  // Config
19
21
  const SERVICE = 'vip-go-cli';
20
22
  exports.SERVICE = SERVICE;
@@ -28,9 +30,9 @@ class Token {
28
30
  return;
29
31
  }
30
32
  const decodedToken = (0, _jwtDecode.default)(token);
31
- this.raw = token;
33
+ this._raw = token;
32
34
  if (decodedToken.id) {
33
- this.id = decodedToken.id;
35
+ this._id = decodedToken.id;
34
36
  }
35
37
  if (decodedToken.iat) {
36
38
  this.iat = new Date(decodedToken.iat * 1000);
@@ -40,7 +42,7 @@ class Token {
40
42
  }
41
43
  }
42
44
  valid() {
43
- if (!this.id) {
45
+ if (!this._id) {
44
46
  return false;
45
47
  }
46
48
  if (!this.iat) {
@@ -59,6 +61,14 @@ class Token {
59
61
  const now = new Date();
60
62
  return now > this.exp;
61
63
  }
64
+ get id() {
65
+ var _this$_id;
66
+ return (_this$_id = this._id) !== null && _this$_id !== void 0 ? _this$_id : NaN;
67
+ }
68
+ get raw() {
69
+ var _this$_raw;
70
+ return (_this$_raw = this._raw) !== null && _this$_raw !== void 0 ? _this$_raw : '';
71
+ }
62
72
  static async uuid() {
63
73
  const service = Token.getServiceName('-uuid');
64
74
  let _uuid = await _keychain.default.getPassword(service);
@@ -72,16 +82,17 @@ class Token {
72
82
  const service = Token.getServiceName('-uuid');
73
83
  await _keychain.default.setPassword(service, _uuid);
74
84
  }
75
- static async set(token) {
85
+ static set(token) {
76
86
  const service = Token.getServiceName();
77
87
  return _keychain.default.setPassword(service, token);
78
88
  }
79
89
  static async get() {
90
+ var _await$keychain$getPa;
80
91
  const service = Token.getServiceName();
81
- const token = await _keychain.default.getPassword(service);
92
+ const token = (_await$keychain$getPa = await _keychain.default.getPassword(service)) !== null && _await$keychain$getPa !== void 0 ? _await$keychain$getPa : '';
82
93
  return new Token(token);
83
94
  }
84
- static async purge() {
95
+ static purge() {
85
96
  const service = Token.getServiceName();
86
97
  return _keychain.default.deletePassword(service);
87
98
  }
@@ -7,6 +7,7 @@ exports.aliasUser = aliasUser;
7
7
  exports.makeCommandTracker = makeCommandTracker;
8
8
  exports.trackEvent = trackEvent;
9
9
  exports.trackEventWithEnv = trackEventWithEnv;
10
+ var _debug = _interopRequireDefault(require("debug"));
10
11
  var _index = _interopRequireDefault(require("./analytics/index"));
11
12
  var _tracks = _interopRequireDefault(require("./analytics/clients/tracks"));
12
13
  var _pendo = _interopRequireDefault(require("./analytics/clients/pendo"));
@@ -17,12 +18,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
17
18
  /**
18
19
  * External dependencies
19
20
  */
20
- const debug = require('debug')('@automattic/vip:analytics');
21
21
 
22
22
  /**
23
23
  * Internal dependencies
24
24
  */
25
25
 
26
+ const debug = (0, _debug.default)('@automattic/vip:analytics');
26
27
  let analytics = null;
27
28
  async function init() {
28
29
  const uuid = await _token.default.uuid();
@@ -37,10 +38,7 @@ async function init() {
37
38
  userId: uuid
38
39
  }));
39
40
  }
40
- analytics = new _index.default({
41
- clients
42
- });
43
- return analytics;
41
+ return new _index.default(clients);
44
42
  }
45
43
  async function getInstance() {
46
44
  if (analytics) {
@@ -49,30 +47,31 @@ async function getInstance() {
49
47
  analytics = await init();
50
48
  return analytics;
51
49
  }
52
- async function trackEvent(...args) {
50
+ async function trackEvent(name, props = {}) {
53
51
  try {
54
52
  await _token.default.uuid();
55
53
  const client = await getInstance();
56
- return await client.trackEvent(...args);
54
+ return await client.trackEvent(name, props);
57
55
  } catch (err) {
58
56
  debug('trackEvent() failed', err);
57
+ return [];
59
58
  }
60
59
  }
61
60
  async function aliasUser(vipUserId) {
62
- try {
63
- if (vipUserId) {
61
+ if (vipUserId) {
62
+ try {
64
63
  await trackEvent('_alias_user', {
65
64
  ui: vipUserId,
66
65
  _ut: _config.default.tracksUserType,
67
- anonid: _token.default.uuid()
66
+ anonid: await _token.default.uuid()
68
67
  });
69
- _token.default.setUuid(vipUserId);
68
+ await _token.default.setUuid(`${vipUserId}`);
69
+ } catch (err) {
70
+ debug('aliasUser() failed', err);
70
71
  }
71
- } catch (err) {
72
- debug('aliasUser() failed', err);
73
72
  }
74
73
  }
75
- async function trackEventWithEnv(appId, envId, eventName, eventProps = {}) {
74
+ function trackEventWithEnv(appId, envId, eventName, eventProps = {}) {
76
75
  return trackEvent(eventName, {
77
76
  ...eventProps,
78
77
  app_id: appId,