Socket
Socket
Sign inDemoInstall

arcjet

Package Overview
Dependencies
Maintainers
2
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arcjet - npm Package Compare versions

Comparing version 1.0.0-alpha.24 to 1.0.0-alpha.25

20

package.json
{
"name": "arcjet",
"version": "1.0.0-alpha.24",
"version": "1.0.0-alpha.25",
"description": "Arcjet TypeScript and JavaScript SDK core",

@@ -43,12 +43,12 @@ "license": "Apache-2.0",

"dependencies": {
"@arcjet/analyze": "1.0.0-alpha.24",
"@arcjet/duration": "1.0.0-alpha.24",
"@arcjet/headers": "1.0.0-alpha.24",
"@arcjet/protocol": "1.0.0-alpha.24",
"@arcjet/runtime": "1.0.0-alpha.24"
"@arcjet/analyze": "1.0.0-alpha.25",
"@arcjet/duration": "1.0.0-alpha.25",
"@arcjet/headers": "1.0.0-alpha.25",
"@arcjet/protocol": "1.0.0-alpha.25",
"@arcjet/runtime": "1.0.0-alpha.25"
},
"devDependencies": {
"@arcjet/eslint-config": "1.0.0-alpha.24",
"@arcjet/rollup-config": "1.0.0-alpha.24",
"@arcjet/tsconfig": "1.0.0-alpha.24",
"@arcjet/eslint-config": "1.0.0-alpha.25",
"@arcjet/rollup-config": "1.0.0-alpha.25",
"@arcjet/tsconfig": "1.0.0-alpha.25",
"@edge-runtime/jest-environment": "3.0.3",

@@ -59,3 +59,3 @@ "@jest/globals": "29.7.0",

"jest": "29.7.0",
"typescript": "5.5.4"
"typescript": "5.6.2"
},

@@ -62,0 +62,0 @@ "publishConfig": {

@@ -40,7 +40,14 @@ <a href="https://arcjet.com" target="_arcjet-home">

## Example
## Rate limit + bot detection example
The 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.
Bot detection is also enabled to block requests from known bots.
```ts
import http from "http";
import arcjet, { createRemoteClient } from "arcjet";
import arcjet, { createRemoteClient, tokenBucket, detectBot } from "arcjet";
import { baseUrl } from "@arcjet/env";

@@ -54,3 +61,18 @@ import { createConnectTransport } from "@connectrpc/connect-node";

key: process.env.ARCJET_KEY,
rules: [],
characteristics: ["userId"], // track requests by a custom user ID
rules: [
// Create a token bucket rate limit. Other algorithms are supported.
tokenBucket({
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
refillRate: 5, // refill 5 tokens per interval
interval: 10, // refill every 10 seconds
capacity: 10, // bucket maximum capacity of 10 tokens
}),
detectBot({
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
// configured with a list of bots to allow from
// https://arcjet.com/bot-list
allow: [], // "allow none" will block all detected bots
}),
],
client: createRemoteClient({

@@ -81,3 +103,3 @@ transport: createConnectTransport({

const decision = await aj.protect(ctx, details);
const decision = await aj.protect(ctx, details, { requested: 5 }); // Deduct 5 tokens from the bucket
console.log(decision);

@@ -84,0 +106,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc