linkedin-relay-mcp 3.22.0 → 3.24.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 +15 -1
- package/README.md +2 -1
- package/dist/cli.js +728 -54
- package/dist/cli.js.map +1 -1
- package/dist/index.js +11 -2
- package/dist/index.js.map +1 -1
- package/dist/mcp-shim.js +235 -8
- package/dist/mcp-shim.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// src/cli.ts
|
|
3
|
-
import { readFileSync as
|
|
3
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
4
4
|
|
|
5
5
|
// src/args.ts
|
|
6
6
|
function parseArgs(argv) {
|
|
@@ -1481,10 +1481,10 @@ function classify(res, opts = {}) {
|
|
|
1481
1481
|
function referencesUrns(data) {
|
|
1482
1482
|
if (data === void 0) return false;
|
|
1483
1483
|
let found = false;
|
|
1484
|
-
const
|
|
1484
|
+
const walk2 = (node) => {
|
|
1485
1485
|
if (found || node === null || typeof node !== "object") return;
|
|
1486
1486
|
if (Array.isArray(node)) {
|
|
1487
|
-
for (const item of node)
|
|
1487
|
+
for (const item of node) walk2(item);
|
|
1488
1488
|
return;
|
|
1489
1489
|
}
|
|
1490
1490
|
for (const [key, value] of Object.entries(node)) {
|
|
@@ -1496,10 +1496,10 @@ function referencesUrns(data) {
|
|
|
1496
1496
|
found = true;
|
|
1497
1497
|
return;
|
|
1498
1498
|
}
|
|
1499
|
-
|
|
1499
|
+
walk2(value);
|
|
1500
1500
|
}
|
|
1501
1501
|
};
|
|
1502
|
-
|
|
1502
|
+
walk2(data);
|
|
1503
1503
|
return found;
|
|
1504
1504
|
}
|
|
1505
1505
|
|
|
@@ -1698,18 +1698,18 @@ function findRefs(data) {
|
|
|
1698
1698
|
}
|
|
1699
1699
|
}
|
|
1700
1700
|
const refs = [];
|
|
1701
|
-
const
|
|
1701
|
+
const walk2 = (node) => {
|
|
1702
1702
|
if (node === null || typeof node !== "object") return;
|
|
1703
1703
|
if (Array.isArray(node)) {
|
|
1704
|
-
for (const item of node)
|
|
1704
|
+
for (const item of node) walk2(item);
|
|
1705
1705
|
return;
|
|
1706
1706
|
}
|
|
1707
1707
|
for (const [key, value] of Object.entries(node)) {
|
|
1708
1708
|
if (key.startsWith("*") && typeof value === "string") refs.push(value);
|
|
1709
|
-
else
|
|
1709
|
+
else walk2(value);
|
|
1710
1710
|
}
|
|
1711
1711
|
};
|
|
1712
|
-
|
|
1712
|
+
walk2(data);
|
|
1713
1713
|
return refs;
|
|
1714
1714
|
}
|
|
1715
1715
|
function parseSingle(payload) {
|
|
@@ -1754,9 +1754,9 @@ function parseCollection(payload, opts) {
|
|
|
1754
1754
|
`LinkedIn claims ${opts.claimedCount} items but returned none \u2014 treat this as a FAILED FETCH, not an empty result.`
|
|
1755
1755
|
);
|
|
1756
1756
|
}
|
|
1757
|
-
const
|
|
1757
|
+
const state2 = unresolved.length > 0 ? "partial" : opts.truncated === true ? "unknown" : "complete";
|
|
1758
1758
|
const meta = {
|
|
1759
|
-
state,
|
|
1759
|
+
state: state2,
|
|
1760
1760
|
operation: opts.operation,
|
|
1761
1761
|
contractCapturedAt: opts.contractCapturedAt ?? "unknown",
|
|
1762
1762
|
// parsedCount counts what we kept; `items` includes the unknowns, which is
|
|
@@ -2045,7 +2045,7 @@ async function mintSessionFromBrowser() {
|
|
|
2045
2045
|
};
|
|
2046
2046
|
}
|
|
2047
2047
|
function getAllCookies(wsUrl) {
|
|
2048
|
-
return new Promise((
|
|
2048
|
+
return new Promise((resolve2, reject) => {
|
|
2049
2049
|
const ws = new WebSocket(wsUrl);
|
|
2050
2050
|
const timer = setTimeout(() => {
|
|
2051
2051
|
ws.close();
|
|
@@ -2057,7 +2057,7 @@ function getAllCookies(wsUrl) {
|
|
|
2057
2057
|
if (msg.id === 1 && msg.result !== void 0) {
|
|
2058
2058
|
clearTimeout(timer);
|
|
2059
2059
|
ws.close();
|
|
2060
|
-
|
|
2060
|
+
resolve2(msg.result.cookies);
|
|
2061
2061
|
}
|
|
2062
2062
|
};
|
|
2063
2063
|
ws.onerror = () => {
|
|
@@ -2296,14 +2296,14 @@ function evaluate(expression, model) {
|
|
|
2296
2296
|
const value = bool2(expression, model);
|
|
2297
2297
|
return value === null ? unknownExpression(JSON.stringify(expression).slice(0, 80)) : { ok: true, value };
|
|
2298
2298
|
}
|
|
2299
|
-
function wireStates(keys, model,
|
|
2299
|
+
function wireStates(keys, model, resolve2) {
|
|
2300
2300
|
const out = [];
|
|
2301
2301
|
for (const id of keys) {
|
|
2302
|
-
const
|
|
2303
|
-
if (
|
|
2304
|
-
let value =
|
|
2305
|
-
if (
|
|
2306
|
-
const r =
|
|
2302
|
+
const state2 = model.get(id);
|
|
2303
|
+
if (state2 === void 0) continue;
|
|
2304
|
+
let value = state2.value;
|
|
2305
|
+
if (state2.protoCase === "expression") {
|
|
2306
|
+
const r = resolve2(id, state2) ?? evaluate(state2.value, model);
|
|
2307
2307
|
if (!r.ok) return r;
|
|
2308
2308
|
value = r.value;
|
|
2309
2309
|
}
|
|
@@ -2311,7 +2311,7 @@ function wireStates(keys, model, resolve) {
|
|
|
2311
2311
|
key: id,
|
|
2312
2312
|
namespace: "MemoryNamespace",
|
|
2313
2313
|
value,
|
|
2314
|
-
originalProtoCase:
|
|
2314
|
+
originalProtoCase: state2.protoCase,
|
|
2315
2315
|
protoKey: { $type: "proto.sdui.Key", value: { $case: "id", id } }
|
|
2316
2316
|
});
|
|
2317
2317
|
}
|
|
@@ -2489,7 +2489,7 @@ function firstIn(rows, ids, find) {
|
|
|
2489
2489
|
}
|
|
2490
2490
|
function authorOf(rows, actor) {
|
|
2491
2491
|
if (actor === void 0) return { fields: {}, used: [] };
|
|
2492
|
-
const
|
|
2492
|
+
const state2 = (key) => (row) => {
|
|
2493
2493
|
const m = row.match(new RegExp(`"${key}"[^]*?"stringValue":"((?:[^"\\\\]|\\\\.)*)"`));
|
|
2494
2494
|
return m?.[1] === void 0 ? void 0 : jsonString(m[1]);
|
|
2495
2495
|
};
|
|
@@ -2500,8 +2500,8 @@ function authorOf(rows, actor) {
|
|
|
2500
2500
|
/"(?:https:\/\/www\.linkedin\.com)?(\/(?:in|company|school|showcase)\/[^"?/]+)/
|
|
2501
2501
|
)?.[1]
|
|
2502
2502
|
);
|
|
2503
|
-
const person = firstIn(rows, actor.under,
|
|
2504
|
-
const headline = firstIn(rows, actor.under,
|
|
2503
|
+
const person = firstIn(rows, actor.under, state2("profile_name_loading_state"));
|
|
2504
|
+
const headline = firstIn(rows, actor.under, state2("profile_headline_loading_state"));
|
|
2505
2505
|
const page = person !== void 0 ? void 0 : firstIn(rows, actor.under, (row) => {
|
|
2506
2506
|
const labels = [...row.matchAll(/"aria-label":"((?:[^"\\]|\\.)+)"/g)].map(
|
|
2507
2507
|
(m) => jsonString(m[1]).trim()
|
|
@@ -4105,8 +4105,8 @@ async function fetchScheduled(client, pageSize = PAGE_SIZE2) {
|
|
|
4105
4105
|
}
|
|
4106
4106
|
if (posts.length >= claimedCount || fresh.length === 0) break;
|
|
4107
4107
|
}
|
|
4108
|
-
const
|
|
4109
|
-
return { ok: true, posts, claimedCount, state };
|
|
4108
|
+
const state2 = posts.length >= claimedCount ? "complete" : "partial";
|
|
4109
|
+
return { ok: true, posts, claimedCount, state: state2 };
|
|
4110
4110
|
}
|
|
4111
4111
|
|
|
4112
4112
|
// src/engine/voyager-write.ts
|
|
@@ -6401,12 +6401,12 @@ var USERINFO = "https://api.linkedin.com/v2/userinfo";
|
|
|
6401
6401
|
var CALLBACK_PORT = 53682;
|
|
6402
6402
|
var REDIRECT_URI = `http://localhost:${CALLBACK_PORT}/callback`;
|
|
6403
6403
|
var SCOPES = ["openid", "profile", "w_member_social"];
|
|
6404
|
-
function authorizationUrl(clientId,
|
|
6404
|
+
function authorizationUrl(clientId, state2) {
|
|
6405
6405
|
const params = new URLSearchParams({
|
|
6406
6406
|
response_type: "code",
|
|
6407
6407
|
client_id: clientId,
|
|
6408
6408
|
redirect_uri: REDIRECT_URI,
|
|
6409
|
-
state,
|
|
6409
|
+
state: state2,
|
|
6410
6410
|
scope: SCOPES.join(" ")
|
|
6411
6411
|
});
|
|
6412
6412
|
return `${AUTHORIZE}?${params.toString()}`;
|
|
@@ -6483,8 +6483,8 @@ function parseCallback(rawUrl, expectedState) {
|
|
|
6483
6483
|
const description = url.searchParams.get("error_description") ?? "";
|
|
6484
6484
|
return { ok: false, message: `LinkedIn denied the request: ${error} ${description}`.trim() };
|
|
6485
6485
|
}
|
|
6486
|
-
const
|
|
6487
|
-
if (
|
|
6486
|
+
const state2 = url.searchParams.get("state");
|
|
6487
|
+
if (state2 !== expectedState) {
|
|
6488
6488
|
return { ok: false, message: "state mismatch \u2014 this callback did not come from this login" };
|
|
6489
6489
|
}
|
|
6490
6490
|
const code = url.searchParams.get("code");
|
|
@@ -6529,7 +6529,7 @@ var CALLBACK_TIMEOUT_MS = 3e5;
|
|
|
6529
6529
|
var DONE_PAGE = `<!doctype html><meta charset="utf-8"><title>lnrelay</title>
|
|
6530
6530
|
<body style="font:16px system-ui;padding:3rem;max-width:32rem">
|
|
6531
6531
|
<h1>Authorised.</h1><p>You can close this tab and go back to the terminal.</p>`;
|
|
6532
|
-
function listenForCallback(
|
|
6532
|
+
function listenForCallback(state2, timeoutMs = CALLBACK_TIMEOUT_MS) {
|
|
6533
6533
|
return new Promise((ready) => {
|
|
6534
6534
|
let settle = () => {
|
|
6535
6535
|
};
|
|
@@ -6545,7 +6545,7 @@ function listenForCallback(state, timeoutMs = CALLBACK_TIMEOUT_MS) {
|
|
|
6545
6545
|
}
|
|
6546
6546
|
res.writeHead(200, { "content-type": "text/html; charset=utf-8", connection: "close" });
|
|
6547
6547
|
res.end(DONE_PAGE);
|
|
6548
|
-
settle(parseCallback(url,
|
|
6548
|
+
settle(parseCallback(url, state2));
|
|
6549
6549
|
});
|
|
6550
6550
|
const timer = setTimeout(() => {
|
|
6551
6551
|
settle({
|
|
@@ -6579,7 +6579,7 @@ function openBrowser(url) {
|
|
|
6579
6579
|
function loginDeps() {
|
|
6580
6580
|
return {
|
|
6581
6581
|
state: () => crypto.randomUUID(),
|
|
6582
|
-
listen: (
|
|
6582
|
+
listen: (state2) => listenForCallback(state2),
|
|
6583
6583
|
open: openBrowser,
|
|
6584
6584
|
write: (s) => process.stderr.write(s),
|
|
6585
6585
|
isTty: process.stdin.isTTY === true && process.stderr.isTTY === true,
|
|
@@ -6617,13 +6617,13 @@ ${OAUTH_SETUP}`
|
|
|
6617
6617
|
async function runOauthLogin(opts, deps = loginDeps()) {
|
|
6618
6618
|
const creds = await credentials(opts, deps);
|
|
6619
6619
|
if ("ok" in creds) return creds;
|
|
6620
|
-
const
|
|
6621
|
-
const listener = await deps.listen(
|
|
6620
|
+
const state2 = deps.state();
|
|
6621
|
+
const listener = await deps.listen(state2);
|
|
6622
6622
|
if (!listener.ok) {
|
|
6623
6623
|
return err("oauth", "AUTH_FAILED", listener.message);
|
|
6624
6624
|
}
|
|
6625
6625
|
try {
|
|
6626
|
-
const url = authorizationUrl(creds.clientId,
|
|
6626
|
+
const url = authorizationUrl(creds.clientId, state2);
|
|
6627
6627
|
deps.write(`Opening LinkedIn for consent. If nothing opens, visit:
|
|
6628
6628
|
|
|
6629
6629
|
${url}
|
|
@@ -7305,6 +7305,15 @@ var COMMANDS = [
|
|
|
7305
7305
|
risk: "read",
|
|
7306
7306
|
implemented: true
|
|
7307
7307
|
},
|
|
7308
|
+
{
|
|
7309
|
+
name: "viewers",
|
|
7310
|
+
cost: "2 page calls",
|
|
7311
|
+
summary: "Who viewed your profile, as your profile-views page shows it: the total for the period, the viewers LinkedIn names (up to 3 on a free account), anonymous ones as LinkedIn describes them, and how many looked in private mode.",
|
|
7312
|
+
usage: "lnrelay viewers [--compact | --fields a,b,c]",
|
|
7313
|
+
audience: ["cli", "mcp"],
|
|
7314
|
+
risk: "read",
|
|
7315
|
+
implemented: true
|
|
7316
|
+
},
|
|
7308
7317
|
{
|
|
7309
7318
|
name: "network",
|
|
7310
7319
|
cost: "1 page call per 50 rows; the counts are 7 calls",
|
|
@@ -7462,8 +7471,8 @@ var COMMANDS = [
|
|
|
7462
7471
|
{
|
|
7463
7472
|
name: "edit",
|
|
7464
7473
|
cost: "1 read + 1 write",
|
|
7465
|
-
summary: "Change the text of a comment or post you wrote, or your profile
|
|
7466
|
-
usage: 'lnrelay edit <comment-urn | share-urn | ugcPost-urn> "<text>"\n lnrelay edit headline|about ("<text>" | --file <path>)\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. A profile edit\n shows the current text beside the new one, sends every other profile field back as\n LinkedIn holds it, and reads the profile back to confirm. Headline max 220 characters.',
|
|
7474
|
+
summary: "Change the text of a comment or post you wrote, your profile headline or About, or your profile photo or cover image. Its own verb, so a comment urn can never be mistaken for something to comment ON.",
|
|
7475
|
+
usage: 'lnrelay edit <comment-urn | share-urn | ugcPost-urn> "<text>"\n lnrelay edit headline|about ("<text>" | --file <path>)\n lnrelay edit photo|banner <image.png|jpg> (photo square, banner 4:1, max 8 MB)\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. A profile edit\n shows the current text beside the new one, sends every other profile field back as\n LinkedIn holds it, and reads the profile back to confirm. Headline max 220 characters.\n An image is uploaded as it is, uncropped, and read back: it must be the one showing.',
|
|
7467
7476
|
audience: ["cli"],
|
|
7468
7477
|
risk: "write",
|
|
7469
7478
|
implemented: true
|
|
@@ -7830,8 +7839,8 @@ async function sendPositionDelete(form, client) {
|
|
|
7830
7839
|
}
|
|
7831
7840
|
|
|
7832
7841
|
// src/commands/write.ts
|
|
7833
|
-
import { readFileSync as
|
|
7834
|
-
import { basename } from "path";
|
|
7842
|
+
import { readFileSync as readFileSync4, statSync as statSync2 } from "fs";
|
|
7843
|
+
import { basename as basename2 } from "path";
|
|
7835
7844
|
|
|
7836
7845
|
// src/engine/oauth-write.ts
|
|
7837
7846
|
var API = "https://api.linkedin.com";
|
|
@@ -7966,7 +7975,7 @@ function states(text6, body) {
|
|
|
7966
7975
|
function commentBody(activityId, text6, tokens, feedType) {
|
|
7967
7976
|
const body = keyBody(tokens.bindingKey);
|
|
7968
7977
|
const activityUrn = { activityUrn: { activityId } };
|
|
7969
|
-
const
|
|
7978
|
+
const binding2 = (prefix) => ({
|
|
7970
7979
|
key: stateKey(prefix, body),
|
|
7971
7980
|
namespace: "MemoryNamespace"
|
|
7972
7981
|
});
|
|
@@ -7986,11 +7995,11 @@ function commentBody(activityId, text6, tokens, feedType) {
|
|
|
7986
7995
|
},
|
|
7987
7996
|
threadUrn: { threadUrnActivityThreadUrn: activityUrn }
|
|
7988
7997
|
},
|
|
7989
|
-
commentFieldBinding:
|
|
7990
|
-
richCommentFieldBinding:
|
|
7991
|
-
linkPreviewIngestedContentId:
|
|
7992
|
-
externalImageUrl:
|
|
7993
|
-
externalImageId:
|
|
7998
|
+
commentFieldBinding: binding2("commentBoxText"),
|
|
7999
|
+
richCommentFieldBinding: binding2("richCommentBoxText"),
|
|
8000
|
+
linkPreviewIngestedContentId: binding2("commentBoxLinkPreviewIngestedContentId"),
|
|
8001
|
+
externalImageUrl: binding2("commentBoxExternalImageUrl"),
|
|
8002
|
+
externalImageId: binding2("commentBoxExternalImageId")
|
|
7994
8003
|
};
|
|
7995
8004
|
const requestedStateKeys = STATE_PREFIXES.map((p) => ({
|
|
7996
8005
|
key: { value: { $case: "id", id: stateKey(p, body) } }
|
|
@@ -8197,6 +8206,463 @@ async function replyToComment(confirmed, client) {
|
|
|
8197
8206
|
return { ok: true, parent: parentThreadUrn(ref) };
|
|
8198
8207
|
}
|
|
8199
8208
|
|
|
8209
|
+
// src/commands/profile-image.ts
|
|
8210
|
+
import { readFileSync as readFileSync3, statSync } from "fs";
|
|
8211
|
+
import { basename, resolve } from "path";
|
|
8212
|
+
|
|
8213
|
+
// src/engine/sdui-profile-image.ts
|
|
8214
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
8215
|
+
var IMAGE_KINDS = {
|
|
8216
|
+
photo: {
|
|
8217
|
+
name: "photo",
|
|
8218
|
+
label: "profile photo",
|
|
8219
|
+
screen: "com.linkedin.sdui.flagshipnav.profile.ProfileAddPicture",
|
|
8220
|
+
originalType: "ProfileOriginalPhoto",
|
|
8221
|
+
displayType: "ProfileDisplayPhoto",
|
|
8222
|
+
save: "com.linkedin.sdui.requests.profile.saveProfilePicture",
|
|
8223
|
+
aspect: 1
|
|
8224
|
+
},
|
|
8225
|
+
banner: {
|
|
8226
|
+
name: "banner",
|
|
8227
|
+
label: "cover image",
|
|
8228
|
+
screen: "com.linkedin.sdui.flagshipnav.profile.ProfileAddBackgroundImage",
|
|
8229
|
+
originalType: "ProfileOriginalBackground",
|
|
8230
|
+
displayType: "ProfileDisplayBackground",
|
|
8231
|
+
save: "com.linkedin.sdui.requests.profile.saveProfileBackgroundImage",
|
|
8232
|
+
aspect: 4
|
|
8233
|
+
}
|
|
8234
|
+
};
|
|
8235
|
+
var REGISTER = "com.linkedin.sdui.requests.profile.profileImageRegister";
|
|
8236
|
+
var REGISTER_REQUEST = REGISTER;
|
|
8237
|
+
var NS = "MemoryNamespace";
|
|
8238
|
+
var PHOTO_SAVING = "ADD_PHOTOPROFILE_PHOTO_UPLOAD_IS_SAVING";
|
|
8239
|
+
var binding = () => `auto-binding-${randomUUID2()}`;
|
|
8240
|
+
var pointer = () => Math.random().toString(36).slice(2, 13).padEnd(11, "0");
|
|
8241
|
+
function newKeys(kind) {
|
|
8242
|
+
return {
|
|
8243
|
+
originalMedia: binding(),
|
|
8244
|
+
originalAssetUrns: binding(),
|
|
8245
|
+
displayMedia: binding(),
|
|
8246
|
+
displayAssetUrns: binding(),
|
|
8247
|
+
saving: kind.name === "photo" ? PHOTO_SAVING : binding(),
|
|
8248
|
+
originalPointer: pointer(),
|
|
8249
|
+
displayPointer: pointer()
|
|
8250
|
+
};
|
|
8251
|
+
}
|
|
8252
|
+
var focusKey = (vanity) => `ProfileComponentStateLastPerformedActionRef${vanity}ProfileComponentState`;
|
|
8253
|
+
var bind = (key) => ({ key, namespace: NS });
|
|
8254
|
+
var stateKey2 = (id) => ({ key: { value: { $case: "id", id } } });
|
|
8255
|
+
var META = { $type: "proto.sdui.common.RequestMetadata" };
|
|
8256
|
+
var WHOLE_IMAGE = {
|
|
8257
|
+
$type: "proto.sdui.media.MediaEditData",
|
|
8258
|
+
croppedRegion: {
|
|
8259
|
+
$type: "proto.sdui.common.Rect",
|
|
8260
|
+
topLeft: { $type: "proto.sdui.common.Coordinate2D", x: 0, y: 0 },
|
|
8261
|
+
topRight: { $type: "proto.sdui.common.Coordinate2D", x: 1, y: 0 },
|
|
8262
|
+
bottomLeft: { $type: "proto.sdui.common.Coordinate2D", x: 0, y: 1 },
|
|
8263
|
+
bottomRight: { $type: "proto.sdui.common.Coordinate2D", x: 1, y: 1 }
|
|
8264
|
+
},
|
|
8265
|
+
scaleRatio: 1,
|
|
8266
|
+
brightness: 0,
|
|
8267
|
+
contrast: 0,
|
|
8268
|
+
saturation: 0,
|
|
8269
|
+
vignette: 0,
|
|
8270
|
+
imageFilter: "ImageFilter_None"
|
|
8271
|
+
};
|
|
8272
|
+
function mediaList(file, name, ptr, edited) {
|
|
8273
|
+
const size = String(file.size);
|
|
8274
|
+
return {
|
|
8275
|
+
$type: "proto.sdui.media.MediaList",
|
|
8276
|
+
mediaFiles: [
|
|
8277
|
+
{
|
|
8278
|
+
mediaAttributions: [],
|
|
8279
|
+
analysisData: {},
|
|
8280
|
+
fileName: name,
|
|
8281
|
+
source: {
|
|
8282
|
+
$case: "localFile",
|
|
8283
|
+
localFile: {
|
|
8284
|
+
fileName: name,
|
|
8285
|
+
mimeType: file.mimeType,
|
|
8286
|
+
filePointer: ptr,
|
|
8287
|
+
size,
|
|
8288
|
+
shouldIncludeFileContents: false
|
|
8289
|
+
}
|
|
8290
|
+
},
|
|
8291
|
+
size,
|
|
8292
|
+
mimeType: file.mimeType,
|
|
8293
|
+
filePointer: ptr,
|
|
8294
|
+
mediaFileId: ptr,
|
|
8295
|
+
...edited ? { editData: WHOLE_IMAGE } : {},
|
|
8296
|
+
captions: [],
|
|
8297
|
+
thumbnails: []
|
|
8298
|
+
}
|
|
8299
|
+
]
|
|
8300
|
+
};
|
|
8301
|
+
}
|
|
8302
|
+
var CASES = {
|
|
8303
|
+
object: "mediaListValue",
|
|
8304
|
+
array: "stringListValue",
|
|
8305
|
+
string: "stringValue",
|
|
8306
|
+
boolean: "booleanValue"
|
|
8307
|
+
};
|
|
8308
|
+
function state(key, value) {
|
|
8309
|
+
const kind = Array.isArray(value) ? "array" : typeof value;
|
|
8310
|
+
return {
|
|
8311
|
+
key,
|
|
8312
|
+
namespace: NS,
|
|
8313
|
+
value,
|
|
8314
|
+
originalProtoCase: CASES[kind],
|
|
8315
|
+
protoKey: { $type: "proto.sdui.Key", value: { $case: "id", id: key } }
|
|
8316
|
+
};
|
|
8317
|
+
}
|
|
8318
|
+
function serverRequest(requestId, payload, states2, screenId) {
|
|
8319
|
+
const requestedStateKeys = states2.map((s) => stateKey2(s.key));
|
|
8320
|
+
const requestedArguments = {
|
|
8321
|
+
$type: "proto.sdui.actions.requests.RequestedArguments",
|
|
8322
|
+
requestedStateKeys,
|
|
8323
|
+
payload,
|
|
8324
|
+
requestMetadata: META
|
|
8325
|
+
};
|
|
8326
|
+
return {
|
|
8327
|
+
requestId,
|
|
8328
|
+
serverRequest: {
|
|
8329
|
+
requestId,
|
|
8330
|
+
requestedArguments,
|
|
8331
|
+
isApfcEnabled: false,
|
|
8332
|
+
isStreaming: false,
|
|
8333
|
+
rumPageKey: ""
|
|
8334
|
+
},
|
|
8335
|
+
states: states2,
|
|
8336
|
+
requestedArguments: { ...requestedArguments, states: states2, screenId, knownTemplateIds: [] }
|
|
8337
|
+
};
|
|
8338
|
+
}
|
|
8339
|
+
var displayNameOf = (req) => req.displayName ?? `edited-image-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.${req.file.name.split(".").pop()}`;
|
|
8340
|
+
function savePlan(kind, req) {
|
|
8341
|
+
const k = req.keys;
|
|
8342
|
+
const focus = focusKey(req.vanity);
|
|
8343
|
+
if (kind.name === "photo") {
|
|
8344
|
+
return {
|
|
8345
|
+
payload: {
|
|
8346
|
+
profileId: req.profileId,
|
|
8347
|
+
vanityName: req.vanity,
|
|
8348
|
+
newMedia: bind(k.displayMedia),
|
|
8349
|
+
originalAssetUrns: bind(k.originalAssetUrns),
|
|
8350
|
+
displayAssetUrns: bind(k.displayAssetUrns),
|
|
8351
|
+
isSavingProfilePhoto: bind(k.saving),
|
|
8352
|
+
focusableComponentRefKey: bind(focus)
|
|
8353
|
+
},
|
|
8354
|
+
keys: [k.displayMedia, k.originalAssetUrns, k.displayAssetUrns, k.saving, focus],
|
|
8355
|
+
focusValue: "topcard-logo-image-referencekey"
|
|
8356
|
+
};
|
|
8357
|
+
}
|
|
8358
|
+
return {
|
|
8359
|
+
payload: {
|
|
8360
|
+
vanityName: req.vanity,
|
|
8361
|
+
profileId: req.profileId,
|
|
8362
|
+
editedMedia: bind(k.displayMedia),
|
|
8363
|
+
displayAssetUrns: bind(k.displayAssetUrns),
|
|
8364
|
+
originalAssetUrns: bind(k.originalAssetUrns),
|
|
8365
|
+
focusableComponentRefKey: bind(focus),
|
|
8366
|
+
isSaving: bind(k.saving),
|
|
8367
|
+
omitDefaultPhotoFilterEditInfo: true
|
|
8368
|
+
},
|
|
8369
|
+
keys: [k.displayMedia, k.displayAssetUrns, k.originalAssetUrns, focus],
|
|
8370
|
+
focusValue: `${req.vanity}_cover_edit_button`
|
|
8371
|
+
};
|
|
8372
|
+
}
|
|
8373
|
+
function registerBody(kind, req) {
|
|
8374
|
+
const k = req.keys;
|
|
8375
|
+
const save = savePlan(kind, req);
|
|
8376
|
+
const payload = {
|
|
8377
|
+
profileId: req.profileId,
|
|
8378
|
+
originalMedia: bind(k.originalMedia),
|
|
8379
|
+
originalAssetUrns: bind(k.originalAssetUrns),
|
|
8380
|
+
originalMediaType: kind.originalType,
|
|
8381
|
+
displayMedia: bind(k.displayMedia),
|
|
8382
|
+
displayMediaType: kind.displayType,
|
|
8383
|
+
displayAssetUrns: bind(k.displayAssetUrns),
|
|
8384
|
+
uploadOriginal: true,
|
|
8385
|
+
followUpRequest: { key: kind.save, data: save.payload, stateKeys: save.keys.map(bind) },
|
|
8386
|
+
skipEdit: false,
|
|
8387
|
+
isSaving: bind(k.saving)
|
|
8388
|
+
};
|
|
8389
|
+
return serverRequest(
|
|
8390
|
+
REGISTER,
|
|
8391
|
+
payload,
|
|
8392
|
+
[
|
|
8393
|
+
state(k.originalMedia, mediaList(req.file, req.file.name, k.originalPointer, false)),
|
|
8394
|
+
state(k.originalAssetUrns, []),
|
|
8395
|
+
state(k.displayMedia, mediaList(req.file, displayNameOf(req), k.displayPointer, true)),
|
|
8396
|
+
state(k.displayAssetUrns, []),
|
|
8397
|
+
state(k.saving, true)
|
|
8398
|
+
],
|
|
8399
|
+
kind.screen
|
|
8400
|
+
);
|
|
8401
|
+
}
|
|
8402
|
+
function saveBody2(kind, req) {
|
|
8403
|
+
const k = req.keys;
|
|
8404
|
+
const save = savePlan(kind, req);
|
|
8405
|
+
const values = {
|
|
8406
|
+
[k.displayMedia]: mediaList(req.file, displayNameOf(req), k.displayPointer, true),
|
|
8407
|
+
[k.originalAssetUrns]: [req.originalId],
|
|
8408
|
+
[k.displayAssetUrns]: [req.displayId],
|
|
8409
|
+
[k.saving]: true,
|
|
8410
|
+
[focusKey(req.vanity)]: save.focusValue
|
|
8411
|
+
};
|
|
8412
|
+
return serverRequest(
|
|
8413
|
+
kind.save,
|
|
8414
|
+
save.payload,
|
|
8415
|
+
save.keys.map((key) => state(key, values[key])),
|
|
8416
|
+
kind.screen
|
|
8417
|
+
);
|
|
8418
|
+
}
|
|
8419
|
+
function* walk(v) {
|
|
8420
|
+
if (Array.isArray(v)) for (const x of v) yield* walk(x);
|
|
8421
|
+
else if (v !== null && typeof v === "object") {
|
|
8422
|
+
yield v;
|
|
8423
|
+
for (const x of Object.values(v)) yield* walk(x);
|
|
8424
|
+
}
|
|
8425
|
+
}
|
|
8426
|
+
var headerName = (key) => key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
8427
|
+
function assetIdOf(n) {
|
|
8428
|
+
if (n.$type !== "proto.sdui.actions.core.SetState") return void 0;
|
|
8429
|
+
const s = n.value?.state;
|
|
8430
|
+
const id = s?.key?.key?.value;
|
|
8431
|
+
const list2 = s?.value?.stringListValue?.stringValues;
|
|
8432
|
+
return typeof id?.id === "string" && typeof list2?.[0] === "string" ? [id.id, list2[0]] : void 0;
|
|
8433
|
+
}
|
|
8434
|
+
function uploadOf(n) {
|
|
8435
|
+
if (typeof n.fileReference !== "string") return void 0;
|
|
8436
|
+
const instruction = n.uploadInstruction?.instruction;
|
|
8437
|
+
const single = instruction?.singleRequestUploadInstruction;
|
|
8438
|
+
if (typeof single?.uploadUrl !== "string") return [n.fileReference, "multipart"];
|
|
8439
|
+
const headers2 = {};
|
|
8440
|
+
for (const h of single.uploadHeaders ?? [])
|
|
8441
|
+
if (typeof h.key === "string" && typeof h.value === "string")
|
|
8442
|
+
headers2[headerName(h.key)] = h.value;
|
|
8443
|
+
return [n.fileReference, { url: single.uploadUrl, headers: headers2 }];
|
|
8444
|
+
}
|
|
8445
|
+
function rowZero(raw) {
|
|
8446
|
+
const row = raw.match(/(?:^|\n)0:(\{.*)/)?.[1];
|
|
8447
|
+
try {
|
|
8448
|
+
return row === void 0 ? void 0 : JSON.parse(row);
|
|
8449
|
+
} catch {
|
|
8450
|
+
return void 0;
|
|
8451
|
+
}
|
|
8452
|
+
}
|
|
8453
|
+
function parseRegister(raw, keys) {
|
|
8454
|
+
const refused = responseErrors(raw);
|
|
8455
|
+
if (refused !== null)
|
|
8456
|
+
return { ok: false, code: "INVALID_INPUT", message: `LinkedIn refused the image: ${refused}` };
|
|
8457
|
+
const ids = /* @__PURE__ */ new Map();
|
|
8458
|
+
const uploads = /* @__PURE__ */ new Map();
|
|
8459
|
+
for (const n of walk(rowZero(raw))) {
|
|
8460
|
+
const id = assetIdOf(n);
|
|
8461
|
+
if (id !== void 0) ids.set(...id);
|
|
8462
|
+
const up = uploadOf(n);
|
|
8463
|
+
if (up !== void 0) uploads.set(...up);
|
|
8464
|
+
}
|
|
8465
|
+
const originalId = ids.get(keys.originalAssetUrns);
|
|
8466
|
+
const displayId = ids.get(keys.displayAssetUrns);
|
|
8467
|
+
const original = uploads.get(keys.originalPointer);
|
|
8468
|
+
const display = uploads.get(keys.displayPointer);
|
|
8469
|
+
if (original === "multipart" || display === "multipart")
|
|
8470
|
+
return {
|
|
8471
|
+
ok: false,
|
|
8472
|
+
code: "NOT_IMPLEMENTED",
|
|
8473
|
+
message: "LinkedIn asked for a multi-part upload, which has not been observed here. Nothing was uploaded. Try a smaller file."
|
|
8474
|
+
};
|
|
8475
|
+
if (originalId === void 0 || displayId === void 0 || !original || !display)
|
|
8476
|
+
return {
|
|
8477
|
+
ok: false,
|
|
8478
|
+
code: "SCHEMA_DRIFT",
|
|
8479
|
+
message: "the image registration carried no asset ids or upload urls; nothing was uploaded"
|
|
8480
|
+
};
|
|
8481
|
+
return { ok: true, originalId, displayId, uploads: { original, display } };
|
|
8482
|
+
}
|
|
8483
|
+
function imageSizeOf(bytes) {
|
|
8484
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
8485
|
+
const png = [137, 80, 78, 71, 13, 10, 26, 10];
|
|
8486
|
+
if (bytes.length >= 24 && png.every((b, i) => bytes[i] === b))
|
|
8487
|
+
return { width: view.getUint32(16), height: view.getUint32(20), mimeType: "image/png" };
|
|
8488
|
+
if (bytes[0] !== 255 || bytes[1] !== 216) return null;
|
|
8489
|
+
let at = 2;
|
|
8490
|
+
while (at + 9 <= bytes.length) {
|
|
8491
|
+
if (bytes[at] !== 255) return null;
|
|
8492
|
+
const marker = bytes[at + 1];
|
|
8493
|
+
if (marker >= 192 && marker <= 207 && ![196, 200, 204].includes(marker))
|
|
8494
|
+
return {
|
|
8495
|
+
height: view.getUint16(at + 5),
|
|
8496
|
+
width: view.getUint16(at + 7),
|
|
8497
|
+
mimeType: "image/jpeg"
|
|
8498
|
+
};
|
|
8499
|
+
at += 2 + view.getUint16(at + 2);
|
|
8500
|
+
}
|
|
8501
|
+
return null;
|
|
8502
|
+
}
|
|
8503
|
+
function picturesOf(json) {
|
|
8504
|
+
const root = json;
|
|
8505
|
+
const urn = root?.data?.["*elements"]?.[0];
|
|
8506
|
+
const p = (root?.included ?? []).find((n) => n.entityUrn === urn);
|
|
8507
|
+
const profileId2 = typeof urn === "string" ? urn.split(":").pop() : void 0;
|
|
8508
|
+
if (p === void 0 || profileId2 === void 0)
|
|
8509
|
+
return { ok: false, code: "SCHEMA_DRIFT", message: "the profile answer carried no profile" };
|
|
8510
|
+
const asset = (pic) => String(pic?.displayImageUrn ?? "").match(/digitalmediaAsset:(.+)$/)?.[1];
|
|
8511
|
+
const photo = asset(p.profilePicture);
|
|
8512
|
+
const banner = asset(p.backgroundPicture);
|
|
8513
|
+
return {
|
|
8514
|
+
ok: true,
|
|
8515
|
+
profileId: profileId2,
|
|
8516
|
+
...photo !== void 0 ? { photo } : {},
|
|
8517
|
+
...banner !== void 0 ? { banner } : {}
|
|
8518
|
+
};
|
|
8519
|
+
}
|
|
8520
|
+
|
|
8521
|
+
// src/commands/profile-image.ts
|
|
8522
|
+
function liveImages(session) {
|
|
8523
|
+
const client = createLiveClient(session);
|
|
8524
|
+
return {
|
|
8525
|
+
vanity: async () => {
|
|
8526
|
+
const me = await createEngine(session).whoami();
|
|
8527
|
+
if (!me.ok) return me;
|
|
8528
|
+
const id = me.value?.publicIdentifier;
|
|
8529
|
+
return typeof id === "string" && id !== "" ? { ok: true, vanity: id } : { ok: false, code: "SCHEMA_DRIFT", message: "whoami returned no public profile id" };
|
|
8530
|
+
},
|
|
8531
|
+
pictures: async (vanity) => {
|
|
8532
|
+
const r = await client.request({
|
|
8533
|
+
url: fullProfileUrl(vanity),
|
|
8534
|
+
spendClass: "profile",
|
|
8535
|
+
operation: "profile-pictures"
|
|
8536
|
+
});
|
|
8537
|
+
return r.ok ? picturesOf(r.json) : r;
|
|
8538
|
+
},
|
|
8539
|
+
register: async (body) => {
|
|
8540
|
+
const raw = await sendAction(REGISTER_REQUEST, body, client, "image-register");
|
|
8541
|
+
return typeof raw === "string" ? { ok: true, raw } : raw;
|
|
8542
|
+
},
|
|
8543
|
+
put: async (upload, bytes, mimeType) => {
|
|
8544
|
+
const r = await client.request({
|
|
8545
|
+
url: upload.url,
|
|
8546
|
+
method: "PUT",
|
|
8547
|
+
bytes,
|
|
8548
|
+
headers: { "content-type": mimeType, ...upload.headers },
|
|
8549
|
+
spendClass: "write",
|
|
8550
|
+
operation: "image-upload"
|
|
8551
|
+
});
|
|
8552
|
+
return r.ok ? { ok: true } : r;
|
|
8553
|
+
},
|
|
8554
|
+
save: async (kind, body) => {
|
|
8555
|
+
const raw = await sendAction(kind.save, body, client, `${kind.name}-save`);
|
|
8556
|
+
return typeof raw === "string" ? { ok: true } : raw;
|
|
8557
|
+
}
|
|
8558
|
+
};
|
|
8559
|
+
}
|
|
8560
|
+
var MAX_BYTES = 8 * 1024 * 1024;
|
|
8561
|
+
function pick(kind, path) {
|
|
8562
|
+
let bytes;
|
|
8563
|
+
try {
|
|
8564
|
+
if (!statSync(path).isFile()) throw new Error("not a file");
|
|
8565
|
+
bytes = new Uint8Array(readFileSync3(path));
|
|
8566
|
+
} catch {
|
|
8567
|
+
return err("edit", "INVALID_INPUT", `cannot read ${path}`);
|
|
8568
|
+
}
|
|
8569
|
+
if (bytes.byteLength > MAX_BYTES)
|
|
8570
|
+
return err("edit", "INVALID_INPUT", `${basename(path)} is over LinkedIn's 8 MB limit`);
|
|
8571
|
+
const size = imageSizeOf(bytes);
|
|
8572
|
+
if (size === null)
|
|
8573
|
+
return err("edit", "INVALID_INPUT", `${basename(path)} is not a PNG or JPEG image`);
|
|
8574
|
+
const ratio = size.width / size.height;
|
|
8575
|
+
if (Math.abs(ratio / kind.aspect - 1) > 0.02) {
|
|
8576
|
+
const want = kind.name === "photo" ? "square" : "4:1 (1584 \xD7 396)";
|
|
8577
|
+
return err(
|
|
8578
|
+
"edit",
|
|
8579
|
+
"INVALID_INPUT",
|
|
8580
|
+
`${basename(path)} is ${size.width} \xD7 ${size.height}; a ${kind.label} must be ${want}`,
|
|
8581
|
+
"It is uploaded as it is, uncropped: crop it to that shape first."
|
|
8582
|
+
);
|
|
8583
|
+
}
|
|
8584
|
+
return { bytes, ...size };
|
|
8585
|
+
}
|
|
8586
|
+
function planOf(kind, file, picked, was, author) {
|
|
8587
|
+
const sha256 = mediaDigest(picked.bytes);
|
|
8588
|
+
return {
|
|
8589
|
+
action: `replace your ${kind.label}`,
|
|
8590
|
+
payload: { image: kind.name, file, sha256, was: was ?? null },
|
|
8591
|
+
summary: [
|
|
8592
|
+
author,
|
|
8593
|
+
`image ${kind.label}`,
|
|
8594
|
+
`file ${file}`,
|
|
8595
|
+
` ${picked.width} \xD7 ${picked.height}, ${picked.bytes.byteLength} bytes, sha256 ${sha256.slice(0, 16)}\u2026`,
|
|
8596
|
+
`now ${was === void 0 ? "none" : `asset ${was}`}`
|
|
8597
|
+
],
|
|
8598
|
+
reversibility: "replaceable again with any file, but the current image is not kept here: have the original file before replacing it. Everyone who can see your profile sees the change.",
|
|
8599
|
+
transport: "voyager"
|
|
8600
|
+
};
|
|
8601
|
+
}
|
|
8602
|
+
async function send2(li, kind, req, picked) {
|
|
8603
|
+
const nothing = (f, step) => err("edit", f.code, `${step} failed (${f.message}); nothing changed on your profile`, f.hint);
|
|
8604
|
+
const registered = await li.register(registerBody(kind, req));
|
|
8605
|
+
if (!registered.ok) return nothing(registered, "registering the image");
|
|
8606
|
+
const ticket = parseRegister(registered.raw, req.keys);
|
|
8607
|
+
if (!ticket.ok) return nothing(ticket, "registering the image");
|
|
8608
|
+
for (const upload of [ticket.uploads.original, ticket.uploads.display]) {
|
|
8609
|
+
const put2 = await li.put(upload, picked.bytes, picked.mimeType);
|
|
8610
|
+
if (!put2.ok) return nothing(put2, "uploading the image");
|
|
8611
|
+
}
|
|
8612
|
+
const saved = await li.save(kind, saveBody2(kind, { ...req, ...ticket }));
|
|
8613
|
+
if (!saved.ok)
|
|
8614
|
+
return err("edit", saved.code, `saving the ${kind.label} failed: ${saved.message}`);
|
|
8615
|
+
return { ok: true, displayId: ticket.displayId };
|
|
8616
|
+
}
|
|
8617
|
+
async function runEditImage(name, path, now = Date.now(), deps = terminalDeps(), surface, keys) {
|
|
8618
|
+
const kind = IMAGE_KINDS[name];
|
|
8619
|
+
if (kind === void 0)
|
|
8620
|
+
return err("edit", "INVALID_INPUT", `'${name}' is not an image this edits`, "photo, banner");
|
|
8621
|
+
if (path === void 0 || path.trim() === "")
|
|
8622
|
+
return err("edit", "INVALID_INPUT", "an image file is required", `lnrelay edit ${name} <file>`);
|
|
8623
|
+
const file = resolve(path);
|
|
8624
|
+
const picked = pick(kind, file);
|
|
8625
|
+
if ("ok" in picked) return picked;
|
|
8626
|
+
const unapprovable = refuseUnapprovable("edit", "editing", deps);
|
|
8627
|
+
if (unapprovable !== null) return unapprovable;
|
|
8628
|
+
const ctx = prepare("edit", now, "voyager", 4);
|
|
8629
|
+
if ("ok" in ctx) return ctx;
|
|
8630
|
+
if (ctx.transport.kind !== "voyager")
|
|
8631
|
+
return err("edit", "NOT_IMPLEMENTED", "profile edits go over the browser session only");
|
|
8632
|
+
const li = surface ?? liveImages(ctx.transport.session);
|
|
8633
|
+
const me = await li.vanity();
|
|
8634
|
+
if (!me.ok) return err("edit", me.code, me.message, me.hint);
|
|
8635
|
+
const before = await li.pictures(me.vanity);
|
|
8636
|
+
if (!before.ok) return err("edit", before.code, before.message, before.hint);
|
|
8637
|
+
const plan = planOf(kind, file, picked, before[kind.name], authorLine(ctx.transport));
|
|
8638
|
+
const gated = await gate("edit", plan, ctx, deps);
|
|
8639
|
+
if ("ok" in gated) return gated;
|
|
8640
|
+
const ext = picked.mimeType === "image/png" ? "png" : "jpg";
|
|
8641
|
+
const sent = await send2(
|
|
8642
|
+
li,
|
|
8643
|
+
kind,
|
|
8644
|
+
{
|
|
8645
|
+
profileId: before.profileId,
|
|
8646
|
+
vanity: me.vanity,
|
|
8647
|
+
file: { name: basename(file), mimeType: picked.mimeType, size: picked.bytes.byteLength },
|
|
8648
|
+
keys: keys ?? newKeys(kind),
|
|
8649
|
+
displayName: `edited-image-${new Date(now).toISOString().replace(/[:.]/g, "-")}.${ext}`
|
|
8650
|
+
},
|
|
8651
|
+
picked
|
|
8652
|
+
);
|
|
8653
|
+
if (!("displayId" in sent)) return sent;
|
|
8654
|
+
const after = await li.pictures(me.vanity);
|
|
8655
|
+
if (!after.ok || after[kind.name] !== sent.displayId) {
|
|
8656
|
+
return err(
|
|
8657
|
+
"edit",
|
|
8658
|
+
"SCHEMA_DRIFT",
|
|
8659
|
+
`LinkedIn accepted the save, but your ${kind.label} does not read back as the new image`,
|
|
8660
|
+
after.ok ? `It shows asset ${after[kind.name] ?? "none"}; the upload was ${sent.displayId}.` : `The read-back failed: ${after.message}`
|
|
8661
|
+
);
|
|
8662
|
+
}
|
|
8663
|
+
return ok("edit", { image: kind.name, verified: true, asset: sent.displayId });
|
|
8664
|
+
}
|
|
8665
|
+
|
|
8200
8666
|
// src/commands/transport.ts
|
|
8201
8667
|
var NO_CREDENTIAL_HINT = [
|
|
8202
8668
|
"Two ways to write, and you need one of them:",
|
|
@@ -8361,7 +8827,7 @@ function loadMedia(flag, path) {
|
|
|
8361
8827
|
return err(
|
|
8362
8828
|
"share",
|
|
8363
8829
|
"INVALID_INPUT",
|
|
8364
|
-
`unsupported file type: ${
|
|
8830
|
+
`unsupported file type: ${basename2(path)}`,
|
|
8365
8831
|
"images: png, jpg, jpeg, gif, webp. videos: mp4, mov. documents: pdf."
|
|
8366
8832
|
);
|
|
8367
8833
|
}
|
|
@@ -8369,21 +8835,21 @@ function loadMedia(flag, path) {
|
|
|
8369
8835
|
return err(
|
|
8370
8836
|
"share",
|
|
8371
8837
|
"INVALID_INPUT",
|
|
8372
|
-
`${
|
|
8838
|
+
`${basename2(path)} is not ${flag === "image" ? "an image" : `a ${flag}`}`,
|
|
8373
8839
|
`pass it with ${KIND_FLAG[kind.kind]}`
|
|
8374
8840
|
);
|
|
8375
8841
|
}
|
|
8376
8842
|
let bytes;
|
|
8377
8843
|
try {
|
|
8378
|
-
if (!
|
|
8379
|
-
bytes = new Uint8Array(
|
|
8844
|
+
if (!statSync2(path).isFile()) throw new Error("not a file");
|
|
8845
|
+
bytes = new Uint8Array(readFileSync4(path));
|
|
8380
8846
|
} catch {
|
|
8381
8847
|
return err("share", "INVALID_INPUT", `cannot read ${path}`);
|
|
8382
8848
|
}
|
|
8383
8849
|
return {
|
|
8384
8850
|
bytes,
|
|
8385
8851
|
approved: {
|
|
8386
|
-
filename:
|
|
8852
|
+
filename: basename2(path),
|
|
8387
8853
|
kind: kind.kind,
|
|
8388
8854
|
contentType: kind.contentType,
|
|
8389
8855
|
size: bytes.byteLength,
|
|
@@ -8801,6 +9267,9 @@ async function runEdit(commentUrn, text6, now = Date.now(), deps = terminalDeps(
|
|
|
8801
9267
|
'lnrelay edit <comment-urn> "<text>"'
|
|
8802
9268
|
);
|
|
8803
9269
|
}
|
|
9270
|
+
if (commentUrn === "photo" || commentUrn === "banner") {
|
|
9271
|
+
return runEditImage(commentUrn, text6, now, deps);
|
|
9272
|
+
}
|
|
8804
9273
|
const ref = parseCommentUrn(commentUrn);
|
|
8805
9274
|
if (ref === null && !commentUrn.startsWith("urn:")) {
|
|
8806
9275
|
return runEditProfile(commentUrn, text6, now, deps);
|
|
@@ -9727,9 +10196,211 @@ async function runSync(source, limit, force, now = Date.now()) {
|
|
|
9727
10196
|
}
|
|
9728
10197
|
}
|
|
9729
10198
|
|
|
10199
|
+
// src/engine/profile-views.ts
|
|
10200
|
+
var SERVER_REQUEST = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
|
|
10201
|
+
var VIEWERS_URL = `${SERVER_REQUEST}?sduiid=WvmpEntityList`;
|
|
10202
|
+
var VIEW_TOTALS_URL = `${SERVER_REQUEST}?sduiid=WvmpAnalytics`;
|
|
10203
|
+
var RANGE = "WvmpSearchFilterType_DATE_RANGE";
|
|
10204
|
+
var META2 = { $type: "proto.sdui.common.RequestMetadata" };
|
|
10205
|
+
function serverRequest2(requestId, stateKey3, payload) {
|
|
10206
|
+
const state2 = {
|
|
10207
|
+
key: stateKey3,
|
|
10208
|
+
namespace: "MemoryNamespace",
|
|
10209
|
+
value: [],
|
|
10210
|
+
originalProtoCase: "stringListValue",
|
|
10211
|
+
protoKey: { $type: "proto.sdui.Key", value: { $case: "id", id: stateKey3 } }
|
|
10212
|
+
};
|
|
10213
|
+
const requestedArguments = {
|
|
10214
|
+
$type: "proto.sdui.actions.requests.RequestedArguments",
|
|
10215
|
+
requestedStateKeys: [{ key: { value: { $case: "id", id: stateKey3 } } }],
|
|
10216
|
+
payload: {
|
|
10217
|
+
...payload,
|
|
10218
|
+
filterTypeList: [RANGE],
|
|
10219
|
+
dateRangeSelectionFilters: { key: stateKey3, namespace: "MemoryNamespace" }
|
|
10220
|
+
},
|
|
10221
|
+
requestMetadata: META2
|
|
10222
|
+
};
|
|
10223
|
+
return {
|
|
10224
|
+
requestId,
|
|
10225
|
+
serverRequest: {
|
|
10226
|
+
requestId,
|
|
10227
|
+
requestedArguments,
|
|
10228
|
+
isApfcEnabled: false,
|
|
10229
|
+
isStreaming: false,
|
|
10230
|
+
rumPageKey: ""
|
|
10231
|
+
},
|
|
10232
|
+
states: [state2],
|
|
10233
|
+
requestedArguments: {
|
|
10234
|
+
...requestedArguments,
|
|
10235
|
+
states: [state2],
|
|
10236
|
+
screenId: "com.linkedin.sdui.flagshipnav.home.Home",
|
|
10237
|
+
knownTemplateIds: []
|
|
10238
|
+
}
|
|
10239
|
+
};
|
|
10240
|
+
}
|
|
10241
|
+
function viewersBody() {
|
|
10242
|
+
return serverRequest2("WvmpEntityList", `entityListQueryFilterPrefix${RANGE}`, {
|
|
10243
|
+
sortType: "ProfileViewSortType_TIME_DESCENDING"
|
|
10244
|
+
});
|
|
10245
|
+
}
|
|
10246
|
+
function viewTotalsBody() {
|
|
10247
|
+
return serverRequest2("WvmpAnalytics", `analyticsFieldsFilterPrefix${RANGE}`, {
|
|
10248
|
+
highlightCardDimensions: [
|
|
10249
|
+
"DimensionType_LOCATION",
|
|
10250
|
+
"DimensionType_INDUSTRY",
|
|
10251
|
+
"DimensionType_ORGANIZATION"
|
|
10252
|
+
],
|
|
10253
|
+
detailsCardDimensions: ["DimensionType_ORGANIZATION"],
|
|
10254
|
+
highlightCardResultCount: 4,
|
|
10255
|
+
detailsCardResultCount: 23
|
|
10256
|
+
});
|
|
10257
|
+
}
|
|
10258
|
+
var drift10 = (message) => ({ ok: false, code: "SCHEMA_DRIFT", message });
|
|
10259
|
+
var unquote3 = (s) => JSON.parse(`"${s}"`);
|
|
10260
|
+
var STR = '((?:[^"\\\\]|\\\\.)+)';
|
|
10261
|
+
var ITEM = /"viewName":"viewer-list-item"(?:,"impressionThresholds":\[[^\]]*\])?[^{}]*"semanticPosition"/;
|
|
10262
|
+
var TEXT_PROPS = /"textProps":\{"fontFamily":"[^"]*","fontSize":"(\w+)","fontStyle":"[^"]*","fontWeight":"(\w+)","lineHeight":"[^"]*","textAlign":"[^"]*","children":/g;
|
|
10263
|
+
var OWN_TEXT = new RegExp(`^\\["${STR}"\\]`);
|
|
10264
|
+
var NESTED_TEXT = new RegExp(`\\[null,"${STR}"`);
|
|
10265
|
+
var LINK2 = new RegExp(`"urlValue":\\{"\\$case":"url","url":"${STR}"`);
|
|
10266
|
+
var PROFILE_ID2 = /ACoA[A-Za-z0-9_-]{10,}/;
|
|
10267
|
+
var PLAIN_TEXT = new RegExp(`"children":\\["${STR}"\\]`, "g");
|
|
10268
|
+
function textsOf(row) {
|
|
10269
|
+
return [...row.matchAll(TEXT_PROPS)].flatMap((m) => {
|
|
10270
|
+
const after = row.slice((m.index ?? 0) + m[0].length, (m.index ?? 0) + m[0].length + 600);
|
|
10271
|
+
const raw = after.match(OWN_TEXT)?.[1] ?? after.match(NESTED_TEXT)?.[1];
|
|
10272
|
+
if (raw === void 0) return [];
|
|
10273
|
+
const text6 = unquote3(raw).trim();
|
|
10274
|
+
return text6 === "" ? [] : [{ size: m[1], weight: m[2], text: text6 }];
|
|
10275
|
+
});
|
|
10276
|
+
}
|
|
10277
|
+
function viewerOf(row, id) {
|
|
10278
|
+
const texts3 = textsOf(row);
|
|
10279
|
+
const at = texts3.findIndex((t) => t.size === "medium" && t.weight === "bold");
|
|
10280
|
+
const first = texts3[at]?.text;
|
|
10281
|
+
if (first === void 0) return void 0;
|
|
10282
|
+
const rest = texts3.slice(at + 1).map((t) => t.text);
|
|
10283
|
+
const degreeText = rest.find((t) => t.startsWith("\u2022"));
|
|
10284
|
+
const lines = rest.filter((t) => t !== degreeText);
|
|
10285
|
+
const viewed = lines.at(-1);
|
|
10286
|
+
const link = row.match(LINK2)?.[1];
|
|
10287
|
+
const url = link === void 0 ? void 0 : unquote3(link);
|
|
10288
|
+
if (url === void 0 || !/linkedin\.com\/in\//.test(url)) {
|
|
10289
|
+
const v = { anonymous: true, description: first };
|
|
10290
|
+
if (viewed !== void 0) v.viewed = viewed;
|
|
10291
|
+
if (url !== void 0) v.searchUrl = url;
|
|
10292
|
+
return v;
|
|
10293
|
+
}
|
|
10294
|
+
const degree = degreeText?.replace(/^•\s*/, "");
|
|
10295
|
+
const headline = lines.length > 1 ? lines[0] : void 0;
|
|
10296
|
+
return {
|
|
10297
|
+
name: first,
|
|
10298
|
+
...id !== void 0 ? { id } : {},
|
|
10299
|
+
url,
|
|
10300
|
+
...degree !== void 0 ? { degree } : {},
|
|
10301
|
+
...headline !== void 0 ? { headline } : {},
|
|
10302
|
+
...viewed !== void 0 ? { viewed } : {}
|
|
10303
|
+
};
|
|
10304
|
+
}
|
|
10305
|
+
var REF = /"\$[LQ]?([0-9a-f]+)"/g;
|
|
10306
|
+
function idUnder(rows, ref, items) {
|
|
10307
|
+
const seen = /* @__PURE__ */ new Set([ref]);
|
|
10308
|
+
const queue = [ref];
|
|
10309
|
+
while (queue.length > 0 && seen.size < 200) {
|
|
10310
|
+
const row = rows.byId.get(queue.shift()) ?? "";
|
|
10311
|
+
const id = row.match(PROFILE_ID2)?.[0];
|
|
10312
|
+
if (id !== void 0) return id;
|
|
10313
|
+
for (const m of row.matchAll(REF)) {
|
|
10314
|
+
const next = m[1];
|
|
10315
|
+
if (!seen.has(next) && !items.has(next) && rows.byId.has(next)) {
|
|
10316
|
+
seen.add(next);
|
|
10317
|
+
queue.push(next);
|
|
10318
|
+
}
|
|
10319
|
+
}
|
|
10320
|
+
}
|
|
10321
|
+
return void 0;
|
|
10322
|
+
}
|
|
10323
|
+
function idsByViewer(rows, items) {
|
|
10324
|
+
const ids = /* @__PURE__ */ new Map();
|
|
10325
|
+
for (const row of rows.byId.values()) {
|
|
10326
|
+
let current;
|
|
10327
|
+
for (const m of row.matchAll(REF)) {
|
|
10328
|
+
const ref = m[1];
|
|
10329
|
+
if (items.has(ref)) current = ref;
|
|
10330
|
+
else if (current !== void 0 && !ids.has(current)) {
|
|
10331
|
+
const id = idUnder(rows, ref, items);
|
|
10332
|
+
if (id !== void 0) ids.set(current, id);
|
|
10333
|
+
}
|
|
10334
|
+
}
|
|
10335
|
+
}
|
|
10336
|
+
return ids;
|
|
10337
|
+
}
|
|
10338
|
+
function parseViewers(stream) {
|
|
10339
|
+
if (!stream.includes('"viewName":"viewer-list"'))
|
|
10340
|
+
return drift10("the profile viewers answer was not the viewer list");
|
|
10341
|
+
const rows = new Rows(stream);
|
|
10342
|
+
const items = new Set([...rows.byId].filter(([, row]) => ITEM.test(row)).map(([id]) => id));
|
|
10343
|
+
const ids = idsByViewer(rows, items);
|
|
10344
|
+
const viewers = [...items].flatMap((id) => viewerOf(rows.byId.get(id) ?? "", ids.get(id)) ?? []);
|
|
10345
|
+
const shown = Math.max(items.size, (stream.match(new RegExp(ITEM, "g")) ?? []).length);
|
|
10346
|
+
if (shown > 0 && viewers.length === 0)
|
|
10347
|
+
return drift10(`${shown} profile viewers were shown but none could be read`);
|
|
10348
|
+
let privateViewers;
|
|
10349
|
+
for (const [id, row] of rows.byId) {
|
|
10350
|
+
if (items.has(id) || privateViewers !== void 0) continue;
|
|
10351
|
+
for (const m of row.matchAll(PLAIN_TEXT)) {
|
|
10352
|
+
const n = unquote3(m[1]).match(/^(\d[\d.,\s]*)\s+\D/)?.[1];
|
|
10353
|
+
if (n !== void 0) {
|
|
10354
|
+
privateViewers = Number(n.replace(/\D/g, ""));
|
|
10355
|
+
break;
|
|
10356
|
+
}
|
|
10357
|
+
}
|
|
10358
|
+
}
|
|
10359
|
+
return privateViewers === void 0 ? { ok: true, viewers } : { ok: true, viewers, privateViewers };
|
|
10360
|
+
}
|
|
10361
|
+
function parseViewTotals(stream) {
|
|
10362
|
+
const texts3 = [...stream.matchAll(PLAIN_TEXT)].map((m) => unquote3(m[1]).trim());
|
|
10363
|
+
const at = texts3.findIndex((t) => /^\d[\d.,\s]*$/.test(t));
|
|
10364
|
+
if (at === -1) return drift10("the profile view totals carried no number");
|
|
10365
|
+
const total = Number(texts3[at].replace(/\D/g, ""));
|
|
10366
|
+
const period = texts3[at + 1];
|
|
10367
|
+
return period === void 0 ? { ok: true, total } : { ok: true, total, period };
|
|
10368
|
+
}
|
|
10369
|
+
|
|
10370
|
+
// src/commands/viewers.ts
|
|
10371
|
+
function liveFetch9(quiet) {
|
|
10372
|
+
const session = loadSession();
|
|
10373
|
+
if (session.state !== "ok")
|
|
10374
|
+
return err("viewers", "AUTH_FAILED", "no LinkedIn session \u2014 run `lnrelay login`");
|
|
10375
|
+
const client = createLiveClient(session.session, void 0, quiet);
|
|
10376
|
+
return async (url, body, spendClass) => {
|
|
10377
|
+
const r = await client.request({ url, method: "POST", body, spendClass, operation: "viewers" });
|
|
10378
|
+
if (!r.ok) return r;
|
|
10379
|
+
return { ok: true, raw: r.classification.raw ?? "" };
|
|
10380
|
+
};
|
|
10381
|
+
}
|
|
10382
|
+
var compactViewer = (v) => "anonymous" in v ? line(["anonymous", v.description, v.viewed]) : line([v.name, v.degree, v.headline, v.viewed, v.url]);
|
|
10383
|
+
async function runViewers(opts = {}, fetch2) {
|
|
10384
|
+
const get = fetch2 ?? liveFetch9(opts.quiet === true);
|
|
10385
|
+
if (typeof get !== "function") return get;
|
|
10386
|
+
const totalsRes = await get(VIEW_TOTALS_URL, viewTotalsBody(), "page");
|
|
10387
|
+
const totals = totalsRes.ok ? parseViewTotals(totalsRes.raw) : totalsRes;
|
|
10388
|
+
const listRes = await get(VIEWERS_URL, viewersBody(), "page");
|
|
10389
|
+
const list2 = listRes.ok ? parseViewers(listRes.raw) : listRes;
|
|
10390
|
+
if (!list2.ok) return err("viewers", list2.code, list2.message, list2.hint);
|
|
10391
|
+
const shown = list2.viewers.length;
|
|
10392
|
+
const state2 = !totals.ok ? "unknown" : totals.total > shown ? "partial" : "complete";
|
|
10393
|
+
return ok("viewers", {
|
|
10394
|
+
...totals.ok ? { total: totals.total, ...totals.period !== void 0 ? { period: totals.period } : {} } : { totalError: `${totals.code}: ${totals.message}` },
|
|
10395
|
+
...list2.privateViewers !== void 0 ? { privateViewers: list2.privateViewers } : {},
|
|
10396
|
+
items: shape(list2.viewers, opts, compactViewer),
|
|
10397
|
+
meta: { state: state2, operation: "viewers", returnedCount: shown }
|
|
10398
|
+
});
|
|
10399
|
+
}
|
|
10400
|
+
|
|
9730
10401
|
// src/entry.ts
|
|
9731
10402
|
import { realpathSync } from "fs";
|
|
9732
|
-
import { basename as
|
|
10403
|
+
import { basename as basename3 } from "path";
|
|
9733
10404
|
import { fileURLToPath } from "url";
|
|
9734
10405
|
function isMainModule(argv1, moduleUrl, importMetaMain) {
|
|
9735
10406
|
if (importMetaMain === true) return true;
|
|
@@ -9744,7 +10415,7 @@ function isMainModule(argv1, moduleUrl, importMetaMain) {
|
|
|
9744
10415
|
}
|
|
9745
10416
|
function shouldForceEntry(argv1, binNames) {
|
|
9746
10417
|
if (argv1 === void 0) return false;
|
|
9747
|
-
return binNames.includes(
|
|
10418
|
+
return binNames.includes(basename3(argv1));
|
|
9748
10419
|
}
|
|
9749
10420
|
function shouldRunAsEntry(argv1, moduleUrl, importMetaMain, binNames) {
|
|
9750
10421
|
if (isMainModule(argv1, moduleUrl, importMetaMain)) {
|
|
@@ -10120,6 +10791,8 @@ async function dispatch(argv, now) {
|
|
|
10120
10791
|
return runPeople(peopleRequest(args), output(args));
|
|
10121
10792
|
case "people-filters":
|
|
10122
10793
|
return runPeopleFilters(peopleRequest(args), output(args));
|
|
10794
|
+
case "viewers":
|
|
10795
|
+
return runViewers(output(args));
|
|
10123
10796
|
case "events":
|
|
10124
10797
|
case "event":
|
|
10125
10798
|
case "company":
|
|
@@ -10181,13 +10854,14 @@ function edit(args, now, deps) {
|
|
|
10181
10854
|
const [target2, inline] = args.positionals;
|
|
10182
10855
|
if (args.flags.file === true) return err("edit", "INVALID_INPUT", "--file needs a path");
|
|
10183
10856
|
const file = str(args, "file");
|
|
10857
|
+
if (target2 === "photo" || target2 === "banner") return runEdit(target2, file ?? inline, now, deps);
|
|
10184
10858
|
if (file === void 0) return runEdit(target2, inline, now, deps);
|
|
10185
10859
|
if (inline !== void 0) {
|
|
10186
10860
|
return err("edit", "INVALID_INPUT", "pass the new text inline or with --file, not both");
|
|
10187
10861
|
}
|
|
10188
10862
|
let text6;
|
|
10189
10863
|
try {
|
|
10190
|
-
text6 =
|
|
10864
|
+
text6 = readFileSync5(file, "utf-8").replace(/\n$/, "");
|
|
10191
10865
|
} catch {
|
|
10192
10866
|
return err("edit", "INVALID_INPUT", `cannot read ${file}`);
|
|
10193
10867
|
}
|
|
@@ -10218,7 +10892,7 @@ function role2(args, now, deps) {
|
|
|
10218
10892
|
return err("role", "INVALID_INPUT", "pass --description or --description-file, not both");
|
|
10219
10893
|
}
|
|
10220
10894
|
try {
|
|
10221
|
-
req.description =
|
|
10895
|
+
req.description = readFileSync5(file, "utf-8").replace(/\n$/, "");
|
|
10222
10896
|
} catch {
|
|
10223
10897
|
return err("role", "INVALID_INPUT", `cannot read ${file}`);
|
|
10224
10898
|
}
|