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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,10 @@
1
1
  import * as React from 'react';
2
2
  import React__default from 'react';
3
- import { ShopifyClient, ShopifyConfig, CartCookieAdapter as CartCookieAdapter$1, NormalizedCart, HasMetafieldsIdentifier } from '@anker-in/shopify-sdk';
4
- import { C as CookieAdapter, b as CartCookieAdapter, R as RouterAdapter, U as UserContextAdapter } from '../types-BLMoxbOk.mjs';
3
+ import { ShopifyClient, ShopifyConfig, CartCookieAdapter, NormalizedCart, AttributeInput, HasMetafieldsIdentifier } from '@anker-in/shopify-sdk';
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 { e as PlusMemberSettingsMetafields } from '../types-CICUnw0v.mjs';
8
- import 'swr/mutation';
7
+ import { e as PlusMemberSettingsMetafields } from '../types-CMMWxyUF.mjs';
9
8
 
10
9
  interface ShopifyContextValue {
11
10
  client: ShopifyClient;
@@ -16,6 +15,7 @@ interface ShopifyContextValue {
16
15
  cartCookieAdapter: CartCookieAdapter;
17
16
  routerAdapter?: RouterAdapter;
18
17
  userAdapter?: UserContextAdapter;
18
+ performanceAdapter?: PerformanceAdapter;
19
19
  }
20
20
  declare const ShopifyContext: React.Context<ShopifyContextValue | null>;
21
21
 
@@ -24,16 +24,17 @@ interface ShopifyProviderProps {
24
24
  locale: string;
25
25
  locales?: string[];
26
26
  cookieAdapter?: CookieAdapter;
27
- cartCookieAdapter?: CartCookieAdapter$1;
27
+ cartCookieAdapter?: CartCookieAdapter;
28
28
  routerAdapter?: RouterAdapter;
29
29
  userAdapter?: UserContextAdapter;
30
30
  children: React__default.ReactNode;
31
+ performanceAdapter?: PerformanceAdapter;
31
32
  }
32
33
  /**
33
34
  * Shopify Provider Component
34
35
  * Provides Shopify context to all child components
35
36
  */
36
- declare function ShopifyProvider({ config, locale, locales, cookieAdapter, cartCookieAdapter, routerAdapter, userAdapter, children, }: ShopifyProviderProps): react_jsx_runtime.JSX.Element;
37
+ declare function ShopifyProvider({ config, locale, locales, cookieAdapter, cartCookieAdapter, routerAdapter, userAdapter, children, performanceAdapter, }: ShopifyProviderProps): react_jsx_runtime.JSX.Element;
37
38
 
38
39
  /**
39
40
  * Hook to access Shopify context
@@ -41,10 +42,6 @@ declare function ShopifyProvider({ config, locale, locales, cookieAdapter, cartC
41
42
  */
42
43
  declare function useShopify(): ShopifyContextValue;
43
44
 
44
- type AttributeInput = {
45
- key: string;
46
- value: string;
47
- };
48
45
  type LoadingState = {
49
46
  editLineQuantityLoading: boolean;
50
47
  editLineCodeAmountLoading: boolean;
@@ -54,6 +51,8 @@ type LoadingState = {
54
51
  interface CartContextValue {
55
52
  /** Current cart data */
56
53
  cart: NormalizedCart | undefined;
54
+ /** Total quantity of items in cart */
55
+ totalQuantity: number;
57
56
  /** Whether cart is loading */
58
57
  isCartLoading: boolean;
59
58
  /** Manually trigger cart fetch */
@@ -66,8 +65,6 @@ interface CartContextValue {
66
65
  removeCustomAttributes: (attributes: {
67
66
  key: string;
68
67
  }[]) => void;
69
- /** Set custom attributes */
70
- setCustomAttributes: (attributes: AttributeInput[]) => void;
71
68
  /** Current locale */
72
69
  locale: string;
73
70
  /** Whether discount code is changing */
@@ -103,6 +100,12 @@ interface CartContextValue {
103
100
  variant: HasMetafieldsIdentifier[];
104
101
  product: HasMetafieldsIdentifier[];
105
102
  };
103
+ /** User profile */
104
+ profile?: any;
105
+ /** Customer data */
106
+ customer?: any;
107
+ /** Plus member settings */
108
+ memberSetting?: PlusMemberSettingsMetafields;
106
109
  }
107
110
  interface CartProviderProps {
108
111
  children: React__default.ReactNode;
@@ -151,14 +154,25 @@ declare function CartProvider({ children, autoFreeGiftConfig, gradientGiftsConfi
151
154
  /**
152
155
  * Hook to access cart context
153
156
  *
154
- * @throws Error if used outside CartProvider
155
- * @returns Cart context value
157
+ * @param options - Optional configuration
158
+ * @param options.optional - If true, returns undefined instead of throwing error when used outside provider
159
+ * @throws Error if used outside CartProvider (unless optional is true)
160
+ * @returns Cart context value (or undefined if optional is true and no provider exists)
156
161
  *
157
162
  * @example
158
163
  * ```tsx
159
164
  * const { cart, mutateCart, isCartLoading, loadingState } = useCartContext()
165
+ *
166
+ * // Optional usage (safe for SSR)
167
+ * const cartContext = useCartContext({ optional: true })
168
+ * if (cartContext) {
169
+ * const { cart } = cartContext
170
+ * }
160
171
  * ```
161
172
  */
162
173
  declare function useCartContext(): CartContextValue;
174
+ declare function useCartContext(options: {
175
+ optional: true;
176
+ }): CartContextValue | null;
163
177
 
164
- export { type AttributeInput, 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,11 +1,10 @@
1
1
  import * as React from 'react';
2
2
  import React__default from 'react';
3
- import { ShopifyClient, ShopifyConfig, CartCookieAdapter as CartCookieAdapter$1, NormalizedCart, HasMetafieldsIdentifier } from '@anker-in/shopify-sdk';
4
- import { C as CookieAdapter, b as CartCookieAdapter, R as RouterAdapter, U as UserContextAdapter } from '../types-BLMoxbOk.js';
3
+ import { ShopifyClient, ShopifyConfig, CartCookieAdapter, NormalizedCart, AttributeInput, HasMetafieldsIdentifier } from '@anker-in/shopify-sdk';
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 { e as PlusMemberSettingsMetafields } from '../types-CICUnw0v.js';
8
- import 'swr/mutation';
7
+ import { e as PlusMemberSettingsMetafields } from '../types-CMMWxyUF.js';
9
8
 
10
9
  interface ShopifyContextValue {
11
10
  client: ShopifyClient;
@@ -16,6 +15,7 @@ interface ShopifyContextValue {
16
15
  cartCookieAdapter: CartCookieAdapter;
17
16
  routerAdapter?: RouterAdapter;
18
17
  userAdapter?: UserContextAdapter;
18
+ performanceAdapter?: PerformanceAdapter;
19
19
  }
20
20
  declare const ShopifyContext: React.Context<ShopifyContextValue | null>;
21
21
 
@@ -24,16 +24,17 @@ interface ShopifyProviderProps {
24
24
  locale: string;
25
25
  locales?: string[];
26
26
  cookieAdapter?: CookieAdapter;
27
- cartCookieAdapter?: CartCookieAdapter$1;
27
+ cartCookieAdapter?: CartCookieAdapter;
28
28
  routerAdapter?: RouterAdapter;
29
29
  userAdapter?: UserContextAdapter;
30
30
  children: React__default.ReactNode;
31
+ performanceAdapter?: PerformanceAdapter;
31
32
  }
32
33
  /**
33
34
  * Shopify Provider Component
34
35
  * Provides Shopify context to all child components
35
36
  */
36
- declare function ShopifyProvider({ config, locale, locales, cookieAdapter, cartCookieAdapter, routerAdapter, userAdapter, children, }: ShopifyProviderProps): react_jsx_runtime.JSX.Element;
37
+ declare function ShopifyProvider({ config, locale, locales, cookieAdapter, cartCookieAdapter, routerAdapter, userAdapter, children, performanceAdapter, }: ShopifyProviderProps): react_jsx_runtime.JSX.Element;
37
38
 
38
39
  /**
39
40
  * Hook to access Shopify context
@@ -41,10 +42,6 @@ declare function ShopifyProvider({ config, locale, locales, cookieAdapter, cartC
41
42
  */
42
43
  declare function useShopify(): ShopifyContextValue;
43
44
 
44
- type AttributeInput = {
45
- key: string;
46
- value: string;
47
- };
48
45
  type LoadingState = {
49
46
  editLineQuantityLoading: boolean;
50
47
  editLineCodeAmountLoading: boolean;
@@ -54,6 +51,8 @@ type LoadingState = {
54
51
  interface CartContextValue {
55
52
  /** Current cart data */
56
53
  cart: NormalizedCart | undefined;
54
+ /** Total quantity of items in cart */
55
+ totalQuantity: number;
57
56
  /** Whether cart is loading */
58
57
  isCartLoading: boolean;
59
58
  /** Manually trigger cart fetch */
@@ -66,8 +65,6 @@ interface CartContextValue {
66
65
  removeCustomAttributes: (attributes: {
67
66
  key: string;
68
67
  }[]) => void;
69
- /** Set custom attributes */
70
- setCustomAttributes: (attributes: AttributeInput[]) => void;
71
68
  /** Current locale */
72
69
  locale: string;
73
70
  /** Whether discount code is changing */
@@ -103,6 +100,12 @@ interface CartContextValue {
103
100
  variant: HasMetafieldsIdentifier[];
104
101
  product: HasMetafieldsIdentifier[];
105
102
  };
103
+ /** User profile */
104
+ profile?: any;
105
+ /** Customer data */
106
+ customer?: any;
107
+ /** Plus member settings */
108
+ memberSetting?: PlusMemberSettingsMetafields;
106
109
  }
107
110
  interface CartProviderProps {
108
111
  children: React__default.ReactNode;
@@ -151,14 +154,25 @@ declare function CartProvider({ children, autoFreeGiftConfig, gradientGiftsConfi
151
154
  /**
152
155
  * Hook to access cart context
153
156
  *
154
- * @throws Error if used outside CartProvider
155
- * @returns Cart context value
157
+ * @param options - Optional configuration
158
+ * @param options.optional - If true, returns undefined instead of throwing error when used outside provider
159
+ * @throws Error if used outside CartProvider (unless optional is true)
160
+ * @returns Cart context value (or undefined if optional is true and no provider exists)
156
161
  *
157
162
  * @example
158
163
  * ```tsx
159
164
  * const { cart, mutateCart, isCartLoading, loadingState } = useCartContext()
165
+ *
166
+ * // Optional usage (safe for SSR)
167
+ * const cartContext = useCartContext({ optional: true })
168
+ * if (cartContext) {
169
+ * const { cart } = cartContext
170
+ * }
160
171
  * ```
161
172
  */
162
173
  declare function useCartContext(): CartContextValue;
174
+ declare function useCartContext(options: {
175
+ optional: true;
176
+ }): CartContextValue | null;
163
177
 
164
- export { type AttributeInput, 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 };