0.10.14 • Published 8 months ago

@flowglad/server v0.10.14

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

@flowglad/server

This package provides a server-side SDK for integrating with Flowglad.

Installation

npm install @flowglad/server
# or
yarn add @flowglad/server
# or
pnpm add @flowglad/server

Usage

import { FlowgladServer } from '@flowglad/server'

const flowgladServer = new FlowgladServer({
  // optional - reads from FLOWGLAD_SECRET_KEY
  apiKey: 'your-api-key',
  // optional
  baseURL: 'https://app.flowglad.com',
  getRequestingCustomer: async () => {
    // Return the current customer
    return {
      externalId: 'user-123',
      name: 'John Doe',
      email: 'john@example.com',
    }
  },
})

// Get the customer ID
const customerId = await flowgladServer.getRequestingCustomerId()

// Get the customer session
const session = await flowgladServer.getSession()

// Find or create a customer
const customer = await flowgladServer.findOrCreateCustomer()

// Get customer billing information
const billing = await flowgladServer.getBilling()

// Get the catalog
const catalog = await flowgladServer.getCatalog()

// Create a subscription
const subscription = await flowgladServer.createSubscription({
  planId: 'plan-123',
  quantity: 1,
})

// Cancel a subscription
const canceledSubscription = await flowgladServer.cancelSubscription({
  id: 'sub-123',
  cancellation: {
    reason: 'customer-requested',
  },
})

// Create a usage event
const usageEvent = await flowgladServer.createUsageEvent({
  featureId: 'feature-123',
  quantity: 1,
  usageDate: new Date().toISOString(),
})

// Create a checkout session
const checkoutSession = await flowgladServer.createCheckoutSession({
  type: 'subscription',
  priceId: 'price-123',
  successUrl: 'https://example.com/success',
  cancelUrl: 'https://example.com/cancel',
})

Integration Tests

This package includes integration tests that test the FlowgladServer against a local implementation of flowglad-next.

Prerequisites

  • Node.js 18+
  • pnpm
  • Docker and Docker Compose

Running Integration Tests Locally

  1. Start the flowglad-next server:
cd platform/flowglad-next
pnpm test:setup
pnpm dev
  1. In a new terminal, run the integration tests:
cd packages/server
pnpm test:integration

Running Integration Tests in CI

The integration tests are automatically run in CI when changes are made to the server package or the flowglad-next package.

License

MIT

0.10.14

8 months ago

0.10.13

8 months ago

0.10.12

8 months ago

0.10.11

8 months ago

0.10.10

8 months ago

0.10.9

8 months ago

0.10.8

9 months ago

0.10.7

9 months ago

0.10.6

10 months ago

0.10.5

10 months ago

0.10.4

10 months ago

0.10.3

10 months ago

0.10.2

10 months ago

0.10.1

10 months ago

0.10.0

10 months ago

0.9.1

10 months ago

0.9.0

10 months ago

0.8.13

10 months ago

0.8.12

10 months ago

0.8.11

10 months ago

0.8.10

10 months ago

0.8.9

10 months ago

0.8.8

10 months ago

0.8.7

10 months ago

0.8.6

10 months ago

0.8.5

10 months ago

0.8.4

10 months ago

0.8.3

10 months ago

0.8.2

10 months ago

0.8.1

10 months ago

0.8.0

11 months ago

0.7.0

11 months ago

0.6.0

11 months ago

0.5.0

11 months ago

0.4.22

11 months ago

0.4.21

11 months ago

0.4.20

11 months ago

0.4.19

11 months ago

0.4.18

11 months ago

0.4.17

11 months ago

0.4.16

11 months ago

0.4.15

11 months ago

0.4.14

11 months ago

0.4.13

11 months ago

0.4.12

11 months ago

0.4.11

11 months ago

0.4.10

11 months ago

0.4.9

11 months ago

0.4.8

11 months ago

0.4.7

11 months ago

0.4.6

11 months ago

0.4.5

11 months ago

0.4.4

11 months ago

0.4.3

11 months ago

0.4.2

11 months ago

0.4.1

11 months ago

0.4.0

11 months ago

0.2.4

11 months ago

0.2.3

11 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.1.0

11 months ago