Skip to content

Commit

Permalink
chore: Add bugs and author info & update readme (#254)
Browse files Browse the repository at this point in the history
- Adds [bugs](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bugs) and [author](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#people-fields-author-contributors) fields to `package.json`.
- Link the NPM version badge to the NPM package page.
- Extand the arcjet-next readme with examples for rate limiting and Shield.
  • Loading branch information
davidmytton authored Feb 27, 2024
1 parent f8ebbdc commit 9b0d2fc
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ 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
- markdownlint@0.39.0
- 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
Expand Down
10 changes: 6 additions & 4 deletions analyze/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
# `@arcjet/analyze`

<p>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Fanalyze?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Fanalyze?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
<a href="https://www.npmjs.com/package/@arcjet/analyze">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Fanalyze?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Fanalyze?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
</a>
</p>

[Arcjet][arcjet] helps developers protect their apps in just a few lines of
Expand Down
9 changes: 9 additions & 0 deletions analyze/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
68 changes: 62 additions & 6 deletions arcjet-next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
# `@arcjet/next`

<p>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Fnext?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Fnext?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
<a href="https://www.npmjs.com/package/@arcjet/next">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Fnext?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Fnext?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
</a>
</p>

[Arcjet][arcjet] helps developers protect their apps in just a few lines of
Expand All @@ -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";
Expand All @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions arcjet-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
10 changes: 6 additions & 4 deletions arcjet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
# `arcjet`

<p>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/arcjet?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/arcjet?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
<a href="https://www.npmjs.com/package/arcjet">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/arcjet?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/arcjet?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
</a>
</p>

[Arcjet][arcjet] helps developers protect their apps in just a few lines of
Expand Down
9 changes: 9 additions & 0 deletions arcjet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
10 changes: 6 additions & 4 deletions duration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
# `@arcjet/ip`

<p>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Fip?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Fip?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
<a href="https://www.npmjs.com/package/@arcjet/duration">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Fduration?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Fduration?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
</a>
</p>

[Arcjet][arcjet] utilities for parsing duration strings.
Expand Down
9 changes: 9 additions & 0 deletions duration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
10 changes: 6 additions & 4 deletions eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
# `@arcjet/eslint-config`

<p>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Feslint-config?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Feslint-config?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
<a href="https://www.npmjs.com/package/@arcjet/eslint-config">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Feslint-config?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Feslint-config?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
</a>
</p>

Custom eslint config for [Arcjet][arcjet] projects.
Expand Down
9 changes: 9 additions & 0 deletions eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
10 changes: 6 additions & 4 deletions ip/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
# `@arcjet/ip`

<p>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Fip?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Fip?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
<a href="https://www.npmjs.com/package/@arcjet/ip">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Fip?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Fip?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
</a>
</p>

[Arcjet][arcjet] utilities for finding the originating IP of a request.
Expand Down
9 changes: 9 additions & 0 deletions ip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
10 changes: 6 additions & 4 deletions logger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
# `@arcjet/logger`

<p>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Flogger?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Flogger?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
<a href="https://www.npmjs.com/package/@arcjet/logger">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Flogger?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Flogger?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
</a>
</p>

[Arcjet][arcjet] logging interface which mirrors the `console` interface but
Expand Down
9 changes: 9 additions & 0 deletions logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
10 changes: 6 additions & 4 deletions protocol/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
# `@arcjet/protocol`

<p>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Fprotocol?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Fprotocol?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
<a href="https://www.npmjs.com/package/@arcjet/protocol">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Fprotocol?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Fprotocol?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
</a>
</p>

The TypeScript & JavaScript interface into the [Arcjet][arcjet] protocol.
Expand Down
9 changes: 9 additions & 0 deletions protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
10 changes: 6 additions & 4 deletions rollup-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
# `@arcjet/rollup-config`

<p>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Frollup-config?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Frollup-config?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
<a href="https://www.npmjs.com/package/@arcjet/rollup-config">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/%40arcjet%2Frollup-config?style=flat-square&label=%E2%9C%A6Aj&labelColor=000000&color=5C5866">
<img alt="npm badge" src="https://img.shields.io/npm/v/%40arcjet%2Frollup-config?style=flat-square&label=%E2%9C%A6Aj&labelColor=ECE6F0&color=ECE6F0">
</picture>
</a>
</p>

Custom rollup config for [Arcjet][arcjet] projects.
Expand Down
9 changes: 9 additions & 0 deletions rollup-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
Loading

0 comments on commit 9b0d2fc

Please sign in to comment.