@appfunnel-dev/sdk 2.0.0-canary.4 → 2.0.0-canary.7

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 (60) hide show
  1. package/README.md +1 -1
  2. package/dist/{checkout-Dz8cGkB_.d.cts → checkout-CMEdxpgo.d.cts} +13 -13
  3. package/dist/{checkout-7Dy6IedP.d.ts → checkout-D1NUPv4p.d.ts} +13 -13
  4. package/dist/{chunk-AKO6XKXP.js → chunk-7YQLPPPG.js} +66 -91
  5. package/dist/chunk-7YQLPPPG.js.map +1 -0
  6. package/dist/{chunk-JSRKA375.cjs → chunk-BPOAWI4G.cjs} +68 -94
  7. package/dist/chunk-BPOAWI4G.cjs.map +1 -0
  8. package/dist/{chunk-M6U3FNRW.js → chunk-CFFMZYPE.js} +3 -3
  9. package/dist/{chunk-M6U3FNRW.js.map → chunk-CFFMZYPE.js.map} +1 -1
  10. package/dist/chunk-EMMSS5I5.cjs +37 -0
  11. package/dist/chunk-EMMSS5I5.cjs.map +1 -0
  12. package/dist/chunk-G3PMV62Z.js +33 -0
  13. package/dist/chunk-G3PMV62Z.js.map +1 -0
  14. package/dist/{chunk-LJYLGLFS.cjs → chunk-QMAZGLGV.cjs} +2 -35
  15. package/dist/chunk-QMAZGLGV.cjs.map +1 -0
  16. package/dist/{chunk-YY375F2B.js → chunk-TNLRQPVY.js} +3 -33
  17. package/dist/chunk-TNLRQPVY.js.map +1 -0
  18. package/dist/{chunk-CY4VBSMX.cjs → chunk-VAOR77NW.cjs} +7 -7
  19. package/dist/{chunk-CY4VBSMX.cjs.map → chunk-VAOR77NW.cjs.map} +1 -1
  20. package/dist/chunk-WYUDL4FI.cjs +8 -0
  21. package/dist/chunk-WYUDL4FI.cjs.map +1 -0
  22. package/dist/chunk-ZZJG4EYL.js +6 -0
  23. package/dist/chunk-ZZJG4EYL.js.map +1 -0
  24. package/dist/driver-paddle.cjs +23 -22
  25. package/dist/driver-paddle.cjs.map +1 -1
  26. package/dist/driver-paddle.d.cts +1 -1
  27. package/dist/driver-paddle.d.ts +1 -1
  28. package/dist/driver-paddle.js +3 -2
  29. package/dist/driver-paddle.js.map +1 -1
  30. package/dist/driver-stripe.cjs +277 -224
  31. package/dist/driver-stripe.cjs.map +1 -1
  32. package/dist/driver-stripe.d.cts +18 -2
  33. package/dist/driver-stripe.d.ts +18 -2
  34. package/dist/driver-stripe.js +244 -192
  35. package/dist/driver-stripe.js.map +1 -1
  36. package/dist/index.cjs +750 -150
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.d.cts +151 -90
  39. package/dist/index.d.ts +151 -90
  40. package/dist/index.js +702 -98
  41. package/dist/index.js.map +1 -1
  42. package/dist/{manifest-Cr2y1op6.d.cts → manifest-CMe8yVkr.d.cts} +131 -88
  43. package/dist/{manifest-Cr2y1op6.d.ts → manifest-CMe8yVkr.d.ts} +131 -88
  44. package/dist/manifest-entry.cjs +62 -47
  45. package/dist/manifest-entry.cjs.map +1 -1
  46. package/dist/manifest-entry.d.cts +15 -15
  47. package/dist/manifest-entry.d.ts +15 -15
  48. package/dist/manifest-entry.js +25 -14
  49. package/dist/manifest-entry.js.map +1 -1
  50. package/dist/protocol.cjs +13 -0
  51. package/dist/protocol.cjs.map +1 -0
  52. package/dist/protocol.d.cts +182 -0
  53. package/dist/protocol.d.ts +182 -0
  54. package/dist/protocol.js +4 -0
  55. package/dist/protocol.js.map +1 -0
  56. package/package.json +14 -2
  57. package/dist/chunk-AKO6XKXP.js.map +0 -1
  58. package/dist/chunk-JSRKA375.cjs.map +0 -1
  59. package/dist/chunk-LJYLGLFS.cjs.map +0 -1
  60. package/dist/chunk-YY375F2B.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/manifest/product-refs.ts","../src/flow/scaffold.ts"],"names":[],"mappings":";;;;AAsBA,SAAS,KAAK,GAAA,EAAqB;AACjC,EAAA,MAAM,GAAA,GAAM,GAAA,CAAI,KAAA,CAAM,EAAE,CAAA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AA,CAAA;AAE9D","file":"manifest-entry.js","sourcesContent":["/**\n * Pure, React-free page scan: find which product SLOTS a funnel's pages reference — the first\n * string-literal arg of `useProduct(...)` and the `product` prop of `<Checkout>` / `<Upsell>`.\n * Ships via `@appfunnel-dev/sdk/manifest` so the BUILD, the EDITOR, and the AI all run the SAME\n * check. The result feeds `compileManifest({ productRefs })`, which flags references to slots the\n * funnel doesn't declare (unknown) or hasn't assigned a catalog product to (unassigned).\n *\n * Non-literal args (`useProduct(selectedId)`, `product={expr}`) and the `useProducts()` wildcard are\n * DYNAMIC — they can't be statically enumerated, so they're reported via `dynamic` and never turned\n * into a hard error (validation relaxes when a funnel is dynamic). Mirrors the mask-then-read\n * discipline the funnel.ts code-mods use, so a `useProduct('x')` inside a comment or string literal\n * can't false-positive.\n */\n\nexport interface ProductRefScan {\n /** Concrete slot names referenced by LITERAL args, deduped, in first-seen order. */\n slots: string[]\n /** True if any ref is a non-literal arg or a `useProducts()` wildcard (not statically enumerable). */\n dynamic: boolean\n}\n\n/** Blank comment + string/template CONTENTS (keep quote delimiters + length) so scans don't fire inside them. */\nfunction mask(src: string): string {\n const out = src.split('')\n const n = src.length\n let i = 0\n while (i < n) {\n const c = src[i]\n const d = src[i + 1]\n if (c === '/' && d === '/') {\n while (i < n && src[i] !== '\\n') { out[i] = ' '; i++ }\n } else if (c === '/' && d === '*') {\n out[i] = ' '; out[i + 1] = ' '; i += 2\n while (i < n) {\n if (src[i] === '*' && src[i + 1] === '/') { out[i] = ' '; out[i + 1] = ' '; i += 2; break }\n if (src[i] !== '\\n') out[i] = ' '\n i++\n }\n } else if (c === \"'\" || c === '\"' || c === '`') {\n i++\n while (i < n && src[i] !== c) {\n if (src[i] === '\\\\') { out[i] = ' '; i++; if (i < n && src[i] !== '\\n') out[i] = ' '; i++; continue }\n if (src[i] !== '\\n') out[i] = ' '\n i++\n }\n i++ // closing delimiter (kept)\n } else i++\n }\n return out.join('')\n}\n\n/** A quoted string literal starting at `open` (a quote char in the MASK). Value read from the ORIGINAL. */\nfunction literalAt(src: string, masked: string, open: number): string | null {\n const q = masked[open]\n if (q !== \"'\" && q !== '\"' && q !== '`') return null\n const close = masked.indexOf(q, open + 1)\n if (close === -1) return null\n return src.slice(open + 1, close)\n}\n\n/** Advance past whitespace in `masked` from `i`. */\nfunction skipWs(masked: string, i: number): number {\n while (i < masked.length && (masked[i] === ' ' || masked[i] === '\\t' || masked[i] === '\\n' || masked[i] === '\\r')) i++\n return i\n}\n\nexport function scanProductRefs(files: Record<string, string>): ProductRefScan {\n const seen = new Set<string>()\n const order: string[] = []\n let dynamic = false\n const add = (v: string) => { if (v && !seen.has(v)) { seen.add(v); order.push(v) } }\n\n for (const [path, source] of Object.entries(files)) {\n if (!/\\.(tsx|jsx|ts|js)$/.test(path)) continue\n const masked = mask(source)\n\n // useProduct( … ) / useProducts( … ) — positions on the MASK (a call inside a string won't match).\n for (const m of masked.matchAll(/\\buseProducts?\\s*\\(/g)) {\n const plural = source.slice(m.index!, m.index! + 11) === 'useProducts'\n const j = skipWs(masked, m.index! + m[0].length)\n if (masked[j] === ')') { if (plural) dynamic = true; continue } // useProducts() = whole-catalog wildcard\n const lit = literalAt(source, masked, j)\n if (lit !== null) add(lit)\n else dynamic = true // useProduct(variable) — can't resolve statically\n }\n\n // <Checkout product=\"…\"> / <Upsell product=\"…\"> — the `product` attribute value.\n for (const m of masked.matchAll(/<(?:Checkout|Upsell)\\b[^>]*?\\bproduct\\s*=\\s*/g)) {\n const j = m.index! + m[0].length\n const lit = literalAt(source, masked, j)\n if (lit !== null) add(lit)\n else if (masked[j] === '{') dynamic = true // product={expr}\n }\n }\n return { slots: order, dynamic }\n}\n","/**\n * Source generators for the funnel build \"machinery\" authors no longer write. `funnel.ts` (the\n * spine: id, responses, products, checkout, and the page list + declarative routing) plus the\n * `pages/` folder are the ONLY authored source. The build (renderer/builder) and the CLI dev server\n * call these to synthesize:\n * - `mount.tsx` — code-split page loaders + `createFunnelTree`\n * - `entry.client.tsx` — hydrate the SSR'd markup from injected data\n * - `entry.server.tsx` — `ssr()` + the compiled `manifest`\n *\n * All string templates, zero runtime deps — this module lives in the pure `@appfunnel-dev/sdk/\n * manifest` entry so tooling imports it without the funnel runtime.\n */\n\nexport interface ScaffoldOptions {\n\t/** Page component keys = `pages/<key>.tsx` filenames (base flow pages AND `@variant` pages). */\n\tpageKeys: string[]\n\t/** Import prefix to reach the funnel root: `'./'` at the root (build), `'../../'` in a subdir (CLI dev). */\n\timportPrefix?: string\n\t/** Whether a `layout.tsx` exists to wrap the pages. */\n\thasLayout?: boolean\n\t/** Whether a `styles.css` exists (client entry imports it). */\n\thasStyles?: boolean\n\t/** Checkout provider from `config.checkout` — wires the driver; omit for none. */\n\tcheckout?: 'stripe' | 'paddle' | null\n\t/** Locales with a `messages/<locale>.json` catalog to bake into the mount (so `t()` resolves at render). */\n\tmessageLocales?: string[]\n\t/** Slot names the pages reference (from `scanProductRefs`), baked into the manifest for validation. */\n\tproductRefs?: string[]\n}\n\n/** A safe JS identifier for a message-catalog import (`en` → `msg_en`, `pt-BR` → `msg_pt_BR`). */\nfunction msgId(locale: string): string {\n\treturn 'msg_' + locale.replace(/[^a-zA-Z0-9]/g, '_')\n}\n\nconst DRIVERS = {\n\tstripe: { name: 'stripeCheckoutDriver', sub: 'driver-stripe' },\n\tpaddle: { name: 'paddleCheckoutDriver', sub: 'driver-paddle' },\n} as const\n\nconst HEADER = '// GENERATED by AppFunnel — do not edit. Built from funnel.ts + the pages/ folder.\\n'\n\n/** `mount.tsx` — the code-split loaders + tree, derived from `config.pages` and the `pages/` files. */\nexport function generateMount(opts: ScaffoldOptions): string {\n\tconst p = opts.importPrefix ?? './'\n\tconst driver = opts.checkout ? DRIVERS[opts.checkout] : null\n\n\tconst locales = opts.messageLocales ?? []\n\tconst imports = [\n\t\t`import { createFunnelTree, type MountOpts, type RuntimePage } from '@appfunnel-dev/sdk'`,\n\t\tdriver && `import { ${driver.name} } from '@appfunnel-dev/sdk/${driver.sub}'`,\n\t\t`import { config } from '${p}funnel'`,\n\t\topts.hasLayout && `import Layout from '${p}layout'`,\n\t\t...locales.map((loc) => `import ${msgId(loc)} from '${p}messages/${loc}.json'`),\n\t]\n\t\t.filter(Boolean)\n\t\t.join('\\n')\n\n\t// A static import() per page file so Vite emits one code-split chunk each.\n\tconst loaders = opts.pageKeys\n\t\t.map(\n\t\t\t(k) => `\\t${JSON.stringify(k)}: () => import(${JSON.stringify(`${p}pages/${k}`)}),`\n\t\t)\n\t\t.join('\\n')\n\n\tconst treeArgs = [\n\t\t'config',\n\t\t'pages',\n\t\topts.hasLayout && 'layout: Layout',\n\t\tdriver && `checkoutDriver: ${driver.name}`,\n\t\tlocales.length > 0 && 'messages',\n\t]\n\t\t.filter(Boolean)\n\t\t.join(', ')\n\n\t// The baked message catalog: locale → messages/<locale>.json (so `t()` resolves at render).\n\tconst messagesConst =\n\t\tlocales.length > 0\n\t\t\t? `\\nconst messages = { ${locales.map((loc) => `${JSON.stringify(loc)}: ${msgId(loc)}`).join(', ')} }\\n`\n\t\t\t: ''\n\n\treturn `${HEADER}${imports}\n\nconst loaders: Record<string, () => Promise<unknown>> = {\n${loaders}\n}\n\n// Flow pages come from funnel.ts (order + meta + routing). Any remaining page file is an off-flow\n// \\`@variant\\` page (wired by experiment records at render time), appended so it's loadable.\nconst decls = config.pages ?? []\nconst flowKeys = new Set(decls.map((d) => d.key))\nexport const pages: RuntimePage[] = [\n\t...decls.map((d) => ({ key: d.key, meta: d, load: loaders[d.key] })),\n\t...Object.keys(loaders)\n\t\t.filter((k) => !flowKeys.has(k))\n\t\t.map((k) => ({ key: k, meta: {}, load: loaders[k] })),\n] as RuntimePage[]\n${messagesConst}\nexport const tree = createFunnelTree({ ${treeArgs} })\n\nexport type { MountOpts }\n`\n}\n\n/** `entry.client.tsx` — hydrate the SSR'd markup from the injected `#__af_data`. */\nexport function generateEntryClient(opts: Pick<ScaffoldOptions, 'importPrefix' | 'hasStyles'>): string {\n\tconst p = opts.importPrefix ?? './'\n\tconst styles = opts.hasStyles ? `import '${p}styles.css'\\n` : ''\n\treturn `${HEADER}${styles}import { hydrateRoot } from 'react-dom/client'\nimport { tree, type MountOpts } from './mount'\n\nconst dataEl = document.getElementById('__af_data')\nconst data = (dataEl?.textContent ? JSON.parse(dataEl.textContent) : {}) as MountOpts & {\n\tinitialKey?: string | null\n}\nconst root = document.getElementById('root')\nif (root) hydrateRoot(root, tree({ ...data, initialKey: data.initialKey ?? undefined }))\n`\n}\n\n/** `entry.server.tsx` — `ssr(opts)` HTML + the compiled `manifest` (read by the build). */\nexport function generateEntryServer(opts: Pick<ScaffoldOptions, 'importPrefix' | 'productRefs'>): string {\n\tconst p = opts.importPrefix ?? './'\n\treturn `${HEADER}import { renderToReadableStream } from 'react-dom/server.browser'\nimport { compileManifest } from '@appfunnel-dev/sdk'\nimport { config } from '${p}funnel'\nimport { tree, pages, type MountOpts } from './mount'\n\nexport const manifest = compileManifest({\n\tfunnel: config,\n\tpages: pages.map((pg) => ({ key: pg.key, meta: pg.meta })),\n\tproductRefs: ${JSON.stringify(opts.productRefs ?? [])},\n})\n\nexport async function ssr(opts: MountOpts): Promise<string> {\n\tconst stream = await renderToReadableStream(tree(opts))\n\tawait stream.allReady\n\treturn await new Response(stream).text()\n}\n`\n}\n\n/** Client-only dev entry (createRoot, no SSR) — for the CLI `dev` server. */\nexport function generateDevEntry(\n\topts: Pick<ScaffoldOptions, 'importPrefix' | 'hasStyles'> & { data: unknown }\n): string {\n\tconst p = opts.importPrefix ?? './'\n\tconst styles = opts.hasStyles ? `import '${p}styles.css'\\n` : ''\n\treturn `${HEADER}${styles}import { createRoot } from 'react-dom/client'\nimport { tree } from './mount'\n\nconst el = document.getElementById('root')\nif (el) createRoot(el).render(tree(${JSON.stringify(opts.data)}))\n`\n}\n"]}
1
+ {"version":3,"sources":["../src/manifest/offering-refs.ts","../src/flow/scaffold.ts"],"names":[],"mappings":";;;;;AAsBA,SAAS,KAAK,GAAA,EAAqB;AACjC,EA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AAA;;AAAA;AAAA,mCAAA,EAIW,IAAA,CAAK,SAAA,CAAU,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,CAAA;AAE9D","file":"manifest-entry.js","sourcesContent":["/**\n * Pure, React-free page scan: find which offering SLOTS a funnel's pages reference — the first\n * string-literal arg of `useOffering(...)` and the `offering` prop of `<Checkout>` / `<Upsell>`.\n * Ships via `@appfunnel-dev/sdk/manifest` so the BUILD, the EDITOR, and the AI all run the SAME\n * check. The result feeds `compileManifest({ offeringRefs })`, which flags references to slots the\n * funnel doesn't declare (unknown) or hasn't assigned a catalog charge key to (unassigned).\n *\n * Non-literal args (`useOffering(selectedId)`, `offering={expr}`) and the `useOfferings()` wildcard are\n * DYNAMIC — they can't be statically enumerated, so they're reported via `dynamic` and never turned\n * into a hard error (validation relaxes when a funnel is dynamic). Mirrors the mask-then-read\n * discipline the funnel.ts code-mods use, so a `useOffering('x')` inside a comment or string literal\n * can't false-positive.\n */\n\nexport interface OfferingRefScan {\n /** Concrete slot names referenced by LITERAL args, deduped, in first-seen order. */\n slots: string[]\n /** True if any ref is a non-literal arg or a `useOfferings()` wildcard (not statically enumerable). */\n dynamic: boolean\n}\n\n/** Blank comment + string/template CONTENTS (keep quote delimiters + length) so scans don't fire inside them. */\nfunction mask(src: string): string {\n const out = src.split('')\n const n = src.length\n let i = 0\n while (i < n) {\n const c = src[i]\n const d = src[i + 1]\n if (c === '/' && d === '/') {\n while (i < n && src[i] !== '\\n') { out[i] = ' '; i++ }\n } else if (c === '/' && d === '*') {\n out[i] = ' '; out[i + 1] = ' '; i += 2\n while (i < n) {\n if (src[i] === '*' && src[i + 1] === '/') { out[i] = ' '; out[i + 1] = ' '; i += 2; break }\n if (src[i] !== '\\n') out[i] = ' '\n i++\n }\n } else if (c === \"'\" || c === '\"' || c === '`') {\n i++\n while (i < n && src[i] !== c) {\n if (src[i] === '\\\\') { out[i] = ' '; i++; if (i < n && src[i] !== '\\n') out[i] = ' '; i++; continue }\n if (src[i] !== '\\n') out[i] = ' '\n i++\n }\n i++ // closing delimiter (kept)\n } else i++\n }\n return out.join('')\n}\n\n/** A quoted string literal starting at `open` (a quote char in the MASK). Value read from the ORIGINAL. */\nfunction literalAt(src: string, masked: string, open: number): string | null {\n const q = masked[open]\n if (q !== \"'\" && q !== '\"' && q !== '`') return null\n const close = masked.indexOf(q, open + 1)\n if (close === -1) return null\n return src.slice(open + 1, close)\n}\n\n/** Advance past whitespace in `masked` from `i`. */\nfunction skipWs(masked: string, i: number): number {\n while (i < masked.length && (masked[i] === ' ' || masked[i] === '\\t' || masked[i] === '\\n' || masked[i] === '\\r')) i++\n return i\n}\n\nexport function scanOfferingRefs(files: Record<string, string>): OfferingRefScan {\n const seen = new Set<string>()\n const order: string[] = []\n let dynamic = false\n const add = (v: string) => { if (v && !seen.has(v)) { seen.add(v); order.push(v) } }\n\n for (const [path, source] of Object.entries(files)) {\n if (!/\\.(tsx|jsx|ts|js)$/.test(path)) continue\n const masked = mask(source)\n\n // useOffering( … ) / useOfferings( … ) — positions on the MASK (a call inside a string won't match).\n for (const m of masked.matchAll(/\\buseOfferings?\\s*\\(/g)) {\n const plural = source.slice(m.index!, m.index! + 12) === 'useOfferings'\n const j = skipWs(masked, m.index! + m[0].length)\n if (masked[j] === ')') { if (plural) dynamic = true; continue } // useOfferings() = whole-catalog wildcard\n const lit = literalAt(source, masked, j)\n if (lit !== null) add(lit)\n else dynamic = true // useOffering(variable) — can't resolve statically\n }\n\n // <Checkout offering=\"…\"> / <Upsell offering=\"…\"> — the `offering` attribute value.\n for (const m of masked.matchAll(/<(?:Checkout|Upsell)\\b[^>]*?\\boffering\\s*=\\s*/g)) {\n const j = m.index! + m[0].length\n const lit = literalAt(source, masked, j)\n if (lit !== null) add(lit)\n else if (masked[j] === '{') dynamic = true // offering={expr}\n }\n }\n return { slots: order, dynamic }\n}\n","/**\n * Source generators for the funnel build \"machinery\" authors no longer write. `funnel.ts` (the\n * spine: id, responses, offerings, checkout, and the page list + declarative routing) plus the\n * `pages/` folder are the ONLY authored source. The build (renderer/builder) and the CLI dev server\n * call these to synthesize:\n * - `mount.tsx` — code-split page loaders + `createFunnelTree`\n * - `entry.client.tsx` — hydrate the SSR'd markup from injected data\n * - `entry.server.tsx` — `ssr()` + the compiled `manifest`\n *\n * All string templates, zero runtime deps — this module lives in the pure `@appfunnel-dev/sdk/\n * manifest` entry so tooling imports it without the funnel runtime.\n */\n\nexport interface ScaffoldOptions {\n\t/** Page component keys = `pages/<key>.tsx` filenames (base flow pages AND `@variant` pages). */\n\tpageKeys: string[]\n\t/** Import prefix to reach the funnel root: `'./'` at the root (build), `'../../'` in a subdir (CLI dev). */\n\timportPrefix?: string\n\t/** Whether a `layout.tsx` exists to wrap the pages. */\n\thasLayout?: boolean\n\t/** Whether a `styles.css` exists (client entry imports it). */\n\thasStyles?: boolean\n\t/** Checkout provider from `config.checkout` — wires the driver; omit for none. */\n\tcheckout?: 'stripe' | 'paddle' | null\n\t/** Locales with a `messages/<locale>.json` catalog to bake into the mount (so `t()` resolves at render). */\n\tmessageLocales?: string[]\n\t/** Slot names the pages reference (from `scanOfferingRefs`), baked into the manifest for validation. */\n\tofferingRefs?: string[]\n}\n\n/** A safe JS identifier for a message-catalog import (`en` → `msg_en`, `pt-BR` → `msg_pt_BR`). */\nfunction msgId(locale: string): string {\n\treturn 'msg_' + locale.replace(/[^a-zA-Z0-9]/g, '_')\n}\n\nconst DRIVERS = {\n\tstripe: { name: 'stripeCheckoutDriver', sub: 'driver-stripe' },\n\tpaddle: { name: 'paddleCheckoutDriver', sub: 'driver-paddle' },\n} as const\n\nconst HEADER =\n\t'// GENERATED by Appfunnel — do not edit. Built from funnel.ts + the pages/ folder.\\n'\n\n/** `mount.tsx` — the code-split loaders + tree, derived from `config.pages` and the `pages/` files. */\nexport function generateMount(opts: ScaffoldOptions): string {\n\tconst p = opts.importPrefix ?? './'\n\tconst driver = opts.checkout ? DRIVERS[opts.checkout] : null\n\n\tconst locales = opts.messageLocales ?? []\n\tconst imports = [\n\t\t`import { createFunnelTree, type MountOpts, type RuntimePage } from '@appfunnel-dev/sdk'`,\n\t\tdriver &&\n\t\t\t`import { ${driver.name} } from '@appfunnel-dev/sdk/${driver.sub}'`,\n\t\t`import { config } from '${p}funnel'`,\n\t\topts.hasLayout && `import Layout from '${p}layout'`,\n\t\t...locales.map(\n\t\t\t(loc) => `import ${msgId(loc)} from '${p}messages/${loc}.json'`\n\t\t),\n\t]\n\t\t.filter(Boolean)\n\t\t.join('\\n')\n\n\t// A static import() per page file so Vite emits one code-split chunk each.\n\tconst loaders = opts.pageKeys\n\t\t.map(\n\t\t\t(k) =>\n\t\t\t\t`\\t${JSON.stringify(k)}: () => import(${JSON.stringify(`${p}pages/${k}`)}),`\n\t\t)\n\t\t.join('\\n')\n\n\tconst treeArgs = [\n\t\t'config',\n\t\t'pages',\n\t\topts.hasLayout && 'layout: Layout',\n\t\tdriver && `checkoutDriver: ${driver.name}`,\n\t\tlocales.length > 0 && 'messages',\n\t]\n\t\t.filter(Boolean)\n\t\t.join(', ')\n\n\t// The baked message catalog: locale → messages/<locale>.json (so `t()` resolves at render).\n\tconst messagesConst =\n\t\tlocales.length > 0\n\t\t\t? `\\nconst messages = { ${locales.map((loc) => `${JSON.stringify(loc)}: ${msgId(loc)}`).join(', ')} }\\n`\n\t\t\t: ''\n\n\treturn `${HEADER}${imports}\n\nconst loaders: Record<string, () => Promise<unknown>> = {\n${loaders}\n}\n\n// Flow pages come from funnel.ts (order + meta + routing). A \\`@variant\\` page MAY also be declared\n// there (with its \\`@\\` key) to carry its OWN optional routing (\\`next\\`) — it still collapses out of\n// the linear flow by the \\`@\\` marker, but its meta rides along here. Any page file NOT declared is an\n// off-flow \\`@variant\\` with no own routing, appended with empty meta so it's still loadable.\nconst decls = config.pages ?? []\nconst flowKeys = new Set(decls.map((d) => d.key))\nexport const pages: RuntimePage[] = [\n\t...decls.map((d) => ({ key: d.key, meta: d, load: loaders[d.key] })),\n\t...Object.keys(loaders)\n\t\t.filter((k) => !flowKeys.has(k))\n\t\t.map((k) => ({ key: k, meta: {}, load: loaders[k] })),\n] as RuntimePage[]\n${messagesConst}\nexport const tree = createFunnelTree({ ${treeArgs} })\n\nexport type { MountOpts }\n`\n}\n\n/** `entry.client.tsx` — hydrate the SSR'd markup from the injected `#__af_data`. */\nexport function generateEntryClient(\n\topts: Pick<ScaffoldOptions, 'importPrefix' | 'hasStyles'>\n): string {\n\tconst p = opts.importPrefix ?? './'\n\tconst styles = opts.hasStyles ? `import '${p}styles.css'\\n` : ''\n\treturn `${HEADER}${styles}import { hydrateRoot } from 'react-dom/client'\nimport { tree, type MountOpts } from './mount'\n\nconst dataEl = document.getElementById('__af_data')\nconst data = (dataEl?.textContent ? JSON.parse(dataEl.textContent) : {}) as MountOpts & {\n\tinitialKey?: string | null\n}\nconst root = document.getElementById('root')\n// FLASH-FREE HYDRATION (SSR-isolation Option B): always DEFER sessionValues on the client. The\n// markup we hydrate against is DEFAULT-state (build-time prerendered, or an SSR render with empty\n// sessionValues), so seeding the store with defaults for the first render is a byte-clean match —\n// no hydration mismatch. The visitor's saved answers (data.sessionValues, present on the \"tail\"\n// path) are then applied post-hydration, popping into already-visible controls with no empty\n// flash. On the cold path sessionValues is absent, so deferring is a no-op (identical output).\nif (root) hydrateRoot(root, tree({ ...data, initialKey: data.initialKey ?? undefined, deferSessionValues: true }))\n`\n}\n\n/** `entry.server.tsx` — `ssr(opts)` HTML + the compiled `manifest` (read by the build). */\nexport function generateEntryServer(\n\topts: Pick<ScaffoldOptions, 'importPrefix' | 'offeringRefs'>\n): string {\n\tconst p = opts.importPrefix ?? './'\n\treturn `${HEADER}import { renderToReadableStream } from 'react-dom/server.browser'\nimport { compileManifest } from '@appfunnel-dev/sdk'\nimport { config } from '${p}funnel'\nimport { tree, pages, type MountOpts } from './mount'\n\nexport const manifest = compileManifest({\n\tfunnel: config,\n\tpages: pages.map((pg) => ({ key: pg.key, meta: pg.meta })),\n\tofferingRefs: ${JSON.stringify(opts.offeringRefs ?? [])},\n})\n\nexport async function ssr(opts: MountOpts): Promise<string> {\n\tconst stream = await renderToReadableStream(tree(opts))\n\tawait stream.allReady\n\treturn await new Response(stream).text()\n}\n`\n}\n\n/** Client-only dev entry (createRoot, no SSR) — for the CLI `dev` server. */\nexport function generateDevEntry(\n\topts: Pick<ScaffoldOptions, 'importPrefix' | 'hasStyles'> & {\n\t\tdata: unknown\n\t}\n): string {\n\tconst p = opts.importPrefix ?? './'\n\tconst styles = opts.hasStyles ? `import '${p}styles.css'\\n` : ''\n\treturn `${HEADER}${styles}import { createRoot } from 'react-dom/client'\nimport { tree } from './mount'\n\nconst el = document.getElementById('root')\nif (el) createRoot(el).render(tree(${JSON.stringify(opts.data)}))\n`\n}\n"]}
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var chunkWYUDL4FI_cjs = require('./chunk-WYUDL4FI.cjs');
4
+ require('./chunk-EMMSS5I5.cjs');
5
+
6
+
7
+
8
+ Object.defineProperty(exports, "AF_PROTOCOL", {
9
+ enumerable: true,
10
+ get: function () { return chunkWYUDL4FI_cjs.AF_PROTOCOL; }
11
+ });
12
+ //# sourceMappingURL=protocol.cjs.map
13
+ //# sourceMappingURL=protocol.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"protocol.cjs"}
@@ -0,0 +1,182 @@
1
+ /**
2
+ * The **Funnel Embed API** wire protocol — the versioned contract for the cross-origin channel
3
+ * between a host (the editor today; 3rd-party embedders later) and a funnel running in a frame.
4
+ *
5
+ * Side-effect-free and (almost) type-only: import it from `@appfunnel-dev/sdk/protocol` on BOTH
6
+ * ends — the funnel side (SDK `EmbedBridge`) and the host side (`@appfunnel/embed` / the dashboard)
7
+ * — so the two can never drift. The runtime that carries these types (the RPC dispatcher, the
8
+ * bridge, the host client) lives elsewhere; this file is just the shared shapes.
9
+ *
10
+ * Two message families ride one envelope:
11
+ * - **methods** — request/response, `id`-correlated (needed the moment anything returns data, e.g.
12
+ * `screenshot`). Host → funnel.
13
+ * - **events** — fire-and-forget notifications. Funnel → host (e.g. `navigation`).
14
+ * A `hello` handshake advertises the protocol major + capability set so an older funnel (pinned to
15
+ * an older SDK via esm.sh) degrades gracefully instead of hanging on an unknown method.
16
+ */
17
+ /**
18
+ * Wire-format major. **Frozen** — bump ONLY on a breaking envelope change, which the design tries to
19
+ * make never happen (new capabilities are new `method`/`event` names, not new envelope shapes). A
20
+ * receiver drops any message whose `af` major it doesn't speak.
21
+ */
22
+ declare const AF_PROTOCOL: 1;
23
+ /**
24
+ * Trust-direction tag — the ONLY vocabulary the preview-host relay gates on (besides origin). **Frozen**:
25
+ * these strings are compiled into every sealed funnel build, so they are renamed NEVER; the protocol
26
+ * evolves via `af`/`kind`/`method`, not by re-tagging. `af-host` = from the host/parent (dashboard/
27
+ * embedder); `af-preview` = from the funnel/embed (the child frame).
28
+ */
29
+ type EnvelopeSource = 'af-host' | 'af-preview';
30
+ interface BaseEnvelope {
31
+ /** Wire-format major — see {@link AF_PROTOCOL}. */
32
+ af: typeof AF_PROTOCOL;
33
+ /** Who sent it (trust direction). */
34
+ source: EnvelopeSource;
35
+ }
36
+ /** Host → funnel: invoke a method. Correlate the reply by `id`. */
37
+ interface RequestMessage<M extends MethodName = MethodName> extends BaseEnvelope {
38
+ kind: 'request';
39
+ id: string;
40
+ method: M;
41
+ params: MethodParams<M>;
42
+ }
43
+ /** Funnel → host: the reply to a {@link RequestMessage}, echoing its `id`. */
44
+ interface ResponseMessage extends BaseEnvelope {
45
+ kind: 'response';
46
+ id: string;
47
+ ok: boolean;
48
+ result?: unknown;
49
+ error?: EmbedError;
50
+ }
51
+ /** Funnel → host: a fire-and-forget notification (no `id`, lossy-tolerant). */
52
+ interface EventMessage<E extends EventName = EventName> extends BaseEnvelope {
53
+ kind: 'event';
54
+ event: E;
55
+ data: EventData<E>;
56
+ }
57
+ /** Either side on connect: announce protocol major + capabilities (see the handshake note above). */
58
+ interface HelloMessage extends BaseEnvelope {
59
+ kind: 'hello';
60
+ role: 'funnel' | 'host';
61
+ /** Wire major this end speaks (== `af`). Negotiated dialect = min of both ends. */
62
+ protocol: number;
63
+ /** Diagnostics only (e.g. '2.0.0-canary.5'). Never gate behavior on this — use `capabilities`. */
64
+ sdkVersion?: string;
65
+ capabilities: Capabilities;
66
+ }
67
+ type EmbedMessage = RequestMessage | ResponseMessage | EventMessage | HelloMessage;
68
+ interface EmbedError {
69
+ code: 'unknown_method' | 'bad_params' | 'not_allowed' | 'failed' | 'timeout';
70
+ message: string;
71
+ }
72
+ /** Host → funnel request/response methods, namespaced by domain. */
73
+ interface Methods {
74
+ /** Current flow position (replaces the old fire-and-forget `nav-request`). */
75
+ 'nav.snapshot': {
76
+ params: void;
77
+ result: NavSnapshot;
78
+ };
79
+ /** Jump to a page key. Resolves when accepted (unknown key → `bad_params` error); the resulting
80
+ * position arrives as a `navigation` event, since the funnel navigates asynchronously. */
81
+ 'nav.goTo': {
82
+ params: {
83
+ key: string;
84
+ };
85
+ result: void;
86
+ };
87
+ 'nav.goNext': {
88
+ params: void;
89
+ result: void;
90
+ };
91
+ 'nav.goPrevious': {
92
+ params: void;
93
+ result: void;
94
+ };
95
+ /** Capture the running funnel to an image (see {@link ScreenshotParams}). */
96
+ screenshot: {
97
+ params: ScreenshotParams;
98
+ result: ScreenshotResult;
99
+ };
100
+ }
101
+ /** Funnel → host fire-and-forget events. */
102
+ interface Events {
103
+ /** The flow moved — pushed on every page change (incl. the initial page). Always on. */
104
+ navigation: NavSnapshot;
105
+ }
106
+ type MethodName = keyof Methods;
107
+ type MethodParams<M extends MethodName> = Methods[M]['params'];
108
+ type MethodResult<M extends MethodName> = Methods[M]['result'];
109
+ type EventName = keyof Events;
110
+ type EventData<E extends EventName> = Events[E];
111
+ /** What an end implements — a SET of tokens (a funnel can be on any historical SDK), not a version int. */
112
+ interface Capabilities {
113
+ methods: MethodName[];
114
+ events: EventName[];
115
+ }
116
+ /** A live snapshot of the funnel's flow position — the single source of truth for both surfaces. */
117
+ interface NavSnapshot {
118
+ /** Current page key. */
119
+ key: string;
120
+ /** Zero-based position in the visitor's traversed path. */
121
+ index: number;
122
+ /** Expected total steps on the branch the current answers imply. */
123
+ total: number;
124
+ /** 0..100 progress along that expected path (matches PageContext.progressPercentage). */
125
+ progressPercentage: number;
126
+ /** Whether `nav.goPrevious` would move. */
127
+ canGoBack: boolean;
128
+ /** Page keys the visitor could advance to next. */
129
+ nextCandidates: string[];
130
+ }
131
+ /** What region of the funnel to capture. Default `{ kind: 'page' }` (the funnel root, full height). */
132
+ type ScreenshotTarget = {
133
+ kind: 'page';
134
+ } | {
135
+ kind: 'viewport';
136
+ } | {
137
+ kind: 'selector';
138
+ selector: string;
139
+ };
140
+ interface ScreenshotParams {
141
+ target?: ScreenshotTarget;
142
+ /** Encoded image format. Default 'png'. */
143
+ format?: 'png' | 'jpeg' | 'webp';
144
+ /** Lossy quality 0..1 for jpeg/webp (ignored for png). Default 0.92. */
145
+ quality?: number;
146
+ /** How the bytes cross postMessage. Default 'blob' (no base64 inflation across the two-hop relay). */
147
+ encoding?: 'blob' | 'dataURL';
148
+ /** Device-pixel scale. Default 2 (deterministic, NOT the live devicePixelRatio). Clamped to `maxScale`. */
149
+ scale?: number;
150
+ /** Upper bound on `scale` (bounds payload size). Default 3. */
151
+ maxScale?: number;
152
+ /** Explicit output box in CSS px (pre-scale). Default = the target's rendered box. */
153
+ width?: number;
154
+ height?: number;
155
+ /** Painted under transparent regions. Default '#ffffff'. `null` → transparent (png/webp only). */
156
+ backgroundColor?: string | null;
157
+ /** await document.fonts.ready before capture. Default true. */
158
+ waitForFonts?: boolean;
159
+ /** await in-tree images decoding + inline them. Default true. */
160
+ waitForImages?: boolean;
161
+ /** Scroll the target through its height first to trigger lazy/IO images (restores scroll). Default false. */
162
+ triggerLazyLoad?: boolean;
163
+ /** Selectors hidden during capture (dev overlays, the "compiling…" chip, cursors). Default []. */
164
+ hideSelectors?: string[];
165
+ /** Hard cap (ms) on the whole capture incl. asset waits. Default 10000. */
166
+ timeout?: number;
167
+ }
168
+ interface ScreenshotResult {
169
+ mime: string;
170
+ /** Produced pixel dimensions (post-scale). */
171
+ width: number;
172
+ height: number;
173
+ /** The scale actually used (after the maxScale clamp). */
174
+ scale: number;
175
+ /** Payload size, for the caller to guard / for telemetry. */
176
+ bytesApprox: number;
177
+ /** Exactly one of these is set, per `params.encoding`. */
178
+ blob?: Blob;
179
+ dataURL?: string;
180
+ }
181
+
182
+ export { AF_PROTOCOL, type Capabilities, type EmbedError, type EmbedMessage, type EnvelopeSource, type EventData, type EventMessage, type EventName, type Events, type HelloMessage, type MethodName, type MethodParams, type MethodResult, type Methods, type NavSnapshot, type RequestMessage, type ResponseMessage, type ScreenshotParams, type ScreenshotResult, type ScreenshotTarget };
@@ -0,0 +1,182 @@
1
+ /**
2
+ * The **Funnel Embed API** wire protocol — the versioned contract for the cross-origin channel
3
+ * between a host (the editor today; 3rd-party embedders later) and a funnel running in a frame.
4
+ *
5
+ * Side-effect-free and (almost) type-only: import it from `@appfunnel-dev/sdk/protocol` on BOTH
6
+ * ends — the funnel side (SDK `EmbedBridge`) and the host side (`@appfunnel/embed` / the dashboard)
7
+ * — so the two can never drift. The runtime that carries these types (the RPC dispatcher, the
8
+ * bridge, the host client) lives elsewhere; this file is just the shared shapes.
9
+ *
10
+ * Two message families ride one envelope:
11
+ * - **methods** — request/response, `id`-correlated (needed the moment anything returns data, e.g.
12
+ * `screenshot`). Host → funnel.
13
+ * - **events** — fire-and-forget notifications. Funnel → host (e.g. `navigation`).
14
+ * A `hello` handshake advertises the protocol major + capability set so an older funnel (pinned to
15
+ * an older SDK via esm.sh) degrades gracefully instead of hanging on an unknown method.
16
+ */
17
+ /**
18
+ * Wire-format major. **Frozen** — bump ONLY on a breaking envelope change, which the design tries to
19
+ * make never happen (new capabilities are new `method`/`event` names, not new envelope shapes). A
20
+ * receiver drops any message whose `af` major it doesn't speak.
21
+ */
22
+ declare const AF_PROTOCOL: 1;
23
+ /**
24
+ * Trust-direction tag — the ONLY vocabulary the preview-host relay gates on (besides origin). **Frozen**:
25
+ * these strings are compiled into every sealed funnel build, so they are renamed NEVER; the protocol
26
+ * evolves via `af`/`kind`/`method`, not by re-tagging. `af-host` = from the host/parent (dashboard/
27
+ * embedder); `af-preview` = from the funnel/embed (the child frame).
28
+ */
29
+ type EnvelopeSource = 'af-host' | 'af-preview';
30
+ interface BaseEnvelope {
31
+ /** Wire-format major — see {@link AF_PROTOCOL}. */
32
+ af: typeof AF_PROTOCOL;
33
+ /** Who sent it (trust direction). */
34
+ source: EnvelopeSource;
35
+ }
36
+ /** Host → funnel: invoke a method. Correlate the reply by `id`. */
37
+ interface RequestMessage<M extends MethodName = MethodName> extends BaseEnvelope {
38
+ kind: 'request';
39
+ id: string;
40
+ method: M;
41
+ params: MethodParams<M>;
42
+ }
43
+ /** Funnel → host: the reply to a {@link RequestMessage}, echoing its `id`. */
44
+ interface ResponseMessage extends BaseEnvelope {
45
+ kind: 'response';
46
+ id: string;
47
+ ok: boolean;
48
+ result?: unknown;
49
+ error?: EmbedError;
50
+ }
51
+ /** Funnel → host: a fire-and-forget notification (no `id`, lossy-tolerant). */
52
+ interface EventMessage<E extends EventName = EventName> extends BaseEnvelope {
53
+ kind: 'event';
54
+ event: E;
55
+ data: EventData<E>;
56
+ }
57
+ /** Either side on connect: announce protocol major + capabilities (see the handshake note above). */
58
+ interface HelloMessage extends BaseEnvelope {
59
+ kind: 'hello';
60
+ role: 'funnel' | 'host';
61
+ /** Wire major this end speaks (== `af`). Negotiated dialect = min of both ends. */
62
+ protocol: number;
63
+ /** Diagnostics only (e.g. '2.0.0-canary.5'). Never gate behavior on this — use `capabilities`. */
64
+ sdkVersion?: string;
65
+ capabilities: Capabilities;
66
+ }
67
+ type EmbedMessage = RequestMessage | ResponseMessage | EventMessage | HelloMessage;
68
+ interface EmbedError {
69
+ code: 'unknown_method' | 'bad_params' | 'not_allowed' | 'failed' | 'timeout';
70
+ message: string;
71
+ }
72
+ /** Host → funnel request/response methods, namespaced by domain. */
73
+ interface Methods {
74
+ /** Current flow position (replaces the old fire-and-forget `nav-request`). */
75
+ 'nav.snapshot': {
76
+ params: void;
77
+ result: NavSnapshot;
78
+ };
79
+ /** Jump to a page key. Resolves when accepted (unknown key → `bad_params` error); the resulting
80
+ * position arrives as a `navigation` event, since the funnel navigates asynchronously. */
81
+ 'nav.goTo': {
82
+ params: {
83
+ key: string;
84
+ };
85
+ result: void;
86
+ };
87
+ 'nav.goNext': {
88
+ params: void;
89
+ result: void;
90
+ };
91
+ 'nav.goPrevious': {
92
+ params: void;
93
+ result: void;
94
+ };
95
+ /** Capture the running funnel to an image (see {@link ScreenshotParams}). */
96
+ screenshot: {
97
+ params: ScreenshotParams;
98
+ result: ScreenshotResult;
99
+ };
100
+ }
101
+ /** Funnel → host fire-and-forget events. */
102
+ interface Events {
103
+ /** The flow moved — pushed on every page change (incl. the initial page). Always on. */
104
+ navigation: NavSnapshot;
105
+ }
106
+ type MethodName = keyof Methods;
107
+ type MethodParams<M extends MethodName> = Methods[M]['params'];
108
+ type MethodResult<M extends MethodName> = Methods[M]['result'];
109
+ type EventName = keyof Events;
110
+ type EventData<E extends EventName> = Events[E];
111
+ /** What an end implements — a SET of tokens (a funnel can be on any historical SDK), not a version int. */
112
+ interface Capabilities {
113
+ methods: MethodName[];
114
+ events: EventName[];
115
+ }
116
+ /** A live snapshot of the funnel's flow position — the single source of truth for both surfaces. */
117
+ interface NavSnapshot {
118
+ /** Current page key. */
119
+ key: string;
120
+ /** Zero-based position in the visitor's traversed path. */
121
+ index: number;
122
+ /** Expected total steps on the branch the current answers imply. */
123
+ total: number;
124
+ /** 0..100 progress along that expected path (matches PageContext.progressPercentage). */
125
+ progressPercentage: number;
126
+ /** Whether `nav.goPrevious` would move. */
127
+ canGoBack: boolean;
128
+ /** Page keys the visitor could advance to next. */
129
+ nextCandidates: string[];
130
+ }
131
+ /** What region of the funnel to capture. Default `{ kind: 'page' }` (the funnel root, full height). */
132
+ type ScreenshotTarget = {
133
+ kind: 'page';
134
+ } | {
135
+ kind: 'viewport';
136
+ } | {
137
+ kind: 'selector';
138
+ selector: string;
139
+ };
140
+ interface ScreenshotParams {
141
+ target?: ScreenshotTarget;
142
+ /** Encoded image format. Default 'png'. */
143
+ format?: 'png' | 'jpeg' | 'webp';
144
+ /** Lossy quality 0..1 for jpeg/webp (ignored for png). Default 0.92. */
145
+ quality?: number;
146
+ /** How the bytes cross postMessage. Default 'blob' (no base64 inflation across the two-hop relay). */
147
+ encoding?: 'blob' | 'dataURL';
148
+ /** Device-pixel scale. Default 2 (deterministic, NOT the live devicePixelRatio). Clamped to `maxScale`. */
149
+ scale?: number;
150
+ /** Upper bound on `scale` (bounds payload size). Default 3. */
151
+ maxScale?: number;
152
+ /** Explicit output box in CSS px (pre-scale). Default = the target's rendered box. */
153
+ width?: number;
154
+ height?: number;
155
+ /** Painted under transparent regions. Default '#ffffff'. `null` → transparent (png/webp only). */
156
+ backgroundColor?: string | null;
157
+ /** await document.fonts.ready before capture. Default true. */
158
+ waitForFonts?: boolean;
159
+ /** await in-tree images decoding + inline them. Default true. */
160
+ waitForImages?: boolean;
161
+ /** Scroll the target through its height first to trigger lazy/IO images (restores scroll). Default false. */
162
+ triggerLazyLoad?: boolean;
163
+ /** Selectors hidden during capture (dev overlays, the "compiling…" chip, cursors). Default []. */
164
+ hideSelectors?: string[];
165
+ /** Hard cap (ms) on the whole capture incl. asset waits. Default 10000. */
166
+ timeout?: number;
167
+ }
168
+ interface ScreenshotResult {
169
+ mime: string;
170
+ /** Produced pixel dimensions (post-scale). */
171
+ width: number;
172
+ height: number;
173
+ /** The scale actually used (after the maxScale clamp). */
174
+ scale: number;
175
+ /** Payload size, for the caller to guard / for telemetry. */
176
+ bytesApprox: number;
177
+ /** Exactly one of these is set, per `params.encoding`. */
178
+ blob?: Blob;
179
+ dataURL?: string;
180
+ }
181
+
182
+ export { AF_PROTOCOL, type Capabilities, type EmbedError, type EmbedMessage, type EnvelopeSource, type EventData, type EventMessage, type EventName, type Events, type HelloMessage, type MethodName, type MethodParams, type MethodResult, type Methods, type NavSnapshot, type RequestMessage, type ResponseMessage, type ScreenshotParams, type ScreenshotResult, type ScreenshotTarget };
@@ -0,0 +1,4 @@
1
+ export { AF_PROTOCOL } from './chunk-ZZJG4EYL.js';
2
+ import './chunk-G3PMV62Z.js';
3
+ //# sourceMappingURL=protocol.js.map
4
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"protocol.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appfunnel-dev/sdk",
3
- "version": "2.0.0-canary.4",
3
+ "version": "2.0.0-canary.7",
4
4
  "description": "The AppFunnel funnel framework — typed namespaces, routing, commerce, modals, i18n for React funnels",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -31,6 +31,16 @@
31
31
  "default": "./dist/manifest-entry.cjs"
32
32
  }
33
33
  },
34
+ "./protocol": {
35
+ "import": {
36
+ "types": "./dist/protocol.d.ts",
37
+ "default": "./dist/protocol.js"
38
+ },
39
+ "require": {
40
+ "types": "./dist/protocol.d.cts",
41
+ "default": "./dist/protocol.cjs"
42
+ }
43
+ },
34
44
  "./driver-stripe": {
35
45
  "import": {
36
46
  "types": "./dist/driver-stripe.d.ts",
@@ -82,9 +92,11 @@
82
92
  "sonner": "^2.0.7",
83
93
  "@stripe/stripe-js": "^9.9.0",
84
94
  "@stripe/react-stripe-js": "^6.7.0",
85
- "@paddle/paddle-js": "^1.6.4"
95
+ "@paddle/paddle-js": "^1.6.4",
96
+ "modern-screenshot": "^4.6.8"
86
97
  },
87
98
  "devDependencies": {
99
+ "@testing-library/dom": "^10.4.1",
88
100
  "@testing-library/react": "^16.1.0",
89
101
  "@types/react": "^19.0.0",
90
102
  "@types/react-dom": "^19.0.0",