diff --git a/.eslintrc.yml b/.eslintrc.yml index 49296770..35dff0b6 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,5 +1,6 @@ root: true env: + node: true browser: true commonjs: true es2021: true diff --git a/src/lib/getCrumb.ts b/src/lib/getCrumb.ts index 29be6057..cffe2b72 100644 --- a/src/lib/getCrumb.ts +++ b/src/lib/getCrumb.ts @@ -18,7 +18,10 @@ export default async function getCrumb( ...fetchOptionsBase, headers: { ...fetchOptionsBase.headers, - cookie: cookieJar.getCookieStringSync(url), + // NB, we won't get a set-cookie header back without this: + accept: "text/html,application/xhtml+xml,application/xml", + // This request will get our first cookies, so nothing to send. + // cookie: cookieJar.getCookieStringSync(url), }, }; @@ -26,9 +29,9 @@ export default async function getCrumb( const setCookieHeader = response.headers.get("set-cookie"); if (setCookieHeader) cookieJar.setFromSetCookieHeaders(setCookieHeader, url); - console.log(response.headers); - console.log(setCookieHeader); - console.log(cookieJar); + // console.log(response.headers); + // console.log(setCookieHeader); + // console.log(cookieJar); const source = await response.text(); diff --git a/src/lib/queue.ts b/src/lib/queue.ts index 3d32df57..973e265b 100644 --- a/src/lib/queue.ts +++ b/src/lib/queue.ts @@ -12,9 +12,9 @@ export interface QueueOptions { } export default class Queue { - concurrency: number = 1; + concurrency = 1; - _running: number = 0; + _running = 0; _queue: Array = []; constructor(opts: QueueOptions = {}) { @@ -40,7 +40,7 @@ export default class Queue { if (this._running < this.concurrency) this.runNext(); } - add(func: () => Promise) { + add(func: () => Promise) { return new Promise((resolve, reject) => { this._queue.push({ func, resolve, reject }); this.checkQueue(); diff --git a/src/lib/yahooFinanceFetch.ts b/src/lib/yahooFinanceFetch.ts index bfccb93f..fbcfd425 100644 --- a/src/lib/yahooFinanceFetch.ts +++ b/src/lib/yahooFinanceFetch.ts @@ -1,4 +1,4 @@ -import type { RequestInit } from "node-fetch"; +import type { RequestInfo, RequestInit, Response } from "node-fetch"; import Queue from "./queue.js"; import type { YahooFinanceOptions } from "./options.js"; @@ -14,8 +14,10 @@ const userAgent = `${pkg.name}/${pkg.version} (+${pkg.repository})`; interface YahooFinanceFetchThisEnv { [key: string]: any; URLSearchParams: (init?: any) => any; - fetch: Function; - fetchDevel: Function; + fetch: (url: RequestInfo, init?: RequestInit) => Promise; + fetchDevel: () => Promise< + (url: RequestInfo, init?: RequestInit) => Promise + >; } interface YahooFinanceFetchThis { @@ -45,7 +47,7 @@ function assertQueueOptions(queue: any, opts: any) { } function substituteVariables(this: YahooFinanceFetchThis, urlBase: string) { - return urlBase.replace(/\$\{([^\}]+)\}/g, (match, varName) => { + return urlBase.replace(/\$\{([^}]+)\}/g, (match, varName) => { if (varName === "YF_QUERY_HOST") { // const hosts = ["query1.finance.yahoo.com", "query2.finance.yahoo.com"]; // return hosts[Math.floor(Math.random() * hosts.length)]; @@ -96,7 +98,7 @@ async function yahooFinanceFetch( const urlSearchParams = new URLSearchParams(params); const url = substituteVariables.call(this, urlBase) + "?" + urlSearchParams.toString(); - console.log(url); + // console.log(url); const fetchOptions = { ...fetchOptionsBase, @@ -106,7 +108,7 @@ async function yahooFinanceFetch( }, }; - console.log(fetchOptions); + // console.log(fetchOptions); // used in moduleExec.ts if (func === "csv") func = "text";