@automattic/vip 2.27.0-dev5 → 2.27.0-dev7

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.
Binary file
@@ -17,5 +17,5 @@
17
17
  var _command = _interopRequireDefault(require("../lib/cli/command"));
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
  (0, _command.default)({
20
- requiredArgs: 2
20
+ requiredArgs: 1
21
21
  }).command('purge-url', 'Purge page cache').argv(process.argv);
@@ -17,5 +17,5 @@
17
17
  var _command = _interopRequireDefault(require("../lib/cli/command"));
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
  (0, _command.default)({
20
- requiredArgs: 1
20
+ requiredArgs: 0
21
21
  }).command('delete', 'Permanently delete an environment variable').command('get', 'Get the value of an environment variable').command('get-all', 'Get the values of all environment variable').command('list', 'List the names of all environment variables').command('set', 'Add or update an environment variable').argv(process.argv);
@@ -20,6 +20,7 @@ var _devEnvironmentLando = require("../lib/dev-environment/dev-environment-lando
20
20
  var _userError = _interopRequireDefault(require("../lib/user-error"));
21
21
  var _devEnvSyncSql = require("../commands/dev-env-sync-sql");
22
22
  var _devEnvironment = require("../lib/constants/dev-environment");
23
+ var _tracker = require("../lib/tracker");
23
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
25
  const examples = [{
25
26
  usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} sync sql @my-test.develop --slug=my_site`,
@@ -50,11 +51,21 @@ const appQuery = `
50
51
  env,
51
52
  slug
52
53
  }) => {
54
+ const trackerFn = (0, _tracker.makeCommandTracker)('dev_env_sync_sql', {
55
+ app: app.id,
56
+ env: env.uniqueLabel,
57
+ slug
58
+ });
59
+ await trackerFn('execute');
53
60
  const lando = await (0, _devEnvironmentLando.bootstrapLando)();
54
61
  const envPath = (0, _devEnvironmentCore.getEnvironmentPath)(slug);
55
62
  if (!(await (0, _devEnvironmentLando.isEnvUp)(lando, envPath))) {
63
+ await trackerFn('env_not_running_error', {
64
+ errorMessage: 'Environment was not running'
65
+ });
56
66
  throw new _userError.default('Environment needs to be started first');
57
67
  }
58
- const cmd = new _devEnvSyncSql.DevEnvSyncSQLCommand(app, env, slug);
68
+ const cmd = new _devEnvSyncSql.DevEnvSyncSQLCommand(app, env, slug, trackerFn);
59
69
  await cmd.run();
70
+ await trackerFn('success');
60
71
  });
@@ -13,7 +13,7 @@ var _command = _interopRequireDefault(require("../lib/cli/command"));
13
13
  var _tracker = require("../lib/tracker");
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
  (0, _command.default)({
16
- requiredArgs: 1
16
+ requiredArgs: 0
17
17
  }).command('preflight', 'Runs preflight tests to validate if your application is ready to be deployed').argv(process.argv, async () => {
18
18
  await (0, _tracker.trackEvent)('vip_validate_command_execute');
19
19
  });
