arcjet / arcjet-js

Arcjet JS SDKs. Rate limiting, bot protection, email verification & attack defense for Node.js, Next.js, Bun & SvelteKit.
https://arcjet.com
Apache License 2.0
173 stars 3 forks source link

fix(sdk): Inform type signature of protect via global characteristics #1043

Closed blaine-arcjet closed 1 week ago

blaine-arcjet commented 1 week ago

This attaches the characteristics key of the SDK configuration into the types of protect(). We leverage some type magic to ensure users specify all data needed when they are using user-defined characteristics.

I totally forgot about this when reviewing the initial PR, but we're lucky to have caught it before the release.

I also needed to fix the tests because the way they were originally written allowed the required request fields to be excluded. @e-moran It's worth noting that rules always need to be directly specified in the rules: [] array for TypeScript's inference to work properly—which avoids the need to annotate your variables. We are able to use as const on the characteristic arrays, but that isn't allowed on function calls like rateLimit().

Closes #1042

trunk-io[bot] commented 1 week ago

😎 Merged successfully - details.