@automattic/vip 2.30.0 → 2.31.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.
- package/CHANGELOG.md +25 -0
- package/assets/dev-env.lando.template.yml.ejs +14 -0
- package/assets/dev-env.nginx.template.conf.ejs +23 -2
- package/dist/bin/vip-dev-env-shell.js +2 -1
- package/dist/bin/vip-dev-env-sync-sql.js +15 -19
- package/dist/bin/vip-dev-env-sync.js +0 -0
- package/dist/bin/vip-dev-env-update.js +1 -0
- package/dist/bin/vip-export-sql.js +12 -11
- package/dist/bin/vip-import-sql.js +2 -2
- package/dist/bin/vip-whoami.js +7 -10
- package/dist/commands/dev-env-sync-sql.js +53 -20
- package/dist/commands/export-sql.js +13 -4
- 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 +4 -2
- package/dist/lib/api/http.js +10 -18
- package/dist/lib/api/user.js +3 -8
- package/dist/lib/api.js +11 -14
- package/dist/lib/app-logs/app-logs.js +3 -6
- 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 +6 -4
- package/dist/lib/dev-environment/dev-environment-configuration-file.js +4 -2
- package/dist/lib/dev-environment/dev-environment-core.js +3 -0
- 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/read-file.js +13 -14
- package/dist/lib/search-and-replace.js +17 -26
- package/dist/lib/tracker.js +12 -12
- package/dist/lib/user-error.js +6 -5
- package/dist/lib/utils.js +18 -22
- package/dist/lib/vip-import-validate-files.js +23 -22
- package/npm-shrinkwrap.json +9 -1043
- package/package.json +3 -6
- package/tsconfig.json +4 -2
- package/dist/lib/analytics/clients/stub.js +0 -16
- package/dist/lib/cli/repo.js +0 -61
- package/noImplictAnyImportBypass.d.ts +0 -6
|
@@ -10,9 +10,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
10
10
|
/**
|
|
11
11
|
* External dependencies
|
|
12
12
|
*/
|
|
13
|
+
|
|
13
14
|
/**
|
|
14
15
|
* Internal dependencies
|
|
15
16
|
*/
|
|
17
|
+
|
|
16
18
|
const query = (0, _graphqlTag.default)`
|
|
17
19
|
query GetEnvironmentVariables(
|
|
18
20
|
$appId: Int!
|
|
@@ -39,6 +41,7 @@ const query = (0, _graphqlTag.default)`
|
|
|
39
41
|
|
|
40
42
|
// List the names (but not values) of environment variables.
|
|
41
43
|
async function listEnvVars(appId, envId) {
|
|
44
|
+
var _data$app$environment, _data$app, _data$app$environment2, _data$app$environment3, _data$app$environment4;
|
|
42
45
|
const api = await (0, _api.default)();
|
|
43
46
|
const variables = {
|
|
44
47
|
appId,
|
|
@@ -50,7 +53,9 @@ async function listEnvVars(appId, envId) {
|
|
|
50
53
|
query,
|
|
51
54
|
variables
|
|
52
55
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
const nodes = (_data$app$environment = (_data$app = data.app) === null || _data$app === void 0 ? void 0 : (_data$app$environment2 = _data$app.environments) === null || _data$app$environment2 === void 0 ? void 0 : (_data$app$environment3 = _data$app$environment2[0]) === null || _data$app$environment3 === void 0 ? void 0 : (_data$app$environment4 = _data$app$environment3.environmentVariables) === null || _data$app$environment4 === void 0 ? void 0 : _data$app$environment4.nodes) !== null && _data$app$environment !== void 0 ? _data$app$environment : [];
|
|
57
|
+
return nodes.map(entry => {
|
|
58
|
+
var _entry$name;
|
|
59
|
+
return (_entry$name = entry === null || entry === void 0 ? void 0 : entry.name) !== null && _entry$name !== void 0 ? _entry$name : '';
|
|
60
|
+
});
|
|
56
61
|
}
|
|
@@ -10,9 +10,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
10
10
|
/**
|
|
11
11
|
* External dependencies
|
|
12
12
|
*/
|
|
13
|
+
|
|
13
14
|
/**
|
|
14
15
|
* Internal dependencies
|
|
15
16
|
*/
|
|
17
|
+
|
|
16
18
|
const mutation = (0, _graphqlTag.default)`
|
|
17
19
|
mutation AddEnvironmentVariable(
|
|
18
20
|
$appId: Int!
|
package/dist/lib/envvar/api.js
CHANGED
|
@@ -44,10 +44,7 @@ var _apiGetAll = _interopRequireDefault(require("./api-get-all"));
|
|
|
44
44
|
var _apiList = _interopRequireDefault(require("./api-list"));
|
|
45
45
|
var _apiSet = _interopRequireDefault(require("./api-set"));
|
|
46
46
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
47
|
-
|
|
48
|
-
*
|
|
49
|
-
* @format
|
|
50
|
-
*/
|
|
47
|
+
// @format
|
|
51
48
|
|
|
52
49
|
/**
|
|
53
50
|
* External dependencies
|
|
@@ -83,7 +80,7 @@ function validateName(name) {
|
|
|
83
80
|
return name === sanitizedName && /^[A-Z]/.test(sanitizedName);
|
|
84
81
|
}
|
|
85
82
|
function validateNameWithMessage(name) {
|
|
86
|
-
(0, _logging.debug)(`Validating environment variable name ${
|
|
83
|
+
(0, _logging.debug)(`Validating environment variable name "${name}"`);
|
|
87
84
|
if (!validateName(name)) {
|
|
88
85
|
const message = ['Environment variable name must consist of A-Z, 0-9, or _,', 'and must start with an uppercase letter.'].join('\n');
|
|
89
86
|
console.log(_chalk.default.bold.red(message));
|
package/dist/lib/envvar/input.js
CHANGED
|
@@ -9,10 +9,7 @@ exports.promptForValue = promptForValue;
|
|
|
9
9
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
10
10
|
var _enquirer = require("enquirer");
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
* @format
|
|
15
|
-
*/
|
|
12
|
+
// @format
|
|
16
13
|
|
|
17
14
|
/**
|
|
18
15
|
* External dependencies
|
|
@@ -27,13 +24,15 @@ function cancel() {
|
|
|
27
24
|
process.exit();
|
|
28
25
|
}
|
|
29
26
|
function confirm(message) {
|
|
30
|
-
return new _enquirer.
|
|
27
|
+
return new _enquirer.Confirm({
|
|
31
28
|
message
|
|
32
29
|
}).run().catch(() => false);
|
|
33
30
|
}
|
|
34
31
|
async function promptForValue(message, mustMatch) {
|
|
35
|
-
var
|
|
36
|
-
const
|
|
32
|
+
var _str$trim;
|
|
33
|
+
const {
|
|
34
|
+
str
|
|
35
|
+
} = await (0, _enquirer.prompt)({
|
|
37
36
|
message,
|
|
38
37
|
name: 'str',
|
|
39
38
|
type: 'input',
|
|
@@ -44,5 +43,5 @@ async function promptForValue(message, mustMatch) {
|
|
|
44
43
|
return true;
|
|
45
44
|
}
|
|
46
45
|
});
|
|
47
|
-
return (
|
|
46
|
+
return (_str$trim = str === null || str === void 0 ? void 0 : str.trim()) !== null && _str$trim !== void 0 ? _str$trim : '';
|
|
48
47
|
}
|
|
@@ -6,10 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.readVariableFromFile = readVariableFromFile;
|
|
7
7
|
var _logging = require("../../lib/envvar/logging");
|
|
8
8
|
var _readFile = require("../read-file");
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* @format
|
|
12
|
-
*/
|
|
9
|
+
// @format
|
|
13
10
|
|
|
14
11
|
/**
|
|
15
12
|
* External dependencies
|
|
@@ -19,7 +16,7 @@ var _readFile = require("../read-file");
|
|
|
19
16
|
* Internal dependencies
|
|
20
17
|
*/
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
(0, _logging.debug)(`Loading variable value from file ${
|
|
24
|
-
return
|
|
19
|
+
function readVariableFromFile(path) {
|
|
20
|
+
(0, _logging.debug)(`Loading variable value from file "${path}"`);
|
|
21
|
+
return (0, _readFile.readFromFile)(path);
|
|
25
22
|
}
|
|
@@ -9,6 +9,7 @@ var _httpsProxyAgent = require("https-proxy-agent");
|
|
|
9
9
|
var _proxyFromEnv = require("proxy-from-env");
|
|
10
10
|
var _debug = _interopRequireDefault(require("debug"));
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
|
|
12
13
|
/**
|
|
13
14
|
* External dependencies
|
|
14
15
|
*/
|
|
@@ -31,10 +32,10 @@ const debug = (0, _debug.default)('vip:proxy-agent');
|
|
|
31
32
|
// 5. NO_PROXY is set along with VIP_USE_SYSTEM_PROXY and any system proxy: null is returned if the no proxy applies, otherwise the first active proxy is used
|
|
32
33
|
// This allows near full customization by the client of what proxy should be used, instead of making assumptions based on the URL string
|
|
33
34
|
function createProxyAgent(url) {
|
|
34
|
-
const VIP_PROXY = process.env.VIP_PROXY || process.env.vip_proxy || null;
|
|
35
|
-
const SOCKS_PROXY = process.env.SOCKS_PROXY || process.env.socks_proxy || null;
|
|
36
|
-
const HTTPS_PROXY = process.env.HTTPS_PROXY || process.env.https_proxy || null;
|
|
37
|
-
const NO_PROXY = process.env.NO_PROXY || process.env.no_proxy || null;
|
|
35
|
+
const VIP_PROXY = process.env.VIP_PROXY || process.env.vip_proxy || null; // NOSONAR
|
|
36
|
+
const SOCKS_PROXY = process.env.SOCKS_PROXY || process.env.socks_proxy || null; // NOSONAR
|
|
37
|
+
const HTTPS_PROXY = process.env.HTTPS_PROXY || process.env.https_proxy || null; // NOSONAR
|
|
38
|
+
const NO_PROXY = process.env.NO_PROXY || process.env.no_proxy || null; // NOSONAR
|
|
38
39
|
|
|
39
40
|
// VIP Socks Proxy should take precedence and should be fully backward compatible
|
|
40
41
|
if (VIP_PROXY) {
|
package/dist/lib/read-file.js
CHANGED
|
@@ -4,14 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.readFromFile = readFromFile;
|
|
7
|
-
var
|
|
7
|
+
var _promises = require("node:fs/promises");
|
|
8
8
|
var exit = _interopRequireWildcard(require("../lib/cli/exit"));
|
|
9
9
|
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); }
|
|
10
10
|
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; }
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
* @format
|
|
14
|
-
*/
|
|
11
|
+
// @format
|
|
15
12
|
|
|
16
13
|
/**
|
|
17
14
|
* External dependencies
|
|
@@ -22,14 +19,16 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
22
19
|
*/
|
|
23
20
|
|
|
24
21
|
async function readFromFile(path) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
exit.withError(
|
|
22
|
+
try {
|
|
23
|
+
const data = await (0, _promises.readFile)(path, 'utf-8');
|
|
24
|
+
return data.trim();
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (!(error instanceof Error)) {
|
|
27
|
+
exit.withError('Unknown error');
|
|
28
|
+
}
|
|
29
|
+
if ('code' in error && error.code === 'ENOENT') {
|
|
30
|
+
exit.withError(`Could not load file "${path}".`);
|
|
31
31
|
}
|
|
32
|
-
exit.withError(message);
|
|
33
|
-
}
|
|
34
|
-
return Buffer.from(data).toString().trim();
|
|
32
|
+
exit.withError(error.message);
|
|
33
|
+
}
|
|
35
34
|
}
|
|
@@ -7,8 +7,9 @@ exports.getReadAndWriteStreams = getReadAndWriteStreams;
|
|
|
7
7
|
exports.searchAndReplace = void 0;
|
|
8
8
|
var _fs = _interopRequireDefault(require("fs"));
|
|
9
9
|
var _path = _interopRequireDefault(require("path"));
|
|
10
|
-
var _chalk =
|
|
10
|
+
var _chalk = require("chalk");
|
|
11
11
|
var _debug = _interopRequireDefault(require("debug"));
|
|
12
|
+
var _promises = require("node:stream/promises");
|
|
12
13
|
var _vipSearchReplace = require("@automattic/vip-search-replace");
|
|
13
14
|
var _tracker = require("../lib/tracker");
|
|
14
15
|
var _prompt = require("../lib/cli/prompt");
|
|
@@ -18,10 +19,7 @@ var _utils = require("./utils");
|
|
|
18
19
|
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); }
|
|
19
20
|
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; }
|
|
20
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
* @format
|
|
24
|
-
*/
|
|
22
|
+
// @format
|
|
25
23
|
|
|
26
24
|
/**
|
|
27
25
|
* External dependencies
|
|
@@ -32,11 +30,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
32
30
|
*/
|
|
33
31
|
|
|
34
32
|
const debug = (0, _debug.default)('@automattic/vip:lib:search-and-replace');
|
|
35
|
-
const flatten = arr => {
|
|
36
|
-
return arr.reduce((flat, toFlatten) => {
|
|
37
|
-
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
|
|
38
|
-
}, []);
|
|
39
|
-
};
|
|
40
33
|
function getReadAndWriteStreams({
|
|
41
34
|
fileName,
|
|
42
35
|
inPlace,
|
|
@@ -103,7 +96,7 @@ const searchAndReplace = async (fileName, pairs, {
|
|
|
103
96
|
const fileSize = (0, _clientFileUploader.getFileSize)(fileName);
|
|
104
97
|
|
|
105
98
|
// if we don't have any pairs to replace with, return the input file
|
|
106
|
-
if (!pairs
|
|
99
|
+
if (!pairs.length) {
|
|
107
100
|
throw new Error('No search and replace parameters provided.');
|
|
108
101
|
}
|
|
109
102
|
|
|
@@ -113,8 +106,7 @@ const searchAndReplace = async (fileName, pairs, {
|
|
|
113
106
|
}
|
|
114
107
|
|
|
115
108
|
// determine all the replacements required
|
|
116
|
-
const
|
|
117
|
-
const replacements = flatten(replacementsArr);
|
|
109
|
+
const replacements = pairs.flatMap(pair => pair.split(',').map(str => str.trim()));
|
|
118
110
|
debug('Pairs: ', pairs, 'Replacements: ', replacements);
|
|
119
111
|
if (inPlace) {
|
|
120
112
|
const approved = await (0, _prompt.confirm)([], 'Are you sure you want to run search and replace on your input file? This operation is not reversible.');
|
|
@@ -142,20 +134,15 @@ const searchAndReplace = async (fileName, pairs, {
|
|
|
142
134
|
try {
|
|
143
135
|
replacedStream = await (0, _vipSearchReplace.replace)(readStream, replacements, binary);
|
|
144
136
|
} catch (replaceError) {
|
|
137
|
+
// replace() throws strings... OMG
|
|
145
138
|
exit.withError(replaceError);
|
|
146
139
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
});
|
|
154
|
-
}).on('error', () => {
|
|
155
|
-
console.log(_chalk.default.red("Oh no! We couldn't write to the output file. Please check your available disk space and file/folder permissions."));
|
|
156
|
-
reject();
|
|
157
|
-
});
|
|
158
|
-
});
|
|
140
|
+
try {
|
|
141
|
+
await (0, _promises.pipeline)(replacedStream, writeStream);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
console.log((0, _chalk.red)("Oh no! We couldn't write to the output file. Please check your available disk space and file/folder permissions."));
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
159
146
|
const endTime = process.hrtime(startTime);
|
|
160
147
|
const end = endTime[1] / 1000000; // time in ms
|
|
161
148
|
|
|
@@ -163,6 +150,10 @@ const searchAndReplace = async (fileName, pairs, {
|
|
|
163
150
|
time_to_run: end,
|
|
164
151
|
file_size: fileSize
|
|
165
152
|
});
|
|
166
|
-
return
|
|
153
|
+
return {
|
|
154
|
+
inputFileName: fileName,
|
|
155
|
+
outputFileName,
|
|
156
|
+
usingStdOut
|
|
157
|
+
};
|
|
167
158
|
};
|
|
168
159
|
exports.searchAndReplace = searchAndReplace;
|
package/dist/lib/tracker.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.aliasUser = aliasUser;
|
|
|
7
7
|
exports.makeCommandTracker = makeCommandTracker;
|
|
8
8
|
exports.trackEvent = trackEvent;
|
|
9
9
|
exports.trackEventWithEnv = trackEventWithEnv;
|
|
10
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
10
11
|
var _index = _interopRequireDefault(require("./analytics/index"));
|
|
11
12
|
var _tracks = _interopRequireDefault(require("./analytics/clients/tracks"));
|
|
12
13
|
var _pendo = _interopRequireDefault(require("./analytics/clients/pendo"));
|
|
@@ -17,12 +18,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
17
18
|
/**
|
|
18
19
|
* External dependencies
|
|
19
20
|
*/
|
|
20
|
-
const debug = require('debug')('@automattic/vip:analytics');
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Internal dependencies
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
+
const debug = (0, _debug.default)('@automattic/vip:analytics');
|
|
26
27
|
let analytics = null;
|
|
27
28
|
async function init() {
|
|
28
29
|
const uuid = await _token.default.uuid();
|
|
@@ -37,9 +38,7 @@ async function init() {
|
|
|
37
38
|
userId: uuid
|
|
38
39
|
}));
|
|
39
40
|
}
|
|
40
|
-
return new _index.default(
|
|
41
|
-
clients
|
|
42
|
-
});
|
|
41
|
+
return new _index.default(clients);
|
|
43
42
|
}
|
|
44
43
|
async function getInstance() {
|
|
45
44
|
if (analytics) {
|
|
@@ -48,30 +47,31 @@ async function getInstance() {
|
|
|
48
47
|
analytics = await init();
|
|
49
48
|
return analytics;
|
|
50
49
|
}
|
|
51
|
-
async function trackEvent(
|
|
50
|
+
async function trackEvent(name, props = {}) {
|
|
52
51
|
try {
|
|
53
52
|
await _token.default.uuid();
|
|
54
53
|
const client = await getInstance();
|
|
55
|
-
return await client.trackEvent(
|
|
54
|
+
return await client.trackEvent(name, props);
|
|
56
55
|
} catch (err) {
|
|
57
56
|
debug('trackEvent() failed', err);
|
|
57
|
+
return [];
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
async function aliasUser(vipUserId) {
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
if (vipUserId) {
|
|
62
|
+
try {
|
|
63
63
|
await trackEvent('_alias_user', {
|
|
64
64
|
ui: vipUserId,
|
|
65
65
|
_ut: _config.default.tracksUserType,
|
|
66
66
|
anonid: await _token.default.uuid()
|
|
67
67
|
});
|
|
68
|
-
await _token.default.setUuid(vipUserId);
|
|
68
|
+
await _token.default.setUuid(`${vipUserId}`);
|
|
69
|
+
} catch (err) {
|
|
70
|
+
debug('aliasUser() failed', err);
|
|
69
71
|
}
|
|
70
|
-
} catch (err) {
|
|
71
|
-
debug('aliasUser() failed', err);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
function trackEventWithEnv(appId, envId, eventName, eventProps = {}) {
|
|
75
75
|
return trackEvent(eventName, {
|
|
76
76
|
...eventProps,
|
|
77
77
|
app_id: appId,
|
package/dist/lib/user-error.js
CHANGED
|
@@ -4,9 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
class UserError extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'UserError';
|
|
11
|
+
}
|
|
9
12
|
}
|
|
10
|
-
|
|
11
|
-
var _default = UserError;
|
|
12
|
-
exports.default = _default;
|
|
13
|
+
exports.default = UserError;
|
package/dist/lib/utils.js
CHANGED
|
@@ -9,12 +9,10 @@ exports.pollUntil = pollUntil;
|
|
|
9
9
|
var _fs = _interopRequireDefault(require("fs"));
|
|
10
10
|
var _path = _interopRequireDefault(require("path"));
|
|
11
11
|
var _os = _interopRequireDefault(require("os"));
|
|
12
|
+
var _promises = require("node:timers/promises");
|
|
12
13
|
var _debug = _interopRequireDefault(require("debug"));
|
|
13
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
* @format
|
|
17
|
-
*/
|
|
15
|
+
// @format
|
|
18
16
|
|
|
19
17
|
/**
|
|
20
18
|
* External dependencies
|
|
@@ -23,7 +21,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
23
21
|
/**
|
|
24
22
|
* Internal dependencies
|
|
25
23
|
*/
|
|
26
|
-
|
|
27
24
|
const debug = (0, _debug.default)('@automattic/vip:lib:utils');
|
|
28
25
|
|
|
29
26
|
/**
|
|
@@ -32,20 +29,19 @@ const debug = (0, _debug.default)('@automattic/vip:lib:utils');
|
|
|
32
29
|
* @param {Function} fn A function to poll
|
|
33
30
|
* @param {number} interval Poll interval in milliseconds
|
|
34
31
|
* @param {Function} isDone A function that accepts the return of `fn`. Stops the polling if it returns true
|
|
35
|
-
* @return {Promise}
|
|
36
|
-
* @throws {Error}
|
|
32
|
+
* @return {Promise} A promise which resolves when the polling is done
|
|
33
|
+
* @throws {Error} If the fn throws an error
|
|
37
34
|
*/
|
|
38
35
|
async function pollUntil(fn, interval, isDone) {
|
|
39
|
-
|
|
40
|
-
while (
|
|
36
|
+
let done = false;
|
|
37
|
+
while (!done) {
|
|
41
38
|
// eslint-disable-next-line no-await-in-loop
|
|
42
39
|
const result = await fn();
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
done = isDone(result);
|
|
41
|
+
if (!done) {
|
|
42
|
+
// eslint-disable-next-line no-await-in-loop
|
|
43
|
+
await (0, _promises.setTimeout)(interval);
|
|
45
44
|
}
|
|
46
|
-
|
|
47
|
-
// eslint-disable-next-line no-await-in-loop
|
|
48
|
-
await new Promise(res => setTimeout(res, interval));
|
|
49
45
|
}
|
|
50
46
|
}
|
|
51
47
|
|
|
@@ -53,8 +49,8 @@ async function pollUntil(fn, interval, isDone) {
|
|
|
53
49
|
* Create a temporary directory in the system's temp directory
|
|
54
50
|
*
|
|
55
51
|
* @param {string} prefix Prefix for the directory name
|
|
56
|
-
* @return {string}
|
|
57
|
-
* @throws {Error}
|
|
52
|
+
* @return {string} Path to the temporary directory
|
|
53
|
+
* @throws {Error} If the directory cannot be created
|
|
58
54
|
*/
|
|
59
55
|
function makeTempDir(prefix = 'vip-cli') {
|
|
60
56
|
const tempDir = _fs.default.mkdtempSync(_path.default.join(_os.default.tmpdir(), `${prefix}-`));
|
|
@@ -71,17 +67,17 @@ function makeTempDir(prefix = 'vip-cli') {
|
|
|
71
67
|
|
|
72
68
|
/**
|
|
73
69
|
* Get absolute path to a file
|
|
74
|
-
*
|
|
70
|
+
*
|
|
75
71
|
* @param {string} filePath Path to the file
|
|
76
|
-
*
|
|
72
|
+
*
|
|
77
73
|
* @return {string} Absolute path to the file
|
|
78
74
|
*/
|
|
79
75
|
function getAbsolutePath(filePath) {
|
|
80
|
-
if (filePath.startsWith('/')) {
|
|
81
|
-
return filePath;
|
|
82
|
-
}
|
|
83
76
|
if (filePath.startsWith('~')) {
|
|
84
77
|
return filePath.replace('~', _os.default.homedir());
|
|
85
78
|
}
|
|
86
|
-
|
|
79
|
+
if (!_path.default.isAbsolute(filePath)) {
|
|
80
|
+
return _path.default.resolve(process.cwd(), filePath);
|
|
81
|
+
}
|
|
82
|
+
return filePath;
|
|
87
83
|
}
|
|
@@ -11,6 +11,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
11
11
|
/**
|
|
12
12
|
* External dependencies
|
|
13
13
|
*/
|
|
14
|
+
|
|
14
15
|
// Accepted media file extensions
|
|
15
16
|
const acceptedExtensions = ['jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'svg', 'tiff', 'tif', 'ico', 'asf', 'asx', 'wmv', 'wmx', 'wm', 'avi', 'divx', 'mov', 'qt', 'mpeg', 'mpg', 'mpe', 'mp4', 'm4v', 'ogv', 'webm', 'mkv', '3gp', '3gpp', '3g2', '3gp2', 'txt', 'asc', 'c', 'cc', 'h', 'srt', 'csv', 'tsv', 'ics', 'rtx', 'css', 'vtt', 'dfxp', 'mp3', 'm4a', 'm4b', 'ra', 'ram', 'wav', 'ogg', 'oga', 'mid', 'midi', 'wma', 'wax', 'mka', 'rtf', 'js', 'pdf', 'class', 'psd', 'xcf', 'doc', 'pot', 'pps', 'ppt', 'wri', 'xla', 'xls', 'xlt', 'xlw', 'mdb', 'mpp', 'docx', 'docm', 'dotx', 'dotm', 'xlsx', 'xlsm', 'xlsb', 'xltx', 'xltm', 'xlam', 'pptx', 'pptm', 'ppsx', 'ppsm', 'potx', 'potm', 'ppam', 'sldx', 'sldm', 'onetoc', ' onetoc2', 'onetmp', 'onepkg', 'oxps', 'xps', 'odt', 'odp', 'ods', 'odg', 'odc', 'odb', 'odf', 'webp', 'wp', 'wpd', 'key', 'numbers', 'pages'];
|
|
16
17
|
|
|
@@ -45,13 +46,12 @@ const recommendedFileStructure = () => {
|
|
|
45
46
|
|
|
46
47
|
// Recommend accepted file types
|
|
47
48
|
const recommendAcceptableFileTypes = () => {
|
|
48
|
-
console.log('Accepted file types: \n\n' + _chalk.default.magenta(`${acceptedExtensions}`));
|
|
49
|
+
console.log('Accepted file types: \n\n' + _chalk.default.magenta(`${acceptedExtensions.join(', ')}`));
|
|
49
50
|
console.log();
|
|
50
51
|
};
|
|
51
52
|
|
|
52
53
|
// Accepted file name characters
|
|
53
54
|
const recommendAcceptableFileNames = () => {
|
|
54
|
-
// const acceptedCharacters = 'Non-English characters, spaces, ( ) [ ] ~';
|
|
55
55
|
const allowedCharacters = [...acceptedCharactersSet].join(' ');
|
|
56
56
|
const notAllowedCharacters = [...prohibitedCharactersSet].join(' ');
|
|
57
57
|
console.log('The following characters are allowed in file names:\n' + _chalk.default.green(`All special characters, including: ${allowedCharacters}\n\n`) + 'The following characters are prohibited in file names:\n' + _chalk.default.red(`Encoded or alternate whitespace, such as ${notAllowedCharacters}, are converted to proper spaces\n`));
|
|
@@ -114,10 +114,10 @@ const findNestedDirectories = directory => {
|
|
|
114
114
|
*
|
|
115
115
|
* @param {string} folderPath Path of the entire folder structure
|
|
116
116
|
* @param {boolean} sites Check if site is a multisite or single site
|
|
117
|
-
*
|
|
117
|
+
* @return {Object} indexes
|
|
118
118
|
*/
|
|
119
119
|
exports.findNestedDirectories = findNestedDirectories;
|
|
120
|
-
|
|
120
|
+
function getIndexPositionOfFolders(folderPath, sites = false) {
|
|
121
121
|
let sitesIndex;
|
|
122
122
|
let siteIDIndex;
|
|
123
123
|
let yearIndex;
|
|
@@ -147,11 +147,11 @@ const getIndexPositionOfFolders = (folderPath, sites) => {
|
|
|
147
147
|
|
|
148
148
|
if (siteID) {
|
|
149
149
|
siteIDIndex = directories.indexOf(siteID[1]);
|
|
150
|
-
}
|
|
151
150
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
// Remove the multisite-specific path to avoid confusing a 2 digit site ID with the month
|
|
152
|
+
// e.g.- `uploads/sites/11/2020/06` -> `uploads/2020/06`
|
|
153
|
+
pathMutate = pathMutate.replace(siteID[0], '');
|
|
154
|
+
}
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
/**
|
|
@@ -197,7 +197,7 @@ const getIndexPositionOfFolders = (folderPath, sites) => {
|
|
|
197
197
|
yearIndex,
|
|
198
198
|
monthIndex
|
|
199
199
|
};
|
|
200
|
-
}
|
|
200
|
+
}
|
|
201
201
|
|
|
202
202
|
/**
|
|
203
203
|
* Single site folder structure validation
|
|
@@ -419,8 +419,8 @@ const isFileSanitized = file => {
|
|
|
419
419
|
*/
|
|
420
420
|
exports.isFileSanitized = isFileSanitized;
|
|
421
421
|
const identifyIntermediateImage = filename => {
|
|
422
|
-
const regex = /(
|
|
423
|
-
return filename.match(regex);
|
|
422
|
+
const regex = /([_-])?(\d+x\d+)(@\d+\w)?(\.\w{3,4})$/;
|
|
423
|
+
return filename.match(regex); // NOSONAR
|
|
424
424
|
};
|
|
425
425
|
|
|
426
426
|
// Check if an intermediate image has an existing original (source) image
|
|
@@ -431,7 +431,7 @@ const doesImageHaveExistingSource = file => {
|
|
|
431
431
|
const intermediateImage = identifyIntermediateImage(filename);
|
|
432
432
|
if (null !== intermediateImage) {
|
|
433
433
|
const imageSizing = intermediateImage[0]; // First capture group of the regex validation
|
|
434
|
-
const extension = _path.default.extname(filename).
|
|
434
|
+
const extension = _path.default.extname(filename).slice(1); // Extension of the path (e.g.- `.jpg`)
|
|
435
435
|
|
|
436
436
|
// Filename manipulation: if an image is an intermediate image, strip away the image sizing
|
|
437
437
|
// e.g.- `panda4000x6000.png` -> `panda.png`
|
|
@@ -446,8 +446,8 @@ const doesImageHaveExistingSource = file => {
|
|
|
446
446
|
if (_fs.default.existsSync(originalImage)) {
|
|
447
447
|
return originalImage;
|
|
448
448
|
}
|
|
449
|
-
return false;
|
|
450
449
|
}
|
|
450
|
+
return false;
|
|
451
451
|
};
|
|
452
452
|
|
|
453
453
|
/**
|
|
@@ -497,26 +497,27 @@ const summaryLogs = ({
|
|
|
497
497
|
totalFiles,
|
|
498
498
|
totalFolders
|
|
499
499
|
}) => {
|
|
500
|
+
const messages = [];
|
|
500
501
|
if (folderErrorsLength > 0) {
|
|
501
|
-
|
|
502
|
+
messages.push(_chalk.default.bgYellow(' RECOMMENDED ') + _chalk.default.bold.yellow(` ${folderErrorsLength} folders, `) + `${totalFolders} folders total`);
|
|
502
503
|
} else {
|
|
503
|
-
|
|
504
|
+
messages.push(_chalk.default.bgGreen(' PASS ') + _chalk.default.bold.green(` ${totalFolders} folders, `) + `${totalFolders} folders total`);
|
|
504
505
|
}
|
|
505
506
|
if (intImagesErrorsLength > 0) {
|
|
506
|
-
|
|
507
|
+
messages.push(_chalk.default.white.bgRed(' ERROR ') + _chalk.default.red(` ${intImagesErrorsLength} intermediate images`) + `, ${totalFiles} files total`);
|
|
507
508
|
} else {
|
|
508
|
-
|
|
509
|
+
messages.push(_chalk.default.white.bgGreen(' PASS ') + _chalk.default.green(` ${intImagesErrorsLength} intermediate images`) + `, ${totalFiles} files total`);
|
|
509
510
|
}
|
|
510
511
|
if (fileTypeErrorsLength > 0) {
|
|
511
|
-
|
|
512
|
+
messages.push(_chalk.default.white.bgRed(' ERROR ') + _chalk.default.red(` ${fileTypeErrorsLength} invalid file extensions`) + `, ${totalFiles} files total`);
|
|
512
513
|
} else {
|
|
513
|
-
|
|
514
|
+
messages.push(_chalk.default.white.bgGreen(' PASS ') + _chalk.default.green(` ${fileTypeErrorsLength} invalid file extensions`) + `, ${totalFiles} files total`);
|
|
514
515
|
}
|
|
515
516
|
if (filenameErrorsLength) {
|
|
516
|
-
|
|
517
|
+
messages.push(_chalk.default.white.bgRed(' ERROR ') + _chalk.default.red(` ${filenameErrorsLength} invalid filenames`) + `, ${totalFiles} files total`);
|
|
517
518
|
} else {
|
|
518
|
-
|
|
519
|
+
messages.push(_chalk.default.bgGreen(' PASS ') + _chalk.default.green(` ${filenameErrorsLength} invalid filenames`) + `, ${totalFiles} files total`);
|
|
519
520
|
}
|
|
520
|
-
console.log(`\n${
|
|
521
|
+
console.log(`\n${messages.join('\n')}\n`);
|
|
521
522
|
};
|
|
522
523
|
exports.summaryLogs = summaryLogs;
|