added getTenantProperty helper

This commit is contained in:
Peter Morton 2023-10-16 21:53:04 -05:00
parent 072325ad0e
commit b4a31c76ca

View File

@ -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);
});
});
}