@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
@@ -6,43 +6,24 @@
6
6
  "use strict";
7
7
 
8
8
  var _chalk = _interopRequireDefault(require("chalk"));
9
-
10
9
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
11
-
12
10
  var _socket = _interopRequireDefault(require("socket.io-client"));
13
-
14
11
  var _socket2 = _interopRequireDefault(require("socket.io-stream"));
15
-
16
12
  var _readline = _interopRequireDefault(require("readline"));
17
-
18
13
  var _stream = require("stream");
19
-
20
14
  var _debug = _interopRequireDefault(require("debug"));
21
-
22
15
  var _api = _interopRequireWildcard(require("../lib/api"));
23
-
24
16
  var _command = _interopRequireWildcard(require("../lib/cli/command"));
25
-
26
17
  var exit = _interopRequireWildcard(require("../lib/cli/exit"));
27
-
28
18
  var _format = require("../lib/cli/format");
29
-
30
19
  var _prompt = require("../lib/cli/prompt");
31
-
32
20
  var _tracker = require("../lib/tracker");
33
-
34
21
  var _token = _interopRequireDefault(require("../lib/token"));
35
-
36
22
  var _rollbar = require("../lib/rollbar");
37
-
38
23
  var _proxyAgent = require("../lib/http/proxy-agent");
39
-
40
24
  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); }
41
-
42
25
  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; }
43
-
44
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
45
-
46
27
  /**
47
28
  * Internal dependencies
48
29
  */
@@ -67,7 +48,6 @@ const cancelCommandChar = '\x03';
67
48
  let currentJob = null;
68
49
  let currentOffset = 0;
69
50
  let commandRunning = false;
