ilml-plugin-linkedin 1.12.0 → 1.13.1
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 +36 -0
- package/dist/applyQueue.mjs +4 -4
- package/dist/enrichProfile.mjs +267 -19
- package/dist/enrichProfiles.mjs +282 -48
- package/dist/funnelRunner.mjs +281 -47
- package/dist/profileHistory.mjs +4 -4
- package/dist/readPost.mjs +76 -0
- package/dist/run.mjs +285 -51
- package/dist/scout.mjs +7 -7
- package/dist/syncAll.mjs +342 -90
- package/dist/verifyAbout.mjs +244 -10
- package/dist/visit.mjs +281 -47
- package/ilml-plugin.json +185 -28
- package/package.json +1 -1
package/dist/visit.mjs
CHANGED
|
@@ -1,63 +1,297 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Kt=Object.defineProperty;var nt=(e,t)=>()=>(e&&(t=e(e=0)),t);var ge=(e,t)=>{for(var n in t)Kt(e,n,{get:t[n],enumerable:!0})};async function $(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function ot(e){return await e.evaluate(()=>{let t=document.querySelectorAll("div.artdeco-modal--is-open");for(let o of t){let r=o.innerText||"",s=r.includes("Premium")||r.includes("premium")||r.includes("Upgrade")||r.includes("upgrade"),i=r.includes("Try for")||r.includes("free trial")||r.includes("/month")||r.includes("per month")||r.includes("Start my")||r.includes("Subscribe"),c=r.includes("Get hired faster")||r.includes("Get hired 2x");if(s||i||c){let a=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(a)return a.click(),{dismissed:!0,matched:r.substring(0,80)};let m=o.querySelectorAll("button");for(let l of m){let y=l.innerText?.trim().toLowerCase()||"",u=l.getAttribute("aria-label")?.toLowerCase()||"";if(y==="not now"||y==="no thanks"||y==="dismiss"||u.includes("dismiss"))return l.click(),{dismissed:!0,matched:r.substring(0,80)}}}}let n=document.querySelector(".premium-upsell-link")||document.querySelector("[data-test-premium-upsell]")||document.querySelector(".premium-hub-upsell");if(n){let o=n.closest('[class*="modal"]')?.querySelector('button[aria-label="Dismiss"]')||n.closest('[class*="banner"]')?.querySelector('button[aria-label="Close"]');if(o)return o.click(),{dismissed:!0,matched:"premium-banner"}}return!1})}var se=nt(()=>{});var ht={};ge(ht,{extractCertificationsFromDetails:()=>_n,extractEducationFromDetails:()=>En,extractExperienceFromDetails:()=>xn,extractFeaturedFromDetails:()=>$n,extractRecommendationsFromDetails:()=>In,extractSkillsFromDetails:()=>An});async function xn(e,t){let n=t.replace(/\/+$/,"")+"/details/experience/";try{await e.goto(n,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3);let o=e.url();if(/\/(login|authwall|checkpoint)/i.test(o))throw new Error(`Session expired \u2014 bounced to ${o} when fetching /details/experience/`);for(let s=0;s<5;s++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await $(900);await $(1e3);let r=0;for(;r<5&&await e.evaluate(()=>{for(let i of document.querySelectorAll("button"))if(/^Load more$/i.test((i.textContent||"").trim()))return i.click(),!0;return!1});)r++,await $(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await $(700);return await e.evaluate(()=>{let s=document.querySelector("main");if(!s)return[];function i(l){let y=[];for(let u of l.querySelectorAll("div")){let f=Array.from(u.children).filter(v=>v.tagName==="DIV");if(f.length<3)continue;let C=f.filter(v=>(v.textContent||"").trim().length>50);C.length<3||(u.textContent||"").length<500||y.push({el:u,count:C.length,totalText:(u.textContent||"").length})}return y.sort((u,f)=>f.count-u.count||u.totalText-f.totalText),y[0]?.el}let c=i(s);if(!c)return[];let a=Array.from(c.children).filter(l=>l.tagName==="DIV").filter(l=>(l.textContent||"").trim().length>50);function m(l){let y=l[0]||null,u=null,f=null;if(l[1]){let b=l[1].split("\xB7").map(I=>I.trim());u=b[0]||null,b[1]&&(f=b[1])}let C=l.findIndex(b=>/(\d{4}|present)/i.test(b)&&/(-|–|—)/i.test(b)&&b.length<80),v=null,_=null;if(C>=0){let b=l[C].split("\xB7").map(I=>I.trim());v=b[0]||null,b[1]&&(_=b[1])}let h=null,g=-1;if(C>=0&&l[C+1]){let b=l[C+1],I=/^[>*\-•]|^>/.test(b),te=/https?:\/\//.test(b),D=/\d{4}/.test(b),me=/,/.test(b)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(b);!I&&!te&&!D&&b.length<100&&me&&(h=b,g=C+1)}let x=null,ee=-1,q=l[l.length-1];if(q&&/and\s+\+\d+\s+skills?$/i.test(q)){ee=l.length-1;let b=q.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);b&&(x={listed:b[1].split(",").map(I=>I.trim()),additional:parseInt(b[2],10)})}let W=new Set([0,1,C,g,ee].filter(b=>b>=0)),T=l.filter((b,I)=>!W.has(I)),ve=T.length>0?T.join(`
|
|
2
2
|
|
|
3
|
-
`):null;return{title:y,company:
|
|
4
|
-
`).map(f=>f.trim()).filter(f=>f&&f.length<5e3);return m(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
`),await e.close(),process.exit(1)}return{browser:e,page:o}}oe();import"dotenv/config";import*as $ from"fs";import*as x from"path";import{fileURLToPath as Wt}from"url";var Gt=Wt(import.meta.url),Yt=x.dirname(x.dirname(Gt)),F=process.env.DATA_DIR?x.resolve(process.env.DATA_DIR,"collected-profiles"):x.join(Yt,"collected-profiles"),we=x.join(F,"people.json"),Mn=x.join(F,"jobs.json"),Fn=x.join(F,"quota.json"),Pn=x.join(F,"conversations.json"),qn=x.join(F,"sync-state.json"),Un=x.join(F,"application-questions.json"),be=x.join(F,"profile-history");var Z=null,zt=null,Kt=null,Qt=null,Zt=null,Xt=null;function Ze(){Z=null,zt=null,Kt=null,Qt=null,Zt=null,Xt=null}function Xe(){$.existsSync(F)||$.mkdirSync(F,{recursive:!0})}function et(e,t){let o=JSON.stringify(t,null,2),n=e+".tmp";$.writeFileSync(n,o);for(let s=0;s<3;s++)try{$.renameSync(n,e);return}catch(r){if(s<2&&(r.code==="EPERM"||r.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw r}}function tt(e,t){if(!$.existsSync(e))return null;try{let o=JSON.parse($.readFileSync(e,"utf-8"));try{$.copyFileSync(e,e+".backup")}catch{}return o}catch(o){console.error(`[!] ${t} is corrupted: ${o.message}`),console.error(` File: ${x.resolve(e)}`);let n=e+".backup";if($.existsSync(n))try{let s=JSON.parse($.readFileSync(n,"utf-8"));console.error(` Restored from ${n}`);try{$.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{$.copyFileSync(e,e+".corrupted")}catch{}return null}}function eo(){return new Date().toISOString().split("T")[0]}var to=["name","title","location","company","connectionDegree","connectionsCount","mutualConnections","photoUrl","hasVerifiedBadge","about","currentCompany","currentSchool","connectionsLevel","mutualConnectionsCount","followers","openToWork","hiring","topSkills","availableSections","experience","featuredLinks","_lastEnrichedAt"],oo=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function Se(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function no(){$.existsSync(be)||$.mkdirSync(be,{recursive:!0})}function ot(e){let t=Se(e);return t?x.join(be,`${t}.json`):null}function so(e){let t=ot(e);return t?tt(t,`profile-history/${Se(e)}.json`)||[]:[]}function ro(e,t){let o=ot(e);if(!o)return;no();let n=so(e);n.unshift(t);try{et(o,n)}catch(s){console.error(`[!] Failed to append profile-history for ${Se(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 io(e,t){if(!e)return[];let o=[];for(let n of oo){let s=e[n],r=t[n];Ke(s)||Ke(r)||Qe(s)!==Qe(r)&&o.push(n)}return o}function lo(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 ne(){return Z||(Xe(),Z=tt(we,"people.json")||{},Z)}function ao(e){Xe(),Z=e;try{et(we,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${x.resolve(we)}`)}}function ve(e,t={}){if(!e)return null;let o=ne(),n=eo(),s=new Date().toISOString(),r=o[e];if(r){let i=io(r,t);i.length>0&&(ro(e,{capturedAt:s,previousLastUpdated:r.lastUpdated||null,changedFields:i,snapshot:lo(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 u of to)if(t[u]!=null){if(Array.isArray(t[u])&&t[u].length===0&&Array.isArray(r[u])&&r[u].length>0)continue;r[u]=t[u]}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 ao(o),o[e]}async function uo(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 A(3e3);let n=e.url();return n.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${n.slice(0,80)}`),!0}async function rt(e,t,o={}){let{extractExperience:n=!1}=o;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await A(3e3),await Je(e)&&(console.log(" Dismissed Premium overlay"),await A(1500),await uo(e,t));let r=0;for(let l=0;l<2;l++){let m=await e.evaluate(()=>document.body.scrollHeight);for(let y=1;y<=6;y++)await e.evaluate(c=>window.scrollTo(0,c),m*y/6),await A(900);let a=await e.evaluate(()=>document.body.scrollHeight);if(a===r)break;r=a}await A(800);let i=await e.evaluate(()=>{let l=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"]),m=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"]),a=h=>{let w=(h||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(w)},y={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 y;let f=[...Array.from(c.querySelectorAll("h1")),...Array.from(c.querySelectorAll("h2"))],C=Array.from(c.querySelectorAll("h2")),S=f.find(h=>{let w=h.textContent&&h.textContent.trim(),b=(w||"").replace(/\s*\(\d+\)$/,"").trim();return w&&w.length>1&&w.length<100&&!l.has(b)&&!m.has(b)}),E=S?S.textContent.trim():null,p=S?S.parentElement:null;for(;p&&p!==c&&!Array.from(p.children).filter(w=>w.tagName==="P").some(w=>{let b=w.textContent&&w.textContent.trim();return b&&b.length>5&&!a(b)});)p=p.parentElement;let g=null,D=null,ee=null,V=null;if(p&&p!==c){let h=Array.from(p.children).filter(b=>b.tagName==="P").filter(b=>{let q=b.textContent&&b.textContent.trim();return q&&q.length>5&&!a(q)});if(h[0]&&(g=h[0].textContent.trim()),h[1]){let b=h[1].textContent.trim().split(/\s*[·•]\s*/);D=b[0]||null,b.length>1&&(ee=b.slice(1).join(" \xB7 "))}let w=Array.from(p.children).filter(b=>b.tagName==="DIV");for(let b=w.length-1;b>=0;b--){let q=w[b].textContent&&w[b].textContent.trim();if(q&&!(E&&q.startsWith(E))&&(V=q.split(/[·•]/)[0].trim(),V))break}}let le=null;if(p){let h=p.querySelectorAll("p, span, div");for(let w of h){let b=(w.textContent||"").trim().replace(/^[·•]\s*/,"");if(b==="1st"||b==="2nd"||b==="3rd"){le=b;break}}}let ae=!!c.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),ce=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),v=ce&&ce.src||null,_=c.textContent||"",ue=null,de=_.match(/(\d+\+?)\s+connections\b/i);de&&(ue=de[1]+" connections");let Q=null,Me=_.match(/(\d+)\s+mutual connection/i),Fe=_.match(/and\s+(\d+)\s+other mutual/i),Tt=_.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):Tt&&(Q=2);let Pe=null,qe=null,Ue=C.find(h=>h.textContent&&h.textContent.trim()==="About");if(Ue){let h=Ue.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let w=(h.textContent||"").trim();w=w.replace(/^About\s*/,"").trim();let b=w.match(/Top skills\s*(.+?)$/i);if(b){let ye=b[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Ot=>Ot.trim()).filter(Boolean);ye.length>0&&ye.length<10&&(qe=ye)}w=w.split(/\n?…\s*more/i)[0].trim(),w=w.split(/\n?\.\.\.\s*more/i)[0].trim(),w=w.split(/\bTop skills\b/i)[0].trim(),w=w.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),Pe=w||null}}let Be=null,Ve=C.find(h=>h.textContent&&h.textContent.trim()==="Activity");if(Ve){let h=Ve.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let w=(h.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);w&&(Be=parseInt(w[1].replace(/,/g,""),10))}}let Dt=[...new Set(C.map(h=>(h.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(h=>h&&h.length>1&&h.length<60&&h!==E).filter(h=>l.has(h)))],te=document.body.textContent||"",Rt=/#OpenToWork\b/i.test(te)||/\bOpen to work\b/.test(te),jt=/#Hiring\b/i.test(te)||/\bI'?m hiring\b/i.test(te)||/\bWe are hiring\b/i.test(te);return{name:E,title:g,location:V,currentCompany:D,currentSchool:ee,connectionDegree:le,hasVerifiedBadge:ae,photoUrl:v,connectionsLevel:ue,mutualConnectionsCount:Q,followers:Be,openToWork:Rt,hiring:jt,about:Pe,topSkills:qe,availableSections:Dt}});console.log(`Viewed: ${i.name} - ${i.title}`);let u=null;if(n){let{extractExperienceFromDetails:l}=await Promise.resolve().then(()=>(st(),nt));u=await l(e,t),console.log(` + Experience: ${u.length} entries`)}return{...i,profileUrl:t,...u!==null&&{experience:u}}}catch(s){console.error(`Error viewing profile ${t}:`,s.message);try{await e.goto("about:blank",{timeout:1e4}),await A(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 fo}from"url";var mo=fo(import.meta.url),po=T.dirname(T.dirname(mo)),W=process.env.DATA_DIR?T.resolve(process.env.DATA_DIR,"market-research"):T.join(po,"market-research"),ho=T.join(W,"scouted-jobs.json"),go=T.join(W,"discovered-people.json"),it=T.join(W,"visit-log.json"),ts=T.join(W,"companies.json"),os=T.join(W,"job-decisions.json");function yo(){R.existsSync(W)||R.mkdirSync(W,{recursive:!0})}function wo(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 i=Date.now();for(;Date.now()-i<200;);continue}throw r}}function ke(e){try{if(R.existsSync(e))return JSON.parse(R.readFileSync(e,"utf-8"))}catch{}return null}function lt(){se=null,So=null,re=null,vo=null,J=null}var se=null;function bo(){return se||(se=ke(ho)||{},se)}var So=null;var re=null;function me(){return re||(re=ke(go)||{},re)}var vo=null;var J=null;function X(){return J||(J=ke(it)||{visits:[]},Array.isArray(J.visits)||(J.visits=[]),J)}function at(e,t={}){if(!e)return;yo();let o=X();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{wo(it,o)}catch(s){console.error(`[!] Failed to save visit-log.json: ${s.message}`)}}function ct(e){let t=X();for(let o=t.visits.length-1;o>=0;o--)if(t.visits[o].profileUrl===e)return t.visits[o].date;return null}function ut(){let e=bo(),t=me(),o=Object.values(e),n=Object.values(t),s={};for(let c of o)c.company&&(s[c.company]=(s[c.company]||0)+1);let r=Object.entries(s).sort((c,f)=>f[1]-c[1]).slice(0,5).map(([c,f])=>`${c} (${f})`),i={};for(let c of o)for(let f of c.techStack||[])i[f]=(i[f]||0)+1;let u=Object.entries(i).sort((c,f)=>f[1]-c[1]).slice(0,8).map(([c,f])=>`${c} (${f})`),l=X(),m=new Date().toISOString().slice(0,10),a=l.visits.filter(c=>c.date.startsWith(m)).length,y=new Set(l.visits.map(c=>c.profileUrl)).size;return{totalJobs:o.length,totalRecruiters:n.length,topCompanies:r,topTech:u,totalVisited:y,todayVisited:a,lastScoutDate:o.length>0?o.sort((c,f)=>(f.scoutedAt||"").localeCompare(c.scoutedAt||""))[0]?.scoutedAt:null}}oe();async function dt(e,t,o={}){let{maxVisits:n=50,delayBetween:s=4e3,skipRecentDays:r=7,verbose:i=!1,extractExperience:u=!1}=o,l={visited:0,skipped:0,errors:0},m=Date.now()-r*24*60*60*1e3;for(let a of t){if(l.visited>=n)break;if(!a.profileUrl)continue;let y=ct(a.profileUrl);if(y&&new Date(y).getTime()>m){l.skipped++;continue}try{let c=await rt(e,a.profileUrl,{extractExperience:u}),f=a.source||"visit";if(c){let S={...c,source:f};u&&Array.isArray(c.experience)&&c.experience.length>0&&(S._lastEnrichedAt=new Date().toISOString()),ve(a.profileUrl,S)}at(a.profileUrl,{name:c?.name||a.name||null,source:f}),l.visited++,i?console.log(` [${l.visited}] ${c?.name||a.profileUrl} \u2014 ${c?.title?.slice(0,40)||"?"}`):l.visited%10===0&&console.log(` Visited: ${l.visited}`);let C=Math.random()*4e3;await A(s+C)}catch(c){l.errors++,i&&console.error(` Error visiting ${a.name||a.profileUrl}: ${c.message?.slice(0,60)}`);let f=(c.message||"").toLowerCase();if(f.includes("detached")||f.includes("session closed")||f.includes("target closed")||f.includes("session expired")||f.includes("bounced to")||f.includes("authwall")||f.includes("checkpoint")||f.includes("redirected to login")){console.log(" Fatal browser/session error \u2014 stopping visits");break}}}return l}function ft(e={}){let{limit:t=150,revisitDays:o=14}=e,n=X(),s=new Set(n.visits?.map(p=>p.profileUrl)||[]),r=new Map;for(let p of n.visits||[]){let g=r.get(p.profileUrl);(!g||p.date>g)&&r.set(p.profileUrl,p.date)}let i=Date.now()-7*24*60*60*1e3,u=Date.now()-o*24*60*60*1e3;function l(p){let g=r.get(p);return g&&new Date(g).getTime()>i}let m=me(),a=Object.entries(m).filter(([p])=>!s.has(p)).map(([p,g])=>({profileUrl:p,name:g.name,source:"new-discovered",priority:1,jobCount:g.jobIds?.length||0})),y=ne(),c=Object.entries(y).filter(([p,g])=>g.connectionStatus==="connected"||l(p)?!1:(g.jobCount||g.jobIds?.length||0)>=2).map(([p,g])=>({profileUrl:p,name:g.name,source:"active-recruiter",priority:2,jobCount:g.jobCount||g.jobIds?.length||0})),f=Object.entries(y).filter(([p,g])=>{let D=g.connectionStatus;return!(!D||D==="connected"||D==="pending"||D==="sent_without_note"||D==="sent_with_note"||l(p)||(g.jobCount||g.jobIds?.length||0)>=2)}).map(([p,g])=>({profileUrl:p,name:g.name,source:"unconnected",priority:3,jobCount:g.jobCount||g.jobIds?.length||0})),C=[...r.entries()].filter(([p,g])=>new Date(g).getTime()<u).map(([p,g])=>({profileUrl:p,name:null,source:"revisit",priority:4,lastVisit:g})),S=p=>p.sort(()=>Math.random()-.5);return a.sort((p,g)=>g.jobCount-p.jobCount),c.sort((p,g)=>g.jobCount-p.jobCount),S(f),S(C),[...a,...c,...f,...C].slice(0,t)}function mt(){let e=me();return Object.entries(e).map(([t,o])=>({profileUrl:t,name:o.name,source:"discovered"}))}function Ce(){let e=ne();return Object.entries(e).filter(([,t])=>{let o=t.connectionStatus;return o&&o!=="connected"&&o!=="pending"&&o!=="sent_without_note"&&o!=="sent_with_note"}).map(([t,o])=>({profileUrl:t,name:o.name,source:"unconnected"}))}function $e(e=14){let t=X(),o=Date.now()-e*24*60*60*1e3,n=new Map;for(let s of t.visits){let r=n.get(s.profileUrl);(!r||s.date>r.date)&&n.set(s.profileUrl,s)}return[...n.entries()].filter(([,s])=>new Date(s.date).getTime()<o).map(([s,r])=>({profileUrl:s,name:r.name,source:"revisit"}))}import"dotenv/config";import*as j from"fs";import*as U from"path";import{fileURLToPath as Eo}from"url";import"dotenv/config";import{createGraphClient as ko,resolveToken as Co}from"@ilivemylife/graph-sdk";import{config as $o}from"dotenv";$o();var pt=Co()||process.env.TOKEN;pt||(console.error(`
|
|
3
|
+
`):null;return{title:y,company:u,employmentType:f,dates:v,duration:_,location:h,description:ve,skills:x,_raw:l}}return a.map(l=>{let u=(l.innerText||"").trim().split(`
|
|
4
|
+
`).map(f=>f.trim()).filter(f=>f&&f.length<5e3);return m(u)}).filter(l=>l.title)})}catch(o){if(/session expired|bounced to|authwall|checkpoint/i.test(o.message||""))throw o;return console.error(`extractExperienceFromDetails failed for ${t}: ${o.message?.slice(0,120)}`),[]}}async function le(e,t,n){let o=t.replace(/\/+$/,"")+`/details/${n}/`;await e.goto(o,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3);let r=e.url();if(/\/(login|authwall|checkpoint)/i.test(r))throw new Error(`Session expired \u2014 bounced to ${r} when fetching /details/${n}/`);if(!r.toLowerCase().includes(`/details/${n.toLowerCase()}/`))throw new Error(`Section /details/${n}/ not available on profile (landed on ${r})`);for(let i=0;i<4;i++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await $(700);await $(800);let s=0;for(;s<5&&await e.evaluate(()=>{for(let c of document.querySelectorAll("button"))if(/^Load more$/i.test((c.textContent||"").trim()))return c.click(),!0;return!1});)s++,await $(1300),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await $(600)}async function ce(e,t,n,o){try{return await o()}catch(r){let s=r.message||"";if(/session expired|bounced to|authwall|checkpoint/i.test(s))throw r;return/not available on profile/i.test(s)?(console.log(` (${t}: section not on profile \u2014 skipped)`),[]):(console.error(`${n} failed for ${e}: ${s.slice(0,120)}`),[])}}async function $n(e,t){return ce(t,"featured","extractFeaturedFromDetails",async()=>(await le(e,t,"featured"),await e.evaluate(`(() => {
|
|
5
|
+
${ae}
|
|
6
|
+
|
|
7
|
+
const main = document.querySelector('main');
|
|
8
|
+
if (!main) return [];
|
|
9
|
+
const container = findEntryContainer(main);
|
|
10
|
+
if (!container) return [];
|
|
11
|
+
|
|
12
|
+
const entries = Array.from(container.children)
|
|
13
|
+
.filter(c => c.tagName === 'DIV')
|
|
14
|
+
.filter(c => (c.textContent || '').trim().length > 30);
|
|
15
|
+
|
|
16
|
+
return entries.map(entry => {
|
|
17
|
+
const raw = (entry.innerText || '').trim();
|
|
18
|
+
const lines = raw.split('\\n').map(l => l.trim()).filter(l => l && l.length < 2000);
|
|
19
|
+
|
|
20
|
+
// External link from any anchor inside the card (filter LinkedIn-internal)
|
|
21
|
+
const anchors = Array.from(entry.querySelectorAll('a[href]'));
|
|
22
|
+
const externalAnchor = anchors.find(a => {
|
|
23
|
+
const h = a.href || '';
|
|
24
|
+
return h.startsWith('http') &&
|
|
25
|
+
!h.includes('linkedin.com/in/') &&
|
|
26
|
+
!h.includes('linkedin.com/posts/') &&
|
|
27
|
+
!h.includes('#');
|
|
28
|
+
});
|
|
29
|
+
const url = externalAnchor?.href || anchors[0]?.href || null;
|
|
30
|
+
|
|
31
|
+
const title = lines[0] || null;
|
|
32
|
+
const caption = lines[1] && lines[1] !== title ? lines[1] : null;
|
|
33
|
+
|
|
34
|
+
return { title, caption, url, _raw: lines };
|
|
35
|
+
}).filter(e => {
|
|
36
|
+
if (!e.title) return false;
|
|
37
|
+
// Reject "People You May Know" sidebar cards: signature is
|
|
38
|
+
// exactly [title, "View"] with no url/caption beyond "View".
|
|
39
|
+
if (e._raw.length === 2 && e._raw[1] === 'View') return false;
|
|
40
|
+
// Reject "Other profiles you may know" widget cards: caption is
|
|
41
|
+
// just a connection-degree marker (e.g. "\xB7 3rd", "\xB7 2nd").
|
|
42
|
+
if (e.caption && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.caption.trim())) return false;
|
|
43
|
+
return true;
|
|
44
|
+
});
|
|
45
|
+
})()`)))}async function En(e,t){return ce(t,"education","extractEducationFromDetails",async()=>(await le(e,t,"education"),await e.evaluate(`(() => {
|
|
46
|
+
${ae}
|
|
47
|
+
|
|
48
|
+
const main = document.querySelector('main');
|
|
49
|
+
if (!main) return [];
|
|
50
|
+
const container = findEntryContainer(main);
|
|
51
|
+
if (!container) return [];
|
|
52
|
+
|
|
53
|
+
const entries = Array.from(container.children)
|
|
54
|
+
.filter(c => c.tagName === 'DIV')
|
|
55
|
+
.filter(c => (c.textContent || '').trim().length > 30);
|
|
56
|
+
|
|
57
|
+
return entries.map(entry => {
|
|
58
|
+
const raw = (entry.innerText || '').trim();
|
|
59
|
+
const lines = raw.split('\\n').map(l => l.trim()).filter(l => l && l.length < 5000);
|
|
60
|
+
|
|
61
|
+
const school = lines[0] || null;
|
|
62
|
+
const degree = lines[1] || null;
|
|
63
|
+
const dates = lines.find(l =>
|
|
64
|
+
/(\\d{4})/.test(l) &&
|
|
65
|
+
/(-|\u2013|\u2014)/i.test(l) &&
|
|
66
|
+
l.length < 80
|
|
67
|
+
) || null;
|
|
68
|
+
const used = new Set([0, 1, dates ? lines.indexOf(dates) : -1].filter(i => i >= 0));
|
|
69
|
+
const descLines = lines.filter((_, i) => !used.has(i));
|
|
70
|
+
const description = descLines.length > 0 ? descLines.join(' / ') : null;
|
|
71
|
+
|
|
72
|
+
return { school, degree, dates, description, _raw: lines };
|
|
73
|
+
}).filter(e => {
|
|
74
|
+
if (!e.school) return false;
|
|
75
|
+
// Reject "People You May Know" sidebar cards: [title, "View"].
|
|
76
|
+
if (e._raw.length === 2 && e._raw[1] === 'View') return false;
|
|
77
|
+
// Reject related-profile widget: "degree" parsed as the
|
|
78
|
+
// connection-degree marker ("\xB7 3rd") instead of a real degree.
|
|
79
|
+
if (e.degree && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.degree.trim())) return false;
|
|
80
|
+
return true;
|
|
81
|
+
});
|
|
82
|
+
})()`)))}async function An(e,t){return ce(t,"skills","extractSkillsFromDetails",async()=>(await le(e,t,"skills"),await e.evaluate(`(() => {
|
|
83
|
+
${ae}
|
|
84
|
+
|
|
85
|
+
const main = document.querySelector('main');
|
|
86
|
+
if (!main) return [];
|
|
87
|
+
const container = findEntryContainer(main);
|
|
88
|
+
if (!container) return [];
|
|
89
|
+
|
|
90
|
+
const entries = Array.from(container.children)
|
|
91
|
+
.filter(c => c.tagName === 'DIV')
|
|
92
|
+
.filter(c => (c.textContent || '').trim().length > 1);
|
|
93
|
+
|
|
94
|
+
const seen = new Set();
|
|
95
|
+
const skills = [];
|
|
96
|
+
for (const entry of entries) {
|
|
97
|
+
const raw = (entry.innerText || '').trim();
|
|
98
|
+
const lines = raw.split('\\n').map(l => l.trim()).filter(Boolean);
|
|
99
|
+
if (lines.length === 0) continue;
|
|
100
|
+
|
|
101
|
+
const name = lines[0];
|
|
102
|
+
if (!name || name.length > 100 || seen.has(name.toLowerCase())) continue;
|
|
103
|
+
seen.add(name.toLowerCase());
|
|
104
|
+
|
|
105
|
+
let endorsements = null;
|
|
106
|
+
for (const l of lines.slice(1)) {
|
|
107
|
+
const m = l.match(/(\\d+)\\s+endorsement/i);
|
|
108
|
+
if (m) { endorsements = parseInt(m[1], 10); break; }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
skills.push({ name, endorsements, _raw: lines });
|
|
112
|
+
}
|
|
113
|
+
return skills;
|
|
114
|
+
})()`)))}async function _n(e,t){return ce(t,"certifications","extractCertificationsFromDetails",async()=>(await le(e,t,"certifications"),await e.evaluate(`(() => {
|
|
115
|
+
${ae}
|
|
116
|
+
|
|
117
|
+
const main = document.querySelector('main');
|
|
118
|
+
if (!main) return [];
|
|
119
|
+
const container = findEntryContainer(main);
|
|
120
|
+
if (!container) return [];
|
|
121
|
+
|
|
122
|
+
const entries = Array.from(container.children)
|
|
123
|
+
.filter(c => c.tagName === 'DIV')
|
|
124
|
+
.filter(c => (c.textContent || '').trim().length > 20);
|
|
125
|
+
|
|
126
|
+
return entries.map(entry => {
|
|
127
|
+
const raw = (entry.innerText || '').trim();
|
|
128
|
+
const lines = raw.split('\\n').map(l => l.trim()).filter(l => l && l.length < 2000);
|
|
129
|
+
|
|
130
|
+
const name = lines[0] || null;
|
|
131
|
+
const issuer = lines[1] || null;
|
|
132
|
+
const issueDate = lines.find(l => /^Issued\\b/i.test(l)) || null;
|
|
133
|
+
const expiryDate = lines.find(l => /Expir(es|ed)\\b/i.test(l)) || null;
|
|
134
|
+
const credentialId = (lines.find(l => /credential id/i.test(l)) || '')
|
|
135
|
+
.replace(/^.*credential id[:\\s]*/i, '').trim() || null;
|
|
136
|
+
|
|
137
|
+
return { name, issuer, issueDate, expiryDate, credentialId, _raw: lines };
|
|
138
|
+
}).filter(e => e.name);
|
|
139
|
+
})()`)))}async function In(e,t){return ce(t,"recommendations","extractRecommendationsFromDetails",async()=>(await le(e,t,"recommendations"),await e.evaluate(`(() => {
|
|
140
|
+
${ae}
|
|
141
|
+
|
|
142
|
+
const main = document.querySelector('main');
|
|
143
|
+
if (!main) return [];
|
|
144
|
+
const container = findEntryContainer(main);
|
|
145
|
+
if (!container) return [];
|
|
146
|
+
|
|
147
|
+
const entries = Array.from(container.children)
|
|
148
|
+
.filter(c => c.tagName === 'DIV')
|
|
149
|
+
.filter(c => (c.textContent || '').trim().length > 50);
|
|
150
|
+
|
|
151
|
+
return entries.map(entry => {
|
|
152
|
+
const raw = (entry.innerText || '').trim();
|
|
153
|
+
const lines = raw.split('\\n').map(l => l.trim()).filter(l => l && l.length < 5000);
|
|
154
|
+
|
|
155
|
+
const recommender = lines[0] || null;
|
|
156
|
+
const recommenderTitle = lines[1] || null;
|
|
157
|
+
const relationship = lines.find(l =>
|
|
158
|
+
/\\b(was |worked |reported |managed |taught |studied )\\b/i.test(l) &&
|
|
159
|
+
l.length < 200
|
|
160
|
+
) || null;
|
|
161
|
+
const date = lines.find(l => /(January|February|March|April|May|June|July|August|September|October|November|December)\\s+\\d{1,2}.*\\d{4}/i.test(l)) || null;
|
|
162
|
+
// Recommendation text is the longest non-meta line
|
|
163
|
+
const text = [...lines].sort((a, b) => b.length - a.length)[0] || '';
|
|
164
|
+
|
|
165
|
+
return { recommender, recommenderTitle, relationship, date, text, _raw: lines };
|
|
166
|
+
}).filter(e => {
|
|
167
|
+
if (!e.recommender || !e.text) return false;
|
|
168
|
+
// Reject "People You May Know" sidebar cards: [title, "View"].
|
|
169
|
+
if (e._raw.length === 2 && e._raw[1] === 'View') return false;
|
|
170
|
+
// Reject related-profile widget: recommenderTitle is the
|
|
171
|
+
// connection-degree marker, not a real job title.
|
|
172
|
+
if (e.recommenderTitle && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.recommenderTitle.trim())) return false;
|
|
173
|
+
return true;
|
|
174
|
+
});
|
|
175
|
+
})()`)))}var ae,gt=nt(()=>{se();ae=`
|
|
176
|
+
function findEntryContainer(root) {
|
|
177
|
+
const candidates = [];
|
|
178
|
+
for (const div of root.querySelectorAll('div')) {
|
|
179
|
+
const directDivs = Array.from(div.children).filter(c => c.tagName === 'DIV');
|
|
180
|
+
if (directDivs.length < 2) continue;
|
|
181
|
+
const substantial = directDivs.filter(c => (c.textContent || '').trim().length > 30);
|
|
182
|
+
if (substantial.length < 2) continue;
|
|
183
|
+
if ((div.textContent || '').length < 200) continue;
|
|
184
|
+
|
|
185
|
+
// Reject "People You May Know" suggestion containers: every substantial
|
|
186
|
+
// child is exactly [title, "View"] (a tiny suggestion card with a single
|
|
187
|
+
// "View" CTA). Real section entries always have richer per-child content
|
|
188
|
+
// (multiple text lines per entry).
|
|
189
|
+
const allLookLikePYMK = substantial.every(c => {
|
|
190
|
+
const lines = (c.innerText || '').trim().split('\\n').map(l => l.trim()).filter(Boolean);
|
|
191
|
+
return lines.length === 2 && lines[1] === 'View';
|
|
192
|
+
});
|
|
193
|
+
if (allLookLikePYMK) continue;
|
|
194
|
+
|
|
195
|
+
// Reject "Other profiles you may know" / related-profile widget:
|
|
196
|
+
// LinkedIn shows this when /details/<section>/ has no real data
|
|
197
|
+
// (e.g. profile has no Featured at all). Every entry is a short
|
|
198
|
+
// [name, "\xB7 Nth"] card with a connection-degree marker as the only
|
|
199
|
+
// metadata. Real Featured / Education / Recommendations entries
|
|
200
|
+
// NEVER consist solely of name + degree.
|
|
201
|
+
const DEGREE_RE = /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i;
|
|
202
|
+
const allLookLikeRelatedProfiles = substantial.every(c => {
|
|
203
|
+
const lines = (c.innerText || '').trim().split('\\n').map(l => l.trim()).filter(Boolean);
|
|
204
|
+
if (lines.length > 4) return false;
|
|
205
|
+
return lines.some(l => DEGREE_RE.test(l));
|
|
206
|
+
});
|
|
207
|
+
if (allLookLikeRelatedProfiles) continue;
|
|
208
|
+
|
|
209
|
+
// Reject LinkedIn footer/legal blocks: when a /details/<section>/ page
|
|
210
|
+
// renders empty, LinkedIn falls back to "Questions? Visit our Help
|
|
211
|
+
// Center", "Select language" (35+ languages), "Recommendation
|
|
212
|
+
// transparency" and similar nav cards inside <main>. These are unique
|
|
213
|
+
// marker strings that never appear inside real section entries.
|
|
214
|
+
const containerText = div.textContent || '';
|
|
215
|
+
const FOOTER_MARKERS = [
|
|
216
|
+
'Visit our Help Center',
|
|
217
|
+
'Select language',
|
|
218
|
+
'Recommendation transparency',
|
|
219
|
+
'Manage your account and privacy',
|
|
220
|
+
'Go to your Settings',
|
|
221
|
+
'Who your viewers also viewed', // "Private to you" PYMK block on empty pages
|
|
222
|
+
'People also viewed',
|
|
223
|
+
'People you may know',
|
|
224
|
+
'More profiles for you', // LinkedIn related-profiles widget shown
|
|
225
|
+
'Other profiles you may know', // when /details/<section>/ is empty
|
|
226
|
+
];
|
|
227
|
+
if (FOOTER_MARKERS.some(m => containerText.includes(m))) continue;
|
|
228
|
+
|
|
229
|
+
candidates.push({ el: div, count: substantial.length, totalText: (div.textContent || '').length });
|
|
230
|
+
}
|
|
231
|
+
// Sort: most children first, then RICHER children (larger totalText) \u2014 real
|
|
232
|
+
// section entries dominate via content density, not just child count. The
|
|
233
|
+
// previous "smaller totalText wins" tie-break gave PYMK sidebars priority
|
|
234
|
+
// over the real Education / Recommendations lists.
|
|
235
|
+
candidates.sort((a, b) => b.count - a.count || b.totalText - a.totalText);
|
|
236
|
+
return candidates[0]?.el;
|
|
237
|
+
}
|
|
238
|
+
`});import on from"puppeteer";import{addExtra as rn}from"puppeteer-extra";import sn from"puppeteer-extra-plugin-stealth";se();import{getPluginConfig as zt}from"@ilivemylife/graph-sdk";var Qt=await zt();for(let[e,t]of Object.entries(Qt))process.env[e]===void 0&&(process.env[e]=t);var Zt=process.env.LINKEDIN_NAME,Y=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Mo=Object.freeze(new Set([Y.DRAFT,Y.CONFIRMED,Y.NEEDS_REVIEW])),Xt=Object.freeze(new Set([Y.DRAFT,Y.CONFIRMED,Y.REJECTED,Y.NEEDS_REVIEW]));import rt from"fs";import en from"path";var tn="cookies.json";function nn(){let e=process.env.ILML_SCOPE_DIR;return e?en.join(e,"plugins-state","linkedin","cookies.json"):tn}function st(){let e=nn();if(!rt.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=rt.readFileSync(e,"utf-8")}catch(o){throw new Error(`Failed to read cookies at ${e}: ${o.message}. Run: ilml linkedin login`)}let n;try{n=JSON.parse(t)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(n)||n.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return n}var it=rn(on);it.use(sn());async function lt(){let e=await it.launch({headless:!1,defaultViewport:null,protocolTimeout:3e5}),t=async()=>{console.log(`
|
|
239
|
+
Closing browser...`);try{await e.close()}catch{}process.exit(0)};process.on("SIGINT",t),process.on("SIGTERM",t);let n=await e.newPage();await n.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})});try{let o=st();await n.setCookie(...o),console.log(" Browser launched, cookies loaded.")}catch(o){console.error(`
|
|
240
|
+
[!] ${o.message}
|
|
241
|
+
`),await e.close(),process.exit(1)}return{browser:e,page:n}}se();import"dotenv/config";import*as E from"fs";import*as A from"path";import{fileURLToPath as ln}from"url";var an=ln(import.meta.url),cn=A.dirname(A.dirname(an)),B=process.env.DATA_DIR?A.resolve(process.env.DATA_DIR,"collected-profiles"):A.join(cn,"collected-profiles"),xe=A.join(B,"people.json"),nr=A.join(B,"jobs.json"),or=A.join(B,"quota.json"),rr=A.join(B,"conversations.json"),sr=A.join(B,"sync-state.json"),ir=A.join(B,"application-questions.json"),$e=A.join(B,"profile-history");var ne=null,un=null,dn=null,fn=null,mn=null,pn=null;function ut(){ne=null,un=null,dn=null,fn=null,mn=null,pn=null}function dt(){E.existsSync(B)||E.mkdirSync(B,{recursive:!0})}function ft(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";E.writeFileSync(o,n);for(let r=0;r<3;r++)try{E.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function mt(e,t){if(!E.existsSync(e))return null;try{let n=JSON.parse(E.readFileSync(e,"utf-8"));try{E.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.message}`),console.error(` File: ${A.resolve(e)}`);let o=e+".backup";if(E.existsSync(o))try{let r=JSON.parse(E.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{E.copyFileSync(o,e)}catch{}return r}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{E.copyFileSync(e,e+".corrupted")}catch{}return null}}function hn(){return new Date().toISOString().split("T")[0]}var gn=["name","title","location","company","connectionDegree","connectionsCount","mutualConnections","photoUrl","hasVerifiedBadge","about","currentCompany","currentSchool","connectionsLevel","mutualConnectionsCount","followers","openToWork","hiring","topSkills","availableSections","experience","featuredLinks","_lastEnrichedAt","featured","education","skillsFull","recommendations","certifications"],yn=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function Ee(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function wn(){E.existsSync($e)||E.mkdirSync($e,{recursive:!0})}function pt(e){let t=Ee(e);return t?A.join($e,`${t}.json`):null}function bn(e){let t=pt(e);return t?mt(t,`profile-history/${Ee(e)}.json`)||[]:[]}function Sn(e,t){let n=pt(e);if(!n)return;wn();let o=bn(e);o.unshift(t);try{ft(n,o)}catch(r){console.error(`[!] Failed to append profile-history for ${Ee(e)}: ${r.message}`)}}function at(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function ct(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function vn(e,t){if(!e)return[];let n=[];for(let o of yn){let r=e[o],s=t[o];at(r)||at(s)||ct(r)!==ct(s)&&n.push(o)}return n}function kn(e){let t=new Set(["seenCount","sources","firstSeen","lastSeen","lastUpdated","encounters","jobIds","lastFullVisitAt","lastSnapshotAt","messageSent","connectionStatus","connectionDate","connectionMethod"]),n={};for(let[o,r]of Object.entries(e))t.has(o)||(n[o]=r);return n}function ie(){return ne||(dt(),ne=mt(xe,"people.json")||{},ne)}function Cn(e){dt(),ne=e;try{ft(xe,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${A.resolve(xe)}`)}}function Ae(e,t={}){if(!e)return null;let n=ie(),o=hn(),r=new Date().toISOString(),s=n[e];if(s){let i=vn(s,t);i.length>0&&(Sn(e,{capturedAt:r,previousLastUpdated:s.lastUpdated||null,changedFields:i,snapshot:kn(s)}),s.lastSnapshotAt=r),s.seenCount=(s.seenCount||1)+1,s.lastSeen=o,s.lastUpdated=r,t.source&&!s.sources?.includes(t.source)&&(s.sources=s.sources||[],s.sources.push(t.source));for(let c of gn)if(t[c]!=null){if(Array.isArray(t[c])&&t[c].length===0&&Array.isArray(s[c])&&s[c].length>0)continue;s[c]=t[c]}Array.isArray(t.availableSections)&&(s.lastFullVisitAt=r)}else n[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,featured:t.featured||null,education:t.education||null,skillsFull:t.skillsFull||null,recommendations:t.recommendations||null,certifications:t.certifications||null,firstSeen:o,lastSeen:o,seenCount:1,sources:t.source?[t.source]:[],connectionStatus:null,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:r,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?r:null};return Cn(n),n[e]}async function Tn(e,t){let n=e.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: npm run login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function yt(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:s=!1,extractSkills:i=!1,extractRecommendations:c=!1,extractCertifications:a=!1}=n;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await $(3e3),await ot(e)&&(console.log(" Dismissed Premium overlay"),await $(1500),await Tn(e,t));let l=0;for(let x=0;x<2;x++){let ee=await e.evaluate(()=>document.body.scrollHeight);for(let W=1;W<=6;W++)await e.evaluate(T=>window.scrollTo(0,T),ee*W/6),await $(900);let q=await e.evaluate(()=>document.body.scrollHeight);if(q===l)break;l=q}await $(800);let y=await e.evaluate(()=>{let x=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"]),ee=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"]),q=p=>{let w=(p||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(w)},W={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:[]},T=document.querySelector("main");if(!T)return W;let ve=[...Array.from(T.querySelectorAll("h1")),...Array.from(T.querySelectorAll("h2"))],b=Array.from(T.querySelectorAll("h2")),I=ve.find(p=>{let w=p.textContent&&p.textContent.trim(),S=(w||"").replace(/\s*\(\d+\)$/,"").trim();return w&&w.length>1&&w.length<100&&!x.has(S)&&!ee.has(S)}),te=I?I.textContent.trim():null,D=I?I.parentElement:null;for(;D&&D!==T&&!Array.from(D.children).filter(w=>w.tagName==="P").some(w=>{let S=w.textContent&&w.textContent.trim();return S&&S.length>5&&!q(S)});)D=D.parentElement;let me=null,Ve=null,He=null,ke=null;if(D&&D!==T){let p=Array.from(D.children).filter(S=>S.tagName==="P").filter(S=>{let V=S.textContent&&S.textContent.trim();return V&&V.length>5&&!q(V)});if(p[0]&&(me=p[0].textContent.trim()),p[1]){let S=p[1].textContent.trim().split(/\s*[·•]\s*/);Ve=S[0]||null,S.length>1&&(He=S.slice(1).join(" \xB7 "))}let w=Array.from(D.children).filter(S=>S.tagName==="DIV");for(let S=w.length-1;S>=0;S--){let V=w[S].textContent&&w[S].textContent.trim();if(V&&!(te&&V.startsWith(te))&&(ke=V.split(/[·•]/)[0].trim(),ke))break}}let Je=null;if(D){let p=D.querySelectorAll("p, span, div");for(let w of p){let S=(w.textContent||"").trim().replace(/^[·•]\s*/,"");if(S==="1st"||S==="2nd"||S==="3rd"){Je=S;break}}}let Ut=!!T.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),We=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),Vt=We&&We.src||null,pe=T.textContent||"",Ye=null,Ge=pe.match(/(\d+\+?)\s+connections\b/i);Ge&&(Ye=Ge[1]+" connections");let he=null,Ke=pe.match(/(\d+)\s+mutual connection/i),ze=pe.match(/and\s+(\d+)\s+other mutual/i),Ht=pe.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);Ke?he=parseInt(Ke[1],10):ze?he=2+parseInt(ze[1],10):Ht&&(he=2);let Qe=null,Ze=null,Xe=b.find(p=>p.textContent&&p.textContent.trim()==="About");if(Xe){let p=Xe.parentElement;for(;p&&p.tagName!=="SECTION";)p=p.parentElement;if(p){let w=(p.textContent||"").trim();w=w.replace(/^About\s*/,"").trim();let S=w.match(/Top skills\s*(.+?)$/i);if(S){let Ce=S[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Gt=>Gt.trim()).filter(Boolean);Ce.length>0&&Ce.length<10&&(Ze=Ce)}w=w.split(/\n?…\s*more/i)[0].trim(),w=w.split(/\n?\.\.\.\s*more/i)[0].trim(),w=w.split(/\bTop skills\b/i)[0].trim(),w=w.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),Qe=w||null}}let et=null,tt=b.find(p=>p.textContent&&p.textContent.trim()==="Activity");if(tt){let p=tt.parentElement;for(;p&&p.tagName!=="SECTION";)p=p.parentElement;if(p){let w=(p.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);w&&(et=parseInt(w[1].replace(/,/g,""),10))}}let Jt=[...new Set(b.map(p=>(p.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(p=>p&&p.length>1&&p.length<60&&p!==te).filter(p=>x.has(p)))],re=document.body.textContent||"",Wt=/#OpenToWork\b/i.test(re)||/\bOpen to work\b/.test(re),Yt=/#Hiring\b/i.test(re)||/\bI'?m hiring\b/i.test(re)||/\bWe are hiring\b/i.test(re);return{name:te,title:me,location:ke,currentCompany:Ve,currentSchool:He,connectionDegree:Je,hasVerifiedBadge:Ut,photoUrl:Vt,connectionsLevel:Ye,mutualConnectionsCount:he,followers:et,openToWork:Wt,hiring:Yt,about:Qe,topSkills:Ze,availableSections:Jt}});console.log(`Viewed: ${y.name} - ${y.title}`);let u=null,f=null,C=null,v=null,_=null,h=null;if(o||r||s||i||c||a){let x=await Promise.resolve().then(()=>(gt(),ht));o&&(u=await x.extractExperienceFromDetails(e,t),console.log(` + Experience: ${u.length} entries`)),r&&(f=await x.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${f.length} entries`)),s&&(C=await x.extractEducationFromDetails(e,t),console.log(` + Education: ${C.length} entries`)),i&&(v=await x.extractSkillsFromDetails(e,t),console.log(` + Skills: ${v.length} entries`)),c&&(_=await x.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${_.length} entries`)),a&&(h=await x.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${h.length} entries`))}return{...y,profileUrl:t,...u!==null&&{experience:u},...f!==null&&{featured:f},...C!==null&&{education:C},...v!==null&&{skillsFull:v},..._!==null&&{recommendations:_},...h!==null&&{certifications:h}}}catch(m){console.error(`Error viewing profile ${t}:`,m.message);try{await e.goto("about:blank",{timeout:1e4}),await $(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(m.message||""))throw m;return null}}import"dotenv/config";import*as O from"fs";import*as j from"path";import{fileURLToPath as Dn}from"url";var Rn=Dn(import.meta.url),jn=j.dirname(j.dirname(Rn)),K=process.env.DATA_DIR?j.resolve(process.env.DATA_DIR,"market-research"):j.join(jn,"market-research"),On=j.join(K,"scouted-jobs.json"),Nn=j.join(K,"discovered-people.json"),wt=j.join(K,"visit-log.json"),Sr=j.join(K,"companies.json"),vr=j.join(K,"job-decisions.json");function Ln(){O.existsSync(K)||O.mkdirSync(K,{recursive:!0})}function Fn(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";O.writeFileSync(o,n);for(let r=0;r<3;r++)try{O.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function _e(e){try{if(O.existsSync(e))return JSON.parse(O.readFileSync(e,"utf-8"))}catch{}return null}function bt(){ue=null,Pn=null,de=null,qn=null,G=null}var ue=null;function Mn(){return ue||(ue=_e(On)||{},ue)}var Pn=null;var de=null;function ye(){return de||(de=_e(Nn)||{},de)}var qn=null;var G=null;function oe(){return G||(G=_e(wt)||{visits:[]},Array.isArray(G.visits)||(G.visits=[]),G)}function St(e,t={}){if(!e)return;Ln();let n=oe();n.visits.push({date:new Date().toISOString(),profileUrl:e,name:t.name||null,source:t.source||"manual"});let o=Date.now()-90*24*60*60*1e3;n.visits=n.visits.filter(r=>new Date(r.date).getTime()>o);try{Fn(wt,n)}catch(r){console.error(`[!] Failed to save visit-log.json: ${r.message}`)}}function vt(e){let t=oe();for(let n=t.visits.length-1;n>=0;n--)if(t.visits[n].profileUrl===e)return t.visits[n].date;return null}function kt(){let e=Mn(),t=ye(),n=Object.values(e),o=Object.values(t),r={};for(let u of n)u.company&&(r[u.company]=(r[u.company]||0)+1);let s=Object.entries(r).sort((u,f)=>f[1]-u[1]).slice(0,5).map(([u,f])=>`${u} (${f})`),i={};for(let u of n)for(let f of u.techStack||[])i[f]=(i[f]||0)+1;let c=Object.entries(i).sort((u,f)=>f[1]-u[1]).slice(0,8).map(([u,f])=>`${u} (${f})`),a=oe(),m=new Date().toISOString().slice(0,10),l=a.visits.filter(u=>u.date.startsWith(m)).length,y=new Set(a.visits.map(u=>u.profileUrl)).size;return{totalJobs:n.length,totalRecruiters:o.length,topCompanies:s,topTech:c,totalVisited:y,todayVisited:l,lastScoutDate:n.length>0?n.sort((u,f)=>(f.scoutedAt||"").localeCompare(u.scoutedAt||""))[0]?.scoutedAt:null}}se();async function Ct(e,t,n={}){let{maxVisits:o=50,delayBetween:r=4e3,skipRecentDays:s=7,verbose:i=!1,extractExperience:c=!1}=n,a={visited:0,skipped:0,errors:0},m=Date.now()-s*24*60*60*1e3;for(let l of t){if(a.visited>=o)break;if(!l.profileUrl)continue;let y=vt(l.profileUrl);if(y&&new Date(y).getTime()>m){a.skipped++;continue}try{let u=await yt(e,l.profileUrl,{extractExperience:c}),f=l.source||"visit";if(u){let v={...u,source:f};c&&Array.isArray(u.experience)&&u.experience.length>0&&(v._lastEnrichedAt=new Date().toISOString()),Ae(l.profileUrl,v)}St(l.profileUrl,{name:u?.name||l.name||null,source:f}),a.visited++,i?console.log(` [${a.visited}] ${u?.name||l.profileUrl} \u2014 ${u?.title?.slice(0,40)||"?"}`):a.visited%10===0&&console.log(` Visited: ${a.visited}`);let C=Math.random()*4e3;await $(r+C)}catch(u){a.errors++,i&&console.error(` Error visiting ${l.name||l.profileUrl}: ${u.message?.slice(0,60)}`);let f=(u.message||"").toLowerCase();if(f.includes("detached")||f.includes("session closed")||f.includes("target closed")||f.includes("session expired")||f.includes("bounced to")||f.includes("authwall")||f.includes("checkpoint")||f.includes("redirected to login")){console.log(" Fatal browser/session error \u2014 stopping visits");break}}}return a}function xt(e={}){let{limit:t=150,revisitDays:n=14}=e,o=oe(),r=new Set(o.visits?.map(h=>h.profileUrl)||[]),s=new Map;for(let h of o.visits||[]){let g=s.get(h.profileUrl);(!g||h.date>g)&&s.set(h.profileUrl,h.date)}let i=Date.now()-7*24*60*60*1e3,c=Date.now()-n*24*60*60*1e3;function a(h){let g=s.get(h);return g&&new Date(g).getTime()>i}let m=ye(),l=Object.entries(m).filter(([h])=>!r.has(h)).map(([h,g])=>({profileUrl:h,name:g.name,source:"new-discovered",priority:1,jobCount:g.jobIds?.length||0})),y=ie(),u=Object.entries(y).filter(([h,g])=>g.connectionStatus==="connected"||a(h)?!1:(g.jobCount||g.jobIds?.length||0)>=2).map(([h,g])=>({profileUrl:h,name:g.name,source:"active-recruiter",priority:2,jobCount:g.jobCount||g.jobIds?.length||0})),f=Object.entries(y).filter(([h,g])=>{let x=g.connectionStatus;return!(!x||x==="connected"||x==="pending"||x==="sent_without_note"||x==="sent_with_note"||a(h)||(g.jobCount||g.jobIds?.length||0)>=2)}).map(([h,g])=>({profileUrl:h,name:g.name,source:"unconnected",priority:3,jobCount:g.jobCount||g.jobIds?.length||0})),C=[...s.entries()].filter(([h,g])=>new Date(g).getTime()<c).map(([h,g])=>({profileUrl:h,name:null,source:"revisit",priority:4,lastVisit:g})),v=h=>h.sort(()=>Math.random()-.5);return l.sort((h,g)=>g.jobCount-h.jobCount),u.sort((h,g)=>g.jobCount-h.jobCount),v(f),v(C),[...l,...u,...f,...C].slice(0,t)}function $t(){let e=ye();return Object.entries(e).map(([t,n])=>({profileUrl:t,name:n.name,source:"discovered"}))}function Ie(){let e=ie();return Object.entries(e).filter(([,t])=>{let n=t.connectionStatus;return n&&n!=="connected"&&n!=="pending"&&n!=="sent_without_note"&&n!=="sent_with_note"}).map(([t,n])=>({profileUrl:t,name:n.name,source:"unconnected"}))}function Te(e=14){let t=oe(),n=Date.now()-e*24*60*60*1e3,o=new Map;for(let r of t.visits){let s=o.get(r.profileUrl);(!s||r.date>s.date)&&o.set(r.profileUrl,r)}return[...o.entries()].filter(([,r])=>new Date(r.date).getTime()<n).map(([r,s])=>({profileUrl:r,name:s.name,source:"revisit"}))}import"dotenv/config";import*as N from"fs";import*as H from"path";import{fileURLToPath as Wn}from"url";import"dotenv/config";import{createGraphClient as Bn,resolveToken as Un}from"@ilivemylife/graph-sdk";import{config as Vn}from"dotenv";Vn();var Et=Un()||process.env.TOKEN;Et||(console.error(`
|
|
8
242
|
[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.
|
|
9
243
|
`),console.error(" Easiest way:"),console.error(" 1. npm install -g @ilivemylife/graph-sdk"),console.error(` 2. ilml login your@email.com yourpassword
|
|
10
244
|
`),console.error(` Or add ILML_TOKEN=... to .env
|
|
11
|
-
`),process.exit(1));var
|
|
245
|
+
`),process.exit(1));var At=Bn({token:Et});function Hn(e){if(!e||e<1e3)return`${e||0}ms`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60),o=t%60;return o?`${n}m ${o}s`:`${n}m`}function Jn({scriptName:e,mode:t,status:n,error:o,duration:r}){let s=n==="error"?"\u2717":n==="quota-reached"?"\u26A0":"\u2713",i=new Date().toISOString().slice(0,16).replace("T"," "),c=r?` ${Hn(r)}`:"",a=n==="error"?`error${o?`: ${String(o).slice(0,80)}`:""}`:n==="quota-reached"?"daily quota reached":"done",m=t&&t!=="default"?` (${t})`:"";return`${s} ${e}${m} \u2014 ${a} \u2014 ${i}${c}`}async function _t({scriptName:e,mode:t,status:n,summaryLines:o,error:r,duration:s}){let i=process.env.NODE_RUN_REPORTS;if(!i||!Array.isArray(o)||o.length===0)return;let a=`**${Jn({scriptName:e,mode:t,status:n,error:r,duration:s})}**
|
|
12
246
|
|
|
13
|
-
${
|
|
14
|
-
`)}`;try{await
|
|
247
|
+
${o.join(`
|
|
248
|
+
`)}`;try{await At.addMessage(i,a)}catch(m){console.error(`[runReport] Failed to post end-of-session message: ${m.message}`)}}var Yn=Wn(import.meta.url),Gn=H.dirname(H.dirname(Yn)),De=process.env.DATA_DIR?H.resolve(process.env.DATA_DIR,"collected-profiles"):H.join(Gn,"collected-profiles"),Re=H.join(De,"run-log.json");function Kn(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";N.writeFileSync(o,n);for(let r=0;r<3;r++)try{N.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function It(){try{if(!N.existsSync(Re))return{runs:[]};let e=JSON.parse(N.readFileSync(Re,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Tt(e){N.existsSync(De)||N.mkdirSync(De,{recursive:!0});try{Kn(Re,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function Dt(e,t="default"){let n=It();for(let i of n.runs)i.status==="running"&&(i.status="interrupted",i.result="interrupted",i.timestamp&&(i.duration=Date.now()-new Date(i.timestamp).getTime()));let o=new Date,r={timestamp:o.toISOString(),script:e,mode:t,status:"running",result:null,duration:null,stats:null,error:null};n.runs.push(r);let s=Date.now()-30*24*60*60*1e3;return n.runs=n.runs.filter(i=>new Date(i.timestamp).getTime()>s),Tt(n),{script:e,mode:t,startTime:o.getTime(),runIndex:n.runs.length-1}}function je(e,t,n=null,o=null){if(!e)return;let r=null;try{let i=It(),c=i.runs[e.runIndex];if(c&&c.status==="running"&&c.script===e.script)c.status=t,c.result=t,c.duration=Date.now()-e.startTime,c.stats=n,c.error=o,r=c.duration;else{let a=i.runs.find(m=>m.script===e.script&&m.status==="running"&&m.timestamp===new Date(e.startTime).toISOString());a&&(a.status=t,a.result=t,a.duration=Date.now()-e.startTime,a.stats=n,a.error=o,r=a.duration)}Tt(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let s=n&&Array.isArray(n.summaryLines)?n.summaryLines:null;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS){let i=t==="error"?"error":n&&n.dailyLimitHit?"quota-reached":"done";_t({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(c=>console.error(`[runLog] postRunReport failed: ${c.message}`))}}import"dotenv/config";import*as d from"fs";import*as qe from"os";import*as k from"path";import{fileURLToPath as po}from"url";var Le={};ge(Le,{NAME:()=>Qn,VERSION:()=>zn,up:()=>eo});import*as L from"fs";import*as we from"path";var zn=1,Qn="normalize-jobs-and-questions",Zn=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],Xn=50;function Oe(e){return L.existsSync(e)?JSON.parse(L.readFileSync(e,"utf-8")):null}function Ne(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{L.writeFileSync(o,n)}catch(r){try{L.unlinkSync(o)}catch{}throw r}try{L.renameSync(o,e)}catch(r){try{L.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}async function eo(e,t){let n=we.join(e,"jobs.json"),o=we.join(t,"scouted-jobs.json"),r=we.join(e,"application-questions.json"),s=Oe(n)||{},i=Oe(o)||{},c=0,a=[];for(let l of Object.keys(s)){if(!i[l])continue;let y=i[l],u=s[l];for(let f of Zn)y[f]!=null&&u[f]==null&&(u[f]=y[f]);a.push(l),c++}c>0?(Ne(n,s),console.log(` Phase 1: Merged ${c} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let m=Oe(r);if(m&&Array.isArray(m.applications)){let l={},y=0;for(let u of m.applications){let f=u.jobId||"unknown";l[f]||(l[f]={applications:[]});let C=(u.questions||[]).map(v=>{let _={type:v.type||"input",question:v.question||"",answer:v.answer||""};return v.options&&(v.options.length<=Xn?_.options=v.options:(_.optionsOmitted=!0,y++)),v.page&&(_.page=v.page),v.wasPreFilled&&(_.wasPreFilled=!0),v.wasRetry&&(_.wasRetry=!0),_});l[f].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||C.length,questions:C})}Ne(r,l),console.log(` Phase 2: Rekeyed ${m.applications.length} applications by jobId (${Object.keys(l).length} unique jobs)`),y>0&&console.log(` Phase 2: Stripped bloated options from ${y} questions`)}else m&&!m.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 l of a)delete i[l];Ne(o,i),console.log(` Phase 3: Removed ${a.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var Fe={};ge(Fe,{NAME:()=>no,VERSION:()=>to,up:()=>so});import*as F from"fs";import*as Rt from"path";var to=2,no="reset-unread-flags";function oo(e){return F.existsSync(e)?JSON.parse(F.readFileSync(e,"utf-8")):null}function ro(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{F.writeFileSync(o,n)}catch(r){try{F.unlinkSync(o)}catch{}throw r}try{F.renameSync(o,e)}catch(r){try{F.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}async function so(e){let t=Rt.join(e,"conversations.json"),n=oo(t);if(!n){console.log(" conversations.json not found \u2014 nothing to reset.");return}let o=0;for(let r of Object.keys(n))n[r].unread===!0&&(n[r].unread=!1,o++);if(o===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}ro(t,n),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var Me={};ge(Me,{NAME:()=>lo,VERSION:()=>io,up:()=>mo});import*as M from"fs";import*as jt from"path";var io=3,lo="recompute-last-message-by",ao=new Set(["draft","confirmed","rejected","needs_review"]);function co(e){return M.existsSync(e)?JSON.parse(M.readFileSync(e,"utf-8")):null}function uo(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{M.writeFileSync(o,n)}catch(r){try{M.unlinkSync(o)}catch{}throw r}try{M.renameSync(o,e)}catch(r){try{M.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}function fo(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!ao.has(s.status));if(n.length===0)return"them";let o=n.map(s=>({m:s,t:Date.parse(s.time)})).filter(s=>Number.isFinite(s.t)).sort((s,i)=>i.t-s.t).map(s=>s.m),r=o.length>0?o:[...n].reverse();for(let s of r){let i=s.sender;if(i===t)return"me";if(i!=="Unknown"&&i!=="")return"them"}return"them"}async function mo(e){let t=jt.join(e,"conversations.json"),n=co(t);if(!n){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let o=process.env.LINKEDIN_NAME;if(!o||typeof o!="string"||!o.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 r=0,s=0,i=0;for(let c of Object.keys(n)){let a=n[c];if(!a||typeof a!="object")continue;Object.prototype.hasOwnProperty.call(a,"_cardSynced")&&(delete a._cardSynced,s++);let m=Array.isArray(a.messages)?a.messages:[],l=fo(m,o),y=l==="me"?"awaiting_reply":"unanswered_by_us";a.lastMessageBy!==l&&i++,a.lastMessageBy=l,a.conversationStatus=y,r++}if(r===0){console.log(" No conversations to recompute.");return}uo(t,n),console.log(` Recomputed lastMessageBy + conversationStatus on ${r} conversations.`),console.log(` ${i} had stale lastMessageBy (now corrected).`),s>0&&console.log(` Cleaned ${s} leftover _cardSynced flags.`),console.log(" Re-run 'ilml linkedin enrich' if you want actionNeeded / summary / autoTags to also update.")}var ho=po(import.meta.url),go=k.dirname(ho),yo=k.dirname(k.dirname(go));function wo(e){return e&&(e==="~"?qe.homedir():e.startsWith("~/")||e.startsWith("~\\")?k.join(qe.homedir(),e.slice(2)):e)}var P=process.env.DATA_DIR?k.resolve(wo(process.env.DATA_DIR)):yo,Q=k.join(P,"collected-profiles"),Z=k.join(P,"market-research"),R=k.join(P,".schema-version"),Ot=[k.join(Q,".schema-version"),k.join(Z,".schema-version")],J=3,U=[{version:1,module:Le},{version:2,module:Fe},{version:3,module:Me}];(function(){U.sort((o,r)=>o.version-r.version);let t=new Set;for(let o of U){if(!Number.isInteger(o.version)||o.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(o.version)} (must be positive integer)`);if(t.has(o.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${o.version}`);t.add(o.version);let r=o.module;if(!r||typeof r.up!="function")throw new Error(`MIGRATION_REGISTRY: v${o.version} module is missing up()`);if(r.VERSION!==void 0&&r.VERSION!==o.version)throw new Error(`MIGRATION_REGISTRY: v${o.version} entry does not match module VERSION (${r.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let n=U.length?U[U.length-1].version:0;if(n!==J)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${J}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<U.length;o++){let r=o+1;if(U[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${U[o].version}`)}})();function Mt(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
15
249
|
[FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
|
|
16
|
-
`),process.exit(1));try{d.mkdirSync(
|
|
17
|
-
[FATAL] Cannot create DATA_DIR (${
|
|
18
|
-
`),process.exit(1))}let e;try{e=d.statSync(
|
|
19
|
-
[FATAL] DATA_DIR (${
|
|
250
|
+
`),process.exit(1));try{d.mkdirSync(P,{recursive:!0})}catch(t){t.code!=="EEXIST"&&(console.error(`
|
|
251
|
+
[FATAL] Cannot create DATA_DIR (${P}): ${t.message}`),console.error(` Fix the path or permissions and try again.
|
|
252
|
+
`),process.exit(1))}let e;try{e=d.statSync(P)}catch(t){console.error(`
|
|
253
|
+
[FATAL] DATA_DIR (${P}) is not accessible: ${t.message}
|
|
20
254
|
`),process.exit(1)}e.isDirectory()||(console.error(`
|
|
21
|
-
[FATAL] DATA_DIR (${
|
|
22
|
-
`),process.exit(1));for(let t of[
|
|
255
|
+
[FATAL] DATA_DIR (${P}) 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.
|
|
256
|
+
`),process.exit(1));for(let t of[Q,Z]){let n;try{n=d.lstatSync(t)}catch(o){if(o.code==="ENOENT")continue;throw o}n.isSymbolicLink()&&(console.error(`
|
|
23
257
|
[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.
|
|
24
|
-
`),process.exit(1))}}var
|
|
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: ${
|
|
258
|
+
`),process.exit(1))}}var z=k.join(P,".migration-lock");function bo(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return d.writeFileSync(z,e,{flag:"wx"}),!0}catch(o){if(o.code!=="EEXIST")throw o}let t;try{t=JSON.parse(d.readFileSync(z,"utf-8"))}catch{t=null}if(t&&Number.isInteger(t.pid)){let o=!1;try{process.kill(t.pid,0),o=!0}catch(i){i.code==="EPERM"&&(o=!0)}let r=24*60*60*1e3,s=1/0;if(t.startedAt){let i=Date.parse(t.startedAt);Number.isNaN(i)||(s=Date.now()-i)}o&&s<r&&(console.error(`
|
|
259
|
+
[FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${t.pid}`),console.error(` Started at: ${t.startedAt||"(unknown)"}`),console.error(` Lock file: ${z}
|
|
26
260
|
`),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.
|
|
27
|
-
`),process.exit(1)),
|
|
28
|
-
[FATAL] Legacy .schema-version file(s) corrupted \u2014 cannot determine current schema version:`);for(let
|
|
261
|
+
`),process.exit(1)),o&&s>=r&&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 n=z+".tmp";try{return d.writeFileSync(n,e),d.renameSync(n,z),!0}catch(o){try{d.unlinkSync(n)}catch{}throw new Error(`Failed to take over stale migration lock: ${o.message}`)}}function Be(){try{if(JSON.parse(d.readFileSync(z,"utf-8")).pid!==process.pid)return;d.unlinkSync(z)}catch{}}var Nt=!1;function So(){if(Nt)return;Nt=!0;let e=()=>{try{Be()}catch{}process.exit(1)};for(let t of["SIGINT","SIGTERM","SIGHUP"])try{process.on(t,e)}catch{}}function vo(){if(d.existsSync(R))return;let e=[],t=[];for(let s of Ot)if(d.existsSync(s))try{e.push({file:s,schema:be(s)})}catch(i){t.push({file:s,err:i.message})}if(t.length>0){console.error(`
|
|
262
|
+
[FATAL] Legacy .schema-version file(s) corrupted \u2014 cannot determine current schema version:`);for(let s of t)console.error(` ${s.file}: ${s.err}`);console.error(`
|
|
29
263
|
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.
|
|
30
|
-
`),process.exit(1)}if(e.length===0)return;let
|
|
31
|
-
[FATAL] Legacy .schema-version files disagree:`);for(let
|
|
32
|
-
`),process.exit(1)}let
|
|
33
|
-
[FATAL] ${
|
|
34
|
-
`),process.exit(1)}let t=
|
|
35
|
-
[FATAL] ${
|
|
36
|
-
`),process.exit(1)),t}function
|
|
37
|
-
[FATAL] Your data schema is at v${t}, but this plugin build only understands up to v${
|
|
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${
|
|
264
|
+
`),process.exit(1)}if(e.length===0)return;let n=e.map(s=>s.schema.version);if(new Set(n).size>1){console.error(`
|
|
265
|
+
[FATAL] Legacy .schema-version files disagree:`);for(let s of e)console.error(` ${s.file}: v${s.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.
|
|
266
|
+
`),process.exit(1)}let o=e[0].schema,r=R+".tmp";try{d.writeFileSync(r,JSON.stringify(o,null,2)),d.renameSync(r,R)}catch(s){try{d.unlinkSync(r)}catch{}throw s}for(let s of Ot)if(d.existsSync(s))try{d.unlinkSync(s)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${R}`)}function ko(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 be(e){let t=d.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function Lt(){if(vo(),!d.existsSync(R))return{version:0,migrations:[]};let e;try{e=be(R)}catch(n){if(n.code==="ENOENT")return{version:0,migrations:[]};console.error(`
|
|
267
|
+
[FATAL] ${R} is not valid JSON: ${n.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.
|
|
268
|
+
`),process.exit(1)}let t=ko(e);return t===null&&(console.error(`
|
|
269
|
+
[FATAL] ${R} 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.
|
|
270
|
+
`),process.exit(1)),t}function Pt(e){try{d.chmodSync(e,384)}catch{}}function Co(e){if(Mt(),d.existsSync(R))try{if(d.lstatSync(R).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${R}. Refusing to write through it (potential symlink attack). Remove the link and re-run.`)}catch(n){if(n.message?.includes("symbolic link"))throw n}let t=R+".tmp";try{d.writeFileSync(t,JSON.stringify(e,null,2)),Pt(t),d.renameSync(t,R)}catch(n){try{d.unlinkSync(t)}catch{}throw n}}function Ft(e,t){if(!d.existsSync(e))return;let n=`.pre-v${String(t).padStart(3,"0")}.backup`,o=d.readdirSync(e).filter(c=>{let a=c.toLowerCase();if(a.includes(".backup")||a===".schema-version"||a.endsWith(".tmp"))return!1;try{return d.statSync(k.join(e,c)).isFile()}catch{return!1}}),r=0,s=0,i=[];for(let c of o){let a=k.join(e,c),m=k.join(e,c+n);if(d.existsSync(m)){s++;continue}try{Bt(a,m),r++}catch(l){i.push({file:c,err:l.message})}}if(i.length>0){let c=new Error(`Failed to back up ${i.length} file(s) in ${k.basename(e)}/: `+i.map(a=>`${a.file} (${a.err})`).join(", "));throw c.code="BACKUP_INCOMPLETE",c}if(r>0||s>0){let c=s>0?` (${s} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${r} files in ${k.basename(e)}/ (${n})${c}`)}}var Pe=!1;async function qt(){if(Pe)return;Mt(),_o();let t=Lt().version;if(t===J){Pe=!0;return}So(),bo(),process.on("exit",Be),t>J&&(console.error(`
|
|
271
|
+
[FATAL] Your data schema is at v${t}, but this plugin build only understands up to v${J}.`),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.
|
|
272
|
+
`),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${J}.
|
|
39
273
|
`),process.exit(1)),console.log(`
|
|
40
|
-
\u{1F4E6} Schema migration: v${t} \u2192 v${
|
|
41
|
-
[FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let
|
|
274
|
+
\u{1F4E6} Schema migration: v${t} \u2192 v${J}`);let n=Io();if(!n.ok){console.error(`
|
|
275
|
+
[FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let r of n.broken)console.error(` ${r.dir}/${r.file}: ${r.err}`);console.error(`
|
|
42
276
|
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'.
|
|
43
|
-
`),process.exit(1)}let
|
|
44
|
-
Running migration v${String(
|
|
45
|
-
[FATAL] Pre-migration backup failed for ${
|
|
46
|
-
`),process.exit(1)}let
|
|
47
|
-
[FATAL] Migration ${
|
|
277
|
+
`),process.exit(1)}let o=U.filter(r=>r.version>t);for(let r of o){console.log(`
|
|
278
|
+
Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,i=`.pre-${s}.backup`;try{Ft(Q,r.version),Ft(Z,r.version)}catch(a){console.error(`
|
|
279
|
+
[FATAL] Pre-migration backup failed for ${s}: ${a.message}`),console.error(" Migration NOT applied. Repair the underlying issue (disk space, permissions, locked files)"),console.error(` and re-run the plugin command.
|
|
280
|
+
`),process.exit(1)}let c=r.module;try{await c.up(Q,Z)}catch(a){console.error(`
|
|
281
|
+
[FATAL] Migration ${s} failed: ${a.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let m=To(i);m.ok?(console.error(` \u2713 Auto-rollback restored ${m.restored} files. Schema stays at v${t}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
|
|
48
282
|
`)):(console.error(` [!] Auto-rollback INCOMPLETE: ${m.error}`),console.error(` Manual recovery: copy *${i} files back over the originals.
|
|
49
283
|
`))}catch(m){console.error(` [!] Auto-rollback CRASHED while restoring: ${m.message}`),console.error(` Manual recovery: copy *${i} files back over the originals.
|
|
50
|
-
`)}process.exit(1)}try{let
|
|
51
|
-
[FATAL] Migration ${
|
|
52
|
-
`),process.exit(1)}console.log(` \u2713 Migration ${
|
|
53
|
-
\u2713 Schema is now at v${
|
|
54
|
-
`)}var
|
|
55
|
-
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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 VISIT STATS"),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(` Unique profiles visited: ${e.totalVisited}`),console.log(` Today: ${e.todayVisited}`),console.log(` Discovered recruiters: ${e.totalRecruiters} (potential visits)`);let t=
|
|
56
|
-
`)}async function
|
|
284
|
+
`)}process.exit(1)}try{let a=new Date().toISOString(),m={version:r.version,name:c.NAME||s,appliedAt:a},l=Lt();l.version=r.version,l.migratedAt=a,l.migrations=l.migrations||[],l.migrations.push(m),Co(l)}catch(a){console.error(`
|
|
285
|
+
[FATAL] Migration ${s} applied successfully but schema version file could NOT be updated: ${a.message}`),console.error(` Your data is in the v${r.version} state but .schema-version still shows v${t}.`),console.error(` On next plugin command the runner will try to re-apply ${s}. If that migration is`),console.error(` idempotent (most are), it will succeed harmlessly. If you're unsure, run 'data-cleanup' and contact support.
|
|
286
|
+
`),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{ut()}catch{}try{bt()}catch{}Pe=!0,Be(),console.log(`
|
|
287
|
+
\u2713 Schema is now at v${J}
|
|
288
|
+
`)}var xo=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function $o(e){let t=e.toLowerCase();return xo.some(n=>n.test(t))}var Eo=6e4;function Ao(){let e=Date.now(),t=[];for(let n of[P,Q,Z]){if(!d.existsSync(n))continue;let o;try{o=d.readdirSync(n)}catch{continue}for(let r of o){if(!$o(r))continue;let s=k.join(n,r);try{let i=d.statSync(s);if(!i.isFile()||e-i.mtimeMs<Eo)continue;t.push({dir:n,file:r,fullPath:s})}catch{}}}return t}function _o({verbose:e=!1}={}){let t=Ao();if(t.length===0)return e&&console.log(" No orphan .tmp files found."),0;let n=0;for(let o of t)try{d.unlinkSync(o.fullPath),n++,e&&console.log(` Removed orphan: ${k.basename(o.dir)}/${o.file}`)}catch(r){console.warn(` [!] Could not remove orphan ${o.fullPath}: ${r.message}`)}return!e&&n>0&&console.log(` Cleaned up ${n} orphan .tmp file(s) from previous run.`),n}function Io(){let e=[];for(let t of[Q,Z]){if(!d.existsSync(t))continue;let n=d.readdirSync(t).filter(o=>{let r=o.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let o of n){let r=k.join(t,o);try{be(r)}catch(s){e.push({dir:k.basename(t),file:o,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function To(e){let t=[],n=[];for(let s of[Q,Z]){if(!d.existsSync(s))continue;let i=d.readdirSync(s).filter(c=>c.endsWith(e));for(let c of i){let a=k.join(s,c),m=c.slice(0,-e.length),l=k.join(s,m);try{m.toLowerCase().endsWith(".json")?be(a):d.accessSync(a,d.constants.R_OK),t.push({backupPath:a,originalPath:l,fileName:c,dir:s})}catch(y){n.push(`${k.basename(s)}/${c}: ${y.message}`)}}}if(n.length>0)return{ok:!1,error:n.join("; "),restored:0};let o=0,r=[];for(let{backupPath:s,originalPath:i,fileName:c,dir:a}of t)try{Bt(s,i),o++}catch(m){r.push(`${k.basename(a)}/${c}: ${m.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:o}:{ok:!0,restored:o}}function Bt(e,t){let n=t+".tmp";try{d.copyFileSync(e,n),Pt(n)}catch(o){try{d.unlinkSync(n)}catch{}throw o}try{d.renameSync(n,t)}catch(o){try{d.unlinkSync(n)}catch{}if(o.code==="EPERM"||o.code==="EBUSY"){let r=new Error(`File locked: ${t} (${o.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 r.code=o.code,r}throw o}}await qt();var fe=process.argv.slice(2),Se=fe.find(e=>e.startsWith("--source="))?.split("=")[1]||"scouted",Ue=parseInt(fe.find(e=>e.startsWith("--max="))?.split("=")[1]||"50"),X=parseInt(fe.find(e=>e.startsWith("--revisit="))?.split("=")[1]||"0"),Do=fe.includes("--list"),Ro=fe.includes("--verbose");function jo(){let e=kt();console.log(`
|
|
289
|
+
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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 VISIT STATS"),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(` Unique profiles visited: ${e.totalVisited}`),console.log(` Today: ${e.todayVisited}`),console.log(` Discovered recruiters: ${e.totalRecruiters} (potential visits)`);let t=Ie();if(console.log(` Unconnected recruiters: ${t.length}`),X>0){let n=Te(X);console.log(` Revisit (>${X}d ago): ${n.length}`)}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
|
|
290
|
+
`)}async function Oo(){if(console.log(`
|
|
57
291
|
LinkedIn Profile Visitor
|
|
58
|
-
`),
|
|
292
|
+
`),Do){jo();return}let e=[],t="";if(X>0?(e=Te(X),t=`revisit (>${X} days)`):Se==="people"?(e=Ie(),t="unconnected recruiters (people.json)"):Se==="scouted"||Se==="discovered"?(e=$t(),t="discovered recruiters (market-research)"):(e=xt({limit:Ue}),t="smart (new \u2192 active \u2192 unconnected \u2192 revisit)"),console.log(` Source: ${t}`),console.log(` Candidates: ${e.length}`),console.log(` Max visits: ${Ue}
|
|
59
293
|
`),e.length===0){console.log(` No profiles to visit. Run npm run scout first.
|
|
60
|
-
`);return}let
|
|
61
|
-
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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(" Visit 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: ${
|
|
62
|
-
`),
|
|
63
|
-
Error:`,
|
|
294
|
+
`);return}let n=Dt("visit",Se),{browser:o,page:r}=await lt();try{let s=await Ct(r,e,{maxVisits:Ue,verbose:Ro,skipRecentDays:X>0?0:7});console.log(`
|
|
295
|
+
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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(" Visit 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: ${s.visited}`),console.log(` Skipped: ${s.skipped} (visited recently)`),console.log(` Errors: ${s.errors}`),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
|
|
296
|
+
`),je(n,"success",s)}catch(s){console.error(`
|
|
297
|
+
Error:`,s.message),je(n,"error",null,s.message)}finally{await o.close().catch(()=>{})}}Oo().catch(e=>{console.error("Visit failed:",e),process.exit(1)});
|