npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@relume_io/partner-node

v2.6.0

Published

Server SDK for Relume partners: answer Relume's signed calls and serve builder sessions without writing any cryptography.

Readme

@relume_io/partner-node

The server SDK for Relume partners. It answers Relume's signed calls and serves builder sessions, so your backend never writes any cryptography.

Your page needs @relume_io/partner-embed. The partner docs have quickstarts, guides and the partner API reference. For Go, use github.com/relumetech/partner-sdk/go.

Install

npm install @relume_io/partner-node

Node 20 or later, or any runtime with fetch and Web Crypto (Cloudflare Workers, Bun, Deno, Next.js edge). No runtime dependencies. Install the same version as @relume_io/partner-embed.

Quickstart (Express)

import express from 'express';
import { Relume } from '@relume_io/partner-node';

const relume = Relume.init<express.Request>({
  secretKey: process.env.RELUME_SECRET_KEY!,
});

// Who is signed in, for the builder's GET /relume/session
relume.getUserIdFromRequest((req) => req.session?.userId ?? null);

relume.onGetUser(async (userId) => {
  const user = await db.users.find(userId);
  return user ? { name: user.name, email: user.email } : null; // null → 404
});
relume.onGetCredits(async (userId) => ({
  balance: await wallet.balance(userId),
}));
relume.onChargeCredits(
  async ({ userId, chargeId, partnerCredits }) =>
    wallet.debit(userId, partnerCredits, { ref: chargeId }), // → { ok, balance }
);
relume.onReverseCharge(
  async ({ userId, reversalId, chargeId, partnerCredits }) =>
    wallet.credit(userId, partnerCredits, {
      ref: reversalId,
      reverses: chargeId,
    }),
);

const app = express();
app.use('/relume', relume.express()); // before express.json()
app.use(express.json());

When a decline isn't about the balance (no subscription, a payment the user has to confirm), say why: return { ok: false, balance, reason, metadata } from onChargeCredits, and the embed's onTopUp gets reason and metadata untouched. reason is a code you choose, 1 to 64 characters of letters, digits and _.:-; metadata is a JSON object of at most 1 KB. The SDK throws on either past its limits, so you find out in development. metadata passes through Relume's servers and the builder iframe: never put a secret in it, send an id your page can look up.

Endpoint URL

On the Partners page in Relume, set each environment's endpoint URL to https://<your backend>/relume/calls.

  • Relume's servers call it, so it must be reachable from the internet. On localhost, use a tunnel such as cloudflared tunnel --url http://localhost:3000 or ngrok http 3000.
  • Give test and live their own URLs, each served with that environment's secret key. Live URLs must be https.
  • The builder can't open for a new user until the endpoint answers: Relume calls user.get before their first session.

Routes

| Route | Called by | Does | | --------------------- | ------------- | ---------------------------------------------------------------------------------------------------------- | | GET /relume/session | the embed SDK | Finds the user with getUserIdFromRequest, calls POST /sessions, returns { clientSecret, expiresAt }. | | POST /relume/calls | Relume | Verifies Relume-Signature, runs your callback for the call's type, checks what it returns. |

relume.express() answers /session and /calls under its mount path (/relume/session and /relume/calls when mounted at the root), and passes everything else on. relume.fetchHandler answers any path ending in /session or /calls.

| Situation | Answer | | ----------------------------------------------------------- | ------------------------------------------------------------------------------ | | Bad or missing signature, or a timestamp over 5 minutes off | 401 invalid_signature; your callback isn't called | | Unknown type, or no callback registered | 400 unsupported_call_type | | A body that isn't valid for its type | 400 invalid_request | | environment isn't your secret key's | 400 environment_mismatch; your callback isn't called | | onGetUser returns null | 404 user_not_found | | onChargeCredits returns { ok: false } | 402 insufficient_credits, with balance, reason and metadata when given | | A decline's reason or metadata past its limits | 500 internal_error; onHandlerError says which | | A callback throws, or returns a bad shape | 500 internal_error; onHandlerError gets the error | | Session route: no Relume-Embed: 1 header | 400 embed_header_missing | | Session route: Sec-Fetch-Site: cross-site | 403 cross_site_request | | Session route: nobody signed in | 401 not_signed_in | | Session route: Relume unreachable or timed out | 502 session_failed, or 504 on a timeout | | Session route: POST /sessions refused | Relume's status and { error }, e.g. 403 user_deactivated |

