@faststore/core 2.2.13 → 2.2.15

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 (96) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/build-manifest.json +36 -36
  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/next-server.js.nft.json +1 -1
  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/next-server.js.nft.json +1 -1
  12. package/.next/prerender-manifest.json +1 -1
  13. package/.next/required-server-files.json +1 -1
  14. package/.next/routes-manifest.json +1 -1
  15. package/.next/server/chunks/390.js +2 -2
  16. package/.next/server/chunks/398.js +2 -2
  17. package/.next/server/chunks/732.js +2 -2
  18. package/.next/server/chunks/74.js +194 -92
  19. package/.next/server/chunks/863.js +2 -2
  20. package/.next/server/chunks/979.js +6 -6
  21. package/.next/server/middleware-build-manifest.js +1 -1
  22. package/.next/server/pages/404.js.nft.json +1 -1
  23. package/.next/server/pages/500.js.nft.json +1 -1
  24. package/.next/server/pages/[...slug].js.nft.json +1 -1
  25. package/.next/server/pages/[slug]/p.js +2 -2
  26. package/.next/server/pages/[slug]/p.js.nft.json +1 -1
  27. package/.next/server/pages/_app.js.nft.json +1 -1
  28. package/.next/server/pages/account.js.nft.json +1 -1
  29. package/.next/server/pages/api/graphql.js.nft.json +1 -1
  30. package/.next/server/pages/checkout.js.nft.json +1 -1
  31. package/.next/server/pages/en-US/404.html +2 -2
  32. package/.next/server/pages/en-US/404.json +1 -1
  33. package/.next/server/pages/en-US/500.html +2 -2
  34. package/.next/server/pages/en-US/500.json +1 -1
  35. package/.next/server/pages/en-US/account.html +2 -2
  36. package/.next/server/pages/en-US/account.json +1 -1
  37. package/.next/server/pages/en-US/checkout.html +2 -2
  38. package/.next/server/pages/en-US/checkout.json +1 -1
  39. package/.next/server/pages/en-US/login.html +2 -2
  40. package/.next/server/pages/en-US/login.json +1 -1
  41. package/.next/server/pages/en-US/s.html +2 -2
  42. package/.next/server/pages/en-US/s.json +1 -1
  43. package/.next/server/pages/en-US.html +3 -3
  44. package/.next/server/pages/en-US.json +1 -1
  45. package/.next/server/pages/index.js.nft.json +1 -1
  46. package/.next/server/pages/login.js.nft.json +1 -1
  47. package/.next/server/pages/s.js +0 -1
  48. package/.next/server/pages/s.js.nft.json +1 -1
  49. package/.next/server/pages-manifest.json +5 -5
  50. package/.next/static/cFoZnnZTCNBP27r9ASmWF/_buildManifest.js +1 -0
  51. package/.next/static/chunks/{400-7ce14b0f942135d1.js → 400-a09ccc622ec96daa.js} +1 -1
  52. package/.next/static/chunks/469-7259b855711d4ad3.js +1 -0
  53. package/.next/static/chunks/{783-864ba18fdcdc2649.js → 783-a67df4e98c1ac27b.js} +1 -1
  54. package/.next/static/chunks/pages/{404-d186c22d910fecbb.js → 404-6763ce07878a1456.js} +1 -1
  55. package/.next/static/chunks/pages/{500-c6f28e1de16c5aab.js → 500-0f4374f30595d27c.js} +1 -1
  56. package/.next/static/chunks/pages/{[...slug]-c7c8e53be9021135.js → [...slug]-111f89162eff5029.js} +1 -1
  57. package/.next/static/chunks/pages/[slug]/{p-fc8a69c60752c685.js → p-0b6789ab8718bdf0.js} +1 -1
  58. package/.next/static/chunks/pages/{account-46edcd73944d7924.js → account-9eb6fab139286c66.js} +1 -1
  59. package/.next/static/chunks/pages/{checkout-49faa1acf04be10c.js → checkout-7cd7b110c7cf2f10.js} +1 -1
  60. package/.next/static/chunks/pages/{index-5088cf4fabfe4812.js → index-3d5c756be5ce8fc7.js} +1 -1
  61. package/.next/static/chunks/pages/{login-e944d38d65d2eea5.js → login-5fd09e6402f47896.js} +1 -1
  62. package/.next/static/chunks/pages/{s-b8b561b006b5056f.js → s-8e32a9b170819fa9.js} +1 -1
  63. package/.next/static/chunks/{webpack-66a77a46f9162613.js → webpack-bc34484a5f5f8214.js} +1 -1
  64. package/.next/trace +78 -77
  65. package/.turbo/turbo-build.log +7 -7
  66. package/.turbo/turbo-test.log +10 -10
  67. package/index.ts +1 -0
  68. package/package.json +2 -2
  69. package/src/components/cms/GlobalSections.tsx +1 -1
  70. package/src/components/common/Alert/Alert.tsx +3 -1
  71. package/src/components/sections/Alert/Alert.tsx +8 -17
  72. package/src/components/sections/Alert/DefaultComponents.ts +6 -0
  73. package/src/components/sections/Alert/OverriddenDefaultAlert.ts +12 -0
  74. package/src/components/sections/BannerText/Overrides.tsx +3 -3
  75. package/src/components/sections/Breadcrumb/Overrides.tsx +3 -3
  76. package/src/components/sections/EmptyState/Overrides.tsx +3 -3
  77. package/src/components/sections/Hero/Overrides.tsx +3 -3
  78. package/src/components/sections/Navbar/Overrides.tsx +3 -3
  79. package/src/components/sections/Newsletter/Overrides.tsx +3 -3
  80. package/src/components/sections/ProductDetails/Overrides.tsx +3 -3
  81. package/src/components/sections/ProductGallery/Overrides.tsx +3 -3
  82. package/src/components/sections/ProductShelf/Overrides.tsx +3 -3
  83. package/src/components/sections/RegionBar/Overrides.tsx +3 -3
  84. package/src/components/sections/Section/Section.tsx +8 -1
  85. package/src/pages/s.tsx +1 -1
  86. package/src/sdk/overrides/OverrideContext.tsx +27 -0
  87. package/src/sdk/overrides/getOverriddenSection.tsx +70 -0
  88. package/src/{utils → sdk/overrides}/overrides.ts +13 -14
  89. package/src/sdk/overrides/sections.tsx +18 -0
  90. package/src/typings/overrides.ts +25 -68
  91. package/src/typings/overridesDefinition.ts +52 -0
  92. package/.next/static/OJh9lsnAreNh11S0nldSP/_buildManifest.js +0 -1
  93. package/.next/static/chunks/520-5a9ae7339f19a163.js +0 -1
  94. package/src/components/sections/Alert/Overrides.tsx +0 -15
  95. package/src/typings/overrideDefinitionUtils.ts +0 -40
  96. /package/.next/static/{OJh9lsnAreNh11S0nldSP → cFoZnnZTCNBP27r9ASmWF}/_ssgManifest.js +0 -0
