graphql-rate-limit
Advanced tools
Comparing version 1.2.3 to 1.2.4
@@ -25,2 +25,6 @@ import { Store } from './store'; | ||
readonly identityArgs?: ReadonlyArray<string>; | ||
/** | ||
* Limit by the length of an input array | ||
*/ | ||
readonly arrayLengthField?: string; | ||
} | ||
@@ -27,0 +31,0 @@ export interface FormatErrorInput { |
@@ -55,6 +55,9 @@ "use strict"; | ||
const accessTimestamps = await store.getForIdentity(identity); | ||
// Create an array of callCount length, filled with the current timestamp | ||
const timestamp = Date.now(); | ||
const newTimestamps = [...new Array(options.callCount || 1)].map(() => timestamp); | ||
const filteredAccessTimestamps = [ | ||
Date.now(), | ||
...accessTimestamps.filter(timestamp => { | ||
return timestamp + options.windowMs > Date.now(); | ||
...newTimestamps, | ||
...accessTimestamps.filter(t => { | ||
return t + options.windowMs > Date.now(); | ||
}) | ||
@@ -78,2 +81,5 @@ ]; | ||
args: { | ||
arrayLengthField: { | ||
type: graphql_1.GraphQLString | ||
}, | ||
identityArgs: { | ||
@@ -108,2 +114,3 @@ type: new graphql_1.GraphQLList(graphql_1.GraphQLString) | ||
const fieldIdentity = getFieldIdentity(name, identityArgs, resolveArgs); | ||
const callCount = lodash_get_1.default(resolveArgs, [this.args.arrayLengthField, 'length']) || 1; | ||
const message = this.args.message || | ||
@@ -117,3 +124,3 @@ config.formatError({ | ||
}); | ||
const isExceedingMax = await validateResolve(config.store, { contextIdentity, fieldIdentity }, { windowMs, max }); | ||
const isExceedingMax = await validateResolve(config.store, { contextIdentity, fieldIdentity }, { windowMs, max, callCount }); | ||
if (isExceedingMax) { | ||
@@ -129,2 +136,2 @@ throw new rate_limit_error_1.RateLimitError(message); | ||
exports.createRateLimitDirective = createRateLimitDirective; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmllbGQtZGlyZWN0aXZlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2xpYi9maWVsZC1kaXJlY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FnQixDQUFDO0FBQzFCLENBQUMsQ0FBQztBQUVPLDREQUF3QiJ9 |
@@ -8,2 +8,3 @@ export interface Identity { | ||
readonly max: number; | ||
readonly callCount?: number; | ||
} |
@@ -25,2 +25,6 @@ import { Store } from './store'; | ||
readonly identityArgs?: ReadonlyArray<string>; | ||
/** | ||
* Limit by the length of an input array | ||
*/ | ||
readonly arrayLengthField?: string; | ||
} | ||
@@ -27,0 +31,0 @@ export interface FormatErrorInput { |
@@ -49,6 +49,9 @@ import { defaultFieldResolver, DirectiveLocation, GraphQLDirective, GraphQLInt, GraphQLList, GraphQLString } from 'graphql'; | ||
const accessTimestamps = await store.getForIdentity(identity); | ||
// Create an array of callCount length, filled with the current timestamp | ||
const timestamp = Date.now(); | ||
const newTimestamps = [...new Array(options.callCount || 1)].map(() => timestamp); | ||
const filteredAccessTimestamps = [ | ||
Date.now(), | ||
...accessTimestamps.filter(timestamp => { | ||
return timestamp + options.windowMs > Date.now(); | ||
...newTimestamps, | ||
...accessTimestamps.filter(t => { | ||
return t + options.windowMs > Date.now(); | ||
}) | ||
@@ -71,2 +74,5 @@ ]; | ||
args: { | ||
arrayLengthField: { | ||
type: GraphQLString | ||
}, | ||
identityArgs: { | ||
@@ -101,2 +107,3 @@ type: new GraphQLList(GraphQLString) | ||
const fieldIdentity = getFieldIdentity(name, identityArgs, resolveArgs); | ||
const callCount = get(resolveArgs, [this.args.arrayLengthField, 'length']) || 1; | ||
const message = this.args.message || | ||
@@ -110,3 +117,3 @@ config.formatError({ | ||
}); | ||
const isExceedingMax = await validateResolve(config.store, { contextIdentity, fieldIdentity }, { windowMs, max }); | ||
const isExceedingMax = await validateResolve(config.store, { contextIdentity, fieldIdentity }, { windowMs, max, callCount }); | ||
if (isExceedingMax) { | ||
@@ -122,2 +129,2 @@ throw new RateLimitError(message); | ||
export { createRateLimitDirective, getFieldIdentity, validateResolve }; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmll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FRLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQztnQkFDaEUsTUFBTSxPQUFPLEdBQ1gsSUFBSSxDQUFDLElBQUksQ0FBQyxPQUFPO29CQUNqQixNQUFNLENBQUMsV0FBVyxDQUFDO3dCQUNqQixlQUFlO3dCQUNmLGFBQWE7d0JBQ2IsU0FBUyxFQUFFLElBQUk7d0JBQ2YsR0FBRzt3QkFDSCxNQUFNLEVBQUUsUUFBUTtxQkFDakIsQ0FBQyxDQUFDO2dCQUVMLE1BQU0sY0FBYyxHQUFHLE1BQU0sZUFBZSxDQUMxQyxNQUFNLENBQUMsS0FBSyxFQUNaLEVBQUUsZUFBZSxFQUFFLGFBQWEsRUFBRSxFQUNsQyxFQUFFLFFBQVEsRUFBRSxHQUFHLEVBQUUsU0FBUyxFQUFFLENBQzdCLENBQUM7Z0JBRUYsSUFBSSxjQUFjLEVBQUU7b0JBQ2xCLE1BQU0sSUFBSSxjQUFjLENBQUMsT0FBTyxDQUFDLENBQUM7aUJBQ25DO2dCQUVELE9BQU8sT0FBTyxDQUFDLEdBQUcsSUFBSSxDQUFDLENBQUM7WUFDMUIsQ0FBQyxDQUFDO1FBQ0osQ0FBQztLQUNGO0lBQ0QsT0FBTyxnQkFBZ0IsQ0FBQztBQUMxQixDQUFDLENBQUM7QUFFRixPQUFPLEVBQUUsd0JBQXdCLEVBQUUsZ0JBQWdCLEVBQUUsZUFBZSxFQUFFLENBQUMifQ== |
@@ -8,2 +8,3 @@ export interface Identity { | ||
readonly max: number; | ||
readonly callCount?: number; | ||
} |
@@ -17,3 +17,3 @@ const { ApolloServer, gql } = require('apollo-server'); | ||
const typeDefs = gql` | ||
directive @rateLimit(message: String, identityArgs: [String], max: Int, window: String) on FIELD_DEFINITION | ||
directive @rateLimit(message: String, identityArgs: [String], arrayLengthField: String, max: Int, window: String) on FIELD_DEFINITION | ||
@@ -31,2 +31,3 @@ type Book { | ||
createBook(title: String!, author: String!): Book @rateLimit(identityArgs: ["title"], max: 2, window: "10s") | ||
deleteBooks(titles: [String]!): Book @rateLimit(identityArgs: ["title"], arrayLengthField: "titles", max: 4, window: "10s") | ||
} | ||
@@ -42,3 +43,6 @@ `; | ||
books.push(args); | ||
return args; | ||
return args; | ||
}, | ||
deleteBooks: () => { | ||
return books[0]; | ||
} | ||
@@ -45,0 +49,0 @@ } |
{ | ||
"name": "graphql-rate-limit", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "A GraphQL Directive to Rate Limit Queries or Mutations 💂♀", | ||
@@ -5,0 +5,0 @@ "main": "build/main/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57259
787