@automattic/vip 4.0.6 → 4.0.7

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.
@@ -43,6 +43,8 @@ function parseEtagHeader(etag) {
43
43
  }
44
44
  return normalizedEtag.replace(/^"(.*)"$/u, '$1');
45
45
  }
46
+ const isStreamBody = body => typeof body?.pipe === 'function';
47
+
46
48
  /**
47
49
  * Wraps `fetch` with exponential-backoff retries.
48
50
  *
@@ -58,14 +60,19 @@ function parseEtagHeader(etag) {
58
60
  * once so the underlying error surfaces instead of the misleading undici one.
59
61
  */
60
62
  async function fetchWithRetry(input, init = {}, retries = 3, createBody) {
61
- const bodyIsStream = typeof init.body?.pipe === 'function';
63
+ const bodyIsStream = isStreamBody(init.body);
62
64
  // Only retry when we can hand `fetch` a fresh, replayable body each attempt.
63
65
  const maxAttempts = createBody || !bodyIsStream ? retries : 0;
64
66
  for (let attempt = 0; attempt <= maxAttempts; attempt++) {
65
67
  const requestInit = createBody ? {
66
68
  ...init,
67
69
  body: createBody()
68
- } : init;
70
+ } : {
71
+ ...init
72
+ };
73
+ if (isStreamBody(requestInit.body) && !requestInit.duplex) {
74
+ requestInit.duplex = 'half';
75
+ }
69
76
  try {
70
77
  // eslint-disable-next-line no-await-in-loop
71
78
  return await (0, _undici.fetch)(input, requestInit);
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@automattic/vip",
3
- "version": "4.0.6",
3
+ "version": "4.0.7",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@automattic/vip",
9
- "version": "4.0.6",
9
+ "version": "4.0.7",
10
10
  "hasInstallScript": true,
11
11
  "license": "MIT",
12
12
  "dependencies": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/vip",
3
- "version": "4.0.6",
3
+ "version": "4.0.7",
4
4
  "description": "The VIP Javascript library & CLI",
5
5
  "main": "index.js",
6
6
  "bin": {