@wrongstack/governance 0.319.1 → 1.0.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/dist/index.js CHANGED
@@ -1211,6 +1211,7 @@ async function connectGovernanceProjectClient(options) {
1211
1211
 
1212
1212
  // src/sanitize.ts
1213
1213
  function sanitizeGovernanceMessage(message) {
1214
+ if (typeof message !== "string") return "";
1214
1215
  return message.replace(/wsg_[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*/gu, "[credential]").slice(0, 512);
1215
1216
  }
1216
1217
 
@@ -4284,7 +4285,14 @@ var SqliteVerificationLedger = class {
4284
4285
  "Verification lease was already consumed."
4285
4286
  );
4286
4287
  }
4287
- if (nowMs >= Date.parse(leaseRow.expires_at)) {
4288
+ const leaseExpiresAtMs = Date.parse(leaseRow.expires_at);
4289
+ if (!Number.isSafeInteger(leaseExpiresAtMs)) {
4290
+ return this.#finishConsumeFailure(
4291
+ "expired",
4292
+ "Verification lease expiry is unreadable; the lease is not honored."
4293
+ );
4294
+ }
4295
+ if (nowMs >= leaseExpiresAtMs) {
4288
4296
  return this.#finishConsumeFailure("expired", "Verification lease has expired.");
4289
4297
  }
4290
4298
  let run;
@@ -4337,8 +4345,10 @@ var SqliteVerificationLedger = class {
4337
4345
  const consumption = consumptionRow ? this.#consumptionFromRow(consumptionRow) : null;
4338
4346
  const nowMs = Date.parse(this.#now());
4339
4347
  if (!Number.isSafeInteger(nowMs)) throw new Error("Verification store clock is invalid.");
4348
+ const expiresAtMs = Date.parse(row.expires_at);
4349
+ const expired = !Number.isSafeInteger(expiresAtMs) || nowMs >= expiresAtMs;
4340
4350
  return deepFreeze2({
4341
- state: consumption ? "consumed" : nowMs >= Date.parse(row.expires_at) ? "expired" : "active",
4351
+ state: consumption ? "consumed" : expired ? "expired" : "active",
4342
4352
  lease: this.#leaseDescriptor(row),
4343
4353
  consumption
4344
4354
  });
@@ -4448,7 +4458,7 @@ function canonicalize2(value) {
4448
4458
  if (Array.isArray(value)) return value.map(canonicalize2);
4449
4459
  if (value && typeof value === "object") {
4450
4460
  return Object.fromEntries(
4451
- Object.entries(value).filter(([, entryValue]) => entryValue !== void 0).sort(([left], [right]) => left.localeCompare(right)).map(([key, entryValue]) => [key, canonicalize2(entryValue)])
4461
+ Object.entries(value).filter(([, entryValue]) => entryValue !== void 0).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, entryValue]) => [key, canonicalize2(entryValue)])
4452
4462
  );
4453
4463
  }
4454
4464
  return value;
@@ -4568,7 +4578,10 @@ var SqliteGovernanceEventStore = class _SqliteGovernanceEventStore {
4568
4578
  aggregate: resultAggregate
4569
4579
  };
4570
4580
  } catch (error) {
4571
- this.db.exec("ROLLBACK");
4581
+ try {
4582
+ this.db.exec("ROLLBACK");
4583
+ } catch {
4584
+ }
4572
4585
  throw error;
4573
4586
  }
4574
4587
  }
@@ -4632,7 +4645,10 @@ var SqliteGovernanceEventStore = class _SqliteGovernanceEventStore {
4632
4645
  this.db.exec("COMMIT");
4633
4646
  return { handled: true, idempotentReplay: false, observation: stored };
4634
4647
  } catch (error) {
4635
- this.db.exec("ROLLBACK");
4648
+ try {
4649
+ this.db.exec("ROLLBACK");
4650
+ } catch {
4651
+ }
4636
4652
  throw error;
4637
4653
  }
4638
4654
  }
