@automattic/vip 3.22.4 → 3.22.6
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/assets/dev-env.lando.template.yml.ejs +4 -0
- package/dist/bin/vip-import-media-abort.js +3 -4
- package/dist/bin/vip-import-media.js +3 -4
- package/dist/bin/vip-import-sql.js +0 -1
- package/dist/bin/vip-import-validate-files.js +0 -3
- package/dist/bin/vip-logs.js +0 -2
- package/dist/bin/vip-slowlogs.js +0 -2
- package/dist/bin/vip-sync.js +3 -2
- package/dist/bin/vip-wp.js +4 -7
- package/dist/commands/backup-db.js +1 -6
- package/dist/commands/dev-env-sync-sql.js +1 -1
- package/dist/commands/export-sql.js +6 -5
- package/dist/commands/phpmyadmin.js +3 -14
- package/dist/commands/wp-ssh.js +2 -4
- package/dist/lib/api/app.js +2 -8
- package/dist/lib/api/feature-flags.js +2 -2
- package/dist/lib/api/http.js +16 -9
- package/dist/lib/api/user.js +1 -3
- package/dist/lib/api.js +24 -50
- package/dist/lib/app-logs/app-logs.js +1 -1
- package/dist/lib/app-slowlogs/app-slowlogs.js +1 -1
- package/dist/lib/cli/apiConfig.js +4 -7
- package/dist/lib/client-file-uploader.js +2 -3
- package/dist/lib/config/software.js +2 -4
- package/dist/lib/constants/dev-environment.js +1 -1
- package/dist/lib/dev-environment/dev-environment-cli.js +0 -2
- package/dist/lib/dev-environment/dev-environment-lando.js +1 -1
- package/dist/lib/envvar/api-get-all.js +1 -1
- package/dist/lib/envvar/api-list.js +1 -1
- package/dist/lib/http/proxy-agent.js +0 -2
- package/dist/lib/keychain.js +1 -1
- package/dist/lib/live-backup-copy.js +0 -3
- package/dist/lib/media-import/config.js +1 -1
- package/dist/lib/media-import/status.js +4 -1
- package/dist/lib/site-import/status.js +6 -1
- package/dist/lib/validations/is-multi-site.js +1 -1
- package/dist/lib/validations/is-multisite-domain-mapped.js +1 -1
- package/dist/lib/validations/sql.js +0 -1
- package/dist/lib/vip-import-validate-files.js +2 -8
- package/eslint.config.js +24 -0
- package/npm-shrinkwrap.json +4169 -13130
- package/package.json +7 -8
- package/.eslintrc.js +0 -22
|
@@ -7,10 +7,14 @@ proxy:
|
|
|
7
7
|
<% if ( multisite ) { %>
|
|
8
8
|
- '*.<%= siteSlug %>.<%= domain %>'
|
|
9
9
|
<% } %>
|
|
10
|
+
<% if ( phpmyadmin ) { %>
|
|
10
11
|
phpmyadmin:
|
|
11
12
|
- <%= siteSlug %>-pma.<%= domain %>
|
|
13
|
+
<% } %>
|
|
14
|
+
<% if ( mailpit ) { %>
|
|
12
15
|
mailpit:
|
|
13
16
|
- <%= siteSlug %>-mailpit.<%= domain %>:8025
|
|
17
|
+
<% } %>
|
|
14
18
|
|
|
15
19
|
keys: false
|
|
16
20
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
+
var _core = require("@apollo/client/core");
|
|
4
5
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
5
6
|
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
6
7
|
var _api = _interopRequireDefault(require("../lib/api"));
|
|
@@ -12,8 +13,6 @@ var _status = require("../lib/media-import/status");
|
|
|
12
13
|
var _tracker = require("../lib/tracker");
|
|
13
14
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
14
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
// eslint-disable-next-line no-duplicate-imports
|
|
16
|
-
|
|
17
16
|
const usage = 'vip import media abort';
|
|
18
17
|
const appQuery = `
|
|
19
18
|
id,
|
|
@@ -98,8 +97,8 @@ Aborting this media import.
|
|
|
98
97
|
progressTracker
|
|
99
98
|
});
|
|
100
99
|
} catch (error) {
|
|
101
|
-
if (error
|
|
102
|
-
for (const err of error.
|
|
100
|
+
if (_core.CombinedGraphQLErrors.is(error)) {
|
|
101
|
+
for (const err of error.errors) {
|
|
103
102
|
console.log(_chalk.default.red('Error:'), err.message);
|
|
104
103
|
}
|
|
105
104
|
return;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
+
var _core = require("@apollo/client/core");
|
|
4
5
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
5
6
|
var _debug = _interopRequireDefault(require("debug"));
|
|
6
7
|
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
@@ -13,8 +14,6 @@ var _status = require("../lib/media-import/status");
|
|
|
13
14
|
var _utils = require("../lib/media-import/utils");
|
|
14
15
|
var _tracker = require("../lib/tracker");
|
|
15
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
-
// eslint-disable-next-line no-duplicate-imports
|
|
17
|
-
|
|
18
17
|
const API_VERSION = 'v2';
|
|
19
18
|
const appQuery = `
|
|
20
19
|
id,
|
|
@@ -197,8 +196,8 @@ Importing Media into your App...
|
|
|
197
196
|
saveErrorLog
|
|
198
197
|
});
|
|
199
198
|
} catch (error) {
|
|
200
|
-
if (error
|
|
201
|
-
for (const err of error.
|
|
199
|
+
if (_core.CombinedGraphQLErrors.is(error)) {
|
|
200
|
+
for (const err of error.errors) {
|
|
202
201
|
console.log(_chalk.default.red('Error:'), err.message);
|
|
203
202
|
}
|
|
204
203
|
return;
|
|
@@ -359,7 +359,6 @@ const displayPlaybook = ({
|
|
|
359
359
|
}
|
|
360
360
|
let siteArray = [];
|
|
361
361
|
if (isMultiSite) {
|
|
362
|
-
// eslint-disable-next-line no-multi-spaces
|
|
363
362
|
console.log(` multisite: ${isMultiSite.toString()}`);
|
|
364
363
|
const selectedEnvironmentObj = app?.environments?.find(env => unformattedEnvironment === env.type);
|
|
365
364
|
siteArray = selectedEnvironmentObj?.wpSitesSDS?.nodes;
|
|
@@ -131,7 +131,6 @@ async function vipImportValidateFilesCmd(arg = []) {
|
|
|
131
131
|
|
|
132
132
|
// Tracks events to track activity
|
|
133
133
|
// Props (object keys) need to be in Snake case vs. camelCase
|
|
134
|
-
/* eslint-disable camelcase */
|
|
135
134
|
const allErrors = {
|
|
136
135
|
folder_errors_length: folderValidation.length,
|
|
137
136
|
int_images_errors_length: intermediateImagesTotal,
|
|
@@ -140,8 +139,6 @@ async function vipImportValidateFilesCmd(arg = []) {
|
|
|
140
139
|
total_files: files.length,
|
|
141
140
|
total_folders: nestedDirectories.length
|
|
142
141
|
};
|
|
143
|
-
/* eslint-enable camelcase */
|
|
144
|
-
|
|
145
142
|
await (0, _tracker.trackEvent)('import_validate_files_command_success', allErrors);
|
|
146
143
|
}
|
|
147
144
|
const usage = 'vip import validate-files';
|
package/dist/bin/vip-logs.js
CHANGED
|
@@ -67,8 +67,6 @@ async function followLogs(opt) {
|
|
|
67
67
|
|
|
68
68
|
// Set an initial default delay
|
|
69
69
|
let delay = DEFAULT_POLLING_DELAY_IN_SECONDS;
|
|
70
|
-
|
|
71
|
-
// eslint-disable-next-line no-constant-condition
|
|
72
70
|
while (true) {
|
|
73
71
|
const limit = isFirstRequest ? opt.limit : LIMIT_MAX;
|
|
74
72
|
requestNumber++;
|
package/dist/bin/vip-slowlogs.js
CHANGED
|
@@ -58,8 +58,6 @@ async function followLogs(opt) {
|
|
|
58
58
|
|
|
59
59
|
// Set an initial default delay
|
|
60
60
|
let delay = DEFAULT_POLLING_DELAY_IN_SECONDS;
|
|
61
|
-
|
|
62
|
-
// eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
|
|
63
61
|
while (true) {
|
|
64
62
|
const limit = isFirstRequest ? opt.limit : LIMIT_MAX;
|
|
65
63
|
requestNumber++;
|
package/dist/bin/vip-sync.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
+
var _core = require("@apollo/client/core");
|
|
4
5
|
var _singleLineLog = require("@wwa/single-line-log");
|
|
5
6
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
6
7
|
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
@@ -44,9 +45,9 @@ const appQuery = `id,name,environments{
|
|
|
44
45
|
}
|
|
45
46
|
});
|
|
46
47
|
} catch (error) {
|
|
47
|
-
if (error
|
|
48
|
+
if (_core.CombinedGraphQLErrors.is(error)) {
|
|
48
49
|
let bail = false;
|
|
49
|
-
for (const err of error.
|
|
50
|
+
for (const err of error.errors) {
|
|
50
51
|
if (err.message !== 'Site is already syncing') {
|
|
51
52
|
bail = true;
|
|
52
53
|
console.log(_chalk.default.red('Error:'), err.message);
|
package/dist/bin/vip-wp.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
+
var _core = require("@apollo/client/core");
|
|
4
5
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
5
6
|
var _debug = _interopRequireDefault(require("debug"));
|
|
6
7
|
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
@@ -331,8 +332,6 @@ const examples = [{
|
|
|
331
332
|
if ((0, _app.isAppNodejs)(appTypeId)) {
|
|
332
333
|
exit.withError('WP-CLI commands are not supported on Node.js environments.');
|
|
333
334
|
}
|
|
334
|
-
|
|
335
|
-
/* eslint-disable camelcase */
|
|
336
335
|
const commonTrackingParams = {
|
|
337
336
|
command: commandForAnalytics,
|
|
338
337
|
app_id: appId,
|
|
@@ -340,8 +339,6 @@ const examples = [{
|
|
|
340
339
|
org_id: orgId,
|
|
341
340
|
method: isSubShell ? 'subshell' : 'shell'
|
|
342
341
|
};
|
|
343
|
-
/* eslint-enable camelcase */
|
|
344
|
-
|
|
345
342
|
(0, _tracker.trackEvent)('wpcli_command_execute', commonTrackingParams).catch(() => {});
|
|
346
343
|
if (isSubShell) {
|
|
347
344
|
// Reset the cursor (can get messed up with enquirer)
|
|
@@ -441,10 +438,10 @@ const examples = [{
|
|
|
441
438
|
result = await getTokenForCommand(appId, envId, wpCliCmd);
|
|
442
439
|
} catch (error) {
|
|
443
440
|
// If this was a GraphQL error, print that to the message to the line
|
|
444
|
-
if (error
|
|
445
|
-
|
|
441
|
+
if (_core.CombinedGraphQLErrors.is(error)) {
|
|
442
|
+
for (const err of error.errors) {
|
|
446
443
|
console.log(_chalk.default.red('Error:'), err.message);
|
|
447
|
-
}
|
|
444
|
+
}
|
|
448
445
|
} else {
|
|
449
446
|
// Else, other type of error, just dump it
|
|
450
447
|
console.log(error);
|
|
@@ -53,12 +53,7 @@ async function getBackupJob(appId, envId) {
|
|
|
53
53
|
},
|
|
54
54
|
fetchPolicy: 'network-only'
|
|
55
55
|
});
|
|
56
|
-
|
|
57
|
-
data: {
|
|
58
|
-
app
|
|
59
|
-
}
|
|
60
|
-
} = response;
|
|
61
|
-
return app?.environments?.[0]?.jobs?.[0];
|
|
56
|
+
return response.data?.app?.environments?.[0]?.jobs?.[0] ?? undefined;
|
|
62
57
|
}
|
|
63
58
|
async function createBackupJob(appId, envId) {
|
|
64
59
|
// Disable global error handling so that we can handle errors ourselves
|
|
@@ -214,7 +214,7 @@ class DevEnvSyncSQLCommand {
|
|
|
214
214
|
do {
|
|
215
215
|
// eslint-disable-next-line no-await-in-loop
|
|
216
216
|
const res = await this.fetchSitesPage(api, appId, environmentId, after);
|
|
217
|
-
if (res.data
|
|
217
|
+
if (res.data?.app?.environments?.[0]?.wpSitesSDS?.nodes) {
|
|
218
218
|
const wpSitesSDS = res.data.app.environments[0].wpSitesSDS;
|
|
219
219
|
allSites.push(...res.data.app.environments[0].wpSitesSDS.nodes.filter(node => Boolean(node)));
|
|
220
220
|
after = wpSitesSDS.nextCursor;
|
|
@@ -97,10 +97,11 @@ async function fetchLatestBackupAndJobStatusBase(appId, envId) {
|
|
|
97
97
|
},
|
|
98
98
|
fetchPolicy: 'network-only'
|
|
99
99
|
});
|
|
100
|
-
const environments = response.data
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
const
|
|
100
|
+
const environments = response.data?.app?.environments;
|
|
101
|
+
const firstEnvironment = environments?.[0];
|
|
102
|
+
const envSqlDumpTool = firstEnvironment?.backupsSqlDumpTool;
|
|
103
|
+
const latestBackup = firstEnvironment?.latestBackup ?? undefined;
|
|
104
|
+
const jobs = firstEnvironment?.jobs || [];
|
|
104
105
|
return {
|
|
105
106
|
latestBackup,
|
|
106
107
|
jobs,
|
|
@@ -141,7 +142,7 @@ async function generateDownloadLink(appId, envId, backupId) {
|
|
|
141
142
|
}
|
|
142
143
|
}
|
|
143
144
|
});
|
|
144
|
-
return response.data?.generateDBBackupCopyUrl?.url;
|
|
145
|
+
return response.data?.generateDBBackupCopyUrl?.url ?? '';
|
|
145
146
|
}
|
|
146
147
|
|
|
147
148
|
/**
|
|
@@ -48,7 +48,6 @@ async function generatePhpMyAdminAccess(envId) {
|
|
|
48
48
|
// Disable global error handling so that we can handle errors ourselves
|
|
49
49
|
(0, _api.disableGlobalGraphQLErrorHandling)();
|
|
50
50
|
const api = (0, _api.default)();
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
51
|
const resp = await api.mutate({
|
|
53
52
|
mutation: GENERATE_PHP_MY_ADMIN_URL_MUTATION,
|
|
54
53
|
variables: {
|
|
@@ -60,16 +59,13 @@ async function generatePhpMyAdminAccess(envId) {
|
|
|
60
59
|
|
|
61
60
|
// Re-enable global error handling
|
|
62
61
|
(0, _api.enableGlobalGraphQLErrorHandling)();
|
|
63
|
-
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
65
|
-
return resp?.data?.generatePHPMyAdminAccess?.url;
|
|
62
|
+
return resp.data?.generatePHPMyAdminAccess?.url ?? '';
|
|
66
63
|
}
|
|
67
64
|
async function enablePhpMyAdmin(envId) {
|
|
68
65
|
// Disable global error handling so that we can handle errors ourselves
|
|
69
66
|
(0, _api.disableGlobalGraphQLErrorHandling)();
|
|
70
67
|
const api = (0, _api.default)();
|
|
71
|
-
|
|
72
|
-
const resp = await api.mutate({
|
|
68
|
+
await api.mutate({
|
|
73
69
|
mutation: ENABLE_PHP_MY_ADMIN_MUTATION,
|
|
74
70
|
variables: {
|
|
75
71
|
input: {
|
|
@@ -80,16 +76,11 @@ async function enablePhpMyAdmin(envId) {
|
|
|
80
76
|
|
|
81
77
|
// Re-enable global error handling
|
|
82
78
|
(0, _api.enableGlobalGraphQLErrorHandling)();
|
|
83
|
-
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
85
|
-
return resp?.data?.generatePHPMyAdminAccess?.url;
|
|
86
79
|
}
|
|
87
80
|
async function getPhpMyAdminStatus(appId, envId) {
|
|
88
81
|
// Disable global error handling so that we can handle errors ourselves
|
|
89
82
|
(0, _api.disableGlobalGraphQLErrorHandling)();
|
|
90
83
|
const api = (0, _api.default)();
|
|
91
|
-
|
|
92
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
93
84
|
const resp = await api.query({
|
|
94
85
|
query: GET_PHP_MY_ADMIN_STATUS_QUERY,
|
|
95
86
|
variables: {
|
|
@@ -101,9 +92,7 @@ async function getPhpMyAdminStatus(appId, envId) {
|
|
|
101
92
|
|
|
102
93
|
// Re-enable global error handling
|
|
103
94
|
(0, _api.enableGlobalGraphQLErrorHandling)();
|
|
104
|
-
|
|
105
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
106
|
-
return resp?.data?.app?.environments?.[0]?.phpMyAdminStatus?.status;
|
|
95
|
+
return resp.data?.app?.environments?.[0]?.phpMyAdminStatus?.status ?? '';
|
|
107
96
|
}
|
|
108
97
|
class PhpMyAdminCommand {
|
|
109
98
|
silent;
|
package/dist/commands/wp-ssh.js
CHANGED
|
@@ -209,10 +209,8 @@ class WPCliCommandOverSSH {
|
|
|
209
209
|
}
|
|
210
210
|
});
|
|
211
211
|
} catch (error) {
|
|
212
|
-
if (
|
|
213
|
-
const message = error.
|
|
214
|
-
return err.message;
|
|
215
|
-
}).join('; ');
|
|
212
|
+
if (_core.CombinedGraphQLErrors.is(error)) {
|
|
213
|
+
const message = error.errors.map(err => err.message).join('; ');
|
|
216
214
|
throw new APIError(message);
|
|
217
215
|
}
|
|
218
216
|
const message = error instanceof Error ? error.message : String(error);
|
package/dist/lib/api/app.js
CHANGED
|
@@ -23,10 +23,7 @@ async function _default(app, fields = 'id,name', fragments = '') {
|
|
|
23
23
|
name: app
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
|
-
|
|
27
|
-
return {};
|
|
28
|
-
}
|
|
29
|
-
return res.data.apps.edges[0];
|
|
26
|
+
return res.data?.apps?.edges?.[0] ?? {};
|
|
30
27
|
}
|
|
31
28
|
if (typeof app === 'string') {
|
|
32
29
|
app = parseInt(app, 10);
|
|
@@ -51,8 +48,5 @@ async function _default(app, fields = 'id,name', fragments = '') {
|
|
|
51
48
|
};
|
|
52
49
|
}
|
|
53
50
|
const res = await api.query(appQuery);
|
|
54
|
-
|
|
55
|
-
return {};
|
|
56
|
-
}
|
|
57
|
-
return res.data.app;
|
|
51
|
+
return res.data?.app ?? {};
|
|
58
52
|
}
|
package/dist/lib/api/http.js
CHANGED
|
@@ -31,17 +31,24 @@ var _default = async (path, options = {}) => {
|
|
|
31
31
|
const authToken = await _token.default.get();
|
|
32
32
|
const proxyAgent = (0, _proxyAgent.createProxyAgent)(url);
|
|
33
33
|
debug('running fetch', url);
|
|
34
|
-
|
|
34
|
+
const headers = new Headers({
|
|
35
|
+
...options.headers
|
|
36
|
+
});
|
|
37
|
+
if (!headers.has('Authorization')) {
|
|
38
|
+
headers.set('Authorization', `Bearer ${authToken.raw}`);
|
|
39
|
+
}
|
|
40
|
+
if (!headers.has('User-Agent')) {
|
|
41
|
+
headers.set('User-Agent', _env.default.userAgent);
|
|
42
|
+
}
|
|
43
|
+
if (!headers.has('Content-Type') && options.method !== 'GET') {
|
|
44
|
+
headers.set('Content-Type', 'application/json');
|
|
45
|
+
}
|
|
46
|
+
const opts = {
|
|
35
47
|
...options,
|
|
36
48
|
agent: proxyAgent ?? undefined,
|
|
37
|
-
headers
|
|
38
|
-
Authorization: `Bearer ${authToken.raw}`,
|
|
39
|
-
'User-Agent': _env.default.userAgent,
|
|
40
|
-
'Content-Type': 'application/json',
|
|
41
|
-
...(options.headers ?? {})
|
|
42
|
-
},
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
49
|
+
headers,
|
|
44
50
|
body: typeof options.body === 'object' ? JSON.stringify(options.body) : options.body
|
|
45
|
-
}
|
|
51
|
+
};
|
|
52
|
+
return (0, _nodeFetch.default)(url, opts);
|
|
46
53
|
};
|
|
47
54
|
exports.default = _default;
|
package/dist/lib/api/user.js
CHANGED
|
@@ -28,9 +28,7 @@ async function getCurrentUserInfo(silenceAuthErrors = false) {
|
|
|
28
28
|
const response = await api.query({
|
|
29
29
|
query: QUERY_CURRENT_USER
|
|
30
30
|
});
|
|
31
|
-
const
|
|
32
|
-
me
|
|
33
|
-
} = response.data;
|
|
31
|
+
const me = response.data?.me;
|
|
34
32
|
if (!me) {
|
|
35
33
|
throw new Error('The API did not return any information about the user.');
|
|
36
34
|
}
|
package/dist/lib/api.js
CHANGED
|
@@ -7,21 +7,16 @@ exports.disableGlobalGraphQLErrorHandling = disableGlobalGraphQLErrorHandling;
|
|
|
7
7
|
exports.enableGlobalGraphQLErrorHandling = enableGlobalGraphQLErrorHandling;
|
|
8
8
|
exports.shouldRetryRequest = shouldRetryRequest;
|
|
9
9
|
var _core = require("@apollo/client/core");
|
|
10
|
-
var _context = require("@apollo/client/link/context");
|
|
11
|
-
var _core2 = require("@apollo/client/link/core");
|
|
12
10
|
var _error = require("@apollo/client/link/error");
|
|
13
11
|
var _retry = require("@apollo/client/link/retry");
|
|
14
12
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
15
13
|
var _debug = _interopRequireDefault(require("debug"));
|
|
14
|
+
var _graphql = require("graphql");
|
|
16
15
|
var _nodeFetch = require("node-fetch");
|
|
17
16
|
var _http = _interopRequireDefault(require("./api/http"));
|
|
18
|
-
var _env = _interopRequireDefault(require("./env"));
|
|
19
|
-
var _token = _interopRequireDefault(require("./token"));
|
|
20
|
-
var _proxyAgent = require("../lib/http/proxy-agent");
|
|
21
17
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
18
|
// Config
|
|
23
19
|
const PRODUCTION_API_HOST = exports.PRODUCTION_API_HOST = 'https://api.wpvip.com';
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
25
20
|
const API_HOST = exports.API_HOST = process.env.API_HOST || PRODUCTION_API_HOST; // NOSONAR
|
|
26
21
|
const API_URL = exports.API_URL = `${API_HOST}/graphql`;
|
|
27
22
|
let globalGraphQLErrorHandlingEnabled = true;
|
|
@@ -38,7 +33,7 @@ function enableGlobalGraphQLErrorHandling() {
|
|
|
38
33
|
}
|
|
39
34
|
function shouldRetryRequest(attempt, operation, error) {
|
|
40
35
|
const debugSuffix = `Operation: ${operation.operationName}. Attempt: ${attempt}.`;
|
|
41
|
-
if (!error || operation.query.definitions.some(def => def.kind ===
|
|
36
|
+
if (!error || operation.query.definitions.some(def => def.kind === _graphql.Kind.OPERATION_DEFINITION && def.operation !== _graphql.OperationTypeNode.QUERY)) {
|
|
42
37
|
debug(`Request failed. ${debugSuffix}`);
|
|
43
38
|
return false;
|
|
44
39
|
}
|
|
@@ -58,71 +53,50 @@ function shouldRetryRequest(attempt, operation, error) {
|
|
|
58
53
|
debug(`Request failed. Retrying request due to server error. ${debugSuffix}`, error);
|
|
59
54
|
return true;
|
|
60
55
|
}
|
|
61
|
-
function isServerError(networkError) {
|
|
62
|
-
if (!networkError) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
return 'result' in networkError;
|
|
66
|
-
}
|
|
67
56
|
function API({
|
|
68
57
|
exitOnError = true,
|
|
69
58
|
silenceAuthErrors = false,
|
|
70
59
|
customRetryLink
|
|
71
60
|
} = {}) {
|
|
72
|
-
const errorLink =
|
|
73
|
-
|
|
74
|
-
graphQLErrors
|
|
61
|
+
const errorLink = new _error.ErrorLink(({
|
|
62
|
+
error
|
|
75
63
|
}) => {
|
|
76
|
-
if (!silenceAuthErrors &&
|
|
77
|
-
let message
|
|
78
|
-
|
|
79
|
-
|
|
64
|
+
if (!silenceAuthErrors && error instanceof _core.ServerError && error.statusCode === 401) {
|
|
65
|
+
let message;
|
|
66
|
+
try {
|
|
67
|
+
const result = JSON.parse(error.bodyText);
|
|
68
|
+
if (typeof result === 'object' && result !== null && 'code' in result && result?.code === 'token-disabled-inactivity') {
|
|
69
|
+
message = 'Your token has expired due to inactivity';
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
// If we can't parse the body, use the default message
|
|
73
|
+
message = 'You are not authorized to perform this request';
|
|
80
74
|
}
|
|
75
|
+
message += '; please log out with `vip logout`, then try again.';
|
|
81
76
|
console.error(_chalk.default.red('Unauthorized:'), message);
|
|
82
77
|
process.exit(1);
|
|
83
78
|
}
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
console.error(_chalk.default.red('Error:'),
|
|
87
|
-
}
|
|
79
|
+
if (_core.CombinedGraphQLErrors.is(error) && globalGraphQLErrorHandlingEnabled) {
|
|
80
|
+
for (const err of error.errors) {
|
|
81
|
+
console.error(_chalk.default.red('Error:'), err.message);
|
|
82
|
+
}
|
|
88
83
|
if (exitOnError) {
|
|
89
84
|
process.exit(1);
|
|
90
85
|
}
|
|
91
86
|
}
|
|
92
87
|
});
|
|
93
|
-
const withToken = (0, _context.setContext)(async () => {
|
|
94
|
-
const token = (await _token.default.get()).raw;
|
|
95
|
-
return {
|
|
96
|
-
token
|
|
97
|
-
};
|
|
98
|
-
});
|
|
99
|
-
const authLink = new _core2.ApolloLink((operation, forward) => {
|
|
100
|
-
const ctx = operation.getContext();
|
|
101
|
-
const headers = {
|
|
102
|
-
'User-Agent': _env.default.userAgent,
|
|
103
|
-
Authorization: `Bearer ${ctx.token}`,
|
|
104
|
-
...ctx.headers
|
|
105
|
-
};
|
|
106
|
-
operation.setContext({
|
|
107
|
-
headers
|
|
108
|
-
});
|
|
109
|
-
return forward(operation);
|
|
110
|
-
});
|
|
111
|
-
const proxyAgent = (0, _proxyAgent.createProxyAgent)(API_URL);
|
|
112
88
|
const httpLink = new _core.HttpLink({
|
|
113
89
|
uri: operation => {
|
|
114
90
|
// to make it easier to write tests, we'll skip adding x_query for tests
|
|
115
91
|
if (process.env.NODE_ENV === 'test') {
|
|
116
92
|
return API_URL;
|
|
117
93
|
}
|
|
118
|
-
|
|
94
|
+
const operationName = operation.operationName ?? '';
|
|
95
|
+
return `${API_URL}?x_query=${encodeURIComponent(operationName)}`;
|
|
119
96
|
},
|
|
120
|
-
fetch: _http.default
|
|
121
|
-
fetchOptions: {
|
|
122
|
-
agent: proxyAgent
|
|
123
|
-
}
|
|
97
|
+
fetch: _http.default
|
|
124
98
|
});
|
|
125
|
-
const retryLink = new _retry.RetryLink({
|
|
99
|
+
const retryLink = customRetryLink ?? new _retry.RetryLink({
|
|
126
100
|
delay: {
|
|
127
101
|
initial: RETRY_LINK_INITIAL_DELAY_MS,
|
|
128
102
|
max: RETRY_LINK_MAX_DELAY_MS
|
|
@@ -130,7 +104,7 @@ function API({
|
|
|
130
104
|
attempts: shouldRetryRequest
|
|
131
105
|
});
|
|
132
106
|
return new _core.ApolloClient({
|
|
133
|
-
link:
|
|
107
|
+
link: _core.ApolloLink.from([errorLink, retryLink, httpLink]),
|
|
134
108
|
cache: new _core.InMemoryCache({
|
|
135
109
|
typePolicies: {
|
|
136
110
|
WPSite: {
|
|
@@ -44,7 +44,7 @@ async function getRecentLogs(appId, envId, type, limit, after) {
|
|
|
44
44
|
after
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
|
-
const logs = response.data
|
|
47
|
+
const logs = response.data?.app?.environments?.[0]?.logs;
|
|
48
48
|
if (!logs?.nodes) {
|
|
49
49
|
throw new Error('Unable to query logs');
|
|
50
50
|
}
|
|
@@ -41,7 +41,7 @@ async function getRecentSlowlogs(appId, envId, limit, after) {
|
|
|
41
41
|
after
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
|
-
const slowlogs = response.data
|
|
44
|
+
const slowlogs = response.data?.app?.environments?.[0]?.slowlogs;
|
|
45
45
|
if (!slowlogs?.nodes) {
|
|
46
46
|
throw new Error('Unable to query slowlogs');
|
|
47
47
|
}
|
|
@@ -20,11 +20,8 @@ async function checkFeatureEnabled(featureName, exitOnFalse = false) {
|
|
|
20
20
|
let isVIP;
|
|
21
21
|
try {
|
|
22
22
|
const res = await featureFlags.get();
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} else {
|
|
26
|
-
isVIP = false;
|
|
27
|
-
}
|
|
23
|
+
const data = res?.data;
|
|
24
|
+
isVIP = Boolean(data?.me?.isVIP);
|
|
28
25
|
} catch (err) {
|
|
29
26
|
const message = err.toString();
|
|
30
27
|
await (0, _tracker.trackEvent)('checkFeatureEnabled_fetch_error', {
|
|
@@ -47,10 +44,10 @@ async function checkIfUserIsVip() {
|
|
|
47
44
|
const token = await _token.default.get();
|
|
48
45
|
if (token.valid()) {
|
|
49
46
|
const res = await featureFlags.get();
|
|
50
|
-
return Boolean(res?.
|
|
47
|
+
return Boolean(res.data?.me?.isVIP);
|
|
51
48
|
}
|
|
52
49
|
return false;
|
|
53
50
|
}
|
|
54
|
-
|
|
51
|
+
function exitWhenFeatureDisabled(featureName) {
|
|
55
52
|
return checkFeatureEnabled(featureName, true);
|
|
56
53
|
}
|
|
@@ -31,7 +31,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
31
31
|
// Need to use CommonJS imports here as the `fetch-retry` typedefs are messed up and throwing TypeJS errors when using `import`
|
|
32
32
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
33
33
|
const fetchWithRetry =
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-require-imports
|
|
35
35
|
require('fetch-retry')(_nodeFetch.default, {
|
|
36
36
|
// Set default retry options
|
|
37
37
|
retries: 3,
|
|
@@ -96,8 +96,6 @@ const unzipFile = async (inputFilename, outputFilename) => {
|
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
98
|
const extractionInfo = extractFunctions[mimeType];
|
|
99
|
-
|
|
100
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
101
99
|
if (!extractionInfo) {
|
|
102
100
|
throw new Error(`unsupported file format: ${mimeType}`);
|
|
103
101
|
}
|
|
@@ -560,6 +558,7 @@ async function completeMultipartUpload({
|
|
|
560
558
|
});
|
|
561
559
|
const completeMultipartUploadResponse = await fetchWithRetry(completeMultipartUploadRequestData.url, completeMultipartUploadRequestData.options);
|
|
562
560
|
if (completeMultipartUploadResponse.status !== 200) {
|
|
561
|
+
// eslint-disable-next-line @typescript-eslint/only-throw-error
|
|
563
562
|
throw await completeMultipartUploadResponse.text();
|
|
564
563
|
}
|
|
565
564
|
|
|
@@ -229,9 +229,7 @@ const _processComponentVersion = (softwareSettings, component, userProvidedVersi
|
|
|
229
229
|
const promptForUpdate = async (appTypeId, opts, softwareSettings) => {
|
|
230
230
|
const component = await _processComponent(appTypeId, opts.component);
|
|
231
231
|
const version = await _processComponentVersion(softwareSettings, component, opts.version);
|
|
232
|
-
const confirm =
|
|
233
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
234
|
-
opts.force || (
|
|
232
|
+
const confirm = opts.force || (
|
|
235
233
|
// NOSONAR
|
|
236
234
|
await new _enquirer.Confirm({
|
|
237
235
|
message: `Are you sure you want to upgrade ${COMPONENT_NAMES[component]} to ${version}?`
|
|
@@ -266,7 +264,7 @@ const _getLatestJob = async (appId, envId) => {
|
|
|
266
264
|
},
|
|
267
265
|
fetchPolicy: 'network-only'
|
|
268
266
|
});
|
|
269
|
-
const jobs = result.data
|
|
267
|
+
const jobs = result.data?.app?.environments?.[0]?.jobs ?? [];
|
|
270
268
|
if (jobs.length) {
|
|
271
269
|
return jobs.reduce((prev, current) => (prev?.createdAt || '') > (current?.createdAt || '') ? prev : current);
|
|
272
270
|
}
|
|
@@ -40,4 +40,4 @@ const DEV_ENVIRONMENT_DEFAULTS = exports.DEV_ENVIRONMENT_DEFAULTS = {
|
|
|
40
40
|
multisite: false,
|
|
41
41
|
phpVersion: Object.keys(DEV_ENVIRONMENT_PHP_VERSIONS)[0]
|
|
42
42
|
};
|
|
43
|
-
const DEV_ENVIRONMENT_VERSION = exports.DEV_ENVIRONMENT_VERSION = '2.3.
|
|
43
|
+
const DEV_ENVIRONMENT_VERSION = exports.DEV_ENVIRONMENT_VERSION = '2.3.2';
|
|
@@ -171,7 +171,6 @@ function getOptionsFromAppInfo(appInfo) {
|
|
|
171
171
|
const integrationsConfig = appInfo.environment?.integrations ?? {};
|
|
172
172
|
const hasES = integrationsConfig['enterprise-search']?.env?.status === 'enabled';
|
|
173
173
|
return {
|
|
174
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
175
174
|
title: appInfo.environment?.name || appInfo.name || '',
|
|
176
175
|
// NOSONAR
|
|
177
176
|
multisite: Boolean(appInfo.environment?.isMultisite),
|
|
@@ -393,7 +392,6 @@ function validateAppCodeLocalPath(providedPath) {
|
|
|
393
392
|
}
|
|
394
393
|
}
|
|
395
394
|
if (missingFiles.length > 0) {
|
|
396
|
-
// eslint-disable-next-line max-len
|
|
397
395
|
const message = `Provided path "${providedPath}" is missing following files/folders: ${missingFiles.join(', ')}. Learn more: https://docs.wpvip.com/wordpress-skeleton/`;
|
|
398
396
|
return {
|
|
399
397
|
result: false,
|
|
@@ -589,7 +589,7 @@ function validateDockerInstalled(lando) {
|
|
|
589
589
|
if (!compose) {
|
|
590
590
|
throw new Error('docker-compose binary could not be located! Please follow the following instructions to install it - https://docs.docker.com/compose/install/');
|
|
591
591
|
}
|
|
592
|
-
if (!(0, _semver.satisfies)(compose, '
|
|
592
|
+
if (!(0, _semver.satisfies)(compose, '>=2.0.0')) {
|
|
593
593
|
throw new Error(`docker-compose version ${compose} is not supported. Please upgrade to version 2.0.0 or higher - https://docs.docker.com/compose/install/`);
|
|
594
594
|
}
|
|
595
595
|
}
|