@faststore/core 3.0.58 → 3.0.59

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.
Files changed (82) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/app-build-manifest.json +4 -4
  3. package/.next/build-manifest.json +31 -31
  4. package/.next/cache/.tsbuildinfo +1 -1
  5. package/.next/cache/config.json +3 -3
  6. package/.next/cache/eslint/.cache_1gneedd +1 -1
  7. package/.next/cache/fetch-cache/50912854cb7c781522a6ff8792d714e549515fcbbbfd660761961b06afe01c07 +1 -1
  8. package/.next/cache/webpack/client-production/0.pack +0 -0
  9. package/.next/cache/webpack/client-production/index.pack +0 -0
  10. package/.next/cache/webpack/server-production/0.pack +0 -0
  11. package/.next/cache/webpack/server-production/index.pack +0 -0
  12. package/.next/next-minimal-server.js.nft.json +1 -1
  13. package/.next/next-server.js.nft.json +1 -1
  14. package/.next/prerender-manifest.js +1 -1
  15. package/.next/prerender-manifest.json +1 -1
  16. package/.next/react-loadable-manifest.json +3 -3
  17. package/.next/routes-manifest.json +1 -1
  18. package/.next/server/app/_not-found.html +2 -2
  19. package/.next/server/app/_not-found.js +1 -1
  20. package/.next/server/app/_not-found.js.nft.json +1 -1
  21. package/.next/server/app/_not-found.rsc +4 -4
  22. package/.next/server/app/_not-found_client-reference-manifest.js +1 -1
  23. package/.next/server/app/fs-next-update/page.js +1 -1
  24. package/.next/server/app/fs-next-update/page.js.nft.json +1 -1
  25. package/.next/server/app/fs-next-update/page_client-reference-manifest.js +1 -1
  26. package/.next/server/app/fs-next-update.html +2 -2
  27. package/.next/server/app/fs-next-update.rsc +4 -4
  28. package/.next/server/chunks/1481.js +2 -2
  29. package/.next/server/chunks/{2317.js → 1889.js} +2 -2
  30. package/.next/server/middleware-build-manifest.js +1 -1
  31. package/.next/server/middleware-react-loadable-manifest.js +1 -1
  32. package/.next/server/pages/404.html +2 -2
  33. package/.next/server/pages/404.js.nft.json +1 -1
  34. package/.next/server/pages/500.js.nft.json +1 -1
  35. package/.next/server/pages/[...slug].js.nft.json +1 -1
  36. package/.next/server/pages/[slug]/p.js.nft.json +1 -1
  37. package/.next/server/pages/_app.js.nft.json +1 -1
  38. package/.next/server/pages/_document.js.nft.json +1 -1
  39. package/.next/server/pages/_error.js.nft.json +1 -1
  40. package/.next/server/pages/account.js.nft.json +1 -1
  41. package/.next/server/pages/api/graphql.js.nft.json +1 -1
  42. package/.next/server/pages/api/health/live.js.nft.json +1 -1
  43. package/.next/server/pages/api/health/ready.js.nft.json +1 -1
  44. package/.next/server/pages/api/preview.js.nft.json +1 -1
  45. package/.next/server/pages/checkout.js.nft.json +1 -1
  46. package/.next/server/pages/en-US/404.html +2 -2
  47. package/.next/server/pages/en-US/404.json +1 -1
  48. package/.next/server/pages/en-US/500.html +2 -2
  49. package/.next/server/pages/en-US/500.json +1 -1
  50. package/.next/server/pages/en-US/account.html +2 -2
  51. package/.next/server/pages/en-US/account.json +1 -1
  52. package/.next/server/pages/en-US/checkout.html +2 -2
  53. package/.next/server/pages/en-US/checkout.json +1 -1
  54. package/.next/server/pages/en-US/login.html +2 -2
  55. package/.next/server/pages/en-US/login.json +1 -1
  56. package/.next/server/pages/en-US/s.html +2 -2
  57. package/.next/server/pages/en-US/s.json +1 -1
  58. package/.next/server/pages/en-US.html +2 -2
  59. package/.next/server/pages/en-US.json +1 -1
  60. package/.next/server/pages/index.js.nft.json +1 -1
  61. package/.next/server/pages/login.js.nft.json +1 -1
  62. package/.next/server/pages/s.js.nft.json +1 -1
  63. package/.next/server/pages-manifest.json +1 -1
  64. package/.next/static/chunks/{432-ea0bb3dcebbaab7b.js → 432-292475e2dafbb79e.js} +1 -1
  65. package/.next/static/chunks/{590-2e7ce772420d1e1a.js → 590-a0b6f16148203bf2.js} +1 -1
  66. package/.next/static/chunks/{667.2cacb6e5980b1219.js → 667.83389641ca332aef.js} +1 -1
  67. package/.next/static/chunks/{722-36fe06b9c486056e.js → 722-ed59bc6f32bb342f.js} +1 -1
  68. package/.next/static/chunks/{724.39212f642dc0d0bf.js → 724.78d40a7affe1d40b.js} +1 -1
  69. package/.next/static/chunks/{853.50e13fd0510fbf80.js → 853.a3933410052d23c8.js} +1 -1
  70. package/.next/static/chunks/app/{layout-aa18388c0586ed1f.js → layout-91b2430897aac937.js} +2 -2
  71. package/.next/static/chunks/pages/[slug]/{p-25a61a48b78901e5.js → p-d7c7044639459d13.js} +1 -1
  72. package/.next/static/chunks/pages/{_app-00cee674a20813ff.js → _app-1930798899758fda.js} +1 -1
  73. package/.next/static/chunks/{webpack-d7ccbda472189c19.js → webpack-a45dc84c9a0ef3fd.js} +1 -1
  74. package/.next/static/lIYvWbgkX76Tpj8gVu1kU/_buildManifest.js +1 -0
  75. package/.next/trace +62 -62
  76. package/.turbo/turbo-build.log +4 -4
  77. package/.turbo/turbo-test.log +4 -4
  78. package/package.json +2 -2
  79. package/src/server/cms/index.ts +30 -57
  80. package/test/server/cms/index.test.ts +2 -32
  81. package/.next/static/2K9MWkRja381SNNuLNTU8/_buildManifest.js +0 -1
  82. /package/.next/static/{2K9MWkRja381SNNuLNTU8 → lIYvWbgkX76Tpj8gVu1kU}/_ssgManifest.js +0 -0
