@faststore/core 2.1.83 → 2.2.0-alpha.0

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 (206) hide show
  1. package/.turbo/turbo-build.log +9 -7
  2. package/.turbo/turbo-test.log +25 -0
  3. package/@generated/graphql/index.ts +183 -79
  4. package/@generated/graphql/persisted.json +5 -5
  5. package/@generated/graphql/schema.graphql +1053 -0
  6. package/api/index.ts +15 -0
  7. package/codegen.yml +2 -1
  8. package/generate.sh +71 -0
  9. package/index.ts +15 -0
  10. package/jest.config.js +6 -0
  11. package/package.json +33 -18
  12. package/src/components/ThirdPartyScripts/ThirdPartyScripts.tsx +1 -2
  13. package/src/components/cms/RenderSections.tsx +4 -5
  14. package/src/components/product/ProductGrid/ProductGrid.tsx +4 -3
  15. package/src/components/sections/Breadcrumb/Breadcrumb.tsx +17 -22
  16. package/src/components/sections/CrossSellingShelf/CrossSellingShelf.tsx +8 -6
  17. package/src/components/sections/ProductDetails/ProductDetails.tsx +23 -33
  18. package/src/components/sections/ProductGallery/ProductGallery.tsx +15 -26
  19. package/src/components/sections/ProductShelf/ProductShelf.tsx +1 -1
  20. package/src/components/sections/ProductTiles/ProductTiles.tsx +4 -3
  21. package/src/components/templates/ProductListingPage/ProductListing.tsx +95 -0
  22. package/src/components/templates/ProductListingPage/ProductListingPage.tsx +34 -68
  23. package/src/components/templates/SearchPage/SearchPage.tsx +81 -0
  24. package/src/components/templates/SearchPage/index.ts +2 -0
  25. package/src/components/ui/ProductGallery/ProductGallery.tsx +24 -16
  26. package/src/components/ui/ProductGallery/ProductGalleryPage.tsx +8 -7
  27. package/src/components/ui/ProductGallery/useDelayedFacets.ts +3 -3
  28. package/src/components/ui/ProductShelf/ProductShelf.tsx +3 -2
  29. package/src/customizations/GlobalOverrides.tsx +0 -2
  30. package/src/customizations/fragments/ClientProduct.ts +9 -0
  31. package/src/customizations/fragments/ClientProductGallery.ts +19 -0
  32. package/src/customizations/fragments/ClientProducts.ts +19 -0
  33. package/src/customizations/fragments/ServerCollectionPage.ts +9 -0
  34. package/src/customizations/fragments/ServerProductPage.ts +9 -0
  35. package/src/customizations/graphql/thirdParty/resolvers/index.ts +3 -0
  36. package/src/customizations/graphql/vtex/resolvers/index.ts +3 -0
  37. package/src/pages/[...slug].tsx +5 -3
  38. package/src/pages/[slug]/p.tsx +38 -18
  39. package/src/pages/s.tsx +22 -34
  40. package/src/sdk/graphql/useQuery.ts +17 -13
  41. package/src/sdk/overrides/PageProvider.tsx +78 -0
  42. package/src/sdk/product/useLocalizedVariables.ts +33 -0
  43. package/src/sdk/product/usePageProductsQuery.ts +139 -0
  44. package/src/{components/sections/ProductGallery/useGalleryQuery.ts → sdk/product/useProductGalleryQuery.ts} +12 -13
  45. package/src/sdk/product/{useProduct.ts → useProductQuery.ts} +10 -7
  46. package/src/sdk/product/useProductsPrefetch.ts +72 -0
  47. package/src/sdk/product/useProductsQuery.ts +17 -63
  48. package/src/server/generator/generateGraphQLSchemaFile.ts +3 -0
  49. package/src/server/generator/schema.ts +82 -0
  50. package/src/server/index.ts +34 -21
  51. package/src/server/options.ts +16 -0
  52. package/test/server/index.test.ts +146 -0
  53. package/.next/BUILD_ID +0 -1
  54. package/.next/build-manifest.json +0 -129
  55. package/.next/cache/.tsbuildinfo +0 -1
  56. package/.next/cache/config.json +0 -7
  57. package/.next/cache/eslint/.cache_1gneedd +0 -1
  58. package/.next/cache/next-server.js.nft.json +0 -1
  59. package/.next/cache/webpack/client-production/0.pack +0 -0
  60. package/.next/cache/webpack/client-production/index.pack +0 -0
  61. package/.next/cache/webpack/server-production/0.pack +0 -0
  62. package/.next/cache/webpack/server-production/index.pack +0 -0
  63. package/.next/export-marker.json +0 -1
  64. package/.next/images-manifest.json +0 -1
  65. package/.next/next-server.js.nft.json +0 -1
  66. package/.next/package.json +0 -1
  67. package/.next/prerender-manifest.json +0 -1
  68. package/.next/react-loadable-manifest.json +0 -44
  69. package/.next/required-server-files.json +0 -1
  70. package/.next/routes-manifest.json +0 -1
  71. package/.next/server/chunks/143.js +0 -106
  72. package/.next/server/chunks/177.js +0 -120
  73. package/.next/server/chunks/183.js +0 -94
  74. package/.next/server/chunks/184.js +0 -61
  75. package/.next/server/chunks/186.js +0 -113
  76. package/.next/server/chunks/289.js +0 -239
  77. package/.next/server/chunks/312.js +0 -697
  78. package/.next/server/chunks/350.js +0 -143
  79. package/.next/server/chunks/483.js +0 -650
  80. package/.next/server/chunks/487.js +0 -9142
  81. package/.next/server/chunks/53.js +0 -61
  82. package/.next/server/chunks/530.js +0 -626
  83. package/.next/server/chunks/576.js +0 -94
  84. package/.next/server/chunks/650.js +0 -9142
  85. package/.next/server/chunks/676.js +0 -32
  86. package/.next/server/chunks/693.js +0 -58
  87. package/.next/server/chunks/71.js +0 -1254
  88. package/.next/server/chunks/74.js +0 -4054
  89. package/.next/server/chunks/753.js +0 -509
  90. package/.next/server/chunks/779.js +0 -58
  91. package/.next/server/chunks/825.js +0 -4039
  92. package/.next/server/chunks/854.js +0 -72
  93. package/.next/server/chunks/859.js +0 -959
  94. package/.next/server/chunks/907.js +0 -1911
  95. package/.next/server/chunks/933.js +0 -517
  96. package/.next/server/chunks/98.js +0 -124
  97. package/.next/server/chunks/988.js +0 -211
  98. package/.next/server/chunks/font-manifest.json +0 -1
  99. package/.next/server/font-manifest.json +0 -1
  100. package/.next/server/middleware-build-manifest.js +0 -1
  101. package/.next/server/middleware-manifest.json +0 -6
  102. package/.next/server/middleware-react-loadable-manifest.js +0 -1
  103. package/.next/server/pages/404.js +0 -386
  104. package/.next/server/pages/404.js.nft.json +0 -1
  105. package/.next/server/pages/500.js +0 -388
  106. package/.next/server/pages/500.js.nft.json +0 -1
  107. package/.next/server/pages/[...slug].js +0 -1005
  108. package/.next/server/pages/[...slug].js.nft.json +0 -1
  109. package/.next/server/pages/[slug]/p.js +0 -2269
  110. package/.next/server/pages/[slug]/p.js.nft.json +0 -1
  111. package/.next/server/pages/_app.js +0 -280
  112. package/.next/server/pages/_app.js.nft.json +0 -1
  113. package/.next/server/pages/_document.js +0 -374
  114. package/.next/server/pages/_document.js.nft.json +0 -1
  115. package/.next/server/pages/_error.js +0 -164
  116. package/.next/server/pages/_error.js.nft.json +0 -1
  117. package/.next/server/pages/account.js +0 -363
  118. package/.next/server/pages/account.js.nft.json +0 -1
  119. package/.next/server/pages/api/graphql.js +0 -365
  120. package/.next/server/pages/api/graphql.js.nft.json +0 -1
  121. package/.next/server/pages/api/health/live.js +0 -31
  122. package/.next/server/pages/api/health/live.js.nft.json +0 -1
  123. package/.next/server/pages/api/health/ready.js +0 -31
  124. package/.next/server/pages/api/health/ready.js.nft.json +0 -1
  125. package/.next/server/pages/api/preview.js +0 -148
  126. package/.next/server/pages/api/preview.js.nft.json +0 -1
  127. package/.next/server/pages/checkout.js +0 -363
  128. package/.next/server/pages/checkout.js.nft.json +0 -1
  129. package/.next/server/pages/en-US/404.html +0 -81
  130. package/.next/server/pages/en-US/404.json +0 -1
  131. package/.next/server/pages/en-US/500.html +0 -81
  132. package/.next/server/pages/en-US/500.json +0 -1
  133. package/.next/server/pages/en-US/account.html +0 -81
  134. package/.next/server/pages/en-US/account.json +0 -1
  135. package/.next/server/pages/en-US/checkout.html +0 -81
  136. package/.next/server/pages/en-US/checkout.json +0 -1
  137. package/.next/server/pages/en-US/login.html +0 -81
  138. package/.next/server/pages/en-US/login.json +0 -1
  139. package/.next/server/pages/en-US/s.html +0 -81
  140. package/.next/server/pages/en-US/s.json +0 -1
  141. package/.next/server/pages/en-US.html +0 -81
  142. package/.next/server/pages/en-US.json +0 -1
  143. package/.next/server/pages/index.js +0 -439
  144. package/.next/server/pages/index.js.nft.json +0 -1
  145. package/.next/server/pages/login.js +0 -368
  146. package/.next/server/pages/login.js.nft.json +0 -1
  147. package/.next/server/pages/s.js +0 -466
  148. package/.next/server/pages/s.js.nft.json +0 -1
  149. package/.next/server/pages-manifest.json +0 -18
  150. package/.next/server/webpack-api-runtime.js +0 -229
  151. package/.next/server/webpack-runtime.js +0 -229
  152. package/.next/static/chunks/143.dd8a556e6957baa1.js +0 -1
  153. package/.next/static/chunks/148.3bb7e05cc5d1c1c4.js +0 -1
  154. package/.next/static/chunks/238-e5e4b2094f0e1df8.js +0 -1
  155. package/.next/static/chunks/243-8f5650ed908aa75c.js +0 -1
  156. package/.next/static/chunks/530.848b014622932b93.js +0 -1
  157. package/.next/static/chunks/548-ab84e9e8b49413ab.js +0 -1
  158. package/.next/static/chunks/603-d1c069aa8a349c86.js +0 -1
  159. package/.next/static/chunks/651.7142f31ce1e052b3.js +0 -1
  160. package/.next/static/chunks/709.7bc5a25ce30abda6.js +0 -1
  161. package/.next/static/chunks/738-67a288ca3569cdbb.js +0 -1
  162. package/.next/static/chunks/741.52f7fb873418346f.js +0 -1
  163. package/.next/static/chunks/98.97381d2021f86cd9.js +0 -1
  164. package/.next/static/chunks/988.d10040040cdfebbb.js +0 -1
  165. package/.next/static/chunks/framework-dfd14d7ce6600b03.js +0 -1
  166. package/.next/static/chunks/main-fd466221927468fd.js +0 -1
  167. package/.next/static/chunks/pages/404-af78f7cd1d3c1f60.js +0 -1
  168. package/.next/static/chunks/pages/500-f6346ca5f9dc4fef.js +0 -1
  169. package/.next/static/chunks/pages/[...slug]-ca533c74c22cb787.js +0 -1
  170. package/.next/static/chunks/pages/[slug]/p-7bb760bb3fcfc0bb.js +0 -1
  171. package/.next/static/chunks/pages/_app-895781b1c7b5bf56.js +0 -1
  172. package/.next/static/chunks/pages/_error-a7a0c1d9bfbb4f38.js +0 -1
  173. package/.next/static/chunks/pages/account-05bd79fb78365e88.js +0 -1
  174. package/.next/static/chunks/pages/checkout-c973786e68f25a39.js +0 -1
  175. package/.next/static/chunks/pages/index-d521ce4f4e2b89a6.js +0 -1
  176. package/.next/static/chunks/pages/login-8deb9243376b6aa1.js +0 -1
  177. package/.next/static/chunks/pages/s-0e516ab36bb49c99.js +0 -1
  178. package/.next/static/chunks/polyfills-c67a75d1b6f99dc8.js +0 -1
  179. package/.next/static/chunks/webpack-062512aedeb4b39e.js +0 -1
  180. package/.next/static/css/0d056c673d2869bb.css +0 -1
  181. package/.next/static/css/4b7138899cd07c63.css +0 -1
  182. package/.next/static/css/527e334fa69cf40a.css +0 -1
  183. package/.next/static/css/6e1a7434f061d0ef.css +0 -1
  184. package/.next/static/css/9e76fef1c9ca89af.css +0 -1
  185. package/.next/static/css/a2eefb25a4608343.css +0 -1
  186. package/.next/static/css/cb7d1fcea42fab9c.css +0 -1
  187. package/.next/static/css/df588bb98c0b0ca6.css +0 -1
  188. package/.next/static/css/e3b039e8f5daf95f.css +0 -1
  189. package/.next/static/css/f0e2d1b8832e935d.css +0 -1
  190. package/.next/static/jxv75E0IlXYBYk71TulQP/_buildManifest.js +0 -1
  191. package/.next/static/jxv75E0IlXYBYk71TulQP/_ssgManifest.js +0 -1
  192. package/.next/trace +0 -80
  193. package/public/~partytown/debug/partytown-atomics.js +0 -556
  194. package/public/~partytown/debug/partytown-media.js +0 -374
  195. package/public/~partytown/debug/partytown-sandbox-sw.js +0 -543
  196. package/public/~partytown/debug/partytown-sw.js +0 -59
  197. package/public/~partytown/debug/partytown-ww-atomics.js +0 -1789
  198. package/public/~partytown/debug/partytown-ww-sw.js +0 -1781
  199. package/public/~partytown/debug/partytown.js +0 -72
  200. package/public/~partytown/partytown-atomics.js +0 -2
  201. package/public/~partytown/partytown-media.js +0 -2
  202. package/public/~partytown/partytown-sw.js +0 -2
  203. package/public/~partytown/partytown.js +0 -2
  204. package/src/components/ui/ProductGallery/usePageProducts.ts +0 -48
  205. package/src/customizations/components/overrides/ThirdPartyScripts.tsx +0 -9
  206. package/src/customizations/scripts/ThirdPartyScripts.tsx +0 -8
