Skip to content

Commit

Permalink
Merge branch 'main' of github.com:arcjet/arcjet-js into eoin/refactor…
Browse files Browse the repository at this point in the history
…-wasm-loader
  • Loading branch information
e-moran committed Oct 15, 2024
2 parents 8e474a1 + 32d6d41 commit 9de9361
Show file tree
Hide file tree
Showing 115 changed files with 21,977 additions and 1,308 deletions.
1 change: 1 addition & 0 deletions .github/.release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"arcjet-nest": "1.0.0-alpha.27",
"arcjet-next": "1.0.0-alpha.27",
"arcjet-node": "1.0.0-alpha.27",
"arcjet-remix": "1.0.0-alpha.27",
"arcjet-sveltekit": "1.0.0-alpha.27",
"body": "1.0.0-alpha.27",
"decorate": "1.0.0-alpha.27",
Expand Down
53 changes: 53 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,34 @@ updates:
- dependency-name: "@typescript-eslint/eslint-plugin"
versions: [">=8"]

- package-ecosystem: npm
directory: /examples/nestjs-graphql
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:
# NestJS uses Express 4
- dependency-name: "@types/express"
versions: [">=5"]
# TODO(#539): Upgrade to eslint 9
- dependency-name: eslint
versions: [">=9"]
- dependency-name: "@typescript-eslint/parser"
versions: [">=8"]
- dependency-name: "@typescript-eslint/eslint-plugin"
versions: [">=8"]

- package-ecosystem: npm
directory: /examples/nestjs-launchdarkly
schedule:
Expand Down Expand Up @@ -681,6 +709,31 @@ updates:
patterns:
- "*"

- package-ecosystem: npm
directory: /examples/remix-express
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:
# TODO(#539): Upgrade to eslint 9
- dependency-name: eslint
versions: [">=9"]
- dependency-name: "@typescript-eslint/parser"
versions: [">=8"]
- dependency-name: "@typescript-eslint/eslint-plugin"
versions: [">=8"]

