Skip to content

feat: Modular API for edge runtimes #2156

Open
@brettwillis

Description

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions