diff --git a/package-lock.json b/package-lock.json index 29bc106..ff99499 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5206,9 +5206,9 @@ "license": "MIT" }, "node_modules/cookie": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz", - "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==", + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz", + "integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==", "dev": true, "license": "MIT", "engines": { @@ -5280,9 +5280,9 @@ } }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, "license": "MIT", "dependencies": { @@ -6827,9 +6827,9 @@ } }, "node_modules/express": { - "version": "4.21.0", - "resolved": "https://registry.npmjs.org/express/-/express-4.21.0.tgz", - "integrity": "sha512-VqcNGcj/Id5ZT1LZ/cfihi3ttTn+NJmkli2eZADigjq29qTlWi/hAQ43t/VLPq8+UX06FCEx3ByOYet6ZFblng==", + "version": "4.21.2", + "resolved": "https://registry.npmjs.org/express/-/express-4.21.2.tgz", + "integrity": "sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==", "dev": true, "license": "MIT", "dependencies": { @@ -6838,7 +6838,7 @@ "body-parser": "1.20.3", "content-disposition": "0.5.4", "content-type": "~1.0.4", - "cookie": "0.6.0", + "cookie": "0.7.1", "cookie-signature": "1.0.6", "debug": "2.6.9", "depd": "2.0.0", @@ -6852,7 +6852,7 @@ "methods": "~1.1.2", "on-finished": "2.4.1", "parseurl": "~1.3.3", - "path-to-regexp": "0.1.10", + "path-to-regexp": "0.1.12", "proxy-addr": "~2.0.7", "qs": "6.13.0", "range-parser": "~1.2.1", @@ -6867,6 +6867,10 @@ }, "engines": { "node": ">= 0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" } }, "node_modules/express/node_modules/debug": { @@ -7925,9 +7929,9 @@ } }, "node_modules/http-proxy-middleware": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/http-proxy-middleware/-/http-proxy-middleware-2.0.6.tgz", - "integrity": "sha512-ya/UeJ6HVBYxrgYotAZo1KvPWlgB48kUJLDePFeneHsVujFaW5WNj2NgWCAE//B1Dl02BIfYlpNgBy8Kf8Rjmw==", + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/http-proxy-middleware/-/http-proxy-middleware-2.0.7.tgz", + "integrity": "sha512-fgVY8AV7qU7z/MmXJ/rxwbrtQH4jBQ9m7kp3llF0liB7glmFeVZFBepQb32T3y8n8k2+AEYuMPCpinYW+/CuRA==", "dev": true, "license": "MIT", "dependencies": { @@ -11204,9 +11208,9 @@ } }, "node_modules/nanoid": { - "version": "3.3.7", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", - "integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==", + "version": "3.3.8", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.8.tgz", + "integrity": "sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w==", "dev": true, "funding": [ { @@ -11699,9 +11703,9 @@ "license": "MIT" }, "node_modules/path-to-regexp": { - "version": "0.1.10", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.10.tgz", - "integrity": "sha512-7lf7qcQidTku0Gu3YDPc8DJ1q7OOucfa/BSsIwjuh56VU7katFvuM8hULfkwB3Fns/rsVF7PwPKVw1sl5KQS9w==", + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz", + "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==", "dev": true, "license": "MIT" }, diff --git a/src/api/useTerminologyServiceApi.test.ts b/src/api/useTerminologyServiceApi.test.ts index c4acee1..9f6cd5e 100644 --- a/src/api/useTerminologyServiceApi.test.ts +++ b/src/api/useTerminologyServiceApi.test.ts @@ -103,4 +103,32 @@ describe("useTerminologyServiceApi", () => { expect(mockedAxios.post).toBeCalledTimes(1); expect(result).toContain("failure"); }); + + it("Log out UMLS success", async () => { + const resp = { status: 200, data: true }; + mockedAxios.delete.mockResolvedValue(resp); + const terminlogyService: TerminologyServiceApi = useTerminologyServiceApi(); + await terminlogyService.logoutUMLS(); + expect(mockedAxios.delete).toBeCalledTimes(1); + }); + + it("Log out UMLS failure", async () => { + const resp = { status: 404, data: false, error: { message: "error" } }; + mockedAxios.delete.mockRejectedValueOnce(resp); + const terminlogyService: TerminologyServiceApi = useTerminologyServiceApi(); + try { + const loggedout = await terminlogyService.logoutUMLS(); + expect(mockedAxios.delete).toBeCalledTimes(1); + expect(loggedout).toBeFalsy(); + } catch {} + }); + + it("Log out UMLS returns false if status is not 200", async () => { + const resp = { status: 201, data: true }; + mockedAxios.delete.mockResolvedValue(resp); + const terminlogyService: TerminologyServiceApi = useTerminologyServiceApi(); + const loggedout = await terminlogyService.logoutUMLS(); + expect(mockedAxios.delete).toBeCalledTimes(1); + expect(loggedout).toBeFalsy(); + }); }); diff --git a/src/api/useTerminologyServiceApi.ts b/src/api/useTerminologyServiceApi.ts index 8976b27..d5ce05d 100644 --- a/src/api/useTerminologyServiceApi.ts +++ b/src/api/useTerminologyServiceApi.ts @@ -48,6 +48,28 @@ export class TerminologyServiceApi { }); return "failure"; } + + async logoutUMLS(): Promise { + const baseUrl = await getServiceUrl(); + const resp = await axios + .delete(`${baseUrl}/vsac/umls-credentials`, { + headers: { + Authorization: `Bearer ${this.getAccessToken()}`, + "Content-Type": "text/plain", + }, + timeout: 15000, + }) + .then((resp) => { + // Check response status and return true if successful + return resp.status === 200; + }) + .catch((error) => { + // Log the error or handle it as needed + console.error("UMLS Logout failed:", error); + throw error; + }); + return false; + } } export const getServiceUrl = async () => {