npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ondc-node

v1.1.6

Published

Integrate ONDC in your JavaScript applications easily.

Downloads

69

Readme

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 Function | Callback Function | Other Function | |:----------------:|:-------------------------:|:-------------------------:| | search | on_search | get_cancellation_reasons |
| select | on_select | cancellation_reasons |
| init | on_init | get_return_reasons |
| confirm | on_confirm | return_reasons | | status | on_status | get_rating_categories |
| track | on_track | rating_categories |
| cancel | on_cancel | get_feedback_categories |
| update | on_update | feedback_categories |
| rating | on_rating | get_feedback_form |
| support | on_support | feedback_form |

Content