Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private addModifier(modifier: string) {
if (this.currentModifer) {
warn(
// prettier-ignore
`You have called \`${this.currentModifer}()\` after \`${modifier}()\`. Your current query was not modified.`
);
return this;
}
this.commit();
if (this.q === "") {
warn(
`You have called \`${modifier}()\` without calling another method to modify your query first. Try calling \`match()\` first.`
);
return this;
}
this.currentModifer = modifier;
private addModifier(modifier: string) {
if (this.currentModifer) {
warn(
// prettier-ignore
`You have called \`${this.currentModifer}()\` after \`${modifier}()\`. Your current query was not modified.`
);
return this;
}
this.commit();
if (this.q === "") {
warn(
`You have called \`${modifier}()\` without calling another method to modify your query first. Try calling \`match()\` first.`
);
return this;
}
this.currentModifer = modifier;
this.q += ` ${modifier.toUpperCase()} `;
return this;
}
public in(this: SearchQueryBuilder, field?: string) {
const fn = `\`in(${field ? `"${field}"` : ""})\``;
if (!this.hasRange && !this.hasTerms) {
warn(
// prettier-ignore
`${fn} was called with no call to \`match(...)\` or \`from(...)\`/\`to(...)\`. Your query was not modified.`
);
return this;
}
if (field && field !== "*") {
this.q += `${field}: `;
}
return this.commit();
}
.then(resolve);
}, function () {
// If it fails, try URL for group base section
groups.getGroup(id, requestOptions)
.then(function (itemSection) {
var newGroup = new group_1.Group(itemSection);
newGroup.init(requestOptions)
.then(resolve);
}, function () {
var error = new arcgis_rest_request_1.ArcGISRequestError("Item or group does not exist or is inaccessible.");
reject(error);
});
});
}
catch (notUsed) {
var error = new arcgis_rest_request_1.ArcGISRequestError("Item or group does not exist or is inaccessible.");
reject(error);
}
});
};
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
);
}