@keeganrelume/partner-embed

中文文档
1.0.0-beta.0发布于 2026/11/01UNLICENSEDTypeScriptES Module零依赖

Frontend SDK for Relume partners: put the Relume builder on your page with one call and a few event handlers.

原始使用文档
文档目录7 节
  1. Install
  2. Quickstart
  3. What it does for you
  4. Relume.init(target, publishableKey, options?)
  5. Events
  6. Methods
  7. Developing

@keeganrelume/partner-embed

The frontend SDK for Relume partners. One call puts the Relume builder on your page; a few event handlers tie it to your wallet. You never touch the iframe or postMessage.

Interim package name. This is published as @keeganrelume/partner-embed until the @relume npm scope is recovered, then as @relume/partner-embed. The API won't change; only the import path will.

It is the browser side of the Relume Partner Protocol v1 (sections 4 and 11). Pair it with @keeganrelume/partner-node on your backend, which mounts the session route this SDK calls.

Install

npm install @keeganrelume/partner-embed
import { Relume } from '@keeganrelume/partner-embed';

Or with a script tag, which defines window.Relume:

<script src="https://cdn.jsdelivr.net/npm/@keeganrelume/[email protected]"></script>

No runtime dependencies. About 6 KB minified.

Quickstart

const relume = Relume.init('#relume', 'pk_live_…');

relume.onTopUp(async ({ required, balance }) => {
  await openCheckout(required - (balance ?? 0)); // your checkout
  relume.refreshCredits(); // the builder re-reads the balance
});
relume.onCreditsChanged(({ balance }) => setHeaderBalance(balance));
relume.onExport(({ siteId, downloadUrl }) => toast('Your site is ready'));
relume.onClose(() => router.back());
relume.onError(({ code, message }) => report(code, message));

The builder fills #relume, so give it a size (for example height: calc(100vh - 64px)). Below 640px wide it covers the whole viewport instead; pass fullScreenOnMobile: false to keep it in the container. Your page needs a <meta name="viewport" content="width=device-width"> for phones to report their real width.

examples/index.html is a whole partner page.

What it does for you

  • Creates the iframe on https://embed.relume.ai/?pk=… and sizes it.
  • Calls your session route (GET /relume/session, mounted by @keeganrelume/partner-node) whenever the builder asks: when it opens, before the session expires and after a 401. The builder renews without a reload.
  • Accepts messages only from the builder's own window on the embed origin, and posts only to that origin. Messages from other scripts or frames are ignored.
  • Agrees a protocol version with the builder, so either side can change its messages without breaking the other.
  • Checks your page's origin against the publishable key's allowed origins. The browser refuses the frame on any other origin, and the frame can't say why, so the SDK fires onError({ code: 'origin_not_allowed' }) and removes it.

Relume.init(target, publishableKey, options?)

target is a selector or an element. Throws a TypeError if it matches nothing or the key isn't a pk_test_…/pk_live_… key.

OptionDefaultWhat it does
sessionUrl/relume/session on your pageYour session route. On another origin it is fetched with credentials, so its CORS must allow your page's origin exactly (never *).
fullScreenOnMobiletrueCover the viewport below 640px.
embedUrlhttps://embed.relume.aiThe builder's host. Relume gives you staging's (https://embed-staging.relume.ai).
apiUrlinferred from embedUrlRelume's API, for the allowed-origins check. Known for Relume's hosts; without one the check is skipped and the builder's own applies.

Events

Each on… method adds a listener and returns a function that removes it.

EventPayloadWhen
onTopUp{ required, balance }A charge was declined. required is the action's price in your credits.
onCreditsChanged{ balance }The balance the builder shows changed. Not fired when your wallet didn't answer.
onExport{ siteId, exportId, downloadUrl }An export is ready.
onClosenoneThe user closed the builder.
onError{ code, message }The builder couldn't start or carry on. Logged to the console when nobody listens.

Error codes: session_failed, user_deactivated, user_suspended, partner_suspended, origin_not_allowed, test_cap_reached and charge_failed (protocol section 11). New codes may be added; treat an unknown one like session_failed.

A handler that throws is logged and doesn't stop the others.

Methods

  • open({ site }) opens one of the user's sites (a siteId from the partner API or onExport). The builder reloads on that site.
  • refreshCredits() asks the builder to re-read the balance from your wallet (credits.get), then fires onCreditsChanged if it changed. Call it after a top-up.
  • destroy() removes the iframe and every listener, and stops any pending session request. The instance does nothing afterwards; call Relume.init again to show the builder again.

Developing

npm ci
npm run typecheck
npm test            # unit tests (happy-dom) and the example's size
npm run test:dist   # builds, then loads the ESM and script-tag output

The postMessage messages live in src/protocol.ts and mirror frontend/base/embed/embed_protocol.ts in the Relume app. Change both together.

Publishing: npm publish --tag latest from this folder (it runs all of the above first).

版本与发布记录

@keeganrelume/partner-embed 共发布 2 个版本,首次发布于 2026/11/01;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.0.0-beta.0latest2026/11/012 天前
0.0.0-stage2026/11/012 天前

关于 @keeganrelume/partner-embed 的常见问题

@keeganrelume/partner-embed 是什么?

reume合作伙伴的前端SDK:将reume构建器与一个调用和几个事件处理程序放在您的页面上。

如何安装 @keeganrelume/partner-embed?

在项目目录运行 npm install @keeganrelume/partner-embed,或使用 pnpm add / yarn add / bun add。

@keeganrelume/partner-embed 支持 TypeScript 吗?

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

@keeganrelume/partner-embed 支持 ESM 还是 CommonJS?

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

@keeganrelume/partner-embed 可以商用吗?

@keeganrelume/partner-embed 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@keeganrelume/partner-embed 还在维护吗?

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