ilml-plugin-linkedin 1.19.2 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/dist/applyQueue.mjs +33 -33
- package/dist/connect.mjs +80 -78
- package/dist/daily.mjs +34 -34
- package/dist/enrichProfile.mjs +15 -15
- package/dist/enrichProfiles.mjs +40 -40
- package/dist/funnelRunner.mjs +60 -60
- package/dist/messageBot.mjs +54 -54
- package/dist/migrationCli.mjs +26 -26
- package/dist/quota.mjs +36 -36
- package/dist/run.mjs +73 -73
- package/dist/scout.mjs +30 -30
- package/dist/syncAll.mjs +112 -112
- package/dist/syncConnections.mjs +50 -50
- package/dist/verifyAbout.mjs +12 -12
- package/dist/version.mjs +1 -1
- package/dist/viewers.mjs +18 -18
- package/dist/visit.mjs +39 -39
- package/ilml-plugin.json +1 -1
- package/package.json +1 -1
package/dist/migrationCli.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var ke=Object.defineProperty;var P=(e,o)=>{for(var n in o)ke(e,n,{get:o[n],enumerable:!0})};import"dotenv/config";import"dotenv/config";import*as i from"fs";import*as K from"os";import*as l from"path";import{fileURLToPath as uo}from"url";var q={};P(q,{NAME:()=>Ae,VERSION:()=>we,up:()=>Ee});import*as A from"fs";import*as J from"path";var we=1,Ae="normalize-jobs-and-questions",je=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],$e=50;function V(e){return A.existsSync(e)?JSON.parse(A.readFileSync(e,"utf-8")):null}function W(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{A.writeFileSync(t,n)}catch(s){try{A.unlinkSync(t)}catch{}throw s}try{A.renameSync(t,e)}catch(s){try{A.unlinkSync(t)}catch{}if(s.code==="EPERM"||s.code==="EBUSY"){let r=new Error(`File locked: ${e} (${s.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw r.code=s.code,r}throw s}}async function Ee(e,o){let n=J.join(e,"jobs.json"),t=J.join(o,"scouted-jobs.json"),s=J.join(e,"application-questions.json"),r=V(n)||{},c=V(t)||{},I=0,u=[];for(let f of Object.keys(r)){if(!c[f])continue;let b=c[f],d=r[f];for(let O of je)b[O]!=null&&d[O]==null&&(d[O]=b[O]);u.push(f),I++}I>0?(W(n,r),console.log(` Phase 1: Merged ${I} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let p=V(s);if(p&&Array.isArray(p.applications)){let f={},b=0;for(let d of p.applications){let O=d.jobId||"unknown";f[O]||(f[O]={applications:[]});let T=(d.questions||[]).map(g=>{let v={type:g.type||"input",question:g.question||"",answer:g.answer||""};return g.options&&(g.options.length<=$e?v.options=g.options:(v.optionsOmitted=!0,b++)),g.page&&(v.page=g.page),g.wasPreFilled&&(v.wasPreFilled=!0),g.wasRetry&&(v.wasRetry=!0),v});f[O].applications.push({applicationId:d.applicationId,date:d.date,result:d.result||"submitted",formPages:d.formPages||null,duration:d.duration||null,retries:d.retries||0,failedField:d.failedField||null,questionCount:d.questionCount||T.length,questions:T})}W(s,f),console.log(` Phase 2: Rekeyed ${p.applications.length} applications by jobId (${Object.keys(f).length} unique jobs)`),b>0&&console.log(` Phase 2: Stripped bloated options from ${b} questions`)}else p&&!p.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(u.length>0){for(let f of u)delete c[f];W(t,c),console.log(` Phase 3: Removed ${u.length} merged entries from scouted-jobs.json (${Object.keys(c).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var Y={};P(Y,{NAME:()=>Oe,VERSION:()=>Ie,up:()=>De});import*as j from"fs";import*as X from"path";var Ie=2,Oe="reset-unread-flags";function Re(e){return j.existsSync(e)?JSON.parse(j.readFileSync(e,"utf-8")):null}function Ne(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{j.writeFileSync(t,n)}catch(s){try{j.unlinkSync(t)}catch{}throw s}try{j.renameSync(t,e)}catch(s){try{j.unlinkSync(t)}catch{}if(s.code==="EPERM"||s.code==="EBUSY"){let r=new Error(`File locked: ${e} (${s.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw r.code=s.code,r}throw s}}async function De(e){let o=X.join(e,"conversations.json"),n=Re(o);if(!n){console.log(" conversations.json not found \u2014 nothing to reset.");return}let t=0;for(let s of Object.keys(n))n[s].unread===!0&&(n[s].unread=!1,t++);if(t===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}Ne(o,n),console.log(` Reset unread=false on ${t} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var G={};P(G,{NAME:()=>Ce,VERSION:()=>Te,up:()=>Me});import*as $ from"fs";import*as Z from"path";var Te=3,Ce="recompute-last-message-by",xe=new Set(["draft","confirmed","rejected","needs_review"]);function _e(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function Fe(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{$.writeFileSync(t,n)}catch(s){try{$.unlinkSync(t)}catch{}throw s}try{$.renameSync(t,e)}catch(s){try{$.unlinkSync(t)}catch{}if(s.code==="EPERM"||s.code==="EBUSY"){let r=new Error(`File locked: ${e} (${s.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw r.code=s.code,r}throw s}}function Le(e,o){if(!e||e.length===0)return"them";let n=e.filter(r=>!xe.has(r.status));if(n.length===0)return"them";let t=n.map(r=>({m:r,t:Date.parse(r.time)})).filter(r=>Number.isFinite(r.t)).sort((r,c)=>c.t-r.t).map(r=>r.m),s=t.length>0?t:[...n].reverse();for(let r of s){let c=r.sender;if(c===o)return"me";if(c!=="Unknown"&&c!=="")return"them"}return"them"}async function Me(e){let o=Z.join(e,"conversations.json"),n=_e(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 s=0,r=0,c=0;for(let I of Object.keys(n)){let u=n[I];if(!u||typeof u!="object")continue;Object.prototype.hasOwnProperty.call(u,"_cardSynced")&&(delete u._cardSynced,r++);let p=Array.isArray(u.messages)?u.messages:[],f=Le(p,t),b=f==="me"?"awaiting_reply":"unanswered_by_us";u.lastMessageBy!==f&&c++,u.lastMessageBy=f,u.conversationStatus=b,s++}if(s===0){console.log(" No conversations to recompute.");return}Fe(o,n),console.log(` Recomputed lastMessageBy + conversationStatus on ${s} conversations.`),console.log(` ${c} had stale lastMessageBy (now corrected).`),r>0&&console.log(` Cleaned ${r} leftover _cardSynced flags.`),console.log(" Re-run 'ilml linkedin enrich' if you want actionNeeded / summary / autoTags to also update.")}var H={};P(H,{NAME:()=>Je,VERSION:()=>Pe,up:()=>We});import*as E from"fs";import*as ee from"path";var Pe=4,Je="split-connection-timestamps",Ue=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function Be(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 Ve(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{E.writeFileSync(t,n)}catch(s){try{E.unlinkSync(t)}catch{}throw s}try{E.renameSync(t,e)}catch(s){try{E.unlinkSync(t)}catch{}if(s.code==="EPERM"||s.code==="EBUSY"){let r=new Error(`File locked: ${e} (${s.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw r.code=s.code,r}throw s}}async function We(e){let o=ee.join(e,"people.json"),n=Be(o);if(!n||typeof n!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let t=0,s=0;for(let r of Object.keys(n)){let c=n[r];!c||typeof c!="object"||(s++,Ue.has(c.connectionStatus)&&c.connectionDate&&!c.requestedConnectionAt&&(c.requestedConnectionAt=c.connectionDate,c.connectionDate=null,t++))}if(t===0){console.log(` Scanned ${s} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}Ve(o,n),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${t} still-pending people (of ${s} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}import{getPluginConfig as qe}from"@ilivemylife/graph-sdk";var Ye=await qe();for(let[e,o]of Object.entries(Ye))process.env[e]===void 0&&(process.env[e]=o);var Oo=process.env.LINKEDIN_NAME,C=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Ro=Object.freeze(new Set([C.DRAFT,C.CONFIRMED,C.NEEDS_REVIEW])),No=Object.freeze(new Set([C.DRAFT,C.CONFIRMED,C.REJECTED,C.NEEDS_REVIEW]));import"dotenv/config";import*as y from"path";import{fileURLToPath as Ge}from"url";var He=Ge(import.meta.url),Ke=y.dirname(y.dirname(He)),x=process.env.DATA_DIR?y.resolve(process.env.DATA_DIR,"collected-profiles"):y.join(Ke,"collected-profiles"),_o=y.join(x,"people.json"),Fo=y.join(x,"jobs.json"),Lo=y.join(x,"quota.json"),Mo=y.join(x,"conversations.json"),Po=y.join(x,"sync-state.json"),Jo=y.join(x,"application-questions.json"),Uo=y.join(x,"profile-history"),oe=(e,o)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:o},Bo=oe(process.env.CONNECT_MAX_DAILY,20),Vo=oe(process.env.CONNECT_MAX_WEEKLY,100),ze=null,Qe=null,Xe=null,Ze=null,eo=null,oo=null;function ne(){ze=null,Qe=null,Xe=null,Ze=null,eo=null,oo=null}import"dotenv/config";import*as k from"path";import{fileURLToPath as no}from"url";var to=no(import.meta.url),so=k.dirname(k.dirname(to)),L=process.env.DATA_DIR?k.resolve(process.env.DATA_DIR,"market-research"):k.join(so,"market-research"),Go=k.join(L,"scouted-jobs.json"),Ho=k.join(L,"discovered-people.json"),Ko=k.join(L,"visit-log.json"),zo=k.join(L,"companies.json"),Qo=k.join(L,"job-decisions.json");function te(){ro=null,io=null,co=null,lo=null,ao=null}var ro=null;var io=null;var co=null;var lo=null;var ao=null;var fo=uo(import.meta.url),po=l.dirname(fo),ho=l.dirname(l.dirname(po));function mo(e){return e&&(e==="~"?K.homedir():e.startsWith("~/")||e.startsWith("~\\")?l.join(K.homedir(),e.slice(2)):e)}var S=process.env.DATA_DIR?l.resolve(mo(process.env.DATA_DIR)):ho,N=l.join(S,"collected-profiles"),D=l.join(S,"market-research"),m=l.join(S,".schema-version"),se=[l.join(N,".schema-version"),l.join(D,".schema-version")],U=4,R=[{version:1,module:q},{version:2,module:Y},{version:3,module:G},{version:4,module:H}];(function(){R.sort((t,s)=>t.version-s.version);let o=new Set;for(let t of R){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 s=t.module;if(!s||typeof s.up!="function")throw new Error(`MIGRATION_REGISTRY: v${t.version} module is missing up()`);if(s.VERSION!==void 0&&s.VERSION!==t.version)throw new Error(`MIGRATION_REGISTRY: v${t.version} entry does not match module VERSION (${s.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let n=R.length?R[R.length-1].version:0;if(n!==U)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${U}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let t=0;t<R.length;t++){let s=t+1;if(R[t].version!==s)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${s} at position ${t} but found v${R[t].version}`)}})();function le(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
1
|
+
var ve=Object.defineProperty;var P=(e,o)=>{for(var n in o)ve(e,n,{get:o[n],enumerable:!0})};import"dotenv/config";import"dotenv/config";import*as i from"fs";import*as K from"os";import*as c from"path";import{fileURLToPath as uo}from"url";var W={};P(W,{NAME:()=>Ae,VERSION:()=>we,up:()=>Ee});import*as A from"fs";import*as U from"path";var we=1,Ae="normalize-jobs-and-questions",je=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],$e=50;function V(e){return A.existsSync(e)?JSON.parse(A.readFileSync(e,"utf-8")):null}function q(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}}async function Ee(e,o){let n=U.join(e,"jobs.json"),t=U.join(o,"scouted-jobs.json"),r=U.join(e,"application-questions.json"),s=V(n)||{},l=V(t)||{},I=0,u=[];for(let f of Object.keys(s)){if(!l[f])continue;let b=l[f],d=s[f];for(let O of je)b[O]!=null&&d[O]==null&&(d[O]=b[O]);u.push(f),I++}I>0?(q(n,s),console.log(` Phase 1: Merged ${I} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let p=V(r);if(p&&Array.isArray(p.applications)){let f={},b=0;for(let d of p.applications){let O=d.jobId||"unknown";f[O]||(f[O]={applications:[]});let N=(d.questions||[]).map(g=>{let k={type:g.type||"input",question:g.question||"",answer:g.answer||""};return g.options&&(g.options.length<=$e?k.options=g.options:(k.optionsOmitted=!0,b++)),g.page&&(k.page=g.page),g.wasPreFilled&&(k.wasPreFilled=!0),g.wasRetry&&(k.wasRetry=!0),k});f[O].applications.push({applicationId:d.applicationId,date:d.date,result:d.result||"submitted",formPages:d.formPages||null,duration:d.duration||null,retries:d.retries||0,failedField:d.failedField||null,questionCount:d.questionCount||N.length,questions:N})}q(r,f),console.log(` Phase 2: Rekeyed ${p.applications.length} applications by jobId (${Object.keys(f).length} unique jobs)`),b>0&&console.log(` Phase 2: Stripped bloated options from ${b} questions`)}else p&&!p.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(u.length>0){for(let f of u)delete l[f];q(t,l),console.log(` Phase 3: Removed ${u.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 G={};P(G,{NAME:()=>Oe,VERSION:()=>Ie,up:()=>De});import*as j from"fs";import*as X from"path";var Ie=2,Oe="reset-unread-flags";function Ce(e){return j.existsSync(e)?JSON.parse(j.readFileSync(e,"utf-8")):null}function Re(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{j.writeFileSync(t,n)}catch(r){try{j.unlinkSync(t)}catch{}throw r}try{j.renameSync(t,e)}catch(r){try{j.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 De(e){let o=X.join(e,"conversations.json"),n=Ce(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}Re(o,n),console.log(` Reset unread=false on ${t} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var Y={};P(Y,{NAME:()=>Te,VERSION:()=>Ne,up:()=>Me});import*as $ from"fs";import*as Z from"path";var Ne=3,Te="recompute-last-message-by",xe=new Set(["draft","confirmed","rejected","needs_review"]);function _e(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function Fe(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}}function Le(e,o){if(!e||e.length===0)return"them";let n=e.filter(s=>!xe.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,l)=>l.t-s.t).map(s=>s.m),r=t.length>0?t:[...n].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 Me(e){let o=Z.join(e,"conversations.json"),n=_e(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,l=0;for(let I of Object.keys(n)){let u=n[I];if(!u||typeof u!="object")continue;Object.prototype.hasOwnProperty.call(u,"_cardSynced")&&(delete u._cardSynced,s++);let p=Array.isArray(u.messages)?u.messages:[],f=Le(p,t),b=f==="me"?"awaiting_reply":"unanswered_by_us";u.lastMessageBy!==f&&l++,u.lastMessageBy=f,u.conversationStatus=b,r++}if(r===0){console.log(" No conversations to recompute.");return}Fe(o,n),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 H={};P(H,{NAME:()=>Ue,VERSION:()=>Pe,up:()=>qe});import*as E from"fs";import*as ee from"path";var Pe=4,Ue="split-connection-timestamps",Je=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function Be(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 Ve(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{E.writeFileSync(t,n)}catch(r){try{E.unlinkSync(t)}catch{}throw r}try{E.renameSync(t,e)}catch(r){try{E.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 qe(e){let o=ee.join(e,"people.json"),n=Be(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 l=n[s];!l||typeof l!="object"||(r++,Je.has(l.connectionStatus)&&l.connectionDate&&!l.requestedConnectionAt&&(l.requestedConnectionAt=l.connectionDate,l.connectionDate=null,t++))}if(t===0){console.log(` Scanned ${r} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}Ve(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{getPluginConfig as We}from"@ilivemylife/graph-sdk";var Ge=await We();for(let[e,o]of Object.entries(Ge))process.env[e]===void 0&&(process.env[e]=o);var Oo=process.env.LINKEDIN_NAME,T=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Co=Object.freeze(new Set([T.DRAFT,T.CONFIRMED,T.NEEDS_REVIEW])),Ro=Object.freeze(new Set([T.DRAFT,T.CONFIRMED,T.REJECTED,T.NEEDS_REVIEW]));import"dotenv/config";import*as y from"path";import{fileURLToPath as Ye}from"url";var He=Ye(import.meta.url),Ke=y.dirname(y.dirname(He)),x=process.env.DATA_DIR?y.resolve(process.env.DATA_DIR,"collected-profiles"):y.join(Ke,"collected-profiles"),_o=y.join(x,"people.json"),Fo=y.join(x,"jobs.json"),Lo=y.join(x,"quota.json"),Mo=y.join(x,"conversations.json"),Po=y.join(x,"sync-state.json"),Uo=y.join(x,"application-questions.json"),Jo=y.join(x,"profile-history"),oe=(e,o)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:o},Bo=oe(process.env.CONNECT_MAX_DAILY,20),Vo=oe(process.env.CONNECT_MAX_WEEKLY,100),ze=null,Qe=null,Xe=null,Ze=null,eo=null,oo=null;function ne(){ze=null,Qe=null,Xe=null,Ze=null,eo=null,oo=null}import"dotenv/config";import*as v from"path";import{fileURLToPath as no}from"url";var to=no(import.meta.url),ro=v.dirname(v.dirname(to)),L=process.env.DATA_DIR?v.resolve(process.env.DATA_DIR,"market-research"):v.join(ro,"market-research"),Qo=v.join(L,"scouted-jobs.json"),Xo=v.join(L,"discovered-people.json"),Zo=v.join(L,"visit-log.json"),en=v.join(L,"companies.json"),on=v.join(L,"job-decisions.json");function te(){so=null,io=null,lo=null,co=null,ao=null}var so=null;var io=null;var lo=null;var co=null;var ao=null;var fo=uo(import.meta.url),po=c.dirname(fo),mo=c.dirname(c.dirname(po));function ho(e){return e&&(e==="~"?K.homedir():e.startsWith("~/")||e.startsWith("~\\")?c.join(K.homedir(),e.slice(2)):e)}var S=process.env.DATA_DIR?c.resolve(ho(process.env.DATA_DIR)):mo,R=c.join(S,"collected-profiles"),D=c.join(S,"market-research"),h=c.join(S,".schema-version"),re=[c.join(R,".schema-version"),c.join(D,".schema-version")],J=4,C=[{version:1,module:W},{version:2,module:G},{version:3,module:Y},{version:4,module:H}];(function(){C.sort((t,r)=>t.version-r.version);let o=new Set;for(let t of C){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=C.length?C[C.length-1].version:0;if(n!==J)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${J}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let t=0;t<C.length;t++){let r=t+1;if(C[t].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${t} but found v${C[t].version}`)}})();function ce(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
2
2
|
[FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
|
|
3
3
|
`),process.exit(1));try{i.mkdirSync(S,{recursive:!0})}catch(o){o.code!=="EEXIST"&&(console.error(`
|
|
4
4
|
[FATAL] Cannot create DATA_DIR (${S}): ${o.message}`),console.error(` Fix the path or permissions and try again.
|
|
@@ -6,57 +6,57 @@ var ke=Object.defineProperty;var P=(e,o)=>{for(var n in o)ke(e,n,{get:o[n],enume
|
|
|
6
6
|
[FATAL] DATA_DIR (${S}) is not accessible: ${o.message}
|
|
7
7
|
`),process.exit(1)}e.isDirectory()||(console.error(`
|
|
8
8
|
[FATAL] DATA_DIR (${S}) 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.
|
|
9
|
-
`),process.exit(1));for(let o of[
|
|
9
|
+
`),process.exit(1));for(let o of[R,D]){let n;try{n=i.lstatSync(o)}catch(t){if(t.code==="ENOENT")continue;throw t}n.isSymbolicLink()&&(console.error(`
|
|
10
10
|
[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.
|
|
11
|
-
`),process.exit(1))}}var _=
|
|
11
|
+
`),process.exit(1))}}var _=c.join(S,".migration-lock");function ae(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return i.writeFileSync(_,e,{flag:"wx"}),!0}catch(t){if(t.code!=="EEXIST")throw t}let o;try{o=JSON.parse(i.readFileSync(_,"utf-8"))}catch{o=null}if(o&&Number.isInteger(o.pid)){let t=!1;try{process.kill(o.pid,0),t=!0}catch(l){l.code==="EPERM"&&(t=!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)}t&&s<r&&(console.error(`
|
|
12
12
|
[FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${o.pid}`),console.error(` Started at: ${o.startedAt||"(unknown)"}`),console.error(` Lock file: ${_}
|
|
13
13
|
`),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.
|
|
14
|
-
`),process.exit(1)),t&&r
|
|
15
|
-
[FATAL] Legacy .schema-version file(s) corrupted \u2014 cannot determine current schema version:`);for(let
|
|
14
|
+
`),process.exit(1)),t&&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 n=_+".tmp";try{return i.writeFileSync(n,e),i.renameSync(n,_),!0}catch(t){try{i.unlinkSync(n)}catch{}throw new Error(`Failed to take over stale migration lock: ${t.message}`)}}function M(){try{if(JSON.parse(i.readFileSync(_,"utf-8")).pid!==process.pid)return;i.unlinkSync(_)}catch{}}var se=!1;function ue(){if(se)return;se=!0;let e=()=>{try{M()}catch{}process.exit(1)};for(let o of["SIGINT","SIGTERM","SIGHUP"])try{process.on(o,e)}catch{}}function go(){if(i.existsSync(h))return;let e=[],o=[];for(let s of re)if(i.existsSync(s))try{e.push({file:s,schema:B(s)})}catch(l){o.push({file:s,err:l.message})}if(o.length>0){console.error(`
|
|
15
|
+
[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(`
|
|
16
16
|
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.
|
|
17
|
-
`),process.exit(1)}if(e.length===0)return;let n=e.map(
|
|
18
|
-
[FATAL] Legacy .schema-version files disagree:`);for(let
|
|
19
|
-
`),process.exit(1)}let t=e[0].schema,
|
|
20
|
-
[FATAL] ${
|
|
17
|
+
`),process.exit(1)}if(e.length===0)return;let n=e.map(s=>s.schema.version);if(new Set(n).size>1){console.error(`
|
|
18
|
+
[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.
|
|
19
|
+
`),process.exit(1)}let t=e[0].schema,r=h+".tmp";try{i.writeFileSync(r,JSON.stringify(t,null,2)),i.renameSync(r,h)}catch(s){try{i.unlinkSync(r)}catch{}throw s}for(let s of re)if(i.existsSync(s))try{i.unlinkSync(s)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${h}`)}function yo(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 B(e){let o=i.readFileSync(e,"utf-8");return o.charCodeAt(0)===65279&&(o=o.slice(1)),JSON.parse(o)}function z(){if(go(),!i.existsSync(h))return{version:0,migrations:[]};let e;try{e=B(h)}catch(n){if(n.code==="ENOENT")return{version:0,migrations:[]};console.error(`
|
|
20
|
+
[FATAL] ${h} is not valid JSON: ${n.message}`),console.error(" Refusing to proceed \u2014 silently treating it as 'fresh install' would re-apply"),console.error(" every migration on top of already-migrated data and corrupt it."),console.error(' Repair the file (set it to {"version":N,"migrations":[...]} matching your real state)'),console.error(` or restore from the *.pre-vNNN.backup files if you have them.
|
|
21
21
|
`),process.exit(1)}let o=yo(e);return o===null&&(console.error(`
|
|
22
|
-
[FATAL] ${
|
|
23
|
-
`),process.exit(1)),o}function fe(e){try{i.chmodSync(e,384)}catch{}}function So(e){if(
|
|
22
|
+
[FATAL] ${h} 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.
|
|
23
|
+
`),process.exit(1)),o}function fe(e){try{i.chmodSync(e,384)}catch{}}function So(e){if(ce(),i.existsSync(h))try{if(i.lstatSync(h).isSymbolicLink())throw new Error(`SCHEMA_FILE is a symbolic link: ${h}. Refusing to write through it (potential symlink attack). Remove the link and re-run.`)}catch(n){if(n.message?.includes("symbolic link"))throw n}let o=h+".tmp";try{i.writeFileSync(o,JSON.stringify(e,null,2)),fe(o),i.renameSync(o,h)}catch(n){try{i.unlinkSync(o)}catch{}throw n}}function ie(e,o){return i.existsSync(e)?i.readdirSync(e).filter(n=>n.endsWith(o)):[]}var bo=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function ko(e){let o=e.toLowerCase();return bo.some(n=>n.test(o))}var vo=6e4;function pe(){let e=Date.now(),o=[];for(let n of[S,R,D]){if(!i.existsSync(n))continue;let t;try{t=i.readdirSync(n)}catch{continue}for(let r of t){if(!ko(r))continue;let s=c.join(n,r);try{let l=i.statSync(s);if(!l.isFile()||e-l.mtimeMs<vo)continue;o.push({dir:n,file:r,fullPath:s})}catch{}}}return o}function wo({verbose:e=!1}={}){let o=pe();if(o.length===0)return e&&console.log(" No orphan .tmp files found."),0;let n=0;for(let t of o)try{i.unlinkSync(t.fullPath),n++,e&&console.log(` Removed orphan: ${c.basename(t.dir)}/${t.file}`)}catch(r){console.warn(` [!] Could not remove orphan ${t.fullPath}: ${r.message}`)}return!e&&n>0&&console.log(` Cleaned up ${n} orphan .tmp file(s) from previous run.`),n}function de(){let e=[];for(let o of[R,D])if(i.existsSync(o))for(let n of i.readdirSync(o))/\.pre-rollback-v\d+\.backup$/.test(n)&&e.push({dir:o,file:n,fullPath:c.join(o,n)});return e}function me({removePreRollback:e=!0}={}){if(console.log(`
|
|
24
24
|
\u{1F4E6} Data cleanup
|
|
25
25
|
`),!i.existsSync(S)){console.log(` DATA_DIR not yet created (${S}) \u2014 nothing to clean.
|
|
26
|
-
`);return}
|
|
27
|
-
[ERROR] Could not acquire cleanup lock: ${
|
|
28
|
-
`),process.exit(1)}let n=wo({verbose:!0}),t=0;if(e){let
|
|
26
|
+
`);return}ce();let o=!1;try{ue(),ae(),o=!0,process.on("exit",()=>{o&&M()})}catch(r){console.error(`
|
|
27
|
+
[ERROR] Could not acquire cleanup lock: ${r.message}
|
|
28
|
+
`),process.exit(1)}let n=wo({verbose:!0}),t=0;if(e){let r=de();if(r.length===0)console.log(" No pre-rollback snapshots found.");else for(let s of r)try{i.unlinkSync(s.fullPath),t++,console.log(` Removed pre-rollback snapshot: ${c.basename(s.dir)}/${s.file}`)}catch(l){console.warn(` [!] Could not remove ${s.fullPath}: ${l.message}`)}}o&&(M(),o=!1),console.log(`
|
|
29
29
|
Done. Removed ${n} orphan .tmp + ${t} pre-rollback snapshot(s).`),console.log(` NOTE: .pre-vNNN.backup files are kept \u2014 they're needed for 'rollback-data'.
|
|
30
|
-
`)}function Ao(){let e=[];for(let o of[
|
|
30
|
+
`)}function Ao(){let e=[];for(let o of[R,D]){if(!i.existsSync(o))continue;let n=i.readdirSync(o).filter(t=>{let r=t.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let t of n){let r=c.join(o,t);try{B(r)}catch(s){e.push({dir:c.basename(o),file:t,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function le(e,o){let n=o+".tmp";try{i.copyFileSync(e,n),fe(n)}catch(t){try{i.unlinkSync(n)}catch{}throw t}try{i.renameSync(n,o)}catch(t){try{i.unlinkSync(n)}catch{}if(t.code==="EPERM"||t.code==="EBUSY"){let r=new Error(`File locked: ${o} (${t.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=t.code,r}throw t}}function he(){console.log(`
|
|
31
31
|
\u{1F4E6} Migration status
|
|
32
|
-
`);let e=z();if(console.log(` Data root: ${S}`),console.log(` Schema file: ${
|
|
32
|
+
`);let e=z();if(console.log(` Data root: ${S}`),console.log(` Schema file: ${h}${i.existsSync(h)?"":" (not yet created \u2014 fresh install)"}`),console.log(` Current version: v${e.version}`),e.migrations?.length){console.log(" Applied migrations:");for(let s of e.migrations){if(!s||typeof s!="object"){console.log(` (malformed entry: ${JSON.stringify(s)})`);continue}let l=String(s.version??"?").padStart(3,"0");console.log(` v${l} \u2014 ${s.name??"(no name)"} (at ${s.appliedAt??"?"})`)}}e.rolledBackAt&&console.log(` Last rollback: ${e.rolledBackAt}`);for(let[s,l]of[["collected-profiles",R],["market-research",D]]){if(!i.existsSync(l))continue;let I=i.readdirSync(l).filter(u=>/\.pre-v\d+\.backup$/.test(u));if(I.length){let u=[...new Set(I.map(p=>p.match(/\.pre-v(\d+)\.backup$/)[1]))].sort();console.log(` Pre-migration backups in ${s}/: ${u.map(p=>`v${p} (${I.filter(f=>f.includes(`pre-v${p}`)).length} files)`).join(", ")}`)}}let o=de();o.length>0&&console.log(` Pre-rollback snapshots: ${o.length} file(s) (run 'data-cleanup' to remove)`);let n=pe();if(n.length>0){console.log(` Orphan .tmp files: ${n.length} (will be cleaned on next plugin run, or now via 'data-cleanup')`);for(let s of n)console.log(` ${c.basename(s.dir)}/${s.file}`)}console.log(),console.log(` Latest available schema: v${J}`);let t=C.filter(s=>s.version>e.version);t.length?(console.log(` Pending: ${t.map(s=>`v${String(s.version).padStart(3,"0")}`).join(", ")}`),console.log(" Run any plugin command (e.g. 'ilml linkedin today') to apply pending migrations.")):console.log(" \u2713 Up to date."),console.log();let r=Ao();if(r.ok)console.log(" Data integrity: \u2713 all JSON files parse cleanly");else{console.log(` Data integrity: \u2717 ${r.broken.length} file(s) corrupted:`);for(let s of r.broken)console.log(` ${s.dir}/${s.file}: ${s.err}`);console.log(" Migrations will refuse to run until these are repaired.")}console.log()}async function ge({confirmed:e=!1}={}){let n=z().version;if(n===0){console.log(`
|
|
33
33
|
No migrations applied \u2014 nothing to roll back.
|
|
34
|
-
`);return}let t=!1,
|
|
35
|
-
[ERROR] No backup files (${
|
|
34
|
+
`);return}let t=!1,r=`.pre-v${String(n).padStart(3,"0")}.backup`,s=ie(R,r),l=ie(D,r);if(s.length+l.length===0&&(console.error(`
|
|
35
|
+
[ERROR] No backup files (${r}) found in either data directory.`),console.error(` Cannot roll back v${n} \u2014 backups may have been deleted.
|
|
36
36
|
`),process.exit(1)),!e){console.log(`
|
|
37
37
|
\u26A0 rollback-data ONLY rolls back DATA, NOT the plugin code.
|
|
38
38
|
`),console.log(" The full rollback is a TWO-STEP procedure. Doing only step 1 leaves you"),console.log(` in a broken state where the next plugin run will re-apply the migration.
|
|
39
39
|
`),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\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),console.log(` STEP 1 (this command): roll back DATA schema v${n} \u2192 v${n-1}`),console.log(" STEP 2 (you, after): roll back CODE ilml plugin install linkedin@<previous>"),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\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
40
|
-
`),console.log(" Between step 1 and step 2: DO NOT run any 'ilml linkedin' command."),console.log(` The current plugin (CURRENT_SCHEMA_VERSION=${
|
|
41
|
-
`),console.log(" This step 1 will also:"),console.log(" - OVERWRITE current data with the pre-migration backup"),console.log(` (${
|
|
40
|
+
`),console.log(" Between step 1 and step 2: DO NOT run any 'ilml linkedin' command."),console.log(` The current plugin (CURRENT_SCHEMA_VERSION=${J}) will see your data on v${n-1}`),console.log(` and immediately re-apply migration v${n}, undoing this rollback.
|
|
41
|
+
`),console.log(" This step 1 will also:"),console.log(" - OVERWRITE current data with the pre-migration backup"),console.log(` (${s.length} files in collected-profiles/, ${l.length} in market-research/)`),console.log(` - Permanently LOSE any data changes made after migration v${n}`),console.log(" (new conversations synced, drafts written, notes added \u2014 all gone)"),console.log(` - Snapshot current state to *.pre-rollback-v${String(n).padStart(3,"0")}.backup before overwriting
|
|
42
42
|
`),console.log(" If you only need to inspect old data without downgrading the plugin,"),console.log(" copy your DATA_DIR somewhere else and use that copy instead \u2014 leaves your"),console.log(` live setup untouched.
|
|
43
43
|
`),console.log(" Proceed with step 1? Re-run with --confirm:"),console.log(" npm run rollback:data -- --confirm"),console.log(` ilml linkedin rollback-data --confirm
|
|
44
|
-
`);return}ue(),ae(),t=!0,process.on("exit",()=>{t&&M()});let u=`.pre-rollback-v${String(n).padStart(3,"0")}.backup`,p=[],f=0;for(let a of[
|
|
44
|
+
`);return}ue(),ae(),t=!0,process.on("exit",()=>{t&&M()});let u=`.pre-rollback-v${String(n).padStart(3,"0")}.backup`,p=[],f=0;for(let a of[R,D]){if(!i.existsSync(a))continue;let F;try{F=i.readdirSync(a).filter(m=>{let w=m.toLowerCase();if(w.includes(".backup")||w===".schema-version"||w.endsWith(".tmp"))return!1;try{return i.statSync(c.join(a,m)).isFile()}catch{return!1}})}catch(m){p.push(`${c.basename(a)}: ${m.message}`);continue}for(let m of F)try{le(c.join(a,m),c.join(a,m+u)),f++}catch(w){p.push(`${c.basename(a)}/${m}: ${w.message}`)}}if(p.length>0){console.error(`
|
|
45
45
|
[FATAL] ${p.length} file(s) could not be snapshotted:`);for(let a of p)console.error(` ${a}`);console.error(`
|
|
46
46
|
Aborting rollback \u2014 without a complete snapshot of your CURRENT state, a`),console.error(' "change your mind" recovery would silently lose the data you have NOW.'),console.error(` Your current data is unchanged. Pre-rollback snapshots created so far: *${u}`),console.error(" (run 'data-cleanup' to remove them, or retry the rollback once the underlying"),console.error(` issue is resolved \u2014 usually a transient file lock from antivirus or an editor).
|
|
47
|
-
`),process.exit(1)}console.log(` Snapshotted ${f} files \u2192 *${u} (in case you change your mind)`);let b=[],d=[];for(let[a,F]of[[
|
|
47
|
+
`),process.exit(1)}console.log(` Snapshotted ${f} files \u2192 *${u} (in case you change your mind)`);let b=[],d=[];for(let[a,F]of[[R,s],[D,l]])for(let m of F){let w=c.join(a,m),Q=m.slice(0,-r.length),be=c.join(a,Q);try{Q.toLowerCase().endsWith(".json")?B(w):i.accessSync(w,i.constants.R_OK),b.push({backupPath:w,originalPath:be,fileName:m})}catch(ke){d.push({file:m,dir:c.basename(a),err:ke.message})}}if(d.length>0){console.error(`
|
|
48
48
|
[ERROR] ${d.length} backup file(s) are corrupted or unreadable:`);for(let a of d)console.error(` ${a.dir}/${a.file}: ${a.err}`);console.error(`
|
|
49
49
|
Aborting rollback BEFORE touching any original file \u2014`),console.error(" partial restore would leave the DB in an inconsistent state."),console.error(` Your current data is unchanged. Pre-rollback snapshots: *${u}
|
|
50
50
|
`),console.error(" Options:"),console.error(" - Restore the corrupted backup(s) from another source and re-run rollback"),console.error(` - Or accept the new schema and don't roll back
|
|
51
51
|
`),process.exit(1)}b.length===0&&(console.error(`
|
|
52
52
|
[ERROR] No backup files found to restore. Aborting.
|
|
53
|
-
`),process.exit(1));let O=new Date().toISOString(),
|
|
54
|
-
[WARNING] ${
|
|
55
|
-
Schema has been lowered to v${n-1} but data is in a mixed state:`),console.error(` ${g} files restored from backup`),console.error(` ${
|
|
53
|
+
`),process.exit(1));let O=new Date().toISOString(),N=z();N.version=n-1,N.migrations=(N.migrations||[]).filter(a=>a&&Number.isInteger(a.version)&&a.version<n),N.rolledBackAt=O,So(N);let g=0,k=[];for(let{backupPath:a,originalPath:F,fileName:m}of b)try{le(a,F),g++}catch(w){k.push({fileName:m,err:w.message})}if(k.length>0){console.error(`
|
|
54
|
+
[WARNING] ${k.length} file(s) could not be restored:`);for(let a of k)console.error(` ${a.fileName}: ${a.err}`);console.error(`
|
|
55
|
+
Schema has been lowered to v${n-1} but data is in a mixed state:`),console.error(` ${g} files restored from backup`),console.error(` ${k.length} files still in their post-migration form`),console.error(` The next plugin run will detect pending migration v${n} and re-apply it,`),console.error(" re-converging the data \u2014 but if you intended to roll back, that's not what you want."),console.error(` Manual fix: copy the missing *${r} files back over their originals, then`),console.error(" re-run 'rollback-data --confirm' to redo the rollback. Pre-rollback snapshots"),console.error(` (*${u}) are still on disk if you'd rather restore the v${n} state.
|
|
56
56
|
`),process.exit(1)}try{ne()}catch{}try{te()}catch{}M(),t=!1,console.log(`
|
|
57
57
|
\u2713 STEP 1 DONE. Restored ${g} files. Data schema is now at v${n-1}.
|
|
58
58
|
`),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\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"),console.log(" \u26A0 STEP 2 REQUIRED \u2014 DO NOT RUN ANY 'ilml linkedin' COMMAND UNTIL"),console.log(` YOU DOWNGRADE THE PLUGIN CODE, or migration v${n} will be re-applied`),console.log(" and this rollback will be silently undone."),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\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
59
59
|
`),console.log(" Run NOW (or as soon as possible):"),console.log(` ilml plugin install linkedin@<previous-version>
|
|
60
60
|
`),console.log(` If something looks wrong, your pre-rollback snapshot is in *${u} files`),console.log(` \u2014 copy them back manually to undo this rollback.
|
|
61
|
-
`)}var Se=process.argv.slice(2),ye=Se[0],jo=Se.includes("--confirm");async function $o(){switch(ye){case"status":
|
|
61
|
+
`)}var Se=process.argv.slice(2),ye=Se[0],jo=Se.includes("--confirm");async function $o(){switch(ye){case"status":he();break;case"rollback-data":await ge({confirmed:jo});break;case"data-cleanup":me();break;default:console.log("Usage:"),console.log(" node migrationCli.mjs status Show schema state + leftover files"),console.log(" node migrationCli.mjs data-cleanup Remove .tmp orphans + pre-rollback snapshots"),console.log(" node migrationCli.mjs rollback-data Preview data rollback (read-only)"),console.log(" node migrationCli.mjs rollback-data --confirm Actually roll back data"),console.log(""),console.log("Note: rollback-data only touches DATA. To roll back the plugin code as well,"),console.log("also run: ilml plugin install linkedin@<previous-version>"),process.exit(ye?1:0)}}$o().catch(e=>{console.error(`
|
|
62
62
|
[ERROR]`,e.message),process.env.VERBOSE&&console.error(e.stack),process.exit(1)});
|
package/dist/quota.mjs
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
var xe=Object.defineProperty;var V=(e,o)=>{for(var n in o)xe(e,n,{get:o[n],enumerable:!0})};import{getPluginConfig as Fe}from"@ilivemylife/graph-sdk";var Le=await Fe();for(let[e,o]of Object.entries(Le))process.env[e]===void 0&&(process.env[e]=o);var Ko=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),zo=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),Xo=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.REJECTED,N.NEEDS_REVIEW]));import"dotenv/config";import*as d from"fs";import*as h from"path";import{fileURLToPath as Me}from"url";var Pe=Me(import.meta.url),Je=h.dirname(h.dirname(Pe)),E=process.env.DATA_DIR?h.resolve(process.env.DATA_DIR,"collected-profiles"):h.join(Je,"collected-profiles"),Ue=h.join(E,"people.json"),tn=h.join(E,"jobs.json"),Ve=h.join(E,"quota.json"),sn=h.join(E,"conversations.json"),rn=h.join(E,"sync-state.json"),cn=h.join(E,"application-questions.json"),ln=h.join(E,"profile-history"),ae=(e,o)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:o},ce=ae(process.env.CONNECT_MAX_DAILY,20),le=ae(process.env.CONNECT_MAX_WEEKLY,100),M=null,Be=null,T=null,qe=null,We=null,Ge=null;function ue(){M=null,Be=null,T=null,qe=null,We=null,Ge=null}function fe(){d.existsSync(E)||d.mkdirSync(E,{recursive:!0})}function pe(e,o){if(!d.existsSync(e))return null;try{let n=JSON.parse(d.readFileSync(e,"utf-8"));try{d.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${o} is corrupted: ${n.message}`),console.error(` File: ${h.resolve(e)}`);let t=e+".backup";if(d.existsSync(t))try{let s=JSON.parse(d.readFileSync(t,"utf-8"));console.error(` Restored from ${t}`);try{d.copyFileSync(t,e)}catch{}return s}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 Ye(){return new Date().toISOString().split("T")[0]}function Y(e){if(!e)return null;let o=e.match(/\/in\/([^/?#]+)/);return o?o[1].toLowerCase():null}function de(){return M||(fe(),M=pe(Ue,"people.json")||{},M)}function H(){return T||(fe(),T=pe(Ve,"quota.json"),(!T||!T.connections)&&(T={connections:[]}),T)}function He(){let e=H(),o=new Date;o.setDate(o.getDate()-7);let n=o.toISOString().split("T")[0];return e.connections.filter(t=>t.date>=n)}function he(){let e=He(),o=Ye(),n=e.filter(s=>s.date===o).length,t=e.length;return{daily:{sent:n,max:ce,remaining:ce-n},weekly:{sent:t,max:le,remaining:le-t}}}import"dotenv/config";import*as i from"fs";import*as ne from"os";import*as u from"path";import{fileURLToPath as Oo}from"url";var z={};V(z,{NAME:()=>Ke,VERSION:()=>Qe,up:()=>Ze});import*as S from"fs";import*as B from"path";var Qe=1,Ke="normalize-jobs-and-questions",ze=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],Xe=50;function Q(e){return S.existsSync(e)?JSON.parse(S.readFileSync(e,"utf-8")):null}function K(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{S.writeFileSync(t,n)}catch(s){try{S.unlinkSync(t)}catch{}throw s}try{S.renameSync(t,e)}catch(s){try{S.unlinkSync(t)}catch{}if(s.code==="EPERM"||s.code==="EBUSY"){let r=new Error(`File locked: ${e} (${s.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw r.code=s.code,r}throw s}}async function Ze(e,o){let n=B.join(e,"jobs.json"),t=B.join(o,"scouted-jobs.json"),s=B.join(e,"application-questions.json"),r=Q(n)||{},c=Q(t)||{},a=0,l=[];for(let f of Object.keys(r)){if(!c[f])continue;let k=c[f],g=r[f];for(let I of ze)k[I]!=null&&g[I]==null&&(g[I]=k[I]);l.push(f),a++}a>0?(K(n,r),console.log(` Phase 1: Merged ${a} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let p=Q(s);if(p&&Array.isArray(p.applications)){let f={},k=0;for(let g of p.applications){let I=g.jobId||"unknown";f[I]||(f[I]={applications:[]});let ie=(g.questions||[]).map($=>{let L={type:$.type||"input",question:$.question||"",answer:$.answer||""};return $.options&&($.options.length<=Xe?L.options=$.options:(L.optionsOmitted=!0,k++)),$.page&&(L.page=$.page),$.wasPreFilled&&(L.wasPreFilled=!0),$.wasRetry&&(L.wasRetry=!0),L});f[I].applications.push({applicationId:g.applicationId,date:g.date,result:g.result||"submitted",formPages:g.formPages||null,duration:g.duration||null,retries:g.retries||0,failedField:g.failedField||null,questionCount:g.questionCount||ie.length,questions:ie})}K(s,f),console.log(` Phase 2: Rekeyed ${p.applications.length} applications by jobId (${Object.keys(f).length} unique jobs)`),k>0&&console.log(` Phase 2: Stripped bloated options from ${k} questions`)}else p&&!p.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 c[f];K(t,c),console.log(` Phase 3: Removed ${l.length} merged entries from scouted-jobs.json (${Object.keys(c).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var X={};V(X,{NAME:()=>oo,VERSION:()=>eo,up:()=>so});import*as b from"fs";import*as ge from"path";var eo=2,oo="reset-unread-flags";function no(e){return b.existsSync(e)?JSON.parse(b.readFileSync(e,"utf-8")):null}function to(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{b.writeFileSync(t,n)}catch(s){try{b.unlinkSync(t)}catch{}throw s}try{b.renameSync(t,e)}catch(s){try{b.unlinkSync(t)}catch{}if(s.code==="EPERM"||s.code==="EBUSY"){let r=new Error(`File locked: ${e} (${s.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw r.code=s.code,r}throw s}}async function so(e){let o=ge.join(e,"conversations.json"),n=no(o);if(!n){console.log(" conversations.json not found \u2014 nothing to reset.");return}let t=0;for(let s of Object.keys(n))n[s].unread===!0&&(n[s].unread=!1,t++);if(t===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}to(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:()=>io,VERSION:()=>ro,up:()=>fo});import*as v from"fs";import*as me from"path";var ro=3,io="recompute-last-message-by",co=new Set(["draft","confirmed","rejected","needs_review"]);function lo(e){return v.existsSync(e)?JSON.parse(v.readFileSync(e,"utf-8")):null}function ao(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{v.writeFileSync(t,n)}catch(s){try{v.unlinkSync(t)}catch{}throw s}try{v.renameSync(t,e)}catch(s){try{v.unlinkSync(t)}catch{}if(s.code==="EPERM"||s.code==="EBUSY"){let r=new Error(`File locked: ${e} (${s.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw r.code=s.code,r}throw s}}function uo(e,o){if(!e||e.length===0)return"them";let n=e.filter(r=>!co.has(r.status));if(n.length===0)return"them";let t=n.map(r=>({m:r,t:Date.parse(r.time)})).filter(r=>Number.isFinite(r.t)).sort((r,c)=>c.t-r.t).map(r=>r.m),s=t.length>0?t:[...n].reverse();for(let r of s){let c=r.sender;if(c===o)return"me";if(c!=="Unknown"&&c!=="")return"them"}return"them"}async function fo(e){let o=me.join(e,"conversations.json"),n=lo(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 s=0,r=0,c=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,r++);let p=Array.isArray(l.messages)?l.messages:[],f=uo(p,t),k=f==="me"?"awaiting_reply":"unanswered_by_us";l.lastMessageBy!==f&&c++,l.lastMessageBy=f,l.conversationStatus=k,s++}if(s===0){console.log(" No conversations to recompute.");return}ao(o,n),console.log(` Recomputed lastMessageBy + conversationStatus on ${s} conversations.`),console.log(` ${c} had stale lastMessageBy (now corrected).`),r>0&&console.log(` Cleaned ${r} leftover _cardSynced flags.`),console.log(" Re-run 'ilml linkedin enrich' if you want actionNeeded / summary / autoTags to also update.")}var ee={};V(ee,{NAME:()=>ho,VERSION:()=>po,up:()=>So});import*as w from"fs";import*as ye from"path";var po=4,ho="split-connection-timestamps",go=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function mo(e){if(!w.existsSync(e))return null;let o=w.readFileSync(e,"utf-8");return o.charCodeAt(0)===65279&&(o=o.slice(1)),JSON.parse(o)}function yo(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{w.writeFileSync(t,n)}catch(s){try{w.unlinkSync(t)}catch{}throw s}try{w.renameSync(t,e)}catch(s){try{w.unlinkSync(t)}catch{}if(s.code==="EPERM"||s.code==="EBUSY"){let r=new Error(`File locked: ${e} (${s.code}). On Windows usually antivirus / file explorer / open editor. Close it and re-run.`);throw r.code=s.code,r}throw s}}async function So(e){let o=ye.join(e,"people.json"),n=mo(o);if(!n||typeof n!="object"){console.log(" people.json not found \u2014 nothing to migrate.");return}let t=0,s=0;for(let r of Object.keys(n)){let c=n[r];!c||typeof c!="object"||(s++,go.has(c.connectionStatus)&&c.connectionDate&&!c.requestedConnectionAt&&(c.requestedConnectionAt=c.connectionDate,c.connectionDate=null,t++))}if(t===0){console.log(` Scanned ${s} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}yo(o,n),console.log(` Moved connectionDate \u2192 requestedConnectionAt on ${t} still-pending people (of ${s} scanned).`),console.log(' connectionDate now means "accepted on" only; requestedConnectionAt means "requested on".')}import"dotenv/config";import*as y from"path";import{fileURLToPath as bo}from"url";var vo=bo(import.meta.url),wo=y.dirname(y.dirname(vo)),P=process.env.DATA_DIR?y.resolve(process.env.DATA_DIR,"market-research"):y.join(wo,"market-research"),pn=y.join(P,"scouted-jobs.json"),dn=y.join(P,"discovered-people.json"),hn=y.join(P,"visit-log.json"),gn=y.join(P,"companies.json"),mn=y.join(P,"job-decisions.json");function Se(){ko=null,$o=null,Ao=null,jo=null,Eo=null}var ko=null;var $o=null;var Ao=null;var jo=null;var Eo=null;var Io=Oo(import.meta.url),To=u.dirname(Io),Do=u.dirname(u.dirname(To));function Ro(e){return e&&(e==="~"?ne.homedir():e.startsWith("~/")||e.startsWith("~\\")?u.join(ne.homedir(),e.slice(2)):e)}var A=process.env.DATA_DIR?u.resolve(Ro(process.env.DATA_DIR)):Do,_=u.join(A,"collected-profiles"),x=u.join(A,"market-research"),m=u.join(A,".schema-version"),be=[u.join(_,".schema-version"),u.join(x,".schema-version")],D=4,O=[{version:1,module:z},{version:2,module:X},{version:3,module:Z},{version:4,module:ee}];(function(){O.sort((t,s)=>t.version-s.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 s=t.module;if(!s||typeof s.up!="function")throw new Error(`MIGRATION_REGISTRY: v${t.version} module is missing up()`);if(s.VERSION!==void 0&&s.VERSION!==t.version)throw new Error(`MIGRATION_REGISTRY: v${t.version} entry does not match module VERSION (${s.VERSION}). Drift between registry and module \u2014 pick one source of truth.`)}let n=O.length?O[O.length-1].version:0;if(n!==D)throw new Error(`MIGRATION_REGISTRY: highest version v${n} but CURRENT_SCHEMA_VERSION=${D}. Forgot to bump CURRENT_SCHEMA_VERSION when adding the new migration?`);for(let t=0;t<O.length;t++){let s=t+1;if(O[t].version!==s)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${s} at position ${t} but found v${O[t].version}`)}})();function $e(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
1
|
+
var _e=Object.defineProperty;var B=(e,o)=>{for(var n in o)_e(e,n,{get:o[n],enumerable:!0})};import{getPluginConfig as Fe}from"@ilivemylife/graph-sdk";var Le=await Fe();for(let[e,o]of Object.entries(Le))process.env[e]===void 0&&(process.env[e]=o);var zo=process.env.LINKEDIN_NAME,R=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Qo=Object.freeze(new Set([R.DRAFT,R.CONFIRMED,R.NEEDS_REVIEW])),Xo=Object.freeze(new Set([R.DRAFT,R.CONFIRMED,R.REJECTED,R.NEEDS_REVIEW]));import"dotenv/config";import*as d from"fs";import*as h from"path";import{fileURLToPath as Me}from"url";var Ue=Me(import.meta.url),Pe=h.dirname(h.dirname(Ue)),E=process.env.DATA_DIR?h.resolve(process.env.DATA_DIR,"collected-profiles"):h.join(Pe,"collected-profiles"),Je=h.join(E,"people.json"),tn=h.join(E,"jobs.json"),Be=h.join(E,"quota.json"),rn=h.join(E,"conversations.json"),sn=h.join(E,"sync-state.json"),ln=h.join(E,"application-questions.json"),cn=h.join(E,"profile-history"),ae=(e,o)=>{let n=parseInt(e,10);return Number.isInteger(n)&&n>=0?n:o},le=ae(process.env.CONNECT_MAX_DAILY,20),ce=ae(process.env.CONNECT_MAX_WEEKLY,100),M=null,qe=null,C=null,Ve=null,We=null,Ge=null;function ue(){M=null,qe=null,C=null,Ve=null,We=null,Ge=null}function fe(){d.existsSync(E)||d.mkdirSync(E,{recursive:!0})}function pe(e,o){if(!d.existsSync(e))return null;try{let n=JSON.parse(d.readFileSync(e,"utf-8"));try{d.copyFileSync(e,e+".backup")}catch{}return n}catch(n){console.error(`[!] ${o} is corrupted: ${n.message}`),console.error(` File: ${h.resolve(e)}`);let t=e+".backup";if(d.existsSync(t))try{let r=JSON.parse(d.readFileSync(t,"utf-8"));console.error(` Restored from ${t}`);try{d.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{d.copyFileSync(e,e+".corrupted")}catch{}return null}}function Ye(){return new Date().toISOString().split("T")[0]}function Y(e){if(!e)return null;let o=e.match(/\/in\/([^/?#]+)/);return o?o[1].toLowerCase():null}function de(){return M||(fe(),M=pe(Je,"people.json")||{},M)}function H(){return C||(fe(),C=pe(Be,"quota.json"),(!C||!C.connections)&&(C={connections:[]}),C)}function He(){let e=H(),o=new Date;o.setDate(o.getDate()-7);let n=o.toISOString().split("T")[0];return e.connections.filter(t=>t.date>=n)}function he(){let e=He(),o=Ye(),n=e.filter(r=>r.date===o).length,t=e.length;return{daily:{sent:n,max:le,remaining:le-n},weekly:{sent:t,max:ce,remaining:ce-t}}}import"dotenv/config";import*as i from"fs";import*as ne from"os";import*as u from"path";import{fileURLToPath as Io}from"url";var Q={};B(Q,{NAME:()=>ze,VERSION:()=>Ke,up:()=>Ze});import*as S from"fs";import*as q from"path";var Ke=1,ze="normalize-jobs-and-questions",Qe=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],Xe=50;function K(e){return S.existsSync(e)?JSON.parse(S.readFileSync(e,"utf-8")):null}function z(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{S.writeFileSync(t,n)}catch(r){try{S.unlinkSync(t)}catch{}throw r}try{S.renameSync(t,e)}catch(r){try{S.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 Ze(e,o){let n=q.join(e,"jobs.json"),t=q.join(o,"scouted-jobs.json"),r=q.join(e,"application-questions.json"),s=K(n)||{},l=K(t)||{},a=0,c=[];for(let f of Object.keys(s)){if(!l[f])continue;let v=l[f],m=s[f];for(let O of Qe)v[O]!=null&&m[O]==null&&(m[O]=v[O]);c.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 p=K(r);if(p&&Array.isArray(p.applications)){let f={},v=0;for(let m of p.applications){let O=m.jobId||"unknown";f[O]||(f[O]={applications:[]});let ie=(m.questions||[]).map(A=>{let L={type:A.type||"input",question:A.question||"",answer:A.answer||""};return A.options&&(A.options.length<=Xe?L.options=A.options:(L.optionsOmitted=!0,v++)),A.page&&(L.page=A.page),A.wasPreFilled&&(L.wasPreFilled=!0),A.wasRetry&&(L.wasRetry=!0),L});f[O].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||ie.length,questions:ie})}z(r,f),console.log(` Phase 2: Rekeyed ${p.applications.length} applications by jobId (${Object.keys(f).length} unique jobs)`),v>0&&console.log(` Phase 2: Stripped bloated options from ${v} questions`)}else p&&!p.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(c.length>0){for(let f of c)delete l[f];z(t,l),console.log(` Phase 3: Removed ${c.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 X={};B(X,{NAME:()=>oo,VERSION:()=>eo,up:()=>ro});import*as b from"fs";import*as me from"path";var eo=2,oo="reset-unread-flags";function no(e){return b.existsSync(e)?JSON.parse(b.readFileSync(e,"utf-8")):null}function to(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{b.writeFileSync(t,n)}catch(r){try{b.unlinkSync(t)}catch{}throw r}try{b.renameSync(t,e)}catch(r){try{b.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 ro(e){let o=me.join(e,"conversations.json"),n=no(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}to(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={};B(Z,{NAME:()=>io,VERSION:()=>so,up:()=>fo});import*as w from"fs";import*as ge from"path";var so=3,io="recompute-last-message-by",lo=new Set(["draft","confirmed","rejected","needs_review"]);function co(e){return w.existsSync(e)?JSON.parse(w.readFileSync(e,"utf-8")):null}function ao(e,o){let n=JSON.stringify(o,null,2),t=e+".tmp";try{w.writeFileSync(t,n)}catch(r){try{w.unlinkSync(t)}catch{}throw r}try{w.renameSync(t,e)}catch(r){try{w.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 uo(e,o){if(!e||e.length===0)return"them";let n=e.filter(s=>!lo.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,l)=>l.t-s.t).map(s=>s.m),r=t.length>0?t:[...n].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=ge.join(e,"conversations.json"),n=co(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,l=0;for(let a of Object.keys(n)){let c=n[a];if(!c||typeof c!="object")continue;Object.prototype.hasOwnProperty.call(c,"_cardSynced")&&(delete c._cardSynced,s++);let p=Array.isArray(c.messages)?c.messages:[],f=uo(p,t),v=f==="me"?"awaiting_reply":"unanswered_by_us";c.lastMessageBy!==f&&l++,c.lastMessageBy=f,c.conversationStatus=v,r++}if(r===0){console.log(" No conversations to recompute.");return}ao(o,n),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 ee={};B(ee,{NAME:()=>ho,VERSION:()=>po,up:()=>So});import*as k from"fs";import*as ye from"path";var po=4,ho="split-connection-timestamps",mo=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]);function go(e){if(!k.existsSync(e))return null;let o=k.readFileSync(e,"utf-8");return o.charCodeAt(0)===65279&&(o=o.slice(1)),JSON.parse(o)}function yo(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 So(e){let o=ye.join(e,"people.json"),n=go(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 l=n[s];!l||typeof l!="object"||(r++,mo.has(l.connectionStatus)&&l.connectionDate&&!l.requestedConnectionAt&&(l.requestedConnectionAt=l.connectionDate,l.connectionDate=null,t++))}if(t===0){console.log(` Scanned ${r} people \u2014 none needed the connectionDate\u2192requestedConnectionAt move.`);return}yo(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 y from"path";import{fileURLToPath as bo}from"url";var wo=bo(import.meta.url),ko=y.dirname(y.dirname(wo)),U=process.env.DATA_DIR?y.resolve(process.env.DATA_DIR,"market-research"):y.join(ko,"market-research"),gn=y.join(U,"scouted-jobs.json"),yn=y.join(U,"discovered-people.json"),Sn=y.join(U,"visit-log.json"),bn=y.join(U,"companies.json"),wn=y.join(U,"job-decisions.json");function Se(){vo=null,Ao=null,$o=null,jo=null,Eo=null}var vo=null;var Ao=null;var $o=null;var jo=null;var Eo=null;var Oo=Io(import.meta.url),Co=u.dirname(Oo),To=u.dirname(u.dirname(Co));function Do(e){return e&&(e==="~"?ne.homedir():e.startsWith("~/")||e.startsWith("~\\")?u.join(ne.homedir(),e.slice(2)):e)}var $=process.env.DATA_DIR?u.resolve(Do(process.env.DATA_DIR)):To,x=u.join($,"collected-profiles"),_=u.join($,"market-research"),g=u.join($,".schema-version"),be=[u.join(x,".schema-version"),u.join(_,".schema-version")],T=4,I=[{version:1,module:Q},{version:2,module:X},{version:3,module:Z},{version:4,module:ee}];(function(){I.sort((t,r)=>t.version-r.version);let o=new Set;for(let t of I){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=I.length?I[I.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<I.length;t++){let r=t+1;if(I[t].version!==r)throw new Error(`MIGRATION_REGISTRY: gap detected \u2014 expected v${r} at position ${t} but found v${I[t].version}`)}})();function Ae(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
2
2
|
[FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
|
|
3
|
-
`),process.exit(1));try{i.mkdirSync(
|
|
4
|
-
[FATAL] Cannot create DATA_DIR (${
|
|
5
|
-
`),process.exit(1))}let e;try{e=i.statSync(
|
|
6
|
-
[FATAL] DATA_DIR (${
|
|
3
|
+
`),process.exit(1));try{i.mkdirSync($,{recursive:!0})}catch(o){o.code!=="EEXIST"&&(console.error(`
|
|
4
|
+
[FATAL] Cannot create DATA_DIR (${$}): ${o.message}`),console.error(` Fix the path or permissions and try again.
|
|
5
|
+
`),process.exit(1))}let e;try{e=i.statSync($)}catch(o){console.error(`
|
|
6
|
+
[FATAL] DATA_DIR (${$}) is not accessible: ${o.message}
|
|
7
7
|
`),process.exit(1)}e.isDirectory()||(console.error(`
|
|
8
|
-
[FATAL] DATA_DIR (${
|
|
9
|
-
`),process.exit(1));for(let o of[_
|
|
8
|
+
[FATAL] DATA_DIR (${$}) 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.
|
|
9
|
+
`),process.exit(1));for(let o of[x,_]){let n;try{n=i.lstatSync(o)}catch(t){if(t.code==="ENOENT")continue;throw t}n.isSymbolicLink()&&(console.error(`
|
|
10
10
|
[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.
|
|
11
|
-
`),process.exit(1))}}var
|
|
12
|
-
[FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${o.pid}`),console.error(` Started at: ${o.startedAt||"(unknown)"}`),console.error(` Lock file: ${
|
|
11
|
+
`),process.exit(1))}}var N=u.join($,".migration-lock");function Ro(){let e=JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()},null,2);try{return i.writeFileSync(N,e,{flag:"wx"}),!0}catch(t){if(t.code!=="EEXIST")throw t}let o;try{o=JSON.parse(i.readFileSync(N,"utf-8"))}catch{o=null}if(o&&Number.isInteger(o.pid)){let t=!1;try{process.kill(o.pid,0),t=!0}catch(l){l.code==="EPERM"&&(t=!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)}t&&s<r&&(console.error(`
|
|
12
|
+
[FATAL] Another plugin process is currently running migrations:`),console.error(` PID: ${o.pid}`),console.error(` Started at: ${o.startedAt||"(unknown)"}`),console.error(` Lock file: ${N}
|
|
13
13
|
`),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.
|
|
14
|
-
`),process.exit(1)),t&&r
|
|
15
|
-
[FATAL] Legacy .schema-version file(s) corrupted \u2014 cannot determine current schema version:`);for(let
|
|
14
|
+
`),process.exit(1)),t&&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 n=N+".tmp";try{return i.writeFileSync(n,e),i.renameSync(n,N),!0}catch(t){try{i.unlinkSync(n)}catch{}throw new Error(`Failed to take over stale migration lock: ${t.message}`)}}function te(){try{if(JSON.parse(i.readFileSync(N,"utf-8")).pid!==process.pid)return;i.unlinkSync(N)}catch{}}var we=!1;function No(){if(we)return;we=!0;let e=()=>{try{te()}catch{}process.exit(1)};for(let o of["SIGINT","SIGTERM","SIGHUP"])try{process.on(o,e)}catch{}}function xo(){if(i.existsSync(g))return;let e=[],o=[];for(let s of be)if(i.existsSync(s))try{e.push({file:s,schema:V(s)})}catch(l){o.push({file:s,err:l.message})}if(o.length>0){console.error(`
|
|
15
|
+
[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(`
|
|
16
16
|
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.
|
|
17
|
-
`),process.exit(1)}if(e.length===0)return;let n=e.map(
|
|
18
|
-
[FATAL] Legacy .schema-version files disagree:`);for(let
|
|
19
|
-
`),process.exit(1)}let t=e[0].schema,
|
|
20
|
-
[FATAL] ${
|
|
21
|
-
`),process.exit(1)}let o=
|
|
22
|
-
[FATAL] ${
|
|
23
|
-
`),process.exit(1)),o}function
|
|
24
|
-
[FATAL] Your data schema is at v${o}, but this plugin build only understands up to v${
|
|
25
|
-
`),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${
|
|
17
|
+
`),process.exit(1)}if(e.length===0)return;let n=e.map(s=>s.schema.version);if(new Set(n).size>1){console.error(`
|
|
18
|
+
[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.
|
|
19
|
+
`),process.exit(1)}let t=e[0].schema,r=g+".tmp";try{i.writeFileSync(r,JSON.stringify(t,null,2)),i.renameSync(r,g)}catch(s){try{i.unlinkSync(r)}catch{}throw s}for(let s of be)if(i.existsSync(s))try{i.unlinkSync(s)}catch{}console.log(` Consolidated legacy .schema-version files \u2192 ${g}`)}function _o(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 V(e){let o=i.readFileSync(e,"utf-8");return o.charCodeAt(0)===65279&&(o=o.slice(1)),JSON.parse(o)}function ke(){if(xo(),!i.existsSync(g))return{version:0,migrations:[]};let e;try{e=V(g)}catch(n){if(n.code==="ENOENT")return{version:0,migrations:[]};console.error(`
|
|
20
|
+
[FATAL] ${g} is not valid JSON: ${n.message}`),console.error(" Refusing to proceed \u2014 silently treating it as 'fresh install' would re-apply"),console.error(" every migration on top of already-migrated data and corrupt it."),console.error(' Repair the file (set it to {"version":N,"migrations":[...]} matching your real state)'),console.error(` or restore from the *.pre-vNNN.backup files if you have them.
|
|
21
|
+
`),process.exit(1)}let o=_o(e);return o===null&&(console.error(`
|
|
22
|
+
[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.
|
|
23
|
+
`),process.exit(1)),o}function $e(e){try{i.chmodSync(e,384)}catch{}}function Fo(e){if(Ae(),i.existsSync(g))try{if(i.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(n){if(n.message?.includes("symbolic link"))throw n}let o=g+".tmp";try{i.writeFileSync(o,JSON.stringify(e,null,2)),$e(o),i.renameSync(o,g)}catch(n){try{i.unlinkSync(o)}catch{}throw n}}function ve(e,o){if(!i.existsSync(e))return;let n=`.pre-v${String(o).padStart(3,"0")}.backup`,t=i.readdirSync(e).filter(a=>{let c=a.toLowerCase();if(c.includes(".backup")||c===".schema-version"||c.endsWith(".tmp"))return!1;try{return i.statSync(u.join(e,a)).isFile()}catch{return!1}}),r=0,s=0,l=[];for(let a of t){let c=u.join(e,a),p=u.join(e,a+n);if(i.existsSync(p)){s++;continue}try{Ee(c,p),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 ${u.basename(e)}/: `+l.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 ${u.basename(e)}/ (${n})${a}`)}}var oe=!1;async function je(){if(oe)return;Ae(),Jo();let o=ke().version;if(o===T){oe=!0;return}No(),Ro(),process.on("exit",te),o>T&&(console.error(`
|
|
24
|
+
[FATAL] Your data schema is at v${o}, but this plugin build only understands up to v${T}.`),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.
|
|
25
|
+
`),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${T}.
|
|
26
26
|
`),process.exit(1)),console.log(`
|
|
27
|
-
\u{1F4E6} Schema migration: v${o} \u2192 v${
|
|
28
|
-
[FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let
|
|
27
|
+
\u{1F4E6} Schema migration: v${o} \u2192 v${T}`);let n=Bo();if(!n.ok){console.error(`
|
|
28
|
+
[FATAL] Cannot migrate \u2014 current data is corrupted:`);for(let r of n.broken)console.error(` ${r.dir}/${r.file}: ${r.err}`);console.error(`
|
|
29
29
|
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'.
|
|
30
|
-
`),process.exit(1)}let t=
|
|
31
|
-
Running migration v${String(
|
|
32
|
-
[FATAL] Pre-migration backup failed for ${
|
|
33
|
-
`),process.exit(1)}let a=
|
|
34
|
-
[FATAL] Migration ${
|
|
35
|
-
`)):(console.error(` [!] Auto-rollback INCOMPLETE: ${p.error}`),console.error(` Manual recovery: copy *${
|
|
36
|
-
`))}catch(p){console.error(` [!] Auto-rollback CRASHED while restoring: ${p.message}`),console.error(` Manual recovery: copy *${
|
|
37
|
-
`)}process.exit(1)}try{let
|
|
38
|
-
[FATAL] Migration ${
|
|
39
|
-
`),process.exit(1)}console.log(` \u2713 Migration ${
|
|
40
|
-
\u2713 Schema is now at v${
|
|
41
|
-
`)}var Lo=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Mo(e){let o=e.toLowerCase();return Lo.some(n=>n.test(o))}var
|
|
30
|
+
`),process.exit(1)}let t=I.filter(r=>r.version>o);for(let r of t){console.log(`
|
|
31
|
+
Running migration v${String(r.version).padStart(3,"0")}...`);let s=`v${String(r.version).padStart(3,"0")}`,l=`.pre-${s}.backup`;try{ve(x,r.version),ve(_,r.version)}catch(c){console.error(`
|
|
32
|
+
[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.
|
|
33
|
+
`),process.exit(1)}let a=r.module;try{await a.up(x,_)}catch(c){console.error(`
|
|
34
|
+
[FATAL] Migration ${s} failed: ${c.message}`),console.error(` Attempting auto-rollback from ${l} files...`);try{let p=qo(l);p.ok?(console.error(` \u2713 Auto-rollback restored ${p.restored} files. Schema stays at v${o}.`),console.error(` The migration will be retried on next plugin command. Fix the root cause first.
|
|
35
|
+
`)):(console.error(` [!] Auto-rollback INCOMPLETE: ${p.error}`),console.error(` Manual recovery: copy *${l} files back over the originals.
|
|
36
|
+
`))}catch(p){console.error(` [!] Auto-rollback CRASHED while restoring: ${p.message}`),console.error(` Manual recovery: copy *${l} files back over the originals.
|
|
37
|
+
`)}process.exit(1)}try{let c=new Date().toISOString(),p={version:r.version,name:a.NAME||s,appliedAt:c},f=ke();f.version=r.version,f.migratedAt=c,f.migrations=f.migrations||[],f.migrations.push(p),Fo(f)}catch(c){console.error(`
|
|
38
|
+
[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${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.
|
|
39
|
+
`),process.exit(1)}console.log(` \u2713 Migration ${s} complete`)}try{ue()}catch{}try{Se()}catch{}oe=!0,te(),console.log(`
|
|
40
|
+
\u2713 Schema is now at v${T}
|
|
41
|
+
`)}var Lo=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Mo(e){let o=e.toLowerCase();return Lo.some(n=>n.test(o))}var Uo=6e4;function Po(){let e=Date.now(),o=[];for(let n of[$,x,_]){if(!i.existsSync(n))continue;let t;try{t=i.readdirSync(n)}catch{continue}for(let r of t){if(!Mo(r))continue;let s=u.join(n,r);try{let l=i.statSync(s);if(!l.isFile()||e-l.mtimeMs<Uo)continue;o.push({dir:n,file:r,fullPath:s})}catch{}}}return o}function Jo({verbose:e=!1}={}){let o=Po();if(o.length===0)return e&&console.log(" No orphan .tmp files found."),0;let n=0;for(let t of o)try{i.unlinkSync(t.fullPath),n++,e&&console.log(` Removed orphan: ${u.basename(t.dir)}/${t.file}`)}catch(r){console.warn(` [!] Could not remove orphan ${t.fullPath}: ${r.message}`)}return!e&&n>0&&console.log(` Cleaned up ${n} orphan .tmp file(s) from previous run.`),n}function Bo(){let e=[];for(let o of[x,_]){if(!i.existsSync(o))continue;let n=i.readdirSync(o).filter(t=>{let r=t.toLowerCase();return r.endsWith(".json")&&!r.includes(".backup")});for(let t of n){let r=u.join(o,t);try{V(r)}catch(s){e.push({dir:u.basename(o),file:t,err:s.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function qo(e){let o=[],n=[];for(let s of[x,_]){if(!i.existsSync(s))continue;let l=i.readdirSync(s).filter(a=>a.endsWith(e));for(let a of l){let c=u.join(s,a),p=a.slice(0,-e.length),f=u.join(s,p);try{p.toLowerCase().endsWith(".json")?V(c):i.accessSync(c,i.constants.R_OK),o.push({backupPath:c,originalPath:f,fileName:a,dir:s})}catch(v){n.push(`${u.basename(s)}/${a}: ${v.message}`)}}}if(n.length>0)return{ok:!1,error:n.join("; "),restored:0};let t=0,r=[];for(let{backupPath:s,originalPath:l,fileName:a,dir:c}of o)try{Ee(s,l),t++}catch(p){r.push(`${u.basename(c)}/${a}: ${p.message}`)}return r.length>0?{ok:!1,error:r.join("; "),restored:t}:{ok:!0,restored:t}}function Ee(e,o){let n=o+".tmp";try{i.copyFileSync(e,n),$e(n)}catch(t){try{i.unlinkSync(n)}catch{}throw t}try{i.renameSync(n,o)}catch(t){try{i.unlinkSync(n)}catch{}if(t.code==="EPERM"||t.code==="EBUSY"){let r=new Error(`File locked: ${o} (${t.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=t.code,r}throw t}}var Te=process.argv.includes("--json"),De=new Set(["connected"]),Re=new Set(["pending","sent_without_note","sent_with_note","sent_without_note_upsell"]),re=["founder","investor","hiring_manager","peer"],Vo=new Date().toISOString().split("T")[0];function Ne(e){if(!e)return 1/0;let o=new Date(e+"T00:00:00Z").getTime(),n=new Date(Vo+"T00:00:00Z").getTime();return Math.round((n-o)/864e5)}function Wo(e,o,n=20){return o?"\u2588".repeat(Math.max(0,Math.round(e/o*n))):""}Te||await je();var Go=H(),G=Go.connections||[],j=he(),se=de(),P=new Map;for(let[e,o]of Object.entries(se)){let n=Y(o.profileUrl||e);n&&!P.has(n)&&P.set(n,o)}for(let e of Object.values(se))for(let o of e.aliases||[])o&&!P.has(o)&&P.set(o,e);var Yo=G.filter(e=>Ne(e.date)<=7),D={},W={};for(let e of Yo){D[e.date]=(D[e.date]||0)+1;let o=e.source||"unknown";W[o]=(W[o]||0)+1}var F={},Ie=new Set;for(let e of G){let o=e.source||"unknown",n=Y(e.profileUrl),t=`${o}|${n}`;if(n&&Ie.has(t))continue;n&&Ie.add(t),F[o]||={sent:0,accepted:0,awaiting:0,stale:0,unknown:0};let r=F[o];r.sent++;let l=(n?P.get(n):null)?.connectionStatus;De.has(l)?r.accepted++:Re.has(l)?(r.awaiting++,Ne(e.date)>14&&r.stale++):r.unknown++}var J={};for(let e of re)J[e]=0;for(let e of Object.values(se)){let o=e.category;if(!re.includes(o))continue;let n=e.connectionStatus;De.has(n)||Re.has(n)||e.connectionDegree!=="1st"&&J[o]++}var xe=Object.values(J).reduce((e,o)=>e+o,0);Te&&(console.log(JSON.stringify({state:j,byDay:D,bySource7d:W,acceptance:F,feederPool:{...J,total:xe},totalLogged:G.length},null,2)),process.exit(0));var Oe=(e,o)=>o?`${Math.round(e/o*100)}%`:"\u2014";console.log(`
|
|
42
42
|
=== LinkedIn Connection Quota ===
|
|
43
43
|
`);console.log("State");console.log(` Today: ${j.daily.sent} / ${j.daily.max} (${j.daily.remaining} left)`);console.log(` Week: ${j.weekly.sent} / ${j.weekly.max} (${j.weekly.remaining} left) \u2014 rolling 7 days`);console.log(` Log: ${G.length} requests recorded all-time
|
|
44
|
-
`);if(Object.keys(
|
|
44
|
+
`);if(Object.keys(D).length){let e=Math.max(...Object.values(D));console.log("Last 7 days");for(let o of Object.keys(D).sort())console.log(` ${o} ${Wo(D[o],e).padEnd(20)} ${D[o]}`);console.log(""),console.log(" by source (7d): "+Object.entries(W).map(([o,n])=>`${o}=${n}`).join(", ")+`
|
|
45
45
|
`)}else console.log(`Last 7 days: no connection requests sent.
|
|
46
|
-
`);var
|
|
46
|
+
`);var Ce=Object.keys(F).sort((e,o)=>F[o].sent-F[e].sent);if(Ce.length){console.log("Acceptance (all-time, unique profiles)"),console.log(" "+"Source".padEnd(24)+"Sent".padStart(6)+"Accept".padStart(8)+"Rate".padStart(7)+"Await".padStart(7)+"Stale>14d".padStart(11));let e={sent:0,accepted:0,awaiting:0,stale:0};for(let o of Ce){let n=F[o];e.sent+=n.sent,e.accepted+=n.accepted,e.awaiting+=n.awaiting,e.stale+=n.stale,console.log(" "+o.padEnd(24)+String(n.sent).padStart(6)+String(n.accepted).padStart(8)+Oe(n.accepted,n.sent).padStart(7)+String(n.awaiting).padStart(7)+String(n.stale).padStart(11))}console.log(" "+"\u2500".repeat(63)),console.log(" "+"TOTAL".padEnd(24)+String(e.sent).padStart(6)+String(e.accepted).padStart(8)+Oe(e.accepted,e.sent).padStart(7)+String(e.awaiting).padStart(7)+String(e.stale).padStart(11)),console.log(" (Accept = they connected \xB7 Await = request still open \xB7 Stale>14d = open >2wk, likely won't)"),console.log(" Acceptance is read from your last `sync` \u2014 run `ilml linkedin sync` to refresh accepted status.\n")}console.log("Feeder pool \u2014 high-value people not yet connected");for(let e of re)console.log(` ${e.padEnd(16)} ${J[e]}`);console.log(` ${"TOTAL".padEnd(16)} ${xe}`);console.log(` \u2192 these could absorb idle daily quota once the category feeder is wired.
|
|
47
47
|
`);j.daily.sent===0&&j.daily.remaining>0&&(console.log(`\u26A0 Today's quota is idle (0/${j.daily.max}). Recruiter auto-connect is off and no`),console.log(` other feeder is wired yet \u2014 run the funnel manually or build the category feeder.
|
|
48
48
|
`));
|