@crvouga/mockingbird-service-customerio 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 CHANGED
@@ -1,14 +1,28 @@
1
1
  # Changelog — @crvouga/mockingbird-service-customerio
2
2
 
3
- ## 3.3.0 (2026-10-12)
3
+ ## 3.5.0 (2026-10-16)
4
4
 
5
5
  ### Features
6
6
 
7
- - unify the emulator control plane ([2068547](https://github.com/crvouga/mockingbird/commit/2068547bedde4e2e2331c1657c1a78120e84428b))
7
+ - resolve SQL, routing and writer gaps ([73f97d0](https://github.com/crvouga/mockingbird/commit/73f97d0d2379f44b9131180498f4fab76648fed9))
8
8
 
9
- ### Dependencies
9
+ ## 3.4.0 (2026-10-15)
10
+
11
+ ### Features
12
+
13
+ - finish durable run lifecycle ([725ea1a](https://github.com/crvouga/mockingbird/commit/725ea1a966dac65434e98f06a9c33aca0d6f32d7))
14
+ - add management and portable archives ([0d2a6dd](https://github.com/crvouga/mockingbird/commit/0d2a6dd0f9fecb3a1ea7c1638f6639787395c2f4))
15
+
16
+ ### Fixes and improvements
10
17
 
11
- - `@crvouga/mockingbird-service-sqlite`
18
+ - correlate cross-namespace operations ([3457a4b](https://github.com/crvouga/mockingbird/commit/3457a4b7dbfd9ad9c8a10671a5744b7c8425d000))
19
+ - harden HTTP stream handling ([674307a](https://github.com/crvouga/mockingbird/commit/674307a869f57907567d462c4f506c3b0a237e13))
20
+
21
+ ## 3.3.0 (2026-10-12)
22
+
23
+ ### Features
24
+
25
+ - unify the emulator control plane ([2068547](https://github.com/crvouga/mockingbird/commit/2068547bedde4e2e2331c1657c1a78120e84428b))
12
26
 
13
27
  ## 3.2.0 (2026-10-08)
14
28
 
@@ -1430,7 +1430,7 @@ var assertSnapshotDocument = (value, label = "snapshot") => {
1430
1430
  });
1431
1431
  }
1432
1432
  if (value.clock !== void 0) {
1433
- if (!isRecord2(value.clock) || typeof value.clock.now !== "number" || typeof value.clock.frozen !== "boolean")
1433
+ if (!isRecord2(value.clock) || typeof value.clock.now !== "number" || !Number.isFinite(value.clock.now) || typeof value.clock.frozen !== "boolean")
1434
1434
  throw new ControlError(`${label}.clock: expected {now, frozen}`);
1435
1435
  }
1436
1436
  return value;
@@ -3328,6 +3328,91 @@ var createMetrics = (partition = true) => {
3328
3328
  };
3329
3329
  };
3330
3330
 
3331
+ // ../core/dist/outbound.js
3332
+ function ownedTransport(policy) {
3333
+ if (!["offline", "allowlist"].includes(policy.mode) || policy.origins?.some((origin) => {
3334
+ try {
3335
+ return new URL(origin).origin !== origin;
3336
+ } catch {
3337
+ return true;
3338
+ }
3339
+ }))
3340
+ throw new Error("invalid outbound transport policy");
3341
+ const reject = (namespace, reason) => {
3342
+ try {
3343
+ policy.onReject?.({ namespace, policy: policy.mode, reason });
3344
+ } catch {
3345
+ }
3346
+ throw new Error(`outbound policy ${policy.mode}: ${reason}`);
3347
+ };
3348
+ return async (request, namespace, send) => {
3349
+ if (policy.mode === "offline")
3350
+ return reject(namespace, "delivery disabled");
3351
+ const allowed = (url2) => ["http:", "https:"].includes(url2.protocol) && !url2.username && !url2.password && (policy.origins ?? []).includes(url2.origin);
3352
+ let url = new URL(request.url);
3353
+ if (!allowed(url))
3354
+ return reject(namespace, "destination not allowed");
3355
+ const max = policy.maxBodyBytes ?? 1024 * 1024;
3356
+ const chunks = [];
3357
+ let size = 0;
3358
+ const reader = request.body?.getReader();
3359
+ if (reader)
3360
+ try {
3361
+ for (; ; ) {
3362
+ const item = await reader.read();
3363
+ if (item.done)
3364
+ break;
3365
+ size += item.value.length;
3366
+ if (size > max)
3367
+ return reject(namespace, "body limit exceeded");
3368
+ chunks.push(item.value);
3369
+ }
3370
+ } finally {
3371
+ void reader.cancel().catch(() => {
3372
+ });
3373
+ reader.releaseLock();
3374
+ }
3375
+ const body = new Uint8Array(size);
3376
+ let offset = 0;
3377
+ for (const chunk of chunks) {
3378
+ body.set(chunk, offset);
3379
+ offset += chunk.length;
3380
+ }
3381
+ let method = request.method, headers = new Headers(request.headers);
3382
+ for (let redirects = 0; ; redirects++) {
3383
+ if (!allowed(url))
3384
+ return reject(namespace, "redirect destination not allowed");
3385
+ const response = await send(new Request(url, {
3386
+ method,
3387
+ headers,
3388
+ ...method !== "GET" && method !== "HEAD" ? { body } : {},
3389
+ redirect: "manual",
3390
+ signal: request.signal
3391
+ }));
3392
+ if (![301, 302, 303, 307, 308].includes(response.status))
3393
+ return response;
3394
+ const location = response.headers.get("location");
3395
+ if (!location)
3396
+ return response;
3397
+ await response.body?.cancel();
3398
+ if (redirects >= (policy.maxRedirects ?? 5))
3399
+ return reject(namespace, "redirect limit exceeded");
3400
+ const next = new URL(location, url);
3401
+ if (next.origin !== url.origin) {
3402
+ headers = new Headers(headers);
3403
+ for (const key of ["authorization", "cookie", "proxy-authorization"])
3404
+ headers.delete(key);
3405
+ }
3406
+ if (response.status === 303 || (response.status === 301 || response.status === 302) && method === "POST") {
3407
+ method = "GET";
3408
+ headers.delete("content-length");
3409
+ headers.delete("content-type");
3410
+ }
3411
+ url = next;
3412
+ }
3413
+ };
3414
+ }
3415
+
3331
3416
  // ../core/dist/outbox.js
3332
3417
  var OutboxStore = class {
3333
3418
  items;
@@ -3973,7 +4058,7 @@ var stateAdminRoutes = (routes) => {
3973
4058
  };
3974
4059
 
3975
4060
  // ../core/dist/version.js
3976
- var PACKAGE_VERSION = true ? "3.3.0" : UNRELEASED_VERSION;
4061
+ var PACKAGE_VERSION = true ? "3.5.0" : UNRELEASED_VERSION;
3977
4062
 
3978
4063
  // ../core/dist/signing.js
3979
4064
  var encoder = new TextEncoder();
@@ -4065,13 +4150,35 @@ var createWebhookHub = (options) => {
4065
4150
  const payloads = /* @__PURE__ */ new Map();
4066
4151
  const faults = /* @__PURE__ */ new Map();
4067
4152
  const held = /* @__PURE__ */ new Map();
4153
+ const deliveryObservers = /* @__PURE__ */ new Set();
4154
+ const notify = (delivery) => {
4155
+ for (const listener of deliveryObservers)
4156
+ try {
4157
+ listener({ namespace: delivery.namespace, state: delivery.state, deliveryId: delivery.id });
4158
+ } catch {
4159
+ }
4160
+ };
4161
+ let transport;
4068
4162
  const inFlight = /* @__PURE__ */ new Set();
4163
+ const workNamespace = /* @__PURE__ */ new Map();
4164
+ const activeDeliveries = /* @__PURE__ */ new Map();
4069
4165
  const controllers = /* @__PURE__ */ new Map();
4070
4166
  let immediate = Promise.resolve();
4071
4167
  const snapshots = /* @__PURE__ */ new WeakMap();
4072
- const track = (work) => {
4168
+ const track = (work, delivery) => {
4073
4169
  inFlight.add(work);
4074
- void work.finally(() => inFlight.delete(work));
4170
+ workNamespace.set(work, delivery.namespace);
4171
+ const active = activeDeliveries.get(delivery.id) ?? { namespace: delivery.namespace, count: 0 };
4172
+ active.count++;
4173
+ activeDeliveries.set(delivery.id, active);
4174
+ const finish = () => {
4175
+ inFlight.delete(work);
4176
+ workNamespace.delete(work);
4177
+ active.count--;
4178
+ if (active.count === 0)
4179
+ activeDeliveries.delete(delivery.id);
4180
+ };
4181
+ void work.then(finish, finish);
4075
4182
  };
4076
4183
  const attempt = async (delivery) => {
4077
4184
  const entry = payloads.get(delivery.id);
@@ -4103,7 +4210,8 @@ var createWebhookHub = (options) => {
4103
4210
  type: message.type,
4104
4211
  tags: message.tags
4105
4212
  });
4106
- const response = await send(new Request(endpoint.url, {
4213
+ const ownedSend = (request) => transport ? transport(request, message.namespace, send) : send(request);
4214
+ const response = await ownedSend(new Request(endpoint.url, {
4107
4215
  method: "POST",
4108
4216
  headers: {
4109
4217
  "content-type": message.contentType,
@@ -4130,6 +4238,7 @@ var createWebhookHub = (options) => {
4130
4238
  const index = delivery.attempts.length;
4131
4239
  if (index >= delays.length) {
4132
4240
  delivery.state = "failed";
4241
+ notify(delivery);
4133
4242
  pending.delete(delivery.id);
4134
4243
  return;
4135
4244
  }
@@ -4139,9 +4248,10 @@ var createWebhookHub = (options) => {
4139
4248
  await attempt(delivery).then((ok) => {
4140
4249
  if (!payloads.has(delivery.id))
4141
4250
  return;
4142
- if (ok)
4251
+ if (ok) {
4143
4252
  delivery.state = "delivered";
4144
- else
4253
+ notify(delivery);
4254
+ } else
4145
4255
  schedule(delivery);
4146
4256
  });
4147
4257
  };
@@ -4150,12 +4260,12 @@ var createWebhookHub = (options) => {
4150
4260
  const task = immediate.then(settle);
4151
4261
  immediate = task.catch(() => {
4152
4262
  });
4153
- track(task);
4263
+ track(task, delivery);
4154
4264
  return;
4155
4265
  }
4156
4266
  const timer = scheduleTimer(() => {
4157
4267
  pending.delete(delivery.id);
4158
- track(settle());
4268
+ track(settle(), delivery);
4159
4269
  }, delay);
4160
4270
  unref(timer);
4161
4271
  pending.set(delivery.id, timer);
@@ -4179,6 +4289,8 @@ var createWebhookHub = (options) => {
4179
4289
  payloads.set(delivery.id, { message, endpoint });
4180
4290
  if (state === "pending")
4181
4291
  schedule(delivery);
4292
+ else
4293
+ notify(delivery);
4182
4294
  }
4183
4295
  };
4184
4296
  const takeFault = (namespace) => {
@@ -4200,8 +4312,19 @@ var createWebhookHub = (options) => {
4200
4312
  fanOut(message);
4201
4313
  };
4202
4314
  const hub = {
4315
+ observeDeliveries(listener) {
4316
+ deliveryObservers.add(listener);
4317
+ return () => deliveryObservers.delete(listener);
4318
+ },
4319
+ setTransportPolicy(policy) {
4320
+ transport = policy;
4321
+ },
4203
4322
  pending(namespace) {
4204
- return inFlight.size + (held.get(namespace)?.length ?? 0) + [...deliveries.values()].filter((d) => d.namespace === namespace && d.state === "pending").length;
4323
+ const ids = new Set([...deliveries.values()].filter((d) => d.namespace === namespace && d.state === "pending").map((d) => d.id));
4324
+ for (const [id2, active] of activeDeliveries)
4325
+ if (active.namespace === namespace)
4326
+ ids.add(id2);
4327
+ return ids.size + (held.get(namespace)?.length ?? 0);
4205
4328
  },
4206
4329
  snapshot(namespace) {
4207
4330
  if (hub.pending(namespace) > 0)
@@ -4217,6 +4340,36 @@ var createWebhookHub = (options) => {
4217
4340
  }));
4218
4341
  return handle;
4219
4342
  },
4343
+ exportSnapshot(handle) {
4344
+ const point = typeof handle === "object" && handle !== null ? snapshots.get(handle) : void 0;
4345
+ if (!point)
4346
+ throw new Error("invalid webhook snapshot");
4347
+ const { namespace: _namespace, ...document2 } = point;
4348
+ return structuredClone(document2);
4349
+ },
4350
+ importSnapshot(namespace, document2) {
4351
+ if (!isRecord4(document2) || !Array.isArray(document2.endpoints) || !Array.isArray(document2.messages) || !Array.isArray(document2.deliveries) || !Array.isArray(document2.payloads) || !Array.isArray(document2.faults))
4352
+ throw new Error("invalid portable webhook snapshot");
4353
+ for (const endpoint of document2.endpoints)
4354
+ if (typeof parseEndpoint(endpoint) === "string")
4355
+ throw new Error("invalid portable webhook endpoint");
4356
+ for (const message of document2.messages)
4357
+ if (!isRecord4(message) || typeof message.id !== "string" || typeof message.body !== "string")
4358
+ throw new Error("invalid portable webhook message");
4359
+ for (const pair of [...document2.deliveries, ...document2.payloads])
4360
+ if (!Array.isArray(pair) || pair.length !== 2 || typeof pair[0] !== "string" || !isRecord4(pair[1]))
4361
+ throw new Error("invalid portable webhook entry");
4362
+ const handle = {};
4363
+ const point = structuredClone(document2);
4364
+ for (const message of point.messages)
4365
+ message.namespace = namespace;
4366
+ for (const [, delivery] of point.deliveries)
4367
+ delivery.namespace = namespace;
4368
+ for (const [, payload] of point.payloads)
4369
+ payload.message.namespace = namespace;
4370
+ snapshots.set(handle, { ...point, namespace });
4371
+ return handle;
4372
+ },
4220
4373
  restore(namespace, handle) {
4221
4374
  const point = typeof handle === "object" && handle !== null ? snapshots.get(handle) : void 0;
4222
4375
  if (!point || point.namespace !== namespace || hub.pending(namespace) > 0)
@@ -4277,9 +4430,14 @@ var createWebhookHub = (options) => {
4277
4430
  const delivery = deliveries.get(id2);
4278
4431
  if (!delivery)
4279
4432
  return void 0;
4280
- const ok = await attempt(delivery);
4281
- if (ok)
4282
- delivery.state = "delivered";
4433
+ const work = (async () => {
4434
+ const ok = await attempt(delivery);
4435
+ if (ok)
4436
+ delivery.state = "delivered";
4437
+ notify({ ...delivery, state: ok ? "delivered" : "failed" });
4438
+ })();
4439
+ track(work, delivery);
4440
+ await work;
4283
4441
  return delivery;
4284
4442
  },
4285
4443
  async flush() {
@@ -4296,11 +4454,12 @@ var createWebhookHub = (options) => {
4296
4454
  if (!delivery)
4297
4455
  continue;
4298
4456
  track(attempt(delivery).then((ok) => {
4299
- if (ok)
4457
+ if (ok) {
4300
4458
  delivery.state = "delivered";
4301
- else
4459
+ notify(delivery);
4460
+ } else
4302
4461
  schedule(delivery);
4303
- }));
4462
+ }), delivery);
4304
4463
  }
4305
4464
  await hub.idle();
4306
4465
  const scheduled = [...pending.values()].some((timer) => timer !== void 0);
@@ -4308,9 +4467,13 @@ var createWebhookHub = (options) => {
4308
4467
  return;
4309
4468
  }
4310
4469
  },
4311
- async idle() {
4312
- while (inFlight.size > 0)
4313
- await Promise.allSettled([...inFlight]);
4470
+ async idle(namespace) {
4471
+ for (; ; ) {
4472
+ const selected = [...inFlight].filter((work) => namespace === void 0 || workNamespace.get(work) === namespace);
4473
+ if (!selected.length)
4474
+ return;
4475
+ await Promise.allSettled(selected);
4476
+ }
4314
4477
  },
4315
4478
  fault(namespace, fault) {
4316
4479
  const queue = faults.get(namespace) ?? [];
@@ -4923,7 +5086,8 @@ var createRuntime = (options) => {
4923
5086
  ...point.rngState !== void 0 ? { rng: { state: point.rngState, ...streams } } : {},
4924
5087
  ...rules ? { faults: rules } : {},
4925
5088
  ...waits ? { latency: waits } : {},
4926
- ...settings?.virtualTime !== void 0 ? { virtualTime: settings.virtualTime } : {}
5089
+ ...settings?.virtualTime !== void 0 ? { virtualTime: settings.virtualTime } : {},
5090
+ ...point.webhooks !== void 0 ? { webhooks: options.webhooks?.exportSnapshot(point.webhooks) } : {}
4927
5091
  };
4928
5092
  };
4929
5093
  const position = (value, label) => {
@@ -5008,7 +5172,8 @@ var createRuntime = (options) => {
5008
5172
  records: stored,
5009
5173
  ...document2.clock ? { clock: { now: document2.clock.now, frozen: document2.clock.frozen } } : {},
5010
5174
  ...document2.rng?.state !== void 0 ? { rngState: position(document2.rng.state, "snapshot.rng.state") } : {},
5011
- controls: held
5175
+ controls: held,
5176
+ ...document2.webhooks !== void 0 ? { webhooks: options.webhooks?.importSnapshot(namespace, document2.webhooks) } : {}
5012
5177
  };
5013
5178
  };
5014
5179
  const kept = /* @__PURE__ */ new Map();
@@ -5142,6 +5307,20 @@ var createRuntime = (options) => {
5142
5307
  restoreAll(namespace, point);
5143
5308
  timelines.delete(namespace);
5144
5309
  },
5310
+ fleetExport(handle) {
5311
+ const point = typeof handle === "object" && handle !== null ? fleetPoints.get(handle) : void 0;
5312
+ if (!point)
5313
+ throw new Error("invalid fleet checkpoint");
5314
+ return toDocument(point);
5315
+ },
5316
+ fleetImport(namespace, document2) {
5317
+ const handle = {};
5318
+ fleetPoints.set(handle, {
5319
+ namespace,
5320
+ ...fromDocument(namespace, assertSnapshotDocument(document2))
5321
+ });
5322
+ return handle;
5323
+ },
5145
5324
  applyPreset: (name2, namespace = DEFAULT_NAMESPACE, overrides = {}) => controls.addFault(namespace, { ...overrides, preset: name2 }),
5146
5325
  instance,
5147
5326
  namespaces: () => [...publicNamespaces].sort(),
@@ -6657,9 +6836,11 @@ export {
6657
6836
  createClock,
6658
6837
  restoreClock,
6659
6838
  parseDuration,
6839
+ normalizeControls,
6660
6840
  normalizeBootControls,
6661
6841
  parseFaultHeader,
6662
6842
  resolveAdminPrefix,
6843
+ ownedTransport,
6663
6844
  document,
6664
6845
  operationIds,
6665
6846
  supportedOperationIds,
@@ -6676,4 +6857,4 @@ export {
6676
6857
  customerIoCredential,
6677
6858
  CustomerIoAPI
6678
6859
  };
6679
- //# sourceMappingURL=chunk-2UCTPXNT.js.map
6860
+ //# sourceMappingURL=chunk-C67SF4WY.js.map