Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
execute: function (query) {
// construct the search call..
return searchItems({
searchForm: {
q: query,
start: 1,
num: 10
}
})
.then((response) => {
// if we got results
if (Array.isArray(response.results) && response.results.length) {
console.info(`${response.total} items found for "${query}".`);
response.results.forEach((entry) => {
console.info(`${entry.id} | ${entry.title}`);
})
} else {
console.info(`No results found for "${query}".`);
}
query.match(tag).in("tags");
if (index !== tags.length - 1) {
query.or();
}
});
query.endGroup();
}
// format the search query for the search text
if (searchText.length) {
query.and().match(searchText);
}
console.log(chalk.blue(`Searching ArcGIS Online: ${query.toParam()}`));
return searchItems({
authentication: session,
q: query,
num: number
})
.then(response => {
return { response, session };
})
.catch(err => {
console.warn(err);
})
}
);
execute: function (id, fileName) {
console.info(`Exporting item ${id} to file ${fileName}`);
// construct the search call..
let model = {};
return getItem(id)
.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) => {
if (maybeData) {
model.data = maybeData;
}
// now write out the file...
jsonfile.writeFileSync(fileName, model, {spaces: 2});
id: createResponse.id,
resource: file,
name: file.name,
authentication: authentication,
params: {}
};
// Check for folder in resource filename
const filenameParts = file.name.split("/");
if (filenameParts.length > 1) {
addResourceOptions.name = filenameParts[1];
addResourceOptions.params = {
resourcesPrefix: filenameParts[0]
};
}
updateDefs.push(portal.addItemResource(addResourceOptions));
});
}
return new Promise((resolve, reject) => {
const updateOptions: portal.IUpdateItemOptions = {
item: itemInfo,
params: {
text: data
},
authentication: authentication
};
portal.updateItem(updateOptions).then(
() => {
if (access && access !== "private") {
// Set access if it is not AGOL default
// Set the access manually since the access value in createItem appears to be ignored
const accessOptions: portal.ISetAccessOptions = {
id: serviceItemId,
access: access === "public" ? "public" : "org", // need to use constants rather than string
authentication: authentication
};
portal.setItemAccess(accessOptions).then(
() => {
progressTickCallback && progressTickCallback();
resolve();
},
e => reject(generalHelpers.fail(e))
);
return new Promise((resolve, reject) => {
const addMetadataOptions: portal.IUpdateItemOptions = {
item: {
id: itemId
},
params: {
// Pass metadata in via params because item property is serialized, which discards a blob
metadata: metadataFile
},
authentication: authentication
};
portal.updateItem(addMetadataOptions).then(resolve, reject);
});
}
isGroup: boolean = false
): Promise {
const updateOptions: any = {
params: {
// Pass image in directly because item object is serialized, which discards a blob
thumbnail: blob
},
authentication: authentication
};
updateOptions[isGroup ? "group" : "item"] = {
id: itemId
};
return isGroup
? portal.updateGroup(updateOptions)
: portal.updateItem(updateOptions);
}
export function addMetadataFromBlob(
blob: Blob,
itemId: string,
authentication: UserSession
): Promise {
const updateOptions: any = {
item: {
id: itemId
},
params: {
// Pass metadata in via params because item property is serialized, which discards a blob
metadata: blob
},
authentication: authentication
};
return portal.updateItem(updateOptions);
}
return new Promise((resolve, reject) => {
// Update its URL
const options = {
item: {
id,
url
},
authentication: authentication
};
portal.updateItem(options).then(
() => {
resolve(id);
},
e => reject(generalHelpers.fail(e))
);
});
}
import { searchItems } from "@esri/arcgis-rest-portal";
let element = document.createElement("div");
document.body.appendChild(element);
searchItems("water").then(response => {
element.innerHTML = JSON.stringify(response); // false
});