Never-ending Pumpkin Mulch

    stripe-event-types
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.2 • Public • Published

    Stripe Event Types

    npm version Build

    This provides TypeScript typings for Stripe webhook events to strongly type the event.type and event.data.object fields. These types are automatically generated by scraping Stripe's documentation for types of events.

    Why is this needed? The typings included in the stripe library are lacking in this respect. The type for event.type is a string instead of a string literal and event.data.object is {} which requires casting each usage of it. This can lead to mistakes in your implementation that could easily be caught with stronger types.

    Typed Webhook Event

    Installation

    Install the package with:

    npm install stripe-event-types
    # or
    yarn add stripe-event-types

    Version compatability

    stripe-event-types version stripe version
    1.x 10.x

    Usage

    Webhook event

    When constructing the webhook event, cast it to Stripe.DiscriminatedEvent to strongly type the event.type and event.data.object fields:

    +/// <reference types="stripe-event-types" />
    
    const event = stripe.webhooks.constructEvent(
      request.body,
      request.headers['stripe-signature'],
      'whsec_test'
    -);
    +) as Stripe.DiscriminatedEvent;

    Event type

    The Stripe.DiscriminatedEvent.Type type is a string literal of all event types:

    /// <reference types="stripe-event-types" />
    
    const type: Stripe.DiscriminatedEvent.Type = "charge.succeeded";

    Keywords

    Install

    npm i stripe-event-types

    DownloadsWeekly Downloads

    181

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    29.4 kB

    Total Files

    4

    Last publish

    Collaborators

    • kgajera