@automattic/vip 2.12.0 → 2.13.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 (105) hide show
  1. package/README.md +12 -1
  2. package/dist/bin/vip-cache-purge-url.js +93 -0
  3. package/{package/dist/bin/vip-config.js → dist/bin/vip-cache.js} +6 -3
  4. package/dist/bin/vip-dev-env-import-sql.js +8 -1
  5. package/dist/bin/vip-dev-env-start.js +2 -1
  6. package/dist/bin/vip-dev-env-update.js +1 -0
  7. package/dist/bin/vip.js +1 -1
  8. package/dist/lib/api/cache-purge.js +76 -0
  9. package/dist/lib/dev-environment/dev-environment-lando.js +31 -3
  10. package/dist/lib/envvar/read-file.js +2 -18
  11. package/{package/dist/lib/envvar → dist/lib}/read-file.js +3 -6
  12. package/dist/lib/validations/sql.js +134 -52
  13. package/npm-shrinkwrap.json +79 -79
  14. package/package.json +4 -2
  15. package/package/dist/bin/vip-app-list.js +0 -73
  16. package/package/dist/bin/vip-app.js +0 -76
  17. package/package/dist/bin/vip-config-envvar-delete.js +0 -97
  18. package/package/dist/bin/vip-config-envvar-get-all.js +0 -94
  19. package/package/dist/bin/vip-config-envvar-get.js +0 -79
  20. package/package/dist/bin/vip-config-envvar-list.js +0 -91
  21. package/package/dist/bin/vip-config-envvar-set.js +0 -123
  22. package/package/dist/bin/vip-config-envvar.js +0 -23
  23. package/package/dist/bin/vip-dev-env-create.js +0 -105
  24. package/package/dist/bin/vip-dev-env-destroy.js +0 -56
  25. package/package/dist/bin/vip-dev-env-exec.js +0 -67
  26. package/package/dist/bin/vip-dev-env-import-media.js +0 -51
  27. package/package/dist/bin/vip-dev-env-import-sql.js +0 -83
  28. package/package/dist/bin/vip-dev-env-import.js +0 -32
  29. package/package/dist/bin/vip-dev-env-info.js +0 -61
  30. package/package/dist/bin/vip-dev-env-list.js +0 -46
  31. package/package/dist/bin/vip-dev-env-start.js +0 -77
  32. package/package/dist/bin/vip-dev-env-stop.js +0 -52
  33. package/package/dist/bin/vip-dev-env-update.js +0 -89
  34. package/package/dist/bin/vip-dev-env.js +0 -23
  35. package/package/dist/bin/vip-import-media-abort.js +0 -132
  36. package/package/dist/bin/vip-import-media-status.js +0 -84
  37. package/package/dist/bin/vip-import-media.js +0 -168
  38. package/package/dist/bin/vip-import-sql-status.js +0 -83
  39. package/package/dist/bin/vip-import-sql.js +0 -580
  40. package/package/dist/bin/vip-import-validate-files.js +0 -191
  41. package/package/dist/bin/vip-import-validate-sql.js +0 -34
  42. package/package/dist/bin/vip-import.js +0 -20
  43. package/package/dist/bin/vip-logs.js +0 -232
  44. package/package/dist/bin/vip-search-replace.js +0 -71
  45. package/package/dist/bin/vip-sync.js +0 -191
  46. package/package/dist/bin/vip-whoami.js +0 -67
  47. package/package/dist/bin/vip-wp.js +0 -555
  48. package/package/dist/bin/vip.js +0 -149
  49. package/package/dist/lib/analytics/clients/client.js +0 -1
  50. package/package/dist/lib/analytics/clients/pendo.js +0 -92
  51. package/package/dist/lib/analytics/clients/stub.js +0 -19
  52. package/package/dist/lib/analytics/clients/tracks.js +0 -128
  53. package/package/dist/lib/analytics/index.js +0 -45
  54. package/package/dist/lib/api/app.js +0 -70
  55. package/package/dist/lib/api/feature-flags.js +0 -39
  56. package/package/dist/lib/api/user.js +0 -58
  57. package/package/dist/lib/api.js +0 -136
  58. package/package/dist/lib/app-logs/app-logs.js +0 -70
  59. package/package/dist/lib/cli/apiConfig.js +0 -90
  60. package/package/dist/lib/cli/command.js +0 -606
  61. package/package/dist/lib/cli/envAlias.js +0 -60
  62. package/package/dist/lib/cli/exit.js +0 -33
  63. package/package/dist/lib/cli/format.js +0 -213
  64. package/package/dist/lib/cli/pager.js +0 -52
  65. package/package/dist/lib/cli/progress.js +0 -208
  66. package/package/dist/lib/cli/prompt.js +0 -37
  67. package/package/dist/lib/cli/repo.js +0 -77
  68. package/package/dist/lib/client-file-uploader.js +0 -602
  69. package/package/dist/lib/constants/dev-environment.js +0 -42
  70. package/package/dist/lib/constants/file-size.js +0 -14
  71. package/package/dist/lib/dev-environment/dev-environment-cli.js +0 -508
  72. package/package/dist/lib/dev-environment/dev-environment-core.js +0 -620
  73. package/package/dist/lib/dev-environment/dev-environment-lando.js +0 -330
  74. package/package/dist/lib/dev-environment/types.js +0 -1
  75. package/package/dist/lib/env.js +0 -36
  76. package/package/dist/lib/envvar/api-delete.js +0 -56
  77. package/package/dist/lib/envvar/api-get-all.js +0 -59
  78. package/package/dist/lib/envvar/api-get.js +0 -24
  79. package/package/dist/lib/envvar/api-list.js +0 -60
  80. package/package/dist/lib/envvar/api-set.js +0 -58
  81. package/package/dist/lib/envvar/api.js +0 -104
  82. package/package/dist/lib/envvar/input.js +0 -55
  83. package/package/dist/lib/envvar/logging.js +0 -33
  84. package/package/dist/lib/http/socks-proxy-agent.js +0 -25
  85. package/package/dist/lib/keychain/browser.js +0 -35
  86. package/package/dist/lib/keychain/insecure.js +0 -63
  87. package/package/dist/lib/keychain/keychain.js +0 -1
  88. package/package/dist/lib/keychain/secure.js +0 -36
  89. package/package/dist/lib/keychain.js +0 -36
  90. package/package/dist/lib/media-import/media-file-import.js +0 -34
  91. package/package/dist/lib/media-import/progress.js +0 -86
  92. package/package/dist/lib/media-import/status.js +0 -335
  93. package/package/dist/lib/rollbar.js +0 -35
  94. package/package/dist/lib/search-and-replace.js +0 -203
  95. package/package/dist/lib/site-import/db-file-import.js +0 -46
  96. package/package/dist/lib/site-import/status.js +0 -444
  97. package/package/dist/lib/token.js +0 -132
  98. package/package/dist/lib/tracker.js +0 -96
  99. package/package/dist/lib/validations/is-multi-site-sql-dump.js +0 -59
  100. package/package/dist/lib/validations/is-multi-site.js +0 -99
  101. package/package/dist/lib/validations/line-by-line.js +0 -92
  102. package/package/dist/lib/validations/site-type.js +0 -66
  103. package/package/dist/lib/validations/sql.js +0 -371
  104. package/package/dist/lib/vip-import-validate-files.js +0 -548
  105. package/package/vip.iml +0 -11
