@esri/arcgis-rest-request
Advanced tools
Comparing version 1.13.2 to 1.14.0
export * from "./request"; | ||
export * from "./utils/encode-form-data"; | ||
export * from "./utils/encode-query-string"; | ||
export * from "./utils/check-for-errors"; | ||
export * from "./utils/warn"; | ||
export * from "./utils/ArcGISRequestError"; | ||
export * from "./utils/ArcGISAuthError"; | ||
export * from "./utils/retryAuthError"; | ||
export * from "./utils/ErrorTypes"; | ||
export * from "./utils/params"; | ||
export * from "./utils/process-params"; | ||
@@ -9,0 +10,0 @@ export * from "./utils/get-portal"; |
@@ -6,5 +6,4 @@ /* Copyright (c) 2018 Environmental Systems Research Institute, Inc. | ||
export * from "./utils/encode-query-string"; | ||
export * from "./utils/check-for-errors"; | ||
export * from "./utils/warn"; | ||
export * from "./utils/ArcGISRequestError"; | ||
export * from "./utils/ArcGISAuthError"; | ||
export * from "./utils/ErrorTypes"; | ||
@@ -11,0 +10,0 @@ export * from "./utils/process-params"; |
@@ -1,26 +0,4 @@ | ||
export declare type GrantTypes = "authorization_code" | "refresh_token" | "client_credentials" | "exchange_refresh_token"; | ||
export interface IParams { | ||
f?: ResponseFormats; | ||
[key: string]: any; | ||
} | ||
export interface IGenerateTokenParams extends IParams { | ||
username?: string; | ||
password?: string; | ||
expiration?: number; | ||
token?: string; | ||
serverUrl?: string; | ||
} | ||
export interface IFetchTokenParams extends IParams { | ||
client_id: string; | ||
client_secret?: string; | ||
grant_type: GrantTypes; | ||
redirect_uri?: string; | ||
refresh_token?: string; | ||
code?: string; | ||
} | ||
export interface ITokenRequestOptions { | ||
params?: IGenerateTokenParams | IFetchTokenParams; | ||
httpMethod?: HTTPMethods; | ||
fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>; | ||
} | ||
import { ArcGISRequestError } from "./utils/ArcGISRequestError"; | ||
import { IRetryAuthError } from "./utils/retryAuthError"; | ||
import { HTTPMethods, IParams, ITokenRequestOptions } from "./utils/params"; | ||
/** | ||
@@ -47,10 +25,2 @@ * Authentication can be supplied to `request` via [`UserSession`](../../auth/UserSession/) or [`ApplicationSession`](../../auth/ApplicationSession/). Both classes extend `IAuthenticationManager`. | ||
/** | ||
* HTTP methods used by the ArcGIS REST API. | ||
*/ | ||
export declare type HTTPMethods = "GET" | "POST"; | ||
/** | ||
* Valid response formats for the `f` parameter. | ||
*/ | ||
export declare type ResponseFormats = "json" | "geojson" | "text" | "html" | "image" | "zip"; | ||
/** | ||
* Options for the `request()` method. | ||
@@ -121,1 +91,24 @@ */ | ||
export declare function request(url: string, requestOptions?: IRequestOptions): Promise<any>; | ||
export declare class ArcGISAuthError extends ArcGISRequestError { | ||
/** | ||
* 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 | ||
*/ | ||
constructor(message?: string, code?: string | number, response?: any, url?: string, options?: IRequestOptions); | ||
retry(getSession: IRetryAuthError, retryLimit?: number): Promise<{}>; | ||
} | ||
/** | ||
* 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 | ||
*/ | ||
export declare function checkForErrors(response: any, url?: string, params?: IParams, options?: IRequestOptions): any; |
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
import * as tslib_1 from "tslib"; | ||
import { checkForErrors } from "./utils/check-for-errors"; | ||
import { encodeFormData } from "./utils/encode-form-data"; | ||
@@ -106,5 +105,9 @@ import { encodeQueryString } from "./utils/encode-query-string"; | ||
} | ||
fetchOptions.headers = {}; | ||
/* istanbul ignore next - karma reports coverage on browser tests only */ | ||
if (typeof window === "undefined") { | ||
fetchOptions.headers["referer"] = "@esri/arcgis-rest"; | ||
} | ||
/* 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"] = | ||
@@ -130,3 +133,3 @@ "application/x-www-form-urlencoded"; | ||
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 */ | ||
/* istanbul ignore next blob responses are difficult to make cross platform we will just have to trust that isomorphic fetch will do its job */ | ||
case "image": | ||
@@ -152,2 +155,94 @@ return response.blob(); | ||
} | ||
var ArcGISAuthError = /** @class */ (function (_super) { | ||
tslib_1.__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 = tslib_1.__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)); | ||
export { ArcGISAuthError }; | ||
/** | ||
* 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 | ||
*/ | ||
export 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; | ||
} | ||
//# sourceMappingURL=request.js.map |
@@ -16,3 +16,4 @@ /* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc. | ||
key !== "maxUrlLength" && | ||
key !== "endpoint") { | ||
key !== "endpoint" && | ||
key !== "decodeValues") { | ||
newOptions.params[key] = oldOptions[key]; | ||
@@ -19,0 +20,0 @@ } |
@@ -9,5 +9,4 @@ "use strict"; | ||
tslib_1.__exportStar(require("./utils/encode-query-string"), exports); | ||
tslib_1.__exportStar(require("./utils/check-for-errors"), exports); | ||
tslib_1.__exportStar(require("./utils/warn"), exports); | ||
tslib_1.__exportStar(require("./utils/ArcGISRequestError"), exports); | ||
tslib_1.__exportStar(require("./utils/ArcGISAuthError"), exports); | ||
tslib_1.__exportStar(require("./utils/ErrorTypes"), exports); | ||
@@ -14,0 +13,0 @@ tslib_1.__exportStar(require("./utils/process-params"), exports); |
@@ -6,3 +6,2 @@ "use strict"; | ||
var tslib_1 = require("tslib"); | ||
var check_for_errors_1 = require("./utils/check-for-errors"); | ||
var encode_form_data_1 = require("./utils/encode-form-data"); | ||
@@ -109,5 +108,9 @@ var encode_query_string_1 = require("./utils/encode-query-string"); | ||
} | ||
fetchOptions.headers = {}; | ||
/* istanbul ignore next - karma reports coverage on browser tests only */ | ||
if (typeof window === "undefined") { | ||
fetchOptions.headers["referer"] = "@esri/arcgis-rest"; | ||
} | ||
/* 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 (!process_params_1.requiresFormData(params)) { | ||
fetchOptions.headers = {}; | ||
fetchOptions.headers["Content-Type"] = | ||
@@ -133,3 +136,3 @@ "application/x-www-form-urlencoded"; | ||
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 */ | ||
/* istanbul ignore next blob responses are difficult to make cross platform we will just have to trust that isomorphic fetch will do its job */ | ||
case "image": | ||
@@ -148,3 +151,3 @@ return response.blob(); | ||
if (params.f === "json" || params.f === "geojson") { | ||
return check_for_errors_1.checkForErrors(data, url, params, options); | ||
return checkForErrors(data, url, params, options); | ||
} | ||
@@ -157,2 +160,95 @@ else { | ||
exports.request = request; | ||
var ArcGISAuthError = /** @class */ (function (_super) { | ||
tslib_1.__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 = tslib_1.__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_1.ArcGISRequestError)); | ||
exports.ArcGISAuthError = ArcGISAuthError; | ||
/** | ||
* 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_1.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_1.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_1.ArcGISRequestError(message, code, response, url, options); | ||
} | ||
return response; | ||
} | ||
exports.checkForErrors = checkForErrors; | ||
//# sourceMappingURL=request.js.map |
@@ -18,3 +18,4 @@ "use strict"; | ||
key !== "maxUrlLength" && | ||
key !== "endpoint") { | ||
key !== "endpoint" && | ||
key !== "decodeValues") { | ||
newOptions.params[key] = oldOptions[key]; | ||
@@ -21,0 +22,0 @@ } |
/* @preserve | ||
* @esri/arcgis-rest-request - v1.13.2 - Apache-2.0 | ||
* @esri/arcgis-rest-request - v1.14.0 - Apache-2.0 | ||
* Copyright (c) 2017-2018 Esri, Inc. | ||
* Fri Nov 02 2018 15:54:43 GMT-0700 (Pacific Daylight Time) | ||
* Wed Nov 14 2018 14:40:32 GMT-0800 (Pacific Standard Time) | ||
*/ | ||
@@ -28,5 +28,8 @@ (function (global, factory) { | ||
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 = function(d, b) { | ||
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]; }; | ||
return extendStatics(d, b); | ||
}; | ||
@@ -39,149 +42,14 @@ function __extends(d, b) { | ||
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; | ||
var __assign = function() { | ||
__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; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
/* 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; | ||
} | ||
/** | ||
* 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 */ | ||
@@ -329,2 +197,35 @@ /** | ||
/* 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-2018 Environmental Systems Research Institute, Inc. | ||
@@ -429,5 +330,9 @@ * Apache-2.0 */ | ||
} | ||
fetchOptions.headers = {}; | ||
/* istanbul ignore next - karma reports coverage on browser tests only */ | ||
if (typeof window === "undefined") { | ||
fetchOptions.headers["referer"] = "@esri/arcgis-rest"; | ||
} | ||
/* 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"] = | ||
@@ -453,3 +358,3 @@ "application/x-www-form-urlencoded"; | ||
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 */ | ||
/* istanbul ignore next blob responses are difficult to make cross platform we will just have to trust that isomorphic fetch will do its job */ | ||
case "image": | ||
@@ -475,3 +380,105 @@ return response.blob(); | ||
} | ||
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)); | ||
/** | ||
* 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; | ||
} | ||
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
/** | ||
* 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. | ||
@@ -545,3 +552,4 @@ * Apache-2.0 */ | ||
key !== "maxUrlLength" && | ||
key !== "endpoint") { | ||
key !== "endpoint" && | ||
key !== "decodeValues") { | ||
newOptions.params[key] = oldOptions[key]; | ||
@@ -556,9 +564,9 @@ } | ||
exports.request = request; | ||
exports.ArcGISAuthError = ArcGISAuthError; | ||
exports.checkForErrors = checkForErrors; | ||
exports.encodeFormData = encodeFormData; | ||
exports.encodeParam = encodeParam; | ||
exports.encodeQueryString = encodeQueryString; | ||
exports.checkForErrors = checkForErrors; | ||
exports.warn = warn; | ||
exports.ArcGISRequestError = ArcGISRequestError; | ||
exports.ArcGISAuthError = ArcGISAuthError; | ||
exports.requiresFormData = requiresFormData; | ||
@@ -565,0 +573,0 @@ exports.processParams = processParams; |
/* @preserve | ||
* @esri/arcgis-rest-request - v1.13.2 - Apache-2.0 | ||
* @esri/arcgis-rest-request - v1.14.0 - Apache-2.0 | ||
* Copyright (c) 2017-2018 Esri, Inc. | ||
* Fri Nov 02 2018 15:54:46 GMT-0700 (Pacific Daylight Time) | ||
* Wed Nov 14 2018 14:40:37 GMT-0800 (Pacific Standard 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})}); | ||
!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=function(e,r){return(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])})(e,r)};var r=function(){return(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}).apply(this,arguments)};function o(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 n(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 a(e,t){return encodeURIComponent(e)+"="+encodeURIComponent(t)}function s(e){var t=n(e);return Object.keys(t).map(function(e){return a(e,t[e])}).join("&")}function c(e){var t=o(e),r=n(e);if(t){var a=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;a.append(e,r[e],t)}else a.append(e,r[e])}),a}return s(e)}var i=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}}();function u(e,t){void 0===t&&(t={params:{f:"json"}});var n=r({httpMethod:"POST"},t),a=[],u=[];if(n.fetch||"undefined"==typeof fetch?(a.push("`fetch`"),u.push("`isomorphic-fetch`")):n.fetch=fetch.bind(Function("return this")()),"undefined"==typeof Promise&&(a.push("`Promise`"),u.push("`es6-promise`")),"undefined"==typeof FormData&&(a.push("`FormData`"),u.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 "+u.join(", ")+" modules at the root of your application to add these to the global scope. See https://bit.ly/2KNwWaJ for more info.");var f=n.httpMethod,h=n.authentication,d=r({f:"json"},t.params),l={method:f,credentials:"same-origin"};return(h?h.getToken(e,{fetch:n.fetch}):Promise.resolve("")).then(function(t){if(t.length&&(d.token=t),"GET"===l.method){var r=""===s(d)?e:e+"?"+s(d);n.maxUrlLength&&r.length>n.maxUrlLength?l.method="POST":e=r}return"POST"===l.method&&(l.body=c(d)),l.headers={},"undefined"==typeof window&&(l.headers.referer="@esri/arcgis-rest"),o(d)||(l.headers["Content-Type"]="application/x-www-form-urlencoded"),n.fetch(e,l)}).then(function(t){if(!t.ok){var r=t.status,o=t.statusText;throw new i(o,"HTTP "+r,t,e,n)}switch(d.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"===d.f||"geojson"===d.f?p(t,e,d,n):t})}i.prototype=Object.create(Error.prototype),i.prototype.constructor=i;var f,h=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,u(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}(i);function p(e,t,r,o){if(e.code>=400){var n=e.message,a=e.code;throw new i(n,a,e,t,o)}if(e.error){var s=e.error,c=(n=s.message,a=s.code,s.messageCode),u=c||a||"UNKNOWN_ERROR_CODE";if(498===a||499===a||"GWM_0003"===c)throw new h(n,u,e,t,o);throw new i(n,u,e,t,o)}if("failed"===e.status||"failure"===e.status){n=void 0,a="UNKNOWN_ERROR_CODE";try{n=JSON.parse(e.statusMessage).message,a=JSON.parse(e.statusMessage).code}catch(t){n=e.statusMessage||e.message}throw new i(n,a,e,t,o)}return e}function d(e){return void 0===e&&(e={}),e.portal?e.portal:e.authentication?e.authentication.portal:"https://www.arcgis.com/sharing/rest"}function l(e,t){var o=e||"self";return u(d(t)+"/portals/"+o,r({httpMethod:"GET"},t))}(f=e.ErrorTypes||(e.ErrorTypes={})).ArcGISRequestError="ArcGISRequestError",f.ArcGISAuthError="ArcGISAuthError",e.request=u,e.ArcGISAuthError=h,e.checkForErrors=p,e.encodeFormData=c,e.encodeParam=a,e.encodeQueryString=s,e.warn=function(e){console&&console.warn&&console.warn.apply(console,[e])},e.ArcGISRequestError=i,e.requiresFormData=o,e.processParams=n,e.getSelf=function(e){return l(null,e)},e.getPortal=l,e.getPortalUrl=d,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&&"decodeValues"!==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.2", | ||
"version": "1.14.0", | ||
"description": "Common methods and utilities for @esri/arcgis-rest-* packages.", | ||
@@ -5,0 +5,0 @@ "main": "dist/node/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
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
221330
76
1999
12