@hanzo/commerce 7.2.0 → 7.3.1

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.
@@ -14,7 +14,7 @@ import type {
14
14
  CategoryNode,
15
15
  } from '../../types'
16
16
 
17
- import { useCommerce } from '../../context'
17
+ import { useCommerce } from '../../service/context'
18
18
  import * as pathUtils from '../../service/path-utils'
19
19
  import { getFacetValuesMutator, ObsStringMutator } from '../../util'
20
20
 
@@ -21,7 +21,7 @@ import type {
21
21
  MultiFamilySelectorOptions,
22
22
  } from '../../types'
23
23
 
24
- import { useCommerce } from '../../context'
24
+ import { useCommerce } from '../../service/context'
25
25
  import { getSelectionUISpecifier } from '../../util'
26
26
 
27
27
  import { CarouselItemSelector, ButtonItemSelector } from '../item-selector'
@@ -9,7 +9,7 @@ import { Image } from '@hanzo/ui/primitives'
9
9
  import type { LineItem } from '../../../types'
10
10
  import { formatCurrencyValue } from '../../../util'
11
11
  import AddToCartWidget from '../../add-to-cart-widget'
12
- import { useCommerce } from '../../../context'
12
+ import { useCommerce } from '../../../service/context'
13
13
 
14
14
  const DEF_IMG_SIZE=40
15
15
 
@@ -7,7 +7,7 @@ import { Button, ScrollArea } from '@hanzo/ui/primitives'
7
7
  import { cn } from '@hanzo/ui/util'
8
8
 
9
9
  import type { LineItem } from '../../../types'
10
- import { useCommerce } from '../../../context'
10
+ import { useCommerce } from '../../../service/context'
11
11
  import { sendFBEvent, sendGAEvent } from '../../../util/analytics'
12
12
 
13
13
  import CartLineItem from './cart-line-item'
@@ -2,15 +2,23 @@
2
2
 
3
3
  import { useEffect, useState } from 'react'
4
4
  import { useSearchParams } from 'next/navigation'
5
+ import { observer } from 'mobx-react-lite'
6
+
5
7
  import { useForm } from 'react-hook-form'
6
8
  import * as z from 'zod'
7
9
  import { zodResolver } from '@hookform/resolvers/zod'
8
10
  import { Check } from 'lucide-react'
9
- import { observer } from 'mobx-react-lite'
10
11
 
11
- import { Button, Form, FormControl, FormField, FormItem, Input } from '@hanzo/ui/primitives'
12
+ import {
13
+ Button,
14
+ Form,
15
+ FormControl,
16
+ FormField,
17
+ FormItem,
18
+ Input
19
+ } from '@hanzo/ui/primitives'
12
20
 
13
- import { useCommerce } from '../../../context'
21
+ import { useCommerce } from '../../../service/context'
14
22
  import type { Promo } from '../../../types'
15
23
  import getPromoFromApi from '../../../util/promo-codes'
16
24
 
@@ -6,7 +6,7 @@ import { cn } from '@hanzo/ui/util'
6
6
 
7
7
  import { formatCurrencyValue } from '../../../util'
8
8
  import PromoCode from './promo-code'
9
- import { useCommerce } from '../../../context'
9
+ import { useCommerce } from '../../../service/context'
10
10
 
