@kehto/paja 0.6.0 → 0.6.3

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.
@@ -243,7 +243,7 @@ function cvmMap(action) {
243
243
  return { senderCap: "cvm:call", recipientCap: null };
244
244
  }
245
245
  function outboxMap(action) {
246
- if (action === "event" || action === "eose" || action === "closed" || action.endsWith(".result") || action.endsWith(".error")) {
246
+ if (action === "event" || action === "closed" || action.endsWith(".result") || action.endsWith(".error")) {
247
247
  return { senderCap: null, recipientCap: "outbox:read" };
248
248
  }
249
249
  if (action === "publish") return { senderCap: "outbox:write", recipientCap: null };
@@ -612,7 +612,7 @@ function deserialize2(json) {
612
612
  return defaultConfig();
613
613
  }
614
614
 
615
- // ../../node_modules/.pnpm/@napplet+core@0.25.0/node_modules/@napplet/core/dist/index.js
615
+ // ../../node_modules/.pnpm/@napplet+core@0.27.0/node_modules/@napplet/core/dist/index.js
616
616
  function createDispatch() {
617
617
  const handlers = /* @__PURE__ */ new Map();
618
618
  function registerNap2(domain, handler) {
@@ -8903,6 +8903,59 @@ var OUTBOX_DESCRIPTOR = {
8903
8903
  version: OUTBOX_SERVICE_VERSION,
8904
8904
  description: "NAP-OUTBOX outbox-aware relay routing \u2014 getEvent/query/subscribe/publish/resolveRelays"
8905
8905
  };
8906
+ function isRecord2(value) {
8907
+ return typeof value === "object" && value !== null;
8908
+ }
8909
+ function stringArray(value) {
8910
+ if (!Array.isArray(value)) return void 0;
8911
+ const strings = value.filter((item) => typeof item === "string");
8912
+ return strings.length > 0 ? strings : void 0;
8913
+ }
8914
+ function uint(value) {
8915
+ return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : void 0;
8916
+ }
8917
+ function sanitizeEventOptions(raw) {
8918
+ if (!isRecord2(raw)) return void 0;
8919
+ const out = {};
8920
+ if (typeof raw.author === "string") out.author = raw.author;
8921
+ const relays = stringArray(raw.relays);
8922
+ if (relays) out.relays = relays;
8923
+ const timeoutMs = uint(raw.timeoutMs);
8924
+ if (timeoutMs !== void 0) out.timeoutMs = timeoutMs;
8925
+ return Object.keys(out).length > 0 ? out : void 0;
8926
+ }
8927
+ function sanitizeQueryOptions(raw) {
8928
+ if (!isRecord2(raw)) return void 0;
8929
+ const out = {};
8930
+ const authors = stringArray(raw.authors);
8931
+ if (authors) out.authors = authors;
8932
+ const relays = stringArray(raw.relays);
8933
+ if (relays) out.relays = relays;
8934
+ const limit = uint(raw.limit);
8935
+ if (limit !== void 0) out.limit = limit;
8936
+ const timeoutMs = uint(raw.timeoutMs);
8937
+ if (timeoutMs !== void 0) out.timeoutMs = timeoutMs;
8938
+ return Object.keys(out).length > 0 ? out : void 0;
8939
+ }
8940
+ var sanitizeSubscribeOptions = sanitizeQueryOptions;
8941
+ function sanitizePublishOptions(raw) {
8942
+ if (!isRecord2(raw)) return void 0;
8943
+ const out = {};
8944
+ const relays = stringArray(raw.relays);
8945
+ if (relays) out.relays = relays;
8946
+ const targetAuthors = stringArray(raw.targetAuthors);
8947
+ if (targetAuthors) out.targetAuthors = targetAuthors;
8948
+ return Object.keys(out).length > 0 ? out : void 0;
8949
+ }
8950
+ function sanitizeTarget(raw) {
8951
+ if (!isRecord2(raw)) return void 0;
8952
+ const out = {};
8953
+ const authors = stringArray(raw.authors);
8954
+ if (authors) out.authors = authors;
8955
+ if (typeof raw.pubkey === "string") out.pubkey = raw.pubkey;
8956
+ if (raw.direction === "read" || raw.direction === "write") out.direction = raw.direction;
8957
+ return out;
8958
+ }
8906
8959
  function normalizeFilters(raw) {
8907
8960
  if (Array.isArray(raw)) {
8908
8961
  const filters = raw.filter((f) => typeof f === "object" && f !== null);
@@ -8919,7 +8972,6 @@ function buildEventQuery(eventId, eventOptions) {
8919
8972
  queryOptions.authors = [eventOptions.author];
8920
8973
  }
8921
8974
  if (Array.isArray(eventOptions?.relays)) queryOptions.relays = eventOptions.relays;
8922
- if (eventOptions?.strategy !== void 0) queryOptions.strategy = eventOptions.strategy;
8923
8975
  if (eventOptions?.timeoutMs !== void 0) queryOptions.timeoutMs = eventOptions.timeoutMs;
8924
8976
  return { filter, queryOptions };
8925
8977
  }
@@ -8957,7 +9009,7 @@ function handleGetEvent(router, msg, send) {
8957
9009
  return;
8958
9010
  }
8959
9011
  const getEvent = router.getEvent ?? ((eventId, eventOptions) => fallbackGetEvent(router, eventId, eventOptions));
8960
- void getEvent(m.eventId, m.options).then((result2) => sendEventResult(id, m.eventId, result2, send)).catch(
9012
+ void getEvent(m.eventId, sanitizeEventOptions(m.options)).then((result2) => sendEventResult(id, m.eventId, result2, send)).catch(
8961
9013
  (err2) => send({ type: "outbox.getEvent.result", id, error: toErrorMessage(err2) })
8962
9014
  );
8963
9015
  }
@@ -8975,7 +9027,7 @@ function createOutboxService(options) {
8975
9027
  send({ type: "outbox.query.result", id, events: [], error: "invalid filter" });
8976
9028
  return;
8977
9029
  }
8978
- void router.query(filters, m.options).then(
9030
+ void router.query(filters, sanitizeQueryOptions(m.options)).then(
8979
9031
  (result2) => send({
8980
9032
  type: "outbox.query.result",
8981
9033
  id,
@@ -9006,7 +9058,7 @@ function createOutboxService(options) {
9006
9058
  send({ type: "outbox.closed", subId, ...reason === void 0 ? {} : { reason } });
9007
9059
  }
9008
9060
  };
9009
- subscriptions.set(subKey, router.subscribe(filters, m.options, sink));
9061
+ subscriptions.set(subKey, router.subscribe(filters, sanitizeSubscribeOptions(m.options), sink));
9010
9062
  }
9011
9063
  function handleClose(windowId, msg, send) {
9012
9064
  const m = msg;
@@ -9024,7 +9076,7 @@ function createOutboxService(options) {
9024
9076
  send({ type: "outbox.publish.result", id, ok: false, error: "invalid filter" });
9025
9077
  return;
9026
9078
  }
9027
- void router.publish(m.event, m.options).then(
9079
+ void router.publish(m.event, sanitizePublishOptions(m.options)).then(
9028
9080
  (result2) => send({
9029
9081
  type: "outbox.publish.result",
9030
9082
  id,
@@ -9041,11 +9093,12 @@ function createOutboxService(options) {
9041
9093
  function handleResolveRelays(msg, send) {
9042
9094
  const m = msg;
9043
9095
  const id = m.id ?? "";
9044
- if (!m.target || typeof m.target !== "object") {
9096
+ const target = sanitizeTarget(m.target);
9097
+ if (!target) {
9045
9098
  send({ type: "outbox.resolveRelays.result", id, error: "invalid filter" });
9046
9099
  return;
9047
9100
  }
9048
- void router.resolveRelays(m.target).then((plan) => send({ type: "outbox.resolveRelays.result", id, plan })).catch(
9101
+ void router.resolveRelays(target).then((plan) => send({ type: "outbox.resolveRelays.result", id, plan })).catch(
9049
9102
  (err2) => send({ type: "outbox.resolveRelays.result", id, error: toErrorMessage(err2) })
9050
9103
  );
9051
9104
  }
@@ -11133,9 +11186,9 @@ var __export = (target, all) => {
11133
11186
  __defProp(target, name, { get: all[name], enumerable: true });
11134
11187
  };
11135
11188
  var verifiedSymbol2 = /* @__PURE__ */ Symbol("verified");
11136
- var isRecord2 = (obj) => obj instanceof Object;
11189
+ var isRecord3 = (obj) => obj instanceof Object;
11137
11190
  function validateEvent2(event) {
11138
- if (!isRecord2(event))
11191
+ if (!isRecord3(event))
11139
11192
  return false;
11140
11193
  if (typeof event.kind !== "number")
11141
11194
  return false;
@@ -14073,9 +14126,9 @@ function renderSignerStatus(state, signerPubkey) {
14073
14126
 
14074
14127
  // ../../node_modules/.pnpm/nostr-tools@2.23.3_typescript@5.9.3/node_modules/nostr-tools/lib/esm/pool.js
14075
14128
  var verifiedSymbol3 = /* @__PURE__ */ Symbol("verified");
14076
- var isRecord3 = (obj) => obj instanceof Object;
14129
+ var isRecord4 = (obj) => obj instanceof Object;
14077
14130
  function validateEvent3(event) {
14078
- if (!isRecord3(event))
14131
+ if (!isRecord4(event))
14079
14132
  return false;
14080
14133
  if (typeof event.kind !== "number")
14081
14134
  return false;
@@ -15564,7 +15617,7 @@ async function resolveNapplet(options) {
15564
15617
  }
15565
15618
 
15566
15619
  // src/runtime-resolver.ts
15567
- var PAJA_NAPPLET_MANIFEST_KIND = 35129;
15620
+ var PAJA_NAPPLET_MANIFEST_KINDS = NAPPLET_KINDS;
15568
15621
  function decodePajaPointer(value) {
15569
15622
  const trimmed = value.trim();
15570
15623
  const decoded = decode(trimmed);
@@ -15648,17 +15701,17 @@ async function resolvePointerEvent(pointer, pool, relays, maxWaitMs) {
15648
15701
  if (!event) {
15649
15702
  throw new Error(`No napplet manifest event found for ${pointer.type} pointer.`);
15650
15703
  }
15651
- if (event.kind !== PAJA_NAPPLET_MANIFEST_KIND) {
15652
- throw new Error(`Pointer resolved kind ${event.kind}; expected ${PAJA_NAPPLET_MANIFEST_KIND}.`);
15704
+ if (!isNappletManifestKind(event.kind)) {
15705
+ throw new Error(`Pointer resolved kind ${event.kind}; expected ${formatNappletManifestKinds()}.`);
15653
15706
  }
15654
15707
  return event;
15655
15708
  }
15656
15709
  function addressableFilter(pointer) {
15657
- if (pointer.kind !== PAJA_NAPPLET_MANIFEST_KIND) {
15658
- throw new Error(`naddr kind ${pointer.kind} is not a napplet manifest kind.`);
15710
+ if (pointer.kind !== NAPPLET_KIND_NAMED) {
15711
+ throw new Error(`naddr kind ${pointer.kind} is not a named NIP-5D napplet manifest kind.`);
15659
15712
  }
15660
15713
  return {
15661
- kinds: [PAJA_NAPPLET_MANIFEST_KIND],
15714
+ kinds: [NAPPLET_KIND_NAMED],
15662
15715
  authors: [pointer.pubkey],
15663
15716
  "#d": [pointer.identifier],
15664
15717
  limit: 1
@@ -15708,6 +15761,9 @@ function normalizeRelayUrl(value) {
15708
15761
  function escapeAttribute(value) {
15709
15762
  return value.replaceAll("&", "&amp;").replaceAll('"', "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
15710
15763
  }
15764
+ function formatNappletManifestKinds() {
15765
+ return PAJA_NAPPLET_MANIFEST_KINDS.join(" / ");
15766
+ }
15711
15767
 
15712
15768
  // src/browser-host.ts
15713
15769
  var bridgeRef = null;