@@ -1,6 +1,6 @@
1
1
  $ yarn partytown & yarn generate && next build
2
- $ faststore generate-graphql -c
3
2
  $ partytown copylib ./public/~partytown
3
+ $ faststore generate-graphql -c
4
4
  Partytown lib copied to: /home/runner/work/faststore/faststore/packages/core/public/~partytown
5
5
  success - GraphQL schema, types, and optimizations successfully generated 🎉
6
6
  ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
@@ -38,7 +38,7 @@ Route (app) Size First Load JS
38
38
  ├ chunks/472-369461a1f39981d5.js 28.4 kB
39
39
  ├ chunks/fd9d1056-43c43818840d7811.js 51.1 kB
40
40
  ├ chunks/main-app-e13fa67c2c3ceca5.js 230 B
41
- └ chunks/webpack-d7ccbda472189c19.js 2.43 kB
41
+ └ chunks/webpack-a45dc84c9a0ef3fd.js 2.43 kB
42
42
 
43
43
  Route (pages) Size First Load JS
44
44
  ┌ ● / 1.04 kB 148 kB
@@ -61,8 +61,8 @@ Route (pages) Size First Load JS
61
61
  + First Load JS shared by all 96.9 kB
62
62
  ├ chunks/framework-21e9365486ba23a6.js 45.4 kB
63
63
  ├ chunks/main-9c9c62c368c0a47e.js 34.8 kB
64
- ├ chunks/pages/_app-00cee674a20813ff.js 11.2 kB
65
- ├ chunks/webpack-d7ccbda472189c19.js 2.43 kB
64
+ ├ chunks/pages/_app-1930798899758fda.js 11.2 kB
65
+ ├ chunks/webpack-a45dc84c9a0ef3fd.js 2.43 kB
66
66
  └ css/5d1f64b61ea581f4.css 3.05 kB
67
67
 
68
68
  λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
@@ -1,9 +1,9 @@
1
1
  $ jest
2
- PASS test/server/cms/index.test.ts (28.539 s)
3
- PASS test/server/index.test.ts (30.283 s)
2
+ PASS test/server/cms/index.test.ts (29.963 s)
3
+ PASS test/server/index.test.ts (31.672 s)
4
4
 
5
5
  Test Suites: 2 passed, 2 total
6
- Tests: 12 passed, 12 total
6
+ Tests: 11 passed, 11 total
7
7
  Snapshots: 0 total