package/README.md CHANGED
@@ -26,6 +26,17 @@ By default, we record information about the usage of this tool using an in-house
26
26
 
27
27
  ## Changelog
28
28
 
29
+ ### 2.13.0 (16 Jun 2022)
30
+
31
+ - #1046 Add Cache Purge Command
32
+ - #1050 [dev-env] Change docs link
33
+ - #1047 [dev-env] Bump lando package
34
+ - #1044 [dev-env] Fix healthchecks No. 2
35
+ - #1043 [dev-env] add docker-compose v2 support
36
+ - #1042 [dev-env] Fix search popup during wizard
37
+ - #1038 [dev-env] Adds domain validation during sql import
38
+ - #1040 [dev-env] track dev-env start time in seconds
39
+
29
40
  ### 2.12.0 (19 May 2022)
30
41
 
31
42
  - #1035 and #1032 Improved publishing checks to publish on npm
@@ -35,7 +46,7 @@ By default, we record information about the usage of this tool using an in-house
35
46
  - #1033 [dev-env] Bump lando in order to support node 18
36
47
 
37
48
  #### Special thanks
38
- frank-cerny for the contribution on #1036
49
+ frank-cerny for the contribution on #999
39
50
 
40
51
  ### 2.11.2 (12 May 2022)
41
52
 
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ *
5
+ * @format
6
+ */
7
+
8
+ /**
9
+ * External dependencies
10
+ */
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ "use strict";
16
+
17
+ Object.defineProperty(exports, "__esModule", {
18
+ value: true
19
+ });
20
+ exports.cachePurgeCommand = cachePurgeCommand;
21
+
22
+ var _cachePurge = require("../lib/api/cache-purge");
23
+
24
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
25
+
26
+ var _tracker = require("../lib/tracker");
27
+
28
+ var _readFile = require("../lib/read-file");
29
+
30
+ var exit = _interopRequireWildcard(require("../lib/cli/exit"));
31
+
32
+ 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); }
33
+
34
+ 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; }
35
+
36
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
37
+
38
+ const examples = [{
39
+ usage: 'vip cache purge-url <URL>',
40
+ description: 'Purge a URL from page cache'
41
+ }, {
42
+ usage: 'vip cache purge-url --from-file=/dev/vip/urls.txt',
43
+ description: 'Purge multiple URLs from page cache'
44
+ }];
45
+
46
+ async function cachePurgeCommand(urls = [], opt = {}) {
47
+ const trackingParams = {
48
+ app_id: opt.app.id,
49
+ command: 'vip cache purge-url',
50
+ env_id: opt.env.id,
51
+ from_file: !!opt.fromFile
52
+ };
53
+ await (0, _tracker.trackEvent)('cache_purge_url_command_execute', trackingParams);
54
+
55
+ if (opt.fromFile) {
56
+ const value = await (0, _readFile.readFromFile)(opt.fromFile);
57
+
58
+ if (value) {
59
+ urls = value.split('\n').map(url => url.trim());
60
+ }
61
+ }
62
+
63
+ if (!urls.length) {
64
+ await (0, _tracker.trackEvent)('cache_purge_url_command_error', { ...trackingParams,
65
+ error: 'No URL provided'
66
+ });
67
+ exit.withError('Please supply at least one URL.');
68
+ }
69
+
70
+ let purgeCacheObject = {};
71
+
72
+ try {
73
+ purgeCacheObject = await (0, _cachePurge.purgeCache)(opt.app.id, opt.env.id, urls);
74
+ } catch (err) {
75
+ await (0, _tracker.trackEvent)('cache_purge_url_command_error', { ...trackingParams,
76
+ error: err.message
77
+ });
78
+ exit.withError(`Failed to purge URL(s) from page cache: ${err.message}`);
79
+ }
80
+
81
+ await (0, _tracker.trackEvent)('cache_purge_url_command_success', trackingParams);
82
+ purgeCacheObject.urls.forEach(url => {
83
+ console.log(`- Purged URL: ${url}`);
84
+ });
85
+ }
86
+
87
+ (0, _command.default)({
88
+ appContext: true,
89
+ appQuery: _cachePurge.appQuery,
90
+ envContext: true,
91
+ wildcardCommand: true,
92
+ usage: 'vip cache purge-url <URL>'
93
+ }).option('from-file', 'Read URLs from file (useful to purge multiple URLs)').examples(examples).argv(process.argv, cachePurgeCommand);
@@ -1,5 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ /**
4
+ *
5
+ * @format
6
+ */
7
+
3
8
  /**
4
9
  * External dependencies
5
10
  */
