linkedin-relay-mcp 3.3.0 → 3.5.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 +8 -2
- package/dist/cli.js +418 -73
- package/dist/cli.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp-shim.js +14 -3
- package/dist/mcp-shim.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1330,6 +1330,17 @@ var CONTRACTS = {
|
|
|
1330
1330
|
// KNOWN INCOMPLETE (2026-08-13): with the namespace fixed this returns the
|
|
1331
1331
|
// owner's posts, but a post created minutes earlier did not appear here, nor
|
|
1332
1332
|
// in `feed`, over ~1.5 hours. Whether that is an indexing lag or a coverage
|
|
1333
|
+
// A WRITE contract: creates a poll object that a post then references. The
|
|
1334
|
+
// queryId is from mguttmann/linkedin-internal-api (docs/24) and returned a
|
|
1335
|
+
// pollSummary urn on this machine on the date below.
|
|
1336
|
+
createPoll: {
|
|
1337
|
+
name: "createPoll",
|
|
1338
|
+
transport: "voyager-graphql",
|
|
1339
|
+
path: `${VOYAGER}/graphql`,
|
|
1340
|
+
queryId: "voyagerFeedDashPollsPollSummary.f8ad99cf791d833d37dddb373d06fb3a",
|
|
1341
|
+
provenance: "verified",
|
|
1342
|
+
capturedAt: "2026-10-13"
|
|
1343
|
+
},
|
|
1333
1344
|
// limit of this projection is UNRESOLVED — do not treat this endpoint as an
|
|
1334
1345
|
// authoritative "all my posts" until it is settled.
|
|
1335
1346
|
myPosts: {
|
|
@@ -2154,7 +2165,9 @@ var TYPES = {
|
|
|
2154
2165
|
gif: { kind: "IMAGE", contentType: "image/gif" },
|
|
2155
2166
|
webp: { kind: "IMAGE", contentType: "image/webp" },
|
|
2156
2167
|
mp4: { kind: "VIDEO", contentType: "video/mp4" },
|
|
2157
|
-
mov: { kind: "VIDEO", contentType: "video/quicktime" }
|
|
2168
|
+
mov: { kind: "VIDEO", contentType: "video/quicktime" },
|
|
2169
|
+
// LinkedIn also takes ppt/pptx/doc/docx; only pdf has been verified here.
|
|
2170
|
+
pdf: { kind: "DOCUMENT", contentType: "application/pdf" }
|
|
2158
2171
|
};
|
|
2159
2172
|
function mediaKindOf(filename) {
|
|
2160
2173
|
const ext = /\.([a-z0-9]+)$/i.exec(filename)?.[1]?.toLowerCase();
|
|
@@ -2162,7 +2175,7 @@ function mediaKindOf(filename) {
|
|
|
2162
2175
|
}
|
|
2163
2176
|
function registerPayload(kind, fileSize, filename) {
|
|
2164
2177
|
return {
|
|
2165
|
-
mediaUploadType: kind
|
|
2178
|
+
mediaUploadType: `${kind}_SHARING`,
|
|
2166
2179
|
fileSize,
|
|
2167
2180
|
filename
|
|
2168
2181
|
};
|
|
@@ -2231,20 +2244,28 @@ async function uploadMedia(file, client) {
|
|
|
2231
2244
|
// src/engine/voyager-write.ts
|
|
2232
2245
|
var VOYAGER2 = "https://www.linkedin.com/voyager/api";
|
|
2233
2246
|
var SHARE_URL = `${VOYAGER2}/contentcreation/normShares`;
|
|
2234
|
-
|
|
2247
|
+
var CATEGORY = {
|
|
2248
|
+
POLL: "URN_REFERENCE",
|
|
2249
|
+
IMAGE: "IMAGE",
|
|
2250
|
+
VIDEO: "VIDEO",
|
|
2251
|
+
DOCUMENT: "NATIVE_DOCUMENT"
|
|
2252
|
+
};
|
|
2253
|
+
function sharePayload(text2, visibility, media = [], scheduledAt) {
|
|
2254
|
+
const schedule = scheduledAt === void 0 ? { postState: "PUBLISHED" } : { postState: "SCHEDULED", scheduledAt };
|
|
2235
2255
|
return {
|
|
2236
2256
|
visibleToConnectionsOnly: visibility === "CONNECTIONS",
|
|
2237
2257
|
externalAudienceProviders: [],
|
|
2238
2258
|
commentaryV2: { text: text2, attributes: [] },
|
|
2239
2259
|
origin: "FEED",
|
|
2240
2260
|
allowedCommentersScope: "ALL",
|
|
2241
|
-
|
|
2261
|
+
...schedule,
|
|
2242
2262
|
// altText only when given, so a post without it keeps the body verified in 2026-08.
|
|
2243
2263
|
media: media.map((m) => ({
|
|
2244
|
-
category: m.category,
|
|
2264
|
+
category: CATEGORY[m.category],
|
|
2245
2265
|
mediaUrn: m.urn,
|
|
2246
2266
|
tapTargets: [],
|
|
2247
|
-
...m.alt === void 0 ? {} : { altText: m.alt }
|
|
2267
|
+
...m.alt === void 0 ? {} : { altText: m.alt },
|
|
2268
|
+
...m.title === void 0 ? {} : { title: { text: m.title } }
|
|
2248
2269
|
}))
|
|
2249
2270
|
};
|
|
2250
2271
|
}
|
|
@@ -2297,6 +2318,12 @@ async function share(confirmed, client, bytes) {
|
|
|
2297
2318
|
}
|
|
2298
2319
|
}
|
|
2299
2320
|
const media = [];
|
|
2321
|
+
const { poll } = confirmed.payload;
|
|
2322
|
+
if (poll !== void 0) {
|
|
2323
|
+
const created = await createPoll(poll, client);
|
|
2324
|
+
if (!created.ok) return created;
|
|
2325
|
+
media.push({ category: "POLL", urn: created.urn });
|
|
2326
|
+
}
|
|
2300
2327
|
for (const [i, a] of approved.entries()) {
|
|
2301
2328
|
const uploaded = await uploadMedia(
|
|
2302
2329
|
{
|
|
@@ -2311,10 +2338,16 @@ async function share(confirmed, client, bytes) {
|
|
|
2311
2338
|
media.push({
|
|
2312
2339
|
category: a.kind,
|
|
2313
2340
|
urn: uploaded.urn,
|
|
2314
|
-
...a.alt === void 0 ? {} : { alt: a.alt }
|
|
2341
|
+
...a.alt === void 0 ? {} : { alt: a.alt },
|
|
2342
|
+
...a.title === void 0 ? {} : { title: a.title }
|
|
2315
2343
|
});
|
|
2316
2344
|
}
|
|
2317
|
-
const body = sharePayload(
|
|
2345
|
+
const body = sharePayload(
|
|
2346
|
+
confirmed.payload.text,
|
|
2347
|
+
confirmed.payload.visibility,
|
|
2348
|
+
media,
|
|
2349
|
+
confirmed.payload.scheduledAt
|
|
2350
|
+
);
|
|
2318
2351
|
const result = await client.request({
|
|
2319
2352
|
url: SHARE_URL,
|
|
2320
2353
|
method: "POST",
|
|
@@ -2334,6 +2367,85 @@ async function share(confirmed, client, bytes) {
|
|
|
2334
2367
|
note: "LinkedIn accepted the post but the response carried no recognisable urn. Run `lnrelay sync my-posts && lnrelay my-posts` to confirm what actually landed \u2014 and do NOT re-run this command on the assumption it failed, or you will post twice."
|
|
2335
2368
|
} : { ok: true, id };
|
|
2336
2369
|
}
|
|
2370
|
+
function editPostBody(text2) {
|
|
2371
|
+
return { patch: { $set: { commentaryV2: { text: text2, attributes: [] } } } };
|
|
2372
|
+
}
|
|
2373
|
+
async function editPost(confirmed, client) {
|
|
2374
|
+
const { urn, text: text2 } = confirmed.payload;
|
|
2375
|
+
const result = await client.request({
|
|
2376
|
+
url: deleteUrl(urn),
|
|
2377
|
+
method: "POST",
|
|
2378
|
+
body: editPostBody(text2),
|
|
2379
|
+
spendClass: "write",
|
|
2380
|
+
operation: "edit-post"
|
|
2381
|
+
});
|
|
2382
|
+
if (!result.ok) {
|
|
2383
|
+
const out = { ok: false, code: result.code, message: result.message };
|
|
2384
|
+
if (result.hint !== void 0) out.hint = result.hint;
|
|
2385
|
+
return out;
|
|
2386
|
+
}
|
|
2387
|
+
const held = result.json?.data?.commentary?.text;
|
|
2388
|
+
if (held !== text2) {
|
|
2389
|
+
return {
|
|
2390
|
+
ok: false,
|
|
2391
|
+
code: "SCHEMA_DRIFT",
|
|
2392
|
+
message: "LinkedIn answered, but the post does not hold the text that was sent",
|
|
2393
|
+
hint: `Look at the post before trying again: \`lnrelay post\` or the browser. ${urn}`
|
|
2394
|
+
};
|
|
2395
|
+
}
|
|
2396
|
+
return { ok: true, id: urn };
|
|
2397
|
+
}
|
|
2398
|
+
var DURATIONS = {
|
|
2399
|
+
"1d": "ONE_DAY",
|
|
2400
|
+
"3d": "THREE_DAYS",
|
|
2401
|
+
"1w": "ONE_WEEK",
|
|
2402
|
+
"2w": "TWO_WEEKS"
|
|
2403
|
+
};
|
|
2404
|
+
function pollDuration(shorthand) {
|
|
2405
|
+
return DURATIONS[shorthand] ?? null;
|
|
2406
|
+
}
|
|
2407
|
+
function gqlError(json) {
|
|
2408
|
+
const j = json;
|
|
2409
|
+
const errors = j?.errors ?? j?.data?.errors;
|
|
2410
|
+
return errors !== void 0 && errors.length > 0 ? errors[0]?.message ?? "GraphQL error" : null;
|
|
2411
|
+
}
|
|
2412
|
+
function pollUrnOf(json) {
|
|
2413
|
+
if (gqlError(json) !== null) return null;
|
|
2414
|
+
return JSON.stringify(json ?? null).match(/urn:li:fsd_pollSummary:\d+/)?.[0] ?? null;
|
|
2415
|
+
}
|
|
2416
|
+
async function createPoll(poll, client) {
|
|
2417
|
+
const contract = contractFor("createPoll");
|
|
2418
|
+
if (contract?.queryId === void 0) {
|
|
2419
|
+
return { ok: false, code: "NOT_IMPLEMENTED", message: "no verified poll contract" };
|
|
2420
|
+
}
|
|
2421
|
+
const result = await client.request({
|
|
2422
|
+
url: `${contract.path}?action=execute&queryId=${contract.queryId}`,
|
|
2423
|
+
method: "POST",
|
|
2424
|
+
body: { variables: { poll }, queryId: contract.queryId, includeWebMetadata: true },
|
|
2425
|
+
spendClass: "write",
|
|
2426
|
+
operation: "create-poll"
|
|
2427
|
+
});
|
|
2428
|
+
if (!result.ok)
|
|
2429
|
+
return { ok: false, code: result.code, message: `${result.message}; nothing was posted` };
|
|
2430
|
+
const error = gqlError(result.json);
|
|
2431
|
+
if (error !== null) {
|
|
2432
|
+
return {
|
|
2433
|
+
ok: false,
|
|
2434
|
+
code: "INVALID_INPUT",
|
|
2435
|
+
message: `LinkedIn refused the poll: ${error}; nothing was posted`
|
|
2436
|
+
};
|
|
2437
|
+
}
|
|
2438
|
+
const urn = pollUrnOf(result.json);
|
|
2439
|
+
if (urn === null) {
|
|
2440
|
+
return {
|
|
2441
|
+
ok: false,
|
|
2442
|
+
code: "SCHEMA_DRIFT",
|
|
2443
|
+
message: "the poll mutation answered without a poll urn; nothing was posted",
|
|
2444
|
+
hint: "The queryId may have rotated \u2014 recapture it (docs/ENGINE-RESEARCH.md)."
|
|
2445
|
+
};
|
|
2446
|
+
}
|
|
2447
|
+
return { ok: true, urn };
|
|
2448
|
+
}
|
|
2337
2449
|
|
|
2338
2450
|
// src/commands/gate.ts
|
|
2339
2451
|
import { createInterface } from "readline/promises";
|
|
@@ -2427,7 +2539,8 @@ function previewLines2(post) {
|
|
|
2427
2539
|
if (post === void 0) {
|
|
2428
2540
|
return [
|
|
2429
2541
|
"content COULD NOT READ THIS POST.",
|
|
2430
|
-
" It is not among your recent posts. That
|
|
2542
|
+
" It is not among your recent published posts. That is expected for a",
|
|
2543
|
+
" scheduled post (deleting one cancels it), and may also mean it is older",
|
|
2431
2544
|
" than the page fetched \u2014 but nothing here has verified what you are",
|
|
2432
2545
|
" about to delete, or that it is yours."
|
|
2433
2546
|
];
|
|
@@ -3325,7 +3438,7 @@ var COMMANDS = [
|
|
|
3325
3438
|
name: "share",
|
|
3326
3439
|
cost: "1 call \u2014 write",
|
|
3327
3440
|
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.",
|
|
3328
|
-
usage: 'lnrelay share "<text>" [--image <path> ... | --video <path>] [--
|
|
3441
|
+
usage: 'lnrelay share "<text>" [--image <path> ... [--alt "<text>" ...] | --video <path>\n | --document <pdf> --title "<title>"] [--at "YYYY-MM-DD HH:MM"]\n [--poll "<question>" --option "<a>" --option "<b>" ... [--duration 1d|3d|1w|2w]]\n [--visibility public|connections] [--via oauth|voyager] [--plan | --confirm <token>]\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 repeats for up to 20, --alt pairs with it by position (--alt ""\n skips one). --at schedules it (local time, or ISO 8601 with an offset; at least 10\n minutes out); LinkedIn publishes it then, and `lnrelay delete <urn>` cancels it.\n --poll takes 2-4 --option and cannot be scheduled yet. Files, documents, polls and\n scheduling go over the private API only.',
|
|
3329
3442
|
audience: ["cli"],
|
|
3330
3443
|
risk: "write",
|
|
3331
3444
|
implemented: true
|
|
@@ -3360,8 +3473,8 @@ var COMMANDS = [
|
|
|
3360
3473
|
{
|
|
3361
3474
|
name: "edit",
|
|
3362
3475
|
cost: "1 read + 1 write",
|
|
3363
|
-
summary: "Change the text of a comment you wrote. Its own verb, so a comment urn can never be mistaken for something to comment ON.",
|
|
3364
|
-
usage: 'lnrelay edit <comment-urn> "<text>"',
|
|
3476
|
+
summary: "Change the text of a comment or post you wrote. Its own verb, so a comment urn can never be mistaken for something to comment ON.",
|
|
3477
|
+
usage: 'lnrelay edit <comment-urn | share-urn | ugcPost-urn> "<text>"\n A post is edited by the urn it was created as (`share` prints it; `my-posts` lists\n it as shareUrn), not its activity urn. The whole text is replaced.',
|
|
3365
3478
|
audience: ["cli"],
|
|
3366
3479
|
risk: "write",
|
|
3367
3480
|
implemented: true
|
|
@@ -3956,20 +4069,53 @@ async function gate(command, plan, ctx, deps) {
|
|
|
3956
4069
|
if ("ok" in gated) return gated;
|
|
3957
4070
|
return { confirmed: gated.confirmed };
|
|
3958
4071
|
}
|
|
4072
|
+
var FLAG_KIND = {
|
|
4073
|
+
image: "IMAGE",
|
|
4074
|
+
video: "VIDEO",
|
|
4075
|
+
document: "DOCUMENT"
|
|
4076
|
+
};
|
|
4077
|
+
var KIND_FLAG = {
|
|
4078
|
+
IMAGE: "--image",
|
|
4079
|
+
VIDEO: "--video",
|
|
4080
|
+
DOCUMENT: "--document"
|
|
4081
|
+
};
|
|
4082
|
+
var KIND_WORD = {
|
|
4083
|
+
IMAGE: "image ",
|
|
4084
|
+
VIDEO: "video ",
|
|
4085
|
+
DOCUMENT: "document"
|
|
4086
|
+
};
|
|
3959
4087
|
function mediaLines(media) {
|
|
3960
|
-
return media.flatMap(({ filename, kind, size, sha256, alt }) => [
|
|
3961
|
-
`${kind
|
|
3962
|
-
...alt === void 0 ? [] : [` alt "${alt}"`]
|
|
4088
|
+
return media.flatMap(({ filename, kind, size, sha256, alt, title }) => [
|
|
4089
|
+
`${KIND_WORD[kind]} ${filename} (${Math.ceil(size / 1024)} KB, sha256 ${sha256.slice(0, 12)})`,
|
|
4090
|
+
...alt === void 0 ? [] : [` alt "${alt}"`],
|
|
4091
|
+
...title === void 0 ? [] : [` title "${title}"`]
|
|
3963
4092
|
]);
|
|
3964
4093
|
}
|
|
3965
4094
|
var MAX_IMAGES = 20;
|
|
3966
|
-
function
|
|
4095
|
+
function mediaRequestError(media) {
|
|
3967
4096
|
const alts = media.alts ?? [];
|
|
3968
|
-
|
|
3969
|
-
|
|
4097
|
+
const single = media.flag !== "image";
|
|
4098
|
+
if (single && media.paths.length > 1) {
|
|
4099
|
+
return err(
|
|
4100
|
+
"share",
|
|
4101
|
+
"INVALID_INPUT",
|
|
4102
|
+
`a post carries one ${media.flag}`,
|
|
4103
|
+
`pass a single --${media.flag}`
|
|
4104
|
+
);
|
|
3970
4105
|
}
|
|
3971
|
-
if (media.flag
|
|
3972
|
-
return err("share", "INVALID_INPUT",
|
|
4106
|
+
if (media.flag !== "image" && alts.length > 0) {
|
|
4107
|
+
return err("share", "INVALID_INPUT", `--alt applies to images, not a ${media.flag}`);
|
|
4108
|
+
}
|
|
4109
|
+
if (media.flag === "document" && (media.title ?? "").trim() === "") {
|
|
4110
|
+
return err(
|
|
4111
|
+
"share",
|
|
4112
|
+
"INVALID_INPUT",
|
|
4113
|
+
"a document needs a title",
|
|
4114
|
+
'pass --title "<what readers see above the document>"'
|
|
4115
|
+
);
|
|
4116
|
+
}
|
|
4117
|
+
if (media.flag !== "document" && media.title !== void 0) {
|
|
4118
|
+
return err("share", "INVALID_INPUT", "--title applies to a --document");
|
|
3973
4119
|
}
|
|
3974
4120
|
if (media.paths.length > MAX_IMAGES) {
|
|
3975
4121
|
return err("share", "INVALID_INPUT", `a post carries at most ${MAX_IMAGES} images`);
|
|
@@ -3982,48 +4128,54 @@ function loadAllMedia(media) {
|
|
|
3982
4128
|
'give one --alt per --image, in the same order; pass --alt "" for an image without one'
|
|
3983
4129
|
);
|
|
3984
4130
|
}
|
|
4131
|
+
return null;
|
|
4132
|
+
}
|
|
4133
|
+
function loadAllMedia(media) {
|
|
4134
|
+
const refused = mediaRequestError(media);
|
|
4135
|
+
if (refused !== null) return refused;
|
|
4136
|
+
const alts = media.alts ?? [];
|
|
3985
4137
|
const approved = [];
|
|
3986
4138
|
const bytes = [];
|
|
3987
4139
|
for (const [i, path] of media.paths.entries()) {
|
|
3988
|
-
const one = loadMedia(
|
|
4140
|
+
const one = loadMedia(media.flag, path);
|
|
3989
4141
|
if ("ok" in one) return one;
|
|
3990
4142
|
const alt = alts[i];
|
|
3991
|
-
|
|
4143
|
+
let a = alt === void 0 || alt === "" ? one.approved : { ...one.approved, alt };
|
|
4144
|
+
if (media.flag === "document") a = { ...a, title: (media.title ?? "").trim() };
|
|
4145
|
+
approved.push(a);
|
|
3992
4146
|
bytes.push(one.bytes);
|
|
3993
4147
|
}
|
|
3994
4148
|
return { approved, bytes };
|
|
3995
4149
|
}
|
|
3996
|
-
function loadMedia(
|
|
3997
|
-
const kind = mediaKindOf(
|
|
4150
|
+
function loadMedia(flag, path) {
|
|
4151
|
+
const kind = mediaKindOf(path);
|
|
3998
4152
|
if (kind === null) {
|
|
3999
4153
|
return err(
|
|
4000
4154
|
"share",
|
|
4001
4155
|
"INVALID_INPUT",
|
|
4002
|
-
`unsupported file type: ${basename(
|
|
4003
|
-
"images: png, jpg, jpeg, gif, webp. videos: mp4, mov."
|
|
4156
|
+
`unsupported file type: ${basename(path)}`,
|
|
4157
|
+
"images: png, jpg, jpeg, gif, webp. videos: mp4, mov. documents: pdf."
|
|
4004
4158
|
);
|
|
4005
4159
|
}
|
|
4006
|
-
|
|
4007
|
-
if (kind.kind !== expected) {
|
|
4008
|
-
const right = kind.kind === "IMAGE" ? "--image" : "--video";
|
|
4160
|
+
if (kind.kind !== FLAG_KIND[flag]) {
|
|
4009
4161
|
return err(
|
|
4010
4162
|
"share",
|
|
4011
4163
|
"INVALID_INPUT",
|
|
4012
|
-
`${basename(
|
|
4013
|
-
`pass it with ${
|
|
4164
|
+
`${basename(path)} is not ${flag === "image" ? "an image" : `a ${flag}`}`,
|
|
4165
|
+
`pass it with ${KIND_FLAG[kind.kind]}`
|
|
4014
4166
|
);
|
|
4015
4167
|
}
|
|
4016
4168
|
let bytes;
|
|
4017
4169
|
try {
|
|
4018
|
-
if (!statSync(
|
|
4019
|
-
bytes = new Uint8Array(readFileSync2(
|
|
4170
|
+
if (!statSync(path).isFile()) throw new Error("not a file");
|
|
4171
|
+
bytes = new Uint8Array(readFileSync2(path));
|
|
4020
4172
|
} catch {
|
|
4021
|
-
return err("share", "INVALID_INPUT", `cannot read ${
|
|
4173
|
+
return err("share", "INVALID_INPUT", `cannot read ${path}`);
|
|
4022
4174
|
}
|
|
4023
4175
|
return {
|
|
4024
4176
|
bytes,
|
|
4025
4177
|
approved: {
|
|
4026
|
-
filename: basename(
|
|
4178
|
+
filename: basename(path),
|
|
4027
4179
|
kind: kind.kind,
|
|
4028
4180
|
contentType: kind.contentType,
|
|
4029
4181
|
size: bytes.byteLength,
|
|
@@ -4031,14 +4183,25 @@ function loadMedia(media) {
|
|
|
4031
4183
|
}
|
|
4032
4184
|
};
|
|
4033
4185
|
}
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
if (
|
|
4186
|
+
function parseScheduleTime(input) {
|
|
4187
|
+
const iso = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
|
|
4188
|
+
if (iso.test(input)) {
|
|
4189
|
+
const t = Date.parse(input);
|
|
4190
|
+
return Number.isNaN(t) ? null : t;
|
|
4191
|
+
}
|
|
4192
|
+
const local = /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2})$/.exec(input);
|
|
4193
|
+
if (local === null) return null;
|
|
4194
|
+
const [y, mo, d, h, mi] = local.slice(1).map(Number);
|
|
4195
|
+
const date = new Date(y, mo - 1, d, h, mi);
|
|
4196
|
+
const same = date.getFullYear() === y && date.getMonth() === mo - 1 && date.getDate() === d && date.getHours() === h && date.getMinutes() === mi;
|
|
4197
|
+
return same ? date.getTime() : null;
|
|
4198
|
+
}
|
|
4199
|
+
var MIN_LEAD_MS = 10 * 6e4;
|
|
4200
|
+
function mediaFrom(media, via2) {
|
|
4201
|
+
if (media === void 0 || media.paths.length === 0) return void 0;
|
|
4202
|
+
const loaded = loadAllMedia(media);
|
|
4203
|
+
if ("ok" in loaded) return loaded;
|
|
4204
|
+
if (via2 === "oauth") {
|
|
4042
4205
|
return err(
|
|
4043
4206
|
"share",
|
|
4044
4207
|
"NOT_IMPLEMENTED",
|
|
@@ -4046,24 +4209,143 @@ async function runShare(text2, visibility, now = Date.now(), deps = terminalDeps
|
|
|
4046
4209
|
"drop --via oauth, or pass --via voyager"
|
|
4047
4210
|
);
|
|
4048
4211
|
}
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
}
|
|
4060
|
-
const plan = {
|
|
4061
|
-
action: "post to your feed",
|
|
4212
|
+
return loaded;
|
|
4213
|
+
}
|
|
4214
|
+
function sharePlan(p) {
|
|
4215
|
+
const payload = { text: p.text, visibility: p.visibility };
|
|
4216
|
+
if (p.media !== void 0) payload.media = p.media;
|
|
4217
|
+
if (p.scheduledAt !== void 0) payload.scheduledAt = p.scheduledAt;
|
|
4218
|
+
if (p.poll !== void 0) payload.poll = p.poll;
|
|
4219
|
+
const scheduled = p.scheduledAt !== void 0;
|
|
4220
|
+
return {
|
|
4221
|
+
action: scheduled ? "schedule a post" : "post to your feed",
|
|
4062
4222
|
payload,
|
|
4063
|
-
summary
|
|
4064
|
-
|
|
4065
|
-
|
|
4223
|
+
summary: [
|
|
4224
|
+
p.author,
|
|
4225
|
+
`content "${p.text}"`,
|
|
4226
|
+
`audience ${p.visibility}`,
|
|
4227
|
+
...p.scheduledAt === void 0 ? [] : [whenLine(p.scheduledAt, p.now)],
|
|
4228
|
+
...p.poll === void 0 ? [] : pollLines(p.poll),
|
|
4229
|
+
...p.media === void 0 ? [] : mediaLines(p.media)
|
|
4230
|
+
],
|
|
4231
|
+
reversibility: scheduled ? "cancel any time before it publishes with `lnrelay delete <urn>`; after that it is public under your name like any post" : "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",
|
|
4232
|
+
transport: p.transport
|
|
4066
4233
|
};
|
|
4234
|
+
}
|
|
4235
|
+
function pollLines(poll) {
|
|
4236
|
+
return [
|
|
4237
|
+
`poll "${poll.question}"`,
|
|
4238
|
+
...poll.options.map((o, i) => ` ${i + 1}. ${o}`),
|
|
4239
|
+
` runs ${poll.duration}`
|
|
4240
|
+
];
|
|
4241
|
+
}
|
|
4242
|
+
function pollFrom(poll, ctx) {
|
|
4243
|
+
if (poll === void 0) return void 0;
|
|
4244
|
+
const refuse2 = (message, hint) => err("share", "INVALID_INPUT", message, hint);
|
|
4245
|
+
if (poll.question.trim() === "") return refuse2("a poll needs a question");
|
|
4246
|
+
const options = poll.options.map((o) => o.trim());
|
|
4247
|
+
if (options.length < 2 || options.length > 4 || options.some((o) => o === "")) {
|
|
4248
|
+
return refuse2("a poll needs 2 to 4 non-empty options", 'repeat --option "<text>" for each');
|
|
4249
|
+
}
|
|
4250
|
+
const duration = pollDuration(poll.duration ?? "1w");
|
|
4251
|
+
if (duration === null) {
|
|
4252
|
+
return refuse2(`unknown --duration '${poll.duration}'`, "one of: 1d, 3d, 1w, 2w");
|
|
4253
|
+
}
|
|
4254
|
+
if (ctx.hasMedia) return refuse2("a post carries a poll or files, not both");
|
|
4255
|
+
if (ctx.scheduled) {
|
|
4256
|
+
return refuse2(
|
|
4257
|
+
"a poll cannot be scheduled yet \u2014 its clock may start when it is created, not published",
|
|
4258
|
+
"post the poll now, or schedule a text post that asks the question"
|
|
4259
|
+
);
|
|
4260
|
+
}
|
|
4261
|
+
if (ctx.via === "oauth") {
|
|
4262
|
+
return err(
|
|
4263
|
+
"share",
|
|
4264
|
+
"NOT_IMPLEMENTED",
|
|
4265
|
+
"polls are only implemented over the private API",
|
|
4266
|
+
"drop --via oauth, or pass --via voyager"
|
|
4267
|
+
);
|
|
4268
|
+
}
|
|
4269
|
+
return { question: poll.question.trim(), options, duration };
|
|
4270
|
+
}
|
|
4271
|
+
function scheduleFrom(at, now, via2) {
|
|
4272
|
+
if (at === void 0) return void 0;
|
|
4273
|
+
const t = parseScheduleTime(at);
|
|
4274
|
+
if (t === null) {
|
|
4275
|
+
return err(
|
|
4276
|
+
"share",
|
|
4277
|
+
"INVALID_INPUT",
|
|
4278
|
+
`cannot read --at '${at}'`,
|
|
4279
|
+
'use "YYYY-MM-DD HH:MM" (local time) or ISO 8601 with an offset, e.g. 2026-10-20T14:00+02:00'
|
|
4280
|
+
);
|
|
4281
|
+
}
|
|
4282
|
+
if (t < now + MIN_LEAD_MS) {
|
|
4283
|
+
return err(
|
|
4284
|
+
"share",
|
|
4285
|
+
"INVALID_INPUT",
|
|
4286
|
+
"--at must be at least 10 minutes from now",
|
|
4287
|
+
"to post right away, leave --at out"
|
|
4288
|
+
);
|
|
4289
|
+
}
|
|
4290
|
+
if (via2 === "oauth") {
|
|
4291
|
+
return err(
|
|
4292
|
+
"share",
|
|
4293
|
+
"NOT_IMPLEMENTED",
|
|
4294
|
+
"scheduling is only implemented over the private API",
|
|
4295
|
+
"drop --via oauth, or pass --via voyager"
|
|
4296
|
+
);
|
|
4297
|
+
}
|
|
4298
|
+
return t;
|
|
4299
|
+
}
|
|
4300
|
+
function whenLine(at, now) {
|
|
4301
|
+
const zone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
4302
|
+
const local = new Date(at).toLocaleString("en-US", {
|
|
4303
|
+
weekday: "short",
|
|
4304
|
+
month: "short",
|
|
4305
|
+
day: "numeric",
|
|
4306
|
+
year: "numeric",
|
|
4307
|
+
hour: "2-digit",
|
|
4308
|
+
minute: "2-digit",
|
|
4309
|
+
hour12: false
|
|
4310
|
+
});
|
|
4311
|
+
const hours = Math.round((at - now) / 36e5);
|
|
4312
|
+
const away = hours < 48 ? `in ${hours} h` : `in ${Math.round(hours / 24)} days`;
|
|
4313
|
+
return `when ${local} (${zone}) \u2014 ${away}`;
|
|
4314
|
+
}
|
|
4315
|
+
async function runShare(text2, visibility, now = Date.now(), deps = terminalDeps(), via2, media, at, poll) {
|
|
4316
|
+
if (text2 === void 0 || text2.trim() === "") {
|
|
4317
|
+
return err("share", "INVALID_INPUT", "text is required", 'lnrelay share "<text>"');
|
|
4318
|
+
}
|
|
4319
|
+
const vis = visibility === "connections" ? "CONNECTIONS" : "PUBLIC";
|
|
4320
|
+
const scheduled = scheduleFrom(at, now, via2);
|
|
4321
|
+
if (typeof scheduled === "object") return scheduled;
|
|
4322
|
+
const scheduledAt = scheduled;
|
|
4323
|
+
const loaded = mediaFrom(media, via2);
|
|
4324
|
+
if (loaded !== void 0 && "ok" in loaded) return loaded;
|
|
4325
|
+
const pollSpec = pollFrom(poll, {
|
|
4326
|
+
hasMedia: loaded !== void 0,
|
|
4327
|
+
scheduled: scheduledAt !== void 0,
|
|
4328
|
+
via: via2
|
|
4329
|
+
});
|
|
4330
|
+
if (pollSpec !== void 0 && "ok" in pollSpec) return pollSpec;
|
|
4331
|
+
const voyagerOnly = loaded !== void 0 || scheduledAt !== void 0 || pollSpec !== void 0;
|
|
4332
|
+
const ctx = prepare(
|
|
4333
|
+
"share",
|
|
4334
|
+
now,
|
|
4335
|
+
voyagerOnly ? "voyager" : via2,
|
|
4336
|
+
2 * (loaded?.approved.length ?? 0) + (pollSpec === void 0 ? 0 : 1) + 1
|
|
4337
|
+
);
|
|
4338
|
+
if ("ok" in ctx) return ctx;
|
|
4339
|
+
const plan = sharePlan({
|
|
4340
|
+
author: authorLine(ctx.transport),
|
|
4341
|
+
transport: ctx.transport.kind,
|
|
4342
|
+
text: text2,
|
|
4343
|
+
visibility: vis,
|
|
4344
|
+
media: loaded?.approved,
|
|
4345
|
+
scheduledAt,
|
|
4346
|
+
poll: pollSpec,
|
|
4347
|
+
now
|
|
4348
|
+
});
|
|
4067
4349
|
const gated = await gate("share", plan, ctx, deps);
|
|
4068
4350
|
if ("ok" in gated) return gated;
|
|
4069
4351
|
const result = ctx.transport.kind === "oauth" ? await share2(gated.confirmed, ctx.transport.token, {
|
|
@@ -4074,10 +4356,41 @@ async function runShare(text2, visibility, now = Date.now(), deps = terminalDeps
|
|
|
4074
4356
|
return ok("share", {
|
|
4075
4357
|
id: result.id ?? null,
|
|
4076
4358
|
transport: ctx.transport.kind,
|
|
4359
|
+
scheduledFor: scheduledAt === void 0 ? void 0 : new Date(scheduledAt).toISOString(),
|
|
4077
4360
|
url: "url" in result ? result.url : void 0,
|
|
4078
4361
|
note: "note" in result ? result.note : ctx.note
|
|
4079
4362
|
});
|
|
4080
4363
|
}
|
|
4364
|
+
async function runEditPost(urn, text2, now, deps) {
|
|
4365
|
+
const unapprovable = refuseUnapprovable("edit", "editing", deps);
|
|
4366
|
+
if (unapprovable !== null) return unapprovable;
|
|
4367
|
+
const ctx = prepare("edit", now, "voyager");
|
|
4368
|
+
if ("ok" in ctx) return ctx;
|
|
4369
|
+
if (ctx.transport.kind !== "voyager") {
|
|
4370
|
+
return err(
|
|
4371
|
+
"edit",
|
|
4372
|
+
"NOT_IMPLEMENTED",
|
|
4373
|
+
"editing a post is only implemented over the private API"
|
|
4374
|
+
);
|
|
4375
|
+
}
|
|
4376
|
+
const before = await lookup(urn, true);
|
|
4377
|
+
const plan = {
|
|
4378
|
+
action: "edit your post",
|
|
4379
|
+
payload: { urn, text: text2 },
|
|
4380
|
+
summary: [
|
|
4381
|
+
authorLine(ctx.transport),
|
|
4382
|
+
`post ${urn}`,
|
|
4383
|
+
...previewLines2(before).map((l) => l.replace(/^content /, "was ")),
|
|
4384
|
+
`new text "${text2}"`
|
|
4385
|
+
],
|
|
4386
|
+
reversibility: "editable again, but the previous text is NOT kept here, LinkedIn marks the post as edited, and an @mention in the old text is not carried over",
|
|
4387
|
+
transport: "voyager"
|
|
4388
|
+
};
|
|
4389
|
+
const gated = await gate("edit", plan, ctx, deps);
|
|
4390
|
+
if ("ok" in gated) return gated;
|
|
4391
|
+
const result = await editPost(gated.confirmed, createLiveClient(ctx.transport.session));
|
|
4392
|
+
return result.ok ? ok("edit", { edited: urn }) : err("edit", result.code, result.message, result.hint);
|
|
4393
|
+
}
|
|
4081
4394
|
function activityIdOf(urn) {
|
|
4082
4395
|
return /^urn:li:(?:activity|ugcPost|share):(\d+)$/.exec(urn)?.[1] ?? null;
|
|
4083
4396
|
}
|
|
@@ -4172,11 +4485,14 @@ async function runEdit(commentUrn, text2, now = Date.now(), deps = terminalDeps(
|
|
|
4172
4485
|
}
|
|
4173
4486
|
const ref = parseCommentUrn(commentUrn);
|
|
4174
4487
|
if (ref === null) {
|
|
4488
|
+
if (/^urn:li:(share|ugcPost):\d+$/.test(commentUrn)) {
|
|
4489
|
+
return runEditPost(commentUrn, text2, now, deps);
|
|
4490
|
+
}
|
|
4175
4491
|
return err(
|
|
4176
4492
|
"edit",
|
|
4177
4493
|
"INVALID_INPUT",
|
|
4178
|
-
`'${commentUrn}' is
|
|
4179
|
-
"
|
|
4494
|
+
`'${commentUrn}' is neither a comment urn nor a post's share/ugcPost urn`,
|
|
4495
|
+
/^urn:li:activity:/.test(commentUrn) ? "A post is edited by the urn it was created as, not its activity urn. `lnrelay share` prints it, and `lnrelay my-posts` lists it as shareUrn." : "Pass a comment urn (from `lnrelay post <activity-urn>`) or a post urn (urn:li:share:\u2026 / urn:li:ugcPost:\u2026)."
|
|
4180
4496
|
);
|
|
4181
4497
|
}
|
|
4182
4498
|
const unapprovable = refuseUnapprovable("edit", "editing", deps);
|
|
@@ -4512,27 +4828,54 @@ function share3(args, now, deps) {
|
|
|
4512
4828
|
"one of: oauth, voyager. Omit it to prefer OAuth and fall back to Voyager."
|
|
4513
4829
|
);
|
|
4514
4830
|
}
|
|
4515
|
-
for (const flag of [
|
|
4831
|
+
for (const flag of [
|
|
4832
|
+
"image",
|
|
4833
|
+
"video",
|
|
4834
|
+
"document",
|
|
4835
|
+
"alt",
|
|
4836
|
+
"title",
|
|
4837
|
+
"at",
|
|
4838
|
+
"poll",
|
|
4839
|
+
"option",
|
|
4840
|
+
"duration"
|
|
4841
|
+
]) {
|
|
4516
4842
|
if (args.flags[flag] === true) {
|
|
4517
|
-
return err("share", "INVALID_INPUT", `--${flag} needs a
|
|
4843
|
+
return err("share", "INVALID_INPUT", `--${flag} needs a value`);
|
|
4518
4844
|
}
|
|
4519
4845
|
}
|
|
4520
|
-
const
|
|
4521
|
-
|
|
4522
|
-
if (images.length > 0 && videos.length > 0) {
|
|
4846
|
+
const kinds = ["image", "video", "document"].map((flag) => ({ flag, paths: list(args, flag) })).filter((k) => k.paths.length > 0);
|
|
4847
|
+
if (kinds.length > 1) {
|
|
4523
4848
|
return err(
|
|
4524
4849
|
"share",
|
|
4525
4850
|
"INVALID_INPUT",
|
|
4526
|
-
|
|
4527
|
-
"pass --image <path> (repeatable) or a single --video <path>"
|
|
4851
|
+
`a post carries ${kinds.map((k) => `${k.flag}s`).join(" or ")}, not both`,
|
|
4852
|
+
"pass --image <path> (repeatable), or a single --video <path>, or a single --document <path>"
|
|
4528
4853
|
);
|
|
4529
4854
|
}
|
|
4530
4855
|
const alts = list(args, "alt");
|
|
4856
|
+
const title = str(args, "title");
|
|
4857
|
+
const chosen = kinds[0];
|
|
4531
4858
|
let media;
|
|
4532
|
-
if (
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4859
|
+
if (chosen !== void 0) {
|
|
4860
|
+
media = { flag: chosen.flag, paths: chosen.paths, alts };
|
|
4861
|
+
if (title !== void 0) media.title = title;
|
|
4862
|
+
} else if (alts.length > 0 || title !== void 0) {
|
|
4863
|
+
return err(
|
|
4864
|
+
"share",
|
|
4865
|
+
"INVALID_INPUT",
|
|
4866
|
+
"--alt and --title describe an attached file, and none was given"
|
|
4867
|
+
);
|
|
4868
|
+
}
|
|
4869
|
+
const question = str(args, "poll");
|
|
4870
|
+
const options = list(args, "option");
|
|
4871
|
+
if (question === void 0 && (options.length > 0 || str(args, "duration") !== void 0)) {
|
|
4872
|
+
return err("share", "INVALID_INPUT", '--option and --duration belong to a --poll "<question>"');
|
|
4873
|
+
}
|
|
4874
|
+
let poll;
|
|
4875
|
+
if (question !== void 0) {
|
|
4876
|
+
poll = { question, options };
|
|
4877
|
+
const duration = str(args, "duration");
|
|
4878
|
+
if (duration !== void 0) poll.duration = duration;
|
|
4536
4879
|
}
|
|
4537
4880
|
return runShare(
|
|
4538
4881
|
args.positionals[0],
|
|
@@ -4540,7 +4883,9 @@ function share3(args, now, deps) {
|
|
|
4540
4883
|
now,
|
|
4541
4884
|
deps,
|
|
4542
4885
|
surface,
|
|
4543
|
-
media
|
|
4886
|
+
media,
|
|
4887
|
+
str(args, "at"),
|
|
4888
|
+
poll
|
|
4544
4889
|
);
|
|
4545
4890
|
}
|
|
4546
4891
|
export {
|