@automattic/vip 3.21.0 → 3.21.2

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.
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.WPCliCommandOverSSH = exports.NonZeroExitCodeError = void 0;
4
+ exports.WPCliCommandOverSSH = exports.NonZeroExitCodeError = exports.APIError = void 0;
5
+ var _core = require("@apollo/client/core");
5
6
  var _chalk = _interopRequireDefault(require("chalk"));
6
7
  var _debug = _interopRequireDefault(require("debug"));
7
8
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
@@ -41,13 +42,17 @@ const TRIGGER_WP_CLI_COMMAND_MUTATION = (0, _graphqlTag.default)`
41
42
  }
42
43
  `;
43
44
  class NonZeroExitCodeError extends Error {
45
+ guid;
44
46
  exitCode;
45
- constructor(message, exitCode) {
47
+ constructor(message, guid, exitCode) {
46
48
  super(message);
49
+ this.guid = guid;
47
50
  this.exitCode = exitCode;
48
51
  }
49
52
  }
50
53
  exports.NonZeroExitCodeError = NonZeroExitCodeError;
54
+ class APIError extends Error {}
55
+ exports.APIError = APIError;
51
56
  class WPCliCommandOverSSH {
52
57
  track;
53
58
  constructor(app, env) {
@@ -69,23 +74,23 @@ class WPCliCommandOverSSH {
69
74
  throw new Error('No app ID or environment ID provided');
70
75
  }
71
76
  debug("Requesting SSH authentication for command '%s'", command);
72
- const sshAuth = await this.getSSHAuthForCommand(command, extraTrackingInfo);
73
- const data = sshAuth.data?.triggerWPCLICommandOnAppEnvironment;
74
- if (!data) {
75
- await this.track('error', {
76
- error: 'no_ssh_auth_data',
77
- message: 'No SSH authentication data received',
78
- ...extraTrackingInfo
79
- });
80
- throw new Error('WP-CLI SSH Authentication failed');
81
- }
82
- debug('Connecting to SSH', {
83
- host: data.sshAuthentication.host,
84
- port: data.sshAuthentication.port,
85
- username: data.sshAuthentication.username,
86
- guid: data.command.guid
87
- });
88
77
  try {
78
+ const sshAuth = await this.getSSHAuthForCommand(command, extraTrackingInfo);
79
+ const data = sshAuth.data?.triggerWPCLICommandOnAppEnvironment;
80
+ if (!data) {
81
+ await this.track('error', {
82
+ error: 'no_ssh_auth_data',
83
+ message: 'No SSH authentication data received',
84
+ ...extraTrackingInfo
85
+ });
86
+ throw new Error('WP-CLI SSH Authentication failed');
87
+ }
88
+ debug('Connecting to SSH', {
89
+ host: data.sshAuthentication.host,
90
+ port: data.sshAuthentication.port,
91
+ username: data.sshAuthentication.username,
92
+ guid: data.command.guid
93
+ });
89
94
  await this.executeCommandOverSSH({
90
95
  host: data.sshAuthentication.host,
91
96
  port: data.sshAuthentication.port,
@@ -101,19 +106,26 @@ class WPCliCommandOverSSH {
101
106
  } catch (err) {
102
107
  if (err instanceof NonZeroExitCodeError) {
103
108
  await this.track('error', {
104
- guid: data?.command.guid,
109
+ guid: err.guid,
105
110
  error: 'non_zero_exit_code',
106
111
  message: `Command failed with exit code ${err.exitCode}`,
107
112
  ...extraTrackingInfo
108
113
  });
109
114
  process.exit(err.exitCode);
115
+ } else if (err instanceof APIError) {
116
+ console.error(`${_chalk.default.red('Error:')} ${err.message}`);
117
+ await this.track('error', {
118
+ error: 'api_error',
119
+ message: `API Error: ${err.message}`,
120
+ ...extraTrackingInfo
121
+ });
122
+ process.exit(1);
110
123
  }
111
124
  const message = err instanceof Error ? err.message : String(err);
112
125
  console.error(`${_chalk.default.red('Error:')} ${message}`);
113
126
  await this.track('error', {
114
- guid: data?.command.guid,
115
127
  error: 'ssh_command_failed',
116
- message: 'Error executing command over SSH',
128
+ message: `Error executing command over SSH: ${message}`,
117
129
  ...extraTrackingInfo
118
130
  });
119
131
  process.exit(1);
@@ -142,7 +154,7 @@ class WPCliCommandOverSSH {
142
154
  }
143
155
  stream.on('exit', exitCode => {
144
156
  if (exitCode !== 0) {
145
- reject(new NonZeroExitCodeError(`Command failed`, exitCode));
157
+ reject(new NonZeroExitCodeError(`Command failed`, guid, exitCode));
146
158
  }
147
159
  });
148
160
  commandStarted = true;
@@ -197,6 +209,12 @@ class WPCliCommandOverSSH {
197
209
  }
198
210
  });
199
211
  } catch (error) {
212
+ if (error instanceof _core.ApolloError) {
213
+ const message = error.graphQLErrors.map(err => {
214
+ return err.message;
215
+ }).join('; ');
216
+ throw new APIError(message);
217
+ }
200
218
  const message = error instanceof Error ? error.message : String(error);
201
219
  await this.track('error', {
202
220
  error: 'trigger_failed',
@@ -28,7 +28,7 @@ const DEV_ENVIRONMENT_PHP_VERSIONS = exports.DEV_ENVIRONMENT_PHP_VERSIONS = {
28
28
  },
29
29
  8.4: {
30
30
  image: 'ghcr.io/automattic/vip-container-images/php-fpm:8.4',
31
- label: '8.4 (experimental)'
31
+ label: '8.4'
32
32
  }
33
33
  };
34
34
  const DEV_ENVIRONMENT_DEFAULTS = exports.DEV_ENVIRONMENT_DEFAULTS = {
@@ -36,4 +36,4 @@ const DEV_ENVIRONMENT_DEFAULTS = exports.DEV_ENVIRONMENT_DEFAULTS = {
36
36
  multisite: false,
37
37
  phpVersion: Object.keys(DEV_ENVIRONMENT_PHP_VERSIONS)[0]
38
38
  };
39
- const DEV_ENVIRONMENT_VERSION = exports.DEV_ENVIRONMENT_VERSION = '2.3.0';
39
+ const DEV_ENVIRONMENT_VERSION = exports.DEV_ENVIRONMENT_VERSION = '2.3.1';
@@ -30,11 +30,11 @@ var _enquirer = require("enquirer");
30
30
  var _graphql = require("graphql");
31
31
  var _utils = require("lando/lib/utils");
32
32
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
33
+ var _nodeCrypto = require("node:crypto");
33
34
  var _nodeFs = _interopRequireDefault(require("node:fs"));
34
35
  var _promises = require("node:fs/promises");
35
36
  var _nodePath = _interopRequireDefault(require("node:path"));
36
37
  var _semver = _interopRequireDefault(require("semver"));
37
- var _uuid = require("uuid");
38
38
  var _devEnvironmentCli = require("./dev-environment-cli");
39
39
  var _devEnvironmentLando = require("./dev-environment-lando");
40
40
  var _app = _interopRequireDefault(require("../api/app"));
@@ -137,7 +137,7 @@ function preProcessInstanceData(instanceData) {
137
137
  cron: Boolean(instanceData.cron),
138
138
  mailpit: Boolean(instanceData.mailpit),
139
139
  pullAfter: instanceData.pullAfter ?? 0,
140
- autologinKey: (0, _uuid.v4)(),
140
+ autologinKey: (0, _nodeCrypto.randomUUID)(),
141
141
  adminPassword: instanceData.adminPassword ?? 'password',
142
142
  version: _devEnvironment.DEV_ENVIRONMENT_VERSION,
143
143
  overrides: instanceData.overrides ?? ''
@@ -863,7 +863,7 @@ ${Object.entries(pathMappings).map(([serverPath, localPath]) => ` <mapping
863
863
  </component>
864
864
  <component name="PhpServers">
865
865
  <servers>
866
- <server host="localhost" id="${(0, _uuid.v4)()}" name="localhost" use_path_mappings="true">
866
+ <server host="localhost" id="${(0, _nodeCrypto.randomUUID)()}" name="localhost" use_path_mappings="true">
867
867
  <path_mappings>
868
868
  <mapping local-root="$PROJECT_DIR$/wordpress" remote-root="/wp" />
869
869
  ${Object.entries(pathMappings).map(([serverPath, localPath]) => `<mapping local-root="${localPath}" remote-root="${serverPath}" />`).join('\n')}
@@ -137,7 +137,7 @@ async function getDownloadURL({
137
137
  }
138
138
  return {
139
139
  url: result.data.generateLiveBackupCopyDownloadURL.url,
140
- size: result.data.generateLiveBackupCopyDownloadURL.size
140
+ size: Number(result.data.generateLiveBackupCopyDownloadURL.size)
141
141
  };
142
142
  } catch (error) {
143
143
  if (error instanceof _utils.PollingTimeoutError) {
package/dist/lib/token.js CHANGED
@@ -3,7 +3,7 @@
3
3
  exports.__esModule = true;
4
4
  exports.default = exports.SERVICE = void 0;
5
5
  var _jwtDecode = require("jwt-decode");
6
- var _uuid2 = require("uuid");
6
+ var _nodeCrypto = require("node:crypto");
7
7
  var _api = require("./api");
8
8
  var _keychain = _interopRequireDefault(require("./keychain"));
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -64,7 +64,7 @@ class Token {
64
64
  const service = Token.getServiceName('-uuid');
65
65
  let _uuid = await _keychain.default.getPassword(service);
66
66
  if (!_uuid) {
67
- _uuid = (0, _uuid2.v4)();
67
+ _uuid = (0, _nodeCrypto.randomUUID)();
68
68
  await _keychain.default.setPassword(service, _uuid);
69
69
  }
70
70
  return _uuid;
package/dist/lib/utils.js CHANGED
@@ -6,6 +6,7 @@ exports.getAbsolutePath = getAbsolutePath;
6
6
  exports.makeTempDir = makeTempDir;
7
7
  exports.parseApiError = parseApiError;
8
8
  exports.pollUntil = pollUntil;
9
+ exports.splitKeyValueString = splitKeyValueString;
9
10
  var _debug = _interopRequireDefault(require("debug"));
10
11
  var _fs = _interopRequireDefault(require("fs"));
11
12
  var _promises = require("node:timers/promises");
@@ -95,4 +96,13 @@ function parseApiError(err) {
95
96
  return err?.message;
96
97
  }
97
98
  return null;
99
+ }
100
+ function splitKeyValueString(str, delimiter = '=') {
101
+ const delimiterIndex = str.indexOf(delimiter);
102
+ if (delimiterIndex === -1) {
103
+ return [str.trim(), ''];
104
+ }
105
+ const key = str.slice(0, delimiterIndex).trim();
106
+ const value = str.slice(delimiterIndex + delimiter.length).trim();
107
+ return [key, value];
98
108
  }