package/api/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ export { gql } from '@faststore/graphql-utils'
2
+ export type {
3
+ StoreAggregateOfferRoot,
4
+ StorePropertyValueRoot,
5
+ StoreCollectionRoot,
6
+ StoreFacetRoot,
7
+ StoreSearchResultRoot,
8
+ StoreSeoRoot,
9
+ StoreShippingSLARoot,
10
+ StoreOfferRoot,
11
+ StoreSkuVariationsRoot,
12
+ StoreProductGroupRoot,
13
+ StoreProductRoot,
14
+ StoreOrganizationRoot,
15
+ } from '@faststore/api'
package/codegen.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  overwrite: true
2
- schema: http://localhost:3000/api/graphql
2
+ errorsOnly: true
3
+ schema: ./@generated/graphql/schema.graphql
3
4
  documents:
4
5
  - ./src/**/*.{ts,tsx}
5
6
  config:
package/generate.sh ADDED
@@ -0,0 +1,71 @@
1
+ #!/bin/sh
2
+
3
+ # ANSI color codes
4
+ RED='\033[0;31m'
5
+ YELLOW='\033[1;33m'
6
+ PURPLE='\033[0;35m'
7
+ GREEN='\033[0;32m'
8
+ NC='\033[0m' # No Color
9
+
10
+ # Initialize debug flag to false
11
+ DEBUG_FLAG=false
12
+
13
+ # Check for --debug flag
14
+ if [ "$1" = "--debug" ]; then
15
+ DEBUG_FLAG=true
16
+ fi
17
+
18
+ # Function to display errors with readable messages
19
+ show_error() {
20
+ local cmd="$3"
21
+
22
+ echo "${RED}error${NC} $1"
23
+ if [ "$DEBUG_FLAG" = "true" ]; then
24
+ echo "${PURPLE}DEBUG - \$ $cmd ${RED}error root ↓${NC}\n$2"
25
+ fi
26
+ exit 1
27
+ }
28
+
29
+ # Function to display warnings
30
+ show_warning() {
31
+ local cmd="$3"
32
+
33
+ echo "${YELLOW}warn${NC} $1"
34
+ if [ "$DEBUG_FLAG" = "true" ]; then
35
+ echo "${PURPLE}DEBUG - \$ $cmd ${YELLOW}warn root ↓${NC}\n$2"
36
+ fi
37
+ }
38
+
39
+ # Function to run a command and handle errors and warnings
40
+ run_command() {
41
+ local cmd="$1"
42
+ local error_message="$2"
43
+ local warn="$3"
44
+ local output
45
+
46
+ if [ "$DEBUG_FLAG" = "true" ]; then
47
+ output="$($cmd --debug --verbose 2>&1)"
48
+ else
49
+ output="$($cmd 2>&1)"
50
+ fi
51
+
52
+ local exit_code="$?"
53
+ if [ "$warn" = "true" ]; then
54
+ if [ "$exit_code" -ne 0 ]; then
55
+ show_warning "$error_message" "$output" "$cmd"
56
+ fi
57
+ elif [ "$exit_code" -ne 0 ]; then
58
+ show_error "$error_message" "$output" "$cmd"
59
+ fi
60
+ }
61
+
62
+ # Run "yarn generate:schema" without outputting logs and errors
63
+ run_command "yarn generate:schema" "Failed to run 'yarn generate:schema'. Please check your setup." "false"
64
+
65
+ # Run graphql-codegen and capture the output
66
+ run_command "graphql-codegen" "GraphQL was not optimized and TS files were not updated. Changes in the GraphQL layer did not take effect" "false"
67
+
68
+ # Run "yarn format:generated" and display a warning if it produces output
69
+ run_command "yarn format:generated" "Failed to format generated files. 'yarn format:generated' thrown errors" "true"
70
+
71
+ echo "${GREEN}GraphQL schema, types, and optimizations successfully generated 🎉${NC}"
package/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ export {
2
+ usePage,
3
+ usePDP,
4
+ usePLP,
5
+ useSearchPage,
6
+ isPDP,
7
+ isPLP,
8
+ isSearchPage,
9
+ } from './src/sdk/overrides/PageProvider'
10
+
11
+ export type {
12
+ PDPContext,
13
+ PLPContext,
14
+ SearchPageContext,
15
+ } from './src/sdk/overrides/PageProvider'
package/jest.config.js ADDED
@@ -0,0 +1,6 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} */
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testPathIgnorePatterns: ['/node_modules/', 'cypress/'],
5
+ modulePaths: ['<rootDir>/test'],
6
+ }
package/package.json CHANGED
@@ -1,17 +1,23 @@
1
1
  {
2
2
  "name": "@faststore/core",
3
- "version": "2.1.83",
3
+ "version": "2.2.0-alpha.0",
4
4
  "license": "MIT",
5
5
  "browserslist": "supports es6-module and not dead",
6
+ "exports": {
7
+ ".": "./index.ts"
8
+ },
6
9
  "scripts": {
7
- "generate": "graphql-codegen",
8
- "build": "yarn partytown && next build",
9
- "dev": "yarn partytown && next dev",
10
+ "generate:schema": "tsx src/server/generator/generateGraphQLSchemaFile.ts",
11
+ "generate": "./generate.sh",
12
+ "build": "yarn partytown & yarn generate && next build",
13
+ "dev": "yarn partytown & yarn generate && next dev",
10
14
  "clean": "rm -r .next",
11
15
  "serve": "next start",
12
- "test": "cypress open",
16
+ "test:e2e": "cypress open",
17
+ "test": "tsdx test",
13
18
  "lhci": "lhci autorun",
14
19
  "format": "prettier --write \"**/*.{ts,js,tsx,jsx,json}\"",
20
+ "format:generated": "prettier --write \"@generated/**/*.{ts,js,tsx,jsx,json}\" --loglevel error",
15
21
  "lint": "next lint",
16
22
  "stylelint": "stylelint \"**/*.scss\"",
17
23
  "stylelint:fix": "stylelint \"**/*.scss\" --fix",
@@ -29,16 +35,24 @@
29
35
  "@envelop/graphql-jit": "^1.1.1",
30
36
  "@envelop/parser-cache": "^2.2.0",
31
37
  "@envelop/validation-cache": "^2.2.0",
32
- "@faststore/api": "^2.1.83",
33
- "@faststore/components": "^2.1.82",
34
- "@faststore/graphql-utils": "^2.1.82",
35
- "@faststore/sdk": "^2.1.82",
36
- "@faststore/ui": "^2.1.82",
38
+ "@faststore/api": "^2.2.0-alpha.0",
39
+ "@faststore/components": "^2.2.0-alpha.0",
40
+ "@faststore/graphql-utils": "^2.2.0-alpha.0",
41
+ "@faststore/sdk": "^2.2.0-alpha.0",
42
+ "@faststore/ui": "^2.2.0-alpha.0",
43
+ "@graphql-codegen/cli": "^3.3.1",
44
+ "@graphql-codegen/typescript": "^3.0.4",
45
+ "@graphql-codegen/typescript-operations": "^3.0.4",
46
+ "@graphql-tools/load-files": "^7.0.0",
47
+ "@graphql-tools/merge": "^9.0.0",
48
+ "@graphql-tools/utils": "^9.2.1",
37
49
  "@types/react": "^18.0.14",
38
50
  "@vtex/client-cms": "^0.2.12",
51
+ "@vtex/prettier-config": "1.0.0",
39
52
  "autoprefixer": "^10.4.0",
40
53
  "chalk": "^5.2.0",
41
54
  "css-loader": "^6.7.1",
55
+ "deepmerge": "^4.3.1",
42
56
  "draft-js": "^0.11.7",
43
57
  "draft-js-export-html": "^1.4.1",
44
58
  "graphql": "^15.0.0",
@@ -48,6 +62,7 @@
48
62
  "next-seo": "^5.4.0",
49
63
  "nextjs-progressbar": "^0.0.14",
50
64
  "postcss": "^8.4.4",
65
+ "prettier": "^2.2.0",
51
66
  "react": "^18.2.0",
52
67
  "react-dom": "^18.2.0",
53
68
  "react-intersection-observer": "^8.32.5",
@@ -57,15 +72,14 @@
57
72
  "style-loader": "^3.3.1",
58
73
  "swr": "^1.3.0",
59
74
  "tsconfig-paths-webpack-plugin": "^3.5.2",
75
+ "tsx": "^3.12.7",
60
76
  "typescript": "4.7.3"
61
77
  },
62
78
  "devDependencies": {
63
79
  "@cypress/code-coverage": "^3.9.10",
64
- "@faststore/eslint-config": "^2.1.82",
80
+ "@envelop/testing": "^6.0.0",
81
+ "@faststore/eslint-config": "^2.2.0-alpha.0",
65
82
  "@faststore/lighthouse": "^1.12.32",
66
- "@graphql-codegen/cli": "^2.6.2",
67
- "@graphql-codegen/typescript": "^2.5.1",
68
- "@graphql-codegen/typescript-operations": "^2.4.2",
69
83
  "@lhci/cli": "^0.9.0",
70
84
  "@storybook/addon-a11y": "^6.5.9",
71
85
  "@storybook/addon-actions": "^6.5.9",
@@ -76,7 +90,7 @@
76
90
  "@storybook/react": "^6.5.9",
77
91
  "@testing-library/cypress": "^8.0.0",
78
92
  "@types/cypress": "^1.1.3",
79
- "@vtex/prettier-config": "1.0.0",
93
+ "@types/jest": "29.1.0",
80
94
  "axe-core": "^4.3.3",
81
95
  "cypress": "9.6.0",
82
96
  "cypress-axe": "^0.13.0",
@@ -85,15 +99,16 @@
85
99
  "eslint": "^7.32.0",
86
100
  "husky": "^5.2.0",
87
101
  "is-ci": "^3.0.0",
102
+ "jest": "29.1.0",
88
103
  "lint-staged": "^10.5.4",
89
104
  "msw-storybook-addon": "^1.6.3",
90
- "prettier": "^2.2.0",
91
105
  "stylelint": "^14.6.0",
92
106
  "stylelint-config-recess-order": "^3.0.0",
93
107
  "stylelint-config-standard": "^24.0.0",
94
108
  "stylelint-config-standard-scss": "^3.0.0",
95
109
  "stylelint-order": "^5.0.0",
96
- "stylelint-scss": "^4.0.1"
110
+ "stylelint-scss": "^4.0.1",
111
+ "ts-jest": "29.1.0"
97
112
  },
98
113
  "lint-staged": {
99
114
  "*.{ts,js,tsx,jsx}": [
@@ -110,5 +125,5 @@
110
125
  "msw": {
111
126
  "workerDirectory": "public"
112
127
  },
113
- "gitHead": "a55301974a0ab1894b32414d372091d956fbc17b"
128
+ "gitHead": "356e52b6eae13cc4000c6915985009d45e7ae0c6"
114
129
  }
@@ -1,5 +1,5 @@
1
1
  import { Partytown } from '@builder.io/partytown/react'
2
- import OverrideComponents from 'src/customizations/GlobalOverrides'
2
+
3
3
  import storeConfig from '../../../faststore.config'
4
4
  import GoogleTagManager from './GoogleTagManager'
5
5
  import VTEX from './vtex'
@@ -26,7 +26,6 @@ function ThirdPartyScripts() {
26
26
  <>
27
27
  {includeGTM && <GoogleTagManager containerId={gtmContainerId} />}
28
28
  {includeVTEX && <VTEX />}
29
- <OverrideComponents.ThirdPartyScripts />
30
29
  <Partytown
31
30
  key="partytown"
32
31
  // Variables to forward to from main to worker
@@ -1,5 +1,5 @@
1
1
  import chalk from 'chalk'
2
- import { ComponentType, PropsWithChildren, useMemo } from 'react'
2
+ import { ComponentType, PropsWithChildren, memo, useMemo } from 'react'
3
3
 
4
4
  import SectionBoundary from './SectionBoundary'
5
5
  import { Section } from '@vtex/client-cms'
@@ -7,7 +7,6 @@ import { Section } from '@vtex/client-cms'
7
7
  interface Props {
8
8
  components: Record<string, ComponentType<any>>
9
9
  sections: Array<{ name: string; data: any }>
10
- context?: unknown
11
10
  }
12
11
 
13
12
  const useDividedSections = (sections: Section[]) => {
@@ -23,7 +22,7 @@ const useDividedSections = (sections: Section[]) => {
23
22
  }, [sections])
24
23
  }
25
24
 
26
- const RenderSectionsBase = ({ sections = [], context, components }: Props) => {
25
+ const RenderSectionsBase = ({ sections = [], components }: Props) => {
27
26
  return (
28
27
  <>
29
28
  {sections.map(({ name, data }, index) => {
@@ -42,7 +41,7 @@ const RenderSectionsBase = ({ sections = [], context, components }: Props) => {
42
41
 
43
42
  return (
44
43
  <SectionBoundary key={`cms-section-${index}`} name={name}>
45
- <Component {...data} context={context} />
44
+ <Component {...data} />
46
45
  </SectionBoundary>
47
46
  )
48
47
  })}
@@ -71,4 +70,4 @@ function RenderSections({
71
70
  )
72
71
  }
73
72
 
74
- export default RenderSections
73
+ export default memo(RenderSections)
@@ -2,18 +2,19 @@ import {
2
2
  ProductGrid as UIProductGrid,
3
3
  ProductGridItem as UIProductGridItem,
4
4
  } from '@faststore/ui'
5
- import type { ProductSummary_ProductFragment } from '@generated/graphql'
5
+ import type { ClientProductsQueryQuery } from '@generated/graphql'
6
6
  import ProductGridSkeleton from 'src/components/skeletons/ProductGridSkeleton'
7
7
 
8
8
  import { ProductCardProps } from '../ProductCard'
9
9
 
10
10
  import { __experimentalProductCard as ProductCard } from 'src/components/sections/ProductGallery/Overrides'
11
+ import { memo } from 'react'
11
12
 
12
13
  interface Props {
13
14
  /**
14
15
  * Products listed on the grid.
15
16
  */
16
- products: Array<{ node: ProductSummary_ProductFragment }>
17
+ products: ClientProductsQueryQuery['search']['products']['edges']
17
18
  page: number
18
19
  /**
19
20
  * Quantity of products listed.
@@ -64,4 +65,4 @@ function ProductGrid({
64
65
  )
65
66
  }
66
67
 
67
- export default ProductGrid
68
+ export default memo(ProductGrid)
@@ -4,36 +4,31 @@ import Breadcrumb from 'src/components/ui/Breadcrumb'
4
4
 
5
5
  import Section from '../Section'
6
6
 
7
- import {
8
- ServerCollectionPageQueryQuery,
9
- ServerProductPageQueryQuery,
10
- } from '@generated/graphql'
11
7
  import styles from './section.module.scss'
12
-
13
- type BreadcrumbContext =
14
- | ServerProductPageQueryQuery['product']
15
- | ServerCollectionPageQueryQuery['collection']
8
+ import {
9
+ PDPContext,
10
+ PLPContext,
11
+ isPDP,
12
+ isPLP,
13
+ usePage,
14
+ } from 'src/sdk/overrides/PageProvider'
16
15
 
17
16
  interface BreadcrumbSectionProps {
18
- context?: BreadcrumbContext
19
17
  icon: string
20
18
  alt: string
21
19
  }
22
20
 
23
- const isProduct = (x: any): x is ServerProductPageQueryQuery['product'] =>
24
- x?.sku != undefined && x?.sku != null
25
- const isCollection = (
26
- x: any
27
- ): x is ServerCollectionPageQueryQuery['collection'] =>
28
- x?.seo != undefined && x?.seo != null && x?.sku == undefined
29
-
30
- function BreadcrumbSection({ context, ...otherProps }: BreadcrumbSectionProps) {
31
- const title = isCollection(context) ? context?.seo?.title : 'All Products'
21
+ function BreadcrumbSection({ ...otherProps }: BreadcrumbSectionProps) {
22
+ const context = usePage<PDPContext | PLPContext>()
23
+ const title = isPLP(context)
24
+ ? context?.data?.collection?.seo?.title
25
+ : 'All Products'
32
26
  const fallback = [{ item: '/', name: title, position: 1 }]
33
- const breadcrumbList = isProduct(context)
34
- ? context?.breadcrumbList?.itemListElement
35
- : isCollection(context)
36
- ? context?.breadcrumbList?.itemListElement
27
+
28
+ const breadcrumbList = isPDP(context)
29
+ ? context?.data?.product?.breadcrumbList?.itemListElement
30
+ : isPLP(context)
31
+ ? context?.data?.collection?.breadcrumbList?.itemListElement
37
32
  : fallback
38
33
 
39
34
  return (
@@ -1,24 +1,26 @@
1
1
  import { useMemo } from 'react'
2
2
 
3
- import type { ProductDetailsFragment_ProductFragment } from '@generated/graphql'
4
3
  import UIProductShelf from 'src/components/ui/ProductShelf'
5
4
  import { useInView } from 'react-intersection-observer'
5
+ import { useProductsQuery } from 'src/sdk/product/useProductsQuery'
6
+ import { usePDP } from 'src/sdk/overrides/PageProvider'
6
7
  import styles from '../ProductShelf/section.module.scss'
7
8
  import Section from '../Section'
8
9
 
9
10
  interface Props {
10
11
  items: number
11
12
  title: string
12
- context: ProductDetailsFragment_ProductFragment
13
13
  kind: 'buy' | 'view'
14
14
  }
15
15
 
16
- const CrossSellingShelf = ({ items, title, context, kind }: Props) => {
16
+ const CrossSellingShelf = ({ items: first, title, kind }: Props) => {
17
17
  const { ref, inView } = useInView()
18
+ const context = usePDP()
19
+ const productGroupID = context?.data?.product?.isVariantOf?.productGroupID
18
20
 
19
21
  const selectedFacets = useMemo(
20
- () => [{ key: kind, value: context.isVariantOf.productGroupID }],
21
- [kind, context.isVariantOf.productGroupID]
22
+ () => [{ key: kind, value: productGroupID }],
23
+ [kind, productGroupID]
22
24
  )
23
25
 
24
26
  return (
@@ -28,7 +30,7 @@ const CrossSellingShelf = ({ items, title, context, kind }: Props) => {
28
30
  >
29
31
  <UIProductShelf
30
32
  inView={inView}
31
- first={items}
33
+ first={first}
32
34
  title={title}
33
35
  selectedFacets={selectedFacets}
34
36
  />
@@ -1,14 +1,12 @@
1
1
  import { useEffect, useState } from 'react'
2
2
 
3
3
  import { gql } from '@faststore/graphql-utils'
4
- import { sendAnalyticsEvent } from '@faststore/sdk'
5
4
  import type { CurrencyCode, ViewItemEvent } from '@faststore/sdk'
6
- import type { ProductDetailsFragment_ProductFragment } from '@generated/graphql'
5
+ import { sendAnalyticsEvent } from '@faststore/sdk'
7
6
 
8
- import { useSession } from 'src/sdk/session'
9
- import { useProduct } from 'src/sdk/product/useProduct'
10
- import { useFormattedPrice } from 'src/sdk/product/useFormattedPrice'
11
7
  import type { AnalyticsItem } from 'src/sdk/analytics/types'
8
+ import { useFormattedPrice } from 'src/sdk/product/useFormattedPrice'
9
+ import { useSession } from 'src/sdk/session'
12
10
 
13
11
  import Section from '../Section'
14
12
  import ProductDescription from 'src/components/ui/ProductDescription'
@@ -17,15 +15,13 @@ import { ProductDetailsSettings } from 'src/components/ui/ProductDetails'
17
15
  import styles from './section.module.scss'
18
16
 
19
17
  import {
20
- ProductTitle,
21
18
  DiscountBadge,
19
+ ProductTitle,
22
20
  __experimentalImageGallery as ImageGallery,
23
21
  __experimentalShippingSimulation as ShippingSimulation,
24
22
  } from 'src/components/sections/ProductDetails/Overrides'
25
23
 
26
- interface ProductDetailsContextProps {
27
- context: ProductDetailsFragment_ProductFragment
28
- }
24
+ import { usePDP } from 'src/sdk/overrides/PageProvider'
29
25
 
30
26
  export interface ProductDetailsProps {
31
27
  productTitle: {
@@ -59,7 +55,6 @@ export interface ProductDetailsProps {
59
55
  }
60
56
 
61
57
  function ProductDetails({
62
- context: staleProduct,
63
58
  productTitle: {
64
59
  refNumber: showRefNumber,
65
60
  discountBadge: {
@@ -87,36 +82,31 @@ function ProductDetails({
87
82
  initiallyExpanded: productDescriptionInitiallyExpanded,
88
83
  displayDescription: shouldDisplayProductDescription,
89
84
  },
90
- }: ProductDetailsProps & ProductDetailsContextProps) {
85
+ }: ProductDetailsProps) {
91
86
  const { currency } = useSession()
92
87
  const [quantity, setQuantity] = useState(1)
88
+ const context = usePDP()
89
+ const { product, isValidating } = context?.data
93
90
 
94
- // Stale while revalidate the product for fetching the new price etc
95
- const { data, isValidating } = useProduct(staleProduct.id, {
96
- product: staleProduct,
97
- })
98
-
99
- if (!data) {
91
+ if (!product) {
100
92
  throw new Error('NotFound')
101
93
  }
102
94
 
103
95
  const {
104
- product: {
105
- id,
106
- sku,
107
- gtin,
108
- name: variantName,
109
- brand,
110
- isVariantOf,
111
- description,
112
- isVariantOf: { name, productGroupID: productId },
113
- image: productImages,
114
- offers: {
115
- offers: [{ availability, price, listPrice, seller }],
116
- lowPrice,
117
- },
96
+ id,
97
+ sku,
98
+ gtin,
99
+ name: variantName,
100
+ brand,
101
+ isVariantOf,
102
+ description,
103
+ isVariantOf: { name, productGroupID: productId },
104
+ image: productImages,
105
+ offers: {
106
+ offers: [{ availability, price, listPrice, seller }],
107
+ lowPrice,
118
108
  },
119
- } = data
109
+ } = product
120
110
 
121
111
  useEffect(() => {
122
112
  sendAnalyticsEvent<ViewItemEvent<AnalyticsItem>>({
@@ -191,7 +181,7 @@ function ProductDetails({
191
181
  >
192
182
  {!outOfStock ? (
193
183
  <ProductDetailsSettings
194
- product={data.product}
184
+ product={product}
195
185
  isValidating={isValidating}
196
186
  buyButtonTitle={buyButtonTitle}
197
187
  quantity={quantity}
@@ -1,19 +1,20 @@
1
1
  import { mark } from 'src/sdk/tests/mark'
2
2
 
3
- import { ServerCollectionPageQueryQuery } from '@generated/graphql'
4
3
  import ProductGallery, {
5
4
  ProductGalleryProps,
6
5
  } from 'src/components/ui/ProductGallery/ProductGallery'
7
- import { SearchPageContextType } from 'src/pages/s'
8
6
  import Section from '../Section'
9
7
  import EmptyGallery from './EmptyGallery'
10
8
  import styles from './section.module.scss'
11
- import { useGalleryQuery } from './useGalleryQuery'
12
-
13
- type ProductGalleryContext = ServerCollectionPageQueryQuery['collection']
9
+ import {
10
+ PLPContext,
11
+ SearchPageContext,
12
+ isPLP,
13
+ isSearchPage,
14
+ usePage,
15
+ } from 'src/sdk/overrides/PageProvider'
14
16
 
15
17
  export interface ProductGallerySectionProps {
16
- context?: ProductGalleryContext
17
18
  searchTermLabel?: ProductGalleryProps['searchTermLabel']
18
19
  totalCountLabel?: ProductGalleryProps['totalCountLabel']
19
20
  filter: ProductGalleryProps['filter']
@@ -24,28 +25,17 @@ export interface ProductGallerySectionProps {
24
25
  productCard?: ProductGalleryProps['productCard']
25
26
  }
26
27
 
27
- const isSearch = (x: any): x is SearchPageContextType =>
28
- x === undefined || x?.title != undefined || x?.searchTerm != undefined
29
- const isCollection = (
30
- x: any
31
- ): x is ServerCollectionPageQueryQuery['collection'] =>
32
- x?.seo != undefined && x?.seo != null && x?.sku == undefined
33
-
34
- function ProductGallerySection({
35
- context,
36
- ...otherProps
37
- }: ProductGallerySectionProps) {
38
- const [title, searchTerm] = isSearch(context)
39
- ? [context?.title, context?.searchTerm]
40
- : isCollection(context)
41
- ? [context?.seo?.title]
28
+ function ProductGallerySection({ ...otherProps }: ProductGallerySectionProps) {
29
+ const context = usePage<SearchPageContext | PLPContext>()
30
+ const [title, searchTerm] = isSearchPage(context)
31
+ ? [context?.data?.title, context?.data?.searchTerm]
32
+ : isPLP(context)
33
+ ? [context?.data?.collection?.seo?.title]
42
34
  : ['']
43
35
 
44
- const { data: productGalleryData } = useGalleryQuery()
45
- const totalCount =
46
- productGalleryData?.search.products.pageInfo.totalCount ?? 0
36
+ const totalCount = context?.data?.search?.products?.pageInfo?.totalCount ?? 0
47
37
 
48
- if (productGalleryData && totalCount === 0) {
38
+ if (context?.data?.search?.products && totalCount === 0) {
49
39
  return (
50
40
  <Section className={`${styles.section} section-product-gallery`}>
51
41
  <section data-testid="product-gallery" data-fs-product-listing>
@@ -62,7 +52,6 @@ function ProductGallerySection({
62
52
  <ProductGallery
63
53
  title={title}
64
54
  searchTerm={searchTerm}
65
- productGalleryData={productGalleryData}
66
55
  totalCount={totalCount}
67
56
  {...otherProps}
68
57
  />
@@ -1,8 +1,8 @@
1
1
  import { useInView } from 'react-intersection-observer'
2
2
  import Section from '../Section'
3
3
 
4
- import styles from './section.module.scss'
5
4
  import ProductShelf, { ProductShelfProps } from 'src/components/ui/ProductShelf'
5
+ import styles from './section.module.scss'
6
6
 
7
7
  function ProductShelfSection({
8
8
  ...otherProps
@@ -1,7 +1,7 @@
1
1
  import { useEffect, useRef } from 'react'
2
2
  import { useInView } from 'react-intersection-observer'
3
3
 
4
- import type { ProductsQueryQueryVariables } from '@generated/graphql'
4
+ import type { ClientProductsQueryQueryVariables } from '@generated/graphql'
5
5
  import ProductCard from 'src/components/product/ProductCard'
6
6
  import ProductTilesSkeleton from 'src/components/skeletons/ProductTilesSkeleton'
7
7
  import Tiles, { Tile } from 'src/components/ui/Tiles'
@@ -12,7 +12,7 @@ import Section from '../Section'
12
12
 
13
13
  import styles from './section.module.scss'
14
14
 
15
- interface ProductTilesProps extends Partial<ProductsQueryQueryVariables> {
15
+ interface ProductTilesProps extends Partial<ClientProductsQueryQueryVariables> {
16
16
  title: string
17
17
  }
18
18
 
@@ -56,7 +56,8 @@ const getSizes = (products: number, idx: number) => {
56
56
  const ProductTiles = ({ title, ...variables }: ProductTilesProps) => {
57
57
  const viewedOnce = useRef(false)
58
58
  const { ref, inView } = useInView()
59
- const products = useProductsQuery(variables)
59
+ const data = useProductsQuery(variables)
60
+ const products = data?.search?.products
60
61
  const productEdges = products?.edges ?? []
61
62
 
62
63
  const { sendViewItemListEvent } = useViewItemListEvent({