@hanzo/commerce 7.1.34 → 7.3.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.
- package/components/buy/buy-card.tsx +1 -1
- package/components/buy/carousel-buy-card.tsx +1 -1
- package/components/cart/cart-panel/cart-line-item.tsx +1 -1
- package/components/cart/cart-panel/index.tsx +1 -1
- package/components/cart/cart-panel/promo-code.tsx +11 -3
- package/components/cart/cart-panel/total-area.tsx +1 -1
- package/components/checkout/payment-step-form/index.tsx +1 -1
- package/components/checkout/payment-step-form/methods/card.tsx +1 -1
- package/components/checkout/payment-step-form/methods/crypto.tsx +1 -1
- package/components/checkout/shipping-step-form.tsx +1 -1
- package/index.ts +2 -2
- package/package.json +1 -1
- package/{context/index.tsx → service/context.tsx} +1 -1
- package/service/impls/standalone/actual-line-item.ts +18 -4
- package/service/impls/standalone/get-instance.ts +64 -0
- package/service/impls/standalone/index.ts +559 -42
- package/service/impls/standalone/{orders → order}/index.ts +2 -2
- package/service/impls/standalone/persistence.ts +33 -0
- package/types/commerce-service.ts +6 -0
- package/util/use-sync-sku-param-w-current-item.ts +1 -1
- package/service/get-instance.ts +0 -3
- package/service/impls/standalone/localStorage.ts +0 -34
- package/service/impls/standalone/standalone-service.ts +0 -550
- /package/service/impls/standalone/{orders/firebase-app.ts → order/firebase.ts} +0 -0
|
@@ -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 {
|
|
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'
|
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
|
|
4
|
+
export type { StandaloneServiceOptions as ServiceOptions } from './service/impls/standalone'
|
|
5
5
|
export {
|
|
6
6
|
useSyncSkuParamWithCurrentItem,
|
|
7
7
|
getFacetValuesMutator,
|
package/package.json
CHANGED
|
@@ -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
|
|
|
@@ -15,13 +15,13 @@ interface ActualLineItemSnapshot {
|
|
|
15
15
|
title: string
|
|
16
16
|
price: number
|
|
17
17
|
quantity: number
|
|
18
|
-
timeAdded: number
|
|
18
|
+
timeAdded: number
|
|
19
|
+
timeModified: number
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
class ActualLineItem
|
|
22
23
|
implements LineItem
|
|
23
24
|
{
|
|
24
|
-
|
|
25
25
|
qu: number = 0
|
|
26
26
|
|
|
27
27
|
id: string
|
|
@@ -39,7 +39,9 @@ class ActualLineItem
|
|
|
39
39
|
animation?: string
|
|
40
40
|
mediaTransform?: MediaTransform
|
|
41
41
|
optionImg?: ImageDef
|
|
42
|
-
|
|
42
|
+
|
|
43
|
+
timeAdded: number = 0 // Timestamp when added
|
|
44
|
+
timeModified: number = 0 // Timestamp quantity last modified (0 if not in cart)
|
|
43
45
|
|
|
44
46
|
constructor(prod: Product, snap?: ActualLineItemSnapshot) {
|
|
45
47
|
this.id = prod.id
|
|
@@ -61,11 +63,13 @@ class ActualLineItem
|
|
|
61
63
|
if (snap) {
|
|
62
64
|
this.qu = snap.quantity
|
|
63
65
|
this.timeAdded = snap.timeAdded
|
|
66
|
+
this.timeModified = snap.timeModified
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
makeObservable(this, {
|
|
67
70
|
qu: observable,
|
|
68
71
|
timeAdded: observable,
|
|
72
|
+
timeModified: observable,
|
|
69
73
|
canDecrement: computed,
|
|
70
74
|
isInCart: computed,
|
|
71
75
|
title: computed,
|
|
@@ -74,6 +78,7 @@ class ActualLineItem
|
|
|
74
78
|
})
|
|
75
79
|
}
|
|
76
80
|
|
|
81
|
+
// TODO: create a way to pass template strings to the ui conf per sku path!
|
|
77
82
|
get title(): string {
|
|
78
83
|
return this.fullTitle ? this.fullTitle : (this.familyTitle + ', ' + this.optionLabel)
|
|
79
84
|
}
|
|
@@ -91,7 +96,8 @@ class ActualLineItem
|
|
|
91
96
|
title,
|
|
92
97
|
price: this.price,
|
|
93
98
|
quantity: this.qu,
|
|
94
|
-
timeAdded: this.timeAdded
|
|
99
|
+
timeAdded: this.timeAdded,
|
|
100
|
+
timeModified: this.timeModified
|
|
95
101
|
} satisfies ActualLineItemSnapshot)
|
|
96
102
|
}
|
|
97
103
|
|
|
@@ -102,6 +108,10 @@ class ActualLineItem
|
|
|
102
108
|
increment(): void {
|
|
103
109
|
if (this.qu === 0) {
|
|
104
110
|
this.timeAdded = new Date().getTime()
|
|
111
|
+
this.timeModified = this.timeAdded
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
this.timeModified = new Date().getTime()
|
|
105
115
|
}
|
|
106
116
|
this.qu++
|
|
107
117
|
}
|
|
@@ -111,6 +121,10 @@ class ActualLineItem
|
|
|
111
121
|
this.qu--
|
|
112
122
|
if (this.qu === 0) {
|
|
113
123
|
this.timeAdded = 0
|
|
124
|
+
this.timeModified = 0
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
this.timeModified = new Date().getTime()
|
|
114
128
|
}
|
|
115
129
|
}
|
|
116
130
|
}
|
|
@@ -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
|
+
|