@automattic/vip 2.22.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 (110) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/automattic-vip-2.23.0.tgz +0 -0
  3. package/dist/bin/vip-app-list.js +0 -12
  4. package/dist/bin/vip-app.js +6 -13
  5. package/dist/bin/vip-cache-purge-url.js +4 -19
  6. package/dist/bin/vip-cache.js +0 -2
  7. package/dist/bin/vip-config-envvar-delete.js +4 -19
  8. package/dist/bin/vip-config-envvar-get-all.js +6 -19
  9. package/dist/bin/vip-config-envvar-get.js +4 -15
  10. package/dist/bin/vip-config-envvar-list.js +8 -20
  11. package/dist/bin/vip-config-envvar-set.js +4 -23
  12. package/dist/bin/vip-config-envvar.js +0 -2
  13. package/dist/bin/vip-config-software-get.js +0 -17
  14. package/dist/bin/vip-config-software-update.js +6 -22
  15. package/dist/bin/vip-config-software.js +0 -2
  16. package/dist/bin/vip-config.js +0 -2
  17. package/dist/bin/vip-dev-env-create.js +0 -18
  18. package/dist/bin/vip-dev-env-destroy.js +0 -9
  19. package/dist/bin/vip-dev-env-exec.js +0 -12
  20. package/dist/bin/vip-dev-env-import-media.js +0 -7
  21. package/dist/bin/vip-dev-env-import-sql.js +2 -17
  22. package/dist/bin/vip-dev-env-import.js +0 -3
  23. package/dist/bin/vip-dev-env-info.js +0 -10
  24. package/dist/bin/vip-dev-env-list.js +0 -7
  25. package/dist/bin/vip-dev-env-start.js +4 -14
  26. package/dist/bin/vip-dev-env-stop.js +0 -9
  27. package/dist/bin/vip-dev-env-update.js +0 -11
  28. package/dist/bin/vip-dev-env.js +0 -2
  29. package/dist/bin/vip-import-media-abort.js +0 -18
  30. package/dist/bin/vip-import-media-status.js +0 -12
  31. package/dist/bin/vip-import-media.js +6 -23
  32. package/dist/bin/vip-import-sql-status.js +0 -12
  33. package/dist/bin/vip-import-sql.js +33 -99
  34. package/dist/bin/vip-import-validate-files.js +21 -42
  35. package/dist/bin/vip-import-validate-sql.js +0 -8
  36. package/dist/bin/vip-import.js +0 -3
  37. package/dist/bin/vip-logs.js +20 -50
  38. package/dist/bin/vip-search-replace.js +8 -14
  39. package/dist/bin/vip-sync.js +2 -25
  40. package/dist/bin/vip-validate-preflight.js +427 -0
  41. package/dist/bin/vip-validate.js +19 -0
  42. package/dist/bin/vip-whoami.js +2 -14
  43. package/dist/bin/vip-wp.js +39 -89
  44. package/dist/bin/vip.js +5 -35
  45. package/dist/lib/analytics/clients/pendo.js +9 -18
  46. package/dist/lib/analytics/clients/stub.js +1 -3
  47. package/dist/lib/analytics/clients/tracks.js +11 -20
  48. package/dist/lib/analytics/index.js +4 -11
  49. package/dist/lib/api/app.js +1 -11
  50. package/dist/lib/api/cache-purge.js +4 -7
  51. package/dist/lib/api/feature-flags.js +1 -4
  52. package/dist/lib/api/http.js +9 -15
  53. package/dist/lib/api/user.js +1 -7
  54. package/dist/lib/api.js +7 -18
  55. package/dist/lib/app-logs/app-logs.js +2 -9
  56. package/dist/lib/app.js +2 -5
  57. package/dist/lib/cli/apiConfig.js +4 -19
  58. package/dist/lib/cli/command.js +43 -133
  59. package/dist/lib/cli/config.js +1 -5
  60. package/dist/lib/cli/envAlias.js +14 -15
  61. package/dist/lib/cli/exit.js +4 -6
  62. package/dist/lib/cli/format.js +8 -50
  63. package/dist/lib/cli/progress.js +13 -42
  64. package/dist/lib/cli/prompt.js +1 -5
  65. package/dist/lib/cli/repo.js +7 -20
  66. package/dist/lib/client-file-uploader.js +44 -97
  67. package/dist/lib/config/software.js +2 -52
  68. package/dist/lib/constants/dev-environment.js +1 -2
  69. package/dist/lib/constants/file-size.js +1 -1
  70. package/dist/lib/constants/vipgo.js +1 -1
  71. package/dist/lib/dev-environment/dev-environment-cli.js +31 -134
  72. package/dist/lib/dev-environment/dev-environment-core.js +63 -171
  73. package/dist/lib/dev-environment/dev-environment-lando.js +16 -71
  74. package/dist/lib/env.js +1 -4
  75. package/dist/lib/envvar/api-delete.js +1 -4
  76. package/dist/lib/envvar/api-get-all.js +1 -4
  77. package/dist/lib/envvar/api-get.js +1 -2
  78. package/dist/lib/envvar/api-list.js +3 -4
  79. package/dist/lib/envvar/api-set.js +1 -4
  80. package/dist/lib/envvar/api.js +5 -16
  81. package/dist/lib/envvar/input.js +1 -8
  82. package/dist/lib/envvar/logging.js +2 -6
  83. package/dist/lib/envvar/read-file.js +1 -3
  84. package/dist/lib/http/proxy-agent.js +17 -22
  85. package/dist/lib/keychain/browser.js +1 -4
  86. package/dist/lib/keychain/insecure.js +1 -10
  87. package/dist/lib/keychain/secure.js +1 -8
  88. package/dist/lib/keychain.js +4 -8
  89. package/dist/lib/logout.js +0 -6
  90. package/dist/lib/media-import/media-file-import.js +3 -7
  91. package/dist/lib/media-import/progress.js +6 -17
  92. package/dist/lib/media-import/status.js +14 -65
  93. package/dist/lib/read-file.js +1 -6
  94. package/dist/lib/rollbar.js +1 -7
  95. package/dist/lib/search-and-replace.js +9 -41
  96. package/dist/lib/site-import/db-file-import.js +3 -9
  97. package/dist/lib/site-import/status.js +17 -74
  98. package/dist/lib/token.js +1 -33
  99. package/dist/lib/tracker.js +4 -20
  100. package/dist/lib/user-error.js +0 -2
  101. package/dist/lib/validations/is-multi-site-sql-dump.js +4 -12
  102. package/dist/lib/validations/is-multi-site.js +5 -21
  103. package/dist/lib/validations/is-multisite-domain-mapped.js +5 -31
  104. package/dist/lib/validations/line-by-line.js +4 -16
  105. package/dist/lib/validations/site-type.js +10 -19
  106. package/dist/lib/validations/sql.js +11 -76
  107. package/dist/lib/validations/utils.js +1 -6
  108. package/dist/lib/vip-import-validate-files.js +82 -109
  109. package/npm-shrinkwrap.json +837 -67
  110. package/package.json +4 -1
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.readFromFile = readFromFile;
7
-
8
7
  var _fs = require("fs");
