linkedin-relay-mcp 3.7.0 → 3.9.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 +19 -0
- package/dist/cli.js +1388 -506
- package/dist/cli.js.map +1 -1
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp-shim.js +657 -2
- package/dist/mcp-shim.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3609,6 +3609,24 @@ var COMMANDS = [
|
|
|
3609
3609
|
risk: "read",
|
|
3610
3610
|
implemented: true
|
|
3611
3611
|
},
|
|
3612
|
+
{
|
|
3613
|
+
name: "experience",
|
|
3614
|
+
cost: "2 calls",
|
|
3615
|
+
summary: "The roles on your own profile, with the position id `role edit|remove` takes.",
|
|
3616
|
+
usage: "lnrelay experience",
|
|
3617
|
+
audience: ["cli", "mcp"],
|
|
3618
|
+
risk: "read",
|
|
3619
|
+
implemented: true
|
|
3620
|
+
},
|
|
3621
|
+
{
|
|
3622
|
+
name: "skills",
|
|
3623
|
+
cost: "3 calls",
|
|
3624
|
+
summary: "The skills on your own profile, with the skill id `skill remove` takes.",
|
|
3625
|
+
usage: "lnrelay skills",
|
|
3626
|
+
audience: ["cli", "mcp"],
|
|
3627
|
+
risk: "read",
|
|
3628
|
+
implemented: true
|
|
3629
|
+
},
|
|
3612
3630
|
{
|
|
3613
3631
|
name: "local",
|
|
3614
3632
|
cost: "free \u2014 local cache",
|
|
@@ -3700,6 +3718,24 @@ var COMMANDS = [
|
|
|
3700
3718
|
risk: "write",
|
|
3701
3719
|
implemented: true
|
|
3702
3720
|
},
|
|
3721
|
+
{
|
|
3722
|
+
name: "role",
|
|
3723
|
+
cost: "3-4 reads + 1 write",
|
|
3724
|
+
summary: "Add, edit or remove a role in your Experience. Never rewrites your headline; notify network is off unless --notify.",
|
|
3725
|
+
usage: 'lnrelay role add --title "<t>" --company "<c>" --start YYYY-MM [--end YYYY-MM | --current]\n [--location "<l>"] [--description "<d>" | --description-file <path>] [--notify]\n lnrelay role edit <position-id> [any of the flags above]\n lnrelay role remove <position-id>\n Position ids come from `lnrelay experience`. The preview shows the role as it is and\n as it will be; the result is read back from the profile. A role with media attached\n is refused. The company is free text (not linked to a company page).',
|
|
3726
|
+
audience: ["cli"],
|
|
3727
|
+
risk: "write",
|
|
3728
|
+
implemented: true
|
|
3729
|
+
},
|
|
3730
|
+
{
|
|
3731
|
+
name: "skill",
|
|
3732
|
+
cost: "4-5 reads + 1 write",
|
|
3733
|
+
summary: "Add a skill to your profile, or remove one.",
|
|
3734
|
+
usage: 'lnrelay skill add "<name>"\n lnrelay skill remove <skill-id>\n Skill ids come from `lnrelay skills`. A skill is added as free text, linked to no role,\n school or project. Removing a skill removes its endorsements with it.',
|
|
3735
|
+
audience: ["cli"],
|
|
3736
|
+
risk: "write",
|
|
3737
|
+
implemented: true
|
|
3738
|
+
},
|
|
3703
3739
|
{
|
|
3704
3740
|
name: "react",
|
|
3705
3741
|
cost: "1 call \u2014 write",
|
|
@@ -3726,344 +3762,179 @@ function helpText() {
|
|
|
3726
3762
|
return lines.join("\n");
|
|
3727
3763
|
}
|
|
3728
3764
|
|
|
3729
|
-
// src/
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3765
|
+
// src/engine/sdui-form.ts
|
|
3766
|
+
function balanced(s, start) {
|
|
3767
|
+
const open = s[start];
|
|
3768
|
+
const close = open === "[" ? "]" : "}";
|
|
3769
|
+
let depth = 0;
|
|
3770
|
+
let inString = false;
|
|
3771
|
+
let escaped = false;
|
|
3772
|
+
for (let i = start; i < s.length; i++) {
|
|
3773
|
+
const ch = s[i];
|
|
3774
|
+
if (escaped) escaped = false;
|
|
3775
|
+
else if (ch === "\\") escaped = true;
|
|
3776
|
+
else if (ch === '"') inString = !inString;
|
|
3777
|
+
else if (!inString && ch === open) depth++;
|
|
3778
|
+
else if (!inString && ch === close) {
|
|
3779
|
+
depth--;
|
|
3780
|
+
if (depth === 0) return s.slice(start, i + 1);
|
|
3781
|
+
}
|
|
3782
|
+
}
|
|
3783
|
+
return null;
|
|
3733
3784
|
}
|
|
3734
|
-
function
|
|
3735
|
-
|
|
3785
|
+
function parseAt(s, start) {
|
|
3786
|
+
const text2 = start < 0 ? null : balanced(s, start);
|
|
3787
|
+
if (text2 === null) return null;
|
|
3788
|
+
try {
|
|
3789
|
+
return JSON.parse(text2);
|
|
3790
|
+
} catch {
|
|
3791
|
+
return null;
|
|
3792
|
+
}
|
|
3736
3793
|
}
|
|
3737
|
-
function
|
|
3738
|
-
const
|
|
3739
|
-
|
|
3740
|
-
|
|
3794
|
+
function plain(v) {
|
|
3795
|
+
const protoCase = String(v.$case);
|
|
3796
|
+
const raw = v[protoCase];
|
|
3797
|
+
if (protoCase === "stringListValue") {
|
|
3798
|
+
return { protoCase, value: raw?.stringValues ?? [] };
|
|
3799
|
+
}
|
|
3800
|
+
if (protoCase === "signedLongValue" && typeof raw === "string" && raw.startsWith("$n")) {
|
|
3801
|
+
return { protoCase, value: { type: "bigint", value: raw.slice(2) } };
|
|
3802
|
+
}
|
|
3803
|
+
return { protoCase, value: raw };
|
|
3741
3804
|
}
|
|
3742
|
-
|
|
3743
|
-
const
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3805
|
+
function readModel(stream) {
|
|
3806
|
+
const at = stream.indexOf('"modelStates":[');
|
|
3807
|
+
const entries = parseAt(stream, at === -1 ? -1 : stream.indexOf("[", at));
|
|
3808
|
+
if (entries === null) return null;
|
|
3809
|
+
const model = /* @__PURE__ */ new Map();
|
|
3810
|
+
for (const entry2 of entries) {
|
|
3811
|
+
const id = entry2.key?.key?.value?.id;
|
|
3812
|
+
if (id !== void 0 && entry2.value !== void 0 && !model.has(id)) {
|
|
3813
|
+
model.set(id, plain(entry2.value));
|
|
3814
|
+
}
|
|
3748
3815
|
}
|
|
3749
|
-
|
|
3750
|
-
if (!result.ok) return err("sync", result.code, result.message, result.hint);
|
|
3751
|
-
const rows = rowsFrom(shapeAll(result.value.parsed.items, result.value.index));
|
|
3752
|
-
const stored = upsert(db, "my-posts", rows, now);
|
|
3753
|
-
setCheckpoint(db, {
|
|
3754
|
-
source: "my-posts",
|
|
3755
|
-
lastSuccessfulAt: now,
|
|
3756
|
-
newestCreatedAt: null,
|
|
3757
|
-
headIds: rows.slice(0, 5).map((r) => r.urn),
|
|
3758
|
-
state: "ok"
|
|
3759
|
-
});
|
|
3760
|
-
return ok("sync", {
|
|
3761
|
-
source: "my-posts",
|
|
3762
|
-
...stored,
|
|
3763
|
-
meta: result.value.parsed.meta,
|
|
3764
|
-
note: rows.length === 0 ? "LinkedIn returned no posts for this account. That is a genuine empty, not a failed fetch \u2014 meta.state says which." : void 0
|
|
3765
|
-
});
|
|
3816
|
+
return model;
|
|
3766
3817
|
}
|
|
3767
|
-
function
|
|
3768
|
-
const
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
"sync",
|
|
3774
|
-
"BUDGET_EXHAUSTED",
|
|
3775
|
-
`connections were synced ${Math.floor(age / 864e5)} days ago`,
|
|
3776
|
-
`This is the most expensive read in the tool and connections change slowly. Wait ${days} more day(s), or pass --force.`
|
|
3818
|
+
function findRequest(stream, requestId) {
|
|
3819
|
+
const at = stream.indexOf(`"requestId":"${requestId}","requestedArguments":`);
|
|
3820
|
+
if (at === -1) return null;
|
|
3821
|
+
const args = parseAt(
|
|
3822
|
+
stream,
|
|
3823
|
+
stream.indexOf("{", stream.indexOf('"requestedArguments":', at))
|
|
3777
3824
|
);
|
|
3825
|
+
return args !== null && Array.isArray(args.requestedStateKeys) && args.payload !== void 0 ? args : null;
|
|
3778
3826
|
}
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
const rows = rowsFrom(shapeAll(result.value.parsed.items, result.value.index));
|
|
3788
|
-
const stored = upsert(db, "connections", rows, now);
|
|
3789
|
-
const claimed = result.value.parsed.meta.claimedCount;
|
|
3790
|
-
const seen = new Set(rows.map((r) => r.urn));
|
|
3791
|
-
const { removed, complete } = diffSnapshot(before, seen, claimed);
|
|
3792
|
-
if (removed.length > 0) removeUrns(db, "connections", removed);
|
|
3793
|
-
setCheckpoint(db, {
|
|
3794
|
-
source: "connections",
|
|
3795
|
-
lastSuccessfulAt: now,
|
|
3796
|
-
newestCreatedAt: null,
|
|
3797
|
-
headIds: [],
|
|
3798
|
-
// Honest: a snapshot, never a watermark.
|
|
3799
|
-
state: complete ? "ok" : "snapshot-partial"
|
|
3800
|
-
});
|
|
3801
|
-
return ok("sync", {
|
|
3802
|
-
source: "connections",
|
|
3803
|
-
added: stored.added,
|
|
3804
|
-
updated: stored.updated,
|
|
3805
|
-
removed: removed.length,
|
|
3806
|
-
claimed,
|
|
3807
|
-
complete,
|
|
3808
|
-
meta: result.value.parsed.meta,
|
|
3809
|
-
note: complete ? void 0 : `Only ${rows.length} of ${claimed} connections were retrieved, so removals could not be determined and none were applied. Raise --limit to complete the snapshot.`
|
|
3810
|
-
});
|
|
3827
|
+
var unknownExpression = (what) => ({
|
|
3828
|
+
ok: false,
|
|
3829
|
+
code: "SCHEMA_DRIFT",
|
|
3830
|
+
message: `the form computes a value with an expression this tool does not evaluate (${what})`,
|
|
3831
|
+
hint: "Nothing was sent. Re-capture the form to see what it has become."
|
|
3832
|
+
});
|
|
3833
|
+
function boundId(body) {
|
|
3834
|
+
return body?.key?.key?.value?.id;
|
|
3811
3835
|
}
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
"lnrelay sync my-posts | lnrelay sync connections"
|
|
3819
|
-
);
|
|
3836
|
+
function str2(node, model) {
|
|
3837
|
+
const e = node.expression;
|
|
3838
|
+
if (e?.$case === "stringValue") return String(e.stringValue);
|
|
3839
|
+
if (e?.$case === "bindableString") {
|
|
3840
|
+
const v = model.get(boundId(e.bindableString) ?? "")?.value;
|
|
3841
|
+
return typeof v === "string" ? v : "";
|
|
3820
3842
|
}
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
"CACHE_CORRUPT",
|
|
3837
|
-
e.message,
|
|
3838
|
-
`Moved to ${e.quarantinedTo}. A corrupt cache is NOT treated as empty \u2014 that would make this sync re-enumerate everything. Inspect it, then re-run.`
|
|
3839
|
-
);
|
|
3843
|
+
return null;
|
|
3844
|
+
}
|
|
3845
|
+
function bool2(node, model) {
|
|
3846
|
+
const e = node.expression;
|
|
3847
|
+
const body = e?.[e?.$case ?? ""];
|
|
3848
|
+
switch (e?.$case) {
|
|
3849
|
+
case "booleanExpression":
|
|
3850
|
+
return bool2(body, model);
|
|
3851
|
+
case "booleanValue":
|
|
3852
|
+
return e.booleanValue === true;
|
|
3853
|
+
case "bindableBoolean":
|
|
3854
|
+
return model.get(boundId(e.bindableBoolean) ?? "")?.value === true;
|
|
3855
|
+
case "notExpression": {
|
|
3856
|
+
const a = bool2(body?.a ?? {}, model);
|
|
3857
|
+
return a === null ? null : !a;
|
|
3840
3858
|
}
|
|
3841
|
-
|
|
3859
|
+
case "orExpression":
|
|
3860
|
+
case "andExpression": {
|
|
3861
|
+
const a = bool2(body?.a ?? {}, model);
|
|
3862
|
+
const b = bool2(body?.b ?? {}, model);
|
|
3863
|
+
if (a === null || b === null) return null;
|
|
3864
|
+
return e.$case === "orExpression" ? a || b : a && b;
|
|
3865
|
+
}
|
|
3866
|
+
case "stringEqualsExpression": {
|
|
3867
|
+
const a = str2(body?.a ?? {}, model);
|
|
3868
|
+
const b = str2(body?.b ?? {}, model);
|
|
3869
|
+
if (a === null || b === null) return null;
|
|
3870
|
+
return body.ignoreCase === true ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
3871
|
+
}
|
|
3872
|
+
default:
|
|
3873
|
+
return null;
|
|
3842
3874
|
}
|
|
3843
3875
|
}
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
import { basename } from "path";
|
|
3848
|
-
|
|
3849
|
-
// src/engine/oauth-write.ts
|
|
3850
|
-
var API = "https://api.linkedin.com";
|
|
3851
|
-
function headers(token) {
|
|
3852
|
-
return {
|
|
3853
|
-
authorization: `Bearer ${token.accessToken}`,
|
|
3854
|
-
"content-type": "application/json",
|
|
3855
|
-
"x-restli-protocol-version": "2.0.0",
|
|
3856
|
-
"linkedin-version": "202601"
|
|
3857
|
-
};
|
|
3858
|
-
}
|
|
3859
|
-
function expired(token, now) {
|
|
3860
|
-
return token.expiresAt <= now;
|
|
3876
|
+
function evaluate(expression, model) {
|
|
3877
|
+
const value = bool2(expression, model);
|
|
3878
|
+
return value === null ? unknownExpression(JSON.stringify(expression).slice(0, 80)) : { ok: true, value };
|
|
3861
3879
|
}
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3880
|
+
function wireStates(keys, model, resolve) {
|
|
3881
|
+
const out = [];
|
|
3882
|
+
for (const id of keys) {
|
|
3883
|
+
const state = model.get(id);
|
|
3884
|
+
if (state === void 0) continue;
|
|
3885
|
+
let value = state.value;
|
|
3886
|
+
if (state.protoCase === "expression") {
|
|
3887
|
+
const r = resolve(id, state) ?? evaluate(state.value, model);
|
|
3888
|
+
if (!r.ok) return r;
|
|
3889
|
+
value = r.value;
|
|
3890
|
+
}
|
|
3891
|
+
out.push({
|
|
3892
|
+
key: id,
|
|
3893
|
+
namespace: "MemoryNamespace",
|
|
3894
|
+
value,
|
|
3895
|
+
originalProtoCase: state.protoCase,
|
|
3896
|
+
protoKey: { $type: "proto.sdui.Key", value: { $case: "id", id } }
|
|
3877
3897
|
});
|
|
3878
|
-
} catch (e) {
|
|
3879
|
-
return { ok: false, code: "FETCH_FAILED", message: e.message };
|
|
3880
|
-
}
|
|
3881
|
-
const text2 = await res.text();
|
|
3882
|
-
if (res.status === 201 || res.status === 200) {
|
|
3883
|
-
const id = res.headers.get("x-restli-id") ?? extractId(text2);
|
|
3884
|
-
return {
|
|
3885
|
-
ok: true,
|
|
3886
|
-
id: id ?? "(unknown)",
|
|
3887
|
-
...id === null ? {} : { url: `https://www.linkedin.com/feed/update/${id}/` }
|
|
3888
|
-
};
|
|
3889
|
-
}
|
|
3890
|
-
if (res.status === 429) {
|
|
3891
|
-
return {
|
|
3892
|
-
ok: false,
|
|
3893
|
-
code: "RATE_LIMITED",
|
|
3894
|
-
message: "LinkedIn throttled the write",
|
|
3895
|
-
hint: "Not retried automatically. Wait, and check `lnrelay budget`."
|
|
3896
|
-
};
|
|
3897
|
-
}
|
|
3898
|
-
if (res.status === 401 || res.status === 403) {
|
|
3899
|
-
return {
|
|
3900
|
-
ok: false,
|
|
3901
|
-
code: "AUTH_FAILED",
|
|
3902
|
-
message: `LinkedIn rejected the token (${res.status})`,
|
|
3903
|
-
hint: 'The scope may not be granted. Check the app has "Share on LinkedIn" added.'
|
|
3904
|
-
};
|
|
3905
3898
|
}
|
|
3899
|
+
return out;
|
|
3900
|
+
}
|
|
3901
|
+
var keysOf = (args) => args.requestedStateKeys.map((k) => k.key.value.id);
|
|
3902
|
+
function requestBody(requestId, args, states2, screen) {
|
|
3903
|
+
const requestedArguments = {
|
|
3904
|
+
$type: "proto.sdui.actions.requests.RequestedArguments",
|
|
3905
|
+
requestedStateKeys: args.requestedStateKeys,
|
|
3906
|
+
payload: args.payload,
|
|
3907
|
+
requestMetadata: { $type: "proto.sdui.common.RequestMetadata" }
|
|
3908
|
+
};
|
|
3906
3909
|
return {
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3910
|
+
requestId,
|
|
3911
|
+
serverRequest: {
|
|
3912
|
+
requestId,
|
|
3913
|
+
requestedArguments,
|
|
3914
|
+
isApfcEnabled: false,
|
|
3915
|
+
isStreaming: false,
|
|
3916
|
+
rumPageKey: ""
|
|
3917
|
+
},
|
|
3918
|
+
states: states2,
|
|
3919
|
+
requestedArguments: { ...requestedArguments, states: states2, screenId: screen, knownTemplateIds: [] }
|
|
3911
3920
|
};
|
|
3912
3921
|
}
|
|
3913
|
-
function
|
|
3914
|
-
return body.match(/"id"\s*:\s*"([^"]+)"/)?.[1] ?? null;
|
|
3915
|
-
}
|
|
3916
|
-
function share2(confirmed, token, deps) {
|
|
3917
|
-
return send(
|
|
3918
|
-
`${API}/rest/posts`,
|
|
3919
|
-
{
|
|
3920
|
-
author: token.memberUrn,
|
|
3921
|
-
commentary: confirmed.payload.text,
|
|
3922
|
-
visibility: confirmed.payload.visibility,
|
|
3923
|
-
distribution: {
|
|
3924
|
-
feedDistribution: "MAIN_FEED",
|
|
3925
|
-
targetEntities: [],
|
|
3926
|
-
thirdPartyDistributionChannels: []
|
|
3927
|
-
},
|
|
3928
|
-
lifecycleState: "PUBLISHED",
|
|
3929
|
-
isReshareDisabledByAuthor: false
|
|
3930
|
-
},
|
|
3931
|
-
token,
|
|
3932
|
-
deps
|
|
3933
|
-
);
|
|
3934
|
-
}
|
|
3935
|
-
|
|
3936
|
-
// src/engine/sdui-comment.ts
|
|
3937
|
-
var SDUI_ACTION2 = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
|
|
3938
|
-
var COMMENT_URL = `${SDUI_ACTION2}?sduiid=com.linkedin.sdui.comments.createComment`;
|
|
3939
|
-
var SCREEN_ID3 = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
|
|
3940
|
-
var STATE_PREFIXES = [
|
|
3941
|
-
"commentBoxText",
|
|
3942
|
-
"richCommentBoxText",
|
|
3943
|
-
"commentBoxLinkPreviewIngestedContentId",
|
|
3944
|
-
"commentBoxExternalImageUrl",
|
|
3945
|
-
"commentBoxExternalImageId"
|
|
3946
|
-
];
|
|
3947
|
-
var FEED_TYPES = { FEED_DETAIL: 3 };
|
|
3948
|
-
function keyBody(bindingKey) {
|
|
3949
|
-
return bindingKey.replace(/^commentBoxText-/, "");
|
|
3950
|
-
}
|
|
3951
|
-
function feedTypeFor(bindingKey) {
|
|
3952
|
-
const suffix = /FeedType_([A-Z_]+)$/.exec(bindingKey)?.[1];
|
|
3953
|
-
return suffix === void 0 ? null : FEED_TYPES[suffix] ?? null;
|
|
3954
|
-
}
|
|
3955
|
-
function stateKey(prefix, body) {
|
|
3956
|
-
return `${prefix}-${body}`;
|
|
3957
|
-
}
|
|
3958
|
-
function states(text2, body) {
|
|
3959
|
-
return STATE_PREFIXES.map((prefix) => {
|
|
3960
|
-
const key = stateKey(prefix, body);
|
|
3961
|
-
const base = {
|
|
3962
|
-
key,
|
|
3963
|
-
namespace: "MemoryNamespace",
|
|
3964
|
-
protoKey: { $type: "proto.sdui.Key", value: { $case: "id", id: key } }
|
|
3965
|
-
};
|
|
3966
|
-
if (prefix === "commentBoxText") {
|
|
3967
|
-
return { ...base, value: text2, originalProtoCase: "stringValue" };
|
|
3968
|
-
}
|
|
3969
|
-
if (prefix === "richCommentBoxText") {
|
|
3970
|
-
return {
|
|
3971
|
-
...base,
|
|
3972
|
-
value: { text: text2, attribute: [], $type: "TextModel", source: "local" },
|
|
3973
|
-
originalProtoCase: "textModelForWrite"
|
|
3974
|
-
};
|
|
3975
|
-
}
|
|
3976
|
-
return { ...base, value: "", originalProtoCase: "stringValue" };
|
|
3977
|
-
});
|
|
3978
|
-
}
|
|
3979
|
-
function commentBody(activityId, text2, tokens, feedType) {
|
|
3980
|
-
const body = keyBody(tokens.bindingKey);
|
|
3981
|
-
const activityUrn = { activityUrn: { activityId } };
|
|
3982
|
-
const binding = (prefix) => ({
|
|
3983
|
-
key: stateKey(prefix, body),
|
|
3984
|
-
namespace: "MemoryNamespace"
|
|
3985
|
-
});
|
|
3986
|
-
const payload = {
|
|
3987
|
-
// The live client's handle for its optimistically-rendered comment. Server
|
|
3988
|
-
// relevance unknown, but it is cheap to send and being faithful to a
|
|
3989
|
-
// captured shape beats trimming fields whose purpose we are guessing at.
|
|
3990
|
-
optimisticKey: `auto-component-${crypto.randomUUID()}`,
|
|
3991
|
-
collection: {
|
|
3992
|
-
updateKey: {
|
|
3993
|
-
feedType,
|
|
3994
|
-
items: [
|
|
3995
|
-
{ feedUpdateUrn: { updateUrnActivityUrn: activityUrn }, trackingId: tokens.trackingId }
|
|
3996
|
-
],
|
|
3997
|
-
aggregationType: 0,
|
|
3998
|
-
isVideoCarousel: false
|
|
3999
|
-
},
|
|
4000
|
-
threadUrn: { threadUrnActivityThreadUrn: activityUrn }
|
|
4001
|
-
},
|
|
4002
|
-
commentFieldBinding: binding("commentBoxText"),
|
|
4003
|
-
richCommentFieldBinding: binding("richCommentBoxText"),
|
|
4004
|
-
linkPreviewIngestedContentId: binding("commentBoxLinkPreviewIngestedContentId"),
|
|
4005
|
-
externalImageUrl: binding("commentBoxExternalImageUrl"),
|
|
4006
|
-
externalImageId: binding("commentBoxExternalImageId")
|
|
4007
|
-
};
|
|
4008
|
-
const requestedStateKeys = STATE_PREFIXES.map((p) => ({
|
|
4009
|
-
key: { value: { $case: "id", id: stateKey(p, body) } }
|
|
4010
|
-
}));
|
|
4011
|
-
const args = {
|
|
4012
|
-
$type: "proto.sdui.actions.requests.RequestedArguments",
|
|
4013
|
-
requestedStateKeys,
|
|
4014
|
-
payload,
|
|
4015
|
-
requestMetadata: { $type: "proto.sdui.common.RequestMetadata" }
|
|
4016
|
-
};
|
|
3922
|
+
function navBody(screen, payload) {
|
|
4017
3923
|
return {
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
},
|
|
4026
|
-
states: states(text2, body),
|
|
4027
|
-
requestedArguments: {
|
|
4028
|
-
...args,
|
|
4029
|
-
states: states(text2, body),
|
|
4030
|
-
screenId: SCREEN_ID3,
|
|
3924
|
+
clientArguments: {
|
|
3925
|
+
$type: "proto.sdui.actions.requests.RequestedArguments",
|
|
3926
|
+
requestedStateKeys: [],
|
|
3927
|
+
payload,
|
|
3928
|
+
requestMetadata: { $type: "proto.sdui.common.RequestMetadata" },
|
|
3929
|
+
states: [],
|
|
3930
|
+
screenId: screen,
|
|
4031
3931
|
knownTemplateIds: []
|
|
4032
|
-
}
|
|
3932
|
+
},
|
|
3933
|
+
isModal: true
|
|
4033
3934
|
};
|
|
4034
3935
|
}
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
if (!keyMatchesPost(tokens.bindingKey, activityId)) {
|
|
4038
|
-
return {
|
|
4039
|
-
ok: false,
|
|
4040
|
-
code: "INVALID_INPUT",
|
|
4041
|
-
message: "the harvested binding key does not belong to this post",
|
|
4042
|
-
hint: "Refusing to send: this is how a comment lands on the wrong post. Re-harvest."
|
|
4043
|
-
};
|
|
4044
|
-
}
|
|
4045
|
-
const feedType = feedTypeFor(tokens.bindingKey);
|
|
4046
|
-
if (feedType === null) {
|
|
4047
|
-
return {
|
|
4048
|
-
ok: false,
|
|
4049
|
-
code: "NOT_IMPLEMENTED",
|
|
4050
|
-
message: `unknown feed type in binding key '${tokens.bindingKey.slice(-24)}'`,
|
|
4051
|
-
hint: "Only FeedType_FEED_DETAIL has been observed, carrying feedType 3. Inventing a number for another context would be a malformed write against a real post. Capture the missing one with `bun run scripts/observe-write.ts`."
|
|
4052
|
-
};
|
|
4053
|
-
}
|
|
4054
|
-
const result = await client.request({
|
|
4055
|
-
url: COMMENT_URL,
|
|
4056
|
-
method: "POST",
|
|
4057
|
-
body: commentBody(activityId, text2, tokens, feedType),
|
|
4058
|
-
spendClass: "write",
|
|
4059
|
-
operation: "comment.create"
|
|
4060
|
-
});
|
|
4061
|
-
if (!result.ok) {
|
|
4062
|
-
const out = { ok: false, code: result.code, message: result.message };
|
|
4063
|
-
if (result.hint !== void 0) out.hint = result.hint;
|
|
4064
|
-
return out;
|
|
4065
|
-
}
|
|
4066
|
-
return { ok: true, id: activityId };
|
|
3936
|
+
function responseErrors(raw) {
|
|
3937
|
+
return raw.match(/"errors":\[([^\]]+)\]/)?.[1]?.slice(0, 300) ?? null;
|
|
4067
3938
|
}
|
|
4068
3939
|
|
|
4069
3940
|
// src/engine/sdui-profile.ts
|
|
@@ -4086,196 +3957,525 @@ var PROFILE_FIELDS = {
|
|
|
4086
3957
|
maxLength: 2600
|
|
4087
3958
|
}
|
|
4088
3959
|
};
|
|
4089
|
-
function formNavBody(screen, vanityName) {
|
|
4090
|
-
return {
|
|
4091
|
-
clientArguments: {
|
|
4092
|
-
$type: "proto.sdui.actions.requests.RequestedArguments",
|
|
4093
|
-
requestedStateKeys: [],
|
|
4094
|
-
payload: { vanityName, isVanityNameResolved: true },
|
|
4095
|
-
requestMetadata: { $type: "proto.sdui.common.RequestMetadata" },
|
|
4096
|
-
states: [],
|
|
4097
|
-
screenId: screen,
|
|
4098
|
-
knownTemplateIds: []
|
|
4099
|
-
},
|
|
4100
|
-
isModal: true
|
|
4101
|
-
};
|
|
4102
|
-
}
|
|
4103
3960
|
var drift2 = (message) => ({
|
|
4104
3961
|
ok: false,
|
|
4105
3962
|
code: "SCHEMA_DRIFT",
|
|
4106
3963
|
message,
|
|
4107
3964
|
hint: "Re-capture the profile form with scripts/observe-write.ts (edit one character, then revert)."
|
|
4108
3965
|
});
|
|
4109
|
-
function
|
|
4110
|
-
const
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
3966
|
+
function readForm(stream, field) {
|
|
3967
|
+
const states2 = readModel(stream);
|
|
3968
|
+
if (states2 === null) return drift2("the profile form carried no initial values");
|
|
3969
|
+
const args = findRequest(stream, field.save);
|
|
3970
|
+
if (args === null)
|
|
3971
|
+
return drift2(`the profile form carried no ${field.save.split(".").pop()} action`);
|
|
3972
|
+
return { ok: true, args, states: states2, screen: field.screen, save: field.save };
|
|
3973
|
+
}
|
|
3974
|
+
function boundKey(form, property) {
|
|
3975
|
+
const ref = form.args.payload[property];
|
|
3976
|
+
return ref?.key;
|
|
3977
|
+
}
|
|
3978
|
+
function currentValue(form, field) {
|
|
3979
|
+
const key = boundKey(form, field.binding);
|
|
3980
|
+
const v = key === void 0 ? void 0 : form.states.get(key)?.value;
|
|
3981
|
+
return typeof v === "string" ? v : void 0;
|
|
3982
|
+
}
|
|
3983
|
+
function topSkills(form) {
|
|
3984
|
+
return (key) => {
|
|
3985
|
+
if (!key.endsWith("ReorderableSkillsFormBindingsskillIdsBinding")) return void 0;
|
|
3986
|
+
const initial = [...form.states.entries()].find(([k]) => k.startsWith("initialSkills"))?.[1];
|
|
3987
|
+
if (initial === void 0) return drift2("the About form carried no initial top skills");
|
|
3988
|
+
if (!Array.isArray(initial.value) || initial.value.length > 0) {
|
|
3989
|
+
return {
|
|
3990
|
+
ok: false,
|
|
3991
|
+
code: "NOT_IMPLEMENTED",
|
|
3992
|
+
message: "your About section has top skills, and saving it with them has not been verified",
|
|
3993
|
+
hint: "Edit About in the browser for now; nothing was changed."
|
|
3994
|
+
};
|
|
4124
3995
|
}
|
|
3996
|
+
return { ok: true, value: [] };
|
|
3997
|
+
};
|
|
3998
|
+
}
|
|
3999
|
+
function saveBody(form, field, value) {
|
|
4000
|
+
if (value.length > field.maxLength) {
|
|
4001
|
+
return {
|
|
4002
|
+
ok: false,
|
|
4003
|
+
code: "INVALID_INPUT",
|
|
4004
|
+
message: `the ${field.name} is ${value.length} characters; LinkedIn allows ${field.maxLength}`
|
|
4005
|
+
};
|
|
4125
4006
|
}
|
|
4126
|
-
|
|
4007
|
+
const target = boundKey(form, field.binding);
|
|
4008
|
+
const current = target === void 0 ? void 0 : form.states.get(target);
|
|
4009
|
+
if (target === void 0 || current === void 0) {
|
|
4010
|
+
return drift2(`the profile form has no ${field.name} field`);
|
|
4011
|
+
}
|
|
4012
|
+
const model = new Map(form.states);
|
|
4013
|
+
model.set(target, { ...current, value });
|
|
4014
|
+
const states2 = wireStates(keysOf(form.args), model, topSkills(form));
|
|
4015
|
+
if (!Array.isArray(states2)) return states2;
|
|
4016
|
+
return { ok: true, body: requestBody(form.save, form.args, states2, form.screen) };
|
|
4127
4017
|
}
|
|
4128
|
-
function
|
|
4129
|
-
const
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4018
|
+
async function fetchProfileForm(field, vanityName, client) {
|
|
4019
|
+
const stream = await openForm(
|
|
4020
|
+
field.screen,
|
|
4021
|
+
{ vanityName, isVanityNameResolved: true },
|
|
4022
|
+
client,
|
|
4023
|
+
`profile-${field.name}-form`
|
|
4024
|
+
);
|
|
4025
|
+
return typeof stream === "string" ? readForm(stream, field) : stream;
|
|
4026
|
+
}
|
|
4027
|
+
async function openForm(screen, payload, client, operation) {
|
|
4028
|
+
const result = await client.request({
|
|
4029
|
+
url: `${NAV_URL}?screenId=${screen}&sduiid=${screen}`,
|
|
4030
|
+
method: "POST",
|
|
4031
|
+
body: navBody(screen, payload),
|
|
4032
|
+
spendClass: "page",
|
|
4033
|
+
operation
|
|
4034
|
+
});
|
|
4035
|
+
if (!result.ok) {
|
|
4036
|
+
const out = { ok: false, code: result.code, message: result.message };
|
|
4037
|
+
if (result.hint !== void 0) out.hint = result.hint;
|
|
4038
|
+
return out;
|
|
4135
4039
|
}
|
|
4040
|
+
return result.classification.raw ?? "";
|
|
4136
4041
|
}
|
|
4137
|
-
function
|
|
4138
|
-
const
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4042
|
+
async function sendAction(requestId, body, client, operation, spendClass = "write") {
|
|
4043
|
+
const result = await client.request({
|
|
4044
|
+
url: `${ACTION_URL}?sduiid=${requestId}`,
|
|
4045
|
+
method: "POST",
|
|
4046
|
+
body,
|
|
4047
|
+
spendClass,
|
|
4048
|
+
operation
|
|
4049
|
+
});
|
|
4050
|
+
if (!result.ok) {
|
|
4051
|
+
const out = { ok: false, code: result.code, message: result.message };
|
|
4052
|
+
if (result.hint !== void 0) out.hint = result.hint;
|
|
4053
|
+
return out;
|
|
4142
4054
|
}
|
|
4143
|
-
|
|
4055
|
+
const raw = result.classification.raw ?? "";
|
|
4056
|
+
const errors = responseErrors(raw);
|
|
4057
|
+
if (errors !== null) {
|
|
4058
|
+
return { ok: false, code: "INVALID_INPUT", message: `LinkedIn refused it: ${errors}` };
|
|
4059
|
+
}
|
|
4060
|
+
return raw;
|
|
4144
4061
|
}
|
|
4145
|
-
function
|
|
4146
|
-
const
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4062
|
+
async function sendProfileSave(form, body, client) {
|
|
4063
|
+
const r = await sendAction(form.save, body, client, "profile-save");
|
|
4064
|
+
return typeof r === "string" ? { ok: true } : r;
|
|
4065
|
+
}
|
|
4066
|
+
|
|
4067
|
+
// src/engine/sdui-position.ts
|
|
4068
|
+
var POSITION = {
|
|
4069
|
+
addScreen: "com.linkedin.sdui.flagshipnav.profile.ProfilePositionAddForm",
|
|
4070
|
+
editScreen: "com.linkedin.sdui.flagshipnav.profile.ProfilePositionDetailsEditForm",
|
|
4071
|
+
listScreen: "com.linkedin.sdui.flagshipnav.profile.ProfileExperienceDetails",
|
|
4072
|
+
media: "com.linkedin.sdui.impl.profile.components.forms.uploadPositionMedia",
|
|
4073
|
+
save: "com.linkedin.sdui.requests.profile.saveProfilePositionForm",
|
|
4074
|
+
delete: "com.linkedin.sdui.requests.profile.deleteProfilePositionForm"
|
|
4075
|
+
};
|
|
4076
|
+
var EDIT_NAV = `{"$type":"proto.sdui.actions.core.NavigateToScreen","screenId":"${POSITION.editScreen}"`;
|
|
4077
|
+
function listPositions(stream) {
|
|
4078
|
+
if (readModel(stream) === null && !stream.includes(EDIT_NAV) && !stream.includes('"rows"')) {
|
|
4079
|
+
return drift2("the Experience screen could not be read");
|
|
4155
4080
|
}
|
|
4156
|
-
const
|
|
4157
|
-
const
|
|
4158
|
-
|
|
4159
|
-
|
|
4081
|
+
const positions = [];
|
|
4082
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4083
|
+
let i = 0;
|
|
4084
|
+
for (; ; ) {
|
|
4085
|
+
i = stream.indexOf(EDIT_NAV, i);
|
|
4086
|
+
if (i === -1) break;
|
|
4087
|
+
const text2 = balanced(stream, i);
|
|
4088
|
+
i += EDIT_NAV.length;
|
|
4089
|
+
if (text2 === null) continue;
|
|
4090
|
+
const payload = JSON.parse(text2).requestedArguments?.payload;
|
|
4091
|
+
const id = payload?.positionId;
|
|
4092
|
+
if (typeof id !== "string" || seen.has(id) || payload === void 0) continue;
|
|
4093
|
+
seen.add(id);
|
|
4094
|
+
positions.push({ positionId: id, title: String(payload.title ?? ""), payload });
|
|
4095
|
+
}
|
|
4096
|
+
if (positions.length === 0 && !stream.includes('"rows"') && !stream.includes("Experience")) {
|
|
4097
|
+
return drift2("the Experience screen listed no roles and did not look like one");
|
|
4098
|
+
}
|
|
4099
|
+
return { ok: true, positions };
|
|
4100
|
+
}
|
|
4101
|
+
function readPositionForm(stream) {
|
|
4102
|
+
const model = readModel(stream);
|
|
4103
|
+
if (model === null) return drift2("the position form carried no initial values");
|
|
4104
|
+
const media = findRequest(stream, POSITION.media);
|
|
4105
|
+
const prefix = media?.payload.formIdPrefix;
|
|
4106
|
+
if (media === null || typeof prefix !== "string") {
|
|
4107
|
+
return drift2("the position form carried no save step (uploadPositionMedia)");
|
|
4108
|
+
}
|
|
4109
|
+
const del = findRequest(stream, POSITION.delete);
|
|
4110
|
+
return {
|
|
4111
|
+
ok: true,
|
|
4112
|
+
model,
|
|
4113
|
+
prefix,
|
|
4114
|
+
media,
|
|
4115
|
+
del,
|
|
4116
|
+
screen: del === null ? POSITION.addScreen : POSITION.editScreen
|
|
4117
|
+
};
|
|
4118
|
+
}
|
|
4119
|
+
var date = (d) => ({
|
|
4120
|
+
$type: "proto.sdui.common.Date",
|
|
4121
|
+
day: 0,
|
|
4122
|
+
month: d.month,
|
|
4123
|
+
year: d.year
|
|
4124
|
+
});
|
|
4125
|
+
var ym = (v) => {
|
|
4126
|
+
const d = v;
|
|
4127
|
+
return d?.year ? `${d.year}-${String(d.month ?? 0).padStart(2, "0")}` : null;
|
|
4128
|
+
};
|
|
4129
|
+
function applyChanges(form, changes) {
|
|
4130
|
+
const model = new Map(form.model);
|
|
4131
|
+
const set = (field, value) => {
|
|
4132
|
+
const key = `${form.prefix}${field}`;
|
|
4133
|
+
const current = model.get(key);
|
|
4134
|
+
if (current === void 0) return false;
|
|
4135
|
+
model.set(key, { ...current, value });
|
|
4136
|
+
return true;
|
|
4137
|
+
};
|
|
4138
|
+
const missing = [];
|
|
4139
|
+
const need = (field, value) => {
|
|
4140
|
+
if (!set(field, value)) missing.push(field);
|
|
4141
|
+
};
|
|
4142
|
+
if (changes.title !== void 0) need("title", changes.title);
|
|
4143
|
+
if (changes.description !== void 0) need("description", changes.description);
|
|
4144
|
+
if (changes.location !== void 0) need("location", changes.location);
|
|
4145
|
+
if (changes.company !== void 0) {
|
|
4146
|
+
need("companyName", changes.company);
|
|
4147
|
+
need("organizationId", -1);
|
|
4148
|
+
need("organizationEntityId", { type: "bigint", value: "-1" });
|
|
4149
|
+
}
|
|
4150
|
+
if (changes.start !== void 0) need("startDate", date(changes.start));
|
|
4151
|
+
if (changes.end === "present") need("isCurrentPosition", true);
|
|
4152
|
+
else if (changes.end !== void 0) {
|
|
4153
|
+
need("isCurrentPosition", false);
|
|
4154
|
+
need("endDate", date(changes.end));
|
|
4155
|
+
}
|
|
4156
|
+
need("dynamicallyCreateHeadline", false);
|
|
4157
|
+
need("allowProfileEditBroadcasts", changes.notify === true);
|
|
4158
|
+
if (missing.length > 0) return drift2(`the position form has no ${missing.join(", ")} field`);
|
|
4159
|
+
const s = roleSummary(model);
|
|
4160
|
+
if (!s.current && s.start !== null && s.end !== null && s.end < s.start) {
|
|
4161
|
+
return {
|
|
4162
|
+
ok: false,
|
|
4163
|
+
code: "INVALID_INPUT",
|
|
4164
|
+
message: `the role ends (${s.end}) before it starts (${s.start})`
|
|
4165
|
+
};
|
|
4166
|
+
}
|
|
4167
|
+
return { ok: true, model };
|
|
4168
|
+
}
|
|
4169
|
+
function roleSummary(model) {
|
|
4170
|
+
const get = (field) => [...model.entries()].find(([k]) => k.endsWith(`ProfilePositionForm${field}`))?.[1].value;
|
|
4171
|
+
const current = get("isCurrentPosition") === true;
|
|
4172
|
+
return {
|
|
4173
|
+
title: String(get("title") ?? ""),
|
|
4174
|
+
company: String(get("companyName") ?? ""),
|
|
4175
|
+
start: ym(get("startDate")),
|
|
4176
|
+
end: current ? null : ym(get("endDate")),
|
|
4177
|
+
current,
|
|
4178
|
+
location: String(get("location") ?? ""),
|
|
4179
|
+
description: String(get("description") ?? "")
|
|
4180
|
+
};
|
|
4181
|
+
}
|
|
4182
|
+
function noMedia(model) {
|
|
4183
|
+
const count2 = [...model.entries()].find(
|
|
4184
|
+
([k]) => k.endsWith("position-mediaUiCollection-mediaCount")
|
|
4185
|
+
)?.[1].value;
|
|
4186
|
+
return typeof count2 === "number" && count2 > 0 ? {
|
|
4187
|
+
ok: false,
|
|
4188
|
+
code: "NOT_IMPLEMENTED",
|
|
4189
|
+
message: "this role has media attached, and saving one with media has not been verified",
|
|
4190
|
+
hint: "Edit it in the browser for now; nothing was changed."
|
|
4191
|
+
} : null;
|
|
4192
|
+
}
|
|
4193
|
+
var resolver = (key) => key.endsWith("position-mediaIds") ? { ok: true, value: [] } : void 0;
|
|
4194
|
+
function mediaBody(form, model) {
|
|
4195
|
+
const refused = noMedia(model);
|
|
4196
|
+
if (refused !== null) return refused;
|
|
4197
|
+
const states2 = wireStates(keysOf(form.media), model, resolver);
|
|
4198
|
+
if (!Array.isArray(states2)) return states2;
|
|
4199
|
+
return { ok: true, body: requestBody(POSITION.media, form.media, states2, form.screen) };
|
|
4200
|
+
}
|
|
4201
|
+
function saveFromReply(reply) {
|
|
4202
|
+
const args = findRequest(reply, POSITION.save);
|
|
4203
|
+
return args === null ? drift2("the media step did not hand back the save action") : { ok: true, args };
|
|
4204
|
+
}
|
|
4205
|
+
function positionSaveBody(save, model, screen) {
|
|
4206
|
+
const sending = new Map(model);
|
|
4207
|
+
for (const [k, v] of sending)
|
|
4208
|
+
if (k.endsWith("isActiveProfileFormLoading")) sending.set(k, { ...v, value: true });
|
|
4209
|
+
const states2 = wireStates(keysOf(save), sending, resolver);
|
|
4210
|
+
if (!Array.isArray(states2)) return states2;
|
|
4211
|
+
return { ok: true, body: requestBody(POSITION.save, save, states2, screen) };
|
|
4212
|
+
}
|
|
4213
|
+
function deleteBody(form) {
|
|
4214
|
+
if (form.del === null)
|
|
4215
|
+
return drift2("this form has no delete action (it is not an existing role)");
|
|
4216
|
+
const states2 = wireStates(keysOf(form.del), form.model, resolver);
|
|
4217
|
+
if (!Array.isArray(states2)) return states2;
|
|
4218
|
+
return { ok: true, body: requestBody(POSITION.delete, form.del, states2, form.screen) };
|
|
4219
|
+
}
|
|
4220
|
+
async function fetchPositions(vanityName, client) {
|
|
4221
|
+
const stream = await openForm(
|
|
4222
|
+
POSITION.listScreen,
|
|
4223
|
+
{ vanityName, isVanityNameResolved: true },
|
|
4224
|
+
client,
|
|
4225
|
+
"experience-list"
|
|
4160
4226
|
);
|
|
4161
|
-
|
|
4162
|
-
|
|
4227
|
+
return typeof stream === "string" ? listPositions(stream) : stream;
|
|
4228
|
+
}
|
|
4229
|
+
async function openPositionForm(payload, client, edit2) {
|
|
4230
|
+
const stream = await openForm(
|
|
4231
|
+
edit2 ? POSITION.editScreen : POSITION.addScreen,
|
|
4232
|
+
{ ...payload, isVanityNameResolved: true },
|
|
4233
|
+
client,
|
|
4234
|
+
edit2 ? "position-edit-form" : "position-add-form"
|
|
4235
|
+
);
|
|
4236
|
+
return typeof stream === "string" ? readPositionForm(stream) : stream;
|
|
4237
|
+
}
|
|
4238
|
+
async function sendPositionSave(form, model, client) {
|
|
4239
|
+
const media = mediaBody(form, model);
|
|
4240
|
+
if (!media.ok) return media;
|
|
4241
|
+
const reply = await sendAction(POSITION.media, media.body, client, "position-media-step", "page");
|
|
4242
|
+
if (typeof reply !== "string") return reply;
|
|
4243
|
+
const save = saveFromReply(reply);
|
|
4244
|
+
if (!save.ok) return save;
|
|
4245
|
+
const body = positionSaveBody(save.args, model, form.screen);
|
|
4246
|
+
if (!body.ok) return body;
|
|
4247
|
+
const sent = await sendAction(POSITION.save, body.body, client, "position-save");
|
|
4248
|
+
return typeof sent === "string" ? { ok: true } : sent;
|
|
4249
|
+
}
|
|
4250
|
+
async function sendPositionDelete(form, client) {
|
|
4251
|
+
const body = deleteBody(form);
|
|
4252
|
+
if (!body.ok) return body;
|
|
4253
|
+
const sent = await sendAction(POSITION.delete, body.body, client, "position-delete");
|
|
4254
|
+
return typeof sent === "string" ? { ok: true } : sent;
|
|
4255
|
+
}
|
|
4256
|
+
|
|
4257
|
+
// src/commands/write.ts
|
|
4258
|
+
import { readFileSync as readFileSync2, statSync } from "fs";
|
|
4259
|
+
import { basename } from "path";
|
|
4260
|
+
|
|
4261
|
+
// src/engine/oauth-write.ts
|
|
4262
|
+
var API = "https://api.linkedin.com";
|
|
4263
|
+
function headers(token) {
|
|
4264
|
+
return {
|
|
4265
|
+
authorization: `Bearer ${token.accessToken}`,
|
|
4266
|
+
"content-type": "application/json",
|
|
4267
|
+
"x-restli-protocol-version": "2.0.0",
|
|
4268
|
+
"linkedin-version": "202601"
|
|
4269
|
+
};
|
|
4270
|
+
}
|
|
4271
|
+
function expired(token, now) {
|
|
4272
|
+
return token.expiresAt <= now;
|
|
4273
|
+
}
|
|
4274
|
+
async function send(url, body, token, deps) {
|
|
4275
|
+
if (expired(token, deps.now())) {
|
|
4276
|
+
return {
|
|
4277
|
+
ok: false,
|
|
4278
|
+
code: "AUTH_FAILED",
|
|
4279
|
+
message: "the OAuth token has expired",
|
|
4280
|
+
hint: "Run `lnrelay oauth` to obtain a fresh token."
|
|
4281
|
+
};
|
|
4163
4282
|
}
|
|
4164
|
-
|
|
4283
|
+
let res;
|
|
4284
|
+
try {
|
|
4285
|
+
res = await deps.fetch(url, {
|
|
4286
|
+
method: "POST",
|
|
4287
|
+
headers: headers(token),
|
|
4288
|
+
body: JSON.stringify(body)
|
|
4289
|
+
});
|
|
4290
|
+
} catch (e) {
|
|
4291
|
+
return { ok: false, code: "FETCH_FAILED", message: e.message };
|
|
4292
|
+
}
|
|
4293
|
+
const text2 = await res.text();
|
|
4294
|
+
if (res.status === 201 || res.status === 200) {
|
|
4295
|
+
const id = res.headers.get("x-restli-id") ?? extractId(text2);
|
|
4296
|
+
return {
|
|
4297
|
+
ok: true,
|
|
4298
|
+
id: id ?? "(unknown)",
|
|
4299
|
+
...id === null ? {} : { url: `https://www.linkedin.com/feed/update/${id}/` }
|
|
4300
|
+
};
|
|
4301
|
+
}
|
|
4302
|
+
if (res.status === 429) {
|
|
4303
|
+
return {
|
|
4304
|
+
ok: false,
|
|
4305
|
+
code: "RATE_LIMITED",
|
|
4306
|
+
message: "LinkedIn throttled the write",
|
|
4307
|
+
hint: "Not retried automatically. Wait, and check `lnrelay budget`."
|
|
4308
|
+
};
|
|
4309
|
+
}
|
|
4310
|
+
if (res.status === 401 || res.status === 403) {
|
|
4311
|
+
return {
|
|
4312
|
+
ok: false,
|
|
4313
|
+
code: "AUTH_FAILED",
|
|
4314
|
+
message: `LinkedIn rejected the token (${res.status})`,
|
|
4315
|
+
hint: 'The scope may not be granted. Check the app has "Share on LinkedIn" added.'
|
|
4316
|
+
};
|
|
4317
|
+
}
|
|
4318
|
+
return {
|
|
4319
|
+
ok: false,
|
|
4320
|
+
code: "FETCH_FAILED",
|
|
4321
|
+
message: `write failed (${res.status})`,
|
|
4322
|
+
hint: text2.slice(0, 300)
|
|
4323
|
+
};
|
|
4324
|
+
}
|
|
4325
|
+
function extractId(body) {
|
|
4326
|
+
return body.match(/"id"\s*:\s*"([^"]+)"/)?.[1] ?? null;
|
|
4327
|
+
}
|
|
4328
|
+
function share2(confirmed, token, deps) {
|
|
4329
|
+
return send(
|
|
4330
|
+
`${API}/rest/posts`,
|
|
4331
|
+
{
|
|
4332
|
+
author: token.memberUrn,
|
|
4333
|
+
commentary: confirmed.payload.text,
|
|
4334
|
+
visibility: confirmed.payload.visibility,
|
|
4335
|
+
distribution: {
|
|
4336
|
+
feedDistribution: "MAIN_FEED",
|
|
4337
|
+
targetEntities: [],
|
|
4338
|
+
thirdPartyDistributionChannels: []
|
|
4339
|
+
},
|
|
4340
|
+
lifecycleState: "PUBLISHED",
|
|
4341
|
+
isReshareDisabledByAuthor: false
|
|
4342
|
+
},
|
|
4343
|
+
token,
|
|
4344
|
+
deps
|
|
4345
|
+
);
|
|
4346
|
+
}
|
|
4347
|
+
|
|
4348
|
+
// src/engine/sdui-comment.ts
|
|
4349
|
+
var SDUI_ACTION2 = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
|
|
4350
|
+
var COMMENT_URL = `${SDUI_ACTION2}?sduiid=com.linkedin.sdui.comments.createComment`;
|
|
4351
|
+
var SCREEN_ID3 = "com.linkedin.sdui.flagshipnav.feed.UpdateDetail";
|
|
4352
|
+
var STATE_PREFIXES = [
|
|
4353
|
+
"commentBoxText",
|
|
4354
|
+
"richCommentBoxText",
|
|
4355
|
+
"commentBoxLinkPreviewIngestedContentId",
|
|
4356
|
+
"commentBoxExternalImageUrl",
|
|
4357
|
+
"commentBoxExternalImageId"
|
|
4358
|
+
];
|
|
4359
|
+
var FEED_TYPES = { FEED_DETAIL: 3 };
|
|
4360
|
+
function keyBody(bindingKey) {
|
|
4361
|
+
return bindingKey.replace(/^commentBoxText-/, "");
|
|
4165
4362
|
}
|
|
4166
|
-
function
|
|
4167
|
-
const
|
|
4168
|
-
return
|
|
4363
|
+
function feedTypeFor(bindingKey) {
|
|
4364
|
+
const suffix = /FeedType_([A-Z_]+)$/.exec(bindingKey)?.[1];
|
|
4365
|
+
return suffix === void 0 ? null : FEED_TYPES[suffix] ?? null;
|
|
4169
4366
|
}
|
|
4170
|
-
function
|
|
4171
|
-
|
|
4172
|
-
const v = key === void 0 ? void 0 : form.states.get(key)?.value;
|
|
4173
|
-
return typeof v === "string" ? v : void 0;
|
|
4367
|
+
function stateKey(prefix, body) {
|
|
4368
|
+
return `${prefix}-${body}`;
|
|
4174
4369
|
}
|
|
4175
|
-
function
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
code: "NOT_IMPLEMENTED",
|
|
4183
|
-
message: "your About section has top skills, and saving it with them has not been verified",
|
|
4184
|
-
hint: "Edit About in the browser for now; nothing was changed."
|
|
4370
|
+
function states(text2, body) {
|
|
4371
|
+
return STATE_PREFIXES.map((prefix) => {
|
|
4372
|
+
const key = stateKey(prefix, body);
|
|
4373
|
+
const base = {
|
|
4374
|
+
key,
|
|
4375
|
+
namespace: "MemoryNamespace",
|
|
4376
|
+
protoKey: { $type: "proto.sdui.Key", value: { $case: "id", id: key } }
|
|
4185
4377
|
};
|
|
4186
|
-
|
|
4187
|
-
|
|
4378
|
+
if (prefix === "commentBoxText") {
|
|
4379
|
+
return { ...base, value: text2, originalProtoCase: "stringValue" };
|
|
4380
|
+
}
|
|
4381
|
+
if (prefix === "richCommentBoxText") {
|
|
4382
|
+
return {
|
|
4383
|
+
...base,
|
|
4384
|
+
value: { text: text2, attribute: [], $type: "TextModel", source: "local" },
|
|
4385
|
+
originalProtoCase: "textModelForWrite"
|
|
4386
|
+
};
|
|
4387
|
+
}
|
|
4388
|
+
return { ...base, value: "", originalProtoCase: "stringValue" };
|
|
4389
|
+
});
|
|
4188
4390
|
}
|
|
4189
|
-
function
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4391
|
+
function commentBody(activityId, text2, tokens, feedType) {
|
|
4392
|
+
const body = keyBody(tokens.bindingKey);
|
|
4393
|
+
const activityUrn = { activityUrn: { activityId } };
|
|
4394
|
+
const binding = (prefix) => ({
|
|
4395
|
+
key: stateKey(prefix, body),
|
|
4396
|
+
namespace: "MemoryNamespace"
|
|
4397
|
+
});
|
|
4398
|
+
const payload = {
|
|
4399
|
+
// The live client's handle for its optimistically-rendered comment. Server
|
|
4400
|
+
// relevance unknown, but it is cheap to send and being faithful to a
|
|
4401
|
+
// captured shape beats trimming fields whose purpose we are guessing at.
|
|
4402
|
+
optimisticKey: `auto-component-${crypto.randomUUID()}`,
|
|
4403
|
+
collection: {
|
|
4404
|
+
updateKey: {
|
|
4405
|
+
feedType,
|
|
4406
|
+
items: [
|
|
4407
|
+
{ feedUpdateUrn: { updateUrnActivityUrn: activityUrn }, trackingId: tokens.trackingId }
|
|
4408
|
+
],
|
|
4409
|
+
aggregationType: 0,
|
|
4410
|
+
isVideoCarousel: false
|
|
4411
|
+
},
|
|
4412
|
+
threadUrn: { threadUrnActivityThreadUrn: activityUrn }
|
|
4413
|
+
},
|
|
4414
|
+
commentFieldBinding: binding("commentBoxText"),
|
|
4415
|
+
richCommentFieldBinding: binding("richCommentBoxText"),
|
|
4416
|
+
linkPreviewIngestedContentId: binding("commentBoxLinkPreviewIngestedContentId"),
|
|
4417
|
+
externalImageUrl: binding("commentBoxExternalImageUrl"),
|
|
4418
|
+
externalImageId: binding("commentBoxExternalImageId")
|
|
4419
|
+
};
|
|
4420
|
+
const requestedStateKeys = STATE_PREFIXES.map((p) => ({
|
|
4421
|
+
key: { value: { $case: "id", id: stateKey(p, body) } }
|
|
4422
|
+
}));
|
|
4423
|
+
const args = {
|
|
4217
4424
|
$type: "proto.sdui.actions.requests.RequestedArguments",
|
|
4218
|
-
requestedStateKeys
|
|
4219
|
-
payload
|
|
4425
|
+
requestedStateKeys,
|
|
4426
|
+
payload,
|
|
4220
4427
|
requestMetadata: { $type: "proto.sdui.common.RequestMetadata" }
|
|
4221
4428
|
};
|
|
4222
|
-
|
|
4223
|
-
requestId:
|
|
4429
|
+
return {
|
|
4430
|
+
requestId: "com.linkedin.sdui.comments.createComment",
|
|
4224
4431
|
serverRequest: {
|
|
4225
|
-
requestId:
|
|
4226
|
-
requestedArguments,
|
|
4432
|
+
requestId: "com.linkedin.sdui.comments.createComment",
|
|
4433
|
+
requestedArguments: args,
|
|
4227
4434
|
isApfcEnabled: false,
|
|
4228
4435
|
isStreaming: false,
|
|
4229
4436
|
rumPageKey: ""
|
|
4230
4437
|
},
|
|
4231
|
-
states:
|
|
4438
|
+
states: states(text2, body),
|
|
4232
4439
|
requestedArguments: {
|
|
4233
|
-
...
|
|
4234
|
-
states:
|
|
4235
|
-
screenId:
|
|
4440
|
+
...args,
|
|
4441
|
+
states: states(text2, body),
|
|
4442
|
+
screenId: SCREEN_ID3,
|
|
4236
4443
|
knownTemplateIds: []
|
|
4237
4444
|
}
|
|
4238
4445
|
};
|
|
4239
|
-
return { ok: true, body };
|
|
4240
4446
|
}
|
|
4241
|
-
async function
|
|
4242
|
-
const
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4447
|
+
async function comment(confirmed, client) {
|
|
4448
|
+
const { activityId, text: text2, tokens } = confirmed.payload;
|
|
4449
|
+
if (!keyMatchesPost(tokens.bindingKey, activityId)) {
|
|
4450
|
+
return {
|
|
4451
|
+
ok: false,
|
|
4452
|
+
code: "INVALID_INPUT",
|
|
4453
|
+
message: "the harvested binding key does not belong to this post",
|
|
4454
|
+
hint: "Refusing to send: this is how a comment lands on the wrong post. Re-harvest."
|
|
4455
|
+
};
|
|
4456
|
+
}
|
|
4457
|
+
const feedType = feedTypeFor(tokens.bindingKey);
|
|
4458
|
+
if (feedType === null) {
|
|
4459
|
+
return {
|
|
4460
|
+
ok: false,
|
|
4461
|
+
code: "NOT_IMPLEMENTED",
|
|
4462
|
+
message: `unknown feed type in binding key '${tokens.bindingKey.slice(-24)}'`,
|
|
4463
|
+
hint: "Only FeedType_FEED_DETAIL has been observed, carrying feedType 3. Inventing a number for another context would be a malformed write against a real post. Capture the missing one with `bun run scripts/observe-write.ts`."
|
|
4464
|
+
};
|
|
4253
4465
|
}
|
|
4254
|
-
return readForm(result.classification.raw ?? "", field);
|
|
4255
|
-
}
|
|
4256
|
-
async function sendProfileSave(form, body, client) {
|
|
4257
4466
|
const result = await client.request({
|
|
4258
|
-
url:
|
|
4467
|
+
url: COMMENT_URL,
|
|
4259
4468
|
method: "POST",
|
|
4260
|
-
body,
|
|
4469
|
+
body: commentBody(activityId, text2, tokens, feedType),
|
|
4261
4470
|
spendClass: "write",
|
|
4262
|
-
operation: "
|
|
4471
|
+
operation: "comment.create"
|
|
4263
4472
|
});
|
|
4264
4473
|
if (!result.ok) {
|
|
4265
4474
|
const out = { ok: false, code: result.code, message: result.message };
|
|
4266
4475
|
if (result.hint !== void 0) out.hint = result.hint;
|
|
4267
4476
|
return out;
|
|
4268
4477
|
}
|
|
4269
|
-
|
|
4270
|
-
const errors = raw.match(/"errors":\[([^\]]+)\]/)?.[1];
|
|
4271
|
-
if (errors !== void 0) {
|
|
4272
|
-
return {
|
|
4273
|
-
ok: false,
|
|
4274
|
-
code: "INVALID_INPUT",
|
|
4275
|
-
message: `LinkedIn refused the save: ${errors.slice(0, 300)}`
|
|
4276
|
-
};
|
|
4277
|
-
}
|
|
4278
|
-
return { ok: true };
|
|
4478
|
+
return { ok: true, id: activityId };
|
|
4279
4479
|
}
|
|
4280
4480
|
|
|
4281
4481
|
// src/engine/sdui-write.ts
|
|
@@ -4625,9 +4825,9 @@ function parseScheduleTime(input) {
|
|
|
4625
4825
|
const local = /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2})$/.exec(input);
|
|
4626
4826
|
if (local === null) return null;
|
|
4627
4827
|
const [y, mo, d, h, mi] = local.slice(1).map(Number);
|
|
4628
|
-
const
|
|
4629
|
-
const same =
|
|
4630
|
-
return same ?
|
|
4828
|
+
const date2 = new Date(y, mo - 1, d, h, mi);
|
|
4829
|
+
const same = date2.getFullYear() === y && date2.getMonth() === mo - 1 && date2.getDate() === d && date2.getHours() === h && date2.getMinutes() === mi;
|
|
4830
|
+
return same ? date2.getTime() : null;
|
|
4631
4831
|
}
|
|
4632
4832
|
var MIN_LEAD_MS = 10 * 6e4;
|
|
4633
4833
|
function mediaFrom(media, via2) {
|
|
@@ -5073,80 +5273,720 @@ async function runReact(postUrn2, type, now = Date.now(), deps = terminalDeps(),
|
|
|
5073
5273
|
const reaction = type.toUpperCase();
|
|
5074
5274
|
if (postUrn2 === void 0) {
|
|
5075
5275
|
return err(
|
|
5076
|
-
"react",
|
|
5276
|
+
"react",
|
|
5277
|
+
"INVALID_INPUT",
|
|
5278
|
+
"a post or comment urn is required",
|
|
5279
|
+
"lnrelay react <urn> [--type LIKE] [--remove]"
|
|
5280
|
+
);
|
|
5281
|
+
}
|
|
5282
|
+
if (!REACTIONS2.includes(reaction)) {
|
|
5283
|
+
return err(
|
|
5284
|
+
"react",
|
|
5285
|
+
"INVALID_INPUT",
|
|
5286
|
+
`unknown reaction '${type}'`,
|
|
5287
|
+
`one of: ${REACTIONS2.join(", ")}`
|
|
5288
|
+
);
|
|
5289
|
+
}
|
|
5290
|
+
const ctx = prepare("react", now, "voyager");
|
|
5291
|
+
if ("ok" in ctx) return ctx;
|
|
5292
|
+
if (ctx.transport.kind !== "voyager") {
|
|
5293
|
+
return err("react", "NOT_IMPLEMENTED", "reacting is only implemented over the private API");
|
|
5294
|
+
}
|
|
5295
|
+
const plan = {
|
|
5296
|
+
action: remove ? "remove a reaction" : "react to a post",
|
|
5297
|
+
payload: { urn: postUrn2, type: reaction, remove },
|
|
5298
|
+
summary: [
|
|
5299
|
+
authorLine(ctx.transport),
|
|
5300
|
+
`on ${postUrn2}`,
|
|
5301
|
+
`reaction ${reaction} \u2014 shows as "${reactionLabel(reaction)}"${remove ? " (REMOVING)" : ""}`
|
|
5302
|
+
],
|
|
5303
|
+
reversibility: remove ? "you can react again; the author may have been notified the first time" : `removable with \`lnrelay react ${postUrn2} --remove --type ${reaction}\` \u2014 the type is required, LinkedIn deletes a specific reaction; the author is notified immediately`,
|
|
5304
|
+
transport: "voyager"
|
|
5305
|
+
};
|
|
5306
|
+
const gated = await gate("react", plan, ctx, deps);
|
|
5307
|
+
if ("ok" in gated) return gated;
|
|
5308
|
+
const result = await react(gated.confirmed, createLiveClient(ctx.transport.session));
|
|
5309
|
+
return result.ok ? ok("react", { id: result.id, removed: remove }) : err("react", result.code, result.message, result.hint);
|
|
5310
|
+
}
|
|
5311
|
+
async function runReply(commentUrn, text2, now = Date.now(), deps = terminalDeps()) {
|
|
5312
|
+
if (commentUrn === void 0 || text2 === void 0 || text2.trim() === "") {
|
|
5313
|
+
return err(
|
|
5314
|
+
"reply",
|
|
5315
|
+
"INVALID_INPUT",
|
|
5316
|
+
"a comment urn and the reply text are required",
|
|
5317
|
+
'lnrelay reply <comment-urn> "<text>"'
|
|
5318
|
+
);
|
|
5319
|
+
}
|
|
5320
|
+
const parent = parseCommentUrn(commentUrn);
|
|
5321
|
+
if (parent === null) {
|
|
5322
|
+
return err(
|
|
5323
|
+
"reply",
|
|
5324
|
+
"INVALID_INPUT",
|
|
5325
|
+
`'${commentUrn}' is not a comment urn`,
|
|
5326
|
+
"To comment on a POST, use `lnrelay comment <activity-urn>`. Comment urns come from `lnrelay post <activity-urn>`."
|
|
5327
|
+
);
|
|
5328
|
+
}
|
|
5329
|
+
const unapprovable = refuseUnapprovable("reply", "replying", deps);
|
|
5330
|
+
if (unapprovable !== null) return unapprovable;
|
|
5331
|
+
const ctx = prepare("reply", now, "voyager");
|
|
5332
|
+
if ("ok" in ctx) return ctx;
|
|
5333
|
+
if (ctx.transport.kind !== "voyager") {
|
|
5334
|
+
return err("reply", "NOT_IMPLEMENTED", "replying is only implemented over the private API");
|
|
5335
|
+
}
|
|
5336
|
+
const plan = {
|
|
5337
|
+
action: "reply to a comment",
|
|
5338
|
+
payload: { ref: parent, text: text2 },
|
|
5339
|
+
summary: [authorLine(ctx.transport), `replying to ${commentUrn}`, `content "${text2}"`],
|
|
5340
|
+
reversibility: "deletable with `lnrelay delete <the reply urn>`; the comment author is notified immediately",
|
|
5341
|
+
transport: "voyager"
|
|
5342
|
+
};
|
|
5343
|
+
const gated = await gate("reply", plan, ctx, deps);
|
|
5344
|
+
if ("ok" in gated) return gated;
|
|
5345
|
+
const result = await replyToComment(
|
|
5346
|
+
gated.confirmed,
|
|
5347
|
+
createLiveClient(ctx.transport.session)
|
|
5348
|
+
);
|
|
5349
|
+
return result.ok ? ok("reply", { repliedTo: commentUrn }) : err("reply", result.code, result.message, result.hint);
|
|
5350
|
+
}
|
|
5351
|
+
|
|
5352
|
+
// src/commands/role.ts
|
|
5353
|
+
function liveRoles(session, quiet = false) {
|
|
5354
|
+
const client = createLiveClient(session, void 0, quiet);
|
|
5355
|
+
return {
|
|
5356
|
+
vanity: async () => {
|
|
5357
|
+
const me = await createEngine(session, void 0, quiet).whoami();
|
|
5358
|
+
if (!me.ok) return me;
|
|
5359
|
+
const id = me.value?.publicIdentifier;
|
|
5360
|
+
return typeof id === "string" && id !== "" ? { ok: true, vanity: id } : { ok: false, code: "SCHEMA_DRIFT", message: "whoami returned no public profile id" };
|
|
5361
|
+
},
|
|
5362
|
+
list: (vanity) => fetchPositions(vanity, client),
|
|
5363
|
+
open: (payload, edit2) => openPositionForm(payload, client, edit2),
|
|
5364
|
+
save: (form, model) => sendPositionSave(form, model, client),
|
|
5365
|
+
remove: (form) => sendPositionDelete(form, client)
|
|
5366
|
+
};
|
|
5367
|
+
}
|
|
5368
|
+
var SUBCOMMANDS = "add, edit <position-id>, remove <position-id>";
|
|
5369
|
+
function yearMonth(flag, v) {
|
|
5370
|
+
const m = /^(\d{4})-(\d{2})$/.exec(v);
|
|
5371
|
+
const month = Number(m?.[2]);
|
|
5372
|
+
if (m === null || month < 1 || month > 12) {
|
|
5373
|
+
return err(
|
|
5374
|
+
"role",
|
|
5375
|
+
"INVALID_INPUT",
|
|
5376
|
+
`--${flag} '${v}' is not a month`,
|
|
5377
|
+
"use YYYY-MM, e.g. 2021-06"
|
|
5378
|
+
);
|
|
5379
|
+
}
|
|
5380
|
+
return { year: Number(m[1]), month };
|
|
5381
|
+
}
|
|
5382
|
+
function changesFrom(req) {
|
|
5383
|
+
const c = {};
|
|
5384
|
+
if (req.title !== void 0) c.title = req.title;
|
|
5385
|
+
if (req.company !== void 0) c.company = req.company;
|
|
5386
|
+
if (req.description !== void 0) c.description = req.description;
|
|
5387
|
+
if (req.location !== void 0) c.location = req.location;
|
|
5388
|
+
if (req.notify === true) c.notify = true;
|
|
5389
|
+
if (req.start !== void 0) {
|
|
5390
|
+
const d = yearMonth("start", req.start);
|
|
5391
|
+
if ("ok" in d) return d;
|
|
5392
|
+
c.start = d;
|
|
5393
|
+
}
|
|
5394
|
+
if (req.current === true && req.end !== void 0) {
|
|
5395
|
+
return err("role", "INVALID_INPUT", "--current and --end contradict each other");
|
|
5396
|
+
}
|
|
5397
|
+
if (req.current === true) c.end = "present";
|
|
5398
|
+
else if (req.end !== void 0) {
|
|
5399
|
+
const d = yearMonth("end", req.end);
|
|
5400
|
+
if ("ok" in d) return d;
|
|
5401
|
+
c.end = d;
|
|
5402
|
+
}
|
|
5403
|
+
return c;
|
|
5404
|
+
}
|
|
5405
|
+
var span = (s) => `${s.start ?? "?"} \u2013 ${s.current ? "present" : s.end ?? "?"}`;
|
|
5406
|
+
var q = (v) => `"${v.length > 160 ? `${v.slice(0, 160)}\u2026` : v.replace(/\n/g, " ")}"`;
|
|
5407
|
+
function roleLines(s) {
|
|
5408
|
+
return [
|
|
5409
|
+
`title ${q(s.title)}`,
|
|
5410
|
+
`company ${q(s.company)}`,
|
|
5411
|
+
`dates ${span(s)}`,
|
|
5412
|
+
...s.location === "" ? [] : [`location ${q(s.location)}`],
|
|
5413
|
+
...s.description === "" ? [] : [`about ${q(s.description)}`]
|
|
5414
|
+
];
|
|
5415
|
+
}
|
|
5416
|
+
function diffLines(a, b) {
|
|
5417
|
+
const out = [];
|
|
5418
|
+
const row = (label, x, y) => {
|
|
5419
|
+
if (x !== y) out.push(`${label.padEnd(8)} ${q(x)} \u2192 ${q(y)}`);
|
|
5420
|
+
};
|
|
5421
|
+
row("title", a.title, b.title);
|
|
5422
|
+
row("company", a.company, b.company);
|
|
5423
|
+
row("dates", span(a), span(b));
|
|
5424
|
+
row("location", a.location, b.location);
|
|
5425
|
+
row("about", a.description, b.description);
|
|
5426
|
+
return out;
|
|
5427
|
+
}
|
|
5428
|
+
var SAFETY = (notify) => [
|
|
5429
|
+
"headline unchanged (LinkedIn would otherwise rewrite it from this role)",
|
|
5430
|
+
`notify ${notify ? "ON \u2014 your network may be told" : "off"}`
|
|
5431
|
+
];
|
|
5432
|
+
async function runRole(sub, target, req, now = Date.now(), deps = terminalDeps(), surface) {
|
|
5433
|
+
if (sub !== "add" && sub !== "edit" && sub !== "remove") {
|
|
5434
|
+
return err(
|
|
5435
|
+
"role",
|
|
5436
|
+
"INVALID_INPUT",
|
|
5437
|
+
`unknown role subcommand '${sub ?? ""}'`,
|
|
5438
|
+
`lnrelay role ${SUBCOMMANDS}`
|
|
5439
|
+
);
|
|
5440
|
+
}
|
|
5441
|
+
if (sub === "add") {
|
|
5442
|
+
const missing = ["title", "company", "start"].filter(
|
|
5443
|
+
(f) => req[f] === void 0 || req[f] === ""
|
|
5444
|
+
);
|
|
5445
|
+
if (missing.length > 0) {
|
|
5446
|
+
return err(
|
|
5447
|
+
"role",
|
|
5448
|
+
"INVALID_INPUT",
|
|
5449
|
+
`a new role needs ${missing.map((f) => `--${f}`).join(", ")}`
|
|
5450
|
+
);
|
|
5451
|
+
}
|
|
5452
|
+
} else if (target === void 0 || !/^\d+$/.test(target)) {
|
|
5453
|
+
return err(
|
|
5454
|
+
"role",
|
|
5077
5455
|
"INVALID_INPUT",
|
|
5078
|
-
|
|
5079
|
-
"
|
|
5456
|
+
`role ${sub} needs a position id`,
|
|
5457
|
+
"list them with `lnrelay experience`"
|
|
5080
5458
|
);
|
|
5081
5459
|
}
|
|
5082
|
-
|
|
5460
|
+
const changes = changesFrom(req);
|
|
5461
|
+
if ("ok" in changes) return changes;
|
|
5462
|
+
if (sub === "edit" && Object.keys(changes).filter((k) => k !== "notify").length === 0) {
|
|
5083
5463
|
return err(
|
|
5084
|
-
"
|
|
5464
|
+
"role",
|
|
5085
5465
|
"INVALID_INPUT",
|
|
5086
|
-
|
|
5087
|
-
|
|
5466
|
+
"nothing to change",
|
|
5467
|
+
"pass --title, --company, --start, --end, --current, --location or --description"
|
|
5088
5468
|
);
|
|
5089
5469
|
}
|
|
5090
|
-
const
|
|
5470
|
+
const unapprovable = refuseUnapprovable("role", "changing a role", deps);
|
|
5471
|
+
if (unapprovable !== null) return unapprovable;
|
|
5472
|
+
const ctx = prepare("role", now, "voyager");
|
|
5091
5473
|
if ("ok" in ctx) return ctx;
|
|
5092
5474
|
if (ctx.transport.kind !== "voyager") {
|
|
5093
|
-
return err("
|
|
5475
|
+
return err("role", "NOT_IMPLEMENTED", "role changes go over the browser session only");
|
|
5476
|
+
}
|
|
5477
|
+
const roles = surface ?? liveRoles(ctx.transport.session);
|
|
5478
|
+
const me = await roles.vanity();
|
|
5479
|
+
if (!me.ok) return err("role", me.code, me.message, me.hint);
|
|
5480
|
+
const listed2 = await roles.list(me.vanity);
|
|
5481
|
+
if (!listed2.ok) return err("role", listed2.code, listed2.message, listed2.hint);
|
|
5482
|
+
if (sub === "add") return addRole(changes, me.vanity, listed2.positions, roles, ctx, deps);
|
|
5483
|
+
const position = listed2.positions.find((p) => p.positionId === target);
|
|
5484
|
+
if (position === void 0) {
|
|
5485
|
+
return err(
|
|
5486
|
+
"role",
|
|
5487
|
+
"NOT_FOUND",
|
|
5488
|
+
`no role ${target} on your profile`,
|
|
5489
|
+
`your roles: ${listed2.positions.map((p) => `${p.positionId} (${p.title})`).join(", ") || "none"}`
|
|
5490
|
+
);
|
|
5094
5491
|
}
|
|
5492
|
+
const form = await roles.open({ ...position.payload, vanityName: me.vanity }, true);
|
|
5493
|
+
if (!form.ok) return err("role", form.code, form.message, form.hint);
|
|
5494
|
+
return sub === "edit" ? editRole(position, form, changes, me.vanity, roles, ctx, deps) : removeRole(position, form, me.vanity, roles, ctx, deps);
|
|
5495
|
+
}
|
|
5496
|
+
async function addRole(changes, vanity, before, roles, ctx, deps) {
|
|
5497
|
+
const form = await roles.open({ vanityName: vanity }, false);
|
|
5498
|
+
if (!form.ok) return err("role", form.code, form.message, form.hint);
|
|
5499
|
+
const applied = applyChanges(form, changes);
|
|
5500
|
+
if (!applied.ok) return err("role", applied.code, applied.message, applied.hint);
|
|
5501
|
+
const role2 = roleSummary(applied.model);
|
|
5095
5502
|
const plan = {
|
|
5096
|
-
action:
|
|
5097
|
-
payload: {
|
|
5503
|
+
action: "add a role to your profile",
|
|
5504
|
+
payload: { changes },
|
|
5505
|
+
summary: [authorLine(ctx.transport), ...roleLines(role2), ...SAFETY(changes.notify === true)],
|
|
5506
|
+
reversibility: "removable with `lnrelay role remove <position-id>`",
|
|
5507
|
+
transport: "voyager"
|
|
5508
|
+
};
|
|
5509
|
+
const gated = await gate("role", plan, ctx, deps);
|
|
5510
|
+
if ("ok" in gated) return gated;
|
|
5511
|
+
const saved = await roles.save(form, applied.model);
|
|
5512
|
+
if (!saved.ok) return err("role", saved.code, saved.message, saved.hint);
|
|
5513
|
+
const after = await roles.list(vanity);
|
|
5514
|
+
const known = new Set(before.map((p) => p.positionId));
|
|
5515
|
+
const added = after.ok ? after.positions.find((p) => !known.has(p.positionId) && p.title === role2.title) : void 0;
|
|
5516
|
+
if (added === void 0) {
|
|
5517
|
+
return err(
|
|
5518
|
+
"role",
|
|
5519
|
+
"SCHEMA_DRIFT",
|
|
5520
|
+
"LinkedIn accepted the role, but it does not appear on your profile"
|
|
5521
|
+
);
|
|
5522
|
+
}
|
|
5523
|
+
return ok("role", { added: added.positionId, verified: true });
|
|
5524
|
+
}
|
|
5525
|
+
async function editRole(position, form, changes, vanity, roles, ctx, deps) {
|
|
5526
|
+
const applied = applyChanges(form, changes);
|
|
5527
|
+
if (!applied.ok) return err("role", applied.code, applied.message, applied.hint);
|
|
5528
|
+
const was = roleSummary(form.model);
|
|
5529
|
+
const will = roleSummary(applied.model);
|
|
5530
|
+
const diff = diffLines(was, will);
|
|
5531
|
+
if (diff.length === 0)
|
|
5532
|
+
return err("role", "INVALID_INPUT", "the role already reads exactly that; nothing to save");
|
|
5533
|
+
const plan = {
|
|
5534
|
+
action: "edit a role on your profile",
|
|
5535
|
+
payload: { positionId: position.positionId, was, changes },
|
|
5098
5536
|
summary: [
|
|
5099
5537
|
authorLine(ctx.transport),
|
|
5100
|
-
`
|
|
5101
|
-
|
|
5538
|
+
`role ${position.positionId}`,
|
|
5539
|
+
...diff,
|
|
5540
|
+
...SAFETY(changes.notify === true)
|
|
5102
5541
|
],
|
|
5103
|
-
reversibility:
|
|
5542
|
+
reversibility: "editable again; the old values are kept only in this preview and the audit log",
|
|
5104
5543
|
transport: "voyager"
|
|
5105
5544
|
};
|
|
5106
|
-
const gated = await gate("
|
|
5545
|
+
const gated = await gate("role", plan, ctx, deps);
|
|
5107
5546
|
if ("ok" in gated) return gated;
|
|
5108
|
-
const
|
|
5109
|
-
|
|
5547
|
+
const saved = await roles.save(form, applied.model);
|
|
5548
|
+
if (!saved.ok) return err("role", saved.code, saved.message, saved.hint);
|
|
5549
|
+
const reread = await roles.open({ ...position.payload, vanityName: vanity }, true);
|
|
5550
|
+
const now = reread.ok ? roleSummary(reread.model) : null;
|
|
5551
|
+
if (now === null || diffLines(will, now).length > 0) {
|
|
5552
|
+
return err(
|
|
5553
|
+
"role",
|
|
5554
|
+
"SCHEMA_DRIFT",
|
|
5555
|
+
"LinkedIn accepted the edit, but the role does not read back as edited"
|
|
5556
|
+
);
|
|
5557
|
+
}
|
|
5558
|
+
return ok("role", { edited: position.positionId, verified: true });
|
|
5110
5559
|
}
|
|
5111
|
-
async function
|
|
5112
|
-
|
|
5560
|
+
async function removeRole(position, form, vanity, roles, ctx, deps) {
|
|
5561
|
+
const role2 = roleSummary(form.model);
|
|
5562
|
+
const plan = {
|
|
5563
|
+
action: "remove a role from your profile",
|
|
5564
|
+
payload: { positionId: position.positionId, role: role2 },
|
|
5565
|
+
summary: [authorLine(ctx.transport), `role ${position.positionId}`, ...roleLines(role2)],
|
|
5566
|
+
reversibility: "NONE. LinkedIn deletes it; re-adding makes a new role.",
|
|
5567
|
+
transport: "voyager"
|
|
5568
|
+
};
|
|
5569
|
+
const gated = await gate("role", plan, ctx, deps);
|
|
5570
|
+
if ("ok" in gated) return gated;
|
|
5571
|
+
const removed = await roles.remove(form);
|
|
5572
|
+
if (!removed.ok) return err("role", removed.code, removed.message, removed.hint);
|
|
5573
|
+
const after = await roles.list(vanity);
|
|
5574
|
+
if (!after.ok || after.positions.some((p) => p.positionId === position.positionId)) {
|
|
5113
5575
|
return err(
|
|
5114
|
-
"
|
|
5576
|
+
"role",
|
|
5577
|
+
"SCHEMA_DRIFT",
|
|
5578
|
+
"LinkedIn accepted the removal, but the role is still listed"
|
|
5579
|
+
);
|
|
5580
|
+
}
|
|
5581
|
+
return ok("role", { removed: position.positionId, verified: true });
|
|
5582
|
+
}
|
|
5583
|
+
async function runExperience(quiet = false) {
|
|
5584
|
+
const session = loadSession();
|
|
5585
|
+
if (session.state !== "ok")
|
|
5586
|
+
return err("experience", "AUTH_FAILED", "no LinkedIn session \u2014 run `lnrelay login`");
|
|
5587
|
+
const roles = liveRoles(session.session, quiet);
|
|
5588
|
+
const me = await roles.vanity();
|
|
5589
|
+
if (!me.ok) return err("experience", me.code, me.message, me.hint);
|
|
5590
|
+
const listed2 = await roles.list(me.vanity);
|
|
5591
|
+
if (!listed2.ok) return err("experience", listed2.code, listed2.message, listed2.hint);
|
|
5592
|
+
return ok("experience", {
|
|
5593
|
+
items: listed2.positions.map((p) => ({ positionId: p.positionId, title: p.title })),
|
|
5594
|
+
meta: { state: "complete", returnedCount: listed2.positions.length }
|
|
5595
|
+
});
|
|
5596
|
+
}
|
|
5597
|
+
|
|
5598
|
+
// src/engine/sdui-skill.ts
|
|
5599
|
+
var SKILL = {
|
|
5600
|
+
addScreen: "com.linkedin.sdui.flagshipnav.profile.ProfileSkillAddForm",
|
|
5601
|
+
editScreen: "com.linkedin.sdui.flagshipnav.profile.ProfileSkillDetailsEditForm",
|
|
5602
|
+
listScreen: "com.linkedin.sdui.flagshipnav.profile.ProfileSkillDetails",
|
|
5603
|
+
pager: "com.linkedin.sdui.pagers.profile.details.skills",
|
|
5604
|
+
save: "com.linkedin.sdui.requests.profile.saveProfileSkillForm",
|
|
5605
|
+
delete: "com.linkedin.sdui.requests.profile.deleteProfileSkillForm"
|
|
5606
|
+
};
|
|
5607
|
+
var EDIT_NAV2 = `{"$type":"proto.sdui.actions.core.NavigateToScreen","screenId":"${SKILL.editScreen}"`;
|
|
5608
|
+
var TEXT2 = /"children":\["((?:[^"\\]|\\.)*)"\]/g;
|
|
5609
|
+
function skillsFromPage(stream) {
|
|
5610
|
+
if (!stream.includes(SKILL.pager) && !stream.includes(EDIT_NAV2) && !stream.includes("isPartialPage")) {
|
|
5611
|
+
return drift2("the skills page could not be read");
|
|
5612
|
+
}
|
|
5613
|
+
const skills = [];
|
|
5614
|
+
let from = 0;
|
|
5615
|
+
let i = 0;
|
|
5616
|
+
for (; ; ) {
|
|
5617
|
+
i = stream.indexOf(EDIT_NAV2, i);
|
|
5618
|
+
if (i === -1) break;
|
|
5619
|
+
const text2 = balanced(stream, i);
|
|
5620
|
+
const end = i;
|
|
5621
|
+
i += EDIT_NAV2.length;
|
|
5622
|
+
if (text2 === null) continue;
|
|
5623
|
+
const payload = JSON.parse(text2).requestedArguments?.payload;
|
|
5624
|
+
const id = payload?.skillId;
|
|
5625
|
+
if (typeof id !== "string" || payload === void 0 || skills.some((s) => s.skillId === id))
|
|
5626
|
+
continue;
|
|
5627
|
+
const names = [...stream.slice(from, end).matchAll(TEXT2)].map(
|
|
5628
|
+
(m) => JSON.parse(`"${m[1]}"`)
|
|
5629
|
+
);
|
|
5630
|
+
skills.push({ skillId: id, name: names.length === 1 ? names[0] ?? null : null, payload });
|
|
5631
|
+
from = end + text2.length;
|
|
5632
|
+
}
|
|
5633
|
+
return { ok: true, skills };
|
|
5634
|
+
}
|
|
5635
|
+
function pagerFrom(payload, start) {
|
|
5636
|
+
const args = {
|
|
5637
|
+
$type: "proto.sdui.actions.requests.RequestedArguments",
|
|
5638
|
+
requestedStateKeys: [],
|
|
5639
|
+
payload: { ...payload, start },
|
|
5640
|
+
requestMetadata: { $type: "proto.sdui.common.RequestMetadata" }
|
|
5641
|
+
};
|
|
5642
|
+
return {
|
|
5643
|
+
pagerId: SKILL.pager,
|
|
5644
|
+
clientArguments: { ...args, states: [], screenId: SKILL.listScreen, knownTemplateIds: [] },
|
|
5645
|
+
paginationRequest: {
|
|
5646
|
+
$type: "proto.sdui.actions.requests.PaginationRequest",
|
|
5647
|
+
pagerId: SKILL.pager,
|
|
5648
|
+
retryCount: 0,
|
|
5649
|
+
requestedArguments: args
|
|
5650
|
+
}
|
|
5651
|
+
};
|
|
5652
|
+
}
|
|
5653
|
+
function readSkillForm(stream) {
|
|
5654
|
+
const model = readModel(stream);
|
|
5655
|
+
if (model === null) return drift2("the skill form carried no initial values");
|
|
5656
|
+
const save = findRequest(stream, SKILL.save);
|
|
5657
|
+
const del = findRequest(stream, SKILL.delete);
|
|
5658
|
+
if (save === null && del === null)
|
|
5659
|
+
return drift2("the skill form carried neither a save nor a delete");
|
|
5660
|
+
return { ok: true, model, save, del, screen: del === null ? SKILL.addScreen : SKILL.editScreen };
|
|
5661
|
+
}
|
|
5662
|
+
var nameKey = (model) => [...model.keys()].find((k) => k.startsWith("addSkillsTypeaheadSkillName"));
|
|
5663
|
+
function skillNameOf(form) {
|
|
5664
|
+
const key = nameKey(form.model);
|
|
5665
|
+
const v = key === void 0 ? void 0 : form.model.get(key)?.value;
|
|
5666
|
+
return typeof v === "string" ? v : null;
|
|
5667
|
+
}
|
|
5668
|
+
function addSkillBody(form, name) {
|
|
5669
|
+
if (name.trim() === "")
|
|
5670
|
+
return { ok: false, code: "INVALID_INPUT", message: "a skill needs a name" };
|
|
5671
|
+
if (form.save === null) return drift2("this form has no save action (it is not the add form)");
|
|
5672
|
+
const key = nameKey(form.model);
|
|
5673
|
+
const current = key === void 0 ? void 0 : form.model.get(key);
|
|
5674
|
+
if (key === void 0 || current === void 0) return drift2("the skill form has no name field");
|
|
5675
|
+
const model = new Map(form.model);
|
|
5676
|
+
model.set(key, { ...current, value: name.trim() });
|
|
5677
|
+
const states2 = wireStates(keysOf(form.save), model, () => void 0);
|
|
5678
|
+
if (!Array.isArray(states2)) return states2;
|
|
5679
|
+
return { ok: true, body: requestBody(SKILL.save, form.save, states2, form.screen) };
|
|
5680
|
+
}
|
|
5681
|
+
function removeSkillBody(form) {
|
|
5682
|
+
if (form.del === null)
|
|
5683
|
+
return drift2("this form has no delete action (it is not an existing skill)");
|
|
5684
|
+
const states2 = wireStates(keysOf(form.del), form.model, () => void 0);
|
|
5685
|
+
if (!Array.isArray(states2)) return states2;
|
|
5686
|
+
return { ok: true, body: requestBody(SKILL.delete, form.del, states2, form.screen) };
|
|
5687
|
+
}
|
|
5688
|
+
var PAGER_URL2 = `https://www.linkedin.com/flagship-web/rsc-action/actions/pagination?sduiid=${SKILL.pager}`;
|
|
5689
|
+
var MAX_PAGES2 = 10;
|
|
5690
|
+
async function fetchSkills(vanityName, client) {
|
|
5691
|
+
const screen = await openForm(
|
|
5692
|
+
SKILL.listScreen,
|
|
5693
|
+
{ vanityName, isVanityNameResolved: true },
|
|
5694
|
+
client,
|
|
5695
|
+
"skills-screen"
|
|
5696
|
+
);
|
|
5697
|
+
if (typeof screen !== "string") return screen;
|
|
5698
|
+
const at = screen.indexOf('"filter":"ProfileSkillCategory_ALL"');
|
|
5699
|
+
const open = at === -1 ? -1 : screen.lastIndexOf('"payload":{', at);
|
|
5700
|
+
const text2 = open === -1 ? null : balanced(screen, open + '"payload":'.length);
|
|
5701
|
+
if (text2 === null) return drift2("the Skills screen carried no list request");
|
|
5702
|
+
const payload = JSON.parse(text2);
|
|
5703
|
+
const count2 = typeof payload.count === "number" ? payload.count : 10;
|
|
5704
|
+
const skills = [];
|
|
5705
|
+
for (let page = 0; page < MAX_PAGES2; page++) {
|
|
5706
|
+
const result = await client.request({
|
|
5707
|
+
url: PAGER_URL2,
|
|
5708
|
+
method: "POST",
|
|
5709
|
+
body: pagerFrom(payload, skills.length),
|
|
5710
|
+
spendClass: "page",
|
|
5711
|
+
operation: "skills"
|
|
5712
|
+
});
|
|
5713
|
+
if (!result.ok) return { ok: false, code: result.code, message: result.message };
|
|
5714
|
+
const parsed = skillsFromPage(result.classification.raw ?? "");
|
|
5715
|
+
if (!parsed.ok) return parsed;
|
|
5716
|
+
const fresh = parsed.skills.filter((s) => !skills.some((k) => k.skillId === s.skillId));
|
|
5717
|
+
skills.push(...fresh);
|
|
5718
|
+
if (parsed.skills.length < count2 || fresh.length === 0) break;
|
|
5719
|
+
}
|
|
5720
|
+
return { ok: true, skills };
|
|
5721
|
+
}
|
|
5722
|
+
async function openSkillForm(payload, client, edit2) {
|
|
5723
|
+
const stream = await openForm(
|
|
5724
|
+
edit2 ? SKILL.editScreen : SKILL.addScreen,
|
|
5725
|
+
{ ...payload, isVanityNameResolved: true },
|
|
5726
|
+
client,
|
|
5727
|
+
edit2 ? "skill-edit-form" : "skill-add-form"
|
|
5728
|
+
);
|
|
5729
|
+
return typeof stream === "string" ? readSkillForm(stream) : stream;
|
|
5730
|
+
}
|
|
5731
|
+
async function sendSkill(body, requestId, client) {
|
|
5732
|
+
const sent = await sendAction(
|
|
5733
|
+
requestId,
|
|
5734
|
+
body,
|
|
5735
|
+
client,
|
|
5736
|
+
requestId === SKILL.save ? "skill-add" : "skill-remove"
|
|
5737
|
+
);
|
|
5738
|
+
return typeof sent === "string" ? { ok: true } : sent;
|
|
5739
|
+
}
|
|
5740
|
+
|
|
5741
|
+
// src/commands/skill.ts
|
|
5742
|
+
function liveSkills(session, quiet = false) {
|
|
5743
|
+
const client = createLiveClient(session, void 0, quiet);
|
|
5744
|
+
return {
|
|
5745
|
+
vanity: async () => {
|
|
5746
|
+
const me = await createEngine(session, void 0, quiet).whoami();
|
|
5747
|
+
if (!me.ok) return me;
|
|
5748
|
+
const id = me.value?.publicIdentifier;
|
|
5749
|
+
return typeof id === "string" && id !== "" ? { ok: true, vanity: id } : { ok: false, code: "SCHEMA_DRIFT", message: "whoami returned no public profile id" };
|
|
5750
|
+
},
|
|
5751
|
+
list: (vanity) => fetchSkills(vanity, client),
|
|
5752
|
+
open: (payload, edit2) => openSkillForm(payload, client, edit2),
|
|
5753
|
+
send: (body, requestId) => sendSkill(body, requestId, client)
|
|
5754
|
+
};
|
|
5755
|
+
}
|
|
5756
|
+
var listed = (skills) => skills.map((s) => `${s.skillId} (${s.name ?? "?"})`).join(", ") || "none";
|
|
5757
|
+
async function runSkill(sub, arg, now = Date.now(), deps = terminalDeps(), surface) {
|
|
5758
|
+
if (sub !== "add" && sub !== "remove") {
|
|
5759
|
+
return err(
|
|
5760
|
+
"skill",
|
|
5115
5761
|
"INVALID_INPUT",
|
|
5116
|
-
|
|
5117
|
-
'lnrelay
|
|
5762
|
+
`unknown skill subcommand '${sub ?? ""}'`,
|
|
5763
|
+
'lnrelay skill add "<name>" | lnrelay skill remove <skill-id>'
|
|
5118
5764
|
);
|
|
5119
5765
|
}
|
|
5120
|
-
|
|
5121
|
-
if (parent === null) {
|
|
5766
|
+
if (arg === void 0 || arg.trim() === "") {
|
|
5122
5767
|
return err(
|
|
5123
|
-
"
|
|
5768
|
+
"skill",
|
|
5124
5769
|
"INVALID_INPUT",
|
|
5125
|
-
|
|
5126
|
-
"
|
|
5770
|
+
sub === "add" ? "the skill name is required" : "the skill id is required",
|
|
5771
|
+
"ids come from `lnrelay skills`"
|
|
5127
5772
|
);
|
|
5128
5773
|
}
|
|
5129
|
-
const unapprovable = refuseUnapprovable("
|
|
5774
|
+
const unapprovable = refuseUnapprovable("skill", "changing your skills", deps);
|
|
5130
5775
|
if (unapprovable !== null) return unapprovable;
|
|
5131
|
-
const ctx = prepare("
|
|
5776
|
+
const ctx = prepare("skill", now, "voyager");
|
|
5132
5777
|
if ("ok" in ctx) return ctx;
|
|
5133
|
-
if (ctx.transport.kind !== "voyager")
|
|
5134
|
-
return err("
|
|
5135
|
-
|
|
5778
|
+
if (ctx.transport.kind !== "voyager")
|
|
5779
|
+
return err("skill", "NOT_IMPLEMENTED", "skill changes go over the browser session only");
|
|
5780
|
+
const skills = surface ?? liveSkills(ctx.transport.session);
|
|
5781
|
+
const me = await skills.vanity();
|
|
5782
|
+
if (!me.ok) return err("skill", me.code, me.message, me.hint);
|
|
5783
|
+
const before = await skills.list(me.vanity);
|
|
5784
|
+
if (!before.ok) return err("skill", before.code, before.message, before.hint);
|
|
5785
|
+
return sub === "add" ? addSkill(arg.trim(), before.skills, me.vanity, skills, ctx, deps) : removeSkill(arg, before.skills, me.vanity, skills, ctx, deps);
|
|
5786
|
+
}
|
|
5787
|
+
async function addSkill(name, current, vanity, skills, ctx, deps) {
|
|
5788
|
+
const dup = current.find((s) => s.name?.toLowerCase() === name.toLowerCase());
|
|
5789
|
+
if (dup !== void 0)
|
|
5790
|
+
return err(
|
|
5791
|
+
"skill",
|
|
5792
|
+
"INVALID_INPUT",
|
|
5793
|
+
`"${dup.name}" is already on your profile (${dup.skillId})`
|
|
5794
|
+
);
|
|
5795
|
+
const form = await skills.open({ vanityName: vanity }, false);
|
|
5796
|
+
if (!form.ok) return err("skill", form.code, form.message, form.hint);
|
|
5797
|
+
const body = addSkillBody(form, name);
|
|
5798
|
+
if (!body.ok) return err("skill", body.code, body.message, body.hint);
|
|
5136
5799
|
const plan = {
|
|
5137
|
-
action: "
|
|
5138
|
-
payload: {
|
|
5139
|
-
summary: [
|
|
5140
|
-
|
|
5800
|
+
action: "add a skill to your profile",
|
|
5801
|
+
payload: { name },
|
|
5802
|
+
summary: [
|
|
5803
|
+
authorLine(ctx.transport),
|
|
5804
|
+
`skill "${name}"`,
|
|
5805
|
+
"linked to nothing (no roles, schools or projects)"
|
|
5806
|
+
],
|
|
5807
|
+
reversibility: "removable with `lnrelay skill remove <skill-id>`",
|
|
5141
5808
|
transport: "voyager"
|
|
5142
5809
|
};
|
|
5143
|
-
const gated = await gate("
|
|
5810
|
+
const gated = await gate("skill", plan, ctx, deps);
|
|
5144
5811
|
if ("ok" in gated) return gated;
|
|
5145
|
-
const
|
|
5146
|
-
|
|
5147
|
-
|
|
5812
|
+
const sent = await skills.send(body.body, SKILL.save);
|
|
5813
|
+
if (!sent.ok) return err("skill", sent.code, sent.message, sent.hint);
|
|
5814
|
+
const after = await skills.list(vanity);
|
|
5815
|
+
const known = new Set(current.map((s) => s.skillId));
|
|
5816
|
+
const added = after.ok ? after.skills.find((s) => !known.has(s.skillId)) : void 0;
|
|
5817
|
+
if (added === void 0)
|
|
5818
|
+
return err(
|
|
5819
|
+
"skill",
|
|
5820
|
+
"SCHEMA_DRIFT",
|
|
5821
|
+
"LinkedIn accepted the skill, but it does not appear on your profile"
|
|
5822
|
+
);
|
|
5823
|
+
return ok("skill", { added: added.skillId, name: added.name, verified: true });
|
|
5824
|
+
}
|
|
5825
|
+
async function removeSkill(arg, current, vanity, skills, ctx, deps) {
|
|
5826
|
+
const target = current.find((s) => s.skillId === arg);
|
|
5827
|
+
if (target === void 0)
|
|
5828
|
+
return err(
|
|
5829
|
+
"skill",
|
|
5830
|
+
"NOT_FOUND",
|
|
5831
|
+
`no skill ${arg} on your profile`,
|
|
5832
|
+
`your skills: ${listed(current)}`
|
|
5833
|
+
);
|
|
5834
|
+
const form = await skills.open({ ...target.payload, vanityName: vanity }, true);
|
|
5835
|
+
if (!form.ok) return err("skill", form.code, form.message, form.hint);
|
|
5836
|
+
const body = removeSkillBody(form);
|
|
5837
|
+
if (!body.ok) return err("skill", body.code, body.message, body.hint);
|
|
5838
|
+
const name = skillNameOf(form) ?? target.name ?? "?";
|
|
5839
|
+
const plan = {
|
|
5840
|
+
action: "remove a skill from your profile",
|
|
5841
|
+
payload: { skillId: target.skillId, name },
|
|
5842
|
+
summary: [authorLine(ctx.transport), `skill "${name}" (${target.skillId})`],
|
|
5843
|
+
reversibility: "NONE for its endorsements, which go with it; the skill itself can be added again",
|
|
5844
|
+
transport: "voyager"
|
|
5845
|
+
};
|
|
5846
|
+
const gated = await gate("skill", plan, ctx, deps);
|
|
5847
|
+
if ("ok" in gated) return gated;
|
|
5848
|
+
const sent = await skills.send(body.body, SKILL.delete);
|
|
5849
|
+
if (!sent.ok) return err("skill", sent.code, sent.message, sent.hint);
|
|
5850
|
+
const after = await skills.list(vanity);
|
|
5851
|
+
if (!after.ok || after.skills.some((s) => s.skillId === target.skillId)) {
|
|
5852
|
+
return err(
|
|
5853
|
+
"skill",
|
|
5854
|
+
"SCHEMA_DRIFT",
|
|
5855
|
+
"LinkedIn accepted the removal, but the skill is still listed"
|
|
5856
|
+
);
|
|
5857
|
+
}
|
|
5858
|
+
return ok("skill", { removed: target.skillId, verified: true });
|
|
5859
|
+
}
|
|
5860
|
+
async function runSkills(quiet = false) {
|
|
5861
|
+
const session = loadSession();
|
|
5862
|
+
if (session.state !== "ok")
|
|
5863
|
+
return err("skills", "AUTH_FAILED", "no LinkedIn session \u2014 run `lnrelay login`");
|
|
5864
|
+
const skills = liveSkills(session.session, quiet);
|
|
5865
|
+
const me = await skills.vanity();
|
|
5866
|
+
if (!me.ok) return err("skills", me.code, me.message, me.hint);
|
|
5867
|
+
const listedSkills = await skills.list(me.vanity);
|
|
5868
|
+
if (!listedSkills.ok)
|
|
5869
|
+
return err("skills", listedSkills.code, listedSkills.message, listedSkills.hint);
|
|
5870
|
+
return ok("skills", {
|
|
5871
|
+
items: listedSkills.skills.map((s) => ({ skillId: s.skillId, name: s.name })),
|
|
5872
|
+
meta: { state: "complete", returnedCount: listedSkills.skills.length }
|
|
5873
|
+
});
|
|
5874
|
+
}
|
|
5875
|
+
|
|
5876
|
+
// src/commands/sync.ts
|
|
5877
|
+
var CONNECTIONS_MIN_INTERVAL_MS = 7 * 864e5;
|
|
5878
|
+
function searchText(item) {
|
|
5879
|
+
return [item.name, item.headline, item.location, item.text, item.author, item.company, item.title].filter((v) => typeof v === "string").join(" ");
|
|
5880
|
+
}
|
|
5881
|
+
function rowsFrom(items) {
|
|
5882
|
+
return items.filter((i) => typeof i.urn === "string" && i.urn !== "").map((i) => ({ urn: i.urn, body: i, text: searchText(i) }));
|
|
5883
|
+
}
|
|
5884
|
+
function diffSnapshot(before, seen, claimed) {
|
|
5885
|
+
const complete = claimed === void 0 || seen.size >= claimed;
|
|
5886
|
+
if (!complete) return { removed: [], complete: false };
|
|
5887
|
+
return { removed: [...before].filter((urn) => !seen.has(urn)), complete: true };
|
|
5888
|
+
}
|
|
5889
|
+
async function syncMyPosts(engine, db, limit, now) {
|
|
5890
|
+
const me = await engine.whoami();
|
|
5891
|
+
if (!me.ok) return err("sync", me.code, me.message, me.hint);
|
|
5892
|
+
const profileUrn = typeof me.value?.entityUrn === "string" ? me.value.entityUrn : void 0;
|
|
5893
|
+
if (profileUrn === void 0) {
|
|
5894
|
+
return err("sync", "SCHEMA_DRIFT", "could not determine the owner profile urn");
|
|
5895
|
+
}
|
|
5896
|
+
const result = await engine.myPosts(profileUrn, limit);
|
|
5897
|
+
if (!result.ok) return err("sync", result.code, result.message, result.hint);
|
|
5898
|
+
const rows = rowsFrom(shapeAll(result.value.parsed.items, result.value.index));
|
|
5899
|
+
const stored = upsert(db, "my-posts", rows, now);
|
|
5900
|
+
setCheckpoint(db, {
|
|
5901
|
+
source: "my-posts",
|
|
5902
|
+
lastSuccessfulAt: now,
|
|
5903
|
+
newestCreatedAt: null,
|
|
5904
|
+
headIds: rows.slice(0, 5).map((r) => r.urn),
|
|
5905
|
+
state: "ok"
|
|
5906
|
+
});
|
|
5907
|
+
return ok("sync", {
|
|
5908
|
+
source: "my-posts",
|
|
5909
|
+
...stored,
|
|
5910
|
+
meta: result.value.parsed.meta,
|
|
5911
|
+
note: rows.length === 0 ? "LinkedIn returned no posts for this account. That is a genuine empty, not a failed fetch \u2014 meta.state says which." : void 0
|
|
5912
|
+
});
|
|
5913
|
+
}
|
|
5914
|
+
function tooSoon(db, now) {
|
|
5915
|
+
const cp = getCheckpoint(db, "connections");
|
|
5916
|
+
const age = cp === void 0 ? Number.POSITIVE_INFINITY : now - cp.lastSuccessfulAt;
|
|
5917
|
+
if (age >= CONNECTIONS_MIN_INTERVAL_MS) return void 0;
|
|
5918
|
+
const days = Math.ceil((CONNECTIONS_MIN_INTERVAL_MS - age) / 864e5);
|
|
5919
|
+
return err(
|
|
5920
|
+
"sync",
|
|
5921
|
+
"BUDGET_EXHAUSTED",
|
|
5922
|
+
`connections were synced ${Math.floor(age / 864e5)} days ago`,
|
|
5923
|
+
`This is the most expensive read in the tool and connections change slowly. Wait ${days} more day(s), or pass --force.`
|
|
5148
5924
|
);
|
|
5149
|
-
|
|
5925
|
+
}
|
|
5926
|
+
async function syncConnections(engine, db, limit, force, now) {
|
|
5927
|
+
const before = urnsFor(db, "connections");
|
|
5928
|
+
if (!force && before.size > 0) {
|
|
5929
|
+
const blocked = tooSoon(db, now);
|
|
5930
|
+
if (blocked !== void 0) return blocked;
|
|
5931
|
+
}
|
|
5932
|
+
const result = await engine.connections(limit);
|
|
5933
|
+
if (!result.ok) return err("sync", result.code, result.message, result.hint);
|
|
5934
|
+
const rows = rowsFrom(shapeAll(result.value.parsed.items, result.value.index));
|
|
5935
|
+
const stored = upsert(db, "connections", rows, now);
|
|
5936
|
+
const claimed = result.value.parsed.meta.claimedCount;
|
|
5937
|
+
const seen = new Set(rows.map((r) => r.urn));
|
|
5938
|
+
const { removed, complete } = diffSnapshot(before, seen, claimed);
|
|
5939
|
+
if (removed.length > 0) removeUrns(db, "connections", removed);
|
|
5940
|
+
setCheckpoint(db, {
|
|
5941
|
+
source: "connections",
|
|
5942
|
+
lastSuccessfulAt: now,
|
|
5943
|
+
newestCreatedAt: null,
|
|
5944
|
+
headIds: [],
|
|
5945
|
+
// Honest: a snapshot, never a watermark.
|
|
5946
|
+
state: complete ? "ok" : "snapshot-partial"
|
|
5947
|
+
});
|
|
5948
|
+
return ok("sync", {
|
|
5949
|
+
source: "connections",
|
|
5950
|
+
added: stored.added,
|
|
5951
|
+
updated: stored.updated,
|
|
5952
|
+
removed: removed.length,
|
|
5953
|
+
claimed,
|
|
5954
|
+
complete,
|
|
5955
|
+
meta: result.value.parsed.meta,
|
|
5956
|
+
note: complete ? void 0 : `Only ${rows.length} of ${claimed} connections were retrieved, so removals could not be determined and none were applied. Raise --limit to complete the snapshot.`
|
|
5957
|
+
});
|
|
5958
|
+
}
|
|
5959
|
+
async function runSync(source, limit, force, now = Date.now()) {
|
|
5960
|
+
if (source !== "my-posts" && source !== "connections") {
|
|
5961
|
+
return err(
|
|
5962
|
+
"sync",
|
|
5963
|
+
"INVALID_INPUT",
|
|
5964
|
+
`unknown sync source '${source ?? ""}'`,
|
|
5965
|
+
"lnrelay sync my-posts | lnrelay sync connections"
|
|
5966
|
+
);
|
|
5967
|
+
}
|
|
5968
|
+
const session = loadSession();
|
|
5969
|
+
if (session.state === "corrupt") {
|
|
5970
|
+
return err("sync", "CACHE_CORRUPT", "the stored session was unreadable", LAUNCH_HINT);
|
|
5971
|
+
}
|
|
5972
|
+
if (session.state === "missing") {
|
|
5973
|
+
return err("sync", "AUTH_FAILED", "no session \u2014 run `lnrelay login` first", LAUNCH_HINT);
|
|
5974
|
+
}
|
|
5975
|
+
const engine = createEngine(session.session);
|
|
5976
|
+
try {
|
|
5977
|
+
const db = openDb(now);
|
|
5978
|
+
return source === "my-posts" ? await syncMyPosts(engine, db, limit, now) : await syncConnections(engine, db, limit, force, now);
|
|
5979
|
+
} catch (e) {
|
|
5980
|
+
if (e instanceof CacheCorrupt) {
|
|
5981
|
+
return err(
|
|
5982
|
+
"sync",
|
|
5983
|
+
"CACHE_CORRUPT",
|
|
5984
|
+
e.message,
|
|
5985
|
+
`Moved to ${e.quarantinedTo}. A corrupt cache is NOT treated as empty \u2014 that would make this sync re-enumerate everything. Inspect it, then re-run.`
|
|
5986
|
+
);
|
|
5987
|
+
}
|
|
5988
|
+
throw e;
|
|
5989
|
+
}
|
|
5150
5990
|
}
|
|
5151
5991
|
|
|
5152
5992
|
// src/entry.ts
|
|
@@ -5280,6 +6120,10 @@ async function dispatch(argv, now) {
|
|
|
5280
6120
|
num(args, "limit") ?? 25,
|
|
5281
6121
|
output(args)
|
|
5282
6122
|
);
|
|
6123
|
+
case "experience":
|
|
6124
|
+
return runExperience(bool(args, "quiet"));
|
|
6125
|
+
case "skills":
|
|
6126
|
+
return runSkills(bool(args, "quiet"));
|
|
5283
6127
|
case "scheduled":
|
|
5284
6128
|
return runScheduled(bool(args, "quiet"));
|
|
5285
6129
|
case "sync":
|
|
@@ -5363,6 +6207,40 @@ function edit(args, now, deps) {
|
|
|
5363
6207
|
}
|
|
5364
6208
|
return runEdit(target, text2, now, deps);
|
|
5365
6209
|
}
|
|
6210
|
+
function role(args, now, deps) {
|
|
6211
|
+
const [sub, target] = args.positionals;
|
|
6212
|
+
const valued = [
|
|
6213
|
+
"title",
|
|
6214
|
+
"company",
|
|
6215
|
+
"start",
|
|
6216
|
+
"end",
|
|
6217
|
+
"location",
|
|
6218
|
+
"description",
|
|
6219
|
+
"description-file"
|
|
6220
|
+
];
|
|
6221
|
+
for (const flag of valued) {
|
|
6222
|
+
if (args.flags[flag] === true) return err("role", "INVALID_INPUT", `--${flag} needs a value`);
|
|
6223
|
+
}
|
|
6224
|
+
const req = {};
|
|
6225
|
+
for (const flag of ["title", "company", "start", "end", "location", "description"]) {
|
|
6226
|
+
const v = str(args, flag);
|
|
6227
|
+
if (v !== void 0) req[flag] = v;
|
|
6228
|
+
}
|
|
6229
|
+
const file = str(args, "description-file");
|
|
6230
|
+
if (file !== void 0) {
|
|
6231
|
+
if (req.description !== void 0) {
|
|
6232
|
+
return err("role", "INVALID_INPUT", "pass --description or --description-file, not both");
|
|
6233
|
+
}
|
|
6234
|
+
try {
|
|
6235
|
+
req.description = readFileSync3(file, "utf-8").replace(/\n$/, "");
|
|
6236
|
+
} catch {
|
|
6237
|
+
return err("role", "INVALID_INPUT", `cannot read ${file}`);
|
|
6238
|
+
}
|
|
6239
|
+
}
|
|
6240
|
+
if (bool(args, "current")) req.current = true;
|
|
6241
|
+
if (bool(args, "notify")) req.notify = true;
|
|
6242
|
+
return runRole(sub, target, req, now, deps);
|
|
6243
|
+
}
|
|
5366
6244
|
function runWrite(command, args, now, deps) {
|
|
5367
6245
|
const [first, second] = args.positionals;
|
|
5368
6246
|
switch (command) {
|
|
@@ -5378,6 +6256,10 @@ function runWrite(command, args, now, deps) {
|
|
|
5378
6256
|
return runReact(first, str(args, "type") ?? "LIKE", now, deps, bool(args, "remove"));
|
|
5379
6257
|
case "delete":
|
|
5380
6258
|
return runDelete(first, now, deps, bool(args, "quiet"));
|
|
6259
|
+
case "role":
|
|
6260
|
+
return role(args, now, deps);
|
|
6261
|
+
case "skill":
|
|
6262
|
+
return runSkill(first, second, now, deps);
|
|
5381
6263
|
default:
|
|
5382
6264
|
return err(command, "NOT_IMPLEMENTED", `'${command}' has no write runner`);
|
|
5383
6265
|
}
|