@crvouga/mockingbird-service-twilio 3.2.0 → 3.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,15 +1,21 @@
1
1
  # Changelog — @crvouga/mockingbird-service-twilio
2
2
 
3
- ## 3.2.0 (2026-10-09)
3
+ ## 3.3.0 (2026-10-12)
4
4
 
5
5
  ### Features
6
6
 
7
- - match Emulate provider coverage ([16b65ce](https://github.com/crvouga/mockingbird/commit/16b65ce791fa216f28ec1521df636f57771d9c5e))
7
+ - unify the emulator control plane ([2068547](https://github.com/crvouga/mockingbird/commit/2068547bedde4e2e2331c1657c1a78120e84428b))
8
8
 
9
9
  ### Dependencies
10
10
 
11
11
  - `@crvouga/mockingbird-service-sqlite`
12
12
 
13
+ ## 3.2.0 (2026-10-08)
14
+
15
+ ### Features
16
+
17
+ - match Emulate provider coverage ([16b65ce](https://github.com/crvouga/mockingbird/commit/16b65ce791fa216f28ec1521df636f57771d9c5e))
18
+
13
19
  ## 3.1.0 (2026-10-08)
14
20
 
15
21
  ### Features
package/DISCOVERY.md CHANGED
@@ -35,6 +35,7 @@ repository; live parity is an additional oracle check, not a substitute for the
35
35
 
36
36
  - `GET /__admin/health`
37
37
  - `GET /__admin`
38
+ - `GET /__admin/controls`
38
39
  - `GET /__admin/state`
39
40
  - `GET /__admin/requests`
40
41
  - `GET /__admin/metrics`
@@ -45,6 +46,28 @@ For HTTP services, use `x-mockingbird-namespace` (or the documented credential/p
45
46
  parallel tests do not share state. Admin state, journal, metrics and fault-preset endpoints are
46
47
  designed for assertions and diagnosis by consuming test suites.
47
48
 
49
+ ## Admin controls
50
+
51
+ Every HTTP emulator takes the same controls, and each means the same thing at boot
52
+ (`createRuntime({ adminControls })`, `serve --admin-controls`), over `/__admin`, and in a request header:
53
+
54
+ | Control | Admin API | Request header | Interface |
55
+ | --- | --- | --- | --- |
56
+ | Isolate state by key | `GET /__admin/namespaces` | `x-mockingbird-namespace: <key>` | [Namespaces](https://mockingbird.chrisvouga.dev/docs/admin-controls/namespaces) |
57
+ | Reset to boot | `POST /__admin/reset` | `x-mockingbird-reset: true` | [Reset](https://mockingbird.chrisvouga.dev/docs/admin-controls/reset) |
58
+ | 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) |
59
+ | Move the clock | `POST /__admin/clock` | `x-mockingbird-time: <instant>`, `x-mockingbird-advance: <duration>` | [Clock](https://mockingbird.chrisvouga.dev/docs/admin-controls/clock) |
60
+ | 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) |
61
+ | Inject a fault | `POST /__admin/faults` | `x-mockingbird-fault: <fault>` | [Faults](https://mockingbird.chrisvouga.dev/docs/admin-controls/faults) |
62
+ | 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) |
63
+ | Replay from a seed | `PUT /__admin/controls` | `x-mockingbird-seed: <seed>` | [Seed and determinism](https://mockingbird.chrisvouga.dev/docs/admin-controls/seed-and-determinism) |
64
+ | See what happened | `GET /__admin/requests`, `GET /__admin/state` | | [Journal, metrics and state](https://mockingbird.chrisvouga.dev/docs/admin-controls/journal-and-state) |
65
+
66
+ `GET /__admin` lists every route and header with a one-line summary, and `GET /__admin/controls`
67
+ is the namespace's current control document. The same seed and the same requests give the same
68
+ bytes. Setting controls as an emulator starts is [Boot](https://mockingbird.chrisvouga.dev/docs/admin-controls/boot); every route and header is in
69
+ the [Reference](https://mockingbird.chrisvouga.dev/docs/admin-controls/reference). The full guide: <https://mockingbird.chrisvouga.dev/docs/admin-controls>.
70
+
48
71
  ## Report a mismatch or missing capability
49
72
 
50
73
  Follow the [agent reporting contract](https://github.com/crvouga/mockingbird/blob/main/docs/REPORTING_ISSUES.md). Include package version,
package/README.md CHANGED
@@ -40,30 +40,35 @@ twilio-node builds a host for each product (`api.twilio.com`, `verify.twilio.com
40
40
  `{emulator}/api/2010-04-01/…`, `{emulator}/verify/v2/…`, `{emulator}/lookups/v2/…`. Pass every
41
41
  `new Twilio(...)` an `httpClient` that rewrites the URL. `twilioMockUrl` does the rewrite:
42
42
 
43
- ```js
44
- import { RequestClient, Twilio } from "twilio"
43
+ ```ts
44
+ import twilio from "twilio"
45
45
  import { twilioMockUrl } from "@crvouga/mockingbird-service-twilio"
46
+ import { createServer } from "@crvouga/mockingbird-service-twilio/server"
47
+
48
+ const server = await createServer() // or process.env.TWILIO_API_BASE_URL, e.g. http://127.0.0.1:8798
49
+
50
+ type RequestOptions = Parameters<twilio.RequestClient["request"]>[0]
46
51
 
47
52
  /** https://verify.twilio.com/v2/Services/VA…/Verifications → {base}/verify/v2/Services/VA…/Verifications */
48
- class MockRequestClient extends RequestClient {
49
- constructor(baseUrl) {
50
- super()
51
- this.baseUrl = baseUrl
52
- }
53
- request(opts) {
54
- return super.request({ ...opts, uri: twilioMockUrl(opts.uri, this.baseUrl) })
53
+ class MockRequestClient extends twilio.RequestClient {
54
+ override request(opts: RequestOptions): Promise<never> {
55
+ const uri = twilioMockUrl(opts.uri, server.url)
56
+ return super.request({ ...opts, uri }) as Promise<never>
55
57
  }
56
58
  }
57
59
 
58
- const { TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN } = process.env
59
- const base = process.env.TWILIO_API_BASE_URL // e.g. http://127.0.0.1:8798
60
- const client = new Twilio(
61
- TWILIO_ACCOUNT_SID,
62
- TWILIO_AUTH_TOKEN,
63
- base ? { httpClient: new MockRequestClient(base) } : {},
64
- )
60
+ // The app's own Twilio client. Only its HTTP client changes.
61
+ const client = twilio("AC00000000000000000000000000000000", "fixture-token", {
62
+ httpClient: new MockRequestClient(),
63
+ })
64
+ const lookup = await client.lookups.v2.phoneNumbers("+12025550123").fetch()
65
+ // lookup.valid === true, lookup.nationalFormat === "(202) 555-0123"
66
+ await server.close()
65
67
  ```
66
68
 
69
+ The example type-checks with twilio 5.13.1 or later; 5.10.0 runs it the same way, but its
70
+ `exports` map hides the typings from `moduleResolution: nodenext`.
71
+
67
72
  The emulator also routes by the `Host` header. A request that reaches it as `lookups.twilio.com`
68
73
  (through a DNS override or a proxy) and has no prefix is served as `/lookups/…`. The recording
69
74
  adapter's raw `fetch` of `https://api.twilio.com/2010-04-01/…` becomes
@@ -73,13 +78,35 @@ adapter's raw `fetch` of `https://api.twilio.com/2010-04-01/…` becomes
73
78
  ### Reading the OTP in a test
74
79
 
75
80
  ```ts
76
- import { createRuntime } from "@crvouga/mockingbird-service-twilio"
77
-
78
- const twilio = createRuntime()
79
- // …the app calls verify.v2.services(VA).verifications.create({ to, channel: "sms" })…
80
- const latest = await twilio.fetch(new Request("http://twilio.test/__admin/verify/+12025550123/latest"))
81
- const { code, sid, status } = (await latest.json()) as { code: string; sid: string; status: string }
82
- // …the app calls verificationChecks.create({ verificationSid: sid, code }) → status "approved"
81
+ import twilio from "twilio"
82
+ import { twilioMockUrl } from "@crvouga/mockingbird-service-twilio"
83
+ import { createServer } from "@crvouga/mockingbird-service-twilio/server"
84
+
85
+ // Test setup: the emulator, and the app's Twilio client pointed at it as above.
86
+ const server = await createServer()
87
+ type RequestOptions = Parameters<twilio.RequestClient["request"]>[0]
88
+ class MockRequestClient extends twilio.RequestClient {
89
+ override request(opts: RequestOptions): Promise<never> {
90
+ const uri = twilioMockUrl(opts.uri, server.url)
91
+ return super.request({ ...opts, uri }) as Promise<never>
92
+ }
93
+ }
94
+ const client = twilio("AC00000000000000000000000000000000", "fixture-token", {
95
+ httpClient: new MockRequestClient(),
96
+ })
97
+ const verify = client.verify.v2.services("VA00000000000000000000000000000000")
98
+
99
+ // The app sends the code.
100
+ const verification = await verify.verifications.create({ to: "+12025550123", channel: "sms" })
101
+
102
+ // The test reads it from the admin plane, the way a user reads the SMS.
103
+ const latest = await fetch(`${server.url}/__admin/verify/+12025550123/latest`)
104
+ const { code } = (await latest.json()) as { code: string; sid: string; status: string }
105
+
106
+ // The app checks it.
107
+ const check = await verify.verificationChecks.create({ verificationSid: verification.sid, code })
108
+ // check.status === "approved"
109
+ await server.close()
83
110
  ```
84
111
 
85
112
  ### Routes