@anker-in/shopify-react 0.1.1-beta.3 → 0.1.1-beta.31

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,1966 +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, 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
- type Attribute = {
738
- key: string;
739
- value: string;
740
- };
741
- type Discount = {
742
- amount: number;
743
- code?: string;
744
- };
745
- type Image = {
746
- url: string;
747
- altText?: string;
748
- width?: number;
749
- height?: number;
750
- };
751
- type Measurement = {
752
- value: number;
753
- unit: string;
754
- };
755
- type ExportSelectedOption = {
756
- id?: string;
757
- name: string;
758
- value: string;
759
- };
760
- type ExportProductVariant = {
761
- id: string;
762
- sku: string;
763
- name: string;
764
- requiresShipping: boolean;
765
- price: number;
766
- listPrice: number;
767
- image?: Image;
768
- isInStock?: boolean;
769
- availableForSale?: boolean;
770
- weight?: number;
771
- height?: Measurement;
772
- width?: Measurement;
773
- depth?: Measurement;
774
- metafields?: any;
775
- quantityAvailable: number;
776
- currentlyNotInStock: boolean;
777
- };
778
- type ExportDiscountAllocations = {
779
- amount: number;
780
- code: string;
781
- };
782
- type ExportLineItem = {
783
- id: string;
784
- variantId: string;
785
- productId: string;
786
- name: string;
787
- quantity: number;
788
- discounts: Discount[];
789
- path: string;
790
- variant: ExportProductVariant;
791
- totalAmount: number;
792
- subtotalAmount: number;
793
- options?: ExportSelectedOption[];
794
- discountAllocations?: ExportDiscountAllocations[];
795
- product?: any;
796
- weight?: number;
797
- customAttributes?: Array<Omit<Attribute, '__typename'>>;
798
- freeGiftVariant?: ExportLineItem;
799
- relatedVariant?: ExportLineItem;
800
- };
801
- type ExportDiscounts = {
802
- applicable: boolean;
803
- code: string;
804
- };
805
- type ExportCart = {
806
- id: string;
807
- customerId?: string;
808
- email?: string;
809
- createdAt: string;
810
- currency: {
811
- code: string;
812
- };
813
- taxesIncluded?: boolean;
814
- lineItems: ExportLineItem[];
815
- totallineItemsDiscount?: number;
816
- orderDiscounts?: number;
817
- lineItemsSubtotalPrice: number;
818
- subtotalPrice: number;
819
- totalPrice: number;
820
- totalTaxAmount: number;
821
- discountCodes: ExportDiscounts[];
822
- discountAllocations?: ExportDiscountAllocations[];
823
- discounts?: Discount[];
824
- url?: string;
825
- ready: boolean;
826
- orderStatusUrl?: any;
827
- customAttributes?: any;
828
- maxNum?: number;
829
- };
830
-
831
- /**
832
- * Hook to generate custom attributes for cart line items
833
- *
834
- * Creates custom attributes based on delivery data to be attached to line items.
835
- *
836
- * @param deliveryData - Delivery data containing custom attributes
837
- * @returns Array of custom attributes for line items
838
- *
839
- * @example
840
- * ```tsx
841
- * const itemAttributes = usePlusMemberItemCustomAttributes({ deliveryData })
842
- *
843
- * // Use in addToCart
844
- * await addToCart({
845
- * lineItems: lineItems.map(item => ({
846
- * ...item,
847
- * customAttributes: [...(item.customAttributes || []), ...itemAttributes]
848
- * }))
849
- * })
850
- * ```
851
- */
852
- declare const usePlusMemberItemCustomAttributes: ({ deliveryData, }: {
853
- deliveryData?: DeliveryData;
854
- }) => Attribute[];
855
-
856
- interface CustomerOrder {
857
- edges?: Array<any>;
858
- }
859
- interface Customer {
860
- orders?: CustomerOrder;
861
- }
862
- /**
863
- * Hook to generate custom attributes for checkout
864
- *
865
- * Creates custom attributes based on delivery data, profile, and customer information
866
- * to be attached to the checkout.
867
- *
868
- * Requires profile to be provided via PlusMemberContext.
869
- *
870
- * @param deliveryData - Delivery data containing custom attributes
871
- * @param product - Product information (optional, for hiding shipping benefits check)
872
- * @param variant - Variant information (optional, for presale and hiding shipping benefits check)
873
- * @param customer - Customer information (optional, for user type determination)
874
- * @param isShowShippingBenefits - Function to check if shipping benefits should be shown (optional)
875
- * @returns Array of custom attributes for checkout
876
- *
877
- * @example
878
- * ```tsx
879
- * const checkoutAttributes = usePlusMemberCheckoutCustomAttributes({
880
- * deliveryData,
881
- * product,
882
- * variant,
883
- * customer,
884
- * isShowShippingBenefits
885
- * })
886
- *
887
- * // Use in checkout
888
- * await createCheckout({
889
- * lineItems,
890
- * customAttributes: checkoutAttributes
891
- * })
892
- * ```
893
- */
894
- declare const usePlusMemberCheckoutCustomAttributes: <TProduct = any, TVariant = any>({ deliveryData, product, variant, customer, isShowShippingBenefits, }: {
895
- deliveryData?: DeliveryData;
896
- product?: TProduct;
897
- variant?: TVariant;
898
- customer?: Customer;
899
- isShowShippingBenefits?: (args: {
900
- variant?: TVariant;
901
- product?: TProduct;
902
- setting: any;
903
- }) => boolean;
904
- }) => Attribute[];
905
-
906
- /**
907
- * useAutoRemovePlusMemberInCart Hook
908
- * 自动移除购物车中的会员产品
909
- * 年费会员删除月费会员产品,月费会员删除年费会员产品
910
- */
911
-
912
- interface UseAutoRemovePlusMemberInCartProps {
913
- /** Plus Member 配置 */
914
- metafields: PlusMemberSettingsMetafields;
915
- /** 用户是否是月费会员 */
916
- isMonthlyPlus?: boolean;
917
- /** 用户是否是年费会员 */
918
- isAnnualPlus?: boolean;
919
- }
920
- /**
921
- * 自动移除购物车中的会员产品
922
- *
923
- * @param props - Hook 参数
924
- * @param props.metafields - Plus Member 配置
925
- * @param props.isMonthlyPlus - 用户是否是月费会员
926
- * @param props.isAnnualPlus - 用户是否是年费会员
927
- *
928
- * @example
929
- * ```tsx
930
- * const { profile } = useProfile()
931
- *
932
- * useAutoRemovePlusMemberInCart({
933
- * metafields: plusMemberSettings,
934
- * isMonthlyPlus: profile?.isMonthlyPlus,
935
- * isAnnualPlus: profile?.isAnnualPlus,
936
- * })
937
- * ```
938
- */
939
- declare function useAutoRemovePlusMemberInCart({ metafields, isMonthlyPlus, isAnnualPlus, }: UseAutoRemovePlusMemberInCartProps): void;
940
-
941
- /**
942
- * useHasPlusMemberInCart Hook
943
- * 判断购物车中是否包含年费会员或月费会员产品
944
- */
945
-
946
- interface UseHasPlusMemberInCartProps {
947
- /** Plus Member 配置 */
948
- memberSetting?: PlusMemberSettingsMetafields;
949
- /** 购物车数据 */
950
- cart?: NormalizedCart;
951
- }
952
- interface HasPlusMemberInCartResult {
953
- /** 购物车中是否有任何会员产品 */
954
- hasPlusMember: boolean;
955
- /** 购物车中是否有月费会员产品 */
956
- hasMonthlyPlus: boolean;
957
- /** 购物车中是否有年费会员产品 */
958
- hasAnnualPlus: boolean;
959
- /** 月费会员产品的 line item */
960
- monthlyPlusItem?: {
961
- id: string;
962
- quantity: number;
963
- handle?: string;
964
- sku?: string;
965
- };
966
- /** 年费会员产品的 line item */
967
- annualPlusItem?: {
968
- id: string;
969
- quantity: number;
970
- handle?: string;
971
- sku?: string;
972
- };
973
- }
974
- /**
975
- * 判断购物车中是否包含年费会员或月费会员产品
976
- *
977
- * @param props - Hook 参数
978
- * @param props.metafields - Plus Member 配置
979
- * @returns 会员产品信息
980
- *
981
- * @example
982
- * ```tsx
983
- * const {
984
- * hasPlusMember,
985
- * hasMonthlyPlus,
986
- * hasAnnualPlus,
987
- * monthlyPlusItem,
988
- * annualPlusItem,
989
- * } = useHasPlusMemberInCart({
990
- * memberSetting: plusMemberSettings,
991
- * })
992
- *
993
- * if (hasPlusMember) {
994
- * console.log('购物车中有会员产品')
995
- * }
996
- * ```
997
- */
998
- declare function useHasPlusMemberInCart({ memberSetting, cart, }: UseHasPlusMemberInCartProps): HasPlusMemberInCartResult;
999
-
1000
- interface UseAddPlusMemberProductsToCartProps {
1001
- /** 购物车数据 */
1002
- cart?: NormalizedCart;
1003
- /** Plus Member 配置 */
1004
- memberSetting?: PlusMemberSettingsMetafields;
1005
- /** 选中的会员模式 */
1006
- selectedPlusMemberMode: DeliveryPlusType;
1007
- /** 选中的会员产品 */
1008
- selectedPlusMemberProduct?: SelectedPlusMemberProduct;
1009
- }
1010
- /**
1011
- * 返回需要添加到购物车的 Plus Member 产品
1012
- *
1013
- * 该 hook 会根据用户选择的会员模式和购物车现有状态,
1014
- * 返回需要添加的会员产品。如果不需要添加会员产品,则返回 undefined。
1015
- *
1016
- * @param props - Hook 参数
1017
- * @param props.cart - 购物车数据
1018
- * @param props.memberSetting - Plus Member 配置
1019
- * @param props.selectedPlusMemberMode - 选中的会员模式
1020
- * @param props.selectedPlusMemberProduct - 选中的会员产品
1021
- * @returns Plus Member 产品对象或 undefined
1022
- *
1023
- * @example
1024
- * ```tsx
1025
- * const plusMemberProduct = useAddPlusMemberProductsToCart({
1026
- * cart,
1027
- * memberSetting,
1028
- * selectedPlusMemberMode: DeliveryPlusType.MONTHLY,
1029
- * selectedPlusMemberProduct: { product, variant },
1030
- * })
1031
- *
1032
- * // plusMemberProduct 格式:
1033
- * // {
1034
- * // product: NormalizedProduct,
1035
- * // variant: NormalizedProductVariant
1036
- * // }
1037
- * // 或 undefined (当不需要添加会员产品时)
1038
- * ```
1039
- */
1040
- declare function useAddPlusMemberProductsToCart({ cart, memberSetting, selectedPlusMemberMode, selectedPlusMemberProduct, }: UseAddPlusMemberProductsToCartProps): {
1041
- product: _anker_in_shopify_sdk.NormalizedProduct;
1042
- variant: _anker_in_shopify_sdk.NormalizedProductVariant;
1043
- } | undefined;
1044
-
1045
- interface PlusMemberProviderProps<TProduct = any, TVariant = any, TProfile = any> {
1046
- variant: TVariant;
1047
- product: TProduct;
1048
- memberSetting: PlusMemberSettingsMetafields;
1049
- initialSelectedPlusMemberMode?: DeliveryPlusType;
1050
- profile?: TProfile;
1051
- locale?: string;
1052
- }
1053
- /**
1054
- * Plus Member Provider Component
1055
- *
1056
- * Provides Plus Member context and state management to child components.
1057
- *
1058
- * @param variant - Product variant
1059
- * @param product - Product
1060
- * @param metafields - Plus member settings from metafields
1061
- * @param initialSelectedPlusMemberMode - Initial selected mode (default: 'free')
1062
- * @param profile - User profile
1063
- * @param locale - Locale code
1064
- * @param children - Child components
1065
- *
1066
- * @example
1067
- * ```tsx
1068
- * <PlusMemberProvider
1069
- * variant={variant}
1070
- * product={product}
1071
- * memberSetting={memberSetting}
1072
- * profile={profile}
1073
- * locale={locale}
1074
- * >
1075
- * <YourComponent />
1076
- * </PlusMemberProvider>
1077
- * ```
1078
- */
1079
- 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;
1080
-
1081
- declare const getReferralAttributes: () => {
1082
- key: string;
1083
- value: string;
1084
- }[];
1085
- declare const useCartAttributes: ({ profile, customer, cart, memberSetting, }: {
1086
- profile: any;
1087
- customer: any;
1088
- cart?: NormalizedCart;
1089
- memberSetting?: PlusMemberSettingsMetafields;
1090
- }) => {
1091
- attributes: Array<{
1092
- key: string;
1093
- value: any;
1094
- }>;
1095
- };
1096
-
1097
- declare const useCartItemQuantityLimit: ({ cart, cartItem, config, }: {
1098
- cart?: NormalizedCart;
1099
- cartItem: NormalizedLineItem;
1100
- config: {
1101
- handle: Record<string, {
1102
- min: number;
1103
- max: number;
1104
- }>;
1105
- sku: Record<string, {
1106
- min: number;
1107
- max: number;
1108
- }>;
1109
- };
1110
- }) => {
1111
- min: number;
1112
- max: number;
1113
- };
1114
-
1115
- declare const useUpdateLineCodeAmountAttributes: ({ cart, mutateCart, isCartLoading, setLoadingState, metafieldIdentifiers, }: {
1116
- cart?: NormalizedCart;
1117
- mutateCart: (cart: NormalizedCart | undefined) => void;
1118
- isCartLoading: boolean;
1119
- setLoadingState: React.Dispatch<React.SetStateAction<any>>;
1120
- metafieldIdentifiers?: {
1121
- variant: HasMetafieldsIdentifier[];
1122
- product: HasMetafieldsIdentifier[];
1123
- };
1124
- }) => void;
1125
-
1126
- declare enum PriceDiscountType {
1127
- PERCENTAGE = 1,// 百分比折扣
1128
- FIXED_AMOUNT = 2
1129
- }
1130
- declare enum PriceBasePriceType {
1131
- MIN_DISCOUNTED_PRICE = 1,// 最低折扣价
1132
- MIN_TOTAL_PRICE = 2
1133
- }
1134
- type PriceDiscountConfig = {
1135
- rule_id: number;
1136
- rule_type: number;
1137
- discount_type: PriceDiscountType;
1138
- discount_value: number;
1139
- base_price_type: PriceBasePriceType;
1140
- applicable_products: Array<{
1141
- product_id: string;
1142
- variant_id?: string;
1143
- }>;
1144
- };
1145
-
1146
- declare const currencyCodeMapping: Record<string, string>;
1147
- declare const defaultSWRMutationConfiguration: SWRMutationConfiguration<any, any, any, any, any> & {
1148
- throwOnError?: boolean;
1149
- };
1150
- declare const CUSTOMER_ATTRIBUTE_KEY = "_discounts_function_env";
1151
- declare const CUSTOMER_SCRIPT_GIFT_KEY = "_giveaway_gradient_gifts";
1152
- declare const CODE_AMOUNT_KEY = "_sku_code_money";
1153
- declare const SCRIPT_CODE_AMOUNT_KEY = "_code_money";
1154
- declare const MAIN_PRODUCT_CODE: string[];
1155
-
1156
- /**
1157
- * Normalize AddToCartLineItem[] to NormalizedLineItem[] format
1158
- * This is used to calculate gifts from lines before they are added to cart
1159
- */
1160
- declare function normalizeAddToCartLines(lines: AddToCartLineItem[]): NormalizedLineItem[];
1161
- /**
1162
- * Create a mock cart structure from AddToCartLineItem[]
1163
- * This is useful for calculating gifts before actual cart operations
1164
- */
1165
- declare function createMockCartFromLines(lines: AddToCartLineItem[], existingCart?: any): any;
1166
-
1167
- declare const getQuery: () => Record<string, string>;
1168
- declare function atobID(id: string): string | undefined;
1169
- declare function btoaID(id: string, type?: 'ProductVariant' | 'Product'): string;
1170
-
1171
- declare const getMatchedMainProductSubTotal: (cartData: any, variant_list: AutoFreeGiftMainProduct["variant_id_list"], main_product: AutoFreeGiftMainProduct) => any;
1172
- declare const safeParse: (str: string) => any;
1173
- declare const getDiscountEnvAttributeValue: (attributes?: {
1174
- key: string;
1175
- value: string;
1176
- }[]) => any;
1177
- declare const checkAttributesUpdateNeeded: (oldAttributes: Attribute$1[], newAttributes: Attribute$1[], customAttributesNeedRemove: {
1178
- key: string;
1179
- }[]) => boolean;
1180
- declare function preCheck(rule_conditions: RuleCondition[], userTags: string[], currentDealsTypes: string[]): boolean;
1181
- declare const formatScriptAutoFreeGift: ({ scriptAutoFreeGiftResult, gradient_gifts, locale, }: {
1182
- scriptAutoFreeGiftResult: UseScriptAutoFreeGiftResult;
1183
- gradient_gifts: any;
1184
- locale: string;
1185
- }) => any[];
1186
- declare const formatFunctionAutoFreeGift: ({ qualifyingGift, giftProductsResult, locale, }: {
1187
- locale: string;
1188
- qualifyingGift?: FormattedGift | null;
1189
- giftProductsResult?: NormalizedProduct[] | [];
1190
- }) => any[];
1191
-
1192
- interface UseProductOptions extends SWRConfiguration<NormalizedProduct | undefined> {
1193
- handle?: string;
1194
- metafieldIdentifiers?: Array<{
1195
- namespace: string;
1196
- key: string;
1197
- }>;
1198
- }
1199
- /**
1200
- * Hook to fetch a single product by handle
1201
- *
1202
- * @param options - Hook options including handle and SWR configuration
1203
- * @returns SWR response with product data
1204
- *
1205
- * @example
1206
- * ```typescript
1207
- * function ProductPage() {
1208
- * const { data: product, error, isLoading } = useProduct({
1209
- * handle: 'my-product'
1210
- * })
1211
- *
1212
- * if (isLoading) return <div>Loading...</div>
1213
- * if (error) return <div>Error loading product</div>
1214
- * if (!product) return <div>Product not found</div>
1215
- *
1216
- * return (
1217
- * <div>
1218
- * <h1>{product.title}</h1>
1219
- * <p>{product.description}</p>
1220
- * <p>${product.price.amount}</p>
1221
- * </div>
1222
- * )
1223
- * }
1224
- * ```
1225
- */
1226
- 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>;
1227
-
1228
- interface UseAllProductsOptions extends SWRConfiguration<NormalizedProduct[]> {
1229
- first?: number;
1230
- query?: string;
1231
- sortKey?: 'TITLE' | 'PRODUCT_TYPE' | 'VENDOR' | 'UPDATED_AT' | 'CREATED_AT' | 'BEST_SELLING' | 'PRICE' | 'RELEVANCE';
1232
- reverse?: boolean;
1233
- metafieldIdentifiers?: Array<{
1234
- namespace: string;
1235
- key: string;
1236
- }>;
1237
- }
1238
- /**
1239
- * Hook to fetch all products
1240
- *
1241
- * This hook automatically handles pagination and fetches all products.
1242
- * Use with caution on stores with many products.
1243
- *
1244
- * @param options - Hook options including query parameters and SWR configuration
1245
- * @returns SWR response with products array
1246
- *
1247
- * @example
1248
- * ```typescript
1249
- * function ProductList() {
1250
- * const { data: products, error, isLoading } = useAllProducts({
1251
- * sortKey: 'TITLE',
1252
- * reverse: false
1253
- * })
1254
- *
1255
- * if (isLoading) return <div>Loading...</div>
1256
- * if (error) return <div>Error loading products</div>
1257
- *
1258
- * return (
1259
- * <div>
1260
- * {products?.map(product => (
1261
- * <div key={product.id}>
1262
- * <h2>{product.title}</h2>
1263
- * <p>${product.price.amount}</p>
1264
- * </div>
1265
- * ))}
1266
- * </div>
1267
- * )
1268
- * }
1269
- * ```
1270
- */
1271
- 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>;
1272
-
1273
- interface UseProductsByHandlesOptions extends SWRConfiguration<NormalizedProduct[]> {
1274
- handles?: string[];
1275
- metafieldIdentifiers?: {
1276
- product: HasMetafieldsIdentifier[];
1277
- variant: HasMetafieldsIdentifier[];
1278
- };
1279
- }
1280
- /**
1281
- * Hook to fetch multiple products by their handles
1282
- *
1283
- * @param options - Hook options including handles array and SWR configuration
1284
- * @returns SWR response with products array
1285
- *
1286
- * @example
1287
- * ```typescript
1288
- * function FeaturedProducts() {
1289
- * const { data: products, error, isLoading } = useProductsByHandles({
1290
- * handles: ['product-1', 'product-2', 'product-3']
1291
- * })
1292
- *
1293
- * if (isLoading) return <div>Loading...</div>
1294
- * if (error) return <div>Error loading products</div>
1295
- *
1296
- * return (
1297
- * <div>
1298
- * {products?.map(product => (
1299
- * <div key={product.id}>
1300
- * <h2>{product.title}</h2>
1301
- * <p>${product.price.amount}</p>
1302
- * </div>
1303
- * ))}
1304
- * </div>
1305
- * )
1306
- * }
1307
- * ```
1308
- */
1309
- 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>;
1310
-
1311
- /**
1312
- * useVariant Hook
1313
- *
1314
- * Client-side hook to get the selected variant based on selected options
1315
- */
1316
-
1317
- type Options = Record<string, string>;
1318
- /**
1319
- * Hook to manage variant selection based on selected options
1320
- *
1321
- * @param product - The product object
1322
- * @param selectedOptions - Currently selected options { Color: 'Red', Size: 'M' }
1323
- * @returns The matching variant
1324
- *
1325
- * @example
1326
- * ```typescript
1327
- * function ProductDetail() {
1328
- * const { data: product } = useProduct({ handle: 'my-product' })
1329
- * const [selectedOptions, setSelectedOptions] = useState({ Color: 'Red', Size: 'M' })
1330
- * const variant = useVariant({ product, selectedOptions })
1331
- *
1332
- * return (
1333
- * <div>
1334
- * <h1>{product.title}</h1>
1335
- * <p>Selected: {variant.title}</p>
1336
- * <p>Price: ${variant.price.amount}</p>
1337
- * <p>Available: {variant.availableForSale ? 'Yes' : 'No'}</p>
1338
- * </div>
1339
- * )
1340
- * }
1341
- * ```
1342
- */
1343
- declare function useVariant({ product, selectedOptions, }: {
1344
- product?: NormalizedProduct;
1345
- selectedOptions: Options;
1346
- }): NormalizedProductVariant | undefined;
1347
-
1348
- /**
1349
- * usePrice Hook
1350
- *
1351
- * Client-side hook to format price for display
1352
- */
1353
- interface UsePriceOptions {
1354
- amount: number;
1355
- baseAmount?: number;
1356
- currencyCode: string;
1357
- soldOutDescription?: string;
1358
- maximumFractionDigits?: number;
1359
- minimumFractionDigits?: number;
1360
- removeTrailingZeros?: boolean;
1361
- }
1362
- interface UsePriceResult {
1363
- price: string;
1364
- basePrice?: string;
1365
- free: boolean;
1366
- }
1367
- /**
1368
- * Hook to format price for display
1369
- *
1370
- * @param options - Price formatting options
1371
- * @returns Formatted price object
1372
- *
1373
- * @example
1374
- * ```typescript
1375
- * function ProductPrice({ variant }) {
1376
- * const { price, basePrice, free } = usePrice({
1377
- * amount: variant.price.amount,
1378
- * baseAmount: variant.compareAtPrice?.amount,
1379
- * currencyCode: variant.price.currencyCode
1380
- * })
1381
- *
1382
- * return (
1383
- * <div>
1384
- * {free ? (
1385
- * <span>Free</span>
1386
- * ) : (
1387
- * <>
1388
- * <span className="price">{price}</span>
1389
- * {basePrice && <span className="original">{basePrice}</span>}
1390
- * </>
1391
- * )}
1392
- * </div>
1393
- * )
1394
- * }
1395
- * ```
1396
- */
1397
- declare function usePrice({ amount, baseAmount, currencyCode, soldOutDescription, maximumFractionDigits, minimumFractionDigits, removeTrailingZeros, }: UsePriceOptions): UsePriceResult;
1398
-
1399
- /**
1400
- * useSelectedOptions Hook
1401
- *
1402
- * Client-side hook to manage selected product options
1403
- */
1404
-
1405
- type SelectedOptionsResult = [Options, Dispatch<SetStateAction<Options>>];
1406
- /**
1407
- * Hook to manage selected product options based on URL query or SKU
1408
- *
1409
- * @param product - The product object
1410
- * @param sku - Optional SKU to match variant
1411
- * @returns Tuple of [options, setOptions]
1412
- *
1413
- * @example
1414
- * ```typescript
1415
- * function ProductDetail() {
1416
- * const { data: product } = useProduct({ handle: 'my-product' })
1417
- * const [selectedOptions, setSelectedOptions] = useSelectedOptions(product)
1418
- * const variant = useVariant({ product, selectedOptions })
1419
- *
1420
- * const handleOptionChange = (name: string, value: string) => {
1421
- * setSelectedOptions(prev => ({ ...prev, [name]: value }))
1422
- * }
1423
- *
1424
- * return (
1425
- * <div>
1426
- * {product?.options.map(option => (
1427
- * <select
1428
- * key={option.id}
1429
- * value={selectedOptions[option.name] || ''}
1430
- * onChange={(e) => handleOptionChange(option.name, e.target.value)}
1431
- * >
1432
- * {option.values.map(value => (
1433
- * <option key={value.label} value={value.label}>
1434
- * {value.label}
1435
- * </option>
1436
- * ))}
1437
- * </select>
1438
- * ))}
1439
- * <p>Selected: {variant?.title}</p>
1440
- * </div>
1441
- * )
1442
- * }
1443
- * ```
1444
- */
1445
- declare function useSelectedOptions(product?: NormalizedProduct, sku?: string): SelectedOptionsResult;
1446
-
1447
- /**
1448
- * useProductUrl Hook
1449
- *
1450
- * Hook to generate product URLs with variant query params
1451
- * Requires routerAdapter to be configured in ShopifyProvider
1452
- */
1453
-
1454
- /**
1455
- * Hook to generate product URLs
1456
- *
1457
- * @param otherQuery - Additional query parameters to include
1458
- * @returns Function to generate product URL
1459
- *
1460
- * @example
1461
- * ```typescript
1462
- * function ProductCard({ product, variant }) {
1463
- * const getProductUrl = useProductUrl()
1464
- *
1465
- * const url = getProductUrl({ product, variant })
1466
- *
1467
- * return (
1468
- * <a href={url}>
1469
- * <h2>{product.title}</h2>
1470
- * <p>{variant.title}</p>
1471
- * </a>
1472
- * )
1473
- * }
1474
- * ```
1475
- *
1476
- * @example With additional query params
1477
- * ```typescript
1478
- * function ProductCard({ product, variant }) {
1479
- * const getProductUrl = useProductUrl({ utm_source: 'email' })
1480
- *
1481
- * const url = getProductUrl({ product, variant })
1482
- * // URL will include: ?variant=123&utm_source=email
1483
- *
1484
- * return <a href={url}>{product.title}</a>
1485
- * }
1486
- * ```
1487
- */
1488
- declare function useProductUrl(otherQuery?: Record<string, string>): ({ product, variant }: {
1489
- product?: NormalizedProduct;
1490
- variant?: NormalizedProductVariant;
1491
- }) => string;
1492
-
1493
- /**
1494
- * useUpdateVariantQuery Hook
1495
- *
1496
- * Hook to automatically update URL query string when variant changes
1497
- */
1498
-
1499
- /**
1500
- * Hook to update URL query string when variant changes
1501
- *
1502
- * This hook automatically updates the browser URL with the selected variant ID
1503
- * without causing a page reload. Useful for shareable URLs and browser history.
1504
- *
1505
- * @param variant - The selected variant
1506
- *
1507
- * @example
1508
- * ```typescript
1509
- * function ProductDetail() {
1510
- * const { data: product } = useProduct({ handle: 'my-product' })
1511
- * const [selectedOptions, setSelectedOptions] = useSelectedOptions(product)
1512
- * const variant = useVariant({ product, selectedOptions })
1513
- *
1514
- * // Automatically updates URL when variant changes
1515
- * useUpdateVariantQuery(variant)
1516
- *
1517
- * return (
1518
- * <div>
1519
- * <h1>{product?.title}</h1>
1520
- * <p>Current variant: {variant?.title}</p>
1521
- * {/* URL will be: /products/my-product?variant=123456 *\/}
1522
- * </div>
1523
- * )
1524
- * }
1525
- * ```
1526
- */
1527
- declare function useUpdateVariantQuery(variant?: NormalizedProductVariant): void;
1528
-
1529
- /**
1530
- * useVariantMedia Hook
1531
- *
1532
- * Hook to get media (images and videos) for the selected variant
1533
- */
1534
-
1535
- type ImageMedia = Media & {
1536
- mediaContentType: 'IMAGE';
1537
- };
1538
- type VideoMedia = Media & {
1539
- mediaContentType: 'VIDEO' | 'EXTERNAL_VIDEO';
1540
- };
1541
- interface VariantMedia {
1542
- productList: ImageMedia[];
1543
- sceneList: ImageMedia[];
1544
- videoList: VideoMedia[];
1545
- }
1546
- /**
1547
- * Hook to get media for the selected variant
1548
- *
1549
- * @param product - The product object
1550
- * @param variant - The selected variant
1551
- * @returns Object with productList (first image), sceneList (other images), videoList
1552
- *
1553
- * @example
1554
- * ```typescript
1555
- * function ProductGallery() {
1556
- * const { data: product } = useProduct({ handle: 'my-product' })
1557
- * const [selectedOptions, setSelectedOptions] = useSelectedOptions(product)
1558
- * const variant = useVariant({ product, selectedOptions })
1559
- * const { productList, sceneList, videoList } = useVariantMedia({ product, variant })
1560
- *
1561
- * return (
1562
- * <div>
1563
- * {/* Main product image *\/}
1564
- * {productList.map(media => (
1565
- * <img key={media.id} src={media.image?.url} alt={media.alt} />
1566
- * ))}
1567
- *
1568
- * {/* Scene/detail images *\/}
1569
- * {sceneList.map(media => (
1570
- * <img key={media.id} src={media.image?.url} alt={media.alt} />
1571
- * ))}
1572
- *
1573
- * {/* Videos *\/}
1574
- * {videoList.map(media => (
1575
- * <video key={media.id} src={media.sources?.[0]?.url} controls />
1576
- * ))}
1577
- * </div>
1578
- * )
1579
- * }
1580
- * ```
1581
- */
1582
- declare function useVariantMedia({ product, variant, }: {
1583
- product?: NormalizedProduct;
1584
- variant?: NormalizedProductVariant;
1585
- }): VariantMedia;
1586
-
1587
- interface UseCollectionOptions extends SWRConfiguration<NormalizedCollection | undefined> {
1588
- handle?: string;
1589
- metafieldIdentifiers?: Array<{
1590
- namespace: string;
1591
- key: string;
1592
- }>;
1593
- }
1594
- 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>;
1595
-
1596
- interface UseAllCollectionsOptions extends SWRConfiguration<NormalizedCollection[]> {
1597
- first?: number;
1598
- query?: string;
1599
- sortKey?: 'TITLE' | 'UPDATED_AT' | 'ID' | 'RELEVANCE';
1600
- reverse?: boolean;
1601
- metafieldIdentifiers?: Array<{
1602
- namespace: string;
1603
- key: string;
1604
- }>;
1605
- }
1606
- 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>;
1607
-
1608
- interface UseCollectionsOptions extends SWRConfiguration<CollectionsConnection> {
1609
- first?: number;
1610
- after?: string;
1611
- query?: string;
1612
- sortKey?: 'TITLE' | 'UPDATED_AT' | 'ID' | 'RELEVANCE';
1613
- reverse?: boolean;
1614
- metafieldIdentifiers?: Array<{
1615
- namespace: string;
1616
- key: string;
1617
- }>;
1618
- }
1619
- 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>;
1620
-
1621
- interface UseBlogOptions extends SWRConfiguration<NormalizedBlog | undefined> {
1622
- handle?: string;
1623
- metafieldIdentifiers?: Array<{
1624
- namespace: string;
1625
- key: string;
1626
- }>;
1627
- }
1628
- 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>;
1629
-
1630
- interface UseAllBlogsOptions extends SWRConfiguration<NormalizedBlog[]> {
1631
- first?: number;
1632
- query?: string;
1633
- metafieldIdentifiers?: Array<{
1634
- namespace: string;
1635
- key: string;
1636
- }>;
1637
- }
1638
- 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>;
1639
-
1640
- interface UseArticleOptions extends SWRConfiguration<NormalizedArticle | undefined> {
1641
- blogHandle?: string;
1642
- articleHandle?: string;
1643
- metafieldIdentifiers?: Array<{
1644
- namespace: string;
1645
- key: string;
1646
- }>;
1647
- }
1648
- 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>;
1649
-
1650
- interface UseArticlesOptions extends SWRConfiguration<NormalizedArticle[]> {
1651
- first?: number;
1652
- query?: string;
1653
- sortKey?: 'PUBLISHED_AT' | 'UPDATED_AT' | 'TITLE' | 'ID' | 'RELEVANCE';
1654
- reverse?: boolean;
1655
- metafieldIdentifiers?: Array<{
1656
- namespace: string;
1657
- key: string;
1658
- }>;
1659
- }
1660
- 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>;
1661
-
1662
- interface UseArticlesInBlogOptions extends SWRConfiguration<NormalizedArticle[]> {
1663
- blogHandle?: string;
1664
- first?: number;
1665
- sortKey?: 'PUBLISHED_AT' | 'UPDATED_AT' | 'TITLE' | 'ID' | 'RELEVANCE';
1666
- reverse?: boolean;
1667
- metafieldIdentifiers?: Array<{
1668
- namespace: string;
1669
- key: string;
1670
- }>;
1671
- }
1672
- 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>;
1673
-
1674
- type SearchResultType = 'ARTICLE' | 'PAGE' | 'PRODUCT';
1675
- interface SearchResultItem {
1676
- type: SearchResultType;
1677
- id?: string;
1678
- handle?: string;
1679
- title?: string;
1680
- description?: string;
1681
- url?: string;
1682
- image?: {
1683
- url: string;
1684
- altText?: string;
1685
- };
1686
- }
1687
- interface SearchResult {
1688
- items: SearchResultItem[];
1689
- totalCount: number;
1690
- pageInfo?: {
1691
- hasNextPage: boolean;
1692
- endCursor?: string;
1693
- };
1694
- }
1695
- interface UseSearchOptions extends SWRConfiguration<SearchResult | undefined> {
1696
- query?: string;
1697
- first?: number;
1698
- types?: SearchResultType[];
1699
- productFilters?: any[];
1700
- }
1701
- 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>;
1702
-
1703
- interface SiteInfo {
1704
- name: string;
1705
- description?: string;
1706
- primaryDomain: {
1707
- url: string;
1708
- host: string;
1709
- };
1710
- brand?: {
1711
- logo?: {
1712
- image?: {
1713
- url: string;
1714
- };
1715
- };
1716
- colors?: {
1717
- primary?: string;
1718
- secondary?: string;
1719
- };
1720
- };
1721
- metafields?: Record<string, any>;
1722
- }
1723
- interface UseSiteOptions extends SWRConfiguration<SiteInfo | undefined> {
1724
- metafieldIdentifiers?: Array<{
1725
- namespace: string;
1726
- key: string;
1727
- }>;
1728
- }
1729
- 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>;
1730
-
1731
- /**
1732
- * useIntersection Hook
1733
- *
1734
- * Observes element visibility using IntersectionObserver API
1735
- */
1736
-
1737
- interface UseIntersectionOptions {
1738
- /** Callback function when element becomes visible */
1739
- callback: () => void;
1740
- /** Only trigger callback once (default: false) */
1741
- once?: boolean;
1742
- /** Root element for intersection (default: viewport) */
1743
- root?: Element | null;
1744
- /** Margin around root (default: '0px') */
1745
- rootMargin?: string;
1746
- /** Visibility threshold 0-1 (default: 0.8) */
1747
- threshold?: number;
1748
- }
1749
- /**
1750
- * Hook to observe element visibility with IntersectionObserver
1751
- *
1752
- * Triggers a callback when the target element becomes visible in the viewport
1753
- *
1754
- * @param targetRef - React ref to the target element
1755
- * @param options - Intersection observer options
1756
- *
1757
- * @example
1758
- * ```typescript
1759
- * function LazyImage() {
1760
- * const imageRef = useRef<HTMLImageElement>(null)
1761
- * const [loaded, setLoaded] = useState(false)
1762
- *
1763
- * useIntersection(imageRef, {
1764
- * callback: () => setLoaded(true),
1765
- * once: true,
1766
- * threshold: 0.5
1767
- * })
1768
- *
1769
- * return (
1770
- * <img
1771
- * ref={imageRef}
1772
- * src={loaded ? actualSrc : placeholderSrc}
1773
- * alt="Lazy loaded"
1774
- * />
1775
- * )
1776
- * }
1777
- * ```
1778
- */
1779
- declare function useIntersection(targetRef: RefObject<Element> | undefined, options: UseIntersectionOptions): void;
1780
-
1781
- /**
1782
- * useExposure Hook
1783
- *
1784
- * Tracks element exposure (visibility + duration) for analytics/tracking
1785
- */
1786
-
1787
- interface UseExposureOptions {
1788
- /** Visibility threshold 0-1 (default: 0.5, meaning 50% visible) */
1789
- threshold?: number;
1790
- /** Duration in milliseconds element must be visible (default: 2000ms) */
1791
- duration?: number;
1792
- /** Only trigger callback once (default: true) */
1793
- once?: boolean;
1794
- /** Callback when element has been exposed for the required duration */
1795
- onExposure: () => void;
1796
- }
1797
- /**
1798
- * Hook to track element exposure (visibility + duration threshold)
1799
- *
1800
- * Useful for tracking ad impressions, product views, or any analytics
1801
- * that require an element to be visible for a certain duration
1802
- *
1803
- * @param targetRef - React ref to the target element
1804
- * @param options - Exposure tracking options
1805
- * @returns Current visibility state
1806
- *
1807
- * @example
1808
- * ```typescript
1809
- * function ProductCard({ product }) {
1810
- * const cardRef = useRef<HTMLDivElement>(null)
1811
- *
1812
- * const isVisible = useExposure(cardRef, {
1813
- * threshold: 0.5, // 50% visible
1814
- * duration: 2000, // 2 seconds
1815
- * once: true, // Only track once
1816
- * onExposure: () => {
1817
- * // Track product impression
1818
- * analytics.track('Product Viewed', {
1819
- * productId: product.id,
1820
- * productName: product.title
1821
- * })
1822
- * }
1823
- * })
1824
- *
1825
- * return (
1826
- * <div ref={cardRef}>
1827
- * {product.title}
1828
- * {isVisible && <div className="viewing-indicator" />}
1829
- * </div>
1830
- * )
1831
- * }
1832
- * ```
1833
- */
1834
- declare function useExposure(targetRef: RefObject<Element>, options: UseExposureOptions): boolean;
1835
-
1836
- /**
1837
- * useGeoLocation Hook
1838
- *
1839
- * Fetches and caches user's geographic location
1840
- */
1841
-
1842
- interface GeoLocationData {
1843
- /** Geographic information */
1844
- geo: {
1845
- /** Country information */
1846
- country?: {
1847
- /** Country code (e.g., 'US', 'GB') */
1848
- code?: string;
1849
- /** Country name */
1850
- name?: string;
1851
- };
1852
- /** Region/state information */
1853
- region?: {
1854
- code?: string;
1855
- name?: string;
1856
- };
1857
- /** City name */
1858
- city?: string;
1859
- /** Coordinates */
1860
- latitude?: number;
1861
- longitude?: number;
1862
- /** Timezone */
1863
- timezone?: string;
1864
- };
1865
- /** Suggested locale based on location */
1866
- suggestLocale?: string;
1867
- }
1868
- interface LocaleMapping {
1869
- /** Countries that should map to EU locale */
1870
- euCountries?: string[];
1871
- /** Countries that should map to DE locale */
1872
- deCountries?: string[];
1873
- /** Countries that should map to AU locale */
1874
- auCountries?: string[];
1875
- /** Countries that should map to AE-EN locale */
1876
- aeEnCountries?: string[];
1877
- /** Custom country to locale mapping */
1878
- customMapping?: Record<string, string>;
1879
- }
1880
- interface UseGeoLocationOptions extends SWRConfiguration<GeoLocationData | undefined> {
1881
- /** API endpoint for fetching geo data (default: '/geolocation') */
1882
- endpoint?: string;
1883
- /** Cache key for localStorage (default: 'geoLocation') */
1884
- cacheKey?: string;
1885
- /** Cache duration in milliseconds (default: 24 hours) */
1886
- cacheDuration?: number;
1887
- /** Locale mapping configuration */
1888
- localeMapping?: LocaleMapping;
1889
- /** Enable automatic caching (default: true) */
1890
- enableCache?: boolean;
1891
- }
1892
- /**
1893
- * Hook to fetch and cache user's geographic location
1894
- *
1895
- * Fetches geo data from an API endpoint and caches it in localStorage
1896
- * Automatically determines suggested locale based on country
1897
- *
1898
- * @param options - Geo location options
1899
- * @returns SWR response with geo location data
1900
- *
1901
- * @example
1902
- * ```typescript
1903
- * function LocaleSwitcher() {
1904
- * const { data: geoData, error, isLoading } = useGeoLocation({
1905
- * endpoint: '/api/geolocation',
1906
- * localeMapping: {
1907
- * euCountries: ['FR', 'DE', 'IT', 'ES'],
1908
- * auCountries: ['AU', 'NZ']
1909
- * }
1910
- * })
1911
- *
1912
- * if (isLoading) return <div>Loading...</div>
1913
- * if (error) return <div>Error loading location</div>
1914
- *
1915
- * return (
1916
- * <div>
1917
- * <p>Country: {geoData?.geo.country?.code}</p>
1918
- * <p>Suggested Locale: {geoData?.suggestLocale}</p>
1919
- * </div>
1920
- * )
1921
- * }
1922
- * ```
1923
- *
1924
- * @example
1925
- * ```typescript
1926
- * // With custom locale mapping
1927
- * const { data } = useGeoLocation({
1928
- * localeMapping: {
1929
- * customMapping: {
1930
- * 'JP': 'ja',
1931
- * 'CN': 'zh-cn',
1932
- * 'TW': 'zh-tw'
1933
- * }
1934
- * }
1935
- * })
1936
- * ```
1937
- */
1938
- declare function useGeoLocation(options?: UseGeoLocationOptions): ReturnType<typeof swr__default<GeoLocationData | undefined>>;
1939
- /**
1940
- * Get cached geo location data without fetching
1941
- *
1942
- * @param cacheKey - Cache key (default: 'geoLocation')
1943
- * @returns Cached geo data or undefined
1944
- *
1945
- * @example
1946
- * ```typescript
1947
- * const cachedGeo = getCachedGeoLocation()
1948
- * if (cachedGeo) {
1949
- * console.log('Country:', cachedGeo.geo.country?.code)
1950
- * }
1951
- * ```
1952
- */
1953
- declare function getCachedGeoLocation(cacheKey?: string): GeoLocationData | undefined;
1954
- /**
1955
- * Clear cached geo location data
1956
- *
1957
- * @param cacheKey - Cache key (default: 'geoLocation')
1958
- *
1959
- * @example
1960
- * ```typescript
1961
- * clearGeoLocationCache()
1962
- * ```
1963
- */
1964
- declare function clearGeoLocationCache(cacheKey?: string): void;
1965
-
1966
- export { PriceBasePriceType as $, type AddCartLinesInput as A, type BuyNowInput as B, type CreateCartInput as C, type DiscountLabel as D, type Config as E, type GiftTier as F, type GiftProduct as G, type RewardItem as H, type GiftProductItem as I, RuleType as J, BuyRuleType as K, type FunctionGiftResult as L, type MainProductInfo as M, type FormattedGift as N, type OrderDiscountResult as O, type CartLineInput as P, type AutoFreeGiftItem as Q, type RemoveCartLinesInput as R, SpendMoneyType as S, type AutoFreeGiftList as T, type UpdateCartAttributesInput as U, type VariantItem as V, OrderDiscountType as W, OrderBasePriceType as X, type TieredDiscount as Y, type OrderDiscountConfig as Z, PriceDiscountType as _, useAddCartLines as a, type ShippingMethodsContext as a$, type PriceDiscountConfig as a0, currencyCodeMapping as a1, defaultSWRMutationConfiguration as a2, CUSTOMER_ATTRIBUTE_KEY as a3, CUSTOMER_SCRIPT_GIFT_KEY as a4, CODE_AMOUNT_KEY as a5, SCRIPT_CODE_AMOUNT_KEY as a6, MAIN_PRODUCT_CODE as a7, getQuery as a8, atobID as a9, type VideoMedia as aA, type VariantMedia as aB, useVariantMedia as aC, type UseCollectionOptions as aD, useCollection as aE, type UseAllCollectionsOptions as aF, useAllCollections as aG, type UseCollectionsOptions as aH, useCollections as aI, type UseBlogOptions as aJ, useBlog as aK, type UseAllBlogsOptions as aL, useAllBlogs as aM, type UseArticleOptions as aN, useArticle as aO, type UseArticlesOptions as aP, useArticles as aQ, type UseArticlesInBlogOptions as aR, useArticlesInBlog as aS, type SearchResultType as aT, type SearchResultItem as aU, type SearchResult as aV, type UseSearchOptions as aW, useSearch as aX, type SiteInfo as aY, type UseSiteOptions as aZ, useSite as a_, btoaID as aa, normalizeAddToCartLines as ab, createMockCartFromLines as ac, getMatchedMainProductSubTotal as ad, safeParse as ae, getDiscountEnvAttributeValue as af, checkAttributesUpdateNeeded as ag, preCheck as ah, formatScriptAutoFreeGift as ai, formatFunctionAutoFreeGift as aj, useSelectedOptions as ak, type SelectedOptionsResult as al, type UseProductOptions as am, useProduct as an, type UseAllProductsOptions as ao, useAllProducts as ap, type UseProductsByHandlesOptions as aq, useProductsByHandles as ar, type Options as as, useVariant as at, type UsePriceOptions as au, type UsePriceResult as av, usePrice as aw, useProductUrl as ax, useUpdateVariantQuery as ay, type ImageMedia as az, useUpdateCartLines as b, type PlusMemberContextValue as b0, PlusMemberContext as b1, usePlusMemberContext as b2, usePlusMonthlyProductVariant as b3, usePlusAnnualProductVariant as b4, type UseShippingMethodsOptions as b5, type UseShippingMethodsResult as b6, useShippingMethods as b7, useShippingMethodAvailableCheck as b8, useReplaceCartPlusMember as b9, type Image as bA, type Measurement as bB, type ExportSelectedOption as bC, type ExportProductVariant as bD, type ExportDiscountAllocations as bE, type ExportLineItem as bF, type ExportDiscounts as bG, type ExportCart as bH, usePlusMemberDeliveryCodes as ba, usePlusMemberItemCustomAttributes as bb, type CustomerOrder as bc, type Customer as bd, usePlusMemberCheckoutCustomAttributes as be, type UseAutoRemovePlusMemberInCartProps as bf, useAutoRemovePlusMemberInCart as bg, type UseHasPlusMemberInCartProps as bh, type HasPlusMemberInCartResult as bi, useHasPlusMemberInCart as bj, type UseAddPlusMemberProductsToCartProps as bk, useAddPlusMemberProductsToCart as bl, type PlusMemberProviderProps as bm, PlusMemberProvider as bn, type UseIntersectionOptions as bo, useIntersection as bp, type UseExposureOptions as bq, useExposure as br, type GeoLocationData as bs, type LocaleMapping as bt, type UseGeoLocationOptions as bu, useGeoLocation as bv, getCachedGeoLocation as bw, clearGeoLocationCache as bx, type Attribute as by, type Discount as bz, useRemoveCartLines as c, type ApplyCartCodesInput as d, useApplyCartCodes as e, type RemoveCartCodesInput as f, useRemoveCartCodes as g, useUpdateCartAttributes as h, type UseBuyNowOptions as i, useBuyNow as j, useCalcAutoFreeGift as k, type UseCalcGiftsFromLinesOptions as l, type UseCalcGiftsFromLinesResult as m, useCalcGiftsFromLines as n, useCalcOrderDiscount as o, getReferralAttributes as p, useCartAttributes as q, useCartItemQuantityLimit as r, type UseScriptAutoFreeGiftResult as s, useScriptAutoFreeGift as t, useCreateCart as u, useUpdateLineCodeAmountAttributes as v, type AutoFreeGift as w, type AutoFreeGiftMainProduct as x, type AutoFreeGiftConfig as y, type RuleCondition as z };