From 8418b242c38c310eb54b8443de9f2639daa5a0d6 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Mon, 29 May 2023 19:20:12 -0500 Subject: [PATCH] Replace Axios with fetch API. --- package-lock.json | 95 +---------------------------------------- package.json | 5 +-- src/api-log-appender.ts | 8 ++-- 3 files changed, 6 insertions(+), 102 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4ee648c..c41a9de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@jdbernard/logging", - "version": "1.1.4", + "version": "1.1.5", "lockfileVersion": 3, "requires": true, "packages": { @@ -8,103 +8,10 @@ "name": "@jdbernard/logging", "version": "1.1.4", "license": "GPL-3.0", - "dependencies": { - "axios": "^1.4.0" - }, "devDependencies": { "typescript": "^5.0.4" } }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" - }, - "node_modules/axios": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.4.0.tgz", - "integrity": "sha512-S4XCWMEmzvo64T9GfvQDOXgYRDJ/wsSZc7Jvdgx5u1sd0JwsuPLqb3SYmusag+edF6ziyMensPVqLTSc1PiSEA==", - "dependencies": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "engines": { - "node": ">=0.4.0" - } - }, - "node_modules/follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, - "node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" - }, "node_modules/typescript": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", diff --git a/package.json b/package.json index a7ae986..81082fa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jdbernard/logging", - "version": "1.1.4", + "version": "1.1.5", "description": "Simple Javascript logging service.", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -24,8 +24,5 @@ "license": "GPL-3.0", "devDependencies": { "typescript": "^5.0.4" - }, - "dependencies": { - "axios": "^1.4.0" } } diff --git a/src/api-log-appender.ts b/src/api-log-appender.ts index 2b62f0c..6ec0b46 100644 --- a/src/api-log-appender.ts +++ b/src/api-log-appender.ts @@ -1,5 +1,3 @@ -import Axios from 'axios'; - import { LogMessage, LogLevel } from './log-message'; import LogAppender from './log-appender'; @@ -16,7 +14,6 @@ export class ApiLogAppender implements LogAppender { public maximumTimePassedInSec = 120; public threshold = LogLevel.ALL; - private http = Axios.create(); private msgBuffer: ApiMessage[] = []; private lastSent = 0; @@ -50,7 +47,10 @@ export class ApiLogAppender implements LogAppender { private doPost() { if (this.msgBuffer.length > 0 && this.authToken) { - this.http.post(this.apiEndpoint, this.msgBuffer, { + fetch(this.apiEndpoint, { + method: 'POST', + mode: 'cors', + body: JSON.stringify(this.msgBuffer), headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${this.authToken}`