From f0f1efa280e1a9a54c640f3cc56794ae7c3e4bfa Mon Sep 17 00:00:00 2001 From: Endre T Date: Thu, 16 Nov 2023 16:08:45 +0100 Subject: [PATCH] upgrade typescript version, fix axios breaking changes (#72) * [security] bump axios lib to latest * upgrade typescript, fix axios BCs * axios to 4.8.4, apply pr suggestions --------- Co-authored-by: andrew-cat --- package-lock.json | 14 +++++++------- package.json | 2 +- src/ConfigFetcher.ts | 12 ++++++------ test/HttpTests.ts | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index df95204..0fe091b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -39,7 +39,7 @@ "karma-webpack": "^5.0.0", "mocha": "^10.2.0", "ts-loader": "^9.3.1", - "typescript": "^4.0.2", + "typescript": "^4.8.4", "webpack": "^5.77.0", "webpack-auto-inject-version": "^1.2.2", "webpack-cli": "^4.10.0" @@ -9367,9 +9367,9 @@ "dev": true }, "node_modules/typescript": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.2.tgz", - "integrity": "sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ==", + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", + "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -17361,9 +17361,9 @@ "dev": true }, "typescript": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.2.tgz", - "integrity": "sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ==", + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", + "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==", "dev": true }, "ua-parser-js": { diff --git a/package.json b/package.json index 6abebc1..32cf72d 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "karma-webpack": "^5.0.0", "mocha": "^10.2.0", "ts-loader": "^9.3.1", - "typescript": "^4.0.2", + "typescript": "^4.8.4", "webpack": "^5.77.0", "webpack-auto-inject-version": "^1.2.2", "webpack-cli": "^4.10.0" diff --git a/src/ConfigFetcher.ts b/src/ConfigFetcher.ts index 17efdf8..31c61d0 100644 --- a/src/ConfigFetcher.ts +++ b/src/ConfigFetcher.ts @@ -1,4 +1,4 @@ -import type { AxiosError, AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from "axios"; +import type { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios"; import axios from "axios"; import type { IConfigFetcher, IFetchResponse, OptionsBase } from "configcat-common"; import { FetchError } from "configcat-common"; @@ -6,7 +6,7 @@ import { FetchError } from "configcat-common"; export class HttpConfigFetcher implements IConfigFetcher { async fetchLogic(options: OptionsBase, lastEtag: string | null): Promise { // If we are not running in browser set the If-None-Match header. - const headers: AxiosRequestHeaders = typeof window !== "undefined" || !lastEtag + const headers: {} = typeof window !== "undefined" || !lastEtag // NOTE: It's intentional that we don't specify the If-None-Match header. // The browser automatically handles it, adding it manually would cause an unnecessary CORS OPTIONS request. ? {} @@ -52,10 +52,10 @@ export class HttpConfigFetcher implements IConfigFetcher { throw err; } - const { status: statusCode, statusText: reasonPhrase } = response; - if (response.status === 200) { - const eTag = response.headers.etag as string; - return { statusCode, reasonPhrase, eTag, body: response.data }; + const { status: statusCode, statusText: reasonPhrase } = response!; + if (statusCode === 200) { + const eTag = response!.headers.etag as string; + return { statusCode, reasonPhrase, eTag, body: response!.data }; } return { statusCode, reasonPhrase }; diff --git a/test/HttpTests.ts b/test/HttpTests.ts index b0351f5..5d4b017 100644 --- a/test/HttpTests.ts +++ b/test/HttpTests.ts @@ -1,4 +1,4 @@ -import axios, { AxiosError } from "axios"; +import axios, { AxiosError, InternalAxiosRequestConfig } from "axios"; import AxiosMockAdapter, { } from "axios-mock-adapter"; import { assert } from "chai"; import { LogLevel } from "../src/index"; @@ -17,7 +17,7 @@ describe("HTTP tests", () => { try { axiosMock.onGet().reply(async config => { await new Promise(resolve => setTimeout(resolve, requestTimeoutMs)); - throw new AxiosError(`timeout of ${config.timeout}ms exceeded`, "ECONNABORTED", config, {}, void 0); + throw new AxiosError(`timeout of ${config.timeout}ms exceeded`, "ECONNABORTED", config as InternalAxiosRequestConfig, {}, void 0); }); const logger = new FakeLogger(); @@ -105,7 +105,7 @@ describe("HTTP tests", () => { try { axiosMock.onGet().reply(config => { - throw new AxiosError(errorMessage, "ECONNABORTED", config, {}, void 0); + throw new AxiosError(errorMessage, "ECONNABORTED", config as InternalAxiosRequestConfig, {}, void 0); }); const logger = new FakeLogger();