@faststore/core 3.0.56 → 3.0.57
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 +11 -11
- package/.next/cache/.tsbuildinfo +1 -1
- package/.next/cache/config.json +3 -3
- package/.next/cache/eslint/.cache_1gneedd +1 -1
- package/.next/cache/fetch-cache/50912854cb7c781522a6ff8792d714e549515fcbbbfd660761961b06afe01c07 +1 -1
- package/.next/cache/webpack/client-production/0.pack +0 -0
- package/.next/cache/webpack/client-production/index.pack +0 -0
- package/.next/cache/webpack/server-production/0.pack +0 -0
- package/.next/cache/webpack/server-production/index.pack +0 -0
- package/.next/next-minimal-server.js.nft.json +1 -1
- package/.next/next-server.js.nft.json +1 -1
- package/.next/prerender-manifest.js +1 -1
- package/.next/prerender-manifest.json +1 -1
- package/.next/routes-manifest.json +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +1 -1
- package/.next/server/app/fs-next-update.html +1 -1
- package/.next/server/app/fs-next-update.rsc +1 -1
- package/.next/server/chunks/1481.js +2 -2
- package/.next/server/chunks/1889.js +2 -2
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/pages/404.html +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/account.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/s.html +2 -2
- package/.next/server/pages/en-US.html +2 -2
- package/.next/server/pages-manifest.json +1 -1
- package/.next/static/{YVsdypyAbd7fqsNOnAbXQ → Gw5UNkUm8jxR5nsCDzVnx}/_buildManifest.js +1 -1
- package/.next/static/chunks/{432-2a9341d243613db4.js → 432-687f6ce5bc27dcf1.js} +1 -1
- package/.next/trace +62 -62
- package/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-test.log +5 -19
- package/package.json +3 -3
- package/src/server/cms/index.ts +70 -4
- package/test/server/cms/index.test.ts +95 -0
- /package/.next/static/{YVsdypyAbd7fqsNOnAbXQ → Gw5UNkUm8jxR5nsCDzVnx}/_ssgManifest.js +0 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
$ yarn partytown & yarn generate && next build
|
|
2
|
+
$ faststore generate-graphql -c
|
|
2
3
|
$ partytown copylib ./public/~partytown
|
|
3
4
|
Partytown lib copied to: /home/runner/work/faststore/faststore/packages/core/public/~partytown
|
|
4
|
-
$ faststore generate-graphql -c
|
|
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
|
|
7
7
|
Attention: Next.js now collects completely anonymous telemetry regarding usage.
|
|
@@ -24,8 +24,8 @@ Browserslist: caniuse-lite is outdated. Please run:
|
|
|
24
24
|
Collecting page data ...
|
|
25
25
|
Generating static pages (0/9) ...
|
|
26
26
|
|
|
27
27
|
Generating static pages (2/9)
|
|
28
|
-
|
|
29
28
|
Generating static pages (4/9)
|
|
30
29
|
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.
|
|
30
|
+
|
|
31
31
|
Generating static pages (4/9)
|
|
32
32
|
|
|
33
33
|
Generating static pages (6/9)
|
|
34
34
|
|
|
35
35
|
✓ Generating static pages (9/9)
|
|
36
36
|
Finalizing page optimization ...
|
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
$ jest
|
|
2
|
-
PASS test/server/index.test.ts (
|
|
3
|
-
|
|
4
|
-
@faststore/api
|
|
5
|
-
✓ should return a valid GraphQL schema (6 ms)
|
|
6
|
-
✓ should return a valid GraphQL schema contain all expected types (7 ms)
|
|
7
|
-
✓ should return a valid GraphQL schema contain all expected queries (2 ms)
|
|
8
|
-
✓ should return a valid GraphQL schema contain all expected mutations
|
|
9
|
-
VTEX API Extension
|
|
10
|
-
✓ getTypeDefsFromFolder function should return an Array (8 ms)
|
|
11
|
-
Third Party API Extension
|
|
12
|
-
✓ getTypeDefsFromFolder function should return an Array (7 ms)
|
|
13
|
-
Final Schema after merging
|
|
14
|
-
✓ should return a valid merged GraphQL schema (31 ms)
|
|
15
|
-
Envelop
|
|
16
|
-
✓ should exist with its plugins (29 ms)
|
|
17
|
-
✓ should handle options and execute (138 ms)
|
|
2
|
+
PASS test/server/cms/index.test.ts (28.834 s)
|
|
3
|
+
PASS test/server/index.test.ts (31.603 s)
|
|
18
4
|
|
|
19
|
-
Test Suites:
|
|
20
|
-
Tests:
|
|
5
|
+
Test Suites: 2 passed, 2 total
|
|
6
|
+
Tests: 12 passed, 12 total
|
|
21
7
|
Snapshots: 0 total
|
|
22
|
-
Time:
|
|
8
|
+
Time: 32.462 s
|
|
23
9
|
Ran all test suites.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/core",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.57",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "vtex/faststore",
|
|
6
6
|
"browserslist": "supports es6-module and not dead",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"css-loader": "^6.7.1",
|
|
63
63
|
"deepmerge": "^4.3.1",
|
|
64
64
|
"draftjs-to-html": "^0.9.1",
|
|
65
|
-
"graphql": "^15.
|
|
65
|
+
"graphql": "^15.6.0",
|
|
66
66
|
"include-media": "^1.4.10",
|
|
67
67
|
"next": "^13.5.6",
|
|
68
68
|
"next-seo": "^6.4.0",
|
|
@@ -125,5 +125,5 @@
|
|
|
125
125
|
"node": "18.19.0",
|
|
126
126
|
"yarn": "1.19.1"
|
|
127
127
|
},
|
|
128
|
-
"gitHead": "
|
|
128
|
+
"gitHead": "b1790641313ddd75103e6697ecfe4adb3f66fef7"
|
|
129
129
|
}
|
package/src/server/cms/index.ts
CHANGED
|
@@ -5,6 +5,14 @@ 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
|
+
|
|
8
16
|
export type Options =
|
|
9
17
|
| Locator
|
|
10
18
|
| {
|
|
@@ -45,10 +53,68 @@ export const clientCMS = new ClientCMS({
|
|
|
45
53
|
tenant: config.api.storeId,
|
|
46
54
|
})
|
|
47
55
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
+
export const getCMSPage = async (
|
|
70
|
+
options: Options,
|
|
71
|
+
extraOptions?: ExtraOptions
|
|
72
|
+
) => {
|
|
73
|
+
const cmsClient = extraOptions?.cmsClient ?? clientCMS
|
|
74
|
+
const cache = extraOptions?.cache ?? getCMSPageCache
|
|
75
|
+
|
|
76
|
+
if (isLocator(options)) {
|
|
77
|
+
return await cmsClient
|
|
78
|
+
.getCMSPage(options)
|
|
79
|
+
.then((page) => ({ data: [page] }))
|
|
80
|
+
}
|
|
81
|
+
|
|
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
|
+
)
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
restOfPages.forEach((response) => {
|
|
111
|
+
pages.push(...response.data)
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
cache[options.contentType] = { data: pages }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return cache[options.contentType]
|
|
52
118
|
}
|
|
53
119
|
|
|
54
120
|
export const getPage = async <T extends ContentData>(options: Options) => {
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { clientCMS, getCMSPage } from '../../../src/server/cms'
|
|
2
|
+
import { jest } from '@jest/globals'
|
|
3
|
+
import { ContentData } from '@vtex/client-cms'
|
|
4
|
+
|
|
5
|
+
describe('CMS Integration', () => {
|
|
6
|
+
const mockData = (count = 1) => {
|
|
7
|
+
const data: ContentData[] = []
|
|
8
|
+
for (let i = 0; i < count; i = i + 1) {
|
|
9
|
+
data.push({
|
|
10
|
+
id: `data-id-${i}`,
|
|
11
|
+
name: `data-name-${i}`,
|
|
12
|
+
status: `data-status-${i}`,
|
|
13
|
+
type: `data-type-${i}`,
|
|
14
|
+
sections: [],
|
|
15
|
+
releaseId: `release-${i}`,
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
return data
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe('getCMSPage', () => {
|
|
22
|
+
it('returns the first page if there is only one page', async () => {
|
|
23
|
+
const mockFunction = jest.fn(() => {
|
|
24
|
+
return Promise.resolve({
|
|
25
|
+
data: mockData(3),
|
|
26
|
+
hasNextPage: false,
|
|
27
|
+
totalItems: 3,
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
clientCMS.getCMSPagesByContentType = mockFunction
|
|
31
|
+
|
|
32
|
+
const result = await getCMSPage(
|
|
33
|
+
{ contentType: 'plp' },
|
|
34
|
+
{ cmsClient: clientCMS }
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
expect(mockFunction.mock.calls.length).toBe(1)
|
|
38
|
+
expect(result.data.length).toBe(3)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('loads multiple pages', async () => {
|
|
42
|
+
const mockFunction: jest.Mock<typeof clientCMS.getCMSPagesByContentType> =
|
|
43
|
+
jest.fn()
|
|
44
|
+
|
|
45
|
+
mockFunction.mockImplementationOnce(() => {
|
|
46
|
+
return Promise.resolve({
|
|
47
|
+
data: mockData(10),
|
|
48
|
+
hasNextPage: true,
|
|
49
|
+
totalItems: 15,
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
mockFunction.mockImplementationOnce(() => {
|
|
53
|
+
return Promise.resolve({
|
|
54
|
+
data: mockData(5),
|
|
55
|
+
hasNextPage: false,
|
|
56
|
+
totalItems: 15,
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
clientCMS.getCMSPagesByContentType = mockFunction
|
|
61
|
+
|
|
62
|
+
const result = await getCMSPage(
|
|
63
|
+
{ contentType: 'plp' },
|
|
64
|
+
{ cmsClient: clientCMS, cache: {} }
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
expect(mockFunction.mock.calls.length).toBe(2)
|
|
68
|
+
expect(result.data.length).toBe(15)
|
|
69
|
+
})
|
|
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
|
+
})
|
|
95
|
+
})
|
|
File without changes
|