@@ -73,14 +73,16 @@ class DevEnvSyncSQLCommand {
73
73
  /**
74
74
  * Creates a new instance of the command
75
75
  *
76
- * @param {string} app The app object
77
- * @param {string} env The environment object
78
- * @param {string} slug The site slug
76
+ * @param {string} app The app object
77
+ * @param {string} env The environment object
78
+ * @param {string} slug The site slug
79
+ * @param {Function} trackerFn Function to call for tracking
79
80
  */
80
- constructor(app, env, slug) {
81
+ constructor(app, env, slug, trackerFn = () => {}) {
81
82
  this.app = app;
82
83
  this.env = env;
83
84
  this.slug = slug;
85
+ this.track = trackerFn;
84
86
  this.tmpDir = (0, _utils.makeTempDir)();
85
87
  }
86
88
  get landoDomain() {
@@ -100,7 +102,7 @@ class DevEnvSyncSQLCommand {
100
102
  * @return {Promise<void>} Promise that resolves when the export is complete
101
103
  */
102
104
  async generateExport() {
103
- const exportCommand = new _exportSql.ExportSQLCommand(this.app, this.env, this.gzFile);
105
+ const exportCommand = new _exportSql.ExportSQLCommand(this.app, this.env, this.gzFile, this.track);
104
106
  await exportCommand.run();
105
107
  }
106
108
 
@@ -158,6 +160,9 @@ class DevEnvSyncSQLCommand {
158
160
  await (0, _clientFileUploader.unzipFile)(this.gzFile, this.sqlFile);
159
161
  console.log(`${_chalk.default.green('✓')} Extracted to ${this.sqlFile}`);
160
162
  } catch (err) {
163
+ await this.track('archive_extraction_error', {
164
+ errorMessage: err === null || err === void 0 ? void 0 : err.message
165
+ });
161
166
  exit.withError(`Error extracting the SQL export: ${err === null || err === void 0 ? void 0 : err.message}`);
162
167
  }
163
168
  try {
@@ -174,6 +179,9 @@ class DevEnvSyncSQLCommand {
174
179
  await this.runSearchReplace();
175
180
  console.log(`${_chalk.default.green('✓')} Search-replace operation is complete`);
176
181
  } catch (err) {
182
+ await this.track('search_replace_error', {
183
+ errorMessage: err === null || err === void 0 ? void 0 : err.message
184
+ });
177
185
  exit.withError(`Error replacing domains: ${err === null || err === void 0 ? void 0 : err.message}`);
178
186
  }
179
187
  try {
@@ -181,6 +189,9 @@ class DevEnvSyncSQLCommand {
181
189
  await this.runImport();
182
190
  console.log(`${_chalk.default.green('✓')} SQL file imported`);
183
191
  } catch (err) {
192
+ await this.track('import_error', {
193
+ errorMessage: err === null || err === void 0 ? void 0 : err.message
194
+ });
184
195
  exit.withError(`Error importing SQL file: ${err === null || err === void 0 ? void 0 : err.message}`);
185
196
  }
186
197
  }
@@ -8,7 +8,7 @@ var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
8
8
  var _fs = _interopRequireDefault(require("fs"));
9
9
  var _https = _interopRequireDefault(require("https"));
10
10
  var _path = _interopRequireDefault(require("path"));
11
- var _api = _interopRequireDefault(require("../lib/api"));
11
+ var _api = _interopRequireWildcard(require("../lib/api"));
12
12
  var _format = require("../lib/cli/format");
13
13
  var _progress = require("../lib/cli/progress");
14
14
  var exit = _interopRequireWildcard(require("../lib/cli/exit"));
@@ -162,8 +162,10 @@ async function generateDownloadLink(appId, envId, backupId) {
162
162
  * @throws {Error} Throws an error if the job creation fails
163
163
  */
164
164
  async function createExportJob(appId, envId, backupId) {
165
+ // Disable global error handling so that we can handle errors ourselves
166
+ (0, _api.disableGlobalGraphQLErrorHandling)();
165
167
  const api = await (0, _api.default)();
166
- const response = await api.mutate({
168
+ await api.mutate({
167
169
  mutation: CREATE_EXPORT_JOB_MUTATION,
168
170
  variables: {
169
171
  input: {
@@ -173,16 +175,9 @@ async function createExportJob(appId, envId, backupId) {
173
175
  }
174
176
  }
175
177
  });
176
- const {
177
- data: {
178
- startDBBackupCopy: {
179
- success
180
- }
181
- }
182
- } = response;
183
- if (!success) {
184
- throw new Error();
185
- }
178
+
179
+ // Re-enable global error handling
180
+ (0, _api.enableGlobalGraphQLErrorHandling)();
186
181
  }
187
182
 
188
183
  /**
@@ -198,11 +193,12 @@ class ExportSQLCommand {
198
193
  /**
199
194
  * Creates an instance of SQLExportCommand
200
195
  *
201
- * @param {any} app The application object
202
- * @param {any} env The environment object
203
- * @param {string} outputFile The output file path
196
+ * @param {any} app The application object
197
+ * @param {any} env The environment object
198
+ * @param {string} outputFile The output file path
199
+ * @param {Function} trackerFn The progress tracker function
204
200
  */
205
- constructor(app, env, outputFile) {
201
+ constructor(app, env, outputFile, trackerFn = () => {}) {
206
202
  this.app = app;
207
203
  this.env = env;
208
204
  this.outputFile = outputFile;
@@ -219,6 +215,7 @@ class ExportSQLCommand {
219
215
  id: this.steps.DOWNLOAD,
220
216
  name: 'Downloading file'
221
217
  }]);
218
+ this.track = trackerFn;
222
219
  }
223
220
 
224
221
  /**
@@ -231,7 +228,6 @@ class ExportSQLCommand {
231
228
  latestBackup,
232
229
  jobs
233
230
  } = await fetchLatestBackupAndJobStatus(this.app.id, this.env.id);
234
- this.runningJobs = jobs.filter(job => job.progress.status === 'running');
235
231
 
236
232
  // Find the job that generates the export for the latest backup
237
233
  return jobs.find(job => {
@@ -316,24 +312,30 @@ class ExportSQLCommand {
316
312
  async run() {
317
313
  console.log(`Fetching the latest backup for ${this.app.name}`);
318
314
  const {
319
- latestBackup,
320
- jobs
315
+ latestBackup
321
316
  } = await fetchLatestBackupAndJobStatus(this.app.id, this.env.id);
322
- this.runningJobs = jobs.filter(job => job.progress.status === 'running');
323
317
  if (!latestBackup) {
318
+ await this.track('no_backup_found_error', {
319
+ errorMessage: 'No backup found for the site'
320
+ });
324
321
  exit.withError(`No backup found for site ${this.app.name}`);
325
322
  } else {
326
323
  console.log(`${(0, _format.getGlyphForStatus)('success')} Latest backup found with timestamp ${latestBackup.createdAt}`);
327
324
  }
328
325
  if (await this.getExportJob()) {
329
326
  console.log(`Attaching to an existing export for the backup with timestamp ${latestBackup.createdAt}`);
330
- } else if (this.runningJobs.length > 0) {
331
- exit.withError('There is an export job already running for this site: ' + `https://dashboard.wpvip.com/apps/${this.app.id}/${this.env.uniqueLabel}/data/database/backups\n` + 'Currently, we allow only one export job per site. Please try again later.');
332
327
  } else {
333
328
  console.log(`Creating a new export for the backup with timestamp ${latestBackup.createdAt}`);
334
329
  try {
335
330
  await createExportJob(this.app.id, this.env.id, latestBackup.id);
336
331
  } catch (err) {
332
+ // Todo: match error code instead of message substring
333
+ if (err !== null && err !== void 0 && err.message.includes('Backup Copy already in progress')) {
334
+ await this.track('export_job_already_running_error', {
335
+ errorMessage: err === null || err === void 0 ? void 0 : err.message
336
+ });
337
+ exit.withError('There is an export job already running for this site: ' + `https://dashboard.wpvip.com/apps/${this.app.id}/${this.env.uniqueLabel}/data/database/backups\n` + 'Currently, we allow only one export job per site. Please try again later.');
338
+ }
337
339
  exit.withError(`Error creating export job: ${err === null || err === void 0 ? void 0 : err.message}`);
338
340
  }
339
341
  }
@@ -355,6 +357,9 @@ class ExportSQLCommand {
355
357
  } catch (err) {
356
358
  this.progressTracker.stepFailed(this.steps.DOWNLOAD);
357
359
  this.stopProgressTracker();
360
+ await this.track('download_failed_error', {
361
+ errorMessage: err === null || err === void 0 ? void 0 : err.message
362
+ });
358
363
  exit.withError(`Error downloading exported file: ${err === null || err === void 0 ? void 0 : err.message}`);
359
364
  }
360
365
  }
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.aliasUser = aliasUser;
7
+ exports.makeCommandTracker = makeCommandTracker;
7
8
  exports.trackEvent = trackEvent;
8
9
  exports.trackEventWithEnv = trackEventWithEnv;
9
10
  var _index = _interopRequireDefault(require("./analytics/index"));
@@ -77,4 +78,13 @@ async function trackEventWithEnv(appId, envId, eventName, eventProps = {}) {
77
78
  app_id: appId,
78
79
  env_id: envId
79
80
  });
81
+ }
82
+ function makeCommandTracker(command, trackingInfo = {}) {
83
+ const trackerFn = async (type, data = {}) => {
84
+ await trackEvent(`${command}_command_${type}`, {
85
+ ...trackingInfo,
86
+ ...data
87
+ });
88
+ };
89
+ return trackerFn;
80
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/vip",
3
- "version": "2.27.0-dev5",
3
+ "version": "2.27.0-dev7",
4
4
  "description": "The VIP Javascript library & CLI",
5
5
  "main": "index.js",
6
6
  "bin": {
Binary file