0.4.0 • Published 2 years ago

ts-limiter v0.4.0

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

Limiter TypeScript SDK

Installation

With npm:

npm install ts-limiter

With yarn:

yarn add ts-limiter

Quick Usage

Default Backend

Initialize SDK with the managed storage backend

import { Limiter } from 'ts-limiter';

const opts = {
  backend: 'Default',
  apiToken: 'api-token',
};
const client = new Limiter('project-id', opts);

S3 Backend (Deprecated)

Initialize SDK with a private S3 bucket storage

import { Limiter } from 'ts-limiter';

const opts = {
  backend: 'S3',
  s3Bucket: 's3-bucket',
  region: 'us-east-1',
  accessKeyId: 'access-key-id',
  secretAccessKey: 'secret-access-key',
};
const client = new Limiter('project-id', opts);

Available Methods

// Bind user to a plan
await client.bind('plan-name', 'user-id');

// Check if a feature is within limit
if (await client.feature('feature-name', 'user-id')) {
  // Pass
}

// Increment usage by 1.
await client.increment('feature-name', 'user-id');

// Decrement usage by 1.
await client.decrement('feature-name', 'user-id');

// Set usage to some value.
await client.set('feature-name', 'user-id', 5);

// Get feature matrix for the project
const featureMatrix = await client.featureMatrix();

// Get user's usage data
const usage = await client.usage('user-id');
0.4.0

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.17

2 years ago

0.1.16

2 years ago

0.1.15

2 years ago

0.1.14

2 years ago

0.1.13

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago