Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (isLocationArray(coords)) {
options.params.location = coords.join();
} else if (isLocation(coords)) {
if (coords.lat) {
options.params.location = coords.long + "," + coords.lat;
}
if (coords.latitude) {
options.params.location = coords.longitude + "," + coords.latitude;
}
} else {
// if input is a point, we can pass it straight through, with or without a spatial reference
options.params.location = coords;
}
return request(`${cleanUrl(options.endpoint)}/reverseGeocode`, options);
}
export function addAttachment(
requestOptions: IAddAttachmentOptions
): Promise<{ addAttachmentResult: IEditFeatureResult }> {
const options: IAddAttachmentOptions = {
params: {},
...requestOptions
};
// `attachment` --> params: {}
options.params.attachment = requestOptions.attachment;
return request(
`${cleanUrl(options.url)}/${options.featureId}/addAttachment`,
options
);
}
"sqlFormat",
"returnExceededLimitFeatures",
"f"
],
{
httpMethod: "GET",
params: {
// set default query parameters
where: "1=1",
outFields: "*",
...requestOptions.params
}
}
);
return request(`${cleanUrl(requestOptions.url)}/query`, queryOptions);
}
constructor(options: IUserSessionOptions) {
this.clientId = options.clientId;
this._refreshToken = options.refreshToken;
this._refreshTokenExpires = options.refreshTokenExpires;
this.username = options.username;
this.password = options.password;
this._token = options.token;
this._tokenExpires = options.tokenExpires;
this.portal = options.portal
? cleanUrl(options.portal)
: "https://www.arcgis.com/sharing/rest";
this.ssl = options.ssl;
this.provider = options.provider || "arcgis";
this.tokenDuration = options.tokenDuration || 20160;
this.redirectUri = options.redirectUri;
this.refreshTokenTTL = options.refreshTokenTTL || 1440;
this.trustedServers = {};
// if a non-federated server was passed explicitly, it should be trusted.
if (options.server) {
// if the url includes more than '/arcgis/', trim the rest
const root = this.getServerRootUrl(options.server);
this.trustedServers[root] = {
token: options.token,
expires: options.tokenExpires
export function updateAttachment(
requestOptions: IUpdateAttachmentOptions
): Promise<{ updateAttachmentResult: IEditFeatureResult }> {
const options: IUpdateAttachmentOptions = {
params: {},
...requestOptions
};
// `attachment` and `attachmentId` --> params: {}
options.params.attachment = requestOptions.attachment;
options.params.attachmentId = requestOptions.attachmentId;
return request(
`${cleanUrl(options.url)}/${options.featureId}/updateAttachment`,
options
);
}
requestOptions,
["objectIds", "relationshipId", "definitionExpression", "outFields"],
{
httpMethod: "GET",
params: {
// set default query parameters
definitionExpression: "1=1",
outFields: "*",
relationshipId: 0,
...requestOptions.params
}
}
);
return request(
`${cleanUrl(requestOptions.url)}/queryRelatedRecords`,
options
);
}
requestOptions.addresses.forEach(address => {
options.params.addresses.records.push({ attributes: address });
});
// the SAS service doesnt support anonymous requests
if (
!requestOptions.authentication &&
options.endpoint === ARCGIS_ONLINE_GEOCODING_URL
) {
return Promise.reject(
"bulk geocoding using the ArcGIS service requires authentication"
);
}
return request(
`${cleanUrl(options.endpoint)}/geocodeAddresses`,
options
).then(response => {
if (options.rawResponse) {
return response;
}
const sr = response.spatialReference;
response.locations.forEach(function(address: { location: IPoint }) {
if (address.location) {
address.location.spatialReference = sr;
}
});
return response;
});
}
export function getFeature(
requestOptions: IGetFeatureOptions
): Promise {
const url = `${cleanUrl(requestOptions.url)}/${requestOptions.id}`;
// default to a GET request
const options: IGetFeatureOptions = {
...{ httpMethod: "GET" },
...requestOptions
};
return request(url, options).then((response: any) => {
if (options.rawResponse) {
return response;
}
return response.feature;
});
}
export function deleteAttachments(
requestOptions: IDeleteAttachmentsOptions
): Promise<{ deleteAttachmentResults: IEditFeatureResult[] }> {
const options: IDeleteAttachmentsOptions = {
params: {},
...requestOptions
};
// `attachmentIds` --> params: {}
options.params.attachmentIds = requestOptions.attachmentIds;
return request(
`${cleanUrl(options.url)}/${options.featureId}/deleteAttachments`,
options
);
}
export function getLayer(
options: ILayerRequestOptions
): Promise {
return request(cleanUrl(options.url), options);
}