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
41 stars 6 forks source link

Support Cloudflare with dynamic import for 'node:crypto' #10

Closed mw10013 closed 6 months ago

mw10013 commented 7 months ago

Closes #9

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.

This PR dynamically imports 'node:crypto'.

In my local environment, 4 tests fail when I run the latest main in paddle-node-sdk. These 4 failures persist with this PR.

Screenshot 2024-03-10 at 8 15 47 PM

https://github.com/mw10013/paddle-cloudflare-worker contains a Cloudflare worker that uses this PR to show the first page of products on Cloudflare. It is deployed here: https://paddle-cloudflare-worker.mw10013.workers.dev/

vijayasingam-paddle commented 6 months ago

Superseded by #20