@anker-in/shopify-react 1.3.0-beta.0 → 1.3.0-beta.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.
- package/dist/hooks/index.d.mts +93 -56
- package/dist/hooks/index.d.ts +93 -56
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/provider/index.d.mts +28 -14
- package/dist/provider/index.d.ts +28 -14
- package/dist/{types-CMMWxyUF.d.mts → types-CM5QrlnE.d.mts} +185 -15
- package/dist/{types-CMMWxyUF.d.ts → types-CM5QrlnE.d.ts} +185 -15
- package/package.json +2 -2
package/dist/hooks/index.d.mts
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
import * as swr_mutation from 'swr/mutation';
|
|
2
2
|
import { SWRMutationConfiguration } from 'swr/mutation';
|
|
3
3
|
import * as _anker_in_shopify_sdk from '@anker-in/shopify-sdk';
|
|
4
|
-
import { CartLineInput, NormalizedCart, NormalizedProduct, NormalizedProductVariant, NormalizedLineItem, UpdateCartLinesOptions, HasMetafieldsIdentifier, Media, NormalizedCollection, CollectionsConnection, NormalizedBlog, NormalizedArticle, NormalizedAttribute } from '@anker-in/shopify-sdk';
|
|
5
|
-
import {
|
|
6
|
-
export {
|
|
7
|
-
import Decimal from 'decimal.js';
|
|
4
|
+
import { CartLineInput, BuyerIdentityInput, NormalizedCart, NormalizedProduct, NormalizedProductVariant, NormalizedLineItem, UpdateCartLinesOptions, HasMetafieldsIdentifier, Media, NormalizedCollection, CollectionsConnection, NormalizedBlog, NormalizedArticle, NormalizedAttribute } from '@anker-in/shopify-sdk';
|
|
5
|
+
import { h as UseAddToCartOptions, g as AddToCartInput, A as AddToCartLineItem, G as GtmParams, C as BuyNowTrackConfig, e as UseScriptAutoFreeGiftResult, m as PlusMemberShippingMethodConfig, n as PlusMemberSettingsMetafields, D as DeliveryPlusType, o as SelectedPlusMemberVariant } from '../types-CM5QrlnE.mjs';
|
|
6
|
+
export { p as DeliveryCustomData, P as PLUS_MEMBER_TYPE, j as PlusMemberMode, l as PlusMemberShippingMethodMetafields, S as ScriptAutoFreeGiftConfig, k as ShippingMethodMode, U as UseAutoRemoveFreeGiftsOptions, a as UseAutoRemoveFreeGiftsResult, d as isAnyGift, c as isBuyGetGift, i as isFunctionGift, b as isScriptGift, u as useAutoRemoveFreeGifts, f as useScriptAutoFreeGift } from '../types-CM5QrlnE.mjs';
|
|
8
7
|
import * as swr from 'swr';
|
|
9
8
|
import swr__default, { SWRConfiguration } from 'swr';
|
|
10
9
|
import * as swr__internal from 'swr/_internal';
|
|
11
10
|
import * as React$1 from 'react';
|
|
12
11
|
import { Dispatch, SetStateAction, PropsWithChildren, RefObject } from 'react';
|
|
13
12
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
13
|
+
import 'decimal.js';
|
|
14
14
|
|
|
15
15
|
interface CreateCartInput {
|
|
16
16
|
/** Lines to add to the cart */
|
|
17
17
|
lines?: CartLineInput[];
|
|
18
18
|
/** Buyer identity for cart creation */
|
|
19
|
-
buyerIdentity?:
|
|
20
|
-
email?: string;
|
|
21
|
-
countryCode?: string;
|
|
22
|
-
};
|
|
19
|
+
buyerIdentity?: BuyerIdentityInput;
|
|
23
20
|
/** Discount codes */
|
|
24
21
|
discountCodes?: string[];
|
|
25
22
|
/** Custom attributes */
|
|
@@ -498,6 +495,52 @@ interface UseUpdateCartAttributesOptions {
|
|
|
498
495
|
*/
|
|
499
496
|
declare function useUpdateCartAttributes({ mutate, metafieldIdentifiers, disabled, swrOptions, }: UseUpdateCartAttributesOptions): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "update-cart-attributes", UpdateCartAttributesInput>;
|
|
500
497
|
|
|
498
|
+
interface UpdateBuyerIdentityInput {
|
|
499
|
+
/** Cart ID (optional, will use cookie) */
|
|
500
|
+
cartId?: string;
|
|
501
|
+
/** Buyer identity information */
|
|
502
|
+
buyerIdentity: BuyerIdentityInput;
|
|
503
|
+
}
|
|
504
|
+
interface UseUpdateBuyerIdentityOptions {
|
|
505
|
+
/** Function to update cart state */
|
|
506
|
+
mutate: (cart: NormalizedCart | undefined) => void;
|
|
507
|
+
/** Metafield identifiers for variant and product */
|
|
508
|
+
metafieldIdentifiers?: {
|
|
509
|
+
variant: HasMetafieldsIdentifier[];
|
|
510
|
+
product: HasMetafieldsIdentifier[];
|
|
511
|
+
};
|
|
512
|
+
/** Disable the mutation */
|
|
513
|
+
disabled?: boolean;
|
|
514
|
+
/** SWR mutation configuration */
|
|
515
|
+
swrOptions?: SWRMutationConfiguration<NormalizedCart | undefined, Error, 'update-buyer-identity', UpdateBuyerIdentityInput>;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Hook for updating buyer identity in the cart
|
|
519
|
+
*
|
|
520
|
+
* @param options - Hook configuration options
|
|
521
|
+
* @returns SWR mutation with trigger function
|
|
522
|
+
*
|
|
523
|
+
* @example
|
|
524
|
+
* ```tsx
|
|
525
|
+
* const { trigger, isMutating } = useUpdateBuyerIdentity({
|
|
526
|
+
* mutate: mutateCart,
|
|
527
|
+
* metafieldIdentifiers: {
|
|
528
|
+
* variant: [...],
|
|
529
|
+
* product: [...]
|
|
530
|
+
* }
|
|
531
|
+
* })
|
|
532
|
+
*
|
|
533
|
+
* await trigger({
|
|
534
|
+
* buyerIdentity: {
|
|
535
|
+
* email: 'customer@example.com',
|
|
536
|
+
* countryCode: 'US',
|
|
537
|
+
* phone: '+1234567890'
|
|
538
|
+
* }
|
|
539
|
+
* })
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
542
|
+
declare function useUpdateBuyerIdentity({ mutate, metafieldIdentifiers, disabled, swrOptions, }: UseUpdateBuyerIdentityOptions): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "update-buyer-identity", UpdateBuyerIdentityInput>;
|
|
543
|
+
|
|
501
544
|
interface BuyNowInput {
|
|
502
545
|
/** Metafield identifiers */
|
|
503
546
|
metafieldIdentifiers?: {
|
|
@@ -514,10 +557,7 @@ interface BuyNowInput {
|
|
|
514
557
|
value: string;
|
|
515
558
|
}>;
|
|
516
559
|
/** Buyer identity */
|
|
517
|
-
buyerIdentity?:
|
|
518
|
-
email?: string;
|
|
519
|
-
countryCode?: string;
|
|
520
|
-
};
|
|
560
|
+
buyerIdentity?: BuyerIdentityInput;
|
|
521
561
|
/** GTM tracking parameters */
|
|
522
562
|
gtmParams?: Omit<GtmParams, 'brand'>;
|
|
523
563
|
/** Facebook Pixel tracking configuration */
|
|
@@ -572,43 +612,6 @@ declare function useBuyNow({ withTrack }?: UseBuyNowOptions, swrOptions?: SWRMut
|
|
|
572
612
|
*/
|
|
573
613
|
declare const useCalcAutoFreeGift: (cart: any, autoFreeGiftConfig: AutoFreeGiftConfig, customer: any, lines?: AddToCartLineItem[]) => FunctionGiftResult;
|
|
574
614
|
|
|
575
|
-
interface GiveawayProduct {
|
|
576
|
-
handle: string;
|
|
577
|
-
sku: string;
|
|
578
|
-
}
|
|
579
|
-
interface Breakpoint {
|
|
580
|
-
breakpoint: string;
|
|
581
|
-
giveawayProducts: GiveawayProduct[];
|
|
582
|
-
}
|
|
583
|
-
interface Campaign {
|
|
584
|
-
activityAvailableQuery?: string;
|
|
585
|
-
activityQroperty?: string;
|
|
586
|
-
breakpoints?: Array<{
|
|
587
|
-
breakpoint: string;
|
|
588
|
-
giveawayProducts: GiveawayProduct[];
|
|
589
|
-
}>;
|
|
590
|
-
includeTags?: string[];
|
|
591
|
-
useTotalAmount?: boolean;
|
|
592
|
-
requireLogin?: boolean;
|
|
593
|
-
}
|
|
594
|
-
interface UseScriptAutoFreeGiftResult {
|
|
595
|
-
involvedLines: NormalizedLineItem[];
|
|
596
|
-
reorder: (a: NormalizedLineItem, b: NormalizedLineItem) => number;
|
|
597
|
-
disableCodeRemove: boolean;
|
|
598
|
-
nextFreeGiftLevel: Breakpoint | null;
|
|
599
|
-
freeGiftLevel: Breakpoint | null;
|
|
600
|
-
involvedSubTotal: Decimal;
|
|
601
|
-
giftProductsResult?: NormalizedProduct[];
|
|
602
|
-
}
|
|
603
|
-
declare const useScriptAutoFreeGift: ({ campaign, _giveaway, cart, locale: providedLocale, lines, profile, }: {
|
|
604
|
-
campaign: Campaign | null;
|
|
605
|
-
_giveaway: string;
|
|
606
|
-
cart: NormalizedCart | undefined;
|
|
607
|
-
locale?: string;
|
|
608
|
-
lines?: AddToCartLineItem[];
|
|
609
|
-
profile?: any;
|
|
610
|
-
}) => UseScriptAutoFreeGiftResult;
|
|
611
|
-
|
|
612
615
|
interface UseCalcGiftsFromLinesOptions {
|
|
613
616
|
/** Lines to calculate gifts from (AddToCartLineItem format) */
|
|
614
617
|
lines: AddToCartLineItem[];
|
|
@@ -695,36 +698,68 @@ declare const getReferralAttributes: () => {
|
|
|
695
698
|
key: string;
|
|
696
699
|
value: any;
|
|
697
700
|
}[];
|
|
701
|
+
/**
|
|
702
|
+
* Detect operating system
|
|
703
|
+
*/
|
|
704
|
+
declare const getOperatingSystem: () => "Android" | "IOS" | "Unknown";
|
|
698
705
|
/**
|
|
699
706
|
* Get user type based on customer information
|
|
700
707
|
*/
|
|
701
708
|
declare const getUserType: (customer?: any) => string;
|
|
709
|
+
/**
|
|
710
|
+
* Get GA4 attributes (sync version)
|
|
711
|
+
*/
|
|
712
|
+
declare function getGA4Attributes(ga4Data?: {
|
|
713
|
+
clientId?: string;
|
|
714
|
+
sessionId?: string;
|
|
715
|
+
} | null): Array<{
|
|
716
|
+
key: string;
|
|
717
|
+
value: string;
|
|
718
|
+
}>;
|
|
719
|
+
/**
|
|
720
|
+
* Get GA4 attributes (async version)
|
|
721
|
+
* Fetches GA4 data and returns formatted attributes
|
|
722
|
+
*/
|
|
723
|
+
declare function getGA4AttributesAsync(): Promise<Array<{
|
|
724
|
+
key: string;
|
|
725
|
+
value: string;
|
|
726
|
+
}>>;
|
|
702
727
|
interface GetCartAttributesProps {
|
|
703
728
|
profile?: any;
|
|
704
729
|
customer?: any;
|
|
705
730
|
cart?: NormalizedCart;
|
|
706
731
|
memberType?: string;
|
|
707
732
|
currentUrl?: string;
|
|
733
|
+
appContext?: {
|
|
734
|
+
isInApp?: boolean;
|
|
735
|
+
appName?: string;
|
|
736
|
+
};
|
|
737
|
+
buyPath?: 'hasCart' | 'buyNow';
|
|
708
738
|
}
|
|
709
739
|
/**
|
|
710
|
-
* Get cart attributes (pure function version)
|
|
740
|
+
* Get basic cart attributes (pure function version)
|
|
711
741
|
*/
|
|
712
|
-
declare function
|
|
742
|
+
declare function getCartBasicAttributes({ profile, customer, cart, memberType, currentUrl, appContext, buyPath, }: GetCartAttributesProps): Array<{
|
|
713
743
|
key: string;
|
|
714
|
-
value:
|
|
744
|
+
value: string;
|
|
715
745
|
}>;
|
|
716
746
|
/**
|
|
717
747
|
* Hook to get cart attributes
|
|
718
748
|
*/
|
|
719
|
-
declare const useCartAttributes: ({ profile, customer, cart, memberType, }: {
|
|
749
|
+
declare const useCartAttributes: ({ profile, customer, cart, memberType, appContext, buyPath, }: {
|
|
720
750
|
profile: any;
|
|
721
751
|
customer: any;
|
|
722
752
|
cart?: NormalizedCart;
|
|
723
753
|
memberType?: string;
|
|
754
|
+
appContext?: {
|
|
755
|
+
isInApp?: boolean;
|
|
756
|
+
appName?: string;
|
|
757
|
+
};
|
|
758
|
+
buyPath?: "hasCart" | "buyNow";
|
|
724
759
|
}) => {
|
|
725
760
|
attributes: Array<{
|
|
726
761
|
key: string;
|
|
727
|
-
value:
|
|
762
|
+
value: string;
|
|
728
763
|
}>;
|
|
729
764
|
};
|
|
730
765
|
|
|
@@ -749,7 +784,7 @@ declare const useCartItemQuantityLimit: ({ cart, cartItem, config, }: {
|
|
|
749
784
|
/**
|
|
750
785
|
* 更新购物车中各个 item 的折后价相关的属性
|
|
751
786
|
*/
|
|
752
|
-
declare const useUpdateLineCodeAmountAttributes: ({ cart, mutateCart, isCartLoading, setLoadingState, metafieldIdentifiers, }: {
|
|
787
|
+
declare const useUpdateLineCodeAmountAttributes: ({ cart, mutateCart, isCartLoading, setLoadingState, metafieldIdentifiers, disabled, }: {
|
|
753
788
|
cart?: NormalizedCart;
|
|
754
789
|
mutateCart: (cart: NormalizedCart | undefined) => void;
|
|
755
790
|
isCartLoading: boolean;
|
|
@@ -758,6 +793,8 @@ declare const useUpdateLineCodeAmountAttributes: ({ cart, mutateCart, isCartLoad
|
|
|
758
793
|
variant: HasMetafieldsIdentifier[];
|
|
759
794
|
product: HasMetafieldsIdentifier[];
|
|
760
795
|
};
|
|
796
|
+
/** 是否禁用更新 */
|
|
797
|
+
disabled?: boolean;
|
|
761
798
|
}) => void;
|
|
762
799
|
|
|
763
800
|
declare const currencyCodeMapping: Record<string, string>;
|
|
@@ -1982,4 +2019,4 @@ declare function getCachedGeoLocation(cacheKey?: string): GeoLocationData | unde
|
|
|
1982
2019
|
*/
|
|
1983
2020
|
declare function clearGeoLocationCache(cacheKey?: string): void;
|
|
1984
2021
|
|
|
1985
|
-
export { type AddCartLinesInput, AddToCartInput, AddToCartLineItem, type ApplyCartCodesInput, type AutoFreeGift, type AutoFreeGiftCartLineInput, type AutoFreeGiftConfig, type AutoFreeGiftItem, type AutoFreeGiftList, type AutoFreeGiftMainProduct, type BuyNowInput, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, type Config, type CreateCartInput, DeliveryPlusType, type DiscountLabel, type FormattedGift, type FunctionGiftResult, type GeoLocationData, type GetCartAttributesProps, type GiftProduct, type GiftProductItem, type GiftTier, type HasPlusMemberInCartProps, type HasPlusMemberInCartResult, type HasPlusMemberInLinesResult, type ImageMedia, type LocaleMapping, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, type MainProductInfo, type NormalizedSearchResultItem, type Options, OrderBasePriceType, type OrderDiscountConfig, type OrderDiscountResult, OrderDiscountType, PlusMemberContext, type PlusMemberContextValue, PlusMemberProvider, type PlusMemberProviderProps, PlusMemberSettingsMetafields, PlusMemberShippingMethodConfig, PriceBasePriceType, type PriceDiscountConfig, PriceDiscountType, type RemoveCartCodesInput, type RemoveCartLinesInput, type RewardItem, type RuleCondition, RuleType, SCRIPT_CODE_AMOUNT_KEY, type SearchResult, type SearchResultType, type SelectedOptionsResult, SelectedPlusMemberVariant, type ShippingMethodsContext, type SiteInfo, SpendMoneyType, type TieredDiscount, type UpdateCartAttributesInput, UseAddToCartOptions, type UseAllBlogsOptions, type UseAllCollectionsOptions, type UseAllProductsOptions, type UseArticleOptions, type UseArticlesInBlogOptions, type UseArticlesOptions, type UseAutoRemovePlusMemberInCartProps, type UseAvailableDeliveryCouponResult, type UseBlogOptions, type UseBuyNowOptions, type UseCalcGiftsFromLinesOptions, type UseCalcGiftsFromLinesResult, type UseCollectionOptions, type UseCollectionsOptions, type UseExposureOptions, type UseGeoLocationOptions, type UseHasPlusMemberInLinesProps, type UseIntersectionOptions, type UsePlusMemberVariantsOptions, type UsePlusMemberVariantsResult, type UsePriceOptions, type UsePriceResult, type UseProductOptions, type UseProductsByHandlesOptions,
|
|
2022
|
+
export { type AddCartLinesInput, AddToCartInput, AddToCartLineItem, type ApplyCartCodesInput, type AutoFreeGift, type AutoFreeGiftCartLineInput, type AutoFreeGiftConfig, type AutoFreeGiftItem, type AutoFreeGiftList, type AutoFreeGiftMainProduct, type BuyNowInput, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, type Config, type CreateCartInput, DeliveryPlusType, type DiscountLabel, type FormattedGift, type FunctionGiftResult, type GeoLocationData, type GetCartAttributesProps, type GiftProduct, type GiftProductItem, type GiftTier, type HasPlusMemberInCartProps, type HasPlusMemberInCartResult, type HasPlusMemberInLinesResult, type ImageMedia, type LocaleMapping, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, type MainProductInfo, type NormalizedSearchResultItem, type Options, OrderBasePriceType, type OrderDiscountConfig, type OrderDiscountResult, OrderDiscountType, PlusMemberContext, type PlusMemberContextValue, PlusMemberProvider, type PlusMemberProviderProps, PlusMemberSettingsMetafields, PlusMemberShippingMethodConfig, PriceBasePriceType, type PriceDiscountConfig, PriceDiscountType, type RemoveCartCodesInput, type RemoveCartLinesInput, type RewardItem, type RuleCondition, RuleType, SCRIPT_CODE_AMOUNT_KEY, type SearchResult, type SearchResultType, type SelectedOptionsResult, SelectedPlusMemberVariant, type ShippingMethodsContext, type SiteInfo, SpendMoneyType, type TieredDiscount, type UpdateBuyerIdentityInput, type UpdateCartAttributesInput, UseAddToCartOptions, type UseAllBlogsOptions, type UseAllCollectionsOptions, type UseAllProductsOptions, type UseArticleOptions, type UseArticlesInBlogOptions, type UseArticlesOptions, type UseAutoRemovePlusMemberInCartProps, type UseAvailableDeliveryCouponResult, type UseBlogOptions, type UseBuyNowOptions, type UseCalcGiftsFromLinesOptions, type UseCalcGiftsFromLinesResult, type UseCollectionOptions, type UseCollectionsOptions, type UseExposureOptions, type UseGeoLocationOptions, type UseHasPlusMemberInLinesProps, type UseIntersectionOptions, type UsePlusMemberVariantsOptions, type UsePlusMemberVariantsResult, type UsePriceOptions, type UsePriceResult, type UseProductOptions, type UseProductsByHandlesOptions, UseScriptAutoFreeGiftResult, type UseSearchOptions, type UseShippingMethodsOptions, type UseShippingMethodsResult, type UseSiteOptions, type UseUpdateBuyerIdentityOptions, type UseUpdateCartAttributesOptions, type VariantItem, type VariantMedia, type VideoMedia, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getCartBasicAttributes, getDiscountEnvAttributeValue, getGA4Attributes, getGA4AttributesAsync, getMatchedMainProductSubTotal, getOperatingSystem, getQuery, getReferralAttributes, getUserType, hasPlusMemberInCart, hasPlusMemberInLines, normalizeAddToCartLines, preCheck, safeParse, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useHasPlusMemberInLines, useIntersection, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberNeedAddToCart, usePlusMemberVariants, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useSearch, useSelectedOptions, useShippingMethods, useSite, useUpdateBuyerIdentity, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia };
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
import * as swr_mutation from 'swr/mutation';
|
|
2
2
|
import { SWRMutationConfiguration } from 'swr/mutation';
|
|
3
3
|
import * as _anker_in_shopify_sdk from '@anker-in/shopify-sdk';
|
|
4
|
-
import { CartLineInput, NormalizedCart, NormalizedProduct, NormalizedProductVariant, NormalizedLineItem, UpdateCartLinesOptions, HasMetafieldsIdentifier, Media, NormalizedCollection, CollectionsConnection, NormalizedBlog, NormalizedArticle, NormalizedAttribute } from '@anker-in/shopify-sdk';
|
|
5
|
-
import {
|
|
6
|
-
export {
|
|
7
|
-
import Decimal from 'decimal.js';
|
|
4
|
+
import { CartLineInput, BuyerIdentityInput, NormalizedCart, NormalizedProduct, NormalizedProductVariant, NormalizedLineItem, UpdateCartLinesOptions, HasMetafieldsIdentifier, Media, NormalizedCollection, CollectionsConnection, NormalizedBlog, NormalizedArticle, NormalizedAttribute } from '@anker-in/shopify-sdk';
|
|
5
|
+
import { h as UseAddToCartOptions, g as AddToCartInput, A as AddToCartLineItem, G as GtmParams, C as BuyNowTrackConfig, e as UseScriptAutoFreeGiftResult, m as PlusMemberShippingMethodConfig, n as PlusMemberSettingsMetafields, D as DeliveryPlusType, o as SelectedPlusMemberVariant } from '../types-CM5QrlnE.js';
|
|
6
|
+
export { p as DeliveryCustomData, P as PLUS_MEMBER_TYPE, j as PlusMemberMode, l as PlusMemberShippingMethodMetafields, S as ScriptAutoFreeGiftConfig, k as ShippingMethodMode, U as UseAutoRemoveFreeGiftsOptions, a as UseAutoRemoveFreeGiftsResult, d as isAnyGift, c as isBuyGetGift, i as isFunctionGift, b as isScriptGift, u as useAutoRemoveFreeGifts, f as useScriptAutoFreeGift } from '../types-CM5QrlnE.js';
|
|
8
7
|
import * as swr from 'swr';
|
|
9
8
|
import swr__default, { SWRConfiguration } from 'swr';
|
|
10
9
|
import * as swr__internal from 'swr/_internal';
|
|
11
10
|
import * as React$1 from 'react';
|
|
12
11
|
import { Dispatch, SetStateAction, PropsWithChildren, RefObject } from 'react';
|
|
13
12
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
13
|
+
import 'decimal.js';
|
|
14
14
|
|
|
15
15
|
interface CreateCartInput {
|
|
16
16
|
/** Lines to add to the cart */
|
|
17
17
|
lines?: CartLineInput[];
|
|
18
18
|
/** Buyer identity for cart creation */
|
|
19
|
-
buyerIdentity?:
|
|
20
|
-
email?: string;
|
|
21
|
-
countryCode?: string;
|
|
22
|
-
};
|
|
19
|
+
buyerIdentity?: BuyerIdentityInput;
|
|
23
20
|
/** Discount codes */
|
|
24
21
|
discountCodes?: string[];
|
|
25
22
|
/** Custom attributes */
|
|
@@ -498,6 +495,52 @@ interface UseUpdateCartAttributesOptions {
|
|
|
498
495
|
*/
|
|
499
496
|
declare function useUpdateCartAttributes({ mutate, metafieldIdentifiers, disabled, swrOptions, }: UseUpdateCartAttributesOptions): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "update-cart-attributes", UpdateCartAttributesInput>;
|
|
500
497
|
|
|
498
|
+
interface UpdateBuyerIdentityInput {
|
|
499
|
+
/** Cart ID (optional, will use cookie) */
|
|
500
|
+
cartId?: string;
|
|
501
|
+
/** Buyer identity information */
|
|
502
|
+
buyerIdentity: BuyerIdentityInput;
|
|
503
|
+
}
|
|
504
|
+
interface UseUpdateBuyerIdentityOptions {
|
|
505
|
+
/** Function to update cart state */
|
|
506
|
+
mutate: (cart: NormalizedCart | undefined) => void;
|
|
507
|
+
/** Metafield identifiers for variant and product */
|
|
508
|
+
metafieldIdentifiers?: {
|
|
509
|
+
variant: HasMetafieldsIdentifier[];
|
|
510
|
+
product: HasMetafieldsIdentifier[];
|
|
511
|
+
};
|
|
512
|
+
/** Disable the mutation */
|
|
513
|
+
disabled?: boolean;
|
|
514
|
+
/** SWR mutation configuration */
|
|
515
|
+
swrOptions?: SWRMutationConfiguration<NormalizedCart | undefined, Error, 'update-buyer-identity', UpdateBuyerIdentityInput>;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Hook for updating buyer identity in the cart
|
|
519
|
+
*
|
|
520
|
+
* @param options - Hook configuration options
|
|
521
|
+
* @returns SWR mutation with trigger function
|
|
522
|
+
*
|
|
523
|
+
* @example
|
|
524
|
+
* ```tsx
|
|
525
|
+
* const { trigger, isMutating } = useUpdateBuyerIdentity({
|
|
526
|
+
* mutate: mutateCart,
|
|
527
|
+
* metafieldIdentifiers: {
|
|
528
|
+
* variant: [...],
|
|
529
|
+
* product: [...]
|
|
530
|
+
* }
|
|
531
|
+
* })
|
|
532
|
+
*
|
|
533
|
+
* await trigger({
|
|
534
|
+
* buyerIdentity: {
|
|
535
|
+
* email: 'customer@example.com',
|
|
536
|
+
* countryCode: 'US',
|
|
537
|
+
* phone: '+1234567890'
|
|
538
|
+
* }
|
|
539
|
+
* })
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
542
|
+
declare function useUpdateBuyerIdentity({ mutate, metafieldIdentifiers, disabled, swrOptions, }: UseUpdateBuyerIdentityOptions): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "update-buyer-identity", UpdateBuyerIdentityInput>;
|
|
543
|
+
|
|
501
544
|
interface BuyNowInput {
|
|
502
545
|
/** Metafield identifiers */
|
|
503
546
|
metafieldIdentifiers?: {
|
|
@@ -514,10 +557,7 @@ interface BuyNowInput {
|
|
|
514
557
|
value: string;
|
|
515
558
|
}>;
|
|
516
559
|
/** Buyer identity */
|
|
517
|
-
buyerIdentity?:
|
|
518
|
-
email?: string;
|
|
519
|
-
countryCode?: string;
|
|
520
|
-
};
|
|
560
|
+
buyerIdentity?: BuyerIdentityInput;
|
|
521
561
|
/** GTM tracking parameters */
|
|
522
562
|
gtmParams?: Omit<GtmParams, 'brand'>;
|
|
523
563
|
/** Facebook Pixel tracking configuration */
|
|
@@ -572,43 +612,6 @@ declare function useBuyNow({ withTrack }?: UseBuyNowOptions, swrOptions?: SWRMut
|
|
|
572
612
|
*/
|
|
573
613
|
declare const useCalcAutoFreeGift: (cart: any, autoFreeGiftConfig: AutoFreeGiftConfig, customer: any, lines?: AddToCartLineItem[]) => FunctionGiftResult;
|
|
574
614
|
|
|
575
|
-
interface GiveawayProduct {
|
|
576
|
-
handle: string;
|
|
577
|
-
sku: string;
|
|
578
|
-
}
|
|
579
|
-
interface Breakpoint {
|
|
580
|
-
breakpoint: string;
|
|
581
|
-
giveawayProducts: GiveawayProduct[];
|
|
582
|
-
}
|
|
583
|
-
interface Campaign {
|
|
584
|
-
activityAvailableQuery?: string;
|
|
585
|
-
activityQroperty?: string;
|
|
586
|
-
breakpoints?: Array<{
|
|
587
|
-
breakpoint: string;
|
|
588
|
-
giveawayProducts: GiveawayProduct[];
|
|
589
|
-
}>;
|
|
590
|
-
includeTags?: string[];
|
|
591
|
-
useTotalAmount?: boolean;
|
|
592
|
-
requireLogin?: boolean;
|
|
593
|
-
}
|
|
594
|
-
interface UseScriptAutoFreeGiftResult {
|
|
595
|
-
involvedLines: NormalizedLineItem[];
|
|
596
|
-
reorder: (a: NormalizedLineItem, b: NormalizedLineItem) => number;
|
|
597
|
-
disableCodeRemove: boolean;
|
|
598
|
-
nextFreeGiftLevel: Breakpoint | null;
|
|
599
|
-
freeGiftLevel: Breakpoint | null;
|
|
600
|
-
involvedSubTotal: Decimal;
|
|
601
|
-
giftProductsResult?: NormalizedProduct[];
|
|
602
|
-
}
|
|
603
|
-
declare const useScriptAutoFreeGift: ({ campaign, _giveaway, cart, locale: providedLocale, lines, profile, }: {
|
|
604
|
-
campaign: Campaign | null;
|
|
605
|
-
_giveaway: string;
|
|
606
|
-
cart: NormalizedCart | undefined;
|
|
607
|
-
locale?: string;
|
|
608
|
-
lines?: AddToCartLineItem[];
|
|
609
|
-
profile?: any;
|
|
610
|
-
}) => UseScriptAutoFreeGiftResult;
|
|
611
|
-
|
|
612
615
|
interface UseCalcGiftsFromLinesOptions {
|
|
613
616
|
/** Lines to calculate gifts from (AddToCartLineItem format) */
|
|
614
617
|
lines: AddToCartLineItem[];
|
|
@@ -695,36 +698,68 @@ declare const getReferralAttributes: () => {
|
|
|
695
698
|
key: string;
|
|
696
699
|
value: any;
|
|
697
700
|
}[];
|
|
701
|
+
/**
|
|
702
|
+
* Detect operating system
|
|
703
|
+
*/
|
|
704
|
+
declare const getOperatingSystem: () => "Android" | "IOS" | "Unknown";
|
|
698
705
|
/**
|
|
699
706
|
* Get user type based on customer information
|
|
700
707
|
*/
|
|
701
708
|
declare const getUserType: (customer?: any) => string;
|
|
709
|
+
/**
|
|
710
|
+
* Get GA4 attributes (sync version)
|
|
711
|
+
*/
|
|
712
|
+
declare function getGA4Attributes(ga4Data?: {
|
|
713
|
+
clientId?: string;
|
|
714
|
+
sessionId?: string;
|
|
715
|
+
} | null): Array<{
|
|
716
|
+
key: string;
|
|
717
|
+
value: string;
|
|
718
|
+
}>;
|
|
719
|
+
/**
|
|
720
|
+
* Get GA4 attributes (async version)
|
|
721
|
+
* Fetches GA4 data and returns formatted attributes
|
|
722
|
+
*/
|
|
723
|
+
declare function getGA4AttributesAsync(): Promise<Array<{
|
|
724
|
+
key: string;
|
|
725
|
+
value: string;
|
|
726
|
+
}>>;
|
|
702
727
|
interface GetCartAttributesProps {
|
|
703
728
|
profile?: any;
|
|
704
729
|
customer?: any;
|
|
705
730
|
cart?: NormalizedCart;
|
|
706
731
|
memberType?: string;
|
|
707
732
|
currentUrl?: string;
|
|
733
|
+
appContext?: {
|
|
734
|
+
isInApp?: boolean;
|
|
735
|
+
appName?: string;
|
|
736
|
+
};
|
|
737
|
+
buyPath?: 'hasCart' | 'buyNow';
|
|
708
738
|
}
|
|
709
739
|
/**
|
|
710
|
-
* Get cart attributes (pure function version)
|
|
740
|
+
* Get basic cart attributes (pure function version)
|
|
711
741
|
*/
|
|
712
|
-
declare function
|
|
742
|
+
declare function getCartBasicAttributes({ profile, customer, cart, memberType, currentUrl, appContext, buyPath, }: GetCartAttributesProps): Array<{
|
|
713
743
|
key: string;
|
|
714
|
-
value:
|
|
744
|
+
value: string;
|
|
715
745
|
}>;
|
|
716
746
|
/**
|
|
717
747
|
* Hook to get cart attributes
|
|
718
748
|
*/
|
|
719
|
-
declare const useCartAttributes: ({ profile, customer, cart, memberType, }: {
|
|
749
|
+
declare const useCartAttributes: ({ profile, customer, cart, memberType, appContext, buyPath, }: {
|
|
720
750
|
profile: any;
|
|
721
751
|
customer: any;
|
|
722
752
|
cart?: NormalizedCart;
|
|
723
753
|
memberType?: string;
|
|
754
|
+
appContext?: {
|
|
755
|
+
isInApp?: boolean;
|
|
756
|
+
appName?: string;
|
|
757
|
+
};
|
|
758
|
+
buyPath?: "hasCart" | "buyNow";
|
|
724
759
|
}) => {
|
|
725
760
|
attributes: Array<{
|
|
726
761
|
key: string;
|
|
727
|
-
value:
|
|
762
|
+
value: string;
|
|
728
763
|
}>;
|
|
729
764
|
};
|
|
730
765
|
|
|
@@ -749,7 +784,7 @@ declare const useCartItemQuantityLimit: ({ cart, cartItem, config, }: {
|
|
|
749
784
|
/**
|
|
750
785
|
* 更新购物车中各个 item 的折后价相关的属性
|
|
751
786
|
*/
|
|
752
|
-
declare const useUpdateLineCodeAmountAttributes: ({ cart, mutateCart, isCartLoading, setLoadingState, metafieldIdentifiers, }: {
|
|
787
|
+
declare const useUpdateLineCodeAmountAttributes: ({ cart, mutateCart, isCartLoading, setLoadingState, metafieldIdentifiers, disabled, }: {
|
|
753
788
|
cart?: NormalizedCart;
|
|
754
789
|
mutateCart: (cart: NormalizedCart | undefined) => void;
|
|
755
790
|
isCartLoading: boolean;
|
|
@@ -758,6 +793,8 @@ declare const useUpdateLineCodeAmountAttributes: ({ cart, mutateCart, isCartLoad
|
|
|
758
793
|
variant: HasMetafieldsIdentifier[];
|
|
759
794
|
product: HasMetafieldsIdentifier[];
|
|
760
795
|
};
|
|
796
|
+
/** 是否禁用更新 */
|
|
797
|
+
disabled?: boolean;
|
|
761
798
|
}) => void;
|
|
762
799
|
|
|
763
800
|
declare const currencyCodeMapping: Record<string, string>;
|
|
@@ -1982,4 +2019,4 @@ declare function getCachedGeoLocation(cacheKey?: string): GeoLocationData | unde
|
|
|
1982
2019
|
*/
|
|
1983
2020
|
declare function clearGeoLocationCache(cacheKey?: string): void;
|
|
1984
2021
|
|
|
1985
|
-
export { type AddCartLinesInput, AddToCartInput, AddToCartLineItem, type ApplyCartCodesInput, type AutoFreeGift, type AutoFreeGiftCartLineInput, type AutoFreeGiftConfig, type AutoFreeGiftItem, type AutoFreeGiftList, type AutoFreeGiftMainProduct, type BuyNowInput, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, type Config, type CreateCartInput, DeliveryPlusType, type DiscountLabel, type FormattedGift, type FunctionGiftResult, type GeoLocationData, type GetCartAttributesProps, type GiftProduct, type GiftProductItem, type GiftTier, type HasPlusMemberInCartProps, type HasPlusMemberInCartResult, type HasPlusMemberInLinesResult, type ImageMedia, type LocaleMapping, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, type MainProductInfo, type NormalizedSearchResultItem, type Options, OrderBasePriceType, type OrderDiscountConfig, type OrderDiscountResult, OrderDiscountType, PlusMemberContext, type PlusMemberContextValue, PlusMemberProvider, type PlusMemberProviderProps, PlusMemberSettingsMetafields, PlusMemberShippingMethodConfig, PriceBasePriceType, type PriceDiscountConfig, PriceDiscountType, type RemoveCartCodesInput, type RemoveCartLinesInput, type RewardItem, type RuleCondition, RuleType, SCRIPT_CODE_AMOUNT_KEY, type SearchResult, type SearchResultType, type SelectedOptionsResult, SelectedPlusMemberVariant, type ShippingMethodsContext, type SiteInfo, SpendMoneyType, type TieredDiscount, type UpdateCartAttributesInput, UseAddToCartOptions, type UseAllBlogsOptions, type UseAllCollectionsOptions, type UseAllProductsOptions, type UseArticleOptions, type UseArticlesInBlogOptions, type UseArticlesOptions, type UseAutoRemovePlusMemberInCartProps, type UseAvailableDeliveryCouponResult, type UseBlogOptions, type UseBuyNowOptions, type UseCalcGiftsFromLinesOptions, type UseCalcGiftsFromLinesResult, type UseCollectionOptions, type UseCollectionsOptions, type UseExposureOptions, type UseGeoLocationOptions, type UseHasPlusMemberInLinesProps, type UseIntersectionOptions, type UsePlusMemberVariantsOptions, type UsePlusMemberVariantsResult, type UsePriceOptions, type UsePriceResult, type UseProductOptions, type UseProductsByHandlesOptions,
|
|
2022
|
+
export { type AddCartLinesInput, AddToCartInput, AddToCartLineItem, type ApplyCartCodesInput, type AutoFreeGift, type AutoFreeGiftCartLineInput, type AutoFreeGiftConfig, type AutoFreeGiftItem, type AutoFreeGiftList, type AutoFreeGiftMainProduct, type BuyNowInput, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, type Config, type CreateCartInput, DeliveryPlusType, type DiscountLabel, type FormattedGift, type FunctionGiftResult, type GeoLocationData, type GetCartAttributesProps, type GiftProduct, type GiftProductItem, type GiftTier, type HasPlusMemberInCartProps, type HasPlusMemberInCartResult, type HasPlusMemberInLinesResult, type ImageMedia, type LocaleMapping, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, type MainProductInfo, type NormalizedSearchResultItem, type Options, OrderBasePriceType, type OrderDiscountConfig, type OrderDiscountResult, OrderDiscountType, PlusMemberContext, type PlusMemberContextValue, PlusMemberProvider, type PlusMemberProviderProps, PlusMemberSettingsMetafields, PlusMemberShippingMethodConfig, PriceBasePriceType, type PriceDiscountConfig, PriceDiscountType, type RemoveCartCodesInput, type RemoveCartLinesInput, type RewardItem, type RuleCondition, RuleType, SCRIPT_CODE_AMOUNT_KEY, type SearchResult, type SearchResultType, type SelectedOptionsResult, SelectedPlusMemberVariant, type ShippingMethodsContext, type SiteInfo, SpendMoneyType, type TieredDiscount, type UpdateBuyerIdentityInput, type UpdateCartAttributesInput, UseAddToCartOptions, type UseAllBlogsOptions, type UseAllCollectionsOptions, type UseAllProductsOptions, type UseArticleOptions, type UseArticlesInBlogOptions, type UseArticlesOptions, type UseAutoRemovePlusMemberInCartProps, type UseAvailableDeliveryCouponResult, type UseBlogOptions, type UseBuyNowOptions, type UseCalcGiftsFromLinesOptions, type UseCalcGiftsFromLinesResult, type UseCollectionOptions, type UseCollectionsOptions, type UseExposureOptions, type UseGeoLocationOptions, type UseHasPlusMemberInLinesProps, type UseIntersectionOptions, type UsePlusMemberVariantsOptions, type UsePlusMemberVariantsResult, type UsePriceOptions, type UsePriceResult, type UseProductOptions, type UseProductsByHandlesOptions, UseScriptAutoFreeGiftResult, type UseSearchOptions, type UseShippingMethodsOptions, type UseShippingMethodsResult, type UseSiteOptions, type UseUpdateBuyerIdentityOptions, type UseUpdateCartAttributesOptions, type VariantItem, type VariantMedia, type VideoMedia, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getCartBasicAttributes, getDiscountEnvAttributeValue, getGA4Attributes, getGA4AttributesAsync, getMatchedMainProductSubTotal, getOperatingSystem, getQuery, getReferralAttributes, getUserType, hasPlusMemberInCart, hasPlusMemberInLines, normalizeAddToCartLines, preCheck, safeParse, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useHasPlusMemberInLines, useIntersection, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberNeedAddToCart, usePlusMemberVariants, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useSearch, useSelectedOptions, useShippingMethods, useSite, useUpdateBuyerIdentity, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export { CartContextValue, CartProvider, CartProviderProps, LoadingState, ShopifyContext, ShopifyContextValue, ShopifyProvider, ShopifyProviderProps, useCartContext, useShopify } from './provider/index.mjs';
|
|
1
|
+
export { AppContext, CartContextValue, CartProvider, CartProviderProps, LoadingState, ShopifyContext, ShopifyContextValue, ShopifyProvider, ShopifyProviderProps, useCartContext, useShopify } from './provider/index.mjs';
|
|
2
2
|
export { C as CookieAdapter, a as CookieOptions, P as PerformanceAdapter, R as RouterAdapter, U as UserContextAdapter } from './types-SKDHauqk.mjs';
|
|
3
3
|
export { BrowserPerformanceAdapter, browserCartCookieAdapter, browserCookieAdapter } from './adapters/index.mjs';
|
|
4
|
-
export { AddCartLinesInput, ApplyCartCodesInput, AutoFreeGift, AutoFreeGiftCartLineInput, AutoFreeGiftConfig, AutoFreeGiftItem, AutoFreeGiftList, AutoFreeGiftMainProduct, BuyNowInput, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, Config, CreateCartInput, DiscountLabel, FormattedGift, FunctionGiftResult, GeoLocationData, GetCartAttributesProps, GiftProduct, GiftProductItem, GiftTier, HasPlusMemberInCartProps, HasPlusMemberInCartResult, HasPlusMemberInLinesResult, ImageMedia, LocaleMapping, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, MainProductInfo, NormalizedSearchResultItem, Options, OrderBasePriceType, OrderDiscountConfig, OrderDiscountResult, OrderDiscountType, PlusMemberContext, PlusMemberContextValue, PlusMemberProvider, PlusMemberProviderProps, PriceBasePriceType, PriceDiscountConfig, PriceDiscountType, RemoveCartCodesInput, RemoveCartLinesInput, RewardItem, RuleCondition, RuleType, SCRIPT_CODE_AMOUNT_KEY, SearchResult, SearchResultType, SelectedOptionsResult, ShippingMethodsContext, SiteInfo, SpendMoneyType, TieredDiscount, UpdateCartAttributesInput, UseAllBlogsOptions, UseAllCollectionsOptions, UseAllProductsOptions, UseArticleOptions, UseArticlesInBlogOptions, UseArticlesOptions, UseAutoRemovePlusMemberInCartProps, UseAvailableDeliveryCouponResult, UseBlogOptions, UseBuyNowOptions, UseCalcGiftsFromLinesOptions, UseCalcGiftsFromLinesResult, UseCollectionOptions, UseCollectionsOptions, UseExposureOptions, UseGeoLocationOptions, UseHasPlusMemberInLinesProps, UseIntersectionOptions, UsePlusMemberVariantsOptions, UsePlusMemberVariantsResult, UsePriceOptions, UsePriceResult, UseProductOptions, UseProductsByHandlesOptions,
|
|
5
|
-
export {
|
|
4
|
+
export { AddCartLinesInput, ApplyCartCodesInput, AutoFreeGift, AutoFreeGiftCartLineInput, AutoFreeGiftConfig, AutoFreeGiftItem, AutoFreeGiftList, AutoFreeGiftMainProduct, BuyNowInput, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, Config, CreateCartInput, DiscountLabel, FormattedGift, FunctionGiftResult, GeoLocationData, GetCartAttributesProps, GiftProduct, GiftProductItem, GiftTier, HasPlusMemberInCartProps, HasPlusMemberInCartResult, HasPlusMemberInLinesResult, ImageMedia, LocaleMapping, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, MainProductInfo, NormalizedSearchResultItem, Options, OrderBasePriceType, OrderDiscountConfig, OrderDiscountResult, OrderDiscountType, PlusMemberContext, PlusMemberContextValue, PlusMemberProvider, PlusMemberProviderProps, PriceBasePriceType, PriceDiscountConfig, PriceDiscountType, RemoveCartCodesInput, RemoveCartLinesInput, RewardItem, RuleCondition, RuleType, SCRIPT_CODE_AMOUNT_KEY, SearchResult, SearchResultType, SelectedOptionsResult, ShippingMethodsContext, SiteInfo, SpendMoneyType, TieredDiscount, UpdateBuyerIdentityInput, UpdateCartAttributesInput, UseAllBlogsOptions, UseAllCollectionsOptions, UseAllProductsOptions, UseArticleOptions, UseArticlesInBlogOptions, UseArticlesOptions, UseAutoRemovePlusMemberInCartProps, UseAvailableDeliveryCouponResult, UseBlogOptions, UseBuyNowOptions, UseCalcGiftsFromLinesOptions, UseCalcGiftsFromLinesResult, UseCollectionOptions, UseCollectionsOptions, UseExposureOptions, UseGeoLocationOptions, UseHasPlusMemberInLinesProps, UseIntersectionOptions, UsePlusMemberVariantsOptions, UsePlusMemberVariantsResult, UsePriceOptions, UsePriceResult, UseProductOptions, UseProductsByHandlesOptions, UseSearchOptions, UseShippingMethodsOptions, UseShippingMethodsResult, UseSiteOptions, UseUpdateBuyerIdentityOptions, UseUpdateCartAttributesOptions, VariantItem, VariantMedia, VideoMedia, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getCartBasicAttributes, getDiscountEnvAttributeValue, getGA4Attributes, getGA4AttributesAsync, getMatchedMainProductSubTotal, getOperatingSystem, getQuery, getReferralAttributes, getUserType, hasPlusMemberInCart, hasPlusMemberInLines, normalizeAddToCartLines, preCheck, safeParse, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useHasPlusMemberInLines, useIntersection, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberNeedAddToCart, usePlusMemberVariants, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useSearch, useSelectedOptions, useShippingMethods, useSite, useUpdateBuyerIdentity, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia } from './hooks/index.mjs';
|
|
5
|
+
export { g as AddToCartInput, A as AddToCartLineItem, C as BuyNowTrackConfig, p as DeliveryCustomData, D as DeliveryPlusType, v as GA4Data, G as GtmParams, P as PLUS_MEMBER_TYPE, j as PlusMemberMode, n as PlusMemberSettingsMetafields, m as PlusMemberShippingMethodConfig, l as PlusMemberShippingMethodMetafields, S as ScriptAutoFreeGiftConfig, o as SelectedPlusMemberVariant, k as ShippingMethodMode, h as UseAddToCartOptions, U as UseAutoRemoveFreeGiftsOptions, a as UseAutoRemoveFreeGiftsResult, e as UseScriptAutoFreeGiftResult, q as gaTrack, x as getGA4ClientId, z as getGA4Data, y as getGA4SessionId, d as isAnyGift, c as isBuyGetGift, i as isFunctionGift, b as isScriptGift, B as trackAddToCartFBQ, t as trackAddToCartGA, r as trackBeginCheckoutGA, E as trackBuyNowFBQ, s as trackBuyNowGA, u as useAutoRemoveFreeGifts, f as useScriptAutoFreeGift, w as waitForGtagReady } from './types-CM5QrlnE.mjs';
|
|
6
6
|
export * from '@anker-in/shopify-sdk';
|
|
7
7
|
import 'react';
|
|
8
8
|
import 'react/jsx-runtime';
|
|
9
9
|
import 'swr';
|
|
10
10
|
import 'swr/mutation';
|
|
11
|
-
import 'decimal.js';
|
|
12
11
|
import 'swr/_internal';
|
|
12
|
+
import 'decimal.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Utility types for TypeScript
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export { CartContextValue, CartProvider, CartProviderProps, LoadingState, ShopifyContext, ShopifyContextValue, ShopifyProvider, ShopifyProviderProps, useCartContext, useShopify } from './provider/index.js';
|
|
1
|
+
export { AppContext, CartContextValue, CartProvider, CartProviderProps, LoadingState, ShopifyContext, ShopifyContextValue, ShopifyProvider, ShopifyProviderProps, useCartContext, useShopify } from './provider/index.js';
|
|
2
2
|
export { C as CookieAdapter, a as CookieOptions, P as PerformanceAdapter, R as RouterAdapter, U as UserContextAdapter } from './types-SKDHauqk.js';
|
|
3
3
|
export { BrowserPerformanceAdapter, browserCartCookieAdapter, browserCookieAdapter } from './adapters/index.js';
|
|
4
|
-
export { AddCartLinesInput, ApplyCartCodesInput, AutoFreeGift, AutoFreeGiftCartLineInput, AutoFreeGiftConfig, AutoFreeGiftItem, AutoFreeGiftList, AutoFreeGiftMainProduct, BuyNowInput, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, Config, CreateCartInput, DiscountLabel, FormattedGift, FunctionGiftResult, GeoLocationData, GetCartAttributesProps, GiftProduct, GiftProductItem, GiftTier, HasPlusMemberInCartProps, HasPlusMemberInCartResult, HasPlusMemberInLinesResult, ImageMedia, LocaleMapping, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, MainProductInfo, NormalizedSearchResultItem, Options, OrderBasePriceType, OrderDiscountConfig, OrderDiscountResult, OrderDiscountType, PlusMemberContext, PlusMemberContextValue, PlusMemberProvider, PlusMemberProviderProps, PriceBasePriceType, PriceDiscountConfig, PriceDiscountType, RemoveCartCodesInput, RemoveCartLinesInput, RewardItem, RuleCondition, RuleType, SCRIPT_CODE_AMOUNT_KEY, SearchResult, SearchResultType, SelectedOptionsResult, ShippingMethodsContext, SiteInfo, SpendMoneyType, TieredDiscount, UpdateCartAttributesInput, UseAllBlogsOptions, UseAllCollectionsOptions, UseAllProductsOptions, UseArticleOptions, UseArticlesInBlogOptions, UseArticlesOptions, UseAutoRemovePlusMemberInCartProps, UseAvailableDeliveryCouponResult, UseBlogOptions, UseBuyNowOptions, UseCalcGiftsFromLinesOptions, UseCalcGiftsFromLinesResult, UseCollectionOptions, UseCollectionsOptions, UseExposureOptions, UseGeoLocationOptions, UseHasPlusMemberInLinesProps, UseIntersectionOptions, UsePlusMemberVariantsOptions, UsePlusMemberVariantsResult, UsePriceOptions, UsePriceResult, UseProductOptions, UseProductsByHandlesOptions,
|
|
5
|
-
export {
|
|
4
|
+
export { AddCartLinesInput, ApplyCartCodesInput, AutoFreeGift, AutoFreeGiftCartLineInput, AutoFreeGiftConfig, AutoFreeGiftItem, AutoFreeGiftList, AutoFreeGiftMainProduct, BuyNowInput, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, Config, CreateCartInput, DiscountLabel, FormattedGift, FunctionGiftResult, GeoLocationData, GetCartAttributesProps, GiftProduct, GiftProductItem, GiftTier, HasPlusMemberInCartProps, HasPlusMemberInCartResult, HasPlusMemberInLinesResult, ImageMedia, LocaleMapping, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, MainProductInfo, NormalizedSearchResultItem, Options, OrderBasePriceType, OrderDiscountConfig, OrderDiscountResult, OrderDiscountType, PlusMemberContext, PlusMemberContextValue, PlusMemberProvider, PlusMemberProviderProps, PriceBasePriceType, PriceDiscountConfig, PriceDiscountType, RemoveCartCodesInput, RemoveCartLinesInput, RewardItem, RuleCondition, RuleType, SCRIPT_CODE_AMOUNT_KEY, SearchResult, SearchResultType, SelectedOptionsResult, ShippingMethodsContext, SiteInfo, SpendMoneyType, TieredDiscount, UpdateBuyerIdentityInput, UpdateCartAttributesInput, UseAllBlogsOptions, UseAllCollectionsOptions, UseAllProductsOptions, UseArticleOptions, UseArticlesInBlogOptions, UseArticlesOptions, UseAutoRemovePlusMemberInCartProps, UseAvailableDeliveryCouponResult, UseBlogOptions, UseBuyNowOptions, UseCalcGiftsFromLinesOptions, UseCalcGiftsFromLinesResult, UseCollectionOptions, UseCollectionsOptions, UseExposureOptions, UseGeoLocationOptions, UseHasPlusMemberInLinesProps, UseIntersectionOptions, UsePlusMemberVariantsOptions, UsePlusMemberVariantsResult, UsePriceOptions, UsePriceResult, UseProductOptions, UseProductsByHandlesOptions, UseSearchOptions, UseShippingMethodsOptions, UseShippingMethodsResult, UseSiteOptions, UseUpdateBuyerIdentityOptions, UseUpdateCartAttributesOptions, VariantItem, VariantMedia, VideoMedia, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getCartBasicAttributes, getDiscountEnvAttributeValue, getGA4Attributes, getGA4AttributesAsync, getMatchedMainProductSubTotal, getOperatingSystem, getQuery, getReferralAttributes, getUserType, hasPlusMemberInCart, hasPlusMemberInLines, normalizeAddToCartLines, preCheck, safeParse, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useHasPlusMemberInLines, useIntersection, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberNeedAddToCart, usePlusMemberVariants, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useSearch, useSelectedOptions, useShippingMethods, useSite, useUpdateBuyerIdentity, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia } from './hooks/index.js';
|
|
5
|
+
export { g as AddToCartInput, A as AddToCartLineItem, C as BuyNowTrackConfig, p as DeliveryCustomData, D as DeliveryPlusType, v as GA4Data, G as GtmParams, P as PLUS_MEMBER_TYPE, j as PlusMemberMode, n as PlusMemberSettingsMetafields, m as PlusMemberShippingMethodConfig, l as PlusMemberShippingMethodMetafields, S as ScriptAutoFreeGiftConfig, o as SelectedPlusMemberVariant, k as ShippingMethodMode, h as UseAddToCartOptions, U as UseAutoRemoveFreeGiftsOptions, a as UseAutoRemoveFreeGiftsResult, e as UseScriptAutoFreeGiftResult, q as gaTrack, x as getGA4ClientId, z as getGA4Data, y as getGA4SessionId, d as isAnyGift, c as isBuyGetGift, i as isFunctionGift, b as isScriptGift, B as trackAddToCartFBQ, t as trackAddToCartGA, r as trackBeginCheckoutGA, E as trackBuyNowFBQ, s as trackBuyNowGA, u as useAutoRemoveFreeGifts, f as useScriptAutoFreeGift, w as waitForGtagReady } from './types-CM5QrlnE.js';
|
|
6
6
|
export * from '@anker-in/shopify-sdk';
|
|
7
7
|
import 'react';
|
|
8
8
|
import 'react/jsx-runtime';
|
|
9
9
|
import 'swr';
|
|
10
10
|
import 'swr/mutation';
|
|
11
|
-
import 'decimal.js';
|
|
12
11
|
import 'swr/_internal';
|
|
12
|
+
import 'decimal.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Utility types for TypeScript
|
|
@@ -4,7 +4,8 @@ import { ShopifyClient, ShopifyConfig, CartCookieAdapter, NormalizedCart, Attrib
|
|
|
4
4
|
import { C as CookieAdapter, R as RouterAdapter, U as UserContextAdapter, P as PerformanceAdapter } from '../types-SKDHauqk.mjs';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { SWRConfiguration } from 'swr';
|
|
7
|
-
import {
|
|
7
|
+
import { S as ScriptAutoFreeGiftConfig, n as PlusMemberSettingsMetafields, U as UseAutoRemoveFreeGiftsOptions } from '../types-CM5QrlnE.mjs';
|
|
8
|
+
import 'decimal.js';
|
|
8
9
|
|
|
9
10
|
interface ShopifyContextValue {
|
|
10
11
|
client: ShopifyClient;
|
|
@@ -48,6 +49,12 @@ type LoadingState = {
|
|
|
48
49
|
listingAutoCodeApplying: boolean;
|
|
49
50
|
userCodeApplying: boolean;
|
|
50
51
|
};
|
|
52
|
+
type AppContext = {
|
|
53
|
+
/** Whether running in app */
|
|
54
|
+
isInApp?: boolean;
|
|
55
|
+
/** App name */
|
|
56
|
+
appName?: string;
|
|
57
|
+
};
|
|
51
58
|
interface CartContextValue {
|
|
52
59
|
/** Current cart data */
|
|
53
60
|
cart: NormalizedCart | undefined;
|
|
@@ -91,10 +98,10 @@ interface CartContextValue {
|
|
|
91
98
|
calculatedAutoFreeGift?: any;
|
|
92
99
|
/** Gifts that need to be added to cart */
|
|
93
100
|
giftNeedAddToCartLines: any[];
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
|
|
101
|
+
/** Function auto free gift config */
|
|
102
|
+
functionAutoFreeGiftConfig?: any;
|
|
103
|
+
/** Script auto free gift config */
|
|
104
|
+
scriptAutoFreeGiftConfig?: ScriptAutoFreeGiftConfig;
|
|
98
105
|
/** Metafield identifiers */
|
|
99
106
|
metafieldIdentifiers?: {
|
|
100
107
|
variant: HasMetafieldsIdentifier[];
|
|
@@ -106,17 +113,19 @@ interface CartContextValue {
|
|
|
106
113
|
customer?: any;
|
|
107
114
|
/** Plus member settings */
|
|
108
115
|
memberSetting?: PlusMemberSettingsMetafields;
|
|
116
|
+
/** App context */
|
|
117
|
+
appContext?: AppContext;
|
|
118
|
+
/** Auto remove free gifts options */
|
|
119
|
+
autoRemoveFreeGiftsOptions?: UseAutoRemoveFreeGiftsOptions;
|
|
109
120
|
}
|
|
110
121
|
interface CartProviderProps {
|
|
111
122
|
children: React__default.ReactNode;
|
|
112
123
|
/** SWR configuration options */
|
|
113
124
|
swrOptions?: SWRConfiguration<NormalizedCart | undefined, Error>;
|
|
114
|
-
/**
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
|
|
118
|
-
/** Function gift configuration */
|
|
119
|
-
fnGiftConf?: any;
|
|
125
|
+
/** Function auto free gift configuration */
|
|
126
|
+
functionAutoFreeGiftConfig?: any;
|
|
127
|
+
/** Script auto free gift configuration */
|
|
128
|
+
scriptAutoFreeGiftConfig?: ScriptAutoFreeGiftConfig;
|
|
120
129
|
/** User profile */
|
|
121
130
|
profile?: any;
|
|
122
131
|
/** Customer data */
|
|
@@ -130,6 +139,10 @@ interface CartProviderProps {
|
|
|
130
139
|
};
|
|
131
140
|
/** Plus member settings */
|
|
132
141
|
memberSetting?: PlusMemberSettingsMetafields;
|
|
142
|
+
/** App context */
|
|
143
|
+
appContext?: AppContext;
|
|
144
|
+
/** 是否禁用自动更新 line item 的 code amount attributes,默认为 false */
|
|
145
|
+
disableUpdateLineCodeAmountAttributes?: boolean;
|
|
133
146
|
}
|
|
134
147
|
/**
|
|
135
148
|
* Cart Provider Component
|
|
@@ -141,7 +154,8 @@ interface CartProviderProps {
|
|
|
141
154
|
* <ShopifyProvider {...config}>
|
|
142
155
|
* <CartProvider
|
|
143
156
|
* locale="us"
|
|
144
|
-
*
|
|
157
|
+
* functionAutoFreeGiftConfig={functionConfig}
|
|
158
|
+
* scriptAutoFreeGiftConfig={scriptConfig}
|
|
145
159
|
* profile={profile}
|
|
146
160
|
* customer={customer}
|
|
147
161
|
* >
|
|
@@ -150,7 +164,7 @@ interface CartProviderProps {
|
|
|
150
164
|
* </ShopifyProvider>
|
|
151
165
|
* ```
|
|
152
166
|
*/
|
|
153
|
-
declare function CartProvider({ children,
|
|
167
|
+
declare function CartProvider({ children, functionAutoFreeGiftConfig, scriptAutoFreeGiftConfig, profile, customer, locale, metafieldIdentifiers, memberSetting, appContext, disableUpdateLineCodeAmountAttributes, }: CartProviderProps): react_jsx_runtime.JSX.Element;
|
|
154
168
|
/**
|
|
155
169
|
* Hook to access cart context
|
|
156
170
|
*
|
|
@@ -175,4 +189,4 @@ declare function useCartContext(options: {
|
|
|
175
189
|
optional: true;
|
|
176
190
|
}): CartContextValue | null;
|
|
177
191
|
|
|
178
|
-
export { type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
|
|
192
|
+
export { type AppContext, type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
|
package/dist/provider/index.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { ShopifyClient, ShopifyConfig, CartCookieAdapter, NormalizedCart, Attrib
|
|
|
4
4
|
import { C as CookieAdapter, R as RouterAdapter, U as UserContextAdapter, P as PerformanceAdapter } from '../types-SKDHauqk.js';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { SWRConfiguration } from 'swr';
|
|
7
|
-
import {
|
|
7
|
+
import { S as ScriptAutoFreeGiftConfig, n as PlusMemberSettingsMetafields, U as UseAutoRemoveFreeGiftsOptions } from '../types-CM5QrlnE.js';
|
|
8
|
+
import 'decimal.js';
|
|
8
9
|
|
|
9
10
|
interface ShopifyContextValue {
|
|
10
11
|
client: ShopifyClient;
|
|
@@ -48,6 +49,12 @@ type LoadingState = {
|
|
|
48
49
|
listingAutoCodeApplying: boolean;
|
|
49
50
|
userCodeApplying: boolean;
|
|
50
51
|
};
|
|
52
|
+
type AppContext = {
|
|
53
|
+
/** Whether running in app */
|
|
54
|
+
isInApp?: boolean;
|
|
55
|
+
/** App name */
|
|
56
|
+
appName?: string;
|
|
57
|
+
};
|
|
51
58
|
interface CartContextValue {
|
|
52
59
|
/** Current cart data */
|
|
53
60
|
cart: NormalizedCart | undefined;
|
|
@@ -91,10 +98,10 @@ interface CartContextValue {
|
|
|
91
98
|
calculatedAutoFreeGift?: any;
|
|
92
99
|
/** Gifts that need to be added to cart */
|
|
93
100
|
giftNeedAddToCartLines: any[];
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
|
|
101
|
+
/** Function auto free gift config */
|
|
102
|
+
functionAutoFreeGiftConfig?: any;
|
|
103
|
+
/** Script auto free gift config */
|
|
104
|
+
scriptAutoFreeGiftConfig?: ScriptAutoFreeGiftConfig;
|
|
98
105
|
/** Metafield identifiers */
|
|
99
106
|
metafieldIdentifiers?: {
|
|
100
107
|
variant: HasMetafieldsIdentifier[];
|
|
@@ -106,17 +113,19 @@ interface CartContextValue {
|
|
|
106
113
|
customer?: any;
|
|
107
114
|
/** Plus member settings */
|
|
108
115
|
memberSetting?: PlusMemberSettingsMetafields;
|
|
116
|
+
/** App context */
|
|
117
|
+
appContext?: AppContext;
|
|
118
|
+
/** Auto remove free gifts options */
|
|
119
|
+
autoRemoveFreeGiftsOptions?: UseAutoRemoveFreeGiftsOptions;
|
|
109
120
|
}
|
|
110
121
|
interface CartProviderProps {
|
|
111
122
|
children: React__default.ReactNode;
|
|
112
123
|
/** SWR configuration options */
|
|
113
124
|
swrOptions?: SWRConfiguration<NormalizedCart | undefined, Error>;
|
|
114
|
-
/**
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
|
|
118
|
-
/** Function gift configuration */
|
|
119
|
-
fnGiftConf?: any;
|
|
125
|
+
/** Function auto free gift configuration */
|
|
126
|
+
functionAutoFreeGiftConfig?: any;
|
|
127
|
+
/** Script auto free gift configuration */
|
|
128
|
+
scriptAutoFreeGiftConfig?: ScriptAutoFreeGiftConfig;
|
|
120
129
|
/** User profile */
|
|
121
130
|
profile?: any;
|
|
122
131
|
/** Customer data */
|
|
@@ -130,6 +139,10 @@ interface CartProviderProps {
|
|
|
130
139
|
};
|
|
131
140
|
/** Plus member settings */
|
|
132
141
|
memberSetting?: PlusMemberSettingsMetafields;
|
|
142
|
+
/** App context */
|
|
143
|
+
appContext?: AppContext;
|
|
144
|
+
/** 是否禁用自动更新 line item 的 code amount attributes,默认为 false */
|
|
145
|
+
disableUpdateLineCodeAmountAttributes?: boolean;
|
|
133
146
|
}
|
|
134
147
|
/**
|
|
135
148
|
* Cart Provider Component
|
|
@@ -141,7 +154,8 @@ interface CartProviderProps {
|
|
|
141
154
|
* <ShopifyProvider {...config}>
|
|
142
155
|
* <CartProvider
|
|
143
156
|
* locale="us"
|
|
144
|
-
*
|
|
157
|
+
* functionAutoFreeGiftConfig={functionConfig}
|
|
158
|
+
* scriptAutoFreeGiftConfig={scriptConfig}
|
|
145
159
|
* profile={profile}
|
|
146
160
|
* customer={customer}
|
|
147
161
|
* >
|
|
@@ -150,7 +164,7 @@ interface CartProviderProps {
|
|
|
150
164
|
* </ShopifyProvider>
|
|
151
165
|
* ```
|
|
152
166
|
*/
|
|
153
|
-
declare function CartProvider({ children,
|
|
167
|
+
declare function CartProvider({ children, functionAutoFreeGiftConfig, scriptAutoFreeGiftConfig, profile, customer, locale, metafieldIdentifiers, memberSetting, appContext, disableUpdateLineCodeAmountAttributes, }: CartProviderProps): react_jsx_runtime.JSX.Element;
|
|
154
168
|
/**
|
|
155
169
|
* Hook to access cart context
|
|
156
170
|
*
|
|
@@ -175,4 +189,4 @@ declare function useCartContext(options: {
|
|
|
175
189
|
optional: true;
|
|
176
190
|
}): CartContextValue | null;
|
|
177
191
|
|
|
178
|
-
export { type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
|
|
192
|
+
export { type AppContext, type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { NormalizedProductVariant, NormalizedProduct,
|
|
1
|
+
import { NormalizedLineItem, MoneyV2, NormalizedProductVariant, NormalizedProduct, BuyerIdentityInput, NormalizedCart } from '@anker-in/shopify-sdk';
|
|
2
|
+
import Decimal from 'decimal.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Tracking Types
|
|
@@ -18,19 +19,30 @@ interface GtmParams {
|
|
|
18
19
|
|
|
19
20
|
declare global {
|
|
20
21
|
interface Window {
|
|
21
|
-
dataLayer?:
|
|
22
|
-
gtag?:
|
|
22
|
+
dataLayer?: Array<Record<string, unknown>>;
|
|
23
|
+
gtag?: {
|
|
24
|
+
(command: 'config', targetId: string, config?: Record<string, unknown>): void;
|
|
25
|
+
(command: 'set', config: Record<string, unknown>): void;
|
|
26
|
+
(command: 'event', eventName: string, eventParams?: Record<string, unknown>): void;
|
|
27
|
+
(command: 'get', targetId: string, fieldName: string, callback?: (value: string) => void): void;
|
|
28
|
+
(command: 'consent', consentArg: string, consentParams?: Record<string, unknown>): void;
|
|
29
|
+
};
|
|
23
30
|
}
|
|
24
31
|
}
|
|
25
32
|
/**
|
|
26
33
|
* Push event to GA4 dataLayer
|
|
27
34
|
*/
|
|
28
|
-
declare const gaTrack: (data:
|
|
35
|
+
declare const gaTrack: (data: Record<string, unknown>) => void;
|
|
29
36
|
/**
|
|
30
37
|
* Track add to cart event in GA4
|
|
31
38
|
*/
|
|
32
39
|
declare const trackAddToCartGA: ({ lineItems, gtmParams, }: {
|
|
33
|
-
lineItems:
|
|
40
|
+
lineItems: Array<NormalizedLineItem & {
|
|
41
|
+
finalPrice?: MoneyV2;
|
|
42
|
+
gtmParams?: {
|
|
43
|
+
item_category_id?: number | string;
|
|
44
|
+
};
|
|
45
|
+
}>;
|
|
34
46
|
gtmParams?: GtmParams;
|
|
35
47
|
}) => void;
|
|
36
48
|
/**
|
|
@@ -46,26 +58,59 @@ declare const trackBeginCheckoutGA: ({ lineItems, currencyCode, gtmParams, }: {
|
|
|
46
58
|
* This triggers begin_checkout event for buy now actions
|
|
47
59
|
*/
|
|
48
60
|
declare const trackBuyNowGA: ({ lineItems, gtmParams, }: {
|
|
49
|
-
lineItems:
|
|
61
|
+
lineItems: Array<NormalizedLineItem & {
|
|
62
|
+
gtmParams?: {
|
|
63
|
+
item_category_id?: number | string;
|
|
64
|
+
};
|
|
65
|
+
}>;
|
|
50
66
|
gtmParams?: GtmParams;
|
|
51
67
|
}) => void;
|
|
68
|
+
/**
|
|
69
|
+
* GA4 Data
|
|
70
|
+
*/
|
|
71
|
+
interface GA4Data {
|
|
72
|
+
clientId: string;
|
|
73
|
+
sessionId: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Wait for gtag to be ready
|
|
77
|
+
*/
|
|
78
|
+
declare function waitForGtagReady(timeout?: number): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Get GA4 client ID
|
|
81
|
+
*/
|
|
82
|
+
declare const getGA4ClientId: (measurementId?: string) => Promise<string>;
|
|
83
|
+
/**
|
|
84
|
+
* Get GA4 session ID
|
|
85
|
+
*/
|
|
86
|
+
declare const getGA4SessionId: (measurementId?: string) => Promise<string>;
|
|
87
|
+
/**
|
|
88
|
+
* Get GA4 data (client ID and session ID)
|
|
89
|
+
*/
|
|
90
|
+
declare const getGA4Data: (measurementId?: string) => Promise<GA4Data>;
|
|
52
91
|
|
|
53
92
|
/**
|
|
54
93
|
* Facebook Pixel Tracking
|
|
55
94
|
* FBQ event tracking utilities
|
|
56
95
|
*/
|
|
57
96
|
|
|
97
|
+
type FbqCommand = 'track' | 'trackCustom' | 'trackSingle' | 'trackCustom';
|
|
98
|
+
type FbqEventName = 'AddToCart' | 'Purchase' | 'InitiateCheckout' | 'ViewContent' | string;
|
|
99
|
+
type FbqEventParams = Record<string, unknown>;
|
|
58
100
|
declare global {
|
|
59
101
|
interface Window {
|
|
60
|
-
fbq?: (
|
|
61
|
-
gtag?: (...args: any[]) => void;
|
|
102
|
+
fbq?: (command: FbqCommand, eventName: FbqEventName, params?: FbqEventParams) => void;
|
|
62
103
|
}
|
|
63
104
|
}
|
|
64
105
|
/**
|
|
65
106
|
* Track add to cart event in Facebook Pixel
|
|
66
107
|
*/
|
|
67
|
-
declare const trackAddToCartFBQ: ({ lineItems }: {
|
|
68
|
-
lineItems:
|
|
108
|
+
declare const trackAddToCartFBQ: ({ lineItems, }: {
|
|
109
|
+
lineItems: Array<NormalizedLineItem & {
|
|
110
|
+
gtmParams?: {
|
|
111
|
+
item_category_id?: number | string;
|
|
112
|
+
};
|
|
113
|
+
}>;
|
|
69
114
|
}) => void;
|
|
70
115
|
/**
|
|
71
116
|
* Configuration for Buy Now tracking events
|
|
@@ -102,6 +147,9 @@ type AddToCartLineItem = {
|
|
|
102
147
|
code: string;
|
|
103
148
|
amount: number;
|
|
104
149
|
};
|
|
150
|
+
gtmParams?: {
|
|
151
|
+
item_category_id?: number | string;
|
|
152
|
+
};
|
|
105
153
|
};
|
|
106
154
|
interface AddToCartInput {
|
|
107
155
|
/** Lines to add */
|
|
@@ -118,10 +166,7 @@ interface AddToCartInput {
|
|
|
118
166
|
/** 全量更新 codes,默认是追加 */
|
|
119
167
|
replaceExistingCodes?: boolean;
|
|
120
168
|
/** Buyer identity for cart creation */
|
|
121
|
-
buyerIdentity?:
|
|
122
|
-
email?: string;
|
|
123
|
-
countryCode?: string;
|
|
124
|
-
};
|
|
169
|
+
buyerIdentity?: BuyerIdentityInput;
|
|
125
170
|
/** GTM tracking parameters */
|
|
126
171
|
gtmParams?: Omit<GtmParams, 'brand'>;
|
|
127
172
|
/** Force create new cart */
|
|
@@ -134,6 +179,131 @@ interface UseAddToCartOptions {
|
|
|
134
179
|
withTrack?: boolean;
|
|
135
180
|
}
|
|
136
181
|
|
|
182
|
+
/**
|
|
183
|
+
* Auto Remove Free Gifts Hook
|
|
184
|
+
*
|
|
185
|
+
* Automatically removes Function and Script free gifts from cart on page load.
|
|
186
|
+
* This ensures gifts are only added at checkout time, not kept in cart permanently.
|
|
187
|
+
*
|
|
188
|
+
* Based on storefront-anker production implementation.
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
interface UseAutoRemoveFreeGiftsOptions {
|
|
192
|
+
/**
|
|
193
|
+
* Whether to remove Function gifts (with _discounts_function_env attribute)
|
|
194
|
+
* @default true
|
|
195
|
+
*/
|
|
196
|
+
removeFunctionGifts?: boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Whether to remove Script gifts (with _giveaway_gradient_gifts attribute)
|
|
199
|
+
* @default true
|
|
200
|
+
*/
|
|
201
|
+
removeScriptGifts?: boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Custom function to identify additional gift line items
|
|
204
|
+
* @param line - Line item to check
|
|
205
|
+
* @returns true if line item is a gift that should be removed
|
|
206
|
+
*/
|
|
207
|
+
isGiftLineItem?: (line: NormalizedLineItem) => boolean;
|
|
208
|
+
}
|
|
209
|
+
interface UseAutoRemoveFreeGiftsResult {
|
|
210
|
+
/** Whether removal is in progress */
|
|
211
|
+
isRemoving: boolean;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Automatically removes free gifts from cart on initialization
|
|
215
|
+
*
|
|
216
|
+
* Function满赠和Script满赠的赠品都会被添加到购物车,需要在返回购物车页面时自动删除。
|
|
217
|
+
* - Function 赠品:带 _discounts_function_env 属性
|
|
218
|
+
* - Script 赠品:带 _giveaway_gradient_gifts 属性
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```tsx
|
|
222
|
+
* function CartPage() {
|
|
223
|
+
* // Auto-remove all gifts on page load
|
|
224
|
+
* useAutoRemoveFreeGifts()
|
|
225
|
+
*
|
|
226
|
+
* return <Cart />
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```tsx
|
|
232
|
+
* // Only remove Function gifts, keep Script gifts
|
|
233
|
+
* useAutoRemoveFreeGifts({
|
|
234
|
+
* removeFunctionGifts: true,
|
|
235
|
+
* removeScriptGifts: false
|
|
236
|
+
* })
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```tsx
|
|
241
|
+
* // Custom gift identification
|
|
242
|
+
* useAutoRemoveFreeGifts({
|
|
243
|
+
* isGiftLineItem: (line) => {
|
|
244
|
+
* // Also remove other campaign gifts
|
|
245
|
+
* return line.customAttributes?.some(
|
|
246
|
+
* attr => attr.key === '_giveaway_summer_campaign'
|
|
247
|
+
* )
|
|
248
|
+
* }
|
|
249
|
+
* })
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
declare function useAutoRemoveFreeGifts(options?: UseAutoRemoveFreeGiftsOptions): UseAutoRemoveFreeGiftsResult;
|
|
253
|
+
/**
|
|
254
|
+
* Helper function to check if a line item is a Function gift
|
|
255
|
+
*/
|
|
256
|
+
declare function isFunctionGift(line: NormalizedLineItem): boolean;
|
|
257
|
+
/**
|
|
258
|
+
* Helper function to check if a line item is a Script gift
|
|
259
|
+
*/
|
|
260
|
+
declare function isScriptGift(line: NormalizedLineItem): boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Helper function to check if a line item is a buy-get gift (买赠)
|
|
263
|
+
*/
|
|
264
|
+
declare function isBuyGetGift(line: NormalizedLineItem): boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Helper function to check if a line item is any type of gift
|
|
267
|
+
*/
|
|
268
|
+
declare function isAnyGift(line: NormalizedLineItem): boolean;
|
|
269
|
+
|
|
270
|
+
interface GiveawayProduct {
|
|
271
|
+
handle: string;
|
|
272
|
+
sku: string;
|
|
273
|
+
}
|
|
274
|
+
interface Breakpoint {
|
|
275
|
+
breakpoint: string;
|
|
276
|
+
giveawayProducts: GiveawayProduct[];
|
|
277
|
+
}
|
|
278
|
+
interface ScriptAutoFreeGiftConfig {
|
|
279
|
+
activityAvailableQuery?: string;
|
|
280
|
+
activityQroperty?: string;
|
|
281
|
+
breakpoints?: Array<{
|
|
282
|
+
breakpoint: string;
|
|
283
|
+
giveawayProducts: GiveawayProduct[];
|
|
284
|
+
}>;
|
|
285
|
+
includeTags?: string[];
|
|
286
|
+
useTotalAmount?: boolean;
|
|
287
|
+
requireLogin?: boolean;
|
|
288
|
+
}
|
|
289
|
+
interface UseScriptAutoFreeGiftResult {
|
|
290
|
+
involvedLines: NormalizedLineItem[];
|
|
291
|
+
reorder: (a: NormalizedLineItem, b: NormalizedLineItem) => number;
|
|
292
|
+
disableCodeRemove: boolean;
|
|
293
|
+
nextFreeGiftLevel: Breakpoint | null;
|
|
294
|
+
freeGiftLevel: Breakpoint | null;
|
|
295
|
+
involvedSubTotal: Decimal;
|
|
296
|
+
giftProductsResult?: NormalizedProduct[];
|
|
297
|
+
}
|
|
298
|
+
declare const useScriptAutoFreeGift: ({ campaign, _giveaway, cart, locale: providedLocale, lines, profile, }: {
|
|
299
|
+
campaign?: ScriptAutoFreeGiftConfig;
|
|
300
|
+
_giveaway: string;
|
|
301
|
+
cart: NormalizedCart | undefined;
|
|
302
|
+
locale?: string;
|
|
303
|
+
lines?: AddToCartLineItem[];
|
|
304
|
+
profile?: any;
|
|
305
|
+
}) => UseScriptAutoFreeGiftResult;
|
|
306
|
+
|
|
137
307
|
/**
|
|
138
308
|
* Plus Member Types
|
|
139
309
|
* Type definitions for Plus Member functionality
|
|
@@ -510,4 +680,4 @@ type DeliveryCustomData = {
|
|
|
510
680
|
plus_type?: DeliveryPlusType;
|
|
511
681
|
};
|
|
512
682
|
|
|
513
|
-
export { type AddToCartLineItem as A, type BuyNowTrackConfig as
|
|
683
|
+
export { type AddToCartLineItem as A, trackAddToCartFBQ as B, type BuyNowTrackConfig as C, DeliveryPlusType as D, trackBuyNowFBQ as E, type GtmParams as G, PLUS_MEMBER_TYPE as P, type ScriptAutoFreeGiftConfig as S, type UseAutoRemoveFreeGiftsOptions as U, type UseAutoRemoveFreeGiftsResult as a, isScriptGift as b, isBuyGetGift as c, isAnyGift as d, type UseScriptAutoFreeGiftResult as e, useScriptAutoFreeGift as f, type AddToCartInput as g, type UseAddToCartOptions as h, isFunctionGift as i, PlusMemberMode as j, ShippingMethodMode as k, type PlusMemberShippingMethodMetafields as l, type PlusMemberShippingMethodConfig as m, type PlusMemberSettingsMetafields as n, type SelectedPlusMemberVariant as o, type DeliveryCustomData as p, gaTrack as q, trackBeginCheckoutGA as r, trackBuyNowGA as s, trackAddToCartGA as t, useAutoRemoveFreeGifts as u, type GA4Data as v, waitForGtagReady as w, getGA4ClientId as x, getGA4SessionId as y, getGA4Data as z };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { NormalizedProductVariant, NormalizedProduct,
|
|
1
|
+
import { NormalizedLineItem, MoneyV2, NormalizedProductVariant, NormalizedProduct, BuyerIdentityInput, NormalizedCart } from '@anker-in/shopify-sdk';
|
|
2
|
+
import Decimal from 'decimal.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Tracking Types
|
|
@@ -18,19 +19,30 @@ interface GtmParams {
|
|
|
18
19
|
|
|
19
20
|
declare global {
|
|
20
21
|
interface Window {
|
|
21
|
-
dataLayer?:
|
|
22
|
-
gtag?:
|
|
22
|
+
dataLayer?: Array<Record<string, unknown>>;
|
|
23
|
+
gtag?: {
|
|
24
|
+
(command: 'config', targetId: string, config?: Record<string, unknown>): void;
|
|
25
|
+
(command: 'set', config: Record<string, unknown>): void;
|
|
26
|
+
(command: 'event', eventName: string, eventParams?: Record<string, unknown>): void;
|
|
27
|
+
(command: 'get', targetId: string, fieldName: string, callback?: (value: string) => void): void;
|
|
28
|
+
(command: 'consent', consentArg: string, consentParams?: Record<string, unknown>): void;
|
|
29
|
+
};
|
|
23
30
|
}
|
|
24
31
|
}
|
|
25
32
|
/**
|
|
26
33
|
* Push event to GA4 dataLayer
|
|
27
34
|
*/
|
|
28
|
-
declare const gaTrack: (data:
|
|
35
|
+
declare const gaTrack: (data: Record<string, unknown>) => void;
|
|
29
36
|
/**
|
|
30
37
|
* Track add to cart event in GA4
|
|
31
38
|
*/
|
|
32
39
|
declare const trackAddToCartGA: ({ lineItems, gtmParams, }: {
|
|
33
|
-
lineItems:
|
|
40
|
+
lineItems: Array<NormalizedLineItem & {
|
|
41
|
+
finalPrice?: MoneyV2;
|
|
42
|
+
gtmParams?: {
|
|
43
|
+
item_category_id?: number | string;
|
|
44
|
+
};
|
|
45
|
+
}>;
|
|
34
46
|
gtmParams?: GtmParams;
|
|
35
47
|
}) => void;
|
|
36
48
|
/**
|
|
@@ -46,26 +58,59 @@ declare const trackBeginCheckoutGA: ({ lineItems, currencyCode, gtmParams, }: {
|
|
|
46
58
|
* This triggers begin_checkout event for buy now actions
|
|
47
59
|
*/
|
|
48
60
|
declare const trackBuyNowGA: ({ lineItems, gtmParams, }: {
|
|
49
|
-
lineItems:
|
|
61
|
+
lineItems: Array<NormalizedLineItem & {
|
|
62
|
+
gtmParams?: {
|
|
63
|
+
item_category_id?: number | string;
|
|
64
|
+
};
|
|
65
|
+
}>;
|
|
50
66
|
gtmParams?: GtmParams;
|
|
51
67
|
}) => void;
|
|
68
|
+
/**
|
|
69
|
+
* GA4 Data
|
|
70
|
+
*/
|
|
71
|
+
interface GA4Data {
|
|
72
|
+
clientId: string;
|
|
73
|
+
sessionId: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Wait for gtag to be ready
|
|
77
|
+
*/
|
|
78
|
+
declare function waitForGtagReady(timeout?: number): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Get GA4 client ID
|
|
81
|
+
*/
|
|
82
|
+
declare const getGA4ClientId: (measurementId?: string) => Promise<string>;
|
|
83
|
+
/**
|
|
84
|
+
* Get GA4 session ID
|
|
85
|
+
*/
|
|
86
|
+
declare const getGA4SessionId: (measurementId?: string) => Promise<string>;
|
|
87
|
+
/**
|
|
88
|
+
* Get GA4 data (client ID and session ID)
|
|
89
|
+
*/
|
|
90
|
+
declare const getGA4Data: (measurementId?: string) => Promise<GA4Data>;
|
|
52
91
|
|
|
53
92
|
/**
|
|
54
93
|
* Facebook Pixel Tracking
|
|
55
94
|
* FBQ event tracking utilities
|
|
56
95
|
*/
|
|
57
96
|
|
|
97
|
+
type FbqCommand = 'track' | 'trackCustom' | 'trackSingle' | 'trackCustom';
|
|
98
|
+
type FbqEventName = 'AddToCart' | 'Purchase' | 'InitiateCheckout' | 'ViewContent' | string;
|
|
99
|
+
type FbqEventParams = Record<string, unknown>;
|
|
58
100
|
declare global {
|
|
59
101
|
interface Window {
|
|
60
|
-
fbq?: (
|
|
61
|
-
gtag?: (...args: any[]) => void;
|
|
102
|
+
fbq?: (command: FbqCommand, eventName: FbqEventName, params?: FbqEventParams) => void;
|
|
62
103
|
}
|
|
63
104
|
}
|
|
64
105
|
/**
|
|
65
106
|
* Track add to cart event in Facebook Pixel
|
|
66
107
|
*/
|
|
67
|
-
declare const trackAddToCartFBQ: ({ lineItems }: {
|
|
68
|
-
lineItems:
|
|
108
|
+
declare const trackAddToCartFBQ: ({ lineItems, }: {
|
|
109
|
+
lineItems: Array<NormalizedLineItem & {
|
|
110
|
+
gtmParams?: {
|
|
111
|
+
item_category_id?: number | string;
|
|
112
|
+
};
|
|
113
|
+
}>;
|
|
69
114
|
}) => void;
|
|
70
115
|
/**
|
|
71
116
|
* Configuration for Buy Now tracking events
|
|
@@ -102,6 +147,9 @@ type AddToCartLineItem = {
|
|
|
102
147
|
code: string;
|
|
103
148
|
amount: number;
|
|
104
149
|
};
|
|
150
|
+
gtmParams?: {
|
|
151
|
+
item_category_id?: number | string;
|
|
152
|
+
};
|
|
105
153
|
};
|
|
106
154
|
interface AddToCartInput {
|
|
107
155
|
/** Lines to add */
|
|
@@ -118,10 +166,7 @@ interface AddToCartInput {
|
|
|
118
166
|
/** 全量更新 codes,默认是追加 */
|
|
119
167
|
replaceExistingCodes?: boolean;
|
|
120
168
|
/** Buyer identity for cart creation */
|
|
121
|
-
buyerIdentity?:
|
|
122
|
-
email?: string;
|
|
123
|
-
countryCode?: string;
|
|
124
|
-
};
|
|
169
|
+
buyerIdentity?: BuyerIdentityInput;
|
|
125
170
|
/** GTM tracking parameters */
|
|
126
171
|
gtmParams?: Omit<GtmParams, 'brand'>;
|
|
127
172
|
/** Force create new cart */
|
|
@@ -134,6 +179,131 @@ interface UseAddToCartOptions {
|
|
|
134
179
|
withTrack?: boolean;
|
|
135
180
|
}
|
|
136
181
|
|
|
182
|
+
/**
|
|
183
|
+
* Auto Remove Free Gifts Hook
|
|
184
|
+
*
|
|
185
|
+
* Automatically removes Function and Script free gifts from cart on page load.
|
|
186
|
+
* This ensures gifts are only added at checkout time, not kept in cart permanently.
|
|
187
|
+
*
|
|
188
|
+
* Based on storefront-anker production implementation.
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
interface UseAutoRemoveFreeGiftsOptions {
|
|
192
|
+
/**
|
|
193
|
+
* Whether to remove Function gifts (with _discounts_function_env attribute)
|
|
194
|
+
* @default true
|
|
195
|
+
*/
|
|
196
|
+
removeFunctionGifts?: boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Whether to remove Script gifts (with _giveaway_gradient_gifts attribute)
|
|
199
|
+
* @default true
|
|
200
|
+
*/
|
|
201
|
+
removeScriptGifts?: boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Custom function to identify additional gift line items
|
|
204
|
+
* @param line - Line item to check
|
|
205
|
+
* @returns true if line item is a gift that should be removed
|
|
206
|
+
*/
|
|
207
|
+
isGiftLineItem?: (line: NormalizedLineItem) => boolean;
|
|
208
|
+
}
|
|
209
|
+
interface UseAutoRemoveFreeGiftsResult {
|
|
210
|
+
/** Whether removal is in progress */
|
|
211
|
+
isRemoving: boolean;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Automatically removes free gifts from cart on initialization
|
|
215
|
+
*
|
|
216
|
+
* Function满赠和Script满赠的赠品都会被添加到购物车,需要在返回购物车页面时自动删除。
|
|
217
|
+
* - Function 赠品:带 _discounts_function_env 属性
|
|
218
|
+
* - Script 赠品:带 _giveaway_gradient_gifts 属性
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```tsx
|
|
222
|
+
* function CartPage() {
|
|
223
|
+
* // Auto-remove all gifts on page load
|
|
224
|
+
* useAutoRemoveFreeGifts()
|
|
225
|
+
*
|
|
226
|
+
* return <Cart />
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```tsx
|
|
232
|
+
* // Only remove Function gifts, keep Script gifts
|
|
233
|
+
* useAutoRemoveFreeGifts({
|
|
234
|
+
* removeFunctionGifts: true,
|
|
235
|
+
* removeScriptGifts: false
|
|
236
|
+
* })
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```tsx
|
|
241
|
+
* // Custom gift identification
|
|
242
|
+
* useAutoRemoveFreeGifts({
|
|
243
|
+
* isGiftLineItem: (line) => {
|
|
244
|
+
* // Also remove other campaign gifts
|
|
245
|
+
* return line.customAttributes?.some(
|
|
246
|
+
* attr => attr.key === '_giveaway_summer_campaign'
|
|
247
|
+
* )
|
|
248
|
+
* }
|
|
249
|
+
* })
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
declare function useAutoRemoveFreeGifts(options?: UseAutoRemoveFreeGiftsOptions): UseAutoRemoveFreeGiftsResult;
|
|
253
|
+
/**
|
|
254
|
+
* Helper function to check if a line item is a Function gift
|
|
255
|
+
*/
|
|
256
|
+
declare function isFunctionGift(line: NormalizedLineItem): boolean;
|
|
257
|
+
/**
|
|
258
|
+
* Helper function to check if a line item is a Script gift
|
|
259
|
+
*/
|
|
260
|
+
declare function isScriptGift(line: NormalizedLineItem): boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Helper function to check if a line item is a buy-get gift (买赠)
|
|
263
|
+
*/
|
|
264
|
+
declare function isBuyGetGift(line: NormalizedLineItem): boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Helper function to check if a line item is any type of gift
|
|
267
|
+
*/
|
|
268
|
+
declare function isAnyGift(line: NormalizedLineItem): boolean;
|
|
269
|
+
|
|
270
|
+
interface GiveawayProduct {
|
|
271
|
+
handle: string;
|
|
272
|
+
sku: string;
|
|
273
|
+
}
|
|
274
|
+
interface Breakpoint {
|
|
275
|
+
breakpoint: string;
|
|
276
|
+
giveawayProducts: GiveawayProduct[];
|
|
277
|
+
}
|
|
278
|
+
interface ScriptAutoFreeGiftConfig {
|
|
279
|
+
activityAvailableQuery?: string;
|
|
280
|
+
activityQroperty?: string;
|
|
281
|
+
breakpoints?: Array<{
|
|
282
|
+
breakpoint: string;
|
|
283
|
+
giveawayProducts: GiveawayProduct[];
|
|
284
|
+
}>;
|
|
285
|
+
includeTags?: string[];
|
|
286
|
+
useTotalAmount?: boolean;
|
|
287
|
+
requireLogin?: boolean;
|
|
288
|
+
}
|
|
289
|
+
interface UseScriptAutoFreeGiftResult {
|
|
290
|
+
involvedLines: NormalizedLineItem[];
|
|
291
|
+
reorder: (a: NormalizedLineItem, b: NormalizedLineItem) => number;
|
|
292
|
+
disableCodeRemove: boolean;
|
|
293
|
+
nextFreeGiftLevel: Breakpoint | null;
|
|
294
|
+
freeGiftLevel: Breakpoint | null;
|
|
295
|
+
involvedSubTotal: Decimal;
|
|
296
|
+
giftProductsResult?: NormalizedProduct[];
|
|
297
|
+
}
|
|
298
|
+
declare const useScriptAutoFreeGift: ({ campaign, _giveaway, cart, locale: providedLocale, lines, profile, }: {
|
|
299
|
+
campaign?: ScriptAutoFreeGiftConfig;
|
|
300
|
+
_giveaway: string;
|
|
301
|
+
cart: NormalizedCart | undefined;
|
|
302
|
+
locale?: string;
|
|
303
|
+
lines?: AddToCartLineItem[];
|
|
304
|
+
profile?: any;
|
|
305
|
+
}) => UseScriptAutoFreeGiftResult;
|
|
306
|
+
|
|
137
307
|
/**
|
|
138
308
|
* Plus Member Types
|
|
139
309
|
* Type definitions for Plus Member functionality
|
|
@@ -510,4 +680,4 @@ type DeliveryCustomData = {
|
|
|
510
680
|
plus_type?: DeliveryPlusType;
|
|
511
681
|
};
|
|
512
682
|
|
|
513
|
-
export { type AddToCartLineItem as A, type BuyNowTrackConfig as
|
|
683
|
+
export { type AddToCartLineItem as A, trackAddToCartFBQ as B, type BuyNowTrackConfig as C, DeliveryPlusType as D, trackBuyNowFBQ as E, type GtmParams as G, PLUS_MEMBER_TYPE as P, type ScriptAutoFreeGiftConfig as S, type UseAutoRemoveFreeGiftsOptions as U, type UseAutoRemoveFreeGiftsResult as a, isScriptGift as b, isBuyGetGift as c, isAnyGift as d, type UseScriptAutoFreeGiftResult as e, useScriptAutoFreeGift as f, type AddToCartInput as g, type UseAddToCartOptions as h, isFunctionGift as i, PlusMemberMode as j, ShippingMethodMode as k, type PlusMemberShippingMethodMetafields as l, type PlusMemberShippingMethodConfig as m, type PlusMemberSettingsMetafields as n, type SelectedPlusMemberVariant as o, type DeliveryCustomData as p, gaTrack as q, trackBeginCheckoutGA as r, trackBuyNowGA as s, trackAddToCartGA as t, useAutoRemoveFreeGifts as u, type GA4Data as v, waitForGtagReady as w, getGA4ClientId as x, getGA4SessionId as y, getGA4Data as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anker-in/shopify-react",
|
|
3
|
-
"version": "1.3.0-beta.
|
|
3
|
+
"version": "1.3.0-beta.1",
|
|
4
4
|
"description": "React hooks and components for Shopify SDK",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"decimal.js": "^10.6.0",
|
|
32
32
|
"js-cookie": "^3.0.5",
|
|
33
33
|
"swr": "^2.2.0",
|
|
34
|
-
"@anker-in/shopify-sdk": "1.2.0-beta.
|
|
34
|
+
"@anker-in/shopify-sdk": "1.2.0-beta.1",
|
|
35
35
|
"@anker-in/shopify-core": "1.0.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|