From f43e6e3de4fe5999582a4854486ffc58f8dbcfd1 Mon Sep 17 00:00:00 2001 From: Rocio De Santiago Date: Fri, 2 Aug 2024 17:08:52 -0500 Subject: [PATCH] add landing page --- .../utils/api/requestMethods/getRequestHeaders.ts | 14 ++++++++++++++ .../api/requestMethods/getTemplateUrl.test.ts | 9 +++++++++ .../src/utils/api/requestMethods/getTemplateUrl.ts | 12 ++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 services/ui-src/src/utils/api/requestMethods/getRequestHeaders.ts create mode 100644 services/ui-src/src/utils/api/requestMethods/getTemplateUrl.test.ts create mode 100644 services/ui-src/src/utils/api/requestMethods/getTemplateUrl.ts diff --git a/services/ui-src/src/utils/api/requestMethods/getRequestHeaders.ts b/services/ui-src/src/utils/api/requestMethods/getRequestHeaders.ts new file mode 100644 index 00000000..ba8eca88 --- /dev/null +++ b/services/ui-src/src/utils/api/requestMethods/getRequestHeaders.ts @@ -0,0 +1,14 @@ +import { Auth } from "aws-amplify"; + +export const getRequestHeaders = async (): Promise => { + try { + const session = await Auth.currentSession(); + const token = await session.getIdToken().getJwtToken(); + const headers = { + "x-api-key": token, + }; + return headers; + } catch (error) { + console.log(error); //eslint-disable-line no-console + } +}; diff --git a/services/ui-src/src/utils/api/requestMethods/getTemplateUrl.test.ts b/services/ui-src/src/utils/api/requestMethods/getTemplateUrl.test.ts new file mode 100644 index 00000000..0084ffe3 --- /dev/null +++ b/services/ui-src/src/utils/api/requestMethods/getTemplateUrl.test.ts @@ -0,0 +1,9 @@ +import { getSignedTemplateUrl } from "./getTemplateUrl"; + +const testTemplateName = "TestName"; + +describe("utils/getTemplateUrl", () => { + test("getSignedTemplateUrl()", () => { + expect(getSignedTemplateUrl(testTemplateName)).toBeTruthy(); + }); +}); diff --git a/services/ui-src/src/utils/api/requestMethods/getTemplateUrl.ts b/services/ui-src/src/utils/api/requestMethods/getTemplateUrl.ts new file mode 100644 index 00000000..cdb55cee --- /dev/null +++ b/services/ui-src/src/utils/api/requestMethods/getTemplateUrl.ts @@ -0,0 +1,12 @@ +import { API } from "aws-amplify"; +import { getRequestHeaders } from "./getRequestHeaders"; + +export async function getSignedTemplateUrl(templateName: string) { + const requestHeaders = await getRequestHeaders(); + const request = { + headers: { ...requestHeaders }, + }; + + const response = await API.get("hcbs", `/templates/${templateName}`, request); + return response; +}