Data feed quickstarts
Node.js, Express, Next.js
@waforge/feed for Node.js 18 and newer, with zero dependencies: Express middleware, a Fetch API handler for Next.js and edge-style runtimes, and signature helpers for any other framework.
1. Install #
The package is not on npm. Download node.zip next to your project and install it from the folder:
unzip node.zip # creates waforge-node/
npm install ./waforge-nodeWAFORGE_FEED_SECRET=wf_fs_...
WAFORGE_FEED_SECRET_PREVIOUS= # optional, during a rotation
WAFORGE_KEY_ID=fs_...
WAFORGE_TENANT=wf_tn_...
WAFORGE_VERIFY=wfv_...2. Write your handlers #
You provide plain async functions. Return null when something does not exist; the package answers 404. Every handler is optional: the manifest only declares the ones you provide.
| Handler | Receives | Returns |
|---|---|---|
searchCatalog | { q, limit, cursor, category, lang } | { items, next_cursor } or an array |
getProduct | { id } | Product or null |
getProductBySku | { sku } | Product or null |
availability | { items } (1 to 50) | [{ product_id, available, quantity_available, status }] |
orderStatus | { order_number, phone } | Order, or null if missing or the phone differs |
deliveryZones, bookingSlots, businessHours, faqs, quote | see reference | Optional |
3a. Express #
const express = require('express');
const { waforgeFeed, wellKnown } = require('@waforge/feed');
const db = require('./db'); // your data layer
const last9 = (v) => String(v || '').replace(/\D/g, '').slice(-9);
const feedOptions = {
secret: process.env.WAFORGE_FEED_SECRET,
previousSecret: process.env.WAFORGE_FEED_SECRET_PREVIOUS,
keyId: process.env.WAFORGE_KEY_ID,
tenant: process.env.WAFORGE_TENANT,
verification: process.env.WAFORGE_VERIFY,
business: { name: 'My Shop', currency: 'QAR', prices_include_tax: true, timezone: 'Asia/Qatar', default_locale: 'en', locales: ['en', 'ar'] },
handlers: {
async searchCatalog({ q, limit }) {
const rows = await db.query('SELECT * FROM products WHERE name LIKE ? LIMIT ?', [`%${q}%`, limit]);
return { items: rows.map(toProduct) };
},
async getProduct({ id }) {
const [row] = await db.query('SELECT * FROM products WHERE id = ?', [id]);
return row ? toProduct(row) : null;
},
async availability({ items }) {
return Promise.all(items.map(async (i) => {
const [row] = await db.query('SELECT stock FROM products WHERE id = ?', [i.product_id]);
const qty = row ? row.stock : null;
const status = qty === null ? 'unknown' : qty <= 0 ? 'out_of_stock' : qty <= 3 ? 'low_stock' : 'in_stock';
return { product_id: i.product_id, available: qty !== null && qty >= i.quantity, quantity_available: qty, status };
}));
},
async orderStatus({ order_number, phone }) {
const [o] = await db.query('SELECT * FROM orders WHERE number = ?', [order_number]);
if (!o || last9(phone).length < 9 || last9(o.phone) !== last9(phone)) return null; // same 404 for both
return { order_number: o.number, status: o.status, status_label: o.status, placed_at: new Date(o.created_at).toISOString() };
},
},
};
function toProduct(p) {
const price = Number(p.price).toFixed(2); // money is a decimal string
return { id: String(p.id), name: p.name, currency: 'QAR', price, url: `https://shop.example.com/p/${p.slug}`,
variants: [{ id: String(p.id), sku: p.sku, price, available: p.stock > 0 }] };
}
const app = express();
app.get('/.well-known/waforge.json', wellKnown(feedOptions));
app.use(waforgeFeed(feedOptions)); // BEFORE express.json(): the signature needs the raw body
app.use(express.json());
// ... your other routes
app.listen(3000);The middleware answers everything under /waforge (change it with basePath) and calls next() for any other path. Behind a proxy, add publicBaseUrl: 'https://shop.example.com/waforge'.
3b. Next.js (App Router) #
// waforge.config.js (server only)
export const feedOptions = {
secret: process.env.WAFORGE_FEED_SECRET,
keyId: process.env.WAFORGE_KEY_ID,
tenant: process.env.WAFORGE_TENANT,
verification: process.env.WAFORGE_VERIFY,
publicBaseUrl: 'https://shop.example.com/waforge',
business: { name: 'My Shop', currency: 'AED', timezone: 'Asia/Dubai' },
handlers: { /* same handlers as in the Express example */ },
};// app/waforge/[...path]/route.js
import { createFetchHandler } from '@waforge/feed';
import { feedOptions } from '../../../waforge.config';
export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';
const handler = createFetchHandler(feedOptions);
export const GET = handler;
export const POST = handler;// app/.well-known/waforge.json/route.js
import { createFetchHandler } from '@waforge/feed';
import { feedOptions } from '../../../waforge.config';
const handler = createFetchHandler({ ...feedOptions, basePath: '/.well-known/waforge.json' });
export const GET = handler; // the base path itself answers with the public manifestThe zip contains this example with a Prisma mapping in examples/nextjs. For the Pages Router, use waforgeFeed() in pages/api/waforge/[...path].js with export const config = { api: { bodyParser: false } } and basePath: '/api/waforge'.
3c. Fastify, Koa, Hono or anything else #
const { verifyWaForgeSignature } = require('@waforge/feed');
// rawBody: the exact bytes received (Buffer or string), before JSON parsing
const ok = verifyWaForgeSignature(rawBody, request.headers['waforge-signature'],
[process.env.WAFORGE_FEED_SECRET, process.env.WAFORGE_FEED_SECRET_PREVIOUS],
{ method: request.method, pathAndQuery: request.url }); // exact path + query as received
if (!ok) return reply.code(401).send({ code: 'unauthorized' });verifyWaForgeSignature checks the HMAC and the 300 second window. It does not block replays by itself: waforgeFeed() and createFetchHandler() do, with an in-memory map per process.
4. Test it #
// node test-feed.mjs (with your server running on :3000)
import { createRequire } from 'node:module';
const { signatureHeader } = createRequire(import.meta.url)('@waforge/feed');
const path = '/waforge/catalog/search?q=card&limit=3';
const header = signatureHeader(process.env.WAFORGE_FEED_SECRET, process.env.WAFORGE_KEY_ID,
Math.floor(Date.now() / 1000), 'GET', path, '');
const res = await fetch('http://localhost:3000' + path, { headers: { 'WaForge-Signature': header } });
console.log(res.status, await res.json());Expect 200 and an envelope. Then run the feed checker from the dashboard against your public URL. The kit's own tests: cd waforge-node && npm test.
5. Push changes (recommended) #
const { sendEvent } = require('@waforge/feed');
await sendEvent('stock.changed', { product_id: 'p1', quantity_available: 0, status: 'out_of_stock' },
{ secret: process.env.WAFORGE_FEED_SECRET, keyId: process.env.WAFORGE_KEY_ID });
// resolves true on a 2xx; 5 s timeout