linkedin-relay-mcp 1.6.0 → 2.0.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 +405 -110
- package/dist/cli.js.map +1 -1
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/mcp-shim.js +13 -4
- package/dist/mcp-shim.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -695,6 +695,21 @@ function retain(source, items) {
|
|
|
695
695
|
}
|
|
696
696
|
}
|
|
697
697
|
|
|
698
|
+
// src/engine/auth.ts
|
|
699
|
+
function csrfToken(jsessionId) {
|
|
700
|
+
return jsessionId.replace(/"/g, "");
|
|
701
|
+
}
|
|
702
|
+
function buildHeaders(session) {
|
|
703
|
+
return {
|
|
704
|
+
cookie: `li_at=${session.liAt}; JSESSIONID=${session.jsessionId}`,
|
|
705
|
+
"csrf-token": csrfToken(session.jsessionId),
|
|
706
|
+
"x-restli-protocol-version": "2.0.0",
|
|
707
|
+
accept: "application/vnd.linkedin.normalized+json+2.1",
|
|
708
|
+
"x-li-lang": "en_US",
|
|
709
|
+
"user-agent": session.userAgent
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
|
|
698
713
|
// src/progress.ts
|
|
699
714
|
function progressReporter(quiet, write = (s) => {
|
|
700
715
|
process.stderr.write(s);
|
|
@@ -800,21 +815,6 @@ function activeCooldown(cooldown, now) {
|
|
|
800
815
|
return now < cooldown.until;
|
|
801
816
|
}
|
|
802
817
|
|
|
803
|
-
// src/engine/auth.ts
|
|
804
|
-
function csrfToken(jsessionId) {
|
|
805
|
-
return jsessionId.replace(/"/g, "");
|
|
806
|
-
}
|
|
807
|
-
function buildHeaders(session) {
|
|
808
|
-
return {
|
|
809
|
-
cookie: `li_at=${session.liAt}; JSESSIONID=${session.jsessionId}`,
|
|
810
|
-
"csrf-token": csrfToken(session.jsessionId),
|
|
811
|
-
"x-restli-protocol-version": "2.0.0",
|
|
812
|
-
accept: "application/vnd.linkedin.normalized+json+2.1",
|
|
813
|
-
"x-li-lang": "en_US",
|
|
814
|
-
"user-agent": session.userAgent
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
|
|
818
818
|
// src/engine/classify.ts
|
|
819
819
|
var CHALLENGE_MARKERS = /checkpoint|challenge|captcha|security verification|unusual activity/i;
|
|
820
820
|
var LOGIN_REDIRECT = /\/login|\/uas\/login|session_redirect/i;
|
|
@@ -1565,6 +1565,247 @@ function totalResultCount(json) {
|
|
|
1565
1565
|
return found?.[1] === void 0 ? void 0 : Number(found[1]);
|
|
1566
1566
|
}
|
|
1567
1567
|
|
|
1568
|
+
// src/engine/sdui-harvest.ts
|
|
1569
|
+
function zigzag(n) {
|
|
1570
|
+
return n << 1n ^ n >> 63n;
|
|
1571
|
+
}
|
|
1572
|
+
function varint(n) {
|
|
1573
|
+
const out = [];
|
|
1574
|
+
let v = n;
|
|
1575
|
+
while (v > 0x7fn) {
|
|
1576
|
+
out.push(Number(v & 0x7fn | 0x80n));
|
|
1577
|
+
v >>= 7n;
|
|
1578
|
+
}
|
|
1579
|
+
out.push(Number(v));
|
|
1580
|
+
return out;
|
|
1581
|
+
}
|
|
1582
|
+
function activityIdSegment(activityId) {
|
|
1583
|
+
if (!/^\d+$/.test(activityId)) {
|
|
1584
|
+
throw new Error(`'${activityId}' is not a numeric activity id`);
|
|
1585
|
+
}
|
|
1586
|
+
const inner = [8, ...varint(zigzag(BigInt(activityId)))];
|
|
1587
|
+
const message = Uint8Array.from([10, inner.length, ...inner]);
|
|
1588
|
+
return btoa(String.fromCharCode(...message)).replace(/=+$/, "");
|
|
1589
|
+
}
|
|
1590
|
+
function keyMatchesPost(bindingKey, activityId) {
|
|
1591
|
+
try {
|
|
1592
|
+
return bindingKey.startsWith(`commentBoxText-${activityIdSegment(activityId)}-`);
|
|
1593
|
+
} catch {
|
|
1594
|
+
return false;
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
var NOT_THE_POST = /checkpoint\/challenge|\/uas\/login|authwall|"status"\s*:\s*999/i;
|
|
1598
|
+
var TRACKING_PROXIMITY = 400;
|
|
1599
|
+
function updateTrackingId(html, activityId) {
|
|
1600
|
+
const idAt = [...html.matchAll(new RegExp(activityId, "g"))].map((m) => m.index ?? 0);
|
|
1601
|
+
if (idAt.length === 0) return null;
|
|
1602
|
+
const pattern = /trackingId(?:"|\\?")+\s*:\s*(?:"|\\?")+([A-Za-z0-9+/=]{16,32})/g;
|
|
1603
|
+
let best = null;
|
|
1604
|
+
for (const m of html.matchAll(pattern)) {
|
|
1605
|
+
const at = m.index ?? 0;
|
|
1606
|
+
const distance = Math.min(...idAt.map((p) => Math.abs(p - at)));
|
|
1607
|
+
if (best === null || distance < best.distance) best = { value: m[1], distance };
|
|
1608
|
+
}
|
|
1609
|
+
return best !== null && best.distance <= TRACKING_PROXIMITY ? best.value : null;
|
|
1610
|
+
}
|
|
1611
|
+
function extractCommentTokens(html, activityId) {
|
|
1612
|
+
if (NOT_THE_POST.test(html)) {
|
|
1613
|
+
return {
|
|
1614
|
+
ok: false,
|
|
1615
|
+
message: "the page returned was a challenge or sign-in wall, not the post",
|
|
1616
|
+
hint: "Re-mint the session with `lnrelay login`, then check `lnrelay risk`."
|
|
1617
|
+
};
|
|
1618
|
+
}
|
|
1619
|
+
let expected;
|
|
1620
|
+
try {
|
|
1621
|
+
expected = activityIdSegment(activityId);
|
|
1622
|
+
} catch (e) {
|
|
1623
|
+
return { ok: false, message: e.message };
|
|
1624
|
+
}
|
|
1625
|
+
const keyPattern = new RegExp(
|
|
1626
|
+
`commentBoxText-${expected.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}-[A-Za-z0-9+/_=-]*FeedType_[A-Z_]+`
|
|
1627
|
+
);
|
|
1628
|
+
const key = keyPattern.exec(html)?.[0];
|
|
1629
|
+
if (key === void 0) {
|
|
1630
|
+
return {
|
|
1631
|
+
ok: false,
|
|
1632
|
+
message: `no comment-box binding key for post ${activityId} was found in the page`,
|
|
1633
|
+
hint: "Either the post does not accept comments, or LinkedIn changed the rendered shape. Re-capture with `bun run scripts/observe-write.ts` before changing this parser."
|
|
1634
|
+
};
|
|
1635
|
+
}
|
|
1636
|
+
const trackingId = updateTrackingId(html, activityId);
|
|
1637
|
+
if (trackingId === null) {
|
|
1638
|
+
return {
|
|
1639
|
+
ok: false,
|
|
1640
|
+
message: `no trackingId adjacent to post ${activityId} was found in the page`,
|
|
1641
|
+
hint: "The page carries several \u2014 one for the page itself, one per rendered update. Only the update's own will do, and guessing would build a malformed comment."
|
|
1642
|
+
};
|
|
1643
|
+
}
|
|
1644
|
+
return { ok: true, bindingKey: key, trackingId };
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
// src/engine/sdui-menu.ts
|
|
1648
|
+
var SDUI_ACTION = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
|
|
1649
|
+
var MENU_OP = "com.linkedin.sdui.requests.comments.commentControlMenuRequest";
|
|
1650
|
+
var SCREEN_ID = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
|
|
1651
|
+
var DELETE_OP = "com.linkedin.sdui.comments.deleteComment";
|
|
1652
|
+
var UPDATE_OP = "com.linkedin.sdui.comments.updateComment";
|
|
1653
|
+
function actionUrl(operation) {
|
|
1654
|
+
return `${SDUI_ACTION}?sduiid=${operation}`;
|
|
1655
|
+
}
|
|
1656
|
+
function sduiEnvelope(operation, payload, states2 = []) {
|
|
1657
|
+
const args = {
|
|
1658
|
+
$type: "proto.sdui.actions.requests.RequestedArguments",
|
|
1659
|
+
requestedStateKeys: [],
|
|
1660
|
+
payload,
|
|
1661
|
+
requestMetadata: { $type: "proto.sdui.common.RequestMetadata" }
|
|
1662
|
+
};
|
|
1663
|
+
return {
|
|
1664
|
+
requestId: operation,
|
|
1665
|
+
serverRequest: {
|
|
1666
|
+
requestId: operation,
|
|
1667
|
+
requestedArguments: args,
|
|
1668
|
+
isApfcEnabled: false,
|
|
1669
|
+
isStreaming: false,
|
|
1670
|
+
rumPageKey: ""
|
|
1671
|
+
},
|
|
1672
|
+
states: states2,
|
|
1673
|
+
requestedArguments: { ...args, states: states2, screenId: SCREEN_ID, knownTemplateIds: [] }
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
function menuBody(activityId, commentId, trackingId) {
|
|
1677
|
+
const activityUrn = { activityUrn: { activityId } };
|
|
1678
|
+
return sduiEnvelope(MENU_OP, {
|
|
1679
|
+
commentUrn: { commentId, thread: `urn:li:activity:${activityId}` },
|
|
1680
|
+
updateKey: {
|
|
1681
|
+
feedType: 3,
|
|
1682
|
+
items: [{ feedUpdateUrn: { updateUrnActivityUrn: activityUrn }, trackingId }],
|
|
1683
|
+
aggregationType: 0,
|
|
1684
|
+
isVideoCarousel: false
|
|
1685
|
+
},
|
|
1686
|
+
menuContentRef: `auto-component-${crypto.randomUUID()}`
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1689
|
+
function extractActionPayload(stream, operation) {
|
|
1690
|
+
const at = stream.indexOf(operation);
|
|
1691
|
+
if (at === -1) return null;
|
|
1692
|
+
const key = stream.indexOf('"payload":', at);
|
|
1693
|
+
if (key === -1) return null;
|
|
1694
|
+
const start = stream.indexOf("{", key);
|
|
1695
|
+
if (start === -1) return null;
|
|
1696
|
+
let depth = 0;
|
|
1697
|
+
let inString = false;
|
|
1698
|
+
let escaped = false;
|
|
1699
|
+
for (let i = start; i < stream.length; i++) {
|
|
1700
|
+
const ch = stream[i];
|
|
1701
|
+
if (escaped) {
|
|
1702
|
+
escaped = false;
|
|
1703
|
+
} else if (ch === "\\") {
|
|
1704
|
+
escaped = true;
|
|
1705
|
+
} else if (ch === '"') {
|
|
1706
|
+
inString = !inString;
|
|
1707
|
+
} else if (!inString && ch === "{") {
|
|
1708
|
+
depth++;
|
|
1709
|
+
} else if (!inString && ch === "}") {
|
|
1710
|
+
depth--;
|
|
1711
|
+
if (depth === 0) {
|
|
1712
|
+
try {
|
|
1713
|
+
return JSON.parse(stream.slice(start, i + 1));
|
|
1714
|
+
} catch {
|
|
1715
|
+
return null;
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
return null;
|
|
1721
|
+
}
|
|
1722
|
+
async function fetchCommentMenu(activityId, commentId, trackingId, client) {
|
|
1723
|
+
const result = await client.request({
|
|
1724
|
+
url: actionUrl(MENU_OP),
|
|
1725
|
+
method: "POST",
|
|
1726
|
+
body: menuBody(activityId, commentId, trackingId),
|
|
1727
|
+
spendClass: "page",
|
|
1728
|
+
operation: "commentMenu"
|
|
1729
|
+
});
|
|
1730
|
+
if (!result.ok) {
|
|
1731
|
+
const out = { ok: false, code: result.code, message: result.message };
|
|
1732
|
+
if (result.hint !== void 0) out.hint = result.hint;
|
|
1733
|
+
return out;
|
|
1734
|
+
}
|
|
1735
|
+
const stream = result.classification.raw ?? "";
|
|
1736
|
+
return { ok: true, stream };
|
|
1737
|
+
}
|
|
1738
|
+
function editStates(payload, text2) {
|
|
1739
|
+
const named = (field) => {
|
|
1740
|
+
const slot = payload[field];
|
|
1741
|
+
return typeof slot?.key === "string" ? slot.key : null;
|
|
1742
|
+
};
|
|
1743
|
+
const plain = named("commentary");
|
|
1744
|
+
const rich = named("richTextCommentary");
|
|
1745
|
+
if (plain === null || rich === null) return [];
|
|
1746
|
+
const entry2 = (key, value, protoCase) => ({
|
|
1747
|
+
key,
|
|
1748
|
+
namespace: "MemoryNamespace",
|
|
1749
|
+
value,
|
|
1750
|
+
originalProtoCase: protoCase,
|
|
1751
|
+
protoKey: { $type: "proto.sdui.Key", value: { $case: "id", id: key } }
|
|
1752
|
+
});
|
|
1753
|
+
return [
|
|
1754
|
+
entry2(plain, text2, "stringValue"),
|
|
1755
|
+
entry2(rich, { text: text2, attribute: [], $type: "TextModel", source: "local" }, "textModelForWrite")
|
|
1756
|
+
];
|
|
1757
|
+
}
|
|
1758
|
+
async function runCommentAction(ref, operation, trackingId, client, newText) {
|
|
1759
|
+
const menu = await fetchCommentMenu(ref.activityId, ref.commentId, trackingId, client);
|
|
1760
|
+
if (!menu.ok) return { ok: false, code: menu.code, message: menu.message };
|
|
1761
|
+
const payload = extractActionPayload(menu.stream, operation);
|
|
1762
|
+
if (payload === null) {
|
|
1763
|
+
return {
|
|
1764
|
+
ok: false,
|
|
1765
|
+
code: "NOT_IMPLEMENTED",
|
|
1766
|
+
message: `LinkedIn did not offer '${operation.split(".").pop()}' on this comment`,
|
|
1767
|
+
hint: "The menu lists only what the server permits \u2014 you may not own this comment, or the action may not exist on this surface. Nothing was sent."
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
const echoed = payload.commentUrn?.commentId;
|
|
1771
|
+
if (echoed !== ref.commentId) {
|
|
1772
|
+
return {
|
|
1773
|
+
ok: false,
|
|
1774
|
+
code: "SCHEMA_DRIFT",
|
|
1775
|
+
message: `the menu described comment ${String(echoed)} but we asked about ${ref.commentId}`,
|
|
1776
|
+
hint: "Refusing to send \u2014 this is how an action lands on the wrong comment."
|
|
1777
|
+
};
|
|
1778
|
+
}
|
|
1779
|
+
const states2 = operation === UPDATE_OP && newText !== void 0 ? editStates(payload, newText) : [];
|
|
1780
|
+
if (operation === UPDATE_OP && states2.length === 0) {
|
|
1781
|
+
return {
|
|
1782
|
+
ok: false,
|
|
1783
|
+
code: "SCHEMA_DRIFT",
|
|
1784
|
+
message: "the menu did not name the comment-text state keys, so an edit cannot be built"
|
|
1785
|
+
};
|
|
1786
|
+
}
|
|
1787
|
+
const result = await client.request({
|
|
1788
|
+
url: actionUrl(operation),
|
|
1789
|
+
method: "POST",
|
|
1790
|
+
body: sduiEnvelope(operation, payload, states2),
|
|
1791
|
+
spendClass: "write",
|
|
1792
|
+
operation: operation.split(".").pop() ?? operation
|
|
1793
|
+
});
|
|
1794
|
+
if (!result.ok) {
|
|
1795
|
+
const out = { ok: false, code: result.code, message: result.message };
|
|
1796
|
+
if (result.hint !== void 0) out.hint = result.hint;
|
|
1797
|
+
return out;
|
|
1798
|
+
}
|
|
1799
|
+
return { ok: true, operation };
|
|
1800
|
+
}
|
|
1801
|
+
function parseCommentUrn(urn) {
|
|
1802
|
+
const fsd = /^urn:li:fsd_comment:\((\d+),urn:li:activity:(\d+)\)$/.exec(urn);
|
|
1803
|
+
if (fsd !== null) return { commentId: fsd[1], activityId: fsd[2] };
|
|
1804
|
+
const plain = /^urn:li:comment:\((?:urn:li:)?activity:(\d+),(\d+)\)$/.exec(urn);
|
|
1805
|
+
if (plain !== null) return { activityId: plain[1], commentId: plain[2] };
|
|
1806
|
+
return null;
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1568
1809
|
// src/engine/session.ts
|
|
1569
1810
|
var SESSION_FILE = "session.json";
|
|
1570
1811
|
function loadSession() {
|
|
@@ -1866,6 +2107,62 @@ function evict(urn, now) {
|
|
|
1866
2107
|
throw e;
|
|
1867
2108
|
}
|
|
1868
2109
|
}
|
|
2110
|
+
async function deleteComment(ref, urn, now, deps) {
|
|
2111
|
+
if (!deps.isTty) {
|
|
2112
|
+
return err(
|
|
2113
|
+
"delete",
|
|
2114
|
+
"CONFIRMATION_REQUIRED",
|
|
2115
|
+
"deleting needs a human to confirm it at an interactive terminal",
|
|
2116
|
+
"No terminal is attached, so nothing was sent and no network call was made."
|
|
2117
|
+
);
|
|
2118
|
+
}
|
|
2119
|
+
const session = loadSession();
|
|
2120
|
+
if (session.state !== "ok") {
|
|
2121
|
+
return err("delete", "AUTH_FAILED", "no LinkedIn session", LAUNCH_HINT);
|
|
2122
|
+
}
|
|
2123
|
+
const refused = reserve("delete", now);
|
|
2124
|
+
if (refused !== null) return refused;
|
|
2125
|
+
const headers2 = buildHeaders(session.session);
|
|
2126
|
+
let html;
|
|
2127
|
+
try {
|
|
2128
|
+
const res = await fetch(
|
|
2129
|
+
`https://www.linkedin.com/feed/update/urn:li:activity:${ref.activityId}/`,
|
|
2130
|
+
{
|
|
2131
|
+
headers: {
|
|
2132
|
+
cookie: headers2.cookie ?? "",
|
|
2133
|
+
"user-agent": headers2["user-agent"] ?? "",
|
|
2134
|
+
accept: "text/html"
|
|
2135
|
+
},
|
|
2136
|
+
redirect: "manual"
|
|
2137
|
+
}
|
|
2138
|
+
);
|
|
2139
|
+
if (res.status !== 200) {
|
|
2140
|
+
return err("delete", "FETCH_FAILED", `the parent post page returned ${res.status}`);
|
|
2141
|
+
}
|
|
2142
|
+
html = await res.text();
|
|
2143
|
+
} catch (e) {
|
|
2144
|
+
return err("delete", "FETCH_FAILED", `could not load the parent post: ${e.message}`);
|
|
2145
|
+
}
|
|
2146
|
+
recordHarvestSpend(now);
|
|
2147
|
+
const tokens = extractCommentTokens(html, ref.activityId);
|
|
2148
|
+
if (!tokens.ok) return err("delete", "SCHEMA_DRIFT", tokens.message, tokens.hint);
|
|
2149
|
+
const plan = {
|
|
2150
|
+
action: "delete your comment",
|
|
2151
|
+
payload: { urn },
|
|
2152
|
+
summary: [`comment ${urn}`, `on post urn:li:activity:${ref.activityId}`],
|
|
2153
|
+
reversibility: "NONE. A deleted comment is gone, with its replies and reactions.",
|
|
2154
|
+
transport: "voyager"
|
|
2155
|
+
};
|
|
2156
|
+
const gated = await gateWrite("delete", plan, now, deps, { commitSpend: false });
|
|
2157
|
+
if ("ok" in gated) return gated;
|
|
2158
|
+
const result = await runCommentAction(
|
|
2159
|
+
ref,
|
|
2160
|
+
DELETE_OP,
|
|
2161
|
+
tokens.trackingId,
|
|
2162
|
+
createLiveClient(session.session)
|
|
2163
|
+
);
|
|
2164
|
+
return result.ok ? ok("delete", { deleted: urn, kind: "comment" }) : err("delete", result.code, result.message, result.hint);
|
|
2165
|
+
}
|
|
1869
2166
|
async function runDelete(urn, now = Date.now(), deps, quiet = false) {
|
|
1870
2167
|
if (urn === void 0 || urn === "") {
|
|
1871
2168
|
return err(
|
|
@@ -1875,12 +2172,14 @@ async function runDelete(urn, now = Date.now(), deps, quiet = false) {
|
|
|
1875
2172
|
"lnrelay delete <urn:li:share:\u2026 | urn:li:activity:\u2026>"
|
|
1876
2173
|
);
|
|
1877
2174
|
}
|
|
2175
|
+
const asComment = parseCommentUrn(urn);
|
|
2176
|
+
if (asComment !== null) return deleteComment(asComment, urn, now, deps ?? terminalDeps());
|
|
1878
2177
|
if (!isDeletableUrn(urn)) {
|
|
1879
2178
|
return err(
|
|
1880
2179
|
"delete",
|
|
1881
2180
|
"INVALID_INPUT",
|
|
1882
2181
|
`'${urn}' does not identify a post`,
|
|
1883
|
-
"Expected urn
|
|
2182
|
+
"Expected a post urn (urn:li:share|activity|ugcPost:<id>) or a comment urn. Refusing before encoding it, because a well-formed request naming the wrong kind of entity is a request to destroy the wrong kind of thing."
|
|
1884
2183
|
);
|
|
1885
2184
|
}
|
|
1886
2185
|
const session = loadSession();
|
|
@@ -2672,8 +2971,8 @@ var COMMANDS = [
|
|
|
2672
2971
|
{
|
|
2673
2972
|
name: "comment",
|
|
2674
2973
|
cost: "1 call \u2014 write",
|
|
2675
|
-
summary: "
|
|
2676
|
-
usage: 'lnrelay comment <activity-urn> "<text>"\n Fetches the post page (~2.8 MB) to harvest a binding key and trackingId, proves
|
|
2974
|
+
summary: "Add a comment to a post. Harvests its binding tokens from the rendered page; no browser needed, but it costs one heavy read.",
|
|
2975
|
+
usage: 'lnrelay comment <activity-urn> "<text>"\n Fetches the post page (~2.8 MB) to harvest a binding key and trackingId, and proves\n the key belongs to that post before asking. To change a comment, see `edit`.',
|
|
2677
2976
|
audience: ["cli"],
|
|
2678
2977
|
risk: "write",
|
|
2679
2978
|
implemented: true
|
|
@@ -2681,8 +2980,17 @@ var COMMANDS = [
|
|
|
2681
2980
|
{
|
|
2682
2981
|
name: "delete",
|
|
2683
2982
|
cost: "1 read + 1 write",
|
|
2684
|
-
summary: "Delete one of your own posts. Reads
|
|
2685
|
-
usage: "lnrelay delete <urn
|
|
2983
|
+
summary: "Delete one of your own posts or comments. Reads a post back and shows its text first \u2014 this is the one action that cannot be undone.",
|
|
2984
|
+
usage: "lnrelay delete <activity-urn> # a post; shows you its text before destroying it\n lnrelay delete <comment-urn> # a comment; the server decides if you may",
|
|
2985
|
+
audience: ["cli"],
|
|
2986
|
+
risk: "write",
|
|
2987
|
+
implemented: true
|
|
2988
|
+
},
|
|
2989
|
+
{
|
|
2990
|
+
name: "edit",
|
|
2991
|
+
cost: "1 read + 1 write",
|
|
2992
|
+
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.",
|
|
2993
|
+
usage: 'lnrelay edit <comment-urn> "<text>"',
|
|
2686
2994
|
audience: ["cli"],
|
|
2687
2995
|
risk: "write",
|
|
2688
2996
|
implemented: true
|
|
@@ -2916,89 +3224,10 @@ function share2(confirmed, token, deps) {
|
|
|
2916
3224
|
);
|
|
2917
3225
|
}
|
|
2918
3226
|
|
|
2919
|
-
// src/engine/sdui-harvest.ts
|
|
2920
|
-
function zigzag(n) {
|
|
2921
|
-
return n << 1n ^ n >> 63n;
|
|
2922
|
-
}
|
|
2923
|
-
function varint(n) {
|
|
2924
|
-
const out = [];
|
|
2925
|
-
let v = n;
|
|
2926
|
-
while (v > 0x7fn) {
|
|
2927
|
-
out.push(Number(v & 0x7fn | 0x80n));
|
|
2928
|
-
v >>= 7n;
|
|
2929
|
-
}
|
|
2930
|
-
out.push(Number(v));
|
|
2931
|
-
return out;
|
|
2932
|
-
}
|
|
2933
|
-
function activityIdSegment(activityId) {
|
|
2934
|
-
if (!/^\d+$/.test(activityId)) {
|
|
2935
|
-
throw new Error(`'${activityId}' is not a numeric activity id`);
|
|
2936
|
-
}
|
|
2937
|
-
const inner = [8, ...varint(zigzag(BigInt(activityId)))];
|
|
2938
|
-
const message = Uint8Array.from([10, inner.length, ...inner]);
|
|
2939
|
-
return btoa(String.fromCharCode(...message)).replace(/=+$/, "");
|
|
2940
|
-
}
|
|
2941
|
-
function keyMatchesPost(bindingKey, activityId) {
|
|
2942
|
-
try {
|
|
2943
|
-
return bindingKey.startsWith(`commentBoxText-${activityIdSegment(activityId)}-`);
|
|
2944
|
-
} catch {
|
|
2945
|
-
return false;
|
|
2946
|
-
}
|
|
2947
|
-
}
|
|
2948
|
-
var NOT_THE_POST = /checkpoint\/challenge|\/uas\/login|authwall|"status"\s*:\s*999/i;
|
|
2949
|
-
var TRACKING_PROXIMITY = 400;
|
|
2950
|
-
function updateTrackingId(html, activityId) {
|
|
2951
|
-
const idAt = [...html.matchAll(new RegExp(activityId, "g"))].map((m) => m.index ?? 0);
|
|
2952
|
-
if (idAt.length === 0) return null;
|
|
2953
|
-
const pattern = /trackingId(?:"|\\?")+\s*:\s*(?:"|\\?")+([A-Za-z0-9+/=]{16,32})/g;
|
|
2954
|
-
let best = null;
|
|
2955
|
-
for (const m of html.matchAll(pattern)) {
|
|
2956
|
-
const at = m.index ?? 0;
|
|
2957
|
-
const distance = Math.min(...idAt.map((p) => Math.abs(p - at)));
|
|
2958
|
-
if (best === null || distance < best.distance) best = { value: m[1], distance };
|
|
2959
|
-
}
|
|
2960
|
-
return best !== null && best.distance <= TRACKING_PROXIMITY ? best.value : null;
|
|
2961
|
-
}
|
|
2962
|
-
function extractCommentTokens(html, activityId) {
|
|
2963
|
-
if (NOT_THE_POST.test(html)) {
|
|
2964
|
-
return {
|
|
2965
|
-
ok: false,
|
|
2966
|
-
message: "the page returned was a challenge or sign-in wall, not the post",
|
|
2967
|
-
hint: "Re-mint the session with `lnrelay login`, then check `lnrelay risk`."
|
|
2968
|
-
};
|
|
2969
|
-
}
|
|
2970
|
-
let expected;
|
|
2971
|
-
try {
|
|
2972
|
-
expected = activityIdSegment(activityId);
|
|
2973
|
-
} catch (e) {
|
|
2974
|
-
return { ok: false, message: e.message };
|
|
2975
|
-
}
|
|
2976
|
-
const keyPattern = new RegExp(
|
|
2977
|
-
`commentBoxText-${expected.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}-[A-Za-z0-9+/_=-]*FeedType_[A-Z_]+`
|
|
2978
|
-
);
|
|
2979
|
-
const key = keyPattern.exec(html)?.[0];
|
|
2980
|
-
if (key === void 0) {
|
|
2981
|
-
return {
|
|
2982
|
-
ok: false,
|
|
2983
|
-
message: `no comment-box binding key for post ${activityId} was found in the page`,
|
|
2984
|
-
hint: "Either the post does not accept comments, or LinkedIn changed the rendered shape. Re-capture with `bun run scripts/observe-write.ts` before changing this parser."
|
|
2985
|
-
};
|
|
2986
|
-
}
|
|
2987
|
-
const trackingId = updateTrackingId(html, activityId);
|
|
2988
|
-
if (trackingId === null) {
|
|
2989
|
-
return {
|
|
2990
|
-
ok: false,
|
|
2991
|
-
message: `no trackingId adjacent to post ${activityId} was found in the page`,
|
|
2992
|
-
hint: "The page carries several \u2014 one for the page itself, one per rendered update. Only the update's own will do, and guessing would build a malformed comment."
|
|
2993
|
-
};
|
|
2994
|
-
}
|
|
2995
|
-
return { ok: true, bindingKey: key, trackingId };
|
|
2996
|
-
}
|
|
2997
|
-
|
|
2998
3227
|
// src/engine/sdui-comment.ts
|
|
2999
|
-
var
|
|
3000
|
-
var COMMENT_URL = `${
|
|
3001
|
-
var
|
|
3228
|
+
var SDUI_ACTION2 = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
|
|
3229
|
+
var COMMENT_URL = `${SDUI_ACTION2}?sduiid=com.linkedin.sdui.comments.createComment`;
|
|
3230
|
+
var SCREEN_ID2 = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
|
|
3002
3231
|
var STATE_PREFIXES = [
|
|
3003
3232
|
"commentBoxText",
|
|
3004
3233
|
"richCommentBoxText",
|
|
@@ -3089,7 +3318,7 @@ function commentBody(activityId, text2, tokens, feedType) {
|
|
|
3089
3318
|
requestedArguments: {
|
|
3090
3319
|
...args,
|
|
3091
3320
|
states: states(text2, body),
|
|
3092
|
-
screenId:
|
|
3321
|
+
screenId: SCREEN_ID2,
|
|
3093
3322
|
knownTemplateIds: []
|
|
3094
3323
|
}
|
|
3095
3324
|
};
|
|
@@ -3129,8 +3358,8 @@ async function comment(confirmed, client) {
|
|
|
3129
3358
|
}
|
|
3130
3359
|
|
|
3131
3360
|
// src/engine/sdui-write.ts
|
|
3132
|
-
var
|
|
3133
|
-
var
|
|
3361
|
+
var SDUI_ACTION3 = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
|
|
3362
|
+
var SCREEN_ID3 = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
|
|
3134
3363
|
var REACTIONS = [
|
|
3135
3364
|
"LIKE",
|
|
3136
3365
|
"PRAISE",
|
|
@@ -3151,7 +3380,7 @@ function reactionLabel(reaction) {
|
|
|
3151
3380
|
return LABELS[reaction];
|
|
3152
3381
|
}
|
|
3153
3382
|
function reactionUrl(op) {
|
|
3154
|
-
return `${
|
|
3383
|
+
return `${SDUI_ACTION3}?sduiid=com.linkedin.sdui.reactions.${op}`;
|
|
3155
3384
|
}
|
|
3156
3385
|
function targetFor(urn) {
|
|
3157
3386
|
const comment2 = /^urn:li:comment:\((urn:li:activity:\d+),(\d+)\)$/.exec(urn);
|
|
@@ -3207,7 +3436,7 @@ function sduiBody(op, target, reaction) {
|
|
|
3207
3436
|
requestedArguments: {
|
|
3208
3437
|
...args,
|
|
3209
3438
|
states: [],
|
|
3210
|
-
screenId:
|
|
3439
|
+
screenId: SCREEN_ID3,
|
|
3211
3440
|
knownTemplateIds: []
|
|
3212
3441
|
}
|
|
3213
3442
|
};
|
|
@@ -3380,9 +3609,22 @@ async function runComment(postUrn2, text2, now = Date.now(), deps = terminalDeps
|
|
|
3380
3609
|
'lnrelay comment <urn> "<text>"'
|
|
3381
3610
|
);
|
|
3382
3611
|
}
|
|
3612
|
+
if (parseCommentUrn(postUrn2) !== null) {
|
|
3613
|
+
return err(
|
|
3614
|
+
"comment",
|
|
3615
|
+
"INVALID_INPUT",
|
|
3616
|
+
"that is a comment urn, not a post urn",
|
|
3617
|
+
`To change its text: lnrelay edit ${postUrn2} "<text>". Replying to a comment is not implemented \u2014 pass the POST urn to add a top-level comment.`
|
|
3618
|
+
);
|
|
3619
|
+
}
|
|
3383
3620
|
const activityId = activityIdOf(postUrn2);
|
|
3384
3621
|
if (activityId === null) {
|
|
3385
|
-
return err(
|
|
3622
|
+
return err(
|
|
3623
|
+
"comment",
|
|
3624
|
+
"INVALID_INPUT",
|
|
3625
|
+
`'${postUrn2}' does not identify a post`,
|
|
3626
|
+
"Pass urn:li:activity:<id>."
|
|
3627
|
+
);
|
|
3386
3628
|
}
|
|
3387
3629
|
if (!deps.isTty) {
|
|
3388
3630
|
return err(
|
|
@@ -3404,7 +3646,7 @@ async function runComment(postUrn2, text2, now = Date.now(), deps = terminalDeps
|
|
|
3404
3646
|
action: "comment on a post",
|
|
3405
3647
|
payload: { activityId, text: text2, tokens: harvested.tokens },
|
|
3406
3648
|
summary: [authorLine(ctx.transport), `on ${postUrn2}`, `content "${text2}"`],
|
|
3407
|
-
reversibility: "deletable
|
|
3649
|
+
reversibility: "deletable with `lnrelay delete <comment-urn>`; the author is notified immediately",
|
|
3408
3650
|
transport: "voyager"
|
|
3409
3651
|
};
|
|
3410
3652
|
const gated = await gate("comment", plan, ctx, deps);
|
|
@@ -3413,7 +3655,58 @@ async function runComment(postUrn2, text2, now = Date.now(), deps = terminalDeps
|
|
|
3413
3655
|
gated.confirmed,
|
|
3414
3656
|
createLiveClient(ctx.transport.session)
|
|
3415
3657
|
);
|
|
3416
|
-
return result.ok ? ok("comment", {
|
|
3658
|
+
return result.ok ? ok("comment", { on: postUrn2 }) : err("comment", result.code, result.message, result.hint);
|
|
3659
|
+
}
|
|
3660
|
+
async function runEdit(commentUrn, text2, now = Date.now(), deps = terminalDeps()) {
|
|
3661
|
+
if (commentUrn === void 0 || text2 === void 0 || text2.trim() === "") {
|
|
3662
|
+
return err(
|
|
3663
|
+
"edit",
|
|
3664
|
+
"INVALID_INPUT",
|
|
3665
|
+
"a comment urn and the new text are required",
|
|
3666
|
+
'lnrelay edit <comment-urn> "<text>"'
|
|
3667
|
+
);
|
|
3668
|
+
}
|
|
3669
|
+
const ref = parseCommentUrn(commentUrn);
|
|
3670
|
+
if (ref === null) {
|
|
3671
|
+
return err(
|
|
3672
|
+
"edit",
|
|
3673
|
+
"INVALID_INPUT",
|
|
3674
|
+
`'${commentUrn}' is not a comment urn`,
|
|
3675
|
+
"Only comments can be edited here \u2014 a published post cannot. Get the urn from `lnrelay post <activity-urn>`."
|
|
3676
|
+
);
|
|
3677
|
+
}
|
|
3678
|
+
if (!deps.isTty) {
|
|
3679
|
+
return err(
|
|
3680
|
+
"edit",
|
|
3681
|
+
"CONFIRMATION_REQUIRED",
|
|
3682
|
+
"editing needs a human to confirm it at an interactive terminal",
|
|
3683
|
+
"No terminal is attached, so nothing was sent and no network call was made."
|
|
3684
|
+
);
|
|
3685
|
+
}
|
|
3686
|
+
const ctx = prepare("edit", now, "voyager");
|
|
3687
|
+
if ("ok" in ctx) return ctx;
|
|
3688
|
+
if (ctx.transport.kind !== "voyager") {
|
|
3689
|
+
return err("edit", "NOT_IMPLEMENTED", "editing is only implemented over the private API");
|
|
3690
|
+
}
|
|
3691
|
+
const harvested = await harvest(ref.activityId, ctx.transport.session, now);
|
|
3692
|
+
if (!("tokens" in harvested)) return harvested;
|
|
3693
|
+
const plan = {
|
|
3694
|
+
action: "edit your comment",
|
|
3695
|
+
payload: { urn: commentUrn, text: text2 },
|
|
3696
|
+
summary: [authorLine(ctx.transport), `comment ${commentUrn}`, `new text "${text2}"`],
|
|
3697
|
+
reversibility: "editable again, but the previous text is NOT recoverable here and LinkedIn marks the comment as edited",
|
|
3698
|
+
transport: "voyager"
|
|
3699
|
+
};
|
|
3700
|
+
const gated = await gate("edit", plan, ctx, deps);
|
|
3701
|
+
if ("ok" in gated) return gated;
|
|
3702
|
+
const result = await runCommentAction(
|
|
3703
|
+
ref,
|
|
3704
|
+
UPDATE_OP,
|
|
3705
|
+
harvested.tokens.trackingId,
|
|
3706
|
+
createLiveClient(ctx.transport.session),
|
|
3707
|
+
text2
|
|
3708
|
+
);
|
|
3709
|
+
return result.ok ? ok("edit", { edited: commentUrn }) : err("edit", result.code, result.message, result.hint);
|
|
3417
3710
|
}
|
|
3418
3711
|
var REACTIONS2 = REACTIONS;
|
|
3419
3712
|
async function runReact(postUrn2, type, now = Date.now(), deps = terminalDeps(), remove = false) {
|
|
@@ -3610,6 +3903,8 @@ async function dispatch(argv, now) {
|
|
|
3610
3903
|
}
|
|
3611
3904
|
case "comment":
|
|
3612
3905
|
return runComment(args.positionals[0], args.positionals[1], now);
|
|
3906
|
+
case "edit":
|
|
3907
|
+
return runEdit(args.positionals[0], args.positionals[1], now);
|
|
3613
3908
|
case "react":
|
|
3614
3909
|
return runReact(
|
|
3615
3910
|
args.positionals[0],
|