@rent-scraper/utils 1.0.14 → 1.0.15-beta.2

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/dist/config.d.mts CHANGED
@@ -9,24 +9,28 @@ interface ScrapeConfig {
9
9
  browser?: BrowserKey;
10
10
  zillowCookie?: string;
11
11
  }
12
+ declare const pointerFilePath: string;
12
13
  declare const globalDir: string;
13
- declare const getConfigFilePath: (source: ListingsSource) => Promise<string>;
14
- declare const checkForConfigFile: (source: ListingsSource) => Promise<boolean | undefined>;
15
- declare const checkForAndReadConfigFile: (source: ListingsSource) => Promise<ScrapeConfig>;
14
+ declare const getConfigFilePath: (source: ListingsSource) => Promise<any>;
15
+ declare const checkForConfigFile: (source: ListingsSource, configFilePath?: string) => Promise<boolean | undefined>;
16
+ declare const checkForPointerFile: () => Promise<boolean | undefined>;
17
+ declare const checkForAndReadConfigFile: (source: ListingsSource) => Promise<ScrapeConfig | undefined>;
16
18
  declare const resetZillowCookie: () => Promise<void>;
17
19
  declare const waitForConfigFile: (source: ListingsSource) => Promise<unknown>;
18
20
  declare const waitForBrowserServer: () => Promise<unknown>;
19
21
  declare const checkBrowserServer: () => Promise<any>;
20
22
  declare const waitForZillowCookie: () => Promise<unknown>;
21
23
  declare const checkForZillowCookie: () => Promise<string | number | Record<number, number | null> | null | undefined>;
22
- declare const checkRequiredConfigValues: (source: ListingsSource, config: ScrapeConfig, task?: string) => string[];
24
+ declare const checkRequiredConfigValues: (source: ListingsSource, config?: ScrapeConfig, task?: string) => string[];
23
25
  declare const getZipCodesFromConfig: (source: ListingsSource) => Promise<number[]>;
24
26
  declare const stringifyZipCodes: (zipCodes: number[]) => string;
25
- declare const readConfigFile: (source: ListingsSource) => Promise<ScrapeConfig>;
27
+ declare const readConfigFile: (source: ListingsSource) => Promise<ScrapeConfig | undefined>;
28
+ declare const writePointerFile: (source: ListingsSource, configDirectory: string, filename?: string) => Promise<any>;
29
+ declare const readPointerFile: (source: ListingsSource) => Promise<any>;
26
30
  declare const getOutputPathFromConfig: (source: ListingsSource) => Promise<string>;
27
31
  declare const getValueFromConfigFile: (source: ListingsSource, key: keyof ScrapeConfig) => Promise<ScrapeConfig[keyof ScrapeConfig] | null>;
28
32
  declare const updateConfigFile: (source: ListingsSource, payload: any) => Promise<void>;
29
- declare const writeConfigFile: (source: ListingsSource, config: ScrapeConfig) => Promise<void>;
33
+ declare const writeConfigFile: (source: ListingsSource, config: ScrapeConfig) => Promise<any>;
30
34
 
31
- export { checkBrowserServer, checkForAndReadConfigFile, checkForConfigFile, checkForZillowCookie, checkRequiredConfigValues, getConfigFilePath, getOutputPathFromConfig, getValueFromConfigFile, getZipCodesFromConfig, globalDir, readConfigFile, resetZillowCookie, stringifyZipCodes, updateConfigFile, waitForBrowserServer, waitForConfigFile, waitForZillowCookie, writeConfigFile };
35
+ export { checkBrowserServer, checkForAndReadConfigFile, checkForConfigFile, checkForPointerFile, checkForZillowCookie, checkRequiredConfigValues, getConfigFilePath, getOutputPathFromConfig, getValueFromConfigFile, getZipCodesFromConfig, globalDir, pointerFilePath, readConfigFile, readPointerFile, resetZillowCookie, stringifyZipCodes, updateConfigFile, waitForBrowserServer, waitForConfigFile, waitForZillowCookie, writeConfigFile, writePointerFile };
32
36
  export type { ScrapeConfig };
