UNPKG

beckn-lightweight

Version:

Lightweight Node.js utilities to integrate Beckn protocol into existing BPPs

27 lines (21 loc) 1.74 kB
const express = require("express"); const createForwardingHandlerFactory = require("./handlers/createForwardingHandler"); function initBecknForwarder(app, config = {}) { app.use(express.json()); const createForwardingHandler = createForwardingHandlerFactory(config); app.post("/search", createForwardingHandler({ messageKey: "intent", callbackAction: "on_search" })); app.post("/select", createForwardingHandler({ messageKey: "order", callbackAction: "on_select" })); app.post("/init", createForwardingHandler({ messageKey: "order", callbackAction: "on_init" })); app.post("/confirm", createForwardingHandler({ messageKey: "order", callbackAction: "on_confirm" })); app.post("/status", createForwardingHandler({ messageKey: "order_id", callbackAction: "on_status" })); app.post("/track", createForwardingHandler({ messageKey: "order_id", callbackAction: "on_track" })); app.post("/cancel", createForwardingHandler({ messageKey: "order", callbackAction: "on_cancel" })); app.post("/support", createForwardingHandler({ messageKey: "ref_id", callbackAction: "on_support" })); app.post("/rating", createForwardingHandler({ messageKey: "id", callbackAction: "on_rating" })); app.post("/feedback", createForwardingHandler({ messageKey: "feedback_form", callbackAction: "on_feedback" })); app.post("/update", createForwardingHandler({ messageKey: "order", callbackAction: "on_update" })); app.post("/issue", createForwardingHandler({ messageKey: "issue", callbackAction: "on_issue" })); app.post("/issue_status", createForwardingHandler({ messageKey: "issue_id", callbackAction: "on_issue_status" })); console.log("✅ Beckn forwarder initialized with config:", config); } module.exports = { initBecknForwarder };