@appfunnel-dev/sdk 2.0.0-canary.1 → 2.0.0-canary.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/capabilities-7_hy5f5G.d.cts +114 -0
  2. package/dist/capabilities-7_hy5f5G.d.ts +114 -0
  3. package/dist/checkout-7Dy6IedP.d.ts +320 -0
  4. package/dist/checkout-Dz8cGkB_.d.cts +320 -0
  5. package/dist/chunk-AKO6XKXP.js +466 -0
  6. package/dist/chunk-AKO6XKXP.js.map +1 -0
  7. package/dist/chunk-CY4VBSMX.cjs +106 -0
  8. package/dist/chunk-CY4VBSMX.cjs.map +1 -0
  9. package/dist/chunk-JSRKA375.cjs +497 -0
  10. package/dist/chunk-JSRKA375.cjs.map +1 -0
  11. package/dist/chunk-LJYLGLFS.cjs +153 -0
  12. package/dist/chunk-LJYLGLFS.cjs.map +1 -0
  13. package/dist/chunk-M6U3FNRW.js +99 -0
  14. package/dist/chunk-M6U3FNRW.js.map +1 -0
  15. package/dist/chunk-YY375F2B.js +140 -0
  16. package/dist/chunk-YY375F2B.js.map +1 -0
  17. package/dist/driver-paddle.cjs +814 -0
  18. package/dist/driver-paddle.cjs.map +1 -0
  19. package/dist/driver-paddle.d.cts +10 -0
  20. package/dist/driver-paddle.d.ts +10 -0
  21. package/dist/driver-paddle.js +811 -0
  22. package/dist/driver-paddle.js.map +1 -0
  23. package/dist/driver-stripe.cjs +2253 -0
  24. package/dist/driver-stripe.cjs.map +1 -0
  25. package/dist/driver-stripe.d.cts +8 -0
  26. package/dist/driver-stripe.d.ts +8 -0
  27. package/dist/driver-stripe.js +2247 -0
  28. package/dist/driver-stripe.js.map +1 -0
  29. package/dist/index.cjs +1962 -811
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +183 -933
  32. package/dist/index.d.ts +183 -933
  33. package/dist/index.js +1683 -653
  34. package/dist/index.js.map +1 -1
  35. package/dist/manifest-Cr2y1op6.d.cts +814 -0
  36. package/dist/manifest-Cr2y1op6.d.ts +814 -0
  37. package/dist/manifest-entry.cjs +312 -0
  38. package/dist/manifest-entry.cjs.map +1 -0
  39. package/dist/manifest-entry.d.cts +209 -0
  40. package/dist/manifest-entry.d.ts +209 -0
  41. package/dist/manifest-entry.js +198 -0
  42. package/dist/manifest-entry.js.map +1 -0
  43. package/package.json +37 -4
