@anker-in/shopify-react 0.1.1-beta.9 → 1.0.0

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