@anker-in/shopify-react 0.1.1-beta.14 → 0.1.1-beta.16

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