@appfunnel-dev/sdk 2.0.0 → 2.0.1
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/CHANGELOG.md +41 -3
- package/dist/{checkout-BYcOfyg_.d.ts → checkout-B1K6ozwk.d.ts} +6 -0
- package/dist/{checkout-BM1T-u6_.d.cts → checkout-C4tFUEdF.d.cts} +6 -0
- package/dist/{chunk-MBTHQP4Z.cjs → chunk-DTSLJ24T.cjs} +11 -3
- package/dist/chunk-DTSLJ24T.cjs.map +1 -0
- package/dist/{chunk-NA7DRFOA.cjs → chunk-E7JXWUNV.cjs} +55 -17
- package/dist/chunk-E7JXWUNV.cjs.map +1 -0
- package/dist/{chunk-KVMNVX6J.js → chunk-USAECFWO.js} +11 -3
- package/dist/chunk-USAECFWO.js.map +1 -0
- package/dist/{chunk-PN7CRJAF.js → chunk-WCBVSZHJ.js} +55 -17
- package/dist/chunk-WCBVSZHJ.js.map +1 -0
- package/dist/driver-paddle.cjs +14 -14
- package/dist/driver-paddle.d.cts +1 -1
- package/dist/driver-paddle.d.ts +1 -1
- package/dist/driver-paddle.js +1 -1
- package/dist/driver-stripe.cjs +15 -15
- package/dist/driver-stripe.d.cts +1 -1
- package/dist/driver-stripe.d.ts +1 -1
- package/dist/driver-stripe.js +2 -2
- package/dist/index.cjs +78 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -6
- package/dist/index.d.ts +25 -6
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/dist/{manifest-BajvtPWs.d.cts → manifest-Dp1oRvqp.d.cts} +23 -0
- package/dist/{manifest-BajvtPWs.d.ts → manifest-Dp1oRvqp.d.ts} +23 -0
- package/dist/manifest-entry.cjs +9 -1
- package/dist/manifest-entry.cjs.map +1 -1
- package/dist/manifest-entry.d.cts +15 -2
- package/dist/manifest-entry.d.ts +15 -2
- package/dist/manifest-entry.js +9 -1
- package/dist/manifest-entry.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-KVMNVX6J.js.map +0 -1
- package/dist/chunk-MBTHQP4Z.cjs.map +0 -1
- package/dist/chunk-NA7DRFOA.cjs.map +0 -1
- package/dist/chunk-PN7CRJAF.js.map +0 -1
|
@@ -72,7 +72,15 @@ function postComplete(ctx, correlationId, providerRef) {
|
|
|
72
72
|
);
|
|
73
73
|
}
|
|
74
74
|
function settlementToResult(s) {
|
|
75
|
-
return {
|
|
75
|
+
return {
|
|
76
|
+
ok: true,
|
|
77
|
+
amountMinor: s.amountMinor,
|
|
78
|
+
currency: s.currency,
|
|
79
|
+
eventId: s.eventId,
|
|
80
|
+
// Carried through so the checkout hook can tell a trial start from a purchase — it decides
|
|
81
|
+
// which conversion event fires, and the browser has no other honest source for it.
|
|
82
|
+
acquisition: s.acquisition
|
|
83
|
+
};
|
|
76
84
|
}
|
|
77
85
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
78
86
|
async function completeWithPoll(ctx, correlationId, opts = {}) {
|
|
@@ -118,5 +126,5 @@ function leaveForRedirect(url) {
|
|
|
118
126
|
}
|
|
119
127
|
|
|
120
128
|
export { completeWithPoll, leaveForRedirect, postComplete, postSession, settlementToResult, toCheckoutError };
|
|
121
|
-
//# sourceMappingURL=chunk-
|
|
122
|
-
//# sourceMappingURL=chunk-
|
|
129
|
+
//# sourceMappingURL=chunk-USAECFWO.js.map
|
|
130
|
+
//# sourceMappingURL=chunk-USAECFWO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/drivers/wire.ts"],"names":[],"mappings":";;;AAiCA,SAAS,QAAA,CAAS,GAAA,EAA4B,IAAA,GAAO,EAAA,EAAY;AAC/D,EAAA,MAAM,IAAA,GAAO,GAAA,CAAI,OAAA,CAAQ,OAAA,CAAQ,QAAQ,EAAE,CAAA;AAC3C,EAAA,IAAI,IAAI,OAAA,EAAS;AACf,IAAA,MAAM,IAAA,GAAO,CAAA,SAAA,EAAY,kBAAA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;AAAA,IACL,EAAA,EAAI,KAAA;AAAA,IACJ,KAAA,EAAO,aAAA;AAAA,MACL,kBAAA;AAAA,MACA,KAAK,cAAA,IAAkB,0EAAA;AAAA;AAAA;AAAA;AAAA,MAIvB,EAAE,SAAA,EAAW,IAAA,EAAM,WAAA,EAAa,oBAAA;AAAqB;AACvD,GACF;AACF;AAkBO,SAAS,iBAAiB,GAAA,EAAsC;AACrE,EAAA,OAAO,IAAI,OAAA,CAAwB,CAAC,OAAA,KAAY;AAC9C,IAAA,IAAI,OAAO,WAAW,WAAA,EAAa;AACjC,MAAA,MAAM,UAAA,GAAa,CAAC,KAAA,KAA+B;AACjD,QAAA,IAAI,CAAC,MAAM,SAAA,EAAW;AACtB,QAAA,MAAA,CAAO,mBAAA,CAAoB,YAAY,UAAU,CAAA;AACjD,QAAA,OAAA,CAAQ;AAAA,UACN,EAAA,EAAI,KAAA;AAAA,UACJ,KAAA,EAAO,aAAA,CAAc,UAAA,EAAY,sDAAsD;AAAA,SACxF,CAAA;AAAA,MACH,CAAA;AACA,MAAA,MAAA,CAAO,gBAAA,CAAiB,YAAY,UAAU,CAAA;AAAA,IAChD;AACA,IAAA,MAAA,CAAO,QAAA,CAAS,OAAO,GAAG,CAAA;AAAA,EAC5B,CAAC,CAAA;AACH","file":"chunk-USAECFWO.js","sourcesContent":["/**\n * Shared wire plumbing for the checkout drivers — the CLIENT half of the v2\n * checkout contract (commerce/checkout-api.ts). Lives under drivers/ (not\n * commerce/) on purpose: it ships only inside the `driver-*` subpath entries,\n * so the core funnel entry never bundles a checkout fetch — the core SDK talks\n * to a {@link CheckoutDriver}, never to the wire.\n *\n * Only `import type` from commerce/checkout(.tsx) here — a runtime import would\n * drag the React checkout primitives into every driver chunk. The one runtime\n * dependency is the pure error taxonomy (capabilities.ts).\n */\nimport type {\n CheckoutCompleteRequest,\n CheckoutCompleteResponse,\n CheckoutSessionRequest,\n CheckoutSessionResponse,\n CheckoutSettlement,\n} from '../commerce/checkout-api'\nimport type { CheckoutDriverContext, CheckoutRequest, CheckoutResult } from '../commerce/checkout'\nimport { checkoutError, type CheckoutError } from '../commerce/capabilities'\n\n/**\n * The ONE place a driver's URL is decided — which is why adding the preview surface needed no\n * change in driver-stripe / driver-paddle, and needs none in whatever driver ships next. Two\n * surfaces, one wire contract:\n *\n * - campaign → `{apiBase}/campaign/{campaignId}/v2/checkout{path}`\n * - preview → `{apiBase}/v2/funnels/{funnelId}/preview-checkout{path}?buildId=…&t=…`\n *\n * The preview surface carries its auth in the query string (the build id + the HMAC token the\n * renderer already served the page with); the request BODY is byte-identical between the two, so\n * the server parses one schema either way.\n */\nfunction endpoint(ctx: CheckoutDriverContext, path = ''): string {\n const base = ctx.apiBase.replace(/\\/+$/, '')\n if (ctx.preview) {\n const auth = `?buildId=${encodeURIComponent(ctx.preview.buildId)}&t=${encodeURIComponent(ctx.preview.token)}`\n return `${base}/v2/funnels/${encodeURIComponent(ctx.funnelId)}/preview-checkout${path}${auth}`\n }\n return `${base}/campaign/${encodeURIComponent(ctx.campaignId ?? '')}/v2/checkout${path}`\n}\n\nasync function postJson<T>(url: string, body: unknown): Promise<T> {\n const res = await fetch(url, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(body),\n })\n // The contract speaks in `step` responses, not HTTP errors — a non-2xx means the\n // request never reached the checkout service properly (proxy, deploy, outage).\n if (!res.ok) throw checkoutError('processing_error', `checkout request failed (HTTP ${res.status})`)\n return (await res.json()) as T\n}\n\n/** Normalize any thrown value into the taxonomy (network drops → `processing_error`). */\nexport function toCheckoutError(e: unknown): CheckoutError {\n if (e && typeof e === 'object' && 'category' in e && 'message' in e && 'retryable' in e) {\n return e as CheckoutError\n }\n return checkoutError('processing_error', e instanceof Error ? e.message : 'Checkout request failed')\n}\n\n/**\n * Open a checkout attempt: `POST {apiBase}/campaign/{campaignId}/v2/checkout`.\n * The correlationId is client-minted per ATTEMPT (idempotency key + the id the\n * server stamps into provider metadata) — mint it once, reuse it on retries.\n */\n/**\n * The current page as a hosted checkout's return target — with `af_checkout` REMOVED.\n *\n * That param is the settle leg's correlation id, and it is not always cleaned up: a resume that\n * ends in `completion_timeout` (a slow webhook, an async/MoR settlement) deliberately leaves it in\n * the address bar so a reload can retry, and the URL sync then carries it onto every later page.\n * Sending it back would make the server append a SECOND `af_checkout`, and `searchParams.get()`\n * returns the FIRST — so the buyer's new, paid attempt would never settle client-side while a\n * stale one replayed. Same reason a seeded `?af_checkout=` in an ad URL must not survive to here.\n *\n * Everything else (utm, click ids) is kept: the return load re-reads it for attribution.\n */\nfunction currentReturnUrl(): string | undefined {\n if (typeof window === 'undefined') return undefined\n try {\n const url = new URL(window.location.href)\n url.searchParams.delete('af_checkout')\n return url.toString()\n } catch {\n return undefined\n }\n}\n\nexport function postSession(\n ctx: CheckoutDriverContext,\n req: CheckoutRequest,\n correlationId: string,\n): Promise<CheckoutSessionResponse> {\n const body: CheckoutSessionRequest = {\n funnelId: ctx.funnelId,\n mode: ctx.mode,\n // The CHARGE identity is the catalog key (resolved from the slot by driverWithCatalog); fall back\n // to `product` for legacy builds where the page named the catalog key directly.\n productKey: req.catalogKey ?? req.product,\n intent: req.intent,\n kind: req.kind,\n // null (not absent) = explicit off-session — the server validates surfaces\n // against the capability matrix, so never let one default in transit.\n surface: req.surface ?? null,\n // The provider VARIANT the author chose for this checkout (Stripe Managed Payments today).\n // Forwarded verbatim, never defaulted: `undefined` drops out of the JSON entirely, so a\n // non-managed attempt puts the exact same bytes on the wire it always has. The server owns\n // the other half of the gate — it re-validates the claim against the store's eligibility.\n managed: req.managed,\n sessionId: ctx.sessionId ?? undefined,\n visitorId: ctx.visitorId ?? undefined,\n // Buyer email collected by the funnel (user.email) — Stripe Customer creation,\n // receipts, Paddle prefill. Injected at attempt time by the FunnelProvider seam.\n email: req.email,\n // The page the buyer is leaving, so a hosted checkout returns them TO IT (with `?af_checkout=`)\n // instead of to the site root. The server keeps only path+query and re-derives the origin from\n // the request headers, so this can't redirect anyone off-domain. Absent during SSR.\n returnUrl: currentReturnUrl(),\n correlationId,\n }\n return postJson<CheckoutSessionResponse>(endpoint(ctx), body)\n}\n\n/** Ask the server to VERIFY with the provider and write the money facts (idempotent). */\nexport function postComplete(\n ctx: CheckoutDriverContext,\n correlationId: string,\n providerRef?: string,\n): Promise<CheckoutCompleteResponse> {\n const body: CheckoutCompleteRequest = { providerRef }\n return postJson<CheckoutCompleteResponse>(\n endpoint(ctx, `/${encodeURIComponent(correlationId)}/complete`),\n body,\n )\n}\n\n/** Server settlement → the SDK's CheckoutResult (eventId passes through for pixel dedup). */\nexport function settlementToResult(s: CheckoutSettlement): CheckoutResult {\n return {\n ok: true,\n amountMinor: s.amountMinor,\n currency: s.currency,\n eventId: s.eventId,\n // Carried through so the checkout hook can tell a trial start from a purchase — it decides\n // which conversion event fires, and the browser has no other honest source for it.\n acquisition: s.acquisition,\n }\n}\n\nexport interface CompletePollOptions {\n providerRef?: string\n /** Total complete attempts before giving up (default 5). */\n attempts?: number\n /** Delay between attempts (default 2000ms). */\n intervalMs?: number\n /** Error message when the provider hasn't confirmed inside the window (MoR/async). */\n timeoutMessage?: string\n}\n\nconst sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms))\n\n/**\n * Complete with a bounded poll. Sync providers (Stripe) settle on the first\n * attempt — the server verifies against the provider inline. MoR/async providers\n * (Paddle) settle via webhook, so `pending` is normal: re-poll a few times, then\n * stop holding the UI hostage — the charge may still land server-side, which is\n * why the timeout error is `retryable` and the message should say the receipt\n * can still arrive (the server's money facts don't depend on this browser).\n */\nexport async function completeWithPoll(\n ctx: CheckoutDriverContext,\n correlationId: string,\n opts: CompletePollOptions = {},\n): Promise<CheckoutResult> {\n const attempts = opts.attempts ?? 5\n const intervalMs = opts.intervalMs ?? 2000\n try {\n for (let i = 0; i < attempts; i++) {\n const res = await postComplete(ctx, correlationId, opts.providerRef)\n if (res.step === 'settled') return settlementToResult(res.result)\n if (res.step === 'failed') return { ok: false, error: res.error }\n if (i < attempts - 1) await sleep(intervalMs)\n }\n } catch (e) {\n return { ok: false, error: toCheckoutError(e) }\n }\n return {\n ok: false,\n error: checkoutError(\n 'processing_error',\n opts.timeoutMessage ?? 'The payment has not been confirmed yet — please check back shortly.',\n // `completion_timeout` marks \"the poll ran out while the attempt was still\n // pending\" — drivers key double-charge guards on it (the attempt may still\n // settle server-side; it was never refused).\n { retryable: true, declineCode: 'completion_timeout' },\n ),\n }\n}\n\n/**\n * The `redirect` step hand-off: navigate to the provider-hosted page and return a\n * promise that settles ONLY if the buyer comes back to this very page. The page\n * is leaving — resolving early would fire `purchase.complete`/navigation for a\n * charge that hasn't happened, and rejecting would flash an error during the\n * (successful) hand-off — so while the navigation proceeds the promise stays\n * pending and `useCheckout` stays in `loading`, the truthful UI for a page\n * mid-navigation. The hosted page's SUCCESS return URL re-enters the funnel with\n * `af_checkout={correlationId}` (a fresh load — this promise is gone; the SDK's\n * resume leg settles the attempt).\n *\n * The one way THIS page comes back to life is a bfcache restore (browser Back\n * from the hosted page): `pageshow` with `persisted: true`. That is a buyer who\n * abandoned the hosted checkout — resolve `canceled` so the trigger re-enables\n * and inline redirect placeholders recover instead of spinning forever.\n */\nexport function leaveForRedirect(url: string): Promise<CheckoutResult> {\n return new Promise<CheckoutResult>((resolve) => {\n if (typeof window !== 'undefined') {\n const onPageshow = (event: PageTransitionEvent) => {\n if (!event.persisted) return\n window.removeEventListener('pageshow', onPageshow)\n resolve({\n ok: false,\n error: checkoutError('canceled', 'Returned from the hosted checkout without completing'),\n })\n }\n window.addEventListener('pageshow', onPageshow)\n }\n window.location.assign(url)\n })\n}\n"]}
|
|
@@ -491,10 +491,23 @@ function interpolate(str, params) {
|
|
|
491
491
|
if (!params) return str;
|
|
492
492
|
return str.replace(/\{\{(\w+)\}\}/g, (_, k) => k in params ? String(params[k]) : `{{${k}}}`);
|
|
493
493
|
}
|
|
494
|
-
|
|
494
|
+
var baseLang = (locale) => locale.split("-")[0];
|
|
495
|
+
function lookupMessage(catalog, chain, key) {
|
|
495
496
|
for (const loc of chain) {
|
|
496
|
-
const
|
|
497
|
-
|
|
497
|
+
const lang = baseLang(loc);
|
|
498
|
+
const exact = catalog[loc]?.[key];
|
|
499
|
+
if (exact !== void 0) return exact;
|
|
500
|
+
if (lang !== loc) {
|
|
501
|
+
const wide = catalog[lang]?.[key];
|
|
502
|
+
if (wide !== void 0) return wide;
|
|
503
|
+
}
|
|
504
|
+
const siblings = Object.keys(catalog).filter(
|
|
505
|
+
(k) => k !== loc && k !== lang && baseLang(k) === lang
|
|
506
|
+
);
|
|
507
|
+
if (siblings.length === 1) {
|
|
508
|
+
const only = catalog[siblings[0]]?.[key];
|
|
509
|
+
if (only !== void 0) return only;
|
|
510
|
+
}
|
|
498
511
|
}
|
|
499
512
|
return void 0;
|
|
500
513
|
}
|
|
@@ -538,9 +551,11 @@ function useTranslation() {
|
|
|
538
551
|
}, [locale, config]);
|
|
539
552
|
const t = useMemo(() => {
|
|
540
553
|
const fn = ((key, params) => {
|
|
541
|
-
const raw =
|
|
554
|
+
const raw = lookupMessage(catalog, chain, key);
|
|
542
555
|
if (raw === void 0) {
|
|
543
|
-
devWarn(
|
|
556
|
+
devWarn(
|
|
557
|
+
`[appfunnel] missing translation: "${key}" (${locale}; tried ${chain.join(" \u2192 ")})`
|
|
558
|
+
);
|
|
544
559
|
return key;
|
|
545
560
|
}
|
|
546
561
|
return interpolate(raw, params);
|
|
@@ -6978,6 +6993,10 @@ function Modal(props) {
|
|
|
6978
6993
|
}
|
|
6979
6994
|
|
|
6980
6995
|
// src/commerce/checkout.tsx
|
|
6996
|
+
function refuseOffering(offering, as) {
|
|
6997
|
+
if (typeof offering === "string" && offering.trim() !== "") return void 0;
|
|
6998
|
+
return `<${as}> has no \`offering\` \u2014 there is nothing to charge. Name the offering slot (offering="plan"). If you are migrating from an older SDK, the prop used to be \`product\`.`;
|
|
6999
|
+
}
|
|
6981
7000
|
function refuseSurface(provider, surface, managed) {
|
|
6982
7001
|
if (!managed) return void 0;
|
|
6983
7002
|
const check = validateCheckout(provider, surface, { managed });
|
|
@@ -7158,20 +7177,31 @@ function useCheckout(opts = {}) {
|
|
|
7158
7177
|
funnel.data.set({ purchased: true });
|
|
7159
7178
|
const { productId, isSubscription } = productFacts(product);
|
|
7160
7179
|
const amount = result.amountMinor != null ? result.amountMinor / 100 : void 0;
|
|
7161
|
-
|
|
7162
|
-
|
|
7163
|
-
|
|
7164
|
-
productId,
|
|
7165
|
-
eventId: result.eventId
|
|
7166
|
-
// server-minted (browser↔CAPI dedup); undefined if none
|
|
7167
|
-
});
|
|
7168
|
-
if (isSubscription) {
|
|
7169
|
-
tracker.track("subscription.created", {
|
|
7180
|
+
const isTrialStart = result.acquisition === "free_trial" || result.acquisition === "paid_trial";
|
|
7181
|
+
if (isTrialStart) {
|
|
7182
|
+
tracker.track("subscription.trial_started", {
|
|
7170
7183
|
amount,
|
|
7171
7184
|
currency: result.currency,
|
|
7172
7185
|
productId,
|
|
7173
7186
|
eventId: result.eventId
|
|
7187
|
+
// server-minted (browser↔CAPI dedup)
|
|
7174
7188
|
});
|
|
7189
|
+
} else {
|
|
7190
|
+
tracker.track("purchase.complete", {
|
|
7191
|
+
amount,
|
|
7192
|
+
currency: result.currency,
|
|
7193
|
+
productId,
|
|
7194
|
+
eventId: result.eventId
|
|
7195
|
+
// server-minted (browser↔CAPI dedup); undefined if none
|
|
7196
|
+
});
|
|
7197
|
+
if (isSubscription) {
|
|
7198
|
+
tracker.track("subscription.created", {
|
|
7199
|
+
amount,
|
|
7200
|
+
currency: result.currency,
|
|
7201
|
+
productId,
|
|
7202
|
+
eventId: result.eventId
|
|
7203
|
+
});
|
|
7204
|
+
}
|
|
7175
7205
|
}
|
|
7176
7206
|
opts.onSuccess?.(result);
|
|
7177
7207
|
if (advance) nav.next();
|
|
@@ -7542,7 +7572,7 @@ function CheckoutImpl({
|
|
|
7542
7572
|
notePreviewCheckout(as, product);
|
|
7543
7573
|
checkout.callbacksFor(product, surface).onSuccess({ ok: true });
|
|
7544
7574
|
};
|
|
7545
|
-
const rejection = refuseSurface(driver.provider, surface, managed);
|
|
7575
|
+
const rejection = refuseOffering(offering, as) ?? refuseSurface(driver.provider, surface, managed);
|
|
7546
7576
|
const callbacksRef = useRef(checkout.callbacksFor);
|
|
7547
7577
|
callbacksRef.current = checkout.callbacksFor;
|
|
7548
7578
|
useEffect(() => {
|
|
@@ -7697,6 +7727,14 @@ function UpsellButton(props) {
|
|
|
7697
7727
|
);
|
|
7698
7728
|
const checkout = useCheckout({ ...options, intent: "upsell", recoverySurface });
|
|
7699
7729
|
const isSample = useOffering(offering)?.sample === true;
|
|
7730
|
+
const rejection = refuseOffering(offering, "UpsellButton");
|
|
7731
|
+
const callbacksRef = useRef(checkout.callbacksFor);
|
|
7732
|
+
callbacksRef.current = checkout.callbacksFor;
|
|
7733
|
+
useEffect(() => {
|
|
7734
|
+
if (!rejection) return;
|
|
7735
|
+
callbacksRef.current(product).onError(checkoutError("processing_error", rejection, { retryable: false }));
|
|
7736
|
+
}, []);
|
|
7737
|
+
if (rejection) return null;
|
|
7700
7738
|
return trigger(
|
|
7701
7739
|
() => {
|
|
7702
7740
|
if (isSample) {
|
|
@@ -9494,5 +9532,5 @@ function useGroupProgress() {
|
|
|
9494
9532
|
}
|
|
9495
9533
|
|
|
9496
9534
|
export { Checkout, CheckoutButton, CheckoutResume, CheckoutSpinner, EmbedBridge, FunnelProvider, FunnelToaster, FunnelView, Modal, Sheet, UpsellButton, VariableStore, attachBus, buildAcquisition, buildContext, createBus, createConsoleTracker, createFunnelStore, createMockDriver, defineModal, dismissAllModals, driverWithEmail, ensureCheckoutButtonStyles, exposurePayload, hideModal, isValidEmail, newEventId, registerModal, removeModal, showModal, toast, unregisterModal, useActiveLocale, useCheckout, useClickIds, useContextValue, useData, useDevice, useExperiment, useField, useFunnel, useGroupProgress, useLocale, useMarketingConsent, useModal, useNavigation, useOffering, useOfferings, usePage, useResponse, useSystem, useTracker, useTranslation, useUserAttribute, useUtm, withBus };
|
|
9497
|
-
//# sourceMappingURL=chunk-
|
|
9498
|
-
//# sourceMappingURL=chunk-
|
|
9535
|
+
//# sourceMappingURL=chunk-WCBVSZHJ.js.map
|
|
9536
|
+
//# sourceMappingURL=chunk-WCBVSZHJ.js.map
|