CORS preflights are left to your app: express() passes them to the next middleware, and fetchHandler answers 204 with no CORS headers, so put your CORS handling in front of it. If your page is on another origin from this backend, pass sessionUrl to the embed SDK, and allow your page's exact origin, with credentials and the Relume-Embed header, on the session route. Never answer with * and never echo the request's Origin.

Callbacks

  • getUserIdFromRequest(request) → userId | null: read the user from your own session. Never take a user id from the query string or body. Pass your framework's request type to Relume.init<…> to type request.

The four on… callbacks below answer Relume's calls. Each gets a second argument, { type, environment, requestId }. environment is always your secret key's: 'test' or 'live'. Quote requestId to Relume support.

  • onGetUser(userId) → { name?, email?, avatarUrl? } | null: name at most 200 characters, email a valid address, avatarUrl an https URL. null for a user you don't know.
  • onGetCredits(userId) → { balance }: a whole number of your own credits, zero or more.

onChargeCredits(charge) → { ok, balance? }

  • Debit partnerCredits only. relumeCredits is what Relume charges you. Never debit it from the user.
  • Idempotent on chargeId. Relume retries a charge with the same chargeId. Debit at most once, and answer a repeat with the same result.
  • Return ok: false when the user can't afford it. The builder then asks them to top up.
  • If you throw or time out, Relume doesn't do the work, and sends a reversal for that chargeId.
  • A build of several pages is one charge, with pageIds instead of pageId and both prices covering every page. Debit it like any other.

onReverseCharge(reversal) → { balance? } | void

  • Credit back the reversal's partnerCredits only, at most once per reversalId. A reversal can cover part of a charge.
  • If chargeId names a charge you never debited, credit nothing, return normally, and record that chargeId as declined. If the charge reaches you later, onChargeCredits must return ok: false without debiting.
  • chargeId is absent for a staff refund. reason is work_failed, charge_unknown or staff_refund; accept new values.
  • Accept reversals for users you have since deactivated.

Other frameworks

relume.fetchHandler is a (Request) => Promise<Response>.

Next.js (app/relume/[route]/route.ts):

import { relume } from '@/lib/relume';

export const GET = relume.fetchHandler;
export const POST = relume.fetchHandler;

Hono:

app.all('/relume/*', (c) => relume.fetchHandler(c.req.raw));

Cloudflare Workers: a Worker reads its secrets from env on each request, so create the client there (Relume.init is cheap and holds no connection):

export default {
  fetch(request: Request, env: Env) {
    const relume = Relume.init<Request>({ secretKey: env.RELUME_SECRET_KEY });
    // …register getUserIdFromRequest and the four callbacks…
    return relume.fetchHandler(request);
  },
};

Anything else: call relume.handleCall({ rawBody, signatureHeader, requestId }) and relume.handleSession(request). Each returns { status, headers, body }. Pass handleSession the fetch Request, the Node request, or an object with headers.

Raw bodies: the signature covers the raw bytes, so a parsed body never verifies. Mount relume.express() before express.json(), or give it express.raw({ type: 'application/json' }). Add nothing that parses the body in front of fetchHandler. If a parser got there first, the call is answered 500 and onHandlerError says why.

Options

Relume.init({
  secretKey: 'sk_test_…', // required; sk_test_… or sk_live_…
  apiBaseUrl: 'https://…', // default: production's; http only for localhost
  apiTimeoutMs: 15_000, // per partner API request attempt
  maxRetries: 2, // retries for 429s, 5xx answers and failed connections
  fetch, // custom fetch for partner API requests
  onHandlerError: (error, info) => logger.error({ error, ...info }),
});

Relume.init throws for a missing key, or one that isn't sk_test_… or sk_live_…. It returns a new client every time, so test and live clients can run side by side.

Calling the partner API

Every partner API endpoint has a typed method.

const { clientSecret } = await relume.sessions.create({ userId: '42' });

const user = await relume.users.get('42'); // { userId, status, siteCount, … }
await relume.users.deactivate('42');
await relume.users.reactivate('42');

