@tagadapay/plugin-sdk 2.2.7 → 2.2.9
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.
- package/README.md +511 -511
- package/dist/react/hooks/useCheckout.js +40 -3
- package/dist/react/hooks/usePluginConfig.js +12 -2
- package/dist/react/hooks/useProducts.d.ts +0 -1
- package/dist/react/providers/TagadaProvider.d.ts +1 -0
- package/dist/react/providers/TagadaProvider.js +20 -11
- package/package.json +78 -78
|
@@ -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);
|
|
@@ -14,6 +14,11 @@ export function useCheckout(options = {}) {
|
|
|
14
14
|
const { checkoutToken: providedToken, autoLoadFromToken = true, } = options;
|
|
15
15
|
const currentCheckoutTokenRef = useRef(null);
|
|
16
16
|
const hasAutoLoadedRef = useRef(false);
|
|
17
|
+
const isSessionInitializedRef = useRef(isSessionInitialized);
|
|
18
|
+
// Keep ref in sync with state
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
isSessionInitializedRef.current = isSessionInitialized;
|
|
21
|
+
}, [isSessionInitialized]);
|
|
17
22
|
// Update debug data whenever checkout state changes with comprehensive information
|
|
18
23
|
useEffect(() => {
|
|
19
24
|
const debugData = checkout
|
|
@@ -52,6 +57,22 @@ export function useCheckout(options = {}) {
|
|
|
52
57
|
console.warn('[Checkout] Cannot init - checkoutToken already provided:', providedToken.substring(0, 8) + '...');
|
|
53
58
|
throw new Error('Cannot initialize new checkout when checkoutToken is already provided. The existing checkout will be auto-loaded.');
|
|
54
59
|
}
|
|
60
|
+
// Wait for CMS session to initialize before making API calls
|
|
61
|
+
if (!isSessionInitialized) {
|
|
62
|
+
console.log('🔄 [useCheckout] Waiting for session initialization to complete...');
|
|
63
|
+
await new Promise((resolve) => {
|
|
64
|
+
const checkSession = () => {
|
|
65
|
+
if (isSessionInitializedRef.current) {
|
|
66
|
+
console.log('✅ [useCheckout] Session initialized, proceeding with checkout init');
|
|
67
|
+
resolve();
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
setTimeout(checkSession, 100); // Check every 100ms
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
checkSession();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
55
76
|
setIsLoading(true);
|
|
56
77
|
setError(null);
|
|
57
78
|
try {
|
|
@@ -104,8 +125,24 @@ export function useCheckout(options = {}) {
|
|
|
104
125
|
finally {
|
|
105
126
|
setIsLoading(false);
|
|
106
127
|
}
|
|
107
|
-
}, [apiService, currentCurrency, providedToken, storeId]);
|
|
128
|
+
}, [apiService, currentCurrency, providedToken, storeId, isSessionInitialized]);
|
|
108
129
|
const getCheckout = useCallback(async (checkoutToken) => {
|
|
130
|
+
// Wait for CMS session to initialize before making API calls
|
|
131
|
+
if (!isSessionInitialized) {
|
|
132
|
+
console.log('🔄 [useCheckout] Waiting for session initialization to complete...');
|
|
133
|
+
await new Promise((resolve) => {
|
|
134
|
+
const checkSession = () => {
|
|
135
|
+
if (isSessionInitializedRef.current) {
|
|
136
|
+
console.log('✅ [useCheckout] Session initialized, proceeding with getCheckout');
|
|
137
|
+
resolve();
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
setTimeout(checkSession, 100); // Check every 100ms
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
checkSession();
|
|
144
|
+
});
|
|
145
|
+
}
|
|
109
146
|
setIsLoading(true);
|
|
110
147
|
setError(null);
|
|
111
148
|
try {
|
|
@@ -138,7 +175,7 @@ export function useCheckout(options = {}) {
|
|
|
138
175
|
finally {
|
|
139
176
|
setIsLoading(false);
|
|
140
177
|
}
|
|
141
|
-
}, [apiService, currentCurrency]);
|
|
178
|
+
}, [apiService, currentCurrency, isSessionInitialized]);
|
|
142
179
|
const refresh = useCallback(async () => {
|
|
143
180
|
if (!currentCheckoutTokenRef.current) {
|
|
144
181
|
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
|
-
|
|
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
|
-
|
|
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);
|
|
@@ -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] ✅
|
|
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
|
-
//
|
|
512
|
-
|
|
513
|
-
const
|
|
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.
|
|
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.9",
|
|
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
|
+
}
|