@crvouga/mockingbird-service-oauth 3.3.0 → 3.5.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 +19 -1
- package/DISCOVERY.md +23 -0
- package/README.md +32 -4
- package/dist/chunk-ANDSQ2HK.js +7350 -0
- package/dist/chunk-ANDSQ2HK.js.map +7 -0
- package/dist/chunk-OYEO5VHR.js +4792 -0
- package/dist/chunk-OYEO5VHR.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +356 -41
- package/dist/index.js +1 -1
- package/dist/server.d.ts +711 -82
- package/dist/server.js +2 -2
- package/package.json +3 -2
- package/dist/chunk-73KPFQ45.js +0 -5444
- package/dist/chunk-73KPFQ45.js.map +0 -7
- package/dist/chunk-OHEZ2REI.js +0 -872
- package/dist/chunk-OHEZ2REI.js.map +0 -7
package/dist/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -197,7 +197,7 @@ type ClockState = {
|
|
|
197
197
|
now: number;
|
|
198
198
|
/** True while time does not advance on its own. */
|
|
199
199
|
frozen: boolean;
|
|
200
|
-
/** Milliseconds
|
|
200
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
201
201
|
offsetMs: number;
|
|
202
202
|
};
|
|
203
203
|
type Clock = {
|
|
@@ -233,7 +233,10 @@ type Rng = {
|
|
|
233
233
|
state(): number;
|
|
234
234
|
/** Restore a state previously returned by {@link state}. */
|
|
235
235
|
setState(state: number): void;
|
|
236
|
-
seed
|
|
236
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
237
|
+
reseed(seed: number | string): void;
|
|
238
|
+
/** The seed the stream currently starts from. */
|
|
239
|
+
readonly seed: number;
|
|
237
240
|
};
|
|
238
241
|
|
|
239
242
|
/**
|
|
@@ -242,44 +245,83 @@ type Rng = {
|
|
|
242
245
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
243
246
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
244
247
|
* appears under load, the 5xx that proves a retry path works.
|
|
248
|
+
*
|
|
249
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
250
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
251
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
245
252
|
*/
|
|
246
253
|
type FaultRule = {
|
|
247
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
254
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
248
255
|
id: string;
|
|
249
256
|
/** Fault only this operation. Omit to match every operation. */
|
|
250
257
|
operationId?: string;
|
|
251
258
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
252
259
|
method?: string;
|
|
260
|
+
/** Fault only this exact path. */
|
|
261
|
+
path?: string;
|
|
253
262
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
254
263
|
pathPrefix?: string;
|
|
264
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
265
|
+
pathPattern?: string;
|
|
266
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
267
|
+
requestHeaders?: Record<string, string>;
|
|
268
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
269
|
+
query?: Record<string, string>;
|
|
255
270
|
/**
|
|
256
271
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
257
272
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
258
273
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
259
274
|
*/
|
|
260
275
|
namespace?: string;
|
|
276
|
+
/** Let this many matching requests through first. */
|
|
277
|
+
after?: number;
|
|
278
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
279
|
+
every?: number;
|
|
280
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
281
|
+
count?: number;
|
|
282
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
283
|
+
rate?: number;
|
|
284
|
+
/**
|
|
285
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
286
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
287
|
+
*/
|
|
288
|
+
from?: Instant | Duration;
|
|
289
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
290
|
+
until?: Instant | Duration;
|
|
261
291
|
/**
|
|
262
|
-
* Status of the injected response. Omit for a rule that only delays
|
|
263
|
-
*
|
|
264
|
-
* the request then still reaches the service.
|
|
292
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
293
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
265
294
|
*/
|
|
266
295
|
status?: number;
|
|
267
296
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
268
297
|
body?: unknown;
|
|
298
|
+
/** Response headers. */
|
|
269
299
|
headers?: Record<string, string>;
|
|
270
|
-
/**
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
rate?: number;
|
|
274
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
300
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
301
|
+
delay?: Duration;
|
|
302
|
+
/** `delay`, in milliseconds. */
|
|
275
303
|
delayMs?: number;
|
|
276
304
|
/** Alias of `delayMs`. */
|
|
277
305
|
latencyMs?: number;
|
|
306
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
307
|
+
jitter?: Duration;
|
|
308
|
+
jitterMs?: number;
|
|
309
|
+
/**
|
|
310
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
311
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
312
|
+
*/
|
|
313
|
+
timeout?: Duration;
|
|
314
|
+
timeoutMs?: number;
|
|
278
315
|
/**
|
|
279
316
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
280
317
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
281
318
|
*/
|
|
282
319
|
drop?: boolean;
|
|
320
|
+
/**
|
|
321
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
322
|
+
* the connection dies mid-body.
|
|
323
|
+
*/
|
|
324
|
+
truncate?: number;
|
|
283
325
|
/**
|
|
284
326
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
285
327
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -288,8 +330,8 @@ type FaultRule = {
|
|
|
288
330
|
effect?: string;
|
|
289
331
|
/** Parameters for `effect`. */
|
|
290
332
|
params?: Record<string, unknown>;
|
|
291
|
-
/**
|
|
292
|
-
|
|
333
|
+
/** The preset this rule was expanded from, if any. */
|
|
334
|
+
fromPreset?: string;
|
|
293
335
|
};
|
|
294
336
|
/** A fault that fired for one request. */
|
|
295
337
|
type FaultHit = {
|
|
@@ -297,6 +339,10 @@ type FaultHit = {
|
|
|
297
339
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
298
340
|
response?: Response;
|
|
299
341
|
drop?: boolean;
|
|
342
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
343
|
+
timeout?: boolean;
|
|
344
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
345
|
+
truncate?: number;
|
|
300
346
|
effect?: {
|
|
301
347
|
name: string;
|
|
302
348
|
params: Record<string, unknown>;
|
|
@@ -321,38 +367,202 @@ type FaultCandidate = {
|
|
|
321
367
|
method: string;
|
|
322
368
|
path: string;
|
|
323
369
|
namespace: string;
|
|
370
|
+
/** Request headers and query, for rules that match on them. */
|
|
371
|
+
headers?: Headers;
|
|
372
|
+
query?: URLSearchParams;
|
|
373
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
374
|
+
now?: number;
|
|
375
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
376
|
+
wait?: (ms: number) => Promise<void>;
|
|
377
|
+
};
|
|
378
|
+
/** A stored rule and how often it was consulted. */
|
|
379
|
+
type FaultListing = FaultRule & {
|
|
380
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
381
|
+
remaining: number | null;
|
|
382
|
+
/** Times the rule faulted a request. */
|
|
383
|
+
hits: number;
|
|
384
|
+
/** Requests that matched the rule, faulted or not. */
|
|
385
|
+
seen: number;
|
|
386
|
+
};
|
|
387
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
388
|
+
type FaultSnapshot = {
|
|
389
|
+
/**
|
|
390
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
391
|
+
* in the order means to a request and holds in any process.
|
|
392
|
+
*/
|
|
393
|
+
rules: (FaultListing & {
|
|
394
|
+
position?: number;
|
|
395
|
+
})[];
|
|
396
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
397
|
+
nextId?: number;
|
|
324
398
|
};
|
|
325
399
|
type FaultRegistry = {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
rules: (FaultRule & {
|
|
329
|
-
remaining: number | null;
|
|
330
|
-
hits: number;
|
|
331
|
-
position: number;
|
|
332
|
-
})[];
|
|
333
|
-
rngState: number;
|
|
334
|
-
};
|
|
400
|
+
snapshot(namespace: string): FaultSnapshot;
|
|
401
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
335
402
|
add(rule: FaultRule): FaultRule;
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
})[];
|
|
348
|
-
rngState: number;
|
|
349
|
-
}): void;
|
|
403
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
404
|
+
nextId(namespace: string): string;
|
|
405
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
406
|
+
list(namespace?: string): FaultListing[];
|
|
407
|
+
get(id: string, namespace?: string): FaultListing | undefined;
|
|
408
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
409
|
+
remove(id: string, namespace?: string): boolean;
|
|
410
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
411
|
+
clear(namespace?: string): void;
|
|
412
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
413
|
+
restore(namespace: string, state: FaultSnapshot): void;
|
|
350
414
|
/**
|
|
351
415
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
352
416
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
353
417
|
* each matching rule's remaining uses.
|
|
354
418
|
*/
|
|
355
419
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
420
|
+
/**
|
|
421
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
422
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
423
|
+
*/
|
|
424
|
+
fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* The admin controls every mock shares, as one document.
|
|
429
|
+
*
|
|
430
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
431
|
+
*
|
|
432
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
433
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
434
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
435
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
436
|
+
*
|
|
437
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
438
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
439
|
+
*/
|
|
440
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
441
|
+
type Duration = number | string;
|
|
442
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
443
|
+
type Instant = number | string;
|
|
444
|
+
type ClockControls = {
|
|
445
|
+
/** Move the clock to this instant. */
|
|
446
|
+
now?: Instant;
|
|
447
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
448
|
+
frozen?: boolean;
|
|
449
|
+
/**
|
|
450
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
451
|
+
* each request still gets its own, reproducible timestamp.
|
|
452
|
+
*/
|
|
453
|
+
autoAdvance?: Duration;
|
|
454
|
+
};
|
|
455
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
456
|
+
type LatencyRuleInput = {
|
|
457
|
+
delay?: Duration;
|
|
458
|
+
jitter?: Duration;
|
|
459
|
+
};
|
|
460
|
+
type LatencyControls = LatencyRuleInput & {
|
|
461
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
462
|
+
operations?: Record<string, Duration | LatencyRuleInput>;
|
|
463
|
+
};
|
|
464
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
465
|
+
type FaultInput = (Omit<FaultRule, "id"> & {
|
|
466
|
+
id?: string;
|
|
467
|
+
}) | ({
|
|
468
|
+
preset: string;
|
|
469
|
+
} & Partial<FaultRule>);
|
|
470
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
471
|
+
declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
|
|
472
|
+
/**
|
|
473
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
474
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
475
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
476
|
+
*/
|
|
477
|
+
type SnapshotDocument = {
|
|
478
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
479
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
480
|
+
service?: string;
|
|
481
|
+
/**
|
|
482
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
483
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
484
|
+
*/
|
|
485
|
+
records: {
|
|
486
|
+
collection: string;
|
|
487
|
+
id: string;
|
|
488
|
+
seq?: number;
|
|
489
|
+
value?: unknown;
|
|
490
|
+
raw?: string;
|
|
491
|
+
}[];
|
|
492
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
493
|
+
sequences?: {
|
|
494
|
+
name: string;
|
|
495
|
+
kind: string;
|
|
496
|
+
value: number;
|
|
497
|
+
}[];
|
|
498
|
+
clock?: {
|
|
499
|
+
now: number;
|
|
500
|
+
frozen: boolean;
|
|
501
|
+
autoAdvanceMs?: number;
|
|
502
|
+
};
|
|
503
|
+
seed?: number | string;
|
|
504
|
+
/** Positions of the seeded random streams. */
|
|
505
|
+
rng?: {
|
|
506
|
+
state: number;
|
|
507
|
+
faults?: number;
|
|
508
|
+
latency?: number;
|
|
509
|
+
};
|
|
510
|
+
faults?: unknown;
|
|
511
|
+
latency?: unknown;
|
|
512
|
+
virtualTime?: boolean;
|
|
513
|
+
/** Quiescent webhook endpoints, delivery history and fault state. Contains private configuration. */
|
|
514
|
+
webhooks?: unknown;
|
|
515
|
+
};
|
|
516
|
+
/** Controls for one namespace. */
|
|
517
|
+
type NamespaceControls = {
|
|
518
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
519
|
+
seed?: number | string;
|
|
520
|
+
clock?: ClockControls;
|
|
521
|
+
/**
|
|
522
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
523
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
524
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
525
|
+
*/
|
|
526
|
+
virtualTime?: boolean;
|
|
527
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
528
|
+
latency?: Duration | LatencyControls;
|
|
529
|
+
faults?: readonly FaultInput[];
|
|
530
|
+
/** Start from this state instead of the service's own seed data. */
|
|
531
|
+
snapshot?: SnapshotDocument;
|
|
532
|
+
};
|
|
533
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
534
|
+
type MockControls = NamespaceControls & {
|
|
535
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
536
|
+
credentials?: Record<string, string>;
|
|
537
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
538
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
539
|
+
};
|
|
540
|
+
/** A latency rule in milliseconds. */
|
|
541
|
+
type LatencyRule = {
|
|
542
|
+
delayMs: number;
|
|
543
|
+
jitterMs: number;
|
|
544
|
+
};
|
|
545
|
+
/** Baseline latency for a namespace, normalized. */
|
|
546
|
+
type LatencyState = LatencyRule & {
|
|
547
|
+
operations: Record<string, LatencyRule>;
|
|
548
|
+
};
|
|
549
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
550
|
+
type ControlHeaderInput = {
|
|
551
|
+
namespace?: string;
|
|
552
|
+
adminKey?: string;
|
|
553
|
+
branch?: string;
|
|
554
|
+
at?: string;
|
|
555
|
+
reset?: boolean;
|
|
556
|
+
restore?: string;
|
|
557
|
+
seed?: number | string;
|
|
558
|
+
time?: Instant | Date;
|
|
559
|
+
advance?: Duration;
|
|
560
|
+
virtualTime?: boolean;
|
|
561
|
+
delay?: Duration;
|
|
562
|
+
timeout?: Duration;
|
|
563
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
564
|
+
fault?: number | string | Record<string, unknown>;
|
|
565
|
+
snapshot?: string;
|
|
356
566
|
};
|
|
357
567
|
|
|
358
568
|
/**
|
|
@@ -392,6 +602,8 @@ type RequestLog = {
|
|
|
392
602
|
unmatched: boolean;
|
|
393
603
|
/** Set when a fault rule produced the response. */
|
|
394
604
|
faultId?: string;
|
|
605
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
606
|
+
delayMs?: number;
|
|
395
607
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
396
608
|
ids?: Record<string, string>;
|
|
397
609
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -437,6 +649,12 @@ type JournalQuery = {
|
|
|
437
649
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
438
650
|
namespace?: string;
|
|
439
651
|
operationId?: string;
|
|
652
|
+
/** Only this HTTP method, case-insensitive. */
|
|
653
|
+
method?: string;
|
|
654
|
+
/** Only this exact path. */
|
|
655
|
+
path?: string;
|
|
656
|
+
/** Only requests this fault rule answered or shaped. */
|
|
657
|
+
faultId?: string;
|
|
440
658
|
status?: number;
|
|
441
659
|
/** Only entries at or after this instant (epoch ms). */
|
|
442
660
|
since?: number;
|
|
@@ -451,6 +669,50 @@ type Journal = {
|
|
|
451
669
|
clear(namespace?: string): void;
|
|
452
670
|
};
|
|
453
671
|
|
|
672
|
+
/**
|
|
673
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
674
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
675
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
676
|
+
* fault hits.
|
|
677
|
+
*/
|
|
678
|
+
type LatencyRegistry = {
|
|
679
|
+
get(namespace: string): LatencyState;
|
|
680
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
681
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
682
|
+
clear(namespace?: string): void;
|
|
683
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
684
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
/** Clock state as the admin API reports it. */
|
|
688
|
+
type ControlClock = ClockState & {
|
|
689
|
+
/** `now`, as ISO-8601. */
|
|
690
|
+
iso: string;
|
|
691
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
692
|
+
autoAdvanceMs: number;
|
|
693
|
+
};
|
|
694
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
695
|
+
type ControlState = {
|
|
696
|
+
namespace: string;
|
|
697
|
+
seed: number | string;
|
|
698
|
+
clock: ControlClock;
|
|
699
|
+
virtualTime: boolean;
|
|
700
|
+
latency: LatencyState;
|
|
701
|
+
faults: FaultListing[];
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
705
|
+
type SnapshotInfo = {
|
|
706
|
+
id: string;
|
|
707
|
+
namespace: string;
|
|
708
|
+
/** Stored rows in the snapshot. */
|
|
709
|
+
records: number;
|
|
710
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
711
|
+
at: number;
|
|
712
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
713
|
+
portable: boolean;
|
|
714
|
+
};
|
|
715
|
+
|
|
454
716
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
455
717
|
type CredentialRegistry = {
|
|
456
718
|
set(credential: string, namespace: string): void;
|
|
@@ -463,6 +725,8 @@ type CredentialRegistry = {
|
|
|
463
725
|
}[];
|
|
464
726
|
};
|
|
465
727
|
|
|
728
|
+
type OwnedTransport = (request: Request, namespace: string, send: typeof fetch) => Promise<Response>;
|
|
729
|
+
|
|
466
730
|
/**
|
|
467
731
|
* A point-in-time copy of everything a service namespace holds.
|
|
468
732
|
*
|
|
@@ -580,8 +844,16 @@ type PublishInput = {
|
|
|
580
844
|
id?: string;
|
|
581
845
|
};
|
|
582
846
|
type WebhookHub = {
|
|
847
|
+
observeDeliveries(listener: (event: {
|
|
848
|
+
namespace: string;
|
|
849
|
+
state: string;
|
|
850
|
+
deliveryId: string;
|
|
851
|
+
}) => void): () => void;
|
|
852
|
+
setTransportPolicy(policy: OwnedTransport): void;
|
|
583
853
|
pending(namespace: string): number;
|
|
584
854
|
snapshot(namespace: string): unknown;
|
|
855
|
+
exportSnapshot(handle: unknown): unknown;
|
|
856
|
+
importSnapshot(namespace: string, document: unknown): unknown;
|
|
585
857
|
restore(namespace: string, snapshot: unknown): void;
|
|
586
858
|
publish(input: PublishInput): WebhookMessage;
|
|
587
859
|
/** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
|
|
@@ -594,7 +866,7 @@ type WebhookHub = {
|
|
|
594
866
|
/** Run every pending retry (and release held reordered messages) now, and every retry those attempts schedule, until nothing is pending. */
|
|
595
867
|
flush(): Promise<void>;
|
|
596
868
|
/** Resolve once nothing is in flight. */
|
|
597
|
-
idle(): Promise<void>;
|
|
869
|
+
idle(namespace?: string): Promise<void>;
|
|
598
870
|
fault(namespace: string, fault: WebhookFault): void;
|
|
599
871
|
clear(namespace?: string): void;
|
|
600
872
|
};
|
|
@@ -605,7 +877,10 @@ type ServiceInstance = FetchAPI & {
|
|
|
605
877
|
};
|
|
606
878
|
type ServiceTimelineState = Readonly<{
|
|
607
879
|
snapshot: NamespaceSnapshot;
|
|
608
|
-
clock
|
|
880
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
881
|
+
clock: Readonly<ClockState & {
|
|
882
|
+
pinned?: boolean;
|
|
883
|
+
}>;
|
|
609
884
|
rngState: number;
|
|
610
885
|
}>;
|
|
611
886
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -618,27 +893,63 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
618
893
|
readonly sqlite: SqliteClient$1;
|
|
619
894
|
readonly clock: Clock;
|
|
620
895
|
readonly faults: FaultRegistry;
|
|
896
|
+
/** Baseline response time per namespace. */
|
|
897
|
+
readonly latency: LatencyRegistry;
|
|
621
898
|
readonly metrics: Metrics;
|
|
622
899
|
readonly journal: Journal;
|
|
623
900
|
readonly rng: Rng;
|
|
624
901
|
readonly credentials: CredentialRegistry;
|
|
625
902
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
626
903
|
readonly webhooks: WebhookHub | undefined;
|
|
627
|
-
/**
|
|
628
|
-
|
|
904
|
+
/**
|
|
905
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
906
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
907
|
+
*/
|
|
629
908
|
namespaceClock(namespace?: string): Clock;
|
|
630
909
|
namespaceOf(request: Request): string;
|
|
631
910
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
632
911
|
fleetSnapshot(namespace: string): object;
|
|
633
912
|
fleetRestore(snapshot: unknown, namespace: string): void;
|
|
913
|
+
fleetExport(snapshot: unknown): SnapshotDocument;
|
|
914
|
+
fleetImport(namespace: string, document: unknown): object;
|
|
634
915
|
/** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
|
|
635
916
|
applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
|
|
636
917
|
/** The instance behind `namespace` (the default one when omitted), created on first use. */
|
|
637
918
|
instance(namespace?: string): T;
|
|
638
919
|
/** Public names of every namespace created so far. */
|
|
639
920
|
namespaces(): string[];
|
|
640
|
-
/**
|
|
921
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
641
922
|
reset(namespace?: string): Promise<void>;
|
|
923
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
924
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
925
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
926
|
+
controls(namespace?: string): ControlState & {
|
|
927
|
+
snapshots: SnapshotInfo[];
|
|
928
|
+
};
|
|
929
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
930
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
931
|
+
snapshots: SnapshotInfo[];
|
|
932
|
+
};
|
|
933
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
934
|
+
readonly snapshots: {
|
|
935
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
936
|
+
create(options?: {
|
|
937
|
+
name?: string;
|
|
938
|
+
namespace?: string;
|
|
939
|
+
}): SnapshotInfo;
|
|
940
|
+
list(namespace?: string): SnapshotInfo[];
|
|
941
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
942
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
943
|
+
/** Store a document as a snapshot without restoring it. */
|
|
944
|
+
import(document: SnapshotDocument, options?: {
|
|
945
|
+
name?: string;
|
|
946
|
+
namespace?: string;
|
|
947
|
+
}): SnapshotInfo;
|
|
948
|
+
restore(id: string, namespace?: string): void;
|
|
949
|
+
delete(id: string, namespace?: string): boolean;
|
|
950
|
+
};
|
|
951
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
952
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
642
953
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
643
954
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
644
955
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -1133,6 +1444,8 @@ type OAuthRuntimeOptions = Omit<OAuthAPIOptions, "namespace" | "now" | "publicNa
|
|
|
1133
1444
|
clock?: Clock;
|
|
1134
1445
|
adminPrefix?: string;
|
|
1135
1446
|
adminKey?: string;
|
|
1447
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
1448
|
+
adminControls?: MockControls;
|
|
1136
1449
|
seed?: number | string;
|
|
1137
1450
|
sqlite?: SqliteClient;
|
|
1138
1451
|
/** Internal storage/runtime name. Multi-mount composition assigns a unique value. */
|
|
@@ -1152,6 +1465,8 @@ type OAuthMultiRuntimeOptions = {
|
|
|
1152
1465
|
sqlite?: SqliteClient;
|
|
1153
1466
|
adminPrefix?: string;
|
|
1154
1467
|
adminKey?: string;
|
|
1468
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
1469
|
+
adminControls?: MockControls;
|
|
1155
1470
|
seed?: number | string;
|
|
1156
1471
|
};
|
|
1157
1472
|
type OAuthMultiRuntime = {
|