@hanzo/commerce 7.1.5 → 7.1.6
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/Icons.tsx +34 -34
- package/components/add-to-cart-widget.tsx +181 -181
- package/components/buy/buy-card.tsx +259 -259
- package/components/buy/carousel-buy-card.tsx +245 -245
- package/components/buy/multi-family/all-variants-carousel.tsx +261 -261
- package/components/buy/multi-family/family-carousel/index.tsx +77 -77
- package/components/buy/multi-family/family-carousel/slide.tsx +83 -83
- package/components/buy/multi-family/family-carousel/state.ts +87 -87
- package/components/buy/multi-family/index.ts +2 -2
- package/components/buy/single-family-selector.tsx +90 -90
- package/components/buy/title-and-byline.tsx +25 -25
- package/components/cart/cart-accordian.tsx +59 -59
- package/components/cart/cart-panel/cart-line-item.tsx +76 -76
- package/components/cart/cart-panel/index.tsx +161 -159
- package/components/cart/cart-panel/promo-code.tsx +98 -98
- package/components/checkout/payment-step-form/card-icon-row.tsx +26 -26
- package/components/checkout/payment-step-form/card-icons/amex.tsx +32 -32
- package/components/checkout/payment-step-form/card-icons/diners-club.tsx +13 -13
- package/components/checkout/payment-step-form/card-icons/discover.tsx +25 -25
- package/components/checkout/payment-step-form/card-icons/jcb.tsx +26 -26
- package/components/checkout/payment-step-form/card-icons/mastercard.tsx +27 -27
- package/components/checkout/payment-step-form/card-icons/visa.tsx +25 -25
- package/components/checkout/payment-step-form/cc-button.tsx +17 -17
- package/components/checkout/payment-step-form/contact-form.tsx +49 -49
- package/components/checkout/payment-step-form/crypto-icons/btc.tsx +11 -11
- package/components/checkout/payment-step-form/crypto-icons/eth.tsx +20 -20
- package/components/checkout/payment-step-form/crypto-icons/usdt.tsx +13 -13
- package/components/checkout/payment-step-form/index.tsx +122 -122
- package/components/checkout/payment-step-form/methods/bank-transfer.tsx +79 -79
- package/components/checkout/payment-step-form/methods/card.tsx +232 -232
- package/components/checkout/payment-step-form/methods/crypto.tsx +227 -227
- package/components/checkout/payment-step-form/methods/index.ts +22 -22
- package/components/checkout/shipping-step-form.tsx +172 -172
- package/components/index.ts +12 -12
- package/components/item/product-card.tsx +48 -48
- package/components/item-selector/button.tsx +188 -188
- package/components/item-selector/carousel/index.tsx +197 -197
- package/components/item-selector/carousel/slider.tsx +40 -40
- package/components/item-selector/index.ts +5 -5
- package/components/item-selector/quantity-indicator.tsx +48 -48
- package/components/node-tabs/index.tsx +91 -91
- package/components/node-tabs/node-image.tsx +31 -31
- package/context/index.tsx +45 -45
- package/index.ts +12 -12
- package/package.json +60 -60
- package/service/debug.ts +41 -41
- package/service/get-instance.ts +2 -2
- package/service/impls/standalone/actual-line-item.ts +121 -121
- package/service/impls/standalone/index.ts +62 -62
- package/service/impls/standalone/localStorage.ts +34 -34
- package/service/impls/standalone/orders/firebase-app.ts +14 -14
- package/service/impls/standalone/orders/index.ts +128 -128
- package/service/impls/standalone/standalone-service.ts +550 -550
- package/service/path-utils.ts +25 -25
- package/service/sep.ts +6 -6
- package/tsconfig.json +10 -10
- package/types/README.md +1 -1
- package/types/category-node.ts +49 -49
- package/types/checkout.ts +46 -46
- package/types/commerce-config.ts +13 -13
- package/types/commerce-service.ts +121 -121
- package/types/family.ts +25 -25
- package/types/index.ts +15 -15
- package/types/item-selector.ts +96 -96
- package/types/line-item.ts +29 -29
- package/types/multi-family-selector-props.ts +19 -19
- package/types/product.ts +20 -20
- package/types/promo.ts +9 -9
- package/types/selection-ui-specifier.ts +51 -51
- package/types/string-mutator.ts +13 -13
- package/types/token-separators.ts +7 -7
- package/util/analytics.ts +20 -20
- package/util/countries.ts +195 -195
- package/util/error.ts +34 -34
- package/util/index.ts +70 -70
- package/util/item-selector-options-accessor.ts +34 -34
- package/util/line-item-ref.ts +23 -23
- package/util/multi-family-selector-options-accessor.ts +14 -14
- package/util/obs-string-mutator.ts +22 -22
- package/util/product-media-accessor.ts +58 -58
- package/util/promo-codes.ts +108 -108
- package/util/selection-ui-specifiers.ts +29 -29
- package/util/square-payment.ts +42 -42
- package/util/use-sync-sku-param-w-current-item.ts +88 -88
package/service/path-utils.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import type { SelectedPaths } from '../types'
|
|
2
|
-
import sep from './sep'
|
|
3
|
-
|
|
4
|
-
export const getSelectedPaths = (
|
|
5
|
-
skuPath: string
|
|
6
|
-
): { paths: SelectedPaths; level: number } => {
|
|
7
|
-
|
|
8
|
-
const toks = skuPath.split(sep.tok)
|
|
9
|
-
const level = toks.length - 1
|
|
10
|
-
const paths: SelectedPaths = {}
|
|
11
|
-
for (let l = 1; l <= level; l++ ) {
|
|
12
|
-
paths[l] = [toks[l]]
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
paths,
|
|
16
|
-
level
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const getParentPath = (skuPath: string): string => (
|
|
21
|
-
skuPath.split(sep.tok).slice(0, -1).join(sep.tok)
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
export const lastToken = (skuPath: string): string => (
|
|
25
|
-
skuPath.split(sep.tok).pop()!
|
|
1
|
+
import type { SelectedPaths } from '../types'
|
|
2
|
+
import sep from './sep'
|
|
3
|
+
|
|
4
|
+
export const getSelectedPaths = (
|
|
5
|
+
skuPath: string
|
|
6
|
+
): { paths: SelectedPaths; level: number } => {
|
|
7
|
+
|
|
8
|
+
const toks = skuPath.split(sep.tok)
|
|
9
|
+
const level = toks.length - 1
|
|
10
|
+
const paths: SelectedPaths = {}
|
|
11
|
+
for (let l = 1; l <= level; l++ ) {
|
|
12
|
+
paths[l] = [toks[l]]
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
paths,
|
|
16
|
+
level
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const getParentPath = (skuPath: string): string => (
|
|
21
|
+
skuPath.split(sep.tok).slice(0, -1).join(sep.tok)
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
export const lastToken = (skuPath: string): string => (
|
|
25
|
+
skuPath.split(sep.tok).pop()!
|
|
26
26
|
)
|
package/service/sep.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { TokenSeparators } from '../types'
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
tok: '-',
|
|
5
|
-
subTok: '_',
|
|
6
|
-
decimal: '.'
|
|
1
|
+
import type { TokenSeparators } from '../types'
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
tok: '-',
|
|
5
|
+
subTok: '_',
|
|
6
|
+
decimal: '.'
|
|
7
7
|
} satisfies TokenSeparators
|
package/tsconfig.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../tsconfig.hanzo.base.json",
|
|
3
|
-
"include": [
|
|
4
|
-
"**/*.ts",
|
|
5
|
-
"**/*.tsx",
|
|
6
|
-
],
|
|
7
|
-
"exclude": [
|
|
8
|
-
"node_modules",
|
|
9
|
-
]
|
|
10
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"extends": "../tsconfig.hanzo.base.json",
|
|
3
|
+
"include": [
|
|
4
|
+
"**/*.ts",
|
|
5
|
+
"**/*.tsx",
|
|
6
|
+
],
|
|
7
|
+
"exclude": [
|
|
8
|
+
"node_modules",
|
|
9
|
+
]
|
|
10
|
+
}
|
package/types/README.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
These are the types that the card ui expects and understands.
|
|
1
|
+
These are the types that the card ui expects and understands.
|
|
2
2
|
There should always be adaptors both ways from Hanzo commerceJs types.
|
package/types/category-node.ts
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import type { ReactNode } from 'react'
|
|
2
|
-
|
|
3
|
-
interface CategoryNode {
|
|
4
|
-
skuToken: string // a token in the sku
|
|
5
|
-
label: string;
|
|
6
|
-
/**
|
|
7
|
-
* Explicitly marks this node as a "last user-visible" / "outermost" Category.
|
|
8
|
-
* Normally, a node is "outermost" when it has no subnodes
|
|
9
|
-
* (and thus is a family with products -- "single-family")
|
|
10
|
-
* But if it *has* subnodes, and its subNodes are actually sibling families
|
|
11
|
-
* of a Category, it must be marked as "outermost" ("multi-family")
|
|
12
|
-
* */
|
|
13
|
-
outermost?: boolean;
|
|
14
|
-
img? : string | ReactNode // icon is required
|
|
15
|
-
imgAR? : number // helps with svgs
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* One word prompt that describes the 'meaning' of
|
|
19
|
-
* the subnodes.
|
|
20
|
-
* For example, if a node is 'Lux Credit',
|
|
21
|
-
* it's subNodesLabel might be 'Level', so some UI's
|
|
22
|
-
* might be configured to render 'Level: Black'
|
|
23
|
-
*
|
|
24
|
-
* or something like...
|
|
25
|
-
*
|
|
26
|
-
* <Tabs title={parentNode.label + ': ' + parentNode.subNodesLabel} values={families.map((f) => (f.shortName))} />
|
|
27
|
-
*
|
|
28
|
-
* ...which renders
|
|
29
|
-
*
|
|
30
|
-
* Lux Credit Levels:
|
|
31
|
-
* Black Elite Founder Sovereign
|
|
32
|
-
*/
|
|
33
|
-
subNodesLabel?: string
|
|
34
|
-
subNodes?: CategoryNode[]
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
type CategoryNodeRole =
|
|
38
|
-
'single-family' |
|
|
39
|
-
'family-in-multi-family' |
|
|
40
|
-
'multi-family' |
|
|
41
|
-
'non-outermost'
|
|
42
|
-
|
|
43
|
-
// Which facets tokens are 'on' at each level
|
|
44
|
-
type SelectedPaths = Record<number, string[]>
|
|
45
|
-
|
|
46
|
-
export type {
|
|
47
|
-
CategoryNodeRole,
|
|
48
|
-
CategoryNode,
|
|
49
|
-
SelectedPaths
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
interface CategoryNode {
|
|
4
|
+
skuToken: string // a token in the sku
|
|
5
|
+
label: string;
|
|
6
|
+
/**
|
|
7
|
+
* Explicitly marks this node as a "last user-visible" / "outermost" Category.
|
|
8
|
+
* Normally, a node is "outermost" when it has no subnodes
|
|
9
|
+
* (and thus is a family with products -- "single-family")
|
|
10
|
+
* But if it *has* subnodes, and its subNodes are actually sibling families
|
|
11
|
+
* of a Category, it must be marked as "outermost" ("multi-family")
|
|
12
|
+
* */
|
|
13
|
+
outermost?: boolean;
|
|
14
|
+
img? : string | ReactNode // icon is required
|
|
15
|
+
imgAR? : number // helps with svgs
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* One word prompt that describes the 'meaning' of
|
|
19
|
+
* the subnodes.
|
|
20
|
+
* For example, if a node is 'Lux Credit',
|
|
21
|
+
* it's subNodesLabel might be 'Level', so some UI's
|
|
22
|
+
* might be configured to render 'Level: Black'
|
|
23
|
+
*
|
|
24
|
+
* or something like...
|
|
25
|
+
*
|
|
26
|
+
* <Tabs title={parentNode.label + ': ' + parentNode.subNodesLabel} values={families.map((f) => (f.shortName))} />
|
|
27
|
+
*
|
|
28
|
+
* ...which renders
|
|
29
|
+
*
|
|
30
|
+
* Lux Credit Levels:
|
|
31
|
+
* Black Elite Founder Sovereign
|
|
32
|
+
*/
|
|
33
|
+
subNodesLabel?: string
|
|
34
|
+
subNodes?: CategoryNode[]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type CategoryNodeRole =
|
|
38
|
+
'single-family' |
|
|
39
|
+
'family-in-multi-family' |
|
|
40
|
+
'multi-family' |
|
|
41
|
+
'non-outermost'
|
|
42
|
+
|
|
43
|
+
// Which facets tokens are 'on' at each level
|
|
44
|
+
type SelectedPaths = Record<number, string[]>
|
|
45
|
+
|
|
46
|
+
export type {
|
|
47
|
+
CategoryNodeRole,
|
|
48
|
+
CategoryNode,
|
|
49
|
+
SelectedPaths
|
|
50
50
|
}
|
package/types/checkout.ts
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import type { ComponentType } from 'react'
|
|
2
|
-
import type { UseFormReturn } from 'react-hook-form'
|
|
3
|
-
|
|
4
|
-
type TransactionStatus = 'unpaid' | 'paid' | 'confirmed' | 'error'
|
|
5
|
-
|
|
6
|
-
interface CheckoutStepComponentProps {
|
|
7
|
-
onDone: () => void
|
|
8
|
-
orderId: string | undefined
|
|
9
|
-
setOrderId: (orderId: string | undefined) => void
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface CheckoutStep {
|
|
13
|
-
name: string
|
|
14
|
-
label?: string
|
|
15
|
-
Comp: ComponentType<CheckoutStepComponentProps>
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type ContactFormType = UseFormReturn<{
|
|
19
|
-
name: string
|
|
20
|
-
email: string
|
|
21
|
-
}, any, {
|
|
22
|
-
name: string
|
|
23
|
-
email: string
|
|
24
|
-
}>
|
|
25
|
-
|
|
26
|
-
interface PaymentMethodComponentProps {
|
|
27
|
-
onDone: () => void
|
|
28
|
-
transactionStatus: TransactionStatus
|
|
29
|
-
setTransactionStatus: (status: TransactionStatus) => void
|
|
30
|
-
storePaymentInfo: (paymentInfo: any) => Promise<void>
|
|
31
|
-
contactForm: ContactFormType
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface PaymentMethodDesc {
|
|
35
|
-
value: string
|
|
36
|
-
label: string
|
|
37
|
-
Comp: ComponentType<PaymentMethodComponentProps>
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export {
|
|
41
|
-
type TransactionStatus,
|
|
42
|
-
type CheckoutStepComponentProps,
|
|
43
|
-
type CheckoutStep,
|
|
44
|
-
type PaymentMethodComponentProps,
|
|
45
|
-
type PaymentMethodDesc,
|
|
46
|
-
type ContactFormType,
|
|
1
|
+
import type { ComponentType } from 'react'
|
|
2
|
+
import type { UseFormReturn } from 'react-hook-form'
|
|
3
|
+
|
|
4
|
+
type TransactionStatus = 'unpaid' | 'paid' | 'confirmed' | 'error'
|
|
5
|
+
|
|
6
|
+
interface CheckoutStepComponentProps {
|
|
7
|
+
onDone: () => void
|
|
8
|
+
orderId: string | undefined
|
|
9
|
+
setOrderId: (orderId: string | undefined) => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface CheckoutStep {
|
|
13
|
+
name: string
|
|
14
|
+
label?: string
|
|
15
|
+
Comp: ComponentType<CheckoutStepComponentProps>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type ContactFormType = UseFormReturn<{
|
|
19
|
+
name: string
|
|
20
|
+
email: string
|
|
21
|
+
}, any, {
|
|
22
|
+
name: string
|
|
23
|
+
email: string
|
|
24
|
+
}>
|
|
25
|
+
|
|
26
|
+
interface PaymentMethodComponentProps {
|
|
27
|
+
onDone: () => void
|
|
28
|
+
transactionStatus: TransactionStatus
|
|
29
|
+
setTransactionStatus: (status: TransactionStatus) => void
|
|
30
|
+
storePaymentInfo: (paymentInfo: any) => Promise<void>
|
|
31
|
+
contactForm: ContactFormType
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface PaymentMethodDesc {
|
|
35
|
+
value: string
|
|
36
|
+
label: string
|
|
37
|
+
Comp: ComponentType<PaymentMethodComponentProps>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
type TransactionStatus,
|
|
42
|
+
type CheckoutStepComponentProps,
|
|
43
|
+
type CheckoutStep,
|
|
44
|
+
type PaymentMethodComponentProps,
|
|
45
|
+
type PaymentMethodDesc,
|
|
46
|
+
type ContactFormType,
|
|
47
47
|
}
|
package/types/commerce-config.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { ServiceOptions } from '..'
|
|
2
|
-
import type { CategoryNode } from './category-node'
|
|
3
|
-
import type { Family } from './family'
|
|
4
|
-
import type { SelectionUISpecifier } from './selection-ui-specifier'
|
|
5
|
-
|
|
6
|
-
interface CommerceConfig {
|
|
7
|
-
families: Family[]
|
|
8
|
-
rootNode: CategoryNode
|
|
9
|
-
options?: ServiceOptions
|
|
10
|
-
uiSpecifiers?: Record<string, SelectionUISpecifier>
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { type CommerceConfig as default }
|
|
1
|
+
import type { ServiceOptions } from '..'
|
|
2
|
+
import type { CategoryNode } from './category-node'
|
|
3
|
+
import type { Family } from './family'
|
|
4
|
+
import type { SelectionUISpecifier } from './selection-ui-specifier'
|
|
5
|
+
|
|
6
|
+
interface CommerceConfig {
|
|
7
|
+
families: Family[]
|
|
8
|
+
rootNode: CategoryNode
|
|
9
|
+
options?: ServiceOptions
|
|
10
|
+
uiSpecifiers?: Record<string, SelectionUISpecifier>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { type CommerceConfig as default }
|
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
import type { LineItem, ObsLineItemRef } from './line-item'
|
|
2
|
-
import type { CategoryNode, SelectedPaths, CategoryNodeRole } from './category-node'
|
|
3
|
-
import type { Family, ObsFamilyRef} from './family'
|
|
4
|
-
import type Promo from './promo'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
interface CommerceService extends ObsLineItemRef, ObsFamilyRef {
|
|
8
|
-
|
|
9
|
-
/** Items in cart */
|
|
10
|
-
get cartItems(): LineItem[]
|
|
11
|
-
/** Total of all quantities of all items in cart */
|
|
12
|
-
get cartQuantity(): number
|
|
13
|
-
/** Total of all prices x quantities of items in cart */
|
|
14
|
-
get cartTotal(): number
|
|
15
|
-
|
|
16
|
-
get promoAppliedCartTotal(): number
|
|
17
|
-
|
|
18
|
-
get cartEmpty(): boolean
|
|
19
|
-
|
|
20
|
-
get appliedPromo(): Promo | null
|
|
21
|
-
setAppliedPromo(promo: Promo | null): void
|
|
22
|
-
/** returns the price with promo applied, of undefined if no promo or promo does not apply */
|
|
23
|
-
itemPromoPrice(item: LineItem): number | undefined
|
|
24
|
-
|
|
25
|
-
getFamilySubtotal(familyId: string): number
|
|
26
|
-
|
|
27
|
-
createOrder(email: string, name?: string): Promise<string | undefined>
|
|
28
|
-
updateOrderShippingInfo(orderId: string, shippingInfo: any): Promise<void>
|
|
29
|
-
updateOrderPaymentInfo(orderId: string, paymentInfo: any): Promise<void>
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Sets the tokens at each level supplied.
|
|
33
|
-
* If a level is selected as [], nothing will be selected.
|
|
34
|
-
* If a level is missing (undefined), everything at that level is selected
|
|
35
|
-
*
|
|
36
|
-
* This selects one or more Family's, and all the LineItem's in them.
|
|
37
|
-
*
|
|
38
|
-
* An empty value object selects all Family's and all LineItem's,
|
|
39
|
-
* */
|
|
40
|
-
selectPaths(value: SelectedPaths): Family[]
|
|
41
|
-
selectPath(skuPath: string): Family[]
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* With role as ...
|
|
45
|
-
*
|
|
46
|
-
* 'single-family':
|
|
47
|
-
* item: item with skuPath as SKU, otherwise undefined
|
|
48
|
-
* node: node at path (or item's parent node),
|
|
49
|
-
* family: node at path as family (or item's parent node as family),
|
|
50
|
-
* families: undefined
|
|
51
|
-
*
|
|
52
|
-
* 'family-in-multi-family':
|
|
53
|
-
* item: item with skuPath as SKU, otherwise undefined
|
|
54
|
-
* node: parent node of this family (or parent node of item's family)
|
|
55
|
-
* family: this family (or item's family)
|
|
56
|
-
* families: this family (or item's family) and siblings
|
|
57
|
-
*
|
|
58
|
-
* 'multi-family':
|
|
59
|
-
* item: undefined
|
|
60
|
-
* node: node at path
|
|
61
|
-
* family: undefined
|
|
62
|
-
* families: subnodes / families of this node
|
|
63
|
-
*
|
|
64
|
-
* 'non-outermost':
|
|
65
|
-
* item: undefined
|
|
66
|
-
* node: node at path
|
|
67
|
-
* family: undefined
|
|
68
|
-
* families: undefined
|
|
69
|
-
*
|
|
70
|
-
*/
|
|
71
|
-
peek(skuPath: string): {
|
|
72
|
-
role: CategoryNodeRole
|
|
73
|
-
family: Family | undefined
|
|
74
|
-
families: Family[] | undefined
|
|
75
|
-
node: CategoryNode | undefined
|
|
76
|
-
item: LineItem | undefined
|
|
77
|
-
} | string // or error string
|
|
78
|
-
|
|
79
|
-
/** @deprecated
|
|
80
|
-
* Whether this path defines a Family, or if it has further levels
|
|
81
|
-
* */
|
|
82
|
-
getNodeAtPath(skuPath: string): CategoryNode | undefined
|
|
83
|
-
|
|
84
|
-
get selectedPaths(): SelectedPaths // returns a copy
|
|
85
|
-
|
|
86
|
-
get selectedItems(): LineItem[]
|
|
87
|
-
get selectedFamilies(): Family[]
|
|
88
|
-
get hasSelection(): boolean
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Who are the subnodes selected at 'level'?
|
|
93
|
-
* If more than one value is selected at 'level',
|
|
94
|
-
* the returned CategoryNode[] may represent multiple sets.
|
|
95
|
-
* */
|
|
96
|
-
getSelectedNodesAtLevel(level: number): CategoryNode[] | undefined
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* For convenience, so widgets can share state.
|
|
100
|
-
* "current" is unrelated to what branches and items are
|
|
101
|
-
* "selected" (with CategoryNode's and paths)
|
|
102
|
-
*
|
|
103
|
-
* SEE ALSO: from ObsLineItemRef and ObsFamilyRef, there are also
|
|
104
|
-
* get item(): LineItem | undefined
|
|
105
|
-
* get family(): Family | undefined
|
|
106
|
-
*
|
|
107
|
-
* These simply delegate to these functions
|
|
108
|
-
* */
|
|
109
|
-
setCurrentItem(sku: string | undefined): boolean // valid sku and was set.
|
|
110
|
-
get currentItem(): LineItem | undefined
|
|
111
|
-
setCurrentFamily(id: string | undefined): boolean // valid id and was set.
|
|
112
|
-
get currentFamily(): Family | undefined
|
|
113
|
-
|
|
114
|
-
// utility
|
|
115
|
-
getFamilyById(id: string): Family | undefined
|
|
116
|
-
getItemBySku(sku: string): LineItem | undefined
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
export {
|
|
121
|
-
type CommerceService as default
|
|
1
|
+
import type { LineItem, ObsLineItemRef } from './line-item'
|
|
2
|
+
import type { CategoryNode, SelectedPaths, CategoryNodeRole } from './category-node'
|
|
3
|
+
import type { Family, ObsFamilyRef} from './family'
|
|
4
|
+
import type Promo from './promo'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
interface CommerceService extends ObsLineItemRef, ObsFamilyRef {
|
|
8
|
+
|
|
9
|
+
/** Items in cart */
|
|
10
|
+
get cartItems(): LineItem[]
|
|
11
|
+
/** Total of all quantities of all items in cart */
|
|
12
|
+
get cartQuantity(): number
|
|
13
|
+
/** Total of all prices x quantities of items in cart */
|
|
14
|
+
get cartTotal(): number
|
|
15
|
+
|
|
16
|
+
get promoAppliedCartTotal(): number
|
|
17
|
+
|
|
18
|
+
get cartEmpty(): boolean
|
|
19
|
+
|
|
20
|
+
get appliedPromo(): Promo | null
|
|
21
|
+
setAppliedPromo(promo: Promo | null): void
|
|
22
|
+
/** returns the price with promo applied, of undefined if no promo or promo does not apply */
|
|
23
|
+
itemPromoPrice(item: LineItem): number | undefined
|
|
24
|
+
|
|
25
|
+
getFamilySubtotal(familyId: string): number
|
|
26
|
+
|
|
27
|
+
createOrder(email: string, name?: string): Promise<string | undefined>
|
|
28
|
+
updateOrderShippingInfo(orderId: string, shippingInfo: any): Promise<void>
|
|
29
|
+
updateOrderPaymentInfo(orderId: string, paymentInfo: any): Promise<void>
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Sets the tokens at each level supplied.
|
|
33
|
+
* If a level is selected as [], nothing will be selected.
|
|
34
|
+
* If a level is missing (undefined), everything at that level is selected
|
|
35
|
+
*
|
|
36
|
+
* This selects one or more Family's, and all the LineItem's in them.
|
|
37
|
+
*
|
|
38
|
+
* An empty value object selects all Family's and all LineItem's,
|
|
39
|
+
* */
|
|
40
|
+
selectPaths(value: SelectedPaths): Family[]
|
|
41
|
+
selectPath(skuPath: string): Family[]
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* With role as ...
|
|
45
|
+
*
|
|
46
|
+
* 'single-family':
|
|
47
|
+
* item: item with skuPath as SKU, otherwise undefined
|
|
48
|
+
* node: node at path (or item's parent node),
|
|
49
|
+
* family: node at path as family (or item's parent node as family),
|
|
50
|
+
* families: undefined
|
|
51
|
+
*
|
|
52
|
+
* 'family-in-multi-family':
|
|
53
|
+
* item: item with skuPath as SKU, otherwise undefined
|
|
54
|
+
* node: parent node of this family (or parent node of item's family)
|
|
55
|
+
* family: this family (or item's family)
|
|
56
|
+
* families: this family (or item's family) and siblings
|
|
57
|
+
*
|
|
58
|
+
* 'multi-family':
|
|
59
|
+
* item: undefined
|
|
60
|
+
* node: node at path
|
|
61
|
+
* family: undefined
|
|
62
|
+
* families: subnodes / families of this node
|
|
63
|
+
*
|
|
64
|
+
* 'non-outermost':
|
|
65
|
+
* item: undefined
|
|
66
|
+
* node: node at path
|
|
67
|
+
* family: undefined
|
|
68
|
+
* families: undefined
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
peek(skuPath: string): {
|
|
72
|
+
role: CategoryNodeRole
|
|
73
|
+
family: Family | undefined
|
|
74
|
+
families: Family[] | undefined
|
|
75
|
+
node: CategoryNode | undefined
|
|
76
|
+
item: LineItem | undefined
|
|
77
|
+
} | string // or error string
|
|
78
|
+
|
|
79
|
+
/** @deprecated
|
|
80
|
+
* Whether this path defines a Family, or if it has further levels
|
|
81
|
+
* */
|
|
82
|
+
getNodeAtPath(skuPath: string): CategoryNode | undefined
|
|
83
|
+
|
|
84
|
+
get selectedPaths(): SelectedPaths // returns a copy
|
|
85
|
+
|
|
86
|
+
get selectedItems(): LineItem[]
|
|
87
|
+
get selectedFamilies(): Family[]
|
|
88
|
+
get hasSelection(): boolean
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Who are the subnodes selected at 'level'?
|
|
93
|
+
* If more than one value is selected at 'level',
|
|
94
|
+
* the returned CategoryNode[] may represent multiple sets.
|
|
95
|
+
* */
|
|
96
|
+
getSelectedNodesAtLevel(level: number): CategoryNode[] | undefined
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* For convenience, so widgets can share state.
|
|
100
|
+
* "current" is unrelated to what branches and items are
|
|
101
|
+
* "selected" (with CategoryNode's and paths)
|
|
102
|
+
*
|
|
103
|
+
* SEE ALSO: from ObsLineItemRef and ObsFamilyRef, there are also
|
|
104
|
+
* get item(): LineItem | undefined
|
|
105
|
+
* get family(): Family | undefined
|
|
106
|
+
*
|
|
107
|
+
* These simply delegate to these functions
|
|
108
|
+
* */
|
|
109
|
+
setCurrentItem(sku: string | undefined): boolean // valid sku and was set.
|
|
110
|
+
get currentItem(): LineItem | undefined
|
|
111
|
+
setCurrentFamily(id: string | undefined): boolean // valid id and was set.
|
|
112
|
+
get currentFamily(): Family | undefined
|
|
113
|
+
|
|
114
|
+
// utility
|
|
115
|
+
getFamilyById(id: string): Family | undefined
|
|
116
|
+
getItemBySku(sku: string): LineItem | undefined
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
export {
|
|
121
|
+
type CommerceService as default
|
|
122
122
|
}
|
package/types/family.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import type { ImageDef } from '@hanzo/ui/types'
|
|
2
|
-
import type Product from './product'
|
|
3
|
-
|
|
4
|
-
interface Family {
|
|
5
|
-
id: string // LXB-AU-B
|
|
6
|
-
title: string // Minted Bar, Lux Elite Card
|
|
7
|
-
titleShort?: string // Elite
|
|
8
|
-
parentTitle?: string // Lux Gold, Lux Credit
|
|
9
|
-
byline?: string // literal text, or name of function on 'this' object that returns a string
|
|
10
|
-
desc?: string
|
|
11
|
-
img?: ImageDef,
|
|
12
|
-
// inbound to the service, they're Products
|
|
13
|
-
// when it's initialized, interally they become LineItems
|
|
14
|
-
// always ok to cast up to LineItem thereafter
|
|
15
|
-
products: Product[]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
interface ObsFamilyRef {
|
|
20
|
-
get family(): Family | undefined
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export {
|
|
24
|
-
type Family,
|
|
25
|
-
type ObsFamilyRef
|
|
1
|
+
import type { ImageDef } from '@hanzo/ui/types'
|
|
2
|
+
import type Product from './product'
|
|
3
|
+
|
|
4
|
+
interface Family {
|
|
5
|
+
id: string // LXB-AU-B
|
|
6
|
+
title: string // Minted Bar, Lux Elite Card
|
|
7
|
+
titleShort?: string // Elite
|
|
8
|
+
parentTitle?: string // Lux Gold, Lux Credit
|
|
9
|
+
byline?: string // literal text, or name of function on 'this' object that returns a string
|
|
10
|
+
desc?: string
|
|
11
|
+
img?: ImageDef,
|
|
12
|
+
// inbound to the service, they're Products
|
|
13
|
+
// when it's initialized, interally they become LineItems
|
|
14
|
+
// always ok to cast up to LineItem thereafter
|
|
15
|
+
products: Product[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
interface ObsFamilyRef {
|
|
20
|
+
get family(): Family | undefined
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
type Family,
|
|
25
|
+
type ObsFamilyRef
|
|
26
26
|
}
|
package/types/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
export type { default as CommerceService } from './commerce-service'
|
|
3
|
-
export type { default as CommerceConfig } from './commerce-config'
|
|
4
|
-
export type { default as MultiFamilySelectorProps } from './multi-family-selector-props'
|
|
5
|
-
export type { default as Product } from './product'
|
|
6
|
-
export type { default as Promo } from './promo'
|
|
7
|
-
export type { default as TokenSeparators } from './token-separators'
|
|
8
|
-
|
|
9
|
-
export * from './category-node'
|
|
10
|
-
export * from './checkout'
|
|
11
|
-
export * from './family'
|
|
12
|
-
export * from './item-selector'
|
|
13
|
-
export * from './line-item'
|
|
14
|
-
export * from './selection-ui-specifier'
|
|
15
|
-
export * from './string-mutator'
|
|
1
|
+
|
|
2
|
+
export type { default as CommerceService } from './commerce-service'
|
|
3
|
+
export type { default as CommerceConfig } from './commerce-config'
|
|
4
|
+
export type { default as MultiFamilySelectorProps } from './multi-family-selector-props'
|
|
5
|
+
export type { default as Product } from './product'
|
|
6
|
+
export type { default as Promo } from './promo'
|
|
7
|
+
export type { default as TokenSeparators } from './token-separators'
|
|
8
|
+
|
|
9
|
+
export * from './category-node'
|
|
10
|
+
export * from './checkout'
|
|
11
|
+
export * from './family'
|
|
12
|
+
export * from './item-selector'
|
|
13
|
+
export * from './line-item'
|
|
14
|
+
export * from './selection-ui-specifier'
|
|
15
|
+
export * from './string-mutator'
|