@faststore/core 3.100.13 → 3.100.14
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/.next/BUILD_ID +1 -1
- package/.next/build-manifest.json +23 -23
- package/.next/cache/.tsbuildinfo +1 -1
- package/.next/cache/config.json +3 -3
- package/.next/cache/webpack/client-production/0.pack +2 -2
- package/.next/cache/webpack/client-production/index.pack +0 -0
- package/.next/cache/webpack/edge-server-production/0.pack +0 -0
- package/.next/cache/webpack/edge-server-production/index.pack +0 -0
- package/.next/cache/webpack/server-production/0.pack +2 -2
- package/.next/cache/webpack/server-production/index.pack +0 -0
- package/.next/prerender-manifest.js +1 -1
- package/.next/prerender-manifest.json +1 -1
- package/.next/react-loadable-manifest.json +8 -8
- package/.next/routes-manifest.json +1 -1
- package/.next/server/chunks/948.js +3 -3
- package/.next/server/chunks/9563.js +1 -1
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/middleware-react-loadable-manifest.js +1 -1
- package/.next/server/pages/api/graphql.js +1 -1
- package/.next/server/pages/api/preview.js +1 -1
- package/.next/server/pages/en-US/404.html +2 -2
- package/.next/server/pages/en-US/500.html +2 -2
- package/.next/server/pages/en-US/checkout.html +2 -2
- package/.next/server/pages/en-US/login.html +2 -2
- package/.next/server/pages/en-US/password-protection.html +2 -2
- package/.next/server/pages/en-US/s.html +2 -2
- package/.next/server/pages/en-US.html +2 -2
- package/.next/server/pages/pvt/account/404.js +1 -1
- package/.next/server/pages-manifest.json +1 -1
- package/.next/static/chunks/{2927.23bae2c79f0ac0f3.js → 2927.5a79877943a6bf7c.js} +1 -1
- package/.next/static/chunks/560.07aa0aecf4f91958.js +1 -0
- package/.next/static/chunks/{UIToast.de15325248043ce5.js → UIToast.19a8664c01a00d3a.js} +1 -1
- package/.next/static/chunks/pages/{[...slug]-d2b8abf5b0c0bb19.js → [...slug]-0fddf377ce473abe.js} +1 -1
- package/.next/static/chunks/webpack-be585819cf6d8141.js +1 -0
- package/.next/static/{2WQ8JPi4Q8ssFa6f44WmW → yXdTayxe85vFRTt69g31B}/_buildManifest.js +1 -1
- package/.next/trace +157 -157
- package/.turbo/turbo-build.log +12 -12
- package/.turbo/turbo-test.log +13 -12
- package/CHANGELOG.md +6 -0
- package/package.json +2 -2
- package/src/server/cms/ResilientClientCMS.ts +168 -0
- package/src/server/cms/index.ts +3 -2
- package/test/server/cms/ResilientClientCMS.test.ts +486 -0
- package/.next/static/chunks/7783.017603f0dd9e1dd7.js +0 -1
- package/.next/static/chunks/webpack-62bcb2a452e15476.js +0 -1
- /package/.next/static/{2WQ8JPi4Q8ssFa6f44WmW → yXdTayxe85vFRTt69g31B}/_ssgManifest.js +0 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @faststore/core@3.100.
|
|
2
|
+
> @faststore/core@3.100.13 prebuild /home/runner/work/faststore/faststore/packages/core
|
|
3
3
|
> na run partytown && na run generate
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @faststore/core@3.100.
|
|
6
|
+
> @faststore/core@3.100.13 partytown /home/runner/work/faststore/faststore/packages/core
|
|
7
7
|
> partytown copylib ./public/~partytown
|
|
8
8
|
|
|
9
9
|
Partytown lib copied to: /home/runner/work/faststore/faststore/packages/core/public/~partytown
|
|
10
10
|
|
|
11
|
-
> @faststore/core@3.100.
|
|
11
|
+
> @faststore/core@3.100.13 generate /home/runner/work/faststore/faststore/packages/core
|
|
12
12
|
> na run generate:schema && na run generate:codegen && na run format:generated
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
> @faststore/core@3.100.
|
|
15
|
+
> @faststore/core@3.100.13 generate:schema /home/runner/work/faststore/faststore/packages/core
|
|
16
16
|
> tsx src/server/generator/generateGraphQLSchemaFile.ts
|
|
17
17
|
|
|
18
18
|
Schema GraphQL file generated successfully
|
|
19
19
|
|
|
20
|
-
> @faststore/core@3.100.
|
|
20
|
+
> @faststore/core@3.100.13 generate:codegen /home/runner/work/faststore/faststore/packages/core
|
|
21
21
|
> graphql-codegen
|
|
22
22
|
|
|
23
23
|
[STARTED] Parse Configuration
|
|
@@ -37,11 +37,11 @@ Running lifecycle hook "afterStart" scripts...
|
|
|
37
37
|
[CLI] Loading Documents
|
|
38
38
|
[CLI] Generating output
|
|
39
39
|
|
|
40
|
-
> @faststore/core@3.100.
|
|
40
|
+
> @faststore/core@3.100.13 format:generated /home/runner/work/faststore/faststore/packages/core
|
|
41
41
|
> prettier --write "@generated/**/*.{ts,js,tsx,jsx,json}" --loglevel error
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
> @faststore/core@3.100.
|
|
44
|
+
> @faststore/core@3.100.13 build /home/runner/work/faststore/faststore/packages/core
|
|
45
45
|
> next build
|
|
46
46
|
|
|
47
47
|
⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
|
|
@@ -63,7 +63,6 @@ Browserslist: browsers data (caniuse-lite) is 22 months old. Please run:
|
|
|
63
63
|
Why you should do it regularly: https://github.com/browserslist/update-db#readme
|
|
64
64
|
<w> [webpack.cache.PackFileCacheStrategy] Skipped not serializable cache item 'Compilation/modules|/home/runner/work/faststore/faststore/node_modules/.pnpm/next@13.5.11_@babel+core@7.26.7_@opentelemetry+api@1.4.1_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.83.4/node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[7].oneOf[9].use[1]!/home/runner/work/faststore/faststore/node_modules/.pnpm/next@13.5.11_@babel+core@7.26.7_@opentelemetry+api@1.4.1_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.83.4/node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[7].oneOf[9].use[2]!/home/runner/work/faststore/faststore/node_modules/.pnpm/next@13.5.11_@babel+core@7.26.7_@opentelemetry+api@1.4.1_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.83.4/node_modules/next/dist/build/webpack/loaders/resolve-url-loader/index.js??ruleSet[1].rules[7].oneOf[9].use[3]!/home/runner/work/faststore/faststore/node_modules/.pnpm/next@13.5.11_@babel+core@7.26.7_@opentelemetry+api@1.4.1_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.83.4/node_modules/next/dist/compiled/sass-loader/cjs.js??ruleSet[1].rules[7].oneOf[9].use[4]!/home/runner/work/faststore/faststore/packages/core/src/components/common/Toast/section.module.scss': No serializer registered for Warning
|
|
65
65
|
<w> while serializing webpack/lib/cache/PackFileCacheStrategy.PackContentItems -> webpack/lib/NormalModule -> Array { 1 items } -> webpack/lib/ModuleWarning -> Warning
|
|
66
|
-
Collecting page data ...
|
|
67
66
|
⚠ Compiled with warnings
|
|
68
67
|
|
|
69
68
|
./src/components/common/Toast/section.module.scss.webpack[javascript/auto]!=!../../node_modules/.pnpm/next@13.5.11_@babel+core@7.26.7_@opentelemetry+api@1.4.1_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.83.4/node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[7].oneOf[9].use[1]!../../node_modules/.pnpm/next@13.5.11_@babel+core@7.26.7_@opentelemetry+api@1.4.1_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.83.4/node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[7].oneOf[9].use[2]!../../node_modules/.pnpm/next@13.5.11_@babel+core@7.26.7_@opentelemetry+api@1.4.1_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.83.4/node_modules/next/dist/build/webpack/loaders/resolve-url-loader/index.js??ruleSet[1].rules[7].oneOf[9].use[3]!../../node_modules/.pnpm/next@13.5.11_@babel+core@7.26.7_@opentelemetry+api@1.4.1_react-dom@18.3.1_react@18.3.1__react@18.3.1_sass@1.83.4/node_modules/next/dist/compiled/sass-loader/cjs.js??ruleSet[1].rules[7].oneOf[9].use[4]!./src/components/common/Toast/section.module.scss
|
|
@@ -84,7 +83,7 @@ Learn more: https://nextjs.org/docs/api-reference/edge-runtime
|
|
|
84
83
|
|
|
85
84
|
Import trace for requested module:
|
|
86
85
|
../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/lib/deflate.js
|
|
87
|
-
../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/jwe/flattened/
|
|
86
|
+
../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js
|
|
88
87
|
../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/index.js
|
|
89
88
|
./src/server/password-protection-service.ts
|
|
90
89
|
|
|
@@ -94,17 +93,18 @@ Learn more: https://nextjs.org/docs/api-reference/edge-runtime
|
|
|
94
93
|
|
|
95
94
|
Import trace for requested module:
|
|
96
95
|
../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/lib/deflate.js
|
|
97
|
-
../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/jwe/flattened/
|
|
96
|
+
../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js
|
|
98
97
|
../../node_modules/.pnpm/jose@6.2.3/node_modules/jose/dist/webapi/index.js
|
|
99
98
|
./src/server/password-protection-service.ts
|
|
100
99
|
|
|
100
|
+
Collecting page data ...
|
|
101
101
|
Generating static pages (0/8) ...
|
|
102
102
|
|
|
103
103
|
Generating static pages (2/8)
|
|
104
104
|
Search not found. Add a new component for this section or remove it from the CMS
|
|
105
105
|
Search not found. Add a new component for this section or remove it from the CMS
|
|
106
|
-
Search not found. Add a new component for this section or remove it from the CMS
|
|
107
106
|
Warning: Dynamic Content not found for the page: home. Refer to the Dynamic Content documentation at https://developers.vtex.com/docs/guides/faststore/dynamic-content-overview for mapping the page and the corresponding data-fetching function.
|
|
108
107
|
|
|
109
108
|
Generating static pages (4/8)
|
|
109
|
+
Search not found. Add a new component for this section or remove it from the CMS
|
|
110
110
|
Search not found. Add a new component for this section or remove it from the CMS
|
|
111
111
|
|
|
112
112
|
Generating static pages (6/8)
|
|
113
113
|
Search not found. Add a new component for this section or remove it from the CMS
|
|
@@ -154,7 +154,7 @@ Route (pages) Size First Load JS
|
|
|
154
154
|
├ chunks/framework-d514426edf885c68.js 45.4 kB
|
|
155
155
|
├ chunks/main-a2d1cfe626f2fef1.js 33.4 kB
|
|
156
156
|
├ chunks/pages/_app-61f81ba19dbd0368.js 26.7 kB
|
|
157
|
-
├ chunks/webpack-
|
|
157
|
+
├ chunks/webpack-be585819cf6d8141.js 3.9 kB
|
|
158
158
|
└ css/146a8678babc61bf.css 9.2 kB
|
|
159
159
|
|
|
160
160
|
ƒ Middleware 45.1 kB
|
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
|
|
2
|
-
> @faststore/core@3.100.
|
|
2
|
+
> @faststore/core@3.100.13 test /home/runner/work/faststore/faststore/packages/core
|
|
3
3
|
> jest
|
|
4
4
|
|
|
5
|
-
PASS test/server/
|
|
6
|
-
PASS test/
|
|
7
|
-
PASS test/server/
|
|
8
|
-
PASS test/utils/
|
|
5
|
+
PASS test/server/content/service.test.ts (12.798 s)
|
|
6
|
+
PASS test/server/password-protection-service.test.ts (13.211 s)
|
|
7
|
+
PASS test/server/cms/ResilientClientCMS.test.ts (13.66 s)
|
|
8
|
+
PASS test/utils/cookieCacheBusting.test.ts
|
|
9
9
|
PASS test/utils/clearCookies.test.ts
|
|
10
|
+
PASS test/utils/multipleTemplates.test.ts
|
|
10
11
|
PASS test/server/cms/index.test.ts
|
|
11
12
|
PASS test/server/content/promiseCache.test.ts
|
|
12
13
|
PASS test/sdk/redirects/index.test.ts
|
|
13
14
|
PASS test/utils/trustedForwardedHost.test.ts
|
|
14
15
|
PASS test/server/cms/global.test.ts
|
|
15
|
-
PASS test/
|
|
16
|
-
PASS test/components/templates/SearchPage/SearchWrapper.browser.test.tsx (9.483 s)
|
|
16
|
+
PASS test/components/templates/SearchPage/SearchWrapper.browser.test.tsx
|
|
17
17
|
● Console
|
|
18
18
|
|
|
19
19
|
console.error
|
|
@@ -43,14 +43,15 @@ PASS test/components/templates/SearchPage/SearchWrapper.browser.test.tsx (9.483
|
|
|
43
43
|
at Object.<anonymous>.__awaiter (test/components/templates/SearchPage/SearchWrapper.browser.test.tsx:15:12)
|
|
44
44
|
at Object.<anonymous> (test/components/templates/SearchPage/SearchWrapper.browser.test.tsx:110:65)
|
|
45
45
|
|
|
46
|
-
PASS test/utils/
|
|
46
|
+
PASS test/utils/mergeDiscoveryConfig.test.ts
|
|
47
47
|
PASS test/utils/subDomainPrefixWarning.test.ts
|
|
48
|
+
PASS test/utils/validateSessionRefreshToken.test.ts
|
|
48
49
|
PASS test/utils/isLocalHost.test.ts
|
|
49
50
|
PASS test/utils/isLocalHost.browser.test.ts
|
|
50
|
-
PASS test/server/index.test.ts
|
|
51
|
+
PASS test/server/index.test.ts
|
|
51
52
|
|
|
52
|
-
Test Suites:
|
|
53
|
-
Tests:
|
|
53
|
+
Test Suites: 18 passed, 18 total
|
|
54
|
+
Tests: 203 passed, 203 total
|
|
54
55
|
Snapshots: 0 total
|
|
55
|
-
Time:
|
|
56
|
+
Time: 21.5 s
|
|
56
57
|
Ran all test suites.
|
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.100.14](https://github.com/vtex/faststore/compare/v3.100.13...v3.100.14) (2026-11-19)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **core:** retry CMS fetch bypassing cache on invalid JSON (3.x) ([#3591](https://github.com/vtex/faststore/issues/3591)) ([f99624f](https://github.com/vtex/faststore/commit/f99624fb13c96fc01a1ddf7d193c459a5795f075))
|
|
11
|
+
|
|
6
12
|
## [3.100.13](https://github.com/vtex/faststore/compare/v3.100.12...v3.100.13) (2026-11-16)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @faststore/core
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/core",
|
|
3
|
-
"version": "3.100.
|
|
3
|
+
"version": "3.100.14",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -128,5 +128,5 @@
|
|
|
128
128
|
"ts-jest": "29.1.1",
|
|
129
129
|
"typescript": "5.3.2"
|
|
130
130
|
},
|
|
131
|
-
"gitHead": "
|
|
131
|
+
"gitHead": "c84386345647795adcca86d633251283b63f5142"
|
|
132
132
|
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import ClientCMS from '@vtex/client-cms'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Query param added to the retry request. The CDN in front of the CMS API
|
|
5
|
+
* includes the query string in its cache key, so a new value is a cache miss
|
|
6
|
+
* that reaches the origin. A `Cache-Control: no-cache` request header is not
|
|
7
|
+
* enough, since CDNs commonly ignore it.
|
|
8
|
+
*/
|
|
9
|
+
export const CACHE_BUST_PARAM = 'cb'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The cache-busting value changes once per window instead of per request, so
|
|
13
|
+
* retries for the same URL within a window share one CDN cache entry: at most
|
|
14
|
+
* one of them reaches the origin, instead of every page generation causing a
|
|
15
|
+
* new cache miss while the bad response stays cached under the original URL.
|
|
16
|
+
*/
|
|
17
|
+
export const CACHE_BUST_WINDOW_MS = 60 * 1000
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* How long a URL whose cache-busting retry also failed skips further retries.
|
|
21
|
+
*
|
|
22
|
+
* Must be at least `CACHE_BUST_WINDOW_MS`: the next retry after the cooldown
|
|
23
|
+
* has to fall in a later window, so it uses a new cache-busting value instead
|
|
24
|
+
* of the one whose cached response just failed. Derived from it to keep that
|
|
25
|
+
* invariant when either value changes.
|
|
26
|
+
*/
|
|
27
|
+
export const RETRY_COOLDOWN_MS = CACHE_BUST_WINDOW_MS
|
|
28
|
+
|
|
29
|
+
type ErrorShape = {
|
|
30
|
+
name?: unknown
|
|
31
|
+
type?: unknown
|
|
32
|
+
cause?: { code?: unknown }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Error codes Node raises while decompressing a response body: zlib (gzip,
|
|
37
|
+
* deflate) uses `Z_*` (e.g. `Z_DATA_ERROR`, `Z_BUF_ERROR`), and brotli uses
|
|
38
|
+
* `ERR_` + the decoder error name, which itself starts with an underscore (e.g.
|
|
39
|
+
* `ERR__ERROR_FORMAT_PADDING_1`). The double underscore is not a typo.
|
|
40
|
+
*/
|
|
41
|
+
const BODY_DECODING_ERROR_CODE = /^(Z_|ERR__ERROR_)/
|
|
42
|
+
|
|
43
|
+
const decodingErrorCode = (error: unknown) => {
|
|
44
|
+
const code = (error as ErrorShape | null)?.cause?.code
|
|
45
|
+
|
|
46
|
+
return typeof code === 'string' && BODY_DECODING_ERROR_CODE.test(code)
|
|
47
|
+
? code
|
|
48
|
+
: undefined
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Whether `error` means the response arrived but its body could not be parsed
|
|
53
|
+
* or decoded:
|
|
54
|
+
* - `SyntaxError`: `response.json()` on a body that is not valid JSON. Checked
|
|
55
|
+
* by name so it also matches errors created in another realm (e.g. a test vm
|
|
56
|
+
* context).
|
|
57
|
+
* - A decoding error while reading the body, when `Content-Encoding` does not
|
|
58
|
+
* match the bytes: undici rejects with `TypeError: terminated`, caused by a
|
|
59
|
+
* zlib or brotli error.
|
|
60
|
+
* - `invalid-json`: the parse failure as reported by `node-fetch`.
|
|
61
|
+
* `@vtex/client-cms` only falls back to it when there is no global fetch,
|
|
62
|
+
* which does not happen on the Node versions core supports (>= 20.9), so this
|
|
63
|
+
* case is only a safeguard.
|
|
64
|
+
*
|
|
65
|
+
* Bodies that parse to an unexpected value (e.g. `null`) are not retried: they
|
|
66
|
+
* keep reaching callers as before.
|
|
67
|
+
*/
|
|
68
|
+
const isInvalidBodyError = (error: unknown) => {
|
|
69
|
+
const { name, type } = (error ?? {}) as ErrorShape
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
name === 'SyntaxError' ||
|
|
73
|
+
type === 'invalid-json' ||
|
|
74
|
+
decodingErrorCode(error) !== undefined
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Error name plus decoding code, without the message (it may embed body). */
|
|
79
|
+
const describeError = (error: unknown) =>
|
|
80
|
+
[(error as ErrorShape | null)?.name, decodingErrorCode(error)]
|
|
81
|
+
.filter(Boolean)
|
|
82
|
+
.join(': ')
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* `ClientCMS` that retries a request once, bypassing CDN caches, when the
|
|
86
|
+
* response body cannot be parsed or decoded. A single bad cached response
|
|
87
|
+
* (e.g. a compressed body stored without its `Content-Encoding`) would
|
|
88
|
+
* otherwise fail every page that depends on it until the cache entry expires.
|
|
89
|
+
*
|
|
90
|
+
* Only that case is retried: network errors are already retried by
|
|
91
|
+
* `@vtex/client-cms`, and non-2xx responses keep failing as before.
|
|
92
|
+
*
|
|
93
|
+
* The retry reaches the origin. When the retry fails too, for any reason (an
|
|
94
|
+
* invalid body, a 5xx, a network error), the origin itself is likely unhealthy,
|
|
95
|
+
* so that URL fails fast without retrying for `RETRY_COOLDOWN_MS` instead of
|
|
96
|
+
* adding an uncached origin hit to every page generation. Skipping the retry
|
|
97
|
+
* only falls back to the behavior without this class.
|
|
98
|
+
*/
|
|
99
|
+
export class ResilientClientCMS extends ClientCMS {
|
|
100
|
+
/** URL -> time until which its cache-busting retry is skipped. */
|
|
101
|
+
private readonly retryCooldownUntil = new Map<string, number>()
|
|
102
|
+
|
|
103
|
+
async fetch<T>(path = '', params?: URLSearchParams): Promise<T> {
|
|
104
|
+
try {
|
|
105
|
+
return await super.fetch<T>(path, params)
|
|
106
|
+
} catch (error) {
|
|
107
|
+
if (!isInvalidBodyError(error)) {
|
|
108
|
+
throw error
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const url = [path, params?.toString()].filter(Boolean).join('?')
|
|
112
|
+
if (this.isCoolingDown(url)) {
|
|
113
|
+
throw error
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Only the error name (and decoding error code) is logged: a JSON parse
|
|
117
|
+
// error message embeds the start of the body, which may be binary.
|
|
118
|
+
console.warn(
|
|
119
|
+
`[CMS] Invalid response body for "${url}" (${describeError(error)}). Retrying once bypassing the cache.`
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
const cacheBustingParams = new URLSearchParams(params)
|
|
123
|
+
cacheBustingParams.set(
|
|
124
|
+
CACHE_BUST_PARAM,
|
|
125
|
+
Math.floor(Date.now() / CACHE_BUST_WINDOW_MS).toString()
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
return await super.fetch<T>(path, cacheBustingParams)
|
|
130
|
+
} catch (retryError) {
|
|
131
|
+
// Any retry failure backs off, not only another invalid body: a 5xx or
|
|
132
|
+
// network error from the origin is also a reason not to add load.
|
|
133
|
+
this.startCooldown(url)
|
|
134
|
+
console.warn(
|
|
135
|
+
`[CMS] Cache-busting retry failed for "${url}" (${describeError(retryError)}). Skipping retries for this URL for ${RETRY_COOLDOWN_MS / 1000}s.`
|
|
136
|
+
)
|
|
137
|
+
throw retryError
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private isCoolingDown(url: string) {
|
|
143
|
+
const until = this.retryCooldownUntil.get(url)
|
|
144
|
+
|
|
145
|
+
if (until === undefined) {
|
|
146
|
+
return false
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (until > Date.now()) {
|
|
150
|
+
return true
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
this.retryCooldownUntil.delete(url)
|
|
154
|
+
return false
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private startCooldown(url: string) {
|
|
158
|
+
const now = Date.now()
|
|
159
|
+
|
|
160
|
+
// Drop expired entries so URLs that are never requested again do not pile
|
|
161
|
+
// up for the lifetime of the process.
|
|
162
|
+
this.retryCooldownUntil.forEach((until, key) => {
|
|
163
|
+
if (until <= now) this.retryCooldownUntil.delete(key)
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
this.retryCooldownUntil.set(url, now + RETRY_COOLDOWN_MS)
|
|
167
|
+
}
|
|
168
|
+
}
|
package/src/server/cms/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { ContentData, ContentTypeOptions, Locator } from '@vtex/client-cms'
|
|
2
|
-
import ClientCMS from '@vtex/client-cms'
|
|
2
|
+
import type ClientCMS from '@vtex/client-cms'
|
|
3
3
|
|
|
4
4
|
import MultipleContentError from 'src/sdk/error/MultipleContentError'
|
|
5
5
|
import { createPromiseCache } from 'src/server/content/promiseCache'
|
|
6
6
|
import { sanitizeHost } from 'src/utils/utilities'
|
|
7
7
|
import config from '../../../discovery.config'
|
|
8
|
+
import { ResilientClientCMS } from './ResilientClientCMS'
|
|
8
9
|
|
|
9
10
|
export type Options =
|
|
10
11
|
| Locator
|
|
@@ -64,7 +65,7 @@ export const isLocator = (x: any): x is Locator =>
|
|
|
64
65
|
typeof x.documentId === 'string' ||
|
|
65
66
|
typeof x.versionId === 'string')
|
|
66
67
|
|
|
67
|
-
export const clientCMS = new
|
|
68
|
+
export const clientCMS = new ResilientClientCMS({
|
|
68
69
|
workspace: config.api.workspace,
|
|
69
70
|
tenant: config.api.storeId,
|
|
70
71
|
builder:
|