etincidunt 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (226) hide show
  1. package/.prettierignore +2 -0
  2. package/.travis.yml +29 -0
  3. package/.vscode/launch.json +24 -0
  4. package/.vscode/settings.json +3 -0
  5. package/demos/ago-node-cli/README.md +29 -0
  6. package/demos/ago-node-cli/ago.js +32 -0
  7. package/demos/ago-node-cli/index.js +11 -0
  8. package/demos/ago-node-cli/lib/item-export-command.js +48 -0
  9. package/demos/ago-node-cli/lib/item-search-command.js +35 -0
  10. package/demos/ago-node-cli/package-lock.json +172 -0
  11. package/demos/ago-node-cli/package.json +30 -0
  12. package/demos/attachments/README.md +5 -0
  13. package/demos/attachments/index.html +164 -0
  14. package/demos/attachments/package-lock.json +182 -0
  15. package/demos/attachments/package.json +18 -0
  16. package/demos/batch-geocoder-node/NYC_Restaurant_Inspection_Results.csv +100 -0
  17. package/demos/batch-geocoder-node/README.md +14 -0
  18. package/demos/batch-geocoder-node/batch-geocode.js +112 -0
  19. package/demos/batch-geocoder-node/config-template.js +18 -0
  20. package/demos/batch-geocoder-node/package-lock.json +109 -0
  21. package/demos/batch-geocoder-node/package.json +37 -0
  22. package/demos/express/README.md +10 -0
  23. package/demos/express/config.json.template +3 -0
  24. package/demos/express/package-lock.json +388 -0
  25. package/demos/express/package.json +18 -0
  26. package/demos/express/server.js +28 -0
  27. package/demos/feature-service-browser/README.md +6 -0
  28. package/demos/feature-service-browser/index.html +122 -0
  29. package/demos/feature-service-browser/package-lock.json +182 -0
  30. package/demos/feature-service-browser/package.json +18 -0
  31. package/demos/geocoder-browser/README.md +10 -0
  32. package/demos/geocoder-browser/config.js.template +1 -0
  33. package/demos/geocoder-browser/index.html +131 -0
  34. package/demos/geocoder-browser/package-lock.json +163 -0
  35. package/demos/geocoder-browser/package.json +19 -0
  36. package/demos/geocoder-browser/post-sign-in.html +25 -0
  37. package/demos/jsapi-integration/README.md +8 -0
  38. package/demos/jsapi-integration/config.js +6 -0
  39. package/demos/jsapi-integration/index.html +79 -0
  40. package/demos/jsapi-integration/package-lock.json +184 -0
  41. package/demos/jsapi-integration/package.json +19 -0
  42. package/demos/oauth2-browser/README.md +12 -0
  43. package/demos/oauth2-browser/authenticate.html +32 -0
  44. package/demos/oauth2-browser/config.js.template +6 -0
  45. package/demos/oauth2-browser/index.html +202 -0
  46. package/demos/oauth2-browser/logo.svg +4 -0
  47. package/demos/oauth2-browser/package-lock.json +163 -0
  48. package/demos/oauth2-browser/package.json +18 -0
  49. package/demos/oauth2-browser/style.css +36 -0
  50. package/demos/vue/.babelrc +6 -0
  51. package/demos/vue/.env.example +8 -0
  52. package/demos/vue/README.md +17 -0
  53. package/demos/vue/index.html +21 -0
  54. package/demos/vue/package-lock.json +7236 -0
  55. package/demos/vue/package.json +39 -0
  56. package/demos/vue/src/assets/logo.svg +29 -0
  57. package/demos/vue/src/components/App.vue +302 -0
  58. package/demos/vue/src/components/Authenticate.vue +68 -0
  59. package/demos/vue/src/components/Loader.vue +216 -0
  60. package/demos/vue/src/main.js +75 -0
  61. package/demos/vue/webpack.config.js +84 -0
  62. package/docs/FAQ.md +28 -0
  63. package/docs/HISTORY.md +62 -0
  64. package/docs/acetate.config.js +214 -0
  65. package/docs/build-typedoc.js +301 -0
  66. package/docs/src/_layout.html +82 -0
  67. package/docs/src/api/_declaration.html +496 -0
  68. package/docs/src/api/_layout.html +127 -0
  69. package/docs/src/api/_package.html +13 -0
  70. package/docs/src/api/index.html +23 -0
  71. package/docs/src/guides/_layout.html +24 -0
  72. package/docs/src/guides/amd-requirejs-dojo.md +40 -0
  73. package/docs/src/guides/babel-and-rollup.md +30 -0
  74. package/docs/src/guides/babel-and-webpack.md +30 -0
  75. package/docs/src/guides/browser-authentication.md +9 -0
  76. package/docs/src/guides/browserify.md +9 -0
  77. package/docs/src/guides/cli-authentication.md +9 -0
  78. package/docs/src/guides/client-server-authentication.md +9 -0
  79. package/docs/src/guides/from-a-cdn.md +36 -0
  80. package/docs/src/guides/index.md +52 -0
  81. package/docs/src/guides/node.md +30 -0
  82. package/docs/src/guides/package-overview.md +8 -0
  83. package/docs/src/guides/server-authentication.md +9 -0
  84. package/docs/src/guides/typescript-and-webpack.md +9 -0
  85. package/docs/src/img/icons.png +0 -0
  86. package/docs/src/img/icons@2x.png +0 -0
  87. package/docs/src/index.html +12 -0
  88. package/docs/src/js/api-search.js +113 -0
  89. package/docs/src/js/index.js +1 -0
  90. package/docs/src/js/nav-toggle.js +41 -0
  91. package/docs/src/sass/_highlight.scss +96 -0
  92. package/docs/src/sass/_icons.scss +157 -0
  93. package/docs/src/sass/style.scss +169 -0
  94. package/jasmine.json +7 -0
  95. package/karma.conf.js +100 -0
  96. package/lerna.json +8 -0
  97. package/notes/README.md +88 -0
  98. package/package.json +91 -0
  99. package/packages/arcgis-rest-auth/README.md +64 -0
  100. package/packages/arcgis-rest-auth/package-lock.json +11 -0
  101. package/packages/arcgis-rest-auth/package.json +51 -0
  102. package/packages/arcgis-rest-auth/src/ApplicationSession.ts +91 -0
  103. package/packages/arcgis-rest-auth/src/UserSession.ts +829 -0
  104. package/packages/arcgis-rest-auth/src/authenticated-request-options.ts +21 -0
  105. package/packages/arcgis-rest-auth/src/fetch-token.ts +55 -0
  106. package/packages/arcgis-rest-auth/src/generate-token.ts +36 -0
  107. package/packages/arcgis-rest-auth/src/index.ts +5 -0
  108. package/packages/arcgis-rest-auth/test/ApplicationSession.test.ts +121 -0
  109. package/packages/arcgis-rest-auth/test/UserSession.test.ts +883 -0
  110. package/packages/arcgis-rest-auth/test/fetchToken.test.ts +76 -0
  111. package/packages/arcgis-rest-auth/test/generateToken.test.ts +36 -0
  112. package/packages/arcgis-rest-auth/test/utils.ts +11 -0
  113. package/packages/arcgis-rest-auth/tsconfig.json +6 -0
  114. package/packages/arcgis-rest-common-types/README.md +61 -0
  115. package/packages/arcgis-rest-common-types/package.json +38 -0
  116. package/packages/arcgis-rest-common-types/src/group.ts +51 -0
  117. package/packages/arcgis-rest-common-types/src/index.ts +467 -0
  118. package/packages/arcgis-rest-common-types/src/item.ts +45 -0
  119. package/packages/arcgis-rest-common-types/src/webmap.ts +1225 -0
  120. package/packages/arcgis-rest-common-types/tsconfig.json +11 -0
  121. package/packages/arcgis-rest-feature-service/README.md +70 -0
  122. package/packages/arcgis-rest-feature-service/package-lock.json +11 -0
  123. package/packages/arcgis-rest-feature-service/package.json +50 -0
  124. package/packages/arcgis-rest-feature-service/src/add.ts +82 -0
  125. package/packages/arcgis-rest-feature-service/src/addAttachment.ts +65 -0
  126. package/packages/arcgis-rest-feature-service/src/delete.ts +85 -0
  127. package/packages/arcgis-rest-feature-service/src/deleteAttachments.ts +68 -0
  128. package/packages/arcgis-rest-feature-service/src/getAttachments.ts +64 -0
  129. package/packages/arcgis-rest-feature-service/src/helpers.ts +77 -0
  130. package/packages/arcgis-rest-feature-service/src/index.ts +8 -0
  131. package/packages/arcgis-rest-feature-service/src/query.ts +174 -0
  132. package/packages/arcgis-rest-feature-service/src/update.ts +81 -0
  133. package/packages/arcgis-rest-feature-service/src/updateAttachment.ts +74 -0
  134. package/packages/arcgis-rest-feature-service/test/attachments.test.ts +179 -0
  135. package/packages/arcgis-rest-feature-service/test/features.test.ts +172 -0
  136. package/packages/arcgis-rest-feature-service/test/mocks/feature.ts +220 -0
  137. package/packages/arcgis-rest-feature-service/test/mocks/foo.txt +1 -0
  138. package/packages/arcgis-rest-feature-service/tsconfig.json +6 -0
  139. package/packages/arcgis-rest-geocoder/README.md +73 -0
  140. package/packages/arcgis-rest-geocoder/package-lock.json +11 -0
  141. package/packages/arcgis-rest-geocoder/package.json +52 -0
  142. package/packages/arcgis-rest-geocoder/src/bulk.ts +102 -0
  143. package/packages/arcgis-rest-geocoder/src/geocode.ts +117 -0
  144. package/packages/arcgis-rest-geocoder/src/helpers.ts +81 -0
  145. package/packages/arcgis-rest-geocoder/src/index.ts +4 -0
  146. package/packages/arcgis-rest-geocoder/src/reverse.ts +84 -0
  147. package/packages/arcgis-rest-geocoder/src/suggest.ts +72 -0
  148. package/packages/arcgis-rest-geocoder/test/geocoder.test.ts +510 -0
  149. package/packages/arcgis-rest-geocoder/test/mocks/responses.ts +588 -0
  150. package/packages/arcgis-rest-geocoder/tsconfig.json +6 -0
  151. package/packages/arcgis-rest-groups/README.md +64 -0
  152. package/packages/arcgis-rest-groups/package-lock.json +11 -0
  153. package/packages/arcgis-rest-groups/package.json +52 -0
  154. package/packages/arcgis-rest-groups/src/groups.ts +272 -0
  155. package/packages/arcgis-rest-groups/src/index.ts +1 -0
  156. package/packages/arcgis-rest-groups/test/groups.test.ts +280 -0
  157. package/packages/arcgis-rest-groups/test/mocks/responses.ts +137 -0
  158. package/packages/arcgis-rest-groups/tsconfig.json +6 -0
  159. package/packages/arcgis-rest-items/README.md +66 -0
  160. package/packages/arcgis-rest-items/package-lock.json +11 -0
  161. package/packages/arcgis-rest-items/package.json +52 -0
  162. package/packages/arcgis-rest-items/src/index.ts +1 -0
  163. package/packages/arcgis-rest-items/src/items.ts +498 -0
  164. package/packages/arcgis-rest-items/test/items.test.ts +1153 -0
  165. package/packages/arcgis-rest-items/test/mocks/foo.zip +0 -0
  166. package/packages/arcgis-rest-items/test/mocks/item.ts +30 -0
  167. package/packages/arcgis-rest-items/test/mocks/resources.ts +28 -0
  168. package/packages/arcgis-rest-items/test/mocks/search.ts +60 -0
  169. package/packages/arcgis-rest-items/tsconfig.json +6 -0
  170. package/packages/arcgis-rest-request/README.md +65 -0
  171. package/packages/arcgis-rest-request/package-lock.json +11 -0
  172. package/packages/arcgis-rest-request/package.json +42 -0
  173. package/packages/arcgis-rest-request/src/index.ts +10 -0
  174. package/packages/arcgis-rest-request/src/request.ts +259 -0
  175. package/packages/arcgis-rest-request/src/utils/ArcGISAuthError.ts +67 -0
  176. package/packages/arcgis-rest-request/src/utils/ArcGISRequestError.ts +73 -0
  177. package/packages/arcgis-rest-request/src/utils/ErrorTypes.ts +29 -0
  178. package/packages/arcgis-rest-request/src/utils/check-for-errors.ts +65 -0
  179. package/packages/arcgis-rest-request/src/utils/encode-form-data.ts +29 -0
  180. package/packages/arcgis-rest-request/src/utils/encode-query-string.ts +23 -0
  181. package/packages/arcgis-rest-request/src/utils/get-portal-url.ts +25 -0
  182. package/packages/arcgis-rest-request/src/utils/get-portal.ts +45 -0
  183. package/packages/arcgis-rest-request/src/utils/process-params.ts +99 -0
  184. package/packages/arcgis-rest-request/test/mocks/errors.ts +59 -0
  185. package/packages/arcgis-rest-request/test/mocks/geojson-feature-collection.ts +10 -0
  186. package/packages/arcgis-rest-request/test/mocks/portal.ts +109 -0
  187. package/packages/arcgis-rest-request/test/mocks/sharing-rest-info.ts +38 -0
  188. package/packages/arcgis-rest-request/test/mocks/webmap.ts +38 -0
  189. package/packages/arcgis-rest-request/test/request.test.ts +296 -0
  190. package/packages/arcgis-rest-request/test/utils/ArcGISAuthError.test.ts +167 -0
  191. package/packages/arcgis-rest-request/test/utils/ArcGISRequestError.test.ts +40 -0
  192. package/packages/arcgis-rest-request/test/utils/check-for-errors.test.ts +101 -0
  193. package/packages/arcgis-rest-request/test/utils/encode-form-data.test.ts +112 -0
  194. package/packages/arcgis-rest-request/test/utils/get-portal-url.test.ts +34 -0
  195. package/packages/arcgis-rest-request/test/utils/portal.test.ts +94 -0
  196. package/packages/arcgis-rest-request/test/utils/process-params.test.ts +190 -0
  197. package/packages/arcgis-rest-request/tsconfig.json +6 -0
  198. package/packages/arcgis-rest-sharing/README.md +67 -0
  199. package/packages/arcgis-rest-sharing/package-lock.json +11 -0
  200. package/packages/arcgis-rest-sharing/package.json +55 -0
  201. package/packages/arcgis-rest-sharing/src/access.ts +91 -0
  202. package/packages/arcgis-rest-sharing/src/group-sharing.ts +212 -0
  203. package/packages/arcgis-rest-sharing/src/helpers.ts +92 -0
  204. package/packages/arcgis-rest-sharing/src/index.ts +2 -0
  205. package/packages/arcgis-rest-sharing/test/access.test.ts +153 -0
  206. package/packages/arcgis-rest-sharing/test/group-sharing.test.ts +436 -0
  207. package/packages/arcgis-rest-sharing/test/mocks/sharing.ts +15 -0
  208. package/packages/arcgis-rest-sharing/tsconfig.json +6 -0
  209. package/packages/arcgis-rest-users/README.md +71 -0
  210. package/packages/arcgis-rest-users/package-lock.json +11 -0
  211. package/packages/arcgis-rest-users/package.json +51 -0
  212. package/packages/arcgis-rest-users/src/index.ts +1 -0
  213. package/packages/arcgis-rest-users/src/users.ts +70 -0
  214. package/packages/arcgis-rest-users/test/mocks/responses.ts +170 -0
  215. package/packages/arcgis-rest-users/test/users.test.ts +97 -0
  216. package/packages/arcgis-rest-users/tsconfig.json +6 -0
  217. package/support/FormData.d.ts +1 -0
  218. package/support/changelog.js +388 -0
  219. package/support/commit-template.txt +19 -0
  220. package/support/deploy-doc-site.js +16 -0
  221. package/support/publish.sh +40 -0
  222. package/support/test-helpers.js +8 -0
  223. package/tsconfig.json +69 -0
  224. package/tslint.json +14 -0
  225. package/umd-base-profile.js +82 -0
  226. package/umd-production-profile.js +13 -0
