diff --git a/frontend/package-lock.json b/frontend/package-lock.json index ca0be5072..d57936fad 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -33,6 +33,7 @@ "react-oidc-context": "^2.3.1", "react-router-dom": "^6.11.0", "sass": "^1.62.1", + "uuid": "^9.0.0", "validator": "^13.9.0" }, "devDependencies": { @@ -1130,6 +1131,15 @@ "react-dom": "^16.8.0 || ^17 || ^18" } }, + "node_modules/@hookform/devtools/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "dev": true, + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.8", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz", @@ -1563,6 +1573,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/@mswjs/data/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "dev": true, + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@mswjs/data/node_modules/yargs": { "version": "17.7.2", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", @@ -10017,10 +10036,13 @@ "dev": true }, "node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "dev": true, + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], "bin": { "uuid": "dist/bin/uuid" } @@ -11340,6 +11362,14 @@ "react-simple-animate": "^3.3.12", "use-deep-compare-effect": "^1.8.1", "uuid": "^8.3.2" + }, + "dependencies": { + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "dev": true + } } }, "@humanwhocodes/config-array": { @@ -11665,6 +11695,12 @@ "dev": true, "optional": true }, + "uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "dev": true + }, "yargs": { "version": "17.7.2", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", @@ -17648,10 +17684,9 @@ "dev": true }, "uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "dev": true + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==" }, "v8-to-istanbul": { "version": "9.1.0", diff --git a/frontend/package.json b/frontend/package.json index 4d897e043..03ef3c18b 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -28,6 +28,7 @@ "react-oidc-context": "^2.3.1", "react-router-dom": "^6.11.0", "sass": "^1.62.1", + "uuid": "^9.0.0", "validator": "^13.9.0" }, "scripts": { diff --git a/frontend/src/common/apiManager/httpRequestHandler.ts b/frontend/src/common/apiManager/httpRequestHandler.ts index 16ee40d67..f0024944e 100644 --- a/frontend/src/common/apiManager/httpRequestHandler.ts +++ b/frontend/src/common/apiManager/httpRequestHandler.ts @@ -1,4 +1,5 @@ import axios from "axios"; +import { v4 as uuidv4 } from "uuid"; import { applyWhenNotNullable, getDefaultNullableVal, @@ -6,6 +7,18 @@ import { } from "../helpers/util"; import { Nullable, RequiredOrNull } from "../types/common"; +// Request interceptor to add a correlationId to the header. +axios.interceptors.request.use( + function (config) { + const { headers } = config; + headers.set("x-correlation-id", uuidv4()); + return config; + }, + function (error) { + console.log("Unable to make a request:", error); + }, +); + // Add environment variables to get the full key. // Full key structure: oidc.user:${AUTH0_ISSUER_URL}:${AUTH0_AUDIENCE} // Full key example:: oidc.user:https://dev.loginproxy.gov.bc.ca/auth/realms/standard:on-route-bc-direct-4598 @@ -135,12 +148,13 @@ export const httpGETRequestStream = (url: string) => { return fetch(url, { headers: { Authorization: getAccessToken(), + "x-correlation-id": uuidv4(), }, }); }; /** - * A HTTP GET Request for streams + * A HTTP POST Request for streams * @param url The URL of the resource. * @returns A Promise with the response from the API. */ @@ -151,6 +165,7 @@ export const httpPOSTRequestStream = (url: string, data: any) => { headers: { Authorization: getAccessToken(), "Content-Type": "application/json", + "x-correlation-id": uuidv4(), }, }); };