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