ilml-plugin-linkedin 1.20.0 → 1.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/dist/applyQueue.mjs +13 -13
- package/dist/connect.mjs +55 -55
- package/dist/daily.mjs +18 -18
- package/dist/enrichProfiles.mjs +5 -5
- package/dist/funnelRunner.mjs +39 -39
- package/dist/migrationCli.mjs +10 -10
- package/dist/quota.mjs +5 -5
- package/dist/run.mjs +45 -45
- package/dist/scout.mjs +11 -11
- package/dist/syncAll.mjs +87 -87
- package/dist/syncConnections.mjs +40 -40
- package/dist/version.mjs +1 -1
- package/dist/viewers.mjs +22 -22
- package/ilml-plugin.json +1 -1
- package/package.json +3 -2
package/dist/daily.mjs
CHANGED
|
@@ -5,7 +5,7 @@ var Le=Object.defineProperty;var q=(e,n)=>{for(var t in n)Le(e,t,{get:n[t],enume
|
|
|
5
5
|
`),process.exit(1));var ie=Me({token:se});function Je(e){if(!e||e<1e3)return`${e||0}ms`;let n=Math.round(e/1e3);if(n<60)return`${n}s`;let t=Math.floor(n/60),o=n%60;return o?`${t}m ${o}s`:`${t}m`}function Be({scriptName:e,mode:n,status:t,error:o,duration:r}){let s=t==="error"?"\u2717":t==="quota-reached"?"\u26A0":"\u2713",i=new Date().toISOString().slice(0,16).replace("T"," "),a=r?` ${Je(r)}`:"",c=t==="error"?`error${o?`: ${String(o).slice(0,80)}`:""}`:t==="quota-reached"?"daily quota reached":"done",u=n&&n!=="default"?` (${n})`:"";return`${s} ${e}${u} \u2014 ${c} \u2014 ${i}${a}`}async function le({scriptName:e,mode:n,status:t,summaryLines:o,error:r,duration:s}){let i=process.env.NODE_RUN_REPORTS;if(!i||!Array.isArray(o)||o.length===0)return;let c=`**${Be({scriptName:e,mode:n,status:t,error:r,duration:s})}**
|
|
6
6
|
|
|
7
7
|
${o.join(`
|
|
8
|
-
`)}`;try{await ie.addMessage(i,c)}catch(u){console.error(`[runReport] Failed to post end-of-session message: ${u.message}`)}}var Ve=qe(import.meta.url),We=R.dirname(R.dirname(Ve)),Y=process.env.DATA_DIR?R.resolve(process.env.DATA_DIR,"collected-profiles"):R.join(We,"collected-profiles"),G=R.join(Y,"run-log.json");function Ye(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";S.writeFileSync(o,t);for(let r=0;r<3;r++)try{S.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 ce(){try{if(!S.existsSync(G))return{runs:[]};let e=JSON.parse(S.readFileSync(G,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function ae(e){S.existsSync(Y)||S.mkdirSync(Y,{recursive:!0});try{Ye(G,e)}catch(n){console.error(`[!] Failed to save run-log.json: ${n.message}`)}}function ue(e,n="default"){let t=ce();for(let i of t.runs)i.status==="running"&&(i.status="interrupted",i.result="interrupted",i.timestamp&&(i.duration=Date.now()-new Date(i.timestamp).getTime()));let o=new Date,r={timestamp:o.toISOString(),script:e,mode:n,status:"running",result:null,duration:null,stats:null,error:null};t.runs.push(r);let s=Date.now()-30*24*60*60*1e3;return t.runs=t.runs.filter(i=>new Date(i.timestamp).getTime()>s),ae(t),{script:e,mode:n,startTime:o.getTime(),runIndex:t.runs.length-1}}function fe(e,n,t=null,o=null){if(!e)return;let r=null;try{let i=ce(),a=i.runs[e.runIndex];if(a&&a.status==="running"&&a.script===e.script)a.status=n,a.result=n,a.duration=Date.now()-e.startTime,a.stats=t,a.error=o,r=a.duration;else{let c=i.runs.find(u=>u.script===e.script&&u.status==="running"&&u.timestamp===new Date(e.startTime).toISOString());c&&(c.status=n,c.result=n,c.duration=Date.now()-e.startTime,c.stats=t,c.error=o,r=c.duration)}ae(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let s=t&&Array.isArray(t.summaryLines)?t.summaryLines:null;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS){let i=n==="error"?"error":t&&t.dailyLimitHit?"quota-reached":"done";le({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(a=>console.error(`[runLog] postRunReport failed: ${a.message}`))}}import{getPluginConfig as Ge}from"@ilivemylife/graph-sdk";var Ke=await Ge();for(let[e,n]of Object.entries(Ke))process.env[e]===void 0&&(process.env[e]=n);var gn=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Sn=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),bn=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.REJECTED,N.NEEDS_REVIEW]));import"dotenv/config";import*as d from"fs";import*as m from"path";import{fileURLToPath as He}from"url";var ze=He(import.meta.url),Qe=m.dirname(m.dirname(ze)),E=process.env.DATA_DIR?m.resolve(process.env.DATA_DIR,"collected-profiles"):m.join(Qe,"collected-profiles"),$n=m.join(E,"people.json"),jn=m.join(E,"jobs.json"),Xe=m.join(E,"quota.json"),En=m.join(E,"conversations.json"),On=m.join(E,"sync-state.json"),In=m.join(E,"application-questions.json"),Rn=m.join(E,"profile-history"),pe=(e,n)=>{let t=parseInt(e,10);return Number.isInteger(t)&&t>=0?t:n},P=pe(process.env.CONNECT_MAX_DAILY,20),U=pe(process.env.CONNECT_MAX_WEEKLY,100),Ze=null,eo=null,D=null,oo=null,no=null,to=null;function de(){Ze=null,eo=null,D=null,oo=null,no=null,to=null}function ro(){d.existsSync(E)||d.mkdirSync(E,{recursive:!0})}function so(e,n){if(!d.existsSync(e))return null;try{let t=JSON.parse(d.readFileSync(e,"utf-8"));try{d.copyFileSync(e,e+".backup")}catch{}return t}catch(t){console.error(`[!] ${n} is corrupted: ${t.message}`),console.error(` File: ${m.resolve(e)}`);let o=e+".backup";if(d.existsSync(o))try{let r=JSON.parse(d.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{d.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{d.copyFileSync(e,e+".corrupted")}catch{}return null}}function me(){return new Date().toISOString().split("T")[0]}function io(){return D||(ro(),D=so(Xe,"quota.json"),(!D||!D.connections)&&(D={connections:[]}),D)}function he(){let e=io(),n=new Date;n.setDate(n.getDate()-7);let t=n.toISOString().split("T")[0];return e.connections.filter(o=>o.date>=t)}function ye(){let e=he(),n=me(),t=e.filter(c=>c.date===n).length,o=e.length,r=t>=P,s=o>=U,i=!r&&!s,a={allowed:i,daily:{sent:t,max:P},weekly:{sent:o,max:U}};return i||(a.reason=r?`Daily limit reached (${t}/${P})`:`Weekly limit reached (${o}/${U})`),a}function ge(){let e=he(),n=me(),t=e.filter(r=>r.date===n).length,o=e.length;return{daily:{sent:t,max:P,remaining:P-t},weekly:{sent:o,max:U,remaining:U-o}}}import"dotenv/config";import*as l from"fs";import*as oe from"os";import*as f from"path";import{fileURLToPath as Po}from"url";var z={};q(z,{NAME:()=>co,VERSION:()=>lo,up:()=>fo});import*as b from"fs";import*as V from"path";var lo=1,co="normalize-jobs-and-questions",ao=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],uo=50;function K(e){return b.existsSync(e)?JSON.parse(b.readFileSync(e,"utf-8")):null}function H(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{b.writeFileSync(o,t)}catch(r){try{b.unlinkSync(o)}catch{}throw r}try{b.renameSync(o,e)}catch(r){try{b.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 fo(e,n){let t=V.join(e,"jobs.json"),o=V.join(n,"scouted-jobs.json"),r=V.join(e,"application-questions.json"),s=K(t)||{},i=K(o)||{},a=0,c=[];for(let p of Object.keys(s)){if(!i[p])continue;let A=i[p],h=s[p];for(let I of ao)A[I]!=null&&h[I]==null&&(h[I]=A[I]);c.push(p),a++}a>0?(H(t,s),console.log(` Phase 1: Merged ${a} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let u=K(r);if(u&&Array.isArray(u.applications)){let p={},A=0;for(let h of u.applications){let I=h.jobId||"unknown";p[I]||(p[I]={applications:[]});let re=(h.questions||[]).map($=>{let L={type:$.type||"input",question:$.question||"",answer:$.answer||""};return $.options&&($.options.length<=uo?L.options=$.options:(L.optionsOmitted=!0,A++)),$.page&&(L.page=$.page),$.wasPreFilled&&(L.wasPreFilled=!0),$.wasRetry&&(L.wasRetry=!0),L});p[I].applications.push({applicationId:h.applicationId,date:h.date,result:h.result||"submitted",formPages:h.formPages||null,duration:h.duration||null,retries:h.retries||0,failedField:h.failedField||null,questionCount:h.questionCount||re.length,questions:re})}H(r,p),console.log(` Phase 2: Rekeyed ${u.applications.length} applications by jobId (${Object.keys(p).length} unique jobs)`),A>0&&console.log(` Phase 2: Stripped bloated options from ${A} questions`)}else u&&!u.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(c.length>0){for(let p of c)delete i[p];H(o,i),console.log(` Phase 3: Removed ${c.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var Q={};q(Q,{NAME:()=>mo,VERSION:()=>po,up:()=>go});import*as w from"fs";import*as Se from"path";var po=2,mo="reset-unread-flags";function ho(e){return w.existsSync(e)?JSON.parse(w.readFileSync(e,"utf-8")):null}function yo(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{w.writeFileSync(o,t)}catch(r){try{w.unlinkSync(o)}catch{}throw r}try{w.renameSync(o,e)}catch(r){try{w.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 go(e){let n=Se.join(e,"conversations.json"),t=ho(n);if(!t){console.log(" conversations.json not found \u2014 nothing to reset.");return}let o=0;for(let r of Object.keys(t))t[r].unread===!0&&(t[r].unread=!1,o++);if(o===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}yo(n,t),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var X={};q(X,{NAME:()=>bo,VERSION:()=>So,up:()=>$o});import*as v from"fs";import*as be from"path";var So=3,bo="recompute-last-message-by",wo=new Set(["draft","confirmed","rejected","needs_review"]);function vo(e){return v.existsSync(e)?JSON.parse(v.readFileSync(e,"utf-8")):null}function ko(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{v.writeFileSync(o,t)}catch(r){try{v.unlinkSync(o)}catch{}throw r}try{v.renameSync(o,e)}catch(r){try{v.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 Ao(e,n){if(!e||e.length===0)return"them";let t=e.filter(s=>!wo.has(s.status));if(t.length===0)return"them";let o=t.map(s=>({m:s,t:Date.parse(s.time)})).filter(s=>Number.isFinite(s.t)).sort((s,i)=>i.t-s.t).map(s=>s.m),r=o.length>0?o:[...t].reverse();for(let s of r){let i=s.sender;if(i===n)return"me";if(i!=="Unknown"&&i!=="")return"them"}return"them"}async function $o(e){let n=be.join(e,"conversations.json"),t=vo(n);if(!t){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let o=process.env.LINKEDIN_NAME;if(!o||typeof o!="string"||!o.trim())throw new Error(`LINKEDIN_NAME env var is not set. Migration v003 needs your display name to determine which messages are yours vs theirs. Set LINKEDIN_NAME in your .env (or run "ilml plugin config linkedin set LINKEDIN_NAME 'Your Name'") and retry.`);let r=0,s=0,i=0;for(let a of Object.keys(t)){let c=t[a];if(!c||typeof c!="object")continue;Object.prototype.hasOwnProperty.call(c,"_cardSynced")&&(delete c._cardSynced,s++);let u=Array.isArray(c.messages)?c.messages:[],p=Ao(u,o),A=p==="me"?"awaiting_reply":"unanswered_by_us";c.lastMessageBy!==p&&i++,c.lastMessageBy=p,c.conversationStatus=A,r++}if(r===0){console.log(" No conversations to recompute.");return}ko(n,t),console.log(` Recomputed lastMessageBy + conversationStatus on ${r} conversations.`),console.log(` ${i} had stale lastMessageBy (now corrected).`),s>0&&console.log(` Cleaned ${s} leftover _cardSynced flags.`),console.log(" Re-run 'ilml linkedin enrich' if you want actionNeeded / summary / autoTags to also update.")}var Z={};q(Z,{NAME:()=>Eo,VERSION:()=>jo,up:()=>Do});import*as k from"fs";import*as we from"path";var jo=4,Eo="split-connection-timestamps",Oo=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function Io(e){if(!k.existsSync(e))return null;let n=k.readFileSync(e,"utf-8");return n.charCodeAt(0)===65279&&(n=n.slice(1)),JSON.parse(n)}function Ro(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{k.writeFileSync(o,t)}catch(r){try{k.unlinkSync(o)}catch{}throw r}try{k.renameSync(o,e)}catch(r){try{k.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 Do(e){let n=we.join(e,"people.json"),t=Io(n);if(!t||typeof t!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let o=0,r=0;for(let s of Object.keys(t)){let i=t[s];!i||typeof i!="object"||(r++,Oo.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}Ro(n,t),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${o} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}import"dotenv/config";import*as g from"path";import{fileURLToPath as To}from"url";var Co=To(import.meta.url),No=g.dirname(g.dirname(Co)),J=process.env.DATA_DIR?g.resolve(process.env.DATA_DIR,"market-research"):g.join(No,"market-research"),Ln=g.join(J,"scouted-jobs.json"),Mn=g.join(J,"discovered-people.json"),Pn=g.join(J,"visit-log.json"),Un=g.join(J,"companies.json"),Jn=g.join(J,"job-decisions.json");function ve(){_o=null,xo=null,Fo=null,Lo=null,Mo=null}var _o=null;var xo=null;var Fo=null;var Lo=null;var Mo=null;var Uo=Po(import.meta.url),Jo=f.dirname(Uo),Bo=f.dirname(f.dirname(Jo));function qo(e){return e&&(e==="~"?oe.homedir():e.startsWith("~/")||e.startsWith("~\\")?f.join(oe.homedir(),e.slice(2)):e)}var j=process.env.DATA_DIR?f.resolve(qo(process.env.DATA_DIR)):Bo,x=f.join(j,"collected-profiles"),F=f.join(j,"market-research"),y=f.join(j,".schema-version"),ke=[f.join(x,".schema-version"),f.join(F,".schema-version")],T=4,O=[{version:1,module:z},{version:2,module:Q},{version:3,module:X},{version:4,module:Z}];(function(){O.sort((o,r)=>o.version-r.version);let n=new Set;for(let o of O){if(!Number.isInteger(o.version)||o.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(o.version)} (must be positive integer)`);if(n.has(o.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${o.version}`);n.add(o.version);let r=o.module;if(!r||typeof r.up!="function")throw new Error(`MIGRATION_REGISTRY: v${o.version} module is missing up()`);if(r.VERSION!==void 0&&r.VERSION!==o.version)throw new Error(`MIGRATION_REGISTRY: v${o.version} entry does not match module VERSION (${r.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let t=O.length?O[O.length-1].version:0;if(t!==T)throw new Error(`MIGRATION_REGISTRY: highest version v${t} but CURRENT_SCHEMA_VERSION=${T}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<O.length;o++){let r=o+1;if(O[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${O[o].version}`)}})();function Ee(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
8
|
+
`)}`;try{await ie.addMessage(i,c)}catch(u){console.error(`[runReport] Failed to post end-of-session message: ${u.message}`)}}var Ve=qe(import.meta.url),We=R.dirname(R.dirname(Ve)),Y=process.env.DATA_DIR?R.resolve(process.env.DATA_DIR,"collected-profiles"):R.join(We,"collected-profiles"),G=R.join(Y,"run-log.json");function Ye(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";S.writeFileSync(o,t);for(let r=0;r<3;r++)try{S.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 ce(){try{if(!S.existsSync(G))return{runs:[]};let e=JSON.parse(S.readFileSync(G,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function ae(e){S.existsSync(Y)||S.mkdirSync(Y,{recursive:!0});try{Ye(G,e)}catch(n){console.error(`[!] Failed to save run-log.json: ${n.message}`)}}function ue(e,n="default"){let t=ce();for(let i of t.runs)i.status==="running"&&(i.status="interrupted",i.result="interrupted",i.timestamp&&(i.duration=Date.now()-new Date(i.timestamp).getTime()));let o=new Date,r={timestamp:o.toISOString(),script:e,mode:n,status:"running",result:null,duration:null,stats:null,error:null};t.runs.push(r);let s=Date.now()-30*24*60*60*1e3;return t.runs=t.runs.filter(i=>new Date(i.timestamp).getTime()>s),ae(t),{script:e,mode:n,startTime:o.getTime(),runIndex:t.runs.length-1}}function fe(e,n,t=null,o=null){if(!e)return;let r=null;try{let i=ce(),a=i.runs[e.runIndex];if(a&&a.status==="running"&&a.script===e.script)a.status=n,a.result=n,a.duration=Date.now()-e.startTime,a.stats=t,a.error=o,r=a.duration;else{let c=i.runs.find(u=>u.script===e.script&&u.status==="running"&&u.timestamp===new Date(e.startTime).toISOString());c&&(c.status=n,c.result=n,c.duration=Date.now()-e.startTime,c.stats=t,c.error=o,r=c.duration)}ae(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let s=t&&Array.isArray(t.summaryLines)?t.summaryLines:null;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS){let i=n==="error"?"error":t&&t.dailyLimitHit?"quota-reached":"done";le({scriptName:e.script,mode:e.mode,status:i,summaryLines:s,error:o,duration:r??Date.now()-e.startTime}).catch(a=>console.error(`[runLog] postRunReport failed: ${a.message}`))}}import{getPluginConfig as Ge}from"@ilivemylife/graph-sdk";var Ke=await Ge();for(let[e,n]of Object.entries(Ke))process.env[e]===void 0&&(process.env[e]=n);var yn=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Sn=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),bn=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.REJECTED,N.NEEDS_REVIEW]));import"dotenv/config";import*as d from"fs";import*as m from"path";import{fileURLToPath as He}from"url";var ze=He(import.meta.url),Qe=m.dirname(m.dirname(ze)),E=process.env.DATA_DIR?m.resolve(process.env.DATA_DIR,"collected-profiles"):m.join(Qe,"collected-profiles"),$n=m.join(E,"people.json"),jn=m.join(E,"jobs.json"),Xe=m.join(E,"quota.json"),En=m.join(E,"conversations.json"),On=m.join(E,"sync-state.json"),In=m.join(E,"application-questions.json"),Rn=m.join(E,"profile-history"),pe=(e,n)=>{let t=parseInt(e,10);return Number.isInteger(t)&&t>=0?t:n},P=pe(process.env.CONNECT_MAX_DAILY,20),U=pe(process.env.CONNECT_MAX_WEEKLY,100),Ze=null,eo=null,T=null,oo=null,no=null,to=null;function de(){Ze=null,eo=null,T=null,oo=null,no=null,to=null}function ro(){d.existsSync(E)||d.mkdirSync(E,{recursive:!0})}function so(e,n){if(!d.existsSync(e))return null;try{let t=JSON.parse(d.readFileSync(e,"utf-8"));try{d.copyFileSync(e,e+".backup")}catch{}return t}catch(t){console.error(`[!] ${n} is corrupted: ${t.message}`),console.error(` File: ${m.resolve(e)}`);let o=e+".backup";if(d.existsSync(o))try{let r=JSON.parse(d.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{d.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{d.copyFileSync(e,e+".corrupted")}catch{}return null}}function me(){return new Date().toISOString().split("T")[0]}function io(){return T||(ro(),T=so(Xe,"quota.json"),(!T||!T.connections)&&(T={connections:[]}),T)}function he(){let e=io(),n=new Date;n.setDate(n.getDate()-7);let t=n.toISOString().split("T")[0];return e.connections.filter(o=>o.date>=t)}function ge(){let e=he(),n=me(),t=e.filter(c=>c.date===n).length,o=e.length,r=t>=P,s=o>=U,i=!r&&!s,a={allowed:i,daily:{sent:t,max:P},weekly:{sent:o,max:U}};return i||(a.reason=r?`Daily limit reached (${t}/${P})`:`Weekly limit reached (${o}/${U})`),a}function ye(){let e=he(),n=me(),t=e.filter(r=>r.date===n).length,o=e.length;return{daily:{sent:t,max:P,remaining:P-t},weekly:{sent:o,max:U,remaining:U-o}}}import"dotenv/config";import*as l from"fs";import*as oe from"os";import*as f from"path";import{fileURLToPath as Po}from"url";var z={};q(z,{NAME:()=>co,VERSION:()=>lo,up:()=>fo});import*as b from"fs";import*as V from"path";var lo=1,co="normalize-jobs-and-questions",ao=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],uo=50;function K(e){return b.existsSync(e)?JSON.parse(b.readFileSync(e,"utf-8")):null}function H(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{b.writeFileSync(o,t)}catch(r){try{b.unlinkSync(o)}catch{}throw r}try{b.renameSync(o,e)}catch(r){try{b.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 fo(e,n){let t=V.join(e,"jobs.json"),o=V.join(n,"scouted-jobs.json"),r=V.join(e,"application-questions.json"),s=K(t)||{},i=K(o)||{},a=0,c=[];for(let p of Object.keys(s)){if(!i[p])continue;let A=i[p],h=s[p];for(let I of ao)A[I]!=null&&h[I]==null&&(h[I]=A[I]);c.push(p),a++}a>0?(H(t,s),console.log(` Phase 1: Merged ${a} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let u=K(r);if(u&&Array.isArray(u.applications)){let p={},A=0;for(let h of u.applications){let I=h.jobId||"unknown";p[I]||(p[I]={applications:[]});let re=(h.questions||[]).map($=>{let L={type:$.type||"input",question:$.question||"",answer:$.answer||""};return $.options&&($.options.length<=uo?L.options=$.options:(L.optionsOmitted=!0,A++)),$.page&&(L.page=$.page),$.wasPreFilled&&(L.wasPreFilled=!0),$.wasRetry&&(L.wasRetry=!0),L});p[I].applications.push({applicationId:h.applicationId,date:h.date,result:h.result||"submitted",formPages:h.formPages||null,duration:h.duration||null,retries:h.retries||0,failedField:h.failedField||null,questionCount:h.questionCount||re.length,questions:re})}H(r,p),console.log(` Phase 2: Rekeyed ${u.applications.length} applications by jobId (${Object.keys(p).length} unique jobs)`),A>0&&console.log(` Phase 2: Stripped bloated options from ${A} questions`)}else u&&!u.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(c.length>0){for(let p of c)delete i[p];H(o,i),console.log(` Phase 3: Removed ${c.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var Q={};q(Q,{NAME:()=>mo,VERSION:()=>po,up:()=>yo});import*as w from"fs";import*as Se from"path";var po=2,mo="reset-unread-flags";function ho(e){return w.existsSync(e)?JSON.parse(w.readFileSync(e,"utf-8")):null}function go(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{w.writeFileSync(o,t)}catch(r){try{w.unlinkSync(o)}catch{}throw r}try{w.renameSync(o,e)}catch(r){try{w.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 yo(e){let n=Se.join(e,"conversations.json"),t=ho(n);if(!t){console.log(" conversations.json not found \u2014 nothing to reset.");return}let o=0;for(let r of Object.keys(t))t[r].unread===!0&&(t[r].unread=!1,o++);if(o===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}go(n,t),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var X={};q(X,{NAME:()=>bo,VERSION:()=>So,up:()=>$o});import*as v from"fs";import*as be from"path";var So=3,bo="recompute-last-message-by",wo=new Set(["draft","confirmed","rejected","needs_review"]);function vo(e){return v.existsSync(e)?JSON.parse(v.readFileSync(e,"utf-8")):null}function ko(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{v.writeFileSync(o,t)}catch(r){try{v.unlinkSync(o)}catch{}throw r}try{v.renameSync(o,e)}catch(r){try{v.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 Ao(e,n){if(!e||e.length===0)return"them";let t=e.filter(s=>!wo.has(s.status));if(t.length===0)return"them";let o=t.map(s=>({m:s,t:Date.parse(s.time)})).filter(s=>Number.isFinite(s.t)).sort((s,i)=>i.t-s.t).map(s=>s.m),r=o.length>0?o:[...t].reverse();for(let s of r){let i=s.sender;if(i===n)return"me";if(i!=="Unknown"&&i!=="")return"them"}return"them"}async function $o(e){let n=be.join(e,"conversations.json"),t=vo(n);if(!t){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let o=process.env.LINKEDIN_NAME;if(!o||typeof o!="string"||!o.trim())throw new Error(`LINKEDIN_NAME env var is not set. Migration v003 needs your display name to determine which messages are yours vs theirs. Set LINKEDIN_NAME in your .env (or run "ilml plugin config linkedin set LINKEDIN_NAME 'Your Name'") and retry.`);let r=0,s=0,i=0;for(let a of Object.keys(t)){let c=t[a];if(!c||typeof c!="object")continue;Object.prototype.hasOwnProperty.call(c,"_cardSynced")&&(delete c._cardSynced,s++);let u=Array.isArray(c.messages)?c.messages:[],p=Ao(u,o),A=p==="me"?"awaiting_reply":"unanswered_by_us";c.lastMessageBy!==p&&i++,c.lastMessageBy=p,c.conversationStatus=A,r++}if(r===0){console.log(" No conversations to recompute.");return}ko(n,t),console.log(` Recomputed lastMessageBy + conversationStatus on ${r} conversations.`),console.log(` ${i} had stale lastMessageBy (now corrected).`),s>0&&console.log(` Cleaned ${s} leftover _cardSynced flags.`),console.log(" Re-run 'ilml linkedin enrich' if you want actionNeeded / summary / autoTags to also update.")}var Z={};q(Z,{NAME:()=>Eo,VERSION:()=>jo,up:()=>To});import*as k from"fs";import*as we from"path";var jo=4,Eo="split-connection-timestamps",Oo=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function Io(e){if(!k.existsSync(e))return null;let n=k.readFileSync(e,"utf-8");return n.charCodeAt(0)===65279&&(n=n.slice(1)),JSON.parse(n)}function Ro(e,n){let t=JSON.stringify(n,null,2),o=e+".tmp";try{k.writeFileSync(o,t)}catch(r){try{k.unlinkSync(o)}catch{}throw r}try{k.renameSync(o,e)}catch(r){try{k.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 To(e){let n=we.join(e,"people.json"),t=Io(n);if(!t||typeof t!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let o=0,r=0;for(let s of Object.keys(t)){let i=t[s];!i||typeof i!="object"||(r++,Oo.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}Ro(n,t),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${o} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}import"dotenv/config";import*as y from"path";import{fileURLToPath as Do}from"url";var Co=Do(import.meta.url),No=y.dirname(y.dirname(Co)),J=process.env.DATA_DIR?y.resolve(process.env.DATA_DIR,"market-research"):y.join(No,"market-research"),Ln=y.join(J,"scouted-jobs.json"),Mn=y.join(J,"discovered-people.json"),Pn=y.join(J,"visit-log.json"),Un=y.join(J,"companies.json"),Jn=y.join(J,"job-decisions.json");function ve(){xo=null,_o=null,Fo=null,Lo=null,Mo=null}var xo=null;var _o=null;var Fo=null;var Lo=null;var Mo=null;var Uo=Po(import.meta.url),Jo=f.dirname(Uo),Bo=f.dirname(f.dirname(Jo));function qo(e){return e&&(e==="~"?oe.homedir():e.startsWith("~/")||e.startsWith("~\\")?f.join(oe.homedir(),e.slice(2)):e)}var j=process.env.DATA_DIR?f.resolve(qo(process.env.DATA_DIR)):Bo,_=f.join(j,"collected-profiles"),F=f.join(j,"market-research"),g=f.join(j,".schema-version"),ke=[f.join(_,".schema-version"),f.join(F,".schema-version")],D=4,O=[{version:1,module:z},{version:2,module:Q},{version:3,module:X},{version:4,module:Z}];(function(){O.sort((o,r)=>o.version-r.version);let n=new Set;for(let o of O){if(!Number.isInteger(o.version)||o.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(o.version)} (must be positive integer)`);if(n.has(o.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${o.version}`);n.add(o.version);let r=o.module;if(!r||typeof r.up!="function")throw new Error(`MIGRATION_REGISTRY: v${o.version} module is missing up()`);if(r.VERSION!==void 0&&r.VERSION!==o.version)throw new Error(`MIGRATION_REGISTRY: v${o.version} entry does not match module VERSION (${r.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let t=O.length?O[O.length-1].version:0;if(t!==D)throw new Error(`MIGRATION_REGISTRY: highest version v${t} but CURRENT_SCHEMA_VERSION=${D}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<O.length;o++){let r=o+1;if(O[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${O[o].version}`)}})();function Ee(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
9
9
|
[FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
|
|
10
10
|
`),process.exit(1));try{l.mkdirSync(j,{recursive:!0})}catch(n){n.code!=="EEXIST"&&(console.error(`
|
|
11
11
|
[FATAL] Cannot create DATA_DIR (${j}): ${n.message}`),console.error(` Fix the path or permissions and try again.
|
|
@@ -13,41 +13,41 @@ ${o.join(`
|
|
|
13
13
|
[FATAL] DATA_DIR (${j}) is not accessible: ${n.message}
|
|
14
14
|
`),process.exit(1)}e.isDirectory()||(console.error(`
|
|
15
15
|
[FATAL] DATA_DIR (${j}) exists but is NOT a directory.`),console.error(` Looks like a typo \u2014 your DATA_DIR points at a file. Fix the path and try again.
|
|
16
|
-
`),process.exit(1));for(let n of[
|
|
16
|
+
`),process.exit(1));for(let n of[_,F]){let t;try{t=l.lstatSync(n)}catch(o){if(o.code==="ENOENT")continue;throw o}t.isSymbolicLink()&&(console.error(`
|
|
17
17
|
[FATAL] Data subdirectory is a symbolic link: ${n}`),console.error(" Refusing to follow \u2014 backup code would copy whatever the link points at."),console.error(` If this is intentional, replace the symlink with the real directory.
|
|
18
|
-
`),process.exit(1))}}var
|
|
19
|
-
[FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${n.pid}`),console.error(` Started at: ${n.startedAt||"(unknown)"}`),console.error(` Lock file: ${
|
|
18
|
+
`),process.exit(1))}}var x=f.join(j,".migration-lock");function Vo(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return l.writeFileSync(x,e,{flag:"wx"}),!0}catch(o){if(o.code!=="EEXIST")throw o}let n;try{n=JSON.parse(l.readFileSync(x,"utf-8"))}catch{n=null}if(n&&Number.isInteger(n.pid)){let o=!1;try{process.kill(n.pid,0),o=!0}catch(i){i.code==="EPERM"&&(o=!0)}let r=24*60*60*1e3,s=1/0;if(n.startedAt){let i=Date.parse(n.startedAt);Number.isNaN(i)||(s=Date.now()-i)}o&&s<r&&(console.error(`
|
|
19
|
+
[FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${n.pid}`),console.error(` Started at: ${n.startedAt||"(unknown)"}`),console.error(` Lock file: ${x}
|
|
20
20
|
`),console.error(" Wait for it to finish, or if you're sure it's not actually running,"),console.error(` delete the lock file manually and re-run.
|
|
21
|
-
`),process.exit(1)),o&&s>=r&&console.log(` Lock holder PID ${n.pid} is alive but lock is older than 24h \u2014 assuming PID reuse, taking over.`)}console.log(` Stale migration lock from PID ${n?.pid??"?"} found \u2014 taking over.`);let t=
|
|
21
|
+
`),process.exit(1)),o&&s>=r&&console.log(` Lock holder PID ${n.pid} is alive but lock is older than 24h \u2014 assuming PID reuse, taking over.`)}console.log(` Stale migration lock from PID ${n?.pid??"?"} found \u2014 taking over.`);let t=x+".tmp";try{return l.writeFileSync(t,e),l.renameSync(t,x),!0}catch(o){try{l.unlinkSync(t)}catch{}throw new Error(`Failed to take over stale migration lock: ${o.message}`)}}function ne(){try{if(JSON.parse(l.readFileSync(x,"utf-8")).pid!==process.pid)return;l.unlinkSync(x)}catch{}}var Ae=!1;function Wo(){if(Ae)return;Ae=!0;let e=()=>{try{ne()}catch{}process.exit(1)};for(let n of["SIGINT","SIGTERM","SIGHUP"])try{process.on(n,e)}catch{}}function Yo(){if(l.existsSync(g))return;let e=[],n=[];for(let s of ke)if(l.existsSync(s))try{e.push({file:s,schema:W(s)})}catch(i){n.push({file:s,err:i.message})}if(n.length>0){console.error(`
|
|
22
22
|
[FATAL] Legacy .schema-version file(s) corrupted \u2014 cannot determine current schema version:`);for(let s of n)console.error(` ${s.file}: ${s.err}`);console.error(`
|
|
23
23
|
Repair the file(s) (likely just an integer 'version' field \u2014 see another working DATA_DIR`),console.error(` or default to {"version":1,"migrations":[]} if you're sure you're on schema v1) and try again.
|
|
24
24
|
`),process.exit(1)}if(e.length===0)return;let t=e.map(s=>s.schema.version);if(new Set(t).size>1){console.error(`
|
|
25
25
|
[FATAL] Legacy .schema-version files disagree:`);for(let s of e)console.error(` ${s.file}: v${s.schema.version}`);console.error(" This means a previous migration crashed between writing the two files."),console.error(` Reconcile manually (delete the wrong one, keep the right one), then re-run.
|
|
26
|
-
`),process.exit(1)}let o=e[0].schema,r=
|
|
27
|
-
[FATAL] ${
|
|
26
|
+
`),process.exit(1)}let o=e[0].schema,r=g+".tmp";try{l.writeFileSync(r,JSON.stringify(o,null,2)),l.renameSync(r,g)}catch(s){try{l.unlinkSync(r)}catch{}throw s}for(let s of ke)if(l.existsSync(s))try{l.unlinkSync(s)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${g}`)}function Go(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let n=Number(e.version);return!Number.isFinite(n)||n<0||!Number.isInteger(n)?null:(e.version=n,Array.isArray(e.migrations)||(e.migrations=[]),e)}function W(e){let n=l.readFileSync(e,"utf-8");return n.charCodeAt(0)===65279&&(n=n.slice(1)),JSON.parse(n)}function $e(){if(Yo(),!l.existsSync(g))return{version:0,migrations:[]};let e;try{e=W(g)}catch(t){if(t.code==="ENOENT")return{version:0,migrations:[]};console.error(`
|
|
27
|
+
[FATAL] ${g} is not valid JSON: ${t.message}`),console.error(" Refusing to proceed \u2014 silently treating it as 'fresh install' would re-apply"),console.error(" every migration on top of already-migrated data and corrupt it."),console.error(' Repair the file (set it to {"version":N,"migrations":[...]} matching your real state)'),console.error(` or restore from the *.pre-vNNN.backup files if you have them.
|
|
28
28
|
`),process.exit(1)}let n=Go(e);return n===null&&(console.error(`
|
|
29
|
-
[FATAL] ${
|
|
30
|
-
`),process.exit(1)),n}function Oe(e){try{l.chmodSync(e,384)}catch{}}function Ko(e){if(Ee(),l.existsSync(
|
|
31
|
-
[FATAL] Your data schema is at v${n}, but this plugin build only understands up to v${
|
|
32
|
-
`),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${
|
|
29
|
+
[FATAL] ${g} has invalid structure:`),console.error(` ${JSON.stringify(e)?.slice(0,200)||"(unparseable)"}`),console.error(' Expected shape: { "version": <integer>, "migrations": [...] }'),console.error(` Repair the file or restore from a backup.
|
|
30
|
+
`),process.exit(1)),n}function Oe(e){try{l.chmodSync(e,384)}catch{}}function Ko(e){if(Ee(),l.existsSync(g))try{if(l.lstatSync(g).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${g}. Refusing to write through it (potential symlink attack). Remove the link and re-run.`)}catch(t){if(t.message?.includes("symbolic link"))throw t}let n=g+".tmp";try{l.writeFileSync(n,JSON.stringify(e,null,2)),Oe(n),l.renameSync(n,g)}catch(t){try{l.unlinkSync(n)}catch{}throw t}}function je(e,n){if(!l.existsSync(e))return;let t=`.pre-v${String(n).padStart(3,"0")}.backup`,o=l.readdirSync(e).filter(a=>{let c=a.toLowerCase();if(c.includes(".backup")||c===".schema-version"||c.endsWith(".tmp"))return!1;try{return l.statSync(f.join(e,a)).isFile()}catch{return!1}}),r=0,s=0,i=[];for(let a of o){let c=f.join(e,a),u=f.join(e,a+t);if(l.existsSync(u)){s++;continue}try{Re(c,u),r++}catch(p){i.push({file:a,err:p.message})}}if(i.length>0){let a=new Error(`Failed to back up ${i.length} file(s) in ${f.basename(e)}/: `+i.map(c=>`${c.file} (${c.err})`).join(", "));throw a.code="BACKUP_INCOMPLETE",a}if(r>0||s>0){let a=s>0?` (${s} pre-existing backup(s) preserved)`:"";console.log(` Backed up ${r} files in ${f.basename(e)}/ (${t})${a}`)}}var ee=!1;async function Ie(){if(ee)return;Ee(),Zo();let n=$e().version;if(n===D){ee=!0;return}Wo(),Vo(),process.on("exit",ne),n>D&&(console.error(`
|
|
31
|
+
[FATAL] Your data schema is at v${n}, but this plugin build only understands up to v${D}.`),console.error(" This usually means you downgraded the plugin without rolling back data."),console.error(` Operating on the newer-format data with this build would risk corrupting it.
|
|
32
|
+
`),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${D}.
|
|
33
33
|
`),process.exit(1)),console.log(`
|
|
34
|
-
\u{1F4E6} Schema migration: v${n} \u2192 v${
|
|
34
|
+
\u{1F4E6} Schema migration: v${n} \u2192 v${D}`);let t=en();if(!t.ok){console.error(`
|
|
35
35
|
[FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let r of t.broken)console.error(` ${r.dir}/${r.file}: ${r.err}`);console.error(`
|
|
36
36
|
Migration ABORTED. No backups taken, no files modified.`),console.error(" Repair the file(s) above (restore from your own backup, or fix manually)"),console.error(` and try again. To inspect: 'ilml linkedin migrate-status'.
|
|
37
37
|
`),process.exit(1)}let o=O.filter(r=>r.version>n);for(let r of o){console.log(`
|
|
38
|
-
Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,i=`.pre-${s}.backup`;try{je(
|
|
38
|
+
Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,i=`.pre-${s}.backup`;try{je(_,r.version),je(F,r.version)}catch(c){console.error(`
|
|
39
39
|
[FATAL] Pre-migration backup failed for ${s}: ${c.message}`),console.error(" Migration NOT applied. Repair the underlying issue (disk space, permissions, locked files)"),console.error(` and re-run the plugin command.
|
|
40
|
-
`),process.exit(1)}let a=r.module;try{await a.up(
|
|
40
|
+
`),process.exit(1)}let a=r.module;try{await a.up(_,F)}catch(c){console.error(`
|
|
41
41
|
[FATAL] Migration ${s} failed: ${c.message}`),console.error(` Attempting auto-rollback from ${i} files...`);try{let u=on(i);u.ok?(console.error(` \u2713 Auto-rollback restored ${u.restored} files. Schema stays at v${n}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
|
|
42
42
|
`)):(console.error(` [!] Auto-rollback INCOMPLETE: ${u.error}`),console.error(` Manual recovery: copy *${i} files back over the originals.
|
|
43
43
|
`))}catch(u){console.error(` [!] Auto-rollback CRASHED while restoring: ${u.message}`),console.error(` Manual recovery: copy *${i} files back over the originals.
|
|
44
44
|
`)}process.exit(1)}try{let c=new Date().toISOString(),u={version:r.version,name:a.NAME||s,appliedAt:c},p=$e();p.version=r.version,p.migratedAt=c,p.migrations=p.migrations||[],p.migrations.push(u),Ko(p)}catch(c){console.error(`
|
|
45
45
|
[FATAL] Migration ${s} applied successfully but schema version file could NOT be updated: ${c.message}`),console.error(` Your data is in the v${r.version} state but .schema-version still shows v${n}.`),console.error(` On next plugin command the runner will try to re-apply ${s}. If that migration is`),console.error(` idempotent (most are), it will succeed harmlessly. If you're unsure, run 'data-cleanup' and contact support.
|
|
46
46
|
`),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{de()}catch{}try{ve()}catch{}ee=!0,ne(),console.log(`
|
|
47
|
-
\u2713 Schema is now at v${
|
|
48
|
-
`)}var Ho=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function zo(e){let n=e.toLowerCase();return Ho.some(t=>t.test(n))}var Qo=6e4;function Xo(){let e=Date.now(),n=[];for(let t of[j,
|
|
49
|
-
${"\u2550".repeat(50)}`),console.log(` STEP: ${e}`),console.log("\u2550".repeat(50)),Ne)return console.log(` [DRY RUN] Would run: node ${n} ${t.join(" ")}`),!0;try{return nn("node",[n,...t],{stdio:"inherit",timeout:18e6}),console.log(` \u2713 ${e} completed`),!0}catch(r){return o?(console.log(` \u26A0 ${e} failed (optional): ${r.message?.slice(0,80)}`),!1):(console.error(` \u2717 ${e} failed: ${r.message?.slice(0,80)}`),!1)}}async function tn(){let e=
|
|
50
|
-
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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(` DAILY PIPELINE (${e})`),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");let n=Fe.filter(C);console.log(` Steps: ${n.join(" \u2192 ")}`),te.size>0&&console.log(` Skipping: ${[...te].join(", ")}`),Ne&&console.log(" [DRY RUN MODE]");let t=ue("daily",e),o={};if(C("apply-queue")&&(o["apply-queue"]=M("Apply Queue (scored jobs)","applyQueue.mjs",["--max=50","--min-score=50"],{optional:!0})),C("apply")){let s=
|
|
47
|
+
\u2713 Schema is now at v${D}
|
|
48
|
+
`)}var Ho=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function zo(e){let n=e.toLowerCase();return Ho.some(t=>t.test(n))}var Qo=6e4;function Xo(){let e=Date.now(),n=[];for(let t of[j,_,F]){if(!l.existsSync(t))continue;let o;try{o=l.readdirSync(t)}catch{continue}for(let r of o){if(!zo(r))continue;let s=f.join(t,r);try{let i=l.statSync(s);if(!i.isFile()||e-i.mtimeMs<Qo)continue;n.push({dir:t,file:r,fullPath:s})}catch{}}}return n}function Zo({verbose:e=!1}={}){let n=Xo();if(n.length===0)return e&&console.log(" No orphan .tmp files found."),0;let t=0;for(let o of n)try{l.unlinkSync(o.fullPath),t++,e&&console.log(` Removed orphan: ${f.basename(o.dir)}/${o.file}`)}catch(r){console.warn(` [!] Could not remove orphan ${o.fullPath}: ${r.message}`)}return!e&&t>0&&console.log(` Cleaned up ${t} orphan .tmp file(s) from previous run.`),t}function en(){let e=[];for(let n of[_,F]){if(!l.existsSync(n))continue;let t=l.readdirSync(n).filter(o=>{let r=o.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let o of t){let r=f.join(n,o);try{W(r)}catch(s){e.push({dir:f.basename(n),file:o,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function on(e){let n=[],t=[];for(let s of[_,F]){if(!l.existsSync(s))continue;let i=l.readdirSync(s).filter(a=>a.endsWith(e));for(let a of i){let c=f.join(s,a),u=a.slice(0,-e.length),p=f.join(s,u);try{u.toLowerCase().endsWith(".json")?W(c):l.accessSync(c,l.constants.R_OK),n.push({backupPath:c,originalPath:p,fileName:a,dir:s})}catch(A){t.push(`${f.basename(s)}/${a}: ${A.message}`)}}}if(t.length>0)return{ok:!1,error:t.join("; "),restored:0};let o=0,r=[];for(let{backupPath:s,originalPath:i,fileName:a,dir:c}of n)try{Re(s,i),o++}catch(u){r.push(`${f.basename(c)}/${a}: ${u.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:o}:{ok:!0,restored:o}}function Re(e,n){let t=n+".tmp";try{l.copyFileSync(e,t),Oe(t)}catch(o){try{l.unlinkSync(t)}catch{}throw o}try{l.renameSync(t,n)}catch(o){try{l.unlinkSync(t)}catch{}if(o.code==="EPERM"||o.code==="EBUSY"){let r=new Error(`File locked: ${n} (${o.code}). On Windows this is usually antivirus / Search Indexer / the file open in another app. Close anything that might be holding it and re-run.`);throw r.code=o.code,r}throw o}}await Ie();var B=process.argv.slice(2),te=new Set((B.find(e=>e.startsWith("--skip="))?.split("=")[1]||"").split(",").filter(Boolean)),Te=new Set((B.find(e=>e.startsWith("--only="))?.split("=")[1]||"").split(",").filter(Boolean)),Ne=B.includes("--dry-run"),xe=B.includes("--jobs"),_e=B.includes("--comms"),De=["apply-queue","apply","funnel","scout","visit"],Ce=["sync","today"],Fe=xe?De:_e?Ce:[...De,...Ce];function C(e){return Te.size>0?Te.has(e):!te.has(e)&&Fe.includes(e)}function M(e,n,t=[],{optional:o=!1}={}){if(console.log(`
|
|
49
|
+
${"\u2550".repeat(50)}`),console.log(` STEP: ${e}`),console.log("\u2550".repeat(50)),Ne)return console.log(` [DRY RUN] Would run: node ${n} ${t.join(" ")}`),!0;try{return nn("node",[n,...t],{stdio:"inherit",timeout:18e6}),console.log(` \u2713 ${e} completed`),!0}catch(r){return o?(console.log(` \u26A0 ${e} failed (optional): ${r.message?.slice(0,80)}`),!1):(console.error(` \u2717 ${e} failed: ${r.message?.slice(0,80)}`),!1)}}async function tn(){let e=xe?"jobs":_e?"comms":"full";console.log(`
|
|
50
|
+
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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(` DAILY PIPELINE (${e})`),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");let n=Fe.filter(C);console.log(` Steps: ${n.join(" \u2192 ")}`),te.size>0&&console.log(` Skipping: ${[...te].join(", ")}`),Ne&&console.log(" [DRY RUN MODE]");let t=ue("daily",e),o={};if(C("apply-queue")&&(o["apply-queue"]=M("Apply Queue (scored jobs)","applyQueue.mjs",["--max=50","--min-score=50"],{optional:!0})),C("apply")){let s=ye();o.apply=M("Apply from Search","run.mjs",[],{optional:!0})}if(C("funnel")&&!C("apply")){let s=ge();s.allowed?o.funnel=M("Connection Funnel","funnelRunner.mjs",["--max=20"],{optional:!0}):(console.log(`
|
|
51
51
|
\u26A0 Funnel skipped: ${s.reason}`),o.funnel="skipped_quota")}C("scout")&&(o.scout=M("Scout Jobs for Tomorrow","scout.mjs",["--max=300","--verbose"],{optional:!0})),C("sync")&&(o.sync=M("Sync Inbox","syncAll.mjs")),C("today")&&(o.today=M("Daily Report","syncAll.mjs",["--today"])),console.log(`
|
|
52
52
|
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`),console.log(" PIPELINE 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");for(let[s,i]of Object.entries(o))console.log(` ${i===!0?"\u2713":i===!1?"\u2717":"\u26A0"} ${s}: ${i===!0?"success":i===!1?"failed":i}`);console.log(`\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550
|
|
53
53
|
`);let r=Object.values(o).some(s=>s===!1);fe(t,r?"partial":"success",o)}tn().catch(e=>{console.error("Daily pipeline failed:",e),process.exit(1)});
|
package/dist/enrichProfiles.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var yn=Object.defineProperty;var ae=(e,t)=>()=>(e&&(t=e(e=0)),t);var me=(e,t)=>{for(var n in t)yn(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 dt(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 c=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(c)return c.click(),{dismissed:!0,matched:r.substring(0,80)};let d=o.querySelectorAll("button");for(let a of d){let m=a.innerText?.trim().toLowerCase()||"",f=a.getAttribute("aria-label")?.toLowerCase()||"";if(m==="not now"||m==="no thanks"||m==="dismiss"||f.includes("dismiss"))return a.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 pe=ae(()=>{});import{getPluginConfig as wn}from"@ilivemylife/graph-sdk";var bn,Sn,ee,yr,vn,_e=ae(async()=>{bn=await wn();for(let[e,t]of Object.entries(bn))process.env[e]===void 0&&(process.env[e]=t);Sn=process.env.LINKEDIN_NAME,ee=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),yr=Object.freeze(new Set([ee.DRAFT,ee.CONFIRMED,ee.NEEDS_REVIEW])),vn=Object.freeze(new Set([ee.DRAFT,ee.CONFIRMED,ee.REJECTED,ee.NEEDS_REVIEW]))});import"dotenv/config";import*as C from"fs";import*as A from"path";import{fileURLToPath as In}from"url";function Rt(){fe=null,Dn=null,jn=null,ue=null,On=null,Nn=null}function Re(){C.existsSync(U)||C.mkdirSync(U,{recursive:!0})}function De(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 je(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: ${A.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 Ln(){return new Date().toISOString().split("T")[0]}function te(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function $t(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function Dt(e,t,n=null){if(!t||e[t])return t;let o=te(t);if(!o)return t;let r=null;for(let[s,i]of Object.entries(e)){if(te(i.profileUrl||s)===o)return s;!r&&Array.isArray(i.aliases)&&i.aliases.includes(o)&&(r=s)}if(r){let s=$t(n),i=$t(e[r].name);if(s&&i&&s===i)return r}return t}function Pn(){C.existsSync(Te)||C.mkdirSync(Te,{recursive:!0})}function jt(e){let t=te(e);return t?A.join(Te,`${t}.json`):null}function qn(e){let t=jt(e);return t?je(t,`profile-history/${te(e)}.json`)||[]:[]}function Un(e,t){let n=jt(e);if(!n)return;Pn();let o=qn(e);o.unshift(t);try{De(n,o)}catch(r){console.error(`[!] Failed to append profile-history for ${te(e)}: ${r.message}`)}}function Et(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function _t(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function Bn(e,t){if(!e)return[];let n=[];for(let o of Mn){let r=e[o],s=t[o];Et(r)||Et(s)||_t(r)!==_t(s)&&n.push(o)}return n}function Vn(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 J(){return fe||(Re(),fe=je(Ie,"people.json")||{},fe)}function Ot(e){Re(),fe=e;try{De(Ie,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${A.resolve(Ie)}`)}}function Oe(){return ue||(Re(),ue=je(It,"conversations.json")||{},Hn(ue),ue)}function Hn(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{De(It,e)}catch{}}}function Ne(e,t={}){if(!e)return null;let n=J(),o=Ln(),r=new Date().toISOString(),s=Dt(n,e,t.name),i=n[s];if(i){let l=Bn(i,t);l.length>0&&(Un(s,{capturedAt:r,previousLastUpdated:i.lastUpdated||null,changedFields:l,snapshot:Vn(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 c of Fn)if(t[c]!=null){if(Array.isArray(t[c])&&t[c].length===0&&Array.isArray(i[c])&&i[c].length>0)continue;i[c]=t[c]}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 Ot(n),n[s]}function Le(e,t,n={}){if(n.dryRun||!e||!t)return;let o=te(t);if(!o)return;let r=J(),s=Dt(r,e),i=r[s];if(!i)return;let l=te(i.profileUrl||s);o!==l&&(Array.isArray(i.aliases)||(i.aliases=[]),i.aliases.includes(o)||(i.aliases.push(o),i.lastUpdated=new Date().toISOString(),Ot(r)))}var Tn,Rn,U,Ie,Pr,qr,It,Ur,Br,Te,Tt,Vr,Hr,fe,Dn,jn,ue,On,Nn,Fn,Mn,he=ae(async()=>{await _e();Tn=In(import.meta.url),Rn=A.dirname(A.dirname(Tn)),U=process.env.DATA_DIR?A.resolve(process.env.DATA_DIR,"collected-profiles"):A.join(Rn,"collected-profiles"),Ie=A.join(U,"people.json"),Pr=A.join(U,"jobs.json"),qr=A.join(U,"quota.json"),It=A.join(U,"conversations.json"),Ur=A.join(U,"sync-state.json"),Br=A.join(U,"application-questions.json"),Te=A.join(U,"profile-history"),Tt=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},Vr=Tt(process.env.CONNECT_MAX_DAILY,20),Hr=Tt(process.env.CONNECT_MAX_WEEKLY,100),fe=null,Dn=null,jn=null,ue=null,On=null,Nn=null;Fn=["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"],Mn=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"]});var Nt={};me(Nt,{extractCertificationsFromDetails:()=>Kn,extractEducationFromDetails:()=>Gn,extractExperienceFromDetails:()=>Wn,extractFeaturedFromDetails:()=>Jn,extractRecommendationsFromDetails:()=>zn,extractSkillsFromDetails:()=>Yn});async function Wn(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(a){let m=[];for(let f of a.querySelectorAll("div")){let p=Array.from(f.children).filter(w=>w.tagName==="DIV");if(p.length<3)continue;let v=p.filter(w=>(w.textContent||"").trim().length>50);v.length<3||(f.textContent||"").length<500||m.push({el:f,count:v.length,totalText:(f.textContent||"").length})}return m.sort((f,p)=>p.count-f.count||f.totalText-p.totalText),m[0]?.el}let l=i(s);if(!l)return[];let c=Array.from(l.children).filter(a=>a.tagName==="DIV").filter(a=>(a.textContent||"").trim().length>50);function d(a){let m=a[0]||null,f=null,p=null;if(a[1]){let b=a[1].split("\xB7").map(_=>_.trim());f=b[0]||null,b[1]&&(p=b[1])}let v=a.findIndex(b=>/(\d{4}|present)/i.test(b)&&/(-|–|—)/i.test(b)&&b.length<80),w=null,$=null;if(v>=0){let b=a[v].split("\xB7").map(_=>_.trim());w=b[0]||null,b[1]&&($=b[1])}let z=null,Q=-1;if(v>=0&&a[v+1]){let b=a[v+1],_=/^[>*\-•]|^>/.test(b),le=/https?:\/\//.test(b),ce=/\d{4}/.test(b),I=/,/.test(b)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(b);!_&&!le&&!ce&&b.length<100&&I&&(z=b,Q=v+1)}let Ae=null,x=-1,Z=a[a.length-1];if(Z&&/and\s+\+\d+\s+skills?$/i.test(Z)){x=a.length-1;let b=Z.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);b&&(Ae={listed:b[1].split(",").map(_=>_.trim()),additional:parseInt(b[2],10)})}let X=new Set([0,1,v,Q,x].filter(b=>b>=0)),V=a.filter((b,_)=>!X.has(_)),R=V.length>0?V.join(`
|
|
1
|
+
var yn=Object.defineProperty;var ae=(e,t)=>()=>(e&&(t=e(e=0)),t);var me=(e,t)=>{for(var n in t)yn(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 dt(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 c=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(c)return c.click(),{dismissed:!0,matched:r.substring(0,80)};let d=o.querySelectorAll("button");for(let a of d){let m=a.innerText?.trim().toLowerCase()||"",f=a.getAttribute("aria-label")?.toLowerCase()||"";if(m==="not now"||m==="no thanks"||m==="dismiss"||f.includes("dismiss"))return a.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 pe=ae(()=>{});import{getPluginConfig as wn}from"@ilivemylife/graph-sdk";var bn,Sn,ee,yr,vn,_e=ae(async()=>{bn=await wn();for(let[e,t]of Object.entries(bn))process.env[e]===void 0&&(process.env[e]=t);Sn=process.env.LINKEDIN_NAME,ee=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),yr=Object.freeze(new Set([ee.DRAFT,ee.CONFIRMED,ee.NEEDS_REVIEW])),vn=Object.freeze(new Set([ee.DRAFT,ee.CONFIRMED,ee.REJECTED,ee.NEEDS_REVIEW]))});import"dotenv/config";import*as C from"fs";import*as A from"path";import{fileURLToPath as In}from"url";function Rt(){fe=null,Dn=null,On=null,ue=null,jn=null,Nn=null}function Re(){C.existsSync(U)||C.mkdirSync(U,{recursive:!0})}function De(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 Oe(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: ${A.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 Ln(){return new Date().toISOString().split("T")[0]}function te(e){if(!e)return null;let t=e.match(/\/in\/([^/?#]+)/);return t?t[1].toLowerCase():null}function $t(e){return typeof e=="string"?e.replace(/\s+/g," ").trim().toLowerCase():""}function Dt(e,t,n=null){if(!t||e[t])return t;let o=te(t);if(!o)return t;let r=null;for(let[s,i]of Object.entries(e)){if(te(i.profileUrl||s)===o)return s;!r&&Array.isArray(i.aliases)&&i.aliases.includes(o)&&(r=s)}if(r){let s=$t(n),i=$t(e[r].name);if(s&&i&&s===i)return r}return t}function Pn(){C.existsSync(Te)||C.mkdirSync(Te,{recursive:!0})}function Ot(e){let t=te(e);return t?A.join(Te,`${t}.json`):null}function qn(e){let t=Ot(e);return t?Oe(t,`profile-history/${te(e)}.json`)||[]:[]}function Un(e,t){let n=Ot(e);if(!n)return;Pn();let o=qn(e);o.unshift(t);try{De(n,o)}catch(r){console.error(`[!] Failed to append profile-history for ${te(e)}: ${r.message}`)}}function Et(e){return!!(e==null||Array.isArray(e)&&e.length===0||typeof e=="string"&&!e.trim())}function _t(e){return Array.isArray(e)?[...e].map(t=>String(t).trim()).sort().join("||"):typeof e=="string"?e.replace(/\s+/g," ").trim():e}function Bn(e,t){if(!e)return[];let n=[];for(let o of Mn){let r=e[o],s=t[o];Et(r)||Et(s)||_t(r)!==_t(s)&&n.push(o)}return n}function Vn(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 J(){return fe||(Re(),fe=Oe(Ie,"people.json")||{},fe)}function jt(e){Re(),fe=e;try{De(Ie,e)}catch(t){console.error(`[!] Failed to save people.json: ${t.message}`),console.error(` Path: ${A.resolve(Ie)}`)}}function je(){return ue||(Re(),ue=Oe(It,"conversations.json")||{},Hn(ue),ue)}function Hn(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{De(It,e)}catch{}}}function Ne(e,t={}){if(!e)return null;let n=J(),o=Ln(),r=new Date().toISOString(),s=Dt(n,e,t.name),i=n[s];if(i){let l=Bn(i,t);l.length>0&&(Un(s,{capturedAt:r,previousLastUpdated:i.lastUpdated||null,changedFields:l,snapshot:Vn(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 c of Fn)if(t[c]!=null){if(Array.isArray(t[c])&&t[c].length===0&&Array.isArray(i[c])&&i[c].length>0)continue;i[c]=t[c]}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 jt(n),n[s]}function Le(e,t,n={}){if(n.dryRun||!e||!t)return;let o=te(t);if(!o)return;let r=J(),s=Dt(r,e),i=r[s];if(!i)return;let l=te(i.profileUrl||s);o!==l&&(Array.isArray(i.aliases)||(i.aliases=[]),i.aliases.includes(o)||(i.aliases.push(o),i.lastUpdated=new Date().toISOString(),jt(r)))}var Tn,Rn,U,Ie,Pr,qr,It,Ur,Br,Te,Tt,Vr,Hr,fe,Dn,On,ue,jn,Nn,Fn,Mn,he=ae(async()=>{await _e();Tn=In(import.meta.url),Rn=A.dirname(A.dirname(Tn)),U=process.env.DATA_DIR?A.resolve(process.env.DATA_DIR,"collected-profiles"):A.join(Rn,"collected-profiles"),Ie=A.join(U,"people.json"),Pr=A.join(U,"jobs.json"),qr=A.join(U,"quota.json"),It=A.join(U,"conversations.json"),Ur=A.join(U,"sync-state.json"),Br=A.join(U,"application-questions.json"),Te=A.join(U,"profile-history"),Tt=(e,t)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:t},Vr=Tt(process.env.CONNECT_MAX_DAILY,20),Hr=Tt(process.env.CONNECT_MAX_WEEKLY,100),fe=null,Dn=null,On=null,ue=null,jn=null,Nn=null;Fn=["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"],Mn=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"]});var Nt={};me(Nt,{extractCertificationsFromDetails:()=>Kn,extractEducationFromDetails:()=>Gn,extractExperienceFromDetails:()=>Wn,extractFeaturedFromDetails:()=>Jn,extractRecommendationsFromDetails:()=>zn,extractSkillsFromDetails:()=>Yn});async function Wn(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(a){let m=[];for(let f of a.querySelectorAll("div")){let p=Array.from(f.children).filter(w=>w.tagName==="DIV");if(p.length<3)continue;let v=p.filter(w=>(w.textContent||"").trim().length>50);v.length<3||(f.textContent||"").length<500||m.push({el:f,count:v.length,totalText:(f.textContent||"").length})}return m.sort((f,p)=>p.count-f.count||f.totalText-p.totalText),m[0]?.el}let l=i(s);if(!l)return[];let c=Array.from(l.children).filter(a=>a.tagName==="DIV").filter(a=>(a.textContent||"").trim().length>50);function d(a){let m=a[0]||null,f=null,p=null;if(a[1]){let b=a[1].split("\xB7").map(_=>_.trim());f=b[0]||null,b[1]&&(p=b[1])}let v=a.findIndex(b=>/(\d{4}|present)/i.test(b)&&/(-|–|—)/i.test(b)&&b.length<80),w=null,$=null;if(v>=0){let b=a[v].split("\xB7").map(_=>_.trim());w=b[0]||null,b[1]&&($=b[1])}let z=null,Q=-1;if(v>=0&&a[v+1]){let b=a[v+1],_=/^[>*\-•]|^>/.test(b),le=/https?:\/\//.test(b),ce=/\d{4}/.test(b),I=/,/.test(b)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(b);!_&&!le&&!ce&&b.length<100&&I&&(z=b,Q=v+1)}let Ae=null,x=-1,Z=a[a.length-1];if(Z&&/and\s+\+\d+\s+skills?$/i.test(Z)){x=a.length-1;let b=Z.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);b&&(Ae={listed:b[1].split(",").map(_=>_.trim()),additional:parseInt(b[2],10)})}let X=new Set([0,1,v,Q,x].filter(b=>b>=0)),V=a.filter((b,_)=>!X.has(_)),R=V.length>0?V.join(`
|
|
2
2
|
|
|
3
3
|
`):null;return{title:m,company:f,employmentType:p,dates:w,duration:$,location:z,description:R,skills:Ae,_raw:a}}return c.map(a=>{let f=(a.innerText||"").trim().split(`
|
|
4
4
|
`).map(p=>p.trim()).filter(p=>p&&p.length<5e3);return d(f)}).filter(a=>a.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 ge(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 we(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 Jn(e,t){return we(t,"featured","extractFeaturedFromDetails",async()=>(await ge(e,t,"featured"),await e.evaluate(`(() => {
|
|
@@ -235,15 +235,15 @@ 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
|
-
`});var Mt=ae(()=>{});import"dotenv/config";import*as
|
|
239
|
-
Closing browser...`);try{await e.close()}catch{}process.exit(0)};process.on("SIGINT",o),process.on("SIGTERM",o);let r=await e.newPage();return await r.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Ct(r,{profileDir:t,needsSeed:n}),console.log(" Browser launched (persistent profile)."),{browser:e,page:r}}pe();await he();async function Qn(e,t){let n=e.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: ilml linkedin login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await k(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function Ft(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:s=!1,extractSkills:i=!1,extractRecommendations:l=!1,extractCertifications:c=!1}=n;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await k(3e3),await dt(e)&&(console.log(" Dismissed Premium overlay"),await k(1500),await Qn(e,t));let a=0;for(let x=0;x<2;x++){let Z=await e.evaluate(()=>document.body.scrollHeight);for(let V=1;V<=6;V++)await e.evaluate(R=>window.scrollTo(0,R),Z*V/6),await k(900);let X=await e.evaluate(()=>document.body.scrollHeight);if(X===a)break;a=X}await k(800);let m=null;try{let x=e.url();x&&/\/in\/[^/?#]/.test(x)&&(m=x.split("?")[0].replace(/\/+$/,""))}catch{}let f=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"]),X=h=>{let g=(h||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(g)},V={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 V;let b=[...Array.from(R.querySelectorAll("h1")),...Array.from(R.querySelectorAll("h2"))],_=Array.from(R.querySelectorAll("h2")),le=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)}),ce=le?le.textContent.trim():null,I=le?le.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&&!X(y)});)I=I.parentElement;let Ze=null,Xe=null,et=null,$e=null;if(I&&I!==R){let h=Array.from(I.children).filter(y=>y.tagName==="P").filter(y=>{let H=y.textContent&&y.textContent.trim();return H&&H.length>5&&!X(H)});if(h[0]&&(Ze=h[0].textContent.trim()),h[1]){let y=h[1].textContent.trim().split(/\s*[·•]\s*/);Xe=y[0]||null,y.length>1&&(et=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 H=g[y].textContent&&g[y].textContent.trim();if(H&&!(ce&&H.startsWith(ce))&&($e=H.split(/[·•]/)[0].trim(),$e))break}}let tt=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"){tt=y;break}}}let un=!!R.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),nt=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),fn=nt&&nt.src||null,Se=R.textContent||"",ot=null,rt=Se.match(/(\d+\+?)\s+connections\b/i);rt&&(ot=rt[1]+" connections");let ve=null,st=Se.match(/(\d+)\s+mutual connection/i),it=Se.match(/and\s+(\d+)\s+other mutual/i),dn=Se.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);st?ve=parseInt(st[1],10):it?ve=2+parseInt(it[1],10):dn&&(ve=2);let lt=null,ct=null,at=_.find(h=>h.textContent&&h.textContent.trim()==="About");if(at){let h=at.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 Ee=y[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(gn=>gn.trim()).filter(Boolean);Ee.length>0&&Ee.length<10&&(ct=Ee)}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(),lt=g||null}}let ut=null,ft=_.find(h=>h.textContent&&h.textContent.trim()==="Activity");if(ft){let h=ft.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let g=(h.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);g&&(ut=parseInt(g[1].replace(/,/g,""),10))}}let mn=[...new Set(_.map(h=>(h.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(h=>h&&h.length>1&&h.length<60&&h!==ce).filter(h=>x.has(h)))],de=document.body.textContent||"",pn=/#OpenToWork\b/i.test(de)||/\bOpen to work\b/.test(de),hn=/#Hiring\b/i.test(de)||/\bI'?m hiring\b/i.test(de)||/\bWe are hiring\b/i.test(de);return{name:ce,title:Ze,location:$e,currentCompany:Xe,currentSchool:et,connectionDegree:tt,hasVerifiedBadge:un,photoUrl:fn,connectionsLevel:ot,mutualConnectionsCount:ve,followers:ut,openToWork:pn,hiring:hn,about:lt,topSkills:ct,availableSections:mn}});console.log(`Viewed: ${f.name} - ${f.title}`);let p=null,v=null,w=null,$=null,z=null,Q=null;if(o||r||s||i||l||c){let x=await Promise.resolve().then(()=>(Lt(),Nt));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&&($=await x.extractSkillsFromDetails(e,t),console.log(` + Skills: ${$.length} entries`)),l&&(z=await x.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${z.length} entries`)),c&&(Q=await x.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${Q.length} entries`))}return{...f,profileUrl:t,resolvedUrl:m,...p!==null&&{experience:p},...v!==null&&{featured:v},...w!==null&&{education:w},...$!==null&&{skillsFull:$},...z!==null&&{recommendations:z},...Q!==null&&{certifications:Q}}}catch(d){console.error(`Error viewing profile ${t}:`,d.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(d.message||""))throw d;return null}}Me();await he();pe();async function Vt(e,t,n={}){let{maxVisits:o=50,delayBetween:r=4e3,skipRecentDays:s=7,verbose:i=!1,extractExperience:l=!1}=n,c={visited:0,skipped:0,errors:0},d=Date.now()-s*24*60*60*1e3;for(let a of t){if(c.visited>=o)break;if(!a.profileUrl)continue;let m=Bt(a.profileUrl);if(m&&new Date(m).getTime()>d){c.skipped++;continue}try{let f=await Ft(e,a.profileUrl,{extractExperience:l}),p=a.source||"visit";if(f){let w={...f,source:p};l&&Array.isArray(f.experience)&&f.experience.length>0&&(w._lastEnrichedAt=new Date().toISOString()),Ne(a.profileUrl,w),f.resolvedUrl&&Le(a.profileUrl,f.resolvedUrl)}Ut(a.profileUrl,{name:f?.name||a.name||null,source:p}),c.visited++,i?console.log(` [${c.visited}] ${f?.name||a.profileUrl} \u2014 ${f?.title?.slice(0,40)||"?"}`):c.visited%10===0&&console.log(` Visited: ${c.visited}`);let v=Math.random()*4e3;await k(r+v)}catch(f){c.errors++,i&&console.error(` Error visiting ${a.name||a.profileUrl}: ${f.message?.slice(0,60)}`);let p=(f.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 c}await he();import"dotenv/config";import*as
|
|
238
|
+
`});var Mt=ae(()=>{});import"dotenv/config";import*as O from"fs";import*as D from"path";import{fileURLToPath as Zn}from"url";function to(){O.existsSync(oe)||O.mkdirSync(oe,{recursive:!0})}function no(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 oo(e){try{if(O.existsSync(e))return JSON.parse(O.readFileSync(e,"utf-8"))}catch{}return null}function qt(){ro=null,so=null,io=null,lo=null,ne=null}function Fe(){return ne||(ne=oo(Pt)||{visits:[]},Array.isArray(ne.visits)||(ne.visits=[]),ne)}function Ut(e,t={}){if(!e)return;to();let n=Fe();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{no(Pt,n)}catch(r){console.error(`[!] Failed to save visit-log.json: ${r.message}`)}}function Bt(e){let t=Fe();for(let n=t.visits.length-1;n>=0;n--)if(t.visits[n].profileUrl===e)return t.visits[n].date;return null}var Xn,eo,oe,cs,as,Pt,us,fs,ro,so,io,lo,ne,Me=ae(()=>{Mt();Xn=Zn(import.meta.url),eo=D.dirname(D.dirname(Xn)),oe=process.env.DATA_DIR?D.resolve(process.env.DATA_DIR,"market-research"):D.join(eo,"market-research"),cs=D.join(oe,"scouted-jobs.json"),as=D.join(oe,"discovered-people.json"),Pt=D.join(oe,"visit-log.json"),us=D.join(oe,"companies.json"),fs=D.join(oe,"job-decisions.json");ro=null,so=null,io=null,lo=null,ne=null});import $n from"puppeteer";import{addExtra as En}from"puppeteer-extra";import _n from"puppeteer-extra-plugin-stealth";pe();await _e();import P from"fs";import W from"path";var kn="cookies.json";function mt(){let e=process.env.ILML_SCOPE_DIR;return e?W.join(e,"plugins-state","linkedin","cookies.json"):kn}function pt(){let e=mt();if(!P.existsSync(e))throw new Error(`Cookies not found at ${e}. Run: ilml linkedin login`);let t;try{t=P.readFileSync(e,"utf-8")}catch(o){throw new Error(`Failed to read cookies at ${e}: ${o.message}. Run: ilml linkedin login`)}let n;try{n=JSON.parse(t)}catch{throw new Error(`Cookies file at ${e} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(n)||n.length===0)throw new Error(`Cookies file at ${e} is empty or not an array. Run: ilml linkedin login`);return n}function ht(){return P.existsSync(mt())}function Cn(){let e=process.env.ILML_SCOPE_DIR;return e?W.join(e,"plugins-state","linkedin"):"."}function gt(e){let t=String(e||"").replace(/[^a-zA-Z0-9_.-]/g,"_").slice(0,80);return/[a-zA-Z0-9]/.test(t)?t:"default"}function xn(){let e=process.env.MY_LINKEDIN_URL,t=e&&e.match(/\/in\/([^/?#]+)/);return t&&t[1]?gt(t[1]):"default"}function yt(e){let t=process.env.LINKEDIN_CHROME_PROFILE_DIR;if(t)return P.existsSync(t)||P.mkdirSync(t,{recursive:!0}),W.resolve(t);let n=gt(e||xn()),o=W.join(Cn(),"chrome-profile",n);return P.existsSync(o)||P.mkdirSync(o,{recursive:!0}),W.resolve(o)}var wt=".ilml-seeded";function bt(e){return!P.existsSync(W.join(e,wt))}function St(e){try{P.writeFileSync(W.join(e,wt),new Date().toISOString())}catch{}}function vt(e){let t=0;for(let n of["SingletonLock","SingletonCookie","SingletonSocket"])try{P.rmSync(W.join(e,n),{force:!0}),t++}catch{}return t}var An={headless:!1,defaultViewport:null,protocolTimeout:3e5};async function kt(e,t={}){let n=yt(),o={...An,...t,userDataDir:n},r;try{r=await e.launch(o)}catch{vt(n);try{r=await e.launch(o)}catch(i){throw new Error(`Could not open the LinkedIn automation Chrome profile at ${n}. If a LinkedIn automation window is already open, close it and retry. (Chrome: ${i.message})`)}}return{browser:r,profileDir:n,needsSeed:bt(n)}}async function Ct(e,t){if(!t||!t.needsSeed)return!1;if(!ht())return console.warn(" \u26A0 No saved LinkedIn session found. If this command comes back empty or redirects to login, run: ilml linkedin login"),!1;try{return await e.setCookie(...pt()),St(t.profileDir),console.log(" (seeded persistent profile from saved cookies \u2014 one-time)"),!0}catch{return!1}}var xt=En($n);xt.use(_n());async function At(){let{browser:e,profileDir:t,needsSeed:n}=await kt(xt),o=async()=>{console.log(`
|
|
239
|
+
Closing browser...`);try{await e.close()}catch{}process.exit(0)};process.on("SIGINT",o),process.on("SIGTERM",o);let r=await e.newPage();return await r.evaluateOnNewDocument(()=>{Object.defineProperty(navigator,"webdriver",{get:()=>{}})}),await Ct(r,{profileDir:t,needsSeed:n}),console.log(" Browser launched (persistent profile)."),{browser:e,page:r}}pe();await he();async function Qn(e,t){let n=e.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: ilml linkedin login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await k(3e3);let o=e.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function Ft(e,t,n={}){let{extractExperience:o=!1,extractFeatured:r=!1,extractEducation:s=!1,extractSkills:i=!1,extractRecommendations:l=!1,extractCertifications:c=!1}=n;try{await e.goto(t,{waitUntil:"domcontentloaded",timeout:6e4}),await k(3e3),await dt(e)&&(console.log(" Dismissed Premium overlay"),await k(1500),await Qn(e,t));let a=0;for(let x=0;x<2;x++){let Z=await e.evaluate(()=>document.body.scrollHeight);for(let V=1;V<=6;V++)await e.evaluate(R=>window.scrollTo(0,R),Z*V/6),await k(900);let X=await e.evaluate(()=>document.body.scrollHeight);if(X===a)break;a=X}await k(800);let m=null;try{let x=e.url();x&&/\/in\/[^/?#]/.test(x)&&(m=x.split("?")[0].replace(/\/+$/,""))}catch{}let f=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"]),X=h=>{let g=(h||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(g)},V={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 V;let b=[...Array.from(R.querySelectorAll("h1")),...Array.from(R.querySelectorAll("h2"))],_=Array.from(R.querySelectorAll("h2")),le=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)}),ce=le?le.textContent.trim():null,I=le?le.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&&!X(y)});)I=I.parentElement;let Ze=null,Xe=null,et=null,$e=null;if(I&&I!==R){let h=Array.from(I.children).filter(y=>y.tagName==="P").filter(y=>{let H=y.textContent&&y.textContent.trim();return H&&H.length>5&&!X(H)});if(h[0]&&(Ze=h[0].textContent.trim()),h[1]){let y=h[1].textContent.trim().split(/\s*[·•]\s*/);Xe=y[0]||null,y.length>1&&(et=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 H=g[y].textContent&&g[y].textContent.trim();if(H&&!(ce&&H.startsWith(ce))&&($e=H.split(/[·•]/)[0].trim(),$e))break}}let tt=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"){tt=y;break}}}let un=!!R.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),nt=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),fn=nt&&nt.src||null,Se=R.textContent||"",ot=null,rt=Se.match(/(\d+\+?)\s+connections\b/i);rt&&(ot=rt[1]+" connections");let ve=null,st=Se.match(/(\d+)\s+mutual connection/i),it=Se.match(/and\s+(\d+)\s+other mutual/i),dn=Se.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);st?ve=parseInt(st[1],10):it?ve=2+parseInt(it[1],10):dn&&(ve=2);let lt=null,ct=null,at=_.find(h=>h.textContent&&h.textContent.trim()==="About");if(at){let h=at.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 Ee=y[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(gn=>gn.trim()).filter(Boolean);Ee.length>0&&Ee.length<10&&(ct=Ee)}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(),lt=g||null}}let ut=null,ft=_.find(h=>h.textContent&&h.textContent.trim()==="Activity");if(ft){let h=ft.parentElement;for(;h&&h.tagName!=="SECTION";)h=h.parentElement;if(h){let g=(h.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);g&&(ut=parseInt(g[1].replace(/,/g,""),10))}}let mn=[...new Set(_.map(h=>(h.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(h=>h&&h.length>1&&h.length<60&&h!==ce).filter(h=>x.has(h)))],de=document.body.textContent||"",pn=/#OpenToWork\b/i.test(de)||/\bOpen to work\b/.test(de),hn=/#Hiring\b/i.test(de)||/\bI'?m hiring\b/i.test(de)||/\bWe are hiring\b/i.test(de);return{name:ce,title:Ze,location:$e,currentCompany:Xe,currentSchool:et,connectionDegree:tt,hasVerifiedBadge:un,photoUrl:fn,connectionsLevel:ot,mutualConnectionsCount:ve,followers:ut,openToWork:pn,hiring:hn,about:lt,topSkills:ct,availableSections:mn}});console.log(`Viewed: ${f.name} - ${f.title}`);let p=null,v=null,w=null,$=null,z=null,Q=null;if(o||r||s||i||l||c){let x=await Promise.resolve().then(()=>(Lt(),Nt));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&&($=await x.extractSkillsFromDetails(e,t),console.log(` + Skills: ${$.length} entries`)),l&&(z=await x.extractRecommendationsFromDetails(e,t),console.log(` + Recommendations: ${z.length} entries`)),c&&(Q=await x.extractCertificationsFromDetails(e,t),console.log(` + Certifications: ${Q.length} entries`))}return{...f,profileUrl:t,resolvedUrl:m,...p!==null&&{experience:p},...v!==null&&{featured:v},...w!==null&&{education:w},...$!==null&&{skillsFull:$},...z!==null&&{recommendations:z},...Q!==null&&{certifications:Q}}}catch(d){console.error(`Error viewing profile ${t}:`,d.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(d.message||""))throw d;return null}}Me();await he();pe();async function Vt(e,t,n={}){let{maxVisits:o=50,delayBetween:r=4e3,skipRecentDays:s=7,verbose:i=!1,extractExperience:l=!1}=n,c={visited:0,skipped:0,errors:0},d=Date.now()-s*24*60*60*1e3;for(let a of t){if(c.visited>=o)break;if(!a.profileUrl)continue;let m=Bt(a.profileUrl);if(m&&new Date(m).getTime()>d){c.skipped++;continue}try{let f=await Ft(e,a.profileUrl,{extractExperience:l}),p=a.source||"visit";if(f){let w={...f,source:p};l&&Array.isArray(f.experience)&&f.experience.length>0&&(w._lastEnrichedAt=new Date().toISOString()),Ne(a.profileUrl,w),f.resolvedUrl&&Le(a.profileUrl,f.resolvedUrl)}Ut(a.profileUrl,{name:f?.name||a.name||null,source:p}),c.visited++,i?console.log(` [${c.visited}] ${f?.name||a.profileUrl} \u2014 ${f?.title?.slice(0,40)||"?"}`):c.visited%10===0&&console.log(` Visited: ${c.visited}`);let v=Math.random()*4e3;await k(r+v)}catch(f){c.errors++,i&&console.error(` Error visiting ${a.name||a.profileUrl}: ${f.message?.slice(0,60)}`);let p=(f.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 c}await he();import"dotenv/config";import*as j from"fs";import*as G from"path";import{fileURLToPath as po}from"url";import"dotenv/config";import{createGraphClient as co,resolveToken as ao}from"@ilivemylife/graph-sdk";import{config as uo}from"dotenv";uo();var Ht=ao()||process.env.TOKEN;Ht||(console.error(`
|
|
240
240
|
[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.
|
|
241
241
|
`),console.error(" Easiest way:"),console.error(" 1. npm install -g @ilivemylife/graph-sdk"),console.error(` 2. ilml login your@email.com yourpassword
|
|
242
242
|
`),console.error(` Or add ILML_TOKEN=... to .env
|
|
243
243
|
`),process.exit(1));var Wt=co({token:Ht});function fo(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 mo({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?` ${fo(r)}`:"",c=n==="error"?`error${o?`: ${String(o).slice(0,80)}`:""}`:n==="quota-reached"?"daily quota reached":"done",d=t&&t!=="default"?` (${t})`:"";return`${s} ${e}${d} \u2014 ${c} \u2014 ${i}${l}`}async function Jt({scriptName:e,mode:t,status:n,summaryLines:o,error:r,duration:s}){let i=process.env.NODE_RUN_REPORTS;if(!i||!Array.isArray(o)||o.length===0)return;let c=`**${mo({scriptName:e,mode:t,status:n,error:r,duration:s})}**
|
|
244
244
|
|
|
245
245
|
${o.join(`
|
|
246
|
-
`)}`;try{await Wt.addMessage(i,c)}catch(d){console.error(`[runReport] Failed to post end-of-session message: ${d.message}`)}}var ho=po(import.meta.url),go=G.dirname(G.dirname(ho)),Pe=process.env.DATA_DIR?G.resolve(process.env.DATA_DIR,"collected-profiles"):G.join(go,"collected-profiles"),qe=G.join(Pe,"run-log.json");function yo(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 Gt(){try{if(!O.existsSync(qe))return{runs:[]};let e=JSON.parse(O.readFileSync(qe,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Yt(e){O.existsSync(Pe)||O.mkdirSync(Pe,{recursive:!0});try{yo(qe,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function Kt(e,t="default"){let n=Gt();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),Yt(n),{script:e,mode:t,startTime:o.getTime(),runIndex:n.runs.length-1}}function Ue(e,t,n=null,o=null){if(!e)return;let r=null;try{let i=Gt(),l=i.runs[e.runIndex];if(l&&l.status==="running"&&l.script===e.script)l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=n,l.error=o,r=l.duration;else{let c=i.runs.find(d=>d.script===e.script&&d.status==="running"&&d.timestamp===new Date(e.startTime).toISOString());c&&(c.status=t,c.result=t,c.duration=Date.now()-e.startTime,c.stats=n,c.error=o,r=c.duration)}Yt(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";Jt({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 Ke from"os";import*as S from"path";import{fileURLToPath as Uo}from"url";var He={};me(He,{NAME:()=>bo,VERSION:()=>wo,up:()=>ko});import*as N from"fs";import*as ke from"path";var wo=1,bo="normalize-jobs-and-questions",So=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],vo=50;function Be(e){return N.existsSync(e)?JSON.parse(N.readFileSync(e,"utf-8")):null}function Ve(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 ko(e,t){let n=ke.join(e,"jobs.json"),o=ke.join(t,"scouted-jobs.json"),r=ke.join(e,"application-questions.json"),s=Be(n)||{},i=Be(o)||{},l=0,c=[];for(let a of Object.keys(s)){if(!i[a])continue;let m=i[a],f=s[a];for(let p of So)m[p]!=null&&f[p]==null&&(f[p]=m[p]);c.push(a),l++}l>0?(Ve(n,s),console.log(` Phase 1: Merged ${l} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let d=Be(r);if(d&&Array.isArray(d.applications)){let a={},m=0;for(let f of d.applications){let p=f.jobId||"unknown";a[p]||(a[p]={applications:[]});let v=(f.questions||[]).map(w=>{let $={type:w.type||"input",question:w.question||"",answer:w.answer||""};return w.options&&(w.options.length<=vo?$.options=w.options:($.optionsOmitted=!0,m++)),w.page&&($.page=w.page),w.wasPreFilled&&($.wasPreFilled=!0),w.wasRetry&&($.wasRetry=!0),$});a[p].applications.push({applicationId:f.applicationId,date:f.date,result:f.result||"submitted",formPages:f.formPages||null,duration:f.duration||null,retries:f.retries||0,failedField:f.failedField||null,questionCount:f.questionCount||v.length,questions:v})}Ve(r,a),console.log(` Phase 2: Rekeyed ${d.applications.length} applications by jobId (${Object.keys(a).length} unique jobs)`),m>0&&console.log(` Phase 2: Stripped bloated options from ${m} questions`)}else d&&!d.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(c.length>0){for(let a of c)delete i[a];Ve(o,i),console.log(` Phase 3: Removed ${c.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var We={};me(We,{NAME:()=>xo,VERSION:()=>Co,up:()=>Eo});import*as L from"fs";import*as zt from"path";var Co=2,xo="reset-unread-flags";function Ao(e){return L.existsSync(e)?JSON.parse(L.readFileSync(e,"utf-8")):null}function $o(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}}async function Eo(e){let t=zt.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}$o(t,n),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var Je={};me(Je,{NAME:()=>Io,VERSION:()=>_o,up:()=>Oo});import*as F from"fs";import*as Qt from"path";var _o=3,Io="recompute-last-message-by",To=new Set(["draft","confirmed","rejected","needs_review"]);function Ro(e){return F.existsSync(e)?JSON.parse(F.readFileSync(e,"utf-8")):null}function Do(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}}function jo(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!To.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 Oo(e){let t=Qt.join(e,"conversations.json"),n=Ro(t);if(!n){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let o=process.env.LINKEDIN_NAME;if(!o||typeof o!="string"||!o.trim())throw new Error(`LINKEDIN_NAME env var is not set. Migration v003 needs your display name to determine which messages are yours vs theirs. Set LINKEDIN_NAME in your .env (or run "ilml plugin config linkedin set LINKEDIN_NAME 'Your Name'") and retry.`);let r=0,s=0,i=0;for(let l of Object.keys(n)){let c=n[l];if(!c||typeof c!="object")continue;Object.prototype.hasOwnProperty.call(c,"_cardSynced")&&(delete c._cardSynced,s++);let d=Array.isArray(c.messages)?c.messages:[],a=jo(d,o),m=a==="me"?"awaiting_reply":"unanswered_by_us";c.lastMessageBy!==a&&i++,c.lastMessageBy=a,c.conversationStatus=m,r++}if(r===0){console.log(" No conversations to recompute.");return}Do(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 Ge={};me(Ge,{NAME:()=>Lo,VERSION:()=>No,up:()=>qo});import*as M from"fs";import*as Zt from"path";var No=4,Lo="split-connection-timestamps",Fo=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function Mo(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 Po(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 qo(e){let t=Zt.join(e,"people.json"),n=Mo(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++,Fo.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}Po(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".')}await he();Me();var Bo=Uo(import.meta.url),Vo=S.dirname(Bo),Ho=S.dirname(S.dirname(Vo));function Wo(e){return e&&(e==="~"?Ke.homedir():e.startsWith("~/")||e.startsWith("~\\")?S.join(Ke.homedir(),e.slice(2)):e)}var q=process.env.DATA_DIR?S.resolve(Wo(process.env.DATA_DIR)):Ho,se=S.join(q,"collected-profiles"),ie=S.join(q,"market-research"),T=S.join(q,".schema-version"),Xt=[S.join(se,".schema-version"),S.join(ie,".schema-version")],Y=4,B=[{version:1,module:He},{version:2,module:We},{version:3,module:Je},{version:4,module:Ge}];(function(){B.sort((o,r)=>o.version-r.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 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=B.length?B[B.length-1].version:0;if(n!==Y)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${Y}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<B.length;o++){let r=o+1;if(B[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${B[o].version}`)}})();function on(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
246
|
+
`)}`;try{await Wt.addMessage(i,c)}catch(d){console.error(`[runReport] Failed to post end-of-session message: ${d.message}`)}}var ho=po(import.meta.url),go=G.dirname(G.dirname(ho)),Pe=process.env.DATA_DIR?G.resolve(process.env.DATA_DIR,"collected-profiles"):G.join(go,"collected-profiles"),qe=G.join(Pe,"run-log.json");function yo(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 Gt(){try{if(!j.existsSync(qe))return{runs:[]};let e=JSON.parse(j.readFileSync(qe,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function Yt(e){j.existsSync(Pe)||j.mkdirSync(Pe,{recursive:!0});try{yo(qe,e)}catch(t){console.error(`[!] Failed to save run-log.json: ${t.message}`)}}function Kt(e,t="default"){let n=Gt();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),Yt(n),{script:e,mode:t,startTime:o.getTime(),runIndex:n.runs.length-1}}function Ue(e,t,n=null,o=null){if(!e)return;let r=null;try{let i=Gt(),l=i.runs[e.runIndex];if(l&&l.status==="running"&&l.script===e.script)l.status=t,l.result=t,l.duration=Date.now()-e.startTime,l.stats=n,l.error=o,r=l.duration;else{let c=i.runs.find(d=>d.script===e.script&&d.status==="running"&&d.timestamp===new Date(e.startTime).toISOString());c&&(c.status=t,c.result=t,c.duration=Date.now()-e.startTime,c.stats=n,c.error=o,r=c.duration)}Yt(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";Jt({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 Ke from"os";import*as S from"path";import{fileURLToPath as Uo}from"url";var He={};me(He,{NAME:()=>bo,VERSION:()=>wo,up:()=>ko});import*as N from"fs";import*as ke from"path";var wo=1,bo="normalize-jobs-and-questions",So=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],vo=50;function Be(e){return N.existsSync(e)?JSON.parse(N.readFileSync(e,"utf-8")):null}function Ve(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 ko(e,t){let n=ke.join(e,"jobs.json"),o=ke.join(t,"scouted-jobs.json"),r=ke.join(e,"application-questions.json"),s=Be(n)||{},i=Be(o)||{},l=0,c=[];for(let a of Object.keys(s)){if(!i[a])continue;let m=i[a],f=s[a];for(let p of So)m[p]!=null&&f[p]==null&&(f[p]=m[p]);c.push(a),l++}l>0?(Ve(n,s),console.log(` Phase 1: Merged ${l} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let d=Be(r);if(d&&Array.isArray(d.applications)){let a={},m=0;for(let f of d.applications){let p=f.jobId||"unknown";a[p]||(a[p]={applications:[]});let v=(f.questions||[]).map(w=>{let $={type:w.type||"input",question:w.question||"",answer:w.answer||""};return w.options&&(w.options.length<=vo?$.options=w.options:($.optionsOmitted=!0,m++)),w.page&&($.page=w.page),w.wasPreFilled&&($.wasPreFilled=!0),w.wasRetry&&($.wasRetry=!0),$});a[p].applications.push({applicationId:f.applicationId,date:f.date,result:f.result||"submitted",formPages:f.formPages||null,duration:f.duration||null,retries:f.retries||0,failedField:f.failedField||null,questionCount:f.questionCount||v.length,questions:v})}Ve(r,a),console.log(` Phase 2: Rekeyed ${d.applications.length} applications by jobId (${Object.keys(a).length} unique jobs)`),m>0&&console.log(` Phase 2: Stripped bloated options from ${m} questions`)}else d&&!d.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(c.length>0){for(let a of c)delete i[a];Ve(o,i),console.log(` Phase 3: Removed ${c.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var We={};me(We,{NAME:()=>xo,VERSION:()=>Co,up:()=>Eo});import*as L from"fs";import*as zt from"path";var Co=2,xo="reset-unread-flags";function Ao(e){return L.existsSync(e)?JSON.parse(L.readFileSync(e,"utf-8")):null}function $o(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}}async function Eo(e){let t=zt.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}$o(t,n),console.log(` Reset unread=false on ${o} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var Je={};me(Je,{NAME:()=>Io,VERSION:()=>_o,up:()=>jo});import*as F from"fs";import*as Qt from"path";var _o=3,Io="recompute-last-message-by",To=new Set(["draft","confirmed","rejected","needs_review"]);function Ro(e){return F.existsSync(e)?JSON.parse(F.readFileSync(e,"utf-8")):null}function Do(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}}function Oo(e,t){if(!e||e.length===0)return"them";let n=e.filter(s=>!To.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 jo(e){let t=Qt.join(e,"conversations.json"),n=Ro(t);if(!n){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let o=process.env.LINKEDIN_NAME;if(!o||typeof o!="string"||!o.trim())throw new Error(`LINKEDIN_NAME env var is not set. Migration v003 needs your display name to determine which messages are yours vs theirs. Set LINKEDIN_NAME in your .env (or run "ilml plugin config linkedin set LINKEDIN_NAME 'Your Name'") and retry.`);let r=0,s=0,i=0;for(let l of Object.keys(n)){let c=n[l];if(!c||typeof c!="object")continue;Object.prototype.hasOwnProperty.call(c,"_cardSynced")&&(delete c._cardSynced,s++);let d=Array.isArray(c.messages)?c.messages:[],a=Oo(d,o),m=a==="me"?"awaiting_reply":"unanswered_by_us";c.lastMessageBy!==a&&i++,c.lastMessageBy=a,c.conversationStatus=m,r++}if(r===0){console.log(" No conversations to recompute.");return}Do(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 Ge={};me(Ge,{NAME:()=>Lo,VERSION:()=>No,up:()=>qo});import*as M from"fs";import*as Zt from"path";var No=4,Lo="split-connection-timestamps",Fo=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function Mo(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 Po(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 qo(e){let t=Zt.join(e,"people.json"),n=Mo(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++,Fo.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}Po(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".')}await he();Me();var Bo=Uo(import.meta.url),Vo=S.dirname(Bo),Ho=S.dirname(S.dirname(Vo));function Wo(e){return e&&(e==="~"?Ke.homedir():e.startsWith("~/")||e.startsWith("~\\")?S.join(Ke.homedir(),e.slice(2)):e)}var q=process.env.DATA_DIR?S.resolve(Wo(process.env.DATA_DIR)):Ho,se=S.join(q,"collected-profiles"),ie=S.join(q,"market-research"),T=S.join(q,".schema-version"),Xt=[S.join(se,".schema-version"),S.join(ie,".schema-version")],Y=4,B=[{version:1,module:He},{version:2,module:We},{version:3,module:Je},{version:4,module:Ge}];(function(){B.sort((o,r)=>o.version-r.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 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=B.length?B[B.length-1].version:0;if(n!==Y)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${Y}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let o=0;o<B.length;o++){let r=o+1;if(B[o].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${o} but found v${B[o].version}`)}})();function on(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
247
247
|
[FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
|
|
248
248
|
`),process.exit(1));try{u.mkdirSync(q,{recursive:!0})}catch(t){t.code!=="EEXIST"&&(console.error(`
|
|
249
249
|
[FATAL] Cannot create DATA_DIR (${q}): ${t.message}`),console.error(` Fix the path or permissions and try again.
|
|
@@ -326,7 +326,7 @@ WHEN TO USE
|
|
|
326
326
|
- You want to backfill in a controlled batch (\u2264 10 per day) before reaching
|
|
327
327
|
out, so AI drafting has full context.
|
|
328
328
|
- Use --connections to keep ban risk low.
|
|
329
|
-
`),process.exit(0));function lr(e){try{return new RegExp(e,"i")}catch(t){console.error(`Invalid regex for --match-title: ${t.message}`),process.exit(1)}}var cr=new Set(["pending","sent_with_note","sent_without_note"]);function ar(e){return!e.about||!e.about.trim()}function ur(e){return!cr.has(e.connectionStatus)}function an(){let e=J(),t=
|
|
329
|
+
`),process.exit(0));function lr(e){try{return new RegExp(e,"i")}catch(t){console.error(`Invalid regex for --match-title: ${t.message}`),process.exit(1)}}var cr=new Set(["pending","sent_with_note","sent_without_note"]);function ar(e){return!e.about||!e.about.trim()}function ur(e){return!cr.has(e.connectionStatus)}function an(){let e=J(),t=je(),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,c])=>l&&l.startsWith("http")).filter(([,l])=>ar(l)).filter(([,l])=>ur(l)).filter(([l])=>!o.has(l)).map(([l,c])=>({profileUrl:l,name:c.name,person:c,hasConversation:n.has(l)}));be&&(s=s.filter(l=>l.person.connectionStatus==="connected")),E&&(s=s.filter(l=>E.test(l.person.title||"")));function i(l){let c=l.person.connectionStatus==="connected";return c&&l.hasConversation?1:c?2:E&&E.test(l.person.title||"")?3:l.hasConversation?4:5}return s.sort((l,c)=>{let d=i(l),a=i(c);if(d!==a)return d-a;let m=l.person.lastFullVisitAt||"",f=c.person.lastFullVisitAt||"";return m.localeCompare(f)}),s.map(l=>({profileUrl:l.profileUrl,name:l.name,source:"enrich-profile"}))}function fr(){let e=J(),t=Object.keys(e).length,n=Object.values(e).filter(m=>m.about&&m.about.trim()).length,o=t-n,r=an(),s={connWithConv:0,conn:0,titleMatch:0,withConv:0,other:0},i=e,l=je(),c=new Set(Object.values(l).map(m=>m.profileUrl).filter(Boolean)),d=Object.values(l).filter(m=>m.profileUrl&&(m.unread===!0||m.actionNeeded==="reply"||m.situation==="needs_our_reply"||m.conversationStatus==="unanswered_by_us")).length,a=0;for(let m of r){let f=i[m.profileUrl],p=f.connectionStatus==="connected",v=E&&E.test(f.title||""),w=c.has(m.profileUrl);f.lastFullVisitAt||a++,p&&w?s.connWithConv++:p?s.conn++:v?s.titleMatch++:w?s.withConv++:s.other++}console.log(`
|
|
330
330
|
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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): ${d}`),console.log(` Visitable (queue): ${r.length}`),console.log(` Never fully visited: ${a} (gone first)`),E&&console.log(` Title-match filter: /${E.source}/i`),be&&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}${E?"":" (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 ${xe}/day \u2192 ~${Math.ceil(r.length/xe)} days to clear queue
|
|
331
331
|
`)}function dr(){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 mr(){if(console.log(`
|
|
332
332
|
LinkedIn Profile Enricher
|