Arcjet helps developers protect their apps in just a few lines of
code. Implement rate limiting, bot protection, email verification, and defense
against common attacks.
This is the Arcjet TypeScript and JavaScript SDK core.
Generally, you'll want to use the Arcjet SDK for your specific framework, such
as @arcjet/next for Next.js. However, this package
can be used to interact with Arcjet if your framework does not have an
integration.
Installation
npm install -S arcjet
Example
import http from"http";
import arcjet, { createRemoteClient } from"arcjet";
import { baseUrl } from"@arcjet/env";
import { createConnectTransport } from"@connectrpc/connect-node";
const aj = arcjet({
// Get your site key from https://app.arcjet.com// and set it as an environment variable rather than hard coding.// See: https://www.npmjs.com/package/dotenvkey: process.env.ARCJET_KEY,
rules: [],
client: createRemoteClient({
transport: createConnectTransport({
baseUrl: baseUrl(process.env),
httpVersion: "2",
}),
}),
});
const server = http.createServer(asyncfunction (
req: http.IncomingMessage,
res: http.ServerResponse,
) {
// Any sort of additional context that might want to be included for the// execution of `protect()`. This is mostly only useful for writing adapters.const ctx = {};
// Construct an object with Arcjet request detailsconst path = newURL(req.url || "", `http://${req.headers.host}`);
const details = {
ip: req.socket.remoteAddress,
method: req.method,
host: req.headers.host,
path: path.pathname,
};
const decision = await aj.protect(ctx, details);
console.log(decision);
if (decision.isDenied()) {
res.writeHead(403, { "Content-Type": "application/json" });
res.end(JSON.stringify({ error: "Forbidden" }));
} else {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ data: "Hello World!" }));
}
});
server.listen(8000);
sdk: Inform type signature of protect via global characteristics (#1043) (1ae4a89), closes #1042
📦 Dependencies
Bump @typescript-eslint/eslint-plugin from 7.13.0 to 7.13.1 (#994) (9481c7f)
Bump @typescript-eslint/eslint-plugin from 7.13.1 to 7.14.1 (#1025) (7e8cc60)
Bump @typescript-eslint/parser from 7.13.0 to 7.13.1 (#993) (d15a09d)
Bump @typescript-eslint/parser from 7.13.1 to 7.14.1 (#1024) (ee81b09)
Bump eslint-config-turbo from 2.0.4 to 2.0.5 (#1023) (aaaf17c)
Bump eslint-config-turbo from 2.0.5 to 2.0.6 (#1052) (e1d3cd3)
dev: Bump bun-types from 1.1.13 to 1.1.17 (#1022) (3aa7181)
dev: Bump typescript from 5.4.5 to 5.5.2 (#1011) (c17a101)
example: Bump @clerk/nextjs from 5.1.5 to 5.1.6 in /examples/nextjs-14-clerk-rl in the dependencies group (#1013) (8bed1dc)
example: Bump @clerk/nextjs from 5.1.5 to 5.1.6 in /examples/nextjs-14-clerk-shield in the dependencies group (#1012) (c4bcde8)
example: Bump @sveltejs/kit from 2.5.17 to 2.5.18 in /examples/sveltekit in the dependencies group (#1046) (ebab7de)
example: Bump ai from 3.1.36 to 3.1.37 in /examples/nextjs-14-openai in the dependencies group (#995) (b43827b)
example: Bump hono from 4.4.9 to 4.4.10 in /examples/nodejs-hono-rl in the dependencies group (#1048) (6e7c1fe)
example: Bump lucide-react from 0.396.0 to 0.399.0 in /examples/nextjs-14-authjs-5 in the dependencies group across 1 directory (#1040) (ea96487)
example: Bump lucide-react from 0.396.0 to 0.399.0 in /examples/nextjs-14-react-hook-form in the dependencies group across 1 directory (#1039) (334ff9e)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-app-dir-rl in the dependencies group (#1051) (ac24a0b)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-app-dir-validate-email in the dependencies group (#1045) (290bc49)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-authjs-5 in the dependencies group (#1056) (e2343f0)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-clerk-rl in the dependencies group (#1058) (422b320)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-clerk-shield in the dependencies group (#1044) (b6b891f)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-decorate in the dependencies group (#1049) (43523a5)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-ip-details in the dependencies group (#1047) (1fe6a05)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-nextauth-4 in the dependencies group (#1054) (caff3dc)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-pages-wrap in the dependencies group (#1055) (90e04f5)
example: Bump postcss from 8.4.38 to 8.4.39 in /examples/nextjs-14-react-hook-form in the dependencies group (#1050) (21e1108)
example: Bump the dependencies group across 1 directory with 2 updates (#1006) (0578cb2)
example: Bump the dependencies group across 1 directory with 2 updates (#1019) (a15df12)
example: Bump the dependencies group across 1 directory with 6 updates (#1017) (fb43c78)
example: Bump the dependencies group across 1 directory with 7 updates (#1028) (a3693d0)
example: Bump the dependencies group across 1 directory with 7 updates (#1036) (4e2bfe9)
example: Bump the dependencies group in /examples/nextjs-14-openai with 2 updates (#1057) (5df2e47)
example: Bump the dependencies group in /examples/nextjs-14-react-hook-form with 2 updates (#996) (988dbf3)
example: Bump the dependencies group in /examples/nodejs-hono-rl with 2 updates (#1007) (c36b9f3)
Move generated protobuf to default buf file path (#1009) (6800a00)
Warn when IP is empty, even if we override it in development (#1000) (da14bcb), closes #987#216
FAQs
Arcjet TypeScript and JavaScript SDK core
The npm package arcjet receives a total of 281 weekly downloads. As such, arcjet popularity was classified as not popular.
We found that arcjet demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 2 open source maintainers collaborating on the project.
Package last updated on 01 Jul 2024
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
The 2023 Python Developers Survey reveals key trends in packaging, web frameworks, and developer demographics, highlighting a shift toward innovative tools as the Python community diversifies and grows among less experienced developers.
GitHub is combatting a new spam campaign that exploits issues with links to malicious downloads, highlighting the need for better moderation tools to protect open-source maintainers' time and security.
uv, Python's new package manager, offers a faster and more efficient alternative to pip with features that simplify tooling, manage Python versions, and streamline development workflows.