ilml-plugin-linkedin 1.20.18 → 1.20.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -1
- package/dist/applyQueue.mjs +18 -20
- package/dist/connect.mjs +72 -74
- package/dist/daily.mjs +27 -29
- package/dist/enrichProfiles.mjs +26 -28
- package/dist/funnelRunner.mjs +41 -42
- package/dist/messageBot.mjs +56 -58
- package/dist/run.mjs +28 -30
- package/dist/scout.mjs +42 -44
- package/dist/syncAll.mjs +74 -76
- package/dist/syncConnections.mjs +30 -32
- package/dist/version.mjs +1 -1
- package/dist/viewers.mjs +36 -38
- package/dist/visit.mjs +33 -35
- package/ilml-plugin.json +1 -1
- package/package.json +1 -1
package/dist/syncConnections.mjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
var
|
|
1
|
+
var dt=Object.defineProperty;var W=(e,t)=>{for(var n in t)dt(e,n,{get:t[n],enumerable:!0})};import{pathToFileURL as to}from"url";import b from"fs";import R from"path";var mt="cookies.json";function X(){let e=process.env.ILML_SCOPE_DIR;return e?R.join(e,"plugins-state","linkedin","cookies.json"):mt}function ht(){let e=X(),t=R.dirname(e);return t&&t!=="."&&!b.existsSync(t)&&b.mkdirSync(t,{recursive:!0}),e}function he(e){let t=ht();return b.writeFileSync(t,JSON.stringify(e)),t}function ge(){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 ye(){return b.existsSync(X())}function gt(){let e=process.env.ILML_SCOPE_DIR;return e?R.join(e,"plugins-state","linkedin"):"."}function Se(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function yt(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?Se(t[1]):"default"}function we(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return b.existsSync(t)||b.mkdirSync(t,{recursive:!0}),R.resolve(t);let n=Se(e||yt()),o=R.join(gt(),"chrome-profile",n);return b.existsSync(o)||b.mkdirSync(o,{recursive:!0}),R.resolve(o)}var be=".ilml-seeded";function ve(e){return!b.existsSync(R.join(e,be))}function ke(e){try{b.writeFileSync(R.join(e,be),new Date().toISOString())}catch{}}function Ae(e){let t=0;for(let n of["SingletonLock","SingletonCookie","SingletonSocket"])try{b.rmSync(R.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},St={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 Y(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=St[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 V(e){let t=Math.floor(Math.random()*2001),n=e+t;return new Promise(o=>setTimeout(o,n))}async function wt(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 bt(e){return Ee.test(e||"")}async function vt(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=he(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
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
|
|
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 Ce(e,{readySelector:t,label:n="page",timeout:o=45e3}={}){let r=await wt(e,t,{timeout:o,label:n});if(!r&&bt(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 Ce(e,{readySelector:n,label:o,timeout:r})}catch(l){if(i&&l.code==="SESSION_EXPIRED"){await vt(e,{label:o});try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:s})}catch{}return await Ce(e,{readySelector:n,label:o,timeout:r})}throw l}}import{getPluginConfig as Ct}from"@ilivemylife/graph-sdk";var kt={day:"r86400","24h":"r86400",today:"r86400",week:"r604800","7d":"r604800",month:"r2592000","30d":"r2592000"},$e=e=>/^(1|true|yes|on)$/i.test(String(e??"").trim());function At(e){return String(e??"").split(/[,\s|]+/).map(t=>t.trim()).filter(Boolean)}function _e(e=process.env){let t=(e.JOB_SEARCH_KEYWORDS||"").trim();if(!t)return null;let n=new URLSearchParams;n.set("keywords",t);let o=(e.JOB_SEARCH_LOCATION||"").trim();o&&n.set("location",o);let r=(e.JOB_SEARCH_GEO_ID||"").trim();r&&n.set("geoId",r);let s=parseInt(e.JOB_SEARCH_RADIUS_MILES,10);Number.isFinite(s)&&s>0&&n.set("distance",String(s)),$e(e.JOB_SEARCH_EASY_APPLY)&&n.set("f_AL","true"),$e(e.JOB_SEARCH_IN_NETWORK)&&n.set("f_JIYN","true");let i=At(e.JOB_SEARCH_COMPANY_IDS);i.length&&n.set("f_C",i.join(","));let l=(e.JOB_SEARCH_DATE_POSTED||"").trim().toLowerCase();l&&n.set("f_TPR",kt[l]||l),n.set("origin","JOB_SEARCH_PAGE_JOB_FILTER");let c="https://www.linkedin.com/jobs/search/?"+n.toString(),a=(e.JOB_SEARCH_EXTRA_PARAMS||"").trim().replace(/^[?&]+/,"");return a&&(c+="&"+a),c}var Et=await Ct();for(let[e,t]of Object.entries(Et))process.env[e]===void 0&&(process.env[e]=t);var xe=_e(process.env);xe&&(process.env.LINKEDIN_SEARCH_URL=xe);var $t=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),bo=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),_t=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 xt}from"url";var It=xt(import.meta.url),Rt=S.dirname(S.dirname(It)),T=process.env.DATA_DIR?S.resolve(process.env.DATA_DIR,"collected-profiles"):S.join(Rt,"collected-profiles"),te=S.join(T,"people.json"),Eo=S.join(T,"jobs.json"),$o=S.join(T,"quota.json"),_o=S.join(T,"conversations.json"),xo=S.join(T,"sync-state.json"),Io=S.join(T,"application-questions.json"),Ro=S.join(T,"profile-history"),Ie=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},To=Ie(process.env.CONNECT_MAX_DAILY,20),Do=Ie(process.env.CONNECT_MAX_WEEKLY,100),M=null,Tt=null,Dt=null,Ot=null,jt=null,Nt=null;function Re(){M=null,Tt=null,Dt=null,Ot=null,jt=null,Nt=null}function Te(){y.existsSync(T)||y.mkdirSync(T,{recursive:!0})}function Lt(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 Ft(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||(Te(),M=Ft(te,"people.json")||{},M)}function De(e){Te(),M=e;try{Lt(te,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${S.resolve(te)}`)}}import Ht from"puppeteer";import{addExtra as Wt}from"puppeteer-extra";import Yt from"puppeteer-extra-plugin-stealth";import ne from"fs";import Pt from"path";var Mt={headless:!1,defaultViewport:null,protocolTimeout:3e5},J=new Set,Oe=!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 Ut(){if(Oe)return;Oe=!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 Pt.join(e,".ilml-browser-session.json")}function Fe(e,t={}){try{ne.writeFileSync(oe(e),JSON.stringify({ownerPid:process.pid,startedAt:Date.now(),...t}))}catch{}}function qt(e,t){try{let n=t.wsEndpoint&&t.wsEndpoint();Fe(e,n?{wsEndpoint:n}:{})}catch{}}function Bt(e){let t=Pe(e);t&&t.ownerPid===process.pid&&B(e)}function B(e){try{ne.rmSync(oe(e),{force:!0})}catch{}}function Pe(e){try{return JSON.parse(ne.readFileSync(oe(e),"utf-8"))}catch{return null}}function je(e){if(!e||e===process.pid)return!0;try{return process.kill(e,0),!0}catch(t){return!t||t.code!=="ESRCH"}}function Ne(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 Le(e,t,{probeTimeoutMs:n=4e3}={}){let o=Pe(t);if(!o)return"free";if(!o.wsEndpoint)return o.ownerPid&&o.ownerPid!==process.pid&&je(o.ownerPid)?"live":(B(t),"free");let r=Symbol("timeout"),s=e.connect({browserWSEndpoint:o.wsEndpoint,defaultViewport:null}).catch(()=>null),i=await Ne(s,n,r);if(i===r)return s.then(c=>{if(c)try{c.disconnect()}catch{}}),"live";if(!i)return B(t),"free";if(je(o.ownerPid)){try{i.disconnect()}catch{}return"live"}if(console.log(" (recovered an orphaned automation browser from a previous run \u2014 closing it)"),await Ne(i.close().then(()=>!0).catch(()=>!1),n,!1))return B(t),"free";try{i.disconnect()}catch{}return"live"}function Jt(e,t){e&&(Ut(),J.add(e),e.on("disconnected",()=>{J.delete(e),t&&B(t)}))}async function Me(e,t={}){let n=we(),o={...Mt,...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 Le(e,n)==="live")throw new Error(r);Fe(n);let s;try{s=await e.launch(o)}catch{if(await Le(e,n)==="live")throw new Error(r);Ae(n);try{s=await e.launch(o)}catch(l){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: ${l.message})`)}}return Jt(s,n),qt(n,s),{browser:s,profileDir:n,needsSeed:ve(n)}}async function Ue(e,t){if(!t||!t.needsSeed)return!1;if(!ye())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(...ge()),ke(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var qe=Wt(Ht);qe.use(Yt());async function Be(){let{browser:e,profileDir:t,needsSeed:n}=await Me(qe),o=await e.newPage();return await o.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Ue(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 en}from"url";import"dotenv/config";import{createGraphClient as Vt,resolveToken as Gt}from"@ilivemylife/graph-sdk";import{config as Kt}from"dotenv";Kt();var Je=Gt()||process.env.TOKEN;Je||(console.error(`
|
|
4
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.
|
|
5
5
|
`),console.error(" Easiest way:"),console.error(" 1. npm install -g @ilivemylife/graph-sdk"),console.error(` 2. ilml login your@email.com yourpassword
|
|
6
6
|
`),console.error(` Or add ILML_TOKEN=... to .env
|
|
7
|
-
`),process.exit(1));var
|
|
8
|
-
|
|
9
|
-
${o.join(`
|
|
10
|
-
`)}`;try{await We.addMessage(i,c)}catch(a){console.error(`[runReport] Failed to post end-of-session message: ${a.message}`)}}var en=Zt(import.meta.url),tn=O.dirname(O.dirname(en)),re=process.env.DATA_DIR?O.resolve(process.env.DATA_DIR,"collected-profiles"):O.join(tn,"collected-profiles"),se=O.join(re,"run-log.json");function nn(e,t){let n=JSON.stringify(t,null,2),o=e+".tmp";C.writeFileSync(o,n);for(let r=0;r<3;r++)try{C.renameSync(o,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function Ve(){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 Ge(e){C.existsSync(re)||C.mkdirSync(re,{recursive:!0});try{nn(se,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function Ke(e,t="default"){let n=Ve();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),Ge(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=Ve(),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)}Ge(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";Ye({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 Nn}from"url";var ae={};W(ae,{NAME:()=>rn,VERSION:()=>on,up:()=>ln});import*as E from"fs";import*as z from"path";var on=1,rn="normalize-jobs-and-questions",sn=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],cn=50;function ce(e){return E.existsSync(e)?JSON.parse(E.readFileSync(e,"utf-8")):null}function le(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,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 sn)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<=cn?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:()=>un,VERSION:()=>an,up:()=>dn});import*as $ from"fs";import*as ze from"path";var an=2,un="reset-unread-flags";function fn(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function pn(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 dn(e){let t=ze.join(e,"conversations.json"),n=fn(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}pn(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:()=>hn,VERSION:()=>mn,up:()=>bn});import*as _ from"fs";import*as Qe from"path";var mn=3,hn="recompute-last-message-by",gn=new Set(["draft","confirmed","rejected","needs_review"]);function yn(e){return _.existsSync(e)?JSON.parse(_.readFileSync(e,"utf-8")):null}function Sn(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}}function wn(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!gn.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 bn(e){let t=Qe.join(e,"conversations.json"),n=yn(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=wn(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}Sn(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:()=>kn,VERSION:()=>vn,up:()=>$n});import*as x from"fs";import*as Xe from"path";var vn=4,kn="split-connection-timestamps",An=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function Cn(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 En(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 $n(e){let t=Xe.join(e,"people.json"),n=Cn(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++,An.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}En(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 _n}from"url";var xn=_n(import.meta.url),In=A.dirname(A.dirname(xn)),H=process.env.DATA_DIR?A.resolve(process.env.DATA_DIR,"market-research"):A.join(In,"market-research"),lr=A.join(H,"scouted-jobs.json"),ar=A.join(H,"discovered-people.json"),ur=A.join(H,"visit-log.json"),fr=A.join(H,"companies.json"),pr=A.join(H,"job-decisions.json");function Ze(){Rn=null,Tn=null,Dn=null,On=null,jn=null}var Rn=null;var Tn=null;var Dn=null;var On=null;var jn=null;var Fn=Nn(import.meta.url),Ln=h.dirname(Fn),Pn=h.dirname(h.dirname(Ln));function Mn(e){return e&&(e==="~"?me.homedir():e.startsWith("~/")||e.startsWith("~\\")?h.join(me.homedir(),e.slice(2)):e)}var I=process.env.DATA_DIR?h.resolve(Mn(process.env.DATA_DIR)):Pn,L=h.join(I,"collected-profiles"),P=h.join(I,"market-research"),v=h.join(I,".schema-version"),et=[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 rt(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
7
|
+
`),process.exit(1));var He=Vt({token:Je});function zt(e){if(!e||e<1e3)return`${e||0}ms`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60),o=t%60;return o?`${n}m ${o}s`:`${n}m`}var Qt={apply:"Job apply","apply-queue":"Job apply (queue)",scout:"Job scout",connect:"Connect run",funnel:"Recruiter funnel",messages:"Messages",sync:"Connections sync","sync-all":"Inbox sync",visit:"Profile visits",viewers:"Profile viewers",daily:"Daily run"};function Xt(e){let t=String(e||"").toLowerCase();return/authwall|session expired|not logged in|re-?auth|logged out|sign ?in/.test(t)?"LinkedIn asked to sign in again. Run `ilml linkedin login`, then run this again.":/protocoltimeout|callfunctionon|target closed|session closed|detached|execution context|browser.*disconnected|connection closed/.test(t)?"The browser stopped responding partway through. This is usually temporary \u2014 just run it again.":/err_aborted|err_network|err_connection|err_name_not_resolved|net::/.test(t)?"A page failed to load (network hiccup). Try running it again in a moment.":/navigation timeout|timeout.*exceeded|waiting for selector|waiting for/.test(t)?"A page took too long to load. Try again in a moment.":/invite limit|weekly.*limit|too many|rate.?limit|quota/.test(t)?"You've reached a LinkedIn sending limit for now. Wait a while, then try again.":"Something went wrong partway through. It is safe to run the command again."}function Zt({scriptName:e,mode:t,status:n,summaryLines:o,error:r,duration:s}){let i=n==="error"?"\u2717":n==="quota-reached"?"\u26A0":"\u2713",l=n==="error"?"stopped early":n==="quota-reached"?"daily limit reached":"done",c=Qt[e]||e,a=t&&t!=="default"?` \xB7 ${t}`:"",f=new Date().toISOString().slice(0,16).replace("T"," "),u=s?` \xB7 ${zt(s)}`:"",d=[];d.push(`## ${i} ${c} \u2014 ${l}`),d.push(`_${f}${a}${u}_`),d.push("");for(let h of o)d.push(`- ${h}`);if(n==="error"){d.push(""),d.push(`**What happened:** ${Xt(r)}`);let h=String(r||"").replace(/\s+/g," ").trim();h&&d.push(`_Technical detail: ${h.slice(0,140)}_`)}return d.join(`
|
|
8
|
+
`)}async function We({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 l=Zt({scriptName:e,mode:t,status:n,summaryLines:o,error:r,duration:s});try{await He.addMessage(i,l)}catch(c){console.error(`[runReport] Failed to post end-of-session message: ${c.message}`)}}var tn=en(import.meta.url),nn=O.dirname(O.dirname(tn)),re=process.env.DATA_DIR?O.resolve(process.env.DATA_DIR,"collected-profiles"):O.join(nn,"collected-profiles"),se=O.join(re,"run-log.json");function on(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 Ye(){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 Ve(e){C.existsSync(re)||C.mkdirSync(re,{recursive:!0});try{on(se,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function rn(e,t="default"){let n=Ye();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),Ve(n),{script:e,mode:t,startTime:o.getTime(),runIndex:n.runs.length-1}}function sn(e,t,n=null,o=null){if(!e)return;let r=null;try{let i=Ye(),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)}Ve(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";We({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}`))}}async function Ge(e,t,n,o,r={}){let{rethrow:s=!0}=r,i=rn(e,t),l={},c=null;try{await n(l)}catch(f){c=f}let a=[];try{let f=o?o(l):[];a=(Array.isArray(f)?f:[]).filter(u=>typeof u=="string"&&u.trim())}catch(f){console.error(`[runLog] summarize threw (report still sent): ${f.message}`)}if(a.length===0&&c&&(a=["(crashed before any progress was recorded)"]),c){let f=t&&t!=="default"?` (${t})`:"";console.error(`
|
|
9
|
+
\u2717 ${e}${f} failed: ${c.message||c}`)}try{sn(i,c?"error":"success",{...l,summaryLines:a},c?c.message||String(c):null)}catch(f){console.error(`[runLog] endRun failed: ${f.message}`)}if(c&&s)throw c;return l}import"dotenv/config";import*as p from"fs";import*as de from"os";import*as g from"path";import{fileURLToPath as Pn}from"url";var le={};W(le,{NAME:()=>ln,VERSION:()=>cn,up:()=>fn});import*as E from"fs";import*as z from"path";var cn=1,ln="normalize-jobs-and-questions",an=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],un=50;function ie(e){return E.existsSync(e)?JSON.parse(E.readFileSync(e,"utf-8")):null}function ce(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 fn(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],d=s[f];for(let h of an)u[h]!=null&&d[h]==null&&(d[h]=u[h]);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 d of a.applications){let h=d.jobId||"unknown";f[h]||(f[h]={applications:[]});let k=(d.questions||[]).map(m=>{let w={type:m.type||"input",question:m.question||"",answer:m.answer||""};return m.options&&(m.options.length<=un?w.options=m.options:(w.optionsOmitted=!0,u++)),m.page&&(w.page=m.page),m.wasPreFilled&&(w.wasPreFilled=!0),m.wasRetry&&(w.wasRetry=!0),w});f[h].applications.push({applicationId:d.applicationId,date:d.date,result:d.result||"submitted",formPages:d.formPages||null,duration:d.duration||null,retries:d.retries||0,failedField:d.failedField||null,questionCount:d.questionCount||k.length,questions:k})}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:()=>dn,VERSION:()=>pn,up:()=>gn});import*as $ from"fs";import*as Ke from"path";var pn=2,dn="reset-unread-flags";function mn(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function hn(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 gn(e){let t=Ke.join(e,"conversations.json"),n=mn(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}hn(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:()=>Sn,VERSION:()=>yn,up:()=>An});import*as _ from"fs";import*as ze from"path";var yn=3,Sn="recompute-last-message-by",wn=new Set(["draft","confirmed","rejected","needs_review"]);function bn(e){return _.existsSync(e)?JSON.parse(_.readFileSync(e,"utf-8")):null}function vn(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}}function kn(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!wn.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 An(e){let t=ze.join(e,"conversations.json"),n=bn(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=kn(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}vn(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:()=>En,VERSION:()=>Cn,up:()=>In});import*as x from"fs";import*as Qe from"path";var Cn=4,En="split-connection-timestamps",$n=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function _n(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 xn(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 In(e){let t=Qe.join(e,"people.json"),n=_n(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++,$n.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}xn(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 Rn}from"url";var Tn=Rn(import.meta.url),Dn=A.dirname(A.dirname(Tn)),H=process.env.DATA_DIR?A.resolve(process.env.DATA_DIR,"market-research"):A.join(Dn,"market-research"),fr=A.join(H,"scouted-jobs.json"),pr=A.join(H,"discovered-people.json"),dr=A.join(H,"visit-log.json"),mr=A.join(H,"companies.json"),hr=A.join(H,"job-decisions.json");function Xe(){On=null,jn=null,Nn=null,Ln=null,Fn=null}var On=null;var jn=null;var Nn=null;var Ln=null;var Fn=null;var Mn=Pn(import.meta.url),Un=g.dirname(Mn),qn=g.dirname(g.dirname(Un));function Bn(e){return e&&(e==="~"?de.homedir():e.startsWith("~/")||e.startsWith("~\\")?g.join(de.homedir(),e.slice(2)):e)}var I=process.env.DATA_DIR?g.resolve(Bn(process.env.DATA_DIR)):qn,F=g.join(I,"collected-profiles"),P=g.join(I,"market-research"),v=g.join(I,".schema-version"),Ze=[g.join(F,".schema-version"),g.join(P,".schema-version")],j=4,D=[{version:1,module:le},{version:2,module:ae},{version:3,module:ue},{version:4,module:fe}];(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 ot(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
11
10
|
[FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
|
|
12
11
|
`),process.exit(1));try{p.mkdirSync(I,{recursive:!0})}catch(t){t.code!=="EEXIST"&&(console.error(`
|
|
13
12
|
[FATAL] Cannot create DATA_DIR (${I}): ${t.message}`),console.error(` Fix the path or permissions and try again.
|
|
@@ -15,57 +14,56 @@ ${o.join(`
|
|
|
15
14
|
[FATAL] DATA_DIR (${I}) is not accessible: ${t.message}
|
|
16
15
|
`),process.exit(1)}e.isDirectory()||(console.error(`
|
|
17
16
|
[FATAL] DATA_DIR (${I}) 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.
|
|
18
|
-
`),process.exit(1));for(let t of[
|
|
17
|
+
`),process.exit(1));for(let t of[F,P]){let n;try{n=p.lstatSync(t)}catch(o){if(o.code==="ENOENT")continue;throw o}n.isSymbolicLink()&&(console.error(`
|
|
19
18
|
[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.
|
|
20
|
-
`),process.exit(1))}}var
|
|
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: ${
|
|
19
|
+
`),process.exit(1))}}var L=g.join(I,".migration-lock");function Jn(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return p.writeFileSync(L,e,{flag:"wx"}),!0}catch(o){if(o.code!=="EEXIST")throw o}let t;try{t=JSON.parse(p.readFileSync(L,"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
|
+
[FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${t.pid}`),console.error(` Started at: ${t.startedAt||"(unknown)"}`),console.error(` Lock file: ${L}
|
|
22
21
|
`),console.error(" Wait for it to finish, or if you're sure it's not actually running,"),console.error(` delete the lock file manually and re-run.
|
|
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=
|
|
22
|
+
`),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=L+".tmp";try{return p.writeFileSync(n,e),p.renameSync(n,L),!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(L,"utf-8")).pid!==process.pid)return;p.unlinkSync(L)}catch{}}var et=!1;function Hn(){if(et)return;et=!0;let e=()=>{try{me()}catch{}process.exit(1)};for(let t of["SIGINT","SIGTERM","SIGHUP"])try{process.on(t,e)}catch{}}function Wn(){if(p.existsSync(v))return;let e=[],t=[];for(let s of Ze)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(`
|
|
24
23
|
[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(`
|
|
25
24
|
Repair the file(s) (likely just an integer 'version' field \u2014 see another working DATA_DIR`),console.error(` or default to {"version":1,"migrations":[]} if you're sure you're on schema v1) and try again.
|
|
26
25
|
`),process.exit(1)}if(e.length===0)return;let n=e.map(s=>s.schema.version);if(new Set(n).size>1){console.error(`
|
|
27
26
|
[FATAL] Legacy .schema-version files disagree:`);for(let s of e)console.error(` ${s.file}: v${s.schema.version}`);console.error(" This means a previous migration crashed between writing the two files."),console.error(` Reconcile manually (delete the wrong one, keep the right one), then re-run.
|
|
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
|
|
27
|
+
`),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 Ze)if(p.existsSync(s))try{p.unlinkSync(s)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${v}`)}function Yn(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 tt(){if(Wn(),!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
28
|
[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=
|
|
29
|
+
`),process.exit(1)}let t=Yn(e);return t===null&&(console.error(`
|
|
31
30
|
[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
|
|
31
|
+
`),process.exit(1)),t}function rt(e){try{p.chmodSync(e,384)}catch{}}function Vn(e){if(ot(),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)),rt(t),p.renameSync(t,v)}catch(n){try{p.unlinkSync(t)}catch{}throw n}}function nt(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(g.join(e,l)).isFile()}catch{return!1}}),r=0,s=0,i=[];for(let l of o){let c=g.join(e,l),a=g.join(e,l+n);if(p.existsSync(a)){s++;continue}try{it(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 ${g.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 ${g.basename(e)}/ (${n})${l}`)}}var pe=!1;async function st(){if(pe)return;ot(),Xn();let t=tt().version;if(t===j){pe=!0;return}Hn(),Jn(),process.on("exit",me),t>j&&(console.error(`
|
|
33
32
|
[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.
|
|
34
33
|
`),console.error(" Options:"),console.error(" A) Re-install the newer plugin version that produced this schema, then"),console.error(" (if you really want to downgrade) run 'rollback-data --confirm' first,"),console.error(" then re-install the older plugin version."),console.error(` B) Manually restore your data from the *.pre-vNNN.backup files matching v${j}.
|
|
35
34
|
`),process.exit(1)),console.log(`
|
|
36
|
-
\u{1F4E6} Schema migration: v${t} \u2192 v${j}`);let n=
|
|
35
|
+
\u{1F4E6} Schema migration: v${t} \u2192 v${j}`);let n=Zn();if(!n.ok){console.error(`
|
|
37
36
|
[FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let r of n.broken)console.error(` ${r.dir}/${r.file}: ${r.err}`);console.error(`
|
|
38
37
|
Migration ABORTED. No backups taken, no files modified.`),console.error(" Repair the file(s) above (restore from your own backup, or fix manually)"),console.error(` and try again. To inspect: 'ilml linkedin migrate-status'.
|
|
39
38
|
`),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{
|
|
39
|
+
Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,i=`.pre-${s}.backup`;try{nt(F,r.version),nt(P,r.version)}catch(c){console.error(`
|
|
41
40
|
[FATAL] Pre-migration backup failed for ${s}: ${c.message}`),console.error(" Migration NOT applied. Repair the underlying issue (disk space, permissions, locked files)"),console.error(` and re-run the plugin command.
|
|
42
|
-
`),process.exit(1)}let l=r.module;try{await l.up(
|
|
43
|
-
[FATAL] Migration ${s} failed: ${c.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let a=
|
|
41
|
+
`),process.exit(1)}let l=r.module;try{await l.up(F,P)}catch(c){console.error(`
|
|
42
|
+
[FATAL] Migration ${s} failed: ${c.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let a=eo(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.
|
|
44
43
|
`)):(console.error(` [!] Auto-rollback INCOMPLETE: ${a.error}`),console.error(` Manual recovery: copy *${i} files back over the originals.
|
|
45
44
|
`))}catch(a){console.error(` [!] Auto-rollback CRASHED while restoring: ${a.message}`),console.error(` Manual recovery: copy *${i} files back over the originals.
|
|
46
|
-
`)}process.exit(1)}try{let c=new Date().toISOString(),a={version:r.version,name:l.NAME||s,appliedAt:c},f=
|
|
45
|
+
`)}process.exit(1)}try{let c=new Date().toISOString(),a={version:r.version,name:l.NAME||s,appliedAt:c},f=tt();f.version=r.version,f.migratedAt=c,f.migrations=f.migrations||[],f.migrations.push(a),Vn(f)}catch(c){console.error(`
|
|
47
46
|
[FATAL] Migration ${s} applied successfully but schema version file could NOT be updated: ${c.message}`),console.error(` Your data is in the v${r.version} state but .schema-version still shows v${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.
|
|
48
|
-
`),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{
|
|
47
|
+
`),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{Re()}catch{}try{Xe()}catch{}pe=!0,me(),console.log(`
|
|
49
48
|
\u2713 Schema is now at v${j}
|
|
50
|
-
`)}var
|
|
49
|
+
`)}var Gn=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Kn(e){let t=e.toLowerCase();return Gn.some(n=>n.test(t))}var zn=6e4;function Qn(){let e=Date.now(),t=[];for(let n of[I,F,P]){if(!p.existsSync(n))continue;let o;try{o=p.readdirSync(n)}catch{continue}for(let r of o){if(!Kn(r))continue;let s=g.join(n,r);try{let i=p.statSync(s);if(!i.isFile()||e-i.mtimeMs<zn)continue;t.push({dir:n,file:r,fullPath:s})}catch{}}}return t}function Xn({verbose:e=!1}={}){let t=Qn();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: ${g.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 Zn(){let e=[];for(let t of[F,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=g.join(t,o);try{Q(r)}catch(s){e.push({dir:g.basename(t),file:o,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function eo(e){let t=[],n=[];for(let s of[F,P]){if(!p.existsSync(s))continue;let i=p.readdirSync(s).filter(l=>l.endsWith(e));for(let l of i){let c=g.join(s,l),a=l.slice(0,-e.length),f=g.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(`${g.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{it(s,i),o++}catch(a){r.push(`${g.basename(c)}/${l}: ${a.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:o}:{ok:!0,restored:o}}function it(e,t){let n=t+".tmp";try{p.copyFileSync(e,n),rt(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 no(){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 oo(){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(`
|
|
51
50
|
=== People Database: ${n} entries ===
|
|
52
51
|
`),console.log("By connection status:");for(let[s,i]of Object.entries(o).sort((l,c)=>c[1]-l[1]))console.log(` ${s.padEnd(30)} ${i}`);console.log(`
|
|
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
|
|
54
|
-
`)[0]||"").trim();for(let[i,l]of Object.entries(o)){let c=null;for(let
|
|
55
|
-
`).map(
|
|
52
|
+
By source:`);for(let[s,i]of Object.entries(r).sort((l,c)=>c[1]-l[1]))console.log(` ${s.padEnd(30)} ${i}`);console.log()}async function ro(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 lt(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
|
+
`)[0]||"").trim();for(let[i,l]of Object.entries(o)){let c=null;for(let m of l){let w=s(m);!w||m.querySelector("img")||(!c||w.length<s(c).length)&&(c=m)}let a=s(c)||null,f=c||l[0];for(let m=0;m<10&&f?.parentElement;m++){f=f.parentElement;let w=f.innerText||"";if((w.includes("Connected on")||w.includes("Message"))&&(w.match(/Connected on/g)||[]).length<=1)break}let u=(f?.innerText||"").split(`
|
|
54
|
+
`).map(m=>m.trim()).filter(Boolean),d=null,h=null,k=u.indexOf(a);if(k>=0&&k+1<u.length){let m=u[k+1];!m.startsWith("Connected on")&&m!=="Message"&&(d=m)}for(let m of u)if(m.startsWith("Connected on")){h=m;break}r.push({profileUrl:i,name:a,title:d,time:h})}return r})}async function at(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 so(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 lt(e),u=0;for(let h of f)h.profileUrl&&(s.has(h.profileUrl)||(s.set(h.profileUrl,h),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&&(pt(Array.from(s.values()),!1),o&&console.log(` \u{1F4BE} Saved progress (${s.size} connections)`)),s.size>=n){console.log(`
|
|
56
55
|
Reached --max=${n}, stopping.`);break}if(u===0){if(l++,l>=c){console.log(`
|
|
57
|
-
${c} rounds with no new cards \u2014 end of list.`);break}}else l=0;let
|
|
58
|
-
`),Array.from(s.values())}async function
|
|
59
|
-
Reached --max=${n}, stopping.`);break}if(u===0&&
|
|
56
|
+
${c} rounds with no new cards \u2014 end of list.`);break}}else l=0;let d=await at(e);o&&d==="clicked"&&console.log(' \u2192 Clicked "Load more"'),await V(2e3)}return o||process.stdout.write(`
|
|
57
|
+
`),Array.from(s.values())}async function io(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 lt(e),u=0,d=0;for(let m of f)m.profileUrl&&(i.has(m.profileUrl)||(i.set(m.profileUrl,m),s.has(m.profileUrl)?d++:u++));let h=Array.from(i.values()).filter(m=>!s.has(m.profileUrl)).length;if(o?console.log(` Round #${l}: ${u} new, ${d} known | New total: ${h}`):process.stdout.write(`\r New connections: ${h} (page #${l})`),h>=n){console.log(`
|
|
58
|
+
Reached --max=${n}, stopping.`);break}if(u===0&&d>0){if(c++,c>=a){console.log(`
|
|
60
59
|
${a} consecutive pages of known connections \u2014 caught up.`);break}}else if(u>0)c=0;else if(c++,c>=a){console.log(`
|
|
61
|
-
${a} empty rounds \u2014 end of list.`);break}let k=await
|
|
62
|
-
`),Array.from(i.values())}var
|
|
60
|
+
${a} empty rounds \u2014 end of list.`);break}let k=await at(e);o&&k==="clicked"&&console.log(' \u2192 Clicked "Load more"'),await V(2e3)}return o||process.stdout.write(`
|
|
61
|
+
`),Array.from(i.values())}var ut=new Set(["pending","sent_with_note","sent_without_note","sent_without_note_upsell"]);function ct(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function ft(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 co(e,t){let n=[],o=ft(t);for(let r of e){if(!r.profileUrl)continue;let s=o.get(G(r.profileUrl)),i=s?t[s]:void 0;i&&ut.has(i.connectionStatus)&&n.push({...r,previousStatus:i.connectionStatus})}return n}function pt(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=ft(n),l=new Map;for(let[c,a]of Object.entries(n)){if(!ut.has(a.connectionStatus))continue;let f=ct(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 d=c.time?Y(c.time.replace(/^Connected\s+on\s+/i,"")):null;u.connectedAt=d||o,u.connectionDate=(d||o).slice(0,10),u.lastUpdated=o,s.updatedToConnected++}else if(s.alreadyConnected++,c.time&&(!u.connectedAt||!u.connectionDate)){let d=Y(c.time.replace(/^Connected\s+on\s+/i,""));d&&(u.connectedAt||(u.connectedAt=d),u.connectionDate||(u.connectionDate=d.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 d={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},h=ct(c.name),k=h?l.get(h)||[]:[];k.length&&(d.possibleDuplicateOf=[...k],s.flaggedDuplicates++,s.flagged.push({name:c.name,candidates:k.length})),n[c.profileUrl]=d,a&&i.set(a,c.profileUrl),s.newPeople++}}return t||De(n),s}function lo(e,t,n,o,r,s){if(console.log(`
|
|
63
62
|
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`),console.log(` Sync Connections Summary (${s})`),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),r&&console.log(` LinkedIn header: ${r.toLocaleString()}`),console.log(` Connections scraped: ${e.length}`),console.log(` New people added: ${n.newPeople}`),console.log(` Updated to connected: ${n.updatedToConnected}`),console.log(` Already connected: ${n.alreadyConnected}`),t.length>0){console.log(`
|
|
64
63
|
Newly accepted (${t.length}):`);for(let i of t)console.log(` \u2713 ${i.name||"Unknown"} (was: ${i.previousStatus})`)}if(n.flaggedDuplicates>0){console.log(`
|
|
65
64
|
\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(`
|
|
66
65
|
[DRY RUN \u2014 nothing written to DB]`),console.log(`\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
|
|
67
|
-
`)}async function
|
|
66
|
+
`)}async function ao(){let e=no();if(await st(),e.list){oo();return}let t=e.full?"full":"incremental";console.log(`
|
|
68
67
|
\u{1F504} Sync LinkedIn Connections (${t})
|
|
69
|
-
`),e.dryRun&&console.log(" [DRY RUN mode]"),e.max!==1/0&&console.log(` Max: ${e.max}`)
|
|
70
|
-
Extracted ${i.length} connections.`);let l=q(),c=
|
|
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===Xn(process.argv[1]).href&&io();export{pt as buildSlugIndex,ro as detectNewlyAccepted,lt as normName,dt as syncToDatabaseBatch};
|
|
68
|
+
`),e.dryRun&&console.log(" [DRY RUN mode]"),e.max!==1/0&&console.log(` Max: ${e.max}`),await Ge("sync",t,async n=>{let{browser:o,page:r}=await Be();try{let s=await ro(r),i=e.full?await so(r,{max:e.max,verbose:e.verbose,dryRun:e.dryRun}):await io(r,{max:e.max,verbose:e.verbose});console.log(`
|
|
69
|
+
Extracted ${i.length} connections.`);let l=q(),c=co(i,l),a=pt(i,e.dryRun);lo(i,c,a,e.dryRun,s,t),n.scraped=i.length,n.newPeople=a.newPeople,n.updatedToConnected=a.updatedToConnected}finally{await o.close().catch(()=>{})}},n=>[`${n.scraped??0} connections scraped, ${n.newPeople??0} new, ${n.updatedToConnected??0} newly connected`],{rethrow:!1})}process.argv[1]&&import.meta.url===to(process.argv[1]).href&&ao();export{ft as buildSlugIndex,co as detectNewlyAccepted,ct as normName,pt as syncToDatabaseBatch};
|
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.
|
|
1
|
+
import{readFileSync as e}from"fs";import{fileURLToPath as r}from"url";function i(){return"1.20.19";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()}`);
|