@aglyn/aglyn 1.4.0 → 1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/aglyn",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -37,16 +37,16 @@
37
37
  "./package.json": "./package.json"
38
38
  },
39
39
  "dependencies": {
40
- "@aglyn/shared-data-enums": "1.4.0",
41
- "@aglyn/shared-data-mdi": "1.4.0",
42
- "@aglyn/shared-data-types": "1.4.0",
43
- "@aglyn/shared-util-email": "1.4.0",
44
- "@aglyn/shared-util-first-touch": "1.4.0",
45
- "@aglyn/shared-util-http": "1.4.0",
46
- "@aglyn/shared-util-logger": "1.4.0",
47
- "@aglyn/shared-util-timestamp": "1.4.0",
48
- "@aglyn/shared-util-tools": "1.4.0",
49
- "@aglyn/shared-util-vendor": "1.4.0",
40
+ "@aglyn/shared-data-enums": "1.5.0",
41
+ "@aglyn/shared-data-mdi": "1.5.0",
42
+ "@aglyn/shared-data-types": "1.5.0",
43
+ "@aglyn/shared-util-email": "1.5.0",
44
+ "@aglyn/shared-util-first-touch": "1.5.0",
45
+ "@aglyn/shared-util-http": "1.5.0",
46
+ "@aglyn/shared-util-logger": "1.5.0",
47
+ "@aglyn/shared-util-timestamp": "1.5.0",
48
+ "@aglyn/shared-util-tools": "1.5.0",
49
+ "@aglyn/shared-util-vendor": "1.5.0",
50
50
  "@data-driven-forms/react-form-renderer": "^4.2.0",
51
51
  "@msgpack/msgpack": "^3.1.3",
52
52
  "@types/unist": "^3.0.3",
@@ -1279,6 +1279,45 @@ export declare const WEBHOOK_FAILURE_WINDOW_MINUTES = 60;
1279
1279
  * retries on its own, so a failure visible here is not one unlucky packet.
1280
1280
  */
1281
1281
  export declare const MAX_FAILED_DELIVERIES_PER_WINDOW = 0;
1282
+ /**
1283
+ * How long a new event can sit on Stripe's undelivered list before it can
1284
+ * count at all (AGL-4133).
1285
+ *
1286
+ * `delivery_success=false` returns events "still pending" as well as events
1287
+ * that failed, so every event starts its life on that list. This is the time
1288
+ * a first attempt gets to land, because a probe memoized for minutes must not
1289
+ * hold that instant as a red.
1290
+ */
1291
+ export declare const WEBHOOK_EVENT_IN_FLIGHT_MS: number;
1292
+ /**
1293
+ * How long a clean claim outranks Stripe's undelivered list (AGL-4133).
1294
+ *
1295
+ * The list lags the deliveries. On 2026-11-03 one new subscription produced
1296
+ * seven events, all seven answered 200 on the first attempt inside five
1297
+ * seconds, and Stripe went on listing one of them with `pending_webhooks: 1`
1298
+ * for about eight minutes before it cleared with no second POST. That read
1299
+ * `deliveries-failing` on a window with no failure in it.
1300
+ *
1301
+ * A claim says the handler STARTED, though, and a function killed mid-dispatch
1302
+ * leaves one behind, so it cannot vouch forever. Eight minutes is a lag; half
1303
+ * an hour is a delivery Stripe never got an answer to, and past this the list
1304
+ * is believed again.
1305
+ */
1306
+ export declare const WEBHOOK_CLAIM_VOUCHES_FOR_MS: number;
1307
+ /**
1308
+ * How many events on Stripe's `delivery_success=false` list really went
1309
+ * undelivered (AGL-4133).
1310
+ *
1311
+ * `claimed` is the events our handler took and did not fail on. Every real
1312
+ * failure stays out of it by construction: a rejected delivery returns 400
1313
+ * before it claims, an early throw deletes its claim, and a half-applied
1314
+ * dispatch holds its claim with `failedAfterEffects` set. An event with no
1315
+ * `created` counts, because an unreadable fact must not read as calm.
1316
+ */
1317
+ export declare function countUndeliveredEvents(listed: ReadonlyArray<{
1318
+ id?: string;
1319
+ created?: number;
1320
+ }>, claimed: ReadonlySet<string>, nowMs: number): number;
1282
1321
  /**
1283
1322
  * Inert deliveries tolerated in the window (AGL-1954).
1284
1323
  *
@@ -1046,6 +1046,47 @@ export function renderHealth(outcome, host, ms) {
1046
1046
  * "Stripe tried to tell us something about money and could not". Stripe
1047
1047
  * retries on its own, so a failure visible here is not one unlucky packet.
1048
1048
  */ export const MAX_FAILED_DELIVERIES_PER_WINDOW = 0;
1049
+ /**
1050
+ * How long a new event can sit on Stripe's undelivered list before it can
1051
+ * count at all (AGL-4133).
1052
+ *
1053
+ * `delivery_success=false` returns events "still pending" as well as events
1054
+ * that failed, so every event starts its life on that list. This is the time
1055
+ * a first attempt gets to land, because a probe memoized for minutes must not
1056
+ * hold that instant as a red.
1057
+ */ export const WEBHOOK_EVENT_IN_FLIGHT_MS = 2 * 60000;
1058
+ /**
1059
+ * How long a clean claim outranks Stripe's undelivered list (AGL-4133).
1060
+ *
1061
+ * The list lags the deliveries. On 2026-11-03 one new subscription produced
1062
+ * seven events, all seven answered 200 on the first attempt inside five
1063
+ * seconds, and Stripe went on listing one of them with `pending_webhooks: 1`
1064
+ * for about eight minutes before it cleared with no second POST. That read
1065
+ * `deliveries-failing` on a window with no failure in it.
1066
+ *
1067
+ * A claim says the handler STARTED, though, and a function killed mid-dispatch
1068
+ * leaves one behind, so it cannot vouch forever. Eight minutes is a lag; half
1069
+ * an hour is a delivery Stripe never got an answer to, and past this the list
1070
+ * is believed again.
1071
+ */ export const WEBHOOK_CLAIM_VOUCHES_FOR_MS = 30 * 60000;
1072
+ /**
1073
+ * How many events on Stripe's `delivery_success=false` list really went
1074
+ * undelivered (AGL-4133).
1075
+ *
1076
+ * `claimed` is the events our handler took and did not fail on. Every real
1077
+ * failure stays out of it by construction: a rejected delivery returns 400
1078
+ * before it claims, an early throw deletes its claim, and a half-applied
1079
+ * dispatch holds its claim with `failedAfterEffects` set. An event with no
1080
+ * `created` counts, because an unreadable fact must not read as calm.
1081
+ */ export function countUndeliveredEvents(listed, claimed, nowMs) {
1082
+ return listed.filter((event)=>{
1083
+ var _event_created;
1084
+ const ageMs = nowMs - ((_event_created = event.created) != null ? _event_created : 0) * 1000;
1085
+ if (ageMs < WEBHOOK_EVENT_IN_FLIGHT_MS) return false;
1086
+ const vouched = ageMs < WEBHOOK_CLAIM_VOUCHES_FOR_MS && claimed.has(String(event.id));
1087
+ return !vouched;
1088
+ }).length;
1089
+ }
1049
1090
  /**
1050
1091
  * Inert deliveries tolerated in the window (AGL-1954).
1051
1092
  *