@automattic/vip 2.21.0 → 2.23.0

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 (111) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/assets/dev-env.lando.template.yml.ejs +1 -1
  3. package/automattic-vip-2.23.0.tgz +0 -0
  4. package/dist/bin/vip-app-list.js +0 -12
  5. package/dist/bin/vip-app.js +6 -13
  6. package/dist/bin/vip-cache-purge-url.js +4 -19
  7. package/dist/bin/vip-cache.js +0 -2
  8. package/dist/bin/vip-config-envvar-delete.js +4 -19
  9. package/dist/bin/vip-config-envvar-get-all.js +6 -19
  10. package/dist/bin/vip-config-envvar-get.js +4 -15
  11. package/dist/bin/vip-config-envvar-list.js +8 -20
  12. package/dist/bin/vip-config-envvar-set.js +4 -23
  13. package/dist/bin/vip-config-envvar.js +0 -2
  14. package/dist/bin/vip-config-software-get.js +0 -17
  15. package/dist/bin/vip-config-software-update.js +6 -22
  16. package/dist/bin/vip-config-software.js +0 -2
  17. package/dist/bin/vip-config.js +0 -2
  18. package/dist/bin/vip-dev-env-create.js +0 -18
  19. package/dist/bin/vip-dev-env-destroy.js +0 -9
  20. package/dist/bin/vip-dev-env-exec.js +0 -12
  21. package/dist/bin/vip-dev-env-import-media.js +0 -7
  22. package/dist/bin/vip-dev-env-import-sql.js +2 -17
  23. package/dist/bin/vip-dev-env-import.js +0 -3
  24. package/dist/bin/vip-dev-env-info.js +0 -10
  25. package/dist/bin/vip-dev-env-list.js +0 -7
  26. package/dist/bin/vip-dev-env-start.js +4 -14
  27. package/dist/bin/vip-dev-env-stop.js +0 -9
  28. package/dist/bin/vip-dev-env-update.js +0 -11
  29. package/dist/bin/vip-dev-env.js +0 -2
  30. package/dist/bin/vip-import-media-abort.js +0 -18
  31. package/dist/bin/vip-import-media-status.js +0 -12
  32. package/dist/bin/vip-import-media.js +6 -23
  33. package/dist/bin/vip-import-sql-status.js +0 -12
  34. package/dist/bin/vip-import-sql.js +40 -103
  35. package/dist/bin/vip-import-validate-files.js +21 -42
  36. package/dist/bin/vip-import-validate-sql.js +0 -8
  37. package/dist/bin/vip-import.js +0 -3
  38. package/dist/bin/vip-logs.js +20 -50
  39. package/dist/bin/vip-search-replace.js +8 -14
  40. package/dist/bin/vip-sync.js +2 -25
  41. package/dist/bin/vip-validate-preflight.js +427 -0
  42. package/dist/bin/vip-validate.js +19 -0
  43. package/dist/bin/vip-whoami.js +2 -14
  44. package/dist/bin/vip-wp.js +39 -89
  45. package/dist/bin/vip.js +5 -35
  46. package/dist/lib/analytics/clients/pendo.js +9 -18
  47. package/dist/lib/analytics/clients/stub.js +1 -3
  48. package/dist/lib/analytics/clients/tracks.js +11 -20
  49. package/dist/lib/analytics/index.js +4 -11
  50. package/dist/lib/api/app.js +1 -11
  51. package/dist/lib/api/cache-purge.js +4 -7
  52. package/dist/lib/api/feature-flags.js +1 -4
  53. package/dist/lib/api/http.js +9 -15
  54. package/dist/lib/api/user.js +1 -7
  55. package/dist/lib/api.js +17 -19
  56. package/dist/lib/app-logs/app-logs.js +2 -9
  57. package/dist/lib/app.js +2 -5
  58. package/dist/lib/cli/apiConfig.js +4 -19
  59. package/dist/lib/cli/command.js +43 -133
  60. package/dist/lib/cli/config.js +1 -5
  61. package/dist/lib/cli/envAlias.js +14 -15
  62. package/dist/lib/cli/exit.js +4 -6
  63. package/dist/lib/cli/format.js +8 -50
  64. package/dist/lib/cli/progress.js +13 -42
  65. package/dist/lib/cli/prompt.js +1 -5
  66. package/dist/lib/cli/repo.js +7 -20
  67. package/dist/lib/client-file-uploader.js +44 -97
  68. package/dist/lib/config/software.js +2 -52
  69. package/dist/lib/constants/dev-environment.js +1 -2
  70. package/dist/lib/constants/file-size.js +1 -1
  71. package/dist/lib/constants/vipgo.js +1 -1
  72. package/dist/lib/dev-environment/dev-environment-cli.js +68 -155
  73. package/dist/lib/dev-environment/dev-environment-core.js +73 -194
  74. package/dist/lib/dev-environment/dev-environment-lando.js +16 -71
  75. package/dist/lib/env.js +1 -4
  76. package/dist/lib/envvar/api-delete.js +1 -4
  77. package/dist/lib/envvar/api-get-all.js +1 -4
  78. package/dist/lib/envvar/api-get.js +1 -2
  79. package/dist/lib/envvar/api-list.js +3 -4
  80. package/dist/lib/envvar/api-set.js +1 -4
  81. package/dist/lib/envvar/api.js +5 -16
  82. package/dist/lib/envvar/input.js +1 -8
  83. package/dist/lib/envvar/logging.js +2 -6
  84. package/dist/lib/envvar/read-file.js +1 -3
  85. package/dist/lib/http/proxy-agent.js +17 -22
  86. package/dist/lib/keychain/browser.js +1 -4
  87. package/dist/lib/keychain/insecure.js +1 -10
  88. package/dist/lib/keychain/secure.js +1 -8
  89. package/dist/lib/keychain.js +4 -8
  90. package/dist/lib/logout.js +0 -6
  91. package/dist/lib/media-import/media-file-import.js +3 -7
  92. package/dist/lib/media-import/progress.js +6 -17
  93. package/dist/lib/media-import/status.js +14 -65
  94. package/dist/lib/read-file.js +1 -6
  95. package/dist/lib/rollbar.js +1 -7
  96. package/dist/lib/search-and-replace.js +9 -41
  97. package/dist/lib/site-import/db-file-import.js +3 -9
  98. package/dist/lib/site-import/status.js +17 -74
  99. package/dist/lib/token.js +1 -33
  100. package/dist/lib/tracker.js +4 -20
  101. package/dist/lib/user-error.js +0 -2
  102. package/dist/lib/validations/is-multi-site-sql-dump.js +4 -12
  103. package/dist/lib/validations/is-multi-site.js +5 -21
  104. package/dist/lib/validations/is-multisite-domain-mapped.js +5 -31
  105. package/dist/lib/validations/line-by-line.js +4 -16
  106. package/dist/lib/validations/site-type.js +10 -19
  107. package/dist/lib/validations/sql.js +11 -76
  108. package/dist/lib/validations/utils.js +1 -6
  109. package/dist/lib/vip-import-validate-files.js +82 -109
  110. package/npm-shrinkwrap.json +2407 -1800
  111. package/package.json +18 -15
