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