@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 +8 -2
- package/DISCOVERY.md +23 -0
- package/README.md +50 -23
- package/dist/chunk-55BRX56F.js +10232 -0
- package/dist/chunk-55BRX56F.js.map +7 -0
- package/dist/{chunk-M73LWCCP.js → chunk-6Z2MR3PO.js} +33 -3
- package/dist/{chunk-M73LWCCP.js.map → chunk-6Z2MR3PO.js.map} +2 -2
- package/dist/{chunk-JGQUWBT2.js → chunk-PTLAPOYJ.js} +136 -25
- package/dist/chunk-PTLAPOYJ.js.map +7 -0
- package/dist/cli.js +3 -3
- package/dist/crypto-II2ETGQQ.js +21 -0
- package/dist/{helpers-BMHFVPFA.js → helpers-5D4ROPWG.js} +2 -2
- package/dist/index.d.ts +345 -41
- package/dist/index.js +2 -2
- package/dist/server.d.ts +684 -81
- package/dist/server.js +3 -3
- package/package.json +3 -2
- package/dist/chunk-JGQUWBT2.js.map +0 -7
- package/dist/chunk-SOEDG3O2.js +0 -8427
- package/dist/chunk-SOEDG3O2.js.map +0 -7
- package/dist/crypto-I5AVO7Q3.js +0 -15
- /package/dist/{crypto-I5AVO7Q3.js.map → crypto-II2ETGQQ.js.map} +0 -0
- /package/dist/{helpers-BMHFVPFA.js.map → helpers-5D4ROPWG.js.map} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -123,6 +123,11 @@ type ProviderOptions = APIOptions$1 & {
|
|
|
123
123
|
fallbackUser?: AuthFallback;
|
|
124
124
|
publicNamespace?: string;
|
|
125
125
|
adminPrefix?: string;
|
|
126
|
+
/**
|
|
127
|
+
* A seeded stream of `[0, 1)` that ids and tokens are minted from, so a run replays from
|
|
128
|
+
* its seed. Default: the platform's randomness.
|
|
129
|
+
*/
|
|
130
|
+
random?: () => number;
|
|
126
131
|
};
|
|
127
132
|
|
|
128
133
|
type MountedAPI = FetchAPI & {
|
|
@@ -324,7 +329,7 @@ type ClockState = {
|
|
|
324
329
|
now: number;
|
|
325
330
|
/** True while time does not advance on its own. */
|
|
326
331
|
frozen: boolean;
|
|
327
|
-
/** Milliseconds
|
|
332
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
328
333
|
offsetMs: number;
|
|
329
334
|
};
|
|
330
335
|
type Clock = {
|
|
@@ -360,7 +365,10 @@ type Rng = {
|
|
|
360
365
|
state(): number;
|
|
361
366
|
/** Restore a state previously returned by {@link state}. */
|
|
362
367
|
setState(state: number): void;
|
|
363
|
-
seed
|
|
368
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
369
|
+
reseed(seed: number | string): void;
|
|
370
|
+
/** The seed the stream currently starts from. */
|
|
371
|
+
readonly seed: number;
|
|
364
372
|
};
|
|
365
373
|
|
|
366
374
|
/**
|
|
@@ -369,44 +377,83 @@ type Rng = {
|
|
|
369
377
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
370
378
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
371
379
|
* appears under load, the 5xx that proves a retry path works.
|
|
380
|
+
*
|
|
381
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
382
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
383
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
372
384
|
*/
|
|
373
385
|
type FaultRule = {
|
|
374
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
386
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
375
387
|
id: string;
|
|
376
388
|
/** Fault only this operation. Omit to match every operation. */
|
|
377
389
|
operationId?: string;
|
|
378
390
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
379
391
|
method?: string;
|
|
392
|
+
/** Fault only this exact path. */
|
|
393
|
+
path?: string;
|
|
380
394
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
381
395
|
pathPrefix?: string;
|
|
396
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
397
|
+
pathPattern?: string;
|
|
398
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
399
|
+
requestHeaders?: Record<string, string>;
|
|
400
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
401
|
+
query?: Record<string, string>;
|
|
382
402
|
/**
|
|
383
403
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
384
404
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
385
405
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
386
406
|
*/
|
|
387
407
|
namespace?: string;
|
|
408
|
+
/** Let this many matching requests through first. */
|
|
409
|
+
after?: number;
|
|
410
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
411
|
+
every?: number;
|
|
412
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
413
|
+
count?: number;
|
|
414
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
415
|
+
rate?: number;
|
|
388
416
|
/**
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
|
|
417
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
418
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
419
|
+
*/
|
|
420
|
+
from?: Instant | Duration;
|
|
421
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
422
|
+
until?: Instant | Duration;
|
|
423
|
+
/**
|
|
424
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
425
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
392
426
|
*/
|
|
393
427
|
status?: number;
|
|
394
428
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
395
429
|
body?: unknown;
|
|
430
|
+
/** Response headers. */
|
|
396
431
|
headers?: Record<string, string>;
|
|
397
|
-
/**
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
rate?: number;
|
|
401
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
432
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
433
|
+
delay?: Duration;
|
|
434
|
+
/** `delay`, in milliseconds. */
|
|
402
435
|
delayMs?: number;
|
|
403
436
|
/** Alias of `delayMs`. */
|
|
404
437
|
latencyMs?: number;
|
|
438
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
439
|
+
jitter?: Duration;
|
|
440
|
+
jitterMs?: number;
|
|
441
|
+
/**
|
|
442
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
443
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
444
|
+
*/
|
|
445
|
+
timeout?: Duration;
|
|
446
|
+
timeoutMs?: number;
|
|
405
447
|
/**
|
|
406
448
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
407
449
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
408
450
|
*/
|
|
409
451
|
drop?: boolean;
|
|
452
|
+
/**
|
|
453
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
454
|
+
* the connection dies mid-body.
|
|
455
|
+
*/
|
|
456
|
+
truncate?: number;
|
|
410
457
|
/**
|
|
411
458
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
412
459
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -415,8 +462,8 @@ type FaultRule = {
|
|
|
415
462
|
effect?: string;
|
|
416
463
|
/** Parameters for `effect`. */
|
|
417
464
|
params?: Record<string, unknown>;
|
|
418
|
-
/**
|
|
419
|
-
|
|
465
|
+
/** The preset this rule was expanded from, if any. */
|
|
466
|
+
fromPreset?: string;
|
|
420
467
|
};
|
|
421
468
|
/** A fault that fired for one request. */
|
|
422
469
|
type FaultHit = {
|
|
@@ -424,6 +471,10 @@ type FaultHit = {
|
|
|
424
471
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
425
472
|
response?: Response;
|
|
426
473
|
drop?: boolean;
|
|
474
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
475
|
+
timeout?: boolean;
|
|
476
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
477
|
+
truncate?: number;
|
|
427
478
|
effect?: {
|
|
428
479
|
name: string;
|
|
429
480
|
params: Record<string, unknown>;
|
|
@@ -448,38 +499,200 @@ type FaultCandidate = {
|
|
|
448
499
|
method: string;
|
|
449
500
|
path: string;
|
|
450
501
|
namespace: string;
|
|
502
|
+
/** Request headers and query, for rules that match on them. */
|
|
503
|
+
headers?: Headers;
|
|
504
|
+
query?: URLSearchParams;
|
|
505
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
506
|
+
now?: number;
|
|
507
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
508
|
+
wait?: (ms: number) => Promise<void>;
|
|
509
|
+
};
|
|
510
|
+
/** A stored rule and how often it was consulted. */
|
|
511
|
+
type FaultListing = FaultRule & {
|
|
512
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
513
|
+
remaining: number | null;
|
|
514
|
+
/** Times the rule faulted a request. */
|
|
515
|
+
hits: number;
|
|
516
|
+
/** Requests that matched the rule, faulted or not. */
|
|
517
|
+
seen: number;
|
|
518
|
+
};
|
|
519
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
520
|
+
type FaultSnapshot = {
|
|
521
|
+
/**
|
|
522
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
523
|
+
* in the order means to a request and holds in any process.
|
|
524
|
+
*/
|
|
525
|
+
rules: (FaultListing & {
|
|
526
|
+
position?: number;
|
|
527
|
+
})[];
|
|
528
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
529
|
+
nextId?: number;
|
|
451
530
|
};
|
|
452
531
|
type FaultRegistry = {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
rules: (FaultRule & {
|
|
456
|
-
remaining: number | null;
|
|
457
|
-
hits: number;
|
|
458
|
-
position: number;
|
|
459
|
-
})[];
|
|
460
|
-
rngState: number;
|
|
461
|
-
};
|
|
532
|
+
snapshot(namespace: string): FaultSnapshot;
|
|
533
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
462
534
|
add(rule: FaultRule): FaultRule;
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
})[];
|
|
475
|
-
rngState: number;
|
|
476
|
-
}): void;
|
|
535
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
536
|
+
nextId(namespace: string): string;
|
|
537
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
538
|
+
list(namespace?: string): FaultListing[];
|
|
539
|
+
get(id: string, namespace?: string): FaultListing | undefined;
|
|
540
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
541
|
+
remove(id: string, namespace?: string): boolean;
|
|
542
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
543
|
+
clear(namespace?: string): void;
|
|
544
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
545
|
+
restore(namespace: string, state: FaultSnapshot): void;
|
|
477
546
|
/**
|
|
478
547
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
479
548
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
480
549
|
* each matching rule's remaining uses.
|
|
481
550
|
*/
|
|
482
551
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
552
|
+
/**
|
|
553
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
554
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
555
|
+
*/
|
|
556
|
+
fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* The admin controls every mock shares, as one document.
|
|
561
|
+
*
|
|
562
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
563
|
+
*
|
|
564
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
565
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
566
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
567
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
568
|
+
*
|
|
569
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
570
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
571
|
+
*/
|
|
572
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
573
|
+
type Duration = number | string;
|
|
574
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
575
|
+
type Instant = number | string;
|
|
576
|
+
type ClockControls = {
|
|
577
|
+
/** Move the clock to this instant. */
|
|
578
|
+
now?: Instant;
|
|
579
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
580
|
+
frozen?: boolean;
|
|
581
|
+
/**
|
|
582
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
583
|
+
* each request still gets its own, reproducible timestamp.
|
|
584
|
+
*/
|
|
585
|
+
autoAdvance?: Duration;
|
|
586
|
+
};
|
|
587
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
588
|
+
type LatencyRuleInput = {
|
|
589
|
+
delay?: Duration;
|
|
590
|
+
jitter?: Duration;
|
|
591
|
+
};
|
|
592
|
+
type LatencyControls = LatencyRuleInput & {
|
|
593
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
594
|
+
operations?: Record<string, Duration | LatencyRuleInput>;
|
|
595
|
+
};
|
|
596
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
597
|
+
type FaultInput = (Omit<FaultRule, "id"> & {
|
|
598
|
+
id?: string;
|
|
599
|
+
}) | ({
|
|
600
|
+
preset: string;
|
|
601
|
+
} & Partial<FaultRule>);
|
|
602
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
603
|
+
declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
|
|
604
|
+
/**
|
|
605
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
606
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
607
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
608
|
+
*/
|
|
609
|
+
type SnapshotDocument = {
|
|
610
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
611
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
612
|
+
service?: string;
|
|
613
|
+
/**
|
|
614
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
615
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
616
|
+
*/
|
|
617
|
+
records: {
|
|
618
|
+
collection: string;
|
|
619
|
+
id: string;
|
|
620
|
+
seq?: number;
|
|
621
|
+
value?: unknown;
|
|
622
|
+
raw?: string;
|
|
623
|
+
}[];
|
|
624
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
625
|
+
sequences?: {
|
|
626
|
+
name: string;
|
|
627
|
+
kind: string;
|
|
628
|
+
value: number;
|
|
629
|
+
}[];
|
|
630
|
+
clock?: {
|
|
631
|
+
now: number;
|
|
632
|
+
frozen: boolean;
|
|
633
|
+
autoAdvanceMs?: number;
|
|
634
|
+
};
|
|
635
|
+
seed?: number | string;
|
|
636
|
+
/** Positions of the seeded random streams. */
|
|
637
|
+
rng?: {
|
|
638
|
+
state: number;
|
|
639
|
+
faults?: number;
|
|
640
|
+
latency?: number;
|
|
641
|
+
};
|
|
642
|
+
faults?: unknown;
|
|
643
|
+
latency?: unknown;
|
|
644
|
+
virtualTime?: boolean;
|
|
645
|
+
};
|
|
646
|
+
/** Controls for one namespace. */
|
|
647
|
+
type NamespaceControls = {
|
|
648
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
649
|
+
seed?: number | string;
|
|
650
|
+
clock?: ClockControls;
|
|
651
|
+
/**
|
|
652
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
653
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
654
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
655
|
+
*/
|
|
656
|
+
virtualTime?: boolean;
|
|
657
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
658
|
+
latency?: Duration | LatencyControls;
|
|
659
|
+
faults?: readonly FaultInput[];
|
|
660
|
+
/** Start from this state instead of the service's own seed data. */
|
|
661
|
+
snapshot?: SnapshotDocument;
|
|
662
|
+
};
|
|
663
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
664
|
+
type MockControls = NamespaceControls & {
|
|
665
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
666
|
+
credentials?: Record<string, string>;
|
|
667
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
668
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
669
|
+
};
|
|
670
|
+
/** A latency rule in milliseconds. */
|
|
671
|
+
type LatencyRule = {
|
|
672
|
+
delayMs: number;
|
|
673
|
+
jitterMs: number;
|
|
674
|
+
};
|
|
675
|
+
/** Baseline latency for a namespace, normalized. */
|
|
676
|
+
type LatencyState = LatencyRule & {
|
|
677
|
+
operations: Record<string, LatencyRule>;
|
|
678
|
+
};
|
|
679
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
680
|
+
type ControlHeaderInput = {
|
|
681
|
+
namespace?: string;
|
|
682
|
+
adminKey?: string;
|
|
683
|
+
branch?: string;
|
|
684
|
+
at?: string;
|
|
685
|
+
reset?: boolean;
|
|
686
|
+
restore?: string;
|
|
687
|
+
seed?: number | string;
|
|
688
|
+
time?: Instant | Date;
|
|
689
|
+
advance?: Duration;
|
|
690
|
+
virtualTime?: boolean;
|
|
691
|
+
delay?: Duration;
|
|
692
|
+
timeout?: Duration;
|
|
693
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
694
|
+
fault?: number | string | Record<string, unknown>;
|
|
695
|
+
snapshot?: string;
|
|
483
696
|
};
|
|
484
697
|
|
|
485
698
|
/**
|
|
@@ -519,6 +732,8 @@ type RequestLog = {
|
|
|
519
732
|
unmatched: boolean;
|
|
520
733
|
/** Set when a fault rule produced the response. */
|
|
521
734
|
faultId?: string;
|
|
735
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
736
|
+
delayMs?: number;
|
|
522
737
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
523
738
|
ids?: Record<string, string>;
|
|
524
739
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -564,6 +779,12 @@ type JournalQuery = {
|
|
|
564
779
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
565
780
|
namespace?: string;
|
|
566
781
|
operationId?: string;
|
|
782
|
+
/** Only this HTTP method, case-insensitive. */
|
|
783
|
+
method?: string;
|
|
784
|
+
/** Only this exact path. */
|
|
785
|
+
path?: string;
|
|
786
|
+
/** Only requests this fault rule answered or shaped. */
|
|
787
|
+
faultId?: string;
|
|
567
788
|
status?: number;
|
|
568
789
|
/** Only entries at or after this instant (epoch ms). */
|
|
569
790
|
since?: number;
|
|
@@ -578,6 +799,50 @@ type Journal = {
|
|
|
578
799
|
clear(namespace?: string): void;
|
|
579
800
|
};
|
|
580
801
|
|
|
802
|
+
/**
|
|
803
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
804
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
805
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
806
|
+
* fault hits.
|
|
807
|
+
*/
|
|
808
|
+
type LatencyRegistry = {
|
|
809
|
+
get(namespace: string): LatencyState;
|
|
810
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
811
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
812
|
+
clear(namespace?: string): void;
|
|
813
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
814
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
/** Clock state as the admin API reports it. */
|
|
818
|
+
type ControlClock = ClockState & {
|
|
819
|
+
/** `now`, as ISO-8601. */
|
|
820
|
+
iso: string;
|
|
821
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
822
|
+
autoAdvanceMs: number;
|
|
823
|
+
};
|
|
824
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
825
|
+
type ControlState = {
|
|
826
|
+
namespace: string;
|
|
827
|
+
seed: number | string;
|
|
828
|
+
clock: ControlClock;
|
|
829
|
+
virtualTime: boolean;
|
|
830
|
+
latency: LatencyState;
|
|
831
|
+
faults: FaultListing[];
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
835
|
+
type SnapshotInfo = {
|
|
836
|
+
id: string;
|
|
837
|
+
namespace: string;
|
|
838
|
+
/** Stored rows in the snapshot. */
|
|
839
|
+
records: number;
|
|
840
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
841
|
+
at: number;
|
|
842
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
843
|
+
portable: boolean;
|
|
844
|
+
};
|
|
845
|
+
|
|
581
846
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
582
847
|
type CredentialRegistry = {
|
|
583
848
|
set(credential: string, namespace: string): void;
|
|
@@ -732,7 +997,10 @@ type ServiceInstance = FetchAPI & {
|
|
|
732
997
|
};
|
|
733
998
|
type ServiceTimelineState = Readonly<{
|
|
734
999
|
snapshot: NamespaceSnapshot;
|
|
735
|
-
clock
|
|
1000
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
1001
|
+
clock: Readonly<ClockState & {
|
|
1002
|
+
pinned?: boolean;
|
|
1003
|
+
}>;
|
|
736
1004
|
rngState: number;
|
|
737
1005
|
}>;
|
|
738
1006
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -745,14 +1013,18 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
745
1013
|
readonly sqlite: SqliteClient$1;
|
|
746
1014
|
readonly clock: Clock;
|
|
747
1015
|
readonly faults: FaultRegistry;
|
|
1016
|
+
/** Baseline response time per namespace. */
|
|
1017
|
+
readonly latency: LatencyRegistry;
|
|
748
1018
|
readonly metrics: Metrics;
|
|
749
1019
|
readonly journal: Journal;
|
|
750
1020
|
readonly rng: Rng;
|
|
751
1021
|
readonly credentials: CredentialRegistry;
|
|
752
1022
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
753
1023
|
readonly webhooks: WebhookHub | undefined;
|
|
754
|
-
/**
|
|
755
|
-
|
|
1024
|
+
/**
|
|
1025
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
1026
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
1027
|
+
*/
|
|
756
1028
|
namespaceClock(namespace?: string): Clock;
|
|
757
1029
|
namespaceOf(request: Request): string;
|
|
758
1030
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
@@ -764,8 +1036,38 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
764
1036
|
instance(namespace?: string): T;
|
|
765
1037
|
/** Public names of every namespace created so far. */
|
|
766
1038
|
namespaces(): string[];
|
|
767
|
-
/**
|
|
1039
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
768
1040
|
reset(namespace?: string): Promise<void>;
|
|
1041
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
1042
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
1043
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
1044
|
+
controls(namespace?: string): ControlState & {
|
|
1045
|
+
snapshots: SnapshotInfo[];
|
|
1046
|
+
};
|
|
1047
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
1048
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
1049
|
+
snapshots: SnapshotInfo[];
|
|
1050
|
+
};
|
|
1051
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
1052
|
+
readonly snapshots: {
|
|
1053
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
1054
|
+
create(options?: {
|
|
1055
|
+
name?: string;
|
|
1056
|
+
namespace?: string;
|
|
1057
|
+
}): SnapshotInfo;
|
|
1058
|
+
list(namespace?: string): SnapshotInfo[];
|
|
1059
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
1060
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
1061
|
+
/** Store a document as a snapshot without restoring it. */
|
|
1062
|
+
import(document: SnapshotDocument, options?: {
|
|
1063
|
+
name?: string;
|
|
1064
|
+
namespace?: string;
|
|
1065
|
+
}): SnapshotInfo;
|
|
1066
|
+
restore(id: string, namespace?: string): void;
|
|
1067
|
+
delete(id: string, namespace?: string): boolean;
|
|
1068
|
+
};
|
|
1069
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
1070
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
769
1071
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
770
1072
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
771
1073
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -1236,6 +1538,8 @@ type TwilioRuntimeOptions = Pick<TwilioAPIOptions, "fixtures" | "baseUrl" | "tok
|
|
|
1236
1538
|
seed?: number | string;
|
|
1237
1539
|
adminPrefix?: string;
|
|
1238
1540
|
adminKey?: string;
|
|
1541
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
1542
|
+
adminControls?: MockControls;
|
|
1239
1543
|
onLog?: (entry: RequestLog) => void;
|
|
1240
1544
|
/** Initial Verify settings for every namespace (e.g. `{fixedCode: "000000"}`). */
|
|
1241
1545
|
verify?: Partial<VerifySettings>;
|
|
@@ -1293,7 +1597,7 @@ declare const createRuntime: (options?: TwilioRuntimeOptions) => TwilioRuntime;
|
|
|
1293
1597
|
declare const TWILIO_NAMESPACE = "twilio";
|
|
1294
1598
|
/** The account sid used when a request carries an API key (`SK…`) instead of an account sid. */
|
|
1295
1599
|
declare const DEFAULT_ACCOUNT_SID = "AC00000000000000000000000000000000";
|
|
1296
|
-
type TwilioAPIOptions = APIOptions & Pick<ProviderOptions, "tokens" | "baseUrl" | "publicNamespace" | "adminPrefix"> & {
|
|
1600
|
+
type TwilioAPIOptions = APIOptions & Pick<ProviderOptions, "tokens" | "baseUrl" | "publicNamespace" | "adminPrefix" | "random"> & {
|
|
1297
1601
|
fixtures?: TwilioSeedConfig;
|
|
1298
1602
|
/** Initial Verify settings for the namespace (fixed code, expiry, attempt limits). */
|
|
1299
1603
|
verify?: Partial<VerifySettings>;
|
package/dist/index.js
CHANGED