Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function addItemData(
requestOptions: IItemDataAddRequestOptions
): Promise {
const owner = determineOwner(requestOptions);
const url = `${getPortalUrl(requestOptions)}/content/users/${owner}/items/${
requestOptions.id
}/update`;
// Portal API requires that the 'data' be POSTed in a `file` form field.
requestOptions.params = {
file: requestOptions.data,
...requestOptions.params
};
return request(url, requestOptions);
}
/**
switch (searchType) {
case "item":
path = "/search";
break;
case "group":
path = "/community/groups";
break;
default:
// "users"
path = "/portals/self/users/search";
break;
}
url = getPortalUrl(options) + path;
// send the request
return request(url, options).then(r => {
if (r.nextStart && r.nextStart !== -1) {
r.nextPage = function() {
let newOptions: ISearchOptions;
if (
typeof search === "string" ||
search instanceof SearchQueryBuilder
) {
newOptions = {
q: search,
start: r.nextStart
};
} else {
newOptions = search;
newOptions.start = r.nextStart;
}
export function fetchToken(
url: string,
requestOptions: ITokenRequestOptions
): Promise {
const options: IRequestOptions = requestOptions;
// we generate a response, so we can't return the raw response
options.rawResponse = false;
return request(url, options).then((response: IFetchTokenRawResponse) => {
const r: IFetchTokenResponse = {
token: response.access_token,
username: response.username,
expires: new Date(
// convert seconds in response to milliseconds and add the value to the current time to calculate a static expiration timestamp
Date.now() + (response.expires_in * 1000 - 1000)
),
ssl: response.ssl === true
};
if (response.refresh_token) {
r.refreshToken = response.refresh_token;
}
return r;
});
}
// if the user wants to make the item private, it needs to be unshared from any/all groups as well
if (requestOptions.access === "private") {
requestOptions.params.groups = " ";
}
if (requestOptions.access === "org") {
requestOptions.params.org = true;
}
// if sharing with everyone, share with the entire organization as well.
if (requestOptions.access === "public") {
// this is how the ArcGIS Online Home app sets public access
// setting org = true instead of account = true will cancel out all sharing
requestOptions.params.account = true;
requestOptions.params.everyone = true;
}
return request(url, requestOptions);
}
if (typeof search === "string") {
options.params.q = search;
} else {
options.params = search.searchForm;
// mixin, giving user supplied requestOptions precedence
options = {
...options,
...search
};
}
// construct the search url
const url = `${getPortalUrl(options)}/search`;
// send the request
return request(url, options);
}
export function getAttachments(
requestOptions: IGetAttachmentsOptions
): Promise<{ attachmentInfos: IAttachmentInfo[] }> {
const options: IGetAttachmentsOptions = {
httpMethod: "GET",
...requestOptions
};
// pass through
return request(
`${cleanUrl(options.url)}/${options.featureId}/attachments`,
options
);
}
export function declineInvitation(
requestOptions: IInvitationRequestOptions
): Promise {
const username = encodeURIComponent(requestOptions.authentication.username);
const portalUrl = getPortalUrl(requestOptions);
const url = `${portalUrl}/community/users/${username}/invitations/${
requestOptions.invitationId
}/decline`;
const options: IInvitationRequestOptions = { ...requestOptions };
return request(url, options);
}
export function protectGroup(
requestOptions: IGroupIdRequestOptions
): Promise<{ success: boolean }> {
const url = `${getPortalUrl(requestOptions)}/community/groups/${
requestOptions.id
}/protect`;
return request(url, requestOptions);
}
layerList.forEach(layer => {
requestsDfd.push(request(serviceUrl + "/" + layer["id"] + "?f=json", requestOptions));
});
export function unprotectItem(
requestOptions: IItemIdRequestOptions
): Promise {
const owner = determineOwner(requestOptions);
const url = `${getPortalUrl(requestOptions)}/content/users/${owner}/items/${
requestOptions.id
}/unprotect`;
return request(url, requestOptions);
}