From b4a31c76ca5946ad7fa5e1746e4d62a80d43a560 Mon Sep 17 00:00:00 2001 From: "Peter.Morton" Date: Mon, 16 Oct 2023 21:53:04 -0500 Subject: [PATCH] added getTenantProperty helper --- src/helpers/index.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/helpers/index.js b/src/helpers/index.js index e67c4ff..88906db 100644 --- a/src/helpers/index.js +++ b/src/helpers/index.js @@ -12,3 +12,41 @@ export function getAuthKeyFromProperties(props) { } return authKey; } + +export function getTenantProperty(key, props) { + return new Promise((resolve, reject) => { + if (!props) { + reject("no props provided for authentication"); + return; + } + if (!key || key.length == 0) { + reject("no key provided"); + return; + } + + var authKey = getAuthKeyFromProperties(props); + console.log(`Fetching TPS Property [${key}]`); + fetch( + `${ + import.meta.env.VITE_EO_SERVICES_URL + }/api/tps?propertyName=${key}&authKey=${authKey}`, + { + credentials: "include", // fetch won't send cookies unless you set credentials + } + ) + .then((response) => { + // check for error response + if (!response.ok) { + reject(response.data || response.statusText); + } + response.json().then((data) => { + console.log("Found Property:" + JSON.stringify(data)); + resolve(data.data.value); + }); + }) + .catch((error) => { + console.error(error); + reject(error); + }); + }); +}