@faststore/core 4.11.4-dev.4 → 4.11.4-dev.5

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,9 +1,9 @@
1
1
 
2
- > @faststore/core@4.11.4-dev.3 generate /home/runner/work/faststore/faststore/packages/core
2
+ > @faststore/core@4.11.4-dev.4 generate /home/runner/work/faststore/faststore/packages/core
3
3
  > pnpm run gen-types && pnpm run cache-graphql
4
4
 
5
5
 
6
- > @faststore/core@4.11.4-dev.3 gen-types /home/runner/work/faststore/faststore/packages/core
6
+ > @faststore/core@4.11.4-dev.4 gen-types /home/runner/work/faststore/faststore/packages/core
7
7
  > node ../cli/bin/run generate-types .
8
8
 
9
9
  [STARTED] Parse Configuration
@@ -19,7 +19,7 @@
19
19
  [COMPLETED] Generate to @generated/
20
20
  [COMPLETED] Generate outputs
21
21
 
22
- > @faststore/core@4.11.4-dev.3 cache-graphql /home/runner/work/faststore/faststore/packages/core
22
+ > @faststore/core@4.11.4-dev.4 cache-graphql /home/runner/work/faststore/faststore/packages/core
23
23
  > node ../cli/bin/run cache-graphql --config=./discovery.config.default.js --queries=./@generated/persisted-documents.json
24
24
 
25
25
  [Info] - Config file location: /home/runner/work/faststore/faststore/packages/core/discovery.config.default.js
@@ -1,5 +1,5 @@
1
1
 
2
- > @faststore/core@4.11.4-dev.3 test /home/runner/work/faststore/faststore/packages/core
2
+ > @faststore/core@4.11.4-dev.4 test /home/runner/work/faststore/faststore/packages/core
3
3
  > vitest run
4
4
 
5
5
 
@@ -7,28 +7,25 @@
7
7
 
8
8
  Not implemented: navigation to another Document
9
9
  Not implemented: navigation to another Document
10
- ✓  browser  test/sdk/ui/useScrollRestoration.browser.test.ts (43 tests) 992ms
10
+ ✓  browser  test/sdk/ui/useScrollRestoration.browser.test.ts (43 tests) 787ms
11
11
  Browserslist: browsers data (caniuse-lite) is 9 months old. Please run:
12
12
  npx update-browserslist-db@latest
13
13
  Why you should do it regularly: https://github.com/browserslist/update-db#readme
14
- ✓  browser  test/components/account/cards/MyAccountListCards.browser.test.tsx (16 tests) 2255ms
15
- ✓ shows the tab bar and renders Personal cards by default  814ms
16
- ✓ paginates when there are more than 25 cards  405ms
17
- ✓  browser  test/components/account/ContractSwitcher.browser.test.tsx (22 tests) 3149ms
18
- ✓ shows an error state when the list fails to load  666ms
19
- ✓ keeps Confirm disabled until a different contract is selected  355ms
20
- ✓  browser  test/components/account/orders/BuyingPolicyAlert.browser.test.tsx (13 tests) 2411ms
21
- ✓ opens the reject confirmation modal with the default English copy  728ms
22
- ✓ opens the reject confirmation modal with CMS-provided labels  359ms
23
- ✓  browser  test/sdk/product/usePageProductsQuery.browser.test.ts (9 tests) 96ms
24
- ✓  browser  test/components/ui/RichText/RichText.browser.test.tsx (8 tests) 388ms
25
- ✓  browser  test/components/account/OrganizationDrawer.browser.test.tsx (10 tests) 1694ms
26
- ✓ renders the menu view with contract details and manage footer  971ms
27
- ✓  browser  test/sdk/localization/useBindingSelector.browser.test.tsx (9 tests) 94ms
28
- ✓  browser  test/components/CartRecommendationShelf/CartRecommendationShelf.browser.test.tsx (13 tests) 100ms
29
- ✓  browser  test/sdk/session/reconcileSessionLocale.browser.test.ts (6 tests) 10ms
30
- ✓  browser  test/components/ui/ProductGallery/GalleryPageHeightLock.browser.test.tsx (8 tests) 93ms
31
- ✓  browser  test/sdk/recommendations/useRecommendationShelf.browser.test.tsx (12 tests) 84ms
14
+ ✓  browser  test/components/account/ContractSwitcher.browser.test.tsx (22 tests) 2308ms
15
+ ✓ shows an error state when the list fails to load  510ms
16
+ ✓  browser  test/components/account/cards/MyAccountListCards.browser.test.tsx (16 tests) 1713ms
17
+ ✓ shows the tab bar and renders Personal cards by default  1004ms
18
+ ✓  browser  test/components/account/orders/BuyingPolicyAlert.browser.test.tsx (13 tests) 2382ms
19
+ ✓ opens the reject confirmation modal with the default English copy  1002ms
20
+ ✓ opens the reject confirmation modal with CMS-provided labels  307ms
21
+ ✓  browser  test/components/ui/RichText/RichText.browser.test.tsx (8 tests) 314ms
22
+ ✓  browser  test/components/account/OrganizationDrawer.browser.test.tsx (10 tests) 1727ms
23
+ ✓ renders the menu view with contract details and manage footer  898ms
24
+ ✓  browser  test/sdk/product/usePageProductsQuery.browser.test.ts (9 tests) 83ms
25
+ ✓  browser  test/sdk/localization/useBindingSelector.browser.test.tsx (9 tests) 40ms
26
+ ✓  browser  test/components/CartRecommendationShelf/CartRecommendationShelf.browser.test.tsx (13 tests) 118ms
27
+ ✓  browser  test/sdk/session/reconcileSessionLocale.browser.test.ts (6 tests) 14ms
28
+ ✓  browser  test/components/ui/ProductGallery/GalleryPageHeightLock.browser.test.tsx (8 tests) 58ms
32
29
  stderr | test/components/RecommendationShelf/RecommendationShelf.browser.test.tsx
33
30
  Error in optimistic validation: TypeError: Failed to parse URL from /api/graphql?operationName=ValidateCartMutation&operationHash=3c71b0d3fc2bade14df68abfa271858beb361b12
34
31
   at node:internal/deps/undici/undici:16416:13
@@ -58,12 +55,22 @@ Browserslist: browsers data (caniuse-lite) is 9 months old. Please run:
58
55
  stderr | test/components/RecommendationShelf/RecommendationShelf.browser.test.tsx > RecommendationShelf > renders nothing when there is an error
59
56
  Error fetching recommendations undefined boom for campaign vrn:recommendations:acc:rec-top-items-v2:campaign-1
60
57
 
61
- ✓  browser  test/components/RecommendationShelf/RecommendationShelf.browser.test.tsx (8 tests) 116ms
62
- ✓  browser  test/sdk/product/useProductQuery.browser.test.ts (5 tests) 371ms
63
- ✓  browser  test/components/sections/Account/AccountOrderDetails.browser.test.tsx (4 tests) 59ms
64
- ✓  browser  test/components/CartSidebar/CartSidebar.browser.test.tsx (5 tests) 126ms
65
- ✓  browser  test/sdk/session/getInitialSession.browser.test.ts (7 tests) 15ms
66
- ✓  browser  test/components/navigation/Navbar.browser.test.tsx (3 tests) 60ms
58
+ ✓  browser  test/components/RecommendationShelf/RecommendationShelf.browser.test.tsx (8 tests) 124ms
59
+ ✓  browser  test/sdk/recommendations/useRecommendationShelf.browser.test.tsx (12 tests) 43ms
60
+ ✓  browser  test/sdk/product/useProductQuery.browser.test.ts (5 tests) 313ms
61
+ ✓  browser  test/components/CartSidebar/CartSidebar.browser.test.tsx (5 tests) 75ms
62
+ ✓  browser  test/sdk/session/getInitialSession.browser.test.ts (7 tests) 12ms
63
+ ✓  browser  test/components/sections/Account/AccountOrderDetails.browser.test.tsx (4 tests) 101ms
64
+ ✓  browser  test/components/navigation/Navbar.browser.test.tsx (3 tests) 98ms
65
+ stderr | test/sdk/session/validateSession.browser.test.ts
66
+ Error in optimistic validation: TypeError: Cannot read properties of undefined (reading 'read')
67
+ at waitForSessionValidated (/home/runner/work/faststore/faststore/packages/core/src/sdk/cart/waitForSessionValidated.ts:16:32)
68
+ at validateCart (/home/runner/work/faststore/faststore/packages/core/src/sdk/cart/index.ts:124:9)
69
+ at onValidate (/home/runner/work/faststore/faststore/packages/core/src/sdk/useStore.ts:18:20)
70
+ at a (/home/runner/work/faststore/faststore/packages/sdk/dist/es/index.mjs:357:23)
71
+  at processTicksAndRejections (node:internal/process/task_queues:103:5)
72
+
73
+ ✓  browser  test/sdk/session/validateSession.browser.test.ts (9 tests) 21ms
67
74
  stderr | test/pages/password-protection.browser.test.tsx > PasswordProtectionLogin > posts the password and redirects to the requested return path
