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