@ghostlytools/cli 1.13.0 → 1.13.2

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.
Files changed (113) hide show
  1. package/README.md +13 -10
  2. package/dist/assets/api-DV52o7A8.js +3 -0
  3. package/dist/assets/{api-CjOaoG-v.js → api-O57SNJcb.js} +495 -99
  4. package/dist/assets/api-O57SNJcb.js.map +1 -0
  5. package/dist/assets/{apiKit-BAGvlQtm.js → apiKit-CPTFJHA7.js} +40 -8
  6. package/dist/assets/{apiKit-BAGvlQtm.js.map → apiKit-CPTFJHA7.js.map} +1 -1
  7. package/dist/assets/{appFetch-BwJd-kNq.js → appFetch-Ca9DNQQ2.js} +2 -2
  8. package/dist/assets/{appFetch-BwJd-kNq.js.map → appFetch-Ca9DNQQ2.js.map} +1 -1
  9. package/dist/assets/{apps-Cuk45sz5.js → apps-gXpGFPiv.js} +16 -14
  10. package/dist/assets/apps-gXpGFPiv.js.map +1 -0
  11. package/dist/assets/{apps-DjY095Af.js → apps-uZTu5FlR.js} +1 -1
  12. package/dist/assets/{arkade-DryM-q5n.js → arkade-B6UNf5HI.js} +2 -2
  13. package/dist/assets/{arkade-DryM-q5n.js.map → arkade-B6UNf5HI.js.map} +1 -1
  14. package/dist/assets/{backup-DekVCDWv.js → backup-CxH3auHB.js} +9 -7
  15. package/dist/assets/backup-CxH3auHB.js.map +1 -0
  16. package/dist/assets/{backup-B56sQqoQ.js → backup-Di2U6QVH.js} +1 -1
  17. package/dist/assets/bark_ffi_wasm_bg-CcafsJla.js.map +1 -1
  18. package/dist/assets/{bitcoind-B2bbVSzh.js → bitcoind-BpZn3bRN.js} +2 -2
  19. package/dist/assets/{bitcoind-B2bbVSzh.js.map → bitcoind-BpZn3bRN.js.map} +1 -1
  20. package/dist/assets/bitcoindevkit_bg-BWQHx7vd.js.map +1 -1
  21. package/dist/assets/{buttons-BGxzOtrq.js → buttons-D4udKEvT.js} +8 -8
  22. package/dist/assets/buttons-D4udKEvT.js.map +1 -0
  23. package/dist/assets/buttons-YTYEqvGC.js +1 -0
  24. package/dist/assets/{client-DcQAfc3h.js → client-DGx7E8b3.js} +3 -3
  25. package/dist/assets/{client-DcQAfc3h.js.map → client-DGx7E8b3.js.map} +1 -1
  26. package/dist/assets/{domainProofs-BDNP1dIy.js → domainProofs-b3Y1Gj9g.js} +6 -2
  27. package/dist/assets/{domainProofs-BDNP1dIy.js.map → domainProofs-b3Y1Gj9g.js.map} +1 -1
  28. package/dist/assets/{engineErrors--9hfgKlK.js → engineErrors-wWlLy54D.js} +11 -3
  29. package/dist/assets/engineErrors-wWlLy54D.js.map +1 -0
  30. package/dist/assets/{errors-DDLFO4Gf.js → errors-JVJsO8Iu.js} +18 -2
  31. package/dist/assets/errors-JVJsO8Iu.js.map +1 -0
  32. package/dist/assets/{fixedHosts-C3hBliM9.js → fixedHosts-CODN2pTL.js} +3 -3
  33. package/dist/assets/{fixedHosts-C3hBliM9.js.map → fixedHosts-CODN2pTL.js.map} +1 -1
  34. package/dist/assets/{ghostly_iroh_web-DIj5xGmR.js → ghostly_iroh_web-9VOwZcJQ.js} +30 -35
  35. package/dist/assets/ghostly_iroh_web-9VOwZcJQ.js.map +1 -0
  36. package/dist/assets/ghostly_iroh_web_bg.wasm +0 -0
  37. package/dist/assets/{groupMeta-goASqzOt.js → groupMeta-CeZpqVVC.js} +174 -37
  38. package/dist/assets/groupMeta-CeZpqVVC.js.map +1 -0
  39. package/dist/assets/{host-C2WRKj3g.js → host-CRA7h5A2.js} +270 -64
  40. package/dist/assets/host-CRA7h5A2.js.map +1 -0
  41. package/dist/assets/{hyperdhtRelay-DLUiwfnt.js → hyperdhtRelay-B34Zhz4P.js} +2 -2
  42. package/dist/assets/{hyperdhtRelay-DLUiwfnt.js.map → hyperdhtRelay-B34Zhz4P.js.map} +1 -1
  43. package/dist/assets/{hyperdhtRelay-bjNGacf5.js → hyperdhtRelay-DDwU5b4P.js} +2 -2
  44. package/dist/assets/{hyperdhtRelay-bjNGacf5.js.map → hyperdhtRelay-DDwU5b4P.js.map} +1 -1
  45. package/dist/assets/{identityProofs-Cksc_K7_.js → identityProofs-B8zCp5_0.js} +140 -27
  46. package/dist/assets/identityProofs-B8zCp5_0.js.map +1 -0
  47. package/dist/assets/{irohWeb-NfthOL98.js → irohWeb-mnOi2Jp7.js} +10838 -4837
  48. package/dist/assets/irohWeb-mnOi2Jp7.js.map +1 -0
  49. package/dist/assets/{linkPreview-DdMf-YAc.js → linkPreview-5kHmKUTN.js} +20 -8
  50. package/dist/assets/linkPreview-5kHmKUTN.js.map +1 -0
  51. package/dist/assets/{main-Dh7fePd8.js → main-Chc871HV.js} +119 -81
  52. package/dist/assets/main-Chc871HV.js.map +1 -0
  53. package/dist/assets/{mainline-DY95WbuK.js → mainline-CDUXtV-I.js} +2 -2
  54. package/dist/assets/{mainline-DY95WbuK.js.map → mainline-CDUXtV-I.js.map} +1 -1
  55. package/dist/assets/{networkReason-Be-hMghr.js → networkReason-DYlPZS5M.js} +2 -2
  56. package/dist/assets/{networkReason-Be-hMghr.js.map → networkReason-DYlPZS5M.js.map} +1 -1
  57. package/dist/assets/{ownDid-BErplN7N.js → ownDid-BOuSlDv-.js} +10 -6
  58. package/dist/assets/ownDid-BOuSlDv-.js.map +1 -0
  59. package/dist/assets/{ownStatus-ClrFjd7h.js → ownStatus-CLA1VPkL.js} +6 -6
  60. package/dist/assets/{ownStatus-ClrFjd7h.js.map → ownStatus-CLA1VPkL.js.map} +1 -1
  61. package/dist/assets/{pairedTransports-BKmvlKz1.js → pairedTransports-DAzupLYo.js} +23 -17
  62. package/dist/assets/pairedTransports-DAzupLYo.js.map +1 -0
  63. package/dist/assets/{paymentIntent-DySU3Ajm.js → paymentIntent-Cr3uZa_0.js} +2 -2
  64. package/dist/assets/{paymentIntent-DySU3Ajm.js.map → paymentIntent-Cr3uZa_0.js.map} +1 -1
  65. package/dist/assets/{profiles-B8xO8-oj.js → profiles-BH1bH9aE.js} +3 -3
  66. package/dist/assets/{profiles-B8xO8-oj.js.map → profiles-BH1bH9aE.js.map} +1 -1
  67. package/dist/assets/{registry--Rg2YvOH.js → registry-DAq16T-V.js} +1 -1
  68. package/dist/assets/{registry-CU8PevhI.js → registry-DP_-RA-v.js} +11 -7
  69. package/dist/assets/registry-DP_-RA-v.js.map +1 -0
  70. package/dist/assets/{relay-CHWg5hpZ.js → relay-gJTOYQJZ.js} +93 -7
  71. package/dist/assets/relay-gJTOYQJZ.js.map +1 -0
  72. package/dist/assets/{resolve-B1upovPM.js → resolve-B1eQ4dVQ.js} +10 -5
  73. package/dist/assets/resolve-B1eQ4dVQ.js.map +1 -0
  74. package/dist/assets/secretGuard-Bh11MPdI.js +1 -0
  75. package/dist/assets/{secretGuard-BrATm_gl.js → secretGuard-oz_3hBfW.js} +19 -2
  76. package/dist/assets/{secretGuard-BrATm_gl.js.map → secretGuard-oz_3hBfW.js.map} +1 -1
  77. package/dist/assets/{server-Dgxx_DaN.js → server-Bd2ofxc1.js} +1283 -6628
  78. package/dist/assets/server-Bd2ofxc1.js.map +1 -0
  79. package/dist/assets/{sshForges-BnvwmNj-.js → sshForges-As7dbGXM.js} +2 -2
  80. package/dist/assets/{sshForges-BnvwmNj-.js.map → sshForges-As7dbGXM.js.map} +1 -1
  81. package/dist/assets/{translate-BcbSWkuq.js → translate-DnuQMfj0.js} +22 -11
  82. package/dist/assets/translate-DnuQMfj0.js.map +1 -0
  83. package/dist/assets/{usdt-CBJ4Q5Ji.js → usdt-DLmtf8F9.js} +4 -4
  84. package/dist/assets/{usdt-CBJ4Q5Ji.js.map → usdt-DLmtf8F9.js.map} +1 -1
  85. package/dist/assets/{waitNotice-ylU3XwjO.js → waitNotice-BHuMofaH.js} +57 -3
  86. package/dist/assets/waitNotice-BHuMofaH.js.map +1 -0
  87. package/dist/ghostly.mjs +1 -1
  88. package/npm-shrinkwrap.json +2 -2
  89. package/package.json +1 -1
  90. package/dist/assets/api-CVtg7MpI.js +0 -3
  91. package/dist/assets/api-CjOaoG-v.js.map +0 -1
  92. package/dist/assets/apps-Cuk45sz5.js.map +0 -1
  93. package/dist/assets/backup-DekVCDWv.js.map +0 -1
  94. package/dist/assets/buttons-BGxzOtrq.js.map +0 -1
  95. package/dist/assets/buttons-CsN2WJOf.js +0 -1
  96. package/dist/assets/engineErrors--9hfgKlK.js.map +0 -1
  97. package/dist/assets/errors-DDLFO4Gf.js.map +0 -1
  98. package/dist/assets/ghostly_iroh_web-DIj5xGmR.js.map +0 -1
  99. package/dist/assets/groupMeta-goASqzOt.js.map +0 -1
  100. package/dist/assets/host-C2WRKj3g.js.map +0 -1
  101. package/dist/assets/identityProofs-Cksc_K7_.js.map +0 -1
  102. package/dist/assets/irohWeb-NfthOL98.js.map +0 -1
  103. package/dist/assets/linkPreview-DdMf-YAc.js.map +0 -1
  104. package/dist/assets/main-Dh7fePd8.js.map +0 -1
  105. package/dist/assets/ownDid-BErplN7N.js.map +0 -1
  106. package/dist/assets/pairedTransports-BKmvlKz1.js.map +0 -1
  107. package/dist/assets/registry-CU8PevhI.js.map +0 -1
  108. package/dist/assets/relay-CHWg5hpZ.js.map +0 -1
  109. package/dist/assets/resolve-B1upovPM.js.map +0 -1
  110. package/dist/assets/secretGuard-Bm6nci0I.js +0 -1
  111. package/dist/assets/server-Dgxx_DaN.js.map +0 -1
  112. package/dist/assets/translate-BcbSWkuq.js.map +0 -1
  113. package/dist/assets/waitNotice-ylU3XwjO.js.map +0 -1
@@ -1,7 +1,7 @@
1
- import { u as groupName, x as INVITE_TAKEN } from "./groupMeta-goASqzOt.js";
1
+ import { u as groupName, x as INVITE_TAKEN } from "./groupMeta-CeZpqVVC.js";
2
2
  import { o as isZ32Key } from "./bytes-C1DNGY18.js";
3
3
  import { r as sanitizeDisplayText } from "./text-li76pThX.js";
4
- import { t as CliError } from "./errors-DDLFO4Gf.js";
4
+ import { t as CliError } from "./errors-JVJsO8Iu.js";
5
5
  // src/jsonOut.ts