@@ -489,6 +489,7 @@ async function acquireGovernanceDaemonStartupLease(options) {
489
489
 
490
490
  // src/sanitize.ts
491
491
  function sanitizeGovernanceMessage(message) {
492
+ if (typeof message !== "string") return "";
492
493
  return message.replace(/wsg_[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*/gu, "[credential]").slice(0, 512);
493
494
  }
494
495
 
@@ -2778,7 +2779,14 @@ var SqliteVerificationLedger = class {
2778
2779
  "Verification lease was already consumed."
2779
2780
  );
2780
2781
  }
2781
- if (nowMs >= Date.parse(leaseRow.expires_at)) {
2782
+ const leaseExpiresAtMs = Date.parse(leaseRow.expires_at);
2783
+ if (!Number.isSafeInteger(leaseExpiresAtMs)) {
2784
+ return this.#finishConsumeFailure(
2785
+ "expired",
2786
+ "Verification lease expiry is unreadable; the lease is not honored."
2787
+ );
2788
+ }
2789
+ if (nowMs >= leaseExpiresAtMs) {
2782
2790
  return this.#finishConsumeFailure("expired", "Verification lease has expired.");
2783
2791
  }
2784
2792
  let run2;
@@ -2831,8 +2839,10 @@ var SqliteVerificationLedger = class {
2831
2839
  const consumption = consumptionRow ? this.#consumptionFromRow(consumptionRow) : null;
2832
2840
  const nowMs = Date.parse(this.#now());
2833
2841
  if (!Number.isSafeInteger(nowMs)) throw new Error("Verification store clock is invalid.");
2842
+ const expiresAtMs = Date.parse(row.expires_at);
2843
+ const expired = !Number.isSafeInteger(expiresAtMs) || nowMs >= expiresAtMs;
2834
2844
  return deepFreeze2({
2835
- state: consumption ? "consumed" : nowMs >= Date.parse(row.expires_at) ? "expired" : "active",
2845
+ state: consumption ? "consumed" : expired ? "expired" : "active",
2836
2846
  lease: this.#leaseDescriptor(row),
2837
2847
  consumption
2838
2848
  });
@@ -2942,7 +2952,7 @@ function canonicalize2(value) {
2942
2952
  if (Array.isArray(value)) return value.map(canonicalize2);
2943
2953
  if (value && typeof value === "object") {
2944
2954
  return Object.fromEntries(
2945
- Object.entries(value).filter(([, entryValue]) => entryValue !== void 0).sort(([left], [right]) => left.localeCompare(right)).map(([key, entryValue]) => [key, canonicalize2(entryValue)])
2955
+ Object.entries(value).filter(([, entryValue]) => entryValue !== void 0).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([key, entryValue]) => [key, canonicalize2(entryValue)])
2946
2956
  );
2947
2957
  }
2948
2958
  return value;
@@ -3062,7 +3072,10 @@ var SqliteGovernanceEventStore = class _SqliteGovernanceEventStore {
3062
3072
  aggregate: resultAggregate
3063
3073
  };
3064
3074
  } catch (error) {
3065
- this.db.exec("ROLLBACK");
3075
+ try {
3076
+ this.db.exec("ROLLBACK");
3077
+ } catch {
3078
+ }
3066
3079
  throw error;
3067
3080
  }
3068
3081
  }
@@ -3126,7 +3139,10 @@ var SqliteGovernanceEventStore = class _SqliteGovernanceEventStore {
3126
3139
  this.db.exec("COMMIT");
3127
3140
  return { handled: true, idempotentReplay: false, observation: stored };
3128
3141
  } catch (error) {
3129
- this.db.exec("ROLLBACK");
3142
+ try {
3143
+ this.db.exec("ROLLBACK");
3144
+ } catch {
3145
+ }
3130
3146
  throw error;
3131
3147
  }
3132
3148
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrongstack/governance",
3
- "version": "0.319.1",
3
+ "version": "1.0.0",
4
4
  "license": "MIT",
5
5
  "description": "Deterministic workflow contracts and transition policy for WrongStack orchestration.",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "README.md"
28
28
  ],
29
29
  "dependencies": {
30
- "@wrongstack/persistence": "0.319.1"
30
+ "@wrongstack/persistence": "1.0.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^26.2.0",