@appfunnel-dev/sdk 0.16.0 → 0.17.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/{chunk-6QKCIT32.cjs → chunk-7BSBNWJ6.cjs} +11 -7
- package/dist/chunk-7BSBNWJ6.cjs.map +1 -0
- package/dist/{chunk-CZQHTQU2.cjs → chunk-7D7VJBOV.cjs} +6 -6
- package/dist/{chunk-CZQHTQU2.cjs.map → chunk-7D7VJBOV.cjs.map} +1 -1
- package/dist/{chunk-FDAIQSVU.js → chunk-7KOSK32P.js} +11 -7
- package/dist/chunk-7KOSK32P.js.map +1 -0
- package/dist/{chunk-IA5WCBUS.js → chunk-YRHJBBAC.js} +3 -3
- package/dist/{chunk-IA5WCBUS.js.map → chunk-YRHJBBAC.js.map} +1 -1
- package/dist/elements/index.cjs +6 -6
- package/dist/elements/index.js +2 -2
- package/dist/index.cjs +51 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +27 -4
- package/dist/index.js.map +1 -1
- package/dist/internal.cjs +2 -2
- package/dist/internal.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-6QKCIT32.cjs.map +0 -1
- package/dist/chunk-FDAIQSVU.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunk7D7VJBOV_cjs = require('./chunk-7D7VJBOV.cjs');
|
|
4
|
+
var chunk7BSBNWJ6_cjs = require('./chunk-7BSBNWJ6.cjs');
|
|
5
5
|
var react = require('react');
|
|
6
6
|
var stripeJs = require('@stripe/stripe-js');
|
|
7
7
|
var sonner = require('sonner');
|
|
@@ -16,7 +16,7 @@ function definePage(definition) {
|
|
|
16
16
|
return definition;
|
|
17
17
|
}
|
|
18
18
|
function useVariable(id) {
|
|
19
|
-
const { variableStore } =
|
|
19
|
+
const { variableStore } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
20
20
|
const subscribe = react.useCallback(
|
|
21
21
|
(callback) => variableStore.subscribe(callback, { keys: [id] }),
|
|
22
22
|
[variableStore, id]
|
|
@@ -33,7 +33,7 @@ function useVariable(id) {
|
|
|
33
33
|
return [value, setValue];
|
|
34
34
|
}
|
|
35
35
|
function useVariables() {
|
|
36
|
-
const { variableStore } =
|
|
36
|
+
const { variableStore } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
37
37
|
const subscribe = react.useCallback(
|
|
38
38
|
(callback) => variableStore.subscribe(callback),
|
|
39
39
|
[variableStore]
|
|
@@ -141,7 +141,7 @@ function toISODateWithFormat(input, format) {
|
|
|
141
141
|
|
|
142
142
|
// src/hooks/useUser.ts
|
|
143
143
|
function useUser() {
|
|
144
|
-
const { variableStore, tracker } =
|
|
144
|
+
const { variableStore, tracker } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
145
145
|
const subscribe = react.useCallback(
|
|
146
146
|
(cb) => variableStore.subscribe(cb, { prefix: "user." }),
|
|
147
147
|
[variableStore]
|
|
@@ -182,7 +182,7 @@ function useUser() {
|
|
|
182
182
|
);
|
|
183
183
|
}
|
|
184
184
|
function useUserProperty(field) {
|
|
185
|
-
const { variableStore } =
|
|
185
|
+
const { variableStore } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
186
186
|
const key = `user.${field}`;
|
|
187
187
|
const subscribe = react.useCallback(
|
|
188
188
|
(cb) => variableStore.subscribe(cb, { keys: [key] }),
|
|
@@ -200,7 +200,7 @@ function useUserProperty(field) {
|
|
|
200
200
|
return [value, setValue];
|
|
201
201
|
}
|
|
202
202
|
function useDateOfBirth(format = "MM/DD/YYYY") {
|
|
203
|
-
const { variableStore } =
|
|
203
|
+
const { variableStore } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
204
204
|
const key = "user.dateOfBirth";
|
|
205
205
|
const subscribe = react.useCallback(
|
|
206
206
|
(cb) => variableStore.subscribe(cb, { keys: [key] }),
|
|
@@ -218,7 +218,7 @@ function useDateOfBirth(format = "MM/DD/YYYY") {
|
|
|
218
218
|
return [value, setValue];
|
|
219
219
|
}
|
|
220
220
|
function useQueryParams() {
|
|
221
|
-
const { variableStore } =
|
|
221
|
+
const { variableStore } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
222
222
|
const subscribe = react.useCallback(
|
|
223
223
|
(cb) => variableStore.subscribe(cb, { prefix: "query." }),
|
|
224
224
|
[variableStore]
|
|
@@ -239,7 +239,7 @@ function useQueryParams() {
|
|
|
239
239
|
}, [variables]);
|
|
240
240
|
}
|
|
241
241
|
function useQueryParam(key) {
|
|
242
|
-
const { variableStore } =
|
|
242
|
+
const { variableStore } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
243
243
|
const prefixedKey = `query.${key}`;
|
|
244
244
|
const subscribe = react.useCallback(
|
|
245
245
|
(cb) => variableStore.subscribe(cb, { keys: [prefixedKey] }),
|
|
@@ -252,7 +252,7 @@ function useQueryParam(key) {
|
|
|
252
252
|
return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
253
253
|
}
|
|
254
254
|
function useData(key) {
|
|
255
|
-
const { variableStore } =
|
|
255
|
+
const { variableStore } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
256
256
|
const prefixedKey = `data.${key}`;
|
|
257
257
|
const subscribe = react.useCallback(
|
|
258
258
|
(cb) => variableStore.subscribe(cb, { keys: [prefixedKey] }),
|
|
@@ -305,7 +305,7 @@ function detect24Hour(locale) {
|
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
307
|
function useTranslation() {
|
|
308
|
-
const { i18n } =
|
|
308
|
+
const { i18n } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
309
309
|
const subscribe = react.useCallback(
|
|
310
310
|
(cb) => i18n.subscribe(cb),
|
|
311
311
|
[i18n]
|
|
@@ -328,7 +328,7 @@ function useTranslation() {
|
|
|
328
328
|
return { t, locale, setLocale, availableLocales };
|
|
329
329
|
}
|
|
330
330
|
function useProducts() {
|
|
331
|
-
const { products, variableStore, selectProduct: ctxSelect } =
|
|
331
|
+
const { products, variableStore, selectProduct: ctxSelect } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
332
332
|
const subscribe = react.useCallback(
|
|
333
333
|
(cb) => variableStore.subscribe(cb, { keys: ["products.selectedProductId"] }),
|
|
334
334
|
[variableStore]
|
|
@@ -345,7 +345,7 @@ function useProducts() {
|
|
|
345
345
|
return { products, selected, select };
|
|
346
346
|
}
|
|
347
347
|
function useTracking() {
|
|
348
|
-
const { tracker } =
|
|
348
|
+
const { tracker } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
349
349
|
const track = react.useCallback(
|
|
350
350
|
(eventName, data) => {
|
|
351
351
|
tracker.track(eventName, data);
|
|
@@ -357,7 +357,7 @@ function useTracking() {
|
|
|
357
357
|
var API_BASE_URL = "https://api.appfunnel.net";
|
|
358
358
|
var PAYMENT_KEYS = ["payment.loading", "payment.error"];
|
|
359
359
|
function usePayment() {
|
|
360
|
-
const { variableStore, products, campaignId, tracker, config } =
|
|
360
|
+
const { variableStore, products, campaignId, tracker, config } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
361
361
|
const showToasts = !config.settings?.disableToasts;
|
|
362
362
|
const subscribe = react.useCallback(
|
|
363
363
|
(cb) => variableStore.subscribe(cb, { keys: PAYMENT_KEYS }),
|
|
@@ -646,7 +646,7 @@ var DEVICE_KEYS = [
|
|
|
646
646
|
"browser.language"
|
|
647
647
|
];
|
|
648
648
|
function useDeviceInfo() {
|
|
649
|
-
const { variableStore } =
|
|
649
|
+
const { variableStore } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
650
650
|
const subscribe = react.useCallback(
|
|
651
651
|
(cb) => variableStore.subscribe(cb, { keys: DEVICE_KEYS }),
|
|
652
652
|
[variableStore]
|
|
@@ -780,7 +780,7 @@ var PAGE_KEYS = [
|
|
|
780
780
|
"page.startedAt"
|
|
781
781
|
];
|
|
782
782
|
function usePageData() {
|
|
783
|
-
const { variableStore } =
|
|
783
|
+
const { variableStore } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
784
784
|
const subscribe = react.useCallback(
|
|
785
785
|
(cb) => variableStore.subscribe(cb, { keys: PAGE_KEYS }),
|
|
786
786
|
[variableStore]
|
|
@@ -802,16 +802,16 @@ function usePageData() {
|
|
|
802
802
|
|
|
803
803
|
// src/hooks/useFunnel.ts
|
|
804
804
|
function useFunnel() {
|
|
805
|
-
const { funnelId, campaignId, tracker } =
|
|
805
|
+
const { funnelId, campaignId, tracker } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
806
806
|
return {
|
|
807
807
|
funnelId,
|
|
808
808
|
campaignId,
|
|
809
809
|
sessionId: tracker.getSessionId(),
|
|
810
810
|
variables: useVariables(),
|
|
811
811
|
user: useUser(),
|
|
812
|
-
responses:
|
|
812
|
+
responses: chunk7D7VJBOV_cjs.useResponses(),
|
|
813
813
|
queryParams: useQueryParams(),
|
|
814
|
-
navigation:
|
|
814
|
+
navigation: chunk7D7VJBOV_cjs.useNavigation(),
|
|
815
815
|
products: useProducts(),
|
|
816
816
|
tracking: useTracking(),
|
|
817
817
|
payment: usePayment()
|
|
@@ -1212,7 +1212,7 @@ var DemoStripePaymentForm = react.forwardRef(
|
|
|
1212
1212
|
onReady,
|
|
1213
1213
|
className
|
|
1214
1214
|
}, ref) {
|
|
1215
|
-
const { variableStore, tracker, products } =
|
|
1215
|
+
const { variableStore, tracker, products } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
1216
1216
|
const validateOnly = mode === "validate-only";
|
|
1217
1217
|
const product = react.useMemo(() => {
|
|
1218
1218
|
if (productId) return products.find((p) => p.id === productId) || null;
|
|
@@ -1272,7 +1272,7 @@ var InnerPaymentForm = react.forwardRef(
|
|
|
1272
1272
|
const stripe = reactStripeJs.useStripe();
|
|
1273
1273
|
const elements = reactStripeJs.useElements();
|
|
1274
1274
|
const [error, setError] = react.useState(null);
|
|
1275
|
-
const { variableStore, campaignId, tracker, products, config } =
|
|
1275
|
+
const { variableStore, campaignId, tracker, products, config } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
1276
1276
|
const showToasts = !config.settings?.disableToasts;
|
|
1277
1277
|
const readyFired = react.useRef(false);
|
|
1278
1278
|
react.useEffect(() => {
|
|
@@ -1423,7 +1423,7 @@ var RealStripePaymentForm = react.forwardRef(
|
|
|
1423
1423
|
appearance,
|
|
1424
1424
|
layout
|
|
1425
1425
|
}, ref) {
|
|
1426
|
-
const { campaignId, tracker, variableStore, products, router, config } =
|
|
1426
|
+
const { campaignId, tracker, variableStore, products, router, config } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
1427
1427
|
const showToasts = !config.settings?.disableToasts;
|
|
1428
1428
|
const [email] = useVariable("user.email");
|
|
1429
1429
|
const validateOnly = mode === "validate-only";
|
|
@@ -1441,6 +1441,7 @@ var RealStripePaymentForm = react.forwardRef(
|
|
|
1441
1441
|
const [clientSecret, setClientSecret] = react.useState(null);
|
|
1442
1442
|
const [error, setError] = react.useState(null);
|
|
1443
1443
|
const [isLoading, setIsLoading] = react.useState(false);
|
|
1444
|
+
const [alreadyCompleted, setAlreadyCompleted] = react.useState(false);
|
|
1444
1445
|
const hasInitialized = react.useRef(false);
|
|
1445
1446
|
react.useEffect(() => {
|
|
1446
1447
|
if (!email || !campaignId || hasInitialized.current) return;
|
|
@@ -1485,6 +1486,25 @@ var RealStripePaymentForm = react.forwardRef(
|
|
|
1485
1486
|
);
|
|
1486
1487
|
const result = await response.json();
|
|
1487
1488
|
if (!result.success) throw new Error(result.error || "Failed to create checkout session");
|
|
1489
|
+
if (result.alreadyCompleted) {
|
|
1490
|
+
variableStore.set("payment.error", "");
|
|
1491
|
+
if (result.subscriptionId) {
|
|
1492
|
+
variableStore.set("stripe.subscriptionId", result.subscriptionId);
|
|
1493
|
+
variableStore.set("subscription.status", result.status);
|
|
1494
|
+
}
|
|
1495
|
+
if (result.paymentIntentId) {
|
|
1496
|
+
variableStore.set("stripe.paymentIntentId", result.paymentIntentId);
|
|
1497
|
+
variableStore.set("payment.status", "succeeded");
|
|
1498
|
+
}
|
|
1499
|
+
tracker.track("checkout.already_completed");
|
|
1500
|
+
setAlreadyCompleted(true);
|
|
1501
|
+
if (variant === "embedded" && successPageKey) {
|
|
1502
|
+
router.goToPage(successPageKey);
|
|
1503
|
+
} else {
|
|
1504
|
+
onSuccess?.();
|
|
1505
|
+
}
|
|
1506
|
+
return;
|
|
1507
|
+
}
|
|
1488
1508
|
setStripePromise(stripeJs.loadStripe(result.publishableKey));
|
|
1489
1509
|
setClientSecret(result.clientSecret);
|
|
1490
1510
|
} else {
|
|
@@ -1524,6 +1544,9 @@ var RealStripePaymentForm = react.forwardRef(
|
|
|
1524
1544
|
};
|
|
1525
1545
|
createIntent();
|
|
1526
1546
|
}, [email, campaignId, product, paymentMode, validateOnly, variant, successPageKey, automaticTax, managedPayments, allowPromotionCodes, router, tracker, variableStore]);
|
|
1547
|
+
if (alreadyCompleted) {
|
|
1548
|
+
return null;
|
|
1549
|
+
}
|
|
1527
1550
|
if (isLoading) {
|
|
1528
1551
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style: { padding: "20px", textAlign: "center", color: "#6b7280" }, children: "Loading payment form..." });
|
|
1529
1552
|
}
|
|
@@ -1579,7 +1602,7 @@ function PaddleCheckout({
|
|
|
1579
1602
|
onError,
|
|
1580
1603
|
className
|
|
1581
1604
|
}) {
|
|
1582
|
-
const { variableStore, tracker, products } =
|
|
1605
|
+
const { variableStore, tracker, products } = chunk7BSBNWJ6_cjs.useFunnelContext();
|
|
1583
1606
|
const containerRef = react.useRef(null);
|
|
1584
1607
|
const initializedRef = react.useRef(false);
|
|
1585
1608
|
const product = productId ? products.find((p) => p.id === productId) : products.find((p) => p.id === variableStore.get("products.selectedProductId"));
|
|
@@ -1638,23 +1661,23 @@ function PaddleCheckout({
|
|
|
1638
1661
|
|
|
1639
1662
|
Object.defineProperty(exports, "useNavigation", {
|
|
1640
1663
|
enumerable: true,
|
|
1641
|
-
get: function () { return
|
|
1664
|
+
get: function () { return chunk7D7VJBOV_cjs.useNavigation; }
|
|
1642
1665
|
});
|
|
1643
1666
|
Object.defineProperty(exports, "useResponse", {
|
|
1644
1667
|
enumerable: true,
|
|
1645
|
-
get: function () { return
|
|
1668
|
+
get: function () { return chunk7D7VJBOV_cjs.useResponse; }
|
|
1646
1669
|
});
|
|
1647
1670
|
Object.defineProperty(exports, "useResponses", {
|
|
1648
1671
|
enumerable: true,
|
|
1649
|
-
get: function () { return
|
|
1672
|
+
get: function () { return chunk7D7VJBOV_cjs.useResponses; }
|
|
1650
1673
|
});
|
|
1651
1674
|
Object.defineProperty(exports, "FunnelProvider", {
|
|
1652
1675
|
enumerable: true,
|
|
1653
|
-
get: function () { return
|
|
1676
|
+
get: function () { return chunk7BSBNWJ6_cjs.FunnelProvider; }
|
|
1654
1677
|
});
|
|
1655
1678
|
Object.defineProperty(exports, "registerIntegration", {
|
|
1656
1679
|
enumerable: true,
|
|
1657
|
-
get: function () { return
|
|
1680
|
+
get: function () { return chunk7BSBNWJ6_cjs.registerIntegration; }
|
|
1658
1681
|
});
|
|
1659
1682
|
Object.defineProperty(exports, "toast", {
|
|
1660
1683
|
enumerable: true,
|