delectusnon 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (276) hide show
  1. package/.prettierignore +2 -0
  2. package/.travis.yml +33 -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 +15 -0
  18. package/demos/batch-geocoder-node/batch-geocode.js +118 -0
  19. package/demos/batch-geocoder-node/config-template.js +18 -0
  20. package/demos/batch-geocoder-node/package-lock.json +116 -0
  21. package/demos/batch-geocoder-node/package.json +39 -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 +473 -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 +182 -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/oauth2-browser-retry/README.md +25 -0
  51. package/demos/oauth2-browser-retry/authenticate.html +21 -0
  52. package/demos/oauth2-browser-retry/index.html +116 -0
  53. package/demos/oauth2-browser-retry/logo.svg +4 -0
  54. package/demos/vue/.env.example +11 -0
  55. package/demos/vue/.eslintrc.js +17 -0
  56. package/demos/vue/.postcssrc.js +5 -0
  57. package/demos/vue/README.md +17 -0
  58. package/demos/vue/babel.config.js +3 -0
  59. package/demos/vue/package-lock.json +11323 -0
  60. package/demos/vue/package.json +33 -0
  61. package/demos/vue/public/favicon.ico +0 -0
  62. package/demos/vue/public/index.html +24 -0
  63. package/demos/vue/src/assets/logo.svg +29 -0
  64. package/demos/vue/src/components/App.vue +308 -0
  65. package/demos/vue/src/components/Authenticate.vue +65 -0
  66. package/demos/vue/src/components/Loader.vue +230 -0
  67. package/demos/vue/src/main.js +92 -0
  68. package/docs/FAQ.md +28 -0
  69. package/docs/HISTORY.md +62 -0
  70. package/docs/acetate.config.js +223 -0
  71. package/docs/build-typedoc.js +301 -0
  72. package/docs/src/_layout.html +82 -0
  73. package/docs/src/api/_declaration.html +496 -0
  74. package/docs/src/api/_layout.html +127 -0
  75. package/docs/src/api/_package.html +13 -0
  76. package/docs/src/api/index.html +23 -0
  77. package/docs/src/guides/_layout.html +24 -0
  78. package/docs/src/guides/amd-requirejs-dojo.md +40 -0
  79. package/docs/src/guides/babel-and-rollup.md +30 -0
  80. package/docs/src/guides/babel-and-webpack.md +30 -0
  81. package/docs/src/guides/browser-authentication.md +31 -0
  82. package/docs/src/guides/browserify.md +9 -0
  83. package/docs/src/guides/cli-authentication.md +9 -0
  84. package/docs/src/guides/client-server-authentication.md +9 -0
  85. package/docs/src/guides/from-a-cdn.md +36 -0
  86. package/docs/src/guides/index.md +52 -0
  87. package/docs/src/guides/node.md +70 -0
  88. package/docs/src/guides/package-overview.md +8 -0
  89. package/docs/src/guides/server-authentication.md +9 -0
  90. package/docs/src/guides/typescript-and-webpack.md +9 -0
  91. package/docs/src/img/icons.png +0 -0
  92. package/docs/src/img/icons@2x.png +0 -0
  93. package/docs/src/index.html +12 -0
  94. package/docs/src/js/api-search.js +112 -0
  95. package/docs/src/js/nav-toggle.js +41 -0
  96. package/docs/src/sass/_highlight.scss +96 -0
  97. package/docs/src/sass/_icons.scss +157 -0
  98. package/docs/src/sass/style.scss +169 -0
  99. package/jasmine.json +7 -0
  100. package/karma.conf.js +100 -0
  101. package/lerna.json +8 -0
  102. package/notes/README.md +88 -0
  103. package/package.json +88 -0
  104. package/packages/arcgis-rest-auth/README.md +64 -0
  105. package/packages/arcgis-rest-auth/package-lock.json +11 -0
  106. package/packages/arcgis-rest-auth/package.json +51 -0
  107. package/packages/arcgis-rest-auth/src/ApplicationSession.ts +109 -0
  108. package/packages/arcgis-rest-auth/src/UserSession.ts +873 -0
  109. package/packages/arcgis-rest-auth/src/authenticated-request-options.ts +24 -0
  110. package/packages/arcgis-rest-auth/src/fetch-token.ts +52 -0
  111. package/packages/arcgis-rest-auth/src/generate-token.ts +39 -0
  112. package/packages/arcgis-rest-auth/src/index.ts +8 -0
  113. package/packages/arcgis-rest-auth/test/ApplicationSession.test.ts +124 -0
  114. package/packages/arcgis-rest-auth/test/UserSession.test.ts +995 -0
  115. package/packages/arcgis-rest-auth/test/fetchToken.test.ts +112 -0
  116. package/packages/arcgis-rest-auth/test/generateToken.test.ts +130 -0
  117. package/packages/arcgis-rest-auth/test/utils.ts +14 -0
  118. package/packages/arcgis-rest-auth/tsconfig.json +6 -0
  119. package/packages/arcgis-rest-common-types/README.md +61 -0
  120. package/packages/arcgis-rest-common-types/package.json +38 -0
  121. package/packages/arcgis-rest-common-types/src/group.ts +54 -0
  122. package/packages/arcgis-rest-common-types/src/index.ts +467 -0
  123. package/packages/arcgis-rest-common-types/src/item.ts +45 -0
  124. package/packages/arcgis-rest-common-types/src/webmap.ts +1232 -0
  125. package/packages/arcgis-rest-common-types/tsconfig.json +11 -0
  126. package/packages/arcgis-rest-feature-service/README.md +70 -0
  127. package/packages/arcgis-rest-feature-service/package-lock.json +11 -0
  128. package/packages/arcgis-rest-feature-service/package.json +50 -0
  129. package/packages/arcgis-rest-feature-service/src/add.ts +81 -0
  130. package/packages/arcgis-rest-feature-service/src/addAttachment.ts +65 -0
  131. package/packages/arcgis-rest-feature-service/src/delete.ts +85 -0
  132. package/packages/arcgis-rest-feature-service/src/deleteAttachments.ts +68 -0
  133. package/packages/arcgis-rest-feature-service/src/getAttachments.ts +64 -0
  134. package/packages/arcgis-rest-feature-service/src/helpers.ts +80 -0
  135. package/packages/arcgis-rest-feature-service/src/index.ts +12 -0
  136. package/packages/arcgis-rest-feature-service/src/query.ts +172 -0
  137. package/packages/arcgis-rest-feature-service/src/queryRelated.ts +91 -0
  138. package/packages/arcgis-rest-feature-service/src/update.ts +81 -0
  139. package/packages/arcgis-rest-feature-service/src/updateAttachment.ts +74 -0
  140. package/packages/arcgis-rest-feature-service/test/attachments.test.ts +203 -0
  141. package/packages/arcgis-rest-feature-service/test/features.test.ts +252 -0
  142. package/packages/arcgis-rest-feature-service/test/mocks/feature.ts +279 -0
  143. package/packages/arcgis-rest-feature-service/test/mocks/foo.txt +1 -0
  144. package/packages/arcgis-rest-feature-service/tsconfig.json +6 -0
  145. package/packages/arcgis-rest-feature-service-admin/README.md +66 -0
  146. package/packages/arcgis-rest-feature-service-admin/package-lock.json +11 -0
  147. package/packages/arcgis-rest-feature-service-admin/package.json +53 -0
  148. package/packages/arcgis-rest-feature-service-admin/src/addTo.ts +70 -0
  149. package/packages/arcgis-rest-feature-service-admin/src/create.ts +195 -0
  150. package/packages/arcgis-rest-feature-service-admin/src/index.ts +2 -0
  151. package/packages/arcgis-rest-feature-service-admin/test/addTo.test.ts +310 -0
  152. package/packages/arcgis-rest-feature-service-admin/test/create.test.ts +412 -0
  153. package/packages/arcgis-rest-feature-service-admin/test/mocks/move.ts +14 -0
  154. package/packages/arcgis-rest-feature-service-admin/test/mocks/service.ts +72 -0
  155. package/packages/arcgis-rest-feature-service-admin/tsconfig.json +6 -0
  156. package/packages/arcgis-rest-geocoder/README.md +79 -0
  157. package/packages/arcgis-rest-geocoder/package-lock.json +11 -0
  158. package/packages/arcgis-rest-geocoder/package.json +52 -0
  159. package/packages/arcgis-rest-geocoder/src/bulk.ts +102 -0
  160. package/packages/arcgis-rest-geocoder/src/geocode.ts +117 -0
  161. package/packages/arcgis-rest-geocoder/src/helpers.ts +79 -0
  162. package/packages/arcgis-rest-geocoder/src/index.ts +8 -0
  163. package/packages/arcgis-rest-geocoder/src/reverse.ts +84 -0
  164. package/packages/arcgis-rest-geocoder/src/suggest.ts +72 -0
  165. package/packages/arcgis-rest-geocoder/test/bulk.test.ts +113 -0
  166. package/packages/arcgis-rest-geocoder/test/geocode.test.ts +121 -0
  167. package/packages/arcgis-rest-geocoder/test/helpers.test.ts +113 -0
  168. package/packages/arcgis-rest-geocoder/test/mocks/responses.ts +591 -0
  169. package/packages/arcgis-rest-geocoder/test/reverse.test.ts +126 -0
  170. package/packages/arcgis-rest-geocoder/test/suggest.test.ts +77 -0
  171. package/packages/arcgis-rest-geocoder/tsconfig.json +6 -0
  172. package/packages/arcgis-rest-groups/README.md +64 -0
  173. package/packages/arcgis-rest-groups/package-lock.json +11 -0
  174. package/packages/arcgis-rest-groups/package.json +52 -0
  175. package/packages/arcgis-rest-groups/src/create.ts +34 -0
  176. package/packages/arcgis-rest-groups/src/get.ts +95 -0
  177. package/packages/arcgis-rest-groups/src/helpers.ts +26 -0
  178. package/packages/arcgis-rest-groups/src/index.ts +11 -0
  179. package/packages/arcgis-rest-groups/src/notification.ts +77 -0
  180. package/packages/arcgis-rest-groups/src/protect.ts +40 -0
  181. package/packages/arcgis-rest-groups/src/remove.ts +23 -0
  182. package/packages/arcgis-rest-groups/src/search.ts +64 -0
  183. package/packages/arcgis-rest-groups/src/update.ts +36 -0
  184. package/packages/arcgis-rest-groups/test/crud.test.ts +104 -0
  185. package/packages/arcgis-rest-groups/test/get.test.ts +101 -0
  186. package/packages/arcgis-rest-groups/test/mocks/responses.ts +141 -0
  187. package/packages/arcgis-rest-groups/test/notification.test.ts +102 -0
  188. package/packages/arcgis-rest-groups/test/protect.test.ts +64 -0
  189. package/packages/arcgis-rest-groups/test/search.test.ts +85 -0
  190. package/packages/arcgis-rest-groups/tsconfig.json +6 -0
  191. package/packages/arcgis-rest-items/README.md +66 -0
  192. package/packages/arcgis-rest-items/package-lock.json +11 -0
  193. package/packages/arcgis-rest-items/package.json +52 -0
  194. package/packages/arcgis-rest-items/src/add.ts +103 -0
  195. package/packages/arcgis-rest-items/src/create.ts +110 -0
  196. package/packages/arcgis-rest-items/src/get.ts +79 -0
  197. package/packages/arcgis-rest-items/src/helpers.ts +147 -0
  198. package/packages/arcgis-rest-items/src/index.ts +11 -0
  199. package/packages/arcgis-rest-items/src/protect.ts +38 -0
  200. package/packages/arcgis-rest-items/src/remove.ts +58 -0
  201. package/packages/arcgis-rest-items/src/search.ts +78 -0
  202. package/packages/arcgis-rest-items/src/update.ts +134 -0
  203. package/packages/arcgis-rest-items/test/add.test.ts +256 -0
  204. package/packages/arcgis-rest-items/test/create.test.ts +371 -0
  205. package/packages/arcgis-rest-items/test/get.test.ts +181 -0
  206. package/packages/arcgis-rest-items/test/mocks/foo.zip +0 -0
  207. package/packages/arcgis-rest-items/test/mocks/item.ts +33 -0
  208. package/packages/arcgis-rest-items/test/mocks/resources.ts +31 -0
  209. package/packages/arcgis-rest-items/test/mocks/search.ts +63 -0
  210. package/packages/arcgis-rest-items/test/protect.test.ts +122 -0
  211. package/packages/arcgis-rest-items/test/remove.test.ts +161 -0
  212. package/packages/arcgis-rest-items/test/search.test.ts +159 -0
  213. package/packages/arcgis-rest-items/test/update.test.ts +450 -0
  214. package/packages/arcgis-rest-items/tsconfig.json +6 -0
  215. package/packages/arcgis-rest-request/README.md +65 -0
  216. package/packages/arcgis-rest-request/package-lock.json +11 -0
  217. package/packages/arcgis-rest-request/package.json +42 -0
  218. package/packages/arcgis-rest-request/src/index.ts +13 -0
  219. package/packages/arcgis-rest-request/src/request.ts +293 -0
  220. package/packages/arcgis-rest-request/src/utils/ArcGISAuthError.ts +67 -0
  221. package/packages/arcgis-rest-request/src/utils/ArcGISRequestError.ts +76 -0
  222. package/packages/arcgis-rest-request/src/utils/ErrorTypes.ts +29 -0
  223. package/packages/arcgis-rest-request/src/utils/check-for-errors.ts +65 -0
  224. package/packages/arcgis-rest-request/src/utils/encode-form-data.ts +34 -0
  225. package/packages/arcgis-rest-request/src/utils/encode-query-string.ts +23 -0
  226. package/packages/arcgis-rest-request/src/utils/get-portal-url.ts +25 -0
  227. package/packages/arcgis-rest-request/src/utils/get-portal.ts +45 -0
  228. package/packages/arcgis-rest-request/src/utils/process-params.ts +99 -0
  229. package/packages/arcgis-rest-request/test/mocks/errors.ts +68 -0
  230. package/packages/arcgis-rest-request/test/mocks/geojson-feature-collection.ts +13 -0
  231. package/packages/arcgis-rest-request/test/mocks/portal.ts +112 -0
  232. package/packages/arcgis-rest-request/test/mocks/sharing-rest-info.ts +41 -0
  233. package/packages/arcgis-rest-request/test/mocks/webmap.ts +41 -0
  234. package/packages/arcgis-rest-request/test/request.test.ts +299 -0
  235. package/packages/arcgis-rest-request/test/utils/ArcGISAuthError.test.ts +170 -0
  236. package/packages/arcgis-rest-request/test/utils/ArcGISRequestError.test.ts +51 -0
  237. package/packages/arcgis-rest-request/test/utils/check-for-errors.test.ts +111 -0
  238. package/packages/arcgis-rest-request/test/utils/encode-form-data.test.ts +133 -0
  239. package/packages/arcgis-rest-request/test/utils/get-portal-url.test.ts +37 -0
  240. package/packages/arcgis-rest-request/test/utils/portal.test.ts +97 -0
  241. package/packages/arcgis-rest-request/test/utils/process-params.test.ts +193 -0
  242. package/packages/arcgis-rest-request/tsconfig.json +6 -0
  243. package/packages/arcgis-rest-sharing/README.md +67 -0
  244. package/packages/arcgis-rest-sharing/package-lock.json +11 -0
  245. package/packages/arcgis-rest-sharing/package.json +57 -0
  246. package/packages/arcgis-rest-sharing/src/access.ts +85 -0
  247. package/packages/arcgis-rest-sharing/src/group-sharing.ts +211 -0
  248. package/packages/arcgis-rest-sharing/src/helpers.ts +82 -0
  249. package/packages/arcgis-rest-sharing/src/index.ts +5 -0
  250. package/packages/arcgis-rest-sharing/test/access.test.ts +154 -0
  251. package/packages/arcgis-rest-sharing/test/group-sharing.test.ts +566 -0
  252. package/packages/arcgis-rest-sharing/test/helpers.test.ts +55 -0
  253. package/packages/arcgis-rest-sharing/test/mocks/sharing.ts +18 -0
  254. package/packages/arcgis-rest-sharing/tsconfig.json +6 -0
  255. package/packages/arcgis-rest-users/README.md +71 -0
  256. package/packages/arcgis-rest-users/package-lock.json +11 -0
  257. package/packages/arcgis-rest-users/package.json +51 -0
  258. package/packages/arcgis-rest-users/src/get.ts +69 -0
  259. package/packages/arcgis-rest-users/src/index.ts +6 -0
  260. package/packages/arcgis-rest-users/src/invitation.ts +166 -0
  261. package/packages/arcgis-rest-users/src/notification.ts +73 -0
  262. package/packages/arcgis-rest-users/test/get.test.ts +99 -0
  263. package/packages/arcgis-rest-users/test/invitation.test.ts +169 -0
  264. package/packages/arcgis-rest-users/test/mocks/invitation.ts +70 -0
  265. package/packages/arcgis-rest-users/test/mocks/notification.ts +34 -0
  266. package/packages/arcgis-rest-users/test/mocks/user.ts +173 -0
  267. package/packages/arcgis-rest-users/test/notification.test.ts +83 -0
  268. package/packages/arcgis-rest-users/tsconfig.json +6 -0
  269. package/support/changelog.js +394 -0
  270. package/support/deploy-doc-site.js +16 -0
  271. package/support/publish.sh +43 -0
  272. package/support/test-helpers.js +8 -0
  273. package/tsconfig.json +69 -0
  274. package/tslint.json +15 -0
  275. package/umd-base-profile.js +82 -0
  276. package/umd-production-profile.js +13 -0
