@funnelsgrove/sdk

中文文档
0.4.0发布于 2026/09/17TypeScriptES Module零依赖近 30 天下载 4939

Embed FunnelsGrove paywalls in web applications

原始使用文档
文档目录3 节
  1. Mount in your frontend
  2. Completion and return URL
  3. Payment setup and rollout

@funnelsgrove/sdk

Embed a published FunnelsGrove paywall directly in a web app. No app backend, secret key, or paywall session is required. The package has no framework dependency.

npm install @funnelsgrove/sdk

The implementation is a release candidate. npm currently contains the metadata-only 0.0.0-bootstrap.0 reservation, without executable SDK code.

Mount in your frontend

import { mountPaywall } from '@funnelsgrove/sdk';

const paywall = mountPaywall({
  container: '#paywall',
  paywallUrl: 'https://pay.example.com/paywall',
  ...(currentUser.funnelsGroveUserId
    ? { userId: currentUser.funnelsGroveUserId }
    : { email: currentUser.email }),
  returnUrl: '/billing/complete',
  onReady: ({ userId }) => console.log('Paywall ready for FG user', userId),
  onComplete: () => console.log('Payment confirmed'),
  onError: (error) => showPaymentError(error.message),
});

// On route change, modal close, or component cleanup:
paywall.destroy();

paywallUrl is the published paywall route, without query parameters or a fragment. Use HTTPS in production; localhost HTTP is supported for development. The published funnel supplies its public FG key and funnel configuration.

Provide FG userId or email. userId is the existing FG public user_id, scoped to this funnel and Test/Live environment. It is not your application's account ID or FG's internal row ID. Unknown IDs fail without creating a user or falling back to email. With email only, FG normalizes and reuses or creates the canonical user. Concurrent requests for the same email converge on one user. If both fields are provided, they must match or resolution fails. Resolution does not change an existing user's email or purchase history. onReady({ userId }) exposes the selected FG ID; the mount keeps it for subsequent provider returns. If an email form in the paywall resolves another owner, it shows a conflict inside the iframe and keeps the current buyer; reopen from the app to select a different account.

This follows FG's public checkout identity model. Browser-supplied ID/email is not proof of ownership of an authenticated app account. This SDK does not change the access model of existing public user APIs.

Completion and return URL

returnUrl is optional. Relative URLs resolve against the app page. After FG verifies the successful checkout, the SDK calls onComplete once per mount and navigates the parent window to returnUrl. Without it, the caller handles navigation. Pending or failed payments do not redirect. The destination is kept in the parent; child messages cannot replace it. A configured redirect still runs if onComplete throws; use the callback for synchronous notification and handle callback errors in your app.

Use verified billing webhooks/subscription state to grant and revoke access, including renewals and cancellations. Browser callbacks and redirects only tell the app to refresh that state.

onError receives a PaywallError with code:

  • paywall_unavailable: reopen the paywall or correct its configuration/identity.
  • confirmation_pending: keep the iframe and use Check payment status.
  • payment_failed: keep the iframe to let the buyer try again.

The SDK checks message origin, sender window and iframe instance, and adjusts iframe height. Settings are exchanged using postMessage; user identity and the app return URL are absent from iframe/provider URLs. Provider success/failure returns reload the FG paywall and recover settings from the original mounted parent. Keep that parent mounted during redirects. A replaced parent or a provider return into a top-level window requires reopening from the app. Solidgate return recovery also uses sessionStorage for its checkout ID; blocked storage can prevent redirect recovery. Inline checkout does not need that storage.

Payment setup and rollout

The funnel uses its existing Stripe/Solidgate checkout, including eligible wallets. The iframe has allow="payment *". Register/verify both app and funnel domains for Apple Pay, and configure Google Pay with the provider. Hosting frame-ancestors and app frame-src policies must permit the intended origins. Real wallets and 3DS require provider/browser acceptance; local fixtures do not establish that support.

Publish SDK, runtime, analytics and payments in dependency order, deploy the matching API, then rebuild the target funnel. Older funnels do not understand this embed protocol. The API image builds local SDK/runtime tarballs before their npm release, but promotion's CLI gate needs published package artifacts.

This is an ESM package. TypeScript supports moduleResolution: "NodeNext" or "Bundler". There is no server import; @funnelsgrove/sdk/embed is the internal FG runtime bridge. The canonical behavior and test mapping are in docs/product-specs/sdk.md.

版本与发布记录

@funnelsgrove/sdk 共发布 2 个版本,首次发布于 2026/09/17;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.4.0latest2026/09/171 个月前
0.0.0-bootstrap.0bootstrap2026/09/171 个月前

关于 @funnelsgrove/sdk 的常见问题

@funnelsgrove/sdk 是什么?

Embed FunnelsGrove paywalls in web applications

如何安装 @funnelsgrove/sdk?

在项目目录运行 npm install @funnelsgrove/sdk,或使用 pnpm add / yarn add / bun add。

@funnelsgrove/sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@funnelsgrove/sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@funnelsgrove/sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@funnelsgrove/sdk 可以商用吗?

@funnelsgrove/sdk 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@funnelsgrove/sdk 的下载量有多少?

根据 npm 官方下载统计,@funnelsgrove/sdk 在 2026/10/16 – 2026/11/14 这 30 天内被下载 4,939 次,日均约 165 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@funnelsgrove/sdk 还在维护吗?

最新版本 0.4.0 发布于 2026/09/17(1 个月前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/09/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。