ilml-plugin-linkedin 1.18.1 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/connect.mjs +75 -75
- package/dist/enrichProfile.mjs +8 -8
- package/dist/enrichProfiles.mjs +13 -13
- package/dist/funnelRunner.mjs +50 -50
- package/dist/run.mjs +57 -57
- package/dist/syncAll.mjs +98 -98
- package/dist/verifyAbout.mjs +4 -4
- package/dist/version.mjs +1 -1
- package/dist/visit.mjs +9 -9
- package/ilml-plugin.json +1 -1
- package/package.json +1 -1
package/dist/enrichProfile.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var wt=Object.defineProperty;var Me=(e,t)=>()=>(e&&(t=e(e=0)),t);var gt=(e,t)=>{for(var n in t)wt(e,n,{get:t[n],enumerable:!0})};async function g(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function
|
|
1
|
+
var wt=Object.defineProperty;var Me=(e,t)=>()=>(e&&(t=e(e=0)),t);var gt=(e,t)=>{for(var n in t)wt(e,n,{get:t[n],enumerable:!0})};async function g(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function Re(e){return await e.evaluate(()=>{let t=document.querySelectorAll("div.artdeco-modal--is-open");for(let o of t){let i=o.innerText||"",r=i.includes("Premium")||i.includes("premium")||i.includes("Upgrade")||i.includes("upgrade"),s=i.includes("Try for")||i.includes("free trial")||i.includes("/month")||i.includes("per month")||i.includes("Start my")||i.includes("Subscribe"),y=i.includes("Get hired faster")||i.includes("Get hired 2x");if(r||s||y){let m=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(m)return m.click(),{dismissed:!0,matched:i.substring(0,80)};let $=o.querySelectorAll("button");for(let c of $){let k=c.innerText?.trim().toLowerCase()||"",h=c.getAttribute("aria-label")?.toLowerCase()||"";if(k==="not now"||k==="no thanks"||k==="dismiss"||h.includes("dismiss"))return c.click(),{dismissed:!0,matched:i.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 ce=Me(()=>{});var Ve={};gt(Ve,{extractCertificationsFromDetails:()=>Nt,extractEducationFromDetails:()=>Rt,extractExperienceFromDetails:()=>Lt,extractFeaturedFromDetails:()=>Mt,extractRecommendationsFromDetails:()=>Tt,extractSkillsFromDetails:()=>Ft});async function Lt(e,t){let n=t.replace(/\/+$/,"")+"/details/experience/";try{await e.goto(n,{waitUntil:"domcontentloaded",timeout:6e4}),await g(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 r=0;r<5;r++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await g(900);await g(1e3);let i=0;for(;i<5&&await e.evaluate(()=>{for(let s of document.querySelectorAll("button"))if(/^Load more$/i.test((s.textContent||"").trim()))return s.click(),!0;return!1});)i++,await g(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await g(700);return await e.evaluate(()=>{let r=document.querySelector("main");if(!r)return[];function s(c){let k=[];for(let h of c.querySelectorAll("div")){let w=Array.from(h.children).filter(E=>E.tagName==="DIV");if(w.length<3)continue;let S=w.filter(E=>(E.textContent||"").trim().length>50);S.length<3||(h.textContent||"").length<500||k.push({el:h,count:S.length,totalText:(h.textContent||"").length})}return k.sort((h,w)=>w.count-h.count||h.totalText-w.totalText),k[0]?.el}let y=s(r);if(!y)return[];let m=Array.from(y.children).filter(c=>c.tagName==="DIV").filter(c=>(c.textContent||"").trim().length>50);function $(c){let k=c[0]||null,h=null,w=null;if(c[1]){let d=c[1].split("\xB7").map(C=>C.trim());h=d[0]||null,d[1]&&(w=d[1])}let S=c.findIndex(d=>/(\d{4}|present)/i.test(d)&&/(-|–|—)/i.test(d)&&d.length<80),E=null,F=null;if(S>=0){let d=c[S].split("\xB7").map(C=>C.trim());E=d[0]||null,d[1]&&(F=d[1])}let N=null,T=-1;if(S>=0&&c[S+1]){let d=c[S+1],C=/^[>*\-•]|^>/.test(d),U=/https?:\/\//.test(d),H=/\d{4}/.test(d),v=/,/.test(d)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(d);!C&&!U&&!H&&d.length<100&&v&&(N=d,T=S+1)}let re=null,p=-1,P=c[c.length-1];if(P&&/and\s+\+\d+\s+skills?$/i.test(P)){p=c.length-1;let d=P.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);d&&(re={listed:d[1].split(",").map(C=>C.trim()),additional:parseInt(d[2],10)})}let j=new Set([0,1,S,T,p].filter(d=>d>=0)),D=c.filter((d,C)=>!j.has(C)),x=D.length>0?D.join(`
|
|
2
2
|
|
|
3
|
-
`):null;return{title:k,company:h,employmentType:w,dates:E,duration:F,location:
|
|
4
|
-
`).map(w=>w.trim()).filter(w=>w&&w.length<5e3);return $(h)}).filter(c=>c.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 J(e,t,n){let o=t.replace(/\/+$/,"")+`/details/${n}/`;await e.goto(o,{waitUntil:"domcontentloaded",timeout:6e4}),await g(3e3);let i=e.url();if(/\/(login|authwall|checkpoint)/i.test(i))throw new Error(`Session expired \u2014 bounced to ${i} when fetching /details/${n}/`);if(!i.toLowerCase().includes(`/details/${n.toLowerCase()}/`))throw new Error(`Section /details/${n}/ not available on profile (landed on ${i})`);for(let
|
|
3
|
+
`):null;return{title:k,company:h,employmentType:w,dates:E,duration:F,location:N,description:x,skills:re,_raw:c}}return m.map(c=>{let h=(c.innerText||"").trim().split(`
|
|
4
|
+
`).map(w=>w.trim()).filter(w=>w&&w.length<5e3);return $(h)}).filter(c=>c.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 J(e,t,n){let o=t.replace(/\/+$/,"")+`/details/${n}/`;await e.goto(o,{waitUntil:"domcontentloaded",timeout:6e4}),await g(3e3);let i=e.url();if(/\/(login|authwall|checkpoint)/i.test(i))throw new Error(`Session expired \u2014 bounced to ${i} when fetching /details/${n}/`);if(!i.toLowerCase().includes(`/details/${n.toLowerCase()}/`))throw new Error(`Section /details/${n}/ not available on profile (landed on ${i})`);for(let s=0;s<4;s++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await g(700);await g(800);let r=0;for(;r<5&&await e.evaluate(()=>{for(let y of document.querySelectorAll("button"))if(/^Load more$/i.test((y.textContent||"").trim()))return y.click(),!0;return!1});)r++,await g(1300),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await g(600)}async function Y(e,t,n,o){try{return await o()}catch(i){let r=i.message||"";if(/session expired|bounced to|authwall|checkpoint/i.test(r))throw i;return/not available on profile/i.test(r)?(console.log(` (${t}: section not on profile \u2014 skipped)`),[]):(console.error(`${n} failed for ${e}: ${r.slice(0,120)}`),[])}}async function Mt(e,t){return Y(t,"featured","extractFeaturedFromDetails",async()=>(await J(e,t,"featured"),await e.evaluate(`(() => {
|
|
5
5
|
${K}
|
|
6
6
|
|
|
7
7
|
const main = document.querySelector('main');
|
|
@@ -42,7 +42,7 @@ var wt=Object.defineProperty;var Me=(e,t)=>()=>(e&&(t=e(e=0)),t);var gt=(e,t)=>{
|
|
|
42
42
|
if (e.caption && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.caption.trim())) return false;
|
|
43
43
|
return true;
|
|
44
44
|
});
|
|
45
|
-
})()`)))}async function
|
|
45
|
+
})()`)))}async function Rt(e,t){return Y(t,"education","extractEducationFromDetails",async()=>(await J(e,t,"education"),await e.evaluate(`(() => {
|
|
46
46
|
${K}
|
|
47
47
|
|
|
48
48
|
const main = document.querySelector('main');
|
|
@@ -111,7 +111,7 @@ var wt=Object.defineProperty;var Me=(e,t)=>()=>(e&&(t=e(e=0)),t);var gt=(e,t)=>{
|
|
|
111
111
|
skills.push({ name, endorsements, _raw: lines });
|
|
112
112
|
}
|
|
113
113
|
return skills;
|
|
114
|
-
})()`)))}async function
|
|
114
|
+
})()`)))}async function Nt(e,t){return Y(t,"certifications","extractCertificationsFromDetails",async()=>(await J(e,t,"certifications"),await e.evaluate(`(() => {
|
|
115
115
|
${K}
|
|
116
116
|
|
|
117
117
|
const main = document.querySelector('main');
|
|
@@ -136,7 +136,7 @@ var wt=Object.defineProperty;var Me=(e,t)=>()=>(e&&(t=e(e=0)),t);var gt=(e,t)=>{
|
|
|
136
136
|
|
|
137
137
|
return { name, issuer, issueDate, expiryDate, credentialId, _raw: lines };
|
|
138
138
|
}).filter(e => e.name);
|
|
139
|
-
})()`)))}async function
|
|
139
|
+
})()`)))}async function Tt(e,t){return Y(t,"recommendations","extractRecommendationsFromDetails",async()=>(await J(e,t,"recommendations"),await e.evaluate(`(() => {
|
|
140
140
|
${K}
|
|
141
141
|
|
|
142
142
|
const main = document.querySelector('main');
|
|
@@ -235,7 +235,7 @@ 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"dotenv/config";import Ut from"puppeteer";ce();import{getPluginConfig as yt}from"@ilivemylife/graph-sdk";var bt=await yt();for(let[e,t]of Object.entries(bt))process.env[e]===void 0&&(process.env[e]=t);var Kt=process.env.LINKEDIN_NAME,O=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Yt=Object.freeze(new Set([O.DRAFT,O.CONFIRMED,O.NEEDS_REVIEW])),zt=Object.freeze(new Set([O.DRAFT,O.CONFIRMED,O.REJECTED,O.NEEDS_REVIEW]));import"dotenv/config";import*as f from"fs";import*as b from"path";import{fileURLToPath as St}from"url";var kt=St(import.meta.url),Ct=b.dirname(b.dirname(kt)),_=process.env.DATA_DIR?b.resolve(process.env.DATA_DIR,"collected-profiles"):b.join(Ct,"collected-profiles"),ue=b.join(_,"people.json"),en=b.join(_,"jobs.json"),tn=b.join(_,"quota.json"),nn=b.join(_,"conversations.json"),on=b.join(_,"sync-state.json"),rn=b.join(_,"application-questions.json"),de=b.join(_,"profile-history"),Pe=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},sn=Pe(process.env.CONNECT_MAX_DAILY,20),ln=Pe(process.env.CONNECT_MAX_WEEKLY,100),W=null;function je(){f.existsSync(_)||f.mkdirSync(_,{recursive:!0})}function Oe(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";f.writeFileSync(o,n);for(let i=0;i<3;i++)try{f.renameSync(o,e);return}catch(s){if(i<2&&(s.code==="EPERM"||s.code==="EBUSY")){let r=Date.now();for(;Date.now()-r<200;);continue}throw s}}function qe(e,t){if(!f.existsSync(e))return null;try{let n=JSON.parse(f.readFileSync(e,"utf-8"));try{f.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.message}`),console.error(` File: ${b.resolve(e)}`);let o=e+".backup";if(f.existsSync(o))try{let i=JSON.parse(f.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{f.copyFileSync(o,e)}catch{}return i}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{f.copyFileSync(e,e+".corrupted")}catch{}return null}}function xt(){return new Date().toISOString().split("T")[0]}var vt=["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"],Et=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function q(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function Fe(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function Be(e,t,n=null){if(!t||e[t])return t;let o=q(t);if(!o)return t;let i=null;for(let[s,r]of Object.entries(e)){if(q(r.profileUrl||s)===o)return s;!i&&Array.isArray(r.aliases)&&r.aliases.includes(o)&&(i=s)}if(i){let s=Fe(n),r=Fe(e[i].name);if(s&&r&&s===r)return i}return t}function It(){f.existsSync(de)||f.mkdirSync(de,{recursive:!0})}function Ue(e){let t=q(e);return t?b.join(de,`${t}.json`):null}function At(e){let t=Ue(e);return t?qe(t,`profile-history/${q(e)}.json`)||[]:[]}function _t(e,t){let n=Ue(e);if(!n)return;It();let o=At(e);o.unshift(t);try{Oe(n,o)}catch(i){console.error(`[!] Failed to append profile-history for ${q(e)}: ${i.message}`)}}function Te(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function Re(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function $t(e,t){if(!e)return[];let n=[];for(let o of Et){let i=e[o],s=t[o];Te(i)||Te(s)||Re(i)!==Re(s)&&n.push(o)}return n}function Dt(e){let t=new Set(["seenCount","sources","firstSeen","lastSeen","lastUpdated","encounters","jobIds","lastFullVisitAt","lastSnapshotAt","messageSent","connectionStatus","connectionDate","connectionMethod"]),n={};for(let[o,i]of Object.entries(e))t.has(o)||(n[o]=i);return n}function fe(){return W||(je(),W=qe(ue,"people.json")||{},W)}function He(e){je(),W=e;try{Oe(ue,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${b.resolve(ue)}`)}}function me(e,t={}){if(!e)return null;let n=fe(),o=xt(),i=new Date().toISOString(),s=Be(n,e,t.name),r=n[s];if(r){let y=$t(r,t);y.length>0&&(_t(s,{capturedAt:i,previousLastUpdated:r.lastUpdated||null,changedFields:y,snapshot:Dt(r)}),r.lastSnapshotAt=i),r.seenCount=(r.seenCount||1)+1,r.lastSeen=o,r.lastUpdated=i,t.source&&!r.sources?.includes(t.source)&&(r.sources=r.sources||[],r.sources.push(t.source));for(let m of vt)if(t[m]!=null){if(Array.isArray(t[m])&&t[m].length===0&&Array.isArray(r[m])&&r[m].length>0)continue;r[m]=t[m]}Array.isArray(t.availableSections)&&(r.lastFullVisitAt=i)}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:i,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?i:null};return He(n),n[s]}function pe(e,t,n={}){if(n.dryRun||!e||!t)return;let o=q(t);if(!o)return;let i=fe(),s=Be(i,e),r=i[s];if(!r)return;let y=q(r.profileUrl||s);o!==y&&(Array.isArray(r.aliases)||(r.aliases=[]),r.aliases.includes(o)||(r.aliases.push(o),r.lastUpdated=new Date().toISOString(),He(i)))}async function Pt(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 g(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function Je(e,t,n={}){let{extractExperience:o=!1,extractFeatured:i=!1,extractEducation:s=!1,extractSkills:r=!1,extractRecommendations:y=!1,extractCertifications:m=!1}=n;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(3e3),await Ne(e)&&(console.log(" Dismissed Premium overlay"),await g(1500),await Pt(e,t));let c=0;for(let p=0;p<2;p++){let P=await e.evaluate(()=>document.body.scrollHeight);for(let D=1;D<=6;D++)await e.evaluate(v=>window.scrollTo(0,v),P*D/6),await g(900);let j=await e.evaluate(()=>document.body.scrollHeight);if(j===c)break;c=j}await g(800);let k=null;try{let p=e.url();p&&/\/in\/[^/?#]/.test(p)&&(k=p.split("?")[0].replace(/\/+$/,""))}catch{}let h=await e.evaluate(()=>{let p=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"]),P=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"]),j=l=>{let a=(l||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(a)},D={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:[]},v=document.querySelector("main");if(!v)return D;let d=[...Array.from(v.querySelectorAll("h1")),...Array.from(v.querySelectorAll("h2"))],C=Array.from(v.querySelectorAll("h2")),U=d.find(l=>{let a=l.textContent&&l.textContent.trim(),u=(a||"").replace(/\s*\(\d+\)$/,"").trim();return a&&a.length>1&&a.length<100&&!p.has(u)&&!P.has(u)}),H=U?U.textContent.trim():null,x=U?U.parentElement:null;for(;x&&x!==v&&!Array.from(x.children).filter(a=>a.tagName==="P").some(a=>{let u=a.textContent&&a.textContent.trim();return u&&u.length>5&&!j(u)});)x=x.parentElement;let ye=null,be=null,Se=null,le=null;if(x&&x!==v){let l=Array.from(x.children).filter(u=>u.tagName==="P").filter(u=>{let L=u.textContent&&u.textContent.trim();return L&&L.length>5&&!j(L)});if(l[0]&&(ye=l[0].textContent.trim()),l[1]){let u=l[1].textContent.trim().split(/\s*[·•]\s*/);be=u[0]||null,u.length>1&&(Se=u.slice(1).join(" \xB7 "))}let a=Array.from(x.children).filter(u=>u.tagName==="DIV");for(let u=a.length-1;u>=0;u--){let L=a[u].textContent&&a[u].textContent.trim();if(L&&!(H&&L.startsWith(H))&&(le=L.split(/[·•]/)[0].trim(),le))break}}let ke=null;if(x){let l=x.querySelectorAll("p, span, div");for(let a of l){let u=(a.textContent||"").trim().replace(/^[·•]\s*/,"");if(u==="1st"||u==="2nd"||u==="3rd"){ke=u;break}}}let ct=!!v.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),Ce=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),ut=Ce&&Ce.src||null,z=v.textContent||"",xe=null,ve=z.match(/(\d+\+?)\s+connections\b/i);ve&&(xe=ve[1]+" connections");let G=null,Ee=z.match(/(\d+)\s+mutual connection/i),Ie=z.match(/and\s+(\d+)\s+other mutual/i),dt=z.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);Ee?G=parseInt(Ee[1],10):Ie?G=2+parseInt(Ie[1],10):dt&&(G=2);let Ae=null,_e=null,$e=C.find(l=>l.textContent&&l.textContent.trim()==="About");if($e){let l=$e.parentElement;for(;l&&l.tagName!=="SECTION";)l=l.parentElement;if(l){let a=(l.textContent||"").trim();a=a.replace(/^About\s*/,"").trim();let u=a.match(/Top skills\s*(.+?)$/i);if(u){let ae=u[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(ht=>ht.trim()).filter(Boolean);ae.length>0&&ae.length<10&&(_e=ae)}a=a.split(/\n?…\s*more/i)[0].trim(),a=a.split(/\n?\.\.\.\s*more/i)[0].trim(),a=a.split(/\bTop skills\b/i)[0].trim(),a=a.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),Ae=a||null}}let De=null,Le=C.find(l=>l.textContent&&l.textContent.trim()==="Activity");if(Le){let l=Le.parentElement;for(;l&&l.tagName!=="SECTION";)l=l.parentElement;if(l){let a=(l.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);a&&(De=parseInt(a[1].replace(/,/g,""),10))}}let ft=[...new Set(C.map(l=>(l.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(l=>l&&l.length>1&&l.length<60&&l!==H).filter(l=>p.has(l)))],V=document.body.textContent||"",mt=/#OpenToWork\b/i.test(V)||/\bOpen to work\b/.test(V),pt=/#Hiring\b/i.test(V)||/\bI'?m hiring\b/i.test(V)||/\bWe are hiring\b/i.test(V);return{name:H,title:ye,location:le,currentCompany:be,currentSchool:Se,connectionDegree:ke,hasVerifiedBadge:ct,photoUrl:ut,connectionsLevel:xe,mutualConnectionsCount:G,followers:De,openToWork:mt,hiring:pt,about:Ae,topSkills:_e,availableSections:ft}});console.log(`Viewed: ${h.name} - ${h.title}`);let w=null,S=null,E=null,F=null,T=null,R=null;if(o||i||s||r||y||m){let p=await Promise.resolve().then(()=>(We(),Ve));o&&(w=await p.extractExperienceFromDetails(e,t),console.log(` + Experience: ${w.length} entries`)),i&&(S=await p.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${S.length} entries`)),s&&(E=await p.extractEducationFromDetails(e,t),console.log(` + Education: ${E.length} entries`)),r&&(F=await p.extractSkillsFromDetails(e,t),console.log(` + Skills: ${F.length} entries`)),y&&(T=await p.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${T.length} entries`)),m&&(R=await p.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${R.length} entries`))}return{...h,profileUrl:t,resolvedUrl:k,...w!==null&&{experience:w},...S!==null&&{featured:S},...E!==null&&{education:E},...F!==null&&{skillsFull:F},...T!==null&&{recommendations:T},...R!==null&&{certifications:R}}}catch($){console.error(`Error viewing profile ${t}:`,$.message);try{await e.goto("about:blank",{timeout:1e4}),await g(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test($.message||""))throw $;return null}}import I from"fs";import M from"path";var jt="cookies.json";function Ke(){let e=process.env.ILML_SCOPE_DIR;return e?M.join(e,"plugins-state","linkedin","cookies.json"):jt}function Ye(){let e=Ke();if(!I.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=I.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 ze(){return I.existsSync(Ke())}function Ot(){let e=process.env.ILML_SCOPE_DIR;return e?M.join(e,"plugins-state","linkedin"):"."}function Ge(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function qt(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?Ge(t[1]):"default"}function Qe(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return I.existsSync(t)||I.mkdirSync(t,{recursive:!0}),M.resolve(t);let n=Ge(e||qt()),o=M.join(Ot(),"chrome-profile",n);return I.existsSync(o)||I.mkdirSync(o,{recursive:!0}),M.resolve(o)}var Ze=".ilml-seeded";function Xe(e){return!I.existsSync(M.join(e,Ze))}function et(e){try{I.writeFileSync(M.join(e,Ze),new Date().toISOString())}catch{}}function tt(e){let t=0;for(let n of["SingletonLock","SingletonCookie","SingletonSocket"])try{I.rmSync(M.join(e,n),{force:!0}),t++}catch{}return t}var Bt={headless:!1,defaultViewport:null,protocolTimeout:3e5};async function nt(e,t={}){let n=Qe(),o={...Bt,...t,userDataDir:n},i;try{i=await e.launch(o)}catch{tt(n);try{i=await e.launch(o)}catch(r){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: ${r.message})`)}}return{browser:i,profileDir:n,needsSeed:Xe(n)}}async function ot(e,t){if(!t||!t.needsSeed)return!1;if(!ze())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(...Ye()),et(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}function it(e){return e?e.replace(/^https?:\/\/(www\.|m\.)?linkedin\.com/i,"https://linkedin.com").split("?")[0].split("#")[0].replace(/\/+$/,"").toLowerCase():""}function rt(e){return(e||"").replace(/ /g," ").replace(/\s+/g," ").trim().toLowerCase()}var A=process.argv.slice(2),Ht=A.includes("--help")||A.includes("-h"),N=A.find(e=>e.startsWith("http")),B=A.includes("--full"),Z=B||A.includes("--with-experience"),X=B||A.includes("--with-featured"),ee=B||A.includes("--with-education"),te=B||A.includes("--with-skills"),ne=B||A.includes("--with-recommendations"),oe=B||A.includes("--with-certifications"),st=[["experience",Z],["featured",X],["education",ee],["skills",te],["recommendations",ne],["certifications",oe]],lt=st.filter(([,e])=>e).length,we=1+lt;function at(){console.log(`
|
|
238
|
+
`});import"dotenv/config";import Ut from"puppeteer";ce();import{getPluginConfig as yt}from"@ilivemylife/graph-sdk";var bt=await yt();for(let[e,t]of Object.entries(bt))process.env[e]===void 0&&(process.env[e]=t);var Kt=process.env.LINKEDIN_NAME,O=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Yt=Object.freeze(new Set([O.DRAFT,O.CONFIRMED,O.NEEDS_REVIEW])),Gt=Object.freeze(new Set([O.DRAFT,O.CONFIRMED,O.REJECTED,O.NEEDS_REVIEW]));import"dotenv/config";import*as f from"fs";import*as b from"path";import{fileURLToPath as St}from"url";var kt=St(import.meta.url),Ct=b.dirname(b.dirname(kt)),_=process.env.DATA_DIR?b.resolve(process.env.DATA_DIR,"collected-profiles"):b.join(Ct,"collected-profiles"),ue=b.join(_,"people.json"),en=b.join(_,"jobs.json"),tn=b.join(_,"quota.json"),nn=b.join(_,"conversations.json"),on=b.join(_,"sync-state.json"),sn=b.join(_,"application-questions.json"),de=b.join(_,"profile-history"),Pe=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},rn=Pe(process.env.CONNECT_MAX_DAILY,20),ln=Pe(process.env.CONNECT_MAX_WEEKLY,100),W=null;function je(){f.existsSync(_)||f.mkdirSync(_,{recursive:!0})}function Oe(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";f.writeFileSync(o,n);for(let i=0;i<3;i++)try{f.renameSync(o,e);return}catch(r){if(i<2&&(r.code==="EPERM"||r.code==="EBUSY")){let s=Date.now();for(;Date.now()-s<200;);continue}throw r}}function qe(e,t){if(!f.existsSync(e))return null;try{let n=JSON.parse(f.readFileSync(e,"utf-8"));try{f.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.message}`),console.error(` File: ${b.resolve(e)}`);let o=e+".backup";if(f.existsSync(o))try{let i=JSON.parse(f.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{f.copyFileSync(o,e)}catch{}return i}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{f.copyFileSync(e,e+".corrupted")}catch{}return null}}function vt(){return new Date().toISOString().split("T")[0]}var xt=["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"],Et=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function q(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function Fe(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function Be(e,t,n=null){if(!t||e[t])return t;let o=q(t);if(!o)return t;let i=null;for(let[r,s]of Object.entries(e)){if(q(s.profileUrl||r)===o)return r;!i&&Array.isArray(s.aliases)&&s.aliases.includes(o)&&(i=r)}if(i){let r=Fe(n),s=Fe(e[i].name);if(r&&s&&r===s)return i}return t}function It(){f.existsSync(de)||f.mkdirSync(de,{recursive:!0})}function Ue(e){let t=q(e);return t?b.join(de,`${t}.json`):null}function At(e){let t=Ue(e);return t?qe(t,`profile-history/${q(e)}.json`)||[]:[]}function _t(e,t){let n=Ue(e);if(!n)return;It();let o=At(e);o.unshift(t);try{Oe(n,o)}catch(i){console.error(`[!] Failed to append profile-history for ${q(e)}: ${i.message}`)}}function Ne(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function Te(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function $t(e,t){if(!e)return[];let n=[];for(let o of Et){let i=e[o],r=t[o];Ne(i)||Ne(r)||Te(i)!==Te(r)&&n.push(o)}return n}function Dt(e){let t=new Set(["seenCount","sources","firstSeen","lastSeen","lastUpdated","encounters","jobIds","lastFullVisitAt","lastSnapshotAt","messageSent","connectionStatus","connectionDate","connectionMethod"]),n={};for(let[o,i]of Object.entries(e))t.has(o)||(n[o]=i);return n}function fe(){return W||(je(),W=qe(ue,"people.json")||{},W)}function He(e){je(),W=e;try{Oe(ue,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${b.resolve(ue)}`)}}function me(e,t={}){if(!e)return null;let n=fe(),o=vt(),i=new Date().toISOString(),r=Be(n,e,t.name),s=n[r];if(s){let y=$t(s,t);y.length>0&&(_t(r,{capturedAt:i,previousLastUpdated:s.lastUpdated||null,changedFields:y,snapshot:Dt(s)}),s.lastSnapshotAt=i),s.seenCount=(s.seenCount||1)+1,s.lastSeen=o,s.lastUpdated=i,t.source&&!s.sources?.includes(t.source)&&(s.sources=s.sources||[],s.sources.push(t.source));for(let m of xt)if(t[m]!=null){if(Array.isArray(t[m])&&t[m].length===0&&Array.isArray(s[m])&&s[m].length>0)continue;s[m]=t[m]}Array.isArray(t.availableSections)&&(s.lastFullVisitAt=i)}else n[r]={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:i,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?i:null};return He(n),n[r]}function pe(e,t,n={}){if(n.dryRun||!e||!t)return;let o=q(t);if(!o)return;let i=fe(),r=Be(i,e),s=i[r];if(!s)return;let y=q(s.profileUrl||r);o!==y&&(Array.isArray(s.aliases)||(s.aliases=[]),s.aliases.includes(o)||(s.aliases.push(o),s.lastUpdated=new Date().toISOString(),He(i)))}async function Pt(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 g(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function Je(e,t,n={}){let{extractExperience:o=!1,extractFeatured:i=!1,extractEducation:r=!1,extractSkills:s=!1,extractRecommendations:y=!1,extractCertifications:m=!1}=n;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await g(3e3),await Re(e)&&(console.log(" Dismissed Premium overlay"),await g(1500),await Pt(e,t));let c=0;for(let p=0;p<2;p++){let P=await e.evaluate(()=>document.body.scrollHeight);for(let D=1;D<=6;D++)await e.evaluate(x=>window.scrollTo(0,x),P*D/6),await g(900);let j=await e.evaluate(()=>document.body.scrollHeight);if(j===c)break;c=j}await g(800);let k=null;try{let p=e.url();p&&/\/in\/[^/?#]/.test(p)&&(k=p.split("?")[0].replace(/\/+$/,""))}catch{}let h=await e.evaluate(()=>{let p=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"]),P=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"]),j=l=>{let a=(l||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(a)},D={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:[]},x=document.querySelector("main");if(!x)return D;let d=[...Array.from(x.querySelectorAll("h1")),...Array.from(x.querySelectorAll("h2"))],C=Array.from(x.querySelectorAll("h2")),U=d.find(l=>{let a=l.textContent&&l.textContent.trim(),u=(a||"").replace(/\s*\(\d+\)$/,"").trim();return a&&a.length>1&&a.length<100&&!p.has(u)&&!P.has(u)}),H=U?U.textContent.trim():null,v=U?U.parentElement:null;for(;v&&v!==x&&!Array.from(v.children).filter(a=>a.tagName==="P").some(a=>{let u=a.textContent&&a.textContent.trim();return u&&u.length>5&&!j(u)});)v=v.parentElement;let ye=null,be=null,Se=null,le=null;if(v&&v!==x){let l=Array.from(v.children).filter(u=>u.tagName==="P").filter(u=>{let L=u.textContent&&u.textContent.trim();return L&&L.length>5&&!j(L)});if(l[0]&&(ye=l[0].textContent.trim()),l[1]){let u=l[1].textContent.trim().split(/\s*[·•]\s*/);be=u[0]||null,u.length>1&&(Se=u.slice(1).join(" \xB7 "))}let a=Array.from(v.children).filter(u=>u.tagName==="DIV");for(let u=a.length-1;u>=0;u--){let L=a[u].textContent&&a[u].textContent.trim();if(L&&!(H&&L.startsWith(H))&&(le=L.split(/[·•]/)[0].trim(),le))break}}let ke=null;if(v){let l=v.querySelectorAll("p, span, div");for(let a of l){let u=(a.textContent||"").trim().replace(/^[·•]\s*/,"");if(u==="1st"||u==="2nd"||u==="3rd"){ke=u;break}}}let ct=!!x.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),Ce=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),ut=Ce&&Ce.src||null,G=x.textContent||"",ve=null,xe=G.match(/(\d+\+?)\s+connections\b/i);xe&&(ve=xe[1]+" connections");let z=null,Ee=G.match(/(\d+)\s+mutual connection/i),Ie=G.match(/and\s+(\d+)\s+other mutual/i),dt=G.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);Ee?z=parseInt(Ee[1],10):Ie?z=2+parseInt(Ie[1],10):dt&&(z=2);let Ae=null,_e=null,$e=C.find(l=>l.textContent&&l.textContent.trim()==="About");if($e){let l=$e.parentElement;for(;l&&l.tagName!=="SECTION";)l=l.parentElement;if(l){let a=(l.textContent||"").trim();a=a.replace(/^About\s*/,"").trim();let u=a.match(/Top skills\s*(.+?)$/i);if(u){let ae=u[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(ht=>ht.trim()).filter(Boolean);ae.length>0&&ae.length<10&&(_e=ae)}a=a.split(/\n?…\s*more/i)[0].trim(),a=a.split(/\n?\.\.\.\s*more/i)[0].trim(),a=a.split(/\bTop skills\b/i)[0].trim(),a=a.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),Ae=a||null}}let De=null,Le=C.find(l=>l.textContent&&l.textContent.trim()==="Activity");if(Le){let l=Le.parentElement;for(;l&&l.tagName!=="SECTION";)l=l.parentElement;if(l){let a=(l.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);a&&(De=parseInt(a[1].replace(/,/g,""),10))}}let ft=[...new Set(C.map(l=>(l.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(l=>l&&l.length>1&&l.length<60&&l!==H).filter(l=>p.has(l)))],V=document.body.textContent||"",mt=/#OpenToWork\b/i.test(V)||/\bOpen to work\b/.test(V),pt=/#Hiring\b/i.test(V)||/\bI'?m hiring\b/i.test(V)||/\bWe are hiring\b/i.test(V);return{name:H,title:ye,location:le,currentCompany:be,currentSchool:Se,connectionDegree:ke,hasVerifiedBadge:ct,photoUrl:ut,connectionsLevel:ve,mutualConnectionsCount:z,followers:De,openToWork:mt,hiring:pt,about:Ae,topSkills:_e,availableSections:ft}});console.log(`Viewed: ${h.name} - ${h.title}`);let w=null,S=null,E=null,F=null,N=null,T=null;if(o||i||r||s||y||m){let p=await Promise.resolve().then(()=>(We(),Ve));o&&(w=await p.extractExperienceFromDetails(e,t),console.log(` + Experience: ${w.length} entries`)),i&&(S=await p.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${S.length} entries`)),r&&(E=await p.extractEducationFromDetails(e,t),console.log(` + Education: ${E.length} entries`)),s&&(F=await p.extractSkillsFromDetails(e,t),console.log(` + Skills: ${F.length} entries`)),y&&(N=await p.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${N.length} entries`)),m&&(T=await p.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${T.length} entries`))}return{...h,profileUrl:t,resolvedUrl:k,...w!==null&&{experience:w},...S!==null&&{featured:S},...E!==null&&{education:E},...F!==null&&{skillsFull:F},...N!==null&&{recommendations:N},...T!==null&&{certifications:T}}}catch($){console.error(`Error viewing profile ${t}:`,$.message);try{await e.goto("about:blank",{timeout:1e4}),await g(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test($.message||""))throw $;return null}}import I from"fs";import M from"path";var jt="cookies.json";function Ke(){let e=process.env.ILML_SCOPE_DIR;return e?M.join(e,"plugins-state","linkedin","cookies.json"):jt}function Ye(){let e=Ke();if(!I.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=I.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 Ge(){return I.existsSync(Ke())}function Ot(){let e=process.env.ILML_SCOPE_DIR;return e?M.join(e,"plugins-state","linkedin"):"."}function ze(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function qt(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?ze(t[1]):"default"}function Qe(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return I.existsSync(t)||I.mkdirSync(t,{recursive:!0}),M.resolve(t);let n=ze(e||qt()),o=M.join(Ot(),"chrome-profile",n);return I.existsSync(o)||I.mkdirSync(o,{recursive:!0}),M.resolve(o)}var Ze=".ilml-seeded";function Xe(e){return!I.existsSync(M.join(e,Ze))}function et(e){try{I.writeFileSync(M.join(e,Ze),new Date().toISOString())}catch{}}function tt(e){let t=0;for(let n of["SingletonLock","SingletonCookie","SingletonSocket"])try{I.rmSync(M.join(e,n),{force:!0}),t++}catch{}return t}var Bt={headless:!1,defaultViewport:null,protocolTimeout:3e5};async function nt(e,t={}){let n=Qe(),o={...Bt,...t,userDataDir:n},i;try{i=await e.launch(o)}catch{tt(n);try{i=await e.launch(o)}catch(s){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: ${s.message})`)}}return{browser:i,profileDir:n,needsSeed:Xe(n)}}async function ot(e,t){if(!t||!t.needsSeed)return!1;if(!Ge())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(...Ye()),et(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}function it(e){return e?e.replace(/^https?:\/\/(www\.|m\.)?linkedin\.com/i,"https://linkedin.com").split("?")[0].split("#")[0].replace(/\/+$/,"").toLowerCase():""}function st(e){return(e||"").replace(/ /g," ").replace(/\s+/g," ").trim().toLowerCase()}var A=process.argv.slice(2),Ht=A.includes("--help")||A.includes("-h"),R=A.find(e=>e.startsWith("http")),B=A.includes("--full"),Z=B||A.includes("--with-experience"),X=B||A.includes("--with-featured"),ee=B||A.includes("--with-education"),te=B||A.includes("--with-skills"),ne=B||A.includes("--with-recommendations"),oe=B||A.includes("--with-certifications"),rt=[["experience",Z],["featured",X],["education",ee],["skills",te],["recommendations",ne],["certifications",oe]],lt=rt.filter(([,e])=>e).length,we=1+lt;function at(){console.log(`
|
|
239
239
|
enrich-profile \u2014 visit ONE LinkedIn profile and save what we learn
|
|
240
240
|
|
|
241
241
|
USAGE
|
|
@@ -286,4 +286,4 @@ WHEN TO USE
|
|
|
286
286
|
- Audit your own LinkedIn profile (--full prints everything to stdout)
|
|
287
287
|
- Deep-dive on one specific contact before reaching out
|
|
288
288
|
- Verify what we know about a recruiter / lead
|
|
289
|
-
`)}Ht&&(at(),process.exit(0));
|
|
289
|
+
`)}Ht&&(at(),process.exit(0));R||(at(),process.exit(1));/linkedin\.com\/in\//i.test(R)||(console.error(`URL doesn't look like a LinkedIn profile: ${R}`),console.error("Expected format: https://www.linkedin.com/in/<slug>/"),process.exit(1));var ge=it(process.env.MY_LINKEDIN_URL||""),se=st(process.env.LINKEDIN_NAME||"");!ge&&!se&&(console.error(""),console.error(" \u26D4 Refusing to run: cannot self-detect without configuration."),console.error(""),console.error(" Set EITHER (preferably both) of:"),console.error(" MY_LINKEDIN_URL=https://www.linkedin.com/in/<your-slug>"),console.error(' LINKEDIN_NAME="Your Full Name"'),console.error(""),console.error(" in .env (dev) or via `ilml plugin config linkedin set <KEY> <VALUE>` (prod)."),console.error(" This prevents your own profile from accidentally landing in people.json."),console.error(""),process.exit(1));var ie=ge&&it(R)===ge,he=rt.filter(([,e])=>e).map(([e])=>e);console.log("");console.log(` enrichProfile \u2014 ${R}`);B?console.log(` Mode: --full (${we} page loads: main + ${he.join(" + ")})`):he.length>0?console.log(` Mode: rich (${we} loads: main + ${he.join(" + ")})`):console.log(" Mode: basic (1 load \u2014 main page only)");console.log(ie?" Target: SELF (URL match) \u2014 will print to stdout, not saved to people.json":se?` Target: TBD \u2014 name-match against "${process.env.LINKEDIN_NAME}" after fetch`:" Target: will save to people.json (no MY_LINKEDIN_URL or LINKEDIN_NAME set for self-check)");lt>0&&(console.log(""),console.log(` \u26A0 ${we} page loads on the SAME profile = normal "deep read" pattern.`),console.log(" This is intentionally single-URL \u2014 DO NOT batch. For batch enrichment"),console.log(" use `enrichProfiles.mjs --with-experience` (gated, capped)."));console.log("");var Q=null;try{let e=await nt(Ut);Q=e.browser;let t=await Q.newPage();await ot(t,e);let n=await Je(t,R,{extractExperience:Z,extractFeatured:X,extractEducation:ee,extractSkills:te,extractRecommendations:ne,extractCertifications:oe});if((!n||!n.name)&&(console.error(" viewProfile returned no name \u2014 profile not loaded or DOM changed"),process.exit(1)),!ie&&se&&n.name&&st(n.name)===se&&(ie=!0,console.log(" \u2191 Detected self via LINKEDIN_NAME match \u2014 will NOT save to people.json")),console.log(""),console.log(" \u2500\u2500\u2500 extracted \u2500\u2500\u2500"),console.log(` name: ${n.name}`),console.log(` title: ${n.title||"(none)"}`),console.log(` location: ${n.location||"(none)"}`),console.log(` about: ${n.about?`${n.about.length} chars`:"(none)"}`),console.log(` topSkills: ${n.topSkills?n.topSkills.join(", "):"(none)"}`),Z&&console.log(` experience: ${(n.experience||[]).length} entries`),X&&console.log(` featured: ${(n.featured||[]).length} entries`),ee&&console.log(` education: ${(n.education||[]).length} entries`),te&&console.log(` skillsFull: ${(n.skillsFull||[]).length} entries`),ne&&console.log(` recommendations: ${(n.recommendations||[]).length} entries`),oe&&console.log(` certifications: ${(n.certifications||[]).length} entries`),console.log(""),ie)console.log(" \u2500\u2500\u2500 full data (self \u2014 not persisted) \u2500\u2500\u2500"),console.log(JSON.stringify(n,null,2));else{let o={name:n.name,title:n.title,location:n.location,about:n.about,currentCompany:n.currentCompany,currentSchool:n.currentSchool,topSkills:n.topSkills,availableSections:n.availableSections,connectionsLevel:n.connectionsLevel,mutualConnectionsCount:n.mutualConnectionsCount,followers:n.followers,openToWork:n.openToWork,hiring:n.hiring,hasVerifiedBadge:n.hasVerifiedBadge,photoUrl:n.photoUrl,source:"enrich-profile-single"},i=[["experience",Z,n.experience],["featured",X,n.featured],["education",ee,n.education],["skillsFull",te,n.skillsFull],["recommendations",ne,n.recommendations],["certifications",oe,n.certifications]],r=!1;for(let[s,y,m]of i)y&&(Array.isArray(m)&&m.length>0?(o[s]=m,r=!0):console.log(` \u26A0 --with-${s==="skillsFull"?"skills":s} returned 0 entries \u2014 NOT writing ${s} (existing data preserved)`));r&&(o._lastEnrichedAt=new Date().toISOString()),me(R,o),n.resolvedUrl&&pe(R,n.resolvedUrl),console.log(" \u2713 Saved to people.json")}}catch(e){console.error(" Error:",e.message),process.exit(1)}finally{Q&&await Q.close().catch(()=>{})}
|
package/dist/enrichProfiles.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var mn=Object.defineProperty;var at=(e,t)=>()=>(e&&(t=e(e=0)),t);var fe=(e,t)=>{for(var n in t)mn(e,n,{get:t[n],enumerable:!0})};async function k(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"),l=r.includes("Get hired faster")||r.includes("Get hired 2x");if(s||i||l){let a=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(a)return a.click(),{dismissed:!0,matched:r.substring(0,80)};let f=o.querySelectorAll("button");for(let c of f){let m=c.innerText?.trim().toLowerCase()||"",d=c.getAttribute("aria-label")?.toLowerCase()||"";if(m==="not now"||m==="no thanks"||m==="dismiss"||d.includes("dismiss"))return c.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 mn=Object.defineProperty;var at=(e,t)=>()=>(e&&(t=e(e=0)),t);var fe=(e,t)=>{for(var n in t)mn(e,n,{get:t[n],enumerable:!0})};async function k(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"),l=r.includes("Get hired faster")||r.includes("Get hired 2x");if(s||i||l){let a=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(a)return a.click(),{dismissed:!0,matched:r.substring(0,80)};let f=o.querySelectorAll("button");for(let c of f){let m=c.innerText?.trim().toLowerCase()||"",d=c.getAttribute("aria-label")?.toLowerCase()||"";if(m==="not now"||m==="no thanks"||m==="dismiss"||d.includes("dismiss"))return c.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 Dt={};fe(Dt,{extractCertificationsFromDetails:()=>Wn,extractEducationFromDetails:()=>Vn,extractExperienceFromDetails:()=>Un,extractFeaturedFromDetails:()=>Bn,extractRecommendationsFromDetails:()=>Jn,extractSkillsFromDetails:()=>Hn});async function Un(e,t){let n=t.replace(/\/+$/,"")+"/details/experience/";try{await e.goto(n,{waitUntil:"domcontentloaded",timeout:6e4}),await k(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 k(900);await k(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 k(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await k(700);return await e.evaluate(()=>{let s=document.querySelector("main");if(!s)return[];function i(c){let m=[];for(let d of c.querySelectorAll("div")){let p=Array.from(d.children).filter(w=>w.tagName==="DIV");if(p.length<3)continue;let v=p.filter(w=>(w.textContent||"").trim().length>50);v.length<3||(d.textContent||"").length<500||m.push({el:d,count:v.length,totalText:(d.textContent||"").length})}return m.sort((d,p)=>p.count-d.count||d.totalText-p.totalText),m[0]?.el}let l=i(s);if(!l)return[];let a=Array.from(l.children).filter(c=>c.tagName==="DIV").filter(c=>(c.textContent||"").trim().length>50);function f(c){let m=c[0]||null,d=null,p=null;if(c[1]){let b=c[1].split("\xB7").map(_=>_.trim());d=b[0]||null,b[1]&&(p=b[1])}let v=c.findIndex(b=>/(\d{4}|present)/i.test(b)&&/(-|–|—)/i.test(b)&&b.length<80),w=null,E=null;if(v>=0){let b=c[v].split("\xB7").map(_=>_.trim());w=b[0]||null,b[1]&&(E=b[1])}let z=null,Q=-1;if(v>=0&&c[v+1]){let b=c[v+1],_=/^[>*\-•]|^>/.test(b),le=/https?:\/\//.test(b),ae=/\d{4}/.test(b),I=/,/.test(b)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(b);!_&&!le&&!ae&&b.length<100&&I&&(z=b,Q=v+1)}let Ce=null,x=-1,Z=c[c.length-1];if(Z&&/and\s+\+\d+\s+skills?$/i.test(Z)){x=c.length-1;let b=Z.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);b&&(Ce={listed:b[1].split(",").map(_=>_.trim()),additional:parseInt(b[2],10)})}let X=new Set([0,1,v,Q,x].filter(b=>b>=0)),V=c.filter((b,_)=>!X.has(_)),R=V.length>0?V.join(`
|
|
2
2
|
|
|
3
|
-
`):null;return{title:m,company:d,employmentType:p,dates:w,duration:E,location:z,description:
|
|
3
|
+
`):null;return{title:m,company:d,employmentType:p,dates:w,duration:E,location:z,description:R,skills:Ce,_raw:c}}return a.map(c=>{let d=(c.innerText||"").trim().split(`
|
|
4
4
|
`).map(p=>p.trim()).filter(p=>p&&p.length<5e3);return f(d)}).filter(c=>c.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 k(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 k(700);await k(800);let s=0;for(;s<5&&await e.evaluate(()=>{for(let l of document.querySelectorAll("button"))if(/^Load more$/i.test((l.textContent||"").trim()))return l.click(),!0;return!1});)s++,await k(1300),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await k(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 Bn(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 kn from"puppeteer";import{addExtra as Cn}from"puppeteer-extra";import xn from"puppeteer-extra-plugin-stealth";me();import{getPluginConfig as pn}from"@ilivemylife/graph-sdk";var hn=await pn();for(let[e,t]of Object.entries(hn))process.env[e]===void 0&&(process.env[e]=t);var gn=process.env.LINKEDIN_NAME,ee=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),mr=Object.freeze(new Set([ee.DRAFT,ee.CONFIRMED,ee.NEEDS_REVIEW])),yn=Object.freeze(new Set([ee.DRAFT,ee.CONFIRMED,ee.REJECTED,ee.NEEDS_REVIEW]));import P from"fs";import W from"path";var wn="cookies.json";function ut(){let e=process.env.ILML_SCOPE_DIR;return e?W.join(e,"plugins-state","linkedin","cookies.json"):wn}function dt(){let e=ut();if(!P.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=P.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 P.existsSync(ut())}function bn(){let e=process.env.ILML_SCOPE_DIR;return e?W.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 Sn(){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 P.existsSync(t)||P.mkdirSync(t,{recursive:!0}),W.resolve(t);let n=mt(e||Sn()),o=W.join(bn(),"chrome-profile",n);return P.existsSync(o)||P.mkdirSync(o,{recursive:!0}),W.resolve(o)}var ht=".ilml-seeded";function gt(e){return!P.existsSync(W.join(e,ht))}function yt(e){try{P.writeFileSync(W.join(e,ht),new Date().toISOString())}catch{}}function wt(e){let t=0;for(let n of["SingletonLock","SingletonCookie","SingletonSocket"])try{P.rmSync(W.join(e,n),{force:!0}),t++}catch{}return t}var vn={headless:!1,defaultViewport:null,protocolTimeout:3e5};async function bt(e,t={}){let n=pt(),o={...vn,...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=Cn(kn);vt.use(xn());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 C from"fs";import*as $ from"path";import{fileURLToPath as $n}from"url";var En=$n(import.meta.url),An=$.dirname($.dirname(En)),U=process.env.DATA_DIR?$.resolve(process.env.DATA_DIR,"collected-profiles"):$.join(An,"collected-profiles"),Ee=$.join(U,"people.json"),Nr=$.join(U,"jobs.json"),Lr=$.join(U,"quota.json"),Et=$.join(U,"conversations.json"),Fr=$.join(U,"sync-state.json"),Mr=$.join(U,"application-questions.json"),Ae=$.join(U,"profile-history"),At=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},Pr=At(process.env.CONNECT_MAX_DAILY,20),qr=At(process.env.CONNECT_MAX_WEEKLY,100),ue=null,_n=null,In=null,ce=null,Tn=null,Dn=null;function _t(){ue=null,_n=null,In=null,ce=null,Tn=null,Dn=null}function _e(){C.existsSync(U)||C.mkdirSync(U,{recursive:!0})}function Ie(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";C.writeFileSync(o,n);for(let r=0;r<3;r++)try{C.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,t){if(!C.existsSync(e))return null;try{let n=JSON.parse(C.readFileSync(e,"utf-8"));try{C.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.message}`),console.error(` File: ${$.resolve(e)}`);let o=e+".backup";if(C.existsSync(o))try{let r=JSON.parse(C.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{C.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{C.copyFileSync(e,e+".corrupted")}catch{}return null}}function Rn(){return new Date().toISOString().split("T")[0]}var On=["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"],jn=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function te(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 It(e,t,n=null){if(!t||e[t])return t;let o=te(t);if(!o)return t;let r=null;for(let[s,i]of Object.entries(e)){if(te(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 Nn(){C.existsSync(Ae)||C.mkdirSync(Ae,{recursive:!0})}function Tt(e){let t=te(e);return t?$.join(Ae,`${t}.json`):null}function Ln(e){let t=Tt(e);return t?Te(t,`profile-history/${te(e)}.json`)||[]:[]}function Fn(e,t){let n=Tt(e);if(!n)return;Nn();let o=Ln(e);o.unshift(t);try{Ie(n,o)}catch(r){console.error(`[!] Failed to append profile-history for ${te(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 Mn(e,t){if(!e)return[];let n=[];for(let o of jn){let r=e[o],s=t[o];xt(r)||xt(s)||$t(r)!==$t(s)&&n.push(o)}return n}function Pn(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 J(){return ue||(_e(),ue=Te(Ee,"people.json")||{},ue)}function Dt(e){_e(),ue=e;try{Ie(Ee,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${$.resolve(Ee)}`)}}function De(){return ce||(_e(),ce=Te(Et,"conversations.json")||{},qn(ce),ce)}function qn(e){let t=0;for(let n of Object.values(e)){if(!(n.draftStatus!==void 0||n.draftPreparedAt!==void 0))continue;let r=(n.messages||[]).find(s=>s.status==="draft");r&&n.draftStatus&&n.draftStatus!=="pending"&&(r.status=n.draftStatus),delete n.draftStatus,delete n.draftPreparedAt,t++}if(t>0){console.log(` [migration] Moved draft state from conv to msg.status for ${t} conversations`);try{Ie(Et,e)}catch{}}}function Re(e,t={}){if(!e)return null;let n=J(),o=Rn(),r=new Date().toISOString(),s=It(n,e,t.name),i=n[s];if(i){let l=Mn(i,t);l.length>0&&(Fn(s,{capturedAt:r,previousLastUpdated:i.lastUpdated||null,changedFields:l,snapshot:Pn(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 a of On)if(t[a]!=null){if(Array.isArray(t[a])&&t[a].length===0&&Array.isArray(i[a])&&i[a].length>0)continue;i[a]=t[a]}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 Dt(n),n[s]}function Oe(e,t,n={}){if(n.dryRun||!e||!t)return;let o=te(t);if(!o)return;let r=J(),s=It(r,e),i=r[s];if(!i)return;let l=te(i.profileUrl||s);o!==l&&(Array.isArray(i.aliases)||(i.aliases=[]),i.aliases.includes(o)||(i.aliases.push(o),i.lastUpdated=new Date().toISOString(),Dt(r)))}async function Yn(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 k(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function jt(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:s=!1,extractSkills:i=!1,extractRecommendations:l=!1,extractCertifications:a=!1}=n;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await k(3e3),await ct(e)&&(console.log(" Dismissed Premium overlay"),await k(1500),await Yn(e,t));let c=0;for(let x=0;x<2;x++){let Z=await e.evaluate(()=>document.body.scrollHeight);for(let V=1;V<=6;V++)await e.evaluate(D=>window.scrollTo(0,D),Z*V/6),await k(900);let X=await e.evaluate(()=>document.body.scrollHeight);if(X===c)break;c=X}await k(800);let m=null;try{let x=e.url();x&&/\/in\/[^/?#]/.test(x)&&(m=x.split("?")[0].replace(/\/+$/,""))}catch{}let d=await e.evaluate(()=>{let x=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),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"]),X=h=>{let g=(h||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(g)},V={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:[]},D=document.querySelector("main");if(!D)return V;let b=[...Array.from(D.querySelectorAll("h1")),...Array.from(D.querySelectorAll("h2"))],_=Array.from(D.querySelectorAll("h2")),le=b.find(h=>{let g=h.textContent&&h.textContent.trim(),y=(g||"").replace(/\s*\(\d+\)$/,"").trim();return g&&g.length>1&&g.length<100&&!x.has(y)&&!Z.has(y)}),ae=le?le.textContent.trim():null,I=le?le.parentElement:null;for(;I&&I!==D&&!Array.from(I.children).filter(g=>g.tagName==="P").some(g=>{let y=g.textContent&&g.textContent.trim();return y&&y.length>5&&!X(y)});)I=I.parentElement;let Ge=null,Ke=null,ze=null,xe=null;if(I&&I!==D){let h=Array.from(I.children).filter(y=>y.tagName==="P").filter(y=>{let H=y.textContent&&y.textContent.trim();return H&&H.length>5&&!X(H)});if(h[0]&&(Ge=h[0].textContent.trim()),h[1]){let y=h[1].textContent.trim().split(/\s*[·•]\s*/);Ke=y[0]||null,y.length>1&&(ze=y.slice(1).join(" \xB7 "))}let g=Array.from(I.children).filter(y=>y.tagName==="DIV");for(let y=g.length-1;y>=0;y--){let H=g[y].textContent&&g[y].textContent.trim();if(H&&!(ae&&H.startsWith(ae))&&(xe=H.split(/[·•]/)[0].trim(),xe))break}}let Qe=null;if(I){let h=I.querySelectorAll("p, span, div");for(let g of h){let y=(g.textContent||"").trim().replace(/^[·•]\s*/,"");if(y==="1st"||y==="2nd"||y==="3rd"){Qe=y;break}}}let sn=!!D.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),Ze=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),ln=Ze&&Ze.src||null,we=D.textContent||"",Xe=null,et=we.match(/(\d+\+?)\s+connections\b/i);et&&(Xe=et[1]+" connections");let be=null,tt=we.match(/(\d+)\s+mutual connection/i),nt=we.match(/and\s+(\d+)\s+other mutual/i),an=we.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);tt?be=parseInt(tt[1],10):nt?be=2+parseInt(nt[1],10):an&&(be=2);let ot=null,rt=null,st=_.find(h=>h.textContent&&h.textContent.trim()==="About");if(st){let h=st.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let g=(h.textContent||"").trim();g=g.replace(/^About\s*/,"").trim();let y=g.match(/Top skills\s*(.+?)$/i);if(y){let $e=y[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(fn=>fn.trim()).filter(Boolean);$e.length>0&&$e.length<10&&(rt=$e)}g=g.split(/\n?…\s*more/i)[0].trim(),g=g.split(/\n?\.\.\.\s*more/i)[0].trim(),g=g.split(/\bTop skills\b/i)[0].trim(),g=g.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),ot=g||null}}let it=null,lt=_.find(h=>h.textContent&&h.textContent.trim()==="Activity");if(lt){let h=lt.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let g=(h.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);g&&(it=parseInt(g[1].replace(/,/g,""),10))}}let cn=[...new Set(_.map(h=>(h.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(h=>h&&h.length>1&&h.length<60&&h!==ae).filter(h=>x.has(h)))],de=document.body.textContent||"",un=/#OpenToWork\b/i.test(de)||/\bOpen to work\b/.test(de),dn=/#Hiring\b/i.test(de)||/\bI'?m hiring\b/i.test(de)||/\bWe are hiring\b/i.test(de);return{name:ae,title:Ge,location:xe,currentCompany:Ke,currentSchool:ze,connectionDegree:Qe,hasVerifiedBadge:sn,photoUrl:ln,connectionsLevel:Xe,mutualConnectionsCount:be,followers:it,openToWork:un,hiring:dn,about:ot,topSkills:rt,availableSections:cn}});console.log(`Viewed: ${d.name} - ${d.title}`);let p=null,v=null,w=null,E=null,z=null,Q=null;if(o||r||s||i||l||a){let x=await Promise.resolve().then(()=>(Ot(),Rt));o&&(p=await x.extractExperienceFromDetails(e,t),console.log(` + Experience: ${p.length} entries`)),r&&(v=await x.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${v.length} entries`)),s&&(w=await x.extractEducationFromDetails(e,t),console.log(` + Education: ${w.length} entries`)),i&&(E=await x.extractSkillsFromDetails(e,t),console.log(` + Skills: ${E.length} entries`)),l&&(z=await x.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${z.length} entries`)),a&&(Q=await x.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${Q.length} entries`))}return{...d,profileUrl:t,resolvedUrl:m,...p!==null&&{experience:p},...v!==null&&{featured:v},...w!==null&&{education:w},...E!==null&&{skillsFull:E},...z!==null&&{recommendations:z},...Q!==null&&{certifications:Q}}}catch(f){console.error(`Error viewing profile ${t}:`,f.message);try{await e.goto("about:blank",{timeout:1e4}),await k(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(f.message||""))throw f;return null}}import"dotenv/config";import*as O from"fs";import*as R from"path";import{fileURLToPath as Gn}from"url";var Kn=Gn(import.meta.url),zn=R.dirname(R.dirname(Kn)),oe=process.env.DATA_DIR?R.resolve(process.env.DATA_DIR,"market-research"):R.join(zn,"market-research"),es=R.join(oe,"scouted-jobs.json"),ts=R.join(oe,"discovered-people.json"),Nt=R.join(oe,"visit-log.json"),ns=R.join(oe,"companies.json"),os=R.join(oe,"job-decisions.json");function Qn(){O.existsSync(oe)||O.mkdirSync(oe,{recursive:!0})}function Zn(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 Xn(e){try{if(O.existsSync(e))return JSON.parse(O.readFileSync(e,"utf-8"))}catch{}return null}function Lt(){eo=null,to=null,no=null,oo=null,ne=null}var eo=null;var to=null;var no=null;var oo=null;var ne=null;function je(){return ne||(ne=Xn(Nt)||{visits:[]},Array.isArray(ne.visits)||(ne.visits=[]),ne)}function Ft(e,t={}){if(!e)return;Qn();let n=je();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{Zn(Nt,n)}catch(r){console.error(`[!] Failed to save visit-log.json: ${r.message}`)}}function Mt(e){let t=je();for(let n=t.visits.length-1;n>=0;n--)if(t.visits[n].profileUrl===e)return t.visits[n].date;return null}me();async function Pt(e,t,n={}){let{maxVisits:o=50,delayBetween:r=4e3,skipRecentDays:s=7,verbose:i=!1,extractExperience:l=!1}=n,a={visited:0,skipped:0,errors:0},f=Date.now()-s*24*60*60*1e3;for(let c of t){if(a.visited>=o)break;if(!c.profileUrl)continue;let m=Mt(c.profileUrl);if(m&&new Date(m).getTime()>f){a.skipped++;continue}try{let d=await jt(e,c.profileUrl,{extractExperience:l}),p=c.source||"visit";if(d){let w={...d,source:p};l&&Array.isArray(d.experience)&&d.experience.length>0&&(w._lastEnrichedAt=new Date().toISOString()),Re(c.profileUrl,w),d.resolvedUrl&&Oe(c.profileUrl,d.resolvedUrl)}Ft(c.profileUrl,{name:d?.name||c.name||null,source:p}),a.visited++,i?console.log(` [${a.visited}] ${d?.name||c.profileUrl} \u2014 ${d?.title?.slice(0,40)||"?"}`):a.visited%10===0&&console.log(` Visited: ${a.visited}`);let v=Math.random()*4e3;await k(r+v)}catch(d){a.errors++,i&&console.error(` Error visiting ${c.name||c.profileUrl}: ${d.message?.slice(0,60)}`);let p=(d.message||"").toLowerCase();if(p.includes("detached")||p.includes("session closed")||p.includes("target closed")||p.includes("session expired")||p.includes("bounced to")||p.includes("authwall")||p.includes("checkpoint")||p.includes("redirected to login")){console.log(" Fatal browser/session error \u2014 stopping visits");break}}}return a}import"dotenv/config";import*as j from"fs";import*as Y from"path";import{fileURLToPath as co}from"url";import"dotenv/config";import{createGraphClient as ro,resolveToken as so}from"@ilivemylife/graph-sdk";import{config as io}from"dotenv";io();var qt=so()||process.env.TOKEN;qt||(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 C from"fs";import*as $ from"path";import{fileURLToPath as $n}from"url";var En=$n(import.meta.url),An=$.dirname($.dirname(En)),U=process.env.DATA_DIR?$.resolve(process.env.DATA_DIR,"collected-profiles"):$.join(An,"collected-profiles"),Ee=$.join(U,"people.json"),Nr=$.join(U,"jobs.json"),Lr=$.join(U,"quota.json"),Et=$.join(U,"conversations.json"),Fr=$.join(U,"sync-state.json"),Mr=$.join(U,"application-questions.json"),Ae=$.join(U,"profile-history"),At=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},Pr=At(process.env.CONNECT_MAX_DAILY,20),qr=At(process.env.CONNECT_MAX_WEEKLY,100),ue=null,_n=null,In=null,ce=null,Tn=null,Rn=null;function _t(){ue=null,_n=null,In=null,ce=null,Tn=null,Rn=null}function _e(){C.existsSync(U)||C.mkdirSync(U,{recursive:!0})}function Ie(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";C.writeFileSync(o,n);for(let r=0;r<3;r++)try{C.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,t){if(!C.existsSync(e))return null;try{let n=JSON.parse(C.readFileSync(e,"utf-8"));try{C.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.message}`),console.error(` File: ${$.resolve(e)}`);let o=e+".backup";if(C.existsSync(o))try{let r=JSON.parse(C.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{C.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{C.copyFileSync(e,e+".corrupted")}catch{}return null}}function Dn(){return new Date().toISOString().split("T")[0]}var On=["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"],jn=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function te(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 It(e,t,n=null){if(!t||e[t])return t;let o=te(t);if(!o)return t;let r=null;for(let[s,i]of Object.entries(e)){if(te(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 Nn(){C.existsSync(Ae)||C.mkdirSync(Ae,{recursive:!0})}function Tt(e){let t=te(e);return t?$.join(Ae,`${t}.json`):null}function Ln(e){let t=Tt(e);return t?Te(t,`profile-history/${te(e)}.json`)||[]:[]}function Fn(e,t){let n=Tt(e);if(!n)return;Nn();let o=Ln(e);o.unshift(t);try{Ie(n,o)}catch(r){console.error(`[!] Failed to append profile-history for ${te(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 Mn(e,t){if(!e)return[];let n=[];for(let o of jn){let r=e[o],s=t[o];xt(r)||xt(s)||$t(r)!==$t(s)&&n.push(o)}return n}function Pn(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 J(){return ue||(_e(),ue=Te(Ee,"people.json")||{},ue)}function Rt(e){_e(),ue=e;try{Ie(Ee,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${$.resolve(Ee)}`)}}function Re(){return ce||(_e(),ce=Te(Et,"conversations.json")||{},qn(ce),ce)}function qn(e){let t=0;for(let n of Object.values(e)){if(!(n.draftStatus!==void 0||n.draftPreparedAt!==void 0))continue;let r=(n.messages||[]).find(s=>s.status==="draft");r&&n.draftStatus&&n.draftStatus!=="pending"&&(r.status=n.draftStatus),delete n.draftStatus,delete n.draftPreparedAt,t++}if(t>0){console.log(` [migration] Moved draft state from conv to msg.status for ${t} conversations`);try{Ie(Et,e)}catch{}}}function De(e,t={}){if(!e)return null;let n=J(),o=Dn(),r=new Date().toISOString(),s=It(n,e,t.name),i=n[s];if(i){let l=Mn(i,t);l.length>0&&(Fn(s,{capturedAt:r,previousLastUpdated:i.lastUpdated||null,changedFields:l,snapshot:Pn(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 a of On)if(t[a]!=null){if(Array.isArray(t[a])&&t[a].length===0&&Array.isArray(i[a])&&i[a].length>0)continue;i[a]=t[a]}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 Rt(n),n[s]}function Oe(e,t,n={}){if(n.dryRun||!e||!t)return;let o=te(t);if(!o)return;let r=J(),s=It(r,e),i=r[s];if(!i)return;let l=te(i.profileUrl||s);o!==l&&(Array.isArray(i.aliases)||(i.aliases=[]),i.aliases.includes(o)||(i.aliases.push(o),i.lastUpdated=new Date().toISOString(),Rt(r)))}async function Gn(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 k(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function jt(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:s=!1,extractSkills:i=!1,extractRecommendations:l=!1,extractCertifications:a=!1}=n;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await k(3e3),await ct(e)&&(console.log(" Dismissed Premium overlay"),await k(1500),await Gn(e,t));let c=0;for(let x=0;x<2;x++){let Z=await e.evaluate(()=>document.body.scrollHeight);for(let V=1;V<=6;V++)await e.evaluate(R=>window.scrollTo(0,R),Z*V/6),await k(900);let X=await e.evaluate(()=>document.body.scrollHeight);if(X===c)break;c=X}await k(800);let m=null;try{let x=e.url();x&&/\/in\/[^/?#]/.test(x)&&(m=x.split("?")[0].replace(/\/+$/,""))}catch{}let d=await e.evaluate(()=>{let x=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),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"]),X=h=>{let g=(h||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(g)},V={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 V;let b=[...Array.from(R.querySelectorAll("h1")),...Array.from(R.querySelectorAll("h2"))],_=Array.from(R.querySelectorAll("h2")),le=b.find(h=>{let g=h.textContent&&h.textContent.trim(),y=(g||"").replace(/\s*\(\d+\)$/,"").trim();return g&&g.length>1&&g.length<100&&!x.has(y)&&!Z.has(y)}),ae=le?le.textContent.trim():null,I=le?le.parentElement:null;for(;I&&I!==R&&!Array.from(I.children).filter(g=>g.tagName==="P").some(g=>{let y=g.textContent&&g.textContent.trim();return y&&y.length>5&&!X(y)});)I=I.parentElement;let Ye=null,Ke=null,ze=null,xe=null;if(I&&I!==R){let h=Array.from(I.children).filter(y=>y.tagName==="P").filter(y=>{let H=y.textContent&&y.textContent.trim();return H&&H.length>5&&!X(H)});if(h[0]&&(Ye=h[0].textContent.trim()),h[1]){let y=h[1].textContent.trim().split(/\s*[·•]\s*/);Ke=y[0]||null,y.length>1&&(ze=y.slice(1).join(" \xB7 "))}let g=Array.from(I.children).filter(y=>y.tagName==="DIV");for(let y=g.length-1;y>=0;y--){let H=g[y].textContent&&g[y].textContent.trim();if(H&&!(ae&&H.startsWith(ae))&&(xe=H.split(/[·•]/)[0].trim(),xe))break}}let Qe=null;if(I){let h=I.querySelectorAll("p, span, div");for(let g of h){let y=(g.textContent||"").trim().replace(/^[·•]\s*/,"");if(y==="1st"||y==="2nd"||y==="3rd"){Qe=y;break}}}let sn=!!R.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),Ze=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),ln=Ze&&Ze.src||null,we=R.textContent||"",Xe=null,et=we.match(/(\d+\+?)\s+connections\b/i);et&&(Xe=et[1]+" connections");let be=null,tt=we.match(/(\d+)\s+mutual connection/i),nt=we.match(/and\s+(\d+)\s+other mutual/i),an=we.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);tt?be=parseInt(tt[1],10):nt?be=2+parseInt(nt[1],10):an&&(be=2);let ot=null,rt=null,st=_.find(h=>h.textContent&&h.textContent.trim()==="About");if(st){let h=st.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let g=(h.textContent||"").trim();g=g.replace(/^About\s*/,"").trim();let y=g.match(/Top skills\s*(.+?)$/i);if(y){let $e=y[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(fn=>fn.trim()).filter(Boolean);$e.length>0&&$e.length<10&&(rt=$e)}g=g.split(/\n?…\s*more/i)[0].trim(),g=g.split(/\n?\.\.\.\s*more/i)[0].trim(),g=g.split(/\bTop skills\b/i)[0].trim(),g=g.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),ot=g||null}}let it=null,lt=_.find(h=>h.textContent&&h.textContent.trim()==="Activity");if(lt){let h=lt.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let g=(h.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);g&&(it=parseInt(g[1].replace(/,/g,""),10))}}let cn=[...new Set(_.map(h=>(h.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(h=>h&&h.length>1&&h.length<60&&h!==ae).filter(h=>x.has(h)))],de=document.body.textContent||"",un=/#OpenToWork\b/i.test(de)||/\bOpen to work\b/.test(de),dn=/#Hiring\b/i.test(de)||/\bI'?m hiring\b/i.test(de)||/\bWe are hiring\b/i.test(de);return{name:ae,title:Ye,location:xe,currentCompany:Ke,currentSchool:ze,connectionDegree:Qe,hasVerifiedBadge:sn,photoUrl:ln,connectionsLevel:Xe,mutualConnectionsCount:be,followers:it,openToWork:un,hiring:dn,about:ot,topSkills:rt,availableSections:cn}});console.log(`Viewed: ${d.name} - ${d.title}`);let p=null,v=null,w=null,E=null,z=null,Q=null;if(o||r||s||i||l||a){let x=await Promise.resolve().then(()=>(Ot(),Dt));o&&(p=await x.extractExperienceFromDetails(e,t),console.log(` + Experience: ${p.length} entries`)),r&&(v=await x.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${v.length} entries`)),s&&(w=await x.extractEducationFromDetails(e,t),console.log(` + Education: ${w.length} entries`)),i&&(E=await x.extractSkillsFromDetails(e,t),console.log(` + Skills: ${E.length} entries`)),l&&(z=await x.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${z.length} entries`)),a&&(Q=await x.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${Q.length} entries`))}return{...d,profileUrl:t,resolvedUrl:m,...p!==null&&{experience:p},...v!==null&&{featured:v},...w!==null&&{education:w},...E!==null&&{skillsFull:E},...z!==null&&{recommendations:z},...Q!==null&&{certifications:Q}}}catch(f){console.error(`Error viewing profile ${t}:`,f.message);try{await e.goto("about:blank",{timeout:1e4}),await k(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(f.message||""))throw f;return null}}import"dotenv/config";import*as O from"fs";import*as D from"path";import{fileURLToPath as Yn}from"url";var Kn=Yn(import.meta.url),zn=D.dirname(D.dirname(Kn)),oe=process.env.DATA_DIR?D.resolve(process.env.DATA_DIR,"market-research"):D.join(zn,"market-research"),es=D.join(oe,"scouted-jobs.json"),ts=D.join(oe,"discovered-people.json"),Nt=D.join(oe,"visit-log.json"),ns=D.join(oe,"companies.json"),os=D.join(oe,"job-decisions.json");function Qn(){O.existsSync(oe)||O.mkdirSync(oe,{recursive:!0})}function Zn(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 Xn(e){try{if(O.existsSync(e))return JSON.parse(O.readFileSync(e,"utf-8"))}catch{}return null}function Lt(){eo=null,to=null,no=null,oo=null,ne=null}var eo=null;var to=null;var no=null;var oo=null;var ne=null;function je(){return ne||(ne=Xn(Nt)||{visits:[]},Array.isArray(ne.visits)||(ne.visits=[]),ne)}function Ft(e,t={}){if(!e)return;Qn();let n=je();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{Zn(Nt,n)}catch(r){console.error(`[!] Failed to save visit-log.json: ${r.message}`)}}function Mt(e){let t=je();for(let n=t.visits.length-1;n>=0;n--)if(t.visits[n].profileUrl===e)return t.visits[n].date;return null}me();async function Pt(e,t,n={}){let{maxVisits:o=50,delayBetween:r=4e3,skipRecentDays:s=7,verbose:i=!1,extractExperience:l=!1}=n,a={visited:0,skipped:0,errors:0},f=Date.now()-s*24*60*60*1e3;for(let c of t){if(a.visited>=o)break;if(!c.profileUrl)continue;let m=Mt(c.profileUrl);if(m&&new Date(m).getTime()>f){a.skipped++;continue}try{let d=await jt(e,c.profileUrl,{extractExperience:l}),p=c.source||"visit";if(d){let w={...d,source:p};l&&Array.isArray(d.experience)&&d.experience.length>0&&(w._lastEnrichedAt=new Date().toISOString()),De(c.profileUrl,w),d.resolvedUrl&&Oe(c.profileUrl,d.resolvedUrl)}Ft(c.profileUrl,{name:d?.name||c.name||null,source:p}),a.visited++,i?console.log(` [${a.visited}] ${d?.name||c.profileUrl} \u2014 ${d?.title?.slice(0,40)||"?"}`):a.visited%10===0&&console.log(` Visited: ${a.visited}`);let v=Math.random()*4e3;await k(r+v)}catch(d){a.errors++,i&&console.error(` Error visiting ${c.name||c.profileUrl}: ${d.message?.slice(0,60)}`);let p=(d.message||"").toLowerCase();if(p.includes("detached")||p.includes("session closed")||p.includes("target closed")||p.includes("session expired")||p.includes("bounced to")||p.includes("authwall")||p.includes("checkpoint")||p.includes("redirected to login")){console.log(" Fatal browser/session error \u2014 stopping visits");break}}}return a}import"dotenv/config";import*as j from"fs";import*as G from"path";import{fileURLToPath as co}from"url";import"dotenv/config";import{createGraphClient as ro,resolveToken as so}from"@ilivemylife/graph-sdk";import{config as io}from"dotenv";io();var qt=so()||process.env.TOKEN;qt||(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 Ut=ro({token:qt});function lo(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 ao({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"," "),l=r?` ${lo(r)}`:"",a=n==="error"?`error${o?`: ${String(o).slice(0,80)}`:""}`:n==="quota-reached"?"daily quota reached":"done",f=t&&t!=="default"?` (${t})`:"";return`${s} ${e}${f} \u2014 ${a} \u2014 ${i}${l}`}async function Bt({scriptName:e,mode:t,status:n,summaryLines:o,error:r,duration:s}){let i=process.env.NODE_RUN_REPORTS;if(!i||!Array.isArray(o)||o.length===0)return;let a=`**${ao({scriptName:e,mode:t,status:n,error:r,duration:s})}**
|
|
244
244
|
|
|
245
245
|
${o.join(`
|
|
246
|
-
`)}`;try{await Ut.addMessage(i,a)}catch(f){console.error(`[runReport] Failed to post end-of-session message: ${f.message}`)}}var uo=co(import.meta.url),fo=Y.dirname(Y.dirname(uo)),Ne=process.env.DATA_DIR?Y.resolve(process.env.DATA_DIR,"collected-profiles"):Y.join(fo,"collected-profiles"),Le=Y.join(Ne,"run-log.json");function mo(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 Vt(){try{if(!j.existsSync(Le))return{runs:[]};let e=JSON.parse(j.readFileSync(Le,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Ht(e){j.existsSync(Ne)||j.mkdirSync(Ne,{recursive:!0});try{mo(Le,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function Wt(e,t="default"){let n=Vt();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),Ht(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=Vt(),l=i.runs[e.runIndex];if(l&&l.status==="running"&&l.script===e.script)l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=n,l.error=o,r=l.duration;else{let a=i.runs.find(f=>f.script===e.script&&f.status==="running"&&f.timestamp===new Date(e.startTime).toISOString());a&&(a.status=t,a.result=t,a.duration=Date.now()-e.startTime,a.stats=n,a.error=o,r=a.duration)}Ht(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";Bt({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(l=>console.error(`[runLog] postRunReport failed: ${l.message}`))}}import"dotenv/config";import*as u from"fs";import*as We from"os";import*as S from"path";import{fileURLToPath as Fo}from"url";var qe={};fe(qe,{NAME:()=>ho,VERSION:()=>po,up:()=>wo});import*as N from"fs";import*as Se from"path";var po=1,ho="normalize-jobs-and-questions",go=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],yo=50;function Me(e){return N.existsSync(e)?JSON.parse(N.readFileSync(e,"utf-8")):null}function Pe(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{N.writeFileSync(o,n)}catch(r){try{N.unlinkSync(o)}catch{}throw r}try{N.renameSync(o,e)}catch(r){try{N.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 wo(e,t){let n=Se.join(e,"jobs.json"),o=Se.join(t,"scouted-jobs.json"),r=Se.join(e,"application-questions.json"),s=Me(n)||{},i=Me(o)||{},l=0,a=[];for(let c of Object.keys(s)){if(!i[c])continue;let m=i[c],d=s[c];for(let p of go)m[p]!=null&&d[p]==null&&(d[p]=m[p]);a.push(c),l++}l>0?(Pe(n,s),console.log(` Phase 1: Merged ${l} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let f=Me(r);if(f&&Array.isArray(f.applications)){let c={},m=0;for(let d of f.applications){let p=d.jobId||"unknown";c[p]||(c[p]={applications:[]});let v=(d.questions||[]).map(w=>{let E={type:w.type||"input",question:w.question||"",answer:w.answer||""};return w.options&&(w.options.length<=yo?E.options=w.options:(E.optionsOmitted=!0,m++)),w.page&&(E.page=w.page),w.wasPreFilled&&(E.wasPreFilled=!0),w.wasRetry&&(E.wasRetry=!0),E});c[p].applications.push({applicationId:d.applicationId,date:d.date,result:d.result||"submitted",formPages:d.formPages||null,duration:d.duration||null,retries:d.retries||0,failedField:d.failedField||null,questionCount:d.questionCount||v.length,questions:v})}Pe(r,c),console.log(` Phase 2: Rekeyed ${f.applications.length} applications by jobId (${Object.keys(c).length} unique jobs)`),m>0&&console.log(` Phase 2: Stripped bloated options from ${m} questions`)}else f&&!f.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(a.length>0){for(let c of a)delete i[c];Pe(o,i),console.log(` Phase 3: Removed ${a.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var Ue={};fe(Ue,{NAME:()=>So,VERSION:()=>bo,up:()=>Co});import*as L from"fs";import*as Jt from"path";var bo=2,So="reset-unread-flags";function vo(e){return L.existsSync(e)?JSON.parse(L.readFileSync(e,"utf-8")):null}function ko(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 Co(e){let t=Jt.join(e,"conversations.json"),n=vo(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}ko(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:()=>xo,up:()=>To});import*as F from"fs";import*as Yt from"path";var xo=3,$o="recompute-last-message-by",Eo=new Set(["draft","confirmed","rejected","needs_review"]);function Ao(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}}function Io(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!Eo.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 To(e){let t=Yt.join(e,"conversations.json"),n=Ao(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 l of Object.keys(n)){let a=n[l];if(!a||typeof a!="object")continue;Object.prototype.hasOwnProperty.call(a,"_cardSynced")&&(delete a._cardSynced,s++);let f=Array.isArray(a.messages)?a.messages:[],c=Io(f,o),m=c==="me"?"awaiting_reply":"unanswered_by_us";a.lastMessageBy!==c&&i++,a.lastMessageBy=c,a.conversationStatus=m,r++}if(r===0){console.log(" No conversations to recompute.");return}_o(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:()=>Ro,VERSION:()=>Do,up:()=>Lo});import*as M from"fs";import*as Gt from"path";var Do=4,Ro="split-connection-timestamps",Oo=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function jo(e){if(!M.existsSync(e))return null;let t=M.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function No(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}}async function Lo(e){let t=Gt.join(e,"people.json"),n=jo(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++,Oo.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}No(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 Mo=Fo(import.meta.url),Po=S.dirname(Mo),qo=S.dirname(S.dirname(Po));function Uo(e){return e&&(e==="~"?We.homedir():e.startsWith("~/")||e.startsWith("~\\")?S.join(We.homedir(),e.slice(2)):e)}var q=process.env.DATA_DIR?S.resolve(Uo(process.env.DATA_DIR)):qo,se=S.join(q,"collected-profiles"),ie=S.join(q,"market-research"),T=S.join(q,".schema-version"),Kt=[S.join(se,".schema-version"),S.join(ie,".schema-version")],G=4,B=[{version:1,module:qe},{version:2,module:Ue},{version:3,module:Be},{version:4,module:Ve}];(function(){B.sort((o,r)=>o.version-r.version);let t=new Set;for(let o of B){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=B.length?B[B.length-1].version:0;if(n!==G)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${G}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<B.length;o++){let r=o+1;if(B[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${B[o].version}`)}})();function Xt(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
246
|
+
`)}`;try{await Ut.addMessage(i,a)}catch(f){console.error(`[runReport] Failed to post end-of-session message: ${f.message}`)}}var uo=co(import.meta.url),fo=G.dirname(G.dirname(uo)),Ne=process.env.DATA_DIR?G.resolve(process.env.DATA_DIR,"collected-profiles"):G.join(fo,"collected-profiles"),Le=G.join(Ne,"run-log.json");function mo(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 Vt(){try{if(!j.existsSync(Le))return{runs:[]};let e=JSON.parse(j.readFileSync(Le,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Ht(e){j.existsSync(Ne)||j.mkdirSync(Ne,{recursive:!0});try{mo(Le,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function Wt(e,t="default"){let n=Vt();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),Ht(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=Vt(),l=i.runs[e.runIndex];if(l&&l.status==="running"&&l.script===e.script)l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=n,l.error=o,r=l.duration;else{let a=i.runs.find(f=>f.script===e.script&&f.status==="running"&&f.timestamp===new Date(e.startTime).toISOString());a&&(a.status=t,a.result=t,a.duration=Date.now()-e.startTime,a.stats=n,a.error=o,r=a.duration)}Ht(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";Bt({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(l=>console.error(`[runLog] postRunReport failed: ${l.message}`))}}import"dotenv/config";import*as u from"fs";import*as We from"os";import*as S from"path";import{fileURLToPath as Fo}from"url";var qe={};fe(qe,{NAME:()=>ho,VERSION:()=>po,up:()=>wo});import*as N from"fs";import*as Se from"path";var po=1,ho="normalize-jobs-and-questions",go=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],yo=50;function Me(e){return N.existsSync(e)?JSON.parse(N.readFileSync(e,"utf-8")):null}function Pe(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{N.writeFileSync(o,n)}catch(r){try{N.unlinkSync(o)}catch{}throw r}try{N.renameSync(o,e)}catch(r){try{N.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 wo(e,t){let n=Se.join(e,"jobs.json"),o=Se.join(t,"scouted-jobs.json"),r=Se.join(e,"application-questions.json"),s=Me(n)||{},i=Me(o)||{},l=0,a=[];for(let c of Object.keys(s)){if(!i[c])continue;let m=i[c],d=s[c];for(let p of go)m[p]!=null&&d[p]==null&&(d[p]=m[p]);a.push(c),l++}l>0?(Pe(n,s),console.log(` Phase 1: Merged ${l} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let f=Me(r);if(f&&Array.isArray(f.applications)){let c={},m=0;for(let d of f.applications){let p=d.jobId||"unknown";c[p]||(c[p]={applications:[]});let v=(d.questions||[]).map(w=>{let E={type:w.type||"input",question:w.question||"",answer:w.answer||""};return w.options&&(w.options.length<=yo?E.options=w.options:(E.optionsOmitted=!0,m++)),w.page&&(E.page=w.page),w.wasPreFilled&&(E.wasPreFilled=!0),w.wasRetry&&(E.wasRetry=!0),E});c[p].applications.push({applicationId:d.applicationId,date:d.date,result:d.result||"submitted",formPages:d.formPages||null,duration:d.duration||null,retries:d.retries||0,failedField:d.failedField||null,questionCount:d.questionCount||v.length,questions:v})}Pe(r,c),console.log(` Phase 2: Rekeyed ${f.applications.length} applications by jobId (${Object.keys(c).length} unique jobs)`),m>0&&console.log(` Phase 2: Stripped bloated options from ${m} questions`)}else f&&!f.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(a.length>0){for(let c of a)delete i[c];Pe(o,i),console.log(` Phase 3: Removed ${a.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var Ue={};fe(Ue,{NAME:()=>So,VERSION:()=>bo,up:()=>Co});import*as L from"fs";import*as Jt from"path";var bo=2,So="reset-unread-flags";function vo(e){return L.existsSync(e)?JSON.parse(L.readFileSync(e,"utf-8")):null}function ko(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 Co(e){let t=Jt.join(e,"conversations.json"),n=vo(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}ko(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:()=>xo,up:()=>To});import*as F from"fs";import*as Gt from"path";var xo=3,$o="recompute-last-message-by",Eo=new Set(["draft","confirmed","rejected","needs_review"]);function Ao(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}}function Io(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!Eo.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 To(e){let t=Gt.join(e,"conversations.json"),n=Ao(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 l of Object.keys(n)){let a=n[l];if(!a||typeof a!="object")continue;Object.prototype.hasOwnProperty.call(a,"_cardSynced")&&(delete a._cardSynced,s++);let f=Array.isArray(a.messages)?a.messages:[],c=Io(f,o),m=c==="me"?"awaiting_reply":"unanswered_by_us";a.lastMessageBy!==c&&i++,a.lastMessageBy=c,a.conversationStatus=m,r++}if(r===0){console.log(" No conversations to recompute.");return}_o(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:()=>Do,VERSION:()=>Ro,up:()=>Lo});import*as M from"fs";import*as Yt from"path";var Ro=4,Do="split-connection-timestamps",Oo=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function jo(e){if(!M.existsSync(e))return null;let t=M.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function No(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}}async function Lo(e){let t=Yt.join(e,"people.json"),n=jo(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++,Oo.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}No(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 Mo=Fo(import.meta.url),Po=S.dirname(Mo),qo=S.dirname(S.dirname(Po));function Uo(e){return e&&(e==="~"?We.homedir():e.startsWith("~/")||e.startsWith("~\\")?S.join(We.homedir(),e.slice(2)):e)}var q=process.env.DATA_DIR?S.resolve(Uo(process.env.DATA_DIR)):qo,se=S.join(q,"collected-profiles"),ie=S.join(q,"market-research"),T=S.join(q,".schema-version"),Kt=[S.join(se,".schema-version"),S.join(ie,".schema-version")],Y=4,B=[{version:1,module:qe},{version:2,module:Ue},{version:3,module:Be},{version:4,module:Ve}];(function(){B.sort((o,r)=>o.version-r.version);let t=new Set;for(let o of B){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=B.length?B[B.length-1].version:0;if(n!==Y)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${Y}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<B.length;o++){let r=o+1;if(B[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${B[o].version}`)}})();function Xt(){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{u.mkdirSync(q,{recursive:!0})}catch(t){t.code!=="EEXIST"&&(console.error(`
|
|
249
249
|
[FATAL] Cannot create DATA_DIR (${q}): ${t.message}`),console.error(` Fix the path or permissions and try again.
|
|
@@ -265,11 +265,11 @@ ${o.join(`
|
|
|
265
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=Wo(e);return t===null&&(console.error(`
|
|
267
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 en(e){try{u.chmodSync(e,384)}catch{}}function Jo(e){if(Xt(),u.existsSync(T))try{if(u.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{u.writeFileSync(t,JSON.stringify(e,null,2)),en(t),u.renameSync(t,T)}catch(n){try{u.unlinkSync(t)}catch{}throw n}}function Zt(e,t){if(!u.existsSync(e))return;let n=`.pre-v${String(t).padStart(3,"0")}.backup`,o=u.readdirSync(e).filter(l=>{let a=l.toLowerCase();if(a.includes(".backup")||a===".schema-version"||a.endsWith(".tmp"))return!1;try{return u.statSync(S.join(e,l)).isFile()}catch{return!1}}),r=0,s=0,i=[];for(let l of o){let a=S.join(e,l),f=S.join(e,l+n);if(u.existsSync(f)){s++;continue}try{nn(a,f),r++}catch(c){i.push({file:l,err:c.message})}}if(i.length>0){let l=new Error(`Failed to back up ${i.length} file(s) in ${S.basename(e)}/: `+i.map(a=>`${a.file} (${a.err})`).join(", "));throw l.code="BACKUP_INCOMPLETE",l}if(r>0||s>0){let l=s>0?` (${s} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${r} files in ${S.basename(e)}/ (${n})${l}`)}}var He=!1;async function tn(){if(He)return;Xt(),Qo();let t=Qt().version;if(t===
|
|
269
|
-
[FATAL] Your data schema is at v${t}, but this plugin build only understands up to v${
|
|
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${
|
|
268
|
+
`),process.exit(1)),t}function en(e){try{u.chmodSync(e,384)}catch{}}function Jo(e){if(Xt(),u.existsSync(T))try{if(u.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{u.writeFileSync(t,JSON.stringify(e,null,2)),en(t),u.renameSync(t,T)}catch(n){try{u.unlinkSync(t)}catch{}throw n}}function Zt(e,t){if(!u.existsSync(e))return;let n=`.pre-v${String(t).padStart(3,"0")}.backup`,o=u.readdirSync(e).filter(l=>{let a=l.toLowerCase();if(a.includes(".backup")||a===".schema-version"||a.endsWith(".tmp"))return!1;try{return u.statSync(S.join(e,l)).isFile()}catch{return!1}}),r=0,s=0,i=[];for(let l of o){let a=S.join(e,l),f=S.join(e,l+n);if(u.existsSync(f)){s++;continue}try{nn(a,f),r++}catch(c){i.push({file:l,err:c.message})}}if(i.length>0){let l=new Error(`Failed to back up ${i.length} file(s) in ${S.basename(e)}/: `+i.map(a=>`${a.file} (${a.err})`).join(", "));throw l.code="BACKUP_INCOMPLETE",l}if(r>0||s>0){let l=s>0?` (${s} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${r} files in ${S.basename(e)}/ (${n})${l}`)}}var He=!1;async function tn(){if(He)return;Xt(),Qo();let t=Qt().version;if(t===Y){He=!0;return}Vo(),Bo(),process.on("exit",Je),t>Y&&(console.error(`
|
|
269
|
+
[FATAL] Your data schema is at v${t}, but this plugin build only understands up to v${Y}.`),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
|
+
`),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${Y}.
|
|
271
271
|
`),process.exit(1)),console.log(`
|
|
272
|
-
\u{1F4E6} Schema migration: v${t} \u2192 v${
|
|
272
|
+
\u{1F4E6} Schema migration: v${t} \u2192 v${Y}`);let n=Zo();if(!n.ok){console.error(`
|
|
273
273
|
[FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let r of n.broken)console.error(` ${r.dir}/${r.file}: ${r.err}`);console.error(`
|
|
274
274
|
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'.
|
|
275
275
|
`),process.exit(1)}let o=B.filter(r=>r.version>t);for(let r of o){console.log(`
|
|
@@ -282,8 +282,8 @@ ${o.join(`
|
|
|
282
282
|
`)}process.exit(1)}try{let a=new Date().toISOString(),f={version:r.version,name:l.NAME||s,appliedAt:a},c=Qt();c.version=r.version,c.migratedAt=a,c.migrations=c.migrations||[],c.migrations.push(f),Jo(c)}catch(a){console.error(`
|
|
283
283
|
[FATAL] Migration ${s} applied successfully but schema version file could NOT be updated: ${a.message}`),console.error(` Your data is in the v${r.version} state but .schema-version still shows v${t}.`),console.error(` On next plugin command the runner will try to re-apply ${s}. If that migration is`),console.error(` idempotent (most are), it will succeed harmlessly. If you're unsure, run 'data-cleanup' and contact support.
|
|
284
284
|
`),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{_t()}catch{}try{Lt()}catch{}He=!0,Je(),console.log(`
|
|
285
|
-
\u2713 Schema is now at v${
|
|
286
|
-
`)}var
|
|
285
|
+
\u2713 Schema is now at v${Y}
|
|
286
|
+
`)}var Go=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Yo(e){let t=e.toLowerCase();return Go.some(n=>n.test(t))}var Ko=6e4;function zo(){let e=Date.now(),t=[];for(let n of[q,se,ie]){if(!u.existsSync(n))continue;let o;try{o=u.readdirSync(n)}catch{continue}for(let r of o){if(!Yo(r))continue;let s=S.join(n,r);try{let i=u.statSync(s);if(!i.isFile()||e-i.mtimeMs<Ko)continue;t.push({dir:n,file:r,fullPath:s})}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 n=0;for(let o of t)try{u.unlinkSync(o.fullPath),n++,e&&console.log(` Removed orphan: ${S.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 Zo(){let e=[];for(let t of[se,ie]){if(!u.existsSync(t))continue;let n=u.readdirSync(t).filter(o=>{let r=o.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let o of n){let r=S.join(t,o);try{ve(r)}catch(s){e.push({dir:S.basename(t),file:o,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function Xo(e){let t=[],n=[];for(let s of[se,ie]){if(!u.existsSync(s))continue;let i=u.readdirSync(s).filter(l=>l.endsWith(e));for(let l of i){let a=S.join(s,l),f=l.slice(0,-e.length),c=S.join(s,f);try{f.toLowerCase().endsWith(".json")?ve(a):u.accessSync(a,u.constants.R_OK),t.push({backupPath:a,originalPath:c,fileName:l,dir:s})}catch(m){n.push(`${S.basename(s)}/${l}: ${m.message}`)}}}if(n.length>0)return{ok:!1,error:n.join("; "),restored:0};let o=0,r=[];for(let{backupPath:s,originalPath:i,fileName:l,dir:a}of t)try{nn(s,i),o++}catch(f){r.push(`${S.basename(a)}/${l}: ${f.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:o}:{ok:!0,restored:o}}function nn(e,t){let n=t+".tmp";try{u.copyFileSync(e,n),en(n)}catch(o){try{u.unlinkSync(n)}catch{}throw o}try{u.renameSync(n,t)}catch(o){try{u.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 tn();var K=process.argv.slice(2),ke=parseInt(K.find(e=>e.startsWith("--max="))?.split("=")[1]||"10"),ye=K.includes("--connections"),on=K.find(e=>e.startsWith("--match-title="))?.split("=").slice(1).join("=")||null,A=on?or(on):null,er=K.includes("--list"),tr=K.includes("--verbose"),Ge=K.includes("--with-experience"),nr=K.includes("--help")||K.includes("-h");nr&&(console.log(`
|
|
287
287
|
enrich-profiles \u2014 batch-visit contacts in people.json missing About text
|
|
288
288
|
|
|
289
289
|
USAGE
|
|
@@ -326,12 +326,12 @@ WHEN TO USE
|
|
|
326
326
|
- You want to backfill in a controlled batch (\u2264 10 per day) before reaching
|
|
327
327
|
out, so AI drafting has full context.
|
|
328
328
|
- Use --connections to keep ban risk low.
|
|
329
|
-
`),process.exit(0));function or(e){try{return new RegExp(e,"i")}catch(t){console.error(`Invalid regex for --match-title: ${t.message}`),process.exit(1)}}var rr=new Set(["pending","sent_with_note","sent_without_note"]);function sr(e){return!e.about||!e.about.trim()}function ir(e){return!rr.has(e.connectionStatus)}function rn(){let e=J(),t=
|
|
329
|
+
`),process.exit(0));function or(e){try{return new RegExp(e,"i")}catch(t){console.error(`Invalid regex for --match-title: ${t.message}`),process.exit(1)}}var rr=new Set(["pending","sent_with_note","sent_without_note"]);function sr(e){return!e.about||!e.about.trim()}function ir(e){return!rr.has(e.connectionStatus)}function rn(){let e=J(),t=Re(),n=new Set,o=new Set;for(let l of Object.values(t))l.profileUrl&&n.add(l.profileUrl),(l.unread===!0||l.actionNeeded==="reply"||l.situation==="needs_our_reply"||l.conversationStatus==="unanswered_by_us")&&l.profileUrl&&o.add(l.profileUrl);let s=Object.entries(e).filter(([l,a])=>l&&l.startsWith("http")).filter(([,l])=>sr(l)).filter(([,l])=>ir(l)).filter(([l])=>!o.has(l)).map(([l,a])=>({profileUrl:l,name:a.name,person:a,hasConversation:n.has(l)}));ye&&(s=s.filter(l=>l.person.connectionStatus==="connected")),A&&(s=s.filter(l=>A.test(l.person.title||"")));function i(l){let a=l.person.connectionStatus==="connected";return a&&l.hasConversation?1:a?2:A&&A.test(l.person.title||"")?3:l.hasConversation?4:5}return s.sort((l,a)=>{let f=i(l),c=i(a);if(f!==c)return f-c;let m=l.person.lastFullVisitAt||"",d=a.person.lastFullVisitAt||"";return m.localeCompare(d)}),s.map(l=>({profileUrl:l.profileUrl,name:l.name,source:"enrich-profile"}))}function lr(){let e=J(),t=Object.keys(e).length,n=Object.values(e).filter(m=>m.about&&m.about.trim()).length,o=t-n,r=rn(),s={connWithConv:0,conn:0,titleMatch:0,withConv:0,other:0},i=e,l=Re(),a=new Set(Object.values(l).map(m=>m.profileUrl).filter(Boolean)),f=Object.values(l).filter(m=>m.profileUrl&&(m.unread===!0||m.actionNeeded==="reply"||m.situation==="needs_our_reply"||m.conversationStatus==="unanswered_by_us")).length,c=0;for(let m of r){let d=i[m.profileUrl],p=d.connectionStatus==="connected",v=A&&A.test(d.title||""),w=a.has(m.profileUrl);d.lastFullVisitAt||c++,p&&w?s.connWithConv++:p?s.conn++:v?s.titleMatch++:w?s.withConv++:s.other++}console.log(`
|
|
330
330
|
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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": ${n} (${(n/t*100).toFixed(1)}%)`),console.log(` Missing "about": ${o}`),console.log(` Skipped (needs reply): ${f}`),console.log(` Visitable (queue): ${r.length}`),console.log(` Never fully visited: ${c} (gone first)`),A&&console.log(` Title-match filter: /${A.source}/i`),ye&&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): ${s.connWithConv}`),console.log(` Tier 2 (connection): ${s.conn}`),console.log(` Tier 3 (title match): ${s.titleMatch}${A?"":" (no --match-title set)"}`),console.log(` Tier 4 (conversation): ${s.withConv}`),console.log(` Tier 5 (other): ${s.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 ${ke}/day \u2192 ~${Math.ceil(r.length/ke)} days to clear queue
|
|
331
331
|
`)}function ar(){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 cr(){if(console.log(`
|
|
332
332
|
LinkedIn Profile Enricher
|
|
333
|
-
`),er){lr();return}ar(),
|
|
334
|
-
`);return}let t=ye&&A?"connections+title":ye?"connections":A?`title=${A.source}`:"all",n=Wt("enrich-profiles",t),{browser:o,page:r}=await kt();try{let s=await Pt(r,e,{maxVisits:ke,verbose:tr,skipRecentDays:7,extractExperience:
|
|
333
|
+
`),er){lr();return}ar(),Ge&&(console.log(""),console.log(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"),console.log(" \u2551 \u26A0 --with-experience: extra ban-risk warning \u2551"),console.log(" \u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563"),console.log(" \u2551 Each visit now does TWO page loads (main + /details/ \u2551"),console.log(" \u2551 experience/). That doubles LinkedIn's view-counter signal \u2551"),console.log(" \u2551 per profile. Keep --max low (\u226410) and run rarely. \u2551"),console.log(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"),console.log(""));let e=rn();if(console.log(` Queue size: ${e.length}`),console.log(` Max visits this session: ${ke}`),A&&console.log(` Title filter: /${A.source}/i`),ye&&console.log(" Connections only: yes"),Ge&&console.log(" With experience: yes (2\xD7 page loads per profile)"),console.log(""),e.length===0){console.log(` Nothing to enrich \u2014 every visitable profile already has "about".
|
|
334
|
+
`);return}let t=ye&&A?"connections+title":ye?"connections":A?`title=${A.source}`:"all",n=Wt("enrich-profiles",t),{browser:o,page:r}=await kt();try{let s=await Pt(r,e,{maxVisits:ke,verbose:tr,skipRecentDays:7,extractExperience:Ge}),i=J(),l=0;for(let a of e.slice(0,s.visited+s.skipped))i[a.profileUrl]?.about?.trim()&&l++;console.log(`
|
|
335
335
|
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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: ${s.visited}`),console.log(` Skipped (recent): ${s.skipped}`),console.log(` Errors: ${s.errors}`),console.log(` Have "about" now: ${l} / ${s.visited+s.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
|
|
336
336
|
`),Fe(n,"success",s)}catch(s){console.error(`
|
|
337
337
|
Error:`,s.message),Fe(n,"error",null,s.message)}finally{await o.close().catch(()=>{})}}cr().catch(e=>{console.error("Enrich-profiles failed:",e),process.exit(1)});
|