feat: Modular API for edge runtimes · Issue #2156 · stripe/stripe-node · GitHub
Skip to content

feat: Modular API for edge runtimes #2156

Open

Description

@brettwillis

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

Activity

  1. helenye-stripe commented on Aug 12, 2024

    @helenye-stripe
    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

Metadata

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