@@ -1,25 +1,24 @@
1
1
  "use strict";
2
2
 
3
3
  var _socksProxyAgent = require("socks-proxy-agent");
4
-
5
4
  var _httpsProxyAgent = require("https-proxy-agent");
6
-
7
5
  var _proxyFromEnv = require("proxy-from-env");
8
-
9
6
  var _debug = _interopRequireDefault(require("debug"));
10
-
11
7
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
-
13
8
  /**
14
9
  * External dependencies
15
10
  */
11
+
16
12
  const debug = (0, _debug.default)('vip:proxy-agent');
13
+
17
14
  /**
18
15
  * Internal dependencies
19
16
  */
17
+
20
18
  // Note: This module requires the use of a special environment variable "VIP_USE_SYSTEM_PROXY"
21
19
  // The setting of it to any value allows this module to create a proxy agent based on proxy environment variables
22
20
  // If not set, this module will revert back to the previous functionality (hence being fully backward compatible and non-breaking for users)
21
+
23
22
  // This function returns a proxy given a few scenarios (in order of precedence):
24
23
  // 1. VIP_PROXY is set: a SOCKS proxy is returned same as the previous version of this module
25
24
  // 2. No applicable variables are set: null is returned (thus, no proxy agent is returned)
@@ -27,34 +26,33 @@ const debug = (0, _debug.default)('vip:proxy-agent');
27
26
  // 4. VIP_USE_SYSTEM_PROXY and HTTPS_PROXY are set: an HTTPS_PROXY is returned
