@tagadapay/plugin-sdk 2.8.9 → 3.0.1

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.
Files changed (54) hide show
  1. package/README.md +14 -14
  2. package/dist/index.js +1 -1
  3. package/dist/react/hooks/usePluginConfig.d.ts +1 -0
  4. package/dist/react/hooks/usePluginConfig.js +69 -18
  5. package/dist/react/providers/TagadaProvider.js +1 -4
  6. package/dist/v2/core/client.d.ts +22 -0
  7. package/dist/v2/core/client.js +90 -1
  8. package/dist/v2/core/config/environment.d.ts +24 -2
  9. package/dist/v2/core/config/environment.js +58 -25
  10. package/dist/v2/core/funnelClient.d.ts +84 -0
  11. package/dist/v2/core/funnelClient.js +252 -0
  12. package/dist/v2/core/index.d.ts +2 -0
  13. package/dist/v2/core/index.js +3 -0
  14. package/dist/v2/core/resources/apiClient.d.ts +5 -0
  15. package/dist/v2/core/resources/apiClient.js +47 -0
  16. package/dist/v2/core/resources/funnel.d.ts +8 -0
  17. package/dist/v2/core/resources/offers.d.ts +182 -8
  18. package/dist/v2/core/resources/offers.js +25 -0
  19. package/dist/v2/core/resources/products.d.ts +5 -0
  20. package/dist/v2/core/resources/products.js +15 -1
  21. package/dist/v2/core/types.d.ts +1 -0
  22. package/dist/v2/core/utils/funnelQueryKeys.d.ts +23 -0
  23. package/dist/v2/core/utils/funnelQueryKeys.js +23 -0
  24. package/dist/v2/core/utils/index.d.ts +2 -0
  25. package/dist/v2/core/utils/index.js +2 -0
  26. package/dist/v2/core/utils/pluginConfig.d.ts +1 -0
  27. package/dist/v2/core/utils/pluginConfig.js +84 -22
  28. package/dist/v2/core/utils/sessionStorage.d.ts +20 -0
  29. package/dist/v2/core/utils/sessionStorage.js +39 -0
  30. package/dist/v2/index.d.ts +3 -2
  31. package/dist/v2/index.js +1 -1
  32. package/dist/v2/react/components/ApplePayButton.js +1 -1
  33. package/dist/v2/react/hooks/__examples__/FunnelContextExample.d.ts +3 -0
  34. package/dist/v2/react/hooks/__examples__/FunnelContextExample.js +4 -3
  35. package/dist/v2/react/hooks/useClubOffers.d.ts +2 -2
  36. package/dist/v2/react/hooks/useFunnel.d.ts +27 -38
  37. package/dist/v2/react/hooks/useFunnel.js +22 -660
  38. package/dist/v2/react/hooks/useFunnelLegacy.d.ts +52 -0
  39. package/dist/v2/react/hooks/useFunnelLegacy.js +733 -0
  40. package/dist/v2/react/hooks/useOfferQuery.d.ts +109 -0
  41. package/dist/v2/react/hooks/useOfferQuery.js +483 -0
  42. package/dist/v2/react/hooks/useOffersQuery.d.ts +10 -58
  43. package/dist/v2/react/hooks/useOffersQuery.js +110 -8
  44. package/dist/v2/react/hooks/useProductsQuery.d.ts +1 -0
  45. package/dist/v2/react/hooks/useProductsQuery.js +10 -6
  46. package/dist/v2/react/index.d.ts +7 -4
  47. package/dist/v2/react/index.js +4 -2
  48. package/dist/v2/react/providers/TagadaProvider.d.ts +45 -2
  49. package/dist/v2/react/providers/TagadaProvider.js +116 -3
  50. package/dist/v2/standalone/index.d.ts +20 -0
  51. package/dist/v2/standalone/index.js +22 -0
  52. package/dist/v2/vue/index.d.ts +6 -0
  53. package/dist/v2/vue/index.js +10 -0
  54. package/package.json +6 -1
