linkedin-relay-mcp 3.4.0 → 3.6.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/dist/cli.js CHANGED
@@ -1330,6 +1330,29 @@ 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
+ },
1344
+ // The composer's link lookup: a URL in, the article LinkedIn made of it out
1345
+ // (`urn:li:article:<id>`), which a post then carries as ARTICLE media. queryId
1346
+ // from mguttmann/linkedin-internal-api; same article urn the web composer
1347
+ // attached when captured on the date below.
1348
+ urlPreview: {
1349
+ name: "urlPreview",
1350
+ transport: "voyager-graphql",
1351
+ path: `${VOYAGER}/graphql`,
1352
+ queryId: "voyagerContentcreationDashUpdateUrlPreview.b092c1aea4b6c087ec0d09614b3b3320",
1353
+ provenance: "verified",
1354
+ capturedAt: "2026-10-13"
1355
+ },
1333
1356
  // limit of this projection is UNRESOLVED — do not treat this endpoint as an
1334
1357
  // authoritative "all my posts" until it is settled.
1335
1358
  myPosts: {
@@ -2234,6 +2257,8 @@ async function uploadMedia(file, client) {
2234
2257
  var VOYAGER2 = "https://www.linkedin.com/voyager/api";
2235
2258
  var SHARE_URL = `${VOYAGER2}/contentcreation/normShares`;
2236
2259
  var CATEGORY = {
2260
+ POLL: "URN_REFERENCE",
2261
+ ARTICLE: "ARTICLE",
2237
2262
  IMAGE: "IMAGE",
2238
2263
  VIDEO: "VIDEO",
2239
2264
  DOCUMENT: "NATIVE_DOCUMENT"
@@ -2306,6 +2331,14 @@ async function share(confirmed, client, bytes) {
2306
2331
  }
2307
2332
  }
2308
2333
  const media = [];
2334
+ const { card } = confirmed.payload;
2335
+ if (card !== void 0) media.push({ category: "ARTICLE", urn: card.urn });
2336
+ const { poll } = confirmed.payload;
2337
+ if (poll !== void 0) {
2338
+ const created = await createPoll(poll, client);
2339
+ if (!created.ok) return created;
2340
+ media.push({ category: "POLL", urn: created.urn });
2341
+ }
2309
2342
  for (const [i, a] of approved.entries()) {
2310
2343
  const uploaded = await uploadMedia(
2311
2344
  {
@@ -2349,6 +2382,142 @@ async function share(confirmed, client, bytes) {
2349
2382
  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."
2350
2383
  } : { ok: true, id };
2351
2384
  }
2385
+ function editPostBody(text2) {
2386
+ return { patch: { $set: { commentaryV2: { text: text2, attributes: [] } } } };
2387
+ }
2388
+ async function editPost(confirmed, client) {
2389
+ const { urn, text: text2 } = confirmed.payload;
2390
+ const result = await client.request({
2391
+ url: deleteUrl(urn),
2392
+ method: "POST",
2393
+ body: editPostBody(text2),
2394
+ spendClass: "write",
2395
+ operation: "edit-post"
2396
+ });
2397
+ if (!result.ok) {
2398
+ const out = { ok: false, code: result.code, message: result.message };
2399
+ if (result.hint !== void 0) out.hint = result.hint;
2400
+ return out;
2401
+ }
2402
+ const held = result.json?.data?.commentary?.text;
2403
+ if (held !== text2) {
2404
+ return {
2405
+ ok: false,
2406
+ code: "SCHEMA_DRIFT",
2407
+ message: "LinkedIn answered, but the post does not hold the text that was sent",
2408
+ hint: `Look at the post before trying again: \`lnrelay post\` or the browser. ${urn}`
2409
+ };
2410
+ }
2411
+ return { ok: true, id: urn };
2412
+ }
2413
+ var DURATIONS = {
2414
+ "1d": "ONE_DAY",
2415
+ "3d": "THREE_DAYS",
2416
+ "1w": "ONE_WEEK",
2417
+ "2w": "TWO_WEEKS"
2418
+ };
2419
+ function pollDuration(shorthand) {
2420
+ return DURATIONS[shorthand] ?? null;
2421
+ }
2422
+ function gqlError(json) {
2423
+ const j = json;
2424
+ const errors = j?.errors ?? j?.data?.errors;
2425
+ return errors !== void 0 && errors.length > 0 ? errors[0]?.message ?? "GraphQL error" : null;
2426
+ }
2427
+ function pollUrnOf(json) {
2428
+ if (gqlError(json) !== null) return null;
2429
+ return JSON.stringify(json ?? null).match(/urn:li:fsd_pollSummary:\d+/)?.[0] ?? null;
2430
+ }
2431
+ async function createPoll(poll, client) {
2432
+ const contract = contractFor("createPoll");
2433
+ if (contract?.queryId === void 0) {
2434
+ return { ok: false, code: "NOT_IMPLEMENTED", message: "no verified poll contract" };
2435
+ }
2436
+ const result = await client.request({
2437
+ url: `${contract.path}?action=execute&queryId=${contract.queryId}`,
2438
+ method: "POST",
2439
+ body: { variables: { poll }, queryId: contract.queryId, includeWebMetadata: true },
2440
+ spendClass: "write",
2441
+ operation: "create-poll"
2442
+ });
2443
+ if (!result.ok)
2444
+ return { ok: false, code: result.code, message: `${result.message}; nothing was posted` };
2445
+ const error = gqlError(result.json);
2446
+ if (error !== null) {
2447
+ return {
2448
+ ok: false,
2449
+ code: "INVALID_INPUT",
2450
+ message: `LinkedIn refused the poll: ${error}; nothing was posted`
2451
+ };
2452
+ }
2453
+ const urn = pollUrnOf(result.json);
2454
+ if (urn === null) {
2455
+ return {
2456
+ ok: false,
2457
+ code: "SCHEMA_DRIFT",
2458
+ message: "the poll mutation answered without a poll urn; nothing was posted",
2459
+ hint: "The queryId may have rotated \u2014 recapture it (docs/ENGINE-RESEARCH.md)."
2460
+ };
2461
+ }
2462
+ return { ok: true, urn };
2463
+ }
2464
+ function firstUrl(text2) {
2465
+ const found = text2.match(/https?:\/\/[^\s<>"]+/)?.[0];
2466
+ if (found === void 0) return null;
2467
+ let url = found.replace(/[.,;:!?'"]+$/, "");
2468
+ if (url.endsWith(")") && !url.includes("(")) url = url.slice(0, -1);
2469
+ return url;
2470
+ }
2471
+ function urlPreviewUrl(url) {
2472
+ const contract = contractFor("urlPreview");
2473
+ return `${contract?.path}?includeWebMetadata=true&variables=(url:${encodeURIComponent(url)})&queryId=${contract?.queryId}`;
2474
+ }
2475
+ function parseUrlPreview(json) {
2476
+ const error = gqlError(json);
2477
+ if (error !== null) {
2478
+ return { ok: false, code: "SCHEMA_DRIFT", message: `the link preview failed: ${error}` };
2479
+ }
2480
+ const j = json;
2481
+ const elements = j?.data?.data?.contentcreationDashUpdateUrlPreviewByUrl?.elements;
2482
+ if (!Array.isArray(elements)) {
2483
+ return {
2484
+ ok: false,
2485
+ code: "SCHEMA_DRIFT",
2486
+ message: "the link preview response had no preview collection",
2487
+ hint: "Re-capture the urlPreview contract: paste a link into the web composer."
2488
+ };
2489
+ }
2490
+ if (elements.length === 0) return { ok: true, card: null };
2491
+ const article = (j.included ?? []).find((e) => e.content?.articleComponent?.articleUrn)?.content?.articleComponent;
2492
+ if (article?.articleUrn === void 0) {
2493
+ return {
2494
+ ok: false,
2495
+ code: "SCHEMA_DRIFT",
2496
+ message: "LinkedIn previewed the link but no article came with it"
2497
+ };
2498
+ }
2499
+ return {
2500
+ ok: true,
2501
+ card: {
2502
+ urn: article.articleUrn,
2503
+ title: article.title?.text ?? "",
2504
+ source: article.subtitle?.text ?? ""
2505
+ }
2506
+ };
2507
+ }
2508
+ async function fetchLinkCard(url, client) {
2509
+ const result = await client.request({
2510
+ url: urlPreviewUrl(url),
2511
+ spendClass: "page",
2512
+ operation: "link-preview"
2513
+ });
2514
+ if (!result.ok) {
2515
+ const out = { ok: false, code: result.code, message: result.message };
2516
+ if (result.hint !== void 0) out.hint = result.hint;
2517
+ return out;
2518
+ }
2519
+ return parseUrlPreview(result.json);
2520
+ }
2352
2521
 
2353
2522
  // src/commands/gate.ts
2354
2523
  import { createInterface } from "readline/promises";
@@ -2583,8 +2752,103 @@ async function runDelete(urn, now = Date.now(), deps, quiet = false) {
2583
2752
  return ok("delete", { deleted: urn, verified: post !== void 0, evictedFromCache: evicted });
2584
2753
  }
2585
2754
 
2755
+ // src/engine/sdui-scheduled.ts
2756
+ var PAGER_ID = "com.linkedin.sdui.pagers.sharing.scheduledPosts";
2757
+ var PAGER_URL = `https://www.linkedin.com/flagship-web/rsc-action/actions/pagination?sduiid=${PAGER_ID}`;
2758
+ var SCREEN_ID2 = "com.linkedin.sdui.flagshipnav.sharing.ShareSchedulePostList";
2759
+ function scheduledPageBody(start, count2) {
2760
+ const args = {
2761
+ $type: "proto.sdui.actions.requests.RequestedArguments",
2762
+ requestedStateKeys: [],
2763
+ payload: { start, count: count2, shareLifeCycleState: "ShareLifeCycleState_SCHEDULED" },
2764
+ requestMetadata: { $type: "proto.sdui.common.RequestMetadata" }
2765
+ };
2766
+ return {
2767
+ pagerId: PAGER_ID,
2768
+ clientArguments: { ...args, states: [], screenId: SCREEN_ID2, knownTemplateIds: [] },
2769
+ paginationRequest: {
2770
+ $type: "proto.sdui.actions.requests.PaginationRequest",
2771
+ pagerId: PAGER_ID,
2772
+ retryCount: 0,
2773
+ requestedArguments: args
2774
+ }
2775
+ };
2776
+ }
2777
+ var COUNT = /"id":"ShareBoxscheduledPostCount"\}\}\},"value":\{"\$case":"intValue","intValue":(\d+)\}/;
2778
+ var ROW = /"feedUpdateUrn":"(urn:li:(?:share|ugcPost):\d+)","scheduledAtEpochMillis":"(\d+)"/g;
2779
+ var TEXT = /"viewName":"mini-update-container"[\s\S]*?"textProps":\{[^{}]*?"children":\["((?:[^"\\]|\\.)*)"\]/g;
2780
+ function parseScheduledPage(stream) {
2781
+ const count2 = stream.match(COUNT);
2782
+ if (count2?.[1] === void 0) {
2783
+ return drift("the scheduled-posts page carried no post count");
2784
+ }
2785
+ const claimedCount = Number(count2[1]);
2786
+ const posts = [];
2787
+ const seen = /* @__PURE__ */ new Set();
2788
+ for (const [, urn, at] of stream.matchAll(ROW)) {
2789
+ if (urn === void 0 || seen.has(urn)) continue;
2790
+ seen.add(urn);
2791
+ posts.push({ urn, scheduledAt: Number(at), text: null });
2792
+ }
2793
+ if (claimedCount > 0 && posts.length === 0) {
2794
+ return drift(`LinkedIn counts ${claimedCount} scheduled posts but no row could be read`);
2795
+ }
2796
+ const texts = [...stream.matchAll(TEXT)].map((m) => JSON.parse(`"${m[1]}"`));
2797
+ if (texts.length === posts.length) {
2798
+ posts.forEach((p, i) => {
2799
+ p.text = texts[i] ?? null;
2800
+ });
2801
+ }
2802
+ return { ok: true, claimedCount, posts };
2803
+ }
2804
+ function drift(message) {
2805
+ return {
2806
+ ok: false,
2807
+ code: "SCHEMA_DRIFT",
2808
+ message,
2809
+ hint: 'Re-capture the scheduled list (open "Scheduled" in the composer) with scripts/observe-write.ts.'
2810
+ };
2811
+ }
2812
+ var PAGE_SIZE = 10;
2813
+ var MAX_PAGES = 10;
2814
+ async function fetchScheduled(client, pageSize = PAGE_SIZE) {
2815
+ const posts = [];
2816
+ const seen = /* @__PURE__ */ new Set();
2817
+ let claimedCount = 0;
2818
+ for (let page = 0; page < MAX_PAGES; page++) {
2819
+ const result = await client.request({
2820
+ url: PAGER_URL,
2821
+ method: "POST",
2822
+ body: scheduledPageBody(posts.length, pageSize),
2823
+ spendClass: "page",
2824
+ operation: "scheduled"
2825
+ });
2826
+ if (!result.ok) {
2827
+ const out = { ok: false, code: result.code, message: result.message };
2828
+ if (result.hint !== void 0) out.hint = result.hint;
2829
+ return out;
2830
+ }
2831
+ const parsed = parseScheduledPage(result.classification.raw ?? "");
2832
+ if (!parsed.ok) return parsed;
2833
+ claimedCount = Math.max(claimedCount, parsed.claimedCount);
2834
+ const fresh = parsed.posts.filter((p) => !seen.has(p.urn));
2835
+ for (const p of fresh) {
2836
+ seen.add(p.urn);
2837
+ posts.push(p);
2838
+ }
2839
+ if (posts.length >= claimedCount || fresh.length === 0) break;
2840
+ }
2841
+ const state = posts.length >= claimedCount ? "complete" : "partial";
2842
+ return { ok: true, posts, claimedCount, state };
2843
+ }
2844
+
2586
2845
  // src/commands/live.ts
2587
2846
  function withSession(command, quiet = false) {
2847
+ const loaded = sessionFor(command);
2848
+ if ("ok" in loaded) return loaded;
2849
+ return { engine: createEngine(loaded.session, void 0, quiet) };
2850
+ }
2851
+ function sessionFor(command) {
2588
2852
  const loaded = loadSession();
2589
2853
  if (loaded.state === "corrupt") {
2590
2854
  return err(
@@ -2597,7 +2861,7 @@ function withSession(command, quiet = false) {
2597
2861
  if (loaded.state === "missing") {
2598
2862
  return err(command, "AUTH_FAILED", "no session \u2014 run `lnrelay login` first", LAUNCH_HINT);
2599
2863
  }
2600
- return { engine: createEngine(loaded.session, void 0, quiet) };
2864
+ return { session: loaded.session };
2601
2865
  }
2602
2866
  function toEnvelope(command, result) {
2603
2867
  return err(command, result.code, result.message, result.hint, void 0, result.retryAfterMs);
@@ -2703,6 +2967,27 @@ async function runReactions(urn, limit, opts = {}) {
2703
2967
  if (!result.ok) return toEnvelope("reactions", result);
2704
2968
  return ok("reactions", { urn: postUrn2, ...collection(result.value, opts) });
2705
2969
  }
2970
+ async function runScheduled(quiet = false) {
2971
+ const ctx = sessionFor("scheduled");
2972
+ if ("ok" in ctx) return ctx;
2973
+ const result = await fetchScheduled(createLiveClient(ctx.session, void 0, quiet));
2974
+ if (!result.ok) return err("scheduled", result.code, result.message, result.hint);
2975
+ return ok("scheduled", scheduledData(result));
2976
+ }
2977
+ function scheduledData(result) {
2978
+ return {
2979
+ items: result.posts.map((p) => ({
2980
+ urn: p.urn,
2981
+ scheduledAt: new Date(p.scheduledAt).toISOString(),
2982
+ text: p.text
2983
+ })),
2984
+ meta: {
2985
+ state: result.state,
2986
+ returnedCount: result.posts.length,
2987
+ claimedCount: result.claimedCount
2988
+ }
2989
+ };
2990
+ }
2706
2991
  function normalisePostUrn(input) {
2707
2992
  if (input === void 0 || input === "") return void 0;
2708
2993
  const found = input.match(/urn:li:(?:activity|ugcPost|share):\d+/);
@@ -3291,6 +3576,15 @@ var COMMANDS = [
3291
3576
  risk: "read",
3292
3577
  implemented: true
3293
3578
  },
3579
+ {
3580
+ name: "scheduled",
3581
+ cost: "1 call per 10 posts",
3582
+ summary: "Your posts waiting to publish, with when. Not in `my-posts` until they go out.",
3583
+ usage: "lnrelay scheduled\n Each row: urn (cancel with `delete`, change with `edit`), scheduledAt, text. Links in\n the text show as lnkd.in short links, as LinkedIn lists them.",
3584
+ audience: ["cli", "mcp"],
3585
+ risk: "read",
3586
+ implemented: true
3587
+ },
3294
3588
  {
3295
3589
  name: "local",
3296
3590
  cost: "free \u2014 local cache",
@@ -3341,7 +3635,7 @@ var COMMANDS = [
3341
3635
  name: "share",
3342
3636
  cost: "1 call \u2014 write",
3343
3637
  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.",
3344
- usage: 'lnrelay share "<text>" [--image <path> ... [--alt "<text>" ...] | --video <path>\n | --document <pdf> --title "<title>"] [--at "YYYY-MM-DD HH:MM"]\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 Files, documents and scheduling go over the private API only.',
3638
+ 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] [--no-card]\n [--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. The first link in the text\n gets the preview card LinkedIn would show (one extra read, named in the preview);\n --no-card posts it as plain text. Files, documents, polls, cards and scheduling go\n over the private API only.',
3345
3639
  audience: ["cli"],
3346
3640
  risk: "write",
3347
3641
  implemented: true
@@ -3376,8 +3670,8 @@ var COMMANDS = [
3376
3670
  {
3377
3671
  name: "edit",
3378
3672
  cost: "1 read + 1 write",
3379
- 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.",
3380
- usage: 'lnrelay edit <comment-urn> "<text>"',
3673
+ 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.",
3674
+ 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.',
3381
3675
  audience: ["cli"],
3382
3676
  risk: "write",
3383
3677
  implemented: true
@@ -3618,7 +3912,7 @@ function share2(confirmed, token, deps) {
3618
3912
  // src/engine/sdui-comment.ts
3619
3913
  var SDUI_ACTION2 = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
3620
3914
  var COMMENT_URL = `${SDUI_ACTION2}?sduiid=com.linkedin.sdui.comments.createComment`;
3621
- var SCREEN_ID2 = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
3915
+ var SCREEN_ID3 = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
3622
3916
  var STATE_PREFIXES = [
3623
3917
  "commentBoxText",
3624
3918
  "richCommentBoxText",
@@ -3709,7 +4003,7 @@ function commentBody(activityId, text2, tokens, feedType) {
3709
4003
  requestedArguments: {
3710
4004
  ...args,
3711
4005
  states: states(text2, body),
3712
- screenId: SCREEN_ID2,
4006
+ screenId: SCREEN_ID3,
3713
4007
  knownTemplateIds: []
3714
4008
  }
3715
4009
  };
@@ -3750,7 +4044,7 @@ async function comment(confirmed, client) {
3750
4044
 
3751
4045
  // src/engine/sdui-write.ts
3752
4046
  var SDUI_ACTION3 = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
3753
- var SCREEN_ID3 = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
4047
+ var SCREEN_ID4 = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
3754
4048
  var REACTIONS = [
3755
4049
  "LIKE",
3756
4050
  "PRAISE",
@@ -3827,7 +4121,7 @@ function sduiBody(op, target, reaction) {
3827
4121
  requestedArguments: {
3828
4122
  ...args,
3829
4123
  states: [],
3830
- screenId: SCREEN_ID3,
4124
+ screenId: SCREEN_ID4,
3831
4125
  knownTemplateIds: []
3832
4126
  }
3833
4127
  };
@@ -4114,6 +4408,89 @@ function mediaFrom(media, via2) {
4114
4408
  }
4115
4409
  return loaded;
4116
4410
  }
4411
+ function sharePlan(p) {
4412
+ const payload = { text: p.text, visibility: p.visibility };
4413
+ if (p.media !== void 0) payload.media = p.media;
4414
+ if (p.scheduledAt !== void 0) payload.scheduledAt = p.scheduledAt;
4415
+ if (p.poll !== void 0) payload.poll = p.poll;
4416
+ if (p.card !== void 0 && p.card !== null) payload.card = p.card;
4417
+ const scheduled = p.scheduledAt !== void 0;
4418
+ return {
4419
+ action: scheduled ? "schedule a post" : "post to your feed",
4420
+ payload,
4421
+ summary: [
4422
+ p.author,
4423
+ `content "${p.text}"`,
4424
+ `audience ${p.visibility}`,
4425
+ ...p.scheduledAt === void 0 ? [] : [whenLine(p.scheduledAt, p.now)],
4426
+ ...p.poll === void 0 ? [] : pollLines(p.poll),
4427
+ ...p.media === void 0 ? [] : mediaLines(p.media),
4428
+ ...cardLines(p.card)
4429
+ ],
4430
+ 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",
4431
+ transport: p.transport
4432
+ };
4433
+ }
4434
+ function cardLines(card) {
4435
+ if (card === void 0) return [];
4436
+ if (card === null) return ["card none \u2014 LinkedIn has no preview for this link"];
4437
+ return [`card "${card.title}" (${card.source})`];
4438
+ }
4439
+ var liveCardLookup = (url, session) => fetchLinkCard(url, createLiveClient(session));
4440
+ function shareNeeds(files, scheduledAt, poll, cardUrl) {
4441
+ const extra = (poll === void 0 ? 0 : 1) + (cardUrl === null ? 0 : 1);
4442
+ return {
4443
+ voyagerOnly: files !== void 0 || scheduledAt !== void 0 || extra > 0,
4444
+ calls: 2 * (files ?? 0) + extra + 1
4445
+ };
4446
+ }
4447
+ async function cardFor(url, transport, link) {
4448
+ if (url === null || transport.kind !== "voyager") return void 0;
4449
+ const found = await (link.lookup ?? liveCardLookup)(url, transport.session);
4450
+ if (found.ok) return found.card;
4451
+ return err(
4452
+ "share",
4453
+ found.code,
4454
+ `could not look up the card for ${url}: ${found.message}; nothing was posted`,
4455
+ "Re-run later, or add --no-card to post the link as plain text."
4456
+ );
4457
+ }
4458
+ function pollLines(poll) {
4459
+ return [
4460
+ `poll "${poll.question}"`,
4461
+ ...poll.options.map((o, i) => ` ${i + 1}. ${o}`),
4462
+ ` runs ${poll.duration}`
4463
+ ];
4464
+ }
4465
+ function pollFrom(poll, ctx) {
4466
+ if (poll === void 0) return void 0;
4467
+ const refuse2 = (message, hint) => err("share", "INVALID_INPUT", message, hint);
4468
+ if (poll.question.trim() === "") return refuse2("a poll needs a question");
4469
+ const options = poll.options.map((o) => o.trim());
4470
+ if (options.length < 2 || options.length > 4 || options.some((o) => o === "")) {
4471
+ return refuse2("a poll needs 2 to 4 non-empty options", 'repeat --option "<text>" for each');
4472
+ }
4473
+ const duration = pollDuration(poll.duration ?? "1w");
4474
+ if (duration === null) {
4475
+ return refuse2(`unknown --duration '${poll.duration}'`, "one of: 1d, 3d, 1w, 2w");
4476
+ }
4477
+ if (ctx.hasMedia) return refuse2("a post carries a poll or files, not both");
4478
+ if (ctx.scheduled) {
4479
+ return refuse2(
4480
+ "a poll cannot be scheduled yet \u2014 its clock may start when it is created, not published",
4481
+ "post the poll now, or schedule a text post that asks the question"
4482
+ );
4483
+ }
4484
+ if (ctx.via === "oauth") {
4485
+ return err(
4486
+ "share",
4487
+ "NOT_IMPLEMENTED",
4488
+ "polls are only implemented over the private API",
4489
+ "drop --via oauth, or pass --via voyager"
4490
+ );
4491
+ }
4492
+ return { question: poll.question.trim(), options, duration };
4493
+ }
4117
4494
  function scheduleFrom(at, now, via2) {
4118
4495
  if (at === void 0) return void 0;
4119
4496
  const t = parseScheduleTime(at);
@@ -4158,7 +4535,7 @@ function whenLine(at, now) {
4158
4535
  const away = hours < 48 ? `in ${hours} h` : `in ${Math.round(hours / 24)} days`;
4159
4536
  return `when ${local} (${zone}) \u2014 ${away}`;
4160
4537
  }
4161
- async function runShare(text2, visibility, now = Date.now(), deps = terminalDeps(), via2, media, at) {
4538
+ async function runShare(text2, visibility, now = Date.now(), deps = terminalDeps(), via2, media, at, poll, link = {}) {
4162
4539
  if (text2 === void 0 || text2.trim() === "") {
4163
4540
  return err("share", "INVALID_INPUT", "text is required", 'lnrelay share "<text>"');
4164
4541
  }
@@ -4168,29 +4545,29 @@ async function runShare(text2, visibility, now = Date.now(), deps = terminalDeps
4168
4545
  const scheduledAt = scheduled;
4169
4546
  const loaded = mediaFrom(media, via2);
4170
4547
  if (loaded !== void 0 && "ok" in loaded) return loaded;
4171
- const voyagerOnly = loaded !== void 0 || scheduledAt !== void 0;
4172
- const ctx = prepare(
4173
- "share",
4174
- now,
4175
- voyagerOnly ? "voyager" : via2,
4176
- 2 * (loaded?.approved.length ?? 0) + 1
4177
- );
4548
+ const pollSpec = pollFrom(poll, {
4549
+ hasMedia: loaded !== void 0,
4550
+ scheduled: scheduledAt !== void 0,
4551
+ via: via2
4552
+ });
4553
+ if (pollSpec !== void 0 && "ok" in pollSpec) return pollSpec;
4554
+ const cardUrl = link.card !== false && loaded === void 0 && pollSpec === void 0 && via2 !== "oauth" ? firstUrl(text2) : null;
4555
+ const needs = shareNeeds(loaded?.approved.length, scheduledAt, pollSpec, cardUrl);
4556
+ const ctx = prepare("share", now, needs.voyagerOnly ? "voyager" : via2, needs.calls);
4178
4557
  if ("ok" in ctx) return ctx;
4179
- const payload = { text: text2, visibility: vis };
4180
- if (scheduledAt !== void 0) payload.scheduledAt = scheduledAt;
4181
- const summary = [authorLine(ctx.transport), `content "${text2}"`, `audience ${vis}`];
4182
- if (scheduledAt !== void 0) summary.push(whenLine(scheduledAt, now));
4183
- if (loaded !== void 0) {
4184
- payload.media = loaded.approved;
4185
- summary.push(...mediaLines(loaded.approved));
4186
- }
4187
- const plan = {
4188
- action: scheduledAt === void 0 ? "post to your feed" : "schedule a post",
4189
- payload,
4190
- summary,
4191
- reversibility: scheduledAt === void 0 ? "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" : "cancel any time before it publishes with `lnrelay delete <urn>`; after that it is public under your name like any post",
4192
- transport: ctx.transport.kind
4193
- };
4558
+ const card = await cardFor(cardUrl, ctx.transport, link);
4559
+ if (card !== void 0 && card !== null && "ok" in card) return card;
4560
+ const plan = sharePlan({
4561
+ author: authorLine(ctx.transport),
4562
+ transport: ctx.transport.kind,
4563
+ text: text2,
4564
+ visibility: vis,
4565
+ media: loaded?.approved,
4566
+ scheduledAt,
4567
+ poll: pollSpec,
4568
+ ...card === void 0 ? {} : { card },
4569
+ now
4570
+ });
4194
4571
  const gated = await gate("share", plan, ctx, deps);
4195
4572
  if ("ok" in gated) return gated;
4196
4573
  const result = ctx.transport.kind === "oauth" ? await share2(gated.confirmed, ctx.transport.token, {
@@ -4206,6 +4583,36 @@ async function runShare(text2, visibility, now = Date.now(), deps = terminalDeps
4206
4583
  note: "note" in result ? result.note : ctx.note
4207
4584
  });
4208
4585
  }
4586
+ async function runEditPost(urn, text2, now, deps) {
4587
+ const unapprovable = refuseUnapprovable("edit", "editing", deps);
4588
+ if (unapprovable !== null) return unapprovable;
4589
+ const ctx = prepare("edit", now, "voyager");
4590
+ if ("ok" in ctx) return ctx;
4591
+ if (ctx.transport.kind !== "voyager") {
4592
+ return err(
4593
+ "edit",
4594
+ "NOT_IMPLEMENTED",
4595
+ "editing a post is only implemented over the private API"
4596
+ );
4597
+ }
4598
+ const before = await lookup(urn, true);
4599
+ const plan = {
4600
+ action: "edit your post",
4601
+ payload: { urn, text: text2 },
4602
+ summary: [
4603
+ authorLine(ctx.transport),
4604
+ `post ${urn}`,
4605
+ ...previewLines2(before).map((l) => l.replace(/^content /, "was ")),
4606
+ `new text "${text2}"`
4607
+ ],
4608
+ 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",
4609
+ transport: "voyager"
4610
+ };
4611
+ const gated = await gate("edit", plan, ctx, deps);
4612
+ if ("ok" in gated) return gated;
4613
+ const result = await editPost(gated.confirmed, createLiveClient(ctx.transport.session));
4614
+ return result.ok ? ok("edit", { edited: urn }) : err("edit", result.code, result.message, result.hint);
4615
+ }
4209
4616
  function activityIdOf(urn) {
4210
4617
  return /^urn:li:(?:activity|ugcPost|share):(\d+)$/.exec(urn)?.[1] ?? null;
4211
4618
  }
@@ -4300,11 +4707,14 @@ async function runEdit(commentUrn, text2, now = Date.now(), deps = terminalDeps(
4300
4707
  }
4301
4708
  const ref = parseCommentUrn(commentUrn);
4302
4709
  if (ref === null) {
4710
+ if (/^urn:li:(share|ugcPost):\d+$/.test(commentUrn)) {
4711
+ return runEditPost(commentUrn, text2, now, deps);
4712
+ }
4303
4713
  return err(
4304
4714
  "edit",
4305
4715
  "INVALID_INPUT",
4306
- `'${commentUrn}' is not a comment urn`,
4307
- "Only comments can be edited here \u2014 a published post cannot. Get the urn from `lnrelay post <activity-urn>`."
4716
+ `'${commentUrn}' is neither a comment urn nor a post's share/ugcPost urn`,
4717
+ /^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)."
4308
4718
  );
4309
4719
  }
4310
4720
  const unapprovable = refuseUnapprovable("edit", "editing", deps);
@@ -4546,6 +4956,8 @@ async function dispatch(argv, now) {
4546
4956
  num(args, "limit") ?? 25,
4547
4957
  output(args)
4548
4958
  );
4959
+ case "scheduled":
4960
+ return runScheduled(bool(args, "quiet"));
4549
4961
  case "sync":
4550
4962
  return runSync(args.positionals[0], num(args, "limit") ?? 50, bool(args, "force"), now);
4551
4963
  case "login":
@@ -4640,11 +5052,29 @@ function share3(args, now, deps) {
4640
5052
  "one of: oauth, voyager. Omit it to prefer OAuth and fall back to Voyager."
4641
5053
  );
4642
5054
  }
4643
- for (const flag of ["image", "video", "document", "alt", "title", "at"]) {
5055
+ for (const flag of [
5056
+ "image",
5057
+ "video",
5058
+ "document",
5059
+ "alt",
5060
+ "title",
5061
+ "at",
5062
+ "poll",
5063
+ "option",
5064
+ "duration"
5065
+ ]) {
4644
5066
  if (args.flags[flag] === true) {
4645
5067
  return err("share", "INVALID_INPUT", `--${flag} needs a value`);
4646
5068
  }
4647
5069
  }
5070
+ if (typeof args.flags["no-card"] === "string") {
5071
+ return err(
5072
+ "share",
5073
+ "INVALID_INPUT",
5074
+ "--no-card takes no value",
5075
+ 'put the text first: lnrelay share "<text>" --no-card'
5076
+ );
5077
+ }
4648
5078
  const kinds = ["image", "video", "document"].map((flag) => ({ flag, paths: list(args, flag) })).filter((k) => k.paths.length > 0);
4649
5079
  if (kinds.length > 1) {
4650
5080
  return err(
@@ -4668,6 +5098,17 @@ function share3(args, now, deps) {
4668
5098
  "--alt and --title describe an attached file, and none was given"
4669
5099
  );
4670
5100
  }
5101
+ const question = str(args, "poll");
5102
+ const options = list(args, "option");
5103
+ if (question === void 0 && (options.length > 0 || str(args, "duration") !== void 0)) {
5104
+ return err("share", "INVALID_INPUT", '--option and --duration belong to a --poll "<question>"');
5105
+ }
5106
+ let poll;
5107
+ if (question !== void 0) {
5108
+ poll = { question, options };
5109
+ const duration = str(args, "duration");
5110
+ if (duration !== void 0) poll.duration = duration;
5111
+ }
4671
5112
  return runShare(
4672
5113
  args.positionals[0],
4673
5114
  str(args, "visibility") ?? "public",
@@ -4675,7 +5116,9 @@ function share3(args, now, deps) {
4675
5116
  deps,
4676
5117
  surface,
4677
5118
  media,
4678
- str(args, "at")
5119
+ str(args, "at"),
5120
+ poll,
5121
+ { card: !bool(args, "no-card") }
4679
5122
  );
4680
5123
  }
4681
5124
  export {