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 🙏

© 2026 – Pkg Stats / Ryan Hefner

idempotent-api-middleware

v1.1.1

Published

<div align="center" id="top"> <img src="https://www.fr8.in/images/logo.png" alt="Idempotent-api-middleware" />

Readme

 

:About

I am an express js API middleware .I will make your API request Idempotent by restricting duplicate API request and store the requestObject , responseObject and status of the request in database through Hasura Graphql.

:Features

  • create an active token for each post request
  • validate token on each request

:Configuration

import express from 'express'
import { GqlConfig  } from '../validator'
const app = express()

const gqlConfig: GqlConfig = new GqlConfig('xxx')
let headers = { 'xxx': 'xxx' }
gqlConfig.setHeaders(headers)

gqlConfig.getActiveToken(ref_id:number ,process:string)
app.use(gqlConfig.validateToken)

:Technologies

The following tools were used in this project:

:Requirements

API Convention

Just add /secured in your API uri
eg : https://127.0.0.1/secured/book/now

  • The API uri that contains "/secured" will be validated for idempotency

  • Before hitting the secured API call getActiveToken(ref_id:number ,process:string ) and get the unique token for the API.

  • While hitting the secured API set the header 'idempotent-token' and 'process'

eg:

let process = 'PAY_NOW'
let unique_token:string = getActiveToken(ref_id:number ,process:string )

curl --location --request POST 'http://localhost:/order/now'
--header 'Content-Type: application/json'
--header 'idempotent-token: unique_token'
--header 'process: PAY_NOW'
--data-raw '{ "member_id": 3018, "amount": 10, "created_by": "[email protected]" }'

Database Configuration

Make your Database like this

  • Schema : transaction

  • Table : token

    • Fields :
      id :In---> auto-generated id
      ref_id :Int ---> process respective to transaction (eg: bank_account_no,employee_id)
      token :String ---> auto-generated UUID -> primary key
      process :String ---> process name (Foreign key to )
      is_active :Boolean ---> token status
      is_request_received:Boolean ---> token request received at
      request:String ---> Request
      request_received_at:timestamp
      initiated_at:timestamp
      response:String ---> Response
      completed_at:timestamp
      status:String ---> transction status
      steps:String ---> Error Occured Stage
  • Table : process

    • Fields :
      id :Int ---> auto-generated id
      name:String ---> process name (eg: BOOK_ORDER,CANCEL_ORDER )
      entity:String ---> process respective to (eg: ORDER , PAYMENT )
  • Graphql :

Either use Hasura Graphql Query or Follow Hasura Graphql Query Standards for Graphql Query and mutation for Database actions
eg:

 query getToken(($token: String!) {
    transaction_token_by_pk(token: $token) {
    ref_id
    is_active
    is_request_received
    request
    response
    process
    initiated_at
    completed_at
       }
}

:License

This project is un-licensed.

Developed by Sanjay Kumar

Back to top