70
-
71
51
  const pipeStreamsToProcess = ({
72
52
  stdin,
73
53
  stdout: outStream
@@ -75,7 +55,6 @@ const pipeStreamsToProcess = ({
75
55
  process.stdin.pipe(stdin);
76
56
  outStream.pipe(process.stdout);
77
57
  };
78
-
79
58
  const unpipeStreamsFromProcess = ({
80
59
  stdin,
81
60
  stdout: outStream
@@ -83,7 +62,6 @@ const unpipeStreamsFromProcess = ({
83
62
  process.stdin.unpipe(stdin);
84
63
  outStream.unpipe(process.stdout);
85
64
  };
86
-
87
65
  const bindStreamEvents = ({
88
66
  subShellRl,
89
67
  commonTrackingParams,
@@ -91,34 +69,34 @@ const bindStreamEvents = ({
91
69
  stdoutStream
92
70
  }) => {
93
71
  stdoutStream.on('error', err => {
94
- commandRunning = false; // TODO handle this better
72
+ commandRunning = false;
95
73
 
74
+ // TODO handle this better
96
75
  console.error('Error: ' + err.message);
97
76
  });
98
77
  stdoutStream.on('end', async () => {
99
78
  subShellRl.clearLine();
100
79
  commandRunning = false;
101
- await (0, _tracker.trackEvent)('wpcli_command_end', commonTrackingParams); // Tell socket.io to stop trying to connect
80
+ await (0, _tracker.trackEvent)('wpcli_command_end', commonTrackingParams);
102
81
 
82
+ // Tell socket.io to stop trying to connect
103
83
  currentJob.socket.close();
104
84
  unpipeStreamsFromProcess({
105
85
  stdin: currentJob.stdinStream,
106
86
  stdout: currentJob.stdoutStream
107
- }); // Reset offset
87
+ });
108
88
 
89
+ // Reset offset
109
90
  currentOffset = 0;
110
-
111
91
  if (!isSubShell) {
112
92
  subShellRl.close();
113
93
  process.exit();
114
94
  return;
115
95
  }
116
-
117
96
  subShellRl.resume();
118
97
  subShellRl.prompt();
119
98
  });
120
99
  };
121
-
122
100
  const getTokenForCommand = async (appId, envId, command) => {
123
101
  const api = await (0, _api.default)();
124
102
  return api.mutate({
@@ -141,9 +119,9 @@ const getTokenForCommand = async (appId, envId, command) => {
141
119
  }
142
120
  }
143
121
  });
144
- }; // eslint-disable-next-line no-unused-vars
145
-
122
+ };
146
123
 
124
+ // eslint-disable-next-line no-unused-vars
147
125
  const cancelCommand = async guid => {
148
126
  const api = await (0, _api.default)();
149
127
  return api.mutate({
@@ -164,7 +142,6 @@ const cancelCommand = async guid => {
164
142
  }
165
143
  });
166
144
  };
167
-
168
145
  const launchCommandAndGetStreams = async ({
169
146
  socket,
170
147
  guid,
@@ -172,12 +149,12 @@ const launchCommandAndGetStreams = async ({
172
149
  offset = 0
173
150
  }) => {
174
151
  const stdoutStream = _socket2.default.createStream();
175
-
176
152
  const stdinStream = _socket2.default.createStream();
177
-
178
153
  stdoutStream.on('data', data => {
179
154
  currentOffset = data.length + currentOffset;
180
- }); // TODO handle all arguments
155
+ });
156
+
157
+ // TODO handle all arguments
181
158
  // TODO handle disconnect - does IOStream correctly buffer stdin?
182
159
  // TODO stderr - currently server doesn't support it, so errors don't terminate process
183
160
 
@@ -199,7 +176,6 @@ const launchCommandAndGetStreams = async ({
199
176
  (0, _socket2.default)(socket).on('error', err => {
200
177
  // This returns the error so it can be catched by the socket.on('error')
201
178
  _rollbar.rollbar.error(err);
202
-
203
179
  return err;
204
180
  });
205
181
  socket.on('error', err => {
@@ -207,9 +183,7 @@ const launchCommandAndGetStreams = async ({
207
183
  console.log(_chalk.default.red('\nError:'), 'Rate limit exceeded: Please wait a moment and try again.');
208
184
  return;
209
185
  }
210
-
211
186
  _rollbar.rollbar.error(err);
212
-
213
187
  console.log(err);
214
188
  });
215
189
  return {
@@ -218,7 +192,6 @@ const launchCommandAndGetStreams = async ({
218
192
  socket
219
193
  };
220
194
  };
221
-
222
195
  const bindReconnectEvents = ({
223
196
  cliCommand,
224
197
  inputToken,
@@ -232,15 +205,14 @@ const bindReconnectEvents = ({
232
205
  currentJob.socket.removeAllListeners('connect_error');
233
206
  currentJob.socket.io.on('reconnect', async () => {
234
207
  debug('socket.io: reconnect');
235
-
236
208
  _rollbar.rollbar.info('WP-CLI socket.io.on( \'reconnect\' )', {
237
209
  custom: {
238
210
  code: 'wp-cli-on-reconnect',
239
211
  commandGuid: cliCommand.guid
240
212
  }
241
- }); // Close old streams
242
-
213
+ });
243
214
 
215
+ // Close old streams
244
216
  unpipeStreamsFromProcess({
245
217
  stdin: currentJob.stdinStream,
246
218
  stdout: currentJob.stdoutStream
@@ -251,8 +223,9 @@ const bindReconnectEvents = ({
251
223
  guid: cliCommand.guid,
252
224
  inputToken: inputToken,
253
225
  offset: currentOffset
254
- }); // Rebind new streams
226
+ });
255
227
 
228
+ // Rebind new streams
256
229
  pipeStreamsToProcess({
257
230
  stdin: currentJob.stdinStream,
258
231
  stdout: currentJob.stdoutStream
@@ -269,36 +242,34 @@ const bindReconnectEvents = ({
269
242
  subShellRl,
270
243
  commonTrackingParams,
271
244
  isSubShell
272
- }); // Resume readline interface
245
+ });
273
246
 
247
+ // Resume readline interface
274
248
  subShellRl.resume();
275
249
  });
276
250
  currentJob.socket.on('retry', async () => {
277
251
  debug('socket: retry');
278
-
279
252
  _rollbar.rollbar.info('WP-CLI socket.io.on( \'retry\' )', {
280
253
  custom: {
281
254
  code: 'wp-cli-on-retry',
282
255
  commandGuid: cliCommand.guid
283
256
  }
284
257
  });
285
-
286
258
  setTimeout(() => {
287
259
  currentJob.socket.io.engine.close();
288
260
  }, 5000);
289
261
  });
290
262
  currentJob.socket.on('connect_error', () => {
291
263
  debug('socket: connect_error; forcing the preference for websocket');
292
-
293
264
  _rollbar.rollbar.info('WP-CLI socket.on( \'connect_error\' )', {
294
265
  custom: {
295
266
  code: 'wp-cli-on-connect_error',
296
267
  commandGuid: cliCommand.guid
297
268
  }
298
- }); // Force the preference for WebSocket in case we see an error during connection
299
- // https://socket.io/docs/v3/client-initialization/#low-level-engine-options
300
-
269
+ });
301
270
 
271
+ // Force the preference for WebSocket in case we see an error during connection
272
+ // https://socket.io/docs/v3/client-initialization/#low-level-engine-options
302
273
  currentJob.socket.io.opts.transports = ['websocket', 'polling'];
303
274
  });
304
275
  currentJob.socket.on('exit', async ({
@@ -306,11 +277,9 @@ const bindReconnectEvents = ({
306
277
  message
307
278
  }) => {
308
279
  debug('socket: exit. Code: %d. Message: %s', exitCode, message);
309
-
310
280
  if (message) {
311
281
  console.log(message);
312
282
  }
313
-
314
283
  currentJob.stdinStream.destroy();
315
284
  currentJob.stdoutStream.destroy();
316
285
  currentJob.socket.close();
@@ -318,16 +287,14 @@ const bindReconnectEvents = ({
318
287
  });
319
288
  currentJob.socket.io.on('reconnect_attempt', attempt => {
320
289
  console.error('There was an error connecting to the server. Retrying...');
321
-
322
290
  if (attempt > 1) {
323
291
  return;
324
- } // create a new input stream so that we can still catch things like SIGINT while reconnecting
325
-
292
+ }
326
293
 
294
+ // create a new input stream so that we can still catch things like SIGINT while reconnecting
327
295
  if (currentJob.stdinStream) {
328
296
  process.stdin.unpipe(currentJob.stdinStream);
329
297
  }
330
-
331
298
  process.stdin.pipe(_socket2.default.createStream());
332
299
  currentJob.stdoutStream = _socket2.default.createStream();
333
300
  bindStreamEvents({
@@ -338,18 +305,19 @@ const bindReconnectEvents = ({
338
305
  });
339
306
  });
340
307
  };
341
-
342
308
  (0, _command.default)({
343
309
  wildcardCommand: true,
344
310
  appContext: true,
345
311
  envContext: true,
346
312
  appQuery
347
313
  }).option('yes', 'Run the command in production without a confirmation prompt').argv(process.argv, async (args, opts) => {
348
- const isSubShell = 0 === args.length; // Have to re-quote anything that needs it before we pass it on
314
+ const isSubShell = 0 === args.length;
349
315
 
316
+ // Have to re-quote anything that needs it before we pass it on
350
317
  const quotedArgs = (0, _format.requoteArgs)(args);
351
- const cmd = quotedArgs.join(' '); // Store only the first 2 parts of command to avoid recording secrets. Can be tweaked
318
+ const cmd = quotedArgs.join(' ');
352
319
 
320
+ // Store only the first 2 parts of command to avoid recording secrets. Can be tweaked
353
321
  const commandForAnalytics = quotedArgs.slice(0, 2).join(' ');
354
322
  const {
355
323
  id: appId,
@@ -362,8 +330,8 @@ const bindReconnectEvents = ({
362
330
  id: envId,
363
331
  type: envName
364
332
  } = opts.env;
365
- /* eslint-disable camelcase */
366
333
 
334
+ /* eslint-disable camelcase */
367
335
  const commonTrackingParams = {
368
336
  command: commandForAnalytics,
369
337
  app_id: appId,
@@ -374,7 +342,6 @@ const bindReconnectEvents = ({
374
342
  /* eslint-enable camelcase */
375
343
 
376
344
  (0, _tracker.trackEvent)('wpcli_command_execute', commonTrackingParams);
377
-
378
345
  if (isSubShell) {
379
346
  // Reset the cursor (can get messed up with enquirer)
380
347
  process.stdout.write('\u001b[?25h');
@@ -384,15 +351,14 @@ const bindReconnectEvents = ({
384
351
  key: 'command',
385
352
  value: `wp ${cmd}`
386
353
  }], `Are you sure you want to run this command on ${(0, _format.formatEnvironment)(envName)} for site ${appName}?`));
387
-
388
354
  if (!yes) {
389
355
  (0, _tracker.trackEvent)('wpcli_confirm_cancel', commonTrackingParams);
390
356
  console.log('Command cancelled');
391
357
  process.exit();
392
358
  }
393
- } // We'll handle our own errors, thank you
394
-
359
+ }
395
360
 
361
+ // We'll handle our own errors, thank you
396
362
  (0, _api.disableGlobalGraphQLErrorHandling)();
397
363
  const promptIdentifier = `${appName}.${(0, _command.getEnvIdentifier)(opts.env)}`;
398
364
  let countSIGINT = 0;
@@ -401,7 +367,6 @@ const bindReconnectEvents = ({
401
367
  if (!this.muted) {
402
368
  process.stdout.write(chunk, encoding);
403
369
  }
404
-
405
370
  callback();
406
371
  }
407
372
  });
@@ -413,44 +378,37 @@ const bindReconnectEvents = ({
413
378
  prompt: '',
414
379
  historySize: 0
415
380
  };
416
-
417
381
  if (isSubShell) {
418
382
  subShellSettings.prompt = (0, _chalk.default)`{bold.yellowBright ${promptIdentifier}:}{blue ~}$ `;
419
383
  subShellSettings.historySize = 200;
420
384
  }
421
-
422
385
  const subShellRl = _readline.default.createInterface(subShellSettings);
423
-
424
386
  subShellRl.on('line', async line => {
425
387
  if (commandRunning) {
426
388
  return;
427
- } // Handle plain return / newline
428
-
389
+ }
429
390
 
391
+ // Handle plain return / newline
430
392
  if (!line) {
431
393
  subShellRl.prompt();
432
394
  return;
433
- } // Check for exit, like SSH (handles both `exit` and `exit;`)
434
-
395
+ }
435
396
 
397
+ // Check for exit, like SSH (handles both `exit` and `exit;`)
436
398
  if (line.startsWith('exit')) {
437
399
  subShellRl.close();
438
400
  process.exit();
439
401
  }
440
-
441
402
  const startsWithWp = line.startsWith('wp ');
442
403
  const empty = 0 === line.length;
443
404
  const userCmdCancelled = line === cancelCommandChar;
444
-
445
405
  if ((empty || !startsWithWp) && !userCmdCancelled) {
446
406
  console.log(_chalk.default.red('Error:'), 'invalid command, please pass a valid WP CLI command.');
447
407
  subShellRl.prompt();
448
408
  return;
449
409
  }
450
-
451
410
  subShellRl.pause();
452
411
  let result;
453
-
454
412
  try {
455
413
  result = await getTokenForCommand(appId, envId, line.replace('wp ', ''));
456
414
  } catch (error) {
@@ -462,19 +420,15 @@ const bindReconnectEvents = ({
462
420
  } else {
463
421
  // Else, other type of error, just dump it
464
422
  _rollbar.rollbar.error(error);
465
-
466
423
  console.log(error);
467
424
  }
468
-
469
425
  if (!isSubShell) {
470
426
  subShellRl.close();
471
427
  process.exit(1);
472
428
  }
473
-
474
429
  subShellRl.prompt();
475
430
  return;
476
431
  }
477
-
478
432
  const {
479
433
  data: {
480
434
  triggerWPCLICommandOnAppEnvironment: {
@@ -483,7 +437,6 @@ const bindReconnectEvents = ({
483
437
  }
484
438
  }
485
439
  } = result;
486
-
487
440
  if (line.includes("'")) {
488
441
  _rollbar.rollbar.info('WP-CLI Command containing single quotes', {
489
442
  custom: {
@@ -492,7 +445,6 @@ const bindReconnectEvents = ({
492
445
  }
493
446
  });
494
447
  }
495
-
496
448
  const token = await _token.default.get();
497
449
  const extraHeaders = {
498
450
  Authorization: `Bearer ${token.raw}`
@@ -531,8 +483,9 @@ const bindReconnectEvents = ({
531
483
  commonTrackingParams,
532
484
  isSubShell
533
485
  });
534
- }); // Fix to re-add the \n character that readline strips when terminal == true
486
+ });
535
487
 
488
+ // Fix to re-add the \n character that readline strips when terminal == true
536
489
  process.stdin.on('data', data => {
537
490
  // only run this in interactive mode for prompts from WP commands
538
491
  if (commandRunning && 0 === Buffer.compare(data, Buffer.from('\r'))) {
@@ -546,29 +499,26 @@ const bindReconnectEvents = ({
546
499
  if (countSIGINT >= 1) {
547
500
  process.exit();
548
501
  }
502
+ countSIGINT += 1;
549
503
 
550
- countSIGINT += 1; // write out CTRL-C/SIGINT
551
-
504
+ // write out CTRL-C/SIGINT
552
505
  process.stdin.write(cancelCommandChar);
553
-
554
506
  if (currentJob && currentJob.stdoutStream) {
555
507
  currentJob.stdoutStream.end();
556
508
  }
557
-
558
509
  await (0, _tracker.trackEvent)('wpcli_cancel_command', commonTrackingParams);
559
- console.log('Command cancelled by user'); // if no command running (.e.g. interactive shell, exit only after doing cleanup)
510
+ console.log('Command cancelled by user');
560
511
 
512
+ // if no command running (.e.g. interactive shell, exit only after doing cleanup)
561
513
  if (commandRunning === false) {
562
514
  process.exit();
563
515
  }
564
516
  });
565
-
566
517
  if (!isSubShell) {
567
518
  mutableStdout.muted = true;
568
519
  subShellRl.write(`wp ${cmd}\n`);
569
520
  mutableStdout.muted = false;
570
521
  return;
571
522
  }
572
-
573
523
  subShellRl.prompt();
574
524
  });
package/dist/bin/vip.js CHANGED
@@ -6,53 +6,37 @@
6
6
  "use strict";
7
7
 
8
8
  var _opn = _interopRequireDefault(require("opn"));
9
-
10
9
  var _enquirer = require("enquirer");
11
-
12
10
  var _chalk = _interopRequireDefault(require("chalk"));
13
-
14
11
  var _debug = _interopRequireDefault(require("debug"));
15
-
16
12
  var _config = _interopRequireDefault(require("../lib/cli/config"));
17
-
18
13
  var _command = _interopRequireWildcard(require("../lib/cli/command"));
19
-
20
14
  var _token = _interopRequireDefault(require("../lib/token"));
21
-
22
15
  var _tracker = require("../lib/tracker");
23
-
24
16
  var _rollbar = require("../lib/rollbar");
25
-
26
17
  var _logout = _interopRequireDefault(require("../lib/logout"));
27
-
28
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); }
29
-
30
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; }
31
-
32
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
-
34
21
  /**
35
22
  * Internal dependencies
36
23
  */
37
24
  const debug = (0, _debug.default)('@automattic/vip:bin:vip');
38
-
39
25
  if (_config.default && _config.default.environment !== 'production') {
40
26
  debug(`${_chalk.default.bgYellow('WARNING:')} RUNNING DEV VERSION OF @automattic/vip`);
41
27
  debug('You should `npm link` your locally checked out copy of this repo as part of your development setup.');
42
- } // Config
43
-
28
+ }
44
29
 
30
+ // Config
45
31
  const tokenURL = 'https://dashboard.wpvip.com/me/cli/token';
46
-
47
32
  const runCmd = async function () {
48
33
  const cmd = (0, _command.default)();
49
34
  cmd.command('logout', 'Logout from your current session', async () => {
50
35
  await (0, _logout.default)();
51
36
  console.log('You are successfully logged out.');
52
- }).command('app', 'List and modify your VIP applications').command('cache', 'Manage page cache for your VIP applications').command('config', 'Set configuration for your VIP applications').command('dev-env', 'Use local dev-environment').command('import', 'Import media or SQL files into your VIP applications').command('logs', 'Get logs from your VIP applications').command('search-replace', 'Perform search and replace tasks on files').command('sync', 'Sync production to a development environment').command('whoami', 'Display details about the currently logged-in user').command('wp', 'Run WP CLI commands against an environment');
37
+ }).command('app', 'List and modify your VIP applications').command('cache', 'Manage page cache for your VIP applications').command('config', 'Set configuration for your VIP applications').command('dev-env', 'Use local dev-environment').command('import', 'Import media or SQL files into your VIP applications').command('logs', 'Get logs from your VIP applications').command('search-replace', 'Perform search and replace tasks on files').command('sync', 'Sync production to a development environment').command('whoami', 'Display details about the currently logged-in user').command('validate', 'Validate your VIP application and environment').command('wp', 'Run WP CLI commands against an environment');
53
38
  cmd.argv(process.argv);
54
39
  };
55
-
56
40
  const rootCmd = async function () {
57
41
  let token = await _token.default.get();
58
42
  const isHelpCommand = process.argv.some(arg => arg === 'help' || arg === '-h' || arg === '--help');
@@ -60,7 +44,6 @@ const rootCmd = async function () {
60
44
  const isLoginCommand = process.argv.some(arg => arg === 'login');
61
45
  const isDevEnvCommandWithoutEnv = process.argv.some(arg => arg === 'dev-env') && !(0, _command.containsAppEnvArgument)(process.argv);
62
46
  debug('Argv:', process.argv);
63
-
64
47
  if (!isLoginCommand && (isLogoutCommand || isHelpCommand || isDevEnvCommandWithoutEnv || token && token.valid())) {
65
48
  runCmd();
66
49
  } else {
@@ -81,12 +64,10 @@ const rootCmd = async function () {
81
64
  name: 'continue',
82
65
  message: 'Ready to authenticate?'
83
66
  });
84
-
85
67
  if (!answer.continue) {
86
68
  await (0, _tracker.trackEvent)('login_command_browser_cancelled');
87
69
  return;
88
70
  }
89
-
90
71
  (0, _opn.default)(tokenURL, {
91
72
  wait: false
92
73
  });
@@ -98,20 +79,16 @@ const rootCmd = async function () {
98
79
  name: 'token',
99
80
  message: 'Access Token:'
100
81
  });
101
-
102
82
  try {
103
83
  token = new _token.default(tokenInput);
104
84
  } catch (err) {
105
85
  console.log('The token provided is malformed. Please check the token and try again.');
106
-
107
86
  _rollbar.rollbar.error(err);
108
-
109
87
  await (0, _tracker.trackEvent)('login_command_token_submit_error', {
110
88
  error: err.message
111
89
  });
112
90
  return;
113
91
  }
114
-
115
92
  if (token.expired()) {
116
93
  console.log('The token provided is expired. Please log in again to refresh the token.');
117
94
  await (0, _tracker.trackEvent)('login_command_token_submit_error', {
@@ -119,7 +96,6 @@ const rootCmd = async function () {
119
96
  });
120
97
  return;
121
98
  }
122
-
123
99
  if (!token.valid()) {
124
100
  console.log('The provided token is not valid. Please log in again to refresh the token.');
125
101
  await (0, _tracker.trackEvent)('login_command_token_submit_error', {
@@ -127,30 +103,24 @@ const rootCmd = async function () {
127
103
  });
128
104
  return;
129
105
  }
130
-
131
106
  try {
132
107
  _token.default.set(token.raw);
133
108
  } catch (err) {
134
109
  await (0, _tracker.trackEvent)('login_command_token_submit_error', {
135
110
  error: err.message
136
111
  });
137
-
138
112
  _rollbar.rollbar.error(err);
139
-
140
113
  throw err;
141
- } // De-anonymize user for tracking
142
-
114
+ }
143
115
 
116
+ // De-anonymize user for tracking
144
117
  await (0, _tracker.aliasUser)(token.id);
145
118
  await (0, _tracker.trackEvent)('login_command_token_submit_success');
146
-
147
119
  if (isLoginCommand) {
148
120
  console.log('You are now logged in - see `vip -h` for a list of available commands.');
149
121
  process.exit();
150
122
  }
151
-
152
123
  runCmd();
153
124
  }
154
125
  };
155
-
156
126
  rootCmd();
@@ -4,67 +4,60 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _http = _interopRequireDefault(require("../../api/http"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
9
 
12
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
-
14
10
  /**
15
11
  * External dependencies
16
12
  */
17
13
  const debug = require('debug')('@automattic/vip:analytics:clients:pendo');
14
+
18
15
  /**
19
16
  * Internal dependencies
20
17
  */
21
18
 
22
-
23
19
  /**
24
20
  * Pendo analytics client.
25
21
  */
22
+
26
23
  class Pendo {
24
+ context = {};
27
25
  static get ENDPOINT() {
28
26
  return '/pendo';
29
27
  }
30
-
31
28
  constructor({
32
29
  userId,
33
30
  eventPrefix,
34
31
  env
35
32
  }) {
36
- _defineProperty(this, "context", {});
37
-
38
33
  this.eventPrefix = eventPrefix;
39
34
  this.userAgent = env.userAgent;
40
35
  this.userId = userId;
41
- this.context = { ...env
36
+ this.context = {
37
+ ...env
42
38
  };
43
39
  }
44
-
45
40
  async trackEvent(eventName, eventProps = {}) {
46
41
  if (!eventName.startsWith(this.eventPrefix)) {
47
42
  eventName = this.eventPrefix + eventName;
48
43
  }
49
-
50
44
  debug('trackEvent()', eventProps);
51
- this.context = { ...this.context,
45
+ this.context = {
46
+ ...this.context,
52
47
  org_id: eventProps.org_slug,
53
48
  org_slug: eventProps.org_slug,
54
49
  userAgent: this.userAgent,
55
50
  userId: this.userId
56
51
  };
57
-
58
52
  try {
59
53
  return await this.send(eventName, eventProps);
60
54
  } catch (error) {
61
55
  debug(error);
62
- } // Resolve to false instead of rejecting
63
-
56
+ }
64
57
 
58
+ // Resolve to false instead of rejecting
65
59
  return Promise.resolve(false);
66
60
  }
67
-
68
61
  async send(eventName, eventProps) {
69
62
  const body = {
70
63
  context: this.context,
@@ -83,7 +76,5 @@ class Pendo {
83
76
  debug('response', responseText);
84
77
  return responseText;
85
78
  }
86
-
87
79
  }
88
-
89
80
  exports.default = Pendo;