@ghostlytools/cli 1.9.0 → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -27
- package/SKILL.md +7 -3
- package/dist/assets/api-BOWLZYXM.js +3 -0
- package/dist/assets/{api-DFCgr6RH.js → api-Bi6hCcwG.js} +100 -47
- package/dist/assets/api-Bi6hCcwG.js.map +1 -0
- package/dist/assets/{apiKit-CCavJJcl.js → apiKit-DzXHZojD.js} +26 -9
- package/dist/assets/apiKit-DzXHZojD.js.map +1 -0
- package/dist/assets/{apps-B7o2BPj6.js → apps-0Ks6KjqS.js} +1 -1
- package/dist/assets/{apps-DmxEG147.js → apps-DIQbzG08.js} +33 -10
- package/dist/assets/apps-DIQbzG08.js.map +1 -0
- package/dist/assets/{arkade-DtYR9H0c.js → arkade-zozCldAE.js} +2 -2
- package/dist/assets/{arkade-DtYR9H0c.js.map → arkade-zozCldAE.js.map} +1 -1
- package/dist/assets/{backup-YIB2XIES.js → backup-BL49Kt-T.js} +7 -6
- package/dist/assets/{backup-YIB2XIES.js.map → backup-BL49Kt-T.js.map} +1 -1
- package/dist/assets/{backup-BserdrNk.js → backup-BvIFcZM7.js} +1 -1
- package/dist/assets/bark_ffi_wasm_bg-EY2uc0Bx.js.map +1 -1
- package/dist/assets/bitcoindevkit_bg-B-iLWrmX.js.map +1 -1
- package/dist/assets/{blobFiles-DOQDRdDI.js → blobFiles-BnjN_Vrz.js} +3 -3
- package/dist/assets/{blobFiles-DOQDRdDI.js.map → blobFiles-BnjN_Vrz.js.map} +1 -1
- package/dist/assets/buttons-CAW5v5EE.js +332 -0
- package/dist/assets/buttons-CAW5v5EE.js.map +1 -0
- package/dist/assets/buttons-oJI5mHSL.js +2 -0
- package/dist/assets/childEnv-BVOQK9EA.js +21 -0
- package/dist/assets/childEnv-BVOQK9EA.js.map +1 -0
- package/dist/assets/client-CyApKBEw.js +473 -0
- package/dist/assets/client-CyApKBEw.js.map +1 -0
- package/dist/assets/codec-DqFxxB_q.js +13 -0
- package/dist/assets/codec-DqFxxB_q.js.map +1 -0
- package/dist/assets/{endpoint-BdaeBw2L.js → endpoint-DWHkXWVM.js} +101 -16
- package/dist/assets/endpoint-DWHkXWVM.js.map +1 -0
- package/dist/assets/{envelope-Dt75vrmY.js → envelope-CMUgz31I.js} +3 -12
- package/dist/assets/envelope-CMUgz31I.js.map +1 -0
- package/dist/assets/fedimint_client_wasm_bg-BtHHlFpp.js.map +1 -1
- package/dist/assets/{fileBytes-BPDKufla.js → fileBytes-DMzrIdCu.js} +1 -1
- package/dist/assets/{fileBytes-DNgrRL0R.js → fileBytes-DjBYYyXT.js} +3 -3
- package/dist/assets/{fileBytes-DNgrRL0R.js.map → fileBytes-DjBYYyXT.js.map} +1 -1
- package/dist/assets/{fileBytes-Q3ehcEr8.js → fileBytes-Douk1yOp.js} +2 -2
- package/dist/assets/{fileBytes-Q3ehcEr8.js.map → fileBytes-Douk1yOp.js.map} +1 -1
- package/dist/assets/fileBytesIdb-CD5Uv490.js +2 -0
- package/dist/assets/{fileBytesIdb-Dm1EyEbT.js → fileBytesIdb-CkClu9YI.js} +3 -3
- package/dist/assets/{fileBytesIdb-Dm1EyEbT.js.map → fileBytesIdb-CkClu9YI.js.map} +1 -1
- package/dist/assets/{fileBytesOpfs-ZGD21c4Q.js → fileBytesOpfs-WryQuOgK.js} +3 -3
- package/dist/assets/{fileBytesOpfs-ZGD21c4Q.js.map → fileBytesOpfs-WryQuOgK.js.map} +1 -1
- package/dist/assets/{fixedHosts-B598JzbC.js → fixedHosts-C2hdCfzK.js} +4 -4
- package/dist/assets/{fixedHosts-B598JzbC.js.map → fixedHosts-C2hdCfzK.js.map} +1 -1
- package/dist/assets/{groupFiles-FXel6zIc.js → groupFiles-BAQIt_bJ.js} +404 -161
- package/dist/assets/groupFiles-BAQIt_bJ.js.map +1 -0
- package/dist/assets/{host-DIBeK_c_.js → host-CaRlDMTd.js} +206 -49
- package/dist/assets/host-CaRlDMTd.js.map +1 -0
- package/dist/assets/{hyperdhtRelay-D185dETu.js → hyperdhtRelay-BxADl3SG.js} +2 -2
- package/dist/assets/{hyperdhtRelay-D185dETu.js.map → hyperdhtRelay-BxADl3SG.js.map} +1 -1
- package/dist/assets/{idb-BkOJES5_.js → idb-BHsAqENE.js} +37 -6
- package/dist/assets/idb-BHsAqENE.js.map +1 -0
- package/dist/assets/{irohWeb-BSv_BWyG.js → irohWeb-D2sh6EWp.js} +65 -7
- package/dist/assets/irohWeb-D2sh6EWp.js.map +1 -0
- package/dist/assets/{main-BbhfMTt8.js → main-Bc4Ow56Z.js} +221 -287
- package/dist/assets/main-Bc4Ow56Z.js.map +1 -0
- package/dist/assets/{mainline-9Vc3c3SA.js → mainline-DWh4Ccri.js} +2 -2
- package/dist/assets/{mainline-9Vc3c3SA.js.map → mainline-DWh4Ccri.js.map} +1 -1
- package/dist/assets/networkReason-DT_D_Wpc.js +474 -0
- package/dist/assets/networkReason-DT_D_Wpc.js.map +1 -0
- package/dist/assets/{nwc-QX3Yt1Sb.js → nwc-DoSEhUKb.js} +3 -3
- package/dist/assets/{nwc-QX3Yt1Sb.js.map → nwc-DoSEhUKb.js.map} +1 -1
- package/dist/assets/{nwcProvider-CzX3xH47.js → nwcProvider-CGWqUjpB.js} +2 -2
- package/dist/assets/{nwcProvider-CzX3xH47.js.map → nwcProvider-CGWqUjpB.js.map} +1 -1
- package/dist/assets/{ownDid-D8z5gwGI.js → ownDid-CbGjRLBn.js} +3 -3
- package/dist/assets/ownDid-CbGjRLBn.js.map +1 -0
- package/dist/assets/{profiles-MFtCmJwK.js → profiles-DgIfvBeN.js} +47 -4
- package/dist/assets/profiles-DgIfvBeN.js.map +1 -0
- package/dist/assets/{registry-B2Dtnibo.js → registry-BSyxGjN6.js} +11 -9
- package/dist/assets/registry-BSyxGjN6.js.map +1 -0
- package/dist/assets/{registry-PTtBMaYZ.js → registry-C5cn80Rw.js} +1 -1
- package/dist/assets/{resolve-ZxVzwFNA.js → resolve-D-9YRFhl.js} +2 -2
- package/dist/assets/{resolve-ZxVzwFNA.js.map → resolve-D-9YRFhl.js.map} +1 -1
- package/dist/assets/{restoredRows-BCRCjhdF.js → restoredRows-CRYwIx3g.js} +2 -2
- package/dist/assets/{restoredRows-BCRCjhdF.js.map → restoredRows-CRYwIx3g.js.map} +1 -1
- package/dist/assets/{buttons-CuRfKnPI.js → secretGuard-CSVNxXVW.js} +80 -330
- package/dist/assets/secretGuard-CSVNxXVW.js.map +1 -0
- package/dist/assets/secretGuard-Q2BKq0q0.js +2 -0
- package/dist/assets/{server-Dw1o8z1o.js → server-BufntkX8.js} +1734 -369
- package/dist/assets/server-BufntkX8.js.map +1 -0
- package/dist/assets/{src-BD8RBVEp.js → src-CCt5s4DK.js} +3073 -1890
- package/dist/assets/src-CCt5s4DK.js.map +1 -0
- package/dist/assets/{sshForges-DWrESWkK.js → sshForges-D8CPaIbR.js} +16 -9
- package/dist/assets/{sshForges-DWrESWkK.js.map → sshForges-D8CPaIbR.js.map} +1 -1
- package/dist/assets/{translate-D1uP0q32.js → translate-Cb-6hMhD.js} +17 -12
- package/dist/assets/translate-Cb-6hMhD.js.map +1 -0
- package/dist/assets/{usdt-DhVN8geQ.js → usdt-ds461mzA.js} +3 -3
- package/dist/assets/{usdt-DhVN8geQ.js.map → usdt-ds461mzA.js.map} +1 -1
- package/dist/assets/{words-DdXPkB3n.js → words-B1ylON2h.js} +4 -2
- package/dist/assets/words-B1ylON2h.js.map +1 -0
- package/dist/ghostly.mjs +1 -1
- package/package.json +1 -1
- package/dist/assets/api-DFCgr6RH.js.map +0 -1
- package/dist/assets/api-raWw9j_m.js +0 -3
- package/dist/assets/apiKit-CCavJJcl.js.map +0 -1
- package/dist/assets/apps-DmxEG147.js.map +0 -1
- package/dist/assets/buttons-CuRfKnPI.js.map +0 -1
- package/dist/assets/buttons-De3LPdSG.js +0 -2
- package/dist/assets/daemonProof-DtrL5lE5.js +0 -236
- package/dist/assets/daemonProof-DtrL5lE5.js.map +0 -1
- package/dist/assets/endpoint-BdaeBw2L.js.map +0 -1
- package/dist/assets/envelope-Dt75vrmY.js.map +0 -1
- package/dist/assets/fileBytesIdb-DZcESfTt.js +0 -2
- package/dist/assets/groupFiles-FXel6zIc.js.map +0 -1
- package/dist/assets/host-DIBeK_c_.js.map +0 -1
- package/dist/assets/idb-BkOJES5_.js.map +0 -1
- package/dist/assets/irohWeb-BSv_BWyG.js.map +0 -1
- package/dist/assets/main-BbhfMTt8.js.map +0 -1
- package/dist/assets/networkReason-BncJ9KSM.js +0 -154
- package/dist/assets/networkReason-BncJ9KSM.js.map +0 -1
- package/dist/assets/ownDid-D8z5gwGI.js.map +0 -1
- package/dist/assets/profiles-MFtCmJwK.js.map +0 -1
- package/dist/assets/registry-B2Dtnibo.js.map +0 -1
- package/dist/assets/server-Dw1o8z1o.js.map +0 -1
- package/dist/assets/src-BD8RBVEp.js.map +0 -1
- package/dist/assets/translate-D1uP0q32.js.map +0 -1
- package/dist/assets/words-DdXPkB3n.js.map +0 -1
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { Ju as randomBytes, Yu as toBase64Url, _i as BUTTONS_CAPABILITY, ao as BUTTON_STYLES, fo as STATUS_CARD_LIMITS, go as buttonLabelClash, yo as checkStatusCard } from "./src-CCt5s4DK.js";
|
|
2
|
+
import { n as secretWords, r as findSecret } from "./secretGuard-CSVNxXVW.js";
|
|
3
|
+
import { t as CliError } from "./errors-R4S2SAEM.js";
|
|
4
|
+
import { _ as oneOf, g as num, h as node, i as chatOrGroup, n as bool, p as messageOf, x as str } from "./apiKit-DzXHZojD.js";
|
|
5
|
+
import { t as goesOn$1 } from "./waitNotice-B8D8WhbE.js";
|
|
6
|
+
//#region src/waits.ts
|
|
7
|
+
var DELIVERY_RANK = {
|
|
8
|
+
sending: 0,
|
|
9
|
+
waiting: 1,
|
|
10
|
+
queued: 1,
|
|
11
|
+
held: 2,
|
|
12
|
+
sent: 2,
|
|
13
|
+
delivered: 3
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* What a timed-out wait says of what happens next: a daemon goes on, a one-shot's profile closes now. A one-shot's
|
|
17
|
+
* `edit` and `group edit` said "while this profile is online" too, as it was about to leave. Ctrl-C says the same.
|
|
18
|
+
*/
|
|
19
|
+
var goesOn = (ctx) => goesOn$1(ctx.mode);
|
|
20
|
+
/** Waits until the contact confirmed the latest edit of one of my messages (it is no longer pending). */
|
|
21
|
+
async function waitForEdit(ctx, chat, messageId, ms) {
|
|
22
|
+
const until = Date.now() + ms;
|
|
23
|
+
for (;;) {
|
|
24
|
+
const message = await node(ctx).getMessage(chat, messageId);
|
|
25
|
+
if (!message) throw new CliError("not_found", `No message ${messageId} in this chat`);
|
|
26
|
+
if (!message.edit?.pending) return message;
|
|
27
|
+
if (Date.now() >= until) throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: the contact has not confirmed the edit yet (it needs a live chat and a contact's app that shows edits). It ${goesOn(ctx)}`, {
|
|
28
|
+
messageId,
|
|
29
|
+
edits: message.edit.seq
|
|
30
|
+
});
|
|
31
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Waits until the contact confirmed my removal of a message, which is already gone here. */
|
|
35
|
+
async function waitForRemoval(ctx, chat, messageId, ms) {
|
|
36
|
+
const until = Date.now() + ms;
|
|
37
|
+
while (node(ctx).removalPending({
|
|
38
|
+
linkId: chat,
|
|
39
|
+
messageId
|
|
40
|
+
})) {
|
|
41
|
+
if (Date.now() >= until) throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: the message is gone here and the contact has not confirmed yet. Its removal ${goesOn(ctx)}`, { messageId });
|
|
42
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Waits until an edge took my group message, or its edit number `edit` (WISP 902: a group has no receipts, so this is
|
|
47
|
+
* as far as the author sees): a member's edge in a private group, an edge to one of my hubs in a community.
|
|
48
|
+
*/
|
|
49
|
+
async function waitForGroupFrame(ctx, groupId, messageId, edit, ms) {
|
|
50
|
+
const until = Date.now() + ms;
|
|
51
|
+
for (;;) {
|
|
52
|
+
const taken = node(ctx).groupTaken({
|
|
53
|
+
groupId,
|
|
54
|
+
messageId,
|
|
55
|
+
...edit ? { edit } : {}
|
|
56
|
+
});
|
|
57
|
+
if (taken > 0) return taken;
|
|
58
|
+
if (Date.now() >= until) throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: no member's edge took it yet (it stays in the group and goes when one opens). It ${goesOn(ctx)}`, {
|
|
59
|
+
messageId,
|
|
60
|
+
...edit ? { edits: edit } : {}
|
|
61
|
+
});
|
|
62
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A one-shot whose text went over the live link waits this long for its receipt before it leaves (`waitForMessage`).
|
|
67
|
+
* Left at `sent`, the engine stopping took the text for unconfirmed, the next start sent it again on the DHT, and that
|
|
68
|
+
* copy took the chat's one DHT text awaiting a receipt: a script's next one-shot send waited 30 s behind it, every 5-8
|
|
69
|
+
* messages, and the last text showed "Connection closed before receipt" though the contact had it (agents#1640).
|
|
70
|
+
*/
|
|
71
|
+
var ONE_SHOT_RECEIPT_MS = 2e3;
|
|
72
|
+
/**
|
|
73
|
+
* Waits until the contact confirmed my reaction or pin in a 1:1 chat (WISP 401): until `pending` no longer finds it in
|
|
74
|
+
* what the contact has not confirmed (`chatUnconfirmed`). It goes on the live session, a reaction also on the DHT
|
|
75
|
+
* envelopes; one not confirmed in time is kept and said again.
|
|
76
|
+
*/
|
|
77
|
+
async function waitForConfirmed(ctx, chat, what, pending, ms) {
|
|
78
|
+
const until = Date.now() + ms;
|
|
79
|
+
while (pending(node(ctx).chatUnconfirmed({ linkId: chat }))) {
|
|
80
|
+
if (Date.now() >= until) throw new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: the contact has not confirmed the ${what} yet. It is kept here and ${goesOn(ctx)}`, { chat });
|
|
81
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Waits until a message of mine reached `target` (`sent`: on its way to the contact; `delivered`: acknowledged). A
|
|
86
|
+
* one-shot's text sent over the live link waits a moment more for its receipt (`ONE_SHOT_RECEIPT_MS`).
|
|
87
|
+
*/
|
|
88
|
+
async function waitForMessage(ctx, chat, messageId, target, ms) {
|
|
89
|
+
const reached = await waitForDelivery(ctx, chat, messageId, target, ms);
|
|
90
|
+
if (ctx.mode !== "one-shot" || target !== "sent" || reached.delivery !== "sent" || reached.via !== "datalink") return reached;
|
|
91
|
+
return waitForDelivery(ctx, chat, messageId, "delivered", ONE_SHOT_RECEIPT_MS).catch(async () => await node(ctx).getMessage(chat, messageId) ?? reached);
|
|
92
|
+
}
|
|
93
|
+
async function waitForDelivery(ctx, chat, messageId, target, ms) {
|
|
94
|
+
const want = DELIVERY_RANK[target];
|
|
95
|
+
const look = (message) => {
|
|
96
|
+
if (!message) return void 0;
|
|
97
|
+
const delivery = message.delivery ?? "sent";
|
|
98
|
+
if (delivery === "failed") throw new CliError("engine", message.deliveryError ?? "The message could not be sent", {
|
|
99
|
+
messageId,
|
|
100
|
+
delivery
|
|
101
|
+
});
|
|
102
|
+
return (DELIVERY_RANK[delivery] ?? 0) >= want ? message : void 0;
|
|
103
|
+
};
|
|
104
|
+
return new Promise((resolve, reject) => {
|
|
105
|
+
let settled = false;
|
|
106
|
+
const finish = (error, message) => {
|
|
107
|
+
if (settled) return;
|
|
108
|
+
settled = true;
|
|
109
|
+
clearTimeout(timer);
|
|
110
|
+
off();
|
|
111
|
+
if (error) reject(error);
|
|
112
|
+
else resolve(message);
|
|
113
|
+
};
|
|
114
|
+
const check = (last = false) => void node(ctx).getMessage(chat, messageId).then((message) => {
|
|
115
|
+
try {
|
|
116
|
+
const done = look(message);
|
|
117
|
+
if (done) finish(null, done);
|
|
118
|
+
else if (last) finish(new CliError("timeout", `Timed out after ${Math.round(ms / 1e3)} s: the message is ${message?.delivery ?? "not sent yet"} and ${goesOn(ctx)}`, {
|
|
119
|
+
messageId,
|
|
120
|
+
delivery: message?.delivery ?? null
|
|
121
|
+
}));
|
|
122
|
+
} catch (error) {
|
|
123
|
+
finish(error);
|
|
124
|
+
}
|
|
125
|
+
}, finish);
|
|
126
|
+
const timer = setTimeout(() => check(true), ms);
|
|
127
|
+
const off = ctx.hub.onEvent((event) => {
|
|
128
|
+
if (event.chat === chat && (event.messageId === messageId || event.message?.id === messageId)) check();
|
|
129
|
+
});
|
|
130
|
+
check();
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/buttons.ts
|
|
135
|
+
/**
|
|
136
|
+
* `--button id:Label` (again for each, 1 to 6), `--style id=primary|neutral|danger`, `--once` and `--id`, as the
|
|
137
|
+
* method's parameters: `buttons` and `buttonsId`. Nothing when no `--button` is given. The label may hold colons: the
|
|
138
|
+
* id ends at the first one. An id given twice, two labels that read the same (ignoring case and spaces at the ends), a
|
|
139
|
+
* label that is another button's id, or a style not listed are a usage error here, before the profile opens; other
|
|
140
|
+
* bounds (ids, labels, how many) are the card's, checked when it is sent.
|
|
141
|
+
*/
|
|
142
|
+
function buttonsOf(options) {
|
|
143
|
+
const given = Array.isArray(options.button) ? options.button : [];
|
|
144
|
+
if (!given.length) {
|
|
145
|
+
for (const flag of [
|
|
146
|
+
"style",
|
|
147
|
+
"once",
|
|
148
|
+
"id"
|
|
149
|
+
]) if (options[flag] !== void 0) throw new CliError("usage", `--${flag} goes with --button id:Label`);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const buttons = given.map((value) => {
|
|
153
|
+
const colon = value.indexOf(":");
|
|
154
|
+
if (colon < 1 || colon === value.length - 1) throw new CliError("usage", `--button takes id:Label, like yes:Yes, not ${JSON.stringify(value)}`);
|
|
155
|
+
return {
|
|
156
|
+
id: value.slice(0, colon),
|
|
157
|
+
label: value.slice(colon + 1).trim()
|
|
158
|
+
};
|
|
159
|
+
});
|
|
160
|
+
const twice = buttons.findIndex((button, at) => buttons.findIndex((other) => other.id === button.id) !== at);
|
|
161
|
+
if (twice !== -1) throw new CliError("usage", `--button ${JSON.stringify(given[twice])} repeats the id ${JSON.stringify(buttons[twice].id)}: each button takes its own`);
|
|
162
|
+
const clash = buttonLabelClash(buttons);
|
|
163
|
+
if (clash) {
|
|
164
|
+
const [at, other] = [JSON.stringify(given[clash.at]), JSON.stringify(given[clash.with])];
|
|
165
|
+
throw new CliError("usage", clash.kind === "label" ? `--button ${at} repeats the label of --button ${other} (ignoring case and spaces): a typed answer could not tell them apart` : `--button ${at} has a label that is the id of --button ${other}: a typed answer could not tell them apart`);
|
|
166
|
+
}
|
|
167
|
+
for (const value of Array.isArray(options.style) ? options.style : []) {
|
|
168
|
+
const eq = value.indexOf("=");
|
|
169
|
+
const button = eq > 0 ? buttons.find((b) => b.id === value.slice(0, eq)) : void 0;
|
|
170
|
+
if (!button) throw new CliError("usage", `--style takes id=primary|neutral|danger for one of the buttons, not ${JSON.stringify(value)}`);
|
|
171
|
+
const style = value.slice(eq + 1);
|
|
172
|
+
if (!BUTTON_STYLES.includes(style)) throw new CliError("usage", `--style ${JSON.stringify(value)}: a button's style is ${BUTTON_STYLES.join(", ")}`);
|
|
173
|
+
button.style = style;
|
|
174
|
+
}
|
|
175
|
+
if (options.once === true) for (const button of buttons) button.once = true;
|
|
176
|
+
return {
|
|
177
|
+
buttons,
|
|
178
|
+
...options.id !== void 0 && { buttonsId: String(options.id) }
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/** A buttons card checked by the sender's rule, or a `bad_request` that says what is wrong. */
|
|
182
|
+
function checked(card) {
|
|
183
|
+
const result = checkStatusCard(card);
|
|
184
|
+
if ("error" in result) throw new CliError("bad_request", `Buttons: ${result.error}`, { card });
|
|
185
|
+
return result.card;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The card a send's `buttons` (and `buttonsId`) make, or undefined when it names none. `buttons` is a list of
|
|
189
|
+
* `{id, label, style?, once?}`; the id of the question is made up (`ask-…`) unless given.
|
|
190
|
+
*/
|
|
191
|
+
function buttonsCard(params) {
|
|
192
|
+
const buttons = params.buttons;
|
|
193
|
+
if (buttons === void 0 || buttons === null) {
|
|
194
|
+
if (params.buttonsId !== void 0) throw new CliError("bad_request", "buttonsId goes with buttons");
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (!Array.isArray(buttons)) throw new CliError("bad_request", "buttons must be a list of {id, label, style?, once?}");
|
|
198
|
+
return checked({
|
|
199
|
+
kind: "buttons",
|
|
200
|
+
id: str(params, "buttonsId") ?? `ask-${toBase64Url(randomBytes(6))}`,
|
|
201
|
+
buttons
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/** Whether a 1:1 contact's app shows and presses buttons: null until its app said what it offers. */
|
|
205
|
+
function pressable(link) {
|
|
206
|
+
const peer = link.sessionOffers?.peer;
|
|
207
|
+
return peer ? peer.includes(BUTTONS_CAPABILITY) : null;
|
|
208
|
+
}
|
|
209
|
+
/** The message of mine with buttons that `button update` names, by its id here (or the id both sides know). */
|
|
210
|
+
function buttonsMessage(message, ref, group) {
|
|
211
|
+
if (!message) throw new CliError("not_found", `No message ${JSON.stringify(ref)} of yours in this ${group ? "group" : "chat"}: the messageId send gave`);
|
|
212
|
+
if (message.card?.kind !== "buttons") throw new CliError("bad_request", "That message has no buttons: send one with send --button id:Label");
|
|
213
|
+
return message;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* `button update`: the answer shown on a question's buttons (`chosen`), the buttons closed (`close`), or a new text
|
|
217
|
+
* (`text`), by editing the message with the same buttons. What is not given stays as it was.
|
|
218
|
+
*/
|
|
219
|
+
async function updateButtons(ctx, params) {
|
|
220
|
+
const target = chatOrGroup(ctx, str(params, "chat", true));
|
|
221
|
+
const ref = str(params, "message", true);
|
|
222
|
+
const chosen = str(params, "chosen");
|
|
223
|
+
const close = bool(params, "close");
|
|
224
|
+
const newText = str(params, "text");
|
|
225
|
+
if (chosen === void 0 && !close && newText === void 0) throw new CliError("bad_request", "Nothing to update: give chosen, close or text");
|
|
226
|
+
if (newText !== void 0 && !bool(params, "force")) {
|
|
227
|
+
const secret = findSecret(newText);
|
|
228
|
+
if (secret) throw new CliError("confirm", `The text looks like ${secretWords(secret)}; update with --force if you mean to`, { kind: secret.kind });
|
|
229
|
+
}
|
|
230
|
+
const message = buttonsMessage(await messageOf(ctx, target.linkId, ref, (m) => m.sender === "me"), ref, target.group);
|
|
231
|
+
if ((message.edit?.seq ?? 0) >= STATUS_CARD_LIMITS.edits) throw new CliError("refused", `This message took ${STATUS_CARD_LIMITS.edits} updates, the most one takes: ask again with a new send`, {
|
|
232
|
+
messageId: message.id,
|
|
233
|
+
edits: message.edit.seq
|
|
234
|
+
});
|
|
235
|
+
const before = message.card;
|
|
236
|
+
if (chosen !== void 0 && !before.buttons.some((b) => b.id === chosen)) throw new CliError("bad_request", `That message has no button ${JSON.stringify(chosen)}; its buttons: ${before.buttons.map((b) => b.id).join(", ")}`, { card: before });
|
|
237
|
+
const card = checked({
|
|
238
|
+
...before,
|
|
239
|
+
...chosen !== void 0 && { chosen },
|
|
240
|
+
...(close || before.closed) && { closed: true }
|
|
241
|
+
});
|
|
242
|
+
const text = newText ?? message.text;
|
|
243
|
+
const wait = oneOf(params, "wait", target.group ? ["none", "sent"] : ["none", "confirmed"], "none");
|
|
244
|
+
const ms = num(params, "timeout", 30, {
|
|
245
|
+
min: 1,
|
|
246
|
+
max: 3600
|
|
247
|
+
}) * 1e3;
|
|
248
|
+
const result = await node(ctx).editMessage({
|
|
249
|
+
linkId: target.linkId,
|
|
250
|
+
messageId: message.id,
|
|
251
|
+
text,
|
|
252
|
+
card
|
|
253
|
+
});
|
|
254
|
+
if (result.error) throw new CliError(result.refused ? "refused" : "unavailable", result.error);
|
|
255
|
+
let edited = await node(ctx).getMessage(target.linkId, message.id);
|
|
256
|
+
if (wait === "confirmed" && edited?.edit?.pending) edited = await waitForEdit(ctx, target.linkId, message.id, ms);
|
|
257
|
+
const edges = wait === "sent" && edited?.edit ? await waitForGroupFrame(ctx, target.id, message.id, edited.edit.seq, ms) : void 0;
|
|
258
|
+
return {
|
|
259
|
+
[target.group ? "group" : "chat"]: target.id,
|
|
260
|
+
buttons: card.id,
|
|
261
|
+
messageId: message.id,
|
|
262
|
+
card,
|
|
263
|
+
edits: edited?.edit?.seq ?? 0,
|
|
264
|
+
...target.group ? { ...edges !== void 0 && { edges } } : { confirmed: !!edited && !edited.edit?.pending }
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* `button press`: the other side of a question, as the app's tap: a press on a button of someone else's message, by
|
|
269
|
+
* its id here (or the id both sides know). The engine sends a reply whose text is the button's label, and refuses what
|
|
270
|
+
* an app would: a button the message does not have, closed buttons, a second answer past `once`, a second press
|
|
271
|
+
* within a second. A one-shot in a chat waits until the press went out, as `send` does.
|
|
272
|
+
*/
|
|
273
|
+
async function pressButton(ctx, params) {
|
|
274
|
+
const target = chatOrGroup(ctx, str(params, "chat", true));
|
|
275
|
+
const ref = str(params, "message", true);
|
|
276
|
+
const buttonId = str(params, "button", true);
|
|
277
|
+
const where = target.group ? "group" : "chat";
|
|
278
|
+
const message = await messageOf(ctx, target.linkId, ref, (m) => m.sender !== "me");
|
|
279
|
+
if (!message) throw new CliError("not_found", `No message ${JSON.stringify(ref)} from someone else in this ${where}: the id its event or history gave`);
|
|
280
|
+
if (message.card?.kind !== "buttons") throw new CliError("bad_request", "That message has no buttons");
|
|
281
|
+
const button = message.card.buttons.find((b) => b.id === buttonId);
|
|
282
|
+
if (!button) throw new CliError("not_found", `That message has no button ${JSON.stringify(buttonId)}; its buttons: ${message.card.buttons.map((b) => b.id).join(", ")}`);
|
|
283
|
+
const wait = target.group ? oneOf(params, "wait", ["none", "sent"], "none") : oneOf(params, "wait", [
|
|
284
|
+
"none",
|
|
285
|
+
"sent",
|
|
286
|
+
"delivered"
|
|
287
|
+
], ctx.mode === "one-shot" ? "sent" : "none");
|
|
288
|
+
const ms = num(params, "timeout", 30, {
|
|
289
|
+
min: 1,
|
|
290
|
+
max: 3600
|
|
291
|
+
}) * 1e3;
|
|
292
|
+
const result = await node(ctx).pressButton({
|
|
293
|
+
linkId: target.linkId,
|
|
294
|
+
messageId: message.id,
|
|
295
|
+
buttonId
|
|
296
|
+
});
|
|
297
|
+
if (result.error) throw new CliError(result.refused ? "refused" : "unavailable", result.error, result.paced ? { paced: true } : void 0);
|
|
298
|
+
const replyId = result.messageId ?? null;
|
|
299
|
+
const answer = {
|
|
300
|
+
[where]: target.id,
|
|
301
|
+
messageId: message.id,
|
|
302
|
+
button: button.id,
|
|
303
|
+
label: button.label,
|
|
304
|
+
replyId
|
|
305
|
+
};
|
|
306
|
+
if (!replyId) return answer;
|
|
307
|
+
if (target.group) {
|
|
308
|
+
const edges = wait === "sent" ? await waitForGroupFrame(ctx, target.id, replyId, void 0, ms) : node(ctx).groupTaken({
|
|
309
|
+
groupId: target.id,
|
|
310
|
+
messageId: replyId
|
|
311
|
+
});
|
|
312
|
+
return {
|
|
313
|
+
...answer,
|
|
314
|
+
edges
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
const reply = wait === "none" ? await node(ctx).getMessage(target.linkId, replyId) : await waitForMessage(ctx, target.linkId, replyId, wait, ms);
|
|
318
|
+
return {
|
|
319
|
+
...answer,
|
|
320
|
+
delivery: reply?.delivery ?? null
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
var BUTTON_METHODS = {
|
|
324
|
+
/** WISP 406 · Message Buttons: a press on a button of someone else's message, as the app's tap. */
|
|
325
|
+
"button.press": pressButton,
|
|
326
|
+
/** WISP 406 · Message Buttons: the answer chosen on a question of mine, its buttons closed, or its text changed. */
|
|
327
|
+
"button.update": updateButtons
|
|
328
|
+
};
|
|
329
|
+
//#endregion
|
|
330
|
+
export { waitForConfirmed as a, waitForMessage as c, pressable as i, waitForRemoval as l, buttonsCard as n, waitForEdit as o, buttonsOf as r, waitForGroupFrame as s, BUTTON_METHODS as t };
|
|
331
|
+
|
|
332
|
+
//# sourceMappingURL=buttons-CAW5v5EE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buttons-CAW5v5EE.js","names":["goesOnIn"],"sources":["../../src/waits.ts","../../src/buttons.ts"],"sourcesContent":["import type { StoredMessage } from \"@ghostly/browser/shared/types\";\nimport { node, type ApiContext } from \"./apiKit\";\nimport { CliError } from \"./errors\";\nimport type { GhostlyEvent } from \"./events\";\nimport { goesOn as goesOnIn } from \"./waitNotice\";\n\n/*\n * Waiting on what a command sent (WISP 1100): a message's delivery, an edit's confirmation, a group frame taken by an\n * edge. Shared by the chat, group and status card methods.\n */\n\nconst DELIVERY_RANK: Record<string, number> = { sending: 0, waiting: 1, queued: 1, held: 2, sent: 2, delivered: 3 };\n\n/**\n * What a timed-out wait says of what happens next: a daemon goes on, a one-shot's profile closes now. A one-shot's\n * `edit` and `group edit` said \"while this profile is online\" too, as it was about to leave. Ctrl-C says the same.\n */\nconst goesOn = (ctx: ApiContext) => goesOnIn(ctx.mode);\n\n/** Waits until the contact confirmed the latest edit of one of my messages (it is no longer pending). */\nexport async function waitForEdit(ctx: ApiContext, chat: string, messageId: string, ms: number): Promise<StoredMessage> {\n const until = Date.now() + ms;\n for (;;) {\n const message = await node(ctx).getMessage(chat, messageId);\n if (!message) throw new CliError(\"not_found\", `No message ${messageId} in this chat`);\n if (!message.edit?.pending) return message;\n if (Date.now() >= until) throw new CliError(\"timeout\", `Timed out after ${Math.round(ms / 1000)} s: the contact has not confirmed the edit yet (it needs a live chat and a contact's app that shows edits). It ${goesOn(ctx)}`, { messageId, edits: message.edit.seq });\n await new Promise((resolve) => setTimeout(resolve, 250));\n }\n}\n\n/** Waits until the contact confirmed my removal of a message, which is already gone here. */\nexport async function waitForRemoval(ctx: ApiContext, chat: string, messageId: string, ms: number): Promise<void> {\n const until = Date.now() + ms;\n while (node(ctx).removalPending({ linkId: chat, messageId })) {\n if (Date.now() >= until) throw new CliError(\"timeout\", `Timed out after ${Math.round(ms / 1000)} s: the message is gone here and the contact has not confirmed yet. Its removal ${goesOn(ctx)}`, { messageId });\n await new Promise((resolve) => setTimeout(resolve, 250));\n }\n}\n\n/**\n * Waits until an edge took my group message, or its edit number `edit` (WISP 902: a group has no receipts, so this is\n * as far as the author sees): a member's edge in a private group, an edge to one of my hubs in a community.\n */\nexport async function waitForGroupFrame(ctx: ApiContext, groupId: string, messageId: string, edit: number | undefined, ms: number): Promise<number> {\n const until = Date.now() + ms;\n for (;;) {\n const taken = node(ctx).groupTaken({ groupId, messageId, ...(edit ? { edit } : {}) });\n if (taken > 0) return taken;\n if (Date.now() >= until) throw new CliError(\"timeout\", `Timed out after ${Math.round(ms / 1000)} s: no member's edge took it yet (it stays in the group and goes when one opens). It ${goesOn(ctx)}`, { messageId, ...(edit ? { edits: edit } : {}) });\n await new Promise((resolve) => setTimeout(resolve, 250));\n }\n}\n\n/**\n * A one-shot whose text went over the live link waits this long for its receipt before it leaves (`waitForMessage`).\n * Left at `sent`, the engine stopping took the text for unconfirmed, the next start sent it again on the DHT, and that\n * copy took the chat's one DHT text awaiting a receipt: a script's next one-shot send waited 30 s behind it, every 5-8\n * messages, and the last text showed \"Connection closed before receipt\" though the contact had it (agents#1640).\n */\nexport const ONE_SHOT_RECEIPT_MS = 2_000;\n\n/**\n * Waits until the contact confirmed my reaction or pin in a 1:1 chat (WISP 401): until `pending` no longer finds it in\n * what the contact has not confirmed (`chatUnconfirmed`). It goes on the live session, a reaction also on the DHT\n * envelopes; one not confirmed in time is kept and said again.\n */\nexport async function waitForConfirmed(ctx: ApiContext, chat: string, what: \"reaction\" | \"pin\", pending: (left: { reactions: number[]; pin: number | null }) => boolean, ms: number): Promise<void> {\n const until = Date.now() + ms;\n while (pending(node(ctx).chatUnconfirmed({ linkId: chat }))) {\n if (Date.now() >= until) throw new CliError(\"timeout\", `Timed out after ${Math.round(ms / 1000)} s: the contact has not confirmed the ${what} yet. It is kept here and ${goesOn(ctx)}`, { chat });\n await new Promise((resolve) => setTimeout(resolve, 250));\n }\n}\n\n/**\n * Waits until a message of mine reached `target` (`sent`: on its way to the contact; `delivered`: acknowledged). A\n * one-shot's text sent over the live link waits a moment more for its receipt (`ONE_SHOT_RECEIPT_MS`).\n */\nexport async function waitForMessage(ctx: ApiContext, chat: string, messageId: string, target: \"sent\" | \"delivered\", ms: number): Promise<StoredMessage> {\n const reached = await waitForDelivery(ctx, chat, messageId, target, ms);\n if (ctx.mode !== \"one-shot\" || target !== \"sent\" || reached.delivery !== \"sent\" || reached.via !== \"datalink\") return reached;\n return waitForDelivery(ctx, chat, messageId, \"delivered\", ONE_SHOT_RECEIPT_MS).catch(async () => (await node(ctx).getMessage(chat, messageId)) ?? reached);\n}\n\nasync function waitForDelivery(ctx: ApiContext, chat: string, messageId: string, target: \"sent\" | \"delivered\", ms: number): Promise<StoredMessage> {\n const want = DELIVERY_RANK[target];\n const look = (message: StoredMessage | undefined) => {\n if (!message) return undefined;\n const delivery = message.delivery ?? \"sent\";\n if (delivery === \"failed\") throw new CliError(\"engine\", message.deliveryError ?? \"The message could not be sent\", { messageId, delivery });\n return (DELIVERY_RANK[delivery] ?? 0) >= want ? message : undefined;\n };\n return new Promise<StoredMessage>((resolve, reject) => {\n let settled = false;\n const finish = (error: unknown, message?: StoredMessage) => {\n if (settled) return;\n settled = true; clearTimeout(timer); off();\n if (error) reject(error); else resolve(message!);\n };\n const check = (last = false) => void node(ctx).getMessage(chat, messageId).then((message) => {\n try {\n const done = look(message);\n if (done) finish(null, done);\n else if (last) finish(new CliError(\"timeout\", `Timed out after ${Math.round(ms / 1000)} s: the message is ${message?.delivery ?? \"not sent yet\"} and ${goesOn(ctx)}`, { messageId, delivery: message?.delivery ?? null }));\n } catch (error) { finish(error); }\n }, finish);\n const timer = setTimeout(() => check(true), ms);\n // Any event naming the message: a message first seen already delivered comes as `message.sent`, never as\n // `message.delivery`. Listening before the first read leaves no gap for a change to slip through.\n const off = ctx.hub.onEvent((event: GhostlyEvent) => {\n if (event.chat === chat && (event.messageId === messageId || (event.message as { id?: string } | undefined)?.id === messageId)) check();\n });\n check();\n });\n}\n","import { BUTTONS_CAPABILITY, BUTTON_STYLES, STATUS_CARD_LIMITS, buttonLabelClash, checkStatusCard, randomBytes, toBase64Url, type ButtonsCard } from \"@ghostly/core\";\nimport type { LinkView, StoredMessage } from \"@ghostly/browser/shared/types\";\nimport type { Parsed } from \"./args\";\nimport { bool, chatOrGroup, messageOf, node, num, oneOf, str, type Method, type Params } from \"./apiKit\";\nimport { CliError } from \"./errors\";\nimport { findSecret, secretWords } from \"./secretGuard\";\nimport { waitForEdit, waitForGroupFrame, waitForMessage } from \"./waits\";\n\n/*\n * Message buttons (WISP 406 · Message Buttons), the bot's side: a message whose text is the question, with up to six\n * buttons under it (`send --button yes:Yes`). A press comes back as a reply whose text is the button's label; the\n * engine marks it (`press`) and `listen` says `button.pressed`. `button update` then shows the answer (`chosen`) and\n * closes the buttons, by editing the message with the same buttons.\n */\n\n/**\n * `--button id:Label` (again for each, 1 to 6), `--style id=primary|neutral|danger`, `--once` and `--id`, as the\n * method's parameters: `buttons` and `buttonsId`. Nothing when no `--button` is given. The label may hold colons: the\n * id ends at the first one. An id given twice, two labels that read the same (ignoring case and spaces at the ends), a\n * label that is another button's id, or a style not listed are a usage error here, before the profile opens; other\n * bounds (ids, labels, how many) are the card's, checked when it is sent.\n */\nexport function buttonsOf(options: Parsed[\"options\"]): { buttons: Record<string, unknown>[]; buttonsId?: string } | undefined {\n const given = Array.isArray(options.button) ? options.button as string[] : [];\n if (!given.length) {\n for (const flag of [\"style\", \"once\", \"id\"] as const)\n if (options[flag] !== undefined) throw new CliError(\"usage\", `--${flag} goes with --button id:Label`);\n return undefined;\n }\n const buttons: Record<string, unknown>[] = given.map((value) => {\n const colon = value.indexOf(\":\");\n if (colon < 1 || colon === value.length - 1) throw new CliError(\"usage\", `--button takes id:Label, like yes:Yes, not ${JSON.stringify(value)}`);\n return { id: value.slice(0, colon), label: value.slice(colon + 1).trim() };\n });\n const twice = buttons.findIndex((button, at) => buttons.findIndex((other) => other.id === button.id) !== at);\n if (twice !== -1) throw new CliError(\"usage\", `--button ${JSON.stringify(given[twice])} repeats the id ${JSON.stringify(buttons[twice].id)}: each button takes its own`);\n // Two buttons a typed answer could not tell apart: the same label, or a label that is another's id (ignoring case).\n const clash = buttonLabelClash(buttons);\n if (clash) {\n const [at, other] = [JSON.stringify(given[clash.at]), JSON.stringify(given[clash.with])];\n throw new CliError(\"usage\", clash.kind === \"label\"\n ? `--button ${at} repeats the label of --button ${other} (ignoring case and spaces): a typed answer could not tell them apart`\n : `--button ${at} has a label that is the id of --button ${other}: a typed answer could not tell them apart`);\n }\n for (const value of Array.isArray(options.style) ? options.style as string[] : []) {\n const eq = value.indexOf(\"=\");\n const button = eq > 0 ? buttons.find((b) => b.id === value.slice(0, eq)) : undefined;\n if (!button) throw new CliError(\"usage\", `--style takes id=primary|neutral|danger for one of the buttons, not ${JSON.stringify(value)}`);\n const style = value.slice(eq + 1);\n if (!(BUTTON_STYLES as readonly string[]).includes(style)) throw new CliError(\"usage\", `--style ${JSON.stringify(value)}: a button's style is ${BUTTON_STYLES.join(\", \")}`);\n button.style = style;\n }\n if (options.once === true) for (const button of buttons) button.once = true;\n return { buttons, ...(options.id !== undefined && { buttonsId: String(options.id) }) };\n}\n\n/** A buttons card checked by the sender's rule, or a `bad_request` that says what is wrong. */\nfunction checked(card: Record<string, unknown>): ButtonsCard {\n const result = checkStatusCard(card);\n if (\"error\" in result) throw new CliError(\"bad_request\", `Buttons: ${result.error}`, { card });\n return result.card as ButtonsCard;\n}\n\n/**\n * The card a send's `buttons` (and `buttonsId`) make, or undefined when it names none. `buttons` is a list of\n * `{id, label, style?, once?}`; the id of the question is made up (`ask-…`) unless given.\n */\nexport function buttonsCard(params: Params): ButtonsCard | undefined {\n const buttons = params.buttons;\n if (buttons === undefined || buttons === null) {\n if (params.buttonsId !== undefined) throw new CliError(\"bad_request\", \"buttonsId goes with buttons\");\n return undefined;\n }\n if (!Array.isArray(buttons)) throw new CliError(\"bad_request\", \"buttons must be a list of {id, label, style?, once?}\");\n const id = str(params, \"buttonsId\") ?? `ask-${toBase64Url(randomBytes(6))}`;\n return checked({ kind: \"buttons\", id, buttons });\n}\n\n/** Whether a 1:1 contact's app shows and presses buttons: null until its app said what it offers. */\nexport function pressable(link: LinkView): boolean | null {\n const peer = link.sessionOffers?.peer;\n return peer ? peer.includes(BUTTONS_CAPABILITY) : null;\n}\n\n/** The message of mine with buttons that `button update` names, by its id here (or the id both sides know). */\nfunction buttonsMessage(message: StoredMessage | undefined, ref: string, group: boolean): StoredMessage & { card: ButtonsCard } {\n if (!message) throw new CliError(\"not_found\", `No message ${JSON.stringify(ref)} of yours in this ${group ? \"group\" : \"chat\"}: the messageId send gave`);\n if (message.card?.kind !== \"buttons\") throw new CliError(\"bad_request\", \"That message has no buttons: send one with send --button id:Label\");\n return message as StoredMessage & { card: ButtonsCard };\n}\n\n/**\n * `button update`: the answer shown on a question's buttons (`chosen`), the buttons closed (`close`), or a new text\n * (`text`), by editing the message with the same buttons. What is not given stays as it was.\n */\nasync function updateButtons(ctx: Parameters<Method>[0], params: Params): Promise<Record<string, unknown>> {\n const target = chatOrGroup(ctx, str(params, \"chat\", true));\n const ref = str(params, \"message\", true);\n const chosen = str(params, \"chosen\");\n const close = bool(params, \"close\");\n const newText = str(params, \"text\");\n if (chosen === undefined && !close && newText === undefined) throw new CliError(\"bad_request\", \"Nothing to update: give chosen, close or text\");\n // A new text is a message like any other: the same guard as `send` and `edit`.\n if (newText !== undefined && !bool(params, \"force\")) {\n const secret = findSecret(newText);\n if (secret) throw new CliError(\"confirm\", `The text looks like ${secretWords(secret)}; update with --force if you mean to`, { kind: secret.kind });\n }\n const message = buttonsMessage(await messageOf(ctx, target.linkId, ref, (m) => m.sender === \"me\"), ref, target.group);\n if ((message.edit?.seq ?? 0) >= STATUS_CARD_LIMITS.edits)\n throw new CliError(\"refused\", `This message took ${STATUS_CARD_LIMITS.edits} updates, the most one takes: ask again with a new send`, { messageId: message.id, edits: message.edit!.seq });\n const before = message.card;\n // Said here, with the buttons it has, as a press says it: the card's own check names only the field.\n if (chosen !== undefined && !before.buttons.some((b) => b.id === chosen))\n throw new CliError(\"bad_request\", `That message has no button ${JSON.stringify(chosen)}; its buttons: ${before.buttons.map((b) => b.id).join(\", \")}`, { card: before });\n const card = checked({ ...before, ...(chosen !== undefined && { chosen }), ...((close || before.closed) && { closed: true }) });\n const text = newText ?? message.text;\n const wait = oneOf(params, \"wait\", target.group ? [\"none\", \"sent\"] as const : [\"none\", \"confirmed\"] as const, \"none\");\n const ms = num(params, \"timeout\", 30, { min: 1, max: 3600 }) * 1000;\n const result = await node(ctx).editMessage({ linkId: target.linkId, messageId: message.id, text, card });\n if (result.error) throw new CliError(result.refused ? \"refused\" : \"unavailable\", result.error);\n let edited = await node(ctx).getMessage(target.linkId, message.id);\n if (wait === \"confirmed\" && edited?.edit?.pending) edited = await waitForEdit(ctx, target.linkId, message.id, ms);\n const edges = wait === \"sent\" && edited?.edit ? await waitForGroupFrame(ctx, target.id, message.id, edited.edit.seq, ms) : undefined;\n return {\n [target.group ? \"group\" : \"chat\"]: target.id, buttons: card.id, messageId: message.id, card, edits: edited?.edit?.seq ?? 0,\n ...(target.group ? { ...(edges !== undefined && { edges }) } : { confirmed: !!edited && !edited.edit?.pending }),\n };\n}\n\n/**\n * `button press`: the other side of a question, as the app's tap: a press on a button of someone else's message, by\n * its id here (or the id both sides know). The engine sends a reply whose text is the button's label, and refuses what\n * an app would: a button the message does not have, closed buttons, a second answer past `once`, a second press\n * within a second. A one-shot in a chat waits until the press went out, as `send` does.\n */\nasync function pressButton(ctx: Parameters<Method>[0], params: Params): Promise<Record<string, unknown>> {\n const target = chatOrGroup(ctx, str(params, \"chat\", true));\n const ref = str(params, \"message\", true);\n const buttonId = str(params, \"button\", true);\n const where = target.group ? \"group\" : \"chat\";\n const message = await messageOf(ctx, target.linkId, ref, (m) => m.sender !== \"me\");\n if (!message) throw new CliError(\"not_found\", `No message ${JSON.stringify(ref)} from someone else in this ${where}: the id its event or history gave`);\n if (message.card?.kind !== \"buttons\") throw new CliError(\"bad_request\", \"That message has no buttons\");\n const button = message.card.buttons.find((b) => b.id === buttonId);\n if (!button) throw new CliError(\"not_found\", `That message has no button ${JSON.stringify(buttonId)}; its buttons: ${message.card.buttons.map((b) => b.id).join(\", \")}`);\n const wait = target.group\n ? oneOf(params, \"wait\", [\"none\", \"sent\"] as const, \"none\")\n : oneOf(params, \"wait\", [\"none\", \"sent\", \"delivered\"] as const, ctx.mode === \"one-shot\" ? \"sent\" : \"none\");\n const ms = num(params, \"timeout\", 30, { min: 1, max: 3600 }) * 1000;\n const result = await node(ctx).pressButton({ linkId: target.linkId, messageId: message.id, buttonId });\n if (result.error) throw new CliError(result.refused ? \"refused\" : \"unavailable\", result.error, result.paced ? { paced: true } : undefined);\n const replyId = result.messageId ?? null;\n const answer = { [where]: target.id, messageId: message.id, button: button.id, label: button.label, replyId };\n if (!replyId) return answer;\n if (target.group) {\n const edges = wait === \"sent\" ? await waitForGroupFrame(ctx, target.id, replyId, undefined, ms) : node(ctx).groupTaken({ groupId: target.id, messageId: replyId });\n return { ...answer, edges };\n }\n const reply = wait === \"none\" ? await node(ctx).getMessage(target.linkId, replyId) : await waitForMessage(ctx, target.linkId, replyId, wait, ms);\n return { ...answer, delivery: reply?.delivery ?? null };\n}\n\nexport const BUTTON_METHODS: Record<string, Method> = {\n /** WISP 406 · Message Buttons: a press on a button of someone else's message, as the app's tap. */\n \"button.press\": pressButton,\n /** WISP 406 · Message Buttons: the answer chosen on a question of mine, its buttons closed, or its text changed. */\n \"button.update\": updateButtons,\n};\n"],"mappings":";;;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AI,OAAO,OAAO;EAChB,MAAM,QAAQ,SAAS,SAAS,MAAM,kBAAkB,KAAK,OAAO,IAAI,SAAS,KAAA,GAAW,EAAE,IAAI,KAAK,GAAG,CAAC,CAAC,WAAW;GAAE,SAAS,OAAO;GAAI,WAAW;EAAQ,CAAC;EACjK,OAAO;GAAE,GAAG;GAAQ;EAAM;CAC5B;CACA,MAAM,QAAQ,SAAS,SAAS,MAAM,KAAK,GAAG,CAAC,CAAC,WAAW,OAAO,QAAQ,OAAO,IAAI,MAAM,eAAe,KAAK,OAAO,QAAQ,SAAS,MAAM,EAAE;CAC/I,OAAO;EAAE,GAAG;EAAQ,UAAU,OAAO,YAAY;CAAK;AACxD;AAEA,IAAa,iBAAyC;;CAEpD,gBAAgB;;CAEhB,iBAAiB;AACnB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/childEnv.ts
|
|
2
|
+
/**
|
|
3
|
+
* Environment variables only the command that reads them needs: the backup passphrase is read by a one-shot
|
|
4
|
+
* `profile backup`/`profile restore` and sent as a call parameter, so no other process (the daemon, a hook, ffmpeg,
|
|
5
|
+
* the translator, `ps`, `xattr`) ever needs it. The one list every child's environment is cleaned with.
|
|
6
|
+
*/
|
|
7
|
+
var SECRET_ENV = ["GHOSTLY_BACKUP_PASSPHRASE"];
|
|
8
|
+
/** `env` less the secrets in `SECRET_ENV`: what a process this one starts gets. */
|
|
9
|
+
function childEnv(env = process.env) {
|
|
10
|
+
const rest = { ...env };
|
|
11
|
+
for (const name of SECRET_ENV) delete rest[name];
|
|
12
|
+
return rest;
|
|
13
|
+
}
|
|
14
|
+
/** Removes the secrets in `SECRET_ENV` from this process's own environment (the daemon, which never reads them). */
|
|
15
|
+
function dropSecretEnv(env = process.env) {
|
|
16
|
+
for (const name of SECRET_ENV) delete env[name];
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { dropSecretEnv as n, childEnv as t };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=childEnv-BVOQK9EA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"childEnv-BVOQK9EA.js","names":[],"sources":["../../src/childEnv.ts"],"sourcesContent":["/**\n * Environment variables only the command that reads them needs: the backup passphrase is read by a one-shot\n * `profile backup`/`profile restore` and sent as a call parameter, so no other process (the daemon, a hook, ffmpeg,\n * the translator, `ps`, `xattr`) ever needs it. The one list every child's environment is cleaned with.\n */\nexport const SECRET_ENV = [\"GHOSTLY_BACKUP_PASSPHRASE\"] as const;\n\n/** `env` less the secrets in `SECRET_ENV`: what a process this one starts gets. */\nexport function childEnv(env: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {\n const rest = { ...env };\n for (const name of SECRET_ENV) delete rest[name];\n return rest;\n}\n\n/** Removes the secrets in `SECRET_ENV` from this process's own environment (the daemon, which never reads them). */\nexport function dropSecretEnv(env: NodeJS.ProcessEnv = process.env): void {\n for (const name of SECRET_ENV) delete env[name];\n}\n"],"mappings":";;;;;;AAKA,IAAa,aAAa,CAAC,2BAA2B;;AAGtD,SAAgB,SAAS,MAAyB,QAAQ,KAAwB;CAChF,MAAM,OAAO,EAAE,GAAG,IAAI;CACtB,KAAK,MAAM,QAAQ,YAAY,OAAO,KAAK;CAC3C,OAAO;AACT;;AAGA,SAAgB,cAAc,MAAyB,QAAQ,KAAW;CACxE,KAAK,MAAM,QAAQ,YAAY,OAAO,IAAI;AAC5C"}
|