@vivero/stoma 0.1.0-rc.6 → 0.1.0-rc.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +325 -0
- package/dist/config/schema.d.ts +5 -5
- package/package.json +5 -3
- package/CHANGELOG.md +0 -141
package/README.md
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# Stoma 🌱
|
|
2
|
+
|
|
3
|
+
**Declarative API gateway as a TypeScript library. Runs on Cloudflare Workers, Node.js, Deno, Bun, and more.**
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Why
|
|
12
|
+
|
|
13
|
+
API gateways in the JavaScript ecosystem are stuck between two bad options:
|
|
14
|
+
|
|
15
|
+
1. **Infrastructure you deploy** -- Kong, KrakenD, AWS API Gateway. Powerful, but they are separate services you provision, configure with YAML, and operate independently from your application code. You lose type safety, your gateway config drifts from your codebase, and you pay for another piece of infrastructure.
|
|
16
|
+
|
|
17
|
+
2. **Dead or abandoned libraries** -- Express Gateway was the closest thing to a TS-native gateway. It is unmaintained, locked to Express 4, and has no story for modern runtimes.
|
|
18
|
+
|
|
19
|
+
There is a third option: **a declarative gateway library that lives in your codebase and deploys with your standard workflow.**
|
|
20
|
+
|
|
21
|
+
`@vivero/stoma` fills this gap. It is a TypeScript library you import -- not a Go binary or YAML config you deploy. Define your routes, policies, and upstreams as typed objects. The library compiles them into an HTTP application you can export directly.
|
|
22
|
+
|
|
23
|
+
- Configured with **TypeScript**, not YAML
|
|
24
|
+
- Lives in **your codebase** -- deploy as part of your app or as a standalone service
|
|
25
|
+
- Runs on Cloudflare Workers, Node.js, Deno, Bun, Fastly, Lambda@Edge, Vercel Edge Functions
|
|
26
|
+
- Optionally leverages **platform-specific features** (Cloudflare Service Bindings, KV, Durable Objects) through a pluggable adapter system
|
|
27
|
+
|
|
28
|
+
Think KrakenD's declarative route-to-pipeline model, but as a TypeScript library.
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- **TypeScript-first with full type safety** -- Every config object, policy, and upstream is typed. No YAML. No JSON Schema. Your editor catches mistakes before your users do.
|
|
33
|
+
- **Powered by Hono** -- lightweight, zero dependencies, Web Standards API. One of the fastest routers in the JavaScript ecosystem.
|
|
34
|
+
- **Declarative route / pipeline / policy chain model** -- Define routes, attach ordered policy chains, and point at an upstream. The gateway wires it all together.
|
|
35
|
+
- **Dozens of built-in policies** -- Auth (JWT, API key, OAuth2, RBAC, HTTP signatures), traffic control (rate limiting, IP filtering, caching, threat protection), resilience (circuit breaker, retry, timeout), transforms (CORS, request/response rewriting, validation), and observability (structured logging, metrics, health checks).
|
|
36
|
+
- **Multi-runtime** -- Core depends only on Hono and the Web `Request`/`Response` API. No Node.js built-ins, no platform lock-in.
|
|
37
|
+
- **Pluggable adapter system** -- Runtime-specific capabilities (distributed stores, background tasks, service bindings) are injected through adapters, not hard-coded. Adapters ship for Cloudflare Workers, Node.js, Deno, Bun, and in-memory development.
|
|
38
|
+
- **Pluggable policy system** -- Policies are middleware functions with metadata. Write a custom policy in a few lines, or use `definePolicy()` from the SDK for a structured approach.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
npm install @vivero/stoma hono
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
### Basic gateway (runs on any runtime)
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { createGateway, jwtAuth, rateLimit, requestLog, cors } from "@vivero/stoma";
|
|
52
|
+
|
|
53
|
+
const gateway = createGateway({
|
|
54
|
+
name: "my-api-gateway",
|
|
55
|
+
basePath: "/api",
|
|
56
|
+
policies: [requestLog(), cors()],
|
|
57
|
+
routes: [
|
|
58
|
+
{
|
|
59
|
+
path: "/users/*",
|
|
60
|
+
methods: ["GET", "POST", "PUT", "DELETE"],
|
|
61
|
+
pipeline: {
|
|
62
|
+
policies: [
|
|
63
|
+
jwtAuth({ secret: "your-secret" }),
|
|
64
|
+
rateLimit({ max: 100, windowSeconds: 60 }),
|
|
65
|
+
],
|
|
66
|
+
upstream: {
|
|
67
|
+
type: "url",
|
|
68
|
+
target: "https://users-api.internal.example.com",
|
|
69
|
+
rewritePath: (path) => path.replace("/api/users", ""),
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
path: "/health",
|
|
75
|
+
pipeline: {
|
|
76
|
+
upstream: {
|
|
77
|
+
type: "handler",
|
|
78
|
+
handler: () =>
|
|
79
|
+
new Response(JSON.stringify({ status: "ok" }), {
|
|
80
|
+
headers: { "Content-Type": "application/json" },
|
|
81
|
+
}),
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export default gateway.app;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
This gateway works out of the box on Cloudflare Workers (`export default gateway.app`), Bun (`export default gateway.app`), Deno (`Deno.serve(gateway.app.fetch)`), or Node.js (via `@hono/node-server`).
|
|
92
|
+
|
|
93
|
+
### With Cloudflare-specific features
|
|
94
|
+
|
|
95
|
+
When deploying to Cloudflare Workers, use the Cloudflare adapter to unlock Service Bindings, KV-backed rate limiting, and Durable Objects:
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { createGateway, jwtAuth, rateLimit, requestLog } from "@vivero/stoma";
|
|
99
|
+
import { cloudflareAdapter } from "@vivero/stoma/adapters/cloudflare";
|
|
100
|
+
|
|
101
|
+
type Env = {
|
|
102
|
+
JWT_SECRET: string;
|
|
103
|
+
USERS_SERVICE: Fetcher;
|
|
104
|
+
RATE_LIMIT_KV: KVNamespace;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export default {
|
|
108
|
+
fetch(request: Request, env: Env, ctx: ExecutionContext) {
|
|
109
|
+
const gateway = createGateway({
|
|
110
|
+
name: "my-api-gateway",
|
|
111
|
+
basePath: "/api",
|
|
112
|
+
adapter: cloudflareAdapter({
|
|
113
|
+
rateLimitKv: env.RATE_LIMIT_KV,
|
|
114
|
+
executionCtx: ctx,
|
|
115
|
+
env,
|
|
116
|
+
}),
|
|
117
|
+
policies: [requestLog()],
|
|
118
|
+
routes: [
|
|
119
|
+
{
|
|
120
|
+
path: "/users/*",
|
|
121
|
+
pipeline: {
|
|
122
|
+
policies: [
|
|
123
|
+
jwtAuth({ secret: env.JWT_SECRET }),
|
|
124
|
+
rateLimit({ max: 100, windowSeconds: 60 }),
|
|
125
|
+
],
|
|
126
|
+
upstream: {
|
|
127
|
+
type: "service-binding",
|
|
128
|
+
service: "USERS_SERVICE",
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
return gateway.app.fetch(request, env, ctx);
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Configuration
|
|
141
|
+
|
|
142
|
+
The gateway is configured entirely through TypeScript. The top-level `GatewayConfig` type drives everything:
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
interface GatewayConfig {
|
|
146
|
+
name?: string; // Gateway name, used in logs and metrics
|
|
147
|
+
basePath?: string; // Base path prefix for all routes (e.g. "/api")
|
|
148
|
+
routes: RouteConfig[]; // Route definitions
|
|
149
|
+
policies?: Policy[]; // Global policies applied to every route
|
|
150
|
+
adapter?: GatewayAdapter; // Runtime adapter for stores and platform capabilities
|
|
151
|
+
onError?: (error: Error, c: unknown) => Response | Promise<Response>;
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Each route defines a **path**, optional **methods**, and a **pipeline**:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
interface RouteConfig {
|
|
159
|
+
path: string; // Hono path syntax: "/users/:id", "/files/*"
|
|
160
|
+
methods?: HttpMethod[]; // ["GET", "POST", ...] -- defaults to all
|
|
161
|
+
pipeline: PipelineConfig; // Policy chain + upstream target
|
|
162
|
+
metadata?: Record<string, unknown>;
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
A pipeline is an ordered chain of policies leading to an upstream:
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
interface PipelineConfig {
|
|
170
|
+
policies?: Policy[]; // Executed in order before the upstream
|
|
171
|
+
upstream: UpstreamConfig; // Where the request goes
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Upstream Types
|
|
176
|
+
|
|
177
|
+
Three upstream types cover the common deployment patterns:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
// URL proxy -- forward to any HTTP endpoint (works on all runtimes)
|
|
181
|
+
{ type: "url", target: "https://api.example.com", headers: { "X-Forwarded-By": "gateway" } }
|
|
182
|
+
|
|
183
|
+
// Service Binding -- zero-latency Worker-to-Worker routing (Cloudflare only)
|
|
184
|
+
{ type: "service-binding", service: "AUTH_SERVICE" }
|
|
185
|
+
|
|
186
|
+
// Inline handler -- respond directly without proxying (works on all runtimes)
|
|
187
|
+
{ type: "handler", handler: (c) => new Response("ok") }
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Adapters
|
|
191
|
+
|
|
192
|
+
Adapters provide runtime-specific store implementations and platform capabilities. The gateway core is runtime-agnostic; adapters plug in distributed rate limiting, caching, background tasks, and service binding dispatch.
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
import { cloudflareAdapter } from "@vivero/stoma/adapters/cloudflare";
|
|
196
|
+
import { nodeAdapter } from "@vivero/stoma/adapters/node";
|
|
197
|
+
import { denoAdapter } from "@vivero/stoma/adapters/deno";
|
|
198
|
+
import { bunAdapter } from "@vivero/stoma/adapters/bun";
|
|
199
|
+
import { memoryAdapter } from "@vivero/stoma/adapters/memory";
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
| Adapter | Stores | `waitUntil` | Service Bindings | Use case |
|
|
203
|
+
|---------|--------|-------------|------------------|----------|
|
|
204
|
+
| `cloudflareAdapter` | KV, Durable Objects, Cache API | Yes | Yes | Production on Cloudflare Workers |
|
|
205
|
+
| `nodeAdapter` | In-memory defaults | No | No | Node.js servers via `@hono/node-server` |
|
|
206
|
+
| `denoAdapter` | In-memory defaults | No | No | Deno / Deno Deploy |
|
|
207
|
+
| `bunAdapter` | In-memory defaults | No | No | Bun servers |
|
|
208
|
+
| `memoryAdapter` | In-memory (all stores) | No | No | Development, testing, single-instance |
|
|
209
|
+
|
|
210
|
+
No adapter is required. Without one, policies that need stores (rate limiting, caching, circuit breaking) fall back to in-memory defaults automatically.
|
|
211
|
+
|
|
212
|
+
## Policies
|
|
213
|
+
|
|
214
|
+
Policies are the building blocks of gateway pipelines. They are middleware handlers with a name and a priority (lower numbers execute first).
|
|
215
|
+
|
|
216
|
+
### Built-in Policies
|
|
217
|
+
|
|
218
|
+
| Category | Policies |
|
|
219
|
+
|----------|----------|
|
|
220
|
+
| **Auth** | `jwtAuth`, `apiKeyAuth`, `basicAuth`, `oauth2`, `rbac`, `generateJwt`, `jws`, `generateHttpSignature`, `verifyHttpSignature` |
|
|
221
|
+
| **Traffic** | `rateLimit`, `ipFilter`, `geoIpFilter`, `cache`, `sslEnforce`, `requestLimit`, `jsonThreatProtection`, `regexThreatProtection`, `trafficShadow`, `interrupt`, `dynamicRouting`, `httpCallout`, `resourceFilter` |
|
|
222
|
+
| **Resilience** | `timeout`, `retry`, `circuitBreaker`, `latencyInjection` |
|
|
223
|
+
| **Transform** | `cors`, `overrideMethod`, `assignAttributes`, `assignContent`, `requestTransform`, `responseTransform`, `requestValidation`, `jsonValidation` |
|
|
224
|
+
| **Observability** | `requestLog`, `metricsReporter`, `assignMetrics`, `health` |
|
|
225
|
+
| **Utility** | `proxy`, `mock` |
|
|
226
|
+
|
|
227
|
+
Every policy accepts a `skip` function for conditional execution:
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
rateLimit({
|
|
231
|
+
max: 100,
|
|
232
|
+
skip: (c) => c.req.header("X-Internal") === "true",
|
|
233
|
+
})
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Writing a Custom Policy
|
|
237
|
+
|
|
238
|
+
A policy is any object conforming to the `Policy` interface:
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
import type { Policy } from "@vivero/stoma";
|
|
242
|
+
|
|
243
|
+
function requestTimer(): Policy {
|
|
244
|
+
return {
|
|
245
|
+
name: "request-timer",
|
|
246
|
+
priority: 5,
|
|
247
|
+
handler: async (c, next) => {
|
|
248
|
+
const start = performance.now();
|
|
249
|
+
await next();
|
|
250
|
+
c.header("X-Response-Time", `${(performance.now() - start).toFixed(1)}ms`);
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
For a more structured approach, use the SDK:
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
import { definePolicy, Priority } from "@vivero/stoma";
|
|
260
|
+
|
|
261
|
+
const requestTimer = definePolicy({
|
|
262
|
+
name: "request-timer",
|
|
263
|
+
priority: Priority.EARLY_TRANSFORM,
|
|
264
|
+
handler: async ({ c, next }) => {
|
|
265
|
+
const start = performance.now();
|
|
266
|
+
await next();
|
|
267
|
+
c.header("X-Response-Time", `${(performance.now() - start).toFixed(1)}ms`);
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Policy Execution Order
|
|
273
|
+
|
|
274
|
+
Policies execute in **priority order** (lowest number first), then in **declaration order** for policies sharing a priority. Global policies and route-level policies are merged and sorted together.
|
|
275
|
+
|
|
276
|
+
| Priority | Phase | Examples |
|
|
277
|
+
|----------|-------|---------|
|
|
278
|
+
| 0 | Observability | `requestLog`, `assignMetrics` |
|
|
279
|
+
| 1 | Network filter | `ipFilter`, `geoIpFilter`, `metricsReporter` |
|
|
280
|
+
| 5 | Early transform | `cors`, `sslEnforce`, `requestLimit`, `latencyInjection` |
|
|
281
|
+
| 10 | Authentication | `jwtAuth`, `apiKeyAuth`, `basicAuth`, `oauth2`, `rbac` |
|
|
282
|
+
| 20 | Rate limiting | `rateLimit` |
|
|
283
|
+
| 30 | Circuit breaker | `circuitBreaker` |
|
|
284
|
+
| 40 | Caching | `cache` |
|
|
285
|
+
| 50 | Mid-pipeline | `requestTransform`, `assignAttributes`, `generateJwt`, `dynamicRouting` |
|
|
286
|
+
| 85 | Timeout | `timeout` |
|
|
287
|
+
| 90 | Retry | `retry` |
|
|
288
|
+
| 92 | Response | `responseTransform`, `trafficShadow`, `resourceFilter` |
|
|
289
|
+
| 95 | Proxy | `proxy`, `generateHttpSignature` |
|
|
290
|
+
| 100 | Default | Custom policies |
|
|
291
|
+
| 999 | Terminal | `mock` |
|
|
292
|
+
|
|
293
|
+
## Documentation & Resources
|
|
294
|
+
|
|
295
|
+
- [Architecture Design](ARCHITECTURE.md) - Deep dive into the gateway's internal design and decisions.
|
|
296
|
+
- [Full Documentation](https://stoma.vivero.dev) - Comprehensive guides, recipes, and API reference.
|
|
297
|
+
|
|
298
|
+
## Package Exports
|
|
299
|
+
|
|
300
|
+
| Import path | Contents |
|
|
301
|
+
|-------------|----------|
|
|
302
|
+
| `@vivero/stoma` | `createGateway`, all policies, metrics, core types |
|
|
303
|
+
| `@vivero/stoma/policies` | Policies only |
|
|
304
|
+
| `@vivero/stoma/sdk` | `definePolicy`, `Priority`, test harness |
|
|
305
|
+
| `@vivero/stoma/config` | Config types + optional Zod validation (requires `zod` peer dep) |
|
|
306
|
+
| `@vivero/stoma/adapters` | All adapter factories |
|
|
307
|
+
| `@vivero/stoma/adapters/cloudflare` | Cloudflare adapter only |
|
|
308
|
+
| `@vivero/stoma/adapters/node` | Node.js adapter only |
|
|
309
|
+
| `@vivero/stoma/adapters/deno` | Deno adapter only |
|
|
310
|
+
| `@vivero/stoma/adapters/bun` | Bun adapter only |
|
|
311
|
+
| `@vivero/stoma/adapters/memory` | In-memory adapter (dev/test) |
|
|
312
|
+
|
|
313
|
+
## Contributing
|
|
314
|
+
|
|
315
|
+
Contributions are welcome. Please open an issue to discuss proposed changes before submitting a pull request.
|
|
316
|
+
|
|
317
|
+
```sh
|
|
318
|
+
yarn install
|
|
319
|
+
yarn test
|
|
320
|
+
yarn typecheck
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
## License
|
|
324
|
+
|
|
325
|
+
MIT
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -72,8 +72,8 @@ declare const PipelineSchema: z.ZodObject<{
|
|
|
72
72
|
}, z.core.$strip>], "type">;
|
|
73
73
|
}, z.core.$strip>;
|
|
74
74
|
declare const HttpMethodSchema: z.ZodEnum<{
|
|
75
|
-
GET: "GET";
|
|
76
75
|
POST: "POST";
|
|
76
|
+
GET: "GET";
|
|
77
77
|
PUT: "PUT";
|
|
78
78
|
PATCH: "PATCH";
|
|
79
79
|
DELETE: "DELETE";
|
|
@@ -83,8 +83,8 @@ declare const HttpMethodSchema: z.ZodEnum<{
|
|
|
83
83
|
declare const RouteSchema: z.ZodObject<{
|
|
84
84
|
path: z.ZodString;
|
|
85
85
|
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
86
|
-
GET: "GET";
|
|
87
86
|
POST: "POST";
|
|
87
|
+
GET: "GET";
|
|
88
88
|
PUT: "PUT";
|
|
89
89
|
PATCH: "PATCH";
|
|
90
90
|
DELETE: "DELETE";
|
|
@@ -129,8 +129,8 @@ declare const ScopeConfigSchema: z.ZodObject<{
|
|
|
129
129
|
routes: z.ZodArray<z.ZodLazy<z.ZodObject<{
|
|
130
130
|
path: z.ZodString;
|
|
131
131
|
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
132
|
-
GET: "GET";
|
|
133
132
|
POST: "POST";
|
|
133
|
+
GET: "GET";
|
|
134
134
|
PUT: "PUT";
|
|
135
135
|
PATCH: "PATCH";
|
|
136
136
|
DELETE: "DELETE";
|
|
@@ -167,8 +167,8 @@ declare const GatewayConfigSchema: z.ZodObject<{
|
|
|
167
167
|
routes: z.ZodArray<z.ZodObject<{
|
|
168
168
|
path: z.ZodString;
|
|
169
169
|
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
170
|
-
GET: "GET";
|
|
171
170
|
POST: "POST";
|
|
171
|
+
GET: "GET";
|
|
172
172
|
PUT: "PUT";
|
|
173
173
|
PATCH: "PATCH";
|
|
174
174
|
DELETE: "DELETE";
|
|
@@ -206,8 +206,8 @@ declare const GatewayConfigSchema: z.ZodObject<{
|
|
|
206
206
|
debug: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
|
|
207
207
|
requestIdHeader: z.ZodOptional<z.ZodString>;
|
|
208
208
|
defaultMethods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
209
|
-
GET: "GET";
|
|
210
209
|
POST: "POST";
|
|
210
|
+
GET: "GET";
|
|
211
211
|
PUT: "PUT";
|
|
212
212
|
PATCH: "PATCH";
|
|
213
213
|
DELETE: "DELETE";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vivero/stoma",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.8",
|
|
4
4
|
"description": "Declarative API gateway as a TypeScript library. Runs on Cloudflare Workers, Node.js, Deno, Bun, and any JavaScript runtime.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -178,10 +178,12 @@
|
|
|
178
178
|
"test:cloudflare": "vitest run --config vitest.cloudflare.ts",
|
|
179
179
|
"test:coverage": "vitest run --coverage",
|
|
180
180
|
"test:watch": "vitest",
|
|
181
|
+
"prepack": "node ../../scripts/resolve-workspace-deps.mjs",
|
|
182
|
+
"postpack": "node ../../scripts/resolve-workspace-deps.mjs --restore",
|
|
181
183
|
"prepublishOnly": "yarn build"
|
|
182
184
|
},
|
|
183
185
|
"dependencies": {
|
|
184
|
-
"@vivero/stoma-core": "0.1.0-rc.
|
|
186
|
+
"@vivero/stoma-core": "0.1.0-rc.1"
|
|
185
187
|
},
|
|
186
188
|
"devDependencies": {
|
|
187
189
|
"@cloudflare/vitest-pool-workers": "^0.8.0",
|
|
@@ -210,4 +212,4 @@
|
|
|
210
212
|
"optional": true
|
|
211
213
|
}
|
|
212
214
|
}
|
|
213
|
-
}
|
|
215
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
# @vivero/stoma
|
|
2
|
-
|
|
3
|
-
## 0.1.0-rc.6
|
|
4
|
-
### Patch Changes
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
- [`c14161a`](https://github.com/vivero-dev/stoma/commit/c14161a0846ef1991bb0fa71337435e6366579a7) Thanks [@JonathanBennett](https://github.com/JonathanBennett)! - Fix Content-Encoding/Content-Length mismatch on proxied upstream responses; enrich request logs with upstream target and client IP from socket
|
|
9
|
-
|
|
10
|
-
### Fixes
|
|
11
|
-
|
|
12
|
-
- **Stale encoding headers on URL and Service Binding upstreams**: The runtime's `fetch()` transparently decompresses gzip/deflate/br responses, but the gateway was forwarding the original `Content-Encoding` and `Content-Length` headers unchanged. Downstream clients (browsers, proxies) would then attempt to decompress an already-decoded body, resulting in `ERR_CONTENT_DECODING_FAILED` or `ERR_CONTENT_LENGTH_MISMATCH` errors. Both `createUrlUpstream` and `createServiceBindingUpstream` now strip `content-encoding` and `content-length` from upstream responses before returning them.
|
|
13
|
-
- **`upstream` always "unknown" in request logs**: The `request-log` policy hardcoded `upstream: "unknown"` because no upstream handler was setting the value. All three upstream types (`createUrlUpstream`, `createServiceBindingUpstream`, `createHandlerUpstream`) now set `c.set("_upstreamTarget", identifier)` with the full resolved URL (including rewritten path and query string), `"service-binding:<name>"`, or `"handler"` respectively.
|
|
14
|
-
- **`clientIp` always "unknown" when running locally**: `extractClientIp()` only checked HTTP headers (`cf-connecting-ip`, `x-forwarded-for`), which aren't present when running with `@hono/node-server` locally. Added a `fallbackAddress` option to `extractClientIp()` and a `getRemoteAddress()` helper in `request-log` that duck-types `c.env.incoming.socket.remoteAddress` from the Node.js adapter.
|
|
15
|
-
|
|
16
|
-
## 0.1.0-rc.5
|
|
17
|
-
### Patch Changes
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
- [`363341d`](https://github.com/vivero-dev/stoma/commit/363341dbc92a9f58a4b7df1ca0c66db2407cfe43) Thanks [@JonathanBennett](https://github.com/JonathanBennett)! - Accept trailing slashes on route paths
|
|
22
|
-
|
|
23
|
-
### Fixes
|
|
24
|
-
|
|
25
|
-
- **Trailing-slash route aliases**: The gateway now registers both `/path` and `/path/` for every non-wildcard route, so requests with a trailing slash no longer 404. This also covers CORS preflight — if a `cors` policy is present, the OPTIONS handler is registered on both variants.
|
|
26
|
-
- **Scope path normalisation**: `scope()` and the internal `joinPaths` helper now strip trailing slashes from prefixes and handle root-path (`"/"`) children correctly, avoiding double-slash joins or unintended `/path/` suffixes.
|
|
27
|
-
|
|
28
|
-
## 0.1.0-rc.5
|
|
29
|
-
### Patch Changes
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
- [`277d1a2`](https://github.com/vivero-dev/stoma/commit/277d1a2d27d98b444f074e4ecf0ae8095ef6f133) Thanks [@JonathanBennett](https://github.com/JonathanBennett)! - Fix policy middleware swallowing handler return values, breaking context finalization
|
|
34
|
-
|
|
35
|
-
### Fixes
|
|
36
|
-
|
|
37
|
-
- **Policy pipeline context finalization**: `policiesToMiddleware` now propagates the return value from policy handlers back to Hono's compose chain. Previously, policies that short-circuit by returning a `Response` (rather than setting `c.res` or calling `next()`) would have their return value discarded, leaving `context.finalized` as `false` and causing Hono to throw "Context is not finalized". Both the fast path (no tracing) and slow path (OTel/policy trace active) are fixed.
|
|
38
|
-
- **Auto-inject OPTIONS for preflight**: When a route restricts its methods (e.g. `methods: ["GET"]`) and a policy that handles OPTIONS preflight is present, the gateway now automatically registers an OPTIONS handler for that path so preflight requests don't 404.
|
|
39
|
-
|
|
40
|
-
## 0.1.0-rc.4
|
|
41
|
-
### Patch Changes
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
- [`c4f3901`](https://github.com/vivero-dev/stoma/commit/c4f39017bf8187e5e750d4bae1acb4fe016b78a8) Thanks [@JonathanBennett](https://github.com/JonathanBennett)! - ### Fixes
|
|
46
|
-
|
|
47
|
-
- Refactored JWT auth validation: Extracted duplicated validation logic from `handler` and `evaluate.onRequest` into a shared `validateJwt()` function. Returns a discriminated `JWTValidationResult`, so each runtime path maps to its own error model.
|
|
48
|
-
|
|
49
|
-
### Docs
|
|
50
|
-
|
|
51
|
-
- Docs have been updated with new about and sustainability pages.
|
|
52
|
-
|
|
53
|
-
## 0.1.0-rc.3
|
|
54
|
-
### Patch Changes
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
- [`e7ecfb7`](https://github.com/vivero-dev/stoma/commit/e7ecfb763ef8b7a750984690436ce8bf7253f804) Thanks [@JonathanBennett](https://github.com/JonathanBennett)! - # Docs updates only:
|
|
59
|
-
|
|
60
|
-
Add Open Graph meta tags and decouple docs deployment from package releases
|
|
61
|
-
|
|
62
|
-
- Add `og:image` and related OG headers to Starlight config
|
|
63
|
-
- Decouple `deploy-docs` CI job from npm publish — docs now deploy on any successful release job
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
- [`c1485eb`](https://github.com/vivero-dev/stoma/commit/c1485eb0e5933c1e45cb0ba05dff75d11569f46d) Thanks [@JonathanBennett](https://github.com/JonathanBennett)! - Tree-shakeable builds — 57% smaller bundles for consumers
|
|
67
|
-
|
|
68
|
-
### Build
|
|
69
|
-
|
|
70
|
-
- **Unbundled dist output**: Switched tsup from bundled code-splitting (`splitting: true`) to per-file transpilation (`bundle: false`). The published `dist/` now mirrors the `src/` module structure, allowing consumer bundlers (esbuild, Rollup, webpack) to tree-shake at the module level instead of importing a monolithic chunk.
|
|
71
|
-
- **`sideEffects: false`**: Added to `package.json` so bundlers can safely drop unused modules.
|
|
72
|
-
- **`/*#__PURE__*/` annotations**: Added to all 33 `definePolicy()` call sites across policy files. These tell bundlers the factory calls can be dropped when their return values are unused.
|
|
73
|
-
|
|
74
|
-
### Impact
|
|
75
|
-
|
|
76
|
-
A basic gateway with `requestLog` + `cors` drops from **89 KB / 28 KB gzip** to **38 KB / 15 KB gzip**. Consumers only pay for the policies they actually import.
|
|
77
|
-
|
|
78
|
-
### Docs
|
|
79
|
-
|
|
80
|
-
- Fixed rate-limit error response in how-it-works guide: error code corrected from `rate_limit_exceeded` to `rate_limited`, `retryAfter` moved from JSON body to response header (matching actual implementation).
|
|
81
|
-
- Fixed IP extraction order: `cf-connecting-ip` checked first, then `x-forwarded-for`.
|
|
82
|
-
|
|
83
|
-
## 0.1.0-rc.2
|
|
84
|
-
### Patch Changes
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
- [`75d0447`](https://github.com/vivero-dev/stoma/commit/75d04472e736fafe9528e258514a9fe3e352e511) Thanks [@JonathanBennett](https://github.com/JonathanBennett)! - Live demo API, interactive editor links across docs, release workflow fixes
|
|
89
|
-
|
|
90
|
-
### Features
|
|
91
|
-
|
|
92
|
-
- **Demo API gateway** (`docs/src/demo-api/`): Real Stoma gateway deployed alongside the docs site at `/demo-api/*`, serving echo, users, products, status, and delay endpoints. Dogfoods Stoma with rate limiting (60 req/min) and CORS. Same-origin deployment eliminates CORS issues from the editor.
|
|
93
|
-
- **EditorLink on all guide and recipe pages**: Added "Open in Editor" buttons to 8 docs pages — webhook firewall, cache resilience, shadow release, caching (basic + advanced), JWT auth (HMAC + JWKS), route scopes, and the basic gateway partial. Real-world example page converted from inline code to imported example with EditorLink.
|
|
94
|
-
|
|
95
|
-
### Fixes
|
|
96
|
-
|
|
97
|
-
- **EditorLink Unicode encoding**: Replaced `btoa()` with `Buffer.from().toString("base64")` to handle non-Latin1 characters in example code.
|
|
98
|
-
- **Release workflow: npm auth**: Added `NODE_AUTH_TOKEN` env var — `setup-node` with `registry-url` generates an `.npmrc` referencing `NODE_AUTH_TOKEN`, not `NPM_TOKEN`. Without this, `changeset publish` would fail with 401.
|
|
99
|
-
- **Release workflow: docs deploy build**: Added `yarn build` (tsup) step before docs build — the demo API worker imports `@vivero/stoma` which resolves to `dist/`, so stoma must be built first.
|
|
100
|
-
- **Release workflow: docs build command**: Changed from `yarn docs:build` (`astro build` only) to `cd docs && yarn build` (`build:assets && astro build`) so the stoma bundle, editor worker, and service worker are built before Astro runs.
|
|
101
|
-
- **Webhook firewall test**: Rewritten to test policy behavior (auth rejection for missing signature) instead of depending on upstream DNS resolution. Tests no longer make outbound network requests.
|
|
102
|
-
|
|
103
|
-
### Docs
|
|
104
|
-
|
|
105
|
-
- All concept examples updated to use the live demo API (`https://stoma.vivero.dev/demo-api`) as upstream target, so editor demos produce real responses instead of 502 errors.
|
|
106
|
-
- Docs Cloudflare Worker updated with `main` entry point and `ASSETS` binding to serve both the demo API and static assets.
|
|
107
|
-
|
|
108
|
-
## 0.1.0-rc.1
|
|
109
|
-
### Patch Changes
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
- [`155433e`](https://github.com/vivero-dev/stoma/commit/155433e7eb9f0050cc7b81fdc582e1d9045a583e) Thanks [@JonathanBennett](https://github.com/JonathanBennett)! - Protocol-agnostic policy evaluation, docs editor improvements, lint fixes
|
|
114
|
-
|
|
115
|
-
- Multi-protocol policy architecture: `PolicyInput`, `PolicyResult`, `PolicyEvaluator` types enabling policies to run outside HTTP (ext_proc, WebSocket)
|
|
116
|
-
- `ipFilter` now exposes `evaluate.onRequest` alongside the existing Hono `handler`
|
|
117
|
-
- Docs editor: Hono types inlined into the stoma type bundle via `--external-inlines hono` (removes hand-written stubs)
|
|
118
|
-
- Docs editor: subpath registration for Monaco IntelliSense (`/sdk`, `/config`, `/adapters/*`)
|
|
119
|
-
- Fixed broken `EditorLink` component (`_href` → `href`)
|
|
120
|
-
- Lint error cleanup
|
|
121
|
-
|
|
122
|
-
## 0.1.0-rc.0
|
|
123
|
-
### Minor Changes
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
- [`bb4d04f`](https://github.com/vivero-dev/stoma/commit/bb4d04ff85c8c133b10c323d92695cf11b944552) Thanks [@JonathanBennett](https://github.com/JonathanBennett)! - Initial release candidate for v0.1.0
|
|
128
|
-
|
|
129
|
-
Declarative API gateway library built on Hono for Cloudflare Workers and edge runtimes. Features:
|
|
130
|
-
|
|
131
|
-
- Gateway construction from declarative TypeScript config
|
|
132
|
-
- 43 policies across auth, traffic, resilience, transform, and observability domains
|
|
133
|
-
- 4-layer policy SDK with `definePolicy()`, priority constants, composable helpers, and test harness
|
|
134
|
-
- Three upstream types: URL proxy, Cloudflare Service Binding, and custom handler
|
|
135
|
-
- Runtime adapters for Cloudflare Workers, Node.js, Deno, and Bun
|
|
136
|
-
- Cloudflare-specific stores (KV, Durable Objects, Cache API)
|
|
137
|
-
- Admin introspection API with Prometheus metrics export
|
|
138
|
-
- W3C trace context propagation
|
|
139
|
-
- Zod-based config validation (optional peer dependency)
|
|
140
|
-
- Zero-dependency debug system with namespace filtering
|
|
141
|
-
- SSRF protection on URL upstreams
|