Skip to content

Commit

Permalink
chore(deps): upgrade prettier, rerun prettier -w .
Browse files Browse the repository at this point in the history
$ yarn prettier -w .
yarn run v1.22.22
$ /home/dragon/www/npm/node-yahoo-finance2/node_modules/.bin/prettier -w .
bin/yahoo-finance.js 71ms
jest.config.ts 72ms (unchanged)
package.json 4ms (unchanged)
renovate.json 2ms (unchanged)
scripts/timeseries.ts 32ms
src/check.ts 4ms (unchanged)
src/env-browser.ts 3ms (unchanged)
src/env-node.ts 2ms (unchanged)
src/env-test.ts 4ms (unchanged)
src/index-browser.ts 5ms
src/index-common.ts 6ms (unchanged)
src/index-node.ts 3ms (unchanged)
src/index-test.ts 2ms (unchanged)
src/lib/commonTypes.ts 2ms (unchanged)
src/lib/cookieJar.ts 7ms
src/lib/csv2json.spec.ts 6ms (unchanged)
src/lib/csv2json.ts 10ms
src/lib/datetime.spec.ts 3ms (unchanged)
src/lib/datetime.ts 17ms
src/lib/errors.ts 9ms
src/lib/fetchDevel.js 13ms
src/lib/getCrumb.spec.ts 13ms
src/lib/getCrumb.ts 32ms
src/lib/moduleCommon.ts 3ms (unchanged)
src/lib/moduleExec.spec.ts 29ms
src/lib/moduleExec.ts 14ms
src/lib/notices.ts 8ms (unchanged)
src/lib/options.ts 12ms
src/lib/queue.ts 7ms
src/lib/setGlobalConfig.spec.ts 10ms
src/lib/setGlobalConfig.ts 6ms
src/lib/validateAndCoerceTypes.spec.ts 25ms
src/lib/validateAndCoerceTypes.ts 8ms
src/lib/yahooFinanceFetch.spec.ts 23ms
src/lib/yahooFinanceFetch.ts 14ms
src/lib/yahooFinanceTypes.spec.ts 23ms
src/lib/yahooFinanceTypes.ts 14ms
src/modules/autoc.spec.ts 2ms (unchanged)
src/modules/autoc.ts 1ms
src/modules/chart.spec.ts 24ms
src/modules/chart.ts 59ms
src/modules/dailyGainers.spec.ts 11ms
src/modules/dailyGainers.ts 17ms
src/modules/fundamentalsTimeSeries.spec.ts 16ms
src/modules/fundamentalsTimeSeries.ts 20ms
src/modules/historical.spec.ts 12ms
src/modules/historical.ts 22ms
src/modules/insights.spec.ts 3ms
src/modules/insights.ts 22ms
src/modules/options.spec.ts 6ms
src/modules/options.ts 14ms
src/modules/quote.spec.ts 13ms
src/modules/quote.ts 46ms
src/modules/quoteSummary-iface.ts 123ms
src/modules/quoteSummary.spec.ts 18ms
src/modules/quoteSummary.ts 9ms
src/modules/recommendationsBySymbol.spec.ts 6ms
src/modules/recommendationsBySymbol.ts 6ms
src/modules/screener.spec.ts 3ms
src/modules/screener.ts 15ms
src/modules/search.spec.ts 2ms
src/modules/search.ts 15ms
src/modules/trendingSymbols.spec.ts 3ms
src/modules/trendingSymbols.ts 5ms
src/other/quoteCombine.spec.ts 7ms (unchanged)
src/other/quoteCombine.ts 6ms
src/typings/jest.d.ts 2ms (unchanged)
tests-modules/cjs/jest.config.js 3ms (unchanged)
tests-modules/cjs/package.json 2ms (unchanged)
tests-modules/cjs/tests/tests.spec.js 2ms (unchanged)
tests-modules/esm/jest.config.js 2ms (unchanged)
tests-modules/esm/package.json 1ms (unchanged)
tests-modules/esm/tests/tests.spec.js 2ms (unchanged)
tests/console.js 3ms (unchanged)
tests/marketTimes.js 14ms (unchanged)
tests/reporter.js 3ms (unchanged)
tests/setupTests.js 1ms (unchanged)
tests/summary-reporter.js 2ms (unchanged)
tests/testSymbols.ts 4ms
tests/testYf.ts 1ms (unchanged)
tests/updateJson.js 2ms (unchanged)
tsconfig.json 2ms (unchanged)
x.js 2ms (unchanged)
Done in 1.64s.
  • Loading branch information
