linkedin-relay-mcp 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -836,13 +836,16 @@ function classifyRedirect(location) {
836
836
  }
837
837
  return fail("FETCH_FAILED", `unexpected redirect to ${location || "(none)"}`);
838
838
  }
839
+ function challengeIn(body) {
840
+ if (!CHALLENGE_MARKERS.test(body.slice(0, 4e3))) return null;
841
+ return fail("CHALLENGE_DETECTED", "a challenge page was returned with status 200", {
842
+ cooldown: "CHALLENGE_DETECTED",
843
+ hint: CHALLENGE_HINT
844
+ });
845
+ }
839
846
  function classifyBody(body) {
840
- if (CHALLENGE_MARKERS.test(body.slice(0, 4e3))) {
841
- return fail("CHALLENGE_DETECTED", "a challenge page was returned with status 200", {
842
- cooldown: "CHALLENGE_DETECTED",
843
- hint: CHALLENGE_HINT
844
- });
845
- }
847
+ const challenge = challengeIn(body);
848
+ if (challenge !== null) return challenge;
846
849
  let json;
847
850
  try {
848
851
  json = JSON.parse(body);
@@ -865,7 +868,7 @@ function classifyBody(body) {
865
868
  }
866
869
  return { outcome: "ok", retry: false, json };
867
870
  }
868
- function classify(res) {
871
+ function classify(res, opts = {}) {
869
872
  const headers2 = res.headers ?? {};
870
873
  if (res.status >= 300 && res.status < 400) {
871
874
  return classifyRedirect(headers2.location ?? "");
@@ -906,6 +909,15 @@ function classify(res) {
906
909
  return fail("FETCH_FAILED", `unexpected status ${res.status}`);
907
910
  }
908
911
  if (res.body.trim() === "") return { outcome: "ok", retry: false, json: null };
912
+ const challenge = challengeIn(res.body);
913
+ if (challenge !== null) return challenge;
914
+ if (opts.expectJson === false) {
915
+ try {
916
+ return { outcome: "ok", retry: false, json: JSON.parse(res.body) };
917
+ } catch {
918
+ return { outcome: "ok", retry: false, json: null };
919
+ }
920
+ }
909
921
  return classifyBody(res.body);
910
922
  }
911
923
  function referencesUrns(data) {
@@ -967,7 +979,8 @@ function createClient(session, deps) {
967
979
  if (raw === null) {
968
980
  return { ok: false, code: "FETCH_FAILED", message: "the request could not be completed" };
969
981
  }
970
- const classification = classify(raw);
982
+ const isRead = (spec.method ?? "GET") === "GET";
983
+ const classification = classify(raw, { expectJson: isRead });
971
984
  if (classification.cooldown !== void 0) {
972
985
  deps.saveCooldown(openCooldown(classification.cooldown, deps.now()));
973
986
  }
@@ -1790,11 +1803,13 @@ function reserve(command, now) {
1790
1803
  const attempt = spend(ledger(), "write", now);
1791
1804
  return "error" in attempt ? err(command, attempt.error.code, attempt.error.message, attempt.error.hint) : null;
1792
1805
  }
1793
- async function gateWrite(command, plan, now, deps) {
1806
+ async function gateWrite(command, plan, now, deps, opts = {}) {
1794
1807
  const outcome = await confirmWrite(plan, budgetLine(now), deps);
1795
1808
  if (!outcome.ok) return err(command, outcome.code, outcome.message, outcome.hint);
1796
- const attempt = spend(ledger(), "write", now);
1797
- if ("permit" in attempt) saveJson(cachePath("budget.json"), attempt.ledger);
1809
+ if (opts.commitSpend !== false) {
1810
+ const attempt = spend(ledger(), "write", now);
1811
+ if ("permit" in attempt) saveJson(cachePath("budget.json"), attempt.ledger);
1812
+ }
1798
1813
  return { confirmed: outcome.confirmed, payload: plan.payload };
1799
1814
  }
1800
1815
 
@@ -1873,7 +1888,9 @@ async function runDelete(urn, now = Date.now(), deps, quiet = false) {
1873
1888
  reversibility: "NONE. A deleted post is gone, with its comments and reactions.",
1874
1889
  transport: "voyager"
1875
1890
  };
1876
- const gated = await gateWrite("delete", plan, now, deps ?? terminalDeps());
1891
+ const gated = await gateWrite("delete", plan, now, deps ?? terminalDeps(), {
1892
+ commitSpend: false
1893
+ });
1877
1894
  if ("ok" in gated) return gated;
1878
1895
  const result = await deletePost(gated.confirmed, createLiveClient(session.session));
1879
1896
  return result.ok ? ok("delete", { deleted: urn, verified: post !== void 0 }) : err("delete", result.code, result.message, result.hint);
@@ -2904,6 +2921,17 @@ var REACTIONS = [
2904
2921
  "APPRECIATION",
2905
2922
  "ENTERTAINMENT"
2906
2923
  ];
2924
+ var LABELS = {
2925
+ LIKE: "Like",
2926
+ PRAISE: "Celebrate",
2927
+ EMPATHY: "Love",
2928
+ INTEREST: "Insightful",
2929
+ APPRECIATION: "Support",
2930
+ ENTERTAINMENT: "Funny"
2931
+ };
2932
+ function reactionLabel(reaction) {
2933
+ return LABELS[reaction];
2934
+ }
2907
2935
  function reactionUrl(op) {
2908
2936
  return `${SDUI_ACTION}?sduiid=com.linkedin.sdui.reactions.${op}`;
2909
2937
  }
@@ -3077,7 +3105,9 @@ function requireOauth(command, ctx) {
3077
3105
  );
3078
3106
  }
3079
3107
  async function gate(command, plan, ctx, deps) {
3080
- const gated = await gateWrite(command, plan, ctx.now, deps);
3108
+ const gated = await gateWrite(command, plan, ctx.now, deps, {
3109
+ commitSpend: ctx.transport.kind === "oauth"
3110
+ });
3081
3111
  if ("ok" in gated) return gated;
3082
3112
  return { confirmed: gated.confirmed };
3083
3113
  }
@@ -3167,9 +3197,9 @@ async function runReact(postUrn2, type, now = Date.now(), deps = terminalDeps(),
3167
3197
  summary: [
3168
3198
  authorLine(ctx.transport),
3169
3199
  `on ${postUrn2}`,
3170
- `reaction ${remove ? `${reaction} (REMOVING)` : reaction}`
3200
+ `reaction ${reaction} \u2014 shows as "${reactionLabel(reaction)}"${remove ? " (REMOVING)" : ""}`
3171
3201
  ],
3172
- reversibility: remove ? "you can react again; the author may have been notified the first time" : "removable with `lnrelay react <urn> --remove`; the author is notified immediately",
3202
+ 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`,
3173
3203
  transport: "voyager"
3174
3204
  };
3175
3205
  const gated = await gate("react", plan, ctx, deps);