@crvouga/mockingbird-service-clerk 0.1.0 → 0.3.0

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,5 +1,23 @@
1
1
  # Changelog — @crvouga/mockingbird-service-clerk
2
2
 
3
- ## 0.1.0 (2026-10-11)
3
+ ## 0.3.0 (2026-10-15)
4
+
5
+ ### Features
6
+
7
+ - finish durable run lifecycle ([725ea1a](https://github.com/crvouga/mockingbird/commit/725ea1a966dac65434e98f06a9c33aca0d6f32d7))
8
+ - add management and portable archives ([0d2a6dd](https://github.com/crvouga/mockingbird/commit/0d2a6dd0f9fecb3a1ea7c1638f6639787395c2f4))
9
+
10
+ ### Fixes and improvements
11
+
12
+ - correlate cross-namespace operations ([3457a4b](https://github.com/crvouga/mockingbird/commit/3457a4b7dbfd9ad9c8a10671a5744b7c8425d000))
13
+ - harden HTTP stream handling ([674307a](https://github.com/crvouga/mockingbird/commit/674307a869f57907567d462c4f506c3b0a237e13))
14
+
15
+ ## 0.2.0 (2026-10-12)
16
+
17
+ ### Features
18
+
19
+ - unify the emulator control plane ([2068547](https://github.com/crvouga/mockingbird/commit/2068547bedde4e2e2331c1657c1a78120e84428b))
20
+
21
+ ## 0.1.0 (2026-10-08)
4
22
 
5
23
  Initial release.
package/DISCOVERY.md CHANGED
@@ -34,6 +34,7 @@ repository; live parity is an additional oracle check, not a substitute for the
34
34
 
35
35
  - `GET /__admin/health`
36
36
  - `GET /__admin`
37
+ - `GET /__admin/controls`
37
38
  - `GET /__admin/state`
38
39
  - `GET /__admin/requests`
39
40
  - `GET /__admin/metrics`
@@ -44,6 +45,28 @@ For HTTP services, use `x-mockingbird-namespace` (or the documented credential/p
44
45
  parallel tests do not share state. Admin state, journal, metrics and fault-preset endpoints are
45
46
  designed for assertions and diagnosis by consuming test suites.
46
47
 
48
+ ## Admin controls
49
+
50
+ Every HTTP emulator takes the same controls, and each means the same thing at boot
51
+ (`createRuntime({ adminControls })`, `serve --admin-controls`), over `/__admin`, and in a request header:
52
+
53
+ | Control | Admin API | Request header | Interface |
54
+ | --- | --- | --- | --- |
55
+ | Isolate state by key | `GET /__admin/namespaces` | `x-mockingbird-namespace: <key>` | [Namespaces](https://mockingbird.chrisvouga.dev/docs/admin-controls/namespaces) |
56
+ | Reset to boot | `POST /__admin/reset` | `x-mockingbird-reset: true` | [Reset](https://mockingbird.chrisvouga.dev/docs/admin-controls/reset) |
57
+ | Snapshot and restore | `POST /__admin/snapshots`, `POST /__admin/snapshots/<id>/restore` | `x-mockingbird-snapshot: <name>`, `x-mockingbird-restore: <name>` | [Snapshot and restore](https://mockingbird.chrisvouga.dev/docs/admin-controls/snapshot-and-restore) |
58
+ | Move the clock | `POST /__admin/clock` | `x-mockingbird-time: <instant>`, `x-mockingbird-advance: <duration>` | [Clock](https://mockingbird.chrisvouga.dev/docs/admin-controls/clock) |
59
+ | Read or branch from old state | `GET /__admin/timeline` | `x-mockingbird-at: <checkpoint>`, `x-mockingbird-branch: <name>` | [Checkpoints and branches](https://mockingbird.chrisvouga.dev/docs/admin-controls/checkpoints-and-branches) |
60
+ | Inject a fault | `POST /__admin/faults` | `x-mockingbird-fault: <fault>` | [Faults](https://mockingbird.chrisvouga.dev/docs/admin-controls/faults) |
61
+ | Latency and timeouts | `PUT /__admin/latency` | `x-mockingbird-delay: <duration>`, `x-mockingbird-timeout: <duration>` | [Latency and timeouts](https://mockingbird.chrisvouga.dev/docs/admin-controls/latency-and-timeouts) |
62
+ | Replay from a seed | `PUT /__admin/controls` | `x-mockingbird-seed: <seed>` | [Seed and determinism](https://mockingbird.chrisvouga.dev/docs/admin-controls/seed-and-determinism) |
63
+ | See what happened | `GET /__admin/requests`, `GET /__admin/state` | | [Journal, metrics and state](https://mockingbird.chrisvouga.dev/docs/admin-controls/journal-and-state) |
64
+
65
+ `GET /__admin` lists every route and header with a one-line summary, and `GET /__admin/controls`
66
+ is the namespace's current control document. The same seed and the same requests give the same
67
+ bytes. Setting controls as an emulator starts is [Boot](https://mockingbird.chrisvouga.dev/docs/admin-controls/boot); every route and header is in
68
+ the [Reference](https://mockingbird.chrisvouga.dev/docs/admin-controls/reference). The full guide: <https://mockingbird.chrisvouga.dev/docs/admin-controls>.
69
+
47
70
  ## Report a mismatch or missing capability
48
71
 
49
72
  Follow the [agent reporting contract](https://github.com/crvouga/mockingbird/blob/main/docs/REPORTING_ISSUES.md). Include package version,
package/README.md CHANGED
@@ -13,11 +13,29 @@ npm install @crvouga/mockingbird-service-clerk
13
13
  ## Usage
14
14
 
15
15
  ```ts
16
- import { createRuntime } from "@crvouga/mockingbird-service-clerk"
17
- const runtime = createRuntime({ seed: 1 })
18
- const response = await runtime.fetch(new Request("https://api.clerk.com"))
16
+ import { createServer } from "@crvouga/mockingbird-service-clerk/server"
17
+
18
+ const server = await createServer({ seed: 1 })
19
+
20
+ // The app's Backend API calls, with the emulator's URL in place of https://api.clerk.com.
21
+ const headers = { authorization: "Bearer sk_test_fixture", "content-type": "application/json" }
22
+ const created = await fetch(`${server.url}/v1/users`, {
23
+ method: "POST",
24
+ headers,
25
+ body: JSON.stringify({ email_address: ["ada@example.com"], first_name: "Ada" }),
26
+ })
27
+ const user = (await created.json()) as { id: string; first_name: string }
28
+ const listed = await fetch(`${server.url}/v1/users?email_address=ada@example.com`, { headers })
29
+ const { data } = (await listed.json()) as { data: { id: string }[] }
30
+ console.log(data[0]?.id === user.id) // true
31
+ await server.close()
19
32
  ```
20
33
 
34
+ The example uses plain `fetch` because `@clerk/backend` only parses a response whose
35
+ `content-type` is exactly `application/json`, and the emulator answers
36
+ `application/json; charset=UTF-8`. With `createClerkClient({ secretKey, apiUrl: server.url })` the
37
+ requests succeed but resources come back as unparsed JSON strings.
38
+
21
39
  ## API
22
40
 
23
41
  - `ClerkAPI`: portable provider instance; accepts SQLite, namespace, clock, fixtures and baseUrl.
@@ -42,11 +42,38 @@ function createHmac(algorithm, key) {
42
42
  };
43
43
  return hash;
44
44
  }
45
+ var source;
46
+ function useRandom(next) {
47
+ source = next;
48
+ }
49
+ function withRandom(next, run) {
50
+ const previous = source;
51
+ source = next;
52
+ try {
53
+ return run();
54
+ } finally {
55
+ source = previous;
56
+ }
57
+ }
58
+ function random() {
59
+ return source ? source() : Math.random();
60
+ }
45
61
  function randomBytes(length) {
46
- return Buffer.from(crypto.getRandomValues(new Uint8Array(length)));
62
+ if (!source)
63
+ return Buffer.from(crypto.getRandomValues(new Uint8Array(length)));
64
+ const out = new Uint8Array(length);
65
+ for (let i = 0; i < length; i++)
66
+ out[i] = Math.floor(source() * 256);
67
+ return Buffer.from(out);
47
68
  }
48
69
  function randomUUID() {
49
- return crypto.randomUUID();
70
+ if (!source)
71
+ return crypto.randomUUID();
72
+ const b = randomBytes(16);
73
+ b[6] = b[6] & 15 | 64;
74
+ b[8] = b[8] & 63 | 128;
75
+ const hex = b.toString("hex");
76
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
50
77
  }
51
78
  function timingSafeEqual(a, b) {
52
79
  if (a.length !== b.length)
@@ -60,8 +87,11 @@ function timingSafeEqual(a, b) {
60
87
  export {
61
88
  createHash,
62
89
  createHmac,
90
+ useRandom,
91
+ withRandom,
92
+ random,
63
93
  randomBytes,
64
94
  randomUUID,
65
95
  timingSafeEqual
66
96
  };
67
- //# sourceMappingURL=chunk-M73LWCCP.js.map
97
+ //# sourceMappingURL=chunk-6Z2MR3PO.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../http/provider/src/vendor/core/crypto.ts"],
4
- "sourcesContent": ["import { hmac } from \"@noble/hashes/hmac.js\"\nimport { sha1 } from \"@noble/hashes/legacy.js\"\nimport { md5 } from \"@noble/hashes/legacy.js\"\nimport { sha256 } from \"@noble/hashes/sha2.js\"\nimport { Buffer } from \"buffer\"\n\nconst digest = (algorithm: string) => {\n if (algorithm === \"sha256\") return sha256\n if (algorithm === \"sha1\") return sha1\n if (algorithm === \"md5\") return md5\n throw new Error(`Unsupported digest ${algorithm}`)\n}\nconst bytes = (input: string | Uint8Array) => typeof input === \"string\" ? new TextEncoder().encode(input) : input\ninterface Hash {\n update(input: string | Uint8Array): Hash\n digest(): Buffer\n digest(encoding: string): string\n}\nexport function createHash(algorithm: string): Hash {\n const parts: Uint8Array[] = []\n const hash = {\n update(input: string | Uint8Array) { parts.push(bytes(input)); return hash },\n digest(encoding?: string): Buffer | string {\n const result = Buffer.from(digest(algorithm)(Buffer.concat(parts)))\n return encoding === \"base64url\" ? result.toString(\"base64\").replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\") : encoding ? result.toString(encoding as BufferEncoding) : result\n },\n }\n return hash as Hash\n}\nexport function createHmac(algorithm: string, key: string | Uint8Array): Hash {\n const parts: Uint8Array[] = []\n const hash = {\n update(input: string | Uint8Array) { parts.push(bytes(input)); return hash },\n digest(encoding?: string): Buffer | string {\n const result = Buffer.from(hmac(digest(algorithm), bytes(key), Buffer.concat(parts)))\n return encoding === \"base64url\" ? result.toString(\"base64\").replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\") : encoding ? result.toString(encoding as BufferEncoding) : result\n },\n }\n return hash as Hash\n}\nexport function randomBytes(length: number): Buffer {\n return Buffer.from(crypto.getRandomValues(new Uint8Array(length)))\n}\nexport function randomUUID(): string { return crypto.randomUUID() }\nexport function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) throw new Error(\"Buffers must have equal lengths\")\n let difference = 0\n for (let i = 0; i < a.length; i++) difference |= a[i] ^ b[i]\n return difference === 0\n}\n"],
5
- "mappings": ";AAAA,SAAS,YAAY;AACrB,SAAS,YAAY;AACrB,SAAS,WAAW;AACpB,SAAS,cAAc;AACvB,SAAS,cAAc;AAEvB,IAAM,SAAS,CAAC,cAAqB;AACnC,MAAI,cAAc;AAAU,WAAO;AACnC,MAAI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,GAAa;AAC1D,MAAI,EAAE,WAAW,EAAE;AAAQ,UAAM,IAAI,MAAM,iCAAiC;AAC5E,MAAI,aAAa;AACjB,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ;AAAK,kBAAc,EAAE,CAAC,IAAI,EAAE,CAAC;AAC3D,SAAO,eAAe;AACxB;",
4
+ "sourcesContent": ["import { hmac } from \"@noble/hashes/hmac.js\"\nimport { sha1 } from \"@noble/hashes/legacy.js\"\nimport { md5 } from \"@noble/hashes/legacy.js\"\nimport { sha256 } from \"@noble/hashes/sha2.js\"\nimport { Buffer } from \"buffer\"\n\nconst digest = (algorithm: string) => {\n if (algorithm === \"sha256\") return sha256\n if (algorithm === \"sha1\") return sha1\n if (algorithm === \"md5\") return md5\n throw new Error(`Unsupported digest ${algorithm}`)\n}\nconst bytes = (input: string | Uint8Array) => typeof input === \"string\" ? new TextEncoder().encode(input) : input\ninterface Hash {\n update(input: string | Uint8Array): Hash\n digest(): Buffer\n digest(encoding: string): string\n}\nexport function createHash(algorithm: string): Hash {\n const parts: Uint8Array[] = []\n const hash = {\n update(input: string | Uint8Array) { parts.push(bytes(input)); return hash },\n digest(encoding?: string): Buffer | string {\n const result = Buffer.from(digest(algorithm)(Buffer.concat(parts)))\n return encoding === \"base64url\" ? result.toString(\"base64\").replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\") : encoding ? result.toString(encoding as BufferEncoding) : result\n },\n }\n return hash as Hash\n}\nexport function createHmac(algorithm: string, key: string | Uint8Array): Hash {\n const parts: Uint8Array[] = []\n const hash = {\n update(input: string | Uint8Array) { parts.push(bytes(input)); return hash },\n digest(encoding?: string): Buffer | string {\n const result = Buffer.from(hmac(digest(algorithm), bytes(key), Buffer.concat(parts)))\n return encoding === \"base64url\" ? result.toString(\"base64\").replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\") : encoding ? result.toString(encoding as BufferEncoding) : result\n },\n }\n return hash as Hash\n}\n/**\n * Mockingbird: where ids and tokens come from. With a seeded stream in place, everything the\n * vendor code mints replays from the seed; without one it is the platform's own randomness.\n */\nlet source: (() => number) | undefined\n/** Mint from `next` (a seeded stream of `[0, 1)`) until told otherwise. */\nexport function useRandom(next: (() => number) | undefined): void { source = next }\n/** Mint from `next` for one synchronous section, then put the previous source back. */\nexport function withRandom<T>(next: (() => number) | undefined, run: () => T): T {\n const previous = source\n source = next\n try { return run() } finally { source = previous }\n}\n/** `Math.random`, from the seeded stream when one is in place. */\nexport function random(): number { return source ? source() : Math.random() }\nexport function randomBytes(length: number): Buffer {\n if (!source) return Buffer.from(crypto.getRandomValues(new Uint8Array(length)))\n const out = new Uint8Array(length)\n for (let i = 0; i < length; i++) out[i] = Math.floor(source() * 256)\n return Buffer.from(out)\n}\nexport function randomUUID(): string {\n if (!source) return crypto.randomUUID()\n const b = randomBytes(16)\n b[6] = (b[6] & 0x0f) | 0x40\n b[8] = (b[8] & 0x3f) | 0x80\n const hex = b.toString(\"hex\")\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`\n}\nexport function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) throw new Error(\"Buffers must have equal lengths\")\n let difference = 0\n for (let i = 0; i < a.length; i++) difference |= a[i] ^ b[i]\n return difference === 0\n}\n"],
5
+ "mappings": ";AAAA,SAAS,YAAY;AACrB,SAAS,YAAY;AACrB,SAAS,WAAW;AACpB,SAAS,cAAc;AACvB,SAAS,cAAc;AAEvB,IAAM,SAAS,CAAC,cAAqB;AACnC,MAAI,cAAc;AAAU,WAAO;AACnC,MAAI,cAAc;AAAQ,WAAO;AACjC,MAAI,cAAc;AAAO,WAAO;AAChC,QAAM,IAAI,MAAM,sBAAsB,SAAS,EAAE;AACnD;AACA,IAAM,QAAQ,CAAC,UAA+B,OAAO,UAAU,WAAW,IAAI,YAAW,EAAG,OAAO,KAAK,IAAI;AAMtG,SAAU,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AAM,IAAI,WAAW,MAAM;AACjC,WAAS,IAAI,GAAG,IAAI,QAAQ;AAAK,QAAI,CAAC,IAAI,KAAK,MAAM,OAAM,IAAK,GAAG;AACnE,SAAO,OAAO,KAAK,GAAG;AACxB;AACM,SAAU,aAAU;AACxB,MAAI,CAAC;AAAQ,WAAO,OAAO,WAAU;AACrC,QAAM,IAAI,YAAY,EAAE;AACxB,IAAE,CAAC,IAAK,EAAE,CAAC,IAAI,KAAQ;AACvB,IAAE,CAAC,IAAK,EAAE,CAAC,IAAI,KAAQ;AACvB,QAAM,MAAM,EAAE,SAAS,KAAK;AAC5B,SAAO,GAAG,IAAI,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,MAAM,GAAG,EAAE,CAAC,IAAI,IAAI,MAAM,IAAI,EAAE,CAAC,IAAI,IAAI,MAAM,IAAI,EAAE,CAAC,IAAI,IAAI,MAAM,EAAE,CAAC;AAC1G;AACM,SAAU,gBAAgB,GAAe,GAAa;AAC1D,MAAI,EAAE,WAAW,EAAE;AAAQ,UAAM,IAAI,MAAM,iCAAiC;AAC5E,MAAI,aAAa;AACjB,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ;AAAK,kBAAc,EAAE,CAAC,IAAI,EAAE,CAAC;AAC3D,SAAO,eAAe;AACxB;",
6
6
  "names": []
7
7
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  randomUUID
3
- } from "./chunk-M73LWCCP.js";
3
+ } from "./chunk-6Z2MR3PO.js";
4
4
 
5
5
  // ../../http/provider/dist/vendor/clerk/helpers.js
6
6
  function generateClerkId(prefix) {
@@ -84,4 +84,4 @@ export {
84
84
  userDisplayName
85
85
  };
86
86
  /*! Adapted from vercel-labs/emulate (Apache-2.0), modified for Mockingbird. See port.json, LICENSE_EMULATE and THIRD_PARTY_NOTICES.md. */
87
- //# sourceMappingURL=chunk-YR65VVP4.js.map
87
+ //# sourceMappingURL=chunk-ASGMRJQK.js.map