ilml-plugin-linkedin 1.12.0 → 1.13.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 +30 -0
- package/dist/applyQueue.mjs +4 -4
- package/dist/enrichProfile.mjs +242 -19
- package/dist/enrichProfiles.mjs +257 -48
- package/dist/funnelRunner.mjs +256 -47
- package/dist/profileHistory.mjs +4 -4
- package/dist/readPost.mjs +70 -0
- package/dist/run.mjs +260 -51
- package/dist/scout.mjs +7 -7
- package/dist/syncAll.mjs +317 -90
- package/dist/verifyAbout.mjs +219 -10
- package/dist/visit.mjs +256 -47
- package/ilml-plugin.json +185 -28
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.13.0 (in development)
|
|
4
|
+
|
|
5
|
+
**1. Read full LinkedIn profile in one command.**
|
|
6
|
+
```
|
|
7
|
+
ilml linkedin enrich-profile <url> --full
|
|
8
|
+
```
|
|
9
|
+
Pulls Experience, Education, Skills, Recommendations, Certifications, Featured. Use on your own profile to audit, or on a contact before reaching out. For one section only: `--with-experience` / `--with-education` / etc.
|
|
10
|
+
|
|
11
|
+
**2. After sync, deep-read profiles of people who just wrote you.**
|
|
12
|
+
```
|
|
13
|
+
ilml linkedin sync-all --auto-enrich-replies
|
|
14
|
+
```
|
|
15
|
+
Opt-in flag, default OFF. After pulling new messages, visits up to 3 profiles of contacts whose latest message is from them. Skips contacts enriched in the last 30 days. Try `--dry-run` first to see the list.
|
|
16
|
+
|
|
17
|
+
**3. Read & analyse a LinkedIn post with your AI.**
|
|
18
|
+
```
|
|
19
|
+
ilml linkedin read-post <url> --json # AI gets structured data
|
|
20
|
+
ilml linkedin read-post <url> --no-comments # skip 1000+ comments
|
|
21
|
+
ilml linkedin read-post <url> --save-to-graph=<nodeId> # save to your graph (opt-in)
|
|
22
|
+
```
|
|
23
|
+
Default: just print. `--json` for AI consumption. `--save-to-graph` is the only way to save — nothing auto-saves. Saved node holds only stable fields (post text, author, hashtags, mentions, media flags); live counts and comments are NOT saved (they change — re-fetch when needed).
|
|
24
|
+
|
|
25
|
+
**4. Every command now has full docs in the plugin manifest.**
|
|
26
|
+
```
|
|
27
|
+
ilml linkedin help <command>
|
|
28
|
+
```
|
|
29
|
+
AI assistants can read the manifest and know how to use any command without seeing the code.
|
|
30
|
+
|
|
31
|
+
**Schema:** no migration. New profile fields (`featured`, `education`, `skillsFull`, `recommendations`, `certifications`) are additive — appear only on records you explicitly enrich after upgrading.
|
|
32
|
+
|
|
3
33
|
## 1.12.0
|
|
4
34
|
- **`ilml linkedin enrich-profile <profile-url>` — pull the full picture on one person into your local contacts DB.** Visits the profile and saves headline, location, About, company, and other basics. Add `--with-experience` and it also pulls the structured Experience list — every role with company, dates, location, description, and skills. Single-URL, on-demand — no batch mode here. Self-profile is recognised (by URL or by your configured name) and printed to your terminal instead of being added to the contacts DB. Run `ilml linkedin enrich-profile --help` for full usage.
|
|
5
35
|
- **`ilml linkedin enrich-profiles --with-experience` — same Experience extraction, in batch.** When you batch-enrich contacts that have missing info (still capped at 10/session by default), each visit can now also pull the structured Experience. An extra ban-risk warning prints because each profile now costs 2 page loads instead of 1 — keep `--max` low.
|
package/dist/applyQueue.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var Ce=Object.defineProperty;var G=(e,n)=>{for(var o in n)Ce(e,o,{get:n[o],enumerable:!0})};import"dotenv/config";import*as D from"fs";import*as L from"path";import{fileURLToPath as Zo}from"url";import{execFileSync as en}from"child_process";import{getPluginConfig as _e}from"@ilivemylife/graph-sdk";var xe=await _e();for(let[e,n]of Object.entries(xe))process.env[e]===void 0&&(process.env[e]=n);var an=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),un=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),fn=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.REJECTED,N.NEEDS_REVIEW]));import"dotenv/config";import*as
|
|
1
|
+
var Ce=Object.defineProperty;var G=(e,n)=>{for(var o in n)Ce(e,o,{get:n[o],enumerable:!0})};import"dotenv/config";import*as D from"fs";import*as L from"path";import{fileURLToPath as Zo}from"url";import{execFileSync as en}from"child_process";import{getPluginConfig as _e}from"@ilivemylife/graph-sdk";var xe=await _e();for(let[e,n]of Object.entries(xe))process.env[e]===void 0&&(process.env[e]=n);var an=process.env.LINKEDIN_NAME,N=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),un=Object.freeze(new Set([N.DRAFT,N.CONFIRMED,N.NEEDS_REVIEW])),fn=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 Fe}from"url";var Le=Fe(import.meta.url),Me=g.dirname(g.dirname(Le)),E=process.env.DATA_DIR?g.resolve(process.env.DATA_DIR,"collected-profiles"):g.join(Me,"collected-profiles"),Pe=g.join(E,"people.json"),gn=g.join(E,"jobs.json"),yn=g.join(E,"quota.json"),Sn=g.join(E,"conversations.json"),bn=g.join(E,"sync-state.json"),vn=g.join(E,"application-questions.json"),wn=g.join(E,"profile-history");var P=null,Je=null,Ue=null,Be=null,qe=null,Ve=null;function le(){P=null,Je=null,Ue=null,Be=null,qe=null,Ve=null}function We(){h.existsSync(E)||h.mkdirSync(E,{recursive:!0})}function Ge(e,n){if(!h.existsSync(e))return null;try{let o=JSON.parse(h.readFileSync(e,"utf-8"));try{h.copyFileSync(e,e+".backup")}catch{}return o}catch(o){console.error(`[!] ${n} is corrupted: ${o.message}`),console.error(` File: ${g.resolve(e)}`);let t=e+".backup";if(h.existsSync(t))try{let s=JSON.parse(h.readFileSync(t,"utf-8"));console.error(` Restored from ${t}`);try{h.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{h.copyFileSync(e,e+".corrupted")}catch{}return null}}function ae(){return P||(We(),P=Ge(Pe,"people.json")||{},P)}import"dotenv/config";import*as v from"fs";import*as b from"path";import{fileURLToPath as Ye}from"url";var He=Ye(import.meta.url),Ke=b.dirname(b.dirname(He)),C=process.env.DATA_DIR?b.resolve(process.env.DATA_DIR,"market-research"):b.join(Ke,"market-research"),ue=b.join(C,"scouted-jobs.json"),jn=b.join(C,"discovered-people.json"),On=b.join(C,"visit-log.json"),En=b.join(C,"companies.json"),Qe=b.join(C,"job-decisions.json");function ze(){v.existsSync(C)||v.mkdirSync(C,{recursive:!0})}function Xe(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";v.writeFileSync(t,o);for(let s=0;s<3;s++)try{v.renameSync(t,e);return}catch(r){if(s<2&&(r.code==="EPERM"||r.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw r}}function fe(e){try{if(v.existsSync(e))return JSON.parse(v.readFileSync(e,"utf-8"))}catch{}return null}function pe(){J=null,U=null,Ze=null,eo=null,oo=null}var J=null;function Y(){return J||(J=fe(ue)||{},J)}function de(e,n){if(!e)return;ze();let o=Y(),t=new Date().toISOString().slice(0,10);if(o[e]){for(let[s,r]of Object.entries(n))r!=null&&(o[e][s]=r);o[e].lastSeen=t}else o[e]={...n,scoutedAt:t,lastSeen:t};try{Xe(ue,o)}catch(s){console.error(`[!] Failed to save scouted-jobs.json: ${s.message}`)}}var U=null;function me(){return U||(U=fe(Qe)||{},U)}var Ze=null;var eo=null;var oo=null;var no=new Set(["java","c#",".net","scala","python","typescript","javascript","react","node.js","aws","azure","docker","kubernetes","microservices","graphql","rest","sql","postgresql","mongodb","kafka","redis","ci/cd","terraform","spring"]),to=new Set(["iot","machine learning","ai","data engineering","spark","go","rust","kotlin","next.js","devops","sre"]),he=["vancouver","british columbia"],so=["canada","montreal","quebec","alberta","calgary","ottawa"],ro=["toronto","ontario"],io=["india","pakistan","nigeria","philippines"];function co(e,n={}){let o=0,t=(e.techStack||[]).map(a=>a.toLowerCase()),s=0,r=0;for(let a of t)no.has(a)&&s++,to.has(a)&&r++;if(o+=Math.min(s*6,24),o+=Math.min(r*3,6),e.salary){let a=lo(e.salary);a&&(a>=15e4?o+=20:a>=12e4?o+=15:a>=1e5?o+=10:a>=8e4?o+=5:a>=100&&a<1e3?o+=15:a>=70&&a<1e3&&(o+=10))}let i=(e.location||"").toLowerCase(),u=/remote/i.test(i)||e.workplaceType==="remote";io.some(a=>i.includes(a))?o-=30:u&&/united states|usa|\bus\b/i.test(i)?o+=25:u&&he.some(a=>i.includes(a))?o+=22:u?o+=20:he.some(a=>i.includes(a))?o+=18:so.some(a=>i.includes(a))?o+=10:ro.some(a=>i.includes(a))&&(o+=5),e.isEasyApply&&(o+=5);let c=(e.seniority||"").toLowerCase();c.includes("senior")||c.includes("lead")||c.includes("staff")?o+=10:c.includes("mid")?o+=5:(c.includes("entry")||c.includes("intern"))&&(o-=10),e.recruiterUrl&&(n.conversationRecruiters?.has(e.recruiterUrl)?o+=20:n.connectedRecruiters?.has(e.recruiterUrl)?o+=15:o+=3);let f=new Set(e.jobTags||[]);return f.has("managerial")?o+=8:f.has("senior-ic")&&(o+=5),f.has("junior")&&(o-=15),f.has("consultant")&&(o-=3),Math.max(0,Math.min(100,o))}function H(e=10,n={}){let{easyApplyOnly:o=!0}=n,t=Y(),s=ae(),r=new Set,i=new Set;for(let[m,p]of Object.entries(s))p.connectionStatus==="connected"&&r.add(m);let u={connectedRecruiters:r,conversationRecruiters:i},c=me(),f=new Set(["applied","skipped","expired","archived"]);return Object.entries(t).filter(([m,p])=>{if(typeof p!="object"||o&&!p.isEasyApply||p.applied)return!1;let y=c[m];return!(y&&f.has(y.status))}).map(([m,p])=>({jobId:m,score:co(p,u),job:p})).sort((m,p)=>{if(p.score!==m.score)return p.score-m.score;let y=m.job.scoutedAt||m.job.postedTime||"";return(p.job.scoutedAt||p.job.postedTime||"").localeCompare(y)}).slice(0,e)}function lo(e){if(!e)return null;let n=e.match(/[\$£€CAD\s]*([\d,]+(?:\.\d+)?)\s*[kK]?/g);if(!n||n.length===0)return null;let o=n.map(t=>{let s=parseFloat(t.replace(/[^\d.]/g,""));return t.toLowerCase().includes("k")&&(s*=1e3),s}).filter(t=>t>0);return o.length>=2?(o[0]+o[1])/2:o.length===1?o[0]:null}import"dotenv/config";import*as w from"fs";import*as I from"path";import{fileURLToPath as ho}from"url";import"dotenv/config";import{createGraphClient as ao,resolveToken as uo}from"@ilivemylife/graph-sdk";import{config as fo}from"dotenv";fo();var ge=uo()||process.env.TOKEN;ge||(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 ye=ao({token:ge});function po(e){if(!e||e<1e3)return`${e||0}ms`;let n=Math.round(e/1e3);if(n<60)return`${n}s`;let o=Math.floor(n/60),t=n%60;return t?`${o}m ${t}s`:`${o}m`}function
|
|
5
|
+
`),process.exit(1));var ye=ao({token:ge});function po(e){if(!e||e<1e3)return`${e||0}ms`;let n=Math.round(e/1e3);if(n<60)return`${n}s`;let o=Math.floor(n/60),t=n%60;return t?`${o}m ${t}s`:`${o}m`}function mo({scriptName:e,mode:n,status:o,error:t,duration:s}){let r=o==="error"?"\u2717":o==="quota-reached"?"\u26A0":"\u2713",i=new Date().toISOString().slice(0,16).replace("T"," "),u=s?` ${po(s)}`:"",c=o==="error"?`error${t?`: ${String(t).slice(0,80)}`:""}`:o==="quota-reached"?"daily quota reached":"done",f=n&&n!=="default"?` (${n})`:"";return`${r} ${e}${f} \u2014 ${c} \u2014 ${i}${u}`}async function Se({scriptName:e,mode:n,status:o,summaryLines:t,error:s,duration:r}){let i=process.env.NODE_RUN_REPORTS;if(!i||!Array.isArray(t)||t.length===0)return;let c=`**${mo({scriptName:e,mode:n,status:o,error:s,duration:r})}**
|
|
6
6
|
|
|
7
7
|
${t.join(`
|
|
8
|
-
`)}`;try{await ye.addMessage(i,c)}catch(f){console.error(`[runReport] Failed to post end-of-session message: ${f.message}`)}}var go=
|
|
8
|
+
`)}`;try{await ye.addMessage(i,c)}catch(f){console.error(`[runReport] Failed to post end-of-session message: ${f.message}`)}}var go=ho(import.meta.url),yo=I.dirname(I.dirname(go)),K=process.env.DATA_DIR?I.resolve(process.env.DATA_DIR,"collected-profiles"):I.join(yo,"collected-profiles"),Q=I.join(K,"run-log.json");function So(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";w.writeFileSync(t,o);for(let s=0;s<3;s++)try{w.renameSync(t,e);return}catch(r){if(s<2&&(r.code==="EPERM"||r.code==="EBUSY")){let i=Date.now();for(;Date.now()-i<200;);continue}throw r}}function be(){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 ve(e){w.existsSync(K)||w.mkdirSync(K,{recursive:!0});try{So(Q,e)}catch(n){console.error(`[!] Failed to save run-log.json: ${n.message}`)}}function we(e,n="default"){let o=be();for(let i of o.runs)i.status==="running"&&(i.status="interrupted",i.result="interrupted",i.timestamp&&(i.duration=Date.now()-new Date(i.timestamp).getTime()));let t=new Date,s={timestamp:t.toISOString(),script:e,mode:n,status:"running",result:null,duration:null,stats:null,error:null};o.runs.push(s);let r=Date.now()-30*24*60*60*1e3;return o.runs=o.runs.filter(i=>new Date(i.timestamp).getTime()>r),ve(o),{script:e,mode:n,startTime:t.getTime(),runIndex:o.runs.length-1}}function z(e,n,o=null,t=null){if(!e)return;let s=null;try{let i=be(),u=i.runs[e.runIndex];if(u&&u.status==="running"&&u.script===e.script)u.status=n,u.result=n,u.duration=Date.now()-e.startTime,u.stats=o,u.error=t,s=u.duration;else{let c=i.runs.find(f=>f.script===e.script&&f.status==="running"&&f.timestamp===new Date(e.startTime).toISOString());c&&(c.status=n,c.result=n,c.duration=Date.now()-e.startTime,c.stats=o,c.error=t,s=c.duration)}ve(i)}catch(i){console.error(`[runLog] Failed to end run: ${i.message}`)}let r=o&&Array.isArray(o.summaryLines)?o.summaryLines:null;if(r&&r.length>0&&process.env.NODE_RUN_REPORTS){let i=n==="error"?"error":o&&o.dailyLimitHit?"quota-reached":"done";Se({scriptName:e.script,mode:e.mode,status:i,summaryLines:r,error:t,duration:s??Date.now()-e.startTime}).catch(u=>console.error(`[runLog] postRunReport failed: ${u.message}`))}}import"dotenv/config";import*as l from"fs";import*as se from"os";import*as d from"path";import{fileURLToPath as Fo}from"url";var ee={};G(ee,{NAME:()=>vo,VERSION:()=>bo,up:()=>ko});import*as $ from"fs";import*as B from"path";var bo=1,vo="normalize-jobs-and-questions",wo=["description","techStack","jobTags","seniority","employmentType","industries","jobFunction","postedTime","applicantCount","companySize","workplaceType","contractType","isEasyApply","applyType","companyUrl","scoutedAt","lastSeen"],$o=50;function X(e){return $.existsSync(e)?JSON.parse($.readFileSync(e,"utf-8")):null}function Z(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{$.writeFileSync(t,o)}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}}async function ko(e,n){let o=B.join(e,"jobs.json"),t=B.join(n,"scouted-jobs.json"),s=B.join(e,"application-questions.json"),r=X(o)||{},i=X(t)||{},u=0,c=[];for(let a of Object.keys(r)){if(!i[a])continue;let m=i[a],p=r[a];for(let y of wo)m[y]!=null&&p[y]==null&&(p[y]=m[y]);c.push(a),u++}u>0?(Z(o,r),console.log(` Phase 1: Merged ${u} scouted jobs into jobs.json`)):console.log(" Phase 1: No overlapping jobs to merge");let f=X(s);if(f&&Array.isArray(f.applications)){let a={},m=0;for(let p of f.applications){let y=p.jobId||"unknown";a[y]||(a[y]={applications:[]});let W=(p.questions||[]).map(j=>{let M={type:j.type||"input",question:j.question||"",answer:j.answer||""};return j.options&&(j.options.length<=$o?M.options=j.options:(M.optionsOmitted=!0,m++)),j.page&&(M.page=j.page),j.wasPreFilled&&(M.wasPreFilled=!0),j.wasRetry&&(M.wasRetry=!0),M});a[y].applications.push({applicationId:p.applicationId,date:p.date,result:p.result||"submitted",formPages:p.formPages||null,duration:p.duration||null,retries:p.retries||0,failedField:p.failedField||null,questionCount:p.questionCount||W.length,questions:W})}Z(s,a),console.log(` Phase 2: Rekeyed ${f.applications.length} applications by jobId (${Object.keys(a).length} unique jobs)`),m>0&&console.log(` Phase 2: Stripped bloated options from ${m} questions`)}else f&&!f.applications?console.log(" Phase 2: application-questions.json already in keyed format"):console.log(" Phase 2: No application-questions.json found");if(c.length>0){for(let a of c)delete i[a];Z(t,i),console.log(` Phase 3: Removed ${c.length} merged entries from scouted-jobs.json (${Object.keys(i).length} remaining)`)}else console.log(" Phase 3: No entries to remove from scouted-jobs.json")}var oe={};G(oe,{NAME:()=>jo,VERSION:()=>Ao,up:()=>Ro});import*as k from"fs";import*as $e from"path";var Ao=2,jo="reset-unread-flags";function Oo(e){return k.existsSync(e)?JSON.parse(k.readFileSync(e,"utf-8")):null}function Eo(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{k.writeFileSync(t,o)}catch(s){try{k.unlinkSync(t)}catch{}throw s}try{k.renameSync(t,e)}catch(s){try{k.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 Ro(e){let n=$e.join(e,"conversations.json"),o=Oo(n);if(!o){console.log(" conversations.json not found \u2014 nothing to reset.");return}let t=0;for(let s of Object.keys(o))o[s].unread===!0&&(o[s].unread=!1,t++);if(t===0){console.log(" No stale unread flags found \u2014 nothing to do.");return}Eo(n,o),console.log(` Reset unread=false on ${t} conversations. Run 'ilml linkedin sync-all' to re-establish real unread state from LinkedIn.`)}var ne={};G(ne,{NAME:()=>To,VERSION:()=>Io,up:()=>xo});import*as A from"fs";import*as ke from"path";var Io=3,To="recompute-last-message-by",Do=new Set(["draft","confirmed","rejected","needs_review"]);function No(e){return A.existsSync(e)?JSON.parse(A.readFileSync(e,"utf-8")):null}function Co(e,n){let o=JSON.stringify(n,null,2),t=e+".tmp";try{A.writeFileSync(t,o)}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}}function _o(e,n){if(!e||e.length===0)return"them";let o=e.filter(r=>!Do.has(r.status));if(o.length===0)return"them";let t=o.map(r=>({m:r,t:Date.parse(r.time)})).filter(r=>Number.isFinite(r.t)).sort((r,i)=>i.t-r.t).map(r=>r.m),s=t.length>0?t:[...o].reverse();for(let r of s){let i=r.sender;if(i===n)return"me";if(i!=="Unknown"&&i!=="")return"them"}return"them"}async function xo(e){let n=ke.join(e,"conversations.json"),o=No(n);if(!o){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,i=0;for(let u of Object.keys(o)){let c=o[u];if(!c||typeof c!="object")continue;Object.prototype.hasOwnProperty.call(c,"_cardSynced")&&(delete c._cardSynced,r++);let f=Array.isArray(c.messages)?c.messages:[],a=_o(f,t),m=a==="me"?"awaiting_reply":"unanswered_by_us";c.lastMessageBy!==a&&i++,c.lastMessageBy=a,c.conversationStatus=m,s++}if(s===0){console.log(" No conversations to recompute.");return}Co(n,o),console.log(` Recomputed lastMessageBy + conversationStatus on ${s} conversations.`),console.log(` ${i} 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 Lo=Fo(import.meta.url),Mo=d.dirname(Lo),Po=d.dirname(d.dirname(Mo));function Jo(e){return e&&(e==="~"?se.homedir():e.startsWith("~/")||e.startsWith("~\\")?d.join(se.homedir(),e.slice(2)):e)}var O=process.env.DATA_DIR?d.resolve(Jo(process.env.DATA_DIR)):Po,x=d.join(O,"collected-profiles"),F=d.join(O,"market-research"),S=d.join(O,".schema-version"),Ae=[d.join(x,".schema-version"),d.join(F,".schema-version")],T=3,R=[{version:1,module:ee},{version:2,module:oe},{version:3,module:ne}];(function(){R.sort((t,s)=>t.version-s.version);let n=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(n.has(t.version))throw new Error(`MIGRATION_REGISTRY: duplicate version v${t.version}`);n.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 o=R.length?R[R.length-1].version:0;if(o!==T)throw new Error(`MIGRATION_REGISTRY: highest version v${o} but CURRENT_SCHEMA_VERSION=${T}. 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 Re(){process.env.DATA_DIR!==void 0&&process.env.DATA_DIR.trim()===""&&process.env.DATA_DIR.length>0&&(console.error(`
|
|
9
9
|
[FATAL] DATA_DIR is set to whitespace ("${process.env.DATA_DIR}"). Either unset it or set a real path.
|
|
10
10
|
`),process.exit(1));try{l.mkdirSync(O,{recursive:!0})}catch(n){n.code!=="EEXIST"&&(console.error(`
|
|
11
11
|
[FATAL] Cannot create DATA_DIR (${O}): ${n.message}`),console.error(` Fix the path or permissions and try again.
|
|
@@ -45,7 +45,7 @@ ${t.join(`
|
|
|
45
45
|
[FATAL] Migration ${r} applied successfully but schema version file could NOT be updated: ${c.message}`),console.error(` Your data is in the v${s.version} state but .schema-version still shows v${n}.`),console.error(` On next plugin command the runner will try to re-apply ${r}. If that migration is`),console.error(` idempotent (most are), it will succeed harmlessly. If you're unsure, run 'data-cleanup' and contact support.
|
|
46
46
|
`),process.exit(1)}console.log(` \u2713 Migration ${r} complete`)}try{le()}catch{}try{pe()}catch{}te=!0,re(),console.log(`
|
|
47
47
|
\u2713 Schema is now at v${T}
|
|
48
|
-
`)}var Go=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Yo(e){let n=e.toLowerCase();return Go.some(o=>o.test(n))}var Ho=6e4;function Ko(){let e=Date.now(),n=[];for(let o of[O,x,F]){if(!l.existsSync(o))continue;let t;try{t=l.readdirSync(o)}catch{continue}for(let s of t){if(!Yo(s))continue;let r=d.join(o,s);try{let i=l.statSync(r);if(!i.isFile()||e-i.mtimeMs<Ho)continue;n.push({dir:o,file:s,fullPath:r})}catch{}}}return n}function Qo({verbose:e=!1}={}){let n=Ko();if(n.length===0)return e&&console.log(" No orphan .tmp files found."),0;let o=0;for(let t of n)try{l.unlinkSync(t.fullPath),o++,e&&console.log(` Removed orphan: ${d.basename(t.dir)}/${t.file}`)}catch(s){console.warn(` [!] Could not remove orphan ${t.fullPath}: ${s.message}`)}return!e&&o>0&&console.log(` Cleaned up ${o} orphan .tmp file(s) from previous run.`),o}function zo(){let e=[];for(let n of[x,F]){if(!l.existsSync(n))continue;let o=l.readdirSync(n).filter(t=>{let s=t.toLowerCase();return s.endsWith(".json")&&!s.includes(".backup")});for(let t of o){let s=d.join(n,t);try{q(s)}catch(r){e.push({dir:d.basename(n),file:t,err:r.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function Xo(e){let n=[],o=[];for(let r of[x,F]){if(!l.existsSync(r))continue;let i=l.readdirSync(r).filter(u=>u.endsWith(e));for(let u of i){let c=d.join(r,u),f=u.slice(0,-e.length),a=d.join(r,f);try{f.toLowerCase().endsWith(".json")?q(c):l.accessSync(c,l.constants.R_OK),n.push({backupPath:c,originalPath:a,fileName:u,dir:r})}catch(
|
|
48
|
+
`)}var Go=[/\.json\.tmp$/,/\.schema-version\.tmp$/,/\.backup\.tmp$/];function Yo(e){let n=e.toLowerCase();return Go.some(o=>o.test(n))}var Ho=6e4;function Ko(){let e=Date.now(),n=[];for(let o of[O,x,F]){if(!l.existsSync(o))continue;let t;try{t=l.readdirSync(o)}catch{continue}for(let s of t){if(!Yo(s))continue;let r=d.join(o,s);try{let i=l.statSync(r);if(!i.isFile()||e-i.mtimeMs<Ho)continue;n.push({dir:o,file:s,fullPath:r})}catch{}}}return n}function Qo({verbose:e=!1}={}){let n=Ko();if(n.length===0)return e&&console.log(" No orphan .tmp files found."),0;let o=0;for(let t of n)try{l.unlinkSync(t.fullPath),o++,e&&console.log(` Removed orphan: ${d.basename(t.dir)}/${t.file}`)}catch(s){console.warn(` [!] Could not remove orphan ${t.fullPath}: ${s.message}`)}return!e&&o>0&&console.log(` Cleaned up ${o} orphan .tmp file(s) from previous run.`),o}function zo(){let e=[];for(let n of[x,F]){if(!l.existsSync(n))continue;let o=l.readdirSync(n).filter(t=>{let s=t.toLowerCase();return s.endsWith(".json")&&!s.includes(".backup")});for(let t of o){let s=d.join(n,t);try{q(s)}catch(r){e.push({dir:d.basename(n),file:t,err:r.message})}}}return e.length===0?{ok:!0}:{ok:!1,broken:e}}function Xo(e){let n=[],o=[];for(let r of[x,F]){if(!l.existsSync(r))continue;let i=l.readdirSync(r).filter(u=>u.endsWith(e));for(let u of i){let c=d.join(r,u),f=u.slice(0,-e.length),a=d.join(r,f);try{f.toLowerCase().endsWith(".json")?q(c):l.accessSync(c,l.constants.R_OK),n.push({backupPath:c,originalPath:a,fileName:u,dir:r})}catch(m){o.push(`${d.basename(r)}/${u}: ${m.message}`)}}}if(o.length>0)return{ok:!1,error:o.join("; "),restored:0};let t=0,s=[];for(let{backupPath:r,originalPath:i,fileName:u,dir:c}of n)try{De(r,i),t++}catch(f){s.push(`${d.basename(c)}/${u}: ${f.message}`)}return s.length>0?{ok:!1,error:s.join("; "),restored:t}:{ok:!0,restored:t}}function De(e,n){let o=n+".tmp";try{l.copyFileSync(e,o),Ie(o)}catch(t){try{l.unlinkSync(o)}catch{}throw t}try{l.renameSync(o,n)}catch(t){try{l.unlinkSync(o)}catch{}if(t.code==="EPERM"||t.code==="EBUSY"){let s=new Error(`File locked: ${n} (${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 s.code=t.code,s}throw t}}var on=Zo(import.meta.url),nn=L.dirname(on),ie=process.env.DATA_DIR?L.resolve(process.env.DATA_DIR,"collected-profiles"):L.join(nn,"collected-profiles");await Te();var ce=process.argv.slice(2),Ne=parseInt(ce.find(e=>e.startsWith("--max="))?.split("=")[1]||"50"),V=parseInt(ce.find(e=>e.startsWith("--min-score="))?.split("=")[1]||"50"),tn=ce.includes("--list");function sn(){let n=H(20,{easyApplyOnly:!0}).filter(o=>o.score>=V);if(console.log(`
|
|
49
49
|
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\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(` APPLY QUEUE (${n.length} jobs, min score ${V})`),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"),n.length===0)console.log(" No jobs in queue. Run: npm run scout");else for(let o=0;o<n.length;o++){let{score:t,job:s,jobId:r}=n[o],i=(s.techStack||[]).slice(0,4).join(", ");console.log(` ${String(o+1).padStart(2)}. [${t}] ${(s.title||"?").slice(0,35)} @ ${(s.company||"?").slice(0,20)}`),console.log(` ${s.salary||"no salary"} | ${s.location||"?"} | ${i||"no tech"}`),console.log(` ${s.url}`)}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
|
|
50
50
|
`)}async function rn(){if(console.log(`
|
|
51
51
|
LinkedIn Apply Queue
|
package/dist/enrichProfile.mjs
CHANGED
|
@@ -1,41 +1,264 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Xe=Object.defineProperty;var Ae=(t,e)=>()=>(t&&(e=t(t=0)),e);var et=(t,e)=>{for(var n in e)Xe(t,n,{get:e[n],enumerable:!0})};async function w(t){let e=Math.floor(Math.random()*2001),n=t+e;return new Promise(o=>setTimeout(o,n))}async function $e(t){return await t.evaluate(()=>{let e=document.querySelectorAll("div.artdeco-modal--is-open");for(let o of e){let i=o.innerText||"",s=i.includes("Premium")||i.includes("premium")||i.includes("Upgrade")||i.includes("upgrade"),f=i.includes("Try for")||i.includes("free trial")||i.includes("/month")||i.includes("per month")||i.includes("Start my")||i.includes("Subscribe"),d=i.includes("Get hired faster")||i.includes("Get hired 2x");if(s||f||d){let D=o.querySelector('button[aria-label="Dismiss"]')||o.querySelector("button.artdeco-modal__dismiss")||o.querySelector("button[data-test-modal-close-btn]");if(D)return D.click(),{dismissed:!0,matched:i.substring(0,80)};let $=o.querySelectorAll("button");for(let a of $){let S=a.innerText?.trim().toLowerCase()||"",p=a.getAttribute("aria-label")?.toLowerCase()||"";if(S==="not now"||S==="no thanks"||S==="dismiss"||p.includes("dismiss"))return a.click(),{dismissed:!0,matched:i.substring(0,80)}}}}let n=document.querySelector(".premium-upsell-link")||document.querySelector("[data-test-premium-upsell]")||document.querySelector(".premium-hub-upsell");if(n){let o=n.closest('[class*="modal"]')?.querySelector('button[aria-label="Dismiss"]')||n.closest('[class*="banner"]')?.querySelector('button[aria-label="Close"]');if(o)return o.click(),{dismissed:!0,matched:"premium-banner"}}return!1})}var re=Ae(()=>{});var Re={};et(Re,{extractCertificationsFromDetails:()=>bt,extractEducationFromDetails:()=>gt,extractExperienceFromDetails:()=>ht,extractFeaturedFromDetails:()=>wt,extractRecommendationsFromDetails:()=>St,extractSkillsFromDetails:()=>yt});async function ht(t,e){let n=e.replace(/\/+$/,"")+"/details/experience/";try{await t.goto(n,{waitUntil:"domcontentloaded",timeout:6e4}),await w(3e3);let o=t.url();if(/\/(login|authwall|checkpoint)/i.test(o))throw new Error(`Session expired \u2014 bounced to ${o} when fetching /details/experience/`);for(let s=0;s<5;s++)await t.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await w(900);await w(1e3);let i=0;for(;i<5&&await t.evaluate(()=>{for(let f of document.querySelectorAll("button"))if(/^Load more$/i.test((f.textContent||"").trim()))return f.click(),!0;return!1});)i++,await w(1500),await t.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await w(700);return await t.evaluate(()=>{let s=document.querySelector("main");if(!s)return[];function f(a){let S=[];for(let p of a.querySelectorAll("div")){let h=Array.from(p.children).filter(v=>v.tagName==="DIV");if(h.length<3)continue;let y=h.filter(v=>(v.textContent||"").trim().length>50);y.length<3||(p.textContent||"").length<500||S.push({el:p,count:y.length,totalText:(p.textContent||"").length})}return S.sort((p,h)=>h.count-p.count||p.totalText-h.totalText),S[0]?.el}let d=f(s);if(!d)return[];let D=Array.from(d.children).filter(a=>a.tagName==="DIV").filter(a=>(a.textContent||"").trim().length>50);function $(a){let S=a[0]||null,p=null,h=null;if(a[1]){let c=a[1].split("\xB7").map(k=>k.trim());p=c[0]||null,c[1]&&(h=c[1])}let y=a.findIndex(c=>/(\d{4}|present)/i.test(c)&&/(-|–|—)/i.test(c)&&c.length<80),v=null,M=null;if(y>=0){let c=a[y].split("\xB7").map(k=>k.trim());v=c[0]||null,c[1]&&(M=c[1])}let F=null,ne=-1;if(y>=0&&a[y+1]){let c=a[y+1],k=/^[>*\-•]|^>/.test(c),j=/https?:\/\//.test(c),x=/\d{4}/.test(c),V=/,/.test(c)||/\bArea\b|\bRegion\b|\bProvince\b|\bCountry\b|, [A-Z]{2}\b/.test(c);!k&&!j&&!x&&c.length<100&&V&&(F=c,ne=y+1)}let b=null,P=-1,I=a[a.length-1];if(I&&/and\s+\+\d+\s+skills?$/i.test(I)){P=a.length-1;let c=I.match(/^(.+?)\s+and\s+\+(\d+)\s+skills?$/i);c&&(b={listed:c[1].split(",").map(k=>k.trim()),additional:parseInt(c[2],10)})}let L=new Set([0,1,y,ne,P].filter(c=>c>=0)),C=a.filter((c,k)=>!L.has(k)),oe=C.length>0?C.join(`
|
|
2
2
|
|
|
3
|
-
`):null;return{title:
|
|
4
|
-
`).map(g=>g.trim()).filter(g=>g&&g.length<5e3);return I(d)}).filter(a=>a.title)})}catch(o){if(/session expired|bounced to|authwall|checkpoint/i.test(o.message||""))throw o;return console.error(`extractExperienceFromDetails failed for ${e}: ${o.message?.slice(0,120)}`),[]}}var ge=le(()=>{K()});import"dotenv/config";import Qe from"puppeteer";K();import{getPluginConfig as Me}from"@ilivemylife/graph-sdk";var Le=await Me();for(let[t,e]of Object.entries(Le))process.env[t]===void 0&&(process.env[t]=e);var tt=process.env.LINKEDIN_NAME,_=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),nt=Object.freeze(new Set([_.DRAFT,_.CONFIRMED,_.NEEDS_REVIEW])),ot=Object.freeze(new Set([_.DRAFT,_.CONFIRMED,_.REJECTED,_.NEEDS_REVIEW]));import"dotenv/config";import*as f from"fs";import*as p from"path";import{fileURLToPath as Ne}from"url";var je=Ne(import.meta.url),Pe=p.dirname(p.dirname(je)),v=process.env.DATA_DIR?p.resolve(process.env.DATA_DIR,"collected-profiles"):p.join(Pe,"collected-profiles"),z=p.join(v,"people.json"),at=p.join(v,"jobs.json"),ct=p.join(v,"quota.json"),ut=p.join(v,"conversations.json"),dt=p.join(v,"sync-state.json"),ft=p.join(v,"application-questions.json"),Q=p.join(v,"profile-history");var T=null;function de(){f.existsSync(v)||f.mkdirSync(v,{recursive:!0})}function fe(t,e){let n=JSON.stringify(e,null,2),o=t+".tmp";f.writeFileSync(o,n);for(let i=0;i<3;i++)try{f.renameSync(o,t);return}catch(r){if(i<2&&(r.code==="EPERM"||r.code==="EBUSY")){let w=Date.now();for(;Date.now()-w<200;);continue}throw r}}function me(t,e){if(!f.existsSync(t))return null;try{let n=JSON.parse(f.readFileSync(t,"utf-8"));try{f.copyFileSync(t,t+".backup")}catch{}return n}catch(n){console.error(`[!] ${e} is corrupted: ${n.message}`),console.error(` File: ${p.resolve(t)}`);let o=t+".backup";if(f.existsSync(o))try{let i=JSON.parse(f.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{f.copyFileSync(o,t)}catch{}return i}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${t}.corrupted`);try{f.copyFileSync(t,t+".corrupted")}catch{}return null}}function Te(){return new Date().toISOString().split("T")[0]}var Fe=["name","title","location","company","connectionDegree","connectionsCount","mutualConnections","photoUrl","hasVerifiedBadge","about","currentCompany","currentSchool","connectionsLevel","mutualConnectionsCount","followers","openToWork","hiring","topSkills","availableSections","experience","featuredLinks","_lastEnrichedAt"],Oe=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function G(t){if(!t)return null;let e=t.match(/\/in\/([^/?#]+)/);return e?e[1].toLowerCase():null}function Re(){f.existsSync(Q)||f.mkdirSync(Q,{recursive:!0})}function pe(t){let e=G(t);return e?p.join(Q,`${e}.json`):null}function qe(t){let e=pe(t);return e?me(e,`profile-history/${G(t)}.json`)||[]:[]}function Be(t,e){let n=pe(t);if(!n)return;Re();let o=qe(t);o.unshift(e);try{fe(n,o)}catch(i){console.error(`[!] Failed to append profile-history for ${G(t)}: ${i.message}`)}}function ce(t){return!!(t==null||Array.isArray(t)&&t.length===0||typeof t=="string"&&!t.trim())}function ue(t){return Array.isArray(t)?[...t].map(e=>String(e).trim()).sort().join("||"):typeof t=="string"?t.replace(/\s+/g," ").trim():t}function Ue(t,e){if(!t)return[];let n=[];for(let o of Oe){let i=t[o],r=e[o];ce(i)||ce(r)||ue(i)!==ue(r)&&n.push(o)}return n}function He(t){let e=new Set(["seenCount","sources","firstSeen","lastSeen","lastUpdated","encounters","jobIds","lastFullVisitAt","lastSnapshotAt","messageSent","connectionStatus","connectionDate","connectionMethod"]),n={};for(let[o,i]of Object.entries(t))e.has(o)||(n[o]=i);return n}function he(){return T||(de(),T=me(z,"people.json")||{},T)}function Ve(t){de(),T=t;try{fe(z,t)}catch(e){console.error(`[!] Failed to save people.json: ${e.message}`),console.error(` Path: ${p.resolve(z)}`)}}function Z(t,e={}){if(!t)return null;let n=he(),o=Te(),i=new Date().toISOString(),r=n[t];if(r){let w=Ue(r,e);w.length>0&&(Be(t,{capturedAt:i,previousLastUpdated:r.lastUpdated||null,changedFields:w,snapshot:He(r)}),r.lastSnapshotAt=i),r.seenCount=(r.seenCount||1)+1,r.lastSeen=o,r.lastUpdated=i,e.source&&!r.sources?.includes(e.source)&&(r.sources=r.sources||[],r.sources.push(e.source));for(let m of Fe)if(e[m]!=null){if(Array.isArray(e[m])&&e[m].length===0&&Array.isArray(r[m])&&r[m].length>0)continue;r[m]=e[m]}Array.isArray(e.availableSections)&&(r.lastFullVisitAt=i)}else n[t]={name:e.name||null,title:e.title||null,location:e.location||null,company:e.company||null,about:e.about||null,connectionDegree:e.connectionDegree||null,connectionsCount:e.connectionsCount||null,mutualConnections:e.mutualConnections||null,photoUrl:e.photoUrl||null,hasVerifiedBadge:e.hasVerifiedBadge||!1,currentCompany:e.currentCompany||null,currentSchool:e.currentSchool||null,connectionsLevel:e.connectionsLevel||null,mutualConnectionsCount:e.mutualConnectionsCount||null,followers:e.followers||null,openToWork:e.openToWork||!1,hiring:e.hiring||!1,topSkills:e.topSkills||null,availableSections:e.availableSections||null,experience:e.experience||null,featuredLinks:e.featuredLinks||null,_lastEnrichedAt:e._lastEnrichedAt||null,firstSeen:o,lastSeen:o,seenCount:1,sources:e.source?[e.source]:[],connectionStatus:null,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:i,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(e.availableSections)?i:null};return Ve(n),n[t]}async function Je(t,e){let n=t.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: npm run login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await t.goto(e,{waitUntil:"domcontentloaded",timeout:6e4}),await k(3e3);let o=t.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function be(t,e,n={}){let{extractExperience:o=!1}=n;try{await t.goto(e,{waitUntil:"domcontentloaded",timeout:6e4}),await k(3e3),await ae(t)&&(console.log(" Dismissed Premium overlay"),await k(1500),await Je(t,e));let r=0;for(let C=0;C<2;C++){let I=await t.evaluate(()=>document.body.scrollHeight);for(let h=1;h<=6;h++)await t.evaluate(d=>window.scrollTo(0,d),I*h/6),await k(900);let a=await t.evaluate(()=>document.body.scrollHeight);if(a===r)break;r=a}await k(800);let w=await t.evaluate(()=>{let C=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),I=new Set(["Ad Options","Don\u2019t want to see this","0 notifications","Explore Premium profiles","You might like","People you may know","Suggested for you","More profiles for you","Promoted"]),a=s=>{let l=(s||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(l)},h={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},d=document.querySelector("main");if(!d)return h;let g=[...Array.from(d.querySelectorAll("h1")),...Array.from(d.querySelectorAll("h2"))],b=Array.from(d.querySelectorAll("h2")),x=g.find(s=>{let l=s.textContent&&s.textContent.trim(),c=(l||"").replace(/\s*\(\d+\)$/,"").trim();return l&&l.length>1&&l.length<100&&!C.has(c)&&!I.has(c)}),A=x?x.textContent.trim():null,y=x?x.parentElement:null;for(;y&&y!==d&&!Array.from(y.children).filter(l=>l.tagName==="P").some(l=>{let c=l.textContent&&l.textContent.trim();return c&&c.length>5&&!a(c)});)y=y.parentElement;let L=null,N=null,j=null,$=null;if(y&&y!==d){let s=Array.from(y.children).filter(c=>c.tagName==="P").filter(c=>{let E=c.textContent&&c.textContent.trim();return E&&E.length>5&&!a(E)});if(s[0]&&(L=s[0].textContent.trim()),s[1]){let c=s[1].textContent.trim().split(/\s*[·•]\s*/);N=c[0]||null,c.length>1&&(j=c.slice(1).join(" \xB7 "))}let l=Array.from(y.children).filter(c=>c.tagName==="DIV");for(let c=l.length-1;c>=0;c--){let E=l[c].textContent&&l[c].textContent.trim();if(E&&!(A&&E.startsWith(A))&&($=E.split(/[·•]/)[0].trim(),$))break}}let O=null;if(y){let s=y.querySelectorAll("p, span, div");for(let l of s){let c=(l.textContent||"").trim().replace(/^[·•]\s*/,"");if(c==="1st"||c==="2nd"||c==="3rd"){O=c;break}}}let R=!!d.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),q=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),u=q&&q.src||null,S=d.textContent||"",B=null,U=S.match(/(\d+\+?)\s+connections\b/i);U&&(B=U[1]+" connections");let M=null,ee=S.match(/(\d+)\s+mutual connection/i),te=S.match(/and\s+(\d+)\s+other mutual/i),ve=S.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);ee?M=parseInt(ee[1],10):te?M=2+parseInt(te[1],10):ve&&(M=2);let ne=null,oe=null,ie=b.find(s=>s.textContent&&s.textContent.trim()==="About");if(ie){let s=ie.parentElement;for(;s&&s.tagName!=="SECTION";)s=s.parentElement;if(s){let l=(s.textContent||"").trim();l=l.replace(/^About\s*/,"").trim();let c=l.match(/Top skills\s*(.+?)$/i);if(c){let Y=c[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map($e=>$e.trim()).filter(Boolean);Y.length>0&&Y.length<10&&(oe=Y)}l=l.split(/\n?…\s*more/i)[0].trim(),l=l.split(/\n?\.\.\.\s*more/i)[0].trim(),l=l.split(/\bTop skills\b/i)[0].trim(),l=l.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),ne=l||null}}let se=null,re=b.find(s=>s.textContent&&s.textContent.trim()==="Activity");if(re){let s=re.parentElement;for(;s&&s.tagName!=="SECTION";)s=s.parentElement;if(s){let l=(s.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);l&&(se=parseInt(l[1].replace(/,/g,""),10))}}let Ee=[...new Set(b.map(s=>(s.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(s=>s&&s.length>1&&s.length<60&&s!==A).filter(s=>C.has(s)))],P=document.body.textContent||"",Ie=/#OpenToWork\b/i.test(P)||/\bOpen to work\b/.test(P),Ae=/#Hiring\b/i.test(P)||/\bI'?m hiring\b/i.test(P)||/\bWe are hiring\b/i.test(P);return{name:A,title:L,location:$,currentCompany:N,currentSchool:j,connectionDegree:O,hasVerifiedBadge:R,photoUrl:u,connectionsLevel:B,mutualConnectionsCount:M,followers:se,openToWork:Ie,hiring:Ae,about:ne,topSkills:oe,availableSections:Ee}});console.log(`Viewed: ${w.name} - ${w.title}`);let m=null;if(o){let{extractExperienceFromDetails:C}=await Promise.resolve().then(()=>(ge(),we));m=await C(t,e),console.log(` + Experience: ${m.length} entries`)}return{...w,profileUrl:e,...m!==null&&{experience:m}}}catch(i){console.error(`Error viewing profile ${e}:`,i.message);try{await t.goto("about:blank",{timeout:1e4}),await k(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test(i.message||""))throw i;return null}}import ye from"fs";import Ye from"path";var Ke="cookies.json";function ze(){let t=process.env.ILML_SCOPE_DIR;return t?Ye.join(t,"plugins-state","linkedin","cookies.json"):Ke}function Se(){let t=ze();if(!ye.existsSync(t))throw new Error(`Cookies not found at ${t}. Run: ilml linkedin login`);let e;try{e=ye.readFileSync(t,"utf-8")}catch(o){throw new Error(`Failed to read cookies at ${t}: ${o.message}. Run: ilml linkedin login`)}let n;try{n=JSON.parse(e)}catch{throw new Error(`Cookies file at ${t} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(n)||n.length===0)throw new Error(`Cookies file at ${t} is empty or not an array. Run: ilml linkedin login`);return n}function ke(t){return t?t.replace(/^https?:\/\/(www\.|m\.)?linkedin\.com/i,"https://linkedin.com").split("?")[0].split("#")[0].replace(/\/+$/,"").toLowerCase():""}function Ce(t){return(t||"").replace(/ /g," ").replace(/\s+/g," ").trim().toLowerCase()}var W=process.argv.slice(2),Ge=W.includes("--help")||W.includes("-h"),D=W.find(t=>t.startsWith("http")),F=W.includes("--with-experience");function xe(){console.log(`
|
|
3
|
+
`):null;return{title:S,company:p,employmentType:h,dates:v,duration:M,location:F,description:oe,skills:b,_raw:a}}return D.map(a=>{let p=(a.innerText||"").trim().split(`
|
|
4
|
+
`).map(h=>h.trim()).filter(h=>h&&h.length<5e3);return $(p)}).filter(a=>a.title)})}catch(o){if(/session expired|bounced to|authwall|checkpoint/i.test(o.message||""))throw o;return console.error(`extractExperienceFromDetails failed for ${e}: ${o.message?.slice(0,120)}`),[]}}async function B(t,e,n){let o=e.replace(/\/+$/,"")+`/details/${n}/`;await t.goto(o,{waitUntil:"domcontentloaded",timeout:6e4}),await w(3e3);let i=t.url();if(/\/(login|authwall|checkpoint)/i.test(i))throw new Error(`Session expired \u2014 bounced to ${i} when fetching /details/${n}/`);if(!i.toLowerCase().includes(`/details/${n.toLowerCase()}/`))throw new Error(`Section /details/${n}/ not available on profile (landed on ${i})`);for(let f=0;f<4;f++)await t.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await w(700);await w(800);let s=0;for(;s<5&&await t.evaluate(()=>{for(let d of document.querySelectorAll("button"))if(/^Load more$/i.test((d.textContent||"").trim()))return d.click(),!0;return!1});)s++,await w(1300),await t.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await w(600)}async function U(t,e,n,o){try{return await o()}catch(i){let s=i.message||"";if(/session expired|bounced to|authwall|checkpoint/i.test(s))throw i;return/not available on profile/i.test(s)?(console.log(` (${e}: section not on profile \u2014 skipped)`),[]):(console.error(`${n} failed for ${t}: ${s.slice(0,120)}`),[])}}async function wt(t,e){return U(e,"featured","extractFeaturedFromDetails",async()=>(await B(t,e,"featured"),await t.evaluate(`(() => {
|
|
5
|
+
${H}
|
|
6
|
+
|
|
7
|
+
const main = document.querySelector('main');
|
|
8
|
+
if (!main) return [];
|
|
9
|
+
const container = findEntryContainer(main);
|
|
10
|
+
if (!container) return [];
|
|
11
|
+
|
|
12
|
+
const entries = Array.from(container.children)
|
|
13
|
+
.filter(c => c.tagName === 'DIV')
|
|
14
|
+
.filter(c => (c.textContent || '').trim().length > 30);
|
|
15
|
+
|
|
16
|
+
return entries.map(entry => {
|
|
17
|
+
const raw = (entry.innerText || '').trim();
|
|
18
|
+
const lines = raw.split('\\n').map(l => l.trim()).filter(l => l && l.length < 2000);
|
|
19
|
+
|
|
20
|
+
// External link from any anchor inside the card (filter LinkedIn-internal)
|
|
21
|
+
const anchors = Array.from(entry.querySelectorAll('a[href]'));
|
|
22
|
+
const externalAnchor = anchors.find(a => {
|
|
23
|
+
const h = a.href || '';
|
|
24
|
+
return h.startsWith('http') &&
|
|
25
|
+
!h.includes('linkedin.com/in/') &&
|
|
26
|
+
!h.includes('linkedin.com/posts/') &&
|
|
27
|
+
!h.includes('#');
|
|
28
|
+
});
|
|
29
|
+
const url = externalAnchor?.href || anchors[0]?.href || null;
|
|
30
|
+
|
|
31
|
+
const title = lines[0] || null;
|
|
32
|
+
const caption = lines[1] && lines[1] !== title ? lines[1] : null;
|
|
33
|
+
|
|
34
|
+
return { title, caption, url, _raw: lines };
|
|
35
|
+
}).filter(e => {
|
|
36
|
+
if (!e.title) return false;
|
|
37
|
+
// Reject "People You May Know" sidebar cards: signature is
|
|
38
|
+
// exactly [title, "View"] with no url/caption beyond "View".
|
|
39
|
+
if (e._raw.length === 2 && e._raw[1] === 'View') return false;
|
|
40
|
+
return true;
|
|
41
|
+
});
|
|
42
|
+
})()`)))}async function gt(t,e){return U(e,"education","extractEducationFromDetails",async()=>(await B(t,e,"education"),await t.evaluate(`(() => {
|
|
43
|
+
${H}
|
|
44
|
+
|
|
45
|
+
const main = document.querySelector('main');
|
|
46
|
+
if (!main) return [];
|
|
47
|
+
const container = findEntryContainer(main);
|
|
48
|
+
if (!container) return [];
|
|
49
|
+
|
|
50
|
+
const entries = Array.from(container.children)
|
|
51
|
+
.filter(c => c.tagName === 'DIV')
|
|
52
|
+
.filter(c => (c.textContent || '').trim().length > 30);
|
|
53
|
+
|
|
54
|
+
return entries.map(entry => {
|
|
55
|
+
const raw = (entry.innerText || '').trim();
|
|
56
|
+
const lines = raw.split('\\n').map(l => l.trim()).filter(l => l && l.length < 5000);
|
|
57
|
+
|
|
58
|
+
const school = lines[0] || null;
|
|
59
|
+
const degree = lines[1] || null;
|
|
60
|
+
const dates = lines.find(l =>
|
|
61
|
+
/(\\d{4})/.test(l) &&
|
|
62
|
+
/(-|\u2013|\u2014)/i.test(l) &&
|
|
63
|
+
l.length < 80
|
|
64
|
+
) || null;
|
|
65
|
+
const used = new Set([0, 1, dates ? lines.indexOf(dates) : -1].filter(i => i >= 0));
|
|
66
|
+
const descLines = lines.filter((_, i) => !used.has(i));
|
|
67
|
+
const description = descLines.length > 0 ? descLines.join(' / ') : null;
|
|
68
|
+
|
|
69
|
+
return { school, degree, dates, description, _raw: lines };
|
|
70
|
+
}).filter(e => {
|
|
71
|
+
if (!e.school) return false;
|
|
72
|
+
// Reject "People You May Know" sidebar cards: [title, "View"].
|
|
73
|
+
if (e._raw.length === 2 && e._raw[1] === 'View') return false;
|
|
74
|
+
return true;
|
|
75
|
+
});
|
|
76
|
+
})()`)))}async function yt(t,e){return U(e,"skills","extractSkillsFromDetails",async()=>(await B(t,e,"skills"),await t.evaluate(`(() => {
|
|
77
|
+
${H}
|
|
78
|
+
|
|
79
|
+
const main = document.querySelector('main');
|
|
80
|
+
if (!main) return [];
|
|
81
|
+
const container = findEntryContainer(main);
|
|
82
|
+
if (!container) return [];
|
|
83
|
+
|
|
84
|
+
const entries = Array.from(container.children)
|
|
85
|
+
.filter(c => c.tagName === 'DIV')
|
|
86
|
+
.filter(c => (c.textContent || '').trim().length > 1);
|
|
87
|
+
|
|
88
|
+
const seen = new Set();
|
|
89
|
+
const skills = [];
|
|
90
|
+
for (const entry of entries) {
|
|
91
|
+
const raw = (entry.innerText || '').trim();
|
|
92
|
+
const lines = raw.split('\\n').map(l => l.trim()).filter(Boolean);
|
|
93
|
+
if (lines.length === 0) continue;
|
|
94
|
+
|
|
95
|
+
const name = lines[0];
|
|
96
|
+
if (!name || name.length > 100 || seen.has(name.toLowerCase())) continue;
|
|
97
|
+
seen.add(name.toLowerCase());
|
|
98
|
+
|
|
99
|
+
let endorsements = null;
|
|
100
|
+
for (const l of lines.slice(1)) {
|
|
101
|
+
const m = l.match(/(\\d+)\\s+endorsement/i);
|
|
102
|
+
if (m) { endorsements = parseInt(m[1], 10); break; }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
skills.push({ name, endorsements, _raw: lines });
|
|
106
|
+
}
|
|
107
|
+
return skills;
|
|
108
|
+
})()`)))}async function bt(t,e){return U(e,"certifications","extractCertificationsFromDetails",async()=>(await B(t,e,"certifications"),await t.evaluate(`(() => {
|
|
109
|
+
${H}
|
|
110
|
+
|
|
111
|
+
const main = document.querySelector('main');
|
|
112
|
+
if (!main) return [];
|
|
113
|
+
const container = findEntryContainer(main);
|
|
114
|
+
if (!container) return [];
|
|
115
|
+
|
|
116
|
+
const entries = Array.from(container.children)
|
|
117
|
+
.filter(c => c.tagName === 'DIV')
|
|
118
|
+
.filter(c => (c.textContent || '').trim().length > 20);
|
|
119
|
+
|
|
120
|
+
return entries.map(entry => {
|
|
121
|
+
const raw = (entry.innerText || '').trim();
|
|
122
|
+
const lines = raw.split('\\n').map(l => l.trim()).filter(l => l && l.length < 2000);
|
|
123
|
+
|
|
124
|
+
const name = lines[0] || null;
|
|
125
|
+
const issuer = lines[1] || null;
|
|
126
|
+
const issueDate = lines.find(l => /^Issued\\b/i.test(l)) || null;
|
|
127
|
+
const expiryDate = lines.find(l => /Expir(es|ed)\\b/i.test(l)) || null;
|
|
128
|
+
const credentialId = (lines.find(l => /credential id/i.test(l)) || '')
|
|
129
|
+
.replace(/^.*credential id[:\\s]*/i, '').trim() || null;
|
|
130
|
+
|
|
131
|
+
return { name, issuer, issueDate, expiryDate, credentialId, _raw: lines };
|
|
132
|
+
}).filter(e => e.name);
|
|
133
|
+
})()`)))}async function St(t,e){return U(e,"recommendations","extractRecommendationsFromDetails",async()=>(await B(t,e,"recommendations"),await t.evaluate(`(() => {
|
|
134
|
+
${H}
|
|
135
|
+
|
|
136
|
+
const main = document.querySelector('main');
|
|
137
|
+
if (!main) return [];
|
|
138
|
+
const container = findEntryContainer(main);
|
|
139
|
+
if (!container) return [];
|
|
140
|
+
|
|
141
|
+
const entries = Array.from(container.children)
|
|
142
|
+
.filter(c => c.tagName === 'DIV')
|
|
143
|
+
.filter(c => (c.textContent || '').trim().length > 50);
|
|
144
|
+
|
|
145
|
+
return entries.map(entry => {
|
|
146
|
+
const raw = (entry.innerText || '').trim();
|
|
147
|
+
const lines = raw.split('\\n').map(l => l.trim()).filter(l => l && l.length < 5000);
|
|
148
|
+
|
|
149
|
+
const recommender = lines[0] || null;
|
|
150
|
+
const recommenderTitle = lines[1] || null;
|
|
151
|
+
const relationship = lines.find(l =>
|
|
152
|
+
/\\b(was |worked |reported |managed |taught |studied )\\b/i.test(l) &&
|
|
153
|
+
l.length < 200
|
|
154
|
+
) || null;
|
|
155
|
+
const date = lines.find(l => /(January|February|March|April|May|June|July|August|September|October|November|December)\\s+\\d{1,2}.*\\d{4}/i.test(l)) || null;
|
|
156
|
+
// Recommendation text is the longest non-meta line
|
|
157
|
+
const text = [...lines].sort((a, b) => b.length - a.length)[0] || '';
|
|
158
|
+
|
|
159
|
+
return { recommender, recommenderTitle, relationship, date, text, _raw: lines };
|
|
160
|
+
}).filter(e => {
|
|
161
|
+
if (!e.recommender || !e.text) return false;
|
|
162
|
+
// Reject "People You May Know" sidebar cards: [title, "View"].
|
|
163
|
+
if (e._raw.length === 2 && e._raw[1] === 'View') return false;
|
|
164
|
+
return true;
|
|
165
|
+
});
|
|
166
|
+
})()`)))}var H,Pe=Ae(()=>{re();H=`
|
|
167
|
+
function findEntryContainer(root) {
|
|
168
|
+
const candidates = [];
|
|
169
|
+
for (const div of root.querySelectorAll('div')) {
|
|
170
|
+
const directDivs = Array.from(div.children).filter(c => c.tagName === 'DIV');
|
|
171
|
+
if (directDivs.length < 2) continue;
|
|
172
|
+
const substantial = directDivs.filter(c => (c.textContent || '').trim().length > 30);
|
|
173
|
+
if (substantial.length < 2) continue;
|
|
174
|
+
if ((div.textContent || '').length < 200) continue;
|
|
175
|
+
|
|
176
|
+
// Reject "People You May Know" suggestion containers: every substantial
|
|
177
|
+
// child is exactly [title, "View"] (a tiny suggestion card with a single
|
|
178
|
+
// "View" CTA). Real section entries always have richer per-child content
|
|
179
|
+
// (multiple text lines per entry).
|
|
180
|
+
const allLookLikePYMK = substantial.every(c => {
|
|
181
|
+
const lines = (c.innerText || '').trim().split('\\n').map(l => l.trim()).filter(Boolean);
|
|
182
|
+
return lines.length === 2 && lines[1] === 'View';
|
|
183
|
+
});
|
|
184
|
+
if (allLookLikePYMK) continue;
|
|
185
|
+
|
|
186
|
+
// Reject LinkedIn footer/legal blocks: when a /details/<section>/ page
|
|
187
|
+
// renders empty, LinkedIn falls back to "Questions? Visit our Help
|
|
188
|
+
// Center", "Select language" (35+ languages), "Recommendation
|
|
189
|
+
// transparency" and similar nav cards inside <main>. These are unique
|
|
190
|
+
// marker strings that never appear inside real section entries.
|
|
191
|
+
const containerText = div.textContent || '';
|
|
192
|
+
const FOOTER_MARKERS = [
|
|
193
|
+
'Visit our Help Center',
|
|
194
|
+
'Select language',
|
|
195
|
+
'Recommendation transparency',
|
|
196
|
+
'Manage your account and privacy',
|
|
197
|
+
'Go to your Settings',
|
|
198
|
+
'Who your viewers also viewed', // "Private to you" PYMK block on empty pages
|
|
199
|
+
'People also viewed',
|
|
200
|
+
'People you may know',
|
|
201
|
+
];
|
|
202
|
+
if (FOOTER_MARKERS.some(m => containerText.includes(m))) continue;
|
|
203
|
+
|
|
204
|
+
candidates.push({ el: div, count: substantial.length, totalText: (div.textContent || '').length });
|
|
205
|
+
}
|
|
206
|
+
// Sort: most children first, then RICHER children (larger totalText) \u2014 real
|
|
207
|
+
// section entries dominate via content density, not just child count. The
|
|
208
|
+
// previous "smaller totalText wins" tie-break gave PYMK sidebars priority
|
|
209
|
+
// over the real Education / Recommendations lists.
|
|
210
|
+
candidates.sort((a, b) => b.count - a.count || b.totalText - a.totalText);
|
|
211
|
+
return candidates[0]?.el;
|
|
212
|
+
}
|
|
213
|
+
`});import"dotenv/config";import Et from"puppeteer";re();import{getPluginConfig as tt}from"@ilivemylife/graph-sdk";var nt=await tt();for(let[t,e]of Object.entries(nt))process.env[t]===void 0&&(process.env[t]=e);var Dt=process.env.LINKEDIN_NAME,T=Object.freeze({DRAFT:"draft",CONFIRMED:"confirmed",REJECTED:"rejected",NEEDS_REVIEW:"needs_review",SENT:"sent"}),Mt=Object.freeze(new Set([T.DRAFT,T.CONFIRMED,T.NEEDS_REVIEW])),Ft=Object.freeze(new Set([T.DRAFT,T.CONFIRMED,T.REJECTED,T.NEEDS_REVIEW]));import"dotenv/config";import*as m from"fs";import*as g from"path";import{fileURLToPath as ot}from"url";var it=ot(import.meta.url),st=g.dirname(g.dirname(it)),A=process.env.DATA_DIR?g.resolve(process.env.DATA_DIR,"collected-profiles"):g.join(st,"collected-profiles"),le=g.join(A,"people.json"),Pt=g.join(A,"jobs.json"),jt=g.join(A,"quota.json"),Ot=g.join(A,"conversations.json"),qt=g.join(A,"sync-state.json"),Bt=g.join(A,"application-questions.json"),ae=g.join(A,"profile-history");var q=null;function Me(){m.existsSync(A)||m.mkdirSync(A,{recursive:!0})}function Fe(t,e){let n=JSON.stringify(e,null,2),o=t+".tmp";m.writeFileSync(o,n);for(let i=0;i<3;i++)try{m.renameSync(o,t);return}catch(s){if(i<2&&(s.code==="EPERM"||s.code==="EBUSY")){let f=Date.now();for(;Date.now()-f<200;);continue}throw s}}function Le(t,e){if(!m.existsSync(t))return null;try{let n=JSON.parse(m.readFileSync(t,"utf-8"));try{m.copyFileSync(t,t+".backup")}catch{}return n}catch(n){console.error(`[!] ${e} is corrupted: ${n.message}`),console.error(` File: ${g.resolve(t)}`);let o=t+".backup";if(m.existsSync(o))try{let i=JSON.parse(m.readFileSync(o,"utf-8"));console.error(` Restored from ${o}`);try{m.copyFileSync(o,t)}catch{}return i}catch{console.error(" Backup also corrupted!")}console.error(` Starting with empty data. Old file preserved as ${t}.corrupted`);try{m.copyFileSync(t,t+".corrupted")}catch{}return null}}function rt(){return new Date().toISOString().split("T")[0]}var lt=["name","title","location","company","connectionDegree","connectionsCount","mutualConnections","photoUrl","hasVerifiedBadge","about","currentCompany","currentSchool","connectionsLevel","mutualConnectionsCount","followers","openToWork","hiring","topSkills","availableSections","experience","featuredLinks","_lastEnrichedAt","featured","education","skillsFull","recommendations","certifications"],at=["name","title","location","currentCompany","currentSchool","connectionDegree","hasVerifiedBadge","openToWork","hiring","about","topSkills"];function ce(t){if(!t)return null;let e=t.match(/\/in\/([^/?#]+)/);return e?e[1].toLowerCase():null}function ct(){m.existsSync(ae)||m.mkdirSync(ae,{recursive:!0})}function Te(t){let e=ce(t);return e?g.join(ae,`${e}.json`):null}function ut(t){let e=Te(t);return e?Le(e,`profile-history/${ce(t)}.json`)||[]:[]}function dt(t,e){let n=Te(t);if(!n)return;ct();let o=ut(t);o.unshift(e);try{Fe(n,o)}catch(i){console.error(`[!] Failed to append profile-history for ${ce(t)}: ${i.message}`)}}function _e(t){return!!(t==null||Array.isArray(t)&&t.length===0||typeof t=="string"&&!t.trim())}function De(t){return Array.isArray(t)?[...t].map(e=>String(e).trim()).sort().join("||"):typeof t=="string"?t.replace(/\s+/g," ").trim():t}function ft(t,e){if(!t)return[];let n=[];for(let o of at){let i=t[o],s=e[o];_e(i)||_e(s)||De(i)!==De(s)&&n.push(o)}return n}function mt(t){let e=new Set(["seenCount","sources","firstSeen","lastSeen","lastUpdated","encounters","jobIds","lastFullVisitAt","lastSnapshotAt","messageSent","connectionStatus","connectionDate","connectionMethod"]),n={};for(let[o,i]of Object.entries(t))e.has(o)||(n[o]=i);return n}function Ne(){return q||(Me(),q=Le(le,"people.json")||{},q)}function pt(t){Me(),q=t;try{Fe(le,t)}catch(e){console.error(`[!] Failed to save people.json: ${e.message}`),console.error(` Path: ${g.resolve(le)}`)}}function ue(t,e={}){if(!t)return null;let n=Ne(),o=rt(),i=new Date().toISOString(),s=n[t];if(s){let f=ft(s,e);f.length>0&&(dt(t,{capturedAt:i,previousLastUpdated:s.lastUpdated||null,changedFields:f,snapshot:mt(s)}),s.lastSnapshotAt=i),s.seenCount=(s.seenCount||1)+1,s.lastSeen=o,s.lastUpdated=i,e.source&&!s.sources?.includes(e.source)&&(s.sources=s.sources||[],s.sources.push(e.source));for(let d of lt)if(e[d]!=null){if(Array.isArray(e[d])&&e[d].length===0&&Array.isArray(s[d])&&s[d].length>0)continue;s[d]=e[d]}Array.isArray(e.availableSections)&&(s.lastFullVisitAt=i)}else n[t]={name:e.name||null,title:e.title||null,location:e.location||null,company:e.company||null,about:e.about||null,connectionDegree:e.connectionDegree||null,connectionsCount:e.connectionsCount||null,mutualConnections:e.mutualConnections||null,photoUrl:e.photoUrl||null,hasVerifiedBadge:e.hasVerifiedBadge||!1,currentCompany:e.currentCompany||null,currentSchool:e.currentSchool||null,connectionsLevel:e.connectionsLevel||null,mutualConnectionsCount:e.mutualConnectionsCount||null,followers:e.followers||null,openToWork:e.openToWork||!1,hiring:e.hiring||!1,topSkills:e.topSkills||null,availableSections:e.availableSections||null,experience:e.experience||null,featuredLinks:e.featuredLinks||null,_lastEnrichedAt:e._lastEnrichedAt||null,featured:e.featured||null,education:e.education||null,skillsFull:e.skillsFull||null,recommendations:e.recommendations||null,certifications:e.certifications||null,firstSeen:o,lastSeen:o,seenCount:1,sources:e.source?[e.source]:[],connectionStatus:null,connectionDate:null,connectionMethod:null,messageSent:null,jobIds:[],lastUpdated:i,lastSnapshotAt:null,lastFullVisitAt:Array.isArray(e.availableSections)?i:null};return pt(n),n[t]}async function kt(t,e){let n=t.url();if(n.includes("/in/"))return!1;if(n.includes("/login")||n.includes("/authwall")||n.includes("/checkpoint"))throw new Error("Session expired \u2014 redirected to login. Run: npm run login");console.log(` Off-track: ${n.slice(0,80)}`),console.log(" Navigating back to profile..."),await t.goto(e,{waitUntil:"domcontentloaded",timeout:6e4}),await w(3e3);let o=t.url();return o.includes("/in/")||console.log(` Recovery failed \u2014 still on: ${o.slice(0,80)}`),!0}async function je(t,e,n={}){let{extractExperience:o=!1,extractFeatured:i=!1,extractEducation:s=!1,extractSkills:f=!1,extractRecommendations:d=!1,extractCertifications:D=!1}=n;try{await t.goto(e,{waitUntil:"domcontentloaded",timeout:6e4}),await w(3e3),await $e(t)&&(console.log(" Dismissed Premium overlay"),await w(1500),await kt(t,e));let a=0;for(let b=0;b<2;b++){let P=await t.evaluate(()=>document.body.scrollHeight);for(let L=1;L<=6;L++)await t.evaluate(C=>window.scrollTo(0,C),P*L/6),await w(900);let I=await t.evaluate(()=>document.body.scrollHeight);if(I===a)break;a=I}await w(800);let S=await t.evaluate(()=>{let b=new Set(["Highlights","About","Activity","Experience","Education","Skills","Recommendations","Languages","Interests","Volunteer experience","Featured","Honors & awards","Honors and awards","Projects","Publications","Patents","Certifications","Licenses & certifications","Courses","Test scores","Organizations"]),P=new Set(["Ad Options","Don\u2019t want to see this","0 notifications","Explore Premium profiles","You might like","People you may know","Suggested for you","More profiles for you","Promoted"]),I=r=>{let l=(r||"").trim().replace(/^[·•]\s*/,"");return/^(1st|2nd|3rd|she\/her|he\/him|they\/them|their\/them)$/i.test(l)},L={name:null,title:null,location:null,currentCompany:null,currentSchool:null,connectionDegree:null,hasVerifiedBadge:!1,photoUrl:null,connectionsLevel:null,mutualConnectionsCount:null,followers:null,openToWork:!1,hiring:!1,about:null,topSkills:null,availableSections:[]},C=document.querySelector("main");if(!C)return L;let oe=[...Array.from(C.querySelectorAll("h1")),...Array.from(C.querySelectorAll("h2"))],c=Array.from(C.querySelectorAll("h2")),k=oe.find(r=>{let l=r.textContent&&r.textContent.trim(),u=(l||"").replace(/\s*\(\d+\)$/,"").trim();return l&&l.length>1&&l.length<100&&!b.has(u)&&!P.has(u)}),j=k?k.textContent.trim():null,x=k?k.parentElement:null;for(;x&&x!==C&&!Array.from(x.children).filter(l=>l.tagName==="P").some(l=>{let u=l.textContent&&l.textContent.trim();return u&&u.length>5&&!I(u)});)x=x.parentElement;let V=null,pe=null,he=null,ie=null;if(x&&x!==C){let r=Array.from(x.children).filter(u=>u.tagName==="P").filter(u=>{let _=u.textContent&&u.textContent.trim();return _&&_.length>5&&!I(_)});if(r[0]&&(V=r[0].textContent.trim()),r[1]){let u=r[1].textContent.trim().split(/\s*[·•]\s*/);pe=u[0]||null,u.length>1&&(he=u.slice(1).join(" \xB7 "))}let l=Array.from(x.children).filter(u=>u.tagName==="DIV");for(let u=l.length-1;u>=0;u--){let _=l[u].textContent&&l[u].textContent.trim();if(_&&!(j&&_.startsWith(j))&&(ie=_.split(/[·•]/)[0].trim(),ie))break}}let we=null;if(x){let r=x.querySelectorAll("p, span, div");for(let l of r){let u=(l.textContent||"").trim().replace(/^[·•]\s*/,"");if(u==="1st"||u==="2nd"||u==="3rd"){we=u;break}}}let Je=!!C.querySelector('svg[data-test-icon="verified"], [aria-label*="Verified" i]'),ge=document.querySelector('main img[width="200"], button img[alt*="photo" i]'),Ke=ge&&ge.src||null,W=C.textContent||"",ye=null,be=W.match(/(\d+\+?)\s+connections\b/i);be&&(ye=be[1]+" connections");let J=null,Se=W.match(/(\d+)\s+mutual connection/i),ke=W.match(/and\s+(\d+)\s+other mutual/i),Ye=W.match(/([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+and\s+([A-Z][\w'-]+(?:\s+[A-Z][\w'-]+)?)\s+are\s+mutual/);Se?J=parseInt(Se[1],10):ke?J=2+parseInt(ke[1],10):Ye&&(J=2);let Ce=null,xe=null,ve=c.find(r=>r.textContent&&r.textContent.trim()==="About");if(ve){let r=ve.parentElement;for(;r&&r.tagName!=="SECTION";)r=r.parentElement;if(r){let l=(r.textContent||"").trim();l=l.replace(/^About\s*/,"").trim();let u=l.match(/Top skills\s*(.+?)$/i);if(u){let se=u[1].split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim().split(/\s*[·•]\s*/).map(Ze=>Ze.trim()).filter(Boolean);se.length>0&&se.length<10&&(xe=se)}l=l.split(/\n?…\s*more/i)[0].trim(),l=l.split(/\n?\.\.\.\s*more/i)[0].trim(),l=l.split(/\bTop skills\b/i)[0].trim(),l=l.split(/\b(?:see (?:more|less)|show (?:more|less))\b/i)[0].trim(),Ce=l||null}}let Ee=null,Ie=c.find(r=>r.textContent&&r.textContent.trim()==="Activity");if(Ie){let r=Ie.parentElement;for(;r&&r.tagName!=="SECTION";)r=r.parentElement;if(r){let l=(r.textContent||"").slice(0,200).match(/([\d,]+)\s+followers/i);l&&(Ee=parseInt(l[1].replace(/,/g,""),10))}}let Qe=[...new Set(c.map(r=>(r.textContent||"").trim().replace(/\s*\(\d+\)$/,"").trim()).filter(r=>r&&r.length>1&&r.length<60&&r!==j).filter(r=>b.has(r)))],O=document.body.textContent||"",ze=/#OpenToWork\b/i.test(O)||/\bOpen to work\b/.test(O),Ge=/#Hiring\b/i.test(O)||/\bI'?m hiring\b/i.test(O)||/\bWe are hiring\b/i.test(O);return{name:j,title:V,location:ie,currentCompany:pe,currentSchool:he,connectionDegree:we,hasVerifiedBadge:Je,photoUrl:Ke,connectionsLevel:ye,mutualConnectionsCount:J,followers:Ee,openToWork:ze,hiring:Ge,about:Ce,topSkills:xe,availableSections:Qe}});console.log(`Viewed: ${S.name} - ${S.title}`);let p=null,h=null,y=null,v=null,M=null,F=null;if(o||i||s||f||d||D){let b=await Promise.resolve().then(()=>(Pe(),Re));o&&(p=await b.extractExperienceFromDetails(t,e),console.log(` + Experience: ${p.length} entries`)),i&&(h=await b.extractFeaturedFromDetails(t,e),console.log(` + Featured: ${h.length} entries`)),s&&(y=await b.extractEducationFromDetails(t,e),console.log(` + Education: ${y.length} entries`)),f&&(v=await b.extractSkillsFromDetails(t,e),console.log(` + Skills: ${v.length} entries`)),d&&(M=await b.extractRecommendationsFromDetails(t,e),console.log(` + Recommendations: ${M.length} entries`)),D&&(F=await b.extractCertificationsFromDetails(t,e),console.log(` + Certifications: ${F.length} entries`))}return{...S,profileUrl:e,...p!==null&&{experience:p},...h!==null&&{featured:h},...y!==null&&{education:y},...v!==null&&{skillsFull:v},...M!==null&&{recommendations:M},...F!==null&&{certifications:F}}}catch($){console.error(`Error viewing profile ${e}:`,$.message);try{await t.goto("about:blank",{timeout:1e4}),await w(1e3)}catch{}if(/session expired|bounced to|authwall|checkpoint|redirected to login/i.test($.message||""))throw $;return null}}import Oe from"fs";import Ct from"path";var xt="cookies.json";function vt(){let t=process.env.ILML_SCOPE_DIR;return t?Ct.join(t,"plugins-state","linkedin","cookies.json"):xt}function qe(){let t=vt();if(!Oe.existsSync(t))throw new Error(`Cookies not found at ${t}. Run: ilml linkedin login`);let e;try{e=Oe.readFileSync(t,"utf-8")}catch(o){throw new Error(`Failed to read cookies at ${t}: ${o.message}. Run: ilml linkedin login`)}let n;try{n=JSON.parse(e)}catch{throw new Error(`Cookies file at ${t} is corrupted (invalid JSON). Run: ilml linkedin login`)}if(!Array.isArray(n)||n.length===0)throw new Error(`Cookies file at ${t} is empty or not an array. Run: ilml linkedin login`);return n}function Be(t){return t?t.replace(/^https?:\/\/(www\.|m\.)?linkedin\.com/i,"https://linkedin.com").split("?")[0].split("#")[0].replace(/\/+$/,"").toLowerCase():""}function He(t){return(t||"").replace(/ /g," ").replace(/\s+/g," ").trim().toLowerCase()}var E=process.argv.slice(2),It=E.includes("--help")||E.includes("-h"),N=E.find(t=>t.startsWith("http")),R=E.includes("--full"),Y=R||E.includes("--with-experience"),Q=R||E.includes("--with-featured"),z=R||E.includes("--with-education"),G=R||E.includes("--with-skills"),Z=R||E.includes("--with-recommendations"),X=R||E.includes("--with-certifications"),Ue=[["experience",Y],["featured",Q],["education",z],["skills",G],["recommendations",Z],["certifications",X]],Ve=Ue.filter(([,t])=>t).length,fe=1+Ve;function We(){console.log(`
|
|
5
214
|
enrich-profile \u2014 visit ONE LinkedIn profile and save what we learn
|
|
6
215
|
|
|
7
216
|
USAGE
|
|
8
|
-
ilml linkedin enrich-profile <profile-url> [--with
|
|
9
|
-
node enrichProfile.mjs <profile-url> [--with
|
|
217
|
+
ilml linkedin enrich-profile <profile-url> [--full | --with-...]
|
|
218
|
+
node enrichProfile.mjs <profile-url> [--full | --with-...] # dev
|
|
10
219
|
|
|
11
220
|
ARGUMENTS
|
|
12
221
|
<profile-url> Required. Full LinkedIn profile URL.
|
|
13
222
|
Example: https://www.linkedin.com/in/<slug>/
|
|
14
223
|
|
|
15
224
|
FLAGS
|
|
16
|
-
--
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
225
|
+
--full Shortcut: enables all --with-* flags. Up to 7 page
|
|
226
|
+
loads (main + Experience + Featured + Education +
|
|
227
|
+
Skills + Recommendations + Certifications). Missing
|
|
228
|
+
sections are skipped automatically (smart-skip), so
|
|
229
|
+
most real profiles cost 3\u20136 loads in practice.
|
|
230
|
+
Recommended for own-profile audit and on-demand
|
|
231
|
+
deep-dive on one contact.
|
|
232
|
+
|
|
233
|
+
--with-experience Adds /details/experience/ \u2192 structured experience[]
|
|
234
|
+
(title, company, dates, location, description, skills).
|
|
235
|
+
--with-featured Adds /details/featured/ \u2192 pinned items (title, caption, url).
|
|
236
|
+
--with-education Adds /details/education/ \u2192 schools, degrees, dates.
|
|
237
|
+
--with-skills Adds /details/skills/ \u2192 full skill list with endorsements.
|
|
238
|
+
--with-recommendations Adds /details/recommendations/ \u2192 received recommendations.
|
|
239
|
+
--with-certifications Adds /details/certifications/ \u2192 licenses & certifications.
|
|
240
|
+
|
|
241
|
+
Each --with-* adds ONE extra navigation = ONE extra page load. Mix and
|
|
242
|
+
match for cheaper partial enrichment.
|
|
243
|
+
|
|
21
244
|
--help, -h Print this help and exit.
|
|
22
245
|
|
|
23
246
|
BEHAVIOUR
|
|
24
247
|
- Saves to people.json via upsertPerson() \u2014 additive merge, never deletes data.
|
|
25
248
|
- Self-profile detected via MY_LINKEDIN_URL or LINKEDIN_NAME \u2192 printed to
|
|
26
249
|
stdout instead of saved (keeps own profile out of the contacts DB).
|
|
27
|
-
- Refuses to run if NEITHER MY_LINKEDIN_URL nor LINKEDIN_NAME is set
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
250
|
+
- Refuses to run if NEITHER MY_LINKEDIN_URL nor LINKEDIN_NAME is set.
|
|
251
|
+
- Any --with-* section that returns 0 entries (DOM change / auth blip)
|
|
252
|
+
preserves the existing stored value \u2014 never wiped.
|
|
253
|
+
- _lastEnrichedAt is set only when at least one rich section returned data.
|
|
31
254
|
|
|
32
255
|
BAN RISK
|
|
33
|
-
Low. One profile = 1
|
|
34
|
-
|
|
35
|
-
|
|
256
|
+
Low. One profile = 1 to 7 page loads depending on flags, all targeting the
|
|
257
|
+
same profile = normal "deep read" human behavior. Intentionally no batch
|
|
258
|
+
mode here. For gated batch enrichment use 'enrich-profiles --with-experience'.
|
|
36
259
|
|
|
37
260
|
WHEN TO USE
|
|
38
|
-
- Audit your own LinkedIn profile (prints to stdout)
|
|
261
|
+
- Audit your own LinkedIn profile (--full prints everything to stdout)
|
|
39
262
|
- Deep-dive on one specific contact before reaching out
|
|
40
263
|
- Verify what we know about a recruiter / lead
|
|
41
|
-
`)}
|
|
264
|
+
`)}It&&(We(),process.exit(0));N||(We(),process.exit(1));/linkedin\.com\/in\//i.test(N)||(console.error(`URL doesn't look like a LinkedIn profile: ${N}`),console.error("Expected format: https://www.linkedin.com/in/<slug>/"),process.exit(1));var me=Be(process.env.MY_LINKEDIN_URL||""),te=He(process.env.LINKEDIN_NAME||"");!me&&!te&&(console.error(""),console.error(" \u26D4 Refusing to run: cannot self-detect without configuration."),console.error(""),console.error(" Set EITHER (preferably both) of:"),console.error(" MY_LINKEDIN_URL=https://www.linkedin.com/in/<your-slug>"),console.error(' LINKEDIN_NAME="Your Full Name"'),console.error(""),console.error(" in .env (dev) or via `ilml plugin config linkedin set <KEY> <VALUE>` (prod)."),console.error(" This prevents your own profile from accidentally landing in people.json."),console.error(""),process.exit(1));var ee=me&&Be(N)===me,de=Ue.filter(([,t])=>t).map(([t])=>t);console.log("");console.log(` enrichProfile \u2014 ${N}`);R?console.log(` Mode: --full (${fe} page loads: main + ${de.join(" + ")})`):de.length>0?console.log(` Mode: rich (${fe} loads: main + ${de.join(" + ")})`):console.log(" Mode: basic (1 load \u2014 main page only)");console.log(ee?" Target: SELF (URL match) \u2014 will print to stdout, not saved to people.json":te?` Target: TBD \u2014 name-match against "${process.env.LINKEDIN_NAME}" after fetch`:" Target: will save to people.json (no MY_LINKEDIN_URL or LINKEDIN_NAME set for self-check)");Ve>0&&(console.log(""),console.log(` \u26A0 ${fe} page loads on the SAME profile = normal "deep read" pattern.`),console.log(" This is intentionally single-URL \u2014 DO NOT batch. For batch enrichment"),console.log(" use `enrichProfiles.mjs --with-experience` (gated, capped)."));console.log("");var K=null;try{K=await Et.launch({headless:!1,defaultViewport:null,protocolTimeout:3e5});let t=await K.newPage();await t.setCookie(...qe());let e=await je(t,N,{extractExperience:Y,extractFeatured:Q,extractEducation:z,extractSkills:G,extractRecommendations:Z,extractCertifications:X});if((!e||!e.name)&&(console.error(" viewProfile returned no name \u2014 profile not loaded or DOM changed"),process.exit(1)),!ee&&te&&e.name&&He(e.name)===te&&(ee=!0,console.log(" \u2191 Detected self via LINKEDIN_NAME match \u2014 will NOT save to people.json")),console.log(""),console.log(" \u2500\u2500\u2500 extracted \u2500\u2500\u2500"),console.log(` name: ${e.name}`),console.log(` title: ${e.title||"(none)"}`),console.log(` location: ${e.location||"(none)"}`),console.log(` about: ${e.about?`${e.about.length} chars`:"(none)"}`),console.log(` topSkills: ${e.topSkills?e.topSkills.join(", "):"(none)"}`),Y&&console.log(` experience: ${(e.experience||[]).length} entries`),Q&&console.log(` featured: ${(e.featured||[]).length} entries`),z&&console.log(` education: ${(e.education||[]).length} entries`),G&&console.log(` skillsFull: ${(e.skillsFull||[]).length} entries`),Z&&console.log(` recommendations: ${(e.recommendations||[]).length} entries`),X&&console.log(` certifications: ${(e.certifications||[]).length} entries`),console.log(""),ee)console.log(" \u2500\u2500\u2500 full data (self \u2014 not persisted) \u2500\u2500\u2500"),console.log(JSON.stringify(e,null,2));else{let n={name:e.name,title:e.title,location:e.location,about:e.about,currentCompany:e.currentCompany,currentSchool:e.currentSchool,topSkills:e.topSkills,availableSections:e.availableSections,connectionsLevel:e.connectionsLevel,mutualConnectionsCount:e.mutualConnectionsCount,followers:e.followers,openToWork:e.openToWork,hiring:e.hiring,hasVerifiedBadge:e.hasVerifiedBadge,photoUrl:e.photoUrl,source:"enrich-profile-single"},o=[["experience",Y,e.experience],["featured",Q,e.featured],["education",z,e.education],["skillsFull",G,e.skillsFull],["recommendations",Z,e.recommendations],["certifications",X,e.certifications]],i=!1;for(let[s,f,d]of o)f&&(Array.isArray(d)&&d.length>0?(n[s]=d,i=!0):console.log(` \u26A0 --with-${s==="skillsFull"?"skills":s} returned 0 entries \u2014 NOT writing ${s} (existing data preserved)`));i&&(n._lastEnrichedAt=new Date().toISOString()),ue(N,n),console.log(" \u2713 Saved to people.json")}}catch(t){console.error(" Error:",t.message),process.exit(1)}finally{K&&await K.close().catch(()=>{})}
|