@@ -15,6 +20,4 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
15
20
 
16
21
  (0, _command.default)({
17
22
  requiredArgs: 2
18
- }).command('envvar', 'Manage environment variables for an application environment').argv(process.argv, async () => {
19
- process.exit(0);
20
- });
23
+ }).command('purge-url', 'Purge page cache').argv(process.argv);
@@ -62,7 +62,14 @@ const examples = [{
62
62
  } = await (0, _devEnvironmentCore.resolveImportPath)(slug, fileName, searchReplace, inPlace);
63
63
 
64
64
  if (!opt.skipValidate) {
65
- await (0, _sql.validate)(fileName, []);
65
+ const expectedDomain = `${slug}.vipdev.lndo.site`;
66
+ await (0, _sql.validate)(resolvedPath, {
67
+ isImport: false,
68
+ skipChecks: [],
69
+ extraCheckParams: {
70
+ siteHomeUrlLando: expectedDomain
71
+ }
72
+ });
66
73
  }
67
74
 
68
75
  const importArg = ['wp', 'db', 'import', inContainerPath];
@@ -66,7 +66,8 @@ const examples = [{
66
66
  }
67
67
 
68
68
  await (0, _devEnvironmentCore.startEnvironment)(slug, options);
69
- const processingTime = new Date() - startProcessing;
69
+ const processingTime = Math.ceil((new Date() - startProcessing) / 1000); // in seconds
70
+
70
71
  const successTrackingInfo = { ...trackingInfo,
71
72
  processing_time: processingTime
72
73
  };
@@ -68,6 +68,7 @@ cmd.argv(process.argv, async (arg, opt) => {
68
68
  statsd: currentInstanceData.statsd,
69
69
  phpmyadmin: currentInstanceData.phpmyadmin,
70
70
  xdebug: currentInstanceData.xdebug,
71
+ enterpriseSearchEnabled: currentInstanceData.enterpriseSearchEnabled,
71
72
  mediaRedirectDomain: currentInstanceData.mediaRedirectDomain,
72
73
  multisite: false,
73
74
  title: ''
package/dist/bin/vip.js CHANGED
@@ -48,7 +48,7 @@ const runCmd = async function () {
48
48
  await _token.default.purge();
49
49
  await (0, _tracker.trackEvent)('logout_command_execute');
50
50
  console.log('You are successfully logged out.');
51
- }).command('app', 'List and modify 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');
51
+ }).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');
52
52
  cmd.argv(process.argv);
53
53
  };
