stripe-sync-engine
stripe-sync-engine copied to clipboard
Cloudflare Worker implementation
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! 🗳️
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)
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).
@kiwicopple What stops us from using supabase-js for the database interactions and making it serverless?
@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 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.
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 It was due to the 2MB limit on edge functions. Seems he pushed an update I will try that and update.
Closing as stale - feel free to open again, if you're working on it