- package-ecosystem: npm
directory: /examples/sveltekit
schedule:
Expand Down
5 changes: 5 additions & 0 deletions .github/release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
"component": "@arcjet/node",
"skip-github-release": true
},
"arcjet-remix": {
"component": "@arcjet/remix",
"skip-github-release": true
},
"arcjet-sveltekit": {
"component": "@arcjet/sveltekit",
"skip-github-release": true
Expand Down Expand Up @@ -142,6 +146,7 @@
"@arcjet/nest",
"@arcjet/next",
"@arcjet/node",
"@arcjet/remix",
"@arcjet/sveltekit",
"@arcjet/decorate",
"@arcjet/duration",
Expand Down
80 changes: 80 additions & 0 deletions .github/workflows/reusable-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,46 @@ jobs:
working-directory: examples/nestjs-fastify
run: npm run build

nestjs-graphql:
name: NestJS + GraphQL
runs-on: ubuntu-latest
permissions:
contents: read
steps:
# Environment security
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
github.com:443
registry.npmjs.org:443
# Checkout
# Most toolchains require checkout first
- name: Checkout
uses: actions/checkout@v4

# Language toolchains
- name: Install Node
uses: actions/[email protected]
with:
node-version: 20

# Workflow

- name: Install dependencies
run: npm ci

- name: Install example dependencies
working-directory: examples/nestjs-graphql
run: npm ci

- name: Build
working-directory: examples/nestjs-graphql
run: npm run build

nestjs-launchdarkly:
name: NestJS + LaunchDarkly
runs-on: ubuntu-latest
Expand Down Expand Up @@ -711,6 +751,46 @@ jobs:
working-directory: examples/nodejs-hono-rl
run: npm run build

remix-express:
name: Remix + Express
runs-on: ubuntu-latest
permissions:
contents: read
steps:
# Environment security
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
github.com:443
registry.npmjs.org:443
# Checkout
# Most toolchains require checkout first
- name: Checkout
uses: actions/checkout@v4

# Language toolchains
- name: Install Node
uses: actions/[email protected]
with:
node-version: 20

# Workflow

- name: Install dependencies
run: npm ci

- name: Install example dependencies
working-directory: examples/remix-express
run: npm ci

- name: Build
working-directory: examples/remix-express
run: npm run build

sveltekit:
name: SvelteKit
runs-on: ubuntu-latest
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ for JS.

- **Bun?** Use the [`@arcjet/bun`][npm-bun] package with our [Bun quick start
guide][bun-quick-start].
- **Deno?** Use the [`npm:@arcjet/deno`][npm-deno] package with our [Deno quick
start guide][deno-quick-start].
- **NestJS?** Use the [`@arcjet/nest`][npm-nest] package with our [NestJS
quick start guide][nest-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
Expand Down Expand Up @@ -153,6 +157,8 @@ find a specific one through the categories and descriptions below.
### SDKs

- [`@arcjet/bun`](./arcjet-bun/README.md): SDK for Bun.sh.
- [`@arcjet/deno`](./arcjet-deno/README.md): SDK for Deno.
- [`@arcjet/nest`](./arcjet-nest/README.md): SDK for NestJS.
- [`@arcjet/next`](./arcjet-next/README.md): SDK for the Next.js framework.
- [`@arcjet/node`](./arcjet-node/README.md): SDK for Node.js.
- [`@arcjet/sveltekit`](./arcjet-sveltekit/README.md): SDK for SvelteKit.
Expand Down Expand Up @@ -205,8 +211,12 @@ Licensed under the [Apache License, Version 2.0][apache-license].

[arcjet]: https://arcjet.com
[npm-bun]: https://www.npmjs.com/package/@arcjet/bun
[npm-deno]: https://www.npmjs.com/package/@arcjet/deno
[npm-nest]: https://www.npmjs.com/package/@arcjet/nest
[npm-next]: https://www.npmjs.com/package/@arcjet/next
[bun-quick-start]: https://docs.arcjet.com/get-started/bun
[deno-quick-start]: https://docs.arcjet.com/get-started/deno
[nest-quick-start]: https://docs.arcjet.com/get-started/nest
[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
Expand Down
Binary file modified analyze-wasm/wasm/arcjet_analyze_js_req.component.core.wasm
Binary file not shown.
Binary file modified analyze-wasm/wasm/arcjet_analyze_js_req.component.core2.wasm
Binary file not shown.
Binary file modified analyze-wasm/wasm/arcjet_analyze_js_req.component.core3.wasm
Binary file not shown.
Binary file modified analyze-wasm/wasm/arcjet_analyze_js_req.component.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion analyze/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@arcjet/tsconfig": "1.0.0-alpha.27",
"@bytecodealliance/jco": "1.5.0",
"@jest/globals": "29.7.0",
"@rollup/wasm-node": "4.23.0",
"@rollup/wasm-node": "4.24.0",
"@types/node": "18.18.0",
"jest": "29.7.0",
"typescript": "5.6.2"
Expand Down
2 changes: 1 addition & 1 deletion arcjet-bun/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@arcjet/tsconfig": "1.0.0-alpha.27",
"@jest/globals": "29.7.0",
"@types/node": "20.12.12",
"@rollup/wasm-node": "4.23.0",
"@rollup/wasm-node": "4.24.0",
"bun-types": "1.1.29",
"jest": "29.7.0",
"typescript": "5.6.2"
Expand Down
2 changes: 1 addition & 1 deletion arcjet-deno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@arcjet/tsconfig": "1.0.0-alpha.27",
"@jest/globals": "29.7.0",
"@types/deno": "2.0.0",
"@rollup/wasm-node": "4.23.0",
"@rollup/wasm-node": "4.24.0",
"jest": "29.7.0",
"typescript": "5.6.2"
},
Expand Down
45 changes: 44 additions & 1 deletion arcjet-nest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Inject, SetMetadata } from "@nestjs/common";
import type {
CanActivate,
ConfigurableModuleAsyncOptions,
ContextType,
DynamicModule,
ExecutionContext,
FactoryProvider,
Expand Down Expand Up @@ -376,6 +377,43 @@ export const ARCJET = Symbol("ARCJET");
const ARCJET_OPTIONS = Symbol("ARCJET_OPTIONS");
const ARCJET_WITH_RULES = Symbol("ARCJET_WITH_RULES");

type GqlContextType = "graphql" | ContextType;

function requestFromContext(context: ExecutionContext) {
const contextType = context.getType<GqlContextType>();
switch (contextType) {
case "graphql": {
// The `req` property should exist on the context at position 2
// https://github.com/nestjs/graphql/blob/8d19548dd8cb8c6d6003552673a6646603d2e22f/packages/graphql/lib/services/gql-execution-context.ts#L37
const ctx = context.getArgByIndex<{ req?: ArcjetNestRequest }>(2);
if (typeof ctx === "object" && ctx !== null && "req" in ctx) {
return ctx.req;
}

// If it isn't there for some reason, we just return undefined
return;
}
case "http": {
// The request object is at position 0
// https://github.com/nestjs/nest/blob/9825529f405fa6064eb98d8ecb2a5d3d5f1e41f9/packages/core/helpers/execution-context-host.ts#L52
return context.getArgByIndex<ArcjetNestRequest>(0);
}
case "ws": {
// TODO: Figure out if we can support "ws" context types
return;
}
case "rpc": {
// TODO: Figure out if we can support "rpc" context types
return;
}
default: {
// Avoiding the _exhaustive check to avoid some TypeScript errors in with
// different compiler options
return;
}
}
}

let ArcjetGuard = class ArcjetGuard implements CanActivate {
aj: ArcjetNest<WithoutCustomProps>;

Expand All @@ -395,7 +433,12 @@ let ArcjetGuard = class ArcjetGuard implements CanActivate {
aj = rules.reduce((aj, rule) => aj.withRule(rule), aj);
}

const request = context.switchToHttp().getRequest();
const request = requestFromContext(context);

// If we cannot access the request, we "fail open" by allowing the request
if (typeof request === "undefined") {
return true;
}

const decision = await aj.protect(request);

Expand Down
2 changes: 1 addition & 1 deletion arcjet-nest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@arcjet/tsconfig": "1.0.0-alpha.27",
"@jest/globals": "29.7.0",
"@nestjs/common": "^10.4.2",
"@rollup/wasm-node": "4.23.0",
"@rollup/wasm-node": "4.24.0",
"@types/node": "18.18.0",
"jest": "29.7.0",
"typescript": "5.6.2"
Expand Down
2 changes: 1 addition & 1 deletion arcjet-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@arcjet/tsconfig": "1.0.0-alpha.27",
"@jest/globals": "29.7.0",
"@types/node": "18.18.0",
"@rollup/wasm-node": "4.23.0",
"@rollup/wasm-node": "4.24.0",
"jest": "29.7.0",
"typescript": "5.6.2"
},
Expand Down
2 changes: 1 addition & 1 deletion arcjet-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@arcjet/tsconfig": "1.0.0-alpha.27",
"@jest/globals": "29.7.0",
"@types/node": "18.18.0",
"@rollup/wasm-node": "4.23.0",
"@rollup/wasm-node": "4.24.0",
"jest": "29.7.0",
"typescript": "5.6.2"
},
Expand Down
6 changes: 6 additions & 0 deletions arcjet-remix/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/.turbo/
/coverage/
/node_modules/
*.d.ts
*.js
!*.config.js
4 changes: 4 additions & 0 deletions arcjet-remix/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ["@arcjet/eslint-config"],
};
Loading

0 comments on commit 9de9361

Please sign in to comment.