liberation:ddp-rate-limiter-mixin

v0.0.2Published 7 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

meteor-ddp-rate-limiter-mixin

This is a mixin for mdg:validated-method to add rate limitation support to Meteor's methods.

Installation

meteor add liberation:ddp-rate-limiter-mixin

Basic examples

Some examples in pseudo code:

1import { PermissionsMixin } from 'meteor/didericis:permissions-mixin'
2import DDPRateLimiterMixin from 'meteor/liberation:ddp-rate-limiter-mixin'
3
4// we can create instance of DDPRateLimiterMixin with default values for all methods.
5const ddpRateLimiterMixin = DDPRateLimiterMixin({
6  numRequests: 50,
7  timeInterval: 1000
8  ...
9})
10
11// or just do it with default settings
12const ddpRateLimiterMixin = DDPRateLimiterMixin()
13
14export const baseMixinsSet = [
15  PermissionsMixin, ddpRateLimiterMixin
16]
1import { baseMixinsSet } from './methodMixins.js'
2
3// with default settings for DDPRateLimiterMixin
4void new ValidatedMethod({
5  name: 'tasks.createTask',
6  mixins: baseMixinsSet,
7  allow: [{
8    roles: ['pm'],
9    group: Roles.GLOBAL_GROUP
10  }],
11  validate: new SimpleSchema({ ... }).validator(),
12  run ({ taskData }) {
13    ...
14  }
15})
16
17// or with custom settings for DDPRateLimiterMixin
18void new ValidatedMethod({
19  name: 'tasks.removeTask',
20  mixins: baseMixinsSet,
21  allow: [{
22    roles: ['pm'],
23    group: Roles.GLOBAL_GROUP
24  }],
25  rateLimit: {
26    matcher: {},                      // optional parameter
27    clientAddress () { return true }, // optional parameter
28    connectionId () { return true },  // optional parameter
29    userId () { return true },        // optional parameter
30    numRequests: 50,                  // optional parameter
31    timeInterval: 1000                // optional parameter
32  },
33  validate: new SimpleSchema({ ... }).validator(),
34  run ({ taskData }) {
35    ...
36  }
37})

For more info check the links: