@railbridgeai/merchant-sdk
v0.1.1
Published
RailBridge SDK for merchant API protection and webhook verification
Downloads
317
Maintainers
Readme
@railbridgeai/merchant-sdk
Merchant-first server SDK for RailBridge.
Goal:
- Protect paid routes with one middleware.
- Keep merchant business logic unchanged.
- Verify webhook signatures with one helper.
Install
npm install @railbridgeai/merchant-sdkRunnable repo example:
Repo contributor note:
- In this repository,
facilitatorconsumes the SDK through a localfile:dependency. - Running
npm --prefix facilitator installalso createspackages/node_modules -> facilitator/node_modulesfor local dependency resolution. - Use the facilitator npm scripts for local smoke tests; you do not need a separate
npm installinsidepackages/server-sdkfor the linked-package path.
Release workflow:
- Bump the version in
packages/server-sdk/package.json. - Push a tag like
sdk-v0.1.0-beta.1. - GitHub Actions publishes the package to the npm registry as
public.
Quick Start (Express)
import express from "express";
import { createRailbridgeFromEnv } from "@railbridgeai/merchant-sdk";
const app = express();
const rb = createRailbridgeFromEnv(process.env);
const start = async () => {
await rb.protectExpress(
app,
{
apiId: "premium_api",
method: "GET",
path: "/api/premium",
},
async (req, res) => {
// Keep business logic here.
const payload = await buildPremiumPayload(req.user);
res.json(payload);
},
);
app.listen(4021);
};
start().catch(console.error);Alternative env-first bootstrap:
import { createRailbridge } from "@railbridgeai/merchant-sdk";
const rb = createRailbridge({
apiKey: process.env.RB_API_KEY,
environment: "testnet",
});In the normal hosted RailBridge flow, merchants should only need:
RB_API_KEYRB_ENV(local,testnet, orlive)
The SDK chooses RailBridge-managed URLs automatically from the environment.
Webhook Verification
import express from "express";
import { createRailbridgeFromEnv } from "@railbridgeai/merchant-sdk";
const app = express();
const rb = createRailbridgeFromEnv(process.env);
// Keep raw payload for signature verification.
app.use("/webhooks/railbridge", express.text({ type: "application/json" }));
app.post(
"/webhooks/railbridge",
rb.webhooks.express({
secret: process.env.RB_WEBHOOK_SECRET,
onEvent: async (event) => {
// idempotent async processing
console.log("railbridge webhook", event.type, event.id);
},
}),
);Merchant Env Vars
RB_API_KEY=rb_...
RB_WEBHOOK_SECRET=whsec_...
RB_ENV=testnetAdvanced overrides:
RB_MERCHANT_OS_URL=https://api.testnet.railbridge.ai
RB_FACILITATOR_URL=https://facilitator.testnet.railbridge.aiOnly use these overrides if:
- you are developing against local/self-hosted RailBridge services
- RailBridge support asked you to target a non-standard endpoint
API Summary
createRailbridge(config)createRailbridgeFromEnv(process.env)client.protect(routeConfig)-> Express middlewareclient.protectExpress(app, routeConfig, handler)-> lowest-friction Express helperclient.resolveRequirements(...)client.webhooks.verify(...)client.webhooks.express(...)
Notes
- This SDK abstracts payment requirement resolution and verify/settle wiring.
- Merchant handlers should only contain business logic.
- Do not call RailBridge internal endpoints (
/v1/internal/*) from merchant apps.
