@xyo-network/event-kit-node 1.0.0 → 1.0.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.
@@ -23,10 +23,7 @@ function createFilesystemCursorStore(options) {
23
23
  try {
24
24
  const raw = await readFile(filePath, "utf8");
25
25
  const parsed = JSON.parse(raw);
26
- if (typeof parsed.lastProcessedBlock !== "number" || !Number.isFinite(parsed.lastProcessedBlock)) {
27
- return void 0;
28
- }
29
- return parsed.lastProcessedBlock;
26
+ return typeof parsed.lastProcessedBlock !== "number" || !Number.isFinite(parsed.lastProcessedBlock) ? void 0 : parsed.lastProcessedBlock;
30
27
  } catch (error) {
31
28
  if (isNotFound(error)) return void 0;
32
29
  throw error;
@@ -481,10 +478,7 @@ function replaceJsonValue(_key, candidate) {
481
478
  return typeof candidate === "bigint" ? { $eventKitBigInt: candidate.toString() } : candidate;
482
479
  }
483
480
  function reviveJson(_key, candidate) {
484
- if (typeof candidate === "object" && candidate !== null && Object.keys(candidate).length === 1 && "$eventKitBigInt" in candidate && typeof candidate.$eventKitBigInt === "string" && /^(?:0|[1-9][0-9]*)$/u.test(candidate.$eventKitBigInt)) {
485
- return BigInt(candidate.$eventKitBigInt);
486
- }
487
- return candidate;
481
+ return typeof candidate === "object" && candidate !== null && Object.keys(candidate).length === 1 && "$eventKitBigInt" in candidate && typeof candidate.$eventKitBigInt === "string" && /^(?:0|[1-9][0-9]*)$/u.test(candidate.$eventKitBigInt) ? BigInt(candidate.$eventKitBigInt) : candidate;
488
482
  }
489
483
  async function unlinkIfMissing3(path) {
490
484
  try {
@@ -1076,7 +1070,7 @@ function createFilesystemPublisherEndpointChallengeStore(options) {
1076
1070
  if (await publish(attempted)) return { kind: "started", record: attempted };
1077
1071
  const winner = await current(challengeHash);
1078
1072
  if (winner === void 0) throw new Error("challenge attempt winner vanished");
1079
- return winner.state === "verified" ? { kind: "verified", record: winner } : { kind: "already-attempted", record: winner };
1073
+ return { kind: winner.state === "verified" ? "verified" : "already-attempted", record: winner };
1080
1074
  },
1081
1075
  async completeVerified(input) {
1082
1076
  const challengeHash = HashZod3.parse(input.challengeHash);
@@ -1085,7 +1079,7 @@ function createFilesystemPublisherEndpointChallengeStore(options) {
1085
1079
  const observed = await current(challengeHash);
1086
1080
  if (observed === void 0) return { kind: "missing" };
1087
1081
  if (observed.state === "verified") {
1088
- return observed.responseHash === responseHash ? { kind: "duplicate", record: observed } : { kind: "collision", record: observed };
1082
+ return { kind: observed.responseHash === responseHash ? "duplicate" : "collision", record: observed };
1089
1083
  }
1090
1084
  if (observed.state !== "attempted") return { kind: "not-attempted", record: observed };
1091
1085
  if (!isLive(observed, input.nowSeconds)) return { kind: "expired", record: observed };
@@ -1097,7 +1091,7 @@ function createFilesystemPublisherEndpointChallengeStore(options) {
1097
1091
  if (await publish(verified)) return { kind: "verified", record: verified };
1098
1092
  const winner = await readState(challengeHash, "verified");
1099
1093
  if (winner === void 0) throw new Error("verified challenge winner vanished");
1100
- return winner.responseHash === responseHash ? { kind: "duplicate", record: winner } : { kind: "collision", record: winner };
1094
+ return { kind: winner.responseHash === responseHash ? "duplicate" : "collision", record: winner };
1101
1095
  },
1102
1096
  get: async (rawHash) => await current(HashZod3.parse(rawHash)),
1103
1097
  async issue(input) {
@@ -2717,11 +2711,7 @@ function loadPublisherAddressPolicy() {
2717
2711
  }
2718
2712
  function isPublicPublisherAddress(address) {
2719
2713
  const policy = loadPublisherAddressPolicy();
2720
- if (isIP(address) === 4)
2721
- return !policy.nonPublicIpv4.check(address, "ipv4");
2722
- if (isIP(address) !== 6)
2723
- return false;
2724
- return policy.globalIpv6.check(address, "ipv6") && !policy.nonPublicIpv6.check(address, "ipv6");
2714
+ return isIP(address) === 4 ? !policy.nonPublicIpv4.check(address, "ipv4") : isIP(address) === 6 && policy.globalIpv6.check(address, "ipv6") && !policy.nonPublicIpv6.check(address, "ipv6");
2725
2715
  }
2726
2716
  function createPublisherHttpsTransport(input) {
2727
2717
  const parsed = OptionsZod.safeParse(input);
@@ -2880,11 +2870,10 @@ function assertDeliveryState(record, subscription) {
2880
2870
  throw new Error("Subscription revision changed without a new identity");
2881
2871
  if (!Number.isSafeInteger(record.cursor) || record.cursor < subscription.fromPosition - 1 || [record.delivered, record.failures, record.nextAttemptMs].some((value) => !(Number.isSafeInteger(value) && value >= 0)) || !["active", "blocked", "cancelled"].includes(record.state))
2882
2872
  throw new Error("Persisted publisher delivery state is invalid");
2883
- if (record.pending !== void 0) {
2884
- const pending = WakeEnvelopeZod2.parse(record.pending);
2885
- if (pending.fromPosition !== record.cursor + 1 || pending.toPosition - pending.fromPosition + 1 > subscription.maxPositionsPerWake || pending.authorizationChainId !== subscription.authorizationChainId || pending.deploymentId !== subscription.deploymentId || pending.queueId !== subscription.queueId || pending.filterHash !== subscription.filterHash || !isDeepStrictEqual2(pending.source, subscription.source))
2886
- throw new Error("Persisted publisher outbox binding is invalid");
2887
- }
2873
+ if (record.pending === void 0) return;
2874
+ const pending = WakeEnvelopeZod2.parse(record.pending);
2875
+ if (pending.fromPosition !== record.cursor + 1 || pending.toPosition - pending.fromPosition + 1 > subscription.maxPositionsPerWake || pending.authorizationChainId !== subscription.authorizationChainId || pending.deploymentId !== subscription.deploymentId || pending.queueId !== subscription.queueId || pending.filterHash !== subscription.filterHash || !isDeepStrictEqual2(pending.source, subscription.source))
2876
+ throw new Error("Persisted publisher outbox binding is invalid");
2888
2877
  }
2889
2878
  function makeEvent(subscription, fromPosition, toPosition, now, wakeId = randomBytes6(16).toString("hex")) {
2890
2879
  return WakeEnvelopeZod2.parse({
@@ -3142,10 +3131,11 @@ async function createPersistentEventPublisherRuntime(options) {
3142
3131
  async start() {
3143
3132
  if (stop !== void 0)
3144
3133
  throw new Error("Publisher is stopped");
3145
- if (!running) {
3146
- await actor.start();
3147
- running = true;
3134
+ if (running) {
3135
+ return;
3148
3136
  }
3137
+ await actor.start();
3138
+ running = true;
3149
3139
  },
3150
3140
  async runOnce() {
3151
3141
  if (stop !== void 0)
@@ -3474,9 +3464,7 @@ import { hostname } from "node:os";
3474
3464
  import PATH12 from "node:path";
3475
3465
  function decode(value) {
3476
3466
  return JSON.parse(value, (_key, candidate) => {
3477
- if (typeof candidate === "object" && candidate !== null && Object.keys(candidate).length === 1 && "$eventKitBigInt" in candidate && typeof candidate.$eventKitBigInt === "string" && /^(?:0|[1-9][0-9]*)$/u.test(candidate.$eventKitBigInt))
3478
- return BigInt(candidate.$eventKitBigInt);
3479
- return candidate;
3467
+ return typeof candidate === "object" && candidate !== null && Object.keys(candidate).length === 1 && "$eventKitBigInt" in candidate && typeof candidate.$eventKitBigInt === "string" && /^(?:0|[1-9][0-9]*)$/u.test(candidate.$eventKitBigInt) ? BigInt(candidate.$eventKitBigInt) : candidate;
3480
3468
  });
3481
3469
  }
3482
3470
  function processExists(pid) {