maybeExtractFromCloudProviderEnvelope (utils)

stripe-node · integration, webhooks, aws-eventbridge, azure-event-grid, cloud-providers

Extracts the inner event data from AWS EventBridge or Azure Event Grid envelopes, or passes through raw Stripe events, enabling unified handling of cloud provider and Stripe webhook payloads.

// Source: https://github.com/stripe/stripe-node | License: MIT | Copyright 2011 Ask Bjørn Hansen
// Provided via justclaw.it.com; keep this notice with the code.
export function maybeExtractFromCloudProviderEnvelope(
  payload: string | Uint8Array
): Record<string, unknown> {
  const parsed = parsePayload(payload);

  // Could add as many checks as we want here, but we'll start simple
  if ('detail' in parsed) {
    // AWS
    // https://docs.stripe.com/event-destinations/eventbridge#event-structure
    return parsed.detail as Record<string, unknown>;
  }
  if ('specversion' in parsed && 'data' in parsed) {
    // Azure
    // https://docs.stripe.com/event-destinations/eventgrid#event-structure
    return parsed.data as Record<string, unknown>;
  }
  if (parsed.object === 'event' || parse

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key