@esri/arcgis-rest-request
Advanced tools
Comparing version 1.13.1 to 1.13.2
/* @preserve | ||
* @esri/arcgis-rest-request - v1.13.1 - Apache-2.0 | ||
* @esri/arcgis-rest-request - v1.13.2 - Apache-2.0 | ||
* Copyright (c) 2017-2018 Esri, Inc. | ||
* Mon Oct 15 2018 12:06:52 GMT-0700 (Pacific Daylight Time) | ||
* Fri Nov 02 2018 15:54:43 GMT-0700 (Pacific Daylight Time) | ||
*/ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.arcgisRest = global.arcgisRest || {}))); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.arcgisRest = global.arcgisRest || {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
function __extends(d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
} | ||
function __extends(d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
} | ||
var __assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
var __assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
// TypeScript 2.1 no longer allows you to extend built in types. See https://github.com/Microsoft/TypeScript/issues/12790#issuecomment-265981442 | ||
// and https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work | ||
// | ||
// This code is from MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types. | ||
var ArcGISRequestError = /** @class */ (function () { | ||
/** | ||
* Create a new `ArcGISRequestError` object. | ||
* | ||
* @param message - The error message from the API | ||
* @param code - The error code from the API | ||
* @param response - The original response from the API that caused the error | ||
* @param url - The original url of the request | ||
* @param options - The original options and parameters of the request | ||
*/ | ||
function ArcGISRequestError(message, code, response, url, options) { | ||
message = message || "UNKNOWN_ERROR"; | ||
code = code || "UNKNOWN_ERROR_CODE"; | ||
this.name = "ArcGISRequestError"; | ||
this.message = | ||
code === "UNKNOWN_ERROR_CODE" ? message : code + ": " + message; | ||
this.originalMessage = message; | ||
this.code = code; | ||
this.response = response; | ||
this.url = url; | ||
this.options = options; | ||
} | ||
return ArcGISRequestError; | ||
}()); | ||
ArcGISRequestError.prototype = Object.create(Error.prototype); | ||
ArcGISRequestError.prototype.constructor = ArcGISRequestError; | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
var ArcGISAuthError = /** @class */ (function (_super) { | ||
__extends(ArcGISAuthError, _super); | ||
/** | ||
* Create a new `ArcGISAuthError` object. | ||
* | ||
* @param message - The error message from the API | ||
* @param code - The error code from the API | ||
* @param response - The original response from the API that caused the error | ||
* @param url - The original url of the request | ||
* @param options - The original options of the request | ||
*/ | ||
function ArcGISAuthError(message, code, response, url, options) { | ||
if (message === void 0) { message = "AUTHENTICATION_ERROR"; } | ||
if (code === void 0) { code = "AUTHENTICATION_ERROR_CODE"; } | ||
var _this = _super.call(this, message, code, response, url, options) || this; | ||
_this.name = "ArcGISAuthError"; | ||
_this.message = | ||
code === "AUTHENTICATION_ERROR_CODE" ? message : code + ": " + message; | ||
return _this; | ||
} | ||
ArcGISAuthError.prototype.retry = function (getSession, retryLimit) { | ||
var _this = this; | ||
if (retryLimit === void 0) { retryLimit = 3; } | ||
var tries = 0; | ||
var retryRequest = function (resolve, reject) { | ||
getSession(_this.url, _this.options) | ||
.then(function (session) { | ||
var newOptions = __assign({}, _this.options, { authentication: session }); | ||
tries = tries + 1; | ||
return request(_this.url, newOptions); | ||
}) | ||
.then(function (response) { | ||
resolve(response); | ||
}) | ||
.catch(function (e) { | ||
if (e.name === "ArcGISAuthError" && tries < retryLimit) { | ||
retryRequest(resolve, reject); | ||
} | ||
else if (e.name === "ArcGISAuthError" && tries >= retryLimit) { | ||
reject(_this); | ||
} | ||
else { | ||
reject(e); | ||
} | ||
}); | ||
}; | ||
return new Promise(function (resolve, reject) { | ||
retryRequest(resolve, reject); | ||
}); | ||
}; | ||
return ArcGISAuthError; | ||
}(ArcGISRequestError)); | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
/** | ||
* Checks for errors in a JSON response from the ArcGIS REST API. If there are no errors, it will return the `data` passed in. If there is an error, it will throw an `ArcGISRequestError` or `ArcGISAuthError`. | ||
* | ||
* @param data The response JSON to check for errors. | ||
* @param url The url of the original request | ||
* @param params The parameters of the original request | ||
* @param options The options of the original request | ||
* @returns The data that was passed in the `data` parameter | ||
*/ | ||
function checkForErrors(response, url, params, options) { | ||
// this is an error message from billing.arcgis.com backend | ||
if (response.code >= 400) { | ||
var message = response.message, code = response.code; | ||
throw new ArcGISRequestError(message, code, response, url, options); | ||
} | ||
// error from ArcGIS Online or an ArcGIS Portal or server instance. | ||
if (response.error) { | ||
var _a = response.error, message = _a.message, code = _a.code, messageCode = _a.messageCode; | ||
var errorCode = messageCode || code || "UNKNOWN_ERROR_CODE"; | ||
if (code === 498 || code === 499 || messageCode === "GWM_0003") { | ||
throw new ArcGISAuthError(message, errorCode, response, url, options); | ||
} | ||
throw new ArcGISRequestError(message, errorCode, response, url, options); | ||
} | ||
// error from a status check | ||
if (response.status === "failed" || response.status === "failure") { | ||
var message = void 0; | ||
var code = "UNKNOWN_ERROR_CODE"; | ||
try { | ||
message = JSON.parse(response.statusMessage).message; | ||
code = JSON.parse(response.statusMessage).code; | ||
} | ||
catch (e) { | ||
message = response.statusMessage || response.message; | ||
} | ||
throw new ArcGISRequestError(message, code, response, url, options); | ||
} | ||
return response; | ||
} | ||
return t; | ||
}; | ||
/** | ||
* Method used internally to surface messages to developers. | ||
*/ | ||
function warn(message) { | ||
if (console && console.warn) { | ||
console.warn.apply(console, [message]); | ||
} | ||
} | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
// TypeScript 2.1 no longer allows you to extend built in types. See https://github.com/Microsoft/TypeScript/issues/12790#issuecomment-265981442 | ||
// and https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work | ||
// | ||
// This code is from MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types. | ||
var ArcGISRequestError = /** @class */ (function () { | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
/** | ||
* Create a new `ArcGISRequestError` object. | ||
* Checks parameters to see if we should use FormData to send the request | ||
* @param params The object whose keys will be encoded. | ||
* @return A boolean indicating if FormData will be required. | ||
*/ | ||
function requiresFormData(params) { | ||
return Object.keys(params).some(function (key) { | ||
var value = params[key]; | ||
if (!value) { | ||
return false; | ||
} | ||
var type = value.constructor.name; | ||
switch (type) { | ||
case "Array": | ||
return false; | ||
case "Object": | ||
return false; | ||
case "Date": | ||
return false; | ||
case "Function": | ||
return false; | ||
case "Boolean": | ||
return false; | ||
case "String": | ||
return false; | ||
case "Number": | ||
return false; | ||
default: | ||
return true; | ||
} | ||
}); | ||
} | ||
/** | ||
* Converts parameters to the proper representation to send to the ArcGIS REST API. | ||
* @param params The object whose keys will be encoded. | ||
* @return A new object with properly encoded values. | ||
*/ | ||
function processParams(params) { | ||
var newParams = {}; | ||
Object.keys(params).forEach(function (key) { | ||
var param = params[key]; | ||
if (!param && | ||
param !== 0 && | ||
typeof param !== "boolean" && | ||
typeof param !== "string") { | ||
return; | ||
} | ||
var type = param.constructor.name; | ||
var value; | ||
// properly encodes objects, arrays and dates for arcgis.com and other services. | ||
// ported from https://github.com/Esri/esri-leaflet/blob/master/src/Request.js#L22-L30 | ||
// also see https://github.com/Esri/arcgis-rest-js/issues/18: | ||
// null, undefined, function are excluded. If you want to send an empty key you need to send an empty string "". | ||
switch (type) { | ||
case "Array": | ||
// Based on the first element of the array, classify array as an array of objects to be stringified | ||
// or an array of non-objects to be comma-separated | ||
value = | ||
param[0] && | ||
param[0].constructor && | ||
param[0].constructor.name === "Object" | ||
? JSON.stringify(param) | ||
: param.join(","); | ||
break; | ||
case "Object": | ||
value = JSON.stringify(param); | ||
break; | ||
case "Date": | ||
value = param.valueOf(); | ||
break; | ||
case "Function": | ||
value = null; | ||
break; | ||
case "Boolean": | ||
value = param + ""; | ||
break; | ||
default: | ||
value = param; | ||
break; | ||
} | ||
if (value || value === 0 || typeof value === "string") { | ||
newParams[key] = value; | ||
} | ||
}); | ||
return newParams; | ||
} | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
function encodeParam(key, value) { | ||
return encodeURIComponent(key) + "=" + encodeURIComponent(value); | ||
} | ||
/** | ||
* Encodes the passed object as a query string. | ||
* | ||
* @param message - The error message from the API | ||
* @param code - The error code from the API | ||
* @param response - The original response from the API that caused the error | ||
* @param url - The original url of the request | ||
* @param options - The original options and parameters of the request | ||
* @param params An object to be encoded. | ||
* @returns An encoded query string. | ||
*/ | ||
function ArcGISRequestError(message, code, response, url, options) { | ||
message = message || "UNKNOWN_ERROR"; | ||
code = code || "UNKNOWN_ERROR_CODE"; | ||
this.name = "ArcGISRequestError"; | ||
this.message = | ||
code === "UNKNOWN_ERROR_CODE" ? message : code + ": " + message; | ||
this.originalMessage = message; | ||
this.code = code; | ||
this.response = response; | ||
this.url = url; | ||
this.options = options; | ||
function encodeQueryString(params) { | ||
var newParams = processParams(params); | ||
return Object.keys(newParams) | ||
.map(function (key) { | ||
return encodeParam(key, newParams[key]); | ||
}) | ||
.join("&"); | ||
} | ||
return ArcGISRequestError; | ||
}()); | ||
ArcGISRequestError.prototype = Object.create(Error.prototype); | ||
ArcGISRequestError.prototype.constructor = ArcGISRequestError; | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
var ArcGISAuthError = /** @class */ (function (_super) { | ||
__extends(ArcGISAuthError, _super); | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
/** | ||
* Create a new `ArcGISAuthError` object. | ||
* Encodes parameters in a [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData) object in browsers or in a [FormData](https://github.com/form-data/form-data) in Node.js | ||
* | ||
* @param message - The error message from the API | ||
* @param code - The error code from the API | ||
* @param response - The original response from the API that caused the error | ||
* @param url - The original url of the request | ||
* @param options - The original options of the request | ||
* @param params An object to be encoded. | ||
* @returns The complete [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData) object. | ||
*/ | ||
function ArcGISAuthError(message, code, response, url, options) { | ||
if (message === void 0) { message = "AUTHENTICATION_ERROR"; } | ||
if (code === void 0) { code = "AUTHENTICATION_ERROR_CODE"; } | ||
var _this = _super.call(this, message, code, response, url, options) || this; | ||
_this.name = "ArcGISAuthError"; | ||
_this.message = | ||
code === "AUTHENTICATION_ERROR_CODE" ? message : code + ": " + message; | ||
return _this; | ||
} | ||
ArcGISAuthError.prototype.retry = function (getSession, retryLimit) { | ||
var _this = this; | ||
if (retryLimit === void 0) { retryLimit = 3; } | ||
var tries = 0; | ||
var retryRequest = function (resolve, reject) { | ||
getSession(_this.url, _this.options) | ||
.then(function (session) { | ||
var newOptions = __assign({}, _this.options, { authentication: session }); | ||
tries = tries + 1; | ||
return request(_this.url, newOptions); | ||
}) | ||
.then(function (response) { | ||
resolve(response); | ||
}) | ||
.catch(function (e) { | ||
if (e.name === "ArcGISAuthError" && tries < retryLimit) { | ||
retryRequest(resolve, reject); | ||
function encodeFormData(params) { | ||
var useFormData = requiresFormData(params); | ||
var newParams = processParams(params); | ||
if (useFormData) { | ||
var formData_1 = new FormData(); | ||
Object.keys(newParams).forEach(function (key) { | ||
if (typeof Blob !== "undefined" && newParams[key] instanceof Blob) { | ||
/* To name the Blob: | ||
1. look to an alternate request parameter called 'fileName' | ||
2. see if 'name' has been tacked onto the Blob manually | ||
3. if all else fails, use the request parameter | ||
*/ | ||
var filename = newParams["fileName"] || newParams[key].name || key; | ||
formData_1.append(key, newParams[key], filename); | ||
} | ||
else if (e.name === "ArcGISAuthError" && tries >= retryLimit) { | ||
reject(_this); | ||
} | ||
else { | ||
reject(e); | ||
formData_1.append(key, newParams[key]); | ||
} | ||
}); | ||
}; | ||
return new Promise(function (resolve, reject) { | ||
retryRequest(resolve, reject); | ||
}); | ||
}; | ||
return ArcGISAuthError; | ||
}(ArcGISRequestError)); | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
/** | ||
* Checks for errors in a JSON response from the ArcGIS REST API. If there are no errors, it will return the `data` passed in. If there is an error, it will throw an `ArcGISRequestError` or `ArcGISAuthError`. | ||
* | ||
* @param data The response JSON to check for errors. | ||
* @param url The url of the original request | ||
* @param params The parameters of the original request | ||
* @param options The options of the original request | ||
* @returns The data that was passed in the `data` parameter | ||
*/ | ||
function checkForErrors(response, url, params, options) { | ||
// this is an error message from billing.arcgis.com backend | ||
if (response.code >= 400) { | ||
var message = response.message, code = response.code; | ||
throw new ArcGISRequestError(message, code, response, url, options); | ||
} | ||
// error from ArcGIS Online or an ArcGIS Portal or server instance. | ||
if (response.error) { | ||
var _a = response.error, message = _a.message, code = _a.code, messageCode = _a.messageCode; | ||
var errorCode = messageCode || code || "UNKNOWN_ERROR_CODE"; | ||
if (code === 498 || code === 499 || messageCode === "GWM_0003") { | ||
throw new ArcGISAuthError(message, errorCode, response, url, options); | ||
return formData_1; | ||
} | ||
throw new ArcGISRequestError(message, errorCode, response, url, options); | ||
} | ||
// error from a status check | ||
if (response.status === "failed" || response.status === "failure") { | ||
var message = void 0; | ||
var code = "UNKNOWN_ERROR_CODE"; | ||
try { | ||
message = JSON.parse(response.statusMessage).message; | ||
code = JSON.parse(response.statusMessage).code; | ||
else { | ||
return encodeQueryString(params); | ||
} | ||
catch (e) { | ||
message = response.statusMessage || response.message; | ||
} | ||
throw new ArcGISRequestError(message, code, response, url, options); | ||
} | ||
return response; | ||
} | ||
/** | ||
* Method used internally to surface messages to developers. | ||
*/ | ||
function warn(message) { | ||
if (console && console.warn) { | ||
console.warn.apply(console, [message]); | ||
} | ||
} | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
/** | ||
* Checks parameters to see if we should use FormData to send the request | ||
* @param params The object whose keys will be encoded. | ||
* @return A boolean indicating if FormData will be required. | ||
*/ | ||
function requiresFormData(params) { | ||
return Object.keys(params).some(function (key) { | ||
var value = params[key]; | ||
if (!value) { | ||
return false; | ||
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
/** | ||
* Generic method for making HTTP requests to ArcGIS REST API endpoints. | ||
* | ||
* ```js | ||
* import { request } from '@esri/arcgis-rest-request'; | ||
* | ||
* request('https://www.arcgis.com/sharing/rest') | ||
* .then((response) => { | ||
* console.log(response.currentVersion); // => 5.2 | ||
* }); | ||
* ``` | ||
* | ||
* ```js | ||
* import { request, HTTPMethods } from '@esri/arcgis-rest-request'; | ||
* | ||
* request('https://www.arcgis.com/sharing/rest', { | ||
* httpMethod: "GET" | ||
* }).then((response) => { | ||
* console.log(response.currentVersion); // => 5.2 | ||
* }); | ||
* ``` | ||
* | ||
* ```js | ||
* import { request, HTTPMethods } from '@esri/arcgis-rest-request'; | ||
* | ||
* request('https://www.arcgis.com/sharing/rest/search', { | ||
* params: { q: 'parks' } | ||
* }).then((response) => { | ||
* console.log(response.total); // => 78379 | ||
* }); | ||
* ``` | ||
* | ||
* @param url - The URL of the ArcGIS REST API endpoint. | ||
* @param requestOptions - Options for the request, including parameters relevant to the endpoint. | ||
* @returns A Promise that will resolve with the data from the response. | ||
*/ | ||
function request(url, requestOptions) { | ||
if (requestOptions === void 0) { requestOptions = { params: { f: "json" } }; } | ||
var options = __assign({ httpMethod: "POST" }, requestOptions); | ||
var missingGlobals = []; | ||
var recommendedPackages = []; | ||
// don't check for a global fetch if a custom implementation was passed through | ||
if (!options.fetch && typeof fetch !== "undefined") { | ||
options.fetch = fetch.bind(Function("return this")()); | ||
} | ||
var type = value.constructor.name; | ||
switch (type) { | ||
case "Array": | ||
return false; | ||
case "Object": | ||
return false; | ||
case "Date": | ||
return false; | ||
case "Function": | ||
return false; | ||
case "Boolean": | ||
return false; | ||
case "String": | ||
return false; | ||
case "Number": | ||
return false; | ||
default: | ||
return true; | ||
else { | ||
missingGlobals.push("`fetch`"); | ||
recommendedPackages.push("`isomorphic-fetch`"); | ||
} | ||
}); | ||
} | ||
/** | ||
* Converts parameters to the proper representation to send to the ArcGIS REST API. | ||
* @param params The object whose keys will be encoded. | ||
* @return A new object with properly encoded values. | ||
*/ | ||
function processParams(params) { | ||
var newParams = {}; | ||
Object.keys(params).forEach(function (key) { | ||
var param = params[key]; | ||
if (!param && | ||
param !== 0 && | ||
typeof param !== "boolean" && | ||
typeof param !== "string") { | ||
return; | ||
if (typeof Promise === "undefined") { | ||
missingGlobals.push("`Promise`"); | ||
recommendedPackages.push("`es6-promise`"); | ||
} | ||
var type = param.constructor.name; | ||
var value; | ||
// properly encodes objects, arrays and dates for arcgis.com and other services. | ||
// ported from https://github.com/Esri/esri-leaflet/blob/master/src/Request.js#L22-L30 | ||
// also see https://github.com/Esri/arcgis-rest-js/issues/18: | ||
// null, undefined, function are excluded. If you want to send an empty key you need to send an empty string "". | ||
switch (type) { | ||
case "Array": | ||
// Based on the first element of the array, classify array as an array of objects to be stringified | ||
// or an array of non-objects to be comma-separated | ||
value = | ||
param[0] && | ||
param[0].constructor && | ||
param[0].constructor.name === "Object" | ||
? JSON.stringify(param) | ||
: param.join(","); | ||
break; | ||
case "Object": | ||
value = JSON.stringify(param); | ||
break; | ||
case "Date": | ||
value = param.valueOf(); | ||
break; | ||
case "Function": | ||
value = null; | ||
break; | ||
case "Boolean": | ||
value = param + ""; | ||
break; | ||
default: | ||
value = param; | ||
break; | ||
if (typeof FormData === "undefined") { | ||
missingGlobals.push("`FormData`"); | ||
recommendedPackages.push("`isomorphic-form-data`"); | ||
} | ||
if (value || value === 0 || typeof value === "string") { | ||
newParams[key] = value; | ||
if (!options.fetch || | ||
typeof Promise === "undefined" || | ||
typeof FormData === "undefined") { | ||
throw new Error("`arcgis-rest-request` requires global variables for `fetch`, `Promise` and `FormData` to be present in the global scope. You are missing " + missingGlobals.join(", ") + ". We recommend installing the " + recommendedPackages.join(", ") + " modules at the root of your application to add these to the global scope. See https://bit.ly/2KNwWaJ for more info."); | ||
} | ||
}); | ||
return newParams; | ||
} | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
function encodeParam(key, value) { | ||
return encodeURIComponent(key) + "=" + encodeURIComponent(value); | ||
} | ||
/** | ||
* Encodes the passed object as a query string. | ||
* | ||
* @param params An object to be encoded. | ||
* @returns An encoded query string. | ||
*/ | ||
function encodeQueryString(params) { | ||
var newParams = processParams(params); | ||
return Object.keys(newParams) | ||
.map(function (key) { | ||
return encodeParam(key, newParams[key]); | ||
}) | ||
.join("&"); | ||
} | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
/** | ||
* Encodes parameters in a [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData) object in browsers or in a [FormData](https://github.com/form-data/form-data) in Node.js | ||
* | ||
* @param params An object to be encoded. | ||
* @returns The complete [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData) object. | ||
*/ | ||
function encodeFormData(params) { | ||
var useFormData = requiresFormData(params); | ||
var newParams = processParams(params); | ||
if (useFormData) { | ||
var formData_1 = new FormData(); | ||
Object.keys(newParams).forEach(function (key) { | ||
if (typeof Blob !== "undefined" && newParams[key] instanceof Blob) { | ||
/* To name the Blob: | ||
1. look to an alternate request parameter called 'fileName' | ||
2. see if 'name' has been tacked onto the Blob manually | ||
3. if all else fails, use the request parameter | ||
*/ | ||
var filename = newParams["fileName"] || newParams[key].name || key; | ||
formData_1.append(key, newParams[key], filename); | ||
var httpMethod = options.httpMethod, authentication = options.authentication; | ||
var params = __assign({ f: "json" }, requestOptions.params); | ||
var fetchOptions = { | ||
method: httpMethod, | ||
// ensures behavior mimics XMLHttpRequest. needed to support sending IWA cookies | ||
credentials: "same-origin" | ||
}; | ||
return (authentication | ||
? authentication.getToken(url, { | ||
fetch: options.fetch | ||
}) | ||
: Promise.resolve("")) | ||
.then(function (token) { | ||
if (token.length) { | ||
params.token = token; | ||
} | ||
if (fetchOptions.method === "GET") { | ||
// encode the parameters into the query string | ||
var queryParams = encodeQueryString(params); | ||
// dont append a '?' unless parameters are actually present | ||
var urlWithQueryString = queryParams === "" ? url : url + "?" + encodeQueryString(params); | ||
if (options.maxUrlLength && | ||
urlWithQueryString.length > options.maxUrlLength) { | ||
// the consumer specified a maximum length for URLs | ||
// and this would exceed it, so use post instead | ||
fetchOptions.method = "POST"; | ||
} | ||
else { | ||
// just use GET | ||
url = urlWithQueryString; | ||
} | ||
} | ||
if (fetchOptions.method === "POST") { | ||
fetchOptions.body = encodeFormData(params); | ||
} | ||
/* istanbul ignore else blob responses are difficult to make cross platform we will just have to trust the isomorphic fetch will do its job */ | ||
if (!requiresFormData(params)) { | ||
fetchOptions.headers = {}; | ||
fetchOptions.headers["Content-Type"] = | ||
"application/x-www-form-urlencoded"; | ||
} | ||
return options.fetch(url, fetchOptions); | ||
}) | ||
.then(function (response) { | ||
if (!response.ok) { | ||
// server responded w/ an actual error (404, 500, etc) | ||
var status_1 = response.status, statusText = response.statusText; | ||
throw new ArcGISRequestError(statusText, "HTTP " + status_1, response, url, options); | ||
} | ||
switch (params.f) { | ||
case "json": | ||
return response.json(); | ||
case "geojson": | ||
return response.json(); | ||
case "html": | ||
return response.text(); | ||
case "text": | ||
return response.text(); | ||
/* istanbul ignore next blob responses are difficult to make cross platform we will just have to trust the isomorphic fetch will do its job */ | ||
case "image": | ||
return response.blob(); | ||
/* istanbul ignore next */ | ||
case "zip": | ||
return response.blob(); | ||
/* istanbul ignore next */ | ||
default: | ||
// hopefully we never need to handle JSON payloads when no f= parameter is set | ||
return response.blob(); | ||
} | ||
}) | ||
.then(function (data) { | ||
if (params.f === "json" || params.f === "geojson") { | ||
return checkForErrors(data, url, params, options); | ||
} | ||
else { | ||
formData_1.append(key, newParams[key]); | ||
return data; | ||
} | ||
}); | ||
return formData_1; | ||
} | ||
else { | ||
return encodeQueryString(params); | ||
} | ||
} | ||
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
/** | ||
* Generic method for making HTTP requests to ArcGIS REST API endpoints. | ||
* | ||
* ```js | ||
* import { request } from '@esri/arcgis-rest-request'; | ||
* | ||
* request('https://www.arcgis.com/sharing/rest') | ||
* .then((response) => { | ||
* console.log(response.currentVersion); // => 5.2 | ||
* }); | ||
* ``` | ||
* | ||
* ```js | ||
* import { request, HTTPMethods } from '@esri/arcgis-rest-request'; | ||
* | ||
* request('https://www.arcgis.com/sharing/rest', { | ||
* httpMethod: "GET" | ||
* }).then((response) => { | ||
* console.log(response.currentVersion); // => 5.2 | ||
* }); | ||
* ``` | ||
* | ||
* ```js | ||
* import { request, HTTPMethods } from '@esri/arcgis-rest-request'; | ||
* | ||
* request('https://www.arcgis.com/sharing/rest/search', { | ||
* params: { q: 'parks' } | ||
* }).then((response) => { | ||
* console.log(response.total); // => 78379 | ||
* }); | ||
* ``` | ||
* | ||
* @param url - The URL of the ArcGIS REST API endpoint. | ||
* @param requestOptions - Options for the request, including parameters relevant to the endpoint. | ||
* @returns A Promise that will resolve with the data from the response. | ||
*/ | ||
function request(url, requestOptions) { | ||
if (requestOptions === void 0) { requestOptions = { params: { f: "json" } }; } | ||
var options = __assign({ httpMethod: "POST" }, requestOptions); | ||
var missingGlobals = []; | ||
var recommendedPackages = []; | ||
// don't check for a global fetch if a custom implementation was passed through | ||
if (!options.fetch && typeof fetch !== "undefined") { | ||
options.fetch = fetch.bind(Function("return this")()); | ||
} | ||
else { | ||
missingGlobals.push("`fetch`"); | ||
recommendedPackages.push("`isomorphic-fetch`"); | ||
} | ||
if (typeof Promise === "undefined") { | ||
missingGlobals.push("`Promise`"); | ||
recommendedPackages.push("`es6-promise`"); | ||
} | ||
if (typeof FormData === "undefined") { | ||
missingGlobals.push("`FormData`"); | ||
recommendedPackages.push("`isomorphic-form-data`"); | ||
} | ||
if (!options.fetch || | ||
typeof Promise === "undefined" || | ||
typeof FormData === "undefined") { | ||
throw new Error("`arcgis-rest-request` requires global variables for `fetch`, `Promise` and `FormData` to be present in the global scope. You are missing " + missingGlobals.join(", ") + ". We recommend installing the " + recommendedPackages.join(", ") + " modules at the root of your application to add these to the global scope. See https://bit.ly/2KNwWaJ for more info."); | ||
} | ||
var httpMethod = options.httpMethod, authentication = options.authentication; | ||
var params = __assign({ f: "json" }, requestOptions.params); | ||
var fetchOptions = { | ||
method: httpMethod, | ||
// ensures behavior mimics XMLHttpRequest. needed to support sending IWA cookies | ||
credentials: "same-origin" | ||
}; | ||
return (authentication | ||
? authentication.getToken(url, { | ||
fetch: options.fetch | ||
}) | ||
: Promise.resolve("")) | ||
.then(function (token) { | ||
if (token.length) { | ||
params.token = token; | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
(function (ErrorTypes) { | ||
ErrorTypes["ArcGISRequestError"] = "ArcGISRequestError"; | ||
ErrorTypes["ArcGISAuthError"] = "ArcGISAuthError"; | ||
})(exports.ErrorTypes || (exports.ErrorTypes = {})); | ||
/** | ||
* Helper that returns the appropriate portal url for a given request. `requestOptions.portal` is given | ||
* precedence over `authentication.portal`. If neither are present, `www.arcgis.com/sharing/rest` is returned. | ||
* | ||
* @param requestOptions - Request options that may have authentication manager | ||
* @returns Portal url to be used in API requests | ||
*/ | ||
function getPortalUrl(requestOptions) { | ||
if (requestOptions === void 0) { requestOptions = {}; } | ||
// use portal in options if specified | ||
if (requestOptions.portal) { | ||
return requestOptions.portal; | ||
} | ||
if (fetchOptions.method === "GET") { | ||
// encode the parameters into the query string | ||
var queryParams = encodeQueryString(params); | ||
// dont append a '?' unless parameters are actually present | ||
var urlWithQueryString = queryParams === "" ? url : url + "?" + encodeQueryString(params); | ||
if (options.maxUrlLength && | ||
urlWithQueryString.length > options.maxUrlLength) { | ||
// the consumer specified a maximum length for URLs | ||
// and this would exceed it, so use post instead | ||
fetchOptions.method = "POST"; | ||
} | ||
else { | ||
// just use GET | ||
url = urlWithQueryString; | ||
} | ||
// if auth was passed, use that portal | ||
if (requestOptions.authentication) { | ||
return requestOptions.authentication.portal; | ||
} | ||
if (fetchOptions.method === "POST") { | ||
fetchOptions.body = encodeFormData(params); | ||
} | ||
/* istanbul ignore else blob responses are difficult to make cross platform we will just have to trust the isomorphic fetch will do its job */ | ||
if (!requiresFormData(params)) { | ||
fetchOptions.headers = {}; | ||
fetchOptions.headers["Content-Type"] = | ||
"application/x-www-form-urlencoded"; | ||
} | ||
return options.fetch(url, fetchOptions); | ||
}) | ||
.then(function (response) { | ||
if (!response.ok) { | ||
// server responded w/ an actual error (404, 500, etc) | ||
var status_1 = response.status, statusText = response.statusText; | ||
throw new ArcGISRequestError(statusText, "HTTP " + status_1, response, url, options); | ||
} | ||
switch (params.f) { | ||
case "json": | ||
return response.json(); | ||
case "geojson": | ||
return response.json(); | ||
case "html": | ||
return response.text(); | ||
case "text": | ||
return response.text(); | ||
/* istanbul ignore next blob responses are difficult to make cross platform we will just have to trust the isomorphic fetch will do its job */ | ||
case "image": | ||
return response.blob(); | ||
/* istanbul ignore next */ | ||
case "zip": | ||
return response.blob(); | ||
/* istanbul ignore next */ | ||
default: | ||
// hopefully we never need to handle JSON payloads when no f= parameter is set | ||
return response.blob(); | ||
} | ||
}) | ||
.then(function (data) { | ||
if (params.f === "json" || params.f === "geojson") { | ||
return checkForErrors(data, url, params, options); | ||
} | ||
else { | ||
return data; | ||
} | ||
}); | ||
} | ||
// default to arcgis.com | ||
return "https://www.arcgis.com/sharing/rest"; | ||
} | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
/** | ||
* Enum describing the different errors that might be thrown by a request. | ||
* | ||
* ```ts | ||
* import { request, ErrorTypes } from '@esri/arcgis-rest-request'; | ||
* | ||
* request("...").catch((e) => { | ||
* switch(e.name) { | ||
* case ErrorType.ArcGISRequestError: | ||
* // handle a general error from the API | ||
* break; | ||
* | ||
* case ErrorType.ArcGISAuthError: | ||
* // handle an authentication error | ||
* break; | ||
* | ||
* default: | ||
* // handle some other error (usually a network error) | ||
* } | ||
* }); | ||
* ``` | ||
*/ | ||
(function (ErrorTypes) { | ||
ErrorTypes["ArcGISRequestError"] = "ArcGISRequestError"; | ||
ErrorTypes["ArcGISAuthError"] = "ArcGISAuthError"; | ||
})(exports.ErrorTypes || (exports.ErrorTypes = {})); | ||
/** | ||
* Helper that returns the appropriate portal url for a given request. `requestOptions.portal` is given | ||
* precedence over `authentication.portal`. If neither are present, `www.arcgis.com/sharing/rest` is returned. | ||
* | ||
* @param requestOptions - Request options that may have authentication manager | ||
* @returns Portal url to be used in API requests | ||
*/ | ||
function getPortalUrl(requestOptions) { | ||
if (requestOptions === void 0) { requestOptions = {}; } | ||
// use portal in options if specified | ||
if (requestOptions.portal) { | ||
return requestOptions.portal; | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
/** | ||
* Get the portal | ||
* @param requestOptions | ||
*/ | ||
function getSelf(requestOptions) { | ||
// just delegate to getPortal w/o an id | ||
return getPortal(null, requestOptions); | ||
} | ||
// if auth was passed, use that portal | ||
if (requestOptions.authentication) { | ||
return requestOptions.authentication.portal; | ||
/** | ||
* Get a portal by id. If no id is passed, it will call portals/self | ||
* @param id | ||
* @param requestOptions | ||
*/ | ||
function getPortal(id, requestOptions) { | ||
// construct the search url | ||
var idOrSelf = id ? id : "self"; | ||
var url = getPortalUrl(requestOptions) + "/portals/" + idOrSelf; | ||
// default to a GET request | ||
var options = __assign({ httpMethod: "GET" }, requestOptions); | ||
// send the request | ||
return request(url, options); | ||
} | ||
// default to arcgis.com | ||
return "https://www.arcgis.com/sharing/rest"; | ||
} | ||
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
/** | ||
* Get the portal | ||
* @param requestOptions | ||
*/ | ||
function getSelf(requestOptions) { | ||
// just delegate to getPortal w/o an id | ||
return getPortal(null, requestOptions); | ||
} | ||
/** | ||
* Get a portal by id. If no id is passed, it will call portals/self | ||
* @param id | ||
* @param requestOptions | ||
*/ | ||
function getPortal(id, requestOptions) { | ||
// construct the search url | ||
var idOrSelf = id ? id : "self"; | ||
var url = getPortalUrl(requestOptions) + "/portals/" + idOrSelf; | ||
// default to a GET request | ||
var options = __assign({ httpMethod: "GET" }, requestOptions); | ||
// send the request | ||
return request(url, options); | ||
} | ||
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
/** | ||
* Helper for methods with lots of first order request options to pass them through as request parameters. | ||
*/ | ||
function appendCustomParams(oldOptions, newOptions) { | ||
// only pass query parameters through in the request, not generic IRequestOptions props | ||
Object.keys(oldOptions).forEach(function (key) { | ||
if (key !== "url" && | ||
key !== "params" && | ||
key !== "authentication" && | ||
key !== "httpMethod" && | ||
key !== "fetch" && | ||
key !== "portal" && | ||
key !== "maxUrlLength" && | ||
key !== "endpoint") { | ||
newOptions.params[key] = oldOptions[key]; | ||
} | ||
}); | ||
} | ||
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
/** | ||
* Helper for methods with lots of first order request options to pass them through as request parameters. | ||
*/ | ||
function appendCustomParams(oldOptions, newOptions) { | ||
// only pass query parameters through in the request, not generic IRequestOptions props | ||
Object.keys(oldOptions).forEach(function (key) { | ||
if (key !== "url" && | ||
key !== "params" && | ||
key !== "authentication" && | ||
key !== "httpMethod" && | ||
key !== "fetch" && | ||
key !== "portal" && | ||
key !== "maxUrlLength" && | ||
key !== "endpoint") { | ||
newOptions.params[key] = oldOptions[key]; | ||
} | ||
}); | ||
} | ||
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
exports.request = request; | ||
exports.encodeFormData = encodeFormData; | ||
exports.encodeParam = encodeParam; | ||
exports.encodeQueryString = encodeQueryString; | ||
exports.checkForErrors = checkForErrors; | ||
exports.warn = warn; | ||
exports.ArcGISRequestError = ArcGISRequestError; | ||
exports.ArcGISAuthError = ArcGISAuthError; | ||
exports.requiresFormData = requiresFormData; | ||
exports.processParams = processParams; | ||
exports.getSelf = getSelf; | ||
exports.getPortal = getPortal; | ||
exports.getPortalUrl = getPortalUrl; | ||
exports.appendCustomParams = appendCustomParams; | ||
exports.request = request; | ||
exports.encodeFormData = encodeFormData; | ||
exports.encodeParam = encodeParam; | ||
exports.encodeQueryString = encodeQueryString; | ||
exports.checkForErrors = checkForErrors; | ||
exports.warn = warn; | ||
exports.ArcGISRequestError = ArcGISRequestError; | ||
exports.ArcGISAuthError = ArcGISAuthError; | ||
exports.requiresFormData = requiresFormData; | ||
exports.processParams = processParams; | ||
exports.getSelf = getSelf; | ||
exports.getPortal = getPortal; | ||
exports.getPortalUrl = getPortalUrl; | ||
exports.appendCustomParams = appendCustomParams; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
//# sourceMappingURL=request.umd.js.map |
/* @preserve | ||
* @esri/arcgis-rest-request - v1.13.1 - Apache-2.0 | ||
* @esri/arcgis-rest-request - v1.13.2 - Apache-2.0 | ||
* Copyright (c) 2017-2018 Esri, Inc. | ||
* Mon Oct 15 2018 12:06:54 GMT-0700 (Pacific Daylight Time) | ||
* Fri Nov 02 2018 15:54:46 GMT-0700 (Pacific Daylight Time) | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.arcgisRest=e.arcgisRest||{})}(this,function(e){"use strict";var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};var r=Object.assign||function(e){for(var t,r=1,o=arguments.length;r<o;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},o=function(){return function(e,t,r,o,n){e=e||"UNKNOWN_ERROR",t=t||"UNKNOWN_ERROR_CODE",this.name="ArcGISRequestError",this.message="UNKNOWN_ERROR_CODE"===t?e:t+": "+e,this.originalMessage=e,this.code=t,this.response=r,this.url=o,this.options=n}}();o.prototype=Object.create(Error.prototype),o.prototype.constructor=o;var n,a=function(e){function o(t,r,o,n,a){void 0===t&&(t="AUTHENTICATION_ERROR"),void 0===r&&(r="AUTHENTICATION_ERROR_CODE");var s=e.call(this,t,r,o,n,a)||this;return s.name="ArcGISAuthError",s.message="AUTHENTICATION_ERROR_CODE"===r?t:r+": "+t,s}return function(e,r){function o(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}(o,e),o.prototype.retry=function(e,t){var o=this;void 0===t&&(t=3);var n=0,a=function(s,c){e(o.url,o.options).then(function(e){var t=r({},o.options,{authentication:e});return n+=1,p(o.url,t)}).then(function(e){s(e)}).catch(function(e){"ArcGISAuthError"===e.name&&n<t?a(s,c):"ArcGISAuthError"===e.name&&n>=t?c(o):c(e)})};return new Promise(function(e,t){a(e,t)})},o}(o);function s(e,t,r,n){if(e.code>=400){var s=e.message,c=e.code;throw new o(s,c,e,t,n)}if(e.error){var i=e.error,u=(s=i.message,c=i.code,i.messageCode),f=u||c||"UNKNOWN_ERROR_CODE";if(498===c||499===c||"GWM_0003"===u)throw new a(s,f,e,t,n);throw new o(s,f,e,t,n)}if("failed"===e.status||"failure"===e.status){s=void 0,c="UNKNOWN_ERROR_CODE";try{s=JSON.parse(e.statusMessage).message,c=JSON.parse(e.statusMessage).code}catch(t){s=e.statusMessage||e.message}throw new o(s,c,e,t,n)}return e}function c(e){return Object.keys(e).some(function(t){var r=e[t];if(!r)return!1;switch(r.constructor.name){case"Array":case"Object":case"Date":case"Function":case"Boolean":case"String":case"Number":return!1;default:return!0}})}function i(e){var t={};return Object.keys(e).forEach(function(r){var o=e[r];if(o||0===o||"boolean"==typeof o||"string"==typeof o){var n;switch(o.constructor.name){case"Array":n=o[0]&&o[0].constructor&&"Object"===o[0].constructor.name?JSON.stringify(o):o.join(",");break;case"Object":n=JSON.stringify(o);break;case"Date":n=o.valueOf();break;case"Function":n=null;break;case"Boolean":n=o+"";break;default:n=o}(n||0===n||"string"==typeof n)&&(t[r]=n)}}),t}function u(e,t){return encodeURIComponent(e)+"="+encodeURIComponent(t)}function f(e){var t=i(e);return Object.keys(t).map(function(e){return u(e,t[e])}).join("&")}function h(e){var t=c(e),r=i(e);if(t){var o=new FormData;return Object.keys(r).forEach(function(e){if("undefined"!=typeof Blob&&r[e]instanceof Blob){var t=r.fileName||r[e].name||e;o.append(e,r[e],t)}else o.append(e,r[e])}),o}return f(e)}function p(e,t){void 0===t&&(t={params:{f:"json"}});var n=r({httpMethod:"POST"},t),a=[],i=[];if(n.fetch||"undefined"==typeof fetch?(a.push("`fetch`"),i.push("`isomorphic-fetch`")):n.fetch=fetch.bind(Function("return this")()),"undefined"==typeof Promise&&(a.push("`Promise`"),i.push("`es6-promise`")),"undefined"==typeof FormData&&(a.push("`FormData`"),i.push("`isomorphic-form-data`")),!n.fetch||"undefined"==typeof Promise||"undefined"==typeof FormData)throw new Error("`arcgis-rest-request` requires global variables for `fetch`, `Promise` and `FormData` to be present in the global scope. You are missing "+a.join(", ")+". We recommend installing the "+i.join(", ")+" modules at the root of your application to add these to the global scope. See https://bit.ly/2KNwWaJ for more info.");var u=n.httpMethod,p=n.authentication,l=r({f:"json"},t.params),d={method:u,credentials:"same-origin"};return(p?p.getToken(e,{fetch:n.fetch}):Promise.resolve("")).then(function(t){if(t.length&&(l.token=t),"GET"===d.method){var r=""===f(l)?e:e+"?"+f(l);n.maxUrlLength&&r.length>n.maxUrlLength?d.method="POST":e=r}return"POST"===d.method&&(d.body=h(l)),c(l)||(d.headers={},d.headers["Content-Type"]="application/x-www-form-urlencoded"),n.fetch(e,d)}).then(function(t){if(!t.ok){var r=t.status,a=t.statusText;throw new o(a,"HTTP "+r,t,e,n)}switch(l.f){case"json":case"geojson":return t.json();case"html":case"text":return t.text();case"image":case"zip":default:return t.blob()}}).then(function(t){return"json"===l.f||"geojson"===l.f?s(t,e,0,n):t})}function l(e){return void 0===e&&(e={}),e.portal?e.portal:e.authentication?e.authentication.portal:"https://www.arcgis.com/sharing/rest"}function d(e,t){var o=e||"self";return p(l(t)+"/portals/"+o,r({httpMethod:"GET"},t))}(n=e.ErrorTypes||(e.ErrorTypes={})).ArcGISRequestError="ArcGISRequestError",n.ArcGISAuthError="ArcGISAuthError",e.request=p,e.encodeFormData=h,e.encodeParam=u,e.encodeQueryString=f,e.checkForErrors=s,e.warn=function(e){console&&console.warn&&console.warn.apply(console,[e])},e.ArcGISRequestError=o,e.ArcGISAuthError=a,e.requiresFormData=c,e.processParams=i,e.getSelf=function(e){return d(null,e)},e.getPortal=d,e.getPortalUrl=l,e.appendCustomParams=function(e,t){Object.keys(e).forEach(function(r){"url"!==r&&"params"!==r&&"authentication"!==r&&"httpMethod"!==r&&"fetch"!==r&&"portal"!==r&&"maxUrlLength"!==r&&"endpoint"!==r&&(t.params[r]=e[r])})},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=request.umd.min.js.map |
{ | ||
"name": "@esri/arcgis-rest-request", | ||
"version": "1.13.1", | ||
"version": "1.13.2", | ||
"description": "Common methods and utilities for @esri/arcgis-rest-* packages.", | ||
@@ -22,3 +22,6 @@ "main": "dist/node/index.js", | ||
"build:umd": "rollup -c ../../umd-base-profile.js && rollup -c ../../umd-production-profile.js", | ||
"build:node": "tsc --module commonjs --outDir ./dist/node" | ||
"build:node": "tsc --module commonjs --outDir ./dist/node", | ||
"dev:esm": "tsc -w --module es2015 --outDir ./dist/esm --declaration", | ||
"dev:umd": "rollup -w -c ../../umd-base-profile.js", | ||
"dev:node": "tsc -w --module commonjs --outDir ./dist/node" | ||
}, | ||
@@ -25,0 +28,0 @@ "publishConfig": { |
[![npm version][npm-img]][npm-url] | ||
[![build status][travis-img]][travis-url] | ||
[![Coverage Status][coverage-img]][coverage-url] | ||
[![apache licensed](https://img.shields.io/badge/license-Apache-green.svg?style=flat-square)](https://raw.githubusercontent.com/Esri/arcgis-rest-js/master/LICENSE) | ||
@@ -9,2 +10,4 @@ | ||
[travis-url]: https://travis-ci.org/Esri/arcgis-rest-js | ||
[coverage-img]: https://coveralls.io/repos/github/Esri/arcgis-rest-js/badge.svg | ||
[coverage-url]: https://coveralls.io/github/Esri/arcgis-rest-js | ||
@@ -11,0 +14,0 @@ # @esri/arcgis-rest-request |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
196408
68
1986