@@ -0,0 +1,84 @@
1
+ /* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
2
+ * Apache-2.0 */
3
+
4
+ import { request } from "@esri/arcgis-rest-request";
5
+
6
+ import { IPoint } from "@esri/arcgis-rest-common-types";
7
+
8
+ import { worldGeocoder, ILocation, IEndpointRequestOptions } from "./helpers";
9
+
10
+ export interface IReverseGeocodeResponse {
11
+ address: {
12
+ [key: string]: any;
13
+ };
14
+ location: IPoint;
15
+ }
16
+
17
+ function isLocationArray(
18
+ coords: ILocation | IPoint | [number, number]
19
+ ): coords is [number, number] {
20
+ return (coords as [number, number]).length === 2;
21
+ }
22
+
23
+ function isLocation(
24
+ coords: ILocation | IPoint | [number, number]
25
+ ): coords is ILocation {
26
+ return (
27
+ (coords as ILocation).latitude !== undefined ||
28
+ (coords as ILocation).lat !== undefined
29
+ );
30
+ }
31
+
32
+ /**
33
+ * Used to determine the address of a location.
34
+ *
35
+ * ```js
36
+ * import { reverseGeocode } from '@esri/arcgis-rest-geocoder';
37
+ *
38
+ * // long, lat
39
+ * reverseGeocode([-118.409,33.943 ])
40
+ * .then((response) => {
41
+ * response.address.PlaceName; // => "LA Airport"
42
+ * });
43
+ *
44
+ * // or
45
+ * reverseGeocode({ long: -118.409, lat: 33.943 })
46
+ * reverseGeocode({ latitude: 33.943, latitude: -118.409 })
47
+ * reverseGeocode({ x: -118.409, y: 33.9425 }) // wgs84 is assumed
48
+ * reverseGeocode({ x: -13181226, y: 4021085, spatialReference: { wkid: 3857 })
49
+ * ```
50
+ *
51
+ * @param coordinates - the location you'd like to associate an address with.
52
+ * @param requestOptions - Additional options for the request including authentication.
53
+ * @returns A Promise that will resolve with the data from the response.
54
+ */
55
+ export function reverseGeocode(
56
+ coords: IPoint | ILocation | [number, number],
57
+ requestOptions?: IEndpointRequestOptions
58
+ ): Promise<IReverseGeocodeResponse> {
59
+ const options: IEndpointRequestOptions = {
60
+ endpoint: worldGeocoder,
61
+ params: {},
62
+ ...requestOptions
63
+ };
64
+
65
+ if (isLocationArray(coords)) {
66
+ options.params.location = coords.join();
67
+ } else if (isLocation(coords)) {
68
+ if (coords.lat) {
69
+ options.params.location = coords.long + "," + coords.lat;
70
+ }
71
+ if (coords.latitude) {
72
+ options.params.location = coords.longitude + "," + coords.latitude;
73
+ }
74
+ } else {
75
+ // if input is a point, we can pass it straight through, with or without a spatial reference
76
+ options.params.location = coords;
77
+ }
78
+
79
+ return request(options.endpoint + "reverseGeocode", options);
80
+ }
81
+
82
+ export default {
83
+ reverseGeocode
84
+ };
@@ -0,0 +1,72 @@
1
+ /* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
2
+ * Apache-2.0 */
3
+
4
+ import { request } from "@esri/arcgis-rest-request";
5
+
6
+ import { worldGeocoder, IEndpointRequestOptions } from "./helpers";
7
+
8
+ export interface ISuggestRequestOptions extends IEndpointRequestOptions {
9
+ /**
10
+ * You can create an autocomplete experience by making a call to suggest with partial text and then passing through the magicKey and complete address that are returned to geocode.
11
+ * ```js
12
+ * import { suggest, geocode } from '@esri/arcgis-rest-geocoder';
13
+ * suggest("LAX")
14
+ * .then((response) => {
15
+ * response.suggestions[2].magicKey; // => "dHA9MCNsb2M9Mjk3ODc2MCNsbmc9MzMjcGw9ODkxNDg4I2xicz0xNDoxNDc4MTI1MA=="
16
+ * });
17
+ * geocode("LAX, 1 World Way, Los Angeles, CA, 90045, USA", {magicKey: "dHA9MCN..."})
18
+ * ```
19
+ */
20
+ magicKey?: string;
21
+ }
22
+
23
+ export interface ISuggestResponse {
24
+ suggestions: Array<{
25
+ text: string;
26
+ magicKey: string;
27
+ isCollection: boolean;
28
+ }>;
29
+ }
30
+
31
+ /**
32
+ * Used to return a placename suggestion for a partial string
33
+ *
34
+ * ```js
35
+ * import { suggest } from '@esri/arcgis-rest-geocoder';
36
+ *
37
+ * suggest("Starb")
38
+ * .then((response) => {
39
+ * response.address.PlaceName; // => "Starbucks"
40
+ * });
41
+ * ```
42
+ *
43
+ * @param requestOptions - Options for the request including authentication and other optional parameters.
44
+ * @returns A Promise that will resolve with the data from the response.
45
+ */
46
+ export function suggest(
47
+ partialText: string,
48
+ requestOptions?: ISuggestRequestOptions
49
+ ): Promise<ISuggestResponse> {
50
+ const options: ISuggestRequestOptions = {
51
+ endpoint: worldGeocoder,
52
+ params: {},
53
+ ...requestOptions
54
+ };
55
+
56
+ // is this the most concise way to mixin these optional parameters?
57
+ if (requestOptions && requestOptions.params) {
58
+ options.params = requestOptions.params;
59
+ }
60
+
61
+ if (requestOptions && requestOptions.magicKey) {
62
+ options.params.magicKey = requestOptions.magicKey;
63
+ }
64
+
65
+ options.params.text = partialText;
66
+
67
+ return request(options.endpoint + "suggest", options);
68
+ }
69
+
70
+ export default {
71
+ suggest
72
+ };
@@ -0,0 +1,510 @@
1
+ import { geocode } from "../src/geocode";
2
+
3
+ import { suggest } from "../src/suggest";
4
+
5
+ import { reverseGeocode } from "../src/reverse";
6
+
7
+ import { bulkGeocode } from "../src/bulk";
8
+
9
+ import { serviceInfo, getGeocodeService } from "../src/helpers";
10
+
11
+ import * as fetchMock from "fetch-mock";
12
+
13
+ import {
14
+ FindAddressCandidates,
15
+ Suggest,
16
+ ReverseGeocode,
17
+ GeocodeAddresses,
18
+ SharingInfo
19
+ } from "./mocks/responses";
20
+
21
+ const addresses = [
22
+ {
23
+ OBJECTID: 1,
24
+ SingleLine: "380 New York St. Redlands 92373"
25
+ },
26
+ {
27
+ OBJECTID: 2,
28
+ SingleLine: "1 World Way Los Angeles 90045"
29
+ }
30
+ ];
31
+
32
+ const customGeocoderUrl =
33
+ "https://foo.com/arcgis/rest/services/Custom/GeocodeServer/";
34
+
35
+ describe("geocode", () => {
36
+ afterEach(fetchMock.restore);
37
+
38
+ it("should make a simple, single geocoding request", done => {
39
+ fetchMock.once("*", FindAddressCandidates);
40
+
41
+ geocode("LAX")
42
+ .then(response => {
43
+ expect(fetchMock.called()).toEqual(true);
44
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
45
+ expect(url).toEqual(
46
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates"
47
+ );
48
+ expect(options.method).toBe("POST");
49
+ expect(options.body).toContain("f=json");
50
+ expect(options.body).toContain("singleLine=LAX");
51
+ // the only property this lib tacks on
52
+ expect(response.spatialReference.wkid).toEqual(4326);
53
+ done();
54
+ })
55
+ .catch(e => {
56
+ fail(e);
57
+ });
58
+ });
59
+
60
+ it("should make a simple, single geocoding request with a custom parameter", done => {
61
+ fetchMock.once("*", FindAddressCandidates);
62
+
63
+ geocode({ params: { singleLine: "LAX", countryCode: "USA" } })
64
+ .then(response => {
65
+ expect(fetchMock.called()).toEqual(true);
66
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
67
+ expect(url).toEqual(
68
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates"
69
+ );
70
+ expect(options.method).toBe("POST");
71
+ expect(options.body).toContain("f=json");
72
+ expect(options.body).toContain("singleLine=LAX");
73
+ expect(options.body).toContain("countryCode=USA");
74
+ // the only property this lib tacks on
75
+ expect(response.spatialReference.wkid).toEqual(4326);
76
+ done();
77
+ })
78
+ .catch(e => {
79
+ fail(e);
80
+ });
81
+ });
82
+
83
+ it("should make a single geocoding request to a custom geocoding service", done => {
84
+ fetchMock.once("*", FindAddressCandidates);
85
+
86
+ geocode({
87
+ endpoint: customGeocoderUrl,
88
+ params: {
89
+ outSr: 3857,
90
+ address: "380 New York St",
91
+ postal: 92373
92
+ }
93
+ })
94
+ .then(response => {
95
+ expect(fetchMock.called()).toEqual(true);
96
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
97
+ expect(url).toEqual(
98
+ "https://foo.com/arcgis/rest/services/Custom/GeocodeServer/findAddressCandidates"
99
+ );
100
+ expect(options.method).toBe("POST");
101
+ expect(options.body).toContain("f=json");
102
+ expect(options.body).toContain(
103
+ `address=${encodeURIComponent("380 New York St")}`
104
+ );
105
+ expect(options.body).toContain("postal=92373");
106
+ expect(options.body).toContain("outSr=3857");
107
+ // the only property this lib tacks on
108
+ expect(response.spatialReference.wkid).toEqual(4326);
109
+ done();
110
+ })
111
+ .catch(e => {
112
+ fail(e);
113
+ });
114
+ });
115
+
116
+ it("should pass through all requestOptions when making a geocoding request", done => {
117
+ fetchMock.once("*", FindAddressCandidates);
118
+
119
+ geocode({
120
+ endpoint: customGeocoderUrl,
121
+ params: {
122
+ outSr: 3857,
123
+ address: "380 New York St",
124
+ postal: 92373
125
+ },
126
+ httpMethod: "GET"
127
+ })
128
+ .then(response => {
129
+ expect(fetchMock.called()).toEqual(true);
130
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
131
+ expect(url).toEqual(
132
+ "https://foo.com/arcgis/rest/services/Custom/GeocodeServer/findAddressCandidates?f=json&outSr=3857&address=380%20New%20York%20St&postal=92373"
133
+ );
134
+ expect(options.method).toBe("GET");
135
+ // the only property this lib tacks on
136
+ expect(response.spatialReference.wkid).toEqual(4326);
137
+ done();
138
+ })
139
+ .catch(e => {
140
+ fail(e);
141
+ });
142
+ });
143
+
144
+ it("should make a reverse geocoding request", done => {
145
+ fetchMock.once("*", ReverseGeocode);
146
+
147
+ reverseGeocode({ x: -118.409, y: 33.9425 })
148
+ .then(response => {
149
+ expect(fetchMock.called()).toEqual(true);
150
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
151
+ expect(url).toEqual(
152
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode"
153
+ );
154
+ expect(options.method).toBe("POST");
155
+ expect(options.body).toContain("f=json");
156
+ expect(options.body).toContain(
157
+ `location=${encodeURIComponent('{"x":-118.409,"y":33.9425}')}`
158
+ );
159
+ expect(response).toEqual(ReverseGeocode); // introspect the entire response
160
+ done();
161
+ })
162
+ .catch(e => {
163
+ fail(e);
164
+ });
165
+ });
166
+
167
+ it("should make a reverse geocoding GET request and pass through a spatial reference", done => {
168
+ fetchMock.once("*", ReverseGeocode);
169
+
170
+ reverseGeocode(
171
+ { x: -118.409, y: 33.9425, spatialReference: { wkid: 4326 } },
172
+ { httpMethod: "GET" }
173
+ )
174
+ .then(response => {
175
+ expect(fetchMock.called()).toEqual(true);
176
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
177
+ expect(url).toEqual(
178
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?f=json&location=%7B%22x%22%3A-118.409%2C%22y%22%3A33.9425%2C%22spatialReference%22%3A%7B%22wkid%22%3A4326%7D%7D"
179
+ );
180
+ expect(options.method).toBe("GET");
181
+ expect(response).toEqual(ReverseGeocode); // this introspects the entire response
182
+ done();
183
+ })
184
+ .catch(e => {
185
+ fail(e);
186
+ });
187
+ });
188
+
189
+ it("should make a reverse geocoding request and translate lat/long JSON objects", done => {
190
+ fetchMock.once("*", ReverseGeocode);
191
+
192
+ reverseGeocode({ longitude: -118.409, latitude: 33.9425 })
193
+ .then(response => {
194
+ expect(fetchMock.called()).toEqual(true);
195
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
196
+ expect(url).toEqual(
197
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode"
198
+ );
199
+ expect(options.method).toBe("POST");
200
+ expect(options.body).toContain("f=json");
201
+ expect(options.body).toContain(
202
+ `location=${encodeURIComponent("-118.409,33.9425")}`
203
+ );
204
+ expect(response).toEqual(ReverseGeocode); // this introspects the entire response
205
+ done();
206
+ })
207
+ .catch(e => {
208
+ fail(e);
209
+ });
210
+ });
211
+
212
+ it("should make a reverse geocoding request and translate lat/long JSON abbreviated objects", done => {
213
+ fetchMock.once("*", ReverseGeocode);
214
+
215
+ reverseGeocode({ lat: 33.9425, long: -118.409 })
216
+ .then(response => {
217
+ expect(fetchMock.called()).toEqual(true);
218
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
219
+ expect(url).toEqual(
220
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode"
221
+ );
222
+ expect(options.method).toBe("POST");
223
+ expect(options.body).toContain("f=json");
224
+ expect(options.body).toContain(
225
+ `location=${encodeURIComponent("-118.409,33.9425")}`
226
+ );
227
+ expect(response).toEqual(ReverseGeocode); // this introspects the entire response
228
+ done();
229
+ })
230
+ .catch(e => {
231
+ fail(e);
232
+ });
233
+ });
234
+
235
+ it("should make a reverse geocoding request and translate a raw long,lat array", done => {
236
+ fetchMock.once("*", ReverseGeocode);
237
+
238
+ reverseGeocode([-118, 34])
239
+ .then(response => {
240
+ expect(fetchMock.called()).toEqual(true);
241
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
242
+ expect(url).toEqual(
243
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode"
244
+ );
245
+ expect(options.method).toBe("POST");
246
+ expect(options.body).toContain("f=json");
247
+ expect(options.body).toContain(
248
+ `location=${encodeURIComponent("-118,34")}`
249
+ );
250
+ expect(response).toEqual(ReverseGeocode); // this introspects the entire response
251
+ done();
252
+ })
253
+ .catch(e => {
254
+ fail(e);
255
+ });
256
+ });
257
+
258
+ it("should make a request for suggestions", done => {
259
+ fetchMock.once("*", Suggest);
260
+
261
+ suggest("LAX")
262
+ .then(response => {
263
+ expect(fetchMock.called()).toEqual(true);
264
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
265
+ expect(url).toEqual(
266
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest"
267
+ );
268
+ expect(options.method).toBe("POST");
269
+ expect(options.body).toContain("f=json");
270
+ expect(options.body).toContain("text=LAX");
271
+ expect(response).toEqual(Suggest); // this introspects the entire response
272
+ done();
273
+ })
274
+ .catch(e => {
275
+ fail(e);
276
+ });
277
+ });
278
+
279
+ it("should make a request for suggestions with magic key", done => {
280
+ fetchMock.once("*", Suggest);
281
+
282
+ suggest("LAX", { magicKey: "foo" })
283
+ .then(response => {
284
+ expect(fetchMock.called()).toEqual(true);
285
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
286
+ expect(url).toEqual(
287
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest"
288
+ );
289
+ expect(options.method).toBe("POST");
290
+ expect(options.body).toContain("f=json");
291
+ expect(options.body).toContain("text=LAX");
292
+ expect(options.body).toContain("magicKey=foo");
293
+ expect(response).toEqual(Suggest); // this introspects the entire response
294
+ done();
295
+ })
296
+ .catch(e => {
297
+ fail(e);
298
+ });
299
+ });
300
+
301
+ it("should make a request for suggestions with other parameters", done => {
302
+ fetchMock.once("*", Suggest);
303
+
304
+ suggest("LAX", { params: { category: "Address,Postal" } })
305
+ .then(response => {
306
+ expect(fetchMock.called()).toEqual(true);
307
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
308
+ expect(url).toEqual(
309
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest"
310
+ );
311
+ expect(options.method).toBe("POST");
312
+ expect(options.body).toContain("f=json");
313
+ expect(options.body).toContain("text=LAX");
314
+ expect(options.body).toContain("category=Address%2CPostal");
315
+ expect(response).toEqual(Suggest); // this introspects the entire response
316
+ done();
317
+ })
318
+ .catch(e => {
319
+ fail(e);
320
+ });
321
+ });
322
+
323
+ it("should make a bulk geocoding request", done => {
324
+ fetchMock.once("*", GeocodeAddresses);
325
+
326
+ const MOCK_AUTH = {
327
+ getToken() {
328
+ return Promise.resolve("token");
329
+ },
330
+ portal: "https://mapsdev.arcgis.com"
331
+ };
332
+
333
+ bulkGeocode({ addresses, authentication: MOCK_AUTH })
334
+ .then(response => {
335
+ expect(fetchMock.called()).toEqual(true);
336
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
337
+ expect(url).toEqual(
338
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/geocodeAddresses"
339
+ );
340
+ expect(options.method).toBe("POST");
341
+ expect(options.body).toContain("f=json");
342
+ expect(options.body).toContain(
343
+ `addresses=${encodeURIComponent(
344
+ '{"records":[{"attributes":{"OBJECTID":1,"SingleLine":"380 New York St. Redlands 92373"}},{"attributes":{"OBJECTID":2,"SingleLine":"1 World Way Los Angeles 90045"}}]}'
345
+ )}`
346
+ );
347
+ expect(options.body).toContain("token=token");
348
+ expect(response.spatialReference.latestWkid).toEqual(4326);
349
+ expect(response.locations[0].address).toEqual(
350
+ "380 New York St, Redlands, California, 92373"
351
+ );
352
+ expect(response.locations[0].location.x).toEqual(-117.19567031799994);
353
+ // the only property this lib tacks on
354
+ expect(response.locations[0].location.spatialReference.wkid).toEqual(
355
+ 4326
356
+ );
357
+ done();
358
+ })
359
+ .catch(e => {
360
+ fail(e);
361
+ });
362
+ });
363
+
364
+ it("should throw an error when a bulk geocoding request is made without a token", done => {
365
+ fetchMock.once("*", GeocodeAddresses);
366
+
367
+ bulkGeocode({ addresses })
368
+ // tslint:disable-next-line
369
+ .catch(e => {
370
+ expect(e).toEqual(
371
+ "bulk geocoding using the ArcGIS service requires authentication"
372
+ );
373
+ done();
374
+ });
375
+ });
376
+
377
+ it("should send a bulk geocoding request to a custom url without a token", done => {
378
+ fetchMock.once("*", GeocodeAddresses);
379
+
380
+ bulkGeocode({
381
+ addresses,
382
+ endpoint:
383
+ "https://customer.gov/arcgis/rest/services/CompositeGeocoder/GeocodeServer/"
384
+ })
385
+ // tslint:disable-next-line
386
+ .then(response => {
387
+ expect(fetchMock.called()).toEqual(true);
388
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
389
+ expect(url).toEqual(
390
+ "https://customer.gov/arcgis/rest/services/CompositeGeocoder/GeocodeServer/geocodeAddresses"
391
+ );
392
+ expect(options.method).toBe("POST");
393
+ expect(options.body).toContain("f=json");
394
+ expect(options.body).toContain(
395
+ `addresses=${encodeURIComponent(
396
+ '{"records":[{"attributes":{"OBJECTID":1,"SingleLine":"380 New York St. Redlands 92373"}},{"attributes":{"OBJECTID":2,"SingleLine":"1 World Way Los Angeles 90045"}}]}'
397
+ )}`
398
+ );
399
+ // expect(options.body).toContain("token=token");
400
+ expect(response.spatialReference.latestWkid).toEqual(4326);
401
+ expect(response.locations[0].address).toEqual(
402
+ "380 New York St, Redlands, California, 92373"
403
+ );
404
+ expect(response.locations[0].location.x).toEqual(-117.19567031799994);
405
+ // the only property this lib tacks on
406
+ expect(response.locations[0].location.spatialReference.wkid).toEqual(
407
+ 4326
408
+ );
409
+ done();
410
+ });
411
+ });
412
+
413
+ it("should retrieve metadata from the World Geocoding Service", done => {
414
+ fetchMock.once("*", SharingInfo);
415
+
416
+ getGeocodeService()
417
+ .then(response => {
418
+ expect(fetchMock.called()).toEqual(true);
419
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
420
+ expect(url).toEqual(
421
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/?f=json"
422
+ );
423
+ expect(options.method).toBe("GET");
424
+ // expect(response).toEqual(SharingInfo); // need to fix something in order introspect the whole response
425
+ expect(response.currentVersion).toEqual(10.41);
426
+ expect(response.serviceDescription).toEqual(
427
+ "Sample geocoder for San Diego, California, USA"
428
+ );
429
+ done();
430
+ })
431
+ .catch(e => {
432
+ fail(e);
433
+ });
434
+ });
435
+
436
+ it("should make POST request for metadata from the World Geocoding Service", done => {
437
+ fetchMock.once("*", SharingInfo);
438
+
439
+ getGeocodeService({ httpMethod: "POST" })
440
+ .then(response => {
441
+ expect(fetchMock.called()).toEqual(true);
442
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
443
+ expect(url).toEqual(
444
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/"
445
+ );
446
+ expect(options.method).toBe("POST");
447
+ expect(options.body).toContain("f=json");
448
+ // expect(paramsSpy).toHaveBeenCalledWith("f", "json");
449
+ // expect(response).toEqual(SharingInfo); // need to fix something in order introspect the whole response
450
+ expect(response.currentVersion).toEqual(10.41);
451
+ expect(response.serviceDescription).toEqual(
452
+ "Sample geocoder for San Diego, California, USA"
453
+ );
454
+ done();
455
+ })
456
+ .catch(e => {
457
+ fail(e);
458
+ });
459
+ });
460
+
461
+ it("should retrieve metadata from custom geocoding services", done => {
462
+ fetchMock.once("*", SharingInfo);
463
+
464
+ getGeocodeService({ endpoint: customGeocoderUrl })
465
+ .then(response => {
466
+ expect(fetchMock.called()).toEqual(true);
467
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
468
+ expect(url).toEqual(
469
+ "https://foo.com/arcgis/rest/services/Custom/GeocodeServer/?f=json"
470
+ );
471
+ expect(options.method).toBe("GET");
472
+ // how to introspect the whole response?
473
+ // expect(response).toEqual(SharingInfo);
474
+ expect(response.currentVersion).toEqual(10.41);
475
+ expect(response.serviceDescription).toEqual(
476
+ "Sample geocoder for San Diego, California, USA"
477
+ );
478
+ done();
479
+ })
480
+ .catch(e => {
481
+ fail(e);
482
+ });
483
+ });
484
+
485
+ it("should retrieve metadata from the World Geocoding Service using the old method name", done => {
486
+ fetchMock.once("*", SharingInfo);
487
+
488
+ // intercept deprecation warning
489
+ console.warn = jasmine.createSpy("warning");
490
+
491
+ serviceInfo()
492
+ .then(response => {
493
+ expect(fetchMock.called()).toEqual(true);
494
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
495
+ expect(url).toEqual(
496
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/?f=json"
497
+ );
498
+ expect(options.method).toBe("GET");
499
+ // expect(response).toEqual(SharingInfo); // need to fix something in order introspect the whole response
500
+ expect(response.currentVersion).toEqual(10.41);
501
+ expect(response.serviceDescription).toEqual(
502
+ "Sample geocoder for San Diego, California, USA"
503
+ );
504
+ done();
505
+ })
506
+ .catch(e => {
507
+ fail(e);
508
+ });
509
+ });
510
+ });