28
27
  // 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
29
28
  // This allows near full customization by the client of what proxy should be used, instead of making assumptions based on the URL string
30
-
31
29
  function createProxyAgent(url) {
32
30
  const VIP_PROXY = process.env.VIP_PROXY || process.env.vip_proxy || null;
33
31
  const SOCKS_PROXY = process.env.SOCKS_PROXY || process.env.socks_proxy || null;
34
32
  const HTTPS_PROXY = process.env.HTTPS_PROXY || process.env.https_proxy || null;
35
- const NO_PROXY = process.env.NO_PROXY || process.env.no_proxy || null; // VIP Socks Proxy should take precedence and should be fully backward compatible
33
+ const NO_PROXY = process.env.NO_PROXY || process.env.no_proxy || null;
36
34
 
35
+ // VIP Socks Proxy should take precedence and should be fully backward compatible
37
36
  if (VIP_PROXY) {
38
37
  debug(`Enabling VIP_PROXY proxy support using config: ${VIP_PROXY}`);
39
38
  return new _socksProxyAgent.SocksProxyAgent(VIP_PROXY);
40
- } // Now check for any system proxy usage
41
-
42
-
39
+ }
40
+ // Now check for any system proxy usage
43
41
  if (process.env.VIP_USE_SYSTEM_PROXY && !coveredInNoProxy(url, NO_PROXY)) {
44
42
  if (SOCKS_PROXY) {
45
43
  debug(`Enabling SOCKS proxy support using config: ${SOCKS_PROXY}`);
46
44
  return new _socksProxyAgent.SocksProxyAgent(SOCKS_PROXY);
47
45
  }
48
-
49
46
  if (HTTPS_PROXY) {
50
47
  debug(`Enabling HTTPS proxy support using config: ${HTTPS_PROXY}`);
51
48
  return new _httpsProxyAgent.HttpsProxyAgent(HTTPS_PROXY);
52
49
  }
53
- } // If no environment variables are set, the no proxy is in effect, or if the proxy enable is not set return null (equivilant of no Proxy agent)
54
-
55
-
50
+ }
51
+ // If no environment variables are set, the no proxy is in effect, or if the proxy enable is not set return null (equivilant of no Proxy agent)
56
52
  return null;
57
- } // Determine if a NO_PROXY variable is applicable to a given URL
53
+ }
54
+
55
+ // Determine if a NO_PROXY variable is applicable to a given URL
58
56
  // Parameters:
59
57
  // - url (string): absolute desintation URL (including the protocol)
60
58
  // - noProxyString (string | null): string representation of the environments current NO_PROXY or no_proxy variable (NO_PROXY takes precedence)
@@ -66,20 +64,17 @@ function createProxyAgent(url) {
66
64
  // Example: '.api' does NOT match wp.api.org, but '.api.org' does (see tests)
67
65
  // 3. abc.com: do not proxy www.abc.com, abc.com, etc.
68
66
  // See proxy-from-env on npmjs.org for full "ruleset"
69
-
70
-
71
67
  function coveredInNoProxy(url, noProxyString) {
72
68
  // If the NO_PROXY env variable is not set, then the URL is not covered in the NO_PROXY (utility below does not handle this case)
73
69
  if (!noProxyString) {
74
70
  return false;
75
- } // If getProxyForUrl returns an empty string, then the host should not be proxied
71
+ }
72
+ // If getProxyForUrl returns an empty string, then the host should not be proxied
76
73
  // This isn't the most straight forward way to determine if a NO_PROXY is applicable, but the only package I could find that is relatively new and maintained
77
-
78
-
79
74
  return (0, _proxyFromEnv.getProxyForUrl)(url) === '';
80
- } // Exports
81
-
75
+ }
82
76
 
77
+ // Exports
83
78
  module.exports = {
84
79
  createProxyAgent
85
80
  };
@@ -8,6 +8,7 @@ exports.default = void 0;
8
8
  /**
9
9
  * Internal dependencies
10
10
  */
