arcjet / arcjet-js

Arcjet JS SDKs. Bot detection, rate limiting, email validation, attack protection, data redaction for Node.js, Next.js, Deno, Bun, SvelteKit, NestJS.
https://arcjet.com
Apache License 2.0
267 stars 7 forks source link

Consider making `validate` an async function #1391

Open blaine-arcjet opened 2 months ago

blaine-arcjet commented 2 months ago

It feels like validate is where we should check if the body is available but I think it's sync which makes it impossible 🤦 We might revisit that in the future.

We may want to revisit the API of validate in entirety. For example, if you called getBody() inside it, how would you access the body in protect()?

_Originally posted by @blaine-arcjet in https://github.com/arcjet/arcjet-js/pull/1300#discussion_r1723961227_

blaine-arcjet commented 2 months ago

See also: #1520

blaine-arcjet commented 1 month ago

I looked into this a bit and it needs more work than just making it an async function because we can't assert the validation via TypeScript.

I think we're going to want to return a value that is the details passed to protect() but I didn't get very far on that work before stashing it.