@appfunnel-dev/sdk 0.10.0 → 0.12.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.
package/dist/index.cjs CHANGED
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var chunkXP44I2MU_cjs = require('./chunk-XP44I2MU.cjs');
4
- var chunkEVUYCLVY_cjs = require('./chunk-EVUYCLVY.cjs');
3
+ var chunkECWTUTEJ_cjs = require('./chunk-ECWTUTEJ.cjs');
4
+ var chunk5E6WNNU4_cjs = require('./chunk-5E6WNNU4.cjs');
5
5
  var react = require('react');
6
+ var sonner = require('sonner');
6
7
  var stripeJs = require('@stripe/stripe-js');
7
8
  var reactStripeJs = require('@stripe/react-stripe-js');
8
9
  var jsxRuntime = require('react/jsx-runtime');
@@ -15,7 +16,7 @@ function definePage(definition) {
15
16
  return definition;
16
17
  }
17
18
  function useVariable(id) {
18
- const { variableStore } = chunkEVUYCLVY_cjs.useFunnelContext();
19
+ const { variableStore } = chunk5E6WNNU4_cjs.useFunnelContext();
19
20
  const subscribe = react.useCallback(
20
21
  (callback) => variableStore.subscribe(callback, { keys: [id] }),
21
22
  [variableStore, id]
@@ -32,7 +33,7 @@ function useVariable(id) {
32
33
  return [value, setValue];
33
34
  }
34
35
  function useVariables() {
35
- const { variableStore } = chunkEVUYCLVY_cjs.useFunnelContext();
36
+ const { variableStore } = chunk5E6WNNU4_cjs.useFunnelContext();
36
37
  const subscribe = react.useCallback(
37
38
  (callback) => variableStore.subscribe(callback),
38
39
  [variableStore]
@@ -140,7 +141,7 @@ function toISODateWithFormat(input, format) {
140
141
 
141
142
  // src/hooks/useUser.ts
142
143
  function useUser() {
143
- const { variableStore, tracker } = chunkEVUYCLVY_cjs.useFunnelContext();
144
+ const { variableStore, tracker } = chunk5E6WNNU4_cjs.useFunnelContext();
144
145
  const subscribe = react.useCallback(
145
146
  (cb) => variableStore.subscribe(cb, { prefix: "user." }),
146
147
  [variableStore]
@@ -178,7 +179,7 @@ function useUser() {
178
179
  );
179
180
  }
180
181
  function useUserProperty(field) {
181
- const { variableStore } = chunkEVUYCLVY_cjs.useFunnelContext();
182
+ const { variableStore } = chunk5E6WNNU4_cjs.useFunnelContext();
182
183
  const key = `user.${field}`;
183
184
  const subscribe = react.useCallback(
184
185
  (cb) => variableStore.subscribe(cb, { keys: [key] }),
@@ -196,7 +197,7 @@ function useUserProperty(field) {
196
197
  return [value, setValue];
197
198
  }
198
199
  function useDateOfBirth(format = "MM/DD/YYYY") {
199
- const { variableStore } = chunkEVUYCLVY_cjs.useFunnelContext();
200
+ const { variableStore } = chunk5E6WNNU4_cjs.useFunnelContext();
200
201
  const key = "user.dateOfBirth";
201
202
  const subscribe = react.useCallback(
202
203
  (cb) => variableStore.subscribe(cb, { keys: [key] }),
@@ -214,7 +215,7 @@ function useDateOfBirth(format = "MM/DD/YYYY") {
214
215
  return [value, setValue];
215
216
  }
216
217
  function useQueryParams() {
217
- const { variableStore } = chunkEVUYCLVY_cjs.useFunnelContext();
218
+ const { variableStore } = chunk5E6WNNU4_cjs.useFunnelContext();
218
219
  const subscribe = react.useCallback(
219
220
  (cb) => variableStore.subscribe(cb, { prefix: "query." }),
220
221
  [variableStore]
@@ -235,7 +236,7 @@ function useQueryParams() {
235
236
  }, [variables]);
236
237
  }
237
238
  function useQueryParam(key) {
238
- const { variableStore } = chunkEVUYCLVY_cjs.useFunnelContext();
239
+ const { variableStore } = chunk5E6WNNU4_cjs.useFunnelContext();
239
240
  const prefixedKey = `query.${key}`;
240
241
  const subscribe = react.useCallback(
241
242
  (cb) => variableStore.subscribe(cb, { keys: [prefixedKey] }),
@@ -248,7 +249,7 @@ function useQueryParam(key) {
248
249
  return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
249
250
  }
250
251
  function useData(key) {
251
- const { variableStore } = chunkEVUYCLVY_cjs.useFunnelContext();
252
+ const { variableStore } = chunk5E6WNNU4_cjs.useFunnelContext();
252
253
  const prefixedKey = `data.${key}`;
253
254
  const subscribe = react.useCallback(
254
255
  (cb) => variableStore.subscribe(cb, { keys: [prefixedKey] }),
@@ -301,7 +302,7 @@ function detect24Hour(locale) {
301
302
  }
302
303
  }
303
304
  function useTranslation() {
304
- const { i18n } = chunkEVUYCLVY_cjs.useFunnelContext();
305
+ const { i18n } = chunk5E6WNNU4_cjs.useFunnelContext();
305
306
  const subscribe = react.useCallback(
306
307
  (cb) => i18n.subscribe(cb),
307
308
  [i18n]
@@ -324,7 +325,7 @@ function useTranslation() {
324
325
  return { t, locale, setLocale, availableLocales };
325
326
  }
326
327
  function useProducts() {
327
- const { products, variableStore, selectProduct: ctxSelect } = chunkEVUYCLVY_cjs.useFunnelContext();
328
+ const { products, variableStore, selectProduct: ctxSelect } = chunk5E6WNNU4_cjs.useFunnelContext();
328
329
  const subscribe = react.useCallback(
329
330
  (cb) => variableStore.subscribe(cb, { keys: ["products.selectedProductId"] }),
330
331
  [variableStore]
@@ -341,7 +342,7 @@ function useProducts() {
341
342
  return { products, selected, select };
342
343
  }
343
344
  function useTracking() {
344
- const { tracker } = chunkEVUYCLVY_cjs.useFunnelContext();
345
+ const { tracker } = chunk5E6WNNU4_cjs.useFunnelContext();
345
346
  const track = react.useCallback(
346
347
  (eventName, data) => {
347
348
  tracker.track(eventName, data);
@@ -353,7 +354,8 @@ function useTracking() {
353
354
  var API_BASE_URL = "https://api.appfunnel.net";
354
355
  var PAYMENT_KEYS = ["payment.loading", "payment.error"];
355
356
  function usePayment() {
356
- const { variableStore, products, campaignId, tracker } = chunkEVUYCLVY_cjs.useFunnelContext();
357
+ const { variableStore, products, campaignId, tracker, config } = chunk5E6WNNU4_cjs.useFunnelContext();
358
+ const showToasts = !config.settings?.disableToasts;
357
359
  const subscribe = react.useCallback(
358
360
  (cb) => variableStore.subscribe(cb, { keys: PAYMENT_KEYS }),
359
361
  [variableStore]
@@ -385,6 +387,7 @@ function usePayment() {
385
387
  const msg = "Please complete payment authorization first";
386
388
  console.error("[Purchase] Failed:", msg);
387
389
  variableStore.set("payment.error", msg);
390
+ if (showToasts) sonner.toast.error(msg);
388
391
  options?.onError?.(msg);
389
392
  return false;
390
393
  }
@@ -401,6 +404,7 @@ function usePayment() {
401
404
  const msg = "Product not found or missing Stripe price";
402
405
  console.error("[Purchase] Failed:", msg);
403
406
  variableStore.set("payment.error", msg);
407
+ if (showToasts) sonner.toast.error(msg);
404
408
  options?.onError?.(msg);
405
409
  return false;
406
410
  }
@@ -450,6 +454,7 @@ function usePayment() {
450
454
  const msg = "Failed to load payment processor";
451
455
  console.error("[Purchase] Failed:", msg);
452
456
  variableStore.set("payment.error", msg);
457
+ if (showToasts) sonner.toast.error(msg);
453
458
  options?.onError?.(msg);
454
459
  return false;
455
460
  }
@@ -466,6 +471,7 @@ function usePayment() {
466
471
  const msg = confirmError?.message || "Payment authentication failed";
467
472
  console.error("[Purchase] 3DS failed:", msg);
468
473
  variableStore.set("payment.error", msg);
474
+ if (showToasts) sonner.toast.error(msg);
469
475
  options?.onError?.(msg);
470
476
  return false;
471
477
  }
@@ -591,6 +597,7 @@ function usePayment() {
591
597
  const msg = result.error || "Purchase failed";
592
598
  console.error("[Purchase] Failed:", msg);
593
599
  variableStore.set("payment.error", msg);
600
+ if (showToasts) sonner.toast.error(msg);
594
601
  options?.onError?.(msg);
595
602
  return false;
596
603
  }
@@ -598,6 +605,7 @@ function usePayment() {
598
605
  const msg = err instanceof Error ? err.message : "Purchase failed";
599
606
  console.error("[Purchase] Exception:", err);
600
607
  variableStore.set("payment.error", msg);
608
+ if (showToasts) sonner.toast.error(msg);
601
609
  options?.onError?.(msg);
602
610
  return false;
603
611
  } finally {
@@ -605,7 +613,7 @@ function usePayment() {
605
613
  variableStore.set("payment.loading", false);
606
614
  }
607
615
  },
608
- [variableStore, products, campaignId, tracker]
616
+ [variableStore, products, campaignId, tracker, showToasts]
609
617
  );
610
618
  return react.useMemo(
611
619
  () => ({
@@ -636,7 +644,7 @@ var DEVICE_KEYS = [
636
644
  "browser.language"
637
645
  ];
638
646
  function useDeviceInfo() {
639
- const { variableStore } = chunkEVUYCLVY_cjs.useFunnelContext();
647
+ const { variableStore } = chunk5E6WNNU4_cjs.useFunnelContext();
640
648
  const subscribe = react.useCallback(
641
649
  (cb) => variableStore.subscribe(cb, { keys: DEVICE_KEYS }),
642
650
  [variableStore]
@@ -770,7 +778,7 @@ var PAGE_KEYS = [
770
778
  "page.startedAt"
771
779
  ];
772
780
  function usePageData() {
773
- const { variableStore } = chunkEVUYCLVY_cjs.useFunnelContext();
781
+ const { variableStore } = chunk5E6WNNU4_cjs.useFunnelContext();
774
782
  const subscribe = react.useCallback(
775
783
  (cb) => variableStore.subscribe(cb, { keys: PAGE_KEYS }),
776
784
  [variableStore]
@@ -792,16 +800,16 @@ function usePageData() {
792
800
 
793
801
  // src/hooks/useFunnel.ts
794
802
  function useFunnel() {
795
- const { funnelId, campaignId, tracker } = chunkEVUYCLVY_cjs.useFunnelContext();
803
+ const { funnelId, campaignId, tracker } = chunk5E6WNNU4_cjs.useFunnelContext();
796
804
  return {
797
805
  funnelId,
798
806
  campaignId,
799
807
  sessionId: tracker.getSessionId(),
800
808
  variables: useVariables(),
801
809
  user: useUser(),
802
- responses: chunkXP44I2MU_cjs.useResponses(),
810
+ responses: chunkECWTUTEJ_cjs.useResponses(),
803
811
  queryParams: useQueryParams(),
804
- navigation: chunkXP44I2MU_cjs.useNavigation(),
812
+ navigation: chunkECWTUTEJ_cjs.useNavigation(),
805
813
  products: useProducts(),
806
814
  tracking: useTracking(),
807
815
  payment: usePayment()
@@ -1202,7 +1210,7 @@ var DemoStripePaymentForm = react.forwardRef(
1202
1210
  onReady,
1203
1211
  className
1204
1212
  }, ref) {
1205
- const { variableStore, tracker, products } = chunkEVUYCLVY_cjs.useFunnelContext();
1213
+ const { variableStore, tracker, products } = chunk5E6WNNU4_cjs.useFunnelContext();
1206
1214
  const validateOnly = mode === "validate-only";
1207
1215
  const product = react.useMemo(() => {
1208
1216
  if (productId) return products.find((p) => p.id === productId) || null;
@@ -1262,7 +1270,8 @@ var InnerPaymentForm = react.forwardRef(
1262
1270
  const stripe = reactStripeJs.useStripe();
1263
1271
  const elements = reactStripeJs.useElements();
1264
1272
  const [error, setError] = react.useState(null);
1265
- const { variableStore, campaignId, tracker, products } = chunkEVUYCLVY_cjs.useFunnelContext();
1273
+ const { variableStore, campaignId, tracker, products, config } = chunk5E6WNNU4_cjs.useFunnelContext();
1274
+ const showToasts = !config.settings?.disableToasts;
1266
1275
  const readyFired = react.useRef(false);
1267
1276
  react.useEffect(() => {
1268
1277
  if (stripe && elements && !readyFired.current) {
@@ -1290,6 +1299,7 @@ var InnerPaymentForm = react.forwardRef(
1290
1299
  const msg = confirmResult.error.message || "Payment failed";
1291
1300
  setError(msg);
1292
1301
  variableStore.set("payment.error", msg);
1302
+ if (showToasts) sonner.toast.error(msg);
1293
1303
  onError?.(msg);
1294
1304
  return;
1295
1305
  }
@@ -1300,6 +1310,7 @@ var InnerPaymentForm = react.forwardRef(
1300
1310
  const msg = "PaymentIntent not found after confirmation";
1301
1311
  setError(msg);
1302
1312
  variableStore.set("payment.error", msg);
1313
+ if (showToasts) sonner.toast.error(msg);
1303
1314
  onError?.(msg);
1304
1315
  return;
1305
1316
  }
@@ -1320,6 +1331,7 @@ var InnerPaymentForm = react.forwardRef(
1320
1331
  const msg = result2.error || "Card validation failed";
1321
1332
  setError(msg);
1322
1333
  variableStore.set("payment.error", msg);
1334
+ if (showToasts) sonner.toast.error(msg);
1323
1335
  onError?.(msg);
1324
1336
  return;
1325
1337
  }
@@ -1341,6 +1353,7 @@ var InnerPaymentForm = react.forwardRef(
1341
1353
  const msg = "No product selected or missing Stripe price";
1342
1354
  setError(msg);
1343
1355
  variableStore.set("payment.error", msg);
1356
+ if (showToasts) sonner.toast.error(msg);
1344
1357
  onError?.(msg);
1345
1358
  return;
1346
1359
  }
@@ -1372,12 +1385,14 @@ var InnerPaymentForm = react.forwardRef(
1372
1385
  const msg = result.error || "Failed to process payment";
1373
1386
  setError(msg);
1374
1387
  variableStore.set("payment.error", msg);
1388
+ if (showToasts) sonner.toast.error(msg);
1375
1389
  onError?.(msg);
1376
1390
  }
1377
1391
  } catch (err) {
1378
1392
  const msg = err instanceof Error ? err.message : "An error occurred";
1379
1393
  setError(msg);
1380
1394
  variableStore.set("payment.error", msg);
1395
+ if (showToasts) sonner.toast.error(msg);
1381
1396
  onError?.(msg);
1382
1397
  } finally {
1383
1398
  variableStore.set("payment.loading", false);
@@ -1406,7 +1421,8 @@ var RealStripePaymentForm = react.forwardRef(
1406
1421
  appearance,
1407
1422
  layout
1408
1423
  }, ref) {
1409
- const { campaignId, tracker, variableStore, products, router } = chunkEVUYCLVY_cjs.useFunnelContext();
1424
+ const { campaignId, tracker, variableStore, products, router, config } = chunk5E6WNNU4_cjs.useFunnelContext();
1425
+ const showToasts = !config.settings?.disableToasts;
1410
1426
  const [email] = useVariable("user.email");
1411
1427
  const validateOnly = mode === "validate-only";
1412
1428
  const product = react.useMemo(() => {
@@ -1498,6 +1514,7 @@ var RealStripePaymentForm = react.forwardRef(
1498
1514
  const msg = err instanceof Error ? err.message : "Failed to initialize payment";
1499
1515
  setError(msg);
1500
1516
  variableStore.set("payment.error", msg);
1517
+ if (showToasts) sonner.toast.error(msg);
1501
1518
  } finally {
1502
1519
  setIsLoading(false);
1503
1520
  variableStore.set("payment.loading", false);
@@ -1560,7 +1577,7 @@ function PaddleCheckout({
1560
1577
  onError,
1561
1578
  className
1562
1579
  }) {
1563
- const { variableStore, tracker, products } = chunkEVUYCLVY_cjs.useFunnelContext();
1580
+ const { variableStore, tracker, products } = chunk5E6WNNU4_cjs.useFunnelContext();
1564
1581
  const containerRef = react.useRef(null);
1565
1582
  const initializedRef = react.useRef(false);
1566
1583
  const product = productId ? products.find((p) => p.id === productId) : products.find((p) => p.id === variableStore.get("products.selectedProductId"));
@@ -1619,23 +1636,27 @@ function PaddleCheckout({
1619
1636
 
1620
1637
  Object.defineProperty(exports, "useNavigation", {
1621
1638
  enumerable: true,
1622
- get: function () { return chunkXP44I2MU_cjs.useNavigation; }
1639
+ get: function () { return chunkECWTUTEJ_cjs.useNavigation; }
1623
1640
  });
1624
1641
  Object.defineProperty(exports, "useResponse", {
1625
1642
  enumerable: true,
1626
- get: function () { return chunkXP44I2MU_cjs.useResponse; }
1643
+ get: function () { return chunkECWTUTEJ_cjs.useResponse; }
1627
1644
  });
1628
1645
  Object.defineProperty(exports, "useResponses", {
1629
1646
  enumerable: true,
1630
- get: function () { return chunkXP44I2MU_cjs.useResponses; }
1647
+ get: function () { return chunkECWTUTEJ_cjs.useResponses; }
1631
1648
  });
1632
1649
  Object.defineProperty(exports, "FunnelProvider", {
1633
1650
  enumerable: true,
1634
- get: function () { return chunkEVUYCLVY_cjs.FunnelProvider; }
1651
+ get: function () { return chunk5E6WNNU4_cjs.FunnelProvider; }
1635
1652
  });
1636
1653
  Object.defineProperty(exports, "registerIntegration", {
1637
1654
  enumerable: true,
1638
- get: function () { return chunkEVUYCLVY_cjs.registerIntegration; }
1655
+ get: function () { return chunk5E6WNNU4_cjs.registerIntegration; }
1656
+ });
1657
+ Object.defineProperty(exports, "toast", {
1658
+ enumerable: true,
1659
+ get: function () { return sonner.toast; }
1639
1660
  });
1640
1661
  exports.PaddleCheckout = PaddleCheckout;
1641
1662
  exports.StripePaymentForm = StripePaymentForm;