package/dist/config.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import{checkForFile as I,parseYamlFile as k,throwError as g,writeYamlFile as M}from"@rent-scraper/utils";import S from"fs";import p from"path";import b from"util";import H from"axios";import{spinner as Q,log as G}from"@clack/prompts";import{mkdir as Z}from"fs/promises";import J from"os";var w={},h={},C={},T;function X(){return T||(T=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.USEFUL_NON_ROOT_PNPM_FIELDS=e.FULL_FILTERED_META_DIR=e.FULL_META_DIR=e.ABBREVIATED_META_DIR=e.WORKSPACE_MANIFEST_FILENAME=e.STORE_VERSION=e.LAYOUT_VERSION=e.ENGINE_NAME=e.MANIFEST_BASE_NAMES=e.LOCKFILE_VERSION=e.LOCKFILE_MAJOR_VERSION=e.WANTED_LOCKFILE=void 0,e.getNodeBinLocationForCurrentOS=t,e.getDenoBinLocationForCurrentOS=i,e.getBunBinLocationForCurrentOS=n,e.WANTED_LOCKFILE="pnpm-lock.yaml",e.LOCKFILE_MAJOR_VERSION="9",e.LOCKFILE_VERSION=`${e.LOCKFILE_MAJOR_VERSION}.0`,e.MANIFEST_BASE_NAMES=["package.json","package.json5","package.yaml"],e.ENGINE_NAME=`${process.platform};${process.arch};node${process.version.split(".")[0].substring(1)}`,e.LAYOUT_VERSION=5,e.STORE_VERSION="v10",e.WORKSPACE_MANIFEST_FILENAME="pnpm-workspace.yaml",e.ABBREVIATED_META_DIR="metadata-v1.3",e.FULL_META_DIR="metadata-full-v1.3",e.FULL_FILTERED_META_DIR="metadata-v1.3",e.USEFUL_NON_ROOT_PNPM_FIELDS=["executionEnv"];function t(c=process.platform){return c==="win32"?"node.exe":"bin/node"}function i(c=process.platform){return c==="win32"?"deno.exe":"deno"}function n(c=process.platform){return c==="win32"?"bun.exe":"bun"}})(C)),C}var D;function ee(){if(D)return h;D=1,Object.defineProperty(h,"__esModule",{value:!0}),h.LockfileMissingDependencyError=h.FetchError=h.PnpmError=void 0;const e=X();class t extends Error{code;hint;attempts;prefix;pkgsStack;constructor(s,r,f){super(r),this.code=s.startsWith("ERR_PNPM_")?s:`ERR_PNPM_${s}`,this.hint=f?.hint,this.attempts=f?.attempts}}h.PnpmError=t;class i extends t{response;request;constructor(s,r,f){const l={url:s.url};s.authHeaderValue&&(l.authHeaderValue=n(s.authHeaderValue));const a=`GET ${s.url}: ${r.statusText} - ${r.status}`;(r.status===401||r.status===403||r.status===404)&&(f=f?`${f}
1
+ import{checkForFile as P,parseYamlFile as _,throwError as m,writeYamlFile as b}from"@rent-scraper/utils";import G from"axios";import S from"fs";import h from"path";import D from"util";import{spinner as Z,log as J}from"@clack/prompts";import{stat as X,mkdir as C}from"fs/promises";import ee from"os";import te from"env-paths";var y={},p={},N={},T;function re(){return T||(T=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.USEFUL_NON_ROOT_PNPM_FIELDS=e.FULL_FILTERED_META_DIR=e.FULL_META_DIR=e.ABBREVIATED_META_DIR=e.WORKSPACE_MANIFEST_FILENAME=e.STORE_VERSION=e.LAYOUT_VERSION=e.ENGINE_NAME=e.MANIFEST_BASE_NAMES=e.LOCKFILE_VERSION=e.LOCKFILE_MAJOR_VERSION=e.WANTED_LOCKFILE=void 0,e.getNodeBinLocationForCurrentOS=t,e.getDenoBinLocationForCurrentOS=r,e.getBunBinLocationForCurrentOS=n,e.WANTED_LOCKFILE="pnpm-lock.yaml",e.LOCKFILE_MAJOR_VERSION="9",e.LOCKFILE_VERSION=`${e.LOCKFILE_MAJOR_VERSION}.0`,e.MANIFEST_BASE_NAMES=["package.json","package.json5","package.yaml"],e.ENGINE_NAME=`${process.platform};${process.arch};node${process.version.split(".")[0].substring(1)}`,e.LAYOUT_VERSION=5,e.STORE_VERSION="v10",e.WORKSPACE_MANIFEST_FILENAME="pnpm-workspace.yaml",e.ABBREVIATED_META_DIR="metadata-v1.3",e.FULL_META_DIR="metadata-full-v1.3",e.FULL_FILTERED_META_DIR="metadata-v1.3",e.USEFUL_NON_ROOT_PNPM_FIELDS=["executionEnv"];function t(c=process.platform){return c==="win32"?"node.exe":"bin/node"}function r(c=process.platform){return c==="win32"?"deno.exe":"deno"}function n(c=process.platform){return c==="win32"?"bun.exe":"bun"}})(N)),N}var $;function ne(){if($)return p;$=1,Object.defineProperty(p,"__esModule",{value:!0}),p.LockfileMissingDependencyError=p.FetchError=p.PnpmError=void 0;const e=re();class t extends Error{code;hint;attempts;prefix;pkgsStack;constructor(a,i,f){super(i),this.code=a.startsWith("ERR_PNPM_")?a:`ERR_PNPM_${a}`,this.hint=f?.hint,this.attempts=f?.attempts}}p.PnpmError=t;class r extends t{response;request;constructor(a,i,f){const l={url:a.url};a.authHeaderValue&&(l.authHeaderValue=n(a.authHeaderValue));const s=`GET ${a.url}: ${i.statusText} - ${i.status}`;(i.status===401||i.status===403||i.status===404)&&(f=f?`${f}
2
2
 
3
- `:"",l.authHeaderValue?f+=`An authorization header was used: ${l.authHeaderValue}`:f+="No authorization header was set for the request."),super(`FETCH_${r.status}`,a,{hint:f}),this.request=l,this.response=r}}h.FetchError=i;function n(u){const[s,r]=u.split(" ");return r==null?"[hidden]":r.length<20?`${s} [hidden]`:`${s} ${r.substring(0,4)}[hidden]`}class c extends t{constructor(s){const r=`Broken lockfile: no entry for '${s}' in ${e.WANTED_LOCKFILE}`;super("LOCKFILE_MISSING_DEPENDENCY",r,{hint:`This issue is probably caused by a badly resolved merge conflict.
4
- To fix the lockfile, run 'pnpm install --no-frozen-lockfile'.`})}}return h.LockfileMissingDependencyError=c,h}var N={exports:{}},y={exports:{}},P,q;function te(){if(q)return P;q=1;class e{constructor(n){this.value=n,this.next=void 0}}class t{constructor(){this.clear()}enqueue(n){const c=new e(n);this._head?(this._tail.next=c,this._tail=c):(this._head=c,this._tail=c),this._size++}dequeue(){const n=this._head;if(n)return this._head=this._head.next,this._size--,n.value}clear(){this._head=void 0,this._tail=void 0,this._size=0}get size(){return this._size}*[Symbol.iterator](){let n=this._head;for(;n;)yield n.value,n=n.next}}return P=t,P}var R,$;function re(){if($)return R;$=1;const e=te();return R=i=>{if(!((Number.isInteger(i)||i===1/0)&&i>0))throw new TypeError("Expected `concurrency` to be a number from 1 and up");const n=new e;let c=0;const u=()=>{c--,n.size>0&&n.dequeue()()},s=async(l,a,...o)=>{c++;const d=(async()=>l(...o))();a(d);try{await d}catch{}u()},r=(l,a,...o)=>{n.enqueue(s.bind(null,l,a,...o)),(async()=>(await Promise.resolve(),c<i&&n.size>0&&n.dequeue()()))()},f=(l,...a)=>new Promise(o=>{r(l,o,...a)});return Object.defineProperties(f,{activeCount:{get:()=>c},pendingCount:{get:()=>n.size},clearQueue:{value:()=>{n.clear()}}}),f},R}var A,z;function ne(){if(z)return A;z=1;const e=re();class t extends Error{constructor(s){super(),this.value=s}}const i=async(u,s)=>s(await u),n=async u=>{const s=await Promise.all(u);if(s[1]===!0)throw new t(s[0]);return!1};return A=async(u,s,r)=>{r={concurrency:1/0,preserveOrder:!0,...r};const f=e(r.concurrency),l=[...u].map(o=>[o,f(i,o,s)]),a=e(r.preserveOrder?1:1/0);try{await Promise.all(l.map(o=>a(n,o)))}catch(o){if(o instanceof t)return o.value;throw o}},A}var V;function ie(){if(V)return y.exports;V=1;const e=p,t=S,{promisify:i}=b,n=ne(),c=i(t.stat),u=i(t.lstat),s={directory:"isDirectory",file:"isFile"};function r({type:l}){if(!(l in s))throw new Error(`Invalid type specified: ${l}`)}const f=(l,a)=>l===void 0||a[s[l]]();return y.exports=async(l,a)=>{a={cwd:process.cwd(),type:"file",allowSymlinks:!0,...a},r(a);const o=a.allowSymlinks?c:u;return n(l,async d=>{try{const E=await o(e.resolve(a.cwd,d));return f(a.type,E)}catch{return!1}},a)},y.exports.sync=(l,a)=>{a={cwd:process.cwd(),allowSymlinks:!0,type:"file",...a},r(a);const o=a.allowSymlinks?t.statSync:t.lstatSync;for(const d of l)try{const E=o(e.resolve(a.cwd,d));if(f(a.type,E))return d}catch{}},y.exports}var m={exports:{}},B;function ae(){if(B)return m.exports;B=1;const e=S,{promisify:t}=b,i=t(e.access);return m.exports=async n=>{try{return await i(n),!0}catch{return!1}},m.exports.sync=n=>{try{return e.accessSync(n),!0}catch{return!1}},m.exports}var K;function se(){return K||(K=1,(function(e){const t=p,i=ie(),n=ae(),c=Symbol("findUp.stop");e.exports=async(u,s={})=>{let r=t.resolve(s.cwd||"");const{root:f}=t.parse(r),l=[].concat(u),a=async o=>{if(typeof u!="function")return i(l,o);const d=await u(o.cwd);return typeof d=="string"?i([d],o):d};for(;;){const o=await a({...s,cwd:r});if(o===c)return;if(o)return t.resolve(r,o);if(r===f)return;r=t.dirname(r)}},e.exports.sync=(u,s={})=>{let r=t.resolve(s.cwd||"");const{root:f}=t.parse(r),l=[].concat(u),a=o=>{if(typeof u!="function")return i.sync(l,o);const d=u(o.cwd);return typeof d=="string"?i.sync([d],o):d};for(;;){const o=a({...s,cwd:r});if(o===c)return;if(o)return t.resolve(r,o);if(r===f)return;r=t.dirname(r)}},e.exports.exists=n,e.exports.sync.exists=n.sync,e.exports.stop=c})(N)),N.exports}var W;function oe(){if(W)return w;W=1;var e=w&&w.__importDefault||function(a){return a&&a.__esModule?a:{default:a}};Object.defineProperty(w,"__esModule",{value:!0}),w.findWorkspaceDir=f;const t=e(S),i=e(p),n=ee(),c=e(se()),u="NPM_CONFIG_WORKSPACE_DIR",s="pnpm-workspace.yaml",r=["pnpm-workspaces.yaml","pnpm-workspaces.yml","pnpm-workspace.yml"];async function f(a){const o=process.env[u]??process.env[u.toLowerCase()],d=o?i.default.join(o,s):await(0,c.default)([s,...r],{cwd:await l(a)});if(d&&i.default.basename(d)!==s)throw new n.PnpmError("BAD_WORKSPACE_MANIFEST_NAME",`The workspace manifest file should be named "pnpm-workspace.yaml". File found: ${d}`);return d&&i.default.dirname(d)}async function l(a){return new Promise(o=>{t.default.realpath.native(a,function(d,E){o(d!==null?a:E)})})}return w}var j=oe();const _=p.join(J.homedir(),"rent-scraper"),L=async e=>{const t=await j.findWorkspaceDir(process.cwd());t||await I(_)||await Z(_,{recursive:!0});const i=t??_;return e==="redfin"?p.join(i,"config.redfin.yaml"):p.join(i,"config.zillow.yaml")},x=async e=>{const t=await L(e);return await I(t)},ce=async e=>{const t=await L(e);return await I(t)||g("Config file is required."),await k(t)},ue=async()=>{const{zillowCookie:e,...t}=await v("zillow");await O("zillow",t)},le=async e=>{try{return await new Promise(t=>{const i=setInterval(async()=>{const n=await x(e);n&&(t(n),clearInterval(i))},1e3)})}catch(t){g(t?.message)}},fe=async()=>{try{return await new Promise((e,t)=>{const i=Q();i.start("Waiting for browser server");let n=0;const c=setInterval(async()=>{n++,n>10&&t(new Error("browser server is not running."));const u=await U();u&&(i.stop("Browser server is connected!"),e(u),clearInterval(c))},1e3)})}catch(e){g(e?.message)}},U=async()=>{try{const{data:e}=await H.get("http://localhost:8082/server");return e.running}catch{return!1}},de=async()=>await new Promise(e=>{const t=setInterval(async()=>{const i=await Y();i&&(e(i),clearInterval(t))},1e3)}),Y=async()=>await F("zillow","zillowCookie"),he=(e,t,i="init")=>{const{outputPath:n,zipCodes:c,browser:u,zillowCookie:s}=t??{},r=[];return n||r.push("outputPath"),c||r.push("zipCodes"),e==="zillow"&&!u&&r.push("browser"),i==="scrape"&&e==="zillow"&&!s&&r.push("zillowCookie"),r},pe=async e=>(await F(e,"zipCodes"))?.replace(/ /g,"").split(",").map(t=>Number(t)),we=e=>e.join(", "),v=async e=>{const t=await L(e);return await k(t)},Ee=async e=>await F(e,"outputPath"),F=async(e,t)=>(await v(e))?.[t]??null,_e=async(e,t)=>{const i=await v(e),n=Object.keys(t),c={...i,...t};await O(e,c),G.success(`Updated ${e} config: ${n.join(", ")}`)},O=async(e,t)=>{const i=await j.findWorkspaceDir(process.cwd())??_;return e==="redfin"?await M(p.join(i,"config.redfin.yaml"),t):await M(p.join(i,"config.zillow.yaml"),t)};export{U as checkBrowserServer,ce as checkForAndReadConfigFile,x as checkForConfigFile,Y as checkForZillowCookie,he as checkRequiredConfigValues,L as getConfigFilePath,Ee as getOutputPathFromConfig,F as getValueFromConfigFile,pe as getZipCodesFromConfig,_ as globalDir,v as readConfigFile,ue as resetZillowCookie,we as stringifyZipCodes,_e as updateConfigFile,fe as waitForBrowserServer,le as waitForConfigFile,de as waitForZillowCookie,O as writeConfigFile};
3
+ `:"",l.authHeaderValue?f+=`An authorization header was used: ${l.authHeaderValue}`:f+="No authorization header was set for the request."),super(`FETCH_${i.status}`,s,{hint:f}),this.request=l,this.response=i}}p.FetchError=r;function n(u){const[a,i]=u.split(" ");return i==null?"[hidden]":i.length<20?`${a} [hidden]`:`${a} ${i.substring(0,4)}[hidden]`}class c extends t{constructor(a){const i=`Broken lockfile: no entry for '${a}' in ${e.WANTED_LOCKFILE}`;super("LOCKFILE_MISSING_DEPENDENCY",i,{hint:`This issue is probably caused by a badly resolved merge conflict.
4
+ To fix the lockfile, run 'pnpm install --no-frozen-lockfile'.`})}}return p.LockfileMissingDependencyError=c,p}var R={exports:{}},L={exports:{}},A,q;function ie(){if(q)return A;q=1;class e{constructor(n){this.value=n,this.next=void 0}}class t{constructor(){this.clear()}enqueue(n){const c=new e(n);this._head?(this._tail.next=c,this._tail=c):(this._head=c,this._tail=c),this._size++}dequeue(){const n=this._head;if(n)return this._head=this._head.next,this._size--,n.value}clear(){this._head=void 0,this._tail=void 0,this._size=0}get size(){return this._size}*[Symbol.iterator](){let n=this._head;for(;n;)yield n.value,n=n.next}}return A=t,A}var O,z;function ae(){if(z)return O;z=1;const e=ie();return O=r=>{if(!((Number.isInteger(r)||r===1/0)&&r>0))throw new TypeError("Expected `concurrency` to be a number from 1 and up");const n=new e;let c=0;const u=()=>{c--,n.size>0&&n.dequeue()()},a=async(l,s,...o)=>{c++;const d=(async()=>l(...o))();s(d);try{await d}catch{}u()},i=(l,s,...o)=>{n.enqueue(a.bind(null,l,s,...o)),(async()=>(await Promise.resolve(),c<r&&n.size>0&&n.dequeue()()))()},f=(l,...s)=>new Promise(o=>{i(l,o,...s)});return Object.defineProperties(f,{activeCount:{get:()=>c},pendingCount:{get:()=>n.size},clearQueue:{value:()=>{n.clear()}}}),f},O}var k,V;function se(){if(V)return k;V=1;const e=ae();class t extends Error{constructor(a){super(),this.value=a}}const r=async(u,a)=>a(await u),n=async u=>{const a=await Promise.all(u);if(a[1]===!0)throw new t(a[0]);return!1};return k=async(u,a,i)=>{i={concurrency:1/0,preserveOrder:!0,...i};const f=e(i.concurrency),l=[...u].map(o=>[o,f(r,o,a)]),s=e(i.preserveOrder?1:1/0);try{await Promise.all(l.map(o=>s(n,o)))}catch(o){if(o instanceof t)return o.value;throw o}},k}var B;function oe(){if(B)return L.exports;B=1;const e=h,t=S,{promisify:r}=D,n=se(),c=r(t.stat),u=r(t.lstat),a={directory:"isDirectory",file:"isFile"};function i({type:l}){if(!(l in a))throw new Error(`Invalid type specified: ${l}`)}const f=(l,s)=>l===void 0||s[a[l]]();return L.exports=async(l,s)=>{s={cwd:process.cwd(),type:"file",allowSymlinks:!0,...s},i(s);const o=s.allowSymlinks?c:u;return n(l,async d=>{try{const E=await o(e.resolve(s.cwd,d));return f(s.type,E)}catch{return!1}},s)},L.exports.sync=(l,s)=>{s={cwd:process.cwd(),allowSymlinks:!0,type:"file",...s},i(s);const o=s.allowSymlinks?t.statSync:t.lstatSync;for(const d of l)try{const E=o(e.resolve(s.cwd,d));if(f(s.type,E))return d}catch{}},L.exports}var v={exports:{}},x;function ce(){if(x)return v.exports;x=1;const e=S,{promisify:t}=D,r=t(e.access);return v.exports=async n=>{try{return await r(n),!0}catch{return!1}},v.exports.sync=n=>{try{return e.accessSync(n),!0}catch{return!1}},v.exports}var K;function ue(){return K||(K=1,(function(e){const t=h,r=oe(),n=ce(),c=Symbol("findUp.stop");e.exports=async(u,a={})=>{let i=t.resolve(a.cwd||"");const{root:f}=t.parse(i),l=[].concat(u),s=async o=>{if(typeof u!="function")return r(l,o);const d=await u(o.cwd);return typeof d=="string"?r([d],o):d};for(;;){const o=await s({...a,cwd:i});if(o===c)return;if(o)return t.resolve(i,o);if(i===f)return;i=t.dirname(i)}},e.exports.sync=(u,a={})=>{let i=t.resolve(a.cwd||"");const{root:f}=t.parse(i),l=[].concat(u),s=o=>{if(typeof u!="function")return r.sync(l,o);const d=u(o.cwd);return typeof d=="string"?r.sync([d],o):d};for(;;){const o=s({...a,cwd:i});if(o===c)return;if(o)return t.resolve(i,o);if(i===f)return;i=t.dirname(i)}},e.exports.exists=n,e.exports.sync.exists=n.sync,e.exports.stop=c})(R)),R.exports}var j;function le(){if(j)return y;j=1;var e=y&&y.__importDefault||function(s){return s&&s.__esModule?s:{default:s}};Object.defineProperty(y,"__esModule",{value:!0}),y.findWorkspaceDir=f;const t=e(S),r=e(h),n=ne(),c=e(ue()),u="NPM_CONFIG_WORKSPACE_DIR",a="pnpm-workspace.yaml",i=["pnpm-workspaces.yaml","pnpm-workspaces.yml","pnpm-workspace.yml"];async function f(s){const o=process.env[u]??process.env[u.toLowerCase()],d=o?r.default.join(o,a):await(0,c.default)([a,...i],{cwd:await l(s)});if(d&&r.default.basename(d)!==a)throw new n.PnpmError("BAD_WORKSPACE_MANIFEST_NAME",`The workspace manifest file should be named "pnpm-workspace.yaml". File found: ${d}`);return d&&r.default.dirname(d)}async function l(s){return new Promise(o=>{t.default.realpath.native(s,function(d,E){o(d!==null?s:E)})})}return y}var fe=le();const de=te("rent-scraper").config,w=h.join(de,"config.yaml"),he=h.join(ee.homedir(),"rent-scraper"),F=async e=>{const t=await fe.findWorkspaceDir(process.cwd());if(t)return e==="redfin"?h.join(t,"config.redfin.yaml"):h.join(t,"config.zillow.yaml");if(await W())return await Q(e)},U=async(e,t)=>{const r=t??await F(e);if(r)return await P(r)},W=async()=>await P(w),pe=async e=>{const t=await F(e);if(t)return await P(t)||m("Config file is required."),await _(t)},we=async()=>{const e=await g("zillow");if(e){const{zillowCookie:t,...r}=e??{};await M("zillow",r)}},ye=async e=>{try{return await new Promise(t=>{const r=setInterval(async()=>{const n=await U(e);n&&(t(n),clearInterval(r))},1e3)})}catch(t){m(t?.message)}},Ee=async()=>{try{return await new Promise((e,t)=>{const r=Z();r.start("Waiting for browser server");let n=0;const c=setInterval(async()=>{n++,n>10&&t(new Error("browser server is not running."));const u=await Y();u&&(r.stop("Browser server is connected!"),e(u),clearInterval(c))},1e3)})}catch(e){m(e?.message)}},Y=async()=>{try{const{data:e}=await G.get("http://localhost:8082/server");return e.running}catch{return!1}},_e=async()=>await new Promise(e=>{const t=setInterval(async()=>{const r=await H();r&&(e(r),clearInterval(t))},1e3)}),H=async()=>await I("zillow","zillowCookie"),me=(e,t,r="init")=>{const{outputPath:n,zipCodes:c,browser:u,zillowCookie:a}=t??{},i=[];return n||i.push("outputPath"),c||i.push("zipCodes"),e==="zillow"&&!u&&i.push("browser"),r==="scrape"&&e==="zillow"&&!a&&i.push("zillowCookie"),i},Fe=async e=>(await I(e,"zipCodes"))?.replace(/ /g,"").split(",").map(t=>Number(t)),Le=e=>e.join(", "),g=async e=>{const t=await F(e);if(t)return await _(t)},ve=async(e,t,r)=>{h.isAbsolute(t)||m("configDirectory must be an absolute path");const n=await X(t).catch(()=>null);n&&!n.isDirectory()&&m(`${t} exists but is not a directory`),await C(t,{recursive:!0});const c=h.dirname(w);await C(c,{recursive:!0}),r=r??`config.${e}.yaml`;const u=h.join(t,r),a={...await _(w),[e]:u};return await b(w,a),(await _(w)??{})?.[e]},Q=async e=>{try{return(await _(w))?.[e]}catch(t){console.error(`Failed to read pointer file at ${w}: ${t.message}`)}},ge=async e=>await I(e,"outputPath"),I=async(e,t)=>(await g(e))?.[t]??null,Ie=async(e,t)=>{const r=await g(e),n=Object.keys(t),c={...r,...t};await M(e,c),J.success(`Updated ${e} config: ${n.join(", ")}`)},M=async(e,t)=>{const r=await F(e);return await C(h.dirname(r),{recursive:!0}),await b(r,t),r};export{Y as checkBrowserServer,pe as checkForAndReadConfigFile,U as checkForConfigFile,W as checkForPointerFile,H as checkForZillowCookie,me as checkRequiredConfigValues,F as getConfigFilePath,ge as getOutputPathFromConfig,I as getValueFromConfigFile,Fe as getZipCodesFromConfig,he as globalDir,w as pointerFilePath,g as readConfigFile,Q as readPointerFile,we as resetZillowCookie,Le as stringifyZipCodes,Ie as updateConfigFile,Ee as waitForBrowserServer,ye as waitForConfigFile,_e as waitForZillowCookie,M as writeConfigFile,ve as writePointerFile};
package/dist/index.d.mts CHANGED
@@ -6,7 +6,7 @@ type List = Item[];
6
6
  declare const groupByKey: (list: any[], key: string | number) => any;
7
7
  declare const isObject: (data: Record<string, unknown>) => boolean;
8
8
  declare const isEmptyObject: (data: Record<string, unknown>) => boolean;
9
- declare function throwError(message: string, status?: number): void;
9
+ declare function throwError(message: string, status?: number): never;
10
10
  declare const parseThrownError: (error: {
11
11
  message: string;
12
12
  }) => any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rent-scraper/utils",
3
- "version": "1.0.14",
3
+ "version": "1.0.15-beta.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.mjs",
@@ -30,8 +30,9 @@
30
30
  "axios": "^1.10.0",
31
31
  "bumpp": "^10.2.3",
32
32
  "csv": "^6.3.11",
33
+ "env-paths": "^3.0.0",
33
34
  "yaml": "^2.8.0",
34
- "@rent-scraper/api": "1.0.14"
35
+ "@rent-scraper/api": "1.0.15-beta.2"
35
36
  },
36
37
  "devDependencies": {
37
38
  "unbuild": "^3.5.0"