Skip to content

Commit

Permalink
chore!: Remove timeout property on ArcjetRateLimitRule (#182)
Browse files Browse the repository at this point in the history
This removes the `timeout` property on `ArcjetRateLimitRule`. Having timeout on rate limits is confusing because each rate limit has a reset time based on the configuration. If we kept timeout ("block duration") around, it would be very confusing to determine when a user will be able to access the resource again.

We're tracking the concept of timeout ("block duration") in arcjet/arcjet#567.
  • Loading branch information
blaine-arcjet authored Feb 6, 2024
1 parent ff3e310 commit 255a4a7
Show file tree
Hide file tree
Showing 10 changed files with 0 additions and 26 deletions.
2 changes: 0 additions & 2 deletions arcjet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ export type RateLimitOptions = {
characteristics?: string[];
window: string;
max: number;
timeout: string;
};

/**
Expand Down Expand Up @@ -595,7 +594,6 @@ export function rateLimit(
characteristics: opt.characteristics,
window: opt.window,
max: opt.max,
timeout: opt.timeout,
});
}

Expand Down
16 changes: 0 additions & 16 deletions arcjet/test/index.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,6 @@ describe("Primitive > rateLimit", () => {
characteristics: ["ip.src"],
window: "1h",
max: 1,
timeout: "10m",
});
expect(rule.type).toEqual("RATE_LIMIT");
expect(rule).toHaveProperty("mode", "DRY_RUN");
Expand All @@ -1938,7 +1937,6 @@ describe("Primitive > rateLimit", () => {
characteristics: ["ip.src"],
window: "1h",
max: 1,
timeout: "10m",
};

const rules = rateLimit(options);
Expand All @@ -1949,7 +1947,6 @@ describe("Primitive > rateLimit", () => {
expect(rules[0]).toHaveProperty("characteristics", ["ip.src"]);
expect(rules[0]).toHaveProperty("window", "1h");
expect(rules[0]).toHaveProperty("max", 1);
expect(rules[0]).toHaveProperty("timeout", "10m");
});

test("produces a multiple rules based on multiple `limit` specified", async () => {
Expand All @@ -1959,14 +1956,12 @@ describe("Primitive > rateLimit", () => {
characteristics: ["ip.src"],
window: "1h",
max: 1,
timeout: "10m",
},
{
match: "/test-double",
characteristics: ["ip.src"],
window: "2h",
max: 2,
timeout: "20m",
},
];

Expand All @@ -1980,7 +1975,6 @@ describe("Primitive > rateLimit", () => {
characteristics: ["ip.src"],
window: "1h",
max: 1,
timeout: "10m",
}),
expect.objectContaining({
type: "RATE_LIMIT",
Expand All @@ -1989,7 +1983,6 @@ describe("Primitive > rateLimit", () => {
characteristics: ["ip.src"],
window: "2h",
max: 2,
timeout: "20m",
}),
]);
});
Expand All @@ -1998,7 +1991,6 @@ describe("Primitive > rateLimit", () => {
const options = {
window: "1h",
max: 1,
timeout: "10m",
};

const [rule] = rateLimit(options);
Expand All @@ -2012,12 +2004,10 @@ describe("Primitive > rateLimit", () => {
{
window: "1h",
max: 1,
timeout: "10m",
},
{
window: "2h",
max: 2,
timeout: "20m",
},
];

Expand All @@ -2030,7 +2020,6 @@ describe("Primitive > rateLimit", () => {
characteristics: undefined,
window: "1h",
max: 1,
timeout: "10m",
}),
expect.objectContaining({
type: "RATE_LIMIT",
Expand All @@ -2039,7 +2028,6 @@ describe("Primitive > rateLimit", () => {
characteristics: undefined,
window: "2h",
max: 2,
timeout: "20m",
}),
]);
});
Expand Down Expand Up @@ -2379,7 +2367,6 @@ describe("Products > protectSignup", () => {
characteristics: ["ip.src"],
window: "1h",
max: 1,
timeout: "10m",
},
bots: {
mode: ArcjetMode.DRY_RUN,
Expand All @@ -2400,14 +2387,12 @@ describe("Products > protectSignup", () => {
characteristics: ["ip.src"],
window: "1h",
max: 1,
timeout: "10m",
},
{
match: "/test",
characteristics: ["ip.src"],
window: "2h",
max: 2,
timeout: "20m",
},
],
});
Expand Down Expand Up @@ -3431,7 +3416,6 @@ describe("Arcjet: Env = Serverless Node runtime on Vercel", () => {
characteristics: ["ip.src"],
window: "1h",
max: 1,
timeout: "10m",
};
const fingerprint =
"fp_1_ac8547705f1f45c5050f1424700dfa3f6f2f681b550ca4f3c19571585aea7a2c";
Expand Down
1 change: 0 additions & 1 deletion examples/nextjs-13-pages-wrap/pages/api/arcjet-edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const aj = arcjet({
//characteristics: ["ip.src"],
window: "1m",
max: 1,
timeout: "10m",
}),
],
});
Expand Down
1 change: 0 additions & 1 deletion examples/nextjs-13-pages-wrap/pages/api/arcjet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const aj = arcjet({
//characteristics: ["ip.src"],
window: "1m",
max: 1,
timeout: "10m",
}),
],
});
Expand Down
1 change: 0 additions & 1 deletion examples/nextjs-14-app-dir-rl/app/api/arcjet/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const aj = arcjet({
characteristics: ["ip.src"],
window: "1h",
max: 1,
timeout: "10m",
}),
],
});
Expand Down
1 change: 0 additions & 1 deletion examples/nextjs-14-openai/app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const aj = arcjet({
characteristics: ["ip.src"],
window: "1m",
max: 60,
timeout: "10m",
}),
],
});
Expand Down
1 change: 0 additions & 1 deletion examples/nextjs-14-pages-wrap/pages/api/arcjet-edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const aj = arcjet({
//characteristics: ["ip.src"],
window: "1m",
max: 1,
timeout: "10m",
}),
],
});
Expand Down
1 change: 0 additions & 1 deletion examples/nextjs-14-pages-wrap/pages/api/arcjet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const aj = arcjet({
//characteristics: ["ip.src"],
window: "1m",
max: 1,
timeout: "10m",
}),
],
});
Expand Down
1 change: 0 additions & 1 deletion protocol/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ export function ArcjetRuleToProtocol<Props extends { [key: string]: unknown }>(
characteristics: rule.characteristics,
window: rule.window,
max: rule.max,
timeout: rule.timeout,
},
},
});
Expand Down
1 change: 0 additions & 1 deletion protocol/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ export interface ArcjetRateLimitRule<Props extends {}>
characteristics?: string[];
window: string;
max: number;
timeout: string;
}

export interface ArcjetEmailRule<Props extends { email: string }>
Expand Down

0 comments on commit 255a4a7

Please sign in to comment.