@crvouga/mockingbird-service-posthog 3.3.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.
@@ -1165,7 +1165,7 @@ var assertSnapshotDocument = (value, label = "snapshot") => {
1165
1165
  });
1166
1166
  }
1167
1167
  if (value.clock !== void 0) {
1168
- if (!isRecord2(value.clock) || typeof value.clock.now !== "number" || typeof value.clock.frozen !== "boolean")
1168
+ if (!isRecord2(value.clock) || typeof value.clock.now !== "number" || !Number.isFinite(value.clock.now) || typeof value.clock.frozen !== "boolean")
1169
1169
  throw new ControlError(`${label}.clock: expected {now, frozen}`);
1170
1170
  }
1171
1171
  return value;
@@ -3045,6 +3045,91 @@ var createMetrics = (partition = true) => {
3045
3045
  };
3046
3046
  };
3047
3047
 
3048
+ // ../core/dist/outbound.js
3049
+ function ownedTransport(policy) {
3050
+ if (!["offline", "allowlist"].includes(policy.mode) || policy.origins?.some((origin) => {
3051
+ try {
3052
+ return new URL(origin).origin !== origin;
3053
+ } catch {
3054
+ return true;
3055
+ }
3056
+ }))
3057
+ throw new Error("invalid outbound transport policy");
3058
+ const reject = (namespace, reason) => {
3059
+ try {
3060
+ policy.onReject?.({ namespace, policy: policy.mode, reason });
3061
+ } catch {
3062
+ }
3063
+ throw new Error(`outbound policy ${policy.mode}: ${reason}`);
3064
+ };
3065
+ return async (request, namespace, send) => {
3066
+ if (policy.mode === "offline")
3067
+ return reject(namespace, "delivery disabled");
3068
+ const allowed = (url2) => ["http:", "https:"].includes(url2.protocol) && !url2.username && !url2.password && (policy.origins ?? []).includes(url2.origin);
3069
+ let url = new URL(request.url);
3070
+ if (!allowed(url))
3071
+ return reject(namespace, "destination not allowed");
3072
+ const max = policy.maxBodyBytes ?? 1024 * 1024;
3073
+ const chunks = [];
3074
+ let size = 0;
3075
+ const reader = request.body?.getReader();
3076
+ if (reader)
3077
+ try {
3078
+ for (; ; ) {
3079
+ const item = await reader.read();
3080
+ if (item.done)
3081
+ break;
3082
+ size += item.value.length;
3083
+ if (size > max)
3084
+ return reject(namespace, "body limit exceeded");
3085
+ chunks.push(item.value);
3086
+ }
3087
+ } finally {
3088
+ void reader.cancel().catch(() => {
3089
+ });
3090
+ reader.releaseLock();
3091
+ }
3092
+ const body = new Uint8Array(size);
3093
+ let offset = 0;
3094
+ for (const chunk of chunks) {
3095
+ body.set(chunk, offset);
3096
+ offset += chunk.length;
3097
+ }
3098
+ let method = request.method, headers = new Headers(request.headers);
3099
+ for (let redirects = 0; ; redirects++) {
3100
+ if (!allowed(url))
3101
+ return reject(namespace, "redirect destination not allowed");
3102
+ const response = await send(new Request(url, {
3103
+ method,
3104
+ headers,
3105
+ ...method !== "GET" && method !== "HEAD" ? { body } : {},
3106
+ redirect: "manual",
3107
+ signal: request.signal
3108
+ }));
3109
+ if (![301, 302, 303, 307, 308].includes(response.status))
3110
+ return response;
3111
+ const location = response.headers.get("location");
3112
+ if (!location)
3113
+ return response;
3114
+ await response.body?.cancel();
3115
+ if (redirects >= (policy.maxRedirects ?? 5))
3116
+ return reject(namespace, "redirect limit exceeded");
3117
+ const next = new URL(location, url);
3118
+ if (next.origin !== url.origin) {
3119
+ headers = new Headers(headers);
3120
+ for (const key of ["authorization", "cookie", "proxy-authorization"])
3121
+ headers.delete(key);
3122
+ }
3123
+ if (response.status === 303 || (response.status === 301 || response.status === 302) && method === "POST") {
3124
+ method = "GET";
3125
+ headers.delete("content-length");
3126
+ headers.delete("content-type");
3127
+ }
3128
+ url = next;
3129
+ }
3130
+ };
3131
+ }
3132
+
3048
3133
  // ../core/dist/outbox.js
