Skip to content

Commit dd4347f

Browse files
pengyingclaude
andcommitted
feat(samples): add TypeScript backend using Grid TypeScript SDK
Express server mirroring the Kotlin sample with the same API contract. Uses @lightsparkdev/grid SDK, tsx runtime, and serves the shared React frontend. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5d76a76 commit dd4347f

17 files changed

Lines changed: 2014 additions & 3 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ cli/dist/
3838

3939
# Frontend build output
4040
samples/frontend/dist/
41+
samples/typescript/public/
4142

4243
# Figma design tokens (local reference only)
4344
mintlify/tokens/

samples/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ Sample applications demonstrating the Grid API payout flow — creating a custom
66

77
```
88
samples/
9-
├── frontend/ # Shared React frontend (works with any backend)
10-
└── kotlin/ # Kotlin (Ktor) backend using the Grid Kotlin SDK
9+
├── frontend/ # Shared React frontend (works with any backend)
10+
├── kotlin/ # Kotlin (Ktor) backend using the Grid Kotlin SDK
11+
└── typescript/ # TypeScript (Express) backend using the Grid TypeScript SDK
1112
```
1213

1314
## Quick Start
1415

15-
See the [Kotlin backend README](kotlin/README.md) for setup instructions.
16+
- [Kotlin backend](kotlin/README.md)
17+
- [TypeScript backend](typescript/README.md)
1618

1719
## Adding a New Language Backend
1820

samples/typescript/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Grid API Credentials (from https://app.lightspark.com)
2+
GRID_API_TOKEN_ID=your_api_token_id
3+
GRID_API_CLIENT_SECRET=your_api_client_secret

samples/typescript/README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Grid API TypeScript Sample
2+
3+
A sample application demonstrating the Grid API payout flow using the [Grid TypeScript SDK](https://www.npmjs.com/package/@lightsparkdev/grid).
4+
5+
## What It Does
6+
7+
This sample walks through a complete payout:
8+
9+
1. **Create Customer** — Register an individual customer on the platform
10+
2. **Create External Account** — Link a USD bank account to the customer
11+
3. **Create Quote** — Get a real-time quote for USDC to USD conversion
12+
4. **Sandbox Fund** — Simulate funding to complete the transaction
13+
14+
Webhook events are streamed to the frontend in real time via Server-Sent Events (SSE).
15+
16+
## Prerequisites
17+
18+
- **Node.js 18+**
19+
- **Grid API sandbox credentials** (Reach out to your contact at lightspark or sales@lightspark.com to get them)
20+
21+
## Setup
22+
23+
1. Copy the environment template:
24+
25+
```bash
26+
cp .env.example .env
27+
```
28+
29+
2. Fill in your credentials in `.env`:
30+
31+
```bash
32+
GRID_API_TOKEN_ID=your_api_token_id
33+
GRID_API_CLIENT_SECRET=your_api_client_secret
34+
```
35+
36+
## Running
37+
38+
### Option 1: Single command (recommended)
39+
40+
Builds the frontend, then starts the server:
41+
42+
```bash
43+
cd samples/typescript
44+
npm install
45+
npm start
46+
```
47+
48+
Open [http://localhost:8080](http://localhost:8080) in your browser.
49+
50+
### Option 2: Separate dev servers (for frontend development)
51+
52+
If you're iterating on the frontend, run them separately for hot reload:
53+
54+
**Terminal 1 — Backend (port 8080):**
55+
56+
```bash
57+
cd samples/typescript
58+
npm install
59+
npm run dev
60+
```
61+
62+
**Terminal 2 — Frontend (port 5173):**
63+
64+
```bash
65+
cd samples/frontend
66+
npm install
67+
npm run dev
68+
```
69+
70+
Open [http://localhost:5173](http://localhost:5173) in your browser. The Vite dev server proxies `/api` requests to the backend.
71+
72+
## Webhook Setup
73+
74+
To receive webhooks locally, expose your backend with a tunnel:
75+
76+
```bash
77+
ngrok http 8080
78+
```
79+
80+
Then configure the webhook URL in your [Grid dashboard](https://app.lightspark.com) as:
81+
82+
```
83+
https://<your-ngrok-id>.ngrok.io/api/webhooks
84+
```
85+
86+
## Architecture
87+
88+
```
89+
Browser (React) → Vite Dev Server (:5173) → Express Backend (:8080) → Grid API
90+
proxy /api Grid TypeScript SDK
91+
92+
Grid Webhooks (POST)
93+
94+
SSE stream → Browser
95+
```
96+
97+
The backend is a thin proxy — it holds your API credentials and translates JSON requests into Grid SDK calls. The frontend handles the step-by-step wizard flow.
98+
99+
## Sample Requests
100+
101+
Grid API calls are in `src/routes/`:
102+
103+
| File | Description |
104+
|------|-------------|
105+
| [`customers.ts`](src/routes/customers.ts) | Create a customer via `client.customers.create()` |
106+
| [`externalAccounts.ts`](src/routes/externalAccounts.ts) | Link a bank account via `client.customers.externalAccounts.create()` |
107+
| [`quotes.ts`](src/routes/quotes.ts) | Create and execute a quote via `client.quotes.create()` / `client.quotes.execute()` |
108+
| [`sandbox.ts`](src/routes/sandbox.ts) | Simulate funding via `client.sandbox.sendFunds()` |
109+
| [`webhooks.ts`](src/routes/webhooks.ts) | Receive incoming webhooks |
110+
111+
Client initialization is in [`gridClient.ts`](src/gridClient.ts).

0 commit comments

Comments
 (0)