@automattic/vip 4.0.7 → 4.0.8
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.
|
@@ -44,6 +44,43 @@ function parseEtagHeader(etag) {
|
|
|
44
44
|
return normalizedEtag.replace(/^"(.*)"$/u, '$1');
|
|
45
45
|
}
|
|
46
46
|
const isStreamBody = body => typeof body?.pipe === 'function';
|
|
47
|
+
function createProgressTransform(onChunk) {
|
|
48
|
+
return new _stream.Transform({
|
|
49
|
+
transform(chunk, _encoding, callback) {
|
|
50
|
+
onChunk(chunk);
|
|
51
|
+
callback(null, chunk);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function omitUnsupportedFetchHeaders(init) {
|
|
56
|
+
if (!init.headers) {
|
|
57
|
+
return init;
|
|
58
|
+
}
|
|
59
|
+
const headers = new _undici.Headers(init.headers);
|
|
60
|
+
headers.delete('expect');
|
|
61
|
+
return {
|
|
62
|
+
...init,
|
|
63
|
+
headers
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function withCauseMessage(err) {
|
|
67
|
+
if (!(err instanceof Error)) {
|
|
68
|
+
return err;
|
|
69
|
+
}
|
|
70
|
+
const cause = err.cause;
|
|
71
|
+
let causeMessage;
|
|
72
|
+
if (cause instanceof Error) {
|
|
73
|
+
causeMessage = cause.message;
|
|
74
|
+
} else if (typeof cause === 'string') {
|
|
75
|
+
causeMessage = cause;
|
|
76
|
+
}
|
|
77
|
+
if (!causeMessage || err.message.includes(causeMessage)) {
|
|
78
|
+
return err;
|
|
79
|
+
}
|
|
80
|
+
return new Error(`${err.message}: ${causeMessage}`, {
|
|
81
|
+
cause: err
|
|
82
|
+
});
|
|
83
|
+
}
|
|
47
84
|
|
|
48
85
|
/**
|
|
49
86
|
* Wraps `fetch` with exponential-backoff retries.
|
|
@@ -75,10 +112,10 @@ async function fetchWithRetry(input, init = {}, retries = 3, createBody) {
|
|
|
75
112
|
}
|
|
76
113
|
try {
|
|
77
114
|
// eslint-disable-next-line no-await-in-loop
|
|
78
|
-
return await (0, _undici.fetch)(input, requestInit);
|
|
115
|
+
return await (0, _undici.fetch)(input, omitUnsupportedFetchHeaders(requestInit));
|
|
79
116
|
} catch (err) {
|
|
80
117
|
if (attempt === maxAttempts) {
|
|
81
|
-
throw err;
|
|
118
|
+
throw withCauseMessage(err);
|
|
82
119
|
}
|
|
83
120
|
// eslint-disable-next-line no-await-in-loop
|
|
84
121
|
await (0, _promises3.setTimeout)(Math.pow(2, attempt) * 1000); // 1000, 2000, 4000
|
|
@@ -260,8 +297,7 @@ async function uploadUsingPutObject({
|
|
|
260
297
|
return fileContent;
|
|
261
298
|
}
|
|
262
299
|
let readBytes = 0;
|
|
263
|
-
const
|
|
264
|
-
progressPassThrough.on('data', data => {
|
|
300
|
+
const progressTransform = createProgressTransform(data => {
|
|
265
301
|
readBytes += data.length;
|
|
266
302
|
const percentage = `${Math.floor(100 * readBytes / fileSize)}%`;
|
|
267
303
|
debug(percentage);
|
|
@@ -269,7 +305,7 @@ async function uploadUsingPutObject({
|
|
|
269
305
|
progressCallback(percentage);
|
|
270
306
|
}
|
|
271
307
|
});
|
|
272
|
-
return (0, _fs.createReadStream)(fileName).pipe(
|
|
308
|
+
return (0, _fs.createReadStream)(fileName).pipe(progressTransform);
|
|
273
309
|
};
|
|
274
310
|
const response = await fetchWithRetry(presignedRequest.url, fetchOptions, 3, createBody);
|
|
275
311
|
if (response.status === 200) {
|
|
@@ -507,15 +543,14 @@ async function uploadParts({
|
|
|
507
543
|
const createBody = () => {
|
|
508
544
|
partBytesRead[index] = 0;
|
|
509
545
|
partPercentages[index] = 0;
|
|
510
|
-
const
|
|
511
|
-
progressPassThrough.on('data', data => {
|
|
546
|
+
const progressTransform = createProgressTransform(data => {
|
|
512
547
|
partBytesRead[index] += data.length;
|
|
513
548
|
partPercentages[index] = Math.floor(100 * partBytesRead[index] / partSize);
|
|
514
549
|
});
|
|
515
550
|
return (0, _fs.createReadStream)(fileMeta.fileName, {
|
|
516
551
|
start,
|
|
517
552
|
end
|
|
518
|
-
}).pipe(
|
|
553
|
+
}).pipe(progressTransform);
|
|
519
554
|
};
|
|
520
555
|
await readyForPartUpload();
|
|
521
556
|
const uploadResult = await uploadPart({
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/vip",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.8",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@automattic/vip",
|
|
9
|
-
"version": "4.0.
|
|
9
|
+
"version": "4.0.8",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|