ilml-plugin-linkedin 1.11.7 → 1.12.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/CHANGELOG.md +18 -0
- package/README.md +7 -1
- package/dist/applyQueue.mjs +4 -4
- package/dist/daily.mjs +4 -4
- package/dist/enrichProfile.mjs +41 -0
- package/dist/enrichProfiles.mjs +84 -38
- package/dist/funnelRunner.mjs +46 -43
- package/dist/help.mjs +15 -0
- package/dist/messageBot.mjs +55 -55
- package/dist/profileHistory.mjs +5 -5
- package/dist/run.mjs +60 -57
- package/dist/scout.mjs +7 -7
- package/dist/syncAll.mjs +19 -19
- package/dist/verifyAbout.mjs +10 -7
- package/dist/viewers.mjs +9 -9
- package/dist/visit.mjs +43 -40
- package/ilml-plugin.json +53 -24
- package/package.json +3 -1
package/dist/enrichProfiles.mjs
CHANGED
|
@@ -1,59 +1,105 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
1
|
+
var Dt=Object.defineProperty;var Ve=(e,t)=>()=>(e&&(t=e(e=0)),t);var de=(e,t)=>{for(var o in t)Dt(e,o,{get:t[o],enumerable:!0})};async function $(e){let t=Math.floor(Math.random()*2001),o=e+t;return new Promise(n=>setTimeout(n,o))}async function We(e){return await e.evaluate(()=>{let t=document.querySelectorAll("div.artdeco-modal--is-open");for(let n of t){let s=n.innerText||"",r=s.includes("Premium")||s.includes("premium")||s.includes("Upgrade")||s.includes("upgrade"),l=s.includes("Try for")||s.includes("free trial")||s.includes("/month")||s.includes("per month")||s.includes("Start my")||s.includes("Subscribe"),i=s.includes("Get hired faster")||s.includes("Get hired 2x");if(r||l||i){let a=n.querySelector('button[aria-label="Dismiss"]')||n.querySelector("button.artdeco-modal__dismiss")||n.querySelector("button[data-test-modal-close-btn]");if(a)return a.click(),{dismissed:!0,matched:s.substring(0,80)};let f=n.querySelectorAll("button");for(let c of f){let m=c.innerText?.trim().toLowerCase()||"",u=c.getAttribute("aria-label")?.toLowerCase()||"";if(m==="not now"||m==="no thanks"||m==="dismiss"||u.includes("dismiss"))return c.click(),{dismissed:!0,matched:s.substring(0,80)}}}}let o=document.querySelector(".premium-upsell-link")||document.querySelector("[data-test-premium-upsell]")||document.querySelector(".premium-hub-upsell");if(o){let n=o.closest('[class*="modal"]')?.querySelector('button[aria-label="Dismiss"]')||o.closest('[class*="banner"]')?.querySelector('button[aria-label="Close"]');if(n)return n.click(),{dismissed:!0,matched:"premium-banner"}}return!1})}var se=Ve(()=>{});var tt={};de(tt,{extractExperienceFromDetails:()=>io});async function io(e,t){let o=t.replace(/\/+$/,"")+"/details/experience/";try{await e.goto(o,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3);let n=e.url();if(/\/(login|authwall|checkpoint)/i.test(n))throw new Error(`Session expired \u2014 bounced to ${n} when fetching /details/experience/`);for(let r=0;r<5;r++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await $(900);await $(1e3);let s=0;for(;s<5&&await e.evaluate(()=>{for(let l of document.querySelectorAll("button"))if(/^Load more$/i.test((l.textContent||"").trim()))return l.click(),!0;return!1});)s++,await $(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await $(700);return await e.evaluate(()=>{let r=document.querySelector("main");if(!r)return[];function l(c){let m=[];for(let u of c.querySelectorAll("div")){let h=Array.from(u.children).filter(w=>w.tagName==="DIV");if(h.length<3)continue;let v=h.filter(w=>(w.textContent||"").trim().length>50);v.length<3||(u.textContent||"").length<500||m.push({el:u,count:v.length,totalText:(u.textContent||"").length})}return m.sort((u,h)=>h.count-u.count||u.totalText-h.totalText),m[0]?.el}let i=l(r);if(!i)return[];let a=Array.from(i.children).filter(c=>c.tagName==="DIV").filter(c=>(c.textContent||"").trim().length>50);function f(c){let m=c[0]||null,u=null,h=null;if(c[1]){let b=c[1].split("\xB7").map(E=>E.trim());u=b[0]||null,b[1]&&(h=b[1])}let v=c.findIndex(b=>/(\d{4}|present)/i.test(b)&&/(-|–|—)/i.test(b)&&b.length<80),w=null,x=null;if(v>=0){let b=c[v].split("\xB7").map(E=>E.trim());w=b[0]||null,b[1]&&(x=b[1])}let A=null,ee=-1;if(v>=0&&c[v+1]){let b=c[v+1],E=/^[>*\-•]|^>/.test(b),ce=/https?:\/\//.test(b),ue=/\d{4}/.test(b),Q=/,/.test(b)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(b);!E&&!ce&&!ue&&b.length<100&&Q&&(A=b,ee=v+1)}let te=null,oe=-1,H=c[c.length-1];if(H&&/and\s+\+\d+\s+skills?$/i.test(H)){oe=c.length-1;let b=H.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);b&&(te={listed:b[1].split(",").map(E=>E.trim()),additional:parseInt(b[2],10)})}let ie=new Set([0,1,v,ee,oe].filter(b=>b>=0)),le=c.filter((b,E)=>!ie.has(E)),ae=le.length>0?le.join(`
|
|
2
|
+
|
|
3
|
+
`):null;return{title:m,company:u,employmentType:h,dates:w,duration:x,location:A,description:ae,skills:te,_raw:c}}return a.map(c=>{let u=(c.innerText||"").trim().split(`
|
|
4
|
+
`).map(h=>h.trim()).filter(h=>h&&h.length<5e3);return f(u)}).filter(c=>c.title)})}catch(n){if(/session expired|bounced to|authwall|checkpoint/i.test(n.message||""))throw n;return console.error(`extractExperienceFromDetails failed for ${t}: ${n.message?.slice(0,120)}`),[]}}var ot=Ve(()=>{se()});import qt from"puppeteer";import{addExtra as Ut}from"puppeteer-extra";import Bt from"puppeteer-extra-plugin-stealth";se();import{getPluginConfig as Ot}from"@ilivemylife/graph-sdk";var jt=await Ot();for(let[e,t]of Object.entries(jt))process.env[e]===void 0&&(process.env[e]=t);var Nt=process.env.LINKEDIN_NAME,V=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),kn=Object.freeze(new Set([V.DRAFT,V.CONFIRMED,V.NEEDS_REVIEW])),Lt=Object.freeze(new Set([V.DRAFT,V.CONFIRMED,V.REJECTED,V.NEEDS_REVIEW]));import Je from"fs";import Mt from"path";var Ft="cookies.json";function Pt(){let e=process.env.ILML_SCOPE_DIR;return e?Mt.join(e,"plugins-state","linkedin","cookies.json"):Ft}function Ge(){let e=Pt();if(!Je.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=Je.readFileSync(e,"utf-8")}catch(n){throw new Error(`Failed to read cookies at ${e}: ${n.message}. Run: ilml linkedin login`)}let o;try{o=JSON.parse(t)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(o)||o.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return o}var Ye=Ut(qt);Ye.use(Bt());async function ze(){let e=await Ye.launch({headless:!1,defaultViewport:null,protocolTimeout:3e5}),t=async()=>{console.log(`
|
|
5
|
+
Closing browser...`);try{await e.close()}catch{}process.exit(0)};process.on("SIGINT",t),process.on("SIGTERM",t);let o=await e.newPage();await o.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})});try{let n=Ge();await o.setCookie(...n),console.log(" Browser launched, cookies loaded.")}catch(n){console.error(`
|
|
3
6
|
[!] ${n.message}
|
|
4
|
-
`),await e.close(),process.exit(1)}return{browser:e,page:o}}import"dotenv/config";import*as w from"fs";import*as S from"path";import{fileURLToPath as Nt}from"url";var Mt=Nt(import.meta.url),Lt=S.dirname(S.dirname(Mt)),j=process.env.DATA_DIR?S.resolve(process.env.DATA_DIR,"collected-profiles"):S.join(Lt,"collected-profiles"),re=S.join(j,"people.json"),Tn=S.join(j,"jobs.json"),Rn=S.join(j,"quota.json"),Ve=S.join(j,"conversations.json"),Dn=S.join(j,"sync-state.json"),On=S.join(j,"application-questions.json"),ie=S.join(j,"profile-history");var G=null,Ft=null,Pt=null,W=null,qt=null,Ut=null;function Je(){G=null,Ft=null,Pt=null,W=null,qt=null,Ut=null}function le(){w.existsSync(j)||w.mkdirSync(j,{recursive:!0})}function ae(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";w.writeFileSync(n,o);for(let s=0;s<3;s++)try{w.renameSync(n,e);return}catch(r){if(s<2&&(r.code==="EPERM"||r.code==="EBUSY")){let l=Date.now();for(;Date.now()-l<200;);continue}throw r}}function ce(e,t){if(!w.existsSync(e))return null;try{let o=JSON.parse(w.readFileSync(e,"utf-8"));try{w.copyFileSync(e,e+".backup")}catch{}return o}catch(o){console.error(`[!] ${t} is corrupted: ${o.message}`),console.error(` File: ${S.resolve(e)}`);let n=e+".backup";if(w.existsSync(n))try{let s=JSON.parse(w.readFileSync(n,"utf-8"));console.error(` Restored from ${n}`);try{w.copyFileSync(n,e)}catch{}return s}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{w.copyFileSync(e,e+".corrupted")}catch{}return null}}function Bt(){return new Date().toISOString().split("T")[0]}var Ht=["name","title","location","company","connectionDegree","connectionsCount","mutualConnections","photoUrl","hasVerifiedBadge","about","currentCompany","currentSchool","connectionsLevel","mutualConnectionsCount","followers","openToWork","hiring","topSkills","availableSections"],Vt=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function ue(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function Jt(){w.existsSync(ie)||w.mkdirSync(ie,{recursive:!0})}function We(e){let t=ue(e);return t?S.join(ie,`${t}.json`):null}function Wt(e){let t=We(e);return t?ce(t,`profile-history/${ue(e)}.json`)||[]:[]}function Gt(e,t){let o=We(e);if(!o)return;Jt();let n=Wt(e);n.unshift(t);try{ae(o,n)}catch(s){console.error(`[!] Failed to append profile-history for ${ue(e)}: ${s.message}`)}}function Be(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function He(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function Yt(e,t){if(!e)return[];let o=[];for(let n of Vt){let s=e[n],r=t[n];Be(s)||Be(r)||He(s)!==He(r)&&o.push(n)}return o}function zt(e){let t=new Set(["seenCount","sources","firstSeen","lastSeen","lastUpdated","encounters","jobIds","lastFullVisitAt","lastSnapshotAt","messageSent","connectionStatus","connectionDate","connectionMethod"]),o={};for(let[n,s]of Object.entries(e))t.has(n)||(o[n]=s);return o}function q(){return G||(le(),G=ce(re,"people.json")||{},G)}function Qt(e){le(),G=e;try{ae(re,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${S.resolve(re)}`)}}function fe(){return W||(le(),W=ce(Ve,"conversations.json")||{},Kt(W),W)}function Kt(e){let t=0;for(let o of Object.values(e)){if(!(o.draftStatus!==void 0||o.draftPreparedAt!==void 0))continue;let s=(o.messages||[]).find(r=>r.status==="draft");s&&o.draftStatus&&o.draftStatus!=="pending"&&(s.status=o.draftStatus),delete o.draftStatus,delete o.draftPreparedAt,t++}if(t>0){console.log(` [migration] Moved draft state from conv to msg.status for ${t} conversations`);try{ae(Ve,e)}catch{}}}function de(e,t={}){if(!e)return null;let o=q(),n=Bt(),s=new Date().toISOString(),r=o[e];if(r){let l=Yt(r,t);l.length>0&&(Gt(e,{capturedAt:s,previousLastUpdated:r.lastUpdated||null,changedFields:l,snapshot:zt(r)}),r.lastSnapshotAt=s),r.seenCount=(r.seenCount||1)+1,r.lastSeen=n,r.lastUpdated=s,t.source&&!r.sources?.includes(t.source)&&(r.sources=r.sources||[],r.sources.push(t.source));for(let i of Ht)t[i]!=null&&(r[i]=t[i]);Array.isArray(t.availableSections)&&(r.lastFullVisitAt=s)}else o[e]={name:t.name||null,title:t.title||null,location:t.location||null,company:t.company||null,about:t.about||null,connectionDegree:t.connectionDegree||null,connectionsCount:t.connectionsCount||null,mutualConnections:t.mutualConnections||null,photoUrl:t.photoUrl||null,hasVerifiedBadge:t.hasVerifiedBadge||!1,currentCompany:t.currentCompany||null,currentSchool:t.currentSchool||null,connectionsLevel:t.connectionsLevel||null,mutualConnectionsCount:t.mutualConnectionsCount||null,followers:t.followers||null,openToWork:t.openToWork||!1,hiring:t.hiring||!1,topSkills:t.topSkills||null,availableSections:t.availableSections||null,firstSeen:n,lastSeen:n,seenCount:1,sources:t.source?[t.source]:[],connectionStatus:null,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:s,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?s:null};return Qt(o),o[e]}async function Zt(e,t){let o=e.url();if(o.includes("/in/"))return!1;if(o.includes("/login")||o.includes("/authwall")||o.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: npm run login");console.log(` Off-track: ${o.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await R(3e3);let n=e.url();return n.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${n.slice(0,80)}`),!0}async function Ge(e,t){try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await R(3e3),await Le(e)&&(console.log(" Dismissed Premium overlay"),await R(1500),await Zt(e,t));let n=0;for(let r=0;r<2;r++){let l=await e.evaluate(()=>document.body.scrollHeight);for(let a=1;a<=6;a++)await e.evaluate(c=>window.scrollTo(0,c),l*a/6),await R(900);let i=await e.evaluate(()=>document.body.scrollHeight);if(i===n)break;n=i}await R(800);let s=await e.evaluate(()=>{let r=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),l=new Set(["Ad Options","Don\u2019t want to see this","0 notifications","Explore Premium profiles","You might like","People you may know","Suggested for you","More profiles for you","Promoted"]),i=m=>{let h=(m||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(h)},a={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},c=document.querySelector("main");if(!c)return a;let d=[...Array.from(c.querySelectorAll("h1")),...Array.from(c.querySelectorAll("h2"))],f=Array.from(c.querySelectorAll("h2")),p=d.find(m=>{let h=m.textContent&&m.textContent.trim(),g=(h||"").replace(/\s*\(\d+\)$/,"").trim();return h&&h.length>1&&h.length<100&&!r.has(g)&&!l.has(g)}),b=p?p.textContent.trim():null,v=p?p.parentElement:null;for(;v&&v!==c&&!Array.from(v.children).filter(h=>h.tagName==="P").some(h=>{let g=h.textContent&&h.textContent.trim();return g&&g.length>5&&!i(g)});)v=v.parentElement;let k=null,O=null,Ae=null,oe=null;if(v&&v!==c){let m=Array.from(v.children).filter(g=>g.tagName==="P").filter(g=>{let M=g.textContent&&g.textContent.trim();return M&&M.length>5&&!i(M)});if(m[0]&&(k=m[0].textContent.trim()),m[1]){let g=m[1].textContent.trim().split(/\s*[·•]\s*/);O=g[0]||null,g.length>1&&(Ae=g.slice(1).join(" \xB7 "))}let h=Array.from(v.children).filter(g=>g.tagName==="DIV");for(let g=h.length-1;g>=0;g--){let M=h[g].textContent&&h[g].textContent.trim();if(M&&!(b&&M.startsWith(b))&&(oe=M.split(/[·•]/)[0].trim(),oe))break}}let Ee=null;if(v){let m=v.querySelectorAll("p, span, div");for(let h of m){let g=(h.textContent||"").trim().replace(/^[·•]\s*/,"");if(g==="1st"||g==="2nd"||g==="3rd"){Ee=g;break}}}let yt=!!c.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),xe=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),wt=xe&&xe.src||null,K=c.textContent||"",_e=null,Ie=K.match(/(\d+\+?)\s+connections\b/i);Ie&&(_e=Ie[1]+" connections");let Z=null,Te=K.match(/(\d+)\s+mutual connection/i),Re=K.match(/and\s+(\d+)\s+other mutual/i),bt=K.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);Te?Z=parseInt(Te[1],10):Re?Z=2+parseInt(Re[1],10):bt&&(Z=2);let De=null,Oe=null,je=f.find(m=>m.textContent&&m.textContent.trim()==="About");if(je){let m=je.parentElement;for(;m&&m.tagName!=="SECTION";)m=m.parentElement;if(m){let h=(m.textContent||"").trim();h=h.replace(/^About\s*/,"").trim();let g=h.match(/Top skills\s*(.+?)$/i);if(g){let ne=g[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Ct=>Ct.trim()).filter(Boolean);ne.length>0&&ne.length<10&&(Oe=ne)}h=h.split(/\n?…\s*more/i)[0].trim(),h=h.split(/\n?\.\.\.\s*more/i)[0].trim(),h=h.split(/\bTop skills\b/i)[0].trim(),h=h.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),De=h||null}}let Ne=null,Me=f.find(m=>m.textContent&&m.textContent.trim()==="Activity");if(Me){let m=Me.parentElement;for(;m&&m.tagName!=="SECTION";)m=m.parentElement;if(m){let h=(m.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);h&&(Ne=parseInt(h[1].replace(/,/g,""),10))}}let St=[...new Set(f.map(m=>(m.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(m=>m&&m.length>1&&m.length<60&&m!==b).filter(m=>r.has(m)))],Y=document.body.textContent||"",vt=/#OpenToWork\b/i.test(Y)||/\bOpen to work\b/.test(Y),kt=/#Hiring\b/i.test(Y)||/\bI'?m hiring\b/i.test(Y)||/\bWe are hiring\b/i.test(Y);return{name:b,title:k,location:oe,currentCompany:O,currentSchool:Ae,connectionDegree:Ee,hasVerifiedBadge:yt,photoUrl:wt,connectionsLevel:_e,mutualConnectionsCount:Z,followers:Ne,openToWork:vt,hiring:kt,about:De,topSkills:Oe,availableSections:St}});return console.log(`Viewed: ${s.name} - ${s.title}`),{...s,profileUrl:t}}catch(o){console.error(`Error viewing profile ${t}:`,o.message);try{await e.goto("about:blank",{timeout:1e4}),await R(1e3)}catch{}return null}}import"dotenv/config";import*as E from"fs";import*as A from"path";import{fileURLToPath as Xt}from"url";var eo=Xt(import.meta.url),to=A.dirname(A.dirname(eo)),B=process.env.DATA_DIR?A.resolve(process.env.DATA_DIR,"market-research"):A.join(to,"market-research"),Wn=A.join(B,"scouted-jobs.json"),Gn=A.join(B,"discovered-people.json"),Ye=A.join(B,"visit-log.json"),Yn=A.join(B,"companies.json"),zn=A.join(B,"job-decisions.json");function oo(){E.existsSync(B)||E.mkdirSync(B,{recursive:!0})}function no(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";E.writeFileSync(n,o);for(let s=0;s<3;s++)try{E.renameSync(n,e);return}catch(r){if(s<2&&(r.code==="EPERM"||r.code==="EBUSY")){let l=Date.now();for(;Date.now()-l<200;);continue}throw r}}function so(e){try{if(E.existsSync(e))return JSON.parse(E.readFileSync(e,"utf-8"))}catch{}return null}function ze(){ro=null,io=null,lo=null,ao=null,U=null}var ro=null;var io=null;var lo=null;var ao=null;var U=null;function me(){return U||(U=so(Ye)||{visits:[]},Array.isArray(U.visits)||(U.visits=[]),U)}function Qe(e,t={}){if(!e)return;oo();let o=me();o.visits.push({date:new Date().toISOString(),profileUrl:e,name:t.name||null,source:t.source||"manual"});let n=Date.now()-90*24*60*60*1e3;o.visits=o.visits.filter(s=>new Date(s.date).getTime()>n);try{no(Ye,o)}catch(s){console.error(`[!] Failed to save visit-log.json: ${s.message}`)}}function Ke(e){let t=me();for(let o=t.visits.length-1;o>=0;o--)if(t.visits[o].profileUrl===e)return t.visits[o].date;return null}async function Ze(e,t,o={}){let{maxVisits:n=50,delayBetween:s=4e3,skipRecentDays:r=7,verbose:l=!1}=o,i={visited:0,skipped:0,errors:0},a=Date.now()-r*24*60*60*1e3;for(let c of t){if(i.visited>=n)break;if(!c.profileUrl)continue;let d=Ke(c.profileUrl);if(d&&new Date(d).getTime()>a){i.skipped++;continue}try{let f=await Ge(e,c.profileUrl),p=c.source||"visit";f&&de(c.profileUrl,{...f,source:p}),Qe(c.profileUrl,{name:f?.name||c.name||null,source:p}),i.visited++,l?console.log(` [${i.visited}] ${f?.name||c.profileUrl} \u2014 ${f?.title?.slice(0,40)||"?"}`):i.visited%10===0&&console.log(` Visited: ${i.visited}`);let b=Math.random()*4e3;await R(s+b)}catch(f){i.errors++,l&&console.error(` Error visiting ${c.name||c.profileUrl}: ${f.message?.slice(0,60)}`);let p=(f.message||"").toLowerCase();if(p.includes("detached")||p.includes("session closed")||p.includes("target closed")){console.log(" Fatal browser error \u2014 stopping visits");break}}}return i}import"dotenv/config";import*as x from"fs";import*as L from"path";import{fileURLToPath as ho}from"url";import"dotenv/config";import{createGraphClient as co,resolveToken as uo}from"@ilivemylife/graph-sdk";import{config as fo}from"dotenv";fo();var Xe=uo()||process.env.TOKEN;Xe||(console.error(`
|
|
7
|
+
`),await e.close(),process.exit(1)}return{browser:e,page:o}}se();import"dotenv/config";import*as k from"fs";import*as C from"path";import{fileURLToPath as Ht}from"url";var Vt=Ht(import.meta.url),Wt=C.dirname(C.dirname(Vt)),M=process.env.DATA_DIR?C.resolve(process.env.DATA_DIR,"collected-profiles"):C.join(Wt,"collected-profiles"),ge=C.join(M,"people.json"),qn=C.join(M,"jobs.json"),Un=C.join(M,"quota.json"),Ze=C.join(M,"conversations.json"),Bn=C.join(M,"sync-state.json"),Hn=C.join(M,"application-questions.json"),ye=C.join(M,"profile-history");var X=null,Jt=null,Gt=null,Z=null,Yt=null,zt=null;function Xe(){X=null,Jt=null,Gt=null,Z=null,Yt=null,zt=null}function we(){k.existsSync(M)||k.mkdirSync(M,{recursive:!0})}function be(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";k.writeFileSync(n,o);for(let s=0;s<3;s++)try{k.renameSync(n,e);return}catch(r){if(s<2&&(r.code==="EPERM"||r.code==="EBUSY")){let l=Date.now();for(;Date.now()-l<200;);continue}throw r}}function Se(e,t){if(!k.existsSync(e))return null;try{let o=JSON.parse(k.readFileSync(e,"utf-8"));try{k.copyFileSync(e,e+".backup")}catch{}return o}catch(o){console.error(`[!] ${t} is corrupted: ${o.message}`),console.error(` File: ${C.resolve(e)}`);let n=e+".backup";if(k.existsSync(n))try{let s=JSON.parse(k.readFileSync(n,"utf-8"));console.error(` Restored from ${n}`);try{k.copyFileSync(n,e)}catch{}return s}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{k.copyFileSync(e,e+".corrupted")}catch{}return null}}function Kt(){return new Date().toISOString().split("T")[0]}var Qt=["name","title","location","company","connectionDegree","connectionsCount","mutualConnections","photoUrl","hasVerifiedBadge","about","currentCompany","currentSchool","connectionsLevel","mutualConnectionsCount","followers","openToWork","hiring","topSkills","availableSections","experience","featuredLinks","_lastEnrichedAt"],Zt=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function ve(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function Xt(){k.existsSync(ye)||k.mkdirSync(ye,{recursive:!0})}function et(e){let t=ve(e);return t?C.join(ye,`${t}.json`):null}function eo(e){let t=et(e);return t?Se(t,`profile-history/${ve(e)}.json`)||[]:[]}function to(e,t){let o=et(e);if(!o)return;Xt();let n=eo(e);n.unshift(t);try{be(o,n)}catch(s){console.error(`[!] Failed to append profile-history for ${ve(e)}: ${s.message}`)}}function Ke(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function Qe(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function oo(e,t){if(!e)return[];let o=[];for(let n of Zt){let s=e[n],r=t[n];Ke(s)||Ke(r)||Qe(s)!==Qe(r)&&o.push(n)}return o}function no(e){let t=new Set(["seenCount","sources","firstSeen","lastSeen","lastUpdated","encounters","jobIds","lastFullVisitAt","lastSnapshotAt","messageSent","connectionStatus","connectionDate","connectionMethod"]),o={};for(let[n,s]of Object.entries(e))t.has(n)||(o[n]=s);return o}function W(){return X||(we(),X=Se(ge,"people.json")||{},X)}function so(e){we(),X=e;try{be(ge,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${C.resolve(ge)}`)}}function ke(){return Z||(we(),Z=Se(Ze,"conversations.json")||{},ro(Z),Z)}function ro(e){let t=0;for(let o of Object.values(e)){if(!(o.draftStatus!==void 0||o.draftPreparedAt!==void 0))continue;let s=(o.messages||[]).find(r=>r.status==="draft");s&&o.draftStatus&&o.draftStatus!=="pending"&&(s.status=o.draftStatus),delete o.draftStatus,delete o.draftPreparedAt,t++}if(t>0){console.log(` [migration] Moved draft state from conv to msg.status for ${t} conversations`);try{be(Ze,e)}catch{}}}function Ce(e,t={}){if(!e)return null;let o=W(),n=Kt(),s=new Date().toISOString(),r=o[e];if(r){let l=oo(r,t);l.length>0&&(to(e,{capturedAt:s,previousLastUpdated:r.lastUpdated||null,changedFields:l,snapshot:no(r)}),r.lastSnapshotAt=s),r.seenCount=(r.seenCount||1)+1,r.lastSeen=n,r.lastUpdated=s,t.source&&!r.sources?.includes(t.source)&&(r.sources=r.sources||[],r.sources.push(t.source));for(let i of Qt)if(t[i]!=null){if(Array.isArray(t[i])&&t[i].length===0&&Array.isArray(r[i])&&r[i].length>0)continue;r[i]=t[i]}Array.isArray(t.availableSections)&&(r.lastFullVisitAt=s)}else o[e]={name:t.name||null,title:t.title||null,location:t.location||null,company:t.company||null,about:t.about||null,connectionDegree:t.connectionDegree||null,connectionsCount:t.connectionsCount||null,mutualConnections:t.mutualConnections||null,photoUrl:t.photoUrl||null,hasVerifiedBadge:t.hasVerifiedBadge||!1,currentCompany:t.currentCompany||null,currentSchool:t.currentSchool||null,connectionsLevel:t.connectionsLevel||null,mutualConnectionsCount:t.mutualConnectionsCount||null,followers:t.followers||null,openToWork:t.openToWork||!1,hiring:t.hiring||!1,topSkills:t.topSkills||null,availableSections:t.availableSections||null,experience:t.experience||null,featuredLinks:t.featuredLinks||null,_lastEnrichedAt:t._lastEnrichedAt||null,firstSeen:n,lastSeen:n,seenCount:1,sources:t.source?[t.source]:[],connectionStatus:null,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:s,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?s:null};return so(o),o[e]}async function lo(e,t){let o=e.url();if(o.includes("/in/"))return!1;if(o.includes("/login")||o.includes("/authwall")||o.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: npm run login");console.log(` Off-track: ${o.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3);let n=e.url();return n.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${n.slice(0,80)}`),!0}async function nt(e,t,o={}){let{extractExperience:n=!1}=o;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3),await We(e)&&(console.log(" Dismissed Premium overlay"),await $(1500),await lo(e,t));let r=0;for(let a=0;a<2;a++){let f=await e.evaluate(()=>document.body.scrollHeight);for(let m=1;m<=6;m++)await e.evaluate(u=>window.scrollTo(0,u),f*m/6),await $(900);let c=await e.evaluate(()=>document.body.scrollHeight);if(c===r)break;r=c}await $(800);let l=await e.evaluate(()=>{let a=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),f=new Set(["Ad Options","Don\u2019t want to see this","0 notifications","Explore Premium profiles","You might like","People you may know","Suggested for you","More profiles for you","Promoted"]),c=p=>{let g=(p||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(g)},m={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},u=document.querySelector("main");if(!u)return m;let h=[...Array.from(u.querySelectorAll("h1")),...Array.from(u.querySelectorAll("h2"))],v=Array.from(u.querySelectorAll("h2")),w=h.find(p=>{let g=p.textContent&&p.textContent.trim(),y=(g||"").replace(/\s*\(\d+\)$/,"").trim();return g&&g.length>1&&g.length<100&&!a.has(y)&&!f.has(y)}),x=w?w.textContent.trim():null,A=w?w.parentElement:null;for(;A&&A!==u&&!Array.from(A.children).filter(g=>g.tagName==="P").some(g=>{let y=g.textContent&&g.textContent.trim();return y&&y.length>5&&!c(y)});)A=A.parentElement;let ee=null,te=null,oe=null,H=null;if(A&&A!==u){let p=Array.from(A.children).filter(y=>y.tagName==="P").filter(y=>{let P=y.textContent&&y.textContent.trim();return P&&P.length>5&&!c(P)});if(p[0]&&(ee=p[0].textContent.trim()),p[1]){let y=p[1].textContent.trim().split(/\s*[·•]\s*/);te=y[0]||null,y.length>1&&(oe=y.slice(1).join(" \xB7 "))}let g=Array.from(A.children).filter(y=>y.tagName==="DIV");for(let y=g.length-1;y>=0;y--){let P=g[y].textContent&&g[y].textContent.trim();if(P&&!(x&&P.startsWith(x))&&(H=P.split(/[·•]/)[0].trim(),H))break}}let ie=null;if(A){let p=A.querySelectorAll("p, span, div");for(let g of p){let y=(g.textContent||"").trim().replace(/^[·•]\s*/,"");if(y==="1st"||y==="2nd"||y==="3rd"){ie=y;break}}}let le=!!u.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),ae=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),b=ae&&ae.src||null,E=u.textContent||"",ce=null,ue=E.match(/(\d+\+?)\s+connections\b/i);ue&&(ce=ue[1]+" connections");let Q=null,Me=E.match(/(\d+)\s+mutual connection/i),Fe=E.match(/and\s+(\d+)\s+other mutual/i),Et=E.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);Me?Q=parseInt(Me[1],10):Fe?Q=2+parseInt(Fe[1],10):Et&&(Q=2);let Pe=null,qe=null,Ue=v.find(p=>p.textContent&&p.textContent.trim()==="About");if(Ue){let p=Ue.parentElement;for(;p&&p.tagName!=="SECTION";)p=p.parentElement;if(p){let g=(p.textContent||"").trim();g=g.replace(/^About\s*/,"").trim();let y=g.match(/Top skills\s*(.+?)$/i);if(y){let he=y[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Rt=>Rt.trim()).filter(Boolean);he.length>0&&he.length<10&&(qe=he)}g=g.split(/\n?…\s*more/i)[0].trim(),g=g.split(/\n?\.\.\.\s*more/i)[0].trim(),g=g.split(/\bTop skills\b/i)[0].trim(),g=g.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),Pe=g||null}}let Be=null,He=v.find(p=>p.textContent&&p.textContent.trim()==="Activity");if(He){let p=He.parentElement;for(;p&&p.tagName!=="SECTION";)p=p.parentElement;if(p){let g=(p.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);g&&(Be=parseInt(g[1].replace(/,/g,""),10))}}let _t=[...new Set(v.map(p=>(p.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(p=>p&&p.length>1&&p.length<60&&p!==x).filter(p=>a.has(p)))],ne=document.body.textContent||"",It=/#OpenToWork\b/i.test(ne)||/\bOpen to work\b/.test(ne),Tt=/#Hiring\b/i.test(ne)||/\bI'?m hiring\b/i.test(ne)||/\bWe are hiring\b/i.test(ne);return{name:x,title:ee,location:H,currentCompany:te,currentSchool:oe,connectionDegree:ie,hasVerifiedBadge:le,photoUrl:b,connectionsLevel:ce,mutualConnectionsCount:Q,followers:Be,openToWork:It,hiring:Tt,about:Pe,topSkills:qe,availableSections:_t}});console.log(`Viewed: ${l.name} - ${l.title}`);let i=null;if(n){let{extractExperienceFromDetails:a}=await Promise.resolve().then(()=>(ot(),tt));i=await a(e,t),console.log(` + Experience: ${i.length} entries`)}return{...l,profileUrl:t,...i!==null&&{experience:i}}}catch(s){console.error(`Error viewing profile ${t}:`,s.message);try{await e.goto("about:blank",{timeout:1e4}),await $(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(s.message||""))throw s;return null}}import"dotenv/config";import*as R from"fs";import*as T from"path";import{fileURLToPath as ao}from"url";var co=ao(import.meta.url),uo=T.dirname(T.dirname(co)),G=process.env.DATA_DIR?T.resolve(process.env.DATA_DIR,"market-research"):T.join(uo,"market-research"),ns=T.join(G,"scouted-jobs.json"),ss=T.join(G,"discovered-people.json"),st=T.join(G,"visit-log.json"),rs=T.join(G,"companies.json"),is=T.join(G,"job-decisions.json");function fo(){R.existsSync(G)||R.mkdirSync(G,{recursive:!0})}function mo(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";R.writeFileSync(n,o);for(let s=0;s<3;s++)try{R.renameSync(n,e);return}catch(r){if(s<2&&(r.code==="EPERM"||r.code==="EBUSY")){let l=Date.now();for(;Date.now()-l<200;);continue}throw r}}function po(e){try{if(R.existsSync(e))return JSON.parse(R.readFileSync(e,"utf-8"))}catch{}return null}function rt(){ho=null,go=null,yo=null,wo=null,J=null}var ho=null;var go=null;var yo=null;var wo=null;var J=null;function $e(){return J||(J=po(st)||{visits:[]},Array.isArray(J.visits)||(J.visits=[]),J)}function it(e,t={}){if(!e)return;fo();let o=$e();o.visits.push({date:new Date().toISOString(),profileUrl:e,name:t.name||null,source:t.source||"manual"});let n=Date.now()-90*24*60*60*1e3;o.visits=o.visits.filter(s=>new Date(s.date).getTime()>n);try{mo(st,o)}catch(s){console.error(`[!] Failed to save visit-log.json: ${s.message}`)}}function lt(e){let t=$e();for(let o=t.visits.length-1;o>=0;o--)if(t.visits[o].profileUrl===e)return t.visits[o].date;return null}se();async function at(e,t,o={}){let{maxVisits:n=50,delayBetween:s=4e3,skipRecentDays:r=7,verbose:l=!1,extractExperience:i=!1}=o,a={visited:0,skipped:0,errors:0},f=Date.now()-r*24*60*60*1e3;for(let c of t){if(a.visited>=n)break;if(!c.profileUrl)continue;let m=lt(c.profileUrl);if(m&&new Date(m).getTime()>f){a.skipped++;continue}try{let u=await nt(e,c.profileUrl,{extractExperience:i}),h=c.source||"visit";if(u){let w={...u,source:h};i&&Array.isArray(u.experience)&&u.experience.length>0&&(w._lastEnrichedAt=new Date().toISOString()),Ce(c.profileUrl,w)}it(c.profileUrl,{name:u?.name||c.name||null,source:h}),a.visited++,l?console.log(` [${a.visited}] ${u?.name||c.profileUrl} \u2014 ${u?.title?.slice(0,40)||"?"}`):a.visited%10===0&&console.log(` Visited: ${a.visited}`);let v=Math.random()*4e3;await $(s+v)}catch(u){a.errors++,l&&console.error(` Error visiting ${c.name||c.profileUrl}: ${u.message?.slice(0,60)}`);let h=(u.message||"").toLowerCase();if(h.includes("detached")||h.includes("session closed")||h.includes("target closed")||h.includes("session expired")||h.includes("bounced to")||h.includes("authwall")||h.includes("checkpoint")||h.includes("redirected to login")){console.log(" Fatal browser/session error \u2014 stopping visits");break}}}return a}import"dotenv/config";import*as D from"fs";import*as q from"path";import{fileURLToPath as $o}from"url";import"dotenv/config";import{createGraphClient as bo,resolveToken as So}from"@ilivemylife/graph-sdk";import{config as vo}from"dotenv";vo();var ct=So()||process.env.TOKEN;ct||(console.error(`
|
|
5
8
|
[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.
|
|
6
9
|
`),console.error(" Easiest way:"),console.error(" 1. npm install -g @ilivemylife/graph-sdk"),console.error(` 2. ilml login your@email.com yourpassword
|
|
7
10
|
`),console.error(` Or add ILML_TOKEN=... to .env
|
|
8
|
-
`),process.exit(1));var
|
|
11
|
+
`),process.exit(1));var ut=bo({token:ct});function ko(e){if(!e||e<1e3)return`${e||0}ms`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let o=Math.floor(t/60),n=t%60;return n?`${o}m ${n}s`:`${o}m`}function Co({scriptName:e,mode:t,status:o,error:n,duration:s}){let r=o==="error"?"\u2717":o==="quota-reached"?"\u26A0":"\u2713",l=new Date().toISOString().slice(0,16).replace("T"," "),i=s?` ${ko(s)}`:"",a=o==="error"?`error${n?`: ${String(n).slice(0,80)}`:""}`:o==="quota-reached"?"daily quota reached":"done",f=t&&t!=="default"?` (${t})`:"";return`${r} ${e}${f} \u2014 ${a} \u2014 ${l}${i}`}async function dt({scriptName:e,mode:t,status:o,summaryLines:n,error:s,duration:r}){let l=process.env.NODE_RUN_REPORTS;if(!l||!Array.isArray(n)||n.length===0)return;let a=`**${Co({scriptName:e,mode:t,status:o,error:s,duration:r})}**
|
|
9
12
|
|
|
10
13
|
${n.join(`
|
|
11
|
-
`)}`;try{await
|
|
14
|
+
`)}`;try{await ut.addMessage(l,a)}catch(f){console.error(`[runReport] Failed to post end-of-session message: ${f.message}`)}}var xo=$o(import.meta.url),Ao=q.dirname(q.dirname(xo)),xe=process.env.DATA_DIR?q.resolve(process.env.DATA_DIR,"collected-profiles"):q.join(Ao,"collected-profiles"),Ae=q.join(xe,"run-log.json");function Eo(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";D.writeFileSync(n,o);for(let s=0;s<3;s++)try{D.renameSync(n,e);return}catch(r){if(s<2&&(r.code==="EPERM"||r.code==="EBUSY")){let l=Date.now();for(;Date.now()-l<200;);continue}throw r}}function ft(){try{if(!D.existsSync(Ae))return{runs:[]};let e=JSON.parse(D.readFileSync(Ae,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function mt(e){D.existsSync(xe)||D.mkdirSync(xe,{recursive:!0});try{Eo(Ae,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function pt(e,t="default"){let o=ft();for(let l of o.runs)l.status==="running"&&(l.status="interrupted",l.result="interrupted",l.timestamp&&(l.duration=Date.now()-new Date(l.timestamp).getTime()));let n=new Date,s={timestamp:n.toISOString(),script:e,mode:t,status:"running",result:null,duration:null,stats:null,error:null};o.runs.push(s);let r=Date.now()-30*24*60*60*1e3;return o.runs=o.runs.filter(l=>new Date(l.timestamp).getTime()>r),mt(o),{script:e,mode:t,startTime:n.getTime(),runIndex:o.runs.length-1}}function Ee(e,t,o=null,n=null){if(!e)return;let s=null;try{let l=ft(),i=l.runs[e.runIndex];if(i&&i.status==="running"&&i.script===e.script)i.status=t,i.result=t,i.duration=Date.now()-e.startTime,i.stats=o,i.error=n,s=i.duration;else{let a=l.runs.find(f=>f.script===e.script&&f.status==="running"&&f.timestamp===new Date(e.startTime).toISOString());a&&(a.status=t,a.result=t,a.duration=Date.now()-e.startTime,a.stats=o,a.error=n,s=a.duration)}mt(l)}catch(l){console.error(`[runLog] Failed to end run: ${l.message}`)}let r=o&&Array.isArray(o.summaryLines)?o.summaryLines:null;if(r&&r.length>0&&process.env.NODE_RUN_REPORTS){let l=t==="error"?"error":o&&o.dailyLimitHit?"quota-reached":"done";dt({scriptName:e.script,mode:e.mode,status:l,summaryLines:r,error:n,duration:s??Date.now()-e.startTime}).catch(i=>console.error(`[runLog] postRunReport failed: ${i.message}`))}}import"dotenv/config";import*as d from"fs";import*as je from"os";import*as S from"path";import{fileURLToPath as Wo}from"url";var Te={};de(Te,{NAME:()=>Io,VERSION:()=>_o,up:()=>Do});import*as O from"fs";import*as fe from"path";var _o=1,Io="normalize-jobs-and-questions",To=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],Ro=50;function _e(e){return O.existsSync(e)?JSON.parse(O.readFileSync(e,"utf-8")):null}function Ie(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";try{O.writeFileSync(n,o)}catch(s){try{O.unlinkSync(n)}catch{}throw s}try{O.renameSync(n,e)}catch(s){try{O.unlinkSync(n)}catch{}if(s.code==="EPERM"||s.code==="EBUSY"){let r=new Error(`File locked: ${e} (${s.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw r.code=s.code,r}throw s}}async function Do(e,t){let o=fe.join(e,"jobs.json"),n=fe.join(t,"scouted-jobs.json"),s=fe.join(e,"application-questions.json"),r=_e(o)||{},l=_e(n)||{},i=0,a=[];for(let c of Object.keys(r)){if(!l[c])continue;let m=l[c],u=r[c];for(let h of To)m[h]!=null&&u[h]==null&&(u[h]=m[h]);a.push(c),i++}i>0?(Ie(o,r),console.log(` Phase 1: Merged ${i} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let f=_e(s);if(f&&Array.isArray(f.applications)){let c={},m=0;for(let u of f.applications){let h=u.jobId||"unknown";c[h]||(c[h]={applications:[]});let v=(u.questions||[]).map(w=>{let x={type:w.type||"input",question:w.question||"",answer:w.answer||""};return w.options&&(w.options.length<=Ro?x.options=w.options:(x.optionsOmitted=!0,m++)),w.page&&(x.page=w.page),w.wasPreFilled&&(x.wasPreFilled=!0),w.wasRetry&&(x.wasRetry=!0),x});c[h].applications.push({applicationId:u.applicationId,date:u.date,result:u.result||"submitted",formPages:u.formPages||null,duration:u.duration||null,retries:u.retries||0,failedField:u.failedField||null,questionCount:u.questionCount||v.length,questions:v})}Ie(s,c),console.log(` Phase 2: Rekeyed ${f.applications.length} applications by jobId (${Object.keys(c).length} unique jobs)`),m>0&&console.log(` Phase 2: Stripped bloated options from ${m} questions`)}else f&&!f.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(a.length>0){for(let c of a)delete l[c];Ie(n,l),console.log(` Phase 3: Removed ${a.length} merged entries from scouted-jobs.json (${Object.keys(l).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var Re={};de(Re,{NAME:()=>jo,VERSION:()=>Oo,up:()=>Mo});import*as j from"fs";import*as ht from"path";var Oo=2,jo="reset-unread-flags";function No(e){return j.existsSync(e)?JSON.parse(j.readFileSync(e,"utf-8")):null}function Lo(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";try{j.writeFileSync(n,o)}catch(s){try{j.unlinkSync(n)}catch{}throw s}try{j.renameSync(n,e)}catch(s){try{j.unlinkSync(n)}catch{}if(s.code==="EPERM"||s.code==="EBUSY"){let r=new Error(`File locked: ${e} (${s.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw r.code=s.code,r}throw s}}async function Mo(e){let t=ht.join(e,"conversations.json"),o=No(t);if(!o){console.log(" conversations.json not found \u2014 nothing to reset.");return}let n=0;for(let s of Object.keys(o))o[s].unread===!0&&(o[s].unread=!1,n++);if(n===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}Lo(t,o),console.log(` Reset unread=false on ${n} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var De={};de(De,{NAME:()=>Po,VERSION:()=>Fo,up:()=>Vo});import*as N from"fs";import*as gt from"path";var Fo=3,Po="recompute-last-message-by",qo=new Set(["draft","confirmed","rejected","needs_review"]);function Uo(e){return N.existsSync(e)?JSON.parse(N.readFileSync(e,"utf-8")):null}function Bo(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";try{N.writeFileSync(n,o)}catch(s){try{N.unlinkSync(n)}catch{}throw s}try{N.renameSync(n,e)}catch(s){try{N.unlinkSync(n)}catch{}if(s.code==="EPERM"||s.code==="EBUSY"){let r=new Error(`File locked: ${e} (${s.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw r.code=s.code,r}throw s}}function Ho(e,t){if(!e||e.length===0)return"them";let o=e.filter(r=>!qo.has(r.status));if(o.length===0)return"them";let n=o.map(r=>({m:r,t:Date.parse(r.time)})).filter(r=>Number.isFinite(r.t)).sort((r,l)=>l.t-r.t).map(r=>r.m),s=n.length>0?n:[...o].reverse();for(let r of s){let l=r.sender;if(l===t)return"me";if(l!=="Unknown"&&l!=="")return"them"}return"them"}async function Vo(e){let t=gt.join(e,"conversations.json"),o=Uo(t);if(!o){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let n=process.env.LINKEDIN_NAME;if(!n||typeof n!="string"||!n.trim())throw new Error(`LINKEDIN_NAME env var is not set. Migration v003 needs your display name to determine which messages are yours vs theirs. Set LINKEDIN_NAME in your .env (or run "ilml plugin config linkedin set LINKEDIN_NAME 'Your Name'") and retry.`);let s=0,r=0,l=0;for(let i of Object.keys(o)){let a=o[i];if(!a||typeof a!="object")continue;Object.prototype.hasOwnProperty.call(a,"_cardSynced")&&(delete a._cardSynced,r++);let f=Array.isArray(a.messages)?a.messages:[],c=Ho(f,n),m=c==="me"?"awaiting_reply":"unanswered_by_us";a.lastMessageBy!==c&&l++,a.lastMessageBy=c,a.conversationStatus=m,s++}if(s===0){console.log(" No conversations to recompute.");return}Bo(t,o),console.log(` Recomputed lastMessageBy + conversationStatus on ${s} conversations.`),console.log(` ${l} had stale lastMessageBy (now corrected).`),r>0&&console.log(` Cleaned ${r} leftover _cardSynced flags.`),console.log(" Re-run 'ilml linkedin enrich' if you want actionNeeded / summary / autoTags to also update.")}var Jo=Wo(import.meta.url),Go=S.dirname(Jo),Yo=S.dirname(S.dirname(Go));function zo(e){return e&&(e==="~"?je.homedir():e.startsWith("~/")||e.startsWith("~\\")?S.join(je.homedir(),e.slice(2)):e)}var L=process.env.DATA_DIR?S.resolve(zo(process.env.DATA_DIR)):Yo,z=S.join(L,"collected-profiles"),K=S.join(L,"market-research"),I=S.join(L,".schema-version"),yt=[S.join(z,".schema-version"),S.join(K,".schema-version")],U=3,F=[{version:1,module:Te},{version:2,module:Re},{version:3,module:De}];(function(){F.sort((n,s)=>n.version-s.version);let t=new Set;for(let n of F){if(!Number.isInteger(n.version)||n.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(n.version)} (must be positive integer)`);if(t.has(n.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${n.version}`);t.add(n.version);let s=n.module;if(!s||typeof s.up!="function")throw new Error(`MIGRATION_REGISTRY: v${n.version} module is missing up()`);if(s.VERSION!==void 0&&s.VERSION!==n.version)throw new Error(`MIGRATION_REGISTRY: v${n.version} entry does not match module VERSION (${s.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let o=F.length?F[F.length-1].version:0;if(o!==U)throw new Error(`MIGRATION_REGISTRY: highest version v${o} but CURRENT_SCHEMA_VERSION=${U}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let n=0;n<F.length;n++){let s=n+1;if(F[n].version!==s)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${s} at position ${n} but found v${F[n].version}`)}})();function vt(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
12
15
|
[FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
|
|
13
|
-
`),process.exit(1));try{
|
|
14
|
-
[FATAL] Cannot create DATA_DIR (${
|
|
15
|
-
`),process.exit(1))}let e;try{e=
|
|
16
|
-
[FATAL] DATA_DIR (${
|
|
16
|
+
`),process.exit(1));try{d.mkdirSync(L,{recursive:!0})}catch(t){t.code!=="EEXIST"&&(console.error(`
|
|
17
|
+
[FATAL] Cannot create DATA_DIR (${L}): ${t.message}`),console.error(` Fix the path or permissions and try again.
|
|
18
|
+
`),process.exit(1))}let e;try{e=d.statSync(L)}catch(t){console.error(`
|
|
19
|
+
[FATAL] DATA_DIR (${L}) is not accessible: ${t.message}
|
|
17
20
|
`),process.exit(1)}e.isDirectory()||(console.error(`
|
|
18
|
-
[FATAL] DATA_DIR (${
|
|
19
|
-
`),process.exit(1));for(let t of[
|
|
21
|
+
[FATAL] DATA_DIR (${L}) exists but is NOT a directory.`),console.error(` Looks like a typo \u2014 your DATA_DIR points at a file. Fix the path and try again.
|
|
22
|
+
`),process.exit(1));for(let t of[z,K]){let o;try{o=d.lstatSync(t)}catch(n){if(n.code==="ENOENT")continue;throw n}o.isSymbolicLink()&&(console.error(`
|
|
20
23
|
[FATAL] Data subdirectory is a symbolic link: ${t}`),console.error(" Refusing to follow \u2014 backup code would copy whatever the link points at."),console.error(` If this is intentional, replace the symlink with the real directory.
|
|
21
|
-
`),process.exit(1))}}var
|
|
22
|
-
[FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${t.pid}`),console.error(` Started at: ${t.startedAt||"(unknown)"}`),console.error(` Lock file: ${
|
|
24
|
+
`),process.exit(1))}}var Y=S.join(L,".migration-lock");function Ko(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return d.writeFileSync(Y,e,{flag:"wx"}),!0}catch(n){if(n.code!=="EEXIST")throw n}let t;try{t=JSON.parse(d.readFileSync(Y,"utf-8"))}catch{t=null}if(t&&Number.isInteger(t.pid)){let n=!1;try{process.kill(t.pid,0),n=!0}catch(l){l.code==="EPERM"&&(n=!0)}let s=24*60*60*1e3,r=1/0;if(t.startedAt){let l=Date.parse(t.startedAt);Number.isNaN(l)||(r=Date.now()-l)}n&&r<s&&(console.error(`
|
|
25
|
+
[FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${t.pid}`),console.error(` Started at: ${t.startedAt||"(unknown)"}`),console.error(` Lock file: ${Y}
|
|
23
26
|
`),console.error(" Wait for it to finish, or if you're sure it's not actually running,"),console.error(` delete the lock file manually and re-run.
|
|
24
|
-
`),process.exit(1)),n&&r>=s&&console.log(` Lock holder PID ${t.pid} is alive but lock is older than 24h \u2014 assuming PID reuse, taking over.`)}console.log(` Stale migration lock from PID ${t?.pid??"?"} found \u2014 taking over.`);let o=
|
|
27
|
+
`),process.exit(1)),n&&r>=s&&console.log(` Lock holder PID ${t.pid} is alive but lock is older than 24h \u2014 assuming PID reuse, taking over.`)}console.log(` Stale migration lock from PID ${t?.pid??"?"} found \u2014 taking over.`);let o=Y+".tmp";try{return d.writeFileSync(o,e),d.renameSync(o,Y),!0}catch(n){try{d.unlinkSync(o)}catch{}throw new Error(`Failed to take over stale migration lock: ${n.message}`)}}function Ne(){try{if(JSON.parse(d.readFileSync(Y,"utf-8")).pid!==process.pid)return;d.unlinkSync(Y)}catch{}}var wt=!1;function Qo(){if(wt)return;wt=!0;let e=()=>{try{Ne()}catch{}process.exit(1)};for(let t of["SIGINT","SIGTERM","SIGHUP"])try{process.on(t,e)}catch{}}function Zo(){if(d.existsSync(I))return;let e=[],t=[];for(let r of yt)if(d.existsSync(r))try{e.push({file:r,schema:me(r)})}catch(l){t.push({file:r,err:l.message})}if(t.length>0){console.error(`
|
|
25
28
|
[FATAL] Legacy .schema-version file(s) corrupted \u2014 cannot determine current schema version:`);for(let r of t)console.error(` ${r.file}: ${r.err}`);console.error(`
|
|
26
29
|
Repair the file(s) (likely just an integer 'version' field \u2014 see another working DATA_DIR`),console.error(` or default to {"version":1,"migrations":[]} if you're sure you're on schema v1) and try again.
|
|
27
30
|
`),process.exit(1)}if(e.length===0)return;let o=e.map(r=>r.schema.version);if(new Set(o).size>1){console.error(`
|
|
28
31
|
[FATAL] Legacy .schema-version files disagree:`);for(let r of e)console.error(` ${r.file}: v${r.schema.version}`);console.error(" This means a previous migration crashed between writing the two files."),console.error(` Reconcile manually (delete the wrong one, keep the right one), then re-run.
|
|
29
|
-
`),process.exit(1)}let n=e[0].schema,s
|
|
30
|
-
[FATAL] ${
|
|
31
|
-
`),process.exit(1)}let t=
|
|
32
|
-
[FATAL] ${
|
|
33
|
-
`),process.exit(1)),t}function
|
|
34
|
-
[FATAL] Your data schema is at v${t}, but this plugin build only understands up to v${
|
|
35
|
-
`),console.error(" Options:"),console.error(" A) Re-install the newer plugin version that produced this schema, then"),console.error(" (if you really want to downgrade) run 'rollback-data --confirm' first,"),console.error(" then re-install the older plugin version."),console.error(` B) Manually restore your data from the *.pre-vNNN.backup files matching v${
|
|
32
|
+
`),process.exit(1)}let n=e[0].schema,s=I+".tmp";try{d.writeFileSync(s,JSON.stringify(n,null,2)),d.renameSync(s,I)}catch(r){try{d.unlinkSync(s)}catch{}throw r}for(let r of yt)if(d.existsSync(r))try{d.unlinkSync(r)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${I}`)}function Xo(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let t=Number(e.version);return!Number.isFinite(t)||t<0||!Number.isInteger(t)?null:(e.version=t,Array.isArray(e.migrations)||(e.migrations=[]),e)}function me(e){let t=d.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function bt(){if(Zo(),!d.existsSync(I))return{version:0,migrations:[]};let e;try{e=me(I)}catch(o){if(o.code==="ENOENT")return{version:0,migrations:[]};console.error(`
|
|
33
|
+
[FATAL] ${I} is not valid JSON: ${o.message}`),console.error(" Refusing to proceed \u2014 silently treating it as 'fresh install' would re-apply"),console.error(" every migration on top of already-migrated data and corrupt it."),console.error(' Repair the file (set it to {"version":N,"migrations":[...]} matching your real state)'),console.error(` or restore from the *.pre-vNNN.backup files if you have them.
|
|
34
|
+
`),process.exit(1)}let t=Xo(e);return t===null&&(console.error(`
|
|
35
|
+
[FATAL] ${I} has invalid structure:`),console.error(` ${JSON.stringify(e)?.slice(0,200)||"(unparseable)"}`),console.error(' Expected shape: { "version": <integer>, "migrations": [...] }'),console.error(` Repair the file or restore from a backup.
|
|
36
|
+
`),process.exit(1)),t}function kt(e){try{d.chmodSync(e,384)}catch{}}function en(e){if(vt(),d.existsSync(I))try{if(d.lstatSync(I).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${I}. Refusing to write through it (potential symlink attack). Remove the link and re-run.`)}catch(o){if(o.message?.includes("symbolic link"))throw o}let t=I+".tmp";try{d.writeFileSync(t,JSON.stringify(e,null,2)),kt(t),d.renameSync(t,I)}catch(o){try{d.unlinkSync(t)}catch{}throw o}}function St(e,t){if(!d.existsSync(e))return;let o=`.pre-v${String(t).padStart(3,"0")}.backup`,n=d.readdirSync(e).filter(i=>{let a=i.toLowerCase();if(a.includes(".backup")||a===".schema-version"||a.endsWith(".tmp"))return!1;try{return d.statSync(S.join(e,i)).isFile()}catch{return!1}}),s=0,r=0,l=[];for(let i of n){let a=S.join(e,i),f=S.join(e,i+o);if(d.existsSync(f)){r++;continue}try{$t(a,f),s++}catch(c){l.push({file:i,err:c.message})}}if(l.length>0){let i=new Error(`Failed to back up ${l.length} file(s) in ${S.basename(e)}/: `+l.map(a=>`${a.file} (${a.err})`).join(", "));throw i.code="BACKUP_INCOMPLETE",i}if(s>0||r>0){let i=r>0?` (${r} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${s} files in ${S.basename(e)}/ (${o})${i}`)}}var Oe=!1;async function Ct(){if(Oe)return;vt(),rn();let t=bt().version;if(t===U){Oe=!0;return}Qo(),Ko(),process.on("exit",Ne),t>U&&(console.error(`
|
|
37
|
+
[FATAL] Your data schema is at v${t}, but this plugin build only understands up to v${U}.`),console.error(" This usually means you downgraded the plugin without rolling back data."),console.error(` Operating on the newer-format data with this build would risk corrupting it.
|
|
38
|
+
`),console.error(" Options:"),console.error(" A) Re-install the newer plugin version that produced this schema, then"),console.error(" (if you really want to downgrade) run 'rollback-data --confirm' first,"),console.error(" then re-install the older plugin version."),console.error(` B) Manually restore your data from the *.pre-vNNN.backup files matching v${U}.
|
|
36
39
|
`),process.exit(1)),console.log(`
|
|
37
|
-
\u{1F4E6} Schema migration: v${t} \u2192 v${
|
|
40
|
+
\u{1F4E6} Schema migration: v${t} \u2192 v${U}`);let o=ln();if(!o.ok){console.error(`
|
|
38
41
|
[FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let s of o.broken)console.error(` ${s.dir}/${s.file}: ${s.err}`);console.error(`
|
|
39
42
|
Migration ABORTED. No backups taken, no files modified.`),console.error(" Repair the file(s) above (restore from your own backup, or fix manually)"),console.error(` and try again. To inspect: 'ilml linkedin migrate-status'.
|
|
40
|
-
`),process.exit(1)}let n=
|
|
41
|
-
Running migration v${String(s.version).padStart(3,"0")}...`);let r=`v${String(s.version).padStart(3,"0")}`,l=`.pre-${r}.backup`;try{
|
|
43
|
+
`),process.exit(1)}let n=F.filter(s=>s.version>t);for(let s of n){console.log(`
|
|
44
|
+
Running migration v${String(s.version).padStart(3,"0")}...`);let r=`v${String(s.version).padStart(3,"0")}`,l=`.pre-${r}.backup`;try{St(z,s.version),St(K,s.version)}catch(a){console.error(`
|
|
42
45
|
[FATAL] Pre-migration backup failed for ${r}: ${a.message}`),console.error(" Migration NOT applied. Repair the underlying issue (disk space, permissions, locked files)"),console.error(` and re-run the plugin command.
|
|
43
|
-
`),process.exit(1)}let i=s.module;try{await i.up(
|
|
44
|
-
[FATAL] Migration ${r} failed: ${a.message}`),console.error(` Attempting auto-rollback from ${l} files...`);try{let
|
|
45
|
-
`)):(console.error(` [!] Auto-rollback INCOMPLETE: ${
|
|
46
|
-
`))}catch(
|
|
47
|
-
`)}process.exit(1)}try{let a=new Date().toISOString(),
|
|
46
|
+
`),process.exit(1)}let i=s.module;try{await i.up(z,K)}catch(a){console.error(`
|
|
47
|
+
[FATAL] Migration ${r} failed: ${a.message}`),console.error(` Attempting auto-rollback from ${l} files...`);try{let f=an(l);f.ok?(console.error(` \u2713 Auto-rollback restored ${f.restored} files. Schema stays at v${t}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
|
|
48
|
+
`)):(console.error(` [!] Auto-rollback INCOMPLETE: ${f.error}`),console.error(` Manual recovery: copy *${l} files back over the originals.
|
|
49
|
+
`))}catch(f){console.error(` [!] Auto-rollback CRASHED while restoring: ${f.message}`),console.error(` Manual recovery: copy *${l} files back over the originals.
|
|
50
|
+
`)}process.exit(1)}try{let a=new Date().toISOString(),f={version:s.version,name:i.NAME||r,appliedAt:a},c=bt();c.version=s.version,c.migratedAt=a,c.migrations=c.migrations||[],c.migrations.push(f),en(c)}catch(a){console.error(`
|
|
48
51
|
[FATAL] Migration ${r} applied successfully but schema version file could NOT be updated: ${a.message}`),console.error(` Your data is in the v${s.version} state but .schema-version still shows v${t}.`),console.error(` On next plugin command the runner will try to re-apply ${r}. If that migration is`),console.error(` idempotent (most are), it will succeed harmlessly. If you're unsure, run 'data-cleanup' and contact support.
|
|
49
|
-
`),process.exit(1)}console.log(` \u2713 Migration ${r} complete`)}try{
|
|
50
|
-
\u2713 Schema is now at v${
|
|
51
|
-
`)}var
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
`),process.exit(1)}console.log(` \u2713 Migration ${r} complete`)}try{Xe()}catch{}try{rt()}catch{}Oe=!0,Ne(),console.log(`
|
|
53
|
+
\u2713 Schema is now at v${U}
|
|
54
|
+
`)}var tn=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function on(e){let t=e.toLowerCase();return tn.some(o=>o.test(t))}var nn=6e4;function sn(){let e=Date.now(),t=[];for(let o of[L,z,K]){if(!d.existsSync(o))continue;let n;try{n=d.readdirSync(o)}catch{continue}for(let s of n){if(!on(s))continue;let r=S.join(o,s);try{let l=d.statSync(r);if(!l.isFile()||e-l.mtimeMs<nn)continue;t.push({dir:o,file:s,fullPath:r})}catch{}}}return t}function rn({verbose:e=!1}={}){let t=sn();if(t.length===0)return e&&console.log(" No orphan .tmp files found."),0;let o=0;for(let n of t)try{d.unlinkSync(n.fullPath),o++,e&&console.log(` Removed orphan: ${S.basename(n.dir)}/${n.file}`)}catch(s){console.warn(` [!] Could not remove orphan ${n.fullPath}: ${s.message}`)}return!e&&o>0&&console.log(` Cleaned up ${o} orphan .tmp file(s) from previous run.`),o}function ln(){let e=[];for(let t of[z,K]){if(!d.existsSync(t))continue;let o=d.readdirSync(t).filter(n=>{let s=n.toLowerCase();return s.endsWith(".json")&&!s.includes(".backup")});for(let n of o){let s=S.join(t,n);try{me(s)}catch(r){e.push({dir:S.basename(t),file:n,err:r.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function an(e){let t=[],o=[];for(let r of[z,K]){if(!d.existsSync(r))continue;let l=d.readdirSync(r).filter(i=>i.endsWith(e));for(let i of l){let a=S.join(r,i),f=i.slice(0,-e.length),c=S.join(r,f);try{f.toLowerCase().endsWith(".json")?me(a):d.accessSync(a,d.constants.R_OK),t.push({backupPath:a,originalPath:c,fileName:i,dir:r})}catch(m){o.push(`${S.basename(r)}/${i}: ${m.message}`)}}}if(o.length>0)return{ok:!1,error:o.join("; "),restored:0};let n=0,s=[];for(let{backupPath:r,originalPath:l,fileName:i,dir:a}of t)try{$t(r,l),n++}catch(f){s.push(`${S.basename(a)}/${i}: ${f.message}`)}return s.length>0?{ok:!1,error:s.join("; "),restored:n}:{ok:!0,restored:n}}function $t(e,t){let o=t+".tmp";try{d.copyFileSync(e,o),kt(o)}catch(n){try{d.unlinkSync(o)}catch{}throw n}try{d.renameSync(o,t)}catch(n){try{d.unlinkSync(o)}catch{}if(n.code==="EPERM"||n.code==="EBUSY"){let s=new Error(`File locked: ${t} (${n.code}). On Windows this is usually antivirus / Search Indexer / the file open in another app. Close anything that might be holding it and re-run.`);throw s.code=n.code,s}throw n}}await Ct();var B=process.argv.slice(2),pe=parseInt(B.find(e=>e.startsWith("--max="))?.split("=")[1]||"10"),re=B.includes("--connections"),xt=B.find(e=>e.startsWith("--match-title="))?.split("=").slice(1).join("=")||null,_=xt?fn(xt):null,cn=B.includes("--list"),un=B.includes("--verbose"),Le=B.includes("--with-experience"),dn=B.includes("--help")||B.includes("-h");dn&&(console.log(`
|
|
55
|
+
enrich-profiles \u2014 batch-visit contacts in people.json missing About text
|
|
56
|
+
|
|
57
|
+
USAGE
|
|
58
|
+
ilml linkedin enrich-profiles [--max=N] [--connections] [--match-title=re] [--with-experience] [--list]
|
|
59
|
+
node enrichProfiles.mjs [flags...] # dev
|
|
60
|
+
|
|
61
|
+
FLAGS
|
|
62
|
+
--max=N Max visits this session (default 10). Higher = more ban-risk.
|
|
63
|
+
--connections Filter queue to 1st-degree connections only.
|
|
64
|
+
Visiting connections is lower-risk than visiting strangers.
|
|
65
|
+
--match-title=<re> Regex filter on current title.
|
|
66
|
+
Example: --match-title="recruiter|sourcer"
|
|
67
|
+
Example: --match-title="founder|ceo"
|
|
68
|
+
--with-experience Opt-in. Each visit also fetches /details/experience/ and
|
|
69
|
+
adds structured experience[] to the saved record.
|
|
70
|
+
DOUBLES the page-view footprint per profile.
|
|
71
|
+
Extra ban-risk warning is printed.
|
|
72
|
+
--list Show queue stats only, no browser. Safe to run anytime.
|
|
73
|
+
--verbose Per-visit logging.
|
|
74
|
+
--help, -h Print this help and exit.
|
|
75
|
+
|
|
76
|
+
BEHAVIOUR
|
|
77
|
+
- Builds a priority-ordered queue of profiles in people.json missing About.
|
|
78
|
+
- Visits in tier order: connected+conversed > connected > title-match > etc.
|
|
79
|
+
- Updates people.json via upsertPerson() \u2014 additive merge, never deletes.
|
|
80
|
+
- With --with-experience: same fixes apply (auth-wall detection, empty-array
|
|
81
|
+
preservation, _lastEnrichedAt only on success).
|
|
82
|
+
|
|
83
|
+
\u26A0 BAN RISK \u2014 HIGH
|
|
84
|
+
Visits profiles WITHOUT follow-up action (no message, no connect request, no
|
|
85
|
+
like). LinkedIn has flagged accounts for exactly this pattern. Recommended:
|
|
86
|
+
- Keep --max \u2264 10
|
|
87
|
+
- Run at most once per day
|
|
88
|
+
- Use --connections for lower risk
|
|
89
|
+
- Prefer organic flows ('visit', 'funnel', 'apply') when possible \u2014 those
|
|
90
|
+
have a purpose and don't trip the same heuristic.
|
|
91
|
+
|
|
92
|
+
WHEN TO USE
|
|
93
|
+
- You have hundreds of contacts in people.json without About text.
|
|
94
|
+
- You want to backfill in a controlled batch (\u2264 10 per day) before reaching
|
|
95
|
+
out, so AI drafting has full context.
|
|
96
|
+
- Use --connections to keep ban risk low.
|
|
97
|
+
`),process.exit(0));function fn(e){try{return new RegExp(e,"i")}catch(t){console.error(`Invalid regex for --match-title: ${t.message}`),process.exit(1)}}var mn=new Set(["pending","sent_with_note","sent_without_note"]);function pn(e){return!e.about||!e.about.trim()}function hn(e){return!mn.has(e.connectionStatus)}function At(){let e=W(),t=ke(),o=new Set,n=new Set;for(let i of Object.values(t))i.profileUrl&&o.add(i.profileUrl),(i.unread===!0||i.actionNeeded==="reply"||i.situation==="needs_our_reply"||i.conversationStatus==="unanswered_by_us")&&i.profileUrl&&n.add(i.profileUrl);let r=Object.entries(e).filter(([i,a])=>i&&i.startsWith("http")).filter(([,i])=>pn(i)).filter(([,i])=>hn(i)).filter(([i])=>!n.has(i)).map(([i,a])=>({profileUrl:i,name:a.name,person:a,hasConversation:o.has(i)}));re&&(r=r.filter(i=>i.person.connectionStatus==="connected")),_&&(r=r.filter(i=>_.test(i.person.title||"")));function l(i){let a=i.person.connectionStatus==="connected";return a&&i.hasConversation?1:a?2:_&&_.test(i.person.title||"")?3:i.hasConversation?4:5}return r.sort((i,a)=>{let f=l(i),c=l(a);if(f!==c)return f-c;let m=i.person.lastFullVisitAt||"",u=a.person.lastFullVisitAt||"";return m.localeCompare(u)}),r.map(i=>({profileUrl:i.profileUrl,name:i.name,source:"enrich-profile"}))}function gn(){let e=W(),t=Object.keys(e).length,o=Object.values(e).filter(m=>m.about&&m.about.trim()).length,n=t-o,s=At(),r={connWithConv:0,conn:0,titleMatch:0,withConv:0,other:0},l=e,i=ke(),a=new Set(Object.values(i).map(m=>m.profileUrl).filter(Boolean)),f=Object.values(i).filter(m=>m.profileUrl&&(m.unread===!0||m.actionNeeded==="reply"||m.situation==="needs_our_reply"||m.conversationStatus==="unanswered_by_us")).length,c=0;for(let m of s){let u=l[m.profileUrl],h=u.connectionStatus==="connected",v=_&&_.test(u.title||""),w=a.has(m.profileUrl);u.lastFullVisitAt||c++,h&&w?r.connWithConv++:h?r.conn++:v?r.titleMatch++:w?r.withConv++:r.other++}console.log(`
|
|
98
|
+
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`),console.log(" PROFILE ENRICHMENT QUEUE"),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),console.log(` Total people: ${t}`),console.log(` With "about": ${o} (${(o/t*100).toFixed(1)}%)`),console.log(` Missing "about": ${n}`),console.log(` Skipped (needs reply): ${f}`),console.log(` Visitable (queue): ${s.length}`),console.log(` Never fully visited: ${c} (gone first)`),_&&console.log(` Title-match filter: /${_.source}/i`),re&&console.log(" Connections-only: yes"),console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),console.log(` Tier 1 (conn+conv): ${r.connWithConv}`),console.log(` Tier 2 (connection): ${r.conn}`),console.log(` Tier 3 (title match): ${r.titleMatch}${_?"":" (no --match-title set)"}`),console.log(` Tier 4 (conversation): ${r.withConv}`),console.log(` Tier 5 (other): ${r.other}`),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),console.log(` At ${pe}/day \u2192 ~${Math.ceil(s.length/pe)} days to clear queue
|
|
99
|
+
`)}function yn(){console.log(""),console.log(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"),console.log(" \u2551 \u26A0 BAN-RISK WARNING \u2014 please read \u2551"),console.log(" \u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563"),console.log(" \u2551 This script visits LinkedIn profiles WITHOUT performing any \u2551"),console.log(" \u2551 follow-up action (no message, no connect request, no like). \u2551"),console.log(" \u2551 LinkedIn has previously flagged accounts for exactly this \u2551"),console.log(' \u2551 pattern with a "we noticed unusual activity" warning. \u2551'),console.log(" \u2551 \u2551"),console.log(" \u2551 Safer alternative: let data accumulate organically through \u2551"),console.log(" \u2551 apply / outreach / funnel / visit \u2014 those visits HAVE a \u2551"),console.log(" \u2551 purpose and don't trip the same heuristic. \u2551"),console.log(" \u2551 \u2551"),console.log(" \u2551 If you proceed, keep --max small (\u226410) and run at most once \u2551"),console.log(" \u2551 per day. Your account, your call. \u2551"),console.log(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"),console.log("")}async function wn(){if(console.log(`
|
|
54
100
|
LinkedIn Profile Enricher
|
|
55
|
-
`),
|
|
56
|
-
`);return}let t=
|
|
101
|
+
`),cn){gn();return}yn(),Le&&(console.log(""),console.log(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"),console.log(" \u2551 \u26A0 --with-experience: extra ban-risk warning \u2551"),console.log(" \u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563"),console.log(" \u2551 Each visit now does TWO page loads (main + /details/ \u2551"),console.log(" \u2551 experience/). That doubles LinkedIn's view-counter signal \u2551"),console.log(" \u2551 per profile. Keep --max low (\u226410) and run rarely. \u2551"),console.log(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"),console.log(""));let e=At();if(console.log(` Queue size: ${e.length}`),console.log(` Max visits this session: ${pe}`),_&&console.log(` Title filter: /${_.source}/i`),re&&console.log(" Connections only: yes"),Le&&console.log(" With experience: yes (2\xD7 page loads per profile)"),console.log(""),e.length===0){console.log(` Nothing to enrich \u2014 every visitable profile already has "about".
|
|
102
|
+
`);return}let t=re&&_?"connections+title":re?"connections":_?`title=${_.source}`:"all",o=pt("enrich-profiles",t),{browser:n,page:s}=await ze();try{let r=await at(s,e,{maxVisits:pe,verbose:un,skipRecentDays:7,extractExperience:Le}),l=W(),i=0;for(let a of e.slice(0,r.visited+r.skipped))l[a.profileUrl]?.about?.trim()&&i++;console.log(`
|
|
57
103
|
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`),console.log(" Enrichment Complete"),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),console.log(` Visited: ${r.visited}`),console.log(` Skipped (recent): ${r.skipped}`),console.log(` Errors: ${r.errors}`),console.log(` Have "about" now: ${i} / ${r.visited+r.skipped}`),console.log(`\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
|
|
58
|
-
`),
|
|
59
|
-
Error:`,r.message),
|
|
104
|
+
`),Ee(o,"success",r)}catch(r){console.error(`
|
|
105
|
+
Error:`,r.message),Ee(o,"error",null,r.message)}finally{await n.close().catch(()=>{})}}wn().catch(e=>{console.error("Enrich-profiles failed:",e),process.exit(1)});
|