3049
3134
  var parseSince = (value) => {
3050
3135
  if (value === null)
@@ -3618,7 +3703,7 @@ var stateAdminRoutes = (routes) => {
3618
3703
  };
3619
3704
 
3620
3705
  // ../core/dist/version.js
3621
- var PACKAGE_VERSION = true ? "3.3.0" : UNRELEASED_VERSION;
3706
+ var PACKAGE_VERSION = true ? "3.4.0" : UNRELEASED_VERSION;
3622
3707
 
3623
3708
  // ../core/dist/signing.js
3624
3709
  var encoder = new TextEncoder();
@@ -4201,7 +4286,8 @@ var createRuntime = (options) => {
4201
4286
  ...point.rngState !== void 0 ? { rng: { state: point.rngState, ...streams } } : {},
4202
4287
  ...rules ? { faults: rules } : {},
4203
4288
  ...waits ? { latency: waits } : {},
4204
- ...settings?.virtualTime !== void 0 ? { virtualTime: settings.virtualTime } : {}
4289
+ ...settings?.virtualTime !== void 0 ? { virtualTime: settings.virtualTime } : {},
4290
+ ...point.webhooks !== void 0 ? { webhooks: options.webhooks?.exportSnapshot(point.webhooks) } : {}
4205
4291
  };
4206
4292
  };
4207
4293
  const position = (value, label) => {
@@ -4286,7 +4372,8 @@ var createRuntime = (options) => {
4286
4372
  records: stored,
4287
4373
  ...document2.clock ? { clock: { now: document2.clock.now, frozen: document2.clock.frozen } } : {},
4288
4374
  ...document2.rng?.state !== void 0 ? { rngState: position(document2.rng.state, "snapshot.rng.state") } : {},
4289
- controls: held
4375
+ controls: held,
4376
+ ...document2.webhooks !== void 0 ? { webhooks: options.webhooks?.importSnapshot(namespace, document2.webhooks) } : {}
4290
4377
  };
4291
4378
  };
4292
4379
  const kept = /* @__PURE__ */ new Map();
@@ -4420,6 +4507,20 @@ var createRuntime = (options) => {
4420
4507
  restoreAll(namespace, point);
4421
4508
  timelines.delete(namespace);
4422
4509
  },
4510
+ fleetExport(handle) {
4511
+ const point = typeof handle === "object" && handle !== null ? fleetPoints.get(handle) : void 0;
4512
+ if (!point)
4513
+ throw new Error("invalid fleet checkpoint");
4514
+ return toDocument(point);
4515
+ },
4516
+ fleetImport(namespace, document2) {
4517
+ const handle = {};
4518
+ fleetPoints.set(handle, {
4519
+ namespace,
4520
+ ...fromDocument(namespace, assertSnapshotDocument(document2))
4521
+ });
4522
+ return handle;
4523
+ },
4423
4524
  applyPreset: (name2, namespace = DEFAULT_NAMESPACE, overrides = {}) => controls.addFault(namespace, { ...overrides, preset: name2 }),
4424
4525
  instance,
4425
4526
  namespaces: () => [...publicNamespaces].sort(),
@@ -6062,9 +6163,11 @@ export {
6062
6163
  createClock,
6063
6164
  restoreClock,
6064
6165
  parseDuration,
6166
+ normalizeControls,
6065
6167
  normalizeBootControls,
6066
6168
  parseFaultHeader,
6067
6169
  resolveAdminPrefix,
6170
+ ownedTransport,
6068
6171
  decodePostHogBody,
6069
6172
  tokenFromBody,
6070
6173
  evaluateFlag,
@@ -6082,4 +6185,4 @@ export {
6082
6185
  scrubProperties,
6083
6186
  PostHogAPI
6084
6187
  };
6085
- //# sourceMappingURL=chunk-CJW2IXDE.js.map
6188
+ //# sourceMappingURL=chunk-YTVQ24KD.js.map