ilml-plugin-linkedin 1.12.0 → 1.13.1
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 +36 -0
- package/dist/applyQueue.mjs +4 -4
- package/dist/enrichProfile.mjs +267 -19
- package/dist/enrichProfiles.mjs +282 -48
- package/dist/funnelRunner.mjs +281 -47
- package/dist/profileHistory.mjs +4 -4
- package/dist/readPost.mjs +76 -0
- package/dist/run.mjs +285 -51
- package/dist/scout.mjs +7 -7
- package/dist/syncAll.mjs +342 -90
- package/dist/verifyAbout.mjs +244 -10
- package/dist/visit.mjs +281 -47
- package/ilml-plugin.json +185 -28
- package/package.json +1 -1
package/dist/scout.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
var vt=Object.defineProperty;var de=(e,t)=>{for(var o in t)vt(e,o,{get:t[o],enumerable:!0})};import xt from"puppeteer";import{addExtra as Ct}from"puppeteer-extra";import It from"puppeteer-extra-plugin-stealth";async function R(e){let t=Math.floor(Math.random()*2001),o=e+t;return new Promise(r=>setTimeout(r,o))}import{getPluginConfig as kt}from"@ilivemylife/graph-sdk";var jt=await kt();for(let[e,t]of Object.entries(jt))process.env[e]===void 0&&(process.env[e]=t);var _t=process.env.LINKEDIN_NAME,B=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Ko=Object.freeze(new Set([B.DRAFT,B.CONFIRMED,B.NEEDS_REVIEW])),Tt=Object.freeze(new Set([B.DRAFT,B.CONFIRMED,B.REJECTED,B.NEEDS_REVIEW]));import Ie from"fs";import $t from"path";var Et="cookies.json";function At(){let e=process.env.ILML_SCOPE_DIR;return e?$t.join(e,"plugins-state","linkedin","cookies.json"):Et}function Re(){let e=At();if(!Ie.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=Ie.readFileSync(e,"utf-8")}catch(r){throw new Error(`Failed to read cookies at ${e}: ${r.message}. Run: ilml linkedin login`)}let o;try{o=JSON.parse(t)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(o)||o.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return o}var De=Ct(xt);De.use(It());async function Oe(){let e=await De.launch({headless:!1,defaultViewport:null,protocolTimeout:3e5}),t=async()=>{console.log(`
|
|
2
2
|
Closing browser...`);try{await e.close()}catch{}process.exit(0)};process.on("SIGINT",t),process.on("SIGTERM",t);let o=await e.newPage();await o.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})});try{let r=Re();await o.setCookie(...r),console.log(" Browser launched, cookies loaded.")}catch(r){console.error(`
|
|
3
3
|
[!] ${r.message}
|
|
4
|
-
`),await e.close(),process.exit(1)}return{browser:e,page:o}}async function Ne(e){let t=[".jobs-search-results-list",".scaffold-layout__list-container",".jobs-search-two-pane__results","div.jobs-search-results-list"];return await e.evaluate(async r=>{let n=null,s=null;for(let h of r)if(n=document.querySelector(h),n){s=h;break}if(!n){let h=document.querySelector("li.scaffold-layout__list-item");if(h){let u=h.parentElement;for(;u&&u!==document.body;){if(u.scrollHeight>u.clientHeight){n=u,s="parent of li.scaffold-layout__list-item";break}u=u.parentElement}}}if(!n)return{found:!1,triedSelectors:r};let i=n.scrollTop,c=300,l=300,f=50,d=0;for(;d<f&&(n.scrollBy(0,c),await new Promise(h=>setTimeout(h,l)),!(n.scrollTop+n.clientHeight>=n.scrollHeight));)d++;return{found:!0,usedSelector:s,initialScroll:i,finalScroll:n.scrollTop,scrollHeight:n.scrollHeight,attempts:d}},t)}async function Le(e,{easyApplyOnly:t=!0}={}){let o=await e.evaluate(()=>{let r=document.querySelectorAll("li.scaffold-layout__list-item");return Array.from(r).map(n=>{let i=(n.querySelector(".job-card-list__footer-wrapper")?.innerText??"").includes("Easy Apply"),c=n.querySelector("a.job-card-container__link");if(c){let l=c.getAttribute("href").split("?")[0],f=n.querySelector(".job-card-list__title--link")?.getAttribute("aria-label")?.replace(/ with verification$/,""),d=n.querySelector(".artdeco-entity-lockup__subtitle")?.innerText.trim(),h=n.querySelector(".artdeco-entity-lockup__caption")?.innerText.trim(),u=n.querySelector(".artdeco-entity-lockup__metadata")?.innerText.trim();return{id:l,isEasyApply:i,applyType:i?"easy-apply":"external",dataId:c.getAttribute("data-control-id"),href:`https://linkedin.com${l}`,jobTitle:f,companyName:d,location:h,salary:u||null,jobLink:i?c.href:null}}return{isEasyApply:!1}})});return t?o.filter(r=>r.isEasyApply&&r.href):o.filter(r=>r.href)}async function Fe(e){let t=await e.evaluate(()=>{let o=document.querySelector('button[aria-label="View next page"]')||document.querySelector(".jobs-search-pagination__button--next");if(o&&!o.disabled){let r=document.querySelector(".jobs-search-pagination__page-state")?.textContent?.trim();return o.click(),{success:!0,pageState:r}}return{success:!1,reason:"No next page button found"}});return console.log(" Pagination:",t.success?t.pageState:t.reason),t.success&&await R(2e3),t.success}async function Pe(e,t){let o=e.url();if(o.includes("/jobs/"))return!1;if(o.includes("/login")||o.includes("/authwall")||o.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: npm run login");console.log(` Off-track: ${o.slice(0,80)}`),console.log(" Navigating back to job search..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await R(3e3);let n=e.url();if(!n.includes("/jobs/"))throw new Error(`Could not return to job search. Current URL: ${n.slice(0,80)}`);return console.log(" Recovered to job search page"),!0}async function Me(e){return e.evaluate(()=>{let t=document.querySelector(".scaffold-layout__detail")||document.querySelector(".jobs-search__job-details")||document.querySelector(".jobs-details")||document.body,o=t.querySelector(".hirer-card__hirer-information");if(o){let i=o.querySelector('a[href*="/in/"]'),c=o.querySelector(".jobs-poster__name")||o.querySelector("strong")||o.querySelector('[class*="name"]');if(i)return{name:c?.textContent?.trim()||i.textContent?.trim(),profileUrl:i.href?.split("?")[0],source:"hiring_team"}}let r=t.querySelector(".jobs-poster__name");if(r){let i=r.closest('a[href*="/in/"]')||r.parentElement?.querySelector('a[href*="/in/"]')||r.parentElement?.parentElement?.querySelector('a[href*="/in/"]');if(i)return{name:r.textContent?.trim(),profileUrl:i.href?.split("?")[0],source:"poster_name"}}let n=t.querySelector(".job-details-people-who-can-help__section--two-pane")||t.querySelector('[class*="people-who-can-help"]');if(n){let i=n.querySelector('a[href*="/in/"]');if(i)return{name:(n.querySelector(".jobs-poster__name")||n.querySelector("strong"))?.textContent?.trim()||i.textContent?.trim(),profileUrl:i.href?.split("?")[0],source:"people_section"}}let s=t.querySelectorAll('a[href*="/in/"]');for(let i of s){let c=i.textContent?.trim();if(c&&c.length>3&&!["View","Connect","Follow","Message","Apply","Save"].includes(c))return{name:c,profileUrl:i.href?.split("?")[0],source:"details_link"}}return null})}async function qe(e){return e.evaluate(()=>{let t=document.querySelector(".scaffold-layout__detail")||document.querySelector(".jobs-search__job-details")||document.querySelector(".jobs-details")||document.body,r=(t.querySelector(".jobs-description__content")||t.querySelector(".jobs-box__html-content")||t.querySelector(".jobs-description"))?.innerText?.trim()||"",n={},s=t.querySelectorAll(".jobs-unified-top-card__job-insight, li.job-criteria__item");for(let J of s){let pe=J.querySelector(".job-criteria__subheader")?.textContent?.trim(),Ce=J.querySelector(".job-criteria__text")?.textContent?.trim();pe&&Ce&&(n[pe.toLowerCase()]=Ce)}let i=["Java","Python","JavaScript","TypeScript","React","Angular","Vue","Node.js","C#",".NET","C\\+\\+","Go","Rust","Scala","Kotlin","AWS","Azure","GCP","Docker","Kubernetes","Terraform","SQL","PostgreSQL","MongoDB","Redis","Kafka","RabbitMQ","Spring","Django","Flask","Express","Next.js","CI/CD","Jenkins","GitHub Actions","GraphQL","REST","Microservices","Machine Learning","AI","Data Engineering","Spark","Hadoop","Snowflake","Databricks","Airflow","iOS","Android","React Native","Flutter","Agile","Scrum","DevOps","SRE"],c=[];for(let J of i)new RegExp("\\b"+J.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b","i").test(r)&&c.push(J.replace(/\\\+/g,"+"));let f=t.querySelector('.jobs-company__box, [class*="jobs-company"], [class*="company-card"]')?.innerText?.trim()?.slice(0,1e3)||null,h=t.querySelector('a.jobs-apply-button[href], a[data-tracking-control-name="public_jobs_apply-link-offsite_sign-up"]')?.getAttribute("href")||null,u=t.querySelector(".job-details-jobs-unified-top-card__company-name, .jobs-unified-top-card__company-name"),p=u?.innerText?.trim()||null,S=(u?.querySelector('a[href*="/company/"]')||t.querySelector('a[href*="/company/"]'))?.getAttribute("href")?.split("?")[0]||null,y=t.querySelector(".job-details-jobs-unified-top-card__primary-description-container")?.innerText?.trim()||"",F=y.match(/(\d+\s+(?:hour|day|week|month)s?\s+ago|Reposted|Just now)/i)?.[0]||null,P=y.match(/(\d[\d,]*)\s+applicant/i),ae=P?parseInt(P[1].replace(/,/g,"")):null,ue=t.querySelectorAll(".job-details-jobs-unified-top-card__job-insight"),oe=Array.from(ue).map(J=>J.innerText?.trim()?.replace(/\s+/g," ")),fe=oe.join(" ").match(/([\d,]+-[\d,]+\s+employees|[\d,]+\+?\s+employees)/i)?.[0]||null,M=oe.join(" ")+" "+y,bt=/\bremote\b/i.test(M)?"remote":/\bhybrid\b/i.test(M)?"hybrid":/\bon-?site\b/i.test(M)?"onsite":null,wt=/\bcontract\b/i.test(M)?"contract":/\bfull-?time\b/i.test(M)?"full-time":/\bpart-?time\b/i.test(M)?"part-time":/\bfreelance\b/i.test(M)?"freelance":/\btemporary\b/i.test(M)?"temporary":null,Ae=t.querySelector(".job-details-jobs-unified-top-card__job-title, .jobs-unified-top-card__job-title, h2.t-24")?.innerText?.trim()||"",re=t.querySelector(".job-details-jobs-unified-top-card__primary-description-container, .jobs-unified-top-card__subtitle-primary-grouping")?.innerText?.trim()||"",C=(Ae+" "+r+" "+re).toLowerCase(),I=Ae.toLowerCase(),m=[];/\bremote\b/.test(C)&&m.push("remote"),/\bhybrid\b/.test(C)&&m.push("hybrid"),/\bon-?site\b|\bin-?office\b/.test(C)&&m.push("onsite"),(m.length===0||!m.includes("remote")&&!m.includes("hybrid")&&!m.includes("onsite"))&&/remote/i.test(re)&&m.push("remote"),/\b(manager|director|vp|vice president|head of|chief|cto|cio|lead.*team|managing)\b/i.test(I)&&m.push("managerial"),/\b(architect|principal|staff|distinguished)\b/i.test(I)&&m.push("senior-ic"),/\b(developer|engineer|programmer|analyst)\b/i.test(I)&&!m.includes("managerial")&&m.push("ic"),/\b(junior|jr\.?|entry)\b/i.test(I)?m.push("junior"):/\b(senior|sr\.?)\b/i.test(I)?m.push("senior"):/\b(staff|principal|distinguished)\b/i.test(I)?m.push("staff+"):/\b(director|vp|chief|cto|cio)\b/i.test(I)?m.push("executive"):/\b(lead|team lead)\b/i.test(I)&&m.push("lead"),/\b(backend|back-end|server-side|api)\b/i.test(C)&&m.push("backend"),/\b(frontend|front-end|ui|ux)\b/i.test(C)&&m.push("frontend"),/\b(full.?stack|fullstack)\b/i.test(C)&&m.push("fullstack"),/\b(devops|sre|infrastructure|platform)\b/i.test(C)&&m.push("devops"),/\b(data engineer|data science|machine learning|ml engineer)\b/i.test(C)&&m.push("data"),/\b(mobile|ios|android|react native|flutter)\b/i.test(C)&&m.push("mobile"),/\b(architect)\b/i.test(I)&&m.push("architect"),/\b(consultant|consulting)\b/i.test(I)&&m.push("consultant");let xe=(n["employment type"]||"").toLowerCase();return(/contract|freelance|temporary/i.test(xe)||/\bcontract\b/i.test(C))&&m.push("contract"),/full.?time|permanent/i.test(xe)&&m.push("permanent"),/\bcanada\b|toronto|vancouver|montreal|ontario|british columbia|quebec|alberta|calgary|ottawa/i.test(re)&&m.push("canada"),/\bunited states\b|\busa\b|new york|california|texas|seattle|san francisco/i.test(re)&&m.push("usa"),(t.querySelector(".jobs-unified-top-card__job-insight--highlight, .compensation__salary")?.innerText?.trim()||""||/\$[\d,]+/.test(r))&&m.push("has-salary"),{description:r.substring(0,5e3),externalApplyUrl:h,companyName:p,companyUrl:S?S.startsWith("/")?"https://www.linkedin.com"+S:S:null,aboutCompany:f,seniority:n["seniority level"]||null,employmentType:n["employment type"]||null,industries:n.industries||null,jobFunction:n["job function"]||null,postedTime:F,applicantCount:ae,companySize:fe,workplaceType:bt,contractType:wt,techStack:[...new Set(c)],jobTags:[...new Set(m)]}})}import"dotenv/config";import*as T from"fs";import*as _ from"path";import{fileURLToPath as Rt}from"url";var Dt=Rt(import.meta.url),Ot=_.dirname(_.dirname(Dt)),V=process.env.DATA_DIR?_.resolve(process.env.DATA_DIR,"market-research"):_.join(Ot,"market-research"),Ue=_.join(V,"scouted-jobs.json"),Je=_.join(V,"discovered-people.json"),Nt=_.join(V,"visit-log.json"),Be=_.join(V,"companies.json"),yn=_.join(V,"job-decisions.json");function me(){T.existsSync(V)||T.mkdirSync(V,{recursive:!0})}function he(e,t){let o=JSON.stringify(t,null,2),r=e+".tmp";T.writeFileSync(r,o);for(let n=0;n<3;n++)try{T.renameSync(r,e);return}catch(s){if(n<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function se(e){try{if(T.existsSync(e))return JSON.parse(T.readFileSync(e,"utf-8"))}catch{}return null}function He(){z=null,Lt=null,Q=null,X=null,H=null}var z=null;function ie(){return z||(z=se(Ue)||{},z)}function Ve(e,t){if(!e)return;me();let o=ie(),r=new Date().toISOString().slice(0,10);if(o[e]){for(let[n,s]of Object.entries(t))s!=null&&(o[e][n]=s);o[e].lastSeen=r}else o[e]={...t,scoutedAt:r,lastSeen:r};try{he(Ue,o)}catch(n){console.error(`[!] Failed to save scouted-jobs.json: ${n.message}`)}}var Lt=null;var Q=null;function We(){return Q||(Q=se(Je)||{},Q)}function Ge(e,t){if(!e)return;me();let o=We(),r=new Date().toISOString().slice(0,10);if(o[e]){let n=o[e];t.name&&(n.name=t.name),t.title&&(n.title=t.title),t.company&&(n.company=t.company),t.location&&(n.location=t.location),t.role&&(n.role=t.role),t.isConnected!=null&&(n.isConnected=t.isConnected),t.jobId&&(n.jobIds||(n.jobIds=[]),n.jobIds.includes(t.jobId)||n.jobIds.push(t.jobId)),n.lastSeen=r,n.seenCount=(n.seenCount||1)+1}else o[e]={name:t.name||null,title:t.title||null,company:t.company||null,location:t.location||null,role:t.role||null,source:t.source||"scout",isConnected:t.isConnected||!1,discoveredAt:r,lastSeen:r,seenCount:1,jobIds:t.jobId?[t.jobId]:[]};try{he(Je,o)}catch(n){console.error(`[!] Failed to save discovered-people.json: ${n.message}`)}}var X=null;function Ft(){return X||(X=se(Be)||{},X)}function Ye(e,t){if(!e)return;me();let o=Ft(),r=new Date().toISOString().slice(0,10);if(o[e]){let n=o[e];t.name&&(n.name=t.name),t.about&&(n.about=t.about),t.size&&(n.size=t.size),t.industries&&(n.industries=t.industries),t.jobId&&(n.jobIds||(n.jobIds=[]),n.jobIds.includes(t.jobId)||n.jobIds.push(t.jobId)),t.recruiterUrl&&(n.recruiterUrls||(n.recruiterUrls=[]),n.recruiterUrls.includes(t.recruiterUrl)||n.recruiterUrls.push(t.recruiterUrl)),n.lastSeen=r,n.jobCount=n.jobIds?.length||0}else o[e]={name:t.name||null,about:t.about||null,size:t.size||null,industries:t.industries||null,discoveredAt:r,lastSeen:r,jobIds:t.jobId?[t.jobId]:[],recruiterUrls:t.recruiterUrl?[t.recruiterUrl]:[],jobCount:t.jobId?1:0};try{he(Be,o)}catch(n){console.error(`[!] Failed to save companies.json: ${n.message}`)}}var H=null;function Pt(){return H||(H=se(Nt)||{visits:[]},Array.isArray(H.visits)||(H.visits=[]),H)}function Ke(){let e=ie(),t=We(),o=Object.values(e),r=Object.values(t),n={};for(let u of o)u.company&&(n[u.company]=(n[u.company]||0)+1);let s=Object.entries(n).sort((u,p)=>p[1]-u[1]).slice(0,5).map(([u,p])=>`${u} (${p})`),i={};for(let u of o)for(let p of u.techStack||[])i[p]=(i[p]||0)+1;let c=Object.entries(i).sort((u,p)=>p[1]-u[1]).slice(0,8).map(([u,p])=>`${u} (${p})`),l=Pt(),f=new Date().toISOString().slice(0,10),d=l.visits.filter(u=>u.date.startsWith(f)).length,h=new Set(l.visits.map(u=>u.profileUrl)).size;return{totalJobs:o.length,totalRecruiters:r.length,topCompanies:s,topTech:c,totalVisited:h,todayVisited:d,lastScoutDate:o.length>0?o.sort((u,p)=>(p.scoutedAt||"").localeCompare(u.scoutedAt||""))[0]?.scoutedAt:null}}import"dotenv/config";import*as b from"fs";import*as v from"path";import{fileURLToPath as Mt}from"url";var qt=Mt(import.meta.url),Ut=v.dirname(v.dirname(qt)),N=process.env.DATA_DIR?v.resolve(process.env.DATA_DIR,"collected-profiles"):v.join(Ut,"collected-profiles"),Jt=v.join(N,"people.json"),Bt=v.join(N,"jobs.json"),kn=v.join(N,"quota.json"),jn=v.join(N,"conversations.json"),_n=v.join(N,"sync-state.json"),Tn=v.join(N,"application-questions.json"),$n=v.join(N,"profile-history");var Z=null,ee=null,Ht=null,Vt=null,Wt=null,Gt=null;function ze(){Z=null,ee=null,Ht=null,Vt=null,Wt=null,Gt=null}function Qe(){b.existsSync(N)||b.mkdirSync(N,{recursive:!0})}function Xe(e,t){if(!b.existsSync(e))return null;try{let o=JSON.parse(b.readFileSync(e,"utf-8"));try{b.copyFileSync(e,e+".backup")}catch{}return o}catch(o){console.error(`[!] ${t} is corrupted: ${o.message}`),console.error(` File: ${v.resolve(e)}`);let r=e+".backup";if(b.existsSync(r))try{let n=JSON.parse(b.readFileSync(r,"utf-8"));console.error(` Restored from ${r}`);try{b.copyFileSync(r,e)}catch{}return n}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{b.copyFileSync(e,e+".corrupted")}catch{}return null}}function Ze(){return Z||(Qe(),Z=Xe(Jt,"people.json")||{},Z)}function et(){return ee||(Qe(),ee=Xe(Bt,"jobs.json")||{},ee)}import"dotenv/config";import*as $ from"fs";import*as q from"path";import{fileURLToPath as Zt}from"url";import"dotenv/config";import{createGraphClient as Yt,resolveToken as Kt}from"@ilivemylife/graph-sdk";import{config as zt}from"dotenv";zt();var tt=Kt()||process.env.TOKEN;tt||(console.error(`
|
|
4
|
+
`),await e.close(),process.exit(1)}return{browser:e,page:o}}async function Ne(e){let t=[".jobs-search-results-list",".scaffold-layout__list-container",".jobs-search-two-pane__results","div.jobs-search-results-list"];return await e.evaluate(async r=>{let n=null,s=null;for(let h of r)if(n=document.querySelector(h),n){s=h;break}if(!n){let h=document.querySelector("li.scaffold-layout__list-item");if(h){let u=h.parentElement;for(;u&&u!==document.body;){if(u.scrollHeight>u.clientHeight){n=u,s="parent of li.scaffold-layout__list-item";break}u=u.parentElement}}}if(!n)return{found:!1,triedSelectors:r};let i=n.scrollTop,c=300,l=300,f=50,d=0;for(;d<f&&(n.scrollBy(0,c),await new Promise(h=>setTimeout(h,l)),!(n.scrollTop+n.clientHeight>=n.scrollHeight));)d++;return{found:!0,usedSelector:s,initialScroll:i,finalScroll:n.scrollTop,scrollHeight:n.scrollHeight,attempts:d}},t)}async function Fe(e,{easyApplyOnly:t=!0}={}){let o=await e.evaluate(()=>{let r=document.querySelectorAll("li.scaffold-layout__list-item");return Array.from(r).map(n=>{let i=(n.querySelector(".job-card-list__footer-wrapper")?.innerText??"").includes("Easy Apply"),c=n.querySelector("a.job-card-container__link");if(c){let l=c.getAttribute("href").split("?")[0],f=n.querySelector(".job-card-list__title--link")?.getAttribute("aria-label")?.replace(/ with verification$/,""),d=n.querySelector(".artdeco-entity-lockup__subtitle")?.innerText.trim(),h=n.querySelector(".artdeco-entity-lockup__caption")?.innerText.trim(),u=n.querySelector(".artdeco-entity-lockup__metadata")?.innerText.trim();return{id:l,isEasyApply:i,applyType:i?"easy-apply":"external",dataId:c.getAttribute("data-control-id"),href:`https://linkedin.com${l}`,jobTitle:f,companyName:d,location:h,salary:u||null,jobLink:i?c.href:null}}return{isEasyApply:!1}})});return t?o.filter(r=>r.isEasyApply&&r.href):o.filter(r=>r.href)}async function Le(e){let t=await e.evaluate(()=>{let o=document.querySelector('button[aria-label="View next page"]')||document.querySelector(".jobs-search-pagination__button--next");if(o&&!o.disabled){let r=document.querySelector(".jobs-search-pagination__page-state")?.textContent?.trim();return o.click(),{success:!0,pageState:r}}return{success:!1,reason:"No next page button found"}});return console.log(" Pagination:",t.success?t.pageState:t.reason),t.success&&await R(2e3),t.success}async function Pe(e,t){let o=e.url();if(o.includes("/jobs/"))return!1;if(o.includes("/login")||o.includes("/authwall")||o.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: npm run login");console.log(` Off-track: ${o.slice(0,80)}`),console.log(" Navigating back to job search..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await R(3e3);let n=e.url();if(!n.includes("/jobs/"))throw new Error(`Could not return to job search. Current URL: ${n.slice(0,80)}`);return console.log(" Recovered to job search page"),!0}async function Me(e){return e.evaluate(()=>{let t=document.querySelector(".scaffold-layout__detail")||document.querySelector(".jobs-search__job-details")||document.querySelector(".jobs-details")||document.body,o=t.querySelector(".hirer-card__hirer-information");if(o){let i=o.querySelector('a[href*="/in/"]'),c=o.querySelector(".jobs-poster__name")||o.querySelector("strong")||o.querySelector('[class*="name"]');if(i)return{name:c?.textContent?.trim()||i.textContent?.trim(),profileUrl:i.href?.split("?")[0],source:"hiring_team"}}let r=t.querySelector(".jobs-poster__name");if(r){let i=r.closest('a[href*="/in/"]')||r.parentElement?.querySelector('a[href*="/in/"]')||r.parentElement?.parentElement?.querySelector('a[href*="/in/"]');if(i)return{name:r.textContent?.trim(),profileUrl:i.href?.split("?")[0],source:"poster_name"}}let n=t.querySelector(".job-details-people-who-can-help__section--two-pane")||t.querySelector('[class*="people-who-can-help"]');if(n){let i=n.querySelector('a[href*="/in/"]');if(i)return{name:(n.querySelector(".jobs-poster__name")||n.querySelector("strong"))?.textContent?.trim()||i.textContent?.trim(),profileUrl:i.href?.split("?")[0],source:"people_section"}}let s=t.querySelectorAll('a[href*="/in/"]');for(let i of s){let c=i.textContent?.trim();if(c&&c.length>3&&!["View","Connect","Follow","Message","Apply","Save"].includes(c))return{name:c,profileUrl:i.href?.split("?")[0],source:"details_link"}}return null})}async function qe(e){return e.evaluate(()=>{let t=document.querySelector(".scaffold-layout__detail")||document.querySelector(".jobs-search__job-details")||document.querySelector(".jobs-details")||document.body,r=(t.querySelector(".jobs-description__content")||t.querySelector(".jobs-box__html-content")||t.querySelector(".jobs-description"))?.innerText?.trim()||"",n={},s=t.querySelectorAll(".jobs-unified-top-card__job-insight, li.job-criteria__item");for(let J of s){let pe=J.querySelector(".job-criteria__subheader")?.textContent?.trim(),Ce=J.querySelector(".job-criteria__text")?.textContent?.trim();pe&&Ce&&(n[pe.toLowerCase()]=Ce)}let i=["Java","Python","JavaScript","TypeScript","React","Angular","Vue","Node.js","C#",".NET","C\\+\\+","Go","Rust","Scala","Kotlin","AWS","Azure","GCP","Docker","Kubernetes","Terraform","SQL","PostgreSQL","MongoDB","Redis","Kafka","RabbitMQ","Spring","Django","Flask","Express","Next.js","CI/CD","Jenkins","GitHub Actions","GraphQL","REST","Microservices","Machine Learning","AI","Data Engineering","Spark","Hadoop","Snowflake","Databricks","Airflow","iOS","Android","React Native","Flutter","Agile","Scrum","DevOps","SRE"],c=[];for(let J of i)new RegExp("\\b"+J.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b","i").test(r)&&c.push(J.replace(/\\\+/g,"+"));let f=t.querySelector('.jobs-company__box, [class*="jobs-company"], [class*="company-card"]')?.innerText?.trim()?.slice(0,1e3)||null,h=t.querySelector('a.jobs-apply-button[href], a[data-tracking-control-name="public_jobs_apply-link-offsite_sign-up"]')?.getAttribute("href")||null,u=t.querySelector(".job-details-jobs-unified-top-card__company-name, .jobs-unified-top-card__company-name"),p=u?.innerText?.trim()||null,S=(u?.querySelector('a[href*="/company/"]')||t.querySelector('a[href*="/company/"]'))?.getAttribute("href")?.split("?")[0]||null,y=t.querySelector(".job-details-jobs-unified-top-card__primary-description-container")?.innerText?.trim()||"",L=y.match(/(\d+\s+(?:hour|day|week|month)s?\s+ago|Reposted|Just now)/i)?.[0]||null,P=y.match(/(\d[\d,]*)\s+applicant/i),ae=P?parseInt(P[1].replace(/,/g,"")):null,ue=t.querySelectorAll(".job-details-jobs-unified-top-card__job-insight"),oe=Array.from(ue).map(J=>J.innerText?.trim()?.replace(/\s+/g," ")),fe=oe.join(" ").match(/([\d,]+-[\d,]+\s+employees|[\d,]+\+?\s+employees)/i)?.[0]||null,M=oe.join(" ")+" "+y,bt=/\bremote\b/i.test(M)?"remote":/\bhybrid\b/i.test(M)?"hybrid":/\bon-?site\b/i.test(M)?"onsite":null,wt=/\bcontract\b/i.test(M)?"contract":/\bfull-?time\b/i.test(M)?"full-time":/\bpart-?time\b/i.test(M)?"part-time":/\bfreelance\b/i.test(M)?"freelance":/\btemporary\b/i.test(M)?"temporary":null,Ae=t.querySelector(".job-details-jobs-unified-top-card__job-title, .jobs-unified-top-card__job-title, h2.t-24")?.innerText?.trim()||"",re=t.querySelector(".job-details-jobs-unified-top-card__primary-description-container, .jobs-unified-top-card__subtitle-primary-grouping")?.innerText?.trim()||"",C=(Ae+" "+r+" "+re).toLowerCase(),I=Ae.toLowerCase(),m=[];/\bremote\b/.test(C)&&m.push("remote"),/\bhybrid\b/.test(C)&&m.push("hybrid"),/\bon-?site\b|\bin-?office\b/.test(C)&&m.push("onsite"),(m.length===0||!m.includes("remote")&&!m.includes("hybrid")&&!m.includes("onsite"))&&/remote/i.test(re)&&m.push("remote"),/\b(manager|director|vp|vice president|head of|chief|cto|cio|lead.*team|managing)\b/i.test(I)&&m.push("managerial"),/\b(architect|principal|staff|distinguished)\b/i.test(I)&&m.push("senior-ic"),/\b(developer|engineer|programmer|analyst)\b/i.test(I)&&!m.includes("managerial")&&m.push("ic"),/\b(junior|jr\.?|entry)\b/i.test(I)?m.push("junior"):/\b(senior|sr\.?)\b/i.test(I)?m.push("senior"):/\b(staff|principal|distinguished)\b/i.test(I)?m.push("staff+"):/\b(director|vp|chief|cto|cio)\b/i.test(I)?m.push("executive"):/\b(lead|team lead)\b/i.test(I)&&m.push("lead"),/\b(backend|back-end|server-side|api)\b/i.test(C)&&m.push("backend"),/\b(frontend|front-end|ui|ux)\b/i.test(C)&&m.push("frontend"),/\b(full.?stack|fullstack)\b/i.test(C)&&m.push("fullstack"),/\b(devops|sre|infrastructure|platform)\b/i.test(C)&&m.push("devops"),/\b(data engineer|data science|machine learning|ml engineer)\b/i.test(C)&&m.push("data"),/\b(mobile|ios|android|react native|flutter)\b/i.test(C)&&m.push("mobile"),/\b(architect)\b/i.test(I)&&m.push("architect"),/\b(consultant|consulting)\b/i.test(I)&&m.push("consultant");let xe=(n["employment type"]||"").toLowerCase();return(/contract|freelance|temporary/i.test(xe)||/\bcontract\b/i.test(C))&&m.push("contract"),/full.?time|permanent/i.test(xe)&&m.push("permanent"),/\bcanada\b|toronto|vancouver|montreal|ontario|british columbia|quebec|alberta|calgary|ottawa/i.test(re)&&m.push("canada"),/\bunited states\b|\busa\b|new york|california|texas|seattle|san francisco/i.test(re)&&m.push("usa"),(t.querySelector(".jobs-unified-top-card__job-insight--highlight, .compensation__salary")?.innerText?.trim()||""||/\$[\d,]+/.test(r))&&m.push("has-salary"),{description:r.substring(0,5e3),externalApplyUrl:h,companyName:p,companyUrl:S?S.startsWith("/")?"https://www.linkedin.com"+S:S:null,aboutCompany:f,seniority:n["seniority level"]||null,employmentType:n["employment type"]||null,industries:n.industries||null,jobFunction:n["job function"]||null,postedTime:L,applicantCount:ae,companySize:fe,workplaceType:bt,contractType:wt,techStack:[...new Set(c)],jobTags:[...new Set(m)]}})}import"dotenv/config";import*as T from"fs";import*as _ from"path";import{fileURLToPath as Rt}from"url";var Dt=Rt(import.meta.url),Ot=_.dirname(_.dirname(Dt)),V=process.env.DATA_DIR?_.resolve(process.env.DATA_DIR,"market-research"):_.join(Ot,"market-research"),Ue=_.join(V,"scouted-jobs.json"),Je=_.join(V,"discovered-people.json"),Nt=_.join(V,"visit-log.json"),Be=_.join(V,"companies.json"),yn=_.join(V,"job-decisions.json");function me(){T.existsSync(V)||T.mkdirSync(V,{recursive:!0})}function he(e,t){let o=JSON.stringify(t,null,2),r=e+".tmp";T.writeFileSync(r,o);for(let n=0;n<3;n++)try{T.renameSync(r,e);return}catch(s){if(n<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function se(e){try{if(T.existsSync(e))return JSON.parse(T.readFileSync(e,"utf-8"))}catch{}return null}function He(){z=null,Ft=null,Q=null,X=null,H=null}var z=null;function ie(){return z||(z=se(Ue)||{},z)}function Ve(e,t){if(!e)return;me();let o=ie(),r=new Date().toISOString().slice(0,10);if(o[e]){for(let[n,s]of Object.entries(t))s!=null&&(o[e][n]=s);o[e].lastSeen=r}else o[e]={...t,scoutedAt:r,lastSeen:r};try{he(Ue,o)}catch(n){console.error(`[!] Failed to save scouted-jobs.json: ${n.message}`)}}var Ft=null;var Q=null;function We(){return Q||(Q=se(Je)||{},Q)}function Ge(e,t){if(!e)return;me();let o=We(),r=new Date().toISOString().slice(0,10);if(o[e]){let n=o[e];t.name&&(n.name=t.name),t.title&&(n.title=t.title),t.company&&(n.company=t.company),t.location&&(n.location=t.location),t.role&&(n.role=t.role),t.isConnected!=null&&(n.isConnected=t.isConnected),t.jobId&&(n.jobIds||(n.jobIds=[]),n.jobIds.includes(t.jobId)||n.jobIds.push(t.jobId)),n.lastSeen=r,n.seenCount=(n.seenCount||1)+1}else o[e]={name:t.name||null,title:t.title||null,company:t.company||null,location:t.location||null,role:t.role||null,source:t.source||"scout",isConnected:t.isConnected||!1,discoveredAt:r,lastSeen:r,seenCount:1,jobIds:t.jobId?[t.jobId]:[]};try{he(Je,o)}catch(n){console.error(`[!] Failed to save discovered-people.json: ${n.message}`)}}var X=null;function Lt(){return X||(X=se(Be)||{},X)}function Ye(e,t){if(!e)return;me();let o=Lt(),r=new Date().toISOString().slice(0,10);if(o[e]){let n=o[e];t.name&&(n.name=t.name),t.about&&(n.about=t.about),t.size&&(n.size=t.size),t.industries&&(n.industries=t.industries),t.jobId&&(n.jobIds||(n.jobIds=[]),n.jobIds.includes(t.jobId)||n.jobIds.push(t.jobId)),t.recruiterUrl&&(n.recruiterUrls||(n.recruiterUrls=[]),n.recruiterUrls.includes(t.recruiterUrl)||n.recruiterUrls.push(t.recruiterUrl)),n.lastSeen=r,n.jobCount=n.jobIds?.length||0}else o[e]={name:t.name||null,about:t.about||null,size:t.size||null,industries:t.industries||null,discoveredAt:r,lastSeen:r,jobIds:t.jobId?[t.jobId]:[],recruiterUrls:t.recruiterUrl?[t.recruiterUrl]:[],jobCount:t.jobId?1:0};try{he(Be,o)}catch(n){console.error(`[!] Failed to save companies.json: ${n.message}`)}}var H=null;function Pt(){return H||(H=se(Nt)||{visits:[]},Array.isArray(H.visits)||(H.visits=[]),H)}function Ke(){let e=ie(),t=We(),o=Object.values(e),r=Object.values(t),n={};for(let u of o)u.company&&(n[u.company]=(n[u.company]||0)+1);let s=Object.entries(n).sort((u,p)=>p[1]-u[1]).slice(0,5).map(([u,p])=>`${u} (${p})`),i={};for(let u of o)for(let p of u.techStack||[])i[p]=(i[p]||0)+1;let c=Object.entries(i).sort((u,p)=>p[1]-u[1]).slice(0,8).map(([u,p])=>`${u} (${p})`),l=Pt(),f=new Date().toISOString().slice(0,10),d=l.visits.filter(u=>u.date.startsWith(f)).length,h=new Set(l.visits.map(u=>u.profileUrl)).size;return{totalJobs:o.length,totalRecruiters:r.length,topCompanies:s,topTech:c,totalVisited:h,todayVisited:d,lastScoutDate:o.length>0?o.sort((u,p)=>(p.scoutedAt||"").localeCompare(u.scoutedAt||""))[0]?.scoutedAt:null}}import"dotenv/config";import*as b from"fs";import*as v from"path";import{fileURLToPath as Mt}from"url";var qt=Mt(import.meta.url),Ut=v.dirname(v.dirname(qt)),N=process.env.DATA_DIR?v.resolve(process.env.DATA_DIR,"collected-profiles"):v.join(Ut,"collected-profiles"),Jt=v.join(N,"people.json"),Bt=v.join(N,"jobs.json"),kn=v.join(N,"quota.json"),jn=v.join(N,"conversations.json"),_n=v.join(N,"sync-state.json"),Tn=v.join(N,"application-questions.json"),$n=v.join(N,"profile-history");var Z=null,ee=null,Ht=null,Vt=null,Wt=null,Gt=null;function ze(){Z=null,ee=null,Ht=null,Vt=null,Wt=null,Gt=null}function Qe(){b.existsSync(N)||b.mkdirSync(N,{recursive:!0})}function Xe(e,t){if(!b.existsSync(e))return null;try{let o=JSON.parse(b.readFileSync(e,"utf-8"));try{b.copyFileSync(e,e+".backup")}catch{}return o}catch(o){console.error(`[!] ${t} is corrupted: ${o.message}`),console.error(` File: ${v.resolve(e)}`);let r=e+".backup";if(b.existsSync(r))try{let n=JSON.parse(b.readFileSync(r,"utf-8"));console.error(` Restored from ${r}`);try{b.copyFileSync(r,e)}catch{}return n}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{b.copyFileSync(e,e+".corrupted")}catch{}return null}}function Ze(){return Z||(Qe(),Z=Xe(Jt,"people.json")||{},Z)}function et(){return ee||(Qe(),ee=Xe(Bt,"jobs.json")||{},ee)}import"dotenv/config";import*as $ from"fs";import*as q from"path";import{fileURLToPath as Zt}from"url";import"dotenv/config";import{createGraphClient as Yt,resolveToken as Kt}from"@ilivemylife/graph-sdk";import{config as zt}from"dotenv";zt();var tt=Kt()||process.env.TOKEN;tt||(console.error(`
|
|
5
5
|
[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.
|
|
6
6
|
`),console.error(" Easiest way:"),console.error(" 1. npm install -g @ilivemylife/graph-sdk"),console.error(` 2. ilml login your@email.com yourpassword
|
|
7
7
|
`),console.error(` Or add ILML_TOKEN=... to .env
|
|
8
8
|
`),process.exit(1));var ot=Yt({token:tt});function Qt(e){if(!e||e<1e3)return`${e||0}ms`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let o=Math.floor(t/60),r=t%60;return r?`${o}m ${r}s`:`${o}m`}function Xt({scriptName:e,mode:t,status:o,error:r,duration:n}){let s=o==="error"?"\u2717":o==="quota-reached"?"\u26A0":"\u2713",i=new Date().toISOString().slice(0,16).replace("T"," "),c=n?` ${Qt(n)}`:"",l=o==="error"?`error${r?`: ${String(r).slice(0,80)}`:""}`:o==="quota-reached"?"daily quota reached":"done",f=t&&t!=="default"?` (${t})`:"";return`${s} ${e}${f} \u2014 ${l} \u2014 ${i}${c}`}async function nt({scriptName:e,mode:t,status:o,summaryLines:r,error:n,duration:s}){let i=process.env.NODE_RUN_REPORTS;if(!i||!Array.isArray(r)||r.length===0)return;let l=`**${Xt({scriptName:e,mode:t,status:o,error:n,duration:s})}**
|
|
9
9
|
|
|
10
10
|
${r.join(`
|
|
11
|
-
`)}`;try{await ot.addMessage(i,l)}catch(f){console.error(`[runReport] Failed to post end-of-session message: ${f.message}`)}}var eo=Zt(import.meta.url),to=q.dirname(q.dirname(eo)),ge=process.env.DATA_DIR?q.resolve(process.env.DATA_DIR,"collected-profiles"):q.join(to,"collected-profiles"),ye=q.join(ge,"run-log.json");function oo(e,t){let o=JSON.stringify(t,null,2),r=e+".tmp";$.writeFileSync(r,o);for(let n=0;n<3;n++)try{$.renameSync(r,e);return}catch(s){if(n<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function rt(){try{if(!$.existsSync(ye))return{runs:[]};let e=JSON.parse($.readFileSync(ye,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function st(e){$.existsSync(ge)||$.mkdirSync(ge,{recursive:!0});try{oo(ye,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function it(e,t="default"){let o=rt();for(let i of o.runs)i.status==="running"&&(i.status="interrupted",i.result="interrupted",i.timestamp&&(i.duration=Date.now()-new Date(i.timestamp).getTime()));let r=new Date,n={timestamp:r.toISOString(),script:e,mode:t,status:"running",result:null,duration:null,stats:null,error:null};o.runs.push(n);let s=Date.now()-30*24*60*60*1e3;return o.runs=o.runs.filter(i=>new Date(i.timestamp).getTime()>s),st(o),{script:e,mode:t,startTime:r.getTime(),runIndex:o.runs.length-1}}function Se(e,t,o=null,r=null){if(!e)return;let n=null;try{let i=rt(),c=i.runs[e.runIndex];if(c&&c.status==="running"&&c.script===e.script)c.status=t,c.result=t,c.duration=Date.now()-e.startTime,c.stats=o,c.error=r,n=c.duration;else{let l=i.runs.find(f=>f.script===e.script&&f.status==="running"&&f.timestamp===new Date(e.startTime).toISOString());l&&(l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=o,l.error=r,n=l.duration)}st(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let s=o&&Array.isArray(o.summaryLines)?o.summaryLines:null;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS){let i=t==="error"?"error":o&&o.dailyLimitHit?"quota-reached":"done";nt({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:r,duration:n??Date.now()-e.startTime}).catch(c=>console.error(`[runLog] postRunReport failed: ${c.message}`))}}import"dotenv/config";import*as a from"fs";import*as Te from"os";import*as g from"path";import{fileURLToPath as vo}from"url";var ve={};de(ve,{NAME:()=>ro,VERSION:()=>no,up:()=>co});import*as E from"fs";import*as ce from"path";var no=1,ro="normalize-jobs-and-questions",so=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],io=50;function be(e){return E.existsSync(e)?JSON.parse(E.readFileSync(e,"utf-8")):null}function we(e,t){let o=JSON.stringify(t,null,2),r=e+".tmp";try{E.writeFileSync(r,o)}catch(n){try{E.unlinkSync(r)}catch{}throw n}try{E.renameSync(r,e)}catch(n){try{E.unlinkSync(r)}catch{}if(n.code==="EPERM"||n.code==="EBUSY"){let s=new Error(`File locked: ${e} (${n.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=n.code,s}throw n}}async function co(e,t){let o=ce.join(e,"jobs.json"),r=ce.join(t,"scouted-jobs.json"),n=ce.join(e,"application-questions.json"),s=be(o)||{},i=be(r)||{},c=0,l=[];for(let d of Object.keys(s)){if(!i[d])continue;let h=i[d],u=s[d];for(let p of so)h[p]!=null&&u[p]==null&&(u[p]=h[p]);l.push(d),c++}c>0?(we(o,s),console.log(` Phase 1: Merged ${c} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let f=be(n);if(f&&Array.isArray(f.applications)){let d={},h=0;for(let u of f.applications){let p=u.jobId||"unknown";d[p]||(d[p]={applications:[]});let j=(u.questions||[]).map(S=>{let w={type:S.type||"input",question:S.question||"",answer:S.answer||""};return S.options&&(S.options.length<=io?w.options=S.options:(w.optionsOmitted=!0,h++)),S.page&&(w.page=S.page),S.wasPreFilled&&(w.wasPreFilled=!0),S.wasRetry&&(w.wasRetry=!0),w});d[p].applications.push({applicationId:u.applicationId,date:u.date,result:u.result||"submitted",formPages:u.formPages||null,duration:u.duration||null,retries:u.retries||0,failedField:u.failedField||null,questionCount:u.questionCount||j.length,questions:j})}we(n,d),console.log(` Phase 2: Rekeyed ${f.applications.length} applications by jobId (${Object.keys(d).length} unique jobs)`),h>0&&console.log(` Phase 2: Stripped bloated options from ${h} questions`)}else f&&!f.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(l.length>0){for(let d of l)delete i[d];we(r,i),console.log(` Phase 3: Removed ${l.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var ke={};de(ke,{NAME:()=>ao,VERSION:()=>lo,up:()=>po});import*as A from"fs";import*as ct from"path";var lo=2,ao="reset-unread-flags";function uo(e){return A.existsSync(e)?JSON.parse(A.readFileSync(e,"utf-8")):null}function fo(e,t){let o=JSON.stringify(t,null,2),r=e+".tmp";try{A.writeFileSync(r,o)}catch(n){try{A.unlinkSync(r)}catch{}throw n}try{A.renameSync(r,e)}catch(n){try{A.unlinkSync(r)}catch{}if(n.code==="EPERM"||n.code==="EBUSY"){let s=new Error(`File locked: ${e} (${n.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=n.code,s}throw n}}async function po(e){let t=ct.join(e,"conversations.json"),o=uo(t);if(!o){console.log(" conversations.json not found \u2014 nothing to reset.");return}let r=0;for(let n of Object.keys(o))o[n].unread===!0&&(o[n].unread=!1,r++);if(r===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}fo(t,o),console.log(` Reset unread=false on ${r} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var je={};de(je,{NAME:()=>ho,VERSION:()=>mo,up:()=>wo});import*as x from"fs";import*as lt from"path";var mo=3,ho="recompute-last-message-by",go=new Set(["draft","confirmed","rejected","needs_review"]);function yo(e){return x.existsSync(e)?JSON.parse(x.readFileSync(e,"utf-8")):null}function So(e,t){let o=JSON.stringify(t,null,2),r=e+".tmp";try{x.writeFileSync(r,o)}catch(n){try{x.unlinkSync(r)}catch{}throw n}try{x.renameSync(r,e)}catch(n){try{x.unlinkSync(r)}catch{}if(n.code==="EPERM"||n.code==="EBUSY"){let s=new Error(`File locked: ${e} (${n.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=n.code,s}throw n}}function bo(e,t){if(!e||e.length===0)return"them";let o=e.filter(s=>!go.has(s.status));if(o.length===0)return"them";let r=o.map(s=>({m:s,t:Date.parse(s.time)})).filter(s=>Number.isFinite(s.t)).sort((s,i)=>i.t-s.t).map(s=>s.m),n=r.length>0?r:[...o].reverse();for(let s of n){let i=s.sender;if(i===t)return"me";if(i!=="Unknown"&&i!=="")return"them"}return"them"}async function wo(e){let t=lt.join(e,"conversations.json"),o=yo(t);if(!o){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let r=process.env.LINKEDIN_NAME;if(!r||typeof r!="string"||!r.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 n=0,s=0,i=0;for(let c of Object.keys(o)){let l=o[c];if(!l||typeof l!="object")continue;Object.prototype.hasOwnProperty.call(l,"_cardSynced")&&(delete l._cardSynced,s++);let f=Array.isArray(l.messages)?l.messages:[],d=bo(f,r),h=d==="me"?"awaiting_reply":"unanswered_by_us";l.lastMessageBy!==d&&i++,l.lastMessageBy=d,l.conversationStatus=h,n++}if(n===0){console.log(" No conversations to recompute.");return}So(t,o),console.log(` Recomputed lastMessageBy + conversationStatus on ${n} 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 ko=vo(import.meta.url),jo=g.dirname(ko),_o=g.dirname(g.dirname(jo));function To(e){return e&&(e==="~"?Te.homedir():e.startsWith("~/")||e.startsWith("~\\")?g.join(Te.homedir(),e.slice(2)):e)}var D=process.env.DATA_DIR?g.resolve(To(process.env.DATA_DIR)):_o,G=g.join(D,"collected-profiles"),Y=g.join(D,"market-research"),k=g.join(D,".schema-version"),at=[g.join(G,".schema-version"),g.join(Y,".schema-version")],U=3,
|
|
11
|
+
`)}`;try{await ot.addMessage(i,l)}catch(f){console.error(`[runReport] Failed to post end-of-session message: ${f.message}`)}}var eo=Zt(import.meta.url),to=q.dirname(q.dirname(eo)),ge=process.env.DATA_DIR?q.resolve(process.env.DATA_DIR,"collected-profiles"):q.join(to,"collected-profiles"),ye=q.join(ge,"run-log.json");function oo(e,t){let o=JSON.stringify(t,null,2),r=e+".tmp";$.writeFileSync(r,o);for(let n=0;n<3;n++)try{$.renameSync(r,e);return}catch(s){if(n<2&&(s.code==="EPERM"||s.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw s}}function rt(){try{if(!$.existsSync(ye))return{runs:[]};let e=JSON.parse($.readFileSync(ye,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function st(e){$.existsSync(ge)||$.mkdirSync(ge,{recursive:!0});try{oo(ye,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function it(e,t="default"){let o=rt();for(let i of o.runs)i.status==="running"&&(i.status="interrupted",i.result="interrupted",i.timestamp&&(i.duration=Date.now()-new Date(i.timestamp).getTime()));let r=new Date,n={timestamp:r.toISOString(),script:e,mode:t,status:"running",result:null,duration:null,stats:null,error:null};o.runs.push(n);let s=Date.now()-30*24*60*60*1e3;return o.runs=o.runs.filter(i=>new Date(i.timestamp).getTime()>s),st(o),{script:e,mode:t,startTime:r.getTime(),runIndex:o.runs.length-1}}function Se(e,t,o=null,r=null){if(!e)return;let n=null;try{let i=rt(),c=i.runs[e.runIndex];if(c&&c.status==="running"&&c.script===e.script)c.status=t,c.result=t,c.duration=Date.now()-e.startTime,c.stats=o,c.error=r,n=c.duration;else{let l=i.runs.find(f=>f.script===e.script&&f.status==="running"&&f.timestamp===new Date(e.startTime).toISOString());l&&(l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=o,l.error=r,n=l.duration)}st(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let s=o&&Array.isArray(o.summaryLines)?o.summaryLines:null;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS){let i=t==="error"?"error":o&&o.dailyLimitHit?"quota-reached":"done";nt({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:r,duration:n??Date.now()-e.startTime}).catch(c=>console.error(`[runLog] postRunReport failed: ${c.message}`))}}import"dotenv/config";import*as a from"fs";import*as Te from"os";import*as g from"path";import{fileURLToPath as vo}from"url";var ve={};de(ve,{NAME:()=>ro,VERSION:()=>no,up:()=>co});import*as E from"fs";import*as ce from"path";var no=1,ro="normalize-jobs-and-questions",so=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],io=50;function be(e){return E.existsSync(e)?JSON.parse(E.readFileSync(e,"utf-8")):null}function we(e,t){let o=JSON.stringify(t,null,2),r=e+".tmp";try{E.writeFileSync(r,o)}catch(n){try{E.unlinkSync(r)}catch{}throw n}try{E.renameSync(r,e)}catch(n){try{E.unlinkSync(r)}catch{}if(n.code==="EPERM"||n.code==="EBUSY"){let s=new Error(`File locked: ${e} (${n.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=n.code,s}throw n}}async function co(e,t){let o=ce.join(e,"jobs.json"),r=ce.join(t,"scouted-jobs.json"),n=ce.join(e,"application-questions.json"),s=be(o)||{},i=be(r)||{},c=0,l=[];for(let d of Object.keys(s)){if(!i[d])continue;let h=i[d],u=s[d];for(let p of so)h[p]!=null&&u[p]==null&&(u[p]=h[p]);l.push(d),c++}c>0?(we(o,s),console.log(` Phase 1: Merged ${c} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let f=be(n);if(f&&Array.isArray(f.applications)){let d={},h=0;for(let u of f.applications){let p=u.jobId||"unknown";d[p]||(d[p]={applications:[]});let j=(u.questions||[]).map(S=>{let w={type:S.type||"input",question:S.question||"",answer:S.answer||""};return S.options&&(S.options.length<=io?w.options=S.options:(w.optionsOmitted=!0,h++)),S.page&&(w.page=S.page),S.wasPreFilled&&(w.wasPreFilled=!0),S.wasRetry&&(w.wasRetry=!0),w});d[p].applications.push({applicationId:u.applicationId,date:u.date,result:u.result||"submitted",formPages:u.formPages||null,duration:u.duration||null,retries:u.retries||0,failedField:u.failedField||null,questionCount:u.questionCount||j.length,questions:j})}we(n,d),console.log(` Phase 2: Rekeyed ${f.applications.length} applications by jobId (${Object.keys(d).length} unique jobs)`),h>0&&console.log(` Phase 2: Stripped bloated options from ${h} questions`)}else f&&!f.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(l.length>0){for(let d of l)delete i[d];we(r,i),console.log(` Phase 3: Removed ${l.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var ke={};de(ke,{NAME:()=>ao,VERSION:()=>lo,up:()=>po});import*as A from"fs";import*as ct from"path";var lo=2,ao="reset-unread-flags";function uo(e){return A.existsSync(e)?JSON.parse(A.readFileSync(e,"utf-8")):null}function fo(e,t){let o=JSON.stringify(t,null,2),r=e+".tmp";try{A.writeFileSync(r,o)}catch(n){try{A.unlinkSync(r)}catch{}throw n}try{A.renameSync(r,e)}catch(n){try{A.unlinkSync(r)}catch{}if(n.code==="EPERM"||n.code==="EBUSY"){let s=new Error(`File locked: ${e} (${n.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=n.code,s}throw n}}async function po(e){let t=ct.join(e,"conversations.json"),o=uo(t);if(!o){console.log(" conversations.json not found \u2014 nothing to reset.");return}let r=0;for(let n of Object.keys(o))o[n].unread===!0&&(o[n].unread=!1,r++);if(r===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}fo(t,o),console.log(` Reset unread=false on ${r} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var je={};de(je,{NAME:()=>ho,VERSION:()=>mo,up:()=>wo});import*as x from"fs";import*as lt from"path";var mo=3,ho="recompute-last-message-by",go=new Set(["draft","confirmed","rejected","needs_review"]);function yo(e){return x.existsSync(e)?JSON.parse(x.readFileSync(e,"utf-8")):null}function So(e,t){let o=JSON.stringify(t,null,2),r=e+".tmp";try{x.writeFileSync(r,o)}catch(n){try{x.unlinkSync(r)}catch{}throw n}try{x.renameSync(r,e)}catch(n){try{x.unlinkSync(r)}catch{}if(n.code==="EPERM"||n.code==="EBUSY"){let s=new Error(`File locked: ${e} (${n.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw s.code=n.code,s}throw n}}function bo(e,t){if(!e||e.length===0)return"them";let o=e.filter(s=>!go.has(s.status));if(o.length===0)return"them";let r=o.map(s=>({m:s,t:Date.parse(s.time)})).filter(s=>Number.isFinite(s.t)).sort((s,i)=>i.t-s.t).map(s=>s.m),n=r.length>0?r:[...o].reverse();for(let s of n){let i=s.sender;if(i===t)return"me";if(i!=="Unknown"&&i!=="")return"them"}return"them"}async function wo(e){let t=lt.join(e,"conversations.json"),o=yo(t);if(!o){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let r=process.env.LINKEDIN_NAME;if(!r||typeof r!="string"||!r.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 n=0,s=0,i=0;for(let c of Object.keys(o)){let l=o[c];if(!l||typeof l!="object")continue;Object.prototype.hasOwnProperty.call(l,"_cardSynced")&&(delete l._cardSynced,s++);let f=Array.isArray(l.messages)?l.messages:[],d=bo(f,r),h=d==="me"?"awaiting_reply":"unanswered_by_us";l.lastMessageBy!==d&&i++,l.lastMessageBy=d,l.conversationStatus=h,n++}if(n===0){console.log(" No conversations to recompute.");return}So(t,o),console.log(` Recomputed lastMessageBy + conversationStatus on ${n} 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 ko=vo(import.meta.url),jo=g.dirname(ko),_o=g.dirname(g.dirname(jo));function To(e){return e&&(e==="~"?Te.homedir():e.startsWith("~/")||e.startsWith("~\\")?g.join(Te.homedir(),e.slice(2)):e)}var D=process.env.DATA_DIR?g.resolve(To(process.env.DATA_DIR)):_o,G=g.join(D,"collected-profiles"),Y=g.join(D,"market-research"),k=g.join(D,".schema-version"),at=[g.join(G,".schema-version"),g.join(Y,".schema-version")],U=3,F=[{version:1,module:ve},{version:2,module:ke},{version:3,module:je}];(function(){F.sort((r,n)=>r.version-n.version);let t=new Set;for(let r of F){if(!Number.isInteger(r.version)||r.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(r.version)} (must be positive integer)`);if(t.has(r.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${r.version}`);t.add(r.version);let n=r.module;if(!n||typeof n.up!="function")throw new Error(`MIGRATION_REGISTRY: v${r.version} module is missing up()`);if(n.VERSION!==void 0&&n.VERSION!==r.version)throw new Error(`MIGRATION_REGISTRY: v${r.version} entry does not match module VERSION (${n.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let o=F.length?F[F.length-1].version:0;if(o!==U)throw new Error(`MIGRATION_REGISTRY: highest version v${o} but CURRENT_SCHEMA_VERSION=${U}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let r=0;r<F.length;r++){let n=r+1;if(F[r].version!==n)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${n} at position ${r} but found v${F[r].version}`)}})();function dt(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
12
12
|
[FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
|
|
13
13
|
`),process.exit(1));try{a.mkdirSync(D,{recursive:!0})}catch(t){t.code!=="EEXIST"&&(console.error(`
|
|
14
14
|
[FATAL] Cannot create DATA_DIR (${D}): ${t.message}`),console.error(` Fix the path or permissions and try again.
|
|
@@ -34,28 +34,28 @@ ${r.join(`
|
|
|
34
34
|
[FATAL] Your data schema is at v${t}, but this plugin build only understands up to v${U}.`),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.
|
|
35
35
|
`),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${U}.
|
|
36
36
|
`),process.exit(1)),console.log(`
|
|
37
|
-
\u{1F4E6} Schema migration: v${t} \u2192 v${U}`);let o=
|
|
37
|
+
\u{1F4E6} Schema migration: v${t} \u2192 v${U}`);let o=Fo();if(!o.ok){console.error(`
|
|
38
38
|
[FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let n of o.broken)console.error(` ${n.dir}/${n.file}: ${n.err}`);console.error(`
|
|
39
39
|
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'.
|
|
40
|
-
`),process.exit(1)}let r=
|
|
40
|
+
`),process.exit(1)}let r=F.filter(n=>n.version>t);for(let n of r){console.log(`
|
|
41
41
|
Running migration v${String(n.version).padStart(3,"0")}...`);let s=`v${String(n.version).padStart(3,"0")}`,i=`.pre-${s}.backup`;try{pt(G,n.version),pt(Y,n.version)}catch(l){console.error(`
|
|
42
42
|
[FATAL] Pre-migration backup failed for ${s}: ${l.message}`),console.error(" Migration NOT applied. Repair the underlying issue (disk space, permissions, locked files)"),console.error(` and re-run the plugin command.
|
|
43
43
|
`),process.exit(1)}let c=n.module;try{await c.up(G,Y)}catch(l){console.error(`
|
|
44
|
-
[FATAL] Migration ${s} failed: ${l.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let f=
|
|
44
|
+
[FATAL] Migration ${s} failed: ${l.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let f=Lo(i);f.ok?(console.error(` \u2713 Auto-rollback restored ${f.restored} files. Schema stays at v${t}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
|
|
45
45
|
`)):(console.error(` [!] Auto-rollback INCOMPLETE: ${f.error}`),console.error(` Manual recovery: copy *${i} files back over the originals.
|
|
46
46
|
`))}catch(f){console.error(` [!] Auto-rollback CRASHED while restoring: ${f.message}`),console.error(` Manual recovery: copy *${i} files back over the originals.
|
|
47
47
|
`)}process.exit(1)}try{let l=new Date().toISOString(),f={version:n.version,name:c.NAME||s,appliedAt:l},d=ft();d.version=n.version,d.migratedAt=l,d.migrations=d.migrations||[],d.migrations.push(f),Co(d)}catch(l){console.error(`
|
|
48
48
|
[FATAL] Migration ${s} applied successfully but schema version file could NOT be updated: ${l.message}`),console.error(` Your data is in the v${n.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.
|
|
49
49
|
`),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{ze()}catch{}try{He()}catch{}_e=!0,$e(),console.log(`
|
|
50
50
|
\u2713 Schema is now at v${U}
|
|
51
|
-
`)}var Io=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Ro(e){let t=e.toLowerCase();return Io.some(o=>o.test(t))}var Do=6e4;function Oo(){let e=Date.now(),t=[];for(let o of[D,G,Y]){if(!a.existsSync(o))continue;let r;try{r=a.readdirSync(o)}catch{continue}for(let n of r){if(!Ro(n))continue;let s=g.join(o,n);try{let i=a.statSync(s);if(!i.isFile()||e-i.mtimeMs<Do)continue;t.push({dir:o,file:n,fullPath:s})}catch{}}}return t}function No({verbose:e=!1}={}){let t=Oo();if(t.length===0)return e&&console.log(" No orphan .tmp files found."),0;let o=0;for(let r of t)try{a.unlinkSync(r.fullPath),o++,e&&console.log(` Removed orphan: ${g.basename(r.dir)}/${r.file}`)}catch(n){console.warn(` [!] Could not remove orphan ${r.fullPath}: ${n.message}`)}return!e&&o>0&&console.log(` Cleaned up ${o} orphan .tmp file(s) from previous run.`),o}function
|
|
51
|
+
`)}var Io=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Ro(e){let t=e.toLowerCase();return Io.some(o=>o.test(t))}var Do=6e4;function Oo(){let e=Date.now(),t=[];for(let o of[D,G,Y]){if(!a.existsSync(o))continue;let r;try{r=a.readdirSync(o)}catch{continue}for(let n of r){if(!Ro(n))continue;let s=g.join(o,n);try{let i=a.statSync(s);if(!i.isFile()||e-i.mtimeMs<Do)continue;t.push({dir:o,file:n,fullPath:s})}catch{}}}return t}function No({verbose:e=!1}={}){let t=Oo();if(t.length===0)return e&&console.log(" No orphan .tmp files found."),0;let o=0;for(let r of t)try{a.unlinkSync(r.fullPath),o++,e&&console.log(` Removed orphan: ${g.basename(r.dir)}/${r.file}`)}catch(n){console.warn(` [!] Could not remove orphan ${r.fullPath}: ${n.message}`)}return!e&&o>0&&console.log(` Cleaned up ${o} orphan .tmp file(s) from previous run.`),o}function Fo(){let e=[];for(let t of[G,Y]){if(!a.existsSync(t))continue;let o=a.readdirSync(t).filter(r=>{let n=r.toLowerCase();return n.endsWith(".json")&&!n.includes(".backup")});for(let r of o){let n=g.join(t,r);try{le(n)}catch(s){e.push({dir:g.basename(t),file:r,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function Lo(e){let t=[],o=[];for(let s of[G,Y]){if(!a.existsSync(s))continue;let i=a.readdirSync(s).filter(c=>c.endsWith(e));for(let c of i){let l=g.join(s,c),f=c.slice(0,-e.length),d=g.join(s,f);try{f.toLowerCase().endsWith(".json")?le(l):a.accessSync(l,a.constants.R_OK),t.push({backupPath:l,originalPath:d,fileName:c,dir:s})}catch(h){o.push(`${g.basename(s)}/${c}: ${h.message}`)}}}if(o.length>0)return{ok:!1,error:o.join("; "),restored:0};let r=0,n=[];for(let{backupPath:s,originalPath:i,fileName:c,dir:l}of t)try{gt(s,i),r++}catch(f){n.push(`${g.basename(l)}/${c}: ${f.message}`)}return n.length>0?{ok:!1,error:n.join("; "),restored:r}:{ok:!0,restored:r}}function gt(e,t){let o=t+".tmp";try{a.copyFileSync(e,o),mt(o)}catch(r){try{a.unlinkSync(o)}catch{}throw r}try{a.renameSync(o,t)}catch(r){try{a.unlinkSync(o)}catch{}if(r.code==="EPERM"||r.code==="EBUSY"){let n=new Error(`File locked: ${t} (${r.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 n.code=r.code,n}throw r}}await ht();var te=process.argv.slice(2),K=parseInt(te.find(e=>e.startsWith("--max="))?.split("=")[1]||"200"),yt=parseInt(te.find(e=>e.startsWith("--pages="))?.split("=")[1]||"20"),St=te.find(e=>e.startsWith("--url="))?.split("=").slice(1).join("="),Po=te.includes("--list"),Ee=te.includes("--verbose");function Mo(){if(St)return[St];let e=process.env.LINKEDIN_SCOUT_URLS;if(e)return e.split(",").map(o=>o.trim()).filter(Boolean);let t=process.env.LINKEDIN_SEARCH_URL;return t?[t]:[]}function qo(){let e=Ke();console.log(`
|
|
52
52
|
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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(" MARKET RESEARCH STATS"),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),console.log(` Scouted jobs: ${e.totalJobs}`),console.log(` Discovered recruiters: ${e.totalRecruiters}`),console.log(` Last scout: ${e.lastScoutDate||"never"}`),console.log(` Profile visits: ${e.totalVisited} unique (${e.todayVisited} today)`),e.topTech.length>0&&console.log(` Top tech: ${e.topTech.join(", ")}`),e.topCompanies.length>0&&console.log(` Top companies: ${e.topCompanies.join(", ")}`),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
|
|
53
53
|
`)}async function Uo(){if(console.log(`
|
|
54
54
|
LinkedIn Job Scout
|
|
55
55
|
`),Po){qo();return}let e=Mo();e.length===0&&(console.error("No search URL. Set LINKEDIN_SCOUT_URL or LINKEDIN_SCOUT_URLS in .env, or use --url=..."),process.exit(1));let t=it("scout",`max=${K},urls=${e.length}`),o={scouted:0,recruitersFound:0,skipped:0,skippedApplied:0,alreadyConnected:0,pages:0,errors:0,urlsProcessed:0},r=ie(),n=et(),s=Ze();console.log(` Scout URLs: ${e.length}`),e.forEach((l,f)=>console.log(` ${f+1}. ${l.slice(0,80)}...`)),console.log(` Max jobs: ${K} | Max pages per URL: ${yt}
|
|
56
56
|
`);let{browser:i,page:c}=await Oe();try{for(let l of e){if(o.scouted>=K)break;o.urlsProcessed++,console.log(`
|
|
57
57
|
\u2550\u2550\u2550 Scout URL ${o.urlsProcessed}/${e.length}: ${l.slice(0,70)}... \u2550\u2550\u2550`),await c.goto(l,{waitUntil:"domcontentloaded",timeout:6e4}),await R(3e3);let f=0,d=!1;for(let h=0;h<yt&&o.scouted<K&&!d;h++){o.pages++,console.log(`
|
|
58
|
-
\u2500\u2500 Page ${h+1} \u2500\u2500`),await Pe(c,l),await Ne(c),await R(1e3);let u=await
|
|
58
|
+
\u2500\u2500 Page ${h+1} \u2500\u2500`),await Pe(c,l),await Ne(c),await R(1e3);let u=await Fe(c,{easyApplyOnly:!1});console.log(` Found ${u.length} jobs on page`);for(let p of u){if(o.scouted>=K)break;let j=p.href?.match(/jobs\/view\/(\d+)/)?.[1]||p.id?.match(/\d+/)?.[0];if(j&&r[j]){o.skipped++;continue}if(j&&n[j]){o.skippedApplied++;continue}try{let S=await c.$(`a[data-control-id="${p.dataId}"]`);if(!S)continue;let w=await c.evaluate(()=>document.querySelector(".job-details-jobs-unified-top-card__job-title, .jobs-unified-top-card__job-title, h2.t-24")?.innerText?.trim()?.slice(0,80)||"");await S.click(),await R(1500+Math.random()*1500);for(let L=0;L<8;L++){let P=await c.evaluate(ae=>{let ue=document.querySelector(".job-details-jobs-unified-top-card__job-title, .jobs-unified-top-card__job-title, h2.t-24"),oe=document.querySelector(".jobs-description__content"),ne=ue?.innerText?.trim()?.slice(0,80)||"",fe=oe?.innerText?.trim()?.length||0;return{title:ne,descLen:fe,titleChanged:ne!==ae&&ne.length>0}},w);if(P.titleChanged&&P.descLen>50)break;await R(600)}let y=await qe(c),O=await Me(c);if(j&&(Ve(j,{title:p.jobTitle,company:y.companyName||p.companyName,companyUrl:y.companyUrl,location:p.location,salary:p.salary,url:p.href,isEasyApply:p.isEasyApply,applyType:p.applyType||(p.isEasyApply?"easy-apply":"external"),externalApplyUrl:y.externalApplyUrl,description:y.description,techStack:y.techStack,jobTags:y.jobTags,seniority:y.seniority,employmentType:y.employmentType,industries:y.industries,jobFunction:y.jobFunction,postedTime:y.postedTime,applicantCount:y.applicantCount,companySize:y.companySize,workplaceType:y.workplaceType,contractType:y.contractType,recruiterUrl:O?.profileUrl||null}),o.scouted++),y.companyUrl&&Ye(y.companyUrl,{name:y.companyName||p.companyName,about:y.aboutCompany,size:y.companySize,industries:y.industries,jobId:j,recruiterUrl:O?.profileUrl}),O?.profileUrl){let P=s[O.profileUrl]?.connectionStatus==="connected";Ge(O.profileUrl,{name:O.name,source:"scout",role:"recruiter",jobId:j,jobTitle:p.jobTitle,isConnected:P}),o.recruitersFound++,P&&o.alreadyConnected++}if(Ee){let L=y.techStack?.slice(0,5).join(", ")||"none";console.log(` [${o.scouted}] ${p.jobTitle?.slice(0,40)} @ ${p.companyName?.slice(0,20)} | ${L}${O?" | \u{1F464} "+O.name:""}`)}else o.scouted%10===0&&console.log(` Scouted: ${o.scouted} (${o.recruitersFound} recruiters)`)}catch(S){o.errors++,f++,Ee&&console.error(` Error: ${S.message?.slice(0,80)}`);let w=(S.message||"").toLowerCase();if(w.includes("detached")||w.includes("session closed")||w.includes("target closed")||w.includes("browser has disconnected")||w.includes("protocol error")){console.log(" \u26A0 Fatal browser error \u2014 stopping scout"),d=!0;break}if(f>=5){console.log(" \u26A0 5 consecutive errors \u2014 stopping scout"),d=!0;break}continue}f=0}if(d)break;if(o.scouted<K)try{if(!await Le(c)){console.log(" No more pages.");break}await R(2e3)}catch(p){console.log(` \u26A0 Pagination failed: ${p.message?.slice(0,60)}`);break}}if(d)break}console.log(`
|
|
59
59
|
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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(" Scout Complete"),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"),console.log(` URLs processed: ${o.urlsProcessed}/${e.length}`),console.log(` Pages scanned: ${o.pages}`),console.log(` Jobs scouted: ${o.scouted}`),console.log(` Skipped (existing): ${o.skipped}`),console.log(` Skipped (applied): ${o.skippedApplied}`),console.log(` Recruiters found: ${o.recruitersFound} (${o.alreadyConnected} already connected)`),console.log(` Errors: ${o.errors}`),console.log(`\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
|
|
60
60
|
`),Se(t,"success",o)}catch(l){console.error(`
|
|
61
61
|
Error:`,l.message),Ee&&console.error(l.stack),Se(t,"error",o,l.message)}finally{await i.close().catch(()=>{})}}Uo().catch(e=>{console.error("Scout failed:",e),process.exit(1)});
|