@tagadapay/plugin-sdk 3.1.8 → 3.1.10

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 (50) hide show
  1. package/README.md +1129 -1129
  2. package/build-cdn.js +223 -113
  3. package/dist/external-tracker.js +135 -81
  4. package/dist/external-tracker.min.js +2 -2
  5. package/dist/external-tracker.min.js.map +4 -4
  6. package/dist/react/providers/TagadaProvider.js +5 -5
  7. package/dist/tagada-sdk.js +10164 -0
  8. package/dist/tagada-sdk.min.js +45 -0
  9. package/dist/tagada-sdk.min.js.map +7 -0
  10. package/dist/v2/core/funnelClient.d.ts +91 -4
  11. package/dist/v2/core/funnelClient.js +42 -3
  12. package/dist/v2/core/resources/funnel.d.ts +10 -0
  13. package/dist/v2/core/resources/payments.d.ts +21 -1
  14. package/dist/v2/core/resources/payments.js +34 -0
  15. package/dist/v2/core/utils/currency.d.ts +14 -0
  16. package/dist/v2/core/utils/currency.js +40 -0
  17. package/dist/v2/core/utils/index.d.ts +1 -0
  18. package/dist/v2/core/utils/index.js +2 -0
  19. package/dist/v2/core/utils/pluginConfig.d.ts +8 -0
  20. package/dist/v2/core/utils/pluginConfig.js +28 -0
  21. package/dist/v2/core/utils/previewMode.d.ts +4 -0
  22. package/dist/v2/core/utils/previewMode.js +28 -0
  23. package/dist/v2/core/utils/previewModeIndicator.js +101 -101
  24. package/dist/v2/index.d.ts +7 -6
  25. package/dist/v2/index.js +6 -6
  26. package/dist/v2/react/components/ApplePayButton.d.ts +1 -2
  27. package/dist/v2/react/components/ApplePayButton.js +57 -58
  28. package/dist/v2/react/components/FunnelScriptInjector.js +161 -172
  29. package/dist/v2/react/components/GooglePayButton.d.ts +2 -0
  30. package/dist/v2/react/components/GooglePayButton.js +80 -64
  31. package/dist/v2/react/hooks/useFunnel.d.ts +8 -2
  32. package/dist/v2/react/hooks/useFunnel.js +2 -2
  33. package/dist/v2/react/hooks/useGoogleAutocomplete.d.ts +10 -0
  34. package/dist/v2/react/hooks/useGoogleAutocomplete.js +48 -0
  35. package/dist/v2/react/hooks/useGooglePayCheckout.d.ts +21 -0
  36. package/dist/v2/react/hooks/useGooglePayCheckout.js +198 -0
  37. package/dist/v2/react/hooks/usePaymentPolling.d.ts +7 -1
  38. package/dist/v2/react/hooks/usePaymentQuery.d.ts +2 -0
  39. package/dist/v2/react/hooks/usePaymentQuery.js +435 -8
  40. package/dist/v2/react/hooks/usePixelTracking.d.ts +56 -0
  41. package/dist/v2/react/hooks/usePixelTracking.js +508 -0
  42. package/dist/v2/react/hooks/useStepConfig.d.ts +8 -6
  43. package/dist/v2/react/hooks/useStepConfig.js +3 -2
  44. package/dist/v2/react/index.d.ts +6 -2
  45. package/dist/v2/react/index.js +3 -1
  46. package/dist/v2/react/providers/ExpressPaymentMethodsProvider.d.ts +1 -0
  47. package/dist/v2/react/providers/ExpressPaymentMethodsProvider.js +33 -13
  48. package/dist/v2/react/providers/TagadaProvider.js +22 -21
  49. package/dist/v2/standalone/index.js +1 -1
  50. package/package.json +112 -112
@@ -84,38 +84,51 @@ export const ExpressPaymentMethodsProvider = ({ children, customerId, checkout,
84
84
  mutationFn: (data) => expressPaymentResource.updateCustomerEmail(customerId, { data }),
85
85
  });
