@dhaneshpurohit/mockstar 0.1.3

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.
Files changed (156) hide show
  1. package/CHANGELOG.md +180 -0
  2. package/LICENSE +21 -0
  3. package/README.md +260 -0
  4. package/dist/cli/commands/init.d.ts +13 -0
  5. package/dist/cli/commands/init.d.ts.map +1 -0
  6. package/dist/cli/commands/migrate.d.ts +13 -0
  7. package/dist/cli/commands/migrate.d.ts.map +1 -0
  8. package/dist/cli.d.ts +3 -0
  9. package/dist/cli.d.ts.map +1 -0
  10. package/dist/cli.js +15076 -0
  11. package/dist/core/config/index.d.ts +5 -0
  12. package/dist/core/config/index.d.ts.map +1 -0
  13. package/dist/core/config/loader.d.ts +14 -0
  14. package/dist/core/config/loader.d.ts.map +1 -0
  15. package/dist/core/config/schema.d.ts +5706 -0
  16. package/dist/core/config/schema.d.ts.map +1 -0
  17. package/dist/core/config/snapshot.d.ts +52 -0
  18. package/dist/core/config/snapshot.d.ts.map +1 -0
  19. package/dist/core/config/watcher.d.ts +13 -0
  20. package/dist/core/config/watcher.d.ts.map +1 -0
  21. package/dist/core/errors/boundary.d.ts +22 -0
  22. package/dist/core/errors/boundary.d.ts.map +1 -0
  23. package/dist/core/errors/index.d.ts +3 -0
  24. package/dist/core/errors/index.d.ts.map +1 -0
  25. package/dist/core/errors/process.d.ts +17 -0
  26. package/dist/core/errors/process.d.ts.map +1 -0
  27. package/dist/core/handlers/index.d.ts +4 -0
  28. package/dist/core/handlers/index.d.ts.map +1 -0
  29. package/dist/core/handlers/registry.d.ts +22 -0
  30. package/dist/core/handlers/registry.d.ts.map +1 -0
  31. package/dist/core/handlers/types.d.ts +42 -0
  32. package/dist/core/handlers/types.d.ts.map +1 -0
  33. package/dist/core/journal/index.d.ts +2 -0
  34. package/dist/core/journal/index.d.ts.map +1 -0
  35. package/dist/core/journal/ring-buffer.d.ts +46 -0
  36. package/dist/core/journal/ring-buffer.d.ts.map +1 -0
  37. package/dist/core/matching/discriminators.d.ts +29 -0
  38. package/dist/core/matching/discriminators.d.ts.map +1 -0
  39. package/dist/core/matching/index.d.ts +24 -0
  40. package/dist/core/matching/index.d.ts.map +1 -0
  41. package/dist/core/matching/path-trie.d.ts +21 -0
  42. package/dist/core/matching/path-trie.d.ts.map +1 -0
  43. package/dist/core/observability/index.d.ts +3 -0
  44. package/dist/core/observability/index.d.ts.map +1 -0
  45. package/dist/core/observability/logger.d.ts +18 -0
  46. package/dist/core/observability/logger.d.ts.map +1 -0
  47. package/dist/core/observability/metrics.d.ts +23 -0
  48. package/dist/core/observability/metrics.d.ts.map +1 -0
  49. package/dist/core/preflight.d.ts +18 -0
  50. package/dist/core/preflight.d.ts.map +1 -0
  51. package/dist/core/scenarios/evaluator.d.ts +52 -0
  52. package/dist/core/scenarios/evaluator.d.ts.map +1 -0
  53. package/dist/core/scenarios/index.d.ts +5 -0
  54. package/dist/core/scenarios/index.d.ts.map +1 -0
  55. package/dist/core/scenarios/merger.d.ts +45 -0
  56. package/dist/core/scenarios/merger.d.ts.map +1 -0
  57. package/dist/core/templating/compiler.d.ts +118 -0
  58. package/dist/core/templating/compiler.d.ts.map +1 -0
  59. package/dist/core/templating/faker.d.ts +14 -0
  60. package/dist/core/templating/faker.d.ts.map +1 -0
  61. package/dist/core/templating/index.d.ts +4 -0
  62. package/dist/core/templating/index.d.ts.map +1 -0
  63. package/dist/core/templating/tier2/id.d.ts +27 -0
  64. package/dist/core/templating/tier2/id.d.ts.map +1 -0
  65. package/dist/core/templating/tier2/index.d.ts +4 -0
  66. package/dist/core/templating/tier2/index.d.ts.map +1 -0
  67. package/dist/core/templating/tier2/now.d.ts +15 -0
  68. package/dist/core/templating/tier2/now.d.ts.map +1 -0
  69. package/dist/core/templating/tier2/walker.d.ts +43 -0
  70. package/dist/core/templating/tier2/walker.d.ts.map +1 -0
  71. package/dist/core/tenancy/extractor.d.ts +20 -0
  72. package/dist/core/tenancy/extractor.d.ts.map +1 -0
  73. package/dist/core/tenancy/index.d.ts +2 -0
  74. package/dist/core/tenancy/index.d.ts.map +1 -0
  75. package/dist/features/admin/auth.d.ts +19 -0
  76. package/dist/features/admin/auth.d.ts.map +1 -0
  77. package/dist/features/admin/endpoints.d.ts +21 -0
  78. package/dist/features/admin/endpoints.d.ts.map +1 -0
  79. package/dist/features/admin/index.d.ts +3 -0
  80. package/dist/features/admin/index.d.ts.map +1 -0
  81. package/dist/features/dynamic-mock.d.ts +16 -0
  82. package/dist/features/dynamic-mock.d.ts.map +1 -0
  83. package/dist/features/enhance/boundary.d.ts +26 -0
  84. package/dist/features/enhance/boundary.d.ts.map +1 -0
  85. package/dist/features/enhance/field-mapping.d.ts +23 -0
  86. package/dist/features/enhance/field-mapping.d.ts.map +1 -0
  87. package/dist/features/enhance/index.d.ts +21 -0
  88. package/dist/features/enhance/index.d.ts.map +1 -0
  89. package/dist/features/openapi/converter.d.ts +55 -0
  90. package/dist/features/openapi/converter.d.ts.map +1 -0
  91. package/dist/features/openapi/importer.d.ts +11 -0
  92. package/dist/features/openapi/importer.d.ts.map +1 -0
  93. package/dist/features/openapi/index.d.ts +3 -0
  94. package/dist/features/openapi/index.d.ts.map +1 -0
  95. package/dist/features/pass-through.d.ts +9 -0
  96. package/dist/features/pass-through.d.ts.map +1 -0
  97. package/dist/features/proxy/ca.d.ts +49 -0
  98. package/dist/features/proxy/ca.d.ts.map +1 -0
  99. package/dist/features/proxy/cert-cache.d.ts +34 -0
  100. package/dist/features/proxy/cert-cache.d.ts.map +1 -0
  101. package/dist/features/proxy/cli.d.ts +2 -0
  102. package/dist/features/proxy/cli.d.ts.map +1 -0
  103. package/dist/features/proxy/config.d.ts +71 -0
  104. package/dist/features/proxy/config.d.ts.map +1 -0
  105. package/dist/features/proxy/dns.d.ts +18 -0
  106. package/dist/features/proxy/dns.d.ts.map +1 -0
  107. package/dist/features/proxy/env-detector.d.ts +7 -0
  108. package/dist/features/proxy/env-detector.d.ts.map +1 -0
  109. package/dist/features/proxy/index.d.ts +15 -0
  110. package/dist/features/proxy/index.d.ts.map +1 -0
  111. package/dist/features/proxy/install-journal.d.ts +51 -0
  112. package/dist/features/proxy/install-journal.d.ts.map +1 -0
  113. package/dist/features/proxy/port-bind.d.ts +33 -0
  114. package/dist/features/proxy/port-bind.d.ts.map +1 -0
  115. package/dist/features/proxy/server.d.ts +19 -0
  116. package/dist/features/proxy/server.d.ts.map +1 -0
  117. package/dist/features/proxy/sni-gate.d.ts +17 -0
  118. package/dist/features/proxy/sni-gate.d.ts.map +1 -0
  119. package/dist/features/proxy/tls-adapter.d.ts +52 -0
  120. package/dist/features/proxy/tls-adapter.d.ts.map +1 -0
  121. package/dist/features/proxy/types.d.ts +103 -0
  122. package/dist/features/proxy/types.d.ts.map +1 -0
  123. package/dist/features/proxy/upstream.d.ts +23 -0
  124. package/dist/features/proxy/upstream.d.ts.map +1 -0
  125. package/dist/features/spec/index.d.ts +17 -0
  126. package/dist/features/spec/index.d.ts.map +1 -0
  127. package/dist/features/static-mock.d.ts +23 -0
  128. package/dist/features/static-mock.d.ts.map +1 -0
  129. package/dist/features/url-validator.d.ts +53 -0
  130. package/dist/features/url-validator.d.ts.map +1 -0
  131. package/dist/features/webhooks/circuit-breaker.d.ts +49 -0
  132. package/dist/features/webhooks/circuit-breaker.d.ts.map +1 -0
  133. package/dist/features/webhooks/compile.d.ts +16 -0
  134. package/dist/features/webhooks/compile.d.ts.map +1 -0
  135. package/dist/features/webhooks/dispatcher.d.ts +45 -0
  136. package/dist/features/webhooks/dispatcher.d.ts.map +1 -0
  137. package/dist/features/webhooks/event-registry.d.ts +36 -0
  138. package/dist/features/webhooks/event-registry.d.ts.map +1 -0
  139. package/dist/features/webhooks/index.d.ts +13 -0
  140. package/dist/features/webhooks/index.d.ts.map +1 -0
  141. package/dist/features/webhooks/journal.d.ts +32 -0
  142. package/dist/features/webhooks/journal.d.ts.map +1 -0
  143. package/dist/features/webhooks/queue.d.ts +93 -0
  144. package/dist/features/webhooks/queue.d.ts.map +1 -0
  145. package/dist/features/webhooks/signing.d.ts +35 -0
  146. package/dist/features/webhooks/signing.d.ts.map +1 -0
  147. package/dist/features/webhooks/types.d.ts +96 -0
  148. package/dist/features/webhooks/types.d.ts.map +1 -0
  149. package/dist/index.d.ts +30 -0
  150. package/dist/index.d.ts.map +1 -0
  151. package/dist/index.js +12813 -0
  152. package/dist/server.d.ts +62 -0
  153. package/dist/server.d.ts.map +1 -0
  154. package/dist/version.d.ts +2 -0
  155. package/dist/version.d.ts.map +1 -0
  156. package/package.json +62 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,180 @@
