@vivero/stoma-cli 0.1.0-rc.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ # @vivero/stoma-cli
2
+
3
+ ## 0.1.0-rc.1
4
+ ### Minor Changes
5
+
6
+
7
+
8
+ - [`44f78e4`](https://github.com/vivero-dev/stoma/commit/44f78e462b92d6f719c6622e3e1126a6d343920f) Thanks [@JonathanBennett](https://github.com/JonathanBennett)! - Initial release of `@vivero/stoma-cli`
9
+
10
+ Local development server and interactive playground for Stoma API gateways.
11
+
12
+ ### Features
13
+
14
+ - **`stoma run <file>`**: Load a gateway file (TypeScript or JS) and serve it on a local Node.js HTTP server via `@hono/node-server`. TypeScript files are automatically bundled with esbuild — no build step or `tsconfig` required.
15
+ - **Remote gateway files**: `stoma run https://... --trust-remote` fetches, transpiles, and serves a gateway from a URL.
16
+ - **Flexible export resolution**: Supports `export default createGateway(...)`, async factory functions, `createPlaygroundGateway` named exports, and bare Hono apps.
17
+ - **Interactive playground** (`--playground`): Serves a browser UI at `/__playground` with a two-pane layout — request builder on the left, response viewer on the right. Includes:
18
+ - Route chips for quick path selection (wildcard paths like `/api/*` display as `/api/` to avoid 404s)
19
+ - Structured header key-value table with add/remove per row
20
+ - Response tabs: Pretty (syntax-highlighted JSON), Raw, and Headers (with count badge)
21
+ - Token store: OAuth tokens persisted in localStorage, auto-detected from response bodies, and auto-applied as `Authorization: Bearer` headers
22
+ - OAuth popup flow: redirect detection, authorization popup, callback relay via `postMessage`, and a banner prompting the user to complete the exchange
23
+ - **CLI options**: `--port`, `--host`, `--debug` (gateway debug logging), `--verbose` (CLI output), graceful shutdown on SIGINT/SIGTERM.
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [[`c14161a`](https://github.com/vivero-dev/stoma/commit/c14161a0846ef1991bb0fa71337435e6366579a7)]:
28
+ - @vivero/stoma@0.1.0-rc.6
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jonathan Bennett
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,188 @@
1
+ # @vivero/stoma-cli
2
+
3
+ CLI for running [Stoma](https://stoma.vivero.dev) API gateways locally. Load a gateway file (TypeScript or JavaScript, local or remote) and serve it on a Node.js HTTP server with an optional interactive playground.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install -g @vivero/stoma-cli
9
+ # or use directly with npx
10
+ npx @vivero/stoma-cli run ./my-gateway.ts
11
+ ```
12
+
13
+ The CLI requires `@vivero/stoma` and `hono` as peer dependencies. Both are included when you install the CLI as a project dependency alongside the gateway library.
14
+
15
+ ## Quick Start
16
+
17
+ Given a gateway file:
18
+
19
+ ```typescript
20
+ // gateway.ts
21
+ import { createGateway, health } from "@vivero/stoma";
22
+ import { memoryAdapter } from "@vivero/stoma/adapters";
23
+
24
+ export default createGateway({
25
+ name: "my-api",
26
+ adapter: memoryAdapter(),
27
+ routes: [
28
+ health({ path: "/health" }),
29
+ {
30
+ path: "/hello",
31
+ methods: ["GET"],
32
+ pipeline: {
33
+ upstream: {
34
+ type: "handler",
35
+ handler: (c) => c.json({ message: "Hello from Stoma" }),
36
+ },
37
+ },
38
+ },
39
+ ],
40
+ });
41
+ ```
42
+
43
+ Run it:
44
+
45
+ ```sh
46
+ stoma run ./gateway.ts
47
+ # Gateway "my-api" listening on http://localhost:8787
48
+ # GET /health
49
+ # GET /hello
50
+ ```
51
+
52
+ ## Commands
53
+
54
+ ### `stoma run <file> [options]`
55
+
56
+ Start a local HTTP server for a Stoma gateway file.
57
+
58
+ | Option | Alias | Default | Description |
59
+ |---|---|---|---|
60
+ | `--port` | `-p` | `8787` | Port to listen on |
61
+ | `--host` | `-H` | `localhost` | Hostname to bind to |
62
+ | `--debug` | `-d` | `false` | Enable gateway debug logging |
63
+ | `--verbose` | `-v` | `false` | Verbose CLI output (prints route table on load) |
64
+ | `--playground` | | `false` | Serve interactive playground UI at `/__playground` |
65
+ | `--trust-remote` | | `false` | Allow loading gateway files from remote URLs |
66
+
67
+ #### Examples
68
+
69
+ ```sh
70
+ # Run on a custom port
71
+ stoma run ./gateway.ts --port 3000
72
+
73
+ # Run with debug logging enabled
74
+ stoma run ./gateway.ts --debug
75
+
76
+ # Run with the interactive playground
77
+ stoma run ./gateway.ts --playground
78
+
79
+ # Run a remote gateway file
80
+ stoma run https://example.com/gateway.ts --trust-remote
81
+ ```
82
+
83
+ ### `stoma --help`
84
+
85
+ Print available commands and global options.
86
+
87
+ ### `stoma --version`
88
+
89
+ Print the CLI version.
90
+
91
+ ## Gateway File Resolution
92
+
93
+ The CLI accepts any file that exports a gateway in one of these forms (checked in order):
94
+
95
+ 1. **Named export `createPlaygroundGateway()`** — called as an async factory
96
+ 2. **Default export function** — called as an async factory, must return a gateway
97
+ 3. **Default export object** with `.app` and `._registry` — used directly as a `GatewayInstance`
98
+ 4. **Default export object** with `.fetch` — treated as a bare Hono app, wrapped in a minimal gateway instance
99
+
100
+ TypeScript files (`.ts`, `.tsx`, `.mts`) are automatically bundled with esbuild before importing. The CLI provides its own `@vivero/stoma` and `hono` packages via `nodePaths`, so gateway files work without a local `node_modules` — you can run a standalone `.ts` file from anywhere (e.g. `~/Downloads/`).
101
+
102
+ ## Remote Gateway Files
103
+
104
+ The CLI can fetch and run gateway files from URLs:
105
+
106
+ ```sh
107
+ stoma run https://raw.githubusercontent.com/user/repo/main/gateway.ts --trust-remote
108
+ ```
109
+
110
+ The `--trust-remote` flag is required because this downloads and executes arbitrary code. Only use it with sources you trust.
111
+
112
+ The file extension is inferred from the URL path. If the URL has no recognisable extension, the CLI falls back to the response `content-type` header, and ultimately defaults to `.ts` (esbuild can transpile both TypeScript and plain JavaScript).
113
+
114
+ The fetched file is written to a temporary directory, resolved through the normal pipeline, and cleaned up after loading.
115
+
116
+ ## Playground
117
+
118
+ When `--playground` is passed, the CLI serves an interactive UI at `/__playground` that lets you:
119
+
120
+ - Browse all registered routes and their policies
121
+ - Send requests to any route and inspect the full response (status, headers, body, timing)
122
+ - Test OAuth flows — callback routes are intercepted with a relay page that sends parameters back to the playground via `postMessage`
123
+
124
+ The playground makes requests server-side (bypassing browser CORS/redirect limitations), so you get accurate response details including redirect responses and custom headers.
125
+
126
+ Playground routes:
127
+
128
+ | Path | Purpose |
129
+ |---|---|
130
+ | `/__playground` | Interactive UI |
131
+ | `/__playground/registry` | Gateway registry as JSON |
132
+ | `/__playground/send` | Server-side request proxy (POST) |
133
+
134
+ ## Graceful Shutdown
135
+
136
+ Press `Ctrl+C` to shut down. The CLI:
137
+
138
+ 1. Stops accepting new connections
139
+ 2. Destroys all active connections
140
+ 3. Waits for the server to close (up to 3 seconds)
141
+ 4. Force-exits if graceful shutdown stalls
142
+
143
+ Pressing `Ctrl+C` a second time force-exits immediately.
144
+
145
+ ## Development
146
+
147
+ ```sh
148
+ # Run from source (no build needed)
149
+ yarn dev run ./path/to/gateway.ts
150
+
151
+ # Build for publishing
152
+ yarn build
153
+
154
+ # Run tests
155
+ yarn test
156
+
157
+ # Type-check
158
+ yarn typecheck
159
+ ```
160
+
161
+ The package exports raw TypeScript source during development — workspace consumers resolve it directly via the `exports` field. The `yarn build` script (tsup) compiles to `dist/` for npm publishing only.
162
+
163
+ ## Architecture
164
+
165
+ ```
166
+ src/
167
+ ├── bin.ts # Entry point — invokes the CLI
168
+ ├── cli.ts # Clipanion CLI setup (registers commands)
169
+ ├── commands/
170
+ │ ├── index.ts # Command re-exports
171
+ │ └── run.ts # `stoma run` command
172
+ ├── gateway/
173
+ │ ├── resolve.ts # Gateway loading: TS transpilation, remote fetch, export resolution
174
+ │ └── types.ts # GatewayInstance, GatewayRegistry types
175
+ ├── server/
176
+ │ └── serve.ts # @hono/node-server wrapper
177
+ ├── playground/
178
+ │ ├── wrap.ts # Wraps gateway fetch with playground routes
179
+ │ ├── html.ts # Playground UI (self-contained HTML/CSS/JS)
180
+ │ └── oauth-relay.ts # OAuth callback relay page
181
+ └── utils/
182
+ ├── logger.ts # Simple console logger with verbose mode
183
+ └── version.ts # Reads version from package.json
184
+ ```
185
+
186
+ ## License
187
+
188
+ MIT