Skip to content

Commit

Permalink
feat: add custom rate limit types (#500)
Browse files Browse the repository at this point in the history
Base types for custom rate limit config type inference (almost forgot).
Basically a dried out version of
https://github.com/netlify/zip-it-and-ship-it/blob/main/src/rate_limit.ts,
but let me know if you think I should just use the original one instead.

Related to ADN-294

Will do the same for edge-functions after this one gets through
  • Loading branch information
paulo authored May 16, 2024
1 parent 3d2a6a6 commit 00e262a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/function/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ export type { Context } from '@netlify/serverless-functions-api'
type Path = `/${string}`
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS'
type CronSchedule = string
type RateLimitAggregator = 'domain' | 'ip'
type RateLimitAction = 'rate_limit' | 'rewrite'

interface RateLimitConfig {
action?: RateLimitAction
aggregateBy?: RateLimitAggregator | RateLimitAggregator[]
to?: string
windowSize: number
}

interface BaseConfig {
/**
Expand All @@ -16,6 +25,8 @@ interface BaseConfig {
* function will run for all supported methods.
*/
method?: HTTPMethod | HTTPMethod[]

rateLimit?: RateLimitConfig
}

interface ConfigWithPath extends BaseConfig {
Expand Down

0 comments on commit 00e262a

Please sign in to comment.