8
- Time: 31.156 s
8
+ Time: 32.63 s
9
9
  Ran all test suites.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/core",
3
- "version": "3.0.58",
3
+ "version": "3.0.59",
4
4
  "license": "MIT",
5
5
  "repository": "vtex/faststore",
6
6
  "browserslist": "supports es6-module and not dead",
@@ -125,5 +125,5 @@
125
125
  "node": "18.19.0",
126
126
  "yarn": "1.19.1"
127
127
  },
128
- "gitHead": "e1f415c74cfb74de617dc85669792439a1e6be29"
128
+ "gitHead": "6f2082f0a7f34b560d13060a7ab5d907871e7353"
129
129
  }
@@ -5,14 +5,6 @@ import MissingContentError from 'src/sdk/error/MissingContentError'
5
5
  import MultipleContentError from 'src/sdk/error/MultipleContentError'
6
6
  import config from '../../../faststore.config'
7
7
 
8
- type Cache<T> = {
9
- [key: string]: { data: Array<T> }
10
- }
11
- type ExtraOptions = {
12
- cmsClient?: ClientCMS
13
- cache?: Cache<ContentData>
14
- }
15
-
16
8
  export type Options =
17
9
  | Locator
18
10
  | {
@@ -53,68 +45,49 @@ export const clientCMS = new ClientCMS({
53
45
  tenant: config.api.storeId,
54
46
  })
55
47
 
56
- /*
57
- * This in memory cache exists because for each page (think category or department)
58
- * we are fetching all the pages of the same content type from the headless CMS to
59
- * find the one that matches the slug.
60
- *
61
- * So instead of making multiple request for the Headless CMS API for each page we make
62
- * one for each content-type and reuse the results for the next page.
63
- *
64
- * Since we rebuild on a CMS publication the server will go away and will "invalidate"
65
- * the cache
66
- */
67
- const getCMSPageCache = {}
68
-
69
48
  export const getCMSPage = async (
70
49
  options: Options,
71
- extraOptions?: ExtraOptions
50
+ cmsClient: ClientCMS = clientCMS
72
51
  ) => {
73
- const cmsClient = extraOptions?.cmsClient ?? clientCMS
74
- const cache = extraOptions?.cache ?? getCMSPageCache
75
-
76
52
  if (isLocator(options)) {
77
53
  return await cmsClient
78
54
  .getCMSPage(options)
79
55
  .then((page) => ({ data: [page] }))
80
56
  }
81
57
 
82
- if (!cache[options.contentType]) {
83
- const pages = []
84
- let page = 1
85
- const perPage = 10
86
- const response = await cmsClient.getCMSPagesByContentType(
87
- options.contentType,
88
- { ...options.filters, page: page, perPage }
89
- )
90
-
91
- pages.push(...response.data)
92
-
93
- const totalPagesToFetch = Math.ceil(response.totalItems / perPage) // How many pages have content
94
- const pagesToFetch = Array.from(
95
- { length: totalPagesToFetch - 1 }, // We want all those pages minus the first one that we fetched
96
- (_, i) => i + 2 // + 1 because indices are 0 based, and + 1 because we already fetched the first
97
- )
98
-
99
- if (response.totalItems > pages.length) {
100
- const restOfPages = await Promise.all(
101
- pagesToFetch.map((i) =>
102
- cmsClient.getCMSPagesByContentType(options.contentType, {
103
- ...options.filters,
104
- page: i,
105
- perPage,
106
- })
107
- )
58
+ const pages = []
59
+ let page = 1
60
+ const perPage = 10
61
+ const response = await cmsClient.getCMSPagesByContentType(
62
+ options.contentType,
63
+ { ...options.filters, page: page, perPage }
64
+ )
65
+
66
+ pages.push(...response.data)
67
+
68
+ const totalPagesToFetch = Math.ceil(response.totalItems / perPage) // How many pages have content
69
+ const pagesToFetch = Array.from(
70
+ { length: totalPagesToFetch - 1 }, // We want all those pages minus the first one that we fetched
71
+ (_, i) => i + 2 // + 1 because indices are 0 based, and + 1 because we already fetched the first
72
+ )
73
+
74
+ if (response.totalItems > pages.length) {
75
+ const restOfPages = await Promise.all(
76
+ pagesToFetch.map((i) =>
77
+ cmsClient.getCMSPagesByContentType(options.contentType, {
78
+ ...options.filters,
79
+ page: i,
80
+ perPage,
81
+ })
108
82
  )
83
+ )
109
84
 
110
- restOfPages.forEach((response) => {
111
- pages.push(...response.data)
112
- })
113
- }
114
- cache[options.contentType] = { data: pages }
85
+ restOfPages.forEach((response) => {
86
+ pages.push(...response.data)
87
+ })
115
88
  }
116
89
 
117
- return cache[options.contentType]
90
+ return { data: pages }
118
91
  }
119
92
 
120
93
  export const getPage = async <T extends ContentData>(options: Options) => {
@@ -29,10 +29,7 @@ describe('CMS Integration', () => {
29
29
  })
30
30
  clientCMS.getCMSPagesByContentType = mockFunction
31
31
 
32
- const result = await getCMSPage(
33
- { contentType: 'plp' },
34
- { cmsClient: clientCMS }
35
- )
32
+ const result = await getCMSPage({ contentType: 'plp' }, clientCMS)
36
33
 
37
34
  expect(mockFunction.mock.calls.length).toBe(1)
38
35
  expect(result.data.length).toBe(3)
@@ -59,37 +56,10 @@ describe('CMS Integration', () => {
59
56
 
60
57
  clientCMS.getCMSPagesByContentType = mockFunction
61
58
 
62
- const result = await getCMSPage(
63
- { contentType: 'plp' },
64
- { cmsClient: clientCMS, cache: {} }
65
- )
59
+ const result = await getCMSPage({ contentType: 'plp' }, clientCMS)
66
60
 
67
61
  expect(mockFunction.mock.calls.length).toBe(2)
68
62
  expect(result.data.length).toBe(15)
69
63
  })
70
-
71
- it('it makes no request if the cache is filled', async () => {
72
- const mockFunction: jest.Mock<typeof clientCMS.getCMSPagesByContentType> =
73
- jest.fn()
74
-
75
- mockFunction.mockImplementationOnce(() => {
76
- return Promise.resolve({
77
- data: mockData(10),
78
- hasNextPage: true,
79
- totalItems: 15,
80
- })
81
- })
82
-
83
- clientCMS.getCMSPagesByContentType = mockFunction
84
-
85
- const cache = { plp: { data: [] } }
86
- const result = await getCMSPage(
87
- { contentType: 'plp' },
88
- { cmsClient: clientCMS, cache: cache }
89
- )
90
-
91
- expect(mockFunction.mock.calls.length).toBe(0)
92
- expect(result.data.length).toBe(0)
93
- })
94
64
  })
95
65
  })
