diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 8fe76c22b..c5cee1c5d 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -22,7 +22,7 @@ lint: - shfmt@3.6.0 - trivy@0.49.1 - yamllint@1.35.1 - - semgrep@1.61.1 + - semgrep@1.62.0 - gitleaks@8.18.2 - actionlint@1.6.26 - git-diff-check @@ -30,7 +30,7 @@ lint: - osv-scanner@1.6.2 - prettier@3.2.5 - svgo@3.2.0 - - trufflehog@3.67.6 + - trufflehog@3.68.0 disabled: # tfsec and checkov are replaced by Trivy - tfsec diff --git a/analyze/README.md b/analyze/README.md index 9aa15beb8..834f4b900 100644 --- a/analyze/README.md +++ b/analyze/README.md @@ -8,10 +8,12 @@ # `@arcjet/analyze`

- - - npm badge - + + + + npm badge + +

[Arcjet][arcjet] helps developers protect their apps in just a few lines of diff --git a/analyze/package.json b/analyze/package.json index e89506ec8..ef1c55b1b 100644 --- a/analyze/package.json +++ b/analyze/package.json @@ -9,6 +9,15 @@ "url": "git+https://github.com/arcjet/arcjet-js.git", "directory": "analyze" }, + "bugs": { + "url": "https://github.com/arcjet/arcjet-js/issues", + "email": "support@arcjet.com" + }, + "author": { + "name": "Arcjet", + "email": "support@arcjet.com", + "url": "https://arcjet.com" + }, "engines": { "node": ">=18" }, diff --git a/arcjet-next/README.md b/arcjet-next/README.md index 2f4c3d26d..9e7e4f408 100644 --- a/arcjet-next/README.md +++ b/arcjet-next/README.md @@ -8,10 +8,12 @@ # `@arcjet/next`

- - - npm badge - + + + + npm badge + +

