@crvouga/mockingbird-service-flex 1.0.2 → 1.1.1

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,6 +1,25 @@
1
1
  # Changelog — @crvouga/mockingbird-service-flex
2
2
 
3
- ## 1.0.2 (2026-09-26)
3
+ ## 1.1.1 (2026-09-29)
4
+
5
+ ### Fixes and improvements
6
+
7
+ - sign and retry webhooks on the injected clock ([1091bde](https://github.com/crvouga/mockingbird/commit/1091bde0df69d9cc3eba2062d8523755e6caca14))
8
+
9
+ ## 1.1.0 (2026-09-29)
10
+
11
+ ### Features
12
+
13
+ - let a scalar naming a later branch's enum value pick that branch ([30ade3a](https://github.com/crvouga/mockingbird/commit/30ade3a28a5b6b273ffbf261216b821acac8e961))
14
+
15
+ ### Fixes and improvements
16
+
17
+ - derive a subscription's period from one clock read ([03e1dbe](https://github.com/crvouga/mockingbird/commit/03e1dbef6dc54c2ff952c05a721f9d61c2cc9f4c))
18
+ - stop cleared webhook deliveries from rescheduling forever ([424b78f](https://github.com/crvouga/mockingbird/commit/424b78f29317b162e3bf7d0049cc19be5b977026))
19
+ - serialize immediate webhook attempts to fix reorder flake ([625c82b](https://github.com/crvouga/mockingbird/commit/625c82b5a8a7992c1cf93e9df68e77af08b353e3))
20
+ - flush drains webhook retries scheduled while it runs ([c58cede](https://github.com/crvouga/mockingbird/commit/c58cede1b6ba7ae5ed3f8721ad9b7cd7bc0b1ca7))
21
+
22
+ ## 1.0.2 (2026-09-25)
4
23
 
5
24
  ### Fixes and improvements
6
25
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createRuntime
3
- } from "./chunk-JYH5AFHL.js";
3
+ } from "./chunk-UQWTCFIV.js";
4
4
 
5
5
  // ../../adapters/node/dist/cli.js
6
6
  import { readFile } from "node:fs/promises";
@@ -379,4 +379,4 @@ export {
379
379
  createServer2 as createServer,
380
380
  serveTarget
381
381
  };
382
- //# sourceMappingURL=chunk-XQ3UGAR4.js.map
382
+ //# sourceMappingURL=chunk-KNQ2MP6O.js.map
@@ -1632,7 +1632,7 @@ var restoreNamespace = (sqlite, namespace, snapshot) => {
1632
1632
  };
1633
1633
 
1634
1634
  // ../core/dist/version.js
1635
- var PACKAGE_VERSION = true ? "1.0.2" : UNRELEASED_VERSION;
1635
+ var PACKAGE_VERSION = true ? "1.1.1" : UNRELEASED_VERSION;
1636
1636
 
1637
1637
  // ../core/dist/signing.js
1638
1638
  var encoder = new TextEncoder();
@@ -1725,6 +1725,7 @@ var createWebhookHub = (options) => {
1725
1725
  const faults = /* @__PURE__ */ new Map();
1726
1726
  const held = /* @__PURE__ */ new Map();
1727
1727
  const inFlight2 = /* @__PURE__ */ new Set();
1728
+ let immediate = Promise.resolve();
1728
1729
  const track = (work) => {
1729
1730
  inFlight2.add(work);
1730
1731
  void work.finally(() => inFlight2.delete(work));
@@ -1787,22 +1788,28 @@ var createWebhookHub = (options) => {
1787
1788
  pending.delete(delivery.id);
1788
1789
  return;
1789
1790
  }
1790
- const run = () => {
1791
- pending.delete(delivery.id);
1792
- track(attempt(delivery).then((ok) => {
1791
+ const settle = async () => {
1792
+ if (!payloads.has(delivery.id))
1793
+ return;
1794
+ await attempt(delivery).then((ok) => {
1793
1795
  if (ok)
1794
1796
  delivery.state = "delivered";
1795
1797
  else
1796
1798
  schedule(delivery);
1797
- }));
1799
+ });
1798
1800
  };
1799
1801
  const delay = delays[index] ?? 0;
1800
1802
  if (delay <= 0) {
1801
- pending.set(delivery.id, void 0);
1802
- run();
1803
+ const task = immediate.then(settle);
1804
+ immediate = task.catch(() => {
1805
+ });
1806
+ track(task);
1803
1807
  return;
1804
1808
  }
1805
- const timer = scheduleTimer(run, delay);
1809
+ const timer = scheduleTimer(() => {
1810
+ pending.delete(delivery.id);
1811
+ track(settle());
1812
+ }, delay);
1806
1813
  unref(timer);
1807
1814
  pending.set(delivery.id, timer);
1808
1815
  };
@@ -1898,25 +1905,30 @@ var createWebhookHub = (options) => {
1898
1905
  return delivery;
1899
1906
  },
1900
1907
  async flush() {
1901
- for (const namespace of [...held.keys()])
1902
- releaseHeld(namespace);
1903
- const waiting = [...pending.entries()];
1904
- for (const [id2, timer] of waiting) {
1905
- if (timer === void 0)
1906
- continue;
1907
- cancel(timer);
1908
- pending.delete(id2);
1909
- const delivery = deliveries.get(id2);
1910
- if (!delivery)
1911
- continue;
1912
- track(attempt(delivery).then((ok) => {
1913
- if (ok)
1914
- delivery.state = "delivered";
1915
- else
1916
- schedule(delivery);
1917
- }));
1908
+ for (; ; ) {
1909
+ for (const namespace of [...held.keys()])
1910
+ releaseHeld(namespace);
1911
+ const waiting = [...pending.entries()];
1912
+ for (const [id2, timer] of waiting) {
1913
+ if (timer === void 0)
1914
+ continue;
1915
+ cancel(timer);
1916
+ pending.delete(id2);
1917
+ const delivery = deliveries.get(id2);
1918
+ if (!delivery)
1919
+ continue;
1920
+ track(attempt(delivery).then((ok) => {
1921
+ if (ok)
1922
+ delivery.state = "delivered";
1923
+ else
1924
+ schedule(delivery);
1925
+ }));
1926
+ }
1927
+ await hub.idle();
1928
+ const scheduled = [...pending.values()].some((timer) => timer !== void 0);
1929
+ if (held.size === 0 && !scheduled)
1930
+ return;
1918
1931
  }
1919
- await hub.idle();
1920
1932
  },
1921
1933
  async idle() {
1922
1934
  while (inFlight2.size > 0)
@@ -4399,6 +4411,8 @@ var FlexAPI = class {
4399
4411
  );
4400
4412
  const first = recurring[0]?.price_data.recurring ?? { interval: "month" };
4401
4413
  const data = session.subscription_data ?? {};
4414
+ const startedMs = this.now();
4415
+ const started = new Date(startedMs).toISOString();
4402
4416
  const subscription = {
4403
4417
  subscription_id: this.state.nextId("fsub_"),
4404
4418
  status: "active",
@@ -4406,12 +4420,12 @@ var FlexAPI = class {
4406
4420
  customer: session.customer,
4407
4421
  default_payment_method: paymentMethod,
4408
4422
  cancel_at_period_end: data.cancel_at_period_end === true,
4409
- current_period_start: this.iso(),
4410
- current_period_end: new Date(periodEnd(this.now(), first)).toISOString(),
4423
+ current_period_start: started,
4424
+ current_period_end: new Date(periodEnd(startedMs, first)).toISOString(),
4411
4425
  canceled_at: null,
4412
4426
  metadata: data.metadata ?? null,
4413
4427
  test_mode: session.test_mode,
4414
- created_at: this.iso()
4428
+ created_at: started
4415
4429
  };
4416
4430
  this.state.subscriptions.insert(subscription.subscription_id, subscription);
4417
4431
  this.emit("customer.subscription.created", { ...subscription }, session.test_mode);
@@ -4719,4 +4733,4 @@ export {
4719
4733
  FlexAPI,
4720
4734
  isNextActionType
4721
4735
  };
4722
- //# sourceMappingURL=chunk-JYH5AFHL.js.map
4736
+ //# sourceMappingURL=chunk-UQWTCFIV.js.map