@@ -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
  warn - You have enabled experimental feature (scrollRestoration) in next.config.js.
7
7
  warn - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
@@ -20,12 +20,12 @@ info - Compiled successfully
20
20
  info - Collecting page data...
21
21
  info - Generating static pages (0/7)
22
22
  warn - AlertSectionIcon not found. Add a new component for this section or remove it from the CMS
23
+ warn - AlertSectionIcon not found. Add a new component for this section or remove it from the CMS
23
24
  info - Generating static pages (1/7)
24
25
  warn - AlertSectionIcon not found. Add a new component for this section or remove it from the CMS
25
26
  warn - AlertSectionIcon not found. Add a new component for this section or remove it from the CMS
26
27
  info - Generating static pages (3/7)
27
28
  warn - AlertSectionIcon not found. Add a new component for this section or remove it from the CMS
28
- warn - AlertSectionIcon not found. Add a new component for this section or remove it from the CMS
29
29
  info - Generating static pages (5/7)
30
30
  warn - AlertSectionIcon not found. Add a new component for this section or remove it from the CMS
31
31
  warn - AlertSectionIcon not found. Add a new component for this section or remove it from the CMS
@@ -40,20 +40,20 @@ Route (pages) Size First Load JS
40
40
  ├ ● /[slug]/p 10.9 kB 135 kB
41
41
  ├ └ css/d7bbfbd552f407e9.css 11.3 kB
42
42
  ├ ○ /404 1.19 kB 111 kB
43
- ├ ● /500 1.2 kB 111 kB
44
- ├ ● /account 670 B 110 kB
43
+ ├ ● /500 1.21 kB 111 kB
44
+ ├ ● /account 669 B 111 kB
45
45
  ├ λ /api/graphql 0 B 78.6 kB