@@ -6,6 +6,13 @@ export class OffersResource {
6
6
  constructor(apiClient) {
7
7
  this.apiClient = apiClient;
8
8
  }
9
+ /**
10
+ * Get a single offer by ID
11
+ */
12
+ async getOfferById(offerId) {
13
+ const response = await this.apiClient.get(`/api/v1/offers/${offerId}`);
14
+ return response;
15
+ }
9
16
  /**
10
17
  * Get offers for a store
11
18
  */
@@ -77,6 +84,24 @@ export class OffersResource {
77
84
  });
78
85
  }
79
86
  /**
87
+ * Transform offer to checkout session with dynamic variant selection
88
+ * Uses lineItems from the offer to create a new checkout session
89
+ */
90
+ async transformToCheckoutSession(offerId, lineItems, mainOrderId, returnUrl) {
91
+ const response = await this.apiClient.post(`/api/v1/offers/${offerId}/transform-to-checkout`, {
92
+ offerId,
93
+ lineItems,
94
+ mainOrderId,
95
+ returnUrl: returnUrl || (typeof window !== 'undefined' ? window.location.origin : ''),
96
+ });
97
+ return {
98
+ checkoutUrl: response.checkoutUrl,
99
+ checkoutSessionId: response.checkoutSessionId,
100
+ customerId: response.customerId,
101
+ };
102
+ }
103
+ /**
104
+ * @deprecated Use transformToCheckoutSession instead
80
105
  * Transform offer to checkout session with dynamic variant selection
81
106
  */
