@tagadapay/plugin-sdk 1.0.29 → 2.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.
@@ -10,6 +10,7 @@ import { setClientToken, getClientToken, clearClientToken } from '../utils/token
10
10
  import { decodeJWTClient, isTokenExpired } from '../utils/jwtDecoder';
11
11
  import { collectDeviceInfo, getBrowserLocale, getUrlParams } from '../utils/deviceInfo';
12
12
  import DebugDrawer from '../components/DebugDrawer';
13
+ import { loadPluginConfig } from '../hooks/usePluginConfig';
13
14
  import { formatMoney, getCurrencyInfo, moneyStringOrNumberToMinorUnits, minorUnitsToMajorUnits, formatMoneyWithoutSymbol, convertCurrency, formatSimpleMoney, } from '../utils/money';
14
15
  // Subtle loading component for initialization
15
16
  const InitializationLoader = () => (_jsx("div", { style: {
@@ -30,7 +31,46 @@ const InitializationLoader = () => (_jsx("div", { style: {
30
31
  ` }) }));
31
32
  const TagadaContext = createContext(null);
32
33
  export function TagadaProvider({ children, environment, customApiConfig, debugMode, // Remove default, will be set based on environment
33
- storeId, accountId, }) {
34
+ storeId: propStoreId, accountId: propAccountId, localConfig, }) {
35
+ // LOCAL DEV ONLY: Use localConfig override if in local development, otherwise use default
36
+ const isLocalDev = typeof window !== 'undefined' &&
37
+ (window.location.hostname === 'localhost' ||
38
+ window.location.hostname.includes('.localhost') ||
39
+ window.location.hostname.includes('127.0.0.1'));
40
+ const configVariant = isLocalDev ? localConfig || 'default' : 'default';
41
+ // Debug logging
42
+ console.log('🔍 TagadaProvider Config Debug:', {
43
+ hostname: typeof window !== 'undefined' ? window.location.hostname : 'SSR',
44
+ isLocalDev,
45
+ localConfig,
46
+ configVariant,
47
+ });
48
+ // Load plugin configuration directly (not using hook to avoid circular dependency)
49
+ const [pluginConfig, setPluginConfig] = useState({ basePath: '/', config: {} });
50
+ const [configLoading, setConfigLoading] = useState(true);
51
+ // Load plugin config on mount with the specified variant
52
+ useEffect(() => {
53
+ const loadConfig = async () => {
54
+ try {
55
+ const config = await loadPluginConfig(configVariant);
56
+ setPluginConfig(config);
57
+ }
58
+ catch (error) {
59
+ console.warn('Failed to load plugin config in TagadaProvider:', error);
60
+ setPluginConfig({ basePath: '/', config: {} });
61
+ }
62
+ finally {
63
+ setConfigLoading(false);
64
+ }
65
+ };
66
+ void loadConfig();
67
+ }, [configVariant]);
68
+ // Extract store/account IDs from plugin config
69
+ const configStoreId = pluginConfig.storeId;
70
+ const configAccountId = pluginConfig.accountId;
71
+ // Use props if provided, otherwise use config from hook
72
+ const storeId = propStoreId || configStoreId;
73
+ const accountId = propAccountId || configAccountId;
34
74
  const [isLoading, setIsLoading] = useState(true);
35
75
  const [isInitialized, setIsInitialized] = useState(false);
36
76
  const [token, setToken] = useState(null);
@@ -279,6 +319,10 @@ storeId, accountId, }) {
279
319
  if (isInitializing.current) {
280
320
  return;
281
321
  }
322
+ // Wait for plugin config to load before initializing
323
+ if (configLoading) {
324
+ return;
325
+ }
282
326
  isInitializing.current = true;
283
327
  const initializeToken = async () => {
284
328
  try {
@@ -331,7 +375,7 @@ storeId, accountId, }) {
331
375
  }
332
376
  };
333
377
  void initializeToken();
334
- }, [storeId, createAnonymousToken, initializeSession]);
378
+ }, [storeId, createAnonymousToken, initializeSession, configLoading]);
335
379
  // Update auth state when customer/session changes
336
380
  useEffect(() => {
337
381
  setAuth({
@@ -398,6 +442,8 @@ storeId, accountId, }) {
398
442
  isLoading,
399
443
  isInitialized,
400
444
  debugMode: finalDebugMode,
445
+ pluginConfig,
446
+ pluginConfigLoading: configLoading,
401
447
  debugCheckout,
402
448
  updateCheckoutDebugData: (data, error, isLoading) => {
403
449
  setDebugCheckout({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tagadapay/plugin-sdk",
3
- "version": "1.0.29",
3
+ "version": "2.0.1",
4
4
  "description": "Modern React SDK for building Tagada Pay plugins",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -38,6 +38,7 @@
38
38
  "@basis-theory/basis-theory-react": "^1.32.5",
39
39
  "@basis-theory/web-threeds": "^1.0.1",
40
40
  "axios": "^1.6.0",
41
+ "iso3166-2-db": "^2.3.11",
41
42
  "react-google-autocomplete": "^2.7.3",
42
43
  "react-intl": "^7.1.11"
43
44
  },