@@ -0,0 +1,102 @@
1
+ /* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
2
+ * Apache-2.0 */
3
+
4
+ import { request } from "@esri/arcgis-rest-request";
5
+
6
+ import { ISpatialReference, IPoint } from "@esri/arcgis-rest-common-types";
7
+
8
+ import { worldGeocoder, IEndpointRequestOptions } from "./helpers";
9
+
10
+ // it'd be better if doc didnt display these properties in alphabetical order
11
+ export interface IAddressBulk {
12
+ /**
13
+ * A unique id must be passed along for each individual address.
14
+ */
15
+ OBJECTID: number;
16
+ address?: string;
17
+ address2?: string;
18
+ address3?: string;
19
+ neighborhood?: string;
20
+ city?: string;
21
+ subregion?: string;
22
+ /**
23
+ * The World Geocoding Service considers US states regions.
24
+ */
25
+ region?: string;
26
+ postal?: number;
27
+ postalExt?: number;
28
+ countryCode?: string;
29
+ }
30
+
31
+ export interface IBulkGeocodeRequestOptions extends IEndpointRequestOptions {
32
+ addresses: IAddressBulk[];
33
+ }
34
+
35
+ export interface IBulkGeocodeResponse {
36
+ spatialReference: ISpatialReference;
37
+ locations: Array<{
38
+ address: string;
39
+ location: IPoint;
40
+ score: number;
41
+ attributes: object;
42
+ }>;
43
+ }
44
+
45
+ /**
46
+ * Used to geocode a [batch](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-geocode-addresses.htm) of addresses.
47
+ *
48
+ * ```js
49
+ * import { bulkGeocode } from '@esri/arcgis-rest-geocoder';
50
+ * import { ApplicationSession } from '@esri/arcgis-rest-auth';
51
+ *
52
+ * const addresses = [
53
+ * { "OBJECTID": 1, "SingleLine": "380 New York Street 92373" },
54
+ * { "OBJECTID": 2, "SingleLine": "1 World Way Los Angeles 90045" }
55
+ * ];
56
+ *
57
+ * bulkGeocode({ addresses, authentication: session })
58
+ * .then((response) => {
59
+ * response.locations[0].location; // => { x: -117, y: 34, spatialReference: { wkid: 4326 } }
60
+ * });
61
+ * ```
62
+ *
63
+ * @param requestOptions - Request options to pass to the geocoder, including an array of addresses and authentication session.
64
+ * @returns A Promise that will resolve with the data from the response.
65
+ */
66
+ export function bulkGeocode(
67
+ requestOptions: IBulkGeocodeRequestOptions // must POST
68
+ ) {
69
+ const options: IBulkGeocodeRequestOptions = {
70
+ endpoint: worldGeocoder,
71
+ params: {
72
+ forStorage: true,
73
+ addresses: { records: [] }
74
+ },
75
+ ...requestOptions
76
+ };
77
+
78
+ requestOptions.addresses.forEach(address => {
79
+ options.params.addresses.records.push({ attributes: address });
80
+ });
81
+
82
+ // the SAS service doesnt support anonymous requests
83
+ if (!requestOptions.authentication && options.endpoint === worldGeocoder) {
84
+ return Promise.reject(
85
+ "bulk geocoding using the ArcGIS service requires authentication"
86
+ );
87
+ }
88
+
89
+ return request(options.endpoint + "geocodeAddresses", options).then(
90
+ response => {
91
+ const sr = response.spatialReference;
92
+ response.locations.forEach(function(address: { location: IPoint }) {
93
+ address.location.spatialReference = sr;
94
+ });
95
+ return response;
96
+ }
97
+ );
98
+ }
99
+
100
+ export default {
101
+ bulkGeocode
102
+ };
@@ -0,0 +1,117 @@
1
+ /* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
2
+ * Apache-2.0 */
3
+
4
+ import { request, IParams } from "@esri/arcgis-rest-request";
5
+
6
+ import {
7
+ IExtent,
8
+ ISpatialReference,
9
+ IPoint
10
+ } from "@esri/arcgis-rest-common-types";
11
+
12
+ import { worldGeocoder, IEndpointRequestOptions } from "./helpers";
13
+
14
+ export interface IGeocodeParams extends IParams {
15
+ /**
16
+ * 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.
17
+ * ```js
18
+ * import { suggest, geocode } from '@esri/arcgis-rest-geocoder';
19
+ * suggest("LAX")
20
+ * .then((response) => {
21
+ * response.suggestions[2].magicKey; // => "dHA9MCNsb2M9Mjk3ODc2MCNsbmc9MzMjcGw9ODkxNDg4I2xicz0xNDoxNDc4MTI1MA=="
22
+ * });
23
+ * geocode("LAX, 1 World Way, Los Angeles, CA, 90045, USA", {magicKey: "dHA9MCN..."})
24
+ * ```
25
+ */
26
+ magicKey?: string;
27
+ }
28
+
29
+ export interface IGeocodeRequestOptions extends IEndpointRequestOptions {
30
+ address?: string;
31
+ address2?: string;
32
+ address3?: string;
33
+ neighborhood?: string;
34
+ city?: string;
35
+ subregion?: string;
36
+ /**
37
+ * The World Geocoding Service expects US states to be passed in as a 'region'.
38
+ */
39
+ region?: string;
40
+ postal?: number;
41
+ postalExt?: number;
42
+ countryCode?: string;
43
+ }
44
+
45
+ export interface IGeocodeResponse {
46
+ spatialReference: ISpatialReference;
47
+ candidates: Array<{
48
+ address: string;
49
+ location: IPoint;
50
+ extent: IExtent;
51
+ attributes: object;
52
+ }>;
53
+ }
54
+
55
+ /**
56
+ * 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.
57
+ *
58
+ * ```js
59
+ * import { geocode } from '@esri/arcgis-rest-geocoder';
60
+ *
61
+ * geocode("LAX")
62
+ * .then((response) => {
63
+ * response.candidates[0].location; // => { x: -118.409, y: 33.943, spatialReference: { wkid: 4326 } }
64
+ * });
65
+ *
66
+ * geocode({
67
+ * params: {
68
+ * address: "1600 Pennsylvania Ave",
69
+ * postal: 20500,
70
+ * countryCode: "USA"
71
+ * }
72
+ * })
73
+ * .then((response) => {
74
+ * response.candidates[0].location; // => { x: -77.036533, y: 38.898719, spatialReference: { wkid: 4326 } }
75
+ * });
76
+ * ```
77
+ *
78
+ * @param address String representing the address or point of interest or RequestOptions to pass to the endpoint.
79
+ * @returns A Promise that will resolve with address candidates for the request.
80
+ */
81
+ export function geocode(
82
+ address: string | IGeocodeRequestOptions
83
+ ): Promise<IGeocodeResponse> {
84
+ let options: IGeocodeRequestOptions = {
85
+ endpoint: worldGeocoder,
86
+ params: {}
87
+ };
88
+
89
+ if (typeof address === "string") {
90
+ options.params.singleLine = address;
91
+ } else {
92
+ options.endpoint = address.endpoint || worldGeocoder;
93
+ options = {
94
+ ...options,
95
+ ...address
96
+ };
97
+ }
98
+
99
+ // add spatialReference property to individual matches
100
+ return request(options.endpoint + "findAddressCandidates", options).then(
101
+ response => {
102
+ const sr = response.spatialReference;
103
+ response.candidates.forEach(function(candidate: {
104
+ location: IPoint;
105
+ extent: IExtent;
106
+ }) {
107
+ candidate.location.spatialReference = sr;
108
+ candidate.extent.spatialReference = sr;
109
+ });
110
+ return response;
111
+ }
112
+ );
113
+ }
114
+
115
+ export default {
116
+ geocode
117
+ };
@@ -0,0 +1,79 @@
1
+ /* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
2
+ * Apache-2.0 */
3
+
4
+ import { request, IRequestOptions, warn } from "@esri/arcgis-rest-request";
5
+
6
+ // https always
7
+ export const worldGeocoder =
8
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/";
9
+
10
+ export interface ILocation {
11
+ latitude?: number;
12
+ longitude?: number;
13
+ lat?: number;
14
+ long?: number;
15
+ }
16
+
17
+ // nice to have: verify custom endpoints contain 'GeocodeServer' and end in a '/'
18
+ export interface IEndpointRequestOptions extends IRequestOptions {
19
+ /**
20
+ * Any ArcGIS Geocoding service (example: http://sampleserver6.arcgisonline.com/arcgis/rest/services/Locators/SanDiego/GeocodeServer )
21
+ */
22
+ endpoint?: string;
23
+ }
24
+
25
+ export interface IGetGeocodeServiceResponse {
26
+ currentVersion: number;
27
+ serviceDescription: string;
28
+ addressFields: any[];
29
+ countries: string[];
30
+ capabilities: string;
31
+ }
32
+
33
+ /**
34
+ * Used to fetch metadata from a geocoding service.
35
+ *
36
+ * ```js
37
+ * import { getGeocoderServiceInfo } from '@esri/arcgis-rest-geocoder';
38
+ *
39
+ * getGeocoderServiceInfo()
40
+ * .then((response) => {
41
+ * response.serviceDescription; // => 'World Geocoder'
42
+ * });
43
+ * ```
44
+ *
45
+ * @param requestOptions - Request options can contain a custom geocoding service to fetch metadata from.
46
+ * @returns A Promise that will resolve with the data from the response.
47
+ */
48
+ export function getGeocodeService(
49
+ requestOptions?: IEndpointRequestOptions
50
+ ): Promise<IGetGeocodeServiceResponse> {
51
+ const url = (requestOptions && requestOptions.endpoint) || worldGeocoder;
52
+
53
+ const options: IEndpointRequestOptions = {
54
+ httpMethod: "GET",
55
+ maxUrlLength: 2000,
56
+ ...requestOptions
57
+ };
58
+
59
+ return request(url, options);
60
+ }
61
+
62
+ /**
63
+ * Deprecated. Please use [`getGeocodeService()`](../getGeocodeService/) instead.
64
+ *
65
+ * @param requestOptions - Request options can contain a custom geocoding service to fetch metadata from.
66
+ * @returns A Promise that will resolve with the data from the response.
67
+ */
68
+ export function serviceInfo(
69
+ requestOptions?: IEndpointRequestOptions
70
+ ): Promise<IGetGeocodeServiceResponse> {
71
+ warn(
72
+ "serviceInfo() will be deprecated in the next major release. please use getGeocoderServiceInfo() instead."
73
+ );
74
+ return getGeocodeService(requestOptions);
75
+ }
76
+
77
+ export default {
78
+ getGeocodeService
79
+ };
@@ -0,0 +1,8 @@
1
+ /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
2
+ * Apache-2.0 */
3
+
4
+ export * from "./geocode";
5
+ export * from "./suggest";
6
+ export * from "./reverse";
7
+ export * from "./bulk";
8
+ export * from "./helpers";
@@ -0,0 +1,84 @@
1
+ /* Copyright (c) 2017-2018 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](https://developers.arcgis.com/rest/geocode/api-reference/geocoding-reverse-geocode.htm).
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-2018 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]((https://developers.arcgis.com/rest/geocode/api-reference/geocoding-suggest.htm) 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,113 @@
1
+ /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
2
+ * Apache-2.0 */
3
+
4
+ import { bulkGeocode } from "../src/bulk";
5
+
6
+ import * as fetchMock from "fetch-mock";
7
+
8
+ import { GeocodeAddresses } from "./mocks/responses";
9
+
10
+ const addresses = [
11
+ {
12
+ OBJECTID: 1,
13
+ SingleLine: "380 New York St. Redlands 92373"
14
+ },
15
+ {
16
+ OBJECTID: 2,
17
+ SingleLine: "1 World Way Los Angeles 90045"
18
+ }
19
+ ];
20
+
21
+ describe("geocode", () => {
22
+ afterEach(fetchMock.restore);
23
+
24
+ it("should make a bulk geocoding request", done => {
25
+ fetchMock.once("*", GeocodeAddresses);
26
+
27
+ const MOCK_AUTH = {
28
+ getToken() {
29
+ return Promise.resolve("token");
30
+ },
31
+ portal: "https://mapsdev.arcgis.com"
32
+ };
33
+
34
+ bulkGeocode({ addresses, authentication: MOCK_AUTH })
35
+ .then(response => {
36
+ expect(fetchMock.called()).toEqual(true);
37
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
38
+ expect(url).toEqual(
39
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/geocodeAddresses"
40
+ );
41
+ expect(options.method).toBe("POST");
42
+ expect(options.body).toContain("f=json");
43
+ expect(options.body).toContain(
44
+ `addresses=${encodeURIComponent(
45
+ '{"records":[{"attributes":{"OBJECTID":1,"SingleLine":"380 New York St. Redlands 92373"}},{"attributes":{"OBJECTID":2,"SingleLine":"1 World Way Los Angeles 90045"}}]}'
46
+ )}`
47
+ );
48
+ expect(options.body).toContain("token=token");
49
+ expect(response.spatialReference.latestWkid).toEqual(4326);
50
+ expect(response.locations[0].address).toEqual(
51
+ "380 New York St, Redlands, California, 92373"
52
+ );
53
+ expect(response.locations[0].location.x).toEqual(-117.19567031799994);
54
+ // the only property this lib tacks on
55
+ expect(response.locations[0].location.spatialReference.wkid).toEqual(
56
+ 4326
57
+ );
58
+ done();
59
+ })
60
+ .catch(e => {
61
+ fail(e);
62
+ });
63
+ });
64
+
65
+ it("should throw an error when a bulk geocoding request is made without a token", done => {
66
+ fetchMock.once("*", GeocodeAddresses);
67
+
68
+ bulkGeocode({ addresses })
69
+ // tslint:disable-next-line
70
+ .catch(e => {
71
+ expect(e).toEqual(
72
+ "bulk geocoding using the ArcGIS service requires authentication"
73
+ );
74
+ done();
75
+ });
76
+ });
77
+
78
+ it("should send a bulk geocoding request to a custom url without a token", done => {
79
+ fetchMock.once("*", GeocodeAddresses);
80
+
81
+ bulkGeocode({
82
+ addresses,
83
+ endpoint:
84
+ "https://customer.gov/arcgis/rest/services/CompositeGeocoder/GeocodeServer/"
85
+ })
86
+ // tslint:disable-next-line
87
+ .then(response => {
88
+ expect(fetchMock.called()).toEqual(true);
89
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
90
+ expect(url).toEqual(
91
+ "https://customer.gov/arcgis/rest/services/CompositeGeocoder/GeocodeServer/geocodeAddresses"
92
+ );
93
+ expect(options.method).toBe("POST");
94
+ expect(options.body).toContain("f=json");
95
+ expect(options.body).toContain(
96
+ `addresses=${encodeURIComponent(
97
+ '{"records":[{"attributes":{"OBJECTID":1,"SingleLine":"380 New York St. Redlands 92373"}},{"attributes":{"OBJECTID":2,"SingleLine":"1 World Way Los Angeles 90045"}}]}'
98
+ )}`
99
+ );
100
+ // expect(options.body).toContain("token=token");
101
+ expect(response.spatialReference.latestWkid).toEqual(4326);
102
+ expect(response.locations[0].address).toEqual(
103
+ "380 New York St, Redlands, California, 92373"
104
+ );
105
+ expect(response.locations[0].location.x).toEqual(-117.19567031799994);
106
+ // the only property this lib tacks on
107
+ expect(response.locations[0].location.spatialReference.wkid).toEqual(
108
+ 4326
109
+ );
110
+ done();
111
+ });
112
+ });
113
+ });
@@ -0,0 +1,121 @@
1
+ /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
2
+ * Apache-2.0 */
3
+
4
+ import { geocode } from "../src/geocode";
5
+
6
+ import * as fetchMock from "fetch-mock";
7
+
8
+ import { FindAddressCandidates } from "./mocks/responses";
9
+
10
+ const customGeocoderUrl =
11
+ "https://foo.com/arcgis/rest/services/Custom/GeocodeServer/";
12
+
13
+ describe("geocode", () => {
14
+ afterEach(fetchMock.restore);
15
+
16
+ it("should make a simple, single geocoding request", done => {
17
+ fetchMock.once("*", FindAddressCandidates);
18
+
19
+ geocode("LAX")
20
+ .then(response => {
21
+ expect(fetchMock.called()).toEqual(true);
22
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
23
+ expect(url).toEqual(
24
+ "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates"
25
+ );
26
+ expect(options.method).toBe("POST");
27
+ expect(options.body).toContain("f=json");
28
+ expect(options.body).toContain("singleLine=LAX");
29
+ // the only property this lib tacks on
30
+ expect(response.spatialReference.wkid).toEqual(4326);
31
+ done();
32
+ })
33
+ .catch(e => {
34
+ fail(e);
35
+ });
36
+ });
37
+
38
+ it("should make a simple, single geocoding request with a custom parameter", done => {
39
+ fetchMock.once("*", FindAddressCandidates);
40
+
41
+ geocode({ params: { singleLine: "LAX", countryCode: "USA" } })
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
+ expect(options.body).toContain("countryCode=USA");
52
+ // the only property this lib tacks on
53
+ expect(response.spatialReference.wkid).toEqual(4326);
54
+ done();
55
+ })
56
+ .catch(e => {
57
+ fail(e);
58
+ });
59
+ });
60
+
61
+ it("should make a single geocoding request to a custom geocoding service", done => {
62
+ fetchMock.once("*", FindAddressCandidates);
63
+
64
+ geocode({
65
+ endpoint: customGeocoderUrl,
66
+ params: {
67
+ outSr: 3857,
68
+ address: "380 New York St",
69
+ postal: 92373
70
+ }
71
+ })
72
+ .then(response => {
73
+ expect(fetchMock.called()).toEqual(true);
74
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
75
+ expect(url).toEqual(
76
+ "https://foo.com/arcgis/rest/services/Custom/GeocodeServer/findAddressCandidates"
77
+ );
78
+ expect(options.method).toBe("POST");
79
+ expect(options.body).toContain("f=json");
80
+ expect(options.body).toContain(
81
+ `address=${encodeURIComponent("380 New York St")}`
82
+ );
83
+ expect(options.body).toContain("postal=92373");
84
+ expect(options.body).toContain("outSr=3857");
85
+ // the only property this lib tacks on
86
+ expect(response.spatialReference.wkid).toEqual(4326);
87
+ done();
88
+ })
89
+ .catch(e => {
90
+ fail(e);
91
+ });
92
+ });
93
+
94
+ it("should pass through all requestOptions when making a geocoding request", done => {
95
+ fetchMock.once("*", FindAddressCandidates);
96
+
97
+ geocode({
98
+ endpoint: customGeocoderUrl,
99
+ params: {
100
+ outSr: 3857,
101
+ address: "380 New York St",
102
+ postal: 92373
103
+ },
104
+ httpMethod: "GET"
105
+ })
106
+ .then(response => {
107
+ expect(fetchMock.called()).toEqual(true);
108
+ const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
109
+ expect(url).toEqual(
110
+ "https://foo.com/arcgis/rest/services/Custom/GeocodeServer/findAddressCandidates?f=json&outSr=3857&address=380%20New%20York%20St&postal=92373"
111
+ );
112
+ expect(options.method).toBe("GET");
113
+ // the only property this lib tacks on
114
+ expect(response.spatialReference.wkid).toEqual(4326);
115
+ done();
116
+ })
117
+ .catch(e => {
118
+ fail(e);
119
+ });
120
+ });
121
+ });