@anker-in/shopify-react 0.1.1-beta.5 → 0.1.1-beta.50

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.
@@ -1,9 +1,1984 @@
1
- export { A as AddCartLinesInput, d as ApplyCartCodesInput, 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, D as DiscountLabel, N as FormattedGift, L as FunctionGiftResult, br as GeoLocationData, G as GiftProduct, I as GiftProductItem, F as GiftTier, bi as HasPlusMemberInCartResult, az as ImageMedia, bs as LocaleMapping, a7 as MAIN_PRODUCT_CODE, M as MainProductInfo, as as Options, X as OrderBasePriceType, Z as OrderDiscountConfig, O as OrderDiscountResult, W as OrderDiscountType, b1 as PlusMemberContext, b0 as PlusMemberContextValue, bm as PlusMemberProvider, bl 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, 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, bp as UseExposureOptions, bt as UseGeoLocationOptions, bh as UseHasPlusMemberInCartProps, bn 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, bw as clearGeoLocationCache, ac as createMockCartFromLines, a1 as currencyCodeMapping, a2 as defaultSWRMutationConfiguration, aj as formatFunctionAutoFreeGift, ai as formatScriptAutoFreeGift, bv 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, bk 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, bq as useExposure, bu as useGeoLocation, bj as useHasPlusMemberInCart, bo 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-eFsqDs13.mjs';
2
- export { a as AddToCartInput, A as AddToCartLineItem, h as DeliveryCustomData, i as DeliveryData, g as DeliveryOption, D as DeliveryPlusType, 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, u as useAddToCart } from '../types-CICUnw0v.mjs';
3
- import 'swr/mutation';
4
- import '@anker-in/shopify-sdk';
5
- import 'decimal.js';
6
- import 'swr';
7
- import 'swr/_internal';
8
- import 'react';
9
- import 'react/jsx-runtime';
1
+ import * as swr_mutation from 'swr/mutation';
2
+ import { SWRMutationConfiguration } from 'swr/mutation';
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 { U as UseAddToCartOptions, a as AddToCartInput, A as AddToCartLineItem, G as GtmParams, B as BuyNowTrackConfig, d as PlusMemberShippingMethodConfig, e as PlusMemberSettingsMetafields, D as DeliveryPlusType, f as SelectedPlusMemberVariant } from '../types-CMMWxyUF.mjs';
6
+ export { g as DeliveryCustomData, P as PLUS_MEMBER_TYPE, b as PlusMemberMode, c as PlusMemberShippingMethodMetafields, S as ShippingMethodMode } from '../types-CMMWxyUF.mjs';
7
+ import Decimal from 'decimal.js';
8
+ import * as swr from 'swr';
9
+ import swr__default, { SWRConfiguration } from 'swr';
10
+ import * as swr__internal from 'swr/_internal';
11
+ import * as React$1 from 'react';
12
+ import { Dispatch, SetStateAction, PropsWithChildren, RefObject } from 'react';
13
+ import * as react_jsx_runtime from 'react/jsx-runtime';
14
+
15
+ interface CreateCartInput {
16
+ /** Lines to add to the cart */
17
+ lines?: CartLineInput[];
18
+ /** Buyer identity for cart creation */
19
+ buyerIdentity?: {
20
+ email?: string;
21
+ countryCode?: string;
22
+ };
23
+ /** Discount codes */
24
+ discountCodes?: string[];
25
+ /** Custom attributes */
26
+ customAttributes?: Array<{
27
+ key: string;
28
+ value: string;
29
+ }>;
30
+ }
31
+ /**
32
+ * Hook for creating a new cart
33
+ *
34
+ * Automatically removes invalid discount codes after creating cart
35
+ *
36
+ * @param options - SWR mutation configuration
37
+ * @returns SWR mutation with trigger function
38
+ *
39
+ * @example
40
+ * ```tsx
41
+ * const { trigger, isMutating } = useCreateCart()
42
+ *
43
+ * // Create empty cart
44
+ * await trigger({})
45
+ *
46
+ * // Create cart with items
47
+ * await trigger({
48
+ * lines: [{
49
+ * merchandiseId: 'gid://shopify/ProductVariant/123',
50
+ * quantity: 1
51
+ * }],
52
+ * buyerIdentity: {
53
+ * email: 'customer@example.com',
54
+ * countryCode: 'US'
55
+ * },
56
+ * discountCodes: ['SUMMER2024']
57
+ * })
58
+ * ```
59
+ */
60
+ declare function useCreateCart({ updateCookie, options, }: {
61
+ updateCookie?: boolean;
62
+ options?: SWRMutationConfiguration<NormalizedCart | undefined, Error, 'create-cart', CreateCartInput>;
63
+ }): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "create-cart", CreateCartInput>;
64
+
65
+ interface AddCartLinesInput {
66
+ /** Cart ID (optional, will create new cart if not provided) */
67
+ cartId?: string;
68
+ /** Lines to add */
69
+ lines: CartLineInput[];
70
+ }
71
+ /**
72
+ * Hook for adding lines to cart
73
+ *
74
+ * - Automatically creates a new cart if no cart ID exists
75
+ * - Automatically removes invalid discount codes after adding items
76
+ *
77
+ * @param options - SWR mutation configuration
78
+ * @returns SWR mutation with trigger function
79
+ *
80
+ * @example
81
+ * ```tsx
82
+ * const { trigger, isMutating } = useAddCartLines()
83
+ *
84
+ * // Add to existing cart
85
+ * await trigger({
86
+ * cartId: 'gid://shopify/Cart/xxx',
87
+ * lines: [{
88
+ * merchandiseId: 'gid://shopify/ProductVariant/123',
89
+ * quantity: 1
90
+ * }]
91
+ * })
92
+ *
93
+ * // Create new cart (no cartId provided)
94
+ * await trigger({
95
+ * lines: [{
96
+ * merchandiseId: 'gid://shopify/ProductVariant/123',
97
+ * quantity: 1
98
+ * }],
99
+ * buyerIdentity: {
100
+ * email: 'customer@example.com',
101
+ * countryCode: 'US'
102
+ * },
103
+ * discountCodes: ['SUMMER2024']
104
+ * })
105
+ * ```
106
+ */
107
+ declare function useAddCartLines(options?: SWRMutationConfiguration<NormalizedCart | undefined, Error, 'add-cart-lines', AddCartLinesInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "add-cart-lines", AddCartLinesInput>;
108
+
109
+ type AutoFreeGift = {
110
+ currentTier: {
111
+ amount: number;
112
+ gift?: NormalizedProductVariant;
113
+ };
114
+ nextTierGoal: {
115
+ amount: number;
116
+ gift?: NormalizedProductVariant;
117
+ };
118
+ };
119
+ type DiscountLabel = {
120
+ cart_checkout_label: string;
121
+ product_label: string;
122
+ sold_out_label: string;
123
+ };
124
+ type AutoFreeGiftMainProduct = {
125
+ spend_money_type: number;
126
+ variant_id_list: string[];
127
+ all_store_variant: boolean;
128
+ };
129
+ type GiftProduct = {
130
+ spend_sum_money: number;
131
+ gift_type: number;
132
+ reward_list: {
133
+ get_unit: number;
134
+ variant_id: string;
135
+ bak_variant_id_list: null;
136
+ }[];
137
+ };
138
+ type AutoFreeGiftConfig = Config[];
139
+ type RuleCondition = {
140
+ with_special_url_params: string[];
141
+ without_special_url_params: string[];
142
+ with_user_tags: string[];
143
+ without_user_tags: string[];
144
+ };
145
+ type MainProductInfo = {
146
+ spend_money_type: SpendMoneyType;
147
+ variant_list: VariantItem[];
148
+ all_store_variant: boolean;
149
+ };
150
+ type Config = {
151
+ rule_id: number;
152
+ rule_type: RuleType;
153
+ discount_label: {
154
+ cart_checkout_label: string;
155
+ product_label: string;
156
+ sold_out_label: string;
157
+ };
158
+ frontend_labels: {
159
+ key: string;
160
+ label: string;
161
+ desc: string;
162
+ }[];
163
+ apply_unit: number;
164
+ rule_result: {
165
+ buy_rule_type: BuyRuleType;
166
+ spend_get_reward: {
167
+ main_product: MainProductInfo;
168
+ gift_product: GiftProductItem[];
169
+ };
170
+ buy_get_reward: {
171
+ main_product: MainProductInfo;
172
+ gift_product: GiftProductItem[] | null;
173
+ };
174
+ };
175
+ rule_conditions?: RuleCondition[];
176
+ };
177
+ interface GiftTier {
178
+ spend_sum_money: number;
179
+ gift_type: number;
180
+ reward_list: RewardItem[];
181
+ }
182
+ interface RewardItem {
183
+ get_unit: number;
184
+ variant_list: VariantItem[];
185
+ }
186
+ interface VariantItem {
187
+ variant_id: string;
188
+ sku: string;
189
+ handle: string;
190
+ discount_value: number;
191
+ }
192
+ interface GiftProductItem {
193
+ spend_sum_money: number;
194
+ gift_type: number;
195
+ reward_list: RewardItem[];
196
+ }
197
+ declare enum RuleType {
198
+ AUTO_FREE_GIFT = 1,// 自动赠品
199
+ BUNDLE = 2,// 组合
200
+ VOLUME_DISCOUNT = 3,// 量价折扣
201
+ ORDER_DISCOUNT = 4,// 订单折扣
202
+ PRICE_DISCOUNT = 5
203
+ }
204
+ declare enum BuyRuleType {
205
+ BUY_GET_GIFT = 1,// 买赠
206
+ SPEND_GET_GIFT = 2
207
+ }
208
+ declare enum SpendMoneyType {
209
+ ORIGIN_PRICE = 1,// 原价
210
+ DISCOUNT_PRICE = 2
211
+ }
212
+ interface FunctionGiftResult {
213
+ qualifyingGift: FormattedGift | null;
214
+ nextTierGoal: GiftTier | null;
215
+ activeCampaign: Config | null;
216
+ isLoading: boolean;
217
+ giftProductsResult?: NormalizedProduct[] | [];
218
+ }
219
+ interface FormattedGift {
220
+ tier: GiftTier;
221
+ itemsToAdd: AutoFreeGiftCartLineInput[];
222
+ }
223
+ interface AutoFreeGiftCartLineInput {
224
+ variant: {
225
+ id: string;
226
+ handle: string;
227
+ sku: string;
228
+ };
229
+ quantity: number;
230
+ attributes: {
231
+ key: string;
232
+ value: string;
233
+ }[];
234
+ }
235
+ type AutoFreeGiftItem = {
236
+ line: NormalizedLineItem;
237
+ isSoldOut: boolean;
238
+ };
239
+ type AutoFreeGiftList = AutoFreeGiftItem[] | [];
240
+
241
+ declare enum OrderDiscountType {
242
+ PERCENTAGE = 1,// 百分比折扣
243
+ FIXED_AMOUNT = 2,// 固定金额折扣
244
+ REDUCE_PRICE = 3
245
+ }
246
+ declare enum OrderBasePriceType {
247
+ ORIGIN_PRICE = 1,// 原价
248
+ MIN_DISCOUNTED_PRICE = 2
249
+ }
250
+ type TieredDiscount = {
251
+ amount: number;
252
+ discount: number;
253
+ discount_type: OrderDiscountType;
254
+ };
255
+ type OrderDiscountConfig = {
256
+ rule_id: number;
257
+ rule_type: number;
258
+ rule_conditions?: RuleCondition[];
259
+ result_detail: {
260
+ main_product: {
261
+ variant_list: Array<{
262
+ variant_id: string;
263
+ sku: string;
264
+ handle: string;
265
+ }>;
266
+ all_store_variant: boolean;
267
+ skip_variants?: Array<{
268
+ variant_id: string;
269
+ sku: string;
270
+ handle: string;
271
+ }>;
272
+ };
273
+ order_discount_conf: {
274
+ base_price: OrderBasePriceType;
275
+ tiered_discounts: TieredDiscount[];
276
+ tiered_discounts_markets?: Record<string, TieredDiscount[]>;
277
+ is_reusable?: boolean;
278
+ min_quantity_items?: number;
279
+ max_apply_times_of_per_order?: number;
280
+ };
281
+ };
282
+ discount_label?: {
283
+ cart_checkout_label?: string;
284
+ product_label?: string;
285
+ sold_out_label?: string;
286
+ };
287
+ frontend_labels?: any[];
288
+ discount_combinations?: {
289
+ other_order_discounts?: boolean;
290
+ other_product_discounts?: boolean;
291
+ shipping_discounts?: boolean;
292
+ };
293
+ };
294
+
295
+ declare enum PriceDiscountType {
296
+ PERCENTAGE = 1,// 百分比折扣
297
+ FIXED_AMOUNT = 2
298
+ }
299
+ declare enum PriceBasePriceType {
300
+ MIN_DISCOUNTED_PRICE = 1,// 最低折扣价
301
+ MIN_TOTAL_PRICE = 2
302
+ }
303
+ type PriceDiscountConfig = {
304
+ rule_id: number;
305
+ rule_type: number;
306
+ discount_type: PriceDiscountType;
307
+ discount_value: number;
308
+ base_price_type: PriceBasePriceType;
309
+ applicable_products: Array<{
310
+ product_id: string;
311
+ variant_id?: string;
312
+ }>;
313
+ };
314
+
315
+ /**
316
+ * Hook for adding items to cart with tracking support
317
+ *
318
+ * This is the enhanced version that includes:
319
+ * - Automatic cart creation if needed
320
+ * - Discount code validation
321
+ * - Google Analytics tracking
322
+ * - Facebook Pixel tracking
323
+ * - Invalid code handling
324
+ *
325
+ * @param options - Hook configuration
326
+ * @param swrOptions - SWR mutation configuration
327
+ * @returns SWR mutation with trigger function
328
+ *
329
+ * @example
330
+ * ```tsx
331
+ * const { trigger, isMutating } = useAddToCart({ withTrack: true})
332
+ *
333
+ * await trigger({
334
+ * lineItems: [{
335
+ * variantId: 'gid://shopify/ProductVariant/123',
336
+ * quantity: 2
337
+ * }],
338
+ * gtmParams: {
339
+ * pageGroup: 'PDP',
340
+ * position: 'Add to Cart Button'
341
+ * }
342
+ * })
343
+ * ```
344
+ */
345
+ declare function useAddToCart({ withTrack }?: UseAddToCartOptions, swrOptions?: SWRMutationConfiguration<NormalizedCart | undefined, Error, string, AddToCartInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, string, AddToCartInput>;
346
+
347
+ /**
348
+ * Hook for updating cart line quantities
349
+ *
350
+ * @param options - SWR mutation configuration
351
+ * @returns SWR mutation with trigger function
352
+ *
353
+ * @example
354
+ * ```tsx
355
+ * const { trigger, isMutating } = useUpdateCartLines()
356
+ *
357
+ * await trigger({
358
+ * lines: [{
359
+ * id: 'gid://shopify/CartLine/123',
360
+ * quantity: 2
361
+ * }]
362
+ * })
363
+ * ```
364
+ */
365
+ declare function useUpdateCartLines(options?: SWRMutationConfiguration<NormalizedCart | undefined, Error, 'update-cart-lines', UpdateCartLinesOptions>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "update-cart-lines", UpdateCartLinesOptions>;
366
+
367
+ interface RemoveCartLinesInput {
368
+ /** Cart ID (optional, will use cookie) */
369
+ cartId?: string;
370
+ /** Line IDs to remove */
371
+ lineIds: string[];
372
+ /** Whether to automatically remove invalid discount codes (default: true) */
373
+ autoRemoveInvalidCodes?: boolean;
374
+ /** Callback when discount codes are removed */
375
+ onCodesRemoved?: (updatedCart: NormalizedCart, removedCodes: string[]) => Promise<NormalizedCart | undefined>;
376
+ }
377
+ /**
378
+ * Hook for removing lines from cart
379
+ *
380
+ * Automatically removes invalid discount codes after removing items
381
+ *
382
+ * @param options - SWR mutation configuration
383
+ * @returns SWR mutation with trigger function
384
+ *
385
+ * @example
386
+ * ```tsx
387
+ * const { trigger, isMutating } = useRemoveCartLines()
388
+ *
389
+ * await trigger({
390
+ * lineIds: ['gid://shopify/CartLine/123']
391
+ * })
392
+ * ```
393
+ */
394
+ declare function useRemoveCartLines(options?: SWRMutationConfiguration<NormalizedCart | undefined, Error, 'remove-cart-lines', RemoveCartLinesInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "remove-cart-lines", RemoveCartLinesInput>;
395
+
396
+ interface ApplyCartCodesInput {
397
+ /** Cart ID (required) */
398
+ cartId?: string;
399
+ /** Discount codes to apply (added to existing applicable codes) */
400
+ discountCodes: string[];
401
+ /** Replace existing applicable codes */
402
+ replaceExistingCodes?: boolean;
403
+ }
404
+ /**
405
+ * Hook for applying discount codes to cart
406
+ *
407
+ * Merges new codes with existing applicable codes and validates them
408
+ *
409
+ * @param options - SWR mutation configuration
410
+ * @returns SWR mutation with trigger function
411
+ *
412
+ * @example
413
+ * ```tsx
414
+ * const { trigger, isMutating, error } = useApplyCartCodes()
415
+ *
416
+ * try {
417
+ * await trigger({
418
+ * cartId: 'gid://shopify/Cart/123',
419
+ * discountCodes: ['SUMMER2024']
420
+ * })
421
+ * } catch (error) {
422
+ * // Handle unapplicable codes
423
+ * }
424
+ * ```
425
+ */
426
+ declare function useApplyCartCodes(options?: SWRMutationConfiguration<NormalizedCart | undefined, Error, 'apply-codes', ApplyCartCodesInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "apply-codes", ApplyCartCodesInput>;
427
+
428
+ interface RemoveCartCodesInput {
429
+ /** Cart ID (required) */
430
+ cartId?: string;
431
+ /** Discount codes to remove */
432
+ discountCodes: string[];
433
+ }
434
+ /**
435
+ * Hook for removing discount codes from cart
436
+ *
437
+ * @param options - SWR mutation configuration
438
+ * @returns SWR mutation with trigger function
439
+ *
440
+ * @example
441
+ * ```tsx
442
+ * const { trigger, isMutating } = useRemoveCartCodes()
443
+ *
444
+ * await trigger({
445
+ * cartId: 'gid://shopify/Cart/123',
446
+ * discountCodes: ['EXPIRED_CODE']
447
+ * })
448
+ * ```
449
+ */
450
+ declare function useRemoveCartCodes(options?: SWRMutationConfiguration<NormalizedCart | undefined, Error, 'remove-codes', RemoveCartCodesInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "remove-codes", RemoveCartCodesInput>;
451
+
452
+ interface UpdateCartAttributesInput {
453
+ /** Cart ID (optional, will use cookie) */
454
+ cartId?: string;
455
+ /** Custom attributes to set on cart */
456
+ attributes: Array<{
457
+ key: string;
458
+ value: string;
459
+ }>;
460
+ }
461
+ interface UseUpdateCartAttributesOptions {
462
+ /** Function to update cart state */
463
+ mutate: (cart: NormalizedCart | undefined) => void;
464
+ /** Metafield identifiers for variant and product */
465
+ metafieldIdentifiers?: {
466
+ variant: HasMetafieldsIdentifier[];
467
+ product: HasMetafieldsIdentifier[];
468
+ };
469
+ /** Disable the mutation */
470
+ disabled?: boolean;
471
+ /** SWR mutation configuration */
472
+ swrOptions?: SWRMutationConfiguration<NormalizedCart | undefined, Error, 'update-cart-attributes', UpdateCartAttributesInput>;
473
+ }
474
+ /**
475
+ * Hook for updating cart attributes (custom key-value pairs)
476
+ *
477
+ * @param options - Hook configuration options
478
+ * @returns SWR mutation with trigger function
479
+ *
480
+ * @example
481
+ * ```tsx
482
+ * const { trigger, isMutating } = useUpdateCartAttributes({
483
+ * mutate: mutateCart,
484
+ * metafieldIdentifiers: {
485
+ * variant: [...],
486
+ * product: [...]
487
+ * }
488
+ * })
489
+ *
490
+ * await trigger({
491
+ * attributes: [
492
+ * { key: 'gift_message', value: 'Happy Birthday!' },
493
+ * { key: 'gift_wrap', value: 'true' }
494
+ * ]
495
+ * })
496
+ * ```
497
+ */
498
+ declare function useUpdateCartAttributes({ mutate, metafieldIdentifiers, disabled, swrOptions, }: UseUpdateCartAttributesOptions): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, "update-cart-attributes", UpdateCartAttributesInput>;
499
+
500
+ interface BuyNowInput {
501
+ /** Metafield identifiers */
502
+ metafieldIdentifiers?: {
503
+ variant: HasMetafieldsIdentifier[];
504
+ product: HasMetafieldsIdentifier[];
505
+ };
506
+ /** Line items to add to the new cart */
507
+ lineItems: Array<AddToCartLineItem>;
508
+ /** Discount codes to apply */
509
+ discountCodes?: string[];
510
+ /** Custom attributes for the cart */
511
+ customAttributes?: Array<{
512
+ key: string;
513
+ value: string;
514
+ }>;
515
+ /** Buyer identity */
516
+ buyerIdentity?: {
517
+ email?: string;
518
+ countryCode?: string;
519
+ };
520
+ /** GTM tracking parameters */
521
+ gtmParams?: Omit<GtmParams, 'brand'>;
522
+ /** Facebook Pixel tracking configuration */
523
+ fbqTrackConfig?: BuyNowTrackConfig;
524
+ /** Whether to redirect to checkout page (default: true) */
525
+ redirectToCheckout?: boolean;
526
+ }
527
+ interface UseBuyNowOptions {
528
+ /** Enable tracking (GA and FBQ) */
529
+ withTrack?: boolean;
530
+ }
531
+ /**
532
+ * Hook for buy now functionality
533
+ *
534
+ * Creates a new cart with the specified items and redirects to checkout.
535
+ * Includes automatic tracking for GA4 and Facebook Pixel.
536
+ *
537
+ * @param options - Hook configuration
538
+ * @param swrOptions - SWR mutation configuration
539
+ * @returns SWR mutation with trigger function
540
+ *
541
+ * @example
542
+ * ```tsx
543
+ * const { trigger, isMutating } = useBuyNow({
544
+ * withTrack: true,
545
+ * redirectToCheckout: true,
546
+ * })
547
+ *
548
+ * await trigger({
549
+ * lineItems: [{
550
+ * variantId: 'gid://shopify/ProductVariant/123',
551
+ * quantity: 1
552
+ * }],
553
+ * gtmParams: {
554
+ * pageGroup: 'PDP',
555
+ * position: 'Buy Now Button'
556
+ * }
557
+ * })
558
+ * ```
559
+ */
560
+ declare function useBuyNow({ withTrack }?: UseBuyNowOptions, swrOptions?: SWRMutationConfiguration<NormalizedCart | undefined, Error, string, BuyNowInput>): swr_mutation.SWRMutationResponse<NormalizedCart | undefined, Error, string, BuyNowInput>;
561
+
562
+ /**
563
+ * [计算型 Hook]
564
+ * 根据购物车、活动配置和用户信息,计算出应得的赠品和下一个目标。
565
+ * 此 Hook 不产生任何副作用。
566
+ * 使用示例:
567
+ * const { qualifyingGift, nextTierGoal, activeCampaign, isLoading } = useCalcAutoFreeGift(cart, autoFreeGiftConfig);
568
+ *
569
+ * 也可以传入 lines 参数来计算加购前的赠品:
570
+ * const { qualifyingGift, nextTierGoal, activeCampaign, isLoading } = useCalcAutoFreeGift(cart, autoFreeGiftConfig, customer, lines);
571
+ */
572
+ declare const useCalcAutoFreeGift: (cart: any, autoFreeGiftConfig: AutoFreeGiftConfig, customer: any, lines?: AddToCartLineItem[]) => FunctionGiftResult;
573
+
574
+ interface GiveawayProduct {
575
+ handle: string;
576
+ sku: string;
577
+ }
578
+ interface Breakpoint {
579
+ breakpoint: string;
580
+ giveawayProducts: GiveawayProduct[];
581
+ }
582
+ interface Campaign {
583
+ activityAvailableQuery?: string;
584
+ activityQroperty?: string;
585
+ breakpoints?: Array<{
586
+ breakpoint: string;
587
+ giveawayProducts: GiveawayProduct[];
588
+ }>;
589
+ includeTags?: string[];
590
+ useTotalAmount?: boolean;
591
+ requireLogin?: boolean;
592
+ }
593
+ interface UseScriptAutoFreeGiftResult {
594
+ involvedLines: NormalizedLineItem[];
595
+ reorder: (a: NormalizedLineItem, b: NormalizedLineItem) => number;
596
+ disableCodeRemove: boolean;
597
+ nextFreeGiftLevel: Breakpoint | null;
598
+ freeGiftLevel: Breakpoint | null;
599
+ involvedSubTotal: Decimal;
600
+ giftProductsResult?: NormalizedProduct[];
601
+ }
602
+ declare const useScriptAutoFreeGift: ({ campaign, _giveaway, cart, locale: providedLocale, lines, profile, }: {
603
+ campaign: Campaign | null;
604
+ _giveaway: string;
605
+ cart: NormalizedCart | undefined;
606
+ locale?: string;
607
+ lines?: AddToCartLineItem[];
608
+ profile?: any;
609
+ }) => UseScriptAutoFreeGiftResult;
610
+
611
+ interface UseCalcGiftsFromLinesOptions {
612
+ /** Lines to calculate gifts from (AddToCartLineItem format) */
613
+ lines: AddToCartLineItem[];
614
+ /** Auto free gift configuration (Function gift) */
615
+ autoFreeGiftConfig?: AutoFreeGiftConfig;
616
+ /** Customer information (required for function gift) */
617
+ customer?: any;
618
+ /** Script gift campaign configuration */
619
+ scriptCampaign?: any;
620
+ /** Script giveaway attribute key */
621
+ scriptGiveawayKey?: string;
622
+ /** Locale for product fetching (optional, will use from ShopifyProvider if not provided) */
623
+ locale?: string;
624
+ }
625
+ interface UseCalcGiftsFromLinesResult {
626
+ /** Function gift calculation result */
627
+ functionGift: FunctionGiftResult;
628
+ /** Script gift calculation result */
629
+ scriptGift: UseScriptAutoFreeGiftResult;
630
+ /** All gift lines that need to be added to cart (combined from both) */
631
+ allGiftLines: AddToCartLineItem[];
632
+ /** Whether any gifts are available */
633
+ hasGifts: boolean;
634
+ }
635
+ /**
636
+ * Calculate gifts from AddToCartLineItem[] before adding to cart
637
+ * Supports both function-based gifts (useCalcAutoFreeGift) and script-based gifts (useScriptAutoFreeGift)
638
+ *
639
+ * Automatically uses locale from ShopifyProvider and cart from CartContext if not provided.
640
+ *
641
+ * @example
642
+ * ```tsx
643
+ * // Basic usage (locale from context, customer required for function gift)
644
+ * const { allGiftLines, hasGifts } = useCalcGiftsFromLines({
645
+ * lines: [{ variant: myVariant, quantity: 2 }],
646
+ * customer: currentCustomer,
647
+ * autoFreeGiftConfig: functionGiftConfig,
648
+ * scriptCampaign: scriptGiftConfig,
649
+ * })
650
+ *
651
+ * // Script gift only (no customer needed)
652
+ * const { allGiftLines, hasGifts } = useCalcGiftsFromLines({
653
+ * lines: [{ variant: myVariant, quantity: 2 }],
654
+ * scriptCampaign: scriptGiftConfig,
655
+ * })
656
+ *
657
+ * // With custom locale
658
+ * const { allGiftLines, hasGifts } = useCalcGiftsFromLines({
659
+ * lines: [{ variant: myVariant, quantity: 2 }],
660
+ * customer: currentCustomer,
661
+ * locale: 'fr',
662
+ * autoFreeGiftConfig: functionGiftConfig,
663
+ * })
664
+ *
665
+ * // Then add both products and gifts to cart
666
+ * await addToCart({
667
+ * lineItems: [...lines, ...allGiftLines]
668
+ * })
669
+ * ```
670
+ */
671
+ declare function useCalcGiftsFromLines({ lines, customer, scriptGiveawayKey, }: UseCalcGiftsFromLinesOptions): UseCalcGiftsFromLinesResult;
672
+
673
+ interface OrderDiscountResult {
674
+ qualifyingDiscount: TieredDiscount | null;
675
+ nextTierGoal: TieredDiscount | null;
676
+ activeCampaign: OrderDiscountConfig | null;
677
+ discountAmount: number;
678
+ cartTotalForDiscount: number;
679
+ isLoading: boolean;
680
+ }
681
+ /**
682
+ * [计算型 Hook]
683
+ * 根据购物车、活动配置和用户信息,计算出应得的订单折扣和下一个目标。
684
+ * 此 Hook 不产生任何副作用。
685
+ * 使用示例:
686
+ * const { qualifyingDiscount, nextTierGoal, activeCampaign, discountAmount, isLoading } = useCalcOrderDiscount(cart, orderDiscountConfig);
687
+ * @param cart - 购物车
688
+ * @param orderDiscountConfig - 订单折扣配置
689
+ * @returns { OrderDiscountResult }
690
+ */
691
+ declare const useCalcOrderDiscount: (cart: any, orderDiscountConfig?: OrderDiscountConfig[], customer?: any) => OrderDiscountResult;
692
+
693
+ declare const getReferralAttributes: () => {
694
+ key: string;
695
+ value: any;
696
+ }[];
697
+ /**
698
+ * Get user type based on customer information
699
+ */
700
+ declare const getUserType: (customer?: any) => string;
701
+ interface GetCartAttributesProps {
702
+ profile?: any;
703
+ customer?: any;
704
+ cart?: NormalizedCart;
705
+ memberType?: string;
706
+ currentUrl?: string;
707
+ }
708
+ /**
709
+ * Get cart attributes (pure function version)
710
+ */
711
+ declare function getCartAttributes({ profile, customer, cart, memberType, currentUrl, }: GetCartAttributesProps): Array<{
712
+ key: string;
713
+ value: any;
714
+ }>;
715
+ /**
716
+ * Hook to get cart attributes
717
+ */
718
+ declare const useCartAttributes: ({ profile, customer, cart, memberType, }: {
719
+ profile: any;
720
+ customer: any;
721
+ cart?: NormalizedCart;
722
+ memberType?: string;
723
+ }) => {
724
+ attributes: Array<{
725
+ key: string;
726
+ value: any;
727
+ }>;
728
+ };
729
+
730
+ declare const useCartItemQuantityLimit: ({ cart, cartItem, config, }: {
731
+ cart?: NormalizedCart;
732
+ cartItem: NormalizedLineItem;
733
+ config: {
734
+ handle: Record<string, {
735
+ min: number;
736
+ max: number;
737
+ }>;
738
+ sku: Record<string, {
739
+ min: number;
740
+ max: number;
741
+ }>;
742
+ };
743
+ }) => {
744
+ min: number;
745
+ max: number;
746
+ };
747
+
748
+ /**
749
+ * 更新购物车中各个 item 的折后价相关的属性
750
+ */
751
+ declare const useUpdateLineCodeAmountAttributes: ({ cart, mutateCart, isCartLoading, setLoadingState, metafieldIdentifiers, }: {
752
+ cart?: NormalizedCart;
753
+ mutateCart: (cart: NormalizedCart | undefined) => void;
754
+ isCartLoading: boolean;
755
+ setLoadingState: React.Dispatch<React.SetStateAction<any>>;
756
+ metafieldIdentifiers?: {
757
+ variant: HasMetafieldsIdentifier[];
758
+ product: HasMetafieldsIdentifier[];
759
+ };
760
+ }) => void;
761
+
762
+ declare const currencyCodeMapping: Record<string, string>;
763
+ declare const defaultSWRMutationConfiguration: SWRMutationConfiguration<any, any, any, any, any> & {
764
+ throwOnError?: boolean;
765
+ };
766
+ declare const CUSTOMER_ATTRIBUTE_KEY = "_discounts_function_env";
767
+ declare const CUSTOMER_SCRIPT_GIFT_KEY = "_giveaway_gradient_gifts";
768
+ declare const CODE_AMOUNT_KEY = "_sku_code_money";
769
+ declare const SCRIPT_CODE_AMOUNT_KEY = "_code_money";
770
+ declare const MEMBER_PRICE_ATTRIBUTE_KEY = "_member_price";
771
+ declare const MAIN_PRODUCT_CODE: string[];
772
+
773
+ /**
774
+ * Normalize AddToCartLineItem[] to NormalizedLineItem[] format
775
+ * This is used to calculate gifts from lines before they are added to cart
776
+ */
777
+ declare function normalizeAddToCartLines(lines: AddToCartLineItem[]): NormalizedLineItem[];
778
+ /**
779
+ * Create a mock cart structure from AddToCartLineItem[]
780
+ * This is useful for calculating gifts before actual cart operations
781
+ */
782
+ declare function createMockCartFromLines(lines: AddToCartLineItem[], existingCart?: any): any;
783
+
784
+ declare const getQuery: () => Record<string, string>;
785
+
786
+ declare const getMatchedMainProductSubTotal: (cartData: any, variant_list: AutoFreeGiftMainProduct["variant_id_list"], main_product: AutoFreeGiftMainProduct) => any;
787
+ declare const safeParse: (str: string) => any;
788
+ declare const getDiscountEnvAttributeValue: (attributes?: {
789
+ key: string;
790
+ value: string;
791
+ }[]) => any;
792
+ declare function preCheck(rule_conditions: RuleCondition[], userTags: string[], currentDealsTypes: string[]): boolean;
793
+ declare const formatScriptAutoFreeGift: ({ scriptAutoFreeGiftResult, gradient_gifts, locale, }: {
794
+ scriptAutoFreeGiftResult: UseScriptAutoFreeGiftResult;
795
+ gradient_gifts: any;
796
+ locale: string;
797
+ }) => any[];
798
+ declare const formatFunctionAutoFreeGift: ({ qualifyingGift, giftProductsResult, locale, }: {
799
+ locale: string;
800
+ qualifyingGift?: FormattedGift | null;
801
+ giftProductsResult?: NormalizedProduct[] | [];
802
+ }) => any[];
803
+
804
+ interface UseProductOptions extends SWRConfiguration<NormalizedProduct | undefined> {
805
+ handle?: string;
806
+ metafieldIdentifiers?: Array<{
807
+ namespace: string;
808
+ key: string;
809
+ }>;
810
+ }
811
+ /**
812
+ * Hook to fetch a single product by handle
813
+ *
814
+ * @param options - Hook options including handle and SWR configuration
815
+ * @returns SWR response with product data
816
+ *
817
+ * @example
818
+ * ```typescript
819
+ * function ProductPage() {
820
+ * const { data: product, error, isLoading } = useProduct({
821
+ * handle: 'my-product'
822
+ * })
823
+ *
824
+ * if (isLoading) return <div>Loading...</div>
825
+ * if (error) return <div>Error loading product</div>
826
+ * if (!product) return <div>Product not found</div>
827
+ *
828
+ * return (
829
+ * <div>
830
+ * <h1>{product.title}</h1>
831
+ * <p>{product.description}</p>
832
+ * <p>${product.price.amount}</p>
833
+ * </div>
834
+ * )
835
+ * }
836
+ * ```
837
+ */
838
+ declare function useProduct(options?: UseProductOptions): swr.SWRResponse<NormalizedProduct | undefined, any, SWRConfiguration<NormalizedProduct | undefined, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct | undefined>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct | undefined>)> | undefined>;
839
+
840
+ interface UseAllProductsOptions extends SWRConfiguration<NormalizedProduct[]> {
841
+ first?: number;
842
+ query?: string;
843
+ sortKey?: 'TITLE' | 'PRODUCT_TYPE' | 'VENDOR' | 'UPDATED_AT' | 'CREATED_AT' | 'BEST_SELLING' | 'PRICE' | 'RELEVANCE';
844
+ reverse?: boolean;
845
+ metafieldIdentifiers?: Array<{
846
+ namespace: string;
847
+ key: string;
848
+ }>;
849
+ }
850
+ /**
851
+ * Hook to fetch all products
852
+ *
853
+ * This hook automatically handles pagination and fetches all products.
854
+ * Use with caution on stores with many products.
855
+ *
856
+ * @param options - Hook options including query parameters and SWR configuration
857
+ * @returns SWR response with products array
858
+ *
859
+ * @example
860
+ * ```typescript
861
+ * function ProductList() {
862
+ * const { data: products, error, isLoading } = useAllProducts({
863
+ * sortKey: 'TITLE',
864
+ * reverse: false
865
+ * })
866
+ *
867
+ * if (isLoading) return <div>Loading...</div>
868
+ * if (error) return <div>Error loading products</div>
869
+ *
870
+ * return (
871
+ * <div>
872
+ * {products?.map(product => (
873
+ * <div key={product.id}>
874
+ * <h2>{product.title}</h2>
875
+ * <p>${product.price.amount}</p>
876
+ * </div>
877
+ * ))}
878
+ * </div>
879
+ * )
880
+ * }
881
+ * ```
882
+ */
883
+ declare function useAllProducts(options?: UseAllProductsOptions): swr.SWRResponse<NormalizedProduct[], any, SWRConfiguration<NormalizedProduct[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>)> | undefined>;
884
+
885
+ interface UseProductsByHandlesOptions extends SWRConfiguration<NormalizedProduct[]> {
886
+ handles?: string[];
887
+ metafieldIdentifiers?: {
888
+ product: HasMetafieldsIdentifier[];
889
+ variant: HasMetafieldsIdentifier[];
890
+ };
891
+ }
892
+ /**
893
+ * Hook to fetch multiple products by their handles
894
+ *
895
+ * @param options - Hook options including handles array and SWR configuration
896
+ * @returns SWR response with products array
897
+ *
898
+ * @example
899
+ * ```typescript
900
+ * function FeaturedProducts() {
901
+ * const { data: products, error, isLoading } = useProductsByHandles({
902
+ * handles: ['product-1', 'product-2', 'product-3']
903
+ * })
904
+ *
905
+ * if (isLoading) return <div>Loading...</div>
906
+ * if (error) return <div>Error loading products</div>
907
+ *
908
+ * return (
909
+ * <div>
910
+ * {products?.map(product => (
911
+ * <div key={product.id}>
912
+ * <h2>{product.title}</h2>
913
+ * <p>${product.price.amount}</p>
914
+ * </div>
915
+ * ))}
916
+ * </div>
917
+ * )
918
+ * }
919
+ * ```
920
+ */
921
+ declare function useProductsByHandles(options?: UseProductsByHandlesOptions): swr.SWRResponse<NormalizedProduct[], any, SWRConfiguration<NormalizedProduct[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedProduct[]>)> | undefined>;
922
+
923
+ /**
924
+ * useVariant Hook
925
+ *
926
+ * Client-side hook to get the selected variant based on selected options
927
+ */
928
+
929
+ type Options = Record<string, string>;
930
+ /**
931
+ * Hook to manage variant selection based on selected options
932
+ *
933
+ * @param product - The product object
934
+ * @param selectedOptions - Currently selected options { Color: 'Red', Size: 'M' }
935
+ * @returns The matching variant
936
+ *
937
+ * @example
938
+ * ```typescript
939
+ * function ProductDetail() {
940
+ * const { data: product } = useProduct({ handle: 'my-product' })
941
+ * const [selectedOptions, setSelectedOptions] = useState({ Color: 'Red', Size: 'M' })
942
+ * const variant = useVariant({ product, selectedOptions })
943
+ *
944
+ * return (
945
+ * <div>
946
+ * <h1>{product.title}</h1>
947
+ * <p>Selected: {variant.title}</p>
948
+ * <p>Price: ${variant.price.amount}</p>
949
+ * <p>Available: {variant.availableForSale ? 'Yes' : 'No'}</p>
950
+ * </div>
951
+ * )
952
+ * }
953
+ * ```
954
+ */
955
+ declare function useVariant({ product, selectedOptions, }: {
956
+ product?: NormalizedProduct;
957
+ selectedOptions: Options;
958
+ }): NormalizedProductVariant | undefined;
959
+
960
+ /**
961
+ * usePrice Hook
962
+ *
963
+ * Client-side hook to format price for display
964
+ */
965
+ interface UsePriceOptions {
966
+ amount: number;
967
+ baseAmount?: number;
968
+ currencyCode: string;
969
+ soldOutDescription?: string;
970
+ maximumFractionDigits?: number;
971
+ minimumFractionDigits?: number;
972
+ removeTrailingZeros?: boolean;
973
+ }
974
+ interface UsePriceResult {
975
+ price: string;
976
+ basePrice?: string;
977
+ free: boolean;
978
+ }
979
+ /**
980
+ * Hook to format price for display
981
+ *
982
+ * @param options - Price formatting options
983
+ * @returns Formatted price object
984
+ *
985
+ * @example
986
+ * ```typescript
987
+ * function ProductPrice({ variant }) {
988
+ * const { price, basePrice, free } = usePrice({
989
+ * amount: variant.price.amount,
990
+ * baseAmount: variant.compareAtPrice?.amount,
991
+ * currencyCode: variant.price.currencyCode
992
+ * })
993
+ *
994
+ * return (
995
+ * <div>
996
+ * {free ? (
997
+ * <span>Free</span>
998
+ * ) : (
999
+ * <>
1000
+ * <span className="price">{price}</span>
1001
+ * {basePrice && <span className="original">{basePrice}</span>}
1002
+ * </>
1003
+ * )}
1004
+ * </div>
1005
+ * )
1006
+ * }
1007
+ * ```
1008
+ */
1009
+ declare function usePrice({ amount, baseAmount, currencyCode, soldOutDescription, maximumFractionDigits, minimumFractionDigits, removeTrailingZeros, }: UsePriceOptions): UsePriceResult;
1010
+
1011
+ /**
1012
+ * useSelectedOptions Hook
1013
+ *
1014
+ * Client-side hook to manage selected product options
1015
+ */
1016
+
1017
+ type SelectedOptionsResult = [Options, Dispatch<SetStateAction<Options>>];
1018
+ /**
1019
+ * Hook to manage selected product options based on URL query or SKU
1020
+ *
1021
+ * @param product - The product object
1022
+ * @param sku - Optional SKU to match variant
1023
+ * @returns Tuple of [options, setOptions]
1024
+ *
1025
+ * @example
1026
+ * ```typescript
1027
+ * function ProductDetail() {
1028
+ * const { data: product } = useProduct({ handle: 'my-product' })
1029
+ * const [selectedOptions, setSelectedOptions] = useSelectedOptions(product)
1030
+ * const variant = useVariant({ product, selectedOptions })
1031
+ *
1032
+ * const handleOptionChange = (name: string, value: string) => {
1033
+ * setSelectedOptions(prev => ({ ...prev, [name]: value }))
1034
+ * }
1035
+ *
1036
+ * return (
1037
+ * <div>
1038
+ * {product?.options.map(option => (
1039
+ * <select
1040
+ * key={option.id}
1041
+ * value={selectedOptions[option.name] || ''}
1042
+ * onChange={(e) => handleOptionChange(option.name, e.target.value)}
1043
+ * >
1044
+ * {option.values.map(value => (
1045
+ * <option key={value.label} value={value.label}>
1046
+ * {value.label}
1047
+ * </option>
1048
+ * ))}
1049
+ * </select>
1050
+ * ))}
1051
+ * <p>Selected: {variant?.title}</p>
1052
+ * </div>
1053
+ * )
1054
+ * }
1055
+ * ```
1056
+ */
1057
+ declare function useSelectedOptions(product?: NormalizedProduct, sku?: string): SelectedOptionsResult;
1058
+
1059
+ /**
1060
+ * useProductUrl Hook
1061
+ *
1062
+ * Hook to generate product URLs with variant query params
1063
+ * Requires routerAdapter to be configured in ShopifyProvider
1064
+ */
1065
+
1066
+ /**
1067
+ * Hook to generate product URLs
1068
+ *
1069
+ * @param otherQuery - Additional query parameters to include
1070
+ * @returns Function to generate product URL
1071
+ *
1072
+ * @example
1073
+ * ```typescript
1074
+ * function ProductCard({ product, variant }) {
1075
+ * const getProductUrl = useProductUrl()
1076
+ *
1077
+ * const url = getProductUrl({ product, variant })
1078
+ *
1079
+ * return (
1080
+ * <a href={url}>
1081
+ * <h2>{product.title}</h2>
1082
+ * <p>{variant.title}</p>
1083
+ * </a>
1084
+ * )
1085
+ * }
1086
+ * ```
1087
+ *
1088
+ * @example With additional query params
1089
+ * ```typescript
1090
+ * function ProductCard({ product, variant }) {
1091
+ * const getProductUrl = useProductUrl({ utm_source: 'email' })
1092
+ *
1093
+ * const url = getProductUrl({ product, variant })
1094
+ * // URL will include: ?variant=123&utm_source=email
1095
+ *
1096
+ * return <a href={url}>{product.title}</a>
1097
+ * }
1098
+ * ```
1099
+ */
1100
+ declare function useProductUrl(otherQuery?: Record<string, string>): ({ product, variant }: {
1101
+ product?: NormalizedProduct;
1102
+ variant?: NormalizedProductVariant;
1103
+ }) => string;
1104
+
1105
+ /**
1106
+ * useUpdateVariantQuery Hook
1107
+ *
1108
+ * Hook to automatically update URL query string when variant changes
1109
+ */
1110
+
1111
+ /**
1112
+ * Hook to update URL query string when variant changes
1113
+ *
1114
+ * This hook automatically updates the browser URL with the selected variant ID
1115
+ * without causing a page reload. Useful for shareable URLs and browser history.
1116
+ *
1117
+ * @param variant - The selected variant
1118
+ *
1119
+ * @example
1120
+ * ```typescript
1121
+ * function ProductDetail() {
1122
+ * const { data: product } = useProduct({ handle: 'my-product' })
1123
+ * const [selectedOptions, setSelectedOptions] = useSelectedOptions(product)
1124
+ * const variant = useVariant({ product, selectedOptions })
1125
+ *
1126
+ * // Automatically updates URL when variant changes
1127
+ * useUpdateVariantQuery(variant)
1128
+ *
1129
+ * return (
1130
+ * <div>
1131
+ * <h1>{product?.title}</h1>
1132
+ * <p>Current variant: {variant?.title}</p>
1133
+ * {/* URL will be: /products/my-product?variant=123456 *\/}
1134
+ * </div>
1135
+ * )
1136
+ * }
1137
+ * ```
1138
+ */
1139
+ declare function useUpdateVariantQuery(variant?: NormalizedProductVariant): void;
1140
+
1141
+ /**
1142
+ * useVariantMedia Hook
1143
+ *
1144
+ * Hook to get media (images and videos) for the selected variant
1145
+ */
1146
+
1147
+ type ImageMedia = Media & {
1148
+ mediaContentType: 'IMAGE';
1149
+ };
1150
+ type VideoMedia = Media & {
1151
+ mediaContentType: 'VIDEO' | 'EXTERNAL_VIDEO';
1152
+ };
1153
+ interface VariantMedia {
1154
+ productList: ImageMedia[];
1155
+ sceneList: ImageMedia[];
1156
+ videoList: VideoMedia[];
1157
+ }
1158
+ /**
1159
+ * Hook to get media for the selected variant
1160
+ *
1161
+ * @param product - The product object
1162
+ * @param variant - The selected variant
1163
+ * @returns Object with productList (first image), sceneList (other images), videoList
1164
+ *
1165
+ * @example
1166
+ * ```typescript
1167
+ * function ProductGallery() {
1168
+ * const { data: product } = useProduct({ handle: 'my-product' })
1169
+ * const [selectedOptions, setSelectedOptions] = useSelectedOptions(product)
1170
+ * const variant = useVariant({ product, selectedOptions })
1171
+ * const { productList, sceneList, videoList } = useVariantMedia({ product, variant })
1172
+ *
1173
+ * return (
1174
+ * <div>
1175
+ * {/* Main product image *\/}
1176
+ * {productList.map(media => (
1177
+ * <img key={media.id} src={media.image?.url} alt={media.alt} />
1178
+ * ))}
1179
+ *
1180
+ * {/* Scene/detail images *\/}
1181
+ * {sceneList.map(media => (
1182
+ * <img key={media.id} src={media.image?.url} alt={media.alt} />
1183
+ * ))}
1184
+ *
1185
+ * {/* Videos *\/}
1186
+ * {videoList.map(media => (
1187
+ * <video key={media.id} src={media.sources?.[0]?.url} controls />
1188
+ * ))}
1189
+ * </div>
1190
+ * )
1191
+ * }
1192
+ * ```
1193
+ */
1194
+ declare function useVariantMedia({ product, variant, }: {
1195
+ product?: NormalizedProduct;
1196
+ variant?: NormalizedProductVariant;
1197
+ }): VariantMedia;
1198
+
1199
+ interface UseCollectionOptions extends SWRConfiguration<NormalizedCollection | undefined> {
1200
+ handle?: string;
1201
+ metafieldIdentifiers?: Array<{
1202
+ namespace: string;
1203
+ key: string;
1204
+ }>;
1205
+ }
1206
+ declare function useCollection(options?: UseCollectionOptions): swr.SWRResponse<NormalizedCollection | undefined, any, SWRConfiguration<NormalizedCollection | undefined, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedCollection | undefined>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedCollection | undefined>)> | undefined>;
1207
+
1208
+ interface UseAllCollectionsOptions extends SWRConfiguration<NormalizedCollection[]> {
1209
+ first?: number;
1210
+ query?: string;
1211
+ sortKey?: 'TITLE' | 'UPDATED_AT' | 'ID' | 'RELEVANCE';
1212
+ reverse?: boolean;
1213
+ metafieldIdentifiers?: Array<{
1214
+ namespace: string;
1215
+ key: string;
1216
+ }>;
1217
+ }
1218
+ declare function useAllCollections(options?: UseAllCollectionsOptions): swr.SWRResponse<NormalizedCollection[], any, SWRConfiguration<NormalizedCollection[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedCollection[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedCollection[]>)> | undefined>;
1219
+
1220
+ interface UseCollectionsOptions extends SWRConfiguration<CollectionsConnection> {
1221
+ first?: number;
1222
+ after?: string;
1223
+ query?: string;
1224
+ sortKey?: 'TITLE' | 'UPDATED_AT' | 'ID' | 'RELEVANCE';
1225
+ reverse?: boolean;
1226
+ metafieldIdentifiers?: Array<{
1227
+ namespace: string;
1228
+ key: string;
1229
+ }>;
1230
+ }
1231
+ declare function useCollections(options?: UseCollectionsOptions): swr.SWRResponse<CollectionsConnection, any, SWRConfiguration<CollectionsConnection, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<CollectionsConnection>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<CollectionsConnection>)> | undefined>;
1232
+
1233
+ interface UseBlogOptions extends SWRConfiguration<NormalizedBlog | undefined> {
1234
+ handle?: string;
1235
+ metafieldIdentifiers?: Array<{
1236
+ namespace: string;
1237
+ key: string;
1238
+ }>;
1239
+ }
1240
+ declare function useBlog(options?: UseBlogOptions): swr.SWRResponse<NormalizedBlog | undefined, any, SWRConfiguration<NormalizedBlog | undefined, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedBlog | undefined>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedBlog | undefined>)> | undefined>;
1241
+
1242
+ interface UseAllBlogsOptions extends SWRConfiguration<NormalizedBlog[]> {
1243
+ first?: number;
1244
+ query?: string;
1245
+ metafieldIdentifiers?: Array<{
1246
+ namespace: string;
1247
+ key: string;
1248
+ }>;
1249
+ }
1250
+ declare function useAllBlogs(options?: UseAllBlogsOptions): swr.SWRResponse<NormalizedBlog[], any, SWRConfiguration<NormalizedBlog[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedBlog[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedBlog[]>)> | undefined>;
1251
+
1252
+ interface UseArticleOptions extends SWRConfiguration<NormalizedArticle | undefined> {
1253
+ blogHandle?: string;
1254
+ articleHandle?: string;
1255
+ metafieldIdentifiers?: Array<{
1256
+ namespace: string;
1257
+ key: string;
1258
+ }>;
1259
+ }
1260
+ declare function useArticle(options?: UseArticleOptions): swr.SWRResponse<NormalizedArticle | undefined, any, SWRConfiguration<NormalizedArticle | undefined, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedArticle | undefined>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedArticle | undefined>)> | undefined>;
1261
+
1262
+ interface UseArticlesOptions extends SWRConfiguration<NormalizedArticle[]> {
1263
+ first?: number;
1264
+ query?: string;
1265
+ sortKey?: 'PUBLISHED_AT' | 'UPDATED_AT' | 'TITLE' | 'ID' | 'RELEVANCE';
1266
+ reverse?: boolean;
1267
+ metafieldIdentifiers?: Array<{
1268
+ namespace: string;
1269
+ key: string;
1270
+ }>;
1271
+ }
1272
+ declare function useArticles(options?: UseArticlesOptions): swr.SWRResponse<NormalizedArticle[], any, SWRConfiguration<NormalizedArticle[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedArticle[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedArticle[]>)> | undefined>;
1273
+
1274
+ interface UseArticlesInBlogOptions extends SWRConfiguration<NormalizedArticle[]> {
1275
+ blogHandle?: string;
1276
+ first?: number;
1277
+ sortKey?: 'PUBLISHED_AT' | 'UPDATED_AT' | 'TITLE' | 'ID' | 'RELEVANCE';
1278
+ reverse?: boolean;
1279
+ metafieldIdentifiers?: Array<{
1280
+ namespace: string;
1281
+ key: string;
1282
+ }>;
1283
+ }
1284
+ declare function useArticlesInBlog(options?: UseArticlesInBlogOptions): swr.SWRResponse<NormalizedArticle[], any, SWRConfiguration<NormalizedArticle[], any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedArticle[]>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<NormalizedArticle[]>)> | undefined>;
1285
+
1286
+ type SearchResultType = 'ARTICLE' | 'PAGE' | 'PRODUCT';
1287
+ interface NormalizedSearchResultItem {
1288
+ type: SearchResultType;
1289
+ id?: string;
1290
+ handle?: string;
1291
+ title?: string;
1292
+ description?: string;
1293
+ url?: string;
1294
+ image?: {
1295
+ url: string;
1296
+ altText?: string;
1297
+ };
1298
+ }
1299
+ interface SearchResult {
1300
+ items: NormalizedSearchResultItem[];
1301
+ totalCount: number;
1302
+ pageInfo?: {
1303
+ hasNextPage: boolean;
1304
+ endCursor?: string;
1305
+ };
1306
+ }
1307
+ interface UseSearchOptions extends SWRConfiguration<SearchResult | undefined> {
1308
+ query?: string;
1309
+ first?: number;
1310
+ types?: SearchResultType[];
1311
+ productFilters?: any[];
1312
+ }
1313
+ declare function useSearch(options?: UseSearchOptions): swr.SWRResponse<SearchResult | undefined, any, SWRConfiguration<SearchResult | undefined, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<SearchResult | undefined>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<SearchResult | undefined>)> | undefined>;
1314
+
1315
+ interface SiteInfo {
1316
+ name: string;
1317
+ description?: string;
1318
+ primaryDomain: {
1319
+ url: string;
1320
+ host: string;
1321
+ };
1322
+ brand?: {
1323
+ logo?: {
1324
+ image?: {
1325
+ url: string;
1326
+ };
1327
+ };
1328
+ colors?: {
1329
+ primary?: string;
1330
+ secondary?: string;
1331
+ };
1332
+ };
1333
+ metafields?: Record<string, any>;
1334
+ }
1335
+ interface UseSiteOptions extends SWRConfiguration<SiteInfo | undefined> {
1336
+ metafieldIdentifiers?: Array<{
1337
+ namespace: string;
1338
+ key: string;
1339
+ }>;
1340
+ }
1341
+ declare function useSite(options?: UseSiteOptions): swr.SWRResponse<SiteInfo | undefined, any, SWRConfiguration<SiteInfo | undefined, any, ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<SiteInfo | undefined>) | ((arg: readonly [any, ...unknown[]]) => swr__internal.FetcherResponse<SiteInfo | undefined>)> | undefined>;
1342
+
1343
+ interface ShippingMethodsContext {
1344
+ freeShippingMethods: PlusMemberShippingMethodConfig[];
1345
+ paymentShippingMethods: PlusMemberShippingMethodConfig[];
1346
+ nddOverweight: boolean;
1347
+ tddOverweight: boolean;
1348
+ nddCoupon?: string;
1349
+ tddCoupon?: string;
1350
+ isLoadingCoupon: boolean;
1351
+ }
1352
+ interface PlusMemberContextValue<TProduct = any, TVariant = any, TProfile extends {
1353
+ isPlus?: boolean;
1354
+ } = any> {
1355
+ plusMemberMetafields: PlusMemberSettingsMetafields;
1356
+ selectedPlusMemberMode: DeliveryPlusType;
1357
+ setSelectedPlusMemberMode: (value: DeliveryPlusType) => void;
1358
+ selectedShippingMethod?: PlusMemberShippingMethodConfig;
1359
+ setSelectedShippingMethod: (value: PlusMemberShippingMethodConfig) => void;
1360
+ showMoreShippingMethod: boolean;
1361
+ setShowMoreShippingMethod: (value: boolean) => void;
1362
+ variant: TVariant;
1363
+ product: TProduct;
1364
+ shippingMethodsContext: ShippingMethodsContext;
1365
+ selectedPlusMemberVariant: SelectedPlusMemberVariant;
1366
+ showPlusMemberBenefit: boolean;
1367
+ setShowPlusMemberBenefit: (value: boolean) => void;
1368
+ profile?: TProfile;
1369
+ }
1370
+ declare const PlusMemberContext: React$1.Context<PlusMemberContextValue<any, any, any>>;
1371
+
1372
+ /**
1373
+ * Hook to access Plus Member Context
1374
+ */
1375
+ declare function usePlusMemberContext<TProfile extends {
1376
+ isPlus?: boolean;
1377
+ } = any>(): PlusMemberContextValue<any, any, any>;
1378
+
1379
+ /**
1380
+ * Hook to get Plus Member Product Variants (Monthly and Annual)
1381
+ */
1382
+
1383
+ interface UsePlusMemberVariantsOptions {
1384
+ /** Plus member metafields configuration */
1385
+ memberSetting: PlusMemberSettingsMetafields;
1386
+ }
1387
+ interface UsePlusMemberVariantsResult {
1388
+ monthlyVariant?: NormalizedProductVariant & {
1389
+ product: NormalizedProduct | undefined;
1390
+ };
1391
+ annualVariant?: NormalizedProductVariant & {
1392
+ product: NormalizedProduct | undefined;
1393
+ };
1394
+ }
1395
+ /**
1396
+ * Get Plus Member product variants (monthly and annual)
1397
+ *
1398
+ * @param options - Configuration options
1399
+ * @returns Monthly and annual variants
1400
+ *
1401
+ * @example
1402
+ * ```tsx
1403
+ * const { monthlyVariant, annualVariant } = usePlusMemberVariants({
1404
+ * plusMemberMetafields
1405
+ * })
1406
+ * ```
1407
+ */
1408
+ declare function usePlusMemberVariants({ memberSetting, }: UsePlusMemberVariantsOptions): UsePlusMemberVariantsResult;
1409
+
1410
+ /**
1411
+ * Hook to calculate available shipping methods based on product weight and member status
1412
+ */
1413
+
1414
+ interface UseShippingMethodsOptions<TVariant = any, TProfile extends {
1415
+ isPlus?: boolean;
1416
+ } = any> {
1417
+ /** Product variant with weight information */
1418
+ variant: TVariant;
1419
+ /** Plus member metafields configuration */
1420
+ plusMemberMetafields: PlusMemberSettingsMetafields;
1421
+ /** Selected plus member mode */
1422
+ selectedPlusMemberMode: DeliveryPlusType;
1423
+ profile?: TProfile;
1424
+ }
1425
+ interface UseShippingMethodsResult {
1426
+ freeShippingMethods: PlusMemberShippingMethodConfig[];
1427
+ paymentShippingMethods: PlusMemberShippingMethodConfig[];
1428
+ nddOverweight: boolean;
1429
+ tddOverweight: boolean;
1430
+ nddCoupon?: string;
1431
+ tddCoupon?: string;
1432
+ isLoadingCoupon: boolean;
1433
+ }
1434
+ /**
1435
+ * Calculate available shipping methods based on product weight, member status, and available coupons
1436
+ *
1437
+ * @param options - Configuration options
1438
+ * @returns Shipping methods categorized by free/payment and overweight status
1439
+ *
1440
+ * @example
1441
+ * ```tsx
1442
+ * const { freeShippingMethods, paymentShippingMethods, nddOverweight, tddOverweight } = useShippingMethods({
1443
+ * variant,
1444
+ * plusMemberMetafields,
1445
+ * selectedPlusMemberMode,
1446
+ * })
1447
+ * ```
1448
+ */
1449
+ declare function useShippingMethods<TVariant extends {
1450
+ weight?: number;
1451
+ } = any>(options: UseShippingMethodsOptions<TVariant>): UseShippingMethodsResult;
1452
+
1453
+ /**
1454
+ * Hook to replace cart plus member product
1455
+ *
1456
+ * When adding a monthly membership while an annual membership exists in cart,
1457
+ * the annual membership will be replaced and vice versa.
1458
+ *
1459
+ * @returns Handler function to replace conflicting membership products
1460
+ *
1461
+ * @example
1462
+ * ```tsx
1463
+ * const replaceCartPlusMember = useReplaceCartPlusMember()
1464
+ *
1465
+ * // Call before adding new membership product
1466
+ * await replaceCartPlusMember()
1467
+ * ```
1468
+ */
1469
+ declare const useReplaceCartPlusMember: () => () => Promise<void>;
1470
+
1471
+ declare const usePlusMemberCheckoutCustomAttributes: ({ disableShipping, isPresaleContains, }: {
1472
+ disableShipping?: boolean;
1473
+ isPresaleContains?: boolean;
1474
+ }) => NormalizedAttribute[];
1475
+
1476
+ /**
1477
+ * useAutoRemovePlusMemberInCart Hook
1478
+ * 付费会员身份自动移除购物车中的会员产品
1479
+ * 年费会员删除月费会员产品,月费会员删除年费会员产品
1480
+ */
1481
+
1482
+ interface UseAutoRemovePlusMemberInCartProps {
1483
+ profile: any;
1484
+ cart?: NormalizedCart;
1485
+ memberSetting: PlusMemberSettingsMetafields;
1486
+ }
1487
+ /**
1488
+ * 自动移除购物车中的会员产品
1489
+ *
1490
+ * @param props - Hook 参数
1491
+ * @param props.memberSetting - Plus Member 配置
1492
+ * @param props.isMonthlyPlus - 用户是否是月费会员
1493
+ * @param props.isAnnualPlus - 用户是否是年费会员
1494
+ *
1495
+ * @example
1496
+ * ```tsx
1497
+ * const { profile } = useProfile()
1498
+ *
1499
+ * useAutoRemovePlusMemberInCart({
1500
+ * cart,
1501
+ * profile,
1502
+ * })
1503
+ * ```
1504
+ */
1505
+ declare function useAutoRemovePlusMemberInCart({ cart, profile, memberSetting, }: UseAutoRemovePlusMemberInCartProps): void;
1506
+
1507
+ /**
1508
+ * Has Plus Member In Cart
1509
+ * 判断购物车中是否包含年费会员或月费会员产品
1510
+ */
1511
+
1512
+ interface HasPlusMemberInCartProps {
1513
+ /** Plus Member 配置 */
1514
+ memberSetting?: PlusMemberSettingsMetafields;
1515
+ /** 购物车数据 */
1516
+ cart?: NormalizedCart;
1517
+ }
1518
+ interface HasPlusMemberInCartResult {
1519
+ /** 购物车中是否有任何会员产品 */
1520
+ hasPlusMember: boolean;
1521
+ /** 购物车中是否有月费会员产品 */
1522
+ hasMonthlyPlus: boolean;
1523
+ /** 购物车中是否有年费会员产品 */
1524
+ hasAnnualPlus: boolean;
1525
+ /** 月费会员产品的 line item */
1526
+ monthlyPlusItem?: {
1527
+ id: string;
1528
+ quantity: number;
1529
+ handle?: string;
1530
+ sku?: string;
1531
+ };
1532
+ /** 年费会员产品的 line item */
1533
+ annualPlusItem?: {
1534
+ id: string;
1535
+ quantity: number;
1536
+ handle?: string;
1537
+ sku?: string;
1538
+ };
1539
+ }
1540
+ /**
1541
+ * 判断购物车中是否包含年费会员或月费会员产品(纯函数版本)
1542
+ *
1543
+ * @param props - 函数参数
1544
+ * @param props.memberSetting - Plus Member 配置
1545
+ * @param props.cart - 购物车数据
1546
+ * @returns 会员产品信息
1547
+ *
1548
+ * @example
1549
+ * ```tsx
1550
+ * const {
1551
+ * hasPlusMember,
1552
+ * hasMonthlyPlus,
1553
+ * hasAnnualPlus,
1554
+ * monthlyPlusItem,
1555
+ * annualPlusItem,
1556
+ * } = hasPlusMemberInCart({
1557
+ * memberSetting: plusMemberSettings,
1558
+ * cart: currentCart,
1559
+ * })
1560
+ *
1561
+ * if (hasPlusMember) {
1562
+ * console.log('购物车中有会员产品')
1563
+ * }
1564
+ * ```
1565
+ */
1566
+ declare function hasPlusMemberInCart({ memberSetting, cart, }: HasPlusMemberInCartProps): HasPlusMemberInCartResult;
1567
+ /**
1568
+ * 判断购物车中是否包含年费会员或月费会员产品(Hook 版本)
1569
+ *
1570
+ * 内部使用 hasPlusMemberInCart 纯函数,并通过 useMemo 优化性能
1571
+ *
1572
+ * @param props - Hook 参数
1573
+ * @param props.memberSetting - Plus Member 配置
1574
+ * @param props.cart - 购物车数据
1575
+ * @returns 会员产品信息
1576
+ *
1577
+ * @example
1578
+ * ```tsx
1579
+ * const {
1580
+ * hasPlusMember,
1581
+ * hasMonthlyPlus,
1582
+ * hasAnnualPlus,
1583
+ * monthlyPlusItem,
1584
+ * annualPlusItem,
1585
+ * } = useHasPlusMemberInCart({
1586
+ * memberSetting: plusMemberSettings,
1587
+ * cart: currentCart,
1588
+ * })
1589
+ *
1590
+ * if (hasPlusMember) {
1591
+ * console.log('购物车中有会员产品')
1592
+ * }
1593
+ * ```
1594
+ */
1595
+ declare function useHasPlusMemberInCart({ memberSetting, cart, }: HasPlusMemberInCartProps): HasPlusMemberInCartResult;
1596
+
1597
+ /**
1598
+ * Hook to check if plus member products are in line items
1599
+ * 判断加购的 line 中是否包含付费会员产品
1600
+ */
1601
+
1602
+ interface UseHasPlusMemberInLinesProps {
1603
+ /** Plus Member 配置 */
1604
+ memberSetting?: PlusMemberSettingsMetafields;
1605
+ /** 加购的 line items */
1606
+ lines: AddToCartLineItem[];
1607
+ }
1608
+ interface HasPlusMemberInLinesResult {
1609
+ /** 加购的 lines 中是否有任何会员产品 */
1610
+ hasPlusMember: boolean;
1611
+ /** 加购的 lines 中是否有月费会员产品 */
1612
+ hasMonthlyPlus: boolean;
1613
+ /** 加购的 lines 中是否有年费会员产品 */
1614
+ hasAnnualPlus: boolean;
1615
+ /** 月费会员产品的 line item */
1616
+ monthlyPlusLine?: AddToCartLineItem;
1617
+ /** 年费会员产品的 line item */
1618
+ annualPlusLine?: AddToCartLineItem;
1619
+ }
1620
+ /**
1621
+ * 判断加购的 line items 中是否包含付费会员产品(纯函数版本)
1622
+ *
1623
+ * @param props - 函数参数
1624
+ * @param props.memberSetting - Plus Member 配置
1625
+ * @param props.lines - 加购的 line items
1626
+ * @returns 会员产品信息
1627
+ *
1628
+ * @example
1629
+ * ```tsx
1630
+ * const {
1631
+ * hasPlusMember,
1632
+ * hasMonthlyPlus,
1633
+ * hasAnnualPlus,
1634
+ * } = hasPlusMemberInLines({
1635
+ * memberSetting: plusMemberSettings,
1636
+ * lines: lineItems,
1637
+ * })
1638
+ *
1639
+ * if (hasPlusMember) {
1640
+ * console.log('加购的商品中包含会员产品')
1641
+ * }
1642
+ * ```
1643
+ */
1644
+ declare function hasPlusMemberInLines({ memberSetting, lines, }: UseHasPlusMemberInLinesProps): HasPlusMemberInLinesResult;
1645
+ /**
1646
+ * 判断加购的 line items 中是否包含付费会员产品(Hook 版本)
1647
+ *
1648
+ * 内部使用 hasPlusMemberInLines 纯函数,并通过 useMemo 优化性能
1649
+ *
1650
+ * @param props - Hook 参数
1651
+ * @param props.memberSetting - Plus Member 配置
1652
+ * @param props.lines - 加购的 line items
1653
+ * @returns 会员产品信息
1654
+ *
1655
+ * @example
1656
+ * ```tsx
1657
+ * const {
1658
+ * hasPlusMember,
1659
+ * hasMonthlyPlus,
1660
+ * hasAnnualPlus,
1661
+ * monthlyPlusLine,
1662
+ * annualPlusLine,
1663
+ * } = useHasPlusMemberInLines({
1664
+ * memberSetting: plusMemberSettings,
1665
+ * lines: lineItems,
1666
+ * })
1667
+ *
1668
+ * if (hasPlusMember) {
1669
+ * console.log('加购的商品中包含会员产品')
1670
+ * }
1671
+ * ```
1672
+ */
1673
+ declare function useHasPlusMemberInLines({ memberSetting, lines, }: UseHasPlusMemberInLinesProps): HasPlusMemberInLinesResult;
1674
+
1675
+ /**
1676
+ * 返回需要添加到购物车的 Plus Member 产品
1677
+ *
1678
+ * 该 hook 会根据用户选择的会员模式和购物车现有状态,
1679
+ * 返回需要添加的会员产品。如果不需要添加会员产品,则返回 undefined。
1680
+ *
1681
+ * @param props - Hook 参数
1682
+ * @param props.cart - 购物车数据
1683
+ * @returns Plus Member 产品对象或 undefined
1684
+ *
1685
+ * @example
1686
+ * ```tsx
1687
+ * const plusMemberVariant = usePlusMemberNeedAddToCart({
1688
+ * cart,
1689
+ * })
1690
+ *
1691
+ * ```
1692
+ */
1693
+ declare function usePlusMemberNeedAddToCart({ cart, profile, }: {
1694
+ cart: NormalizedCart;
1695
+ profile?: any;
1696
+ }): (_anker_in_shopify_sdk.NormalizedProductVariant & {
1697
+ product: _anker_in_shopify_sdk.NormalizedProduct | undefined;
1698
+ }) | undefined;
1699
+
1700
+ interface UseAvailableDeliveryCouponResult {
1701
+ nddCoupon?: string;
1702
+ tddCoupon?: string;
1703
+ isLoading: boolean;
1704
+ }
1705
+ declare const useAvailableDeliveryCoupon: ({ profile, }: {
1706
+ profile?: any;
1707
+ }) => UseAvailableDeliveryCouponResult;
1708
+
1709
+ interface PlusMemberProviderProps<TProduct = any, TVariant = any, TProfile extends {
1710
+ isPlus?: boolean;
1711
+ } = any> {
1712
+ variant: TVariant;
1713
+ product: TProduct;
1714
+ memberSetting: PlusMemberSettingsMetafields;
1715
+ initialSelectedPlusMemberMode?: DeliveryPlusType;
1716
+ profile?: TProfile;
1717
+ }
1718
+ /**
1719
+ * Plus Member Provider Component
1720
+ *
1721
+ * Provides Plus Member context and state management to child components.
1722
+ *
1723
+ * @param variant - Product variant
1724
+ * @param product - Product
1725
+ * @param metafields - Plus member settings from metafields
1726
+ * @param initialSelectedPlusMemberMode - Initial selected mode (default: 'free')
1727
+ * @param profile - User profile
1728
+ * @param locale - Locale code
1729
+ * @param children - Child components
1730
+ *
1731
+ * @example
1732
+ * ```tsx
1733
+ * <PlusMemberProvider
1734
+ * variant={variant}
1735
+ * product={product}
1736
+ * memberSetting={memberSetting}
1737
+ * profile={profile}
1738
+ * >
1739
+ * <YourComponent />
1740
+ * </PlusMemberProvider>
1741
+ * ```
1742
+ */
1743
+ declare const PlusMemberProvider: <TProduct = any, TVariant extends {
1744
+ weight?: number;
1745
+ } = any, TProfile extends {
1746
+ isPlus?: boolean;
1747
+ } = any>({ variant, product, memberSetting, initialSelectedPlusMemberMode, profile, children, }: PropsWithChildren<PlusMemberProviderProps<TProduct, TVariant, TProfile>>) => react_jsx_runtime.JSX.Element;
1748
+
1749
+ /**
1750
+ * useIntersection Hook
1751
+ *
1752
+ * Observes element visibility using IntersectionObserver API
1753
+ */
1754
+
1755
+ interface UseIntersectionOptions {
1756
+ /** Callback function when element becomes visible */
1757
+ callback: () => void;
1758
+ /** Only trigger callback once (default: false) */
1759
+ once?: boolean;
1760
+ /** Root element for intersection (default: viewport) */
1761
+ root?: Element | null;
1762
+ /** Margin around root (default: '0px') */
1763
+ rootMargin?: string;
1764
+ /** Visibility threshold 0-1 (default: 0.8) */
1765
+ threshold?: number;
1766
+ }
1767
+ /**
1768
+ * Hook to observe element visibility with IntersectionObserver
1769
+ *
1770
+ * Triggers a callback when the target element becomes visible in the viewport
1771
+ *
1772
+ * @param targetRef - React ref to the target element
1773
+ * @param options - Intersection observer options
1774
+ *
1775
+ * @example
1776
+ * ```typescript
1777
+ * function LazyImage() {
1778
+ * const imageRef = useRef<HTMLImageElement>(null)
1779
+ * const [loaded, setLoaded] = useState(false)
1780
+ *
1781
+ * useIntersection(imageRef, {
1782
+ * callback: () => setLoaded(true),
1783
+ * once: true,
1784
+ * threshold: 0.5
1785
+ * })
1786
+ *
1787
+ * return (
1788
+ * <img
1789
+ * ref={imageRef}
1790
+ * src={loaded ? actualSrc : placeholderSrc}
1791
+ * alt="Lazy loaded"
1792
+ * />
1793
+ * )
1794
+ * }
1795
+ * ```
1796
+ */
1797
+ declare function useIntersection(targetRef: RefObject<Element> | undefined, options: UseIntersectionOptions): void;
1798
+
1799
+ /**
1800
+ * useExposure Hook
1801
+ *
1802
+ * Tracks element exposure (visibility + duration) for analytics/tracking
1803
+ */
1804
+
1805
+ interface UseExposureOptions {
1806
+ /** Visibility threshold 0-1 (default: 0.5, meaning 50% visible) */
1807
+ threshold?: number;
1808
+ /** Duration in milliseconds element must be visible (default: 2000ms) */
1809
+ duration?: number;
1810
+ /** Only trigger callback once (default: true) */
1811
+ once?: boolean;
1812
+ /** Callback when element has been exposed for the required duration */
1813
+ onExposure: () => void;
1814
+ }
1815
+ /**
1816
+ * Hook to track element exposure (visibility + duration threshold)
1817
+ *
1818
+ * Useful for tracking ad impressions, product views, or any analytics
1819
+ * that require an element to be visible for a certain duration
1820
+ *
1821
+ * @param targetRef - React ref to the target element
1822
+ * @param options - Exposure tracking options
1823
+ * @returns Current visibility state
1824
+ *
1825
+ * @example
1826
+ * ```typescript
1827
+ * function ProductCard({ product }) {
1828
+ * const cardRef = useRef<HTMLDivElement>(null)
1829
+ *
1830
+ * const isVisible = useExposure(cardRef, {
1831
+ * threshold: 0.5, // 50% visible
1832
+ * duration: 2000, // 2 seconds
1833
+ * once: true, // Only track once
1834
+ * onExposure: () => {
1835
+ * // Track product impression
1836
+ * analytics.track('Product Viewed', {
1837
+ * productId: product.id,
1838
+ * productName: product.title
1839
+ * })
1840
+ * }
1841
+ * })
1842
+ *
1843
+ * return (
1844
+ * <div ref={cardRef}>
1845
+ * {product.title}
1846
+ * {isVisible && <div className="viewing-indicator" />}
1847
+ * </div>
1848
+ * )
1849
+ * }
1850
+ * ```
1851
+ */
1852
+ declare function useExposure(targetRef: RefObject<Element>, options: UseExposureOptions): boolean;
1853
+
1854
+ /**
1855
+ * useGeoLocation Hook
1856
+ *
1857
+ * Fetches and caches user's geographic location
1858
+ */
1859
+
1860
+ interface GeoLocationData {
1861
+ /** Geographic information */
1862
+ geo: {
1863
+ /** Country information */
1864
+ country?: {
1865
+ /** Country code (e.g., 'US', 'GB') */
1866
+ code?: string;
1867
+ /** Country name */
1868
+ name?: string;
1869
+ };
1870
+ /** Region/state information */
1871
+ region?: {
1872
+ code?: string;
1873
+ name?: string;
1874
+ };
1875
+ /** City name */
1876
+ city?: string;
1877
+ /** Coordinates */
1878
+ latitude?: number;
1879
+ longitude?: number;
1880
+ /** Timezone */
1881
+ timezone?: string;
1882
+ };
1883
+ /** Suggested locale based on location */
1884
+ suggestLocale?: string;
1885
+ }
1886
+ interface LocaleMapping {
1887
+ /** Countries that should map to EU locale */
1888
+ euCountries?: string[];
1889
+ /** Countries that should map to DE locale */
1890
+ deCountries?: string[];
1891
+ /** Countries that should map to AU locale */
1892
+ auCountries?: string[];
1893
+ /** Countries that should map to AE-EN locale */
1894
+ aeEnCountries?: string[];
1895
+ /** Custom country to locale mapping */
1896
+ customMapping?: Record<string, string>;
1897
+ }
1898
+ interface UseGeoLocationOptions extends SWRConfiguration<GeoLocationData | undefined> {
1899
+ /** API endpoint for fetching geo data (default: '/geolocation') */
1900
+ endpoint?: string;
1901
+ /** Cache key for localStorage (default: 'geoLocation') */
1902
+ cacheKey?: string;
1903
+ /** Cache duration in milliseconds (default: 24 hours) */
1904
+ cacheDuration?: number;
1905
+ /** Locale mapping configuration */
1906
+ localeMapping?: LocaleMapping;
1907
+ /** Enable automatic caching (default: true) */
1908
+ enableCache?: boolean;
1909
+ }
1910
+ /**
1911
+ * Hook to fetch and cache user's geographic location
1912
+ *
1913
+ * Fetches geo data from an API endpoint and caches it in localStorage
1914
+ * Automatically determines suggested locale based on country
1915
+ *
1916
+ * @param options - Geo location options
1917
+ * @returns SWR response with geo location data
1918
+ *
1919
+ * @example
1920
+ * ```typescript
1921
+ * function LocaleSwitcher() {
1922
+ * const { data: geoData, error, isLoading } = useGeoLocation({
1923
+ * endpoint: '/api/geolocation',
1924
+ * localeMapping: {
1925
+ * euCountries: ['FR', 'DE', 'IT', 'ES'],
1926
+ * auCountries: ['AU', 'NZ']
1927
+ * }
1928
+ * })
1929
+ *
1930
+ * if (isLoading) return <div>Loading...</div>
1931
+ * if (error) return <div>Error loading location</div>
1932
+ *
1933
+ * return (
1934
+ * <div>
1935
+ * <p>Country: {geoData?.geo.country?.code}</p>
1936
+ * <p>Suggested Locale: {geoData?.suggestLocale}</p>
1937
+ * </div>
1938
+ * )
1939
+ * }
1940
+ * ```
1941
+ *
1942
+ * @example
1943
+ * ```typescript
1944
+ * // With custom locale mapping
1945
+ * const { data } = useGeoLocation({
1946
+ * localeMapping: {
1947
+ * customMapping: {
1948
+ * 'JP': 'ja',
1949
+ * 'CN': 'zh-cn',
1950
+ * 'TW': 'zh-tw'
1951
+ * }
1952
+ * }
1953
+ * })
1954
+ * ```
1955
+ */
1956
+ declare function useGeoLocation(options?: UseGeoLocationOptions): ReturnType<typeof swr__default<GeoLocationData | undefined>>;
1957
+ /**
1958
+ * Get cached geo location data without fetching
1959
+ *
1960
+ * @param cacheKey - Cache key (default: 'geoLocation')
1961
+ * @returns Cached geo data or undefined
1962
+ *
1963
+ * @example
1964
+ * ```typescript
1965
+ * const cachedGeo = getCachedGeoLocation()
1966
+ * if (cachedGeo) {
1967
+ * console.log('Country:', cachedGeo.geo.country?.code)
1968
+ * }
1969
+ * ```
1970
+ */
1971
+ declare function getCachedGeoLocation(cacheKey?: string): GeoLocationData | undefined;
1972
+ /**
1973
+ * Clear cached geo location data
1974
+ *
1975
+ * @param cacheKey - Cache key (default: 'geoLocation')
1976
+ *
1977
+ * @example
1978
+ * ```typescript
1979
+ * clearGeoLocationCache()
1980
+ * ```
1981
+ */
1982
+ declare function clearGeoLocationCache(cacheKey?: string): void;
1983
+
1984
+ 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, type UseScriptAutoFreeGiftResult, type UseSearchOptions, type UseShippingMethodsOptions, type UseShippingMethodsResult, type UseSiteOptions, type UseUpdateCartAttributesOptions, type VariantItem, type VariantMedia, type VideoMedia, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getCartAttributes, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, 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, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethods, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia };