@dhaneshpurohit/mockstar 0.6.0 → 0.6.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 CHANGED
@@ -1,3 +1,10 @@
1
+ ## [0.6.1](https://github.com/dhanesh/mockstar/compare/v0.6.0...v0.6.1) (2026-11-24)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **webhooks:** allow quoted token arguments in object webhook bodies ([2079894](https://github.com/dhanesh/mockstar/commit/207989483d4f7389bd45a75bd18df648769d0305)), closes [#56](https://github.com/dhanesh/mockstar/issues/56)
7
+
1
8
  # [0.6.0](https://github.com/dhanesh/mockstar/compare/v0.5.0...v0.6.0) (2026-11-23)
2
9
 
3
10
 
package/README.md CHANGED
@@ -63,6 +63,23 @@ bun run src/cli.ts ./examples/mocks
63
63
 
64
64
  A persona-specific deployment walkthrough lives in [docs/DEPLOYMENT.md](./docs/DEPLOYMENT.md).
65
65
 
66
+ ### CLI reference
67
+
68
+ ```bash
69
+ mockstar serve ./mocks [--port 3000] [--host 127.0.0.1] [--handlers ./handlers] \
70
+ [--deterministic] [--no-watch] [--allow-webhook-url-header] [--webhook-journal-file <path>]
71
+ mockstar init [dir] | import <openapi> <out-dir> | enhance <tenant-dir> | migrate --schema <dir> --from vX.Y --to vX.Z
72
+ mockstar help # full list, including env vars
73
+ ```
74
+
75
+ | Env (CLI only) | Effect |
76
+ |---|---|
77
+ | `MOCKSTAR_DETERMINISTIC=1` | Same as `--deterministic` |
78
+ | `MOCKSTAR_ADMIN_TOKEN` | Enables the admin API; this root token opens `/metrics`. Tenant admin routes need the tenant's `adminToken` |
79
+ | `MOCKSTAR_PORT`, `MOCKSTAR_HOST` | Listen address |
80
+
81
+ Use `mockstar help` (not `mockstar serve --help`) to print the options.
82
+
66
83
  ## Config layout
67
84
 
68
85
  ```
@@ -96,7 +113,7 @@ Any string value inside `response.body` or `response.headers` can contain `{{
96
113
  | Token | Value |
97
114
  |---|---|
98
115
  | `{{tenant}}` | Tenant identifier the request was routed to |
99
- | `{{requestId}}` | Per-request UUID assigned by mockstar |
116
+ | `{{requestId}}` | Request id assigned by mockstar: a UUID, or `req-00000001`, `req-00000002`, … (one counter per server) in deterministic mode |
100
117
 
101
118
  ### Random data (faker)
102
119
 
@@ -126,7 +143,7 @@ Any string value inside `response.body` or `response.headers` can contain `{{
126
143
  | `{{now.millis}}` | Current time as Unix milliseconds (number) |
127
144
  | `{{now.iso}}` | Current time as ISO 8601 string |
128
145
 
129
- In `--deterministic` mode (`MOCKSTAR_DETERMINISTIC=1`) all faker and `now.*` tokens return fixed seed-derived values so CI replays are byte-identical.
146
+ In `--deterministic` mode (`MOCKSTAR_DETERMINISTIC=1` for the CLI, `launch({ deterministic: true })` for the library), `now.*` returns a fixed time (`2026-01-01T00:00:00Z`) and faker and `id()` values are seeded per tenant, mock and hit number, so CI replays are byte-identical. See [docs/SDET.md](./docs/SDET.md#what-deterministic-guarantees) for exactly what is and is not guaranteed.
130
147
 
131
148
  Full reference including type-preservation rules and worked examples: [docs/TIER2.md](./docs/TIER2.md).
132
149
 
@@ -154,7 +171,7 @@ Capabilities at a glance:
154
171
  | | |
155
172
  |---|---|
156
173
  | **Configuration channels** | Per-route `url`, `{{ env.NAME }}` interpolation, admin API, opt-in `X-Mockstar-Webhook-Url` request header (gated by `--allow-webhook-url-header`) |
157
- | **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 |
174
+ | **Delivery contract** | At-least-once within queue + circuit bounds, exponential backoff with jitter (default `[1s, 2s, 4s, 8s, 16s]`), `X-Mockstar-Delivery-Id` header (currently the triggering request id: stable across retries, but shared by every webhook that one request fires, so do not deduplicate on it alone) |
158
175
  | **Signing** | Opt-in HMAC-SHA256 with a **configurable wire format** — `signedPayload` (bytes signed) and `signatureTemplate` (header value) are independent, plus `digestEncoding: hex \| base64`. Ships verified shapes for GitHub, Slack, Stripe, Shopify and Razorpay. Secrets via `{{ env.X }}` or `file:/path` (inline rejected at config-load) |
159
176
  | **Request caps** | Per-tenant `maxBodyBytes` (413, enforced on the byte stream so chunked encoding can't bypass it) and `requestsPerSecond` (429 + `Retry-After`, token bucket so bursts aren't punished; default 10,000/s) |
160
177
  | **Reliability** | Per-webhook circuit breaker, drop-oldest queue cap, per-attempt `AbortSignal.timeout`, optional `expectResponse: { status, body }` body assertion |
package/dist/cli.js CHANGED
@@ -3203,8 +3203,7 @@ function compileOne(spec) {
3203
3203
  const urlTemplate = compileTemplate(spec.url);
3204
3204
  let body = null;
3205
3205
  if (spec.body !== undefined && spec.body !== null) {
3206
- const bodyString = typeof spec.body === "string" ? spec.body : JSON.stringify(spec.body);
3207
- body = compileTemplate(bodyString);
3206
+ body = typeof spec.body === "string" ? compileTemplate(spec.body) : compileJsonBody(spec.body);
3208
3207
  }
3209
3208
  const headers = new Map;
3210
3209
  for (const [key, value] of Object.entries(spec.headers ?? {})) {
@@ -3244,6 +3243,39 @@ function compileOne(spec) {
3244
3243
  acceptHeaderOverride: spec.acceptHeaderOverride
3245
3244
  };
3246
3245
  }
3246
+ function compileNode(value) {
3247
+ if (typeof value === "string")
3248
+ return { kind: "string", template: compileTemplate(value) };
3249
+ if (Array.isArray(value))
3250
+ return { kind: "array", items: value.map(compileNode) };
3251
+ if (value !== null && typeof value === "object") {
3252
+ return {
3253
+ kind: "object",
3254
+ entries: Object.entries(value).map(([k2, v2]) => [compileTemplate(k2), compileNode(v2)])
3255
+ };
3256
+ }
3257
+ return { kind: "literal", value };
3258
+ }
3259
+ function renderNode(node, ctx) {
3260
+ switch (node.kind) {
3261
+ case "string":
3262
+ return node.template.render(ctx);
3263
+ case "literal":
3264
+ return node.value;
3265
+ case "array":
3266
+ return node.items.map((n2) => renderNode(n2, ctx));
3267
+ case "object": {
3268
+ const out = {};
3269
+ for (const [key, child] of node.entries)
3270
+ out[key.render(ctx)] = renderNode(child, ctx);
3271
+ return out;
3272
+ }
3273
+ }
3274
+ }
3275
+ function compileJsonBody(value) {
3276
+ const root = compileNode(value);
3277
+ return { render: (ctx) => JSON.stringify(renderNode(root, ctx)) };
3278
+ }
3247
3279
 
3248
3280
  // src/core/handlers/registry.ts
3249
3281
  import { readdir, stat } from "fs/promises";
@@ -15425,7 +15457,7 @@ function proxyHelp() {
15425
15457
  }
15426
15458
 
15427
15459
  // src/version.ts
15428
- var MOCKSTAR_VERSION = "0.6.0";
15460
+ var MOCKSTAR_VERSION = "0.6.1";
15429
15461
 
15430
15462
  // src/cli.ts
15431
15463
  function parseArgs(argv) {
@@ -6,11 +6,13 @@ import type { CompiledWebhookSpec } from "./types.ts";
6
6
  *
7
7
  * Body templating handles two shapes:
8
8
  * - string body: compiled directly (whole-string rendering)
9
- * - object/array body: serialised once at compile time with placeholder tokens
10
- * intact, then compileTemplate'd as a string. This is sufficient for v0.x;
11
- * it loses type-preservation for JSON bodies (numbers in templates render
12
- * as strings) but matches T7's stated reuse of the existing engine.
13
- * Type-preserving JSON bodies (renderCompiledJson) can be added later.
9
+ * - object/array body: every string leaf (and object key) is compiled on its own and
10
+ * the result is serialised with JSON.stringify at render time (#56). Compiling the
11
+ * stringified body as one template escaped the quotes inside tokens such as
12
+ * `{{id("evt_", 14)}}` and broke them. Leaves render in key order, so faker/id draws
13
+ * happen in the same order as before. Rendered values are still strings (numbers in
14
+ * templates render as "3"), and are now JSON-escaped. Type-preserving JSON bodies
15
+ * (renderCompiledJson) remain a possible future change.
14
16
  */
15
17
  export declare function compileWebhookSpecs(entries: readonly Entry[]): Map<string, readonly CompiledWebhookSpec[]>;
16
18
  //# sourceMappingURL=compile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/features/webhooks/compile.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAgB,MAAM,6BAA6B,CAAC;AAEvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,SAAS,mBAAmB,EAAE,CAAC,CAQ1G"}
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/features/webhooks/compile.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAgB,MAAM,6BAA6B,CAAC;AAEvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,SAAS,mBAAmB,EAAE,CAAC,CAQ1G"}
package/dist/index.js CHANGED
@@ -2739,8 +2739,7 @@ function compileOne(spec) {
2739
2739
  const urlTemplate = compileTemplate(spec.url);
2740
2740
  let body = null;
2741
2741
  if (spec.body !== undefined && spec.body !== null) {
2742
- const bodyString = typeof spec.body === "string" ? spec.body : JSON.stringify(spec.body);
2743
- body = compileTemplate(bodyString);
2742
+ body = typeof spec.body === "string" ? compileTemplate(spec.body) : compileJsonBody(spec.body);
2744
2743
  }
2745
2744
  const headers = new Map;
2746
2745
  for (const [key, value] of Object.entries(spec.headers ?? {})) {
@@ -2780,6 +2779,39 @@ function compileOne(spec) {
2780
2779
  acceptHeaderOverride: spec.acceptHeaderOverride
2781
2780
  };
2782
2781
  }
2782
+ function compileNode(value) {
2783
+ if (typeof value === "string")
2784
+ return { kind: "string", template: compileTemplate(value) };
2785
+ if (Array.isArray(value))
2786
+ return { kind: "array", items: value.map(compileNode) };
2787
+ if (value !== null && typeof value === "object") {
2788
+ return {
2789
+ kind: "object",
2790
+ entries: Object.entries(value).map(([k2, v2]) => [compileTemplate(k2), compileNode(v2)])
2791
+ };
2792
+ }
2793
+ return { kind: "literal", value };
2794
+ }
2795
+ function renderNode(node, ctx) {
2796
+ switch (node.kind) {
2797
+ case "string":
2798
+ return node.template.render(ctx);
2799
+ case "literal":
2800
+ return node.value;
2801
+ case "array":
2802
+ return node.items.map((n2) => renderNode(n2, ctx));
2803
+ case "object": {
2804
+ const out = {};
2805
+ for (const [key, child] of node.entries)
2806
+ out[key.render(ctx)] = renderNode(child, ctx);
2807
+ return out;
2808
+ }
2809
+ }
2810
+ }
2811
+ function compileJsonBody(value) {
2812
+ const root = compileNode(value);
2813
+ return { render: (ctx) => JSON.stringify(renderNode(root, ctx)) };
2814
+ }
2783
2815
 
2784
2816
  // src/core/handlers/registry.ts
2785
2817
  import { readdir, stat } from "fs/promises";
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const MOCKSTAR_VERSION = "0.6.0";
1
+ export declare const MOCKSTAR_VERSION = "0.6.1";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhaneshpurohit/mockstar",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "Bun-based mock server with static + dynamic mocking, JSON config, named JS handlers, pass-through, multi-tenancy, and test-data utilities.",
5
5
  "license": "MIT",
6
6
  "repository": {