PaddleHQ / paddle-node-sdk

Node.js SDK for working with the Paddle API in server-side apps.
https://developer.paddle.com/
Apache License 2.0
42 stars 6 forks source link

[Feature]: Support Cloudflare #9

Closed mw10013 closed 5 months ago

mw10013 commented 7 months ago

Tell us about your feature request

Tweak paddle-node-sdk so that it runs on Cloudflare.

What problem are you looking to solve?

paddle-node-sdk does not run on Cloudflare because it imports crypto without a node: prefix. Node.js compatibility in Cloudflare requires the node: prefix per https://developers.cloudflare.com/workers/runtime-apis/nodejs/

paddle-node-sdk is cjs and node:crypto on Cloudflare seems to be esm. Cjs must use a dynamic import to import esm.

Additional context

No response

How important is this suggestion to you?

Critical

vijayasingam-paddle commented 6 months ago

Hi @mw10013, Brilliant feedback and thank you for the Pull request.

We will do some testing and get back to you.

Thank you.

vijayasingam-paddle commented 6 months ago

Hi @mw10013, We checked your PR and we agree that changing the two offending imports might fix the problem for now. However, there is a good chance we could start using some other Node JS feature breaking the ESM compatibility.

As a strategic solution, We have updated the package to export both CommonJS and ESM format so that the build systems can pick up the appropriate format.

We have released a beta version 1.3.0-beta.0 to trial this approach. We will move it to the main branch after it is field tested for a while.

Please use the new version and let us know how it goes.

Thank you.

mw10013 commented 6 months ago

@vijayasingam-paddle 1.3.0-beta.0 works in my paddle-cloudflare-worker smoke test (https://paddle-cloudflare-worker.mw10013.workers.dev/ displays the first page of products). Also, in the project I'm working on which includes reconciling database with paddle, changing subscriptions, and webhook. Gratitude!