gadicc committed Aug 12, 2024
1 parent 46ee6c1 commit c58c84b
Show file tree
Hide file tree
Showing 52 changed files with 425 additions and 421 deletions.
2 changes: 1 addition & 1 deletion bin/yahoo-finance.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (moduleName === "--help" || moduleName === "-h") {
console.log();
console.log("Run the quoteSummary module with two submodules:");
console.log(
'$ yahoo-finance.js quoteSummary AAPL \'{"modules":["assetProfile", "secFilings"]}\''
'$ yahoo-finance.js quoteSummary AAPL \'{"modules":["assetProfile", "secFilings"]}\'',
);
console.log();
console.log("Available modules:");
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "5.62.0",
"eslint": "8.57.0",
"eslint-config-prettier": "8.10.0",
"eslint-config-prettier": "^9.1.0",
"globby": "13.2.2",
"jest": "29.7.0",
"jest-tobetype": "1.2.3",
"prettier": "2.8.8",
"prettier": "^3.3.3",
"semantic-release": "19.0.5",
"ts-jest": "29.1.2",
"ts-node": "10.9.2",
Expand Down
4 changes: 2 additions & 2 deletions scripts/timeseries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ async function main() {
for (const entry of har.log.entries) {
const json = await getTimeseriesJSON();
const refererHeader = entry.request.headers.find(
(header) => header.name === "Referer"
(header) => header.name === "Referer",
);
const typeParam = entry.request.queryString.find(
(header) => header.name === "type"
(header) => header.name === "type",
);

if (!refererHeader) {
Expand Down
2 changes: 1 addition & 1 deletion src/index-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ console.warn(
"⚠️ WARNING! This package (i.e. `yahoo-finance2`) is being used in the browser.",
"Trying to use this may not work because of CORS. Be aware of that (and don't file issues for help with that).",
"You can use a proxy to make CORS errors disappear, but we will not help you with that.",
"Please read the README (https://github.com/gadicc/node-yahoo-finance2) for more details."
"Please read the README (https://github.com/gadicc/node-yahoo-finance2) for more details.",
);

export default yahooFinance;
2 changes: 1 addition & 1 deletion src/lib/cookieJar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Cookie, CookieJar } from "tough-cookie";
export class ExtendedCookieJar extends CookieJar {
async setFromSetCookieHeaders(
setCookieHeader: string | Array<string>,
url: string
url: string,
) {
let cookies;
// console.log("setFromSetCookieHeaders", setCookieHeader);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/csv2json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function camelize(str: string): string {
.map((str, i) =>
i === 0
? str.toLowerCase()
: str[0].toUpperCase() + str.substr(1).toLowerCase()
: str[0].toUpperCase() + str.substr(1).toLowerCase(),
)
.join("");
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const isTime = (value: string, strictTimeZone?: boolean): boolean => {
*/
export const isDateTime = (
value: string,
strictTimeZone?: boolean
strictTimeZone?: boolean,
): boolean => {
const dateTime: string[] = value.split(DATE_TIME_SEPARATOR);
return (
Expand Down
2 changes: 1 addition & 1 deletion src/lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class FailedYahooValidationError extends Error {

constructor(
message: string,
{ result, errors }: { result: any; errors?: null | ValidationError[] }
{ result, errors }: { result: any; errors?: null | ValidationError[] },
) {
super(message);
this.result = result;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/fetchDevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function fetchDevel(url, fetchOptions) {
// Use query2 for all our tests / fixtures / cache
url = url.replace(
/^https:\/\/query1.finance.yahoo.com/,
"https://query2.finance.yahoo.com"
"https://query2.finance.yahoo.com",
);

// Remove crumb param to have consistent cacheable URLs
Expand All @@ -56,7 +56,7 @@ async function fetchDevel(url, fetchOptions) {
*/
const destUrl = new URL(
"./" + (fetchOptions.devel === true ? urlHash(url) : fetchOptions.devel),
BASE_URL
BASE_URL,
);

const filename = destUrl.toString();
Expand Down
16 changes: 8 additions & 8 deletions src/lib/getCrumb.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("getCrumb", () => {
logger,
"https://finance.yahoo.com/quote/AAPL",
"getCrumb-quote-AAPL.json",
true
true,
);
expect(crumb).toBe("mloUP8q7ZPH");
});
Expand All @@ -48,7 +48,7 @@ describe("getCrumb", () => {
fetch,
{ devel: true },
logger,
"https://finance.yahoo.com/quote/AAPL"
"https://finance.yahoo.com/quote/AAPL",
);
expect(crumb).toBe("mloUP8q7ZPH");

Expand All @@ -59,7 +59,7 @@ describe("getCrumb", () => {
fetch,
{ devel: true },
logger,
"https://finance.yahoo.com/quote/AAPL"
"https://finance.yahoo.com/quote/AAPL",
);
expect(crumb).toBe("mloUP8q7ZPH");
});
Expand All @@ -75,8 +75,8 @@ describe("getCrumb", () => {
logger,
"https://finance.yahoo.com/quote/AAPL",
"getCrumb-quote-AAPL-no-cookies.fake.json",
true
)
true,
),
).rejects.toThrowError(/No set-cookie/);
});

Expand Down Expand Up @@ -142,7 +142,7 @@ describe("getCrumb", () => {
logger,
"https://finance.yahoo.com/quote/AAPL",
"getCrumb-quote-AAPL-pre-consent-VPN-UK.json",
true
true,
);
expect(crumb).toBe("mloUP8q7ZPH");
// consoleSilent();
Expand All @@ -168,7 +168,7 @@ describe("getCrumb", () => {
{ devel: true },
logger,
"https://finance.yahoo.com/quote/TSLA",
_getCrumb as any
_getCrumb as any,
);

getCrumb(
Expand All @@ -177,7 +177,7 @@ describe("getCrumb", () => {
{ devel: true },
logger,
"https://finance.yahoo.com/quote/TSLA",
_getCrumb as any
_getCrumb as any,
);

expect(_getCrumb).toHaveBeenCalledTimes(1);
Expand Down
54 changes: 27 additions & 27 deletions src/lib/getCrumb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let crumb: string | null = null;

const parseHtmlEntities = (str: string) =>
str.replace(/&#x([0-9A-Fa-f]{1,3});/gi, (_, numStr) =>
String.fromCharCode(parseInt(numStr, 16))
String.fromCharCode(parseInt(numStr, 16)),
);

type CrumbOptions = RequestInit & { devel?: boolean | string };
Expand All @@ -22,7 +22,7 @@ export async function _getCrumb(
logger: Logger,
url = "https://finance.yahoo.com/quote/AAPL",
develOverride = "getCrumb-quote-AAPL.json",
noCache = false
noCache = false,
): Promise<string | null> {
if (!crumb) {
const cookies = await cookieJar.getCookies(CONFIG_FAKE_URL);
Expand All @@ -43,7 +43,7 @@ export async function _getCrumb(

async function processSetCookieHeader(
header: string[] | undefined,
url: string
url: string,
) {
if (header) {
await cookieJar.setFromSetCookieHeaders(header, url);
Expand Down Expand Up @@ -104,24 +104,24 @@ export async function _getCrumb(
};
logger.debug(
"fetch",
consentLocation /*, collectConsentFetchOptions */
consentLocation /*, collectConsentFetchOptions */,
);

const collectConsentResponse = await fetch(
consentLocation,
collectConsentFetchOptions
collectConsentFetchOptions,
);
const collectConsentBody = await collectConsentResponse.text();

const collectConsentResponseParams =
[
...collectConsentBody.matchAll(
/<input type="hidden" name="([^"]+)" value="([^"]+)">/g
/<input type="hidden" name="([^"]+)" value="([^"]+)">/g,
),
]
.map(
([, name, value]) =>
`${name}=${encodeURIComponent(parseHtmlEntities(value))}&`
`${name}=${encodeURIComponent(parseHtmlEntities(value))}&`,
)
.join("") + "agree=agree&agree=agree";

Expand All @@ -139,75 +139,75 @@ export async function _getCrumb(
};
logger.debug(
"fetch",
consentLocation /*, collectConsentSubmitFetchOptions */
consentLocation /*, collectConsentSubmitFetchOptions */,
);
const collectConsentSubmitResponse = await fetch(
consentLocation,
collectConsentSubmitFetchOptions
collectConsentSubmitFetchOptions,
);

// Set-Cookie: CFC=AQABCAFkWkdkjEMdLwQ9&s=AQAAAClxdtC-&g=ZFj24w; Expires=Wed, 8 May 2024 01:18:54 GMT; Domain=consent.yahoo.com; Path=/; Secure
if (
!(await processSetCookieHeader(
collectConsentSubmitResponse.headers.raw()["set-cookie"],
consentLocation
consentLocation,
))
)
throw new Error(
"No set-cookie header on collectConsentSubmitResponse, please report."
"No set-cookie header on collectConsentSubmitResponse, please report.",
);

// https://guce.yahoo.com/copyConsent?sessionId=3_cc-session_04da10ea-1025-4676-8175-60d2508bfc6c&lang=en-GB
const collectConsentSubmitResponseLocation =
collectConsentSubmitResponse.headers.get("location");
if (!collectConsentSubmitResponseLocation)
throw new Error(
"collectConsentSubmitResponse unexpectedly did not return a Location header, please report."
"collectConsentSubmitResponse unexpectedly did not return a Location header, please report.",
);

const copyConsentFetchOptions: typeof fetchOptions = {
...consentFetchOptions,
headers: {
...fetchOptions.headers,
cookie: await cookieJar.getCookieString(
collectConsentSubmitResponseLocation
collectConsentSubmitResponseLocation,
),
},
devel: "getCrumb-quote-AAPL-copyConsent",
};

logger.debug(
"fetch",
collectConsentSubmitResponseLocation /*, copyConsentFetchOptions */
collectConsentSubmitResponseLocation /*, copyConsentFetchOptions */,
);
const copyConsentResponse = await fetch(
collectConsentSubmitResponseLocation,
copyConsentFetchOptions
copyConsentFetchOptions,
);

if (
!(await processSetCookieHeader(
copyConsentResponse.headers.raw()["set-cookie"],
collectConsentSubmitResponseLocation
collectConsentSubmitResponseLocation,
))
)
throw new Error(
"No set-cookie header on copyConsentResponse, please report."
"No set-cookie header on copyConsentResponse, please report.",
);

const copyConsentResponseLocation =
copyConsentResponse.headers.get("location");
if (!copyConsentResponseLocation)
throw new Error(
"collectConsentSubmitResponse unexpectedly did not return a Location header, please report."
"collectConsentSubmitResponse unexpectedly did not return a Location header, please report.",
);

const finalResponseFetchOptions: typeof fetchOptions = {
...fetchOptions,
headers: {
...fetchOptions.headers,
cookie: await cookieJar.getCookieString(
collectConsentSubmitResponseLocation
collectConsentSubmitResponseLocation,
),
},
devel: "getCrumb-quote-AAPL-consent-final-redirect.html",
Expand All @@ -220,15 +220,15 @@ export async function _getCrumb(
logger,
copyConsentResponseLocation,
"getCrumb-quote-AAPL-consent-final-redirect.html",
noCache
noCache,
);
}
} else {
console.error(
"We expected a redirect to guce.yahoo.com, but got " + location
"We expected a redirect to guce.yahoo.com, but got " + location,
);
console.error(
"We'll try to continue anyway - you can safely ignore this if the request succeeds"
"We'll try to continue anyway - you can safely ignore this if the request succeeds",
);
// throw new Error(
// "Unsupported redirect to " + location + ", please report.");
Expand All @@ -247,7 +247,7 @@ export async function _getCrumb(
);
*/
throw new Error(
"No set-cookie header present in Yahoo's response. Something must have changed, please report."
"No set-cookie header present in Yahoo's response. Something must have changed, please report.",
);
}

Expand Down Expand Up @@ -311,15 +311,15 @@ export async function _getCrumb(
"Failed to get crumb, status " +
getCrumbResponse.status +
", statusText: " +
getCrumbResponse.statusText
getCrumbResponse.statusText,
);
}

const crumbFromGetCrumb = await getCrumbResponse.text();
crumb = crumbFromGetCrumb;
if (!crumb)
throw new Error(
"Could not find crumb. Yahoo's API may have changed; please report."
"Could not find crumb. Yahoo's API may have changed; please report.",
);

logger.debug("New crumb: " + crumb);
Expand All @@ -328,7 +328,7 @@ export async function _getCrumb(
key: "crumb",
value: crumb,
}),
CONFIG_FAKE_URL
CONFIG_FAKE_URL,
);

promise = null;
Expand All @@ -349,7 +349,7 @@ export default function getCrumb(
fetchOptionsBase: CrumbOptions,
logger: Logger,
url = "https://finance.yahoo.com/quote/AAPL",
__getCrumb = _getCrumb
__getCrumb = _getCrumb,
) {
showNotice("yahooSurvey");

Expand Down
Loading

0 comments on commit c58c84b

Please sign in to comment.