@automattic/vip 2.30.0-dev1 → 2.31.0-dev1
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.
- package/CHANGELOG.md +10 -0
- package/assets/dev-env.lando.template.yml.ejs +7 -2
- package/dist/bin/vip-dev-env-create.js +4 -1
- package/dist/bin/vip-dev-env-sync-sql.js +11 -18
- package/dist/bin/vip-export-sql.js +12 -11
- package/dist/bin/vip-import-sql.js +2 -2
- package/dist/bin/vip-import-validate-sql.js +2 -2
- package/dist/bin/vip-whoami.js +7 -10
- package/dist/bin/vip-wp.js +7 -5
- package/dist/bin/vip.js +9 -6
- package/dist/commands/dev-env-sync-sql.js +29 -15
- package/dist/commands/export-sql.js +1 -1
- package/dist/lib/analytics/clients/pendo.js +11 -20
- package/dist/lib/analytics/clients/tracks.js +12 -12
- package/dist/lib/analytics/index.js +9 -12
- package/dist/lib/api/app.js +10 -13
- package/dist/lib/api/cache-purge.js +3 -10
- package/dist/lib/api/feature-flags.js +6 -3
- package/dist/lib/api/http.js +10 -18
- package/dist/lib/api/user.js +3 -8
- package/dist/lib/api.js +13 -16
- package/dist/lib/app-logs/app-logs.js +3 -6
- package/dist/lib/app.js +2 -0
- package/dist/lib/cli/apiConfig.js +10 -7
- package/dist/lib/cli/config.js +2 -3
- package/dist/lib/cli/envAlias.js +11 -9
- package/dist/lib/cli/exit.js +4 -7
- package/dist/lib/cli/format.js +25 -26
- package/dist/lib/cli/progress.js +7 -3
- package/dist/lib/cli/prompt.js +3 -2
- package/dist/lib/client-file-uploader.js +86 -87
- package/dist/lib/config/software.js +18 -12
- package/dist/lib/dev-environment/dev-environment-cli.js +47 -3
- package/dist/lib/dev-environment/dev-environment-lando.js +2 -2
- package/dist/lib/env.js +16 -13
- package/dist/lib/envvar/api-delete.js +2 -0
- package/dist/lib/envvar/api-get-all.js +4 -1
- package/dist/lib/envvar/api-get.js +3 -1
- package/dist/lib/envvar/api-list.js +8 -3
- package/dist/lib/envvar/api-set.js +2 -0
- package/dist/lib/envvar/api.js +2 -5
- package/dist/lib/envvar/input.js +7 -8
- package/dist/lib/envvar/read-file.js +4 -7
- package/dist/lib/http/proxy-agent.js +5 -4
- package/dist/lib/keychain/insecure.js +25 -26
- package/dist/lib/keychain/secure.js +5 -2
- package/dist/lib/keychain.js +11 -18
- package/dist/lib/media-import/status.js +2 -2
- package/dist/lib/read-file.js +13 -14
- package/dist/lib/search-and-replace.js +17 -26
- package/dist/lib/site-import/status.js +4 -3
- package/dist/lib/token.js +17 -6
- package/dist/lib/tracker.js +13 -14
- package/dist/lib/user-error.js +6 -5
- package/dist/lib/utils.js +18 -22
- package/dist/lib/validations/sql.js +3 -3
- package/dist/lib/vip-import-validate-files.js +23 -22
- package/npm-shrinkwrap.json +1041 -1230
- package/package.json +30 -8
- package/tsconfig.json +37 -0
- package/dist/lib/analytics/clients/stub.js +0 -16
- package/dist/lib/cli/repo.js +0 -61
- package/dist/lib/keychain/browser.js +0 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
## Changelog
|
|
2
2
|
|
|
3
|
+
### 2.30.0
|
|
4
|
+
|
|
5
|
+
- #1264 feature(dev-env): Add dev-env-sync-sql command
|
|
6
|
+
- #1376 refactor: Convert keychain to TypeScript
|
|
7
|
+
- #1370 fix: Fix issues found by SonarCloud
|
|
8
|
+
- #1374 Add TypeScript support
|
|
9
|
+
- #1334 Dev-env: Allow --multisite to accept boolean, subdirectory, or subdomain values
|
|
10
|
+
- #1375 fix(api): Set non-zero exit code on error
|
|
11
|
+
- #1373 Reverting accidental push to vip-cli
|
|
12
|
+
|
|
3
13
|
### 2.29.1
|
|
4
14
|
|
|
5
15
|
- #1372 fix(export): Make vip-export-sql.js executable
|
|
@@ -74,8 +74,13 @@ services:
|
|
|
74
74
|
run_as_root:
|
|
75
75
|
- chown www-data:www-data /wp/wp-content/mu-plugins /wp/config /wp/log /wp/wp-content/uploads /wp
|
|
76
76
|
run:
|
|
77
|
-
-
|
|
78
|
-
|
|
77
|
+
- >
|
|
78
|
+
sh /dev-tools/setup.sh
|
|
79
|
+
--host database
|
|
80
|
+
--user root
|
|
81
|
+
--domain "http://<%= siteSlug %>.vipdev.lndo.site/"
|
|
82
|
+
--title "<%= wpTitle %>"
|
|
83
|
+
<% if ( multisite ) { %>--ms-domain "<%= siteSlug %>.vipdev.lndo.site" <% if ( multisite === true || multisite === 'subdomain' ) { %>--subdomain <% } %> <% } %>
|
|
79
84
|
database:
|
|
80
85
|
type: compose
|
|
81
86
|
services:
|
|
@@ -42,8 +42,11 @@ const examples = [{
|
|
|
42
42
|
}, {
|
|
43
43
|
usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} create --multisite --wordpress="5.8" --app-code="~/git/my_code"`,
|
|
44
44
|
description: 'Creates a local multisite dev environment using WP 5.8 and application code is expected to be in "~/git/my_code"'
|
|
45
|
+
}, {
|
|
46
|
+
usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} create --multisite=subdirectory --wordpress="5.8" --app-code="~/git/my_code"`,
|
|
47
|
+
description: 'Creates a local multisite dev environment with a subdirectory URL structure using WP 5.8 and application code is expected to be in "~/git/my_code"'
|
|
45
48
|
}];
|
|
46
|
-
const cmd = (0, _command.default)().option('slug', 'Custom name of the dev environment').option('title', 'Title for the WordPress site').option('multisite', 'Enable multisite install', undefined, _devEnvironmentCli.
|
|
49
|
+
const cmd = (0, _command.default)().option('slug', 'Custom name of the dev environment').option('title', 'Title for the WordPress site').option('multisite', 'Enable multisite install', undefined, _devEnvironmentCli.processStringOrBooleanOption);
|
|
47
50
|
(0, _devEnvironmentCli.addDevEnvConfigurationOptions)(cmd);
|
|
48
51
|
cmd.examples(examples);
|
|
49
52
|
cmd.argv(process.argv, async (arg, opt) => {
|
|
@@ -8,9 +8,12 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* External dependencies
|
|
10
10
|
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
11
15
|
"use strict";
|
|
12
16
|
|
|
13
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
14
17
|
var _command = _interopRequireDefault(require("../lib/cli/command"));
|
|
15
18
|
var _devEnvironmentCore = require("../lib/dev-environment/dev-environment-core");
|
|
16
19
|
var _devEnvironmentLando = require("../lib/dev-environment/dev-environment-lando");
|
|
@@ -19,9 +22,6 @@ var _devEnvSyncSql = require("../commands/dev-env-sync-sql");
|
|
|
19
22
|
var _devEnvironment = require("../lib/constants/dev-environment");
|
|
20
23
|
var _tracker = require("../lib/tracker");
|
|
21
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
-
/**
|
|
23
|
-
* Internal dependencies
|
|
24
|
-
*/
|
|
25
25
|
const examples = [{
|
|
26
26
|
usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} sync sql @my-test.develop --slug=my_site`,
|
|
27
27
|
description: 'Syncs with the `my-test` site\'s `develop` environment database into `my_site`'
|
|
@@ -39,6 +39,13 @@ const appQuery = `
|
|
|
39
39
|
primaryDomain { name }
|
|
40
40
|
uniqueLabel
|
|
41
41
|
isMultisite
|
|
42
|
+
wpSitesSDS(first:500) {
|
|
43
|
+
nodes {
|
|
44
|
+
id
|
|
45
|
+
blogId
|
|
46
|
+
homeUrl
|
|
47
|
+
}
|
|
48
|
+
}
|
|
42
49
|
}
|
|
43
50
|
`;
|
|
44
51
|
(0, _command.default)({
|
|
@@ -58,20 +65,6 @@ const appQuery = `
|
|
|
58
65
|
slug
|
|
59
66
|
});
|
|
60
67
|
await trackerFn('execute');
|
|
61
|
-
if (env.isMultisite) {
|
|
62
|
-
console.log(_chalk.default.yellow('You seem to be trying to sync a SQL database for a network site.'));
|
|
63
|
-
console.log(_chalk.default.yellow('Unfortunately, the current version of our tool does not yet support syncing network sites.\n'));
|
|
64
|
-
console.log(_chalk.default.yellow('However, you can manually export the database using the following command:'));
|
|
65
|
-
console.log(_chalk.default.yellow(_chalk.default.bold(`vip export sql @${app.id}.${env.uniqueLabel} --output=${app.id}-${env.uniqueLabel}-exported.sql.gz\n`)));
|
|
66
|
-
console.log(_chalk.default.yellow('After exporting the database, you\'ll need to perform the necessary search and replace operations on the exported file to update any relevant data or configurations.'));
|
|
67
|
-
console.log(_chalk.default.yellow('See: https://docs.wpvip.com/how-tos/dev-env-add-content/#h-3-import-the-sql-file\n'));
|
|
68
|
-
console.log(_chalk.default.yellow('Once you\'ve made the required changes, you can import the modified SQL file into your development environment using the following command:'));
|
|
69
|
-
console.log(_chalk.default.yellow(_chalk.default.bold(`vip dev-env import sql ${app.id}-${env.uniqueLabel}-exported.sql.gz --slug=${slug}`)));
|
|
70
|
-
await trackerFn('aborted', {
|
|
71
|
-
error_type: 'multisite_not_supported'
|
|
72
|
-
});
|
|
73
|
-
process.exit(0);
|
|
74
|
-
}
|
|
75
68
|
const lando = await (0, _devEnvironmentLando.bootstrapLando)();
|
|
76
69
|
const envPath = (0, _devEnvironmentCore.getEnvironmentPath)(slug);
|
|
77
70
|
if (!(await (0, _devEnvironmentLando.isEnvUp)(lando, envPath))) {
|
|
@@ -26,17 +26,18 @@ const examples = [{
|
|
|
26
26
|
description: 'The output file can be specified with the --output flag'
|
|
27
27
|
}];
|
|
28
28
|
const appQuery = `
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
id,
|
|
30
|
+
name,
|
|
31
|
+
type,
|
|
32
|
+
organization { id, name },
|
|
33
|
+
environments{
|
|
34
|
+
id
|
|
35
|
+
appId
|
|
36
|
+
type
|
|
37
|
+
name
|
|
38
|
+
primaryDomain { name }
|
|
39
|
+
uniqueLabel
|
|
40
|
+
}
|
|
40
41
|
`;
|
|
41
42
|
(0, _command.default)({
|
|
42
43
|
appContext: true,
|
|
@@ -317,7 +317,7 @@ const displayPlaybook = ({
|
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
};
|
|
320
|
-
(0, _command.default)({
|
|
320
|
+
void (0, _command.default)({
|
|
321
321
|
appContext: true,
|
|
322
322
|
appQuery,
|
|
323
323
|
envContext: true,
|
|
@@ -498,7 +498,7 @@ Processing the SQL import for your environment...
|
|
|
498
498
|
} catch (uploadError) {
|
|
499
499
|
await track('import_sql_command_error', {
|
|
500
500
|
error_type: 'upload_failed',
|
|
501
|
-
upload_error: uploadError
|
|
501
|
+
upload_error: uploadError.message
|
|
502
502
|
});
|
|
503
503
|
progressTracker.stepFailed('upload');
|
|
504
504
|
return failWithError(uploadError);
|
|
@@ -17,8 +17,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
17
17
|
requiredArgs: 1
|
|
18
18
|
}).example('vip import validate-sql <file>', 'Run the import validation against file').argv(process.argv, async arg => {
|
|
19
19
|
const filename = arg[0];
|
|
20
|
-
if (!
|
|
20
|
+
if (!filename) {
|
|
21
21
|
exit.withError('You must pass in a filename');
|
|
22
22
|
}
|
|
23
|
-
(0, _sql.validate)(filename);
|
|
23
|
+
await (0, _sql.validate)(filename);
|
|
24
24
|
});
|
package/dist/bin/vip-whoami.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @format
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
3
|
/**
|
|
9
4
|
* External dependencies
|
|
10
5
|
*/
|
|
@@ -26,28 +21,30 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
26
21
|
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; }
|
|
27
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
28
23
|
async function whoamiCommand() {
|
|
24
|
+
var _currentUser$displayN, _currentUser$id;
|
|
29
25
|
const trackingParams = {
|
|
30
26
|
command: 'vip whoami'
|
|
31
27
|
};
|
|
32
28
|
await (0, _tracker.trackEvent)('whoami_command_execute', trackingParams);
|
|
33
|
-
let currentUser
|
|
29
|
+
let currentUser;
|
|
34
30
|
try {
|
|
35
31
|
currentUser = await (0, _user.getCurrentUserInfo)();
|
|
36
32
|
} catch (err) {
|
|
33
|
+
const error = err instanceof Error ? err : new Error('Unknown error');
|
|
37
34
|
await (0, _tracker.trackEvent)('whoami_command_error', {
|
|
38
35
|
...trackingParams,
|
|
39
|
-
error:
|
|
36
|
+
error: error.message
|
|
40
37
|
});
|
|
41
|
-
exit.withError(`Failed to fetch information about the currently logged-in user error: ${
|
|
38
|
+
exit.withError(`Failed to fetch information about the currently logged-in user error: ${error.message}`);
|
|
42
39
|
}
|
|
43
40
|
await (0, _tracker.trackEvent)('whoami_command_success', trackingParams);
|
|
44
|
-
const output = [`- Howdy ${currentUser.displayName}!`, `- Your user ID is ${currentUser.id}`];
|
|
41
|
+
const output = [`- Howdy ${(_currentUser$displayN = currentUser.displayName) !== null && _currentUser$displayN !== void 0 ? _currentUser$displayN : 'user'}!`, `- Your user ID is ${(_currentUser$id = currentUser.id) !== null && _currentUser$id !== void 0 ? _currentUser$id : ' not found'}`];
|
|
45
42
|
if (currentUser.isVIP) {
|
|
46
43
|
output.push('- Your account has VIP Staff permissions');
|
|
47
44
|
}
|
|
48
45
|
console.log(output.join('\n'));
|
|
49
46
|
}
|
|
50
|
-
(0, _command.default)({
|
|
47
|
+
void (0, _command.default)({
|
|
51
48
|
usage: 'vip whoami'
|
|
52
49
|
}).examples([{
|
|
53
50
|
usage: 'vip whoami',
|
package/dist/bin/vip-wp.js
CHANGED
|
@@ -207,7 +207,7 @@ const bindReconnectEvents = ({
|
|
|
207
207
|
stdin: currentJob.stdinStream,
|
|
208
208
|
stdout: currentJob.stdoutStream
|
|
209
209
|
});
|
|
210
|
-
(0, _tracker.trackEvent)('wpcli_command_reconnect', commonTrackingParams);
|
|
210
|
+
(0, _tracker.trackEvent)('wpcli_command_reconnect', commonTrackingParams).catch(() => {});
|
|
211
211
|
currentJob = await launchCommandAndGetStreams({
|
|
212
212
|
socket: currentJob.socket,
|
|
213
213
|
guid: cliCommand.guid,
|
|
@@ -319,7 +319,7 @@ const bindReconnectEvents = ({
|
|
|
319
319
|
};
|
|
320
320
|
/* eslint-enable camelcase */
|
|
321
321
|
|
|
322
|
-
(0, _tracker.trackEvent)('wpcli_command_execute', commonTrackingParams);
|
|
322
|
+
(0, _tracker.trackEvent)('wpcli_command_execute', commonTrackingParams).catch(() => {});
|
|
323
323
|
if (isSubShell) {
|
|
324
324
|
// Reset the cursor (can get messed up with enquirer)
|
|
325
325
|
process.stdout.write('\u001b[?25h');
|
|
@@ -330,7 +330,7 @@ const bindReconnectEvents = ({
|
|
|
330
330
|
value: `wp ${cmd}`
|
|
331
331
|
}], `Are you sure you want to run this command on ${(0, _format.formatEnvironment)(envName)} for site ${appName}?`));
|
|
332
332
|
if (!yes) {
|
|
333
|
-
(0, _tracker.trackEvent)('wpcli_confirm_cancel', commonTrackingParams);
|
|
333
|
+
(0, _tracker.trackEvent)('wpcli_confirm_cancel', commonTrackingParams).catch(() => {});
|
|
334
334
|
console.log('Command cancelled');
|
|
335
335
|
process.exit();
|
|
336
336
|
}
|
|
@@ -458,12 +458,14 @@ const bindReconnectEvents = ({
|
|
|
458
458
|
process.stdin.on('data', data => {
|
|
459
459
|
// only run this in interactive mode for prompts from WP commands
|
|
460
460
|
if (commandRunning && 0 === Buffer.compare(data, Buffer.from('\r'))) {
|
|
461
|
-
|
|
461
|
+
var _currentJob;
|
|
462
|
+
if ((_currentJob = currentJob) !== null && _currentJob !== void 0 && _currentJob.stdinStream) {
|
|
462
463
|
currentJob.stdinStream.write('\n');
|
|
463
464
|
}
|
|
464
465
|
}
|
|
465
466
|
});
|
|
466
467
|
subShellRl.on('SIGINT', async () => {
|
|
468
|
+
var _currentJob2;
|
|
467
469
|
// if we have a 2nd SIGINT, exit immediately
|
|
468
470
|
if (countSIGINT >= 1) {
|
|
469
471
|
process.exit();
|
|
@@ -472,7 +474,7 @@ const bindReconnectEvents = ({
|
|
|
472
474
|
|
|
473
475
|
// write out CTRL-C/SIGINT
|
|
474
476
|
process.stdin.write(cancelCommandChar);
|
|
475
|
-
if (currentJob &&
|
|
477
|
+
if ((_currentJob2 = currentJob) !== null && _currentJob2 !== void 0 && _currentJob2.stdoutStream) {
|
|
476
478
|
currentJob.stdoutStream.end();
|
|
477
479
|
}
|
|
478
480
|
await (0, _tracker.trackEvent)('wpcli_cancel_command', commonTrackingParams);
|
package/dist/bin/vip.js
CHANGED
|
@@ -10,7 +10,7 @@ var _chalk = _interopRequireDefault(require("chalk"));
|
|
|
10
10
|
var _debug = _interopRequireDefault(require("debug"));
|
|
11
11
|
var _config = _interopRequireDefault(require("../lib/cli/config"));
|
|
12
12
|
var _command = _interopRequireWildcard(require("../lib/cli/command"));
|
|
13
|
-
var
|
|
13
|
+
var _token2 = _interopRequireDefault(require("../lib/token"));
|
|
14
14
|
var _tracker = require("../lib/tracker");
|
|
15
15
|
var _logout = _interopRequireDefault(require("../lib/logout"));
|
|
16
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); }
|
|
@@ -39,14 +39,15 @@ function doesArgvHaveAtLeastOneParam(argv, params) {
|
|
|
39
39
|
return argv.some(arg => params.includes(arg));
|
|
40
40
|
}
|
|
41
41
|
const rootCmd = async function () {
|
|
42
|
-
|
|
42
|
+
var _token;
|
|
43
|
+
let token = await _token2.default.get();
|
|
43
44
|
const isHelpCommand = doesArgvHaveAtLeastOneParam(process.argv, ['help', '-h', '--help']);
|
|
44
45
|
const isVersionCommand = doesArgvHaveAtLeastOneParam(process.argv, ['-v', '--version']);
|
|
45
46
|
const isLogoutCommand = doesArgvHaveAtLeastOneParam(process.argv, ['logout']);
|
|
46
47
|
const isLoginCommand = doesArgvHaveAtLeastOneParam(process.argv, ['login']);
|
|
47
48
|
const isDevEnvCommandWithoutEnv = doesArgvHaveAtLeastOneParam(process.argv, ['dev-env']) && !(0, _command.containsAppEnvArgument)(process.argv);
|
|
48
49
|
debug('Argv:', process.argv);
|
|
49
|
-
if (!isLoginCommand && (isLogoutCommand || isHelpCommand || isVersionCommand || isDevEnvCommandWithoutEnv || token &&
|
|
50
|
+
if (!isLoginCommand && (isLogoutCommand || isHelpCommand || isVersionCommand || isDevEnvCommandWithoutEnv || (_token = token) !== null && _token !== void 0 && _token.valid())) {
|
|
50
51
|
await runCmd();
|
|
51
52
|
} else {
|
|
52
53
|
console.log();
|
|
@@ -82,7 +83,7 @@ const rootCmd = async function () {
|
|
|
82
83
|
message: 'Access Token:'
|
|
83
84
|
});
|
|
84
85
|
try {
|
|
85
|
-
token = new
|
|
86
|
+
token = new _token2.default(tokenInput);
|
|
86
87
|
} catch (err) {
|
|
87
88
|
console.log('The token provided is malformed. Please check the token and try again.');
|
|
88
89
|
await (0, _tracker.trackEvent)('login_command_token_submit_error', {
|
|
@@ -105,7 +106,7 @@ const rootCmd = async function () {
|
|
|
105
106
|
return;
|
|
106
107
|
}
|
|
107
108
|
try {
|
|
108
|
-
await
|
|
109
|
+
await _token2.default.set(token.raw);
|
|
109
110
|
} catch (err) {
|
|
110
111
|
await (0, _tracker.trackEvent)('login_command_token_submit_error', {
|
|
111
112
|
error: err.message
|
|
@@ -123,4 +124,6 @@ const rootCmd = async function () {
|
|
|
123
124
|
await runCmd();
|
|
124
125
|
}
|
|
125
126
|
};
|
|
126
|
-
|
|
127
|
+
|
|
128
|
+
// We may end up having an unhandled rejection here :-(
|
|
129
|
+
void rootCmd();
|
|
@@ -37,13 +37,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
37
37
|
* @return {string} Site home url. null if not found
|
|
38
38
|
*/
|
|
39
39
|
function findSiteHomeUrl(sql) {
|
|
40
|
+
var _sql$match;
|
|
40
41
|
const regex = "'(siteurl|home)',\\s?'(.*?)'";
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
const url = results[2];
|
|
44
|
-
return _url.default.parse(url).hostname;
|
|
45
|
-
}
|
|
46
|
-
return null;
|
|
42
|
+
const url = ((_sql$match = sql.match(regex)) === null || _sql$match === void 0 ? void 0 : _sql$match[2]) || '';
|
|
43
|
+
return _url.default.parse(url).hostname || null;
|
|
47
44
|
}
|
|
48
45
|
|
|
49
46
|
/**
|
|
@@ -60,11 +57,12 @@ async function extractSiteUrls(sqlFile) {
|
|
|
60
57
|
readInterface.on('line', line => {
|
|
61
58
|
const domain = findSiteHomeUrl(line);
|
|
62
59
|
if (domain) {
|
|
63
|
-
domains.add(
|
|
60
|
+
domains.add(domain);
|
|
64
61
|
}
|
|
65
62
|
});
|
|
66
63
|
readInterface.on('close', () => {
|
|
67
|
-
|
|
64
|
+
// Soring by length so that longest domains are replaced first
|
|
65
|
+
resolve(Array.from(domains).sort((dom1, dom2) => dom2.length - dom1.length));
|
|
68
66
|
});
|
|
69
67
|
readInterface.on('error', reject);
|
|
70
68
|
});
|
|
@@ -86,7 +84,7 @@ class DevEnvSyncSQLCommand {
|
|
|
86
84
|
this.tmpDir = (0, _utils.makeTempDir)();
|
|
87
85
|
}
|
|
88
86
|
get landoDomain() {
|
|
89
|
-
return
|
|
87
|
+
return `${this.slug}.vipdev.lndo.site`;
|
|
90
88
|
}
|
|
91
89
|
get sqlFile() {
|
|
92
90
|
return `${this.tmpDir}/sql-export.sql`;
|
|
@@ -114,7 +112,7 @@ class DevEnvSyncSQLCommand {
|
|
|
114
112
|
* @throws {Error} If there is an error reading the file
|
|
115
113
|
*/
|
|
116
114
|
async runSearchReplace() {
|
|
117
|
-
const replacements = this.
|
|
115
|
+
const replacements = Object.entries(this.searchReplaceMap).flat();
|
|
118
116
|
const readStream = _fs.default.createReadStream(this.sqlFile);
|
|
119
117
|
const replacedStream = await (0, _vipSearchReplace.replace)(readStream, replacements);
|
|
120
118
|
const outputFile = `${this.tmpDir}/sql-export-sr.sql`;
|
|
@@ -127,6 +125,20 @@ class DevEnvSyncSQLCommand {
|
|
|
127
125
|
replacedStream.on('error', reject);
|
|
128
126
|
});
|
|
129
127
|
}
|
|
128
|
+
generateSearchReplaceMap() {
|
|
129
|
+
this.searchReplaceMap = {};
|
|
130
|
+
for (const url of this.siteUrls) {
|
|
131
|
+
this.searchReplaceMap[url] = this.landoDomain;
|
|
132
|
+
}
|
|
133
|
+
const networkSites = this.env.wpSitesSDS.nodes;
|
|
134
|
+
if (!networkSites) return;
|
|
135
|
+
for (const site of networkSites) {
|
|
136
|
+
if (!site.blogId || site.blogId === 1) continue;
|
|
137
|
+
const url = site.homeUrl.replace(/https?:\/\//, '');
|
|
138
|
+
if (!this.searchReplaceMap[url]) return;
|
|
139
|
+
this.searchReplaceMap[url] = `${site.blogId}.${this.landoDomain}`;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
130
142
|
|
|
131
143
|
/**
|
|
132
144
|
* Runs the SQL import command to import the SQL file
|
|
@@ -161,9 +173,9 @@ class DevEnvSyncSQLCommand {
|
|
|
161
173
|
console.log(`${_chalk.default.green('✓')} Extracted to ${this.sqlFile}`);
|
|
162
174
|
} catch (err) {
|
|
163
175
|
await this.track('archive_extraction_error', {
|
|
164
|
-
errorMessage: err
|
|
176
|
+
errorMessage: err.message
|
|
165
177
|
});
|
|
166
|
-
exit.withError(`Error extracting the SQL export: ${err
|
|
178
|
+
exit.withError(`Error extracting the SQL export: ${err.message}`);
|
|
167
179
|
}
|
|
168
180
|
try {
|
|
169
181
|
console.log('Extracting site urls from the SQL file...');
|
|
@@ -171,11 +183,13 @@ class DevEnvSyncSQLCommand {
|
|
|
171
183
|
} catch (err) {
|
|
172
184
|
exit.withError(`Error extracting site URLs: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
173
185
|
}
|
|
186
|
+
console.log('Generating search-replace configuration...');
|
|
187
|
+
this.generateSearchReplaceMap();
|
|
174
188
|
try {
|
|
175
189
|
console.log('Running the following search-replace operations on the SQL file:');
|
|
176
|
-
|
|
177
|
-
console.log(` ${domain} -> ${
|
|
178
|
-
}
|
|
190
|
+
for (const [domain, landoDomain] of Object.entries(this.searchReplaceMap)) {
|
|
191
|
+
console.log(` ${domain} -> ${landoDomain}`);
|
|
192
|
+
}
|
|
179
193
|
await this.runSearchReplace();
|
|
180
194
|
console.log(`${_chalk.default.green('✓')} Search-replace operation is complete`);
|
|
181
195
|
} catch (err) {
|
|
@@ -353,7 +353,7 @@ class ExportSQLCommand {
|
|
|
353
353
|
error_type: 'job_already_running',
|
|
354
354
|
error_message: err === null || err === void 0 ? void 0 : err.message
|
|
355
355
|
});
|
|
356
|
-
exit.withError('There is an export job already running for this
|
|
356
|
+
exit.withError('There is an export job already running for this environment: ' + `https://dashboard.wpvip.com/apps/${this.app.id}/${this.env.uniqueLabel}/data/database/backups\n` + 'Currently, we allow only one export job at a time, per site. Please try again later.');
|
|
357
357
|
}
|
|
358
358
|
exit.withError(`Error creating export job: ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
359
359
|
}
|
|
@@ -4,36 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
7
8
|
var _http = _interopRequireDefault(require("../../../lib/api/http"));
|
|
8
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
10
|
/**
|
|
10
11
|
* External dependencies
|
|
11
12
|
*/
|
|
12
|
-
const debug = require('debug')('@automattic/vip:analytics:clients:pendo');
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Internal dependencies
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
const debug = (0, _debug.default)('@automattic/vip:analytics:clients:pendo');
|
|
18
19
|
/**
|
|
19
20
|
* Pendo analytics client.
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
22
|
class Pendo {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
userId,
|
|
29
|
-
eventPrefix,
|
|
30
|
-
env
|
|
31
|
-
}) {
|
|
32
|
-
this.eventPrefix = eventPrefix;
|
|
33
|
-
this.userAgent = env.userAgent;
|
|
34
|
-
this.userId = userId;
|
|
23
|
+
static ENDPOINT = '/pendo';
|
|
24
|
+
constructor(options) {
|
|
25
|
+
this.eventPrefix = options.eventPrefix;
|
|
26
|
+
this.userAgent = options.env.userAgent;
|
|
27
|
+
this.userId = options.userId;
|
|
35
28
|
this.context = {
|
|
36
|
-
...env
|
|
29
|
+
...options.env
|
|
37
30
|
};
|
|
38
31
|
}
|
|
39
32
|
async trackEvent(eventName, eventProps = {}) {
|
|
@@ -52,10 +45,8 @@ class Pendo {
|
|
|
52
45
|
return await this.send(eventName, eventProps);
|
|
53
46
|
} catch (error) {
|
|
54
47
|
debug(error);
|
|
48
|
+
return Promise.resolve(false);
|
|
55
49
|
}
|
|
56
|
-
|
|
57
|
-
// Resolve to false instead of rejecting
|
|
58
|
-
return Promise.resolve(false);
|
|
59
50
|
}
|
|
60
51
|
async send(eventName, eventProps) {
|
|
61
52
|
const body = {
|
|
@@ -69,11 +60,11 @@ class Pendo {
|
|
|
69
60
|
debug('send()', body);
|
|
70
61
|
const response = await (0, _http.default)(Pendo.ENDPOINT, {
|
|
71
62
|
method: 'POST',
|
|
72
|
-
body
|
|
63
|
+
body: JSON.stringify(body)
|
|
73
64
|
});
|
|
74
65
|
const responseText = await response.text();
|
|
75
66
|
debug('response', responseText);
|
|
76
|
-
return
|
|
67
|
+
return response;
|
|
77
68
|
}
|
|
78
69
|
}
|
|
79
70
|
exports.default = Pendo;
|
|
@@ -6,19 +6,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
|
8
8
|
var _querystring = _interopRequireDefault(require("querystring"));
|
|
9
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
9
10
|
var _apiConfig = require("../../cli/apiConfig");
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
12
|
/**
|
|
12
13
|
* External dependencies
|
|
13
14
|
*/
|
|
14
|
-
const debug = require('debug')('@automattic/vip:analytics:clients:tracks');
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Internal dependencies
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
+
const debug = (0, _debug.default)('@automattic/vip:analytics:clients:tracks');
|
|
20
21
|
const validEventOrPropNamePattern = /^[a-z_][a-z0-9_]*$/;
|
|
21
|
-
|
|
22
22
|
/**
|
|
23
23
|
* Simple class for tracking using Automattic Tracks.
|
|
24
24
|
*
|
|
@@ -28,9 +28,7 @@ const validEventOrPropNamePattern = /^[a-z_][a-z0-9_]*$/;
|
|
|
28
28
|
// TODO: add batch support (can include multiples in `events` array)
|
|
29
29
|
|
|
30
30
|
class Tracks {
|
|
31
|
-
static
|
|
32
|
-
return 'https://public-api.wordpress.com/rest/v1.1/tracks/record';
|
|
33
|
-
}
|
|
31
|
+
static ENDPOINT = 'https://public-api.wordpress.com/rest/v1.1/tracks/record';
|
|
34
32
|
constructor(userId, userType, eventPrefix, env) {
|
|
35
33
|
this.eventPrefix = eventPrefix;
|
|
36
34
|
this.userAgent = env.userAgent;
|
|
@@ -54,9 +52,10 @@ class Tracks {
|
|
|
54
52
|
});
|
|
55
53
|
eventProps.is_vip = await (0, _apiConfig.checkIfUserIsVip)(); // Add `is_vip` flag to every Tracks event recorded
|
|
56
54
|
|
|
57
|
-
const event =
|
|
58
|
-
_en: name
|
|
59
|
-
|
|
55
|
+
const event = {
|
|
56
|
+
_en: name,
|
|
57
|
+
...eventProps
|
|
58
|
+
};
|
|
60
59
|
|
|
61
60
|
// For when we want to support batched events
|
|
62
61
|
const events = [event];
|
|
@@ -89,10 +88,13 @@ class Tracks {
|
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
// Resolve to false instead of rejecting
|
|
92
|
-
return
|
|
91
|
+
return false;
|
|
93
92
|
}
|
|
94
93
|
send(extraParams) {
|
|
95
|
-
const params =
|
|
94
|
+
const params = {
|
|
95
|
+
...this.baseParams,
|
|
96
|
+
...extraParams
|
|
97
|
+
};
|
|
96
98
|
const method = 'POST';
|
|
97
99
|
const body = _querystring.default.stringify(params);
|
|
98
100
|
const headers = {
|
|
@@ -100,8 +102,6 @@ class Tracks {
|
|
|
100
102
|
'User-Agent': this.userAgent
|
|
101
103
|
};
|
|
102
104
|
debug('send()', body);
|
|
103
|
-
|
|
104
|
-
// eslint-disable-next-line no-undef
|
|
105
105
|
return (0, _nodeFetch.default)(Tracks.ENDPOINT, {
|
|
106
106
|
method,
|
|
107
107
|
body,
|
|
@@ -5,15 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _debug = _interopRequireDefault(require("debug"));
|
|
8
|
-
var _stub = _interopRequireDefault(require("./clients/stub"));
|
|
9
8
|
var _env = _interopRequireDefault(require("../env"));
|
|
10
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
10
|
/**
|
|
12
11
|
* External dependencies
|
|
13
12
|
*/
|
|
13
|
+
|
|
14
14
|
/**
|
|
15
15
|
* Internal dependencies
|
|
16
16
|
*/
|
|
17
|
+
|
|
17
18
|
const debug = (0, _debug.default)('@automattic/vip:analytics');
|
|
18
19
|
|
|
19
20
|
/* eslint-disable camelcase */
|
|
@@ -26,23 +27,19 @@ const client_info = {
|
|
|
26
27
|
/* eslint-enable camelcase */
|
|
27
28
|
|
|
28
29
|
class Analytics {
|
|
29
|
-
constructor({
|
|
30
|
-
clients = new _stub.default()
|
|
31
|
-
}) {
|
|
30
|
+
constructor(clients) {
|
|
32
31
|
this.clients = clients;
|
|
33
32
|
}
|
|
34
33
|
async trackEvent(name, props = {}) {
|
|
35
34
|
if (process.env.DO_NOT_TRACK) {
|
|
36
35
|
debug(`trackEvent() for ${name} => skipping per DO_NOT_TRACK variable`);
|
|
37
|
-
return
|
|
36
|
+
return [];
|
|
38
37
|
}
|
|
39
|
-
return Promise.all(this.clients.map(client => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
}));
|
|
38
|
+
return Promise.all(this.clients.map(client => client.trackEvent(name, {
|
|
39
|
+
// eslint-disable-next-line camelcase
|
|
40
|
+
...client_info,
|
|
41
|
+
...props
|
|
42
|
+
})));
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
exports.default = Analytics;
|