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

docs: Add quick start links & update Bun example #870

Merged
merged 6 commits into from
Jun 7, 2024
Merged
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
25 changes: 0 additions & 25 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -340,31 +340,6 @@ updates:
- dependency-name: eslint
versions: [">=9"]

- package-ecosystem: npm
directory: /examples/nextjs-example
schedule:
# Our dependencies should be checked daily
interval: daily
assignees:
- blaine-arcjet
reviewers:
- blaine-arcjet
commit-message:
prefix: deps(example)
prefix-development: deps(example)
groups:
dependencies:
patterns:
- "*"
ignore:
# Ignore updates to the @types/node package due to conflict between
# Headers in DOM.
- dependency-name: "@types/node"
versions: [">18.18"]
# TODO(#539): Upgrade to eslint 9
- dependency-name: eslint
versions: [">=9"]

- package-ecosystem: npm
directory: /examples/nodejs-express-rl
schedule:
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<a href="https://arcjet.com" target="_arcjet-home">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/arcjet-logo-minimal-dark-mark-all.svg">
<img src="https://arcjet.com/arcjet-logo-minimal-light-mark-all.svg" alt="Arcjet Logo" height="128" width="auto">
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg">
<img src="https://arcjet.com/logo/arcjet-light-lockup-voyage-horizontal.svg" alt="Arcjet Logo" height="128" width="auto">
</picture>
</a>

Expand All @@ -15,20 +15,22 @@
</p>

[Arcjet][arcjet] helps developers protect their apps in just a few lines of
code. Implement rate limiting, bot protection, email verification & defense
code. Implement rate limiting, bot protection, email verification, and defense
against common attacks.

This is the monorepo containing various [Arcjet][arcjet] open source packages
for JS.

## Quick start

- **Bun?** Use the [`@arcjet/bun`][npm-bun] package.
- **Bun?** Use the [`@arcjet/bun`][npm-bun] package with our [Bun quick start
guide][bun-quick-start].
- **Next.js?** Use the [`@arcjet/next`][npm-next] package with our [Next.js
quick start guide][next-quick-start].
- **Node.js?** Use the [`@arcjet/node`][npm-node] package with our [Node.js
quick start guide][node-quick-start].
- **SvelteKit?** Use the [`@arcjet/sveltekit`][npm-sveltekit] package.
- **SvelteKit?** Use the [`@arcjet/sveltekit`][npm-sveltekit] package with our
[SvelteKit quick start guide][sveltekit-quick-start].

## Get help

Expand Down Expand Up @@ -199,9 +201,11 @@ Licensed under the [Apache License, Version 2.0][apache-license].
[arcjet]: https://arcjet.com
[npm-bun]: https://www.npmjs.com/package/@arcjet/bun
[npm-next]: https://www.npmjs.com/package/@arcjet/next
[bun-quick-start]: https://docs.arcjet.com/get-started/bun
[next-quick-start]: https://docs.arcjet.com/get-started/nextjs
[npm-node]: https://www.npmjs.com/package/@arcjet/node
[node-quick-start]: https://docs.arcjet.com/get-started/nodejs
[sveltekit-quick-start]: https://docs.arcjet.com/get-started/sveltekit
[npm-sveltekit]: https://www.npmjs.com/package/@arcjet/sveltekit
[discord-invite]: https://discord.gg/TPra6jqZDC
[support]: https://docs.arcjet.com/support
Expand Down
6 changes: 3 additions & 3 deletions analyze/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<a href="https://arcjet.com" target="_arcjet-home">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/arcjet-logo-dark-planet-arrival.svg">
<img src="https://arcjet.com/arcjet-logo-light-planet-arrival.svg" alt="Arcjet Logo" height="144" width="auto">
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg">
<img src="https://arcjet.com/logo/arcjet-light-lockup-voyage-horizontal.svg" alt="Arcjet Logo" height="128" width="auto">
</picture>
</a>

