@kehto/services 0.13.1 → 0.14.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/dist/index.js CHANGED
@@ -231,9 +231,9 @@ function createNotificationService(options) {
231
231
 
232
232
  // src/identity-service.ts
233
233
  var IDENTITY_SERVICE_VERSION = "1.0.0";
234
- function sendProviderError(send, result, fallback, err2) {
234
+ function sendProviderError(send, result2, fallback, err2) {
235
235
  send({
236
- ...result,
236
+ ...result2,
237
237
  error: err2?.message ?? fallback
238
238
  });
239
239
  }
@@ -251,7 +251,7 @@ function sendOptionalProviderResult(options, send, fallbackResult, errorFallback
251
251
  send(fallbackResult);
252
252
  return;
253
253
  }
254
- Promise.resolve(getCurrentPubkey(options)).then((pubkey) => buildResult(pubkey)).then((result) => send(result)).catch((err2) => sendProviderError(send, fallbackResult, errorFallback, err2));
254
+ Promise.resolve(getCurrentPubkey(options)).then((pubkey) => buildResult(pubkey)).then((result2) => send(result2)).catch((err2) => sendProviderError(send, fallbackResult, errorFallback, err2));
255
255
  }
256
256
  function sendIdentityError(send, id, typeBase, error) {
257
257
  send({ type: `${typeBase}.error`, id, error });
@@ -262,21 +262,21 @@ function sendSignerError(send, id, typeBase, fallback, err2) {
262
262
  function handleGetPublicKey(options, id, send) {
263
263
  const signer = options.getSigner();
264
264
  if (!signer) {
265
- const result = {
265
+ const result2 = {
266
266
  type: "identity.getPublicKey.result",
267
267
  id,
268
268
  pubkey: ""
269
269
  };
270
- send(result);
270
+ send(result2);
271
271
  return;
272
272
  }
273
273
  Promise.resolve(signer.getPublicKey?.()).then((pubkey) => {
274
- const result = {
274
+ const result2 = {
275
275
  type: "identity.getPublicKey.result",
276
276
  id,
277
277
  pubkey: pubkey ?? ""
278
278
  };
279
- send(result);
279
+ send(result2);
280
280
  }).catch((err2) => sendSignerError(send, id, "identity.getPublicKey", "getPublicKey failed", err2));
281
281
  }
282
282
  function handleGetRelays(options, id, send) {
@@ -286,12 +286,12 @@ function handleGetRelays(options, id, send) {
286
286
  return;
287
287
  }
288
288
  Promise.resolve(signer.getRelays?.() ?? {}).then((relays) => {
289
- const result = {
289
+ const result2 = {
290
290
  type: "identity.getRelays.result",
291
291
  id,
292
292
  relays
293
293
  };
294
- send(result);
294
+ send(result2);
295
295
  }).catch((err2) => sendSignerError(send, id, "identity.getRelays", "getRelays failed", err2));
296
296
  }
297
297
  function handleReadProvider(options, id, message, send) {
@@ -560,6 +560,92 @@ function createCacheService(options) {
560
560
  };
561
561
  }
562
562
 
563
+ // src/count-service.ts
564
+ var DEFAULT_MAX_FILTERS = 16;
565
+ function createCountService(options) {
566
+ return {
567
+ descriptor: {
568
+ name: "count",
569
+ version: "1.0.0",
570
+ description: "Runtime-mediated NIP-01 filter counts"
571
+ },
572
+ handleMessage(windowId, message, send) {
573
+ if (message.type !== "count.query") return;
574
+ const countMessage = message;
575
+ const id = typeof countMessage.id === "string" ? countMessage.id : "";
576
+ const filters = countMessage.filters;
577
+ if (!isValidFilterArray(filters)) {
578
+ send(result(id, { ok: false, error: "invalid-filter", reason: "count.query requires a non-empty filters array" }));
579
+ return;
580
+ }
581
+ const maxFilters = options.maxFilters ?? DEFAULT_MAX_FILTERS;
582
+ if (filters.length > maxFilters) {
583
+ send(result(id, { ok: false, error: "too-expensive", reason: `count.query accepts at most ${maxFilters} filters` }));
584
+ return;
585
+ }
586
+ for (let i = 0; i < filters.length; i++) {
587
+ const supported = options.isFilterSupported?.(filters[i], i) ?? true;
588
+ if (supported !== true) {
589
+ send(result(id, {
590
+ ok: false,
591
+ error: "unsupported-filter",
592
+ reason: typeof supported === "string" ? supported : `filter ${i} is not supported by this count backend`
593
+ }));
594
+ return;
595
+ }
596
+ }
597
+ const request = {
598
+ filters,
599
+ windowId,
600
+ ...isPlainObject(countMessage.options) ? { options: countMessage.options } : {}
601
+ };
602
+ Promise.resolve(options.count(request)).then((countResult) => {
603
+ send(result(id, normalizeCountResult(countResult)));
604
+ }).catch((error) => {
605
+ send(result(id, {
606
+ ok: false,
607
+ error: "count-unavailable",
608
+ reason: error instanceof Error ? error.message : "count backend failed"
609
+ }));
610
+ });
611
+ }
612
+ };
613
+ }
614
+ function result(id, value) {
615
+ return {
616
+ type: "count.query.result",
617
+ id,
618
+ ok: value.ok,
619
+ ...typeof value.count === "number" ? { count: value.count } : {},
620
+ ...typeof value.approximate === "boolean" ? { approximate: value.approximate } : {},
621
+ ...typeof value.hll === "string" ? { hll: value.hll } : {},
622
+ ...Array.isArray(value.relays) ? { relays: value.relays.filter((relay) => typeof relay === "string") } : {},
623
+ ...typeof value.error === "string" ? { error: value.error } : {},
624
+ ...typeof value.reason === "string" ? { reason: value.reason } : {}
625
+ };
626
+ }
627
+ function normalizeCountResult(value) {
628
+ if (typeof value === "number") {
629
+ return Number.isFinite(value) && value >= 0 ? { ok: true, count: Math.floor(value), approximate: false } : { ok: false, error: "count-unavailable", reason: "count backend returned an invalid count" };
630
+ }
631
+ const count = typeof value.count === "number" && Number.isFinite(value.count) && value.count >= 0 ? Math.floor(value.count) : void 0;
632
+ return {
633
+ ok: value.ok === true,
634
+ ...count !== void 0 ? { count } : {},
635
+ ...typeof value.approximate === "boolean" ? { approximate: value.approximate } : {},
636
+ ...typeof value.hll === "string" ? { hll: value.hll } : {},
637
+ ...Array.isArray(value.relays) ? { relays: value.relays } : {},
638
+ ...typeof value.error === "string" ? { error: value.error } : {},
639
+ ...typeof value.reason === "string" ? { reason: value.reason } : {}
640
+ };
641
+ }
642
+ function isValidFilterArray(value) {
643
+ return Array.isArray(value) && value.length > 0 && value.every((filter) => isPlainObject(filter));
644
+ }
645
+ function isPlainObject(value) {
646
+ return typeof value === "object" && value !== null && !Array.isArray(value);
647
+ }
648
+
563
649
  // src/coordinated-relay.ts
564
650
  var DEFAULT_EOSE_TIMEOUT_MS = 15e3;
565
651
  function createCoordinatedRelay(options) {
@@ -807,13 +893,13 @@ function createKeysService(options = {}) {
807
893
  return;
808
894
  }
809
895
  }
810
- const result = {
896
+ const result2 = {
811
897
  type: "keys.registerAction.result",
812
898
  id: m.id,
813
899
  actionId: m.action.id,
814
900
  ...m.action.defaultKey ? { binding: m.action.defaultKey } : {}
815
901
  };
816
- send(result);
902
+ send(result2);
817
903
  return;
818
904
  }
819
905
  case "keys.unregisterAction": {
@@ -954,13 +1040,13 @@ function createKeysService(options = {}) {
954
1040
  return;
955
1041
  }
956
1042
  }
957
- const result = {
1043
+ const result2 = {
958
1044
  type: "keys.registerAction.result",
959
1045
  id: m.id,
960
1046
  actionId: m.action.id,
961
1047
  ...m.action.defaultKey ? { binding: m.action.defaultKey } : {}
962
1048
  };
963
- send(result);
1049
+ send(result2);
964
1050
  return;
965
1051
  }
966
1052
  case "keys.unregisterAction": {
@@ -1391,12 +1477,12 @@ function createNotifyService(options = {}) {
1391
1477
  case "notify.send": {
1392
1478
  const m = message;
1393
1479
  options.onSend?.(windowId, m);
1394
- const result = {
1480
+ const result2 = {
1395
1481
  type: "notify.send.result",
1396
1482
  id: m.id,
1397
1483
  notificationId: gen()
1398
1484
  };
1399
- send(result);
1485
+ send(result2);
1400
1486
  return;
1401
1487
  }
1402
1488
  case "notify.dismiss":
@@ -1405,12 +1491,12 @@ function createNotifyService(options = {}) {
1405
1491
  return;
1406
1492
  case "notify.permission.request": {
1407
1493
  const m = message;
1408
- const result = {
1494
+ const result2 = {
1409
1495
  type: "notify.permission.result",
1410
1496
  id: m.id,
1411
1497
  granted: defaultGrant
1412
1498
  };
1413
- send(result);
1499
+ send(result2);
1414
1500
  return;
1415
1501
  }
1416
1502
  default: {
@@ -1451,12 +1537,12 @@ function createThemeService(options = {}) {
1451
1537
  handleMessage(_windowId, message, send) {
1452
1538
  const id = message.id ?? "";
1453
1539
  if (message.type === "theme.get") {
1454
- const result = {
1540
+ const result2 = {
1455
1541
  type: "theme.get.result",
1456
1542
  id,
1457
1543
  theme: currentTheme
1458
1544
  };
1459
- send(result);
1545
+ send(result2);
1460
1546
  return;
1461
1547
  }
1462
1548
  send({
@@ -1580,14 +1666,14 @@ function createConfigService(options) {
1580
1666
  case "config.registerSchema": {
1581
1667
  const m = message;
1582
1668
  const validation = options.registerSchema ? options.registerSchema(windowId, m.schema, m.version) : validateCoreSubset(m.schema);
1583
- const result = validation.ok ? { type: "config.registerSchema.result", id: m.id, ok: true } : {
1669
+ const result2 = validation.ok ? { type: "config.registerSchema.result", id: m.id, ok: true } : {
1584
1670
  type: "config.registerSchema.result",
1585
1671
  id: m.id,
1586
1672
  ok: false,
1587
1673
  code: validation.code,
1588
1674
  error: validation.error
1589
1675
  };
1590
- send(result);
1676
+ send(result2);
1591
1677
  return;
1592
1678
  }
1593
1679
  case "config.openSettings": {
@@ -1958,33 +2044,33 @@ function buildEventQuery(eventId, eventOptions) {
1958
2044
  if (eventOptions?.timeoutMs !== void 0) queryOptions.timeoutMs = eventOptions.timeoutMs;
1959
2045
  return { filter, queryOptions };
1960
2046
  }
1961
- function eventResultFromQuery(eventId, result) {
1962
- const event = result.events.find((candidate) => candidate.id === eventId);
2047
+ function eventResultFromQuery(eventId, result2) {
2048
+ const event = result2.events.find((candidate) => candidate.id === eventId);
1963
2049
  const eventResult = {
1964
- relays: event ? result.relays[eventId] ?? [] : []
2050
+ relays: event ? result2.relays[eventId] ?? [] : []
1965
2051
  };
1966
2052
  if (event) eventResult.event = event;
1967
- if (!event) eventResult.error = result.error ?? "not found";
1968
- else if (result.error !== void 0) eventResult.error = result.error;
1969
- if (result.incomplete !== void 0) eventResult.incomplete = result.incomplete;
2053
+ if (!event) eventResult.error = result2.error ?? "not found";
2054
+ else if (result2.error !== void 0) eventResult.error = result2.error;
2055
+ if (result2.incomplete !== void 0) eventResult.incomplete = result2.incomplete;
1970
2056
  return eventResult;
1971
2057
  }
1972
2058
  function fallbackGetEvent(router, eventId, eventOptions) {
1973
2059
  const { filter, queryOptions } = buildEventQuery(eventId, eventOptions);
1974
- return router.query([filter], queryOptions).then((result) => eventResultFromQuery(eventId, result));
2060
+ return router.query([filter], queryOptions).then((result2) => eventResultFromQuery(eventId, result2));
1975
2061
  }
1976
- function sendEventResult(id, eventId, result, send) {
1977
- if (result.event && result.event.id !== eventId) {
2062
+ function sendEventResult(id, eventId, result2, send) {
2063
+ if (result2.event && result2.event.id !== eventId) {
1978
2064
  send({ type: "outbox.getEvent.result", id, relays: [], error: "not found" });
1979
2065
  return;
1980
2066
  }
1981
2067
  send({
1982
2068
  type: "outbox.getEvent.result",
1983
2069
  id,
1984
- ...result.event === void 0 ? {} : { event: result.event },
1985
- relays: result.relays,
1986
- ...result.incomplete === void 0 ? {} : { incomplete: result.incomplete },
1987
- ...result.error === void 0 ? {} : { error: result.error }
2070
+ ...result2.event === void 0 ? {} : { event: result2.event },
2071
+ relays: result2.relays,
2072
+ ...result2.incomplete === void 0 ? {} : { incomplete: result2.incomplete },
2073
+ ...result2.error === void 0 ? {} : { error: result2.error }
1988
2074
  });
1989
2075
  }
1990
2076
  function handleGetEvent(router, msg, send) {
@@ -1995,7 +2081,7 @@ function handleGetEvent(router, msg, send) {
1995
2081
  return;
1996
2082
  }
1997
2083
  const getEvent = router.getEvent ?? ((eventId, eventOptions) => fallbackGetEvent(router, eventId, eventOptions));
1998
- void getEvent(m.eventId, m.options).then((result) => sendEventResult(id, m.eventId, result, send)).catch(
2084
+ void getEvent(m.eventId, m.options).then((result2) => sendEventResult(id, m.eventId, result2, send)).catch(
1999
2085
  (err2) => send({ type: "outbox.getEvent.result", id, relays: [], error: toErrorMessage(err2) })
2000
2086
  );
2001
2087
  }
@@ -2014,13 +2100,13 @@ function createOutboxService(options) {
2014
2100
  return;
2015
2101
  }
2016
2102
  void router.query(filters, m.options).then(
2017
- (result) => send({
2103
+ (result2) => send({
2018
2104
  type: "outbox.query.result",
2019
2105
  id,
2020
- events: result.events,
2021
- relays: result.relays,
2022
- ...result.incomplete === void 0 ? {} : { incomplete: result.incomplete },
2023
- ...result.error === void 0 ? {} : { error: result.error }
2106
+ events: result2.events,
2107
+ relays: result2.relays,
2108
+ ...result2.incomplete === void 0 ? {} : { incomplete: result2.incomplete },
2109
+ ...result2.error === void 0 ? {} : { error: result2.error }
2024
2110
  })
2025
2111
  ).catch(
2026
2112
  (err2) => send({ type: "outbox.query.result", id, events: [], relays: {}, error: toErrorMessage(err2) })
@@ -2065,14 +2151,14 @@ function createOutboxService(options) {
2065
2151
  return;
2066
2152
  }
2067
2153
  void router.publish(m.event, m.options).then(
2068
- (result) => send({
2154
+ (result2) => send({
2069
2155
  type: "outbox.publish.result",
2070
2156
  id,
2071
- ok: result.ok,
2072
- ...result.event === void 0 ? {} : { event: result.event },
2073
- ...result.eventId === void 0 ? {} : { eventId: result.eventId },
2074
- ...result.relays === void 0 ? {} : { relays: result.relays },
2075
- ...result.error === void 0 ? {} : { error: result.error }
2157
+ ok: result2.ok,
2158
+ ...result2.event === void 0 ? {} : { event: result2.event },
2159
+ ...result2.eventId === void 0 ? {} : { eventId: result2.eventId },
2160
+ ...result2.relays === void 0 ? {} : { relays: result2.relays },
2161
+ ...result2.error === void 0 ? {} : { error: result2.error }
2076
2162
  })
2077
2163
  ).catch(
2078
2164
  (err2) => send({ type: "outbox.publish.result", id, ok: false, error: toErrorMessage(err2) })
@@ -2269,9 +2355,9 @@ async function queryImpl(ctx, filters, options) {
2269
2355
  if (options?.limit !== void 0 && events.length > options.limit) {
2270
2356
  events = [...events].sort((a, b) => b.created_at - a.created_at).slice(0, options.limit);
2271
2357
  }
2272
- const result = { events, relays: collected.relayMap };
2273
- if (incomplete) result.incomplete = true;
2274
- return result;
2358
+ const result2 = { events, relays: collected.relayMap };
2359
+ if (incomplete) result2.incomplete = true;
2360
+ return result2;
2275
2361
  }
2276
2362
  async function getEventImpl(ctx, eventId, options) {
2277
2363
  if (typeof eventId !== "string" || eventId.length === 0) {
@@ -2288,14 +2374,14 @@ async function getEventImpl(ctx, eventId, options) {
2288
2374
  if (options?.timeoutMs !== void 0) queryOptions.timeoutMs = options.timeoutMs;
2289
2375
  const queryResult = await queryImpl(ctx, [filter], queryOptions);
2290
2376
  const event = queryResult.events.find((candidate) => candidate.id === eventId);
2291
- const result = {
2377
+ const result2 = {
2292
2378
  relays: event ? queryResult.relays[eventId] ?? [] : []
2293
2379
  };
2294
- if (event) result.event = event;
2295
- if (!event) result.error = queryResult.error ?? "not found";
2296
- else if (queryResult.error !== void 0) result.error = queryResult.error;
2297
- if (queryResult.incomplete !== void 0) result.incomplete = queryResult.incomplete;
2298
- return result;
2380
+ if (event) result2.event = event;
2381
+ if (!event) result2.error = queryResult.error ?? "not found";
2382
+ else if (queryResult.error !== void 0) result2.error = queryResult.error;
2383
+ if (queryResult.incomplete !== void 0) result2.incomplete = queryResult.incomplete;
2384
+ return result2;
2299
2385
  }
2300
2386
  function closeLiveSub(sub) {
2301
2387
  for (const handle of sub.handles) {
@@ -2384,9 +2470,9 @@ async function publishImpl(ctx, template, options) {
2384
2470
  return { ok: false, event: signed, eventId: signed.id, error: err2 instanceof Error ? err2.message : "publish failed" };
2385
2471
  }
2386
2472
  const ok = Object.values(relays).some(Boolean);
2387
- const result = { ok, event: signed, eventId: signed.id, relays };
2388
- if (!ok) result.error = "publish denied";
2389
- return result;
2473
+ const result2 = { ok, event: signed, eventId: signed.id, relays };
2474
+ if (!ok) result2.error = "publish denied";
2475
+ return result2;
2390
2476
  }
2391
2477
  function createRelayPoolOutboxRouter(options) {
2392
2478
  if (!options || typeof options.relayPool !== "object" || options.relayPool === null) {
@@ -2496,8 +2582,8 @@ function createUploadService(options) {
2496
2582
  send({ type: "upload.status.changed", status: stamped });
2497
2583
  }
2498
2584
  };
2499
- void uploader.upload(request, ctx).then((result) => {
2500
- const stamped = { ...result, uploadId };
2585
+ void uploader.upload(request, ctx).then((result2) => {
2586
+ const stamped = { ...result2, uploadId };
2501
2587
  const entry = entries.get(key);
2502
2588
  if (entry) entry.status = { ...stamped, updatedAt: now() };
2503
2589
  send({ type: "upload.upload.result", id, result: stamped });
@@ -2634,7 +2720,7 @@ async function uploadNip96(args) {
2634
2720
  function fromNip94Tags(uploadId, rail, tags, fallbackSize, fallbackSha) {
2635
2721
  const get = (name) => tags.find((t) => t[0] === name)?.[1];
2636
2722
  const url = get("url");
2637
- const result = {
2723
+ const result2 = {
2638
2724
  ok: Boolean(url),
2639
2725
  uploadId,
2640
2726
  status: url ? "complete" : "failed",
@@ -2642,19 +2728,19 @@ function fromNip94Tags(uploadId, rail, tags, fallbackSize, fallbackSha) {
2642
2728
  sha256: get("x") ?? fallbackSha,
2643
2729
  nip94: tags
2644
2730
  };
2645
- if (url) result.url = url;
2731
+ if (url) result2.url = url;
2646
2732
  const ox = get("ox");
2647
- if (ox) result.originalSha256 = ox;
2733
+ if (ox) result2.originalSha256 = ox;
2648
2734
  const size = get("size");
2649
- result.size = size ? Number(size) : fallbackSize;
2735
+ result2.size = size ? Number(size) : fallbackSize;
2650
2736
  const m = get("m");
2651
- if (m) result.mimeType = m;
2737
+ if (m) result2.mimeType = m;
2652
2738
  const dim = parseDimensions(get("dim"));
2653
- if (dim) result.dimensions = dim;
2739
+ if (dim) result2.dimensions = dim;
2654
2740
  const blurhash = get("blurhash");
2655
- if (blurhash) result.blurhash = blurhash;
2656
- if (!url) result.error = "server returned no url";
2657
- return result;
2741
+ if (blurhash) result2.blurhash = blurhash;
2742
+ if (!url) result2.error = "server returned no url";
2743
+ return result2;
2658
2744
  }
2659
2745
  async function uploadBlossom(args) {
2660
2746
  const { request, ctx, server, bytes, sha256, signEvent, fetchFn, nowS } = args;
@@ -2683,7 +2769,7 @@ async function uploadBlossom(args) {
2683
2769
  if (!blob.url) {
2684
2770
  return failed(ctx.uploadId, "blossom", "server returned no url", sha256);
2685
2771
  }
2686
- const result = {
2772
+ const result2 = {
2687
2773
  ok: true,
2688
2774
  uploadId: ctx.uploadId,
2689
2775
  status: "complete",
@@ -2692,8 +2778,8 @@ async function uploadBlossom(args) {
2692
2778
  sha256: blob.sha256 ?? sha256,
2693
2779
  size: blob.size ?? bytes.byteLength
2694
2780
  };
2695
- if (blob.type) result.mimeType = blob.type;
2696
- return result;
2781
+ if (blob.type) result2.mimeType = blob.type;
2782
+ return result2;
2697
2783
  }
2698
2784
  function failed(uploadId, rail, error, sha256) {
2699
2785
  return { ok: false, uploadId, status: "failed", rail, error, ...sha256 ? { sha256 } : {} };
@@ -2781,7 +2867,7 @@ function createIntentService(options) {
2781
2867
  send,
2782
2868
  "intent.invoke.result",
2783
2869
  id,
2784
- (result) => ({ type: "intent.invoke.result", id, result })
2870
+ (result2) => ({ type: "intent.invoke.result", id, result: result2 })
2785
2871
  );
2786
2872
  }
2787
2873
  function handleAvailable(msg, send) {
@@ -3111,12 +3197,12 @@ async function handleOpen(options, windowId, message, send) {
3111
3197
  return;
3112
3198
  }
3113
3199
  try {
3114
- const result = await options.open({ windowId, url: parsed, options: message.options });
3200
+ const result2 = await options.open({ windowId, url: parsed, options: message.options });
3115
3201
  send({
3116
3202
  type: "link.open.result",
3117
3203
  id: message.id,
3118
- status: result.status,
3119
- ...result.status === "denied" ? { error: "blocked-by-policy" } : {}
3204
+ status: result2.status,
3205
+ ...result2.status === "denied" ? { error: "blocked-by-policy" } : {}
3120
3206
  });
3121
3207
  } catch {
3122
3208
  send(denied(message.id, "blocked-by-policy"));
@@ -3188,7 +3274,7 @@ function settleMutation(hook, message, context, send, resultType) {
3188
3274
  () => hook(message.list, message.items, message.options, context),
3189
3275
  send,
3190
3276
  (error) => ({ type: resultType, id: message.id, ok: false, error: "list-unavailable", reason: error }),
3191
- (result) => ({ type: resultType, id: message.id, ...result })
3277
+ (result2) => ({ type: resultType, id: message.id, ...result2 })
3192
3278
  );
3193
3279
  }
3194
3280
  function createListsService(options = {}) {
@@ -3274,7 +3360,7 @@ function createSerialService(options = {}) {
3274
3360
  () => options.open(serialMessage.request, context),
3275
3361
  send,
3276
3362
  (error) => ({ type: "serial.open.result", id, error }),
3277
- (result) => ({ type: "serial.open.result", id, session: result.session })
3363
+ (result2) => ({ type: "serial.open.result", id, session: result2.session })
3278
3364
  );
3279
3365
  return;
3280
3366
  }
@@ -3371,7 +3457,7 @@ function createBleService(options = {}) {
3371
3457
  () => options.open(bleMessage.request, context),
3372
3458
  send,
3373
3459
  (error) => ({ type: "ble.open.result", id, error }),
3374
- (result) => ({ type: "ble.open.result", id, session: result.session })
3460
+ (result2) => ({ type: "ble.open.result", id, session: result2.session })
3375
3461
  );
3376
3462
  return;
3377
3463
  }
@@ -3524,7 +3610,7 @@ function createWebrtcService(options = {}) {
3524
3610
  () => options.open(webrtcMessage.request, context),
3525
3611
  send,
3526
3612
  (error) => ({ type: "webrtc.open.result", id, error }),
3527
- (result) => ({ type: "webrtc.open.result", id, session: result.session })
3613
+ (result2) => ({ type: "webrtc.open.result", id, session: result2.session })
3528
3614
  );
3529
3615
  return;
3530
3616
  }
@@ -3675,7 +3761,7 @@ function decodeNrelay(value) {
3675
3761
  function convertBits(data, fromBits, toBits, pad) {
3676
3762
  let acc = 0;
3677
3763
  let bits = 0;
3678
- const result = [];
3764
+ const result2 = [];
3679
3765
  const maxv = (1 << toBits) - 1;
3680
3766
  const maxAcc = (1 << fromBits + toBits - 1) - 1;
3681
3767
  for (const value of data) {
@@ -3684,15 +3770,15 @@ function convertBits(data, fromBits, toBits, pad) {
3684
3770
  bits += fromBits;
3685
3771
  while (bits >= toBits) {
3686
3772
  bits -= toBits;
3687
- result.push(acc >> bits & maxv);
3773
+ result2.push(acc >> bits & maxv);
3688
3774
  }
3689
3775
  }
3690
3776
  if (pad) {
3691
- if (bits > 0) result.push(acc << toBits - bits & maxv);
3777
+ if (bits > 0) result2.push(acc << toBits - bits & maxv);
3692
3778
  } else if (bits >= fromBits || (acc << toBits - bits & maxv) !== 0) {
3693
3779
  throw new Error("invalid bech32 padding");
3694
3780
  }
3695
- return result;
3781
+ return result2;
3696
3782
  }
3697
3783
  function settle5(call, send, okFalse, onValue) {
3698
3784
  let pending;
@@ -3712,14 +3798,14 @@ function createCommonService(options = {}) {
3712
3798
  const context = { windowId };
3713
3799
  if (message.type === "common.encodeNip19") {
3714
3800
  const input = message.input;
3715
- const result = input ? encodeNip19(input) : { ok: false, error: "invalid input" };
3716
- send({ type: "common.encodeNip19.result", id, ...result });
3801
+ const result2 = input ? encodeNip19(input) : { ok: false, error: "invalid input" };
3802
+ send({ type: "common.encodeNip19.result", id, ...result2 });
3717
3803
  return;
3718
3804
  }
3719
3805
  if (message.type === "common.decodeNip19") {
3720
3806
  const value = message.value;
3721
- const result = typeof value === "string" ? decodeNip19Value(value) : { ok: false, error: "invalid value" };
3722
- send({ type: "common.decodeNip19.result", id, ...result });
3807
+ const result2 = typeof value === "string" ? decodeNip19Value(value) : { ok: false, error: "invalid value" };
3808
+ send({ type: "common.decodeNip19.result", id, ...result2 });
3723
3809
  return;
3724
3810
  }
3725
3811
  if (message.type === "common.getProfile") {
@@ -3732,7 +3818,7 @@ function createCommonService(options = {}) {
3732
3818
  () => options.getProfile(target, context),
3733
3819
  send,
3734
3820
  (error) => ({ type: "common.getProfile.result", id, ok: false, pubkey: target ?? "", error }),
3735
- (result) => ({ type: "common.getProfile.result", id, ...result })
3821
+ (result2) => ({ type: "common.getProfile.result", id, ...result2 })
3736
3822
  );
3737
3823
  return;
3738
3824
  }
@@ -3745,7 +3831,7 @@ function createCommonService(options = {}) {
3745
3831
  () => options.follows(context),
3746
3832
  send,
3747
3833
  (error) => ({ type: "common.follows.result", id, ok: false, pubkeys: [], error }),
3748
- (result) => ({ type: "common.follows.result", id, ...result })
3834
+ (result2) => ({ type: "common.follows.result", id, ...result2 })
3749
3835
  );
3750
3836
  return;
3751
3837
  }
@@ -3769,7 +3855,7 @@ function createCommonService(options = {}) {
3769
3855
  () => options.react(m.targetEventId, m.reaction, m.customEmojiHref, context),
3770
3856
  send,
3771
3857
  (error) => ({ type: "common.react.result", id, ok: false, error }),
3772
- (result) => ({ type: "common.react.result", id, ...result })
3858
+ (result2) => ({ type: "common.react.result", id, ...result2 })
3773
3859
  );
3774
3860
  return;
3775
3861
  }
@@ -3783,7 +3869,7 @@ function createCommonService(options = {}) {
3783
3869
  () => options.report(m.target, m.reason, m.text, context),
3784
3870
  send,
3785
3871
  (error) => ({ type: "common.report.result", id, ok: false, error }),
3786
- (result) => ({ type: "common.report.result", id, ...result })
3872
+ (result2) => ({ type: "common.report.result", id, ...result2 })
3787
3873
  );
3788
3874
  return;
3789
3875
  }
@@ -3806,7 +3892,7 @@ function settleAction(action, pubkeys, context, send, resultType, id, unavailabl
3806
3892
  () => action(pubkeys, context),
3807
3893
  send,
3808
3894
  (error) => ({ type: resultType, id, ok: false, error }),
3809
- (result) => ({ type: resultType, id, ...result })
3895
+ (result2) => ({ type: resultType, id, ...result2 })
3810
3896
  );
3811
3897
  }
3812
3898
 
@@ -3861,7 +3947,7 @@ function createDmService(options) {
3861
3947
  );
3862
3948
  return;
3863
3949
  case "dm.send":
3864
- void adapter.send(message).then((result) => send({ type: "dm.send.result", id: requestId, ...result })).catch((error) => send({ type: "dm.send.result", id: requestId, error: err(error) }));
3950
+ void adapter.send(message).then((result2) => send({ type: "dm.send.result", id: requestId, ...result2 })).catch((error) => send({ type: "dm.send.result", id: requestId, error: err(error) }));
3865
3951
  return;
3866
3952
  case "dm.subscribe": {
3867
3953
  let activeSubscriptionId = "";
@@ -4463,6 +4549,7 @@ export {
4463
4549
  createCoordinatedRelay,
4464
4550
  createCordnDmAdapter,
4465
4551
  createCordnRelayCoordinatorClient,
4552
+ createCountService,
4466
4553
  createCvmService,
4467
4554
  createDmService,
4468
4555
  createHttpUploader,