@ghostlytools/cli 1.13.1 → 1.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -12
- package/dist/assets/api-DO0YMLiB.js +3 -0
- package/dist/assets/{api-Dnq86JAA.js → api-Dz2cw7WD.js} +512 -103
- package/dist/assets/api-Dz2cw7WD.js.map +1 -0
- package/dist/assets/{apiKit-nLK4jeTq.js → apiKit-DAFsWtyk.js} +53 -7
- package/dist/assets/apiKit-DAFsWtyk.js.map +1 -0
- package/dist/assets/{appFetch-wqBWi3Ry.js → appFetch-BQO5Pk7W.js} +2 -2
- package/dist/assets/{appFetch-wqBWi3Ry.js.map → appFetch-BQO5Pk7W.js.map} +1 -1
- package/dist/assets/{apps-DBVhKpfe.js → apps-B88rYWRm.js} +51 -23
- package/dist/assets/apps-B88rYWRm.js.map +1 -0
- package/dist/assets/{apps-nLtyhC2f.js → apps-D4KRpZB4.js} +1 -1
- package/dist/assets/{arkade-DryM-q5n.js → arkade-B6UNf5HI.js} +2 -2
- package/dist/assets/{arkade-DryM-q5n.js.map → arkade-B6UNf5HI.js.map} +1 -1
- package/dist/assets/{backup-D6s0LQdg.js → backup-BeXBtbVL.js} +1 -1
- package/dist/assets/{backup-Bczllmzf.js → backup-CNLY905d.js} +15 -8
- package/dist/assets/backup-CNLY905d.js.map +1 -0
- package/dist/assets/bark_ffi_wasm_bg-CjjCN3FD.js +5 -0
- package/dist/assets/{bitcoind-DML_-Xbv.js → bitcoind-BXZdQ1wZ.js} +2 -2
- package/dist/assets/{bitcoind-DML_-Xbv.js.map → bitcoind-BXZdQ1wZ.js.map} +1 -1
- package/dist/assets/bitcoindevkit_bg-D6IFIaJi.js +5 -0
- package/dist/assets/{buttons-B3C3vdhH.js → buttons-BKojbx0Q.js} +4 -4
- package/dist/assets/{buttons-B3C3vdhH.js.map → buttons-BKojbx0Q.js.map} +1 -1
- package/dist/assets/buttons-_5Fw8uHn.js +1 -0
- package/dist/assets/{client-B7jRrSnb.js → client-BtPhfWjK.js} +2 -2
- package/dist/assets/{client-B7jRrSnb.js.map → client-BtPhfWjK.js.map} +1 -1
- package/dist/assets/{engineErrors--9hfgKlK.js → engineErrors-wWlLy54D.js} +11 -3
- package/dist/assets/engineErrors-wWlLy54D.js.map +1 -0
- package/dist/assets/{fedimintSdk-D-6H9Pe7.js → fedimintSdk-eLXBrj9i.js} +2 -2
- package/dist/assets/{fedimintSdk-D-6H9Pe7.js.map → fedimintSdk-eLXBrj9i.js.map} +1 -1
- package/dist/assets/fedimint_client_wasm_bg-CRQlnJdu.js +5 -0
- package/dist/assets/{fixedHosts-H3i6o9Iy.js → fixedHosts-BJFL8Ell.js} +3 -3
- package/dist/assets/{fixedHosts-H3i6o9Iy.js.map → fixedHosts-BJFL8Ell.js.map} +1 -1
- package/dist/assets/{groupMeta--fxSh792.js → groupMeta-Cz95F6sX.js} +201 -43
- package/dist/assets/groupMeta-Cz95F6sX.js.map +1 -0
- package/dist/assets/{host-CGzVFfMz.js → host-BsBWxTtW.js} +276 -53
- package/dist/assets/host-BsBWxTtW.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-Ce-gWsRY.js → hyperdhtRelay-B34Zhz4P.js} +2 -2
- package/dist/assets/{hyperdhtRelay-Ce-gWsRY.js.map → hyperdhtRelay-B34Zhz4P.js.map} +1 -1
- package/dist/assets/{hyperdhtRelay-B4_wdCtx.js → hyperdhtRelay-DDwU5b4P.js} +2 -2
- package/dist/assets/{hyperdhtRelay-B4_wdCtx.js.map → hyperdhtRelay-DDwU5b4P.js.map} +1 -1
- package/dist/assets/{identityProofs-Cksc_K7_.js → identityProofs-zI_Iy9uI.js} +154 -27
- package/dist/assets/identityProofs-zI_Iy9uI.js.map +1 -0
- package/dist/assets/{irohWeb-Dp1i8v6n.js → irohWeb-BLDcHwYz.js} +10866 -4829
- package/dist/assets/irohWeb-BLDcHwYz.js.map +1 -0
- package/dist/assets/{linkPreview-DdMf-YAc.js → linkPreview-5kHmKUTN.js} +20 -8
- package/dist/assets/linkPreview-5kHmKUTN.js.map +1 -0
- package/dist/assets/{main-C8J53SwH.js → main-D48Ben7C.js} +122 -49
- package/dist/assets/main-D48Ben7C.js.map +1 -0
- package/dist/assets/{mainline-DY95WbuK.js → mainline-CDUXtV-I.js} +2 -2
- package/dist/assets/{mainline-DY95WbuK.js.map → mainline-CDUXtV-I.js.map} +1 -1
- package/dist/assets/{networkReason-Be-hMghr.js → networkReason-DYlPZS5M.js} +2 -2
- package/dist/assets/{networkReason-Be-hMghr.js.map → networkReason-DYlPZS5M.js.map} +1 -1
- package/dist/assets/{ownDid-oa-T2vmZ.js → ownDid-CwxFBzOH.js} +6 -5
- package/dist/assets/ownDid-CwxFBzOH.js.map +1 -0
- package/dist/assets/{ownStatus-Bc08eNJY.js → ownStatus-DjD0sQKF.js} +34 -11
- package/dist/assets/ownStatus-DjD0sQKF.js.map +1 -0
- package/dist/assets/{pairedTransports-Dppn8lUN.js → pairedTransports-DAzupLYo.js} +21 -15
- package/dist/assets/pairedTransports-DAzupLYo.js.map +1 -0
- package/dist/assets/{paymentIntent-DySU3Ajm.js → paymentIntent-Cr3uZa_0.js} +2 -2
- package/dist/assets/{paymentIntent-DySU3Ajm.js.map → paymentIntent-Cr3uZa_0.js.map} +1 -1
- package/dist/assets/{profiles-B2uy04ph.js → profiles-BAJf0c9E.js} +33 -8
- package/dist/assets/profiles-BAJf0c9E.js.map +1 -0
- package/dist/assets/{registry-bLIfG619.js → registry-CHwHTWbK.js} +1 -1
- package/dist/assets/{registry-DbTLLs3y.js → registry-CPuexTle.js} +25 -13
- package/dist/assets/registry-CPuexTle.js.map +1 -0
- package/dist/assets/{relay-CHWg5hpZ.js → relay-gJTOYQJZ.js} +93 -7
- package/dist/assets/relay-gJTOYQJZ.js.map +1 -0
- package/dist/assets/{resolve-DNX-eecG.js → resolve-BqmGXKn4.js} +3 -3
- package/dist/assets/{resolve-DNX-eecG.js.map → resolve-BqmGXKn4.js.map} +1 -1
- package/dist/assets/{server-DWJ4RzJn.js → server-e4oKeNez.js} +901 -6262
- package/dist/assets/server-e4oKeNez.js.map +1 -0
- package/dist/assets/{sshForges-BnvwmNj-.js → sshForges-Cqt3qfWe.js} +2 -2
- package/dist/assets/{sshForges-BnvwmNj-.js.map → sshForges-Cqt3qfWe.js.map} +1 -1
- package/dist/assets/{translate-CHj_PdLg.js → translate-DnuQMfj0.js} +10 -4
- package/dist/assets/translate-DnuQMfj0.js.map +1 -0
- package/dist/assets/{usdt-CBJ4Q5Ji.js → usdt-DLmtf8F9.js} +4 -4
- package/dist/assets/{usdt-CBJ4Q5Ji.js.map → usdt-DLmtf8F9.js.map} +1 -1
- package/dist/assets/{waitNotice-Cvz5CiKR.js → waitNotice-mB0Ym145.js} +2 -2
- package/dist/assets/{waitNotice-Cvz5CiKR.js.map → waitNotice-mB0Ym145.js.map} +1 -1
- package/dist/ghostly.mjs +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/dist/assets/api-DF36rBJK.js +0 -3
- package/dist/assets/api-Dnq86JAA.js.map +0 -1
- package/dist/assets/apiKit-nLK4jeTq.js.map +0 -1
- package/dist/assets/apps-DBVhKpfe.js.map +0 -1
- package/dist/assets/backup-Bczllmzf.js.map +0 -1
- package/dist/assets/bark_ffi_wasm_bg-CcafsJla.js +0 -5
- package/dist/assets/bark_ffi_wasm_bg-CcafsJla.js.map +0 -1
- package/dist/assets/bark_ffi_wasm_bg-VNmaJsc9.wasm +0 -0
- package/dist/assets/bitcoindevkit_bg-BWQHx7vd.js +0 -5
- package/dist/assets/bitcoindevkit_bg-BWQHx7vd.js.map +0 -1
- package/dist/assets/bitcoindevkit_bg-DXil67yS.wasm +0 -0
- package/dist/assets/buttons-DaY5FYlV.js +0 -1
- package/dist/assets/engineErrors--9hfgKlK.js.map +0 -1
- package/dist/assets/fedimint_client_wasm_bg-Cr5xGD-w.js +0 -5
- package/dist/assets/fedimint_client_wasm_bg-Cr5xGD-w.js.map +0 -1
- package/dist/assets/fedimint_client_wasm_bg-DeFtkIv6.wasm +0 -0
- package/dist/assets/groupMeta--fxSh792.js.map +0 -1
- package/dist/assets/host-CGzVFfMz.js.map +0 -1
- package/dist/assets/identityProofs-Cksc_K7_.js.map +0 -1
- package/dist/assets/irohWeb-Dp1i8v6n.js.map +0 -1
- package/dist/assets/linkPreview-DdMf-YAc.js.map +0 -1
- package/dist/assets/main-C8J53SwH.js.map +0 -1
- package/dist/assets/ownDid-oa-T2vmZ.js.map +0 -1
- package/dist/assets/ownStatus-Bc08eNJY.js.map +0 -1
- package/dist/assets/pairedTransports-Dppn8lUN.js.map +0 -1
- package/dist/assets/profiles-B2uy04ph.js.map +0 -1
- package/dist/assets/registry-DbTLLs3y.js.map +0 -1
- package/dist/assets/relay-CHWg5hpZ.js.map +0 -1
- package/dist/assets/server-DWJ4RzJn.js.map +0 -1
- package/dist/assets/translate-CHj_PdLg.js.map +0 -1
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { c as normalizeRelayUrl, l as relayUrlProblem } from "./relay-
|
|
1
|
+
import { $a as readImageMeta, Ai as GhostlyHttpError, An as baseMime, Dn as PLAYABLE_AUDIO, Dt as TYPING_KINDS, Ea as isAppUrl, En as sanitizeMime, Er as checkStatusCard, Fi as LIMITS, Fn as voiceLevel, Mr as MESSAGE_CLOCK_SKEW_MS, Ni as parseLocalTarget, Nn as parseVoiceMeta, O as GROUP_FILE_LIMITS, On as VOICE_LIMITS, Ot as TYPING_REFRESH_MS, Pa as appRef, Pn as voiceDownloadName, Pr as claimedTime, Si as AWAITING_PEER_MS, Tn as sanitizeFileName, Va as isAppRef, br as appCardId, cr as replySnippet, do as ownInviteRefusal, ji as VIEWER_PERMISSIONS_POLICY, jn as downsamplePeaks, jt as sanitizeTypingStatus, kn as VOICE_METER, kr as statusCardBytes, lo as inviteLink, n as groupCallSfu, nn as APP_DATA_MAX_BYTES, vr as STATUS_CARD_LIMITS, wr as cardLine, xr as appCardUrl } from "./groupMeta-Cz95F6sX.js";
|
|
2
|
+
import { G as removeStored, J as waitingGroupFile, P as paymentNetwork, Pt as decodeCommunityLink, T as replyRef, Y as IDENTITY_DRAFT_TTL_MS, an as withoutAudioMetadata, b as groupOfFile, cn as NO_PICTURE_METADATA, d as groupPayLineId, f as groupPayNoteId, l as normalizeMintUrl, ln as stripPictureMetadata, p as groupPayTwin, sn as withoutVideoMetadata, t as DEFAULT_IROH_RELAYS, u as groupMemberOfLink, un as withoutPictureMetadata, v as groupFileId, vt as iceServerProblem, yt as iceServerSetting, zt as decodeGroupEntryLink } from "./irohWeb-BLDcHwYz.js";
|
|
3
|
+
import { c as normalizeRelayUrl, l as relayUrlProblem } from "./relay-gJTOYQJZ.js";
|
|
4
4
|
import { n as secretWords, r as findSecret, t as guardText } from "./secretGuard-oz_3hBfW.js";
|
|
5
|
-
import { a as PAY_METHODS, d as ENGINE_METHODS, f as ENGINE_PARAMS, g as engineParamsProblem, i as CHAT_METHODS, l as withStoredIds, m as READ_PARAMS, n as statusJson, o as TRANSPORT_NAMES, p as ENGINE_READS, r as ADDRESS_TYPES, s as WALLET_TYPES, t as checkOwnStatus, u as DESTRUCTIVE_CALLS } from "./ownStatus-
|
|
5
|
+
import { a as PAY_METHODS, d as ENGINE_METHODS, f as ENGINE_PARAMS, g as engineParamsProblem, i as CHAT_METHODS, l as withStoredIds, m as READ_PARAMS, n as statusJson, o as TRANSPORT_NAMES, p as ENGINE_READS, r as ADDRESS_TYPES, s as WALLET_TYPES, t as checkOwnStatus, u as DESTRUCTIVE_CALLS } from "./ownStatus-DjD0sQKF.js";
|
|
6
6
|
import { i as localFileError, o as shownValue, r as asCliError, t as CliError } from "./errors-JVJsO8Iu.js";
|
|
7
|
-
import { A as
|
|
7
|
+
import { A as oneOf, B as state, C as noMessage, D as notInYet, E as node, F as sharedGroupIds, H as transportOffered, I as shownName, L as sinceSeq, M as ownChatOf, N as sentAt, O as notInYetError, P as settingsOf, R as somebodyJoined, S as noFile, U as waitForState, V as str, W as shellWord, _ as keptForJoin, a as contactKeyOf, b as nameKey, c as findChatOrGroup, d as groupById, f as groupCalled, g as inviteTaken, h as groupPrefixed, j as oneShotWaits, k as num, l as findGroup, m as groupOf, n as chatOf, o as dhtOnly, p as groupNameOf, r as chatOrGroup, s as findChat, t as bool, v as list, w as nobodyJoined, y as messageOf } from "./apiKit-DAFsWtyk.js";
|
|
8
8
|
import { l as toBase64Url, s as randomBytes$1 } from "./bytes-C1DNGY18.js";
|
|
9
9
|
import { f as FILE_BYTES_STEP, o as fileBytes, s as fileBytesOf } from "./fileBytes-CfvUXdSy.js";
|
|
10
10
|
import { p as fileStore } from "./idb-ewvbqyDI.js";
|
|
11
11
|
import { t as childEnv } from "./childEnv-C-99hdbL.js";
|
|
12
|
-
import { a as checkTextSize$1, c as goesOn, d as purgeMessage, f as waitForConfirmed, g as waitForRemoval, h as waitForMessage, i as pressable, l as nobodyElseIn, m as waitForGroupFrame, n as buttonsCard, o as ended, p as waitForEdit, s as foldsAnyway, t as BUTTON_METHODS, u as outOf } from "./buttons-
|
|
13
|
-
import { a as checkShownName } from "./profiles-
|
|
14
|
-
import {
|
|
15
|
-
import { m as identityStatement } from "./identityProofs-
|
|
16
|
-
import { a as SignerTimeout, i as parseProofBunker, t as IDENTITY_PROVIDERS } from "./registry-
|
|
17
|
-
import { t as BACKUP_METHODS } from "./backup-
|
|
18
|
-
import { s as isAppFetchUrl } from "./appFetch-
|
|
19
|
-
import { o as checkedBundle } from "./apps-
|
|
20
|
-
import { m as parsePaymentAmount } from "./paymentIntent-
|
|
21
|
-
import { a as heldWords, n as dhtOnlyNote, t as chatState } from "./waitNotice-
|
|
12
|
+
import { a as checkTextSize$1, c as goesOn, d as purgeMessage, f as waitForConfirmed, g as waitForRemoval, h as waitForMessage, i as pressable, l as nobodyElseIn, m as waitForGroupFrame, n as buttonsCard, o as ended, p as waitForEdit, s as foldsAnyway, t as BUTTON_METHODS, u as outOf } from "./buttons-BKojbx0Q.js";
|
|
13
|
+
import { a as checkShownName } from "./profiles-BAJf0c9E.js";
|
|
14
|
+
import { o as MAX_AVATAR_LENGTH, s as sanitizeAvatar } from "./linkPreview-5kHmKUTN.js";
|
|
15
|
+
import { m as identityStatement } from "./identityProofs-zI_Iy9uI.js";
|
|
16
|
+
import { a as SignerTimeout, i as parseProofBunker, t as IDENTITY_PROVIDERS } from "./registry-CPuexTle.js";
|
|
17
|
+
import { t as BACKUP_METHODS } from "./backup-CNLY905d.js";
|
|
18
|
+
import { s as isAppFetchUrl } from "./appFetch-BQO5Pk7W.js";
|
|
19
|
+
import { o as checkedBundle } from "./apps-B88rYWRm.js";
|
|
20
|
+
import { m as parsePaymentAmount } from "./paymentIntent-Cr3uZa_0.js";
|
|
21
|
+
import { a as heldWords, n as dhtOnlyNote, t as chatState } from "./waitNotice-mB0Ym145.js";
|
|
22
22
|
import { generateMnemonic } from "@scure/bip39";
|
|
23
23
|
import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
24
24
|
import { execFile, spawn } from "node:child_process";
|
|
@@ -937,7 +937,11 @@ async function stageWhileAsked(bytes, id, path, source, gone) {
|
|
|
937
937
|
* the announcement. This device is its first holder and serves the members who ask.
|
|
938
938
|
*/
|
|
939
939
|
async function sendToGroup(ctx, params, group, path, name, picked, gone) {
|
|
940
|
-
if (picked > GROUP_FILE_LIMITS.maxBytes) throw new CliError("refused", `Too large for a group (
|
|
940
|
+
if (picked > GROUP_FILE_LIMITS.maxBytes) throw new CliError("refused", `Too large for a group: ${name} is ${megabytes(picked)}, a group takes up to ${GROUP_FILE_LIMITS.maxBytes / 1048576} MiB (send it in a 1:1 chat)`, {
|
|
941
|
+
reason: "too_large",
|
|
942
|
+
size: picked,
|
|
943
|
+
max: GROUP_FILE_LIMITS.maxBytes
|
|
944
|
+
});
|
|
941
945
|
if (!picked) throw new CliError("refused", "An empty file cannot go to a group");
|
|
942
946
|
const mime = mimeOf(path, str(params, "mime"), params.voice !== void 0);
|
|
943
947
|
const replyTo = str(params, "reply");
|
|
@@ -1015,14 +1019,15 @@ var NAME_BYTES = 255;
|
|
|
1015
1019
|
/**
|
|
1016
1020
|
* `name` as an entry of a folder: an app's name may have 200 characters, which in UTF-8 can be 800 bytes. The end of
|
|
1017
1021
|
* its stem goes until it fits, its extension stays (as `sanitizeFileName` shortens it), so "文…文.txt" is saved as a text.
|
|
1022
|
+
* A `mark` (" (2)") goes between them and is kept too.
|
|
1018
1023
|
*/
|
|
1019
|
-
function fitName(name) {
|
|
1024
|
+
function fitName(name, mark = "") {
|
|
1020
1025
|
const fits = (candidate) => Buffer.byteLength(candidate) <= NAME_BYTES;
|
|
1021
|
-
if (fits(name)) return name;
|
|
1026
|
+
if (!mark && fits(name)) return name;
|
|
1022
1027
|
const extension = /\.[^.\s]{1,15}$/u.exec(name)?.[0] ?? "";
|
|
1023
1028
|
const stem = [...name.slice(0, name.length - extension.length)];
|
|
1024
|
-
while (stem.length && !fits(stem.join("").trimEnd() + extension)) stem.pop();
|
|
1025
|
-
return (stem.join("").trimEnd() || "file") + extension;
|
|
1029
|
+
while (stem.length && !fits(stem.join("").trimEnd() + mark + extension)) stem.pop();
|
|
1030
|
+
return (stem.join("").trimEnd() || "file") + mark + extension;
|
|
1026
1031
|
}
|
|
1027
1032
|
/**
|
|
1028
1033
|
* The name `file save --dir` writes a file under. Its sender chose it, and the folder is one scripts and people run
|
|
@@ -1082,6 +1087,48 @@ var ACTIONS = [
|
|
|
1082
1087
|
"request"
|
|
1083
1088
|
];
|
|
1084
1089
|
/**
|
|
1090
|
+
* Who ended a transfer, and how, from the engine's words for it (core's `chatFiles.ts`): its view says only `failed`,
|
|
1091
|
+
* and a script could not tell "the contact said no" from "I already did it" without reading the English.
|
|
1092
|
+
*/
|
|
1093
|
+
var ENDS = {
|
|
1094
|
+
"You cancelled it": {
|
|
1095
|
+
reason: "cancelled",
|
|
1096
|
+
by: "me"
|
|
1097
|
+
},
|
|
1098
|
+
"You declined it": {
|
|
1099
|
+
reason: "declined",
|
|
1100
|
+
by: "me"
|
|
1101
|
+
},
|
|
1102
|
+
"Cancelled by your contact": {
|
|
1103
|
+
reason: "cancelled",
|
|
1104
|
+
by: "contact"
|
|
1105
|
+
},
|
|
1106
|
+
"Declined by your contact": {
|
|
1107
|
+
reason: "declined",
|
|
1108
|
+
by: "contact"
|
|
1109
|
+
},
|
|
1110
|
+
"Cancelled by the sender": {
|
|
1111
|
+
reason: "cancelled",
|
|
1112
|
+
by: "contact"
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
1115
|
+
var endOf = (transfer) => ENDS[transfer.error ?? ""] ?? {
|
|
1116
|
+
reason: "failed",
|
|
1117
|
+
by: null
|
|
1118
|
+
};
|
|
1119
|
+
/**
|
|
1120
|
+
* A transfer that ended, refused with its words and the way out: the sender still has the bytes and sends them again
|
|
1121
|
+
* (`file resend` goes on from what the contact holds, while it may); the receiver asks the contact for them.
|
|
1122
|
+
*/
|
|
1123
|
+
function endedFile(fileId, where, transfer, outgoing) {
|
|
1124
|
+
const way = where && "chat" in where ? outgoing ? transfer.retry ? " (file resend sends it again)" : ` (send it again: ghostly file send ${where.chat} <path>)` : " (ask the contact to send it again)" : "";
|
|
1125
|
+
return new CliError("refused", `It ended: ${transfer.error ?? "failed"}${way}`, {
|
|
1126
|
+
file: fileId,
|
|
1127
|
+
...where,
|
|
1128
|
+
...endOf(transfer)
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1085
1132
|
* `file wait`: until a transfer ends: done answers, failed is an `engine` error with the transfer's words (and whether
|
|
1086
1133
|
* `file resend` can go on). A file whose transfer this run has not seen answers from the file store. `stopping`: the
|
|
1087
1134
|
* daemon's stop ends it as well (`waitForState`), for `file send --wait`, which answers with what it knows then.
|
|
@@ -1112,7 +1159,8 @@ async function waitForFile(ctx, params, stopping) {
|
|
|
1112
1159
|
if (transfer.state === "failed") throw new CliError("engine", transfer.error ?? "The transfer failed", {
|
|
1113
1160
|
file: fileId,
|
|
1114
1161
|
...where,
|
|
1115
|
-
retry: !!transfer.retry
|
|
1162
|
+
retry: !!transfer.retry,
|
|
1163
|
+
...endOf(transfer)
|
|
1116
1164
|
});
|
|
1117
1165
|
if (transfer.state !== "done") throw waitsForYou((stored ?? await fileStore.get(fileId).catch(() => void 0))?.metadata?.name, fileId, where, transfer.size);
|
|
1118
1166
|
return {
|
|
@@ -1122,6 +1170,15 @@ async function waitForFile(ctx, params, stopping) {
|
|
|
1122
1170
|
size: transfer.size
|
|
1123
1171
|
};
|
|
1124
1172
|
}
|
|
1173
|
+
/**
|
|
1174
|
+
* `file accept` of a file that does not fit the room left beside the files still coming (`FileDesk.accept`), in this
|
|
1175
|
+
* CLI's MB: the engine's line gave the room in binary MB beside a size in decimal ones, and neither the files still
|
|
1176
|
+
* coming that take the rest nor the way out.
|
|
1177
|
+
*/
|
|
1178
|
+
function noRoomWords(fileId, name, size, room, coming) {
|
|
1179
|
+
const rest = coming > 0 ? `, and ${megabytes(coming)} of files still coming need it first` : "";
|
|
1180
|
+
return `${name ?? "The file"} (${megabytes(size)}) does not fit: ${megabytes(room)} free${rest}. Free some space, then ghostly file accept ${fileId} again (or file decline)`;
|
|
1181
|
+
}
|
|
1125
1182
|
/** A received file that waits for this person's `file accept` (`file wait`, `file save`): said naming the command. */
|
|
1126
1183
|
function waitsForYou(name, fileId, where, size) {
|
|
1127
1184
|
return new CliError("confirm", `${name ?? "The file"} (${megabytes(size)}) waits for you to take it: ghostly file accept ${fileId} (or file decline)`, {
|
|
@@ -1305,14 +1362,22 @@ var FILE_METHODS = {
|
|
|
1305
1362
|
if (outgoing !== (action === "resend")) throw new CliError("bad_request", outgoing ? "A file sent from here is sent again: file resend" : "A received file is asked for again: file request");
|
|
1306
1363
|
const transfer = state(ctx).transfers[fileId];
|
|
1307
1364
|
if (!transfer || transfer.state === "done") throw new CliError("refused", outgoing ? "Nothing to send again: it arrived whole" : "Nothing to ask for: the file is all here");
|
|
1308
|
-
if (transfer.state === "failed" && (!outgoing || !transfer.retry)) throw
|
|
1365
|
+
if (transfer.state === "failed" && (!outgoing || !transfer.retry)) throw endedFile(fileId, where, transfer, outgoing);
|
|
1309
1366
|
} else {
|
|
1310
1367
|
const outgoing = fileId.startsWith(`${linkId}-out-`);
|
|
1311
1368
|
if (outgoing && (action === "accept" || action === "decline")) throw new CliError("bad_request", "A file sent from here is not accepted or declined: file cancel stops it");
|
|
1312
1369
|
await refuseAllHere();
|
|
1313
1370
|
const transfer = state(ctx).transfers[fileId] ?? (await fileStore.get(fileId).catch(() => void 0))?.transfer;
|
|
1314
1371
|
if (action === "pause" && transfer?.stage === "verifying") throw new CliError("refused", "Too late to pause: it is being checked");
|
|
1315
|
-
if (transfer?.state === "failed")
|
|
1372
|
+
if (transfer?.state === "failed") {
|
|
1373
|
+
if ((action === "cancel" || action === "decline") && endOf(transfer).by === "me") return {
|
|
1374
|
+
...where,
|
|
1375
|
+
file: fileId,
|
|
1376
|
+
action,
|
|
1377
|
+
transfer: state(ctx).transfers[fileId] ?? transfer
|
|
1378
|
+
};
|
|
1379
|
+
throw endedFile(fileId, where, transfer, outgoing);
|
|
1380
|
+
}
|
|
1316
1381
|
const whole = outgoing && transfer?.state === "transferring" && (transfer.stage === "verifying" || transfer.size > 0 && transfer.transferred >= transfer.size && transfer.stage !== "asking" && transfer.stage !== "queued" && transfer.stage !== "paused");
|
|
1317
1382
|
if (whole && action === "cancel") throw new CliError("refused", "Too late to cancel: it arrived whole, and the contact keeps it");
|
|
1318
1383
|
if (whole && action === "pause") throw new CliError("refused", "Too late to pause: it arrived whole, and the contact keeps it");
|
|
@@ -1327,8 +1392,8 @@ var FILE_METHODS = {
|
|
|
1327
1392
|
action
|
|
1328
1393
|
});
|
|
1329
1394
|
} catch (error) {
|
|
1330
|
-
const room = error
|
|
1331
|
-
if (action === "accept" && error instanceof Error && typeof room === "number" && error.message.startsWith("No room on this device")) throw new CliError("refused",
|
|
1395
|
+
const { room, size, coming } = error ?? {};
|
|
1396
|
+
if (action === "accept" && error instanceof Error && typeof room === "number" && error.message.startsWith("No room on this device")) throw new CliError("refused", noRoomWords(fileId, (await fileStore.get(fileId).catch(() => void 0))?.metadata?.name, typeof size === "number" ? size : view?.size ?? 0, room, typeof coming === "number" ? coming : 0), {
|
|
1332
1397
|
reason: "no_room",
|
|
1333
1398
|
room
|
|
1334
1399
|
});
|
|
@@ -1360,7 +1425,7 @@ var FILE_METHODS = {
|
|
|
1360
1425
|
if (!stored?.metadata) throw noFile(fileId);
|
|
1361
1426
|
if (stored.leftOut) throw new CliError("not_found", "Not in this backup: the light backup this profile was restored from left the file out");
|
|
1362
1427
|
const transfer = stored.direction === "out" ? void 0 : state(ctx).transfers[fileId] ?? waitingGroupFile(stored) ?? stored.transfer;
|
|
1363
|
-
if (transfer?.state === "failed") throw
|
|
1428
|
+
if (transfer?.state === "failed") throw endedFile(fileId, stored.linkId.startsWith("group:") ? { group: stored.linkId.slice(6) } : { chat: stored.linkId }, transfer, false);
|
|
1364
1429
|
if (transfer?.state === "transferring" && transfer.stage === "asking" && transfer.direction === "in") {
|
|
1365
1430
|
let where;
|
|
1366
1431
|
try {
|
|
@@ -1379,6 +1444,10 @@ var FILE_METHODS = {
|
|
|
1379
1444
|
}
|
|
1380
1445
|
const free = !force && !str(params, "path") && !!stored.metadata.voice;
|
|
1381
1446
|
const ext = extname(named), stem = named.slice(0, named.length - ext.length);
|
|
1447
|
+
const numbered = (n) => {
|
|
1448
|
+
const plain = `${stem} (${n})${ext}`;
|
|
1449
|
+
return Buffer.byteLength(basename(plain)) <= NAME_BYTES ? plain : join(dirname(named), fitName(basename(named), ` (${n})`));
|
|
1450
|
+
};
|
|
1382
1451
|
let next = 2;
|
|
1383
1452
|
const taken = async (target, code) => {
|
|
1384
1453
|
const there = await stat(target).catch(() => void 0);
|
|
@@ -1389,14 +1458,14 @@ var FILE_METHODS = {
|
|
|
1389
1458
|
if (path) return new CliError("confirm", replace);
|
|
1390
1459
|
if (free && next <= 1e3) return new CliError("confirm", replace);
|
|
1391
1460
|
let n = 2;
|
|
1392
|
-
while (n <= 1e3 && await stat(
|
|
1393
|
-
const other =
|
|
1461
|
+
while (n <= 1e3 && await stat(numbered(n)).catch(() => void 0)) n += 1;
|
|
1462
|
+
const other = numbered(n);
|
|
1394
1463
|
return new CliError("confirm", `${replace}, or --path ${shellWord(other, "<the one in details.path>")} (path over the socket) to keep both`, { path: other });
|
|
1395
1464
|
};
|
|
1396
1465
|
let target = named;
|
|
1397
1466
|
for (let refused = await taken(target); refused; refused = await taken(target)) {
|
|
1398
1467
|
if (!free || refused.code !== "confirm" || next > 1e3) throw refused;
|
|
1399
|
-
target =
|
|
1468
|
+
target = numbered(next);
|
|
1400
1469
|
next += 1;
|
|
1401
1470
|
}
|
|
1402
1471
|
const partial = join(dirname(target), `.ghostly-save-${process.pid}-${toBase64Url(randomBytes$1(6))}.partial`);
|
|
@@ -1445,7 +1514,7 @@ var FILE_METHODS = {
|
|
|
1445
1514
|
const code = error.code;
|
|
1446
1515
|
const refused = code === "EEXIST" || code === "EISDIR" || code === "ENOTEMPTY" ? await taken(target, code) : void 0;
|
|
1447
1516
|
if (free && refused?.code === "confirm" && next <= 1e3) {
|
|
1448
|
-
target =
|
|
1517
|
+
target = numbered(next);
|
|
1449
1518
|
next += 1;
|
|
1450
1519
|
continue;
|
|
1451
1520
|
}
|
|
@@ -2359,6 +2428,15 @@ function groupPayTwins(messages, notes, payments, group) {
|
|
|
2359
2428
|
return twins;
|
|
2360
2429
|
}
|
|
2361
2430
|
/**
|
|
2431
|
+
* A link join reads `status: "invited"` though nobody invited it: its `note` says that it knocks at the link and how to
|
|
2432
|
+
* stop it. Nothing for anything else.
|
|
2433
|
+
*/
|
|
2434
|
+
function knockNote(group) {
|
|
2435
|
+
if (group.status || !group.invitation?.viaLink) return void 0;
|
|
2436
|
+
const id = shellWord(group.id, group.id);
|
|
2437
|
+
return { note: group.invitation.unanswered ? `You opened its link and nobody let you in: ghostly group accept ${id} knocks again, ghostly group decline ${id} drops it` : `You opened its link and knock until a member's app lets you in (stage says how far): ghostly group decline ${id} stops it` };
|
|
2438
|
+
}
|
|
2439
|
+
/**
|
|
2362
2440
|
* A group as the CLI prints it. The entry link lets anyone who reads it join, so it is `<hidden>` unless asked for
|
|
2363
2441
|
* (`--show-secret`, or `group link`); null when the group has none.
|
|
2364
2442
|
*/
|
|
@@ -2386,10 +2464,11 @@ function groupJson(group, showSecret = false) {
|
|
|
2386
2464
|
})),
|
|
2387
2465
|
...group.hubs ? { hubs: group.hubs } : {},
|
|
2388
2466
|
invitation: group.invitation ? {
|
|
2389
|
-
chat: group.invitation.linkId,
|
|
2467
|
+
chat: group.invitation.viaLink ? null : group.invitation.linkId,
|
|
2390
2468
|
accepted: group.invitation.accepted,
|
|
2391
2469
|
viaLink: !!group.invitation.viaLink,
|
|
2392
2470
|
stage: group.invitation.stage ?? null,
|
|
2471
|
+
...knockNote(group),
|
|
2393
2472
|
...group.invitation.unanswered ? { unanswered: true } : {},
|
|
2394
2473
|
...group.invitation.takenBack ? { takenBack: true } : {}
|
|
2395
2474
|
} : null,
|
|
@@ -2504,9 +2583,9 @@ function callNode(raw, ref, groupId) {
|
|
|
2504
2583
|
*/
|
|
2505
2584
|
function joined(ctx, params, twin) {
|
|
2506
2585
|
const group = groupOf(ctx, params, twin);
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2586
|
+
const yet = notInYet(group, str(params, "group", true));
|
|
2587
|
+
if (yet) throw new CliError("refused", yet);
|
|
2588
|
+
return group;
|
|
2510
2589
|
}
|
|
2511
2590
|
/** The member `params.member` names in `group`, this profile's own name said to be it; by its key only for a grant. */
|
|
2512
2591
|
var member = (ctx, group, params, grant = false) => findMember(group, str(params, "member", true), settingsOf(ctx).nick, grant);
|
|
@@ -2553,6 +2632,7 @@ var GROUP_ADMIN_METHODS = {
|
|
|
2553
2632
|
},
|
|
2554
2633
|
async "group.hub"(ctx, params) {
|
|
2555
2634
|
const group = joined(ctx, params);
|
|
2635
|
+
if (group.profile === "community") throw new CliError("refused", `${group.name} is a community: it chooses its hubs by itself; group hub is for a private group past 16 members`);
|
|
2556
2636
|
const role = str(params, "role") ?? "auto";
|
|
2557
2637
|
if (![
|
|
2558
2638
|
"pin",
|
|
@@ -2594,6 +2674,7 @@ var GROUP_ADMIN_METHODS = {
|
|
|
2594
2674
|
link: null
|
|
2595
2675
|
};
|
|
2596
2676
|
}
|
|
2677
|
+
if (group.profile === "community" && !group.isAdmin && !group.entryLink && !reset) throw new CliError("refused", "The admin turned the link off: nobody can join with it, and the link shared before will not work again. Only the admin can make a new one.");
|
|
2597
2678
|
const { link } = await node(ctx).enableGroupLink({
|
|
2598
2679
|
groupId: group.id,
|
|
2599
2680
|
...reset ? { reset: true } : {}
|
|
@@ -2646,7 +2727,8 @@ var GROUP_ADMIN_METHODS = {
|
|
|
2646
2727
|
*/
|
|
2647
2728
|
var drafts = /* @__PURE__ */ new Map();
|
|
2648
2729
|
var NO_DRAFT = `No such draft here: it is kept by the daemon that made it, for ${IDENTITY_DRAFT_TTL_MS / 6e4} minutes and while fewer than 4 newer ones wait`;
|
|
2649
|
-
|
|
2730
|
+
/** The provider `id` names; a one-shot `identity add` asks before the profile opens (main.ts `identityAddCommand`). */
|
|
2731
|
+
function identityProvider(id) {
|
|
2650
2732
|
const found = IDENTITY_PROVIDERS.find((p) => p.id === id);
|
|
2651
2733
|
if (!found) throw new CliError("not_found", `No identity provider ${id} (ghostly identity providers)`);
|
|
2652
2734
|
return found;
|
|
@@ -2771,7 +2853,7 @@ var IDENTITY_METHODS = {
|
|
|
2771
2853
|
/** Starts a proof. In-app signers finish it here; the others return the statement and what to do with it. */
|
|
2772
2854
|
async "identity.add"(ctx, params) {
|
|
2773
2855
|
pruneDrafts();
|
|
2774
|
-
const p =
|
|
2856
|
+
const p = identityProvider(str(params, "provider", true));
|
|
2775
2857
|
const signer = signerOf(p, str(params, "signer"));
|
|
2776
2858
|
if (signer.kind === "in-app") {
|
|
2777
2859
|
const values = params.fields ?? {};
|
|
@@ -2791,6 +2873,11 @@ var IDENTITY_METHODS = {
|
|
|
2791
2873
|
});
|
|
2792
2874
|
const signal = AbortSignal.timeout(seconds * 1e3);
|
|
2793
2875
|
let signed = false;
|
|
2876
|
+
const request = str(params, "request");
|
|
2877
|
+
const tag = {
|
|
2878
|
+
provider: p.id,
|
|
2879
|
+
...request ? { request } : {}
|
|
2880
|
+
};
|
|
2794
2881
|
return {
|
|
2795
2882
|
done: true,
|
|
2796
2883
|
proof: proofJson(await signer.run({
|
|
@@ -2799,19 +2886,19 @@ var IDENTITY_METHODS = {
|
|
|
2799
2886
|
waitMs: seconds * 1e3,
|
|
2800
2887
|
onAuthUrl: (url) => {
|
|
2801
2888
|
ctx.hub.emitLive("identity.approval", `identity.approval:${Date.now()}`, {
|
|
2802
|
-
|
|
2889
|
+
...tag,
|
|
2803
2890
|
url
|
|
2804
2891
|
});
|
|
2805
2892
|
},
|
|
2806
2893
|
onProgress: (message) => {
|
|
2807
2894
|
ctx.hub.emit("identity.progress", `identity.progress:${Date.now()}`, {
|
|
2808
|
-
|
|
2895
|
+
...tag,
|
|
2809
2896
|
message
|
|
2810
2897
|
});
|
|
2811
2898
|
},
|
|
2812
2899
|
onApproval: (request) => {
|
|
2813
2900
|
if (request) ctx.hub.emitLive("identity.approval", `identity.approval:${Date.now()}`, {
|
|
2814
|
-
|
|
2901
|
+
...tag,
|
|
2815
2902
|
...request.qr ? {
|
|
2816
2903
|
qr: request.qr.value,
|
|
2817
2904
|
label: request.qr.label
|
|
@@ -2871,7 +2958,7 @@ var IDENTITY_METHODS = {
|
|
|
2871
2958
|
pruneDrafts();
|
|
2872
2959
|
const draft = drafts.get(str(params, "draft", true));
|
|
2873
2960
|
if (!draft) throw new CliError("not_found", NO_DRAFT);
|
|
2874
|
-
const signer = signerOf(
|
|
2961
|
+
const signer = signerOf(identityProvider(draft.provider), draft.signer);
|
|
2875
2962
|
const statement = identityStatement(draft.binding);
|
|
2876
2963
|
let evidence;
|
|
2877
2964
|
try {
|
|
@@ -3271,9 +3358,25 @@ async function proxy(request, response, chunks, send, cookies, policy) {
|
|
|
3271
3358
|
*/
|
|
3272
3359
|
function serviceOf(ctx, params) {
|
|
3273
3360
|
const serviceId = str(params, "service", true);
|
|
3274
|
-
|
|
3361
|
+
const { services } = state(ctx);
|
|
3362
|
+
if (!services.some((s) => s.id === serviceId)) throw noService(serviceId, servicesNamed(services, serviceId));
|
|
3275
3363
|
return serviceId;
|
|
3276
3364
|
}
|
|
3365
|
+
/** The ids of the services `given` names by their name, compared as a chat's label is (`nameKey`: one case, one form). */
|
|
3366
|
+
function servicesNamed(services, given) {
|
|
3367
|
+
const key = nameKey(given);
|
|
3368
|
+
return key ? services.filter((s) => nameKey(s.name) === key).map((s) => s.id) : [];
|
|
3369
|
+
}
|
|
3370
|
+
/**
|
|
3371
|
+
* No service of that id. A service's name given instead (`service add "My App"` makes `my-app`) is told which id to
|
|
3372
|
+
* use: before, it read "No service" of a service `service list` shows by that very name. Same code and exit either way.
|
|
3373
|
+
*/
|
|
3374
|
+
function noService(given, named) {
|
|
3375
|
+
const quoted = JSON.stringify(given);
|
|
3376
|
+
if (!named.length) return new CliError("not_found", `No service ${quoted} (ghostly service list)`);
|
|
3377
|
+
const which = named.length === 1 ? `${named[0]}: use its id` : `${named.length} services, ${named.slice(0, -1).join(", ")} and ${named.at(-1)}: use one of their ids`;
|
|
3378
|
+
return new CliError("not_found", `No service with id ${quoted}. ${quoted} is the name of ${which} (ghostly service list)`);
|
|
3379
|
+
}
|
|
3277
3380
|
/**
|
|
3278
3381
|
* On, unless `off`; or as the answer's own key (`shared`, `enabled`) says, when a socket client sends it back. Before,
|
|
3279
3382
|
* only `off` was read, so `{"shared": false}` shared the service with the contact and `{"enabled": false}` turned it on.
|
|
@@ -3304,6 +3407,27 @@ function serviceNameOf(params) {
|
|
|
3304
3407
|
});
|
|
3305
3408
|
return name;
|
|
3306
3409
|
}
|
|
3410
|
+
/** `service add`'s name and target, checked with no profile open (api.ts `refuseBeforeStart`). */
|
|
3411
|
+
function serviceShape(params) {
|
|
3412
|
+
const name = serviceNameOf(params);
|
|
3413
|
+
const target = str(params, "target", true);
|
|
3414
|
+
try {
|
|
3415
|
+
parseLocalTarget(target);
|
|
3416
|
+
} catch (error) {
|
|
3417
|
+
const said = error instanceof Error ? error.message : String(error);
|
|
3418
|
+
const text = target.trim();
|
|
3419
|
+
let shown = "";
|
|
3420
|
+
try {
|
|
3421
|
+
const url = new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(text) ? text : `http://${text}`);
|
|
3422
|
+
shown = `: ${url.protocol}//${url.host}${url.pathname}`;
|
|
3423
|
+
} catch {}
|
|
3424
|
+
throw new CliError(/^Only services on this machine/.test(said) ? "refused" : "bad_request", `${said}${shown}`);
|
|
3425
|
+
}
|
|
3426
|
+
return {
|
|
3427
|
+
name,
|
|
3428
|
+
target
|
|
3429
|
+
};
|
|
3430
|
+
}
|
|
3307
3431
|
function portError(error, port) {
|
|
3308
3432
|
const { code } = error ?? {};
|
|
3309
3433
|
if (port && code === "EADDRINUSE") return new CliError("busy", `Port ${port} is in use on this machine: choose another, or leave out --port`);
|
|
@@ -3322,20 +3446,7 @@ var SERVICE_METHODS = {
|
|
|
3322
3446
|
})) };
|
|
3323
3447
|
},
|
|
3324
3448
|
async "service.add"(ctx, params) {
|
|
3325
|
-
const name =
|
|
3326
|
-
const target = str(params, "target", true);
|
|
3327
|
-
try {
|
|
3328
|
-
parseLocalTarget(target);
|
|
3329
|
-
} catch (error) {
|
|
3330
|
-
const said = error instanceof Error ? error.message : String(error);
|
|
3331
|
-
const text = target.trim();
|
|
3332
|
-
let shown = text;
|
|
3333
|
-
try {
|
|
3334
|
-
const url = new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(text) ? text : `http://${text}`);
|
|
3335
|
-
shown = `${url.protocol}//${url.host}${url.pathname}`;
|
|
3336
|
-
} catch {}
|
|
3337
|
-
throw new CliError(/^Only services on this machine/.test(said) ? "refused" : "bad_request", `${said}: ${shown}`);
|
|
3338
|
-
}
|
|
3449
|
+
const { name, target } = serviceShape(params);
|
|
3339
3450
|
const { serviceId } = node(ctx).addService({
|
|
3340
3451
|
name,
|
|
3341
3452
|
target
|
|
@@ -3535,10 +3646,13 @@ function servedApp(apps, ref) {
|
|
|
3535
3646
|
}
|
|
3536
3647
|
/** A link a contact's app reads a card's bundle from. */
|
|
3537
3648
|
var readable = (url) => isAppFetchUrl(url) && appCardUrl(url) !== void 0;
|
|
3538
|
-
/**
|
|
3649
|
+
/**
|
|
3650
|
+
* Whether this engine offers apps/1 now: it read the list when it started, so the first app served waits for a restart,
|
|
3651
|
+
* and so does the end of the offer once the last one is unserved.
|
|
3652
|
+
*/
|
|
3539
3653
|
var offered = (ctx, apps) => ({
|
|
3540
3654
|
offered: ctx.runtime.apps,
|
|
3541
|
-
...apps.length > 0
|
|
3655
|
+
...apps.length > 0 !== ctx.runtime.apps && { restart: true }
|
|
3542
3656
|
});
|
|
3543
3657
|
var APP_SERVE_METHODS = {
|
|
3544
3658
|
async "app.serve"(ctx, params) {
|
|
@@ -3795,6 +3909,42 @@ var NOT_SENT = {
|
|
|
3795
3909
|
message: `More than 48 frames in a second, or the connection is still sending earlier ones: slow down and send it again`
|
|
3796
3910
|
}
|
|
3797
3911
|
};
|
|
3912
|
+
// ../../apps/ui/src/lib/localHost.ts
|
|
3913
|
+
/**
|
|
3914
|
+
* Names only a local network answers (RFC 6762, RFC 8375, ICANN's .internal, and the usual router and company ones).
|
|
3915
|
+
* A copy of packages/core/src/localNames.ts, as this module imports nothing; the same as Desktop's
|
|
3916
|
+
* apps/desktop/src/local_names.rs (src/test/chat/linkPreviewParse.test.ts pins all three).
|
|
3917
|
+
*/
|
|
3918
|
+
var LOCAL_SUFFIXES = [
|
|
3919
|
+
"localhost",
|
|
3920
|
+
"local",
|
|
3921
|
+
"internal",
|
|
3922
|
+
"lan",
|
|
3923
|
+
"home",
|
|
3924
|
+
"home.arpa",
|
|
3925
|
+
"localdomain",
|
|
3926
|
+
"intranet",
|
|
3927
|
+
"corp"
|
|
3928
|
+
];
|
|
3929
|
+
/**
|
|
3930
|
+
* A host that names this machine or the local network, as far as its spelling tells: a name under a local suffix
|
|
3931
|
+
* (`localhost`, `.local`, `.lan`, `.home`, `.corp`, …), a single label, private and reserved IP addresses. Previews
|
|
3932
|
+
* are never made for these, a page on the internet may not point its picture at one, and a contact's app may not open
|
|
3933
|
+
* one. (Desktop also checks the addresses a name resolves to.)
|
|
3934
|
+
* In a module of its own, importing nothing: the extension's background worker reads it too.
|
|
3935
|
+
*/
|
|
3936
|
+
function isLocalHost(hostname) {
|
|
3937
|
+
const host = hostname.toLowerCase().replace(/\.+$/, "").replace(/^\[|\]$/g, "");
|
|
3938
|
+
if (!host.includes(".") && !host.includes(":")) return true;
|
|
3939
|
+
if (LOCAL_SUFFIXES.some((s) => host === s || host.endsWith(`.${s}`))) return true;
|
|
3940
|
+
const v4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
|
|
3941
|
+
if (v4) {
|
|
3942
|
+
const [a, b] = [Number(v4[1]), Number(v4[2])];
|
|
3943
|
+
return a === 0 || a === 10 || a === 127 || a >= 224 || a === 169 && b === 254 || a === 172 && b >= 16 && b < 32 || a === 192 && b === 168 || a === 100 && b >= 64 && b < 128 || a === 198 && (b === 18 || b === 19) || a === 192 && b === 0;
|
|
3944
|
+
}
|
|
3945
|
+
if (host.includes(":")) return !/^[23][0-9a-f]{3}:/.test(host) || host.includes(".") || host.startsWith("2002:") || /^2001:(0{0,4}|0{0,3}db8):/.test(host);
|
|
3946
|
+
return false;
|
|
3947
|
+
}
|
|
3798
3948
|
// src/wallets.ts
|
|
3799
3949
|
/**
|
|
3800
3950
|
* Wallets and payments (WISP 1100, phase 2): the app's wallet deck and a chat's payment sheet, as methods. Test
|
|
@@ -4013,6 +4163,54 @@ function memoOf(params, verb, field = "memo") {
|
|
|
4013
4163
|
}
|
|
4014
4164
|
return memo || void 0;
|
|
4015
4165
|
}
|
|
4166
|
+
/**
|
|
4167
|
+
* What `pay` reads of its own words, the target's shape among them: checked again before a one-shot opens the profile
|
|
4168
|
+
* (`refuseBeforeStart`), where a target that is no invoice, address or LNURL started every saved chat to be refused.
|
|
4169
|
+
*/
|
|
4170
|
+
function payShape(params) {
|
|
4171
|
+
const comment = memoOf(params, "pay", "comment");
|
|
4172
|
+
const text = str(params, "target", true).trim();
|
|
4173
|
+
const card = cardParam(params);
|
|
4174
|
+
if (params.chat !== void 0 && !isInvoice(text)) throw new CliError("usage", "--chat names the chat an invoice came from: an address's or LNURL's invoice is its server's");
|
|
4175
|
+
if (!isInvoice(text) && !isLnurl(text)) throw new CliError("bad_request", "Not a Lightning invoice, Lightning address or LNURL");
|
|
4176
|
+
return {
|
|
4177
|
+
comment,
|
|
4178
|
+
text,
|
|
4179
|
+
card
|
|
4180
|
+
};
|
|
4181
|
+
}
|
|
4182
|
+
/** The token `wallet redeem` takes, refused as the engine refuses one Cashu's library cannot read (`refuseBeforeStart`). */
|
|
4183
|
+
async function tokenShape(params) {
|
|
4184
|
+
const token = str(params, "token", true).trim();
|
|
4185
|
+
const { getTokenMetadata } = await import("@cashu/cashu-ts");
|
|
4186
|
+
try {
|
|
4187
|
+
getTokenMetadata(token);
|
|
4188
|
+
} catch {
|
|
4189
|
+
throw new CliError("bad_request", "That is not a valid ecash token");
|
|
4190
|
+
}
|
|
4191
|
+
return token;
|
|
4192
|
+
}
|
|
4193
|
+
/** The mint URL `wallet add-mint` takes, refused in the engine's words when it is no URL or not https (`refuseBeforeStart`). */
|
|
4194
|
+
function mintUrlShape(params) {
|
|
4195
|
+
const url = str(params, "url", true);
|
|
4196
|
+
try {
|
|
4197
|
+
normalizeMintUrl(url);
|
|
4198
|
+
} catch (error) {
|
|
4199
|
+
throw badMintUrl(error) ? new CliError("bad_request", error.message) : error;
|
|
4200
|
+
}
|
|
4201
|
+
return url;
|
|
4202
|
+
}
|
|
4203
|
+
/**
|
|
4204
|
+
* What `pay` says with `paid: false`: the payment is not known paid yet. The mint (or the card's source) holds it
|
|
4205
|
+
* pending, or its answer was lost; the engine keeps asking and never pays it twice. Before, the answer said `paid:
|
|
4206
|
+
* false` and nothing else, and no read showed the sats the Cashu wallet set aside for it. Said in the
|
|
4207
|
+
* words of the app's Cashu card ("set aside", `wallet.cashu.setAsideInfo`).
|
|
4208
|
+
*/
|
|
4209
|
+
function notPaidYet(ctx, n, source, amount, feeReserve) {
|
|
4210
|
+
const running = ctx.mode === "one-shot" ? " while this profile runs (`ghostly daemon --detach`)" : "";
|
|
4211
|
+
if (source !== "cashu-mint") return `Not paid yet: your Lightning source has not confirmed this payment (it is pending, or its answer was lost). It is asked again${running} and never paid twice: \`ghostly wallet list\` shows the card's balance once it settles.`;
|
|
4212
|
+
return `Not paid yet: the mint has not settled this payment (it is pending, or its answer was lost). ${`${amount + feeReserve} ${n === "testnet" ? "test sats" : "sats"}`} are set aside for it, out of the balance: they leave with the payment, or come back to the balance if the mint says it failed. It settles by itself: the wallet keeps asking the mint${running} and never pays it twice. \`ghostly wallet history\` lists it once paid, and \`ghostly wallet list\` shows the balance.`;
|
|
4213
|
+
}
|
|
4016
4214
|
function badMintUrl(error) {
|
|
4017
4215
|
const code = error instanceof Error ? error.engineCode : void 0;
|
|
4018
4216
|
return code === "invalidMintUrl" || code === "mintNotHttps";
|
|
@@ -4067,6 +4265,34 @@ function walletRefusal(error) {
|
|
|
4067
4265
|
const code = WALLET_REFUSALS.find(([pattern]) => pattern.test(error.message))?.[1];
|
|
4068
4266
|
return code ? new CliError(code, error.message) : error;
|
|
4069
4267
|
}
|
|
4268
|
+
/**
|
|
4269
|
+
* `wallet redeem` of ecash from a mint that is not one of the wallet's: the engine names the mint's host only and no
|
|
4270
|
+
* way on. Its words, then the command that adds the whole mint URL (the token's), for one who trusts that mint: a mint
|
|
4271
|
+
* holds the sats, so it is offered, never done. Shell-quoted as any hint's word; a URL no quoting survives is not printed.
|
|
4272
|
+
*/
|
|
4273
|
+
function mintNotAdded(error) {
|
|
4274
|
+
if (!(error instanceof Error) || !/^Ecash from \S+ is not accepted$/.test(error.message)) return void 0;
|
|
4275
|
+
const mint = error.mint;
|
|
4276
|
+
if (typeof mint !== "string") return void 0;
|
|
4277
|
+
return new CliError("engine", `${error.message}: its mint is not one of yours (if you trust it to hold your sats: ghostly wallet add-mint ${shellWord(mint, "<the token's mint URL>")})`);
|
|
4278
|
+
}
|
|
4279
|
+
/**
|
|
4280
|
+
* The mints `mintNotAdded` offers no `add-mint` for. A token is what a contact sends, and the way out reads as the
|
|
4281
|
+
* app's advice: never a command `wallet add-mint` refuses (plain http off this machine), nor one that makes a server
|
|
4282
|
+
* on this machine or the local network a mint the wallet then talks to. One who runs such a mint types its URL.
|
|
4283
|
+
*/
|
|
4284
|
+
function mintNotOffered(error) {
|
|
4285
|
+
const mint = error instanceof Error && /^Ecash from \S+ is not accepted$/.test(error.message) ? error.mint : void 0;
|
|
4286
|
+
if (typeof mint !== "string") return void 0;
|
|
4287
|
+
const words = error.message;
|
|
4288
|
+
try {
|
|
4289
|
+
normalizeMintUrl(mint);
|
|
4290
|
+
} catch (refusal) {
|
|
4291
|
+
return new CliError("engine", `${words}: its mint is not one of yours, and not one a wallet can add (${refusal.message})`);
|
|
4292
|
+
}
|
|
4293
|
+
if (!isLocalHost(new URL(mint).hostname)) return void 0;
|
|
4294
|
+
return new CliError("engine", `${words}: its mint is not one of yours, and it is on this machine or a local network (add a mint there only if you run it yourself)`);
|
|
4295
|
+
}
|
|
4070
4296
|
var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
4071
4297
|
async "wallet.list"(ctx, params) {
|
|
4072
4298
|
await federationsOpen(ctx);
|
|
@@ -4212,11 +4438,13 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
4212
4438
|
};
|
|
4213
4439
|
},
|
|
4214
4440
|
async "wallet.redeem"(ctx, params) {
|
|
4215
|
-
return node(ctx).walletReceiveToken({ token:
|
|
4441
|
+
return node(ctx).walletReceiveToken({ token: await tokenShape(params) }).catch((error) => {
|
|
4442
|
+
throw mintNotOffered(error) ?? mintNotAdded(error) ?? error;
|
|
4443
|
+
});
|
|
4216
4444
|
},
|
|
4217
4445
|
async "wallet.mint.add"(ctx, params) {
|
|
4218
4446
|
return node(ctx).walletAddMint({
|
|
4219
|
-
url:
|
|
4447
|
+
url: mintUrlShape(params),
|
|
4220
4448
|
...bool(params, "primary") ? { primary: true } : {}
|
|
4221
4449
|
}).catch((error) => {
|
|
4222
4450
|
throw badMintUrl(error) ? new CliError("bad_request", error.message) : error;
|
|
@@ -4248,18 +4476,13 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
4248
4476
|
},
|
|
4249
4477
|
/** An invoice, a Lightning address or an LNURL, from the network's Lightning (a card of it, or its default). */
|
|
4250
4478
|
async "pay"(ctx, params) {
|
|
4251
|
-
const comment =
|
|
4252
|
-
const text = str(params, "target", true).trim();
|
|
4253
|
-
const card = cardParam(params);
|
|
4479
|
+
const { comment, text, card } = payShape(params);
|
|
4254
4480
|
let invoice = text.replace(/^lightning:/i, "");
|
|
4255
|
-
let n;
|
|
4256
4481
|
let note;
|
|
4257
|
-
if (params.chat !== void 0 && !isInvoice(text)) throw new CliError("usage", "--chat names the chat an invoice came from: an address's or LNURL's invoice is its server's");
|
|
4258
4482
|
const chat = params.chat === void 0 ? void 0 : ownChatOf(ctx, params);
|
|
4259
4483
|
if (chat) inviteTaken(chat);
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
n = network(params);
|
|
4484
|
+
const n = network(params);
|
|
4485
|
+
if (!isInvoice(text)) {
|
|
4263
4486
|
const amount = num(params, "amount", 0, { min: 1 });
|
|
4264
4487
|
if (!amount) throw new CliError("bad_request", "amount is required to pay a Lightning address or LNURL");
|
|
4265
4488
|
if (n === "mainnet" && !bool(params, "confirmReal")) throw new CliError("confirm", "This pays real money (Mainnet): pass --confirm-real to confirm this payment");
|
|
@@ -4276,7 +4499,7 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
4276
4499
|
});
|
|
4277
4500
|
invoice = got.invoice;
|
|
4278
4501
|
note = got.note;
|
|
4279
|
-
}
|
|
4502
|
+
}
|
|
4280
4503
|
if (n === "mainnet" && !bool(params, "confirmReal")) throw new CliError("confirm", "This pays real money (Mainnet): pass --confirm-real to confirm this payment");
|
|
4281
4504
|
await federationsOpen(ctx);
|
|
4282
4505
|
const quote = await node(ctx).walletQuoteInvoice({
|
|
@@ -4298,12 +4521,14 @@ var WALLET_METHODS = Object.fromEntries(Object.entries({
|
|
|
4298
4521
|
invoice
|
|
4299
4522
|
} : {}
|
|
4300
4523
|
});
|
|
4524
|
+
const source = quote.source ?? quote.mint;
|
|
4301
4525
|
return {
|
|
4302
4526
|
network: n,
|
|
4303
4527
|
amount: quote.amount,
|
|
4304
4528
|
feeReserve: quote.feeReserve,
|
|
4305
|
-
source
|
|
4306
|
-
paid: paid.paid
|
|
4529
|
+
source,
|
|
4530
|
+
paid: paid.paid,
|
|
4531
|
+
...!paid.paid && { note: notPaidYet(ctx, n, source, quote.amount, quote.feeReserve) }
|
|
4307
4532
|
};
|
|
4308
4533
|
},
|
|
4309
4534
|
/** Ecash to a contact in a chat (the payment sheet's Pay). */
|
|
@@ -4711,6 +4936,8 @@ var NO_ROOM = {
|
|
|
4711
4936
|
var JOIN_STOPS = /* @__PURE__ */ new Set(["replaced", ...Object.keys(NO_ROOM)]);
|
|
4712
4937
|
/** How long a one-shot `group join` waits to be let in: as long as a one-shot `invite join` waits to pair. */
|
|
4713
4938
|
var ONE_SHOT_JOIN_S = 60;
|
|
4939
|
+
/** A replaced link never lets it in: the next step is a new link, not a daemon. */
|
|
4940
|
+
var REPLACED = "This link was replaced or turned off: ask someone in the group for the current link, then ghostly group join <link>";
|
|
4714
4941
|
/**
|
|
4715
4942
|
* A one-shot `group join` waits to be let in, as a one-shot invite join waits to pair: a member's app lets the joiner
|
|
4716
4943
|
* in only while its knocks go on, and they stop when the command leaves. It left at once with `{"group": id}` and exit
|
|
@@ -4757,10 +4984,23 @@ async function letIn(ctx, groupId, link, held) {
|
|
|
4757
4984
|
}
|
|
4758
4985
|
if (ctx.mode !== "one-shot") {
|
|
4759
4986
|
const now = seen(state(ctx));
|
|
4987
|
+
const joined = now?.status === "active", stage = now?.invitation?.stage ?? null;
|
|
4988
|
+
if (joined || !now?.invitation?.viaLink) return {
|
|
4989
|
+
group: groupId,
|
|
4990
|
+
joined,
|
|
4991
|
+
stage
|
|
4992
|
+
};
|
|
4993
|
+
if (stage === "replaced") return {
|
|
4994
|
+
group: groupId,
|
|
4995
|
+
joined,
|
|
4996
|
+
stage,
|
|
4997
|
+
warning: REPLACED
|
|
4998
|
+
};
|
|
4760
4999
|
return {
|
|
4761
5000
|
group: groupId,
|
|
4762
|
-
joined
|
|
4763
|
-
stage
|
|
5001
|
+
joined,
|
|
5002
|
+
stage,
|
|
5003
|
+
warning: `Not in yet: the daemon goes on knocking at the group's link until a member's app lets you in: ghostly group show ${id} follows it, ghostly group decline ${id} stops it`
|
|
4764
5004
|
};
|
|
4765
5005
|
}
|
|
4766
5006
|
const done = (g) => !g || g.status === "active" || JOIN_STOPS.has(g.invitation?.stage ?? "");
|
|
@@ -4781,7 +5021,7 @@ async function letIn(ctx, groupId, link, held) {
|
|
|
4781
5021
|
group: groupId,
|
|
4782
5022
|
joined,
|
|
4783
5023
|
stage,
|
|
4784
|
-
warning:
|
|
5024
|
+
warning: REPLACED
|
|
4785
5025
|
};
|
|
4786
5026
|
const show = `keep it running (ghostly daemon --detach), then ghostly group show ${shellWord(groupId, groupId)}`;
|
|
4787
5027
|
const full = stage === "full" ? group.invitation?.full : void 0;
|
|
@@ -4833,6 +5073,34 @@ function dhtOnlyTimeout(ctx, chat, text, ref, ms, error) {
|
|
|
4833
5073
|
note
|
|
4834
5074
|
}) : error;
|
|
4835
5075
|
}
|
|
5076
|
+
/**
|
|
5077
|
+
* What keeps `link` off a live session, or undefined: a chat on DHT only opens none (WISP 100: no app dials it). A hold
|
|
5078
|
+
* of this side's (`chat disconnect --hold`) ends by itself (`held`: when), unless the contact's choice keeps it there
|
|
5079
|
+
* too; this side's choice or the contact's is `chat connect`'s refusal (apiKit `dhtOnly`), in its words.
|
|
5080
|
+
*/
|
|
5081
|
+
function offLive(ctx, link) {
|
|
5082
|
+
const held = link.deliveryMode === "dht" && link.dhtDelivery?.peerMode !== "dht" ? holdEnds(ctx, link.id) : null;
|
|
5083
|
+
if (held !== null) return { held };
|
|
5084
|
+
try {
|
|
5085
|
+
dhtOnly(link);
|
|
5086
|
+
} catch (error) {
|
|
5087
|
+
if (error instanceof CliError) return { refusal: error };
|
|
5088
|
+
throw error;
|
|
5089
|
+
}
|
|
5090
|
+
}
|
|
5091
|
+
/**
|
|
5092
|
+
* A `chat wait --until live` that timed out on a chat on DHT only: it could never go live, and its timeout read as a
|
|
5093
|
+
* slow network, so a script waited again. Said with why and what ends it, in `chat connect`'s words; same code, exit
|
|
5094
|
+
* and fields. Read as the chat is at the end: one taken off DHT only meanwhile keeps the usual words.
|
|
5095
|
+
*/
|
|
5096
|
+
function liveNeverCame(ctx, linkId, ref, error) {
|
|
5097
|
+
if (!(error instanceof CliError) || error.code !== "timeout" || error.details) return error;
|
|
5098
|
+
const link = state(ctx).links.find((l) => l.id === linkId);
|
|
5099
|
+
const off = link && offLive(ctx, link);
|
|
5100
|
+
if (!off) return error;
|
|
5101
|
+
const why = "held" in off ? heldWords(off.held, ref, "it goes live", ctx.mode === "one-shot") : off.refusal.message;
|
|
5102
|
+
return new CliError("timeout", `${error.message}. ${why.charAt(0).toUpperCase()}${why.slice(1)}`);
|
|
5103
|
+
}
|
|
4836
5104
|
var METHODS = {
|
|
4837
5105
|
...WALLET_METHODS,
|
|
4838
5106
|
...FILE_METHODS,
|
|
@@ -4946,9 +5214,10 @@ var METHODS = {
|
|
|
4946
5214
|
}
|
|
4947
5215
|
patch[key] = servers;
|
|
4948
5216
|
const unused = servers.flatMap((server) => server.urls.split(/[\s,]+/)).filter((url) => /^turns:|\?transport=tcp$/i.test(url));
|
|
4949
|
-
if (unused.length) warning = `The CLI reaches TURN over UDP only: it does not use ${unused.join(", ")} (the apps do). Add a turn: server over UDP for the CLI`;
|
|
5217
|
+
if (unused.length) warning = (warning ? `${warning}. ` : "") + `The CLI reaches TURN over UDP only: it does not use ${unused.join(", ")} (the apps do). Add a turn: server over UDP for the CLI`;
|
|
4950
5218
|
continue;
|
|
4951
5219
|
}
|
|
5220
|
+
if (key === "hyperdhtRelay" && value) warning = (warning ? `${warning}. ` : "") + "This CLI runs HyperDHT itself and does not dial through hyperdhtRelay: it uses it only with Hide my IP from contacts, which comes in a later release. It is kept for the apps this profile moves to";
|
|
4952
5221
|
patch[key] = value;
|
|
4953
5222
|
}
|
|
4954
5223
|
await node(ctx).updateSettings({ settings: patch }).catch((error) => {
|
|
@@ -5090,6 +5359,8 @@ var METHODS = {
|
|
|
5090
5359
|
if (secret) throw new CliError("confirm", `The text looks like ${secretWords(secret)}; edit with --force if you mean to`, { kind: secret.kind });
|
|
5091
5360
|
}
|
|
5092
5361
|
const { wait, ms } = confirmWait(ctx, params, link.id);
|
|
5362
|
+
const prior = await node(ctx).getMessage(link.id, messageId);
|
|
5363
|
+
const before = prior ? prior.edit?.seq ?? 0 : void 0;
|
|
5093
5364
|
const result = await node(ctx).editMessage({
|
|
5094
5365
|
linkId: link.id,
|
|
5095
5366
|
messageId,
|
|
@@ -5101,6 +5372,8 @@ var METHODS = {
|
|
|
5101
5372
|
}, dhtTooLong(ctx, link, result.error, "edit", str(params, "chat", true)), result);
|
|
5102
5373
|
const id = result.messageId ?? messageId;
|
|
5103
5374
|
let message = await node(ctx).getMessage(link.id, id);
|
|
5375
|
+
const edits = message?.edit?.seq ?? 0;
|
|
5376
|
+
const unchanged = !!message && edits === (before ?? 0);
|
|
5104
5377
|
if (wait === "confirmed" && message?.edit?.pending) message = await waitForEdit(ctx, link.id, id, ms);
|
|
5105
5378
|
const confirmed = !!message && !message.edit?.pending;
|
|
5106
5379
|
return {
|
|
@@ -5108,6 +5381,7 @@ var METHODS = {
|
|
|
5108
5381
|
messageId: id,
|
|
5109
5382
|
edits: message?.edit?.seq ?? 0,
|
|
5110
5383
|
confirmed,
|
|
5384
|
+
...unchanged && { unchanged: true },
|
|
5111
5385
|
...!confirmed && result.note && { note: result.note },
|
|
5112
5386
|
...!confirmed && keptForJoin(ctx, link.id, "the edit")
|
|
5113
5387
|
};
|
|
@@ -5205,7 +5479,11 @@ var METHODS = {
|
|
|
5205
5479
|
ref: str(params, "chat", true)
|
|
5206
5480
|
}) : void 0;
|
|
5207
5481
|
if (gone) throw gone;
|
|
5208
|
-
if (result.error)
|
|
5482
|
+
if (result.error) {
|
|
5483
|
+
const error = new CliError(result.refused || /Only the admin/.test(result.error) ? "refused" : /not in this (?:chat|group)|Nothing is pinned/.test(result.error) ? "not_found" : "bad_request", result.error);
|
|
5484
|
+
const group = target.group ? groupById(ctx, target.id) : void 0;
|
|
5485
|
+
throw group ? notInYetError(group, str(params, "chat", true), error) : error;
|
|
5486
|
+
}
|
|
5209
5487
|
if (target.group) {
|
|
5210
5488
|
const n = result.n, pinned = remove ? null : messageId;
|
|
5211
5489
|
const edges = !n ? 0 : wait === "sent" ? await waitForGroupFrame(ctx, target.id, messageId ?? "", { pin: n }, ms) : node(ctx).groupTaken({
|
|
@@ -5421,14 +5699,15 @@ var METHODS = {
|
|
|
5421
5699
|
max: 3600
|
|
5422
5700
|
}) * 1e3;
|
|
5423
5701
|
const ref = str(params, "message", true);
|
|
5424
|
-
|
|
5425
|
-
|
|
5702
|
+
let theirs;
|
|
5703
|
+
const message = await messageOf(ctx, target.linkId, ref, (m) => {
|
|
5704
|
+
if (m.sender !== "me" && (m.id === ref || m.wireId === ref)) theirs ??= m;
|
|
5705
|
+
return m.sender === "me";
|
|
5706
|
+
});
|
|
5707
|
+
if (!message) throw deleteNotMine(ctx, target, ref, theirs, {
|
|
5426
5708
|
group: target.group,
|
|
5427
5709
|
ref: str(params, "chat", true)
|
|
5428
|
-
},
|
|
5429
|
-
whose: "of yours",
|
|
5430
|
-
tail: ": only your own messages are deleted for everyone"
|
|
5431
|
-
});
|
|
5710
|
+
}, purge);
|
|
5432
5711
|
const result = await node(ctx).removeMessage({
|
|
5433
5712
|
linkId: target.linkId,
|
|
5434
5713
|
messageId: message.id
|
|
@@ -5487,7 +5766,7 @@ var METHODS = {
|
|
|
5487
5766
|
};
|
|
5488
5767
|
let link;
|
|
5489
5768
|
try {
|
|
5490
|
-
link = notAGroup(ctx, params, () => chatOf(ctx, params), (shown, id) => `ghostly message delete ${groupPrefixed(typed) === null && reachesGroup(typed) ? shown : shellWord(groupPrefixed(typed) === null ? `group:${typed}` : typed, `group:${id}`)} ${ref === "<message>" ? ref : shellWord(ref, "<message>")} --everyone${purge ? " --purge" : ""}`);
|
|
5769
|
+
link = notAGroup(ctx, params, () => chatOf(ctx, params), (shown, id) => `ghostly message delete ${id === void 0 || groupPrefixed(typed) === null && reachesGroup(typed) ? shown : shellWord(groupPrefixed(typed) === null ? `group:${typed}` : typed, `group:${id}`)} ${ref === "<message>" ? ref : shellWord(ref, "<message>")} --everyone${purge ? " --purge" : ""}${byItsId(id)}`);
|
|
5491
5770
|
} catch (error) {
|
|
5492
5771
|
const group = error instanceof CliError ? error.details?.group : void 0;
|
|
5493
5772
|
const theirs = typeof group === "string" && ref !== "<message>" ? await messageOf(ctx, `group:${group}`, ref).catch(() => void 0) : void 0;
|
|
@@ -5548,7 +5827,7 @@ var METHODS = {
|
|
|
5548
5827
|
return { removed: link.id };
|
|
5549
5828
|
},
|
|
5550
5829
|
async "chat.transport"(ctx, params) {
|
|
5551
|
-
const link =
|
|
5830
|
+
const link = chatNotGroupLink(ctx, params);
|
|
5552
5831
|
const name = str(params, "transport", true);
|
|
5553
5832
|
const transport = Object.hasOwn(TRANSPORT_NAMES, name) ? TRANSPORT_NAMES[name] : void 0;
|
|
5554
5833
|
if (!transport) throw new CliError("bad_request", `transport must be one of auto, dht, webrtc, iroh, hyperdht`);
|
|
@@ -5563,7 +5842,7 @@ var METHODS = {
|
|
|
5563
5842
|
},
|
|
5564
5843
|
/** Reconnects now; a chat held off its direct link (`chat disconnect --hold`) leaves the hold first. */
|
|
5565
5844
|
async "chat.connect"(ctx, params) {
|
|
5566
|
-
const link =
|
|
5845
|
+
const link = chatNotGroupLink(ctx, params);
|
|
5567
5846
|
await releaseHold(ctx, link.id, "connect");
|
|
5568
5847
|
inviteTaken(link);
|
|
5569
5848
|
dhtOnly(findChat(state(ctx).links, link.id));
|
|
@@ -5578,7 +5857,7 @@ var METHODS = {
|
|
|
5578
5857
|
* direct link that long, on the DHT (its "DHT only" choice, taken back after); 0 ends a hold now.
|
|
5579
5858
|
*/
|
|
5580
5859
|
async "chat.disconnect"(ctx, params) {
|
|
5581
|
-
const link =
|
|
5860
|
+
const link = chatNotGroupLink(ctx, params);
|
|
5582
5861
|
const minutes = params.hold === void 0 ? void 0 : num(params, "hold", 0, {
|
|
5583
5862
|
min: 0,
|
|
5584
5863
|
max: HOLD_MAX_MINUTES
|
|
@@ -5609,7 +5888,7 @@ var METHODS = {
|
|
|
5609
5888
|
return chatJson(findChat(state(ctx).links, link.id));
|
|
5610
5889
|
},
|
|
5611
5890
|
async "chat.wait"(ctx, params) {
|
|
5612
|
-
const link =
|
|
5891
|
+
const link = chatNotGroupLink(ctx, params);
|
|
5613
5892
|
const until = oneOf(params, "until", [
|
|
5614
5893
|
"live",
|
|
5615
5894
|
"text",
|
|
@@ -5619,11 +5898,14 @@ var METHODS = {
|
|
|
5619
5898
|
min: 1,
|
|
5620
5899
|
max: 86400
|
|
5621
5900
|
}) * 1e3;
|
|
5901
|
+
const ref = str(params, "chat", true);
|
|
5622
5902
|
return chatJson(await waitForState(ctx, (s) => {
|
|
5623
5903
|
const now = s.links.find((l) => l.id === link.id);
|
|
5624
5904
|
if (!now) throw new CliError("not_found", `Chat ${link.id} was removed`);
|
|
5625
5905
|
return (until === "live" ? isLive(now) : until === "text" ? now.textDelivery === "stream" || now.textDelivery === "dht" || now.textDelivery === "hold" : !!now.peerParticipationKey || !!now.pairingProgress?.peerSeen || now.pairing?.status === "ready" || isLive(now)) ? now : void 0;
|
|
5626
|
-
}, ms, `chat ${
|
|
5906
|
+
}, ms, `chat ${ref} ${chatState(until).to}`).catch((error) => {
|
|
5907
|
+
throw until === "live" ? liveNeverCame(ctx, link.id, ref, error) : error;
|
|
5908
|
+
}));
|
|
5627
5909
|
},
|
|
5628
5910
|
async "group.create"(ctx, params) {
|
|
5629
5911
|
const name = groupNameOf(params);
|
|
@@ -5645,7 +5927,7 @@ var METHODS = {
|
|
|
5645
5927
|
({groupId} = await node(ctx).joinGroupByLink({ link }));
|
|
5646
5928
|
} catch (error) {
|
|
5647
5929
|
if (error instanceof Error && error.message === "This is not a link to a group") throw new CliError("bad_request", error.message);
|
|
5648
|
-
throw error;
|
|
5930
|
+
throw joinRefused(link, error);
|
|
5649
5931
|
}
|
|
5650
5932
|
return letIn(ctx, groupId, link, before.find((g) => g.id === groupId));
|
|
5651
5933
|
},
|
|
@@ -5701,7 +5983,7 @@ var METHODS = {
|
|
|
5701
5983
|
if (result.error) throw replyTo && notHere(result.error, replyTo, {
|
|
5702
5984
|
group: true,
|
|
5703
5985
|
ref: str(params, "group", true)
|
|
5704
|
-
}) || (result.refused ? new CliError("refused", result.error) : groupSendRefused(result.error));
|
|
5986
|
+
}) || notInYetError(group, str(params, "group", true), result.refused ? new CliError("refused", result.error) : groupSendRefused(result.error));
|
|
5705
5987
|
const messageId = result.messageId ?? null;
|
|
5706
5988
|
const edges = messageId ? wait === "sent" ? await waitForGroupFrame(ctx, group.id, messageId, void 0, ms) : node(ctx).groupTaken({
|
|
5707
5989
|
groupId: group.id,
|
|
@@ -5784,9 +6066,12 @@ var METHODS = {
|
|
|
5784
6066
|
min: 1,
|
|
5785
6067
|
max: 3600
|
|
5786
6068
|
}) * 1e3;
|
|
6069
|
+
const ref = str(params, "group", true);
|
|
5787
6070
|
const { n, ...said } = await react(ctx, `group:${group.id}`, params, {
|
|
5788
6071
|
group: true,
|
|
5789
|
-
ref
|
|
6072
|
+
ref
|
|
6073
|
+
}).catch((error) => {
|
|
6074
|
+
throw error instanceof CliError ? notInYetError(group, ref, error) : error;
|
|
5790
6075
|
});
|
|
5791
6076
|
const edges = !n ? 0 : wait === "sent" ? await waitForGroupFrame(ctx, group.id, said.messageId, { reaction: n }, ms) : node(ctx).groupTaken({
|
|
5792
6077
|
groupId: group.id,
|
|
@@ -5818,7 +6103,7 @@ var METHODS = {
|
|
|
5818
6103
|
max: 600
|
|
5819
6104
|
});
|
|
5820
6105
|
if (!typing && seconds) throw new CliError("bad_request", "for keeps typing on: not with stop");
|
|
5821
|
-
if (typing && group.status !== "active") throw new CliError("refused", group.statusReason ?? "You are not in this group");
|
|
6106
|
+
if (typing && group.status !== "active") throw new CliError("refused", group.statusReason ?? notInYet(group, str(params, "group", true)) ?? "You are not in this group");
|
|
5822
6107
|
const target = { groupId: group.id };
|
|
5823
6108
|
endTyping(ctx, target, false);
|
|
5824
6109
|
sayTyping(ctx, target, typing, word);
|
|
@@ -5840,7 +6125,10 @@ var METHODS = {
|
|
|
5840
6125
|
async "group.leave"(ctx, params) {
|
|
5841
6126
|
const group = groupOf(ctx, params);
|
|
5842
6127
|
if (!bool(params, "yes")) throw new CliError("confirm", "Leaving a group deletes its history and files on this device; pass --yes (yes: true over the socket) to go on");
|
|
5843
|
-
const
|
|
6128
|
+
const ref = str(params, "group", true);
|
|
6129
|
+
const { admin } = await node(ctx).leaveGroup({ groupId: group.id }).catch((error) => {
|
|
6130
|
+
throw leaveRefused(ctx, group, ref, error);
|
|
6131
|
+
});
|
|
5844
6132
|
const next = admin ? group.members.find((m) => m.key === admin) : void 0;
|
|
5845
6133
|
return {
|
|
5846
6134
|
left: group.id,
|
|
@@ -5853,7 +6141,9 @@ var METHODS = {
|
|
|
5853
6141
|
async "group.forget"(ctx, params) {
|
|
5854
6142
|
const group = groupOf(ctx, params, "chat remove <chat> --yes");
|
|
5855
6143
|
if (!bool(params, "yes")) throw new CliError("confirm", "Forgetting a group deletes its history on this device; pass --yes (yes: true over the socket) to go on");
|
|
5856
|
-
await node(ctx).forgetGroup({ groupId: group.id })
|
|
6144
|
+
await node(ctx).forgetGroup({ groupId: group.id }).catch((error) => {
|
|
6145
|
+
throw nobodyForLeave(ctx, group, str(params, "group", true), error) ?? error;
|
|
6146
|
+
});
|
|
5857
6147
|
return { forgotten: group.id };
|
|
5858
6148
|
},
|
|
5859
6149
|
async "group.accept"(ctx, params) {
|
|
@@ -5992,9 +6282,9 @@ async function guardEngineSend(ctx, method, args) {
|
|
|
5992
6282
|
...args.fields && typeof args.fields === "object" ? Object.values(args.fields) : []
|
|
5993
6283
|
];
|
|
5994
6284
|
if (method === "forwardMessages") {
|
|
5995
|
-
const ids = Array.isArray(args.messageIds) ? args.messageIds.filter((id) => typeof id === "string") : [];
|
|
6285
|
+
const ids = Array.isArray(args.messageIds) ? [...new Set(args.messageIds.filter((id) => typeof id === "string"))] : [];
|
|
5996
6286
|
const linkId = args.linkId;
|
|
5997
|
-
texts = typeof linkId === "string" && linkId ? await Promise.all(ids.map(async (id) => {
|
|
6287
|
+
texts = typeof linkId === "string" && linkId && ids.length <= 30 ? await Promise.all(ids.map(async (id) => {
|
|
5998
6288
|
const message = await node(ctx).getMessage(linkId, id);
|
|
5999
6289
|
return message && !message.file ? message.text : null;
|
|
6000
6290
|
})) : [];
|
|
@@ -6069,11 +6359,69 @@ function groupSendRefused(error) {
|
|
|
6069
6359
|
if (/^You (were removed from|left|are no longer in) this group$|Membership changes are halted/.test(error)) return new CliError("refused", error);
|
|
6070
6360
|
return new CliError("unavailable", error);
|
|
6071
6361
|
}
|
|
6362
|
+
/** The engine's admin who may not leave: the app's words say "make someone the admin", which names no command here. */
|
|
6363
|
+
var ADMIN_ALONE = "You are the admin and nobody else in the group is online to take over. Try again when a member is, or make someone the admin first.";
|
|
6364
|
+
/** A community's leave (or an admin's forget, which leaves first) with no edge to a member to carry it. */
|
|
6365
|
+
var NOBODY_FOR_LEAVE = "Nobody in the group is connected right now to take your leave. Try again in a moment.";
|
|
6366
|
+
/**
|
|
6367
|
+
* A community's leave nobody was connected to take, said with the CLI's next step: "Try again in a moment" never passed
|
|
6368
|
+
* in a one-shot, which has no edge yet when it runs, and every member is refused alike (`group admin` hands nothing on
|
|
6369
|
+
* here). The code stays the engine's. Undefined for other errors.
|
|
6370
|
+
*/
|
|
6371
|
+
function nobodyForLeave(ctx, group, ref, error) {
|
|
6372
|
+
if (!(error instanceof Error) || error.message !== NOBODY_FOR_LEAVE) return void 0;
|
|
6373
|
+
const shown = shellWord(ref, group.id), show = `ghostly group show ${shown} says who is`;
|
|
6374
|
+
return new CliError("engine", ctx.mode === "one-shot" ? `Nobody in ${groupCalled(group)} is connected to take your leave, and a command without a daemon has no connection yet: keep this profile online (ghostly daemon --detach), then ghostly group leave ${shown} --yes once a member is (${show})` : `Nobody in ${groupCalled(group)} is connected to take your leave: try again when a member is online (${show})`);
|
|
6375
|
+
}
|
|
6376
|
+
/**
|
|
6377
|
+
* `group leave` the engine refused, said with the CLI's next step: an invitation not joined yet answered "Group not
|
|
6378
|
+
* found" of a group `group show` lists (its way out is `group decline`), an admin alone online "make someone the
|
|
6379
|
+
* admin", the app's words, and a community nobody is connected to (`nobodyForLeave`). The code stays the engine's.
|
|
6380
|
+
*/
|
|
6381
|
+
function leaveRefused(ctx, group, ref, error) {
|
|
6382
|
+
if (!(error instanceof Error)) return error;
|
|
6383
|
+
const nobody = nobodyForLeave(ctx, group, ref, error);
|
|
6384
|
+
if (nobody) return nobody;
|
|
6385
|
+
const shown = shellWord(ref, group.id);
|
|
6386
|
+
if (error.message === ADMIN_ALONE) return new CliError("engine", `You are the admin and nobody else in ${groupCalled(group)} is online to take over: try again when a member is, or make one the admin first (ghostly group admin ${shown} <member key>)`);
|
|
6387
|
+
const yet = error.message === "Group not found" ? notInYet(group, ref, true) : void 0;
|
|
6388
|
+
return yet ? new CliError("engine", yet) : error;
|
|
6389
|
+
}
|
|
6390
|
+
/**
|
|
6391
|
+
* `group join` the engine refused for a group held here under the link's id, in the app's words ("Delete it from this
|
|
6392
|
+
* device", its menu item), said with the CLI's command. The code stays the engine's. "Answer it first" comes only for
|
|
6393
|
+
* an invitation taken back (a live one is kept and the link goes on beside it), which `group accept` refuses: its way
|
|
6394
|
+
* out is `group decline`.
|
|
6395
|
+
*/
|
|
6396
|
+
/**
|
|
6397
|
+
* The link `group join` takes, read before a one-shot opens the profile (`refuseBeforeStart`): one that names no group,
|
|
6398
|
+
* a private one's or a community's, is refused as the engine's `joinByLink` refuses it with the same two decoders.
|
|
6399
|
+
*/
|
|
6400
|
+
function groupLinkShape(params) {
|
|
6401
|
+
const link = str(params, "link", true);
|
|
6402
|
+
if (!decodeCommunityLink(link) && !decodeGroupEntryLink(link)) throw new CliError("bad_request", "This is not a link to a group");
|
|
6403
|
+
}
|
|
6404
|
+
function joinRefused(link, error) {
|
|
6405
|
+
if (!(error instanceof Error)) return error;
|
|
6406
|
+
const id = (decodeCommunityLink(link) ?? decodeGroupEntryLink(link))?.g ?? "<group>";
|
|
6407
|
+
if (error.message === "You are out of this group and its history is still here. Delete it from this device to join with a link.") return new CliError("engine", `You are out of this group and its history is still here: ghostly group forget ${id} --yes deletes it from this device, then join with the link`);
|
|
6408
|
+
if (error.message === "You have an invitation to this group. Answer it first.") return new CliError("engine", `Its invitation to this group was taken back: ghostly group decline ${id} drops it, then join with the link`);
|
|
6409
|
+
return error;
|
|
6410
|
+
}
|
|
6411
|
+
/**
|
|
6412
|
+
* The chat a command about a chat's own connection names (`chat connect`, `disconnect`, `transport`, `wait`): a group's
|
|
6413
|
+
* name says a group has none of its own, as `chat show` names `group show`. It read "(ghostly chat list)", a list that
|
|
6414
|
+
* never has the group.
|
|
6415
|
+
*/
|
|
6416
|
+
function chatNotGroupLink(ctx, params) {
|
|
6417
|
+
return notAGroup(ctx, params, () => chatOf(ctx, params), (shown, id) => `it connects through its members' chats, with no transport of its own (${id === void 0 ? "ghostly group list" : `ghostly group show ${shown}`})`);
|
|
6418
|
+
}
|
|
6072
6419
|
/**
|
|
6073
6420
|
* A chat command given a group's id, prefix or name: `not_found` that says it is a group, with `hint`: the group
|
|
6074
6421
|
* command that takes it (`react` on a group, where `group react` is meant), or what to do where none does. `group:<id>`,
|
|
6075
6422
|
* the form `pin` and `saved` take, is that group too (it read "No chat" before). A name no chat and no group has stays
|
|
6076
|
-
* the chat's error.
|
|
6423
|
+
* the chat's error. A name more than one group has says so too, with no `id` for `hint` (`shown` is `<group>`): the
|
|
6424
|
+
* group to name is one of theirs, by its id (`ghostly group list`).
|
|
6077
6425
|
*/
|
|
6078
6426
|
function notAGroup(ctx, params, chat, hint) {
|
|
6079
6427
|
try {
|
|
@@ -6085,16 +6433,19 @@ function notAGroup(ctx, params, chat, hint) {
|
|
|
6085
6433
|
let group;
|
|
6086
6434
|
try {
|
|
6087
6435
|
group = findGroup(state(ctx).groups, named);
|
|
6088
|
-
} catch {
|
|
6436
|
+
} catch (inner) {
|
|
6437
|
+
if (sharedGroupIds(inner)) throw new CliError("not_found", `${JSON.stringify(ref)} names more than one group, not a chat: ${hint("<group>")}`);
|
|
6089
6438
|
throw error;
|
|
6090
6439
|
}
|
|
6091
6440
|
const shown = shellWord(named, group.id);
|
|
6092
6441
|
throw new CliError("not_found", `${JSON.stringify(ref)} is a group, not a chat: ${hint(shown, group.id)}`, { group: group.id });
|
|
6093
6442
|
}
|
|
6094
6443
|
}
|
|
6444
|
+
/** Where a command offered for a name more than one group has (no `id`) finds the id of the one meant. */
|
|
6445
|
+
var byItsId = (id) => id === void 0 ? ", with the id of the group meant (ghostly group list)" : "";
|
|
6095
6446
|
/** The chat a chat command with a group twin names: a group's name says so, with `command`, the twin (see `notAGroup`). */
|
|
6096
6447
|
function chatNotGroup(ctx, params, command, rest = "") {
|
|
6097
|
-
return notAGroup(ctx, params, () => chatOf(ctx, params), (shown) => `ghostly ${command} ${shown}${rest ? ` ${rest}` : ""}`);
|
|
6448
|
+
return notAGroup(ctx, params, () => chatOf(ctx, params), (shown, id) => `ghostly ${command} ${shown}${rest ? ` ${rest}` : ""}${byItsId(id)}`);
|
|
6098
6449
|
}
|
|
6099
6450
|
/**
|
|
6100
6451
|
* An edit the engine refused. A message that is not in the chat or group at all is `not_found` (exit 3), said as every
|
|
@@ -6106,12 +6457,37 @@ function chatNotGroup(ctx, params, command, rest = "") {
|
|
|
6106
6457
|
async function editRefused(ctx, linkId, ref, place, error, result) {
|
|
6107
6458
|
if (!result.refused) return new CliError("unavailable", error);
|
|
6108
6459
|
if (result.missing ?? !await messageOf(ctx, linkId, ref)) return noMessage(ref, place);
|
|
6109
|
-
return new CliError("refused", error);
|
|
6460
|
+
return new CliError("refused", editRefusalWords(error, ref, place));
|
|
6461
|
+
}
|
|
6462
|
+
/**
|
|
6463
|
+
* The engine's refusal of an edit with what to run instead: it named none, so a bot that hit the edit cap had a sentence
|
|
6464
|
+
* and exit 1 to go on. Matched by the engine's exact words (`editMessage`, `GroupEdits.edit`); any other sentence, or
|
|
6465
|
+
* one these no longer match, stays the engine's.
|
|
6466
|
+
*/
|
|
6467
|
+
function editRefusalWords(error, ref, place) {
|
|
6468
|
+
const chat = shellWord(place.ref, place.group ? "<group>" : "<chat>"), id = shellWord(ref, "<message>");
|
|
6469
|
+
const send = `ghostly ${place.group ? "group send" : "send"} ${chat}`;
|
|
6470
|
+
if (error === "Only your own text messages can be edited") return `${error}: to answer this one, reply to it (${send} --reply ${id} <text>)`;
|
|
6471
|
+
const most = /^(This message was edited \d+ times, the most one takes)\.$/.exec(error);
|
|
6472
|
+
if (most) return `${most[1]}: send the new text as a new message (${send} <text>); ghostly message delete ${chat} ${id} --everyone takes the old one away`;
|
|
6473
|
+
if (error === "An edit cannot read as a join notice.") return "An edit cannot read as a join notice (\"👋 … joined\"): change its first words";
|
|
6474
|
+
return error;
|
|
6475
|
+
}
|
|
6476
|
+
/**
|
|
6477
|
+
* `message delete --everyone` given no message of mine. It said "No message … of yours" for all of them, as if one of
|
|
6478
|
+
* mine deleted already were the contact's: another's message says whose it is (in a chat, with the delete that takes
|
|
6479
|
+
* it off this device), one of mine deleted already says so (the chat's deleted ids), and any other is not here.
|
|
6480
|
+
*/
|
|
6481
|
+
function deleteNotMine(ctx, target, ref, theirs, place, purge) {
|
|
6482
|
+
if (theirs && target.group) return new CliError("not_found", `${JSON.stringify(ref)} is another member's message: only its author deletes a group's message, for everyone`);
|
|
6483
|
+
if (theirs) return new CliError("not_found", `${JSON.stringify(ref)} is the contact's message: only your own messages are deleted for everyone (ghostly message delete ${shellWord(place.ref, "<chat>")} ${shellWord(theirs.id, "<message>")}${purge ? " --purge" : ""} deletes it on this device)`);
|
|
6484
|
+
const deleted = !target.group && node(ctx).deletedIdsOf(target.linkId).includes(ref);
|
|
6485
|
+
return noMessage(ref, place, deleted ? { tail: ": it was deleted already" } : {});
|
|
6110
6486
|
}
|
|
6111
6487
|
/**
|
|
6112
6488
|
* About the longest ASCII text, and edit, the DHT packet carries once sealed and signed: within the 256 bytes, the
|
|
6113
6489
|
* envelope's authentication (and an edit's element) takes the rest. The edge moves by a byte or two with the chat (the
|
|
6114
|
-
* envelope's sequence, the edit's number), so the words say "about"; `
|
|
6490
|
+
* envelope's sequence, the edit's number), so the words say "about"; `dhtPacketBudget.test.ts` sends both sizes on two
|
|
6115
6491
|
* paired daemons.
|
|
6116
6492
|
*/
|
|
6117
6493
|
var DHT_TEXT_FITS = 248;
|
|
@@ -6169,7 +6545,24 @@ async function connectWithin(ctx, link, ms) {
|
|
|
6169
6545
|
} finally {
|
|
6170
6546
|
clearTimeout(timer);
|
|
6171
6547
|
}
|
|
6172
|
-
throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s:
|
|
6548
|
+
throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: ${notLiveYet(ctx, link)}. ${connectNext(ctx, link)}`, { chat: link.id });
|
|
6549
|
+
}
|
|
6550
|
+
/**
|
|
6551
|
+
* How long after a daemon's start a chat with no attempt ended yet reads as still resuming: with many chats, the start
|
|
6552
|
+
* brings them back a few at a time, over minutes.
|
|
6553
|
+
*/
|
|
6554
|
+
var RESUMING_MS = 3e5;
|
|
6555
|
+
/**
|
|
6556
|
+
* Why a daemon's `chat connect` timed out, as the chat reads at the end. No attempt of this run ended yet
|
|
6557
|
+
* (`lastAttempt` null) while the daemon just started, or while the contact reads online: the chat is still coming
|
|
6558
|
+
* back, nobody failed to answer. It said "the contact did not answer" right after a `daemon restart`, with the
|
|
6559
|
+
* contact online. A one-shot always just started: it keeps the words it had.
|
|
6560
|
+
*/
|
|
6561
|
+
function notLiveYet(ctx, link) {
|
|
6562
|
+
const now = state(ctx).links.find((l) => l.id === link.id) ?? link;
|
|
6563
|
+
if (ctx.mode !== "daemon" || now.liveAttempt) return "the contact did not answer";
|
|
6564
|
+
if (process.uptime() * 1e3 < RESUMING_MS) return "the chat is still resuming after the daemon's start, and no attempt to reach the contact has ended yet";
|
|
6565
|
+
return now.peerOnline ? "your contact's app reads online, and no attempt to reach it has ended yet" : "the contact did not answer";
|
|
6173
6566
|
}
|
|
6174
6567
|
/** What happens after a `chat connect` the contact did not answer: the daemon dials again by itself, a one-shot does not. */
|
|
6175
6568
|
function connectNext(ctx, link) {
|
|
@@ -6301,6 +6694,22 @@ function quoteChecked(json, message, originals) {
|
|
|
6301
6694
|
}
|
|
6302
6695
|
};
|
|
6303
6696
|
}
|
|
6697
|
+
/**
|
|
6698
|
+
* Each method's check of its own words, the one its handler makes first: none needs the profile. A one-shot makes it
|
|
6699
|
+
* before the profile opens (main.ts `session`): a target that is no invoice, a token or mint URL that is none, or a word
|
|
6700
|
+
* that is no group link started every saved chat to be refused (with 10 chats, 20 relay requests and 0.4 s more).
|
|
6701
|
+
*/
|
|
6702
|
+
var SHAPES = {
|
|
6703
|
+
"pay": payShape,
|
|
6704
|
+
"wallet.redeem": tokenShape,
|
|
6705
|
+
"wallet.mint.add": mintUrlShape,
|
|
6706
|
+
"group.join": groupLinkShape,
|
|
6707
|
+
"service.add": serviceShape
|
|
6708
|
+
};
|
|
6709
|
+
/** Throws what `method` answers `params` whose shape it refuses, with no profile open; nothing for any other. */
|
|
6710
|
+
async function refuseBeforeStart(method, params) {
|
|
6711
|
+
if (Object.hasOwn(SHAPES, method)) await SHAPES[method](params);
|
|
6712
|
+
}
|
|
6304
6713
|
var API_METHODS = Object.keys(METHODS);
|
|
6305
6714
|
/**
|
|
6306
6715
|
* Runs one method of the API: one the table lists itself (`constructor`, which every object has, is none). `call`: who
|
|
@@ -6312,6 +6721,6 @@ async function callApi(ctx, method, params = {}, call) {
|
|
|
6312
6721
|
if (params === null || typeof params !== "object" || Array.isArray(params)) throw new CliError("bad_request", "params must be an object");
|
|
6313
6722
|
return run(ctx, await withStoredIds(ctx, params), call);
|
|
6314
6723
|
}
|
|
6315
|
-
export {
|
|
6724
|
+
export { groupJson as _, hideStateSecrets as a, resumeHolds as b, refuseBeforeStart as c, reportAppFrames as d, servedApps as f, chatMessageJson as g, chatJson as h, groupSendRefused as i, settingsInEffect as l, identityProvider as m, SETTABLE as n, mentionsFor as o, nodeLocalFetch as p, callApi as r, redactSettings as s, API_METHODS as t, paymentJson as u, groupMessageJson as v, flushCardUpdates as x, groupPayTwins as y };
|
|
6316
6725
|
|
|
6317
|
-
//# sourceMappingURL=api-
|
|
6726
|
+
//# sourceMappingURL=api-Dz2cw7WD.js.map
|