@tagadapay/plugin-sdk 2.2.7 → 2.2.8

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,7 +4,7 @@ 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 { apiService, updateCheckoutDebugData, refreshCoordinator, currency } = useTagadaContext();
7
+ const { apiService, updateCheckoutDebugData, refreshCoordinator, currency, isSessionInitialized } = useTagadaContext();
8
8
  const { storeId } = usePluginConfig();
9
9
  const { code: currentCurrency } = useCurrency();
10
10
  const [checkout, setCheckout] = useState(null);
@@ -52,6 +52,10 @@ export function useCheckout(options = {}) {
52
52
  console.warn('[Checkout] Cannot init - checkoutToken already provided:', providedToken.substring(0, 8) + '...');
53
53
  throw new Error('Cannot initialize new checkout when checkoutToken is already provided. The existing checkout will be auto-loaded.');
54
54
  }
55
+ // Check if CMS session is initialized before making API calls
56
+ if (!isSessionInitialized) {
57
+ throw new Error('Session not initialized. Please wait for the SDK to complete initialization before calling init().');
58
+ }
55
59
  setIsLoading(true);
56
60
  setError(null);
57
61
  try {
@@ -104,8 +108,12 @@ export function useCheckout(options = {}) {
104
108
  finally {
105
109
  setIsLoading(false);
106
110
  }
107
- }, [apiService, currentCurrency, providedToken, storeId]);
111
+ }, [apiService, currentCurrency, providedToken, storeId, isSessionInitialized]);
108
112
  const getCheckout = useCallback(async (checkoutToken) => {
113
+ // Check if CMS session is initialized before making API calls
114
+ if (!isSessionInitialized) {
115
+ throw new Error('Session not initialized. Please wait for the SDK to complete initialization before calling getCheckout().');
116
+ }
109
117
  setIsLoading(true);
110
118
  setError(null);
111
119
  try {
@@ -138,7 +146,7 @@ export function useCheckout(options = {}) {
138
146
  finally {
139
147
  setIsLoading(false);
140
148
  }
141
- }, [apiService, currentCurrency]);
149
+ }, [apiService, currentCurrency, isSessionInitialized]);
142
150
  const refresh = useCallback(async () => {
143
151
  if (!currentCheckoutTokenRef.current) {
144
152
  throw new Error('No checkout session to refresh');
@@ -16,7 +16,12 @@ let configPromise = null;
16
16
  const loadLocalDevConfig = async (configVariant = 'default') => {
17
17
  try {
18
18
  // Only try to load local config in development
19
- if (process.env.NODE_ENV !== 'development') {
19
+ // Use hostname-based detection for better Vite compatibility
20
+ const isLocalDev = typeof window !== 'undefined' &&
21
+ (window.location.hostname === 'localhost' ||
22
+ window.location.hostname.includes('.localhost') ||
23
+ window.location.hostname.includes('127.0.0.1'));
24
+ if (!isLocalDev) {
20
25
  return null;
21
26
  }
22
27
  // Load local store/account config
@@ -176,7 +181,12 @@ export const clearPluginConfigCache = () => {
176
181
  * Development helper to log current configuration
177
182
  */
178
183
  export const debugPluginConfig = async (configVariant = 'default') => {
179
- if (process.env.NODE_ENV !== 'development') {
184
+ // Use hostname-based detection for better Vite compatibility
185
+ const isLocalDev = typeof window !== 'undefined' &&
186
+ (window.location.hostname === 'localhost' ||
187
+ window.location.hostname.includes('.localhost') ||
188
+ window.location.hostname.includes('127.0.0.1'));
189
+ if (!isLocalDev) {
180
190
  return;
181
191
  }
182
192
  const config = await getPluginConfig(configVariant);
@@ -14,7 +14,6 @@ export interface ProductPrice {
14
14
  export interface ProductVariant {
15
15
  id: string;
16
16
  name: string;
17
- description: string;
18
17
  sku?: string;
19
18
  weight?: number;
20
19
  imageUrl?: string;
@@ -17,6 +17,7 @@ interface TagadaContextValue {
17
17
  apiService: ApiService;
18
18
  isLoading: boolean;
19
19
  isInitialized: boolean;
20
+ isSessionInitialized: boolean;
20
21
  debugMode: boolean;
21
22
  pluginConfig: PluginConfig;
22
23
  pluginConfigLoading: boolean;
@@ -38,11 +38,11 @@ const InitializationLoader = () => (_jsxs("div", { style: {
38
38
  borderTop: '1.5px solid #9ca3af',
39
39
  borderRadius: '50%',
40
40
  animation: 'tagada-spin 1s linear infinite',
41
- } }), _jsx("span", { children: "Loading..." }), _jsx("style", { children: `
42
- @keyframes tagada-spin {
43
- 0% { transform: rotate(0deg); }
44
- 100% { transform: rotate(360deg); }
45
- }
41
+ } }), _jsx("span", { children: "Loading..." }), _jsx("style", { children: `
42
+ @keyframes tagada-spin {
43
+ 0% { transform: rotate(0deg); }
44
+ 100% { transform: rotate(360deg); }
45
+ }
46
46
  ` })] }));
47
47
  const TagadaContext = createContext(null);
48
48
  export function TagadaProvider({ children, environment, customApiConfig, debugMode, // Remove default, will be set based on environment
@@ -77,12 +77,13 @@ localConfig, }) {
77
77
  console.warn('⚠️ No store ID found in plugin config. This may cause hooks to fail.');
78
78
  }
79
79
  setPluginConfig(config);
80
- console.log('✅ Plugin config loaded:', {
80
+ console.log('✅ Phase 1 & 2 Complete - Plugin config loaded:', {
81
81
  storeId: config.storeId,
82
82
  accountId: config.accountId,
83
83
  basePath: config.basePath,
84
84
  hasConfig: !!config.config,
85
85
  });
86
+ console.log('🚀 Children can now render - Phase 3 (session init) will continue in background');
86
87
  }
87
88
  catch (error) {
88
89
  console.error('❌ Failed to load plugin config in TagadaProvider:', error);
@@ -158,6 +159,7 @@ localConfig, }) {
158
159
  const [customer, setCustomer] = useState(null);
159
160
  const [session, setSession] = useState(null);
160
161
  const [store, setStore] = useState(null);
162
+ const [isSessionInitialized, setIsSessionInitialized] = useState(false);
161
163
  // Initialize locale and currency with defaults
162
164
  const [locale, setLocale] = useState({
163
165
  locale: 'en-US',
@@ -282,6 +284,7 @@ localConfig, }) {
282
284
  }
283
285
  console.debug('[SDK] Session initialized successfully');
284
286
  setIsInitialized(true);
287
+ setIsSessionInitialized(true); // Mark CMS session as ready
285
288
  setIsLoading(false);
286
289
  }
287
290
  catch (error) {
@@ -298,7 +301,7 @@ localConfig, }) {
298
301
  if (hasAttemptedAnonymousToken || !targetStoreId) {
299
302
  return;
300
303
  }
301
- console.log('[SDK] 🚀 Starting initialization...');
304
+ console.log('[SDK] 🚀 Starting Phase 3 - Session initialization...');
302
305
  if (finalDebugMode) {
303
306
  console.debug('[SDK][DEBUG] Creating anonymous token for store:', targetStoreId);
304
307
  }
@@ -328,7 +331,8 @@ localConfig, }) {
328
331
  setIsInitialized(true);
329
332
  setIsLoading(false);
330
333
  }
331
- console.log('[SDK] ✅ Initialization completed successfully');
334
+ console.log('[SDK] ✅ Phase 3 Complete - Session initialization completed successfully');
335
+ setIsSessionInitialized(true); // Mark CMS session as ready
332
336
  }
333
337
  catch (error) {
334
338
  console.error('[SDK] ❌ Initialization failed:', error);
@@ -340,6 +344,7 @@ localConfig, }) {
340
344
  }
341
345
  }, [apiService, hasAttemptedAnonymousToken, initializeSession, finalDebugMode]);
342
346
  // Initialize token from storage or create anonymous token
347
+ // This runs in the background after phases 1 & 2 complete, but doesn't block rendering
343
348
  useEffect(() => {
344
349
  if (isInitializing.current) {
345
350
  return;
@@ -389,6 +394,7 @@ localConfig, }) {
389
394
  else {
390
395
  console.error('[SDK] Failed to decode token');
391
396
  setIsInitialized(true);
397
+ setIsSessionInitialized(false); // Session failed to initialize
392
398
  setIsLoading(false);
393
399
  }
394
400
  }
@@ -467,6 +473,7 @@ localConfig, }) {
467
473
  apiService,
468
474
  isLoading,
469
475
  isInitialized,
476
+ isSessionInitialized,
470
477
  debugMode: finalDebugMode,
471
478
  pluginConfig,
472
479
  pluginConfigLoading: configLoading,
@@ -501,6 +508,7 @@ localConfig, }) {
501
508
  apiService,
502
509
  isLoading,
503
510
  isInitialized,
511
+ isSessionInitialized,
504
512
  finalDebugMode,
505
513
  pluginConfig,
506
514
  configLoading,
@@ -508,9 +516,10 @@ localConfig, }) {
508
516
  refreshCoordinator,
509
517
  ]);
510
518
  // Determine if we should show loading
511
- // Show loading if: config is loading OR (config loaded but no store ID and session not initialized)
512
- const shouldShowLoading = configLoading || (!storeId && !isInitialized);
513
- const canRenderChildren = !configLoading && storeId && isInitialized;
519
+ // Phase 1 & 2 are mandatory: config loading and storeId availability
520
+ // Phase 3 (session initialization) is now optional/non-blocking
521
+ const shouldShowLoading = configLoading || (!storeId && configLoading);
522
+ const canRenderChildren = !configLoading && storeId; // Remove isInitialized requirement
514
523
  return (_jsxs(TagadaContext.Provider, { value: contextValue, children: [shouldShowLoading && _jsx(InitializationLoader, {}), finalDebugMode && canRenderChildren && (_jsxs(_Fragment, { children: [_jsx("button", { onClick: () => setIsDebugDrawerOpen(true), style: {
515
524
  position: 'fixed',
516
525
  bottom: '16px',
package/package.json CHANGED
@@ -1,78 +1,78 @@
1
- {
2
- "name": "@tagadapay/plugin-sdk",
3
- "version": "2.2.7",
4
- "description": "Modern React SDK for building Tagada Pay plugins",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "types": "./dist/index.d.ts",
10
- "import": "./dist/index.js",
11
- "require": "./dist/index.js"
12
- },
13
- "./react": {
14
- "types": "./dist/react/index.d.ts",
15
- "import": "./dist/react/index.js",
16
- "require": "./dist/react/index.js"
17
- }
18
- },
19
- "scripts": {
20
- "build": "tsc",
21
- "clean": "rm -rf dist",
22
- "lint": "echo \"No linting configured\"",
23
- "test": "echo \"No tests yet\" && exit 0",
24
- "dev": "tsc --watch",
25
- "prepublishOnly": "npm run clean && npm run build",
26
- "publish:patch": "npm version patch && npm publish",
27
- "publish:minor": "npm version minor && npm publish",
28
- "publish:major": "npm version major && npm publish",
29
- "publish:beta": "npm version prerelease --preid=beta && npm publish --tag beta",
30
- "publish:alpha": "npm version prerelease --preid=alpha && npm publish --tag alpha",
31
- "version:patch": "npm version patch",
32
- "version:minor": "npm version minor",
33
- "version:major": "npm version major",
34
- "version:beta": "npm version prerelease --preid=beta",
35
- "version:alpha": "npm version prerelease --preid=alpha"
36
- },
37
- "keywords": [
38
- "tagadapay",
39
- "cms",
40
- "plugin",
41
- "sdk",
42
- "react",
43
- "typescript"
44
- ],
45
- "author": "Tagada Pay",
46
- "license": "MIT",
47
- "dependencies": {
48
- "@basis-theory/apple-pay-js": "^2.0.2",
49
- "@basis-theory/basis-theory-js": "^4.30.0",
50
- "@basis-theory/basis-theory-react": "^1.32.5",
51
- "@basis-theory/web-threeds": "^1.0.1",
52
- "axios": "^1.6.0",
53
- "iso3166-2-db": "^2.3.11",
54
- "react-intl": "^7.1.11"
55
- },
56
- "devDependencies": {
57
- "@types/node": "^18.0.0",
58
- "@types/react": "^19",
59
- "@types/react-dom": "^19",
60
- "typescript": "^5.0.0"
61
- },
62
- "peerDependencies": {
63
- "react": "^18.0.0 || ^19.0.0",
64
- "react-dom": "^18.0.0 || ^19.0.0"
65
- },
66
- "files": [
67
- "dist/**/*",
68
- "README.md"
69
- ],
70
- "repository": {
71
- "type": "git",
72
- "url": "git+https://github.com/tagadapay/plugin-sdk.git"
73
- },
74
- "bugs": {
75
- "url": "https://github.com/tagadapay/plugin-sdk/issues"
76
- },
77
- "homepage": "https://github.com/tagadapay/plugin-sdk#readme"
78
- }
1
+ {
2
+ "name": "@tagadapay/plugin-sdk",
3
+ "version": "2.2.8",
4
+ "description": "Modern React SDK for building Tagada Pay plugins",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js"
12
+ },
13
+ "./react": {
14
+ "types": "./dist/react/index.d.ts",
15
+ "import": "./dist/react/index.js",
16
+ "require": "./dist/react/index.js"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "clean": "rm -rf dist",
22
+ "lint": "echo \"No linting configured\"",
23
+ "test": "echo \"No tests yet\" && exit 0",
24
+ "dev": "tsc --watch",
25
+ "prepublishOnly": "npm run clean && npm run build",
26
+ "publish:patch": "npm version patch && npm publish",
27
+ "publish:minor": "npm version minor && npm publish",
28
+ "publish:major": "npm version major && npm publish",
29
+ "publish:beta": "npm version prerelease --preid=beta && npm publish --tag beta",
30
+ "publish:alpha": "npm version prerelease --preid=alpha && npm publish --tag alpha",
31
+ "version:patch": "npm version patch",
32
+ "version:minor": "npm version minor",
33
+ "version:major": "npm version major",
34
+ "version:beta": "npm version prerelease --preid=beta",
35
+ "version:alpha": "npm version prerelease --preid=alpha"
36
+ },
37
+ "keywords": [
38
+ "tagadapay",
39
+ "cms",
40
+ "plugin",
41
+ "sdk",
42
+ "react",
43
+ "typescript"
44
+ ],
45
+ "author": "Tagada Pay",
46
+ "license": "MIT",
47
+ "dependencies": {
48
+ "@basis-theory/apple-pay-js": "^2.0.2",
49
+ "@basis-theory/basis-theory-js": "^4.30.0",
50
+ "@basis-theory/basis-theory-react": "^1.32.5",
51
+ "@basis-theory/web-threeds": "^1.0.1",
52
+ "axios": "^1.6.0",
53
+ "iso3166-2-db": "^2.3.11",
54
+ "react-intl": "^7.1.11"
55
+ },
56
+ "devDependencies": {
57
+ "@types/node": "^18.0.0",
58
+ "@types/react": "^19",
59
+ "@types/react-dom": "^19",
60
+ "typescript": "^5.0.0"
61
+ },
62
+ "peerDependencies": {
63
+ "react": "^18.0.0 || ^19.0.0",
64
+ "react-dom": "^18.0.0 || ^19.0.0"
65
+ },
66
+ "files": [
67
+ "dist/**/*",
68
+ "README.md"
69
+ ],
70
+ "repository": {
71
+ "type": "git",
72
+ "url": "git+https://github.com/tagadapay/plugin-sdk.git"
73
+ },
74
+ "bugs": {
75
+ "url": "https://github.com/tagadapay/plugin-sdk/issues"
76
+ },
77
+ "homepage": "https://github.com/tagadapay/plugin-sdk#readme"
78
+ }