@@ -0,0 +1,814 @@
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 `customerId` once known; before identification it's the
144
+ * signed anonymous `visitorId` (P1). It is deliberately **not** the session id or
145
+ * fingerprint — a returning visitor (e.g. via winback) must keep their variant
146
+ * across sessions/devices (landmine #4). Both null = unidentifiable traffic, and
147
+ * the experiment layer falls back to control rather than bucket on nothing.
148
+ */
149
+ interface IdentityContext {
150
+ /** Known customer id (post-identification). The preferred bucketing seed. */
151
+ customerId: string | null;
152
+ /** Signed anonymous visitor id. The fallback bucketing seed. */
153
+ visitorId: string | null;
154
+ }
155
+ interface SystemContext {
156
+ funnelId: string;
157
+ campaignId: string;
158
+ /** Render mode — `test` for preview/QA, `live` for public traffic. */
159
+ mode: 'test' | 'live';
160
+ /** Epoch ms captured at build time (stable per render, not a live clock). */
161
+ now: number;
162
+ }
163
+ /** The whole read-only computed namespace, as read in predicates: `s.context.*`. */
164
+ interface FunnelContext {
165
+ device: DeviceContext;
166
+ browser: BrowserContext;
167
+ os: OsContext;
168
+ locale: LocaleContext;
169
+ page: PageContext;
170
+ utm: UtmContext;
171
+ /** Per-network ad click-ids captured on entry (funnel-readable; also forwarded for CAPI). */
172
+ clickIds: ClickIdContext;
173
+ session: SessionContext;
174
+ identity: IdentityContext;
175
+ system: SystemContext;
176
+ }
177
+ /**
178
+ * Assemble the full {@link Acquisition} snapshot from the context + `document`
179
+ * (cookies, referrer, path) — captured once on entry, forwarded to the tracker for
180
+ * first-class persistence (session + first-touch Customer) + CAPI.
181
+ */
182
+ declare function buildAcquisition(context: FunnelContext): Acquisition;
183
+ interface BuildContextOptions {
184
+ funnelId?: string;
185
+ campaignId?: string;
186
+ mode?: 'test' | 'live';
187
+ /** Stable build-time clock (avoids `Date.now()` churn in renders/tests). */
188
+ now?: number;
189
+ sessionId?: string | null;
190
+ /** Known customer id — the preferred stable bucketing seed (phase-4 §4.2). */
191
+ customerId?: string | null;
192
+ /** Signed anonymous visitor id — the fallback bucketing seed. */
193
+ visitorId?: string | null;
194
+ /** Overrides for any slice — used by the server to hydrate `utm`/`session`. */
195
+ overrides?: Partial<FunnelContext>;
196
+ }
197
+ /**
198
+ * Build the read-only {@link FunnelContext} once, at mount. `page` starts at the
199
+ * first page and is replaced per navigation when assembling a snapshot.
200
+ */
201
+ declare function buildContext(opts?: BuildContextOptions): FunnelContext;
202
+
203
+ /**
204
+ * Pure catalog math — no React, no I/O. Split out of {@link ./catalog} so the
205
+ * server/tooling entry (`@appfunnel-dev/sdk/manifest`) can compile/resolve
206
+ * products without pulling react-dom or any component code into its graph.
207
+ * {@link ./catalog} re-exports everything here and adds the React wiring.
208
+ */
209
+ type Interval = 'day' | 'week' | 'month' | 'year' | 'one_time';
210
+ /** What the platform hands the funnel per product (a single provider-resolved price). */
211
+ interface ProductInput {
212
+ id: string;
213
+ /** The catalog product KEY this input charges (the slot's assignment). Defaults to `id` (legacy/identity slots). */
214
+ catalogKey?: string;
215
+ name?: string;
216
+ displayName?: string;
217
+ /** Provider-resolved price in **minor units** (the provider chose the currency). */
218
+ amount: number;
219
+ /** Currency of `amount`, as the provider resolved it (e.g. `DKK`). */
220
+ currency: string;
221
+ interval?: Interval;
222
+ intervalCount?: number;
223
+ trialDays?: number;
224
+ /** Trial price in minor units (omit/0 = free trial). */
225
+ trialAmount?: number;
226
+ /** Settlement provider — opaque to the author, used by the checkout driver. */
227
+ provider?: string;
228
+ }
229
+ /** A money value with a locale-formatted string. */
230
+ interface Money {
231
+ /** Major units, e.g. `79`. */
232
+ amount: number;
233
+ /** Minor units, e.g. `7900`. */
234
+ minor: number;
235
+ currency: string;
236
+ /** Locale-formatted, e.g. `kr 79,00` / `€9,99` / `$9.99`. */
237
+ formatted: string;
238
+ }
239
+ /**
240
+ * The product with its amounts resolved (currency + period math), **before**
241
+ * locale formatting — what the catalog stores. `useProduct` formats it.
242
+ */
243
+ interface ResolvedProduct {
244
+ id: string;
245
+ /** The catalog product KEY charged (the CHARGE identity; `id` is the SLOT/display identity). */
246
+ catalogKey: string;
247
+ name: string;
248
+ displayName: string;
249
+ provider: string;
250
+ currency: string;
251
+ priceMinor: number;
252
+ perDayMinor: number;
253
+ perWeekMinor: number;
254
+ perMonthMinor: number;
255
+ perYearMinor: number;
256
+ period: string;
257
+ periodly: string;
258
+ hasTrial: boolean;
259
+ trialDays: number;
260
+ trialMinor: number;
261
+ }
262
+ /** Display-ready product the author reads (every amount locale-formatted). */
263
+ interface Product {
264
+ id: string;
265
+ /** The catalog product KEY charged (the CHARGE identity; `id` is the SLOT/display identity). */
266
+ catalogKey: string;
267
+ name: string;
268
+ displayName: string;
269
+ provider: string;
270
+ price: Money;
271
+ /** e.g. `month`, `quarter`, `one-time`. */
272
+ period: string;
273
+ /** e.g. `monthly`, `quarterly`, `one-time`. */
274
+ periodly: string;
275
+ /** Period-normalized prices (for "just $0.27/day" style copy). */
276
+ perDay: Money;
277
+ perWeek: Money;
278
+ perMonth: Money;
279
+ perYear: Money;
280
+ hasTrial: boolean;
281
+ trialDays: number;
282
+ trialPrice: Money | null;
283
+ }
284
+ /**
285
+ * Resolve a {@link ProductInput} into amounts + period math (no formatting yet).
286
+ * Per-period amounts are **integer minor units** (each derived from the exact
287
+ * daily rate, then rounded — never round-then-multiply, so error doesn't compound).
288
+ */
289
+ declare function resolveProduct(input: ProductInput): ResolvedProduct;
290
+ /** Build the id → {@link ResolvedProduct} catalog. Formatting happens at read time. */
291
+ declare function buildCatalog(inputs: ProductInput[]): Map<string, ResolvedProduct>;
292
+ /**
293
+ * The minor-unit exponent for a currency (`USD`→2, `JPY`→0, `KWD`/`BHD`→3),
294
+ * derived from `Intl.NumberFormat(...).resolvedOptions().maximumFractionDigits`
295
+ * with a fallback of 2 for unknown/invalid codes.
296
+ */
297
+ declare function currencyExponent(currency: string): number;
298
+ /** Format minor units of `currency` in `locale` (exponent-aware: 7900 JPY = ¥7,900). */
299
+ declare function formatMoney(minor: number, currency: string, locale: string): Money;
300
+ /** Format a {@link ResolvedProduct} into a display {@link Product} in `locale`. */
301
+ declare function formatProduct(r: ResolvedProduct, locale: string): Product;
302
+
303
+ /**
304
+ * The funnel **spine** — the constrained, declarative configuration authored as
305
+ * code (`defineFunnel` / `pageMeta` / `definePage`) yet **dashboard-editable**
306
+ * (static AST parse → pretty UI → codegen) and compiled to the manifest IR.
307
+ *
308
+ * Principle: **presentation = code** (the page components), **configuration =
309
+ * data** (this spine). See docs/platform-v2/06-funnel-project-model.md.
310
+ *
311
+ * Routing is **declarative nodes + code predicates** (decided — doc 06): a
312
+ * page's `next` is an ordered list of {@link Route}s, each with a **static `to`
313
+ * page key** (so the dashboard can draw every possible edge without executing
314
+ * anything) and an optional `when` **gate** that returns true/false. The gate is
315
+ * either a declarative {@link Condition} (one field — UI-editable data) or a code
316
+ * {@link Predicate} (`s => boolean` — the escape hatch, opaque body but the edge
317
+ * is still visible). First matching route wins; a route with no `when` is the
318
+ * fallback. Multiple conditions = multiple routes (or boolean logic in one
319
+ * predicate). Omit `next` entirely for the default linear flow.
320
+ */
321
+ /**
322
+ * Read-only view of every namespace a routing/condition predicate can branch
323
+ * on. `user`/`responses`/`data` are the writable namespaces; `context` is the
324
+ * read-only computed one ({@link FunnelContext}).
325
+ */
326
+ interface FunnelSnapshot {
327
+ user: Record<string, VariableValue>;
328
+ responses: Record<string, VariableValue>;
329
+ data: Record<string, VariableValue>;
330
+ context: FunnelContext;
331
+ }
332
+ /** A code-predicate gate — `s => s.responses.goal === 'gain'`. */
333
+ type Predicate = (s: FunnelSnapshot) => boolean;
334
+ type ConditionOp = 'eq' | 'neq' | 'in' | 'gt' | 'gte' | 'lt' | 'lte' | 'exists' | 'empty' | 'contains';
335
+ /**
336
+ * A declarative gate over **one** namespaced field — UI-editable data the
337
+ * dashboard renders as a condition row (`field` `op` `value`). `field` is a
338
+ * dotted path into the snapshot: `responses.goal`, `user.country`,
339
+ * `context.device.isMobile`.
340
+ */
341
+ interface Condition {
342
+ field: string;
343
+ op: ConditionOp;
344
+ value?: VariableValue | VariableValue[];
345
+ }
346
+ /** An edge gate: either declarative data ({@link Condition}) or a {@link Predicate}. */
347
+ type Gate = Condition | Predicate;
348
+ /**
349
+ * One routing edge out of a page. `to` is a **static** target key (the dashboard
350
+ * reads these to draw the flow graph); `when` gates the edge (omit = fallback).
351
+ */
352
+ interface Route {
353
+ to: string;
354
+ when?: Gate;
355
+ }
356
+ /** Evaluate a declarative {@link Condition} against a snapshot. */
357
+ declare function evaluateCondition(cond: Condition, s: FunnelSnapshot): boolean;
358
+ /** Evaluate either gate kind to a boolean. */
359
+ declare function evaluateGate(gate: Gate, s: FunnelSnapshot): boolean;
360
+ /**
361
+ * Resolve an ordered list of routes to a target page key, or `undefined` to fall
362
+ * through to the linear next. First route whose gate passes (or has no `when`)
363
+ * wins.
364
+ */
365
+ declare function resolveRoute(routes: Route[] | undefined, s: FunnelSnapshot): string | undefined;
366
+ type PageType = 'default' | 'email-capture' | 'paywall' | 'upsell' | 'finish';
367
+ interface PageMeta {
368
+ /** Page kind — drives behavior + analytics (e.g. `paywall`, `upsell`). */
369
+ type?: PageType;
370
+ /** URL slug; defaults to the page key. */
371
+ slug?: string;
372
+ /**
373
+ * Ordered routing edges out of this page (first match wins). Each has a static
374
+ * `to` key + an optional `when` gate. Omit for the default linear flow.
375
+ */
376
+ next?: Route[];
377
+ /**
378
+ * Entry precondition for **deep-link / reload** restoration. When the runtime is
379
+ * asked to start *on this page* (not via in-funnel navigation), it restores there
380
+ * only if `guard` passes against the restored snapshot — otherwise it falls back
381
+ * to the start page. e.g. an upsell page: `guard: s => s.data.purchased === true`.
382
+ * Reaching the page via `next()` is unaffected (routing already gated it). Omit =
383
+ * always restorable. Same gate kind as routing (`Condition` or predicate).
384
+ */
385
+ guard?: Gate;
386
+ }
387
+ /**
388
+ * Identity helper for a page's co-located metadata.
389
+ * `export const meta = pageMeta({ type: 'paywall', next: s => … })`.
390
+ */
391
+ declare function pageMeta(meta: PageMeta): PageMeta;
392
+ /**
393
+ * The effective entry guard for a page: an explicit `meta.guard` if the author set
394
+ * one, **otherwise** the page-type default (e.g. paywall/upsell need email). The
395
+ * explicit guard fully **overrides** the default — it's not combined. Returns
396
+ * `undefined` when neither applies.
397
+ */
398
+ declare function entryGuard(meta?: PageMeta): Gate | undefined;
399
+ /**
400
+ * Identity helper for a page component. The page is plain React that reaches the
401
+ * runtime through hooks (`useResponse`, `useNavigation`, …) — there is no `sdk`
402
+ * prop. `export default definePage(function Welcome() { … })`.
403
+ */
404
+ declare function definePage<P extends object = Record<string, never>>(component: ComponentType<P>): ComponentType<P>;
405
+ /** A page in the flow: its key + (optional) co-located meta. */
406
+ interface FlowPage {
407
+ key: string;
408
+ meta?: PageMeta;
409
+ }
410
+ /**
411
+ * A page as declared in `funnel.ts` — the key + its metadata, flattened. This is the
412
+ * AUTHORED shape (funnel.ts owns the page list, order, and routing); the build generates
413
+ * the code-split `mount.tsx` from it. Routing (`next`) must stay DECLARATIVE (Route[] with
414
+ * `{ to, when }` conditions, no predicate functions) so the web builder UI can edit it.
415
+ */
416
+ interface FunnelPage extends PageMeta {
417
+ key: string;
418
+ }
419
+ /**
420
+ * Decide the next page from `currentKey`:
421
+ * 1. the current page's `next` routes ({@link resolveRoute}), if one matches, else
422
+ * 2. the next page in file order (the default linear flow), else
423
+ * 3. `undefined` (end of funnel / current key not found).
424
+ */
425
+ declare function nextPage(pages: FlowPage[], currentKey: string, s: FunnelSnapshot): string | undefined;
426
+ /**
427
+ * Every page a visitor *could* go to next from `currentKey` — all route targets
428
+ * (regardless of gate, since we don't know which will pass) plus the linear next.
429
+ * Used to **prefetch** the likely-next page chunks; not for navigation.
430
+ */
431
+ declare function outgoingKeys(pages: FlowPage[], currentKey: string): string[];
432
+ /**
433
+ * The number of pages on the path from `startKey` to a `finish` (or the end of
434
+ * the flow) **given the current state** — the denominator for progress. It walks
435
+ * the actual routing ({@link nextPage}) rather than counting all files, so a
436
+ * branched funnel reaches 100% on whichever path the visitor's answers select.
437
+ * Re-traced per navigation; a visited set guards against routing cycles.
438
+ */
439
+ declare function expectedPathLength(pages: FlowPage[], startKey: string, s: FunnelSnapshot): number;
440
+ interface FunnelLocales {
441
+ default: string;
442
+ supported: string[];
443
+ fallback?: string;
444
+ }
445
+ /**
446
+ * The funnel-level spine. Flow is mostly inferred from page file order + each
447
+ * page's `next`; this holds the funnel-wide config. Stays **thin** — routing
448
+ * lives co-located on pages (doc 06: "funnel.ts stays thin").
449
+ */
450
+ interface FunnelDefinition {
451
+ id: string;
452
+ /**
453
+ * The funnel's pages — order, type, and declarative routing — the source of truth the
454
+ * web builder edits and the build generates `mount.tsx` from. Each `key` maps to a
455
+ * `pages/<key>.tsx` component. Omit `pages` on hand-written funnels that still ship their
456
+ * own `mount.tsx` (back-compat); new/generated funnels declare them here.
457
+ */
458
+ pages?: FunnelPage[];
459
+ /** Which checkout provider the paywall/checkout uses. The build wires the driver. */
460
+ checkout?: 'stripe' | 'paddle';
461
+ /** `responses.*` runtime variables (default values). */
462
+ responses?: Record<string, VariableConfig>;
463
+ /** `data.*` working/scratch variables (default values). */
464
+ data?: Record<string, VariableConfig>;
465
+ /**
466
+ * The catalog products this funnel sells, as SLOTS: a local, stable key each PAGE
467
+ * references (`useProduct('primary')`, `<Checkout product="primary">`) → the catalog product
468
+ * KEY it's assigned to. Swap the assignment to change the offer WITHOUT touching page code;
469
+ * `null` = a declared-but-unassigned slot. A bare `string[]` is legacy sugar for IDENTITY
470
+ * slots (`['pro'] ≡ { pro: 'pro' }`) — every existing funnel keeps working. Prices resolve
471
+ * from the project catalog per environment (Live/Test) at render.
472
+ */
473
+ products?: string[] | Record<string, string | null>;
474
+ locales?: FunnelLocales;
475
+ /**
476
+ * When `true`, the funnel shows the **geo-specific** currency/price the payment
477
+ * provider resolves (Stripe `currency_options`, Paddle preview, Whop, SolidGate,
478
+ * …). When `false` (default), a single fixed currency is used. AppFunnel does no
479
+ * FX — this only toggles whether the platform asks the provider for the geo
480
+ * price; the SDK just displays whatever resolved `{amount, currency}` it's handed.
481
+ * (See docs/platform-v2 phase-3 §3.6.)
482
+ */
483
+ locationAwareCurrency?: boolean;
484
+ }
485
+ /** Identity helper for a funnel definition. */
486
+ declare function defineFunnel(def: FunnelDefinition): FunnelDefinition;
487
+ /** A funnel product SLOT: the local key pages reference → the assigned catalog product key (null = unassigned). */
488
+ interface ProductSlot {
489
+ slot: string;
490
+ catalogKey: string | null;
491
+ }
492
+ /**
493
+ * Normalize `FunnelDefinition.products` to a slot list. A legacy `string[]` becomes IDENTITY
494
+ * slots (`['pro'] → [{ slot:'pro', catalogKey:'pro' }]`); a `{ slot: key|null }` map becomes its
495
+ * entries (insertion order preserved, so `useProducts()` is deterministic).
496
+ */
497
+ declare function normalizeProducts(products: FunnelDefinition['products']): ProductSlot[];
498
+ /** The unique, ASSIGNED catalog keys a funnel charges — for the promote gate + catalog reverse-lookup. */
499
+ declare function funnelCatalogKeys(products: FunnelDefinition['products']): string[];
500
+
501
+ /**
502
+ * Pure locale resolution — no React. Split out of {@link ./translation} so the
503
+ * server/tooling entry (`@appfunnel-dev/sdk/manifest`) can resolve a visitor's
504
+ * locale without pulling component code. {@link ./translation} re-exports it.
505
+ */
506
+
507
+ type Direction = 'ltr' | 'rtl';
508
+ /** Whether a locale is right-to-left (by language subtag). */
509
+ declare function isRtl(locale: string): boolean;
510
+ /**
511
+ * Resolve the active locale: `override` (URL/param) → `detected` (device) →
512
+ * funnel default, each only if supported (matched by exact tag or language
513
+ * subtag). Mirrors doc 05's resolution chain (the geo/header steps happen
514
+ * server-side and arrive via `override`/`detected`).
515
+ */
516
+ declare function resolveLocale(config: FunnelLocales | undefined, detected: string, override?: string): string;
517
+
518
+ /**
519
+ * **Runtime page-level experiments** — A/B/n on a *single page inside one funnel*,
520
+ * resolved at render time (phase-4). No funnel duplication: a slot (e.g. the page
521
+ * `welcome`) has alternate versions filed as siblings (`welcome@b.tsx`), and the
522
+ * runtime shows **one** of them per visitor, collapsing the losers out of the
523
+ * linear flow. The flow keeps stable **slot keys** (the control's key); only the
524
+ * rendered component swaps — so routing, the manifest, and analytics all key on the
525
+ * slot, not the variant.
526
+ *
527
+ * **Where the wiring lives:** the *variant pages* are code (compiled into the
528
+ * bundle). The *experiment wiring* — slot, variant→page map, weights, status — is
529
+ * **operational data the platform owns** (a DB record, edited by the dashboard,
530
+ * changed without recompiling the funnel). The SDK is storage-agnostic: the
531
+ * platform hands the runtime experiment records to `FunnelProvider`, the same way
532
+ * it hands in resolved product prices. This module just resolves them.
533
+ *
534
+ * **The only source-side marker** is the `@` in a variant file's key
535
+ * (`welcome@b`): it tells the *build* (manifest, flow graph) that a page is an
536
+ * off-flow variant of its slot, so the structure is correct without the DB. The
537
+ * label/weight/experiment-id are not in source.
538
+ *
539
+ * Bucketing is a deterministic FNV-1a hash, **namespaced by experiment id** so
540
+ * independent experiments bucket orthogonally (the basis for layering 100+ tests,
541
+ * §4.3). The seed is the durable identity ({@link bucketingSeed}) — never the
542
+ * session/fingerprint — so a returning visitor keeps their variant (landmine #4).
543
+ * Stability across an *add-a-variant* edit is the platform's job: an experiment's
544
+ * variant set is immutable while running (reweighting / adding an arm = a new
545
+ * experiment version), so within one record the assignment never moves.
546
+ *
547
+ * This module is pure (no React, no I/O) → it unit-tests trivially and the
548
+ * dashboard/server can reuse the same assignment math.
549
+ */
550
+
551
+ /**
552
+ * FNV-1a 32-bit hash → unsigned int. Deterministic and isomorphic (no `crypto`,
553
+ * runs the same in the browser, a worker, and a build). The same math v0 used,
554
+ * kept because it's sound — only the *seed* changes (identity, not session).
555
+ */
556
+ declare function fnv1a(input: string): number;
557
+ /** Map a seed string to a stable float in `[0, 1)`. */
558
+ declare function hashToUnit(seed: string): number;
559
+ /**
560
+ * Pick a variant key by weight from a stable unit position `u ∈ [0,1)`. Variants
561
+ * are walked in declaration order and the first whose cumulative weight band
562
+ * contains `u` wins, so the same `u` always lands in the same variant.
563
+ */
564
+ declare function pickByWeight(weights: Record<string, number>, u: number): string;
565
+ /**
566
+ * Deterministically assign a visitor (`seed`) to a variant of one experiment.
567
+ * The hash is **namespaced by `experimentId`** so two experiments on the same
568
+ * traffic don't correlate (orthogonal layering).
569
+ */
570
+ declare function assignVariant(experimentId: string, seed: string, weights: Record<string, number>): string;
571
+ /**
572
+ * The stable bucketing seed: the signed `visitorId`, else the known `customerId`.
573
+ * Never the session id or fingerprint (landmine #4). `null` when neither is known
574
+ * — the caller then serves control instead of bucketing on nothing.
575
+ *
576
+ * visitorId-FIRST (not customerId-first) is deliberate: the customerId injected for an
577
+ * anonymous visitor is minted server-side AFTER the first tracked event, so it is absent on
578
+ * visit 1 and present on visit 2 — seeding on it would flip a returning visitor's arm and
579
+ * count them in two arms of the same version. The signed `af_vid` cookie is the durable
580
+ * identity that's stable from the first pageload, so it seeds; customerId is only the fallback
581
+ * for cookieless SDK embeds. This matches the server-side FUNNEL split, which already seeds on
582
+ * the verified visitorId (resolve.ts). (Cross-device stable bucketing for IDENTIFIED customers
583
+ * is P3's IdentitySDK job, not this anonymous path.)
584
+ */
585
+ declare function bucketingSeed(context: FunnelContext): string | null;
586
+ /** Split a page key into its slot + optional variant: `welcome@b` → `{ slot, variant: 'b' }`. */
587
+ declare function parseSlotKey(key: string): {
588
+ slot: string;
589
+ variant?: string;
590
+ };
591
+ /** True if a page key is an off-flow variant (`welcome@b`), by the source-side `@` marker. */
592
+ declare function isVariantKey(key: string): boolean;
593
+ /** One arm of an experiment: which page renders, at what weight. */
594
+ interface ExperimentVariant {
595
+ /** The page key this arm renders (the slot's control, or a `@variant` sibling). */
596
+ page: string;
597
+ /** Relative weight in the split (need not sum to 100; zero = paused arm). */
598
+ weight: number;
599
+ }
600
+ /**
601
+ * A runtime experiment record — the operational wiring the **platform** owns and
602
+ * hands to the SDK (not authored in the funnel source). The variant *pages* are
603
+ * code in the bundle; this is the live config over them.
604
+ */
605
+ interface RuntimeExperiment {
606
+ id: string;
607
+ /** The page key holding the flow position (the anchor / control). */
608
+ slot: string;
609
+ /** label → arm. One arm's `page` is the `slot` (control); others are `@variant` siblings. */
610
+ variants: Record<string, ExperimentVariant>;
611
+ /** Lifecycle. Absent = running. */
612
+ status?: 'running' | 'paused' | 'stopped';
613
+ /** When stopped, the variant label everyone sees until promotion bakes it into the slot. */
614
+ winner?: string;
615
+ /** Primary metric (analytics only; not used for resolution). */
616
+ metric?: string;
617
+ /** Platform record version (immutable-while-running; reweight = new version). Rides on
618
+ * exposure events so results key on (experimentId, version, variant). */
619
+ version?: number;
620
+ }
621
+ interface ExperimentResolution {
622
+ /** experiment id → assigned variant label. */
623
+ assignments: Record<string, string>;
624
+ /** Page keys forming the effective linear flow (variant siblings removed), in order. */
625
+ activeKeys: string[];
626
+ /** Slot key → the page key whose component should render there. */
627
+ render: Record<string, string>;
628
+ /** Variant page key → its slot key. For remapping a route that targets a variant. */
629
+ slotOf: Record<string, string>;
630
+ /** Slot key → the experiment id it hosts (drives the exposure event). */
631
+ experimentOf: Record<string, string>;
632
+ /** Experiment id → platform record version (rides on exposure events). */
633
+ versionOf: Record<string, number>;
634
+ }
635
+ /**
636
+ * Weights map (label → weight) for one experiment's arms. Exported (via the pure
637
+ * manifest entry) so the server-side FUNNEL split (renderer resolve) projects arms
638
+ * the same way before calling {@link assignVariant}, instead of re-inlining it.
639
+ */
640
+ declare function weightsOf(variants: Record<string, {
641
+ weight: number;
642
+ }>): Record<string, number>;
643
+ /**
644
+ * Resolve which page version each experiment slot shows for this visitor, and
645
+ * which page keys remain in the linear flow.
646
+ *
647
+ * Variant pages are detected structurally by the `@` in their key, so they
648
+ * collapse out of the linear flow even for a slot with no active experiment.
649
+ * For each *running* experiment the visitor is bucketed (stable on `seed`); a
650
+ * *stopped* one serves its `winner`; a *paused* one (or no seed) serves the slot.
651
+ */
652
+ declare function resolveExperiments(pages: {
653
+ key: string;
654
+ }[], experiments: RuntimeExperiment[], seed: string | null): ExperimentResolution;
655
+ /** One referential problem with an experiment record. */
656
+ interface ExperimentIssue {
657
+ /** The offending experiment id (`'*'` for a cross-experiment issue). */
658
+ experimentId: string;
659
+ code: 'slot_missing' | 'slot_is_variant' | 'slot_conflict' | 'duplicate_id' | 'variant_page_missing' | 'variant_slot_mismatch' | 'no_control' | 'no_traffic' | 'negative_weight' | 'bad_winner' | 'single_arm' | 'orphan_variant';
660
+ message: string;
661
+ }
662
+ interface ExperimentValidation {
663
+ ok: boolean;
664
+ errors: ExperimentIssue[];
665
+ warnings: ExperimentIssue[];
666
+ }
667
+ /**
668
+ * Cross-check experiment records against the funnel's pages — the publish-time /
669
+ * experiment-edit gate that catches the dangling references the runtime can't see
670
+ * (the experiment wiring lives in the DB; the pages live in the build, so they can
671
+ * drift). Pure: hand it the runtime experiments + the funnel's page keys (e.g.
672
+ * `manifest.pages`).
673
+ *
674
+ * Errors block; warnings inform. `orphan_variant` is a warning, not an error — a
675
+ * `@variant` file with no running experiment is dead-but-harmless (a paused test, or
676
+ * one not wired yet).
677
+ */
678
+ declare function validateExperiments(experiments: RuntimeExperiment[], pages: {
679
+ key: string;
680
+ }[]): ExperimentValidation;
681
+
682
+ /**
683
+ * The **manifest** — the declarative IR a funnel project compiles to (doc 06).
684
+ * It's the machine-readable artifact the platform operates on without executing
685
+ * the funnel: the dashboard draws the flow graph from it, analytics binds to its
686
+ * **stable ids**, validation runs against it, and the renderer reads it to resolve
687
+ * routing.
688
+ *
689
+ * `compileManifest` evaluates the spine (the funnel config + each page's co-located
690
+ * `meta`) into that IR. It's pure — no I/O — so it unit-tests trivially. **It runs
691
+ * server-side**, as the IR step of the publish build over the canonical files in our
692
+ * storage (R2). The client/CLI never produces the authoritative manifest — R2 is the
693
+ * source of truth, the server compiles. (A local dev preview may run it for itself,
694
+ * but that output is never published.)
695
+ *
696
+ * Edge model mirrors the runtime ({@link ../flow/spine}.`nextPage`): a page's
697
+ * `meta.next` routes become **branch** edges (with a serialized condition — a
698
+ * declarative {@link Condition}, or an opaque marker for a code predicate), and the
699
+ * implicit file-order fall-through becomes a **linear** edge (unless an
700
+ * unconditional route already covers it, or the page is a `finish`).
701
+ *
702
+ * Experiments are **not** compiled here. A variant page is recognised structurally
703
+ * by the `@` in its key (`welcome@b`) and tagged `variantOf` + collapsed out of the
704
+ * linear flow; the experiment *wiring* (labels/weights/status) is operational data
705
+ * the platform owns and overlays at render time, not part of the funnel build.
706
+ *
707
+ * Stable ids: the page **key** is the source anchor, so `id === key` here. The
708
+ * durable analytics id is the semantic page name (a slot survives a winner being
709
+ * promoted into it); transient `@variant` pages only ever key analytics by
710
+ * `(experimentId, variant)` in immutable results — a platform concern.
711
+ */
712
+
713
+ interface ManifestPage {
714
+ id: string;
715
+ key: string;
716
+ type: PageType;
717
+ slug: string;
718
+ index: number;
719
+ /**
720
+ * Set on a variant page (`welcome@b`) to its **slot** (`welcome`) — a structural
721
+ * marker that this node is an off-flow alternate, not a linear step. The
722
+ * experiment *wiring* (label/weight/id) is operational data the platform owns,
723
+ * not the manifest.
724
+ */
725
+ variantOf?: string;
726
+ }
727
+ type EdgeCondition = {
728
+ kind: 'declarative';
729
+ condition: Condition;
730
+ }
731
+ /** A code predicate — opaque body; `label` may be supplied later by AST parsing. */
732
+ | {
733
+ kind: 'predicate';
734
+ label?: string;
735
+ };
736
+ interface ManifestEdge {
737
+ from: string;
738
+ to: string;
739
+ kind: 'branch' | 'linear';
740
+ /** Absent = unconditional (a fallback route, or the linear fall-through). */
741
+ condition?: EdgeCondition;
742
+ }
743
+ interface ManifestValidation {
744
+ /**
745
+ * `ok` = none of the hard errors: the original set (dead ends, unreachable
746
+ * pages, bad targets, missing email capture) AND the structural errors added
747
+ * later (duplicate keys, orphan variants, no reachable finish). Slug
748
+ * collisions are a **warning** — reported but not folded into `ok` (slugs are
749
+ * display/URL sugar; keys are the routing identity).
750
+ */
751
+ ok: boolean;
752
+ /** Page ids you can't proceed from (and that aren't a `finish`). */
753
+ deadEnds: string[];
754
+ /** Page ids not reachable from the start. */
755
+ unreachable: string[];
756
+ /** Routes whose target page key doesn't exist. */
757
+ badTargets: {
758
+ from: string;
759
+ to: string;
760
+ }[];
761
+ /** True if the funnel never writes `user.email` (the mandatory identity step). */
762
+ missingEmailCapture: boolean;
763
+ /** Page keys that appear more than once (keys are the stable ids — hard error). */
764
+ duplicateKeys: string[];
765
+ /** Flow pages sharing a slug (URL ambiguity — warning, not folded into `ok`). */
766
+ slugCollisions: {
767
+ slug: string;
768
+ pages: string[];
769
+ }[];
770
+ /** Variant pages (`x@b`) whose slot (`x`) doesn't exist as a flow page (hard error). */
771
+ orphanVariants: string[];
772
+ /**
773
+ * True when no `finish` page is reachable from the start — e.g. the flow loops
774
+ * (a cycle with no exit) or every path stalls before a terminal page. Dead ends
775
+ * catch pages with no outgoing edge; this catches funnels that *never end* even
776
+ * though every page can proceed. Hard error.
777
+ */
778
+ noReachableFinish: boolean;
779
+ /** Slot names a PAGE references (`useProduct`/`<Checkout product>`) that the funnel doesn't declare — hard error. */
780
+ unknownProductRefs: string[];
781
+ /** Declared slots a page references but which have no catalog product assigned (map value `null`) — hard error. */
782
+ unassignedSlots: string[];
783
+ }
784
+ interface FunnelManifest {
785
+ id: string;
786
+ pages: ManifestPage[];
787
+ flow: {
788
+ start: string | null;
789
+ nodes: string[];
790
+ edges: ManifestEdge[];
791
+ };
792
+ /** The unique, ASSIGNED catalog keys the funnel charges (for the promote gate + catalog reverse-lookup). */
793
+ products: string[];
794
+ /** Product SLOTS: slot → assigned catalog key|null. `products` above is the unique assigned keys. */
795
+ productSlots: ProductSlot[];
796
+ /** Slot names PAGES reference (from the build's scan); validated against `productSlots`. Absent = no scan ran. */
797
+ productRefs?: string[];
798
+ locales?: FunnelLocales;
799
+ validation: ManifestValidation;
800
+ }
801
+ interface CompileInput {
802
+ funnel: FunnelDefinition;
803
+ /** Pages in file order (the default flow); `meta` holds type/slug/next. */
804
+ pages: {
805
+ key: string;
806
+ meta?: PageMeta;
807
+ }[];
808
+ /** Slot names the funnel's PAGES reference (from `scanProductRefs`) — cross-checked against the declared slots. */
809
+ productRefs?: string[];
810
+ }
811
+ /** Compile a funnel's spine into its declarative {@link FunnelManifest} IR. */
812
+ declare function compileManifest(input: CompileInput): FunnelManifest;
813
+
814
+ export { evaluateCondition 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, type Route as H, type IdentityContext as I, type SystemContext as J, assignVariant as K, type LocaleContext as L, type ManifestEdge as M, bucketingSeed as N, type OsContext as O, type Product as P, buildAcquisition as Q, type RuntimeExperiment as R, type SessionContext as S, buildCatalog as T, type UtmContext as U, type VariableValue as V, compileManifest as W, currencyExponent as X, defineFunnel as Y, definePage as Z, entryGuard as _, type VariableConfig as a, evaluateGate as a0, expectedPathLength as a1, fnv1a as a2, formatMoney as a3, formatProduct as a4, hashToUnit as a5, isRtl as a6, isVariantKey as a7, nextPage as a8, outgoingKeys as a9, pageMeta as aa, parseSlotKey as ab, pickByWeight as ac, resolveExperiments as ad, resolveLocale as ae, resolveProduct as af, resolveRoute as ag, validateExperiments as ah, type FunnelPage as ai, type ProductSlot as aj, funnelCatalogKeys as ak, normalizeProducts as al, weightsOf as am, type FunnelSnapshot as b, type FunnelDefinition as c, buildContext as d, type ProductInput as e, type PageMeta as f, type PageContext as g, type BuildContextOptions as h, type CompileInput as i, type Condition as j, type ConditionOp as k, type DeviceContext as l, type ExperimentIssue as m, type ExperimentResolution as n, type ExperimentValidation as o, type ExperimentVariant as p, type FlowPage as q, type FunnelLocales as r, type FunnelManifest as s, type Interval as t, type ManifestPage as u, type ManifestValidation as v, type Money as w, type PageType as x, type Predicate as y, type ResolvedProduct as z };