@hanzo/commerce 7.1.4 → 7.1.5

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 (84) hide show
  1. package/components/Icons.tsx +34 -34
  2. package/components/add-to-cart-widget.tsx +181 -181
  3. package/components/buy/buy-card.tsx +259 -259
  4. package/components/buy/carousel-buy-card.tsx +245 -245
  5. package/components/buy/multi-family/all-variants-carousel.tsx +261 -261
  6. package/components/buy/multi-family/family-carousel/index.tsx +77 -77
  7. package/components/buy/multi-family/family-carousel/slide.tsx +83 -83
  8. package/components/buy/multi-family/family-carousel/state.ts +87 -87
  9. package/components/buy/multi-family/index.ts +2 -2
  10. package/components/buy/single-family-selector.tsx +90 -90
  11. package/components/buy/title-and-byline.tsx +25 -25
  12. package/components/cart/cart-accordian.tsx +59 -59
  13. package/components/cart/cart-panel/cart-line-item.tsx +76 -76
  14. package/components/cart/cart-panel/index.tsx +159 -159
  15. package/components/cart/cart-panel/promo-code.tsx +98 -98
  16. package/components/checkout/payment-step-form/card-icon-row.tsx +26 -26
  17. package/components/checkout/payment-step-form/card-icons/amex.tsx +32 -32
  18. package/components/checkout/payment-step-form/card-icons/diners-club.tsx +13 -13
  19. package/components/checkout/payment-step-form/card-icons/discover.tsx +25 -25
  20. package/components/checkout/payment-step-form/card-icons/jcb.tsx +26 -26
  21. package/components/checkout/payment-step-form/card-icons/mastercard.tsx +27 -27
  22. package/components/checkout/payment-step-form/card-icons/visa.tsx +25 -25
  23. package/components/checkout/payment-step-form/cc-button.tsx +17 -17
  24. package/components/checkout/payment-step-form/contact-form.tsx +49 -49
  25. package/components/checkout/payment-step-form/crypto-icons/btc.tsx +11 -11
  26. package/components/checkout/payment-step-form/crypto-icons/eth.tsx +20 -20
  27. package/components/checkout/payment-step-form/crypto-icons/usdt.tsx +13 -13
  28. package/components/checkout/payment-step-form/index.tsx +122 -122
  29. package/components/checkout/payment-step-form/methods/bank-transfer.tsx +79 -79
  30. package/components/checkout/payment-step-form/methods/card.tsx +232 -232
  31. package/components/checkout/payment-step-form/methods/crypto.tsx +227 -227
  32. package/components/checkout/payment-step-form/methods/index.ts +22 -22
  33. package/components/checkout/shipping-step-form.tsx +172 -172
  34. package/components/index.ts +12 -12
  35. package/components/item/product-card.tsx +48 -48
  36. package/components/item-selector/button.tsx +188 -188
  37. package/components/item-selector/carousel/index.tsx +197 -197
  38. package/components/item-selector/carousel/slider.tsx +40 -40
  39. package/components/item-selector/index.ts +5 -5
  40. package/components/item-selector/quantity-indicator.tsx +48 -48
  41. package/components/node-tabs/index.tsx +91 -91
  42. package/components/node-tabs/node-image.tsx +31 -31
  43. package/context/index.tsx +45 -45
  44. package/index.ts +12 -12
  45. package/package.json +60 -60
  46. package/service/debug.ts +41 -41
  47. package/service/get-instance.ts +2 -2
  48. package/service/impls/standalone/actual-line-item.ts +121 -121
  49. package/service/impls/standalone/index.ts +62 -62
  50. package/service/impls/standalone/localStorage.ts +34 -34
  51. package/service/impls/standalone/orders/firebase-app.ts +14 -14
  52. package/service/impls/standalone/orders/index.ts +128 -128
  53. package/service/impls/standalone/standalone-service.ts +550 -550
  54. package/service/path-utils.ts +25 -25
  55. package/service/sep.ts +6 -6
  56. package/tsconfig.json +10 -10
  57. package/types/README.md +1 -1
  58. package/types/category-node.ts +49 -49
  59. package/types/checkout.ts +46 -46
  60. package/types/commerce-config.ts +13 -13
  61. package/types/commerce-service.ts +121 -121
  62. package/types/family.ts +25 -25
  63. package/types/index.ts +15 -15
  64. package/types/item-selector.ts +96 -96
  65. package/types/line-item.ts +29 -29
  66. package/types/multi-family-selector-props.ts +19 -19
  67. package/types/product.ts +20 -20
  68. package/types/promo.ts +9 -9
  69. package/types/selection-ui-specifier.ts +51 -51
  70. package/types/string-mutator.ts +13 -13
  71. package/types/token-separators.ts +7 -7
  72. package/util/analytics.ts +20 -20
  73. package/util/countries.ts +195 -195
  74. package/util/error.ts +34 -34
  75. package/util/index.ts +70 -70
  76. package/util/item-selector-options-accessor.ts +34 -34
  77. package/util/line-item-ref.ts +23 -23
  78. package/util/multi-family-selector-options-accessor.ts +14 -14
  79. package/util/obs-string-mutator.ts +22 -22
  80. package/util/product-media-accessor.ts +58 -58
  81. package/util/promo-codes.ts +108 -108
  82. package/util/selection-ui-specifiers.ts +29 -29
  83. package/util/square-payment.ts +42 -42
  84. package/util/use-sync-sku-param-w-current-item.ts +88 -88
