Isomorphic SDK support
See original GitHub issueHey! Congratulations on public notion API and awesome work on minimal and typed js SDK 💯
As of the current version, this package seems to only work with node.js, which makes missing lots of opportunities for supporting non-nodejs environments such as Deno, Cloudflare workers, universal frameworks like Nuxt.js , and frontend libraries like vue-notion this can open LOTS of new opportunities for using sdk.
For this change, we need to avoid depending on got
and using a universal alternative (fetch
) API. Since request
is already refactored, it would be easy to allow providing custom client implementation or creating multi-target bundles (see ohmyfetch as an example) that importing @notionhq/client
be as is now but having @notionhq/client/isomorphic
import (or /node
import) that is preconfigured with either node-fetch or got or faster node clients like nodejs/undici / undici-fetch
I can propose a PR if above seems reasonable for purpose of notion-sdk.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:41
- Comments:16 (3 by maintainers)
Top GitHub Comments
+1 Came here surprised to see that it doesn’t support Cloudflare Workers yet, since Notion API makes the perfect case for doing automation with 0-ms cold boot start server-less platforms.
I vote for having a
requestClient
parameter for flexibility, but at the same time I think also having support by default (ie. being tested and having official support) for most popular platforms outside Node would be a very important thing for the future of this project (and the growing community).It looks like ky allows providing one’s own fetch function compatible with the browser API.
I don’t feel like ky provides a huge benefit over fetch - it’s not so hard to write one’s own wrappers around the API if need be and less abstractions usually means easier debugging in my experience.
I think passing in a fetch function is a good pattern though.