@faststore/core 3.0.11 → 3.0.13

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 (57) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/build-manifest.json +3 -3
  3. package/.next/cache/.tsbuildinfo +1 -1
  4. package/.next/cache/config.json +3 -3
  5. package/.next/cache/eslint/.cache_1gneedd +1 -1
  6. package/.next/cache/webpack/client-production/0.pack +0 -0
  7. package/.next/cache/webpack/client-production/index.pack +0 -0
  8. package/.next/cache/webpack/server-production/0.pack +0 -0
  9. package/.next/cache/webpack/server-production/index.pack +0 -0
  10. package/.next/next-minimal-server.js.nft.json +1 -1
  11. package/.next/next-server.js.nft.json +1 -1
  12. package/.next/prerender-manifest.js +1 -1
  13. package/.next/prerender-manifest.json +1 -1
  14. package/.next/routes-manifest.json +1 -1
  15. package/.next/server/chunks/498.js +1 -1
  16. package/.next/server/chunks/640.js +1 -1
  17. package/.next/server/chunks/646.js +3 -3
  18. package/.next/server/chunks/997.js +1 -1
  19. package/.next/server/functions-config-manifest.json +1 -1
  20. package/.next/server/middleware-build-manifest.js +1 -1
  21. package/.next/server/pages/404.js +1 -1
  22. package/.next/server/pages/500.js +1 -1
  23. package/.next/server/pages/[...slug].js +1 -1
  24. package/.next/server/pages/[slug]/p.js +1 -1
  25. package/.next/server/pages/en-US/404.html +2 -2
  26. package/.next/server/pages/en-US/500.html +2 -2
  27. package/.next/server/pages/en-US/account.html +2 -2
  28. package/.next/server/pages/en-US/checkout.html +2 -2
  29. package/.next/server/pages/en-US/login.html +2 -2
  30. package/.next/server/pages/en-US/s.html +2 -2
  31. package/.next/server/pages/en-US.html +2 -2
  32. package/.next/server/pages/en-US.json +1 -1
  33. package/.next/server/pages/index.js +1 -1
  34. package/.next/server/pages/login.js +1 -1
  35. package/.next/server/pages/s.js +1 -1
  36. package/.next/server/pages-manifest.json +1 -1
  37. package/.next/static/{4vX-pcZ2UBYJ2at7PjGjO → bcMMWaQUHRCjjoHG-aJw2}/_buildManifest.js +1 -1
  38. package/.next/static/chunks/pages/{_app-6516d0c2c7e0e686.js → _app-ad8623e78bc5b766.js} +1 -1
  39. package/.next/trace +91 -91
  40. package/.turbo/turbo-build.log +4 -2
  41. package/.turbo/turbo-test.log +10 -10
  42. package/faststore.config.default.js +4 -0
  43. package/package.json +4 -4
  44. package/src/components/cms/GlobalSections.tsx +17 -1
  45. package/src/components/templates/LandingPage/LandingPage.tsx +19 -2
  46. package/src/pages/[...slug].tsx +28 -6
  47. package/src/pages/[slug]/p.tsx +23 -7
  48. package/src/pages/index.tsx +24 -8
  49. package/src/pages/s.tsx +25 -9
  50. package/src/sdk/graphql/prefetchQuery.ts +2 -3
  51. package/src/sdk/graphql/request.ts +3 -2
  52. package/src/sdk/graphql/useLazyQuery.ts +2 -3
  53. package/src/sdk/graphql/useQuery.ts +2 -3
  54. package/src/server/cms.ts +26 -0
  55. package/src/server/index.ts +2 -2
  56. package/tsconfig.json +2 -0
  57. /package/.next/static/{4vX-pcZ2UBYJ2at7PjGjO → bcMMWaQUHRCjjoHG-aJw2}/_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
@@ -27,6 +27,8 @@ Browserslist: caniuse-lite is outdated. Please run:
27
27
  Generating static pages (0/7) ...
28
28
 
29
29
  Generating static pages (1/7)
30
30
 
31
31
  Generating static pages (3/7)
32
+ warn - CustomIconsAlert not found. Add a new component for this section or remove it from the CMS
33
+ warn - SimpleAlert not found. Add a new component for this section or remove it from the CMS
32
34
 
33
35
  Generating static pages (5/7)
34
36
 
35
37
  ✓ Generating static pages (7/7)
36
38
  Finalizing page optimization ...
@@ -53,7 +55,7 @@ Route (pages) Size First Load JS
53
55
  + First Load JS shared by all 96.5 kB
