ilml-plugin-linkedin 1.20.22 → 1.20.26
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 +17 -0
- package/dist/applyQueue.mjs +38 -38
- package/dist/connect.mjs +78 -77
- package/dist/daily.mjs +34 -34
- package/dist/enrichProfiles.mjs +50 -50
- package/dist/funnelRunner.mjs +61 -60
- package/dist/messageBot.mjs +67 -67
- package/dist/migrationCli.mjs +44 -44
- package/dist/peopleSearchCli.mjs +13 -0
- package/dist/quota.mjs +34 -34
- package/dist/run.mjs +65 -64
- package/dist/scout.mjs +33 -33
- package/dist/syncAll.mjs +99 -98
- package/dist/syncConnections.mjs +48 -48
- package/dist/version.mjs +1 -1
- package/dist/viewers.mjs +35 -35
- package/dist/visit.mjs +48 -48
- package/ilml-plugin.json +19 -1
- package/package.json +2 -1
package/dist/daily.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
1
|
+
var We=Object.defineProperty;var B=(e,o)=>{for(var t in o)We(e,t,{get:o[t],enumerable:!0})};import{execFileSync as vn}from"child_process";import"dotenv/config";import*as w from"fs";import*as _ from"path";import{fileURLToPath as Ze}from"url";import"dotenv/config";import{createGraphClient as Ye,resolveToken as Ge}from"@ilivemylife/graph-sdk";import{config as He}from"dotenv";He();var ae=Ge()||process.env.TOKEN;ae||(console.error(`
|
|
2
2
|
[FATAL] No iLiveMyLife token found.`),console.error(" The bot uses Lifebot AI to decide which jobs to apply for"),console.error(` and how to fill application forms. It cannot work without it.
|
|
3
3
|
`),console.error(" Easiest way:"),console.error(" 1. npm install -g @ilivemylife/graph-sdk"),console.error(` 2. ilml login your@email.com yourpassword
|
|
4
4
|
`),console.error(` Or add ILML_TOKEN=... to .env
|
|
5
|
-
`),process.exit(1));var
|
|
6
|
-
`)}async function le({scriptName:e,mode:o,status:n,summaryLines:t,error:r,stoppedReason:s,duration:i}){let a=process.env.NODE_RUN_REPORTS;if(!a||!Array.isArray(t)||t.length===0)return;let l=Ge({scriptName:e,mode:o,status:n,summaryLines:t,error:r,stoppedReason:s,duration:i});try{await ie.addMessage(a,l)}catch(u){console.error(`[runReport] Failed to post end-of-session message: ${u.message}`)}}var Ke=He(import.meta.url),ze=I.dirname(I.dirname(Ke)),G=process.env.DATA_DIR?I.resolve(process.env.DATA_DIR,"collected-profiles"):I.join(ze,"collected-profiles"),H=I.join(G,"run-log.json");function Qe(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";w.writeFileSync(t,n);for(let r=0;r<3;r++)try{w.renameSync(t,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(!w.existsSync(H))return{runs:[]};let e=JSON.parse(w.readFileSync(H,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function ae(e){w.existsSync(G)||w.mkdirSync(G,{recursive:!0});try{Qe(H,e)}catch(o){console.error(`[!] Failed to save run-log.json: ${o.message}`)}}function ue(e,o="default"){let n=ce();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 t=new Date,r={timestamp:t.toISOString(),script:e,mode:o,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),ae(n),{script:e,mode:o,startTime:t.getTime(),runIndex:n.runs.length-1}}function fe(e,o,n=null,t=null){if(!e)return;let r=null;try{let a=ce(),l=a.runs[e.runIndex];if(l&&l.status==="running"&&l.script===e.script)l.status=o,l.result=o,l.duration=Date.now()-e.startTime,l.stats=n,l.error=t,r=l.duration;else{let u=a.runs.find(f=>f.script===e.script&&f.status==="running"&&f.timestamp===new Date(e.startTime).toISOString());u&&(u.status=o,u.result=o,u.duration=Date.now()-e.startTime,u.stats=n,u.error=t,r=u.duration)}ae(a)}catch(a){console.error(`[runLog] Failed to end run: ${a.message}`)}let s=n&&Array.isArray(n.summaryLines)?n.summaryLines:null,i=n&&n.__deferReport===!0;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS&&!i){let a=o==="error"?"error":n&&n.dailyLimitHit?"quota-reached":"done";le({scriptName:e.script,mode:e.mode,status:a,summaryLines:s,error:t,duration:r??Date.now()-e.startTime}).catch(l=>console.error(`[runLog] postRunReport failed: ${l.message}`))}}import{getPluginConfig as eo}from"@ilivemylife/graph-sdk";var Xe={day:"r86400","24h":"r86400",today:"r86400",week:"r604800","7d":"r604800",month:"r2592000","30d":"r2592000"},pe=e=>/^(1|true|yes|on)$/i.test(String(e??"").trim());function Ze(e){return String(e??"").split(/[,\s|]+/).map(o=>o.trim()).filter(Boolean)}function de(e=process.env){let o=(e.JOB_SEARCH_KEYWORDS||"").trim();if(!o)return null;let n=new URLSearchParams;n.set("keywords",o);let t=(e.JOB_SEARCH_LOCATION||"").trim();t&&n.set("location",t);let r=(e.JOB_SEARCH_GEO_ID||"").trim();r&&n.set("geoId",r);let s=parseInt(e.JOB_SEARCH_RADIUS_MILES,10);Number.isFinite(s)&&s>0&&n.set("distance",String(s)),pe(e.JOB_SEARCH_EASY_APPLY)&&n.set("f_AL","true"),pe(e.JOB_SEARCH_IN_NETWORK)&&n.set("f_JIYN","true");let i=Ze(e.JOB_SEARCH_COMPANY_IDS);i.length&&n.set("f_C",i.join(","));let a=(e.JOB_SEARCH_DATE_POSTED||"").trim().toLowerCase();a&&n.set("f_TPR",Xe[a]||a),n.set("origin","JOB_SEARCH_PAGE_JOB_FILTER");let l="https://www.linkedin.com/jobs/search/?"+n.toString(),u=(e.JOB_SEARCH_EXTRA_PARAMS||"").trim().replace(/^[?&]+/,"");return u&&(l+="&"+u),l}var oo=await eo();for(let[e,o]of Object.entries(oo))process.env[e]===void 0&&(process.env[e]=o);var me=de(process.env);me&&(process.env.LINKEDIN_SEARCH_URL=me);var Rn=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),jn=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),On=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.REJECTED,N.NEEDS_REVIEW]));import"dotenv/config";import*as h from"fs";import*as g from"path";import{fileURLToPath as no}from"url";var to=no(import.meta.url),ro=g.dirname(g.dirname(to)),j=process.env.DATA_DIR?g.resolve(process.env.DATA_DIR,"collected-profiles"):g.join(ro,"collected-profiles"),Cn=g.join(j,"people.json"),Nn=g.join(j,"jobs.json"),so=g.join(j,"quota.json"),xn=g.join(j,"conversations.json"),Fn=g.join(j,"sync-state.json"),Ln=g.join(j,"application-questions.json"),Pn=g.join(j,"profile-history"),he=(e,o)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:o},U=he(process.env.CONNECT_MAX_DAILY,20),J=he(process.env.CONNECT_MAX_WEEKLY,100),io=null,lo=null,_=null,co=null,ao=null,uo=null;function ge(){io=null,lo=null,_=null,co=null,ao=null,uo=null}function fo(){h.existsSync(j)||h.mkdirSync(j,{recursive:!0})}function po(e,o){if(!h.existsSync(e))return null;try{let n=JSON.parse(h.readFileSync(e,"utf-8"));try{h.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${o} is corrupted: ${n.message}`),console.error(` File: ${g.resolve(e)}`);let t=e+".backup";if(h.existsSync(t))try{let r=JSON.parse(h.readFileSync(t,"utf-8"));console.error(` Restored from ${t}`);try{h.copyFileSync(t,e)}catch{}return r}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{h.copyFileSync(e,e+".corrupted")}catch{}return null}}function ye(){return new Date().toISOString().split("T")[0]}function mo(){return _||(fo(),_=po(so,"quota.json"),(!_||!_.connections)&&(_={connections:[]}),_)}function Se(){let e=mo(),o=new Date;o.setDate(o.getDate()-7);let n=o.toISOString().split("T")[0];return e.connections.filter(t=>t.date>=n)}function be(){let e=Se(),o=ye(),n=e.filter(l=>l.date===o).length,t=e.length,r=n>=U,s=t>=J,i=!r&&!s,a={allowed:i,daily:{sent:n,max:U},weekly:{sent:t,max:J}};return i||(a.reason=r?`Daily limit reached (${n}/${U})`:`Weekly limit reached (${t}/${J})`),a}function we(){let e=Se(),o=ye(),n=e.filter(r=>r.date===o).length,t=e.length;return{daily:{sent:n,max:U,remaining:U-n},weekly:{sent:t,max:J,remaining:J-t}}}import"dotenv/config";import*as c from"fs";import*as ne from"os";import*as p from"path";import{fileURLToPath as Yo}from"url";var Q={};V(Q,{NAME:()=>go,VERSION:()=>ho,up:()=>bo});import*as v from"fs";import*as W from"path";var ho=1,go="normalize-jobs-and-questions",yo=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],So=50;function K(e){return v.existsSync(e)?JSON.parse(v.readFileSync(e,"utf-8")):null}function z(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{v.writeFileSync(t,n)}catch(r){try{v.unlinkSync(t)}catch{}throw r}try{v.renameSync(t,e)}catch(r){try{v.unlinkSync(t)}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 bo(e,o){let n=W.join(e,"jobs.json"),t=W.join(o,"scouted-jobs.json"),r=W.join(e,"application-questions.json"),s=K(n)||{},i=K(t)||{},a=0,l=[];for(let f of Object.keys(s)){if(!i[f])continue;let S=i[f],m=s[f];for(let d of yo)S[d]!=null&&m[d]==null&&(m[d]=S[d]);l.push(f),a++}a>0?(z(n,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 f={},S=0;for(let m of u.applications){let d=m.jobId||"unknown";f[d]||(f[d]={applications:[]});let C=(m.questions||[]).map(E=>{let P={type:E.type||"input",question:E.question||"",answer:E.answer||""};return E.options&&(E.options.length<=So?P.options=E.options:(P.optionsOmitted=!0,S++)),E.page&&(P.page=E.page),E.wasPreFilled&&(P.wasPreFilled=!0),E.wasRetry&&(P.wasRetry=!0),P});f[d].applications.push({applicationId:m.applicationId,date:m.date,result:m.result||"submitted",formPages:m.formPages||null,duration:m.duration||null,retries:m.retries||0,failedField:m.failedField||null,questionCount:m.questionCount||C.length,questions:C})}z(r,f),console.log(` Phase 2: Rekeyed ${u.applications.length} applications by jobId (${Object.keys(f).length} unique jobs)`),S>0&&console.log(` Phase 2: Stripped bloated options from ${S} 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(l.length>0){for(let f of l)delete i[f];z(t,i),console.log(` Phase 3: Removed ${l.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var X={};V(X,{NAME:()=>vo,VERSION:()=>wo,up:()=>$o});import*as k from"fs";import*as ve from"path";var wo=2,vo="reset-unread-flags";function ko(e){return k.existsSync(e)?JSON.parse(k.readFileSync(e,"utf-8")):null}function Ao(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{k.writeFileSync(t,n)}catch(r){try{k.unlinkSync(t)}catch{}throw r}try{k.renameSync(t,e)}catch(r){try{k.unlinkSync(t)}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 $o(e){let o=ve.join(e,"conversations.json"),n=ko(o);if(!n){console.log(" conversations.json not found \u2014 nothing to reset.");return}let t=0;for(let r of Object.keys(n))n[r].unread===!0&&(n[r].unread=!1,t++);if(t===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}Ao(o,n),console.log(` Reset unread=false on ${t} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var Z={};V(Z,{NAME:()=>Ro,VERSION:()=>Eo,up:()=>To});import*as A from"fs";import*as ke from"path";var Eo=3,Ro="recompute-last-message-by",jo=new Set(["draft","confirmed","rejected","needs_review"]);function Oo(e){return A.existsSync(e)?JSON.parse(A.readFileSync(e,"utf-8")):null}function Io(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{A.writeFileSync(t,n)}catch(r){try{A.unlinkSync(t)}catch{}throw r}try{A.renameSync(t,e)}catch(r){try{A.unlinkSync(t)}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 _o(e,o){if(!e||e.length===0)return"them";let n=e.filter(s=>!jo.has(s.status));if(n.length===0)return"them";let t=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=t.length>0?t:[...n].reverse();for(let s of r){let i=s.sender;if(i===o)return"me";if(i!=="Unknown"&&i!=="")return"them"}return"them"}async function To(e){let o=ke.join(e,"conversations.json"),n=Oo(o);if(!n){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let t=process.env.LINKEDIN_NAME;if(!t||typeof t!="string"||!t.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(n)){let l=n[a];if(!l||typeof l!="object")continue;Object.prototype.hasOwnProperty.call(l,"_cardSynced")&&(delete l._cardSynced,s++);let u=Array.isArray(l.messages)?l.messages:[],f=_o(u,t),S=f==="me"?"awaiting_reply":"unanswered_by_us";l.lastMessageBy!==f&&i++,l.lastMessageBy=f,l.conversationStatus=S,r++}if(r===0){console.log(" No conversations to recompute.");return}Io(o,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 ee={};V(ee,{NAME:()=>Co,VERSION:()=>Do,up:()=>Lo});import*as $ from"fs";import*as Ae from"path";var Do=4,Co="split-connection-timestamps",No=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function xo(e){if(!$.existsSync(e))return null;let o=$.readFileSync(e,"utf-8");return o.charCodeAt(0)===65279&&(o=o.slice(1)),JSON.parse(o)}function Fo(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{$.writeFileSync(t,n)}catch(r){try{$.unlinkSync(t)}catch{}throw r}try{$.renameSync(t,e)}catch(r){try{$.unlinkSync(t)}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 Lo(e){let o=Ae.join(e,"people.json"),n=xo(o);if(!n||typeof n!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let t=0,r=0;for(let s of Object.keys(n)){let i=n[s];!i||typeof i!="object"||(r++,No.has(i.connectionStatus)&&i.connectionDate&&!i.requestedConnectionAt&&(i.requestedConnectionAt=i.connectionDate,i.connectionDate=null,t++))}if(t===0){console.log(` Scanned ${r} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}Fo(o,n),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${t} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}import"dotenv/config";import*as b from"path";import{fileURLToPath as Po}from"url";var Mo=Po(import.meta.url),Uo=b.dirname(b.dirname(Mo)),B=process.env.DATA_DIR?b.resolve(process.env.DATA_DIR,"market-research"):b.join(Uo,"market-research"),Yn=b.join(B,"scouted-jobs.json"),Gn=b.join(B,"discovered-people.json"),Hn=b.join(B,"visit-log.json"),Kn=b.join(B,"companies.json"),zn=b.join(B,"job-decisions.json");function $e(){Jo=null,Bo=null,qo=null,Vo=null,Wo=null}var Jo=null;var Bo=null;var qo=null;var Vo=null;var Wo=null;var Go=Yo(import.meta.url),Ho=p.dirname(Go),Ko=p.dirname(p.dirname(Ho));function zo(e){return e&&(e==="~"?ne.homedir():e.startsWith("~/")||e.startsWith("~\\")?p.join(ne.homedir(),e.slice(2)):e)}var R=process.env.DATA_DIR?p.resolve(zo(process.env.DATA_DIR)):Ko,F=p.join(R,"collected-profiles"),L=p.join(R,"market-research"),y=p.join(R,".schema-version"),Ee=[p.join(F,".schema-version"),p.join(L,".schema-version")],T=4,O=[{version:1,module:Q},{version:2,module:X},{version:3,module:Z},{version:4,module:ee}];(function(){O.sort((t,r)=>t.version-r.version);let o=new Set;for(let t of O){if(!Number.isInteger(t.version)||t.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(t.version)} (must be positive integer)`);if(o.has(t.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${t.version}`);o.add(t.version);let r=t.module;if(!r||typeof r.up!="function")throw new Error(`MIGRATION_REGISTRY: v${t.version} module is missing up()`);if(r.VERSION!==void 0&&r.VERSION!==t.version)throw new Error(`MIGRATION_REGISTRY: v${t.version} entry does not match module VERSION (${r.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let n=O.length?O[O.length-1].version:0;if(n!==T)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${T}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let t=0;t<O.length;t++){let r=t+1;if(O[t].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${t} but found v${O[t].version}`)}})();function Ie(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
5
|
+
`),process.exit(1));var ue=Ye({token:ae});function Ke(e){if(!e||e<1e3)return`${e||0}ms`;let o=Math.round(e/1e3);if(o<60)return`${o}s`;let t=Math.floor(o/60),n=o%60;return n?`${t}m ${n}s`:`${t}m`}var ze={apply:"Job apply","apply-queue":"Job apply (queue)",scout:"Job scout",connect:"Connect run",funnel:"Recruiter funnel",messages:"Messages",sync:"Connections sync","sync-all":"Inbox sync",visit:"Profile visits",viewers:"Profile viewers",daily:"Daily run"};function Qe(e){let o=String(e||"").toLowerCase();return/authwall|session expired|not logged in|re-?auth|logged out|sign ?in/.test(o)?"LinkedIn asked to sign in again. Run `ilml linkedin login`, then run this again.":/protocoltimeout|callfunctionon|target closed|session closed|detached|execution context|browser.*disconnected|connection closed/.test(o)?"The browser stopped responding partway through. This is usually temporary \u2014 just run it again.":/err_aborted|err_network|err_connection|err_name_not_resolved|net::/.test(o)?"A page failed to load (network hiccup). Try running it again in a moment.":/navigation timeout|timeout.*exceeded|waiting for selector|waiting for/.test(o)?"A page took too long to load. Try again in a moment.":/invite limit|weekly.*limit|too many|rate.?limit|quota/.test(o)?"You've reached a LinkedIn sending limit for now. Wait a while, then try again.":"Something went wrong partway through. It is safe to run the command again."}function Xe({scriptName:e,mode:o,status:t,summaryLines:n,error:r,stoppedReason:s,duration:l}){let a=t==="error"||t==="stopped"?t==="error"?"\u2717":"\u26A0":t==="quota-reached"?"\u26A0":"\u2713",i=t==="error"?"stopped early":t==="stopped"?`stopped \u2014 ${s||"did not finish"}`:t==="quota-reached"?"daily limit reached":"done",u=ze[e]||e,f=o&&o!=="default"?` \xB7 ${o}`:"",g=new Date().toISOString().slice(0,16).replace("T"," "),m=l?` \xB7 ${Ke(l)}`:"",d=[];d.push(`## ${a} ${u} \u2014 ${i}`),d.push(`_${g}${f}${m}_`),d.push("");for(let N of n)d.push(`- ${N}`);if(t==="error"){d.push(""),d.push(`**What happened:** ${Qe(r)}`);let N=String(r||"").replace(/\s+/g," ").trim();N&&d.push(`_Technical detail: ${N.slice(0,140)}_`)}return d.join(`
|
|
6
|
+
`)}async function fe({scriptName:e,mode:o,status:t,summaryLines:n,error:r,stoppedReason:s,duration:l}){let a=process.env.NODE_RUN_REPORTS;if(!a||!Array.isArray(n)||n.length===0)return;let i=Xe({scriptName:e,mode:o,status:t,summaryLines:n,error:r,stoppedReason:s,duration:l});try{await ue.addMessage(a,i)}catch(u){console.error(`[runReport] Failed to post end-of-session message: ${u.message}`)}}var eo=Ze(import.meta.url),oo=_.dirname(_.dirname(eo)),z=process.env.DATA_DIR?_.resolve(process.env.DATA_DIR,"collected-profiles"):_.join(oo,"collected-profiles"),Q=_.join(z,"run-log.json");function no(e,o){let t=JSON.stringify(o,null,2),n=e+".tmp";w.writeFileSync(n,t);for(let r=0;r<3;r++)try{w.renameSync(n,e);return}catch(s){if(r<2&&(s.code==="EPERM"||s.code==="EBUSY")){let l=Date.now();for(;Date.now()-l<200;);continue}throw s}}function pe(){try{if(!w.existsSync(Q))return{runs:[]};let e=JSON.parse(w.readFileSync(Q,"utf-8"));return!e.runs||!Array.isArray(e.runs)?{runs:[]}:e}catch{return{runs:[]}}}function de(e){w.existsSync(z)||w.mkdirSync(z,{recursive:!0});try{no(Q,e)}catch(o){console.error(`[!] Failed to save run-log.json: ${o.message}`)}}function me(e,o="default"){let t=pe();for(let l of t.runs)l.status==="running"&&(l.status="interrupted",l.result="interrupted",l.timestamp&&(l.duration=Date.now()-new Date(l.timestamp).getTime()));let n=new Date,r={timestamp:n.toISOString(),script:e,mode:o,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(l=>new Date(l.timestamp).getTime()>s),de(t),{script:e,mode:o,startTime:n.getTime(),runIndex:t.runs.length-1}}function he(e,o,t=null,n=null){if(!e)return;let r=null;try{let a=pe(),i=a.runs[e.runIndex];if(i&&i.status==="running"&&i.script===e.script)i.status=o,i.result=o,i.duration=Date.now()-e.startTime,i.stats=t,i.error=n,r=i.duration;else{let u=a.runs.find(f=>f.script===e.script&&f.status==="running"&&f.timestamp===new Date(e.startTime).toISOString());u&&(u.status=o,u.result=o,u.duration=Date.now()-e.startTime,u.stats=t,u.error=n,r=u.duration)}de(a)}catch(a){console.error(`[runLog] Failed to end run: ${a.message}`)}let s=t&&Array.isArray(t.summaryLines)?t.summaryLines:null,l=t&&t.__deferReport===!0;if(s&&s.length>0&&process.env.NODE_RUN_REPORTS&&!l){let a=o==="error"?"error":t&&t.dailyLimitHit?"quota-reached":"done";fe({scriptName:e.script,mode:e.mode,status:a,summaryLines:s,error:n,duration:r??Date.now()-e.startTime}).catch(i=>console.error(`[runLog] postRunReport failed: ${i.message}`))}}import{getPluginConfig as so}from"@ilivemylife/graph-sdk";var to={day:"r86400","24h":"r86400",today:"r86400",week:"r604800","7d":"r604800",month:"r2592000","30d":"r2592000"},ge=e=>/^(1|true|yes|on)$/i.test(String(e??"").trim());function ro(e){return String(e??"").split(/[,\s|]+/).map(o=>o.trim()).filter(Boolean)}function ye(e=process.env){let o=(e.JOB_SEARCH_KEYWORDS||"").trim();if(!o)return null;let t=new URLSearchParams;t.set("keywords",o);let n=(e.JOB_SEARCH_LOCATION||"").trim();n&&t.set("location",n);let r=(e.JOB_SEARCH_GEO_ID||"").trim();r&&t.set("geoId",r);let s=parseInt(e.JOB_SEARCH_RADIUS_MILES,10);Number.isFinite(s)&&s>0&&t.set("distance",String(s)),ge(e.JOB_SEARCH_EASY_APPLY)&&t.set("f_AL","true"),ge(e.JOB_SEARCH_IN_NETWORK)&&t.set("f_JIYN","true");let l=ro(e.JOB_SEARCH_COMPANY_IDS);l.length&&t.set("f_C",l.join(","));let a=(e.JOB_SEARCH_DATE_POSTED||"").trim().toLowerCase();a&&t.set("f_TPR",to[a]||a),t.set("origin","JOB_SEARCH_PAGE_JOB_FILTER");let i="https://www.linkedin.com/jobs/search/?"+t.toString(),u=(e.JOB_SEARCH_EXTRA_PARAMS||"").trim().replace(/^[?&]+/,"");return u&&(i+="&"+u),i}var io=await so();for(let[e,o]of Object.entries(io))process.env[e]===void 0&&(process.env[e]=o);var Se=ye(process.env);Se&&(process.env.LINKEDIN_SEARCH_URL=Se);var Ln=process.env.LINKEDIN_NAME,x=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Mn=Object.freeze(new Set([x.DRAFT,x.CONFIRMED,x.NEEDS_REVIEW])),Pn=Object.freeze(new Set([x.DRAFT,x.CONFIRMED,x.REJECTED,x.NEEDS_REVIEW]));import"dotenv/config";import*as h from"fs";import*as y from"path";import{fileURLToPath as lo}from"url";var co=lo(import.meta.url),ao=y.dirname(y.dirname(co)),O=process.env.DATA_DIR?y.resolve(process.env.DATA_DIR,"collected-profiles"):y.join(ao,"collected-profiles"),Vn=y.join(O,"people.json"),Wn=y.join(O,"jobs.json"),uo=y.join(O,"quota.json"),Yn=y.join(O,"conversations.json"),Gn=y.join(O,"sync-state.json"),Hn=y.join(O,"application-questions.json"),Kn=y.join(O,"profile-history"),be=(e,o)=>{let t=parseInt(e,10);return Number.isInteger(t)&&t>=0?t:o},q=be(process.env.CONNECT_MAX_DAILY,20),V=be(process.env.CONNECT_MAX_WEEKLY,100),fo=null,po=null,T=null,mo=null,ho=null,go=null;function we(){fo=null,po=null,T=null,mo=null,ho=null,go=null}function yo(){h.existsSync(O)||h.mkdirSync(O,{recursive:!0})}function So(e,o){if(!h.existsSync(e))return null;try{let t=JSON.parse(h.readFileSync(e,"utf-8"));try{h.copyFileSync(e,e+".backup")}catch{}return t}catch(t){console.error(`[!] ${o} is corrupted: ${t.message}`),console.error(` File: ${y.resolve(e)}`);let n=e+".backup";if(h.existsSync(n))try{let r=JSON.parse(h.readFileSync(n,"utf-8"));console.error(` Restored from ${n}`);try{h.copyFileSync(n,e)}catch{}return r}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${e}.corrupted`);try{h.copyFileSync(e,e+".corrupted")}catch{}return null}}function ve(){return new Date().toISOString().split("T")[0]}function bo(){return T||(yo(),T=So(uo,"quota.json"),(!T||!T.connections)&&(T={connections:[]}),T)}function ke(){let e=bo(),o=new Date;o.setDate(o.getDate()-7);let t=o.toISOString().split("T")[0];return e.connections.filter(n=>n.date>=t)}function Ae(){let e=ke(),o=ve(),t=e.filter(i=>i.date===o).length,n=e.length,r=t>=q,s=n>=V,l=!r&&!s,a={allowed:l,daily:{sent:t,max:q},weekly:{sent:n,max:V}};return l||(a.reason=r?`Daily limit reached (${t}/${q})`:`Weekly limit reached (${n}/${V})`),a}function $e(){let e=ke(),o=ve(),t=e.filter(r=>r.date===o).length,n=e.length;return{daily:{sent:t,max:q,remaining:q-t},weekly:{sent:n,max:V,remaining:V-n}}}import"dotenv/config";import*as c from"fs";import*as ie from"os";import*as p from"path";import{fileURLToPath as tn}from"url";var ee={};B(ee,{NAME:()=>vo,VERSION:()=>wo,up:()=>$o});import*as v from"fs";import*as H from"path";var wo=1,vo="normalize-jobs-and-questions",ko=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],Ao=50;function X(e){return v.existsSync(e)?JSON.parse(v.readFileSync(e,"utf-8")):null}function Z(e,o){let t=JSON.stringify(o,null,2),n=e+".tmp";try{v.writeFileSync(n,t)}catch(r){try{v.unlinkSync(n)}catch{}throw r}try{v.renameSync(n,e)}catch(r){try{v.unlinkSync(n)}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 $o(e,o){let t=H.join(e,"jobs.json"),n=H.join(o,"scouted-jobs.json"),r=H.join(e,"application-questions.json"),s=X(t)||{},l=X(n)||{},a=0,i=[];for(let f of Object.keys(s)){if(!l[f])continue;let g=l[f],m=s[f];for(let d of ko)g[d]!=null&&m[d]==null&&(m[d]=g[d]);i.push(f),a++}a>0?(Z(t,s),console.log(` Phase 1: Merged ${a} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let u=X(r);if(u&&Array.isArray(u.applications)){let f={},g=0;for(let m of u.applications){let d=m.jobId||"unknown";f[d]||(f[d]={applications:[]});let N=(m.questions||[]).map(j=>{let U={type:j.type||"input",question:j.question||"",answer:j.answer||""};return j.options&&(j.options.length<=Ao?U.options=j.options:(U.optionsOmitted=!0,g++)),j.page&&(U.page=j.page),j.wasPreFilled&&(U.wasPreFilled=!0),j.wasRetry&&(U.wasRetry=!0),U});f[d].applications.push({applicationId:m.applicationId,date:m.date,result:m.result||"submitted",formPages:m.formPages||null,duration:m.duration||null,retries:m.retries||0,failedField:m.failedField||null,questionCount:m.questionCount||N.length,questions:N})}Z(r,f),console.log(` Phase 2: Rekeyed ${u.applications.length} applications by jobId (${Object.keys(f).length} unique jobs)`),g>0&&console.log(` Phase 2: Stripped bloated options from ${g} 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(i.length>0){for(let f of i)delete l[f];Z(n,l),console.log(` Phase 3: Removed ${i.length} merged entries from scouted-jobs.json (${Object.keys(l).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var oe={};B(oe,{NAME:()=>jo,VERSION:()=>Eo,up:()=>Io});import*as k from"fs";import*as Ee from"path";var Eo=2,jo="reset-unread-flags";function Ro(e){return k.existsSync(e)?JSON.parse(k.readFileSync(e,"utf-8")):null}function Oo(e,o){let t=JSON.stringify(o,null,2),n=e+".tmp";try{k.writeFileSync(n,t)}catch(r){try{k.unlinkSync(n)}catch{}throw r}try{k.renameSync(n,e)}catch(r){try{k.unlinkSync(n)}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 Io(e){let o=Ee.join(e,"conversations.json"),t=Ro(o);if(!t){console.log(" conversations.json not found \u2014 nothing to reset.");return}let n=0;for(let r of Object.keys(t))t[r].unread===!0&&(t[r].unread=!1,n++);if(n===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}Oo(o,t),console.log(` Reset unread=false on ${n} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var ne={};B(ne,{NAME:()=>To,VERSION:()=>_o,up:()=>Fo});import*as A from"fs";import*as je from"path";var _o=3,To="recompute-last-message-by",Do=new Set(["draft","confirmed","rejected","needs_review"]);function Co(e){return A.existsSync(e)?JSON.parse(A.readFileSync(e,"utf-8")):null}function No(e,o){let t=JSON.stringify(o,null,2),n=e+".tmp";try{A.writeFileSync(n,t)}catch(r){try{A.unlinkSync(n)}catch{}throw r}try{A.renameSync(n,e)}catch(r){try{A.unlinkSync(n)}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 xo(e,o){if(!e||e.length===0)return"them";let t=e.filter(s=>!Do.has(s.status));if(t.length===0)return"them";let n=t.map(s=>({m:s,t:Date.parse(s.time)})).filter(s=>Number.isFinite(s.t)).sort((s,l)=>l.t-s.t).map(s=>s.m),r=n.length>0?n:[...t].reverse();for(let s of r){let l=s.sender;if(l===o)return"me";if(l!=="Unknown"&&l!=="")return"them"}return"them"}async function Fo(e){let o=je.join(e,"conversations.json"),t=Co(o);if(!t){console.log(" conversations.json not found \u2014 nothing to recompute.");return}let n=process.env.LINKEDIN_NAME;if(!n||typeof n!="string"||!n.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,l=0;for(let a of Object.keys(t)){let i=t[a];if(!i||typeof i!="object")continue;Object.prototype.hasOwnProperty.call(i,"_cardSynced")&&(delete i._cardSynced,s++);let u=Array.isArray(i.messages)?i.messages:[],f=xo(u,n),g=f==="me"?"awaiting_reply":"unanswered_by_us";i.lastMessageBy!==f&&l++,i.lastMessageBy=f,i.conversationStatus=g,r++}if(r===0){console.log(" No conversations to recompute.");return}No(o,t),console.log(` Recomputed lastMessageBy + conversationStatus on ${r} conversations.`),console.log(` ${l} 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 te={};B(te,{NAME:()=>Mo,VERSION:()=>Lo,up:()=>Bo});import*as $ from"fs";import*as Re from"path";var Lo=4,Mo="split-connection-timestamps",Po=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function Uo(e){if(!$.existsSync(e))return null;let o=$.readFileSync(e,"utf-8");return o.charCodeAt(0)===65279&&(o=o.slice(1)),JSON.parse(o)}function Jo(e,o){let t=JSON.stringify(o,null,2),n=e+".tmp";try{$.writeFileSync(n,t)}catch(r){try{$.unlinkSync(n)}catch{}throw r}try{$.renameSync(n,e)}catch(r){try{$.unlinkSync(n)}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 Bo(e){let o=Re.join(e,"people.json"),t=Uo(o);if(!t||typeof t!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let n=0,r=0;for(let s of Object.keys(t)){let l=t[s];!l||typeof l!="object"||(r++,Po.has(l.connectionStatus)&&l.connectionDate&&!l.requestedConnectionAt&&(l.requestedConnectionAt=l.connectionDate,l.connectionDate=null,n++))}if(n===0){console.log(` Scanned ${r} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}Jo(o,t),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${n} still-pending people (of ${r} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}var re={};B(re,{NAME:()=>Vo,VERSION:()=>qo,up:()=>Ho});import*as E from"fs";import*as Oe from"path";var qo=5,Vo="rename-headline-to-title",F=/[·•]\s*(1st|2nd|3rd)\+?/i,Wo=e=>(e||"").replace(/\s+/g," ").trim(),W=e=>Wo(e).replace(/^[+·•\s]+/,"").replace(/[·•\s]+$/,"");function Yo(e){if(!E.existsSync(e))return null;let o=E.readFileSync(e,"utf-8");return o.charCodeAt(0)===65279&&(o=o.slice(1)),JSON.parse(o)}function Go(e,o){let t=JSON.stringify(o),n=e+".tmp";try{E.writeFileSync(n,t)}catch(r){try{E.unlinkSync(n)}catch{}throw r}try{E.renameSync(n,e)}catch(r){try{E.unlinkSync(n)}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 Ho(e,o){let t=Oe.join(o,"discovered-people.json"),n=Yo(t);if(!n||typeof n!="object"){console.log(" discovered-people.json not found \u2014 nothing to migrate.");return}let r=Array.isArray(n)?n:Object.values(n),s=0,l=0,a=0;for(let i of r)if(!(!i||typeof i!="object")){if(s++,i.name&&F.test(i.name)){let u=W(String(i.name).split(F)[0]),f=String(i.name).match(/[·•]\s*(?:1st|2nd|3rd)\+?\s*(.+)$/i),g=f?W(f[1]):"";u&&(i.name=u,l++),g&&(!i.headline||F.test(String(i.headline))||!W(i.headline))&&(i.headline=g)}if(Object.prototype.hasOwnProperty.call(i,"headline")){let u=W(i.headline||"");F.test(u)&&(u=""),(!i.title||F.test(String(i.title)))&&(i.title=u||(i.title&&!F.test(String(i.title))?i.title:null)||null),delete i.headline,a++}else if(typeof i.title=="string"){let u=W(i.title);u&&!F.test(u)&&u!==i.title&&(i.title=u)}}if(a===0&&l===0){console.log(` Scanned ${s} discovered people \u2014 already unified (no headline field, clean names).`);return}Go(t,n),console.log(` discovered-people.json: scanned ${s}, de-glued ${l} names, moved ${a} headline\u2192title.`),console.log(" Every record now carries a single `title` field (matches people.json).")}import"dotenv/config";import*as b from"path";import{fileURLToPath as Ko}from"url";var zo=Ko(import.meta.url),Qo=b.dirname(b.dirname(zo)),Y=process.env.DATA_DIR?b.resolve(process.env.DATA_DIR,"market-research"):b.join(Qo,"market-research"),tt=b.join(Y,"scouted-jobs.json"),rt=b.join(Y,"discovered-people.json"),st=b.join(Y,"visit-log.json"),it=b.join(Y,"companies.json"),lt=b.join(Y,"job-decisions.json");function Ie(){Xo=null,Zo=null,en=null,on=null,nn=null}var Xo=null;var Zo=null;var en=null;var on=null;var nn=null;var rn=tn(import.meta.url),sn=p.dirname(rn),ln=p.dirname(p.dirname(sn));function cn(e){return e&&(e==="~"?ie.homedir():e.startsWith("~/")||e.startsWith("~\\")?p.join(ie.homedir(),e.slice(2)):e)}var R=process.env.DATA_DIR?p.resolve(cn(process.env.DATA_DIR)):ln,M=p.join(R,"collected-profiles"),P=p.join(R,"market-research"),S=p.join(R,".schema-version"),_e=[p.join(M,".schema-version"),p.join(P,".schema-version")],D=5,I=[{version:1,module:ee},{version:2,module:oe},{version:3,module:ne},{version:4,module:te},{version:5,module:re}];(function(){I.sort((n,r)=>n.version-r.version);let o=new Set;for(let n of I){if(!Number.isInteger(n.version)||n.version<1)throw new Error(`MIGRATION_REGISTRY: invalid version ${JSON.stringify(n.version)} (must be positive integer)`);if(o.has(n.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${n.version}`);o.add(n.version);let r=n.module;if(!r||typeof r.up!="function")throw new Error(`MIGRATION_REGISTRY: v${n.version} module is missing up()`);if(r.VERSION!==void 0&&r.VERSION!==n.version)throw new Error(`MIGRATION_REGISTRY: v${n.version} entry does not match module VERSION (${r.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let t=I.length?I[I.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 n=0;n<I.length;n++){let r=n+1;if(I[n].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${n} but found v${I[n].version}`)}})();function Ne(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
7
7
|
[FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
|
|
8
8
|
`),process.exit(1));try{c.mkdirSync(R,{recursive:!0})}catch(o){o.code!=="EEXIST"&&(console.error(`
|
|
9
9
|
[FATAL] Cannot create DATA_DIR (${R}): ${o.message}`),console.error(` Fix the path or permissions and try again.
|
|
@@ -11,41 +11,41 @@ var Ue=Object.defineProperty;var V=(e,o)=>{for(var n in o)Ue(e,n,{get:o[n],enume
|
|
|
11
11
|
[FATAL] DATA_DIR (${R}) is not accessible: ${o.message}
|
|
12
12
|
`),process.exit(1)}e.isDirectory()||(console.error(`
|
|
13
13
|
[FATAL] DATA_DIR (${R}) 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.
|
|
14
|
-
`),process.exit(1));for(let o of[
|
|
14
|
+
`),process.exit(1));for(let o of[M,P]){let t;try{t=c.lstatSync(o)}catch(n){if(n.code==="ENOENT")continue;throw n}t.isSymbolicLink()&&(console.error(`
|
|
15
15
|
[FATAL] Data subdirectory is a symbolic link: ${o}`),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.
|
|
16
|
-
`),process.exit(1))}}var
|
|
17
|
-
[FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${o.pid}`),console.error(` Started at: ${o.startedAt||"(unknown)"}`),console.error(` Lock file: ${
|
|
16
|
+
`),process.exit(1))}}var L=p.join(R,".migration-lock");function an(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return c.writeFileSync(L,e,{flag:"wx"}),!0}catch(n){if(n.code!=="EEXIST")throw n}let o;try{o=JSON.parse(c.readFileSync(L,"utf-8"))}catch{o=null}if(o&&Number.isInteger(o.pid)){let n=!1;try{process.kill(o.pid,0),n=!0}catch(l){l.code==="EPERM"&&(n=!0)}let r=24*60*60*1e3,s=1/0;if(o.startedAt){let l=Date.parse(o.startedAt);Number.isNaN(l)||(s=Date.now()-l)}n&&s<r&&(console.error(`
|
|
17
|
+
[FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${o.pid}`),console.error(` Started at: ${o.startedAt||"(unknown)"}`),console.error(` Lock file: ${L}
|
|
18
18
|
`),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.
|
|
19
|
-
`),process.exit(1)),
|
|
19
|
+
`),process.exit(1)),n&&s>=r&&console.log(` Lock holder PID ${o.pid} is alive but lock is older than 24h \u2014 assuming PID reuse, taking over.`)}console.log(` Stale migration lock from PID ${o?.pid??"?"} found \u2014 taking over.`);let t=L+".tmp";try{return c.writeFileSync(t,e),c.renameSync(t,L),!0}catch(n){try{c.unlinkSync(t)}catch{}throw new Error(`Failed to take over stale migration lock: ${n.message}`)}}function le(){try{if(JSON.parse(c.readFileSync(L,"utf-8")).pid!==process.pid)return;c.unlinkSync(L)}catch{}}var Te=!1;function un(){if(Te)return;Te=!0;let e=()=>{try{le()}catch{}process.exit(1)};for(let o of["SIGINT","SIGTERM","SIGHUP"])try{process.on(o,e)}catch{}}function fn(){if(c.existsSync(S))return;let e=[],o=[];for(let s of _e)if(c.existsSync(s))try{e.push({file:s,schema:K(s)})}catch(l){o.push({file:s,err:l.message})}if(o.length>0){console.error(`
|
|
20
20
|
[FATAL] Legacy .schema-version file(s) corrupted \u2014 cannot determine current schema version:`);for(let s of o)console.error(` ${s.file}: ${s.err}`);console.error(`
|
|
21
21
|
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.
|
|
22
|
-
`),process.exit(1)}if(e.length===0)return;let
|
|
22
|
+
`),process.exit(1)}if(e.length===0)return;let t=e.map(s=>s.schema.version);if(new Set(t).size>1){console.error(`
|
|
23
23
|
[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.
|
|
24
|
-
`),process.exit(1)}let
|
|
25
|
-
[FATAL] ${
|
|
26
|
-
`),process.exit(1)}let o=
|
|
27
|
-
[FATAL] ${
|
|
28
|
-
`),process.exit(1)),o}function
|
|
29
|
-
[FATAL] Your data schema is at v${o}, but this plugin build only understands up to v${
|
|
30
|
-
`),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${
|
|
24
|
+
`),process.exit(1)}let n=e[0].schema,r=S+".tmp";try{c.writeFileSync(r,JSON.stringify(n,null,2)),c.renameSync(r,S)}catch(s){try{c.unlinkSync(r)}catch{}throw s}for(let s of _e)if(c.existsSync(s))try{c.unlinkSync(s)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${S}`)}function pn(e){if(e===null||typeof e!="object"||Array.isArray(e))return null;let o=Number(e.version);return!Number.isFinite(o)||o<0||!Number.isInteger(o)?null:(e.version=o,Array.isArray(e.migrations)||(e.migrations=[]),e)}function K(e){let o=c.readFileSync(e,"utf-8");return o.charCodeAt(0)===65279&&(o=o.slice(1)),JSON.parse(o)}function De(){if(fn(),!c.existsSync(S))return{version:0,migrations:[]};let e;try{e=K(S)}catch(t){if(t.code==="ENOENT")return{version:0,migrations:[]};console.error(`
|
|
25
|
+
[FATAL] ${S} 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.
|
|
26
|
+
`),process.exit(1)}let o=pn(e);return o===null&&(console.error(`
|
|
27
|
+
[FATAL] ${S} 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.
|
|
28
|
+
`),process.exit(1)),o}function xe(e){try{c.chmodSync(e,384)}catch{}}function dn(e){if(Ne(),c.existsSync(S))try{if(c.lstatSync(S).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${S}. 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 o=S+".tmp";try{c.writeFileSync(o,JSON.stringify(e,null,2)),xe(o),c.renameSync(o,S)}catch(t){try{c.unlinkSync(o)}catch{}throw t}}function Ce(e,o){if(!c.existsSync(e))return;let t=`.pre-v${String(o).padStart(3,"0")}.backup`,n=c.readdirSync(e).filter(a=>{let i=a.toLowerCase();if(i.includes(".backup")||i===".schema-version"||i.endsWith(".tmp"))return!1;try{return c.statSync(p.join(e,a)).isFile()}catch{return!1}}),r=0,s=0,l=[];for(let a of n){let i=p.join(e,a),u=p.join(e,a+t);if(c.existsSync(u)){s++;continue}try{Le(i,u),r++}catch(f){l.push({file:a,err:f.message})}}if(l.length>0){let a=new Error(`Failed to back up ${l.length} file(s) in ${p.basename(e)}/: `+l.map(i=>`${i.file} (${i.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 ${p.basename(e)}/ (${t})${a}`)}}var se=!1;async function Fe(){if(se)return;Ne(),Sn();let o=De().version;if(o===D){se=!0;return}un(),an(),process.on("exit",le),o>D&&(console.error(`
|
|
29
|
+
[FATAL] Your data schema is at v${o}, 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.
|
|
30
|
+
`),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}.
|
|
31
31
|
`),process.exit(1)),console.log(`
|
|
32
|
-
\u{1F4E6} Schema migration: v${o} \u2192 v${
|
|
33
|
-
[FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let r of
|
|
32
|
+
\u{1F4E6} Schema migration: v${o} \u2192 v${D}`);let t=bn();if(!t.ok){console.error(`
|
|
33
|
+
[FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let r of t.broken)console.error(` ${r.dir}/${r.file}: ${r.err}`);console.error(`
|
|
34
34
|
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'.
|
|
35
|
-
`),process.exit(1)}let
|
|
36
|
-
Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,
|
|
37
|
-
[FATAL] Pre-migration backup failed for ${s}: ${
|
|
38
|
-
`),process.exit(1)}let a=r.module;try{await a.up(
|
|
39
|
-
[FATAL] Migration ${s} failed: ${
|
|
40
|
-
`)):(console.error(` [!] Auto-rollback INCOMPLETE: ${u.error}`),console.error(` Manual recovery: copy *${
|
|
41
|
-
`))}catch(u){console.error(` [!] Auto-rollback CRASHED while restoring: ${u.message}`),console.error(` Manual recovery: copy *${
|
|
42
|
-
`)}process.exit(1)}try{let
|
|
43
|
-
[FATAL] Migration ${s} applied successfully but schema version file could NOT be updated: ${
|
|
44
|
-
`),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{
|
|
45
|
-
\u2713 Schema is now at v${
|
|
46
|
-
`)}var
|
|
47
|
-
${"\u2550".repeat(50)}`),console.log(` STEP: ${e}`),console.log("\u2550".repeat(50)),
|
|
48
|
-
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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 o=
|
|
49
|
-
\u26A0 Funnel skipped: ${s.reason}`),
|
|
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(" 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,
|
|
51
|
-
`);let r=Object.values(
|
|
35
|
+
`),process.exit(1)}let n=I.filter(r=>r.version>o);for(let r of n){console.log(`
|
|
36
|
+
Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,l=`.pre-${s}.backup`;try{Ce(M,r.version),Ce(P,r.version)}catch(i){console.error(`
|
|
37
|
+
[FATAL] Pre-migration backup failed for ${s}: ${i.message}`),console.error(" Migration NOT applied. Repair the underlying issue (disk space, permissions, locked files)"),console.error(` and re-run the plugin command.
|
|
38
|
+
`),process.exit(1)}let a=r.module;try{await a.up(M,P)}catch(i){console.error(`
|
|
39
|
+
[FATAL] Migration ${s} failed: ${i.message}`),console.error(` Attempting auto-rollback from ${l} files...`);try{let u=wn(l);u.ok?(console.error(` \u2713 Auto-rollback restored ${u.restored} files. Schema stays at v${o}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
|
|
40
|
+
`)):(console.error(` [!] Auto-rollback INCOMPLETE: ${u.error}`),console.error(` Manual recovery: copy *${l} files back over the originals.
|
|
41
|
+
`))}catch(u){console.error(` [!] Auto-rollback CRASHED while restoring: ${u.message}`),console.error(` Manual recovery: copy *${l} files back over the originals.
|
|
42
|
+
`)}process.exit(1)}try{let i=new Date().toISOString(),u={version:r.version,name:a.NAME||s,appliedAt:i},f=De();f.version=r.version,f.migratedAt=i,f.migrations=f.migrations||[],f.migrations.push(u),dn(f)}catch(i){console.error(`
|
|
43
|
+
[FATAL] Migration ${s} applied successfully but schema version file could NOT be updated: ${i.message}`),console.error(` Your data is in the v${r.version} state but .schema-version still shows v${o}.`),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.
|
|
44
|
+
`),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{we()}catch{}try{Ie()}catch{}se=!0,le(),console.log(`
|
|
45
|
+
\u2713 Schema is now at v${D}
|
|
46
|
+
`)}var mn=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function hn(e){let o=e.toLowerCase();return mn.some(t=>t.test(o))}var gn=6e4;function yn(){let e=Date.now(),o=[];for(let t of[R,M,P]){if(!c.existsSync(t))continue;let n;try{n=c.readdirSync(t)}catch{continue}for(let r of n){if(!hn(r))continue;let s=p.join(t,r);try{let l=c.statSync(s);if(!l.isFile()||e-l.mtimeMs<gn)continue;o.push({dir:t,file:r,fullPath:s})}catch{}}}return o}function Sn({verbose:e=!1}={}){let o=yn();if(o.length===0)return e&&console.log(" No orphan .tmp files found."),0;let t=0;for(let n of o)try{c.unlinkSync(n.fullPath),t++,e&&console.log(` Removed orphan: ${p.basename(n.dir)}/${n.file}`)}catch(r){console.warn(` [!] Could not remove orphan ${n.fullPath}: ${r.message}`)}return!e&&t>0&&console.log(` Cleaned up ${t} orphan .tmp file(s) from previous run.`),t}function bn(){let e=[];for(let o of[M,P]){if(!c.existsSync(o))continue;let t=c.readdirSync(o).filter(n=>{let r=n.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let n of t){let r=p.join(o,n);try{K(r)}catch(s){e.push({dir:p.basename(o),file:n,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function wn(e){let o=[],t=[];for(let s of[M,P]){if(!c.existsSync(s))continue;let l=c.readdirSync(s).filter(a=>a.endsWith(e));for(let a of l){let i=p.join(s,a),u=a.slice(0,-e.length),f=p.join(s,u);try{u.toLowerCase().endsWith(".json")?K(i):c.accessSync(i,c.constants.R_OK),o.push({backupPath:i,originalPath:f,fileName:a,dir:s})}catch(g){t.push(`${p.basename(s)}/${a}: ${g.message}`)}}}if(t.length>0)return{ok:!1,error:t.join("; "),restored:0};let n=0,r=[];for(let{backupPath:s,originalPath:l,fileName:a,dir:i}of o)try{Le(s,l),n++}catch(u){r.push(`${p.basename(i)}/${a}: ${u.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:n}:{ok:!0,restored:n}}function Le(e,o){let t=o+".tmp";try{c.copyFileSync(e,t),xe(t)}catch(n){try{c.unlinkSync(t)}catch{}throw n}try{c.renameSync(t,o)}catch(n){try{c.unlinkSync(t)}catch{}if(n.code==="EPERM"||n.code==="EBUSY"){let r=new Error(`File locked: ${o} (${n.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=n.code,r}throw n}}await Fe();var G=process.argv.slice(2),ce=new Set((G.find(e=>e.startsWith("--skip="))?.split("=")[1]||"").split(",").filter(Boolean)),Me=new Set((G.find(e=>e.startsWith("--only="))?.split("=")[1]||"").split(",").filter(Boolean)),Je=G.includes("--dry-run"),Be=G.includes("--jobs"),qe=G.includes("--comms"),Pe=["apply-queue","apply","funnel","scout","visit"],Ue=["sync","today"],Ve=Be?Pe:qe?Ue:[...Pe,...Ue];function C(e){return Me.size>0?Me.has(e):!ce.has(e)&&Ve.includes(e)}function J(e,o,t=[],{optional:n=!1}={}){if(console.log(`
|
|
47
|
+
${"\u2550".repeat(50)}`),console.log(` STEP: ${e}`),console.log("\u2550".repeat(50)),Je)return console.log(` [DRY RUN] Would run: node ${o} ${t.join(" ")}`),!0;try{return vn("node",[o,...t],{stdio:"inherit",timeout:18e6}),console.log(` \u2713 ${e} completed`),!0}catch(r){return n?(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 kn(){let e=Be?"jobs":qe?"comms":"full";console.log(`
|
|
48
|
+
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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 o=Ve.filter(C);console.log(` Steps: ${o.join(" \u2192 ")}`),ce.size>0&&console.log(` Skipping: ${[...ce].join(", ")}`),Je&&console.log(" [DRY RUN MODE]");let t=me("daily",e),n={};if(C("apply-queue")&&(n["apply-queue"]=J("Apply Queue (scored jobs)","applyQueue.mjs",["--max=50","--min-score=50"],{optional:!0})),C("apply")){let s=$e();n.apply=J("Apply from Search","run.mjs",[],{optional:!0})}if(C("funnel")&&!C("apply")){let s=Ae();s.allowed?n.funnel=J("Connection Funnel","funnelRunner.mjs",["--max=20"],{optional:!0}):(console.log(`
|
|
49
|
+
\u26A0 Funnel skipped: ${s.reason}`),n.funnel="skipped_quota")}C("scout")&&(n.scout=J("Scout Jobs for Tomorrow","scout.mjs",["--max=300","--verbose"],{optional:!0})),C("sync")&&(n.sync=J("Sync Inbox","syncAll.mjs")),C("today")&&(n.today=J("Daily Report","syncAll.mjs",["--today"])),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(" 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,l]of Object.entries(n))console.log(` ${l===!0?"\u2713":l===!1?"\u2717":"\u26A0"} ${s}: ${l===!0?"success":l===!1?"failed":l}`);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
|
|
51
|
+
`);let r=Object.values(n).some(s=>s===!1);he(t,r?"partial":"success",n)}kn().catch(e=>{console.error("Daily pipeline failed:",e),process.exit(1)});
|