46
46
  ├ λ /api/health/live 0 B 78.6 kB
47
47
  ├ λ /api/health/ready 0 B 78.6 kB
48
48
  ├ λ /api/preview 0 B 78.6 kB
49
- ├ ● /checkout 657 B 110 kB
49
+ ├ ● /checkout 657 B 111 kB
50
50
  ├ ● /login 1.14 kB 111 kB
51
- └ ● /s 4.58 kB 125 kB
51
+ └ ● /s 4.57 kB 125 kB
52
52
  + First Load JS shared by all 81.7 kB
53
53
  ├ chunks/framework-dfd14d7ce6600b03.js 45.3 kB
54
54
  ├ chunks/main-e4e873ee741162eb.js 24.1 kB
55
55
  ├ chunks/pages/_app-48d56037a2534a44.js 6.99 kB
56
- ├ chunks/webpack-66a77a46f9162613.js 2.25 kB
56
+ ├ chunks/webpack-bc34484a5f5f8214.js 2.25 kB
57
57
  └ css/5d1f64b61ea581f4.css 3.06 kB
58
58
 
59
59
  λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
@@ -1,25 +1,25 @@
1
1
  $ tsdx test
2
2
  ts-jest[versions] (WARN) Version 29.1.0 of jest installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=25.0.0 <26.0.0). Please do not report issues in ts-jest if you are using unsupported versions.
3
3
  ts-jest[versions] (WARN) Version 4.9.4 of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=3.4.0 <4.0.0). Please do not report issues in ts-jest if you are using unsupported versions.
4
- PASS test/server/index.test.ts (9.304s)
4
+ PASS test/server/index.test.ts (6.422s)
5
5
  FastStore GraphQL Layer
6
6
  @faststore/api
7
- ✓ should return a valid GraphQL schema (6ms)
8
- ✓ should return a valid GraphQL schema contain all expected types (9ms)
9
- ✓ should return a valid GraphQL schema contain all expected queries (9ms)
10
- ✓ should return a valid GraphQL schema contain all expected mutations (1ms)
7
+ ✓ should return a valid GraphQL schema (5ms)
8
+ ✓ should return a valid GraphQL schema contain all expected types (5ms)
9
+ ✓ should return a valid GraphQL schema contain all expected queries (2ms)
10
+ ✓ should return a valid GraphQL schema contain all expected mutations
11
11
  VTEX API Extension
12
- ✓ getTypeDefsFromFolder function should return an Array (7ms)
12
+ ✓ getTypeDefsFromFolder function should return an Array (11ms)
13
13
  Third Party API Extension
14
14
  ✓ getTypeDefsFromFolder function should return an Array (5ms)
15
15
  Final Schema after merging
16
- ✓ should return a valid merged GraphQL schema (34ms)
16
+ ✓ should return a valid merged GraphQL schema (26ms)
17
17
  Envelop
18
- ✓ should exist with its plugins (34ms)
19
- ✓ should handle options and execute (463ms)
18
+ ✓ should exist with its plugins (25ms)
19
+ ✓ should handle options and execute (324ms)
20
20
 
21
21
  Test Suites: 1 passed, 1 total
22
22
  Tests: 9 passed, 9 total
23
23
  Snapshots: 0 total
24
- Time: 10.117s
24
+ Time: 6.854s
25
25
  Ran all test suites.
