@crvouga/mockingbird-service-twilio 0.1.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.
@@ -0,0 +1,1148 @@
1
+ import { Hono } from 'hono';
2
+
3
+ /**
4
+ * Anything that can answer a Fetch `Request` with a `Response`.
5
+ *
6
+ * Every Mockingbird service implements this, and every runtime adapter consumes it.
7
+ * It is the only contract shared across the whole graph.
8
+ */
9
+ interface FetchAPI$1 {
10
+ fetch(request: Request): Promise<Response>;
11
+ }
12
+
13
+ /**
14
+ * The single source of time for a service.
15
+ *
16
+ * Every timestamp a mock writes reads from here, so a suite moves time instead of
17
+ * sleeping: appointment windows, result delays and expiries become reachable in
18
+ * milliseconds. A frozen clock also makes timestamps reproducible from a seed.
19
+ */
20
+ type ClockState = {
21
+ /** Current epoch milliseconds. */
22
+ now: number;
23
+ /** True while time does not advance on its own. */
24
+ frozen: boolean;
25
+ /** Milliseconds this clock adds to its underlying source. */
26
+ offsetMs: number;
27
+ };
28
+ type Clock = {
29
+ now(): number;
30
+ /** Pin the clock to an exact instant, keeping it frozen if it already was. */
31
+ set(epochMs: number): void;
32
+ /** Move the clock forward, or back with a negative delta. */
33
+ advance(deltaMs: number): void;
34
+ /** Stop time at the current instant. */
35
+ freeze(): void;
36
+ /** Resume from the current instant. */
37
+ unfreeze(): void;
38
+ /** Drop back to the underlying source, live. */
39
+ reset(): void;
40
+ state(): ClockState;
41
+ };
42
+
43
+ /** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
44
+ type SqliteValue$1 = null | number | bigint | string | Uint8Array | boolean;
45
+ /** Mutation counters returned by {@link SqliteStatement.run}. */
46
+ type SqliteRunResult$1 = {
47
+ changes: number;
48
+ lastInsertRowid: number | bigint;
49
+ };
50
+ /**
51
+ * Prepared statement bound to a {@link SqliteClient}.
52
+ *
53
+ * Pass bind values as rest arguments on each call (no sticky `bind()`).
54
+ */
55
+ interface SqliteStatement$1 {
56
+ run(...params: SqliteValue$1[]): SqliteRunResult$1;
57
+ all<T = Record<string, unknown>>(...params: SqliteValue$1[]): T[];
58
+ get<T = Record<string, unknown>>(...params: SqliteValue$1[]): T | undefined;
59
+ }
60
+ /**
61
+ * Sync SQLite client port owned by Mockingbird.
62
+ *
63
+ * Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
64
+ * `bun:sqlite` instances all work when they expose this surface.
65
+ */
66
+ interface SqliteClient$1 {
67
+ exec(sql: string): void;
68
+ prepare(sql: string): SqliteStatement$1;
69
+ transaction<T>(fn: () => T): T;
70
+ }
71
+
72
+ /** Every stored record carries a monotonically increasing sequence for stable ordering. */
73
+ type Stored<T> = {
74
+ seq: number;
75
+ value: T;
76
+ };
77
+ type ListRecordsOptions<T> = {
78
+ /** Keep only records passing the predicate. */
79
+ where?: (value: T, seq: number) => boolean;
80
+ /** Sort order; default newest first. */
81
+ order?: "newest" | "oldest";
82
+ };
83
+ /**
84
+ * A SQLite-backed table of JSON records addressed by id. Ordering is by insertion
85
+ * sequence, never by id lexicographic order, so list semantics stay stable.
86
+ */
87
+ declare class Collection<T> {
88
+ private readonly sqlite;
89
+ private readonly namespace;
90
+ private readonly name;
91
+ constructor(sqlite: SqliteClient$1, namespace: string, name: string);
92
+ private bumpCollectionSeq;
93
+ nextSequence(): number;
94
+ get(id: string): T | undefined;
95
+ has(id: string): boolean;
96
+ /** Insert a new record, assigning it the next sequence number. */
97
+ insert(id: string, value: T): Stored<T>;
98
+ /** Replace an existing record's value, keeping its position. */
99
+ update(id: string, value: T): Stored<T> | undefined;
100
+ delete(id: string): boolean;
101
+ /** How many records the collection holds, without reading them. */
102
+ count(): number;
103
+ list(options?: ListRecordsOptions<T>): Array<Stored<T> & {
104
+ id: string;
105
+ }>;
106
+ }
107
+
108
+ /**
109
+ * Seeded pseudo-random numbers, so anything a mock invents — ids, jitter, which
110
+ * request a percentage fault hits — is reproducible from a seed.
111
+ *
112
+ * mulberry32: small, fast, and stable across runtimes, which matters more here
113
+ * than statistical quality.
114
+ */
115
+ type Rng = {
116
+ /** Next value in `[0, 1)`. */
117
+ next(): number;
118
+ /** Next integer in `[min, max]`. */
119
+ int(min: number, max: number): number;
120
+ /** Restart the stream from its seed. */
121
+ reset(): void;
122
+ /** Serializable engine state used by deterministic checkpoints. */
123
+ state(): number;
124
+ /** Restore a state previously returned by {@link state}. */
125
+ setState(state: number): void;
126
+ seed: number;
127
+ };
128
+
129
+ /**
130
+ * A deliberate failure injected in front of an operation.
131
+ *
132
+ * This is how a suite reaches the vendor's failure modes without the vendor: the
133
+ * quota error that only appears when a shared sandbox is full, the 429 that only
134
+ * appears under load, the 5xx that proves a retry path works.
135
+ */
136
+ type FaultRule = {
137
+ /** Stable id, so a suite can retire exactly the rule it added. */
138
+ id: string;
139
+ /** Fault only this operation. Omit to match every operation. */
140
+ operationId?: string;
141
+ /** Fault only this HTTP method, case-insensitive. Omit to match every method. */
142
+ method?: string;
143
+ /** Fault only paths starting with this prefix. Omit to match every path. */
144
+ pathPrefix?: string;
145
+ /**
146
+ * Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
147
+ * an in-process caller usually wants, and what a parallel worker usually does not:
148
+ * rules added through `POST /__admin/faults` default to the calling namespace.
149
+ */
150
+ namespace?: string;
151
+ /**
152
+ * Status of the injected response. Omit for a rule that only delays (`delayMs` /
153
+ * `latencyMs`), only drops the connection (`drop`), or only switches on an `effect`:
154
+ * the request then still reaches the service.
155
+ */
156
+ status?: number;
157
+ /** Response body, serialized as JSON. A string is sent as-is. */
158
+ body?: unknown;
159
+ headers?: Record<string, string>;
160
+ /** Retire the rule after this many faults. Omit to keep it until removed. */
161
+ count?: number;
162
+ /** Fault this fraction of matching requests, `0`–`1`. Default `1`. */
163
+ rate?: number;
164
+ /** Hold the response back this long, to exercise timeouts. */
165
+ delayMs?: number;
166
+ /** Alias of `delayMs`. */
167
+ latencyMs?: number;
168
+ /**
169
+ * Drop the connection instead of answering: an in-process `fetch` rejects with a
170
+ * `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
171
+ */
172
+ drop?: boolean;
173
+ /**
174
+ * A named service behaviour to switch on for the matching request instead of (or
175
+ * before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
176
+ * read it with `faultEffects(request)`.
177
+ */
178
+ effect?: string;
179
+ /** Parameters for `effect`. */
180
+ params?: Record<string, unknown>;
181
+ /** From the preset this rule was expanded from, if any. */
182
+ preset?: string;
183
+ };
184
+ /** A fault that fired for one request. */
185
+ type FaultHit = {
186
+ id: string;
187
+ /** The injected response; absent when the rule only delays, drops, or sets an effect. */
188
+ response?: Response;
189
+ drop?: boolean;
190
+ effect?: {
191
+ name: string;
192
+ params: Record<string, unknown>;
193
+ };
194
+ };
195
+ /**
196
+ * A named, documented fault a suite switches on by name
197
+ * (`POST /__admin/faults {"preset": "rate_limited"}`): one or more rules, and optionally a
198
+ * webhook delivery fault.
199
+ */
200
+ type FaultPreset = {
201
+ description: string;
202
+ rules?: Omit<FaultRule, "id">[];
203
+ webhook?: {
204
+ mode: "duplicate" | "reorder" | "drop";
205
+ count?: number;
206
+ };
207
+ };
208
+ /** What a request looks like to the fault matcher. */
209
+ type FaultCandidate = {
210
+ operationId: string | undefined;
211
+ method: string;
212
+ path: string;
213
+ namespace: string;
214
+ };
215
+ type FaultRegistry = {
216
+ add(rule: FaultRule): FaultRule;
217
+ list(): (FaultRule & {
218
+ remaining: number | null;
219
+ hits: number;
220
+ })[];
221
+ remove(id: string): boolean;
222
+ clear(): void;
223
+ /**
224
+ * Every fault this request should get, in rule order, stopping at the first that answers
225
+ * or drops (effect-only and delay-only rules let later rules match too). Consumes one of
226
+ * each matching rule's remaining uses.
227
+ */
228
+ take(candidate: FaultCandidate): Promise<FaultHit[]>;
229
+ };
230
+
231
+ /** One handled request, as the structured log sees it. */
232
+ type RequestLog = {
233
+ service: string;
234
+ namespace: string;
235
+ operationId: string | undefined;
236
+ method: string;
237
+ path: string;
238
+ status: number;
239
+ durationMs: number;
240
+ /** True when the path matched no operation in the contract. */
241
+ unmatched: boolean;
242
+ /** Set when a fault rule produced the response. */
243
+ faultId?: string;
244
+ /** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
245
+ ids?: Record<string, string>;
246
+ /** Set when the service created a resource the request referred to but that did not exist. */
247
+ adopted?: boolean;
248
+ };
249
+ type MetricsReport = {
250
+ requests: number;
251
+ /** Counts keyed `<operationId> <status>`. */
252
+ byOperation: Record<string, number>;
253
+ /**
254
+ * Paths that matched no operation, most frequent first.
255
+ *
256
+ * This is the early-warning signal: a consumer calling something the mock does
257
+ * not implement shows up here as a count, before it fails a suite as a 404.
258
+ */
259
+ unmatched: {
260
+ method: string;
261
+ path: string;
262
+ count: number;
263
+ }[];
264
+ faults: number;
265
+ totalDurationMs: number;
266
+ };
267
+ type Metrics = {
268
+ record(entry: RequestLog): void;
269
+ report(): MetricsReport;
270
+ reset(): void;
271
+ };
272
+
273
+ /** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
274
+ type JournalEntry = RequestLog & {
275
+ at: string;
276
+ };
277
+ type JournalQuery = {
278
+ /** Only this namespace. Omit for every namespace, oldest first across all of them. */
279
+ namespace?: string;
280
+ operationId?: string;
281
+ status?: number;
282
+ /** Only entries at or after this instant (epoch ms). */
283
+ since?: number;
284
+ /** At most this many, the most recent kept. */
285
+ limit?: number;
286
+ };
287
+ type Journal = {
288
+ readonly size: number;
289
+ record(entry: JournalEntry): void;
290
+ list(query?: JournalQuery): JournalEntry[];
291
+ /** Forget one namespace's entries, or every namespace's. */
292
+ clear(namespace?: string): void;
293
+ };
294
+
295
+ /** Credential → namespace mapping behind `PUT /__admin/credentials`. */
296
+ type CredentialRegistry = {
297
+ set(credential: string, namespace: string): void;
298
+ get(credential: string): string | undefined;
299
+ remove(credential: string): boolean;
300
+ clear(): void;
301
+ entries(): {
302
+ credential: string;
303
+ namespace: string;
304
+ }[];
305
+ };
306
+
307
+ /** A stable identifier for a point in a {@link Timeline}. */
308
+ type CheckpointId = string;
309
+ /** An immutable node in a timeline's checkpoint DAG. */
310
+ type Checkpoint<T> = Readonly<{
311
+ id: CheckpointId;
312
+ branch: string;
313
+ parent: CheckpointId | null;
314
+ /** Logical time supplied by the timeline's injected clock. */
315
+ at: number;
316
+ value: T;
317
+ }>;
318
+ type TimelineOptions = {
319
+ /** Logical clock used to stamp checkpoints. Defaults to a deterministic counter. */
320
+ now?: () => number;
321
+ /** Maximum retained checkpoints. Branch heads are never collected. Default 1,000. */
322
+ maxCheckpoints?: number;
323
+ /** Customize deterministic checkpoint IDs. */
324
+ id?: (sequence: number) => CheckpointId;
325
+ };
326
+ type CommitOptions = {
327
+ branch?: string;
328
+ /** Parent checkpoint. Defaults to the selected branch's current head. */
329
+ parent?: CheckpointId | null;
330
+ };
331
+ type ForkOptions = {
332
+ /** Checkpoint to fork from. Defaults to the main branch's head. */
333
+ from?: CheckpointId;
334
+ };
335
+ /**
336
+ * Small, storage-agnostic checkpoint DAG shared by service runtimes. Its values may be immutable
337
+ * records, namespace images, or copy-on-write SQL engine snapshots.
338
+ *
339
+ * Values are retained by reference. Engines can therefore use persistent/COW snapshots while
340
+ * simpler services can use immutable values. IDs and GC order are deterministic, and all IO
341
+ * (the logical clock) is injected.
342
+ */
343
+ declare class Timeline<T> {
344
+ readonly maxCheckpoints: number;
345
+ private readonly now;
346
+ private readonly makeId;
347
+ private readonly nodes;
348
+ private readonly heads;
349
+ /** Unreferenced nodes in the exact order they became collectible. */
350
+ private readonly evictable;
351
+ /** Branch heads plus explicit retainers. Absent means zero. */
352
+ private readonly references;
353
+ private readonly explicitPins;
354
+ private sequence;
355
+ constructor(options?: TimelineOptions);
356
+ /** Capture a new immutable value and move `branch` to it. */
357
+ commit(value: T, options?: CommitOptions): Checkpoint<T>;
358
+ /** Create a branch pointer without copying its checkpoint value. */
359
+ fork(branch: string, options?: ForkOptions): Checkpoint<T> | undefined;
360
+ /** Move a branch pointer to an existing checkpoint. */
361
+ checkout(branch: string, id: CheckpointId): Checkpoint<T>;
362
+ get(id: CheckpointId): Checkpoint<T>;
363
+ head(branch?: string): Checkpoint<T> | undefined;
364
+ hasBranch(branch: string): boolean;
365
+ branches(): Readonly<Record<string, CheckpointId>>;
366
+ checkpoints(): readonly Checkpoint<T>[];
367
+ /** Number of retained checkpoints without allocating an array. */
368
+ get size(): number;
369
+ /** Pin a checkpoint independently of branch heads (used by compatibility snapshot handles). */
370
+ retain(id: CheckpointId): Checkpoint<T>;
371
+ /** Release one explicit pin. Branch heads remain pinned until moved or deleted. */
372
+ release(id: CheckpointId): boolean;
373
+ deleteBranch(branch: string): boolean;
374
+ /**
375
+ * Deterministically discard oldest unpinned checkpoints. Collection is O(number removed):
376
+ * commits never scan pinned nodes or the retained history. Parents are metadata rather than a
377
+ * storage dependency, so a retained node remains usable after pruning.
378
+ */
379
+ gc(max?: number): CheckpointId[];
380
+ private collect;
381
+ private moveHead;
382
+ private addReference;
383
+ private removeReference;
384
+ private assertBranch;
385
+ }
386
+
387
+ /**
388
+ * Anything that can answer a Fetch `Request` with a `Response`.
389
+ *
390
+ * Every Mockingbird service implements this, and every runtime adapter consumes it.
391
+ * It is the only contract shared across the whole graph.
392
+ */
393
+ interface FetchAPI {
394
+ fetch(request: Request): Promise<Response>;
395
+ }
396
+
397
+ /**
398
+ * A point-in-time copy of everything a service namespace holds.
399
+ *
400
+ * All service state lives in the two core tables keyed by namespace, so a snapshot
401
+ * is generic: any service gets per-test rollback without knowing its own schema.
402
+ * Restoring is much cheaper than rebuilding a namespace from a corpus.
403
+ */
404
+ type NamespaceSnapshot = {
405
+ namespace: string;
406
+ records: {
407
+ collection: string;
408
+ id: string;
409
+ seq: number;
410
+ value: string;
411
+ }[];
412
+ sequences: {
413
+ name: string;
414
+ kind: string;
415
+ value: number;
416
+ }[];
417
+ };
418
+
419
+ type WebhookEndpoint = {
420
+ /** Stable id; generated when omitted. */
421
+ id?: string;
422
+ url: string;
423
+ secret?: string;
424
+ /** Event types to deliver; omit or include `"*"` for every type. */
425
+ events?: string[];
426
+ /** Deliver only messages whose tags include all of these (e.g. `{ account: "mso" }`). */
427
+ tags?: Record<string, string>;
428
+ /** The public URL the receiver verifies signatures against (Twilio), when it differs. */
429
+ signUrl?: string;
430
+ headers?: Record<string, string>;
431
+ };
432
+ type WebhookMessage = {
433
+ id: string;
434
+ namespace: string;
435
+ type: string;
436
+ body: string;
437
+ contentType: string;
438
+ tags: Record<string, string>;
439
+ headers?: Record<string, string>;
440
+ /** Wall-clock ISO-8601 time of publication. */
441
+ publishedAt: string;
442
+ };
443
+ type WebhookAttempt = {
444
+ attempt: number;
445
+ at: string;
446
+ status: number | null;
447
+ error: string | null;
448
+ durationMs: number;
449
+ /** Exact receiver response body, when one was returned. */
450
+ responseBody?: string | null;
451
+ };
452
+ type WebhookDelivery = {
453
+ id: string;
454
+ messageId: string;
455
+ namespace: string;
456
+ type: string;
457
+ endpointId: string;
458
+ url: string;
459
+ state: "pending" | "delivered" | "failed" | "dropped";
460
+ attempts: WebhookAttempt[];
461
+ };
462
+ /** A delivery-level fault: what happens to the next `count` messages in a namespace. */
463
+ type WebhookFault = {
464
+ mode: "duplicate" | "reorder" | "drop";
465
+ /** Messages affected; default 1. */
466
+ count?: number;
467
+ };
468
+ type PublishInput = {
469
+ namespace: string;
470
+ type: string;
471
+ /** Exact body; objects are JSON-encoded. */
472
+ body: string | Record<string, unknown> | unknown[];
473
+ /** Default `application/json`, or form-encoded when `form` is given. */
474
+ contentType?: string;
475
+ /** Form parameters, when the vendor posts `application/x-www-form-urlencoded`. */
476
+ form?: Record<string, string>;
477
+ tags?: Record<string, string>;
478
+ /** Message-specific delivery headers, captured as part of durable message state. */
479
+ headers?: Record<string, string>;
480
+ /** Message id; generated when omitted. */
481
+ id?: string;
482
+ };
483
+ type WebhookHub = {
484
+ publish(input: PublishInput): WebhookMessage;
485
+ /** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
486
+ setEndpoints(namespace: string, endpoints: WebhookEndpoint[]): WebhookEndpoint[];
487
+ /** The endpoints a namespace delivers to: its own, plus the global ones. */
488
+ endpoints(namespace: string): WebhookEndpoint[];
489
+ messages(namespace?: string): WebhookMessage[];
490
+ deliveries(namespace?: string): WebhookDelivery[];
491
+ replay(deliveryId: string): Promise<WebhookDelivery | undefined>;
492
+ /** Run every pending retry (and release held reordered messages) now. */
493
+ flush(): Promise<void>;
494
+ /** Resolve once nothing is in flight. */
495
+ idle(): Promise<void>;
496
+ fault(namespace: string, fault: WebhookFault): void;
497
+ clear(namespace?: string): void;
498
+ };
499
+
500
+ /** What the runtime needs from a service: a Fetch handler it can reset. */
501
+ type ServiceInstance = FetchAPI & {
502
+ reset(): Promise<void>;
503
+ };
504
+ type ServiceTimelineState = Readonly<{
505
+ snapshot: NamespaceSnapshot;
506
+ clock: Readonly<ReturnType<Clock["state"]>>;
507
+ rngState: number;
508
+ }>;
509
+ type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
510
+ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
511
+ readonly name: string;
512
+ readonly sqlite: SqliteClient$1;
513
+ readonly clock: Clock;
514
+ readonly faults: FaultRegistry;
515
+ readonly metrics: Metrics;
516
+ readonly journal: Journal;
517
+ readonly rng: Rng;
518
+ readonly credentials: CredentialRegistry;
519
+ /** The webhook hub, when the service has outbound webhooks. */
520
+ readonly webhooks: WebhookHub | undefined;
521
+ /** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
522
+ applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
523
+ /** The instance behind `namespace` (the default one when omitted), created on first use. */
524
+ instance(namespace?: string): T;
525
+ /** Public names of every namespace created so far. */
526
+ namespaces(): string[];
527
+ /** Reset one namespace, or every namespace with `"*"`. */
528
+ reset(namespace?: string): Promise<void>;
529
+ snapshot(namespace?: string): NamespaceSnapshot;
530
+ restore(snapshot: NamespaceSnapshot, namespace?: string): void;
531
+ /** Capture the current branch. Mutating HTTP calls do this automatically. */
532
+ checkpoint(namespace?: string, branch?: string): ServiceCheckpoint;
533
+ /** Create an isolated branch, optionally from a historical checkpoint. */
534
+ branch(name: string, options?: {
535
+ namespace?: string;
536
+ at?: string;
537
+ }): ServiceCheckpoint;
538
+ /** Restore a branch, clock, and PRNG to a checkpoint. */
539
+ checkout(checkpoint: string, options?: {
540
+ namespace?: string;
541
+ branch?: string;
542
+ }): void;
543
+ /** Inspect the retained history for a namespace. */
544
+ timeline(namespace?: string): Timeline<ServiceTimelineState>;
545
+ };
546
+
547
+ /**
548
+ * What a comms vendor "sent" (an SMS, an email, a Slack post), kept per namespace so a
549
+ * suite can assert on it and read codes and links out of it. Stored in SQLite beside the
550
+ * service's other records, so reset, snapshot and restore cover it.
551
+ */
552
+ type OutboxItem = {
553
+ id: string;
554
+ /** Recipient(s): a phone number, email address, channel or webhook path. */
555
+ to: string | string[];
556
+ /** ISO-8601 on the mock clock. */
557
+ createdAt: string;
558
+ };
559
+ type OutboxQuery = {
560
+ /** Case-insensitive match on any recipient. */
561
+ to?: string;
562
+ /** Only items at or after this instant (epoch ms). */
563
+ since?: number;
564
+ /** Extra filter over the item. */
565
+ where?: (item: Record<string, unknown>) => boolean;
566
+ limit?: number;
567
+ };
568
+ declare class OutboxStore<T extends OutboxItem = OutboxItem> {
569
+ private readonly items;
570
+ constructor(sqlite: SqliteClient$1, namespace: string, name?: string);
571
+ record(item: T): T;
572
+ get(id: string): T | undefined;
573
+ update(id: string, item: T): void;
574
+ /** Oldest first, so a suite reads messages in the order they were sent. */
575
+ list(query?: OutboxQuery): T[];
576
+ }
577
+
578
+ /** Options every provider constructor accepts. */
579
+ type APIOptions = {
580
+ /** Sync SQLite client. Defaults to `@crvouga/mockingbird-service-sqlite`. */
581
+ sqlite?: SqliteClient$1;
582
+ /** Clock used for `created`-style fields. Default `Date.now`. */
583
+ now?: () => number;
584
+ /**
585
+ * Storage namespace for this instance's records. Instances sharing one SQLite
586
+ * client stay isolated when their namespaces differ. Defaults to the service name.
587
+ */
588
+ namespace?: string;
589
+ };
590
+
591
+ /** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
592
+ type SqliteValue = null | number | bigint | string | Uint8Array | boolean;
593
+ /** Mutation counters returned by {@link SqliteStatement.run}. */
594
+ type SqliteRunResult = {
595
+ changes: number;
596
+ lastInsertRowid: number | bigint;
597
+ };
598
+ /**
599
+ * Prepared statement bound to a {@link SqliteClient}.
600
+ *
601
+ * Pass bind values as rest arguments on each call (no sticky `bind()`).
602
+ */
603
+ interface SqliteStatement {
604
+ run(...params: SqliteValue[]): SqliteRunResult;
605
+ all<T = Record<string, unknown>>(...params: SqliteValue[]): T[];
606
+ get<T = Record<string, unknown>>(...params: SqliteValue[]): T | undefined;
607
+ }
608
+ /**
609
+ * Sync SQLite client port owned by Mockingbird.
610
+ *
611
+ * Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
612
+ * `bun:sqlite` instances all work when they expose this surface.
613
+ */
614
+ interface SqliteClient {
615
+ exec(sql: string): void;
616
+ prepare(sql: string): SqliteStatement;
617
+ transaction<T>(fn: () => T): T;
618
+ }
619
+
620
+ /**
621
+ * Lookup v2 number validation, modelled on what the live API answers (it is libphonenumber:
622
+ * the validation errors are libphonenumber's reasons). Verified live for fictional 555-01xx
623
+ * numbers and malformed inputs; see scripts/parity.ts.
624
+ */
625
+ type ValidationError = "TOO_SHORT" | "TOO_LONG" | "INVALID_BUT_POSSIBLE" | "INVALID_COUNTRY_CODE" | "INVALID_LENGTH" | "NOT_A_NUMBER";
626
+ type LookupResult = {
627
+ calling_country_code: string | null;
628
+ country_code: string | null;
629
+ phone_number: string;
630
+ national_format: string | null;
631
+ valid: boolean;
632
+ validation_errors: ValidationError[];
633
+ };
634
+ /**
635
+ * Validate the way Lookup v2 does. `raw` is the decoded path segment; `countryCode` the
636
+ * optional `CountryCode` query parameter (the region for a national-format number).
637
+ */
638
+ declare const lookup: (raw: string, countryCode?: string) => LookupResult;
639
+ /** `+` and digits only: the key admin routes and overrides use. */
640
+ declare const e164Key: (value: string) => string;
641
+
642
+ type VerificationStatus = "pending" | "approved" | "canceled" | "expired";
643
+ /**
644
+ * One Verify verification. `code` never leaves the mock through the vendor API: tests read it
645
+ * with `GET /__admin/verify/:e164/latest` (or from the outbox), as a phone would receive it.
646
+ */
647
+ type VerificationRecord = {
648
+ sid: string;
649
+ serviceSid: string;
650
+ accountSid: string;
651
+ to: string;
652
+ channel: string;
653
+ code: string;
654
+ status: VerificationStatus;
655
+ /** Check attempts made against this verification (right or wrong). */
656
+ attempts: number;
657
+ sendAttempts: {
658
+ attemptSid: string;
659
+ channel: string;
660
+ time: string;
661
+ timeMs: number;
662
+ }[];
663
+ createdAtMs: number;
664
+ dateCreated: string;
665
+ dateUpdated: string;
666
+ };
667
+ /** A Message resource as `Messages.json` answers it. */
668
+ type MessageRecord = {
669
+ sid: string;
670
+ account_sid: string;
671
+ api_version: "2010-04-01";
672
+ body: string;
673
+ to: string;
674
+ from: string | null;
675
+ messaging_service_sid: string | null;
676
+ status: "queued" | "accepted";
677
+ direction: "outbound-api";
678
+ num_segments: string;
679
+ num_media: string;
680
+ price: null;
681
+ price_unit: "USD";
682
+ error_code: null;
683
+ error_message: null;
684
+ date_created: string;
685
+ date_updated: string;
686
+ date_sent: null;
687
+ uri: string;
688
+ subresource_uris: {
689
+ media: string;
690
+ feedback: string;
691
+ };
692
+ };
693
+ type RecordingRecord = {
694
+ sid: string;
695
+ accountSid: string;
696
+ callSid: string;
697
+ /** The WAV exactly as served with `RequestedChannels=2`. */
698
+ wavBase64: string;
699
+ channels: number;
700
+ duration: number;
701
+ createdAt: string;
702
+ deleted: boolean;
703
+ };
704
+ /** What the mock "sent": outbound SMS and every Verify code delivery. */
705
+ type TwilioOutboxItem = OutboxItem & {
706
+ kind: "sms" | "verify";
707
+ sid: string;
708
+ to: string;
709
+ from: string | null;
710
+ messagingServiceSid: string | null;
711
+ body: string;
712
+ channel: string;
713
+ /** The Verify code, for `kind: "verify"`. */
714
+ code?: string;
715
+ mediaUrls?: string[];
716
+ };
717
+ type LookupOverride = {
718
+ valid: boolean;
719
+ validationErrors: ValidationError[];
720
+ };
721
+ /** Per-namespace Verify knobs, set through `PUT /__admin/verify`; cleared on reset. */
722
+ type VerifySettings = {
723
+ /** Every new verification gets this code; `null` means a random 6-digit code. */
724
+ fixedCode: string | null;
725
+ /** Verifications expire this long after creation, on the mock clock (Twilio: 10 min). */
726
+ ttlSeconds: number;
727
+ /** Checks allowed per verification; the next one is 429 60202. */
728
+ maxCheckAttempts: number;
729
+ /** Sends allowed per number and service within `sendWindowSeconds`; the next is 429 60203. */
730
+ maxSendAttempts: number;
731
+ sendWindowSeconds: number;
732
+ };
733
+ declare const DEFAULT_VERIFY_SETTINGS: VerifySettings;
734
+ declare class TwilioState {
735
+ private readonly namespace;
736
+ private readonly seed;
737
+ readonly verifications: Collection<VerificationRecord>;
738
+ readonly messages: Collection<MessageRecord>;
739
+ readonly recordings: Collection<RecordingRecord>;
740
+ readonly lookups: Collection<LookupOverride>;
741
+ readonly settings: Collection<VerifySettings>;
742
+ readonly outbox: OutboxStore<TwilioOutboxItem>;
743
+ private readonly ids;
744
+ constructor(sqlite: SqliteClient, namespace: string, seed?: Partial<VerifySettings>);
745
+ /** A Twilio sid: two-letter prefix plus 32 hex characters, deterministic per history. */
746
+ sid(prefix: string): string;
747
+ /** A random-looking but reproducible 6-digit code for a new verification. */
748
+ code(sid: string, length?: number): string;
749
+ verify(): VerifySettings;
750
+ updateVerify(patch: Partial<VerifySettings>): VerifySettings;
751
+ /** Newest first. */
752
+ verificationsTo(to: string, serviceSid?: string): VerificationRecord[];
753
+ }
754
+
755
+ /**
756
+ * The slice of OpenAPI 3.1 (and JSON Schema 2020-12) Mockingbird understands.
757
+ * Unknown keys (including `x-*` extensions) are preserved on every object.
758
+ */
759
+ type JsonPrimitive = string | number | boolean | null;
760
+ type JsonValue = JsonPrimitive | JsonValue[] | {
761
+ [key: string]: JsonValue;
762
+ };
763
+ type ReferenceObject = {
764
+ $ref: string;
765
+ description?: string;
766
+ summary?: string;
767
+ };
768
+ type SchemaType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
769
+ type SchemaObject = {
770
+ $ref?: string;
771
+ type?: SchemaType | SchemaType[];
772
+ title?: string;
773
+ description?: string;
774
+ format?: string;
775
+ enum?: JsonValue[];
776
+ const?: JsonValue;
777
+ default?: JsonValue;
778
+ example?: JsonValue;
779
+ examples?: JsonValue[];
780
+ nullable?: boolean;
781
+ deprecated?: boolean;
782
+ readOnly?: boolean;
783
+ writeOnly?: boolean;
784
+ minimum?: number;
785
+ maximum?: number;
786
+ exclusiveMinimum?: number;
787
+ exclusiveMaximum?: number;
788
+ multipleOf?: number;
789
+ minLength?: number;
790
+ maxLength?: number;
791
+ pattern?: string;
792
+ minItems?: number;
793
+ maxItems?: number;
794
+ uniqueItems?: boolean;
795
+ items?: SchemaObject;
796
+ prefixItems?: SchemaObject[];
797
+ minProperties?: number;
798
+ maxProperties?: number;
799
+ required?: string[];
800
+ properties?: Record<string, SchemaObject>;
801
+ additionalProperties?: boolean | SchemaObject;
802
+ propertyNames?: SchemaObject;
803
+ oneOf?: SchemaObject[];
804
+ anyOf?: SchemaObject[];
805
+ allOf?: SchemaObject[];
806
+ not?: SchemaObject;
807
+ discriminator?: {
808
+ propertyName: string;
809
+ mapping?: Record<string, string>;
810
+ };
811
+ [extension: `x-${string}`]: unknown;
812
+ };
813
+ type ParameterLocation = "path" | "query" | "header" | "cookie";
814
+ type ParameterObject = {
815
+ name: string;
816
+ in: ParameterLocation;
817
+ description?: string;
818
+ required?: boolean;
819
+ deprecated?: boolean;
820
+ style?: string;
821
+ explode?: boolean;
822
+ schema?: SchemaObject;
823
+ content?: Record<string, MediaTypeObject>;
824
+ example?: JsonValue;
825
+ [extension: `x-${string}`]: unknown;
826
+ };
827
+ type MediaTypeObject = {
828
+ schema?: SchemaObject;
829
+ example?: JsonValue;
830
+ examples?: Record<string, unknown>;
831
+ encoding?: Record<string, unknown>;
832
+ [extension: `x-${string}`]: unknown;
833
+ };
834
+ type RequestBodyObject = {
835
+ description?: string;
836
+ required?: boolean;
837
+ content: Record<string, MediaTypeObject>;
838
+ [extension: `x-${string}`]: unknown;
839
+ };
840
+ type HeaderObject = {
841
+ description?: string;
842
+ required?: boolean;
843
+ schema?: SchemaObject;
844
+ [extension: `x-${string}`]: unknown;
845
+ };
846
+ type ResponseObject = {
847
+ description: string;
848
+ headers?: Record<string, HeaderObject | ReferenceObject>;
849
+ content?: Record<string, MediaTypeObject>;
850
+ [extension: `x-${string}`]: unknown;
851
+ };
852
+ type ResponsesObject = Record<string, ResponseObject | ReferenceObject>;
853
+ type SecurityRequirementObject = Record<string, string[]>;
854
+ type OperationObject = {
855
+ operationId?: string;
856
+ summary?: string;
857
+ description?: string;
858
+ tags?: string[];
859
+ deprecated?: boolean;
860
+ parameters?: Array<ParameterObject | ReferenceObject>;
861
+ requestBody?: RequestBodyObject | ReferenceObject;
862
+ responses: ResponsesObject;
863
+ security?: SecurityRequirementObject[];
864
+ [extension: `x-${string}`]: unknown;
865
+ };
866
+ declare const HTTP_METHODS: readonly ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
867
+ type HttpMethod = (typeof HTTP_METHODS)[number];
868
+ type PathItemObject = {
869
+ summary?: string;
870
+ description?: string;
871
+ parameters?: Array<ParameterObject | ReferenceObject>;
872
+ [extension: `x-${string}`]: unknown;
873
+ } & Partial<Record<HttpMethod, OperationObject>>;
874
+ type SecuritySchemeObject = {
875
+ type: "apiKey" | "http" | "oauth2" | "openIdConnect" | "mutualTLS";
876
+ description?: string;
877
+ name?: string;
878
+ in?: ParameterLocation;
879
+ scheme?: string;
880
+ bearerFormat?: string;
881
+ flows?: Record<string, unknown>;
882
+ openIdConnectUrl?: string;
883
+ [extension: `x-${string}`]: unknown;
884
+ };
885
+ type ComponentsObject = {
886
+ schemas?: Record<string, SchemaObject>;
887
+ responses?: Record<string, ResponseObject>;
888
+ parameters?: Record<string, ParameterObject>;
889
+ requestBodies?: Record<string, RequestBodyObject>;
890
+ headers?: Record<string, HeaderObject>;
891
+ securitySchemes?: Record<string, SecuritySchemeObject>;
892
+ [extension: `x-${string}`]: unknown;
893
+ };
894
+ type ServerObject = {
895
+ url: string;
896
+ description?: string;
897
+ variables?: Record<string, unknown>;
898
+ [extension: `x-${string}`]: unknown;
899
+ };
900
+ type InfoObject = {
901
+ title: string;
902
+ version: string;
903
+ description?: string;
904
+ [extension: `x-${string}`]: unknown;
905
+ };
906
+ type OpenAPIDocument = {
907
+ openapi: string;
908
+ info: InfoObject;
909
+ servers?: ServerObject[];
910
+ paths: Record<string, PathItemObject>;
911
+ components?: ComponentsObject;
912
+ security?: SecurityRequirementObject[];
913
+ tags?: Array<{
914
+ name: string;
915
+ description?: string;
916
+ }>;
917
+ [extension: `x-${string}`]: unknown;
918
+ };
919
+
920
+ declare const document: OpenAPIDocument;
921
+ type OperationId = "FetchPhoneNumber" | "CreateVerification" | "FetchVerification" | "UpdateVerification" | "CreateVerificationCheck" | "CreateMessage" | "FetchMessage" | "FetchRecordingMedia" | "FetchRecording" | "DeleteRecording";
922
+ type SupportedOperationId = "FetchPhoneNumber" | "CreateVerification" | "FetchVerification" | "UpdateVerification" | "CreateVerificationCheck" | "CreateMessage" | "FetchMessage" | "FetchRecordingMedia" | "FetchRecording" | "DeleteRecording";
923
+ declare const operationIds: readonly ["FetchPhoneNumber", "CreateVerification", "FetchVerification", "UpdateVerification", "CreateVerificationCheck", "CreateMessage", "FetchMessage", "FetchRecordingMedia", "FetchRecording", "DeleteRecording"];
924
+ declare const supportedOperationIds: readonly ["FetchPhoneNumber", "CreateVerification", "FetchVerification", "UpdateVerification", "CreateVerificationCheck", "CreateMessage", "FetchMessage", "FetchRecordingMedia", "FetchRecording", "DeleteRecording"];
925
+
926
+ /**
927
+ * Routing Twilio's per-product hosts onto one mock origin.
928
+ *
929
+ * twilio-node builds absolute URLs on a host per product (`https://verify.twilio.com/v2/…`,
930
+ * `https://lookups.twilio.com/v2/…`, `https://api.twilio.com/2010-04-01/…`). The mock serves
931
+ * them all on one port and tells them apart by the product carried as the first path segment:
932
+ * `{mock}/verify/v2/…`, `{mock}/lookups/v2/…`, `{mock}/api/2010-04-01/…`.
933
+ */
934
+ /** The products the mock serves, by their host's first label. */
935
+ declare const TWILIO_PRODUCTS: readonly ["api", "verify", "lookups"];
936
+ /**
937
+ * The mock URL for an upstream Twilio URL: `https://verify.twilio.com/v2/Services/VA…/Verifications`
938
+ * with base `http://127.0.0.1:8798` becomes `http://127.0.0.1:8798/verify/v2/Services/VA…/Verifications`.
939
+ * A base with a path (`http://127.0.0.1:8798/ns/worker-1`) keeps it. Non-Twilio URLs are
940
+ * returned unchanged.
941
+ */
942
+ declare const twilioMockUrl: (uri: string, mockBaseUrl: string) => string;
943
+
944
+ /**
945
+ * Just enough RIFF/WAVE for the Recordings surface: synthesise a PCM recording, read a WAV's
946
+ * format, and mix a dual-channel recording down to mono (what Twilio serves unless the
947
+ * request asks for `RequestedChannels=2`).
948
+ */
949
+ type WavFormat = {
950
+ audioFormat: number;
951
+ channels: number;
952
+ sampleRate: number;
953
+ bitsPerSample: number;
954
+ /** Offset and length of the `data` chunk, when present. */
955
+ dataOffset: number;
956
+ dataLength: number;
957
+ };
958
+ /** The `fmt ` and `data` chunks of a RIFF/WAVE file, or `undefined` when it is not one. */
959
+ declare const readWav: (bytes: Uint8Array) => WavFormat | undefined;
960
+ /**
961
+ * A 16-bit PCM WAV like a Twilio call recording (8 kHz). Each channel carries a quiet tone at a
962
+ * different pitch, so a mix-down is observably not either channel.
963
+ */
964
+ declare const synthesizeWav: (options?: {
965
+ channels?: number;
966
+ seconds?: number;
967
+ }) => Uint8Array<ArrayBuffer>;
968
+ /** Average a 16-bit PCM WAV's channels into one; anything else is returned unchanged. */
969
+ declare const mixDownToMono: (bytes: Uint8Array) => Uint8Array;
970
+
971
+ /**
972
+ * Every named Twilio misbehaviour our consumer branches on, switched on with
973
+ * `POST /__admin/faults {"preset": "<name>"}` (add `count` to limit it). Our code branches on
974
+ * HTTP status class and transport errors only, never on Twilio's numeric codes.
975
+ */
976
+ declare const TWILIO_PRESETS: Record<string, FaultPreset>;
977
+ /** Event types the hub publishes; endpoints can filter on them (`PUT /__admin/webhook-endpoints`). */
978
+ declare const TWILIO_WEBHOOK_EVENTS: {
979
+ readonly "sms.inbound": "/messaging/inbound/sms";
980
+ readonly "voice.twiml": "/admin/messaging/voice/twiml";
981
+ readonly "voice.disclosure": "/admin/messaging/voice/disclosure";
982
+ readonly "voice.status": "/admin/messaging/voice/status";
983
+ readonly "voice.recording": "/admin/messaging/voice/recording";
984
+ };
985
+ type VoiceWebhookKind = "twiml" | "disclosure" | "status" | "recording";
986
+ /**
987
+ * Where Twilio's inbound webhooks go: the app's origin, the public base URL it verifies
988
+ * signatures against (`TWILIO_VOICE_WEBHOOK_BASE_URL`), and the auth token it verifies with.
989
+ */
990
+ type TwilioAppWebhooks = {
991
+ /** Where the mock posts, e.g. `http://127.0.0.1:3000`. */
992
+ url: string;
993
+ /** The public base URL the app signs against. Default: `url`. */
994
+ publicBaseUrl?: string;
995
+ /** The app's `TWILIO_AUTH_TOKEN` (the HMAC key). */
996
+ authToken: string;
997
+ /** `AccountSid` in the payloads. Default {@link DEFAULT_ACCOUNT_SID}. */
998
+ accountSid?: string;
999
+ /** `To` of inbound SMS (the app requires `TWILIO_VOICE_CALLER_ID`). */
1000
+ callerId?: string;
1001
+ /** `MessagingServiceSid` of inbound SMS, when the number belongs to one. */
1002
+ messagingServiceSid?: string;
1003
+ };
1004
+ type TwilioRuntimeOptions = {
1005
+ sqlite?: SqliteClient;
1006
+ clock?: Clock;
1007
+ seed?: number | string;
1008
+ adminKey?: string;
1009
+ onLog?: (entry: RequestLog) => void;
1010
+ /** Initial Verify settings for every namespace (e.g. `{fixedCode: "000000"}`). */
1011
+ verify?: Partial<VerifySettings>;
1012
+ /** Accepted `AccountSid → AuthToken` pairs; omitted, any `AC…` sid with a token works. */
1013
+ accounts?: Record<string, string>;
1014
+ /** Inbound SMS and voice webhooks to the app. */
1015
+ app?: TwilioAppWebhooks;
1016
+ /** Delay before each webhook attempt. Default `[0]`: Twilio does not retry these. */
1017
+ retryDelaysMs?: readonly number[];
1018
+ /** Sends webhooks (tests pass an in-process receiver). Default global `fetch`. */
1019
+ fetch?: (request: Request) => Promise<Response>;
1020
+ };
1021
+ type InboundSmsInput = {
1022
+ from: string;
1023
+ body: string;
1024
+ /** Default: the configured `callerId`. */
1025
+ to?: string;
1026
+ /** Media URLs (https) or `{url, contentType}`; makes the sid `MM…`. */
1027
+ media?: (string | {
1028
+ url: string;
1029
+ contentType?: string;
1030
+ })[];
1031
+ messageSid?: string;
1032
+ accountSid?: string;
1033
+ /** Extra form parameters, verbatim. */
1034
+ params?: Record<string, string>;
1035
+ };
1036
+ /** One delivery of an admin-triggered webhook, with what the app answered. */
1037
+ type DeliveryOutcome = {
1038
+ url: string;
1039
+ state: string;
1040
+ status: number | null;
1041
+ error: string | null;
1042
+ response: string | null;
1043
+ };
1044
+ type TwilioRuntime = ServiceRuntime<TwilioAPI> & {
1045
+ readonly webhooks: WebhookHub;
1046
+ /** Sign and post an inbound SMS to the app; resolves once delivered (or failed). */
1047
+ inboundSms(input: InboundSmsInput, namespace?: string): Promise<SentWebhook>;
1048
+ /** Sign and post a voice webhook (`twiml`, `disclosure`, `status`, `recording`). */
1049
+ voiceWebhook(kind: VoiceWebhookKind, params?: Record<string, string>, namespace?: string): Promise<SentWebhook>;
1050
+ };
1051
+ type SentWebhook = {
1052
+ params: Record<string, string>;
1053
+ deliveries: DeliveryOutcome[];
1054
+ };
1055
+ /**
1056
+ * The Twilio mock with Mockingbird's full service contract: `/health`, `/__admin/*`,
1057
+ * namespaces by header, by `/ns/<name>` prefix, or by AccountSid
1058
+ * (`PUT /__admin/credentials {"credentials": {"<AccountSid>": "<namespace>"}}`), clock
1059
+ * control, fault presets, an outbox, and signed inbound SMS and voice webhooks.
1060
+ */
1061
+ declare const createRuntime: (options?: TwilioRuntimeOptions) => TwilioRuntime;
1062
+
1063
+ declare const TWILIO_NAMESPACE = "twilio";
1064
+ /** The account sid used when a request carries an API key (`SK…`) instead of an account sid. */
1065
+ declare const DEFAULT_ACCOUNT_SID = "AC00000000000000000000000000000000";
1066
+ type TwilioAPIOptions = APIOptions & {
1067
+ /** Initial Verify settings for the namespace (fixed code, expiry, attempt limits). */
1068
+ verify?: Partial<VerifySettings>;
1069
+ /**
1070
+ * Accepted `AccountSid → AuthToken` pairs. Omitted: any `AC…`/`SK…` username with a
1071
+ * non-empty password authenticates (Twilio's test credentials included).
1072
+ */
1073
+ accounts?: Record<string, string>;
1074
+ };
1075
+ /** Twilio's JSON error body, `{code, message, more_info, status}`, with `X-Twilio-Error-Code`. */
1076
+ declare const twilioError: (status: number, code: number, message: string) => Response;
1077
+ type LatestVerification = {
1078
+ sid: string;
1079
+ code: string;
1080
+ status: VerificationRecord["status"];
1081
+ to: string;
1082
+ channel: string;
1083
+ serviceSid: string;
1084
+ attempts: number;
1085
+ sendAttempts: number;
1086
+ createdAt: string;
1087
+ expiresAt: string;
1088
+ };
1089
+ type PutRecordingInput = {
1090
+ /** WAV bytes; omitted means a synthesised 16-bit 8 kHz PCM recording. */
1091
+ wav?: Uint8Array;
1092
+ /** For a synthesised recording. Default 2 (a dual-channel call recording). */
1093
+ channels?: number;
1094
+ seconds?: number;
1095
+ accountSid?: string;
1096
+ callSid?: string;
1097
+ };
1098
+ /**
1099
+ * Stateful mock of Twilio Lookup v2, Verify v2, Programmable Messaging and call Recordings,
1100
+ * with each product routed by its host carried as a path prefix (`/lookups`, `/verify`,
1101
+ * `/api`).
1102
+ */
1103
+ declare class TwilioAPI implements FetchAPI$1 {
1104
+ readonly app: Hono;
1105
+ readonly sqlite: SqliteClient;
1106
+ readonly state: TwilioState;
1107
+ private readonly service;
1108
+ private readonly now;
1109
+ private readonly accounts;
1110
+ constructor(options?: TwilioAPIOptions);
1111
+ fetch(request: Request): Promise<Response>;
1112
+ reset(): Promise<void>;
1113
+ private authenticate;
1114
+ /** The account a request acts for: the path's, else the Basic username when it is one. */
1115
+ private accountOf;
1116
+ private requireAccount;
1117
+ /** Lookup validity, with any `PUT /__admin/lookups/:e164` override applied. */
1118
+ resolveLookup(raw: string, countryCode?: string): LookupResult;
1119
+ private fetchPhoneNumber;
1120
+ private requireService;
1121
+ /** The verification as of now: a pending one past its expiry becomes `expired`. */
1122
+ private current;
1123
+ private verificationBody;
1124
+ /** `To` as Verify accepts it: an email for the email channel, else a valid E.164 number. */
1125
+ private verifyRecipient;
1126
+ private createVerification;
1127
+ private findVerification;
1128
+ private fetchVerification;
1129
+ private updateVerification;
1130
+ private createVerificationCheck;
1131
+ private createMessage;
1132
+ private fetchMessage;
1133
+ private findRecording;
1134
+ private fetchRecordingMedia;
1135
+ private recordingBody;
1136
+ private fetchRecording;
1137
+ private deleteRecording;
1138
+ /** The newest verification to a number (what `GET /__admin/verify/:e164/latest` answers). */
1139
+ latestVerification(to: string): LatestVerification | undefined;
1140
+ setLookup(e164: string, override: LookupOverride): void;
1141
+ /** Store (or synthesise) a recording so `GET …/Recordings/{sid}.wav` serves it. */
1142
+ putRecording(sid: string, input?: PutRecordingInput): RecordingRecord;
1143
+ outbox(): TwilioOutboxItem[];
1144
+ messages(): MessageRecord[];
1145
+ }
1146
+
1147
+ export { DEFAULT_ACCOUNT_SID, DEFAULT_VERIFY_SETTINGS, TWILIO_NAMESPACE, TWILIO_PRESETS, TWILIO_PRODUCTS, TWILIO_WEBHOOK_EVENTS, TwilioAPI, createRuntime, document, e164Key, lookup, mixDownToMono, operationIds, readWav, supportedOperationIds, synthesizeWav, twilioError, twilioMockUrl };
1148
+ export type { FetchAPI$1 as FetchAPI, InboundSmsInput, LatestVerification, LookupOverride, LookupResult, MessageRecord, OperationId, PutRecordingInput, RecordingRecord, SqliteClient, SupportedOperationId, TwilioAPIOptions, TwilioAppWebhooks, TwilioOutboxItem, TwilioRuntime, TwilioRuntimeOptions, ValidationError, VerificationRecord, VerificationStatus, VerifySettings, VoiceWebhookKind, WavFormat };