@zenuinebit/eway-bill
v0.1.0
Published
E-way bill JSON payload builder and checks: vehicle number, validity, value threshold.
Readme
@zenuinebit/eway-bill
Builds the JSON for generating an e-way bill from an invoice, and checks the inputs the portal is strict about: GSTINs, PIN codes, HSN codes, vehicle numbers and distance. Builds on @zenuinebit/gst-report and @zenuinebit/address-india.
Check before you rely on it. Field names and codes follow the NIC e-way bill JSON as commonly documented. The portal and the rules (value limit, validity, exemptions) change, and differ by state and goods. Validate the payload with the official tools, and treat the result as plain data you can adjust. It does not replace your accountant.
import { buildEwayBill, toEwayJson, isValidVehicleNumber, validityDays, validUntil, requiresEwayBill } from "@zenuinebit/eway-bill";
const bill = buildEwayBill({
invoice: { // the same SaleInvoice used by gst-report
number: "INV/2025-26/0042",
date: "2025-04-10",
placeOfSupply: "Karnataka",
buyer: { gstin: "29ABCPD1234E1ZA", name: "Bengaluru Traders" },
lines: [{ description: "Tea 250g", hsn: "0902", quantity: 100, unitPrice: 10_000, taxRate: 5 }],
},
from: { gstin: "27AAPFU0939F1ZV", name: "ZenuineBit Foods", address1: "1 Main Rd", place: "Pune", pincode: "411001" },
to: { gstin: "29ABCPD1234E1ZA", name: "Bengaluru Traders", address1: "5 MG Rd", place: "Bengaluru", pincode: "560001" },
transport: { distanceKm: 840, vehicleNo: "MH 12 AB 1234" },
unitByHsn: { "0902": "KGS" }, // unit per HSN, default "NOS"
});
await fs.writeFile("ewb.json", toEwayJson(input));
validityDays(840); // 5 (1 day per 200 km for ordinary cargo)
validUntil("2025-04-10", 840); // "2025-04-15"
requiresEwayBill(7_500_000, 5_000_000); // you pass your own limit, in minor unitsWhat it does
- Works out values with the same GST maths as
gst-report: CGST+SGST within a state, IGST between states. Values are in rupees, datesdd/MM/yyyy, PIN codes and HSN codes as numbers. fromStateCodecomes from the GSTIN.actFromStateCodecomes from thestateyou give for the address, so dispatch from another state is supported. For an unregistered buyer, usegstin: "URP"and give astate.- Road transport needs a vehicle number or a transporter GSTIN (Part A only). Rail, air and ship need the transport document number and date.
- Throws a clear message for a bad GSTIN, PIN, HSN (4 to 8 digits), vehicle number or distance.
toBulkJson(inputs, version)wraps several bills; pass the version string the portal currently asks for.
Not included: calling the e-way bill API (authentication, generate, update vehicle, cancel, extend), consolidated e-way bills, cess, other charges and round-off, bill-to/ship-to sub-types beyond the codes you pass, and exemption rules. The value limit is not assumed: pass it to requiresEwayBill.