[Arcjet][arcjet] helps developers protect their apps in just a few lines of @@ -31,7 +33,61 @@ started. npm install -S @arcjet/next ``` -## Example +## Rate limit example + +The [Arcjet rate +limit](https://docs.arcjet.com/rate-limiting/concepts) example below +applies a token bucket rate limit rule to a route where we identify the user +based on their ID e.g. if they are logged in. The bucket is configured with a +maximum capacity of 10 tokens and refills by 5 tokens every 10 seconds. Each +request consumes 5 tokens. + +See the [Arcjet rate limit +documentation](https://docs.arcjet.com/rate-limiting/quick-start/nextjs) for +details. + +```ts +import arcjet, { tokenBucket } from "@arcjet/next"; +import { NextResponse } from "next/server"; + +const aj = arcjet({ + key: process.env.ARCJET_KEY!, // Get your site key from https://app.arcjet.com + rules: [ + // Create a token bucket rate limit. Other algorithms are supported. + tokenBucket({ + mode: "LIVE", // will block requests. Use "DRY_RUN" to log only + characteristics: ["userId"], // track requests by a custom user ID + refillRate: 5, // refill 5 tokens per interval + interval: 10, // refill every 10 seconds + capacity: 10, // bucket maximum capacity of 10 tokens + }), + ], +}); + +export async function GET(req: Request) { + const userId = "user123"; // Replace with your authenticated user ID + const decision = await aj.protect(req, { userId, requested: 5 }); // Deduct 5 tokens from the bucket + console.log("Arcjet decision", decision); + + if (decision.isDenied()) { + return NextResponse.json( + { error: "Too Many Requests", reason: decision.reason }, + { status: 429 }, + ); + } + + return NextResponse.json({ message: "Hello world" }); +} +``` + +## Shield example + +[Arcjet Shield](https://docs.arcjet.com/shield/concepts) protects your +application against common attacks, including the OWASP Top 10. It’s enabled by +default and runs on every request with negligible performance impact. + +See the [Arcjet Shield +documentation](https://docs.arcjet.com/shield/quick-start/nextjs) for details. ```ts import arcjet from "@arcjet/next"; @@ -42,7 +98,7 @@ const aj = arcjet({ // and set it as an environment variable rather than hard coding. // See: https://nextjs.org/docs/app/building-your-application/configuring/environment-variables key: process.env.ARCJET_KEY, - rules: [], + rules: [], // Shield requires no rule configuration }); export async function GET(req: Request) { diff --git a/arcjet-next/package.json b/arcjet-next/package.json index d843de62c..f4fb7873c 100644 --- a/arcjet-next/package.json +++ b/arcjet-next/package.json @@ -9,6 +9,15 @@ "url": "git+https://github.com/arcjet/arcjet-js.git", "directory": "arcjet-next" }, + "bugs": { + "url": "https://github.com/arcjet/arcjet-js/issues", + "email": "support@arcjet.com" + }, + "author": { + "name": "Arcjet", + "email": "support@arcjet.com", + "url": "https://arcjet.com" + }, "engines": { "node": ">=18" }, diff --git a/arcjet/README.md b/arcjet/README.md index 819fc2d44..cc7fb60fe 100644 --- a/arcjet/README.md +++ b/arcjet/README.md @@ -8,10 +8,12 @@ # `arcjet`

- - - npm badge - + + + + npm badge + +

[Arcjet][arcjet] helps developers protect their apps in just a few lines of diff --git a/arcjet/package.json b/arcjet/package.json index d9f507506..9647180bb 100644 --- a/arcjet/package.json +++ b/arcjet/package.json @@ -9,6 +9,15 @@ "url": "git+https://github.com/arcjet/arcjet-js.git", "directory": "arcjet" }, + "bugs": { + "url": "https://github.com/arcjet/arcjet-js/issues", + "email": "support@arcjet.com" + }, + "author": { + "name": "Arcjet", + "email": "support@arcjet.com", + "url": "https://arcjet.com" + }, "engines": { "node": ">=18" }, diff --git a/duration/README.md b/duration/README.md index e65d4dbcc..1d07011a3 100644 --- a/duration/README.md +++ b/duration/README.md @@ -8,10 +8,12 @@ # `@arcjet/ip`

- - - npm badge - + + + + npm badge + +

[Arcjet][arcjet] utilities for parsing duration strings. diff --git a/duration/package.json b/duration/package.json index 44725fbca..5d2b4220c 100644 --- a/duration/package.json +++ b/duration/package.json @@ -9,6 +9,15 @@ "url": "git+https://github.com/arcjet/arcjet-js.git", "directory": "ip" }, + "bugs": { + "url": "https://github.com/arcjet/arcjet-js/issues", + "email": "support@arcjet.com" + }, + "author": { + "name": "Arcjet", + "email": "support@arcjet.com", + "url": "https://arcjet.com" + }, "engines": { "node": ">=18" }, diff --git a/eslint-config/README.md b/eslint-config/README.md index 1bdc6d34d..a45d8f91d 100644 --- a/eslint-config/README.md +++ b/eslint-config/README.md @@ -8,10 +8,12 @@ # `@arcjet/eslint-config`

- - - npm badge - + + + + npm badge + +

Custom eslint config for [Arcjet][arcjet] projects. diff --git a/eslint-config/package.json b/eslint-config/package.json index 802561fc5..a02969292 100644 --- a/eslint-config/package.json +++ b/eslint-config/package.json @@ -9,6 +9,15 @@ "url": "git+https://github.com/arcjet/arcjet-js.git", "directory": "eslint-config" }, + "bugs": { + "url": "https://github.com/arcjet/arcjet-js/issues", + "email": "support@arcjet.com" + }, + "author": { + "name": "Arcjet", + "email": "support@arcjet.com", + "url": "https://arcjet.com" + }, "engines": { "node": ">=18" }, diff --git a/ip/README.md b/ip/README.md index 056859dc3..e205a89d7 100644 --- a/ip/README.md +++ b/ip/README.md @@ -8,10 +8,12 @@ # `@arcjet/ip`

- - - npm badge - + + + + npm badge + +

