From 9476b085419ae492a8b6c3b5d59e619648723c32 Mon Sep 17 00:00:00 2001 From: David Mytton Date: Sat, 10 Feb 2024 16:19:27 +0000 Subject: [PATCH] docs(examples): Additional comments --- .../pages/api/arcjet-edge.ts | 8 +- .../nextjs-13-pages-wrap/pages/api/arcjet.ts | 8 +- .../app/api/arcjet/route.ts | 11 +- .../app/api/custom_timeout/route.ts | 4 +- .../app/api/arcjet/route.ts | 4 +- .../nextjs-14-pages-wrap/.env.local.example | 1 + examples/nextjs-14-pages-wrap/README.md | 6 +- .../nextjs-14-pages-wrap/environment.d.ts | 5 + .../nextjs-14-pages-wrap/package-lock.json | 110 ++++++++---------- examples/nextjs-14-pages-wrap/package.json | 4 +- .../pages/api/arcjet-edge.ts | 8 +- .../nextjs-14-pages-wrap/pages/api/arcjet.ts | 8 +- 12 files changed, 86 insertions(+), 91 deletions(-) create mode 100644 examples/nextjs-14-pages-wrap/.env.local.example create mode 100644 examples/nextjs-14-pages-wrap/environment.d.ts diff --git a/examples/nextjs-13-pages-wrap/pages/api/arcjet-edge.ts b/examples/nextjs-13-pages-wrap/pages/api/arcjet-edge.ts index a177e9e6c..971061b7d 100644 --- a/examples/nextjs-13-pages-wrap/pages/api/arcjet-edge.ts +++ b/examples/nextjs-13-pages-wrap/pages/api/arcjet-edge.ts @@ -12,12 +12,14 @@ const aj = arcjet({ // See: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables key: process.env.ARCJET_KEY, rules: [ + // Fixed window rate limit. Arcjet also supports sliding window and token + // bucket. fixedWindow({ - mode: "LIVE", + mode: "LIVE", // will block requests. Use "DRY_RUN" to log only // Limiting by ip.src is the default if not specified //characteristics: ["ip.src"], - window: "1m", - max: 1, + window: "1m", // 1 min fixed window + max: 1, // allow a single request (for demo purposes) }), ], }); diff --git a/examples/nextjs-13-pages-wrap/pages/api/arcjet.ts b/examples/nextjs-13-pages-wrap/pages/api/arcjet.ts index b03097038..30a69647a 100644 --- a/examples/nextjs-13-pages-wrap/pages/api/arcjet.ts +++ b/examples/nextjs-13-pages-wrap/pages/api/arcjet.ts @@ -8,12 +8,14 @@ const aj = arcjet({ // See: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables key: process.env.ARCJET_KEY, rules: [ + // Fixed window rate limit. Arcjet also supports sliding window and token + // bucket. fixedWindow({ - mode: "LIVE", + mode: "LIVE", // will block requests. Use "DRY_RUN" to log only // Limiting by ip.src is the default if not specified //characteristics: ["ip.src"], - window: "1m", - max: 1, + window: "1m", // 1 min fixed window + max: 1, // allow a single request (for demo purposes) }), ], }); diff --git a/examples/nextjs-14-app-dir-rl/app/api/arcjet/route.ts b/examples/nextjs-14-app-dir-rl/app/api/arcjet/route.ts index 94dfe92aa..31cc33ad0 100644 --- a/examples/nextjs-14-app-dir-rl/app/api/arcjet/route.ts +++ b/examples/nextjs-14-app-dir-rl/app/api/arcjet/route.ts @@ -7,11 +7,14 @@ const aj = arcjet({ // See: https://nextjs.org/docs/app/building-your-application/configuring/environment-variables key: process.env.ARCJET_KEY!, rules: [ + // Fixed window rate limit. Arcjet also supports sliding window and token + // bucket. fixedWindow({ - mode: "LIVE", - characteristics: ["ip.src"], - window: "1h", - max: 1, + mode: "LIVE", // will block requests. Use "DRY_RUN" to log only + // Limiting by ip.src is the default if not specified + //characteristics: ["ip.src"], + window: "1m", // 1 min fixed window + max: 1, // allow a single request (for demo purposes) }), ], }); diff --git a/examples/nextjs-14-app-dir-rl/app/api/custom_timeout/route.ts b/examples/nextjs-14-app-dir-rl/app/api/custom_timeout/route.ts index 21ac3bf26..494e43890 100644 --- a/examples/nextjs-14-app-dir-rl/app/api/custom_timeout/route.ts +++ b/examples/nextjs-14-app-dir-rl/app/api/custom_timeout/route.ts @@ -17,8 +17,8 @@ const aj = arcjet({ key: process.env.ARCJET_KEY!, rules: [ validateEmail({ - mode: "LIVE", - block: ["NO_MX_RECORDS"], + mode: "LIVE", // will block requests. Use "DRY_RUN" to log only + block: ["NO_MX_RECORDS"], // block email addresses with no MX records }), ], client, diff --git a/examples/nextjs-14-app-dir-validate-email/app/api/arcjet/route.ts b/examples/nextjs-14-app-dir-validate-email/app/api/arcjet/route.ts index 220315eb5..56a586fec 100644 --- a/examples/nextjs-14-app-dir-validate-email/app/api/arcjet/route.ts +++ b/examples/nextjs-14-app-dir-validate-email/app/api/arcjet/route.ts @@ -8,8 +8,8 @@ const aj = arcjet({ key: process.env.ARCJET_KEY, rules: [ validateEmail({ - mode: "LIVE", - block: ["NO_MX_RECORDS"], + mode: "LIVE", // will block requests. Use "DRY_RUN" to log only + block: ["NO_MX_RECORDS"], // block email addresses with no MX records }), ], }); diff --git a/examples/nextjs-14-pages-wrap/.env.local.example b/examples/nextjs-14-pages-wrap/.env.local.example new file mode 100644 index 000000000..0c183c7ac --- /dev/null +++ b/examples/nextjs-14-pages-wrap/.env.local.example @@ -0,0 +1 @@ +ARCJET_KEY= \ No newline at end of file diff --git a/examples/nextjs-14-pages-wrap/README.md b/examples/nextjs-14-pages-wrap/README.md index b55f13dcc..cf375ddea 100644 --- a/examples/nextjs-14-pages-wrap/README.md +++ b/examples/nextjs-14-pages-wrap/README.md @@ -25,11 +25,7 @@ Route](https://nextjs.org/docs/pages/building-your-application/routing/api-route npm ci ``` -3. Add your Arcjet key to `.env.local` - - ```env - ARCJET_KEY= - ``` +3. Rename `.env.local.example` to `.env.local` and add your Arcjet key. 4. Start the dev server. diff --git a/examples/nextjs-14-pages-wrap/environment.d.ts b/examples/nextjs-14-pages-wrap/environment.d.ts new file mode 100644 index 000000000..9ae2b0722 --- /dev/null +++ b/examples/nextjs-14-pages-wrap/environment.d.ts @@ -0,0 +1,5 @@ +declare namespace NodeJS { + export interface ProcessEnv { + readonly ARCJET_KEY: string; + } +} \ No newline at end of file diff --git a/examples/nextjs-14-pages-wrap/package-lock.json b/examples/nextjs-14-pages-wrap/package-lock.json index c02be4b0d..2ab1a8bf0 100644 --- a/examples/nextjs-14-pages-wrap/package-lock.json +++ b/examples/nextjs-14-pages-wrap/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.0", "dependencies": { "@arcjet/next": "file:../../arcjet-next", - "next": "14.0.4", + "next": "14.1.0", "react": "^18", "react-dom": "^18" }, @@ -268,9 +268,9 @@ } }, "node_modules/@next/env": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/env/-/env-14.0.4.tgz", - "integrity": "sha512-irQnbMLbUNQpP1wcE5NstJtbuA/69kRfzBrpAD7Gsn8zm/CY6YQYc3HQBz8QPxwISG26tIm5afvvVbu508oBeQ==" + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/@next/env/-/env-14.1.0.tgz", + "integrity": "sha512-Py8zIo+02ht82brwwhTg36iogzFqGLPXlRGKQw5s+qP/kMNc4MAyDeEwBKDijk6zTIbegEgu8Qy7C1LboslQAw==" }, "node_modules/@next/eslint-plugin-next": { "version": "14.1.0", @@ -328,9 +328,9 @@ } }, "node_modules/@next/swc-darwin-arm64": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.0.4.tgz", - "integrity": "sha512-mF05E/5uPthWzyYDyptcwHptucf/jj09i2SXBPwNzbgBNc+XnwzrL0U6BmPjQeOL+FiB+iG1gwBeq7mlDjSRPg==", + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.1.0.tgz", + "integrity": "sha512-nUDn7TOGcIeyQni6lZHfzNoo9S0euXnu0jhsbMOmMJUBfgsnESdjN97kM7cBqQxZa8L/bM9om/S5/1dzCrW6wQ==", "cpu": [ "arm64" ], @@ -343,9 +343,9 @@ } }, "node_modules/@next/swc-darwin-x64": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.0.4.tgz", - "integrity": "sha512-IZQ3C7Bx0k2rYtrZZxKKiusMTM9WWcK5ajyhOZkYYTCc8xytmwSzR1skU7qLgVT/EY9xtXDG0WhY6fyujnI3rw==", + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.1.0.tgz", + "integrity": "sha512-1jgudN5haWxiAl3O1ljUS2GfupPmcftu2RYJqZiMJmmbBT5M1XDffjUtRUzP4W3cBHsrvkfOFdQ71hAreNQP6g==", "cpu": [ "x64" ], @@ -358,9 +358,9 @@ } }, "node_modules/@next/swc-linux-arm64-gnu": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.0.4.tgz", - "integrity": "sha512-VwwZKrBQo/MGb1VOrxJ6LrKvbpo7UbROuyMRvQKTFKhNaXjUmKTu7wxVkIuCARAfiI8JpaWAnKR+D6tzpCcM4w==", + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.1.0.tgz", + "integrity": "sha512-RHo7Tcj+jllXUbK7xk2NyIDod3YcCPDZxj1WLIYxd709BQ7WuRYl3OWUNG+WUfqeQBds6kvZYlc42NJJTNi4tQ==", "cpu": [ "arm64" ], @@ -373,9 +373,9 @@ } }, "node_modules/@next/swc-linux-arm64-musl": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.0.4.tgz", - "integrity": "sha512-8QftwPEW37XxXoAwsn+nXlodKWHfpMaSvt81W43Wh8dv0gkheD+30ezWMcFGHLI71KiWmHK5PSQbTQGUiidvLQ==", + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.1.0.tgz", + "integrity": "sha512-v6kP8sHYxjO8RwHmWMJSq7VZP2nYCkRVQ0qolh2l6xroe9QjbgV8siTbduED4u0hlk0+tjS6/Tuy4n5XCp+l6g==", "cpu": [ "arm64" ], @@ -388,9 +388,9 @@ } }, "node_modules/@next/swc-linux-x64-gnu": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.0.4.tgz", - "integrity": "sha512-/s/Pme3VKfZAfISlYVq2hzFS8AcAIOTnoKupc/j4WlvF6GQ0VouS2Q2KEgPuO1eMBwakWPB1aYFIA4VNVh667A==", + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.1.0.tgz", + "integrity": "sha512-zJ2pnoFYB1F4vmEVlb/eSe+VH679zT1VdXlZKX+pE66grOgjmKJHKacf82g/sWE4MQ4Rk2FMBCRnX+l6/TVYzQ==", "cpu": [ "x64" ], @@ -403,9 +403,9 @@ } }, "node_modules/@next/swc-linux-x64-musl": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.0.4.tgz", - "integrity": "sha512-m8z/6Fyal4L9Bnlxde5g2Mfa1Z7dasMQyhEhskDATpqr+Y0mjOBZcXQ7G5U+vgL22cI4T7MfvgtrM2jdopqWaw==", + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.1.0.tgz", + "integrity": "sha512-rbaIYFt2X9YZBSbH/CwGAjbBG2/MrACCVu2X0+kSykHzHnYH5FjHxwXLkcoJ10cX0aWCEynpu+rP76x0914atg==", "cpu": [ "x64" ], @@ -418,9 +418,9 @@ } }, "node_modules/@next/swc-win32-arm64-msvc": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.0.4.tgz", - "integrity": "sha512-7Wv4PRiWIAWbm5XrGz3D8HUkCVDMMz9igffZG4NB1p4u1KoItwx9qjATHz88kwCEal/HXmbShucaslXCQXUM5w==", + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.1.0.tgz", + "integrity": "sha512-o1N5TsYc8f/HpGt39OUQpQ9AKIGApd3QLueu7hXk//2xq5Z9OxmV6sQfNp8C7qYmiOlHYODOGqNNa0e9jvchGQ==", "cpu": [ "arm64" ], @@ -433,9 +433,9 @@ } }, "node_modules/@next/swc-win32-ia32-msvc": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.0.4.tgz", - "integrity": "sha512-zLeNEAPULsl0phfGb4kdzF/cAVIfaC7hY+kt0/d+y9mzcZHsMS3hAS829WbJ31DkSlVKQeHEjZHIdhN+Pg7Gyg==", + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.1.0.tgz", + "integrity": "sha512-XXIuB1DBRCFwNO6EEzCTMHT5pauwaSj4SWs7CYnME57eaReAKBXCnkUE80p/pAZcewm7hs+vGvNqDPacEXHVkw==", "cpu": [ "ia32" ], @@ -448,9 +448,9 @@ } }, "node_modules/@next/swc-win32-x64-msvc": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.0.4.tgz", - "integrity": "sha512-yEh2+R8qDlDCjxVpzOTEpBLQTEFAcP2A8fUFLaWNap9GitYKkKv1//y2S6XY6zsR4rCOPRpU7plYDR+az2n30A==", + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.1.0.tgz", + "integrity": "sha512-9WEbVRRAqJ3YFVqEZIxUqkiO8l1nool1LmNxygr5HWF8AcSYsEpneUDhmjUVJEzO2A04+oPtZdombzzPPkTtgg==", "cpu": [ "x64" ], @@ -2210,11 +2210,6 @@ "node": ">=10.13.0" } }, - "node_modules/glob-to-regexp": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", - "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==" - }, "node_modules/globals": { "version": "13.24.0", "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", @@ -3074,18 +3069,17 @@ "dev": true }, "node_modules/next": { - "version": "14.0.4", - "resolved": "https://registry.npmjs.org/next/-/next-14.0.4.tgz", - "integrity": "sha512-qbwypnM7327SadwFtxXnQdGiKpkuhaRLE2uq62/nRul9cj9KhQ5LhHmlziTNqUidZotw/Q1I9OjirBROdUJNgA==", + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/next/-/next-14.1.0.tgz", + "integrity": "sha512-wlzrsbfeSU48YQBjZhDzOwhWhGsy+uQycR8bHAOt1LY1bn3zZEcDyHQOEoN3aWzQ8LHCAJ1nqrWCc9XF2+O45Q==", "dependencies": { - "@next/env": "14.0.4", + "@next/env": "14.1.0", "@swc/helpers": "0.5.2", "busboy": "1.6.0", - "caniuse-lite": "^1.0.30001406", + "caniuse-lite": "^1.0.30001579", "graceful-fs": "^4.2.11", "postcss": "8.4.31", - "styled-jsx": "5.1.1", - "watchpack": "2.4.0" + "styled-jsx": "5.1.1" }, "bin": { "next": "dist/bin/next" @@ -3094,15 +3088,15 @@ "node": ">=18.17.0" }, "optionalDependencies": { - "@next/swc-darwin-arm64": "14.0.4", - "@next/swc-darwin-x64": "14.0.4", - "@next/swc-linux-arm64-gnu": "14.0.4", - "@next/swc-linux-arm64-musl": "14.0.4", - "@next/swc-linux-x64-gnu": "14.0.4", - "@next/swc-linux-x64-musl": "14.0.4", - "@next/swc-win32-arm64-msvc": "14.0.4", - "@next/swc-win32-ia32-msvc": "14.0.4", - "@next/swc-win32-x64-msvc": "14.0.4" + "@next/swc-darwin-arm64": "14.1.0", + "@next/swc-darwin-x64": "14.1.0", + "@next/swc-linux-arm64-gnu": "14.1.0", + "@next/swc-linux-arm64-musl": "14.1.0", + "@next/swc-linux-x64-gnu": "14.1.0", + "@next/swc-linux-x64-musl": "14.1.0", + "@next/swc-win32-arm64-msvc": "14.1.0", + "@next/swc-win32-ia32-msvc": "14.1.0", + "@next/swc-win32-x64-msvc": "14.1.0" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", @@ -4546,18 +4540,6 @@ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "dev": true }, - "node_modules/watchpack": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.0.tgz", - "integrity": "sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg==", - "dependencies": { - "glob-to-regexp": "^0.4.1", - "graceful-fs": "^4.1.2" - }, - "engines": { - "node": ">=10.13.0" - } - }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/examples/nextjs-14-pages-wrap/package.json b/examples/nextjs-14-pages-wrap/package.json index 1dca4effc..e2af2c990 100644 --- a/examples/nextjs-14-pages-wrap/package.json +++ b/examples/nextjs-14-pages-wrap/package.json @@ -10,7 +10,7 @@ }, "dependencies": { "@arcjet/next": "file:../../arcjet-next", - "next": "14.0.4", + "next": "14.1.0", "react": "^18", "react-dom": "^18" }, @@ -25,4 +25,4 @@ "tailwindcss": "^3.4.1", "typescript": "^5" } -} +} \ No newline at end of file diff --git a/examples/nextjs-14-pages-wrap/pages/api/arcjet-edge.ts b/examples/nextjs-14-pages-wrap/pages/api/arcjet-edge.ts index bafb9abb6..121e953ba 100644 --- a/examples/nextjs-14-pages-wrap/pages/api/arcjet-edge.ts +++ b/examples/nextjs-14-pages-wrap/pages/api/arcjet-edge.ts @@ -12,12 +12,14 @@ const aj = arcjet({ // See: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables key: process.env.ARCJET_KEY!, rules: [ + // Fixed window rate limit. Arcjet also supports sliding window and token + // bucket. fixedWindow({ - mode: "LIVE", + mode: "LIVE", // will block requests. Use "DRY_RUN" to log only // Limiting by ip.src is the default if not specified //characteristics: ["ip.src"], - window: "1m", - max: 1, + window: "1m", // 1 min fixed window + max: 1, // allow a single request (for demo purposes) }), ], }); diff --git a/examples/nextjs-14-pages-wrap/pages/api/arcjet.ts b/examples/nextjs-14-pages-wrap/pages/api/arcjet.ts index fe667c1b2..36f06826a 100644 --- a/examples/nextjs-14-pages-wrap/pages/api/arcjet.ts +++ b/examples/nextjs-14-pages-wrap/pages/api/arcjet.ts @@ -8,12 +8,14 @@ const aj = arcjet({ // See: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables key: process.env.ARCJET_KEY!, rules: [ + // Fixed window rate limit. Arcjet also supports sliding window and token + // bucket. fixedWindow({ - mode: "LIVE", + mode: "LIVE", // will block requests. Use "DRY_RUN" to log only // Limiting by ip.src is the default if not specified //characteristics: ["ip.src"], - window: "1m", - max: 1, + window: "1m", // 1 min fixed window + max: 1, // allow a single request (for demo purposes) }), ], });