6
6
  /**
7
7
  * What `JSON.stringify` leaves raw and a terminal may act on: DEL and the C1 controls (CSI, OSC, ST, NEL... in UTF-8),
@@ -434,14 +434,21 @@ var TRANSPORT_TITLES = {
434
434
  * app too, by its last word. `chat transport` took any: toward a contact with no WebRTC (`GHOSTLY_WEBRTC=0`) the choice
435
435
  * was kept and the chat stayed where it was, saying nothing; for one this app lacks, the engine answered `engine`,
436
436
  * "Transport unavailable". Refused instead, saying whose app lacks it (`details.reason`, as a chat's wait says it).
437
+ * This app's lack names the way out, as the contact's does: the transports both apps run, `auto`, and for an Iroh
438
+ * whose relays did not answer, where they are set. It read "This app has no Iroh running", with no next step.
437
439
  */
438
440
  function transportOffered(link, transport) {
439
441
  const mine = (link.deliveryMode === "dht" ? link.runnableTransports : void 0) ?? link.availableTransports;
440
442
  const title = TRANSPORT_TITLES[transport], error = link.transportErrors?.[transport];
441
- if (mine && !mine.includes(transport)) throw new CliError("refused", `This app has no ${title} running${error ? `: ${error}` : ""}`, {
442
- reason: "app-lacks",
443
- transport
444
- });
443
+ if (mine && !mine.includes(transport)) {
444
+ const both = mine.filter((t) => !link.peerTransports?.length || link.peerTransports.includes(t)).map((t) => t.split("/")[0]);
445
+ const choose = both.length ? `choose another (${both.join(", ")}), or auto` : "choose auto";
446
+ const relays = transport === "iroh/1" && error && /relay/i.test(error) ? `check its relays (${process.env.GHOSTLY_IROH_RELAYS?.trim() ? "GHOSTLY_IROH_RELAYS" : "irohRelays in ghostly settings get"}), or ` : "";
447
+ throw new CliError("refused", `This app has no ${title} running${error ? ` (${error})` : ""}: ${relays}${choose}`, {
448
+ reason: "app-lacks",
449
+ transport
450
+ });
451
+ }
445
452
  if (link.peerTransports?.length && !link.peerTransports.includes(transport)) throw new CliError("refused", `Your contact's app doesn't have ${title}: choose another, or auto`, {
446
453
  reason: "contact-lacks",
447
454
  transport
@@ -491,6 +498,31 @@ function groupOf(ctx, params, twin) {
491
498
  throw new CliError("not_found", `${JSON.stringify(ref)} is a chat, not a group${twin ? `: ghostly ${twin.replace("<chat>", shown)}` : " (ghostly group list)"}`, { chat: chat.id });
492
499
  }
493
500
  }
501
+ /** A group as a sentence names it: one joined by its link has no name until a member's app lets this profile in. */
502
+ var groupCalled = (group) => group.name || "this group";
503
+ /**
504
+ * A group this profile is not in yet (only its invitation, or a knock at its link), said with what the person can do,
505
+ * the same sentence for every command; undefined for any other group. `ref`: the group as the command named it.
506
+ * `decline`: the step out of it (`group leave`), not into it. An invitation its admin took back (left, forgot the group
507
+ * or handed the role on) has no way in: `group accept` answers "This invitation was taken back", so it names
508
+ * `group decline`, which drops it from the list.
509
+ */
510
+ function notInYet(group, ref, decline = false) {
511
+ if (group.status || !group.invitation) return void 0;
512
+ const shown = shellWord(ref, group.id);
513
+ const { accepted, viaLink, takenBack } = group.invitation;
514
+ if (takenBack && !decline) return `Its invitation to ${groupCalled(group)} was taken back: ghostly group decline ${shown} drops it`;
515
+ const why = decline ? `ghostly group decline ${shown} turns it down` : !accepted ? `ghostly group accept ${shown} joins it` : viaLink ? "you opened its link, and no member's app has let you in" : "you accepted its invitation, and its admin has not let you in";
516
+ return `You are not in ${groupCalled(group)} yet: ${why}`;
517
+ }
518
+ /**
519
+ * The engine's refusal of a group this profile is not in yet ("You are not in this group", "Group not found"), said as
520
+ * `notInYet` says it, with the same code; any other error as it is.
521
+ */
522
+ function notInYetError(group, ref, error, decline = false) {
523
+ const said = /^(You are not in this group( yet)?|Group not found)$/.test(error.message) ? notInYet(group, ref, decline) : void 0;
524
+ return said ? new CliError(error.code, said, error.details) : error;
525
+ }
494
526
  /**
495
527
  * The group whose id `id` is, built alone with its members' edges, as `byId` builds a chat: a group's own id names it
496
528
  * before anything else does (`findGroup`), and a bot names a group by the id its events give. Undefined for any other
@@ -544,6 +576,6 @@ function waitForState(ctx, check, ms, what, stopping) {
544
576
  else stopping?.addEventListener("abort", stopped, { once: true });
545
577
  });
546
578
  }
547
- export { sentAt as A, shellWord as B, nobodyJoined as C, oneOf as D, num as E, startNamedChats as F, state as I, str as L, shownName as M, sinceSeq as N, oneShotWaits as O, somebodyJoined as P, transportOffered as R, noMessage as S, node as T, jsonOut as V, list as _, contactKeyOf as a, namedByThem as b, findChatOrGroup as c, groupById as d, groupNameOf as f, keptForJoin as g, inviteTaken as h, cleanName as i, settingsOf as j, ownChatOf as k, findGroup as l, groupPrefixed as m, chatOf as n, dhtOnly as o, groupOf as p, chatOrGroup as r, findChat as s, bool as t, findOwnNamedChat as u, messageOf as v, nobodyJoinedChat as w, noFile as x, nameKey as y, waitForState as z };
579
+ export { oneOf as A, str as B, noMessage as C, notInYet as D, node as E, shownName as F, waitForState as H, sinceSeq as I, somebodyJoined as L, ownChatOf as M, sentAt as N, notInYetError as O, settingsOf as P, startNamedChats as R, noFile as S, nobodyJoinedChat as T, shellWord as U, transportOffered as V, jsonOut as W, keptForJoin as _, contactKeyOf as a, nameKey as b, findChatOrGroup as c, groupById as d, groupCalled as f, inviteTaken as g, groupPrefixed as h, cleanName as i, oneShotWaits as j, num as k, findGroup as l, groupOf as m, chatOf as n, dhtOnly as o, groupNameOf as p, chatOrGroup as r, findChat as s, bool as t, findOwnNamedChat as u, list as v, nobodyJoined as w, namedByThem as x, messageOf as y, state as z };
548
580
 
549
- //# sourceMappingURL=apiKit-BAGvlQtm.js.map
581
+ //# sourceMappingURL=apiKit-CPTFJHA7.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"apiKit-BAGvlQtm.js","names":[],"sources":["../../src/jsonOut.ts","../../src/shellWord.ts","../../src/apiKit.ts"],"sourcesContent":["/**\n * What `JSON.stringify` leaves raw and a terminal may act on: DEL and the C1 controls (CSI, OSC, ST, NEL... in UTF-8),\n * the line and paragraph separators, and the bidi marks, embeddings, overrides and isolates that reorder a line. Only\n * a string holds them, and a peer writes some of those strings (a message's text), so the CLI's output writes them as\n * `\\uXXXX`: the same JSON value for every reader, nothing a terminal acts on. What is stored stays whole.\n */\nconst RAW = /[\\u007f-\\u009f\\u061c\\u200e\\u200f\\u2028\\u2029\\u202a-\\u202e\\u2066-\\u2069]/g;\n\n/** `value` as the JSON the CLI prints: `JSON.stringify`, with `RAW` escaped. */\nexport function jsonOut(value: unknown, space?: number): string {\n return JSON.stringify(value, null, space)?.replace(RAW, (char) => \"\\\\u\" + char.charCodeAt(0).toString(16).padStart(4, \"0\"));\n}\n","import { jsonOut } from \"./jsonOut\";\n\n/**\n * A word as a hint offers it to be pasted into a shell: as it is when plain, else single-quoted. JSON's double quotes\n * are no shell quoting: `\"$5 lunch\"` pasted names ` lunch`, and a backtick in it runs a command. A leading `=` stays\n * quoted too (zsh expands `=word` to a command's path). Every \"<name> (2)\" a keep-both hint names has a `(` in it, a\n * syntax error in bash and zsh unquoted.\n *\n * The CLI prints every answer, an error too, as JSON, and a hint is pasted as the terminal shows it: a `'` quoted as\n * `'\\''` read `'\\\\''` there, which ended the quote, and the rest of the word ran as commands (a group's name is its\n * inviter's, a kept-both file's its sender's). A `\"` or a `\\` came out doubled the same way. No shell quoting survives\n * that, so such a word is not offered: `instead` is said, an id that names the same thing or where the details hold it.\n */\nexport function shellWord(word: string, instead: string): string {\n if (/^[\\w@%+:,./-][\\w@%+=:,./-]*$/.test(word)) return word;\n return word.includes(\"'\") || jsonOut(word) !== `\"${word}\"` ? instead : `'${word}'`;\n}\n","import { groupName, INVITE_TAKEN, isZ32Key, MAX_GROUP_NAME_BYTES, MAX_GROUP_NAME_LENGTH, sanitizeDisplayText, type PairedTransport } from \"@ghostly/core\";\nimport type { GhostlyNode } from \"@ghostly/browser/engine/node\";\nimport type { EngineState, GroupView, LinkView, Settings, StoredMessage } from \"@ghostly/browser/shared/types\";\nimport { CliError } from \"./errors\";\nimport { shellWord } from \"./shellWord\";\nimport type { CallManager } from \"./calls/manager\";\nimport type { EventHub } from \"./events\";\nimport type { GroupAutoJoin } from \"./groupAuto\";\nimport type { Runtime } from \"./runtime/engine\";\n\n/**\n * The methods of the local control API (WISP 1100): the daemon answers them over its socket, and a one-shot\n * command calls them in its own process. Parameters come from JSON: every one is checked here.\n */\nexport interface ApiContext {\n runtime: Runtime;\n hub: EventHub;\n /** Voice calls (WISP 1100 § Calls). */\n calls: CallManager;\n /** Group invitations accepted by themselves (`group auto`). */\n groupAuto: GroupAutoJoin;\n /** How the host runs: a daemon stays; a one-shot leaves when its command is done. */\n mode: \"daemon\" | \"one-shot\";\n version: string;\n /** The daemon asks to stop (answered first). */\n stop?: () => void;\n /**\n * Aborted when the daemon stops (`serve().close`): a wait still open answers with what it knows (`waits.ts`), as a\n * timeout with `details.reason: \"daemon-stopped\"`, before the connections end.\n */\n stopping?: AbortSignal;\n /** The daemon is a `listen` that found none and runs the profile itself: a stop ends that listen too. */\n listen?: true;\n}\n\nexport type Params = Record<string, unknown>;\n/** What a call knows of who asked it. */\nexport interface CallScope {\n /**\n * Aborted when the daemon's connection the call came on closes (Ctrl-C on the command, its process gone): nobody\n * reads the answer any more. A call that leaves something behind for its answer (`profile.backup`) stops on it.\n */\n gone?: AbortSignal;\n}\n\nexport type Method = (ctx: ApiContext, params: Params, call?: CallScope) => Promise<unknown>;\n\nexport const node = (ctx: ApiContext): GhostlyNode => ctx.runtime.server.node;\nexport const state = (ctx: ApiContext): EngineState => node(ctx).getState();\n/** The engine's settings, without building `state` (a view of every chat). */\nexport const settingsOf = (ctx: ApiContext): Settings => node(ctx).getSettings();\n\n/**\n * The time of a send the engine names its row after (`me_<timestamp>`: a file, a payment, a request), its own even\n * within one millisecond (a bot paying or sending several times at once over the socket, `file send` run in\n * parallel), or the chat keeps only one. One clock for all of them: they share the row names. A file's resend after a\n * drop finds its row by it, as a forward does.\n */\nlet lastSentAt = 0;\nexport const sentAt = () => (lastSentAt = Math.max(Date.now(), lastSentAt + 1));\n\n// ---------- parameters ----------\n\nexport function str(params: Params, name: string, required: true): string;\nexport function str(params: Params, name: string, required?: false): string | undefined;\nexport function str(params: Params, name: string, required = false): string | undefined {\n const value = params[name];\n if (value === undefined || value === null || value === \"\") {\n if (required) throw new CliError(\"bad_request\", `${name} is required`);\n return undefined;\n }\n if (typeof value !== \"string\") throw new CliError(\"bad_request\", `${name} must be a string`);\n return value;\n}\n/** A number in `[min, max]`; `whole` takes only whole ones (a count of messages), as the engine needs them. */\nexport function num(params: Params, name: string, fallback: number, { min = 0, max = Number.MAX_SAFE_INTEGER, whole = false } = {}): number {\n const value = params[name];\n if (value === undefined || value === null) return fallback;\n if (typeof value !== \"number\" || !Number.isFinite(value) || value < min || value > max) throw new CliError(\"bad_request\", `${name} must be a ${whole ? \"whole \" : \"\"}number from ${min} to ${max}`);\n if (whole && !Number.isSafeInteger(value)) throw new CliError(\"bad_request\", `${name} must be a whole number from ${min} to ${max}`);\n return value;\n}\n/**\n * The seq `events.replay` and `events.subscribe` start after: whole, from 0; `fallback` when left out. A cursor sent as\n * text (\"412\") was a stream from now on the socket with no error, and a negative one a gap of seqs that never were.\n */\nexport function sinceSeq(params: Params, fallback: number): number {\n return num(params, \"since\", fallback, { whole: true });\n}\nexport function bool(params: Params, name: string): boolean {\n const value = params[name];\n if (value === undefined || value === null) return false;\n if (typeof value !== \"boolean\") throw new CliError(\"bad_request\", `${name} must be true or false`);\n return value;\n}\nexport function list(params: Params, name: string): string[] {\n const value = params[name];\n if (value === undefined || value === null) return [];\n if (!Array.isArray(value) || value.some((item) => typeof item !== \"string\")) throw new CliError(\"bad_request\", `${name} must be a list of strings`);\n return value as string[];\n}\n/**\n * One of `values`; `fallback` when it was left out. Given empty (an unset variable in a script: `wallet remove \"\"`), it\n * is refused like any other wrong choice, never read as left out: that acted on the default (the Cashu wallet).\n */\nexport function oneOf<T extends string>(params: Params, name: string, values: readonly T[], fallback: T): T {\n const value = params[name] === \"\" ? \"\" : str(params, name) ?? fallback;\n if (!values.includes(value as T)) throw new CliError(\"bad_request\", `${name} must be one of ${values.join(\", \")}`);\n return value as T;\n}\n\n// ---------- finding things ----------\n\nconst KEY_SHAPED = /^[ybndrfg8ejkmcpqxot1uwisza345h769]{52}$/;\n/**\n * A chat's id as the engine makes it (the first 16 characters of a z-base-32 key) and the CLI prints it as `chat`. A ref\n * so shaped is only ever an id: tested on its `nameKey`, so that a case, a space or an invisible character more is too.\n */\nconst CHAT_ID_SHAPED = /^[ybndrfg8ejkmcpqxot1uwisza345h769]{16}$/;\n/**\n * A contact key as chats show it (`peer`): 52 characters of z-base-32, in its one canonical spelling. The same 52\n * characters with the last one respelled decode to the same bytes but are no key (WISP 02): refused here, so that\n * they never fall through to a chat's name, which its contact chooses.\n */\nexport const CONTACT_KEY = {\n test(ref: string): boolean {\n if (isZ32Key(ref)) return true;\n if (KEY_SHAPED.test(ref)) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} is not a contact key: a key has one spelling, and its last character is not this one`);\n return false;\n },\n};\n\n/**\n * The contact key `ref` is once read as a name is (`nameKey`: trimmed, invisible characters dropped, one case), or\n * undefined for a ref not shaped as one. A key a script or a paste left a line break, a space or capitals on is still\n * that key, and only ever names by key: never a chat, a group or a member by a name someone else chose. Every ref that\n * may be a key is read here, so no caller tests the raw string.\n */\nexport function contactKeyOf(ref: string): string | undefined {\n const key = nameKey(ref);\n return CONTACT_KEY.test(key) ? key : undefined;\n}\n\n/**\n * A chat's label, its contact's name or a group's name as a ref is compared with it: cleaned as the engine cleans a name\n * it stores (`renameLink`, `groupName`: any run of whitespace one space, invisible and direction-changing characters\n * dropped, trimmed), in one Unicode form (NFC) and one case. The string given to `chat rename` or `group create` finds\n * what it named, though what was stored is the cleaned one. Empty when nothing visible is left: that names nothing.\n */\nexport function nameKey(name: string | null | undefined): string {\n if (!name) return \"\";\n return (sanitizeDisplayText(name.replace(/\\s+/gu, \" \"), Infinity)?.replace(/ {2,}/g, \" \") ?? \"\").normalize(\"NFC\").toLowerCase();\n}\n\n/**\n * A name this side writes (a chat's label, the profile's name, a group's name) cleaned as the engine stores a name\n * (`renameLink`, `groupName`): any run of whitespace (a tab, a line break) one space, invisible and direction-changing\n * characters dropped, trimmed, in NFC: `nameKey` without the case. Counted after that, in code points as the engine\n * counts: undefined past `max`, \"\" when nothing visible is left. Every command that writes a name checks it here, so a\n * tab is a space and not a second line, and a name is never refused at a length it does not have once stored.\n */\nexport function cleanName(name: string, max: number): string | undefined {\n const clean = (sanitizeDisplayText(name.replace(/\\s+/gu, \" \"), Infinity)?.replace(/ {2,}/g, \" \") ?? \"\").normalize(\"NFC\");\n return [...clean].length > max ? undefined : clean;\n}\n\n/**\n * `name` as `cleanName` stores it, or the one refusal every name kind gives (`bad_request`), so a chat's, the profile's\n * and a group's name read alike. `subject` starts the sentence (\"A chat's name\", \"nick\"); `empty` follows \"needs a\n * character that shows\" (what an empty name does instead, when it does something). Too long says the count as stored,\n * in code points as the engine counts, and the largest character of several code points in it (a joined emoji or a\n * flag counts as several): the person sees what to cut, and a bot reads `details.length` and `details.max`.\n */\nexport function shownName(name: string, max: number, subject: string, empty = \"\"): string {\n const clean = cleanName(name, Infinity) ?? \"\";\n const length = [...clean].length;\n if (length > max) {\n const widest = [...new Intl.Segmenter(undefined, { granularity: \"grapheme\" }).segment(clean)]\n .map(({ segment }) => segment).reduce((a, b) => ([...b].length > [...a].length ? b : a), \"\");\n const several = [...widest].length > 1 ? `: ${widest} counts as ${[...widest].length}` : \"\";\n throw new CliError(\"bad_request\", `${subject} is up to ${max} characters as stored (this one is ${length}${several})`, { length, max });\n }\n if (!clean) throw new CliError(\"bad_request\", `${subject} needs a character that shows${empty}`);\n return clean;\n}\n\n/**\n * The `name` param of `group create` and `group rename`, refused as a chat's or the profile's name is (`shownName`),\n * then as the engine takes it (`groupName`: the same cleaning, 64 code points, 256 bytes; 64 code points never pass\n * 256 bytes, so its refusal is only a guard). Said here, before anything is made.\n */\nexport function groupNameOf(params: Params): string {\n const name = groupName(shownName(str(params, \"name\", true), MAX_GROUP_NAME_LENGTH, \"A group's name\"));\n if (!name) throw new CliError(\"bad_request\", `A group's name is up to ${MAX_GROUP_NAME_BYTES} bytes as stored`);\n return name;\n}\n\n/** Whether `name` is the one `key` (a ref's `nameKey`) names. */\nconst namedAs = (key: string, name: string | null | undefined) => key !== \"\" && nameKey(name) === key;\n\n/**\n * A chat by its id; by its contact's key (only by the key: a name is never taken for one); by the label this side gave\n * it; and only when no label matches, by a unique prefix of its id or the name the contact gave itself. The contact\n * controls both of those (a joiner's chat id is made from the inviter's code), so neither wins over a label, and a ref\n * that fits one chat's prefix and another's name is refused. A ref shaped as a chat's id is only ever an id, or a label\n * given here. `group:<ref>` is never a chat (a group, as everywhere). A ref\n * that names no chat but one of `groups` says it is a group (see `noChat`).\n */\nexport function findChat(links: readonly LinkView[], ref: string, groups: readonly GroupView[] = []): LinkView {\n return chatBy(links, ref, groups).link;\n}\n\n/**\n * No chat by `ref`. A group's id, prefix or name (or `group:<id>`) says it is a group, as `groupOf` says a chat is one:\n * `chat connect`, `identity share`, `call start` and the other commands that take only a 1:1 chat read `No chat \"Crew\"`,\n * as if nothing had that name.\n */\nfunction noChat(ref: string, groups: readonly GroupView[]): CliError {\n const group = groupNamed(ref, groups);\n if (group) return new CliError(\"not_found\", `${JSON.stringify(ref)} is a group, not a chat (ghostly chat list)`, { group: group.id });\n return new CliError(\"not_found\", `No chat ${JSON.stringify(ref)} (ghostly chat list)`);\n}\n\n/** A chat or group ref as a next step shows it: as given, quoted only when it holds more than a word (see `shellWord`). */\nconst shownRef = (place: RefPlace) => shellWord(place.ref, place.group ? \"<group>\" : \"<chat>\");\n\n/** The chat or the group a message or a file was looked for in, as the command was given it (`ref`). */\nexport type RefPlace = { group: boolean; ref: string };\n\n/**\n * No message by `id` in a chat or a group, said one way by every command that takes one, as `noChat` says a chat: the id\n * quoted as given, and where the ids are. `whose` (\"of yours\", \"from someone else\") is what it had to be; `tail` what\n * else it may have failed for (\", or it takes no reaction\", \": only your own messages are sent again\").\n */\nexport function noMessage(id: string, place: RefPlace, { whose, tail }: { whose?: string; tail?: string } = {}): CliError {\n const history = `ghostly ${place.group ? \"group\" : \"chat\"} history ${shownRef(place)}`;\n return new CliError(\"not_found\", `No message ${JSON.stringify(id)}${whose ? ` ${whose}` : \"\"} in this ${place.group ? \"group\" : \"chat\"}${tail ?? \"\"} (${history})`);\n}\n\n/** No file by `id`, as `noMessage` says a message: in the chat or group named (`place`), or in none when none was. */\nexport function noFile(id: string, place?: RefPlace): CliError {\n const where = place ? ` in this ${place.group ? \"group\" : \"chat\"}` : \"\";\n return new CliError(\"not_found\", `No file ${JSON.stringify(id)}${where} (ghostly file list ${place ? shownRef(place) : \"<chat|group>\"})`);\n}\n\n/** The one group `ref` names, if any (none, or more than one: undefined). */\nfunction groupNamed(ref: string, groups: readonly GroupView[]): GroupView | undefined {\n try { return findGroup(groups, ref); } catch { return undefined; }\n}\n\n/** `findChat`, and whether only what the contact controls (`theirName`: a prefix of the id, its own name) found the chat. */\nfunction chatBy(links: readonly LinkView[], ref: string, groups: readonly GroupView[] = []): { link: LinkView; theirName: boolean } {\n // \"\" (an unset variable in a script) is a prefix of every id: it took the only chat.\n if (!ref.trim()) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} names no chat`);\n const exact = links.find((link) => link.id === ref);\n if (exact) return { link: exact, theirName: false };\n const contact = contactKeyOf(ref);\n if (contact !== undefined) {\n const byKey = links.filter((link) => link.peerPubKeyZ32 === contact);\n if (byKey.length === 1) return { link: byKey[0], theirName: false };\n if (byKey.length > 1) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} names more than one chat: use its id`, { matches: byKey.map((link) => link.id) });\n throw new CliError(\"not_found\", `No chat with ${JSON.stringify(ref)} (ghostly chat list)`);\n }\n const key = nameKey(ref);\n const named = (name: string | null | undefined) => namedAs(key, name);\n const byLabel = links.filter((link) => named(link.label));\n // `group:<ref>` names a group (`groupPrefixed`), never a chat: not by a name its contact chose, nor by a label given\n // here (a chat labelled `group:Crew` was that chat for `chat show` and the group Crew for `send`). A chat labelled so\n // before labels were refused (`chatName`) is named by its id.\n if (groupPrefixed(ref) !== null) {\n if (byLabel.length && !groupNamed(ref, groups)) throw new CliError(\"not_found\", `${JSON.stringify(ref)} names a group, never a chat: name the chat labelled so by its id, and give it another name (ghostly chat rename <chat> <name>)`, { matches: byLabel.map((link) => link.id) });\n throw noChat(ref, groups);\n }\n // A chat's id no chat has (one removed since: a bot kept it from an event) is no chat. Its contact and whoever saw its\n // invite know it, so another contact could call itself that and take every later command sent by it. A label given\n // here still names the chat: only this side chooses it.\n if (!byLabel.length && CHAT_ID_SHAPED.test(key)) throw noChat(ref, groups);\n const found = byLabel.length ? byLabel : [...new Set([...links.filter((link) => link.id.startsWith(ref)), ...links.filter((link) => named(link.peerNick))])];\n if (found.length === 1) return { link: found[0], theirName: !byLabel.length };\n if (found.length > 1) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} names more than one chat: use its id`, { matches: found.map((link) => link.id) });\n throw noChat(ref, groups);\n}\n\n/**\n * `findChat` for a grant the daemon keeps acting on (`call auto on --from`): only the chat's id, its contact's key or the\n * label this side gave it name the chat. A prefix of its id or the name its contact gave itself is refused, with the\n * chat it found: the contact chose those, so another contact could take the grant by calling itself that name.\n */\nexport function findOwnNamedChat(links: readonly LinkView[], ref: string, groups: readonly GroupView[] = []): LinkView {\n const chat = chatBy(links, ref, groups);\n if (chat.theirName) throw namedByThem(ref, { chat: chat.link.id, name: chat.link.peerNick ?? null, contact: chat.link.peerPubKeyZ32 });\n return chat.link;\n}\n\n/** `findOwnNamedChat`'s refusal: `ref` found `chat` only by what its contact chose. */\nexport function namedByThem(ref: string, chat: { chat: string; name: string | null; contact: string | undefined }): CliError {\n return new CliError(\"bad_request\", `${JSON.stringify(ref)} names a chat only by what its contact chose (a prefix of its id, its own name): use the chat's id, its contact's key or a label given here (ghostly chat rename <chat> <name>)`, chat);\n}\n\n/**\n * `group:<ref>`, the form that names a group wherever a group is taken (docs/CLI.md § What it does): `<ref>`, read as any\n * other ref (`findGroup`: an id, a prefix of it or a name). Null for a ref without it. `findGroup` and `findChatOrGroup`\n * both read the prefix here, so a group command and a command that takes a chat or a group never read it apart.\n */\nexport const groupPrefixed = (ref: string): string | null => (ref.startsWith(\"group:\") ? ref.slice(\"group:\".length) : null);\n\n/** Only an invitation so far: this profile is not in the group (yet), and whoever invited chose its name. */\nconst invitedOnly = (group: GroupView) => group.status === undefined && !!group.invitation;\n\n/**\n * A group by its id, by its name, or by a unique prefix of its id. Whoever created a group chose its id and its admin\n * chooses its name, so neither wins over the other: a ref that is one group's name and another's prefix is refused,\n * with both ids, as `chatBy` does for chats. A group this profile is in wins over an invitation with the same name or\n * prefix (the one who invites chooses those); an invitation is still found by its id, and by name or prefix where no\n * group of this profile has it. `group:<ref>` is `<ref>` (`groupPrefixed`); before, only the commands that take a chat\n * or a group read it, and every group command and `listen --group` answered it `No group`.\n */\nexport function findGroup(groups: readonly GroupView[], given: string): GroupView {\n const ref = groupPrefixed(given) ?? given;\n // Each refusal echoes the ref as given (`\"group:k86q\"`), not the part after `group:`: what the person typed.\n if (!ref.trim()) throw new CliError(\"bad_request\", `${JSON.stringify(given)} names no group`);\n const exact = groups.find((group) => group.id === ref);\n if (exact) return exact;\n const key = nameKey(ref);\n for (const among of [groups.filter((group) => !invitedOnly(group)), groups.filter(invitedOnly)]) {\n const found = among.filter((group) => namedAs(key, group.name) || group.id.startsWith(ref));\n if (found.length === 1) return found[0];\n if (found.length > 1) throw new CliError(\"bad_request\", `${JSON.stringify(given)} names more than one group: use its id`, { matches: found.map((group) => group.id) });\n }\n throw new CliError(\"not_found\", `No group ${JSON.stringify(given)} (ghostly group list)`);\n}\n\n/**\n * A chat or a group, where a command takes either: `group:<id>` is a group; anything else a chat first (`findChat`),\n * then a group. A chat found only by what its contact chose (a prefix of its id, its own name) never takes what also\n * names a group: a group's\n * own id is that group, and a prefix or the name of a group this profile is in is refused, with both ids. With neither,\n * one `not_found` names both and where to look (a contact's key: no chat with it); a name that matches more than one\n * chat or group stays that error.\n */\nexport function findChatOrGroup(links: readonly LinkView[], groups: readonly GroupView[], ref: string): { link: LinkView } | { group: GroupView } {\n if (groupPrefixed(ref) !== null) return { group: findGroup(groups, ref) };\n let chat: ReturnType<typeof chatBy>;\n try {\n chat = chatBy(links, ref);\n } catch (error) {\n if (!(error instanceof CliError) || error.code !== \"not_found\") throw error;\n // Nor is it a group's name or a prefix of a group's id (its admin and its creator chose those; a group's own id is\n // longer), nor is a contact's key with no chat: `group:<ref>` names a group.\n if (CHAT_ID_SHAPED.test(nameKey(ref)) || contactKeyOf(ref) !== undefined) throw error;\n try { return { group: findGroup(groups, ref) }; } catch (inner) {\n if (!(inner instanceof CliError) || inner.code !== \"not_found\") throw inner;\n throw new CliError(\"not_found\", `No chat or group ${JSON.stringify(ref)} (ghostly chat list, ghostly group list)`);\n }\n }\n if (!chat.theirName) return { link: chat.link };\n const exact = groups.find((group) => group.id === ref);\n if (exact) return { group: exact };\n const key = nameKey(ref);\n const also = groups.filter((group) => !invitedOnly(group) && (group.id.startsWith(ref) || namedAs(key, group.name)));\n if (also.length) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} names a chat (by what its contact chose) and a group: use the chat's id or group:<id>`, { chat: chat.link.id, groups: also.map((group) => group.id) });\n return { link: chat.link };\n}\n\n/**\n * Starts the chats and groups a call names (its `chat`, a forward's `to`, its `group`) in a runtime that left the saved\n * chats and the groups' edges unstarted (`RuntimeOptions.deferChats`). A ref that names nothing starts nothing: the\n * call says so itself.\n */\nexport async function startNamedChats(ctx: ApiContext, params: Params): Promise<void> {\n const { links, groups } = state(ctx);\n for (const ref of [params.chat, ...(Array.isArray(params.to) ? params.to : [])]) {\n if (typeof ref !== \"string\") continue;\n let found: ReturnType<typeof findChatOrGroup>;\n try { found = findChatOrGroup(links, groups, ref); } catch { continue; }\n if (\"link\" in found) await node(ctx).startDeferredChat(found.link.id);\n else node(ctx).startDeferredGroup(found.group.id);\n }\n if (typeof params.group === \"string\") {\n try { node(ctx).startDeferredGroup(findGroup(groups, params.group).id); } catch { /* the call says so itself */ }\n }\n}\n\n/**\n * The chat a call names. `s`: a state the call built already. Each build is a view of every chat (about 15-20 µs a\n * chat, on the daemon's one thread): one lookup builds one, never one per list it reads.\n */\nexport function chatOf(ctx: ApiContext, params: Params, s?: EngineState): LinkView {\n const ref = str(params, \"chat\", true);\n if (!s) { const chat = byId(ctx, ref); if (chat) return chat; }\n const { links, groups } = s ?? state(ctx);\n return findChat(links, ref, groups);\n}\n/** `findOwnNamedChat` for the chat a call names, as `chatOf`. */\nexport function ownChatOf(ctx: ApiContext, params: Params, s?: EngineState): LinkView {\n const ref = str(params, \"chat\", true);\n if (!s) { const chat = byId(ctx, ref); if (chat) return chat; }\n const { links, groups } = s ?? state(ctx);\n return findOwnNamedChat(links, ref, groups);\n}\n/**\n * The chat whose id `ref` is, built alone: a chat's own id names it before anything else does (`chatBy`), and a bot\n * names its chats by the ids its events give. Undefined for any other ref, which the whole list is read for.\n */\nconst byId = (ctx: ApiContext, ref: string): LinkView | undefined => node(ctx).chatView(ref);\n\n/** A chat of mine whose invite nobody took yet: no contact's key, so nothing goes out until they join. */\nexport const nobodyJoined = (link: LinkView): boolean => !!(link.profile && link.inviteCode && !link.peerParticipationKey);\n\n/**\n * `nobodyJoined` by the chat's id: a group's (`group:<id>`) is never one. That chat's view alone: every card send or\n * update, `file send` and unconfirmed edit asks it, and built every chat for it (once in a daemon, up to three times\n * in a one-shot `usage send`).\n */\nexport const nobodyJoinedChat = (ctx: ApiContext, chat: string): boolean => {\n const link = byId(ctx, chat);\n return !!link && nobodyJoined(link);\n};\n\n/**\n * Whether a one-shot waits by default on what it did in a 1:1 chat: it leaves with its process, so it stays until that\n * went out or the contact confirmed it. Not on a chat nobody joined yet: there is no one to wait for, and `edit`, `react`,\n * `pin`, a card or a file sat their whole wait (a file 300 s), then failed `timeout`, exit 4, which a bot retries: one\n * more card or file each time. What was done is kept and goes once they join; the answer says so (`keptForJoin`).\n */\nexport const oneShotWaits = (ctx: ApiContext, chat: string): boolean => ctx.mode === \"one-shot\" && !nobodyJoinedChat(ctx, chat);\n\n/** An answer's `note` on a chat nobody joined yet: `what` is kept and goes once they join. Nothing on any other chat. */\nexport const keptForJoin = (ctx: ApiContext, chat: string, what: string): { note?: string } => nobodyJoinedChat(ctx, chat)\n ? { note: `Nobody joined this chat yet: ${what} goes once they join${ctx.mode === \"one-shot\" ? \" while this profile is online (`ghostly daemon --detach`)\" : \"\"}` }\n : {};\n\n/**\n * A chat whose invite nobody took yet has no session to close either: `chat disconnect` answered done with the chat at\n * `connecting`, and `--hold` put the waiting invite on DHT only (a one-shot answered `pairing: error`).\n */\nexport function somebodyJoined(link: LinkView): void {\n if (nobodyJoined(link)) throw new CliError(\"unavailable\", \"Nobody joined this chat yet: its invite is still waiting to be taken\");\n}\n\n/**\n * A chat whose invite nobody took yet: nobody is there to pay or to dial, and its stage says so. Before, `chat pay`\n * waited 15 s and `chat connect` 25 s for the contact, then answered `engine`. A chat whose invite someone else used\n * first is refused too, with the sentence `send` gives: its contact seals everything to them (`connect` waited 120 s,\n * then answered `timeout`, a code a bot retries).\n */\nexport function inviteTaken(link: LinkView): void {\n somebodyJoined(link);\n if (link.dhtDelivery?.inviteTaken && link.textDelivery !== \"stream\") throw new CliError(\"refused\", INVITE_TAKEN);\n}\n\n/**\n * A chat on DHT only opens no live session: the engine refused `chat connect` as `engine`, \"Both peers must choose a\n * live method first\", which read as if this side had to change something. Refused instead, naming whose choice it is\n * (`details.reason`): the contact's (`peer-dht-only`, nothing to do here but wait), or this side's (`dht-only`).\n */\nexport function dhtOnly(link: LinkView): void {\n if (link.deliveryMode === \"dht\") throw new CliError(\"refused\", \"This chat is on DHT only on this side: choose a live method first (chat transport auto)\", { reason: \"dht-only\" });\n if (link.dhtDelivery?.peerMode === \"dht\") throw new CliError(\"refused\", \"Your contact keeps this chat on DHT only: it goes live once they choose a live method. Short texts still go on the DHT\", { reason: \"peer-dht-only\" });\n}\n\nconst TRANSPORT_TITLES: Record<PairedTransport, string> = { \"webrtc/1\": \"WebRTC\", \"iroh/1\": \"Iroh\", \"hyperdht/1\": \"HyperDHT\" };\n\n/**\n * A transport the chat's Connection menu offers: one this app runs (on DHT only, one it can start), and the contact's\n * app too, by its last word. `chat transport` took any: toward a contact with no WebRTC (`GHOSTLY_WEBRTC=0`) the choice\n * was kept and the chat stayed where it was, saying nothing; for one this app lacks, the engine answered `engine`,\n * \"Transport unavailable\". Refused instead, saying whose app lacks it (`details.reason`, as a chat's wait says it).\n */\nexport function transportOffered(link: LinkView, transport: PairedTransport): void {\n const mine = (link.deliveryMode === \"dht\" ? link.runnableTransports : undefined) ?? link.availableTransports;\n const title = TRANSPORT_TITLES[transport], error = link.transportErrors?.[transport];\n if (mine && !mine.includes(transport)) throw new CliError(\"refused\", `This app has no ${title} running${error ? `: ${error}` : \"\"}`, { reason: \"app-lacks\", transport });\n if (link.peerTransports?.length && !link.peerTransports.includes(transport)) throw new CliError(\"refused\", `Your contact's app doesn't have ${title}: choose another, or auto`, { reason: \"contact-lacks\", transport });\n}\n\n/** A chat or a group as `findChatOrGroup` reads it. `linkId` is what the engine calls it. `s`: as for `chatOf`. */\nexport function chatOrGroup(ctx: ApiContext, ref: string, s?: EngineState): { id: string; linkId: string; group: boolean } {\n const chat = s ? undefined : byId(ctx, ref);\n if (chat) return { id: chat.id, linkId: chat.id, group: false };\n const { links, groups } = s ?? state(ctx);\n const found = findChatOrGroup(links, groups, ref);\n return \"group\" in found ? { id: found.group.id, linkId: `group:${found.group.id}`, group: true } : { id: found.link.id, linkId: found.link.id, group: false };\n}\n\n/**\n * The group a group command names. A chat's id, key or name says it is a chat, with `twin`, the chat command that takes\n * it (`group send` on a chat, where `send` is meant; `<chat>` stands for the ref), else where the groups are listed.\n * It read \"No group\" before. A name nothing has stays that error.\n */\nexport function groupOf(ctx: ApiContext, params: Params, twin?: string): GroupView {\n const ref = str(params, \"group\", true);\n const byId = groupById(ctx, groupPrefixed(ref) ?? ref);\n if (byId) return byId;\n const { links, groups } = state(ctx);\n try { return findGroup(groups, ref); } catch (error) {\n // `group:<ref>` names a group only: never a chat, as in `findChatOrGroup`.\n if (!(error instanceof CliError) || error.code !== \"not_found\" || groupPrefixed(ref) !== null) throw error;\n let chat: LinkView;\n try { chat = findChat(links, ref); } catch { throw error; }\n const shown = shellWord(ref, chat.id);\n throw new CliError(\"not_found\", `${JSON.stringify(ref)} is a chat, not a group${twin ? `: ghostly ${twin.replace(\"<chat>\", shown)}` : \" (ghostly group list)\"}`, { chat: chat.id });\n }\n}\n\n/**\n * The group whose id `id` is, built alone with its members' edges, as `byId` builds a chat: a group's own id names it\n * before anything else does (`findGroup`), and a bot names a group by the id its events give. Undefined for any other\n * ref, which the whole list is read for.\n */\nexport const groupById = (ctx: ApiContext, id: string): GroupView | undefined => node(ctx).groupView(id);\n\n/**\n * A message of a chat or a group (`group:<id>`) named by its id here, read as one row; only a name that is no such\n * row's key (the id both sides know, `wireId`) reads the whole history. `keep`: only a message it accepts (mine, or\n * someone else's). The history is synchronous work on the daemon's one thread, about 120 ms at 10,000 messages.\n */\nexport async function messageOf(ctx: ApiContext, linkId: string, ref: string, keep: (message: StoredMessage) => boolean = () => true): Promise<StoredMessage | undefined> {\n const found = await node(ctx).getMessage(linkId, ref);\n if (found && keep(found)) return found;\n const all = linkId.startsWith(\"group:\") ? await node(ctx).groupMessages({ groupId: linkId.slice(\"group:\".length) }) : await node(ctx).getMessages(linkId);\n return all.find((m) => keep(m) && m.wireId === ref);\n}\n\n// ---------- waiting ----------\n\n/**\n * Resolves with `check`'s first defined answer: now, or on a later state; `timeout` error after `ms`. A check that\n * throws on a later state (`chat wait`'s chat removed) ends the wait with its error: the hub swallows what its\n * listeners throw, and the wait went on to its timeout.\n *\n * `stopping` (a daemon's `ctx.stopping`): the daemon's stop ends it too, as a timeout with `details.reason:\n * \"daemon-stopped\"`, for a wait whose command did something (`file send --wait`) and answers with what it knows. A\n * wait that changes nothing is left to its connection's end, and its client asks it again (main.ts `READ_WAITS`).\n */\nexport function waitForState<T>(ctx: ApiContext, check: (state: EngineState) => T | undefined, ms: number, what: string, stopping?: AbortSignal): Promise<T> {\n const now = check(state(ctx));\n if (now !== undefined) return Promise.resolve(now);\n return new Promise<T>((resolve, reject) => {\n const end = (error: unknown) => { clearTimeout(timer); off(); stopping?.removeEventListener(\"abort\", stopped); if (error) reject(error); };\n const stopped = () => end(new CliError(\"timeout\", `The daemon stopped before the wait ended, waiting for ${what}`, { reason: \"daemon-stopped\" }));\n const timer = setTimeout(() => end(new CliError(\"timeout\", `Timed out after ${Math.round(ms / 1000)} s waiting for ${what}`)), ms);\n const off = ctx.hub.onState((next) => {\n let value: T | undefined;\n try { value = check(next); } catch (error) { end(error); return; }\n if (value === undefined) return;\n end(null);\n resolve(value);\n });\n if (stopping?.aborted) stopped();\n else stopping?.addEventListener(\"abort\", stopped, { once: true });\n });\n}\n\n"],"mappings":";;;;;;;;;;;AAMA,IAAM,MAAM;;AAGZ,SAAgB,QAAQ,OAAgB,OAAwB;CAC9D,OAAO,KAAK,UAAU,OAAO,MAAM,KAAK,CAAC,EAAE,QAAQ,MAAM,SAAS,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC;AAC5H;;;;;;;;;;;;;ACEA,SAAgB,UAAU,MAAc,SAAyB;CAC/D,IAAI,+BAA+B,KAAK,IAAI,GAAG,OAAO;CACtD,OAAO,KAAK,SAAS,GAAG,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,KAAK,UAAU,IAAI,KAAK;AAClF;;AC+BA,IAAa,QAAQ,QAAiC,IAAI,QAAQ,OAAO;AACzE,IAAa,SAAS,QAAiC,KAAK,GAAG,CAAC,CAAC,SAAS;;AAE1E,IAAa,cAAc,QAA8B,KAAK,GAAG,CAAC,CAAC,YAAY;;;;;;;AAQ/E,IAAI,aAAa;AACjB,IAAa,eAAgB,aAAa,KAAK,IAAI,KAAK,IAAI,GAAG,aAAa,CAAC;AAM7E,SAAgB,IAAI,QAAgB,MAAc,WAAW,OAA2B;CACtF,MAAM,QAAQ,OAAO;CACrB,IAAI,UAAU,KAAA,KAAa,UAAU,QAAQ,UAAU,IAAI;EACzD,IAAI,UAAU,MAAM,I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src/apiKit.ts"],"sourcesContent":["/**\n * What `JSON.stringify` leaves raw and a terminal may act on: DEL and the C1 controls (CSI, OSC, ST, NEL... in UTF-8),\n * the line and paragraph separators, and the bidi marks, embeddings, overrides and isolates that reorder a line. Only\n * a string holds them, and a peer writes some of those strings (a message's text), so the CLI's output writes them as\n * `\\uXXXX`: the same JSON value for every reader, nothing a terminal acts on. What is stored stays whole.\n */\nconst RAW = /[\\u007f-\\u009f\\u061c\\u200e\\u200f\\u2028\\u2029\\u202a-\\u202e\\u2066-\\u2069]/g;\n\n/** `value` as the JSON the CLI prints: `JSON.stringify`, with `RAW` escaped. */\nexport function jsonOut(value: unknown, space?: number): string {\n return JSON.stringify(value, null, space)?.replace(RAW, (char) => \"\\\\u\" + char.charCodeAt(0).toString(16).padStart(4, \"0\"));\n}\n","import { jsonOut } from \"./jsonOut\";\n\n/**\n * A word as a hint offers it to be pasted into a shell: as it is when plain, else single-quoted. JSON's double quotes\n * are no shell quoting: `\"$5 lunch\"` pasted names ` lunch`, and a backtick in it runs a command. A leading `=` stays\n * quoted too (zsh expands `=word` to a command's path). Every \"<name> (2)\" a keep-both hint names has a `(` in it, a\n * syntax error in bash and zsh unquoted.\n *\n * The CLI prints every answer, an error too, as JSON, and a hint is pasted as the terminal shows it: a `'` quoted as\n * `'\\''` read `'\\\\''` there, which ended the quote, and the rest of the word ran as commands (a group's name is its\n * inviter's, a kept-both file's its sender's). A `\"` or a `\\` came out doubled the same way. No shell quoting survives\n * that, so such a word is not offered: `instead` is said, an id that names the same thing or where the details hold it.\n */\nexport function shellWord(word: string, instead: string): string {\n if (/^[\\w@%+:,./-][\\w@%+=:,./-]*$/.test(word)) return word;\n return word.includes(\"'\") || jsonOut(word) !== `\"${word}\"` ? instead : `'${word}'`;\n}\n","import { groupName, INVITE_TAKEN, isZ32Key, MAX_GROUP_NAME_BYTES, MAX_GROUP_NAME_LENGTH, sanitizeDisplayText, type PairedTransport } from \"@ghostly/core\";\nimport type { GhostlyNode } from \"@ghostly/browser/engine/node\";\nimport type { EngineState, GroupView, LinkView, Settings, StoredMessage } from \"@ghostly/browser/shared/types\";\nimport { CliError } from \"./errors\";\nimport { shellWord } from \"./shellWord\";\nimport type { CallManager } from \"./calls/manager\";\nimport type { EventHub } from \"./events\";\nimport type { GroupAutoJoin } from \"./groupAuto\";\nimport type { Runtime } from \"./runtime/engine\";\n\n/**\n * The methods of the local control API (WISP 1100): the daemon answers them over its socket, and a one-shot\n * command calls them in its own process. Parameters come from JSON: every one is checked here.\n */\nexport interface ApiContext {\n runtime: Runtime;\n hub: EventHub;\n /** Voice calls (WISP 1100 § Calls). */\n calls: CallManager;\n /** Group invitations accepted by themselves (`group auto`). */\n groupAuto: GroupAutoJoin;\n /** How the host runs: a daemon stays; a one-shot leaves when its command is done. */\n mode: \"daemon\" | \"one-shot\";\n version: string;\n /** The daemon asks to stop (answered first). */\n stop?: () => void;\n /**\n * Aborted when the daemon stops (`serve().close`): a wait still open answers with what it knows (`waits.ts`), as a\n * timeout with `details.reason: \"daemon-stopped\"`, before the connections end.\n */\n stopping?: AbortSignal;\n /** The daemon is a `listen` that found none and runs the profile itself: a stop ends that listen too. */\n listen?: true;\n}\n\nexport type Params = Record<string, unknown>;\n/** What a call knows of who asked it. */\nexport interface CallScope {\n /**\n * Aborted when the daemon's connection the call came on closes (Ctrl-C on the command, its process gone): nobody\n * reads the answer any more. A call that leaves something behind for its answer (`profile.backup`) stops on it.\n */\n gone?: AbortSignal;\n}\n\nexport type Method = (ctx: ApiContext, params: Params, call?: CallScope) => Promise<unknown>;\n\nexport const node = (ctx: ApiContext): GhostlyNode => ctx.runtime.server.node;\nexport const state = (ctx: ApiContext): EngineState => node(ctx).getState();\n/** The engine's settings, without building `state` (a view of every chat). */\nexport const settingsOf = (ctx: ApiContext): Settings => node(ctx).getSettings();\n\n/**\n * The time of a send the engine names its row after (`me_<timestamp>`: a file, a payment, a request), its own even\n * within one millisecond (a bot paying or sending several times at once over the socket, `file send` run in\n * parallel), or the chat keeps only one. One clock for all of them: they share the row names. A file's resend after a\n * drop finds its row by it, as a forward does.\n */\nlet lastSentAt = 0;\nexport const sentAt = () => (lastSentAt = Math.max(Date.now(), lastSentAt + 1));\n\n// ---------- parameters ----------\n\nexport function str(params: Params, name: string, required: true): string;\nexport function str(params: Params, name: string, required?: false): string | undefined;\nexport function str(params: Params, name: string, required = false): string | undefined {\n const value = params[name];\n if (value === undefined || value === null || value === \"\") {\n if (required) throw new CliError(\"bad_request\", `${name} is required`);\n return undefined;\n }\n if (typeof value !== \"string\") throw new CliError(\"bad_request\", `${name} must be a string`);\n return value;\n}\n/** A number in `[min, max]`; `whole` takes only whole ones (a count of messages), as the engine needs them. */\nexport function num(params: Params, name: string, fallback: number, { min = 0, max = Number.MAX_SAFE_INTEGER, whole = false } = {}): number {\n const value = params[name];\n if (value === undefined || value === null) return fallback;\n if (typeof value !== \"number\" || !Number.isFinite(value) || value < min || value > max) throw new CliError(\"bad_request\", `${name} must be a ${whole ? \"whole \" : \"\"}number from ${min} to ${max}`);\n if (whole && !Number.isSafeInteger(value)) throw new CliError(\"bad_request\", `${name} must be a whole number from ${min} to ${max}`);\n return value;\n}\n/**\n * The seq `events.replay` and `events.subscribe` start after: whole, from 0; `fallback` when left out. A cursor sent as\n * text (\"412\") was a stream from now on the socket with no error, and a negative one a gap of seqs that never were.\n */\nexport function sinceSeq(params: Params, fallback: number): number {\n return num(params, \"since\", fallback, { whole: true });\n}\nexport function bool(params: Params, name: string): boolean {\n const value = params[name];\n if (value === undefined || value === null) return false;\n if (typeof value !== \"boolean\") throw new CliError(\"bad_request\", `${name} must be true or false`);\n return value;\n}\nexport function list(params: Params, name: string): string[] {\n const value = params[name];\n if (value === undefined || value === null) return [];\n if (!Array.isArray(value) || value.some((item) => typeof item !== \"string\")) throw new CliError(\"bad_request\", `${name} must be a list of strings`);\n return value as string[];\n}\n/**\n * One of `values`; `fallback` when it was left out. Given empty (an unset variable in a script: `wallet remove \"\"`), it\n * is refused like any other wrong choice, never read as left out: that acted on the default (the Cashu wallet).\n */\nexport function oneOf<T extends string>(params: Params, name: string, values: readonly T[], fallback: T): T {\n const value = params[name] === \"\" ? \"\" : str(params, name) ?? fallback;\n if (!values.includes(value as T)) throw new CliError(\"bad_request\", `${name} must be one of ${values.join(\", \")}`);\n return value as T;\n}\n\n// ---------- finding things ----------\n\nconst KEY_SHAPED = /^[ybndrfg8ejkmcpqxot1uwisza345h769]{52}$/;\n/**\n * A chat's id as the engine makes it (the first 16 characters of a z-base-32 key) and the CLI prints it as `chat`. A ref\n * so shaped is only ever an id: tested on its `nameKey`, so that a case, a space or an invisible character more is too.\n */\nconst CHAT_ID_SHAPED = /^[ybndrfg8ejkmcpqxot1uwisza345h769]{16}$/;\n/**\n * A contact key as chats show it (`peer`): 52 characters of z-base-32, in its one canonical spelling. The same 52\n * characters with the last one respelled decode to the same bytes but are no key (WISP 02): refused here, so that\n * they never fall through to a chat's name, which its contact chooses.\n */\nexport const CONTACT_KEY = {\n test(ref: string): boolean {\n if (isZ32Key(ref)) return true;\n if (KEY_SHAPED.test(ref)) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} is not a contact key: a key has one spelling, and its last character is not this one`);\n return false;\n },\n};\n\n/**\n * The contact key `ref` is once read as a name is (`nameKey`: trimmed, invisible characters dropped, one case), or\n * undefined for a ref not shaped as one. A key a script or a paste left a line break, a space or capitals on is still\n * that key, and only ever names by key: never a chat, a group or a member by a name someone else chose. Every ref that\n * may be a key is read here, so no caller tests the raw string.\n */\nexport function contactKeyOf(ref: string): string | undefined {\n const key = nameKey(ref);\n return CONTACT_KEY.test(key) ? key : undefined;\n}\n\n/**\n * A chat's label, its contact's name or a group's name as a ref is compared with it: cleaned as the engine cleans a name\n * it stores (`renameLink`, `groupName`: any run of whitespace one space, invisible and direction-changing characters\n * dropped, trimmed), in one Unicode form (NFC) and one case. The string given to `chat rename` or `group create` finds\n * what it named, though what was stored is the cleaned one. Empty when nothing visible is left: that names nothing.\n */\nexport function nameKey(name: string | null | undefined): string {\n if (!name) return \"\";\n return (sanitizeDisplayText(name.replace(/\\s+/gu, \" \"), Infinity)?.replace(/ {2,}/g, \" \") ?? \"\").normalize(\"NFC\").toLowerCase();\n}\n\n/**\n * A name this side writes (a chat's label, the profile's name, a group's name) cleaned as the engine stores a name\n * (`renameLink`, `groupName`): any run of whitespace (a tab, a line break) one space, invisible and direction-changing\n * characters dropped, trimmed, in NFC: `nameKey` without the case. Counted after that, in code points as the engine\n * counts: undefined past `max`, \"\" when nothing visible is left. Every command that writes a name checks it here, so a\n * tab is a space and not a second line, and a name is never refused at a length it does not have once stored.\n */\nexport function cleanName(name: string, max: number): string | undefined {\n const clean = (sanitizeDisplayText(name.replace(/\\s+/gu, \" \"), Infinity)?.replace(/ {2,}/g, \" \") ?? \"\").normalize(\"NFC\");\n return [...clean].length > max ? undefined : clean;\n}\n\n/**\n * `name` as `cleanName` stores it, or the one refusal every name kind gives (`bad_request`), so a chat's, the profile's\n * and a group's name read alike. `subject` starts the sentence (\"A chat's name\", \"nick\"); `empty` follows \"needs a\n * character that shows\" (what an empty name does instead, when it does something). Too long says the count as stored,\n * in code points as the engine counts, and the largest character of several code points in it (a joined emoji or a\n * flag counts as several): the person sees what to cut, and a bot reads `details.length` and `details.max`.\n */\nexport function shownName(name: string, max: number, subject: string, empty = \"\"): string {\n const clean = cleanName(name, Infinity) ?? \"\";\n const length = [...clean].length;\n if (length > max) {\n const widest = [...new Intl.Segmenter(undefined, { granularity: \"grapheme\" }).segment(clean)]\n .map(({ segment }) => segment).reduce((a, b) => ([...b].length > [...a].length ? b : a), \"\");\n const several = [...widest].length > 1 ? `: ${widest} counts as ${[...widest].length}` : \"\";\n throw new CliError(\"bad_request\", `${subject} is up to ${max} characters as stored (this one is ${length}${several})`, { length, max });\n }\n if (!clean) throw new CliError(\"bad_request\", `${subject} needs a character that shows${empty}`);\n return clean;\n}\n\n/**\n * The `name` param of `group create` and `group rename`, refused as a chat's or the profile's name is (`shownName`),\n * then as the engine takes it (`groupName`: the same cleaning, 64 code points, 256 bytes; 64 code points never pass\n * 256 bytes, so its refusal is only a guard). Said here, before anything is made.\n */\nexport function groupNameOf(params: Params): string {\n const name = groupName(shownName(str(params, \"name\", true), MAX_GROUP_NAME_LENGTH, \"A group's name\"));\n if (!name) throw new CliError(\"bad_request\", `A group's name is up to ${MAX_GROUP_NAME_BYTES} bytes as stored`);\n return name;\n}\n\n/** Whether `name` is the one `key` (a ref's `nameKey`) names. */\nconst namedAs = (key: string, name: string | null | undefined) => key !== \"\" && nameKey(name) === key;\n\n/**\n * A chat by its id; by its contact's key (only by the key: a name is never taken for one); by the label this side gave\n * it; and only when no label matches, by a unique prefix of its id or the name the contact gave itself. The contact\n * controls both of those (a joiner's chat id is made from the inviter's code), so neither wins over a label, and a ref\n * that fits one chat's prefix and another's name is refused. A ref shaped as a chat's id is only ever an id, or a label\n * given here. `group:<ref>` is never a chat (a group, as everywhere). A ref\n * that names no chat but one of `groups` says it is a group (see `noChat`).\n */\nexport function findChat(links: readonly LinkView[], ref: string, groups: readonly GroupView[] = []): LinkView {\n return chatBy(links, ref, groups).link;\n}\n\n/**\n * No chat by `ref`. A group's id, prefix or name (or `group:<id>`) says it is a group, as `groupOf` says a chat is one:\n * `chat connect`, `identity share`, `call start` and the other commands that take only a 1:1 chat read `No chat \"Crew\"`,\n * as if nothing had that name.\n */\nfunction noChat(ref: string, groups: readonly GroupView[]): CliError {\n const group = groupNamed(ref, groups);\n if (group) return new CliError(\"not_found\", `${JSON.stringify(ref)} is a group, not a chat (ghostly chat list)`, { group: group.id });\n return new CliError(\"not_found\", `No chat ${JSON.stringify(ref)} (ghostly chat list)`);\n}\n\n/** A chat or group ref as a next step shows it: as given, quoted only when it holds more than a word (see `shellWord`). */\nconst shownRef = (place: RefPlace) => shellWord(place.ref, place.group ? \"<group>\" : \"<chat>\");\n\n/** The chat or the group a message or a file was looked for in, as the command was given it (`ref`). */\nexport type RefPlace = { group: boolean; ref: string };\n\n/**\n * No message by `id` in a chat or a group, said one way by every command that takes one, as `noChat` says a chat: the id\n * quoted as given, and where the ids are. `whose` (\"of yours\", \"from someone else\") is what it had to be; `tail` what\n * else it may have failed for (\", or it takes no reaction\", \": only your own messages are sent again\").\n */\nexport function noMessage(id: string, place: RefPlace, { whose, tail }: { whose?: string; tail?: string } = {}): CliError {\n const history = `ghostly ${place.group ? \"group\" : \"chat\"} history ${shownRef(place)}`;\n return new CliError(\"not_found\", `No message ${JSON.stringify(id)}${whose ? ` ${whose}` : \"\"} in this ${place.group ? \"group\" : \"chat\"}${tail ?? \"\"} (${history})`);\n}\n\n/** No file by `id`, as `noMessage` says a message: in the chat or group named (`place`), or in none when none was. */\nexport function noFile(id: string, place?: RefPlace): CliError {\n const where = place ? ` in this ${place.group ? \"group\" : \"chat\"}` : \"\";\n return new CliError(\"not_found\", `No file ${JSON.stringify(id)}${where} (ghostly file list ${place ? shownRef(place) : \"<chat|group>\"})`);\n}\n\n/** The one group `ref` names, if any (none, or more than one: undefined). */\nfunction groupNamed(ref: string, groups: readonly GroupView[]): GroupView | undefined {\n try { return findGroup(groups, ref); } catch { return undefined; }\n}\n\n/** `findChat`, and whether only what the contact controls (`theirName`: a prefix of the id, its own name) found the chat. */\nfunction chatBy(links: readonly LinkView[], ref: string, groups: readonly GroupView[] = []): { link: LinkView; theirName: boolean } {\n // \"\" (an unset variable in a script) is a prefix of every id: it took the only chat.\n if (!ref.trim()) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} names no chat`);\n const exact = links.find((link) => link.id === ref);\n if (exact) return { link: exact, theirName: false };\n const contact = contactKeyOf(ref);\n if (contact !== undefined) {\n const byKey = links.filter((link) => link.peerPubKeyZ32 === contact);\n if (byKey.length === 1) return { link: byKey[0], theirName: false };\n if (byKey.length > 1) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} names more than one chat: use its id`, { matches: byKey.map((link) => link.id) });\n throw new CliError(\"not_found\", `No chat with ${JSON.stringify(ref)} (ghostly chat list)`);\n }\n const key = nameKey(ref);\n const named = (name: string | null | undefined) => namedAs(key, name);\n const byLabel = links.filter((link) => named(link.label));\n // `group:<ref>` names a group (`groupPrefixed`), never a chat: not by a name its contact chose, nor by a label given\n // here (a chat labelled `group:Crew` was that chat for `chat show` and the group Crew for `send`). A chat labelled so\n // before labels were refused (`chatName`) is named by its id.\n if (groupPrefixed(ref) !== null) {\n if (byLabel.length && !groupNamed(ref, groups)) throw new CliError(\"not_found\", `${JSON.stringify(ref)} names a group, never a chat: name the chat labelled so by its id, and give it another name (ghostly chat rename <chat> <name>)`, { matches: byLabel.map((link) => link.id) });\n throw noChat(ref, groups);\n }\n // A chat's id no chat has (one removed since: a bot kept it from an event) is no chat. Its contact and whoever saw its\n // invite know it, so another contact could call itself that and take every later command sent by it. A label given\n // here still names the chat: only this side chooses it.\n if (!byLabel.length && CHAT_ID_SHAPED.test(key)) throw noChat(ref, groups);\n const found = byLabel.length ? byLabel : [...new Set([...links.filter((link) => link.id.startsWith(ref)), ...links.filter((link) => named(link.peerNick))])];\n if (found.length === 1) return { link: found[0], theirName: !byLabel.length };\n if (found.length > 1) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} names more than one chat: use its id`, { matches: found.map((link) => link.id) });\n throw noChat(ref, groups);\n}\n\n/**\n * `findChat` for a grant the daemon keeps acting on (`call auto on --from`): only the chat's id, its contact's key or the\n * label this side gave it name the chat. A prefix of its id or the name its contact gave itself is refused, with the\n * chat it found: the contact chose those, so another contact could take the grant by calling itself that name.\n */\nexport function findOwnNamedChat(links: readonly LinkView[], ref: string, groups: readonly GroupView[] = []): LinkView {\n const chat = chatBy(links, ref, groups);\n if (chat.theirName) throw namedByThem(ref, { chat: chat.link.id, name: chat.link.peerNick ?? null, contact: chat.link.peerPubKeyZ32 });\n return chat.link;\n}\n\n/** `findOwnNamedChat`'s refusal: `ref` found `chat` only by what its contact chose. */\nexport function namedByThem(ref: string, chat: { chat: string; name: string | null; contact: string | undefined }): CliError {\n return new CliError(\"bad_request\", `${JSON.stringify(ref)} names a chat only by what its contact chose (a prefix of its id, its own name): use the chat's id, its contact's key or a label given here (ghostly chat rename <chat> <name>)`, chat);\n}\n\n/**\n * `group:<ref>`, the form that names a group wherever a group is taken (docs/CLI.md § What it does): `<ref>`, read as any\n * other ref (`findGroup`: an id, a prefix of it or a name). Null for a ref without it. `findGroup` and `findChatOrGroup`\n * both read the prefix here, so a group command and a command that takes a chat or a group never read it apart.\n */\nexport const groupPrefixed = (ref: string): string | null => (ref.startsWith(\"group:\") ? ref.slice(\"group:\".length) : null);\n\n/** Only an invitation so far: this profile is not in the group (yet), and whoever invited chose its name. */\nconst invitedOnly = (group: GroupView) => group.status === undefined && !!group.invitation;\n\n/**\n * A group by its id, by its name, or by a unique prefix of its id. Whoever created a group chose its id and its admin\n * chooses its name, so neither wins over the other: a ref that is one group's name and another's prefix is refused,\n * with both ids, as `chatBy` does for chats. A group this profile is in wins over an invitation with the same name or\n * prefix (the one who invites chooses those); an invitation is still found by its id, and by name or prefix where no\n * group of this profile has it. `group:<ref>` is `<ref>` (`groupPrefixed`); before, only the commands that take a chat\n * or a group read it, and every group command and `listen --group` answered it `No group`.\n */\nexport function findGroup(groups: readonly GroupView[], given: string): GroupView {\n const ref = groupPrefixed(given) ?? given;\n // Each refusal echoes the ref as given (`\"group:k86q\"`), not the part after `group:`: what the person typed.\n if (!ref.trim()) throw new CliError(\"bad_request\", `${JSON.stringify(given)} names no group`);\n const exact = groups.find((group) => group.id === ref);\n if (exact) return exact;\n const key = nameKey(ref);\n for (const among of [groups.filter((group) => !invitedOnly(group)), groups.filter(invitedOnly)]) {\n const found = among.filter((group) => namedAs(key, group.name) || group.id.startsWith(ref));\n if (found.length === 1) return found[0];\n if (found.length > 1) throw new CliError(\"bad_request\", `${JSON.stringify(given)} names more than one group: use its id`, { matches: found.map((group) => group.id) });\n }\n throw new CliError(\"not_found\", `No group ${JSON.stringify(given)} (ghostly group list)`);\n}\n\n/**\n * A chat or a group, where a command takes either: `group:<id>` is a group; anything else a chat first (`findChat`),\n * then a group. A chat found only by what its contact chose (a prefix of its id, its own name) never takes what also\n * names a group: a group's\n * own id is that group, and a prefix or the name of a group this profile is in is refused, with both ids. With neither,\n * one `not_found` names both and where to look (a contact's key: no chat with it); a name that matches more than one\n * chat or group stays that error.\n */\nexport function findChatOrGroup(links: readonly LinkView[], groups: readonly GroupView[], ref: string): { link: LinkView } | { group: GroupView } {\n if (groupPrefixed(ref) !== null) return { group: findGroup(groups, ref) };\n let chat: ReturnType<typeof chatBy>;\n try {\n chat = chatBy(links, ref);\n } catch (error) {\n if (!(error instanceof CliError) || error.code !== \"not_found\") throw error;\n // Nor is it a group's name or a prefix of a group's id (its admin and its creator chose those; a group's own id is\n // longer), nor is a contact's key with no chat: `group:<ref>` names a group.\n if (CHAT_ID_SHAPED.test(nameKey(ref)) || contactKeyOf(ref) !== undefined) throw error;\n try { return { group: findGroup(groups, ref) }; } catch (inner) {\n if (!(inner instanceof CliError) || inner.code !== \"not_found\") throw inner;\n throw new CliError(\"not_found\", `No chat or group ${JSON.stringify(ref)} (ghostly chat list, ghostly group list)`);\n }\n }\n if (!chat.theirName) return { link: chat.link };\n const exact = groups.find((group) => group.id === ref);\n if (exact) return { group: exact };\n const key = nameKey(ref);\n const also = groups.filter((group) => !invitedOnly(group) && (group.id.startsWith(ref) || namedAs(key, group.name)));\n if (also.length) throw new CliError(\"bad_request\", `${JSON.stringify(ref)} names a chat (by what its contact chose) and a group: use the chat's id or group:<id>`, { chat: chat.link.id, groups: also.map((group) => group.id) });\n return { link: chat.link };\n}\n\n/**\n * Starts the chats and groups a call names (its `chat`, a forward's `to`, its `group`) in a runtime that left the saved\n * chats and the groups' edges unstarted (`RuntimeOptions.deferChats`). A ref that names nothing starts nothing: the\n * call says so itself.\n */\nexport async function startNamedChats(ctx: ApiContext, params: Params): Promise<void> {\n const { links, groups } = state(ctx);\n for (const ref of [params.chat, ...(Array.isArray(params.to) ? params.to : [])]) {\n if (typeof ref !== \"string\") continue;\n let found: ReturnType<typeof findChatOrGroup>;\n try { found = findChatOrGroup(links, groups, ref); } catch { continue; }\n if (\"link\" in found) await node(ctx).startDeferredChat(found.link.id);\n else node(ctx).startDeferredGroup(found.group.id);\n }\n if (typeof params.group === \"string\") {\n try { node(ctx).startDeferredGroup(findGroup(groups, params.group).id); } catch { /* the call says so itself */ }\n }\n}\n\n/**\n * The chat a call names. `s`: a state the call built already. Each build is a view of every chat (about 15-20 µs a\n * chat, on the daemon's one thread): one lookup builds one, never one per list it reads.\n */\nexport function chatOf(ctx: ApiContext, params: Params, s?: EngineState): LinkView {\n const ref = str(params, \"chat\", true);\n if (!s) { const chat = byId(ctx, ref); if (chat) return chat; }\n const { links, groups } = s ?? state(ctx);\n return findChat(links, ref, groups);\n}\n/** `findOwnNamedChat` for the chat a call names, as `chatOf`. */\nexport function ownChatOf(ctx: ApiContext, params: Params, s?: EngineState): LinkView {\n const ref = str(params, \"chat\", true);\n if (!s) { const chat = byId(ctx, ref); if (chat) return chat; }\n const { links, groups } = s ?? state(ctx);\n return findOwnNamedChat(links, ref, groups);\n}\n/**\n * The chat whose id `ref` is, built alone: a chat's own id names it before anything else does (`chatBy`), and a bot\n * names its chats by the ids its events give. Undefined for any other ref, which the whole list is read for.\n */\nconst byId = (ctx: ApiContext, ref: string): LinkView | undefined => node(ctx).chatView(ref);\n\n/** A chat of mine whose invite nobody took yet: no contact's key, so nothing goes out until they join. */\nexport const nobodyJoined = (link: LinkView): boolean => !!(link.profile && link.inviteCode && !link.peerParticipationKey);\n\n/**\n * `nobodyJoined` by the chat's id: a group's (`group:<id>`) is never one. That chat's view alone: every card send or\n * update, `file send` and unconfirmed edit asks it, and built every chat for it (once in a daemon, up to three times\n * in a one-shot `usage send`).\n */\nexport const nobodyJoinedChat = (ctx: ApiContext, chat: string): boolean => {\n const link = byId(ctx, chat);\n return !!link && nobodyJoined(link);\n};\n\n/**\n * Whether a one-shot waits by default on what it did in a 1:1 chat: it leaves with its process, so it stays until that\n * went out or the contact confirmed it. Not on a chat nobody joined yet: there is no one to wait for, and `edit`, `react`,\n * `pin`, a card or a file sat their whole wait (a file 300 s), then failed `timeout`, exit 4, which a bot retries: one\n * more card or file each time. What was done is kept and goes once they join; the answer says so (`keptForJoin`).\n */\nexport const oneShotWaits = (ctx: ApiContext, chat: string): boolean => ctx.mode === \"one-shot\" && !nobodyJoinedChat(ctx, chat);\n\n/** An answer's `note` on a chat nobody joined yet: `what` is kept and goes once they join. Nothing on any other chat. */\nexport const keptForJoin = (ctx: ApiContext, chat: string, what: string): { note?: string } => nobodyJoinedChat(ctx, chat)\n ? { note: `Nobody joined this chat yet: ${what} goes once they join${ctx.mode === \"one-shot\" ? \" while this profile is online (`ghostly daemon --detach`)\" : \"\"}` }\n : {};\n\n/**\n * A chat whose invite nobody took yet has no session to close either: `chat disconnect` answered done with the chat at\n * `connecting`, and `--hold` put the waiting invite on DHT only (a one-shot answered `pairing: error`).\n */\nexport function somebodyJoined(link: LinkView): void {\n if (nobodyJoined(link)) throw new CliError(\"unavailable\", \"Nobody joined this chat yet: its invite is still waiting to be taken\");\n}\n\n/**\n * A chat whose invite nobody took yet: nobody is there to pay or to dial, and its stage says so. Before, `chat pay`\n * waited 15 s and `chat connect` 25 s for the contact, then answered `engine`. A chat whose invite someone else used\n * first is refused too, with the sentence `send` gives: its contact seals everything to them (`connect` waited 120 s,\n * then answered `timeout`, a code a bot retries).\n */\nexport function inviteTaken(link: LinkView): void {\n somebodyJoined(link);\n if (link.dhtDelivery?.inviteTaken && link.textDelivery !== \"stream\") throw new CliError(\"refused\", INVITE_TAKEN);\n}\n\n/**\n * A chat on DHT only opens no live session: the engine refused `chat connect` as `engine`, \"Both peers must choose a\n * live method first\", which read as if this side had to change something. Refused instead, naming whose choice it is\n * (`details.reason`): the contact's (`peer-dht-only`, nothing to do here but wait), or this side's (`dht-only`).\n */\nexport function dhtOnly(link: LinkView): void {\n if (link.deliveryMode === \"dht\") throw new CliError(\"refused\", \"This chat is on DHT only on this side: choose a live method first (chat transport auto)\", { reason: \"dht-only\" });\n if (link.dhtDelivery?.peerMode === \"dht\") throw new CliError(\"refused\", \"Your contact keeps this chat on DHT only: it goes live once they choose a live method. Short texts still go on the DHT\", { reason: \"peer-dht-only\" });\n}\n\nconst TRANSPORT_TITLES: Record<PairedTransport, string> = { \"webrtc/1\": \"WebRTC\", \"iroh/1\": \"Iroh\", \"hyperdht/1\": \"HyperDHT\" };\n\n/**\n * A transport the chat's Connection menu offers: one this app runs (on DHT only, one it can start), and the contact's\n * app too, by its last word. `chat transport` took any: toward a contact with no WebRTC (`GHOSTLY_WEBRTC=0`) the choice\n * was kept and the chat stayed where it was, saying nothing; for one this app lacks, the engine answered `engine`,\n * \"Transport unavailable\". Refused instead, saying whose app lacks it (`details.reason`, as a chat's wait says it).\n * This app's lack names the way out, as the contact's does: the transports both apps run, `auto`, and for an Iroh\n * whose relays did not answer, where they are set. It read \"This app has no Iroh running\", with no next step.\n */\nexport function transportOffered(link: LinkView, transport: PairedTransport): void {\n const mine = (link.deliveryMode === \"dht\" ? link.runnableTransports : undefined) ?? link.availableTransports;\n const title = TRANSPORT_TITLES[transport], error = link.transportErrors?.[transport];\n if (mine && !mine.includes(transport)) {\n const both = mine.filter((t) => !link.peerTransports?.length || link.peerTransports.includes(t)).map((t) => t.split(\"/\")[0]);\n const choose = both.length ? `choose another (${both.join(\", \")}), or auto` : \"choose auto\";\n // `GHOSTLY_IROH_RELAYS` pins the relays of this process: the setting is not read then (runtime/engine.ts `irohRelays`).\n const relays = transport === \"iroh/1\" && error && /relay/i.test(error)\n ? `check its relays (${process.env.GHOSTLY_IROH_RELAYS?.trim() ? \"GHOSTLY_IROH_RELAYS\" : \"irohRelays in ghostly settings get\"}), or ` : \"\";\n throw new CliError(\"refused\", `This app has no ${title} running${error ? ` (${error})` : \"\"}: ${relays}${choose}`, { reason: \"app-lacks\", transport });\n }\n if (link.peerTransports?.length && !link.peerTransports.includes(transport)) throw new CliError(\"refused\", `Your contact's app doesn't have ${title}: choose another, or auto`, { reason: \"contact-lacks\", transport });\n}\n\n/** A chat or a group as `findChatOrGroup` reads it. `linkId` is what the engine calls it. `s`: as for `chatOf`. */\nexport function chatOrGroup(ctx: ApiContext, ref: string, s?: EngineState): { id: string; linkId: string; group: boolean } {\n const chat = s ? undefined : byId(ctx, ref);\n if (chat) return { id: chat.id, linkId: chat.id, group: false };\n const { links, groups } = s ?? state(ctx);\n const found = findChatOrGroup(links, groups, ref);\n return \"group\" in found ? { id: found.group.id, linkId: `group:${found.group.id}`, group: true } : { id: found.link.id, linkId: found.link.id, group: false };\n}\n\n/**\n * The group a group command names. A chat's id, key or name says it is a chat, with `twin`, the chat command that takes\n * it (`group send` on a chat, where `send` is meant; `<chat>` stands for the ref), else where the groups are listed.\n * It read \"No group\" before. A name nothing has stays that error.\n */\nexport function groupOf(ctx: ApiContext, params: Params, twin?: string): GroupView {\n const ref = str(params, \"group\", true);\n const byId = groupById(ctx, groupPrefixed(ref) ?? ref);\n if (byId) return byId;\n const { links, groups } = state(ctx);\n try { return findGroup(groups, ref); } catch (error) {\n // `group:<ref>` names a group only: never a chat, as in `findChatOrGroup`.\n if (!(error instanceof CliError) || error.code !== \"not_found\" || groupPrefixed(ref) !== null) throw error;\n let chat: LinkView;\n try { chat = findChat(links, ref); } catch { throw error; }\n const shown = shellWord(ref, chat.id);\n throw new CliError(\"not_found\", `${JSON.stringify(ref)} is a chat, not a group${twin ? `: ghostly ${twin.replace(\"<chat>\", shown)}` : \" (ghostly group list)\"}`, { chat: chat.id });\n }\n}\n\n/** A group as a sentence names it: one joined by its link has no name until a member's app lets this profile in. */\nexport const groupCalled = (group: GroupView) => group.name || \"this group\";\n\n/**\n * A group this profile is not in yet (only its invitation, or a knock at its link), said with what the person can do,\n * the same sentence for every command; undefined for any other group. `ref`: the group as the command named it.\n * `decline`: the step out of it (`group leave`), not into it. An invitation its admin took back (left, forgot the group\n * or handed the role on) has no way in: `group accept` answers \"This invitation was taken back\", so it names\n * `group decline`, which drops it from the list.\n */\nexport function notInYet(group: GroupView, ref: string, decline = false): string | undefined {\n if (group.status || !group.invitation) return undefined;\n const shown = shellWord(ref, group.id);\n const { accepted, viaLink, takenBack } = group.invitation;\n if (takenBack && !decline) return `Its invitation to ${groupCalled(group)} was taken back: ghostly group decline ${shown} drops it`;\n const why = decline ? `ghostly group decline ${shown} turns it down`\n : !accepted ? `ghostly group accept ${shown} joins it`\n : viaLink ? \"you opened its link, and no member's app has let you in\"\n : \"you accepted its invitation, and its admin has not let you in\";\n return `You are not in ${groupCalled(group)} yet: ${why}`;\n}\n\n/**\n * The engine's refusal of a group this profile is not in yet (\"You are not in this group\", \"Group not found\"), said as\n * `notInYet` says it, with the same code; any other error as it is.\n */\nexport function notInYetError(group: GroupView, ref: string, error: CliError, decline = false): CliError {\n const said = /^(You are not in this group( yet)?|Group not found)$/.test(error.message) ? notInYet(group, ref, decline) : undefined;\n return said ? new CliError(error.code, said, error.details) : error;\n}\n\n/**\n * The group whose id `id` is, built alone with its members' edges, as `byId` builds a chat: a group's own id names it\n * before anything else does (`findGroup`), and a bot names a group by the id its events give. Undefined for any other\n * ref, which the whole list is read for.\n */\nexport const groupById = (ctx: ApiContext, id: string): GroupView | undefined => node(ctx).groupView(id);\n\n/**\n * A message of a chat or a group (`group:<id>`) named by its id here, read as one row; only a name that is no such\n * row's key (the id both sides know, `wireId`) reads the whole history. `keep`: only a message it accepts (mine, or\n * someone else's). The history is synchronous work on the daemon's one thread, about 120 ms at 10,000 messages.\n */\nexport async function messageOf(ctx: ApiContext, linkId: string, ref: string, keep: (message: StoredMessage) => boolean = () => true): Promise<StoredMessage | undefined> {\n const found = await node(ctx).getMessage(linkId, ref);\n if (found && keep(found)) return found;\n const all = linkId.startsWith(\"group:\") ? await node(ctx).groupMessages({ groupId: linkId.slice(\"group:\".length) }) : await node(ctx).getMessages(linkId);\n return all.find((m) => keep(m) && m.wireId === ref);\n}\n\n// ---------- waiting ----------\n\n/**\n * Resolves with `check`'s first defined answer: now, or on a later state; `timeout` error after `ms`. A check that\n * throws on a later state (`chat wait`'s chat removed) ends the wait with its error: the hub swallows what its\n * listeners throw, and the wait went on to its timeout.\n *\n * `stopping` (a daemon's `ctx.stopping`): the daemon's stop ends it too, as a timeout with `details.reason:\n * \"daemon-stopped\"`, for a wait whose command did something (`file send --wait`) and answers with what it knows. A\n * wait that changes nothing is left to its connection's end, and its client asks it again (main.ts `READ_WAITS`).\n */\nexport function waitForState<T>(ctx: ApiContext, check: (state: EngineState) => T | undefined, ms: number, what: string, stopping?: AbortSignal): Promise<T> {\n const now = check(state(ctx));\n if (now !== undefined) return Promise.resolve(now);\n return new Promise<T>((resolve, reject) => {\n const end = (error: unknown) => { clearTimeout(timer); off(); stopping?.removeEventListener(\"abort\", stopped); if (error) reject(error); };\n const stopped = () => end(new CliError(\"timeout\", `The daemon stopped before the wait ended, waiting for ${what}`, { reason: \"daemon-stopped\" }));\n const timer = setTimeout(() => end(new CliError(\"timeout\", `Timed out after ${Math.round(ms / 1000)} s waiting for ${what}`)), ms);\n const off = ctx.hub.onState((next) => {\n let value: T | undefined;\n try { value = check(next); } catch (error) { end(error); return; }\n if (value === undefined) return;\n end(null);\n resolve(value);\n });\n if (stopping?.aborted) stopped();\n else stopping?.addEventListener(\"abort\", stopped, { once: true });\n });\n}\n\n"],"mappings":";;;;;;;;;;;AAMA,IAAM,MAAM;;AAGZ,SAAgB,QAAQ,OAAgB,OAAwB;CAC9D,OAAO,KAAK,UAAU,OAAO,MAAM,KAAK,CAAC,EAAE,QAAQ,MAAM,SAAS,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC;AAC5H;;;;;;;;;;;;;ACEA,SAAgB,UAAU,MAAc,SAAyB;CAC/D,IAAI,+BAA+B,KAAK,IAAI,GAAG,OAAO;CACtD,OAAO,KAAK,SAAS,GAAG,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,KAAK,UAAU,IAAI,KAAK;AAClF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AA,GAAW;GACzB,IAAI,IAAI;GACR,QAAQ,KAAK;EACf,CAAC;EACD,IAAI,UAAU,SAAS,QAAQ;OAC1B,UAAU,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;CAClE,CAAC;AACH"}
@@ -1,6 +1,6 @@
1
1
  import { l as toBase64Url, u as toZ32 } from "./bytes-C1DNGY18.js";
2
2
  import { x as sign } from "./pkarr-BQo4PcCg.js";
3
- import { Ca as isAppUrl, Fa as isAppKey, Ga as verifyAppRevocation, Ia as isAppLine, Ka as verifyAppSignature, La as isAppRef, Ma as appRefPublisher, Oa as APP_PREFIXES, Pa as isAppHash, Qa as readCanonicalJson, Sa as findAppForbiddenKey, Ua as signAppObject, Va as readAppSignature, Za as canonicalJsonBytes, za as readAppRevocationShape } from "./groupMeta-goASqzOt.js";
3
+ import { Ba as isAppLine, Ea as isAppUrl, Fa as appRefPublisher, Ga as readAppSignature, Ra as isAppHash, Ta as findAppForbiddenKey, Ua as readAppRevocationShape, Va as isAppRef, Xa as verifyAppSignature, Ya as verifyAppRevocation, ja as APP_PREFIXES, no as readCanonicalJson, qa as signAppObject, to as canonicalJsonBytes, za as isAppKey } from "./groupMeta-CeZpqVVC.js";
4
4
  import { ed25519 } from "@noble/curves/ed25519.js";
5
5
  import { sha256 } from "@noble/hashes/sha2.js";
6
6
  // ../core/src/signer.ts
@@ -599,4 +599,4 @@ function besideUrl(url, name) {
599
599
  }
600
600
  export { webCryptoSigner as S, readAppStore as _, besideUrl as a, signAppStore as b, isGitHubPage as c, appStoreDecision as d, appUpdateDecision as f, checkAppStoreIndex as g, APP_STORE_LIMITS as h, appPasteUrl as i, addedAppPermissions as l, planAppUpdate as m, APP_FETCH_LIMITS as n, boundedAppFetch as o, checkAppBeforeRun as p, AppFetchError as r, isAppFetchUrl as s, APP_FETCH_HOSTS as t, appRevocationFor as u, readAppStoreSteps as v, seedSigner as x, repeatedJsonKey as y };
601
601
 
602
- //# sourceMappingURL=appFetch-BwJd-kNq.js.map
602
+ //# sourceMappingURL=appFetch-Ca9DNQQ2.js.map