@faststore/core 2.2.0-alpha.0 → 2.2.0-alpha.10

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 (232) hide show
  1. package/.next/BUILD_ID +1 -0
  2. package/.next/build-manifest.json +128 -0
  3. package/.next/cache/.tsbuildinfo +1 -0
  4. package/.next/cache/config.json +7 -0
  5. package/.next/cache/eslint/.cache_1gneedd +1 -0
  6. package/.next/cache/next-server.js.nft.json +1 -0
  7. package/.next/cache/webpack/client-production/0.pack +0 -0
  8. package/.next/cache/webpack/client-production/index.pack +0 -0
  9. package/.next/cache/webpack/server-production/0.pack +0 -0
  10. package/.next/cache/webpack/server-production/index.pack +0 -0
  11. package/.next/export-marker.json +1 -0
  12. package/.next/images-manifest.json +1 -0
  13. package/.next/next-server.js.nft.json +1 -0
  14. package/.next/package.json +1 -0
  15. package/.next/prerender-manifest.json +1 -0
  16. package/.next/react-loadable-manifest.json +47 -0
  17. package/.next/required-server-files.json +1 -0
  18. package/.next/routes-manifest.json +1 -0
  19. package/.next/server/chunks/117.js +430 -0
  20. package/.next/server/chunks/177.js +120 -0
  21. package/.next/server/chunks/183.js +95 -0
  22. package/.next/server/chunks/184.js +61 -0
  23. package/.next/server/chunks/289.js +240 -0
  24. package/.next/server/chunks/312.js +678 -0
  25. package/.next/server/chunks/350.js +200 -0
  26. package/.next/server/chunks/37.js +610 -0
  27. package/.next/server/chunks/386.js +200 -0
  28. package/.next/server/chunks/387.js +550 -0
  29. package/.next/server/chunks/52.js +4007 -0
  30. package/.next/server/chunks/53.js +61 -0
  31. package/.next/server/chunks/574.js +145 -0
  32. package/.next/server/chunks/576.js +95 -0
  33. package/.next/server/chunks/585.js +640 -0
  34. package/.next/server/chunks/676.js +32 -0
  35. package/.next/server/chunks/692.js +111 -0
  36. package/.next/server/chunks/693.js +58 -0
  37. package/.next/server/chunks/732.js +1880 -0
  38. package/.next/server/chunks/74.js +3964 -0
  39. package/.next/server/chunks/779.js +58 -0
  40. package/.next/server/chunks/817.js +4007 -0
  41. package/.next/server/chunks/825.js +4074 -0
  42. package/.next/server/chunks/854.js +72 -0
  43. package/.next/server/chunks/859.js +959 -0
  44. package/.next/server/chunks/897.js +1289 -0
  45. package/.next/server/chunks/98.js +163 -0
  46. package/.next/server/chunks/988.js +211 -0
  47. package/.next/server/chunks/font-manifest.json +1 -0
  48. package/.next/server/font-manifest.json +1 -0
  49. package/.next/server/middleware-build-manifest.js +1 -0
  50. package/.next/server/middleware-manifest.json +6 -0
  51. package/.next/server/middleware-react-loadable-manifest.js +1 -0
  52. package/.next/server/pages/404.js +386 -0
  53. package/.next/server/pages/404.js.nft.json +1 -0
  54. package/.next/server/pages/500.js +388 -0
  55. package/.next/server/pages/500.js.nft.json +1 -0
  56. package/.next/server/pages/[...slug].js +1084 -0
  57. package/.next/server/pages/[...slug].js.nft.json +1 -0
  58. package/.next/server/pages/[slug]/p.js +2274 -0
  59. package/.next/server/pages/[slug]/p.js.nft.json +1 -0
  60. package/.next/server/pages/_app.js +279 -0
  61. package/.next/server/pages/_app.js.nft.json +1 -0
  62. package/.next/server/pages/_document.js +358 -0
  63. package/.next/server/pages/_document.js.nft.json +1 -0
  64. package/.next/server/pages/_error.js +164 -0
  65. package/.next/server/pages/_error.js.nft.json +1 -0
  66. package/.next/server/pages/account.js +363 -0
  67. package/.next/server/pages/account.js.nft.json +1 -0
  68. package/.next/server/pages/api/graphql.js +457 -0
  69. package/.next/server/pages/api/graphql.js.nft.json +1 -0
  70. package/.next/server/pages/api/health/live.js +31 -0
  71. package/.next/server/pages/api/health/live.js.nft.json +1 -0
  72. package/.next/server/pages/api/health/ready.js +31 -0
  73. package/.next/server/pages/api/health/ready.js.nft.json +1 -0
  74. package/.next/server/pages/api/preview.js +130 -0
  75. package/.next/server/pages/api/preview.js.nft.json +1 -0
  76. package/.next/server/pages/checkout.js +363 -0
  77. package/.next/server/pages/checkout.js.nft.json +1 -0
  78. package/.next/server/pages/en-US/404.html +81 -0
  79. package/.next/server/pages/en-US/404.json +1 -0
  80. package/.next/server/pages/en-US/500.html +81 -0
  81. package/.next/server/pages/en-US/500.json +1 -0
  82. package/.next/server/pages/en-US/account.html +81 -0
  83. package/.next/server/pages/en-US/account.json +1 -0
  84. package/.next/server/pages/en-US/checkout.html +81 -0
  85. package/.next/server/pages/en-US/checkout.json +1 -0
  86. package/.next/server/pages/en-US/login.html +81 -0
  87. package/.next/server/pages/en-US/login.json +1 -0
  88. package/.next/server/pages/en-US/s.html +81 -0
  89. package/.next/server/pages/en-US/s.json +1 -0
  90. package/.next/server/pages/en-US.html +90 -0
  91. package/.next/server/pages/en-US.json +1 -0
  92. package/.next/server/pages/index.js +432 -0
  93. package/.next/server/pages/index.js.nft.json +1 -0
  94. package/.next/server/pages/login.js +368 -0
  95. package/.next/server/pages/login.js.nft.json +1 -0
  96. package/.next/server/pages/s.js +548 -0
  97. package/.next/server/pages/s.js.nft.json +1 -0
  98. package/.next/server/pages-manifest.json +18 -0
  99. package/.next/server/webpack-api-runtime.js +229 -0
  100. package/.next/server/webpack-runtime.js +229 -0
  101. package/.next/static/2ZML9vssR--cHRUHvx_OG/_buildManifest.js +1 -0
  102. package/.next/static/2ZML9vssR--cHRUHvx_OG/_ssgManifest.js +1 -0
  103. package/.next/static/chunks/251.ffc4f3998ecb915a.js +1 -0
  104. package/.next/static/chunks/383-6217b37bd38ffd07.js +1 -0
  105. package/.next/static/chunks/386.d01e0db26c523f0f.js +1 -0
  106. package/.next/static/chunks/574.70612be06fd1365f.js +1 -0
  107. package/.next/static/chunks/585.3350efefe61c9461.js +1 -0
  108. package/.next/static/chunks/635-666ee2cad2925bb7.js +1 -0
  109. package/.next/static/chunks/651.7142f31ce1e052b3.js +1 -0
  110. package/.next/static/chunks/721-f1665b3f1d98b7a9.js +1 -0
  111. package/.next/static/chunks/722-d0cc87aacd616b5d.js +1 -0
  112. package/.next/static/chunks/741.52f7fb873418346f.js +1 -0
  113. package/.next/static/chunks/783-ded9d8cda0d5c8d9.js +1 -0
  114. package/.next/static/chunks/800.851af48fe2ab4a4c.js +1 -0
  115. package/.next/static/chunks/98.40c7e17d9de4eb8f.js +1 -0
  116. package/.next/static/chunks/988.afda042dd9ba11d1.js +1 -0
  117. package/.next/static/chunks/framework-dfd14d7ce6600b03.js +1 -0
  118. package/.next/static/chunks/main-e4e873ee741162eb.js +1 -0
  119. package/.next/static/chunks/pages/404-6c674028b2f80cbb.js +1 -0
  120. package/.next/static/chunks/pages/500-ff55de77265a7e43.js +1 -0
  121. package/.next/static/chunks/pages/[...slug]-7f8dc13cc9542463.js +1 -0
  122. package/.next/static/chunks/pages/[slug]/p-2fb3fd9027f2923b.js +1 -0
  123. package/.next/static/chunks/pages/_app-7db7de3d205714be.js +1 -0
  124. package/.next/static/chunks/pages/_error-a7a0c1d9bfbb4f38.js +1 -0
  125. package/.next/static/chunks/pages/account-b06035cba2c99604.js +1 -0
  126. package/.next/static/chunks/pages/checkout-f0c3e8d691cb8a54.js +1 -0
  127. package/.next/static/chunks/pages/index-a141c747fcc197a1.js +1 -0
  128. package/.next/static/chunks/pages/login-4e0e6cab7a07f1f3.js +1 -0
  129. package/.next/static/chunks/pages/s-823f8e1cabbf63b3.js +1 -0
  130. package/.next/static/chunks/polyfills-c67a75d1b6f99dc8.js +1 -0
  131. package/.next/static/chunks/webpack-f3d0973d5a781e73.js +1 -0
  132. package/.next/static/css/527e334fa69cf40a.css +1 -0
  133. package/.next/static/css/6a7fdc5a21fbead5.css +1 -0
  134. package/.next/static/css/6e1a7434f061d0ef.css +1 -0
  135. package/.next/static/css/723835bce380750d.css +1 -0
  136. package/.next/static/css/8f93a4630936c20b.css +1 -0
  137. package/.next/static/css/9e76fef1c9ca89af.css +1 -0
  138. package/.next/static/css/9f79fa103f49bca1.css +1 -0
  139. package/.next/static/css/a2eefb25a4608343.css +1 -0
  140. package/.next/static/css/cb7d1fcea42fab9c.css +1 -0
  141. package/.next/static/css/df588bb98c0b0ca6.css +1 -0
  142. package/.next/static/css/fd27ecc37832aa54.css +1 -0
  143. package/.next/trace +77 -0
  144. package/.turbo/turbo-build.log +24 -21
  145. package/.turbo/turbo-lint.log +3 -0
  146. package/.turbo/turbo-test.log +11 -11
  147. package/@generated/graphql/index.ts +38 -14
  148. package/@generated/graphql/persisted.json +6 -6
  149. package/README.md +3 -3
  150. package/cms/faststore/sections.json +56 -2
  151. package/cypress/global.js +8 -0
  152. package/cypress/integration/a11y.test.js +7 -24
  153. package/cypress/integration/analytics.test.js +78 -87
  154. package/cypress/integration/cart.test.js +4 -4
  155. package/cypress/integration/plp.test.js +6 -6
  156. package/cypress/integration/search.test.js +1 -1
  157. package/cypress/integration/seo.test.js +14 -14
  158. package/cypress.config.ts +19 -0
  159. package/faststore.config.js +2 -1
  160. package/index.ts +4 -0
  161. package/next.config.js +4 -0
  162. package/package.json +22 -18
  163. package/public/~partytown/debug/partytown-atomics.js +556 -0
  164. package/public/~partytown/debug/partytown-media.js +374 -0
  165. package/public/~partytown/debug/partytown-sandbox-sw.js +543 -0
  166. package/public/~partytown/debug/partytown-sw.js +59 -0
  167. package/public/~partytown/debug/partytown-ww-atomics.js +1789 -0
  168. package/public/~partytown/debug/partytown-ww-sw.js +1781 -0
  169. package/public/~partytown/debug/partytown.js +72 -0
  170. package/public/~partytown/partytown-atomics.js +2 -0
  171. package/public/~partytown/partytown-media.js +2 -0
  172. package/public/~partytown/partytown-sw.js +2 -0
  173. package/public/~partytown/partytown.js +2 -0
  174. package/src/components/ThirdPartyScripts/ThirdPartyScripts.tsx +2 -1
  175. package/src/components/cart/CartSidebar/CartSidebar.tsx +41 -27
  176. package/src/components/navigation/Navbar/Navbar.tsx +3 -4
  177. package/src/components/navigation/NavbarSlider/NavbarSlider.tsx +4 -5
  178. package/src/components/product/NotAvailableButton/NotAvailableButton.tsx +13 -0
  179. package/src/components/product/NotAvailableButton/index.ts +1 -0
  180. package/src/components/product/ProductGrid/ProductGrid.tsx +2 -2
  181. package/src/components/search/Filter/Filter.tsx +1 -1
  182. package/src/components/search/Filter/FilterDesktop.tsx +1 -1
  183. package/src/components/search/Filter/FilterSlider.tsx +1 -1
  184. package/src/components/search/SearchInput/SearchInput.tsx +12 -1
  185. package/src/components/search/SearchTop/SearchTop.tsx +7 -1
  186. package/src/components/sections/CrossSellingShelf/CrossSellingShelf.tsx +0 -1
  187. package/src/components/sections/Footer/Footer.tsx +14 -2
  188. package/src/components/sections/Navbar/Navbar.tsx +4 -0
  189. package/src/components/sections/Newsletter/Overrides.tsx +4 -0
  190. package/src/components/sections/ProductDetails/Overrides.tsx +8 -4
  191. package/src/components/sections/ProductDetails/ProductDetails.tsx +26 -15
  192. package/src/components/sections/ProductTiles/ProductTiles.tsx +3 -2
  193. package/src/components/ui/ImageGallery/ImageGallery.tsx +13 -6
  194. package/src/components/ui/Newsletter/Newsletter.tsx +6 -44
  195. package/src/components/ui/Newsletter/NewsletterAddendum.tsx +86 -0
  196. package/src/components/ui/ProductDescription/ProductDescription.tsx +6 -1
  197. package/src/components/ui/ProductDetails/ProductDetailsSettings.tsx +97 -58
  198. package/src/components/ui/ProductGallery/ProductGallery.tsx +2 -2
  199. package/src/components/ui/ShippingSimulation/ShippingSimulation.tsx +12 -34
  200. package/src/customizations/GlobalOverrides.tsx +2 -0
  201. package/src/customizations/components/overrides/ThirdPartyScripts.tsx +9 -0
  202. package/src/customizations/fragments/{ClientProducts.ts → ClientManyProducts.ts} +1 -1
  203. package/src/customizations/fragments/ClientSearchSuggestions.ts +13 -0
  204. package/src/customizations/fragments/ClientShippingSimulation.ts +11 -0
  205. package/src/customizations/fragments/ClientTopSearchSuggestions.ts +13 -0
  206. package/src/customizations/fragments/{ServerProductPage.ts → ServerProduct.ts} +1 -1
  207. package/src/customizations/scripts/ThirdPartyScripts.tsx +8 -0
  208. package/src/experimental/index.ts +58 -0
  209. package/src/pages/[...slug].tsx +5 -2
  210. package/src/pages/[slug]/p.tsx +7 -7
  211. package/src/sdk/analytics/index.tsx +1 -1
  212. package/src/sdk/analytics/platform/vtex/search.ts +67 -31
  213. package/src/sdk/analytics/types.ts +14 -0
  214. package/src/sdk/overrides/PageProvider.tsx +9 -5
  215. package/src/sdk/product/useLocalizedVariables.ts +2 -2
  216. package/src/sdk/product/usePageProductsQuery.ts +8 -8
  217. package/src/sdk/product/useProductGalleryQuery.ts +32 -3
  218. package/src/sdk/product/useProductsPrefetch.ts +4 -4
  219. package/src/sdk/product/useProductsQuery.ts +7 -7
  220. package/src/sdk/search/useSuggestions.ts +48 -16
  221. package/src/sdk/search/useTopSearch.ts +7 -12
  222. package/src/sdk/shipping/index.ts +6 -4
  223. package/src/{components/ui/ShippingSimulation → sdk/shipping}/useShippingSimulation.ts +33 -56
  224. package/src/server/generator/schema.ts +2 -1
  225. package/src/typings/overrides.ts +8 -2
  226. package/src/utils/getCookie.ts +14 -0
  227. package/tsconfig.json +2 -1
  228. package/cypress.json +0 -9
  229. package/generate.sh +0 -71
  230. /package/src/{components/ui/ProductGallery → sdk/search}/useDelayedFacets.ts +0 -0
  231. /package/src/{components/ui/ProductGallery → sdk/search}/useDelayedPagination.ts +0 -0
  232. /package/src/{components/search/Filter → sdk/search}/useFilter.ts +0 -0
