linkedin-relay-mcp 3.0.3 → 3.2.0
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/.claude/skills/linkedin-relay/SKILL.md +27 -12
- package/dist/cli.js +572 -174
- package/dist/cli.js.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp-shim.js +21 -2
- package/dist/mcp-shim.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -45,9 +45,9 @@ function num(args, name) {
|
|
|
45
45
|
return Number.isFinite(n) ? n : void 0;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
// src/
|
|
49
|
-
import {
|
|
50
|
-
import {
|
|
48
|
+
// src/commands/approval.ts
|
|
49
|
+
import { appendFileSync, mkdirSync as mkdirSync2 } from "fs";
|
|
50
|
+
import { dirname as dirname2 } from "path";
|
|
51
51
|
|
|
52
52
|
// src/cache/store.ts
|
|
53
53
|
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
|
|
@@ -90,7 +90,224 @@ function saveJson(path, value) {
|
|
|
90
90
|
renameSync(tmp, path);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
// src/output.ts
|
|
94
|
+
function ok(command, data) {
|
|
95
|
+
return { ok: true, command, data };
|
|
96
|
+
}
|
|
97
|
+
function err(command, code, message, hint, status, retryAfterMs) {
|
|
98
|
+
const error = { code, message };
|
|
99
|
+
if (hint !== void 0) error.hint = hint;
|
|
100
|
+
if (status !== void 0) error.status = status;
|
|
101
|
+
if (retryAfterMs !== void 0) error.retryAfterMs = retryAfterMs;
|
|
102
|
+
return { ok: false, command, error };
|
|
103
|
+
}
|
|
104
|
+
function toJson(envelope) {
|
|
105
|
+
return JSON.stringify(envelope, null, 2);
|
|
106
|
+
}
|
|
107
|
+
function exitCodeFor(envelope) {
|
|
108
|
+
if (envelope.ok) return 0;
|
|
109
|
+
return envelope.error.code === "UNKNOWN_COMMAND" ? 2 : 1;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// src/commands/confirm.ts
|
|
113
|
+
import { createHash } from "crypto";
|
|
114
|
+
var APPROVAL_MODES = ["interactive", "agent", "unattended"];
|
|
115
|
+
function confirmToken(action, payload) {
|
|
116
|
+
return createHash("sha256").update(`${action}:${JSON.stringify(payload)}`).digest("hex").slice(0, 4);
|
|
117
|
+
}
|
|
118
|
+
function riskLines(transport) {
|
|
119
|
+
return transport === "oauth" ? [
|
|
120
|
+
" This write itself is sanctioned \u2014 it uses LinkedIn's own",
|
|
121
|
+
" w_member_social scope. The reads this tool performs are not."
|
|
122
|
+
] : [
|
|
123
|
+
" This goes over the PRIVATE API, not a sanctioned one. It breaches",
|
|
124
|
+
" LinkedIn User Agreement \xA78.2 and can permanently restrict this account."
|
|
125
|
+
];
|
|
126
|
+
}
|
|
127
|
+
function planToken(plan) {
|
|
128
|
+
return confirmToken(plan.action, plan.tokenBasis ?? plan.payload);
|
|
129
|
+
}
|
|
130
|
+
function previewLines(plan, budgetLine2) {
|
|
131
|
+
return [
|
|
132
|
+
`ABOUT TO ${plan.action.toUpperCase()} ON LINKEDIN`,
|
|
133
|
+
...plan.summary,
|
|
134
|
+
`via ${plan.transport === "oauth" ? "official OAuth (w_member_social)" : "Voyager (private API)"}`,
|
|
135
|
+
`undo ${plan.reversibility}`,
|
|
136
|
+
...riskLines(plan.transport).map((l) => l.trim()),
|
|
137
|
+
budgetLine2
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
function renderPlan(plan, budgetLine2) {
|
|
141
|
+
const token = planToken(plan);
|
|
142
|
+
const lines = [
|
|
143
|
+
"",
|
|
144
|
+
` ABOUT TO ${plan.action.toUpperCase()} ON LINKEDIN`,
|
|
145
|
+
` ${"\u2500".repeat(58)}`,
|
|
146
|
+
...plan.summary.map((l) => ` ${l}`),
|
|
147
|
+
` via ${plan.transport === "oauth" ? "official OAuth (w_member_social)" : "Voyager (private API)"}`,
|
|
148
|
+
` undo ${plan.reversibility}`,
|
|
149
|
+
"",
|
|
150
|
+
...riskLines(plan.transport),
|
|
151
|
+
` ${budgetLine2}`,
|
|
152
|
+
"",
|
|
153
|
+
` Type ${token} to confirm, anything else to abort: `
|
|
154
|
+
];
|
|
155
|
+
return lines.join("\n");
|
|
156
|
+
}
|
|
157
|
+
function canApprove(deps) {
|
|
158
|
+
const a = deps.approval ?? { mode: "interactive" };
|
|
159
|
+
if (a.planOnly === true || a.mode === "unattended") return true;
|
|
160
|
+
if (a.mode === "agent" && a.token !== void 0) return true;
|
|
161
|
+
return deps.isTty;
|
|
162
|
+
}
|
|
163
|
+
var refuse = (message, hint) => ({ ok: false, code: "CONFIRMATION_REQUIRED", message, hint });
|
|
164
|
+
async function confirmWrite(plan, budgetLine2, deps) {
|
|
165
|
+
const a = deps.approval ?? { mode: "interactive" };
|
|
166
|
+
const token = planToken(plan);
|
|
167
|
+
const mint = () => ({
|
|
168
|
+
ok: true,
|
|
169
|
+
confirmed: { action: plan.action, payload: plan.payload, token }
|
|
170
|
+
});
|
|
171
|
+
if (a.planOnly === true) {
|
|
172
|
+
return { ok: false, code: "PLANNED", token, preview: previewLines(plan, budgetLine2) };
|
|
173
|
+
}
|
|
174
|
+
if (a.token !== void 0) {
|
|
175
|
+
if (a.mode === "interactive") {
|
|
176
|
+
return refuse(
|
|
177
|
+
`--confirm is not accepted in interactive approval mode; nothing was sent`,
|
|
178
|
+
"In this mode only a human at a terminal approves a write. The owner can allow agents to confirm on their word with `lnrelay approval set agent`, run at a terminal."
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
if (a.token !== token) {
|
|
182
|
+
return refuse(
|
|
183
|
+
"the content changed since it was previewed \u2014 the token no longer matches; nothing was sent",
|
|
184
|
+
"Run again with --plan, show the new preview, and confirm with the new token."
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
return mint();
|
|
188
|
+
}
|
|
189
|
+
if (a.mode === "unattended") return mint();
|
|
190
|
+
if (!deps.isTty) {
|
|
191
|
+
return a.mode === "agent" ? refuse(
|
|
192
|
+
`'${plan.action}' needs the owner's approval of this exact content`,
|
|
193
|
+
"Nothing was sent. Run the same command with --plan, show the preview to the owner, and when they approve re-run it with --confirm <token>."
|
|
194
|
+
) : refuse(
|
|
195
|
+
`'${plan.action}' needs a human to confirm it at an interactive terminal`,
|
|
196
|
+
"No terminal is attached, so nothing was sent and no network call was made. Run this command yourself in a shell. There is no --yes flag; only the owner can change how writes are approved, with `lnrelay approval set`, at a terminal."
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
const answer = (await deps.prompt(renderPlan(plan, budgetLine2))).trim();
|
|
200
|
+
if (answer !== token) {
|
|
201
|
+
return refuse(
|
|
202
|
+
"aborted \u2014 the confirmation token did not match",
|
|
203
|
+
"Nothing was sent. Re-run and type the token shown in the prompt."
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return mint();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/commands/approval.ts
|
|
210
|
+
var MEANING = {
|
|
211
|
+
interactive: "every write waits for a human to type a token at a terminal",
|
|
212
|
+
agent: "an agent may write after the owner approves the exact content: --plan to preview, --confirm <token> once they say so",
|
|
213
|
+
unattended: "agents may write without asking; budget caps, cooldowns and the audit log still apply"
|
|
214
|
+
};
|
|
215
|
+
var isMode = (v) => typeof v === "string" && APPROVAL_MODES.includes(v);
|
|
216
|
+
function loadApprovalMode() {
|
|
217
|
+
const loaded = loadJson(cachePath("config.json"));
|
|
218
|
+
if (loaded.state === "missing") return { ok: true, mode: "interactive" };
|
|
219
|
+
if (loaded.state === "corrupt") {
|
|
220
|
+
return {
|
|
221
|
+
ok: false,
|
|
222
|
+
message: "the approval setting was unreadable and has been quarantined",
|
|
223
|
+
hint: `Moved to ${loaded.quarantinedTo}. Writes fall back to interactive from the next run; set another mode with \`lnrelay approval set\`.`
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const mode = loaded.value.approval ?? "interactive";
|
|
227
|
+
if (!isMode(mode)) {
|
|
228
|
+
return {
|
|
229
|
+
ok: false,
|
|
230
|
+
message: `unknown approval mode '${String(mode)}' in config.json`,
|
|
231
|
+
hint: `one of: ${APPROVAL_MODES.join(", ")}. Set it with \`lnrelay approval set <mode>\`.`
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
return { ok: true, mode };
|
|
235
|
+
}
|
|
236
|
+
function setToken(mode) {
|
|
237
|
+
return confirmToken("set approval mode", mode);
|
|
238
|
+
}
|
|
239
|
+
function append(entry2) {
|
|
240
|
+
const path = cachePath("writes.jsonl");
|
|
241
|
+
mkdirSync2(dirname2(path), { recursive: true });
|
|
242
|
+
appendFileSync(path, `${JSON.stringify({ at: (/* @__PURE__ */ new Date()).toISOString(), ...entry2 })}
|
|
243
|
+
`, {
|
|
244
|
+
mode: 384
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
var approvedInThisRun = false;
|
|
248
|
+
function wasApproved() {
|
|
249
|
+
return approvedInThisRun;
|
|
250
|
+
}
|
|
251
|
+
function auditApproval(command, mode, summary, token) {
|
|
252
|
+
approvedInThisRun = true;
|
|
253
|
+
append({ event: "approved", command, mode, summary, token });
|
|
254
|
+
}
|
|
255
|
+
function auditOutcome(command, mode, envelope) {
|
|
256
|
+
append(
|
|
257
|
+
envelope.ok ? { event: "outcome", command, mode, ok: true, data: envelope.data } : { event: "outcome", command, mode, ok: false, error: envelope.error }
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
function runApprovalShow() {
|
|
261
|
+
const loaded = loadApprovalMode();
|
|
262
|
+
if (!loaded.ok) return err("approval", "CACHE_CORRUPT", loaded.message, loaded.hint);
|
|
263
|
+
return ok("approval", {
|
|
264
|
+
mode: loaded.mode,
|
|
265
|
+
meaning: MEANING[loaded.mode],
|
|
266
|
+
audit: cachePath("writes.jsonl")
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
async function runApprovalSet(mode, deps) {
|
|
270
|
+
if (!isMode(mode)) {
|
|
271
|
+
return err(
|
|
272
|
+
"approval",
|
|
273
|
+
"INVALID_INPUT",
|
|
274
|
+
`unknown approval mode '${mode ?? ""}'`,
|
|
275
|
+
`one of: ${APPROVAL_MODES.map((m) => `${m} (${MEANING[m]})`).join("; ")}`
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
if (!deps.isTty) {
|
|
279
|
+
return err(
|
|
280
|
+
"approval",
|
|
281
|
+
"CONFIRMATION_REQUIRED",
|
|
282
|
+
"the approval mode can only be changed by a human at an interactive terminal",
|
|
283
|
+
"Nothing was changed. An agent cannot choose how its own writes are approved."
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
const token = setToken(mode);
|
|
287
|
+
const answer = (await deps.prompt(
|
|
288
|
+
[
|
|
289
|
+
"",
|
|
290
|
+
` SET LINKEDIN WRITE APPROVAL TO: ${mode.toUpperCase()}`,
|
|
291
|
+
` ${MEANING[mode]}`,
|
|
292
|
+
"",
|
|
293
|
+
` Type ${token} to confirm, anything else to abort: `
|
|
294
|
+
].join("\n")
|
|
295
|
+
)).trim();
|
|
296
|
+
if (answer !== token) {
|
|
297
|
+
return err("approval", "CONFIRMATION_REQUIRED", "aborted \u2014 nothing was changed");
|
|
298
|
+
}
|
|
299
|
+
const current = loadJson(cachePath("config.json"));
|
|
300
|
+
saveJson(cachePath("config.json"), {
|
|
301
|
+
...current.state === "ok" ? current.value : {},
|
|
302
|
+
approval: mode
|
|
303
|
+
});
|
|
304
|
+
append({ event: "mode", mode });
|
|
305
|
+
return ok("approval", { mode, meaning: MEANING[mode] });
|
|
306
|
+
}
|
|
307
|
+
|
|
93
308
|
// src/cache/db.ts
|
|
309
|
+
import { Database } from "bun:sqlite";
|
|
310
|
+
import { mkdirSync as mkdirSync3, renameSync as renameSync2 } from "fs";
|
|
94
311
|
var DB_FILE = "cache.db";
|
|
95
312
|
var THIRD_PARTY_TTL_MS = 30 * 864e5;
|
|
96
313
|
function fold(value) {
|
|
@@ -130,7 +347,7 @@ var CacheCorrupt = class extends Error {
|
|
|
130
347
|
quarantinedTo;
|
|
131
348
|
};
|
|
132
349
|
function openDb(now = Date.now()) {
|
|
133
|
-
|
|
350
|
+
mkdirSync3(cacheDir(), { recursive: true });
|
|
134
351
|
const path = cachePath(DB_FILE);
|
|
135
352
|
let db;
|
|
136
353
|
try {
|
|
@@ -166,7 +383,7 @@ function quarantine2(path, reason, now) {
|
|
|
166
383
|
const stamp = new Date(now).toISOString().replace(/[:.]/g, "-");
|
|
167
384
|
const target = cachePath("quarantine", stamp, DB_FILE);
|
|
168
385
|
try {
|
|
169
|
-
|
|
386
|
+
mkdirSync3(cachePath("quarantine", stamp), { recursive: true });
|
|
170
387
|
renameSync2(path, target);
|
|
171
388
|
} catch {
|
|
172
389
|
}
|
|
@@ -187,7 +404,7 @@ function upsert(db, source, rows, now = Date.now()) {
|
|
|
187
404
|
let added = 0;
|
|
188
405
|
let updated = 0;
|
|
189
406
|
const exists = db.query("SELECT 1 FROM records WHERE urn = ? AND source = ?");
|
|
190
|
-
const
|
|
407
|
+
const write2 = db.query(
|
|
191
408
|
`INSERT INTO records (urn, source, body, text, textFold, firstSeenAt, updatedAt, expiresAt)
|
|
192
409
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
193
410
|
ON CONFLICT(urn, source) DO UPDATE SET
|
|
@@ -198,7 +415,7 @@ function upsert(db, source, rows, now = Date.now()) {
|
|
|
198
415
|
for (const row of rows) {
|
|
199
416
|
if (exists.get(row.urn, source) === null) added++;
|
|
200
417
|
else updated++;
|
|
201
|
-
|
|
418
|
+
write2.run(
|
|
202
419
|
row.urn,
|
|
203
420
|
source,
|
|
204
421
|
JSON.stringify(row.body),
|
|
@@ -401,9 +618,13 @@ function shapePost(node, index) {
|
|
|
401
618
|
const urn = postUrn(node);
|
|
402
619
|
const social = deref(node, "*socialDetail", index);
|
|
403
620
|
const counts = social === void 0 ? void 0 : deref(social, "*totalSocialActivityCounts", index);
|
|
621
|
+
const meta = node.metadata;
|
|
404
622
|
return defined({
|
|
405
623
|
type: typeOf(node),
|
|
406
624
|
urn,
|
|
625
|
+
// The urn the post was CREATED as (share or ugcPost) — what `share` prints,
|
|
626
|
+
// and a different number from the activity urn above.
|
|
627
|
+
shareUrn: typeof meta?.shareUrn === "string" ? meta.shareUrn : void 0,
|
|
407
628
|
threadUrn: typeof social?.urn === "string" ? social.urn : void 0,
|
|
408
629
|
author: text(actor?.name),
|
|
409
630
|
// `text()` already trims; LinkedIn pads these with trailing spaces.
|
|
@@ -552,25 +773,6 @@ function compactRows(rows) {
|
|
|
552
773
|
});
|
|
553
774
|
}
|
|
554
775
|
|
|
555
|
-
// src/output.ts
|
|
556
|
-
function ok(command, data) {
|
|
557
|
-
return { ok: true, command, data };
|
|
558
|
-
}
|
|
559
|
-
function err(command, code, message, hint, status, retryAfterMs) {
|
|
560
|
-
const error = { code, message };
|
|
561
|
-
if (hint !== void 0) error.hint = hint;
|
|
562
|
-
if (status !== void 0) error.status = status;
|
|
563
|
-
if (retryAfterMs !== void 0) error.retryAfterMs = retryAfterMs;
|
|
564
|
-
return { ok: false, command, error };
|
|
565
|
-
}
|
|
566
|
-
function toJson(envelope) {
|
|
567
|
-
return JSON.stringify(envelope, null, 2);
|
|
568
|
-
}
|
|
569
|
-
function exitCodeFor(envelope) {
|
|
570
|
-
if (envelope.ok) return 0;
|
|
571
|
-
return envelope.error.code === "UNKNOWN_COMMAND" ? 2 : 1;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
776
|
// src/commands/cache.ts
|
|
575
777
|
var SOURCES = ["connections", "my-posts", "third-party"];
|
|
576
778
|
function corruptEnvelope(command, e) {
|
|
@@ -711,11 +913,11 @@ function buildHeaders(session) {
|
|
|
711
913
|
}
|
|
712
914
|
|
|
713
915
|
// src/progress.ts
|
|
714
|
-
function progressReporter(quiet,
|
|
916
|
+
function progressReporter(quiet, write2 = (s) => {
|
|
715
917
|
process.stderr.write(s);
|
|
716
918
|
}) {
|
|
717
919
|
return (msg) => {
|
|
718
|
-
if (!quiet)
|
|
920
|
+
if (!quiet) write2(`${msg}
|
|
719
921
|
`);
|
|
720
922
|
};
|
|
721
923
|
}
|
|
@@ -1008,14 +1210,20 @@ function createClient(session, deps) {
|
|
|
1008
1210
|
}
|
|
1009
1211
|
return { request };
|
|
1010
1212
|
}
|
|
1213
|
+
function encodeBody(spec) {
|
|
1214
|
+
if (spec.bytes !== void 0) return spec.bytes;
|
|
1215
|
+
return spec.body === void 0 ? void 0 : JSON.stringify(spec.body);
|
|
1216
|
+
}
|
|
1011
1217
|
async function fetchRaw(spec, session, deps) {
|
|
1012
1218
|
const requestHeaders = buildHeaders(session);
|
|
1013
1219
|
if (spec.body !== void 0) requestHeaders["content-type"] = "application/json; charset=UTF-8";
|
|
1220
|
+
Object.assign(requestHeaders, spec.headers);
|
|
1221
|
+
const body = encodeBody(spec);
|
|
1014
1222
|
try {
|
|
1015
1223
|
const res = await deps.fetch(spec.url, {
|
|
1016
1224
|
method: spec.method ?? "GET",
|
|
1017
1225
|
headers: requestHeaders,
|
|
1018
|
-
...
|
|
1226
|
+
...body === void 0 ? {} : { body },
|
|
1019
1227
|
// Manual, so a login or checkpoint redirect is classified rather than
|
|
1020
1228
|
// silently followed into an HTML page that parses as "no data".
|
|
1021
1229
|
redirect: "manual"
|
|
@@ -1924,10 +2132,96 @@ function getAllCookies(wsUrl) {
|
|
|
1924
2132
|
});
|
|
1925
2133
|
}
|
|
1926
2134
|
|
|
2135
|
+
// src/engine/voyager-write.ts
|
|
2136
|
+
import { createHash as createHash2 } from "crypto";
|
|
2137
|
+
|
|
2138
|
+
// src/engine/voyager-media.ts
|
|
2139
|
+
var MEDIA_UPLOAD_URL = "https://www.linkedin.com/voyager/api/voyagerVideoDashMediaUploadMetadata?action=upload";
|
|
2140
|
+
var TYPES = {
|
|
2141
|
+
png: { kind: "IMAGE", contentType: "image/png" },
|
|
2142
|
+
jpg: { kind: "IMAGE", contentType: "image/jpeg" },
|
|
2143
|
+
jpeg: { kind: "IMAGE", contentType: "image/jpeg" },
|
|
2144
|
+
gif: { kind: "IMAGE", contentType: "image/gif" },
|
|
2145
|
+
webp: { kind: "IMAGE", contentType: "image/webp" },
|
|
2146
|
+
mp4: { kind: "VIDEO", contentType: "video/mp4" },
|
|
2147
|
+
mov: { kind: "VIDEO", contentType: "video/quicktime" }
|
|
2148
|
+
};
|
|
2149
|
+
function mediaKindOf(filename) {
|
|
2150
|
+
const ext = /\.([a-z0-9]+)$/i.exec(filename)?.[1]?.toLowerCase();
|
|
2151
|
+
return ext === void 0 ? null : TYPES[ext] ?? null;
|
|
2152
|
+
}
|
|
2153
|
+
function registerPayload(kind, fileSize, filename) {
|
|
2154
|
+
return {
|
|
2155
|
+
mediaUploadType: kind === "IMAGE" ? "IMAGE_SHARING" : "VIDEO_SHARING",
|
|
2156
|
+
fileSize,
|
|
2157
|
+
filename
|
|
2158
|
+
};
|
|
2159
|
+
}
|
|
2160
|
+
function parseUploadTicket(json) {
|
|
2161
|
+
const v = json?.data?.value;
|
|
2162
|
+
if (v?.type !== void 0 && v.type !== "SINGLE") {
|
|
2163
|
+
return {
|
|
2164
|
+
ok: false,
|
|
2165
|
+
code: "NOT_IMPLEMENTED",
|
|
2166
|
+
message: `LinkedIn asked for a ${String(v.type)} upload, which is only used for large files and has not been observed here. Nothing was uploaded or posted. Try a smaller file.`
|
|
2167
|
+
};
|
|
2168
|
+
}
|
|
2169
|
+
const urn = v?.urn;
|
|
2170
|
+
const uploadUrl = v?.singleUploadUrl;
|
|
2171
|
+
if (typeof urn !== "string" || typeof uploadUrl !== "string") {
|
|
2172
|
+
return {
|
|
2173
|
+
ok: false,
|
|
2174
|
+
code: "SCHEMA_DRIFT",
|
|
2175
|
+
message: "the upload ticket carried no asset urn or upload url; nothing was posted"
|
|
2176
|
+
};
|
|
2177
|
+
}
|
|
2178
|
+
const headers2 = v?.singleUploadHeaders;
|
|
2179
|
+
return {
|
|
2180
|
+
ok: true,
|
|
2181
|
+
urn,
|
|
2182
|
+
uploadUrl,
|
|
2183
|
+
uploadHeaders: headers2 !== null && typeof headers2 === "object" ? headers2 : {}
|
|
2184
|
+
};
|
|
2185
|
+
}
|
|
2186
|
+
async function uploadMedia(file, client) {
|
|
2187
|
+
const registered = await client.request({
|
|
2188
|
+
url: MEDIA_UPLOAD_URL,
|
|
2189
|
+
method: "POST",
|
|
2190
|
+
body: registerPayload(file.kind, file.bytes.byteLength, file.filename),
|
|
2191
|
+
spendClass: "write",
|
|
2192
|
+
operation: "register-upload"
|
|
2193
|
+
});
|
|
2194
|
+
if (!registered.ok) {
|
|
2195
|
+
return {
|
|
2196
|
+
ok: false,
|
|
2197
|
+
code: registered.code,
|
|
2198
|
+
message: `${registered.message}; nothing was posted`
|
|
2199
|
+
};
|
|
2200
|
+
}
|
|
2201
|
+
const ticket = parseUploadTicket(registered.json);
|
|
2202
|
+
if (!ticket.ok) return ticket;
|
|
2203
|
+
const put = await client.request({
|
|
2204
|
+
url: ticket.uploadUrl,
|
|
2205
|
+
method: "PUT",
|
|
2206
|
+
bytes: file.bytes,
|
|
2207
|
+
headers: { "content-type": file.contentType, ...ticket.uploadHeaders },
|
|
2208
|
+
spendClass: "write",
|
|
2209
|
+
operation: "upload"
|
|
2210
|
+
});
|
|
2211
|
+
if (!put.ok) {
|
|
2212
|
+
return {
|
|
2213
|
+
ok: false,
|
|
2214
|
+
code: put.code,
|
|
2215
|
+
message: `uploading ${file.filename} failed (${put.message}); nothing was posted`
|
|
2216
|
+
};
|
|
2217
|
+
}
|
|
2218
|
+
return { ok: true, urn: ticket.urn };
|
|
2219
|
+
}
|
|
2220
|
+
|
|
1927
2221
|
// src/engine/voyager-write.ts
|
|
1928
2222
|
var VOYAGER2 = "https://www.linkedin.com/voyager/api";
|
|
1929
2223
|
var SHARE_URL = `${VOYAGER2}/contentcreation/normShares`;
|
|
1930
|
-
function sharePayload(text2, visibility) {
|
|
2224
|
+
function sharePayload(text2, visibility, media = []) {
|
|
1931
2225
|
return {
|
|
1932
2226
|
visibleToConnectionsOnly: visibility === "CONNECTIONS",
|
|
1933
2227
|
externalAudienceProviders: [],
|
|
@@ -1935,9 +2229,12 @@ function sharePayload(text2, visibility) {
|
|
|
1935
2229
|
origin: "FEED",
|
|
1936
2230
|
allowedCommentersScope: "ALL",
|
|
1937
2231
|
postState: "PUBLISHED",
|
|
1938
|
-
media: []
|
|
2232
|
+
media: media.map((m) => ({ category: m.category, mediaUrn: m.urn, tapTargets: [] }))
|
|
1939
2233
|
};
|
|
1940
2234
|
}
|
|
2235
|
+
function mediaDigest(bytes) {
|
|
2236
|
+
return createHash2("sha256").update(bytes).digest("hex");
|
|
2237
|
+
}
|
|
1941
2238
|
var POST_URN = /urn:li:(share|activity|ugcPost):\d+/;
|
|
1942
2239
|
function isDeletableUrn(urn) {
|
|
1943
2240
|
return new RegExp(`^${POST_URN.source}$`).test(urn);
|
|
@@ -1970,8 +2267,30 @@ async function deletePost(confirmed, client) {
|
|
|
1970
2267
|
function extractShareUrn(json) {
|
|
1971
2268
|
return JSON.stringify(json ?? null).match(POST_URN)?.[0] ?? null;
|
|
1972
2269
|
}
|
|
1973
|
-
async function share(confirmed, client) {
|
|
1974
|
-
const
|
|
2270
|
+
async function share(confirmed, client, bytes) {
|
|
2271
|
+
const { media: approved } = confirmed.payload;
|
|
2272
|
+
const media = [];
|
|
2273
|
+
if (approved !== void 0) {
|
|
2274
|
+
if (bytes === void 0 || mediaDigest(bytes) !== approved.sha256) {
|
|
2275
|
+
return {
|
|
2276
|
+
ok: false,
|
|
2277
|
+
code: "INVALID_INPUT",
|
|
2278
|
+
message: `${approved.filename} changed after it was approved; nothing was sent`
|
|
2279
|
+
};
|
|
2280
|
+
}
|
|
2281
|
+
const uploaded = await uploadMedia(
|
|
2282
|
+
{
|
|
2283
|
+
bytes,
|
|
2284
|
+
filename: approved.filename,
|
|
2285
|
+
kind: approved.kind,
|
|
2286
|
+
contentType: approved.contentType
|
|
2287
|
+
},
|
|
2288
|
+
client
|
|
2289
|
+
);
|
|
2290
|
+
if (!uploaded.ok) return uploaded;
|
|
2291
|
+
media.push({ category: approved.kind, urn: uploaded.urn });
|
|
2292
|
+
}
|
|
2293
|
+
const body = sharePayload(confirmed.payload.text, confirmed.payload.visibility, media);
|
|
1975
2294
|
const result = await client.request({
|
|
1976
2295
|
url: SHARE_URL,
|
|
1977
2296
|
method: "POST",
|
|
@@ -1994,64 +2313,6 @@ async function share(confirmed, client) {
|
|
|
1994
2313
|
|
|
1995
2314
|
// src/commands/gate.ts
|
|
1996
2315
|
import { createInterface } from "readline/promises";
|
|
1997
|
-
|
|
1998
|
-
// src/commands/confirm.ts
|
|
1999
|
-
import { createHash } from "crypto";
|
|
2000
|
-
function confirmToken(action, payload) {
|
|
2001
|
-
return createHash("sha256").update(`${action}:${JSON.stringify(payload)}`).digest("hex").slice(0, 4);
|
|
2002
|
-
}
|
|
2003
|
-
function riskLines(transport) {
|
|
2004
|
-
return transport === "oauth" ? [
|
|
2005
|
-
" This write itself is sanctioned \u2014 it uses LinkedIn's own",
|
|
2006
|
-
" w_member_social scope. The reads this tool performs are not."
|
|
2007
|
-
] : [
|
|
2008
|
-
" This goes over the PRIVATE API, not a sanctioned one. It breaches",
|
|
2009
|
-
" LinkedIn User Agreement \xA78.2 and can permanently restrict this account."
|
|
2010
|
-
];
|
|
2011
|
-
}
|
|
2012
|
-
function renderPlan(plan, budgetLine2) {
|
|
2013
|
-
const token = confirmToken(plan.action, plan.payload);
|
|
2014
|
-
const lines = [
|
|
2015
|
-
"",
|
|
2016
|
-
` ABOUT TO ${plan.action.toUpperCase()} ON LINKEDIN`,
|
|
2017
|
-
` ${"\u2500".repeat(58)}`,
|
|
2018
|
-
...plan.summary.map((l) => ` ${l}`),
|
|
2019
|
-
` via ${plan.transport === "oauth" ? "official OAuth (w_member_social)" : "Voyager (private API)"}`,
|
|
2020
|
-
` undo ${plan.reversibility}`,
|
|
2021
|
-
"",
|
|
2022
|
-
...riskLines(plan.transport),
|
|
2023
|
-
` ${budgetLine2}`,
|
|
2024
|
-
"",
|
|
2025
|
-
` Type ${token} to confirm, anything else to abort: `
|
|
2026
|
-
];
|
|
2027
|
-
return lines.join("\n");
|
|
2028
|
-
}
|
|
2029
|
-
async function confirmWrite(plan, budgetLine2, deps) {
|
|
2030
|
-
if (!deps.isTty) {
|
|
2031
|
-
return {
|
|
2032
|
-
ok: false,
|
|
2033
|
-
code: "CONFIRMATION_REQUIRED",
|
|
2034
|
-
message: `'${plan.action}' needs a human to confirm it at an interactive terminal`,
|
|
2035
|
-
hint: "No terminal is attached, so nothing was sent and no network call was made. Run this command yourself in a shell. There is deliberately no --yes flag: an agent that could set one would not be confirming anything."
|
|
2036
|
-
};
|
|
2037
|
-
}
|
|
2038
|
-
const token = confirmToken(plan.action, plan.payload);
|
|
2039
|
-
const answer = (await deps.prompt(renderPlan(plan, budgetLine2))).trim();
|
|
2040
|
-
if (answer !== token) {
|
|
2041
|
-
return {
|
|
2042
|
-
ok: false,
|
|
2043
|
-
code: "CONFIRMATION_REQUIRED",
|
|
2044
|
-
message: "aborted \u2014 the confirmation token did not match",
|
|
2045
|
-
hint: "Nothing was sent. Re-run and type the token shown in the prompt."
|
|
2046
|
-
};
|
|
2047
|
-
}
|
|
2048
|
-
return {
|
|
2049
|
-
ok: true,
|
|
2050
|
-
confirmed: { action: plan.action, payload: plan.payload, token }
|
|
2051
|
-
};
|
|
2052
|
-
}
|
|
2053
|
-
|
|
2054
|
-
// src/commands/gate.ts
|
|
2055
2316
|
function ledger() {
|
|
2056
2317
|
const result = loadJson(cachePath("budget.json"));
|
|
2057
2318
|
return result.state === "ok" ? result.value : emptyLedger();
|
|
@@ -2060,6 +2321,20 @@ function budgetLine(now) {
|
|
|
2060
2321
|
const s = summarise(ledger(), "write", now);
|
|
2061
2322
|
return `${s.remaining} of ${s.cap} writes left today.`;
|
|
2062
2323
|
}
|
|
2324
|
+
function refuseUnapprovable(command, action, deps) {
|
|
2325
|
+
if (canApprove(deps)) return null;
|
|
2326
|
+
return deps.approval?.mode === "agent" ? err(
|
|
2327
|
+
command,
|
|
2328
|
+
"CONFIRMATION_REQUIRED",
|
|
2329
|
+
`${action} needs the owner's approval of this exact content`,
|
|
2330
|
+
"Nothing was sent and no network call was made. Run the same command with --plan, show the preview to the owner, and when they approve re-run it with --confirm <token>."
|
|
2331
|
+
) : err(
|
|
2332
|
+
command,
|
|
2333
|
+
"CONFIRMATION_REQUIRED",
|
|
2334
|
+
`${action} needs a human to confirm it at an interactive terminal`,
|
|
2335
|
+
"No terminal is attached, so nothing was sent and no network call was made."
|
|
2336
|
+
);
|
|
2337
|
+
}
|
|
2063
2338
|
function terminalDeps() {
|
|
2064
2339
|
return {
|
|
2065
2340
|
isTty: process.stdin.isTTY === true && process.stdout.isTTY === true,
|
|
@@ -2076,13 +2351,34 @@ function recordHarvestSpend(now) {
|
|
|
2076
2351
|
const attempt = spend(ledger(), "page", now);
|
|
2077
2352
|
if ("permit" in attempt) saveJson(cachePath("budget.json"), attempt.ledger);
|
|
2078
2353
|
}
|
|
2079
|
-
function reserve(command, now) {
|
|
2080
|
-
|
|
2081
|
-
|
|
2354
|
+
function reserve(command, now, calls = 1) {
|
|
2355
|
+
let current = ledger();
|
|
2356
|
+
for (let i = 0; i < calls; i++) {
|
|
2357
|
+
const attempt = spend(current, "write", now + i * MIN_GAP_MS);
|
|
2358
|
+
if ("error" in attempt) {
|
|
2359
|
+
return err(command, attempt.error.code, attempt.error.message, attempt.error.hint);
|
|
2360
|
+
}
|
|
2361
|
+
current = attempt.ledger;
|
|
2362
|
+
}
|
|
2363
|
+
return null;
|
|
2082
2364
|
}
|
|
2083
2365
|
async function gateWrite(command, plan, now, deps, opts = {}) {
|
|
2084
2366
|
const outcome = await confirmWrite(plan, budgetLine(now), deps);
|
|
2367
|
+
if (!outcome.ok && outcome.code === "PLANNED") {
|
|
2368
|
+
return ok(command, {
|
|
2369
|
+
planned: true,
|
|
2370
|
+
token: outcome.token,
|
|
2371
|
+
preview: outcome.preview,
|
|
2372
|
+
next: `show this to the owner; on their approval re-run the same command with --confirm ${outcome.token}`
|
|
2373
|
+
});
|
|
2374
|
+
}
|
|
2085
2375
|
if (!outcome.ok) return err(command, outcome.code, outcome.message, outcome.hint);
|
|
2376
|
+
auditApproval(
|
|
2377
|
+
command,
|
|
2378
|
+
deps.approval?.mode ?? "interactive",
|
|
2379
|
+
plan.summary,
|
|
2380
|
+
outcome.confirmed.token
|
|
2381
|
+
);
|
|
2086
2382
|
if (opts.commitSpend !== false) {
|
|
2087
2383
|
const attempt = spend(ledger(), "write", now);
|
|
2088
2384
|
if ("permit" in attempt) saveJson(cachePath("budget.json"), attempt.ledger);
|
|
@@ -2099,9 +2395,11 @@ function postId(urn) {
|
|
|
2099
2395
|
function findOwnPost(posts, urn) {
|
|
2100
2396
|
const id = postId(urn);
|
|
2101
2397
|
if (id === void 0) return void 0;
|
|
2102
|
-
return posts.find(
|
|
2398
|
+
return posts.find(
|
|
2399
|
+
(p) => typeof p.urn === "string" && postId(p.urn) === id || p.shareUrn === urn
|
|
2400
|
+
);
|
|
2103
2401
|
}
|
|
2104
|
-
function
|
|
2402
|
+
function previewLines2(post) {
|
|
2105
2403
|
if (post === void 0) {
|
|
2106
2404
|
return [
|
|
2107
2405
|
"content COULD NOT READ THIS POST.",
|
|
@@ -2140,14 +2438,8 @@ function evict(urn, now) {
|
|
|
2140
2438
|
}
|
|
2141
2439
|
}
|
|
2142
2440
|
async function deleteComment(ref, urn, now, deps) {
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
"delete",
|
|
2146
|
-
"CONFIRMATION_REQUIRED",
|
|
2147
|
-
"deleting needs a human to confirm it at an interactive terminal",
|
|
2148
|
-
"No terminal is attached, so nothing was sent and no network call was made."
|
|
2149
|
-
);
|
|
2150
|
-
}
|
|
2441
|
+
const unapprovable = refuseUnapprovable("delete", "deleting", deps);
|
|
2442
|
+
if (unapprovable !== null) return unapprovable;
|
|
2151
2443
|
const session = loadSession();
|
|
2152
2444
|
if (session.state !== "ok") {
|
|
2153
2445
|
return err("delete", "AUTH_FAILED", "no LinkedIn session", LAUNCH_HINT);
|
|
@@ -2229,11 +2521,13 @@ async function runDelete(urn, now = Date.now(), deps, quiet = false) {
|
|
|
2229
2521
|
}
|
|
2230
2522
|
const refused = reserve("delete", now);
|
|
2231
2523
|
if (refused !== null) return refused;
|
|
2524
|
+
const unapprovable = refuseUnapprovable("delete", "deleting", deps ?? terminalDeps());
|
|
2525
|
+
if (unapprovable !== null) return unapprovable;
|
|
2232
2526
|
const post = await lookup(urn, quiet);
|
|
2233
2527
|
const plan = {
|
|
2234
2528
|
action: "delete a post",
|
|
2235
2529
|
payload: { urn },
|
|
2236
|
-
summary: [`post ${urn}`, ...
|
|
2530
|
+
summary: [`post ${urn}`, ...previewLines2(post)],
|
|
2237
2531
|
reversibility: "NONE. A deleted post is gone, with its comments and reactions.",
|
|
2238
2532
|
transport: "voyager"
|
|
2239
2533
|
};
|
|
@@ -2243,7 +2537,9 @@ async function runDelete(urn, now = Date.now(), deps, quiet = false) {
|
|
|
2243
2537
|
if ("ok" in gated) return gated;
|
|
2244
2538
|
const result = await deletePost(gated.confirmed, createLiveClient(session.session));
|
|
2245
2539
|
if (!result.ok) return err("delete", result.code, result.message, result.hint);
|
|
2246
|
-
const
|
|
2540
|
+
const target = evictionTarget(result);
|
|
2541
|
+
const cached = typeof post?.urn === "string" ? post.urn : target;
|
|
2542
|
+
const evicted = evict(target === null ? null : cached, now);
|
|
2247
2543
|
return ok("delete", { deleted: urn, verified: post !== void 0, evictedFromCache: evicted });
|
|
2248
2544
|
}
|
|
2249
2545
|
|
|
@@ -2992,11 +3288,20 @@ var COMMANDS = [
|
|
|
2992
3288
|
risk: "local",
|
|
2993
3289
|
implemented: true
|
|
2994
3290
|
},
|
|
3291
|
+
{
|
|
3292
|
+
name: "approval",
|
|
3293
|
+
cost: "free \u2014 local",
|
|
3294
|
+
summary: "Show or set how writes are approved: interactive (a human at a terminal), agent (the owner approves a --plan preview in chat), or unattended. Only a terminal can change it.",
|
|
3295
|
+
usage: "lnrelay approval [show]\n lnrelay approval set <interactive|agent|unattended>\n Setting needs an interactive terminal and a typed token. Every approval and outcome\n is appended to ~/.lnrelay/writes.jsonl.",
|
|
3296
|
+
audience: ["cli"],
|
|
3297
|
+
risk: "local",
|
|
3298
|
+
implemented: true
|
|
3299
|
+
},
|
|
2995
3300
|
{
|
|
2996
3301
|
name: "share",
|
|
2997
3302
|
cost: "1 call \u2014 write",
|
|
2998
3303
|
summary: "Post to your own feed. Prefers LinkedIn's official OAuth scope, falls back to the private API when no token exists \u2014 the prompt always names which.",
|
|
2999
|
-
usage: 'lnrelay share "<text>" [--visibility public|connections]
|
|
3304
|
+
usage: 'lnrelay share "<text>" [--image <path> | --video <path>] [--visibility public|connections]\n [--via oauth|voyager]\n Approval follows `lnrelay approval`: --plan previews and returns a token without\n sending; --confirm <token> sends it in agent mode. In interactive mode it asks at a\n terminal. --image (png/jpg/gif/webp) or --video (mp4/mov) uploads the file first, over the\n private API only; the prompt shows its size and sha256.',
|
|
3000
3305
|
audience: ["cli"],
|
|
3001
3306
|
risk: "write",
|
|
3002
3307
|
implemented: true
|
|
@@ -3179,6 +3484,10 @@ async function runSync(source, limit, force, now = Date.now()) {
|
|
|
3179
3484
|
}
|
|
3180
3485
|
}
|
|
3181
3486
|
|
|
3487
|
+
// src/commands/write.ts
|
|
3488
|
+
import { readFileSync as readFileSync2, statSync } from "fs";
|
|
3489
|
+
import { basename } from "path";
|
|
3490
|
+
|
|
3182
3491
|
// src/engine/oauth-write.ts
|
|
3183
3492
|
var API = "https://api.linkedin.com";
|
|
3184
3493
|
function headers(token) {
|
|
@@ -3599,7 +3908,7 @@ function chooseTransport(inputs, requested) {
|
|
|
3599
3908
|
function authorLine(transport) {
|
|
3600
3909
|
return transport.kind === "oauth" ? `as ${transport.token.memberUrn}` : `as ${transport.session.ownerUrn ?? "you (browser session)"}`;
|
|
3601
3910
|
}
|
|
3602
|
-
function prepare(command, now, via2) {
|
|
3911
|
+
function prepare(command, now, via2, calls = 1) {
|
|
3603
3912
|
const session = loadSession();
|
|
3604
3913
|
const choice = chooseTransport(
|
|
3605
3914
|
{ token: loadToken(), session: session.state === "ok" ? session.session : null, now },
|
|
@@ -3610,7 +3919,7 @@ function prepare(command, now, via2) {
|
|
|
3610
3919
|
|
|
3611
3920
|
${OAUTH_SETUP}`);
|
|
3612
3921
|
}
|
|
3613
|
-
const refused = reserve(command, now);
|
|
3922
|
+
const refused = reserve(command, now, calls);
|
|
3614
3923
|
if (refused !== null) return refused;
|
|
3615
3924
|
const ctx = { transport: choice.transport, now };
|
|
3616
3925
|
if (choice.note !== void 0) ctx.note = choice.note;
|
|
@@ -3623,17 +3932,77 @@ async function gate(command, plan, ctx, deps) {
|
|
|
3623
3932
|
if ("ok" in gated) return gated;
|
|
3624
3933
|
return { confirmed: gated.confirmed };
|
|
3625
3934
|
}
|
|
3626
|
-
|
|
3935
|
+
function loadMedia(media) {
|
|
3936
|
+
const kind = mediaKindOf(media.path);
|
|
3937
|
+
if (kind === null) {
|
|
3938
|
+
return err(
|
|
3939
|
+
"share",
|
|
3940
|
+
"INVALID_INPUT",
|
|
3941
|
+
`unsupported file type: ${basename(media.path)}`,
|
|
3942
|
+
"images: png, jpg, jpeg, gif, webp. videos: mp4, mov."
|
|
3943
|
+
);
|
|
3944
|
+
}
|
|
3945
|
+
const expected = media.flag === "image" ? "IMAGE" : "VIDEO";
|
|
3946
|
+
if (kind.kind !== expected) {
|
|
3947
|
+
const right = kind.kind === "IMAGE" ? "--image" : "--video";
|
|
3948
|
+
return err(
|
|
3949
|
+
"share",
|
|
3950
|
+
"INVALID_INPUT",
|
|
3951
|
+
`${basename(media.path)} is not a${media.flag === "image" ? "n image" : " video"}`,
|
|
3952
|
+
`pass it with ${right}`
|
|
3953
|
+
);
|
|
3954
|
+
}
|
|
3955
|
+
let bytes;
|
|
3956
|
+
try {
|
|
3957
|
+
if (!statSync(media.path).isFile()) throw new Error("not a file");
|
|
3958
|
+
bytes = new Uint8Array(readFileSync2(media.path));
|
|
3959
|
+
} catch {
|
|
3960
|
+
return err("share", "INVALID_INPUT", `cannot read ${media.path}`);
|
|
3961
|
+
}
|
|
3962
|
+
return {
|
|
3963
|
+
bytes,
|
|
3964
|
+
approved: {
|
|
3965
|
+
filename: basename(media.path),
|
|
3966
|
+
kind: kind.kind,
|
|
3967
|
+
contentType: kind.contentType,
|
|
3968
|
+
size: bytes.byteLength,
|
|
3969
|
+
sha256: mediaDigest(bytes)
|
|
3970
|
+
}
|
|
3971
|
+
};
|
|
3972
|
+
}
|
|
3973
|
+
async function runShare(text2, visibility, now = Date.now(), deps = terminalDeps(), via2, media) {
|
|
3627
3974
|
if (text2 === void 0 || text2.trim() === "") {
|
|
3628
3975
|
return err("share", "INVALID_INPUT", "text is required", 'lnrelay share "<text>"');
|
|
3629
3976
|
}
|
|
3630
3977
|
const vis = visibility === "connections" ? "CONNECTIONS" : "PUBLIC";
|
|
3631
|
-
const
|
|
3978
|
+
const loaded = media === void 0 ? void 0 : loadMedia(media);
|
|
3979
|
+
if (loaded !== void 0 && "ok" in loaded) return loaded;
|
|
3980
|
+
if (loaded !== void 0 && via2 === "oauth") {
|
|
3981
|
+
return err(
|
|
3982
|
+
"share",
|
|
3983
|
+
"NOT_IMPLEMENTED",
|
|
3984
|
+
"posting media is only implemented over the private API",
|
|
3985
|
+
"drop --via oauth, or pass --via voyager"
|
|
3986
|
+
);
|
|
3987
|
+
}
|
|
3988
|
+
const ctx = loaded === void 0 ? prepare("share", now, via2) : prepare("share", now, "voyager", 3);
|
|
3632
3989
|
if ("ok" in ctx) return ctx;
|
|
3990
|
+
const payload = {
|
|
3991
|
+
text: text2,
|
|
3992
|
+
visibility: vis
|
|
3993
|
+
};
|
|
3994
|
+
const summary = [authorLine(ctx.transport), `content "${text2}"`, `audience ${vis}`];
|
|
3995
|
+
if (loaded !== void 0) {
|
|
3996
|
+
payload.media = loaded.approved;
|
|
3997
|
+
const { filename, kind, size, sha256 } = loaded.approved;
|
|
3998
|
+
summary.push(
|
|
3999
|
+
`${kind === "IMAGE" ? "image" : "video"} ${filename} (${Math.ceil(size / 1024)} KB, sha256 ${sha256.slice(0, 12)})`
|
|
4000
|
+
);
|
|
4001
|
+
}
|
|
3633
4002
|
const plan = {
|
|
3634
4003
|
action: "post to your feed",
|
|
3635
|
-
payload
|
|
3636
|
-
summary
|
|
4004
|
+
payload,
|
|
4005
|
+
summary,
|
|
3637
4006
|
reversibility: "deletable with `lnrelay delete <urn>`, but it is public under your name the moment it lands and anyone who saw it cannot un-see it",
|
|
3638
4007
|
transport: ctx.transport.kind
|
|
3639
4008
|
};
|
|
@@ -3642,7 +4011,7 @@ async function runShare(text2, visibility, now = Date.now(), deps = terminalDeps
|
|
|
3642
4011
|
const result = ctx.transport.kind === "oauth" ? await share2(gated.confirmed, ctx.transport.token, {
|
|
3643
4012
|
fetch: globalThis.fetch,
|
|
3644
4013
|
now: () => now
|
|
3645
|
-
}) : await share(gated.confirmed, createLiveClient(ctx.transport.session));
|
|
4014
|
+
}) : await share(gated.confirmed, createLiveClient(ctx.transport.session), loaded?.bytes);
|
|
3646
4015
|
if (!result.ok) return err("share", result.code, result.message, result.hint);
|
|
3647
4016
|
return ok("share", {
|
|
3648
4017
|
id: result.id ?? null,
|
|
@@ -3706,14 +4075,8 @@ async function runComment(postUrn2, text2, now = Date.now(), deps = terminalDeps
|
|
|
3706
4075
|
"Pass urn:li:activity:<id>."
|
|
3707
4076
|
);
|
|
3708
4077
|
}
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
"comment",
|
|
3712
|
-
"CONFIRMATION_REQUIRED",
|
|
3713
|
-
"commenting needs a human to confirm it at an interactive terminal",
|
|
3714
|
-
"No terminal is attached, so nothing was sent and no network call was made."
|
|
3715
|
-
);
|
|
3716
|
-
}
|
|
4078
|
+
const unapprovable = refuseUnapprovable("comment", "commenting", deps);
|
|
4079
|
+
if (unapprovable !== null) return unapprovable;
|
|
3717
4080
|
const ctx = prepare("comment", now, "voyager");
|
|
3718
4081
|
if ("ok" in ctx) return ctx;
|
|
3719
4082
|
if (ctx.transport.kind !== "voyager") {
|
|
@@ -3725,6 +4088,9 @@ async function runComment(postUrn2, text2, now = Date.now(), deps = terminalDeps
|
|
|
3725
4088
|
const plan = {
|
|
3726
4089
|
action: "comment on a post",
|
|
3727
4090
|
payload: { activityId, text: text2, tokens: harvested.tokens },
|
|
4091
|
+
// The harvested trackingId changes on every render, so --plan and --confirm
|
|
4092
|
+
// would never agree on a token derived from it. The intent is what's approved.
|
|
4093
|
+
tokenBasis: { activityId, text: text2 },
|
|
3728
4094
|
summary: [authorLine(ctx.transport), `on ${postUrn2}`, `content "${text2}"`],
|
|
3729
4095
|
reversibility: "deletable with `lnrelay delete <comment-urn>`; the author is notified immediately",
|
|
3730
4096
|
transport: "voyager"
|
|
@@ -3755,14 +4121,8 @@ async function runEdit(commentUrn, text2, now = Date.now(), deps = terminalDeps(
|
|
|
3755
4121
|
"Only comments can be edited here \u2014 a published post cannot. Get the urn from `lnrelay post <activity-urn>`."
|
|
3756
4122
|
);
|
|
3757
4123
|
}
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
"edit",
|
|
3761
|
-
"CONFIRMATION_REQUIRED",
|
|
3762
|
-
"editing needs a human to confirm it at an interactive terminal",
|
|
3763
|
-
"No terminal is attached, so nothing was sent and no network call was made."
|
|
3764
|
-
);
|
|
3765
|
-
}
|
|
4124
|
+
const unapprovable = refuseUnapprovable("edit", "editing", deps);
|
|
4125
|
+
if (unapprovable !== null) return unapprovable;
|
|
3766
4126
|
const ctx = prepare("edit", now, "voyager");
|
|
3767
4127
|
if ("ok" in ctx) return ctx;
|
|
3768
4128
|
if (ctx.transport.kind !== "voyager") {
|
|
@@ -3846,14 +4206,8 @@ async function runReply(commentUrn, text2, now = Date.now(), deps = terminalDeps
|
|
|
3846
4206
|
"To comment on a POST, use `lnrelay comment <activity-urn>`. Comment urns come from `lnrelay post <activity-urn>`."
|
|
3847
4207
|
);
|
|
3848
4208
|
}
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
"reply",
|
|
3852
|
-
"CONFIRMATION_REQUIRED",
|
|
3853
|
-
"replying needs a human to confirm it at an interactive terminal",
|
|
3854
|
-
"No terminal is attached, so nothing was sent and no network call was made."
|
|
3855
|
-
);
|
|
3856
|
-
}
|
|
4209
|
+
const unapprovable = refuseUnapprovable("reply", "replying", deps);
|
|
4210
|
+
if (unapprovable !== null) return unapprovable;
|
|
3857
4211
|
const ctx = prepare("reply", now, "voyager");
|
|
3858
4212
|
if ("ok" in ctx) return ctx;
|
|
3859
4213
|
if (ctx.transport.kind !== "voyager") {
|
|
@@ -3877,7 +4231,7 @@ async function runReply(commentUrn, text2, now = Date.now(), deps = terminalDeps
|
|
|
3877
4231
|
|
|
3878
4232
|
// src/entry.ts
|
|
3879
4233
|
import { realpathSync } from "fs";
|
|
3880
|
-
import { basename } from "path";
|
|
4234
|
+
import { basename as basename2 } from "path";
|
|
3881
4235
|
import { fileURLToPath } from "url";
|
|
3882
4236
|
function isMainModule(argv1, moduleUrl, importMetaMain) {
|
|
3883
4237
|
if (importMetaMain === true) return true;
|
|
@@ -3892,7 +4246,7 @@ function isMainModule(argv1, moduleUrl, importMetaMain) {
|
|
|
3892
4246
|
}
|
|
3893
4247
|
function shouldForceEntry(argv1, binNames) {
|
|
3894
4248
|
if (argv1 === void 0) return false;
|
|
3895
|
-
return binNames.includes(
|
|
4249
|
+
return binNames.includes(basename2(argv1));
|
|
3896
4250
|
}
|
|
3897
4251
|
function shouldRunAsEntry(argv1, moduleUrl, importMetaMain, binNames) {
|
|
3898
4252
|
if (isMainModule(argv1, moduleUrl, importMetaMain)) {
|
|
@@ -3967,7 +4321,10 @@ async function dispatch(argv, now) {
|
|
|
3967
4321
|
`Usage when it lands: ${def.usage.split("\n")[0]}. See docs/PLAN.md for the phase it belongs to.`
|
|
3968
4322
|
);
|
|
3969
4323
|
}
|
|
4324
|
+
if (def.risk === "write") return write(command, args, now);
|
|
3970
4325
|
switch (command) {
|
|
4326
|
+
case "approval":
|
|
4327
|
+
return args.positionals[0] === "set" ? runApprovalSet(args.positionals[1], terminalDeps()) : runApprovalShow();
|
|
3971
4328
|
case "doctor":
|
|
3972
4329
|
return runDoctor(now, bool(args, "offline"));
|
|
3973
4330
|
case "budget":
|
|
@@ -4009,40 +4366,6 @@ async function dispatch(argv, now) {
|
|
|
4009
4366
|
return runLogin();
|
|
4010
4367
|
case "oauth":
|
|
4011
4368
|
return oauth(args);
|
|
4012
|
-
case "share": {
|
|
4013
|
-
const surface = via(args);
|
|
4014
|
-
if (surface === "invalid") {
|
|
4015
|
-
return err(
|
|
4016
|
-
"share",
|
|
4017
|
-
"INVALID_INPUT",
|
|
4018
|
-
`unknown --via '${str(args, "via") ?? ""}'`,
|
|
4019
|
-
"one of: oauth, voyager. Omit it to prefer OAuth and fall back to Voyager."
|
|
4020
|
-
);
|
|
4021
|
-
}
|
|
4022
|
-
return runShare(
|
|
4023
|
-
args.positionals[0],
|
|
4024
|
-
str(args, "visibility") ?? "public",
|
|
4025
|
-
now,
|
|
4026
|
-
void 0,
|
|
4027
|
-
surface
|
|
4028
|
-
);
|
|
4029
|
-
}
|
|
4030
|
-
case "comment":
|
|
4031
|
-
return runComment(args.positionals[0], args.positionals[1], now);
|
|
4032
|
-
case "edit":
|
|
4033
|
-
return runEdit(args.positionals[0], args.positionals[1], now);
|
|
4034
|
-
case "reply":
|
|
4035
|
-
return runReply(args.positionals[0], args.positionals[1], now);
|
|
4036
|
-
case "react":
|
|
4037
|
-
return runReact(
|
|
4038
|
-
args.positionals[0],
|
|
4039
|
-
str(args, "type") ?? "LIKE",
|
|
4040
|
-
now,
|
|
4041
|
-
void 0,
|
|
4042
|
-
bool(args, "remove")
|
|
4043
|
-
);
|
|
4044
|
-
case "delete":
|
|
4045
|
-
return runDelete(args.positionals[0], now, void 0, bool(args, "quiet"));
|
|
4046
4369
|
case "whoami":
|
|
4047
4370
|
return runWhoami(bool(args, "raw"));
|
|
4048
4371
|
case "profile":
|
|
@@ -4083,6 +4406,81 @@ if (entry.run) {
|
|
|
4083
4406
|
`);
|
|
4084
4407
|
process.exit(exitCodeFor(envelope));
|
|
4085
4408
|
}
|
|
4409
|
+
async function write(command, args, now) {
|
|
4410
|
+
if (args.flags.confirm === true) {
|
|
4411
|
+
return err(
|
|
4412
|
+
command,
|
|
4413
|
+
"INVALID_INPUT",
|
|
4414
|
+
"--confirm needs the token that --plan returned",
|
|
4415
|
+
`lnrelay ${command} \u2026 --plan, then the same command with --confirm <token>`
|
|
4416
|
+
);
|
|
4417
|
+
}
|
|
4418
|
+
const mode = loadApprovalMode();
|
|
4419
|
+
if (!mode.ok) return err(command, "CACHE_CORRUPT", mode.message, mode.hint);
|
|
4420
|
+
const deps = {
|
|
4421
|
+
...terminalDeps(),
|
|
4422
|
+
approval: { mode: mode.mode, token: str(args, "confirm"), planOnly: bool(args, "plan") }
|
|
4423
|
+
};
|
|
4424
|
+
const envelope = await runWrite(command, args, now, deps);
|
|
4425
|
+
if (wasApproved()) auditOutcome(command, mode.mode, envelope);
|
|
4426
|
+
return envelope;
|
|
4427
|
+
}
|
|
4428
|
+
function runWrite(command, args, now, deps) {
|
|
4429
|
+
const [first, second] = args.positionals;
|
|
4430
|
+
switch (command) {
|
|
4431
|
+
case "share":
|
|
4432
|
+
return share3(args, now, deps);
|
|
4433
|
+
case "comment":
|
|
4434
|
+
return runComment(first, second, now, deps);
|
|
4435
|
+
case "edit":
|
|
4436
|
+
return runEdit(first, second, now, deps);
|
|
4437
|
+
case "reply":
|
|
4438
|
+
return runReply(first, second, now, deps);
|
|
4439
|
+
case "react":
|
|
4440
|
+
return runReact(first, str(args, "type") ?? "LIKE", now, deps, bool(args, "remove"));
|
|
4441
|
+
case "delete":
|
|
4442
|
+
return runDelete(first, now, deps, bool(args, "quiet"));
|
|
4443
|
+
default:
|
|
4444
|
+
return err(command, "NOT_IMPLEMENTED", `'${command}' has no write runner`);
|
|
4445
|
+
}
|
|
4446
|
+
}
|
|
4447
|
+
function share3(args, now, deps) {
|
|
4448
|
+
const surface = via(args);
|
|
4449
|
+
if (surface === "invalid") {
|
|
4450
|
+
return err(
|
|
4451
|
+
"share",
|
|
4452
|
+
"INVALID_INPUT",
|
|
4453
|
+
`unknown --via '${str(args, "via") ?? ""}'`,
|
|
4454
|
+
"one of: oauth, voyager. Omit it to prefer OAuth and fall back to Voyager."
|
|
4455
|
+
);
|
|
4456
|
+
}
|
|
4457
|
+
for (const flag of ["image", "video"]) {
|
|
4458
|
+
if (args.flags[flag] === true) {
|
|
4459
|
+
return err("share", "INVALID_INPUT", `--${flag} needs a file path`);
|
|
4460
|
+
}
|
|
4461
|
+
}
|
|
4462
|
+
const image = str(args, "image");
|
|
4463
|
+
const video = str(args, "video");
|
|
4464
|
+
if (image !== void 0 && video !== void 0) {
|
|
4465
|
+
return err(
|
|
4466
|
+
"share",
|
|
4467
|
+
"INVALID_INPUT",
|
|
4468
|
+
"a post carries an image or a video, not both",
|
|
4469
|
+
"pass one of --image <path> or --video <path>"
|
|
4470
|
+
);
|
|
4471
|
+
}
|
|
4472
|
+
let media;
|
|
4473
|
+
if (image !== void 0) media = { flag: "image", path: image };
|
|
4474
|
+
else if (video !== void 0) media = { flag: "video", path: video };
|
|
4475
|
+
return runShare(
|
|
4476
|
+
args.positionals[0],
|
|
4477
|
+
str(args, "visibility") ?? "public",
|
|
4478
|
+
now,
|
|
4479
|
+
deps,
|
|
4480
|
+
surface,
|
|
4481
|
+
media
|
|
4482
|
+
);
|
|
4483
|
+
}
|
|
4086
4484
|
export {
|
|
4087
4485
|
dispatch
|
|
4088
4486
|
};
|