82
107
  async transformToCheckout(offerId, returnUrl) {
@@ -7,6 +7,7 @@ import { ApiClient } from './apiClient';
7
7
  export interface GetProductsOptions {
8
8
  storeId: string;
9
9
  productIds?: string[];
10
+ variantIds?: string[];
10
11
  includeVariants?: boolean;
11
12
  includePrices?: boolean;
12
13
  }
@@ -26,4 +27,8 @@ export declare class ProductsResource {
26
27
  * Get multiple products by IDs
27
28
  */
28
29
  getProductsByIds(productIds: string[], options: GetProductsOptions): Promise<Product[]>;
30
+ /**
31
+ * Get products by variant IDs (efficient filtering on the backend)
32
+ */
33
+ getProductsByVariantIds(variantIds: string[], options: GetProductsOptions): Promise<Product[]>;
29
34
  }
@@ -10,9 +10,10 @@ export class ProductsResource {
10
10
  * Get all products for a store
11
11
  */
12
12
  async getProducts(options) {
13
- const { storeId, includeVariants = true, includePrices = true } = options;
13
+ const { storeId, variantIds, includeVariants = true, includePrices = true } = options;
14
14
  const response = await this.apiClient.post('/api/v1/products', {
15
15
  storeId,
16
+ variantIds,
16
17
  includeVariants,
17
18
  includePrices,
18
19
  });
@@ -46,4 +47,17 @@ export class ProductsResource {
46
47
  const results = await Promise.all(fetchPromises);
47
48
  return results.filter((product) => product !== null);
48
49
  }
50
+ /**
51
+ * Get products by variant IDs (efficient filtering on the backend)
52
+ */
53
+ async getProductsByVariantIds(variantIds, options) {
54
+ const { storeId, includeVariants = true, includePrices = true } = options;
55
+ const response = await this.apiClient.post('/api/v1/products', {
56
+ storeId,
57
+ variantIds, // Backend will filter products that have these variants
58
+ includeVariants,
59
+ includePrices,
60
+ });
61
+ return Array.isArray(response) ? response : response.items ?? [];
62
+ }
49
63
  }
@@ -60,6 +60,7 @@ export interface Currency {
60
60
  }
61
61
  export interface Store {
62
62
  id: string;
63
+ accountId: string;
63
64
  name: string;
64
65
  domain: string;
65
66
  currency: string;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Funnel Query Keys - Core SDK (Framework-agnostic)
3
+ * Standardized query keys for caching funnel data
4
+ * Can be used with any query library (TanStack Query, SWR, etc.)
5
+ */
6
+ /**
7
+ * Query keys for funnel operations
8
+ * These keys are used for caching and invalidation strategies
9
+ */
10
+ export declare const funnelQueryKeys: {
11
+ /**
12
+ * Key for a specific funnel session
13
+ */
14
+ session: (sessionId: string) => readonly ["funnel", "session", string];
15
+ /**
16
+ * Key for all funnel sessions
17
+ */
18
+ allSessions: () => readonly ["funnel", "sessions"];
19
+ /**
20
+ * Key for funnel metadata/configuration
21
+ */
22
+ funnelMeta: (funnelId: string) => readonly ["funnel", "meta", string];
23
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Funnel Query Keys - Core SDK (Framework-agnostic)
3
+ * Standardized query keys for caching funnel data
4
+ * Can be used with any query library (TanStack Query, SWR, etc.)
5
+ */
6
+ /**
7
+ * Query keys for funnel operations
8
+ * These keys are used for caching and invalidation strategies
9
+ */
10
+ export const funnelQueryKeys = {
11
+ /**
12
+ * Key for a specific funnel session
13
+ */
14
+ session: (sessionId) => ['funnel', 'session', sessionId],
15
+ /**
16
+ * Key for all funnel sessions
17
+ */
18
+ allSessions: () => ['funnel', 'sessions'],
19
+ /**
20
+ * Key for funnel metadata/configuration
21
+ */
22
+ funnelMeta: (funnelId) => ['funnel', 'meta', funnelId],
23
+ };
@@ -10,3 +10,5 @@ export * from './checkout';
10
10
  export * from './promotions';
11
11
  export * from './postPurchases';
12
12
  export * from './orderBump';
13
+ export * from './sessionStorage';
14
+ export * from './funnelQueryKeys';
@@ -10,3 +10,5 @@ export * from './checkout';
10
10
  export * from './promotions';
11
11
  export * from './postPurchases';
12
12
  export * from './orderBump';
13
+ export * from './sessionStorage';
14
+ export * from './funnelQueryKeys';
@@ -7,6 +7,7 @@ export type PluginConfig<TConfig = Record<string, any>> = {
7
7
  accountId?: string;
8
8
  basePath?: string;
9
9
  config?: any;
10
+ staticResources?: Record<string, any>;
10
11
  productId?: string;
11
12
  variants?: Record<string, string>;
12
13
  prices?: Record<string, any>;
@@ -2,6 +2,7 @@
2
2
  * Plugin Configuration Utility Functions
3
3
  * Pure functions for plugin configuration management
4
4
  */
5
+ import { isLocalEnvironment } from '../config/environment';
5
6
  import { resolveEnvValue } from './env';
6
7
  /**
7
8
  * Load local development configuration
@@ -14,14 +15,9 @@ const loadLocalDevConfig = async (configVariant = 'default') => {
14
15
  // Skip local config loading if explicitly in production mode
15
16
  return null;
16
17
  }
17
- // Only try to load local config in development
18
- // Use hostname-based detection for better Vite compatibility
19
- const isLocalDev = typeof window !== 'undefined' &&
20
- (window.location.hostname === 'localhost' ||
21
- window.location.hostname.includes('ngrok-free.app') ||
22
- window.location.hostname.includes('.localhost') ||
23
- window.location.hostname.includes('127.0.0.1'));
24
- if (!isLocalDev) {
18
+ // Only try to load local config in TRUE local development (not deployed CDN instances)
19
+ // Exclude CDN subdomains (e.g., instance-id.cdn.localhost)
20
+ if (!isLocalEnvironment(true)) {
25
21
  return null;
26
22
  }
27
23
  // Load local store/account config
@@ -87,6 +83,38 @@ const loadLocalDevConfig = async (configVariant = 'default') => {
87
83
  return null;
88
84
  }
89
85
  };
86
+ /**
87
+ * Load static resources for local development
88
+ * Loads /config/resources.static.json
89
+ */
90
+ const loadStaticResources = async () => {
91
+ try {
92
+ // Check for explicit environment override
93
+ const env = resolveEnvValue('TAGADA_ENV') || resolveEnvValue('TAGADA_ENVIRONMENT');
94
+ if (env === 'production') {
95
+ return null;
96
+ }
97
+ // Only try to load in TRUE local development (not deployed CDN instances)
98
+ // Exclude CDN subdomains (e.g., instance-id.cdn.localhost)
99
+ if (!isLocalEnvironment(true)) {
100
+ return null;
101
+ }
102
+ // Load static resources file
103
+ console.log('🛠️ [V2] Attempting to load /config/resources.static.json...');
104
+ const response = await fetch('/config/resources.static.json');
105
+ if (!response.ok) {
106
+ console.log('🛠️ [V2] resources.static.json not found or failed to load');
107
+ return null;
108
+ }
109
+ const staticResources = await response.json();
110
+ console.log('🛠️ [V2] ✅ Loaded local static resources:', staticResources);
111
+ return staticResources;
112
+ }
113
+ catch (error) {
114
+ console.error('🛠️ [V2] ❌ Error loading static resources:', error);
115
+ return null;
116
+ }
117
+ };
90
118
  /**
91
119
  * Helper to get content from meta tag
92
120
  */
@@ -143,28 +171,70 @@ const loadProductionConfig = async () => {
143
171
  * Handles local dev, production, and raw config
144
172
  */
145
173
  export const loadPluginConfig = async (configVariant = 'default', rawConfig) => {
174
+ console.log('🔧 [V2] loadPluginConfig called with variant:', configVariant);
175
+ // Load static resources first (only in local dev)
176
+ const staticResources = await loadStaticResources();
177
+ console.log('🔧 [V2] Static resources loaded:', {
178
+ hasStaticResources: !!staticResources,
179
+ staticResourcesKeys: staticResources ? Object.keys(staticResources) : [],
180
+ });
146
181
  // If raw config is provided, use it directly
147
182
  if (rawConfig) {
148
- return {
183
+ const result = {
149
184
  storeId: rawConfig.storeId,
150
185
  accountId: rawConfig.accountId,
151
186
  basePath: rawConfig.basePath ?? '/',
152
187
  config: rawConfig.config ?? {},
188
+ staticResources: staticResources ?? undefined,
153
189
  };
190
+ console.log('🔧 [V2] Final config (raw):', {
191
+ hasStoreId: !!result.storeId,
192
+ hasStaticResources: !!result.staticResources,
193
+ staticResourcesKeys: result.staticResources ? Object.keys(result.staticResources) : [],
194
+ });
195
+ return result;
154
196
  }
155
197
  else {
156
198
  const rawConfig = await createRawPluginConfig();
157
199
  if (rawConfig) {
158
- return rawConfig;
200
+ const result = {
201
+ ...rawConfig,
202
+ staticResources: staticResources ?? undefined,
203
+ };
204
+ console.log('🔧 [V2] Final config (createRawPluginConfig):', {
205
+ hasStoreId: !!result.storeId,
206
+ hasStaticResources: !!result.staticResources,
207
+ staticResourcesKeys: result.staticResources ? Object.keys(result.staticResources) : [],
208
+ });
209
+ return result;
159
210
  }
160
211
  }
161
212
  // Try local development config
162
213
  const localConfig = await loadLocalDevConfig(configVariant);
163
214
  if (localConfig) {
164
- return localConfig;
215
+ const result = {
216
+ ...localConfig,
217
+ staticResources: staticResources ?? undefined,
218
+ };
219
+ console.log('🔧 [V2] Final config (local):', {
220
+ hasStoreId: !!result.storeId,
221
+ hasStaticResources: !!result.staticResources,
222
+ staticResourcesKeys: result.staticResources ? Object.keys(result.staticResources) : [],
223
+ });
224
+ return result;
165
225
  }
166
226
  // Fall back to production config
167
- return loadProductionConfig();
227
+ const productionConfig = await loadProductionConfig();
228
+ const result = {
229
+ ...productionConfig,
230
+ staticResources: staticResources ?? undefined,
231
+ };
232
+ console.log('🔧 [V2] Final config (production):', {
233
+ hasStoreId: !!result.storeId,
234
+ hasStaticResources: !!result.staticResources,
235
+ staticResourcesKeys: result.staticResources ? Object.keys(result.staticResources) : [],
236
+ });
237
+ return result;
168
238
  };
169
239
  /**
170
240
  * Helper to load local config file for development (from /config directory)
@@ -173,11 +243,7 @@ export const loadPluginConfig = async (configVariant = 'default', rawConfig) =>
173
243
  export async function loadLocalConfig(configName = 'default', defaultConfig) {
174
244
  try {
175
245
  // Only load in localhost
176
- const isLocalhost = typeof window !== 'undefined' &&
177
- (window.location.hostname === 'localhost' ||
178
- window.location.hostname.includes('.localhost') ||
179
- window.location.hostname.includes('127.0.0.1'));
180
- if (!isLocalhost) {
246
+ if (!isLocalEnvironment()) {
181
247
  return null;
182
248
  }
183
249
  if (defaultConfig) {
@@ -217,11 +283,7 @@ export async function loadLocalConfig(configName = 'default', defaultConfig) {
217
283
  export async function createRawPluginConfig() {
218
284
  try {
219
285
  // Only run in true localhost - production should use meta tags
220
- const isLocalhost = typeof window !== 'undefined' &&
221
- (window.location.hostname === 'localhost' ||
222
- window.location.hostname.includes('.localhost') ||
223
- window.location.hostname.includes('127.0.0.1'));
224
- if (!isLocalhost) {
286
+ if (!isLocalEnvironment()) {
225
287
  console.log('[createRawPluginConfig] Not localhost, skipping - will use meta tags in production');
226
288
  return undefined;
227
289
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Session Storage Utilities - Core SDK (Framework-agnostic)
3
+ * Handles session persistence using browser cookies
4
+ */
5
+ /**
6
+ * Save funnel session ID to browser cookie
7
+ */
8
+ export declare function setFunnelSessionCookie(sessionId: string): void;
9
+ /**
10
+ * Retrieve funnel session ID from browser cookie
11
+ */
12
+ export declare function getFunnelSessionCookie(): string | undefined;
13
+ /**
14
+ * Clear funnel session cookie
15
+ */
16
+ export declare function clearFunnelSessionCookie(): void;
17
+ /**
18
+ * Check if a funnel session cookie exists
19
+ */
20
+ export declare function hasFunnelSessionCookie(): boolean;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Session Storage Utilities - Core SDK (Framework-agnostic)
3
+ * Handles session persistence using browser cookies
4
+ */
5
+ const FUNNEL_SESSION_COOKIE_NAME = 'tgd-funnel-session-id';
6
+ const SESSION_MAX_AGE = 30 * 24 * 60 * 60; // 30 days
7
+ /**
8
+ * Save funnel session ID to browser cookie
9
+ */
10
+ export function setFunnelSessionCookie(sessionId) {
11
+ if (typeof document === 'undefined')
12
+ return;
13
+ document.cookie = `${FUNNEL_SESSION_COOKIE_NAME}=${sessionId}; path=/; max-age=${SESSION_MAX_AGE}; SameSite=Lax`;
14
+ }
15
+ /**
16
+ * Retrieve funnel session ID from browser cookie
17
+ */
18
+ export function getFunnelSessionCookie() {
19
+ if (typeof document === 'undefined')
20
+ return undefined;
21
+ const cookie = document.cookie
22
+ .split('; ')
23
+ .find((row) => row.startsWith(`${FUNNEL_SESSION_COOKIE_NAME}=`));
24
+ return cookie ? cookie.split('=')[1] : undefined;
25
+ }
26
+ /**
27
+ * Clear funnel session cookie
28
+ */
29
+ export function clearFunnelSessionCookie() {
30
+ if (typeof document === 'undefined')
31
+ return;
32
+ document.cookie = `${FUNNEL_SESSION_COOKIE_NAME}=; path=/; max-age=0`;
33
+ }
34
+ /**
35
+ * Check if a funnel session cookie exists
36
+ */
37
+ export function hasFunnelSessionCookie() {
38
+ return !!getFunnelSessionCookie();
39
+ }
@@ -14,7 +14,7 @@ export * from './core/pathRemapping';
14
14
  export type { CheckoutData, CheckoutInitParams, CheckoutLineItem, CheckoutSession, CheckoutSessionPreview, Promotion } from './core/resources/checkout';
15
15
  export type { Order, OrderLineItem } from './core/utils/order';
16
16
  export type { PostPurchaseOffer, PostPurchaseOfferItem, PostPurchaseOfferSummary } from './core/resources/postPurchases';
17
- export type { Offer, OfferItem, OfferSummary } from './core/resources/offers';
17
+ export type { Offer, OfferSummary, OfferSummaryItem } from './core/resources/offers';
18
18
  export type { OrderBumpOffer, OrderBumpPreview } from './core/utils/orderBump';
19
19
  export type { ApplePayToken, CardPaymentMethod, Payment, PaymentInstrumentCustomer, PaymentInstrumentCustomerResponse, PaymentInstrumentResponse, PaymentOptions, PaymentResponse } from './core/resources/payments';
20
20
  export type { ShippingRate, ShippingRatesResponse } from './core/resources/shippingRates';
@@ -23,8 +23,9 @@ export type { ToggleOrderBumpResponse, VipOffer, VipPreviewResponse } from './co
23
23
  export type { StoreConfig } from './core/resources/storeConfig';
24
24
  export { FunnelActionType } from './core/resources/funnel';
25
25
  export type { BackNavigationActionData, CartUpdatedActionData, DirectNavigationActionData, FormSubmitActionData, FunnelContextUpdateRequest, FunnelContextUpdateResponse, FunnelAction as FunnelEvent, FunnelInitializeRequest, FunnelInitializeResponse, FunnelNavigateRequest, FunnelNavigateResponse, FunnelNavigationAction, FunnelNavigationResult, NextAction, OfferAcceptedActionData, OfferDeclinedActionData, PaymentFailedActionData, PaymentSuccessActionData, SimpleFunnelContext } from './core/resources/funnel';
26
- export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useAuth, useCheckout, useCheckoutToken, useClubOffers, useCountryOptions, useCredits, useCurrency, useCustomer, useCustomerInfos, useCustomerOrders, useCustomerSubscriptions, useDiscounts, useExpressPaymentMethods, useFunnel, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useLogin, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useRemappableParams, useShippingRates, useSimpleFunnel, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useTranslation, useVipOffers } from './react';
26
+ export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useAuth, useCheckout, useCheckoutToken, useClubOffers, useCountryOptions, useCredits, useCurrency, useCustomer, useCustomerInfos, useCustomerOrders, useCustomerSubscriptions, useDiscounts, useExpressPaymentMethods, useFunnel, useFunnelLegacy, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useLogin, useOffer, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useRemappableParams, useShippingRates, useSimpleFunnel, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useTranslation, useVipOffers } from './react';
27
27
  export type { TranslateFunction, TranslationText, UseTranslationOptions, UseTranslationResult } from './react/hooks/useTranslation';
28
+ export type { FunnelContextValue } from './react/hooks/useFunnel';
28
29
  export type { ClubOffer, ClubOfferItem, ClubOfferLineItem, ClubOfferSummary, UseClubOffersOptions, UseClubOffersResult } from './react/hooks/useClubOffers';
29
30
  export type { UseCreditsOptions, UseCreditsResult } from './react/hooks/useCredits';
30
31
  export type { UseLoginOptions, UseLoginResult } from './react/hooks/useLogin';
package/dist/v2/index.js CHANGED
@@ -15,4 +15,4 @@ export * from './core/utils/products';
15
15
  export * from './core/pathRemapping';
16
16
  export { FunnelActionType } from './core/resources/funnel';
17
17
  // React exports (hooks and components only, types are exported above)
18
- export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useAuth, useCheckout, useCheckoutToken, useClubOffers, useCountryOptions, useCredits, useCurrency, useCustomer, useCustomerInfos, useCustomerOrders, useCustomerSubscriptions, useDiscounts, useExpressPaymentMethods, useFunnel, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useLogin, useOffers, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useRemappableParams, useShippingRates, useSimpleFunnel, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useTranslation, useVipOffers } from './react';
18
+ export { ApplePayButton, ExpressPaymentMethodsProvider, formatMoney, getAvailableLanguages, GooglePayButton, queryKeys, TagadaProvider, useApiMutation, useApiQuery, useAuth, useCheckout, useCheckoutToken, useClubOffers, useCountryOptions, useCredits, useCurrency, useCustomer, useCustomerInfos, useCustomerOrders, useCustomerSubscriptions, useDiscounts, useExpressPaymentMethods, useFunnel, useFunnelLegacy, useGeoLocation, useGoogleAutocomplete, useInvalidateQuery, useISOData, useLanguageImport, useLogin, useOffer, useOrder, useOrderBump, usePayment, usePluginConfig, usePostPurchases, usePreloadQuery, useProducts, usePromotions, useRegionOptions, useRemappableParams, useShippingRates, useSimpleFunnel, useStoreConfig, useTagadaContext, useThreeds, useThreedsModal, useTranslation, useVipOffers } from './react';
@@ -5,7 +5,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
5
  */
6
6
  import { useCallback, useEffect, useState } from 'react';
7
7
  import { useExpressPaymentMethods } from '../hooks/useExpressPaymentMethods';
8
- export const ApplePayButton = ({ className = '', disabled = false, onSuccess, onError, onCancel, storeName, currencyCode = 'USD', variant = 'outline', size = 'lg', checkout, }) => {
8
+ export const ApplePayButton = ({ className = '', disabled = false, onSuccess, onError, onCancel, storeName, currencyCode = 'USD', variant = 'default', size = 'lg', checkout, }) => {
9
9
  const { applePayPaymentMethod, shippingMethods, lineItems, handleAddExpressId, updateCheckoutSessionValues, updateCustomerEmail, reComputeOrderSummary, setError: setContextError, } = useExpressPaymentMethods();
10
10
  const [processingPayment, setProcessingPayment] = useState(false);
11
11
  const [isApplePayAvailable, setIsApplePayAvailable] = useState(false);
@@ -3,6 +3,9 @@
3
3
  *
4
4
  * This example demonstrates how to access data from previous steps
5
5
  * using the funnel context, including order, customer, and other resources.
6
+ *
7
+ * Note: Funnel initialization is now configured at the provider level:
8
+ * <TagadaProvider autoInitializeFunnel={true} funnelId="...">
6
9
  */
7
10
  export declare function FunnelContextExample(): import("react/jsx-runtime").JSX.Element;
8
11
  /**
@@ -4,12 +4,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
4
  *
5
5
  * This example demonstrates how to access data from previous steps
6
6
  * using the funnel context, including order, customer, and other resources.
7
+ *
8
+ * Note: Funnel initialization is now configured at the provider level:
9
+ * <TagadaProvider autoInitializeFunnel={true} funnelId="...">
7
10
  */
8
11
  import { useFunnel } from '../useFunnel';
9
12
  export function FunnelContextExample() {
10
- const { context, isLoading, isInitialized } = useFunnel({
11
- autoInitialize: true,
12
- });
13
+ const { context, isLoading, isInitialized } = useFunnel();
13
14
  if (isLoading) {
14
15
  return _jsx("div", { children: "Loading funnel session..." });
15
16
  }
@@ -9,7 +9,7 @@ export interface ClubOfferItem {
9
9
  variant: {
10
10
  name: string;
11
11
  description: string;
12
- imageUrl: string;
12
+ imageUrl: string | null;
13
13
  grams: number;
14
14
  };
15
15
  unitAmount: number;
@@ -31,7 +31,7 @@ export interface ClubOfferLineItem {
31
31
  id: string;
32
32
  name: string;
33
33
  description: string | null;
34
- imageUrl: string;
34
+ imageUrl: string | null;
35
35
  grams: number;
36
36
  product: {
37
37
  id: string;
@@ -1,51 +1,40 @@
1
1
  /**
2
- * useFunnel Hook (v2) - TanStack Query-based funnel navigation
2
+ * useFunnel Hook - Access funnel state and navigation methods
3
3
  *
4
- * Modern implementation using TanStack Query for state management
5
- * and the v2 ApiClient for API calls.
4
+ * This hook consumes the funnel state from TagadaProvider. All complex
5
+ * initialization and session management is handled at the provider level.
6
+ *
7
+ * Usage:
8
+ * ```tsx
9
+ * // In your root component or layout:
10
+ * <TagadaProvider funnelId="funnelv2_xxx" autoInitializeFunnel={true}>
11
+ * <YourApp />
12
+ * </TagadaProvider>
13
+ *
14
+ * // In any child component:
15
+ * const { context, next, isLoading } = useFunnel();
16
+ * ```
6
17
  */
7
18
  import { FunnelAction, FunnelNavigationResult, SimpleFunnelContext } from '../../core/resources/funnel';
8
- export interface UseFunnelOptions {
9
- funnelId?: string;
10
- currentStepId?: string;
11
- onNavigate?: (result: FunnelNavigationResult) => void | boolean;
12
- onError?: (error: Error) => void;
13
- autoInitialize?: boolean;
14
- enabled?: boolean;
15
- }
16
- export interface UseFunnelResult {
17
- next: (event: FunnelAction) => Promise<any>;
18
- goToStep: (stepId: string) => Promise<any>;
19
- updateContext: (updates: Partial<SimpleFunnelContext>) => Promise<void>;
19
+ import { FunnelState } from '../../core/funnelClient';
20
+ export interface FunnelContextValue extends FunnelState {
20
21
  currentStep: {
21
22
  id: string;
22
- };
23
- context: SimpleFunnelContext | null;
24
- isLoading: boolean;
25
- isInitialized: boolean;
23
+ } | null;
24
+ next: (event: FunnelAction) => Promise<FunnelNavigationResult>;
25
+ goToStep: (stepId: string) => Promise<FunnelNavigationResult>;
26
+ updateContext: (updates: Partial<SimpleFunnelContext>) => Promise<void>;
26
27
  initializeSession: (entryStepId?: string) => Promise<void>;
27
28
  endSession: () => Promise<void>;
28
29
  retryInitialization: () => Promise<void>;
29
- initializationError: Error | null;
30
- isSessionLoading: boolean;
31
- sessionError: Error | null;
32
- refetch: () => void;
30
+ refetch: () => Promise<void>;
33
31
  }
34
32
  /**
35
- * React Hook for Funnel Navigation (Plugin SDK v2)
33
+ * Hook to access funnel state and methods
36
34
  *
37
- * Modern funnel navigation using TanStack Query for state management
38
- * and the v2 ApiClient architecture.
39
- */
40
- export declare function useFunnel(options?: UseFunnelOptions): UseFunnelResult;
41
- /**
42
- * Simplified funnel hook for basic step tracking (v2)
35
+ * This hook simply returns the funnel state from TagadaProvider.
36
+ * All complex logic is handled at the provider level.
37
+ *
38
+ * @returns FunnelContextValue with state and methods
43
39
  */
44
- export declare function useSimpleFunnel(funnelId: string, initialStepId?: string): {
45
- currentStepId: string;
46
- next: (event: FunnelAction) => Promise<any>;
47
- goToStep: (stepId: string) => Promise<any>;
48
- isLoading: boolean;
49
- context: SimpleFunnelContext<{}> | null;
50
- };
51
- export type { FunnelAction as FunnelEvent, FunnelNavigationAction, FunnelNavigationResult, SimpleFunnelContext } from '../../core/resources/funnel';
40
+ export declare function useFunnel(): FunnelContextValue;