68
75
  Warning: An update to PasswordProtectionLogin inside a test was not wrapped in act(...).
69
76
 
@@ -293,19 +300,11 @@ act(() => {
293
300
  This ensures that you're testing the behavior the user would see in the browser. Learn more at https://reactjs.org/link/wrap-tests-with-act
294
301
  at PasswordProtectionLogin (/home/runner/work/faststore/faststore/packages/core/src/pages/password-protection/index.tsx:19:69)
295
302
 
296
- ✓  browser  test/pages/password-protection.browser.test.tsx (6 tests) 852ms
297
- ✓ renders the password protection form  405ms
298
- stderr | test/sdk/session/validateSession.browser.test.ts
299
- Error in optimistic validation: TypeError: Cannot read properties of undefined (reading 'read')
300
- at waitForSessionValidated (/home/runner/work/faststore/faststore/packages/core/src/sdk/cart/waitForSessionValidated.ts:16:32)
301
- at validateCart (/home/runner/work/faststore/faststore/packages/core/src/sdk/cart/index.ts:124:9)
302
- at onValidate (/home/runner/work/faststore/faststore/packages/core/src/sdk/useStore.ts:18:20)
303
- at a (/home/runner/work/faststore/faststore/packages/sdk/dist/es/index.mjs:357:23)
304
-  at processTicksAndRejections (node:internal/process/task_queues:103:5)
305
-
306
- ✓  browser  test/sdk/session/validateSession.browser.test.ts (9 tests) 22ms
307
- ✓  browser  test/components/account/OrganizationDrawerFooter.browser.test.tsx (8 tests) 824ms
308
- ✓ shows manage link for organization managers  501ms
303
+ ✓  browser  test/pages/password-protection.browser.test.tsx (6 tests) 1035ms
304
+ ✓ renders the password protection form  456ms
305
+ ✓  browser  test/components/account/OrganizationDrawerFooter.browser.test.tsx (8 tests) 597ms
306
+ ✓ shows manage link for organization managers  316ms
307
+ ✓  browser  test/sdk/account/useSwitchContract.browser.test.ts (5 tests) 80ms
309
308
  stderr | test/components/cms/RenderSections.browser.test.tsx
310
309
  Error in optimistic validation: TypeError: Cannot read properties of undefined (reading 'read')
311
310
  at waitForSessionValidated (/home/runner/work/faststore/faststore/packages/core/src/sdk/cart/waitForSessionValidated.ts:16:32)
@@ -314,10 +313,9 @@ This ensures that you're testing the behavior the user would see in the browser.
314
313
  at a (/home/runner/work/faststore/faststore/packages/sdk/dist/es/index.mjs:357:23)
315
314
   at processTicksAndRejections (node:internal/process/task_queues:103:5)
316
315
 
317
- ✓  browser  test/sdk/account/useSwitchContract.browser.test.ts (5 tests) 60ms
318
- ✓  browser  test/components/cms/RenderSections.browser.test.tsx (5 tests) 107ms
319
- ✓  browser  test/sdk/product/usePageProductsQuery.deliveryPromise.browser.test.ts (3 tests) 32ms
320
- ✓  browser  test/components/navigation/NavbarSlider.browser.test.tsx (2 tests) 28ms
316
+ ✓  browser  test/components/cms/RenderSections.browser.test.tsx (5 tests) 79ms
317
+ ✓  browser  test/components/navigation/NavbarSlider.browser.test.tsx (2 tests) 33ms
318
+ ✓  browser  test/sdk/product/usePageProductsQuery.deliveryPromise.browser.test.ts (3 tests) 29ms
321
319
  stderr | test/sdk/localization/store-url.browser.test.ts
322
320
  Error in optimistic validation: TypeError: Cannot read properties of undefined (reading 'read')
323
321
  at waitForSessionValidated (/home/runner/work/faststore/faststore/packages/core/src/sdk/cart/waitForSessionValidated.ts:16:32)
@@ -326,9 +324,9 @@ This ensures that you're testing the behavior the user would see in the browser.
326
324
  at a (/home/runner/work/faststore/faststore/packages/sdk/dist/es/index.mjs:357:23)
327
325
   at processTicksAndRejections (node:internal/process/task_queues:103:5)
328
326
 
329
- ✓  browser  test/sdk/localization/store-url.browser.test.ts (3 tests) 5ms
330
- ✓  browser  test/components/account/Menu.browser.test.tsx (6 tests) 290ms
331
- ✓  browser  test/sdk/account/useAvailableContracts.browser.test.ts (6 tests) 24ms
327
+ ✓  browser  test/sdk/localization/store-url.browser.test.ts (3 tests) 4ms
328
+ ✓  browser  test/components/account/Menu.browser.test.tsx (6 tests) 266ms
329
+ ✓  browser  test/sdk/account/useAvailableContracts.browser.test.ts (6 tests) 34ms
332
330
  stderr | test/sdk/session/refreshTokenRoute.browser.test.ts
333
331
  Error in optimistic validation: TypeError: Cannot read properties of undefined (reading 'read')
334
332
  at waitForSessionValidated (/home/runner/work/faststore/faststore/packages/core/src/sdk/cart/waitForSessionValidated.ts:16:32)
@@ -337,13 +335,13 @@ This ensures that you're testing the behavior the user would see in the browser.
337
335
  at a (/home/runner/work/faststore/faststore/packages/sdk/dist/es/index.mjs:357:23)
338
336
   at processTicksAndRejections (node:internal/process/task_queues:103:5)
339
337
 
340
- ✓  browser  test/sdk/session/refreshTokenRoute.browser.test.ts (3 tests) 8ms
341
- ✓  browser  test/components/templates/SearchPage/SearchWrapper.browser.test.tsx (3 tests) 33ms
342
- ✓  browser  test/sdk/recommendations/useRecommendationShelf.sessionFallback.browser.test.tsx (2 tests) 131ms
343
- ✓  browser  test/components/CartRecommendationShelf/CartRecommendationProductCard.browser.test.tsx (3 tests) 55ms
344
- ✓  browser  test/components/navigation/NavbarAccountArea.browser.test.tsx (4 tests) 60ms
345
- ✓  browser  test/components/sections/Account/AccountListQuotes.browser.test.tsx (4 tests) 114ms
346
- ✓  browser  test/sdk/account/changeContractToken.browser.test.ts (9 tests) 19ms
338
+ ✓  browser  test/components/templates/SearchPage/SearchWrapper.browser.test.tsx (3 tests) 41ms
339
+ ✓  browser  test/sdk/session/refreshTokenRoute.browser.test.ts (3 tests) 7ms
340
+ ✓  browser  test/sdk/recommendations/useRecommendationShelf.sessionFallback.browser.test.tsx (2 tests) 126ms
341
+ ✓  browser  test/components/navigation/NavbarAccountArea.browser.test.tsx (4 tests) 50ms
342
+ ✓  browser  test/components/CartRecommendationShelf/CartRecommendationProductCard.browser.test.tsx (3 tests) 43ms
343
+ ✓  browser  test/components/sections/Account/AccountListQuotes.browser.test.tsx (4 tests) 94ms
344
+ ✓  browser  test/sdk/account/changeContractToken.browser.test.ts (9 tests) 16ms
347
345
  stderr | test/components/account/doLogout.browser.test.ts
348
346
  Error in optimistic validation: TypeError: Cannot read properties of undefined (reading 'read')
349
347
  at waitForSessionValidated (/home/runner/work/faststore/faststore/packages/core/src/sdk/cart/waitForSessionValidated.ts:16:32)
@@ -352,11 +350,11 @@ This ensures that you're testing the behavior the user would see in the browser.
352
350
  at a (/home/runner/work/faststore/faststore/packages/sdk/dist/es/index.mjs:357:23)
353
351
   at processTicksAndRejections (node:internal/process/task_queues:103:5)
354
352
 
355
- ✓  browser  test/components/account/doLogout.browser.test.ts (1 test) 21ms
356
- ✓  browser  test/components/account/OrganizationDrawerHeader.browser.test.tsx (5 tests) 266ms
357
- ✓  browser  test/sdk/product/useProductNotFoundRedirect.browser.test.ts (7 tests) 35ms
358
- ✓  browser  test/sdk/account/useRefreshToken.browser.test.ts (4 tests) 139ms
359
- ✓  browser  test/components/ui/LocalizationButton.browser.test.tsx (3 tests) 44ms
353
+ ✓  browser  test/components/account/doLogout.browser.test.ts (1 test) 27ms
354
+ ✓  browser  test/components/account/OrganizationDrawerHeader.browser.test.tsx (5 tests) 270ms
355
+ ✓  browser  test/sdk/product/useProductNotFoundRedirect.browser.test.ts (7 tests) 23ms
356
+ ✓  browser  test/sdk/account/useRefreshToken.browser.test.ts (4 tests) 135ms
357
+ ✓  browser  test/components/ui/LocalizationButton.browser.test.tsx (3 tests) 35ms
360
358
  stderr | test/sdk/account/clearPersistedSessionState.browser.test.ts
361
359
  Error in optimistic validation: TypeError: Cannot read properties of undefined (reading 'read')
362
360
  at waitForSessionValidated (/home/runner/work/faststore/faststore/packages/core/src/sdk/cart/waitForSessionValidated.ts:16:32)
@@ -365,15 +363,14 @@ This ensures that you're testing the behavior the user would see in the browser.
365
363
  at a (/home/runner/work/faststore/faststore/packages/sdk/dist/es/index.mjs:357:23)
366
364
   at processTicksAndRejections (node:internal/process/task_queues:103:5)
367
365
 
368
- ✓  browser  test/components/account/OrganizationSignInButton.browser.test.tsx (4 tests) 251ms
369
- ✓  browser  test/sdk/account/clearPersistedSessionState.browser.test.ts (4 tests) 18ms
370
- ✓  browser  test/components/sections/Account/AccountOrderDelivery.browser.test.tsx (2 tests) 81ms
371
- ✓  browser  test/components/account/orders/DeliveryOptionAccordion.browser.test.tsx (2 tests) 104ms
372
- ✓  browser  test/components/sections/Account/AccountOrderStatus.browser.test.tsx (3 tests) 102ms
373
- ✓  browser  test/components/sections/Account/AccountListCards.browser.test.tsx (3 tests) 66ms
374
- ✓  browser  test/components/region/useRegion.browser.test.ts (1 test) 22ms
375
- ✓  browser  test/components/sections/Account/AccountOrdersList.browser.test.tsx (2 tests) 25ms
376
- ✓  browser  test/components/account/orders/SummaryCard.browser.test.tsx (2 tests) 100ms
366
+ ✓  browser  test/components/account/OrganizationSignInButton.browser.test.tsx (4 tests) 217ms
367
+ ✓  browser  test/sdk/account/clearPersistedSessionState.browser.test.ts (4 tests) 17ms
368
+ ✓  browser  test/components/sections/Account/AccountOrderDelivery.browser.test.tsx (2 tests) 73ms
369
+ ✓  browser  test/components/account/orders/DeliveryOptionAccordion.browser.test.tsx (2 tests) 63ms
370
+ ✓  browser  test/components/sections/Account/AccountOrderStatus.browser.test.tsx (3 tests) 79ms
371
+ ✓  browser  test/components/sections/Account/AccountListCards.browser.test.tsx (3 tests) 67ms
372
+ ✓  browser  test/components/region/useRegion.browser.test.ts (1 test) 15ms
373
+ ✓  browser  test/components/sections/Account/AccountOrdersList.browser.test.tsx (2 tests) 20ms
377
374
  stderr | test/sdk/session/sessionStore.browser.test.ts
378
375
  Error in optimistic validation: TypeError: Cannot read properties of undefined (reading 'read')
379
376
  at waitForSessionValidated (/home/runner/work/faststore/faststore/packages/core/src/sdk/cart/waitForSessionValidated.ts:16:32)
@@ -382,9 +379,10 @@ This ensures that you're testing the behavior the user would see in the browser.
382
379
  at a (/home/runner/work/faststore/faststore/packages/sdk/dist/es/index.mjs:357:23)
383
380
   at processTicksAndRejections (node:internal/process/task_queues:103:5)
384
381
 
385
- ✓  browser  test/sdk/session/sessionStore.browser.test.ts (2 tests) 7ms
386
- ✓  browser  test/components/account/orders/DeliveryOptionAccordionDeliveryInfo.browser.test.tsx (1 test) 40ms
387
- ✓  browser  test/utils/shouldBypassRefreshToken.browser.test.ts (5 tests) 4ms
382
+ ✓  browser  test/sdk/session/sessionStore.browser.test.ts (2 tests) 4ms
383
+ ✓  browser  test/components/account/orders/SummaryCard.browser.test.tsx (2 tests) 47ms
384
+ ✓  browser  test/components/account/orders/DeliveryOptionAccordionDeliveryInfo.browser.test.tsx (1 test) 33ms
385
+ ✓  browser  test/utils/shouldBypassRefreshToken.browser.test.ts (5 tests) 5ms
388
386
  stderr | test/sdk/account/refreshToken.browser.test.ts
389
387
  Error in optimistic validation: TypeError: Cannot read properties of undefined (reading 'read')
390
388
  at waitForSessionValidated (/home/runner/work/faststore/faststore/packages/core/src/sdk/cart/waitForSessionValidated.ts:16:32)
@@ -393,19 +391,19 @@ This ensures that you're testing the behavior the user would see in the browser.
393
391
  at a (/home/runner/work/faststore/faststore/packages/sdk/dist/es/index.mjs:357:23)
394
392
   at processTicksAndRejections (node:internal/process/task_queues:103:5)
395
393
 
396
- ✓  browser  test/sdk/account/refreshToken.browser.test.ts (2 tests) 6ms
397
- ✓  browser  test/sdk/session/reconcileSessionLocale.disabled.browser.test.ts (1 test) 7ms
398
- ✓  browser  test/components/account/orders/StatusCard.browser.test.tsx (2 tests) 106ms
399
- ✓  browser  test/components/account/orders/DeliveryCard.browser.test.tsx (1 test) 43ms
400
- ✓  browser  test/components/account/orders/DeliveryOptionAccordionProducts.browser.test.tsx (1 test) 39ms
401
- ✓  browser  test/components/skeletons/ProductGridSkeleton.browser.test.tsx (2 tests) 25ms
402
- ✓  node  test/pages/api/switch-contract.test.ts (61 tests) 141ms
403
- ✓  node  test/utils/localization/bindingPaths.test.ts (71 tests) 20ms
404
- ✓  browser  test/components/account/orders/FilterFacetPendingApproval.browser.test.tsx (1 test) 161ms
405
- ✓  node  test/server/password-protection-service.test.ts (22 tests) 32ms
406
- ✓  node  test/server/content/service.test.ts (32 tests) 42ms
407
- ✓  node  test/sdk/localization/useBindingSelector.test.tsx (22 tests) 9ms
408
- ✓  node  test/utils/match-url.test.ts (10 tests) 10ms
394
+ ✓  browser  test/sdk/account/refreshToken.browser.test.ts (2 tests) 3ms
395
+ ✓  browser  test/components/account/orders/StatusCard.browser.test.tsx (2 tests) 77ms
396
+ ✓  browser  test/sdk/session/reconcileSessionLocale.disabled.browser.test.ts (1 test) 3ms
397
+ ✓  browser  test/components/account/orders/DeliveryCard.browser.test.tsx (1 test) 37ms
398
+ ✓  browser  test/components/account/orders/DeliveryOptionAccordionProducts.browser.test.tsx (1 test) 34ms
399
+ ✓  browser  test/components/skeletons/ProductGridSkeleton.browser.test.tsx (2 tests) 30ms
400
+ ✓  node  test/pages/api/switch-contract.test.ts (61 tests) 148ms
401
+ ✓  node  test/utils/localization/bindingPaths.test.ts (71 tests) 15ms
402
+ ✓  browser  test/components/account/orders/FilterFacetPendingApproval.browser.test.tsx (1 test) 149ms
403
+ ✓  node  test/server/content/service.test.ts (32 tests) 33ms
404
+ ✓  node  test/server/password-protection-service.test.ts (22 tests) 30ms
405
+ ✓  node  test/server/cms/ResilientClientCMS.test.ts (24 tests) 99ms
406
+ ✓  node  test/sdk/localization/useBindingSelector.test.tsx (22 tests) 8ms
409
407
  stderr | test/sdk/deliveryPromise/provider.effect.test.tsx > DeliveryPromiseProvider pickup fetch > clears the loading flag after a failed request and retries on the next update
410
408
  Failed to fetch pickup points: Error: network
411
409
  at /home/runner/work/faststore/faststore/packages/core/test/sdk/deliveryPromise/provider.effect.test.tsx:250:30
@@ -432,7 +430,8 @@ This ensures that you're testing the behavior the user would see in the browser.
432
430
  at trace (file:///home/runner/work/faststore/faststore/node_modules/.pnpm/vitest@4.0.18_@opentelemetry+api@1.9.0_@types+node@20.19.13_jiti@2.6.1_jsdom@27.4.0_sas_13be941c57d55f08f06eeaf1c180ddfe/node_modules/vitest/dist/chunks/test.B8ej_ZHS.js:239:21)
433
431
  at runTest (file:///home/runner/work/faststore/faststore/node_modules/.pnpm/@vitest+runner@4.0.18/node_modules/@vitest/runner/dist/index.js:1653:12)
434
432
 
435
- ✓  node  test/sdk/deliveryPromise/provider.effect.test.tsx (9 tests) 86ms
433
+ ✓  node  test/sdk/deliveryPromise/provider.effect.test.tsx (9 tests) 68ms
434
+ ✓  node  test/utils/match-url.test.ts (10 tests) 8ms
436
435
  stderr | test/pages/api/graphql.test.ts > /api/graphql error status propagation > propagates the upstream 400 from a wrapped BadRequestError instead of 500
437
436
  Graphql execution returned with error: [
438
437
  {
@@ -574,10 +573,10 @@ This ensures that you're testing the behavior the user would see in the browser.
574
573
  extensions: { status: 401, type: 'UnauthorizedError' }
575
574
  }
576
575
 
577
- ✓  node  test/pages/api/graphql.test.ts (30 tests) 40ms
578
- ✓  node  test/pages/api/unlock.test.ts (15 tests) 129ms
579
- ✓  node  test/sdk/session/syncSalesChannelFromOrderForm.test.ts (14 tests) 11ms
580
- ✓  node  test/sdk/localization/bindingSelector.test.ts (18 tests) 6ms
576
+ ✓  node  test/pages/api/graphql.test.ts (30 tests) 29ms
577
+ ✓  node  test/pages/api/unlock.test.ts (15 tests) 120ms
578
+ ✓  node  test/sdk/session/syncSalesChannelFromOrderForm.test.ts (14 tests) 9ms
579
+ ✓  node  test/sdk/localization/bindingSelector.test.ts (18 tests) 7ms
581
580
  stderr | test/components/search/SearchInputComponent.test.tsx
582
581
  Warning: forwardRef render functions accept exactly two parameters: props and ref. Did you forget to use the ref parameter?
583
582
 
@@ -651,64 +650,63 @@ Warning: React does not recognize the `providerProps` prop on a DOM element. If
651
650
  at Suspense
652
651
  at Wrapper (/home/runner/work/faststore/faststore/packages/core/test/components/search/SearchInputComponent.test.tsx:139:20)
653
652
 
654
- ✓  node  test/components/search/SearchInputComponent.test.tsx (8 tests) 148ms
655
- ✓  node  test/sdk/account/refreshToken.test.ts (21 tests) 11ms
656
- ✓  node  test/components/quotes/MyAccountListQuotesTable.test.tsx (15 tests) 398ms
657
- ✓  node  test/sdk/search/useSearchHistory.test.ts (13 tests) 43ms
653
+ ✓  node  test/components/search/SearchInputComponent.test.tsx (8 tests) 183ms
654
+ ✓  node  test/sdk/account/refreshToken.test.ts (21 tests) 10ms
655
+ ✓  node  test/components/quotes/MyAccountListQuotesTable.test.tsx (15 tests) 324ms
656
+ ✓  node  test/sdk/search/useSearchHistory.test.ts (13 tests) 35ms
658
657
  stderr | test/pages/pvt/account/cards/index.test.ts > Cards page getServerSideProps > redirects to /pvt/account/403 when the query fails with 401/403
659
658
  { extensions: { status: 401 } }
660
659
 
661
660
  stderr | test/pages/pvt/account/cards/index.test.ts > Cards page getServerSideProps > renders the error state (no redirect) when the query fails with a non-auth status
662
661
  { extensions: { status: 502 } }
663
662
 
664
- ✓  node  test/pages/pvt/account/cards/index.test.ts (8 tests) 7ms
665
- ✓  node  test/components/quotes/quoteFilters.test.ts (26 tests) 22ms
666
- ✓  node  test/utils/productJsonLd.test.ts (36 tests) 8ms
667
- ✓  node  test/components/quotes/MyAccountListQuotes.test.tsx (11 tests) 808ms
668
- ✓ navigates with the search term on blur  359ms
669
- ✓ navigates without a label param when the search is cleared  357ms
670
- ✓  node  test/utils/cookieCacheBusting.test.ts (10 tests) 11ms
671
- ✓  node  test/experimental/myAccountCmsServerSideProps.test.ts (5 tests) 6ms
672
- ✓  node  test/utils/clearCookies.test.ts (20 tests) 27ms
673
- ✓  node  test/utils/multipleTemplates.test.ts (8 tests) 4ms
663
+ ✓  node  test/pages/pvt/account/cards/index.test.ts (8 tests) 6ms
664
+ ✓  node  test/components/quotes/quoteFilters.test.ts (26 tests) 19ms
665
+ ✓  node  test/utils/productJsonLd.test.ts (36 tests) 10ms
666
+ ✓  node  test/utils/cookieCacheBusting.test.ts (10 tests) 10ms
667
+ ✓  node  test/components/quotes/MyAccountListQuotes.test.tsx (11 tests) 802ms
668
+ ✓ navigates with the search term on blur  358ms
669
+ ✓ navigates without a label param when the search is cleared  360ms
670
+ ✓  node  test/experimental/myAccountCmsServerSideProps.test.ts (5 tests) 8ms
671
+ ✓  node  test/utils/clearCookies.test.ts (20 tests) 25ms
672
+ ✓  node  test/utils/multipleTemplates.test.ts (8 tests) 6ms
674
673
  stderr | test/sdk/account/useSetPassword.test.ts > useSetPassword > maps wrongcredentials error responses to the existing message
675
674
  Set password request failed: Bad Request
676
675
 
677
- ✓  node  test/sdk/account/useSetPassword.test.ts (6 tests) 42ms
676
+ ✓  node  test/sdk/account/useSetPassword.test.ts (6 tests) 38ms
678
677
  ✓  node  test/sdk/orderEntry/useOrderEntryOperation.test.ts (8 tests) 36ms
679
- ✓  node  test/utils/localization/localizeRedirectDestination.test.ts (11 tests) 6ms
678
+ ✓  node  test/utils/localization/localizeRedirectDestination.test.ts (11 tests) 4ms
680
679
  ✓  node  test/components/quotes/MyAccountQuotesFilterSlider.test.tsx (8 tests) 149ms
681
- ✓  node  test/components/quotes/MyAccountQuotesStatusSelector.test.tsx (14 tests) 122ms
682
- ✓  node  test/utils/localization/hreflang.test.ts (8 tests) 7ms
683
- ✓  node  test/server/cms/index.test.ts (7 tests) 7ms
684
- ✓  node  test/components/quotes/MyAccountQuotesSelectedTags.test.tsx (10 tests) 101ms
685
- ✓  node  test/sdk/account/getMyAccountRoutes.test.ts (13 tests) 8ms
680
+ ✓  node  test/components/quotes/MyAccountQuotesStatusSelector.test.tsx (14 tests) 124ms
681
+ ✓  node  test/utils/localization/hreflang.test.ts (8 tests) 6ms
682
+ ✓  node  test/sdk/account/getMyAccountRoutes.test.ts (13 tests) 6ms
683
+ ✓  node  test/server/cms/index.test.ts (7 tests) 9ms
684
+ ✓  node  test/components/quotes/MyAccountQuotesSelectedTags.test.tsx (10 tests) 72ms
686
685
  ✓  node  test/server/content/promiseCache.test.ts (10 tests) 14ms
687
- ✓  node  test/sdk/redirects/index.test.ts (7 tests) 43ms
688
- ✓  node  test/sdk/orderEntry/useOrderEntryUpload.test.ts (8 tests) 45ms
689
- ✓  node  test/utils/toRevalidate.test.ts (16 tests) 32ms
690
- ✓  node  test/sdk/orderEntry/useOrderEntry.test.ts (8 tests) 46ms
691
- ✓  node  test/utils/trustedForwardedHost.test.ts (36 tests) 9ms
692
- ✓  node  test/proxy.localization.test.ts (5 tests) 54ms
693
- ✓  node  test/components/account/orders/getDeliveryOptionLabel.test.ts (21 tests) 5ms
694
- ✓  node  test/sdk/graphql/retryPolicy.test.ts (18 tests) 14ms
695
- ✓  node  test/server/cms/myAccountDefaultSections.test.ts (9 tests) 5ms
696
- ✓  node  test/utils/productJsonLdRendering.test.tsx (5 tests) 12ms
697
- ✓  node  test/server/index.test.ts (7 tests) 834ms
698
- ✓ should handle options and execute  432ms
699
- ✓  node  test/proxy.test.ts (4 tests) 14ms
700
- ✓  node  test/pages/api/logout.test.ts (4 tests) 33ms
701
- ✓  node  test/utils/shouldBypassRefreshToken.test.ts (14 tests) 7ms
702
- ✓  node  test/sdk/analytics/useStartRecommendationSession.test.ts (6 tests) 47ms
703
- ✓  node  test/sdk/orderEntry/useOrderFormItems.test.ts (7 tests) 38ms
704
- ✓  node  test/server/webops-api.test.ts (9 tests) 15ms
705
- ✓  node  test/components/account/orders/StatusCard.test.ts (3 tests) 28ms
706
- ✓  node  test/sdk/localization/store-url.test.ts (4 tests) 3ms
707
- ✓  node  test/sdk/deliveryPromise/queries.test.ts (4 tests) 9ms
708
- ✓  node  test/sdk/cart/waitForSessionValidated.test.ts (5 tests) 10ms
709
- ✓  node  test/server/cms/global.test.ts (3 tests) 5ms
686
+ ✓  node  test/sdk/redirects/index.test.ts (7 tests) 33ms
687
+ ✓  node  test/sdk/orderEntry/useOrderEntryUpload.test.ts (8 tests) 63ms
688
+ ✓  node  test/sdk/orderEntry/useOrderEntry.test.ts (8 tests) 33ms
689
+ ✓  node  test/utils/toRevalidate.test.ts (16 tests) 35ms
690
+ ✓  node  test/utils/trustedForwardedHost.test.ts (36 tests) 8ms
691
+ ✓  node  test/proxy.localization.test.ts (5 tests) 33ms
692
+ ✓  node  test/components/account/orders/getDeliveryOptionLabel.test.ts (21 tests) 6ms
693
+ ✓  node  test/sdk/graphql/retryPolicy.test.ts (18 tests) 13ms
694
+ ✓  node  test/server/index.test.ts (7 tests) 560ms
695
+ ✓  node  test/server/cms/myAccountDefaultSections.test.ts (9 tests) 6ms
696
+ ✓  node  test/utils/productJsonLdRendering.test.tsx (5 tests) 11ms
697
+ ✓  node  test/proxy.test.ts (4 tests) 17ms
698
+ ✓  node  test/pages/api/logout.test.ts (4 tests) 25ms
699
+ ✓  node  test/utils/shouldBypassRefreshToken.test.ts (14 tests) 4ms
700
+ ✓  node  test/server/webops-api.test.ts (9 tests) 17ms
701
+ ✓  node  test/sdk/orderEntry/useOrderFormItems.test.ts (7 tests) 44ms
702
+ ✓  node  test/sdk/analytics/useStartRecommendationSession.test.ts (6 tests) 46ms
703
+ ✓  node  test/sdk/deliveryPromise/queries.test.ts (4 tests) 7ms
704
+ ✓  node  test/components/account/orders/StatusCard.test.ts (3 tests) 22ms
705
+ ✓  node  test/sdk/localization/store-url.test.ts (4 tests) 4ms
706
+ ✓  node  test/sdk/cart/waitForSessionValidated.test.ts (5 tests) 9ms
707
+ ✓  node  test/server/cms/global.test.ts (3 tests) 4ms
710
708
  ✓  node  test/sdk/deliveryPromise/provider.test.ts (11 tests) 6ms
711
- ✓  node  test/sdk/auth/useAuth.test.ts (5 tests) 31ms
709
+ ✓  node  test/sdk/auth/useAuth.test.ts (5 tests) 25ms
712
710
  stderr | test/server/storeDirectives.test.ts > store directives through the core server > applies @auth from a store field and validates the session once
713
711
  https://storeframework.vtexcommercestable.com.br/api/vtexid/credential/validate {
714
712
  headers: { 'content-type': 'application/json', 'X-FORWARDED-HOST': '' },
@@ -716,44 +714,44 @@ Warning: React does not recognize the `providerProps` prop on a DOM element. If
716
714
  method: 'POST'
717
715
  } { status: 401, statusText: 'Unauthorized', headers: {} }
718
716
 
719
- ✓  node  test/server/storeDirectives.test.ts (2 tests) 55ms
720
- ✓  node  test/utils/mergeDiscoveryConfig.test.ts (8 tests) 9ms
721
- ✓  node  test/server/rootSpan.test.ts (4 tests) 31ms
722
- ✓  node  test/utils/getRequestHostname.test.ts (12 tests) 4ms
723
- ✓  node  test/pages/api/preview.test.ts (2 tests) 6ms
724
- ✓  node  test/components/account/Layout.test.tsx (6 tests) 63ms
725
- ✓  node  test/components/search/SearchInput.test.ts (6 tests) 7ms
726
- ✓  node  test/utils/validateSessionRefreshToken.test.ts (6 tests) 6ms
727
- ✓  node  test/components/search/SearchDropdown.test.tsx (1 test) 18ms
728
- ✓  node  test/components/region/useRegion.test.ts (1 test) 17ms
729
- ✓  node  test/pages/pvt/account/403.test.ts (5 tests) 7ms
730
- ✓  node  test/sdk/recommendations/vrn.test.ts (5 tests) 5ms
731
- ✓  node  test/utils/retry.test.ts (5 tests) 14ms
732
- ✓  node  test/sdk/account/getIsB2BBuyer.test.ts (7 tests) 6ms
733
- ✓  node  test/sdk/account/getB2BSessionClaims.test.ts (4 tests) 4ms
734
- ✓  node  test/sdk/recommendations/useRecommendationUserId.test.ts (4 tests) 187ms
717
+ ✓  node  test/server/storeDirectives.test.ts (2 tests) 58ms
718
+ ✓  node  test/server/rootSpan.test.ts (4 tests) 33ms
719
+ ✓  node  test/utils/mergeDiscoveryConfig.test.ts (8 tests) 7ms
720
+ ✓  node  test/utils/getRequestHostname.test.ts (12 tests) 5ms
721
+ ✓  node  test/pages/api/preview.test.ts (2 tests) 7ms
722
+ ✓  node  test/components/account/Layout.test.tsx (6 tests) 50ms
723
+ ✓  node  test/components/search/SearchInput.test.ts (6 tests) 6ms
724
+ ✓  node  test/utils/validateSessionRefreshToken.test.ts (6 tests) 3ms
725
+ ✓  node  test/components/search/SearchDropdown.test.tsx (1 test) 17ms
726
+ ✓  node  test/components/region/useRegion.test.ts (1 test) 22ms
727
+ ✓  node  test/pages/pvt/account/403.test.ts (5 tests) 4ms
728
+ ✓  node  test/sdk/recommendations/vrn.test.ts (5 tests) 3ms
729
+ ✓  node  test/utils/retry.test.ts (5 tests) 17ms
730
+ ✓  node  test/sdk/account/getIsB2BBuyer.test.ts (7 tests) 5ms
731
+ ✓  node  test/sdk/account/getB2BSessionClaims.test.ts (4 tests) 3ms
732
+ ✓  node  test/sdk/recommendations/useRecommendationUserId.test.ts (4 tests) 184ms
735
733
  ✓  node  test/utils/subDomainPrefixWarning.test.ts (6 tests) 4ms
736
- ✓  node  test/utils/userOrderStatus.test.ts (4 tests) 5ms
737
- ✓  node  test/utils/unlockResponse.test.ts (11 tests) 4ms
738
- ✓  node  test/sdk/recommendations/useRecommendations.test.ts (2 tests) 5ms
739
- ✓  node  test/components/account/OrganizationDrawerBody.test.tsx (3 tests) 34ms
740
- ✓  node  test/sdk/deliveryPromise/reducer.test.ts (2 tests) 5ms
741
- ✓  node  test/utils/isLocalHost.test.ts (7 tests) 3ms
742
- ✓  node  test/components/quotes/MyAccountQuoteStatusBadge.test.tsx (4 tests) 39ms
734
+ ✓  node  test/utils/userOrderStatus.test.ts (4 tests) 4ms
735
+ ✓  node  test/utils/unlockResponse.test.ts (11 tests) 5ms
736
+ ✓  node  test/sdk/recommendations/useRecommendations.test.ts (2 tests) 4ms
737
+ ✓  node  test/components/account/OrganizationDrawerBody.test.tsx (3 tests) 30ms
738
+ ✓  node  test/sdk/deliveryPromise/reducer.test.ts (2 tests) 4ms
739
+ ✓  node  test/components/quotes/MyAccountQuoteStatusBadge.test.tsx (4 tests) 36ms
740
+ ✓  node  test/utils/isLocalHost.test.ts (7 tests) 4ms
743
741
  ✓  node  test/sdk/session/toSessionInput.test.ts (3 tests) 4ms
744
- ✓  node  test/components/account/orders/getOrderTotalLabel.test.ts (6 tests) 4ms
745
- ✓  node  test/components/account/orders/listOrdersLabels.test.ts (2 tests) 4ms
746
- ✓  node  test/utils/getCookie.test.ts (4 tests) 5ms
747
- ✓  node  test/components/auth/ProfileChallenge.test.tsx (3 tests) 37ms
748
- ✓  node  test/sdk/session/isSignInAreaResolved.test.ts (3 tests) 2ms
749
- ✓  node  test/utils/filterChannel.test.ts (2 tests) 4ms
742
+ ✓  node  test/components/account/orders/getOrderTotalLabel.test.ts (6 tests) 3ms
743
+ ✓  node  test/components/account/orders/listOrdersLabels.test.ts (2 tests) 3ms
744
+ ✓  node  test/utils/getCookie.test.ts (4 tests) 4ms
745
+ ✓  node  test/sdk/session/isSignInAreaResolved.test.ts (3 tests) 3ms
746
+ ✓  node  test/utils/filterChannel.test.ts (2 tests) 2ms
747
+ ✓  node  test/components/auth/ProfileChallenge.test.tsx (3 tests) 34ms
750
748
  ✓  node  test/sdk/analytics/utils.test.ts (2 tests) 3ms
751
749
  ✓  node  test/instrumentation.test.ts (3 tests) 5ms
752
- ✓  node  test/components/account/orders/orderDetailsLabels.test.ts (1 test) 4ms
753
- ✓  node  test/sdk/account/clearPersistedSessionState.test.ts (1 test) 8ms
750
+ ✓  node  test/components/account/orders/orderDetailsLabels.test.ts (1 test) 2ms
751
+ ✓  node  test/sdk/account/clearPersistedSessionState.test.ts (1 test) 6ms
754
752
 
755
-  Test Files  151 passed (151)
756
-  Tests  1289 passed (1289)
757
-  Start at  12:25:27
758
-  Duration  60.94s (transform 15.17s, setup 0ms, import 56.78s, tests 20.96s, environment 72.60s)
753
+  Test Files  152 passed (152)
754
+  Tests  1313 passed (1313)
755
+  Start at  13:21:27
756
+  Duration  53.04s (transform 11.66s, setup 0ms, import 45.59s, tests 18.41s, environment 66.42s)
759
757
 
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
+ ## [4.11.4-dev.5](https://github.com/vtex/faststore/compare/v4.11.4-dev.4...v4.11.4-dev.5) (2026-11-19)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **core:** retry CMS fetch bypassing cache on invalid JSON ([#3590](https://github.com/vtex/faststore/issues/3590)) ([12f9062](https://github.com/vtex/faststore/commit/12f9062184eef948f29d2aeac0308c97300d842f))
11
+
6
12
  ## [4.11.4-dev.4](https://github.com/vtex/faststore/compare/v4.11.4-dev.3...v4.11.4-dev.4) (2026-11-19)
7
13
 
8
14
  ### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/core",
3
- "version": "4.11.4-dev.4",
3
+ "version": "4.11.4-dev.5",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -70,11 +70,11 @@
70
70
  "style-loader": "^3.3.1",
71
71
  "swr": "^2.2.5",
72
72
  "use-sync-external-store": "^1.6.0",
73
- "@faststore/api": "4.11.4-dev.4",
74
- "@faststore/diagnostics": "4.11.4-dev.4",
75
- "@faststore/lighthouse": "4.11.4-dev.4",
76
- "@faststore/sdk": "4.11.4-dev.4",
77
- "@faststore/ui": "4.11.4-dev.4"
73
+ "@faststore/api": "4.11.4-dev.5",
74
+ "@faststore/diagnostics": "4.11.4-dev.5",
75
+ "@faststore/sdk": "4.11.4-dev.5",
76
+ "@faststore/lighthouse": "4.11.4-dev.5",
77
+ "@faststore/ui": "4.11.4-dev.5"
78
78
  },
79
79
  "devDependencies": {
80
80
  "@cypress/code-coverage": "^3.12.1",
@@ -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
+ }
@@ -1,11 +1,12 @@
1
1
  import type { ContentData, 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 { getStoreURL } from 'src/sdk/localization/useLocalizationConfig'
6
6
  import { createPromiseCache } from 'src/server/content/promiseCache'
7
7
  import { sanitizeHost } from 'src/utils/utilities'
8
8
  import config from '../../../discovery.config'
9
+ import { ResilientClientCMS } from './ResilientClientCMS'
9
10
 
10
11
  export type Options =
11
12
  | Locator
@@ -72,7 +73,7 @@ export const isLocator = (x: any): x is Locator =>
72
73
  typeof x.documentId === 'string' ||
73
74
  typeof x.versionId === 'string')
74
75
 
75
- export const clientCMS = new ClientCMS({
76
+ export const clientCMS = new ResilientClientCMS({
76
77
  workspace: config.api.workspace,
77
78
  tenant: config.api.storeId,
78
79
  builder:
@@ -0,0 +1,482 @@
1
+ import type { Server } from 'node:http'
2
+ import { createServer } from 'node:http'
3
+ import type { AddressInfo } from 'node:net'
4
+ import { gzipSync } from 'node:zlib'
5
+ import ClientCMS from '@vtex/client-cms'
6
+ import type { ContentData, ContentPage } from '@vtex/client-cms'
7
+ import {
8
+ afterAll,
9
+ afterEach,
10
+ beforeAll,
11
+ beforeEach,
12
+ describe,
13
+ expect,
14
+ it,
15
+ vi,
16
+ } from 'vitest'
17
+
18
+ import { clientCMS, cmsPageCache, getCMSPage } from '../../../src/server/cms'
19
+ import {
20
+ CACHE_BUST_PARAM,
21
+ CACHE_BUST_WINDOW_MS,
22
+ RETRY_COOLDOWN_MS,
23
+ ResilientClientCMS,
24
+ } from '../../../src/server/cms/ResilientClientCMS'
25
+
26
+ const invalidJSON = () =>
27
+ new SyntaxError('Unexpected token \u001f in JSON at position 0')
28
+
29
+ const contentData = (id: string): ContentData => ({
30
+ id,
31
+ name: id,
32
+ status: 'published',
33
+ type: 'plp',
34
+ sections: [],
35
+ releaseId: '',
36
+ })
37
+
38
+ const listingPage = (
39
+ page: number,
40
+ count: number,
41
+ totalItems: number
42
+ ): ContentPage => ({
43
+ data: Array.from({ length: count }, (_, i) =>
44
+ contentData(`page-${page}-item-${i}`)
45
+ ),
46
+ hasNextPage: page * 10 < totalItems,
47
+ totalItems,
48
+ })
49
+
50
+ describe('ResilientClientCMS', () => {
51
+ // `ResilientClientCMS#fetch` delegates to the `ClientCMS` implementation,
52
+ // which performs the HTTP request and parses the JSON body.
53
+ let baseFetch: ReturnType<typeof vi.spyOn>
54
+ let warn: ReturnType<typeof vi.spyOn>
55
+
56
+ const createClient = () =>
57
+ new ResilientClientCMS({
58
+ tenant: 'store',
59
+ workspace: 'master',
60
+ builder: 'faststore',
61
+ host: 'www.example.com',
62
+ })
63
+
64
+ const paramsOfCall = (call: number) =>
65
+ baseFetch.mock.calls[call][1] as URLSearchParams | undefined
66
+
67
+ beforeEach(() => {
68
+ cmsPageCache.clear()
69
+ baseFetch = vi.spyOn(ClientCMS.prototype, 'fetch')
70
+ warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
71
+ })
72
+
73
+ afterEach(() => {
74
+ vi.restoreAllMocks()
75
+ })
76
+
77
+ it('makes a single request when the response is valid', async () => {
78
+ const page = listingPage(1, 3, 3)
79
+ baseFetch.mockResolvedValueOnce(page)
80
+
81
+ const result = await createClient().getCMSPagesByContentType('plp')
82
+
83
+ expect(result).toEqual(page)
84
+ expect(baseFetch).toHaveBeenCalledTimes(1)
85
+ expect(paramsOfCall(0)?.has(CACHE_BUST_PARAM)).toBe(false)
86
+ expect(warn).not.toHaveBeenCalled()
87
+ })
88
+
89
+ it('retries once bypassing the cache when the body is not valid JSON', async () => {
90
+ const page = listingPage(8, 10, 100)
91
+ baseFetch.mockRejectedValueOnce(invalidJSON()).mockResolvedValueOnce(page)
92
+
93
+ const result = await createClient().getCMSPagesByContentType('plp', {
94
+ page: 8,
95
+ perPage: 10,
96
+ })
97
+
98
+ expect(result).toEqual(page)
99
+ expect(baseFetch).toHaveBeenCalledTimes(2)
100
+
101
+ expect(baseFetch.mock.calls[1][0]).toBe('plp')
102
+ const retryParams = paramsOfCall(1)
103
+ expect(retryParams?.get('page')).toBe('8')
104
+ expect(retryParams?.get('per_page')).toBe('10')
105
+ expect(retryParams?.get(CACHE_BUST_PARAM)).toMatch(/^\d+$/)
106
+ // The original params are not mutated.
107
+ expect(paramsOfCall(0)?.has(CACHE_BUST_PARAM)).toBe(false)
108
+
109
+ expect(warn).toHaveBeenCalledTimes(1)
110
+ expect(warn.mock.calls[0][0]).toContain('plp?page=8&per_page=10')
111
+ })
112
+
113
+ it('rejects when the retry is not valid JSON either', async () => {
114
+ baseFetch
115
+ .mockRejectedValueOnce(invalidJSON())
116
+ .mockRejectedValueOnce(invalidJSON())
117
+
118
+ await expect(
119
+ createClient().getCMSPagesByContentType('plp')
120
+ ).rejects.toBeInstanceOf(SyntaxError)
121
+ expect(baseFetch).toHaveBeenCalledTimes(2)
122
+ })
123
+
124
+ it('handles the invalid-json error raised by node-fetch', async () => {
125
+ const nodeFetchError = Object.assign(
126
+ new Error('invalid json response body'),
127
+ { type: 'invalid-json' }
128
+ )
129
+ const document = contentData('document')
130
+ baseFetch
131
+ .mockRejectedValueOnce(nodeFetchError)
132
+ .mockResolvedValueOnce(document)
133
+
134
+ const result = await createClient().getCMSPage({
135
+ contentType: 'landingPage',
136
+ documentId: 'document',
137
+ versionId: 'version',
138
+ })
139
+
140
+ expect(result).toEqual(document)
141
+ expect(baseFetch).toHaveBeenCalledTimes(2)
142
+ expect(baseFetch.mock.calls[1][0]).toBe('landingPage/document')
143
+ expect(paramsOfCall(1)?.get('versionId')).toBe('version')
144
+ })
145
+
146
+ it('passes a body that parses to null through without retrying', async () => {
147
+ baseFetch.mockResolvedValueOnce(null)
148
+
149
+ const result = await createClient().getCMSPagesByContentType('plp')
150
+
151
+ expect(result).toBeNull()
152
+ expect(baseFetch).toHaveBeenCalledTimes(1)
153
+ expect(warn).not.toHaveBeenCalled()
154
+ })
155
+
156
+ it('adds the cache-busting param to requests without params', async () => {
157
+ baseFetch
158
+ .mockRejectedValueOnce(invalidJSON())
159
+ .mockResolvedValueOnce({ contentTypes: [{ id: 'plp' }] })
160
+
161
+ const result = await createClient().getAllContentTypeIds()
162
+
163
+ expect(result).toEqual(['plp'])
164
+ expect(paramsOfCall(1)?.has(CACHE_BUST_PARAM)).toBe(true)
165
+ })
166
+
167
+ it('does not retry other errors', async () => {
168
+ const error = new Error('Error while fetching')
169
+ baseFetch.mockRejectedValueOnce(error)
170
+
171
+ await expect(createClient().getCMSPagesByContentType('plp')).rejects.toBe(
172
+ error
173
+ )
174
+ expect(baseFetch).toHaveBeenCalledTimes(1)
175
+ expect(warn).not.toHaveBeenCalled()
176
+ })
177
+
178
+ it('retries when the body cannot be decoded', async () => {
179
+ // undici's error when `Content-Encoding` does not match the body bytes.
180
+ const decodingError = Object.assign(new TypeError('terminated'), {
181
+ cause: Object.assign(new Error('incorrect header check'), {
182
+ code: 'Z_DATA_ERROR',
183
+ }),
184
+ })
185
+ const page = listingPage(1, 1, 1)
186
+ baseFetch.mockRejectedValueOnce(decodingError).mockResolvedValueOnce(page)
187
+
188
+ const result = await createClient().getCMSPagesByContentType('plp')
189
+
190
+ expect(result).toEqual(page)
191
+ expect(baseFetch).toHaveBeenCalledTimes(2)
192
+ expect(warn.mock.calls[0][0]).toContain('TypeError: Z_DATA_ERROR')
193
+ })
194
+
195
+ it('retries a SyntaxError created in another realm', async () => {
196
+ const foreignSyntaxError = Object.assign(new Error('Unexpected token'), {
197
+ name: 'SyntaxError',
198
+ })
199
+ const page = listingPage(1, 1, 1)
200
+ baseFetch
201
+ .mockRejectedValueOnce(foreignSyntaxError)
202
+ .mockResolvedValueOnce(page)
203
+
204
+ const result = await createClient().getCMSPagesByContentType('plp')
205
+
206
+ expect(result).toEqual(page)
207
+ expect(baseFetch).toHaveBeenCalledTimes(2)
208
+ })
209
+
210
+ it('does not retry a connection reset while reading the body', async () => {
211
+ const error = Object.assign(new TypeError('terminated'), {
212
+ cause: Object.assign(new Error('read ECONNRESET'), {
213
+ code: 'ECONNRESET',
214
+ }),
215
+ })
216
+ baseFetch.mockRejectedValueOnce(error)
217
+
218
+ await expect(createClient().getCMSPagesByContentType('plp')).rejects.toBe(
219
+ error
220
+ )
221
+ expect(baseFetch).toHaveBeenCalledTimes(1)
222
+ })
223
+
224
+ it('retries when a brotli body cannot be decoded', async () => {
225
+ // Node's brotli decoder codes start with `ERR__ERROR_` (double underscore).
226
+ const decodingError = Object.assign(new TypeError('terminated'), {
227
+ cause: Object.assign(new Error('Decompression failed'), {
228
+ code: 'ERR__ERROR_FORMAT_PADDING_1',
229
+ }),
230
+ })
231
+ const page = listingPage(1, 1, 1)
232
+ baseFetch.mockRejectedValueOnce(decodingError).mockResolvedValueOnce(page)
233
+
234
+ const result = await createClient().getCMSPagesByContentType('plp')
235
+
236
+ expect(result).toEqual(page)
237
+ expect(baseFetch).toHaveBeenCalledTimes(2)
238
+ expect(warn.mock.calls[0][0]).toContain(
239
+ 'TypeError: ERR__ERROR_FORMAT_PADDING_1'
240
+ )
241
+ })
242
+
243
+ it('reuses the cache-busting value within a window', async () => {
244
+ const now = vi.spyOn(Date, 'now').mockReturnValue(10 * CACHE_BUST_WINDOW_MS)
245
+ const client = createClient()
246
+ const page = listingPage(1, 1, 1)
247
+ baseFetch
248
+ .mockRejectedValueOnce(invalidJSON())
249
+ .mockResolvedValueOnce(page)
250
+ .mockRejectedValueOnce(invalidJSON())
251
+ .mockResolvedValueOnce(page)
252
+ .mockRejectedValueOnce(invalidJSON())
253
+ .mockResolvedValueOnce(page)
254
+
255
+ await client.getCMSPagesByContentType('plp')
256
+ now.mockReturnValue(11 * CACHE_BUST_WINDOW_MS - 1)
257
+ await client.getCMSPagesByContentType('plp')
258
+ now.mockReturnValue(11 * CACHE_BUST_WINDOW_MS)
259
+ await client.getCMSPagesByContentType('plp')
260
+
261
+ expect(paramsOfCall(1)?.get(CACHE_BUST_PARAM)).toBe('10')
262
+ expect(paramsOfCall(3)?.get(CACHE_BUST_PARAM)).toBe('10')
263
+ expect(paramsOfCall(5)?.get(CACHE_BUST_PARAM)).toBe('11')
264
+ })
265
+
266
+ describe('retry cooldown', () => {
267
+ it('fails fast for a URL whose retry also failed', async () => {
268
+ const client = createClient()
269
+ baseFetch.mockRejectedValue(invalidJSON())
270
+
271
+ await expect(
272
+ client.getCMSPagesByContentType('plp')
273
+ ).rejects.toBeInstanceOf(SyntaxError)
274
+ expect(baseFetch).toHaveBeenCalledTimes(2)
275
+
276
+ await expect(
277
+ client.getCMSPagesByContentType('plp')
278
+ ).rejects.toBeInstanceOf(SyntaxError)
279
+ expect(baseFetch).toHaveBeenCalledTimes(3)
280
+ // One warning for the retry and one for the cooldown.
281
+ expect(warn).toHaveBeenCalledTimes(2)
282
+ expect(warn.mock.calls[1][0]).toContain(
283
+ 'Skipping retries for this URL for 60s'
284
+ )
285
+ })
286
+
287
+ it('also backs off when the retry fails with another error', async () => {
288
+ const client = createClient()
289
+ const originError = new Error('Error while fetching')
290
+ baseFetch
291
+ .mockRejectedValueOnce(invalidJSON())
292
+ .mockRejectedValueOnce(originError)
293
+ .mockRejectedValueOnce(invalidJSON())
294
+
295
+ await expect(client.getCMSPagesByContentType('plp')).rejects.toBe(
296
+ originError
297
+ )
298
+ await expect(
299
+ client.getCMSPagesByContentType('plp')
300
+ ).rejects.toBeInstanceOf(SyntaxError)
301
+ expect(baseFetch).toHaveBeenCalledTimes(3)
302
+ })
303
+
304
+ it('still retries other URLs', async () => {
305
+ const client = createClient()
306
+ const page = listingPage(2, 10, 20)
307
+ baseFetch
308
+ .mockRejectedValueOnce(invalidJSON())
309
+ .mockRejectedValueOnce(invalidJSON())
310
+ .mockRejectedValueOnce(invalidJSON())
311
+ .mockResolvedValueOnce(page)
312
+
313
+ await expect(
314
+ client.getCMSPagesByContentType('plp')
315
+ ).rejects.toBeInstanceOf(SyntaxError)
316
+ await expect(
317
+ client.getCMSPagesByContentType('plp', { page: 2 })
318
+ ).resolves.toEqual(page)
319
+ expect(baseFetch).toHaveBeenCalledTimes(4)
320
+ })
321
+
322
+ it('retries the URL again after the cooldown', async () => {
323
+ const now = vi.spyOn(Date, 'now').mockReturnValue(1_000_000)
324
+ const client = createClient()
325
+ const page = listingPage(1, 1, 1)
326
+ baseFetch
327
+ .mockRejectedValueOnce(invalidJSON())
328
+ .mockRejectedValueOnce(invalidJSON())
329
+ .mockRejectedValueOnce(invalidJSON())
330
+ .mockResolvedValueOnce(page)
331
+
332
+ await expect(
333
+ client.getCMSPagesByContentType('plp')
334
+ ).rejects.toBeInstanceOf(SyntaxError)
335
+
336
+ now.mockReturnValue(1_000_000 + RETRY_COOLDOWN_MS)
337
+
338
+ await expect(client.getCMSPagesByContentType('plp')).resolves.toEqual(
339
+ page
340
+ )
341
+ expect(baseFetch).toHaveBeenCalledTimes(4)
342
+ // The retry after the cooldown uses a new cache-busting value.
343
+ expect(paramsOfCall(3)?.get(CACHE_BUST_PARAM)).not.toBe(
344
+ paramsOfCall(1)?.get(CACHE_BUST_PARAM)
345
+ )
346
+ })
347
+
348
+ it('lasts at least one cache-busting window', () => {
349
+ expect(RETRY_COOLDOWN_MS).toBeGreaterThanOrEqual(CACHE_BUST_WINDOW_MS)
350
+ })
351
+ })
352
+
353
+ describe('with real HTTP responses', () => {
354
+ // Real `fetch` and `response.json()` against a local server, like
355
+ // `@vtex/client-cms` does, to pin the error shapes the runtime produces.
356
+ // The server answers the bad body until the cache-busting param is sent,
357
+ // and closes each connection so `server.close()` does not wait on sockets.
358
+ const good: ContentPage = { data: [], hasNextPage: false, totalItems: 0 }
359
+ const goodJSON = JSON.stringify(good)
360
+ const badResponses: Record<
361
+ string,
362
+ { headers: Record<string, string>; body: string | Buffer }
363
+ > = {
364
+ 'gzip-without-content-encoding': {
365
+ headers: {},
366
+ body: gzipSync(goodJSON),
367
+ },
368
+ 'content-encoding-gzip-on-plain-body': {
369
+ headers: { 'content-encoding': 'gzip' },
370
+ body: goodJSON,
371
+ },
372
+ 'content-encoding-br-on-plain-body': {
373
+ headers: { 'content-encoding': 'br' },
374
+ body: goodJSON,
375
+ },
376
+ 'html-page': {
377
+ headers: { 'content-type': 'text/html' },
378
+ body: '<html>Error</html>',
379
+ },
380
+ 'truncated-json': { headers: {}, body: goodJSON.slice(0, 10) },
381
+ }
382
+
383
+ let server: Server
384
+ let origin = ''
385
+
386
+ beforeAll(async () => {
387
+ server = createServer((req, res) => {
388
+ const url = new URL(req.url ?? '/', 'http://localhost')
389
+ const bad = badResponses[url.pathname.slice(1)]
390
+
391
+ if (bad && !url.searchParams.has(CACHE_BUST_PARAM)) {
392
+ res.writeHead(200, { ...bad.headers, connection: 'close' })
393
+ res.end(bad.body)
394
+ return
395
+ }
396
+
397
+ res.writeHead(200, {
398
+ 'content-type': 'application/json',
399
+ connection: 'close',
400
+ })
401
+ res.end(goodJSON)
402
+ })
403
+ await new Promise<void>((resolve) =>
404
+ server.listen(0, '127.0.0.1', resolve)
405
+ )
406
+ origin = `http://127.0.0.1:${(server.address() as AddressInfo).port}`
407
+ })
408
+
409
+ afterAll(async () => {
410
+ await new Promise<void>((resolve) => server.close(() => resolve()))
411
+ })
412
+
413
+ beforeEach(() => {
414
+ baseFetch.mockImplementation(
415
+ async (path?: string, params?: URLSearchParams) => {
416
+ const query = params?.toString()
417
+ const response = await fetch(
418
+ [`${origin}/${path}`, query].filter(Boolean).join('?')
419
+ )
420
+
421
+ if (!response.ok) {
422
+ throw new Error('Error while fetching')
423
+ }
424
+
425
+ return response.json()
426
+ }
427
+ )
428
+ })
429
+
430
+ it.each(Object.keys(badResponses))(
431
+ 'retries a %s response',
432
+ async (name) => {
433
+ await expect(
434
+ createClient().getCMSPagesByContentType(name)
435
+ ).resolves.toEqual(good)
436
+ expect(baseFetch).toHaveBeenCalledTimes(2)
437
+ }
438
+ )
439
+ })
440
+
441
+ describe('getCMSPage', () => {
442
+ // Page 1 says there are 25 items, so pages 2 and 3 are fetched in
443
+ // parallel. Page 2 answers with an invalid body the first time.
444
+ const mockListingWithOneBadPage = () => {
445
+ let badResponses = 1
446
+
447
+ baseFetch.mockImplementation(async (_path, params) => {
448
+ const page = Number((params as URLSearchParams).get('page'))
449
+
450
+ if (page === 2 && badResponses > 0) {
451
+ badResponses -= 1
452
+ throw invalidJSON()
453
+ }
454
+
455
+ return listingPage(page, page === 3 ? 5 : 10, 25)
456
+ })
457
+ }
458
+
459
+ it('recovers when one page of a listing has an invalid body', async () => {
460
+ mockListingWithOneBadPage()
461
+
462
+ const result = await getCMSPage({ contentType: 'plp' }, createClient())
463
+
464
+ expect(result.data).toHaveLength(25)
465
+ expect(result.data[10].id).toBe('page-2-item-0')
466
+ // Pages 1, 2 and 3, plus the retry of page 2.
467
+ expect(baseFetch).toHaveBeenCalledTimes(4)
468
+ expect(warn).toHaveBeenCalledTimes(1)
469
+ expect(warn.mock.calls[0][0]).toContain('page=2')
470
+ })
471
+
472
+ it('is used by the default CMS client', async () => {
473
+ mockListingWithOneBadPage()
474
+
475
+ const result = await getCMSPage({ contentType: 'plp' }, clientCMS)
476
+
477
+ expect(clientCMS).toBeInstanceOf(ResilientClientCMS)
478
+ expect(result.data).toHaveLength(25)
479
+ expect(baseFetch).toHaveBeenCalledTimes(4)
480
+ })
481
+ })
482
+ })