package/index.ts CHANGED
@@ -17,3 +17,4 @@ export type {
17
17
  export { useProductsQuery } from './src/sdk/product/useProductsQuery'
18
18
 
19
19
  export * from './src/typings/overrides'
20
+ export { getOverriddenSection } from './src/sdk/overrides/getOverriddenSection'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faststore/core",
3
- "version": "2.2.13",
3
+ "version": "2.2.15",
4
4
  "license": "MIT",
5
5
  "browserslist": "supports es6-module and not dead",
6
6
  "exports": {
@@ -129,5 +129,5 @@
129
129
  "msw": {
130
130
  "workerDirectory": "public"
131
131
  },
132
- "gitHead": "e86acedc75c7b8d3a1e5321f8c05b3b9bcf9b450"
132
+ "gitHead": "39ef3562d3460aa5c3cdc1aaac663829d303a050"
133
133
  }
@@ -7,7 +7,7 @@ import { PageContentType, getPage } from 'src/server/cms'
7
7
  import Toast from 'src/components/common/Toast'
8
8
  import RenderSections from './RenderSections'
9
9
 
10
- import Alert from 'src/components/sections/Alert'
10
+ import { OverriddenDefaultAlert as Alert } from 'src/components/sections/Alert/OverriddenDefaultAlert'
11
11
  import Footer from 'src/components/sections/Footer'
12
12
  import Navbar from 'src/components/sections/Navbar'
13
13
  import RegionBar from 'src/components/sections/RegionBar'
@@ -7,7 +7,7 @@ import { mark } from 'src/sdk/tests/mark'
7
7
  import Section from 'src/components/sections/Section/Section'
8
8
  import styles from './section.module.scss'
9
9
 
10
- import { Alert as AlertWrapper } from 'src/components/sections/Alert/Overrides'
10
+ import { useOverrideComponents } from 'src/sdk/overrides/OverrideContext'
11
11
 
12
12
  export interface AlertProps extends UIAlertProps {
13
13
  /**
@@ -18,11 +18,13 @@ export interface AlertProps extends UIAlertProps {
18
18
  */
19
19
  content?: ReactNode
20
20
  }
21
+
21
22
  function Alert({
22
23
  content,
23
24
  children,
24
25
  ...otherProps
25
26
  }: PropsWithChildren<AlertProps>) {
27
+ const { Alert: AlertWrapper } = useOverrideComponents<'Alert'>()
26
28
  const [displayAlert, setDisplayAlert] = useState(true)
27
29
 
28
30
  const onAlertClose = useCallback(
@@ -1,10 +1,7 @@
1
1
  import { ReactNode } from 'react'
2
2
 
3
3
  import CommonAlert from 'src/components/common/Alert'
4
- import {
5
- Alert as AlertWrapper,
6
- Icon,
7
- } from 'src/components/sections/Alert/Overrides'
4
+ import { useOverrideComponents } from 'src/sdk/overrides/OverrideContext'
8
5
 
9
6
  export interface AlertProps {
10
7
  icon: string
@@ -18,26 +15,20 @@ export interface AlertProps {
18
15
  }
19
16
 
20
17
  // TODO: Change actionPath and actionLabel with Link
21
- function Alert({
22
- icon = Icon.props.name,
23
- content,
24
- link: {
25
- text = AlertWrapper.props.link?.children,
26
- to = AlertWrapper.props.link?.href,
27
- },
28
- dismissible = AlertWrapper.props.dismissible,
29
- }: AlertProps) {
18
+ function Alert({ icon, content, link: { text, to }, dismissible }: AlertProps) {
19
+ const { Alert: AlertWrapper, Icon } = useOverrideComponents<'Alert'>()
20
+
30
21
  return (
31
22
  <CommonAlert
32
- icon={<Icon.Component {...Icon.props} name={icon} />}
23
+ icon={<Icon.Component {...Icon.props} name={icon ?? Icon.props.name} />}
33
24
  {...AlertWrapper.props}
34
25
  link={{
35
26
  ...(AlertWrapper.props.link ?? {}),
36
- children: text,
37
- href: to,
27
+ children: text ?? AlertWrapper.props.link?.children,
28
+ href: to ?? AlertWrapper.props.link?.href,
38
29
  target: AlertWrapper.props.link?.target ?? '_self',
39
30
  }}
40
- dismissible={dismissible}
31
+ dismissible={dismissible ?? AlertWrapper.props.dismissible}
41
32
  >
42
33
  {content}
43
34
  </CommonAlert>
@@ -0,0 +1,6 @@
1
+ import { Alert as UIAlert, Icon as UIIcon } from '@faststore/ui'
2
+
3
+ export const AlertDefaultComponents = {
4
+ Alert: UIAlert,
5
+ Icon: UIIcon,
6
+ } as const
@@ -0,0 +1,12 @@
1
+ import { override } from 'src/customizations/src/components/overrides/Alert'
2
+ import { getOverriddenSection } from 'src/sdk/overrides/getOverriddenSection'
3
+ import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition'
4
+
5
+ /**
6
+ * This component exists to support overrides 1.0
7
+ *
8
+ * This allows users to override the default Alert section present in the Headless CMS
9
+ */
10
+ export const OverriddenDefaultAlert = getOverriddenSection(
11
+ override as SectionOverrideDefinition<'Alert'>
12
+ )
@@ -3,16 +3,16 @@ import {
3
3
  BannerTextContent as UIBannerTextContent,
4
4
  } from '@faststore/ui'
5
5
 
6
- import { getSectionOverrides } from 'src/utils/overrides'
6
+ import { getSectionOverrides } from 'src/sdk/overrides/overrides'
7
7
  import { override } from 'src/customizations/src/components/overrides/BannerText'
8
- import type { BannerTextOverrideDefinition } from 'src/typings/overrides'
8
+ import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition'
9
9
 
10
10
  const { BannerText, BannerTextContent } = getSectionOverrides(
11
11
  {
12
12
  BannerText: UIBannerText,
13
13
  BannerTextContent: UIBannerTextContent,
14
14
  },
15
- override as BannerTextOverrideDefinition
15
+ override as SectionOverrideDefinition<'BannerText'>
16
16
  )
17
17
 
18
18
  export { BannerText, BannerTextContent }
@@ -1,15 +1,15 @@
1
1
  import { Breadcrumb as UIBreadcrumb, Icon as UIIcon } from '@faststore/ui'
2
2
 
3
- import { getSectionOverrides } from 'src/utils/overrides'
3
+ import { getSectionOverrides } from 'src/sdk/overrides/overrides'
4
4
  import { override } from 'src/customizations/src/components/overrides/Breadcrumb'
5
- import type { BreadcrumbOverrideDefinition } from 'src/typings/overrides'
5
+ import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition'
6
6
 
7
7
  const { Breadcrumb, Icon } = getSectionOverrides(
8
8
  {
9
9
  Breadcrumb: UIBreadcrumb,
10
10
  Icon: UIIcon,
11
11
  },
12
- override as BreadcrumbOverrideDefinition
12
+ override as SectionOverrideDefinition<'Breadcrumb'>
13
13
  )
14
14
 
15
15
  export { Breadcrumb, Icon }
@@ -1,14 +1,14 @@
1
1
  import { EmptyState as UIEmptyState } from '@faststore/ui'
2
2
 
3
- import { getSectionOverrides } from 'src/utils/overrides'
3
+ import { getSectionOverrides } from 'src/sdk/overrides/overrides'
4
4
  import { override } from 'src/customizations/src/components/overrides/EmptyState'
5
- import type { EmptyStateOverrideDefinition } from 'src/typings/overrides'
5
+ import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition'
6
6
 
7
7
  const { EmptyState } = getSectionOverrides(
8
8
  {
9
9
  EmptyState: UIEmptyState,
10
10
  },
11
- override as EmptyStateOverrideDefinition
11
+ override as SectionOverrideDefinition<'EmptyState'>
12
12
  )
13
13
 
14
14
  export { EmptyState }
@@ -4,9 +4,9 @@ import {
4
4
  HeroHeader as UIHeroHeader,
5
5
  } from '@faststore/ui'
6
6
 
7
- import { getSectionOverrides } from 'src/utils/overrides'
7
+ import { getSectionOverrides } from 'src/sdk/overrides/overrides'
8
8
  import { override } from 'src/customizations/src/components/overrides/Hero'
9
- import type { HeroOverrideDefinition } from 'src/typings/overrides'
9
+ import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition'
10
10
 
11
11
  const { Hero, HeroImage, HeroHeader } = getSectionOverrides(
12
12
  {
@@ -14,7 +14,7 @@ const { Hero, HeroImage, HeroHeader } = getSectionOverrides(
14
14
  HeroImage: UIHeroImage,
15
15
  HeroHeader: UIHeroHeader,
16
16
  },
17
- override as HeroOverrideDefinition
17
+ override as SectionOverrideDefinition<'Hero'>
18
18
  )
19
19
 
20
20
  export { Hero, HeroImage, HeroHeader }
@@ -12,9 +12,9 @@ import {
12
12
  IconButton as UIIconButton,
13
13
  } from '@faststore/ui'
14
14
 
15
- import { getSectionOverrides } from 'src/utils/overrides'
15
+ import { getSectionOverrides } from 'src/sdk/overrides/overrides'
16
16
  import { override } from 'src/customizations/src/components/overrides/Navbar'
17
- import type { NavbarOverrideDefinition } from 'src/typings/overrides'
17
+ import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition'
18
18
 
19
19
  const {
20
20
  Navbar,
@@ -42,7 +42,7 @@ const {
42
42
  NavbarButtons: UINavbarButtons,
43
43
  IconButton: UIIconButton,
44
44
  },
45
- override as NavbarOverrideDefinition
45
+ override as SectionOverrideDefinition<'Navbar'>
46
46
  )
47
47
 
48
48
  export {
@@ -5,9 +5,9 @@ import {
5
5
  } from '@faststore/ui'
6
6
  import { NewsletterAddendum } from 'src/components/ui/Newsletter/NewsletterAddendum'
7
7
 
8
- import { getSectionOverrides } from 'src/utils/overrides'
8
+ import { getSectionOverrides } from 'src/sdk/overrides/overrides'
9
9
  import { override } from 'src/customizations/src/components/overrides/Newsletter'
10
- import type { NewsletterOverrideDefinition } from 'src/typings/overrides'
10
+ import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition'
11
11
 
12
12
  const {
13
13
  ToastIconSuccess,
@@ -27,7 +27,7 @@ const {
27
27
  Button: UIButton,
28
28
  __experimentalNewsletterAddendum: NewsletterAddendum,
29
29
  },
30
- override as NewsletterOverrideDefinition
30
+ override as SectionOverrideDefinition<'Newsletter'>
31
31
  )
32
32
 
33
33
  export {
@@ -16,9 +16,9 @@ import LocalShippingSimulation from 'src/components/ui/ShippingSimulation/Shippi
16
16
  import { Image } from 'src/components/ui/Image'
17
17
  import LocalNotAvailableButton from 'src/components/product/NotAvailableButton'
18
18
 
19
- import { getSectionOverrides } from 'src/utils/overrides'
19
+ import { getSectionOverrides } from 'src/sdk/overrides/overrides'
20
20
  import { override } from 'src/customizations/src/components/overrides/ProductDetails'
21
- import type { ProductDetailsOverrideDefinition } from 'src/typings/overrides'
21
+ import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition'
22
22
 
23
23
  const {
24
24
  ProductTitle,
@@ -52,7 +52,7 @@ const {
52
52
  __experimentalShippingSimulation: LocalShippingSimulation,
53
53
  __experimentalNotAvailableButton: LocalNotAvailableButton,
54
54
  },
55
- override as ProductDetailsOverrideDefinition
55
+ override as SectionOverrideDefinition<'ProductDetails'>
56
56
  )
57
57
 
58
58
  export {
@@ -13,9 +13,9 @@ const FilterSlider = lazy(
13
13
  () => import('src/components/search/Filter/FilterSlider')
14
14
  )
15
15
 
16
- import { getSectionOverrides } from 'src/utils/overrides'
16
+ import { getSectionOverrides } from 'src/sdk/overrides/overrides'
17
17
  import { override } from 'src/customizations/src/components/overrides/ProductGallery'
18
- import type { ProductGalleryOverrideDefinition } from 'src/typings/overrides'
18
+ import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition'
19
19
 
20
20
  const {
21
21
  MobileFilterButton,
@@ -43,7 +43,7 @@ const {
43
43
  __experimentalFilterSlider: FilterSlider,
44
44
  __experimentalProductCard: ProductCard,
45
45
  },
46
- override as ProductGalleryOverrideDefinition
46
+ override as SectionOverrideDefinition<'ProductGallery'>
47
47
  )
48
48
 
49
49
  export {
@@ -3,9 +3,9 @@ import { ProductShelf as UIProductShelf } from '@faststore/ui'
3
3
  import ProductCard from 'src/components/product/ProductCard'
4
4
  import Carousel from 'src/components/ui/Carousel'
5
5
 
6
- import { getSectionOverrides } from 'src/utils/overrides'
6
+ import { getSectionOverrides } from 'src/sdk/overrides/overrides'
7
7
  import { override } from 'src/customizations/src/components/overrides/ProductShelf'
8
- import type { ProductShelfOverrideDefinition } from 'src/typings/overrides'
8
+ import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition'
9
9
 
10
10
  const { ProductShelf, __experimentalCarousel, __experimentalProductCard } =
11
11
  getSectionOverrides(
@@ -14,7 +14,7 @@ const { ProductShelf, __experimentalCarousel, __experimentalProductCard } =
14
14
  __experimentalCarousel: Carousel,
15
15
  __experimentalProductCard: ProductCard,
16
16
  },
17
- override as ProductShelfOverrideDefinition
17
+ override as SectionOverrideDefinition<'ProductShelf'>
18
18
  )
19
19
 
20
20
  export { ProductShelf, __experimentalCarousel, __experimentalProductCard }
@@ -1,8 +1,8 @@
1
1
  import { RegionBar as UIRegionBar, Icon as UIIcon } from '@faststore/ui'
2
2
 
3
- import { getSectionOverrides } from 'src/utils/overrides'
3
+ import { getSectionOverrides } from 'src/sdk/overrides/overrides'
4
4
  import { override } from 'src/customizations/src/components/overrides/RegionBar'
5
- import type { RegionBarOverrideDefinition } from 'src/typings/overrides'
5
+ import type { SectionOverrideDefinition } from 'src/typings/overridesDefinition'
6
6
 
7
7
  const { RegionBar, LocationIcon, ButtonIcon } = getSectionOverrides(
8
8
  {
@@ -10,7 +10,7 @@ const { RegionBar, LocationIcon, ButtonIcon } = getSectionOverrides(
10
10
  LocationIcon: UIIcon,
11
11
  ButtonIcon: UIIcon,
12
12
  },
13
- override as RegionBarOverrideDefinition
13
+ override as SectionOverrideDefinition<'RegionBar'>
14
14
  )
15
15
 
16
16
  export { RegionBar, LocationIcon, ButtonIcon }
@@ -1,6 +1,8 @@
1
1
  import { forwardRef } from 'react'
2
2
  import type { DetailedHTMLProps, HTMLAttributes } from 'react'
3
3
 
4
+ import { useOverrideClassName } from 'src/sdk/overrides/OverrideContext'
5
+
4
6
  type BaseProps = DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>
5
7
 
6
8
  type SectionProps = BaseProps & {
@@ -11,10 +13,15 @@ const Section = forwardRef<HTMLDivElement, SectionProps>(function Section(
11
13
  { as, className = '', ...otherProps },
12
14
  ref
13
15
  ) {
16
+ const overrideClassName = useOverrideClassName() ?? ''
14
17
  const Component = as ?? 'section'
15
18
 
16
19
  return (
17
- <Component ref={ref} className={`section ${className}`} {...otherProps} />
20
+ <Component
21
+ ref={ref}
22
+ className={`section ${className} ${overrideClassName}`.trim()}
23
+ {...otherProps}
24
+ />
18
25
  )
19
26
  })
20
27
 
package/src/pages/s.tsx CHANGED
@@ -94,7 +94,7 @@ function Page({ page: searchContentType, globalSections }: Props) {
94
94
  }}
95
95
  />
96
96
 
97
- <UISROnly as="h1" text={title} />
97
+ <UISROnly text={title} />
98
98
 
99
99
  {/*
100
100
  WARNING: Do not import or render components from any
@@ -0,0 +1,27 @@
1
+ import { createContext, useContext } from 'react'
2
+
3
+ import type { OverriddenComponents } from '../../typings/overridesDefinition'
4
+ import type { SectionsOverrides } from '../../typings/overrides'
5
+
6
+ type OverrideContextType<
7
+ SectionName extends keyof SectionsOverrides = keyof SectionsOverrides
8
+ > = {
9
+ className?: string
10
+ components: OverriddenComponents<SectionName>
11
+ }
12
+
13
+ const OverrideContext = createContext<OverrideContextType>(null)
14
+
15
+ export const OverrideProvider = OverrideContext.Provider
16
+
17
+ export const useOverrideContext = <
18
+ SectionName extends keyof SectionsOverrides = keyof SectionsOverrides
19
+ >() => useContext(OverrideContext) as OverrideContextType<SectionName>
20
+
21
+ export const useOverrideComponents = <
22
+ SectionName extends keyof SectionsOverrides = keyof SectionsOverrides
23
+ >() =>
24
+ useContext(OverrideContext)
25
+ .components as OverrideContextType<SectionName>['components']
26
+
27
+ export const useOverrideClassName = () => useContext(OverrideContext)?.className
@@ -0,0 +1,70 @@
1
+ import type { ComponentProps, ComponentType } from 'react'
2
+
3
+ import { OverrideProvider } from './OverrideContext'
4
+ import { DefaultComponents, Sections } from './sections'
5
+ import { getSectionOverrides } from './overrides'
6
+ import type {
7
+ DefaultSectionComponentsDefinitions,
8
+ OverriddenComponents,
9
+ SectionOverrideDefinition,
10
+ } from '../../typings/overridesDefinition'
11
+ import type { SupportedSectionsOverridesV2 } from '../../typings/overrides'
12
+
13
+ /**
14
+ * This function adds OverrideContext to the tree. It is essential for the compatible sections
15
+ * to consume the components it provides.
16
+ */
17
+ function createOverriddenSection<
18
+ SectionName extends keyof SupportedSectionsOverridesV2
19
+ >({
20
+ Section,
21
+ sectionOverrides,
22
+ className,
23
+ }: {
24
+ /** This type wizardry is here because the props won't behave correctly if done directly: (typeof Sections)[SectionName] */
25
+ Section: ComponentType<ComponentProps<(typeof Sections)[SectionName]>>
26
+ sectionOverrides: OverriddenComponents<SectionName>
27
+ className?: string
28
+ }) {
29
+ const overrideContextValue = { className, components: sectionOverrides }
30
+
31
+ return function OverriddenSection(
32
+ props: React.ComponentProps<typeof Section>
33
+ ) {
34
+ return (
35
+ <OverrideProvider value={overrideContextValue}>
36
+ <Section {...props} />
37
+ </OverrideProvider>
38
+ )
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Accepts override options and returns a React component for the overridden section.
44
+ * The overridden section is based on the options specified in the override definition.
45
+ *
46
+ * @param override An object containing override options.
47
+ * @returns The overridden section of choice
48
+ * @see https://www.faststore.dev/docs/building-sections/overriding-components-and-props
49
+ */
50
+ export function getOverriddenSection<
51
+ SectionName extends keyof SupportedSectionsOverridesV2
52
+ >(override: SectionOverrideDefinition<SectionName>) {
53
+ const defaultComponents = DefaultComponents[
54
+ override.section
55
+ ] as DefaultSectionComponentsDefinitions<SectionName>
56
+
57
+ if (!defaultComponents) {
58
+ throw new Error(
59
+ `Section ${override.section} does not exist. Please provide a valid section name to override.`
60
+ )
61
+ }
62
+
63
+ const sectionOverrides = getSectionOverrides(defaultComponents, override)
64
+
65
+ return createOverriddenSection({
66
+ Section: Sections[override.section],
67
+ sectionOverrides: sectionOverrides,
68
+ className: override.className,
69
+ })
70
+ }
@@ -1,20 +1,19 @@
1
1
  import type {
2
2
  DefaultSectionComponentsDefinitions,
3
3
  ComponentOverrideDefinition,
4
- Merge,
5
- } from 'src/typings/overrideDefinitionUtils'
6
-
7
- import type { SectionOverride } from 'src/typings/overrides'
8
-
9
- export type GetSectionOverridesReturn<SO extends SectionOverride> = {
10
- [Key in keyof SO['components']]: Merge<SO['components'][Key]>
11
- }
12
-
13
- export function getSectionOverrides<SO extends SectionOverride>(
14
- defaultComponents: DefaultSectionComponentsDefinitions<SO>,
15
- override: SO
16
- ): GetSectionOverridesReturn<SO> {
17
- const overriddenComponents = {} as GetSectionOverridesReturn<SO>
4
+ SectionOverrideDefinition,
5
+ OverriddenComponents,
6
+ } from '../../typings/overridesDefinition'
7
+
8
+ import type { SectionsOverrides } from '../../typings/overrides'
9
+
10
+ export function getSectionOverrides<
11
+ SectionName extends keyof SectionsOverrides
12
+ >(
13
+ defaultComponents: DefaultSectionComponentsDefinitions<SectionName>,
14
+ override: SectionOverrideDefinition<SectionName>
15
+ ): OverriddenComponents<SectionName> {
16
+ const overriddenComponents = {} as OverriddenComponents<SectionName>
18
17
 
19
18
  Object.entries(defaultComponents).forEach(([key, value]) => {
20
19
  const componentOverride:
@@ -0,0 +1,18 @@
1
+ import Alert from '../../components/sections/Alert'
2
+
3
+ import type { DefaultSectionComponentsDefinitions } from '../../typings/overridesDefinition'
4
+ import type { SectionsOverrides } from '../../typings/overrides'
5
+ import { AlertDefaultComponents } from '../../components/sections/Alert/DefaultComponents'
6
+
7
+ export const Sections = {
8
+ Alert,
9
+ }
10
+
11
+ export const DefaultComponents: Partial<
12
+ Record<
13
+ keyof SectionsOverrides,
14
+ DefaultSectionComponentsDefinitions<keyof SectionsOverrides>
15
+ >
16
+ > = {
17
+ Alert: AlertDefaultComponents,
18
+ }