ilml-plugin-linkedin 1.20.18 → 1.20.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -1
- package/dist/applyQueue.mjs +18 -20
- package/dist/connect.mjs +72 -74
- package/dist/daily.mjs +27 -29
- package/dist/enrichProfiles.mjs +26 -28
- package/dist/funnelRunner.mjs +41 -42
- package/dist/messageBot.mjs +56 -58
- package/dist/run.mjs +28 -30
- package/dist/scout.mjs +42 -44
- package/dist/syncAll.mjs +74 -76
- package/dist/syncConnections.mjs +30 -32
- package/dist/version.mjs +1 -1
- package/dist/viewers.mjs +36 -38
- package/dist/visit.mjs +33 -35
- package/ilml-plugin.json +1 -1
- package/package.json +1 -1
package/dist/visit.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Mn=Object.defineProperty;var Y=(e,t)=>()=>(e&&(t=e(e=0)),t);var pe=(e,t)=>{for(var n in t)Mn(e,n,{get:t[n],enumerable:!0})};import T from"fs";import V from"path";function Le(){let e=process.env.ILML_SCOPE_DIR;return e?V.join(e,"plugins-state","linkedin","cookies.json"):qn}function Un(){let e=Le(),t=V.dirname(e);return t&&t!=="."&&!T.existsSync(t)&&T.mkdirSync(t,{recursive:!0}),e}function St(e){let t=Un();return T.writeFileSync(t,JSON.stringify(e)),t}function bt(){let e=Le();if(!T.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=T.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 vt(){return T.existsSync(Le())}function Bn(){let e=process.env.ILML_SCOPE_DIR;return e?V.join(e,"plugins-state","linkedin"):"."}function kt(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function Vn(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?kt(t[1]):"default"}function Ct(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return T.existsSync(t)||T.mkdirSync(t,{recursive:!0}),V.resolve(t);let n=kt(e||Vn()),o=V.join(Bn(),"chrome-profile",n);return T.existsSync(o)||T.mkdirSync(o,{recursive:!0}),V.resolve(o)}function At(e){return!T.existsSync(V.join(e,xt))}function Et(e){try{T.writeFileSync(V.join(e,xt),new Date().toISOString())}catch{}}function _t(e){let t=0;for(let n of["SingletonLock","SingletonCookie","SingletonSocket"])try{T.rmSync(V.join(e,n),{force:!0}),t++}catch{}return t}var qn,xt,Ee=Y(()=>{qn="cookies.json";xt=".ilml-seeded"});async function x(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function Hn(e,t,{timeout:n=45e3,poll:o=1e3,label:r="page"}={}){let s=Date.now();for(;Date.now()-s<n;){try{if(await e.evaluate(a=>!!document.querySelector(a),t)){let a=Date.now()-s;return a>6e3&&console.log(` (waited ${Math.round(a/1e3)}s for LinkedIn to finish loading ${r})`),!0}}catch{}await new Promise(i=>setTimeout(i,o))}return!1}function Jn(e){return It.test(e||"")}async function Wn(e,{credentialWaitMs:t=36e4,label:n="page"}={}){console.log(` \u26A0 Auth wall on ${n} \u2014 attempting self-recovery (cookies may just need a refresh)...`);try{await e.goto("https://www.linkedin.com/feed/",{waitUntil:"domcontentloaded",timeout:6e4})}catch{}let o=!!(process.stdin&&process.stdin.isTTY),r=o?t:Math.min(t,45e3),s=Date.now(),i=!1;for(;Date.now()-s<r;){let l="wait";try{l=await e.evaluate(d=>!new RegExp(d).test(location.href)&&document.querySelector("#global-nav, nav.global-nav")?"in":document.querySelector('input#username, input[name="session_key"], input#password')?"creds":"wait",It.source)}catch{}if(l==="in"){try{let d=await e.cookies();if(Array.isArray(d)&&d.some(p=>p.name==="li_at")){let p=St(d);console.log(` \u2713 Session recovered \u2014 re-saved ${d.length} cookies (${p}).`)}else console.log(" \u2713 Session recovered (kept existing cookie snapshot \u2014 refreshed set had no li_at).")}catch(d){console.log(` \u2713 Session recovered (cookie re-save skipped: ${d.message}).`)}return!0}if(l==="creds"){if(!o){let d=new Error(`Session expired (${n}) \u2014 credentials required and no interactive terminal. Run: ilml linkedin login`);throw d.code="SESSION_EXPIRED",d}i||(i=!0,console.log(`
|
|
2
2
|
\u26A0 LinkedIn is asking for your login + password (cookies not enough this time).`),console.log(" \u2192 Sign in MANUALLY in the browser window that is already open."),console.log(` I will wait and resume automatically \u2014 do NOT close the window or re-run the command.
|
|
3
|
-
`))}await new Promise(d=>setTimeout(d,2500))}let a=new Error(`Session expired (${n}) \u2014 not signed in within the wait window. Run: ilml linkedin login`);throw a.code="SESSION_EXPIRED",a}async function It(e,{readySelector:t,label:n="page",timeout:o=45e3}={}){let r=await Jn(e,t,{timeout:o,label:n});if(!r&&Wn(e.url())){let s=new Error(`Session expired (${n}) \u2014 redirected to login. Run: ilml linkedin login`);throw s.code="SESSION_EXPIRED",s}return r}async function ce(e,t,{readySelector:n,label:o="page",timeout:r=45e3,gotoTimeout:s=6e4,autoRecover:i=!0}={}){await e.goto(t,{waitUntil:"domcontentloaded",timeout:s});try{return await It(e,{readySelector:n,label:o,timeout:r})}catch(a){if(i&&a.code==="SESSION_EXPIRED"){await Gn(e,{label:o});try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:s})}catch{}return await It(e,{readySelector:n,label:o,timeout:r})}throw a}}async function Dt(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"),a=r.includes("Get hired faster")||r.includes("Get hired 2x");if(s||i||a){let l=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(l)return l.click(),{dismissed:!0,matched:r.substring(0,80)};let d=o.querySelectorAll("button");for(let c of d){let y=c.innerText?.trim().toLowerCase()||"",u=c.getAttribute("aria-label")?.toLowerCase()||"";if(y==="not now"||y==="no thanks"||y==="dismiss"||u.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 Rt,he=Y(()=>{Ee();Rt=/\/authwall|\/login|\/checkpoint|\/uas\/login/});function Kn(e){return String(e??"").split(/[,\s|]+/).map(t=>t.trim()).filter(Boolean)}function Ot(e=process.env){let t=(e.JOB_SEARCH_KEYWORDS||"").trim();if(!t)return null;let n=new URLSearchParams;n.set("keywords",t);let o=(e.JOB_SEARCH_LOCATION||"").trim();o&&n.set("location",o);let r=(e.JOB_SEARCH_GEO_ID||"").trim();r&&n.set("geoId",r);let s=parseInt(e.JOB_SEARCH_RADIUS_MILES,10);Number.isFinite(s)&&s>0&&n.set("distance",String(s)),Tt(e.JOB_SEARCH_EASY_APPLY)&&n.set("f_AL","true"),Tt(e.JOB_SEARCH_IN_NETWORK)&&n.set("f_JIYN","true");let i=Kn(e.JOB_SEARCH_COMPANY_IDS);i.length&&n.set("f_C",i.join(","));let a=(e.JOB_SEARCH_DATE_POSTED||"").trim().toLowerCase();a&&n.set("f_TPR",Yn[a]||a),n.set("origin","JOB_SEARCH_PAGE_JOB_FILTER");let l="https://www.linkedin.com/jobs/search/?"+n.toString(),d=(e.JOB_SEARCH_EXTRA_PARAMS||"").trim().replace(/^[?&]+/,"");return d&&(l+="&"+d),l}var Yn,Tt,jt=Y(()=>{Yn={day:"r86400","24h":"r86400",today:"r86400",week:"r604800","7d":"r604800",month:"r2592000","30d":"r2592000"},Tt=e=>/^(1|true|yes|on)$/i.test(String(e??"").trim())});import{getPluginConfig as zn}from"@ilivemylife/graph-sdk";var Qn,Nt,Xn,Z,Qr,Zn,Pe=Y(async()=>{jt();Qn=await zn();for(let[e,t]of Object.entries(Qn))process.env[e]===void 0&&(process.env[e]=t);Nt=Ot(process.env);Nt&&(process.env.LINKEDIN_SEARCH_URL=Nt);Xn=process.env.LINKEDIN_NAME,Z=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Qr=Object.freeze(new Set([Z.DRAFT,Z.CONFIRMED,Z.NEEDS_REVIEW])),Zn=Object.freeze(new Set([Z.DRAFT,Z.CONFIRMED,Z.REJECTED,Z.NEEDS_REVIEW]))});import"dotenv/config";import*as A from"fs";import*as _ from"path";import{fileURLToPath as co}from"url";function zt(){ue=null,mo=null,po=null,ho=null,go=null,yo=null}function Qt(){A.existsSync(H)||A.mkdirSync(H,{recursive:!0})}function Xt(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";A.writeFileSync(o,n);for(let r=0;r<3;r++)try{A.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 Zt(e,t){if(!A.existsSync(e))return null;try{let n=JSON.parse(A.readFileSync(e,"utf-8"));try{A.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(A.existsSync(o))try{let r=JSON.parse(A.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{A.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{A.copyFileSync(e,e+".corrupted")}catch{}return null}}function wo(){return new Date().toISOString().split("T")[0]}function ee(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function Wt(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function en(e,t,n=null){if(!t||e[t])return t;let o=ee(t);if(!o)return t;let r=null;for(let[s,i]of Object.entries(e)){if(ee(i.profileUrl||s)===o)return s;!r&&Array.isArray(i.aliases)&&i.aliases.includes(o)&&(r=s)}if(r){let s=Wt(n),i=Wt(e[r].name);if(s&&i&&s===i)return r}return t}function vo(){A.existsSync(Ue)||A.mkdirSync(Ue,{recursive:!0})}function tn(e){let t=ee(e);return t?_.join(Ue,`${t}.json`):null}function ko(e){let t=tn(e);return t?Zt(t,`profile-history/${ee(e)}.json`)||[]:[]}function Co(e,t){let n=tn(e);if(!n)return;vo();let o=ko(e);o.unshift(t);try{Xt(n,o)}catch(r){console.error(`[!] Failed to append profile-history for ${ee(e)}: ${r.message}`)}}function Gt(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function Yt(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function xo(e,t){if(!e)return[];let n=[];for(let o of bo){let r=e[o],s=t[o];Gt(r)||Gt(s)||Yt(r)!==Yt(s)&&n.push(o)}return n}function Ao(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 de(){return ue||(Qt(),ue=Zt(qe,"people.json")||{},ue)}function nn(e){Qt(),ue=e;try{Xt(qe,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${_.resolve(qe)}`)}}function Be(e,t={}){if(!e)return null;let n=de(),o=wo(),r=new Date().toISOString(),s=en(n,e,t.name),i=n[s];if(i){let a=xo(i,t);a.length>0&&(Co(s,{capturedAt:r,previousLastUpdated:i.lastUpdated||null,changedFields:a,snapshot:Ao(i)}),i.lastSnapshotAt=r),i.seenCount=(i.seenCount||1)+1,i.lastSeen=o,i.lastUpdated=r,t.source&&!i.sources?.includes(t.source)&&(i.sources=i.sources||[],i.sources.push(t.source));for(let l of So)if(t[l]!=null){if(Array.isArray(t[l])&&t[l].length===0&&Array.isArray(i[l])&&i[l].length>0)continue;i[l]=t[l]}Array.isArray(t.availableSections)&&(i.lastFullVisitAt=r)}else n[s]={name:t.name||null,title:t.title||null,location:t.location||null,company:t.company||null,about:t.about||null,connectionDegree:t.connectionDegree||null,connectionsCount:t.connectionsCount||null,mutualConnections:t.mutualConnections||null,photoUrl:t.photoUrl||null,hasVerifiedBadge:t.hasVerifiedBadge||!1,currentCompany:t.currentCompany||null,currentSchool:t.currentSchool||null,connectionsLevel:t.connectionsLevel||null,mutualConnectionsCount:t.mutualConnectionsCount||null,followers:t.followers||null,openToWork:t.openToWork||!1,hiring:t.hiring||!1,topSkills:t.topSkills||null,availableSections:t.availableSections||null,experience:t.experience||null,featuredLinks:t.featuredLinks||null,_lastEnrichedAt:t._lastEnrichedAt||null,featured:t.featured||null,education:t.education||null,skillsFull:t.skillsFull||null,recommendations:t.recommendations||null,certifications:t.certifications||null,firstSeen:o,lastSeen:o,seenCount:1,sources:t.source?[t.source]:[],connectionStatus:null,requestedConnectionAt:null,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:r,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?r:null};return nn(n),n[s]}function Ve(e,t,n={}){if(n.dryRun||!e||!t)return;let o=ee(t);if(!o)return;let r=de(),s=en(r,e),i=r[s];if(!i)return;let a=ee(i.profileUrl||s);o!==a&&(Array.isArray(i.aliases)||(i.aliases=[]),i.aliases.includes(o)||(i.aliases.push(o),i.lastUpdated=new Date().toISOString(),nn(r)))}var uo,fo,H,qe,ws,Ss,bs,vs,ks,Ue,Kt,Cs,xs,ue,mo,po,ho,go,yo,So,bo,$e=Y(async()=>{await Pe();uo=co(import.meta.url),fo=_.dirname(_.dirname(uo)),H=process.env.DATA_DIR?_.resolve(process.env.DATA_DIR,"collected-profiles"):_.join(fo,"collected-profiles"),qe=_.join(H,"people.json"),ws=_.join(H,"jobs.json"),Ss=_.join(H,"quota.json"),bs=_.join(H,"conversations.json"),vs=_.join(H,"sync-state.json"),ks=_.join(H,"application-questions.json"),Ue=_.join(H,"profile-history"),Kt=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},Cs=Kt(process.env.CONNECT_MAX_DAILY,20),xs=Kt(process.env.CONNECT_MAX_WEEKLY,100),ue=null,mo=null,po=null,ho=null,go=null,yo=null;So=["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"],bo=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"]});var on={};pe(on,{extractCertificationsFromDetails:()=>Ro,extractEducationFromDetails:()=>$o,extractExperienceFromDetails:()=>Eo,extractFeaturedFromDetails:()=>_o,extractRecommendationsFromDetails:()=>Do,extractSkillsFromDetails:()=>Io});async function Eo(e,t){let n=t.replace(/\/+$/,"")+"/details/experience/";try{await ce(e,n,{readySelector:"main .pvs-list, .scaffold-layout__main, main.scaffold-layout__main, section.artdeco-card",label:"experience details"}),await x(1e3);let o=e.url();if(!o.toLowerCase().includes("/details/experience/"))throw new Error(`Section /details/experience/ not available on profile (landed on ${o})`);for(let s=0;s<5;s++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await x(900);await x(1e3);let r=0;for(;r<5&&await e.evaluate(()=>{for(let i of document.querySelectorAll("button"))if(/^Load more$/i.test((i.textContent||"").trim()))return i.click(),!0;return!1});)r++,await x(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await x(700);return await e.evaluate(()=>{let s=document.querySelector("main");if(!s)return[];function i(c){let y=[];for(let u of c.querySelectorAll("div")){let m=Array.from(u.children).filter(b=>b.tagName==="DIV");if(m.length<3)continue;let C=m.filter(b=>(b.textContent||"").trim().length>50);C.length<3||(u.textContent||"").length<500||y.push({el:u,count:C.length,totalText:(u.textContent||"").length})}return y.sort((u,m)=>m.count-u.count||u.totalText-m.totalText),y[0]?.el}let a=i(s);if(!a)return[];let l=Array.from(a.children).filter(c=>c.tagName==="DIV").filter(c=>(c.textContent||"").trim().length>50);function d(c){let y=c[0]||null,u=null,m=null;if(c[1]){let v=c[1].split("\xB7").map(I=>I.trim());u=v[0]||null,v[1]&&(m=v[1])}let C=c.findIndex(v=>/(\d{4}|present)/i.test(v)&&/(-|–|—)/i.test(v)&&v.length<80),b=null,$=null;if(C>=0){let v=c[C].split("\xB7").map(I=>I.trim());b=v[0]||null,v[1]&&($=v[1])}let g=null,h=-1;if(C>=0&&c[C+1]){let v=c[C+1],I=/^[>*\-•]|^>/.test(v),le=/https?:\/\//.test(v),ae=/\d{4}/.test(v),R=/,/.test(v)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(v);!I&&!le&&!ae&&v.length<100&&R&&(g=v,h=C+1)}let B=null,E=-1,Q=c[c.length-1];if(Q&&/and\s+\+\d+\s+skills?$/i.test(Q)){E=c.length-1;let v=Q.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);v&&(B={listed:v[1].split(",").map(I=>I.trim()),additional:parseInt(v[2],10)})}let X=new Set([0,1,C,h,E].filter(v=>v>=0)),W=c.filter((v,I)=>!X.has(I)),O=W.length>0?W.join(`
|
|
3
|
+
`))}await new Promise(d=>setTimeout(d,2500))}let a=new Error(`Session expired (${n}) \u2014 not signed in within the wait window. Run: ilml linkedin login`);throw a.code="SESSION_EXPIRED",a}async function $t(e,{readySelector:t,label:n="page",timeout:o=45e3}={}){let r=await Hn(e,t,{timeout:o,label:n});if(!r&&Jn(e.url())){let s=new Error(`Session expired (${n}) \u2014 redirected to login. Run: ilml linkedin login`);throw s.code="SESSION_EXPIRED",s}return r}async function ce(e,t,{readySelector:n,label:o="page",timeout:r=45e3,gotoTimeout:s=6e4,autoRecover:i=!0}={}){await e.goto(t,{waitUntil:"domcontentloaded",timeout:s});try{return await $t(e,{readySelector:n,label:o,timeout:r})}catch(a){if(i&&a.code==="SESSION_EXPIRED"){await Wn(e,{label:o});try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:s})}catch{}return await $t(e,{readySelector:n,label:o,timeout:r})}throw a}}async function Rt(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"),a=r.includes("Get hired faster")||r.includes("Get hired 2x");if(s||i||a){let l=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(l)return l.click(),{dismissed:!0,matched:r.substring(0,80)};let d=o.querySelectorAll("button");for(let c of d){let p=c.innerText?.trim().toLowerCase()||"",u=c.getAttribute("aria-label")?.toLowerCase()||"";if(p==="not now"||p==="no thanks"||p==="dismiss"||u.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 It,he=Y(()=>{Ee();It=/\/authwall|\/login|\/checkpoint|\/uas\/login/});function Yn(e){return String(e??"").split(/[,\s|]+/).map(t=>t.trim()).filter(Boolean)}function Dt(e=process.env){let t=(e.JOB_SEARCH_KEYWORDS||"").trim();if(!t)return null;let n=new URLSearchParams;n.set("keywords",t);let o=(e.JOB_SEARCH_LOCATION||"").trim();o&&n.set("location",o);let r=(e.JOB_SEARCH_GEO_ID||"").trim();r&&n.set("geoId",r);let s=parseInt(e.JOB_SEARCH_RADIUS_MILES,10);Number.isFinite(s)&&s>0&&n.set("distance",String(s)),Tt(e.JOB_SEARCH_EASY_APPLY)&&n.set("f_AL","true"),Tt(e.JOB_SEARCH_IN_NETWORK)&&n.set("f_JIYN","true");let i=Yn(e.JOB_SEARCH_COMPANY_IDS);i.length&&n.set("f_C",i.join(","));let a=(e.JOB_SEARCH_DATE_POSTED||"").trim().toLowerCase();a&&n.set("f_TPR",Gn[a]||a),n.set("origin","JOB_SEARCH_PAGE_JOB_FILTER");let l="https://www.linkedin.com/jobs/search/?"+n.toString(),d=(e.JOB_SEARCH_EXTRA_PARAMS||"").trim().replace(/^[?&]+/,"");return d&&(l+="&"+d),l}var Gn,Tt,Ot=Y(()=>{Gn={day:"r86400","24h":"r86400",today:"r86400",week:"r604800","7d":"r604800",month:"r2592000","30d":"r2592000"},Tt=e=>/^(1|true|yes|on)$/i.test(String(e??"").trim())});import{getPluginConfig as Kn}from"@ilivemylife/graph-sdk";var zn,jt,Qn,Z,es,Xn,Pe=Y(async()=>{Ot();zn=await Kn();for(let[e,t]of Object.entries(zn))process.env[e]===void 0&&(process.env[e]=t);jt=Dt(process.env);jt&&(process.env.LINKEDIN_SEARCH_URL=jt);Qn=process.env.LINKEDIN_NAME,Z=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),es=Object.freeze(new Set([Z.DRAFT,Z.CONFIRMED,Z.NEEDS_REVIEW])),Xn=Object.freeze(new Set([Z.DRAFT,Z.CONFIRMED,Z.REJECTED,Z.NEEDS_REVIEW]))});import"dotenv/config";import*as A from"fs";import*as _ from"path";import{fileURLToPath as ao}from"url";function Kt(){ue=null,fo=null,mo=null,po=null,ho=null,go=null}function zt(){A.existsSync(H)||A.mkdirSync(H,{recursive:!0})}function Qt(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";A.writeFileSync(o,n);for(let r=0;r<3;r++)try{A.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 Xt(e,t){if(!A.existsSync(e))return null;try{let n=JSON.parse(A.readFileSync(e,"utf-8"));try{A.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(A.existsSync(o))try{let r=JSON.parse(A.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{A.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{A.copyFileSync(e,e+".corrupted")}catch{}return null}}function yo(){return new Date().toISOString().split("T")[0]}function ee(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function Jt(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function Zt(e,t,n=null){if(!t||e[t])return t;let o=ee(t);if(!o)return t;let r=null;for(let[s,i]of Object.entries(e)){if(ee(i.profileUrl||s)===o)return s;!r&&Array.isArray(i.aliases)&&i.aliases.includes(o)&&(r=s)}if(r){let s=Jt(n),i=Jt(e[r].name);if(s&&i&&s===i)return r}return t}function bo(){A.existsSync(Ue)||A.mkdirSync(Ue,{recursive:!0})}function en(e){let t=ee(e);return t?_.join(Ue,`${t}.json`):null}function vo(e){let t=en(e);return t?Xt(t,`profile-history/${ee(e)}.json`)||[]:[]}function ko(e,t){let n=en(e);if(!n)return;bo();let o=vo(e);o.unshift(t);try{Qt(n,o)}catch(r){console.error(`[!] Failed to append profile-history for ${ee(e)}: ${r.message}`)}}function Wt(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function Gt(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function Co(e,t){if(!e)return[];let n=[];for(let o of So){let r=e[o],s=t[o];Wt(r)||Wt(s)||Gt(r)!==Gt(s)&&n.push(o)}return n}function xo(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 de(){return ue||(zt(),ue=Xt(qe,"people.json")||{},ue)}function tn(e){zt(),ue=e;try{Qt(qe,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${_.resolve(qe)}`)}}function Be(e,t={}){if(!e)return null;let n=de(),o=yo(),r=new Date().toISOString(),s=Zt(n,e,t.name),i=n[s];if(i){let a=Co(i,t);a.length>0&&(ko(s,{capturedAt:r,previousLastUpdated:i.lastUpdated||null,changedFields:a,snapshot:xo(i)}),i.lastSnapshotAt=r),i.seenCount=(i.seenCount||1)+1,i.lastSeen=o,i.lastUpdated=r,t.source&&!i.sources?.includes(t.source)&&(i.sources=i.sources||[],i.sources.push(t.source));for(let l of wo)if(t[l]!=null){if(Array.isArray(t[l])&&t[l].length===0&&Array.isArray(i[l])&&i[l].length>0)continue;i[l]=t[l]}Array.isArray(t.availableSections)&&(i.lastFullVisitAt=r)}else n[s]={name:t.name||null,title:t.title||null,location:t.location||null,company:t.company||null,about:t.about||null,connectionDegree:t.connectionDegree||null,connectionsCount:t.connectionsCount||null,mutualConnections:t.mutualConnections||null,photoUrl:t.photoUrl||null,hasVerifiedBadge:t.hasVerifiedBadge||!1,currentCompany:t.currentCompany||null,currentSchool:t.currentSchool||null,connectionsLevel:t.connectionsLevel||null,mutualConnectionsCount:t.mutualConnectionsCount||null,followers:t.followers||null,openToWork:t.openToWork||!1,hiring:t.hiring||!1,topSkills:t.topSkills||null,availableSections:t.availableSections||null,experience:t.experience||null,featuredLinks:t.featuredLinks||null,_lastEnrichedAt:t._lastEnrichedAt||null,featured:t.featured||null,education:t.education||null,skillsFull:t.skillsFull||null,recommendations:t.recommendations||null,certifications:t.certifications||null,firstSeen:o,lastSeen:o,seenCount:1,sources:t.source?[t.source]:[],connectionStatus:null,requestedConnectionAt:null,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:r,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?r:null};return tn(n),n[s]}function Ve(e,t,n={}){if(n.dryRun||!e||!t)return;let o=ee(t);if(!o)return;let r=de(),s=Zt(r,e),i=r[s];if(!i)return;let a=ee(i.profileUrl||s);o!==a&&(Array.isArray(i.aliases)||(i.aliases=[]),i.aliases.includes(o)||(i.aliases.push(o),i.lastUpdated=new Date().toISOString(),tn(r)))}var co,uo,H,qe,vs,ks,Cs,xs,As,Ue,Yt,Es,_s,ue,fo,mo,po,ho,go,wo,So,$e=Y(async()=>{await Pe();co=ao(import.meta.url),uo=_.dirname(_.dirname(co)),H=process.env.DATA_DIR?_.resolve(process.env.DATA_DIR,"collected-profiles"):_.join(uo,"collected-profiles"),qe=_.join(H,"people.json"),vs=_.join(H,"jobs.json"),ks=_.join(H,"quota.json"),Cs=_.join(H,"conversations.json"),xs=_.join(H,"sync-state.json"),As=_.join(H,"application-questions.json"),Ue=_.join(H,"profile-history"),Yt=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},Es=Yt(process.env.CONNECT_MAX_DAILY,20),_s=Yt(process.env.CONNECT_MAX_WEEKLY,100),ue=null,fo=null,mo=null,po=null,ho=null,go=null;wo=["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"],So=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"]});var nn={};pe(nn,{extractCertificationsFromDetails:()=>Io,extractEducationFromDetails:()=>_o,extractExperienceFromDetails:()=>Ao,extractFeaturedFromDetails:()=>Eo,extractRecommendationsFromDetails:()=>Ro,extractSkillsFromDetails:()=>$o});async function Ao(e,t){let n=t.replace(/\/+$/,"")+"/details/experience/";try{await ce(e,n,{readySelector:"main .pvs-list, .scaffold-layout__main, main.scaffold-layout__main, section.artdeco-card",label:"experience details"}),await x(1e3);let o=e.url();if(!o.toLowerCase().includes("/details/experience/"))throw new Error(`Section /details/experience/ not available on profile (landed on ${o})`);for(let s=0;s<5;s++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await x(900);await x(1e3);let r=0;for(;r<5&&await e.evaluate(()=>{for(let i of document.querySelectorAll("button"))if(/^Load more$/i.test((i.textContent||"").trim()))return i.click(),!0;return!1});)r++,await x(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await x(700);return await e.evaluate(()=>{let s=document.querySelector("main");if(!s)return[];function i(c){let p=[];for(let u of c.querySelectorAll("div")){let f=Array.from(u.children).filter(b=>b.tagName==="DIV");if(f.length<3)continue;let C=f.filter(b=>(b.textContent||"").trim().length>50);C.length<3||(u.textContent||"").length<500||p.push({el:u,count:C.length,totalText:(u.textContent||"").length})}return p.sort((u,f)=>f.count-u.count||u.totalText-f.totalText),p[0]?.el}let a=i(s);if(!a)return[];let l=Array.from(a.children).filter(c=>c.tagName==="DIV").filter(c=>(c.textContent||"").trim().length>50);function d(c){let p=c[0]||null,u=null,f=null;if(c[1]){let v=c[1].split("\xB7").map(I=>I.trim());u=v[0]||null,v[1]&&(f=v[1])}let C=c.findIndex(v=>/(\d{4}|present)/i.test(v)&&/(-|–|—)/i.test(v)&&v.length<80),b=null,$=null;if(C>=0){let v=c[C].split("\xB7").map(I=>I.trim());b=v[0]||null,v[1]&&($=v[1])}let y=null,g=-1;if(C>=0&&c[C+1]){let v=c[C+1],I=/^[>*\-•]|^>/.test(v),le=/https?:\/\//.test(v),ae=/\d{4}/.test(v),R=/,/.test(v)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(v);!I&&!le&&!ae&&v.length<100&&R&&(y=v,g=C+1)}let B=null,E=-1,Q=c[c.length-1];if(Q&&/and\s+\+\d+\s+skills?$/i.test(Q)){E=c.length-1;let v=Q.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);v&&(B={listed:v[1].split(",").map(I=>I.trim()),additional:parseInt(v[2],10)})}let X=new Set([0,1,C,g,E].filter(v=>v>=0)),W=c.filter((v,I)=>!X.has(I)),O=W.length>0?W.join(`
|
|
4
4
|
|
|
5
|
-
`):null;return{title:
|
|
6
|
-
`).map(
|
|
5
|
+
`):null;return{title:p,company:u,employmentType:f,dates:b,duration:$,location:y,description:O,skills:B,_raw:c}}return l.map(c=>{let u=(c.innerText||"").trim().split(`
|
|
6
|
+
`).map(f=>f.trim()).filter(f=>f&&f.length<5e3);return d(u)}).filter(c=>c.title)})}catch(o){if(o.code==="SESSION_EXPIRED"||/^session expired/i.test(o.message||""))throw o;return console.error(`extractExperienceFromDetails failed for ${t}: ${o.message?.slice(0,120)}`),[]}}async function we(e,t,n){let o=t.replace(/\/+$/,"")+`/details/${n}/`;await ce(e,o,{readySelector:"main .pvs-list, .scaffold-layout__main, main.scaffold-layout__main, section.artdeco-card",label:`details/${n}`}),await x(1e3);let r=e.url();if(!r.toLowerCase().includes(`/details/${n.toLowerCase()}/`))throw new Error(`Section /details/${n}/ not available on profile (landed on ${r})`);for(let i=0;i<4;i++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await x(700);await x(800);let s=0;for(;s<5&&await e.evaluate(()=>{for(let a of document.querySelectorAll("button"))if(/^Load more$/i.test((a.textContent||"").trim()))return a.click(),!0;return!1});)s++,await x(1300),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await x(600)}async function be(e,t,n,o){try{return await o()}catch(r){let s=r.message||"";if(r.code==="SESSION_EXPIRED"||/^session expired/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 Eo(e,t){return be(t,"featured","extractFeaturedFromDetails",async()=>(await we(e,t,"featured"),await e.evaluate(`(() => {
|
|
7
7
|
${Se}
|
|
8
8
|
|
|
9
9
|
const main = document.querySelector('main');
|
|
@@ -44,7 +44,7 @@ var qn=Object.defineProperty;var Y=(e,t)=>()=>(e&&(t=e(e=0)),t);var pe=(e,t)=>{f
|
|
|
44
44
|
if (e.caption && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.caption.trim())) return false;
|
|
45
45
|
return true;
|
|
46
46
|
});
|
|
47
|
-
})()`)))}async function
|
|
47
|
+
})()`)))}async function _o(e,t){return be(t,"education","extractEducationFromDetails",async()=>(await we(e,t,"education"),await e.evaluate(`(() => {
|
|
48
48
|
${Se}
|
|
49
49
|
|
|
50
50
|
const main = document.querySelector('main');
|
|
@@ -81,7 +81,7 @@ var qn=Object.defineProperty;var Y=(e,t)=>()=>(e&&(t=e(e=0)),t);var pe=(e,t)=>{f
|
|
|
81
81
|
if (e.degree && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.degree.trim())) return false;
|
|
82
82
|
return true;
|
|
83
83
|
});
|
|
84
|
-
})()`)))}async function
|
|
84
|
+
})()`)))}async function $o(e,t){return be(t,"skills","extractSkillsFromDetails",async()=>(await we(e,t,"skills"),await e.evaluate(`(() => {
|
|
85
85
|
${Se}
|
|
86
86
|
|
|
87
87
|
const main = document.querySelector('main');
|
|
@@ -113,7 +113,7 @@ var qn=Object.defineProperty;var Y=(e,t)=>()=>(e&&(t=e(e=0)),t);var pe=(e,t)=>{f
|
|
|
113
113
|
skills.push({ name, endorsements, _raw: lines });
|
|
114
114
|
}
|
|
115
115
|
return skills;
|
|
116
|
-
})()`)))}async function
|
|
116
|
+
})()`)))}async function Io(e,t){return be(t,"certifications","extractCertificationsFromDetails",async()=>(await we(e,t,"certifications"),await e.evaluate(`(() => {
|
|
117
117
|
${Se}
|
|
118
118
|
|
|
119
119
|
const main = document.querySelector('main');
|
|
@@ -138,7 +138,7 @@ var qn=Object.defineProperty;var Y=(e,t)=>()=>(e&&(t=e(e=0)),t);var pe=(e,t)=>{f
|
|
|
138
138
|
|
|
139
139
|
return { name, issuer, issueDate, expiryDate, credentialId, _raw: lines };
|
|
140
140
|
}).filter(e => e.name);
|
|
141
|
-
})()`)))}async function
|
|
141
|
+
})()`)))}async function Ro(e,t){return be(t,"recommendations","extractRecommendationsFromDetails",async()=>(await we(e,t,"recommendations"),await e.evaluate(`(() => {
|
|
142
142
|
${Se}
|
|
143
143
|
|
|
144
144
|
const main = document.querySelector('main');
|
|
@@ -174,7 +174,7 @@ var qn=Object.defineProperty;var Y=(e,t)=>()=>(e&&(t=e(e=0)),t);var pe=(e,t)=>{f
|
|
|
174
174
|
if (e.recommenderTitle && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.recommenderTitle.trim())) return false;
|
|
175
175
|
return true;
|
|
176
176
|
});
|
|
177
|
-
})()`)))}var Se,
|
|
177
|
+
})()`)))}var Se,on=Y(()=>{he();Se=`
|
|
178
178
|
function findEntryContainer(root) {
|
|
179
179
|
const candidates = [];
|
|
180
180
|
for (const div of root.querySelectorAll('div')) {
|
|
@@ -237,60 +237,58 @@ function findEntryContainer(root) {
|
|
|
237
237
|
candidates.sort((a, b) => b.count - a.count || b.totalText - a.totalText);
|
|
238
238
|
return candidates[0]?.el;
|
|
239
239
|
}
|
|
240
|
-
`});var ln=Y(()=>{});import"dotenv/config";import*as N from"fs";import*as j from"path";import{fileURLToPath as Oo}from"url";function Fo(){N.existsSync(ne)||N.mkdirSync(ne,{recursive:!0})}function Mo(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";N.writeFileSync(o,n);for(let r=0;r<3;r++)try{N.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function He(e){try{if(N.existsSync(e))return JSON.parse(N.readFileSync(e,"utf-8"))}catch{}return null}function cn(){ve=null,Uo=null,ke=null,Bo=null,te=null}function qo(){return ve||(ve=He(Lo)||{},ve)}function Ie(){return ke||(ke=He(Po)||{},ke)}function fe(){return te||(te=He(an)||{visits:[]},Array.isArray(te.visits)||(te.visits=[]),te)}function un(e,t={}){if(!e)return;Fo();let n=fe();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{Mo(an,n)}catch(r){console.error(`[!] Failed to save visit-log.json: ${r.message}`)}}function dn(e){let t=fe();for(let n=t.visits.length-1;n>=0;n--)if(t.visits[n].profileUrl===e)return t.visits[n].date;return null}function fn(){let e=qo(),t=Ie(),n=Object.values(e),o=Object.values(t),r={};for(let u of n)u.company&&(r[u.company]=(r[u.company]||0)+1);let s=Object.entries(r).sort((u,m)=>m[1]-u[1]).slice(0,5).map(([u,m])=>`${u} (${m})`),i={};for(let u of n)for(let m of u.techStack||[])i[m]=(i[m]||0)+1;let a=Object.entries(i).sort((u,m)=>m[1]-u[1]).slice(0,8).map(([u,m])=>`${u} (${m})`),l=fe(),d=new Date().toISOString().slice(0,10),c=l.visits.filter(u=>u.date.startsWith(d)).length,y=new Set(l.visits.map(u=>u.profileUrl)).size;return{totalJobs:n.length,totalRecruiters:o.length,topCompanies:s,topTech:a,totalVisited:y,todayVisited:c,lastScoutDate:n.length>0?n.sort((u,m)=>(m.scoutedAt||"").localeCompare(u.scoutedAt||""))[0]?.scoutedAt:null}}var jo,No,ne,Lo,Po,an,Bs,Vs,ve,Uo,ke,Bo,te,Re=Y(()=>{ln();jo=Oo(import.meta.url),No=j.dirname(j.dirname(jo)),ne=process.env.DATA_DIR?j.resolve(process.env.DATA_DIR,"market-research"):j.join(No,"market-research"),Lo=j.join(ne,"scouted-jobs.json"),Po=j.join(ne,"discovered-people.json"),an=j.join(ne,"visit-log.json"),Bs=j.join(ne,"companies.json"),Vs=j.join(ne,"job-decisions.json");ve=null;Uo=null,ke=null;Bo=null,te=null});import io from"puppeteer";import{addExtra as lo}from"puppeteer-extra";import ao from"puppeteer-extra-plugin-stealth";he();await Pe();Ee();Ee();import Fe from"fs";import eo from"path";var to={headless:!1,defaultViewport:null,protocolTimeout:3e5},ye=new Set,Lt=!1;async function _e(){let e=[...ye].map(t=>{try{return Promise.resolve(t.close()).catch(()=>{})}catch{return Promise.resolve()}});ye.clear(),await Promise.race([Promise.all(e),new Promise(t=>setTimeout(t,5e3))])}function no(){if(Lt)return;Lt=!0;let e=t=>async()=>{await _e(),process.exit(t)};process.once("SIGINT",e(130)),process.once("SIGTERM",e(143)),process.once("SIGHUP",e(129)),process.once("uncaughtException",async t=>{await _e(),console.error(t&&t.stack||t),process.exit(1)}),process.once("unhandledRejection",async t=>{await _e(),console.error(t),process.exit(1)}),process.stdout.on("error",async t=>{t&&t.code==="EPIPE"&&(await _e(),process.exit(0))}),process.on("exit",()=>{for(let t of ye)try{let n=t.process&&t.process();n&&n.kill("SIGKILL")}catch{}})}function Me(e){return eo.join(e,".ilml-browser-session.json")}function qt(e,t={}){try{Fe.writeFileSync(Me(e),JSON.stringify({ownerPid:process.pid,startedAt:Date.now(),...t}))}catch{}}function oo(e,t){try{let n=t.wsEndpoint&&t.wsEndpoint();qt(e,n?{wsEndpoint:n}:{})}catch{}}function ro(e){let t=Ut(e);t&&t.ownerPid===process.pid&&ge(e)}function ge(e){try{Fe.rmSync(Me(e),{force:!0})}catch{}}function Ut(e){try{return JSON.parse(Fe.readFileSync(Me(e),"utf-8"))}catch{return null}}function Pt(e){if(!e||e===process.pid)return!0;try{return process.kill(e,0),!0}catch(t){return!t||t.code!=="ESRCH"}}function Ft(e,t,n){let o,r=new Promise(i=>{o=setTimeout(()=>i(n),t)}),s=Promise.resolve(e).then(i=>(clearTimeout(o),i),i=>{throw clearTimeout(o),i});return Promise.race([s,r])}async function Mt(e,t,{probeTimeoutMs:n=4e3}={}){let o=Ut(t);if(!o)return"free";if(!o.wsEndpoint)return o.ownerPid&&o.ownerPid!==process.pid&&Pt(o.ownerPid)?"live":(ge(t),"free");let r=Symbol("timeout"),s=e.connect({browserWSEndpoint:o.wsEndpoint,defaultViewport:null}).catch(()=>null),i=await Ft(s,n,r);if(i===r)return s.then(l=>{if(l)try{l.disconnect()}catch{}}),"live";if(!i)return ge(t),"free";if(Pt(o.ownerPid)){try{i.disconnect()}catch{}return"live"}if(console.log(" (recovered an orphaned automation browser from a previous run \u2014 closing it)"),await Ft(i.close().then(()=>!0).catch(()=>!1),n,!1))return ge(t),"free";try{i.disconnect()}catch{}return"live"}function so(e,t){e&&(no(),ye.add(e),e.on("disconnected",()=>{ye.delete(e),t&&ge(t)}))}async function Bt(e,t={}){let n=xt(),o={...to,...t,userDataDir:n},r=`Could not open the LinkedIn automation Chrome profile at ${n}. Another LinkedIn automation command is already running (or its window is still open) \u2014 wait for it to finish or close that window, then retry.`;if(await Mt(e,n)==="live")throw new Error(r);qt(n);let s;try{s=await e.launch(o)}catch{if(await Mt(e,n)==="live")throw new Error(r);$t(n);try{s=await e.launch(o)}catch(a){throw ro(n),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: ${a.message})`)}}return so(s,n),oo(n,s),{browser:s,profileDir:n,needsSeed:Et(n)}}async function Vt(e,t){if(!t||!t.needsSeed)return!1;if(!kt())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(...vt()),_t(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var Ht=lo(io);Ht.use(ao());async function Jt(){let{browser:e,profileDir:t,needsSeed:n}=await Bt(Ht),o=await e.newPage();return await o.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Vt(o,{profileDir:t,needsSeed:n}),console.log(" Browser launched (persistent profile)."),{browser:e,page:o}}he();await $e();async function To(e,t){let n=e.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: ilml linkedin login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await x(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function sn(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:s=!1,extractSkills:i=!1,extractRecommendations:a=!1,extractCertifications:l=!1}=n;try{await ce(e,t,{readySelector:".scaffold-layout__main, main.scaffold-layout__main, .pv-top-card, section.pv-top-card",label:"profile"}),await x(1500),await Dt(e)&&(console.log(" Dismissed Premium overlay"),await x(1500),await To(e,t));let c=0;for(let E=0;E<2;E++){let Q=await e.evaluate(()=>document.body.scrollHeight);for(let W=1;W<=6;W++)await e.evaluate(O=>window.scrollTo(0,O),Q*W/6),await x(900);let X=await e.evaluate(()=>document.body.scrollHeight);if(X===c)break;c=X}await x(800);let y=null;try{let E=e.url();E&&/\/in\/[^/?#]/.test(E)&&(y=E.split("?")[0].replace(/\/+$/,""))}catch{}let u=await e.evaluate(()=>{let E=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),Q=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=p=>{let w=(p||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(w)},W={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},O=document.querySelector("main");if(!O)return W;let v=[...Array.from(O.querySelectorAll("h1")),...Array.from(O.querySelectorAll("h2"))],I=Array.from(O.querySelectorAll("h2")),le=v.find(p=>{let w=p.textContent&&p.textContent.trim(),S=(w||"").replace(/\s*\(\d+\)$/,"").trim();return w&&w.length>1&&w.length<100&&!E.has(S)&&!Q.has(S)}),ae=le?le.textContent.trim():null,R=le?le.parentElement:null;for(;R&&R!==O&&!Array.from(R.children).filter(w=>w.tagName==="P").some(w=>{let S=w.textContent&&w.textContent.trim();return S&&S.length>5&&!X(S)});)R=R.parentElement;let it=null,lt=null,at=null,je=null;if(R&&R!==O){let p=Array.from(R.children).filter(S=>S.tagName==="P").filter(S=>{let G=S.textContent&&S.textContent.trim();return G&&G.length>5&&!X(G)});if(p[0]&&(it=p[0].textContent.trim()),p[1]){let S=p[1].textContent.trim().split(/\s*[·•]\s*/);lt=S[0]||null,S.length>1&&(at=S.slice(1).join(" \xB7 "))}let w=Array.from(R.children).filter(S=>S.tagName==="DIV");for(let S=w.length-1;S>=0;S--){let G=w[S].textContent&&w[S].textContent.trim();if(G&&!(ae&&G.startsWith(ae))&&(je=G.split(/[·•]/)[0].trim(),je))break}}let ct=null;if(R){let p=R.querySelectorAll("p, span, div");for(let w of p){let S=(w.textContent||"").trim().replace(/^[·•]\s*/,"");if(S==="1st"||S==="2nd"||S==="3rd"){ct=S;break}}}let On=!!O.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),ut=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),jn=ut&&ut.src||null,xe=O.textContent||"",dt=null,ft=xe.match(/(\d+\+?)\s+connections\b/i);ft&&(dt=ft[1]+" connections");let Ae=null,mt=xe.match(/(\d+)\s+mutual connection/i),pt=xe.match(/and\s+(\d+)\s+other mutual/i),Nn=xe.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);mt?Ae=parseInt(mt[1],10):pt?Ae=2+parseInt(pt[1],10):Nn&&(Ae=2);let ht=null,gt=null,yt=I.find(p=>p.textContent&&p.textContent.trim()==="About");if(yt){let p=yt.parentElement;for(;p&&p.tagName!=="SECTION";)p=p.parentElement;if(p){let w=(p.textContent||"").trim();w=w.replace(/^About\s*/,"").trim();let S=w.match(/Top skills\s*(.+?)$/i);if(S){let Ne=S[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Mn=>Mn.trim()).filter(Boolean);Ne.length>0&&Ne.length<10&&(gt=Ne)}w=w.split(/\n?…\s*more/i)[0].trim(),w=w.split(/\n?\.\.\.\s*more/i)[0].trim(),w=w.split(/\bTop skills\b/i)[0].trim(),w=w.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),ht=w||null}}let wt=null,St=I.find(p=>p.textContent&&p.textContent.trim()==="Activity");if(St){let p=St.parentElement;for(;p&&p.tagName!=="SECTION";)p=p.parentElement;if(p){let w=(p.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);w&&(wt=parseInt(w[1].replace(/,/g,""),10))}}let Ln=[...new Set(I.map(p=>(p.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(p=>p&&p.length>1&&p.length<60&&p!==ae).filter(p=>E.has(p)))],me=document.body.textContent||"",Pn=/#OpenToWork\b/i.test(me)||/\bOpen to work\b/.test(me),Fn=/#Hiring\b/i.test(me)||/\bI'?m hiring\b/i.test(me)||/\bWe are hiring\b/i.test(me);return{name:ae,title:it,location:je,currentCompany:lt,currentSchool:at,connectionDegree:ct,hasVerifiedBadge:On,photoUrl:jn,connectionsLevel:dt,mutualConnectionsCount:Ae,followers:wt,openToWork:Pn,hiring:Fn,about:ht,topSkills:gt,availableSections:Ln}});console.log(`Viewed: ${u.name} - ${u.title}`);let m=null,C=null,b=null,$=null,g=null,h=null;if(o||r||s||i||a||l){let E=await Promise.resolve().then(()=>(rn(),on));o&&(m=await E.extractExperienceFromDetails(e,t),console.log(` + Experience: ${m.length} entries`)),r&&(C=await E.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${C.length} entries`)),s&&(b=await E.extractEducationFromDetails(e,t),console.log(` + Education: ${b.length} entries`)),i&&($=await E.extractSkillsFromDetails(e,t),console.log(` + Skills: ${$.length} entries`)),a&&(g=await E.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${g.length} entries`)),l&&(h=await E.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${h.length} entries`))}return{...u,profileUrl:t,resolvedUrl:y,...m!==null&&{experience:m},...C!==null&&{featured:C},...b!==null&&{education:b},...$!==null&&{skillsFull:$},...g!==null&&{recommendations:g},...h!==null&&{certifications:h}}}catch(d){console.error(`Error viewing profile ${t}:`,d.message);try{await e.goto("about:blank",{timeout:1e4}),await x(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(d.message||""))throw d;return null}}Re();await $e();he();async function mn(e,t,n={}){let{maxVisits:o=50,delayBetween:r=4e3,skipRecentDays:s=7,verbose:i=!1,extractExperience:a=!1}=n,l={visited:0,skipped:0,errors:0},d=Date.now()-s*24*60*60*1e3;for(let c of t){if(l.visited>=o)break;if(!c.profileUrl)continue;let y=dn(c.profileUrl);if(y&&new Date(y).getTime()>d){l.skipped++;continue}try{let u=await sn(e,c.profileUrl,{extractExperience:a}),m=c.source||"visit";if(u){let b={...u,source:m};a&&Array.isArray(u.experience)&&u.experience.length>0&&(b._lastEnrichedAt=new Date().toISOString()),Be(c.profileUrl,b),u.resolvedUrl&&Ve(c.profileUrl,u.resolvedUrl)}un(c.profileUrl,{name:u?.name||c.name||null,source:m}),l.visited++,i?console.log(` [${l.visited}] ${u?.name||c.profileUrl} \u2014 ${u?.title?.slice(0,40)||"?"}`):l.visited%10===0&&console.log(` Visited: ${l.visited}`);let C=Math.random()*4e3;await x(r+C)}catch(u){l.errors++,i&&console.error(` Error visiting ${c.name||c.profileUrl}: ${u.message?.slice(0,60)}`);let m=(u.message||"").toLowerCase();if(m.includes("detached")||m.includes("session closed")||m.includes("target closed")||m.includes("session expired")||m.includes("bounced to")||m.includes("authwall")||m.includes("checkpoint")||m.includes("redirected to login")){console.log(" Fatal browser/session error \u2014 stopping visits");break}}}return l}function pn(e={}){let{limit:t=150,revisitDays:n=14}=e,o=fe(),r=new Set(o.visits?.map(g=>g.profileUrl)||[]),s=new Map;for(let g of o.visits||[]){let h=s.get(g.profileUrl);(!h||g.date>h)&&s.set(g.profileUrl,g.date)}let i=Date.now()-7*24*60*60*1e3,a=Date.now()-n*24*60*60*1e3;function l(g){let h=s.get(g);return h&&new Date(h).getTime()>i}let d=Ie(),c=Object.entries(d).filter(([g])=>!r.has(g)).map(([g,h])=>({profileUrl:g,name:h.name,source:"new-discovered",priority:1,jobCount:h.jobIds?.length||0})),y=de(),u=Object.entries(y).filter(([g,h])=>h.connectionStatus==="connected"||l(g)?!1:(h.jobCount||h.jobIds?.length||0)>=2).map(([g,h])=>({profileUrl:g,name:h.name,source:"active-recruiter",priority:2,jobCount:h.jobCount||h.jobIds?.length||0})),m=Object.entries(y).filter(([g,h])=>{let B=h.connectionStatus;return!(!B||B==="connected"||B==="pending"||B==="sent_without_note"||B==="sent_with_note"||l(g)||(h.jobCount||h.jobIds?.length||0)>=2)}).map(([g,h])=>({profileUrl:g,name:h.name,source:"unconnected",priority:3,jobCount:h.jobCount||h.jobIds?.length||0})),C=[...s.entries()].filter(([g,h])=>new Date(h).getTime()<a).map(([g,h])=>({profileUrl:g,name:null,source:"revisit",priority:4,lastVisit:h})),b=g=>g.sort(()=>Math.random()-.5);return c.sort((g,h)=>h.jobCount-g.jobCount),u.sort((g,h)=>h.jobCount-g.jobCount),b(m),b(C),[...c,...u,...m,...C].slice(0,t)}function hn(){let e=Ie();return Object.entries(e).map(([t,n])=>({profileUrl:t,name:n.name,source:"discovered"}))}function Je(){let e=de();return Object.entries(e).filter(([,t])=>{let n=t.connectionStatus;return n&&n!=="connected"&&n!=="pending"&&n!=="sent_without_note"&&n!=="sent_with_note"}).map(([t,n])=>({profileUrl:t,name:n.name,source:"unconnected"}))}function We(e=14){let t=fe(),n=Date.now()-e*24*60*60*1e3,o=new Map;for(let r of t.visits){let s=o.get(r.profileUrl);(!s||r.date>s.date)&&o.set(r.profileUrl,r)}return[...o.entries()].filter(([,r])=>new Date(r.date).getTime()<n).map(([r,s])=>({profileUrl:r,name:s.name,source:"revisit"}))}Re();import"dotenv/config";import*as L from"fs";import*as K from"path";import{fileURLToPath as Yo}from"url";import"dotenv/config";import{createGraphClient as Vo,resolveToken as Ho}from"@ilivemylife/graph-sdk";import{config as Jo}from"dotenv";Jo();var gn=Ho()||process.env.TOKEN;gn||(console.error(`
|
|
240
|
+
`});var sn=Y(()=>{});import"dotenv/config";import*as N from"fs";import*as j from"path";import{fileURLToPath as Do}from"url";function Po(){N.existsSync(ne)||N.mkdirSync(ne,{recursive:!0})}function Fo(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";N.writeFileSync(o,n);for(let r=0;r<3;r++)try{N.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function He(e){try{if(N.existsSync(e))return JSON.parse(N.readFileSync(e,"utf-8"))}catch{}return null}function an(){ve=null,qo=null,ke=null,Uo=null,te=null}function Mo(){return ve||(ve=He(No)||{},ve)}function Ie(){return ke||(ke=He(Lo)||{},ke)}function fe(){return te||(te=He(ln)||{visits:[]},Array.isArray(te.visits)||(te.visits=[]),te)}function cn(e,t={}){if(!e)return;Po();let n=fe();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{Fo(ln,n)}catch(r){console.error(`[!] Failed to save visit-log.json: ${r.message}`)}}function un(e){let t=fe();for(let n=t.visits.length-1;n>=0;n--)if(t.visits[n].profileUrl===e)return t.visits[n].date;return null}function dn(){let e=Mo(),t=Ie(),n=Object.values(e),o=Object.values(t),r={};for(let u of n)u.company&&(r[u.company]=(r[u.company]||0)+1);let s=Object.entries(r).sort((u,f)=>f[1]-u[1]).slice(0,5).map(([u,f])=>`${u} (${f})`),i={};for(let u of n)for(let f of u.techStack||[])i[f]=(i[f]||0)+1;let a=Object.entries(i).sort((u,f)=>f[1]-u[1]).slice(0,8).map(([u,f])=>`${u} (${f})`),l=fe(),d=new Date().toISOString().slice(0,10),c=l.visits.filter(u=>u.date.startsWith(d)).length,p=new Set(l.visits.map(u=>u.profileUrl)).size;return{totalJobs:n.length,totalRecruiters:o.length,topCompanies:s,topTech:a,totalVisited:p,todayVisited:c,lastScoutDate:n.length>0?n.sort((u,f)=>(f.scoutedAt||"").localeCompare(u.scoutedAt||""))[0]?.scoutedAt:null}}var Oo,jo,ne,No,Lo,ln,Js,Ws,ve,qo,ke,Uo,te,Re=Y(()=>{sn();Oo=Do(import.meta.url),jo=j.dirname(j.dirname(Oo)),ne=process.env.DATA_DIR?j.resolve(process.env.DATA_DIR,"market-research"):j.join(jo,"market-research"),No=j.join(ne,"scouted-jobs.json"),Lo=j.join(ne,"discovered-people.json"),ln=j.join(ne,"visit-log.json"),Js=j.join(ne,"companies.json"),Ws=j.join(ne,"job-decisions.json");ve=null;qo=null,ke=null;Uo=null,te=null});import so from"puppeteer";import{addExtra as io}from"puppeteer-extra";import lo from"puppeteer-extra-plugin-stealth";he();await Pe();Ee();Ee();import Fe from"fs";import Zn from"path";var eo={headless:!1,defaultViewport:null,protocolTimeout:3e5},ye=new Set,Nt=!1;async function _e(){let e=[...ye].map(t=>{try{return Promise.resolve(t.close()).catch(()=>{})}catch{return Promise.resolve()}});ye.clear(),await Promise.race([Promise.all(e),new Promise(t=>setTimeout(t,5e3))])}function to(){if(Nt)return;Nt=!0;let e=t=>async()=>{await _e(),process.exit(t)};process.once("SIGINT",e(130)),process.once("SIGTERM",e(143)),process.once("SIGHUP",e(129)),process.once("uncaughtException",async t=>{await _e(),console.error(t&&t.stack||t),process.exit(1)}),process.once("unhandledRejection",async t=>{await _e(),console.error(t),process.exit(1)}),process.stdout.on("error",async t=>{t&&t.code==="EPIPE"&&(await _e(),process.exit(0))}),process.on("exit",()=>{for(let t of ye)try{let n=t.process&&t.process();n&&n.kill("SIGKILL")}catch{}})}function Me(e){return Zn.join(e,".ilml-browser-session.json")}function Mt(e,t={}){try{Fe.writeFileSync(Me(e),JSON.stringify({ownerPid:process.pid,startedAt:Date.now(),...t}))}catch{}}function no(e,t){try{let n=t.wsEndpoint&&t.wsEndpoint();Mt(e,n?{wsEndpoint:n}:{})}catch{}}function oo(e){let t=qt(e);t&&t.ownerPid===process.pid&&ge(e)}function ge(e){try{Fe.rmSync(Me(e),{force:!0})}catch{}}function qt(e){try{return JSON.parse(Fe.readFileSync(Me(e),"utf-8"))}catch{return null}}function Lt(e){if(!e||e===process.pid)return!0;try{return process.kill(e,0),!0}catch(t){return!t||t.code!=="ESRCH"}}function Pt(e,t,n){let o,r=new Promise(i=>{o=setTimeout(()=>i(n),t)}),s=Promise.resolve(e).then(i=>(clearTimeout(o),i),i=>{throw clearTimeout(o),i});return Promise.race([s,r])}async function Ft(e,t,{probeTimeoutMs:n=4e3}={}){let o=qt(t);if(!o)return"free";if(!o.wsEndpoint)return o.ownerPid&&o.ownerPid!==process.pid&&Lt(o.ownerPid)?"live":(ge(t),"free");let r=Symbol("timeout"),s=e.connect({browserWSEndpoint:o.wsEndpoint,defaultViewport:null}).catch(()=>null),i=await Pt(s,n,r);if(i===r)return s.then(l=>{if(l)try{l.disconnect()}catch{}}),"live";if(!i)return ge(t),"free";if(Lt(o.ownerPid)){try{i.disconnect()}catch{}return"live"}if(console.log(" (recovered an orphaned automation browser from a previous run \u2014 closing it)"),await Pt(i.close().then(()=>!0).catch(()=>!1),n,!1))return ge(t),"free";try{i.disconnect()}catch{}return"live"}function ro(e,t){e&&(to(),ye.add(e),e.on("disconnected",()=>{ye.delete(e),t&&ge(t)}))}async function Ut(e,t={}){let n=Ct(),o={...eo,...t,userDataDir:n},r=`Could not open the LinkedIn automation Chrome profile at ${n}. Another LinkedIn automation command is already running (or its window is still open) \u2014 wait for it to finish or close that window, then retry.`;if(await Ft(e,n)==="live")throw new Error(r);Mt(n);let s;try{s=await e.launch(o)}catch{if(await Ft(e,n)==="live")throw new Error(r);_t(n);try{s=await e.launch(o)}catch(a){throw oo(n),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: ${a.message})`)}}return ro(s,n),no(n,s),{browser:s,profileDir:n,needsSeed:At(n)}}async function Bt(e,t){if(!t||!t.needsSeed)return!1;if(!vt())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(...bt()),Et(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var Vt=io(so);Vt.use(lo());async function Ht(){let{browser:e,profileDir:t,needsSeed:n}=await Ut(Vt),o=await e.newPage();return await o.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Bt(o,{profileDir:t,needsSeed:n}),console.log(" Browser launched (persistent profile)."),{browser:e,page:o}}he();await $e();async function To(e,t){let n=e.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: ilml linkedin login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await x(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function rn(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:s=!1,extractSkills:i=!1,extractRecommendations:a=!1,extractCertifications:l=!1}=n;try{await ce(e,t,{readySelector:".scaffold-layout__main, main.scaffold-layout__main, .pv-top-card, section.pv-top-card",label:"profile"}),await x(1500),await Rt(e)&&(console.log(" Dismissed Premium overlay"),await x(1500),await To(e,t));let c=0;for(let E=0;E<2;E++){let Q=await e.evaluate(()=>document.body.scrollHeight);for(let W=1;W<=6;W++)await e.evaluate(O=>window.scrollTo(0,O),Q*W/6),await x(900);let X=await e.evaluate(()=>document.body.scrollHeight);if(X===c)break;c=X}await x(800);let p=null;try{let E=e.url();E&&/\/in\/[^/?#]/.test(E)&&(p=E.split("?")[0].replace(/\/+$/,""))}catch{}let u=await e.evaluate(()=>{let E=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),Q=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 w=(h||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(w)},W={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},O=document.querySelector("main");if(!O)return W;let v=[...Array.from(O.querySelectorAll("h1")),...Array.from(O.querySelectorAll("h2"))],I=Array.from(O.querySelectorAll("h2")),le=v.find(h=>{let w=h.textContent&&h.textContent.trim(),S=(w||"").replace(/\s*\(\d+\)$/,"").trim();return w&&w.length>1&&w.length<100&&!E.has(S)&&!Q.has(S)}),ae=le?le.textContent.trim():null,R=le?le.parentElement:null;for(;R&&R!==O&&!Array.from(R.children).filter(w=>w.tagName==="P").some(w=>{let S=w.textContent&&w.textContent.trim();return S&&S.length>5&&!X(S)});)R=R.parentElement;let st=null,it=null,lt=null,je=null;if(R&&R!==O){let h=Array.from(R.children).filter(S=>S.tagName==="P").filter(S=>{let G=S.textContent&&S.textContent.trim();return G&&G.length>5&&!X(G)});if(h[0]&&(st=h[0].textContent.trim()),h[1]){let S=h[1].textContent.trim().split(/\s*[·•]\s*/);it=S[0]||null,S.length>1&&(lt=S.slice(1).join(" \xB7 "))}let w=Array.from(R.children).filter(S=>S.tagName==="DIV");for(let S=w.length-1;S>=0;S--){let G=w[S].textContent&&w[S].textContent.trim();if(G&&!(ae&&G.startsWith(ae))&&(je=G.split(/[·•]/)[0].trim(),je))break}}let at=null;if(R){let h=R.querySelectorAll("p, span, div");for(let w of h){let S=(w.textContent||"").trim().replace(/^[·•]\s*/,"");if(S==="1st"||S==="2nd"||S==="3rd"){at=S;break}}}let Dn=!!O.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),ct=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),On=ct&&ct.src||null,xe=O.textContent||"",ut=null,dt=xe.match(/(\d+\+?)\s+connections\b/i);dt&&(ut=dt[1]+" connections");let Ae=null,ft=xe.match(/(\d+)\s+mutual connection/i),mt=xe.match(/and\s+(\d+)\s+other mutual/i),jn=xe.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);ft?Ae=parseInt(ft[1],10):mt?Ae=2+parseInt(mt[1],10):jn&&(Ae=2);let pt=null,ht=null,gt=I.find(h=>h.textContent&&h.textContent.trim()==="About");if(gt){let h=gt.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let w=(h.textContent||"").trim();w=w.replace(/^About\s*/,"").trim();let S=w.match(/Top skills\s*(.+?)$/i);if(S){let Ne=S[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Fn=>Fn.trim()).filter(Boolean);Ne.length>0&&Ne.length<10&&(ht=Ne)}w=w.split(/\n?…\s*more/i)[0].trim(),w=w.split(/\n?\.\.\.\s*more/i)[0].trim(),w=w.split(/\bTop skills\b/i)[0].trim(),w=w.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),pt=w||null}}let yt=null,wt=I.find(h=>h.textContent&&h.textContent.trim()==="Activity");if(wt){let h=wt.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let w=(h.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);w&&(yt=parseInt(w[1].replace(/,/g,""),10))}}let Nn=[...new Set(I.map(h=>(h.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(h=>h&&h.length>1&&h.length<60&&h!==ae).filter(h=>E.has(h)))],me=document.body.textContent||"",Ln=/#OpenToWork\b/i.test(me)||/\bOpen to work\b/.test(me),Pn=/#Hiring\b/i.test(me)||/\bI'?m hiring\b/i.test(me)||/\bWe are hiring\b/i.test(me);return{name:ae,title:st,location:je,currentCompany:it,currentSchool:lt,connectionDegree:at,hasVerifiedBadge:Dn,photoUrl:On,connectionsLevel:ut,mutualConnectionsCount:Ae,followers:yt,openToWork:Ln,hiring:Pn,about:pt,topSkills:ht,availableSections:Nn}});console.log(`Viewed: ${u.name} - ${u.title}`);let f=null,C=null,b=null,$=null,y=null,g=null;if(o||r||s||i||a||l){let E=await Promise.resolve().then(()=>(on(),nn));o&&(f=await E.extractExperienceFromDetails(e,t),console.log(` + Experience: ${f.length} entries`)),r&&(C=await E.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${C.length} entries`)),s&&(b=await E.extractEducationFromDetails(e,t),console.log(` + Education: ${b.length} entries`)),i&&($=await E.extractSkillsFromDetails(e,t),console.log(` + Skills: ${$.length} entries`)),a&&(y=await E.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${y.length} entries`)),l&&(g=await E.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${g.length} entries`))}return{...u,profileUrl:t,resolvedUrl:p,...f!==null&&{experience:f},...C!==null&&{featured:C},...b!==null&&{education:b},...$!==null&&{skillsFull:$},...y!==null&&{recommendations:y},...g!==null&&{certifications:g}}}catch(d){console.error(`Error viewing profile ${t}:`,d.message);try{await e.goto("about:blank",{timeout:1e4}),await x(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(d.message||""))throw d;return null}}Re();await $e();he();async function fn(e,t,n={}){let{maxVisits:o=50,delayBetween:r=4e3,skipRecentDays:s=7,verbose:i=!1,extractExperience:a=!1}=n,l={visited:0,skipped:0,errors:0},d=Date.now()-s*24*60*60*1e3;for(let c of t){if(l.visited>=o)break;if(!c.profileUrl)continue;let p=un(c.profileUrl);if(p&&new Date(p).getTime()>d){l.skipped++;continue}try{let u=await rn(e,c.profileUrl,{extractExperience:a}),f=c.source||"visit";if(u){let b={...u,source:f};a&&Array.isArray(u.experience)&&u.experience.length>0&&(b._lastEnrichedAt=new Date().toISOString()),Be(c.profileUrl,b),u.resolvedUrl&&Ve(c.profileUrl,u.resolvedUrl)}cn(c.profileUrl,{name:u?.name||c.name||null,source:f}),l.visited++,i?console.log(` [${l.visited}] ${u?.name||c.profileUrl} \u2014 ${u?.title?.slice(0,40)||"?"}`):l.visited%10===0&&console.log(` Visited: ${l.visited}`);let C=Math.random()*4e3;await x(r+C)}catch(u){l.errors++,i&&console.error(` Error visiting ${c.name||c.profileUrl}: ${u.message?.slice(0,60)}`);let f=(u.message||"").toLowerCase();if(f.includes("detached")||f.includes("session closed")||f.includes("target closed")||f.includes("session expired")||f.includes("bounced to")||f.includes("authwall")||f.includes("checkpoint")||f.includes("redirected to login")){console.log(" Fatal browser/session error \u2014 stopping visits");break}}}return l}function mn(e={}){let{limit:t=150,revisitDays:n=14}=e,o=fe(),r=new Set(o.visits?.map(y=>y.profileUrl)||[]),s=new Map;for(let y of o.visits||[]){let g=s.get(y.profileUrl);(!g||y.date>g)&&s.set(y.profileUrl,y.date)}let i=Date.now()-7*24*60*60*1e3,a=Date.now()-n*24*60*60*1e3;function l(y){let g=s.get(y);return g&&new Date(g).getTime()>i}let d=Ie(),c=Object.entries(d).filter(([y])=>!r.has(y)).map(([y,g])=>({profileUrl:y,name:g.name,source:"new-discovered",priority:1,jobCount:g.jobIds?.length||0})),p=de(),u=Object.entries(p).filter(([y,g])=>g.connectionStatus==="connected"||l(y)?!1:(g.jobCount||g.jobIds?.length||0)>=2).map(([y,g])=>({profileUrl:y,name:g.name,source:"active-recruiter",priority:2,jobCount:g.jobCount||g.jobIds?.length||0})),f=Object.entries(p).filter(([y,g])=>{let B=g.connectionStatus;return!(!B||B==="connected"||B==="pending"||B==="sent_without_note"||B==="sent_with_note"||l(y)||(g.jobCount||g.jobIds?.length||0)>=2)}).map(([y,g])=>({profileUrl:y,name:g.name,source:"unconnected",priority:3,jobCount:g.jobCount||g.jobIds?.length||0})),C=[...s.entries()].filter(([y,g])=>new Date(g).getTime()<a).map(([y,g])=>({profileUrl:y,name:null,source:"revisit",priority:4,lastVisit:g})),b=y=>y.sort(()=>Math.random()-.5);return c.sort((y,g)=>g.jobCount-y.jobCount),u.sort((y,g)=>g.jobCount-y.jobCount),b(f),b(C),[...c,...u,...f,...C].slice(0,t)}function pn(){let e=Ie();return Object.entries(e).map(([t,n])=>({profileUrl:t,name:n.name,source:"discovered"}))}function Je(){let e=de();return Object.entries(e).filter(([,t])=>{let n=t.connectionStatus;return n&&n!=="connected"&&n!=="pending"&&n!=="sent_without_note"&&n!=="sent_with_note"}).map(([t,n])=>({profileUrl:t,name:n.name,source:"unconnected"}))}function We(e=14){let t=fe(),n=Date.now()-e*24*60*60*1e3,o=new Map;for(let r of t.visits){let s=o.get(r.profileUrl);(!s||r.date>s.date)&&o.set(r.profileUrl,r)}return[...o.entries()].filter(([,r])=>new Date(r.date).getTime()<n).map(([r,s])=>({profileUrl:r,name:s.name,source:"revisit"}))}Re();import"dotenv/config";import*as L from"fs";import*as K from"path";import{fileURLToPath as Ko}from"url";import"dotenv/config";import{createGraphClient as Bo,resolveToken as Vo}from"@ilivemylife/graph-sdk";import{config as Ho}from"dotenv";Ho();var hn=Vo()||process.env.TOKEN;hn||(console.error(`
|
|
241
241
|
[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.
|
|
242
242
|
`),console.error(" Easiest way:"),console.error(" 1. npm install -g @ilivemylife/graph-sdk"),console.error(` 2. ilml login your@email.com yourpassword
|
|
243
243
|
`),console.error(` Or add ILML_TOKEN=... to .env
|
|
244
|
-
`),process.exit(1));var
|
|
245
|
-
|
|
246
|
-
${o.join(`
|
|
247
|
-
`)}`;try{await yn.addMessage(i,l)}catch(d){console.error(`[runReport] Failed to post end-of-session message: ${d.message}`)}}var Ko=Yo(import.meta.url),zo=K.dirname(K.dirname(Ko)),Ge=process.env.DATA_DIR?K.resolve(process.env.DATA_DIR,"collected-profiles"):K.join(zo,"collected-profiles"),Ye=K.join(Ge,"run-log.json");function Qo(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";L.writeFileSync(o,n);for(let r=0;r<3;r++)try{L.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 Sn(){try{if(!L.existsSync(Ye))return{runs:[]};let e=JSON.parse(L.readFileSync(Ye,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function bn(e){L.existsSync(Ge)||L.mkdirSync(Ge,{recursive:!0});try{Qo(Ye,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function vn(e,t="default"){let n=Sn();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),bn(n),{script:e,mode:t,startTime:o.getTime(),runIndex:n.runs.length-1}}function Ke(e,t,n=null,o=null){if(!e)return;let r=null;try{let i=Sn(),a=i.runs[e.runIndex];if(a&&a.status==="running"&&a.script===e.script)a.status=t,a.result=t,a.duration=Date.now()-e.startTime,a.stats=n,a.error=o,r=a.duration;else{let l=i.runs.find(d=>d.script===e.script&&d.status==="running"&&d.timestamp===new Date(e.startTime).toISOString());l&&(l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=n,l.error=o,r=l.duration)}bn(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";wn({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(a=>console.error(`[runLog] postRunReport failed: ${a.message}`))}}import"dotenv/config";import*as f from"fs";import*as ot from"os";import*as k from"path";import{fileURLToPath as vr}from"url";var Xe={};pe(Xe,{NAME:()=>Zo,VERSION:()=>Xo,up:()=>nr});import*as P from"fs";import*as De from"path";var Xo=1,Zo="normalize-jobs-and-questions",er=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],tr=50;function ze(e){return P.existsSync(e)?JSON.parse(P.readFileSync(e,"utf-8")):null}function Qe(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{P.writeFileSync(o,n)}catch(r){try{P.unlinkSync(o)}catch{}throw r}try{P.renameSync(o,e)}catch(r){try{P.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}async function nr(e,t){let n=De.join(e,"jobs.json"),o=De.join(t,"scouted-jobs.json"),r=De.join(e,"application-questions.json"),s=ze(n)||{},i=ze(o)||{},a=0,l=[];for(let c of Object.keys(s)){if(!i[c])continue;let y=i[c],u=s[c];for(let m of er)y[m]!=null&&u[m]==null&&(u[m]=y[m]);l.push(c),a++}a>0?(Qe(n,s),console.log(` Phase 1: Merged ${a} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let d=ze(r);if(d&&Array.isArray(d.applications)){let c={},y=0;for(let u of d.applications){let m=u.jobId||"unknown";c[m]||(c[m]={applications:[]});let C=(u.questions||[]).map(b=>{let $={type:b.type||"input",question:b.question||"",answer:b.answer||""};return b.options&&(b.options.length<=tr?$.options=b.options:($.optionsOmitted=!0,y++)),b.page&&($.page=b.page),b.wasPreFilled&&($.wasPreFilled=!0),b.wasRetry&&($.wasRetry=!0),$});c[m].applications.push({applicationId:u.applicationId,date:u.date,result:u.result||"submitted",formPages:u.formPages||null,duration:u.duration||null,retries:u.retries||0,failedField:u.failedField||null,questionCount:u.questionCount||C.length,questions:C})}Qe(r,c),console.log(` Phase 2: Rekeyed ${d.applications.length} applications by jobId (${Object.keys(c).length} unique jobs)`),y>0&&console.log(` Phase 2: Stripped bloated options from ${y} questions`)}else d&&!d.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(l.length>0){for(let c of l)delete i[c];Qe(o,i),console.log(` Phase 3: Removed ${l.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var Ze={};pe(Ze,{NAME:()=>rr,VERSION:()=>or,up:()=>lr});import*as F from"fs";import*as kn from"path";var or=2,rr="reset-unread-flags";function sr(e){return F.existsSync(e)?JSON.parse(F.readFileSync(e,"utf-8")):null}function ir(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{F.writeFileSync(o,n)}catch(r){try{F.unlinkSync(o)}catch{}throw r}try{F.renameSync(o,e)}catch(r){try{F.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}async function lr(e){let t=kn.join(e,"conversations.json"),n=sr(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}ir(t,n),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var et={};pe(et,{NAME:()=>cr,VERSION:()=>ar,up:()=>pr});import*as M from"fs";import*as Cn from"path";var ar=3,cr="recompute-last-message-by",ur=new Set(["draft","confirmed","rejected","needs_review"]);function dr(e){return M.existsSync(e)?JSON.parse(M.readFileSync(e,"utf-8")):null}function fr(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{M.writeFileSync(o,n)}catch(r){try{M.unlinkSync(o)}catch{}throw r}try{M.renameSync(o,e)}catch(r){try{M.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}function mr(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!ur.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 pr(e){let t=Cn.join(e,"conversations.json"),n=dr(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 a of Object.keys(n)){let l=n[a];if(!l||typeof l!="object")continue;Object.prototype.hasOwnProperty.call(l,"_cardSynced")&&(delete l._cardSynced,s++);let d=Array.isArray(l.messages)?l.messages:[],c=mr(d,o),y=c==="me"?"awaiting_reply":"unanswered_by_us";l.lastMessageBy!==c&&i++,l.lastMessageBy=c,l.conversationStatus=y,r++}if(r===0){console.log(" No conversations to recompute.");return}fr(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 tt={};pe(tt,{NAME:()=>gr,VERSION:()=>hr,up:()=>br});import*as q from"fs";import*as xn from"path";var hr=4,gr="split-connection-timestamps",yr=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function wr(e){if(!q.existsSync(e))return null;let t=q.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function Sr(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{q.writeFileSync(o,n)}catch(r){try{q.unlinkSync(o)}catch{}throw r}try{q.renameSync(o,e)}catch(r){try{q.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 br(e){let t=xn.join(e,"people.json"),n=wr(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++,yr.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}Sr(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".')}await $e();Re();var kr=vr(import.meta.url),Cr=k.dirname(kr),xr=k.dirname(k.dirname(Cr));function Ar(e){return e&&(e==="~"?ot.homedir():e.startsWith("~/")||e.startsWith("~\\")?k.join(ot.homedir(),e.slice(2)):e)}var U=process.env.DATA_DIR?k.resolve(Ar(process.env.DATA_DIR)):xr,re=k.join(U,"collected-profiles"),se=k.join(U,"market-research"),T=k.join(U,".schema-version"),An=[k.join(re,".schema-version"),k.join(se,".schema-version")],z=4,J=[{version:1,module:Xe},{version:2,module:Ze},{version:3,module:et},{version:4,module:tt}];(function(){J.sort((o,r)=>o.version-r.version);let t=new Set;for(let o of J){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=J.length?J[J.length-1].version:0;if(n!==z)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${z}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<J.length;o++){let r=o+1;if(J[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${J[o].version}`)}})();function In(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
244
|
+
`),process.exit(1));var gn=Bo({token:hn});function Jo(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`}var Wo={apply:"Job apply","apply-queue":"Job apply (queue)",scout:"Job scout",connect:"Connect run",funnel:"Recruiter funnel",messages:"Messages",sync:"Connections sync","sync-all":"Inbox sync",visit:"Profile visits",viewers:"Profile viewers",daily:"Daily run"};function Go(e){let t=String(e||"").toLowerCase();return/authwall|session expired|not logged in|re-?auth|logged out|sign ?in/.test(t)?"LinkedIn asked to sign in again. Run `ilml linkedin login`, then run this again.":/protocoltimeout|callfunctionon|target closed|session closed|detached|execution context|browser.*disconnected|connection closed/.test(t)?"The browser stopped responding partway through. This is usually temporary \u2014 just run it again.":/err_aborted|err_network|err_connection|err_name_not_resolved|net::/.test(t)?"A page failed to load (network hiccup). Try running it again in a moment.":/navigation timeout|timeout.*exceeded|waiting for selector|waiting for/.test(t)?"A page took too long to load. Try again in a moment.":/invite limit|weekly.*limit|too many|rate.?limit|quota/.test(t)?"You've reached a LinkedIn sending limit for now. Wait a while, then try again.":"Something went wrong partway through. It is safe to run the command again."}function Yo({scriptName:e,mode:t,status:n,summaryLines:o,error:r,duration:s}){let i=n==="error"?"\u2717":n==="quota-reached"?"\u26A0":"\u2713",a=n==="error"?"stopped early":n==="quota-reached"?"daily limit reached":"done",l=Wo[e]||e,d=t&&t!=="default"?` \xB7 ${t}`:"",c=new Date().toISOString().slice(0,16).replace("T"," "),p=s?` \xB7 ${Jo(s)}`:"",u=[];u.push(`## ${i} ${l} \u2014 ${a}`),u.push(`_${c}${d}${p}_`),u.push("");for(let f of o)u.push(`- ${f}`);if(n==="error"){u.push(""),u.push(`**What happened:** ${Go(r)}`);let f=String(r||"").replace(/\s+/g," ").trim();f&&u.push(`_Technical detail: ${f.slice(0,140)}_`)}return u.join(`
|
|
245
|
+
`)}async function yn({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=Yo({scriptName:e,mode:t,status:n,summaryLines:o,error:r,duration:s});try{await gn.addMessage(i,a)}catch(l){console.error(`[runReport] Failed to post end-of-session message: ${l.message}`)}}var zo=Ko(import.meta.url),Qo=K.dirname(K.dirname(zo)),Ge=process.env.DATA_DIR?K.resolve(process.env.DATA_DIR,"collected-profiles"):K.join(Qo,"collected-profiles"),Ye=K.join(Ge,"run-log.json");function Xo(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";L.writeFileSync(o,n);for(let r=0;r<3;r++)try{L.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 wn(){try{if(!L.existsSync(Ye))return{runs:[]};let e=JSON.parse(L.readFileSync(Ye,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Sn(e){L.existsSync(Ge)||L.mkdirSync(Ge,{recursive:!0});try{Xo(Ye,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function Zo(e,t="default"){let n=wn();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),Sn(n),{script:e,mode:t,startTime:o.getTime(),runIndex:n.runs.length-1}}function er(e,t,n=null,o=null){if(!e)return;let r=null;try{let i=wn(),a=i.runs[e.runIndex];if(a&&a.status==="running"&&a.script===e.script)a.status=t,a.result=t,a.duration=Date.now()-e.startTime,a.stats=n,a.error=o,r=a.duration;else{let l=i.runs.find(d=>d.script===e.script&&d.status==="running"&&d.timestamp===new Date(e.startTime).toISOString());l&&(l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=n,l.error=o,r=l.duration)}Sn(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";yn({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(a=>console.error(`[runLog] postRunReport failed: ${a.message}`))}}async function bn(e,t,n,o,r={}){let{rethrow:s=!0}=r,i=Zo(e,t),a={},l=null;try{await n(a)}catch(c){l=c}let d=[];try{let c=o?o(a):[];d=(Array.isArray(c)?c:[]).filter(p=>typeof p=="string"&&p.trim())}catch(c){console.error(`[runLog] summarize threw (report still sent): ${c.message}`)}if(d.length===0&&l&&(d=["(crashed before any progress was recorded)"]),l){let c=t&&t!=="default"?` (${t})`:"";console.error(`
|
|
246
|
+
\u2717 ${e}${c} failed: ${l.message||l}`)}try{er(i,l?"error":"success",{...a,summaryLines:d},l?l.message||String(l):null)}catch(c){console.error(`[runLog] endRun failed: ${c.message}`)}if(l&&s)throw l;return a}import"dotenv/config";import*as m from"fs";import*as nt from"os";import*as k from"path";import{fileURLToPath as xr}from"url";var Qe={};pe(Qe,{NAME:()=>nr,VERSION:()=>tr,up:()=>sr});import*as P from"fs";import*as Te from"path";var tr=1,nr="normalize-jobs-and-questions",or=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],rr=50;function Ke(e){return P.existsSync(e)?JSON.parse(P.readFileSync(e,"utf-8")):null}function ze(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{P.writeFileSync(o,n)}catch(r){try{P.unlinkSync(o)}catch{}throw r}try{P.renameSync(o,e)}catch(r){try{P.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}async function sr(e,t){let n=Te.join(e,"jobs.json"),o=Te.join(t,"scouted-jobs.json"),r=Te.join(e,"application-questions.json"),s=Ke(n)||{},i=Ke(o)||{},a=0,l=[];for(let c of Object.keys(s)){if(!i[c])continue;let p=i[c],u=s[c];for(let f of or)p[f]!=null&&u[f]==null&&(u[f]=p[f]);l.push(c),a++}a>0?(ze(n,s),console.log(` Phase 1: Merged ${a} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let d=Ke(r);if(d&&Array.isArray(d.applications)){let c={},p=0;for(let u of d.applications){let f=u.jobId||"unknown";c[f]||(c[f]={applications:[]});let C=(u.questions||[]).map(b=>{let $={type:b.type||"input",question:b.question||"",answer:b.answer||""};return b.options&&(b.options.length<=rr?$.options=b.options:($.optionsOmitted=!0,p++)),b.page&&($.page=b.page),b.wasPreFilled&&($.wasPreFilled=!0),b.wasRetry&&($.wasRetry=!0),$});c[f].applications.push({applicationId:u.applicationId,date:u.date,result:u.result||"submitted",formPages:u.formPages||null,duration:u.duration||null,retries:u.retries||0,failedField:u.failedField||null,questionCount:u.questionCount||C.length,questions:C})}ze(r,c),console.log(` Phase 2: Rekeyed ${d.applications.length} applications by jobId (${Object.keys(c).length} unique jobs)`),p>0&&console.log(` Phase 2: Stripped bloated options from ${p} questions`)}else d&&!d.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(l.length>0){for(let c of l)delete i[c];ze(o,i),console.log(` Phase 3: Removed ${l.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var Xe={};pe(Xe,{NAME:()=>lr,VERSION:()=>ir,up:()=>ur});import*as F from"fs";import*as vn from"path";var ir=2,lr="reset-unread-flags";function ar(e){return F.existsSync(e)?JSON.parse(F.readFileSync(e,"utf-8")):null}function cr(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{F.writeFileSync(o,n)}catch(r){try{F.unlinkSync(o)}catch{}throw r}try{F.renameSync(o,e)}catch(r){try{F.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}async function ur(e){let t=vn.join(e,"conversations.json"),n=ar(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}cr(t,n),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var Ze={};pe(Ze,{NAME:()=>fr,VERSION:()=>dr,up:()=>yr});import*as M from"fs";import*as kn from"path";var dr=3,fr="recompute-last-message-by",mr=new Set(["draft","confirmed","rejected","needs_review"]);function pr(e){return M.existsSync(e)?JSON.parse(M.readFileSync(e,"utf-8")):null}function hr(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{M.writeFileSync(o,n)}catch(r){try{M.unlinkSync(o)}catch{}throw r}try{M.renameSync(o,e)}catch(r){try{M.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}function gr(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!mr.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 yr(e){let t=kn.join(e,"conversations.json"),n=pr(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 a of Object.keys(n)){let l=n[a];if(!l||typeof l!="object")continue;Object.prototype.hasOwnProperty.call(l,"_cardSynced")&&(delete l._cardSynced,s++);let d=Array.isArray(l.messages)?l.messages:[],c=gr(d,o),p=c==="me"?"awaiting_reply":"unanswered_by_us";l.lastMessageBy!==c&&i++,l.lastMessageBy=c,l.conversationStatus=p,r++}if(r===0){console.log(" No conversations to recompute.");return}hr(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 et={};pe(et,{NAME:()=>Sr,VERSION:()=>wr,up:()=>Cr});import*as q from"fs";import*as Cn from"path";var wr=4,Sr="split-connection-timestamps",br=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function vr(e){if(!q.existsSync(e))return null;let t=q.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function kr(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{q.writeFileSync(o,n)}catch(r){try{q.unlinkSync(o)}catch{}throw r}try{q.renameSync(o,e)}catch(r){try{q.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 Cr(e){let t=Cn.join(e,"people.json"),n=vr(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++,br.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}kr(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".')}await $e();Re();var Ar=xr(import.meta.url),Er=k.dirname(Ar),_r=k.dirname(k.dirname(Er));function $r(e){return e&&(e==="~"?nt.homedir():e.startsWith("~/")||e.startsWith("~\\")?k.join(nt.homedir(),e.slice(2)):e)}var U=process.env.DATA_DIR?k.resolve($r(process.env.DATA_DIR)):_r,re=k.join(U,"collected-profiles"),se=k.join(U,"market-research"),D=k.join(U,".schema-version"),xn=[k.join(re,".schema-version"),k.join(se,".schema-version")],z=4,J=[{version:1,module:Qe},{version:2,module:Xe},{version:3,module:Ze},{version:4,module:et}];(function(){J.sort((o,r)=>o.version-r.version);let t=new Set;for(let o of J){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=J.length?J[J.length-1].version:0;if(n!==z)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${z}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<J.length;o++){let r=o+1;if(J[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${J[o].version}`)}})();function $n(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
248
247
|
[FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
|
|
249
|
-
`),process.exit(1));try{
|
|
248
|
+
`),process.exit(1));try{m.mkdirSync(U,{recursive:!0})}catch(t){t.code!=="EEXIST"&&(console.error(`
|
|
250
249
|
[FATAL] Cannot create DATA_DIR (${U}): ${t.message}`),console.error(` Fix the path or permissions and try again.
|
|
251
|
-
`),process.exit(1))}let e;try{e=
|
|
250
|
+
`),process.exit(1))}let e;try{e=m.statSync(U)}catch(t){console.error(`
|
|
252
251
|
[FATAL] DATA_DIR (${U}) is not accessible: ${t.message}
|
|
253
252
|
`),process.exit(1)}e.isDirectory()||(console.error(`
|
|
254
253
|
[FATAL] DATA_DIR (${U}) exists but is NOT a directory.`),console.error(` Looks like a typo \u2014 your DATA_DIR points at a file. Fix the path and try again.
|
|
255
|
-
`),process.exit(1));for(let t of[re,se]){let n;try{n=
|
|
254
|
+
`),process.exit(1));for(let t of[re,se]){let n;try{n=m.lstatSync(t)}catch(o){if(o.code==="ENOENT")continue;throw o}n.isSymbolicLink()&&(console.error(`
|
|
256
255
|
[FATAL] Data subdirectory is a symbolic link: ${t}`),console.error(" Refusing to follow \u2014 backup code would copy whatever the link points at."),console.error(` If this is intentional, replace the symlink with the real directory.
|
|
257
|
-
`),process.exit(1))}}var oe=k.join(U,".migration-lock");function
|
|
256
|
+
`),process.exit(1))}}var oe=k.join(U,".migration-lock");function Ir(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return m.writeFileSync(oe,e,{flag:"wx"}),!0}catch(o){if(o.code!=="EEXIST")throw o}let t;try{t=JSON.parse(m.readFileSync(oe,"utf-8"))}catch{t=null}if(t&&Number.isInteger(t.pid)){let o=!1;try{process.kill(t.pid,0),o=!0}catch(i){i.code==="EPERM"&&(o=!0)}let r=24*60*60*1e3,s=1/0;if(t.startedAt){let i=Date.parse(t.startedAt);Number.isNaN(i)||(s=Date.now()-i)}o&&s<r&&(console.error(`
|
|
258
257
|
[FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${t.pid}`),console.error(` Started at: ${t.startedAt||"(unknown)"}`),console.error(` Lock file: ${oe}
|
|
259
258
|
`),console.error(" Wait for it to finish, or if you're sure it's not actually running,"),console.error(` delete the lock file manually and re-run.
|
|
260
|
-
`),process.exit(1)),o&&s>=r&&console.log(` Lock holder PID ${t.pid} is alive but lock is older than 24h \u2014 assuming PID reuse, taking over.`)}console.log(` Stale migration lock from PID ${t?.pid??"?"} found \u2014 taking over.`);let n=oe+".tmp";try{return
|
|
259
|
+
`),process.exit(1)),o&&s>=r&&console.log(` Lock holder PID ${t.pid} is alive but lock is older than 24h \u2014 assuming PID reuse, taking over.`)}console.log(` Stale migration lock from PID ${t?.pid??"?"} found \u2014 taking over.`);let n=oe+".tmp";try{return m.writeFileSync(n,e),m.renameSync(n,oe),!0}catch(o){try{m.unlinkSync(n)}catch{}throw new Error(`Failed to take over stale migration lock: ${o.message}`)}}function ot(){try{if(JSON.parse(m.readFileSync(oe,"utf-8")).pid!==process.pid)return;m.unlinkSync(oe)}catch{}}var An=!1;function Rr(){if(An)return;An=!0;let e=()=>{try{ot()}catch{}process.exit(1)};for(let t of["SIGINT","SIGTERM","SIGHUP"])try{process.on(t,e)}catch{}}function Tr(){if(m.existsSync(D))return;let e=[],t=[];for(let s of xn)if(m.existsSync(s))try{e.push({file:s,schema:De(s)})}catch(i){t.push({file:s,err:i.message})}if(t.length>0){console.error(`
|
|
261
260
|
[FATAL] Legacy .schema-version file(s) corrupted \u2014 cannot determine current schema version:`);for(let s of t)console.error(` ${s.file}: ${s.err}`);console.error(`
|
|
262
261
|
Repair the file(s) (likely just an integer 'version' field \u2014 see another working DATA_DIR`),console.error(` or default to {"version":1,"migrations":[]} if you're sure you're on schema v1) and try again.
|
|
263
262
|
`),process.exit(1)}if(e.length===0)return;let n=e.map(s=>s.schema.version);if(new Set(n).size>1){console.error(`
|
|
264
263
|
[FATAL] Legacy .schema-version files disagree:`);for(let s of e)console.error(` ${s.file}: v${s.schema.version}`);console.error(" This means a previous migration crashed between writing the two files."),console.error(` Reconcile manually (delete the wrong one, keep the right one), then re-run.
|
|
265
|
-
`),process.exit(1)}let o=e[0].schema,r=
|
|
266
|
-
[FATAL] ${
|
|
267
|
-
`),process.exit(1)}let t=
|
|
268
|
-
[FATAL] ${
|
|
269
|
-
`),process.exit(1)),t}function
|
|
264
|
+
`),process.exit(1)}let o=e[0].schema,r=D+".tmp";try{m.writeFileSync(r,JSON.stringify(o,null,2)),m.renameSync(r,D)}catch(s){try{m.unlinkSync(r)}catch{}throw s}for(let s of xn)if(m.existsSync(s))try{m.unlinkSync(s)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${D}`)}function Dr(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let t=Number(e.version);return!Number.isFinite(t)||t<0||!Number.isInteger(t)?null:(e.version=t,Array.isArray(e.migrations)||(e.migrations=[]),e)}function De(e){let t=m.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function En(){if(Tr(),!m.existsSync(D))return{version:0,migrations:[]};let e;try{e=De(D)}catch(n){if(n.code==="ENOENT")return{version:0,migrations:[]};console.error(`
|
|
265
|
+
[FATAL] ${D} 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
|
+
`),process.exit(1)}let t=Dr(e);return t===null&&(console.error(`
|
|
267
|
+
[FATAL] ${D} 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 In(e){try{m.chmodSync(e,384)}catch{}}function Or(e){if($n(),m.existsSync(D))try{if(m.lstatSync(D).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${D}. 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=D+".tmp";try{m.writeFileSync(t,JSON.stringify(e,null,2)),In(t),m.renameSync(t,D)}catch(n){try{m.unlinkSync(t)}catch{}throw n}}function _n(e,t){if(!m.existsSync(e))return;let n=`.pre-v${String(t).padStart(3,"0")}.backup`,o=m.readdirSync(e).filter(a=>{let l=a.toLowerCase();if(l.includes(".backup")||l===".schema-version"||l.endsWith(".tmp"))return!1;try{return m.statSync(k.join(e,a)).isFile()}catch{return!1}}),r=0,s=0,i=[];for(let a of o){let l=k.join(e,a),d=k.join(e,a+n);if(m.existsSync(d)){s++;continue}try{Tn(l,d),r++}catch(c){i.push({file:a,err:c.message})}}if(i.length>0){let a=new Error(`Failed to back up ${i.length} file(s) in ${k.basename(e)}/: `+i.map(l=>`${l.file} (${l.err})`).join(", "));throw a.code="BACKUP_INCOMPLETE",a}if(r>0||s>0){let a=s>0?` (${s} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${r} files in ${k.basename(e)}/ (${n})${a}`)}}var tt=!1;async function Rn(){if(tt)return;$n(),Fr();let t=En().version;if(t===z){tt=!0;return}Rr(),Ir(),process.on("exit",ot),t>z&&(console.error(`
|
|
270
269
|
[FATAL] Your data schema is at v${t}, but this plugin build only understands up to v${z}.`),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.
|
|
271
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${z}.
|
|
272
271
|
`),process.exit(1)),console.log(`
|
|
273
|
-
\u{1F4E6} Schema migration: v${t} \u2192 v${z}`);let n=
|
|
272
|
+
\u{1F4E6} Schema migration: v${t} \u2192 v${z}`);let n=Mr();if(!n.ok){console.error(`
|
|
274
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(`
|
|
275
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'.
|
|
276
275
|
`),process.exit(1)}let o=J.filter(r=>r.version>t);for(let r of o){console.log(`
|
|
277
|
-
Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,i=`.pre-${s}.backup`;try{
|
|
276
|
+
Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,i=`.pre-${s}.backup`;try{_n(re,r.version),_n(se,r.version)}catch(l){console.error(`
|
|
278
277
|
[FATAL] Pre-migration backup failed for ${s}: ${l.message}`),console.error(" Migration NOT applied. Repair the underlying issue (disk space, permissions, locked files)"),console.error(` and re-run the plugin command.
|
|
279
278
|
`),process.exit(1)}let a=r.module;try{await a.up(re,se)}catch(l){console.error(`
|
|
280
|
-
[FATAL] Migration ${s} failed: ${l.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let d=
|
|
279
|
+
[FATAL] Migration ${s} failed: ${l.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let d=qr(i);d.ok?(console.error(` \u2713 Auto-rollback restored ${d.restored} files. Schema stays at v${t}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
|
|
281
280
|
`)):(console.error(` [!] Auto-rollback INCOMPLETE: ${d.error}`),console.error(` Manual recovery: copy *${i} files back over the originals.
|
|
282
281
|
`))}catch(d){console.error(` [!] Auto-rollback CRASHED while restoring: ${d.message}`),console.error(` Manual recovery: copy *${i} files back over the originals.
|
|
283
|
-
`)}process.exit(1)}try{let l=new Date().toISOString(),d={version:r.version,name:a.NAME||s,appliedAt:l},c=
|
|
282
|
+
`)}process.exit(1)}try{let l=new Date().toISOString(),d={version:r.version,name:a.NAME||s,appliedAt:l},c=En();c.version=r.version,c.migratedAt=l,c.migrations=c.migrations||[],c.migrations.push(d),Or(c)}catch(l){console.error(`
|
|
284
283
|
[FATAL] Migration ${s} applied successfully but schema version file could NOT be updated: ${l.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.
|
|
285
|
-
`),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{
|
|
284
|
+
`),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{Kt()}catch{}try{an()}catch{}tt=!0,ot(),console.log(`
|
|
286
285
|
\u2713 Schema is now at v${z}
|
|
287
|
-
`)}var
|
|
286
|
+
`)}var jr=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Nr(e){let t=e.toLowerCase();return jr.some(n=>n.test(t))}var Lr=6e4;function Pr(){let e=Date.now(),t=[];for(let n of[U,re,se]){if(!m.existsSync(n))continue;let o;try{o=m.readdirSync(n)}catch{continue}for(let r of o){if(!Nr(r))continue;let s=k.join(n,r);try{let i=m.statSync(s);if(!i.isFile()||e-i.mtimeMs<Lr)continue;t.push({dir:n,file:r,fullPath:s})}catch{}}}return t}function Fr({verbose:e=!1}={}){let t=Pr();if(t.length===0)return e&&console.log(" No orphan .tmp files found."),0;let n=0;for(let o of t)try{m.unlinkSync(o.fullPath),n++,e&&console.log(` Removed orphan: ${k.basename(o.dir)}/${o.file}`)}catch(r){console.warn(` [!] Could not remove orphan ${o.fullPath}: ${r.message}`)}return!e&&n>0&&console.log(` Cleaned up ${n} orphan .tmp file(s) from previous run.`),n}function Mr(){let e=[];for(let t of[re,se]){if(!m.existsSync(t))continue;let n=m.readdirSync(t).filter(o=>{let r=o.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let o of n){let r=k.join(t,o);try{De(r)}catch(s){e.push({dir:k.basename(t),file:o,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function qr(e){let t=[],n=[];for(let s of[re,se]){if(!m.existsSync(s))continue;let i=m.readdirSync(s).filter(a=>a.endsWith(e));for(let a of i){let l=k.join(s,a),d=a.slice(0,-e.length),c=k.join(s,d);try{d.toLowerCase().endsWith(".json")?De(l):m.accessSync(l,m.constants.R_OK),t.push({backupPath:l,originalPath:c,fileName:a,dir:s})}catch(p){n.push(`${k.basename(s)}/${a}: ${p.message}`)}}}if(n.length>0)return{ok:!1,error:n.join("; "),restored:0};let o=0,r=[];for(let{backupPath:s,originalPath:i,fileName:a,dir:l}of t)try{Tn(s,i),o++}catch(d){r.push(`${k.basename(l)}/${a}: ${d.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:o}:{ok:!0,restored:o}}function Tn(e,t){let n=t+".tmp";try{m.copyFileSync(e,n),In(n)}catch(o){try{m.unlinkSync(n)}catch{}throw o}try{m.renameSync(n,t)}catch(o){try{m.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 Rn();var Ce=process.argv.slice(2),Oe=Ce.find(e=>e.startsWith("--source="))?.split("=")[1]||"scouted",rt=parseInt(Ce.find(e=>e.startsWith("--max="))?.split("=")[1]||"50"),ie=parseInt(Ce.find(e=>e.startsWith("--revisit="))?.split("=")[1]||"0"),Ur=Ce.includes("--list"),Br=Ce.includes("--verbose");function Vr(){let e=dn();console.log(`
|
|
288
287
|
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`),console.log(" PROFILE VISIT STATS"),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),console.log(` Unique profiles visited: ${e.totalVisited}`),console.log(` Today: ${e.todayVisited}`),console.log(` Discovered recruiters: ${e.totalRecruiters} (potential visits)`);let t=Je();if(console.log(` Unconnected recruiters: ${t.length}`),ie>0){let n=We(ie);console.log(` Revisit (>${ie}d ago): ${n.length}`)}console.log(`\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
|
|
289
|
-
`)}async function
|
|
288
|
+
`)}async function Hr(){if(console.log(`
|
|
290
289
|
LinkedIn Profile Visitor
|
|
291
|
-
`),
|
|
290
|
+
`),Ur){Vr();return}let e=[],t="";if(ie>0?(e=We(ie),t=`revisit (>${ie} days)`):Oe==="people"?(e=Je(),t="unconnected recruiters (people.json)"):Oe==="scouted"||Oe==="discovered"?(e=pn(),t="discovered recruiters (market-research)"):(e=mn({limit:rt}),t="smart (new \u2192 active \u2192 unconnected \u2192 revisit)"),console.log(` Source: ${t}`),console.log(` Candidates: ${e.length}`),console.log(` Max visits: ${rt}
|
|
292
291
|
`),e.length===0){console.log(` No profiles to visit. Run npm run scout first.
|
|
293
|
-
`);return}
|
|
292
|
+
`);return}await bn("visit",Oe,async n=>{let{browser:o,page:r}=await Ht();try{let s=await fn(r,e,{maxVisits:rt,verbose:Br,skipRecentDays:ie>0?0:7});Object.assign(n,s),console.log(`
|
|
294
293
|
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`),console.log(" Visit Complete"),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),console.log(` Visited: ${s.visited}`),console.log(` Skipped: ${s.skipped} (visited recently)`),console.log(` Errors: ${s.errors}`),console.log(`\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
|
|
295
|
-
`),
|
|
296
|
-
Error:`,s.message),Ke(n,"error",null,s.message)}finally{await o.close().catch(()=>{})}}Ur().catch(e=>{console.error("Visit failed:",e),process.exit(1)});
|
|
294
|
+
`)}finally{await o.close().catch(()=>{})}},n=>[`${n.visited??0} visited, ${n.skipped??0} skipped (recent), ${n.errors??0} errors`],{rethrow:!1})}Hr().catch(e=>{console.error("Visit failed:",e),process.exit(1)});
|
package/ilml-plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "linkedin",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.19",
|
|
4
4
|
"description": "Reference ilml plugin: keep a local mirror of your LinkedIn data with AI-assisted workflows",
|
|
5
5
|
"commands": {
|
|
6
6
|
"help": { "run": "node dist/help.mjs", "description": "List all commands with descriptions; or `help <cmd>` for detailed info on one command (usage, flags, ban-risk, when-to-use). Reads ilml-plugin.json directly.", "usage": "ilml linkedin help [<cmd>]", "useWhen": "You forgot what a command does, or you're an AI agent picking the right tool." },
|
package/package.json
CHANGED