ilml-plugin-linkedin 1.20.0 → 1.20.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,12 @@
1
- var ze=Object.defineProperty;var H=(e,n)=>{for(var o in n)ze(e,o,{get:n[o],enumerable:!0})};import{pathToFileURL as Co}from"url";var K={jan:0,feb:1,mar:2,apr:3,may:4,jun:5,jul:6,aug:7,sep:8,oct:9,nov:10,dec:11},Qe={sunday:0,monday:1,tuesday:2,wednesday:3,thursday:4,friday:5,saturday:6};function U(e){let n=e.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);if(!n)return null;let o=parseInt(n[1],10),t=parseInt(n[2],10),r=n[3].toUpperCase()==="PM";return r&&o!==12&&(o+=12),!r&&o===12&&(o=0),{hours:o,minutes:t}}function W(e,n){if(!e)return null;let o=e.trim();if(!o)return null;if(n=n||new Date,/^just\s*now$/i.test(o))return n.toISOString();if(/^today\b/i.test(o)||/^\d{1,2}:\d{2}\s*(AM|PM)$/i.test(o)){let l=U(o),c=new Date(n);return l?c.setHours(l.hours,l.minutes,0,0):c.setHours(0,0,0,0),c.toISOString()}let t=o.match(/^(Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)\s*(.*)/i);if(t){let l=Qe[t[1].toLowerCase()],c=U(t[2]||""),a=new Date(n),u=a.getDay()-l;return u<=0&&(u+=7),a.setDate(a.getDate()-u),c?a.setHours(c.hours,c.minutes,0,0):a.setHours(0,0,0,0),a.toISOString()}let r=o.match(/^([A-Z][a-z]+)\s+(\d{1,2}),?\s+(\d{4})\s*(.*)/i);if(r){let l=K[r[1].toLowerCase().slice(0,3)];if(l===void 0)return null;let c=parseInt(r[2],10),a=parseInt(r[3],10),f=U(r[4]||"");return new Date(a,l,c,f?.hours||0,f?.minutes||0,0,0).toISOString()}let s=o.match(/^([A-Z][a-z]+)\s+(\d{1,2}),\s*(.*)/i);if(s){let l=K[s[1].toLowerCase().slice(0,3)];if(l===void 0)return null;let c=parseInt(s[2],10),a=U(s[3]||""),f=n.getFullYear(),u=new Date(f,l,c,a?.hours||0,a?.minutes||0,0,0);return u>n&&u.setFullYear(f-1),u.toISOString()}let i=o.match(/^([A-Z][a-z]+)\s+(\d{1,2})\s*(.*)/i);if(i){let l=K[i[1].toLowerCase().slice(0,3)];if(l===void 0)return null;let c=parseInt(i[2],10),a=U(i[3]||""),f=n.getFullYear(),u=new Date(f,l,c,a?.hours||0,a?.minutes||0,0,0);return u>n&&u.setFullYear(f-1),u.toISOString()}return null}async function q(e){let n=Math.floor(Math.random()*2001),o=e+n;return new Promise(t=>setTimeout(t,o))}import{getPluginConfig as Xe}from"@ilivemylife/graph-sdk";var Ze=await Xe();for(let[e,n]of Object.entries(Ze))process.env[e]===void 0&&(process.env[e]=n);var en=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Fo=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),nn=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.REJECTED,N.NEEDS_REVIEW]));import"dotenv/config";import*as y from"fs";import*as S from"path";import{fileURLToPath as on}from"url";var tn=on(import.meta.url),rn=S.dirname(S.dirname(tn)),T=process.env.DATA_DIR?S.resolve(process.env.DATA_DIR,"collected-profiles"):S.join(rn,"collected-profiles"),z=S.join(T,"people.json"),qo=S.join(T,"jobs.json"),Bo=S.join(T,"quota.json"),Jo=S.join(T,"conversations.json"),Ho=S.join(T,"sync-state.json"),Wo=S.join(T,"application-questions.json"),Vo=S.join(T,"profile-history"),ae=(e,n)=>{let o=parseInt(e,10);return Number.isInteger(o)&&o>=0?o:n},Yo=ae(process.env.CONNECT_MAX_DAILY,20),Go=ae(process.env.CONNECT_MAX_WEEKLY,100),M=null,sn=null,cn=null,ln=null,an=null,un=null;function ue(){M=null,sn=null,cn=null,ln=null,an=null,un=null}function fe(){y.existsSync(T)||y.mkdirSync(T,{recursive:!0})}function fn(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";y.writeFileSync(t,o);for(let r=0;r<3;r++)try{y.renameSync(t,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(e,n){if(!y.existsSync(e))return null;try{let o=JSON.parse(y.readFileSync(e,"utf-8"));try{y.copyFileSync(e,e+".backup")}catch{}return o}catch(o){console.error(`[!] ${n} is corrupted: ${o.message}`),console.error(` File: ${S.resolve(e)}`);let t=e+".backup";if(y.existsSync(t))try{let r=JSON.parse(y.readFileSync(t,"utf-8"));console.error(` Restored from ${t}`);try{y.copyFileSync(t,e)}catch{}return r}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{y.copyFileSync(e,e+".corrupted")}catch{}return null}}function V(e){if(!e)return null;let n=e.match(/\/in\/([^/?#]+)/);return n?n[1].toLowerCase():null}function B(){return M||(fe(),M=pn(z,"people.json")||{},M)}function pe(e){fe(),M=e;try{fn(z,e)}catch(n){console.error(`[!] Failed to save people.json: ${n.message}`),console.error(` Path: ${S.resolve(z)}`)}}import yn from"puppeteer";import{addExtra as Sn}from"puppeteer-extra";import wn from"puppeteer-extra-plugin-stealth";import I from"fs";import R from"path";var dn="cookies.json";function de(){let e=process.env.ILML_SCOPE_DIR;return e?R.join(e,"plugins-state","linkedin","cookies.json"):dn}function me(){let e=de();if(!I.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let n;try{n=I.readFileSync(e,"utf-8")}catch(t){throw new Error(`Failed to read cookies at ${e}: ${t.message}. Run: ilml linkedin login`)}let o;try{o=JSON.parse(n)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(o)||o.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return o}function he(){return I.existsSync(de())}function mn(){let e=process.env.ILML_SCOPE_DIR;return e?R.join(e,"plugins-state","linkedin"):"."}function ge(e){let n=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(n)?n:"default"}function hn(){let e=process.env.MY_LINKEDIN_URL,n=e&&e.match(/\/in\/([^/?#]+)/);return n&&n[1]?ge(n[1]):"default"}function ye(e){let n=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(n)return I.existsSync(n)||I.mkdirSync(n,{recursive:!0}),R.resolve(n);let o=ge(e||hn()),t=R.join(mn(),"chrome-profile",o);return I.existsSync(t)||I.mkdirSync(t,{recursive:!0}),R.resolve(t)}var Se=".ilml-seeded";function we(e){return!I.existsSync(R.join(e,Se))}function be(e){try{I.writeFileSync(R.join(e,Se),new Date().toISOString())}catch{}}function ve(e){let n=0;for(let o of["SingletonLock","SingletonCookie","SingletonSocket"])try{I.rmSync(R.join(e,o),{force:!0}),n++}catch{}return n}var gn={headless:!1,defaultViewport:null,protocolTimeout:3e5};async function ke(e,n={}){let o=ye(),t={...gn,...n,userDataDir:o},r;try{r=await e.launch(t)}catch{ve(o);try{r=await e.launch(t)}catch(i){throw new Error(`Could not open the LinkedIn automation Chrome profile at ${o}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${i.message})`)}}return{browser:r,profileDir:o,needsSeed:we(o)}}async function Ae(e,n){if(!n||!n.needsSeed)return!1;if(!he())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(...me()),be(n.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var Ce=Sn(yn);Ce.use(wn());async function $e(){let{browser:e,profileDir:n,needsSeed:o}=await ke(Ce),t=async()=>{console.log(`
2
- Closing browser...`);try{await e.close()}catch{}process.exit(0)};process.on("SIGINT",t),process.on("SIGTERM",t);let r=await e.newPage();return await r.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Ae(r,{profileDir:n,needsSeed:o}),console.log(" Browser launched (persistent profile)."),{browser:e,page:r}}import"dotenv/config";import*as A from"fs";import*as j from"path";import{fileURLToPath as $n}from"url";import"dotenv/config";import{createGraphClient as bn,resolveToken as vn}from"@ilivemylife/graph-sdk";import{config as kn}from"dotenv";kn();var Ee=vn()||process.env.TOKEN;Ee||(console.error(`
1
+ var ze=Object.defineProperty;var H=(e,n)=>{for(var t in n)ze(e,t,{get:n[t],enumerable:!0})};import{pathToFileURL as At}from"url";var K={jan:0,feb:1,mar:2,apr:3,may:4,jun:5,jul:6,aug:7,sep:8,oct:9,nov:10,dec:11},Qe={sunday:0,monday:1,tuesday:2,wednesday:3,thursday:4,friday:5,saturday:6};function U(e){let n=e.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);if(!n)return null;let t=parseInt(n[1],10),o=parseInt(n[2],10),r=n[3].toUpperCase()==="PM";return r&&t!==12&&(t+=12),!r&&t===12&&(t=0),{hours:t,minutes:o}}function W(e,n){if(!e)return null;let t=e.trim();if(!t)return null;if(n=n||new Date,/^just\s*now$/i.test(t))return n.toISOString();if(/^today\b/i.test(t)||/^\d{1,2}:\d{2}\s*(AM|PM)$/i.test(t)){let l=U(t),c=new Date(n);return l?c.setHours(l.hours,l.minutes,0,0):c.setHours(0,0,0,0),c.toISOString()}let o=t.match(/^(Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)\s*(.*)/i);if(o){let l=Qe[o[1].toLowerCase()],c=U(o[2]||""),a=new Date(n),u=a.getDay()-l;return u<=0&&(u+=7),a.setDate(a.getDate()-u),c?a.setHours(c.hours,c.minutes,0,0):a.setHours(0,0,0,0),a.toISOString()}let r=t.match(/^([A-Z][a-z]+)\s+(\d{1,2}),?\s+(\d{4})\s*(.*)/i);if(r){let l=K[r[1].toLowerCase().slice(0,3)];if(l===void 0)return null;let c=parseInt(r[2],10),a=parseInt(r[3],10),f=U(r[4]||"");return new Date(a,l,c,f?.hours||0,f?.minutes||0,0,0).toISOString()}let s=t.match(/^([A-Z][a-z]+)\s+(\d{1,2}),\s*(.*)/i);if(s){let l=K[s[1].toLowerCase().slice(0,3)];if(l===void 0)return null;let c=parseInt(s[2],10),a=U(s[3]||""),f=n.getFullYear(),u=new Date(f,l,c,a?.hours||0,a?.minutes||0,0,0);return u>n&&u.setFullYear(f-1),u.toISOString()}let i=t.match(/^([A-Z][a-z]+)\s+(\d{1,2})\s*(.*)/i);if(i){let l=K[i[1].toLowerCase().slice(0,3)];if(l===void 0)return null;let c=parseInt(i[2],10),a=U(i[3]||""),f=n.getFullYear(),u=new Date(f,l,c,a?.hours||0,a?.minutes||0,0,0);return u>n&&u.setFullYear(f-1),u.toISOString()}return null}async function q(e){let n=Math.floor(Math.random()*2001),t=e+n;return new Promise(o=>setTimeout(o,t))}import{getPluginConfig as Xe}from"@ilivemylife/graph-sdk";var Ze=await Xe();for(let[e,n]of Object.entries(Ze))process.env[e]===void 0&&(process.env[e]=n);var en=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Nt=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),nn=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.REJECTED,N.NEEDS_REVIEW]));import"dotenv/config";import*as y from"fs";import*as S from"path";import{fileURLToPath as tn}from"url";var on=tn(import.meta.url),rn=S.dirname(S.dirname(on)),T=process.env.DATA_DIR?S.resolve(process.env.DATA_DIR,"collected-profiles"):S.join(rn,"collected-profiles"),z=S.join(T,"people.json"),Ut=S.join(T,"jobs.json"),qt=S.join(T,"quota.json"),Bt=S.join(T,"conversations.json"),Jt=S.join(T,"sync-state.json"),Ht=S.join(T,"application-questions.json"),Wt=S.join(T,"profile-history"),ae=(e,n)=>{let t=parseInt(e,10);return Number.isInteger(t)&&t>=0?t:n},Vt=ae(process.env.CONNECT_MAX_DAILY,20),Yt=ae(process.env.CONNECT_MAX_WEEKLY,100),M=null,sn=null,cn=null,ln=null,an=null,un=null;function ue(){M=null,sn=null,cn=null,ln=null,an=null,un=null}function fe(){y.existsSync(T)||y.mkdirSync(T,{recursive:!0})}function fn(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";y.writeFileSync(o,t);for(let r=0;r<3;r++)try{y.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(e,n){if(!y.existsSync(e))return null;try{let t=JSON.parse(y.readFileSync(e,"utf-8"));try{y.copyFileSync(e,e+".backup")}catch{}return t}catch(t){console.error(`[!] ${n} is corrupted: ${t.message}`),console.error(` File: ${S.resolve(e)}`);let o=e+".backup";if(y.existsSync(o))try{let r=JSON.parse(y.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{y.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{y.copyFileSync(e,e+".corrupted")}catch{}return null}}function V(e){if(!e)return null;let n=e.match(/\/in\/([^/?#]+)/);return n?n[1].toLowerCase():null}function B(){return M||(fe(),M=pn(z,"people.json")||{},M)}function pe(e){fe(),M=e;try{fn(z,e)}catch(n){console.error(`[!] Failed to save people.json: ${n.message}`),console.error(` Path: ${S.resolve(z)}`)}}import yn from"puppeteer";import{addExtra as Sn}from"puppeteer-extra";import wn from"puppeteer-extra-plugin-stealth";import I from"fs";import R from"path";var dn="cookies.json";function de(){let e=process.env.ILML_SCOPE_DIR;return e?R.join(e,"plugins-state","linkedin","cookies.json"):dn}function me(){let e=de();if(!I.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let n;try{n=I.readFileSync(e,"utf-8")}catch(o){throw new Error(`Failed to read cookies at ${e}: ${o.message}. Run: ilml linkedin login`)}let t;try{t=JSON.parse(n)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(t)||t.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return t}function he(){return I.existsSync(de())}function mn(){let e=process.env.ILML_SCOPE_DIR;return e?R.join(e,"plugins-state","linkedin"):"."}function ge(e){let n=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(n)?n:"default"}function hn(){let e=process.env.MY_LINKEDIN_URL,n=e&&e.match(/\/in\/([^/?#]+)/);return n&&n[1]?ge(n[1]):"default"}function ye(e){let n=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(n)return I.existsSync(n)||I.mkdirSync(n,{recursive:!0}),R.resolve(n);let t=ge(e||hn()),o=R.join(mn(),"chrome-profile",t);return I.existsSync(o)||I.mkdirSync(o,{recursive:!0}),R.resolve(o)}var Se=".ilml-seeded";function we(e){return!I.existsSync(R.join(e,Se))}function be(e){try{I.writeFileSync(R.join(e,Se),new Date().toISOString())}catch{}}function ve(e){let n=0;for(let t of["SingletonLock","SingletonCookie","SingletonSocket"])try{I.rmSync(R.join(e,t),{force:!0}),n++}catch{}return n}var gn={headless:!1,defaultViewport:null,protocolTimeout:3e5};async function ke(e,n={}){let t=ye(),o={...gn,...n,userDataDir:t},r;try{r=await e.launch(o)}catch{ve(t);try{r=await e.launch(o)}catch(i){throw new Error(`Could not open the LinkedIn automation Chrome profile at ${t}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${i.message})`)}}return{browser:r,profileDir:t,needsSeed:we(t)}}async function Ae(e,n){if(!n||!n.needsSeed)return!1;if(!he())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(...me()),be(n.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var Ce=Sn(yn);Ce.use(wn());async function $e(){let{browser:e,profileDir:n,needsSeed:t}=await ke(Ce),o=async()=>{console.log(`
2
+ Closing browser...`);try{await e.close()}catch{}process.exit(0)};process.on("SIGINT",o),process.on("SIGTERM",o);let r=await e.newPage();return await r.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Ae(r,{profileDir:n,needsSeed:t}),console.log(" Browser launched (persistent profile)."),{browser:e,page:r}}import"dotenv/config";import*as A from"fs";import*as O from"path";import{fileURLToPath as $n}from"url";import"dotenv/config";import{createGraphClient as bn,resolveToken as vn}from"@ilivemylife/graph-sdk";import{config as kn}from"dotenv";kn();var Ee=vn()||process.env.TOKEN;Ee||(console.error(`
3
3
  [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.
4
4
  `),console.error(" Easiest way:"),console.error(" 1. npm install -g @ilivemylife/graph-sdk"),console.error(` 2. ilml login your@email.com yourpassword
5
5
  `),console.error(` Or add ILML_TOKEN=... to .env
6
- `),process.exit(1));var xe=bn({token:Ee});function An(e){if(!e||e<1e3)return`${e||0}ms`;let n=Math.round(e/1e3);if(n<60)return`${n}s`;let o=Math.floor(n/60),t=n%60;return t?`${o}m ${t}s`:`${o}m`}function Cn({scriptName:e,mode:n,status:o,error:t,duration:r}){let s=o==="error"?"\u2717":o==="quota-reached"?"\u26A0":"\u2713",i=new Date().toISOString().slice(0,16).replace("T"," "),l=r?` ${An(r)}`:"",c=o==="error"?`error${t?`: ${String(t).slice(0,80)}`:""}`:o==="quota-reached"?"daily quota reached":"done",a=n&&n!=="default"?` (${n})`:"";return`${s} ${e}${a} \u2014 ${c} \u2014 ${i}${l}`}async function Ie({scriptName:e,mode:n,status:o,summaryLines:t,error:r,duration:s}){let i=process.env.NODE_RUN_REPORTS;if(!i||!Array.isArray(t)||t.length===0)return;let c=`**${Cn({scriptName:e,mode:n,status:o,error:r,duration:s})}**
6
+ `),process.exit(1));var xe=bn({token:Ee});function An(e){if(!e||e<1e3)return`${e||0}ms`;let n=Math.round(e/1e3);if(n<60)return`${n}s`;let t=Math.floor(n/60),o=n%60;return o?`${t}m ${o}s`:`${t}m`}function Cn({scriptName:e,mode:n,status:t,error:o,duration:r}){let s=t==="error"?"\u2717":t==="quota-reached"?"\u26A0":"\u2713",i=new Date().toISOString().slice(0,16).replace("T"," "),l=r?` ${An(r)}`:"",c=t==="error"?`error${o?`: ${String(o).slice(0,80)}`:""}`:t==="quota-reached"?"daily quota reached":"done",a=n&&n!=="default"?` (${n})`:"";return`${s} ${e}${a} \u2014 ${c} \u2014 ${i}${l}`}async function Ie({scriptName:e,mode:n,status:t,summaryLines:o,error:r,duration:s}){let i=process.env.NODE_RUN_REPORTS;if(!i||!Array.isArray(o)||o.length===0)return;let c=`**${Cn({scriptName:e,mode:n,status:t,error:r,duration:s})}**
7
7
 
8
- ${t.join(`
9
- `)}`;try{await xe.addMessage(i,c)}catch(a){console.error(`[runReport] Failed to post end-of-session message: ${a.message}`)}}var En=$n(import.meta.url),xn=j.dirname(j.dirname(En)),Q=process.env.DATA_DIR?j.resolve(process.env.DATA_DIR,"collected-profiles"):j.join(xn,"collected-profiles"),X=j.join(Q,"run-log.json");function In(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";A.writeFileSync(t,o);for(let r=0;r<3;r++)try{A.renameSync(t,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 De(){try{if(!A.existsSync(X))return{runs:[]};let e=JSON.parse(A.readFileSync(X,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Te(e){A.existsSync(Q)||A.mkdirSync(Q,{recursive:!0});try{In(X,e)}catch(n){console.error(`[!] Failed to save run-log.json: ${n.message}`)}}function _e(e,n="default"){let o=De();for(let i of o.runs)i.status==="running"&&(i.status="interrupted",i.result="interrupted",i.timestamp&&(i.duration=Date.now()-new Date(i.timestamp).getTime()));let t=new Date,r={timestamp:t.toISOString(),script:e,mode:n,status:"running",result:null,duration:null,stats:null,error:null};o.runs.push(r);let s=Date.now()-30*24*60*60*1e3;return o.runs=o.runs.filter(i=>new Date(i.timestamp).getTime()>s),Te(o),{script:e,mode:n,startTime:t.getTime(),runIndex:o.runs.length-1}}function Z(e,n,o=null,t=null){if(!e)return;let r=null;try{let i=De(),l=i.runs[e.runIndex];if(l&&l.status==="running"&&l.script===e.script)l.status=n,l.result=n,l.duration=Date.now()-e.startTime,l.stats=o,l.error=t,r=l.duration;else{let c=i.runs.find(a=>a.script===e.script&&a.status==="running"&&a.timestamp===new Date(e.startTime).toISOString());c&&(c.status=n,c.result=n,c.duration=Date.now()-e.startTime,c.stats=o,c.error=t,r=c.duration)}Te(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let s=o&&Array.isArray(o.summaryLines)?o.summaryLines:null;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS){let i=n==="error"?"error":o&&o.dailyLimitHit?"quota-reached":"done";Ie({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:t,duration:r??Date.now()-e.startTime}).catch(l=>console.error(`[runLog] postRunReport failed: ${l.message}`))}}import"dotenv/config";import*as p from"fs";import*as ce from"os";import*as h from"path";import{fileURLToPath as io}from"url";var oe={};H(oe,{NAME:()=>Tn,VERSION:()=>Dn,up:()=>jn});import*as C from"fs";import*as Y from"path";var Dn=1,Tn="normalize-jobs-and-questions",_n=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],Rn=50;function ee(e){return C.existsSync(e)?JSON.parse(C.readFileSync(e,"utf-8")):null}function ne(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{C.writeFileSync(t,o)}catch(r){try{C.unlinkSync(t)}catch{}throw r}try{C.renameSync(t,e)}catch(r){try{C.unlinkSync(t)}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 jn(e,n){let o=Y.join(e,"jobs.json"),t=Y.join(n,"scouted-jobs.json"),r=Y.join(e,"application-questions.json"),s=ee(o)||{},i=ee(t)||{},l=0,c=[];for(let f of Object.keys(s)){if(!i[f])continue;let u=i[f],m=s[f];for(let g of _n)u[g]!=null&&m[g]==null&&(m[g]=u[g]);c.push(f),l++}l>0?(ne(o,s),console.log(` Phase 1: Merged ${l} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let a=ee(r);if(a&&Array.isArray(a.applications)){let f={},u=0;for(let m of a.applications){let g=m.jobId||"unknown";f[g]||(f[g]={applications:[]});let v=(m.questions||[]).map(d=>{let w={type:d.type||"input",question:d.question||"",answer:d.answer||""};return d.options&&(d.options.length<=Rn?w.options=d.options:(w.optionsOmitted=!0,u++)),d.page&&(w.page=d.page),d.wasPreFilled&&(w.wasPreFilled=!0),d.wasRetry&&(w.wasRetry=!0),w});f[g].applications.push({applicationId:m.applicationId,date:m.date,result:m.result||"submitted",formPages:m.formPages||null,duration:m.duration||null,retries:m.retries||0,failedField:m.failedField||null,questionCount:m.questionCount||v.length,questions:v})}ne(r,f),console.log(` Phase 2: Rekeyed ${a.applications.length} applications by jobId (${Object.keys(f).length} unique jobs)`),u>0&&console.log(` Phase 2: Stripped bloated options from ${u} questions`)}else a&&!a.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(c.length>0){for(let f of c)delete i[f];ne(t,i),console.log(` Phase 3: Removed ${c.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 te={};H(te,{NAME:()=>Nn,VERSION:()=>On,up:()=>Pn});import*as $ from"fs";import*as Re from"path";var On=2,Nn="reset-unread-flags";function Fn(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function Ln(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{$.writeFileSync(t,o)}catch(r){try{$.unlinkSync(t)}catch{}throw r}try{$.renameSync(t,e)}catch(r){try{$.unlinkSync(t)}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 Pn(e){let n=Re.join(e,"conversations.json"),o=Fn(n);if(!o){console.log(" conversations.json not found \u2014 nothing to reset.");return}let t=0;for(let r of Object.keys(o))o[r].unread===!0&&(o[r].unread=!1,t++);if(t===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}Ln(n,o),console.log(` Reset unread=false on ${t} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var re={};H(re,{NAME:()=>Un,VERSION:()=>Mn,up:()=>Wn});import*as E from"fs";import*as je from"path";var Mn=3,Un="recompute-last-message-by",qn=new Set(["draft","confirmed","rejected","needs_review"]);function Bn(e){return E.existsSync(e)?JSON.parse(E.readFileSync(e,"utf-8")):null}function Jn(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{E.writeFileSync(t,o)}catch(r){try{E.unlinkSync(t)}catch{}throw r}try{E.renameSync(t,e)}catch(r){try{E.unlinkSync(t)}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 Hn(e,n){if(!e||e.length===0)return"them";let o=e.filter(s=>!qn.has(s.status));if(o.length===0)return"them";let t=o.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=t.length>0?t:[...o].reverse();for(let s of r){let i=s.sender;if(i===n)return"me";if(i!=="Unknown"&&i!=="")return"them"}return"them"}async function Wn(e){let n=je.join(e,"conversations.json"),o=Bn(n);if(!o){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let t=process.env.LINKEDIN_NAME;if(!t||typeof t!="string"||!t.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(o)){let c=o[l];if(!c||typeof c!="object")continue;Object.prototype.hasOwnProperty.call(c,"_cardSynced")&&(delete c._cardSynced,s++);let a=Array.isArray(c.messages)?c.messages:[],f=Hn(a,t),u=f==="me"?"awaiting_reply":"unanswered_by_us";c.lastMessageBy!==f&&i++,c.lastMessageBy=f,c.conversationStatus=u,r++}if(r===0){console.log(" No conversations to recompute.");return}Jn(n,o),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 se={};H(se,{NAME:()=>Yn,VERSION:()=>Vn,up:()=>Qn});import*as x from"fs";import*as Oe from"path";var Vn=4,Yn="split-connection-timestamps",Gn=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function Kn(e){if(!x.existsSync(e))return null;let n=x.readFileSync(e,"utf-8");return n.charCodeAt(0)===65279&&(n=n.slice(1)),JSON.parse(n)}function zn(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{x.writeFileSync(t,o)}catch(r){try{x.unlinkSync(t)}catch{}throw r}try{x.renameSync(t,e)}catch(r){try{x.unlinkSync(t)}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 Qn(e){let n=Oe.join(e,"people.json"),o=Kn(n);if(!o||typeof o!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let t=0,r=0;for(let s of Object.keys(o)){let i=o[s];!i||typeof i!="object"||(r++,Gn.has(i.connectionStatus)&&i.connectionDate&&!i.requestedConnectionAt&&(i.requestedConnectionAt=i.connectionDate,i.connectionDate=null,t++))}if(t===0){console.log(` Scanned ${r} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}zn(n,o),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${t} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}import"dotenv/config";import*as k from"path";import{fileURLToPath as Xn}from"url";var Zn=Xn(import.meta.url),eo=k.dirname(k.dirname(Zn)),J=process.env.DATA_DIR?k.resolve(process.env.DATA_DIR,"market-research"):k.join(eo,"market-research"),It=k.join(J,"scouted-jobs.json"),Dt=k.join(J,"discovered-people.json"),Tt=k.join(J,"visit-log.json"),_t=k.join(J,"companies.json"),Rt=k.join(J,"job-decisions.json");function Ne(){no=null,oo=null,to=null,ro=null,so=null}var no=null;var oo=null;var to=null;var ro=null;var so=null;var co=io(import.meta.url),lo=h.dirname(co),ao=h.dirname(h.dirname(lo));function uo(e){return e&&(e==="~"?ce.homedir():e.startsWith("~/")||e.startsWith("~\\")?h.join(ce.homedir(),e.slice(2)):e)}var D=process.env.DATA_DIR?h.resolve(uo(process.env.DATA_DIR)):ao,L=h.join(D,"collected-profiles"),P=h.join(D,"market-research"),b=h.join(D,".schema-version"),Fe=[h.join(L,".schema-version"),h.join(P,".schema-version")],O=4,_=[{version:1,module:oe},{version:2,module:te},{version:3,module:re},{version:4,module:se}];(function(){_.sort((t,r)=>t.version-r.version);let n=new Set;for(let t of _){if(!Number.isInteger(t.version)||t.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(t.version)} (must be positive integer)`);if(n.has(t.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${t.version}`);n.add(t.version);let r=t.module;if(!r||typeof r.up!="function")throw new Error(`MIGRATION_REGISTRY: v${t.version} module is missing up()`);if(r.VERSION!==void 0&&r.VERSION!==t.version)throw new Error(`MIGRATION_REGISTRY: v${t.version} entry does not match module VERSION (${r.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let o=_.length?_[_.length-1].version:0;if(o!==O)throw new Error(`MIGRATION_REGISTRY: highest version v${o} but CURRENT_SCHEMA_VERSION=${O}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let t=0;t<_.length;t++){let r=t+1;if(_[t].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${t} but found v${_[t].version}`)}})();function Ue(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
8
+ ${o.join(`
9
+ `)}`;try{await xe.addMessage(i,c)}catch(a){console.error(`[runReport] Failed to post end-of-session message: ${a.message}`)}}var En=$n(import.meta.url),xn=O.dirname(O.dirname(En)),Q=process.env.DATA_DIR?O.resolve(process.env.DATA_DIR,"collected-profiles"):O.join(xn,"collected-profiles"),X=O.join(Q,"run-log.json");function In(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";A.writeFileSync(o,t);for(let r=0;r<3;r++)try{A.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function De(){try{if(!A.existsSync(X))return{runs:[]};let e=JSON.parse(A.readFileSync(X,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Te(e){A.existsSync(Q)||A.mkdirSync(Q,{recursive:!0});try{In(X,e)}catch(n){console.error(`[!] Failed to save run-log.json: ${n.message}`)}}function _e(e,n="default"){let t=De();for(let i of t.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:n,status:"running",result:null,duration:null,stats:null,error:null};t.runs.push(r);let s=Date.now()-30*24*60*60*1e3;return t.runs=t.runs.filter(i=>new Date(i.timestamp).getTime()>s),Te(t),{script:e,mode:n,startTime:o.getTime(),runIndex:t.runs.length-1}}function Z(e,n,t=null,o=null){if(!e)return;let r=null;try{let i=De(),l=i.runs[e.runIndex];if(l&&l.status==="running"&&l.script===e.script)l.status=n,l.result=n,l.duration=Date.now()-e.startTime,l.stats=t,l.error=o,r=l.duration;else{let c=i.runs.find(a=>a.script===e.script&&a.status==="running"&&a.timestamp===new Date(e.startTime).toISOString());c&&(c.status=n,c.result=n,c.duration=Date.now()-e.startTime,c.stats=t,c.error=o,r=c.duration)}Te(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let s=t&&Array.isArray(t.summaryLines)?t.summaryLines:null;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS){let i=n==="error"?"error":t&&t.dailyLimitHit?"quota-reached":"done";Ie({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(l=>console.error(`[runLog] postRunReport failed: ${l.message}`))}}import"dotenv/config";import*as p from"fs";import*as ce from"os";import*as h from"path";import{fileURLToPath as it}from"url";var te={};H(te,{NAME:()=>Tn,VERSION:()=>Dn,up:()=>On});import*as C from"fs";import*as Y from"path";var Dn=1,Tn="normalize-jobs-and-questions",_n=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],Rn=50;function ee(e){return C.existsSync(e)?JSON.parse(C.readFileSync(e,"utf-8")):null}function ne(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{C.writeFileSync(o,t)}catch(r){try{C.unlinkSync(o)}catch{}throw r}try{C.renameSync(o,e)}catch(r){try{C.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 On(e,n){let t=Y.join(e,"jobs.json"),o=Y.join(n,"scouted-jobs.json"),r=Y.join(e,"application-questions.json"),s=ee(t)||{},i=ee(o)||{},l=0,c=[];for(let f of Object.keys(s)){if(!i[f])continue;let u=i[f],m=s[f];for(let g of _n)u[g]!=null&&m[g]==null&&(m[g]=u[g]);c.push(f),l++}l>0?(ne(t,s),console.log(` Phase 1: Merged ${l} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let a=ee(r);if(a&&Array.isArray(a.applications)){let f={},u=0;for(let m of a.applications){let g=m.jobId||"unknown";f[g]||(f[g]={applications:[]});let v=(m.questions||[]).map(d=>{let w={type:d.type||"input",question:d.question||"",answer:d.answer||""};return d.options&&(d.options.length<=Rn?w.options=d.options:(w.optionsOmitted=!0,u++)),d.page&&(w.page=d.page),d.wasPreFilled&&(w.wasPreFilled=!0),d.wasRetry&&(w.wasRetry=!0),w});f[g].applications.push({applicationId:m.applicationId,date:m.date,result:m.result||"submitted",formPages:m.formPages||null,duration:m.duration||null,retries:m.retries||0,failedField:m.failedField||null,questionCount:m.questionCount||v.length,questions:v})}ne(r,f),console.log(` Phase 2: Rekeyed ${a.applications.length} applications by jobId (${Object.keys(f).length} unique jobs)`),u>0&&console.log(` Phase 2: Stripped bloated options from ${u} questions`)}else a&&!a.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(c.length>0){for(let f of c)delete i[f];ne(o,i),console.log(` Phase 3: Removed ${c.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 oe={};H(oe,{NAME:()=>Nn,VERSION:()=>jn,up:()=>Pn});import*as $ from"fs";import*as Re from"path";var jn=2,Nn="reset-unread-flags";function Fn(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function Ln(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{$.writeFileSync(o,t)}catch(r){try{$.unlinkSync(o)}catch{}throw r}try{$.renameSync(o,e)}catch(r){try{$.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 Pn(e){let n=Re.join(e,"conversations.json"),t=Fn(n);if(!t){console.log(" conversations.json not found \u2014 nothing to reset.");return}let o=0;for(let r of Object.keys(t))t[r].unread===!0&&(t[r].unread=!1,o++);if(o===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}Ln(n,t),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var re={};H(re,{NAME:()=>Un,VERSION:()=>Mn,up:()=>Wn});import*as E from"fs";import*as Oe from"path";var Mn=3,Un="recompute-last-message-by",qn=new Set(["draft","confirmed","rejected","needs_review"]);function Bn(e){return E.existsSync(e)?JSON.parse(E.readFileSync(e,"utf-8")):null}function Jn(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{E.writeFileSync(o,t)}catch(r){try{E.unlinkSync(o)}catch{}throw r}try{E.renameSync(o,e)}catch(r){try{E.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 Hn(e,n){if(!e||e.length===0)return"them";let t=e.filter(s=>!qn.has(s.status));if(t.length===0)return"them";let o=t.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:[...t].reverse();for(let s of r){let i=s.sender;if(i===n)return"me";if(i!=="Unknown"&&i!=="")return"them"}return"them"}async function Wn(e){let n=Oe.join(e,"conversations.json"),t=Bn(n);if(!t){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(t)){let c=t[l];if(!c||typeof c!="object")continue;Object.prototype.hasOwnProperty.call(c,"_cardSynced")&&(delete c._cardSynced,s++);let a=Array.isArray(c.messages)?c.messages:[],f=Hn(a,o),u=f==="me"?"awaiting_reply":"unanswered_by_us";c.lastMessageBy!==f&&i++,c.lastMessageBy=f,c.conversationStatus=u,r++}if(r===0){console.log(" No conversations to recompute.");return}Jn(n,t),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 se={};H(se,{NAME:()=>Yn,VERSION:()=>Vn,up:()=>Qn});import*as x from"fs";import*as je from"path";var Vn=4,Yn="split-connection-timestamps",Gn=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function Kn(e){if(!x.existsSync(e))return null;let n=x.readFileSync(e,"utf-8");return n.charCodeAt(0)===65279&&(n=n.slice(1)),JSON.parse(n)}function zn(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{x.writeFileSync(o,t)}catch(r){try{x.unlinkSync(o)}catch{}throw r}try{x.renameSync(o,e)}catch(r){try{x.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 Qn(e){let n=je.join(e,"people.json"),t=Kn(n);if(!t||typeof t!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let o=0,r=0;for(let s of Object.keys(t)){let i=t[s];!i||typeof i!="object"||(r++,Gn.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}zn(n,t),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".')}import"dotenv/config";import*as k from"path";import{fileURLToPath as Xn}from"url";var Zn=Xn(import.meta.url),et=k.dirname(k.dirname(Zn)),J=process.env.DATA_DIR?k.resolve(process.env.DATA_DIR,"market-research"):k.join(et,"market-research"),Io=k.join(J,"scouted-jobs.json"),Do=k.join(J,"discovered-people.json"),To=k.join(J,"visit-log.json"),_o=k.join(J,"companies.json"),Ro=k.join(J,"job-decisions.json");function Ne(){nt=null,tt=null,ot=null,rt=null,st=null}var nt=null;var tt=null;var ot=null;var rt=null;var st=null;var ct=it(import.meta.url),lt=h.dirname(ct),at=h.dirname(h.dirname(lt));function ut(e){return e&&(e==="~"?ce.homedir():e.startsWith("~/")||e.startsWith("~\\")?h.join(ce.homedir(),e.slice(2)):e)}var D=process.env.DATA_DIR?h.resolve(ut(process.env.DATA_DIR)):at,L=h.join(D,"collected-profiles"),P=h.join(D,"market-research"),b=h.join(D,".schema-version"),Fe=[h.join(L,".schema-version"),h.join(P,".schema-version")],j=4,_=[{version:1,module:te},{version:2,module:oe},{version:3,module:re},{version:4,module:se}];(function(){_.sort((o,r)=>o.version-r.version);let n=new Set;for(let o of _){if(!Number.isInteger(o.version)||o.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(o.version)} (must be positive integer)`);if(n.has(o.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${o.version}`);n.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 t=_.length?_[_.length-1].version:0;if(t!==j)throw new Error(`MIGRATION_REGISTRY: highest version v${t} but CURRENT_SCHEMA_VERSION=${j}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<_.length;o++){let r=o+1;if(_[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${_[o].version}`)}})();function Ue(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
10
10
  [FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
11
11
  `),process.exit(1));try{p.mkdirSync(D,{recursive:!0})}catch(n){n.code!=="EEXIST"&&(console.error(`
12
12
  [FATAL] Cannot create DATA_DIR (${D}): ${n.message}`),console.error(` Fix the path or permissions and try again.
@@ -14,57 +14,57 @@ ${t.join(`
14
14
  [FATAL] DATA_DIR (${D}) is not accessible: ${n.message}
15
15
  `),process.exit(1)}e.isDirectory()||(console.error(`
16
16
  [FATAL] DATA_DIR (${D}) exists but is NOT a directory.`),console.error(` Looks like a typo \u2014 your DATA_DIR points at a file. Fix the path and try again.
17
- `),process.exit(1));for(let n of[L,P]){let o;try{o=p.lstatSync(n)}catch(t){if(t.code==="ENOENT")continue;throw t}o.isSymbolicLink()&&(console.error(`
17
+ `),process.exit(1));for(let n of[L,P]){let t;try{t=p.lstatSync(n)}catch(o){if(o.code==="ENOENT")continue;throw o}t.isSymbolicLink()&&(console.error(`
18
18
  [FATAL] Data subdirectory is a symbolic link: ${n}`),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.
19
- `),process.exit(1))}}var F=h.join(D,".migration-lock");function fo(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return p.writeFileSync(F,e,{flag:"wx"}),!0}catch(t){if(t.code!=="EEXIST")throw t}let n;try{n=JSON.parse(p.readFileSync(F,"utf-8"))}catch{n=null}if(n&&Number.isInteger(n.pid)){let t=!1;try{process.kill(n.pid,0),t=!0}catch(i){i.code==="EPERM"&&(t=!0)}let r=24*60*60*1e3,s=1/0;if(n.startedAt){let i=Date.parse(n.startedAt);Number.isNaN(i)||(s=Date.now()-i)}t&&s<r&&(console.error(`
19
+ `),process.exit(1))}}var F=h.join(D,".migration-lock");function ft(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return p.writeFileSync(F,e,{flag:"wx"}),!0}catch(o){if(o.code!=="EEXIST")throw o}let n;try{n=JSON.parse(p.readFileSync(F,"utf-8"))}catch{n=null}if(n&&Number.isInteger(n.pid)){let o=!1;try{process.kill(n.pid,0),o=!0}catch(i){i.code==="EPERM"&&(o=!0)}let r=24*60*60*1e3,s=1/0;if(n.startedAt){let i=Date.parse(n.startedAt);Number.isNaN(i)||(s=Date.now()-i)}o&&s<r&&(console.error(`
20
20
  [FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${n.pid}`),console.error(` Started at: ${n.startedAt||"(unknown)"}`),console.error(` Lock file: ${F}
21
21
  `),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.
22
- `),process.exit(1)),t&&s>=r&&console.log(` Lock holder PID ${n.pid} is alive but lock is older than 24h \u2014 assuming PID reuse, taking over.`)}console.log(` Stale migration lock from PID ${n?.pid??"?"} found \u2014 taking over.`);let o=F+".tmp";try{return p.writeFileSync(o,e),p.renameSync(o,F),!0}catch(t){try{p.unlinkSync(o)}catch{}throw new Error(`Failed to take over stale migration lock: ${t.message}`)}}function le(){try{if(JSON.parse(p.readFileSync(F,"utf-8")).pid!==process.pid)return;p.unlinkSync(F)}catch{}}var Le=!1;function po(){if(Le)return;Le=!0;let e=()=>{try{le()}catch{}process.exit(1)};for(let n of["SIGINT","SIGTERM","SIGHUP"])try{process.on(n,e)}catch{}}function mo(){if(p.existsSync(b))return;let e=[],n=[];for(let s of Fe)if(p.existsSync(s))try{e.push({file:s,schema:G(s)})}catch(i){n.push({file:s,err:i.message})}if(n.length>0){console.error(`
22
+ `),process.exit(1)),o&&s>=r&&console.log(` Lock holder PID ${n.pid} is alive but lock is older than 24h \u2014 assuming PID reuse, taking over.`)}console.log(` Stale migration lock from PID ${n?.pid??"?"} found \u2014 taking over.`);let t=F+".tmp";try{return p.writeFileSync(t,e),p.renameSync(t,F),!0}catch(o){try{p.unlinkSync(t)}catch{}throw new Error(`Failed to take over stale migration lock: ${o.message}`)}}function le(){try{if(JSON.parse(p.readFileSync(F,"utf-8")).pid!==process.pid)return;p.unlinkSync(F)}catch{}}var Le=!1;function pt(){if(Le)return;Le=!0;let e=()=>{try{le()}catch{}process.exit(1)};for(let n of["SIGINT","SIGTERM","SIGHUP"])try{process.on(n,e)}catch{}}function dt(){if(p.existsSync(b))return;let e=[],n=[];for(let s of Fe)if(p.existsSync(s))try{e.push({file:s,schema:G(s)})}catch(i){n.push({file:s,err:i.message})}if(n.length>0){console.error(`
23
23
  [FATAL] Legacy .schema-version file(s) corrupted \u2014 cannot determine current schema version:`);for(let s of n)console.error(` ${s.file}: ${s.err}`);console.error(`
24
24
  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.
25
- `),process.exit(1)}if(e.length===0)return;let o=e.map(s=>s.schema.version);if(new Set(o).size>1){console.error(`
25
+ `),process.exit(1)}if(e.length===0)return;let t=e.map(s=>s.schema.version);if(new Set(t).size>1){console.error(`
26
26
  [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.
27
- `),process.exit(1)}let t=e[0].schema,r=b+".tmp";try{p.writeFileSync(r,JSON.stringify(t,null,2)),p.renameSync(r,b)}catch(s){try{p.unlinkSync(r)}catch{}throw s}for(let s of Fe)if(p.existsSync(s))try{p.unlinkSync(s)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${b}`)}function ho(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let n=Number(e.version);return!Number.isFinite(n)||n<0||!Number.isInteger(n)?null:(e.version=n,Array.isArray(e.migrations)||(e.migrations=[]),e)}function G(e){let n=p.readFileSync(e,"utf-8");return n.charCodeAt(0)===65279&&(n=n.slice(1)),JSON.parse(n)}function Pe(){if(mo(),!p.existsSync(b))return{version:0,migrations:[]};let e;try{e=G(b)}catch(o){if(o.code==="ENOENT")return{version:0,migrations:[]};console.error(`
28
- [FATAL] ${b} is not valid JSON: ${o.message}`),console.error(" Refusing to proceed \u2014 silently treating it as 'fresh install' would re-apply"),console.error(" every migration on top of already-migrated data and corrupt it."),console.error(' Repair the file (set it to {"version":N,"migrations":[...]} matching your real state)'),console.error(` or restore from the *.pre-vNNN.backup files if you have them.
29
- `),process.exit(1)}let n=ho(e);return n===null&&(console.error(`
27
+ `),process.exit(1)}let o=e[0].schema,r=b+".tmp";try{p.writeFileSync(r,JSON.stringify(o,null,2)),p.renameSync(r,b)}catch(s){try{p.unlinkSync(r)}catch{}throw s}for(let s of Fe)if(p.existsSync(s))try{p.unlinkSync(s)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${b}`)}function mt(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let n=Number(e.version);return!Number.isFinite(n)||n<0||!Number.isInteger(n)?null:(e.version=n,Array.isArray(e.migrations)||(e.migrations=[]),e)}function G(e){let n=p.readFileSync(e,"utf-8");return n.charCodeAt(0)===65279&&(n=n.slice(1)),JSON.parse(n)}function Pe(){if(dt(),!p.existsSync(b))return{version:0,migrations:[]};let e;try{e=G(b)}catch(t){if(t.code==="ENOENT")return{version:0,migrations:[]};console.error(`
28
+ [FATAL] ${b} is not valid JSON: ${t.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.
29
+ `),process.exit(1)}let n=mt(e);return n===null&&(console.error(`
30
30
  [FATAL] ${b} 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.
31
- `),process.exit(1)),n}function qe(e){try{p.chmodSync(e,384)}catch{}}function go(e){if(Ue(),p.existsSync(b))try{if(p.lstatSync(b).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${b}. Refusing to write through it (potential symlink attack). Remove the link and re-run.`)}catch(o){if(o.message?.includes("symbolic link"))throw o}let n=b+".tmp";try{p.writeFileSync(n,JSON.stringify(e,null,2)),qe(n),p.renameSync(n,b)}catch(o){try{p.unlinkSync(n)}catch{}throw o}}function Me(e,n){if(!p.existsSync(e))return;let o=`.pre-v${String(n).padStart(3,"0")}.backup`,t=p.readdirSync(e).filter(l=>{let c=l.toLowerCase();if(c.includes(".backup")||c===".schema-version"||c.endsWith(".tmp"))return!1;try{return p.statSync(h.join(e,l)).isFile()}catch{return!1}}),r=0,s=0,i=[];for(let l of t){let c=h.join(e,l),a=h.join(e,l+o);if(p.existsSync(a)){s++;continue}try{Je(c,a),r++}catch(f){i.push({file:l,err:f.message})}}if(i.length>0){let l=new Error(`Failed to back up ${i.length} file(s) in ${h.basename(e)}/: `+i.map(c=>`${c.file} (${c.err})`).join(", "));throw l.code="BACKUP_INCOMPLETE",l}if(r>0||s>0){let l=s>0?` (${s} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${r} files in ${h.basename(e)}/ (${o})${l}`)}}var ie=!1;async function Be(){if(ie)return;Ue(),vo();let n=Pe().version;if(n===O){ie=!0;return}po(),fo(),process.on("exit",le),n>O&&(console.error(`
32
- [FATAL] Your data schema is at v${n}, but this plugin build only understands up to v${O}.`),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.
33
- `),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${O}.
31
+ `),process.exit(1)),n}function qe(e){try{p.chmodSync(e,384)}catch{}}function ht(e){if(Ue(),p.existsSync(b))try{if(p.lstatSync(b).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${b}. Refusing to write through it (potential symlink attack). Remove the link and re-run.`)}catch(t){if(t.message?.includes("symbolic link"))throw t}let n=b+".tmp";try{p.writeFileSync(n,JSON.stringify(e,null,2)),qe(n),p.renameSync(n,b)}catch(t){try{p.unlinkSync(n)}catch{}throw t}}function Me(e,n){if(!p.existsSync(e))return;let t=`.pre-v${String(n).padStart(3,"0")}.backup`,o=p.readdirSync(e).filter(l=>{let c=l.toLowerCase();if(c.includes(".backup")||c===".schema-version"||c.endsWith(".tmp"))return!1;try{return p.statSync(h.join(e,l)).isFile()}catch{return!1}}),r=0,s=0,i=[];for(let l of o){let c=h.join(e,l),a=h.join(e,l+t);if(p.existsSync(a)){s++;continue}try{Je(c,a),r++}catch(f){i.push({file:l,err:f.message})}}if(i.length>0){let l=new Error(`Failed to back up ${i.length} file(s) in ${h.basename(e)}/: `+i.map(c=>`${c.file} (${c.err})`).join(", "));throw l.code="BACKUP_INCOMPLETE",l}if(r>0||s>0){let l=s>0?` (${s} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${r} files in ${h.basename(e)}/ (${t})${l}`)}}var ie=!1;async function Be(){if(ie)return;Ue(),bt();let n=Pe().version;if(n===j){ie=!0;return}pt(),ft(),process.on("exit",le),n>j&&(console.error(`
32
+ [FATAL] Your data schema is at v${n}, but this plugin build only understands up to v${j}.`),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.
33
+ `),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${j}.
34
34
  `),process.exit(1)),console.log(`
35
- \u{1F4E6} Schema migration: v${n} \u2192 v${O}`);let o=ko();if(!o.ok){console.error(`
36
- [FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let r of o.broken)console.error(` ${r.dir}/${r.file}: ${r.err}`);console.error(`
35
+ \u{1F4E6} Schema migration: v${n} \u2192 v${j}`);let t=vt();if(!t.ok){console.error(`
36
+ [FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let r of t.broken)console.error(` ${r.dir}/${r.file}: ${r.err}`);console.error(`
37
37
  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'.
38
- `),process.exit(1)}let t=_.filter(r=>r.version>n);for(let r of t){console.log(`
38
+ `),process.exit(1)}let o=_.filter(r=>r.version>n);for(let r of o){console.log(`
39
39
  Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,i=`.pre-${s}.backup`;try{Me(L,r.version),Me(P,r.version)}catch(c){console.error(`
40
40
  [FATAL] Pre-migration backup failed for ${s}: ${c.message}`),console.error(" Migration NOT applied. Repair the underlying issue (disk space, permissions, locked files)"),console.error(` and re-run the plugin command.
41
41
  `),process.exit(1)}let l=r.module;try{await l.up(L,P)}catch(c){console.error(`
42
- [FATAL] Migration ${s} failed: ${c.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let a=Ao(i);a.ok?(console.error(` \u2713 Auto-rollback restored ${a.restored} files. Schema stays at v${n}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
42
+ [FATAL] Migration ${s} failed: ${c.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let a=kt(i);a.ok?(console.error(` \u2713 Auto-rollback restored ${a.restored} files. Schema stays at v${n}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
43
43
  `)):(console.error(` [!] Auto-rollback INCOMPLETE: ${a.error}`),console.error(` Manual recovery: copy *${i} files back over the originals.
44
44
  `))}catch(a){console.error(` [!] Auto-rollback CRASHED while restoring: ${a.message}`),console.error(` Manual recovery: copy *${i} files back over the originals.
45
- `)}process.exit(1)}try{let c=new Date().toISOString(),a={version:r.version,name:l.NAME||s,appliedAt:c},f=Pe();f.version=r.version,f.migratedAt=c,f.migrations=f.migrations||[],f.migrations.push(a),go(f)}catch(c){console.error(`
45
+ `)}process.exit(1)}try{let c=new Date().toISOString(),a={version:r.version,name:l.NAME||s,appliedAt:c},f=Pe();f.version=r.version,f.migratedAt=c,f.migrations=f.migrations||[],f.migrations.push(a),ht(f)}catch(c){console.error(`
46
46
  [FATAL] Migration ${s} applied successfully but schema version file could NOT be updated: ${c.message}`),console.error(` Your data is in the v${r.version} state but .schema-version still shows v${n}.`),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.
47
47
  `),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{ue()}catch{}try{Ne()}catch{}ie=!0,le(),console.log(`
48
- \u2713 Schema is now at v${O}
49
- `)}var yo=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function So(e){let n=e.toLowerCase();return yo.some(o=>o.test(n))}var wo=6e4;function bo(){let e=Date.now(),n=[];for(let o of[D,L,P]){if(!p.existsSync(o))continue;let t;try{t=p.readdirSync(o)}catch{continue}for(let r of t){if(!So(r))continue;let s=h.join(o,r);try{let i=p.statSync(s);if(!i.isFile()||e-i.mtimeMs<wo)continue;n.push({dir:o,file:r,fullPath:s})}catch{}}}return n}function vo({verbose:e=!1}={}){let n=bo();if(n.length===0)return e&&console.log(" No orphan .tmp files found."),0;let o=0;for(let t of n)try{p.unlinkSync(t.fullPath),o++,e&&console.log(` Removed orphan: ${h.basename(t.dir)}/${t.file}`)}catch(r){console.warn(` [!] Could not remove orphan ${t.fullPath}: ${r.message}`)}return!e&&o>0&&console.log(` Cleaned up ${o} orphan .tmp file(s) from previous run.`),o}function ko(){let e=[];for(let n of[L,P]){if(!p.existsSync(n))continue;let o=p.readdirSync(n).filter(t=>{let r=t.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let t of o){let r=h.join(n,t);try{G(r)}catch(s){e.push({dir:h.basename(n),file:t,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function Ao(e){let n=[],o=[];for(let s of[L,P]){if(!p.existsSync(s))continue;let i=p.readdirSync(s).filter(l=>l.endsWith(e));for(let l of i){let c=h.join(s,l),a=l.slice(0,-e.length),f=h.join(s,a);try{a.toLowerCase().endsWith(".json")?G(c):p.accessSync(c,p.constants.R_OK),n.push({backupPath:c,originalPath:f,fileName:l,dir:s})}catch(u){o.push(`${h.basename(s)}/${l}: ${u.message}`)}}}if(o.length>0)return{ok:!1,error:o.join("; "),restored:0};let t=0,r=[];for(let{backupPath:s,originalPath:i,fileName:l,dir:c}of n)try{Je(s,i),t++}catch(a){r.push(`${h.basename(c)}/${l}: ${a.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:t}:{ok:!0,restored:t}}function Je(e,n){let o=n+".tmp";try{p.copyFileSync(e,o),qe(o)}catch(t){try{p.unlinkSync(o)}catch{}throw t}try{p.renameSync(o,n)}catch(t){try{p.unlinkSync(o)}catch{}if(t.code==="EPERM"||t.code==="EBUSY"){let r=new Error(`File locked: ${n} (${t.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=t.code,r}throw t}}function $o(){let e={list:!1,full:!1,max:1/0,dryRun:!1,verbose:!1};for(let n of process.argv.slice(2))n==="--list"?e.list=!0:n==="--full"?e.full=!0:n==="--dry-run"?e.dryRun=!0:n==="--verbose"?e.verbose=!0:n.startsWith("--max=")&&(e.max=parseInt(n.split("=")[1],10));return e}function Eo(){let e=B(),n=Object.values(e),o=n.length,t={};for(let s of n){let i=s.connectionStatus||"(none)";t[i]=(t[i]||0)+1}let r={};for(let s of n){for(let i of s.sources||[])r[i]=(r[i]||0)+1;(!s.sources||s.sources.length===0)&&(r["(no source)"]=(r["(no source)"]||0)+1)}console.log(`
50
- === People Database: ${o} entries ===
51
- `),console.log("By connection status:");for(let[s,i]of Object.entries(t).sort((l,c)=>c[1]-l[1]))console.log(` ${s.padEnd(30)} ${i}`);console.log(`
52
- By source:`);for(let[s,i]of Object.entries(r).sort((l,c)=>c[1]-l[1]))console.log(` ${s.padEnd(30)} ${i}`);console.log()}async function xo(e){let n="https://www.linkedin.com/mynetwork/invite-connect/connections/";console.log(`Navigating to ${n}`),await e.goto(n,{waitUntil:"domcontentloaded",timeout:6e4}),await q(3e3);let o=e.url();if(o.includes("/login")||o.includes("/authwall"))throw new Error("Redirected to login (not logged in, or session expired). Run: ilml linkedin login");try{await e.waitForSelector('main a[href*="/in/"]',{timeout:15e3})}catch{console.warn("\u26A0 No connection cards found after 15s. Page may have changed layout.")}let t=await e.evaluate(()=>{let i=((document.querySelector("main")||document.body).innerText||"").match(/([\d,]+)\s+connections?/i);return i?parseInt(i[1].replace(/,/g,""),10):null});return t&&console.log(` LinkedIn reports: ${t.toLocaleString()} connections`),t}async function We(e){return e.evaluate(()=>{let o=(document.querySelector("main")||document.body).querySelectorAll('a[href*="/in/"]'),t={};for(let i of o){let l=i.getAttribute("href");if(!l)continue;let c;try{let a=new URL(l,location.origin);c=a.origin+a.pathname.replace(/\/+$/,"")}catch{continue}t[c]||(t[c]=[]),t[c].push(i)}let r=[],s=i=>((i&&(i.innerText||i.textContent)||"").trim().split(`
53
- `)[0]||"").trim();for(let[i,l]of Object.entries(t)){let c=null;for(let d of l){let w=s(d);!w||d.querySelector("img")||(!c||w.length<s(c).length)&&(c=d)}let a=s(c)||null,f=c||l[0];for(let d=0;d<10&&f?.parentElement;d++){f=f.parentElement;let w=f.innerText||"";if((w.includes("Connected on")||w.includes("Message"))&&(w.match(/Connected on/g)||[]).length<=1)break}let u=(f?.innerText||"").split(`
54
- `).map(d=>d.trim()).filter(Boolean),m=null,g=null,v=u.indexOf(a);if(v>=0&&v+1<u.length){let d=u[v+1];!d.startsWith("Connected on")&&d!=="Message"&&(m=d)}for(let d of u)if(d.startsWith("Connected on")){g=d;break}r.push({profileUrl:i,name:a,title:m,time:g})}return r})}async function Ve(e){return e.evaluate(()=>{let n=document.querySelector("main")||document.body,o=null,t=[n,...n.querySelectorAll("div, section")];for(let s of t){let i=getComputedStyle(s);if((i.overflowY==="auto"||i.overflowY==="scroll")&&s.scrollHeight>s.clientHeight+10){o=s;break}}o&&o.scrollBy(0,800),window.scrollBy(0,800);let r=document.querySelectorAll("button");for(let s of r){let i=s.textContent?.trim().toLowerCase()||"";if((i.includes("load more")||i.includes("show more"))&&s.getBoundingClientRect().height>0)return s.click(),"clicked"}return o?"scrolled":"window-scroll"})}async function Io(e,n){let{max:o,verbose:t,dryRun:r}=n,s=new Map,i=0,l=0,c=3,a=10;for(;;){i++;let f=await We(e),u=0;for(let g of f)g.profileUrl&&(s.has(g.profileUrl)||(s.set(g.profileUrl,g),u++));if(t?console.log(` Round #${i}: ${u} new | Total: ${s.size}`):process.stdout.write(`\r Connections found: ${s.size} (page #${i})`),!r&&i%a===0&&(Ke(Array.from(s.values()),!1),t&&console.log(` \u{1F4BE} Saved progress (${s.size} connections)`)),s.size>=o){console.log(`
55
- Reached --max=${o}, stopping.`);break}if(u===0){if(l++,l>=c){console.log(`
56
- ${c} rounds with no new cards \u2014 end of list.`);break}}else l=0;let m=await Ve(e);t&&m==="clicked"&&console.log(' \u2192 Clicked "Load more"'),await q(2e3)}return t||process.stdout.write(`
57
- `),Array.from(s.values())}async function Do(e,n){let{max:o,verbose:t}=n,r=B(),s=new Set;for(let[f,u]of Object.entries(r))u.connectionStatus==="connected"&&u.sources?.includes("sync-connections")&&s.add(f);console.log(` Known synced connections in DB: ${s.size}`);let i=new Map,l=0,c=0,a=3;for(;;){l++;let f=await We(e),u=0,m=0;for(let d of f)d.profileUrl&&(i.has(d.profileUrl)||(i.set(d.profileUrl,d),s.has(d.profileUrl)?m++:u++));let g=Array.from(i.values()).filter(d=>!s.has(d.profileUrl)).length;if(t?console.log(` Round #${l}: ${u} new, ${m} known | New total: ${g}`):process.stdout.write(`\r New connections: ${g} (page #${l})`),g>=o){console.log(`
58
- Reached --max=${o}, stopping.`);break}if(u===0&&m>0){if(c++,c>=a){console.log(`
48
+ \u2713 Schema is now at v${j}
49
+ `)}var gt=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function yt(e){let n=e.toLowerCase();return gt.some(t=>t.test(n))}var St=6e4;function wt(){let e=Date.now(),n=[];for(let t of[D,L,P]){if(!p.existsSync(t))continue;let o;try{o=p.readdirSync(t)}catch{continue}for(let r of o){if(!yt(r))continue;let s=h.join(t,r);try{let i=p.statSync(s);if(!i.isFile()||e-i.mtimeMs<St)continue;n.push({dir:t,file:r,fullPath:s})}catch{}}}return n}function bt({verbose:e=!1}={}){let n=wt();if(n.length===0)return e&&console.log(" No orphan .tmp files found."),0;let t=0;for(let o of n)try{p.unlinkSync(o.fullPath),t++,e&&console.log(` Removed orphan: ${h.basename(o.dir)}/${o.file}`)}catch(r){console.warn(` [!] Could not remove orphan ${o.fullPath}: ${r.message}`)}return!e&&t>0&&console.log(` Cleaned up ${t} orphan .tmp file(s) from previous run.`),t}function vt(){let e=[];for(let n of[L,P]){if(!p.existsSync(n))continue;let t=p.readdirSync(n).filter(o=>{let r=o.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let o of t){let r=h.join(n,o);try{G(r)}catch(s){e.push({dir:h.basename(n),file:o,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function kt(e){let n=[],t=[];for(let s of[L,P]){if(!p.existsSync(s))continue;let i=p.readdirSync(s).filter(l=>l.endsWith(e));for(let l of i){let c=h.join(s,l),a=l.slice(0,-e.length),f=h.join(s,a);try{a.toLowerCase().endsWith(".json")?G(c):p.accessSync(c,p.constants.R_OK),n.push({backupPath:c,originalPath:f,fileName:l,dir:s})}catch(u){t.push(`${h.basename(s)}/${l}: ${u.message}`)}}}if(t.length>0)return{ok:!1,error:t.join("; "),restored:0};let o=0,r=[];for(let{backupPath:s,originalPath:i,fileName:l,dir:c}of n)try{Je(s,i),o++}catch(a){r.push(`${h.basename(c)}/${l}: ${a.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:o}:{ok:!0,restored:o}}function Je(e,n){let t=n+".tmp";try{p.copyFileSync(e,t),qe(t)}catch(o){try{p.unlinkSync(t)}catch{}throw o}try{p.renameSync(t,n)}catch(o){try{p.unlinkSync(t)}catch{}if(o.code==="EPERM"||o.code==="EBUSY"){let r=new Error(`File locked: ${n} (${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}}function Ct(){let e={list:!1,full:!1,max:1/0,dryRun:!1,verbose:!1};for(let n of process.argv.slice(2))n==="--list"?e.list=!0:n==="--full"?e.full=!0:n==="--dry-run"?e.dryRun=!0:n==="--verbose"?e.verbose=!0:n.startsWith("--max=")&&(e.max=parseInt(n.split("=")[1],10));return e}function $t(){let e=B(),n=Object.values(e),t=n.length,o={};for(let s of n){let i=s.connectionStatus||"(none)";o[i]=(o[i]||0)+1}let r={};for(let s of n){for(let i of s.sources||[])r[i]=(r[i]||0)+1;(!s.sources||s.sources.length===0)&&(r["(no source)"]=(r["(no source)"]||0)+1)}console.log(`
50
+ === People Database: ${t} entries ===
51
+ `),console.log("By connection status:");for(let[s,i]of Object.entries(o).sort((l,c)=>c[1]-l[1]))console.log(` ${s.padEnd(30)} ${i}`);console.log(`
52
+ By source:`);for(let[s,i]of Object.entries(r).sort((l,c)=>c[1]-l[1]))console.log(` ${s.padEnd(30)} ${i}`);console.log()}async function Et(e){let n="https://www.linkedin.com/mynetwork/invite-connect/connections/";console.log(`Navigating to ${n}`),await e.goto(n,{waitUntil:"domcontentloaded",timeout:6e4}),await q(3e3);let t=e.url();if(t.includes("/login")||t.includes("/authwall"))throw new Error("Redirected to login (not logged in, or session expired). Run: ilml linkedin login");try{await e.waitForSelector('main a[href*="/in/"]',{timeout:15e3})}catch{console.warn("\u26A0 No connection cards found after 15s. Page may have changed layout.")}let o=await e.evaluate(()=>{let i=((document.querySelector("main")||document.body).innerText||"").match(/([\d,]+)\s+connections?/i);return i?parseInt(i[1].replace(/,/g,""),10):null});return o&&console.log(` LinkedIn reports: ${o.toLocaleString()} connections`),o}async function We(e){return e.evaluate(()=>{let t=(document.querySelector("main")||document.body).querySelectorAll('a[href*="/in/"]'),o={};for(let i of t){let l=i.getAttribute("href");if(!l)continue;let c;try{let a=new URL(l,location.origin);c=a.origin+a.pathname.replace(/\/+$/,"")}catch{continue}o[c]||(o[c]=[]),o[c].push(i)}let r=[],s=i=>((i&&(i.innerText||i.textContent)||"").trim().split(`
53
+ `)[0]||"").trim();for(let[i,l]of Object.entries(o)){let c=null;for(let d of l){let w=s(d);!w||d.querySelector("img")||(!c||w.length<s(c).length)&&(c=d)}let a=s(c)||null,f=c||l[0];for(let d=0;d<10&&f?.parentElement;d++){f=f.parentElement;let w=f.innerText||"";if((w.includes("Connected on")||w.includes("Message"))&&(w.match(/Connected on/g)||[]).length<=1)break}let u=(f?.innerText||"").split(`
54
+ `).map(d=>d.trim()).filter(Boolean),m=null,g=null,v=u.indexOf(a);if(v>=0&&v+1<u.length){let d=u[v+1];!d.startsWith("Connected on")&&d!=="Message"&&(m=d)}for(let d of u)if(d.startsWith("Connected on")){g=d;break}r.push({profileUrl:i,name:a,title:m,time:g})}return r})}async function Ve(e){return e.evaluate(()=>{let n=document.querySelector("main")||document.body,t=null,o=[n,...n.querySelectorAll("div, section")];for(let s of o){let i=getComputedStyle(s);if((i.overflowY==="auto"||i.overflowY==="scroll")&&s.scrollHeight>s.clientHeight+10){t=s;break}}t&&t.scrollBy(0,800),window.scrollBy(0,800);let r=document.querySelectorAll("button");for(let s of r){let i=s.textContent?.trim().toLowerCase()||"";if((i.includes("load more")||i.includes("show more"))&&s.getBoundingClientRect().height>0)return s.click(),"clicked"}return t?"scrolled":"window-scroll"})}async function xt(e,n){let{max:t,verbose:o,dryRun:r}=n,s=new Map,i=0,l=0,c=3,a=10;for(;;){i++;let f=await We(e),u=0;for(let g of f)g.profileUrl&&(s.has(g.profileUrl)||(s.set(g.profileUrl,g),u++));if(o?console.log(` Round #${i}: ${u} new | Total: ${s.size}`):process.stdout.write(`\r Connections found: ${s.size} (page #${i})`),!r&&i%a===0&&(Ke(Array.from(s.values()),!1),o&&console.log(` \u{1F4BE} Saved progress (${s.size} connections)`)),s.size>=t){console.log(`
55
+ Reached --max=${t}, stopping.`);break}if(u===0){if(l++,l>=c){console.log(`
56
+ ${c} rounds with no new cards \u2014 end of list.`);break}}else l=0;let m=await Ve(e);o&&m==="clicked"&&console.log(' \u2192 Clicked "Load more"'),await q(2e3)}return o||process.stdout.write(`
57
+ `),Array.from(s.values())}async function It(e,n){let{max:t,verbose:o}=n,r=B(),s=new Set;for(let[f,u]of Object.entries(r))u.connectionStatus==="connected"&&u.sources?.includes("sync-connections")&&s.add(f);console.log(` Known synced connections in DB: ${s.size}`);let i=new Map,l=0,c=0,a=3;for(;;){l++;let f=await We(e),u=0,m=0;for(let d of f)d.profileUrl&&(i.has(d.profileUrl)||(i.set(d.profileUrl,d),s.has(d.profileUrl)?m++:u++));let g=Array.from(i.values()).filter(d=>!s.has(d.profileUrl)).length;if(o?console.log(` Round #${l}: ${u} new, ${m} known | New total: ${g}`):process.stdout.write(`\r New connections: ${g} (page #${l})`),g>=t){console.log(`
58
+ Reached --max=${t}, stopping.`);break}if(u===0&&m>0){if(c++,c>=a){console.log(`
59
59
  ${a} consecutive pages of known connections \u2014 caught up.`);break}}else if(u>0)c=0;else if(c++,c>=a){console.log(`
60
- ${a} empty rounds \u2014 end of list.`);break}let v=await Ve(e);t&&v==="clicked"&&console.log(' \u2192 Clicked "Load more"'),await q(2e3)}return t||process.stdout.write(`
61
- `),Array.from(i.values())}var Ye=new Set(["pending","sent_with_note","sent_without_note","sent_without_note_upsell"]);function He(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function Ge(e){let n=new Map;for(let[o,t]of Object.entries(e)){let r=V(t.profileUrl||o);r&&!n.has(r)&&n.set(r,o)}for(let[o,t]of Object.entries(e))for(let r of t.aliases||[])r&&!n.has(r)&&n.set(r,o);return n}function To(e,n){let o=[],t=Ge(n);for(let r of e){if(!r.profileUrl)continue;let s=t.get(V(r.profileUrl)),i=s?n[s]:void 0;i&&Ye.has(i.connectionStatus)&&o.push({...r,previousStatus:i.connectionStatus})}return o}function Ke(e,n){let o=B(),t=new Date().toISOString(),r=t.slice(0,10),s={newPeople:0,updatedToConnected:0,alreadyConnected:0,flaggedDuplicates:0,flagged:[]},i=Ge(o),l=new Map;for(let[c,a]of Object.entries(o)){if(!Ye.has(a.connectionStatus))continue;let f=He(a.name);f&&(l.has(f)||l.set(f,[]),l.get(f).push(c))}for(let c of e){if(!c.profileUrl)continue;let a=V(c.profileUrl),f=a?i.get(a):null,u=f?o[f]:void 0;if(u){if(u.connectionStatus!=="connected"){u.connectionStatus="connected";let m=c.time?W(c.time.replace(/^Connected\s+on\s+/i,"")):null;u.connectedAt=m||t,u.connectionDate=(m||t).slice(0,10),u.lastUpdated=t,s.updatedToConnected++}else if(s.alreadyConnected++,c.time&&(!u.connectedAt||!u.connectionDate)){let m=W(c.time.replace(/^Connected\s+on\s+/i,""));m&&(u.connectedAt||(u.connectedAt=m),u.connectionDate||(u.connectionDate=m.slice(0,10)),u.lastUpdated=t)}c.name&&!u.name&&(u.name=c.name),c.title&&(u.title=c.title),u.sources||(u.sources=[]),u.sources.includes("sync-connections")||u.sources.push("sync-connections"),u.lastSeen=r,u.seenCount=(u.seenCount||1)+1,u.lastUpdated=t}else{let m={name:c.name,title:c.title,location:null,company:null,connectionDegree:"1st",connectionsCount:null,mutualConnections:null,photoUrl:null,hasVerifiedBadge:!1,firstSeen:r,lastSeen:r,seenCount:1,sources:["sync-connections"],connectionStatus:"connected",connectionDate:r,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:t},g=He(c.name),v=g?l.get(g)||[]:[];v.length&&(m.possibleDuplicateOf=[...v],s.flaggedDuplicates++,s.flagged.push({name:c.name,candidates:v.length})),o[c.profileUrl]=m,a&&i.set(a,c.profileUrl),s.newPeople++}}return n||pe(o),s}function _o(e,n,o,t,r,s){if(console.log(`
62
- \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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(` Sync Connections Summary (${s})`),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"),r&&console.log(` LinkedIn header: ${r.toLocaleString()}`),console.log(` Connections scraped: ${e.length}`),console.log(` New people added: ${o.newPeople}`),console.log(` Updated to connected: ${o.updatedToConnected}`),console.log(` Already connected: ${o.alreadyConnected}`),n.length>0){console.log(`
63
- Newly accepted (${n.length}):`);for(let i of n)console.log(` \u2713 ${i.name||"Unknown"} (was: ${i.previousStatus})`)}if(o.flaggedDuplicates>0){console.log(`
64
- \u26A0 Possible duplicates (${o.flaggedDuplicates}) \u2014 new connection shares a name with a still-pending person (likely the same person accepting under a vanity url we couldn't match by slug). Flagged for review, NOT merged:`);for(let i of o.flagged||[])console.log(` ? ${i.name||"Unknown"}${i.candidates>1?` (${i.candidates} candidates)`:""}`)}t&&console.log(`
60
+ ${a} empty rounds \u2014 end of list.`);break}let v=await Ve(e);o&&v==="clicked"&&console.log(' \u2192 Clicked "Load more"'),await q(2e3)}return o||process.stdout.write(`
61
+ `),Array.from(i.values())}var Ye=new Set(["pending","sent_with_note","sent_without_note","sent_without_note_upsell"]);function He(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function Ge(e){let n=new Map;for(let[t,o]of Object.entries(e)){let r=V(o.profileUrl||t);r&&!n.has(r)&&n.set(r,t)}for(let[t,o]of Object.entries(e))for(let r of o.aliases||[])r&&!n.has(r)&&n.set(r,t);return n}function Dt(e,n){let t=[],o=Ge(n);for(let r of e){if(!r.profileUrl)continue;let s=o.get(V(r.profileUrl)),i=s?n[s]:void 0;i&&Ye.has(i.connectionStatus)&&t.push({...r,previousStatus:i.connectionStatus})}return t}function Ke(e,n){let t=B(),o=new Date().toISOString(),r=o.slice(0,10),s={newPeople:0,updatedToConnected:0,alreadyConnected:0,flaggedDuplicates:0,flagged:[]},i=Ge(t),l=new Map;for(let[c,a]of Object.entries(t)){if(!Ye.has(a.connectionStatus))continue;let f=He(a.name);f&&(l.has(f)||l.set(f,[]),l.get(f).push(c))}for(let c of e){if(!c.profileUrl)continue;let a=V(c.profileUrl),f=a?i.get(a):null,u=f?t[f]:void 0;if(u){if(u.connectionStatus!=="connected"){u.connectionStatus="connected";let m=c.time?W(c.time.replace(/^Connected\s+on\s+/i,"")):null;u.connectedAt=m||o,u.connectionDate=(m||o).slice(0,10),u.lastUpdated=o,s.updatedToConnected++}else if(s.alreadyConnected++,c.time&&(!u.connectedAt||!u.connectionDate)){let m=W(c.time.replace(/^Connected\s+on\s+/i,""));m&&(u.connectedAt||(u.connectedAt=m),u.connectionDate||(u.connectionDate=m.slice(0,10)),u.lastUpdated=o)}c.name&&!u.name&&(u.name=c.name),c.title&&(u.title=c.title),u.sources||(u.sources=[]),u.sources.includes("sync-connections")||u.sources.push("sync-connections"),u.lastSeen=r,u.seenCount=(u.seenCount||1)+1,u.lastUpdated=o}else{let m={name:c.name,title:c.title,location:null,company:null,connectionDegree:"1st",connectionsCount:null,mutualConnections:null,photoUrl:null,hasVerifiedBadge:!1,firstSeen:r,lastSeen:r,seenCount:1,sources:["sync-connections"],connectionStatus:"connected",connectionDate:r,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:o},g=He(c.name),v=g?l.get(g)||[]:[];v.length&&(m.possibleDuplicateOf=[...v],s.flaggedDuplicates++,s.flagged.push({name:c.name,candidates:v.length})),t[c.profileUrl]=m,a&&i.set(a,c.profileUrl),s.newPeople++}}return n||pe(t),s}function Tt(e,n,t,o,r,s){if(console.log(`
62
+ \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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(` Sync Connections Summary (${s})`),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"),r&&console.log(` LinkedIn header: ${r.toLocaleString()}`),console.log(` Connections scraped: ${e.length}`),console.log(` New people added: ${t.newPeople}`),console.log(` Updated to connected: ${t.updatedToConnected}`),console.log(` Already connected: ${t.alreadyConnected}`),n.length>0){console.log(`
63
+ Newly accepted (${n.length}):`);for(let i of n)console.log(` \u2713 ${i.name||"Unknown"} (was: ${i.previousStatus})`)}if(t.flaggedDuplicates>0){console.log(`
64
+ \u26A0 Possible duplicates (${t.flaggedDuplicates}) \u2014 new connection shares a name with a still-pending person (likely the same person accepting under a vanity url we couldn't match by slug). Flagged for review, NOT merged:`);for(let i of t.flagged||[])console.log(` ? ${i.name||"Unknown"}${i.candidates>1?` (${i.candidates} candidates)`:""}`)}o&&console.log(`
65
65
  [DRY RUN \u2014 nothing written to DB]`),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
66
- `)}async function Ro(){let e=$o();if(await Be(),e.list){Eo();return}let n=e.full?"full":"incremental",o=_e("sync",n);console.log(`
66
+ `)}async function _t(){let e=Ct();if(await Be(),e.list){$t();return}let n=e.full?"full":"incremental",t=_e("sync",n);console.log(`
67
67
  \u{1F504} Sync LinkedIn Connections (${n})
68
- `),e.dryRun&&console.log(" [DRY RUN mode]"),e.max!==1/0&&console.log(` Max: ${e.max}`);let{browser:t,page:r}=await $e();try{let s=await xo(r),i=e.full?await Io(r,{max:e.max,verbose:e.verbose,dryRun:e.dryRun}):await Do(r,{max:e.max,verbose:e.verbose});console.log(`
69
- Extracted ${i.length} connections.`);let l=B(),c=To(i,l),a=Ke(i,e.dryRun);_o(i,c,a,e.dryRun,s,n),Z(o,"success",{scraped:i.length,newPeople:a.newPeople,updatedToConnected:a.updatedToConnected})}catch(s){console.error(`
70
- \u2717 Error:`,s.message),e.verbose&&console.error(s.stack),Z(o,"error",null,s.message)}finally{await t.close().catch(()=>{})}}process.argv[1]&&import.meta.url===Co(process.argv[1]).href&&Ro();export{Ge as buildSlugIndex,To as detectNewlyAccepted,He as normName,Ke as syncToDatabaseBatch};
68
+ `),e.dryRun&&console.log(" [DRY RUN mode]"),e.max!==1/0&&console.log(` Max: ${e.max}`);let{browser:o,page:r}=await $e();try{let s=await Et(r),i=e.full?await xt(r,{max:e.max,verbose:e.verbose,dryRun:e.dryRun}):await It(r,{max:e.max,verbose:e.verbose});console.log(`
69
+ Extracted ${i.length} connections.`);let l=B(),c=Dt(i,l),a=Ke(i,e.dryRun);Tt(i,c,a,e.dryRun,s,n),Z(t,"success",{scraped:i.length,newPeople:a.newPeople,updatedToConnected:a.updatedToConnected})}catch(s){console.error(`
70
+ \u2717 Error:`,s.message),e.verbose&&console.error(s.stack),Z(t,"error",null,s.message)}finally{await o.close().catch(()=>{})}}process.argv[1]&&import.meta.url===At(process.argv[1]).href&&_t();export{Ge as buildSlugIndex,Dt as detectNewlyAccepted,He as normName,Ke as syncToDatabaseBatch};
@@ -1,4 +1,4 @@
1
- var Ve=Object.defineProperty;var Y=(e,t)=>()=>(e&&(t=e(e=0)),t);var We=(e,t)=>{for(var o in t)Ve(e,o,{get:t[o],enumerable:!0})};async function f(e){let t=Math.floor(Math.random()*2001),o=e+t;return new Promise(n=>setTimeout(n,o))}async function we(e){return await e.evaluate(()=>{let t=document.querySelectorAll("div.artdeco-modal--is-open");for(let n of t){let i=n.innerText||"",d=i.includes("Premium")||i.includes("premium")||i.includes("Upgrade")||i.includes("upgrade"),l=i.includes("Try for")||i.includes("free trial")||i.includes("/month")||i.includes("per month")||i.includes("Start my")||i.includes("Subscribe"),g=i.includes("Get hired faster")||i.includes("Get hired 2x");if(d||l||g){let L=n.querySelector('button[aria-label="Dismiss"]')||n.querySelector("button.artdeco-modal__dismiss")||n.querySelector("button[data-test-modal-close-btn]");if(L)return L.click(),{dismissed:!0,matched:i.substring(0,80)};let I=n.querySelectorAll("button");for(let a of I){let S=a.innerText?.trim().toLowerCase()||"",p=a.getAttribute("aria-label")?.toLowerCase()||"";if(S==="not now"||S==="no thanks"||S==="dismiss"||p.includes("dismiss"))return a.click(),{dismissed:!0,matched:i.substring(0,80)}}}}let o=document.querySelector(".premium-upsell-link")||document.querySelector("[data-test-premium-upsell]")||document.querySelector(".premium-hub-upsell");if(o){let n=o.closest('[class*="modal"]')?.querySelector('button[aria-label="Dismiss"]')||o.closest('[class*="banner"]')?.querySelector('button[aria-label="Close"]');if(n)return n.click(),{dismissed:!0,matched:"premium-banner"}}return!1})}var H=Y(()=>{});import{getPluginConfig as Je}from"@ilivemylife/graph-sdk";var Ke,Ye,N,kt,Ge,X=Y(async()=>{Ke=await Je();for(let[e,t]of Object.entries(Ke))process.env[e]===void 0&&(process.env[e]=t);Ye=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),kt=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),Ge=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.REJECTED,N.NEEDS_REVIEW]))});import"dotenv/config";import*as w from"fs";import*as b from"path";import{fileURLToPath as ot}from"url";function lt(){w.existsSync(A)||w.mkdirSync(A,{recursive:!0})}function at(e,t){if(!w.existsSync(e))return null;try{let o=JSON.parse(w.readFileSync(e,"utf-8"));try{w.copyFileSync(e,e+".backup")}catch{}return o}catch(o){console.error(`[!] ${t} is corrupted: ${o.message}`),console.error(` File: ${b.resolve(e)}`);let n=e+".backup";if(w.existsSync(n))try{let i=JSON.parse(w.readFileSync(n,"utf-8"));console.error(` Restored from ${n}`);try{w.copyFileSync(n,e)}catch{}return i}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{w.copyFileSync(e,e+".corrupted")}catch{}return null}}function ee(){return G||(lt(),G=at(st,"people.json")||{},G)}var it,rt,A,st,Wt,Jt,Kt,Yt,Gt,zt,Te,Qt,Zt,G,te=Y(async()=>{await X();it=ot(import.meta.url),rt=b.dirname(b.dirname(it)),A=process.env.DATA_DIR?b.resolve(process.env.DATA_DIR,"collected-profiles"):b.join(rt,"collected-profiles"),st=b.join(A,"people.json"),Wt=b.join(A,"jobs.json"),Jt=b.join(A,"quota.json"),Kt=b.join(A,"conversations.json"),Yt=b.join(A,"sync-state.json"),Gt=b.join(A,"application-questions.json"),zt=b.join(A,"profile-history"),Te=(e,t)=>{let o=parseInt(e,10);return Number.isInteger(o)&&o>=0?o:t},Qt=Te(process.env.CONNECT_MAX_DAILY,20),Zt=Te(process.env.CONNECT_MAX_WEEKLY,100),G=null});var Le={};We(Le,{extractCertificationsFromDetails:()=>mt,extractEducationFromDetails:()=>dt,extractExperienceFromDetails:()=>ct,extractFeaturedFromDetails:()=>ut,extractRecommendationsFromDetails:()=>pt,extractSkillsFromDetails:()=>ft});async function ct(e,t){let o=t.replace(/\/+$/,"")+"/details/experience/";try{await e.goto(o,{waitUntil:"domcontentloaded",timeout:6e4}),await f(3e3);let n=e.url();if(/\/(login|authwall|checkpoint)/i.test(n))throw new Error(`Session expired \u2014 bounced to ${n} when fetching /details/experience/`);for(let d=0;d<5;d++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await f(900);await f(1e3);let i=0;for(;i<5&&await e.evaluate(()=>{for(let l of document.querySelectorAll("button"))if(/^Load more$/i.test((l.textContent||"").trim()))return l.click(),!0;return!1});)i++,await f(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await f(700);return await e.evaluate(()=>{let d=document.querySelector("main");if(!d)return[];function l(a){let S=[];for(let p of a.querySelectorAll("div")){let h=Array.from(p.children).filter(x=>x.tagName==="DIV");if(h.length<3)continue;let y=h.filter(x=>(x.textContent||"").trim().length>50);y.length<3||(p.textContent||"").length<500||S.push({el:p,count:y.length,totalText:(p.textContent||"").length})}return S.sort((p,h)=>h.count-p.count||p.totalText-h.totalText),S[0]?.el}let g=l(d);if(!g)return[];let L=Array.from(g.children).filter(a=>a.tagName==="DIV").filter(a=>(a.textContent||"").trim().length>50);function I(a){let S=a[0]||null,p=null,h=null;if(a[1]){let u=a[1].split("\xB7").map(v=>v.trim());p=u[0]||null,u[1]&&(h=u[1])}let y=a.findIndex(u=>/(\d{4}|present)/i.test(u)&&/(-|–|—)/i.test(u)&&u.length<80),x=null,M=null;if(y>=0){let u=a[y].split("\xB7").map(v=>v.trim());x=u[0]||null,u[1]&&(M=u[1])}let q=null,R=-1;if(y>=0&&a[y+1]){let u=a[y+1],v=/^[>*\-•]|^&gt;/.test(u),j=/https?:\/\//.test(u),O=/\d{4}/.test(u),C=/,/.test(u)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(u);!v&&!j&&!O&&u.length<100&&C&&(q=u,R=y+1)}let z=null,m=-1,F=a[a.length-1];if(F&&/and\s+\+\d+\s+skills?$/i.test(F)){m=a.length-1;let u=F.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);u&&(z={listed:u[1].split(",").map(v=>v.trim()),additional:parseInt(u[2],10)})}let P=new Set([0,1,y,R,m].filter(u=>u>=0)),$=a.filter((u,v)=>!P.has(v)),k=$.length>0?$.join(`
1
+ var Ve=Object.defineProperty;var K=(e,t)=>()=>(e&&(t=e(e=0)),t);var We=(e,t)=>{for(var o in t)Ve(e,o,{get:t[o],enumerable:!0})};async function f(e){let t=Math.floor(Math.random()*2001),o=e+t;return new Promise(n=>setTimeout(n,o))}async function we(e){return await e.evaluate(()=>{let t=document.querySelectorAll("div.artdeco-modal--is-open");for(let n of t){let i=n.innerText||"",d=i.includes("Premium")||i.includes("premium")||i.includes("Upgrade")||i.includes("upgrade"),l=i.includes("Try for")||i.includes("free trial")||i.includes("/month")||i.includes("per month")||i.includes("Start my")||i.includes("Subscribe"),g=i.includes("Get hired faster")||i.includes("Get hired 2x");if(d||l||g){let L=n.querySelector('button[aria-label="Dismiss"]')||n.querySelector("button.artdeco-modal__dismiss")||n.querySelector("button[data-test-modal-close-btn]");if(L)return L.click(),{dismissed:!0,matched:i.substring(0,80)};let I=n.querySelectorAll("button");for(let a of I){let S=a.innerText?.trim().toLowerCase()||"",p=a.getAttribute("aria-label")?.toLowerCase()||"";if(S==="not now"||S==="no thanks"||S==="dismiss"||p.includes("dismiss"))return a.click(),{dismissed:!0,matched:i.substring(0,80)}}}}let o=document.querySelector(".premium-upsell-link")||document.querySelector("[data-test-premium-upsell]")||document.querySelector(".premium-hub-upsell");if(o){let n=o.closest('[class*="modal"]')?.querySelector('button[aria-label="Dismiss"]')||o.closest('[class*="banner"]')?.querySelector('button[aria-label="Close"]');if(n)return n.click(),{dismissed:!0,matched:"premium-banner"}}return!1})}var H=K(()=>{});import{getPluginConfig as Je}from"@ilivemylife/graph-sdk";var Ye,Ke,j,kt,Ge,X=K(async()=>{Ye=await Je();for(let[e,t]of Object.entries(Ye))process.env[e]===void 0&&(process.env[e]=t);Ke=process.env.LINKEDIN_NAME,j=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),kt=Object.freeze(new Set([j.DRAFT,j.CONFIRMED,j.NEEDS_REVIEW])),Ge=Object.freeze(new Set([j.DRAFT,j.CONFIRMED,j.REJECTED,j.NEEDS_REVIEW]))});import"dotenv/config";import*as w from"fs";import*as b from"path";import{fileURLToPath as ot}from"url";function lt(){w.existsSync(A)||w.mkdirSync(A,{recursive:!0})}function at(e,t){if(!w.existsSync(e))return null;try{let o=JSON.parse(w.readFileSync(e,"utf-8"));try{w.copyFileSync(e,e+".backup")}catch{}return o}catch(o){console.error(`[!] ${t} is corrupted: ${o.message}`),console.error(` File: ${b.resolve(e)}`);let n=e+".backup";if(w.existsSync(n))try{let i=JSON.parse(w.readFileSync(n,"utf-8"));console.error(` Restored from ${n}`);try{w.copyFileSync(n,e)}catch{}return i}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{w.copyFileSync(e,e+".corrupted")}catch{}return null}}function ee(){return G||(lt(),G=at(st,"people.json")||{},G)}var it,rt,A,st,Wt,Jt,Yt,Kt,Gt,zt,Te,Qt,Zt,G,te=K(async()=>{await X();it=ot(import.meta.url),rt=b.dirname(b.dirname(it)),A=process.env.DATA_DIR?b.resolve(process.env.DATA_DIR,"collected-profiles"):b.join(rt,"collected-profiles"),st=b.join(A,"people.json"),Wt=b.join(A,"jobs.json"),Jt=b.join(A,"quota.json"),Yt=b.join(A,"conversations.json"),Kt=b.join(A,"sync-state.json"),Gt=b.join(A,"application-questions.json"),zt=b.join(A,"profile-history"),Te=(e,t)=>{let o=parseInt(e,10);return Number.isInteger(o)&&o>=0?o:t},Qt=Te(process.env.CONNECT_MAX_DAILY,20),Zt=Te(process.env.CONNECT_MAX_WEEKLY,100),G=null});var Le={};We(Le,{extractCertificationsFromDetails:()=>mt,extractEducationFromDetails:()=>dt,extractExperienceFromDetails:()=>ct,extractFeaturedFromDetails:()=>ut,extractRecommendationsFromDetails:()=>pt,extractSkillsFromDetails:()=>ft});async function ct(e,t){let o=t.replace(/\/+$/,"")+"/details/experience/";try{await e.goto(o,{waitUntil:"domcontentloaded",timeout:6e4}),await f(3e3);let n=e.url();if(/\/(login|authwall|checkpoint)/i.test(n))throw new Error(`Session expired \u2014 bounced to ${n} when fetching /details/experience/`);for(let d=0;d<5;d++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await f(900);await f(1e3);let i=0;for(;i<5&&await e.evaluate(()=>{for(let l of document.querySelectorAll("button"))if(/^Load more$/i.test((l.textContent||"").trim()))return l.click(),!0;return!1});)i++,await f(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await f(700);return await e.evaluate(()=>{let d=document.querySelector("main");if(!d)return[];function l(a){let S=[];for(let p of a.querySelectorAll("div")){let h=Array.from(p.children).filter(x=>x.tagName==="DIV");if(h.length<3)continue;let y=h.filter(x=>(x.textContent||"").trim().length>50);y.length<3||(p.textContent||"").length<500||S.push({el:p,count:y.length,totalText:(p.textContent||"").length})}return S.sort((p,h)=>h.count-p.count||p.totalText-h.totalText),S[0]?.el}let g=l(d);if(!g)return[];let L=Array.from(g.children).filter(a=>a.tagName==="DIV").filter(a=>(a.textContent||"").trim().length>50);function I(a){let S=a[0]||null,p=null,h=null;if(a[1]){let u=a[1].split("\xB7").map(v=>v.trim());p=u[0]||null,u[1]&&(h=u[1])}let y=a.findIndex(u=>/(\d{4}|present)/i.test(u)&&/(-|–|—)/i.test(u)&&u.length<80),x=null,M=null;if(y>=0){let u=a[y].split("\xB7").map(v=>v.trim());x=u[0]||null,u[1]&&(M=u[1])}let q=null,R=-1;if(y>=0&&a[y+1]){let u=a[y+1],v=/^[>*\-•]|^&gt;/.test(u),N=/https?:\/\//.test(u),O=/\d{4}/.test(u),C=/,/.test(u)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(u);!v&&!N&&!O&&u.length<100&&C&&(q=u,R=y+1)}let z=null,m=-1,F=a[a.length-1];if(F&&/and\s+\+\d+\s+skills?$/i.test(F)){m=a.length-1;let u=F.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);u&&(z={listed:u[1].split(",").map(v=>v.trim()),additional:parseInt(u[2],10)})}let P=new Set([0,1,y,R,m].filter(u=>u>=0)),$=a.filter((u,v)=>!P.has(v)),k=$.length>0?$.join(`
2
2
 
3
3
  `):null;return{title:S,company:p,employmentType:h,dates:x,duration:M,location:q,description:k,skills:z,_raw:a}}return L.map(a=>{let p=(a.innerText||"").trim().split(`
4
4
  `).map(h=>h.trim()).filter(h=>h&&h.length<5e3);return I(p)}).filter(a=>a.title)})}catch(n){if(/session expired|bounced to|authwall|checkpoint/i.test(n.message||""))throw n;return console.error(`extractExperienceFromDetails failed for ${t}: ${n.message?.slice(0,120)}`),[]}}async function U(e,t,o){let n=t.replace(/\/+$/,"")+`/details/${o}/`;await e.goto(n,{waitUntil:"domcontentloaded",timeout:6e4}),await f(3e3);let i=e.url();if(/\/(login|authwall|checkpoint)/i.test(i))throw new Error(`Session expired \u2014 bounced to ${i} when fetching /details/${o}/`);if(!i.toLowerCase().includes(`/details/${o.toLowerCase()}/`))throw new Error(`Section /details/${o}/ not available on profile (landed on ${i})`);for(let l=0;l<4;l++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await f(700);await f(800);let d=0;for(;d<5&&await e.evaluate(()=>{for(let g of document.querySelectorAll("button"))if(/^Load more$/i.test((g.textContent||"").trim()))return g.click(),!0;return!1});)d++,await f(1300),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await f(600)}async function W(e,t,o,n){try{return await n()}catch(i){let d=i.message||"";if(/session expired|bounced to|authwall|checkpoint/i.test(d))throw i;return/not available on profile/i.test(d)?(console.log(` (${t}: section not on profile \u2014 skipped)`),[]):(console.error(`${o} failed for ${e}: ${d.slice(0,120)}`),[])}}async function ut(e,t){return W(t,"featured","extractFeaturedFromDetails",async()=>(await U(e,t,"featured"),await e.evaluate(`(() => {
@@ -172,7 +172,7 @@ var Ve=Object.defineProperty;var Y=(e,t)=>()=>(e&&(t=e(e=0)),t);var We=(e,t)=>{f
172
172
  if (e.recommenderTitle && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.recommenderTitle.trim())) return false;
173
173
  return true;
174
174
  });
175
- })()`)))}var V,Me=Y(()=>{H();V=`
175
+ })()`)))}var V,Me=K(()=>{H();V=`
176
176
  function findEntryContainer(root) {
177
177
  const candidates = [];
178
178
  for (const div of root.querySelectorAll('div')) {
@@ -236,7 +236,7 @@ function findEntryContainer(root) {
236
236
  return candidates[0]?.el;
237
237
  }
238
238
  `});import et from"puppeteer";import{addExtra as tt}from"puppeteer-extra";import nt from"puppeteer-extra-plugin-stealth";H();await X();import _ from"fs";import T from"path";var ze="cookies.json";function ye(){let e=process.env.ILML_SCOPE_DIR;return e?T.join(e,"plugins-state","linkedin","cookies.json"):ze}function be(){let e=ye();if(!_.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=_.readFileSync(e,"utf-8")}catch(n){throw new Error(`Failed to read cookies at ${e}: ${n.message}. Run: ilml linkedin login`)}let o;try{o=JSON.parse(t)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(o)||o.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return o}function Se(){return _.existsSync(ye())}function Qe(){let e=process.env.ILML_SCOPE_DIR;return e?T.join(e,"plugins-state","linkedin"):"."}function ve(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function Ze(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?ve(t[1]):"default"}function Ce(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return _.existsSync(t)||_.mkdirSync(t,{recursive:!0}),T.resolve(t);let o=ve(e||Ze()),n=T.join(Qe(),"chrome-profile",o);return _.existsSync(n)||_.mkdirSync(n,{recursive:!0}),T.resolve(n)}var ke=".ilml-seeded";function xe(e){return!_.existsSync(T.join(e,ke))}function _e(e){try{_.writeFileSync(T.join(e,ke),new Date().toISOString())}catch{}}function Ee(e){let t=0;for(let o of["SingletonLock","SingletonCookie","SingletonSocket"])try{_.rmSync(T.join(e,o),{force:!0}),t++}catch{}return t}var Xe={headless:!1,defaultViewport:null,protocolTimeout:3e5};async function Ae(e,t={}){let o=Ce(),n={...Xe,...t,userDataDir:o},i;try{i=await e.launch(n)}catch{Ee(o);try{i=await e.launch(n)}catch(l){throw new Error(`Could not open the LinkedIn automation Chrome profile at ${o}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${l.message})`)}}return{browser:i,profileDir:o,needsSeed:xe(o)}}async function Ie(e,t){if(!t||!t.needsSeed)return!1;if(!Se())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(...be()),_e(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var $e=tt(et);$e.use(nt());async function De(){let{browser:e,profileDir:t,needsSeed:o}=await Ae($e),n=async()=>{console.log(`
239
- Closing browser...`);try{await e.close()}catch{}process.exit(0)};process.on("SIGINT",n),process.on("SIGTERM",n);let i=await e.newPage();return await i.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Ie(i,{profileDir:t,needsSeed:o}),console.log(" Browser launched (persistent profile)."),{browser:e,page:i}}H();await te();async function ht(e,t){let o=e.url();if(o.includes("/in/"))return!1;if(o.includes("/login")||o.includes("/authwall")||o.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: ilml linkedin login");console.log(` Off-track: ${o.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await f(3e3);let n=e.url();return n.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${n.slice(0,80)}`),!0}async function qe(e,t,o={}){let{extractExperience:n=!1,extractFeatured:i=!1,extractEducation:d=!1,extractSkills:l=!1,extractRecommendations:g=!1,extractCertifications:L=!1}=o;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await f(3e3),await we(e)&&(console.log(" Dismissed Premium overlay"),await f(1500),await ht(e,t));let a=0;for(let m=0;m<2;m++){let F=await e.evaluate(()=>document.body.scrollHeight);for(let $=1;$<=6;$++)await e.evaluate(k=>window.scrollTo(0,k),F*$/6),await f(900);let P=await e.evaluate(()=>document.body.scrollHeight);if(P===a)break;a=P}await f(800);let S=null;try{let m=e.url();m&&/\/in\/[^/?#]/.test(m)&&(S=m.split("?")[0].replace(/\/+$/,""))}catch{}let p=await e.evaluate(()=>{let m=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),F=new Set(["Ad Options","Don\u2019t want to see this","0 notifications","Explore Premium profiles","You might like","People you may know","Suggested for you","More profiles for you","Promoted"]),P=r=>{let s=(r||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(s)},$={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},k=document.querySelector("main");if(!k)return $;let u=[...Array.from(k.querySelectorAll("h1")),...Array.from(k.querySelectorAll("h2"))],v=Array.from(k.querySelectorAll("h2")),j=u.find(r=>{let s=r.textContent&&r.textContent.trim(),c=(s||"").replace(/\s*\(\d+\)$/,"").trim();return s&&s.length>1&&s.length<100&&!m.has(c)&&!F.has(c)}),O=j?j.textContent.trim():null,C=j?j.parentElement:null;for(;C&&C!==k&&!Array.from(C.children).filter(s=>s.tagName==="P").some(s=>{let c=s.textContent&&s.textContent.trim();return c&&c.length>5&&!P(c)});)C=C.parentElement;let oe=null,ie=null,re=null,Q=null;if(C&&C!==k){let r=Array.from(C.children).filter(c=>c.tagName==="P").filter(c=>{let D=c.textContent&&c.textContent.trim();return D&&D.length>5&&!P(D)});if(r[0]&&(oe=r[0].textContent.trim()),r[1]){let c=r[1].textContent.trim().split(/\s*[·•]\s*/);ie=c[0]||null,c.length>1&&(re=c.slice(1).join(" \xB7 "))}let s=Array.from(C.children).filter(c=>c.tagName==="DIV");for(let c=s.length-1;c>=0;c--){let D=s[c].textContent&&s[c].textContent.trim();if(D&&!(O&&D.startsWith(O))&&(Q=D.split(/[·•]/)[0].trim(),Q))break}}let se=null;if(C){let r=C.querySelectorAll("p, span, div");for(let s of r){let c=(s.textContent||"").trim().replace(/^[·•]\s*/,"");if(c==="1st"||c==="2nd"||c==="3rd"){se=c;break}}}let Pe=!!k.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),le=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),Ne=le&&le.src||null,J=k.textContent||"",ae=null,ce=J.match(/(\d+\+?)\s+connections\b/i);ce&&(ae=ce[1]+" connections");let K=null,ue=J.match(/(\d+)\s+mutual connection/i),de=J.match(/and\s+(\d+)\s+other mutual/i),je=J.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);ue?K=parseInt(ue[1],10):de?K=2+parseInt(de[1],10):je&&(K=2);let fe=null,me=null,pe=v.find(r=>r.textContent&&r.textContent.trim()==="About");if(pe){let r=pe.parentElement;for(;r&&r.tagName!=="SECTION";)r=r.parentElement;if(r){let s=(r.textContent||"").trim();s=s.replace(/^About\s*/,"").trim();let c=s.match(/Top skills\s*(.+?)$/i);if(c){let Z=c[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Ue=>Ue.trim()).filter(Boolean);Z.length>0&&Z.length<10&&(me=Z)}s=s.split(/\n?…\s*more/i)[0].trim(),s=s.split(/\n?\.\.\.\s*more/i)[0].trim(),s=s.split(/\bTop skills\b/i)[0].trim(),s=s.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),fe=s||null}}let he=null,ge=v.find(r=>r.textContent&&r.textContent.trim()==="Activity");if(ge){let r=ge.parentElement;for(;r&&r.tagName!=="SECTION";)r=r.parentElement;if(r){let s=(r.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);s&&(he=parseInt(s[1].replace(/,/g,""),10))}}let Oe=[...new Set(v.map(r=>(r.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(r=>r&&r.length>1&&r.length<60&&r!==O).filter(r=>m.has(r)))],B=document.body.textContent||"",Be=/#OpenToWork\b/i.test(B)||/\bOpen to work\b/.test(B),He=/#Hiring\b/i.test(B)||/\bI'?m hiring\b/i.test(B)||/\bWe are hiring\b/i.test(B);return{name:O,title:oe,location:Q,currentCompany:ie,currentSchool:re,connectionDegree:se,hasVerifiedBadge:Pe,photoUrl:Ne,connectionsLevel:ae,mutualConnectionsCount:K,followers:he,openToWork:Be,hiring:He,about:fe,topSkills:me,availableSections:Oe}});console.log(`Viewed: ${p.name} - ${p.title}`);let h=null,y=null,x=null,M=null,q=null,R=null;if(n||i||d||l||g||L){let m=await Promise.resolve().then(()=>(Me(),Le));n&&(h=await m.extractExperienceFromDetails(e,t),console.log(` + Experience: ${h.length} entries`)),i&&(y=await m.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${y.length} entries`)),d&&(x=await m.extractEducationFromDetails(e,t),console.log(` + Education: ${x.length} entries`)),l&&(M=await m.extractSkillsFromDetails(e,t),console.log(` + Skills: ${M.length} entries`)),g&&(q=await m.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${q.length} entries`)),L&&(R=await m.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${R.length} entries`))}return{...p,profileUrl:t,resolvedUrl:S,...h!==null&&{experience:h},...y!==null&&{featured:y},...x!==null&&{education:x},...M!==null&&{skillsFull:M},...q!==null&&{recommendations:q},...R!==null&&{certifications:R}}}catch(I){console.error(`Error viewing profile ${t}:`,I.message);try{await e.goto("about:blank",{timeout:1e4}),await f(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(I.message||""))throw I;return null}}await te();H();var ne=process.argv.slice(2),Re=ne.filter(e=>e.startsWith("http")),Fe=parseInt(ne.find(e=>e.startsWith("--pick="))?.split("=")[1]||"0"),gt=ne.includes("--has-about");function wt(e,t){return[...e].sort(()=>Math.random()-.5).slice(0,t)}function yt(){if(Re.length>0)return Re.map(t=>({url:t,name:"(arg)"}));if(Fe>0){let t=ee(),o=Object.entries(t).filter(([n])=>n.startsWith("http")).filter(([,n])=>gt?!!(n.about&&n.about.trim()):!n.about);return wt(o,Fe).map(([n,i])=>({url:n,name:i.name}))}let e=process.env.MY_LINKEDIN_URL;return e||(console.error("Pass a URL, use --pick=N, or set MY_LINKEDIN_URL in .env"),process.exit(1)),[{url:e,name:"(self)"}]}function E(e,t,o=80){if(t==null){console.log(` ${e.padEnd(20)} (null)`);return}let n=String(t),i=n.length>o?n.slice(0,o)+`\u2026 (+${n.length-o} chars)`:n;console.log(` ${e.padEnd(20)} ${i} [len=${n.length}]`)}async function bt(){let e=yt();console.log(`
239
+ Closing browser...`);try{await e.close()}catch{}process.exit(0)};process.on("SIGINT",n),process.on("SIGTERM",n);let i=await e.newPage();return await i.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Ie(i,{profileDir:t,needsSeed:o}),console.log(" Browser launched (persistent profile)."),{browser:e,page:i}}H();await te();async function ht(e,t){let o=e.url();if(o.includes("/in/"))return!1;if(o.includes("/login")||o.includes("/authwall")||o.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: ilml linkedin login");console.log(` Off-track: ${o.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await f(3e3);let n=e.url();return n.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${n.slice(0,80)}`),!0}async function qe(e,t,o={}){let{extractExperience:n=!1,extractFeatured:i=!1,extractEducation:d=!1,extractSkills:l=!1,extractRecommendations:g=!1,extractCertifications:L=!1}=o;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await f(3e3),await we(e)&&(console.log(" Dismissed Premium overlay"),await f(1500),await ht(e,t));let a=0;for(let m=0;m<2;m++){let F=await e.evaluate(()=>document.body.scrollHeight);for(let $=1;$<=6;$++)await e.evaluate(k=>window.scrollTo(0,k),F*$/6),await f(900);let P=await e.evaluate(()=>document.body.scrollHeight);if(P===a)break;a=P}await f(800);let S=null;try{let m=e.url();m&&/\/in\/[^/?#]/.test(m)&&(S=m.split("?")[0].replace(/\/+$/,""))}catch{}let p=await e.evaluate(()=>{let m=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),F=new Set(["Ad Options","Don\u2019t want to see this","0 notifications","Explore Premium profiles","You might like","People you may know","Suggested for you","More profiles for you","Promoted"]),P=r=>{let s=(r||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(s)},$={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},k=document.querySelector("main");if(!k)return $;let u=[...Array.from(k.querySelectorAll("h1")),...Array.from(k.querySelectorAll("h2"))],v=Array.from(k.querySelectorAll("h2")),N=u.find(r=>{let s=r.textContent&&r.textContent.trim(),c=(s||"").replace(/\s*\(\d+\)$/,"").trim();return s&&s.length>1&&s.length<100&&!m.has(c)&&!F.has(c)}),O=N?N.textContent.trim():null,C=N?N.parentElement:null;for(;C&&C!==k&&!Array.from(C.children).filter(s=>s.tagName==="P").some(s=>{let c=s.textContent&&s.textContent.trim();return c&&c.length>5&&!P(c)});)C=C.parentElement;let oe=null,ie=null,re=null,Q=null;if(C&&C!==k){let r=Array.from(C.children).filter(c=>c.tagName==="P").filter(c=>{let D=c.textContent&&c.textContent.trim();return D&&D.length>5&&!P(D)});if(r[0]&&(oe=r[0].textContent.trim()),r[1]){let c=r[1].textContent.trim().split(/\s*[·•]\s*/);ie=c[0]||null,c.length>1&&(re=c.slice(1).join(" \xB7 "))}let s=Array.from(C.children).filter(c=>c.tagName==="DIV");for(let c=s.length-1;c>=0;c--){let D=s[c].textContent&&s[c].textContent.trim();if(D&&!(O&&D.startsWith(O))&&(Q=D.split(/[·•]/)[0].trim(),Q))break}}let se=null;if(C){let r=C.querySelectorAll("p, span, div");for(let s of r){let c=(s.textContent||"").trim().replace(/^[·•]\s*/,"");if(c==="1st"||c==="2nd"||c==="3rd"){se=c;break}}}let Pe=!!k.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),le=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),je=le&&le.src||null,J=k.textContent||"",ae=null,ce=J.match(/(\d+\+?)\s+connections\b/i);ce&&(ae=ce[1]+" connections");let Y=null,ue=J.match(/(\d+)\s+mutual connection/i),de=J.match(/and\s+(\d+)\s+other mutual/i),Ne=J.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);ue?Y=parseInt(ue[1],10):de?Y=2+parseInt(de[1],10):Ne&&(Y=2);let fe=null,me=null,pe=v.find(r=>r.textContent&&r.textContent.trim()==="About");if(pe){let r=pe.parentElement;for(;r&&r.tagName!=="SECTION";)r=r.parentElement;if(r){let s=(r.textContent||"").trim();s=s.replace(/^About\s*/,"").trim();let c=s.match(/Top skills\s*(.+?)$/i);if(c){let Z=c[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Ue=>Ue.trim()).filter(Boolean);Z.length>0&&Z.length<10&&(me=Z)}s=s.split(/\n?…\s*more/i)[0].trim(),s=s.split(/\n?\.\.\.\s*more/i)[0].trim(),s=s.split(/\bTop skills\b/i)[0].trim(),s=s.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),fe=s||null}}let he=null,ge=v.find(r=>r.textContent&&r.textContent.trim()==="Activity");if(ge){let r=ge.parentElement;for(;r&&r.tagName!=="SECTION";)r=r.parentElement;if(r){let s=(r.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);s&&(he=parseInt(s[1].replace(/,/g,""),10))}}let Oe=[...new Set(v.map(r=>(r.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(r=>r&&r.length>1&&r.length<60&&r!==O).filter(r=>m.has(r)))],B=document.body.textContent||"",Be=/#OpenToWork\b/i.test(B)||/\bOpen to work\b/.test(B),He=/#Hiring\b/i.test(B)||/\bI'?m hiring\b/i.test(B)||/\bWe are hiring\b/i.test(B);return{name:O,title:oe,location:Q,currentCompany:ie,currentSchool:re,connectionDegree:se,hasVerifiedBadge:Pe,photoUrl:je,connectionsLevel:ae,mutualConnectionsCount:Y,followers:he,openToWork:Be,hiring:He,about:fe,topSkills:me,availableSections:Oe}});console.log(`Viewed: ${p.name} - ${p.title}`);let h=null,y=null,x=null,M=null,q=null,R=null;if(n||i||d||l||g||L){let m=await Promise.resolve().then(()=>(Me(),Le));n&&(h=await m.extractExperienceFromDetails(e,t),console.log(` + Experience: ${h.length} entries`)),i&&(y=await m.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${y.length} entries`)),d&&(x=await m.extractEducationFromDetails(e,t),console.log(` + Education: ${x.length} entries`)),l&&(M=await m.extractSkillsFromDetails(e,t),console.log(` + Skills: ${M.length} entries`)),g&&(q=await m.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${q.length} entries`)),L&&(R=await m.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${R.length} entries`))}return{...p,profileUrl:t,resolvedUrl:S,...h!==null&&{experience:h},...y!==null&&{featured:y},...x!==null&&{education:x},...M!==null&&{skillsFull:M},...q!==null&&{recommendations:q},...R!==null&&{certifications:R}}}catch(I){console.error(`Error viewing profile ${t}:`,I.message);try{await e.goto("about:blank",{timeout:1e4}),await f(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(I.message||""))throw I;return null}}await te();H();var ne=process.argv.slice(2),Re=ne.filter(e=>e.startsWith("http")),Fe=parseInt(ne.find(e=>e.startsWith("--pick="))?.split("=")[1]||"0"),gt=ne.includes("--has-about");function wt(e,t){return[...e].sort(()=>Math.random()-.5).slice(0,t)}function yt(){if(Re.length>0)return Re.map(t=>({url:t,name:"(arg)"}));if(Fe>0){let t=ee(),o=Object.entries(t).filter(([n])=>n.startsWith("http")).filter(([,n])=>gt?!!(n.about&&n.about.trim()):!n.about);return wt(o,Fe).map(([n,i])=>({url:n,name:i.name}))}let e=process.env.MY_LINKEDIN_URL;return e||(console.error("Pass a URL, use --pick=N, or set MY_LINKEDIN_URL in .env"),process.exit(1)),[{url:e,name:"(self)"}]}function E(e,t,o=80){if(t==null){console.log(` ${e.padEnd(20)} (null)`);return}let n=String(t),i=n.length>o?n.slice(0,o)+`\u2026 (+${n.length-o} chars)`:n;console.log(` ${e.padEnd(20)} ${i} [len=${n.length}]`)}async function bt(){let e=yt();console.log(`
240
240
  About-selector verification \u2014 ${e.length} profile(s)
241
241
  `);let{browser:t,page:o}=await De();try{for(let n=0;n<e.length;n++){let{url:i,name:d}=e[n];console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),console.log(` [${n+1}/${e.length}] ${d}`),console.log(` ${i}`),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");let l=await qe(o,i);if(!l){console.log(` \u26A0 viewProfile returned null \u2014 selector failed entirely
242
242
  `);continue}E("name",l.name),E("title",l.title),E("location",l.location),E("company",l.company),E("connectionDegree",l.connectionDegree),E("connectionsCount",l.connectionsCount),E("mutualConnections",l.mutualConnections),E("hasVerifiedBadge",l.hasVerifiedBadge),E("photoUrl",l.photoUrl,60),console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 about \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),E("about",l.about,200);let g=[];l.name||g.push("NAME MISSING"),l.title||g.push("TITLE MISSING"),l.location||g.push("LOCATION MISSING"),l.about||g.push("ABOUT MISSING"),console.log(`
package/dist/version.mjs CHANGED
@@ -1 +1 @@
1
- import{readFileSync as e}from"fs";import{fileURLToPath as r}from"url";function i(){return"1.20.0";try{let n=new URL("./ilml-plugin.json",import.meta.url);return JSON.parse(e(r(n),"utf-8")).version}catch{return"unknown"}}console.log(`ilml-plugin-linkedin ${i()}`);
1
+ import{readFileSync as e}from"fs";import{fileURLToPath as r}from"url";function i(){return"1.20.2";try{let n=new URL("./ilml-plugin.json",import.meta.url);return JSON.parse(e(r(n),"utf-8")).version}catch{return"unknown"}}console.log(`ilml-plugin-linkedin ${i()}`);