[Arcjet][arcjet] utilities for finding the originating IP of a request. diff --git a/ip/package.json b/ip/package.json index 9b2e514fa..b719366e6 100644 --- a/ip/package.json +++ b/ip/package.json @@ -9,6 +9,15 @@ "url": "git+https://github.com/arcjet/arcjet-js.git", "directory": "ip" }, + "bugs": { + "url": "https://github.com/arcjet/arcjet-js/issues", + "email": "support@arcjet.com" + }, + "author": { + "name": "Arcjet", + "email": "support@arcjet.com", + "url": "https://arcjet.com" + }, "engines": { "node": ">=18" }, diff --git a/logger/README.md b/logger/README.md index c2608a132..de97eeaaf 100644 --- a/logger/README.md +++ b/logger/README.md @@ -8,10 +8,12 @@ # `@arcjet/logger`

- - - npm badge - + + + + npm badge + +

[Arcjet][arcjet] logging interface which mirrors the `console` interface but diff --git a/logger/package.json b/logger/package.json index fb3a4b88e..c47c4b98e 100644 --- a/logger/package.json +++ b/logger/package.json @@ -9,6 +9,15 @@ "url": "git+https://github.com/arcjet/arcjet-js.git", "directory": "logger" }, + "bugs": { + "url": "https://github.com/arcjet/arcjet-js/issues", + "email": "support@arcjet.com" + }, + "author": { + "name": "Arcjet", + "email": "support@arcjet.com", + "url": "https://arcjet.com" + }, "engines": { "node": ">=18" }, diff --git a/protocol/README.md b/protocol/README.md index f83aeb490..d3e4eb5f5 100644 --- a/protocol/README.md +++ b/protocol/README.md @@ -8,10 +8,12 @@ # `@arcjet/protocol`

- - - npm badge - + + + + npm badge + +

The TypeScript & JavaScript interface into the [Arcjet][arcjet] protocol. diff --git a/protocol/package.json b/protocol/package.json index 9b1252f4b..8f5cc0ae2 100644 --- a/protocol/package.json +++ b/protocol/package.json @@ -9,6 +9,15 @@ "url": "git+https://github.com/arcjet/arcjet-js.git", "directory": "protocol" }, + "bugs": { + "url": "https://github.com/arcjet/arcjet-js/issues", + "email": "support@arcjet.com" + }, + "author": { + "name": "Arcjet", + "email": "support@arcjet.com", + "url": "https://arcjet.com" + }, "engines": { "node": ">=18" }, diff --git a/rollup-config/README.md b/rollup-config/README.md index 95f82899b..b315012c6 100644 --- a/rollup-config/README.md +++ b/rollup-config/README.md @@ -8,10 +8,12 @@ # `@arcjet/rollup-config`

- - - npm badge - + + + + npm badge + +

Custom rollup config for [Arcjet][arcjet] projects. diff --git a/rollup-config/package.json b/rollup-config/package.json index c31606ff5..627e8e034 100644 --- a/rollup-config/package.json +++ b/rollup-config/package.json @@ -9,6 +9,15 @@ "url": "git+https://github.com/arcjet/arcjet-js.git", "directory": "rollup-config" }, + "bugs": { + "url": "https://github.com/arcjet/arcjet-js/issues", + "email": "support@arcjet.com" + }, + "author": { + "name": "Arcjet", + "email": "support@arcjet.com", + "url": "https://arcjet.com" + }, "engines": { "node": ">=18" }, diff --git a/tsconfig/README.md b/tsconfig/README.md index a113a2c46..170b381d5 100644 --- a/tsconfig/README.md +++ b/tsconfig/README.md @@ -8,10 +8,12 @@ # `@arcjet/tsconfig`

- - - npm badge - + + + + npm badge + +

Custom tsconfig for [Arcjet][arcjet] projects. diff --git a/tsconfig/package.json b/tsconfig/package.json index 220fa245b..ae3b01be2 100644 --- a/tsconfig/package.json +++ b/tsconfig/package.json @@ -9,6 +9,15 @@ "url": "git+https://github.com/arcjet/arcjet-js.git", "directory": "tsconfig" }, + "bugs": { + "url": "https://github.com/arcjet/arcjet-js/issues", + "email": "support@arcjet.com" + }, + "author": { + "name": "Arcjet", + "email": "support@arcjet.com", + "url": "https://arcjet.com" + }, "engines": { "node": ">=18" },