1
+ ## [0.1.3](https://github.com/dhanesh/mockstar/compare/v0.1.2...v0.1.3) (2026-06-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **cli:** derive version from package.json (stop hardcoded constant going stale) ([cde5735](https://github.com/dhanesh/mockstar/commit/cde573529561646eaa62121603a197772137a88c))
7
+ * **release:** trigger release.yml on auto-tags (drop [skip ci]) ([b7a340b](https://github.com/dhanesh/mockstar/commit/b7a340b6d74843d7a881216b73d6b5a01e112489))
8
+
9
+ ## [0.1.2](https://github.com/dhanesh/mockstar/compare/v0.1.1...v0.1.2) (2026-06-23)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * **cli:** recognize the `serve` subcommand keyword ([288edc5](https://github.com/dhanesh/mockstar/commit/288edc527d56f09dd5965488e7edd8b0b6e5716d))
15
+
16
+ ## [0.1.1](https://github.com/dhanesh/mockstar/compare/v0.1.0...v0.1.1) (2026-06-23)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * **schema:** regenerate schema/VERSION for 0.1.0 ([7766ad7](https://github.com/dhanesh/mockstar/commit/7766ad777f0cb38c8c0e82930735620e5df59b8c))
22
+
23
+ # Changelog
24
+
25
+ All notable changes to Mockstar are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
26
+
27
+ ## [Unreleased] — v1.0 scope (target)
28
+
29
+ > Satisfies RT-11 (v1 scope explicitly documented).
30
+
31
+ ### In v1.0
32
+
33
+ - **Mocking.** Static mocks; dynamic mocks via named JS handlers loaded from `handlers/`.
34
+ - **Scenarios.** Attribute-keyed branching within a single mock entry — different responses for different request shapes without separate files. See `docs/SCENARIOS.md`.
35
+ - **Outbound webhooks.** Per-route `webhooks: [...]` fire after the matched response flushes. HMAC-SHA256 signing (opt-in, env/file secrets), explicit retry curves with circuit breaker, drop-oldest queue cap, sync await admin endpoint for SDET assertions, optional response-body assertion, post-restart JSONL journal file. In-process queue (no Redis). See `docs/webhooks/`.
36
+ - **Config.** JSON mock configs validated by Zod at boot (fail-fast) and on hot-reload (warn-and-keep-previous). Exported JSON Schema for editor autocomplete.
37
+ - **Request matching.** Method + path + path params + query (exact / partial) + headers (exact / regex) + JSON body (partial + JSONPath). Precomputed match index for O(log n) first-level dispatch.
38
+ - **Pass-through.** Per-route opt-in proxy to an explicit upstream with configurable timeout and structured 502 on failure. Upstream URLs validated via the shared hardened URL validator.
39
+ - **Multi-tenancy.** Tenants identified by URL path prefix, subdomain, or `X-Mockstar-Tenant` header (deployment-configurable). Per-tenant config directories, per-tenant journal, per-tenant rate limits.
40
+ - **Test-data utilities.** `{{ }}` templating with faker-style generators, request-value echo, `{{ env.X }}` interpolation, and fixed/jittered delay simulation.
41
+ - **OpenAPI import.** Offline converter `mockstar import openapi.yaml → mocks/{tenant}/`. Runs as an isolated Bun subprocess. External `$ref` resolution disabled.
42
+ - **Observability.** JSON stdout logs, Prometheus `/metrics`, per-tenant bounded request journal, `/health` + `/ready`.
43
+ - **Error isolation.** Per-request try/catch tier + process-level `unhandledRejection`/`uncaughtException` hooks that flip `/ready` to 503 and exit for orchestrator restart.
44
+ - **Deterministic mode.** `MOCKSTAR_DETERMINISTIC=1` makes CI assertions byte-identical across runs.
45
+ - **Distribution.** `bunx mockstar`, Docker image, compiled single binary, and library embed (`import { createServer } from 'mockstar'`).
46
+ - **Admin read endpoints** (journal, metrics, ready) with two-tier token auth (per-tenant + optional root).
47
+
48
+ ### Deferred to v1.1
49
+
50
+ - **Admin write API.** Runtime CRUD on mocks without filesystem access. In v1 the DevOps persona deploys via K8s ConfigMap or Docker volume mount.
51
+ - **Stateful mocks.** Named state, transitions, sequenced responses. (Scenarios shipped — see "In v1.0".)
52
+ - **GraphQL / gRPC mocking.**
53
+ - **Fault injection / chaos.**
54
+ - **Recording mode.** Record real traffic into mock configs from a live upstream.
55
+ - **Webhook auto-resume across restart.** Pending in-flight retries are lost on restart — `--webhook-journal-file` persists delivery records but does not auto-replay them on next boot. Cross-restart replay is a manual admin call.
56
+
57
+ ### Known limitations
58
+
59
+ - Compiled binary boot SLO is `< 500 ms` vs. `< 200 ms` for bunx / library / Docker-process — runtime init overhead is out of our control (see TN4 in `.manifold/mockstar.md`).
60
+ - Production deployment requires a restart-capable orchestrator (Docker `restart=always`, K8s `RestartPolicy: Always`, systemd `Restart=on-failure`). See `docs/DEPLOYMENT.md`.
61
+
62
+ ## Tier 1 — HTTPS transparent upstream (`mockstar proxy`)
63
+
64
+ _Constraint-first designed in `.manifold/tier1-https-proxy.md`. Binding constraint: RT-1 (local CA)._
65
+
66
+ ### In v1 proxy
67
+
68
+ - **HTTPS termination** on `127.0.0.1:443` via Bun's TLS stack.
69
+ - **Local CA** managed by [mkcert](https://github.com/FiloSottile/mkcert). CA common name includes user + hostname for self-identification (S5).
70
+ - **On-demand leaf certificates** with 24-hour TTL (TN4); SNI-gated issuance refuses unknown hostnames (RT-3, S3).
71
+ - **DNS** via dnsmasq (default) with automatic `/etc/hosts` fallback on hostile environments (RT-5 + TN2).
72
+ - **Port 443 binding** via OS capability grants (Linux setcap / macOS launchd) — no sudo at runtime.
73
+ - **Atomic install / uninstall** with append-only journal at `~/.mockstar/install-state.json`; LIFO rollback on failure (RT-7).
74
+ - **Environment hostility detection** refuses install in CI/container environments (S4), warns on MDM / VPN DNS overrides (RT-10).
75
+ - **Observability** reuses mockstar's logger + metrics primitives (RT-9).
76
+ - **CLI** integrated as `mockstar proxy {install|start|uninstall|status|reload}`.
77
+ - **Node.js gotcha** prominently documented: `NODE_EXTRA_CA_CERTS` required for Node-based SDKs (U4).
78
+
79
+ ### Deferred to v1.1 (proxy)
80
+
81
+ - **Windows** native support. v1 is macOS + Linux only (B2). WSL2 works today.
82
+ - **Traffic recording** — proxy observes but doesn't persist request/response bodies.
83
+ - **Mutual TLS** (client-cert auth).
84
+ - **Request transformation** — header rewrites, body mutation, etc.
85
+ - **Wildcard hostnames** — configure subdomains explicitly in v1.
86
+ - **OS keychain-backed CA key** — rootCA-key.pem lives in mkcert's default path with 0600 file perms today; keychain storage (Touch-ID-gated on macOS) is a v1.1 hardening.
87
+
88
+ ### Proxy known limitations
89
+
90
+ - First TLS handshake per hostname is slower (~50–100 ms cert generation); subsequent handshakes hit the cache (~sub-ms).
91
+ - SDKs that pin certificate fingerprints (not CAs) cannot be proxied. No known Razorpay/Stripe/Twilio SDK currently pins.
92
+ - Production deployment is explicitly out of scope — this is a developer-laptop tool (B3).
93
+
94
+ ---
95
+
96
+ ## Outbound webhooks
97
+
98
+ _Constraint-first designed in `.manifold/webhooks.md`. Binding constraint: RT-1 (in-process queue primitive). 26 constraints, 7 tensions, 16 required truths, all SATISFIED at TESTED level._
99
+
100
+ ### In v1 webhooks
101
+
102
+ - **Per-route attachment.** `webhooks: WebhookSpec[]` field on any `MockEntry` (T5). Fires after matched response flushes via `queueMicrotask` — served-request latency unaffected (T4).
103
+ - **Configuration channels.** Per-route `url`, `{{ env.NAME }}` interpolation, admin API list/journal/replay/await endpoints, opt-in `X-Mockstar-Webhook-Url` request header (B2, B5).
104
+ - **Industry-standard delivery contract.** At-least-once-within-bounds, exponential backoff with ±jitter (default `[1s, 2s, 4s, 8s, 16s]`), idempotent `X-Mockstar-Delivery-Id` (B3).
105
+ - **HMAC-SHA256 signing.** Opt-in per webhook. Stripe-style `${ts}.${rawBody}` signed payload, configurable signature/timestamp headers, default 5-min replay window. Secrets via `{{ env.X }}` or `file:/path` only — inline rejected at config-load (S1, S3, RT-2).
106
+ - **In-process queue.** `p-queue` for concurrency, hand-rolled retry loop for explicit backoff arrays. Per-tenant isolation, drop-oldest cap (default 1024), `webhook_queue_dropped_total` counter on overflow (T1, O1, TN2).
107
+ - **Per-webhook circuit breaker.** Three-state machine (closed/open/half-open), default 5-failure threshold + 30s cooldown (O3).
108
+ - **Hardened URL validation.** Reuses `validateUpstreamUrl` from the proxy. HTTPS-only by default; per-webhook `allowHttp` and `allowPrivateNetworks` opt-ins are independent (T6, S2, TN4).
109
+ - **Admin path skip.** `/_mockstar/*`, `/__admin/*`, `/health`, `/ready`, `/metrics` NEVER trigger webhooks regardless of `match.path` (S4).
110
+ - **Sync await.** `POST /__admin/tenants/:t/webhooks/await?id=…` resolves on terminal state — eliminates flaky polling in SDET test suites (U1, TN3).
111
+ - **Replay.** `POST /__admin/tenants/:t/webhooks/:deliveryId/replay` re-enqueues using the current snapshot's spec; 410 if the spec was removed since the original delivery (O4, TN7).
112
+ - **Optional `--webhook-journal-file <path>`** appends every delivery attempt as JSONL for post-restart forensic replay (T2, INT-1).
113
+ - **Observability.** Five Prometheus metrics + Grafana dashboard + alert rules + two runbooks (queue overflow, circuit trip).
114
+
115
+ ### Deferred for webhooks
116
+
117
+ - **Auto-resume across restart.** In-flight retries are lost on restart by design (TN6, in-memory only). `--webhook-journal-file` plus admin replay is the supported workflow.
118
+ - **Type-preserving JSON-body templating for webhook payloads.** Bodies render as strings (whole-string templates only); type-preservation for JSON leaves matches response-body semantics — deferred to v0.2.
119
+ - **Pluggable queue interface.** No `WebhookQueue` extension contract pre-1.0 — hand-rolled-lean discipline holds. Re-evaluate if SDETs request durable queuing.
120
+ - **Public `# TYPE` lines in metrics output.** Cross-feature gap; counters and histograms also lack them. Tracked separately.
121
+
122
+ ### Webhook known limitations
123
+
124
+ - HMAC-SHA256 is the only signing algorithm in v0.x.
125
+ - Replay templates render against an empty inbound-request snapshot — `{{ request.body.x }}` resolves to empty string. Documented as a recovery-tool semantics, not a wire-replay primitive.
126
+ - High-concurrency `AbortSignal.timeout` socket hygiene is functionally tested but not load-tested (post-deploy SRE concern).
127
+
128
+ ---
129
+
130
+ ## [0.1.0] — 2026-06-23
131
+
132
+ First stable release — consolidates the `0.1.0-alpha`/`rc` line into a signed,
133
+ multi-arch, container-first distribution.
134
+
135
+ ### Added
136
+ - **Signed multi-arch container** at `ghcr.io/dhanesh/mockstar` (`linux/amd64` +
137
+ `linux/arm64`), cosign-signed by digest with a CycloneDX SBOM + Trivy scan;
138
+ SLSA build provenance on stable tags.
139
+ - **Helm chart** (`charts/mockstar`) — single-replica, secure-by-default (non-root
140
+ uid 10001, read-only root FS, dropped caps), `/health` + `/ready` probes,
141
+ per-tenant ConfigMap mounts, optional handlers mount; published as a signed OCI
142
+ artifact at `ghcr.io/dhanesh/charts/mockstar`.
143
+ - **Automated versioning** via semantic-release (conventional commits → tag →
144
+ release pipeline). See `docs/releasing.md`.
145
+
146
+ ### Changed
147
+ - npm package scoped to `@dhaneshpurohit/mockstar`; npm publish is opt-in via the
148
+ `PUBLISH_NPM` repo variable (container/helm/binaries publish regardless).
149
+ - Minimum supported Bun raised to **1.3.0** (pinned toolchain `1.3.14`).
150
+
151
+ ### Verified
152
+ - Outbound webhooks (delivery, request-reflection templating, HMAC-SHA256 signing,
153
+ `expectResponse` fan-out); DNS-resolving SSRF guard; circuit-breaker single
154
+ half-open probe. CI green across the Bun matrix (1.3.0 + latest).
155
+
156
+ ## [0.1.0-rc.1] — 2026-04-20
157
+
158
+ > Satisfies RT-18 (CHANGELOG-gated release) — first tagged artifact the release workflow is expected to build end-to-end.
159
+
160
+ ### Added (distribution-packaging manifold)
161
+ - **Pinned Bun runtime** via `.bun-version` (RT-1). All workflows read it.
162
+ - **Dual-URL JSON Schema hosting** at `schemas.mockstar.dev/v0/` (rolling) and `/v0.N/` (immutable) via `schema-publish.yml` (RT-2). `docs/SCHEMA-HOSTING.md` documents the contract.
163
+ - **`mockstar init [dir]`** — scaffolds `mocks/default/example.json` + `mockstar.config.json` with `$schema` pinned to the current minor (RT-13, RT-14).
164
+ - **`mockstar migrate --schema --from vX.Y --to vX.Z`** — rewrites `$schema` URLs when a minor bump ships (RT-2).
165
+ - **npm Trusted Publishing via OIDC** with auto-provenance (RT-3, RT-7). No `NPM_TOKEN` in CI.
166
+ - **Cosign keyless signing by digest** (never by tag) for container + Helm chart (RT-4).
167
+ - **CycloneDX SBOM attestation** via `cosign attest --type cyclonedx` (RT-4).
168
+ - **SLSA Level 3 build provenance** on stable releases only (TN1 resolution — pre-releases skip SLSA; RT-5).
169
+ - **`halt-clean` job** — deletes unsigned container tags if any publish step fails, so S1 ("every published artifact is signed") is never silently violated (RT-6).
170
+ - **Four-target binary matrix** via `bun build --compile` covering darwin-arm64/x64 and linux-arm64/x64, 150 MB ceiling enforced (RT-9, TN2).
171
+ - **Multi-arch container** (`linux/amd64,linux/arm64`) with `provenance: mode=max` and SBOM (RT-8).
172
+ - **Helm chart as OCI artifact** at `ghcr.io/.../charts/mockstar`, digest-preferred image resolution, labeled-ConfigMap tenant pattern that survives `helm upgrade`/`rollback` (RT-10, RT-11, RT-12, TN5).
173
+ - **Per-persona 5-minute quickstart-smoke CI** (Dev / SDET / DevOps) enforcing the SLO at the job level (RT-13).
174
+ - **Trivy CVE gate** on release — CRITICAL severity, `ignore-unfixed: true`, fails on fixable CVEs (RT-19).
175
+ - **SDET support matrix** covering Jest 30, Jest 29, Vitest 2, and `bun test` with runnable examples (RT-15).
176
+ - **Team + versioning docs** — `CONTRIBUTING.md`, `docs/TEAM-WORKFLOW.md`, `docs/VERSIONING.md`, OIDC setup checklist (RT-16, RT-17).
177
+
178
+ ## [0.1.0-alpha.1] — 2026-04-13
179
+
180
+ - Initial constraint-first scaffold generated from `/manifold:m4-generate`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mockstar contributors
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,260 @@
1
+ # Mockstar
2
+
3
+ [![quickstart-smoke](https://github.com/dhanesh/mockstar/actions/workflows/quickstart-smoke.yml/badge.svg)](https://github.com/dhanesh/mockstar/actions/workflows/quickstart-smoke.yml)
4
+ [![release](https://github.com/dhanesh/mockstar/actions/workflows/release.yml/badge.svg)](https://github.com/dhanesh/mockstar/actions/workflows/release.yml)
5
+
6
+ > **Status:** pre-1.0. Minors may break mocks-file shape — see [docs/VERSIONING.md](./docs/VERSIONING.md). Pin `$schema` to `https://schemas.mockstar.dev/v0.<N>/mock.json` for stability.
7
+
8
+ > A Bun-based mock server with static + dynamic mocking, JSON config, named JS handlers, pass-through routing, multi-tenancy, and test-data utilities.
9
+
10
+ ## Demo
11
+
12
+ ![mockstar demo — make docker-run + curl](./docs/media/demo.svg)
13
+
14
+ <sub>Recorded with [asciinema](https://asciinema.org/) — raw cast at [`docs/media/demo.cast`](./docs/media/demo.cast). Regenerate with `make record-demo` (requires `asciinema`, `jq`, `npx`, Docker).</sub>
15
+
16
+ ## For SDETs
17
+
18
+ Mockstar ships a library embed (`import { launch } from '@dhaneshpurohit/mockstar'`) supported
19
+ across Jest 30, Jest 29, Vitest, and `bun test`. See [docs/SDET.md](./docs/SDET.md)
20
+ + the [`examples/sdet-*`](./examples) directories.
21
+
22
+ ## Contributing
23
+
24
+ Read [CONTRIBUTING.md](./CONTRIBUTING.md). Maintainers: [docs/TEAM-WORKFLOW.md](./docs/TEAM-WORKFLOW.md).
25
+
26
+
27
+ Mockstar targets three personas equally:
28
+
29
+ - **SDETs** — library-embed in test suites, ephemeral instances per CI run, deterministic mode
30
+ - **Developers** — `bunx @dhaneshpurohit/mockstar ./mocks` with file-watch hot reload
31
+ - **DevOps** — Docker image in shared staging with per-tenant ConfigMap mounts
32
+
33
+ > Built on [Hono](https://hono.dev/) on [Bun](https://bun.sh/). Targets p99 < 5ms for static mock responses. See [DECISIONS.md](./docs/DECISIONS.md) for the constraint-first design record.
34
+
35
+ ## Quick start
36
+
37
+ ```bash
38
+ bun install
39
+ bun run src/cli.ts ./examples/mocks
40
+ # http://localhost:3000
41
+ ```
42
+
43
+ A persona-specific deployment walkthrough lives in [docs/DEPLOYMENT.md](./docs/DEPLOYMENT.md).
44
+
45
+ ## Config layout
46
+
47
+ ```
48
+ mocks/
49
+ default/ # one directory per tenant
50
+ users.json # a mock config file
51
+ orders.json
52
+ handlers/ # named JS function handlers
53
+ echo.ts
54
+ ```
55
+
56
+ See [docs/CONFIG.md](./docs/CONFIG.md) for the full schema and [docs/HANDLERS.md](./docs/HANDLERS.md) for dynamic handlers.
57
+
58
+ ## Response templating
59
+
60
+ Any string value inside `response.body` or `response.headers` can contain `{{ … }}` placeholders. Whole-string placeholders in a JSON body preserve their source type — a number stays a number, an object stays an object.
61
+
62
+ ### Request reflection
63
+
64
+ | Token | Value |
65
+ |---|---|
66
+ | `{{request.method}}` | HTTP verb (`GET`, `POST`, …) |
67
+ | `{{request.path}}` | Full request path |
68
+ | `{{request.params.<name>}}` | Path parameter captured by `:name` in `match.path` |
69
+ | `{{request.query.<name>}}` | URL query-string value |
70
+ | `{{request.headers.<name>}}` | Request header value (case-insensitive) |
71
+ | `{{request.body.<dot.path>}}` | Dot-path into the parsed JSON request body |
72
+
73
+ ### Context
74
+
75
+ | Token | Value |
76
+ |---|---|
77
+ | `{{tenant}}` | Tenant identifier the request was routed to |
78
+ | `{{requestId}}` | Per-request UUID assigned by mockstar |
79
+
80
+ ### Random data (faker)
81
+
82
+ | Token | Value |
83
+ |---|---|
84
+ | `{{faker.uuid}}` | Random UUID v4 |
85
+ | `{{faker.email}}` | Random email address |
86
+ | `{{faker.name}}` | Random full name |
87
+ | `{{faker.integer(min, max)}}` | Random integer in `[min, max]` |
88
+ | `{{faker.pick(["a","b","c"])}}` | Random element from the array |
89
+ | `{{faker.boolean}}` | `true` or `false` |
90
+ | `{{faker.dateIso}}` | Random recent date as ISO 8601 string |
91
+
92
+ ### Provider-shape IDs
93
+
94
+ | Token | Value |
95
+ |---|---|
96
+ | `{{id("prefix_", 14)}}` | `prefix_` + 14 random base62 chars — e.g. `order_4OwxzMjhPIt4YQ` |
97
+ | `{{id("prefix_", 14, "0123456789abcdef")}}` | Same with a custom alphabet (hex shown) |
98
+ | `{{id.named("key", "prefix_", 14)}}` | Mint once per request per name — repeated calls with the same `key` return the identical value, useful when the same ID appears in multiple fields |
99
+
100
+ ### Timestamps
101
+
102
+ | Token | Value |
103
+ |---|---|
104
+ | `{{now.unix}}` | Current time as Unix seconds (number) |
105
+ | `{{now.millis}}` | Current time as Unix milliseconds (number) |
106
+ | `{{now.iso}}` | Current time as ISO 8601 string |
107
+
108
+ In `--deterministic` mode (`MOCKSTAR_DETERMINISTIC=1`) all faker and `now.*` tokens return fixed seed-derived values so CI replays are byte-identical.
109
+
110
+ Full reference including type-preservation rules and worked examples: [docs/TIER2.md](./docs/TIER2.md).
111
+
112
+ ## Outbound webhooks
113
+
114
+ Attach `webhooks: [...]` to any mock entry to fire HTTP deliveries **after** the matched response flushes — useful for verifying receiver-side webhook handlers in integration tests, dogfooding partner integrations, and modeling provider behavior in fixtures.
115
+
116
+ ```jsonc
117
+ {
118
+ "id": "orders-create",
119
+ "match": { "method": "POST", "path": "/orders" },
120
+ "response": { "kind": "static", "status": 201, "body": { "id": "{{id(\"ord_\", 12)}}" } },
121
+ "webhooks": [{
122
+ "id": "order-created",
123
+ "url": "https://api.partner.example/hooks/order-created",
124
+ "method": "POST",
125
+ "headers": { "content-type": "application/json" },
126
+ "body": { "orderId": "{{request.body.orderId}}", "tenant": "{{tenant}}" }
127
+ }]
128
+ }
129
+ ```
130
+
131
+ Capabilities at a glance:
132
+
133
+ | | |
134
+ |---|---|
135
+ | **Configuration channels** | Per-route `url`, `{{ env.NAME }}` interpolation, admin API, opt-in `X-Mockstar-Webhook-Url` request header (gated by `--allow-webhook-url-header`) |
136
+ | **Delivery contract** | At-least-once within queue + circuit bounds, exponential backoff with jitter (default `[1s, 2s, 4s, 8s, 16s]`), idempotent `X-Mockstar-Delivery-Id` header |
137
+ | **Signing** | Opt-in HMAC-SHA256, Stripe-style `${ts}.${rawBody}` payload, secrets via `{{ env.X }}` or `file:/path` (inline rejected at config-load) |
138
+ | **Reliability** | Per-webhook circuit breaker, drop-oldest queue cap, per-attempt `AbortSignal.timeout`, optional `expectResponse: { status, body }` body assertion |
139
+ | **Observability** | `/__admin/tenants/:t/webhooks` list (secrets redacted), `/webhooks/journal` history, `POST /webhooks/await?id=…` for sync test assertions, `POST /webhooks/:id/replay` for recovery |
140
+ | **Metrics** | `webhook_delivery_total{outcome}`, `webhook_delivery_latency_us`, `webhook_queue_depth`, `webhook_queue_dropped_total`, `webhook_circuit_state` |
141
+ | **Distribution** | In-process (no Redis); single-binary and SDET-embed friendly |
142
+
143
+ Full guide, decisions log, and security model: [docs/webhooks/README.md](./docs/webhooks/README.md), [docs/webhooks/DECISIONS.md](./docs/webhooks/DECISIONS.md), [docs/webhooks/SECURITY.md](./docs/webhooks/SECURITY.md). Worked example loadable via `bun run dev`: [examples/mocks/default/webhooks-example.json](./examples/mocks/default/webhooks-example.json).
144
+
145
+ ## What's in v1, what's deferred
146
+
147
+ See [CHANGELOG.md](./CHANGELOG.md). TL;DR: static + dynamic + pass-through + scenarios + outbound webhooks + OpenAPI import + admin read endpoints + multi-tenancy ship in v1. Stateful mocks, GraphQL, gRPC, fault injection, and a config-mutation admin API are explicitly deferred to v1.1.
148
+
149
+ ## HTTPS transparent upstream (`mockstar proxy`)
150
+
151
+ Point real HTTPS traffic at your local mocks with zero application code changes — `https://api.razorpay.com` resolves to `127.0.0.1`, terminates on a mkcert-trusted leaf, and forwards to mockstar-on-3000. macOS + Linux only in v1.
152
+
153
+ ```bash
154
+ mockstar proxy install # one-time: installs CA, DNS, port-bind grant
155
+ mockstar proxy start # runs the HTTPS listener on :443
156
+ ```
157
+
158
+ See [docs/PROXY.md](./docs/PROXY.md) for the full guide and [docs/PROXY-RECOVERY.md](./docs/PROXY-RECOVERY.md) for incident recovery.
159
+
160
+ ## Running with Docker
161
+
162
+ The image is published multi-arch (`linux/amd64` + `linux/arm64`), public, and signed:
163
+
164
+ ```bash
165
+ docker pull ghcr.io/dhanesh/mockstar:latest # or a pinned tag, e.g. :v0.1.0-alpha.1
166
+ ```
167
+
168
+ The image is **lean — it ships no mocks**. You mount your mock content at run time. The
169
+ default command serves `/config/mocks`; named JS handlers (if any) are read from
170
+ `/config/handlers`. It listens on port `3000` and runs as a non-root user (uid `10001`).
171
+
172
+ ### Run with your mocks mounted
173
+
174
+ Point a host folder at `/config/mocks` (and `/config/handlers` if you use named handlers):
175
+
176
+ ```bash
177
+ docker run --rm -p 3000:3000 \
178
+ -v "$PWD/mocks:/config/mocks:ro" \
179
+ -v "$PWD/handlers:/config/handlers:ro" \
180
+ ghcr.io/dhanesh/mockstar:latest
181
+
182
+ # in another shell:
183
+ curl localhost:3000/health # {"status":"ok"}
184
+ curl localhost:3000/users/123 # your mocked response
185
+ ```
186
+
187
+ Hardened run (read-only root filesystem + writable temp), matching the Helm chart's
188
+ security posture:
189
+
190
+ ```bash
191
+ docker run --rm -p 3000:3000 \
192
+ --read-only --tmpfs /tmp \
193
+ -v "$PWD/mocks:/config/mocks:ro" \
194
+ ghcr.io/dhanesh/mockstar:latest
195
+ ```
196
+
197
+ ### Adding more mocks
198
+
199
+ The mounted folder follows the [Config layout](#config-layout) — **one sub-directory per
200
+ tenant**, one JSON file per resource:
201
+
202
+ ```
203
+ mocks/
204
+ default/ # the default tenant
205
+ users.json
206
+ orders.json
207
+ billing.json # ← drop in new files to add more routes
208
+ acme/ # add a directory to add a tenant
209
+ users.json
210
+ handlers/ # optional named JS/TS handlers referenced by dynamic mocks
211
+ computeTotal.ts
212
+ ```
213
+
214
+ Add a file (or tenant directory) under your mounted `mocks/` folder and it's served — no
215
+ image rebuild. Mock JSON changes are hot-reloaded on the mounted volume; **named handler
216
+ changes require a container restart** (handlers are loaded at boot).
217
+
218
+ ### Bake mocks into an image (shared deployments)
219
+
220
+ For a self-contained, versioned fixture set your team/CI can pull and run with **no mount**,
221
+ build a thin image on top of the published base:
222
+
223
+ ```dockerfile
224
+ # Dockerfile
225
+ FROM ghcr.io/dhanesh/mockstar:latest
226
+ # Copy your fixtures in (owned by the non-root runtime user)
227
+ COPY --chown=10001:10001 mocks/ /config/mocks/
228
+ COPY --chown=10001:10001 handlers/ /config/handlers/ # omit if you have no handlers
229
+ # Base image already sets ENTRYPOINT + CMD (serve /config/mocks on :3000)
230
+ ```
231
+
232
+ ```bash
233
+ docker build -t ghcr.io/your-org/team-fixtures:1.0 .
234
+ docker run --rm -p 3000:3000 ghcr.io/your-org/team-fixtures:1.0 # mocks are baked in
235
+ ```
236
+
237
+ Pin the base by digest (`FROM ghcr.io/dhanesh/mockstar@sha256:…`) for reproducible builds,
238
+ push the result to your own registry, and every consumer gets the identical mock set.
239
+
240
+ ## Kubernetes / Helm
241
+
242
+ Deploy the mock + webhook server with the chart in [`charts/mockstar`](./charts/mockstar) — secure-by-default (read-only root FS, non-root uid 10001, dropped caps, admin token via Secret).
243
+
244
+ ```bash
245
+ helm install mockstar oci://ghcr.io/dhanesh/charts/mockstar \
246
+ --version 0.1.0 --namespace mockstar --create-namespace
247
+ ```
248
+
249
+ - **Single replica by design** (`replicaCount: 1`, `Recreate`): the journal, scenario state, and webhook queue are in-memory and per-pod — scaling beyond 1 splits that state.
250
+ - The TLS-intercepting `mockstar proxy` is a local-only experimental dev tool and is **not** deployed by the chart.
251
+
252
+ Full guide — tenant ConfigMaps, handlers, admin token Secret, NetworkPolicy egress, probes/metrics, image-by-digest: [docs/deployment/helm.md](./docs/deployment/helm.md).
253
+
254
+ ## Security
255
+
256
+ See [docs/SECURITY.md](./docs/SECURITY.md) for the threat model, [SECURITY.md](./SECURITY.md) for the security policy and posture. Admin endpoints are disabled by default. Pass-through and OpenAPI import share a hardened URL validator that rejects private-range targets by default (addressing CVE-2026-39885-class OpenAPI `$ref` attacks).
257
+
258
+ ## License & governance
259
+
260
+ MIT — see [LICENSE](./LICENSE). Governance policy, irreversible-decision watch list, and the protocol for changing project-level commitments live in [docs/GOVERNANCE.md](./docs/GOVERNANCE.md).
@@ -0,0 +1,13 @@
1
+ export interface InitOptions {
2
+ readonly dir: string;
3
+ readonly minorTag: string;
4
+ readonly force: boolean;
5
+ }
6
+ export interface InitResult {
7
+ readonly created: readonly string[];
8
+ readonly skipped: readonly string[];
9
+ }
10
+ export declare function runInit(options: InitOptions): Promise<InitResult>;
11
+ /** Derive the minor tag from a semver string (e.g. "0.1.0-rc.1" -> "v0.1"). */
12
+ export declare function minorTagFromVersion(version: string): string;
13
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AA8CD,wBAAsB,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CA0BvE;AAED,+EAA+E;AAC/E,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAK3D"}
@@ -0,0 +1,13 @@
1
+ export interface MigrateOptions {
2
+ readonly dir: string;
3
+ readonly from: string;
4
+ readonly to: string;
5
+ readonly dryRun: boolean;
6
+ }
7
+ export interface MigrateResult {
8
+ readonly filesScanned: number;
9
+ readonly filesChanged: number;
10
+ readonly mismatched: readonly string[];
11
+ }
12
+ export declare function runMigrateSchema(options: MigrateOptions): Promise<MigrateResult>;
13
+ //# sourceMappingURL=migrate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/migrate.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;CACxC;AAmBD,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CA0CtF"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bun
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}