9
-
10
8
  var exit = _interopRequireWildcard(require("./cli/exit"));
11
-
12
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); }
13
-
14
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; }
15
-
16
11
  /**
17
12
  *
18
13
  * @format
@@ -25,6 +20,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
25
20
  /**
26
21
  * Internal dependencies
27
22
  */
23
+
28
24
  async function readFromFile(path) {
29
25
  const data = await _fs.promises.readFile(path, 'binary').catch(({
30
26
  message
@@ -33,7 +29,6 @@ async function readFromFile(path) {
33
29
  if (message.startsWith('ENOENT: no such file or directory')) {
34
30
  exit.withError(`Could not load file ${JSON.stringify(path)}.`);
35
31
  }
36
-
37
32
  exit.withError(message);
38
33
  });
39
34
  return Buffer.from(data).toString().trim();
@@ -4,23 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.rollbar = void 0;
7
-
8
7
  var _env = _interopRequireDefault(require("./env"));
9
-
10
8
  var _config = _interopRequireDefault(require("./cli/config"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  /**
15
11
  * Internal dependencies
16
12
  */
17
- const Rollbar = require('rollbar');
18
13
 
14
+ const Rollbar = require('rollbar');
19
15
  const rollbar = new Rollbar({
20
16
  accessToken: '99c8f982d64f47049fde6f6f9d567070',
21
17
  captureUncaught: true,
22
18
  captureUnhandledRejections: true,
23
-
24
19
  /* eslint-disable camelcase */
25
20
  payload: {
26
21
  platform: 'client',
@@ -30,6 +25,5 @@ const rollbar = new Rollbar({
30
25
  environment: _config.default.environment
31
26
  }
32
27
  /* eslint-enable camelcase */
33
-
34
28
  });
35
29
  exports.rollbar = rollbar;
@@ -5,33 +5,19 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getReadAndWriteStreams = getReadAndWriteStreams;
7
7
  exports.searchAndReplace = void 0;
8
-
9
8
  var _fs = _interopRequireDefault(require("fs"));
10
-
11
9
  var _os = _interopRequireDefault(require("os"));
12
-
13
10
  var _path = _interopRequireDefault(require("path"));
14
-
15
11
  var _chalk = _interopRequireDefault(require("chalk"));
16
-
17
12
  var _debug = _interopRequireDefault(require("debug"));
18
-
19
13
  var _vipSearchReplace = require("@automattic/vip-search-replace");
20
-
21
14
  var _tracker = require("./tracker");
22
-
23
15
  var _prompt = require("./cli/prompt");
24
-
25
16
  var _clientFileUploader = require("./client-file-uploader");
26
-
27
17
  var exit = _interopRequireWildcard(require("./cli/exit"));
28
-
29
18
  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); }
30
-
31
19
  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; }
32
-
33
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
34
-
35
21
  /**
36
22
  *
37
23
  * @format
@@ -44,21 +30,18 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
44
30
  /**
45
31
  * Internal dependencies
46
32
  */
47
- const debug = (0, _debug.default)('@automattic/vip:lib:search-and-replace');
48
33
 
34
+ const debug = (0, _debug.default)('@automattic/vip:lib:search-and-replace');
49
35
  const flatten = arr => {
50
36
  return arr.reduce((flat, toFlatten) => {
51
37
  return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
52
38
  }, []);
53
39
  };
54
-
55
40
  function makeTempDir() {
56
41
  const tmpDir = _fs.default.mkdtempSync(_path.default.join(_os.default.tmpdir(), 'vip-search-replace-'));
57
-
58
42
  debug(`Created a directory to hold temporary files: ${tmpDir}`);
59
43
  return tmpDir;
60
44
  }
61
-
62
45
  function getReadAndWriteStreams({
63
46
  fileName,
64
47
  inPlace,
@@ -67,12 +50,9 @@ function getReadAndWriteStreams({
67
50
  let writeStream;
68
51
  let usingStdOut = false;
69
52
  let outputFileName;
70
-
71
53
  if (inPlace) {
72
54
  const midputFileName = _path.default.join(makeTempDir(), _path.default.basename(fileName));
73
-
74
55
  _fs.default.copyFileSync(fileName, midputFileName);
75
-
76
56
  debug(`Copied input file to ${midputFileName}`);
77
57
  debug(`Set output to the original file path ${fileName}`);
78
58
  outputFileName = fileName;
@@ -83,37 +63,29 @@ function getReadAndWriteStreams({
83
63
  writeStream: _fs.default.createWriteStream(fileName)
84
64
  };
85
65
  }
86
-
87
66
  debug(`Reading input from file: ${fileName}`);
88
-
89
67
  switch (typeof output) {
90
68
  case 'string':
91
69
  writeStream = _fs.default.createWriteStream(output);
92
70
  outputFileName = output;
93
71
  debug(`Outputting to file: ${outputFileName}`);
94
72
  break;
95
-
96
73
  case 'object':
97
74
  writeStream = output;
98
-
99
75
  if (writeStream === process.stdout) {
100
76
  usingStdOut = true;
101
77
  debug('Outputting to the standard output stream');
102
78
  } else {
103
79
  debug('Outputting to the provided output stream');
104
80
  }
105
-
106
81
  break;
107
-
108
82
  default:
109
83
  const tmpOutFile = _path.default.join(makeTempDir(), _path.default.basename(fileName));
110
-
111
84
  writeStream = _fs.default.createWriteStream(tmpOutFile);
112
85
  outputFileName = tmpOutFile;
113
86
  debug(`Outputting to file: ${outputFileName}`);
114
87
  break;
115
88
  }
116
-
117
89
  return {
118
90
  outputFileName,
119
91
  readStream: _fs.default.createReadStream(fileName),
@@ -121,7 +93,6 @@ function getReadAndWriteStreams({
121
93
  writeStream
122
94
  };
123
95
  }
124
-
125
96
  const searchAndReplace = async (fileName, pairs, {
126
97
  isImport = true,
127
98
  inPlace = false,
@@ -132,25 +103,26 @@ const searchAndReplace = async (fileName, pairs, {
132
103
  in_place: inPlace
133
104
  });
134
105
  const startTime = process.hrtime();
135
- const fileSize = (0, _clientFileUploader.getFileSize)(fileName); // if we don't have any pairs to replace with, return the input file
106
+ const fileSize = (0, _clientFileUploader.getFileSize)(fileName);
136
107
 
108
+ // if we don't have any pairs to replace with, return the input file
137
109
  if (!pairs || !pairs.length) {
138
110
  throw new Error('No search and replace parameters provided.');
139
- } // If only one pair is provided, ensure we have an array
140
-
111
+ }
141
112
 
113
+ // If only one pair is provided, ensure we have an array
142
114
  if (!Array.isArray(pairs)) {
143
115
  pairs = [pairs];
144
- } // determine all the replacements required
145
-
116
+ }
146
117
 
118
+ // determine all the replacements required
147
119
  const replacementsArr = pairs.map(pair => pair.split(',').map(str => str.trim()));
148
120
  const replacements = flatten(replacementsArr);
149
121
  debug('Pairs: ', pairs, 'Replacements: ', replacements);
150
-
151
122
  if (inPlace) {
152
- 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.'); // Bail if user does not wish to proceed
123
+ 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.');
153
124
 
125
+ // Bail if user does not wish to proceed
154
126
  if (!approved) {
155
127
  await (0, _tracker.trackEvent)('search_replace_in_place_cancelled', {
156
128
  is_import: isImport,
@@ -159,7 +131,6 @@ const searchAndReplace = async (fileName, pairs, {
159
131
  process.exit();
160
132
  }
161
133
  }
162
-
163
134
  const {
164
135
  usingStdOut,
165
136
  outputFileName,
@@ -171,13 +142,11 @@ const searchAndReplace = async (fileName, pairs, {
171
142
  output
172
143
  });
173
144
  let replacedStream;
174
-
175
145
  try {
176
146
  replacedStream = await (0, _vipSearchReplace.replace)(readStream, replacements, binary);
177
147
  } catch (replaceError) {
178
148
  exit.withError(replaceError);
179
149
  }
180
-
181
150
  const result = await new Promise((resolve, reject) => {
182
151
  replacedStream.pipe(writeStream).on('finish', () => {
183
152
  resolve({
@@ -199,5 +168,4 @@ const searchAndReplace = async (fileName, pairs, {
199
168
  });
200
169
  return result;
201
170
  };
202
-
203
171
  exports.searchAndReplace = searchAndReplace;
@@ -3,11 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.SYNC_STATUS_NOT_SYNCING = exports.SUPPORTED_DB_FILE_IMPORT_SITE_TYPES = exports.SQL_IMPORT_FILE_SIZE_LIMIT_LAUNCHED = exports.SQL_IMPORT_FILE_SIZE_LIMIT = void 0;
6
7
  exports.currentUserCanImportForApp = currentUserCanImportForApp;
7
- exports.isImportingBlockedBySync = exports.SYNC_STATUS_NOT_SYNCING = exports.isSupportedApp = exports.SUPPORTED_DB_FILE_IMPORT_SITE_TYPES = exports.SQL_IMPORT_FILE_SIZE_LIMIT_LAUNCHED = exports.SQL_IMPORT_FILE_SIZE_LIMIT = void 0;
8
-
8
+ exports.isSupportedApp = exports.isImportingBlockedBySync = void 0;
9
9
  var _fileSize = require("../constants/file-size");
10
-
11
10
  /**
12
11
  *
13
12
  * @format
@@ -16,31 +15,26 @@ var _fileSize = require("../constants/file-size");
16
15
  /**
17
16
  * Internal dependencies
18
17
  */
18
+
19
19
  const SQL_IMPORT_FILE_SIZE_LIMIT = 100 * _fileSize.GB_IN_BYTES;
20
20
  exports.SQL_IMPORT_FILE_SIZE_LIMIT = SQL_IMPORT_FILE_SIZE_LIMIT;
21
21
  const SQL_IMPORT_FILE_SIZE_LIMIT_LAUNCHED = 5 * _fileSize.GB_IN_BYTES;
22
22
  exports.SQL_IMPORT_FILE_SIZE_LIMIT_LAUNCHED = SQL_IMPORT_FILE_SIZE_LIMIT_LAUNCHED;
23
-
24
23
  function currentUserCanImportForApp(app) {
25
24
  // TODO: implement
26
25
  return !!app;
27
26
  }
28
-
29
27
  const SUPPORTED_DB_FILE_IMPORT_SITE_TYPES = ['WordPress'];
30
28
  exports.SUPPORTED_DB_FILE_IMPORT_SITE_TYPES = SUPPORTED_DB_FILE_IMPORT_SITE_TYPES;
31
-
32
29
  const isSupportedApp = ({
33
30
  type
34
31
  }) => SUPPORTED_DB_FILE_IMPORT_SITE_TYPES.includes(type);
35
-
36
32
  exports.isSupportedApp = isSupportedApp;
37
33
  const SYNC_STATUS_NOT_SYNCING = 'not_syncing';
38
34
  exports.SYNC_STATUS_NOT_SYNCING = SYNC_STATUS_NOT_SYNCING;
39
-
40
35
  const isImportingBlockedBySync = ({
41
36
  syncProgress: {
42
37
  status
43
38
  }
44
39
  }) => status !== SYNC_STATUS_NOT_SYNCING;
45
-
46
40
  exports.isImportingBlockedBySync = isImportingBlockedBySync;
@@ -3,31 +3,19 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.importSqlCheckStatus = importSqlCheckStatus;
7
6
  exports.default = void 0;
8
-
7
+ exports.importSqlCheckStatus = importSqlCheckStatus;
9
8
  var _chalk = _interopRequireDefault(require("chalk"));
10
-
11
9
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
12
-
13
10
  var _debug = _interopRequireDefault(require("debug"));
14
-
15
11
  var _api = _interopRequireDefault(require("../api"));
16
-
17
12
  var _dbFileImport = require("./db-file-import");
18
-
19
13
  var _progress = require("../cli/progress");
20
-
21
14
  var exit = _interopRequireWildcard(require("../cli/exit"));
22
-
23
15
  var _format = require("../cli/format");
24
-
25
16
  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); }
26
-
27
17
  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; }
28
-
29
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
-
31
19
  /**
32
20
  *
33
21
  * @format
@@ -40,6 +28,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
40
28
  /**
41
29
  * Internal dependencies
42
30
  */
31
+
43
32
  const debug = (0, _debug.default)('vip:lib/site-import/status');
44
33
  const IMPORT_SQL_PROGRESS_POLL_INTERVAL = 5000;
45
34
  const IMPORT_SQL_PROGRESS_QUERY = (0, _graphqlTag.default)`
@@ -82,7 +71,6 @@ const IMPORT_SQL_PROGRESS_QUERY = (0, _graphqlTag.default)`
82
71
  }
83
72
  }
84
73
  `;
85
-
86
74
  async function getStatus(api, appId, envId) {
87
75
  const response = await api.query({
88
76
  query: IMPORT_SQL_PROGRESS_QUERY,
@@ -99,22 +87,18 @@ async function getStatus(api, appId, envId) {
99
87
  }
100
88
  }
101
89
  } = response;
102
-
103
90
  if (!(environments !== null && environments !== void 0 && environments.length)) {
104
91
  throw new Error('Unable to determine import status from environment');
105
92
  }
106
-
107
93
  const [environment] = environments;
108
94
  const {
109
95
  importStatus,
110
96
  jobs,
111
97
  launched
112
98
  } = environment;
113
-
114
99
  if (!environment.isK8sResident && !(jobs !== null && jobs !== void 0 && jobs.length)) {
115
100
  return {};
116
101
  }
117
-
118
102
  const [importJob] = jobs;
119
103
  return {
120
104
  importStatus,
@@ -122,7 +106,6 @@ async function getStatus(api, appId, envId) {
122
106
  launched
123
107
  };
124
108
  }
125
-
126
109
  function getErrorMessage(importFailed, launched = false) {
127
110
  debug({
128
111
  importFailed
@@ -130,7 +113,6 @@ function getErrorMessage(importFailed, launched = false) {
130
113
  const rollbackMessage = launched ? '' : `Your site is ${_chalk.default.blue('automatically being rolled back')} to the last backup prior to your import job.
131
114
  `;
132
115
  let message = importFailed.error;
133
-
134
116
  if (importFailed.inImportProgress) {
135
117
  switch (importFailed.stepName) {
136
118
  case 'import_preflights':
@@ -142,13 +124,11 @@ Your site content was not altered.
142
124
  If this error persists, please contact support.
143
125
  `;
144
126
  break;
145
-
146
127
  case 'importing_db':
147
128
  message += `
148
129
  This error occurred during the mysql batch script processing of your SQL file.
149
130
 
150
131
  ${rollbackMessage}`;
151
-
152
132
  if (importFailed.commandOutput) {
153
133
  const commandOutput = [].concat(importFailed.commandOutput).join(';');
154
134
  message += `
@@ -159,15 +139,12 @@ The server said:
159
139
  } else {
160
140
  message += 'Please contact support and include this message along with your sql file.';
161
141
  }
162
-
163
142
  break;
164
-
165
143
  case 'validating_db':
166
144
  message += `\nThis error occurred during the post-import validation of the imported data.
167
145
 
168
146
  ${rollbackMessage}
169
147
  `;
170
-
171
148
  if (importFailed.commandOutput) {
172
149
  const commandOutput = [].concat(importFailed.commandOutput).join(';');
173
150
  message += `
@@ -178,58 +155,47 @@ The server said:
178
155
  } else {
179
156
  message += 'Please contact support and include this message along with your sql file.';
180
157
  }
181
-
182
158
  break;
183
-
184
159
  default:
185
160
  }
186
161
  }
187
-
188
162
  return message;
189
163
  }
190
-
191
164
  async function importSqlCheckStatus({
192
165
  app,
193
166
  env,
194
167
  progressTracker
195
168
  }) {
196
169
  // Stop printing so we can pass our callback
197
- progressTracker.stopPrinting(); // NO `console.log` in this function (until results are final)! It will break the progress printing.
170
+ progressTracker.stopPrinting();
198
171
 
172
+ // NO `console.log` in this function (until results are final)! It will break the progress printing.
199
173
  const api = await (0, _api.default)();
200
-
201
174
  if (!(0, _dbFileImport.currentUserCanImportForApp)(app)) {
202
175
  throw new Error('The currently authenticated account does not have permission to view SQL import status.');
203
176
  }
204
-
205
177
  let createdAt;
206
178
  let completedAt;
207
179
  let overallStatus = 'Checking...';
208
-
209
180
  const setProgressTrackerSuffix = () => {
210
181
  const sprite = (0, _format.getGlyphForStatus)(overallStatus, progressTracker.runningSprite);
211
182
  const formattedCreatedAt = createdAt ? `${new Date(createdAt).toLocaleString()} (${createdAt})` : 'TBD';
212
183
  const formattedCompletedAt = createdAt && completedAt ? `${new Date(completedAt).toLocaleString()} (${completedAt})` : 'TBD';
213
184
  const exitPrompt = '(Press ^C to hide progress. The import will continue in the background.)';
214
185
  let statusMessage;
215
-
216
186
  switch (overallStatus) {
217
187
  case 'success':
218
188
  statusMessage = `Success ${sprite} imported data should be visible on your site ${env.primaryDomain.name}.`;
219
189
  break;
220
-
221
190
  case 'running':
222
191
  if (progressTracker.allStepsSucceeded()) {
223
192
  statusMessage = `Finishing up... ${sprite} `;
224
193
  break;
225
194
  }
226
-
227
195
  // Intentionally no break to get default case:
228
-
229
196
  default:
230
197
  statusMessage = `${(0, _format.capitalize)(overallStatus)} ${sprite}`;
231
198
  }
232
-
233
199
  const maybeExitPrompt = `${overallStatus === 'running' ? exitPrompt : ''}`;
234
200
  const jobCreateCompleteTimestamps = `
235
201
  SQL Import Started: ${formattedCreatedAt}
@@ -244,20 +210,15 @@ ${maybeExitPrompt}
244
210
  `;
245
211
  progressTracker.suffix = suffix;
246
212
  };
247
-
248
213
  const setSuffixAndPrint = () => {
249
214
  setProgressTrackerSuffix();
250
215
  progressTracker.print();
251
216
  };
252
-
253
217
  progressTracker.startPrinting(setSuffixAndPrint);
254
-
255
218
  const getResults = () => new Promise((resolve, reject) => {
256
219
  const checkStatus = async () => {
257
220
  var _importJob$progress$s, _importJob$progress, _importJob$progress$s2, _importJob$progress2;
258
-
259
221
  let status;
260
-
261
222
  try {
262
223
  status = await getStatus(api, app.id, env.id);
263
224
  } catch (error) {
@@ -265,7 +226,6 @@ ${maybeExitPrompt}
265
226
  error
266
227
  });
267
228
  }
268
-
269
229
  const {
270
230
  importStatus,
271
231
  launched
@@ -274,21 +234,19 @@ ${maybeExitPrompt}
274
234
  importJob
275
235
  } = status;
276
236
  let jobStatus,
277
- jobSteps = [];
278
-
237
+ jobSteps = [];
279
238
  if (env.isK8sResident) {
280
239
  // in the future the API may provide this in k8s jobs so account for that.
281
240
  // Until then we need to create the importJob from the status object.
282
241
  if (!importJob) {
283
242
  var _importStatus$progres, _importStatus$progres2;
284
-
285
243
  importJob = {};
286
- const statusSteps = importStatus === null || importStatus === void 0 ? void 0 : (_importStatus$progres = importStatus.progress) === null || _importStatus$progres === void 0 ? void 0 : _importStatus$progres.steps; // if the progress meta isn't filled out yet, wait until it is.
244
+ const statusSteps = importStatus === null || importStatus === void 0 ? void 0 : (_importStatus$progres = importStatus.progress) === null || _importStatus$progres === void 0 ? void 0 : _importStatus$progres.steps;
287
245
 
246
+ // if the progress meta isn't filled out yet, wait until it is.
288
247
  if (!statusSteps) {
289
248
  return setTimeout(checkStatus, IMPORT_SQL_PROGRESS_POLL_INTERVAL);
290
249
  }
291
-
292
250
  jobSteps = statusSteps.map(step => {
293
251
  return {
294
252
  id: step.name,
@@ -296,7 +254,6 @@ ${maybeExitPrompt}
296
254
  status: step.result
297
255
  };
298
256
  });
299
-
300
257
  if (statusSteps.some(({
301
258
  result
302
259
  }) => result === 'failed') && !statusSteps.find(({
@@ -310,11 +267,9 @@ ${maybeExitPrompt}
310
267
  jobStatus = 'success';
311
268
  importJob.completedAt = new Date(Math.max(...statusSteps.map(step => step.finished_at), 0) * 1000).toUTCString();
312
269
  }
313
-
314
270
  if (importStatus !== null && importStatus !== void 0 && (_importStatus$progres2 = importStatus.progress) !== null && _importStatus$progres2 !== void 0 && _importStatus$progres2.started_at) {
315
271
  importJob.createdAt = new Date(importStatus.progress.started_at * 1000).toUTCString();
316
272
  }
317
-
318
273
  importJob.progress = {
319
274
  status: jobStatus,
320
275
  steps: jobSteps
@@ -323,7 +278,6 @@ ${maybeExitPrompt}
323
278
  } else if (!importJob) {
324
279
  return resolve('No import job found');
325
280
  }
326
-
327
281
  jobStatus = (_importJob$progress$s = (_importJob$progress = importJob.progress) === null || _importJob$progress === void 0 ? void 0 : _importJob$progress.status) !== null && _importJob$progress$s !== void 0 ? _importJob$progress$s : 'unknown';
328
282
  jobSteps = (_importJob$progress$s2 = (_importJob$progress2 = importJob.progress) === null || _importJob$progress2 === void 0 ? void 0 : _importJob$progress2.steps) !== null && _importJob$progress$s2 !== void 0 ? _importJob$progress$s2 : [];
329
283
  createdAt = importJob.createdAt;
@@ -342,36 +296,30 @@ ${maybeExitPrompt}
342
296
  importStepProgress
343
297
  });
344
298
  let jobCreationTime;
345
-
346
299
  try {
347
300
  jobCreationTime = new Date(createdAt).getTime();
348
301
  } catch (err) {
349
302
  debug('Unable to parse createdAt to a Date');
350
303
  }
351
-
352
304
  let failedImportStep;
353
-
354
305
  if (jobCreationTime && (importStepProgress === null || importStepProgress === void 0 ? void 0 : importStepProgress.started_at) * 1000 >= jobCreationTime) {
355
306
  // The contents of the `import_progress` meta are pertinent to the most recent import job
356
307
  failedImportStep = importStepProgress.steps.find(step => (step === null || step === void 0 ? void 0 : step.result) === 'failed' && 1000 * (step === null || step === void 0 ? void 0 : step.started_at) > new Date(createdAt).getTime());
357
308
  }
358
-
359
309
  if (!jobSteps.length) {
360
310
  return reject({
361
311
  error: 'Could not enumerate the import job steps',
362
312
  launched
363
313
  });
364
314
  }
365
-
366
315
  if (failedImportStep) {
367
316
  // The server marks the step as a success as per the host action, demote it to 'failed'
368
317
  const _jobSteps = [...jobSteps];
369
-
370
318
  const failedJobStepIndex = _jobSteps.findIndex(({
371
319
  id
372
320
  }) => id === 'import');
373
-
374
- _jobSteps[failedJobStepIndex] = { ..._jobSteps[failedJobStepIndex],
321
+ _jobSteps[failedJobStepIndex] = {
322
+ ..._jobSteps[failedJobStepIndex],
375
323
  status: 'failed'
376
324
  };
377
325
  progressTracker.setStepsFromServer(_jobSteps);
@@ -386,10 +334,8 @@ ${maybeExitPrompt}
386
334
  launched
387
335
  });
388
336
  }
389
-
390
337
  progressTracker.setStepsFromServer(jobSteps);
391
338
  setSuffixAndPrint();
392
-
393
339
  if (jobStatus === 'error') {
394
340
  return reject({
395
341
  error: 'Import job failed',
@@ -397,37 +343,35 @@ ${maybeExitPrompt}
397
343
  launched
398
344
  });
399
345
  }
400
-
401
346
  if (jobStatus !== 'running' && completedAt) {
402
347
  return resolve(importJob);
403
348
  }
404
-
405
349
  overallStatus = 'running';
406
350
  setTimeout(checkStatus, IMPORT_SQL_PROGRESS_POLL_INTERVAL);
407
- }; // Kick off the check
408
-
351
+ };
409
352
 
353
+ // Kick off the check
410
354
  checkStatus();
411
355
  });
412
-
413
356
  try {
414
357
  const results = await getResults();
415
-
416
358
  if (typeof results === 'string') {
417
359
  overallStatus = results;
418
360
  } else {
419
361
  var _results$progress;
420
-
421
- overallStatus = (results === null || results === void 0 ? void 0 : (_results$progress = results.progress) === null || _results$progress === void 0 ? void 0 : _results$progress.status) || 'unknown'; // This shouldn't be 'unknown'...what should we do here?
362
+ overallStatus = (results === null || results === void 0 ? void 0 : (_results$progress = results.progress) === null || _results$progress === void 0 ? void 0 : _results$progress.status) || 'unknown';
363
+ // This shouldn't be 'unknown'...what should we do here?
422
364
  }
423
365
 
424
366
  progressTracker.stopPrinting();
425
- setProgressTrackerSuffix(); // Print one final time
367
+ setProgressTrackerSuffix();
426
368
 
369
+ // Print one final time
427
370
  progressTracker.print({
428
371
  clearAfter: true
429
- }); // This type of result is not an importing error. e.g. no import job was found
372
+ });
430
373
 
374
+ // This type of result is not an importing error. e.g. no import job was found
431
375
  process.exit(0);
432
376
  } catch (importFailed) {
433
377
  progressTracker.stopPrinting();
@@ -437,7 +381,6 @@ ${maybeExitPrompt}
437
381
  exit.withError(getErrorMessage(importFailed, importFailed.launched));
438
382
  }
439
383
  }
440
-
441
384
  var _default = {
442
385
  importSqlCheckStatus
443
386
  };