@crvouga/mockingbird-service-resend 3.2.0 → 3.4.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 +18 -4
- package/DISCOVERY.md +23 -0
- package/README.md +17 -7
- 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-KPX5JPKL.js +8720 -0
- package/dist/chunk-KPX5JPKL.js.map +7 -0
- package/dist/chunk-ZB42MLNS.js +4835 -0
- package/dist/chunk-ZB42MLNS.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 +362 -42
- package/dist/index.js +2 -2
- package/dist/server.d.ts +717 -83
- package/dist/server.js +3 -3
- package/package.json +3 -2
- package/dist/chunk-WMQIKI4U.js +0 -915
- package/dist/chunk-WMQIKI4U.js.map +0 -7
- package/dist/chunk-XQ4BQDIK.js +0 -6736
- package/dist/chunk-XQ4BQDIK.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/cli.js
CHANGED
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
runCli,
|
|
4
4
|
serveCommand,
|
|
5
5
|
serveTarget
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-ZB42MLNS.js";
|
|
7
|
+
import "./chunk-KPX5JPKL.js";
|
|
8
|
+
import "./chunk-6Z2MR3PO.js";
|
|
9
9
|
|
|
10
10
|
// src/cli.ts
|
|
11
11
|
var code = await runCli(
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createHash,
|
|
3
|
+
createHmac,
|
|
4
|
+
random,
|
|
5
|
+
randomBytes,
|
|
6
|
+
randomUUID,
|
|
7
|
+
timingSafeEqual,
|
|
8
|
+
useRandom,
|
|
9
|
+
withRandom
|
|
10
|
+
} from "./chunk-6Z2MR3PO.js";
|
|
11
|
+
export {
|
|
12
|
+
createHash,
|
|
13
|
+
createHmac,
|
|
14
|
+
random,
|
|
15
|
+
randomBytes,
|
|
16
|
+
randomUUID,
|
|
17
|
+
timingSafeEqual,
|
|
18
|
+
useRandom,
|
|
19
|
+
withRandom
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=crypto-II2ETGQQ.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
randomUUID
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6Z2MR3PO.js";
|
|
4
4
|
|
|
5
5
|
// ../../http/provider/dist/vendor/clerk/helpers.js
|
|
6
6
|
function generateClerkId(prefix) {
|
|
@@ -83,4 +83,4 @@ export {
|
|
|
83
83
|
userDisplayName
|
|
84
84
|
};
|
|
85
85
|
/*! Adapted from vercel-labs/emulate (Apache-2.0), modified for Mockingbird. See port.json, LICENSE_EMULATE and THIRD_PARTY_NOTICES.md. */
|
|
86
|
-
//# sourceMappingURL=helpers-
|
|
86
|
+
//# sourceMappingURL=helpers-5D4ROPWG.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -93,6 +93,11 @@ type ProviderOptions = APIOptions$1 & {
|
|
|
93
93
|
fallbackUser?: AuthFallback;
|
|
94
94
|
publicNamespace?: string;
|
|
95
95
|
adminPrefix?: string;
|
|
96
|
+
/**
|
|
97
|
+
* A seeded stream of `[0, 1)` that ids and tokens are minted from, so a run replays from
|
|
98
|
+
* its seed. Default: the platform's randomness.
|
|
99
|
+
*/
|
|
100
|
+
random?: () => number;
|
|
96
101
|
};
|
|
97
102
|
|
|
98
103
|
type MountedAPI = FetchAPI & {
|
|
@@ -294,7 +299,7 @@ type ClockState = {
|
|
|
294
299
|
now: number;
|
|
295
300
|
/** True while time does not advance on its own. */
|
|
296
301
|
frozen: boolean;
|
|
297
|
-
/** Milliseconds
|
|
302
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
298
303
|
offsetMs: number;
|
|
299
304
|
};
|
|
300
305
|
type Clock = {
|
|
@@ -330,7 +335,10 @@ type Rng = {
|
|
|
330
335
|
state(): number;
|
|
331
336
|
/** Restore a state previously returned by {@link state}. */
|
|
332
337
|
setState(state: number): void;
|
|
333
|
-
seed
|
|
338
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
339
|
+
reseed(seed: number | string): void;
|
|
340
|
+
/** The seed the stream currently starts from. */
|
|
341
|
+
readonly seed: number;
|
|
334
342
|
};
|
|
335
343
|
|
|
336
344
|
/**
|
|
@@ -339,44 +347,83 @@ type Rng = {
|
|
|
339
347
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
340
348
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
341
349
|
* appears under load, the 5xx that proves a retry path works.
|
|
350
|
+
*
|
|
351
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
352
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
353
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
342
354
|
*/
|
|
343
355
|
type FaultRule = {
|
|
344
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
356
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
345
357
|
id: string;
|
|
346
358
|
/** Fault only this operation. Omit to match every operation. */
|
|
347
359
|
operationId?: string;
|
|
348
360
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
349
361
|
method?: string;
|
|
362
|
+
/** Fault only this exact path. */
|
|
363
|
+
path?: string;
|
|
350
364
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
351
365
|
pathPrefix?: string;
|
|
366
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
367
|
+
pathPattern?: string;
|
|
368
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
369
|
+
requestHeaders?: Record<string, string>;
|
|
370
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
371
|
+
query?: Record<string, string>;
|
|
352
372
|
/**
|
|
353
373
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
354
374
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
355
375
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
356
376
|
*/
|
|
357
377
|
namespace?: string;
|
|
378
|
+
/** Let this many matching requests through first. */
|
|
379
|
+
after?: number;
|
|
380
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
381
|
+
every?: number;
|
|
382
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
383
|
+
count?: number;
|
|
384
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
385
|
+
rate?: number;
|
|
358
386
|
/**
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
|
|
387
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
388
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
389
|
+
*/
|
|
390
|
+
from?: Instant | Duration;
|
|
391
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
392
|
+
until?: Instant | Duration;
|
|
393
|
+
/**
|
|
394
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
395
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
362
396
|
*/
|
|
363
397
|
status?: number;
|
|
364
398
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
365
399
|
body?: unknown;
|
|
400
|
+
/** Response headers. */
|
|
366
401
|
headers?: Record<string, string>;
|
|
367
|
-
/**
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
rate?: number;
|
|
371
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
402
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
403
|
+
delay?: Duration;
|
|
404
|
+
/** `delay`, in milliseconds. */
|
|
372
405
|
delayMs?: number;
|
|
373
406
|
/** Alias of `delayMs`. */
|
|
374
407
|
latencyMs?: number;
|
|
408
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
409
|
+
jitter?: Duration;
|
|
410
|
+
jitterMs?: number;
|
|
411
|
+
/**
|
|
412
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
413
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
414
|
+
*/
|
|
415
|
+
timeout?: Duration;
|
|
416
|
+
timeoutMs?: number;
|
|
375
417
|
/**
|
|
376
418
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
377
419
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
378
420
|
*/
|
|
379
421
|
drop?: boolean;
|
|
422
|
+
/**
|
|
423
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
424
|
+
* the connection dies mid-body.
|
|
425
|
+
*/
|
|
426
|
+
truncate?: number;
|
|
380
427
|
/**
|
|
381
428
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
382
429
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -385,8 +432,8 @@ type FaultRule = {
|
|
|
385
432
|
effect?: string;
|
|
386
433
|
/** Parameters for `effect`. */
|
|
387
434
|
params?: Record<string, unknown>;
|
|
388
|
-
/**
|
|
389
|
-
|
|
435
|
+
/** The preset this rule was expanded from, if any. */
|
|
436
|
+
fromPreset?: string;
|
|
390
437
|
};
|
|
391
438
|
/** A fault that fired for one request. */
|
|
392
439
|
type FaultHit = {
|
|
@@ -394,6 +441,10 @@ type FaultHit = {
|
|
|
394
441
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
395
442
|
response?: Response;
|
|
396
443
|
drop?: boolean;
|
|
444
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
445
|
+
timeout?: boolean;
|
|
446
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
447
|
+
truncate?: number;
|
|
397
448
|
effect?: {
|
|
398
449
|
name: string;
|
|
399
450
|
params: Record<string, unknown>;
|
|
@@ -418,38 +469,202 @@ type FaultCandidate = {
|
|
|
418
469
|
method: string;
|
|
419
470
|
path: string;
|
|
420
471
|
namespace: string;
|
|
472
|
+
/** Request headers and query, for rules that match on them. */
|
|
473
|
+
headers?: Headers;
|
|
474
|
+
query?: URLSearchParams;
|
|
475
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
476
|
+
now?: number;
|
|
477
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
478
|
+
wait?: (ms: number) => Promise<void>;
|
|
479
|
+
};
|
|
480
|
+
/** A stored rule and how often it was consulted. */
|
|
481
|
+
type FaultListing = FaultRule & {
|
|
482
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
483
|
+
remaining: number | null;
|
|
484
|
+
/** Times the rule faulted a request. */
|
|
485
|
+
hits: number;
|
|
486
|
+
/** Requests that matched the rule, faulted or not. */
|
|
487
|
+
seen: number;
|
|
488
|
+
};
|
|
489
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
490
|
+
type FaultSnapshot = {
|
|
491
|
+
/**
|
|
492
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
493
|
+
* in the order means to a request and holds in any process.
|
|
494
|
+
*/
|
|
495
|
+
rules: (FaultListing & {
|
|
496
|
+
position?: number;
|
|
497
|
+
})[];
|
|
498
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
499
|
+
nextId?: number;
|
|
421
500
|
};
|
|
422
501
|
type FaultRegistry = {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
rules: (FaultRule & {
|
|
426
|
-
remaining: number | null;
|
|
427
|
-
hits: number;
|
|
428
|
-
position: number;
|
|
429
|
-
})[];
|
|
430
|
-
rngState: number;
|
|
431
|
-
};
|
|
502
|
+
snapshot(namespace: string): FaultSnapshot;
|
|
503
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
432
504
|
add(rule: FaultRule): FaultRule;
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
})[];
|
|
445
|
-
rngState: number;
|
|
446
|
-
}): void;
|
|
505
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
506
|
+
nextId(namespace: string): string;
|
|
507
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
508
|
+
list(namespace?: string): FaultListing[];
|
|
509
|
+
get(id: string, namespace?: string): FaultListing | undefined;
|
|
510
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
511
|
+
remove(id: string, namespace?: string): boolean;
|
|
512
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
513
|
+
clear(namespace?: string): void;
|
|
514
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
515
|
+
restore(namespace: string, state: FaultSnapshot): void;
|
|
447
516
|
/**
|
|
448
517
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
449
518
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
450
519
|
* each matching rule's remaining uses.
|
|
451
520
|
*/
|
|
452
521
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
522
|
+
/**
|
|
523
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
524
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
525
|
+
*/
|
|
526
|
+
fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* The admin controls every mock shares, as one document.
|
|
531
|
+
*
|
|
532
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
533
|
+
*
|
|
534
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
535
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
536
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
537
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
538
|
+
*
|
|
539
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
540
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
541
|
+
*/
|
|
542
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
543
|
+
type Duration = number | string;
|
|
544
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
545
|
+
type Instant = number | string;
|
|
546
|
+
type ClockControls = {
|
|
547
|
+
/** Move the clock to this instant. */
|
|
548
|
+
now?: Instant;
|
|
549
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
550
|
+
frozen?: boolean;
|
|
551
|
+
/**
|
|
552
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
553
|
+
* each request still gets its own, reproducible timestamp.
|
|
554
|
+
*/
|
|
555
|
+
autoAdvance?: Duration;
|
|
556
|
+
};
|
|
557
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
558
|
+
type LatencyRuleInput = {
|
|
559
|
+
delay?: Duration;
|
|
560
|
+
jitter?: Duration;
|
|
561
|
+
};
|
|
562
|
+
type LatencyControls = LatencyRuleInput & {
|
|
563
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
564
|
+
operations?: Record<string, Duration | LatencyRuleInput>;
|
|
565
|
+
};
|
|
566
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
567
|
+
type FaultInput = (Omit<FaultRule, "id"> & {
|
|
568
|
+
id?: string;
|
|
569
|
+
}) | ({
|
|
570
|
+
preset: string;
|
|
571
|
+
} & Partial<FaultRule>);
|
|
572
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
573
|
+
declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
|
|
574
|
+
/**
|
|
575
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
576
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
577
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
578
|
+
*/
|
|
579
|
+
type SnapshotDocument = {
|
|
580
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
581
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
582
|
+
service?: string;
|
|
583
|
+
/**
|
|
584
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
585
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
586
|
+
*/
|
|
587
|
+
records: {
|
|
588
|
+
collection: string;
|
|
589
|
+
id: string;
|
|
590
|
+
seq?: number;
|
|
591
|
+
value?: unknown;
|
|
592
|
+
raw?: string;
|
|
593
|
+
}[];
|
|
594
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
595
|
+
sequences?: {
|
|
596
|
+
name: string;
|
|
597
|
+
kind: string;
|
|
598
|
+
value: number;
|
|
599
|
+
}[];
|
|
600
|
+
clock?: {
|
|
601
|
+
now: number;
|
|
602
|
+
frozen: boolean;
|
|
603
|
+
autoAdvanceMs?: number;
|
|
604
|
+
};
|
|
605
|
+
seed?: number | string;
|
|
606
|
+
/** Positions of the seeded random streams. */
|
|
607
|
+
rng?: {
|
|
608
|
+
state: number;
|
|
609
|
+
faults?: number;
|
|
610
|
+
latency?: number;
|
|
611
|
+
};
|
|
612
|
+
faults?: unknown;
|
|
613
|
+
latency?: unknown;
|
|
614
|
+
virtualTime?: boolean;
|
|
615
|
+
/** Quiescent webhook endpoints, delivery history and fault state. Contains private configuration. */
|
|
616
|
+
webhooks?: unknown;
|
|
617
|
+
};
|
|
618
|
+
/** Controls for one namespace. */
|
|
619
|
+
type NamespaceControls = {
|
|
620
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
621
|
+
seed?: number | string;
|
|
622
|
+
clock?: ClockControls;
|
|
623
|
+
/**
|
|
624
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
625
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
626
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
627
|
+
*/
|
|
628
|
+
virtualTime?: boolean;
|
|
629
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
630
|
+
latency?: Duration | LatencyControls;
|
|
631
|
+
faults?: readonly FaultInput[];
|
|
632
|
+
/** Start from this state instead of the service's own seed data. */
|
|
633
|
+
snapshot?: SnapshotDocument;
|
|
634
|
+
};
|
|
635
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
636
|
+
type MockControls = NamespaceControls & {
|
|
637
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
638
|
+
credentials?: Record<string, string>;
|
|
639
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
640
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
641
|
+
};
|
|
642
|
+
/** A latency rule in milliseconds. */
|
|
643
|
+
type LatencyRule = {
|
|
644
|
+
delayMs: number;
|
|
645
|
+
jitterMs: number;
|
|
646
|
+
};
|
|
647
|
+
/** Baseline latency for a namespace, normalized. */
|
|
648
|
+
type LatencyState = LatencyRule & {
|
|
649
|
+
operations: Record<string, LatencyRule>;
|
|
650
|
+
};
|
|
651
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
652
|
+
type ControlHeaderInput = {
|
|
653
|
+
namespace?: string;
|
|
654
|
+
adminKey?: string;
|
|
655
|
+
branch?: string;
|
|
656
|
+
at?: string;
|
|
657
|
+
reset?: boolean;
|
|
658
|
+
restore?: string;
|
|
659
|
+
seed?: number | string;
|
|
660
|
+
time?: Instant | Date;
|
|
661
|
+
advance?: Duration;
|
|
662
|
+
virtualTime?: boolean;
|
|
663
|
+
delay?: Duration;
|
|
664
|
+
timeout?: Duration;
|
|
665
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
666
|
+
fault?: number | string | Record<string, unknown>;
|
|
667
|
+
snapshot?: string;
|
|
453
668
|
};
|
|
454
669
|
|
|
455
670
|
/**
|
|
@@ -489,6 +704,8 @@ type RequestLog = {
|
|
|
489
704
|
unmatched: boolean;
|
|
490
705
|
/** Set when a fault rule produced the response. */
|
|
491
706
|
faultId?: string;
|
|
707
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
708
|
+
delayMs?: number;
|
|
492
709
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
493
710
|
ids?: Record<string, string>;
|
|
494
711
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -534,6 +751,12 @@ type JournalQuery = {
|
|
|
534
751
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
535
752
|
namespace?: string;
|
|
536
753
|
operationId?: string;
|
|
754
|
+
/** Only this HTTP method, case-insensitive. */
|
|
755
|
+
method?: string;
|
|
756
|
+
/** Only this exact path. */
|
|
757
|
+
path?: string;
|
|
758
|
+
/** Only requests this fault rule answered or shaped. */
|
|
759
|
+
faultId?: string;
|
|
537
760
|
status?: number;
|
|
538
761
|
/** Only entries at or after this instant (epoch ms). */
|
|
539
762
|
since?: number;
|
|
@@ -548,6 +771,50 @@ type Journal = {
|
|
|
548
771
|
clear(namespace?: string): void;
|
|
549
772
|
};
|
|
550
773
|
|
|
774
|
+
/**
|
|
775
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
776
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
777
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
778
|
+
* fault hits.
|
|
779
|
+
*/
|
|
780
|
+
type LatencyRegistry = {
|
|
781
|
+
get(namespace: string): LatencyState;
|
|
782
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
783
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
784
|
+
clear(namespace?: string): void;
|
|
785
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
786
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
/** Clock state as the admin API reports it. */
|
|
790
|
+
type ControlClock = ClockState & {
|
|
791
|
+
/** `now`, as ISO-8601. */
|
|
792
|
+
iso: string;
|
|
793
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
794
|
+
autoAdvanceMs: number;
|
|
795
|
+
};
|
|
796
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
797
|
+
type ControlState = {
|
|
798
|
+
namespace: string;
|
|
799
|
+
seed: number | string;
|
|
800
|
+
clock: ControlClock;
|
|
801
|
+
virtualTime: boolean;
|
|
802
|
+
latency: LatencyState;
|
|
803
|
+
faults: FaultListing[];
|
|
804
|
+
};
|
|
805
|
+
|
|
806
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
807
|
+
type SnapshotInfo = {
|
|
808
|
+
id: string;
|
|
809
|
+
namespace: string;
|
|
810
|
+
/** Stored rows in the snapshot. */
|
|
811
|
+
records: number;
|
|
812
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
813
|
+
at: number;
|
|
814
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
815
|
+
portable: boolean;
|
|
816
|
+
};
|
|
817
|
+
|
|
551
818
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
552
819
|
type CredentialRegistry = {
|
|
553
820
|
set(credential: string, namespace: string): void;
|
|
@@ -578,6 +845,8 @@ declare class IdempotencyStore {
|
|
|
578
845
|
run(key: string, fingerprint: string, errors: IdempotencyErrors, handler: () => Promise<Response> | Response, replayable?: (status: number) => boolean): Promise<Response>;
|
|
579
846
|
}
|
|
580
847
|
|
|
848
|
+
type OwnedTransport = (request: Request, namespace: string, send: typeof fetch) => Promise<Response>;
|
|
849
|
+
|
|
581
850
|
/**
|
|
582
851
|
* A point-in-time copy of everything a service namespace holds.
|
|
583
852
|
*
|
|
@@ -695,8 +964,16 @@ type PublishInput = {
|
|
|
695
964
|
id?: string;
|
|
696
965
|
};
|
|
697
966
|
type WebhookHub = {
|
|
967
|
+
observeDeliveries(listener: (event: {
|
|
968
|
+
namespace: string;
|
|
969
|
+
state: string;
|
|
970
|
+
deliveryId: string;
|
|
971
|
+
}) => void): () => void;
|
|
972
|
+
setTransportPolicy(policy: OwnedTransport): void;
|
|
698
973
|
pending(namespace: string): number;
|
|
699
974
|
snapshot(namespace: string): unknown;
|
|
975
|
+
exportSnapshot(handle: unknown): unknown;
|
|
976
|
+
importSnapshot(namespace: string, document: unknown): unknown;
|
|
700
977
|
restore(namespace: string, snapshot: unknown): void;
|
|
701
978
|
publish(input: PublishInput): WebhookMessage;
|
|
702
979
|
/** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
|
|
@@ -709,7 +986,7 @@ type WebhookHub = {
|
|
|
709
986
|
/** Run every pending retry (and release held reordered messages) now, and every retry those attempts schedule, until nothing is pending. */
|
|
710
987
|
flush(): Promise<void>;
|
|
711
988
|
/** Resolve once nothing is in flight. */
|
|
712
|
-
idle(): Promise<void>;
|
|
989
|
+
idle(namespace?: string): Promise<void>;
|
|
713
990
|
fault(namespace: string, fault: WebhookFault): void;
|
|
714
991
|
clear(namespace?: string): void;
|
|
715
992
|
};
|
|
@@ -720,7 +997,10 @@ type ServiceInstance = FetchAPI & {
|
|
|
720
997
|
};
|
|
721
998
|
type ServiceTimelineState = Readonly<{
|
|
722
999
|
snapshot: NamespaceSnapshot;
|
|
723
|
-
clock
|
|
1000
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
1001
|
+
clock: Readonly<ClockState & {
|
|
1002
|
+
pinned?: boolean;
|
|
1003
|
+
}>;
|
|
724
1004
|
rngState: number;
|
|
725
1005
|
}>;
|
|
726
1006
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -733,27 +1013,63 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
733
1013
|
readonly sqlite: SqliteClient$1;
|
|
734
1014
|
readonly clock: Clock;
|
|
735
1015
|
readonly faults: FaultRegistry;
|
|
1016
|
+
/** Baseline response time per namespace. */
|
|
1017
|
+
readonly latency: LatencyRegistry;
|
|
736
1018
|
readonly metrics: Metrics;
|
|
737
1019
|
readonly journal: Journal;
|
|
738
1020
|
readonly rng: Rng;
|
|
739
1021
|
readonly credentials: CredentialRegistry;
|
|
740
1022
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
741
1023
|
readonly webhooks: WebhookHub | undefined;
|
|
742
|
-
/**
|
|
743
|
-
|
|
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
|
+
*/
|
|
744
1028
|
namespaceClock(namespace?: string): Clock;
|
|
745
1029
|
namespaceOf(request: Request): string;
|
|
746
1030
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
747
1031
|
fleetSnapshot(namespace: string): object;
|
|
748
1032
|
fleetRestore(snapshot: unknown, namespace: string): void;
|
|
1033
|
+
fleetExport(snapshot: unknown): SnapshotDocument;
|
|
1034
|
+
fleetImport(namespace: string, document: unknown): object;
|
|
749
1035
|
/** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
|
|
750
1036
|
applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
|
|
751
1037
|
/** The instance behind `namespace` (the default one when omitted), created on first use. */
|
|
752
1038
|
instance(namespace?: string): T;
|
|
753
1039
|
/** Public names of every namespace created so far. */
|
|
754
1040
|
namespaces(): string[];
|
|
755
|
-
/**
|
|
1041
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
756
1042
|
reset(namespace?: string): Promise<void>;
|
|
1043
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
1044
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
1045
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
1046
|
+
controls(namespace?: string): ControlState & {
|
|
1047
|
+
snapshots: SnapshotInfo[];
|
|
1048
|
+
};
|
|
1049
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
1050
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
1051
|
+
snapshots: SnapshotInfo[];
|
|
1052
|
+
};
|
|
1053
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
1054
|
+
readonly snapshots: {
|
|
1055
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
1056
|
+
create(options?: {
|
|
1057
|
+
name?: string;
|
|
1058
|
+
namespace?: string;
|
|
1059
|
+
}): SnapshotInfo;
|
|
1060
|
+
list(namespace?: string): SnapshotInfo[];
|
|
1061
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
1062
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
1063
|
+
/** Store a document as a snapshot without restoring it. */
|
|
1064
|
+
import(document: SnapshotDocument, options?: {
|
|
1065
|
+
name?: string;
|
|
1066
|
+
namespace?: string;
|
|
1067
|
+
}): SnapshotInfo;
|
|
1068
|
+
restore(id: string, namespace?: string): void;
|
|
1069
|
+
delete(id: string, namespace?: string): boolean;
|
|
1070
|
+
};
|
|
1071
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
1072
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
757
1073
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
758
1074
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
759
1075
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -1090,6 +1406,8 @@ type ForwardTarget = {
|
|
|
1090
1406
|
adminPrefix?: string;
|
|
1091
1407
|
/** Its `x-mockingbird-admin-key`, when it has one. */
|
|
1092
1408
|
adminKey?: string;
|
|
1409
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
1410
|
+
adminControls?: MockControls;
|
|
1093
1411
|
/** Give up on a forward after this long (the send still succeeds). Default 2000 ms. */
|
|
1094
1412
|
timeoutMs?: number;
|
|
1095
1413
|
fetch?: (request: Request) => Promise<Response>;
|
|
@@ -1110,6 +1428,8 @@ type ResendRuntimeOptions = Pick<ResendAPIOptions, "fixtures" | "baseUrl" | "tok
|
|
|
1110
1428
|
seed?: number | string;
|
|
1111
1429
|
adminPrefix?: string;
|
|
1112
1430
|
adminKey?: string;
|
|
1431
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
1432
|
+
adminControls?: MockControls;
|
|
1113
1433
|
onLog?: (entry: RequestLog) => void;
|
|
1114
1434
|
/**
|
|
1115
1435
|
* Where `email.received` webhooks go (`POST /messaging/inbound/email`), signed with the
|
|
@@ -1202,7 +1522,7 @@ type SendOutcomeEvent = {
|
|
|
1202
1522
|
namespace: string;
|
|
1203
1523
|
emailId?: string;
|
|
1204
1524
|
};
|
|
1205
|
-
type ResendAPIOptions = APIOptions & Pick<ProviderOptions, "tokens" | "baseUrl" | "publicNamespace" | "adminPrefix"> & {
|
|
1525
|
+
type ResendAPIOptions = APIOptions & Pick<ProviderOptions, "tokens" | "baseUrl" | "publicNamespace" | "adminPrefix" | "random"> & {
|
|
1206
1526
|
fixtures?: ResendSeedConfig;
|
|
1207
1527
|
/** The public namespace name, for `/__admin/ns/<name>` download URLs. Default: the default namespace. */
|
|
1208
1528
|
adminPrefix?: string;
|
package/dist/index.js
CHANGED