@crvouga/mockingbird-runtime 0.5.0 → 0.7.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.
@@ -7,7 +7,7 @@ import {
7
7
  createMetrics,
8
8
  maskCredential,
9
9
  resolveAdminPrefix
10
- } from "../chunk-GAIPLMRY.js";
10
+ } from "../chunk-MZMSHIAI.js";
11
11
  import "../chunk-U36J5GCB.js";
12
12
 
13
13
  // ../service/core/dist/engine-admin.js
package/dist/service.d.ts CHANGED
@@ -174,6 +174,25 @@ type UpstreamOptions = {
174
174
  };
175
175
  declare const upstreamRequest: (request: Request, baseUrl: string) => Request;
176
176
 
177
+ /** An admission quota applied on the namespace clock. */
178
+ type FaultLimit = {
179
+ requests: number;
180
+ per: Duration;
181
+ key?: "namespace" | "credential";
182
+ window?: "fixed" | "sliding";
183
+ };
184
+ type LimitState = {
185
+ used: number;
186
+ windowStart: number | null;
187
+ windowResetsAt: number | null;
188
+ };
189
+ type LimitBucket = {
190
+ start: number;
191
+ used: number;
192
+ } | {
193
+ arrivals: number[];
194
+ };
195
+
177
196
  /**
178
197
  * Seeded pseudo-random numbers, so anything a mock invents — ids, jitter, which
179
198
  * request a percentage fault hits — is reproducible from a seed.
@@ -244,6 +263,8 @@ type FaultRule = {
244
263
  * rules added through `POST /__admin/faults` default to the calling namespace.
245
264
  */
246
265
  namespace?: string;
266
+ /** Admit at most this many matching requests per window. */
267
+ limit?: FaultLimit;
247
268
  /** Let this many matching requests through first. */
248
269
  after?: number;
249
270
  /** Then fault only every nth matching request: `3` faults the 3rd, 6th, 9th. */
@@ -363,13 +384,17 @@ type FaultCandidate = {
363
384
  * `undefined` for a body that is missing or not JSON. It must leave the request readable.
364
385
  */
365
386
  readJson?: () => Promise<unknown>;
387
+ /** The service-specific credential, if it has one. */
388
+ credential?: () => string | undefined;
366
389
  /** The namespace clock, for `from` / `until`. Rules with a window are skipped without it. */
367
390
  now?: number;
391
+ /** Read the clock again after asynchronous request matching. */
392
+ clockNow?: () => number;
368
393
  /** How to spend a delay for this request. Default: the registry's own sleep. */
369
394
  wait?: (ms: number) => Promise<void>;
370
395
  };
371
396
  /** A stored rule and how often it was consulted. */
372
- type FaultListing = FaultRule & {
397
+ type FaultListing = FaultRule & Partial<LimitState> & {
373
398
  /** Faults left before the rule retires. `null` when it has no `count`. */
374
399
  remaining: number | null;
375
400
  /** Times the rule faulted a request. */
@@ -385,6 +410,7 @@ type FaultSnapshot = {
385
410
  */
386
411
  rules: (FaultListing & {
387
412
  position?: number;
413
+ limitBuckets?: [string, LimitBucket][];
388
414
  })[];
389
415
  /** How many `fault_<n>` ids the namespace has handed out. */
390
416
  nextId?: number;
@@ -439,7 +465,7 @@ declare const normalizeFault: (input: unknown, context?: {
439
465
  * registry used on its own: it serves `default`, and every other namespace gets a stream of
440
466
  * its own from the same seed.
441
467
  */
442
- declare const createFaultRegistry: (random?: Rng | ((namespace: string) => Rng), sleep?: (ms: number) => Promise<void>) => FaultRegistry;
468
+ declare const createFaultRegistry: (random?: Rng | ((namespace: string) => Rng), sleep?: (ms: number) => Promise<void>, now?: (namespace: string) => number) => FaultRegistry;
443
469
 
444
470
  /**
445
471
  * The admin controls every mock shares, as one document.
@@ -2226,6 +2252,8 @@ type WebhookEndpoint = {
2226
2252
  tags?: Record<string, string>;
2227
2253
  /** The public URL the receiver verifies signatures against (Twilio), when it differs. */
2228
2254
  signUrl?: string;
2255
+ /** Disable automatic retry attempts for this endpoint. Explicit replay remains available. */
2256
+ retry?: false;
2229
2257
  headers?: Record<string, string>;
2230
2258
  };
2231
2259
  type WebhookMessage = {
@@ -2276,6 +2304,8 @@ type PublishInput = {
2276
2304
  tags?: Record<string, string>;
2277
2305
  /** Message-specific delivery headers, captured as part of durable message state. */
2278
2306
  headers?: Record<string, string>;
2307
+ /** Additional delivery endpoint for this message only. */
2308
+ endpoint?: WebhookEndpoint;
2279
2309
  /** Message id; generated when omitted. */
2280
2310
  id?: string;
2281
2311
  };
@@ -2382,6 +2412,8 @@ type RuntimeOptions<T extends ServiceInstance> = {
2382
2412
  /** Reject unsupported forwarding surfaces before any network request. */
2383
2413
  canForward?: (request: Request) => boolean;
2384
2414
  upstreamRequest?: (request: Request, baseUrl: string) => Request;
2415
+ /** Return an emulated refusal before request fault rules are consumed. Read from a request clone. */
2416
+ beforeFaults?: (instance: T, request: Request) => Response | undefined | Promise<Response | undefined>;
2385
2417
  /** Service name, e.g. `"junction"`. Also the default namespace's storage key. */
2386
2418
  name: string;
2387
2419
  /** Build the instance backing one namespace. Called once per namespace, on first use. */
package/dist/service.js CHANGED
@@ -67,7 +67,7 @@ import {
67
67
  verifyOperations,
68
68
  webhookAdminRoutes,
69
69
  withNamespaceRollback
70
- } from "./chunk-BK5KDNUE.js";
70
+ } from "./chunk-CIJF35LX.js";
71
71
  import "./chunk-2KDYLZXC.js";
72
72
  import {
73
73
  ADMIN_CONTROL_PAGES,
@@ -129,7 +129,7 @@ import {
129
129
  toBase64,
130
130
  toHex,
131
131
  upstreamRequest
132
- } from "./chunk-GAIPLMRY.js";
132
+ } from "./chunk-MZMSHIAI.js";
133
133
  import {
134
134
  requestBaseUrl
135
135
  } from "./chunk-U36J5GCB.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crvouga/mockingbird-runtime",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "The shared Mockingbird runtime every emulator service depends on: router, admin API and page, snapshots, faults and clock, installed once however many emulators an application uses.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,6 +16,10 @@
16
16
  "types": "./dist/index.d.ts",
17
17
  "default": "./dist/index.js"
18
18
  },
19
+ "./authoring": {
20
+ "types": "./dist/authoring.d.ts",
21
+ "default": "./dist/authoring.js"
22
+ },
19
23
  "./core": {
20
24
  "types": "./dist/core.d.ts",
21
25
  "default": "./dist/core.js"
@@ -120,8 +124,8 @@
120
124
  "graphql": "17.0.0",
121
125
  "hono": "4.13.11",
122
126
  "jose": "6.2.2",
123
- "@crvouga/mockingbird-ui": "0.5.0",
124
- "@crvouga/mockingbird-preview": "0.3.0"
127
+ "@crvouga/mockingbird-ui": "0.6.0",
128
+ "@crvouga/mockingbird-preview": "0.3.1"
125
129
  },
126
130
  "devDependencies": {
127
131
  "@crvouga/mockingbird-adapter-node": "0.0.0-development",