2.2.1 • Published 2 years ago

idempotency v2.2.1

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

idempotency

Use DynamoDB to store idempotency keys and check for replay. Results are cached to protect against multi-replay attacks.

Installation

> npm install --save idempotency

Usage

Firstly create a dynamodb table to store the keys and values. By default it has the following schema (all can be overriden using configuration see below):

  • Table Name: idempotency
  • Partition Key: id
  • TTL Key: ttl
  • TTL: 60

Simple Example

const {check} = require('idempotency');

const myfunc = async({id}) {
  const { replay } = await check({id});
  if(replay) {
    console.error("this is a replay")
  } else {
    console.log("all is good")
  }
}

Example with Configuration

const {check} = require('idempotency');

const config = {
  tablename: 'TABLE',
  idField: 'ID',
  ttlField: 'TTL',
  ttl: 42,
};

const myfunc = async({id}) {
  await configure(config); // should be done once really
  
  const { replay } = await check({id});
  if(replay) {
    console.error("this is a replay")
  } else {
    console.log("all is good")
  }
}
2.2.1

2 years ago

2.2.0

3 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.0.0

6 years ago