Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Modular API for edge runtimes #2156

Open
brettwillis opened this issue Aug 12, 2024 · 1 comment
Open

feat: Modular API for edge runtimes #2156

brettwillis opened this issue Aug 12, 2024 · 1 comment

Comments

@brettwillis
Copy link
Contributor

Is your feature request related to a problem? Please describe.

In "edge runtimes" such as Cloudflare Workers, Vercel Edge Functions, the size of the application code comes at a premium (as little as 1MB of JS). In such environments it is beneficial to have modular exports/entrypoints that allow importing only the code that is required so that bundlers can remove unused code.

This concept is also generally useful for reducing the startup time of any app, not just edge runtimes.

The Stripe SDK has many modules so it's not small.

Describe the solution you'd like

In addition to the existing API, provide modular exports as an alternative for importing only the required functionality.

This could look like:

import Stripe from 'stripe/core';
import PaymentIntents from 'stripe/payment-intents';

const stripe = new Stripe({...});

const paymentIntents = new PaymentIntents(stripe);

await paymentIntents.retrieve(...);

I notice the SDK is already structured in much the same way as this behind the scenes. But there a a few issues with the above proposed API... eg an app would potentially instantiate many instances of the modules around it's codebase. There are a few ways to improve this but needs careful consideration about the API.

So even better yet, something like this:

import Stripe from 'stripe/core';
import { retrievePaymentIntent } from 'stripe/payment-intents';

const stripe = new Stripe({...});

await retrievePaymentIntent(stripe, ...);

Describe alternatives you've considered

No response

Additional context

No response

@helenye-stripe
Copy link
Contributor

Hi @brettwillis. Thanks for bringing this up! We plan to investigate ways to make the SDK less resource-intensive in the future. We have also thought about using tree-shaking to do this, see #1693. I'll keep this issue open and update once there is progress here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants