ilml-plugin-linkedin 1.20.11 → 1.20.13

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/readPost.mjs CHANGED
@@ -2,17 +2,17 @@ var Ie=Object.defineProperty;var _e=(e,o)=>()=>(e&&(o=e(e=0)),o);var Te=(e,o)=>{
2
2
  [FATAL] No iLiveMyLife token found.`),console.error(" The bot uses Lifebot AI to decide which jobs to apply for"),console.error(` and how to fill application forms. It cannot work without it.
3
3
  `),console.error(" Easiest way:"),console.error(" 1. npm install -g @ilivemylife/graph-sdk"),console.error(` 2. ilml login your@email.com yourpassword
4
4
  `),console.error(` Or add ILML_TOKEN=... to .env
5
- `),process.exit(1));Ge=He({token:Se})});import"dotenv/config";import Je from"puppeteer";import x from"fs";import P from"path";var Ee="cookies.json";function K(){let e=process.env.ILML_SCOPE_DIR;return e?P.join(e,"plugins-state","linkedin","cookies.json"):Ee}function be(){let e=K(),o=P.dirname(e);return o&&o!=="."&&!x.existsSync(o)&&x.mkdirSync(o,{recursive:!0}),e}function z(e){let o=be();return x.writeFileSync(o,JSON.stringify(e)),o}function V(){let e=K();if(!x.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let o;try{o=x.readFileSync(e,"utf-8")}catch(i){throw new Error(`Failed to read cookies at ${e}: ${i.message}. Run: ilml linkedin login`)}let t;try{t=JSON.parse(o)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(t)||t.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return t}function Q(){return x.existsSync(K())}function $e(){let e=process.env.ILML_SCOPE_DIR;return e?P.join(e,"plugins-state","linkedin"):"."}function ee(e){let o=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(o)?o:"default"}function Le(){let e=process.env.MY_LINKEDIN_URL,o=e&&e.match(/\/in\/([^/?#]+)/);return o&&o[1]?ee(o[1]):"default"}function te(e){let o=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(o)return x.existsSync(o)||x.mkdirSync(o,{recursive:!0}),P.resolve(o);let t=ee(e||Le()),i=P.join($e(),"chrome-profile",t);return x.existsSync(i)||x.mkdirSync(i,{recursive:!0}),P.resolve(i)}var oe=".ilml-seeded";function ne(e){return!x.existsSync(P.join(e,oe))}function se(e){try{x.writeFileSync(P.join(e,oe),new Date().toISOString())}catch{}}function re(e){let o=0;for(let t of["SingletonLock","SingletonCookie","SingletonSocket"])try{x.rmSync(P.join(e,t),{force:!0}),o++}catch{}return o}async function Oe(e,o,{timeout:t=45e3,poll:i=1e3,label:l="page"}={}){let r=Date.now();for(;Date.now()-r<t;){try{if(await e.evaluate(h=>!!document.querySelector(h),o)){let h=Date.now()-r;return h>6e3&&console.log(` (waited ${Math.round(h/1e3)}s for LinkedIn to finish loading ${l})`),!0}}catch{}await new Promise(d=>setTimeout(d,i))}return!1}var ae=/\/authwall|\/login|\/checkpoint|\/uas\/login/;function De(e){return ae.test(e||"")}async function Re(e,{credentialWaitMs:o=36e4,label:t="page"}={}){console.log(` \u26A0 Auth wall on ${t} \u2014 attempting self-recovery (cookies may just need a refresh)...`);try{await e.goto("https://www.linkedin.com/feed/",{waitUntil:"domcontentloaded",timeout:6e4})}catch{}let i=!!(process.stdin&&process.stdin.isTTY),l=i?o:Math.min(o,45e3),r=Date.now(),d=!1;for(;Date.now()-r<l;){let n="wait";try{n=await e.evaluate(p=>!new RegExp(p).test(location.href)&&document.querySelector("#global-nav, nav.global-nav")?"in":document.querySelector('input#username, input[name="session_key"], input#password')?"creds":"wait",ae.source)}catch{}if(n==="in"){try{let p=await e.cookies();if(Array.isArray(p)&&p.some(k=>k.name==="li_at")){let k=z(p);console.log(` \u2713 Session recovered \u2014 re-saved ${p.length} cookies (${k}).`)}else console.log(" \u2713 Session recovered (kept existing cookie snapshot \u2014 refreshed set had no li_at).")}catch(p){console.log(` \u2713 Session recovered (cookie re-save skipped: ${p.message}).`)}return!0}if(n==="creds"){if(!i){let p=new Error(`Session expired (${t}) \u2014 credentials required and no interactive terminal. Run: ilml linkedin login`);throw p.code="SESSION_EXPIRED",p}d||(d=!0,console.log(`
5
+ `),process.exit(1));Ge=He({token:Se})});import"dotenv/config";import Je from"puppeteer";import x from"fs";import P from"path";var be="cookies.json";function K(){let e=process.env.ILML_SCOPE_DIR;return e?P.join(e,"plugins-state","linkedin","cookies.json"):be}function Ee(){let e=K(),o=P.dirname(e);return o&&o!=="."&&!x.existsSync(o)&&x.mkdirSync(o,{recursive:!0}),e}function z(e){let o=Ee();return x.writeFileSync(o,JSON.stringify(e)),o}function V(){let e=K();if(!x.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let o;try{o=x.readFileSync(e,"utf-8")}catch(i){throw new Error(`Failed to read cookies at ${e}: ${i.message}. Run: ilml linkedin login`)}let t;try{t=JSON.parse(o)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(t)||t.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return t}function Q(){return x.existsSync(K())}function $e(){let e=process.env.ILML_SCOPE_DIR;return e?P.join(e,"plugins-state","linkedin"):"."}function ee(e){let o=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(o)?o:"default"}function Le(){let e=process.env.MY_LINKEDIN_URL,o=e&&e.match(/\/in\/([^/?#]+)/);return o&&o[1]?ee(o[1]):"default"}function te(e){let o=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(o)return x.existsSync(o)||x.mkdirSync(o,{recursive:!0}),P.resolve(o);let t=ee(e||Le()),i=P.join($e(),"chrome-profile",t);return x.existsSync(i)||x.mkdirSync(i,{recursive:!0}),P.resolve(i)}var oe=".ilml-seeded";function ne(e){return!x.existsSync(P.join(e,oe))}function se(e){try{x.writeFileSync(P.join(e,oe),new Date().toISOString())}catch{}}function re(e){let o=0;for(let t of["SingletonLock","SingletonCookie","SingletonSocket"])try{x.rmSync(P.join(e,t),{force:!0}),o++}catch{}return o}async function Oe(e,o,{timeout:t=45e3,poll:i=1e3,label:u="page"}={}){let r=Date.now();for(;Date.now()-r<t;){try{if(await e.evaluate(h=>!!document.querySelector(h),o)){let h=Date.now()-r;return h>6e3&&console.log(` (waited ${Math.round(h/1e3)}s for LinkedIn to finish loading ${u})`),!0}}catch{}await new Promise(c=>setTimeout(c,i))}return!1}var ae=/\/authwall|\/login|\/checkpoint|\/uas\/login/;function De(e){return ae.test(e||"")}async function Re(e,{credentialWaitMs:o=36e4,label:t="page"}={}){console.log(` \u26A0 Auth wall on ${t} \u2014 attempting self-recovery (cookies may just need a refresh)...`);try{await e.goto("https://www.linkedin.com/feed/",{waitUntil:"domcontentloaded",timeout:6e4})}catch{}let i=!!(process.stdin&&process.stdin.isTTY),u=i?o:Math.min(o,45e3),r=Date.now(),c=!1;for(;Date.now()-r<u;){let n="wait";try{n=await e.evaluate(p=>!new RegExp(p).test(location.href)&&document.querySelector("#global-nav, nav.global-nav")?"in":document.querySelector('input#username, input[name="session_key"], input#password')?"creds":"wait",ae.source)}catch{}if(n==="in"){try{let p=await e.cookies();if(Array.isArray(p)&&p.some(k=>k.name==="li_at")){let k=z(p);console.log(` \u2713 Session recovered \u2014 re-saved ${p.length} cookies (${k}).`)}else console.log(" \u2713 Session recovered (kept existing cookie snapshot \u2014 refreshed set had no li_at).")}catch(p){console.log(` \u2713 Session recovered (cookie re-save skipped: ${p.message}).`)}return!0}if(n==="creds"){if(!i){let p=new Error(`Session expired (${t}) \u2014 credentials required and no interactive terminal. Run: ilml linkedin login`);throw p.code="SESSION_EXPIRED",p}c||(c=!0,console.log(`
6
6
  \u26A0 LinkedIn is asking for your login + password (cookies not enough this time).`),console.log(" \u2192 Sign in MANUALLY in the browser window that is already open."),console.log(` I will wait and resume automatically \u2014 do NOT close the window or re-run the command.
7
- `))}await new Promise(p=>setTimeout(p,2500))}let h=new Error(`Session expired (${t}) \u2014 not signed in within the wait window. Run: ilml linkedin login`);throw h.code="SESSION_EXPIRED",h}async function ie(e,{readySelector:o,label:t="page",timeout:i=45e3}={}){let l=await Oe(e,o,{timeout:i,label:t});if(!l&&De(e.url())){let r=new Error(`Session expired (${t}) \u2014 redirected to login. Run: ilml linkedin login`);throw r.code="SESSION_EXPIRED",r}return l}async function ce(e,o,{readySelector:t,label:i="page",timeout:l=45e3,gotoTimeout:r=6e4,autoRecover:d=!0}={}){await e.goto(o,{waitUntil:"domcontentloaded",timeout:r});try{return await ie(e,{readySelector:t,label:i,timeout:l})}catch(h){if(d&&h.code==="SESSION_EXPIRED"){await Re(e,{label:i});try{await e.goto(o,{waitUntil:"domcontentloaded",timeout:r})}catch{}return await ie(e,{readySelector:t,label:i,timeout:l})}throw h}}var W=e=>new Promise(o=>setTimeout(o,e));function le(e){return e?e.split("?")[0].split("#")[0]:""}async function ue(e,o,t={}){let i=t.commentPasses??4,l=t.skipComments??!1,r=Number.isFinite(t.commentsMax)?t.commentsMax:1/0;try{await ce(e,o,{readySelector:"main, .scaffold-layout__main",label:"post",timeout:45e3})}catch(s){if(s.code==="SESSION_EXPIRED")return{authWall:!0};throw s}if(await W(1e3),await e.evaluate(()=>/\/login|\/authwall|\/checkpoint|\/uas\//.test(location.pathname)||!!document.querySelector('input[name="session_key"]')))return{authWall:!0};let h=l?2:6;for(let s=0;s<h;s++)await e.evaluate(()=>window.scrollBy(0,1200)),await W(l?500:1e3);if(l)await e.evaluate(()=>{for(let s of document.querySelectorAll("button")){let g=`${s.innerText||""} ${s.getAttribute("aria-label")||""}`;if(/^(see more|…more|show more)$/i.test(g.trim()))try{s.click()}catch{}}}),await W(500);else for(let s=0;s<i;s++){let g=await e.evaluate(()=>{let c=0;for(let m of document.querySelectorAll("button")){let S=`${m.innerText||""} ${m.getAttribute("aria-label")||""}`;if(/see more|…more|show more|load more comments|more comments|previous replies|more replies|показать ещё|ещё|загрузить ещё|показать предыдущие/i.test(S))try{m.click(),c++}catch{}}return c});if(await W(1800),!g)break}let n=await e.evaluate(()=>{let s=(w,y)=>{for(let I of y){let C=w&&w.querySelector(I);if(C&&(C.innerText||"").trim())return C.innerText.trim()}return""},g=(w,y)=>{for(let I of y){let C=w&&w.querySelector(I);if(C&&C.href)return C.href}return""},c=document.querySelector("main")||document.body,m=document.querySelector(".fie-impression-container")||document.querySelector(".feed-shared-update-v2")||c,S={name:s(m,['.update-components-actor__title span[aria-hidden="true"]','.update-components-actor__name span[aria-hidden="true"]',".update-components-actor__title",".update-components-actor__name"]),profileUrl:g(m,['.update-components-actor__container a[href*="/in/"]','.update-components-actor__meta a[href*="/in/"]','a.app-aware-link[href*="/in/"]']),headline:s(m,[".update-components-actor__description"])},$=s(m,[".update-components-update-v2__commentary",".feed-shared-update-v2__description",".update-components-text"]),F=s(m,['.update-components-actor__sub-description span[aria-hidden="true"]',".update-components-actor__sub-description"]),N=s(document,[".social-details-social-counts__reactions-count",".social-details-social-counts__social-proof-fallback-number"]),U=s(document,['button[aria-label*="comment" i] span',".social-details-social-counts__comments"]),A=s(document,['button[aria-label*="repost" i] span',".social-details-social-counts__reposts",".social-details-social-counts__shares"]),f=m.querySelector(".update-components-update-v2__commentary")||m.querySelector(".update-components-text")||m,L=Array.from(f?.querySelectorAll?.('a[href*="/in/"], a[href*="/company/"]')||[]),b=[],j=new Set;for(let w of L){let y=(w.href||"").split("?")[0].replace(/\/$/,"");if(!y||j.has(y))continue;j.add(y);let I=(w.textContent||"").trim(),C=y.includes("/company/")?"company":"person";b.push({kind:C,url:y,label:I||null})}let q=Array.from(new Set((($||"")+" "+(f?.textContent||"")).match(/#[\p{L}\p{N}_]{2,40}/gu)||[])),J={hasImage:!!m.querySelector(".update-components-image, img.feed-shared-image__image"),hasVideo:!!m.querySelector("video, .update-components-video, .feed-shared-update-v2__content video"),hasArticle:!!m.querySelector(".update-components-article, .feed-shared-article"),hasDocument:!!m.querySelector(".feed-shared-document, .update-components-document"),hasPoll:!!m.querySelector(".update-components-poll, .feed-shared-poll")},H=document.querySelectorAll("article.comments-comment-entity, .comments-comment-entity, .comments-comment-item"),u=[];for(let w of H){let y=s(w,[".comments-comment-meta__description-title",'.comments-post-meta__name-text span[aria-hidden="true"]',".comments-post-meta__name-text"]),I=s(w,[".comments-comment-item__main-content",".comments-comment-entity__content .update-components-text",".comments-comment-entity__content",".update-components-text"]);!y&&!I||u.push({author:{name:y,profileUrl:g(w,['a[href*="/in/"]']),headline:s(w,[".comments-comment-meta__description-subtitle",".comments-post-meta__headline"])},text:I})}let B=new Set,Ae=u.filter(w=>{let y=`${w.author.name}|${w.text.slice(0,80)}`;return B.has(y)?!1:(B.add(y),!0)});return{url:location.href,author:S,text:$,postedAt:F,reactions:N,commentCount:U,repostCount:A,hashtags:q,mentions:b,media:J,comments:Ae,fullText:(c.innerText||"").replace(/\n{3,}/g,`
7
+ `))}await new Promise(p=>setTimeout(p,2500))}let h=new Error(`Session expired (${t}) \u2014 not signed in within the wait window. Run: ilml linkedin login`);throw h.code="SESSION_EXPIRED",h}async function ie(e,{readySelector:o,label:t="page",timeout:i=45e3}={}){let u=await Oe(e,o,{timeout:i,label:t});if(!u&&De(e.url())){let r=new Error(`Session expired (${t}) \u2014 redirected to login. Run: ilml linkedin login`);throw r.code="SESSION_EXPIRED",r}return u}async function ce(e,o,{readySelector:t,label:i="page",timeout:u=45e3,gotoTimeout:r=6e4,autoRecover:c=!0}={}){await e.goto(o,{waitUntil:"domcontentloaded",timeout:r});try{return await ie(e,{readySelector:t,label:i,timeout:u})}catch(h){if(c&&h.code==="SESSION_EXPIRED"){await Re(e,{label:i});try{await e.goto(o,{waitUntil:"domcontentloaded",timeout:r})}catch{}return await ie(e,{readySelector:t,label:i,timeout:u})}throw h}}var W=e=>new Promise(o=>setTimeout(o,e));function le(e){return e?e.split("?")[0].split("#")[0]:""}async function ue(e,o,t={}){let i=t.commentPasses??4,u=t.skipComments??!1,r=Number.isFinite(t.commentsMax)?t.commentsMax:1/0;try{await ce(e,o,{readySelector:"#global-nav, .scaffold-layout__main",label:"post",timeout:45e3})}catch(s){if(s.code==="SESSION_EXPIRED")return{authWall:!0};throw s}await W(1e3);let c=!1;try{c=await e.evaluate(()=>/\/login|\/authwall|\/checkpoint|\/uas\//.test(location.pathname)||!!document.querySelector('input[name="session_key"]'))}catch{}if(c)return{authWall:!0};let h=u?2:6;for(let s=0;s<h;s++)await e.evaluate(()=>window.scrollBy(0,1200)),await W(u?500:1e3);if(u)await e.evaluate(()=>{for(let s of document.querySelectorAll("button")){let g=`${s.innerText||""} ${s.getAttribute("aria-label")||""}`;if(/^(see more|…more|show more)$/i.test(g.trim()))try{s.click()}catch{}}}),await W(500);else for(let s=0;s<i;s++){let g=await e.evaluate(()=>{let l=0;for(let m of document.querySelectorAll("button")){let S=`${m.innerText||""} ${m.getAttribute("aria-label")||""}`;if(/see more|…more|show more|load more comments|more comments|previous replies|more replies|показать ещё|ещё|загрузить ещё|показать предыдущие/i.test(S))try{m.click(),l++}catch{}}return l});if(await W(1800),!g)break}let n=await e.evaluate(()=>{let s=(w,y)=>{for(let I of y){let C=w&&w.querySelector(I);if(C&&(C.innerText||"").trim())return C.innerText.trim()}return""},g=(w,y)=>{for(let I of y){let C=w&&w.querySelector(I);if(C&&C.href)return C.href}return""},l=document.querySelector("main")||document.body,m=document.querySelector(".fie-impression-container")||document.querySelector(".feed-shared-update-v2")||l,S={name:s(m,['.update-components-actor__title span[aria-hidden="true"]','.update-components-actor__name span[aria-hidden="true"]',".update-components-actor__title",".update-components-actor__name"]),profileUrl:g(m,['.update-components-actor__container a[href*="/in/"]','.update-components-actor__meta a[href*="/in/"]','a.app-aware-link[href*="/in/"]']),headline:s(m,[".update-components-actor__description"])},$=s(m,[".update-components-update-v2__commentary",".feed-shared-update-v2__description",".update-components-text"]),F=s(m,['.update-components-actor__sub-description span[aria-hidden="true"]',".update-components-actor__sub-description"]),N=s(document,[".social-details-social-counts__reactions-count",".social-details-social-counts__social-proof-fallback-number"]),U=s(document,['button[aria-label*="comment" i] span',".social-details-social-counts__comments"]),A=s(document,['button[aria-label*="repost" i] span',".social-details-social-counts__reposts",".social-details-social-counts__shares"]),f=m.querySelector(".update-components-update-v2__commentary")||m.querySelector(".update-components-text")||m,L=Array.from(f?.querySelectorAll?.('a[href*="/in/"], a[href*="/company/"]')||[]),E=[],j=new Set;for(let w of L){let y=(w.href||"").split("?")[0].replace(/\/$/,"");if(!y||j.has(y))continue;j.add(y);let I=(w.textContent||"").trim(),C=y.includes("/company/")?"company":"person";E.push({kind:C,url:y,label:I||null})}let q=Array.from(new Set((($||"")+" "+(f?.textContent||"")).match(/#[\p{L}\p{N}_]{2,40}/gu)||[])),J={hasImage:!!m.querySelector(".update-components-image, img.feed-shared-image__image"),hasVideo:!!m.querySelector("video, .update-components-video, .feed-shared-update-v2__content video"),hasArticle:!!m.querySelector(".update-components-article, .feed-shared-article"),hasDocument:!!m.querySelector(".feed-shared-document, .update-components-document"),hasPoll:!!m.querySelector(".update-components-poll, .feed-shared-poll")},H=document.querySelectorAll("article.comments-comment-entity, .comments-comment-entity, .comments-comment-item"),d=[];for(let w of H){let y=s(w,[".comments-comment-meta__description-title",'.comments-post-meta__name-text span[aria-hidden="true"]',".comments-post-meta__name-text"]),I=s(w,[".comments-comment-item__main-content",".comments-comment-entity__content .update-components-text",".comments-comment-entity__content",".update-components-text"]);!y&&!I||d.push({author:{name:y,profileUrl:g(w,['a[href*="/in/"]']),headline:s(w,[".comments-comment-meta__description-subtitle",".comments-post-meta__headline"])},text:I})}let B=new Set,Ae=d.filter(w=>{let y=`${w.author.name}|${w.text.slice(0,80)}`;return B.has(y)?!1:(B.add(y),!0)});return{url:location.href,author:S,text:$,postedAt:F,reactions:N,commentCount:U,repostCount:A,hashtags:q,mentions:E,media:J,comments:Ae,fullText:(l.innerText||"").replace(/\n{3,}/g,`
8
8
 
9
- `)}});l?(n.comments=[],n.commentsTruncated=!0,n.commentsTruncatedReason="skipComments"):Number.isFinite(r)&&n.comments.length>r?(n.commentsTruncated=!0,n.commentsTruncatedReason=`commentsMax=${r}`,n.commentsTruncatedOriginalCount=n.comments.length,n.comments=n.comments.slice(0,r)):n.commentsTruncated=!1,n.author.profileUrl=le(n.author.profileUrl),n.comments=n.comments.map(s=>({...s,author:{...s.author,profileUrl:le(s.author.profileUrl)}}));let p=n.fullText||"";if(!n.author.name){let s=p.match(/\n\s*Feed post\s*\n+\s*([^\n]+)/i);s&&(n.author.name=s[1].trim())}if(!n.reactions){let s=p.match(/([\d,]+)\s+reactions?/i);s&&(n.reactions=s[1])}if(!n.commentCount){let s=p.match(/([\d,]+)\s+comments?/i);s&&(n.commentCount=s[1])}let a=p,k=a.search(/\n\s*Feed post\s*\n/i);if(k>=0&&(a=a.slice(k).replace(/^\s*Feed post\s*\n/i,"")),a=a.replace(/\n\s*About\s*\n+\s*Accessibility[\s\S]*$/i,"").replace(/\n\s*LinkedIn Corporation ©[\s\S]*$/i,"").trim(),n.cleanText=a,n.cleanText){let s=n.cleanText.split(`
10
- `).map(c=>c.trim()),g=s.findIndex(c=>/^\d+\s*[mhdwy]\s*•/i.test(c));if(g>=0&&(n.postedAt||(n.postedAt=s[g].replace(/\s*•\s*$/,"").trim()),!n.text)){let c=[];for(let m=g+1;m<s.length;m++){let S=s[m];if(/^(Most relevant|Top comments|Comments|All comments|\d+ comments?)\b/i.test(S)||/^[\d,]+$/.test(S)&&/^[\d,]+$/.test(s[m+1]||""))break;c.push(S)}n.text=c.join(`
9
+ `)}});u?(n.comments=[],n.commentsTruncated=!0,n.commentsTruncatedReason="skipComments"):Number.isFinite(r)&&n.comments.length>r?(n.commentsTruncated=!0,n.commentsTruncatedReason=`commentsMax=${r}`,n.commentsTruncatedOriginalCount=n.comments.length,n.comments=n.comments.slice(0,r)):n.commentsTruncated=!1,n.author.profileUrl=le(n.author.profileUrl),n.comments=n.comments.map(s=>({...s,author:{...s.author,profileUrl:le(s.author.profileUrl)}}));let p=n.fullText||"";if(!n.author.name){let s=p.match(/\n\s*Feed post\s*\n+\s*([^\n]+)/i);s&&(n.author.name=s[1].trim())}if(!n.reactions){let s=p.match(/([\d,]+)\s+reactions?/i);s&&(n.reactions=s[1])}if(!n.commentCount){let s=p.match(/([\d,]+)\s+comments?/i);s&&(n.commentCount=s[1])}let a=p,k=a.search(/\n\s*Feed post\s*\n/i);if(k>=0&&(a=a.slice(k).replace(/^\s*Feed post\s*\n/i,"")),a=a.replace(/\n\s*About\s*\n+\s*Accessibility[\s\S]*$/i,"").replace(/\n\s*LinkedIn Corporation ©[\s\S]*$/i,"").trim(),n.cleanText=a,n.cleanText){let s=n.cleanText.split(`
10
+ `).map(l=>l.trim()),g=s.findIndex(l=>/^\d+\s*[mhdwy]\s*•/i.test(l));if(g>=0&&(n.postedAt||(n.postedAt=s[g].replace(/\s*•\s*$/,"").trim()),!n.text)){let l=[];for(let m=g+1;m<s.length;m++){let S=s[m];if(/^(Most relevant|Top comments|Comments|All comments|\d+ comments?)\b/i.test(S)||/^[\d,]+$/.test(S)&&/^[\d,]+$/.test(s[m+1]||""))break;l.push(S)}n.text=l.join(`
11
11
  `).replace(/\n{3,}/g,`
12
12
 
13
- `).trim()}}if(!l&&n.comments.length===0&&n.cleanText){let s=n.cleanText.split(`
14
- `).map(c=>c.trim()),g=s.findIndex(c=>/^(Most relevant|Top comments|Recent comments)$/i.test(c));if(g>=0){let c=s.slice(g+1),m=[],S=[];for(let f of c){if(/^\d+\s+reactions?/i.test(f)){S.length>0&&m.push(S),S=[];continue}S.push(f)}S.length>0&&m.push(S);let $=f=>/Premium Profile|Verified Profile/i.test(f),F=f=>/[·•]\s*\d+(?:st|nd|rd|th)\+?/i.test(f),N=f=>/^\d+$/.test(f),U=f=>/^(Reactions|Reply|Like|Author|See translation|Show \d+)$/i.test(f),A=[];for(let f of m){let L=f.findIndex(u=>u==="Follow");if(L<0)continue;let b=(f.find(u=>u&&!$(u)&&!F(u)&&!N(u)&&!U(u))||"").trim(),j=f.find(u=>/^\d+[hmsdwy]$/.test(u))||"",q=f.slice(0,L).filter(u=>u&&u!==b&&u!==j&&!$(u)&&!F(u)&&!N(u)&&!U(u));q.sort((u,B)=>B.length-u.length);let J=q[0]||"",H=f.slice(L+1).filter(u=>u&&u!=="Reply"&&u!=="Like"&&u!=="Reactions").join(`
15
- `).trim();b&&H&&A.push({author:{name:b,headline:J,profileUrl:""},text:H})}if(A.length>0){let f=Number.isFinite(r)?A.slice(0,r):A;n.comments=f,n.commentsFromCleanTextFallback=!0,f.length<A.length&&(n.commentsTruncated=!0,n.commentsTruncatedReason=`commentsMax=${r}`,n.commentsTruncatedOriginalCount=A.length)}}}if(n.text&&Array.isArray(n.mentions)&&n.mentions.length>0){let s=n.text.toLowerCase(),g=n.mentions.filter(c=>c.label?s.includes(c.label.toLowerCase()):!1);n.mentionsFilteredFromDOM=n.mentions.length-g.length,n.mentions=g}let M=o.match(/(?:activity-|share-)(\d{6,})/);return n.urn=M?M[1]:"",n}import Y from"fs";import Me from"path";var Fe={headless:!1,defaultViewport:null,protocolTimeout:3e5},D=new Set,de=!1;async function G(){let e=[...D].map(o=>{try{return Promise.resolve(o.close()).catch(()=>{})}catch{return Promise.resolve()}});D.clear(),await Promise.race([Promise.all(e),new Promise(o=>setTimeout(o,5e3))])}function Ne(){if(de)return;de=!0;let e=o=>async()=>{await G(),process.exit(o)};process.once("SIGINT",e(130)),process.once("SIGTERM",e(143)),process.once("SIGHUP",e(129)),process.once("uncaughtException",async o=>{await G(),console.error(o&&o.stack||o),process.exit(1)}),process.once("unhandledRejection",async o=>{await G(),console.error(o),process.exit(1)}),process.stdout.on("error",async o=>{o&&o.code==="EPIPE"&&(await G(),process.exit(0))}),process.on("exit",()=>{for(let o of D)try{let t=o.process&&o.process();t&&t.kill("SIGKILL")}catch{}})}function X(e){return Me.join(e,".ilml-browser-session.json")}function he(e,o={}){try{Y.writeFileSync(X(e),JSON.stringify({ownerPid:process.pid,startedAt:Date.now(),...o}))}catch{}}function Ue(e,o){try{let t=o.wsEndpoint&&o.wsEndpoint();he(e,t?{wsEndpoint:t}:{})}catch{}}function je(e){let o=ge(e);o&&o.ownerPid===process.pid&&O(e)}function O(e){try{Y.rmSync(X(e),{force:!0})}catch{}}function ge(e){try{return JSON.parse(Y.readFileSync(X(e),"utf-8"))}catch{return null}}function me(e){if(!e||e===process.pid)return!0;try{return process.kill(e,0),!0}catch(o){return!o||o.code!=="ESRCH"}}function pe(e,o,t){let i,l=new Promise(d=>{i=setTimeout(()=>d(t),o)}),r=Promise.resolve(e).then(d=>(clearTimeout(i),d),d=>{throw clearTimeout(i),d});return Promise.race([r,l])}async function fe(e,o,{probeTimeoutMs:t=4e3}={}){let i=ge(o);if(!i)return"free";if(!i.wsEndpoint)return i.ownerPid&&i.ownerPid!==process.pid&&me(i.ownerPid)?"live":(O(o),"free");let l=Symbol("timeout"),r=e.connect({browserWSEndpoint:i.wsEndpoint,defaultViewport:null}).catch(()=>null),d=await pe(r,t,l);if(d===l)return r.then(n=>{if(n)try{n.disconnect()}catch{}}),"live";if(!d)return O(o),"free";if(me(i.ownerPid)){try{d.disconnect()}catch{}return"live"}if(console.log(" (recovered an orphaned automation browser from a previous run \u2014 closing it)"),await pe(d.close().then(()=>!0).catch(()=>!1),t,!1))return O(o),"free";try{d.disconnect()}catch{}return"live"}function qe(e,o){e&&(Ne(),D.add(e),e.on("disconnected",()=>{D.delete(e),o&&O(o)}))}async function we(e,o={}){let t=te(),i={...Fe,...o,userDataDir:t},l=`Could not open the LinkedIn automation Chrome profile at ${t}. Another LinkedIn automation command is already running (or its window is still open) \u2014 wait for it to finish or close that window, then retry.`;if(await fe(e,t)==="live")throw new Error(l);he(t);let r;try{r=await e.launch(i)}catch{if(await fe(e,t)==="live")throw new Error(l);re(t);try{r=await e.launch(i)}catch(h){throw je(t),new Error(`Could not open the LinkedIn automation Chrome profile at ${t}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${h.message})`)}}return qe(r,t),Ue(t,r),{browser:r,profileDir:t,needsSeed:ne(t)}}async function ye(e,o){if(!o||!o.needsSeed)return!1;if(!Q())return console.warn(" \u26A0 No saved LinkedIn session found. If this command comes back empty or redirects to login, run: ilml linkedin login"),!1;try{return await e.setCookie(...V()),se(o.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var _=process.argv.slice(2),Ke=_.includes("--help")||_.includes("-h"),Pe=_.includes("--json"),R=_.find(e=>e.startsWith("--save-to-graph="))?.split("=")[1]||null,Z=_.find(e=>e.startsWith("--out="))?.split("=")[1]||null,Ye=_.includes("--no-comments"),Ce=_.find(e=>e.startsWith("--comments-max="))?.split("=")[1],Xe=Ce!=null?parseInt(Ce,10):null,E=_.find(e=>e.startsWith("http")),v=Pe?(...e)=>console.error(...e):(...e)=>console.log(...e);function ve(){console.log(`
13
+ `).trim()}}if(!u&&n.comments.length===0&&n.cleanText){let s=n.cleanText.split(`
14
+ `).map(l=>l.trim()),g=s.findIndex(l=>/^(Most relevant|Top comments|Recent comments)$/i.test(l));if(g>=0){let l=s.slice(g+1),m=[],S=[];for(let f of l){if(/^\d+\s+reactions?/i.test(f)){S.length>0&&m.push(S),S=[];continue}S.push(f)}S.length>0&&m.push(S);let $=f=>/Premium Profile|Verified Profile/i.test(f),F=f=>/[·•]\s*\d+(?:st|nd|rd|th)\+?/i.test(f),N=f=>/^\d+$/.test(f),U=f=>/^(Reactions|Reply|Like|Author|See translation|Show \d+)$/i.test(f),A=[];for(let f of m){let L=f.findIndex(d=>d==="Follow");if(L<0)continue;let E=(f.find(d=>d&&!$(d)&&!F(d)&&!N(d)&&!U(d))||"").trim(),j=f.find(d=>/^\d+[hmsdwy]$/.test(d))||"",q=f.slice(0,L).filter(d=>d&&d!==E&&d!==j&&!$(d)&&!F(d)&&!N(d)&&!U(d));q.sort((d,B)=>B.length-d.length);let J=q[0]||"",H=f.slice(L+1).filter(d=>d&&d!=="Reply"&&d!=="Like"&&d!=="Reactions").join(`
15
+ `).trim();E&&H&&A.push({author:{name:E,headline:J,profileUrl:""},text:H})}if(A.length>0){let f=Number.isFinite(r)?A.slice(0,r):A;n.comments=f,n.commentsFromCleanTextFallback=!0,f.length<A.length&&(n.commentsTruncated=!0,n.commentsTruncatedReason=`commentsMax=${r}`,n.commentsTruncatedOriginalCount=A.length)}}}if(n.text&&Array.isArray(n.mentions)&&n.mentions.length>0){let s=n.text.toLowerCase(),g=n.mentions.filter(l=>l.label?s.includes(l.label.toLowerCase()):!1);n.mentionsFilteredFromDOM=n.mentions.length-g.length,n.mentions=g}let M=o.match(/(?:activity-|share-)(\d{6,})/);return n.urn=M?M[1]:"",n}import Y from"fs";import Me from"path";var Fe={headless:!1,defaultViewport:null,protocolTimeout:3e5},D=new Set,de=!1;async function G(){let e=[...D].map(o=>{try{return Promise.resolve(o.close()).catch(()=>{})}catch{return Promise.resolve()}});D.clear(),await Promise.race([Promise.all(e),new Promise(o=>setTimeout(o,5e3))])}function Ne(){if(de)return;de=!0;let e=o=>async()=>{await G(),process.exit(o)};process.once("SIGINT",e(130)),process.once("SIGTERM",e(143)),process.once("SIGHUP",e(129)),process.once("uncaughtException",async o=>{await G(),console.error(o&&o.stack||o),process.exit(1)}),process.once("unhandledRejection",async o=>{await G(),console.error(o),process.exit(1)}),process.stdout.on("error",async o=>{o&&o.code==="EPIPE"&&(await G(),process.exit(0))}),process.on("exit",()=>{for(let o of D)try{let t=o.process&&o.process();t&&t.kill("SIGKILL")}catch{}})}function X(e){return Me.join(e,".ilml-browser-session.json")}function he(e,o={}){try{Y.writeFileSync(X(e),JSON.stringify({ownerPid:process.pid,startedAt:Date.now(),...o}))}catch{}}function Ue(e,o){try{let t=o.wsEndpoint&&o.wsEndpoint();he(e,t?{wsEndpoint:t}:{})}catch{}}function je(e){let o=ge(e);o&&o.ownerPid===process.pid&&O(e)}function O(e){try{Y.rmSync(X(e),{force:!0})}catch{}}function ge(e){try{return JSON.parse(Y.readFileSync(X(e),"utf-8"))}catch{return null}}function me(e){if(!e||e===process.pid)return!0;try{return process.kill(e,0),!0}catch(o){return!o||o.code!=="ESRCH"}}function pe(e,o,t){let i,u=new Promise(c=>{i=setTimeout(()=>c(t),o)}),r=Promise.resolve(e).then(c=>(clearTimeout(i),c),c=>{throw clearTimeout(i),c});return Promise.race([r,u])}async function fe(e,o,{probeTimeoutMs:t=4e3}={}){let i=ge(o);if(!i)return"free";if(!i.wsEndpoint)return i.ownerPid&&i.ownerPid!==process.pid&&me(i.ownerPid)?"live":(O(o),"free");let u=Symbol("timeout"),r=e.connect({browserWSEndpoint:i.wsEndpoint,defaultViewport:null}).catch(()=>null),c=await pe(r,t,u);if(c===u)return r.then(n=>{if(n)try{n.disconnect()}catch{}}),"live";if(!c)return O(o),"free";if(me(i.ownerPid)){try{c.disconnect()}catch{}return"live"}if(console.log(" (recovered an orphaned automation browser from a previous run \u2014 closing it)"),await pe(c.close().then(()=>!0).catch(()=>!1),t,!1))return O(o),"free";try{c.disconnect()}catch{}return"live"}function qe(e,o){e&&(Ne(),D.add(e),e.on("disconnected",()=>{D.delete(e),o&&O(o)}))}async function we(e,o={}){let t=te(),i={...Fe,...o,userDataDir:t},u=`Could not open the LinkedIn automation Chrome profile at ${t}. Another LinkedIn automation command is already running (or its window is still open) \u2014 wait for it to finish or close that window, then retry.`;if(await fe(e,t)==="live")throw new Error(u);he(t);let r;try{r=await e.launch(i)}catch{if(await fe(e,t)==="live")throw new Error(u);re(t);try{r=await e.launch(i)}catch(h){throw je(t),new Error(`Could not open the LinkedIn automation Chrome profile at ${t}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${h.message})`)}}return qe(r,t),Ue(t,r),{browser:r,profileDir:t,needsSeed:ne(t)}}async function ye(e,o){if(!o||!o.needsSeed)return!1;if(!Q())return console.warn(" \u26A0 No saved LinkedIn session found. If this command comes back empty or redirects to login, run: ilml linkedin login"),!1;try{return await e.setCookie(...V()),se(o.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var _=process.argv.slice(2),Ke=_.includes("--help")||_.includes("-h"),Pe=_.includes("--json"),R=_.find(e=>e.startsWith("--save-to-graph="))?.split("=")[1]||null,Z=_.find(e=>e.startsWith("--out="))?.split("=")[1]||null,Ye=_.includes("--no-comments"),Ce=_.find(e=>e.startsWith("--comments-max="))?.split("=")[1],Xe=Ce!=null?parseInt(Ce,10):null,b=_.find(e=>e.startsWith("http")),v=Pe?(...e)=>console.error(...e):(...e)=>console.log(...e);function ve(){console.log(`
16
16
  read-post \u2014 read ONE LinkedIn post by URL (analysis-first; saving is opt-in)
17
17
 
18
18
  DEFAULT USE CASE
@@ -73,6 +73,6 @@ WHAT YOU GET ON ONE PAGE LOAD (no extra cost regardless of flags)
73
73
  BAN RISK
74
74
  Low. One post view = a single page load = normal human browsing.
75
75
  --no-comments is even quieter (skips the load-more-comments scroll loop).
76
- `)}Ke&&(ve(),process.exit(0));E||(ve(),process.exit(1));/linkedin\.com\/(posts|feed|in)\/|linkedin\.com\/.*(activity|update)/i.test(E)||(console.error(`URL doesn't look like a LinkedIn post: ${E}`),console.error("Expected something like:"),console.error(" https://www.linkedin.com/posts/<slug>-activity-<id>-xxxx"),console.error(" https://www.linkedin.com/feed/update/urn:li:activity:<id>"),process.exit(1));v("");v(` read-post \u2014 ${E}`);v("");var T=null;try{let e=await we(Je);T=e.browser;let o=await T.newPage();await ye(o,e);let t=await ue(o,E,{skipComments:Ye,commentsMax:Xe});if(t.authWall){console.error(" \u26D4 Auth wall \u2014 cookies expired or not logged in."),console.error(" Run 'ilml linkedin login' (or: node src/saveLoginState.mjs) and retry.");try{T&&await T.close()}catch{}T=null,process.exit(2)}let i=null;if(R){let r=t.author||{},d=t.text||t.cleanText||t.fullText||"",h=(d.replace(/\s+/g," ").trim()||"(empty post)").slice(0,80),n=`${r.name||"unknown"} \u2014 ${h}${h.length===80?"\u2026":""}`,p={url:t.url||E,urn:t.urn||null,author:t.author||null,text:t.text||null,postedAt:t.postedAt||null,hashtags:t.hashtags||[],mentions:t.mentions||[],media:t.media||null,capturedAt:new Date().toISOString()},a=[];r.name&&a.push(`**Author:** ${r.name}${r.headline?` \u2014 ${r.headline}`:""}`),r.profileUrl&&a.push(`**Profile:** ${r.profileUrl}`),t.postedAt&&a.push(`**Posted:** ${t.postedAt}`),a.push(`**Source:** ${E}`),a.push(`**Captured:** ${p.capturedAt.slice(0,10)}`),a.push(""),a.push("---"),a.push(""),a.push(d||"(post text not extracted)"),t.hashtags?.length&&(a.push(""),a.push(`**Hashtags:** ${t.hashtags.join(" ")}`)),t.mentions?.length&&(a.push(""),a.push(`**Mentions:** ${t.mentions.map(s=>`[${s.label||s.kind}](${s.url})`).join(", ")}`));let k=Object.entries(t.media||{}).filter(([,s])=>s).map(([s])=>s.replace(/^has/,"").toLowerCase());k.length&&(a.push(""),a.push(`**Media:** ${k.join(", ")}`)),a.push(""),a.push("---"),a.push(""),a.push("*Live engagement (reactions / comments / reposts) is intentionally NOT saved here \u2014 those drift. Re-run `read-post --json` on the source URL for current numbers.*"),a.push(""),a.push("```json"),a.push(JSON.stringify(p,null,2)),a.push("```");let M=a.join(`
77
- `);try{let{graph:s}=await Promise.resolve().then(()=>(ke(),xe)),g=await s.addItem(R,{title:n,description:M,tags:["linkedin-post"]}),c=g?.id||g?.item?.id||null;i={parentId:R,nodeId:c,url:c?`https://app.ilivemylife.io/item/${c}`:null},v(""),v(` \u2713 Saved to graph as child of ${R}`),v(` New node: ${c||"(id not returned by SDK)"}`),c&&v(` URL: https://app.ilivemylife.io/item/${c}`),v("")}catch(s){i={parentId:R,error:s.message?.slice(0,200)},console.error(""),console.error(` \u26A0 Failed to save to graph: ${s.message?.slice(0,200)}`),console.error(" The post was still extracted successfully \u2014 printing below."),console.error("")}}let l={...t,...i!==null&&{savedToGraph:i}};if(Z&&((await import("fs")).writeFileSync(Z,JSON.stringify(l,null,2)),v(` \u2713 Wrote ${(JSON.stringify(l).length/1024).toFixed(1)}KB to ${Z}`)),Pe)console.log(JSON.stringify(l,null,2));else{let r=t.author||{};console.log(" \u2500\u2500\u2500 POST \u2500\u2500\u2500"),console.log(` Author: ${r.name||"(unknown)"}${r.headline?` \u2014 ${r.headline}`:""}`),r.profileUrl&&console.log(` Profile: ${r.profileUrl}`),t.postedAt&&console.log(` Posted: ${t.postedAt}`);let d=[`${t.reactions||"0"} reactions`,`${t.commentCount||t.comments.length||"0"} comments`,t.repostCount?`${t.repostCount} reposts`:null].filter(Boolean).join(" ");console.log(` Engagement: ${d}`);let h=Object.entries(t.media||{}).filter(([,n])=>n).map(([n])=>n.replace(/^has/,"").toLowerCase());if(h.length&&console.log(` Media: ${h.join(", ")}`),t.hashtags?.length&&console.log(` Hashtags: ${t.hashtags.join(" ")}`),t.mentions?.length&&console.log(` Mentions: ${t.mentions.map(n=>`${n.label||n.url} (${n.kind})`).join(", ")}`),console.log(""),t.commentsTruncated){let n=t.commentsTruncatedReason==="skipComments"?"(comments skipped via --no-comments)":`(showing first ${t.comments.length} of ${t.commentsTruncatedOriginalCount} \u2014 capped via --comments-max)`;console.log(` Note: ${n}`),console.log("")}if(t.comments.length){console.log(t.text||"(post text not parsed \u2014 see cleanText below)"),console.log(""),console.log(` \u2500\u2500\u2500 COMMENTS (${t.comments.length}) \u2500\u2500\u2500`);for(let n of t.comments){let p=n.author||{};console.log(""),console.log(` \u2022 ${p.name||"(unknown)"}${p.headline?` \u2014 ${p.headline}`:""}`),n.text&&console.log(` ${n.text.replace(/\n+/g,`
76
+ `)}Ke&&(ve(),process.exit(0));b||(ve(),process.exit(1));/linkedin\.com\/(posts|feed|in)\/|linkedin\.com\/.*(activity|update)/i.test(b)||(console.error(`URL doesn't look like a LinkedIn post: ${b}`),console.error("Expected something like:"),console.error(" https://www.linkedin.com/posts/<slug>-activity-<id>-xxxx"),console.error(" https://www.linkedin.com/feed/update/urn:li:activity:<id>"),process.exit(1));v("");v(` read-post \u2014 ${b}`);v("");var T=null;try{let e=await we(Je);T=e.browser;let o=await T.newPage();await ye(o,e);let t=await ue(o,b,{skipComments:Ye,commentsMax:Xe});if(t.authWall){console.error(" \u26D4 Auth wall \u2014 cookies expired or not logged in."),console.error(" Run 'ilml linkedin login' (or: node src/saveLoginState.mjs) and retry.");try{T&&await T.close()}catch{}T=null,process.exit(2)}let i=null;if(R){let r=t.author||{},c=t.text||t.cleanText||t.fullText||"",h=(c.replace(/\s+/g," ").trim()||"(empty post)").slice(0,80),n=`${r.name||"unknown"} \u2014 ${h}${h.length===80?"\u2026":""}`,p={url:t.url||b,urn:t.urn||null,author:t.author||null,text:t.text||null,postedAt:t.postedAt||null,hashtags:t.hashtags||[],mentions:t.mentions||[],media:t.media||null,capturedAt:new Date().toISOString()},a=[];r.name&&a.push(`**Author:** ${r.name}${r.headline?` \u2014 ${r.headline}`:""}`),r.profileUrl&&a.push(`**Profile:** ${r.profileUrl}`),t.postedAt&&a.push(`**Posted:** ${t.postedAt}`),a.push(`**Source:** ${b}`),a.push(`**Captured:** ${p.capturedAt.slice(0,10)}`),a.push(""),a.push("---"),a.push(""),a.push(c||"(post text not extracted)"),t.hashtags?.length&&(a.push(""),a.push(`**Hashtags:** ${t.hashtags.join(" ")}`)),t.mentions?.length&&(a.push(""),a.push(`**Mentions:** ${t.mentions.map(s=>`[${s.label||s.kind}](${s.url})`).join(", ")}`));let k=Object.entries(t.media||{}).filter(([,s])=>s).map(([s])=>s.replace(/^has/,"").toLowerCase());k.length&&(a.push(""),a.push(`**Media:** ${k.join(", ")}`)),a.push(""),a.push("---"),a.push(""),a.push("*Live engagement (reactions / comments / reposts) is intentionally NOT saved here \u2014 those drift. Re-run `read-post --json` on the source URL for current numbers.*"),a.push(""),a.push("```json"),a.push(JSON.stringify(p,null,2)),a.push("```");let M=a.join(`
77
+ `);try{let{graph:s}=await Promise.resolve().then(()=>(ke(),xe)),g=await s.addItem(R,{title:n,description:M,tags:["linkedin-post"]}),l=g?.id||g?.item?.id||null;i={parentId:R,nodeId:l,url:l?`https://app.ilivemylife.io/item/${l}`:null},v(""),v(` \u2713 Saved to graph as child of ${R}`),v(` New node: ${l||"(id not returned by SDK)"}`),l&&v(` URL: https://app.ilivemylife.io/item/${l}`),v("")}catch(s){i={parentId:R,error:s.message?.slice(0,200)},console.error(""),console.error(` \u26A0 Failed to save to graph: ${s.message?.slice(0,200)}`),console.error(" The post was still extracted successfully \u2014 printing below."),console.error("")}}let u={...t,...i!==null&&{savedToGraph:i}};if(Z&&((await import("fs")).writeFileSync(Z,JSON.stringify(u,null,2)),v(` \u2713 Wrote ${(JSON.stringify(u).length/1024).toFixed(1)}KB to ${Z}`)),Pe)console.log(JSON.stringify(u,null,2));else{let r=t.author||{};console.log(" \u2500\u2500\u2500 POST \u2500\u2500\u2500"),console.log(` Author: ${r.name||"(unknown)"}${r.headline?` \u2014 ${r.headline}`:""}`),r.profileUrl&&console.log(` Profile: ${r.profileUrl}`),t.postedAt&&console.log(` Posted: ${t.postedAt}`);let c=[`${t.reactions||"0"} reactions`,`${t.commentCount||t.comments.length||"0"} comments`,t.repostCount?`${t.repostCount} reposts`:null].filter(Boolean).join(" ");console.log(` Engagement: ${c}`);let h=Object.entries(t.media||{}).filter(([,n])=>n).map(([n])=>n.replace(/^has/,"").toLowerCase());if(h.length&&console.log(` Media: ${h.join(", ")}`),t.hashtags?.length&&console.log(` Hashtags: ${t.hashtags.join(" ")}`),t.mentions?.length&&console.log(` Mentions: ${t.mentions.map(n=>`${n.label||n.url} (${n.kind})`).join(", ")}`),console.log(""),t.commentsTruncated){let n=t.commentsTruncatedReason==="skipComments"?"(comments skipped via --no-comments)":`(showing first ${t.comments.length} of ${t.commentsTruncatedOriginalCount} \u2014 capped via --comments-max)`;console.log(` Note: ${n}`),console.log("")}if(t.comments.length){console.log(t.text||"(post text not parsed \u2014 see cleanText below)"),console.log(""),console.log(` \u2500\u2500\u2500 COMMENTS (${t.comments.length}) \u2500\u2500\u2500`);for(let n of t.comments){let p=n.author||{};console.log(""),console.log(` \u2022 ${p.name||"(unknown)"}${p.headline?` \u2014 ${p.headline}`:""}`),n.text&&console.log(` ${n.text.replace(/\n+/g,`
78
78
  `)}`)}}else console.log(t.cleanText||t.fullText||"(no content extracted)");console.log(""),console.log(" (use --json for the full structured object)")}}catch(e){console.error(" Error:",e.message),process.exit(1)}finally{T&&await T.close().catch(()=>{})}