@@ -1,6 +1,6 @@
1
1
  import { gql } from '@faststore/graphql-utils'
2
2
  import { useSearch } from '@faststore/sdk'
3
- import { ClientProductsQueryQueryVariables } from '@generated/graphql'
3
+ import { ClientManyProductsQueryQueryVariables } from '@generated/graphql'
4
4
  import { useEffect, useCallback } from 'react'
5
5
  import type { QueryOptions } from '../graphql/useQuery'
6
6
  import { useSWRConfig } from 'swr'
@@ -8,14 +8,14 @@ import { prefetchQuery } from '../graphql/prefetchQuery'
8
8
  import { useLocalizedVariables } from './useLocalizedVariables'
9
9
 
10
10
  export const query = gql`
11
- query ClientProductsQuery(
11
+ query ClientManyProductsQuery(
12
12
  $first: Int!
13
13
  $after: String
14
14
  $sort: StoreSort!
15
15
  $term: String!
16
16
  $selectedFacets: [IStoreSelectedFacet!]!
17
17
  ) {
18
- ...ClientProducts
18
+ ...ClientManyProducts
19
19
  search(
20
20
  first: $first
21
21
  after: $after
@@ -38,7 +38,7 @@ export const query = gql`
38
38
  `
39
39
 
40
40
  export const useProductsQueryPrefetch = (
41
- variables: ClientProductsQueryQueryVariables,
41
+ variables: ClientManyProductsQueryQueryVariables,
42
42
  options?: QueryOptions
43
43
  ) => {
44
44
  const localizedVariables = useLocalizedVariables(variables)
@@ -1,8 +1,8 @@
1
1
  import { gql } from '@faststore/graphql-utils'
2
2
 
3
3
  import type {
4
- ClientProductsQueryQuery,
5
- ClientProductsQueryQueryVariables,
4
+ ClientManyProductsQueryQuery,
5
+ ClientManyProductsQueryQueryVariables,
6
6
  } from '@generated/graphql'
7
7
 
8
8
  import type { QueryOptions } from '../graphql/useQuery'
@@ -10,14 +10,14 @@ import { useQuery } from '../graphql/useQuery'
10
10
  import { useLocalizedVariables } from './useLocalizedVariables'
11
11
 
12
12
  export const query = gql`