@@ -1,122 +1,122 @@
1
- import {
2
- action,
3
- computed,
4
- makeObservable,
5
- observable,
6
- } from 'mobx'
7
-
8
- import type { ImageDef, MediaTransform, VideoDef } from '@hanzo/ui/types'
9
-
10
- import type { Product, LineItem, CommerceService } from '../../../types'
11
-
12
- interface ActualLineItemSnapshot {
13
- sku: string
14
- familyId: string // helps impl of restoreFromSnapshot
15
- title: string
16
- price: number
17
- quantity: number
18
- timeAdded: number // helps to sort view of order and cart
19
- }
20
-
21
- class ActualLineItem
22
- implements LineItem
23
- {
24
-
25
- qu: number = 0
26
-
27
- id: string
28
- sku: string
29
- fullTitle?: string
30
- optionLabel: string
31
- optionLabelShort?: string
32
- familyTitle: string
33
- familyId: string
34
- byline?: string
35
- desc?: string
36
- price: number
37
- img?: ImageDef
38
- video?: VideoDef
39
- animation?: string
40
- mediaTransform?: MediaTransform
41
- optionImg?: ImageDef
42
- timeAdded: number = 0 // timeAdded of being added to cart
43
-
44
- constructor(prod: Product, snap?: ActualLineItemSnapshot) {
45
- this.id = prod.id
46
- this.sku = prod.sku
47
- this.fullTitle = prod.fullTitle
48
- this.optionLabel = prod.optionLabel
49
- this.optionLabelShort = prod.optionLabelShort
50
- this.familyTitle = prod.familyTitle
51
- this.familyId = prod.familyId
52
- this.byline = prod.byline
53
- this.desc = prod.desc
54
- this.price = prod.price
55
- this.img = prod.img
56
- this.video = prod.video
57
- this.animation = prod.animation
58
- this.optionImg = prod.optionImg
59
- this.mediaTransform = prod.mediaTransform
60
-
61
- if (snap) {
62
- this.qu = snap.quantity
63
- this.timeAdded = snap.timeAdded
64
- }
65
-
66
- makeObservable(this, {
67
- qu: observable,
68
- timeAdded: observable,
69
- canDecrement: computed,
70
- isInCart: computed,
71
- title: computed,
72
- increment: action,
73
- decrement: action,
74
- })
75
- }
76
-
77
- get title(): string {
78
- return this.fullTitle ? this.fullTitle : (this.familyTitle + ', ' + this.optionLabel)
79
- }
80
-
81
- takeSnapshot = (cmmc: CommerceService): ActualLineItemSnapshot => {
82
-
83
- const title = this.fullTitle ?
84
- this.fullTitle
85
- :
86
- ((cmmc.getFamilyById(this.familyId)?.title ?? this.familyTitle) + ', ' + this.optionLabel)
87
-
88
- return({
89
- sku: this.sku,
90
- familyId: this.familyId,
91
- title,
92
- price: this.price,
93
- quantity: this.qu,
94
- timeAdded: this.timeAdded
95
- } satisfies ActualLineItemSnapshot)
96
- }
97
-
98
- get canDecrement(): boolean { return this.qu > 0 }
99
- get quantity(): number {return this.qu}
100
- get isInCart(): boolean {return this.qu > 0}
101
-
102
- increment(): void {
103
- if (this.qu === 0) {
104
- this.timeAdded = new Date().getTime()
105
- }
106
- this.qu++
107
- }
108
-
109
- decrement(): void {
110
- if (this.canDecrement) {
111
- this.qu--
112
- if (this.qu === 0) {
113
- this.timeAdded = 0
114
- }
115
- }
116
- }
117
- }
118
-
119
- export {
120
- type ActualLineItemSnapshot,
121
- ActualLineItem as default
1
+ import {
2
+ action,
3
+ computed,
4
+ makeObservable,
5
+ observable,
6
+ } from 'mobx'
7
+
8
+ import type { ImageDef, MediaTransform, VideoDef } from '@hanzo/ui/types'
9
+
10
+ import type { Product, LineItem, CommerceService } from '../../../types'
11
+
12
+ interface ActualLineItemSnapshot {
13
+ sku: string
14
+ familyId: string // helps impl of restoreFromSnapshot
15
+ title: string
16
+ price: number
17
+ quantity: number
18
+ timeAdded: number // helps to sort view of order and cart
19
+ }
20
+
21
+ class ActualLineItem
22
+ implements LineItem
23
+ {
24
+
25
+ qu: number = 0
26
+
27
+ id: string
28
+ sku: string
29
+ fullTitle?: string
30
+ optionLabel: string
31
+ optionLabelShort?: string
32
+ familyTitle: string
33
+ familyId: string
34
+ byline?: string
35
+ desc?: string
36
+ price: number
37
+ img?: ImageDef
38
+ video?: VideoDef
39
+ animation?: string
40
+ mediaTransform?: MediaTransform
41
+ optionImg?: ImageDef
42
+ timeAdded: number = 0 // timeAdded of being added to cart
43
+
44
+ constructor(prod: Product, snap?: ActualLineItemSnapshot) {
45
+ this.id = prod.id
46
+ this.sku = prod.sku
47
+ this.fullTitle = prod.fullTitle
48
+ this.optionLabel = prod.optionLabel
49
+ this.optionLabelShort = prod.optionLabelShort
50
+ this.familyTitle = prod.familyTitle
51
+ this.familyId = prod.familyId
52
+ this.byline = prod.byline
53
+ this.desc = prod.desc
54
+ this.price = prod.price
55
+ this.img = prod.img
56
+ this.video = prod.video
57
+ this.animation = prod.animation
58
+ this.optionImg = prod.optionImg
59
+ this.mediaTransform = prod.mediaTransform
60
+
61
+ if (snap) {
62
+ this.qu = snap.quantity
63
+ this.timeAdded = snap.timeAdded
64
+ }
65
+
66
+ makeObservable(this, {
67
+ qu: observable,
68
+ timeAdded: observable,
69
+ canDecrement: computed,
70
+ isInCart: computed,
71
+ title: computed,
72
+ increment: action,
73
+ decrement: action,
74
+ })
75
+ }
76
+
77
+ get title(): string {
78
+ return this.fullTitle ? this.fullTitle : (this.familyTitle + ', ' + this.optionLabel)
79
+ }
80
+
81
+ takeSnapshot = (cmmc: CommerceService): ActualLineItemSnapshot => {
82
+
83
+ const title = this.fullTitle ?
84
+ this.fullTitle
85
+ :
86
+ ((cmmc.getFamilyById(this.familyId)?.title ?? this.familyTitle) + ', ' + this.optionLabel)
87
+
88
+ return({
89
+ sku: this.sku,
90
+ familyId: this.familyId,
91
+ title,
92
+ price: this.price,
93
+ quantity: this.qu,
94
+ timeAdded: this.timeAdded
95
+ } satisfies ActualLineItemSnapshot)
96
+ }
97
+
98
+ get canDecrement(): boolean { return this.qu > 0 }
99
+ get quantity(): number {return this.qu}
100
+ get isInCart(): boolean {return this.qu > 0}
101
+
102
+ increment(): void {
103
+ if (this.qu === 0) {
104
+ this.timeAdded = new Date().getTime()
105
+ }
106
+ this.qu++
107
+ }
108
+
109
+ decrement(): void {
110
+ if (this.canDecrement) {
111
+ this.qu--
112
+ if (this.qu === 0) {
113
+ this.timeAdded = 0
114
+ }
115
+ }
116
+ }
117
+ }
118
+
119
+ export {
120
+ type ActualLineItemSnapshot,
121
+ ActualLineItem as default
122
122
  }
@@ -1,62 +1,62 @@
1
- import { enableStaticRendering } from 'mobx-react-lite'
2
-
3
- import type { CommerceService, Family, CategoryNode, SelectionUISpecifier, CommerceConfig } from '../../../types'
4
- import StandaloneService, {type StandaloneServiceOptions} from './standalone-service'
5
- import { initSelectionUI } from '../../../util'
6
-
7
- import { readSnapshot, listenAndWriteSnapshots } from './localStorage'
8
-
9
- enableStaticRendering(typeof window === "undefined")
10
-
11
- const _log = (s: string) => {
12
- const d = new Date()
13
- console.log(`TIMESTAMPED: ${d.getUTCMinutes()}:${d.getUTCSeconds()}:${d.getUTCMilliseconds()}`)
14
- console.log(s)
15
- }
16
-
17
- // https://dev.to/ivandotv/mobx-server-side-rendering-with-next-js-4m18
18
-
19
- let instance: StandaloneService | undefined = undefined
20
-
21
- export const getInstance = ({
22
- families,
23
- rootNode,
24
- options,
25
- uiSpecifiers
26
- }: CommerceConfig) : CommerceService => {
27
-
28
- if (!options) {
29
- throw new Error('cmmc getInstance(): Standalone Commerce Service requires config options!')
30
- }
31
-
32
- if (typeof window === "undefined") {
33
- if (uiSpecifiers) {
34
- initSelectionUI(uiSpecifiers)
35
- }
36
- //_log("NEW INSTANCE FOR SERVER")
37
- return new StandaloneService(
38
- families,
39
- rootNode,
40
- options
41
- )
42
- }
43
-
44
- // Client side, create the store only once in the client
45
- if (!instance) {
46
- if (uiSpecifiers) {
47
- initSelectionUI(uiSpecifiers)
48
- }
49
- //_log("NEW INSTANCE FOR CLIENT")
50
- const snapShot = readSnapshot()
51
- instance = new StandaloneService(
52
- families,
53
- rootNode,
54
- options,
55
- snapShot
56
- )
57
- listenAndWriteSnapshots(instance)
58
- }
59
-
60
- return instance
61
- }
62
-
1
+ import { enableStaticRendering } from 'mobx-react-lite'
2
+
3
+ import type { CommerceService, Family, CategoryNode, SelectionUISpecifier, CommerceConfig } from '../../../types'
4
+ import StandaloneService, {type StandaloneServiceOptions} from './standalone-service'
5
+ import { initSelectionUI } from '../../../util'
6
+
7
+ import { readSnapshot, listenAndWriteSnapshots } from './localStorage'
8
+
9
+ enableStaticRendering(typeof window === "undefined")
10
+
11
+ const _log = (s: string) => {
12
+ const d = new Date()
13
+ console.log(`TIMESTAMPED: ${d.getUTCMinutes()}:${d.getUTCSeconds()}:${d.getUTCMilliseconds()}`)
14
+ console.log(s)
15
+ }
16
+
17
+ // https://dev.to/ivandotv/mobx-server-side-rendering-with-next-js-4m18
18
+
19
+ let instance: StandaloneService | undefined = undefined
20
+
21
+ export const getInstance = ({
22
+ families,
23
+ rootNode,
24
+ options,
25
+ uiSpecifiers
26
+ }: CommerceConfig) : CommerceService => {
27
+
28
+ if (!options) {
29
+ throw new Error('cmmc getInstance(): Standalone Commerce Service requires config options!')
30
+ }
31
+
32
+ if (typeof window === "undefined") {
33
+ if (uiSpecifiers) {
34
+ initSelectionUI(uiSpecifiers)
35
+ }
36
+ //_log("NEW INSTANCE FOR SERVER")
37
+ return new StandaloneService(
38
+ families,
39
+ rootNode,
40
+ options
41
+ )
42
+ }
43
+
44
+ // Client side, create the store only once in the client
45
+ if (!instance) {
46
+ if (uiSpecifiers) {
47
+ initSelectionUI(uiSpecifiers)
48
+ }
49
+ //_log("NEW INSTANCE FOR CLIENT")
50
+ const snapShot = readSnapshot()
51
+ instance = new StandaloneService(
52
+ families,
53
+ rootNode,
54
+ options,
55
+ snapShot
56
+ )
57
+ listenAndWriteSnapshots(instance)
58
+ }
59
+
60
+ return instance
61
+ }
62
+
@@ -1,34 +1,34 @@
1
- import { reaction } from 'mobx'
2
- import StandaloneService, { type StandaloneServiceSnapshot } from './standalone-service'
3
-
4
- const LS_KEY = 'lux-cart'
5
-
6
- const readSnapshot = (): StandaloneServiceSnapshot | undefined => {
7
- const snapshotAsStr = localStorage.getItem(LS_KEY)
8
- return snapshotAsStr ? JSON.parse(snapshotAsStr) as StandaloneServiceSnapshot : undefined
9
- }
10
-
11
- const listenAndWriteSnapshots = (cmmc: StandaloneService): void => {
12
-
13
- if (typeof window !== 'undefined') {
14
- reaction(
15
- () => (cmmc.cartTotal),
16
- (total) => {
17
- if (total > 0) {
18
- const snapshot = cmmc.takeSnapshot()
19
- // console.log(`CMMC LOCAL STORAGE UPDATE. (CART TOTAL: ${total}`)
20
- localStorage.setItem(LS_KEY, JSON.stringify(snapshot) )
21
- }
22
- else {
23
- localStorage.removeItem(LS_KEY)
24
- }
25
- }
26
- )
27
- }
28
- }
29
-
30
- export {
31
- readSnapshot,
32
- listenAndWriteSnapshots
33
- }
34
-
1
+ import { reaction } from 'mobx'
2
+ import StandaloneService, { type StandaloneServiceSnapshot } from './standalone-service'
3
+
4
+ const LS_KEY = 'lux-cart'
5
+
6
+ const readSnapshot = (): StandaloneServiceSnapshot | undefined => {
7
+ const snapshotAsStr = localStorage.getItem(LS_KEY)
8
+ return snapshotAsStr ? JSON.parse(snapshotAsStr) as StandaloneServiceSnapshot : undefined
9
+ }
10
+
11
+ const listenAndWriteSnapshots = (cmmc: StandaloneService): void => {
12
+
13
+ if (typeof window !== 'undefined') {
14
+ reaction(
15
+ () => (cmmc.cartTotal),
16
+ (total) => {
17
+ if (total > 0) {
18
+ const snapshot = cmmc.takeSnapshot()
19
+ // console.log(`CMMC LOCAL STORAGE UPDATE. (CART TOTAL: ${total}`)
20
+ localStorage.setItem(LS_KEY, JSON.stringify(snapshot) )
21
+ }
22
+ else {
23
+ localStorage.removeItem(LS_KEY)
24
+ }
25
+ }
26
+ )
27
+ }
28
+ }
29
+
30
+ export {
31
+ readSnapshot,
32
+ listenAndWriteSnapshots
33
+ }
34
+
@@ -1,14 +1,14 @@
1
- import { initializeApp, getApps } from 'firebase/app'
2
-
3
- const firebaseConfig = {
4
- apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
5
- authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
6
- projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
7
- storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
8
- messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
9
- appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
10
- measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
11
- }
12
-
13
- // Initialize Firebase instance if there isn't one already
14
- export default getApps().length === 0 ? initializeApp(firebaseConfig) : getApps()[0]
1
+ import { initializeApp, getApps } from 'firebase/app'
2
+
3
+ const firebaseConfig = {
4
+ apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
5
+ authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
6
+ projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
7
+ storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
8
+ messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
9
+ appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
10
+ measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
11
+ }
12
+
13
+ // Initialize Firebase instance if there isn't one already
14
+ export default getApps().length === 0 ? initializeApp(firebaseConfig) : getApps()[0]