stripe-sync-engine icon indicating copy to clipboard operation
stripe-sync-engine copied to clipboard

Cloudflare Worker implementation

Open prescience-data opened this issue 3 years ago • 4 comments

Feature request

Currently the sync engine requires a Fastify server component.

It would be great if there was a Cloudflare Worker implementation to make it easy to deploy (as I can't see any reason the code wouldn't work within a Worker)

Describe the solution you'd like

https://developers.cloudflare.com/workers/examples

It is also possible (we have implemented a "small scope" version of this) to authenticate using the frontend user's JWT back with Supabase from within the worker to authenticate and check permissions etc and retrieve their customer_id, so an "icing on top" feature would be a 1:1 with the Stripe API spec that allows this too! 🗳️

prescience-data avatar Jan 01 '22 04:01 prescience-data

I can't see any reason the code wouldn't work within a Worker)

It definitely could but there are a few caveats:

  • workers are serverless, and serverless functions don't work well with Postgres unless you have a connection pooler
  • we might need some long-running functions to backfill data (perhaps that's doable with Durable Objects?)

retrieve their customer_id, so an "icing on top" feature would be a 1:1 with the Stripe API spec that allows this too

This is probably beyond the scope of this project, but if you are saving the data to you database you can query it directly from there. eg in supabase:

supabase.from('customers').eq('id', customerId)

kiwicopple avatar Jan 01 '22 07:01 kiwicopple

workers are serverless, and serverless functions don't work well with Postgres unless you have a connection pooler

Ah yes, I just realised the reason we don't have this issue is that we use the PostgREST layer (using the authenticated user's token for identification + the service token for any higher level tasks).

prescience-data avatar Jan 03 '22 11:01 prescience-data

@kiwicopple What stops us from using supabase-js for the database interactions and making it serverless?

ak4zh avatar Aug 25 '22 04:08 ak4zh

@ak4zh - This is actually possible now using Supabase Functions.

I'll look into this (although I'm still not sure how to do a long-running task like backfilling because I believe that Deno Deploy has a invocation timeout

Side note - I see that @lawrencecchen actually implemented this in the recent hackathon:

https://www.madewithsupabase.com/p/stripe-sync

kiwicopple avatar Sep 05 '22 14:09 kiwicopple

@kiwicopple I was using stripe-sync in two of my projects but it seems you cannot deploy it anymore unless you have a PRO plan.

https://github.com/lawrencecchen/stripe-sync/issues/1

Maybe supabase can allow it as an inbuilt plugin in future.

ak4zh avatar Nov 16 '22 07:11 ak4zh

it seems you cannot deploy it anymore unless you have a PRO plan.

can you share more? You should be able to use this with any postgres database (including a free-tier)

Lawrence's sync engine should also work!

kiwicopple avatar Nov 16 '22 16:11 kiwicopple

@kiwicopple It was due to the 2MB limit on edge functions. Seems he pushed an update I will try that and update.

ak4zh avatar Nov 16 '22 17:11 ak4zh

Closing as stale - feel free to open again, if you're working on it

kevcodez avatar Nov 20 '23 13:11 kevcodez