86
86
  // Recompute order summary (refetch after updates)
87
- // Uses current checkout prop and refetches shipping rates
87
+ // Refetches checkout and shipping rates to get fresh data
88
88
  const reComputeOrderSummary = useCallback(async () => {
89
89
  try {
90
- // Only refetch shipping rates - checkout is managed by parent
90
+ // Refetch checkout to get latest data
91
+ await queryClient.refetchQueries({ queryKey: ['checkout'] });
91
92
  await refetchRates();
92
- // Use current checkout prop (will be updated by parent after address mutation)
93
- const currentSummary = checkout?.summary;
94
- if (!currentSummary || !shippingRates) {
93
+ // Wait a bit for queries to settle
94
+ await new Promise((resolve) => setTimeout(resolve, 100));
95
+ // Get fresh data from cache
96
+ const queryCache = queryClient.getQueryCache();
97
+ const checkoutQueries = queryCache.findAll({ queryKey: ['checkout'] });
98
+ // Try to find the checkout that matches our current session ID
99
+ const currentSessionId = checkout?.checkoutSession?.id;
100
+ const matchingCheckout = checkoutQueries.find((query) => query.state.data && query.state.data?.checkoutSession?.id === currentSessionId);
101
+ const freshCheckout = matchingCheckout
102
+ ? matchingCheckout.state.data
103
+ : checkoutQueries.length > 0
104
+ ? checkoutQueries[0].state.data
105
+ : checkout;
106
+ const freshSummary = freshCheckout?.summary || checkout?.summary;
107
+ if (!freshSummary || !shippingRates) {
95
108
  console.error('[ExpressProvider] Missing data:', {
96
- hasSummary: !!currentSummary,
109
+ hasSummary: !!freshSummary,
97
110
  hasShippingRates: !!shippingRates,
98
- checkout,
111
+ checkout: freshCheckout || checkout,
99
112
  });
100
113
  return undefined;
101
114
  }
102
115
  const recomputedLineItems = [
103
116
  {
104
117
  label: 'Subtotal',
105
- amount: minorUnitsToCurrencyString(currentSummary.subtotalAdjustedAmount, currentSummary.currency),
118
+ amount: minorUnitsToCurrencyString(freshSummary.subtotalAdjustedAmount, freshSummary.currency),
106
119
  },
107
120
  {
108
121
  label: 'Shipping',
109
- amount: minorUnitsToCurrencyString(currentSummary.shippingCost ?? 0, currentSummary.currency),
122
+ amount: minorUnitsToCurrencyString(freshSummary.shippingCost ?? 0, freshSummary.currency),
110
123
  },
111
124
  {
112
125
  label: 'Tax',
113
- amount: minorUnitsToCurrencyString(currentSummary.totalTaxAmount, currentSummary.currency),
126
+ amount: minorUnitsToCurrencyString(freshSummary.totalTaxAmount, freshSummary.currency),
114
127
  },
115
128
  ];
116
129
  const total = {
117
130
  label: 'Order Total',
118
- amount: minorUnitsToCurrencyString(currentSummary.totalAdjustedAmount, currentSummary.currency),
131
+ amount: minorUnitsToCurrencyString(freshSummary.totalAdjustedAmount, freshSummary.currency),
119
132
  };
120
133
  const recomputedShippingMethods = (shippingRates || []).map((rate) => ({
121
134
  label: rate.shippingRateName,
@@ -123,17 +136,20 @@ export const ExpressPaymentMethodsProvider = ({ children, customerId, checkout,
123
136
  identifier: rate.id,
124
137
  detail: rate.description || '',
125
138
  }));
139
+ // Get selected shipping rate ID from fresh checkout
140
+ const selectedShippingRateId = freshCheckout?.checkoutSession?.shippingRate?.id;
126
141
  return {
127
142
  lineItems: recomputedLineItems,
128
143
  total,
129
144
  shippingMethods: recomputedShippingMethods,
145
+ selectedShippingRateId,
130
146
  };
131
147
  }
132
148
  catch (e) {
133
149
  console.error('Error recomputing order summary:', e);
134
150
  return undefined;
135
151
  }
136
- }, [refetchRates, shippingRates, minorUnitsToCurrencyString, checkout]);
152
+ }, [refetchRates, shippingRates, minorUnitsToCurrencyString, checkout, queryClient]);
137
153
  // Update checkout session values
138
154
  const updateCheckoutSessionValues = useCallback(async (input) => {
139
155
  await updateAddressMutation.mutateAsync(input.data);
@@ -144,8 +160,12 @@ export const ExpressPaymentMethodsProvider = ({ children, customerId, checkout,
144
160
  return;
145
161
  await updateEmailMutation.mutateAsync(input.data);
146
162
  }, [customerId, updateEmailMutation]);
163
+ // Check if Apple Pay is available (window.ApplePaySession only exists on Apple devices)
164
+ const isApplePayAvailable = typeof window !== 'undefined' && typeof window.ApplePaySession !== 'undefined';
147
165
  // Identify specific payment method types
148
- const applePayPaymentMethod = useMemo(() => paymentMethods?.find((p) => p.type === 'apple_pay'), [paymentMethods]);
166
+ const applePayPaymentMethod = useMemo(() => {
167
+ return isApplePayAvailable ? paymentMethods?.find((p) => p.type === 'apple_pay') : undefined;
168
+ }, [paymentMethods, isApplePayAvailable]);
149
169
  const googlePayPaymentMethod = useMemo(() => paymentMethods?.find((p) => p.type === 'google_pay'), [paymentMethods]);
150
170
  const paypalPaymentMethod = useMemo(() => paymentMethods?.find((p) => p.type === 'paypal'), [paymentMethods]);
151
171
  const klarnaPaymentMethod = useMemo(() => paymentMethods?.find((p) => p.type === 'klarna'), [paymentMethods]);
@@ -11,6 +11,7 @@ import { TagadaClient } from '../../core/client';
11
11
  import { default as DebugDrawer } from '../components/DebugDrawer';
12
12
  import { FunnelScriptInjector } from '../components/FunnelScriptInjector';
13
13
  import { setGlobalApiClient } from '../hooks/useApiQuery';
14
+ import { PixelTrackingProvider } from '../hooks/usePixelTracking';
14
15
  // Professional, subtle loading component for initialization
15
16
  const InitializationLoader = () => (_jsxs("div", { style: {
16
17
  position: 'fixed',
@@ -37,11 +38,11 @@ const InitializationLoader = () => (_jsxs("div", { style: {
37
38
  borderTop: '1.5px solid #9ca3af',
38
39
  borderRadius: '50%',
39
40
  animation: 'tagada-spin 1s linear infinite',
40
- } }), _jsx("span", { children: "Loading..." }), _jsx("style", { children: `
41
- @keyframes tagada-spin {
42
- 0% { transform: rotate(0deg); }
43
- 100% { transform: rotate(360deg); }
44
- }
41
+ } }), _jsx("span", { children: "Loading..." }), _jsx("style", { children: `
42
+ @keyframes tagada-spin {
43
+ 0% { transform: rotate(0deg); }
44
+ 100% { transform: rotate(360deg); }
45
+ }
45
46
  ` })] }));
46
47
  const TagadaContext = createContext(null);
47
48
  export function TagadaProvider({ children, environment, customApiConfig, debugMode, localConfig, blockUntilSessionReady = false, rawPluginConfig, features, funnelId, autoInitializeFunnel = true, onNavigate, onFunnelError, debugScripts = [], }) {
@@ -319,22 +320,22 @@ export function TagadaProvider({ children, environment, customApiConfig, debugMo
319
320
  // Loading State Logic
320
321
  const shouldShowLoading = state.isLoading || state.pluginConfigLoading || (blockUntilSessionReady && !state.isSessionInitialized);
321
322
  const canRenderChildren = !state.pluginConfigLoading && (!blockUntilSessionReady || state.isSessionInitialized);
322
- return (_jsx(QueryClientProvider, { client: queryClient, children: _jsxs(TagadaContext.Provider, { value: contextValue, children: [_jsx(FunnelScriptInjector, { ...funnelState }), shouldShowLoading && _jsx(InitializationLoader, {}), state.debugMode && canRenderChildren && (_jsxs(_Fragment, { children: [_jsx("button", { onClick: () => setIsDebugDrawerOpen(true), style: {
323
- position: 'fixed',
324
- bottom: '16px',
325
- right: '16px',
326
- backgroundColor: '#f97316',
327
- color: 'white',
328
- border: 'none',
329
- borderRadius: '50%',
330
- width: '56px',
331
- height: '56px',
332
- fontSize: '20px',
333
- cursor: 'pointer',
334
- boxShadow: '0 4px 12px rgba(0, 0, 0, 0.3)',
335
- zIndex: 999997,
336
- transition: 'all 0.2s ease',
337
- }, title: "Open TagadaPay SDK Debug Panel", children: "\uD83D\uDC1B" }), _jsx(DebugDrawer, { isOpen: isDebugDrawerOpen, onClose: () => setIsDebugDrawerOpen(false) })] })), canRenderChildren && children] }) }));
323
+ return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(TagadaContext.Provider, { value: contextValue, children: _jsxs(PixelTrackingProvider, { children: [_jsx(FunnelScriptInjector, { ...funnelState }), shouldShowLoading && _jsx(InitializationLoader, {}), state.debugMode && canRenderChildren && (_jsxs(_Fragment, { children: [_jsx("button", { onClick: () => setIsDebugDrawerOpen(true), style: {
324
+ position: 'fixed',
325
+ bottom: '16px',
326
+ right: '16px',
327
+ backgroundColor: '#f97316',
328
+ color: 'white',
329
+ border: 'none',
330
+ borderRadius: '50%',
331
+ width: '56px',
332
+ height: '56px',
333
+ fontSize: '20px',
334
+ cursor: 'pointer',
335
+ boxShadow: '0 4px 12px rgba(0, 0, 0, 0.3)',
336
+ zIndex: 999997,
337
+ transition: 'all 0.2s ease',
338
+ }, title: "Open TagadaPay SDK Debug Panel", children: "\uD83D\uDC1B" }), _jsx(DebugDrawer, { isOpen: isDebugDrawerOpen, onClose: () => setIsDebugDrawerOpen(false) })] })), canRenderChildren && children] }) }) }));
338
339
  }
339
340
  export function useTagadaContext() {
340
341
  const context = useContext(TagadaContext);
@@ -19,7 +19,7 @@ export function createTagadaClient(config = {}) {
19
19
  // Re-export Core Classes
20
20
  export { TagadaClient, ApiClient, CheckoutResource };
21
21
  export { FunnelActionType } from '../core/resources/funnel';
22
- // Re-export Utilities
22
+ // Re-export Utilities (includes formatMoney from core/utils/currency)
23
23
  export * from '../core/utils';
24
24
  // ============================================================================
25
25
  // EXTERNAL PAGE TRACKER
package/package.json CHANGED
@@ -1,112 +1,112 @@
1
- {
2
- "name": "@tagadapay/plugin-sdk",
3
- "version": "3.1.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
- "./v2": {
19
- "types": "./dist/v2/index.d.ts",
20
- "import": "./dist/v2/index.js",
21
- "require": "./dist/v2/index.js"
22
- },
23
- "./v2/standalone": {
24
- "types": "./dist/v2/standalone/index.d.ts",
25
- "import": "./dist/v2/standalone/index.js",
26
- "require": "./dist/v2/standalone/index.js"
27
- },
28
- "./external-tracker": {
29
- "browser": "./dist/external-tracker.min.js",
30
- "default": "./dist/external-tracker.min.js"
31
- }
32
- },
33
- "scripts": {
34
- "build": "tsc && npm run build:cdn",
35
- "build:cdn": "node build-cdn.js",
36
- "build:ts": "tsc",
37
- "clean": "rm -rf dist",
38
- "lint": "echo \"No linting configured\"",
39
- "test": "jest --no-watchman",
40
- "test:watch": "jest --watch --no-watchman",
41
- "test:coverage": "jest --coverage --no-watchman",
42
- "dev": "tsc --watch",
43
- "prepublishOnly": "npm run clean && npm run build",
44
- "publish:patch": "npm version patch && npm publish",
45
- "publish:minor": "npm version minor && npm publish",
46
- "publish:major": "npm version major && npm publish",
47
- "publish:beta": "npm version prerelease --preid=beta && npm publish --tag beta",
48
- "publish:alpha": "npm version prerelease --preid=alpha && npm publish --tag alpha",
49
- "version:patch": "npm version patch",
50
- "version:minor": "npm version minor",
51
- "version:major": "npm version major",
52
- "version:beta": "npm version prerelease --preid=beta",
53
- "version:alpha": "npm version prerelease --preid=alpha",
54
- "version:check": "node version-sync.js check",
55
- "version:sync": "node version-sync.js sync",
56
- "version:list": "node version-sync.js list",
57
- "version:next": "node version-sync.js next",
58
- "postversion": "echo \"✅ Version updated to $(node -p 'require(\"./package.json\").version')\" && (git push && git push --tags || echo \"⚠️ Git push failed - you may need to pull and push manually\")"
59
- },
60
- "keywords": [
61
- "tagadapay",
62
- "cms",
63
- "plugin",
64
- "sdk",
65
- "react",
66
- "typescript"
67
- ],
68
- "author": "Tagada Pay",
69
- "license": "MIT",
70
- "dependencies": {
71
- "@basis-theory/apple-pay-js": "^2.0.2",
72
- "@basis-theory/basis-theory-js": "^4.30.0",
73
- "@basis-theory/basis-theory-react": "^1.32.5",
74
- "@basis-theory/web-threeds": "^1.0.1",
75
- "@google-pay/button-react": "^3.0.10",
76
- "@tagadapay/plugin-sdk": "link:",
77
- "@tanstack/react-query": "^5.90.2",
78
- "@ua-parser-js/pro-enterprise": "^2.0.6",
79
- "axios": "^1.10.0",
80
- "iso3166-2-db": "^2.3.11",
81
- "path-to-regexp": "^8.2.0",
82
- "react-intl": "^7.1.11",
83
- "swr": "^2.3.6"
84
- },
85
- "devDependencies": {
86
- "@types/jest": "^29.5.0",
87
- "@types/node": "^18.0.0",
88
- "@types/react": "^19",
89
- "@types/react-dom": "^19",
90
- "esbuild": "^0.24.2",
91
- "jest": "^29.5.0",
92
- "ts-jest": "^29.1.0",
93
- "typescript": "^5.0.0"
94
- },
95
- "peerDependencies": {
96
- "react": "^18.0.0 || ^19.0.0",
97
- "react-dom": "^18.0.0 || ^19.0.0"
98
- },
99
- "files": [
100
- "dist/**/*",
101
- "README.md",
102
- "build-cdn.js"
103
- ],
104
- "repository": {
105
- "type": "git",
106
- "url": "git+https://github.com/tagadapay/plugin-sdk.git"
107
- },
108
- "bugs": {
109
- "url": "https://github.com/tagadapay/plugin-sdk/issues"
110
- },
111
- "homepage": "https://github.com/tagadapay/plugin-sdk#readme"
112
- }
1
+ {
2
+ "name": "@tagadapay/plugin-sdk",
3
+ "version": "3.1.10",
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
+ "./v2": {
19
+ "types": "./dist/v2/index.d.ts",
20
+ "import": "./dist/v2/index.js",
21
+ "require": "./dist/v2/index.js"
22
+ },
23
+ "./v2/standalone": {
24
+ "types": "./dist/v2/standalone/index.d.ts",
25
+ "import": "./dist/v2/standalone/index.js",
26
+ "require": "./dist/v2/standalone/index.js"
27
+ },
28
+ "./external-tracker": {
29
+ "browser": "./dist/external-tracker.min.js",
30
+ "default": "./dist/external-tracker.min.js"
31
+ }
32
+ },
33
+ "scripts": {
34
+ "build": "tsc && npm run build:cdn",
35
+ "build:cdn": "node build-cdn.js",
36
+ "build:ts": "tsc",
37
+ "clean": "rm -rf dist",
38
+ "lint": "echo \"No linting configured\"",
39
+ "test": "jest --no-watchman",
40
+ "test:watch": "jest --watch --no-watchman",
41
+ "test:coverage": "jest --coverage --no-watchman",
42
+ "dev": "tsc --watch",
43
+ "prepublishOnly": "npm run clean && npm run build",
44
+ "publish:patch": "npm version patch && npm publish",
45
+ "publish:minor": "npm version minor && npm publish",
46
+ "publish:major": "npm version major && npm publish",
47
+ "publish:beta": "npm version prerelease --preid=beta && npm publish --tag beta",
48
+ "publish:alpha": "npm version prerelease --preid=alpha && npm publish --tag alpha",
49
+ "version:patch": "npm version patch",
50
+ "version:minor": "npm version minor",
51
+ "version:major": "npm version major",
52
+ "version:beta": "npm version prerelease --preid=beta",
53
+ "version:alpha": "npm version prerelease --preid=alpha",
54
+ "version:check": "node version-sync.js check",
55
+ "version:sync": "node version-sync.js sync",
56
+ "version:list": "node version-sync.js list",
57
+ "version:next": "node version-sync.js next",
58
+ "postversion": "echo \"✅ Version updated to $(node -p 'require(\"./package.json\").version')\" && (git push && git push --tags || echo \"⚠️ Git push failed - you may need to pull and push manually\")"
59
+ },
60
+ "keywords": [
61
+ "tagadapay",
62
+ "cms",
63
+ "plugin",
64
+ "sdk",
65
+ "react",
66
+ "typescript"
67
+ ],
68
+ "author": "Tagada Pay",
69
+ "license": "MIT",
70
+ "dependencies": {
71
+ "@basis-theory/apple-pay-js": "^2.0.2",
72
+ "@basis-theory/basis-theory-js": "^4.30.0",
73
+ "@basis-theory/basis-theory-react": "^1.32.5",
74
+ "@basis-theory/web-threeds": "^1.0.1",
75
+ "@google-pay/button-react": "^3.0.10",
76
+ "@tagadapay/plugin-sdk": "link:",
77
+ "@tanstack/react-query": "^5.90.2",
78
+ "@ua-parser-js/pro-enterprise": "^2.0.6",
79
+ "axios": "^1.10.0",
80
+ "iso3166-2-db": "^2.3.11",
81
+ "path-to-regexp": "^8.2.0",
82
+ "react-intl": "^7.1.11",
83
+ "swr": "^2.3.6"
84
+ },
85
+ "devDependencies": {
86
+ "@types/jest": "^29.5.0",
87
+ "@types/node": "^18.0.0",
88
+ "@types/react": "^19",
89
+ "@types/react-dom": "^19",
90
+ "esbuild": "^0.24.2",
91
+ "jest": "^29.5.0",
92
+ "ts-jest": "^29.1.0",
93
+ "typescript": "^5.0.0"
94
+ },
95
+ "peerDependencies": {
96
+ "react": "^18.0.0 || ^19.0.0",
97
+ "react-dom": "^18.0.0 || ^19.0.0"
98
+ },
99
+ "files": [
100
+ "dist/**/*",
101
+ "README.md",
102
+ "build-cdn.js"
103
+ ],
104
+ "repository": {
105
+ "type": "git",
106
+ "url": "git+https://github.com/tagadapay/plugin-sdk.git"
107
+ },
108
+ "bugs": {
109
+ "url": "https://github.com/tagadapay/plugin-sdk/issues"
110
+ },
111
+ "homepage": "https://github.com/tagadapay/plugin-sdk#readme"
112
+ }