@tagadapay/plugin-sdk 2.4.38 → 2.4.39

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,40 +1,11 @@
1
1
  import { useCallback, useEffect, useRef, useState } from 'react';
2
2
  import { useCurrency } from '../hooks/useCurrency';
3
- import { useTagadaContextSafe } from '../providers/TagadaProvider';
3
+ import { useTagadaContext } from '../providers/TagadaProvider';
4
4
  import { collectTrackingData } from '../utils/trackingUtils';
5
5
  import { usePluginConfig } from './usePluginConfig';
6
6
  export function useCheckout(options = {}) {
7
- const context = useTagadaContextSafe();
7
+ const { apiService, updateCheckoutDebugData, refreshCoordinator, currency, isSessionInitialized } = useTagadaContext();
8
8
  const { storeId } = usePluginConfig();
9
- // If context is not ready yet, return loading state
10
- if (!context) {
11
- return {
12
- checkout: null,
13
- error: null,
14
- isLoading: true,
15
- isInitialized: false,
16
- initialized: false,
17
- init: async () => ({ checkoutUrl: '', checkoutSession: {}, checkoutToken: '' }),
18
- getCheckout: async () => ({}),
19
- refresh: async () => { },
20
- updateAddress: async () => ({ success: false, shippingCountryChanged: false, billingCountryChanged: false }),
21
- setCheckoutInfo: async () => ({ success: false }),
22
- applyPromotionCode: async () => ({ success: false }),
23
- removePromotion: async () => ({ success: false }),
24
- getAppliedPromotions: async () => [],
25
- updateLineItems: async () => ({ success: false }),
26
- addLineItems: async () => ({ success: false }),
27
- removeLineItems: async () => ({ success: false }),
28
- setItemQuantity: async () => ({ success: false }),
29
- toggleOrderBump: async () => ({ success: false }),
30
- updateCustomer: async () => ({ success: false }),
31
- updateCustomerAndSessionInfo: async () => ({ success: false }),
32
- previewOrderSummary: async () => ({ savings: 0, savingsPct: 0, currency: 'USD' }),
33
- previewCheckoutSession: async () => ({ success: false, preview: {} }),
34
- clear: () => { },
35
- };
36
- }
37
- const { apiService, updateCheckoutDebugData, refreshCoordinator, currency, isSessionInitialized } = context;
38
9
  const { code: currentCurrency } = useCurrency();
39
10
  const [checkout, setCheckout] = useState(null);
40
11
  const [isLoading, setIsLoading] = useState(false);
@@ -1,21 +1,7 @@
1
1
  import { useState, useCallback, useEffect } from 'react';
2
- import { useTagadaContextSafe } from '../providers/TagadaProvider';
2
+ import { useTagadaContext } from '../providers/TagadaProvider';
3
3
  export function useOrderBump(options) {
4
- const context = useTagadaContextSafe();
5
- // If context is not ready yet, return loading state
6
- if (!context) {
7
- return {
8
- isSelected: false,
9
- preview: null,
10
- savings: null,
11
- isLoading: false,
12
- isToggling: false,
13
- error: null,
14
- toggle: async () => ({ success: false }),
15
- refreshPreview: async () => { },
16
- };
17
- }
18
- const { apiService, refreshCoordinator } = context;
4
+ const { apiService, refreshCoordinator } = useTagadaContext();
19
5
  const { checkoutSessionId, offerId, orderBumpType = 'vip', autoPreview = true } = options;
20
6
  const [isSelected, setIsSelected] = useState(false);
21
7
  const [preview, setPreview] = useState(null);
@@ -83,7 +83,7 @@ export interface PaymentInstrumentCustomer {
83
83
  token: string;
84
84
  isDefault: boolean;
85
85
  isActive: boolean;
86
- metadata: {};
86
+ metadata: Record<string, unknown>;
87
87
  customerId: string;
88
88
  accountId: string;
89
89
  createdAt: string;
@@ -1,7 +1,7 @@
1
1
  import { useBasisTheory } from '@basis-theory/basis-theory-react';
2
2
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { getBasisTheoryApiKey } from '../config/payment';
4
- import { useTagadaContextSafe } from '../providers/TagadaProvider';
4
+ import { useTagadaContext } from '../providers/TagadaProvider';
5
5
  import { usePaymentPolling } from './usePaymentPolling';
6
6
  import { useThreeds } from './useThreeds';
7
7
  // Helper function to format expiry date
@@ -16,23 +16,7 @@ const getCardMonthAndYear = (expiryDate) => {
16
16
  };
17
17
  };
18
18
  export function usePayment() {
19
- const context = useTagadaContextSafe();
20
- // If context is not ready yet, return loading state
21
- if (!context) {
22
- return {
23
- processCardPayment: async () => ({ paymentId: '', payment: {} }),
24
- processApplePayPayment: async () => ({ paymentId: '', payment: {} }),
25
- processPaymentWithInstrument: async () => ({ paymentId: '', payment: {} }),
26
- createCardPaymentInstrument: async () => ({ id: '', token: '', type: 'card' }),
27
- createApplePayPaymentInstrument: async () => ({ id: '', token: '', type: 'apple_pay' }),
28
- getCardPaymentInstruments: async () => [],
29
- isLoading: false,
30
- error: null,
31
- clearError: () => { },
32
- currentPaymentId: null,
33
- };
34
- }
35
- const { apiService, environment } = context;
19
+ const { apiService, environment } = useTagadaContext();
36
20
  const [isLoading, setIsLoading] = useState(false);
37
21
  const [error, setError] = useState(null);
38
22
  const [currentPaymentId, setCurrentPaymentId] = useState(null);
@@ -18,7 +18,7 @@
18
18
  * - Headers for store/account info
19
19
  * - Meta tags for deployment config
20
20
  */
21
- import { useTagadaContextSafe } from '../providers/TagadaProvider';
21
+ import { useTagadaContext } from '../providers/TagadaProvider';
22
22
  // Simple cache for plugin configuration
23
23
  let cachedConfig = null;
24
24
  let configPromise = null;
@@ -161,18 +161,7 @@ export const loadPluginConfig = async (configVariant = 'default', rawConfig) =>
161
161
  * Gets config from TagadaProvider context (no parameters needed)
162
162
  */
163
163
  export const usePluginConfig = () => {
164
- const context = useTagadaContextSafe();
165
- // If context is not ready yet, return loading state
166
- if (!context) {
167
- return {
168
- storeId: undefined,
169
- accountId: undefined,
170
- basePath: '/',
171
- config: {},
172
- loading: true,
173
- };
174
- }
175
- const { pluginConfig, pluginConfigLoading } = context;
164
+ const { pluginConfig, pluginConfigLoading } = useTagadaContext();
176
165
  return {
177
166
  storeId: pluginConfig.storeId,
178
167
  accountId: pluginConfig.accountId,
@@ -1,23 +1,9 @@
1
1
  import { useCallback, useEffect, useMemo, useState } from 'react';
2
- import { useTagadaContextSafe } from '../providers/TagadaProvider';
2
+ import { useTagadaContext } from '../providers/TagadaProvider';
3
3
  import { usePluginConfig } from './usePluginConfig';
4
4
  export function useProducts(options = {}) {
5
- const context = useTagadaContextSafe();
5
+ const { apiService } = useTagadaContext();
6
6
  const { storeId } = usePluginConfig();
7
- // If context is not ready yet, return loading state
8
- if (!context) {
9
- return {
10
- products: [],
11
- isLoading: true,
12
- error: null,
13
- getVariant: () => undefined,
14
- getProduct: () => undefined,
15
- getAllVariants: () => [],
16
- filterVariants: () => [],
17
- refetch: async () => { },
18
- };
19
- }
20
- const { apiService } = context;
21
7
  const [products, setProducts] = useState([]);
22
8
  const [isLoading, setIsLoading] = useState(false);
23
9
  const [error, setError] = useState(null);
@@ -22,7 +22,7 @@ export { useShippingRates } from './hooks/useShippingRates';
22
22
  export type { UseShippingRatesOptions, UseShippingRatesResult } from './hooks/useShippingRates';
23
23
  export { useTranslations } from './hooks/useTranslations';
24
24
  export { useVipOffers } from './hooks/useVipOffers';
25
- export { useTagadaContext, useTagadaContextSafe } from './providers/TagadaProvider';
25
+ export { useTagadaContext } from './providers/TagadaProvider';
26
26
  export { clearPluginConfigCache, debugPluginConfig, getPluginConfig, useBasePath, usePluginConfig } from './hooks/usePluginConfig';
27
27
  export type { PluginConfig } from './hooks/usePluginConfig';
28
28
  export { getAvailableLanguages, useCountryOptions, useISOData, useRegionOptions, useLanguageImport } from './hooks/useISOData';
@@ -24,7 +24,7 @@ export { useSession } from './hooks/useSession';
24
24
  export { useShippingRates } from './hooks/useShippingRates';
25
25
  export { useTranslations } from './hooks/useTranslations';
26
26
  export { useVipOffers } from './hooks/useVipOffers';
27
- export { useTagadaContext, useTagadaContextSafe } from './providers/TagadaProvider';
27
+ export { useTagadaContext } from './providers/TagadaProvider';
28
28
  // Plugin configuration hooks
29
29
  export { clearPluginConfigCache, debugPluginConfig, getPluginConfig, useBasePath, usePluginConfig } from './hooks/usePluginConfig';
30
30
  // ISO Data hooks
@@ -60,5 +60,4 @@ export declare function TagadaProvider({ children, environment, customApiConfig,
60
60
  localConfig, blockUntilSessionReady, // Default to new non-blocking behavior
61
61
  rawPluginConfig, }: TagadaProviderProps): import("react/jsx-runtime").JSX.Element;
62
62
  export declare function useTagadaContext(): TagadaContextValue;
63
- export declare function useTagadaContextSafe(): TagadaContextValue | null;
64
63
  export {};
@@ -66,8 +66,19 @@ rawPluginConfig, }) {
66
66
  hasLoggedRef.current = true;
67
67
  }
68
68
  // Load plugin configuration directly (not using hook to avoid circular dependency)
69
- const [pluginConfig, setPluginConfig] = useState({ basePath: '/', config: {} });
70
- const [configLoading, setConfigLoading] = useState(true);
69
+ // Initialize with raw config if available to avoid empty config during loading
70
+ const [pluginConfig, setPluginConfig] = useState(() => {
71
+ if (rawPluginConfig) {
72
+ return {
73
+ storeId: rawPluginConfig.storeId,
74
+ accountId: rawPluginConfig.accountId,
75
+ basePath: rawPluginConfig.basePath ?? '/',
76
+ config: rawPluginConfig.config ?? {},
77
+ };
78
+ }
79
+ return { basePath: '/', config: {} };
80
+ });
81
+ const [configLoading, setConfigLoading] = useState(!rawPluginConfig);
71
82
  // Load plugin config on mount with the specified variant
72
83
  useEffect(() => {
73
84
  const loadConfig = async () => {
@@ -524,12 +535,9 @@ rawPluginConfig, }) {
524
535
  refreshCoordinator,
525
536
  ]);
526
537
  // Determine if we should show loading
527
- // Phase 1 & 2 are mandatory: config loading and storeId availability
528
- // Phase 3 (session initialization) is optional/non-blocking by default
529
- const shouldShowLoading = configLoading || (!storeId && configLoading);
530
- const canRenderChildren = blockUntilSessionReady
531
- ? !configLoading && storeId && isInitialized // Old behavior: wait for all phases
532
- : !configLoading && storeId; // New behavior: render after phases 1 & 2
538
+ // Always block until config is loaded (even if empty)
539
+ const shouldShowLoading = configLoading;
540
+ const canRenderChildren = !configLoading;
533
541
  return (_jsxs(TagadaContext.Provider, { value: contextValue, children: [shouldShowLoading && _jsx(InitializationLoader, {}), finalDebugMode && canRenderChildren && (_jsxs(_Fragment, { children: [_jsx("button", { onClick: () => setIsDebugDrawerOpen(true), style: {
534
542
  position: 'fixed',
535
543
  bottom: '16px',
@@ -560,10 +568,6 @@ export function useTagadaContext() {
560
568
  }
561
569
  return context;
562
570
  }
563
- // Safe version that returns null instead of throwing
564
- export function useTagadaContextSafe() {
565
- return useContext(TagadaContext);
566
- }
567
571
  // Helper functions
568
572
  function getCurrencySymbol(code) {
569
573
  const symbols = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagadapay/plugin-sdk",
3
- "version": "2.4.38",
3
+ "version": "2.4.39",
4
4
  "description": "Modern React SDK for building Tagada Pay plugins",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",