Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Add fixedWindow, tokenBucket, and slidingWindow primitives #171

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions arcjet-next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import type { NextMiddlewareResult } from "next/dist/server/web/types.js";
import arcjet, {
ArcjetDecision,
ArcjetOptions,
Primitive,
Product,
ArcjetHeaders,
Runtime,
ArcjetRequest,
Expand All @@ -21,6 +19,8 @@ import arcjet, {
RemoteClientOptions,
defaultBaseUrl,
createRemoteClient,
ArcjetPrimitive,
ArcjetProduct,
} from "arcjet";
import findIP from "@arcjet/ip";

Expand Down Expand Up @@ -64,6 +64,14 @@ type PlainObject = {
[key: string]: unknown;
};

// Primitives and Products can be specified in a variety of ways and are
// externally grouped as `rules`
// See ExtraRules below for further explanation on why we define them like this.
type PrimitivesOrProduct<Props extends {} = {}> =
| ArcjetPrimitive<Props>
| ArcjetPrimitive<Props>[]
| ArcjetProduct<Props>;

/**
* Ensures redirects are followed to properly support the Next.js/Vercel Edge
* Runtime.
Expand Down Expand Up @@ -157,7 +165,7 @@ export interface ArcjetNext<Props extends PlainObject> {
* These can be overriden on a per-request basis by providing them to the
* `protect()` or `protectApi` methods.
*/
export default function arcjetNext<const Rules extends (Primitive | Product)[]>(
export default function arcjetNext<const Rules extends PrimitivesOrProduct[]>(
options: ArcjetOptions<Rules>,
): ArcjetNext<Simplify<ExtraProps<Rules>>> {
const client = options.client ?? createNextRemoteClient();
Expand Down
Loading
Loading