Skip to content

Commit

Permalink
upgrade typescript version, fix axios breaking changes (#72)
Browse files Browse the repository at this point in the history
* [security] bump axios lib to latest

* upgrade typescript, fix axios BCs

* axios to 4.8.4, apply pr suggestions

---------

Co-authored-by: andrew-cat <[email protected]>
  • Loading branch information
endret and andrew-cat authored Nov 16, 2023
1 parent 845dbf3 commit f0f1efa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions src/ConfigFetcher.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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";

export class HttpConfigFetcher implements IConfigFetcher {
async fetchLogic(options: OptionsBase, lastEtag: string | null): Promise<IFetchResponse> {
// 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.
? {}
Expand Down Expand Up @@ -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 };
Expand Down
6 changes: 3 additions & 3 deletions test/HttpTests.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -17,7 +17,7 @@ describe("HTTP tests", () => {
try {
axiosMock.onGet().reply(async config => {
await new Promise<any>(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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit f0f1efa

Please sign in to comment.