@tagadapay/plugin-sdk 3.1.25 → 4.0.0

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 (48) hide show
  1. package/README.md +1129 -1129
  2. package/build-cdn.js +499 -499
  3. package/dist/external-tracker.js +5 -5
  4. package/dist/external-tracker.min.js +2 -2
  5. package/dist/external-tracker.min.js.map +2 -2
  6. package/dist/react/config/payment.d.ts +2 -2
  7. package/dist/react/config/payment.js +5 -5
  8. package/dist/react/hooks/usePayment.d.ts +7 -0
  9. package/dist/react/hooks/usePayment.js +1 -0
  10. package/dist/react/providers/TagadaProvider.js +5 -5
  11. package/dist/tagada-react-sdk-minimal.min.js +2 -2
  12. package/dist/tagada-react-sdk-minimal.min.js.map +4 -4
  13. package/dist/tagada-react-sdk.js +1616 -1275
  14. package/dist/tagada-react-sdk.min.js +2 -2
  15. package/dist/tagada-react-sdk.min.js.map +4 -4
  16. package/dist/tagada-sdk.js +869 -27
  17. package/dist/tagada-sdk.min.js +2 -2
  18. package/dist/tagada-sdk.min.js.map +4 -4
  19. package/dist/v2/core/config/environment.d.ts +3 -3
  20. package/dist/v2/core/config/environment.js +7 -7
  21. package/dist/v2/core/funnelClient.d.ts +2 -0
  22. package/dist/v2/core/resources/funnel.d.ts +1 -1
  23. package/dist/v2/core/resources/geo.d.ts +50 -0
  24. package/dist/v2/core/resources/geo.js +35 -0
  25. package/dist/v2/core/resources/payments.d.ts +19 -1
  26. package/dist/v2/core/resources/payments.js +8 -0
  27. package/dist/v2/core/utils/previewModeIndicator.js +101 -101
  28. package/dist/v2/react/components/FunnelScriptInjector.js +167 -19
  29. package/dist/v2/react/components/StripeExpressButton.d.ts +8 -0
  30. package/dist/v2/react/components/StripeExpressButton.js +22 -1
  31. package/dist/v2/react/hooks/payment-actions/useNgeniusThreedsAction.d.ts +15 -0
  32. package/dist/v2/react/hooks/payment-actions/useNgeniusThreedsAction.js +166 -0
  33. package/dist/v2/react/hooks/payment-actions/usePaymentActionHandler.js +12 -0
  34. package/dist/v2/react/hooks/payment-processing/usePaymentProcessors.js +1 -0
  35. package/dist/v2/react/hooks/useISOData.js +25 -7
  36. package/dist/v2/react/hooks/usePaymentPolling.d.ts +1 -1
  37. package/dist/v2/react/providers/ExpressPaymentMethodsProvider.js +12 -4
  38. package/dist/v2/react/providers/TagadaProvider.js +5 -5
  39. package/dist/v2/standalone/apple-pay-service.d.ts +12 -0
  40. package/dist/v2/standalone/apple-pay-service.js +12 -0
  41. package/dist/v2/standalone/external-tracker.d.ts +1 -1
  42. package/dist/v2/standalone/google-pay-service.d.ts +9 -0
  43. package/dist/v2/standalone/google-pay-service.js +9 -0
  44. package/dist/v2/standalone/index.d.ts +8 -1
  45. package/dist/v2/standalone/index.js +7 -0
  46. package/dist/v2/standalone/payment-service.d.ts +18 -5
  47. package/dist/v2/standalone/payment-service.js +62 -9
  48. package/package.json +115 -114
