@anker-in/shopify-react 1.2.2-beta.8 → 1.3.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,8 +4,7 @@ import { ShopifyClient, ShopifyConfig, CartCookieAdapter, NormalizedCart, Attrib
4
4
  import { C as CookieAdapter, R as RouterAdapter, U as UserContextAdapter, P as PerformanceAdapter } from '../types-SKDHauqk.mjs';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { SWRConfiguration } from 'swr';
7
- import { S as ScriptAutoFreeGiftConfig, n as PlusMemberSettingsMetafields, U as UseAutoRemoveFreeGiftsOptions } from '../types-DfR13pDe.mjs';
8
- import 'decimal.js';
7
+ import { e as PlusMemberSettingsMetafields } from '../types-CMMWxyUF.mjs';
9
8
 
10
9
  interface ShopifyContextValue {
11
10
  client: ShopifyClient;
@@ -49,12 +48,6 @@ type LoadingState = {
49
48
  listingAutoCodeApplying: boolean;
50
49
  userCodeApplying: boolean;
51
50
  };
52
- type AppContext = {
53
- /** Whether running in app */
54
- isInApp?: boolean;
55
- /** App name */
56
- appName?: string;
57
- };
58
51
  interface CartContextValue {
59
52
  /** Current cart data */
60
53
  cart: NormalizedCart | undefined;
@@ -98,10 +91,10 @@ interface CartContextValue {
98
91
  calculatedAutoFreeGift?: any;
99
92
  /** Gifts that need to be added to cart */
100
93
  giftNeedAddToCartLines: any[];
101
- /** Function auto free gift config */
102
- functionAutoFreeGiftConfig?: any;
103
- /** Script auto free gift config */
104
- scriptAutoFreeGiftConfig?: ScriptAutoFreeGiftConfig;
94
+ /** Auto free gift config */
95
+ autoFreeGiftConfig?: any;
96
+ /** Gradient gifts config */
97
+ gradientGiftsConfig?: any;
105
98
  /** Metafield identifiers */
106
99
  metafieldIdentifiers?: {
107
100
  variant: HasMetafieldsIdentifier[];
@@ -113,19 +106,17 @@ interface CartContextValue {
113
106
  customer?: any;
114
107
  /** Plus member settings */
115
108
  memberSetting?: PlusMemberSettingsMetafields;
116
- /** App context */
117
- appContext?: AppContext;
118
- /** Auto remove free gifts options */
119
- autoRemoveFreeGiftsOptions?: UseAutoRemoveFreeGiftsOptions;
120
109
  }
121
110
  interface CartProviderProps {
122
111
  children: React__default.ReactNode;
123
112
  /** SWR configuration options */
124
113
  swrOptions?: SWRConfiguration<NormalizedCart | undefined, Error>;
125
- /** Function auto free gift configuration */
126
- functionAutoFreeGiftConfig?: any;
127
- /** Script auto free gift configuration */
128
- scriptAutoFreeGiftConfig?: ScriptAutoFreeGiftConfig;
114
+ /** Auto free gift configuration */
115
+ autoFreeGiftConfig?: any;
116
+ /** Gradient gifts configuration (for script gifts) */
117
+ gradientGiftsConfig?: any;
118
+ /** Function gift configuration */
119
+ fnGiftConf?: any;
129
120
  /** User profile */
130
121
  profile?: any;
131
122
  /** Customer data */
@@ -139,10 +130,6 @@ interface CartProviderProps {
139
130
  };
140
131
  /** Plus member settings */
141
132
  memberSetting?: PlusMemberSettingsMetafields;
142
- /** App context */
143
- appContext?: AppContext;
144
- /** 是否禁用自动更新 line item 的 code amount attributes,默认为 false */
145
- disableUpdateLineCodeAmountAttributes?: boolean;
146
133
  }
147
134
  /**
148
135
  * Cart Provider Component
@@ -154,8 +141,7 @@ interface CartProviderProps {
154
141
  * <ShopifyProvider {...config}>
155
142
  * <CartProvider
156
143
  * locale="us"
157
- * functionAutoFreeGiftConfig={functionConfig}
158
- * scriptAutoFreeGiftConfig={scriptConfig}
144
+ * autoFreeGiftConfig={config}
159
145
  * profile={profile}
160
146
  * customer={customer}
161
147
  * >
@@ -164,7 +150,7 @@ interface CartProviderProps {
164
150
  * </ShopifyProvider>
165
151
  * ```
166
152
  */
167
- declare function CartProvider({ children, functionAutoFreeGiftConfig, scriptAutoFreeGiftConfig, profile, customer, locale, metafieldIdentifiers, memberSetting, appContext, disableUpdateLineCodeAmountAttributes, }: CartProviderProps): react_jsx_runtime.JSX.Element;
153
+ declare function CartProvider({ children, autoFreeGiftConfig, gradientGiftsConfig, profile, customer, locale, metafieldIdentifiers, memberSetting, }: CartProviderProps): react_jsx_runtime.JSX.Element;
168
154
  /**
169
155
  * Hook to access cart context
170
156
  *
@@ -189,4 +175,4 @@ declare function useCartContext(options: {
189
175
  optional: true;
190
176
  }): CartContextValue | null;
191
177
 
192
- export { type AppContext, type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
178
+ export { type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
@@ -4,8 +4,7 @@ import { ShopifyClient, ShopifyConfig, CartCookieAdapter, NormalizedCart, Attrib
4
4
  import { C as CookieAdapter, R as RouterAdapter, U as UserContextAdapter, P as PerformanceAdapter } from '../types-SKDHauqk.js';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { SWRConfiguration } from 'swr';
7
- import { S as ScriptAutoFreeGiftConfig, n as PlusMemberSettingsMetafields, U as UseAutoRemoveFreeGiftsOptions } from '../types-DfR13pDe.js';
8
- import 'decimal.js';
7
+ import { e as PlusMemberSettingsMetafields } from '../types-CMMWxyUF.js';
9
8
 
10
9
  interface ShopifyContextValue {
11
10
  client: ShopifyClient;
@@ -49,12 +48,6 @@ type LoadingState = {
49
48
  listingAutoCodeApplying: boolean;
50
49
  userCodeApplying: boolean;
51
50
  };
52
- type AppContext = {
53
- /** Whether running in app */
54
- isInApp?: boolean;
55
- /** App name */
56
- appName?: string;
57
- };
58
51
  interface CartContextValue {
59
52
  /** Current cart data */
60
53
  cart: NormalizedCart | undefined;
@@ -98,10 +91,10 @@ interface CartContextValue {
98
91
  calculatedAutoFreeGift?: any;
99
92
  /** Gifts that need to be added to cart */
100
93
  giftNeedAddToCartLines: any[];
101
- /** Function auto free gift config */
102
- functionAutoFreeGiftConfig?: any;
103
- /** Script auto free gift config */
104
- scriptAutoFreeGiftConfig?: ScriptAutoFreeGiftConfig;
94
+ /** Auto free gift config */
95
+ autoFreeGiftConfig?: any;
96
+ /** Gradient gifts config */
97
+ gradientGiftsConfig?: any;
105
98
  /** Metafield identifiers */
106
99
  metafieldIdentifiers?: {
107
100
  variant: HasMetafieldsIdentifier[];
@@ -113,19 +106,17 @@ interface CartContextValue {
113
106
  customer?: any;
114
107
  /** Plus member settings */
115
108
  memberSetting?: PlusMemberSettingsMetafields;
116
- /** App context */
117
- appContext?: AppContext;
118
- /** Auto remove free gifts options */
119
- autoRemoveFreeGiftsOptions?: UseAutoRemoveFreeGiftsOptions;
120
109
  }
121
110
  interface CartProviderProps {
122
111
  children: React__default.ReactNode;
123
112
  /** SWR configuration options */
124
113
  swrOptions?: SWRConfiguration<NormalizedCart | undefined, Error>;
125
- /** Function auto free gift configuration */
126
- functionAutoFreeGiftConfig?: any;
127
- /** Script auto free gift configuration */
128
- scriptAutoFreeGiftConfig?: ScriptAutoFreeGiftConfig;
114
+ /** Auto free gift configuration */
115
+ autoFreeGiftConfig?: any;
116
+ /** Gradient gifts configuration (for script gifts) */
117
+ gradientGiftsConfig?: any;
118
+ /** Function gift configuration */
119
+ fnGiftConf?: any;
129
120
  /** User profile */
130
121
  profile?: any;
131
122
  /** Customer data */
@@ -139,10 +130,6 @@ interface CartProviderProps {
139
130
  };
140
131
  /** Plus member settings */
141
132
  memberSetting?: PlusMemberSettingsMetafields;
142
- /** App context */
143
- appContext?: AppContext;
144
- /** 是否禁用自动更新 line item 的 code amount attributes,默认为 false */
145
- disableUpdateLineCodeAmountAttributes?: boolean;
146
133
  }
147
134
  /**
148
135
  * Cart Provider Component
@@ -154,8 +141,7 @@ interface CartProviderProps {
154
141
  * <ShopifyProvider {...config}>
155
142
  * <CartProvider
156
143
  * locale="us"
157
- * functionAutoFreeGiftConfig={functionConfig}
158
- * scriptAutoFreeGiftConfig={scriptConfig}
144
+ * autoFreeGiftConfig={config}
159
145
  * profile={profile}
160
146
  * customer={customer}
161
147
  * >
@@ -164,7 +150,7 @@ interface CartProviderProps {
164
150
  * </ShopifyProvider>
165
151
  * ```
166
152
  */
167
- declare function CartProvider({ children, functionAutoFreeGiftConfig, scriptAutoFreeGiftConfig, profile, customer, locale, metafieldIdentifiers, memberSetting, appContext, disableUpdateLineCodeAmountAttributes, }: CartProviderProps): react_jsx_runtime.JSX.Element;
153
+ declare function CartProvider({ children, autoFreeGiftConfig, gradientGiftsConfig, profile, customer, locale, metafieldIdentifiers, memberSetting, }: CartProviderProps): react_jsx_runtime.JSX.Element;
168
154
  /**
169
155
  * Hook to access cart context
170
156
  *
@@ -189,4 +175,4 @@ declare function useCartContext(options: {
189
175
  optional: true;
190
176
  }): CartContextValue | null;
191
177
 
192
- export { type AppContext, type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
178
+ export { type CartContextValue, CartProvider, type CartProviderProps, type LoadingState, ShopifyContext, type ShopifyContextValue, ShopifyProvider, type ShopifyProviderProps, useCartContext, useShopify };
@@ -1,5 +1,4 @@
1
- import { NormalizedLineItem, MoneyV2, NormalizedProductVariant, NormalizedProduct, NormalizedCart } from '@anker-in/shopify-sdk';
2
- import Decimal from 'decimal.js';
1
+ import { NormalizedProductVariant, NormalizedProduct, MoneyV2, NormalizedCart } from '@anker-in/shopify-sdk';
3
2
 
4
3
  /**
5
4
  * Tracking Types
@@ -19,30 +18,19 @@ interface GtmParams {
19
18
 
20
19
  declare global {
21
20
  interface Window {
22
- dataLayer?: Array<Record<string, unknown>>;
23
- gtag?: {
24
- (command: 'config', targetId: string, config?: Record<string, unknown>): void;
25
- (command: 'set', config: Record<string, unknown>): void;
26
- (command: 'event', eventName: string, eventParams?: Record<string, unknown>): void;
27
- (command: 'get', targetId: string, fieldName: string, callback?: (value: string) => void): void;
28
- (command: 'consent', consentArg: string, consentParams?: Record<string, unknown>): void;
29
- };
21
+ dataLayer?: any[];
22
+ gtag?: (...args: any) => void;
30
23
  }
31
24
  }
32
25
  /**
33
26
  * Push event to GA4 dataLayer
34
27
  */
35
- declare const gaTrack: (data: Record<string, unknown>) => void;
28
+ declare const gaTrack: (data: any) => void;
36
29
  /**
37
30
  * Track add to cart event in GA4
38
31
  */
39
32
  declare const trackAddToCartGA: ({ lineItems, gtmParams, }: {
40
- lineItems: Array<NormalizedLineItem & {
41
- finalPrice?: MoneyV2;
42
- gtmParams?: {
43
- item_category_id?: number | string;
44
- };
45
- }>;
33
+ lineItems: AddToCartLineItem[];
46
34
  gtmParams?: GtmParams;
47
35
  }) => void;
48
36
  /**
@@ -58,59 +46,26 @@ declare const trackBeginCheckoutGA: ({ lineItems, currencyCode, gtmParams, }: {
58
46
  * This triggers begin_checkout event for buy now actions
59
47
  */
60
48
  declare const trackBuyNowGA: ({ lineItems, gtmParams, }: {
61
- lineItems: Array<NormalizedLineItem & {
62
- gtmParams?: {
63
- item_category_id?: number | string;
64
- };
65
- }>;
49
+ lineItems: AddToCartLineItem[];
66
50
  gtmParams?: GtmParams;
67
51
  }) => void;
68
- /**
69
- * GA4 Data
70
- */
71
- interface GA4Data {
72
- clientId: string;
73
- sessionId: string;
74
- }
75
- /**
76
- * Wait for gtag to be ready
77
- */
78
- declare function waitForGtagReady(timeout?: number): Promise<void>;
79
- /**
80
- * Get GA4 client ID
81
- */
82
- declare const getGA4ClientId: (measurementId?: string) => Promise<string>;
83
- /**
84
- * Get GA4 session ID
85
- */
86
- declare const getGA4SessionId: (measurementId?: string) => Promise<string>;
87
- /**
88
- * Get GA4 data (client ID and session ID)
89
- */
90
- declare const getGA4Data: (measurementId?: string) => Promise<GA4Data>;
91
52
 
92
53
  /**
93
54
  * Facebook Pixel Tracking
94
55
  * FBQ event tracking utilities
95
56
  */
96
57
 
97
- type FbqCommand = 'track' | 'trackCustom' | 'trackSingle' | 'trackCustom';
98
- type FbqEventName = 'AddToCart' | 'Purchase' | 'InitiateCheckout' | 'ViewContent' | string;
99
- type FbqEventParams = Record<string, unknown>;
100
58
  declare global {
101
59
  interface Window {
102
- fbq?: (command: FbqCommand, eventName: FbqEventName, params?: FbqEventParams) => void;
60
+ fbq?: (...args: any[]) => void;
61
+ gtag?: (...args: any[]) => void;
103
62
  }
104
63
  }
105
64
  /**
106
65
  * Track add to cart event in Facebook Pixel
107
66
  */
108
- declare const trackAddToCartFBQ: ({ lineItems, }: {
109
- lineItems: Array<NormalizedLineItem & {
110
- gtmParams?: {
111
- item_category_id?: number | string;
112
- };
113
- }>;
67
+ declare const trackAddToCartFBQ: ({ lineItems }: {
68
+ lineItems: AddToCartLineItem[];
114
69
  }) => void;
115
70
  /**
116
71
  * Configuration for Buy Now tracking events
@@ -147,9 +102,6 @@ type AddToCartLineItem = {
147
102
  code: string;
148
103
  amount: number;
149
104
  };
150
- gtmParams?: {
151
- item_category_id?: number | string;
152
- };
153
105
  };
154
106
  interface AddToCartInput {
155
107
  /** Lines to add */
@@ -182,131 +134,6 @@ interface UseAddToCartOptions {
182
134
  withTrack?: boolean;
183
135
  }
184
136
 
185
- /**
186
- * Auto Remove Free Gifts Hook
187
- *
188
- * Automatically removes Function and Script free gifts from cart on page load.
189
- * This ensures gifts are only added at checkout time, not kept in cart permanently.
190
- *
191
- * Based on storefront-anker production implementation.
192
- */
193
-
194
- interface UseAutoRemoveFreeGiftsOptions {
195
- /**
196
- * Whether to remove Function gifts (with _discounts_function_env attribute)
197
- * @default true
198
- */
199
- removeFunctionGifts?: boolean;
200
- /**
201
- * Whether to remove Script gifts (with _giveaway_gradient_gifts attribute)
202
- * @default true
203
- */
204
- removeScriptGifts?: boolean;
205
- /**
206
- * Custom function to identify additional gift line items
207
- * @param line - Line item to check
208
- * @returns true if line item is a gift that should be removed
209
- */
210
- isGiftLineItem?: (line: NormalizedLineItem) => boolean;
211
- }
212
- interface UseAutoRemoveFreeGiftsResult {
213
- /** Whether removal is in progress */
214
- isRemoving: boolean;
215
- }
216
- /**
217
- * Automatically removes free gifts from cart on initialization
218
- *
219
- * Function满赠和Script满赠的赠品都会被添加到购物车,需要在返回购物车页面时自动删除。
220
- * - Function 赠品:带 _discounts_function_env 属性
221
- * - Script 赠品:带 _giveaway_gradient_gifts 属性
222
- *
223
- * @example
224
- * ```tsx
225
- * function CartPage() {
226
- * // Auto-remove all gifts on page load
227
- * useAutoRemoveFreeGifts()
228
- *
229
- * return <Cart />
230
- * }
231
- * ```
232
- *
233
- * @example
234
- * ```tsx
235
- * // Only remove Function gifts, keep Script gifts
236
- * useAutoRemoveFreeGifts({
237
- * removeFunctionGifts: true,
238
- * removeScriptGifts: false
239
- * })
240
- * ```
241
- *
242
- * @example
243
- * ```tsx
244
- * // Custom gift identification
245
- * useAutoRemoveFreeGifts({
246
- * isGiftLineItem: (line) => {
247
- * // Also remove other campaign gifts
248
- * return line.customAttributes?.some(
249
- * attr => attr.key === '_giveaway_summer_campaign'
250
- * )
251
- * }
252
- * })
253
- * ```
254
- */
255
- declare function useAutoRemoveFreeGifts(options?: UseAutoRemoveFreeGiftsOptions): UseAutoRemoveFreeGiftsResult;
256
- /**
257
- * Helper function to check if a line item is a Function gift
258
- */
259
- declare function isFunctionGift(line: NormalizedLineItem): boolean;
260
- /**
261
- * Helper function to check if a line item is a Script gift
262
- */
263
- declare function isScriptGift(line: NormalizedLineItem): boolean;
264
- /**
265
- * Helper function to check if a line item is a buy-get gift (买赠)
266
- */
267
- declare function isBuyGetGift(line: NormalizedLineItem): boolean;
268
- /**
269
- * Helper function to check if a line item is any type of gift
270
- */
271
- declare function isAnyGift(line: NormalizedLineItem): boolean;
272
-
273
- interface GiveawayProduct {
274
- handle: string;
275
- sku: string;
276
- }
277
- interface Breakpoint {
278
- breakpoint: string;
279
- giveawayProducts: GiveawayProduct[];
280
- }
281
- interface ScriptAutoFreeGiftConfig {
282
- activityAvailableQuery?: string;
283
- activityQroperty?: string;
284
- breakpoints?: Array<{
285
- breakpoint: string;
286
- giveawayProducts: GiveawayProduct[];
287
- }>;
288
- includeTags?: string[];
289
- useTotalAmount?: boolean;
290
- requireLogin?: boolean;
291
- }
292
- interface UseScriptAutoFreeGiftResult {
293
- involvedLines: NormalizedLineItem[];
294
- reorder: (a: NormalizedLineItem, b: NormalizedLineItem) => number;
295
- disableCodeRemove: boolean;
296
- nextFreeGiftLevel: Breakpoint | null;
297
- freeGiftLevel: Breakpoint | null;
298
- involvedSubTotal: Decimal;
299
- giftProductsResult?: NormalizedProduct[];
300
- }
301
- declare const useScriptAutoFreeGift: ({ campaign, _giveaway, cart, locale: providedLocale, lines, profile, }: {
302
- campaign?: ScriptAutoFreeGiftConfig;
303
- _giveaway: string;
304
- cart: NormalizedCart | undefined;
305
- locale?: string;
306
- lines?: AddToCartLineItem[];
307
- profile?: any;
308
- }) => UseScriptAutoFreeGiftResult;
309
-
310
137
  /**
311
138
  * Plus Member Types
312
139
  * Type definitions for Plus Member functionality
@@ -683,4 +510,4 @@ type DeliveryCustomData = {
683
510
  plus_type?: DeliveryPlusType;
684
511
  };
685
512
 
686
- export { type AddToCartLineItem as A, trackAddToCartFBQ as B, type BuyNowTrackConfig as C, DeliveryPlusType as D, trackBuyNowFBQ as E, type GtmParams as G, PLUS_MEMBER_TYPE as P, type ScriptAutoFreeGiftConfig as S, type UseAutoRemoveFreeGiftsOptions as U, type UseAutoRemoveFreeGiftsResult as a, isScriptGift as b, isBuyGetGift as c, isAnyGift as d, type UseScriptAutoFreeGiftResult as e, useScriptAutoFreeGift as f, type AddToCartInput as g, type UseAddToCartOptions as h, isFunctionGift as i, PlusMemberMode as j, ShippingMethodMode as k, type PlusMemberShippingMethodMetafields as l, type PlusMemberShippingMethodConfig as m, type PlusMemberSettingsMetafields as n, type SelectedPlusMemberVariant as o, type DeliveryCustomData as p, gaTrack as q, trackBeginCheckoutGA as r, trackBuyNowGA as s, trackAddToCartGA as t, useAutoRemoveFreeGifts as u, type GA4Data as v, waitForGtagReady as w, getGA4ClientId as x, getGA4SessionId as y, getGA4Data as z };
513
+ export { type AddToCartLineItem as A, type BuyNowTrackConfig as B, DeliveryPlusType as D, type GtmParams as G, PLUS_MEMBER_TYPE as P, ShippingMethodMode as S, type UseAddToCartOptions as U, type AddToCartInput as a, PlusMemberMode as b, type PlusMemberShippingMethodMetafields as c, type PlusMemberShippingMethodConfig as d, type PlusMemberSettingsMetafields as e, type SelectedPlusMemberVariant as f, type DeliveryCustomData as g, gaTrack as h, trackBeginCheckoutGA as i, trackBuyNowGA as j, trackAddToCartFBQ as k, trackBuyNowFBQ as l, trackAddToCartGA as t };