1.1.6 • Published 2 years ago

ondc-node v1.1.6

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

ondc-node

This library can be used to integrate ONDC in JavaScript based applications.

Package is developed in TypeScript and will work with Node.Js & other JavaScript based stacks.

Introduction 👋

ONDC stands for Open Network for Digital Commernce.

ONDC is an Open Network which makes it easy for any buyer and seller to engage in a transactions.

LOGO

How to install? 👀

npm i ondc-node --save

☝️ Using to call APIs

Initialization

const ondc = require('ondc-node');
const instance = new ondc.ONDC({
    host: "http://localhost:5000",
    bapId: "bap.com",
    bapUri: "https://bap.com/beckn",
    bppId: "bpp.com",
    bppUri: "https://bpp.com/beckn",
    country: "IND",
    city: "std:080",
    ttl: "P1M"
});

Search an Item

const response = await instance.search({
        "item": {
            "descriptor": {
                "name": "ABC Aata"
            }
        },
        "fulfillment": {
            "end": {
                "location": {
                    "gps": "12.4535445,77.9283792"
                }
            }
        }
    })

✌️ Using as Express Middleware

const ONDC = require('ondc-node');
const express = require("express");

const app = express();
app.use(express.json());

app.use(ONDC.Middleware({"on_search": onSearchHandler, "init": initHandler}));

🤩 Effortless Authorization 🔐 with ONDC

You can use ondc.createAuthorizationHeader function to create Authorization header signature.

    const ondc = require('ondc-node');
    // Private key & Public keys are must for Auth to work
    const instance = new ondc.ONDC({
        host: "http://localhost:5000",
        bapId: "bap.com",
        bapUri: "https://bap.com/beckn",
        bppId: "bpp.com",
        bppUri: "https://bpp.com/beckn",
        country: "IND",
        city: "std:080",
        ttl: "P1M",
        publicKey: "<Public Key>",
        privateKey: "<Private Key>",
        uniqueKey: "dev.test.ondc-node.com",
        subscriberId: "<Gateway Address>",
    });

    let body = {
        "item": {
            "descriptor": {
                "name": "ABC Aata"
            }
        },
        "fulfillment": {
            "end": {
                "location": {
                    "gps": "12.4535445,77.9283792"
                }
            }
        }
    };
    // apiKey is sent in Authorization Header
    instance.apiKey = await instance.createAuthorizationHeader(body);
    const response = await instance.search(body)

Next function is ondc.verifyHeader which is used to verify the Authorization header signature with senders Public Keys.

You can fetch the public key from Gateway using /lookup call.

    const publicKey = "<Public key of Sender>";

    // verifyHeader return true/false
    let output = await ondc.verifyHeader(req.header.Authorization, {
        signing_public_key: publicKey
    }, req.body);

    console.log(`output: ${output}`);

Reference 📚

Functions Covered 🚀

Async FunctionCallback FunctionOther Function
searchon_searchget_cancellation_reasons
selecton_selectcancellation_reasons
initon_initget_return_reasons
confirmon_confirmreturn_reasons
statuson_statusget_rating_categories
trackon_trackrating_categories
cancelon_cancelget_feedback_categories
updateon_updatefeedback_categories
ratingon_ratingget_feedback_form
supporton_supportfeedback_form

Content

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago