@crvouga/mockingbird-service-workos 1.1.0 → 1.2.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 +6 -4
- package/DISCOVERY.md +23 -0
- package/README.md +28 -3
- package/dist/chunk-LE5B6IJG.js +5417 -0
- package/dist/chunk-LE5B6IJG.js.map +7 -0
- package/dist/{chunk-BIGV6FI5.js → chunk-X5OR3IYU.js} +136 -25
- package/dist/chunk-X5OR3IYU.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.d.ts +339 -40
- package/dist/index.js +1 -1
- package/dist/server.d.ts +678 -80
- package/dist/server.js +2 -2
- package/package.json +3 -2
- package/dist/chunk-BIGV6FI5.js.map +0 -7
- package/dist/chunk-JITNKKHL.js +0 -3626
- package/dist/chunk-JITNKKHL.js.map +0 -7
package/dist/index.d.ts
CHANGED
|
@@ -239,7 +239,7 @@ type ClockState = {
|
|
|
239
239
|
now: number;
|
|
240
240
|
/** True while time does not advance on its own. */
|
|
241
241
|
frozen: boolean;
|
|
242
|
-
/** Milliseconds
|
|
242
|
+
/** Milliseconds a running clock adds to its underlying source. `0` while frozen. */
|
|
243
243
|
offsetMs: number;
|
|
244
244
|
};
|
|
245
245
|
type Clock = {
|
|
@@ -275,7 +275,10 @@ type Rng = {
|
|
|
275
275
|
state(): number;
|
|
276
276
|
/** Restore a state previously returned by {@link state}. */
|
|
277
277
|
setState(state: number): void;
|
|
278
|
-
seed
|
|
278
|
+
/** Restart the stream from a new seed. `reset` then returns to this seed. */
|
|
279
|
+
reseed(seed: number | string): void;
|
|
280
|
+
/** The seed the stream currently starts from. */
|
|
281
|
+
readonly seed: number;
|
|
279
282
|
};
|
|
280
283
|
|
|
281
284
|
/**
|
|
@@ -284,44 +287,83 @@ type Rng = {
|
|
|
284
287
|
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
285
288
|
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
286
289
|
* appears under load, the 5xx that proves a retry path works.
|
|
290
|
+
*
|
|
291
|
+
* A rule has three parts. What it **matches** (`operationId`, `method`, `path`, …), **when**
|
|
292
|
+
* it fires among the matching requests (`after`, `every`, `count`, `rate`, `from`, `until`),
|
|
293
|
+
* and what it **does** (`status`, `delay`, `timeout`, `drop`, `truncate`, `effect`).
|
|
287
294
|
*/
|
|
288
295
|
type FaultRule = {
|
|
289
|
-
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
296
|
+
/** Stable id, so a suite can retire exactly the rule it added. Unique within a namespace. */
|
|
290
297
|
id: string;
|
|
291
298
|
/** Fault only this operation. Omit to match every operation. */
|
|
292
299
|
operationId?: string;
|
|
293
300
|
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
294
301
|
method?: string;
|
|
302
|
+
/** Fault only this exact path. */
|
|
303
|
+
path?: string;
|
|
295
304
|
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
296
305
|
pathPrefix?: string;
|
|
306
|
+
/** Fault only paths matching this regular expression (JavaScript syntax, unanchored). */
|
|
307
|
+
pathPattern?: string;
|
|
308
|
+
/** Fault only requests carrying these headers. `"*"` matches any value. */
|
|
309
|
+
requestHeaders?: Record<string, string>;
|
|
310
|
+
/** Fault only requests carrying these query parameters. `"*"` matches any value. */
|
|
311
|
+
query?: Record<string, string>;
|
|
297
312
|
/**
|
|
298
313
|
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
299
314
|
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
300
315
|
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
301
316
|
*/
|
|
302
317
|
namespace?: string;
|
|
318
|
+
/** Let this many matching requests through first. */
|
|
319
|
+
after?: number;
|
|
320
|
+
/** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
|
|
321
|
+
every?: number;
|
|
322
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
323
|
+
count?: number;
|
|
324
|
+
/** Fault this fraction of the remaining requests, `0`–`1`, drawn from the seed. Default `1`. */
|
|
325
|
+
rate?: number;
|
|
326
|
+
/**
|
|
327
|
+
* Fault only from this instant on the namespace clock. A duration (`"5m"`) counts from the
|
|
328
|
+
* clock when the rule was added. Listed as epoch ms.
|
|
329
|
+
*/
|
|
330
|
+
from?: Instant | Duration;
|
|
331
|
+
/** Stop faulting at this instant on the namespace clock. A duration counts from when added. */
|
|
332
|
+
until?: Instant | Duration;
|
|
303
333
|
/**
|
|
304
|
-
* Status of the injected response. Omit for a rule that only delays
|
|
305
|
-
*
|
|
306
|
-
* the request then still reaches the service.
|
|
334
|
+
* Status of the injected response. Omit for a rule that only delays, times out, drops,
|
|
335
|
+
* truncates, or switches on an `effect`: the request then still reaches the service.
|
|
307
336
|
*/
|
|
308
337
|
status?: number;
|
|
309
338
|
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
310
339
|
body?: unknown;
|
|
340
|
+
/** Response headers. */
|
|
311
341
|
headers?: Record<string, string>;
|
|
312
|
-
/**
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
rate?: number;
|
|
316
|
-
/** Hold the response back this long, to exercise timeouts. */
|
|
342
|
+
/** Hold the response back this long. Listed as `delayMs`. */
|
|
343
|
+
delay?: Duration;
|
|
344
|
+
/** `delay`, in milliseconds. */
|
|
317
345
|
delayMs?: number;
|
|
318
346
|
/** Alias of `delayMs`. */
|
|
319
347
|
latencyMs?: number;
|
|
348
|
+
/** Extra seeded delay in `[0, jitter]`. Listed as `jitterMs`. */
|
|
349
|
+
jitter?: Duration;
|
|
350
|
+
jitterMs?: number;
|
|
351
|
+
/**
|
|
352
|
+
* Never answer: hold the request this long, then drop the connection. Listed as
|
|
353
|
+
* `timeoutMs`. With virtual time the wait is spent on the mock clock.
|
|
354
|
+
*/
|
|
355
|
+
timeout?: Duration;
|
|
356
|
+
timeoutMs?: number;
|
|
320
357
|
/**
|
|
321
358
|
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
322
359
|
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
323
360
|
*/
|
|
324
361
|
drop?: boolean;
|
|
362
|
+
/**
|
|
363
|
+
* Cut the response body off after this many bytes: the status and headers arrive, then
|
|
364
|
+
* the connection dies mid-body.
|
|
365
|
+
*/
|
|
366
|
+
truncate?: number;
|
|
325
367
|
/**
|
|
326
368
|
* A named service behaviour to switch on for the matching request instead of (or
|
|
327
369
|
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
@@ -330,8 +372,8 @@ type FaultRule = {
|
|
|
330
372
|
effect?: string;
|
|
331
373
|
/** Parameters for `effect`. */
|
|
332
374
|
params?: Record<string, unknown>;
|
|
333
|
-
/**
|
|
334
|
-
|
|
375
|
+
/** The preset this rule was expanded from, if any. */
|
|
376
|
+
fromPreset?: string;
|
|
335
377
|
};
|
|
336
378
|
/** A fault that fired for one request. */
|
|
337
379
|
type FaultHit = {
|
|
@@ -339,6 +381,10 @@ type FaultHit = {
|
|
|
339
381
|
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
340
382
|
response?: Response;
|
|
341
383
|
drop?: boolean;
|
|
384
|
+
/** Set with `drop` when the rule held the request for its `timeout` first. */
|
|
385
|
+
timeout?: boolean;
|
|
386
|
+
/** Bytes of response body to let through before the connection dies. */
|
|
387
|
+
truncate?: number;
|
|
342
388
|
effect?: {
|
|
343
389
|
name: string;
|
|
344
390
|
params: Record<string, unknown>;
|
|
@@ -363,38 +409,200 @@ type FaultCandidate = {
|
|
|
363
409
|
method: string;
|
|
364
410
|
path: string;
|
|
365
411
|
namespace: string;
|
|
412
|
+
/** Request headers and query, for rules that match on them. */
|
|
413
|
+
headers?: Headers;
|
|
414
|
+
query?: URLSearchParams;
|
|
415
|
+
/** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
|
|
416
|
+
now?: number;
|
|
417
|
+
/** How to spend a delay for this request. Default: the registry's own sleep. */
|
|
418
|
+
wait?: (ms: number) => Promise<void>;
|
|
419
|
+
};
|
|
420
|
+
/** A stored rule and how often it was consulted. */
|
|
421
|
+
type FaultListing = FaultRule & {
|
|
422
|
+
/** Faults left before the rule retires. `null` when it has no `count`. */
|
|
423
|
+
remaining: number | null;
|
|
424
|
+
/** Times the rule faulted a request. */
|
|
425
|
+
hits: number;
|
|
426
|
+
/** Requests that matched the rule, faulted or not. */
|
|
427
|
+
seen: number;
|
|
428
|
+
};
|
|
429
|
+
/** A namespace's own rules, with their counters, in the order they are tried. */
|
|
430
|
+
type FaultSnapshot = {
|
|
431
|
+
/**
|
|
432
|
+
* `position` is how many `"*"` rules are tried before the rule, which is what its place
|
|
433
|
+
* in the order means to a request and holds in any process.
|
|
434
|
+
*/
|
|
435
|
+
rules: (FaultListing & {
|
|
436
|
+
position?: number;
|
|
437
|
+
})[];
|
|
438
|
+
/** How many `fault_<n>` ids the namespace has handed out. */
|
|
439
|
+
nextId?: number;
|
|
366
440
|
};
|
|
367
441
|
type FaultRegistry = {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
rules: (FaultRule & {
|
|
371
|
-
remaining: number | null;
|
|
372
|
-
hits: number;
|
|
373
|
-
position: number;
|
|
374
|
-
})[];
|
|
375
|
-
rngState: number;
|
|
376
|
-
};
|
|
442
|
+
snapshot(namespace: string): FaultSnapshot;
|
|
443
|
+
/** Add a rule, or replace the rule with the same id in the same namespace. */
|
|
377
444
|
add(rule: FaultRule): FaultRule;
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
})[];
|
|
390
|
-
rngState: number;
|
|
391
|
-
}): void;
|
|
445
|
+
/** The next unused `fault_<n>` id in `namespace`. */
|
|
446
|
+
nextId(namespace: string): string;
|
|
447
|
+
/** Every rule, or the rules a namespace's requests can hit: its own and the global ones. */
|
|
448
|
+
list(namespace?: string): FaultListing[];
|
|
449
|
+
get(id: string, namespace?: string): FaultListing | undefined;
|
|
450
|
+
/** Remove a rule by id: from `namespace` (its own, then a global one), or wherever it is. */
|
|
451
|
+
remove(id: string, namespace?: string): boolean;
|
|
452
|
+
/** Remove every rule, or one namespace's own rules. */
|
|
453
|
+
clear(namespace?: string): void;
|
|
454
|
+
/** Replace a namespace's own rules with a snapshot's, wherever the snapshot was taken. */
|
|
455
|
+
restore(namespace: string, state: FaultSnapshot): void;
|
|
392
456
|
/**
|
|
393
457
|
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
394
458
|
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
395
459
|
* each matching rule's remaining uses.
|
|
396
460
|
*/
|
|
397
461
|
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
462
|
+
/**
|
|
463
|
+
* Fire these rules at one request without storing them: no matching, no schedule, in order,
|
|
464
|
+
* stopping at the first that answers or drops. Jitter draws from the namespace's stream.
|
|
465
|
+
*/
|
|
466
|
+
fire(rules: readonly FaultRule[], candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* The admin controls every mock shares, as one document.
|
|
471
|
+
*
|
|
472
|
+
* The same shape is accepted in three places, and means the same thing in each:
|
|
473
|
+
*
|
|
474
|
+
* - at boot: `createRuntime({ adminControls })`, `serve --admin-controls`,
|
|
475
|
+
* `MOCKINGBIRD_ADMIN_CONTROLS`
|
|
476
|
+
* - over HTTP: `PUT /__admin/controls`
|
|
477
|
+
* - per request: the `x-mockingbird-*` headers in {@link CONTROL_HEADERS}
|
|
478
|
+
*
|
|
479
|
+
* Every control is deterministic: given the same seed, clock and requests, a mock answers
|
|
480
|
+
* the same bytes. Nothing here reads the wall clock or `Math.random`.
|
|
481
|
+
*/
|
|
482
|
+
/** Milliseconds, or a string like `"250ms"`, `"2s"`, `"15m"`, `"1h"`, `"3d"`. */
|
|
483
|
+
type Duration = number | string;
|
|
484
|
+
/** Epoch milliseconds, or an ISO-8601 string. */
|
|
485
|
+
type Instant = number | string;
|
|
486
|
+
type ClockControls = {
|
|
487
|
+
/** Move the clock to this instant. */
|
|
488
|
+
now?: Instant;
|
|
489
|
+
/** Stop time. A frozen clock moves only when told to, so timestamps replay exactly. */
|
|
490
|
+
frozen?: boolean;
|
|
491
|
+
/**
|
|
492
|
+
* Step the clock forward by this much before every vendor request. With a frozen clock
|
|
493
|
+
* each request still gets its own, reproducible timestamp.
|
|
494
|
+
*/
|
|
495
|
+
autoAdvance?: Duration;
|
|
496
|
+
};
|
|
497
|
+
/** How long a response takes: a fixed delay plus seeded jitter in `[0, jitter]`. */
|
|
498
|
+
type LatencyRuleInput = {
|
|
499
|
+
delay?: Duration;
|
|
500
|
+
jitter?: Duration;
|
|
501
|
+
};
|
|
502
|
+
type LatencyControls = LatencyRuleInput & {
|
|
503
|
+
/** Per-operation overrides, keyed by operationId. A bare duration is its `delay`. */
|
|
504
|
+
operations?: Record<string, Duration | LatencyRuleInput>;
|
|
505
|
+
};
|
|
506
|
+
/** A fault to add: a rule (the id is assigned when omitted), or a named preset with overrides. */
|
|
507
|
+
type FaultInput = (Omit<FaultRule, "id"> & {
|
|
508
|
+
id?: string;
|
|
509
|
+
}) | ({
|
|
510
|
+
preset: string;
|
|
511
|
+
} & Partial<FaultRule>);
|
|
512
|
+
/** Identifies a {@link SnapshotDocument}. */
|
|
513
|
+
declare const SNAPSHOT_FORMAT = "mockingbird.snapshot/v1";
|
|
514
|
+
/**
|
|
515
|
+
* A namespace, as portable JSON: what `GET /__admin/snapshots/:id` returns and what
|
|
516
|
+
* `PUT /__admin/snapshots/:id` and the boot `snapshot` control accept. Only `format` and
|
|
517
|
+
* `records` are required, so a hand-written seed file is a valid snapshot.
|
|
518
|
+
*/
|
|
519
|
+
type SnapshotDocument = {
|
|
520
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
521
|
+
/** The service that wrote it. A snapshot is rejected by any other service. */
|
|
522
|
+
service?: string;
|
|
523
|
+
/**
|
|
524
|
+
* Stored rows. `seq` orders a collection; omitted, rows keep their listed order. `raw` is
|
|
525
|
+
* the stored text of a row that is not a plain record, and replaces `value` when present.
|
|
526
|
+
*/
|
|
527
|
+
records: {
|
|
528
|
+
collection: string;
|
|
529
|
+
id: string;
|
|
530
|
+
seq?: number;
|
|
531
|
+
value?: unknown;
|
|
532
|
+
raw?: string;
|
|
533
|
+
}[];
|
|
534
|
+
/** Id counters, so the next generated id continues where the snapshot left off. */
|
|
535
|
+
sequences?: {
|
|
536
|
+
name: string;
|
|
537
|
+
kind: string;
|
|
538
|
+
value: number;
|
|
539
|
+
}[];
|
|
540
|
+
clock?: {
|
|
541
|
+
now: number;
|
|
542
|
+
frozen: boolean;
|
|
543
|
+
autoAdvanceMs?: number;
|
|
544
|
+
};
|
|
545
|
+
seed?: number | string;
|
|
546
|
+
/** Positions of the seeded random streams. */
|
|
547
|
+
rng?: {
|
|
548
|
+
state: number;
|
|
549
|
+
faults?: number;
|
|
550
|
+
latency?: number;
|
|
551
|
+
};
|
|
552
|
+
faults?: unknown;
|
|
553
|
+
latency?: unknown;
|
|
554
|
+
virtualTime?: boolean;
|
|
555
|
+
};
|
|
556
|
+
/** Controls for one namespace. */
|
|
557
|
+
type NamespaceControls = {
|
|
558
|
+
/** Seeds every random choice: fault rates, jitter, and whatever the service invents. */
|
|
559
|
+
seed?: number | string;
|
|
560
|
+
clock?: ClockControls;
|
|
561
|
+
/**
|
|
562
|
+
* Spend injected waits (latency, fault delays, timeouts) on the mock clock instead of the
|
|
563
|
+
* wall clock: the request returns at once, the clock has moved, and the journal records
|
|
564
|
+
* the wait exactly. Default `false`: waits are real, so a client's own timeout can fire.
|
|
565
|
+
*/
|
|
566
|
+
virtualTime?: boolean;
|
|
567
|
+
/** Baseline response time for every vendor request. A bare duration is its `delay`. */
|
|
568
|
+
latency?: Duration | LatencyControls;
|
|
569
|
+
faults?: readonly FaultInput[];
|
|
570
|
+
/** Start from this state instead of the service's own seed data. */
|
|
571
|
+
snapshot?: SnapshotDocument;
|
|
572
|
+
};
|
|
573
|
+
/** {@link NamespaceControls} for every namespace, with per-namespace overrides. */
|
|
574
|
+
type MockControls = NamespaceControls & {
|
|
575
|
+
/** Vendor credential → namespace, for SDKs that cannot send a namespace header. */
|
|
576
|
+
credentials?: Record<string, string>;
|
|
577
|
+
/** Overrides for named namespaces. A key given here replaces the shared value. */
|
|
578
|
+
namespaces?: Record<string, NamespaceControls>;
|
|
579
|
+
};
|
|
580
|
+
/** A latency rule in milliseconds. */
|
|
581
|
+
type LatencyRule = {
|
|
582
|
+
delayMs: number;
|
|
583
|
+
jitterMs: number;
|
|
584
|
+
};
|
|
585
|
+
/** Baseline latency for a namespace, normalized. */
|
|
586
|
+
type LatencyState = LatencyRule & {
|
|
587
|
+
operations: Record<string, LatencyRule>;
|
|
588
|
+
};
|
|
589
|
+
/** What {@link controlHeaders} turns into request headers. */
|
|
590
|
+
type ControlHeaderInput = {
|
|
591
|
+
namespace?: string;
|
|
592
|
+
adminKey?: string;
|
|
593
|
+
branch?: string;
|
|
594
|
+
at?: string;
|
|
595
|
+
reset?: boolean;
|
|
596
|
+
restore?: string;
|
|
597
|
+
seed?: number | string;
|
|
598
|
+
time?: Instant | Date;
|
|
599
|
+
advance?: Duration;
|
|
600
|
+
virtualTime?: boolean;
|
|
601
|
+
delay?: Duration;
|
|
602
|
+
timeout?: Duration;
|
|
603
|
+
/** A status, `"drop"`, a preset name, or a fault rule. */
|
|
604
|
+
fault?: number | string | Record<string, unknown>;
|
|
605
|
+
snapshot?: string;
|
|
398
606
|
};
|
|
399
607
|
|
|
400
608
|
/**
|
|
@@ -434,6 +642,8 @@ type RequestLog = {
|
|
|
434
642
|
unmatched: boolean;
|
|
435
643
|
/** Set when a fault rule produced the response. */
|
|
436
644
|
faultId?: string;
|
|
645
|
+
/** Milliseconds of injected wait: latency, fault delays and timeouts. Absent when none. */
|
|
646
|
+
delayMs?: number;
|
|
437
647
|
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
438
648
|
ids?: Record<string, string>;
|
|
439
649
|
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
@@ -479,6 +689,12 @@ type JournalQuery = {
|
|
|
479
689
|
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
480
690
|
namespace?: string;
|
|
481
691
|
operationId?: string;
|
|
692
|
+
/** Only this HTTP method, case-insensitive. */
|
|
693
|
+
method?: string;
|
|
694
|
+
/** Only this exact path. */
|
|
695
|
+
path?: string;
|
|
696
|
+
/** Only requests this fault rule answered or shaped. */
|
|
697
|
+
faultId?: string;
|
|
482
698
|
status?: number;
|
|
483
699
|
/** Only entries at or after this instant (epoch ms). */
|
|
484
700
|
since?: number;
|
|
@@ -493,6 +709,50 @@ type Journal = {
|
|
|
493
709
|
clear(namespace?: string): void;
|
|
494
710
|
};
|
|
495
711
|
|
|
712
|
+
/**
|
|
713
|
+
* Baseline response time, per namespace: how long every vendor request takes before any
|
|
714
|
+
* fault is considered. Jitter draws from a stream the caller owns, one per namespace and
|
|
715
|
+
* separate from the fault stream, so adding latency never shifts which requests a `rate`
|
|
716
|
+
* fault hits.
|
|
717
|
+
*/
|
|
718
|
+
type LatencyRegistry = {
|
|
719
|
+
get(namespace: string): LatencyState;
|
|
720
|
+
set(namespace: string, state: LatencyState): LatencyState;
|
|
721
|
+
/** Remove one namespace's latency, or every namespace's. */
|
|
722
|
+
clear(namespace?: string): void;
|
|
723
|
+
/** Milliseconds this request waits. Draws jitter, so call it once per request. */
|
|
724
|
+
take(namespace: string, operationId: string | undefined): number;
|
|
725
|
+
};
|
|
726
|
+
|
|
727
|
+
/** Clock state as the admin API reports it. */
|
|
728
|
+
type ControlClock = ClockState & {
|
|
729
|
+
/** `now`, as ISO-8601. */
|
|
730
|
+
iso: string;
|
|
731
|
+
/** Milliseconds the clock steps before every vendor request. */
|
|
732
|
+
autoAdvanceMs: number;
|
|
733
|
+
};
|
|
734
|
+
/** One namespace's controls: the body of `GET /__admin/controls`. */
|
|
735
|
+
type ControlState = {
|
|
736
|
+
namespace: string;
|
|
737
|
+
seed: number | string;
|
|
738
|
+
clock: ControlClock;
|
|
739
|
+
virtualTime: boolean;
|
|
740
|
+
latency: LatencyState;
|
|
741
|
+
faults: FaultListing[];
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
/** What `GET /__admin/snapshots` lists for each snapshot. */
|
|
745
|
+
type SnapshotInfo = {
|
|
746
|
+
id: string;
|
|
747
|
+
namespace: string;
|
|
748
|
+
/** Stored rows in the snapshot. */
|
|
749
|
+
records: number;
|
|
750
|
+
/** The namespace clock when it was taken, epoch ms. */
|
|
751
|
+
at: number;
|
|
752
|
+
/** Whether `GET /snapshots/:id` can return it as a {@link SnapshotDocument}. */
|
|
753
|
+
portable: boolean;
|
|
754
|
+
};
|
|
755
|
+
|
|
496
756
|
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
497
757
|
type CredentialRegistry = {
|
|
498
758
|
set(credential: string, namespace: string): void;
|
|
@@ -647,7 +907,10 @@ type ServiceInstance = FetchAPI & {
|
|
|
647
907
|
};
|
|
648
908
|
type ServiceTimelineState = Readonly<{
|
|
649
909
|
snapshot: NamespaceSnapshot;
|
|
650
|
-
clock
|
|
910
|
+
/** `pinned`: the namespace's clock was frozen itself, not just following a frozen base. */
|
|
911
|
+
clock: Readonly<ClockState & {
|
|
912
|
+
pinned?: boolean;
|
|
913
|
+
}>;
|
|
651
914
|
rngState: number;
|
|
652
915
|
}>;
|
|
653
916
|
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
@@ -660,14 +923,18 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
660
923
|
readonly sqlite: SqliteClient;
|
|
661
924
|
readonly clock: Clock;
|
|
662
925
|
readonly faults: FaultRegistry;
|
|
926
|
+
/** Baseline response time per namespace. */
|
|
927
|
+
readonly latency: LatencyRegistry;
|
|
663
928
|
readonly metrics: Metrics;
|
|
664
929
|
readonly journal: Journal;
|
|
665
930
|
readonly rng: Rng;
|
|
666
931
|
readonly credentials: CredentialRegistry;
|
|
667
932
|
/** The webhook hub, when the service has outbound webhooks. */
|
|
668
933
|
readonly webhooks: WebhookHub | undefined;
|
|
669
|
-
/**
|
|
670
|
-
|
|
934
|
+
/**
|
|
935
|
+
* A namespace's clock. Each follows the base clock, {@link ServiceRuntime.clock}, with an
|
|
936
|
+
* offset and a freeze of its own, so moving one never moves another.
|
|
937
|
+
*/
|
|
671
938
|
namespaceClock(namespace?: string): Clock;
|
|
672
939
|
namespaceOf(request: Request): string;
|
|
673
940
|
/** Opaque in-process checkpoint including records, controls and webhook history. */
|
|
@@ -679,8 +946,38 @@ type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
|
679
946
|
instance(namespace?: string): T;
|
|
680
947
|
/** Public names of every namespace created so far. */
|
|
681
948
|
namespaces(): string[];
|
|
682
|
-
/**
|
|
949
|
+
/** Return one namespace to its boot state, or every namespace with `"*"`. */
|
|
683
950
|
reset(namespace?: string): Promise<void>;
|
|
951
|
+
/** Reset a namespace and forget it, releasing everything it held. */
|
|
952
|
+
dropNamespace(namespace: string): Promise<void>;
|
|
953
|
+
/** A namespace's controls: seed, clock, virtual time, latency, faults and snapshots. */
|
|
954
|
+
controls(namespace?: string): ControlState & {
|
|
955
|
+
snapshots: SnapshotInfo[];
|
|
956
|
+
};
|
|
957
|
+
/** Apply a control document to a namespace. A given key replaces that control. */
|
|
958
|
+
configure(controls: NamespaceControls, namespace?: string): ControlState & {
|
|
959
|
+
snapshots: SnapshotInfo[];
|
|
960
|
+
};
|
|
961
|
+
/** Named snapshots of a namespace: records, clock, random streams, faults and latency. */
|
|
962
|
+
readonly snapshots: {
|
|
963
|
+
/** Capture the namespace now. Reusing a name replaces that snapshot. */
|
|
964
|
+
create(options?: {
|
|
965
|
+
name?: string;
|
|
966
|
+
namespace?: string;
|
|
967
|
+
}): SnapshotInfo;
|
|
968
|
+
list(namespace?: string): SnapshotInfo[];
|
|
969
|
+
/** The snapshot as portable JSON, to commit beside a suite or boot another mock from. */
|
|
970
|
+
export(id: string, namespace?: string): SnapshotDocument;
|
|
971
|
+
/** Store a document as a snapshot without restoring it. */
|
|
972
|
+
import(document: SnapshotDocument, options?: {
|
|
973
|
+
name?: string;
|
|
974
|
+
namespace?: string;
|
|
975
|
+
}): SnapshotInfo;
|
|
976
|
+
restore(id: string, namespace?: string): void;
|
|
977
|
+
delete(id: string, namespace?: string): boolean;
|
|
978
|
+
};
|
|
979
|
+
/** Request headers that carry controls, checked: spread them into a `fetch` or an SDK's defaults. */
|
|
980
|
+
headers(input: ControlHeaderInput): Record<string, string>;
|
|
684
981
|
snapshot(namespace?: string): NamespaceSnapshot;
|
|
685
982
|
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
686
983
|
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
@@ -878,6 +1175,8 @@ type WorkOSRuntimeOptions = Omit<WorkOSAPIOptions, "namespace" | "now"> & {
|
|
|
878
1175
|
seed?: string | number;
|
|
879
1176
|
adminPrefix?: string;
|
|
880
1177
|
adminKey?: string;
|
|
1178
|
+
/** Admin controls to boot with: clock, latency, faults, seed, a starting snapshot. */
|
|
1179
|
+
adminControls?: MockControls;
|
|
881
1180
|
onLog?: (entry: RequestLog) => void;
|
|
882
1181
|
};
|
|
883
1182
|
type WorkOSRuntime = ServiceRuntime<WorkOSAPI>;
|