54
56
  ├ chunks/framework-8e279965036b6169.js 45.4 kB
55
57
  ├ chunks/main-6f63f6746cc029db.js 33.1 kB
56
- ├ chunks/pages/_app-6516d0c2c7e0e686.js 12.5 kB
58
+ ├ chunks/pages/_app-ad8623e78bc5b766.js 12.5 kB
57
59
  ├ chunks/webpack-b4a2fdf4ef127bb7.js 2.45 kB
58
60
  └ css/5d1f64b61ea581f4.css 3.05 kB
59
61
 
@@ -1,23 +1,23 @@
1
1
  $ jest
2
- PASS test/server/index.test.ts (21.487 s)
2
+ PASS test/server/index.test.ts (21.419 s)
3
3
  FastStore GraphQL Layer
4
4
  @faststore/api
5
- ✓ should return a valid GraphQL schema (9 ms)
6
- ✓ should return a valid GraphQL schema contain all expected types (21 ms)
7
- ✓ should return a valid GraphQL schema contain all expected queries (5 ms)
5
+ ✓ should return a valid GraphQL schema (8 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 (1 ms)
8
8
  ✓ should return a valid GraphQL schema contain all expected mutations (1 ms)
9
9
  VTEX API Extension
10
- ✓ getTypeDefsFromFolder function should return an Array (8 ms)
10
+ ✓ getTypeDefsFromFolder function should return an Array (5 ms)
11
11
  Third Party API Extension
12
- ✓ getTypeDefsFromFolder function should return an Array (23 ms)
12
+ ✓ getTypeDefsFromFolder function should return an Array (4 ms)
13
13
  Final Schema after merging
14
- ✓ should return a valid merged GraphQL schema (57 ms)
14
+ ✓ should return a valid merged GraphQL schema (26 ms)
15
15
  Envelop
16
- ✓ should exist with its plugins (67 ms)
17
- ✓ should handle options and execute (289 ms)
16
+ ✓ should exist with its plugins (39 ms)
17
+ ✓ should handle options and execute (329 ms)
18
18
 
19
19
  Test Suites: 1 passed, 1 total
20
20
  Tests: 9 passed, 9 total
21
21
  Snapshots: 0 total
22
- Time: 21.534 s
22
+ Time: 21.518 s
23
23
  Ran all test suites.
@@ -88,6 +88,10 @@ module.exports = {
88
88
  gtmContainerId: 'GTM-PGHZ95N',
89
89
  },
90
90
 
91
+ cms: {
92
+ data: process.env.CMS_DATA,
93
+ },
94
+
91
95
  experimental: {
92
96
  cypressVersion: 12,
93
97
  enableCypressExtension: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/core",
3
- "version": "3.0.11",
3
+ "version": "3.0.13",
4
4
  "license": "MIT",
5
5
  "repository": "vtex/faststore",
6
6
  "browserslist": "supports es6-module and not dead",
@@ -41,7 +41,7 @@
41
41
  "@envelop/validation-cache": "^2.2.0",
42
42
  "@faststore/api": "^3.0.7",
43
43
  "@faststore/components": "^3.0.7",
44
- "@faststore/graphql-utils": "^3.0.7",
44
+ "@faststore/graphql-utils": "^3.0.13",
45
45
  "@faststore/sdk": "^3.0.7",
46
46
  "@faststore/ui": "^3.0.7",
47
47
  "@graphql-codegen/cli": "^3.3.1",
@@ -83,7 +83,7 @@
83
83
  "devDependencies": {
84
84
  "@cypress/code-coverage": "^3.12.1",
85
85
  "@envelop/testing": "^6.0.0",
86
- "@faststore/cli": "^3.0.7",
86
+ "@faststore/cli": "^3.0.13",
87
87
  "@faststore/eslint-config": "^3.0.7",
88
88
  "@faststore/lighthouse": "^1.12.32",
89
89
  "@lhci/cli": "^0.9.0",
@@ -128,5 +128,5 @@
128
128
  "node": "18.19.0",
129
129
  "yarn": "1.19.1"
130
130
  },
131
- "gitHead": "3ab949e5801ba04f7e884b63f0e5e2cde9df0ceb"
131
+ "gitHead": "9ccaaa8c2e9e6b2c9f3c82ac3d52405e51ddd6a0"
132
132
  }
@@ -1,8 +1,9 @@
1
1
  import { Locator, Section } from '@vtex/client-cms'
2
2
  import type { ComponentType } from 'react'
3
3
  import { PropsWithChildren, lazy } from 'react'
4
+ import storeConfig from 'faststore.config'
4
5
  import CUSTOM_COMPONENTS from 'src/customizations/src/components'
5
- import { PageContentType, getPage } from 'src/server/cms'
6
+ import { PageContentType, getPage, getPageByVersionId } from 'src/server/cms'
6
7
 
7
8
  import Toast from 'src/components/common/Toast'
8
9
  import RenderSections from './RenderSections'
@@ -50,6 +51,21 @@ export default GlobalSections
50
51
  export const getGlobalSectionsData = async (
51
52
  previewData: Locator
52
53
  ): Promise<GlobalSectionsData> => {
54
+ if (storeConfig.cms.data) {
55
+ const cmsData = JSON.parse(storeConfig.cms.data)
56
+ const page = cmsData[GLOBAL_SECTIONS_CONTENT_TYPE][0]
57
+
58
+ if (page) {
59
+ const pageData = await getPageByVersionId<PageContentType>({
60
+ contentType: GLOBAL_SECTIONS_CONTENT_TYPE,
61
+ documentId: page.documentId,
62
+ versionId: page.versionId,
63
+ })
64
+
65
+ return pageData
66
+ }
67
+ }
68
+
53
69
  const { sections } = await getPage<PageContentType>({
54
70
  ...(previewData?.contentType === GLOBAL_SECTIONS_CONTENT_TYPE &&
55
71
  previewData),
@@ -10,11 +10,11 @@ import { OverriddenDefaultNewsletter as Newsletter } from 'src/components/sectio
10
10
  import { OverriddenDefaultProductShelf as ProductShelf } from 'src/components/sections/ProductShelf/OverriddenDefaultProductShelf'
11
11
  import Incentives from 'src/components/sections/Incentives'
12
12
  import ProductTiles from 'src/components/sections/ProductTiles'
13
- import { getPage } from 'src/server/cms'
13
+ import { getPage, getPageByVersionId } from 'src/server/cms'
14
14
  import type { PageContentType } from 'src/server/cms'
15
15
  import CUSTOM_COMPONENTS from 'src/customizations/src/components'
16
16
 
17
- import storeConfig from '../../../../faststore.config'
17
+ import storeConfig from 'faststore.config'
18
18
 
19
19
  /* A list of components that can be used in the CMS. */
20
20
  const COMPONENTS: Record<string, ComponentType<any>> = {
@@ -85,6 +85,23 @@ export const getLandingPageBySlug = async (
85
85
  previewData: Locator
86
86
  ) => {
87
87
  try {
88
+ if (storeConfig.cms.data) {
89
+ const cmsData = JSON.parse(storeConfig.cms.data)
90
+ const pageBySlug = cmsData['landingPage'].find((page) => {
91
+ slug === page.settings?.seo?.slug
92
+ })
93
+
94
+ if (pageBySlug) {
95
+ const landingPageData = await getPageByVersionId<PageContentType>({
96
+ contentType: 'landingPage',
97
+ documentId: pageBySlug.documentId,
98
+ versionId: pageBySlug.versionId,
99
+ })
100
+
101
+ return landingPageData
102
+ }
103
+ }
104
+
88
105
  const landingPageData = await getPage<PageContentType>({
89
106
  ...(previewData?.contentType === 'landingPage'
90
107
  ? previewData
@@ -1,5 +1,6 @@
1
1
  import { isNotFoundError } from '@faststore/api'
2
2
  import type { GetStaticPaths, GetStaticProps } from 'next'
3
+ import storeConfig from 'faststore.config'
3
4
 
4
5
  import { gql } from '@generated'
5
6
  import type {
@@ -14,7 +15,12 @@ import GlobalSections, {
14
15
  getGlobalSectionsData,
15
16
  GlobalSectionsData,
16
17
  } from 'src/components/cms/GlobalSections'
17
- import { getPage, PageContentType, PLPContentType } from 'src/server/cms'
18
+ import {
19
+ getPage,
20
+ getPageByVersionId,
21
+ PageContentType,
22
+ PLPContentType,
23
+ } from 'src/server/cms'
18
24
  import ProductListingPage, {
19
25
  ProductListingPageProps,
20
26
  } from 'src/components/templates/ProductListingPage'
@@ -100,7 +106,7 @@ export const getStaticProps: GetStaticProps<
100
106
  }
101
107
  }
102
108
 
103
- const [{ data, errors = [] }, page] = await Promise.all([
109
+ const [{ data, errors = [] }] = await Promise.all([
104
110
  execute<
105
111
  ServerCollectionPageQueryQueryVariables,
106
112
  ServerCollectionPageQueryQuery
@@ -108,11 +114,27 @@ export const getStaticProps: GetStaticProps<
108
114
  variables: { slug },
109
115
  operation: query,
110
116
  }),
111
- getPage<PLPContentType>({
117
+ ])
118
+
119
+ let pageData
120
+
121
+ if (storeConfig.cms.data) {
122
+ const cmsData = JSON.parse(storeConfig.cms.data)
123
+ const page = cmsData['plp'][0]
124
+
125
+ if (page) {
126
+ pageData = await getPageByVersionId<PLPContentType>({
127
+ contentType: 'plp',
128
+ documentId: page.documentId,
129
+ versionId: page.versionId,
130
+ })
131
+ }
132
+ } else {
133
+ pageData = await getPage<PLPContentType>({
112
134
  ...(previewData?.contentType === 'plp' ? previewData : null),
113
135
  contentType: 'plp',
114
- }),
115
- ])
136
+ })
137
+ }
116
138
 
117
139
  const notFound = errors.find(isNotFoundError)
118
140
 
@@ -130,7 +152,7 @@ export const getStaticProps: GetStaticProps<
130
152
  return {
131
153
  props: {
132
154
  data,
133
- page,
155
+ page: pageData,
134
156
  globalSections: await globalSectionsPromise,
135
157
  type: 'plp',
136
158
  key: slug,
@@ -21,13 +21,13 @@ import { useSession } from 'src/sdk/session'
21
21
  import { mark } from 'src/sdk/tests/mark'
22
22
  import { execute } from 'src/server'
23
23
  import type { PDPContentType } from 'src/server/cms'
24
- import { getPage } from 'src/server/cms'
24
+ import { getPage, getPageByVersionId } from 'src/server/cms'
25
25
 
26
26
  import GlobalSections, {
27
27
  GlobalSectionsData,
28
28
  getGlobalSectionsData,
29
29
  } from 'src/components/cms/GlobalSections'
30
- import storeConfig from '../../../faststore.config'
30
+ import storeConfig from 'faststore.config'
31
31
  import { useProductQuery } from 'src/sdk/product/useProductQuery'
32
32
  import PageProvider, { PDPContext } from 'src/sdk/overrides/PageProvider'
33
33
 
@@ -200,18 +200,34 @@ export const getStaticProps: GetStaticProps<
200
200
  Locator
201
201
  > = async ({ params, previewData }) => {
202
202
  const slug = params?.slug ?? ''
203
- const [searchResult, cmsPage, globalSections] = await Promise.all([
203
+ const [searchResult, globalSections] = await Promise.all([
204
204
  execute<ServerProductQueryQueryVariables, ServerProductQueryQuery>({
205
205
  variables: { locator: [{ key: 'slug', value: slug }] },
206
206
  operation: query,
207
207
  }),
208
- getPage<PDPContentType>({
209
- ...(previewData?.contentType === 'pdp' ? previewData : null),
210
- contentType: 'pdp',
211
- }),
212
208
  getGlobalSectionsData(previewData),
213
209
  ])
214
210
 
211
+ let cmsPage
212
+
213
+ if (storeConfig.cms.data) {
214
+ const cmsData = JSON.parse(storeConfig.cms.data)
215
+ const page = cmsData['pdp'][0]
216
+
217
+ if (page) {
218
+ cmsPage = getPageByVersionId<PDPContentType>({
219
+ contentType: 'pdp',
220
+ documentId: page.documentId,
221
+ versionId: page.versionId,
222
+ })
223
+ }
224
+ } else {
225
+ cmsPage = getPage<PDPContentType>({
226
+ ...(previewData?.contentType === 'pdp' ? previewData : null),
227
+ contentType: 'pdp',
228
+ })
229
+ }
230
+
215
231
  const { data, errors = [] } = searchResult
216
232
 
217
233
  const notFound = errors.find(isNotFoundError)
@@ -13,7 +13,7 @@ import ProductTiles from 'src/components/sections/ProductTiles'
13
13
  import CUSTOM_COMPONENTS from 'src/customizations/src/components'
14
14
  import { mark } from 'src/sdk/tests/mark'
15
15
  import type { PageContentType } from 'src/server/cms'
16
- import { getPage } from 'src/server/cms'
16
+ import { getPage, getPageByVersionId } from 'src/server/cms'
17
17
 
18
18
  import GlobalSections, {
19
19
  GlobalSectionsData,
@@ -85,13 +85,29 @@ export const getStaticProps: GetStaticProps<
85
85
  Record<string, string>,
86
86
  Locator
87
87
  > = async ({ previewData }) => {
88
- const [page, globalSections] = await Promise.all([
89
- getPage<PageContentType>({
90
- ...(previewData?.contentType === 'home' && previewData),
91
- contentType: 'home',
92
- }),
93
- getGlobalSectionsData(previewData),
94
- ])
88
+ const globalSections = await getGlobalSectionsData(previewData)
89
+
90
+ if (storeConfig.cms.data) {
91
+ const cmsData = JSON.parse(storeConfig.cms.data)
92
+ const page = cmsData['home'][0]
93
+
94
+ if (page) {
95
+ const pageData = await getPageByVersionId<PageContentType>({
96
+ contentType: 'home',
97
+ documentId: page.documentId,
98
+ versionId: page.versionId,
99
+ })
100
+
101
+ return {
102
+ props: { page: pageData, globalSections },
103
+ }
104
+ }
105
+ }
106
+
107
+ const page = await getPage<PageContentType>({
108
+ ...(previewData?.contentType === 'home' && previewData),
109
+ contentType: 'home',
110
+ })
95
111
 
96
112
  return {
97
113
  props: { page, globalSections },
package/src/pages/s.tsx CHANGED
@@ -19,8 +19,8 @@ import GlobalSections, {
19
19
  getGlobalSectionsData,
20
20
  GlobalSectionsData,
21
21
  } from 'src/components/cms/GlobalSections'
22
- import { getPage, SearchContentType } from 'src/server/cms'
23
- import storeConfig from '../../faststore.config'
22
+ import { getPage, getPageByVersionId, SearchContentType } from 'src/server/cms'
23
+ import storeConfig from 'faststore.config'
24
24
  import SearchPage from 'src/components/templates/SearchPage/SearchPage'
25
25
 
26
26
  type Props = {
@@ -118,13 +118,29 @@ export const getStaticProps: GetStaticProps<
118
118
  Record<string, string>,
119
119
  Locator
120
120
  > = async ({ previewData }) => {
121
- const [page, globalSections] = await Promise.all([
122
- getPage<SearchContentType>({
123
- ...(previewData?.contentType === 'search' ? previewData : null),
124
- contentType: 'search',
125
- }),
126
- getGlobalSectionsData(previewData),
127
- ])
121
+ const globalSections = await getGlobalSectionsData(previewData)
122
+
123
+ if (storeConfig.cms.data) {
124
+ const cmsData = JSON.parse(storeConfig.cms.data)
125
+ const page = cmsData['search'][0]
126
+
127
+ if (page) {
128
+ const pageData = await getPageByVersionId<SearchContentType>({
129
+ contentType: 'search',
130
+ documentId: page.documentId,
131
+ versionId: page.versionId,
132
+ })
133
+
134
+ return {
135
+ props: { page: pageData, globalSections },
136
+ }
137
+ }
138
+ }
139
+
140
+ const page = await getPage<SearchContentType>({
141
+ ...(previewData?.contentType === 'search' ? previewData : null),
142
+ contentType: 'search',
143
+ })
128
144
 
129
145
  return {
130
146
  props: {
@@ -3,11 +3,10 @@ import type { Cache } from 'swr'
3
3
 
4
4
  import { request } from './request'
5
5
  import { getKey } from './useQuery'
6
- import type { RequestOptions } from './request'
7
- import { TypedDocumentString } from '@generated/graphql'
6
+ import type { Operation, RequestOptions } from './request'
8
7
 
9
8
  export const prefetchQuery = <Data, Variables = Record<string, unknown>>(
10
- operation: TypedDocumentString<any, any>,
9
+ operation: Operation,
11
10
  variables: Variables,
12
11
  { cache, ...options }: Partial<RequestOptions> & { cache: Cache }
13
12
  ) => {
@@ -1,6 +1,7 @@
1
1
  import { TypedDocumentString } from '@generated/graphql'
2
2
 
3
3
  export type RequestOptions = Omit<BaseRequestOptions, 'operation' | 'variables'>
4
+ export type Operation = Pick<TypedDocumentString<any, any>, '__meta__'>
4
5
 
5
6
  export interface GraphQLResponse<D = any> {
6
7
  data: D
@@ -8,7 +9,7 @@ export interface GraphQLResponse<D = any> {
8
9
  }
9
10
 
10
11
  export interface BaseRequestOptions<V = any> {
11
- operation: TypedDocumentString<any, any>
12
+ operation: Operation
12
13
  variables: V
13
14
  fetchOptions?: RequestInit
14
15
  }
@@ -20,7 +21,7 @@ const DEFAULT_HEADERS_BY_VERB: Record<string, Record<string, string>> = {
20
21
  }
21
22
 
22
23
  export const request = async <Query = unknown, Variables = unknown>(
23
- operation: TypedDocumentString<any, any>,
24
+ operation: Operation,
24
25
  variables: Variables,
25
26
  options?: RequestOptions
26
27
  ) => {
@@ -1,12 +1,11 @@
1
1
  import useSWR from 'swr'
2
2
 
3
- import { request } from './request'
3
+ import { type Operation, request } from './request'
4
4
  import { DEFAULT_OPTIONS, getKey } from './useQuery'
5
5
  import type { QueryOptions } from './useQuery'
6
- import { TypedDocumentString } from '@generated/graphql'
7
6
 
8
7
  export const useLazyQuery = <Data, Variables = Record<string, unknown>>(
9
- operation: TypedDocumentString<any, any>,
8
+ operation: Operation,
10
9
  variables: Variables,
11
10
  options?: QueryOptions
12
11
  ) => {
@@ -2,8 +2,7 @@ import useSWR from 'swr'
2
2
  import type { SWRConfiguration } from 'swr'
3
3
 
4
4
  import { request } from './request'
5
- import type { RequestOptions } from './request'
6
- import { TypedDocumentString } from '@generated/graphql'
5
+ import type { Operation, RequestOptions } from './request'
7
6
 
8
7
  export type QueryOptions = SWRConfiguration &
9
8
  RequestOptions & { doNotRun?: boolean }
@@ -23,7 +22,7 @@ export const DEFAULT_OPTIONS = {
23
22
  }
24
23
 
25
24
  export const useQuery = <Data, Variables = Record<string, unknown>>(
26
- operation: TypedDocumentString<any, any>,
25
+ operation: Operation,
27
26
  variables: Variables,
28
27
  options?: QueryOptions
29
28
  ) =>
package/src/server/cms.ts CHANGED
@@ -39,6 +39,32 @@ export const getPage = async <T extends ContentData>(options: Options) => {
39
39
  return pages[0] as T
40
40
  }
41
41
 
42
+ export type VersionOptions = {
43
+ contentType: string
44
+ documentId: string
45
+ versionId: string
46
+ }
47
+
48
+ export const getPageByVersionId = async <T extends ContentData>(
49
+ options: VersionOptions
50
+ ) => {
51
+ const result = await clientCMS
52
+ .getCMSPage(options)
53
+ .then((page) => ({ data: [page] }))
54
+
55
+ const pages = result.data
56
+
57
+ if (!pages[0]) {
58
+ throw new MissingContentError(options)
59
+ }
60
+
61
+ if (pages.length !== 1) {
62
+ throw new MultipleContentError(options)
63
+ }
64
+
65
+ return pages[0] as T
66
+ }
67
+
42
68
  type ProductGallerySettings = {
43
69
  settings: {
44
70
  productGallery: {
@@ -27,10 +27,10 @@ import vtexExtensionsResolvers from '../customizations/src/graphql/vtex/resolver
27
27
  import thirdPartyResolvers from '../customizations/src/graphql/thirdParty/resolvers'
28
28
 
29
29
  import { apiOptions } from './options'
30
- import { TypedDocumentString } from '@generated/graphql'
30
+ import { Operation } from '../sdk/graphql/request'
31
31
 
32
32
  interface ExecuteOptions<V = Record<string, unknown>> {
33
- operation: Pick<TypedDocumentString<any, any>, '__meta__'>
33
+ operation: Operation
34
34
  variables: V
35
35
  query?: string | null
36
36
  }
package/tsconfig.json CHANGED
@@ -14,6 +14,8 @@
14
14
  "paths": {
15
15
  "src/*": ["src/*"],
16
16
  "@generated/*": ["@generated/*"],
17
+ "@faststore/core": ["index.ts"],
18
+ "@faststore/core/api": ["api/index.ts"],
17
19
  "@faststore/core/experimental": ["src/experimental/index.ts"]
18
20
  },
19
21
  "forceConsistentCasingInFileNames": true,