Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { webmapId } = params;
// if we are on the server we won't have an actuall UserSession just a
// JSON representation of one. So we need to hydrate a UserSession.
const userSession = process.browser ? session : new UserSession(session);
// next we can request both the webmap item and the webmap data (the JSON)
// and process the data to get a list of layers.
return Promise.all([
getItem(webmapId, {
authentication: userSession
}).catch(error => {
return retryWithNewSession(error, this.fetch);
}),
getItemData(webmapId, {
authentication: userSession
}).catch(error => {
return retryWithNewSession(error, this.fetch);
})
]).then(([item, webmap]) => {
const layers = webmap.operationalLayers
.concat(webmap.baseMap.baseMapLayers)
.map(layer => {
return {
title: layer.title || layer.id,
url: layer.url,
itemId: layer.itemId
};
});
return {
item,
.then((item) => {
model.item = item;
if (this.shouldFetchData(item.type)){
console.info(`...Fetching ./data for item of type ${item.type}`);
return getItemData(id);
} else {
console.info(`...Items of type ${item.type} do not have json ./data - skipping`);
return Promise.resolve();
}
})
.then((maybeData) => {
public async getItem(itemId : string) : Promise{
const item = await getItem(itemId, {
portal: this.restURL,
authentication: this.authentication,
});
const itemData = await getItemData(itemId, {
authentication: this.authentication,
portal: this.restURL,
});
let data;
if(typeof itemData === 'string'){
try {
data = JSON.parse(itemData);
} catch(e){
data = itemData;
}
} else {
data = itemData;
}
return {item, data};