@appfunnel-dev/sdk 2.0.0-canary.1 → 2.0.0-canary.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/capabilities-Dq22RCr_.d.cts +180 -0
- package/dist/capabilities-Dq22RCr_.d.ts +180 -0
- package/dist/checkout-ClaO5IYV.d.ts +333 -0
- package/dist/checkout-DBp4bCpC.d.cts +333 -0
- package/dist/chunk-7JLOF6CJ.cjs +172 -0
- package/dist/chunk-7JLOF6CJ.cjs.map +1 -0
- package/dist/chunk-EMMSS5I5.cjs +37 -0
- package/dist/chunk-EMMSS5I5.cjs.map +1 -0
- package/dist/chunk-G3PMV62Z.js +33 -0
- package/dist/chunk-G3PMV62Z.js.map +1 -0
- package/dist/chunk-JAO6AA4R.js +99 -0
- package/dist/chunk-JAO6AA4R.js.map +1 -0
- package/dist/chunk-OXQBEKZ5.js +157 -0
- package/dist/chunk-OXQBEKZ5.js.map +1 -0
- package/dist/chunk-VV7TFC64.cjs +106 -0
- package/dist/chunk-VV7TFC64.cjs.map +1 -0
- package/dist/chunk-VW2HVPR4.js +446 -0
- package/dist/chunk-VW2HVPR4.js.map +1 -0
- package/dist/chunk-WYUDL4FI.cjs +8 -0
- package/dist/chunk-WYUDL4FI.cjs.map +1 -0
- package/dist/chunk-Y4YNJ2EX.cjs +476 -0
- package/dist/chunk-Y4YNJ2EX.cjs.map +1 -0
- package/dist/chunk-ZZJG4EYL.js +6 -0
- package/dist/chunk-ZZJG4EYL.js.map +1 -0
- package/dist/driver-paddle.cjs +817 -0
- package/dist/driver-paddle.cjs.map +1 -0
- package/dist/driver-paddle.d.cts +10 -0
- package/dist/driver-paddle.d.ts +10 -0
- package/dist/driver-paddle.js +814 -0
- package/dist/driver-paddle.js.map +1 -0
- package/dist/driver-stripe.cjs +2312 -0
- package/dist/driver-stripe.cjs.map +1 -0
- package/dist/driver-stripe.d.cts +24 -0
- package/dist/driver-stripe.d.ts +24 -0
- package/dist/driver-stripe.js +2305 -0
- package/dist/driver-stripe.js.map +1 -0
- package/dist/index.cjs +2650 -841
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +343 -1005
- package/dist/index.d.ts +343 -1005
- package/dist/index.js +2381 -701
- package/dist/index.js.map +1 -1
- package/dist/manifest-B3Tdab0M.d.cts +920 -0
- package/dist/manifest-B3Tdab0M.d.ts +920 -0
- package/dist/manifest-entry.cjs +408 -0
- package/dist/manifest-entry.cjs.map +1 -0
- package/dist/manifest-entry.d.cts +192 -0
- package/dist/manifest-entry.d.ts +192 -0
- package/dist/manifest-entry.js +270 -0
- package/dist/manifest-entry.js.map +1 -0
- package/dist/protocol.cjs +13 -0
- package/dist/protocol.cjs.map +1 -0
- package/dist/protocol.d.cts +182 -0
- package/dist/protocol.d.ts +182 -0
- package/dist/protocol.js +4 -0
- package/dist/protocol.js.map +1 -0
- package/package.json +49 -4
|
@@ -0,0 +1,920 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
type VariableType = 'string' | 'number' | 'boolean' | 'stringArray';
|
|
4
|
+
type VariableValue = string | number | boolean | string[] | null | undefined;
|
|
5
|
+
interface VariableConfig {
|
|
6
|
+
type: VariableType;
|
|
7
|
+
default?: VariableValue;
|
|
8
|
+
persist?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* v2 `context` — the **read-only, computed** namespace.
|
|
13
|
+
*
|
|
14
|
+
* Everything the funnel can *read* but never *write*: the device, the visitor's
|
|
15
|
+
* locale, the current page, acquisition params (UTM), the session, and system
|
|
16
|
+
* facts (funnel id, test/live mode, clock). It supersedes the v0 flat
|
|
17
|
+
* `page.*`/`device.*`/`browser.*`/`os.*`/`query.*`/`metadata.*` system variables
|
|
18
|
+
* (see {@link ./systemVariables}) by folding them into one nested object.
|
|
19
|
+
*
|
|
20
|
+
* Why it's *not* in the {@link ./variableStore}: the store holds **writable**
|
|
21
|
+
* state (`user`/`responses`/`data`) that persists + re-renders per key. Context
|
|
22
|
+
* is derived and read-only, so it lives as a plain object on a React context —
|
|
23
|
+
* no subscriptions, no churn. The one moving part (`page`) is merged into the
|
|
24
|
+
* snapshot from navigation state at read time.
|
|
25
|
+
*
|
|
26
|
+
* Authors read it through hooks (`useDevice()`, `useLocale()`, `usePage()`,
|
|
27
|
+
* `useUtm()`) or inside routing/condition predicates as `s.context.*`.
|
|
28
|
+
*/
|
|
29
|
+
interface DeviceContext {
|
|
30
|
+
type: 'mobile' | 'tablet' | 'desktop';
|
|
31
|
+
isMobile: boolean;
|
|
32
|
+
isTablet: boolean;
|
|
33
|
+
screenWidth: number;
|
|
34
|
+
screenHeight: number;
|
|
35
|
+
viewportWidth: number;
|
|
36
|
+
viewportHeight: number;
|
|
37
|
+
colorDepth: number;
|
|
38
|
+
pixelRatio: number;
|
|
39
|
+
}
|
|
40
|
+
interface BrowserContext {
|
|
41
|
+
name: string;
|
|
42
|
+
version: string;
|
|
43
|
+
userAgent: string;
|
|
44
|
+
language: string;
|
|
45
|
+
cookieEnabled: boolean;
|
|
46
|
+
online: boolean;
|
|
47
|
+
}
|
|
48
|
+
interface OsContext {
|
|
49
|
+
name: string;
|
|
50
|
+
timezone: string;
|
|
51
|
+
}
|
|
52
|
+
interface LocaleContext {
|
|
53
|
+
/** Full locale, e.g. `en-US`. */
|
|
54
|
+
locale: string;
|
|
55
|
+
/** Language subtag, e.g. `en`. */
|
|
56
|
+
language: string;
|
|
57
|
+
/** Region subtag, e.g. `US` (may be empty). */
|
|
58
|
+
region: string;
|
|
59
|
+
/** IANA timezone, e.g. `America/New_York`. */
|
|
60
|
+
timeZone: string;
|
|
61
|
+
}
|
|
62
|
+
interface PageContext {
|
|
63
|
+
/** Current page key. */
|
|
64
|
+
key: string;
|
|
65
|
+
/** Current page URL slug (`meta.slug`, defaults to the key) — what the renderer puts in the path. */
|
|
66
|
+
slug: string;
|
|
67
|
+
/** 0-based position in the visited history. */
|
|
68
|
+
index: number;
|
|
69
|
+
/** Total pages in the (expected) flow. */
|
|
70
|
+
total: number;
|
|
71
|
+
/** 0–100. */
|
|
72
|
+
progressPercentage: number;
|
|
73
|
+
/** Epoch ms the current page was entered. */
|
|
74
|
+
startedAt: number;
|
|
75
|
+
}
|
|
76
|
+
/** Acquisition / ad params captured on entry (the old `query.*` utm slice). */
|
|
77
|
+
interface UtmContext {
|
|
78
|
+
source?: string;
|
|
79
|
+
medium?: string;
|
|
80
|
+
campaign?: string;
|
|
81
|
+
content?: string;
|
|
82
|
+
term?: string;
|
|
83
|
+
[key: string]: string | undefined;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Per-network ad **click-ids** captured from the entry URL — the matching signals
|
|
87
|
+
* the server CAPI needs. Named per network (not a generic bag) so the platform +
|
|
88
|
+
* each integration map them precisely; `[key]` catches any others.
|
|
89
|
+
*/
|
|
90
|
+
interface ClickIdContext {
|
|
91
|
+
/** Meta / Facebook */
|
|
92
|
+
fbclid?: string;
|
|
93
|
+
/** Google Ads (+ gbraid/wbraid for app↔web) */
|
|
94
|
+
gclid?: string;
|
|
95
|
+
gbraid?: string;
|
|
96
|
+
wbraid?: string;
|
|
97
|
+
/** Microsoft / Bing */
|
|
98
|
+
msclkid?: string;
|
|
99
|
+
/** TikTok */
|
|
100
|
+
ttclid?: string;
|
|
101
|
+
/** Twitter / X */
|
|
102
|
+
twclid?: string;
|
|
103
|
+
/** Snapchat */
|
|
104
|
+
sccid?: string;
|
|
105
|
+
/** LinkedIn */
|
|
106
|
+
li_fat_id?: string;
|
|
107
|
+
/** Pinterest */
|
|
108
|
+
epik?: string;
|
|
109
|
+
/** Reddit */
|
|
110
|
+
rdt_cid?: string;
|
|
111
|
+
[key: string]: string | undefined;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The full acquisition snapshot captured once on entry — the funnel reads `utm` /
|
|
115
|
+
* `clickIds` off {@link FunnelContext}; the SDK forwards this whole thing to the
|
|
116
|
+
* tracker (`setAcquisition`) so the platform persists it **first-class**: per-visit
|
|
117
|
+
* on the session + **first-touch (write-once) on the Customer**, and the click-ids /
|
|
118
|
+
* `_fbp`/`_fbc` cookies feed CAPI. Not stored as a generic attribute/answer.
|
|
119
|
+
*/
|
|
120
|
+
interface Acquisition {
|
|
121
|
+
utm: UtmContext;
|
|
122
|
+
clickIds: ClickIdContext;
|
|
123
|
+
/** CAPI cookies (`_fbp`/`_fbc`) read from `document.cookie` (not funnel-readable). */
|
|
124
|
+
cookies: {
|
|
125
|
+
fbp?: string;
|
|
126
|
+
fbc?: string;
|
|
127
|
+
};
|
|
128
|
+
/** `document.referrer` at entry. */
|
|
129
|
+
referrer: string;
|
|
130
|
+
/** Entry URL path (the landing page). */
|
|
131
|
+
landingPath: string;
|
|
132
|
+
}
|
|
133
|
+
interface SessionContext {
|
|
134
|
+
/** Server session id; null until resolved. */
|
|
135
|
+
id: string | null;
|
|
136
|
+
/** Epoch ms the session began. */
|
|
137
|
+
startedAt: number;
|
|
138
|
+
/** `document.referrer` at entry. */
|
|
139
|
+
referrer: string;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Durable identity for **stable experiment bucketing** (phase-4 §4.2). The
|
|
143
|
+
* preferred seed is the signed anonymous `visitorId` (stable from the first
|
|
144
|
+
* pageload, matching the server-side FUNNEL split in resolve.ts); `customerId` is
|
|
145
|
+
* only the fallback for cookieless SDK embeds. visitorId-FIRST is deliberate — the
|
|
146
|
+
* anon customerId is minted server-side AFTER the first tracked event, so seeding
|
|
147
|
+
* on it would flip a returning visitor's arm between visit 1 and 2 (see
|
|
148
|
+
* {@link ../flow/experiments}.bucketingSeed). It is deliberately **not** the
|
|
149
|
+
* session id or fingerprint — a returning visitor (e.g. via winback) must keep
|
|
150
|
+
* their variant across sessions (landmine #4). Both null = unidentifiable traffic,
|
|
151
|
+
* and the experiment layer falls back to control rather than bucket on nothing.
|
|
152
|
+
*/
|
|
153
|
+
interface IdentityContext {
|
|
154
|
+
/** Known customer id (post-identification). The fallback bucketing seed (cookieless embeds). */
|
|
155
|
+
customerId: string | null;
|
|
156
|
+
/** Signed anonymous visitor id. The preferred bucketing seed (stable from visit 1). */
|
|
157
|
+
visitorId: string | null;
|
|
158
|
+
}
|
|
159
|
+
interface SystemContext {
|
|
160
|
+
funnelId: string;
|
|
161
|
+
campaignId: string;
|
|
162
|
+
/** Render mode — `test` for preview/QA, `live` for public traffic. */
|
|
163
|
+
mode: 'test' | 'live';
|
|
164
|
+
/** Epoch ms captured at build time (stable per render, not a live clock). */
|
|
165
|
+
now: number;
|
|
166
|
+
}
|
|
167
|
+
/** The whole read-only computed namespace, as read in predicates: `s.context.*`. */
|
|
168
|
+
interface FunnelContext {
|
|
169
|
+
device: DeviceContext;
|
|
170
|
+
browser: BrowserContext;
|
|
171
|
+
os: OsContext;
|
|
172
|
+
locale: LocaleContext;
|
|
173
|
+
page: PageContext;
|
|
174
|
+
utm: UtmContext;
|
|
175
|
+
/** Per-network ad click-ids captured on entry (funnel-readable; also forwarded for CAPI). */
|
|
176
|
+
clickIds: ClickIdContext;
|
|
177
|
+
session: SessionContext;
|
|
178
|
+
identity: IdentityContext;
|
|
179
|
+
system: SystemContext;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Assemble the full {@link Acquisition} snapshot from the context + `document`
|
|
183
|
+
* (cookies, referrer, path) — captured once on entry, forwarded to the tracker for
|
|
184
|
+
* first-class persistence (session + first-touch Customer) + CAPI.
|
|
185
|
+
*/
|
|
186
|
+
declare function buildAcquisition(context: FunnelContext): Acquisition;
|
|
187
|
+
interface BuildContextOptions {
|
|
188
|
+
funnelId?: string;
|
|
189
|
+
campaignId?: string;
|
|
190
|
+
mode?: 'test' | 'live';
|
|
191
|
+
/** Stable build-time clock (avoids `Date.now()` churn in renders/tests). */
|
|
192
|
+
now?: number;
|
|
193
|
+
sessionId?: string | null;
|
|
194
|
+
/** Known customer id — the preferred stable bucketing seed (phase-4 §4.2). */
|
|
195
|
+
customerId?: string | null;
|
|
196
|
+
/** Signed anonymous visitor id — the fallback bucketing seed. */
|
|
197
|
+
visitorId?: string | null;
|
|
198
|
+
/** Overrides for any slice — used by the server to hydrate `utm`/`session`. */
|
|
199
|
+
overrides?: Partial<FunnelContext>;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Build the read-only {@link FunnelContext} once, at mount. `page` starts at the
|
|
203
|
+
* first page and is replaced per navigation when assembling a snapshot.
|
|
204
|
+
*/
|
|
205
|
+
declare function buildContext(opts?: BuildContextOptions): FunnelContext;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Pure catalog math — no React, no I/O. Split out of {@link ./catalog} so the
|
|
209
|
+
* server/tooling entry (`@appfunnel-dev/sdk/manifest`) can compile/resolve
|
|
210
|
+
* offerings without pulling react-dom or any component code into its graph.
|
|
211
|
+
* {@link ./catalog} re-exports everything here and adds the React wiring.
|
|
212
|
+
*/
|
|
213
|
+
type Interval = 'day' | 'week' | 'month' | 'year' | 'one_time';
|
|
214
|
+
/** What the platform hands the funnel per offering (a single provider-resolved price). */
|
|
215
|
+
interface OfferingInput {
|
|
216
|
+
id: string;
|
|
217
|
+
/** The catalog charge KEY this input charges (the slot's assignment). Defaults to `id` (legacy/identity slots). */
|
|
218
|
+
catalogKey?: string;
|
|
219
|
+
name?: string;
|
|
220
|
+
displayName?: string;
|
|
221
|
+
/** Provider-resolved price in **minor units** (the provider chose the currency). */
|
|
222
|
+
amount: number;
|
|
223
|
+
/** Currency of `amount`, as the provider resolved it (e.g. `DKK`). */
|
|
224
|
+
currency: string;
|
|
225
|
+
interval?: Interval;
|
|
226
|
+
intervalCount?: number;
|
|
227
|
+
trialDays?: number;
|
|
228
|
+
/** Trial price in minor units (omit/0 = free trial). */
|
|
229
|
+
trialAmount?: number;
|
|
230
|
+
/** Settlement provider — opaque to the author, used by the checkout driver. */
|
|
231
|
+
provider?: string;
|
|
232
|
+
}
|
|
233
|
+
/** A money value with a locale-formatted string. */
|
|
234
|
+
interface Money {
|
|
235
|
+
/** Major units, e.g. `79`. */
|
|
236
|
+
amount: number;
|
|
237
|
+
/** Minor units, e.g. `7900`. */
|
|
238
|
+
minor: number;
|
|
239
|
+
currency: string;
|
|
240
|
+
/** Locale-formatted, e.g. `kr 79,00` / `€9,99` / `$9.99`. */
|
|
241
|
+
formatted: string;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* The offering with its amounts resolved (currency + period math), **before**
|
|
245
|
+
* locale formatting — what the catalog stores. `useOffering` formats it.
|
|
246
|
+
*/
|
|
247
|
+
interface ResolvedOffering {
|
|
248
|
+
id: string;
|
|
249
|
+
/** The catalog charge KEY charged (the CHARGE identity; `id` is the SLOT/display identity). */
|
|
250
|
+
catalogKey: string;
|
|
251
|
+
name: string;
|
|
252
|
+
displayName: string;
|
|
253
|
+
provider: string;
|
|
254
|
+
currency: string;
|
|
255
|
+
priceMinor: number;
|
|
256
|
+
perDayMinor: number;
|
|
257
|
+
perWeekMinor: number;
|
|
258
|
+
perMonthMinor: number;
|
|
259
|
+
perYearMinor: number;
|
|
260
|
+
period: string;
|
|
261
|
+
periodly: string;
|
|
262
|
+
hasTrial: boolean;
|
|
263
|
+
trialDays: number;
|
|
264
|
+
trialMinor: number;
|
|
265
|
+
}
|
|
266
|
+
/** Display-ready offering the author reads (every amount locale-formatted). */
|
|
267
|
+
interface Offering {
|
|
268
|
+
id: string;
|
|
269
|
+
/** The catalog charge KEY charged (the CHARGE identity; `id` is the SLOT/display identity). */
|
|
270
|
+
catalogKey: string;
|
|
271
|
+
name: string;
|
|
272
|
+
displayName: string;
|
|
273
|
+
provider: string;
|
|
274
|
+
price: Money;
|
|
275
|
+
/** e.g. `month`, `quarter`, `one-time`. */
|
|
276
|
+
period: string;
|
|
277
|
+
/** e.g. `monthly`, `quarterly`, `one-time`. */
|
|
278
|
+
periodly: string;
|
|
279
|
+
/** Period-normalized prices (for "just $0.27/day" style copy). */
|
|
280
|
+
perDay: Money;
|
|
281
|
+
perWeek: Money;
|
|
282
|
+
perMonth: Money;
|
|
283
|
+
perYear: Money;
|
|
284
|
+
hasTrial: boolean;
|
|
285
|
+
trialDays: number;
|
|
286
|
+
trialPrice: Money | null;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Resolve an {@link OfferingInput} into amounts + period math (no formatting yet).
|
|
290
|
+
* Per-period amounts are **integer minor units** (each derived from the exact
|
|
291
|
+
* daily rate, then rounded — never round-then-multiply, so error doesn't compound).
|
|
292
|
+
*/
|
|
293
|
+
declare function resolveOffering(input: OfferingInput): ResolvedOffering;
|
|
294
|
+
/** Build the id → {@link ResolvedOffering} catalog. Formatting happens at read time. */
|
|
295
|
+
declare function buildCatalog(inputs: OfferingInput[]): Map<string, ResolvedOffering>;
|
|
296
|
+
/**
|
|
297
|
+
* The minor-unit exponent for a currency (`USD`→2, `JPY`→0, `KWD`/`BHD`→3),
|
|
298
|
+
* derived from `Intl.NumberFormat(...).resolvedOptions().maximumFractionDigits`
|
|
299
|
+
* with a fallback of 2 for unknown/invalid codes.
|
|
300
|
+
*/
|
|
301
|
+
declare function currencyExponent(currency: string): number;
|
|
302
|
+
/** Format minor units of `currency` in `locale` (exponent-aware: 7900 JPY = ¥7,900). */
|
|
303
|
+
declare function formatMoney(minor: number, currency: string, locale: string): Money;
|
|
304
|
+
/** Format a {@link ResolvedOffering} into a display {@link Offering} in `locale`. */
|
|
305
|
+
declare function formatOffering(r: ResolvedOffering, locale: string): Offering;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* The funnel **spine** — the constrained, declarative configuration authored as
|
|
309
|
+
* code (`defineFunnel` / `pageMeta` / `definePage`) yet **dashboard-editable**
|
|
310
|
+
* (static AST parse → pretty UI → codegen) and compiled to the manifest IR.
|
|
311
|
+
*
|
|
312
|
+
* Principle: **presentation = code** (the page components), **configuration =
|
|
313
|
+
* data** (this spine). See docs/platform-v2/06-funnel-project-model.md.
|
|
314
|
+
*
|
|
315
|
+
* Routing is **declarative nodes + code predicates** (decided — doc 06): a
|
|
316
|
+
* page's `next` is an ordered list of {@link Route}s, each with a **static `to`
|
|
317
|
+
* page key** (so the dashboard can draw every possible edge without executing
|
|
318
|
+
* anything) and an optional `when` **gate** that returns true/false. The gate is
|
|
319
|
+
* either a declarative {@link Condition} (one field — UI-editable data) or a code
|
|
320
|
+
* {@link Predicate} (`s => boolean` — the escape hatch, opaque body but the edge
|
|
321
|
+
* is still visible). First matching route wins; a route with no `when` is the
|
|
322
|
+
* fallback. Multiple conditions = multiple routes (or boolean logic in one
|
|
323
|
+
* predicate). Omit `next` entirely for the default linear flow.
|
|
324
|
+
*/
|
|
325
|
+
/**
|
|
326
|
+
* Read-only view of every namespace a routing/condition predicate can branch
|
|
327
|
+
* on. `user`/`responses`/`data` are the writable namespaces; `context` is the
|
|
328
|
+
* read-only computed one ({@link FunnelContext}).
|
|
329
|
+
*/
|
|
330
|
+
interface FunnelSnapshot {
|
|
331
|
+
user: Record<string, VariableValue>;
|
|
332
|
+
responses: Record<string, VariableValue>;
|
|
333
|
+
data: Record<string, VariableValue>;
|
|
334
|
+
context: FunnelContext;
|
|
335
|
+
}
|
|
336
|
+
/** A code-predicate gate — `s => s.responses.goal === 'gain'`. */
|
|
337
|
+
type Predicate = (s: FunnelSnapshot) => boolean;
|
|
338
|
+
type ConditionOp = 'eq' | 'neq' | 'in' | 'gt' | 'gte' | 'lt' | 'lte' | 'exists' | 'empty' | 'contains';
|
|
339
|
+
/**
|
|
340
|
+
* A declarative gate over **one** namespaced field — UI-editable data the
|
|
341
|
+
* dashboard renders as a condition row (`field` `op` `value`). `field` is a
|
|
342
|
+
* dotted path into the snapshot: `responses.goal`, `user.country`,
|
|
343
|
+
* `context.device.isMobile`.
|
|
344
|
+
*/
|
|
345
|
+
interface Condition {
|
|
346
|
+
field: string;
|
|
347
|
+
op: ConditionOp;
|
|
348
|
+
value?: VariableValue | VariableValue[];
|
|
349
|
+
}
|
|
350
|
+
/** An edge gate: either declarative data ({@link Condition}) or a {@link Predicate}. */
|
|
351
|
+
type Gate = Condition | Predicate;
|
|
352
|
+
/**
|
|
353
|
+
* One routing edge out of a page. `to` is a **static** target key (the dashboard
|
|
354
|
+
* reads these to draw the flow graph); `when` gates the edge (omit = fallback).
|
|
355
|
+
*/
|
|
356
|
+
interface Route {
|
|
357
|
+
to: string;
|
|
358
|
+
when?: Gate;
|
|
359
|
+
}
|
|
360
|
+
/** Evaluate a declarative {@link Condition} against a snapshot. */
|
|
361
|
+
declare function evaluateCondition(cond: Condition, s: FunnelSnapshot): boolean;
|
|
362
|
+
/** Evaluate either gate kind to a boolean. */
|
|
363
|
+
declare function evaluateGate(gate: Gate, s: FunnelSnapshot): boolean;
|
|
364
|
+
/**
|
|
365
|
+
* Resolve an ordered list of routes to a target page key, or `undefined` to fall
|
|
366
|
+
* through to the linear next. First route whose gate passes (or has no `when`)
|
|
367
|
+
* wins.
|
|
368
|
+
*/
|
|
369
|
+
declare function resolveRoute(routes: Route[] | undefined, s: FunnelSnapshot): string | undefined;
|
|
370
|
+
type PageType = 'default' | 'email-capture' | 'paywall' | 'upsell' | 'finish';
|
|
371
|
+
interface PageMeta {
|
|
372
|
+
/** Page kind — drives behavior + analytics (e.g. `paywall`, `upsell`). */
|
|
373
|
+
type?: PageType;
|
|
374
|
+
/** URL slug; defaults to the page key. */
|
|
375
|
+
slug?: string;
|
|
376
|
+
/**
|
|
377
|
+
* Ordered routing edges out of this page (first match wins). Each has a static
|
|
378
|
+
* `to` key + an optional `when` gate. Omit for the default linear flow.
|
|
379
|
+
*
|
|
380
|
+
* OPTIONAL per-variant routing: a `@variant` page (`paywall@b`) MAY carry its own
|
|
381
|
+
* `next`. When that variant is the one served for its slot, its `next` governs
|
|
382
|
+
* routing for that visitor; absent, the variant inherits the slot's routing (the
|
|
383
|
+
* default — a pure superset, no behavior change for existing funnels). Assignment,
|
|
384
|
+
* exposure, and progress still anchor on the slot; only the next-page lookup
|
|
385
|
+
* consults the served variant's routes. See {@link FunnelPage}.
|
|
386
|
+
*/
|
|
387
|
+
next?: Route[];
|
|
388
|
+
/**
|
|
389
|
+
* Entry precondition for **deep-link / reload** restoration. When the runtime is
|
|
390
|
+
* asked to start *on this page* (not via in-funnel navigation), it restores there
|
|
391
|
+
* only if `guard` passes against the restored snapshot — otherwise it falls back
|
|
392
|
+
* to the start page. e.g. an upsell page: `guard: s => s.data.purchased === true`.
|
|
393
|
+
* Reaching the page via `next()` is unaffected (routing already gated it). Omit =
|
|
394
|
+
* always restorable. Same gate kind as routing (`Condition` or predicate).
|
|
395
|
+
*/
|
|
396
|
+
guard?: Gate;
|
|
397
|
+
/**
|
|
398
|
+
* BUILD-TIME PRERENDER OPT-OUT (SSR-isolation Option B, FIX 2). Set `dynamic: true` (alias
|
|
399
|
+
* `prerender: false`) on a page whose **structure** (which sections exist — not just their text
|
|
400
|
+
* values) depends on the visitor's `sessionValues`. Such a page can't be prerendered flash-free:
|
|
401
|
+
* the default-state markup would structurally differ from the value-applied render and reflow
|
|
402
|
+
* after hydration. Opting out makes the build SKIP prerendering it, so the renderer serves it via
|
|
403
|
+
* live SSR (the same fallback branch a build with no prerender entry already uses) — correct
|
|
404
|
+
* first paint, no pop-in. Value-only variation (text/price into a fixed structure) does NOT need
|
|
405
|
+
* this: deferred defaults make it flash-free. Omit = prerendered (the default).
|
|
406
|
+
*/
|
|
407
|
+
dynamic?: boolean;
|
|
408
|
+
/** @see {@link PageMeta.dynamic} — `prerender: false` is the inverse alias (author preference). */
|
|
409
|
+
prerender?: boolean;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Identity helper for a page's co-located metadata.
|
|
413
|
+
* `export const meta = pageMeta({ type: 'paywall', next: s => … })`.
|
|
414
|
+
*/
|
|
415
|
+
declare function pageMeta(meta: PageMeta): PageMeta;
|
|
416
|
+
/**
|
|
417
|
+
* The effective entry guard for a page: an explicit `meta.guard` if the author set
|
|
418
|
+
* one, **otherwise** the page-type default (e.g. paywall/upsell need email). The
|
|
419
|
+
* explicit guard fully **overrides** the default — it's not combined. Returns
|
|
420
|
+
* `undefined` when neither applies.
|
|
421
|
+
*/
|
|
422
|
+
declare function entryGuard(meta?: PageMeta): Gate | undefined;
|
|
423
|
+
/**
|
|
424
|
+
* Identity helper for a page component. The page is plain React that reaches the
|
|
425
|
+
* runtime through hooks (`useResponse`, `useNavigation`, …) — there is no `sdk`
|
|
426
|
+
* prop. `export default definePage(function Welcome() { … })`.
|
|
427
|
+
*/
|
|
428
|
+
declare function definePage<P extends object = Record<string, never>>(component: ComponentType<P>): ComponentType<P>;
|
|
429
|
+
/** A page in the flow: its key + (optional) co-located meta. */
|
|
430
|
+
interface FlowPage {
|
|
431
|
+
key: string;
|
|
432
|
+
meta?: PageMeta;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* A page as declared in `funnel.ts` — the key + its metadata, flattened. This is the
|
|
436
|
+
* AUTHORED shape (funnel.ts owns the page list, order, and routing); the build generates
|
|
437
|
+
* the code-split `mount.tsx` from it. Routing (`next`) must stay DECLARATIVE (Route[] with
|
|
438
|
+
* `{ to, when }` conditions, no predicate functions) so the web builder UI can edit it.
|
|
439
|
+
*
|
|
440
|
+
* OPTIONAL variant routing (default off): a served variant's OWN routing is authored by
|
|
441
|
+
* declaring the variant here with its `@` key and a `next`, e.g.
|
|
442
|
+
* `{ key: 'paywall@b', next: [{ to: 'special-offer' }] }`. A variant declared this way keys
|
|
443
|
+
* on the `@` marker, so it still collapses out of the linear flow (it is NOT a linear step);
|
|
444
|
+
* its `next` is consulted only when that variant is the one served for its slot. Omit the
|
|
445
|
+
* declaration (leave the variant an undeclared `pages/<slot>@<v>.tsx` file) to inherit the
|
|
446
|
+
* slot's routing — the existing behavior, unchanged. The slot's control keeps owning
|
|
447
|
+
* assignment/exposure/progress; only the next-page lookup for a branched variant differs.
|
|
448
|
+
*/
|
|
449
|
+
interface FunnelPage extends PageMeta {
|
|
450
|
+
key: string;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Decide the next page from `currentKey`:
|
|
454
|
+
* 1. the current page's `next` routes ({@link resolveRoute}), if one matches, else
|
|
455
|
+
* 2. the next page in file order (the default linear flow), else
|
|
456
|
+
* 3. `undefined` (end of funnel / current key not found).
|
|
457
|
+
*/
|
|
458
|
+
declare function nextPage(pages: FlowPage[], currentKey: string, s: FunnelSnapshot): string | undefined;
|
|
459
|
+
/**
|
|
460
|
+
* Every page a visitor *could* go to next from `currentKey` — all route targets
|
|
461
|
+
* (regardless of gate, since we don't know which will pass) plus the linear next.
|
|
462
|
+
* Used to **prefetch** the likely-next page chunks; not for navigation.
|
|
463
|
+
*/
|
|
464
|
+
declare function outgoingKeys(pages: FlowPage[], currentKey: string): string[];
|
|
465
|
+
/**
|
|
466
|
+
* The number of pages on the path from `startKey` to a `finish` (or the end of
|
|
467
|
+
* the flow) **given the current state** — the denominator for progress. It walks
|
|
468
|
+
* the actual routing ({@link nextPage}) rather than counting all files, so a
|
|
469
|
+
* branched funnel reaches 100% on whichever path the visitor's answers select.
|
|
470
|
+
* Re-traced per navigation; a visited set guards against routing cycles.
|
|
471
|
+
*/
|
|
472
|
+
declare function expectedPathLength(pages: FlowPage[], startKey: string, s: FunnelSnapshot): number;
|
|
473
|
+
interface FunnelLocales {
|
|
474
|
+
default: string;
|
|
475
|
+
supported: string[];
|
|
476
|
+
fallback?: string;
|
|
477
|
+
/**
|
|
478
|
+
* When `true`, a visitor with no explicit language in the URL (no `/<locale>/` path prefix and no
|
|
479
|
+
* `?language=`) is served the best match for their **browser** `Accept-Language` among `supported`
|
|
480
|
+
* (base-matched, so `en-GB` → `en`); no match falls back to `default`. When `false`/absent (the
|
|
481
|
+
* default), an unspecified visitor always gets `default` — the URL is the only way to switch.
|
|
482
|
+
*/
|
|
483
|
+
autoDetectLanguage?: boolean;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* The funnel-level spine. Flow is mostly inferred from page file order + each
|
|
487
|
+
* page's `next`; this holds the funnel-wide config. Stays **thin** — routing
|
|
488
|
+
* lives co-located on pages (doc 06: "funnel.ts stays thin").
|
|
489
|
+
*/
|
|
490
|
+
interface FunnelDefinition {
|
|
491
|
+
id: string;
|
|
492
|
+
/**
|
|
493
|
+
* The funnel's pages — order, type, and declarative routing — the source of truth the
|
|
494
|
+
* web builder edits and the build generates `mount.tsx` from. Each `key` maps to a
|
|
495
|
+
* `pages/<key>.tsx` component. Omit `pages` on hand-written funnels that still ship their
|
|
496
|
+
* own `mount.tsx` (back-compat); new/generated funnels declare them here.
|
|
497
|
+
*/
|
|
498
|
+
pages?: FunnelPage[];
|
|
499
|
+
/** Which checkout provider the paywall/checkout uses. The build wires the driver. */
|
|
500
|
+
checkout?: 'stripe' | 'paddle';
|
|
501
|
+
/** `responses.*` runtime variables (default values). */
|
|
502
|
+
responses?: Record<string, VariableConfig>;
|
|
503
|
+
/** `data.*` working/scratch variables (default values). */
|
|
504
|
+
data?: Record<string, VariableConfig>;
|
|
505
|
+
/**
|
|
506
|
+
* The catalog offerings this funnel sells, as SLOTS: a local, stable key each PAGE
|
|
507
|
+
* references (`useOffering('primary')`, `<Checkout offering="primary">`) → the catalog charge
|
|
508
|
+
* KEY it's assigned to. Swap the assignment to change the offer WITHOUT touching page code;
|
|
509
|
+
* `null` = a declared-but-unassigned slot. A bare `string[]` is legacy sugar for IDENTITY
|
|
510
|
+
* slots (`['pro'] ≡ { pro: 'pro' }`) — every existing funnel keeps working. Prices resolve
|
|
511
|
+
* from the project catalog per environment (Live/Test) at render.
|
|
512
|
+
*/
|
|
513
|
+
offerings?: string[] | Record<string, string | null>;
|
|
514
|
+
locales?: FunnelLocales;
|
|
515
|
+
/**
|
|
516
|
+
* When `true`, the funnel shows the **geo-specific** currency/price the payment
|
|
517
|
+
* provider resolves (Stripe `currency_options`, Paddle preview, Whop, SolidGate,
|
|
518
|
+
* …). When `false` (default), a single fixed currency is used. Appfunnel does no
|
|
519
|
+
* FX — this only toggles whether the platform asks the provider for the geo
|
|
520
|
+
* price; the SDK just displays whatever resolved `{amount, currency}` it's handed.
|
|
521
|
+
* (See docs/platform-v2 phase-3 §3.6.)
|
|
522
|
+
*/
|
|
523
|
+
locationAwareCurrency?: boolean;
|
|
524
|
+
}
|
|
525
|
+
/** Identity helper for a funnel definition. */
|
|
526
|
+
declare function defineFunnel(def: FunnelDefinition): FunnelDefinition;
|
|
527
|
+
/** A funnel offering SLOT: the local key pages reference → the assigned catalog charge key (null = unassigned). */
|
|
528
|
+
interface OfferingSlot {
|
|
529
|
+
slot: string;
|
|
530
|
+
catalogKey: string | null;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Normalize `FunnelDefinition.offerings` to a slot list. A legacy `string[]` becomes IDENTITY
|
|
534
|
+
* slots (`['pro'] → [{ slot:'pro', catalogKey:'pro' }]`); a `{ slot: key|null }` map becomes its
|
|
535
|
+
* entries (insertion order preserved, so `useOfferings()` is deterministic).
|
|
536
|
+
*/
|
|
537
|
+
declare function normalizeOfferings(offerings: FunnelDefinition['offerings']): OfferingSlot[];
|
|
538
|
+
/** The unique, ASSIGNED catalog keys a funnel charges — for the promote gate + catalog reverse-lookup. */
|
|
539
|
+
declare function funnelCatalogKeys(offerings: FunnelDefinition['offerings']): string[];
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Pure locale resolution — no React. Split out of {@link ./translation} so the
|
|
543
|
+
* server/tooling entry (`@appfunnel-dev/sdk/manifest`) can resolve a visitor's
|
|
544
|
+
* locale without pulling component code. {@link ./translation} re-exports it.
|
|
545
|
+
*/
|
|
546
|
+
|
|
547
|
+
type Direction = 'ltr' | 'rtl';
|
|
548
|
+
/** Whether a locale is right-to-left (by language subtag). */
|
|
549
|
+
declare function isRtl(locale: string): boolean;
|
|
550
|
+
/**
|
|
551
|
+
* Resolve the active locale: `override` (URL/param) → `detected` (device) →
|
|
552
|
+
* funnel default, each only if supported (matched by exact tag or language
|
|
553
|
+
* subtag). Mirrors doc 05's resolution chain (the geo/header steps happen
|
|
554
|
+
* server-side and arrive via `override`/`detected`).
|
|
555
|
+
*/
|
|
556
|
+
declare function resolveLocale(config: FunnelLocales | undefined, detected: string, override?: string): string;
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* **Runtime page-level experiments** — A/B/n on a *single page inside one funnel*,
|
|
560
|
+
* resolved at render time (phase-4). No funnel duplication: a slot (e.g. the page
|
|
561
|
+
* `welcome`) has alternate versions filed as siblings (`welcome@b.tsx`), and the
|
|
562
|
+
* runtime shows **one** of them per visitor, collapsing the losers out of the
|
|
563
|
+
* linear flow. The flow keeps stable **slot keys** (the control's key); only the
|
|
564
|
+
* rendered component swaps — so routing, the manifest, and analytics all key on the
|
|
565
|
+
* slot, not the variant.
|
|
566
|
+
*
|
|
567
|
+
* **Where the wiring lives:** the *variant pages* are code (compiled into the
|
|
568
|
+
* bundle). The *experiment wiring* — slot, variant→page map, weights, status — is
|
|
569
|
+
* **operational data the platform owns** (a DB record, edited by the dashboard,
|
|
570
|
+
* changed without recompiling the funnel). The SDK is storage-agnostic: the
|
|
571
|
+
* platform hands the runtime experiment records to `FunnelProvider`, the same way
|
|
572
|
+
* it hands in resolved product prices. This module just resolves them.
|
|
573
|
+
*
|
|
574
|
+
* **The only source-side marker** is the `@` in a variant file's key
|
|
575
|
+
* (`welcome@b`): it tells the *build* (manifest, flow graph) that a page is an
|
|
576
|
+
* off-flow variant of its slot, so the structure is correct without the DB. The
|
|
577
|
+
* label/weight/experiment-id are not in source.
|
|
578
|
+
*
|
|
579
|
+
* Bucketing is a deterministic FNV-1a hash, **namespaced by experiment id** so
|
|
580
|
+
* independent experiments bucket orthogonally (the basis for layering 100+ tests,
|
|
581
|
+
* §4.3). The seed is the durable identity ({@link bucketingSeed}) — never the
|
|
582
|
+
* session/fingerprint — so a returning visitor keeps their variant (landmine #4).
|
|
583
|
+
* Stability across an *add-a-variant* edit is the platform's job: an experiment's
|
|
584
|
+
* variant set is immutable while running (reweighting / adding an arm = a new
|
|
585
|
+
* experiment version), so within one record the assignment never moves.
|
|
586
|
+
*
|
|
587
|
+
* This module is pure (no React, no I/O) → it unit-tests trivially and the
|
|
588
|
+
* dashboard/server can reuse the same assignment math.
|
|
589
|
+
*/
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* FNV-1a 32-bit hash → unsigned int. Deterministic and isomorphic (no `crypto`,
|
|
593
|
+
* runs the same in the browser, a worker, and a build). The same math v0 used,
|
|
594
|
+
* kept because it's sound — only the *seed* changes (identity, not session).
|
|
595
|
+
*/
|
|
596
|
+
declare function fnv1a(input: string): number;
|
|
597
|
+
/** Map a seed string to a stable float in `[0, 1)`. */
|
|
598
|
+
declare function hashToUnit(seed: string): number;
|
|
599
|
+
/**
|
|
600
|
+
* Pick a variant key by weight from a stable unit position `u ∈ [0,1)`. Variants
|
|
601
|
+
* are walked in declaration order and the first whose cumulative weight band
|
|
602
|
+
* contains `u` wins, so the same `u` always lands in the same variant.
|
|
603
|
+
*/
|
|
604
|
+
declare function pickByWeight(weights: Record<string, number>, u: number): string;
|
|
605
|
+
/**
|
|
606
|
+
* Deterministically assign a visitor (`seed`) to a variant of one experiment.
|
|
607
|
+
* The hash is **namespaced by `experimentId`** so two experiments on the same
|
|
608
|
+
* traffic don't correlate (orthogonal layering).
|
|
609
|
+
*/
|
|
610
|
+
declare function assignVariant(experimentId: string, seed: string, weights: Record<string, number>): string;
|
|
611
|
+
/**
|
|
612
|
+
* The stable bucketing seed: the signed `visitorId`, else the known `customerId`.
|
|
613
|
+
* Never the session id or fingerprint (landmine #4). `null` when neither is known
|
|
614
|
+
* — the caller then serves control instead of bucketing on nothing.
|
|
615
|
+
*
|
|
616
|
+
* visitorId-FIRST (not customerId-first) is deliberate: the customerId injected for an
|
|
617
|
+
* anonymous visitor is minted server-side AFTER the first tracked event, so it is absent on
|
|
618
|
+
* visit 1 and present on visit 2 — seeding on it would flip a returning visitor's arm and
|
|
619
|
+
* count them in two arms of the same version. The signed `af_vid` cookie is the durable
|
|
620
|
+
* identity that's stable from the first pageload, so it seeds; customerId is only the fallback
|
|
621
|
+
* for cookieless SDK embeds. This matches the server-side FUNNEL split, which already seeds on
|
|
622
|
+
* the verified visitorId (resolve.ts). (Cross-device stable bucketing for IDENTIFIED customers
|
|
623
|
+
* is P3's IdentitySDK job, not this anonymous path.)
|
|
624
|
+
*/
|
|
625
|
+
declare function bucketingSeed(context: FunnelContext): string | null;
|
|
626
|
+
/** Split a page key into its slot + optional variant: `welcome@b` → `{ slot, variant: 'b' }`. */
|
|
627
|
+
declare function parseSlotKey(key: string): {
|
|
628
|
+
slot: string;
|
|
629
|
+
variant?: string;
|
|
630
|
+
};
|
|
631
|
+
/** True if a page key is an off-flow variant (`welcome@b`), by the source-side `@` marker. */
|
|
632
|
+
declare function isVariantKey(key: string): boolean;
|
|
633
|
+
/** One arm of a running experiment: which page renders, at what weight. */
|
|
634
|
+
interface ExperimentArm {
|
|
635
|
+
/** The page key this arm renders (the slot's control, or a `@variant` sibling). */
|
|
636
|
+
page: string;
|
|
637
|
+
/** Relative weight in the split (need not sum to 100; zero = paused arm). */
|
|
638
|
+
weight: number;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* A runtime experiment record — the operational wiring the **platform** owns and
|
|
642
|
+
* hands to the SDK (not authored in the funnel source). Projected from the unified
|
|
643
|
+
* `Experiment`/`ExperimentArm` graph (a RUNNING PAGE experiment + its arms): the
|
|
644
|
+
* experiment's `slot` names the base page, and each arm becomes a `variants` entry
|
|
645
|
+
* `{ page: arm.pageKey, weight: arm.weight }` keyed by `arm.label`. The variant
|
|
646
|
+
* *pages* are code in the LIVE build; this is the live split over them.
|
|
647
|
+
*
|
|
648
|
+
* The serve join only ever hands over RUNNING experiments, and the server's
|
|
649
|
+
* draft-write + serve guards make every active arm's page GUARANTEED present in the
|
|
650
|
+
* LIVE build (an experiment owns its arm pages' lifecycle — you end the experiment to
|
|
651
|
+
* remove a page, you can't drift it away). So there is no lifecycle/winner state and
|
|
652
|
+
* no "arm page missing" case to resolve here.
|
|
653
|
+
*/
|
|
654
|
+
interface RuntimeExperiment {
|
|
655
|
+
id: string;
|
|
656
|
+
/** The page key holding the flow position (the anchor / the control arm's base page). */
|
|
657
|
+
slot: string;
|
|
658
|
+
/** label → arm. The control arm's `page` is the `slot`; others are `@variant` siblings. */
|
|
659
|
+
variants: Record<string, ExperimentArm>;
|
|
660
|
+
/** Primary metric (analytics only; not used for resolution). */
|
|
661
|
+
metric?: string;
|
|
662
|
+
/** Platform record version (immutable-while-running; reweight = new version). Rides on
|
|
663
|
+
* exposure events so results key on (experimentId, version, variant). */
|
|
664
|
+
version?: number;
|
|
665
|
+
}
|
|
666
|
+
interface ExperimentResolution {
|
|
667
|
+
/** experiment id → assigned variant label. */
|
|
668
|
+
assignments: Record<string, string>;
|
|
669
|
+
/** Page keys forming the effective linear flow (variant siblings removed), in order. */
|
|
670
|
+
activeKeys: string[];
|
|
671
|
+
/** Slot key → the page key whose component should render there. */
|
|
672
|
+
render: Record<string, string>;
|
|
673
|
+
/** Variant page key → its slot key. For remapping a route that targets a variant. */
|
|
674
|
+
slotOf: Record<string, string>;
|
|
675
|
+
/** Slot key → the experiment id it hosts (drives the exposure event). */
|
|
676
|
+
experimentOf: Record<string, string>;
|
|
677
|
+
/** Experiment id → platform record version (rides on exposure events). */
|
|
678
|
+
versionOf: Record<string, number>;
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Weights map (label → weight) for one experiment's arms. Exported (via the pure
|
|
682
|
+
* manifest entry) so the server-side FUNNEL split (renderer resolve) projects arms
|
|
683
|
+
* the same way before calling {@link assignVariant}, instead of re-inlining it.
|
|
684
|
+
*/
|
|
685
|
+
declare function weightsOf(variants: Record<string, {
|
|
686
|
+
weight: number;
|
|
687
|
+
}>): Record<string, number>;
|
|
688
|
+
/**
|
|
689
|
+
* Resolve which page version each experiment slot shows for this visitor, and which
|
|
690
|
+
* page keys remain in the linear flow.
|
|
691
|
+
*
|
|
692
|
+
* Variant pages are detected structurally by the `@` in their key, so they collapse
|
|
693
|
+
* out of the linear flow even for a slot with no active experiment. Each served
|
|
694
|
+
* experiment is RUNNING with all its arm pages guaranteed present in the LIVE build
|
|
695
|
+
* (the server draft-write + serve guards enforce the experiment-owned lifecycle
|
|
696
|
+
* invariant), so the visitor is bucketed deterministically on `seed` and the assigned
|
|
697
|
+
* arm's page is swapped in with no presence check. With no `seed` there is nothing
|
|
698
|
+
* stable to bucket on, so every slot renders its own control page.
|
|
699
|
+
*/
|
|
700
|
+
declare function resolveExperiments(pages: {
|
|
701
|
+
key: string;
|
|
702
|
+
}[], experiments: RuntimeExperiment[], seed: string | null): ExperimentResolution;
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* Pure, React-free page scan: find which offering SLOTS a funnel's pages reference — the first
|
|
706
|
+
* string-literal arg of `useOffering(...)` and the `offering` prop of `<Checkout>` / `<Upsell>`.
|
|
707
|
+
* Ships via `@appfunnel-dev/sdk/manifest` so the BUILD, the EDITOR, and the AI all run the SAME
|
|
708
|
+
* check. The result feeds `compileManifest({ offeringRefs })`, which flags references to slots the
|
|
709
|
+
* funnel doesn't declare (unknown) or hasn't assigned a catalog charge key to (unassigned).
|
|
710
|
+
*
|
|
711
|
+
* Non-literal args (`useOffering(selectedId)`, `offering={expr}`) and the `useOfferings()` wildcard are
|
|
712
|
+
* DYNAMIC — they can't be statically enumerated, so they're reported via `dynamic` and never turned
|
|
713
|
+
* into a hard error (validation relaxes when a funnel is dynamic). Mirrors the mask-then-read
|
|
714
|
+
* discipline the funnel.ts code-mods use, so a `useOffering('x')` inside a comment or string literal
|
|
715
|
+
* can't false-positive.
|
|
716
|
+
*/
|
|
717
|
+
interface OfferingRefScan {
|
|
718
|
+
/** Concrete slot names referenced by LITERAL args, deduped, in first-seen order. */
|
|
719
|
+
slots: string[];
|
|
720
|
+
/** True if any ref is a non-literal arg or a `useOfferings()` wildcard (not statically enumerable). */
|
|
721
|
+
dynamic: boolean;
|
|
722
|
+
/**
|
|
723
|
+
* Checkout-SURFACE usage the pages express — feeds the publish (provider × surface) capability
|
|
724
|
+
* gate. Absent-field back-compat: a manifest compiled before this existed simply omits it, and
|
|
725
|
+
* the gate skips (no false blocks). See {@link CheckoutUsageScan}.
|
|
726
|
+
*/
|
|
727
|
+
checkout: CheckoutUsageScan;
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* What the pages ask the checkout to DO, statically — the surfaces they mount and the off-session
|
|
731
|
+
* upsell kinds they charge. Literal values only; a computed value (`surface={expr}`) sets
|
|
732
|
+
* {@link dynamic} so the publish gate WARNS instead of hard-failing (it can't enumerate it).
|
|
733
|
+
*/
|
|
734
|
+
interface CheckoutUsageScan {
|
|
735
|
+
/**
|
|
736
|
+
* Purchase SURFACES the pages request, deduped in first-seen order. Captures every literal
|
|
737
|
+
* `<Checkout surface="…">` plus the on-session re-collect surfaces `<Checkout|Upsell fallback="…">`
|
|
738
|
+
* and `recoverySurface="…"` (a fallback re-collects a card → it IS a purchase surface the provider
|
|
739
|
+
* must support). Validated with `validateCheckout(provider, surface)`.
|
|
740
|
+
*/
|
|
741
|
+
surfaces: string[];
|
|
742
|
+
/**
|
|
743
|
+
* Off-session upsell KINDS from `<Upsell kind="…">`, deduped. A `<Upsell>` with no `kind` attr
|
|
744
|
+
* defaults to `'subscription'` (mirrors the runtime default), so an unadorned `<Upsell>` records
|
|
745
|
+
* `'subscription'`. Validated with `validateUpsell(provider, paywallSurface, kind)`.
|
|
746
|
+
*/
|
|
747
|
+
upsellKinds: string[];
|
|
748
|
+
/** True if any surface/kind was a non-literal (computed) value → the gate WARNS, never blocks, on it. */
|
|
749
|
+
dynamic: boolean;
|
|
750
|
+
}
|
|
751
|
+
declare function scanOfferingRefs(files: Record<string, string>): OfferingRefScan;
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* The **manifest** — the declarative IR a funnel project compiles to (doc 06).
|
|
755
|
+
* It's the machine-readable artifact the platform operates on without executing
|
|
756
|
+
* the funnel: the dashboard draws the flow graph from it, analytics binds to its
|
|
757
|
+
* **stable ids**, validation runs against it, and the renderer reads it to resolve
|
|
758
|
+
* routing.
|
|
759
|
+
*
|
|
760
|
+
* `compileManifest` evaluates the spine (the funnel config + each page's co-located
|
|
761
|
+
* `meta`) into that IR. It's pure — no I/O — so it unit-tests trivially. **It runs
|
|
762
|
+
* server-side**, as the IR step of the publish build over the canonical files in our
|
|
763
|
+
* storage (R2). The client/CLI never produces the authoritative manifest — R2 is the
|
|
764
|
+
* source of truth, the server compiles. (A local dev preview may run it for itself,
|
|
765
|
+
* but that output is never published.)
|
|
766
|
+
*
|
|
767
|
+
* Edge model mirrors the runtime ({@link ../flow/spine}.`nextPage`): a page's
|
|
768
|
+
* `meta.next` routes become **branch** edges (with a serialized condition — a
|
|
769
|
+
* declarative {@link Condition}, or an opaque marker for a code predicate), and the
|
|
770
|
+
* implicit file-order fall-through becomes a **linear** edge (unless an
|
|
771
|
+
* unconditional route already covers it, or the page is a `finish`).
|
|
772
|
+
*
|
|
773
|
+
* Experiments are **not** compiled here. A variant page is recognised structurally
|
|
774
|
+
* by the `@` in its key (`welcome@b`) and tagged `variantOf` + collapsed out of the
|
|
775
|
+
* linear flow; the experiment *wiring* (labels/weights/status) is operational data
|
|
776
|
+
* the platform owns and overlays at render time, not part of the funnel build.
|
|
777
|
+
*
|
|
778
|
+
* Stable ids: the page **key** is the source anchor, so `id === key` here. The
|
|
779
|
+
* durable analytics id is the semantic page name (a slot survives a winner being
|
|
780
|
+
* promoted into it); transient `@variant` pages only ever key analytics by
|
|
781
|
+
* `(experimentId, variant)` in immutable results — a platform concern.
|
|
782
|
+
*/
|
|
783
|
+
|
|
784
|
+
interface ManifestPage {
|
|
785
|
+
id: string;
|
|
786
|
+
key: string;
|
|
787
|
+
type: PageType;
|
|
788
|
+
slug: string;
|
|
789
|
+
index: number;
|
|
790
|
+
/**
|
|
791
|
+
* Set on a variant page (`welcome@b`) to its **slot** (`welcome`) — a structural
|
|
792
|
+
* marker that this node is an off-flow alternate, not a linear step. The
|
|
793
|
+
* experiment *wiring* (label/weight/id) is operational data the platform owns,
|
|
794
|
+
* not the manifest.
|
|
795
|
+
*/
|
|
796
|
+
variantOf?: string;
|
|
797
|
+
/**
|
|
798
|
+
* The page's effective ENTRY guard, serialized (SSR-isolation Option B, FIX 1): a `declarative`
|
|
799
|
+
* {@link Condition} the renderer can evaluate SERVER-SIDE against the visitor's session snapshot
|
|
800
|
+
* to pick the right prerendered variant (target vs bounce) without running tenant code, or an
|
|
801
|
+
* opaque `predicate` marker (author code — the renderer must fall back to live SSR for that
|
|
802
|
+
* deep-link). Absent = no entry guard (always restorable). Mirrors {@link entryGuard}.
|
|
803
|
+
*/
|
|
804
|
+
entryGuard?: EdgeCondition;
|
|
805
|
+
/**
|
|
806
|
+
* BUILD-TIME PRERENDER OPT-OUT (SSR-isolation Option B, FIX 2). True when the page's `meta.dynamic`
|
|
807
|
+
* (or `prerender: false`) opts it out of prerendering because its STRUCTURE depends on
|
|
808
|
+
* sessionValues. The prerender stage skips it; the renderer serves it via live SSR.
|
|
809
|
+
*/
|
|
810
|
+
dynamic?: boolean;
|
|
811
|
+
}
|
|
812
|
+
type EdgeCondition = {
|
|
813
|
+
kind: 'declarative';
|
|
814
|
+
condition: Condition;
|
|
815
|
+
}
|
|
816
|
+
/** A code predicate — opaque body; `label` may be supplied later by AST parsing. */
|
|
817
|
+
| {
|
|
818
|
+
kind: 'predicate';
|
|
819
|
+
label?: string;
|
|
820
|
+
};
|
|
821
|
+
interface ManifestEdge {
|
|
822
|
+
from: string;
|
|
823
|
+
to: string;
|
|
824
|
+
kind: 'branch' | 'linear';
|
|
825
|
+
/** Absent = unconditional (a fallback route, or the linear fall-through). */
|
|
826
|
+
condition?: EdgeCondition;
|
|
827
|
+
/**
|
|
828
|
+
* True on a **variant-only branch**: an edge whose `from` is a `@variant` key,
|
|
829
|
+
* emitted when that served variant carries its OWN `meta.next` (optional divergent
|
|
830
|
+
* routing). Lets consumers (the editor's Flow canvas) tell a variant's private branch
|
|
831
|
+
* apart from a normal slot edge. Optional/absent on every non-variant edge.
|
|
832
|
+
*/
|
|
833
|
+
variant?: true;
|
|
834
|
+
}
|
|
835
|
+
interface ManifestValidation {
|
|
836
|
+
/**
|
|
837
|
+
* `ok` = none of the hard errors: the original set (dead ends, unreachable
|
|
838
|
+
* pages, bad targets, missing email capture) AND the structural errors added
|
|
839
|
+
* later (duplicate keys, orphan variants, no reachable finish). Slug
|
|
840
|
+
* collisions are a **warning** — reported but not folded into `ok` (slugs are
|
|
841
|
+
* display/URL sugar; keys are the routing identity).
|
|
842
|
+
*/
|
|
843
|
+
ok: boolean;
|
|
844
|
+
/** Page ids you can't proceed from (and that aren't a `finish`). */
|
|
845
|
+
deadEnds: string[];
|
|
846
|
+
/** Page ids not reachable from the start. */
|
|
847
|
+
unreachable: string[];
|
|
848
|
+
/** Routes whose target page key doesn't exist. */
|
|
849
|
+
badTargets: {
|
|
850
|
+
from: string;
|
|
851
|
+
to: string;
|
|
852
|
+
}[];
|
|
853
|
+
/** True if the funnel never writes `user.email` (the mandatory identity step). */
|
|
854
|
+
missingEmailCapture: boolean;
|
|
855
|
+
/** Page keys that appear more than once (keys are the stable ids — hard error). */
|
|
856
|
+
duplicateKeys: string[];
|
|
857
|
+
/** Flow pages sharing a slug (URL ambiguity — warning, not folded into `ok`). */
|
|
858
|
+
slugCollisions: {
|
|
859
|
+
slug: string;
|
|
860
|
+
pages: string[];
|
|
861
|
+
}[];
|
|
862
|
+
/** Variant pages (`x@b`) whose slot (`x`) doesn't exist as a flow page (hard error). */
|
|
863
|
+
orphanVariants: string[];
|
|
864
|
+
/**
|
|
865
|
+
* True when no `finish` page is reachable from the start — e.g. the flow loops
|
|
866
|
+
* (a cycle with no exit) or every path stalls before a terminal page. Dead ends
|
|
867
|
+
* catch pages with no outgoing edge; this catches funnels that *never end* even
|
|
868
|
+
* though every page can proceed. Hard error.
|
|
869
|
+
*/
|
|
870
|
+
noReachableFinish: boolean;
|
|
871
|
+
/** Slot names a PAGE references (`useOffering`/`<Checkout offering>`) that the funnel doesn't declare — hard error. */
|
|
872
|
+
unknownOfferingRefs: string[];
|
|
873
|
+
/** Declared slots a page references but which have no catalog charge key assigned (map value `null`) — hard error. */
|
|
874
|
+
unassignedSlots: string[];
|
|
875
|
+
}
|
|
876
|
+
interface FunnelManifest {
|
|
877
|
+
id: string;
|
|
878
|
+
pages: ManifestPage[];
|
|
879
|
+
flow: {
|
|
880
|
+
start: string | null;
|
|
881
|
+
nodes: string[];
|
|
882
|
+
edges: ManifestEdge[];
|
|
883
|
+
};
|
|
884
|
+
/** The unique, ASSIGNED catalog keys the funnel charges (for the promote gate + catalog reverse-lookup). */
|
|
885
|
+
offerings: string[];
|
|
886
|
+
/** Offering SLOTS: slot → assigned catalog key|null. `offerings` above is the unique assigned keys. */
|
|
887
|
+
offeringSlots: OfferingSlot[];
|
|
888
|
+
/** Slot names PAGES reference (from the build's scan); validated against `offeringSlots`. Absent = no scan ran. */
|
|
889
|
+
offeringRefs?: string[];
|
|
890
|
+
/**
|
|
891
|
+
* The funnel's `checkout:` driver bundle from `funnel.ts` (`FunnelDefinition.checkout`), carried so
|
|
892
|
+
* the publish gate can cross-validate it against the offerings' RESOLVED provider (§7 item 5 — the
|
|
893
|
+
* redundant field is never checked today). Absent = the funnel declares no `checkout:`.
|
|
894
|
+
*/
|
|
895
|
+
checkout?: 'stripe' | 'paddle';
|
|
896
|
+
/**
|
|
897
|
+
* Checkout-SURFACE usage the pages express (from `scanOfferingRefs(...).checkout`), carried so the
|
|
898
|
+
* publish (provider × surface) capability gate can run `validateCheckout`/`validateUpsell`. Absent =
|
|
899
|
+
* no scan ran (old manifest) → the gate skips capability validation (back-compat, no false blocks).
|
|
900
|
+
*/
|
|
901
|
+
checkoutRefs?: CheckoutUsageScan;
|
|
902
|
+
locales?: FunnelLocales;
|
|
903
|
+
validation: ManifestValidation;
|
|
904
|
+
}
|
|
905
|
+
interface CompileInput {
|
|
906
|
+
funnel: FunnelDefinition;
|
|
907
|
+
/** Pages in file order (the default flow); `meta` holds type/slug/next. */
|
|
908
|
+
pages: {
|
|
909
|
+
key: string;
|
|
910
|
+
meta?: PageMeta;
|
|
911
|
+
}[];
|
|
912
|
+
/** Slot names the funnel's PAGES reference (from `scanOfferingRefs`) — cross-checked against the declared slots. */
|
|
913
|
+
offeringRefs?: string[];
|
|
914
|
+
/** Checkout-surface usage the pages express (from `scanOfferingRefs(...).checkout`) — carried onto the manifest for the publish capability gate. */
|
|
915
|
+
checkoutRefs?: CheckoutUsageScan;
|
|
916
|
+
}
|
|
917
|
+
/** Compile a funnel's spine into its declarative {@link FunnelManifest} IR. */
|
|
918
|
+
declare function compileManifest(input: CompileInput): FunnelManifest;
|
|
919
|
+
|
|
920
|
+
export { expectedPathLength as $, type Acquisition as A, type BrowserContext as B, type ClickIdContext as C, type Direction as D, type EdgeCondition as E, type FunnelContext as F, type Gate as G, assignVariant as H, type IdentityContext as I, bucketingSeed as J, buildAcquisition as K, type LocaleContext as L, type ManifestEdge as M, buildCatalog as N, type Offering as O, type PageMeta as P, compileManifest as Q, type RuntimeExperiment as R, type SessionContext as S, currencyExponent as T, type UtmContext as U, type VariableValue as V, defineFunnel as W, definePage as X, entryGuard as Y, evaluateCondition as Z, evaluateGate as _, type VariableConfig as a, fnv1a as a0, formatMoney as a1, formatOffering as a2, hashToUnit as a3, isRtl as a4, isVariantKey as a5, nextPage as a6, outgoingKeys as a7, pageMeta as a8, parseSlotKey as a9, pickByWeight as aa, resolveExperiments as ab, resolveLocale as ac, resolveOffering as ad, resolveRoute as ae, type CheckoutUsageScan as af, type FunnelPage as ag, type OfferingRefScan as ah, type OfferingSlot as ai, funnelCatalogKeys as aj, normalizeOfferings as ak, scanOfferingRefs as al, weightsOf as am, type FunnelSnapshot as b, type FunnelDefinition as c, buildContext as d, type OfferingInput as e, type PageContext as f, type BuildContextOptions as g, type CompileInput as h, type Condition as i, type ConditionOp as j, type DeviceContext as k, type ExperimentArm as l, type ExperimentResolution as m, type FlowPage as n, type FunnelLocales as o, type FunnelManifest as p, type Interval as q, type ManifestPage as r, type ManifestValidation as s, type Money as t, type OsContext as u, type PageType as v, type Predicate as w, type ResolvedOffering as x, type Route as y, type SystemContext as z };
|