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,30 @@
1
+ import { IItem } from "@esri/arcgis-rest-common-types";
2
+
3
+ export const ItemSuccessResponse: any = {
4
+ success: true,
5
+ id: "3efakeitemid0000"
6
+ };
7
+
8
+ export const ItemResponse: IItem = {
9
+ id: "4bc",
10
+ owner: "jeffvader",
11
+ title: "DS Plans",
12
+ description: "The plans",
13
+ snippet: "Yeah these are the ones",
14
+ tags: ["plans", "star dust"],
15
+ type: "Web Map",
16
+ typeKeywords: ["Javascript", "hubSiteApplication"],
17
+ properties: {
18
+ parentId: "3eb"
19
+ },
20
+ created: 123,
21
+ modified: 456,
22
+ protected: false
23
+ };
24
+
25
+ export const ItemDataResponse: any = {
26
+ source: "3ef",
27
+ values: {
28
+ key: "value"
29
+ }
30
+ };
@@ -0,0 +1,28 @@
1
+ export const GetItemResourcesResponse: any = {
2
+ total: 3,
3
+ start: 1,
4
+ num: 3,
5
+ nextStart: -1,
6
+ resources: [
7
+ {
8
+ resource: "image/banner.jpg"
9
+ },
10
+ {
11
+ resource: "image/logo.jpg"
12
+ },
13
+ {
14
+ resource: "text/desc.txt"
15
+ }
16
+ ]
17
+ };
18
+
19
+ export const RemoveItemResourceResponse: any = {
20
+ success: true
21
+ };
22
+
23
+ export const UpdateItemResourceResponse: any = {
24
+ success: true,
25
+ itemId: "0c66beb52dff4994be67937cdadbdbf1",
26
+ owner: "jsmith",
27
+ folder: null
28
+ };
@@ -0,0 +1,60 @@
1
+ import { ISearchResult } from "../../src/items";
2
+
3
+ export const SearchResponse: ISearchResult = {
4
+ query: "",
5
+ total: 10795,
6
+ start: 1,
7
+ num: 1,
8
+ nextStart: 2,
9
+ results: [
10
+ {
11
+ id: "a5b",
12
+ owner: "dcadminqa",
13
+ created: 1496748288000,
14
+ modified: 1508856526000,
15
+ name: "survey123_7d7a9fabcb0c44bcaf1d6473cd088a07",
16
+ title: " Drug Activity Reporter",
17
+ type: "Feature Service",
18
+ typeKeywords: [
19
+ "ArcGIS Server",
20
+ "Data",
21
+ "Feature Access",
22
+ "Feature Service",
23
+ "OwnerView",
24
+ "Service",
25
+ "Survey123",
26
+ "Survey123 Hub",
27
+ "Hosted Service"
28
+ ],
29
+ description: "Some Description",
30
+ tags: [],
31
+ snippet: "Some Snippet",
32
+ thumbnail: "thumbnail/ago_downloaded.png",
33
+ documentation: "WAT docs",
34
+ extent: [[-180, -90], [180, 90]],
35
+ categories: [],
36
+ spatialReference: null,
37
+ accessInformation: null,
38
+ licenseInfo: null,
39
+ culture: null,
40
+ properties: {},
41
+ url:
42
+ "https://servicesqa.arcgis.com/97KLIFOSt5CxbiRI/arcgis/rest/services/survey123_7d7a9fabcb0c44bcaf1d6473cd088a07/FeatureServer",
43
+ proxyFilter: null,
44
+ access: "shared",
45
+ size: -1,
46
+ appCategories: [],
47
+ industries: [],
48
+ languages: [],
49
+ largeThumbnail: null,
50
+ banner: null,
51
+ screenshots: [],
52
+ listed: false,
53
+ numComments: 0,
54
+ numRatings: 0,
55
+ avgRating: 0,
56
+ numViews: 4,
57
+ protected: false
58
+ }
59
+ ]
60
+ };
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "include": [
4
+ "src/**/*.ts"
5
+ ]
6
+ }
@@ -0,0 +1,65 @@
1
+ [![npm version][npm-img]][npm-url]
2
+ [![build status][travis-img]][travis-url]
3
+ [![apache licensed](https://img.shields.io/badge/license-Apache-green.svg?style=flat-square)](https://raw.githubusercontent.com/Esri/arcgis-rest-js/master/LICENSE)
4
+
5
+ [npm-img]: https://img.shields.io/npm/v/@esri/arcgis-rest-request.svg?style=flat-square
6
+ [npm-url]: https://www.npmjs.com/package/@esri/arcgis-rest-request
7
+ [travis-img]: https://img.shields.io/travis/Esri/arcgis-rest-js/master.svg?style=flat-square
8
+ [travis-url]: https://travis-ci.org/Esri/arcgis-rest-js
9
+
10
+ # @esri/arcgis-rest-request
11
+
12
+ > A module for making requests to the ArcGIS REST API that runs in Node.js and modern browsers.
13
+
14
+ ### Example
15
+
16
+ ```bash
17
+ npm install @esri/arcgis-rest-request
18
+ ```
19
+
20
+ ```js
21
+ import { request } from '@esri/arcgis-rest-request';
22
+
23
+ const url = "https://www.arcgis.com/sharing/rest/content/items/6e03e8c26aad4b9c92a87c1063ddb0e3/data";
24
+
25
+ request(url)
26
+ .then(response => {
27
+ console.log(response) // WebMap JSON
28
+ });
29
+ ```
30
+
31
+ ### [API Reference](https://esri.github.io/arcgis-rest-js/api/request/)
32
+
33
+ ### Issues
34
+
35
+ If something isn't working the way you expected, please take a look at [previously logged issues](https://github.com/Esri/arcgis-rest-js/issues) first. Have you found a new bug? Want to request a new feature? We'd [**love**](https://github.com/Esri/arcgis-rest-js/issues/new) to hear from you.
36
+
37
+ If you're looking for help you can also post issues on [GIS Stackexchange](http://gis.stackexchange.com/questions/ask?tags=esri-oss).
38
+
39
+ ### Versioning
40
+
41
+ For transparency into the release cycle and in striving to maintain backward compatibility, @esri/arcgis-rest-js is maintained under Semantic Versioning guidelines and will adhere to these rules whenever possible.
42
+
43
+ For more information on SemVer, please visit <http://semver.org/>.
44
+
45
+ ### Contributing
46
+
47
+ Esri welcomes contributions from anyone and everyone. Please see our [guidelines for contributing](CONTRIBUTING.md).
48
+
49
+ ### License
50
+
51
+ Copyright &copy; 2017-2018 Esri
52
+
53
+ Licensed under the Apache License, Version 2.0 (the "License");
54
+ you may not use this file except in compliance with the License.
55
+ You may obtain a copy of the License at
56
+
57
+ > http://www.apache.org/licenses/LICENSE-2.0
58
+
59
+ Unless required by applicable law or agreed to in writing, software
60
+ distributed under the License is distributed on an "AS IS" BASIS,
61
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
62
+ See the License for the specific language governing permissions and
63
+ limitations under the License.
64
+
65
+ A copy of the license is available in the repository's [LICENSE](../../LICENSE) file.
@@ -0,0 +1,11 @@
1
+ {
2
+ "requires": true,
3
+ "lockfileVersion": 1,
4
+ "dependencies": {
5
+ "tslib": {
6
+ "version": "1.7.1",
7
+ "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.7.1.tgz",
8
+ "integrity": "sha1-vIAEFkaRkjp5/oN4u+s9ogF1OOw="
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@esri/arcgis-rest-request",
3
+ "version": "1.6.0",
4
+ "description": "Common methods and utilities for @esri/arcgis-rest-* packages.",
5
+ "main": "dist/node/index.js",
6
+ "browser": "dist/umd/request.umd.js",
7
+ "module": "dist/esm/index.js",
8
+ "js:next": "dist/esm/index.js",
9
+ "types": "dist/esm/index.d.ts",
10
+ "license": "Apache-2.0",
11
+ "dependencies": {
12
+ "tslib": "^1.7.1"
13
+ },
14
+ "files": [
15
+ "dist/**"
16
+ ],
17
+ "scripts": {
18
+ "prepare": "npm run build",
19
+ "build": "npm run build:node && npm run build:umd && npm run build:esm",
20
+ "build:esm": "tsc --module es2015 --outDir ./dist/esm --declaration",
21
+ "build:umd": "rollup -c ../../umd-base-profile.js && rollup -c ../../umd-production-profile.js",
22
+ "build:node": "tsc --module commonjs --outDir ./dist/node"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/Esri/arcgis-rest-js.git"
30
+ },
31
+ "contributors": [
32
+ {
33
+ "name": "Patrick Arlt",
34
+ "email": "parlt@esri.com",
35
+ "url": "http://patrickarlt.com/"
36
+ }
37
+ ],
38
+ "bugs": {
39
+ "url": "https://github.com/Esri/arcgis-rest-js/issues"
40
+ },
41
+ "homepage": "https://github.com/Esri/arcgis-rest-js#readme"
42
+ }
@@ -0,0 +1,10 @@
1
+ export * from "./request";
2
+ export * from "./utils/encode-form-data";
3
+ export * from "./utils/encode-query-string";
4
+ export * from "./utils/check-for-errors";
5
+ export * from "./utils/ArcGISRequestError";
6
+ export * from "./utils/ArcGISAuthError";
7
+ export * from "./utils/ErrorTypes";
8
+ export * from "./utils/process-params";
9
+ export * from "./utils/get-portal";
10
+ export * from "./utils/get-portal-url";
@@ -0,0 +1,259 @@
1
+ /* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
2
+ * Apache-2.0 */
3
+
4
+ import { checkForErrors } from "./utils/check-for-errors";
5
+ import { encodeFormData } from "./utils/encode-form-data";
6
+ import { encodeQueryString } from "./utils/encode-query-string";
7
+ import { requiresFormData } from "./utils/process-params";
8
+ import { ArcGISRequestError } from "./utils/ArcGISRequestError";
9
+
10
+ /**
11
+ * Authentication can be supplied to `request` via [`UserSession`](../../auth/UserSession/) or [`ApplicationSession`](../../auth/ApplicationSession/). Both classes extend `IAuthenticationManager`.
12
+ * ```js
13
+ * const session = new UserSession({
14
+ * username: "jsmith",
15
+ * password: "123456",
16
+ * // optional
17
+ * portal: "https://[yourserver]/arcgis/sharing/rest"
18
+ * })
19
+ *
20
+ * request(url, { authentication: session })
21
+ * ```
22
+ */
23
+ export interface IAuthenticationManager {
24
+ /**
25
+ * Defaults to 'https://www.arcgis.com/sharing/rest'.
26
+ */
27
+ portal: string;
28
+ getToken(url: string): Promise<string>;
29
+ }
30
+
31
+ /**
32
+ * HTTP methods used by the ArcGIS REST API.
33
+ */
34
+ export type HTTPMethods = "GET" | "POST";
35
+
36
+ /**
37
+ * Valid response formats for the `f` parameter.
38
+ */
39
+ export type ResponseFormats =
40
+ | "json"
41
+ | "geojson"
42
+ | "text"
43
+ | "html"
44
+ | "image"
45
+ | "zip";
46
+
47
+ export interface IParams {
48
+ f?: ResponseFormats;
49
+ [key: string]: any;
50
+ }
51
+
52
+ /**
53
+ * Options for the `request()` method.
54
+ */
55
+ export interface IRequestOptions {
56
+ /**
57
+ * Additional parameters to pass in the request.
58
+ */
59
+ params?: IParams;
60
+
61
+ /**
62
+ * The HTTP method to send the request with.
63
+ */
64
+ httpMethod?: HTTPMethods;
65
+
66
+ /**
67
+ * The instance of `IAuthenticationManager` to use to authenticate this request.
68
+ */
69
+ authentication?: IAuthenticationManager;
70
+
71
+ /**
72
+ * Base url for the portal you want to make the request to. Defaults to 'https://www.arcgis.com/sharing/rest'.
73
+ */
74
+ portal?: string;
75
+
76
+ /**
77
+ * The implementation of `fetch` to use. Defaults to a global `fetch`.
78
+ */
79
+ fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
80
+
81
+ /**
82
+ * If the length of a GET request's URL exceeds `maxUrlLength` the request will use POST instead.
83
+ */
84
+ maxUrlLength?: number;
85
+ }
86
+
87
+ /**
88
+ * Generic method for making HTTP requests to ArcGIS REST API endpoints.
89
+ *
90
+ * ```js
91
+ * import { request } from '@esri/arcgis-rest-request';
92
+ *
93
+ * request('https://www.arcgis.com/sharing/rest')
94
+ * .then((response) => {
95
+ * console.log(response.currentVersion); // => 5.2
96
+ * });
97
+ * ```
98
+ *
99
+ * ```js
100
+ * import { request, HTTPMethods } from '@esri/arcgis-rest-request';
101
+ *
102
+ * request('https://www.arcgis.com/sharing/rest', {
103
+ * httpMethod: "GET"
104
+ * }).then((response) => {
105
+ * console.log(response.currentVersion); // => 5.2
106
+ * });
107
+ * ```
108
+ *
109
+ * ```js
110
+ * import { request, HTTPMethods } from '@esri/arcgis-rest-request';
111
+ *
112
+ * request('https://www.arcgis.com/sharing/rest/search', {
113
+ * params: { q: 'parks' }
114
+ * }).then((response) => {
115
+ * console.log(response.total); // => 78379
116
+ * });
117
+ * ```
118
+ *
119
+ * @param url - The URL of the ArcGIS REST API endpoint.
120
+ * @param requestOptions - Options for the request, including parameters relevant to the endpoint.
121
+ * @returns A Promise that will resolve with the data from the response.
122
+ */
123
+ export function request(
124
+ url: string,
125
+ requestOptions: IRequestOptions = { params: { f: "json" } }
126
+ ): Promise<any> {
127
+ const options: IRequestOptions = {
128
+ httpMethod: "POST",
129
+ fetch,
130
+ ...requestOptions
131
+ };
132
+
133
+ const missingGlobals: string[] = [];
134
+ const recommendedPackages: string[] = [];
135
+
136
+ if (!options.fetch) {
137
+ missingGlobals.push("`fetch`");
138
+ recommendedPackages.push("`isomorphic-fetch`");
139
+ }
140
+
141
+ if (!Promise) {
142
+ missingGlobals.push("`Promise`");
143
+ recommendedPackages.push("`es6-promise`");
144
+ }
145
+
146
+ if (!FormData) {
147
+ missingGlobals.push("`FormData`");
148
+ recommendedPackages.push("`isomorphic-form-data`");
149
+ }
150
+
151
+ if (!options.fetch || !Promise || !FormData) {
152
+ throw new Error(
153
+ `\`arcgis-rest-request\` requires global variables for \`fetch\`, \`Promise\` and \`FormData\` to be present in the global scope. You are missing ${missingGlobals.join(
154
+ ", "
155
+ )}. We recommend installing the ${recommendedPackages.join(
156
+ ", "
157
+ )} modules at the root of your application to add these to the global scope. See https://bit.ly/2KNwWaJ for more info.`
158
+ );
159
+ }
160
+
161
+ if (options.fetch === fetch) {
162
+ options.fetch = fetch.bind(Function("return this")());
163
+ }
164
+
165
+ const { httpMethod, authentication } = options;
166
+
167
+ const params: IParams = {
168
+ ...{ f: "json" },
169
+ ...requestOptions.params
170
+ };
171
+
172
+ const fetchOptions: RequestInit = {
173
+ method: httpMethod,
174
+ // ensures behavior mimics XMLHttpRequest. needed to support sending IWA cookies
175
+ credentials: "same-origin"
176
+ };
177
+
178
+ return (authentication ? authentication.getToken(url) : Promise.resolve(""))
179
+ .then(token => {
180
+ if (token.length) {
181
+ params.token = token;
182
+ }
183
+
184
+ if (fetchOptions.method === "GET") {
185
+ // encode the parameters into the query string
186
+ const queryParams = encodeQueryString(params);
187
+ // dont append a '?' unless parameters are actually present
188
+ const urlWithQueryString =
189
+ queryParams === "" ? url : url + "?" + encodeQueryString(params);
190
+
191
+ if (
192
+ options.maxUrlLength &&
193
+ urlWithQueryString.length > options.maxUrlLength
194
+ ) {
195
+ // the consumer specified a maximum length for URLs
196
+ // and this would exceed it, so use post instead
197
+ fetchOptions.method = "POST";
198
+ } else {
199
+ // just use GET
200
+ url = urlWithQueryString;
201
+ }
202
+ }
203
+
204
+ if (fetchOptions.method === "POST") {
205
+ fetchOptions.body = encodeFormData(params);
206
+ }
207
+
208
+ /* istanbul ignore else blob responses are difficult to make cross platform we will just have to trust the isomorphic fetch will do its job */
209
+ if (!requiresFormData(params)) {
210
+ fetchOptions.headers = new Headers();
211
+ fetchOptions.headers.append(
212
+ "Content-Type",
213
+ "application/x-www-form-urlencoded"
214
+ );
215
+ }
216
+
217
+ return options.fetch(url, fetchOptions);
218
+ })
219
+ .then(response => {
220
+ if (!response.ok) {
221
+ // server responded w/ an actual error (404, 500, etc)
222
+ const { status, statusText } = response;
223
+ throw new ArcGISRequestError(
224
+ statusText,
225
+ `HTTP ${status}`,
226
+ response,
227
+ url,
228
+ options
229
+ );
230
+ }
231
+ switch (params.f) {
232
+ case "json":
233
+ return response.json();
234
+ case "geojson":
235
+ return response.json();
236
+ case "html":
237
+ return response.text();
238
+ case "text":
239
+ return response.text();
240
+ /* istanbul ignore next blob responses are difficult to make cross platform we will just have to trust the isomorphic fetch will do its job */
241
+ case "image":
242
+ return response.blob();
243
+ /* istanbul ignore next */
244
+ case "zip":
245
+ return response.blob();
246
+ /* istanbul ignore next */
247
+ default:
248
+ // hopefully we never need to handle JSON payloads when no f= parameter is set
249
+ return response.blob();
250
+ }
251
+ })
252
+ .then(data => {
253
+ if (params.f === "json" || params.f === "geojson") {
254
+ return checkForErrors(data, url, params, options);
255
+ } else {
256
+ return data;
257
+ }
258
+ });
259
+ }
@@ -0,0 +1,67 @@
1
+ /* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
2
+ * Apache-2.0 */
3
+
4
+ import { request, IRequestOptions, IAuthenticationManager } from "../request";
5
+ import { ArcGISRequestError } from "./ArcGISRequestError";
6
+
7
+ export type IRetryAuthError = (
8
+ url: string,
9
+ options: IRequestOptions
10
+ ) => Promise<IAuthenticationManager>;
11
+
12
+ export class ArcGISAuthError extends ArcGISRequestError {
13
+ /**
14
+ * Create a new `ArcGISAuthError` object.
15
+ *
16
+ * @param message - The error message from the API
17
+ * @param code - The error code from the API
18
+ * @param response - The original response from the API that caused the error
19
+ * @param url - The original url of the request
20
+ * @param options - The original options of the request
21
+ */
22
+ constructor(
23
+ message = "AUTHENTICATION_ERROR",
24
+ code: string | number = "AUTHENTICATION_ERROR_CODE",
25
+ response?: any,
26
+ url?: string,
27
+ options?: IRequestOptions
28
+ ) {
29
+ super(message, code, response, url, options);
30
+ this.name = "ArcGISAuthError";
31
+ this.message =
32
+ code === "AUTHENTICATION_ERROR_CODE" ? message : `${code}: ${message}`;
33
+ }
34
+
35
+ retry(getSession: IRetryAuthError, retryLimit = 3) {
36
+ let tries = 0;
37
+
38
+ const retryRequest = (resolve: any, reject: any) => {
39
+ getSession(this.url, this.options)
40
+ .then(session => {
41
+ const newOptions = {
42
+ ...this.options,
43
+ ...{ authentication: session }
44
+ };
45
+
46
+ tries = tries + 1;
47
+ return request(this.url, newOptions);
48
+ })
49
+ .then(response => {
50
+ resolve(response);
51
+ })
52
+ .catch(e => {
53
+ if (e.name === "ArcGISAuthError" && tries < retryLimit) {
54
+ retryRequest(resolve, reject);
55
+ } else if (e.name === "ArcGISAuthError" && tries >= retryLimit) {
56
+ reject(this);
57
+ } else {
58
+ reject(e);
59
+ }
60
+ });
61
+ };
62
+
63
+ return new Promise((resolve, reject) => {
64
+ retryRequest(resolve, reject);
65
+ });
66
+ }
67
+ }
@@ -0,0 +1,73 @@
1
+ /* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
2
+ * Apache-2.0 */
3
+
4
+ import { IRequestOptions } from "../request";
5
+
6
+ // TypeScript 2.1 no longer allows you to extend built in types. See https://github.com/Microsoft/TypeScript/issues/12790#issuecomment-265981442
7
+ // and https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
8
+ //
9
+ // This code is from MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types.
10
+ export class ArcGISRequestError {
11
+ /**
12
+ * The name of this error. Will always be `"ArcGISRequestError"` to conform with the [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) class.
13
+ */
14
+ name: string;
15
+
16
+ /**
17
+ * Formatted error message. See the [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) class for more details.
18
+ */
19
+ message: string;
20
+
21
+ /**
22
+ * The errror message return from the request.
23
+ */
24
+ originalMessage: string;
25
+
26
+ /**
27
+ * The error code returned from the request.
28
+ */
29
+ code: string | number;
30
+
31
+ /**
32
+ * The original JSON response the caused the error.
33
+ */
34
+ response: any;
35
+
36
+ /**
37
+ * The URL of the original request that caused the error
38
+ */
39
+ url: string;
40
+
41
+ /**
42
+ * The options of the original request that caused the error
43
+ */
44
+ options: IRequestOptions;
45
+
46
+ /**
47
+ * Create a new `ArcGISRequestError` object.
48
+ *
49
+ * @param message - The error message from the API
50
+ * @param code - The error code from the API
51
+ * @param response - The original response from the API that caused the error
52
+ * @param url - The original url of the request
53
+ * @param options - The original options and parameters of the request
54
+ */
55
+ constructor(
56
+ message = "UNKNOWN_ERROR",
57
+ code: string | number = "UNKNOWN_ERROR_CODE",
58
+ response?: any,
59
+ url?: string,
60
+ options?: IRequestOptions
61
+ ) {
62
+ this.name = "ArcGISRequestError";
63
+ this.message =
64
+ code === "UNKNOWN_ERROR_CODE" ? message : `${code}: ${message}`;
65
+ this.originalMessage = message;
66
+ this.code = code;
67
+ this.response = response;
68
+ this.url = url;
69
+ this.options = options;
70
+ }
71
+ }
72
+ ArcGISRequestError.prototype = Object.create(Error.prototype);
73
+ ArcGISRequestError.prototype.constructor = ArcGISRequestError;
@@ -0,0 +1,29 @@
1
+ /* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
2
+ * Apache-2.0 */
3
+
4
+ /**
5
+ * Enum describing the different errors that might be thrown by a request.
6
+ *
7
+ * ```ts
8
+ * import { request, ErrorTypes } from '@esri/arcgis-rest-request';
9
+ *
10
+ * request("...").catch((e) => {
11
+ * switch(e.name) {
12
+ * case ErrorType.ArcGISRequestError:
13
+ * // handle a general error from the API
14
+ * break;
15
+ *
16
+ * case ErrorType.ArcGISAuthError:
17
+ * // handle an authentication error
18
+ * break;
19
+ *
20
+ * default:
21
+ * // handle some other error (usually a network error)
22
+ * }
23
+ * });
24
+ * ```
25
+ */
26
+ export enum ErrorTypes {
27
+ ArcGISRequestError = "ArcGISRequestError",
28
+ ArcGISAuthError = "ArcGISAuthError"
29
+ }