diff --git a/package.json b/package.json index 625d51a08a..2fcfcf7b6a 100644 --- a/package.json +++ b/package.json @@ -108,17 +108,87 @@ "release:prepare": "lerna publish --skip-git --skip-npm --yes && node ./support/changelog.js", "release:review": "git --no-pager diff --word-diff", "release:publish": "./support/publish.sh", - "c": "npm run precommit && git-cz" + "c": "git-cz" }, "repository": { "type": "git", "url": "git+https://github.com/Esri/arcgis-rest-js.git" }, "contributors": [ + { + "name": "Anthony Lukach" + }, + { + "name": "Bill Reynolds", + "email": "wreynolds@esri.com" + }, + { + "name": "City of Veronia GIS" + }, + { + "name": "Dave Bouwman", + "email": "dbouwman@esri.com" + }, + { + "name": "Enguerrand des Vaux" + }, + { + "name": "Gavin Rehkemper", + "email": "grehkemper@esri.com" + }, + { + "name": "Ian Trewella" + }, + { + "name": "Idi Eradiri", + "email": "ieradiri@esri.com" + }, + { + "name": "Jeff Jacobson" + }, + { + "name": "John Gravois", + "email": "john@esri.com" + }, + { + "name": "Junshan Liu", + "email": "jliu@esri.com" + }, + { + "name": "Max Payson", + "email": "mpayson@esri.com" + }, + { + "name": "Mike 'Jupe' Juniper", + "email": "mjuniper@esri.com" + }, + { + "name": "Mike Tschudi", + "email": "mtschudi@esri.com" + }, + { + "name": "Noah Mulfinger", + "email": "nmulfinger@esri.com" + }, { "name": "Patrick Arlt", "email": "parlt@esri.com", "url": "http://patrickarlt.com/" + }, + { + "name": "Richard Hincamp" + }, + { + "name": "Steven Kitterman", + "email": "skitterman@esri.com" + }, + { + "name": "Stephen Sylvia", + "email": "ssylvia@esri.com" + }, + { + "name": "Tom Wayson", + "email": "twayson@esri.com" } ], "license": "Apache-2.0", diff --git a/packages/arcgis-rest-feature-service/src/add.ts b/packages/arcgis-rest-feature-service/src/add.ts index 8ad262bcd5..3b276373a8 100644 --- a/packages/arcgis-rest-feature-service/src/add.ts +++ b/packages/arcgis-rest-feature-service/src/add.ts @@ -2,13 +2,12 @@ * Apache-2.0 */ import { IFeature } from "@esri/arcgis-rest-common-types"; -import { request, IRequestOptions } from "@esri/arcgis-rest-request"; - import { - IEditFeaturesParams, - IEditFeatureResult, + request, + IRequestOptions, appendCustomParams -} from "./helpers"; +} from "@esri/arcgis-rest-request"; +import { IEditFeaturesParams, IEditFeatureResult } from "./helpers"; /** * Add features request options. See the [REST Documentation](https://developers.arcgis.com/rest/services-reference/add-features.htm) for more information. diff --git a/packages/arcgis-rest-feature-service/src/addAttachment.ts b/packages/arcgis-rest-feature-service/src/addAttachment.ts index f92602122b..9a8f68fbd9 100644 --- a/packages/arcgis-rest-feature-service/src/addAttachment.ts +++ b/packages/arcgis-rest-feature-service/src/addAttachment.ts @@ -2,7 +2,6 @@ * Apache-2.0 */ import { request, IRequestOptions } from "@esri/arcgis-rest-request"; - import { IEditFeatureResult } from "./helpers"; /** diff --git a/packages/arcgis-rest-feature-service/src/delete.ts b/packages/arcgis-rest-feature-service/src/delete.ts index c4d32dc535..ad22b2e465 100644 --- a/packages/arcgis-rest-feature-service/src/delete.ts +++ b/packages/arcgis-rest-feature-service/src/delete.ts @@ -1,13 +1,15 @@ /* Copyright (c) 2017 Environmental Systems Research Institute, Inc. * Apache-2.0 */ -import { request, IRequestOptions } from "@esri/arcgis-rest-request"; - +import { + request, + IRequestOptions, + appendCustomParams +} from "@esri/arcgis-rest-request"; import { IEditFeaturesParams, IEditFeatureResult, - ISharedQueryParams, - appendCustomParams + ISharedQueryParams } from "./helpers"; /** diff --git a/packages/arcgis-rest-feature-service/src/deleteAttachments.ts b/packages/arcgis-rest-feature-service/src/deleteAttachments.ts index cd4279717b..a723bdfc9e 100644 --- a/packages/arcgis-rest-feature-service/src/deleteAttachments.ts +++ b/packages/arcgis-rest-feature-service/src/deleteAttachments.ts @@ -2,7 +2,6 @@ * Apache-2.0 */ import { request, IRequestOptions } from "@esri/arcgis-rest-request"; - import { IEditFeatureResult } from "./helpers"; /** diff --git a/packages/arcgis-rest-feature-service/src/helpers.ts b/packages/arcgis-rest-feature-service/src/helpers.ts index 350611abae..4c386f56a8 100644 --- a/packages/arcgis-rest-feature-service/src/helpers.ts +++ b/packages/arcgis-rest-feature-service/src/helpers.ts @@ -7,13 +7,6 @@ import { IGeometry, ISpatialReference } from "@esri/arcgis-rest-common-types"; -import { IRequestOptions } from "@esri/arcgis-rest-request"; - -import { IQueryFeaturesRequestOptions } from "./query"; -import { IAddFeaturesRequestOptions } from "./add"; -import { IUpdateFeaturesRequestOptions } from "./update"; -import { IDeleteFeaturesRequestOptions } from "./delete"; -import { IQueryRelatedRequestOptions } from "./queryRelated"; export interface ISharedQueryParams { where?: string; @@ -50,31 +43,3 @@ export interface IEditFeaturesParams { */ rollbackOnFailure?: boolean; } - -/** - * Used internally by the package to ensure that first order request options are passed through as request parameters. - */ -export function appendCustomParams( - oldOptions: - | IQueryFeaturesRequestOptions - | IAddFeaturesRequestOptions - | IUpdateFeaturesRequestOptions - | IDeleteFeaturesRequestOptions - | IQueryRelatedRequestOptions, - newOptions: IRequestOptions -) { - // only pass query parameters through in the request, not generic IRequestOptions props - Object.keys(oldOptions).forEach(function(key: string) { - if ( - key !== "url" && - key !== "params" && - key !== "authentication" && - key !== "httpMethod" && - key !== "fetch" && - key !== "portal" && - key !== "maxUrlLength" - ) { - newOptions.params[key] = (oldOptions as { [key: string]: any })[key]; - } - }); -} diff --git a/packages/arcgis-rest-feature-service/src/query.ts b/packages/arcgis-rest-feature-service/src/query.ts index 9ed5d0dee3..4434c679fb 100644 --- a/packages/arcgis-rest-feature-service/src/query.ts +++ b/packages/arcgis-rest-feature-service/src/query.ts @@ -1,6 +1,11 @@ /* Copyright (c) 2017 Environmental Systems Research Institute, Inc. * Apache-2.0 */ +import { + request, + IRequestOptions, + appendCustomParams +} from "@esri/arcgis-rest-request"; import { ISpatialReference, IFeatureSet, @@ -8,9 +13,8 @@ import { esriUnits, IExtent } from "@esri/arcgis-rest-common-types"; -import { request, IRequestOptions } from "@esri/arcgis-rest-request"; +import { ISharedQueryParams } from "./helpers"; -import { ISharedQueryParams, appendCustomParams } from "./helpers"; /** * Request options to fetch a feature by id. */ diff --git a/packages/arcgis-rest-feature-service/src/queryRelated.ts b/packages/arcgis-rest-feature-service/src/queryRelated.ts index c1e5cac340..d33ed8a81a 100644 --- a/packages/arcgis-rest-feature-service/src/queryRelated.ts +++ b/packages/arcgis-rest-feature-service/src/queryRelated.ts @@ -1,6 +1,11 @@ /* Copyright (c) 2018 Environmental Systems Research Institute, Inc. * Apache-2.0 */ +import { + request, + IRequestOptions, + appendCustomParams +} from "@esri/arcgis-rest-request"; import { ISpatialReference, IFeature, @@ -8,8 +13,6 @@ import { esriGeometryType, IField } from "@esri/arcgis-rest-common-types"; -import { request, IRequestOptions } from "@esri/arcgis-rest-request"; -import { appendCustomParams } from "./helpers"; /** * Related record query request options. Additional arguments can be passed via the [params](/arcgis-rest-js/api/feature-service/IQueryRelatedRequestOptions/#params) property. See the [REST Documentation](https://developers.arcgis.com/rest/services-reference/query-related-feature-service-.htm) for more information and a full list of parameters. diff --git a/packages/arcgis-rest-feature-service/src/update.ts b/packages/arcgis-rest-feature-service/src/update.ts index 4ab983b18c..750a9fa15c 100644 --- a/packages/arcgis-rest-feature-service/src/update.ts +++ b/packages/arcgis-rest-feature-service/src/update.ts @@ -2,13 +2,12 @@ * Apache-2.0 */ import { IFeature } from "@esri/arcgis-rest-common-types"; -import { request, IRequestOptions } from "@esri/arcgis-rest-request"; - import { - IEditFeaturesParams, - IEditFeatureResult, + request, + IRequestOptions, appendCustomParams -} from "./helpers"; +} from "@esri/arcgis-rest-request"; +import { IEditFeaturesParams, IEditFeatureResult } from "./helpers"; /** * Update features request options. See the [REST Documentation](https://developers.arcgis.com/rest/services-reference/update-features.htm) for more information. diff --git a/packages/arcgis-rest-feature-service/src/updateAttachment.ts b/packages/arcgis-rest-feature-service/src/updateAttachment.ts index b0db27ae0f..58cd0aecad 100644 --- a/packages/arcgis-rest-feature-service/src/updateAttachment.ts +++ b/packages/arcgis-rest-feature-service/src/updateAttachment.ts @@ -2,7 +2,6 @@ * Apache-2.0 */ import { request, IRequestOptions } from "@esri/arcgis-rest-request"; - import { IEditFeatureResult } from "./helpers"; /** diff --git a/packages/arcgis-rest-geocoder/src/geocode.ts b/packages/arcgis-rest-geocoder/src/geocode.ts index 1c6bdf333e..50f53c37c5 100644 --- a/packages/arcgis-rest-geocoder/src/geocode.ts +++ b/packages/arcgis-rest-geocoder/src/geocode.ts @@ -1,7 +1,11 @@ /* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc. * Apache-2.0 */ -import { request, IParams } from "@esri/arcgis-rest-request"; +import { + request, + IParams, + appendCustomParams +} from "@esri/arcgis-rest-request"; import { IExtent, @@ -27,6 +31,10 @@ export interface IGeocodeParams extends IParams { } export interface IGeocodeRequestOptions extends IEndpointRequestOptions { + /** + * use this if all your address info is contained in a single string. + */ + singleLine?: string; address?: string; address2?: string; address3?: string; @@ -53,25 +61,23 @@ export interface IGeocodeResponse { } /** - * Used to determine the [location](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-find-address-candidates.htm) of a single address or point of interest. + * Used to determine the location of a single address or point of interest. See the [REST Documentation](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-find-address-candidates.htm) for more information. * * ```js * import { geocode } from '@esri/arcgis-rest-geocoder'; * * geocode("LAX") * .then((response) => { - * response.candidates[0].location; // => { x: -118.409, y: 33.943, spatialReference: { wkid: 4326 } } + * response.candidates[0].location; // => { x: -118.409, y: 33.943, spatialReference: ... } * }); * * geocode({ - * params: { - * address: "1600 Pennsylvania Ave", - * postal: 20500, - * countryCode: "USA" - * } + * address: "1600 Pennsylvania Ave", + * postal: 20500, + * countryCode: "USA" * }) * .then((response) => { - * response.candidates[0].location; // => { x: -77.036533, y: 38.898719, spatialReference: { wkid: 4326 } } + * response.candidates[0].location; // => { x: -77.036533, y: 38.898719, spatialReference: ... } * }); * ``` * @@ -94,6 +100,8 @@ export function geocode( ...options, ...address }; + + appendCustomParams(address, options); } // add spatialReference property to individual matches diff --git a/packages/arcgis-rest-geocoder/src/suggest.ts b/packages/arcgis-rest-geocoder/src/suggest.ts index b2449e833a..3e8bbe6f37 100644 --- a/packages/arcgis-rest-geocoder/src/suggest.ts +++ b/packages/arcgis-rest-geocoder/src/suggest.ts @@ -49,21 +49,16 @@ export function suggest( ): Promise { const options: ISuggestRequestOptions = { endpoint: worldGeocoder, - params: {}, + params: { text: partialText }, ...requestOptions }; - // is this the most concise way to mixin these optional parameters? - if (requestOptions && requestOptions.params) { - options.params = requestOptions.params; - } + options.params.text = partialText; if (requestOptions && requestOptions.magicKey) { options.params.magicKey = requestOptions.magicKey; } - options.params.text = partialText; - return request(options.endpoint + "suggest", options); } diff --git a/packages/arcgis-rest-geocoder/test/geocode.test.ts b/packages/arcgis-rest-geocoder/test/geocode.test.ts index d2a6472d76..9964ad1fc3 100644 --- a/packages/arcgis-rest-geocoder/test/geocode.test.ts +++ b/packages/arcgis-rest-geocoder/test/geocode.test.ts @@ -35,6 +35,33 @@ describe("geocode", () => { }); }); + it("should a geocoding request with custom parameters", done => { + fetchMock.once("*", FindAddressCandidates); + + geocode({ address: "1600 Pennsylvania Avenue", city: "Washington D.C." }) + .then(response => { + expect(fetchMock.called()).toEqual(true); + const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); + expect(url).toEqual( + "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates" + ); + expect(options.method).toBe("POST"); + expect(options.body).toContain("f=json"); + expect(options.body).toContain( + `address=${encodeURIComponent("1600 Pennsylvania Avenue")}` + ); + expect(options.body).toContain( + `city=${encodeURIComponent("Washington D.C.")}` + ); + // the only property this lib tacks on + expect(response.spatialReference.wkid).toEqual(4326); + done(); + }) + .catch(e => { + fail(e); + }); + }); + it("should make a simple, single geocoding request with a custom parameter", done => { fetchMock.once("*", FindAddressCandidates); diff --git a/packages/arcgis-rest-geocoder/test/helpers.test.ts b/packages/arcgis-rest-geocoder/test/helpers.test.ts index fd3f3da6b1..b5f13c53b8 100644 --- a/packages/arcgis-rest-geocoder/test/helpers.test.ts +++ b/packages/arcgis-rest-geocoder/test/helpers.test.ts @@ -2,9 +2,7 @@ * Apache-2.0 */ import { serviceInfo, getGeocodeService } from "../src/helpers"; - import * as fetchMock from "fetch-mock"; - import { SharingInfo } from "./mocks/responses"; const customGeocoderUrl = diff --git a/packages/arcgis-rest-geocoder/test/suggest.test.ts b/packages/arcgis-rest-geocoder/test/suggest.test.ts index de1abbda83..c942e2da15 100644 --- a/packages/arcgis-rest-geocoder/test/suggest.test.ts +++ b/packages/arcgis-rest-geocoder/test/suggest.test.ts @@ -2,9 +2,7 @@ * Apache-2.0 */ import { suggest } from "../src/suggest"; - import * as fetchMock from "fetch-mock"; - import { Suggest } from "./mocks/responses"; describe("geocode", () => { @@ -74,4 +72,27 @@ describe("geocode", () => { fail(e); }); }); + + it("should make a request for suggestions with magic key and other parameters", done => { + fetchMock.once("*", Suggest); + + suggest("LAX", { magicKey: "foo", params: { category: "Address,Postal" } }) + .then(response => { + expect(fetchMock.called()).toEqual(true); + const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); + expect(url).toEqual( + "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest" + ); + expect(options.method).toBe("POST"); + expect(options.body).toContain("f=json"); + expect(options.body).toContain("text=LAX"); + expect(options.body).toContain("magicKey=foo"); + expect(options.body).toContain("category=Address%2CPostal"); + expect(response).toEqual(Suggest); // this introspects the entire response + done(); + }) + .catch(e => { + fail(e); + }); + }); }); diff --git a/packages/arcgis-rest-request/src/index.ts b/packages/arcgis-rest-request/src/index.ts index 89934c21d8..1c83a1adac 100644 --- a/packages/arcgis-rest-request/src/index.ts +++ b/packages/arcgis-rest-request/src/index.ts @@ -11,3 +11,4 @@ export * from "./utils/ErrorTypes"; export * from "./utils/process-params"; export * from "./utils/get-portal"; export * from "./utils/get-portal-url"; +export * from "./utils/append-custom-params"; diff --git a/packages/arcgis-rest-request/src/utils/append-custom-params.ts b/packages/arcgis-rest-request/src/utils/append-custom-params.ts new file mode 100644 index 0000000000..8a0d073549 --- /dev/null +++ b/packages/arcgis-rest-request/src/utils/append-custom-params.ts @@ -0,0 +1,28 @@ +/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc. + * Apache-2.0 */ + +import { IRequestOptions } from "../request"; + +/** + * Helper for methods with lots of first order request options to pass them through as request parameters. + */ +export function appendCustomParams( + oldOptions: IRequestOptions, + newOptions: IRequestOptions +) { + // only pass query parameters through in the request, not generic IRequestOptions props + Object.keys(oldOptions).forEach(function(key: string) { + if ( + key !== "url" && + key !== "params" && + key !== "authentication" && + key !== "httpMethod" && + key !== "fetch" && + key !== "portal" && + key !== "maxUrlLength" && + key !== "endpoint" + ) { + newOptions.params[key] = (oldOptions as { [key: string]: any })[key]; + } + }); +}