Leverege Platform

Leverege Platform

  • Overview
  • JSDocs
  • REST API
  • Help

›Server Libraries

Platform Overview

  • Overview
  • Architecture
  • Core Concepts

Guides

  • Platform Setup
  • Building a Project
  • API UI

Services

  • API Server
  • Message Processor
  • Transponder
  • Reason
  • Scheduler
  • Messenger
  • Emailer
  • Rest Server
  • DB Curator

API

  • API
  • Interface
  • Project
  • System
  • Device
  • Blueprint
  • Collection
  • Child
  • History
  • Scenario
  • Script
  • Template
  • Timer
  • User
  • Users

Server Libraries

  • Log
  • Messages
  • Message Queue
  • Cache
  • Lock
  • Limit
  • Cluster Manager
  • Error
  • Exit

Utilities

  • Promise
  • Data Store
  • Factory
  • Path
  • Reasoner
  • Object Util
  • Array Util
  • String Util
  • Base62 Util
  • Value Cache
  • Validator
  • Lol

UI

  • API Redux
  • UI Builder
  • UI Elements
  • UI Redux
  • UI Mapbox Elements
  • UI Active Theme
  • UI Color Elements
  • UI Linear View Elements

Limit

The limit library is used with messaging services. The limit library limits the number of messages that a user can get in a time period, and if that limit is reached, does not send the user more messages for a specified time period. Limit uses namespaces, so that messages can be limited independent of each other.

Install

npm install -save @leverege/limit

Usage

An example of a redis based approach:

const Limit = require( '@leverege/limit' );
const limitConfig = process.env.LIMIT_CONFIG || 
  { type : 'redis', 
    connection : {
      host : '127.0.0.1',
      port : 6379
    },
  };

const limit = Limit.create( { namespace : 'myApp', limitConfig } )

Limiting

// Create a connection to the limiter mechanism. Give it a namespace
const limiter = Limit.create( { namespace : 'myApp'}, limitConfig )

// Create a limit object for a specific key (which can be namespaced),
// with specific properties.
const limit = limiter.limit( 'myKey', {
    count : 10,        // only allow 10
    period : 10*1000,      // over a 10 second period
    duration : 60*60*1000, // or limit for one hour
  })

// Same can be done with a namespaced key.
const limit = limiter.limit( 'myKey', {
    count : 5,        // only allow 5
    period : 30*1000,     // over a 30 second period
    duration : 5*60*1000, // or limit for 5 minutes
  })

const limited = await limit.isLimited( ) // increment and check if we are limited

if ( limited ) {
  // dont do the action
  return
}
// do the action

← LockCluster Manager →
  • Install
  • Usage
  • Limiting
Leverege Platform
Docs
Overview
Connect
FacebookLinkedInTwitter
Facebook Open Source