statsig-io / node-js-server-sdk

Statsig's SDK for server-side Node.js applications.
ISC License
20 stars 15 forks source link

Edge Runtime support #17

Closed dferber90 closed 1 year ago

dferber90 commented 1 year ago

I'm trying to use this package in a Next.js Edge API Route or a Middleware.

These two places use a special Edge Runtime which has constraints different from Node.js, for example Buffer does not exist there.

At the moment getHashedName and computeUserHash are using the sha.js package which internally uses Buffer. This prevents the package from being usable from Edge Runtime.

Both Edge Runtime supports and Node.js support SubtleCrypto mdn, (edge-runtime) so it might be possible to switch both functions to this implementation.

This change would allow the package to be used from Next.js Middleware and Edge API Routes.

tore-statsig commented 1 year ago

Interesting, thanks for the detailed issue. We will look into it