@anker-in/shopify-react 0.1.1-beta.2 → 0.1.1-beta.4
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 +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +155 -9
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +153 -10
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-Bea95u2X.d.mts → index-Utuz9i5x.d.mts} +113 -36
- package/dist/{index-BZ6WbAdZ.d.ts → index-aSsTcW2O.d.ts} +113 -36
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +157 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +155 -10
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +2 -0
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +96 -9
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +96 -9
- package/dist/provider/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -428,8 +428,108 @@ type AutoFreeGiftList = AutoFreeGiftItem[] | [];
|
|
|
428
428
|
* 此 Hook 不产生任何副作用。
|
|
429
429
|
* 使用示例:
|
|
430
430
|
* const { qualifyingGift, nextTierGoal, activeCampaign, isLoading } = useCalcAutoFreeGift(cart, autoFreeGiftConfig);
|
|
431
|
+
*
|
|
432
|
+
* 也可以传入 lines 参数来计算加购前的赠品:
|
|
433
|
+
* const { qualifyingGift, nextTierGoal, activeCampaign, isLoading } = useCalcAutoFreeGift(cart, autoFreeGiftConfig, customer, lines);
|
|
431
434
|
*/
|
|
432
|
-
declare const useCalcAutoFreeGift: (cart: any, autoFreeGiftConfig: AutoFreeGiftConfig, customer: any) => FunctionGiftResult;
|
|
435
|
+
declare const useCalcAutoFreeGift: (cart: any, autoFreeGiftConfig: AutoFreeGiftConfig, customer: any, lines?: AddToCartLineItem[]) => FunctionGiftResult;
|
|
436
|
+
|
|
437
|
+
interface GiveawayProduct {
|
|
438
|
+
handle: string;
|
|
439
|
+
sku: string;
|
|
440
|
+
}
|
|
441
|
+
interface Breakpoint {
|
|
442
|
+
breakpoint: string;
|
|
443
|
+
giveawayProducts: GiveawayProduct[];
|
|
444
|
+
}
|
|
445
|
+
interface Campaign {
|
|
446
|
+
activityAvailableQuery?: string;
|
|
447
|
+
activityQroperty?: string;
|
|
448
|
+
breakpoints?: Array<{
|
|
449
|
+
breakpoint: string;
|
|
450
|
+
giveawayProducts: GiveawayProduct[];
|
|
451
|
+
}>;
|
|
452
|
+
includeTags?: string[];
|
|
453
|
+
useTotalAmount?: boolean;
|
|
454
|
+
}
|
|
455
|
+
interface UseScriptAutoFreeGiftResult {
|
|
456
|
+
involvedLines: NormalizedLineItem[];
|
|
457
|
+
reorder: (a: NormalizedLineItem, b: NormalizedLineItem) => number;
|
|
458
|
+
disableCodeRemove: boolean;
|
|
459
|
+
nextFreeGiftLevel: Breakpoint | null;
|
|
460
|
+
freeGiftLevel: Breakpoint | null;
|
|
461
|
+
involvedSubTotal: Decimal;
|
|
462
|
+
giftProductsResult?: NormalizedProduct[];
|
|
463
|
+
}
|
|
464
|
+
declare const useScriptAutoFreeGift: ({ campaign, _giveaway, cart, locale: providedLocale, lines, }: {
|
|
465
|
+
campaign: Campaign | null;
|
|
466
|
+
_giveaway: string;
|
|
467
|
+
cart: NormalizedCart | undefined;
|
|
468
|
+
locale?: string;
|
|
469
|
+
lines?: AddToCartLineItem[];
|
|
470
|
+
}) => UseScriptAutoFreeGiftResult;
|
|
471
|
+
|
|
472
|
+
interface UseCalcGiftsFromLinesOptions {
|
|
473
|
+
/** Lines to calculate gifts from (AddToCartLineItem format) */
|
|
474
|
+
lines: AddToCartLineItem[];
|
|
475
|
+
/** Auto free gift configuration (Function gift) */
|
|
476
|
+
autoFreeGiftConfig?: AutoFreeGiftConfig;
|
|
477
|
+
/** Customer information (required for function gift) */
|
|
478
|
+
customer?: any;
|
|
479
|
+
/** Script gift campaign configuration */
|
|
480
|
+
scriptCampaign?: any;
|
|
481
|
+
/** Script giveaway attribute key */
|
|
482
|
+
scriptGiveawayKey?: string;
|
|
483
|
+
/** Locale for product fetching (optional, will use from ShopifyProvider if not provided) */
|
|
484
|
+
locale?: string;
|
|
485
|
+
}
|
|
486
|
+
interface UseCalcGiftsFromLinesResult {
|
|
487
|
+
/** Function gift calculation result */
|
|
488
|
+
functionGift: FunctionGiftResult;
|
|
489
|
+
/** Script gift calculation result */
|
|
490
|
+
scriptGift: UseScriptAutoFreeGiftResult;
|
|
491
|
+
/** All gift lines that need to be added to cart (combined from both) */
|
|
492
|
+
allGiftLines: CartLineInput[];
|
|
493
|
+
/** Whether any gifts are available */
|
|
494
|
+
hasGifts: boolean;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Calculate gifts from AddToCartLineItem[] before adding to cart
|
|
498
|
+
* Supports both function-based gifts (useCalcAutoFreeGift) and script-based gifts (useScriptAutoFreeGift)
|
|
499
|
+
*
|
|
500
|
+
* Automatically uses locale from ShopifyProvider and cart from CartContext if not provided.
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```tsx
|
|
504
|
+
* // Basic usage (locale from context, customer required for function gift)
|
|
505
|
+
* const { allGiftLines, hasGifts } = useCalcGiftsFromLines({
|
|
506
|
+
* lines: [{ variant: myVariant, quantity: 2 }],
|
|
507
|
+
* customer: currentCustomer,
|
|
508
|
+
* autoFreeGiftConfig: functionGiftConfig,
|
|
509
|
+
* scriptCampaign: scriptGiftConfig,
|
|
510
|
+
* })
|
|
511
|
+
*
|
|
512
|
+
* // Script gift only (no customer needed)
|
|
513
|
+
* const { allGiftLines, hasGifts } = useCalcGiftsFromLines({
|
|
514
|
+
* lines: [{ variant: myVariant, quantity: 2 }],
|
|
515
|
+
* scriptCampaign: scriptGiftConfig,
|
|
516
|
+
* })
|
|
517
|
+
*
|
|
518
|
+
* // With custom locale
|
|
519
|
+
* const { allGiftLines, hasGifts } = useCalcGiftsFromLines({
|
|
520
|
+
* lines: [{ variant: myVariant, quantity: 2 }],
|
|
521
|
+
* customer: currentCustomer,
|
|
522
|
+
* locale: 'fr',
|
|
523
|
+
* autoFreeGiftConfig: functionGiftConfig,
|
|
524
|
+
* })
|
|
525
|
+
*
|
|
526
|
+
* // Then add both products and gifts to cart
|
|
527
|
+
* await addToCart({
|
|
528
|
+
* lineItems: [...lines, ...allGiftLines]
|
|
529
|
+
* })
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
declare function useCalcGiftsFromLines({ lines, customer, scriptGiveawayKey, }: UseCalcGiftsFromLinesOptions): UseCalcGiftsFromLinesResult;
|
|
433
533
|
|
|
434
534
|
declare enum OrderDiscountType {
|
|
435
535
|
PERCENTAGE = 1,// 百分比折扣
|
|
@@ -1012,40 +1112,6 @@ declare const useCartItemQuantityLimit: ({ cart, cartItem, config, }: {
|
|
|
1012
1112
|
max: number;
|
|
1013
1113
|
};
|
|
1014
1114
|
|
|
1015
|
-
interface GiveawayProduct {
|
|
1016
|
-
handle: string;
|
|
1017
|
-
sku: string;
|
|
1018
|
-
}
|
|
1019
|
-
interface Breakpoint {
|
|
1020
|
-
breakpoint: string;
|
|
1021
|
-
giveawayProducts: GiveawayProduct[];
|
|
1022
|
-
}
|
|
1023
|
-
interface Campaign {
|
|
1024
|
-
activityAvailableQuery?: string;
|
|
1025
|
-
activityQroperty?: string;
|
|
1026
|
-
breakpoints?: Array<{
|
|
1027
|
-
breakpoint: string;
|
|
1028
|
-
giveawayProducts: GiveawayProduct[];
|
|
1029
|
-
}>;
|
|
1030
|
-
includeTags?: string[];
|
|
1031
|
-
useTotalAmount?: boolean;
|
|
1032
|
-
}
|
|
1033
|
-
interface UseScriptAutoFreeGiftResult {
|
|
1034
|
-
involvedLines: NormalizedLineItem[];
|
|
1035
|
-
reorder: (a: NormalizedLineItem, b: NormalizedLineItem) => number;
|
|
1036
|
-
disableCodeRemove: boolean;
|
|
1037
|
-
nextFreeGiftLevel: Breakpoint | null;
|
|
1038
|
-
freeGiftLevel: Breakpoint | null;
|
|
1039
|
-
involvedSubTotal: Decimal;
|
|
1040
|
-
giftProductsResult?: NormalizedProduct[];
|
|
1041
|
-
}
|
|
1042
|
-
declare const useScriptAutoFreeGift: ({ campaign, _giveaway, cart, locale: providedLocale, }: {
|
|
1043
|
-
campaign: Campaign | null;
|
|
1044
|
-
_giveaway: string;
|
|
1045
|
-
cart: NormalizedCart | undefined;
|
|
1046
|
-
locale?: string;
|
|
1047
|
-
}) => UseScriptAutoFreeGiftResult;
|
|
1048
|
-
|
|
1049
1115
|
declare const useUpdateLineCodeAmountAttributes: ({ cart, mutateCart, isCartLoading, setLoadingState, metafieldIdentifiers, }: {
|
|
1050
1116
|
cart?: NormalizedCart;
|
|
1051
1117
|
mutateCart: (cart: NormalizedCart | undefined) => void;
|
|
@@ -1087,6 +1153,17 @@ declare const CODE_AMOUNT_KEY = "_sku_code_money";
|
|
|
1087
1153
|
declare const SCRIPT_CODE_AMOUNT_KEY = "_code_money";
|
|
1088
1154
|
declare const MAIN_PRODUCT_CODE: string[];
|
|
1089
1155
|
|
|
1156
|
+
/**
|
|
1157
|
+
* Normalize AddToCartLineItem[] to NormalizedLineItem[] format
|
|
1158
|
+
* This is used to calculate gifts from lines before they are added to cart
|
|
1159
|
+
*/
|
|
1160
|
+
declare function normalizeAddToCartLines(lines: AddToCartLineItem[]): NormalizedLineItem[];
|
|
1161
|
+
/**
|
|
1162
|
+
* Create a mock cart structure from AddToCartLineItem[]
|
|
1163
|
+
* This is useful for calculating gifts before actual cart operations
|
|
1164
|
+
*/
|
|
1165
|
+
declare function createMockCartFromLines(lines: AddToCartLineItem[], existingCart?: any): any;
|
|
1166
|
+
|
|
1090
1167
|
declare const getQuery: () => Record<string, string>;
|
|
1091
1168
|
declare function atobID(id: string): string | undefined;
|
|
1092
1169
|
declare function btoaID(id: string, type?: 'ProductVariant' | 'Product'): string;
|
|
@@ -1886,4 +1963,4 @@ declare function getCachedGeoLocation(cacheKey?: string): GeoLocationData | unde
|
|
|
1886
1963
|
*/
|
|
1887
1964
|
declare function clearGeoLocationCache(cacheKey?: string): void;
|
|
1888
1965
|
|
|
1889
|
-
export {
|
|
1966
|
+
export { PriceBasePriceType as $, type AddCartLinesInput as A, type BuyNowInput as B, type CreateCartInput as C, type DiscountLabel as D, type Config as E, type GiftTier as F, type GiftProduct as G, type RewardItem as H, type GiftProductItem as I, RuleType as J, BuyRuleType as K, type FunctionGiftResult as L, type MainProductInfo as M, type FormattedGift as N, type OrderDiscountResult as O, type CartLineInput as P, type AutoFreeGiftItem as Q, type RemoveCartLinesInput as R, SpendMoneyType as S, type AutoFreeGiftList as T, type UpdateCartAttributesInput as U, type VariantItem as V, OrderDiscountType as W, OrderBasePriceType as X, type TieredDiscount as Y, type OrderDiscountConfig as Z, PriceDiscountType as _, useAddCartLines as a, type ShippingMethodsContext as a$, type PriceDiscountConfig as a0, currencyCodeMapping as a1, defaultSWRMutationConfiguration as a2, CUSTOMER_ATTRIBUTE_KEY as a3, CUSTOMER_SCRIPT_GIFT_KEY as a4, CODE_AMOUNT_KEY as a5, SCRIPT_CODE_AMOUNT_KEY as a6, MAIN_PRODUCT_CODE as a7, getQuery as a8, atobID as a9, type VideoMedia as aA, type VariantMedia as aB, useVariantMedia as aC, type UseCollectionOptions as aD, useCollection as aE, type UseAllCollectionsOptions as aF, useAllCollections as aG, type UseCollectionsOptions as aH, useCollections as aI, type UseBlogOptions as aJ, useBlog as aK, type UseAllBlogsOptions as aL, useAllBlogs as aM, type UseArticleOptions as aN, useArticle as aO, type UseArticlesOptions as aP, useArticles as aQ, type UseArticlesInBlogOptions as aR, useArticlesInBlog as aS, type SearchResultType as aT, type SearchResultItem as aU, type SearchResult as aV, type UseSearchOptions as aW, useSearch as aX, type SiteInfo as aY, type UseSiteOptions as aZ, useSite as a_, btoaID as aa, normalizeAddToCartLines as ab, createMockCartFromLines as ac, getMatchedMainProductSubTotal as ad, safeParse as ae, getDiscountEnvAttributeValue as af, checkAttributesUpdateNeeded as ag, preCheck as ah, formatScriptAutoFreeGift as ai, formatFunctionAutoFreeGift as aj, useSelectedOptions as ak, type SelectedOptionsResult as al, type UseProductOptions as am, useProduct as an, type UseAllProductsOptions as ao, useAllProducts as ap, type UseProductsByHandlesOptions as aq, useProductsByHandles as ar, type Options as as, useVariant as at, type UsePriceOptions as au, type UsePriceResult as av, usePrice as aw, useProductUrl as ax, useUpdateVariantQuery as ay, type ImageMedia as az, useUpdateCartLines as b, type PlusMemberContextValue as b0, PlusMemberContext as b1, usePlusMemberContext as b2, usePlusMonthlyProductVariant as b3, usePlusAnnualProductVariant as b4, type UseShippingMethodsOptions as b5, type UseShippingMethodsResult as b6, useShippingMethods as b7, useShippingMethodAvailableCheck as b8, useReplaceCartPlusMember as b9, type Image as bA, type Measurement as bB, type ExportSelectedOption as bC, type ExportProductVariant as bD, type ExportDiscountAllocations as bE, type ExportLineItem as bF, type ExportDiscounts as bG, type ExportCart as bH, usePlusMemberDeliveryCodes as ba, usePlusMemberItemCustomAttributes as bb, type CustomerOrder as bc, type Customer as bd, usePlusMemberCheckoutCustomAttributes as be, type UseAutoRemovePlusMemberInCartProps as bf, useAutoRemovePlusMemberInCart as bg, type UseHasPlusMemberInCartProps as bh, type HasPlusMemberInCartResult as bi, useHasPlusMemberInCart as bj, type UseAddPlusMemberProductsToCartProps as bk, useAddPlusMemberProductsToCart as bl, type PlusMemberProviderProps as bm, PlusMemberProvider as bn, type UseIntersectionOptions as bo, useIntersection as bp, type UseExposureOptions as bq, useExposure as br, type GeoLocationData as bs, type LocaleMapping as bt, type UseGeoLocationOptions as bu, useGeoLocation as bv, getCachedGeoLocation as bw, clearGeoLocationCache as bx, type Attribute as by, type Discount as bz, useRemoveCartLines as c, type ApplyCartCodesInput as d, useApplyCartCodes as e, type RemoveCartCodesInput as f, useRemoveCartCodes as g, useUpdateCartAttributes as h, type UseBuyNowOptions as i, useBuyNow as j, useCalcAutoFreeGift as k, type UseCalcGiftsFromLinesOptions as l, type UseCalcGiftsFromLinesResult as m, useCalcGiftsFromLines as n, useCalcOrderDiscount as o, getReferralAttributes as p, useCartAttributes as q, useCartItemQuantityLimit as r, type UseScriptAutoFreeGiftResult as s, useScriptAutoFreeGift as t, useCreateCart as u, useUpdateLineCodeAmountAttributes as v, type AutoFreeGift as w, type AutoFreeGiftMainProduct as x, type AutoFreeGiftConfig as y, type RuleCondition as z };
|
|
@@ -428,8 +428,108 @@ type AutoFreeGiftList = AutoFreeGiftItem[] | [];
|
|
|
428
428
|
* 此 Hook 不产生任何副作用。
|
|
429
429
|
* 使用示例:
|
|
430
430
|
* const { qualifyingGift, nextTierGoal, activeCampaign, isLoading } = useCalcAutoFreeGift(cart, autoFreeGiftConfig);
|
|
431
|
+
*
|
|
432
|
+
* 也可以传入 lines 参数来计算加购前的赠品:
|
|
433
|
+
* const { qualifyingGift, nextTierGoal, activeCampaign, isLoading } = useCalcAutoFreeGift(cart, autoFreeGiftConfig, customer, lines);
|
|
431
434
|
*/
|
|
432
|
-
declare const useCalcAutoFreeGift: (cart: any, autoFreeGiftConfig: AutoFreeGiftConfig, customer: any) => FunctionGiftResult;
|
|
435
|
+
declare const useCalcAutoFreeGift: (cart: any, autoFreeGiftConfig: AutoFreeGiftConfig, customer: any, lines?: AddToCartLineItem[]) => FunctionGiftResult;
|
|
436
|
+
|
|
437
|
+
interface GiveawayProduct {
|
|
438
|
+
handle: string;
|
|
439
|
+
sku: string;
|
|
440
|
+
}
|
|
441
|
+
interface Breakpoint {
|
|
442
|
+
breakpoint: string;
|
|
443
|
+
giveawayProducts: GiveawayProduct[];
|
|
444
|
+
}
|
|
445
|
+
interface Campaign {
|
|
446
|
+
activityAvailableQuery?: string;
|
|
447
|
+
activityQroperty?: string;
|
|
448
|
+
breakpoints?: Array<{
|
|
449
|
+
breakpoint: string;
|
|
450
|
+
giveawayProducts: GiveawayProduct[];
|
|
451
|
+
}>;
|
|
452
|
+
includeTags?: string[];
|
|
453
|
+
useTotalAmount?: boolean;
|
|
454
|
+
}
|
|
455
|
+
interface UseScriptAutoFreeGiftResult {
|
|
456
|
+
involvedLines: NormalizedLineItem[];
|
|
457
|
+
reorder: (a: NormalizedLineItem, b: NormalizedLineItem) => number;
|
|
458
|
+
disableCodeRemove: boolean;
|
|
459
|
+
nextFreeGiftLevel: Breakpoint | null;
|
|
460
|
+
freeGiftLevel: Breakpoint | null;
|
|
461
|
+
involvedSubTotal: Decimal;
|
|
462
|
+
giftProductsResult?: NormalizedProduct[];
|
|
463
|
+
}
|
|
464
|
+
declare const useScriptAutoFreeGift: ({ campaign, _giveaway, cart, locale: providedLocale, lines, }: {
|
|
465
|
+
campaign: Campaign | null;
|
|
466
|
+
_giveaway: string;
|
|
467
|
+
cart: NormalizedCart | undefined;
|
|
468
|
+
locale?: string;
|
|
469
|
+
lines?: AddToCartLineItem[];
|
|
470
|
+
}) => UseScriptAutoFreeGiftResult;
|
|
471
|
+
|
|
472
|
+
interface UseCalcGiftsFromLinesOptions {
|
|
473
|
+
/** Lines to calculate gifts from (AddToCartLineItem format) */
|
|
474
|
+
lines: AddToCartLineItem[];
|
|
475
|
+
/** Auto free gift configuration (Function gift) */
|
|
476
|
+
autoFreeGiftConfig?: AutoFreeGiftConfig;
|
|
477
|
+
/** Customer information (required for function gift) */
|
|
478
|
+
customer?: any;
|
|
479
|
+
/** Script gift campaign configuration */
|
|
480
|
+
scriptCampaign?: any;
|
|
481
|
+
/** Script giveaway attribute key */
|
|
482
|
+
scriptGiveawayKey?: string;
|
|
483
|
+
/** Locale for product fetching (optional, will use from ShopifyProvider if not provided) */
|
|
484
|
+
locale?: string;
|
|
485
|
+
}
|
|
486
|
+
interface UseCalcGiftsFromLinesResult {
|
|
487
|
+
/** Function gift calculation result */
|
|
488
|
+
functionGift: FunctionGiftResult;
|
|
489
|
+
/** Script gift calculation result */
|
|
490
|
+
scriptGift: UseScriptAutoFreeGiftResult;
|
|
491
|
+
/** All gift lines that need to be added to cart (combined from both) */
|
|
492
|
+
allGiftLines: CartLineInput[];
|
|
493
|
+
/** Whether any gifts are available */
|
|
494
|
+
hasGifts: boolean;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Calculate gifts from AddToCartLineItem[] before adding to cart
|
|
498
|
+
* Supports both function-based gifts (useCalcAutoFreeGift) and script-based gifts (useScriptAutoFreeGift)
|
|
499
|
+
*
|
|
500
|
+
* Automatically uses locale from ShopifyProvider and cart from CartContext if not provided.
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```tsx
|
|
504
|
+
* // Basic usage (locale from context, customer required for function gift)
|
|
505
|
+
* const { allGiftLines, hasGifts } = useCalcGiftsFromLines({
|
|
506
|
+
* lines: [{ variant: myVariant, quantity: 2 }],
|
|
507
|
+
* customer: currentCustomer,
|
|
508
|
+
* autoFreeGiftConfig: functionGiftConfig,
|
|
509
|
+
* scriptCampaign: scriptGiftConfig,
|
|
510
|
+
* })
|
|
511
|
+
*
|
|
512
|
+
* // Script gift only (no customer needed)
|
|
513
|
+
* const { allGiftLines, hasGifts } = useCalcGiftsFromLines({
|
|
514
|
+
* lines: [{ variant: myVariant, quantity: 2 }],
|
|
515
|
+
* scriptCampaign: scriptGiftConfig,
|
|
516
|
+
* })
|
|
517
|
+
*
|
|
518
|
+
* // With custom locale
|
|
519
|
+
* const { allGiftLines, hasGifts } = useCalcGiftsFromLines({
|
|
520
|
+
* lines: [{ variant: myVariant, quantity: 2 }],
|
|
521
|
+
* customer: currentCustomer,
|
|
522
|
+
* locale: 'fr',
|
|
523
|
+
* autoFreeGiftConfig: functionGiftConfig,
|
|
524
|
+
* })
|
|
525
|
+
*
|
|
526
|
+
* // Then add both products and gifts to cart
|
|
527
|
+
* await addToCart({
|
|
528
|
+
* lineItems: [...lines, ...allGiftLines]
|
|
529
|
+
* })
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
declare function useCalcGiftsFromLines({ lines, customer, scriptGiveawayKey, }: UseCalcGiftsFromLinesOptions): UseCalcGiftsFromLinesResult;
|
|
433
533
|
|
|
434
534
|
declare enum OrderDiscountType {
|
|
435
535
|
PERCENTAGE = 1,// 百分比折扣
|
|
@@ -1012,40 +1112,6 @@ declare const useCartItemQuantityLimit: ({ cart, cartItem, config, }: {
|
|
|
1012
1112
|
max: number;
|
|
1013
1113
|
};
|
|
1014
1114
|
|
|
1015
|
-
interface GiveawayProduct {
|
|
1016
|
-
handle: string;
|
|
1017
|
-
sku: string;
|
|
1018
|
-
}
|
|
1019
|
-
interface Breakpoint {
|
|
1020
|
-
breakpoint: string;
|
|
1021
|
-
giveawayProducts: GiveawayProduct[];
|
|
1022
|
-
}
|
|
1023
|
-
interface Campaign {
|
|
1024
|
-
activityAvailableQuery?: string;
|
|
1025
|
-
activityQroperty?: string;
|
|
1026
|
-
breakpoints?: Array<{
|
|
1027
|
-
breakpoint: string;
|
|
1028
|
-
giveawayProducts: GiveawayProduct[];
|
|
1029
|
-
}>;
|
|
1030
|
-
includeTags?: string[];
|
|
1031
|
-
useTotalAmount?: boolean;
|
|
1032
|
-
}
|
|
1033
|
-
interface UseScriptAutoFreeGiftResult {
|
|
1034
|
-
involvedLines: NormalizedLineItem[];
|
|
1035
|
-
reorder: (a: NormalizedLineItem, b: NormalizedLineItem) => number;
|
|
1036
|
-
disableCodeRemove: boolean;
|
|
1037
|
-
nextFreeGiftLevel: Breakpoint | null;
|
|
1038
|
-
freeGiftLevel: Breakpoint | null;
|
|
1039
|
-
involvedSubTotal: Decimal;
|
|
1040
|
-
giftProductsResult?: NormalizedProduct[];
|
|
1041
|
-
}
|
|
1042
|
-
declare const useScriptAutoFreeGift: ({ campaign, _giveaway, cart, locale: providedLocale, }: {
|
|
1043
|
-
campaign: Campaign | null;
|
|
1044
|
-
_giveaway: string;
|
|
1045
|
-
cart: NormalizedCart | undefined;
|
|
1046
|
-
locale?: string;
|
|
1047
|
-
}) => UseScriptAutoFreeGiftResult;
|
|
1048
|
-
|
|
1049
1115
|
declare const useUpdateLineCodeAmountAttributes: ({ cart, mutateCart, isCartLoading, setLoadingState, metafieldIdentifiers, }: {
|
|
1050
1116
|
cart?: NormalizedCart;
|
|
1051
1117
|
mutateCart: (cart: NormalizedCart | undefined) => void;
|
|
@@ -1087,6 +1153,17 @@ declare const CODE_AMOUNT_KEY = "_sku_code_money";
|
|
|
1087
1153
|
declare const SCRIPT_CODE_AMOUNT_KEY = "_code_money";
|
|
1088
1154
|
declare const MAIN_PRODUCT_CODE: string[];
|
|
1089
1155
|
|
|
1156
|
+
/**
|
|
1157
|
+
* Normalize AddToCartLineItem[] to NormalizedLineItem[] format
|
|
1158
|
+
* This is used to calculate gifts from lines before they are added to cart
|
|
1159
|
+
*/
|
|
1160
|
+
declare function normalizeAddToCartLines(lines: AddToCartLineItem[]): NormalizedLineItem[];
|
|
1161
|
+
/**
|
|
1162
|
+
* Create a mock cart structure from AddToCartLineItem[]
|
|
1163
|
+
* This is useful for calculating gifts before actual cart operations
|
|
1164
|
+
*/
|
|
1165
|
+
declare function createMockCartFromLines(lines: AddToCartLineItem[], existingCart?: any): any;
|
|
1166
|
+
|
|
1090
1167
|
declare const getQuery: () => Record<string, string>;
|
|
1091
1168
|
declare function atobID(id: string): string | undefined;
|
|
1092
1169
|
declare function btoaID(id: string, type?: 'ProductVariant' | 'Product'): string;
|
|
@@ -1886,4 +1963,4 @@ declare function getCachedGeoLocation(cacheKey?: string): GeoLocationData | unde
|
|
|
1886
1963
|
*/
|
|
1887
1964
|
declare function clearGeoLocationCache(cacheKey?: string): void;
|
|
1888
1965
|
|
|
1889
|
-
export {
|
|
1966
|
+
export { PriceBasePriceType as $, type AddCartLinesInput as A, type BuyNowInput as B, type CreateCartInput as C, type DiscountLabel as D, type Config as E, type GiftTier as F, type GiftProduct as G, type RewardItem as H, type GiftProductItem as I, RuleType as J, BuyRuleType as K, type FunctionGiftResult as L, type MainProductInfo as M, type FormattedGift as N, type OrderDiscountResult as O, type CartLineInput as P, type AutoFreeGiftItem as Q, type RemoveCartLinesInput as R, SpendMoneyType as S, type AutoFreeGiftList as T, type UpdateCartAttributesInput as U, type VariantItem as V, OrderDiscountType as W, OrderBasePriceType as X, type TieredDiscount as Y, type OrderDiscountConfig as Z, PriceDiscountType as _, useAddCartLines as a, type ShippingMethodsContext as a$, type PriceDiscountConfig as a0, currencyCodeMapping as a1, defaultSWRMutationConfiguration as a2, CUSTOMER_ATTRIBUTE_KEY as a3, CUSTOMER_SCRIPT_GIFT_KEY as a4, CODE_AMOUNT_KEY as a5, SCRIPT_CODE_AMOUNT_KEY as a6, MAIN_PRODUCT_CODE as a7, getQuery as a8, atobID as a9, type VideoMedia as aA, type VariantMedia as aB, useVariantMedia as aC, type UseCollectionOptions as aD, useCollection as aE, type UseAllCollectionsOptions as aF, useAllCollections as aG, type UseCollectionsOptions as aH, useCollections as aI, type UseBlogOptions as aJ, useBlog as aK, type UseAllBlogsOptions as aL, useAllBlogs as aM, type UseArticleOptions as aN, useArticle as aO, type UseArticlesOptions as aP, useArticles as aQ, type UseArticlesInBlogOptions as aR, useArticlesInBlog as aS, type SearchResultType as aT, type SearchResultItem as aU, type SearchResult as aV, type UseSearchOptions as aW, useSearch as aX, type SiteInfo as aY, type UseSiteOptions as aZ, useSite as a_, btoaID as aa, normalizeAddToCartLines as ab, createMockCartFromLines as ac, getMatchedMainProductSubTotal as ad, safeParse as ae, getDiscountEnvAttributeValue as af, checkAttributesUpdateNeeded as ag, preCheck as ah, formatScriptAutoFreeGift as ai, formatFunctionAutoFreeGift as aj, useSelectedOptions as ak, type SelectedOptionsResult as al, type UseProductOptions as am, useProduct as an, type UseAllProductsOptions as ao, useAllProducts as ap, type UseProductsByHandlesOptions as aq, useProductsByHandles as ar, type Options as as, useVariant as at, type UsePriceOptions as au, type UsePriceResult as av, usePrice as aw, useProductUrl as ax, useUpdateVariantQuery as ay, type ImageMedia as az, useUpdateCartLines as b, type PlusMemberContextValue as b0, PlusMemberContext as b1, usePlusMemberContext as b2, usePlusMonthlyProductVariant as b3, usePlusAnnualProductVariant as b4, type UseShippingMethodsOptions as b5, type UseShippingMethodsResult as b6, useShippingMethods as b7, useShippingMethodAvailableCheck as b8, useReplaceCartPlusMember as b9, type Image as bA, type Measurement as bB, type ExportSelectedOption as bC, type ExportProductVariant as bD, type ExportDiscountAllocations as bE, type ExportLineItem as bF, type ExportDiscounts as bG, type ExportCart as bH, usePlusMemberDeliveryCodes as ba, usePlusMemberItemCustomAttributes as bb, type CustomerOrder as bc, type Customer as bd, usePlusMemberCheckoutCustomAttributes as be, type UseAutoRemovePlusMemberInCartProps as bf, useAutoRemovePlusMemberInCart as bg, type UseHasPlusMemberInCartProps as bh, type HasPlusMemberInCartResult as bi, useHasPlusMemberInCart as bj, type UseAddPlusMemberProductsToCartProps as bk, useAddPlusMemberProductsToCart as bl, type PlusMemberProviderProps as bm, PlusMemberProvider as bn, type UseIntersectionOptions as bo, useIntersection as bp, type UseExposureOptions as bq, useExposure as br, type GeoLocationData as bs, type LocaleMapping as bt, type UseGeoLocationOptions as bu, useGeoLocation as bv, getCachedGeoLocation as bw, clearGeoLocationCache as bx, type Attribute as by, type Discount as bz, useRemoveCartLines as c, type ApplyCartCodesInput as d, useApplyCartCodes as e, type RemoveCartCodesInput as f, useRemoveCartCodes as g, useUpdateCartAttributes as h, type UseBuyNowOptions as i, useBuyNow as j, useCalcAutoFreeGift as k, type UseCalcGiftsFromLinesOptions as l, type UseCalcGiftsFromLinesResult as m, useCalcGiftsFromLines as n, useCalcOrderDiscount as o, getReferralAttributes as p, useCartAttributes as q, useCartItemQuantityLimit as r, type UseScriptAutoFreeGiftResult as s, useScriptAutoFreeGift as t, useCreateCart as u, useUpdateLineCodeAmountAttributes as v, type AutoFreeGift as w, type AutoFreeGiftMainProduct as x, type AutoFreeGiftConfig as y, type RuleCondition as z };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { AttributeInput, CartContextValue, CartProvider, CartProviderProps, LoadingState, ShopifyContext, ShopifyContextValue, ShopifyProvider, ShopifyProviderProps, useCartContext, useShopify } from './provider/index.mjs';
|
|
2
2
|
export { b as CartCookieAdapter, C as CookieAdapter, a as CookieOptions, R as RouterAdapter, U as UserContextAdapter } from './types-BLMoxbOk.mjs';
|
|
3
3
|
export { browserCartCookieAdapter, browserCookieAdapter } from './adapters/index.mjs';
|
|
4
|
-
export { A as AddCartLinesInput, d as ApplyCartCodesInput,
|
|
4
|
+
export { A as AddCartLinesInput, d as ApplyCartCodesInput, by as Attribute, w as AutoFreeGift, y as AutoFreeGiftConfig, Q as AutoFreeGiftItem, T as AutoFreeGiftList, x as AutoFreeGiftMainProduct, B as BuyNowInput, K as BuyRuleType, a5 as CODE_AMOUNT_KEY, a3 as CUSTOMER_ATTRIBUTE_KEY, a4 as CUSTOMER_SCRIPT_GIFT_KEY, P as CartLineInput, E as Config, C as CreateCartInput, bd as Customer, bc as CustomerOrder, bz as Discount, D as DiscountLabel, bH as ExportCart, bE as ExportDiscountAllocations, bG as ExportDiscounts, bF as ExportLineItem, bD as ExportProductVariant, bC as ExportSelectedOption, N as FormattedGift, L as FunctionGiftResult, bs as GeoLocationData, G as GiftProduct, I as GiftProductItem, F as GiftTier, bi as HasPlusMemberInCartResult, bA as Image, az as ImageMedia, bt as LocaleMapping, a7 as MAIN_PRODUCT_CODE, M as MainProductInfo, bB as Measurement, as as Options, X as OrderBasePriceType, Z as OrderDiscountConfig, O as OrderDiscountResult, W as OrderDiscountType, b1 as PlusMemberContext, b0 as PlusMemberContextValue, bn as PlusMemberProvider, bm as PlusMemberProviderProps, $ as PriceBasePriceType, a0 as PriceDiscountConfig, _ as PriceDiscountType, f as RemoveCartCodesInput, R as RemoveCartLinesInput, H as RewardItem, z as RuleCondition, J as RuleType, a6 as SCRIPT_CODE_AMOUNT_KEY, aV as SearchResult, aU as SearchResultItem, aT as SearchResultType, al as SelectedOptionsResult, a$ as ShippingMethodsContext, aY as SiteInfo, S as SpendMoneyType, Y as TieredDiscount, U as UpdateCartAttributesInput, bk as UseAddPlusMemberProductsToCartProps, aL as UseAllBlogsOptions, aF as UseAllCollectionsOptions, ao as UseAllProductsOptions, aN as UseArticleOptions, aR as UseArticlesInBlogOptions, aP as UseArticlesOptions, bf as UseAutoRemovePlusMemberInCartProps, aJ as UseBlogOptions, i as UseBuyNowOptions, l as UseCalcGiftsFromLinesOptions, m as UseCalcGiftsFromLinesResult, aD as UseCollectionOptions, aH as UseCollectionsOptions, bq as UseExposureOptions, bu as UseGeoLocationOptions, bh as UseHasPlusMemberInCartProps, bo as UseIntersectionOptions, au as UsePriceOptions, av as UsePriceResult, am as UseProductOptions, aq as UseProductsByHandlesOptions, s as UseScriptAutoFreeGiftResult, aW as UseSearchOptions, b5 as UseShippingMethodsOptions, b6 as UseShippingMethodsResult, aZ as UseSiteOptions, V as VariantItem, aB as VariantMedia, aA as VideoMedia, a9 as atobID, aa as btoaID, ag as checkAttributesUpdateNeeded, bx as clearGeoLocationCache, ac as createMockCartFromLines, a1 as currencyCodeMapping, a2 as defaultSWRMutationConfiguration, aj as formatFunctionAutoFreeGift, ai as formatScriptAutoFreeGift, bw as getCachedGeoLocation, af as getDiscountEnvAttributeValue, ad as getMatchedMainProductSubTotal, a8 as getQuery, p as getReferralAttributes, ab as normalizeAddToCartLines, ah as preCheck, ae as safeParse, a as useAddCartLines, bl as useAddPlusMemberProductsToCart, aM as useAllBlogs, aG as useAllCollections, ap as useAllProducts, e as useApplyCartCodes, aO as useArticle, aQ as useArticles, aS as useArticlesInBlog, bg as useAutoRemovePlusMemberInCart, aK as useBlog, j as useBuyNow, k as useCalcAutoFreeGift, n as useCalcGiftsFromLines, o as useCalcOrderDiscount, q as useCartAttributes, r as useCartItemQuantityLimit, aE as useCollection, aI as useCollections, u as useCreateCart, br as useExposure, bv as useGeoLocation, bj as useHasPlusMemberInCart, bp as useIntersection, b4 as usePlusAnnualProductVariant, be as usePlusMemberCheckoutCustomAttributes, b2 as usePlusMemberContext, ba as usePlusMemberDeliveryCodes, bb as usePlusMemberItemCustomAttributes, b3 as usePlusMonthlyProductVariant, aw as usePrice, an as useProduct, ax as useProductUrl, ar as useProductsByHandles, g as useRemoveCartCodes, c as useRemoveCartLines, b9 as useReplaceCartPlusMember, t as useScriptAutoFreeGift, aX as useSearch, ak as useSelectedOptions, b8 as useShippingMethodAvailableCheck, b7 as useShippingMethods, a_ as useSite, h as useUpdateCartAttributes, b as useUpdateCartLines, v as useUpdateLineCodeAmountAttributes, ay as useUpdateVariantQuery, at as useVariant, aC as useVariantMedia } from './index-Utuz9i5x.mjs';
|
|
5
5
|
export { a as AddToCartInput, A as AddToCartLineItem, B as BuyNowTrackConfig, h as DeliveryCustomData, i as DeliveryData, g as DeliveryOption, D as DeliveryPlusType, G as GtmParams, M as MailingAddress, P as PLUS_MEMBER_TYPE, b as PlusMemberMode, e as PlusMemberSettingsMetafields, d as PlusMemberShippingMethodConfig, c as PlusMemberShippingMethodMetafields, f as SelectedPlusMemberProduct, S as ShippingMethodMode, U as UseAddToCartOptions, j as gaTrack, m as trackAddToCartFBQ, t as trackAddToCartGA, k as trackBeginCheckoutGA, n as trackBuyNowFBQ, l as trackBuyNowGA, u as useAddToCart } from './types-CICUnw0v.mjs';
|
|
6
6
|
export { ShopifyConfig, clearLocalStorage, createShopifyClient, getLocalStorage, removeLocalStorage, setLocalStorage } from '@anker-in/shopify-sdk';
|
|
7
7
|
import 'react';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { AttributeInput, CartContextValue, CartProvider, CartProviderProps, LoadingState, ShopifyContext, ShopifyContextValue, ShopifyProvider, ShopifyProviderProps, useCartContext, useShopify } from './provider/index.js';
|
|
2
2
|
export { b as CartCookieAdapter, C as CookieAdapter, a as CookieOptions, R as RouterAdapter, U as UserContextAdapter } from './types-BLMoxbOk.js';
|
|
3
3
|
export { browserCartCookieAdapter, browserCookieAdapter } from './adapters/index.js';
|
|
4
|
-
export { A as AddCartLinesInput, d as ApplyCartCodesInput,
|
|
4
|
+
export { A as AddCartLinesInput, d as ApplyCartCodesInput, by as Attribute, w as AutoFreeGift, y as AutoFreeGiftConfig, Q as AutoFreeGiftItem, T as AutoFreeGiftList, x as AutoFreeGiftMainProduct, B as BuyNowInput, K as BuyRuleType, a5 as CODE_AMOUNT_KEY, a3 as CUSTOMER_ATTRIBUTE_KEY, a4 as CUSTOMER_SCRIPT_GIFT_KEY, P as CartLineInput, E as Config, C as CreateCartInput, bd as Customer, bc as CustomerOrder, bz as Discount, D as DiscountLabel, bH as ExportCart, bE as ExportDiscountAllocations, bG as ExportDiscounts, bF as ExportLineItem, bD as ExportProductVariant, bC as ExportSelectedOption, N as FormattedGift, L as FunctionGiftResult, bs as GeoLocationData, G as GiftProduct, I as GiftProductItem, F as GiftTier, bi as HasPlusMemberInCartResult, bA as Image, az as ImageMedia, bt as LocaleMapping, a7 as MAIN_PRODUCT_CODE, M as MainProductInfo, bB as Measurement, as as Options, X as OrderBasePriceType, Z as OrderDiscountConfig, O as OrderDiscountResult, W as OrderDiscountType, b1 as PlusMemberContext, b0 as PlusMemberContextValue, bn as PlusMemberProvider, bm as PlusMemberProviderProps, $ as PriceBasePriceType, a0 as PriceDiscountConfig, _ as PriceDiscountType, f as RemoveCartCodesInput, R as RemoveCartLinesInput, H as RewardItem, z as RuleCondition, J as RuleType, a6 as SCRIPT_CODE_AMOUNT_KEY, aV as SearchResult, aU as SearchResultItem, aT as SearchResultType, al as SelectedOptionsResult, a$ as ShippingMethodsContext, aY as SiteInfo, S as SpendMoneyType, Y as TieredDiscount, U as UpdateCartAttributesInput, bk as UseAddPlusMemberProductsToCartProps, aL as UseAllBlogsOptions, aF as UseAllCollectionsOptions, ao as UseAllProductsOptions, aN as UseArticleOptions, aR as UseArticlesInBlogOptions, aP as UseArticlesOptions, bf as UseAutoRemovePlusMemberInCartProps, aJ as UseBlogOptions, i as UseBuyNowOptions, l as UseCalcGiftsFromLinesOptions, m as UseCalcGiftsFromLinesResult, aD as UseCollectionOptions, aH as UseCollectionsOptions, bq as UseExposureOptions, bu as UseGeoLocationOptions, bh as UseHasPlusMemberInCartProps, bo as UseIntersectionOptions, au as UsePriceOptions, av as UsePriceResult, am as UseProductOptions, aq as UseProductsByHandlesOptions, s as UseScriptAutoFreeGiftResult, aW as UseSearchOptions, b5 as UseShippingMethodsOptions, b6 as UseShippingMethodsResult, aZ as UseSiteOptions, V as VariantItem, aB as VariantMedia, aA as VideoMedia, a9 as atobID, aa as btoaID, ag as checkAttributesUpdateNeeded, bx as clearGeoLocationCache, ac as createMockCartFromLines, a1 as currencyCodeMapping, a2 as defaultSWRMutationConfiguration, aj as formatFunctionAutoFreeGift, ai as formatScriptAutoFreeGift, bw as getCachedGeoLocation, af as getDiscountEnvAttributeValue, ad as getMatchedMainProductSubTotal, a8 as getQuery, p as getReferralAttributes, ab as normalizeAddToCartLines, ah as preCheck, ae as safeParse, a as useAddCartLines, bl as useAddPlusMemberProductsToCart, aM as useAllBlogs, aG as useAllCollections, ap as useAllProducts, e as useApplyCartCodes, aO as useArticle, aQ as useArticles, aS as useArticlesInBlog, bg as useAutoRemovePlusMemberInCart, aK as useBlog, j as useBuyNow, k as useCalcAutoFreeGift, n as useCalcGiftsFromLines, o as useCalcOrderDiscount, q as useCartAttributes, r as useCartItemQuantityLimit, aE as useCollection, aI as useCollections, u as useCreateCart, br as useExposure, bv as useGeoLocation, bj as useHasPlusMemberInCart, bp as useIntersection, b4 as usePlusAnnualProductVariant, be as usePlusMemberCheckoutCustomAttributes, b2 as usePlusMemberContext, ba as usePlusMemberDeliveryCodes, bb as usePlusMemberItemCustomAttributes, b3 as usePlusMonthlyProductVariant, aw as usePrice, an as useProduct, ax as useProductUrl, ar as useProductsByHandles, g as useRemoveCartCodes, c as useRemoveCartLines, b9 as useReplaceCartPlusMember, t as useScriptAutoFreeGift, aX as useSearch, ak as useSelectedOptions, b8 as useShippingMethodAvailableCheck, b7 as useShippingMethods, a_ as useSite, h as useUpdateCartAttributes, b as useUpdateCartLines, v as useUpdateLineCodeAmountAttributes, ay as useUpdateVariantQuery, at as useVariant, aC as useVariantMedia } from './index-aSsTcW2O.js';
|
|
5
5
|
export { a as AddToCartInput, A as AddToCartLineItem, B as BuyNowTrackConfig, h as DeliveryCustomData, i as DeliveryData, g as DeliveryOption, D as DeliveryPlusType, G as GtmParams, M as MailingAddress, P as PLUS_MEMBER_TYPE, b as PlusMemberMode, e as PlusMemberSettingsMetafields, d as PlusMemberShippingMethodConfig, c as PlusMemberShippingMethodMetafields, f as SelectedPlusMemberProduct, S as ShippingMethodMode, U as UseAddToCartOptions, j as gaTrack, m as trackAddToCartFBQ, t as trackAddToCartGA, k as trackBeginCheckoutGA, n as trackBuyNowFBQ, l as trackBuyNowGA, u as useAddToCart } from './types-CICUnw0v.js';
|
|
6
6
|
export { ShopifyConfig, clearLocalStorage, createShopifyClient, getLocalStorage, removeLocalStorage, setLocalStorage } from '@anker-in/shopify-sdk';
|
|
7
7
|
import 'react';
|