11
11
  const TotalArea: React.FC<{
12
12
  showPromoCode?: boolean
@@ -9,7 +9,7 @@ import { useForm } from 'react-hook-form'
9
9
  import { Tabs, TabsContent, TabsList, TabsTrigger } from '@hanzo/ui/primitives'
10
10
  import { useAuth } from '@hanzo/auth/service'
11
11
 
12
- import { useCommerce } from '../../../context'
12
+ import { useCommerce } from '../../../service/context'
13
13
  import { sendFBEvent, sendGAEvent } from '../../../util/analytics'
14
14
  import type { CheckoutStepComponentProps, TransactionStatus } from '../../../types'
15
15
 
@@ -15,7 +15,7 @@ import {
15
15
 
16
16
  import { cn } from '@hanzo/ui/util'
17
17
 
18
- import { useCommerce } from '../../../../context'
18
+ import { useCommerce } from '../../../../service/context'
19
19
  import { processSquareCardPayment } from '../../../../util'
20
20
  import type { PaymentMethodComponentProps } from '../../../../types'
21
21
  import { sendFBEvent, sendGAEvent } from '../../../../util/analytics'
@@ -19,7 +19,7 @@ import {
19
19
  } from '@hanzo/ui/primitives'
20
20
 
21
21
  import Eth from '../crypto-icons/eth'
22
- import { useCommerce } from '../../../../context'
22
+ import { useCommerce } from '../../../../service/context'
23
23
  import type { PaymentMethodComponentProps } from '../../../../types'
24
24
  import { sendFBEvent, sendGAEvent } from '../../../../util/analytics'
25
25
 
@@ -19,7 +19,7 @@ import {
19
19
  SelectValue
20
20
  } from '@hanzo/ui/primitives'
21
21
 
22
- import { useCommerce } from '../../context'
22
+ import { useCommerce } from '../../service/context'
23
23
 
24
24
  import countries from '../../util/countries'
25
25
  import { sendGAEvent } from '../../util/analytics'
@@ -178,7 +178,7 @@ const CarouselItemSelector: React.FC<ItemSelectorProps> = observer(({
178
178
  </div>
179
179
  {showByline && itemRef.item.byline && (<p>{itemRef.item.byline}</p>)}
180
180
  </ApplyTypography>
181
- {showSlider && (
181
+ {showSlider && items.length > 1 && (
182
182
  <ItemCarouselSlider
183
183
  clx='mt-5 w-[320px]'
184
184
  numStops={items.length}
package/index.ts CHANGED
@@ -1,7 +1,7 @@
1
- export * from './context'
1
+ export * from './service/context'
2
2
  export * from './components'
3
3
  // Impl-dependent, so leave w impl
4
- export type { StandaloneServiceOptions as ServiceOptions } from './service/impls/standalone/standalone-service'
4
+ export type { StandaloneServiceOptions as ServiceOptions } from './service/impls/standalone'
5
5
  export {
6
6
  useSyncSkuParamWithCurrentItem,
7
7
  getFacetValuesMutator,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/commerce",
3
- "version": "7.2.0",
3
+ "version": "7.3.1",
4
4
  "description": "e-commerce framework.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -11,8 +11,8 @@ import { enableStaticRendering } from 'mobx-react-lite'
11
11
  enableStaticRendering(typeof window === "undefined")
12
12
 
13
13
  import type CommerceService from '../types/commerce-service'
14
- import getInstance from '../service/get-instance'
15
14
  import type { CommerceConfig } from '../types'
15
+ import { getInstance } from './impls/standalone'
16
16
 
17
17
  const CommerceContext = createContext<CommerceService | undefined>(undefined)
18
18
 
@@ -78,6 +78,7 @@ class ActualLineItem
78
78
  })
79
79
  }
80
80
 
81
+ // TODO: create a way to pass template strings to the ui conf per sku path!
81
82
  get title(): string {
82
83
  return this.fullTitle ? this.fullTitle : (this.familyTitle + ', ' + this.optionLabel)
83
84
  }
@@ -0,0 +1,64 @@
1
+ import { enableStaticRendering } from 'mobx-react-lite'
2
+
3
+ import type { CommerceService, CommerceConfig } from '../../../types'
4
+ import { StandaloneService } from './index'
5
+ import { initSelectionUI } from '../../../util'
6
+
7
+ import { readSnapshot, writeSnapshotsOnChange } from './persistence'
8
+
9
+ enableStaticRendering(typeof window === "undefined")
10
+
11
+ const _LOG = false
12
+ const _log = (s: string) => {
13
+ if (!_LOG) return;
14
+ const d = new Date()
15
+ console.log(`TIMESTAMPED: ${d.getUTCMinutes()}:${d.getUTCSeconds()}:${d.getUTCMilliseconds()}`)
16
+ console.log(s)
17
+ }
18
+
19
+ // https://dev.to/ivandotv/mobx-server-side-rendering-with-next-js-4m18
20
+
21
+ let instance: StandaloneService | undefined = undefined
22
+
23
+ export const getInstance = ({
24
+ families,
25
+ rootNode,
26
+ options,
27
+ uiSpecifiers
28
+ }: CommerceConfig) : CommerceService => {
29
+
30
+ if (!options) {
31
+ throw new Error('cmmc getInstance(): Standalone Commerce Service requires config options!')
32
+ }
33
+
34
+ if (typeof window === "undefined") {
35
+ if (uiSpecifiers) {
36
+ initSelectionUI(uiSpecifiers)
37
+ }
38
+ _log("NEW INSTANCE: SERVER") //////////
39
+ return new StandaloneService(
40
+ families,
41
+ rootNode,
42
+ options
43
+ )
44
+ }
45
+
46
+ // Client side, create the store only once in the client
47
+ if (!instance) {
48
+ if (uiSpecifiers) {
49
+ initSelectionUI(uiSpecifiers)
50
+ }
51
+ _log("NEW INSTANCE: CLIENT") ///////////
52
+ const snapShot = readSnapshot(options.localStorageKey)
53
+ instance = new StandaloneService(
54
+ families,
55
+ rootNode,
56
+ options,
57
+ snapShot
58
+ )
59
+ writeSnapshotsOnChange(instance, options.localStorageKey)
60
+ }
61
+
62
+ return instance
63
+ }
64
+