@crvouga/mockingbird-service-slack 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 -17
- package/dist/chunk-4JPRLFNZ.js +12740 -0
- package/dist/chunk-4JPRLFNZ.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-DHAINBRN.js +5113 -0
- package/dist/chunk-DHAINBRN.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 +360 -42
- package/dist/index.js +2 -2
- package/dist/server.d.ts +715 -83
- package/dist/server.js +3 -3
- package/package.json +3 -2
- package/dist/chunk-B4MV67Z4.js +0 -10836
- package/dist/chunk-B4MV67Z4.js.map +0 -7
- package/dist/chunk-IM5DJEPT.js +0 -1194
- package/dist/chunk-IM5DJEPT.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-DHAINBRN.js";
|
|
7
|
+
import "./chunk-4JPRLFNZ.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
|
@@ -172,6 +172,11 @@ type ProviderOptions = APIOptions$1 & {
|
|
|
172
172
|
fallbackUser?: AuthFallback;
|
|
173
173
|
publicNamespace?: string;
|
|
174
174
|
adminPrefix?: string;
|
|
175
|
+
/**
|
|
176
|
+
* A seeded stream of `[0, 1)` that ids and tokens are minted from, so a run replays from
|
|
177
|
+
* its seed. Default: the platform's randomness.
|
|
178
|
+
*/
|
|
179
|
+
random?: () => number;
|
|
175
180
|
};
|
|
176
181
|
|
|
177
182
|
type MountedAPI = FetchAPI & {
|
|
@@ -373,7 +378,7 @@ type ClockState = {
|
|
|
373
378
|
now: number;
|
|
374
379
|
/** True while time does not advance on its own. */
|
|
375
380
|
frozen: boolean;
|
|
376
|
-
/** Milliseconds
|
|
381
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
377
382
|
offsetMs: number;
|
|
378
383
|
};
|
|
379
384
|
type Clock = {
|
|
@@ -409,7 +414,10 @@ type Rng = {
|
|
|
409
414
|
state(): number;
|
|
410
415
|
/** Restore a state previously returned by {@link state}. */
|
|
411
416
|
setState(state: number): void;
|
|
412
|
-
seed
|
|
417
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
418
|
+
reseed(seed: number | string): void;
|
|
419
|
+
/** The seed the stream currently starts from. */
|
|
420
|
+
readonly seed: number;
|
|
413
421
|
};
|
|
414
422
|
|
|
415
423
|
/**
|
|
@@ -418,44 +426,83 @@ type Rng = {
|
|
|
418
426
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
419
427
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
420
428
|
* appears under load, the 5xx that proves a retry path works.
|
|
429
|
+
*
|
|
430
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
431
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
432
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
421
433
|
*/
|
|
422
434
|
type FaultRule = {
|
|
423
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
435
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
424
436
|
id: string;
|
|
425
437
|
/** Fault only this operation. Omit to match every operation. */
|
|
426
438
|
operationId?: string;
|
|
427
439
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
428
440
|
method?: string;
|
|
441
|
+
/** Fault only this exact path. */
|
|
442
|
+
path?: string;
|
|
429
443
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
430
444
|
pathPrefix?: string;
|
|
445
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
446
|
+
pathPattern?: string;
|
|
447
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
448
|
+
requestHeaders?: Record<string, string>;
|
|
449
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
450
|
+
query?: Record<string, string>;
|
|
431
451
|
/**
|
|
432
452
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
433
453
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
434
454
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
435
455
|
*/
|
|
436
456
|
namespace?: string;
|
|
457
|
+
/** Let this many matching requests through first. */
|
|
458
|
+
after?: number;
|
|
459
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
460
|
+
every?: number;
|
|
461
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
462
|
+
count?: number;
|
|
463
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
464
|
+
rate?: number;
|
|
437
465
|
/**
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
|
|
466
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
467
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
468
|
+
*/
|
|
469
|
+
from?: Instant | Duration;
|
|
470
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
471
|
+
until?: Instant | Duration;
|
|
472
|
+
/**
|
|
473
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
474
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
441
475
|
*/
|
|
442
476
|
status?: number;
|
|
443
477
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
444
478
|
body?: unknown;
|
|
479
|
+
/** Response headers. */
|
|
445
480
|
headers?: Record<string, string>;
|
|
446
|
-
/**
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
rate?: number;
|
|
450
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
481
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
482
|
+
delay?: Duration;
|
|
483
|
+
/** `delay`, in milliseconds. */
|
|
451
484
|
delayMs?: number;
|
|
452
485
|
/** Alias of `delayMs`. */
|
|
453
486
|
latencyMs?: number;
|
|
487
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
488
|
+
jitter?: Duration;
|
|
489
|
+
jitterMs?: number;
|
|
490
|
+
/**
|
|
491
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
492
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
493
|
+
*/
|
|
494
|
+
timeout?: Duration;
|
|
495
|
+
timeoutMs?: number;
|
|
454
496
|
/**
|
|
455
497
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
456
498
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
457
499
|
*/
|
|
458
500
|
drop?: boolean;
|
|
501
|
+
/**
|
|
502
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
503
|
+
* the connection dies mid-body.
|
|
504
|
+
*/
|
|
505
|
+
truncate?: number;
|
|
459
506
|
/**
|
|
460
507
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
461
508
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -464,8 +511,8 @@ type FaultRule = {
|
|
|
464
511
|
effect?: string;
|
|
465
512
|
/** Parameters for `effect`. */
|
|
466
513
|
params?: Record<string, unknown>;
|
|
467
|
-
/**
|
|
468
|
-
|
|
514
|
+
/** The preset this rule was expanded from, if any. */
|
|
515
|
+
fromPreset?: string;
|
|
469
516
|
};
|
|
470
517
|
/** A fault that fired for one request. */
|
|
471
518
|
type FaultHit = {
|
|
@@ -473,6 +520,10 @@ type FaultHit = {
|
|
|
473
520
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
474
521
|
response?: Response;
|
|
475
522
|
drop?: boolean;
|
|
523
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
524
|
+
timeout?: boolean;
|
|
525
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
526
|
+
truncate?: number;
|
|
476
527
|
effect?: {
|
|
477
528
|
name: string;
|
|
478
529
|
params: Record<string, unknown>;
|
|
@@ -497,38 +548,202 @@ type FaultCandidate = {
|
|
|
497
548
|
method: string;
|
|
498
549
|
path: string;
|
|
499
550
|
namespace: string;
|
|
551
|
+
/** Request headers and query, for rules that match on them. */
|
|
552
|
+
headers?: Headers;
|
|
553
|
+
query?: URLSearchParams;
|
|
554
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
555
|
+
now?: number;
|
|
556
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
557
|
+
wait?: (ms: number) => Promise<void>;
|
|
558
|
+
};
|
|
559
|
+
/** A stored rule and how often it was consulted. */
|
|
560
|
+
type FaultListing = FaultRule & {
|
|
561
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
562
|
+
remaining: number | null;
|
|
563
|
+
/** Times the rule faulted a request. */
|
|
564
|
+
hits: number;
|
|
565
|
+
/** Requests that matched the rule, faulted or not. */
|
|
566
|
+
seen: number;
|
|
567
|
+
};
|
|
568
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
569
|
+
type FaultSnapshot = {
|
|
570
|
+
/**
|
|
571
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
572
|
+
* in the order means to a request and holds in any process.
|
|
573
|
+
*/
|
|
574
|
+
rules: (FaultListing & {
|
|
575
|
+
position?: number;
|
|
576
|
+
})[];
|
|
577
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
578
|
+
nextId?: number;
|
|
500
579
|
};
|
|
501
580
|
type FaultRegistry = {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
rules: (FaultRule & {
|
|
505
|
-
remaining: number | null;
|
|
506
|
-
hits: number;
|
|
507
|
-
position: number;
|
|
508
|
-
})[];
|
|
509
|
-
rngState: number;
|
|
510
|
-
};
|
|
581
|
+
snapshot(namespace: string): FaultSnapshot;
|
|
582
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
511
583
|
add(rule: FaultRule): FaultRule;
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
})[];
|
|
524
|
-
rngState: number;
|
|
525
|
-
}): void;
|
|
584
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
585
|
+
nextId(namespace: string): string;
|
|
586
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
587
|
+
list(namespace?: string): FaultListing[];
|
|
588
|
+
get(id: string, namespace?: string): FaultListing | undefined;
|
|
589
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
590
|
+
remove(id: string, namespace?: string): boolean;
|
|
591
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
592
|
+
clear(namespace?: string): void;
|
|
593
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
594
|
+
restore(namespace: string, state: FaultSnapshot): void;
|
|
526
595
|
/**
|
|
527
596
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
528
597
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
529
598
|
* each matching rule's remaining uses.
|
|
530
599
|
*/
|
|
531
600
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
601
|
+
/**
|
|
602
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
603
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
604
|
+
*/
|
|
605
|
+
fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* The admin controls every mock shares, as one document.
|
|
610
|
+
*
|
|
611
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
612
|
+
*
|
|
613
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
614
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
615
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
616
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
617
|
+
*
|
|
618
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
619
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
620
|
+
*/
|
|
621
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
622
|
+
type Duration = number | string;
|
|
623
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
624
|
+
type Instant = number | string;
|
|
625
|
+
type ClockControls = {
|
|
626
|
+
/** Move the clock to this instant. */
|
|
627
|
+
now?: Instant;
|
|
628
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
629
|
+
frozen?: boolean;
|
|
630
|
+
/**
|
|
631
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
632
|
+
* each request still gets its own, reproducible timestamp.
|
|
633
|
+
*/
|
|
634
|
+
autoAdvance?: Duration;
|
|
635
|
+
};
|
|
636
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
637
|
+
type LatencyRuleInput = {
|
|
638
|
+
delay?: Duration;
|
|
639
|
+
jitter?: Duration;
|
|
640
|
+
};
|
|
641
|
+
type LatencyControls = LatencyRuleInput & {
|
|
642
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
643
|
+
operations?: Record<string, Duration | LatencyRuleInput>;
|
|
644
|
+
};
|
|
645
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
646
|
+
type FaultInput = (Omit<FaultRule, "id"> & {
|
|
647
|
+
id?: string;
|
|
648
|
+
}) | ({
|
|
649
|
+
preset: string;
|
|
650
|
+
} & Partial<FaultRule>);
|
|
651
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
652
|
+
declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
|
|
653
|
+
/**
|
|
654
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
655
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
656
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
657
|
+
*/
|
|
658
|
+
type SnapshotDocument = {
|
|
659
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
660
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
661
|
+
service?: string;
|
|
662
|
+
/**
|
|
663
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
664
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
665
|
+
*/
|
|
666
|
+
records: {
|
|
667
|
+
collection: string;
|
|
668
|
+
id: string;
|
|
669
|
+
seq?: number;
|
|
670
|
+
value?: unknown;
|
|
671
|
+
raw?: string;
|
|
672
|
+
}[];
|
|
673
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
674
|
+
sequences?: {
|
|
675
|
+
name: string;
|
|
676
|
+
kind: string;
|
|
677
|
+
value: number;
|
|
678
|
+
}[];
|
|
679
|
+
clock?: {
|
|
680
|
+
now: number;
|
|
681
|
+
frozen: boolean;
|
|
682
|
+
autoAdvanceMs?: number;
|
|
683
|
+
};
|
|
684
|
+
seed?: number | string;
|
|
685
|
+
/** Positions of the seeded random streams. */
|
|
686
|
+
rng?: {
|
|
687
|
+
state: number;
|
|
688
|
+
faults?: number;
|
|
689
|
+
latency?: number;
|
|
690
|
+
};
|
|
691
|
+
faults?: unknown;
|
|
692
|
+
latency?: unknown;
|
|
693
|
+
virtualTime?: boolean;
|
|
694
|
+
/** Quiescent webhook endpoints, delivery history and fault state. Contains private configuration. */
|
|
695
|
+
webhooks?: unknown;
|
|
696
|
+
};
|
|
697
|
+
/** Controls for one namespace. */
|
|
698
|
+
type NamespaceControls = {
|
|
699
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
700
|
+
seed?: number | string;
|
|
701
|
+
clock?: ClockControls;
|
|
702
|
+
/**
|
|
703
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
704
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
705
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
706
|
+
*/
|
|
707
|
+
virtualTime?: boolean;
|
|
708
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
709
|
+
latency?: Duration | LatencyControls;
|
|
710
|
+
faults?: readonly FaultInput[];
|
|
711
|
+
/** Start from this state instead of the service's own seed data. */
|
|
712
|
+
snapshot?: SnapshotDocument;
|
|
713
|
+
};
|
|
714
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
715
|
+
type MockControls = NamespaceControls & {
|
|
716
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
717
|
+
credentials?: Record<string, string>;
|
|
718
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
719
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
720
|
+
};
|
|
721
|
+
/** A latency rule in milliseconds. */
|
|
722
|
+
type LatencyRule = {
|
|
723
|
+
delayMs: number;
|
|
724
|
+
jitterMs: number;
|
|
725
|
+
};
|
|
726
|
+
/** Baseline latency for a namespace, normalized. */
|
|
727
|
+
type LatencyState = LatencyRule & {
|
|
728
|
+
operations: Record<string, LatencyRule>;
|
|
729
|
+
};
|
|
730
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
731
|
+
type ControlHeaderInput = {
|
|
732
|
+
namespace?: string;
|
|
733
|
+
adminKey?: string;
|
|
734
|
+
branch?: string;
|
|
735
|
+
at?: string;
|
|
736
|
+
reset?: boolean;
|
|
737
|
+
restore?: string;
|
|
738
|
+
seed?: number | string;
|
|
739
|
+
time?: Instant | Date;
|
|
740
|
+
advance?: Duration;
|
|
741
|
+
virtualTime?: boolean;
|
|
742
|
+
delay?: Duration;
|
|
743
|
+
timeout?: Duration;
|
|
744
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
745
|
+
fault?: number | string | Record<string, unknown>;
|
|
746
|
+
snapshot?: string;
|
|
532
747
|
};
|
|
533
748
|
|
|
534
749
|
/**
|
|
@@ -568,6 +783,8 @@ type RequestLog = {
|
|
|
568
783
|
unmatched: boolean;
|
|
569
784
|
/** Set when a fault rule produced the response. */
|
|
570
785
|
faultId?: string;
|
|
786
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
787
|
+
delayMs?: number;
|
|
571
788
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
572
789
|
ids?: Record<string, string>;
|
|
573
790
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -613,6 +830,12 @@ type JournalQuery = {
|
|
|
613
830
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
614
831
|
namespace?: string;
|
|
615
832
|
operationId?: string;
|
|
833
|
+
/** Only this HTTP method, case-insensitive. */
|
|
834
|
+
method?: string;
|
|
835
|
+
/** Only this exact path. */
|
|
836
|
+
path?: string;
|
|
837
|
+
/** Only requests this fault rule answered or shaped. */
|
|
838
|
+
faultId?: string;
|
|
616
839
|
status?: number;
|
|
617
840
|
/** Only entries at or after this instant (epoch ms). */
|
|
618
841
|
since?: number;
|
|
@@ -627,6 +850,50 @@ type Journal = {
|
|
|
627
850
|
clear(namespace?: string): void;
|
|
628
851
|
};
|
|
629
852
|
|
|
853
|
+
/**
|
|
854
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
855
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
856
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
857
|
+
* fault hits.
|
|
858
|
+
*/
|
|
859
|
+
type LatencyRegistry = {
|
|
860
|
+
get(namespace: string): LatencyState;
|
|
861
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
862
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
863
|
+
clear(namespace?: string): void;
|
|
864
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
865
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
/** Clock state as the admin API reports it. */
|
|
869
|
+
type ControlClock = ClockState & {
|
|
870
|
+
/** `now`, as ISO-8601. */
|
|
871
|
+
iso: string;
|
|
872
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
873
|
+
autoAdvanceMs: number;
|
|
874
|
+
};
|
|
875
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
876
|
+
type ControlState = {
|
|
877
|
+
namespace: string;
|
|
878
|
+
seed: number | string;
|
|
879
|
+
clock: ControlClock;
|
|
880
|
+
virtualTime: boolean;
|
|
881
|
+
latency: LatencyState;
|
|
882
|
+
faults: FaultListing[];
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
886
|
+
type SnapshotInfo = {
|
|
887
|
+
id: string;
|
|
888
|
+
namespace: string;
|
|
889
|
+
/** Stored rows in the snapshot. */
|
|
890
|
+
records: number;
|
|
891
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
892
|
+
at: number;
|
|
893
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
894
|
+
portable: boolean;
|
|
895
|
+
};
|
|
896
|
+
|
|
630
897
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
631
898
|
type CredentialRegistry = {
|
|
632
899
|
set(credential: string, namespace: string): void;
|
|
@@ -639,6 +906,8 @@ type CredentialRegistry = {
|
|
|
639
906
|
}[];
|
|
640
907
|
};
|
|
641
908
|
|
|
909
|
+
type OwnedTransport = (request: Request, namespace: string, send: typeof fetch) => Promise<Response>;
|
|
910
|
+
|
|
642
911
|
/**
|
|
643
912
|
* A point-in-time copy of everything a service namespace holds.
|
|
644
913
|
*
|
|
@@ -756,8 +1025,16 @@ type PublishInput = {
|
|
|
756
1025
|
id?: string;
|
|
757
1026
|
};
|
|
758
1027
|
type WebhookHub = {
|
|
1028
|
+
observeDeliveries(listener: (event: {
|
|
1029
|
+
namespace: string;
|
|
1030
|
+
state: string;
|
|
1031
|
+
deliveryId: string;
|
|
1032
|
+
}) => void): () => void;
|
|
1033
|
+
setTransportPolicy(policy: OwnedTransport): void;
|
|
759
1034
|
pending(namespace: string): number;
|
|
760
1035
|
snapshot(namespace: string): unknown;
|
|
1036
|
+
exportSnapshot(handle: unknown): unknown;
|
|
1037
|
+
importSnapshot(namespace: string, document: unknown): unknown;
|
|
761
1038
|
restore(namespace: string, snapshot: unknown): void;
|
|
762
1039
|
publish(input: PublishInput): WebhookMessage;
|
|
763
1040
|
/** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
|
|
@@ -770,7 +1047,7 @@ type WebhookHub = {
|
|
|
770
1047
|
/** Run every pending retry (and release held reordered messages) now, and every retry those attempts schedule, until nothing is pending. */
|
|
771
1048
|
flush(): Promise<void>;
|
|
772
1049
|
/** Resolve once nothing is in flight. */
|
|
773
|
-
idle(): Promise<void>;
|
|
1050
|
+
idle(namespace?: string): Promise<void>;
|
|
774
1051
|
fault(namespace: string, fault: WebhookFault): void;
|
|
775
1052
|
clear(namespace?: string): void;
|
|
776
1053
|
};
|
|
@@ -781,7 +1058,10 @@ type ServiceInstance = FetchAPI & {
|
|
|
781
1058
|
};
|
|
782
1059
|
type ServiceTimelineState = Readonly<{
|
|
783
1060
|
snapshot: NamespaceSnapshot;
|
|
784
|
-
clock
|
|
1061
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
1062
|
+
clock: Readonly<ClockState & {
|
|
1063
|
+
pinned?: boolean;
|
|
1064
|
+
}>;
|
|
785
1065
|
rngState: number;
|
|
786
1066
|
}>;
|
|
787
1067
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -794,27 +1074,63 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
794
1074
|
readonly sqlite: SqliteClient$1;
|
|
795
1075
|
readonly clock: Clock;
|
|
796
1076
|
readonly faults: FaultRegistry;
|
|
1077
|
+
/** Baseline response time per namespace. */
|
|
1078
|
+
readonly latency: LatencyRegistry;
|
|
797
1079
|
readonly metrics: Metrics;
|
|
798
1080
|
readonly journal: Journal;
|
|
799
1081
|
readonly rng: Rng;
|
|
800
1082
|
readonly credentials: CredentialRegistry;
|
|
801
1083
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
802
1084
|
readonly webhooks: WebhookHub | undefined;
|
|
803
|
-
/**
|
|
804
|
-
|
|
1085
|
+
/**
|
|
1086
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
1087
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
1088
|
+
*/
|
|
805
1089
|
namespaceClock(namespace?: string): Clock;
|
|
806
1090
|
namespaceOf(request: Request): string;
|
|
807
1091
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
808
1092
|
fleetSnapshot(namespace: string): object;
|
|
809
1093
|
fleetRestore(snapshot: unknown, namespace: string): void;
|
|
1094
|
+
fleetExport(snapshot: unknown): SnapshotDocument;
|
|
1095
|
+
fleetImport(namespace: string, document: unknown): object;
|
|
810
1096
|
/** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
|
|
811
1097
|
applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
|
|
812
1098
|
/** The instance behind `namespace` (the default one when omitted), created on first use. */
|
|
813
1099
|
instance(namespace?: string): T;
|
|
814
1100
|
/** Public names of every namespace created so far. */
|
|
815
1101
|
namespaces(): string[];
|
|
816
|
-
/**
|
|
1102
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
817
1103
|
reset(namespace?: string): Promise<void>;
|
|
1104
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
1105
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
1106
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
1107
|
+
controls(namespace?: string): ControlState & {
|
|
1108
|
+
snapshots: SnapshotInfo[];
|
|
1109
|
+
};
|
|
1110
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
1111
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
1112
|
+
snapshots: SnapshotInfo[];
|
|
1113
|
+
};
|
|
1114
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
1115
|
+
readonly snapshots: {
|
|
1116
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
1117
|
+
create(options?: {
|
|
1118
|
+
name?: string;
|
|
1119
|
+
namespace?: string;
|
|
1120
|
+
}): SnapshotInfo;
|
|
1121
|
+
list(namespace?: string): SnapshotInfo[];
|
|
1122
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
1123
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
1124
|
+
/** Store a document as a snapshot without restoring it. */
|
|
1125
|
+
import(document: SnapshotDocument, options?: {
|
|
1126
|
+
name?: string;
|
|
1127
|
+
namespace?: string;
|
|
1128
|
+
}): SnapshotInfo;
|
|
1129
|
+
restore(id: string, namespace?: string): void;
|
|
1130
|
+
delete(id: string, namespace?: string): boolean;
|
|
1131
|
+
};
|
|
1132
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
1133
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
818
1134
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
819
1135
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
820
1136
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -1214,6 +1530,8 @@ type SlackRuntimeOptions = Pick<SlackAPIOptions, "fixtures" | "baseUrl" | "token
|
|
|
1214
1530
|
seed?: number | string;
|
|
1215
1531
|
adminPrefix?: string;
|
|
1216
1532
|
adminKey?: string;
|
|
1533
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
1534
|
+
adminControls?: MockControls;
|
|
1217
1535
|
onLog?: (entry: RequestLog) => void;
|
|
1218
1536
|
settings?: Partial<Settings>;
|
|
1219
1537
|
};
|
|
@@ -1226,7 +1544,7 @@ type SlackRuntime = ServiceRuntime<SlackAPI>;
|
|
|
1226
1544
|
declare const createRuntime: (options?: SlackRuntimeOptions) => SlackRuntime;
|
|
1227
1545
|
|
|
1228
1546
|
declare const SLACK_NAMESPACE = "slack";
|
|
1229
|
-
type SlackAPIOptions = APIOptions & Pick<ProviderOptions, "tokens" | "baseUrl" | "publicNamespace" | "adminPrefix"> & {
|
|
1547
|
+
type SlackAPIOptions = APIOptions & Pick<ProviderOptions, "tokens" | "baseUrl" | "publicNamespace" | "adminPrefix" | "random"> & {
|
|
1230
1548
|
fixtures?: SlackSeedConfig;
|
|
1231
1549
|
/** Initial per-namespace settings (workspace identity, accepted tokens, strict channels). */
|
|
1232
1550
|
settings?: Partial<Settings>;
|
package/dist/index.js
CHANGED