mollie-api-node icon indicating copy to clipboard operation
mollie-api-node copied to clipboard

Using Mollie on Cloudflare Workers

Open jvanmourik opened this issue 3 years ago • 10 comments

Hello, Is it possible to use this package in combination with Cloudflare Workers? Currently it does not allow for use outside the node process, am I correct?

Error: Unexpected process release name undefined. This may indicate that the Mollie API client is integrated into a website or app. This is not recommended, please see https://github.com/mollie/mollie-api-node/#a-note-on-use-outside-of-nodejs. If this is a mistake, please let us know: https://github.com/mollie/mollie-api-node/issues

Thanks

jvanmourik avatar May 30 '21 19:05 jvanmourik

Thanks for the issue, Jacco!

While it does not allow for use outside of Node.js, this is an artificial limitation.

In the past, we've seen developers attempting to include this library in client-side websites/apps. Doing so would cause requests to be made to the Mollie servers directly from the user's machine, leaking the API key to the public. This is a severe security risk. The check you've discovered was introduced to prevent developers from shooting themselves in the foot. You are unfortunately collateral damage in this case.

To support Cloudflare Workers, we should:

  • tweak this check (or ‒ if everything else fails ‒ add a flag which disables the check entirely), and
  • ensure the library does not require any Node.js-specific APIs not supported by Cloudflare Workers.

Pimm avatar Jun 01 '21 11:06 Pimm

Hi @Pimm @jvanmourik,

We are in the same situation. We are trying to use Mollie from a Cloudflare worker, build on Node.

Is this Mollie Node package fully supported by now? Or does it still require some tweaks for a Cloudflare worker?

If we decide to tweak it, what are the risks of breaking when there is an update from Mollie?

Thanks for your help :)

nielswhydonate avatar Jan 04 '22 08:01 nielswhydonate

Hi Niels,

The library currently contains a check introduced to prevent developers from shooting themselves in the foot.

If you remove this check, the library should maybe perhaps work just fine on Cloudflare Workers. However, I haven't tested this yet. And before we announce official support for Cloudflare Workers, I want to test it thoroughly.

This is currently high on the backlog. I plan to look into this after the rollout of 3.6.0. I'll keep you up-to-date. If that just sounds too vague and you're willing to get your hands dirty, you are more than welcome to experiment and get involved. The door to my office is always open. Please feel free to step in at any time. (I'm working from home, so ehm… that stepping in part was meant figuratively.)

Pimm avatar Jan 05 '22 10:01 Pimm

Thanks for your response Pimm! Great to hear it's high on the backlog. If we make some progress, I will definitely post it here.

nielswhydonate avatar Jan 05 '22 18:01 nielswhydonate

Would love to see support for this!

ItsWendell avatar Jul 22 '22 20:07 ItsWendell

As axios would need to be replaced with fetch (axios doesn't work in Cloudflare Workers), see https://github.com/axios/axios/issues/1219 and https://github.com/slackapi/node-slack-sdk/issues/1335 for similar issues.

hansottowirtz avatar Dec 10 '22 21:12 hansottowirtz

I didn't want to create a new issue, but this problem is also happening on Deno. This runtime doesn't expose a process object like Node, so targeting it would have to be done in a different way. Maybe this lib could help https://github.com/flexdinesh/browser-or-node/tree/master

renancouto avatar Jul 01 '23 13:07 renancouto

Thanks, Renan.

Pimm avatar Jul 03 '23 07:07 Pimm

Any news on this? Cloudflare Worker support would be great.

rkettelerij avatar Aug 24 '23 16:08 rkettelerij

Would love to see platform agnostic support! Maybe something like this could help a lot https://github.com/unjs/unenv

Gerbuuun avatar Mar 31 '24 16:03 Gerbuuun