const { siteId } = await relume.sites.create('42', { name: 'Bloom Florist' });
const site = await relume.sites.get(siteId); // { name, publish, lastExport, … }
await relume.sites.update(siteId, { name: 'Bloom' }); // the renamed site
await relume.sites.delete(siteId); // { siteId, deleted: true }
const exported = await relume.exports.get(siteId, exportId); // from the embed's onExport, or site.lastExport

const entry = await relume.ledger.get('ch_…'); // with partnerResponse

const { data, creditRate, creditUnit } = await relume.prices.get();
// data: [{ action, partnerCredits (null when unpriced), relumeCredits, creditRate }]
// creditRate: your default credits per Relume credit, or null
// creditUnit: { singular: 'coin', plural: 'coins', iconUrl? }
  • prices.get() returns your prices, your default creditRate and creditUnit: what the builder calls your credits, and the icon it shows beside amounts. prices.list() returns the prices alone. An action with a credit rate (set on the Partners page) costs relumeCredits times it.
  • A user who has never opened the builder has no Relume account, so sites.list and sites.create answer user_not_found. Before creating a site for them, call sessions.create({ userId }): it creates the account.
  • site.publish is null until the site is first published. Then status is published while it's live at url (its custom domain, or else its preview URL), publishedAt is the last publish, and hostingStatus is its hosting plan's: active, past_due, canceled or none.
  • sites.delete takes a site published on its preview URL offline: check publish.status first and warn the user. A site with a custom domain, in any state, answers site_has_custom_domain (the user removes the domain in the builder first); otherwise one whose hostingStatus is active or past_due answers site_has_hosting_plan (the plan must be canceled first). A suspended user's sites can't be renamed or deleted (user_suspended).
  • site.lastExport is the most recent export the user made in the builder. Once it's ready, its downloadUrl works for 10 minutes; exports.get(siteId, exportId) signs a new one. An export is expired once a newer one replaced it, and while its owner is deactivated or suspended.
  • sites.create isn't idempotent, and a repeated sites.delete answers site_not_found, so those two retry only a 429.

Each method throws a RelumeError when the API refuses, with status, code (safe to switch on) and requestId (quote it to Relume support):

try {
  await relume.users.reactivate('42');
} catch (error) {
  if (error instanceof RelumeError && error.code === 'user_suspended') {
    // Only Relume staff can reactivate this user.
  }
}

Lists

sites.list, ledger.list and usage.get follow the cursor for you: iterate items with for await, pages with .pages(), or collect them with .toArray().

To reconcile your wallet, poll the ledger from the cursor you stored last time. An entry appears again when its status changes, so upsert on id:

const entries = relume.ledger.list({ after: await loadCursor() });
for await (const page of entries.pages()) {
  await upsertEntries(page.data);
  await saveCursor(page.nextCursor); // checkpoint after each page
}

After a plain for await, entries.nextCursor is the cursor of the last page you finished, so breaking out early never skips an entry. Site lists can't be polled this way, because new sites sort to the front: list them from the beginning each time.

Retries

A 429 is retried after its Retry-After, unless that's over a minute. A 5xx (except 501 and 505) or a failed connection is retried with exponential backoff. maxRetries (default 2) sets how many retries follow the first attempt. The session route makes one attempt, because a browser is waiting.

Checking your endpoint

Before going live, run the conformance checker against your test endpoint. It works on any endpoint, whether or not it uses this SDK:

RELUME_SECRET_KEY=sk_test_… npx @relume_io/partner-node check \
  --url https://partner.example/relume/calls --user 42

It calls your endpoint the way Relume does, and checks signatures, environments, idempotency on chargeId and reversalId, the unknown-charge rule and the session route's refusals. The partner docs list every check.

  • --user must be a user your wallet knows, holding at least 2 credits. The check charges them 2 and reverses everything it charged.
  • Pass the key in RELUME_SECRET_KEY, not --secret-key: a key on the command line lands in shell history and CI logs.
  • It finds the session route next to a --url ending in /calls; otherwise pass --session-url. If a login guards that route, give the check a test user's cookie in RELUME_SESSION_HEADERS (one Name: value a line) or with --session-header "Cookie: …" (repeatable). Prefer the variable: a cookie on the command line leaks like a key does.
  • It exits 0 only when every check passes, so you can run it in CI. A live key is refused unless you pass --live, because the check moves real credits.

Signing helpers

For your own tests, or another runtime: verifySignature, signCall, parseSignatureHeader and computeSignature. They pass the protocol's test vectors.

License

MIT