54
54
 
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.purgeCache = purgeCache;
7
+ exports.appQuery = void 0;
8
+
9
+ var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
10
+
11
+ var _api = _interopRequireDefault(require("../api"));
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ /**
16
+ *
17
+ * @format
18
+ */
19
+
20
+ /**
21
+ * External dependencies
22
+ */
23
+
24
+ /**
25
+ * Internal dependencies
26
+ */
27
+ const mutation = (0, _graphqlTag.default)`
28
+ mutation PurgePageCacheMutation(
29
+ $appId: Int!
30
+ $envId: Int!
31
+ $urls: [String!]!
32
+ ) {
33
+ purgePageCache( input: {
34
+ appId: $appId
35
+ environmentId: $envId
36
+ urls: $urls
37
+ } ) {
38
+ success
39
+ urls
40
+ }
41
+ }
42
+ `; // The subquery for environments lets users choose any environment, including production.
43
+
44
+ const appQuery = `
45
+ id
46
+ name
47
+ environments {
48
+ id
49
+ appId
50
+ name
51
+ primaryDomain {
52
+ name
53
+ }
54
+ type
55
+ }
56
+ `;
57
+ exports.appQuery = appQuery;
58
+
59
+ async function purgeCache(appId, envId, urls) {
60
+ const api = await (0, _api.default)();
61
+ const variables = {
62
+ appId,
63
+ envId,
64
+ urls
65
+ };
66
+ const response = await api.mutate({
67
+ mutation,
68
+ variables
69
+ });
70
+ const {
71
+ data: {
72
+ purgePageCache
73
+ }
74
+ } = response;
75
+ return purgePageCache;
76
+ }
@@ -110,14 +110,42 @@ function addHooks(app, lando) {
110
110
  app.events.on('post-start', 1, () => healthcheckHook(app, lando));
111
111
  }