13
- query ClientProductsQuery(
13
+ query ClientManyProductsQuery(
14
14
  $first: Int!
15
15
  $after: String
16
16
  $sort: StoreSort!
17
17
  $term: String!
18
18
  $selectedFacets: [IStoreSelectedFacet!]!
19
19
  ) {
20
- ...ClientProducts
20
+ ...ClientManyProducts
21
21
  search(
22
22
  first: $first
23
23
  after: $after
@@ -43,14 +43,14 @@ export const query = gql`
43
43
  * Use this hook for fetching a list of products, like shelves and tiles
44
44
  */
45
45
  export const useProductsQuery = (
46
- variables: Partial<ClientProductsQueryQueryVariables>,
46
+ variables: Partial<ClientManyProductsQueryQueryVariables>,
47
47
  options?: QueryOptions
48
48
  ) => {
49
49
  const localizedVariables = useLocalizedVariables(variables)
50
50
 
51
51
  const { data } = useQuery<
52
- ClientProductsQueryQuery,
53
- ClientProductsQueryQueryVariables
52
+ ClientManyProductsQueryQuery,
53
+ ClientManyProductsQueryQueryVariables
54
54
  >(query, localizedVariables, {
55
55
  fallbackData: null,
56
56
  suspense: true,
@@ -1,20 +1,23 @@
1
- import { gql } from '@faststore/graphql-utils'
1
+ import { useMemo } from 'react'
2
2
 
3
+ import { sendAnalyticsEvent } from '@faststore/sdk'
4
+ import { gql } from '@faststore/graphql-utils'
3
5
  import { useQuery } from 'src/sdk/graphql/useQuery'
6
+
4
7
  import type {
5
- SearchSuggestionsQueryQuery as Query,
6
- SearchSuggestionsQueryQueryVariables as Variables,
8
+ ClientSearchSuggestionsQueryQuery as Query,
9
+ ClientSearchSuggestionsQueryQueryVariables as Variables,
7
10
  } from '@generated/graphql'
11
+ import type { IntelligentSearchQueryEvent } from '../analytics/types'
8
12
 
9
13
  import { useSession } from '../session'
10
14
 
11
- const MAX_SUGGESTIONS = 5
12
-
13
15
  const query = gql`
14
- query SearchSuggestionsQuery(
16
+ query ClientSearchSuggestionsQuery(
15
17
  $term: String!
16
18
  $selectedFacets: [IStoreSelectedFacet!]
17
19
  ) {
20
+ ...ClientSearchSuggestions
18
21
  search(first: 5, term: $term, selectedFacets: $selectedFacets) {
19
22
  suggestions {
20
23
  terms {
@@ -24,25 +27,54 @@ const query = gql`
24
27
  ...ProductSummary_product
25
28
  }
26
29
  }
30
+ products {
31
+ pageInfo {
32
+ totalCount
33
+ }
34
+ }
35
+ metadata {
36
+ ...SearchEvent_metadata
37
+ }
27
38
  }
28
39
  }
29
40
  `
30
41
 
31
- function useSuggestions(term: string, limit: number = MAX_SUGGESTIONS) {
42
+ function useSuggestions(term: string) {
32
43
  const { channel, locale } = useSession()
33
44
 
34
- const { data, error } = useQuery<Query, Variables>(query, {
35
- term,
36
- selectedFacets: [
37
- { key: 'channel', value: channel ?? '' },
38
- { key: 'locale', value: locale },
39
- ],
45
+ const variables = useMemo(
46
+ () => ({
47
+ term,
48
+ selectedFacets: [
49
+ { key: 'channel', value: channel ?? '' },
50
+ { key: 'locale', value: locale },
51
+ ],
52
+ }),
53
+ [term, locale, channel]
54
+ )
55
+ const { data, error } = useQuery<Query, Variables>(query, variables, {
56
+ onSuccess: (callbackData) => {
57
+ if (callbackData && term) {
58
+ sendAnalyticsEvent<IntelligentSearchQueryEvent>({
59
+ name: 'intelligent_search_query',
60
+ params: {
61
+ locale,
62
+ term,
63
+ url: window.location.href,
64
+ logicalOperator:
65
+ callbackData.search.metadata?.logicalOperator ?? 'and',
66
+ isTermMisspelled:
67
+ callbackData.search.metadata?.isTermMisspelled ?? false,
68
+ totalCount: callbackData.search.products.pageInfo.totalCount,
69
+ },
70
+ })
71
+ }
72
+ },
40
73
  })
41
74
 
42
75
  return {
43
- terms: (data?.search.suggestions.terms ?? []).slice(0, limit),
44
- products: (data?.search.suggestions.products ?? []).slice(0, limit),
45
- isLoading: !error && !data,
76
+ data,
77
+ error,
46
78
  }
47
79
  }
48
80
 
@@ -2,20 +2,18 @@ import { gql } from '@faststore/graphql-utils'
2
2
 
3
3
  import { useQuery } from 'src/sdk/graphql/useQuery'
4
4
  import type {
5
- StoreSuggestionTerm,
6
- SearchSuggestionsQueryQuery as Query,
7
- SearchSuggestionsQueryQueryVariables as Variables,
5
+ ClientSearchSuggestionsQueryQuery as Query,
6
+ ClientSearchSuggestionsQueryQueryVariables as Variables,
8
7
  } from '@generated/graphql'
9
8
 
10
9
  import { useSession } from '../session'
11
10
 
12
- const MAX_TOP_SEARCH_TERMS = 5
13
-
14
11
  const query = gql`
15
- query TopSearchSuggestionsQuery(
12
+ query ClientTopSearchSuggestionsQuery(
16
13
  $term: String!
17
14
  $selectedFacets: [IStoreSelectedFacet!]
18
15
  ) {
16
+ ...ClientTopSearchSuggestions
19
17
  search(first: 5, term: $term, selectedFacets: $selectedFacets) {
20
18
  suggestions {
21
19
  terms {
@@ -26,10 +24,7 @@ const query = gql`
26
24
  }
27
25
  `
28
26
 
29
- function useTopSearch(
30
- initialTerms: StoreSuggestionTerm[] = [],
31
- limit: number = MAX_TOP_SEARCH_TERMS
32
- ) {
27
+ function useTopSearch() {
33
28
  const { channel, locale } = useSession()
34
29
 
35
30
  const { data, error } = useQuery<Query, Variables>(query, {
@@ -41,8 +36,8 @@ function useTopSearch(
41
36
  })
42
37
 
43
38
  return {
44
- terms: (data?.search.suggestions.terms ?? initialTerms).slice(0, limit),
45
- isLoading: !error && !data,
39
+ data,
40
+ error,
46
41
  }
47
42
  }
48
43
 
@@ -2,18 +2,19 @@ import type { IShippingItem } from '@faststore/api'
2
2
  import { gql } from '@faststore/graphql-utils'
3
3
 
4
4
  import type {
5
- ShippingSimulationQueryQuery as Query,
6
- ShippingSimulationQueryQueryVariables as Variables,
5
+ ClientShippingSimulationQueryQuery as Query,
6
+ ClientShippingSimulationQueryQueryVariables as Variables,
7
7
  } from '@generated/graphql'
8
8
 
9
9
  import { request } from '../graphql/request'
10
10
 
11
11
  const query = gql`
12
- query ShippingSimulationQuery(
12
+ query ClientShippingSimulationQuery(
13
13
  $postalCode: String!
14
14
  $country: String!
15
15
  $items: [IShippingItem!]!
16
16
  ) {
17
+ ...ClientShippingSimulation
17
18
  shipping(items: $items, postalCode: $postalCode, country: $country) {
18
19
  logisticsInfo {
19
20
  slas {
@@ -32,6 +33,7 @@ const query = gql`
32
33
  address {
33
34
  city
34
35
  neighborhood
36
+ state
35
37
  }
36
38
  }
37
39
  }
@@ -54,7 +56,7 @@ export const getShippingSimulation = async ({
54
56
  country,
55
57
  })
56
58
 
57
- return data.shipping
59
+ return data
58
60
  }
59
61
 
60
62
  export default getShippingSimulation
@@ -1,6 +1,8 @@
1
1
  import type { ChangeEvent } from 'react'
2
- import { useCallback, useEffect, useReducer } from 'react'
3
- import { ShippingSimulationProps as UIShippingSimulationProps } from '@faststore/components'
2
+ import { useCallback, useEffect, useReducer, useRef } from 'react'
3
+ import { ClientShippingSimulationQueryQuery } from '@generated/graphql'
4
+ import getShippingSimulation from '.'
5
+ import { useSession } from '../session'
4
6
 
5
7
  export interface ProductShippingInfo {
6
8
  id: string
@@ -14,14 +16,9 @@ type InputProps = {
14
16
  errorMessage?: string
15
17
  }
16
18
 
17
- type ShippingSimulationProps = {
18
- location?: string
19
- options?: UIShippingSimulationProps['options']
20
- }
21
-
22
19
  type State = {
23
20
  input: InputProps
24
- shippingSimulation: ShippingSimulationProps
21
+ shippingSimulation?: ClientShippingSimulationQueryQuery['shipping']
25
22
  }
26
23
 
27
24
  type Action =
@@ -41,17 +38,15 @@ type Action =
41
38
  type: 'clear'
42
39
  }
43
40
 
44
- const createEmptySimulation = () => ({
45
- input: {
46
- postalCode: '',
47
- displayClearButton: false,
48
- errorMessage: '',
49
- },
50
- shippingSimulation: {
51
- location: '',
52
- options: [],
53
- },
54
- })
41
+ const createEmptySimulation = () =>
42
+ ({
43
+ input: {
44
+ postalCode: '',
45
+ displayClearButton: false,
46
+ errorMessage: '',
47
+ },
48
+ shippingSimulation: undefined,
49
+ } as State)
55
50
 
56
51
  const reducer = (state: State, action: Action) => {
57
52
  const { type } = action
@@ -104,38 +99,31 @@ const reducer = (state: State, action: Action) => {
104
99
  }
105
100
  }
106
101
 
107
- export type FetchShippingSimulation = (
108
- shippingItem: ProductShippingInfo,
109
- country: string,
110
- postalCode: string
111
- ) => Promise<[string, UIShippingSimulationProps['options']]>
112
-
113
- export const useShippingSimulation = (
114
- shippingItem: ProductShippingInfo,
115
- fetchShippingSimulationFn: FetchShippingSimulation,
116
- sessionPostalCode: string,
117
- country: string
118
- ) => {
102
+ export const useShippingSimulation = (shippingItem: ProductShippingInfo) => {
119
103
  const [{ input, shippingSimulation }, dispatch] = useReducer(
120
104
  reducer,
121
105
  null,
122
106
  createEmptySimulation
123
107
  )
124
108
 
109
+ const { country, postalCode: sessionPostalCode } = useSession()
125
110
  const { postalCode: shippingPostalCode } = input
111
+ const shippingPostalCodeRef = useRef(shippingPostalCode)
126
112
 
127
113
  useEffect(() => {
128
- if (!sessionPostalCode || shippingPostalCode) {
114
+ const shouldFetch = sessionPostalCode && !shippingPostalCodeRef.current
115
+ if (!shouldFetch) {
129
116
  return
130
117
  }
131
118
 
132
119
  // Use sessionPostalCode if there is no shippingPostalCode
133
120
  async function fetchShipping() {
134
- const [location, options] = await fetchShippingSimulationFn(
135
- shippingItem,
121
+ const data = await getShippingSimulation({
136
122
  country,
137
- sessionPostalCode ?? ''
138
- )
123
+ postalCode: sessionPostalCode ?? '',
124
+ items: [shippingItem],
125
+ })
126
+ const shippingSimulation = data.shipping
139
127
 
140
128
  dispatch({
141
129
  type: 'update',
@@ -145,30 +133,22 @@ export const useShippingSimulation = (
145
133
  displayClearButton: true,
146
134
  errorMessage: '',
147
135
  },
148
- shippingSimulation: {
149
- location,
150
- options,
151
- },
136
+ shippingSimulation,
152
137
  },
153
138
  })
154
139
  }
155
140
 
156
141
  fetchShipping()
157
- }, [
158
- country,
159
- fetchShippingSimulationFn,
160
- sessionPostalCode,
161
- shippingItem,
162
- shippingPostalCode,
163
- ])
142
+ }, [country, sessionPostalCode, shippingItem])
164
143
 
165
144
  const handleSubmit = useCallback(async () => {
166
145
  try {
167
- const [location, options] = await fetchShippingSimulationFn(
168
- shippingItem,
146
+ const data = await getShippingSimulation({
169
147
  country,
170
- shippingPostalCode ?? ''
171
- )
148
+ postalCode: shippingPostalCode ?? '',
149
+ items: [shippingItem],
150
+ })
151
+ const shippingSimulation = data.shipping
172
152
 
173
153
  dispatch({
174
154
  type: 'update',
@@ -177,10 +157,7 @@ export const useShippingSimulation = (
177
157
  displayClearButton: true,
178
158
  errorMessage: '',
179
159
  },
180
- shippingSimulation: {
181
- location,
182
- options,
183
- },
160
+ shippingSimulation,
184
161
  },
185
162
  })
186
163
  } catch (error) {
@@ -192,7 +169,7 @@ export const useShippingSimulation = (
192
169
  },
193
170
  })
194
171
  }
195
- }, [country, fetchShippingSimulationFn, shippingItem, shippingPostalCode])
172
+ }, [country, shippingItem, shippingPostalCode])
196
173
 
197
174
  const handleOnInput = useCallback((e: ChangeEvent<HTMLInputElement>) => {
198
175
  const currentValue = e.currentTarget.value
@@ -1,3 +1,4 @@
1
+ import path from 'path'
1
2
  import { writeFileSync } from 'fs-extra'
2
3
  import { getSchema, getTypeDefs } from '@faststore/api'
3
4
  import { printSchemaWithDirectives } from '@graphql-tools/utils'
@@ -69,7 +70,7 @@ export const getMergedSchema = (): GraphQLSchema =>
69
70
  export function writeGraphqlSchemaFile(apiSchema: GraphQLSchema) {
70
71
  try {
71
72
  writeFileSync(
72
- [process.cwd(), '@generated', 'graphql', 'schema.graphql'].join('/'),
73
+ path.join(process.cwd(), '@generated', 'graphql', 'schema.graphql'),
73
74
  printSchemaWithDirectives(apiSchema)
74
75
  )
75
76
 
@@ -13,7 +13,7 @@ import type {
13
13
  IconButtonProps,
14
14
  IconProps,
15
15
  ImageGalleryProps,
16
- ImageZoomProps,
16
+ ImageGalleryViewerProps,
17
17
  InputFieldProps,
18
18
  LinkButtonProps,
19
19
  NavbarButtonsProps,
@@ -40,6 +40,7 @@ import type {
40
40
  ComponentOverrideDefinition,
41
41
  SectionOverrideDefinition,
42
42
  } from './overrideDefinitionUtils'
43
+ import { NewsletterAddendumProps } from 'src/components/ui/Newsletter/NewsletterAddendum'
43
44
 
44
45
  export type SectionOverride =
45
46
  | AlertOverrideDefinition
@@ -164,6 +165,7 @@ export type NewsletterOverrideDefinition = SectionOverrideDefinition<
164
165
  Omit<InputFieldProps, 'inputRef'>
165
166
  >
166
167
  Button: ComponentOverrideDefinition<ButtonProps, ButtonProps>
168
+ __experimentalNewsletterAddendum: ComponentOverrideDefinition<NewsletterAddendumProps, NewsletterAddendumProps>
167
169
  }
168
170
  >
169
171
 
@@ -197,10 +199,14 @@ export type ProductDetailsOverrideDefinition = SectionOverrideDefinition<
197
199
  ImageGalleryProps,
198
200
  ImageGalleryProps
199
201
  >
200
- ImageZoom: ComponentOverrideDefinition<ImageZoomProps, ImageZoomProps>
202
+ ImageGalleryViewer: ComponentOverrideDefinition<
203
+ ImageGalleryViewerProps,
204
+ ImageGalleryViewerProps
205
+ >
201
206
  __experimentalImageGalleryImage: ComponentOverrideDefinition<any, any>
202
207
  __experimentalImageGallery: ComponentOverrideDefinition<any, any>
203
208
  __experimentalShippingSimulation: ComponentOverrideDefinition<any, any>
209
+ __experimentalNotAvailableButton: ComponentOverrideDefinition<any, any>
204
210
  }
205
211
  >
206
212
 
@@ -0,0 +1,14 @@
1
+ export function getCookie(name: string): string | undefined {
2
+ const cookieString = decodeURIComponent(document.cookie)
3
+ const cookies = cookieString.split(';')
4
+
5
+ for (const cookie of cookies) {
6
+ const [cookieName, cookieValue] = cookie.trim().split('=')
7
+
8
+ if (cookieName === name) {
9
+ return cookieValue
10
+ }
11
+ }
12
+
13
+ return undefined // Cookie not found
14
+ }
package/tsconfig.json CHANGED
@@ -13,7 +13,8 @@
13
13
  "allowJs": true,
14
14
  "paths": {
15
15
  "src/*": ["src/*"],
16
- "@generated/*": ["@generated/*"]
16
+ "@generated/*": ["@generated/*"],
17
+ "@faststore/core/experimental": ["src/experimental/index.ts"]
17
18
  },
18
19
  "forceConsistentCasingInFileNames": true,
19
20
  "strict": false,
package/cypress.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "baseUrl": "http://localhost:3000/",
3
- "retries": 0,
4
- "video": true,
5
- "trashAssetsBeforeRuns": true,
6
- "screenshotOnRunFailure": true,
7
- "viewportWidth": 1000,
8
- "viewportHeight": 600
9
- }
package/generate.sh DELETED
@@ -1,71 +0,0 @@
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}"