11
+
11
12
  class Secure {
12
13
  getPassword(service) {
13
14
  return new Promise(resolve => {
@@ -15,21 +16,17 @@ class Secure {
15
16
  return resolve(password);
16
17
  });
17
18
  }
18
-
19
19
  setPassword(service, password) {
20
20
  return new Promise(resolve => {
21
21
  const set = !!window.localStorage.setItem(service, password);
22
22
  return resolve(set);
23
23
  });
24
24
  }
25
-
26
25
  deletePassword(service) {
27
26
  return new Promise(resolve => {
28
27
  const del = !!window.localStorage.removeItem(service);
29
28
  return resolve(del);
30
29
  });
31
30
  }
32
-
33
31
  }
34
-
35
32
  exports.default = Secure;
@@ -9,31 +9,27 @@ exports.default = void 0;
9
9
  * External dependencies
10
10
  */
11
11
  const Configstore = require('configstore');
12
+
12
13
  /**
13
14
  * Internal dependencies
14
15
  */
15
16
 
16
-
17
17
  class Insecure {
18
18
  constructor(file) {
19
19
  this.file = file;
20
20
  this.configstore = new Configstore(this.file);
21
21
  }
22
-
23
22
  getPassword(service) {
24
23
  return new Promise((resolve, reject) => {
25
24
  let password = null;
26
-
27
25
  try {
28
26
  password = this.configstore.get(service);
29
27
  } catch (err) {
30
28
  return reject(err);
31
29
  }
32
-
33
30
  return resolve(password);
34
31
  });
35
32
  }
36
-
37
33
  setPassword(service, password) {
38
34
  return new Promise((resolve, reject) => {
39
35
  try {
@@ -41,11 +37,9 @@ class Insecure {
41
37
  } catch (err) {
42
38
  return reject(err);
43
39
  }
44
-
45
40
  resolve(true);
46
41
  });
47
42
  }
48
-
49
43
  deletePassword(service) {
50
44
  return new Promise((resolve, reject) => {
51
45
  try {
@@ -53,11 +47,8 @@ class Insecure {
53
47
  } catch (err) {
54
48
  return reject(err);
55
49
  }
56
-
57
50
  resolve(true);
58
51
  });
59
52
  }
60
-
61
53
  }
62
-
63
54
  exports.default = Insecure;
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _keytar = _interopRequireDefault(require("keytar"));
9
-
10
8
  var _keychain = _interopRequireDefault(require("./keychain"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  /**
15
11
  * External dependencies
16
12
  */
@@ -18,19 +14,16 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
18
14
  /**
19
15
  * Internal dependencies
20
16
  */
17
+
21
18
  class Secure {
22
19
  getPassword(service) {
23
20
  return _keytar.default.getPassword(service, service);
24
21
  }
25
-
26
22
  setPassword(service, password) {
27
23
  return _keytar.default.setPassword(service, service, password);
28
24
  }
29
-
30
25
  deletePassword(service) {
31
26
  return _keytar.default.deletePassword(service, service);
32
27
  }
33
-
34
28
  }
35
-
36
29
  exports.default = Secure;
@@ -1,36 +1,32 @@
1
1
  "use strict";
2
2
 
3
3
  var _insecure = _interopRequireDefault(require("./keychain/insecure"));
4
-
5
4
  var _browser = _interopRequireDefault(require("./keychain/browser"));
6
-
7
5
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
-
9
6
  /**
10
7
  * External dependencies
11
8
  */
12
9
  const debug = require('debug')('@automattic/vip:keychain');
10
+
13
11
  /**
14
12
  * Internal dependencies
15
13
  */
16
14
 
17
-
18
15
  let exportValue = {};
19
-
20
16
  if (typeof window === 'undefined' || typeof window.localStorage === 'undefined') {
21
17
  // node
18
+
22
19
  try {
23
20
  // Try using Secure keychain ("keytar") first
24
21
  const Secure = require("./keychain/secure");
25
-
26
22
  exportValue = new Secure();
27
23
  } catch (error) {
28
- debug('Cannot use Secure keychain; falling back to Insecure keychain (Details: %o)', error); // Fallback to Insecure keychain if we can't
24
+ debug('Cannot use Secure keychain; falling back to Insecure keychain (Details: %o)', error);
29
25
 
26
+ // Fallback to Insecure keychain if we can't
30
27
  exportValue = new _insecure.default('vip-go-cli');
31
28
  }
32
29
  } else {
33
30
  exportValue = new _browser.default();
34
31
  }
35
-
36
32
  module.exports = exportValue;
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _token = _interopRequireDefault(require("./token"));
9
-
10
8
  var _tracker = require("./tracker");
11
-
12
9
  var _http = _interopRequireDefault(require("./api/http"));
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
11
  /**
17
12
  * Internal dependencies
18
13
  */
@@ -23,5 +18,4 @@ var _default = async () => {
23
18
  await _token.default.purge();
24
19
  await (0, _tracker.trackEvent)('logout_command_execute');
25
20
  };
26
-
27
21
  exports.default = _default;
@@ -3,11 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.SUPPORTED_MEDIA_FILE_IMPORT_SITE_TYPES = exports.MEDIA_IMPORT_FILE_SIZE_LIMIT = void 0;
6
7
  exports.currentUserCanImportForApp = currentUserCanImportForApp;
7
- exports.isSupportedApp = exports.SUPPORTED_MEDIA_FILE_IMPORT_SITE_TYPES = exports.MEDIA_IMPORT_FILE_SIZE_LIMIT = void 0;
8
-
8
+ exports.isSupportedApp = void 0;
9
9
  var _fileSize = require("../constants/file-size");
10
-
11
10
  /**
12
11
  *
13
12
  * @format
@@ -16,19 +15,16 @@ var _fileSize = require("../constants/file-size");
16
15
  /**
17
16
  * Internal dependencies
18
17
  */
18
+
19
19
  const MEDIA_IMPORT_FILE_SIZE_LIMIT = 30 * _fileSize.GB_IN_BYTES;
20
20
  exports.MEDIA_IMPORT_FILE_SIZE_LIMIT = MEDIA_IMPORT_FILE_SIZE_LIMIT;
21
-
22
21
  function currentUserCanImportForApp(app) {
23
22
  // TODO: implement
24
23
  return !!app;
25
24
  }
26
-
27
25
  const SUPPORTED_MEDIA_FILE_IMPORT_SITE_TYPES = ['WordPress'];
28
26
  exports.SUPPORTED_MEDIA_FILE_IMPORT_SITE_TYPES = SUPPORTED_MEDIA_FILE_IMPORT_SITE_TYPES;
29
-
30
27
  const isSupportedApp = ({
31
28
  type
32
29
  }) => SUPPORTED_MEDIA_FILE_IMPORT_SITE_TYPES.includes(type);
33
-
34
30
  exports.isSupportedApp = isSupportedApp;
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.MediaImportProgressTracker = void 0;
7
-
8
7
  var _singleLineLog = require("single-line-log");
9
-
10
8
  var _status = require("./status");
11
-
12
9
  var _format = require("../cli/format");
13
-
14
10
  /** @format */
15
11
 
16
12
  /**
@@ -20,12 +16,16 @@ var _format = require("../cli/format");
20
16
  /**
21
17
  * Internal dependencies
22
18
  */
19
+
23
20
  const PRINT_INTERVAL = process.env.DEBUG ? 5000 : 200; // How often the report is printed. Mainly affects the "spinner" animation.
24
21
 
25
22
  class MediaImportProgressTracker {
26
23
  // Spinnerz go brrrr
24
+
27
25
  // This gets printed before the step status
26
+
28
27
  // This gets printed after the step status
28
+
29
29
  constructor(status) {
30
30
  this.runningSprite = new _format.RunningSprite();
31
31
  this.hasFailure = false;
@@ -33,54 +33,43 @@ class MediaImportProgressTracker {
33
33
  this.prefix = '';
34
34
  this.suffix = '';
35
35
  }
36
-
37
36
  setStatus(status) {
38
37
  if ('FAILED' === status.status) {
39
38
  this.hasFailure = true;
40
39
  }
41
-
42
40
  this.status = Object.assign({}, status);
43
41
  }
44
-
45
42
  startPrinting(prePrintCallback = () => {}) {
46
43
  this.printInterval = setInterval(() => {
47
44
  prePrintCallback();
48
45
  this.print();
49
46
  }, PRINT_INTERVAL);
50
47
  }
51
-
52
48
  stopPrinting() {
53
49
  if (this.printInterval) {
54
50
  clearInterval(this.printInterval);
55
51
  }
56
52
  }
57
-
58
53
  print({
59
54
  clearAfter = false
60
55
  } = {}) {
61
56
  if (!this.hasPrinted) {
62
57
  this.hasPrinted = true;
63
-
64
58
  _singleLineLog.stdout.clear();
65
59
  }
66
-
67
60
  const statusIcon = (0, _status.getGlyphForStatus)(this.status.status, this.runningSprite);
68
61
  let logs;
69
-
70
62
  if (this.status.filesProcessed && this.status.filesTotal) {
71
63
  const progressPercentage = Math.floor(this.status.filesProcessed / this.status.filesTotal * 100);
72
64
  logs = `Imported Files: ${this.status.filesProcessed}/${this.status.filesTotal} - ${progressPercentage}% ${statusIcon}`;
73
- } // Output the logs
74
-
65
+ }
75
66
 
67
+ // Output the logs
76
68
  (0, _singleLineLog.stdout)(`${this.prefix || ''}${logs || ''}${this.suffix || ''}`);
77
-
78
69
  if (clearAfter) {
79
70
  // Break out of the "Single log line" buffer
80
71
  _singleLineLog.stdout.clear();
81
72
  }
82
73
  }
83
-
84
74
  }
85
-
86
75
  exports.MediaImportProgressTracker = MediaImportProgressTracker;
@@ -3,32 +3,20 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.default = void 0;
6
7
  exports.getGlyphForStatus = getGlyphForStatus;
7
8
  exports.mediaImportCheckStatus = mediaImportCheckStatus;
8
- exports.default = void 0;
9
-
10
9
  var _chalk = _interopRequireDefault(require("chalk"));
11
-
12
10
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
13
-
14
11
  var _fs = require("fs");
15
-
16
12
  var path = _interopRequireWildcard(require("path"));
17
-
18
13
  var _api = _interopRequireDefault(require("../api"));
19
-
20
14
  var _mediaFileImport = require("./media-file-import");
21
-
22
15
  var _progress = require("./progress");
23
-
24
16
  var _format = require("../cli/format");
25
-
26
17
  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); }
27
-
28
18
  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; }
29
-
30
19
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
-
32
20
  /**
33
21
  *
34
22
  * @format
@@ -41,6 +29,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
41
29
  /**
42
30
  * Internal dependencies
43
31
  */
32
+
44
33
  const IMPORT_MEDIA_PROGRESS_POLL_INTERVAL = 1000;
45
34
  const ONE_MINUTE_IN_MILLISECONDS = 1000 * 60;
46
35
  const TWO_MINUTES_IN_MILLISECONDS = 2 * ONE_MINUTE_IN_MILLISECONDS;
@@ -71,7 +60,6 @@ const IMPORT_MEDIA_PROGRESS_QUERY = (0, _graphqlTag.default)`
71
60
  }
72
61
  }
73
62
  `;
74
-
75
63
  async function getStatus(api, appId, envId) {
76
64
  const response = await api.query({
77
65
  query: IMPORT_MEDIA_PROGRESS_QUERY,
@@ -88,23 +76,19 @@ async function getStatus(api, appId, envId) {
88
76
  }
89
77
  }
90
78
  } = response;
91
-
92
79
  if (!(environments !== null && environments !== void 0 && environments.length)) {
93
80
  throw new Error('Unable to determine import status from environment');
94
81
  }
95
-
96
82
  const [environment] = environments;
97
83
  const {
98
84
  mediaImportStatus
99
85
  } = environment;
100
86
  return mediaImportStatus;
101
87
  }
102
-
103
88
  function getGlyphForStatus(status, runningSprite) {
104
89
  switch (status) {
105
90
  case 'INITIALIZING':
106
91
  return '○';
107
-
108
92
  case 'INITIALIZED':
109
93
  case 'RUNNING':
110
94
  case 'COMPLETING':
@@ -112,28 +96,21 @@ function getGlyphForStatus(status, runningSprite) {
112
96
  case 'VALIDATING':
113
97
  case 'VALIDATED':
114
98
  return _chalk.default.blueBright(runningSprite);
115
-
116
99
  case 'COMPLETED':
117
100
  return _chalk.default.green('✓');
118
-
119
101
  case 'FAILED':
120
102
  return _chalk.default.red('✕');
121
-
122
103
  case 'ABORTED':
123
104
  case 'ABORTING':
124
105
  return _chalk.default.yellow('⚠️');
125
-
126
106
  default:
127
107
  return '';
128
108
  }
129
109
  }
130
-
131
110
  function buildErrorMessage(importFailed) {
132
111
  let message = '';
133
-
134
112
  if ('FAILED' === importFailed.status) {
135
113
  const globalFailureDetails = importFailed.failureDetails;
136
-
137
114
  if (globalFailureDetails) {
138
115
  message += `${_chalk.default.red('Import failed at status: ')}`;
139
116
  message += `${_chalk.default.redBright.bold(globalFailureDetails.previousStatus)}\n`;
@@ -144,13 +121,11 @@ function buildErrorMessage(importFailed) {
144
121
  return message;
145
122
  }
146
123
  }
147
-
148
124
  message += _chalk.default.red(importFailed.error ? importFailed.error : importFailed);
149
125
  message += '\n\nPlease check the status of your Import using `vip import media status @mysite.production`';
150
126
  message += '\n\nIf this error persists and you are not sure on how to fix, please contact support\n';
151
127
  return message;
152
128
  }
153
-
154
129
  function buildFileErrors(fileErrors, exportFileErrorsToJson) {
155
130
  if (exportFileErrorsToJson) {
156
131
  const fileErrorsToExport = fileErrors.map(fileError => {
@@ -161,17 +136,13 @@ function buildFileErrors(fileErrors, exportFileErrorsToJson) {
161
136
  });
162
137
  return (0, _format.formatData)(fileErrorsToExport, 'json');
163
138
  }
164
-
165
139
  let errorString = '';
166
-
167
140
  for (const fileError of fileErrors) {
168
141
  errorString += `File Name: ${fileError.fileName}`;
169
142
  errorString += `\n\nErrors:\n\t- ${fileError.errors}\n\n\n\n`;
170
143
  }
171
-
172
144
  return errorString;
173
145
  }
174
-
175
146
  async function mediaImportCheckStatus({
176
147
  app,
177
148
  env,
@@ -179,34 +150,28 @@ async function mediaImportCheckStatus({
179
150
  exportFileErrorsToJson
180
151
  }) {
181
152
  // Stop printing so we can pass our callback
182
- progressTracker.stopPrinting(); // NO `console.log` in this function (until results are final)! It will break the progress printing.
153
+ progressTracker.stopPrinting();
183
154
 
155
+ // NO `console.log` in this function (until results are final)! It will break the progress printing.
184
156
  const api = await (0, _api.default)();
185
-
186
157
  if (!(0, _mediaFileImport.currentUserCanImportForApp)(app)) {
187
158
  throw new Error('The currently authenticated account does not have permission to view Media Import status.');
188
159
  }
189
-
190
160
  let overallStatus = 'Checking...';
191
-
192
161
  const setProgressTrackerSuffix = () => {
193
162
  const sprite = getGlyphForStatus(overallStatus, progressTracker.runningSprite);
194
163
  const exitPrompt = '(Press ^C to hide progress. The import will continue in the background.)';
195
164
  let statusMessage;
196
-
197
165
  switch (overallStatus) {
198
166
  case 'INITIALIZING':
199
167
  statusMessage = `INITIALIZING ${sprite} : We're downloading the files to be imported...`;
200
168
  break;
201
-
202
169
  case 'COMPLETED':
203
170
  statusMessage = `COMPLETED ${sprite} : The imported files should be visible on your App`;
204
171
  break;
205
-
206
172
  default:
207
173
  statusMessage = `${(0, _format.capitalize)(overallStatus)} ${sprite}`;
208
174
  }
209
-
210
175
  const maybeExitPrompt = ['COMPLETED', 'ABORTED', 'FAILED'].includes(overallStatus) ? '' : exitPrompt;
211
176
  const suffix = `
212
177
  =============================================================
@@ -217,24 +182,18 @@ ${maybeExitPrompt}
217
182
  `;
218
183
  progressTracker.suffix = suffix;
219
184
  };
220
-
221
185
  const setSuffixAndPrint = () => {
222
186
  setProgressTrackerSuffix();
223
187
  progressTracker.print();
224
188
  };
225
-
226
189
  progressTracker.startPrinting(setSuffixAndPrint);
227
-
228
190
  const getResults = () => new Promise((resolve, reject) => {
229
191
  let startDate = Date.now();
230
192
  let pollIntervalDecreasing = false;
231
-
232
193
  const checkStatus = async pollInterval => {
233
194
  let mediaImportStatus;
234
-
235
195
  try {
236
196
  mediaImportStatus = await getStatus(api, app.id, env.id);
237
-
238
197
  if (!mediaImportStatus) {
239
198
  return reject({
240
199
  error: 'Requested app/environment is not available for this operation. If you think this is not correct, please contact Support.'
@@ -245,75 +204,66 @@ ${maybeExitPrompt}
245
204
  error
246
205
  });
247
206
  }
248
-
249
207
  const {
250
208
  status
251
209
  } = mediaImportStatus;
252
210
  const failedMediaImport = 'FAILED' === status;
253
-
254
211
  if (failedMediaImport) {
255
212
  progressTracker.setStatus(mediaImportStatus);
256
213
  overallStatus = 'FAILED';
257
214
  setSuffixAndPrint();
258
- return reject({ ...mediaImportStatus,
215
+ return reject({
216
+ ...mediaImportStatus,
259
217
  error: 'Import FAILED'
260
218
  });
261
219
  }
262
-
263
220
  progressTracker.setStatus(mediaImportStatus);
264
221
  setSuffixAndPrint();
265
-
266
222
  if (['COMPLETED', 'ABORTED'].includes(status)) {
267
223
  return resolve(mediaImportStatus);
268
224
  }
225
+ overallStatus = status;
269
226
 
270
- overallStatus = status; // after two minutes, we'll start decreasing the pollInterval
271
-
272
- pollIntervalDecreasing = pollIntervalDecreasing || startDate < Date.now() - TWO_MINUTES_IN_MILLISECONDS; // decrease poll interval by a second, every minute
227
+ // after two minutes, we'll start decreasing the pollInterval
228
+ pollIntervalDecreasing = pollIntervalDecreasing || startDate < Date.now() - TWO_MINUTES_IN_MILLISECONDS;
273
229
 
230
+ // decrease poll interval by a second, every minute
274
231
  if (pollIntervalDecreasing && startDate < Date.now() - ONE_MINUTE_IN_MILLISECONDS) {
275
232
  pollInterval = pollInterval + IMPORT_MEDIA_PROGRESS_POLL_INTERVAL;
276
233
  startDate = Date.now();
277
234
  }
278
-
279
235
  setTimeout(() => {
280
236
  checkStatus(pollInterval);
281
237
  }, pollInterval);
282
- }; // Kick off the check
283
-
238
+ };
284
239
 
240
+ // Kick off the check
285
241
  checkStatus(IMPORT_MEDIA_PROGRESS_POLL_INTERVAL);
286
242
  });
287
-
288
243
  try {
289
244
  var _results$failureDetai;
290
-
291
245
  const results = await getResults();
292
246
  overallStatus = (results === null || results === void 0 ? void 0 : results.status) || 'unknown';
293
247
  progressTracker.stopPrinting();
294
248
  setProgressTrackerSuffix();
295
249
  progressTracker.print();
296
250
  const fileErrors = (_results$failureDetai = results.failureDetails) === null || _results$failureDetai === void 0 ? void 0 : _results$failureDetai.fileErrors;
297
-
298
251
  if (!!fileErrors && fileErrors.length > 0) {
299
252
  progressTracker.suffix += `${_chalk.default.yellow(`⚠️ ${fileErrors.length} file error(s) have been extracted`)}`;
300
-
301
253
  if (results.filesTotal - results.filesProcessed !== fileErrors.length) {
302
254
  progressTracker.suffix += `. ${_chalk.default.italic.yellow('File-errors report size threshold reached.')}`;
303
255
  }
304
-
305
256
  const formattedData = buildFileErrors(fileErrors, exportFileErrorsToJson);
306
257
  const errorsFile = `media-import-${app.name}-${Date.now()}${!!exportFileErrorsToJson ? '.json' : '.txt'}`;
307
-
308
258
  try {
309
259
  await _fs.promises.writeFile(errorsFile, formattedData);
310
260
  progressTracker.suffix += `\n\n${_chalk.default.yellow(`All errors have been exported to ${_chalk.default.bold(path.resolve(errorsFile))}`)}\n\n`;
311
261
  } catch (writeFileErr) {
312
262
  progressTracker.suffix += `\n\n${_chalk.default.red(`Could not export errors to file\n${writeFileErr}`)}\n\n`;
313
263
  }
314
- } // Print one final time
315
-
264
+ }
316
265
 
266
+ // Print one final time
317
267
  progressTracker.print({
318
268
  clearAfter: true
319
269
  });
@@ -328,7 +278,6 @@ ${maybeExitPrompt}
328
278
  process.exit(1);
329
279
  }
330
280
  }
331
-
332
281
  var _default = {
333
282
  mediaImportCheckStatus
334
283
  };