112
112
 
113
+ const healthChecks = {
114
+ database: 'mysql -uroot --silent --execute "SHOW DATABASES;"',
115
+ 'vip-search': "curl -s --noproxy '*' -XGET localhost:9200",
116
+ php: '[[ -f /wp/wp-includes/pomo/mo.php ]]'
117
+ };
118
+
113
119
  async function healthcheckHook(app, lando) {
114
120
  try {
115
121
  await lando.Promise.retry(async () => {
116
122
  const list = await lando.engine.list({
117
123
  project: app.project
118
124
  });
119
- const containersWithHealthCheck = list.filter(container => container.status.includes('health'));
120
- const notHealthyContainers = containersWithHealthCheck.filter(container => !container.status.includes('healthy'));
125
+ const notHealthyContainers = [];
126
+
127
+ for (const container of list) {
128
+ if (healthChecks[container.service]) {
129
+ try {
130
+ debug(`Testing ${container.service}: ${healthChecks[container.service]}`);
131
+ await app.engine.run({
132
+ id: container.id,
133
+ cmd: healthChecks[container.service],
134
+ compose: app.compose,
135
+ project: app.project,
136
+ opts: {
137
+ silent: true,
138
+ noTTY: true,
139
+ cstdio: 'pipe',
140
+ services: [container.service]
141
+ }
142
+ });
143
+ } catch (e) {
144
+ debug(`${container.service} Health check failed`);
145
+ notHealthyContainers.push(container);
146
+ }
147
+ }
148
+ }
121
149
 
122
150
  if (notHealthyContainers.length) {
123
151
  for (const container of notHealthyContainers) {
@@ -185,7 +213,7 @@ async function landoInfo(instancePath) {
185
213
  } // Add documentation link
186
214
 
187
215
 
188
- appInfo.Documentation = 'https://docs.wpvip.com/technical-references/vip-local-development-environment/tips/';
216
+ appInfo.Documentation = 'https://docs.wpvip.com/technical-references/vip-local-development-environment/';
189
217
  return appInfo;
190
218
  }
191
219
 
@@ -5,15 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.readVariableFromFile = readVariableFromFile;
7
7
 
8
- var _fs = require("fs");
9
-
10
- var exit = _interopRequireWildcard(require("../cli/exit"));
11
-
12
8
  var _logging = require("./logging");
13
9
 
14
- 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); }
15
-
16
- 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; }
10
+ var _readFile = require("../read-file");
17
11
 
18
12
  /**
19
13
  *
@@ -29,15 +23,5 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
29
23
  */
30
24
  async function readVariableFromFile(path) {
31
25
  (0, _logging.debug)(`Loading variable value from file ${JSON.stringify(path)}`);
32
- const data = await _fs.promises.readFile(path, 'binary').catch(({
33
- message
34
- }) => {
35
- // Provide friendly version of common error.
36
- if (message.startsWith('ENOENT: no such file or directory')) {
37
- exit.withError(`Could not load file ${JSON.stringify(path)}.`);
38
- }
39
-
40
- exit.withError(message);
41
- });
42
- return Buffer.from(data).toString().trim();
26
+ return await (0, _readFile.readFromFile)(path);
43
27
  }
@@ -3,13 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.readVariableFromFile = readVariableFromFile;
6
+ exports.readFromFile = readFromFile;
7
7
 
8
8
  var _fs = require("fs");
9
9
 
10
- var exit = _interopRequireWildcard(require("../cli/exit"));
11
-
12
- var _logging = require("./logging");
10
+ var exit = _interopRequireWildcard(require("./cli/exit"));
13
11
 
14
12
  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); }
15
13
 
@@ -27,8 +25,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
27
25
  /**
28
26
  * Internal dependencies
29
27
  */
30
- async function readVariableFromFile(path) {
31
- (0, _logging.debug)(`Loading variable value from file ${JSON.stringify(path)}`);
28
+ async function readFromFile(path) {
32
29
  const data = await _fs.promises.readFile(path, 'binary').catch(({
33
30
  message
34
31
  }) => {