ilml-plugin-linkedin 1.20.8 → 1.20.9

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,69 +1,71 @@
1
- var lt=Object.defineProperty;var W=(e,t)=>{for(var n in t)lt(e,n,{get:t[n],enumerable:!0})};import{pathToFileURL as Hn}from"url";var X={jan:0,feb:1,mar:2,apr:3,may:4,jun:5,jul:6,aug:7,sep:8,oct:9,nov:10,dec:11},at={sunday:0,monday:1,tuesday:2,wednesday:3,thursday:4,friday:5,saturday:6};function U(e){let t=e.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);if(!t)return null;let n=parseInt(t[1],10),o=parseInt(t[2],10),r=t[3].toUpperCase()==="PM";return r&&n!==12&&(n+=12),!r&&n===12&&(n=0),{hours:n,minutes:o}}function V(e,t){if(!e)return null;let n=e.trim();if(!n)return null;if(t=t||new Date,/^just\s*now$/i.test(n))return t.toISOString();if(/^today\b/i.test(n)||/^\d{1,2}:\d{2}\s*(AM|PM)$/i.test(n)){let l=U(n),c=new Date(t);return l?c.setHours(l.hours,l.minutes,0,0):c.setHours(0,0,0,0),c.toISOString()}let o=n.match(/^(Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)\s*(.*)/i);if(o){let l=at[o[1].toLowerCase()],c=U(o[2]||""),a=new Date(t),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=n.match(/^([A-Z][a-z]+)\s+(\d{1,2}),?\s+(\d{4})\s*(.*)/i);if(r){let l=X[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=n.match(/^([A-Z][a-z]+)\s+(\d{1,2}),\s*(.*)/i);if(s){let l=X[s[1].toLowerCase().slice(0,3)];if(l===void 0)return null;let c=parseInt(s[2],10),a=U(s[3]||""),f=t.getFullYear(),u=new Date(f,l,c,a?.hours||0,a?.minutes||0,0,0);return u>t&&u.setFullYear(f-1),u.toISOString()}let i=n.match(/^([A-Z][a-z]+)\s+(\d{1,2})\s*(.*)/i);if(i){let l=X[i[1].toLowerCase().slice(0,3)];if(l===void 0)return null;let c=parseInt(i[2],10),a=U(i[3]||""),f=t.getFullYear(),u=new Date(f,l,c,a?.hours||0,a?.minutes||0,0,0);return u>t&&u.setFullYear(f-1),u.toISOString()}return null}async function G(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function ut(e,t,{timeout:n=45e3,poll:o=1e3,label:r="page"}={}){let s=Date.now();for(;Date.now()-s<n;){try{if(await e.evaluate(l=>!!document.querySelector(l),t)){let l=Date.now()-s;return l>6e3&&console.log(` (waited ${Math.round(l/1e3)}s for LinkedIn to finish loading ${r})`),!0}}catch{}await new Promise(i=>setTimeout(i,o))}return!1}var ft=/\/authwall|\/login|\/checkpoint|\/uas\/login/;function pt(e){return ft.test(e||"")}async function dt(e,{readySelector:t,label:n="page",timeout:o=45e3}={}){let r=await ut(e,t,{timeout:o,label:n});if(!r&&pt(e.url())){let s=new Error(`Session expired (${n}) \u2014 redirected to login. Run: ilml linkedin login`);throw s.code="SESSION_EXPIRED",s}return r}async function Z(e,t,{readySelector:n,label:o="page",timeout:r=45e3,gotoTimeout:s=6e4}={}){return await e.goto(t,{waitUntil:"domcontentloaded",timeout:s}),dt(e,{readySelector:n,label:o,timeout:r})}import{getPluginConfig as mt}from"@ilivemylife/graph-sdk";var ht=await mt();for(let[e,t]of Object.entries(ht))process.env[e]===void 0&&(process.env[e]=t);var gt=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),no=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),yt=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 St}from"url";var wt=St(import.meta.url),bt=S.dirname(S.dirname(wt)),_=process.env.DATA_DIR?S.resolve(process.env.DATA_DIR,"collected-profiles"):S.join(bt,"collected-profiles"),ee=S.join(_,"people.json"),co=S.join(_,"jobs.json"),lo=S.join(_,"quota.json"),ao=S.join(_,"conversations.json"),uo=S.join(_,"sync-state.json"),fo=S.join(_,"application-questions.json"),po=S.join(_,"profile-history"),he=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},mo=he(process.env.CONNECT_MAX_DAILY,20),ho=he(process.env.CONNECT_MAX_WEEKLY,100),M=null,vt=null,kt=null,At=null,Ct=null,$t=null;function ge(){M=null,vt=null,kt=null,At=null,Ct=null,$t=null}function ye(){y.existsSync(_)||y.mkdirSync(_,{recursive:!0})}function Et(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";y.writeFileSync(o,n);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 xt(e,t){if(!y.existsSync(e))return null;try{let n=JSON.parse(y.readFileSync(e,"utf-8"));try{y.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.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 Y(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function q(){return M||(ye(),M=xt(ee,"people.json")||{},M)}function Se(e){ye(),M=e;try{Et(ee,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${S.resolve(ee)}`)}}import Lt from"puppeteer";import{addExtra as Pt}from"puppeteer-extra";import Mt from"puppeteer-extra-plugin-stealth";import I from"fs";import D from"path";var It="cookies.json";function we(){let e=process.env.ILML_SCOPE_DIR;return e?D.join(e,"plugins-state","linkedin","cookies.json"):It}function be(){let e=we();if(!I.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=I.readFileSync(e,"utf-8")}catch(o){throw new Error(`Failed to read cookies at ${e}: ${o.message}. Run: ilml linkedin login`)}let n;try{n=JSON.parse(t)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(n)||n.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return n}function ve(){return I.existsSync(we())}function Tt(){let e=process.env.ILML_SCOPE_DIR;return e?D.join(e,"plugins-state","linkedin"):"."}function ke(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function _t(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?ke(t[1]):"default"}function Ae(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return I.existsSync(t)||I.mkdirSync(t,{recursive:!0}),D.resolve(t);let n=ke(e||_t()),o=D.join(Tt(),"chrome-profile",n);return I.existsSync(o)||I.mkdirSync(o,{recursive:!0}),D.resolve(o)}var Ce=".ilml-seeded";function $e(e){return!I.existsSync(D.join(e,Ce))}function Ee(e){try{I.writeFileSync(D.join(e,Ce),new Date().toISOString())}catch{}}function xe(e){let t=0;for(let n of["SingletonLock","SingletonCookie","SingletonSocket"])try{I.rmSync(D.join(e,n),{force:!0}),t++}catch{}return t}import te from"fs";import Rt from"path";var Dt={headless:!1,defaultViewport:null,protocolTimeout:3e5},J=new Set,Ie=!1;async function K(){let e=[...J].map(t=>{try{return Promise.resolve(t.close()).catch(()=>{})}catch{return Promise.resolve()}});J.clear(),await Promise.race([Promise.all(e),new Promise(t=>setTimeout(t,5e3))])}function Ot(){if(Ie)return;Ie=!0;let e=t=>async()=>{await K(),process.exit(t)};process.once("SIGINT",e(130)),process.once("SIGTERM",e(143)),process.once("SIGHUP",e(129)),process.once("uncaughtException",async t=>{await K(),console.error(t&&t.stack||t),process.exit(1)}),process.once("unhandledRejection",async t=>{await K(),console.error(t),process.exit(1)}),process.stdout.on("error",async t=>{t&&t.code==="EPIPE"&&(await K(),process.exit(0))}),process.on("exit",()=>{for(let t of J)try{let n=t.process&&t.process();n&&n.kill("SIGKILL")}catch{}})}function ne(e){return Rt.join(e,".ilml-browser-session.json")}function De(e,t={}){try{te.writeFileSync(ne(e),JSON.stringify({ownerPid:process.pid,startedAt:Date.now(),...t}))}catch{}}function jt(e,t){try{let n=t.wsEndpoint&&t.wsEndpoint();De(e,n?{wsEndpoint:n}:{})}catch{}}function Nt(e){let t=Oe(e);t&&t.ownerPid===process.pid&&B(e)}function B(e){try{te.rmSync(ne(e),{force:!0})}catch{}}function Oe(e){try{return JSON.parse(te.readFileSync(ne(e),"utf-8"))}catch{return null}}function Te(e){if(!e||e===process.pid)return!0;try{return process.kill(e,0),!0}catch(t){return!t||t.code!=="ESRCH"}}function _e(e,t,n){let o,r=new Promise(i=>{o=setTimeout(()=>i(n),t)}),s=Promise.resolve(e).then(i=>(clearTimeout(o),i),i=>{throw clearTimeout(o),i});return Promise.race([s,r])}async function Re(e,t,{probeTimeoutMs:n=4e3}={}){let o=Oe(t);if(!o)return"free";if(!o.wsEndpoint)return o.ownerPid&&o.ownerPid!==process.pid&&Te(o.ownerPid)?"live":(B(t),"free");let r=Symbol("timeout"),s=e.connect({browserWSEndpoint:o.wsEndpoint,defaultViewport:null}).catch(()=>null),i=await _e(s,n,r);if(i===r)return s.then(c=>{if(c)try{c.disconnect()}catch{}}),"live";if(!i)return B(t),"free";if(Te(o.ownerPid)){try{i.disconnect()}catch{}return"live"}if(console.log(" (recovered an orphaned automation browser from a previous run \u2014 closing it)"),await _e(i.close().then(()=>!0).catch(()=>!1),n,!1))return B(t),"free";try{i.disconnect()}catch{}return"live"}function Ft(e,t){e&&(Ot(),J.add(e),e.on("disconnected",()=>{J.delete(e),t&&B(t)}))}async function je(e,t={}){let n=Ae(),o={...Dt,...t,userDataDir:n},r=`Could not open the LinkedIn automation Chrome profile at ${n}. Another LinkedIn automation command is already running (or its window is still open) \u2014 wait for it to finish or close that window, then retry.`;if(await Re(e,n)==="live")throw new Error(r);De(n);let s;try{s=await e.launch(o)}catch{if(await Re(e,n)==="live")throw new Error(r);xe(n);try{s=await e.launch(o)}catch(l){throw Nt(n),new Error(`Could not open the LinkedIn automation Chrome profile at ${n}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${l.message})`)}}return Ft(s,n),jt(n,s),{browser:s,profileDir:n,needsSeed:$e(n)}}async function Ne(e,t){if(!t||!t.needsSeed)return!1;if(!ve())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()),Ee(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var Fe=Pt(Lt);Fe.use(Mt());async function Le(){let{browser:e,profileDir:t,needsSeed:n}=await je(Fe),o=await e.newPage();return await o.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Ne(o,{profileDir:t,needsSeed:n}),console.log(" Browser launched (persistent profile)."),{browser:e,page:o}}import"dotenv/config";import*as A from"fs";import*as O from"path";import{fileURLToPath as Wt}from"url";import"dotenv/config";import{createGraphClient as Ut,resolveToken as qt}from"@ilivemylife/graph-sdk";import{config as Bt}from"dotenv";Bt();var Pe=qt()||process.env.TOKEN;Pe||(console.error(`
1
+ var ft=Object.defineProperty;var W=(e,t)=>{for(var n in t)ft(e,n,{get:t[n],enumerable:!0})};import{pathToFileURL as Yn}from"url";import b from"fs";import T from"path";var pt="cookies.json";function X(){let e=process.env.ILML_SCOPE_DIR;return e?T.join(e,"plugins-state","linkedin","cookies.json"):pt}function dt(){let e=X(),t=T.dirname(e);return t&&t!=="."&&!b.existsSync(t)&&b.mkdirSync(t,{recursive:!0}),e}function ge(e){let t=dt();return b.writeFileSync(t,JSON.stringify(e)),t}function ye(){let e=X();if(!b.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=b.readFileSync(e,"utf-8")}catch(o){throw new Error(`Failed to read cookies at ${e}: ${o.message}. Run: ilml linkedin login`)}let n;try{n=JSON.parse(t)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(n)||n.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return n}function Se(){return b.existsSync(X())}function mt(){let e=process.env.ILML_SCOPE_DIR;return e?T.join(e,"plugins-state","linkedin"):"."}function we(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function ht(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?we(t[1]):"default"}function be(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return b.existsSync(t)||b.mkdirSync(t,{recursive:!0}),T.resolve(t);let n=we(e||ht()),o=T.join(mt(),"chrome-profile",n);return b.existsSync(o)||b.mkdirSync(o,{recursive:!0}),T.resolve(o)}var ve=".ilml-seeded";function ke(e){return!b.existsSync(T.join(e,ve))}function Ae(e){try{b.writeFileSync(T.join(e,ve),new Date().toISOString())}catch{}}function Ce(e){let t=0;for(let n of["SingletonLock","SingletonCookie","SingletonSocket"])try{b.rmSync(T.join(e,n),{force:!0}),t++}catch{}return t}var Z={jan:0,feb:1,mar:2,apr:3,may:4,jun:5,jul:6,aug:7,sep:8,oct:9,nov:10,dec:11},gt={sunday:0,monday:1,tuesday:2,wednesday:3,thursday:4,friday:5,saturday:6};function U(e){let t=e.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);if(!t)return null;let n=parseInt(t[1],10),o=parseInt(t[2],10),r=t[3].toUpperCase()==="PM";return r&&n!==12&&(n+=12),!r&&n===12&&(n=0),{hours:n,minutes:o}}function V(e,t){if(!e)return null;let n=e.trim();if(!n)return null;if(t=t||new Date,/^just\s*now$/i.test(n))return t.toISOString();if(/^today\b/i.test(n)||/^\d{1,2}:\d{2}\s*(AM|PM)$/i.test(n)){let l=U(n),c=new Date(t);return l?c.setHours(l.hours,l.minutes,0,0):c.setHours(0,0,0,0),c.toISOString()}let o=n.match(/^(Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)\s*(.*)/i);if(o){let l=gt[o[1].toLowerCase()],c=U(o[2]||""),a=new Date(t),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=n.match(/^([A-Z][a-z]+)\s+(\d{1,2}),?\s+(\d{4})\s*(.*)/i);if(r){let l=Z[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=n.match(/^([A-Z][a-z]+)\s+(\d{1,2}),\s*(.*)/i);if(s){let l=Z[s[1].toLowerCase().slice(0,3)];if(l===void 0)return null;let c=parseInt(s[2],10),a=U(s[3]||""),f=t.getFullYear(),u=new Date(f,l,c,a?.hours||0,a?.minutes||0,0,0);return u>t&&u.setFullYear(f-1),u.toISOString()}let i=n.match(/^([A-Z][a-z]+)\s+(\d{1,2})\s*(.*)/i);if(i){let l=Z[i[1].toLowerCase().slice(0,3)];if(l===void 0)return null;let c=parseInt(i[2],10),a=U(i[3]||""),f=t.getFullYear(),u=new Date(f,l,c,a?.hours||0,a?.minutes||0,0,0);return u>t&&u.setFullYear(f-1),u.toISOString()}return null}async function Y(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function yt(e,t,{timeout:n=45e3,poll:o=1e3,label:r="page"}={}){let s=Date.now();for(;Date.now()-s<n;){try{if(await e.evaluate(l=>!!document.querySelector(l),t)){let l=Date.now()-s;return l>6e3&&console.log(` (waited ${Math.round(l/1e3)}s for LinkedIn to finish loading ${r})`),!0}}catch{}await new Promise(i=>setTimeout(i,o))}return!1}var Ee=/\/authwall|\/login|\/checkpoint|\/uas\/login/;function St(e){return Ee.test(e||"")}async function wt(e,{credentialWaitMs:t=36e4,label:n="page"}={}){console.log(` \u26A0 Auth wall on ${n} \u2014 attempting self-recovery (cookies may just need a refresh)...`);try{await e.goto("https://www.linkedin.com/feed/",{waitUntil:"domcontentloaded",timeout:6e4})}catch{}let o=!!(process.stdin&&process.stdin.isTTY),r=o?t:Math.min(t,45e3),s=Date.now(),i=!1;for(;Date.now()-s<r;){let c="wait";try{c=await e.evaluate(a=>!new RegExp(a).test(location.href)&&document.querySelector("#global-nav, nav.global-nav")?"in":document.querySelector('input#username, input[name="session_key"], input#password')?"creds":"wait",Ee.source)}catch{}if(c==="in"){try{let a=await e.cookies();if(Array.isArray(a)&&a.some(u=>u.name==="li_at")){let u=ge(a);console.log(` \u2713 Session recovered \u2014 re-saved ${a.length} cookies (${u}).`)}else console.log(" \u2713 Session recovered (kept existing cookie snapshot \u2014 refreshed set had no li_at).")}catch(a){console.log(` \u2713 Session recovered (cookie re-save skipped: ${a.message}).`)}return!0}if(c==="creds"){if(!o){let a=new Error(`Session expired (${n}) \u2014 credentials required and no interactive terminal. Run: ilml linkedin login`);throw a.code="SESSION_EXPIRED",a}i||(i=!0,console.log(`
2
+ \u26A0 LinkedIn is asking for your login + password (cookies not enough this time).`),console.log(" \u2192 Sign in MANUALLY in the browser window that is already open."),console.log(` I will wait and resume automatically \u2014 do NOT close the window or re-run the command.
3
+ `))}await new Promise(a=>setTimeout(a,2500))}let l=new Error(`Session expired (${n}) \u2014 not signed in within the wait window. Run: ilml linkedin login`);throw l.code="SESSION_EXPIRED",l}async function $e(e,{readySelector:t,label:n="page",timeout:o=45e3}={}){let r=await yt(e,t,{timeout:o,label:n});if(!r&&St(e.url())){let s=new Error(`Session expired (${n}) \u2014 redirected to login. Run: ilml linkedin login`);throw s.code="SESSION_EXPIRED",s}return r}async function ee(e,t,{readySelector:n,label:o="page",timeout:r=45e3,gotoTimeout:s=6e4,autoRecover:i=!0}={}){await e.goto(t,{waitUntil:"domcontentloaded",timeout:s});try{return await $e(e,{readySelector:n,label:o,timeout:r})}catch(l){if(i&&l.code==="SESSION_EXPIRED"){await wt(e,{label:o});try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:s})}catch{}return await $e(e,{readySelector:n,label:o,timeout:r})}throw l}}import{getPluginConfig as bt}from"@ilivemylife/graph-sdk";var vt=await bt();for(let[e,t]of Object.entries(vt))process.env[e]===void 0&&(process.env[e]=t);var kt=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),ao=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),At=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 Ct}from"url";var $t=Ct(import.meta.url),Et=S.dirname(S.dirname($t)),R=process.env.DATA_DIR?S.resolve(process.env.DATA_DIR,"collected-profiles"):S.join(Et,"collected-profiles"),te=S.join(R,"people.json"),ho=S.join(R,"jobs.json"),go=S.join(R,"quota.json"),yo=S.join(R,"conversations.json"),So=S.join(R,"sync-state.json"),wo=S.join(R,"application-questions.json"),bo=S.join(R,"profile-history"),xe=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},vo=xe(process.env.CONNECT_MAX_DAILY,20),ko=xe(process.env.CONNECT_MAX_WEEKLY,100),M=null,xt=null,It=null,_t=null,Tt=null,Rt=null;function Ie(){M=null,xt=null,It=null,_t=null,Tt=null,Rt=null}function _e(){y.existsSync(R)||y.mkdirSync(R,{recursive:!0})}function Dt(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";y.writeFileSync(o,n);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 Ot(e,t){if(!y.existsSync(e))return null;try{let n=JSON.parse(y.readFileSync(e,"utf-8"));try{y.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.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 G(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function q(){return M||(_e(),M=Ot(te,"people.json")||{},M)}function Te(e){_e(),M=e;try{Dt(te,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${S.resolve(te)}`)}}import Ut from"puppeteer";import{addExtra as qt}from"puppeteer-extra";import Bt from"puppeteer-extra-plugin-stealth";import ne from"fs";import jt from"path";var Nt={headless:!1,defaultViewport:null,protocolTimeout:3e5},J=new Set,Re=!1;async function K(){let e=[...J].map(t=>{try{return Promise.resolve(t.close()).catch(()=>{})}catch{return Promise.resolve()}});J.clear(),await Promise.race([Promise.all(e),new Promise(t=>setTimeout(t,5e3))])}function Ft(){if(Re)return;Re=!0;let e=t=>async()=>{await K(),process.exit(t)};process.once("SIGINT",e(130)),process.once("SIGTERM",e(143)),process.once("SIGHUP",e(129)),process.once("uncaughtException",async t=>{await K(),console.error(t&&t.stack||t),process.exit(1)}),process.once("unhandledRejection",async t=>{await K(),console.error(t),process.exit(1)}),process.stdout.on("error",async t=>{t&&t.code==="EPIPE"&&(await K(),process.exit(0))}),process.on("exit",()=>{for(let t of J)try{let n=t.process&&t.process();n&&n.kill("SIGKILL")}catch{}})}function oe(e){return jt.join(e,".ilml-browser-session.json")}function Ne(e,t={}){try{ne.writeFileSync(oe(e),JSON.stringify({ownerPid:process.pid,startedAt:Date.now(),...t}))}catch{}}function Lt(e,t){try{let n=t.wsEndpoint&&t.wsEndpoint();Ne(e,n?{wsEndpoint:n}:{})}catch{}}function Pt(e){let t=Fe(e);t&&t.ownerPid===process.pid&&B(e)}function B(e){try{ne.rmSync(oe(e),{force:!0})}catch{}}function Fe(e){try{return JSON.parse(ne.readFileSync(oe(e),"utf-8"))}catch{return null}}function De(e){if(!e||e===process.pid)return!0;try{return process.kill(e,0),!0}catch(t){return!t||t.code!=="ESRCH"}}function Oe(e,t,n){let o,r=new Promise(i=>{o=setTimeout(()=>i(n),t)}),s=Promise.resolve(e).then(i=>(clearTimeout(o),i),i=>{throw clearTimeout(o),i});return Promise.race([s,r])}async function je(e,t,{probeTimeoutMs:n=4e3}={}){let o=Fe(t);if(!o)return"free";if(!o.wsEndpoint)return o.ownerPid&&o.ownerPid!==process.pid&&De(o.ownerPid)?"live":(B(t),"free");let r=Symbol("timeout"),s=e.connect({browserWSEndpoint:o.wsEndpoint,defaultViewport:null}).catch(()=>null),i=await Oe(s,n,r);if(i===r)return s.then(c=>{if(c)try{c.disconnect()}catch{}}),"live";if(!i)return B(t),"free";if(De(o.ownerPid)){try{i.disconnect()}catch{}return"live"}if(console.log(" (recovered an orphaned automation browser from a previous run \u2014 closing it)"),await Oe(i.close().then(()=>!0).catch(()=>!1),n,!1))return B(t),"free";try{i.disconnect()}catch{}return"live"}function Mt(e,t){e&&(Ft(),J.add(e),e.on("disconnected",()=>{J.delete(e),t&&B(t)}))}async function Le(e,t={}){let n=be(),o={...Nt,...t,userDataDir:n},r=`Could not open the LinkedIn automation Chrome profile at ${n}. Another LinkedIn automation command is already running (or its window is still open) \u2014 wait for it to finish or close that window, then retry.`;if(await je(e,n)==="live")throw new Error(r);Ne(n);let s;try{s=await e.launch(o)}catch{if(await je(e,n)==="live")throw new Error(r);Ce(n);try{s=await e.launch(o)}catch(l){throw Pt(n),new Error(`Could not open the LinkedIn automation Chrome profile at ${n}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${l.message})`)}}return Mt(s,n),Lt(n,s),{browser:s,profileDir:n,needsSeed:ke(n)}}async function Pe(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(...ye()),Ae(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var Me=qt(Ut);Me.use(Bt());async function Ue(){let{browser:e,profileDir:t,needsSeed:n}=await Le(Me),o=await e.newPage();return await o.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Pe(o,{profileDir:t,needsSeed:n}),console.log(" Browser launched (persistent profile)."),{browser:e,page:o}}import"dotenv/config";import*as C from"fs";import*as O from"path";import{fileURLToPath as Gt}from"url";import"dotenv/config";import{createGraphClient as Jt,resolveToken as Ht}from"@ilivemylife/graph-sdk";import{config as Wt}from"dotenv";Wt();var qe=Ht()||process.env.TOKEN;qe||(console.error(`
2
4
  [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.
3
5
  `),console.error(" Easiest way:"),console.error(" 1. npm install -g @ilivemylife/graph-sdk"),console.error(` 2. ilml login your@email.com yourpassword
4
6
  `),console.error(` Or add ILML_TOKEN=... to .env
5
- `),process.exit(1));var Me=Ut({token:Pe});function Jt(e){if(!e||e<1e3)return`${e||0}ms`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60),o=t%60;return o?`${n}m ${o}s`:`${n}m`}function Ht({scriptName:e,mode:t,status:n,error:o,duration:r}){let s=n==="error"?"\u2717":n==="quota-reached"?"\u26A0":"\u2713",i=new Date().toISOString().slice(0,16).replace("T"," "),l=r?` ${Jt(r)}`:"",c=n==="error"?`error${o?`: ${String(o).slice(0,80)}`:""}`:n==="quota-reached"?"daily quota reached":"done",a=t&&t!=="default"?` (${t})`:"";return`${s} ${e}${a} \u2014 ${c} \u2014 ${i}${l}`}async function Ue({scriptName:e,mode:t,status:n,summaryLines:o,error:r,duration:s}){let i=process.env.NODE_RUN_REPORTS;if(!i||!Array.isArray(o)||o.length===0)return;let c=`**${Ht({scriptName:e,mode:t,status:n,error:r,duration:s})}**
7
+ `),process.exit(1));var Be=Jt({token:qe});function Vt(e){if(!e||e<1e3)return`${e||0}ms`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60),o=t%60;return o?`${n}m ${o}s`:`${n}m`}function Yt({scriptName:e,mode:t,status:n,error:o,duration:r}){let s=n==="error"?"\u2717":n==="quota-reached"?"\u26A0":"\u2713",i=new Date().toISOString().slice(0,16).replace("T"," "),l=r?` ${Vt(r)}`:"",c=n==="error"?`error${o?`: ${String(o).slice(0,80)}`:""}`:n==="quota-reached"?"daily quota reached":"done",a=t&&t!=="default"?` (${t})`:"";return`${s} ${e}${a} \u2014 ${c} \u2014 ${i}${l}`}async function Je({scriptName:e,mode:t,status:n,summaryLines:o,error:r,duration:s}){let i=process.env.NODE_RUN_REPORTS;if(!i||!Array.isArray(o)||o.length===0)return;let c=`**${Yt({scriptName:e,mode:t,status:n,error:r,duration:s})}**
6
8
 
7
9
  ${o.join(`
8
- `)}`;try{await Me.addMessage(i,c)}catch(a){console.error(`[runReport] Failed to post end-of-session message: ${a.message}`)}}var Vt=Wt(import.meta.url),Gt=O.dirname(O.dirname(Vt)),oe=process.env.DATA_DIR?O.resolve(process.env.DATA_DIR,"collected-profiles"):O.join(Gt,"collected-profiles"),re=O.join(oe,"run-log.json");function Yt(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";A.writeFileSync(o,n);for(let r=0;r<3;r++)try{A.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function qe(){try{if(!A.existsSync(re))return{runs:[]};let e=JSON.parse(A.readFileSync(re,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Be(e){A.existsSync(oe)||A.mkdirSync(oe,{recursive:!0});try{Yt(re,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function Je(e,t="default"){let n=qe();for(let i of n.runs)i.status==="running"&&(i.status="interrupted",i.result="interrupted",i.timestamp&&(i.duration=Date.now()-new Date(i.timestamp).getTime()));let o=new Date,r={timestamp:o.toISOString(),script:e,mode:t,status:"running",result:null,duration:null,stats:null,error:null};n.runs.push(r);let s=Date.now()-30*24*60*60*1e3;return n.runs=n.runs.filter(i=>new Date(i.timestamp).getTime()>s),Be(n),{script:e,mode:t,startTime:o.getTime(),runIndex:n.runs.length-1}}function se(e,t,n=null,o=null){if(!e)return;let r=null;try{let i=qe(),l=i.runs[e.runIndex];if(l&&l.status==="running"&&l.script===e.script)l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=n,l.error=o,r=l.duration;else{let c=i.runs.find(a=>a.script===e.script&&a.status==="running"&&a.timestamp===new Date(e.startTime).toISOString());c&&(c.status=t,c.result=t,c.duration=Date.now()-e.startTime,c.stats=n,c.error=o,r=c.duration)}Be(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let s=n&&Array.isArray(n.summaryLines)?n.summaryLines:null;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS){let i=t==="error"?"error":n&&n.dailyLimitHit?"quota-reached":"done";Ue({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 de from"os";import*as h from"path";import{fileURLToPath as xn}from"url";var le={};W(le,{NAME:()=>zt,VERSION:()=>Kt,up:()=>Zt});import*as C from"fs";import*as z from"path";var Kt=1,zt="normalize-jobs-and-questions",Qt=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],Xt=50;function ie(e){return C.existsSync(e)?JSON.parse(C.readFileSync(e,"utf-8")):null}function ce(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{C.writeFileSync(o,n)}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 Zt(e,t){let n=z.join(e,"jobs.json"),o=z.join(t,"scouted-jobs.json"),r=z.join(e,"application-questions.json"),s=ie(n)||{},i=ie(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 Qt)u[g]!=null&&m[g]==null&&(m[g]=u[g]);c.push(f),l++}l>0?(ce(n,s),console.log(` Phase 1: Merged ${l} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let a=ie(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<=Xt?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})}ce(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];ce(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 ae={};W(ae,{NAME:()=>tn,VERSION:()=>en,up:()=>rn});import*as $ from"fs";import*as He from"path";var en=2,tn="reset-unread-flags";function nn(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function on(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{$.writeFileSync(o,n)}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 rn(e){let t=He.join(e,"conversations.json"),n=nn(t);if(!n){console.log(" conversations.json not found \u2014 nothing to reset.");return}let o=0;for(let r of Object.keys(n))n[r].unread===!0&&(n[r].unread=!1,o++);if(o===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}on(t,n),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var ue={};W(ue,{NAME:()=>cn,VERSION:()=>sn,up:()=>pn});import*as E from"fs";import*as We from"path";var sn=3,cn="recompute-last-message-by",ln=new Set(["draft","confirmed","rejected","needs_review"]);function an(e){return E.existsSync(e)?JSON.parse(E.readFileSync(e,"utf-8")):null}function un(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{E.writeFileSync(o,n)}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 fn(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!ln.has(s.status));if(n.length===0)return"them";let o=n.map(s=>({m:s,t:Date.parse(s.time)})).filter(s=>Number.isFinite(s.t)).sort((s,i)=>i.t-s.t).map(s=>s.m),r=o.length>0?o:[...n].reverse();for(let s of r){let i=s.sender;if(i===t)return"me";if(i!=="Unknown"&&i!=="")return"them"}return"them"}async function pn(e){let t=We.join(e,"conversations.json"),n=an(t);if(!n){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let o=process.env.LINKEDIN_NAME;if(!o||typeof o!="string"||!o.trim())throw new Error(`LINKEDIN_NAME env var is not set. Migration v003 needs your display name to determine which messages are yours vs theirs. Set LINKEDIN_NAME in your .env (or run "ilml plugin config linkedin set LINKEDIN_NAME 'Your Name'") and retry.`);let r=0,s=0,i=0;for(let l of Object.keys(n)){let c=n[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=fn(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}un(t,n),console.log(` Recomputed lastMessageBy + conversationStatus on ${r} conversations.`),console.log(` ${i} had stale lastMessageBy (now corrected).`),s>0&&console.log(` Cleaned ${s} leftover _cardSynced flags.`),console.log(" Re-run 'ilml linkedin enrich' if you want actionNeeded / summary / autoTags to also update.")}var fe={};W(fe,{NAME:()=>mn,VERSION:()=>dn,up:()=>Sn});import*as x from"fs";import*as Ve from"path";var dn=4,mn="split-connection-timestamps",hn=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function gn(e){if(!x.existsSync(e))return null;let t=x.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function yn(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{x.writeFileSync(o,n)}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 Sn(e){let t=Ve.join(e,"people.json"),n=gn(t);if(!n||typeof n!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let o=0,r=0;for(let s of Object.keys(n)){let i=n[s];!i||typeof i!="object"||(r++,hn.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}yn(t,n),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${o} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}import"dotenv/config";import*as k from"path";import{fileURLToPath as wn}from"url";var bn=wn(import.meta.url),vn=k.dirname(k.dirname(bn)),H=process.env.DATA_DIR?k.resolve(process.env.DATA_DIR,"market-research"):k.join(vn,"market-research"),Qo=k.join(H,"scouted-jobs.json"),Xo=k.join(H,"discovered-people.json"),Zo=k.join(H,"visit-log.json"),er=k.join(H,"companies.json"),tr=k.join(H,"job-decisions.json");function Ge(){kn=null,An=null,Cn=null,$n=null,En=null}var kn=null;var An=null;var Cn=null;var $n=null;var En=null;var In=xn(import.meta.url),Tn=h.dirname(In),_n=h.dirname(h.dirname(Tn));function Rn(e){return e&&(e==="~"?de.homedir():e.startsWith("~/")||e.startsWith("~\\")?h.join(de.homedir(),e.slice(2)):e)}var T=process.env.DATA_DIR?h.resolve(Rn(process.env.DATA_DIR)):_n,L=h.join(T,"collected-profiles"),P=h.join(T,"market-research"),b=h.join(T,".schema-version"),Ye=[h.join(L,".schema-version"),h.join(P,".schema-version")],j=4,R=[{version:1,module:le},{version:2,module:ae},{version:3,module:ue},{version:4,module:fe}];(function(){R.sort((o,r)=>o.version-r.version);let t=new Set;for(let o of R){if(!Number.isInteger(o.version)||o.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(o.version)} (must be positive integer)`);if(t.has(o.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${o.version}`);t.add(o.version);let r=o.module;if(!r||typeof r.up!="function")throw new Error(`MIGRATION_REGISTRY: v${o.version} module is missing up()`);if(r.VERSION!==void 0&&r.VERSION!==o.version)throw new Error(`MIGRATION_REGISTRY: v${o.version} entry does not match module VERSION (${r.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let n=R.length?R[R.length-1].version:0;if(n!==j)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${j}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<R.length;o++){let r=o+1;if(R[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${R[o].version}`)}})();function Xe(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
10
+ `)}`;try{await Be.addMessage(i,c)}catch(a){console.error(`[runReport] Failed to post end-of-session message: ${a.message}`)}}var Kt=Gt(import.meta.url),zt=O.dirname(O.dirname(Kt)),re=process.env.DATA_DIR?O.resolve(process.env.DATA_DIR,"collected-profiles"):O.join(zt,"collected-profiles"),se=O.join(re,"run-log.json");function Qt(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";C.writeFileSync(o,n);for(let r=0;r<3;r++)try{C.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function He(){try{if(!C.existsSync(se))return{runs:[]};let e=JSON.parse(C.readFileSync(se,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function We(e){C.existsSync(re)||C.mkdirSync(re,{recursive:!0});try{Qt(se,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function Ve(e,t="default"){let n=He();for(let i of n.runs)i.status==="running"&&(i.status="interrupted",i.result="interrupted",i.timestamp&&(i.duration=Date.now()-new Date(i.timestamp).getTime()));let o=new Date,r={timestamp:o.toISOString(),script:e,mode:t,status:"running",result:null,duration:null,stats:null,error:null};n.runs.push(r);let s=Date.now()-30*24*60*60*1e3;return n.runs=n.runs.filter(i=>new Date(i.timestamp).getTime()>s),We(n),{script:e,mode:t,startTime:o.getTime(),runIndex:n.runs.length-1}}function ie(e,t,n=null,o=null){if(!e)return;let r=null;try{let i=He(),l=i.runs[e.runIndex];if(l&&l.status==="running"&&l.script===e.script)l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=n,l.error=o,r=l.duration;else{let c=i.runs.find(a=>a.script===e.script&&a.status==="running"&&a.timestamp===new Date(e.startTime).toISOString());c&&(c.status=t,c.result=t,c.duration=Date.now()-e.startTime,c.stats=n,c.error=o,r=c.duration)}We(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let s=n&&Array.isArray(n.summaryLines)?n.summaryLines:null;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS){let i=t==="error"?"error":n&&n.dailyLimitHit?"quota-reached":"done";Je({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 me from"os";import*as h from"path";import{fileURLToPath as Tn}from"url";var ae={};W(ae,{NAME:()=>Zt,VERSION:()=>Xt,up:()=>nn});import*as $ from"fs";import*as z from"path";var Xt=1,Zt="normalize-jobs-and-questions",en=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],tn=50;function ce(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function le(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{$.writeFileSync(o,n)}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 nn(e,t){let n=z.join(e,"jobs.json"),o=z.join(t,"scouted-jobs.json"),r=z.join(e,"application-questions.json"),s=ce(n)||{},i=ce(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 en)u[g]!=null&&m[g]==null&&(m[g]=u[g]);c.push(f),l++}l>0?(le(n,s),console.log(` Phase 1: Merged ${l} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let a=ce(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 k=(m.questions||[]).map(d=>{let w={type:d.type||"input",question:d.question||"",answer:d.answer||""};return d.options&&(d.options.length<=tn?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||k.length,questions:k})}le(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];le(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 ue={};W(ue,{NAME:()=>rn,VERSION:()=>on,up:()=>ln});import*as E from"fs";import*as Ye from"path";var on=2,rn="reset-unread-flags";function sn(e){return E.existsSync(e)?JSON.parse(E.readFileSync(e,"utf-8")):null}function cn(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{E.writeFileSync(o,n)}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}}async function ln(e){let t=Ye.join(e,"conversations.json"),n=sn(t);if(!n){console.log(" conversations.json not found \u2014 nothing to reset.");return}let o=0;for(let r of Object.keys(n))n[r].unread===!0&&(n[r].unread=!1,o++);if(o===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}cn(t,n),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var fe={};W(fe,{NAME:()=>un,VERSION:()=>an,up:()=>hn});import*as x from"fs";import*as Ge from"path";var an=3,un="recompute-last-message-by",fn=new Set(["draft","confirmed","rejected","needs_review"]);function pn(e){return x.existsSync(e)?JSON.parse(x.readFileSync(e,"utf-8")):null}function dn(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{x.writeFileSync(o,n)}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}}function mn(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!fn.has(s.status));if(n.length===0)return"them";let o=n.map(s=>({m:s,t:Date.parse(s.time)})).filter(s=>Number.isFinite(s.t)).sort((s,i)=>i.t-s.t).map(s=>s.m),r=o.length>0?o:[...n].reverse();for(let s of r){let i=s.sender;if(i===t)return"me";if(i!=="Unknown"&&i!=="")return"them"}return"them"}async function hn(e){let t=Ge.join(e,"conversations.json"),n=pn(t);if(!n){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let o=process.env.LINKEDIN_NAME;if(!o||typeof o!="string"||!o.trim())throw new Error(`LINKEDIN_NAME env var is not set. Migration v003 needs your display name to determine which messages are yours vs theirs. Set LINKEDIN_NAME in your .env (or run "ilml plugin config linkedin set LINKEDIN_NAME 'Your Name'") and retry.`);let r=0,s=0,i=0;for(let l of Object.keys(n)){let c=n[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=mn(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}dn(t,n),console.log(` Recomputed lastMessageBy + conversationStatus on ${r} conversations.`),console.log(` ${i} had stale lastMessageBy (now corrected).`),s>0&&console.log(` Cleaned ${s} leftover _cardSynced flags.`),console.log(" Re-run 'ilml linkedin enrich' if you want actionNeeded / summary / autoTags to also update.")}var pe={};W(pe,{NAME:()=>yn,VERSION:()=>gn,up:()=>vn});import*as I from"fs";import*as Ke from"path";var gn=4,yn="split-connection-timestamps",Sn=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function wn(e){if(!I.existsSync(e))return null;let t=I.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function bn(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";try{I.writeFileSync(o,n)}catch(r){try{I.unlinkSync(o)}catch{}throw r}try{I.renameSync(o,e)}catch(r){try{I.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 vn(e){let t=Ke.join(e,"people.json"),n=wn(t);if(!n||typeof n!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let o=0,r=0;for(let s of Object.keys(n)){let i=n[s];!i||typeof i!="object"||(r++,Sn.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}bn(t,n),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${o} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}import"dotenv/config";import*as A from"path";import{fileURLToPath as kn}from"url";var An=kn(import.meta.url),Cn=A.dirname(A.dirname(An)),H=process.env.DATA_DIR?A.resolve(process.env.DATA_DIR,"market-research"):A.join(Cn,"market-research"),tr=A.join(H,"scouted-jobs.json"),nr=A.join(H,"discovered-people.json"),or=A.join(H,"visit-log.json"),rr=A.join(H,"companies.json"),sr=A.join(H,"job-decisions.json");function ze(){$n=null,En=null,xn=null,In=null,_n=null}var $n=null;var En=null;var xn=null;var In=null;var _n=null;var Rn=Tn(import.meta.url),Dn=h.dirname(Rn),On=h.dirname(h.dirname(Dn));function jn(e){return e&&(e==="~"?me.homedir():e.startsWith("~/")||e.startsWith("~\\")?h.join(me.homedir(),e.slice(2)):e)}var _=process.env.DATA_DIR?h.resolve(jn(process.env.DATA_DIR)):On,L=h.join(_,"collected-profiles"),P=h.join(_,"market-research"),v=h.join(_,".schema-version"),Qe=[h.join(L,".schema-version"),h.join(P,".schema-version")],j=4,D=[{version:1,module:ae},{version:2,module:ue},{version:3,module:fe},{version:4,module:pe}];(function(){D.sort((o,r)=>o.version-r.version);let t=new Set;for(let o of D){if(!Number.isInteger(o.version)||o.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(o.version)} (must be positive integer)`);if(t.has(o.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${o.version}`);t.add(o.version);let r=o.module;if(!r||typeof r.up!="function")throw new Error(`MIGRATION_REGISTRY: v${o.version} module is missing up()`);if(r.VERSION!==void 0&&r.VERSION!==o.version)throw new Error(`MIGRATION_REGISTRY: v${o.version} entry does not match module VERSION (${r.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let n=D.length?D[D.length-1].version:0;if(n!==j)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${j}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<D.length;o++){let r=o+1;if(D[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${D[o].version}`)}})();function tt(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
9
11
  [FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
10
- `),process.exit(1));try{p.mkdirSync(T,{recursive:!0})}catch(t){t.code!=="EEXIST"&&(console.error(`
11
- [FATAL] Cannot create DATA_DIR (${T}): ${t.message}`),console.error(` Fix the path or permissions and try again.
12
- `),process.exit(1))}let e;try{e=p.statSync(T)}catch(t){console.error(`
13
- [FATAL] DATA_DIR (${T}) is not accessible: ${t.message}
12
+ `),process.exit(1));try{p.mkdirSync(_,{recursive:!0})}catch(t){t.code!=="EEXIST"&&(console.error(`
13
+ [FATAL] Cannot create DATA_DIR (${_}): ${t.message}`),console.error(` Fix the path or permissions and try again.
14
+ `),process.exit(1))}let e;try{e=p.statSync(_)}catch(t){console.error(`
15
+ [FATAL] DATA_DIR (${_}) is not accessible: ${t.message}
14
16
  `),process.exit(1)}e.isDirectory()||(console.error(`
15
- [FATAL] DATA_DIR (${T}) 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
+ [FATAL] DATA_DIR (${_}) 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.
16
18
  `),process.exit(1));for(let t of[L,P]){let n;try{n=p.lstatSync(t)}catch(o){if(o.code==="ENOENT")continue;throw o}n.isSymbolicLink()&&(console.error(`
17
19
  [FATAL] Data subdirectory is a symbolic link: ${t}`),console.error(" Refusing to follow \u2014 backup code would copy whatever the link points at."),console.error(` If this is intentional, replace the symlink with the real directory.
18
- `),process.exit(1))}}var F=h.join(T,".migration-lock");function Dn(){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 t;try{t=JSON.parse(p.readFileSync(F,"utf-8"))}catch{t=null}if(t&&Number.isInteger(t.pid)){let o=!1;try{process.kill(t.pid,0),o=!0}catch(i){i.code==="EPERM"&&(o=!0)}let r=24*60*60*1e3,s=1/0;if(t.startedAt){let i=Date.parse(t.startedAt);Number.isNaN(i)||(s=Date.now()-i)}o&&s<r&&(console.error(`
20
+ `),process.exit(1))}}var F=h.join(_,".migration-lock");function Nn(){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 t;try{t=JSON.parse(p.readFileSync(F,"utf-8"))}catch{t=null}if(t&&Number.isInteger(t.pid)){let o=!1;try{process.kill(t.pid,0),o=!0}catch(i){i.code==="EPERM"&&(o=!0)}let r=24*60*60*1e3,s=1/0;if(t.startedAt){let i=Date.parse(t.startedAt);Number.isNaN(i)||(s=Date.now()-i)}o&&s<r&&(console.error(`
19
21
  [FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${t.pid}`),console.error(` Started at: ${t.startedAt||"(unknown)"}`),console.error(` Lock file: ${F}
20
22
  `),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.
21
- `),process.exit(1)),o&&s>=r&&console.log(` Lock holder PID ${t.pid} is alive but lock is older than 24h \u2014 assuming PID reuse, taking over.`)}console.log(` Stale migration lock from PID ${t?.pid??"?"} found \u2014 taking over.`);let n=F+".tmp";try{return p.writeFileSync(n,e),p.renameSync(n,F),!0}catch(o){try{p.unlinkSync(n)}catch{}throw new Error(`Failed to take over stale migration lock: ${o.message}`)}}function me(){try{if(JSON.parse(p.readFileSync(F,"utf-8")).pid!==process.pid)return;p.unlinkSync(F)}catch{}}var Ke=!1;function On(){if(Ke)return;Ke=!0;let e=()=>{try{me()}catch{}process.exit(1)};for(let t of["SIGINT","SIGTERM","SIGHUP"])try{process.on(t,e)}catch{}}function jn(){if(p.existsSync(b))return;let e=[],t=[];for(let s of Ye)if(p.existsSync(s))try{e.push({file:s,schema:Q(s)})}catch(i){t.push({file:s,err:i.message})}if(t.length>0){console.error(`
23
+ `),process.exit(1)),o&&s>=r&&console.log(` Lock holder PID ${t.pid} is alive but lock is older than 24h \u2014 assuming PID reuse, taking over.`)}console.log(` Stale migration lock from PID ${t?.pid??"?"} found \u2014 taking over.`);let n=F+".tmp";try{return p.writeFileSync(n,e),p.renameSync(n,F),!0}catch(o){try{p.unlinkSync(n)}catch{}throw new Error(`Failed to take over stale migration lock: ${o.message}`)}}function he(){try{if(JSON.parse(p.readFileSync(F,"utf-8")).pid!==process.pid)return;p.unlinkSync(F)}catch{}}var Xe=!1;function Fn(){if(Xe)return;Xe=!0;let e=()=>{try{he()}catch{}process.exit(1)};for(let t of["SIGINT","SIGTERM","SIGHUP"])try{process.on(t,e)}catch{}}function Ln(){if(p.existsSync(v))return;let e=[],t=[];for(let s of Qe)if(p.existsSync(s))try{e.push({file:s,schema:Q(s)})}catch(i){t.push({file:s,err:i.message})}if(t.length>0){console.error(`
22
24
  [FATAL] Legacy .schema-version file(s) corrupted \u2014 cannot determine current schema version:`);for(let s of t)console.error(` ${s.file}: ${s.err}`);console.error(`
23
25
  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.
24
26
  `),process.exit(1)}if(e.length===0)return;let n=e.map(s=>s.schema.version);if(new Set(n).size>1){console.error(`
25
27
  [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.
26
- `),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 Ye)if(p.existsSync(s))try{p.unlinkSync(s)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${b}`)}function Nn(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let t=Number(e.version);return!Number.isFinite(t)||t<0||!Number.isInteger(t)?null:(e.version=t,Array.isArray(e.migrations)||(e.migrations=[]),e)}function Q(e){let t=p.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function ze(){if(jn(),!p.existsSync(b))return{version:0,migrations:[]};let e;try{e=Q(b)}catch(n){if(n.code==="ENOENT")return{version:0,migrations:[]};console.error(`
27
- [FATAL] ${b} is not valid JSON: ${n.message}`),console.error(" Refusing to proceed \u2014 silently treating it as 'fresh install' would re-apply"),console.error(" every migration on top of already-migrated data and corrupt it."),console.error(' Repair the file (set it to {"version":N,"migrations":[...]} matching your real state)'),console.error(` or restore from the *.pre-vNNN.backup files if you have them.
28
- `),process.exit(1)}let t=Nn(e);return t===null&&(console.error(`
29
- [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.
30
- `),process.exit(1)),t}function Ze(e){try{p.chmodSync(e,384)}catch{}}function Fn(e){if(Xe(),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(n){if(n.message?.includes("symbolic link"))throw n}let t=b+".tmp";try{p.writeFileSync(t,JSON.stringify(e,null,2)),Ze(t),p.renameSync(t,b)}catch(n){try{p.unlinkSync(t)}catch{}throw n}}function Qe(e,t){if(!p.existsSync(e))return;let n=`.pre-v${String(t).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+n);if(p.existsSync(a)){s++;continue}try{tt(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)}/ (${n})${l}`)}}var pe=!1;async function et(){if(pe)return;Xe(),qn();let t=ze().version;if(t===j){pe=!0;return}On(),Dn(),process.on("exit",me),t>j&&(console.error(`
28
+ `),process.exit(1)}let o=e[0].schema,r=v+".tmp";try{p.writeFileSync(r,JSON.stringify(o,null,2)),p.renameSync(r,v)}catch(s){try{p.unlinkSync(r)}catch{}throw s}for(let s of Qe)if(p.existsSync(s))try{p.unlinkSync(s)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${v}`)}function Pn(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let t=Number(e.version);return!Number.isFinite(t)||t<0||!Number.isInteger(t)?null:(e.version=t,Array.isArray(e.migrations)||(e.migrations=[]),e)}function Q(e){let t=p.readFileSync(e,"utf-8");return t.charCodeAt(0)===65279&&(t=t.slice(1)),JSON.parse(t)}function Ze(){if(Ln(),!p.existsSync(v))return{version:0,migrations:[]};let e;try{e=Q(v)}catch(n){if(n.code==="ENOENT")return{version:0,migrations:[]};console.error(`
29
+ [FATAL] ${v} is not valid JSON: ${n.message}`),console.error(" Refusing to proceed \u2014 silently treating it as 'fresh install' would re-apply"),console.error(" every migration on top of already-migrated data and corrupt it."),console.error(' Repair the file (set it to {"version":N,"migrations":[...]} matching your real state)'),console.error(` or restore from the *.pre-vNNN.backup files if you have them.
30
+ `),process.exit(1)}let t=Pn(e);return t===null&&(console.error(`
31
+ [FATAL] ${v} 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.
32
+ `),process.exit(1)),t}function nt(e){try{p.chmodSync(e,384)}catch{}}function Mn(e){if(tt(),p.existsSync(v))try{if(p.lstatSync(v).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${v}. Refusing to write through it (potential symlink attack). Remove the link and re-run.`)}catch(n){if(n.message?.includes("symbolic link"))throw n}let t=v+".tmp";try{p.writeFileSync(t,JSON.stringify(e,null,2)),nt(t),p.renameSync(t,v)}catch(n){try{p.unlinkSync(t)}catch{}throw n}}function et(e,t){if(!p.existsSync(e))return;let n=`.pre-v${String(t).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+n);if(p.existsSync(a)){s++;continue}try{rt(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)}/ (${n})${l}`)}}var de=!1;async function ot(){if(de)return;tt(),Hn();let t=Ze().version;if(t===j){de=!0;return}Fn(),Nn(),process.on("exit",he),t>j&&(console.error(`
31
33
  [FATAL] Your data schema is at v${t}, 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.
32
34
  `),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}.
33
35
  `),process.exit(1)),console.log(`
34
- \u{1F4E6} Schema migration: v${t} \u2192 v${j}`);let n=Bn();if(!n.ok){console.error(`
36
+ \u{1F4E6} Schema migration: v${t} \u2192 v${j}`);let n=Wn();if(!n.ok){console.error(`
35
37
  [FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let r of n.broken)console.error(` ${r.dir}/${r.file}: ${r.err}`);console.error(`
36
38
  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'.
37
- `),process.exit(1)}let o=R.filter(r=>r.version>t);for(let r of o){console.log(`
38
- Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,i=`.pre-${s}.backup`;try{Qe(L,r.version),Qe(P,r.version)}catch(c){console.error(`
39
+ `),process.exit(1)}let o=D.filter(r=>r.version>t);for(let r of o){console.log(`
40
+ Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,i=`.pre-${s}.backup`;try{et(L,r.version),et(P,r.version)}catch(c){console.error(`
39
41
  [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.
40
42
  `),process.exit(1)}let l=r.module;try{await l.up(L,P)}catch(c){console.error(`
41
- [FATAL] Migration ${s} failed: ${c.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let a=Jn(i);a.ok?(console.error(` \u2713 Auto-rollback restored ${a.restored} files. Schema stays at v${t}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
43
+ [FATAL] Migration ${s} failed: ${c.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let a=Vn(i);a.ok?(console.error(` \u2713 Auto-rollback restored ${a.restored} files. Schema stays at v${t}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
42
44
  `)):(console.error(` [!] Auto-rollback INCOMPLETE: ${a.error}`),console.error(` Manual recovery: copy *${i} files back over the originals.
43
45
  `))}catch(a){console.error(` [!] Auto-rollback CRASHED while restoring: ${a.message}`),console.error(` Manual recovery: copy *${i} files back over the originals.
44
- `)}process.exit(1)}try{let c=new Date().toISOString(),a={version:r.version,name:l.NAME||s,appliedAt:c},f=ze();f.version=r.version,f.migratedAt=c,f.migrations=f.migrations||[],f.migrations.push(a),Fn(f)}catch(c){console.error(`
46
+ `)}process.exit(1)}try{let c=new Date().toISOString(),a={version:r.version,name:l.NAME||s,appliedAt:c},f=Ze();f.version=r.version,f.migratedAt=c,f.migrations=f.migrations||[],f.migrations.push(a),Mn(f)}catch(c){console.error(`
45
47
  [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${t}.`),console.error(` On next plugin command the runner will try to re-apply ${s}. If that migration is`),console.error(` idempotent (most are), it will succeed harmlessly. If you're unsure, run 'data-cleanup' and contact support.
46
- `),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{ge()}catch{}try{Ge()}catch{}pe=!0,me(),console.log(`
48
+ `),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{Ie()}catch{}try{ze()}catch{}de=!0,he(),console.log(`
47
49
  \u2713 Schema is now at v${j}
48
- `)}var Ln=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Pn(e){let t=e.toLowerCase();return Ln.some(n=>n.test(t))}var Mn=6e4;function Un(){let e=Date.now(),t=[];for(let n of[T,L,P]){if(!p.existsSync(n))continue;let o;try{o=p.readdirSync(n)}catch{continue}for(let r of o){if(!Pn(r))continue;let s=h.join(n,r);try{let i=p.statSync(s);if(!i.isFile()||e-i.mtimeMs<Mn)continue;t.push({dir:n,file:r,fullPath:s})}catch{}}}return t}function qn({verbose:e=!1}={}){let t=Un();if(t.length===0)return e&&console.log(" No orphan .tmp files found."),0;let n=0;for(let o of t)try{p.unlinkSync(o.fullPath),n++,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&&n>0&&console.log(` Cleaned up ${n} orphan .tmp file(s) from previous run.`),n}function Bn(){let e=[];for(let t of[L,P]){if(!p.existsSync(t))continue;let n=p.readdirSync(t).filter(o=>{let r=o.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let o of n){let r=h.join(t,o);try{Q(r)}catch(s){e.push({dir:h.basename(t),file:o,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function Jn(e){let t=[],n=[];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")?Q(c):p.accessSync(c,p.constants.R_OK),t.push({backupPath:c,originalPath:f,fileName:l,dir:s})}catch(u){n.push(`${h.basename(s)}/${l}: ${u.message}`)}}}if(n.length>0)return{ok:!1,error:n.join("; "),restored:0};let o=0,r=[];for(let{backupPath:s,originalPath:i,fileName:l,dir:c}of t)try{tt(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 tt(e,t){let n=t+".tmp";try{p.copyFileSync(e,n),Ze(n)}catch(o){try{p.unlinkSync(n)}catch{}throw o}try{p.renameSync(n,t)}catch(o){try{p.unlinkSync(n)}catch{}if(o.code==="EPERM"||o.code==="EBUSY"){let r=new Error(`File locked: ${t} (${o.code}). On Windows this is usually antivirus / Search Indexer / the file open in another app. Close anything that might be holding it and re-run.`);throw r.code=o.code,r}throw o}}function Wn(){let e={list:!1,full:!1,max:1/0,dryRun:!1,verbose:!1};for(let t of process.argv.slice(2))t==="--list"?e.list=!0:t==="--full"?e.full=!0:t==="--dry-run"?e.dryRun=!0:t==="--verbose"?e.verbose=!0:t.startsWith("--max=")&&(e.max=parseInt(t.split("=")[1],10));return e}function Vn(){let e=q(),t=Object.values(e),n=t.length,o={};for(let s of t){let i=s.connectionStatus||"(none)";o[i]=(o[i]||0)+1}let r={};for(let s of t){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
+ `)}var Un=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function qn(e){let t=e.toLowerCase();return Un.some(n=>n.test(t))}var Bn=6e4;function Jn(){let e=Date.now(),t=[];for(let n of[_,L,P]){if(!p.existsSync(n))continue;let o;try{o=p.readdirSync(n)}catch{continue}for(let r of o){if(!qn(r))continue;let s=h.join(n,r);try{let i=p.statSync(s);if(!i.isFile()||e-i.mtimeMs<Bn)continue;t.push({dir:n,file:r,fullPath:s})}catch{}}}return t}function Hn({verbose:e=!1}={}){let t=Jn();if(t.length===0)return e&&console.log(" No orphan .tmp files found."),0;let n=0;for(let o of t)try{p.unlinkSync(o.fullPath),n++,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&&n>0&&console.log(` Cleaned up ${n} orphan .tmp file(s) from previous run.`),n}function Wn(){let e=[];for(let t of[L,P]){if(!p.existsSync(t))continue;let n=p.readdirSync(t).filter(o=>{let r=o.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let o of n){let r=h.join(t,o);try{Q(r)}catch(s){e.push({dir:h.basename(t),file:o,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function Vn(e){let t=[],n=[];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")?Q(c):p.accessSync(c,p.constants.R_OK),t.push({backupPath:c,originalPath:f,fileName:l,dir:s})}catch(u){n.push(`${h.basename(s)}/${l}: ${u.message}`)}}}if(n.length>0)return{ok:!1,error:n.join("; "),restored:0};let o=0,r=[];for(let{backupPath:s,originalPath:i,fileName:l,dir:c}of t)try{rt(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 rt(e,t){let n=t+".tmp";try{p.copyFileSync(e,n),nt(n)}catch(o){try{p.unlinkSync(n)}catch{}throw o}try{p.renameSync(n,t)}catch(o){try{p.unlinkSync(n)}catch{}if(o.code==="EPERM"||o.code==="EBUSY"){let r=new Error(`File locked: ${t} (${o.code}). On Windows this is usually antivirus / Search Indexer / the file open in another app. Close anything that might be holding it and re-run.`);throw r.code=o.code,r}throw o}}function Gn(){let e={list:!1,full:!1,max:1/0,dryRun:!1,verbose:!1};for(let t of process.argv.slice(2))t==="--list"?e.list=!0:t==="--full"?e.full=!0:t==="--dry-run"?e.dryRun=!0:t==="--verbose"?e.verbose=!0:t.startsWith("--max=")&&(e.max=parseInt(t.split("=")[1],10));return e}function Kn(){let e=q(),t=Object.values(e),n=t.length,o={};for(let s of t){let i=s.connectionStatus||"(none)";o[i]=(o[i]||0)+1}let r={};for(let s of t){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(`
49
51
  === People Database: ${n} entries ===
50
52
  `),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(`
51
- 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 Gn(e){let t="https://www.linkedin.com/mynetwork/invite-connect/connections/";console.log(`Navigating to ${t}`),await Z(e,t,{readySelector:'main a[href*="/in/"]',label:"connections"})||console.warn("\u26A0 No connection cards found after 45s. 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 ot(e){return e.evaluate(()=>{let n=(document.querySelector("main")||document.body).querySelectorAll('a[href*="/in/"]'),o={};for(let i of n){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
+ 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 zn(e){let t="https://www.linkedin.com/mynetwork/invite-connect/connections/";console.log(`Navigating to ${t}`),await ee(e,t,{readySelector:'main a[href*="/in/"]',label:"connections"})||console.warn("\u26A0 No connection cards found after 45s. 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 it(e){return e.evaluate(()=>{let n=(document.querySelector("main")||document.body).querySelectorAll('a[href*="/in/"]'),o={};for(let i of n){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(`
52
54
  `)[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(`
53
- `).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 rt(e){return e.evaluate(()=>{let t=document.querySelector("main")||document.body,n=null,o=[t,...t.querySelectorAll("div, section")];for(let s of o){let i=getComputedStyle(s);if((i.overflowY==="auto"||i.overflowY==="scroll")&&s.scrollHeight>s.clientHeight+10){n=s;break}}n&&n.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 n?"scrolled":"window-scroll"})}async function Yn(e,t){let{max:n,verbose:o,dryRun:r}=t,s=new Map,i=0,l=0,c=3,a=10;for(;;){i++;let f=await ot(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&&(ct(Array.from(s.values()),!1),o&&console.log(` \u{1F4BE} Saved progress (${s.size} connections)`)),s.size>=n){console.log(`
55
+ `).map(d=>d.trim()).filter(Boolean),m=null,g=null,k=u.indexOf(a);if(k>=0&&k+1<u.length){let d=u[k+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 ct(e){return e.evaluate(()=>{let t=document.querySelector("main")||document.body,n=null,o=[t,...t.querySelectorAll("div, section")];for(let s of o){let i=getComputedStyle(s);if((i.overflowY==="auto"||i.overflowY==="scroll")&&s.scrollHeight>s.clientHeight+10){n=s;break}}n&&n.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 n?"scrolled":"window-scroll"})}async function Qn(e,t){let{max:n,verbose:o,dryRun:r}=t,s=new Map,i=0,l=0,c=3,a=10;for(;;){i++;let f=await it(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&&(ut(Array.from(s.values()),!1),o&&console.log(` \u{1F4BE} Saved progress (${s.size} connections)`)),s.size>=n){console.log(`
54
56
  Reached --max=${n}, stopping.`);break}if(u===0){if(l++,l>=c){console.log(`
55
- ${c} rounds with no new cards \u2014 end of list.`);break}}else l=0;let m=await rt(e);o&&m==="clicked"&&console.log(' \u2192 Clicked "Load more"'),await G(2e3)}return o||process.stdout.write(`
56
- `),Array.from(s.values())}async function Kn(e,t){let{max:n,verbose:o}=t,r=q(),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 ot(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>=n){console.log(`
57
+ ${c} rounds with no new cards \u2014 end of list.`);break}}else l=0;let m=await ct(e);o&&m==="clicked"&&console.log(' \u2192 Clicked "Load more"'),await Y(2e3)}return o||process.stdout.write(`
58
+ `),Array.from(s.values())}async function Xn(e,t){let{max:n,verbose:o}=t,r=q(),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 it(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>=n){console.log(`
57
59
  Reached --max=${n}, stopping.`);break}if(u===0&&m>0){if(c++,c>=a){console.log(`
58
60
  ${a} consecutive pages of known connections \u2014 caught up.`);break}}else if(u>0)c=0;else if(c++,c>=a){console.log(`
59
- ${a} empty rounds \u2014 end of list.`);break}let v=await rt(e);o&&v==="clicked"&&console.log(' \u2192 Clicked "Load more"'),await G(2e3)}return o||process.stdout.write(`
60
- `),Array.from(i.values())}var st=new Set(["pending","sent_with_note","sent_without_note","sent_without_note_upsell"]);function nt(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function it(e){let t=new Map;for(let[n,o]of Object.entries(e)){let r=Y(o.profileUrl||n);r&&!t.has(r)&&t.set(r,n)}for(let[n,o]of Object.entries(e))for(let r of o.aliases||[])r&&!t.has(r)&&t.set(r,n);return t}function zn(e,t){let n=[],o=it(t);for(let r of e){if(!r.profileUrl)continue;let s=o.get(Y(r.profileUrl)),i=s?t[s]:void 0;i&&st.has(i.connectionStatus)&&n.push({...r,previousStatus:i.connectionStatus})}return n}function ct(e,t){let n=q(),o=new Date().toISOString(),r=o.slice(0,10),s={newPeople:0,updatedToConnected:0,alreadyConnected:0,flaggedDuplicates:0,flagged:[]},i=it(n),l=new Map;for(let[c,a]of Object.entries(n)){if(!st.has(a.connectionStatus))continue;let f=nt(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=Y(c.profileUrl),f=a?i.get(a):null,u=f?n[f]:void 0;if(u){if(u.connectionStatus!=="connected"){u.connectionStatus="connected";let m=c.time?V(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=V(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=nt(c.name),v=g?l.get(g)||[]:[];v.length&&(m.possibleDuplicateOf=[...v],s.flaggedDuplicates++,s.flagged.push({name:c.name,candidates:v.length})),n[c.profileUrl]=m,a&&i.set(a,c.profileUrl),s.newPeople++}}return t||Se(n),s}function Qn(e,t,n,o,r,s){if(console.log(`
61
+ ${a} empty rounds \u2014 end of list.`);break}let k=await ct(e);o&&k==="clicked"&&console.log(' \u2192 Clicked "Load more"'),await Y(2e3)}return o||process.stdout.write(`
62
+ `),Array.from(i.values())}var lt=new Set(["pending","sent_with_note","sent_without_note","sent_without_note_upsell"]);function st(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function at(e){let t=new Map;for(let[n,o]of Object.entries(e)){let r=G(o.profileUrl||n);r&&!t.has(r)&&t.set(r,n)}for(let[n,o]of Object.entries(e))for(let r of o.aliases||[])r&&!t.has(r)&&t.set(r,n);return t}function Zn(e,t){let n=[],o=at(t);for(let r of e){if(!r.profileUrl)continue;let s=o.get(G(r.profileUrl)),i=s?t[s]:void 0;i&&lt.has(i.connectionStatus)&&n.push({...r,previousStatus:i.connectionStatus})}return n}function ut(e,t){let n=q(),o=new Date().toISOString(),r=o.slice(0,10),s={newPeople:0,updatedToConnected:0,alreadyConnected:0,flaggedDuplicates:0,flagged:[]},i=at(n),l=new Map;for(let[c,a]of Object.entries(n)){if(!lt.has(a.connectionStatus))continue;let f=st(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=G(c.profileUrl),f=a?i.get(a):null,u=f?n[f]:void 0;if(u){if(u.connectionStatus!=="connected"){u.connectionStatus="connected";let m=c.time?V(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=V(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=st(c.name),k=g?l.get(g)||[]:[];k.length&&(m.possibleDuplicateOf=[...k],s.flaggedDuplicates++,s.flagged.push({name:c.name,candidates:k.length})),n[c.profileUrl]=m,a&&i.set(a,c.profileUrl),s.newPeople++}}return t||Te(n),s}function eo(e,t,n,o,r,s){if(console.log(`
61
63
  \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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: ${n.newPeople}`),console.log(` Updated to connected: ${n.updatedToConnected}`),console.log(` Already connected: ${n.alreadyConnected}`),t.length>0){console.log(`
62
64
  Newly accepted (${t.length}):`);for(let i of t)console.log(` \u2713 ${i.name||"Unknown"} (was: ${i.previousStatus})`)}if(n.flaggedDuplicates>0){console.log(`
63
65
  \u26A0 Possible duplicates (${n.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 n.flagged||[])console.log(` ? ${i.name||"Unknown"}${i.candidates>1?` (${i.candidates} candidates)`:""}`)}o&&console.log(`
64
66
  [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
65
- `)}async function Xn(){let e=Wn();if(await et(),e.list){Vn();return}let t=e.full?"full":"incremental",n=Je("sync",t);console.log(`
67
+ `)}async function to(){let e=Gn();if(await ot(),e.list){Kn();return}let t=e.full?"full":"incremental",n=Ve("sync",t);console.log(`
66
68
  \u{1F504} Sync LinkedIn Connections (${t})
67
- `),e.dryRun&&console.log(" [DRY RUN mode]"),e.max!==1/0&&console.log(` Max: ${e.max}`);let{browser:o,page:r}=await Le();try{let s=await Gn(r),i=e.full?await Yn(r,{max:e.max,verbose:e.verbose,dryRun:e.dryRun}):await Kn(r,{max:e.max,verbose:e.verbose});console.log(`
68
- Extracted ${i.length} connections.`);let l=q(),c=zn(i,l),a=ct(i,e.dryRun);Qn(i,c,a,e.dryRun,s,t),se(n,"success",{scraped:i.length,newPeople:a.newPeople,updatedToConnected:a.updatedToConnected})}catch(s){console.error(`
69
- \u2717 Error:`,s.message),e.verbose&&console.error(s.stack),se(n,"error",null,s.message)}finally{await o.close().catch(()=>{})}}process.argv[1]&&import.meta.url===Hn(process.argv[1]).href&&Xn();export{it as buildSlugIndex,zn as detectNewlyAccepted,nt as normName,ct as syncToDatabaseBatch};
69
+ `),e.dryRun&&console.log(" [DRY RUN mode]"),e.max!==1/0&&console.log(` Max: ${e.max}`);let{browser:o,page:r}=await Ue();try{let s=await zn(r),i=e.full?await Qn(r,{max:e.max,verbose:e.verbose,dryRun:e.dryRun}):await Xn(r,{max:e.max,verbose:e.verbose});console.log(`
70
+ Extracted ${i.length} connections.`);let l=q(),c=Zn(i,l),a=ut(i,e.dryRun);eo(i,c,a,e.dryRun,s,t),ie(n,"success",{scraped:i.length,newPeople:a.newPeople,updatedToConnected:a.updatedToConnected})}catch(s){console.error(`
71
+ \u2717 Error:`,s.message),e.verbose&&console.error(s.stack),ie(n,"error",null,s.message)}finally{await o.close().catch(()=>{})}}process.argv[1]&&import.meta.url===Yn(process.argv[1]).href&&to();export{at as buildSlugIndex,Zn as detectNewlyAccepted,st as normName,ut as syncToDatabaseBatch};
@@ -1,8 +1,10 @@
1
- var ot=Object.defineProperty;var z=(e,t)=>()=>(e&&(t=e(e=0)),t);var rt=(e,t)=>{for(var n in t)ot(e,n,{get:t[n],enumerable:!0})};async function m(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function it(e,t,{timeout:n=45e3,poll:o=1e3,label:r="page"}={}){let a=Date.now();for(;Date.now()-a<n;){try{if(await e.evaluate(f=>!!document.querySelector(f),t)){let f=Date.now()-a;return f>6e3&&console.log(` (waited ${Math.round(f/1e3)}s for LinkedIn to finish loading ${r})`),!0}}catch{}await new Promise(i=>setTimeout(i,o))}return!1}function at(e){return st.test(e||"")}async function ne(e,{readySelector:t,label:n="page",timeout:o=45e3}={}){let r=await it(e,t,{timeout:o,label:n});if(!r&&at(e.url())){let a=new Error(`Session expired (${n}) \u2014 redirected to login. Run: ilml linkedin login`);throw a.code="SESSION_EXPIRED",a}return r}async function oe(e,t,{readySelector:n,label:o="page",timeout:r=45e3,gotoTimeout:a=6e4}={}){return await e.goto(t,{waitUntil:"domcontentloaded",timeout:a}),ne(e,{readySelector:n,label:o,timeout:r})}async function xe(e){return await e.evaluate(()=>{let t=document.querySelectorAll("div.artdeco-modal--is-open");for(let o of t){let r=o.innerText||"",a=r.includes("Premium")||r.includes("premium")||r.includes("Upgrade")||r.includes("upgrade"),i=r.includes("Try for")||r.includes("free trial")||r.includes("/month")||r.includes("per month")||r.includes("Start my")||r.includes("Subscribe"),f=r.includes("Get hired faster")||r.includes("Get hired 2x");if(a||i||f){let x=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(x)return x.click(),{dismissed:!0,matched:r.substring(0,80)};let d=o.querySelectorAll("button");for(let S of d){let h=S.innerText?.trim().toLowerCase()||"",w=S.getAttribute("aria-label")?.toLowerCase()||"";if(h==="not now"||h==="no thanks"||h==="dismiss"||w.includes("dismiss"))return S.click(),{dismissed:!0,matched:r.substring(0,80)}}}}let n=document.querySelector(".premium-upsell-link")||document.querySelector("[data-test-premium-upsell]")||document.querySelector(".premium-hub-upsell");if(n){let o=n.closest('[class*="modal"]')?.querySelector('button[aria-label="Dismiss"]')||n.closest('[class*="banner"]')?.querySelector('button[aria-label="Close"]');if(o)return o.click(),{dismissed:!0,matched:"premium-banner"}}return!1})}var st,H=z(()=>{st=/\/authwall|\/login|\/checkpoint|\/uas\/login/});import{getPluginConfig as lt}from"@ilivemylife/graph-sdk";var ct,ut,q,Vt,dt,re=z(async()=>{ct=await lt();for(let[e,t]of Object.entries(ct))process.env[e]===void 0&&(process.env[e]=t);ut=process.env.LINKEDIN_NAME,q=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Vt=Object.freeze(new Set([q.DRAFT,q.CONFIRMED,q.NEEDS_REVIEW])),dt=Object.freeze(new Set([q.DRAFT,q.CONFIRMED,q.REJECTED,q.NEEDS_REVIEW]))});import"dotenv/config";import*as g from"fs";import*as b from"path";import{fileURLToPath as xt}from"url";function It(){g.existsSync(A)||g.mkdirSync(A,{recursive:!0})}function $t(e,t){if(!g.existsSync(e))return null;try{let n=JSON.parse(g.readFileSync(e,"utf-8"));try{g.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.message}`),console.error(` File: ${b.resolve(e)}`);let o=e+".backup";if(g.existsSync(o))try{let r=JSON.parse(g.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{g.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{g.copyFileSync(e,e+".corrupted")}catch{}return null}}function ae(){return Z||(It(),Z=$t(At,"people.json")||{},Z)}var _t,Et,A,At,hn,wn,gn,yn,bn,Sn,Ve,vn,Cn,Z,le=z(async()=>{await re();_t=xt(import.meta.url),Et=b.dirname(b.dirname(_t)),A=process.env.DATA_DIR?b.resolve(process.env.DATA_DIR,"collected-profiles"):b.join(Et,"collected-profiles"),At=b.join(A,"people.json"),hn=b.join(A,"jobs.json"),wn=b.join(A,"quota.json"),gn=b.join(A,"conversations.json"),yn=b.join(A,"sync-state.json"),bn=b.join(A,"application-questions.json"),Sn=b.join(A,"profile-history"),Ve=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},vn=Ve(process.env.CONNECT_MAX_DAILY,20),Cn=Ve(process.env.CONNECT_MAX_WEEKLY,100),Z=null});var We={};rt(We,{extractCertificationsFromDetails:()=>Rt,extractEducationFromDetails:()=>Lt,extractExperienceFromDetails:()=>Dt,extractFeaturedFromDetails:()=>Tt,extractRecommendationsFromDetails:()=>Mt,extractSkillsFromDetails:()=>Pt});async function Dt(e,t){let n=t.replace(/\/+$/,"")+"/details/experience/";try{await e.goto(n,{waitUntil:"domcontentloaded",timeout:6e4}),await ne(e,{readySelector:"main .pvs-list, .scaffold-layout__main, main.scaffold-layout__main, section.artdeco-card",label:"experience details"}),await m(1e3);for(let r=0;r<5;r++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await m(900);await m(1e3);let o=0;for(;o<5&&await e.evaluate(()=>{for(let a of document.querySelectorAll("button"))if(/^Load more$/i.test((a.textContent||"").trim()))return a.click(),!0;return!1});)o++,await m(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await m(700);return await e.evaluate(()=>{let r=document.querySelector("main");if(!r)return[];function a(d){let S=[];for(let h of d.querySelectorAll("div")){let w=Array.from(h.children).filter(v=>v.tagName==="DIV");if(w.length<3)continue;let y=w.filter(v=>(v.textContent||"").trim().length>50);y.length<3||(h.textContent||"").length<500||S.push({el:h,count:y.length,totalText:(h.textContent||"").length})}return S.sort((h,w)=>w.count-h.count||h.totalText-w.totalText),S[0]?.el}let i=a(r);if(!i)return[];let f=Array.from(i.children).filter(d=>d.tagName==="DIV").filter(d=>(d.textContent||"").trim().length>50);function x(d){let S=d[0]||null,h=null,w=null;if(d[1]){let l=d[1].split("\xB7").map(C=>C.trim());h=l[0]||null,l[1]&&(w=l[1])}let y=d.findIndex(l=>/(\d{4}|present)/i.test(l)&&/(-|–|—)/i.test(l)&&l.length<80),v=null,T=null;if(y>=0){let l=d[y].split("\xB7").map(C=>C.trim());v=l[0]||null,l[1]&&(T=l[1])}let L=null,P=-1;if(y>=0&&d[y+1]){let l=d[y+1],C=/^[>*\-•]|^&gt;/.test(l),O=/https?:\/\//.test(l),F=/\d{4}/.test(l),N=/,/.test(l)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(l);!C&&!O&&!F&&l.length<100&&N&&(L=l,P=y+1)}let R=null,X=-1,p=d[d.length-1];if(p&&/and\s+\+\d+\s+skills?$/i.test(p)){X=d.length-1;let l=p.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);l&&(R={listed:l[1].split(",").map(C=>C.trim()),additional:parseInt(l[2],10)})}let j=new Set([0,1,y,P,X].filter(l=>l>=0)),I=d.filter((l,C)=>!j.has(C)),M=I.length>0?I.join(`
1
+ var st=Object.defineProperty;var H=(e,t)=>()=>(e&&(t=e(e=0)),t);var at=(e,t)=>{for(var n in t)st(e,n,{get:t[n],enumerable:!0})};import k from"fs";import A from"path";function ie(){let e=process.env.ILML_SCOPE_DIR;return e?A.join(e,"plugins-state","linkedin","cookies.json"):lt}function ct(){let e=ie(),t=A.dirname(e);return t&&t!=="."&&!k.existsSync(t)&&k.mkdirSync(t,{recursive:!0}),e}function Ee(e){let t=ct();return k.writeFileSync(t,JSON.stringify(e)),t}function Ae(){let e=ie();if(!k.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=k.readFileSync(e,"utf-8")}catch(o){throw new Error(`Failed to read cookies at ${e}: ${o.message}. Run: ilml linkedin login`)}let n;try{n=JSON.parse(t)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(n)||n.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return n}function Ie(){return k.existsSync(ie())}function ut(){let e=process.env.ILML_SCOPE_DIR;return e?A.join(e,"plugins-state","linkedin"):"."}function $e(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function dt(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?$e(t[1]):"default"}function De(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return k.existsSync(t)||k.mkdirSync(t,{recursive:!0}),A.resolve(t);let n=$e(e||dt()),o=A.join(ut(),"chrome-profile",n);return k.existsSync(o)||k.mkdirSync(o,{recursive:!0}),A.resolve(o)}function Le(e){return!k.existsSync(A.join(e,Te))}function Pe(e){try{k.writeFileSync(A.join(e,Te),new Date().toISOString())}catch{}}function Re(e){let t=0;for(let n of["SingletonLock","SingletonCookie","SingletonSocket"])try{k.rmSync(A.join(e,n),{force:!0}),t++}catch{}return t}var lt,Te,Q=H(()=>{lt="cookies.json";Te=".ilml-seeded"});async function p(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function ft(e,t,{timeout:n=45e3,poll:o=1e3,label:i="page"}={}){let l=Date.now();for(;Date.now()-l<n;){try{if(await e.evaluate(d=>!!document.querySelector(d),t)){let d=Date.now()-l;return d>6e3&&console.log(` (waited ${Math.round(d/1e3)}s for LinkedIn to finish loading ${i})`),!0}}catch{}await new Promise(r=>setTimeout(r,o))}return!1}function mt(e){return Me.test(e||"")}async function pt(e,{credentialWaitMs:t=36e4,label:n="page"}={}){console.log(` \u26A0 Auth wall on ${n} \u2014 attempting self-recovery (cookies may just need a refresh)...`);try{await e.goto("https://www.linkedin.com/feed/",{waitUntil:"domcontentloaded",timeout:6e4})}catch{}let o=!!(process.stdin&&process.stdin.isTTY),i=o?t:Math.min(t,45e3),l=Date.now(),r=!1;for(;Date.now()-l<i;){let v="wait";try{v=await e.evaluate(s=>!new RegExp(s).test(location.href)&&document.querySelector("#global-nav, nav.global-nav")?"in":document.querySelector('input#username, input[name="session_key"], input#password')?"creds":"wait",Me.source)}catch{}if(v==="in"){try{let s=await e.cookies();if(Array.isArray(s)&&s.some(m=>m.name==="li_at")){let m=Ee(s);console.log(` \u2713 Session recovered \u2014 re-saved ${s.length} cookies (${m}).`)}else console.log(" \u2713 Session recovered (kept existing cookie snapshot \u2014 refreshed set had no li_at).")}catch(s){console.log(` \u2713 Session recovered (cookie re-save skipped: ${s.message}).`)}return!0}if(v==="creds"){if(!o){let s=new Error(`Session expired (${n}) \u2014 credentials required and no interactive terminal. Run: ilml linkedin login`);throw s.code="SESSION_EXPIRED",s}r||(r=!0,console.log(`
2
+ \u26A0 LinkedIn is asking for your login + password (cookies not enough this time).`),console.log(" \u2192 Sign in MANUALLY in the browser window that is already open."),console.log(` I will wait and resume automatically \u2014 do NOT close the window or re-run the command.
3
+ `))}await new Promise(s=>setTimeout(s,2500))}let d=new Error(`Session expired (${n}) \u2014 not signed in within the wait window. Run: ilml linkedin login`);throw d.code="SESSION_EXPIRED",d}async function Z(e,{readySelector:t,label:n="page",timeout:o=45e3}={}){let i=await ft(e,t,{timeout:o,label:n});if(!i&&mt(e.url())){let l=new Error(`Session expired (${n}) \u2014 redirected to login. Run: ilml linkedin login`);throw l.code="SESSION_EXPIRED",l}return i}async function re(e,t,{readySelector:n,label:o="page",timeout:i=45e3,gotoTimeout:l=6e4,autoRecover:r=!0}={}){await e.goto(t,{waitUntil:"domcontentloaded",timeout:l});try{return await Z(e,{readySelector:n,label:o,timeout:i})}catch(d){if(r&&d.code==="SESSION_EXPIRED"){await pt(e,{label:o});try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:l})}catch{}return await Z(e,{readySelector:n,label:o,timeout:i})}throw d}}async function qe(e){return await e.evaluate(()=>{let t=document.querySelectorAll("div.artdeco-modal--is-open");for(let o of t){let i=o.innerText||"",l=i.includes("Premium")||i.includes("premium")||i.includes("Upgrade")||i.includes("upgrade"),r=i.includes("Try for")||i.includes("free trial")||i.includes("/month")||i.includes("per month")||i.includes("Start my")||i.includes("Subscribe"),d=i.includes("Get hired faster")||i.includes("Get hired 2x");if(l||r||d){let v=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(v)return v.click(),{dismissed:!0,matched:i.substring(0,80)};let s=o.querySelectorAll("button");for(let g of s){let m=g.innerText?.trim().toLowerCase()||"",w=g.getAttribute("aria-label")?.toLowerCase()||"";if(m==="not now"||m==="no thanks"||m==="dismiss"||w.includes("dismiss"))return g.click(),{dismissed:!0,matched:i.substring(0,80)}}}}let n=document.querySelector(".premium-upsell-link")||document.querySelector("[data-test-premium-upsell]")||document.querySelector(".premium-hub-upsell");if(n){let o=n.closest('[class*="modal"]')?.querySelector('button[aria-label="Dismiss"]')||n.closest('[class*="banner"]')?.querySelector('button[aria-label="Close"]');if(o)return o.click(),{dismissed:!0,matched:"premium-banner"}}return!1})}var Me,U=H(()=>{Q();Me=/\/authwall|\/login|\/checkpoint|\/uas\/login/});import{getPluginConfig as ht}from"@ilivemylife/graph-sdk";var wt,gt,q,Zt,yt,se=H(async()=>{wt=await ht();for(let[e,t]of Object.entries(wt))process.env[e]===void 0&&(process.env[e]=t);gt=process.env.LINKEDIN_NAME,q=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Zt=Object.freeze(new Set([q.DRAFT,q.CONFIRMED,q.NEEDS_REVIEW])),yt=Object.freeze(new Set([q.DRAFT,q.CONFIRMED,q.REJECTED,q.NEEDS_REVIEW]))});import"dotenv/config";import*as y from"fs";import*as S from"path";import{fileURLToPath as It}from"url";function Lt(){y.existsSync(I)||y.mkdirSync(I,{recursive:!0})}function Pt(e,t){if(!y.existsSync(e))return null;try{let n=JSON.parse(y.readFileSync(e,"utf-8"));try{y.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${t} is corrupted: ${n.message}`),console.error(` File: ${S.resolve(e)}`);let o=e+".backup";if(y.existsSync(o))try{let i=JSON.parse(y.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{y.copyFileSync(o,e)}catch{}return i}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{y.copyFileSync(e,e+".corrupted")}catch{}return null}}function ce(){return ee||(Lt(),ee=Pt(Tt,"people.json")||{},ee)}var $t,Dt,I,Tt,Sn,vn,kn,Cn,xn,_n,Ye,En,An,ee,ue=H(async()=>{await se();$t=It(import.meta.url),Dt=S.dirname(S.dirname($t)),I=process.env.DATA_DIR?S.resolve(process.env.DATA_DIR,"collected-profiles"):S.join(Dt,"collected-profiles"),Tt=S.join(I,"people.json"),Sn=S.join(I,"jobs.json"),vn=S.join(I,"quota.json"),kn=S.join(I,"conversations.json"),Cn=S.join(I,"sync-state.json"),xn=S.join(I,"application-questions.json"),_n=S.join(I,"profile-history"),Ye=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},En=Ye(process.env.CONNECT_MAX_DAILY,20),An=Ye(process.env.CONNECT_MAX_WEEKLY,100),ee=null});var Ke={};at(Ke,{extractCertificationsFromDetails:()=>Nt,extractEducationFromDetails:()=>qt,extractExperienceFromDetails:()=>Rt,extractFeaturedFromDetails:()=>Mt,extractRecommendationsFromDetails:()=>Ot,extractSkillsFromDetails:()=>Ft});async function Rt(e,t){let n=t.replace(/\/+$/,"")+"/details/experience/";try{await e.goto(n,{waitUntil:"domcontentloaded",timeout:6e4}),await Z(e,{readySelector:"main .pvs-list, .scaffold-layout__main, main.scaffold-layout__main, section.artdeco-card",label:"experience details"}),await p(1e3);for(let i=0;i<5;i++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await p(900);await p(1e3);let o=0;for(;o<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});)o++,await p(1500),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await p(700);return await e.evaluate(()=>{let i=document.querySelector("main");if(!i)return[];function l(s){let g=[];for(let m of s.querySelectorAll("div")){let w=Array.from(m.children).filter(C=>C.tagName==="DIV");if(w.length<3)continue;let b=w.filter(C=>(C.textContent||"").trim().length>50);b.length<3||(m.textContent||"").length<500||g.push({el:m,count:b.length,totalText:(m.textContent||"").length})}return g.sort((m,w)=>w.count-m.count||m.totalText-w.totalText),g[0]?.el}let r=l(i);if(!r)return[];let d=Array.from(r.children).filter(s=>s.tagName==="DIV").filter(s=>(s.textContent||"").trim().length>50);function v(s){let g=s[0]||null,m=null,w=null;if(s[1]){let c=s[1].split("\xB7").map(x=>x.trim());m=c[0]||null,c[1]&&(w=c[1])}let b=s.findIndex(c=>/(\d{4}|present)/i.test(c)&&/(-|–|—)/i.test(c)&&c.length<80),C=null,T=null;if(b>=0){let c=s[b].split("\xB7").map(x=>x.trim());C=c[0]||null,c[1]&&(T=c[1])}let L=null,P=-1;if(b>=0&&s[b+1]){let c=s[b+1],x=/^[>*\-•]|^&gt;/.test(c),j=/https?:\/\//.test(c),F=/\d{4}/.test(c),N=/,/.test(c)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(c);!x&&!j&&!F&&c.length<100&&N&&(L=c,P=b+1)}let R=null,te=-1,h=s[s.length-1];if(h&&/and\s+\+\d+\s+skills?$/i.test(h)){te=s.length-1;let c=h.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);c&&(R={listed:c[1].split(",").map(x=>x.trim()),additional:parseInt(c[2],10)})}let O=new Set([0,1,b,P,te].filter(c=>c>=0)),$=s.filter((c,x)=>!O.has(x)),M=$.length>0?$.join(`
2
4
 
3
- `):null;return{title:S,company:h,employmentType:w,dates:v,duration:T,location:L,description:M,skills:R,_raw:d}}return f.map(d=>{let h=(d.innerText||"").trim().split(`
4
- `).map(w=>w.trim()).filter(w=>w&&w.length<5e3);return x(h)}).filter(d=>d.title)})}catch(o){if(/session expired|bounced to|authwall|checkpoint/i.test(o.message||""))throw o;return console.error(`extractExperienceFromDetails failed for ${t}: ${o.message?.slice(0,120)}`),[]}}async function W(e,t,n){let o=t.replace(/\/+$/,"")+`/details/${n}/`;await e.goto(o,{waitUntil:"domcontentloaded",timeout:6e4}),await m(3e3);let r=e.url();if(/\/(login|authwall|checkpoint)/i.test(r))throw new Error(`Session expired \u2014 bounced to ${r} when fetching /details/${n}/`);if(!r.toLowerCase().includes(`/details/${n.toLowerCase()}/`))throw new Error(`Section /details/${n}/ not available on profile (landed on ${r})`);for(let i=0;i<4;i++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await m(700);await m(800);let a=0;for(;a<5&&await e.evaluate(()=>{for(let f of document.querySelectorAll("button"))if(/^Load more$/i.test((f.textContent||"").trim()))return f.click(),!0;return!1});)a++,await m(1300),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await m(600)}async function Y(e,t,n,o){try{return await o()}catch(r){let a=r.message||"";if(/session expired|bounced to|authwall|checkpoint/i.test(a))throw r;return/not available on profile/i.test(a)?(console.log(` (${t}: section not on profile \u2014 skipped)`),[]):(console.error(`${n} failed for ${e}: ${a.slice(0,120)}`),[])}}async function Tt(e,t){return Y(t,"featured","extractFeaturedFromDetails",async()=>(await W(e,t,"featured"),await e.evaluate(`(() => {
5
- ${J}
5
+ `):null;return{title:g,company:m,employmentType:w,dates:C,duration:T,location:L,description:M,skills:R,_raw:s}}return d.map(s=>{let m=(s.innerText||"").trim().split(`
6
+ `).map(w=>w.trim()).filter(w=>w&&w.length<5e3);return v(m)}).filter(s=>s.title)})}catch(o){if(/session expired|bounced to|authwall|checkpoint/i.test(o.message||""))throw o;return console.error(`extractExperienceFromDetails failed for ${t}: ${o.message?.slice(0,120)}`),[]}}async function J(e,t,n){let o=t.replace(/\/+$/,"")+`/details/${n}/`;await e.goto(o,{waitUntil:"domcontentloaded",timeout:6e4}),await p(3e3);let i=e.url();if(/\/(login|authwall|checkpoint)/i.test(i))throw new Error(`Session expired \u2014 bounced to ${i} when fetching /details/${n}/`);if(!i.toLowerCase().includes(`/details/${n.toLowerCase()}/`))throw new Error(`Section /details/${n}/ not available on profile (landed on ${i})`);for(let r=0;r<4;r++)await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await p(700);await p(800);let l=0;for(;l<5&&await e.evaluate(()=>{for(let d of document.querySelectorAll("button"))if(/^Load more$/i.test((d.textContent||"").trim()))return d.click(),!0;return!1});)l++,await p(1300),await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await p(600)}async function K(e,t,n,o){try{return await o()}catch(i){let l=i.message||"";if(/session expired|bounced to|authwall|checkpoint/i.test(l))throw i;return/not available on profile/i.test(l)?(console.log(` (${t}: section not on profile \u2014 skipped)`),[]):(console.error(`${n} failed for ${e}: ${l.slice(0,120)}`),[])}}async function Mt(e,t){return K(t,"featured","extractFeaturedFromDetails",async()=>(await J(e,t,"featured"),await e.evaluate(`(() => {
7
+ ${Y}
6
8
 
7
9
  const main = document.querySelector('main');
8
10
  if (!main) return [];
@@ -42,8 +44,8 @@ var ot=Object.defineProperty;var z=(e,t)=>()=>(e&&(t=e(e=0)),t);var rt=(e,t)=>{f
42
44
  if (e.caption && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.caption.trim())) return false;
43
45
  return true;
44
46
  });
45
- })()`)))}async function Lt(e,t){return Y(t,"education","extractEducationFromDetails",async()=>(await W(e,t,"education"),await e.evaluate(`(() => {
46
- ${J}
47
+ })()`)))}async function qt(e,t){return K(t,"education","extractEducationFromDetails",async()=>(await J(e,t,"education"),await e.evaluate(`(() => {
48
+ ${Y}
47
49
 
48
50
  const main = document.querySelector('main');
49
51
  if (!main) return [];
@@ -79,8 +81,8 @@ var ot=Object.defineProperty;var z=(e,t)=>()=>(e&&(t=e(e=0)),t);var rt=(e,t)=>{f
79
81
  if (e.degree && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.degree.trim())) return false;
80
82
  return true;
81
83
  });
82
- })()`)))}async function Pt(e,t){return Y(t,"skills","extractSkillsFromDetails",async()=>(await W(e,t,"skills"),await e.evaluate(`(() => {
83
- ${J}
84
+ })()`)))}async function Ft(e,t){return K(t,"skills","extractSkillsFromDetails",async()=>(await J(e,t,"skills"),await e.evaluate(`(() => {
85
+ ${Y}
84
86
 
85
87
  const main = document.querySelector('main');
86
88
  if (!main) return [];
@@ -111,8 +113,8 @@ var ot=Object.defineProperty;var z=(e,t)=>()=>(e&&(t=e(e=0)),t);var rt=(e,t)=>{f
111
113
  skills.push({ name, endorsements, _raw: lines });
112
114
  }
113
115
  return skills;
114
- })()`)))}async function Rt(e,t){return Y(t,"certifications","extractCertificationsFromDetails",async()=>(await W(e,t,"certifications"),await e.evaluate(`(() => {
115
- ${J}
116
+ })()`)))}async function Nt(e,t){return K(t,"certifications","extractCertificationsFromDetails",async()=>(await J(e,t,"certifications"),await e.evaluate(`(() => {
117
+ ${Y}
116
118
 
117
119
  const main = document.querySelector('main');
118
120
  if (!main) return [];
@@ -136,8 +138,8 @@ var ot=Object.defineProperty;var z=(e,t)=>()=>(e&&(t=e(e=0)),t);var rt=(e,t)=>{f
136
138
 
137
139
  return { name, issuer, issueDate, expiryDate, credentialId, _raw: lines };
138
140
  }).filter(e => e.name);
139
- })()`)))}async function Mt(e,t){return Y(t,"recommendations","extractRecommendationsFromDetails",async()=>(await W(e,t,"recommendations"),await e.evaluate(`(() => {
140
- ${J}
141
+ })()`)))}async function Ot(e,t){return K(t,"recommendations","extractRecommendationsFromDetails",async()=>(await J(e,t,"recommendations"),await e.evaluate(`(() => {
142
+ ${Y}
141
143
 
142
144
  const main = document.querySelector('main');
143
145
  if (!main) return [];
@@ -172,7 +174,7 @@ var ot=Object.defineProperty;var z=(e,t)=>()=>(e&&(t=e(e=0)),t);var rt=(e,t)=>{f
172
174
  if (e.recommenderTitle && /^\xB7\\s*\\d+(?:st|nd|rd|th)\\+?$/i.test(e.recommenderTitle.trim())) return false;
173
175
  return true;
174
176
  });
175
- })()`)))}var J,Je=z(()=>{H();J=`
177
+ })()`)))}var Y,Ge=H(()=>{U();Y=`
176
178
  function findEntryContainer(root) {
177
179
  const candidates = [];
178
180
  for (const div of root.querySelectorAll('div')) {
@@ -235,9 +237,9 @@ function findEntryContainer(root) {
235
237
  candidates.sort((a, b) => b.count - a.count || b.totalText - a.totalText);
236
238
  return candidates[0]?.el;
237
239
  }
238
- `});import vt from"puppeteer";import{addExtra as Ct}from"puppeteer-extra";import kt from"puppeteer-extra-plugin-stealth";H();await re();import _ from"fs";import D from"path";var ft="cookies.json";function _e(){let e=process.env.ILML_SCOPE_DIR;return e?D.join(e,"plugins-state","linkedin","cookies.json"):ft}function Ee(){let e=_e();if(!_.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=_.readFileSync(e,"utf-8")}catch(o){throw new Error(`Failed to read cookies at ${e}: ${o.message}. Run: ilml linkedin login`)}let n;try{n=JSON.parse(t)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(n)||n.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return n}function Ae(){return _.existsSync(_e())}function mt(){let e=process.env.ILML_SCOPE_DIR;return e?D.join(e,"plugins-state","linkedin"):"."}function Ie(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function pt(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?Ie(t[1]):"default"}function $e(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return _.existsSync(t)||_.mkdirSync(t,{recursive:!0}),D.resolve(t);let n=Ie(e||pt()),o=D.join(mt(),"chrome-profile",n);return _.existsSync(o)||_.mkdirSync(o,{recursive:!0}),D.resolve(o)}var De=".ilml-seeded";function Te(e){return!_.existsSync(D.join(e,De))}function Le(e){try{_.writeFileSync(D.join(e,De),new Date().toISOString())}catch{}}function Pe(e){let t=0;for(let n of["SingletonLock","SingletonCookie","SingletonSocket"])try{_.rmSync(D.join(e,n),{force:!0}),t++}catch{}return t}import ie from"fs";import ht from"path";var wt={headless:!1,defaultViewport:null,protocolTimeout:3e5},V=new Set,Re=!1;async function Q(){let e=[...V].map(t=>{try{return Promise.resolve(t.close()).catch(()=>{})}catch{return Promise.resolve()}});V.clear(),await Promise.race([Promise.all(e),new Promise(t=>setTimeout(t,5e3))])}function gt(){if(Re)return;Re=!0;let e=t=>async()=>{await Q(),process.exit(t)};process.once("SIGINT",e(130)),process.once("SIGTERM",e(143)),process.once("SIGHUP",e(129)),process.once("uncaughtException",async t=>{await Q(),console.error(t&&t.stack||t),process.exit(1)}),process.once("unhandledRejection",async t=>{await Q(),console.error(t),process.exit(1)}),process.stdout.on("error",async t=>{t&&t.code==="EPIPE"&&(await Q(),process.exit(0))}),process.on("exit",()=>{for(let t of V)try{let n=t.process&&t.process();n&&n.kill("SIGKILL")}catch{}})}function se(e){return ht.join(e,".ilml-browser-session.json")}function Ne(e,t={}){try{ie.writeFileSync(se(e),JSON.stringify({ownerPid:process.pid,startedAt:Date.now(),...t}))}catch{}}function yt(e,t){try{let n=t.wsEndpoint&&t.wsEndpoint();Ne(e,n?{wsEndpoint:n}:{})}catch{}}function bt(e){let t=je(e);t&&t.ownerPid===process.pid&&U(e)}function U(e){try{ie.rmSync(se(e),{force:!0})}catch{}}function je(e){try{return JSON.parse(ie.readFileSync(se(e),"utf-8"))}catch{return null}}function Me(e){if(!e||e===process.pid)return!0;try{return process.kill(e,0),!0}catch(t){return!t||t.code!=="ESRCH"}}function qe(e,t,n){let o,r=new Promise(i=>{o=setTimeout(()=>i(n),t)}),a=Promise.resolve(e).then(i=>(clearTimeout(o),i),i=>{throw clearTimeout(o),i});return Promise.race([a,r])}async function Fe(e,t,{probeTimeoutMs:n=4e3}={}){let o=je(t);if(!o)return"free";if(!o.wsEndpoint)return o.ownerPid&&o.ownerPid!==process.pid&&Me(o.ownerPid)?"live":(U(t),"free");let r=Symbol("timeout"),a=e.connect({browserWSEndpoint:o.wsEndpoint,defaultViewport:null}).catch(()=>null),i=await qe(a,n,r);if(i===r)return a.then(x=>{if(x)try{x.disconnect()}catch{}}),"live";if(!i)return U(t),"free";if(Me(o.ownerPid)){try{i.disconnect()}catch{}return"live"}if(console.log(" (recovered an orphaned automation browser from a previous run \u2014 closing it)"),await qe(i.close().then(()=>!0).catch(()=>!1),n,!1))return U(t),"free";try{i.disconnect()}catch{}return"live"}function St(e,t){e&&(gt(),V.add(e),e.on("disconnected",()=>{V.delete(e),t&&U(t)}))}async function Oe(e,t={}){let n=$e(),o={...wt,...t,userDataDir:n},r=`Could not open the LinkedIn automation Chrome profile at ${n}. Another LinkedIn automation command is already running (or its window is still open) \u2014 wait for it to finish or close that window, then retry.`;if(await Fe(e,n)==="live")throw new Error(r);Ne(n);let a;try{a=await e.launch(o)}catch{if(await Fe(e,n)==="live")throw new Error(r);Pe(n);try{a=await e.launch(o)}catch(f){throw bt(n),new Error(`Could not open the LinkedIn automation Chrome profile at ${n}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${f.message})`)}}return St(a,n),yt(n,a),{browser:a,profileDir:n,needsSeed:Te(n)}}async function Be(e,t){if(!t||!t.needsSeed)return!1;if(!Ae())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(...Ee()),Le(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var He=Ct(vt);He.use(kt());async function Ue(){let{browser:e,profileDir:t,needsSeed:n}=await Oe(He),o=await e.newPage();return await o.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Be(o,{profileDir:t,needsSeed:n}),console.log(" Browser launched (persistent profile)."),{browser:e,page:o}}H();await le();async function qt(e,t){let n=e.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: ilml linkedin login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await m(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function Ye(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:a=!1,extractSkills:i=!1,extractRecommendations:f=!1,extractCertifications:x=!1}=n;try{await oe(e,t,{readySelector:".scaffold-layout__main, main.scaffold-layout__main, .pv-top-card, section.pv-top-card",label:"profile"}),await m(1500),await xe(e)&&(console.log(" Dismissed Premium overlay"),await m(1500),await qt(e,t));let S=0;for(let p=0;p<2;p++){let j=await e.evaluate(()=>document.body.scrollHeight);for(let M=1;M<=6;M++)await e.evaluate(l=>window.scrollTo(0,l),j*M/6),await m(900);let I=await e.evaluate(()=>document.body.scrollHeight);if(I===S)break;S=I}await m(800);let h=null;try{let p=e.url();p&&/\/in\/[^/?#]/.test(p)&&(h=p.split("?")[0].replace(/\/+$/,""))}catch{}let w=await e.evaluate(()=>{let p=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),j=new Set(["Ad Options","Don\u2019t want to see this","0 notifications","Explore Premium profiles","You might like","People you may know","Suggested for you","More profiles for you","Promoted"]),I=s=>{let c=(s||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(c)},M={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:[]},l=document.querySelector("main");if(!l)return M;let C=[...Array.from(l.querySelectorAll("h1")),...Array.from(l.querySelectorAll("h2"))],O=Array.from(l.querySelectorAll("h2")),F=C.find(s=>{let c=s.textContent&&s.textContent.trim(),u=(c||"").replace(/\s*\(\d+\)$/,"").trim();return c&&c.length>1&&c.length<100&&!p.has(u)&&!j.has(u)}),N=F?F.textContent.trim():null,k=F?F.parentElement:null;for(;k&&k!==l&&!Array.from(k.children).filter(c=>c.tagName==="P").some(c=>{let u=c.textContent&&c.textContent.trim();return u&&u.length>5&&!I(u)});)k=k.parentElement;let ue=null,de=null,fe=null,ee=null;if(k&&k!==l){let s=Array.from(k.children).filter(u=>u.tagName==="P").filter(u=>{let $=u.textContent&&u.textContent.trim();return $&&$.length>5&&!I($)});if(s[0]&&(ue=s[0].textContent.trim()),s[1]){let u=s[1].textContent.trim().split(/\s*[·•]\s*/);de=u[0]||null,u.length>1&&(fe=u.slice(1).join(" \xB7 "))}let c=Array.from(k.children).filter(u=>u.tagName==="DIV");for(let u=c.length-1;u>=0;u--){let $=c[u].textContent&&c[u].textContent.trim();if($&&!(N&&$.startsWith(N))&&(ee=$.split(/[·•]/)[0].trim(),ee))break}}let me=null;if(k){let s=k.querySelectorAll("p, span, div");for(let c of s){let u=(c.textContent||"").trim().replace(/^[·•]\s*/,"");if(u==="1st"||u==="2nd"||u==="3rd"){me=u;break}}}let ze=!!l.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),pe=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),Qe=pe&&pe.src||null,K=l.textContent||"",he=null,we=K.match(/(\d+\+?)\s+connections\b/i);we&&(he=we[1]+" connections");let G=null,ge=K.match(/(\d+)\s+mutual connection/i),ye=K.match(/and\s+(\d+)\s+other mutual/i),Ze=K.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);ge?G=parseInt(ge[1],10):ye?G=2+parseInt(ye[1],10):Ze&&(G=2);let be=null,Se=null,ve=O.find(s=>s.textContent&&s.textContent.trim()==="About");if(ve){let s=ve.parentElement;for(;s&&s.tagName!=="SECTION";)s=s.parentElement;if(s){let c=(s.textContent||"").trim();c=c.replace(/^About\s*/,"").trim();let u=c.match(/Top skills\s*(.+?)$/i);if(u){let te=u[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(nt=>nt.trim()).filter(Boolean);te.length>0&&te.length<10&&(Se=te)}c=c.split(/\n?…\s*more/i)[0].trim(),c=c.split(/\n?\.\.\.\s*more/i)[0].trim(),c=c.split(/\bTop skills\b/i)[0].trim(),c=c.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),be=c||null}}let Ce=null,ke=O.find(s=>s.textContent&&s.textContent.trim()==="Activity");if(ke){let s=ke.parentElement;for(;s&&s.tagName!=="SECTION";)s=s.parentElement;if(s){let c=(s.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);c&&(Ce=parseInt(c[1].replace(/,/g,""),10))}}let Xe=[...new Set(O.map(s=>(s.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(s=>s&&s.length>1&&s.length<60&&s!==N).filter(s=>p.has(s)))],B=document.body.textContent||"",et=/#OpenToWork\b/i.test(B)||/\bOpen to work\b/.test(B),tt=/#Hiring\b/i.test(B)||/\bI'?m hiring\b/i.test(B)||/\bWe are hiring\b/i.test(B);return{name:N,title:ue,location:ee,currentCompany:de,currentSchool:fe,connectionDegree:me,hasVerifiedBadge:ze,photoUrl:Qe,connectionsLevel:he,mutualConnectionsCount:G,followers:Ce,openToWork:et,hiring:tt,about:be,topSkills:Se,availableSections:Xe}});console.log(`Viewed: ${w.name} - ${w.title}`);let y=null,v=null,T=null,L=null,P=null,R=null;if(o||r||a||i||f||x){let p=await Promise.resolve().then(()=>(Je(),We));o&&(y=await p.extractExperienceFromDetails(e,t),console.log(` + Experience: ${y.length} entries`)),r&&(v=await p.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${v.length} entries`)),a&&(T=await p.extractEducationFromDetails(e,t),console.log(` + Education: ${T.length} entries`)),i&&(L=await p.extractSkillsFromDetails(e,t),console.log(` + Skills: ${L.length} entries`)),f&&(P=await p.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${P.length} entries`)),x&&(R=await p.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${R.length} entries`))}return{...w,profileUrl:t,resolvedUrl:h,...y!==null&&{experience:y},...v!==null&&{featured:v},...T!==null&&{education:T},...L!==null&&{skillsFull:L},...P!==null&&{recommendations:P},...R!==null&&{certifications:R}}}catch(d){console.error(`Error viewing profile ${t}:`,d.message);try{await e.goto("about:blank",{timeout:1e4}),await m(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(d.message||""))throw d;return null}}await le();H();var ce=process.argv.slice(2),Ke=ce.filter(e=>e.startsWith("http")),Ge=parseInt(ce.find(e=>e.startsWith("--pick="))?.split("=")[1]||"0"),Ft=ce.includes("--has-about");function Nt(e,t){return[...e].sort(()=>Math.random()-.5).slice(0,t)}function jt(){if(Ke.length>0)return Ke.map(t=>({url:t,name:"(arg)"}));if(Ge>0){let t=ae(),n=Object.entries(t).filter(([o])=>o.startsWith("http")).filter(([,o])=>Ft?!!(o.about&&o.about.trim()):!o.about);return Nt(n,Ge).map(([o,r])=>({url:o,name:r.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,n=80){if(t==null){console.log(` ${e.padEnd(20)} (null)`);return}let o=String(t),r=o.length>n?o.slice(0,n)+`\u2026 (+${o.length-n} chars)`:o;console.log(` ${e.padEnd(20)} ${r} [len=${o.length}]`)}async function Ot(){let e=jt();console.log(`
240
+ `});import _t from"puppeteer";import{addExtra as Et}from"puppeteer-extra";import At from"puppeteer-extra-plugin-stealth";U();await se();Q();Q();import ae from"fs";import bt from"path";var St={headless:!1,defaultViewport:null,protocolTimeout:3e5},W=new Set,Fe=!1;async function X(){let e=[...W].map(t=>{try{return Promise.resolve(t.close()).catch(()=>{})}catch{return Promise.resolve()}});W.clear(),await Promise.race([Promise.all(e),new Promise(t=>setTimeout(t,5e3))])}function vt(){if(Fe)return;Fe=!0;let e=t=>async()=>{await X(),process.exit(t)};process.once("SIGINT",e(130)),process.once("SIGTERM",e(143)),process.once("SIGHUP",e(129)),process.once("uncaughtException",async t=>{await X(),console.error(t&&t.stack||t),process.exit(1)}),process.once("unhandledRejection",async t=>{await X(),console.error(t),process.exit(1)}),process.stdout.on("error",async t=>{t&&t.code==="EPIPE"&&(await X(),process.exit(0))}),process.on("exit",()=>{for(let t of W)try{let n=t.process&&t.process();n&&n.kill("SIGKILL")}catch{}})}function le(e){return bt.join(e,".ilml-browser-session.json")}function Be(e,t={}){try{ae.writeFileSync(le(e),JSON.stringify({ownerPid:process.pid,startedAt:Date.now(),...t}))}catch{}}function kt(e,t){try{let n=t.wsEndpoint&&t.wsEndpoint();Be(e,n?{wsEndpoint:n}:{})}catch{}}function Ct(e){let t=He(e);t&&t.ownerPid===process.pid&&V(e)}function V(e){try{ae.rmSync(le(e),{force:!0})}catch{}}function He(e){try{return JSON.parse(ae.readFileSync(le(e),"utf-8"))}catch{return null}}function Ne(e){if(!e||e===process.pid)return!0;try{return process.kill(e,0),!0}catch(t){return!t||t.code!=="ESRCH"}}function Oe(e,t,n){let o,i=new Promise(r=>{o=setTimeout(()=>r(n),t)}),l=Promise.resolve(e).then(r=>(clearTimeout(o),r),r=>{throw clearTimeout(o),r});return Promise.race([l,i])}async function je(e,t,{probeTimeoutMs:n=4e3}={}){let o=He(t);if(!o)return"free";if(!o.wsEndpoint)return o.ownerPid&&o.ownerPid!==process.pid&&Ne(o.ownerPid)?"live":(V(t),"free");let i=Symbol("timeout"),l=e.connect({browserWSEndpoint:o.wsEndpoint,defaultViewport:null}).catch(()=>null),r=await Oe(l,n,i);if(r===i)return l.then(v=>{if(v)try{v.disconnect()}catch{}}),"live";if(!r)return V(t),"free";if(Ne(o.ownerPid)){try{r.disconnect()}catch{}return"live"}if(console.log(" (recovered an orphaned automation browser from a previous run \u2014 closing it)"),await Oe(r.close().then(()=>!0).catch(()=>!1),n,!1))return V(t),"free";try{r.disconnect()}catch{}return"live"}function xt(e,t){e&&(vt(),W.add(e),e.on("disconnected",()=>{W.delete(e),t&&V(t)}))}async function Ue(e,t={}){let n=De(),o={...St,...t,userDataDir:n},i=`Could not open the LinkedIn automation Chrome profile at ${n}. Another LinkedIn automation command is already running (or its window is still open) \u2014 wait for it to finish or close that window, then retry.`;if(await je(e,n)==="live")throw new Error(i);Be(n);let l;try{l=await e.launch(o)}catch{if(await je(e,n)==="live")throw new Error(i);Re(n);try{l=await e.launch(o)}catch(d){throw Ct(n),new Error(`Could not open the LinkedIn automation Chrome profile at ${n}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${d.message})`)}}return xt(l,n),kt(n,l),{browser:l,profileDir:n,needsSeed:Le(n)}}async function Ve(e,t){if(!t||!t.needsSeed)return!1;if(!Ie())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(...Ae()),Pe(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var We=Et(_t);We.use(At());async function Je(){let{browser:e,profileDir:t,needsSeed:n}=await Ue(We),o=await e.newPage();return await o.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Ve(o,{profileDir:t,needsSeed:n}),console.log(" Browser launched (persistent profile)."),{browser:e,page:o}}U();await ue();async function jt(e,t){let n=e.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: ilml linkedin login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await p(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function ze(e,t,n={}){let{extractExperience:o=!1,extractFeatured:i=!1,extractEducation:l=!1,extractSkills:r=!1,extractRecommendations:d=!1,extractCertifications:v=!1}=n;try{await re(e,t,{readySelector:".scaffold-layout__main, main.scaffold-layout__main, .pv-top-card, section.pv-top-card",label:"profile"}),await p(1500),await qe(e)&&(console.log(" Dismissed Premium overlay"),await p(1500),await jt(e,t));let g=0;for(let h=0;h<2;h++){let O=await e.evaluate(()=>document.body.scrollHeight);for(let M=1;M<=6;M++)await e.evaluate(c=>window.scrollTo(0,c),O*M/6),await p(900);let $=await e.evaluate(()=>document.body.scrollHeight);if($===g)break;g=$}await p(800);let m=null;try{let h=e.url();h&&/\/in\/[^/?#]/.test(h)&&(m=h.split("?")[0].replace(/\/+$/,""))}catch{}let w=await e.evaluate(()=>{let h=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"]),O=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"]),$=a=>{let u=(a||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(u)},M={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},c=document.querySelector("main");if(!c)return M;let x=[...Array.from(c.querySelectorAll("h1")),...Array.from(c.querySelectorAll("h2"))],j=Array.from(c.querySelectorAll("h2")),F=x.find(a=>{let u=a.textContent&&a.textContent.trim(),f=(u||"").replace(/\s*\(\d+\)$/,"").trim();return u&&u.length>1&&u.length<100&&!h.has(f)&&!O.has(f)}),N=F?F.textContent.trim():null,_=F?F.parentElement:null;for(;_&&_!==c&&!Array.from(_.children).filter(u=>u.tagName==="P").some(u=>{let f=u.textContent&&u.textContent.trim();return f&&f.length>5&&!$(f)});)_=_.parentElement;let fe=null,me=null,pe=null,ne=null;if(_&&_!==c){let a=Array.from(_.children).filter(f=>f.tagName==="P").filter(f=>{let D=f.textContent&&f.textContent.trim();return D&&D.length>5&&!$(D)});if(a[0]&&(fe=a[0].textContent.trim()),a[1]){let f=a[1].textContent.trim().split(/\s*[·•]\s*/);me=f[0]||null,f.length>1&&(pe=f.slice(1).join(" \xB7 "))}let u=Array.from(_.children).filter(f=>f.tagName==="DIV");for(let f=u.length-1;f>=0;f--){let D=u[f].textContent&&u[f].textContent.trim();if(D&&!(N&&D.startsWith(N))&&(ne=D.split(/[·•]/)[0].trim(),ne))break}}let he=null;if(_){let a=_.querySelectorAll("p, span, div");for(let u of a){let f=(u.textContent||"").trim().replace(/^[·•]\s*/,"");if(f==="1st"||f==="2nd"||f==="3rd"){he=f;break}}}let Xe=!!c.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),we=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),et=we&&we.src||null,G=c.textContent||"",ge=null,ye=G.match(/(\d+\+?)\s+connections\b/i);ye&&(ge=ye[1]+" connections");let z=null,be=G.match(/(\d+)\s+mutual connection/i),Se=G.match(/and\s+(\d+)\s+other mutual/i),tt=G.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);be?z=parseInt(be[1],10):Se?z=2+parseInt(Se[1],10):tt&&(z=2);let ve=null,ke=null,Ce=j.find(a=>a.textContent&&a.textContent.trim()==="About");if(Ce){let a=Ce.parentElement;for(;a&&a.tagName!=="SECTION";)a=a.parentElement;if(a){let u=(a.textContent||"").trim();u=u.replace(/^About\s*/,"").trim();let f=u.match(/Top skills\s*(.+?)$/i);if(f){let oe=f[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(rt=>rt.trim()).filter(Boolean);oe.length>0&&oe.length<10&&(ke=oe)}u=u.split(/\n?…\s*more/i)[0].trim(),u=u.split(/\n?\.\.\.\s*more/i)[0].trim(),u=u.split(/\bTop skills\b/i)[0].trim(),u=u.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),ve=u||null}}let xe=null,_e=j.find(a=>a.textContent&&a.textContent.trim()==="Activity");if(_e){let a=_e.parentElement;for(;a&&a.tagName!=="SECTION";)a=a.parentElement;if(a){let u=(a.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);u&&(xe=parseInt(u[1].replace(/,/g,""),10))}}let nt=[...new Set(j.map(a=>(a.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(a=>a&&a.length>1&&a.length<60&&a!==N).filter(a=>h.has(a)))],B=document.body.textContent||"",ot=/#OpenToWork\b/i.test(B)||/\bOpen to work\b/.test(B),it=/#Hiring\b/i.test(B)||/\bI'?m hiring\b/i.test(B)||/\bWe are hiring\b/i.test(B);return{name:N,title:fe,location:ne,currentCompany:me,currentSchool:pe,connectionDegree:he,hasVerifiedBadge:Xe,photoUrl:et,connectionsLevel:ge,mutualConnectionsCount:z,followers:xe,openToWork:ot,hiring:it,about:ve,topSkills:ke,availableSections:nt}});console.log(`Viewed: ${w.name} - ${w.title}`);let b=null,C=null,T=null,L=null,P=null,R=null;if(o||i||l||r||d||v){let h=await Promise.resolve().then(()=>(Ge(),Ke));o&&(b=await h.extractExperienceFromDetails(e,t),console.log(` + Experience: ${b.length} entries`)),i&&(C=await h.extractFeaturedFromDetails(e,t),console.log(` + Featured: ${C.length} entries`)),l&&(T=await h.extractEducationFromDetails(e,t),console.log(` + Education: ${T.length} entries`)),r&&(L=await h.extractSkillsFromDetails(e,t),console.log(` + Skills: ${L.length} entries`)),d&&(P=await h.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${P.length} entries`)),v&&(R=await h.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${R.length} entries`))}return{...w,profileUrl:t,resolvedUrl:m,...b!==null&&{experience:b},...C!==null&&{featured:C},...T!==null&&{education:T},...L!==null&&{skillsFull:L},...P!==null&&{recommendations:P},...R!==null&&{certifications:R}}}catch(s){console.error(`Error viewing profile ${t}:`,s.message);try{await e.goto("about:blank",{timeout:1e4}),await p(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(s.message||""))throw s;return null}}await ue();U();var de=process.argv.slice(2),Qe=de.filter(e=>e.startsWith("http")),Ze=parseInt(de.find(e=>e.startsWith("--pick="))?.split("=")[1]||"0"),Bt=de.includes("--has-about");function Ht(e,t){return[...e].sort(()=>Math.random()-.5).slice(0,t)}function Ut(){if(Qe.length>0)return Qe.map(t=>({url:t,name:"(arg)"}));if(Ze>0){let t=ce(),n=Object.entries(t).filter(([o])=>o.startsWith("http")).filter(([,o])=>Bt?!!(o.about&&o.about.trim()):!o.about);return Ht(n,Ze).map(([o,i])=>({url:o,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,n=80){if(t==null){console.log(` ${e.padEnd(20)} (null)`);return}let o=String(t),i=o.length>n?o.slice(0,n)+`\u2026 (+${o.length-n} chars)`:o;console.log(` ${e.padEnd(20)} ${i} [len=${o.length}]`)}async function Vt(){let e=Ut();console.log(`
239
241
  About-selector verification \u2014 ${e.length} profile(s)
240
- `);let{browser:t,page:n}=await Ue();try{for(let o=0;o<e.length;o++){let{url:r,name:a}=e[o];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(` [${o+1}/${e.length}] ${a}`),console.log(` ${r}`),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 i=await Ye(n,r);if(!i){console.log(` \u26A0 viewProfile returned null \u2014 selector failed entirely
241
- `);continue}E("name",i.name),E("title",i.title),E("location",i.location),E("company",i.company),E("connectionDegree",i.connectionDegree),E("connectionsCount",i.connectionsCount),E("mutualConnections",i.mutualConnections),E("hasVerifiedBadge",i.hasVerifiedBadge),E("photoUrl",i.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",i.about,200);let f=[];i.name||f.push("NAME MISSING"),i.title||f.push("TITLE MISSING"),i.location||f.push("LOCATION MISSING"),i.about||f.push("ABOUT MISSING"),console.log(`
242
- Verdict: ${f.length===0?"OK \u2014 all core fields present":f.join(", ")}
243
- `),o<e.length-1&&await m(3e3+Math.random()*2e3)}}finally{await t.close().catch(()=>{})}}Ot().catch(e=>{console.error("verify-about failed:",e),process.exit(1)});
242
+ `);let{browser:t,page:n}=await Je();try{for(let o=0;o<e.length;o++){let{url:i,name:l}=e[o];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(` [${o+1}/${e.length}] ${l}`),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 r=await ze(n,i);if(!r){console.log(` \u26A0 viewProfile returned null \u2014 selector failed entirely
243
+ `);continue}E("name",r.name),E("title",r.title),E("location",r.location),E("company",r.company),E("connectionDegree",r.connectionDegree),E("connectionsCount",r.connectionsCount),E("mutualConnections",r.mutualConnections),E("hasVerifiedBadge",r.hasVerifiedBadge),E("photoUrl",r.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",r.about,200);let d=[];r.name||d.push("NAME MISSING"),r.title||d.push("TITLE MISSING"),r.location||d.push("LOCATION MISSING"),r.about||d.push("ABOUT MISSING"),console.log(`
244
+ Verdict: ${d.length===0?"OK \u2014 all core fields present":d.join(", ")}
245
+ `),o<e.length-1&&await p(3e3+Math.random()*2e3)}}finally{await t.close().catch(()=>{})}}Vt().catch(e=>{console.error("verify-about failed:",e),process.exit(1)});
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.8";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.9";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()}`);