package/build-cdn.js CHANGED
@@ -1,499 +1,499 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Build script for creating standalone CDN bundles
5
- *
6
- * This creates:
7
- * - dist/external-tracker.min.js - Minified UMD bundle for CDN (tracking only)
8
- * - dist/external-tracker.js - Non-minified for debugging
9
- * - dist/tagada-sdk.min.js - Full standalone SDK bundle for CDN
10
- * - dist/tagada-sdk.js - Non-minified for debugging
11
- *
12
- * Usage:
13
- * node build-cdn.js
14
- * npm run build:cdn
15
- */
16
-
17
- const esbuild = require('esbuild');
18
- const path = require('path');
19
- const fs = require('fs');
20
-
21
- const TRACKER_ENTRY = path.join(__dirname, 'src/v2/standalone/external-tracker.ts');
22
- const SDK_ENTRY = path.join(__dirname, 'src/v2/standalone/index.ts');
23
- const REACT_SDK_ENTRY = path.join(__dirname, 'src/v2/react/index.ts');
24
- const REACT_SDK_MINIMAL_ENTRY = path.join(__dirname, 'src/v2/cdn-react-minimal.ts');
25
- const OUT_DIR = path.join(__dirname, 'dist');
26
-
27
- async function build() {
28
- console.log('šŸ”Ø Building CDN bundles...\n');
29
-
30
- // ==========================================================================
31
- // EXTERNAL TRACKER (lightweight, tracking only)
32
- // ==========================================================================
33
- console.log('šŸ“¦ Building external-tracker...');
34
-
35
- // Build minified UMD bundle
36
- await esbuild.build({
37
- entryPoints: [TRACKER_ENTRY],
38
- bundle: true,
39
- minify: true,
40
- sourcemap: true,
41
- target: ['es2018', 'chrome58', 'firefox57', 'safari11', 'edge79'],
42
- format: 'iife',
43
- globalName: 'TagadaTrackerBundle',
44
- outfile: path.join(OUT_DIR, 'external-tracker.min.js'),
45
- // Don't include React - this is a standalone script
46
- external: [],
47
- // Define globals for browser environment
48
- define: {
49
- 'process.env.NODE_ENV': '"production"',
50
- },
51
- // Footer to expose TagadaTracker on window
52
- footer: {
53
- js: `
54
- // Expose TagadaTracker globally (if not already done in bundle)
55
- if (typeof window !== 'undefined' && TagadaTrackerBundle && TagadaTrackerBundle.TagadaTracker) {
56
- window.TagadaTracker = TagadaTrackerBundle.TagadaTracker;
57
- }
58
- `.trim(),
59
- },
60
- banner: {
61
- js: `/**
62
- * TagadaPay External Tracker v${require('./package.json').version}
63
- * CDN Bundle - Standalone tracking for external pages
64
- * @license MIT
65
- */`,
66
- },
67
- });
68
-
69
- console.log(' āœ… dist/external-tracker.min.js (minified + sourcemap)');
70
-
71
- // Build non-minified version for debugging
72
- await esbuild.build({
73
- entryPoints: [TRACKER_ENTRY],
74
- bundle: true,
75
- minify: false,
76
- sourcemap: false,
77
- target: ['es2018', 'chrome58', 'firefox57', 'safari11', 'edge79'],
78
- format: 'iife',
79
- globalName: 'TagadaTrackerBundle',
80
- outfile: path.join(OUT_DIR, 'external-tracker.js'),
81
- external: [],
82
- define: {
83
- 'process.env.NODE_ENV': '"development"',
84
- },
85
- footer: {
86
- js: `
87
- // Expose TagadaTracker globally
88
- if (typeof window !== 'undefined' && TagadaTrackerBundle && TagadaTrackerBundle.TagadaTracker) {
89
- window.TagadaTracker = TagadaTrackerBundle.TagadaTracker;
90
- }
91
- `.trim(),
92
- },
93
- banner: {
94
- js: `/**
95
- * TagadaPay External Tracker v${require('./package.json').version}
96
- * CDN Bundle - Standalone tracking for external pages (Debug Build)
97
- * @license MIT
98
- */`,
99
- },
100
- });
101
-
102
- console.log(' āœ… dist/external-tracker.js (non-minified for debugging)');
103
-
104
- // ==========================================================================
105
- // FULL STANDALONE SDK (createTagadaClient, config loading, hot reload, etc.)
106
- // ==========================================================================
107
- console.log('\nšŸ“¦ Building tagada-sdk (full standalone SDK)...');
108
-
109
- // Build minified SDK bundle
110
- await esbuild.build({
111
- entryPoints: [SDK_ENTRY],
112
- bundle: true,
113
- minify: true,
114
- sourcemap: true,
115
- target: ['es2018', 'chrome58', 'firefox57', 'safari11', 'edge79'],
116
- format: 'iife',
117
- globalName: 'TagadaSDKBundle',
118
- outfile: path.join(OUT_DIR, 'tagada-sdk.min.js'),
119
- external: [],
120
- define: {
121
- 'process.env.NODE_ENV': '"production"',
122
- },
123
- footer: {
124
- js: `
125
- // Expose SDK under window.tgd namespace (clean, single global)
126
- if (typeof window !== 'undefined' && TagadaSDKBundle) {
127
- window.tgd = window.tgd || {};
128
- // Core
129
- window.tgd.createTagadaClient = TagadaSDKBundle.createTagadaClient;
130
- // Config utilities
131
- window.tgd.getPluginConfig = TagadaSDKBundle.getPluginConfig;
132
- window.tgd.loadPluginConfig = TagadaSDKBundle.loadPluginConfig;
133
- // Hot reload
134
- window.tgd.onConfigUpdate = TagadaSDKBundle.onConfigUpdate;
135
- window.tgd.sendConfigUpdate = TagadaSDKBundle.sendConfigUpdate;
136
- window.tgd.broadcastConfigUpdate = TagadaSDKBundle.broadcastConfigUpdate;
137
- // Currency
138
- window.tgd.formatMoney = TagadaSDKBundle.formatMoney;
139
- // Script injection (auto-runs on load, but can be manually called)
140
- window.tgd.injectStepConfigScripts = TagadaSDKBundle.injectStepConfigScripts;
141
- // Full bundle reference
142
- window.tgd.sdk = TagadaSDKBundle;
143
- }
144
- `.trim(),
145
- },
146
- banner: {
147
- js: `/**
148
- * TagadaPay SDK v${require('./package.json').version}
149
- * CDN Bundle - Full standalone SDK for external/vanilla pages
150
- * Usage: window.tgd.createTagadaClient(), window.tgd.formatMoney(), etc.
151
- * @license MIT
152
- */`,
153
- },
154
- });
155
-
156
- console.log(' āœ… dist/tagada-sdk.min.js (minified + sourcemap)');
157
-
158
- // Build non-minified SDK version for debugging
159
- await esbuild.build({
160
- entryPoints: [SDK_ENTRY],
161
- bundle: true,
162
- minify: false,
163
- sourcemap: false,
164
- target: ['es2018', 'chrome58', 'firefox57', 'safari11', 'edge79'],
165
- format: 'iife',
166
- globalName: 'TagadaSDKBundle',
167
- outfile: path.join(OUT_DIR, 'tagada-sdk.js'),
168
- external: [],
169
- define: {
170
- 'process.env.NODE_ENV': '"development"',
171
- },
172
- footer: {
173
- js: `
174
- // Expose SDK under window.tgd namespace (clean, single global)
175
- if (typeof window !== 'undefined' && TagadaSDKBundle) {
176
- window.tgd = window.tgd || {};
177
- window.tgd.createTagadaClient = TagadaSDKBundle.createTagadaClient;
178
- window.tgd.getPluginConfig = TagadaSDKBundle.getPluginConfig;
179
- window.tgd.loadPluginConfig = TagadaSDKBundle.loadPluginConfig;
180
- window.tgd.onConfigUpdate = TagadaSDKBundle.onConfigUpdate;
181
- window.tgd.sendConfigUpdate = TagadaSDKBundle.sendConfigUpdate;
182
- window.tgd.broadcastConfigUpdate = TagadaSDKBundle.broadcastConfigUpdate;
183
- window.tgd.formatMoney = TagadaSDKBundle.formatMoney;
184
- window.tgd.injectStepConfigScripts = TagadaSDKBundle.injectStepConfigScripts;
185
- window.tgd.sdk = TagadaSDKBundle;
186
- }
187
- `.trim(),
188
- },
189
- banner: {
190
- js: `/**
191
- * TagadaPay SDK v${require('./package.json').version}
192
- * CDN Bundle - Full standalone SDK (Debug Build)
193
- * Usage: window.tgd.createTagadaClient(), window.tgd.formatMoney(), etc.
194
- * @license MIT
195
- */`,
196
- },
197
- });
198
-
199
- console.log(' āœ… dist/tagada-sdk.js (non-minified for debugging)');
200
-
201
- // ==========================================================================
202
- // REACT SDK (TagadaProvider, hooks - for use with React apps via CDN)
203
- // ==========================================================================
204
- console.log('\nšŸ“¦ Building tagada-react-sdk (React hooks & provider)...');
205
-
206
- // Build minified React SDK bundle
207
- await esbuild.build({
208
- entryPoints: [REACT_SDK_ENTRY],
209
- bundle: true,
210
- minify: true,
211
- sourcemap: true,
212
- target: ['es2018', 'chrome58', 'firefox57', 'safari11', 'edge79'],
213
- format: 'iife',
214
- globalName: 'TagadaReactSDKBundle',
215
- outfile: path.join(OUT_DIR, 'tagada-react-sdk.min.js'),
216
- // React is external - expects window.React
217
- external: ['react', 'react-dom'],
218
- define: {
219
- 'process.env.NODE_ENV': '"production"',
220
- },
221
- footer: {
222
- js: `
223
- // Expose React SDK under window.tgd namespace
224
- if (typeof window !== 'undefined' && TagadaReactSDKBundle) {
225
- window.tgd = window.tgd || {};
226
- // Provider
227
- window.tgd.TagadaProvider = TagadaReactSDKBundle.TagadaProvider;
228
- window.tgd.useTagadaContext = TagadaReactSDKBundle.useTagadaContext;
229
- // Core hooks
230
- window.tgd.useCheckout = TagadaReactSDKBundle.useCheckout;
231
- window.tgd.useCheckoutSession = TagadaReactSDKBundle.useCheckoutSession;
232
- window.tgd.useSession = TagadaReactSDKBundle.useSession;
233
- window.tgd.useCustomer = TagadaReactSDKBundle.useCustomer;
234
- window.tgd.useCustomerInfos = TagadaReactSDKBundle.useCustomerInfos;
235
- window.tgd.useEnvironment = TagadaReactSDKBundle.useEnvironment;
236
- window.tgd.useCurrency = TagadaReactSDKBundle.useCurrency;
237
- window.tgd.useLocale = TagadaReactSDKBundle.useLocale;
238
- // Commerce hooks
239
- window.tgd.useShippingRates = TagadaReactSDKBundle.useShippingRates;
240
- window.tgd.useDiscounts = TagadaReactSDKBundle.useDiscounts;
241
- window.tgd.useOrderBump = TagadaReactSDKBundle.useOrderBump;
242
- window.tgd.useOrderBumpV2 = TagadaReactSDKBundle.useOrderBumpV2;
243
- window.tgd.useOrderBumpV3 = TagadaReactSDKBundle.useOrderBumpV3;
244
- window.tgd.useProducts = TagadaReactSDKBundle.useProducts;
245
- window.tgd.useOffers = TagadaReactSDKBundle.useOffers;
246
- window.tgd.usePostPurchases = TagadaReactSDKBundle.usePostPurchases;
247
- // Payment hooks
248
- window.tgd.usePayment = TagadaReactSDKBundle.usePayment;
249
- window.tgd.useThreeds = TagadaReactSDKBundle.useThreeds;
250
- window.tgd.useApplePay = TagadaReactSDKBundle.useApplePay;
251
- window.tgd.useGooglePay = TagadaReactSDKBundle.useGooglePay;
252
- window.tgd.useExpressPaymentMethods = TagadaReactSDKBundle.useExpressPaymentMethods;
253
- window.tgd.ExpressPaymentMethodsProvider = TagadaReactSDKBundle.ExpressPaymentMethodsProvider;
254
- // Utility hooks
255
- window.tgd.useGeoLocation = TagadaReactSDKBundle.useGeoLocation;
256
- window.tgd.useGoogleAutocomplete = TagadaReactSDKBundle.useGoogleAutocomplete;
257
- window.tgd.useISOData = TagadaReactSDKBundle.useISOData;
258
- window.tgd.usePluginConfig = TagadaReactSDKBundle.usePluginConfig;
259
- window.tgd.useTranslations = TagadaReactSDKBundle.useTranslations;
260
- // Funnel
261
- window.tgd.useFunnel = TagadaReactSDKBundle.useFunnel;
262
- // Components
263
- window.tgd.Button = TagadaReactSDKBundle.Button;
264
- window.tgd.ApplePayButton = TagadaReactSDKBundle.ApplePayButton;
265
- window.tgd.GooglePayButton = TagadaReactSDKBundle.GooglePayButton;
266
- // Utilities
267
- window.tgd.formatMoney = TagadaReactSDKBundle.formatMoney;
268
- // Full bundle reference
269
- window.tgd.react = TagadaReactSDKBundle;
270
- }
271
- `.trim(),
272
- },
273
- banner: {
274
- js: `/**
275
- * TagadaPay React SDK v${require('./package.json').version}
276
- * CDN Bundle - React hooks and TagadaProvider for checkout integration
277
- * Requires: React 18+ loaded before this script
278
- * Usage: window.tgd.TagadaProvider, window.tgd.useCheckout, etc.
279
- * @license MIT
280
- */`,
281
- },
282
- });
283
-
284
- console.log(' āœ… dist/tagada-react-sdk.min.js (minified + sourcemap)');
285
-
286
- // Build non-minified React SDK version for debugging
287
- await esbuild.build({
288
- entryPoints: [REACT_SDK_ENTRY],
289
- bundle: true,
290
- minify: false,
291
- sourcemap: false,
292
- target: ['es2018', 'chrome58', 'firefox57', 'safari11', 'edge79'],
293
- format: 'iife',
294
- globalName: 'TagadaReactSDKBundle',
295
- outfile: path.join(OUT_DIR, 'tagada-react-sdk.js'),
296
- external: ['react', 'react-dom'],
297
- define: {
298
- 'process.env.NODE_ENV': '"development"',
299
- },
300
- footer: {
301
- js: `
302
- // Expose React SDK under window.tgd namespace
303
- if (typeof window !== 'undefined' && TagadaReactSDKBundle) {
304
- window.tgd = window.tgd || {};
305
- window.tgd.TagadaProvider = TagadaReactSDKBundle.TagadaProvider;
306
- window.tgd.useTagadaContext = TagadaReactSDKBundle.useTagadaContext;
307
- window.tgd.useCheckout = TagadaReactSDKBundle.useCheckout;
308
- window.tgd.useCheckoutSession = TagadaReactSDKBundle.useCheckoutSession;
309
- window.tgd.useSession = TagadaReactSDKBundle.useSession;
310
- window.tgd.useCustomer = TagadaReactSDKBundle.useCustomer;
311
- window.tgd.useCustomerInfos = TagadaReactSDKBundle.useCustomerInfos;
312
- window.tgd.useEnvironment = TagadaReactSDKBundle.useEnvironment;
313
- window.tgd.useCurrency = TagadaReactSDKBundle.useCurrency;
314
- window.tgd.useLocale = TagadaReactSDKBundle.useLocale;
315
- window.tgd.useShippingRates = TagadaReactSDKBundle.useShippingRates;
316
- window.tgd.useDiscounts = TagadaReactSDKBundle.useDiscounts;
317
- window.tgd.useOrderBump = TagadaReactSDKBundle.useOrderBump;
318
- window.tgd.useOrderBumpV2 = TagadaReactSDKBundle.useOrderBumpV2;
319
- window.tgd.useOrderBumpV3 = TagadaReactSDKBundle.useOrderBumpV3;
320
- window.tgd.useProducts = TagadaReactSDKBundle.useProducts;
321
- window.tgd.useOffers = TagadaReactSDKBundle.useOffers;
322
- window.tgd.usePostPurchases = TagadaReactSDKBundle.usePostPurchases;
323
- window.tgd.usePayment = TagadaReactSDKBundle.usePayment;
324
- window.tgd.useThreeds = TagadaReactSDKBundle.useThreeds;
325
- window.tgd.useApplePay = TagadaReactSDKBundle.useApplePay;
326
- window.tgd.useGooglePay = TagadaReactSDKBundle.useGooglePay;
327
- window.tgd.useExpressPaymentMethods = TagadaReactSDKBundle.useExpressPaymentMethods;
328
- window.tgd.ExpressPaymentMethodsProvider = TagadaReactSDKBundle.ExpressPaymentMethodsProvider;
329
- window.tgd.useGeoLocation = TagadaReactSDKBundle.useGeoLocation;
330
- window.tgd.useGoogleAutocomplete = TagadaReactSDKBundle.useGoogleAutocomplete;
331
- window.tgd.useISOData = TagadaReactSDKBundle.useISOData;
332
- window.tgd.usePluginConfig = TagadaReactSDKBundle.usePluginConfig;
333
- window.tgd.useTranslations = TagadaReactSDKBundle.useTranslations;
334
- window.tgd.useFunnel = TagadaReactSDKBundle.useFunnel;
335
- window.tgd.Button = TagadaReactSDKBundle.Button;
336
- window.tgd.ApplePayButton = TagadaReactSDKBundle.ApplePayButton;
337
- window.tgd.GooglePayButton = TagadaReactSDKBundle.GooglePayButton;
338
- window.tgd.formatMoney = TagadaReactSDKBundle.formatMoney;
339
- window.tgd.react = TagadaReactSDKBundle;
340
- }
341
- `.trim(),
342
- },
343
- banner: {
344
- js: `/**
345
- * TagadaPay React SDK v${require('./package.json').version}
346
- * CDN Bundle - React hooks and TagadaProvider (Debug Build)
347
- * @license MIT
348
- */`,
349
- },
350
- });
351
-
352
- console.log(' āœ… dist/tagada-react-sdk.js (non-minified for debugging)');
353
-
354
- // ==========================================================================
355
- // MINIMAL REACT SDK (TagadaProvider + essential checkout hooks only)
356
- // ==========================================================================
357
- console.log('\nšŸ“¦ Building tagada-react-sdk-minimal (slim checkout SDK)...');
358
-
359
- // Plugin to replace React imports with window globals
360
- const reactGlobalsPlugin = {
361
- name: 'react-globals',
362
- setup(build) {
363
- // Intercept react imports and return window globals
364
- build.onResolve({ filter: /^react(-dom)?(\/.*)?$/ }, args => ({
365
- path: args.path,
366
- namespace: 'react-global',
367
- }));
368
-
369
- build.onLoad({ filter: /.*/, namespace: 'react-global' }, args => {
370
- if (args.path === 'react') {
371
- return {
372
- contents: 'module.exports = window.React;',
373
- loader: 'js',
374
- };
375
- }
376
- // Handle JSX runtime - map to React.createElement
377
- if (args.path === 'react/jsx-runtime' || args.path === 'react/jsx-dev-runtime') {
378
- return {
379
- contents: `
380
- var React = window.React;
381
- module.exports = {
382
- jsx: React.createElement,
383
- jsxs: React.createElement,
384
- jsxDEV: React.createElement,
385
- Fragment: React.Fragment,
386
- };
387
- `,
388
- loader: 'js',
389
- };
390
- }
391
- if (args.path === 'react-dom' || args.path === 'react-dom/client') {
392
- return {
393
- contents: 'module.exports = window.ReactDOM;',
394
- loader: 'js',
395
- };
396
- }
397
- return { contents: 'module.exports = {};', loader: 'js' };
398
- });
399
- },
400
- };
401
-
402
- // Build minified minimal React SDK bundle
403
- await esbuild.build({
404
- entryPoints: [REACT_SDK_MINIMAL_ENTRY],
405
- bundle: true,
406
- minify: true,
407
- sourcemap: true,
408
- target: ['es2018', 'chrome58', 'firefox57', 'safari11', 'edge79'],
409
- format: 'iife',
410
- globalName: 'TagadaReactMinimalBundle',
411
- outfile: path.join(OUT_DIR, 'tagada-react-sdk-minimal.min.js'),
412
- plugins: [reactGlobalsPlugin],
413
- define: {
414
- 'process.env.NODE_ENV': '"production"',
415
- },
416
- footer: {
417
- js: `
418
- // Expose minimal React SDK under window.tgd namespace
419
- if (typeof window !== 'undefined' && TagadaReactMinimalBundle) {
420
- window.tgd = window.tgd || {};
421
- // Provider
422
- window.tgd.TagadaProvider = TagadaReactMinimalBundle.TagadaProvider;
423
- window.tgd.useTagadaContext = TagadaReactMinimalBundle.useTagadaContext;
424
- // Core checkout hooks
425
- window.tgd.useCheckout = TagadaReactMinimalBundle.useCheckout;
426
- window.tgd.useShippingRates = TagadaReactMinimalBundle.useShippingRates;
427
- window.tgd.useDiscounts = TagadaReactMinimalBundle.useDiscounts;
428
- window.tgd.useOrderBump = TagadaReactMinimalBundle.useOrderBump;
429
- window.tgd.usePostPurchases = TagadaReactMinimalBundle.usePostPurchases;
430
- window.tgd.usePayment = TagadaReactMinimalBundle.usePayment;
431
- window.tgd.useThreeds = TagadaReactMinimalBundle.useThreeds;
432
- // Utilities
433
- window.tgd.useCurrency = TagadaReactMinimalBundle.useCurrency;
434
- window.tgd.usePluginConfig = TagadaReactMinimalBundle.usePluginConfig;
435
- window.tgd.useFunnel = TagadaReactMinimalBundle.useFunnel;
436
- window.tgd.formatMoney = TagadaReactMinimalBundle.formatMoney;
437
- // Mark as minimal
438
- window.tgd._minimal = true;
439
- }
440
- `.trim(),
441
- },
442
- banner: {
443
- js: `/**
444
- * TagadaPay React SDK MINIMAL v${require('./package.json').version}
445
- * CDN Bundle - Slim checkout SDK (TagadaProvider + essential hooks only)
446
- * Requires: React 18+ loaded before this script
447
- * For full SDK with all hooks, use tagada-react-sdk.min.js instead
448
- * @license MIT
449
- */`,
450
- },
451
- });
452
-
453
- console.log(' āœ… dist/tagada-react-sdk-minimal.min.js (minified + sourcemap)');
454
-
455
- // Get file sizes
456
- const trackerMinSize = fs.statSync(path.join(OUT_DIR, 'external-tracker.min.js')).size;
457
- const trackerFullSize = fs.statSync(path.join(OUT_DIR, 'external-tracker.js')).size;
458
- const sdkMinSize = fs.statSync(path.join(OUT_DIR, 'tagada-sdk.min.js')).size;
459
- const sdkFullSize = fs.statSync(path.join(OUT_DIR, 'tagada-sdk.js')).size;
460
- const reactSdkMinSize = fs.statSync(path.join(OUT_DIR, 'tagada-react-sdk.min.js')).size;
461
- const reactSdkFullSize = fs.statSync(path.join(OUT_DIR, 'tagada-react-sdk.js')).size;
462
- const reactSdkMinimalSize = fs.statSync(path.join(OUT_DIR, 'tagada-react-sdk-minimal.min.js')).size;
463
-
464
- console.log('\nšŸ“¦ Bundle sizes:');
465
- console.log(` external-tracker.min.js: ${(trackerMinSize / 1024).toFixed(2)} KB`);
466
- console.log(` external-tracker.js: ${(trackerFullSize / 1024).toFixed(2)} KB`);
467
- console.log(` tagada-sdk.min.js: ${(sdkMinSize / 1024).toFixed(2)} KB`);
468
- console.log(` tagada-sdk.js: ${(sdkFullSize / 1024).toFixed(2)} KB`);
469
- console.log(` tagada-react-sdk.min.js: ${(reactSdkMinSize / 1024).toFixed(2)} KB (full)`);
470
- console.log(` tagada-react-sdk.js: ${(reactSdkFullSize / 1024).toFixed(2)} KB`);
471
- console.log(` tagada-react-sdk-minimal.min.js: ${(reactSdkMinimalSize / 1024).toFixed(2)} KB (slim) ⭐`);
472
-
473
- console.log('\n✨ CDN build complete!\n');
474
- console.log('Usage via CDN:');
475
- console.log('');
476
- console.log(' // External Tracker (lightweight, tracking only):');
477
- console.log(' <script src="https://cdn.jsdelivr.net/npm/@tagadapay/plugin-sdk/dist/external-tracker.min.js"></script>');
478
- console.log(' <script>TagadaTracker.init({ storeId: "store_xxx", ... });</script>');
479
- console.log('');
480
- console.log(' // Full SDK (createTagadaClient, config, hot reload):');
481
- console.log(' <script src="https://cdn.jsdelivr.net/npm/@tagadapay/plugin-sdk/dist/tagada-sdk.min.js"></script>');
482
- console.log(' <script>');
483
- console.log(' const client = window.tgd.createTagadaClient({ features: { funnel: true } });');
484
- console.log(' client.subscribe((state) => console.log(state));');
485
- console.log(' </script>');
486
- console.log('');
487
- console.log(' // React SDK (hooks & TagadaProvider - requires React 18+):');
488
- console.log(' <script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>');
489
- console.log(' <script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>');
490
- console.log(' <script src="https://cdn.jsdelivr.net/npm/@tagadapay/plugin-sdk/dist/tagada-react-sdk.min.js"></script>');
491
- console.log(' // Then use: window.tgd.TagadaProvider, window.tgd.useCheckout, etc.\n');
492
- }
493
-
494
- build().catch((err) => {
495
- console.error('Build failed:', err);
496
- process.exit(1);
497
- });
498
-
499
-
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Build script for creating standalone CDN bundles
5
+ *
6
+ * This creates:
7
+ * - dist/external-tracker.min.js - Minified UMD bundle for CDN (tracking only)
8
+ * - dist/external-tracker.js - Non-minified for debugging
9
+ * - dist/tagada-sdk.min.js - Full standalone SDK bundle for CDN
10
+ * - dist/tagada-sdk.js - Non-minified for debugging
11
+ *
12
+ * Usage:
13
+ * node build-cdn.js
14
+ * npm run build:cdn
15
+ */
16
+
17
+ const esbuild = require('esbuild');
18
+ const path = require('path');
19
+ const fs = require('fs');
20
+
21
+ const TRACKER_ENTRY = path.join(__dirname, 'src/v2/standalone/external-tracker.ts');
22
+ const SDK_ENTRY = path.join(__dirname, 'src/v2/standalone/index.ts');
23
+ const REACT_SDK_ENTRY = path.join(__dirname, 'src/v2/react/index.ts');
24
+ const REACT_SDK_MINIMAL_ENTRY = path.join(__dirname, 'src/v2/cdn-react-minimal.ts');
25
+ const OUT_DIR = path.join(__dirname, 'dist');
26
+
27
+ async function build() {
28
+ console.log('šŸ”Ø Building CDN bundles...\n');
29
+
30
+ // ==========================================================================
31
+ // EXTERNAL TRACKER (lightweight, tracking only)
32
+ // ==========================================================================
33
+ console.log('šŸ“¦ Building external-tracker...');
34
+
35
+ // Build minified UMD bundle
36
+ await esbuild.build({
37
+ entryPoints: [TRACKER_ENTRY],
38
+ bundle: true,
39
+ minify: true,
40
+ sourcemap: true,
41
+ target: ['es2018', 'chrome58', 'firefox57', 'safari11', 'edge79'],
42
+ format: 'iife',
43
+ globalName: 'TagadaTrackerBundle',
44
+ outfile: path.join(OUT_DIR, 'external-tracker.min.js'),
45
+ // Don't include React - this is a standalone script
46
+ external: [],
47
+ // Define globals for browser environment
48
+ define: {
49
+ 'process.env.NODE_ENV': '"production"',
50
+ },
51
+ // Footer to expose TagadaTracker on window
52
+ footer: {
53
+ js: `
54
+ // Expose TagadaTracker globally (if not already done in bundle)
55
+ if (typeof window !== 'undefined' && TagadaTrackerBundle && TagadaTrackerBundle.TagadaTracker) {
56
+ window.TagadaTracker = TagadaTrackerBundle.TagadaTracker;
57
+ }
58
+ `.trim(),
59
+ },
60
+ banner: {
61
+ js: `/**
62
+ * TagadaPay External Tracker v${require('./package.json').version}
63
+ * CDN Bundle - Standalone tracking for external pages
64
+ * @license MIT
65
+ */`,
66
+ },
67
+ });
68
+
69
+ console.log(' āœ… dist/external-tracker.min.js (minified + sourcemap)');
70
+
71
+ // Build non-minified version for debugging
72
+ await esbuild.build({
73
+ entryPoints: [TRACKER_ENTRY],
74
+ bundle: true,
75
+ minify: false,
76
+ sourcemap: false,
77
+ target: ['es2018', 'chrome58', 'firefox57', 'safari11', 'edge79'],
78
+ format: 'iife',
79
+ globalName: 'TagadaTrackerBundle',
80
+ outfile: path.join(OUT_DIR, 'external-tracker.js'),
81
+ external: [],
82
+ define: {
83
+ 'process.env.NODE_ENV': '"development"',
84
+ },
85
+ footer: {
86
+ js: `
87
+ // Expose TagadaTracker globally
88
+ if (typeof window !== 'undefined' && TagadaTrackerBundle && TagadaTrackerBundle.TagadaTracker) {
89
+ window.TagadaTracker = TagadaTrackerBundle.TagadaTracker;
90
+ }
91
+ `.trim(),
92
+ },
93
+ banner: {
94
+ js: `/**
95
+ * TagadaPay External Tracker v${require('./package.json').version}
96
+ * CDN Bundle - Standalone tracking for external pages (Debug Build)
97
+ * @license MIT
98
+ */`,
99
+ },
100
+ });
101
+
102
+ console.log(' āœ… dist/external-tracker.js (non-minified for debugging)');
103
+
104
+ // ==========================================================================
105
+ // FULL STANDALONE SDK (createTagadaClient, config loading, hot reload, etc.)
106
+ // ==========================================================================
107
+ console.log('\nšŸ“¦ Building tagada-sdk (full standalone SDK)...');
108
+
109
+ // Build minified SDK bundle
110
+ await esbuild.build({
111
+ entryPoints: [SDK_ENTRY],
112
+ bundle: true,
113
+ minify: true,
114
+ sourcemap: true,
115
+ target: ['es2018', 'chrome58', 'firefox57', 'safari11', 'edge79'],
116
+ format: 'iife',
117
+ globalName: 'TagadaSDKBundle',
118
+ outfile: path.join(OUT_DIR, 'tagada-sdk.min.js'),
119
+ external: [],
120
+ define: {
121
+ 'process.env.NODE_ENV': '"production"',
122
+ },
123
+ footer: {
124
+ js: `
125
+ // Expose SDK under window.tgd namespace (clean, single global)
126
+ if (typeof window !== 'undefined' && TagadaSDKBundle) {
127
+ window.tgd = window.tgd || {};
128
+ // Core
129
+ window.tgd.createTagadaClient = TagadaSDKBundle.createTagadaClient;
130
+ // Config utilities
131
+ window.tgd.getPluginConfig = TagadaSDKBundle.getPluginConfig;
132
+ window.tgd.loadPluginConfig = TagadaSDKBundle.loadPluginConfig;
133
+ // Hot reload
134
+ window.tgd.onConfigUpdate = TagadaSDKBundle.onConfigUpdate;
135
+ window.tgd.sendConfigUpdate = TagadaSDKBundle.sendConfigUpdate;
136
+ window.tgd.broadcastConfigUpdate = TagadaSDKBundle.broadcastConfigUpdate;
137
+ // Currency
138
+ window.tgd.formatMoney = TagadaSDKBundle.formatMoney;
139
+ // Script injection (auto-runs on load, but can be manually called)
140
+ window.tgd.injectStepConfigScripts = TagadaSDKBundle.injectStepConfigScripts;
141
+ // Full bundle reference
142
+ window.tgd.sdk = TagadaSDKBundle;
143
+ }
144
+ `.trim(),
145
+ },
146
+ banner: {
147
+ js: `/**
148
+ * TagadaPay SDK v${require('./package.json').version}
149
+ * CDN Bundle - Full standalone SDK for external/vanilla pages
150
+ * Usage: window.tgd.createTagadaClient(), window.tgd.formatMoney(), etc.
151
+ * @license MIT
152
+ */`,
153
+ },
154
+ });
155
+
156
+ console.log(' āœ… dist/tagada-sdk.min.js (minified + sourcemap)');
157
+
158
+ // Build non-minified SDK version for debugging
159
+ await esbuild.build({
160
+ entryPoints: [SDK_ENTRY],
161
+ bundle: true,
162
+ minify: false,
163
+ sourcemap: false,
164
+ target: ['es2018', 'chrome58', 'firefox57', 'safari11', 'edge79'],
165
+ format: 'iife',
166
+ globalName: 'TagadaSDKBundle',
167
+ outfile: path.join(OUT_DIR, 'tagada-sdk.js'),
168
+ external: [],
169
+ define: {
170
+ 'process.env.NODE_ENV': '"development"',
171
+ },
172
+ footer: {
173
+ js: `
174
+ // Expose SDK under window.tgd namespace (clean, single global)
175
+ if (typeof window !== 'undefined' && TagadaSDKBundle) {
176
+ window.tgd = window.tgd || {};
177
+ window.tgd.createTagadaClient = TagadaSDKBundle.createTagadaClient;
178
+ window.tgd.getPluginConfig = TagadaSDKBundle.getPluginConfig;
179
+ window.tgd.loadPluginConfig = TagadaSDKBundle.loadPluginConfig;
180
+ window.tgd.onConfigUpdate = TagadaSDKBundle.onConfigUpdate;
181
+ window.tgd.sendConfigUpdate = TagadaSDKBundle.sendConfigUpdate;
182
+ window.tgd.broadcastConfigUpdate = TagadaSDKBundle.broadcastConfigUpdate;
183
+ window.tgd.formatMoney = TagadaSDKBundle.formatMoney;
184
+ window.tgd.injectStepConfigScripts = TagadaSDKBundle.injectStepConfigScripts;
185
+ window.tgd.sdk = TagadaSDKBundle;
186
+ }
187
+ `.trim(),
188
+ },
189
+ banner: {
190
+ js: `/**
191
+ * TagadaPay SDK v${require('./package.json').version}
192
+ * CDN Bundle - Full standalone SDK (Debug Build)
193
+ * Usage: window.tgd.createTagadaClient(), window.tgd.formatMoney(), etc.
194
+ * @license MIT
195
+ */`,
196
+ },
197
+ });
198
+
199
+ console.log(' āœ… dist/tagada-sdk.js (non-minified for debugging)');
200
+
201
+ // ==========================================================================
202
+ // REACT SDK (TagadaProvider, hooks - for use with React apps via CDN)
203
+ // ==========================================================================
204
+ console.log('\nšŸ“¦ Building tagada-react-sdk (React hooks & provider)...');
205
+
206
+ // Build minified React SDK bundle
207
+ await esbuild.build({
208
+ entryPoints: [REACT_SDK_ENTRY],
209
+ bundle: true,
210
+ minify: true,
211
+ sourcemap: true,
212
+ target: ['es2018', 'chrome58', 'firefox57', 'safari11', 'edge79'],
213
+ format: 'iife',
214
+ globalName: 'TagadaReactSDKBundle',
215
+ outfile: path.join(OUT_DIR, 'tagada-react-sdk.min.js'),
216
+ // React is external - expects window.React
217
+ external: ['react', 'react-dom'],
218
+ define: {
219
+ 'process.env.NODE_ENV': '"production"',
220
+ },
221
+ footer: {
222
+ js: `
223
+ // Expose React SDK under window.tgd namespace
224
+ if (typeof window !== 'undefined' && TagadaReactSDKBundle) {
225
+ window.tgd = window.tgd || {};
226
+ // Provider
227
+ window.tgd.TagadaProvider = TagadaReactSDKBundle.TagadaProvider;
228
+ window.tgd.useTagadaContext = TagadaReactSDKBundle.useTagadaContext;
229
+ // Core hooks
230
+ window.tgd.useCheckout = TagadaReactSDKBundle.useCheckout;
231
+ window.tgd.useCheckoutSession = TagadaReactSDKBundle.useCheckoutSession;
232
+ window.tgd.useSession = TagadaReactSDKBundle.useSession;
233
+ window.tgd.useCustomer = TagadaReactSDKBundle.useCustomer;
234
+ window.tgd.useCustomerInfos = TagadaReactSDKBundle.useCustomerInfos;
235
+ window.tgd.useEnvironment = TagadaReactSDKBundle.useEnvironment;
236
+ window.tgd.useCurrency = TagadaReactSDKBundle.useCurrency;
237
+ window.tgd.useLocale = TagadaReactSDKBundle.useLocale;
238
+ // Commerce hooks
239
+ window.tgd.useShippingRates = TagadaReactSDKBundle.useShippingRates;
240
+ window.tgd.useDiscounts = TagadaReactSDKBundle.useDiscounts;
241
+ window.tgd.useOrderBump = TagadaReactSDKBundle.useOrderBump;
242
+ window.tgd.useOrderBumpV2 = TagadaReactSDKBundle.useOrderBumpV2;
243
+ window.tgd.useOrderBumpV3 = TagadaReactSDKBundle.useOrderBumpV3;
244
+ window.tgd.useProducts = TagadaReactSDKBundle.useProducts;
245
+ window.tgd.useOffers = TagadaReactSDKBundle.useOffers;
246
+ window.tgd.usePostPurchases = TagadaReactSDKBundle.usePostPurchases;
247
+ // Payment hooks
248
+ window.tgd.usePayment = TagadaReactSDKBundle.usePayment;
249
+ window.tgd.useThreeds = TagadaReactSDKBundle.useThreeds;
250
+ window.tgd.useApplePay = TagadaReactSDKBundle.useApplePay;
251
+ window.tgd.useGooglePay = TagadaReactSDKBundle.useGooglePay;
252
+ window.tgd.useExpressPaymentMethods = TagadaReactSDKBundle.useExpressPaymentMethods;
253
+ window.tgd.ExpressPaymentMethodsProvider = TagadaReactSDKBundle.ExpressPaymentMethodsProvider;
254
+ // Utility hooks
255
+ window.tgd.useGeoLocation = TagadaReactSDKBundle.useGeoLocation;
256
+ window.tgd.useGoogleAutocomplete = TagadaReactSDKBundle.useGoogleAutocomplete;
257
+ window.tgd.useISOData = TagadaReactSDKBundle.useISOData;
258
+ window.tgd.usePluginConfig = TagadaReactSDKBundle.usePluginConfig;
259
+ window.tgd.useTranslations = TagadaReactSDKBundle.useTranslations;
260
+ // Funnel
261
+ window.tgd.useFunnel = TagadaReactSDKBundle.useFunnel;
262
+ // Components
263
+ window.tgd.Button = TagadaReactSDKBundle.Button;
264
+ window.tgd.ApplePayButton = TagadaReactSDKBundle.ApplePayButton;
265
+ window.tgd.GooglePayButton = TagadaReactSDKBundle.GooglePayButton;
266
+ // Utilities
267
+ window.tgd.formatMoney = TagadaReactSDKBundle.formatMoney;
268
+ // Full bundle reference
269
+ window.tgd.react = TagadaReactSDKBundle;
270
+ }
271
+ `.trim(),
272
+ },
273
+ banner: {
274
+ js: `/**
275
+ * TagadaPay React SDK v${require('./package.json').version}
276
+ * CDN Bundle - React hooks and TagadaProvider for checkout integration
277
+ * Requires: React 18+ loaded before this script
278
+ * Usage: window.tgd.TagadaProvider, window.tgd.useCheckout, etc.
279
+ * @license MIT
280
+ */`,
281
+ },
282
+ });
283
+
284
+ console.log(' āœ… dist/tagada-react-sdk.min.js (minified + sourcemap)');
285
+
286
+ // Build non-minified React SDK version for debugging
287
+ await esbuild.build({
288
+ entryPoints: [REACT_SDK_ENTRY],
289
+ bundle: true,
290
+ minify: false,
291
+ sourcemap: false,
292
+ target: ['es2018', 'chrome58', 'firefox57', 'safari11', 'edge79'],
293
+ format: 'iife',
294
+ globalName: 'TagadaReactSDKBundle',
295
+ outfile: path.join(OUT_DIR, 'tagada-react-sdk.js'),
296
+ external: ['react', 'react-dom'],
297
+ define: {
298
+ 'process.env.NODE_ENV': '"development"',
299
+ },
300
+ footer: {
301
+ js: `
302
+ // Expose React SDK under window.tgd namespace
303
+ if (typeof window !== 'undefined' && TagadaReactSDKBundle) {
304
+ window.tgd = window.tgd || {};
305
+ window.tgd.TagadaProvider = TagadaReactSDKBundle.TagadaProvider;
306
+ window.tgd.useTagadaContext = TagadaReactSDKBundle.useTagadaContext;
307
+ window.tgd.useCheckout = TagadaReactSDKBundle.useCheckout;
308
+ window.tgd.useCheckoutSession = TagadaReactSDKBundle.useCheckoutSession;
309
+ window.tgd.useSession = TagadaReactSDKBundle.useSession;
310
+ window.tgd.useCustomer = TagadaReactSDKBundle.useCustomer;
311
+ window.tgd.useCustomerInfos = TagadaReactSDKBundle.useCustomerInfos;
312
+ window.tgd.useEnvironment = TagadaReactSDKBundle.useEnvironment;
313
+ window.tgd.useCurrency = TagadaReactSDKBundle.useCurrency;
314
+ window.tgd.useLocale = TagadaReactSDKBundle.useLocale;
315
+ window.tgd.useShippingRates = TagadaReactSDKBundle.useShippingRates;
316
+ window.tgd.useDiscounts = TagadaReactSDKBundle.useDiscounts;
317
+ window.tgd.useOrderBump = TagadaReactSDKBundle.useOrderBump;
318
+ window.tgd.useOrderBumpV2 = TagadaReactSDKBundle.useOrderBumpV2;
319
+ window.tgd.useOrderBumpV3 = TagadaReactSDKBundle.useOrderBumpV3;
320
+ window.tgd.useProducts = TagadaReactSDKBundle.useProducts;
321
+ window.tgd.useOffers = TagadaReactSDKBundle.useOffers;
322
+ window.tgd.usePostPurchases = TagadaReactSDKBundle.usePostPurchases;
323
+ window.tgd.usePayment = TagadaReactSDKBundle.usePayment;
324
+ window.tgd.useThreeds = TagadaReactSDKBundle.useThreeds;
325
+ window.tgd.useApplePay = TagadaReactSDKBundle.useApplePay;
326
+ window.tgd.useGooglePay = TagadaReactSDKBundle.useGooglePay;
327
+ window.tgd.useExpressPaymentMethods = TagadaReactSDKBundle.useExpressPaymentMethods;
328
+ window.tgd.ExpressPaymentMethodsProvider = TagadaReactSDKBundle.ExpressPaymentMethodsProvider;
329
+ window.tgd.useGeoLocation = TagadaReactSDKBundle.useGeoLocation;
330
+ window.tgd.useGoogleAutocomplete = TagadaReactSDKBundle.useGoogleAutocomplete;
331
+ window.tgd.useISOData = TagadaReactSDKBundle.useISOData;
332
+ window.tgd.usePluginConfig = TagadaReactSDKBundle.usePluginConfig;
333
+ window.tgd.useTranslations = TagadaReactSDKBundle.useTranslations;
334
+ window.tgd.useFunnel = TagadaReactSDKBundle.useFunnel;
335
+ window.tgd.Button = TagadaReactSDKBundle.Button;
336
+ window.tgd.ApplePayButton = TagadaReactSDKBundle.ApplePayButton;
337
+ window.tgd.GooglePayButton = TagadaReactSDKBundle.GooglePayButton;
338
+ window.tgd.formatMoney = TagadaReactSDKBundle.formatMoney;
339
+ window.tgd.react = TagadaReactSDKBundle;
340
+ }
341
+ `.trim(),
342
+ },
343
+ banner: {
344
+ js: `/**
345
+ * TagadaPay React SDK v${require('./package.json').version}
346
+ * CDN Bundle - React hooks and TagadaProvider (Debug Build)
347
+ * @license MIT
348
+ */`,
349
+ },
350
+ });
351
+
352
+ console.log(' āœ… dist/tagada-react-sdk.js (non-minified for debugging)');
353
+
354
+ // ==========================================================================
355
+ // MINIMAL REACT SDK (TagadaProvider + essential checkout hooks only)
356
+ // ==========================================================================
357
+ console.log('\nšŸ“¦ Building tagada-react-sdk-minimal (slim checkout SDK)...');
358
+
359
+ // Plugin to replace React imports with window globals
360
+ const reactGlobalsPlugin = {
361
+ name: 'react-globals',
362
+ setup(build) {
363
+ // Intercept react imports and return window globals
364
+ build.onResolve({ filter: /^react(-dom)?(\/.*)?$/ }, args => ({
365
+ path: args.path,
366
+ namespace: 'react-global',
367
+ }));
368
+
369
+ build.onLoad({ filter: /.*/, namespace: 'react-global' }, args => {
370
+ if (args.path === 'react') {
371
+ return {
372
+ contents: 'module.exports = window.React;',
373
+ loader: 'js',
374
+ };
375
+ }
376
+ // Handle JSX runtime - map to React.createElement
377
+ if (args.path === 'react/jsx-runtime' || args.path === 'react/jsx-dev-runtime') {
378
+ return {
379
+ contents: `
380
+ var React = window.React;
381
+ module.exports = {
382
+ jsx: React.createElement,
383
+ jsxs: React.createElement,
384
+ jsxDEV: React.createElement,
385
+ Fragment: React.Fragment,
386
+ };
387
+ `,
388
+ loader: 'js',
389
+ };
390
+ }
391
+ if (args.path === 'react-dom' || args.path === 'react-dom/client') {
392
+ return {
393
+ contents: 'module.exports = window.ReactDOM;',
394
+ loader: 'js',
395
+ };
396
+ }
397
+ return { contents: 'module.exports = {};', loader: 'js' };
398
+ });
399
+ },
400
+ };
401
+
402
+ // Build minified minimal React SDK bundle
403
+ await esbuild.build({
404
+ entryPoints: [REACT_SDK_MINIMAL_ENTRY],
405
+ bundle: true,
406
+ minify: true,
407
+ sourcemap: true,
408
+ target: ['es2018', 'chrome58', 'firefox57', 'safari11', 'edge79'],
409
+ format: 'iife',
410
+ globalName: 'TagadaReactMinimalBundle',
411
+ outfile: path.join(OUT_DIR, 'tagada-react-sdk-minimal.min.js'),
412
+ plugins: [reactGlobalsPlugin],
413
+ define: {
414
+ 'process.env.NODE_ENV': '"production"',
415
+ },
416
+ footer: {
417
+ js: `
418
+ // Expose minimal React SDK under window.tgd namespace
419
+ if (typeof window !== 'undefined' && TagadaReactMinimalBundle) {
420
+ window.tgd = window.tgd || {};
421
+ // Provider
422
+ window.tgd.TagadaProvider = TagadaReactMinimalBundle.TagadaProvider;
423
+ window.tgd.useTagadaContext = TagadaReactMinimalBundle.useTagadaContext;
424
+ // Core checkout hooks
425
+ window.tgd.useCheckout = TagadaReactMinimalBundle.useCheckout;
426
+ window.tgd.useShippingRates = TagadaReactMinimalBundle.useShippingRates;
427
+ window.tgd.useDiscounts = TagadaReactMinimalBundle.useDiscounts;
428
+ window.tgd.useOrderBump = TagadaReactMinimalBundle.useOrderBump;
429
+ window.tgd.usePostPurchases = TagadaReactMinimalBundle.usePostPurchases;
430
+ window.tgd.usePayment = TagadaReactMinimalBundle.usePayment;
431
+ window.tgd.useThreeds = TagadaReactMinimalBundle.useThreeds;
432
+ // Utilities
433
+ window.tgd.useCurrency = TagadaReactMinimalBundle.useCurrency;
434
+ window.tgd.usePluginConfig = TagadaReactMinimalBundle.usePluginConfig;
435
+ window.tgd.useFunnel = TagadaReactMinimalBundle.useFunnel;
436
+ window.tgd.formatMoney = TagadaReactMinimalBundle.formatMoney;
437
+ // Mark as minimal
438
+ window.tgd._minimal = true;
439
+ }
440
+ `.trim(),
441
+ },
442
+ banner: {
443
+ js: `/**
444
+ * TagadaPay React SDK MINIMAL v${require('./package.json').version}
445
+ * CDN Bundle - Slim checkout SDK (TagadaProvider + essential hooks only)
446
+ * Requires: React 18+ loaded before this script
447
+ * For full SDK with all hooks, use tagada-react-sdk.min.js instead
448
+ * @license MIT
449
+ */`,
450
+ },
451
+ });
452
+
453
+ console.log(' āœ… dist/tagada-react-sdk-minimal.min.js (minified + sourcemap)');
454
+
455
+ // Get file sizes
456
+ const trackerMinSize = fs.statSync(path.join(OUT_DIR, 'external-tracker.min.js')).size;
457
+ const trackerFullSize = fs.statSync(path.join(OUT_DIR, 'external-tracker.js')).size;
458
+ const sdkMinSize = fs.statSync(path.join(OUT_DIR, 'tagada-sdk.min.js')).size;
459
+ const sdkFullSize = fs.statSync(path.join(OUT_DIR, 'tagada-sdk.js')).size;
460
+ const reactSdkMinSize = fs.statSync(path.join(OUT_DIR, 'tagada-react-sdk.min.js')).size;
461
+ const reactSdkFullSize = fs.statSync(path.join(OUT_DIR, 'tagada-react-sdk.js')).size;
462
+ const reactSdkMinimalSize = fs.statSync(path.join(OUT_DIR, 'tagada-react-sdk-minimal.min.js')).size;
463
+
464
+ console.log('\nšŸ“¦ Bundle sizes:');
465
+ console.log(` external-tracker.min.js: ${(trackerMinSize / 1024).toFixed(2)} KB`);
466
+ console.log(` external-tracker.js: ${(trackerFullSize / 1024).toFixed(2)} KB`);
467
+ console.log(` tagada-sdk.min.js: ${(sdkMinSize / 1024).toFixed(2)} KB`);
468
+ console.log(` tagada-sdk.js: ${(sdkFullSize / 1024).toFixed(2)} KB`);
469
+ console.log(` tagada-react-sdk.min.js: ${(reactSdkMinSize / 1024).toFixed(2)} KB (full)`);
470
+ console.log(` tagada-react-sdk.js: ${(reactSdkFullSize / 1024).toFixed(2)} KB`);
471
+ console.log(` tagada-react-sdk-minimal.min.js: ${(reactSdkMinimalSize / 1024).toFixed(2)} KB (slim) ⭐`);
472
+
473
+ console.log('\n✨ CDN build complete!\n');
474
+ console.log('Usage via CDN:');
475
+ console.log('');
476
+ console.log(' // External Tracker (lightweight, tracking only):');
477
+ console.log(' <script src="https://cdn.jsdelivr.net/npm/@tagadapay/plugin-sdk/dist/external-tracker.min.js"></script>');
478
+ console.log(' <script>TagadaTracker.init({ storeId: "store_xxx", ... });</script>');
479
+ console.log('');
480
+ console.log(' // Full SDK (createTagadaClient, config, hot reload):');
481
+ console.log(' <script src="https://cdn.jsdelivr.net/npm/@tagadapay/plugin-sdk/dist/tagada-sdk.min.js"></script>');
482
+ console.log(' <script>');
483
+ console.log(' const client = window.tgd.createTagadaClient({ features: { funnel: true } });');
484
+ console.log(' client.subscribe((state) => console.log(state));');
485
+ console.log(' </script>');
486
+ console.log('');
487
+ console.log(' // React SDK (hooks & TagadaProvider - requires React 18+):');
488
+ console.log(' <script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>');
489
+ console.log(' <script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>');
490
+ console.log(' <script src="https://cdn.jsdelivr.net/npm/@tagadapay/plugin-sdk/dist/tagada-react-sdk.min.js"></script>');
491
+ console.log(' // Then use: window.tgd.TagadaProvider, window.tgd.useCheckout, etc.\n');
492
+ }
493
+
494
+ build().catch((err) => {
495
+ console.error('Build failed:', err);
496
+ process.exit(1);
497
+ });
498
+
499
+