Expand All @@ -17,7 +17,7 @@
</p>

[Arcjet][arcjet] helps developers protect their apps in just a few lines of
code. Implement rate limiting, bot protection, email verification & defense
code. Implement rate limiting, bot protection, email verification, and defense
against common attacks.

This is the [Arcjet][arcjet] local analysis engine.
Expand Down
11 changes: 8 additions & 3 deletions arcjet-bun/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<a href="https://arcjet.com" target="_arcjet-home">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/arcjet-logo-dark-planet-arrival.svg">
<img src="https://arcjet.com/arcjet-logo-light-planet-arrival.svg" alt="Arcjet Logo" height="144" width="auto">
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg">
<img src="https://arcjet.com/logo/arcjet-light-lockup-voyage-horizontal.svg" alt="Arcjet Logo" height="128" width="auto">
</picture>
</a>

Expand All @@ -17,11 +17,15 @@
</p>

[Arcjet][arcjet] helps developers protect their apps in just a few lines of
code. Implement rate limiting, bot protection, email verification & defense
code. Implement rate limiting, bot protection, email verification, and defense
against common attacks.

This is the [Arcjet][arcjet] SDK for [Bun.sh][bun-sh].

## Getting started

Visit the [quick start guide][quick-start] to get started.

## Example app

Try an Arcjet protected app live at [https://example.arcjet.com][example-url]
Expand Down Expand Up @@ -116,6 +120,7 @@ Licensed under the [Apache License, Version 2.0][apache-license].
[arcjet]: https://arcjet.com
[bun-sh]: https://bun.sh/
[example-url]: https://example.arcjet.com
[quick-start]: https://docs.arcjet.com/get-started/bun
[example-source]: https://github.com/arcjet/arcjet-js-example
[rate-limit-concepts-docs]: https://docs.arcjet.com/rate-limiting/concepts
[shield-concepts-docs]: https://docs.arcjet.com/shield/concepts
Expand Down
9 changes: 5 additions & 4 deletions arcjet-next/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<a href="https://arcjet.com" target="_arcjet-home">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/arcjet-logo-dark-planet-arrival.svg">
<img src="https://arcjet.com/arcjet-logo-light-planet-arrival.svg" alt="Arcjet Logo" height="144" width="auto">
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg">
<img src="https://arcjet.com/logo/arcjet-light-lockup-voyage-horizontal.svg" alt="Arcjet Logo" height="128" width="auto">
</picture>
</a>

Expand All @@ -17,7 +17,7 @@
</p>

[Arcjet][arcjet] helps developers protect their apps in just a few lines of
code. Implement rate limiting, bot protection, email verification & defense
code. Implement rate limiting, bot protection, email verification, and defense
against common attacks.

This is the [Arcjet][arcjet] SDK for the [Next.js][next-js] framework.
Expand All @@ -27,7 +27,7 @@ package.

## Getting started

Visit [docs.arcjet.com][next-sdk-docs] to get started.
Visit the [quick start guide][quick-start] to get started.

## Example app

Expand Down Expand Up @@ -130,6 +130,7 @@ Licensed under the [Apache License, Version 2.0][apache-license].
[arcjet]: https://arcjet.com
[next-js]: https://nextjs.org/
[alt-sdk]: https://www.npmjs.com/package/@arcjet/node
[quick-start]: https://docs.arcjet.com/get-started/nextjs
[next-sdk-docs]: https://docs.arcjet.com/reference/nextjs
[example-url]: https://example.arcjet.com
[example-source]: https://github.com/arcjet/arcjet-js-example
Expand Down
11 changes: 8 additions & 3 deletions arcjet-node/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<a href="https://arcjet.com" target="_arcjet-home">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/arcjet-logo-dark-planet-arrival.svg">
<img src="https://arcjet.com/arcjet-logo-light-planet-arrival.svg" alt="Arcjet Logo" height="144" width="auto">
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg">
<img src="https://arcjet.com/logo/arcjet-light-lockup-voyage-horizontal.svg" alt="Arcjet Logo" height="128" width="auto">
</picture>
</a>

Expand All @@ -17,14 +17,18 @@
</p>

[Arcjet][arcjet] helps developers protect their apps in just a few lines of
code. Implement rate limiting, bot protection, email verification & defense
code. Implement rate limiting, bot protection, email verification, and defense
against common attacks.

This is the [Arcjet][arcjet] SDK for [Node.js][node-js].

**Looking for our Next.js framework SDK?** Check out the
[`@arcjet/next`][alt-sdk] package.

## Getting started

Visit the [quick start guide][quick-start] to get started.

## Example app

Try an Arcjet protected app live at [https://example.arcjet.com][example-url]
Expand Down Expand Up @@ -129,6 +133,7 @@ Licensed under the [Apache License, Version 2.0][apache-license].
[node-js]: https://nodejs.org/
[alt-sdk]: https://www.npmjs.com/package/@arcjet/next
[example-url]: https://example.arcjet.com
[quick-start]: https://docs.arcjet.com/get-started/nodejs
[example-source]: https://github.com/arcjet/arcjet-js-example
[rate-limit-concepts-docs]: https://docs.arcjet.com/rate-limiting/concepts
[shield-concepts-docs]: https://docs.arcjet.com/shield/concepts
Expand Down
11 changes: 8 additions & 3 deletions arcjet-sveltekit/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<a href="https://arcjet.com" target="_arcjet-home">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/arcjet-logo-dark-planet-arrival.svg">
<img src="https://arcjet.com/arcjet-logo-light-planet-arrival.svg" alt="Arcjet Logo" height="144" width="auto">
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg">
<img src="https://arcjet.com/logo/arcjet-light-lockup-voyage-horizontal.svg" alt="Arcjet Logo" height="128" width="auto">
</picture>
</a>

Expand All @@ -17,11 +17,15 @@
</p>

[Arcjet][arcjet] helps developers protect their apps in just a few lines of
code. Implement rate limiting, bot protection, email verification & defense
code. Implement rate limiting, bot protection, email verification, and defense
against common attacks.

This is the [Arcjet][arcjet] SDK for [SvelteKit][sveltekit].

## Getting started

Visit the [quick start guide][quick-start] to get started.

## Example app

Try an Arcjet protected app live at [https://example.arcjet.com][example-url]
Expand Down Expand Up @@ -127,6 +131,7 @@ Licensed under the [Apache License, Version 2.0][apache-license].
[arcjet]: https://arcjet.com
[sveltekit]: https://kit.svelte.dev/
[example-url]: https://example.arcjet.com
[quick-start]: https://docs.arcjet.com/get-started/sveltekit
[example-source]: https://github.com/arcjet/arcjet-js-example
[rate-limit-concepts-docs]: https://docs.arcjet.com/rate-limiting/concepts
[shield-concepts-docs]: https://docs.arcjet.com/shield/concepts
Expand Down
6 changes: 3 additions & 3 deletions arcjet/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<a href="https://arcjet.com" target="_arcjet-home">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/arcjet-logo-minimal-dark-mark-all.svg">
<img src="https://arcjet.com/arcjet-logo-minimal-light-mark-all.svg" alt="Arcjet Logo" height="128" width="auto">
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg">
<img src="https://arcjet.com/logo/arcjet-light-lockup-voyage-horizontal.svg" alt="Arcjet Logo" height="128" width="auto">
</picture>
</a>

Expand All @@ -17,7 +17,7 @@
</p>

[Arcjet][arcjet] helps developers protect their apps in just a few lines of
code. Implement rate limiting, bot protection, email verification & defense
code. Implement rate limiting, bot protection, email verification, and defense
against common attacks.

This is the [Arcjet][arcjet] TypeScript and JavaScript SDK core.
Expand Down
4 changes: 2 additions & 2 deletions decorate/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<a href="https://arcjet.com" target="_arcjet-home">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/arcjet-logo-dark-planet-arrival.svg">
<img src="https://arcjet.com/arcjet-logo-light-planet-arrival.svg" alt="Arcjet Logo" height="144" width="auto">
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg">
<img src="https://arcjet.com/logo/arcjet-light-lockup-voyage-horizontal.svg" alt="Arcjet Logo" height="128" width="auto">
</picture>
</a>

Expand Down
4 changes: 2 additions & 2 deletions duration/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<a href="https://arcjet.com" target="_arcjet-home">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/arcjet-logo-dark-planet-arrival.svg">
<img src="https://arcjet.com/arcjet-logo-light-planet-arrival.svg" alt="Arcjet Logo" height="144" width="auto">
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg">
<img src="https://arcjet.com/logo/arcjet-light-lockup-voyage-horizontal.svg" alt="Arcjet Logo" height="128" width="auto">
</picture>
</a>

Expand Down
4 changes: 2 additions & 2 deletions eslint-config/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<a href="https://arcjet.com" target="_arcjet-home">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/arcjet-logo-dark-planet-arrival.svg">
<img src="https://arcjet.com/arcjet-logo-light-planet-arrival.svg" alt="Arcjet Logo" height="144" width="auto">
<source media="(prefers-color-scheme: dark)" srcset="https://arcjet.com/logo/arcjet-dark-lockup-voyage-horizontal.svg">
<img src="https://arcjet.com/logo/arcjet-light-lockup-voyage-horizontal.svg" alt="Arcjet Logo" height="128" width="auto">
</picture>
</a>

Expand Down
56 changes: 37 additions & 19 deletions examples/bun-rl/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import arcjet, { fixedWindow, shield } from "@arcjet/bun";
import arcjet, { shield, tokenBucket } from "@arcjet/bun";

const aj = arcjet({
key: Bun.env.ARCJET_KEY!,
key: Bun.env.ARCJET_KEY!, // Get your site key from https://app.arcjet.com
rules: [
// Shield protects your app from common attacks like SQL injection
shield({ mode: "LIVE" }),
fixedWindow({
mode: "LIVE",
max: 1,
window: "1m",
// 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
}),
],
});
Expand All @@ -16,30 +20,44 @@ const aj = arcjet({
export default {
port: 3000,
fetch: aj.handler(async (req) => {
const decision = await aj.protect(req);
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 request ID", decision.id);
console.log("Arcjet decision", decision.conclusion);

if (decision.isDenied()) {
return new Response("Blocked", { status: 403 });
if (decision.reason.isRateLimit()) {
return new Response("Too many requests", { status: 429 });
} else {
return new Response("Forbidden", { status: 403 });
}
}

return new Response("Hello world");
}),
};

// Or using the `Bun.serve()` API
// const server = Bun.serve({
// port: 3000,
// fetch: aj.handler(async (req) => {
// const decision = await aj.protect(req);
/*
const server = Bun.serve({
davidmytton marked this conversation as resolved.
Show resolved Hide resolved
port: 3000,
fetch: aj.handler(async (req) => {
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 request ID", decision.id);
console.log("Arcjet decision", decision.conclusion);

// if (decision.isDenied()) {
// return new Response("Blocked", { status: 403 });
// }
if (decision.isDenied()) {
if (decision.reason.isRateLimit()) {
return new Response("Too many requests", { status: 429 });
} else {
return new Response("Forbidden", { status: 403 });
}
}

// return new Response("Hello world");
// }),
// });
return new Response("Hello world");
}),
});

// console.log(`Listening on ${server.url}`);
console.log(`Listening on ${server.url}`);
*/
1 change: 0 additions & 1 deletion examples/nextjs-example/.env.local.example

This file was deleted.

Loading
Loading