ilml-plugin-linkedin 1.20.22 → 1.20.27
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 +22 -0
- package/dist/applyQueue.mjs +38 -38
- package/dist/connect.mjs +78 -77
- package/dist/daily.mjs +34 -34
- package/dist/enrichProfiles.mjs +50 -50
- package/dist/funnelRunner.mjs +61 -60
- package/dist/messageBot.mjs +67 -67
- package/dist/migrationCli.mjs +44 -44
- package/dist/peopleSearchCli.mjs +13 -0
- package/dist/quota.mjs +34 -34
- package/dist/run.mjs +75 -74
- package/dist/scout.mjs +33 -33
- package/dist/syncAll.mjs +99 -98
- package/dist/syncConnections.mjs +48 -48
- package/dist/version.mjs +1 -1
- package/dist/viewers.mjs +35 -35
- package/dist/visit.mjs +48 -48
- package/ilml-plugin.json +19 -1
- package/package.json +2 -1
package/dist/enrichProfiles.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Bn=Object.defineProperty;var G=(e,t)=>()=>(e&&(t=e(e=0)),t);var fe=(e,t)=>{for(var n in t)Bn(e,n,{get:t[n],enumerable:!0})};import R from"fs";import B from"path";function Le(){let e=process.env.ILML_SCOPE_DIR;return e?B.join(e,"plugins-state","linkedin","cookies.json"):Hn}function Vn(){let e=Le(),t=B.dirname(e);return t&&t!=="."&&!R.existsSync(t)&&R.mkdirSync(t,{recursive:!0}),e}function xt(e){let t=Vn();return R.writeFileSync(t,JSON.stringify(e)),t}function Et(){let e=Le();if(!R.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=R.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 At(){return R.existsSync(Le())}function Jn(){let e=process.env.ILML_SCOPE_DIR;return e?B.join(e,"plugins-state","linkedin"):"."}function _t(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function Wn(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?_t(t[1]):"default"}function $t(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return R.existsSync(t)||R.mkdirSync(t,{recursive:!0}),B.resolve(t);let n=_t(e||Wn()),o=B.join(Jn(),"chrome-profile",n);return R.existsSync(o)||R.mkdirSync(o,{recursive:!0}),B.resolve(o)}function Rt(e){return!R.existsSync(B.join(e,It))}function Tt(e){try{R.writeFileSync(B.join(e,It),new Date().toISOString())}catch{}}function Dt(e){let t=0;for(let n of["SingletonLock","SingletonCookie","SingletonSocket"])try{R.rmSync(B.join(e,n),{force:!0}),t++}catch{}return t}var Hn,It,$e=G(()=>{Hn="cookies.json";It=".ilml-seeded"});async function k(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function Gn(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(c=>!!document.querySelector(c),t)){let c=Date.now()-s;return c>6e3&&console.log(` (waited ${Math.round(c/1e3)}s for LinkedIn to finish loading ${r})`),!0}}catch{}await new Promise(i=>setTimeout(i,o))}return!1}function Yn(e){return jt.test(e||"")}async function Kn(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(u=>!new RegExp(u).test(location.href)&&document.querySelector("#global-nav, nav.global-nav")?"in":document.querySelector('input#username, input[name="session_key"], input#password')?"creds":"wait",jt.source)}catch{}if(l==="in"){try{let u=await e.cookies();if(Array.isArray(u)&&u.some(m=>m.name==="li_at")){let m=xt(u);console.log(` \u2713 Session recovered \u2014 re-saved ${u.length} cookies (${m}).`)}else console.log(" \u2713 Session recovered (kept existing cookie snapshot \u2014 refreshed set had no li_at).")}catch(u){console.log(` \u2713 Session recovered (cookie re-save skipped: ${u.message}).`)}return!0}if(l==="creds"){if(!o){let u=new Error(`Session expired (${n}) \u2014 credentials required and no interactive terminal. Run: ilml linkedin login`);throw u.code="SESSION_EXPIRED",u}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(u=>setTimeout(u,2500))}let l=new Error(`Session expired (${n}) \u2014 not signed in within the wait window. Run: ilml linkedin login`);throw l.code="SESSION_EXPIRED",l}async function It(e,{readySelector:t,label:n="page",timeout:o=45e3}={}){let r=await Bn(e,t,{timeout:o,label:n});if(!r&&Hn(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 ue(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(l){if(i&&l.code==="SESSION_EXPIRED"){await Vn(e,{label:o});try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:s})}catch{}return await It(e,{readySelector:n,label:o,timeout:r})}throw l}}async function Tt(e){return await e.evaluate(()=>{let t=document.querySelectorAll("div.artdeco-modal--is-open");for(let o of t){let r=o.innerText||"",s=r.includes("Premium")||r.includes("premium")||r.includes("Upgrade")||r.includes("upgrade"),i=r.includes("Try for")||r.includes("free trial")||r.includes("/month")||r.includes("per month")||r.includes("Start my")||r.includes("Subscribe"),l=r.includes("Get hired faster")||r.includes("Get hired 2x");if(s||i||l){let a=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(a)return a.click(),{dismissed:!0,matched:r.substring(0,80)};let u=o.querySelectorAll("button");for(let c of u){let p=c.innerText?.trim().toLowerCase()||"",f=c.getAttribute("aria-label")?.toLowerCase()||"";if(p==="not now"||p==="no thanks"||p==="dismiss"||f.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=W(()=>{Ee();Rt=/\/authwall|\/login|\/checkpoint|\/uas\/login/});function Wn(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)),Dt(e.JOB_SEARCH_EASY_APPLY)&&n.set("f_AL","true"),Dt(e.JOB_SEARCH_IN_NETWORK)&&n.set("f_JIYN","true");let i=Wn(e.JOB_SEARCH_COMPANY_IDS);i.length&&n.set("f_C",i.join(","));let l=(e.JOB_SEARCH_DATE_POSTED||"").trim().toLowerCase();l&&n.set("f_TPR",Jn[l]||l),n.set("origin","JOB_SEARCH_PAGE_JOB_FILTER");let a="https://www.linkedin.com/jobs/search/?"+n.toString(),u=(e.JOB_SEARCH_EXTRA_PARAMS||"").trim().replace(/^[?&]+/,"");return u&&(a+="&"+u),a}var Jn,Dt,Nt=W(()=>{Jn={day:"r86400","24h":"r86400",today:"r86400",week:"r604800","7d":"r604800",month:"r2592000","30d":"r2592000"},Dt=e=>/^(1|true|yes|on)$/i.test(String(e??"").trim())});import{getPluginConfig as Gn}from"@ilivemylife/graph-sdk";var Yn,jt,Kn,te,ns,zn,Ne=W(async()=>{Nt();Yn=await Gn();for(let[e,t]of Object.entries(Yn))process.env[e]===void 0&&(process.env[e]=t);jt=Ot(process.env);jt&&(process.env.LINKEDIN_SEARCH_URL=jt);Kn=process.env.LINKEDIN_NAME,te=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),ns=Object.freeze(new Set([te.DRAFT,te.CONFIRMED,te.NEEDS_REVIEW])),zn=Object.freeze(new Set([te.DRAFT,te.CONFIRMED,te.REJECTED,te.NEEDS_REVIEW]))});import"dotenv/config";import*as C from"fs";import*as E from"path";import{fileURLToPath as io}from"url";function Qt(){fe=null,co=null,uo=null,de=null,fo=null,mo=null}function Me(){C.existsSync(B)||C.mkdirSync(B,{recursive:!0})}function Ue(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";C.writeFileSync(o,n);for(let r=0;r<3;r++)try{C.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function qe(e,t){if(!C.existsSync(e))return null;try{let n=JSON.parse(C.readFileSync(e,"utf-8"));try{C.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.message}`),console.error(` File: ${E.resolve(e)}`);let o=e+".backup";if(C.existsSync(o))try{let r=JSON.parse(C.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{C.copyFileSync(o,e)}catch{}return r}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{C.copyFileSync(e,e+".corrupted")}catch{}return null}}function po(){return new Date().toISOString().split("T")[0]}function ne(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 Xt(e,t,n=null){if(!t||e[t])return t;let o=ne(t);if(!o)return t;let r=null;for(let[s,i]of Object.entries(e)){if(ne(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 yo(){C.existsSync(Fe)||C.mkdirSync(Fe,{recursive:!0})}function Zt(e){let t=ne(e);return t?E.join(Fe,`${t}.json`):null}function wo(e){let t=Zt(e);return t?qe(t,`profile-history/${ne(e)}.json`)||[]:[]}function bo(e,t){let n=Zt(e);if(!n)return;yo();let o=wo(e);o.unshift(t);try{Ue(n,o)}catch(r){console.error(`[!] Failed to append profile-history for ${ne(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 So(e,t){if(!e)return[];let n=[];for(let o of go){let r=e[o],s=t[o];Gt(r)||Gt(s)||Yt(r)!==Yt(s)&&n.push(o)}return n}function vo(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 G(){return fe||(Me(),fe=qe(Pe,"people.json")||{},fe)}function en(e){Me(),fe=e;try{Ue(Pe,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${E.resolve(Pe)}`)}}function Be(){return de||(Me(),de=qe(Kt,"conversations.json")||{},ko(de),de)}function ko(e){let t=0;for(let n of Object.values(e)){if(!(n.draftStatus!==void 0||n.draftPreparedAt!==void 0))continue;let r=(n.messages||[]).find(s=>s.status==="draft");r&&n.draftStatus&&n.draftStatus!=="pending"&&(r.status=n.draftStatus),delete n.draftStatus,delete n.draftPreparedAt,t++}if(t>0){console.log(` [migration] Moved draft state from conv to msg.status for ${t} conversations`);try{Ue(Kt,e)}catch{}}}function He(e,t={}){if(!e)return null;let n=G(),o=po(),r=new Date().toISOString(),s=Xt(n,e,t.name),i=n[s];if(i){let l=So(i,t);l.length>0&&(bo(s,{capturedAt:r,previousLastUpdated:i.lastUpdated||null,changedFields:l,snapshot:vo(i)}),i.lastSnapshotAt=r),i.seenCount=(i.seenCount||1)+1,i.lastSeen=o,i.lastUpdated=r,t.source&&!i.sources?.includes(t.source)&&(i.sources=i.sources||[],i.sources.push(t.source));for(let a of ho)if(t[a]!=null){if(Array.isArray(t[a])&&t[a].length===0&&Array.isArray(i[a])&&i[a].length>0)continue;i[a]=t[a]}Array.isArray(t.availableSections)&&(i.lastFullVisitAt=r)}else n[s]={name:t.name||null,title:t.title||null,location:t.location||null,company:t.company||null,about:t.about||null,connectionDegree:t.connectionDegree||null,connectionsCount:t.connectionsCount||null,mutualConnections:t.mutualConnections||null,photoUrl:t.photoUrl||null,hasVerifiedBadge:t.hasVerifiedBadge||!1,currentCompany:t.currentCompany||null,currentSchool:t.currentSchool||null,connectionsLevel:t.connectionsLevel||null,mutualConnectionsCount:t.mutualConnectionsCount||null,followers:t.followers||null,openToWork:t.openToWork||!1,hiring:t.hiring||!1,topSkills:t.topSkills||null,availableSections:t.availableSections||null,experience:t.experience||null,featuredLinks:t.featuredLinks||null,_lastEnrichedAt:t._lastEnrichedAt||null,featured:t.featured||null,education:t.education||null,skillsFull:t.skillsFull||null,recommendations:t.recommendations||null,certifications:t.certifications||null,firstSeen:o,lastSeen:o,seenCount:1,sources:t.source?[t.source]:[],connectionStatus:null,requestedConnectionAt:null,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:r,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(t.availableSections)?r:null};return en(n),n[s]}function Ve(e,t,n={}){if(n.dryRun||!e||!t)return;let o=ne(t);if(!o)return;let r=G(),s=Xt(r,e),i=r[s];if(!i)return;let l=ne(i.profileUrl||s);o!==l&&(Array.isArray(i.aliases)||(i.aliases=[]),i.aliases.includes(o)||(i.aliases.push(o),i.lastUpdated=new Date().toISOString(),en(r)))}var lo,ao,B,Pe,Cs,xs,Kt,Es,As,Fe,zt,_s,$s,fe,co,uo,de,fo,mo,ho,go,we=W(async()=>{await Ne();lo=io(import.meta.url),ao=E.dirname(E.dirname(lo)),B=process.env.DATA_DIR?E.resolve(process.env.DATA_DIR,"collected-profiles"):E.join(ao,"collected-profiles"),Pe=E.join(B,"people.json"),Cs=E.join(B,"jobs.json"),xs=E.join(B,"quota.json"),Kt=E.join(B,"conversations.json"),Es=E.join(B,"sync-state.json"),As=E.join(B,"application-questions.json"),Fe=E.join(B,"profile-history"),zt=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},_s=zt(process.env.CONNECT_MAX_DAILY,20),$s=zt(process.env.CONNECT_MAX_WEEKLY,100),fe=null,co=null,uo=null,de=null,fo=null,mo=null;ho=["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"],go=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"]});var tn={};pe(tn,{extractCertificationsFromDetails:()=>_o,extractEducationFromDetails:()=>Eo,extractExperienceFromDetails:()=>Co,extractFeaturedFromDetails:()=>xo,extractRecommendationsFromDetails:()=>$o,extractSkillsFromDetails:()=>Ao});async function Co(e,t){let n=t.replace(/\/+$/,"")+"/details/experience/";try{await ue(e,n,{readySelector:"main .pvs-list, .scaffold-layout__main, main.scaffold-layout__main, section.artdeco-card",label:"experience details"}),await k(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 k(900);await k(1e3);let r=0;for(;r<5&&await e.evaluate(()=>{for(let i of document.querySelectorAll("button"))if(/^Load more$/i.test((i.textContent||"").trim()))return i.click(),!0;return!1});)r++,await k(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await k(700);return await e.evaluate(()=>{let s=document.querySelector("main");if(!s)return[];function i(c){let p=[];for(let f of c.querySelectorAll("div")){let m=Array.from(f.children).filter(w=>w.tagName==="DIV");if(m.length<3)continue;let v=m.filter(w=>(w.textContent||"").trim().length>50);v.length<3||(f.textContent||"").length<500||p.push({el:f,count:v.length,totalText:(f.textContent||"").length})}return p.sort((f,m)=>m.count-f.count||f.totalText-m.totalText),p[0]?.el}let l=i(s);if(!l)return[];let a=Array.from(l.children).filter(c=>c.tagName==="DIV").filter(c=>(c.textContent||"").trim().length>50);function u(c){let p=c[0]||null,f=null,m=null;if(c[1]){let b=c[1].split("\xB7").map($=>$.trim());f=b[0]||null,b[1]&&(m=b[1])}let v=c.findIndex(b=>/(\d{4}|present)/i.test(b)&&/(-|–|—)/i.test(b)&&b.length<80),w=null,A=null;if(v>=0){let b=c[v].split("\xB7").map($=>$.trim());w=b[0]||null,b[1]&&(A=b[1])}let Q=null,X=-1;if(v>=0&&c[v+1]){let b=c[v+1],$=/^[>*\-•]|^>/.test(b),ae=/https?:\/\//.test(b),ce=/\d{4}/.test(b),I=/,/.test(b)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(b);!$&&!ae&&!ce&&b.length<100&&I&&(Q=b,X=v+1)}let Re=null,x=-1,Z=c[c.length-1];if(Z&&/and\s+\+\d+\s+skills?$/i.test(Z)){x=c.length-1;let b=Z.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);b&&(Re={listed:b[1].split(",").map($=>$.trim()),additional:parseInt(b[2],10)})}let ee=new Set([0,1,v,X,x].filter(b=>b>=0)),V=c.filter((b,$)=>!ee.has($)),D=V.length>0?V.join(`
|
|
3
|
+
`))}await new Promise(u=>setTimeout(u,2500))}let c=new Error(`Session expired (${n}) \u2014 not signed in within the wait window. Run: ilml linkedin login`);throw c.code="SESSION_EXPIRED",c}async function Ot(e,{readySelector:t,label:n="page",timeout:o=45e3}={}){let r=await Gn(e,t,{timeout:o,label:n});if(!r&&Yn(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 me(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 Ot(e,{readySelector:n,label:o,timeout:r})}catch(c){if(i&&c.code==="SESSION_EXPIRED"){await Kn(e,{label:o});try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:s})}catch{}return await Ot(e,{readySelector:n,label:o,timeout:r})}throw c}}async function Nt(e){return await e.evaluate(()=>{let t=document.querySelectorAll("div.artdeco-modal--is-open");for(let o of t){let r=o.innerText||"",s=r.includes("Premium")||r.includes("premium")||r.includes("Upgrade")||r.includes("upgrade"),i=r.includes("Try for")||r.includes("free trial")||r.includes("/month")||r.includes("per month")||r.includes("Start my")||r.includes("Subscribe"),c=r.includes("Get hired faster")||r.includes("Get hired 2x");if(s||i||c){let 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 u=o.querySelectorAll("button");for(let a of u){let m=a.innerText?.trim().toLowerCase()||"",f=a.getAttribute("aria-label")?.toLowerCase()||"";if(m==="not now"||m==="no thanks"||m==="dismiss"||f.includes("dismiss"))return a.click(),{dismissed:!0,matched:r.substring(0,80)}}}}let n=document.querySelector(".premium-upsell-link")||document.querySelector("[data-test-premium-upsell]")||document.querySelector(".premium-hub-upsell");if(n){let o=n.closest('[class*="modal"]')?.querySelector('button[aria-label="Dismiss"]')||n.closest('[class*="banner"]')?.querySelector('button[aria-label="Close"]');if(o)return o.click(),{dismissed:!0,matched:"premium-banner"}}return!1})}var jt,ye=G(()=>{$e();jt=/\/authwall|\/login|\/checkpoint|\/uas\/login/});function Qn(e){return String(e??"").split(/[,\s|]+/).map(t=>t.trim()).filter(Boolean)}function Pt(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)),Lt(e.JOB_SEARCH_EASY_APPLY)&&n.set("f_AL","true"),Lt(e.JOB_SEARCH_IN_NETWORK)&&n.set("f_JIYN","true");let i=Qn(e.JOB_SEARCH_COMPANY_IDS);i.length&&n.set("f_C",i.join(","));let c=(e.JOB_SEARCH_DATE_POSTED||"").trim().toLowerCase();c&&n.set("f_TPR",zn[c]||c),n.set("origin","JOB_SEARCH_PAGE_JOB_FILTER");let l="https://www.linkedin.com/jobs/search/?"+n.toString(),u=(e.JOB_SEARCH_EXTRA_PARAMS||"").trim().replace(/^[?&]+/,"");return u&&(l+="&"+u),l}var zn,Lt,Ft=G(()=>{zn={day:"r86400","24h":"r86400",today:"r86400",week:"r604800","7d":"r604800",month:"r2592000","30d":"r2592000"},Lt=e=>/^(1|true|yes|on)$/i.test(String(e??"").trim())});import{getPluginConfig as Xn}from"@ilivemylife/graph-sdk";var Zn,Mt,eo,ne,ms,to,Pe=G(async()=>{Ft();Zn=await Xn();for(let[e,t]of Object.entries(Zn))process.env[e]===void 0&&(process.env[e]=t);Mt=Pt(process.env);Mt&&(process.env.LINKEDIN_SEARCH_URL=Mt);eo=process.env.LINKEDIN_NAME,ne=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),ms=Object.freeze(new Set([ne.DRAFT,ne.CONFIRMED,ne.NEEDS_REVIEW])),to=Object.freeze(new Set([ne.DRAFT,ne.CONFIRMED,ne.REJECTED,ne.NEEDS_REVIEW]))});import"dotenv/config";import*as C from"fs";import*as E from"path";import{fileURLToPath as fo}from"url";function tn(){he=null,ho=null,go=null,pe=null,yo=null,wo=null}function Be(){C.existsSync(H)||C.mkdirSync(H,{recursive:!0})}function He(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";C.writeFileSync(o,n);for(let r=0;r<3;r++)try{C.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function Ve(e,t){if(!C.existsSync(e))return null;try{let n=JSON.parse(C.readFileSync(e,"utf-8"));try{C.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.message}`),console.error(` File: ${E.resolve(e)}`);let o=e+".backup";if(C.existsSync(o))try{let r=JSON.parse(C.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{C.copyFileSync(o,e)}catch{}return r}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{C.copyFileSync(e,e+".corrupted")}catch{}return null}}function bo(){return new Date().toISOString().split("T")[0]}function oe(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function zt(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function nn(e,t,n=null){if(!t||e[t])return t;let o=oe(t);if(!o)return t;let r=null;for(let[s,i]of Object.entries(e)){if(oe(i.profileUrl||s)===o)return s;!r&&Array.isArray(i.aliases)&&i.aliases.includes(o)&&(r=s)}if(r){let s=zt(n),i=zt(e[r].name);if(s&&i&&s===i)return r}return t}function ko(){C.existsSync(qe)||C.mkdirSync(qe,{recursive:!0})}function on(e){let t=oe(e);return t?E.join(qe,`${t}.json`):null}function Co(e){let t=on(e);return t?Ve(t,`profile-history/${oe(e)}.json`)||[]:[]}function xo(e,t){let n=on(e);if(!n)return;ko();let o=Co(e);o.unshift(t);try{He(n,o)}catch(r){console.error(`[!] Failed to append profile-history for ${oe(e)}: ${r.message}`)}}function Qt(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function Xt(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function Eo(e,t){if(!e)return[];let n=[];for(let o of vo){let r=e[o],s=t[o];Qt(r)||Qt(s)||Xt(r)!==Xt(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 Y(){return he||(Be(),he=Ve(Ue,"people.json")||{},he)}function rn(e){Be(),he=e;try{He(Ue,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${E.resolve(Ue)}`)}}function Je(){return pe||(Be(),pe=Ve(Zt,"conversations.json")||{},_o(pe),pe)}function _o(e){let t=0;for(let n of Object.values(e)){if(!(n.draftStatus!==void 0||n.draftPreparedAt!==void 0))continue;let r=(n.messages||[]).find(s=>s.status==="draft");r&&n.draftStatus&&n.draftStatus!=="pending"&&(r.status=n.draftStatus),delete n.draftStatus,delete n.draftPreparedAt,t++}if(t>0){console.log(` [migration] Moved draft state from conv to msg.status for ${t} conversations`);try{He(Zt,e)}catch{}}}function We(e,t={}){if(!e)return null;let n=Y(),o=bo(),r=new Date().toISOString(),s=nn(n,e,t.name),i=n[s];if(i){let c=Eo(i,t);c.length>0&&(xo(s,{capturedAt:r,previousLastUpdated:i.lastUpdated||null,changedFields:c,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 rn(n),n[s]}function Ge(e,t,n={}){if(n.dryRun||!e||!t)return;let o=oe(t);if(!o)return;let r=Y(),s=nn(r,e),i=r[s];if(!i)return;let c=oe(i.profileUrl||s);o!==c&&(Array.isArray(i.aliases)||(i.aliases=[]),i.aliases.includes(o)||(i.aliases.push(o),i.lastUpdated=new Date().toISOString(),rn(r)))}var mo,po,H,Ue,js,Ns,Zt,Ls,Ps,qe,en,Fs,Ms,he,ho,go,pe,yo,wo,So,vo,Se=G(async()=>{await Pe();mo=fo(import.meta.url),po=E.dirname(E.dirname(mo)),H=process.env.DATA_DIR?E.resolve(process.env.DATA_DIR,"collected-profiles"):E.join(po,"collected-profiles"),Ue=E.join(H,"people.json"),js=E.join(H,"jobs.json"),Ns=E.join(H,"quota.json"),Zt=E.join(H,"conversations.json"),Ls=E.join(H,"sync-state.json"),Ps=E.join(H,"application-questions.json"),qe=E.join(H,"profile-history"),en=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},Fs=en(process.env.CONNECT_MAX_DAILY,20),Ms=en(process.env.CONNECT_MAX_WEEKLY,100),he=null,ho=null,go=null,pe=null,yo=null,wo=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"],vo=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"]});var sn={};fe(sn,{extractCertificationsFromDetails:()=>Do,extractEducationFromDetails:()=>Ro,extractExperienceFromDetails:()=>$o,extractFeaturedFromDetails:()=>Io,extractRecommendationsFromDetails:()=>Oo,extractSkillsFromDetails:()=>To});async function $o(e,t){let n=t.replace(/\/+$/,"")+"/details/experience/";try{await me(e,n,{readySelector:"main .pvs-list, .scaffold-layout__main, main.scaffold-layout__main, section.artdeco-card",label:"experience details"}),await k(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 k(900);await k(1e3);let r=0;for(;r<5&&await e.evaluate(()=>{for(let i of document.querySelectorAll("button"))if(/^Load more$/i.test((i.textContent||"").trim()))return i.click(),!0;return!1});)r++,await k(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await k(700);return await e.evaluate(()=>{let s=document.querySelector("main");if(!s)return[];function i(a){let m=[];for(let f of a.querySelectorAll("div")){let p=Array.from(f.children).filter(w=>w.tagName==="DIV");if(p.length<3)continue;let v=p.filter(w=>(w.textContent||"").trim().length>50);v.length<3||(f.textContent||"").length<500||m.push({el:f,count:v.length,totalText:(f.textContent||"").length})}return m.sort((f,p)=>p.count-f.count||f.totalText-p.totalText),m[0]?.el}let c=i(s);if(!c)return[];let l=Array.from(c.children).filter(a=>a.tagName==="DIV").filter(a=>(a.textContent||"").trim().length>50);function u(a){let m=a[0]||null,f=null,p=null;if(a[1]){let b=a[1].split("\xB7").map($=>$.trim());f=b[0]||null,b[1]&&(p=b[1])}let v=a.findIndex(b=>/(\d{4}|present)/i.test(b)&&/(-|–|—)/i.test(b)&&b.length<80),w=null,A=null;if(v>=0){let b=a[v].split("\xB7").map($=>$.trim());w=b[0]||null,b[1]&&(A=b[1])}let X=null,Z=-1;if(v>=0&&a[v+1]){let b=a[v+1],$=/^[>*\-•]|^>/.test(b),ue=/https?:\/\//.test(b),de=/\d{4}/.test(b),I=/,/.test(b)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(b);!$&&!ue&&!de&&b.length<100&&I&&(X=b,Z=v+1)}let Oe=null,x=-1,ee=a[a.length-1];if(ee&&/and\s+\+\d+\s+skills?$/i.test(ee)){x=a.length-1;let b=ee.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);b&&(Oe={listed:b[1].split(",").map($=>$.trim()),additional:parseInt(b[2],10)})}let te=new Set([0,1,v,Z,x].filter(b=>b>=0)),J=a.filter((b,$)=>!te.has($)),D=J.length>0?J.join(`
|
|
4
4
|
|
|
5
|
-
`):null;return{title:
|
|
6
|
-
`).map(
|
|
7
|
-
${
|
|
5
|
+
`):null;return{title:m,company:f,employmentType:p,dates:w,duration:A,location:X,description:D,skills:Oe,_raw:a}}return l.map(a=>{let f=(a.innerText||"").trim().split(`
|
|
6
|
+
`).map(p=>p.trim()).filter(p=>p&&p.length<5e3);return u(f)}).filter(a=>a.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 ve(e,t,n){let o=t.replace(/\/+$/,"")+`/details/${n}/`;await me(e,o,{readySelector:"main .pvs-list, .scaffold-layout__main, main.scaffold-layout__main, section.artdeco-card",label:`details/${n}`}),await k(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 k(700);await k(800);let s=0;for(;s<5&&await e.evaluate(()=>{for(let c of document.querySelectorAll("button"))if(/^Load more$/i.test((c.textContent||"").trim()))return c.click(),!0;return!1});)s++,await k(1300),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await k(600)}async function Ce(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 Io(e,t){return Ce(t,"featured","extractFeaturedFromDetails",async()=>(await ve(e,t,"featured"),await e.evaluate(`(() => {
|
|
7
|
+
${ke}
|
|
8
8
|
|
|
9
9
|
const main = document.querySelector('main');
|
|
10
10
|
if (!main) return [];
|
|
@@ -44,8 +44,8 @@ var Pn=Object.defineProperty;var W=(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
|
|
48
|
-
${
|
|
47
|
+
})()`)))}async function Ro(e,t){return Ce(t,"education","extractEducationFromDetails",async()=>(await ve(e,t,"education"),await e.evaluate(`(() => {
|
|
48
|
+
${ke}
|
|
49
49
|
|
|
50
50
|
const main = document.querySelector('main');
|
|
51
51
|
if (!main) return [];
|
|
@@ -81,8 +81,8 @@ var Pn=Object.defineProperty;var W=(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
|
|
85
|
-
${
|
|
84
|
+
})()`)))}async function To(e,t){return Ce(t,"skills","extractSkillsFromDetails",async()=>(await ve(e,t,"skills"),await e.evaluate(`(() => {
|
|
85
|
+
${ke}
|
|
86
86
|
|
|
87
87
|
const main = document.querySelector('main');
|
|
88
88
|
if (!main) return [];
|
|
@@ -113,8 +113,8 @@ var Pn=Object.defineProperty;var W=(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
|
|
117
|
-
${
|
|
116
|
+
})()`)))}async function Do(e,t){return Ce(t,"certifications","extractCertificationsFromDetails",async()=>(await ve(e,t,"certifications"),await e.evaluate(`(() => {
|
|
117
|
+
${ke}
|
|
118
118
|
|
|
119
119
|
const main = document.querySelector('main');
|
|
120
120
|
if (!main) return [];
|
|
@@ -138,8 +138,8 @@ var Pn=Object.defineProperty;var W=(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
|
|
142
|
-
${
|
|
141
|
+
})()`)))}async function Oo(e,t){return Ce(t,"recommendations","extractRecommendationsFromDetails",async()=>(await ve(e,t,"recommendations"),await e.evaluate(`(() => {
|
|
142
|
+
${ke}
|
|
143
143
|
|
|
144
144
|
const main = document.querySelector('main');
|
|
145
145
|
if (!main) return [];
|
|
@@ -174,7 +174,7 @@ var Pn=Object.defineProperty;var W=(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
|
|
177
|
+
})()`)))}var ke,ln=G(()=>{ye();ke=`
|
|
178
178
|
function findEntryContainer(root) {
|
|
179
179
|
const candidates = [];
|
|
180
180
|
for (const div of root.querySelectorAll('div')) {
|
|
@@ -237,52 +237,52 @@ 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 rn=W(()=>{});import"dotenv/config";import*as N from"fs";import*as O from"path";import{fileURLToPath as Ro}from"url";function Oo(){N.existsSync(re)||N.mkdirSync(re,{recursive:!0})}function No(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 jo(e){try{if(N.existsSync(e))return JSON.parse(N.readFileSync(e,"utf-8"))}catch{}return null}function ln(){Lo=null,Po=null,Fo=null,Mo=null,oe=null}function Je(){return oe||(oe=jo(sn)||{visits:[]},Array.isArray(oe.visits)||(oe.visits=[]),oe)}function an(e,t={}){if(!e)return;Oo();let n=Je();n.visits.push({date:new Date().toISOString(),profileUrl:e,name:t.name||null,source:t.source||"manual"});let o=Date.now()-90*24*60*60*1e3;n.visits=n.visits.filter(r=>new Date(r.date).getTime()>o);try{No(sn,n)}catch(r){console.error(`[!] Failed to save visit-log.json: ${r.message}`)}}function cn(e){let t=Je();for(let n=t.visits.length-1;n>=0;n--)if(t.visits[n].profileUrl===e)return t.visits[n].date;return null}var To,Do,re,Ws,Gs,sn,Ys,Ks,Lo,Po,Fo,Mo,oe,We=W(()=>{rn();To=Ro(import.meta.url),Do=O.dirname(O.dirname(To)),re=process.env.DATA_DIR?O.resolve(process.env.DATA_DIR,"market-research"):O.join(Do,"market-research"),Ws=O.join(re,"scouted-jobs.json"),Gs=O.join(re,"discovered-people.json"),sn=O.join(re,"visit-log.json"),Ys=O.join(re,"companies.json"),Ks=O.join(re,"job-decisions.json");Lo=null,Po=null,Fo=null,Mo=null,oe=null});import oo from"puppeteer";import{addExtra as ro}from"puppeteer-extra";import so from"puppeteer-extra-plugin-stealth";he();await Ne();Ee();Ee();import je from"fs";import Qn from"path";var Xn={headless:!1,defaultViewport:null,protocolTimeout:3e5},ye=new Set,Lt=!1;async function Ae(){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 Zn(){if(Lt)return;Lt=!0;let e=t=>async()=>{await Ae(),process.exit(t)};process.once("SIGINT",e(130)),process.once("SIGTERM",e(143)),process.once("SIGHUP",e(129)),process.once("uncaughtException",async t=>{await Ae(),console.error(t&&t.stack||t),process.exit(1)}),process.once("unhandledRejection",async t=>{await Ae(),console.error(t),process.exit(1)}),process.stdout.on("error",async t=>{t&&t.code==="EPIPE"&&(await Ae(),process.exit(0))}),process.on("exit",()=>{for(let t of ye)try{let n=t.process&&t.process();n&&n.kill("SIGKILL")}catch{}})}function Le(e){return Qn.join(e,".ilml-browser-session.json")}function Ut(e,t={}){try{je.writeFileSync(Le(e),JSON.stringify({ownerPid:process.pid,startedAt:Date.now(),...t}))}catch{}}function eo(e,t){try{let n=t.wsEndpoint&&t.wsEndpoint();Ut(e,n?{wsEndpoint:n}:{})}catch{}}function to(e){let t=qt(e);t&&t.ownerPid===process.pid&&ge(e)}function ge(e){try{je.rmSync(Le(e),{force:!0})}catch{}}function qt(e){try{return JSON.parse(je.readFileSync(Le(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=qt(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(a=>{if(a)try{a.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 no(e,t){e&&(Zn(),ye.add(e),e.on("disconnected",()=>{ye.delete(e),t&&ge(t)}))}async function Bt(e,t={}){let n=xt(),o={...Xn,...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);Ut(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(l){throw to(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: ${l.message})`)}}return no(s,n),eo(n,s),{browser:s,profileDir:n,needsSeed:At(n)}}async function Ht(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 Vt=ro(oo);Vt.use(so());async function Jt(){let{browser:e,profileDir:t,needsSeed:n}=await Bt(Vt),o=await e.newPage();return await o.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Ht(o,{profileDir:t,needsSeed:n}),console.log(" Browser launched (persistent profile)."),{browser:e,page:o}}he();await we();async function Io(e,t){let n=e.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: ilml linkedin login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await k(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function on(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:s=!1,extractSkills:i=!1,extractRecommendations:l=!1,extractCertifications:a=!1}=n;try{await ue(e,t,{readySelector:".scaffold-layout__main, main.scaffold-layout__main, .pv-top-card, section.pv-top-card",label:"profile"}),await k(1500),await Tt(e)&&(console.log(" Dismissed Premium overlay"),await k(1500),await Io(e,t));let c=0;for(let x=0;x<2;x++){let Z=await e.evaluate(()=>document.body.scrollHeight);for(let V=1;V<=6;V++)await e.evaluate(D=>window.scrollTo(0,D),Z*V/6),await k(900);let ee=await e.evaluate(()=>document.body.scrollHeight);if(ee===c)break;c=ee}await k(800);let p=null;try{let x=e.url();x&&/\/in\/[^/?#]/.test(x)&&(p=x.split("?")[0].replace(/\/+$/,""))}catch{}let f=await e.evaluate(()=>{let x=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),Z=new Set(["Ad Options","Don\u2019t want to see this","0 notifications","Explore Premium profiles","You might like","People you may know","Suggested for you","More profiles for you","Promoted"]),ee=h=>{let g=(h||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(g)},V={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},D=document.querySelector("main");if(!D)return V;let b=[...Array.from(D.querySelectorAll("h1")),...Array.from(D.querySelectorAll("h2"))],$=Array.from(D.querySelectorAll("h2")),ae=b.find(h=>{let g=h.textContent&&h.textContent.trim(),y=(g||"").replace(/\s*\(\d+\)$/,"").trim();return g&&g.length>1&&g.length<100&&!x.has(y)&&!Z.has(y)}),ce=ae?ae.textContent.trim():null,I=ae?ae.parentElement:null;for(;I&&I!==D&&!Array.from(I.children).filter(g=>g.tagName==="P").some(g=>{let y=g.textContent&&g.textContent.trim();return y&&y.length>5&&!ee(y)});)I=I.parentElement;let it=null,lt=null,at=null,Te=null;if(I&&I!==D){let h=Array.from(I.children).filter(y=>y.tagName==="P").filter(y=>{let J=y.textContent&&y.textContent.trim();return J&&J.length>5&&!ee(J)});if(h[0]&&(it=h[0].textContent.trim()),h[1]){let y=h[1].textContent.trim().split(/\s*[·•]\s*/);lt=y[0]||null,y.length>1&&(at=y.slice(1).join(" \xB7 "))}let g=Array.from(I.children).filter(y=>y.tagName==="DIV");for(let y=g.length-1;y>=0;y--){let J=g[y].textContent&&g[y].textContent.trim();if(J&&!(ce&&J.startsWith(ce))&&(Te=J.split(/[·•]/)[0].trim(),Te))break}}let ct=null;if(I){let h=I.querySelectorAll("p, span, div");for(let g of h){let y=(g.textContent||"").trim().replace(/^[·•]\s*/,"");if(y==="1st"||y==="2nd"||y==="3rd"){ct=y;break}}}let Rn=!!D.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),ut=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),Tn=ut&&ut.src||null,Ce=D.textContent||"",dt=null,ft=Ce.match(/(\d+\+?)\s+connections\b/i);ft&&(dt=ft[1]+" connections");let xe=null,mt=Ce.match(/(\d+)\s+mutual connection/i),pt=Ce.match(/and\s+(\d+)\s+other mutual/i),Dn=Ce.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);mt?xe=parseInt(mt[1],10):pt?xe=2+parseInt(pt[1],10):Dn&&(xe=2);let ht=null,gt=null,yt=$.find(h=>h.textContent&&h.textContent.trim()==="About");if(yt){let h=yt.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let g=(h.textContent||"").trim();g=g.replace(/^About\s*/,"").trim();let y=g.match(/Top skills\s*(.+?)$/i);if(y){let De=y[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Ln=>Ln.trim()).filter(Boolean);De.length>0&&De.length<10&&(gt=De)}g=g.split(/\n?…\s*more/i)[0].trim(),g=g.split(/\n?\.\.\.\s*more/i)[0].trim(),g=g.split(/\bTop skills\b/i)[0].trim(),g=g.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),ht=g||null}}let wt=null,bt=$.find(h=>h.textContent&&h.textContent.trim()==="Activity");if(bt){let h=bt.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let g=(h.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);g&&(wt=parseInt(g[1].replace(/,/g,""),10))}}let On=[...new Set($.map(h=>(h.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(h=>h&&h.length>1&&h.length<60&&h!==ce).filter(h=>x.has(h)))],me=document.body.textContent||"",Nn=/#OpenToWork\b/i.test(me)||/\bOpen to work\b/.test(me),jn=/#Hiring\b/i.test(me)||/\bI'?m hiring\b/i.test(me)||/\bWe are hiring\b/i.test(me);return{name:ce,title:it,location:Te,currentCompany:lt,currentSchool:at,connectionDegree:ct,hasVerifiedBadge:Rn,photoUrl:Tn,connectionsLevel:dt,mutualConnectionsCount:xe,followers:wt,openToWork:Nn,hiring:jn,about:ht,topSkills:gt,availableSections:On}});console.log(`Viewed: ${f.name} - ${f.title}`);let m=null,v=null,w=null,A=null,Q=null,X=null;if(o||r||s||i||l||a){let x=await Promise.resolve().then(()=>(nn(),tn));o&&(m=await x.extractExperienceFromDetails(e,t),console.log(` + Experience: ${m.length} entries`)),r&&(v=await x.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${v.length} entries`)),s&&(w=await x.extractEducationFromDetails(e,t),console.log(` + Education: ${w.length} entries`)),i&&(A=await x.extractSkillsFromDetails(e,t),console.log(` + Skills: ${A.length} entries`)),l&&(Q=await x.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${Q.length} entries`)),a&&(X=await x.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${X.length} entries`))}return{...f,profileUrl:t,resolvedUrl:p,...m!==null&&{experience:m},...v!==null&&{featured:v},...w!==null&&{education:w},...A!==null&&{skillsFull:A},...Q!==null&&{recommendations:Q},...X!==null&&{certifications:X}}}catch(u){console.error(`Error viewing profile ${t}:`,u.message);try{await e.goto("about:blank",{timeout:1e4}),await k(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(u.message||""))throw u;return null}}We();await we();he();async function un(e,t,n={}){let{maxVisits:o=10,delayBetween:r=4e3,skipRecentDays:s=7,verbose:i=!1,extractExperience:l=!1}=n,a={visited:0,skipped:0,errors:0},u=Date.now()-s*24*60*60*1e3;for(let c of t){if(a.visited>=o)break;if(!c.profileUrl)continue;let p=cn(c.profileUrl);if(p&&new Date(p).getTime()>u){a.skipped++;continue}try{let f=await on(e,c.profileUrl,{extractExperience:l}),m=c.source||"visit";if(f){let w={...f,source:m};l&&Array.isArray(f.experience)&&f.experience.length>0&&(w._lastEnrichedAt=new Date().toISOString()),He(c.profileUrl,w),f.resolvedUrl&&Ve(c.profileUrl,f.resolvedUrl)}an(c.profileUrl,{name:f?.name||c.name||null,source:m}),a.visited++,i?console.log(` [${a.visited}] ${f?.name||c.profileUrl} \u2014 ${f?.title?.slice(0,40)||"?"}`):a.visited%10===0&&console.log(` Visited: ${a.visited}`);let v=Math.random()*4e3;await k(r+v)}catch(f){a.errors++,i&&console.error(` Error visiting ${c.name||c.profileUrl}: ${f.message?.slice(0,60)}`);let m=(f.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 a}await we();import"dotenv/config";import*as j from"fs";import*as Y from"path";import{fileURLToPath as Go}from"url";import"dotenv/config";import{createGraphClient as Uo,resolveToken as qo}from"@ilivemylife/graph-sdk";import{config as Bo}from"dotenv";Bo();var dn=qo()||process.env.TOKEN;dn||(console.error(`
|
|
240
|
+
`});var an=G(()=>{});import"dotenv/config";import*as j from"fs";import*as O from"path";import{fileURLToPath as No}from"url";function Fo(){j.existsSync(se)||j.mkdirSync(se,{recursive:!0})}function Mo(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";j.writeFileSync(o,n);for(let r=0;r<3;r++)try{j.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function Uo(e){try{if(j.existsSync(e))return JSON.parse(j.readFileSync(e,"utf-8"))}catch{}return null}function dn(){qo=null,Bo=null,Ho=null,Vo=null,re=null}function Ye(){return re||(re=Uo(un)||{visits:[]},Array.isArray(re.visits)||(re.visits=[]),re)}function fn(e,t={}){if(!e)return;Fo();let n=Ye();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(un,n)}catch(r){console.error(`[!] Failed to save visit-log.json: ${r.message}`)}}function mn(e){let t=Ye();for(let n=t.visits.length-1;n>=0;n--)if(t.visits[n].profileUrl===e)return t.visits[n].date;return null}var Lo,Po,se,oi,ri,un,si,ii,qo,Bo,Ho,Vo,re,Ke=G(()=>{an();Lo=No(import.meta.url),Po=O.dirname(O.dirname(Lo)),se=process.env.DATA_DIR?O.resolve(process.env.DATA_DIR,"market-research"):O.join(Po,"market-research"),oi=O.join(se,"scouted-jobs.json"),ri=O.join(se,"discovered-people.json"),un=O.join(se,"visit-log.json"),si=O.join(se,"companies.json"),ii=O.join(se,"job-decisions.json");qo=null,Bo=null,Ho=null,Vo=null,re=null});import co from"puppeteer";import{addExtra as ao}from"puppeteer-extra";import uo from"puppeteer-extra-plugin-stealth";ye();await Pe();$e();$e();import Fe from"fs";import no from"path";var oo={headless:!1,defaultViewport:null,protocolTimeout:3e5},be=new Set,Ut=!1;async function Ie(){let e=[...be].map(t=>{try{return Promise.resolve(t.close()).catch(()=>{})}catch{return Promise.resolve()}});be.clear(),await Promise.race([Promise.all(e),new Promise(t=>setTimeout(t,5e3))])}function ro(){if(Ut)return;Ut=!0;let e=t=>async()=>{await Ie(),process.exit(t)};process.once("SIGINT",e(130)),process.once("SIGTERM",e(143)),process.once("SIGHUP",e(129)),process.once("uncaughtException",async t=>{await Ie(),console.error(t&&t.stack||t),process.exit(1)}),process.once("unhandledRejection",async t=>{await Ie(),console.error(t),process.exit(1)}),process.stdout.on("error",async t=>{t&&t.code==="EPIPE"&&(await Ie(),process.exit(0))}),process.on("exit",()=>{for(let t of be)try{let n=t.process&&t.process();n&&n.kill("SIGKILL")}catch{}})}function Me(e){return no.join(e,".ilml-browser-session.json")}function Vt(e,t={}){try{Fe.writeFileSync(Me(e),JSON.stringify({ownerPid:process.pid,startedAt:Date.now(),...t}))}catch{}}function so(e,t){try{let n=t.wsEndpoint&&t.wsEndpoint();Vt(e,n?{wsEndpoint:n}:{})}catch{}}function io(e){let t=Jt(e);t&&t.ownerPid===process.pid&&we(e)}function we(e){try{Fe.rmSync(Me(e),{force:!0})}catch{}}function Jt(e){try{return JSON.parse(Fe.readFileSync(Me(e),"utf-8"))}catch{return null}}function qt(e){if(!e||e===process.pid)return!0;try{return process.kill(e,0),!0}catch(t){return!t||t.code!=="ESRCH"}}function Bt(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 Ht(e,t,{probeTimeoutMs:n=4e3}={}){let o=Jt(t);if(!o)return"free";if(!o.wsEndpoint)return o.ownerPid&&o.ownerPid!==process.pid&&qt(o.ownerPid)?"live":(we(t),"free");let r=Symbol("timeout"),s=e.connect({browserWSEndpoint:o.wsEndpoint,defaultViewport:null}).catch(()=>null),i=await Bt(s,n,r);if(i===r)return s.then(l=>{if(l)try{l.disconnect()}catch{}}),"live";if(!i)return we(t),"free";if(qt(o.ownerPid)){try{i.disconnect()}catch{}return"live"}if(console.log(" (recovered an orphaned automation browser from a previous run \u2014 closing it)"),await Bt(i.close().then(()=>!0).catch(()=>!1),n,!1))return we(t),"free";try{i.disconnect()}catch{}return"live"}function lo(e,t){e&&(ro(),be.add(e),e.on("disconnected",()=>{be.delete(e),t&&we(t)}))}async function Wt(e,t={}){let n=$t(),o={...oo,...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 Ht(e,n)==="live")throw new Error(r);Vt(n);let s;try{s=await e.launch(o)}catch{if(await Ht(e,n)==="live")throw new Error(r);Dt(n);try{s=await e.launch(o)}catch(c){throw io(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: ${c.message})`)}}return lo(s,n),so(n,s),{browser:s,profileDir:n,needsSeed:Rt(n)}}async function Gt(e,t){if(!t||!t.needsSeed)return!1;if(!At())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(...Et()),Tt(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var Yt=ao(co);Yt.use(uo());async function Kt(){let{browser:e,profileDir:t,needsSeed:n}=await Wt(Yt),o=await e.newPage();return await o.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Gt(o,{profileDir:t,needsSeed:n}),console.log(" Browser launched (persistent profile)."),{browser:e,page:o}}ye();await Se();async function jo(e,t){let n=e.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: ilml linkedin login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await k(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function cn(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:s=!1,extractSkills:i=!1,extractRecommendations:c=!1,extractCertifications:l=!1}=n;try{await me(e,t,{readySelector:".scaffold-layout__main, main.scaffold-layout__main, .pv-top-card, section.pv-top-card",label:"profile"}),await k(1500),await Nt(e)&&(console.log(" Dismissed Premium overlay"),await k(1500),await jo(e,t));let a=0;for(let x=0;x<2;x++){let ee=await e.evaluate(()=>document.body.scrollHeight);for(let J=1;J<=6;J++)await e.evaluate(D=>window.scrollTo(0,D),ee*J/6),await k(900);let te=await e.evaluate(()=>document.body.scrollHeight);if(te===a)break;a=te}await k(800);let m=null;try{let x=e.url();x&&/\/in\/[^/?#]/.test(x)&&(m=x.split("?")[0].replace(/\/+$/,""))}catch{}let f=await e.evaluate(()=>{let x=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),ee=new Set(["Ad Options","Don\u2019t want to see this","0 notifications","Explore Premium profiles","You might like","People you may know","Suggested for you","More profiles for you","Promoted"]),te=h=>{let g=(h||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(g)},J={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},D=document.querySelector("main");if(!D)return J;let b=[...Array.from(D.querySelectorAll("h1")),...Array.from(D.querySelectorAll("h2"))],$=Array.from(D.querySelectorAll("h2")),ue=b.find(h=>{let g=h.textContent&&h.textContent.trim(),y=(g||"").replace(/\s*\(\d+\)$/,"").trim();return g&&g.length>1&&g.length<100&&!x.has(y)&&!ee.has(y)}),de=ue?ue.textContent.trim():null,I=ue?ue.parentElement:null;for(;I&&I!==D&&!Array.from(I.children).filter(g=>g.tagName==="P").some(g=>{let y=g.textContent&&g.textContent.trim();return y&&y.length>5&&!te(y)});)I=I.parentElement;let ut=null,dt=null,ft=null,je=null;if(I&&I!==D){let h=Array.from(I.children).filter(y=>y.tagName==="P").filter(y=>{let W=y.textContent&&y.textContent.trim();return W&&W.length>5&&!te(W)});if(h[0]&&(ut=h[0].textContent.trim()),h[1]){let y=h[1].textContent.trim().split(/\s*[·•]\s*/);dt=y[0]||null,y.length>1&&(ft=y.slice(1).join(" \xB7 "))}let g=Array.from(I.children).filter(y=>y.tagName==="DIV");for(let y=g.length-1;y>=0;y--){let W=g[y].textContent&&g[y].textContent.trim();if(W&&!(de&&W.startsWith(de))&&(je=W.split(/[·•]/)[0].trim(),je))break}}let mt=null;if(I){let h=I.querySelectorAll("p, span, div");for(let g of h){let y=(g.textContent||"").trim().replace(/^[·•]\s*/,"");if(y==="1st"||y==="2nd"||y==="3rd"){mt=y;break}}}let Nn=!!D.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),pt=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),Ln=pt&&pt.src||null,Ae=D.textContent||"",ht=null,gt=Ae.match(/(\d+\+?)\s+connections\b/i);gt&&(ht=gt[1]+" connections");let _e=null,yt=Ae.match(/(\d+)\s+mutual connection/i),wt=Ae.match(/and\s+(\d+)\s+other mutual/i),Pn=Ae.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);yt?_e=parseInt(yt[1],10):wt?_e=2+parseInt(wt[1],10):Pn&&(_e=2);let bt=null,St=null,vt=$.find(h=>h.textContent&&h.textContent.trim()==="About");if(vt){let h=vt.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let g=(h.textContent||"").trim();g=g.replace(/^About\s*/,"").trim();let y=g.match(/Top skills\s*(.+?)$/i);if(y){let Ne=y[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(qn=>qn.trim()).filter(Boolean);Ne.length>0&&Ne.length<10&&(St=Ne)}g=g.split(/\n?…\s*more/i)[0].trim(),g=g.split(/\n?\.\.\.\s*more/i)[0].trim(),g=g.split(/\bTop skills\b/i)[0].trim(),g=g.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),bt=g||null}}let kt=null,Ct=$.find(h=>h.textContent&&h.textContent.trim()==="Activity");if(Ct){let h=Ct.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let g=(h.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);g&&(kt=parseInt(g[1].replace(/,/g,""),10))}}let Fn=[...new Set($.map(h=>(h.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(h=>h&&h.length>1&&h.length<60&&h!==de).filter(h=>x.has(h)))],ge=document.body.textContent||"",Mn=/#OpenToWork\b/i.test(ge)||/\bOpen to work\b/.test(ge),Un=/#Hiring\b/i.test(ge)||/\bI'?m hiring\b/i.test(ge)||/\bWe are hiring\b/i.test(ge);return{name:de,title:ut,location:je,currentCompany:dt,currentSchool:ft,connectionDegree:mt,hasVerifiedBadge:Nn,photoUrl:Ln,connectionsLevel:ht,mutualConnectionsCount:_e,followers:kt,openToWork:Mn,hiring:Un,about:bt,topSkills:St,availableSections:Fn}});console.log(`Viewed: ${f.name} - ${f.title}`);let p=null,v=null,w=null,A=null,X=null,Z=null;if(o||r||s||i||c||l){let x=await Promise.resolve().then(()=>(ln(),sn));o&&(p=await x.extractExperienceFromDetails(e,t),console.log(` + Experience: ${p.length} entries`)),r&&(v=await x.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${v.length} entries`)),s&&(w=await x.extractEducationFromDetails(e,t),console.log(` + Education: ${w.length} entries`)),i&&(A=await x.extractSkillsFromDetails(e,t),console.log(` + Skills: ${A.length} entries`)),c&&(X=await x.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${X.length} entries`)),l&&(Z=await x.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${Z.length} entries`))}return{...f,profileUrl:t,resolvedUrl:m,...p!==null&&{experience:p},...v!==null&&{featured:v},...w!==null&&{education:w},...A!==null&&{skillsFull:A},...X!==null&&{recommendations:X},...Z!==null&&{certifications:Z}}}catch(u){console.error(`Error viewing profile ${t}:`,u.message);try{await e.goto("about:blank",{timeout:1e4}),await k(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(u.message||""))throw u;return null}}Ke();await Se();ye();async function pn(e,t,n={}){let{maxVisits:o=10,delayBetween:r=4e3,skipRecentDays:s=7,verbose:i=!1,extractExperience:c=!1}=n,l={visited:0,skipped:0,errors:0},u=Date.now()-s*24*60*60*1e3;for(let a of t){if(l.visited>=o)break;if(!a.profileUrl)continue;let m=mn(a.profileUrl);if(m&&new Date(m).getTime()>u){l.skipped++;continue}try{let f=await cn(e,a.profileUrl,{extractExperience:c}),p=a.source||"visit";if(f){let w={...f,source:p};c&&Array.isArray(f.experience)&&f.experience.length>0&&(w._lastEnrichedAt=new Date().toISOString()),We(a.profileUrl,w),f.resolvedUrl&&Ge(a.profileUrl,f.resolvedUrl)}fn(a.profileUrl,{name:f?.name||a.name||null,source:p}),l.visited++,i?console.log(` [${l.visited}] ${f?.name||a.profileUrl} \u2014 ${f?.title?.slice(0,40)||"?"}`):l.visited%10===0&&console.log(` Visited: ${l.visited}`);let v=Math.random()*4e3;await k(r+v)}catch(f){l.errors++,i&&console.error(` Error visiting ${a.name||a.profileUrl}: ${f.message?.slice(0,60)}`);let p=(f.message||"").toLowerCase();if(p.includes("detached")||p.includes("session closed")||p.includes("target closed")||p.includes("session expired")||p.includes("bounced to")||p.includes("authwall")||p.includes("checkpoint")||p.includes("redirected to login")){console.log(" Fatal browser/session error \u2014 stopping visits");break}}}return l}await Se();import"dotenv/config";import*as N from"fs";import*as K from"path";import{fileURLToPath as Xo}from"url";import"dotenv/config";import{createGraphClient as Jo,resolveToken as Wo}from"@ilivemylife/graph-sdk";import{config as Go}from"dotenv";Go();var hn=Wo()||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
|
-
`)}async function mn({scriptName:e,mode:t,status:n,summaryLines:o,error:r,stoppedReason:s,duration:i}){let l=process.env.NODE_RUN_REPORTS;if(!l||!Array.isArray(o)||o.length===0)return;let a=Wo({scriptName:e,mode:t,status:n,summaryLines:o,error:r,stoppedReason:s,duration:i});try{await fn.addMessage(l,a)}catch(u){console.error(`[runReport] Failed to post end-of-session message: ${u.message}`)}}var Yo=Go(import.meta.url),Ko=Y.dirname(Y.dirname(Yo)),Ge=process.env.DATA_DIR?Y.resolve(process.env.DATA_DIR,"collected-profiles"):Y.join(Ko,"collected-profiles"),Ye=Y.join(Ge,"run-log.json");function zo(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";j.writeFileSync(o,n);for(let r=0;r<3;r++)try{j.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function pn(){try{if(!j.existsSync(Ye))return{runs:[]};let e=JSON.parse(j.readFileSync(Ye,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function hn(e){j.existsSync(Ge)||j.mkdirSync(Ge,{recursive:!0});try{zo(Ye,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function gn(e,t="default"){let n=pn();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),hn(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 l=pn(),a=l.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 u=l.runs.find(c=>c.script===e.script&&c.status==="running"&&c.timestamp===new Date(e.startTime).toISOString());u&&(u.status=t,u.result=t,u.duration=Date.now()-e.startTime,u.stats=n,u.error=o,r=u.duration)}hn(l)}catch(l){console.error(`[runLog] Failed to end run: ${l.message}`)}let s=n&&Array.isArray(n.summaryLines)?n.summaryLines:null,i=n&&n.__deferReport===!0;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS&&!i){let l=t==="error"?"error":n&&n.dailyLimitHit?"quota-reached":"done";mn({scriptName:e.script,mode:e.mode,status:l,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(a=>console.error(`[runLog] postRunReport failed: ${a.message}`))}}import"dotenv/config";import*as d from"fs";import*as ot from"os";import*as S from"path";import{fileURLToPath as Sr}from"url";var Xe={};pe(Xe,{NAME:()=>Xo,VERSION:()=>Qo,up:()=>tr});import*as L from"fs";import*as _e from"path";var Qo=1,Xo="normalize-jobs-and-questions",Zo=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],er=50;function ze(e){return L.existsSync(e)?JSON.parse(L.readFileSync(e,"utf-8")):null}function Qe(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{L.writeFileSync(o,n)}catch(r){try{L.unlinkSync(o)}catch{}throw r}try{L.renameSync(o,e)}catch(r){try{L.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}async function tr(e,t){let n=_e.join(e,"jobs.json"),o=_e.join(t,"scouted-jobs.json"),r=_e.join(e,"application-questions.json"),s=ze(n)||{},i=ze(o)||{},l=0,a=[];for(let c of Object.keys(s)){if(!i[c])continue;let p=i[c],f=s[c];for(let m of Zo)p[m]!=null&&f[m]==null&&(f[m]=p[m]);a.push(c),l++}l>0?(Qe(n,s),console.log(` Phase 1: Merged ${l} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let u=ze(r);if(u&&Array.isArray(u.applications)){let c={},p=0;for(let f of u.applications){let m=f.jobId||"unknown";c[m]||(c[m]={applications:[]});let v=(f.questions||[]).map(w=>{let A={type:w.type||"input",question:w.question||"",answer:w.answer||""};return w.options&&(w.options.length<=er?A.options=w.options:(A.optionsOmitted=!0,p++)),w.page&&(A.page=w.page),w.wasPreFilled&&(A.wasPreFilled=!0),w.wasRetry&&(A.wasRetry=!0),A});c[m].applications.push({applicationId:f.applicationId,date:f.date,result:f.result||"submitted",formPages:f.formPages||null,duration:f.duration||null,retries:f.retries||0,failedField:f.failedField||null,questionCount:f.questionCount||v.length,questions:v})}Qe(r,c),console.log(` Phase 2: Rekeyed ${u.applications.length} applications by jobId (${Object.keys(c).length} unique jobs)`),p>0&&console.log(` Phase 2: Stripped bloated options from ${p} questions`)}else u&&!u.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(a.length>0){for(let c of a)delete i[c];Qe(o,i),console.log(` Phase 3: Removed ${a.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var Ze={};pe(Ze,{NAME:()=>or,VERSION:()=>nr,up:()=>ir});import*as P from"fs";import*as yn from"path";var nr=2,or="reset-unread-flags";function rr(e){return P.existsSync(e)?JSON.parse(P.readFileSync(e,"utf-8")):null}function sr(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 ir(e){let t=yn.join(e,"conversations.json"),n=rr(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}sr(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:()=>ar,VERSION:()=>lr,up:()=>mr});import*as F from"fs";import*as wn from"path";var lr=3,ar="recompute-last-message-by",cr=new Set(["draft","confirmed","rejected","needs_review"]);function ur(e){return F.existsSync(e)?JSON.parse(F.readFileSync(e,"utf-8")):null}function dr(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{F.writeFileSync(o,n)}catch(r){try{F.unlinkSync(o)}catch{}throw r}try{F.renameSync(o,e)}catch(r){try{F.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}function fr(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!cr.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 mr(e){let t=wn.join(e,"conversations.json"),n=ur(t);if(!n){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let o=process.env.LINKEDIN_NAME;if(!o||typeof o!="string"||!o.trim())throw new Error(`LINKEDIN_NAME env var is not set. Migration v003 needs your display name to determine which messages are yours vs theirs. Set LINKEDIN_NAME in your .env (or run "ilml plugin config linkedin set LINKEDIN_NAME 'Your Name'") and retry.`);let r=0,s=0,i=0;for(let l of Object.keys(n)){let a=n[l];if(!a||typeof a!="object")continue;Object.prototype.hasOwnProperty.call(a,"_cardSynced")&&(delete a._cardSynced,s++);let u=Array.isArray(a.messages)?a.messages:[],c=fr(u,o),p=c==="me"?"awaiting_reply":"unanswered_by_us";a.lastMessageBy!==c&&i++,a.lastMessageBy=c,a.conversationStatus=p,r++}if(r===0){console.log(" No conversations to recompute.");return}dr(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:()=>hr,VERSION:()=>pr,up:()=>br});import*as M from"fs";import*as bn from"path";var pr=4,hr="split-connection-timestamps",gr=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function yr(e){if(!M.existsSync(e))return null;let t=M.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function wr(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{M.writeFileSync(o,n)}catch(r){try{M.unlinkSync(o)}catch{}throw r}try{M.renameSync(o,e)}catch(r){try{M.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}async function br(e){let t=bn.join(e,"people.json"),n=yr(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++,gr.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}wr(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 we();We();var vr=Sr(import.meta.url),kr=S.dirname(vr),Cr=S.dirname(S.dirname(kr));function xr(e){return e&&(e==="~"?ot.homedir():e.startsWith("~/")||e.startsWith("~\\")?S.join(ot.homedir(),e.slice(2)):e)}var U=process.env.DATA_DIR?S.resolve(xr(process.env.DATA_DIR)):Cr,ie=S.join(U,"collected-profiles"),le=S.join(U,"market-research"),T=S.join(U,".schema-version"),Sn=[S.join(ie,".schema-version"),S.join(le,".schema-version")],K=4,H=[{version:1,module:Xe},{version:2,module:Ze},{version:3,module:et},{version:4,module:tt}];(function(){H.sort((o,r)=>o.version-r.version);let t=new Set;for(let o of H){if(!Number.isInteger(o.version)||o.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(o.version)} (must be positive integer)`);if(t.has(o.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${o.version}`);t.add(o.version);let r=o.module;if(!r||typeof r.up!="function")throw new Error(`MIGRATION_REGISTRY: v${o.version} module is missing up()`);if(r.VERSION!==void 0&&r.VERSION!==o.version)throw new Error(`MIGRATION_REGISTRY: v${o.version} entry does not match module VERSION (${r.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let n=H.length?H[H.length-1].version:0;if(n!==K)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${K}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<H.length;o++){let r=o+1;if(H[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${H[o].version}`)}})();function xn(){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=Jo({token:hn});function Yo(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 Ko={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 zo(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 Qo({scriptName:e,mode:t,status:n,summaryLines:o,error:r,stoppedReason:s,duration:i}){let c=n==="error"||n==="stopped"?n==="error"?"\u2717":"\u26A0":n==="quota-reached"?"\u26A0":"\u2713",l=n==="error"?"stopped early":n==="stopped"?`stopped \u2014 ${s||"did not finish"}`:n==="quota-reached"?"daily limit reached":"done",u=Ko[e]||e,a=t&&t!=="default"?` \xB7 ${t}`:"",m=new Date().toISOString().slice(0,16).replace("T"," "),f=i?` \xB7 ${Yo(i)}`:"",p=[];p.push(`## ${c} ${u} \u2014 ${l}`),p.push(`_${m}${a}${f}_`),p.push("");for(let v of o)p.push(`- ${v}`);if(n==="error"){p.push(""),p.push(`**What happened:** ${zo(r)}`);let v=String(r||"").replace(/\s+/g," ").trim();v&&p.push(`_Technical detail: ${v.slice(0,140)}_`)}return p.join(`
|
|
245
|
+
`)}async function yn({scriptName:e,mode:t,status:n,summaryLines:o,error:r,stoppedReason:s,duration:i}){let c=process.env.NODE_RUN_REPORTS;if(!c||!Array.isArray(o)||o.length===0)return;let l=Qo({scriptName:e,mode:t,status:n,summaryLines:o,error:r,stoppedReason:s,duration:i});try{await gn.addMessage(c,l)}catch(u){console.error(`[runReport] Failed to post end-of-session message: ${u.message}`)}}var Zo=Xo(import.meta.url),er=K.dirname(K.dirname(Zo)),ze=process.env.DATA_DIR?K.resolve(process.env.DATA_DIR,"collected-profiles"):K.join(er,"collected-profiles"),Qe=K.join(ze,"run-log.json");function tr(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 wn(){try{if(!N.existsSync(Qe))return{runs:[]};let e=JSON.parse(N.readFileSync(Qe,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function bn(e){N.existsSync(ze)||N.mkdirSync(ze,{recursive:!0});try{tr(Qe,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function Sn(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),bn(n),{script:e,mode:t,startTime:o.getTime(),runIndex:n.runs.length-1}}function Xe(e,t,n=null,o=null){if(!e)return;let r=null;try{let c=wn(),l=c.runs[e.runIndex];if(l&&l.status==="running"&&l.script===e.script)l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=n,l.error=o,r=l.duration;else{let u=c.runs.find(a=>a.script===e.script&&a.status==="running"&&a.timestamp===new Date(e.startTime).toISOString());u&&(u.status=t,u.result=t,u.duration=Date.now()-e.startTime,u.stats=n,u.error=o,r=u.duration)}bn(c)}catch(c){console.error(`[runLog] Failed to end run: ${c.message}`)}let s=n&&Array.isArray(n.summaryLines)?n.summaryLines:null,i=n&&n.__deferReport===!0;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS&&!i){let c=t==="error"?"error":n&&n.dailyLimitHit?"quota-reached":"done";yn({scriptName:e.script,mode:e.mode,status:c,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(l=>console.error(`[runLog] postRunReport failed: ${l.message}`))}}import"dotenv/config";import*as d from"fs";import*as lt from"os";import*as S from"path";import{fileURLToPath as Tr}from"url";var tt={};fe(tt,{NAME:()=>or,VERSION:()=>nr,up:()=>ir});import*as L from"fs";import*as Re from"path";var nr=1,or="normalize-jobs-and-questions",rr=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],sr=50;function Ze(e){return L.existsSync(e)?JSON.parse(L.readFileSync(e,"utf-8")):null}function et(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{L.writeFileSync(o,n)}catch(r){try{L.unlinkSync(o)}catch{}throw r}try{L.renameSync(o,e)}catch(r){try{L.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}async function ir(e,t){let n=Re.join(e,"jobs.json"),o=Re.join(t,"scouted-jobs.json"),r=Re.join(e,"application-questions.json"),s=Ze(n)||{},i=Ze(o)||{},c=0,l=[];for(let a of Object.keys(s)){if(!i[a])continue;let m=i[a],f=s[a];for(let p of rr)m[p]!=null&&f[p]==null&&(f[p]=m[p]);l.push(a),c++}c>0?(et(n,s),console.log(` Phase 1: Merged ${c} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let u=Ze(r);if(u&&Array.isArray(u.applications)){let a={},m=0;for(let f of u.applications){let p=f.jobId||"unknown";a[p]||(a[p]={applications:[]});let v=(f.questions||[]).map(w=>{let A={type:w.type||"input",question:w.question||"",answer:w.answer||""};return w.options&&(w.options.length<=sr?A.options=w.options:(A.optionsOmitted=!0,m++)),w.page&&(A.page=w.page),w.wasPreFilled&&(A.wasPreFilled=!0),w.wasRetry&&(A.wasRetry=!0),A});a[p].applications.push({applicationId:f.applicationId,date:f.date,result:f.result||"submitted",formPages:f.formPages||null,duration:f.duration||null,retries:f.retries||0,failedField:f.failedField||null,questionCount:f.questionCount||v.length,questions:v})}et(r,a),console.log(` Phase 2: Rekeyed ${u.applications.length} applications by jobId (${Object.keys(a).length} unique jobs)`),m>0&&console.log(` Phase 2: Stripped bloated options from ${m} questions`)}else u&&!u.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(l.length>0){for(let a of l)delete i[a];et(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 nt={};fe(nt,{NAME:()=>cr,VERSION:()=>lr,up:()=>dr});import*as P from"fs";import*as vn from"path";var lr=2,cr="reset-unread-flags";function ar(e){return P.existsSync(e)?JSON.parse(P.readFileSync(e,"utf-8")):null}function ur(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 dr(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}ur(t,n),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var ot={};fe(ot,{NAME:()=>mr,VERSION:()=>fr,up:()=>wr});import*as F from"fs";import*as kn from"path";var fr=3,mr="recompute-last-message-by",pr=new Set(["draft","confirmed","rejected","needs_review"]);function hr(e){return F.existsSync(e)?JSON.parse(F.readFileSync(e,"utf-8")):null}function gr(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{F.writeFileSync(o,n)}catch(r){try{F.unlinkSync(o)}catch{}throw r}try{F.renameSync(o,e)}catch(r){try{F.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}function yr(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!pr.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 wr(e){let t=kn.join(e,"conversations.json"),n=hr(t);if(!n){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let o=process.env.LINKEDIN_NAME;if(!o||typeof o!="string"||!o.trim())throw new Error(`LINKEDIN_NAME env var is not set. Migration v003 needs your display name to determine which messages are yours vs theirs. Set LINKEDIN_NAME in your .env (or run "ilml plugin config linkedin set LINKEDIN_NAME 'Your Name'") and retry.`);let r=0,s=0,i=0;for(let c of Object.keys(n)){let l=n[c];if(!l||typeof l!="object")continue;Object.prototype.hasOwnProperty.call(l,"_cardSynced")&&(delete l._cardSynced,s++);let u=Array.isArray(l.messages)?l.messages:[],a=yr(u,o),m=a==="me"?"awaiting_reply":"unanswered_by_us";l.lastMessageBy!==a&&i++,l.lastMessageBy=a,l.conversationStatus=m,r++}if(r===0){console.log(" No conversations to recompute.");return}gr(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 rt={};fe(rt,{NAME:()=>Sr,VERSION:()=>br,up:()=>xr});import*as M from"fs";import*as Cn from"path";var br=4,Sr="split-connection-timestamps",vr=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function kr(e){if(!M.existsSync(e))return null;let t=M.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function Cr(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{M.writeFileSync(o,n)}catch(r){try{M.unlinkSync(o)}catch{}throw r}try{M.renameSync(o,e)}catch(r){try{M.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let s=new Error(`File locked: ${e} (${r.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=r.code,s}throw r}}async function xr(e){let t=Cn.join(e,"people.json"),n=kr(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++,vr.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}Cr(t,n),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${o} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}var st={};fe(st,{NAME:()=>Ar,VERSION:()=>Er,up:()=>Rr});import*as U from"fs";import*as xn from"path";var Er=5,Ar="rename-headline-to-title",ie=/[·•]\s*(1st|2nd|3rd)\+?/i,_r=e=>(e||"").replace(/\s+/g," ").trim(),xe=e=>_r(e).replace(/^[+·•\s]+/,"").replace(/[·•\s]+$/,"");function $r(e){if(!U.existsSync(e))return null;let t=U.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function Ir(e,t){let n=JSON.stringify(t),o=e+".tmp";try{U.writeFileSync(o,n)}catch(r){try{U.unlinkSync(o)}catch{}throw r}try{U.renameSync(o,e)}catch(r){try{U.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 Rr(e,t){let n=xn.join(t,"discovered-people.json"),o=$r(n);if(!o||typeof o!="object"){console.log(" discovered-people.json not found \u2014 nothing to migrate.");return}let r=Array.isArray(o)?o:Object.values(o),s=0,i=0,c=0;for(let l of r)if(!(!l||typeof l!="object")){if(s++,l.name&&ie.test(l.name)){let u=xe(String(l.name).split(ie)[0]),a=String(l.name).match(/[·•]\s*(?:1st|2nd|3rd)\+?\s*(.+)$/i),m=a?xe(a[1]):"";u&&(l.name=u,i++),m&&(!l.headline||ie.test(String(l.headline))||!xe(l.headline))&&(l.headline=m)}if(Object.prototype.hasOwnProperty.call(l,"headline")){let u=xe(l.headline||"");ie.test(u)&&(u=""),(!l.title||ie.test(String(l.title)))&&(l.title=u||(l.title&&!ie.test(String(l.title))?l.title:null)||null),delete l.headline,c++}else if(typeof l.title=="string"){let u=xe(l.title);u&&!ie.test(u)&&u!==l.title&&(l.title=u)}}if(c===0&&i===0){console.log(` Scanned ${s} discovered people \u2014 already unified (no headline field, clean names).`);return}Ir(n,o),console.log(` discovered-people.json: scanned ${s}, de-glued ${i} names, moved ${c} headline\u2192title.`),console.log(" Every record now carries a single `title` field (matches people.json).")}await Se();Ke();var Dr=Tr(import.meta.url),Or=S.dirname(Dr),jr=S.dirname(S.dirname(Or));function Nr(e){return e&&(e==="~"?lt.homedir():e.startsWith("~/")||e.startsWith("~\\")?S.join(lt.homedir(),e.slice(2)):e)}var q=process.env.DATA_DIR?S.resolve(Nr(process.env.DATA_DIR)):jr,ce=S.join(q,"collected-profiles"),ae=S.join(q,"market-research"),T=S.join(q,".schema-version"),En=[S.join(ce,".schema-version"),S.join(ae,".schema-version")],z=5,V=[{version:1,module:tt},{version:2,module:nt},{version:3,module:ot},{version:4,module:rt},{version:5,module:st}];(function(){V.sort((o,r)=>o.version-r.version);let t=new Set;for(let o of V){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=V.length?V[V.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<V.length;o++){let r=o+1;if(V[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${V[o].version}`)}})();function In(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
246
246
|
[FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
|
|
247
|
-
`),process.exit(1));try{d.mkdirSync(
|
|
248
|
-
[FATAL] Cannot create DATA_DIR (${
|
|
249
|
-
`),process.exit(1))}let e;try{e=d.statSync(
|
|
250
|
-
[FATAL] DATA_DIR (${
|
|
247
|
+
`),process.exit(1));try{d.mkdirSync(q,{recursive:!0})}catch(t){t.code!=="EEXIST"&&(console.error(`
|
|
248
|
+
[FATAL] Cannot create DATA_DIR (${q}): ${t.message}`),console.error(` Fix the path or permissions and try again.
|
|
249
|
+
`),process.exit(1))}let e;try{e=d.statSync(q)}catch(t){console.error(`
|
|
250
|
+
[FATAL] DATA_DIR (${q}) is not accessible: ${t.message}
|
|
251
251
|
`),process.exit(1)}e.isDirectory()||(console.error(`
|
|
252
|
-
[FATAL] DATA_DIR (${
|
|
253
|
-
`),process.exit(1));for(let t of[
|
|
252
|
+
[FATAL] DATA_DIR (${q}) 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.
|
|
253
|
+
`),process.exit(1));for(let t of[ce,ae]){let n;try{n=d.lstatSync(t)}catch(o){if(o.code==="ENOENT")continue;throw o}n.isSymbolicLink()&&(console.error(`
|
|
254
254
|
[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.
|
|
255
|
-
`),process.exit(1))}}var
|
|
256
|
-
[FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${t.pid}`),console.error(` Started at: ${t.startedAt||"(unknown)"}`),console.error(` Lock file: ${
|
|
255
|
+
`),process.exit(1))}}var le=S.join(q,".migration-lock");function Lr(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return d.writeFileSync(le,e,{flag:"wx"}),!0}catch(o){if(o.code!=="EEXIST")throw o}let t;try{t=JSON.parse(d.readFileSync(le,"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(`
|
|
256
|
+
[FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${t.pid}`),console.error(` Started at: ${t.startedAt||"(unknown)"}`),console.error(` Lock file: ${le}
|
|
257
257
|
`),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.
|
|
258
|
-
`),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=
|
|
258
|
+
`),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=le+".tmp";try{return d.writeFileSync(n,e),d.renameSync(n,le),!0}catch(o){try{d.unlinkSync(n)}catch{}throw new Error(`Failed to take over stale migration lock: ${o.message}`)}}function ct(){try{if(JSON.parse(d.readFileSync(le,"utf-8")).pid!==process.pid)return;d.unlinkSync(le)}catch{}}var An=!1;function Pr(){if(An)return;An=!0;let e=()=>{try{ct()}catch{}process.exit(1)};for(let t of["SIGINT","SIGTERM","SIGHUP"])try{process.on(t,e)}catch{}}function Fr(){if(d.existsSync(T))return;let e=[],t=[];for(let s of En)if(d.existsSync(s))try{e.push({file:s,schema:Te(s)})}catch(i){t.push({file:s,err:i.message})}if(t.length>0){console.error(`
|
|
259
259
|
[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(`
|
|
260
260
|
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.
|
|
261
261
|
`),process.exit(1)}if(e.length===0)return;let n=e.map(s=>s.schema.version);if(new Set(n).size>1){console.error(`
|
|
262
262
|
[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.
|
|
263
|
-
`),process.exit(1)}let o=e[0].schema,r=T+".tmp";try{d.writeFileSync(r,JSON.stringify(o,null,2)),d.renameSync(r,T)}catch(s){try{d.unlinkSync(r)}catch{}throw s}for(let s of
|
|
263
|
+
`),process.exit(1)}let o=e[0].schema,r=T+".tmp";try{d.writeFileSync(r,JSON.stringify(o,null,2)),d.renameSync(r,T)}catch(s){try{d.unlinkSync(r)}catch{}throw s}for(let s of En)if(d.existsSync(s))try{d.unlinkSync(s)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${T}`)}function Mr(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 Te(e){let t=d.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function _n(){if(Fr(),!d.existsSync(T))return{version:0,migrations:[]};let e;try{e=Te(T)}catch(n){if(n.code==="ENOENT")return{version:0,migrations:[]};console.error(`
|
|
264
264
|
[FATAL] ${T} is not valid JSON: ${n.message}`),console.error(" Refusing to proceed \u2014 silently treating it as 'fresh install' would re-apply"),console.error(" every migration on top of already-migrated data and corrupt it."),console.error(' Repair the file (set it to {"version":N,"migrations":[...]} matching your real state)'),console.error(` or restore from the *.pre-vNNN.backup files if you have them.
|
|
265
|
-
`),process.exit(1)}let t
|
|
265
|
+
`),process.exit(1)}let t=Mr(e);return t===null&&(console.error(`
|
|
266
266
|
[FATAL] ${T} has invalid structure:`),console.error(` ${JSON.stringify(e)?.slice(0,200)||"(unparseable)"}`),console.error(' Expected shape: { "version": <integer>, "migrations": [...] }'),console.error(` Repair the file or restore from a backup.
|
|
267
|
-
`),process.exit(1)),t}function
|
|
268
|
-
[FATAL] Your data schema is at v${t}, but this plugin build only understands up to v${
|
|
269
|
-
`),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${
|
|
267
|
+
`),process.exit(1)),t}function Rn(e){try{d.chmodSync(e,384)}catch{}}function Ur(e){if(In(),d.existsSync(T))try{if(d.lstatSync(T).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${T}. Refusing to write through it (potential symlink attack). Remove the link and re-run.`)}catch(n){if(n.message?.includes("symbolic link"))throw n}let t=T+".tmp";try{d.writeFileSync(t,JSON.stringify(e,null,2)),Rn(t),d.renameSync(t,T)}catch(n){try{d.unlinkSync(t)}catch{}throw n}}function $n(e,t){if(!d.existsSync(e))return;let n=`.pre-v${String(t).padStart(3,"0")}.backup`,o=d.readdirSync(e).filter(c=>{let l=c.toLowerCase();if(l.includes(".backup")||l===".schema-version"||l.endsWith(".tmp"))return!1;try{return d.statSync(S.join(e,c)).isFile()}catch{return!1}}),r=0,s=0,i=[];for(let c of o){let l=S.join(e,c),u=S.join(e,c+n);if(d.existsSync(u)){s++;continue}try{Dn(l,u),r++}catch(a){i.push({file:c,err:a.message})}}if(i.length>0){let c=new Error(`Failed to back up ${i.length} file(s) in ${S.basename(e)}/: `+i.map(l=>`${l.file} (${l.err})`).join(", "));throw c.code="BACKUP_INCOMPLETE",c}if(r>0||s>0){let c=s>0?` (${s} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${r} files in ${S.basename(e)}/ (${n})${c}`)}}var it=!1;async function Tn(){if(it)return;In(),Jr();let t=_n().version;if(t===z){it=!0;return}Pr(),Lr(),process.on("exit",ct),t>z&&(console.error(`
|
|
268
|
+
[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.
|
|
269
|
+
`),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}.
|
|
270
270
|
`),process.exit(1)),console.log(`
|
|
271
|
-
\u{1F4E6} Schema migration: v${t} \u2192 v${
|
|
271
|
+
\u{1F4E6} Schema migration: v${t} \u2192 v${z}`);let n=Wr();if(!n.ok){console.error(`
|
|
272
272
|
[FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let r of n.broken)console.error(` ${r.dir}/${r.file}: ${r.err}`);console.error(`
|
|
273
273
|
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'.
|
|
274
|
-
`),process.exit(1)}let o=
|
|
275
|
-
Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,i=`.pre-${s}.backup`;try{
|
|
276
|
-
[FATAL] Pre-migration backup failed for ${s}: ${
|
|
277
|
-
`),process.exit(1)}let
|
|
278
|
-
[FATAL] Migration ${s} failed: ${
|
|
274
|
+
`),process.exit(1)}let o=V.filter(r=>r.version>t);for(let r of o){console.log(`
|
|
275
|
+
Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,i=`.pre-${s}.backup`;try{$n(ce,r.version),$n(ae,r.version)}catch(l){console.error(`
|
|
276
|
+
[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.
|
|
277
|
+
`),process.exit(1)}let c=r.module;try{await c.up(ce,ae)}catch(l){console.error(`
|
|
278
|
+
[FATAL] Migration ${s} failed: ${l.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let u=Gr(i);u.ok?(console.error(` \u2713 Auto-rollback restored ${u.restored} files. Schema stays at v${t}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
|
|
279
279
|
`)):(console.error(` [!] Auto-rollback INCOMPLETE: ${u.error}`),console.error(` Manual recovery: copy *${i} files back over the originals.
|
|
280
280
|
`))}catch(u){console.error(` [!] Auto-rollback CRASHED while restoring: ${u.message}`),console.error(` Manual recovery: copy *${i} files back over the originals.
|
|
281
|
-
`)}process.exit(1)}try{let
|
|
282
|
-
[FATAL] Migration ${s} applied successfully but schema version file could NOT be updated: ${
|
|
283
|
-
`),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{
|
|
284
|
-
\u2713 Schema is now at v${
|
|
285
|
-
`)}var
|
|
281
|
+
`)}process.exit(1)}try{let l=new Date().toISOString(),u={version:r.version,name:c.NAME||s,appliedAt:l},a=_n();a.version=r.version,a.migratedAt=l,a.migrations=a.migrations||[],a.migrations.push(u),Ur(a)}catch(l){console.error(`
|
|
282
|
+
[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.
|
|
283
|
+
`),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{tn()}catch{}try{dn()}catch{}it=!0,ct(),console.log(`
|
|
284
|
+
\u2713 Schema is now at v${z}
|
|
285
|
+
`)}var qr=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Br(e){let t=e.toLowerCase();return qr.some(n=>n.test(t))}var Hr=6e4;function Vr(){let e=Date.now(),t=[];for(let n of[q,ce,ae]){if(!d.existsSync(n))continue;let o;try{o=d.readdirSync(n)}catch{continue}for(let r of o){if(!Br(r))continue;let s=S.join(n,r);try{let i=d.statSync(s);if(!i.isFile()||e-i.mtimeMs<Hr)continue;t.push({dir:n,file:r,fullPath:s})}catch{}}}return t}function Jr({verbose:e=!1}={}){let t=Vr();if(t.length===0)return e&&console.log(" No orphan .tmp files found."),0;let n=0;for(let o of t)try{d.unlinkSync(o.fullPath),n++,e&&console.log(` Removed orphan: ${S.basename(o.dir)}/${o.file}`)}catch(r){console.warn(` [!] Could not remove orphan ${o.fullPath}: ${r.message}`)}return!e&&n>0&&console.log(` Cleaned up ${n} orphan .tmp file(s) from previous run.`),n}function Wr(){let e=[];for(let t of[ce,ae]){if(!d.existsSync(t))continue;let n=d.readdirSync(t).filter(o=>{let r=o.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let o of n){let r=S.join(t,o);try{Te(r)}catch(s){e.push({dir:S.basename(t),file:o,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function Gr(e){let t=[],n=[];for(let s of[ce,ae]){if(!d.existsSync(s))continue;let i=d.readdirSync(s).filter(c=>c.endsWith(e));for(let c of i){let l=S.join(s,c),u=c.slice(0,-e.length),a=S.join(s,u);try{u.toLowerCase().endsWith(".json")?Te(l):d.accessSync(l,d.constants.R_OK),t.push({backupPath:l,originalPath:a,fileName:c,dir:s})}catch(m){n.push(`${S.basename(s)}/${c}: ${m.message}`)}}}if(n.length>0)return{ok:!1,error:n.join("; "),restored:0};let o=0,r=[];for(let{backupPath:s,originalPath:i,fileName:c,dir:l}of t)try{Dn(s,i),o++}catch(u){r.push(`${S.basename(l)}/${c}: ${u.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:o}:{ok:!0,restored:o}}function Dn(e,t){let n=t+".tmp";try{d.copyFileSync(e,n),Rn(n)}catch(o){try{d.unlinkSync(n)}catch{}throw o}try{d.renameSync(n,t)}catch(o){try{d.unlinkSync(n)}catch{}if(o.code==="EPERM"||o.code==="EBUSY"){let r=new Error(`File locked: ${t} (${o.code}). On Windows this is usually antivirus / Search Indexer / the file open in another app. Close anything that might be holding it and re-run.`);throw r.code=o.code,r}throw o}}await Tn();var Q=process.argv.slice(2),De=parseInt(Q.find(e=>e.startsWith("--max="))?.split("=")[1]||"10"),Ee=Q.includes("--connections"),On=Q.find(e=>e.startsWith("--match-title="))?.split("=").slice(1).join("=")||null,_=On?Qr(On):null,Yr=Q.includes("--list"),Kr=Q.includes("--verbose"),at=Q.includes("--with-experience"),zr=Q.includes("--help")||Q.includes("-h");zr&&(console.log(`
|
|
286
286
|
enrich-profiles \u2014 batch-visit contacts in people.json missing About text
|
|
287
287
|
|
|
288
288
|
USAGE
|
|
@@ -325,12 +325,12 @@ WHEN TO USE
|
|
|
325
325
|
- You want to backfill in a controlled batch (\u2264 10 per day) before reaching
|
|
326
326
|
out, so AI drafting has full context.
|
|
327
327
|
- Use --connections to keep ban risk low.
|
|
328
|
-
`),process.exit(0));function
|
|
329
|
-
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`),console.log(" PROFILE ENRICHMENT QUEUE"),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),console.log(` Total people: ${t}`),console.log(` With "about": ${n} (${(n/t*100).toFixed(1)}%)`),console.log(` Missing "about": ${o}`),console.log(` Skipped (needs reply): ${u}`),console.log(` Visitable (queue): ${r.length}`),console.log(` Never fully visited: ${
|
|
330
|
-
`)}function
|
|
328
|
+
`),process.exit(0));function Qr(e){try{return new RegExp(e,"i")}catch(t){console.error(`Invalid regex for --match-title: ${t.message}`),process.exit(1)}}var Xr=new Set(["pending","sent_with_note","sent_without_note"]);function Zr(e){return!e.about||!e.about.trim()}function es(e){return!Xr.has(e.connectionStatus)}function jn(){let e=Y(),t=Je(),n=new Set,o=new Set;for(let c of Object.values(t))c.profileUrl&&n.add(c.profileUrl),(c.unread===!0||c.actionNeeded==="reply"||c.situation==="needs_our_reply"||c.conversationStatus==="unanswered_by_us")&&c.profileUrl&&o.add(c.profileUrl);let s=Object.entries(e).filter(([c,l])=>c&&c.startsWith("http")).filter(([,c])=>Zr(c)).filter(([,c])=>es(c)).filter(([c])=>!o.has(c)).map(([c,l])=>({profileUrl:c,name:l.name,person:l,hasConversation:n.has(c)}));Ee&&(s=s.filter(c=>c.person.connectionStatus==="connected")),_&&(s=s.filter(c=>_.test(c.person.title||"")));function i(c){let l=c.person.connectionStatus==="connected";return l&&c.hasConversation?1:l?2:_&&_.test(c.person.title||"")?3:c.hasConversation?4:5}return s.sort((c,l)=>{let u=i(c),a=i(l);if(u!==a)return u-a;let m=c.person.lastFullVisitAt||"",f=l.person.lastFullVisitAt||"";return m.localeCompare(f)}),s.map(c=>({profileUrl:c.profileUrl,name:c.name,source:"enrich-profile"}))}function ts(){let e=Y(),t=Object.keys(e).length,n=Object.values(e).filter(m=>m.about&&m.about.trim()).length,o=t-n,r=jn(),s={connWithConv:0,conn:0,titleMatch:0,withConv:0,other:0},i=e,c=Je(),l=new Set(Object.values(c).map(m=>m.profileUrl).filter(Boolean)),u=Object.values(c).filter(m=>m.profileUrl&&(m.unread===!0||m.actionNeeded==="reply"||m.situation==="needs_our_reply"||m.conversationStatus==="unanswered_by_us")).length,a=0;for(let m of r){let f=i[m.profileUrl],p=f.connectionStatus==="connected",v=_&&_.test(f.title||""),w=l.has(m.profileUrl);f.lastFullVisitAt||a++,p&&w?s.connWithConv++:p?s.conn++:v?s.titleMatch++:w?s.withConv++:s.other++}console.log(`
|
|
329
|
+
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`),console.log(" PROFILE ENRICHMENT QUEUE"),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),console.log(` Total people: ${t}`),console.log(` With "about": ${n} (${(n/t*100).toFixed(1)}%)`),console.log(` Missing "about": ${o}`),console.log(` Skipped (needs reply): ${u}`),console.log(` Visitable (queue): ${r.length}`),console.log(` Never fully visited: ${a} (gone first)`),_&&console.log(` Title-match filter: /${_.source}/i`),Ee&&console.log(" Connections-only: yes"),console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),console.log(` Tier 1 (conn+conv): ${s.connWithConv}`),console.log(` Tier 2 (connection): ${s.conn}`),console.log(` Tier 3 (title match): ${s.titleMatch}${_?"":" (no --match-title set)"}`),console.log(` Tier 4 (conversation): ${s.withConv}`),console.log(` Tier 5 (other): ${s.other}`),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),console.log(` At ${De}/day \u2192 ~${Math.ceil(r.length/De)} days to clear queue
|
|
330
|
+
`)}function ns(){console.log(""),console.log(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"),console.log(" \u2551 \u26A0 BAN-RISK WARNING \u2014 please read \u2551"),console.log(" \u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563"),console.log(" \u2551 This script visits LinkedIn profiles WITHOUT performing any \u2551"),console.log(" \u2551 follow-up action (no message, no connect request, no like). \u2551"),console.log(" \u2551 LinkedIn has previously flagged accounts for exactly this \u2551"),console.log(' \u2551 pattern with a "we noticed unusual activity" warning. \u2551'),console.log(" \u2551 \u2551"),console.log(" \u2551 Safer alternative: let data accumulate organically through \u2551"),console.log(" \u2551 apply / outreach / funnel / visit \u2014 those visits HAVE a \u2551"),console.log(" \u2551 purpose and don't trip the same heuristic. \u2551"),console.log(" \u2551 \u2551"),console.log(" \u2551 If you proceed, keep --max small (\u226410) and run at most once \u2551"),console.log(" \u2551 per day. Your account, your call. \u2551"),console.log(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"),console.log("")}async function os(){if(console.log(`
|
|
331
331
|
LinkedIn Profile Enricher
|
|
332
|
-
`),
|
|
333
|
-
`);return}let t=
|
|
334
|
-
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`),console.log(" Enrichment Complete"),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),console.log(` Visited: ${s.visited}`),console.log(` Skipped (recent): ${s.skipped}`),console.log(` Errors: ${s.errors}`),console.log(` Have "about" now: ${
|
|
335
|
-
`),
|
|
336
|
-
Error:`,s.message),
|
|
332
|
+
`),Yr){ts();return}ns(),at&&(console.log(""),console.log(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"),console.log(" \u2551 \u26A0 --with-experience: extra ban-risk warning \u2551"),console.log(" \u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563"),console.log(" \u2551 Each visit now does TWO page loads (main + /details/ \u2551"),console.log(" \u2551 experience/). That doubles LinkedIn's view-counter signal \u2551"),console.log(" \u2551 per profile. Keep --max low (\u226410) and run rarely. \u2551"),console.log(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"),console.log(""));let e=jn();if(console.log(` Queue size: ${e.length}`),console.log(` Max visits this session: ${De}`),_&&console.log(` Title filter: /${_.source}/i`),Ee&&console.log(" Connections only: yes"),at&&console.log(" With experience: yes (2\xD7 page loads per profile)"),console.log(""),e.length===0){console.log(` Nothing to enrich \u2014 every visitable profile already has "about".
|
|
333
|
+
`);return}let t=Ee&&_?"connections+title":Ee?"connections":_?`title=${_.source}`:"all",n=Sn("enrich-profiles",t),{browser:o,page:r}=await Kt();try{let s=await pn(r,e,{maxVisits:De,verbose:Kr,skipRecentDays:7,extractExperience:at}),i=Y(),c=0;for(let l of e.slice(0,s.visited+s.skipped))i[l.profileUrl]?.about?.trim()&&c++;console.log(`
|
|
334
|
+
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`),console.log(" Enrichment Complete"),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),console.log(` Visited: ${s.visited}`),console.log(` Skipped (recent): ${s.skipped}`),console.log(` Errors: ${s.errors}`),console.log(` Have "about" now: ${c} / ${s.visited+s.skipped}`),console.log(`\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
|
|
335
|
+
`),Xe(n,"success",s)}catch(s){console.error(`
|
|
336
|
+
Error:`,s.message),Xe(n,"error",null,s.message)}finally{await o.close().catch(()=>{})}}os().catch(e=>{console.error("Enrich-profiles failed:",e),process.exit(1)});
|