ilml-plugin-linkedin 1.19.0 → 1.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/connect.mjs +66 -66
- package/dist/enrichProfile.mjs +9 -9
- package/dist/funnelRunner.mjs +49 -49
- package/dist/run.mjs +52 -52
- package/dist/syncAll.mjs +86 -86
- package/dist/verifyAbout.mjs +4 -4
- package/dist/version.mjs +1 -1
- package/dist/visit.mjs +11 -11
- package/ilml-plugin.json +1 -1
- package/package.json +1 -1
package/dist/verifyAbout.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var He=Object.defineProperty;var pe=(e,t)=>()=>(e&&(t=e(e=0)),t);var Ue=(e,t)=>{for(var o in t)He(e,o,{get:t[o],enumerable:!0})};async function f(e){let t=Math.floor(Math.random()*2001),o=e+t;return new Promise(n=>setTimeout(n,o))}async function he(e){return await e.evaluate(()=>{let t=document.querySelectorAll("div.artdeco-modal--is-open");for(let n of t){let i=n.innerText||"",d=i.includes("Premium")||i.includes("premium")||i.includes("Upgrade")||i.includes("upgrade"),l=i.includes("Try for")||i.includes("free trial")||i.includes("/month")||i.includes("per month")||i.includes("Start my")||i.includes("Subscribe"),g=i.includes("Get hired faster")||i.includes("Get hired 2x");if(d||l||g){let L=n.querySelector('button[aria-label="Dismiss"]')||n.querySelector("button.artdeco-modal__dismiss")||n.querySelector("button[data-test-modal-close-btn]");if(L)return L.click(),{dismissed:!0,matched:i.substring(0,80)};let I=n.querySelectorAll("button");for(let a of I){let S=a.innerText?.trim().toLowerCase()||"",p=a.getAttribute("aria-label")?.toLowerCase()||"";if(S==="not now"||S==="no thanks"||S==="dismiss"||p.includes("dismiss"))return a.click(),{dismissed:!0,matched:i.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 H=pe(()=>{});var De={};Ue(De,{extractCertificationsFromDetails:()=>dt,extractEducationFromDetails:()=>ct,extractExperienceFromDetails:()=>lt,extractFeaturedFromDetails:()=>at,extractRecommendationsFromDetails:()=>ft,extractSkillsFromDetails:()=>ut});async function lt(e,t){let o=t.replace(/\/+$/,"")+"/details/experience/";try{await e.goto(o,{waitUntil:"domcontentloaded",timeout:6e4}),await f(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 d=0;d<5;d++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await f(900);await f(1e3);let i=0;for(;i<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});)i++,await f(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await f(700);return await e.evaluate(()=>{let d=document.querySelector("main");if(!d)return[];function l(a){let S=[];for(let p of a.querySelectorAll("div")){let h=Array.from(p.children).filter(x=>x.tagName==="DIV");if(h.length<3)continue;let y=h.filter(x=>(x.textContent||"").trim().length>50);y.length<3||(p.textContent||"").length<500||S.push({el:p,count:y.length,totalText:(p.textContent||"").length})}return S.sort((p,h)=>h.count-p.count||p.totalText-h.totalText),S[0]?.el}let g=l(d);if(!g)return[];let L=Array.from(g.children).filter(a=>a.tagName==="DIV").filter(a=>(a.textContent||"").trim().length>50);function I(a){let S=a[0]||null,p=null,h=null;if(a[1]){let u=a[1].split("\xB7").map(
|
|
1
|
+
var He=Object.defineProperty;var pe=(e,t)=>()=>(e&&(t=e(e=0)),t);var Ue=(e,t)=>{for(var o in t)He(e,o,{get:t[o],enumerable:!0})};async function f(e){let t=Math.floor(Math.random()*2001),o=e+t;return new Promise(n=>setTimeout(n,o))}async function he(e){return await e.evaluate(()=>{let t=document.querySelectorAll("div.artdeco-modal--is-open");for(let n of t){let i=n.innerText||"",d=i.includes("Premium")||i.includes("premium")||i.includes("Upgrade")||i.includes("upgrade"),l=i.includes("Try for")||i.includes("free trial")||i.includes("/month")||i.includes("per month")||i.includes("Start my")||i.includes("Subscribe"),g=i.includes("Get hired faster")||i.includes("Get hired 2x");if(d||l||g){let L=n.querySelector('button[aria-label="Dismiss"]')||n.querySelector("button.artdeco-modal__dismiss")||n.querySelector("button[data-test-modal-close-btn]");if(L)return L.click(),{dismissed:!0,matched:i.substring(0,80)};let I=n.querySelectorAll("button");for(let a of I){let S=a.innerText?.trim().toLowerCase()||"",p=a.getAttribute("aria-label")?.toLowerCase()||"";if(S==="not now"||S==="no thanks"||S==="dismiss"||p.includes("dismiss"))return a.click(),{dismissed:!0,matched:i.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 H=pe(()=>{});var De={};Ue(De,{extractCertificationsFromDetails:()=>dt,extractEducationFromDetails:()=>ct,extractExperienceFromDetails:()=>lt,extractFeaturedFromDetails:()=>at,extractRecommendationsFromDetails:()=>ft,extractSkillsFromDetails:()=>ut});async function lt(e,t){let o=t.replace(/\/+$/,"")+"/details/experience/";try{await e.goto(o,{waitUntil:"domcontentloaded",timeout:6e4}),await f(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 d=0;d<5;d++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await f(900);await f(1e3);let i=0;for(;i<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});)i++,await f(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await f(700);return await e.evaluate(()=>{let d=document.querySelector("main");if(!d)return[];function l(a){let S=[];for(let p of a.querySelectorAll("div")){let h=Array.from(p.children).filter(x=>x.tagName==="DIV");if(h.length<3)continue;let y=h.filter(x=>(x.textContent||"").trim().length>50);y.length<3||(p.textContent||"").length<500||S.push({el:p,count:y.length,totalText:(p.textContent||"").length})}return S.sort((p,h)=>h.count-p.count||p.totalText-h.totalText),S[0]?.el}let g=l(d);if(!g)return[];let L=Array.from(g.children).filter(a=>a.tagName==="DIV").filter(a=>(a.textContent||"").trim().length>50);function I(a){let S=a[0]||null,p=null,h=null;if(a[1]){let u=a[1].split("\xB7").map(v=>v.trim());p=u[0]||null,u[1]&&(h=u[1])}let y=a.findIndex(u=>/(\d{4}|present)/i.test(u)&&/(-|–|—)/i.test(u)&&u.length<80),x=null,M=null;if(y>=0){let u=a[y].split("\xB7").map(v=>v.trim());x=u[0]||null,u[1]&&(M=u[1])}let q=null,R=-1;if(y>=0&&a[y+1]){let u=a[y+1],v=/^[>*\-•]|^>/.test(u),N=/https?:\/\//.test(u),O=/\d{4}/.test(u),C=/,/.test(u)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(u);!v&&!N&&!O&&u.length<100&&C&&(q=u,R=y+1)}let G=null,m=-1,F=a[a.length-1];if(F&&/and\s+\+\d+\s+skills?$/i.test(F)){m=a.length-1;let u=F.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);u&&(G={listed:u[1].split(",").map(v=>v.trim()),additional:parseInt(u[2],10)})}let P=new Set([0,1,y,R,m].filter(u=>u>=0)),$=a.filter((u,v)=>!P.has(v)),k=$.length>0?$.join(`
|
|
2
2
|
|
|
3
|
-
`):null;return{title:S,company:p,employmentType:h,dates:x,duration:M,location:
|
|
3
|
+
`):null;return{title:S,company:p,employmentType:h,dates:x,duration:M,location:q,description:k,skills:G,_raw:a}}return L.map(a=>{let p=(a.innerText||"").trim().split(`
|
|
4
4
|
`).map(h=>h.trim()).filter(h=>h&&h.length<5e3);return I(p)}).filter(a=>a.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)}`),[]}}async function U(e,t,o){let n=t.replace(/\/+$/,"")+`/details/${o}/`;await e.goto(n,{waitUntil:"domcontentloaded",timeout:6e4}),await f(3e3);let i=e.url();if(/\/(login|authwall|checkpoint)/i.test(i))throw new Error(`Session expired \u2014 bounced to ${i} when fetching /details/${o}/`);if(!i.toLowerCase().includes(`/details/${o.toLowerCase()}/`))throw new Error(`Section /details/${o}/ not available on profile (landed on ${i})`);for(let l=0;l<4;l++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await f(700);await f(800);let d=0;for(;d<5&&await e.evaluate(()=>{for(let g of document.querySelectorAll("button"))if(/^Load more$/i.test((g.textContent||"").trim()))return g.click(),!0;return!1});)d++,await f(1300),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await f(600)}async function W(e,t,o,n){try{return await n()}catch(i){let d=i.message||"";if(/session expired|bounced to|authwall|checkpoint/i.test(d))throw i;return/not available on profile/i.test(d)?(console.log(` (${t}: section not on profile \u2014 skipped)`),[]):(console.error(`${o} failed for ${e}: ${d.slice(0,120)}`),[])}}async function at(e,t){return W(t,"featured","extractFeaturedFromDetails",async()=>(await U(e,t,"featured"),await e.evaluate(`(() => {
|
|
5
5
|
${V}
|
|
6
6
|
|
|
@@ -235,8 +235,8 @@ function findEntryContainer(root) {
|
|
|
235
235
|
candidates.sort((a, b) => b.count - a.count || b.totalText - a.totalText);
|
|
236
236
|
return candidates[0]?.el;
|
|
237
237
|
}
|
|
238
|
-
`});import Ze from"puppeteer";import{addExtra as Xe}from"puppeteer-extra";import et from"puppeteer-extra-plugin-stealth";H();import{getPluginConfig as Ve}from"@ilivemylife/graph-sdk";var We=await Ve();for(let[e,t]of Object.entries(We))process.env[e]===void 0&&(process.env[e]=t);var Je=process.env.LINKEDIN_NAME,j=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),
|
|
239
|
-
Closing browser...`);try{await e.close()}catch{}process.exit(0)};process.on("SIGINT",n),process.on("SIGTERM",n);let i=await e.newPage();return await i.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Ee(i,{profileDir:t,needsSeed:o}),console.log(" Browser launched (persistent profile)."),{browser:e,page:i}}H();import"dotenv/config";import*as w from"fs";import*as b from"path";import{fileURLToPath as tt}from"url";var nt=tt(import.meta.url),ot=b.dirname(b.dirname(nt)),A=process.env.DATA_DIR?b.resolve(process.env.DATA_DIR,"collected-profiles"):b.join(ot,"collected-profiles"),it=b.join(A,"people.json"),Ut=b.join(A,"jobs.json"),Vt=b.join(A,"quota.json"),Wt=b.join(A,"conversations.json"),Jt=b.join(A,"sync-state.json"),Kt=b.join(A,"application-questions.json"),Yt=b.join(A,"profile-history"),$e=(e,t)=>{let o=parseInt(e,10);return Number.isInteger(o)&&o>=0?o:t},Gt=$e(process.env.CONNECT_MAX_DAILY,20),zt=$e(process.env.CONNECT_MAX_WEEKLY,100),Y=null;function
|
|
238
|
+
`});import Ze from"puppeteer";import{addExtra as Xe}from"puppeteer-extra";import et from"puppeteer-extra-plugin-stealth";H();import{getPluginConfig as Ve}from"@ilivemylife/graph-sdk";var We=await Ve();for(let[e,t]of Object.entries(We))process.env[e]===void 0&&(process.env[e]=t);var Je=process.env.LINKEDIN_NAME,j=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),vt=Object.freeze(new Set([j.DRAFT,j.CONFIRMED,j.NEEDS_REVIEW])),Ke=Object.freeze(new Set([j.DRAFT,j.CONFIRMED,j.REJECTED,j.NEEDS_REVIEW]));import _ from"fs";import T from"path";var Ye="cookies.json";function ge(){let e=process.env.ILML_SCOPE_DIR;return e?T.join(e,"plugins-state","linkedin","cookies.json"):Ye}function we(){let e=ge();if(!_.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=_.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}function ye(){return _.existsSync(ge())}function Ge(){let e=process.env.ILML_SCOPE_DIR;return e?T.join(e,"plugins-state","linkedin"):"."}function be(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function ze(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?be(t[1]):"default"}function Se(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return _.existsSync(t)||_.mkdirSync(t,{recursive:!0}),T.resolve(t);let o=be(e||ze()),n=T.join(Ge(),"chrome-profile",o);return _.existsSync(n)||_.mkdirSync(n,{recursive:!0}),T.resolve(n)}var ve=".ilml-seeded";function Ce(e){return!_.existsSync(T.join(e,ve))}function ke(e){try{_.writeFileSync(T.join(e,ve),new Date().toISOString())}catch{}}function xe(e){let t=0;for(let o of["SingletonLock","SingletonCookie","SingletonSocket"])try{_.rmSync(T.join(e,o),{force:!0}),t++}catch{}return t}var Qe={headless:!1,defaultViewport:null,protocolTimeout:3e5};async function _e(e,t={}){let o=Se(),n={...Qe,...t,userDataDir:o},i;try{i=await e.launch(n)}catch{xe(o);try{i=await e.launch(n)}catch(l){throw new Error(`Could not open the LinkedIn automation Chrome profile at ${o}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${l.message})`)}}return{browser:i,profileDir:o,needsSeed:Ce(o)}}async function Ee(e,t){if(!t||!t.needsSeed)return!1;if(!ye())return console.warn(" \u26A0 No saved LinkedIn session found. If this command comes back empty or redirects to login, run: ilml linkedin login"),!1;try{return await e.setCookie(...we()),ke(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var Ae=Xe(Ze);Ae.use(et());async function Ie(){let{browser:e,profileDir:t,needsSeed:o}=await _e(Ae),n=async()=>{console.log(`
|
|
239
|
+
Closing browser...`);try{await e.close()}catch{}process.exit(0)};process.on("SIGINT",n),process.on("SIGTERM",n);let i=await e.newPage();return await i.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Ee(i,{profileDir:t,needsSeed:o}),console.log(" Browser launched (persistent profile)."),{browser:e,page:i}}H();import"dotenv/config";import*as w from"fs";import*as b from"path";import{fileURLToPath as tt}from"url";var nt=tt(import.meta.url),ot=b.dirname(b.dirname(nt)),A=process.env.DATA_DIR?b.resolve(process.env.DATA_DIR,"collected-profiles"):b.join(ot,"collected-profiles"),it=b.join(A,"people.json"),Ut=b.join(A,"jobs.json"),Vt=b.join(A,"quota.json"),Wt=b.join(A,"conversations.json"),Jt=b.join(A,"sync-state.json"),Kt=b.join(A,"application-questions.json"),Yt=b.join(A,"profile-history"),$e=(e,t)=>{let o=parseInt(e,10);return Number.isInteger(o)&&o>=0?o:t},Gt=$e(process.env.CONNECT_MAX_DAILY,20),zt=$e(process.env.CONNECT_MAX_WEEKLY,100),Y=null;function rt(){w.existsSync(A)||w.mkdirSync(A,{recursive:!0})}function st(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: ${b.resolve(e)}`);let n=e+".backup";if(w.existsSync(n))try{let i=JSON.parse(w.readFileSync(n,"utf-8"));console.error(` Restored from ${n}`);try{w.copyFileSync(n,e)}catch{}return i}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 Z(){return Y||(rt(),Y=st(it,"people.json")||{},Y)}async function mt(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: ilml linkedin login");console.log(` Off-track: ${o.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await f(3e3);let n=e.url();return n.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${n.slice(0,80)}`),!0}async function Le(e,t,o={}){let{extractExperience:n=!1,extractFeatured:i=!1,extractEducation:d=!1,extractSkills:l=!1,extractRecommendations:g=!1,extractCertifications:L=!1}=o;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await f(3e3),await he(e)&&(console.log(" Dismissed Premium overlay"),await f(1500),await mt(e,t));let a=0;for(let m=0;m<2;m++){let F=await e.evaluate(()=>document.body.scrollHeight);for(let $=1;$<=6;$++)await e.evaluate(k=>window.scrollTo(0,k),F*$/6),await f(900);let P=await e.evaluate(()=>document.body.scrollHeight);if(P===a)break;a=P}await f(800);let S=null;try{let m=e.url();m&&/\/in\/[^/?#]/.test(m)&&(S=m.split("?")[0].replace(/\/+$/,""))}catch{}let p=await e.evaluate(()=>{let m=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"]),P=r=>{let s=(r||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(s)},$={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:[]},k=document.querySelector("main");if(!k)return $;let u=[...Array.from(k.querySelectorAll("h1")),...Array.from(k.querySelectorAll("h2"))],v=Array.from(k.querySelectorAll("h2")),N=u.find(r=>{let s=r.textContent&&r.textContent.trim(),c=(s||"").replace(/\s*\(\d+\)$/,"").trim();return s&&s.length>1&&s.length<100&&!m.has(c)&&!F.has(c)}),O=N?N.textContent.trim():null,C=N?N.parentElement:null;for(;C&&C!==k&&!Array.from(C.children).filter(s=>s.tagName==="P").some(s=>{let c=s.textContent&&s.textContent.trim();return c&&c.length>5&&!P(c)});)C=C.parentElement;let ee=null,te=null,ne=null,z=null;if(C&&C!==k){let r=Array.from(C.children).filter(c=>c.tagName==="P").filter(c=>{let D=c.textContent&&c.textContent.trim();return D&&D.length>5&&!P(D)});if(r[0]&&(ee=r[0].textContent.trim()),r[1]){let c=r[1].textContent.trim().split(/\s*[·•]\s*/);te=c[0]||null,c.length>1&&(ne=c.slice(1).join(" \xB7 "))}let s=Array.from(C.children).filter(c=>c.tagName==="DIV");for(let c=s.length-1;c>=0;c--){let D=s[c].textContent&&s[c].textContent.trim();if(D&&!(O&&D.startsWith(O))&&(z=D.split(/[·•]/)[0].trim(),z))break}}let oe=null;if(C){let r=C.querySelectorAll("p, span, div");for(let s of r){let c=(s.textContent||"").trim().replace(/^[·•]\s*/,"");if(c==="1st"||c==="2nd"||c==="3rd"){oe=c;break}}}let Re=!!k.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),ie=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),Fe=ie&&ie.src||null,J=k.textContent||"",re=null,se=J.match(/(\d+\+?)\s+connections\b/i);se&&(re=se[1]+" connections");let K=null,le=J.match(/(\d+)\s+mutual connection/i),ae=J.match(/and\s+(\d+)\s+other mutual/i),Pe=J.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);le?K=parseInt(le[1],10):ae?K=2+parseInt(ae[1],10):Pe&&(K=2);let ce=null,ue=null,de=v.find(r=>r.textContent&&r.textContent.trim()==="About");if(de){let r=de.parentElement;for(;r&&r.tagName!=="SECTION";)r=r.parentElement;if(r){let s=(r.textContent||"").trim();s=s.replace(/^About\s*/,"").trim();let c=s.match(/Top skills\s*(.+?)$/i);if(c){let Q=c[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Be=>Be.trim()).filter(Boolean);Q.length>0&&Q.length<10&&(ue=Q)}s=s.split(/\n?…\s*more/i)[0].trim(),s=s.split(/\n?\.\.\.\s*more/i)[0].trim(),s=s.split(/\bTop skills\b/i)[0].trim(),s=s.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),ce=s||null}}let fe=null,me=v.find(r=>r.textContent&&r.textContent.trim()==="Activity");if(me){let r=me.parentElement;for(;r&&r.tagName!=="SECTION";)r=r.parentElement;if(r){let s=(r.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);s&&(fe=parseInt(s[1].replace(/,/g,""),10))}}let je=[...new Set(v.map(r=>(r.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(r=>r&&r.length>1&&r.length<60&&r!==O).filter(r=>m.has(r)))],B=document.body.textContent||"",Ne=/#OpenToWork\b/i.test(B)||/\bOpen to work\b/.test(B),Oe=/#Hiring\b/i.test(B)||/\bI'?m hiring\b/i.test(B)||/\bWe are hiring\b/i.test(B);return{name:O,title:ee,location:z,currentCompany:te,currentSchool:ne,connectionDegree:oe,hasVerifiedBadge:Re,photoUrl:Fe,connectionsLevel:re,mutualConnectionsCount:K,followers:fe,openToWork:Ne,hiring:Oe,about:ce,topSkills:ue,availableSections:je}});console.log(`Viewed: ${p.name} - ${p.title}`);let h=null,y=null,x=null,M=null,q=null,R=null;if(n||i||d||l||g||L){let m=await Promise.resolve().then(()=>(Te(),De));n&&(h=await m.extractExperienceFromDetails(e,t),console.log(` + Experience: ${h.length} entries`)),i&&(y=await m.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${y.length} entries`)),d&&(x=await m.extractEducationFromDetails(e,t),console.log(` + Education: ${x.length} entries`)),l&&(M=await m.extractSkillsFromDetails(e,t),console.log(` + Skills: ${M.length} entries`)),g&&(q=await m.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${q.length} entries`)),L&&(R=await m.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${R.length} entries`))}return{...p,profileUrl:t,resolvedUrl:S,...h!==null&&{experience:h},...y!==null&&{featured:y},...x!==null&&{education:x},...M!==null&&{skillsFull:M},...q!==null&&{recommendations:q},...R!==null&&{certifications:R}}}catch(I){console.error(`Error viewing profile ${t}:`,I.message);try{await e.goto("about:blank",{timeout:1e4}),await f(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(I.message||""))throw I;return null}}H();var X=process.argv.slice(2),Me=X.filter(e=>e.startsWith("http")),qe=parseInt(X.find(e=>e.startsWith("--pick="))?.split("=")[1]||"0"),pt=X.includes("--has-about");function ht(e,t){return[...e].sort(()=>Math.random()-.5).slice(0,t)}function gt(){if(Me.length>0)return Me.map(t=>({url:t,name:"(arg)"}));if(qe>0){let t=Z(),o=Object.entries(t).filter(([n])=>n.startsWith("http")).filter(([,n])=>pt?!!(n.about&&n.about.trim()):!n.about);return ht(o,qe).map(([n,i])=>({url:n,name:i.name}))}let e=process.env.MY_LINKEDIN_URL;return e||(console.error("Pass a URL, use --pick=N, or set MY_LINKEDIN_URL in .env"),process.exit(1)),[{url:e,name:"(self)"}]}function E(e,t,o=80){if(t==null){console.log(` ${e.padEnd(20)} (null)`);return}let n=String(t),i=n.length>o?n.slice(0,o)+`\u2026 (+${n.length-o} chars)`:n;console.log(` ${e.padEnd(20)} ${i} [len=${n.length}]`)}async function wt(){let e=gt();console.log(`
|
|
240
240
|
About-selector verification \u2014 ${e.length} profile(s)
|
|
241
241
|
`);let{browser:t,page:o}=await Ie();try{for(let n=0;n<e.length;n++){let{url:i,name:d}=e[n];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(` [${n+1}/${e.length}] ${d}`),console.log(` ${i}`),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");let l=await Le(o,i);if(!l){console.log(` \u26A0 viewProfile returned null \u2014 selector failed entirely
|
|
242
242
|
`);continue}E("name",l.name),E("title",l.title),E("location",l.location),E("company",l.company),E("connectionDegree",l.connectionDegree),E("connectionsCount",l.connectionsCount),E("mutualConnections",l.mutualConnections),E("hasVerifiedBadge",l.hasVerifiedBadge),E("photoUrl",l.photoUrl,60),console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 about \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),E("about",l.about,200);let g=[];l.name||g.push("NAME MISSING"),l.title||g.push("TITLE MISSING"),l.location||g.push("LOCATION MISSING"),l.about||g.push("ABOUT MISSING"),console.log(`
|
package/dist/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readFileSync as e}from"fs";import{fileURLToPath as r}from"url";function i(){return"1.19.
|
|
1
|
+
import{readFileSync as e}from"fs";import{fileURLToPath as r}from"url";function i(){return"1.19.2";try{let n=new URL("./ilml-plugin.json",import.meta.url);return JSON.parse(e(r(n),"utf-8")).version}catch{return"unknown"}}console.log(`ilml-plugin-linkedin ${i()}`);
|
package/dist/visit.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var gn=Object.defineProperty;var at=(e,t)=>()=>(e&&(t=e(e=0)),t);var fe=(e,t)=>{for(var n in t)gn(e,n,{get:t[n],enumerable:!0})};async function x(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function ct(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"),u=r.includes("Get hired faster")||r.includes("Get hired 2x");if(s||i||u){let l=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(l)return l.click(),{dismissed:!0,matched:r.substring(0,80)};let m=o.querySelectorAll("button");for(let a of m){let w=a.innerText?.trim().toLowerCase()||"",c=a.getAttribute("aria-label")?.toLowerCase()||"";if(w==="not now"||w==="no thanks"||w==="dismiss"||c.includes("dismiss"))return a.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 me=at(()=>{});var
|
|
1
|
+
var gn=Object.defineProperty;var at=(e,t)=>()=>(e&&(t=e(e=0)),t);var fe=(e,t)=>{for(var n in t)gn(e,n,{get:t[n],enumerable:!0})};async function x(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function ct(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"),u=r.includes("Get hired faster")||r.includes("Get hired 2x");if(s||i||u){let l=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(l)return l.click(),{dismissed:!0,matched:r.substring(0,80)};let m=o.querySelectorAll("button");for(let a of m){let w=a.innerText?.trim().toLowerCase()||"",c=a.getAttribute("aria-label")?.toLowerCase()||"";if(w==="not now"||w==="no thanks"||w==="dismiss"||c.includes("dismiss"))return a.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 me=at(()=>{});var jt={};fe(jt,{extractCertificationsFromDetails:()=>Gn,extractEducationFromDetails:()=>Wn,extractExperienceFromDetails:()=>Hn,extractFeaturedFromDetails:()=>Jn,extractRecommendationsFromDetails:()=>Kn,extractSkillsFromDetails:()=>Yn});async function Hn(e,t){let n=t.replace(/\/+$/,"")+"/details/experience/";try{await e.goto(n,{waitUntil:"domcontentloaded",timeout:6e4}),await x(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 x(900);await x(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 x(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await x(700);return await e.evaluate(()=>{let s=document.querySelector("main");if(!s)return[];function i(a){let w=[];for(let c of a.querySelectorAll("div")){let f=Array.from(c.children).filter(S=>S.tagName==="DIV");if(f.length<3)continue;let C=f.filter(S=>(S.textContent||"").trim().length>50);C.length<3||(c.textContent||"").length<500||w.push({el:c,count:C.length,totalText:(c.textContent||"").length})}return w.sort((c,f)=>f.count-c.count||c.totalText-f.totalText),w[0]?.el}let u=i(s);if(!u)return[];let l=Array.from(u.children).filter(a=>a.tagName==="DIV").filter(a=>(a.textContent||"").trim().length>50);function m(a){let w=a[0]||null,c=null,f=null;if(a[1]){let v=a[1].split("\xB7").map(I=>I.trim());c=v[0]||null,v[1]&&(f=v[1])}let C=a.findIndex(v=>/(\d{4}|present)/i.test(v)&&/(-|–|—)/i.test(v)&&v.length<80),S=null,_=null;if(C>=0){let v=a[C].split("\xB7").map(I=>I.trim());S=v[0]||null,v[1]&&(_=v[1])}let g=null,h=-1;if(C>=0&&a[C+1]){let v=a[C+1],I=/^[>*\-•]|^>/.test(v),ie=/https?:\/\//.test(v),le=/\d{4}/.test(v),D=/,/.test(v)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(v);!I&&!ie&&!le&&v.length<100&&D&&(g=v,h=C+1)}let B=null,E=-1,z=a[a.length-1];if(z&&/and\s+\+\d+\s+skills?$/i.test(z)){E=a.length-1;let v=z.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);v&&(B={listed:v[1].split(",").map(I=>I.trim()),additional:parseInt(v[2],10)})}let Q=new Set([0,1,C,h,E].filter(v=>v>=0)),J=a.filter((v,I)=>!Q.has(I)),R=J.length>0?J.join(`
|
|
2
2
|
|
|
3
|
-
`):null;return{title:w,company:c,employmentType:f,dates:S,duration:_,location:g,description:
|
|
3
|
+
`):null;return{title:w,company:c,employmentType:f,dates:S,duration:_,location:g,description:R,skills:B,_raw:a}}return l.map(a=>{let c=(a.innerText||"").trim().split(`
|
|
4
4
|
`).map(f=>f.trim()).filter(f=>f&&f.length<5e3);return m(c)}).filter(a=>a.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 pe(e,t,n){let o=t.replace(/\/+$/,"")+`/details/${n}/`;await e.goto(o,{waitUntil:"domcontentloaded",timeout:6e4}),await x(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 x(700);await x(800);let s=0;for(;s<5&&await e.evaluate(()=>{for(let u of document.querySelectorAll("button"))if(/^Load more$/i.test((u.textContent||"").trim()))return u.click(),!0;return!1});)s++,await x(1300),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await x(600)}async function ge(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 Jn(e,t){return ge(t,"featured","extractFeaturedFromDetails",async()=>(await pe(e,t,"featured"),await e.evaluate(`(() => {
|
|
5
5
|
${he}
|
|
6
6
|
|
|
@@ -236,14 +236,14 @@ function findEntryContainer(root) {
|
|
|
236
236
|
return candidates[0]?.el;
|
|
237
237
|
}
|
|
238
238
|
`});import $n from"puppeteer";import{addExtra as En}from"puppeteer-extra";import An from"puppeteer-extra-plugin-stealth";me();import{getPluginConfig as yn}from"@ilivemylife/graph-sdk";var wn=await yn();for(let[e,t]of Object.entries(wn))process.env[e]===void 0&&(process.env[e]=t);var bn=process.env.LINKEDIN_NAME,Z=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),ur=Object.freeze(new Set([Z.DRAFT,Z.CONFIRMED,Z.NEEDS_REVIEW])),Sn=Object.freeze(new Set([Z.DRAFT,Z.CONFIRMED,Z.REJECTED,Z.NEEDS_REVIEW]));import q from"fs";import Y from"path";var vn="cookies.json";function ut(){let e=process.env.ILML_SCOPE_DIR;return e?Y.join(e,"plugins-state","linkedin","cookies.json"):vn}function dt(){let e=ut();if(!q.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=q.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}function ft(){return q.existsSync(ut())}function kn(){let e=process.env.ILML_SCOPE_DIR;return e?Y.join(e,"plugins-state","linkedin"):"."}function mt(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function Cn(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?mt(t[1]):"default"}function pt(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return q.existsSync(t)||q.mkdirSync(t,{recursive:!0}),Y.resolve(t);let n=mt(e||Cn()),o=Y.join(kn(),"chrome-profile",n);return q.existsSync(o)||q.mkdirSync(o,{recursive:!0}),Y.resolve(o)}var ht=".ilml-seeded";function gt(e){return!q.existsSync(Y.join(e,ht))}function yt(e){try{q.writeFileSync(Y.join(e,ht),new Date().toISOString())}catch{}}function wt(e){let t=0;for(let n of["SingletonLock","SingletonCookie","SingletonSocket"])try{q.rmSync(Y.join(e,n),{force:!0}),t++}catch{}return t}var xn={headless:!1,defaultViewport:null,protocolTimeout:3e5};async function bt(e,t={}){let n=pt(),o={...xn,...t,userDataDir:n},r;try{r=await e.launch(o)}catch{wt(n);try{r=await e.launch(o)}catch(i){throw new Error(`Could not open the LinkedIn automation Chrome profile at ${n}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${i.message})`)}}return{browser:r,profileDir:n,needsSeed:gt(n)}}async function St(e,t){if(!t||!t.needsSeed)return!1;if(!ft())return console.warn(" \u26A0 No saved LinkedIn session found. If this command comes back empty or redirects to login, run: ilml linkedin login"),!1;try{return await e.setCookie(...dt()),yt(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var vt=En($n);vt.use(An());async function kt(){let{browser:e,profileDir:t,needsSeed:n}=await bt(vt),o=async()=>{console.log(`
|
|
239
|
-
Closing browser...`);try{await e.close()}catch{}process.exit(0)};process.on("SIGINT",o),process.on("SIGTERM",o);let r=await e.newPage();return await r.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await St(r,{profileDir:t,needsSeed:n}),console.log(" Browser launched (persistent profile)."),{browser:e,page:r}}me();import"dotenv/config";import*as $ from"fs";import*as A from"path";import{fileURLToPath as _n}from"url";var In=_n(import.meta.url),Dn=A.dirname(A.dirname(In)),V=process.env.DATA_DIR?A.resolve(process.env.DATA_DIR,"collected-profiles"):A.join(Dn,"collected-profiles"),_e=A.join(V,"people.json"),Tr=A.join(V,"jobs.json"),jr=A.join(V,"quota.json"),Or=A.join(V,"conversations.json"),Nr=A.join(V,"sync-state.json"),Lr=A.join(V,"application-questions.json"),Ie=A.join(V,"profile-history"),Et=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},Fr=Et(process.env.CONNECT_MAX_DAILY,20),Mr=Et(process.env.CONNECT_MAX_WEEKLY,100),ae=null,Rn=null,Tn=null,jn=null,On=null,Nn=null;function At(){ae=null,Rn=null,Tn=null,jn=null,On=null,Nn=null}function _t(){$.existsSync(V)||$.mkdirSync(V,{recursive:!0})}function It(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";$.writeFileSync(o,n);for(let r=0;r<3;r++)try{$.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 Dt(e,t){if(!$.existsSync(e))return null;try{let n=JSON.parse($.readFileSync(e,"utf-8"));try{$.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($.existsSync(o))try{let r=JSON.parse($.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{$.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{$.copyFileSync(e,e+".corrupted")}catch{}return null}}function Ln(){return new Date().toISOString().split("T")[0]}var Fn=["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"],Mn=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function X(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function Ct(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function Rt(e,t,n=null){if(!t||e[t])return t;let o=X(t);if(!o)return t;let r=null;for(let[s,i]of Object.entries(e)){if(X(i.profileUrl||s)===o)return s;!r&&Array.isArray(i.aliases)&&i.aliases.includes(o)&&(r=s)}if(r){let s=Ct(n),i=Ct(e[r].name);if(s&&i&&s===i)return r}return t}function Pn(){$.existsSync(Ie)||$.mkdirSync(Ie,{recursive:!0})}function Tt(e){let t=X(e);return t?A.join(Ie,`${t}.json`):null}function qn(e){let t=Tt(e);return t?Dt(t,`profile-history/${X(e)}.json`)||[]:[]}function Un(e,t){let n=Tt(e);if(!n)return;Pn();let o=qn(e);o.unshift(t);try{It(n,o)}catch(r){console.error(`[!] Failed to append profile-history for ${X(e)}: ${r.message}`)}}function xt(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function $t(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function Bn(e,t){if(!e)return[];let n=[];for(let o of Mn){let r=e[o],s=t[o];xt(r)||xt(s)||$t(r)!==$t(s)&&n.push(o)}return n}function Vn(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 ce(){return ae||(_t(),ae=Dt(_e,"people.json")||{},ae)}function jt(e){_t(),ae=e;try{It(_e,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${A.resolve(_e)}`)}}function De(e,t={}){if(!e)return null;let n=ce(),o=Ln(),r=new Date().toISOString(),s=Rt(n,e,t.name),i=n[s];if(i){let u=Bn(i,t);u.length>0&&(Un(s,{capturedAt:r,previousLastUpdated:i.lastUpdated||null,changedFields:u,snapshot:Vn(i)}),i.lastSnapshotAt=r),i.seenCount=(i.seenCount||1)+1,i.lastSeen=o,i.lastUpdated=r,t.source&&!i.sources?.includes(t.source)&&(i.sources=i.sources||[],i.sources.push(t.source));for(let l of Fn)if(t[l]!=null){if(Array.isArray(t[l])&&t[l].length===0&&Array.isArray(i[l])&&i[l].length>0)continue;i[l]=t[l]}Array.isArray(t.availableSections)&&(i.lastFullVisitAt=r)}else n[s]={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,requestedConnectionAt:null,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:r,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?r:null};return jt(n),n[s]}function Re(e,t,n={}){if(n.dryRun||!e||!t)return;let o=X(t);if(!o)return;let r=ce(),s=Rt(r,e),i=r[s];if(!i)return;let u=X(i.profileUrl||s);o!==u&&(Array.isArray(i.aliases)||(i.aliases=[]),i.aliases.includes(o)||(i.aliases.push(o),i.lastUpdated=new Date().toISOString(),jt(r)))}async function zn(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: ilml linkedin login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await x(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function Lt(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:s=!1,extractSkills:i=!1,extractRecommendations:u=!1,extractCertifications:l=!1}=n;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await x(3e3),await ct(e)&&(console.log(" Dismissed Premium overlay"),await x(1500),await zn(e,t));let a=0;for(let E=0;E<2;E++){let z=await e.evaluate(()=>document.body.scrollHeight);for(let J=1;J<=6;J++)await e.evaluate(T=>window.scrollTo(0,T),z*J/6),await x(900);let Q=await e.evaluate(()=>document.body.scrollHeight);if(Q===a)break;a=Q}await x(800);let w=null;try{let E=e.url();E&&/\/in\/[^/?#]/.test(E)&&(w=E.split("?")[0].replace(/\/+$/,""))}catch{}let c=await e.evaluate(()=>{let E=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"]),z=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 y=(p||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(y)},J={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 J;let v=[...Array.from(T.querySelectorAll("h1")),...Array.from(T.querySelectorAll("h2"))],I=Array.from(T.querySelectorAll("h2")),ie=v.find(p=>{let y=p.textContent&&p.textContent.trim(),b=(y||"").replace(/\s*\(\d+\)$/,"").trim();return y&&y.length>1&&y.length<100&&!E.has(b)&&!z.has(b)}),le=ie?ie.textContent.trim():null,D=ie?ie.parentElement:null;for(;D&&D!==T&&!Array.from(D.children).filter(y=>y.tagName==="P").some(y=>{let b=y.textContent&&y.textContent.trim();return b&&b.length>5&&!Q(b)});)D=D.parentElement;let Ge=null,Ke=null,ze=null,Ee=null;if(D&&D!==T){let p=Array.from(D.children).filter(b=>b.tagName==="P").filter(b=>{let W=b.textContent&&b.textContent.trim();return W&&W.length>5&&!Q(W)});if(p[0]&&(Ge=p[0].textContent.trim()),p[1]){let b=p[1].textContent.trim().split(/\s*[·•]\s*/);Ke=b[0]||null,b.length>1&&(ze=b.slice(1).join(" \xB7 "))}let y=Array.from(D.children).filter(b=>b.tagName==="DIV");for(let b=y.length-1;b>=0;b--){let W=y[b].textContent&&y[b].textContent.trim();if(W&&!(le&&W.startsWith(le))&&(Ee=W.split(/[·•]/)[0].trim(),Ee))break}}let Qe=null;if(D){let p=D.querySelectorAll("p, span, div");for(let y of p){let b=(y.textContent||"").trim().replace(/^[·•]\s*/,"");if(b==="1st"||b==="2nd"||b==="3rd"){Qe=b;break}}}let cn=!!T.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),Ze=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),un=Ze&&Ze.src||null,Se=T.textContent||"",Xe=null,et=Se.match(/(\d+\+?)\s+connections\b/i);et&&(Xe=et[1]+" connections");let ve=null,tt=Se.match(/(\d+)\s+mutual connection/i),nt=Se.match(/and\s+(\d+)\s+other mutual/i),dn=Se.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);tt?ve=parseInt(tt[1],10):nt?ve=2+parseInt(nt[1],10):dn&&(ve=2);let ot=null,rt=null,st=I.find(p=>p.textContent&&p.textContent.trim()==="About");if(st){let p=st.parentElement;for(;p&&p.tagName!=="SECTION";)p=p.parentElement;if(p){let y=(p.textContent||"").trim();y=y.replace(/^About\s*/,"").trim();let b=y.match(/Top skills\s*(.+?)$/i);if(b){let Ae=b[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(hn=>hn.trim()).filter(Boolean);Ae.length>0&&Ae.length<10&&(rt=Ae)}y=y.split(/\n?…\s*more/i)[0].trim(),y=y.split(/\n?\.\.\.\s*more/i)[0].trim(),y=y.split(/\bTop skills\b/i)[0].trim(),y=y.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),ot=y||null}}let it=null,lt=I.find(p=>p.textContent&&p.textContent.trim()==="Activity");if(lt){let p=lt.parentElement;for(;p&&p.tagName!=="SECTION";)p=p.parentElement;if(p){let y=(p.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);y&&(it=parseInt(y[1].replace(/,/g,""),10))}}let fn=[...new Set(I.map(p=>(p.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(p=>p&&p.length>1&&p.length<60&&p!==le).filter(p=>E.has(p)))],de=document.body.textContent||"",mn=/#OpenToWork\b/i.test(de)||/\bOpen to work\b/.test(de),pn=/#Hiring\b/i.test(de)||/\bI'?m hiring\b/i.test(de)||/\bWe are hiring\b/i.test(de);return{name:le,title:Ge,location:Ee,currentCompany:Ke,currentSchool:ze,connectionDegree:Qe,hasVerifiedBadge:cn,photoUrl:un,connectionsLevel:Xe,mutualConnectionsCount:ve,followers:it,openToWork:mn,hiring:pn,about:ot,topSkills:rt,availableSections:fn}});console.log(`Viewed: ${c.name} - ${c.title}`);let f=null,C=null,S=null,_=null,g=null,h=null;if(o||r||s||i||u||l){let E=await Promise.resolve().then(()=>(Nt(),Ot));o&&(f=await E.extractExperienceFromDetails(e,t),console.log(` + Experience: ${f.length} entries`)),r&&(C=await E.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${C.length} entries`)),s&&(S=await E.extractEducationFromDetails(e,t),console.log(` + Education: ${S.length} entries`)),i&&(_=await E.extractSkillsFromDetails(e,t),console.log(` + Skills: ${_.length} entries`)),u&&(g=await E.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${g.length} entries`)),l&&(h=await E.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${h.length} entries`))}return{...c,profileUrl:t,resolvedUrl:w,...f!==null&&{experience:f},...C!==null&&{featured:C},...S!==null&&{education:S},..._!==null&&{skillsFull:_},...g!==null&&{recommendations:g},...h!==null&&{certifications:h}}}catch(m){console.error(`Error viewing profile ${t}:`,m.message);try{await e.goto("about:blank",{timeout:1e4}),await x(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 Qn}from"url";var Zn=Qn(import.meta.url),Xn=j.dirname(j.dirname(Zn)),te=process.env.DATA_DIR?j.resolve(process.env.DATA_DIR,"market-research"):j.join(Xn,"market-research"),eo=j.join(te,"scouted-jobs.json"),to=j.join(te,"discovered-people.json"),Ft=j.join(te,"visit-log.json"),Zr=j.join(te,"companies.json"),Xr=j.join(te,"job-decisions.json");function no(){O.existsSync(te)||O.mkdirSync(te,{recursive:!0})}function oo(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 Te(e){try{if(O.existsSync(e))return JSON.parse(O.readFileSync(e,"utf-8"))}catch{}return null}function Mt(){ye=null,so=null,we=null,io=null,ee=null}var ye=null;function ro(){return ye||(ye=Te(eo)||{},ye)}var so=null;var we=null;function ke(){return we||(we=Te(to)||{},we)}var io=null;var ee=null;function ue(){return ee||(ee=Te(Ft)||{visits:[]},Array.isArray(ee.visits)||(ee.visits=[]),ee)}function Pt(e,t={}){if(!e)return;no();let n=ue();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{oo(Ft,n)}catch(r){console.error(`[!] Failed to save visit-log.json: ${r.message}`)}}function qt(e){let t=ue();for(let n=t.visits.length-1;n>=0;n--)if(t.visits[n].profileUrl===e)return t.visits[n].date;return null}function Ut(){let e=ro(),t=ke(),n=Object.values(e),o=Object.values(t),r={};for(let c of n)c.company&&(r[c.company]=(r[c.company]||0)+1);let s=Object.entries(r).sort((c,f)=>f[1]-c[1]).slice(0,5).map(([c,f])=>`${c} (${f})`),i={};for(let c of n)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=ue(),m=new Date().toISOString().slice(0,10),a=l.visits.filter(c=>c.date.startsWith(m)).length,w=new Set(l.visits.map(c=>c.profileUrl)).size;return{totalJobs:n.length,totalRecruiters:o.length,topCompanies:s,topTech:u,totalVisited:w,todayVisited:a,lastScoutDate:n.length>0?n.sort((c,f)=>(f.scoutedAt||"").localeCompare(c.scoutedAt||""))[0]?.scoutedAt:null}}me();async function Bt(e,t,n={}){let{maxVisits:o=50,delayBetween:r=4e3,skipRecentDays:s=7,verbose:i=!1,extractExperience:u=!1}=n,l={visited:0,skipped:0,errors:0},m=Date.now()-s*24*60*60*1e3;for(let a of t){if(l.visited>=o)break;if(!a.profileUrl)continue;let w=qt(a.profileUrl);if(w&&new Date(w).getTime()>m){l.skipped++;continue}try{let c=await Lt(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()),De(a.profileUrl,S),c.resolvedUrl&&Re(a.profileUrl,c.resolvedUrl)}Pt(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 x(r+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 Vt(e={}){let{limit:t=150,revisitDays:n=14}=e,o=ue(),r=new Set(o.visits?.map(g=>g.profileUrl)||[]),s=new Map;for(let g of o.visits||[]){let h=s.get(g.profileUrl);(!h||g.date>h)&&s.set(g.profileUrl,g.date)}let i=Date.now()-7*24*60*60*1e3,u=Date.now()-n*24*60*60*1e3;function l(g){let h=s.get(g);return h&&new Date(h).getTime()>i}let m=ke(),a=Object.entries(m).filter(([g])=>!r.has(g)).map(([g,h])=>({profileUrl:g,name:h.name,source:"new-discovered",priority:1,jobCount:h.jobIds?.length||0})),w=ce(),c=Object.entries(w).filter(([g,h])=>h.connectionStatus==="connected"||l(g)?!1:(h.jobCount||h.jobIds?.length||0)>=2).map(([g,h])=>({profileUrl:g,name:h.name,source:"active-recruiter",priority:2,jobCount:h.jobCount||h.jobIds?.length||0})),f=Object.entries(w).filter(([g,h])=>{let B=h.connectionStatus;return!(!B||B==="connected"||B==="pending"||B==="sent_without_note"||B==="sent_with_note"||l(g)||(h.jobCount||h.jobIds?.length||0)>=2)}).map(([g,h])=>({profileUrl:g,name:h.name,source:"unconnected",priority:3,jobCount:h.jobCount||h.jobIds?.length||0})),C=[...s.entries()].filter(([g,h])=>new Date(h).getTime()<u).map(([g,h])=>({profileUrl:g,name:null,source:"revisit",priority:4,lastVisit:h})),S=g=>g.sort(()=>Math.random()-.5);return a.sort((g,h)=>h.jobCount-g.jobCount),c.sort((g,h)=>h.jobCount-g.jobCount),S(f),S(C),[...a,...c,...f,...C].slice(0,t)}function Ht(){let e=ke();return Object.entries(e).map(([t,n])=>({profileUrl:t,name:n.name,source:"discovered"}))}function je(){let e=ce();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 Oe(e=14){let t=ue(),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 G from"path";import{fileURLToPath as mo}from"url";import"dotenv/config";import{createGraphClient as lo,resolveToken as ao}from"@ilivemylife/graph-sdk";import{config as co}from"dotenv";co();var Jt=ao()||process.env.TOKEN;Jt||(console.error(`
|
|
239
|
+
Closing browser...`);try{await e.close()}catch{}process.exit(0)};process.on("SIGINT",o),process.on("SIGTERM",o);let r=await e.newPage();return await r.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await St(r,{profileDir:t,needsSeed:n}),console.log(" Browser launched (persistent profile)."),{browser:e,page:r}}me();import"dotenv/config";import*as $ from"fs";import*as A from"path";import{fileURLToPath as _n}from"url";var In=_n(import.meta.url),Dn=A.dirname(A.dirname(In)),V=process.env.DATA_DIR?A.resolve(process.env.DATA_DIR,"collected-profiles"):A.join(Dn,"collected-profiles"),_e=A.join(V,"people.json"),Rr=A.join(V,"jobs.json"),Or=A.join(V,"quota.json"),jr=A.join(V,"conversations.json"),Nr=A.join(V,"sync-state.json"),Lr=A.join(V,"application-questions.json"),Ie=A.join(V,"profile-history"),Et=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},Fr=Et(process.env.CONNECT_MAX_DAILY,20),Mr=Et(process.env.CONNECT_MAX_WEEKLY,100),ae=null,Tn=null,Rn=null,On=null,jn=null,Nn=null;function At(){ae=null,Tn=null,Rn=null,On=null,jn=null,Nn=null}function _t(){$.existsSync(V)||$.mkdirSync(V,{recursive:!0})}function It(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";$.writeFileSync(o,n);for(let r=0;r<3;r++)try{$.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 Dt(e,t){if(!$.existsSync(e))return null;try{let n=JSON.parse($.readFileSync(e,"utf-8"));try{$.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($.existsSync(o))try{let r=JSON.parse($.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{$.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{$.copyFileSync(e,e+".corrupted")}catch{}return null}}function Ln(){return new Date().toISOString().split("T")[0]}var Fn=["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"],Mn=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function X(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function Ct(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function Tt(e,t,n=null){if(!t||e[t])return t;let o=X(t);if(!o)return t;let r=null;for(let[s,i]of Object.entries(e)){if(X(i.profileUrl||s)===o)return s;!r&&Array.isArray(i.aliases)&&i.aliases.includes(o)&&(r=s)}if(r){let s=Ct(n),i=Ct(e[r].name);if(s&&i&&s===i)return r}return t}function Pn(){$.existsSync(Ie)||$.mkdirSync(Ie,{recursive:!0})}function Rt(e){let t=X(e);return t?A.join(Ie,`${t}.json`):null}function qn(e){let t=Rt(e);return t?Dt(t,`profile-history/${X(e)}.json`)||[]:[]}function Un(e,t){let n=Rt(e);if(!n)return;Pn();let o=qn(e);o.unshift(t);try{It(n,o)}catch(r){console.error(`[!] Failed to append profile-history for ${X(e)}: ${r.message}`)}}function xt(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function $t(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function Bn(e,t){if(!e)return[];let n=[];for(let o of Mn){let r=e[o],s=t[o];xt(r)||xt(s)||$t(r)!==$t(s)&&n.push(o)}return n}function Vn(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 ce(){return ae||(_t(),ae=Dt(_e,"people.json")||{},ae)}function Ot(e){_t(),ae=e;try{It(_e,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${A.resolve(_e)}`)}}function De(e,t={}){if(!e)return null;let n=ce(),o=Ln(),r=new Date().toISOString(),s=Tt(n,e,t.name),i=n[s];if(i){let u=Bn(i,t);u.length>0&&(Un(s,{capturedAt:r,previousLastUpdated:i.lastUpdated||null,changedFields:u,snapshot:Vn(i)}),i.lastSnapshotAt=r),i.seenCount=(i.seenCount||1)+1,i.lastSeen=o,i.lastUpdated=r,t.source&&!i.sources?.includes(t.source)&&(i.sources=i.sources||[],i.sources.push(t.source));for(let l of Fn)if(t[l]!=null){if(Array.isArray(t[l])&&t[l].length===0&&Array.isArray(i[l])&&i[l].length>0)continue;i[l]=t[l]}Array.isArray(t.availableSections)&&(i.lastFullVisitAt=r)}else n[s]={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,requestedConnectionAt:null,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:r,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?r:null};return Ot(n),n[s]}function Te(e,t,n={}){if(n.dryRun||!e||!t)return;let o=X(t);if(!o)return;let r=ce(),s=Tt(r,e),i=r[s];if(!i)return;let u=X(i.profileUrl||s);o!==u&&(Array.isArray(i.aliases)||(i.aliases=[]),i.aliases.includes(o)||(i.aliases.push(o),i.lastUpdated=new Date().toISOString(),Ot(r)))}async function zn(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: ilml linkedin login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await x(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function Lt(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:s=!1,extractSkills:i=!1,extractRecommendations:u=!1,extractCertifications:l=!1}=n;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await x(3e3),await ct(e)&&(console.log(" Dismissed Premium overlay"),await x(1500),await zn(e,t));let a=0;for(let E=0;E<2;E++){let z=await e.evaluate(()=>document.body.scrollHeight);for(let J=1;J<=6;J++)await e.evaluate(R=>window.scrollTo(0,R),z*J/6),await x(900);let Q=await e.evaluate(()=>document.body.scrollHeight);if(Q===a)break;a=Q}await x(800);let w=null;try{let E=e.url();E&&/\/in\/[^/?#]/.test(E)&&(w=E.split("?")[0].replace(/\/+$/,""))}catch{}let c=await e.evaluate(()=>{let E=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"]),z=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 y=(p||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(y)},J={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:[]},R=document.querySelector("main");if(!R)return J;let v=[...Array.from(R.querySelectorAll("h1")),...Array.from(R.querySelectorAll("h2"))],I=Array.from(R.querySelectorAll("h2")),ie=v.find(p=>{let y=p.textContent&&p.textContent.trim(),b=(y||"").replace(/\s*\(\d+\)$/,"").trim();return y&&y.length>1&&y.length<100&&!E.has(b)&&!z.has(b)}),le=ie?ie.textContent.trim():null,D=ie?ie.parentElement:null;for(;D&&D!==R&&!Array.from(D.children).filter(y=>y.tagName==="P").some(y=>{let b=y.textContent&&y.textContent.trim();return b&&b.length>5&&!Q(b)});)D=D.parentElement;let Ge=null,Ke=null,ze=null,Ee=null;if(D&&D!==R){let p=Array.from(D.children).filter(b=>b.tagName==="P").filter(b=>{let W=b.textContent&&b.textContent.trim();return W&&W.length>5&&!Q(W)});if(p[0]&&(Ge=p[0].textContent.trim()),p[1]){let b=p[1].textContent.trim().split(/\s*[·•]\s*/);Ke=b[0]||null,b.length>1&&(ze=b.slice(1).join(" \xB7 "))}let y=Array.from(D.children).filter(b=>b.tagName==="DIV");for(let b=y.length-1;b>=0;b--){let W=y[b].textContent&&y[b].textContent.trim();if(W&&!(le&&W.startsWith(le))&&(Ee=W.split(/[·•]/)[0].trim(),Ee))break}}let Qe=null;if(D){let p=D.querySelectorAll("p, span, div");for(let y of p){let b=(y.textContent||"").trim().replace(/^[·•]\s*/,"");if(b==="1st"||b==="2nd"||b==="3rd"){Qe=b;break}}}let cn=!!R.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),Ze=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),un=Ze&&Ze.src||null,Se=R.textContent||"",Xe=null,et=Se.match(/(\d+\+?)\s+connections\b/i);et&&(Xe=et[1]+" connections");let ve=null,tt=Se.match(/(\d+)\s+mutual connection/i),nt=Se.match(/and\s+(\d+)\s+other mutual/i),dn=Se.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);tt?ve=parseInt(tt[1],10):nt?ve=2+parseInt(nt[1],10):dn&&(ve=2);let ot=null,rt=null,st=I.find(p=>p.textContent&&p.textContent.trim()==="About");if(st){let p=st.parentElement;for(;p&&p.tagName!=="SECTION";)p=p.parentElement;if(p){let y=(p.textContent||"").trim();y=y.replace(/^About\s*/,"").trim();let b=y.match(/Top skills\s*(.+?)$/i);if(b){let Ae=b[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(hn=>hn.trim()).filter(Boolean);Ae.length>0&&Ae.length<10&&(rt=Ae)}y=y.split(/\n?…\s*more/i)[0].trim(),y=y.split(/\n?\.\.\.\s*more/i)[0].trim(),y=y.split(/\bTop skills\b/i)[0].trim(),y=y.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),ot=y||null}}let it=null,lt=I.find(p=>p.textContent&&p.textContent.trim()==="Activity");if(lt){let p=lt.parentElement;for(;p&&p.tagName!=="SECTION";)p=p.parentElement;if(p){let y=(p.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);y&&(it=parseInt(y[1].replace(/,/g,""),10))}}let fn=[...new Set(I.map(p=>(p.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(p=>p&&p.length>1&&p.length<60&&p!==le).filter(p=>E.has(p)))],de=document.body.textContent||"",mn=/#OpenToWork\b/i.test(de)||/\bOpen to work\b/.test(de),pn=/#Hiring\b/i.test(de)||/\bI'?m hiring\b/i.test(de)||/\bWe are hiring\b/i.test(de);return{name:le,title:Ge,location:Ee,currentCompany:Ke,currentSchool:ze,connectionDegree:Qe,hasVerifiedBadge:cn,photoUrl:un,connectionsLevel:Xe,mutualConnectionsCount:ve,followers:it,openToWork:mn,hiring:pn,about:ot,topSkills:rt,availableSections:fn}});console.log(`Viewed: ${c.name} - ${c.title}`);let f=null,C=null,S=null,_=null,g=null,h=null;if(o||r||s||i||u||l){let E=await Promise.resolve().then(()=>(Nt(),jt));o&&(f=await E.extractExperienceFromDetails(e,t),console.log(` + Experience: ${f.length} entries`)),r&&(C=await E.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${C.length} entries`)),s&&(S=await E.extractEducationFromDetails(e,t),console.log(` + Education: ${S.length} entries`)),i&&(_=await E.extractSkillsFromDetails(e,t),console.log(` + Skills: ${_.length} entries`)),u&&(g=await E.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${g.length} entries`)),l&&(h=await E.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${h.length} entries`))}return{...c,profileUrl:t,resolvedUrl:w,...f!==null&&{experience:f},...C!==null&&{featured:C},...S!==null&&{education:S},..._!==null&&{skillsFull:_},...g!==null&&{recommendations:g},...h!==null&&{certifications:h}}}catch(m){console.error(`Error viewing profile ${t}:`,m.message);try{await e.goto("about:blank",{timeout:1e4}),await x(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 j from"fs";import*as O from"path";import{fileURLToPath as Qn}from"url";var Zn=Qn(import.meta.url),Xn=O.dirname(O.dirname(Zn)),te=process.env.DATA_DIR?O.resolve(process.env.DATA_DIR,"market-research"):O.join(Xn,"market-research"),eo=O.join(te,"scouted-jobs.json"),to=O.join(te,"discovered-people.json"),Ft=O.join(te,"visit-log.json"),Zr=O.join(te,"companies.json"),Xr=O.join(te,"job-decisions.json");function no(){j.existsSync(te)||j.mkdirSync(te,{recursive:!0})}function oo(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";j.writeFileSync(o,n);for(let r=0;r<3;r++)try{j.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 Re(e){try{if(j.existsSync(e))return JSON.parse(j.readFileSync(e,"utf-8"))}catch{}return null}function Mt(){ye=null,so=null,we=null,io=null,ee=null}var ye=null;function ro(){return ye||(ye=Re(eo)||{},ye)}var so=null;var we=null;function ke(){return we||(we=Re(to)||{},we)}var io=null;var ee=null;function ue(){return ee||(ee=Re(Ft)||{visits:[]},Array.isArray(ee.visits)||(ee.visits=[]),ee)}function Pt(e,t={}){if(!e)return;no();let n=ue();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{oo(Ft,n)}catch(r){console.error(`[!] Failed to save visit-log.json: ${r.message}`)}}function qt(e){let t=ue();for(let n=t.visits.length-1;n>=0;n--)if(t.visits[n].profileUrl===e)return t.visits[n].date;return null}function Ut(){let e=ro(),t=ke(),n=Object.values(e),o=Object.values(t),r={};for(let c of n)c.company&&(r[c.company]=(r[c.company]||0)+1);let s=Object.entries(r).sort((c,f)=>f[1]-c[1]).slice(0,5).map(([c,f])=>`${c} (${f})`),i={};for(let c of n)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=ue(),m=new Date().toISOString().slice(0,10),a=l.visits.filter(c=>c.date.startsWith(m)).length,w=new Set(l.visits.map(c=>c.profileUrl)).size;return{totalJobs:n.length,totalRecruiters:o.length,topCompanies:s,topTech:u,totalVisited:w,todayVisited:a,lastScoutDate:n.length>0?n.sort((c,f)=>(f.scoutedAt||"").localeCompare(c.scoutedAt||""))[0]?.scoutedAt:null}}me();async function Bt(e,t,n={}){let{maxVisits:o=50,delayBetween:r=4e3,skipRecentDays:s=7,verbose:i=!1,extractExperience:u=!1}=n,l={visited:0,skipped:0,errors:0},m=Date.now()-s*24*60*60*1e3;for(let a of t){if(l.visited>=o)break;if(!a.profileUrl)continue;let w=qt(a.profileUrl);if(w&&new Date(w).getTime()>m){l.skipped++;continue}try{let c=await Lt(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()),De(a.profileUrl,S),c.resolvedUrl&&Te(a.profileUrl,c.resolvedUrl)}Pt(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 x(r+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 Vt(e={}){let{limit:t=150,revisitDays:n=14}=e,o=ue(),r=new Set(o.visits?.map(g=>g.profileUrl)||[]),s=new Map;for(let g of o.visits||[]){let h=s.get(g.profileUrl);(!h||g.date>h)&&s.set(g.profileUrl,g.date)}let i=Date.now()-7*24*60*60*1e3,u=Date.now()-n*24*60*60*1e3;function l(g){let h=s.get(g);return h&&new Date(h).getTime()>i}let m=ke(),a=Object.entries(m).filter(([g])=>!r.has(g)).map(([g,h])=>({profileUrl:g,name:h.name,source:"new-discovered",priority:1,jobCount:h.jobIds?.length||0})),w=ce(),c=Object.entries(w).filter(([g,h])=>h.connectionStatus==="connected"||l(g)?!1:(h.jobCount||h.jobIds?.length||0)>=2).map(([g,h])=>({profileUrl:g,name:h.name,source:"active-recruiter",priority:2,jobCount:h.jobCount||h.jobIds?.length||0})),f=Object.entries(w).filter(([g,h])=>{let B=h.connectionStatus;return!(!B||B==="connected"||B==="pending"||B==="sent_without_note"||B==="sent_with_note"||l(g)||(h.jobCount||h.jobIds?.length||0)>=2)}).map(([g,h])=>({profileUrl:g,name:h.name,source:"unconnected",priority:3,jobCount:h.jobCount||h.jobIds?.length||0})),C=[...s.entries()].filter(([g,h])=>new Date(h).getTime()<u).map(([g,h])=>({profileUrl:g,name:null,source:"revisit",priority:4,lastVisit:h})),S=g=>g.sort(()=>Math.random()-.5);return a.sort((g,h)=>h.jobCount-g.jobCount),c.sort((g,h)=>h.jobCount-g.jobCount),S(f),S(C),[...a,...c,...f,...C].slice(0,t)}function Ht(){let e=ke();return Object.entries(e).map(([t,n])=>({profileUrl:t,name:n.name,source:"discovered"}))}function Oe(){let e=ce();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 je(e=14){let t=ue(),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 G from"path";import{fileURLToPath as mo}from"url";import"dotenv/config";import{createGraphClient as lo,resolveToken as ao}from"@ilivemylife/graph-sdk";import{config as co}from"dotenv";co();var Jt=ao()||process.env.TOKEN;Jt||(console.error(`
|
|
240
240
|
[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.
|
|
241
241
|
`),console.error(" Easiest way:"),console.error(" 1. npm install -g @ilivemylife/graph-sdk"),console.error(` 2. ilml login your@email.com yourpassword
|
|
242
242
|
`),console.error(` Or add ILML_TOKEN=... to .env
|
|
243
243
|
`),process.exit(1));var Wt=lo({token:Jt});function uo(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 fo({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"," "),u=r?` ${uo(r)}`:"",l=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 ${l} \u2014 ${i}${u}`}async function Yt({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 l=`**${fo({scriptName:e,mode:t,status:n,error:r,duration:s})}**
|
|
244
244
|
|
|
245
245
|
${o.join(`
|
|
246
|
-
`)}`;try{await Wt.addMessage(i,l)}catch(m){console.error(`[runReport] Failed to post end-of-session message: ${m.message}`)}}var po=mo(import.meta.url),ho=G.dirname(G.dirname(po)),Ne=process.env.DATA_DIR?G.resolve(process.env.DATA_DIR,"collected-profiles"):G.join(ho,"collected-profiles"),Le=G.join(Ne,"run-log.json");function go(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 Gt(){try{if(!N.existsSync(Le))return{runs:[]};let e=JSON.parse(N.readFileSync(Le,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Kt(e){N.existsSync(Ne)||N.mkdirSync(Ne,{recursive:!0});try{go(Le,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function zt(e,t="default"){let n=Gt();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),Kt(n),{script:e,mode:t,startTime:o.getTime(),runIndex:n.runs.length-1}}function Fe(e,t,n=null,o=null){if(!e)return;let r=null;try{let i=Gt(),u=i.runs[e.runIndex];if(u&&u.status==="running"&&u.script===e.script)u.status=t,u.result=t,u.duration=Date.now()-e.startTime,u.stats=n,u.error=o,r=u.duration;else{let l=i.runs.find(m=>m.script===e.script&&m.status==="running"&&m.timestamp===new Date(e.startTime).toISOString());l&&(l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=n,l.error=o,r=l.duration)}Kt(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";Yt({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(u=>console.error(`[runLog] postRunReport failed: ${u.message}`))}}import"dotenv/config";import*as d from"fs";import*as Je from"os";import*as k from"path";import{fileURLToPath as qo}from"url";var qe={};fe(qe,{NAME:()=>wo,VERSION:()=>yo,up:()=>vo});import*as L from"fs";import*as Ce from"path";var yo=1,wo="normalize-jobs-and-questions",bo=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],So=50;function Me(e){return L.existsSync(e)?JSON.parse(L.readFileSync(e,"utf-8")):null}function Pe(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 vo(e,t){let n=Ce.join(e,"jobs.json"),o=Ce.join(t,"scouted-jobs.json"),r=Ce.join(e,"application-questions.json"),s=Me(n)||{},i=Me(o)||{},u=0,l=[];for(let a of Object.keys(s)){if(!i[a])continue;let w=i[a],c=s[a];for(let f of bo)w[f]!=null&&c[f]==null&&(c[f]=w[f]);l.push(a),u++}u>0?(Pe(n,s),console.log(` Phase 1: Merged ${u} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let m=Me(r);if(m&&Array.isArray(m.applications)){let a={},w=0;for(let c of m.applications){let f=c.jobId||"unknown";a[f]||(a[f]={applications:[]});let C=(c.questions||[]).map(S=>{let _={type:S.type||"input",question:S.question||"",answer:S.answer||""};return S.options&&(S.options.length<=So?_.options=S.options:(_.optionsOmitted=!0,w++)),S.page&&(_.page=S.page),S.wasPreFilled&&(_.wasPreFilled=!0),S.wasRetry&&(_.wasRetry=!0),_});a[f].applications.push({applicationId:c.applicationId,date:c.date,result:c.result||"submitted",formPages:c.formPages||null,duration:c.duration||null,retries:c.retries||0,failedField:c.failedField||null,questionCount:c.questionCount||C.length,questions:C})}Pe(r,a),console.log(` Phase 2: Rekeyed ${m.applications.length} applications by jobId (${Object.keys(a).length} unique jobs)`),w>0&&console.log(` Phase 2: Stripped bloated options from ${w} 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(l.length>0){for(let a of l)delete i[a];Pe(o,i),console.log(` Phase 3: Removed ${l.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 Ue={};fe(Ue,{NAME:()=>Co,VERSION:()=>ko,up:()=>Eo});import*as F from"fs";import*as Qt from"path";var ko=2,Co="reset-unread-flags";function xo(e){return F.existsSync(e)?JSON.parse(F.readFileSync(e,"utf-8")):null}function $o(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 Eo(e){let t=Qt.join(e,"conversations.json"),n=xo(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}$o(t,n),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var Be={};fe(Be,{NAME:()=>_o,VERSION:()=>Ao,up:()=>jo});import*as M from"fs";import*as Zt from"path";var Ao=3,_o="recompute-last-message-by",Io=new Set(["draft","confirmed","rejected","needs_review"]);function Do(e){return M.existsSync(e)?JSON.parse(M.readFileSync(e,"utf-8")):null}function Ro(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 To(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!Io.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 jo(e){let t=Zt.join(e,"conversations.json"),n=Do(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 u of Object.keys(n)){let l=n[u];if(!l||typeof l!="object")continue;Object.prototype.hasOwnProperty.call(l,"_cardSynced")&&(delete l._cardSynced,s++);let m=Array.isArray(l.messages)?l.messages:[],a=To(m,o),w=a==="me"?"awaiting_reply":"unanswered_by_us";l.lastMessageBy!==a&&i++,l.lastMessageBy=a,l.conversationStatus=w,r++}if(r===0){console.log(" No conversations to recompute.");return}Ro(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 Ve={};fe(Ve,{NAME:()=>No,VERSION:()=>Oo,up:()=>Po});import*as P from"fs";import*as Xt from"path";var Oo=4,No="split-connection-timestamps",Lo=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function Fo(e){if(!P.existsSync(e))return null;let t=P.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function Mo(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{P.writeFileSync(o,n)}catch(r){try{P.unlinkSync(o)}catch{}throw r}try{P.renameSync(o,e)}catch(r){try{P.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 Po(e){let t=Xt.join(e,"people.json"),n=Fo(t);if(!n||typeof n!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let o=0,r=0;for(let s of Object.keys(n)){let i=n[s];!i||typeof i!="object"||(r++,Lo.has(i.connectionStatus)&&i.connectionDate&&!i.requestedConnectionAt&&(i.requestedConnectionAt=i.connectionDate,i.connectionDate=null,o++))}if(o===0){console.log(` Scanned ${r} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}Mo(t,n),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${o} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}var Uo=qo(import.meta.url),Bo=k.dirname(Uo),Vo=k.dirname(k.dirname(Bo));function Ho(e){return e&&(e==="~"?Je.homedir():e.startsWith("~/")||e.startsWith("~\\")?k.join(Je.homedir(),e.slice(2)):e)}var U=process.env.DATA_DIR?k.resolve(Ho(process.env.DATA_DIR)):Vo,oe=k.join(U,"collected-profiles"),re=k.join(U,"market-research"),R=k.join(U,".schema-version"),en=[k.join(oe,".schema-version"),k.join(re,".schema-version")],K=4,H=[{version:1,module:qe},{version:2,module:Ue},{version:3,module:Be},{version:4,module:Ve}];(function(){H.sort((o,r)=>o.version-r.version);let t=new Set;for(let o of H){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=H.length?H[H.length-1].version:0;if(n!==K)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${K}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<H.length;o++){let r=o+1;if(H[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${H[o].version}`)}})();function rn(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
246
|
+
`)}`;try{await Wt.addMessage(i,l)}catch(m){console.error(`[runReport] Failed to post end-of-session message: ${m.message}`)}}var po=mo(import.meta.url),ho=G.dirname(G.dirname(po)),Ne=process.env.DATA_DIR?G.resolve(process.env.DATA_DIR,"collected-profiles"):G.join(ho,"collected-profiles"),Le=G.join(Ne,"run-log.json");function go(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 Gt(){try{if(!N.existsSync(Le))return{runs:[]};let e=JSON.parse(N.readFileSync(Le,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Kt(e){N.existsSync(Ne)||N.mkdirSync(Ne,{recursive:!0});try{go(Le,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function zt(e,t="default"){let n=Gt();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),Kt(n),{script:e,mode:t,startTime:o.getTime(),runIndex:n.runs.length-1}}function Fe(e,t,n=null,o=null){if(!e)return;let r=null;try{let i=Gt(),u=i.runs[e.runIndex];if(u&&u.status==="running"&&u.script===e.script)u.status=t,u.result=t,u.duration=Date.now()-e.startTime,u.stats=n,u.error=o,r=u.duration;else{let l=i.runs.find(m=>m.script===e.script&&m.status==="running"&&m.timestamp===new Date(e.startTime).toISOString());l&&(l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=n,l.error=o,r=l.duration)}Kt(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";Yt({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(u=>console.error(`[runLog] postRunReport failed: ${u.message}`))}}import"dotenv/config";import*as d from"fs";import*as Je from"os";import*as k from"path";import{fileURLToPath as qo}from"url";var qe={};fe(qe,{NAME:()=>wo,VERSION:()=>yo,up:()=>vo});import*as L from"fs";import*as Ce from"path";var yo=1,wo="normalize-jobs-and-questions",bo=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],So=50;function Me(e){return L.existsSync(e)?JSON.parse(L.readFileSync(e,"utf-8")):null}function Pe(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 vo(e,t){let n=Ce.join(e,"jobs.json"),o=Ce.join(t,"scouted-jobs.json"),r=Ce.join(e,"application-questions.json"),s=Me(n)||{},i=Me(o)||{},u=0,l=[];for(let a of Object.keys(s)){if(!i[a])continue;let w=i[a],c=s[a];for(let f of bo)w[f]!=null&&c[f]==null&&(c[f]=w[f]);l.push(a),u++}u>0?(Pe(n,s),console.log(` Phase 1: Merged ${u} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let m=Me(r);if(m&&Array.isArray(m.applications)){let a={},w=0;for(let c of m.applications){let f=c.jobId||"unknown";a[f]||(a[f]={applications:[]});let C=(c.questions||[]).map(S=>{let _={type:S.type||"input",question:S.question||"",answer:S.answer||""};return S.options&&(S.options.length<=So?_.options=S.options:(_.optionsOmitted=!0,w++)),S.page&&(_.page=S.page),S.wasPreFilled&&(_.wasPreFilled=!0),S.wasRetry&&(_.wasRetry=!0),_});a[f].applications.push({applicationId:c.applicationId,date:c.date,result:c.result||"submitted",formPages:c.formPages||null,duration:c.duration||null,retries:c.retries||0,failedField:c.failedField||null,questionCount:c.questionCount||C.length,questions:C})}Pe(r,a),console.log(` Phase 2: Rekeyed ${m.applications.length} applications by jobId (${Object.keys(a).length} unique jobs)`),w>0&&console.log(` Phase 2: Stripped bloated options from ${w} 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(l.length>0){for(let a of l)delete i[a];Pe(o,i),console.log(` Phase 3: Removed ${l.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 Ue={};fe(Ue,{NAME:()=>Co,VERSION:()=>ko,up:()=>Eo});import*as F from"fs";import*as Qt from"path";var ko=2,Co="reset-unread-flags";function xo(e){return F.existsSync(e)?JSON.parse(F.readFileSync(e,"utf-8")):null}function $o(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 Eo(e){let t=Qt.join(e,"conversations.json"),n=xo(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}$o(t,n),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var Be={};fe(Be,{NAME:()=>_o,VERSION:()=>Ao,up:()=>Oo});import*as M from"fs";import*as Zt from"path";var Ao=3,_o="recompute-last-message-by",Io=new Set(["draft","confirmed","rejected","needs_review"]);function Do(e){return M.existsSync(e)?JSON.parse(M.readFileSync(e,"utf-8")):null}function To(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 Ro(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!Io.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 Oo(e){let t=Zt.join(e,"conversations.json"),n=Do(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 u of Object.keys(n)){let l=n[u];if(!l||typeof l!="object")continue;Object.prototype.hasOwnProperty.call(l,"_cardSynced")&&(delete l._cardSynced,s++);let m=Array.isArray(l.messages)?l.messages:[],a=Ro(m,o),w=a==="me"?"awaiting_reply":"unanswered_by_us";l.lastMessageBy!==a&&i++,l.lastMessageBy=a,l.conversationStatus=w,r++}if(r===0){console.log(" No conversations to recompute.");return}To(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 Ve={};fe(Ve,{NAME:()=>No,VERSION:()=>jo,up:()=>Po});import*as P from"fs";import*as Xt from"path";var jo=4,No="split-connection-timestamps",Lo=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function Fo(e){if(!P.existsSync(e))return null;let t=P.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function Mo(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{P.writeFileSync(o,n)}catch(r){try{P.unlinkSync(o)}catch{}throw r}try{P.renameSync(o,e)}catch(r){try{P.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 Po(e){let t=Xt.join(e,"people.json"),n=Fo(t);if(!n||typeof n!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let o=0,r=0;for(let s of Object.keys(n)){let i=n[s];!i||typeof i!="object"||(r++,Lo.has(i.connectionStatus)&&i.connectionDate&&!i.requestedConnectionAt&&(i.requestedConnectionAt=i.connectionDate,i.connectionDate=null,o++))}if(o===0){console.log(` Scanned ${r} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}Mo(t,n),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${o} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}var Uo=qo(import.meta.url),Bo=k.dirname(Uo),Vo=k.dirname(k.dirname(Bo));function Ho(e){return e&&(e==="~"?Je.homedir():e.startsWith("~/")||e.startsWith("~\\")?k.join(Je.homedir(),e.slice(2)):e)}var U=process.env.DATA_DIR?k.resolve(Ho(process.env.DATA_DIR)):Vo,oe=k.join(U,"collected-profiles"),re=k.join(U,"market-research"),T=k.join(U,".schema-version"),en=[k.join(oe,".schema-version"),k.join(re,".schema-version")],K=4,H=[{version:1,module:qe},{version:2,module:Ue},{version:3,module:Be},{version:4,module:Ve}];(function(){H.sort((o,r)=>o.version-r.version);let t=new Set;for(let o of H){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=H.length?H[H.length-1].version:0;if(n!==K)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${K}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<H.length;o++){let r=o+1;if(H[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${H[o].version}`)}})();function rn(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
247
247
|
[FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
|
|
248
248
|
`),process.exit(1));try{d.mkdirSync(U,{recursive:!0})}catch(t){t.code!=="EEXIST"&&(console.error(`
|
|
249
249
|
[FATAL] Cannot create DATA_DIR (${U}): ${t.message}`),console.error(` Fix the path or permissions and try again.
|
|
@@ -256,16 +256,16 @@ ${o.join(`
|
|
|
256
256
|
`),process.exit(1))}}var ne=k.join(U,".migration-lock");function Jo(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return d.writeFileSync(ne,e,{flag:"wx"}),!0}catch(o){if(o.code!=="EEXIST")throw o}let t;try{t=JSON.parse(d.readFileSync(ne,"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(`
|
|
257
257
|
[FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${t.pid}`),console.error(` Started at: ${t.startedAt||"(unknown)"}`),console.error(` Lock file: ${ne}
|
|
258
258
|
`),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.
|
|
259
|
-
`),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=ne+".tmp";try{return d.writeFileSync(n,e),d.renameSync(n,ne),!0}catch(o){try{d.unlinkSync(n)}catch{}throw new Error(`Failed to take over stale migration lock: ${o.message}`)}}function We(){try{if(JSON.parse(d.readFileSync(ne,"utf-8")).pid!==process.pid)return;d.unlinkSync(ne)}catch{}}var tn=!1;function Wo(){if(tn)return;tn=!0;let e=()=>{try{We()}catch{}process.exit(1)};for(let t of["SIGINT","SIGTERM","SIGHUP"])try{process.on(t,e)}catch{}}function Yo(){if(d.existsSync(
|
|
259
|
+
`),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=ne+".tmp";try{return d.writeFileSync(n,e),d.renameSync(n,ne),!0}catch(o){try{d.unlinkSync(n)}catch{}throw new Error(`Failed to take over stale migration lock: ${o.message}`)}}function We(){try{if(JSON.parse(d.readFileSync(ne,"utf-8")).pid!==process.pid)return;d.unlinkSync(ne)}catch{}}var tn=!1;function Wo(){if(tn)return;tn=!0;let e=()=>{try{We()}catch{}process.exit(1)};for(let t of["SIGINT","SIGTERM","SIGHUP"])try{process.on(t,e)}catch{}}function Yo(){if(d.existsSync(T))return;let e=[],t=[];for(let s of en)if(d.existsSync(s))try{e.push({file:s,schema:xe(s)})}catch(i){t.push({file:s,err:i.message})}if(t.length>0){console.error(`
|
|
260
260
|
[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(`
|
|
261
261
|
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.
|
|
262
262
|
`),process.exit(1)}if(e.length===0)return;let n=e.map(s=>s.schema.version);if(new Set(n).size>1){console.error(`
|
|
263
263
|
[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.
|
|
264
|
-
`),process.exit(1)}let o=e[0].schema,r=
|
|
265
|
-
[FATAL] ${
|
|
264
|
+
`),process.exit(1)}let o=e[0].schema,r=T+".tmp";try{d.writeFileSync(r,JSON.stringify(o,null,2)),d.renameSync(r,T)}catch(s){try{d.unlinkSync(r)}catch{}throw s}for(let s of en)if(d.existsSync(s))try{d.unlinkSync(s)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${T}`)}function Go(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 xe(e){let t=d.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function nn(){if(Yo(),!d.existsSync(T))return{version:0,migrations:[]};let e;try{e=xe(T)}catch(n){if(n.code==="ENOENT")return{version:0,migrations:[]};console.error(`
|
|
265
|
+
[FATAL] ${T} 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.
|
|
266
266
|
`),process.exit(1)}let t=Go(e);return t===null&&(console.error(`
|
|
267
|
-
[FATAL] ${
|
|
268
|
-
`),process.exit(1)),t}function sn(e){try{d.chmodSync(e,384)}catch{}}function Ko(e){if(rn(),d.existsSync(
|
|
267
|
+
[FATAL] ${T} 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.
|
|
268
|
+
`),process.exit(1)),t}function sn(e){try{d.chmodSync(e,384)}catch{}}function Ko(e){if(rn(),d.existsSync(T))try{if(d.lstatSync(T).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${T}. 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=T+".tmp";try{d.writeFileSync(t,JSON.stringify(e,null,2)),sn(t),d.renameSync(t,T)}catch(n){try{d.unlinkSync(t)}catch{}throw n}}function on(e,t){if(!d.existsSync(e))return;let n=`.pre-v${String(t).padStart(3,"0")}.backup`,o=d.readdirSync(e).filter(u=>{let l=u.toLowerCase();if(l.includes(".backup")||l===".schema-version"||l.endsWith(".tmp"))return!1;try{return d.statSync(k.join(e,u)).isFile()}catch{return!1}}),r=0,s=0,i=[];for(let u of o){let l=k.join(e,u),m=k.join(e,u+n);if(d.existsSync(m)){s++;continue}try{an(l,m),r++}catch(a){i.push({file:u,err:a.message})}}if(i.length>0){let u=new Error(`Failed to back up ${i.length} file(s) in ${k.basename(e)}/: `+i.map(l=>`${l.file} (${l.err})`).join(", "));throw u.code="BACKUP_INCOMPLETE",u}if(r>0||s>0){let u=s>0?` (${s} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${r} files in ${k.basename(e)}/ (${n})${u}`)}}var He=!1;async function ln(){if(He)return;rn(),er();let t=nn().version;if(t===K){He=!0;return}Wo(),Jo(),process.on("exit",We),t>K&&(console.error(`
|
|
269
269
|
[FATAL] Your data schema is at v${t}, but this plugin build only understands up to v${K}.`),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.
|
|
270
270
|
`),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${K}.
|
|
271
271
|
`),process.exit(1)),console.log(`
|
|
@@ -284,10 +284,10 @@ ${o.join(`
|
|
|
284
284
|
`),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{At()}catch{}try{Mt()}catch{}He=!0,We(),console.log(`
|
|
285
285
|
\u2713 Schema is now at v${K}
|
|
286
286
|
`)}var zo=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Qo(e){let t=e.toLowerCase();return zo.some(n=>n.test(t))}var Zo=6e4;function Xo(){let e=Date.now(),t=[];for(let n of[U,oe,re]){if(!d.existsSync(n))continue;let o;try{o=d.readdirSync(n)}catch{continue}for(let r of o){if(!Qo(r))continue;let s=k.join(n,r);try{let i=d.statSync(s);if(!i.isFile()||e-i.mtimeMs<Zo)continue;t.push({dir:n,file:r,fullPath:s})}catch{}}}return t}function er({verbose:e=!1}={}){let t=Xo();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 tr(){let e=[];for(let t of[oe,re]){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{xe(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 nr(e){let t=[],n=[];for(let s of[oe,re]){if(!d.existsSync(s))continue;let i=d.readdirSync(s).filter(u=>u.endsWith(e));for(let u of i){let l=k.join(s,u),m=u.slice(0,-e.length),a=k.join(s,m);try{m.toLowerCase().endsWith(".json")?xe(l):d.accessSync(l,d.constants.R_OK),t.push({backupPath:l,originalPath:a,fileName:u,dir:s})}catch(w){n.push(`${k.basename(s)}/${u}: ${w.message}`)}}}if(n.length>0)return{ok:!1,error:n.join("; "),restored:0};let o=0,r=[];for(let{backupPath:s,originalPath:i,fileName:u,dir:l}of t)try{an(s,i),o++}catch(m){r.push(`${k.basename(l)}/${u}: ${m.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:o}:{ok:!0,restored:o}}function an(e,t){let n=t+".tmp";try{d.copyFileSync(e,n),sn(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 ln();var be=process.argv.slice(2),$e=be.find(e=>e.startsWith("--source="))?.split("=")[1]||"scouted",Ye=parseInt(be.find(e=>e.startsWith("--max="))?.split("=")[1]||"50"),se=parseInt(be.find(e=>e.startsWith("--revisit="))?.split("=")[1]||"0"),or=be.includes("--list"),rr=be.includes("--verbose");function sr(){let e=Ut();console.log(`
|
|
287
|
-
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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=
|
|
287
|
+
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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=Oe();if(console.log(` Unconnected recruiters: ${t.length}`),se>0){let n=je(se);console.log(` Revisit (>${se}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
|
|
288
288
|
`)}async function ir(){if(console.log(`
|
|
289
289
|
LinkedIn Profile Visitor
|
|
290
|
-
`),or){sr();return}let e=[],t="";if(se>0?(e=
|
|
290
|
+
`),or){sr();return}let e=[],t="";if(se>0?(e=je(se),t=`revisit (>${se} days)`):$e==="people"?(e=Oe(),t="unconnected recruiters (people.json)"):$e==="scouted"||$e==="discovered"?(e=Ht(),t="discovered recruiters (market-research)"):(e=Vt({limit:Ye}),t="smart (new \u2192 active \u2192 unconnected \u2192 revisit)"),console.log(` Source: ${t}`),console.log(` Candidates: ${e.length}`),console.log(` Max visits: ${Ye}
|
|
291
291
|
`),e.length===0){console.log(` No profiles to visit. Run npm run scout first.
|
|
292
292
|
`);return}let n=zt("visit",$e),{browser:o,page:r}=await kt();try{let s=await Bt(r,e,{maxVisits:Ye,verbose:rr,skipRecentDays:se>0?0:7});console.log(`
|
|
293
293
|
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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
|
package/ilml-plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "linkedin",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.2",
|
|
4
4
|
"description": "Reference ilml plugin: keep a local mirror of your LinkedIn data with AI-assisted workflows",
|
|
5
5
|
"commands": {
|
|
6
6
|
"help": { "run": "node dist/help.mjs", "description": "List all commands with descriptions; or `help <cmd>` for detailed info on one command (usage, flags, ban-risk, when-to-use). Reads ilml-plugin.json directly.", "usage": "ilml linkedin help [<cmd>]", "useWhen": "You forgot what a command does, or you're an AI agent picking the right tool." },
|
package/package.json
CHANGED