Hi all,
I’m currently working on a Code dashboard tile which shows the current version of an extension in relation to the latest version posted in the hub. I’m hoping to use this code for Workflows so I can be notified when extensions fall out of date. But I need to get over this first hurdle.
This is the code I have created so far:
async function checkVersion(extensionName) {
// fetching extensions from the hub
const response = await fetch(
'https://{environmentid}.live.dynatrace.com/api/v2/hub/extensions2/' + extensionName,
{
headers: {
method: "GET",
Accept: "application/json; charset=utf-8",
'Authorization': 'Api-Token <REDACTED>'
}
}
);
const result = await response.json();
return result.extension2Details.recommendedCatalogVersion;
}
export default async function () {
// fetching current extensions in environment
const response = await fetch(
'https://{environmentid}.live.dynatrace.com/api/v2/extensions',
{
headers: {
method: "GET",
Accept: "application/json",
'Authorization': 'Api-Token <REDACTED>'
}
}
);
const result = await response.json();
const itemsArray = Object.values(result.extensions);
const filteredItems = itemsArray.map(extension => ({
'Extension Name': extension.extensionName,
'Version': extension.version,
'Version To Date': checkVersion(extension.extensionName).then()
}));
//console.log(checkVersion("com.dynatrace.filesystem").then());
return filteredItems;
}
I realise this may be an issue with items not being resolved yet as part of the checkVersion() function but even manually calling it makes this appear in the console:
Promise { <pending> }
..which I assume is happening in the table generated from this, too.
If I use await like this:
await checkVersion("com.dynatrace.filesystem")
…I do get some data back, but I can’t use it in the mapping function as I get this:
"message": "Parse error: await isn't allowed in non-async function at file:///script.ts:34:30\n\n 'Version To Date': await checkVersion(extension.extensionName)