customerio / customerio-node

A node.js client for the Customer.io REST API.
https://customer.io/docs/api/
MIT License
55 stars 35 forks source link

Support Edge environments #146

Open lopezjurip opened 1 year ago

lopezjurip commented 1 year ago

This project relies on the native "http" / "https" modules from Node.js which are not compatible on Edge environments such as Cloudflare Workers, Next.js Edge Routes / middleware nor AWS Lambda Edge.

I would recommend a version built on top of "fetch" witch is getting a native Node.js implementation.

mike-engel commented 1 year ago

@lopezjurip Thanks for this issue—I wasn't aware that those edge platforms didn't implement those node modules.

Support for this, while being backwards compatible with the latest LTS, seems a bit tricky. Are you aware of any packages that make http requests that support both native node.js and edge platforms? What does the error look like when using this?

mkcode commented 1 year ago

I would also really like to see edge support in this library. I am currently using the web API directly to workaround this.

@mike-engel - fetch is natively supported in all edge runtimes and also natively supported in Node 18 and higher: https://nodejs.org/en/blog/announcements/v18-release-announce#fetch-experimental

It can be polyfilled to older Node versions using this library: https://github.com/node-fetch/node-fetch/tree/main

A native implementation can simply be checked for and polyfilled if not present, like done here: https://github.com/lquixada/cross-fetch/blob/v4.x/src/node-polyfill.js

It looks like this project would need a big overhaul to replace http with fetch, but working in all JS environments is really important future proofing!

mkcode commented 1 year ago

And we are now past the EOL for Node 16, so no polyfill needed if you minimally support Node 18 and higher: https://nodejs.dev/en/about/releases/

derek-cove commented 1 month ago

+1 on wanting a library that can run on edge. Any update on this? Would this ever be prioritized?

@mkcode - do you have any code for using the web API directly that you could share?