@@ -1 +0,0 @@
1
- self.__BUILD_MANIFEST=function(s,c,a,e,t,b,i,u){return{__rewrites:{afterFiles:[],beforeFiles:[],fallback:[]},"/":[s,c,a,e,t,"static/css/fa6d43e3c11a59dc.css","static/chunks/pages/index-86dd2dba6f6f1621.js"],"/404":[s,c,a,b,"static/chunks/pages/404-be2217109dab18cf.js"],"/500":[s,c,a,b,"static/chunks/pages/500-64a07a16830e129c.js"],"/_error":["static/chunks/pages/_error-65ac7445167ddb62.js"],"/account":[s,c,a,"static/chunks/pages/account-70e52900601fc5eb.js"],"/checkout":[s,c,a,"static/chunks/pages/checkout-fe8c38b138ddecef.js"],"/login":[s,c,a,b,"static/chunks/pages/login-258e5b7ecec36481.js"],"/s":[s,c,a,e,t,i,u,"static/chunks/pages/s-53cc10ba9aa8331e.js"],"/[slug]/p":[s,c,a,e,t,"static/css/65f6dd6d16812461.css","static/chunks/pages/[slug]/p-25a61a48b78901e5.js"],"/[...slug]":[s,c,a,e,t,i,u,"static/css/3eed8d7ed5000eb8.css","static/chunks/pages/[...slug]-12c6dd879f1da8e0.js"],sortedPages:["/","/404","/500","/_app","/_error","/account","/checkout","/login","/s","/[slug]/p","/[...slug]"]}}("static/chunks/470-a762f2bf2d218abf.js","static/css/25261a033e496803.css","static/chunks/432-ea0bb3dcebbaab7b.js","static/css/548bab931c45c770.css","static/chunks/590-2e7ce772420d1e1a.js","static/css/ec44b650be144ada.css","static/css/185f3332f3d0db64.css","static/chunks/722-36fe06b9c486056e.js"),self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB();