impeditmaiores 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.prettierignore +2 -0
- package/.travis.yml +35 -0
- package/.vscode/launch.json +24 -0
- package/.vscode/settings.json +3 -0
- package/codecov.yml +7 -0
- package/demos/ago-node-cli/README.md +29 -0
- package/demos/ago-node-cli/ago.js +33 -0
- package/demos/ago-node-cli/index.js +11 -0
- package/demos/ago-node-cli/lib/item-export-command.js +48 -0
- package/demos/ago-node-cli/lib/item-search-command.js +35 -0
- package/demos/ago-node-cli/package-lock.json +152 -0
- package/demos/ago-node-cli/package.json +30 -0
- package/demos/attachments/README.md +5 -0
- package/demos/attachments/index.html +165 -0
- package/demos/attachments/package-lock.json +182 -0
- package/demos/attachments/package.json +18 -0
- package/demos/batch-geocoder-node/NYC_Restaurant_Inspection_Results.csv +100 -0
- package/demos/batch-geocoder-node/README.md +15 -0
- package/demos/batch-geocoder-node/batch-geocode.js +115 -0
- package/demos/batch-geocoder-node/config-template.js +18 -0
- package/demos/batch-geocoder-node/package-lock.json +81 -0
- package/demos/batch-geocoder-node/package.json +37 -0
- package/demos/express/README.md +15 -0
- package/demos/express/config.json.template +3 -0
- package/demos/express/package-lock.json +413 -0
- package/demos/express/package.json +18 -0
- package/demos/express/server.js +33 -0
- package/demos/feature-service-browser/README.md +6 -0
- package/demos/feature-service-browser/index.html +122 -0
- package/demos/feature-service-browser/package-lock.json +182 -0
- package/demos/feature-service-browser/package.json +18 -0
- package/demos/geocoder-browser/README.md +10 -0
- package/demos/geocoder-browser/config.js.template +1 -0
- package/demos/geocoder-browser/index.html +131 -0
- package/demos/geocoder-browser/package-lock.json +182 -0
- package/demos/geocoder-browser/package.json +19 -0
- package/demos/geocoder-browser/post-sign-in.html +25 -0
- package/demos/jsapi-integration/README.md +25 -0
- package/demos/jsapi-integration/config.js +6 -0
- package/demos/jsapi-integration/index.html +89 -0
- package/demos/jsapi-integration/package-lock.json +184 -0
- package/demos/jsapi-integration/package.json +19 -0
- package/demos/node-cli-item-management/README.md +10 -0
- package/demos/node-cli-item-management/index.js +238 -0
- package/demos/node-cli-item-management/package-lock.json +152 -0
- package/demos/node-cli-item-management/package.json +27 -0
- package/demos/node-cli-item-management/screenshot.png +0 -0
- package/demos/oauth2-browser/README.md +14 -0
- package/demos/oauth2-browser/authenticate.html +30 -0
- package/demos/oauth2-browser/config.js.template +6 -0
- package/demos/oauth2-browser/index.html +211 -0
- package/demos/oauth2-browser/logo.svg +4 -0
- package/demos/oauth2-browser/package-lock.json +224 -0
- package/demos/oauth2-browser/package.json +18 -0
- package/demos/oauth2-browser/style.css +36 -0
- package/demos/oauth2-browser-retry/README.md +25 -0
- package/demos/oauth2-browser-retry/authenticate.html +22 -0
- package/demos/oauth2-browser-retry/index.html +116 -0
- package/demos/oauth2-browser-retry/logo.svg +4 -0
- package/demos/stream-response-to-file/README.md +7 -0
- package/demos/stream-response-to-file/index.js +36 -0
- package/demos/stream-response-to-file/output/.gitkeep +0 -0
- package/demos/stream-response-to-file/package-lock.json +60 -0
- package/demos/stream-response-to-file/package.json +33 -0
- package/demos/tree-shaking-rollup/.babelrc +3 -0
- package/demos/tree-shaking-rollup/README.md +9 -0
- package/demos/tree-shaking-rollup/index.html +11 -0
- package/demos/tree-shaking-rollup/package-lock.json +2225 -0
- package/demos/tree-shaking-rollup/package.json +25 -0
- package/demos/tree-shaking-rollup/rollup.config.js +17 -0
- package/demos/tree-shaking-rollup/src/index.js +8 -0
- package/demos/tree-shaking-webpack/README.md +8 -0
- package/demos/tree-shaking-webpack/index.html +11 -0
- package/demos/tree-shaking-webpack/package-lock.json +4614 -0
- package/demos/tree-shaking-webpack/package.json +24 -0
- package/demos/tree-shaking-webpack/src/index.js +10 -0
- package/demos/tree-shaking-webpack/webpack.config.js +27 -0
- package/demos/vue/.env.example +11 -0
- package/demos/vue/.eslintrc.js +17 -0
- package/demos/vue/.postcssrc.js +5 -0
- package/demos/vue/README.md +17 -0
- package/demos/vue/babel.config.js +3 -0
- package/demos/vue/package-lock.json +11342 -0
- package/demos/vue/package.json +33 -0
- package/demos/vue/public/favicon.ico +0 -0
- package/demos/vue/public/index.html +24 -0
- package/demos/vue/src/assets/logo.svg +29 -0
- package/demos/vue/src/components/App.vue +305 -0
- package/demos/vue/src/components/Authenticate.vue +65 -0
- package/demos/vue/src/components/Loader.vue +230 -0
- package/demos/vue/src/main.js +92 -0
- package/demos/webmap-checker-sapper/.env.example +5 -0
- package/demos/webmap-checker-sapper/README.md +123 -0
- package/demos/webmap-checker-sapper/appveyor.yml +18 -0
- package/demos/webmap-checker-sapper/cypress/fixtures/example.json +5 -0
- package/demos/webmap-checker-sapper/cypress/integration/spec.js +19 -0
- package/demos/webmap-checker-sapper/cypress/plugins/index.js +17 -0
- package/demos/webmap-checker-sapper/cypress/support/commands.js +25 -0
- package/demos/webmap-checker-sapper/cypress/support/index.js +20 -0
- package/demos/webmap-checker-sapper/cypress.json +4 -0
- package/demos/webmap-checker-sapper/package-lock.json +3870 -0
- package/demos/webmap-checker-sapper/package.json +50 -0
- package/demos/webmap-checker-sapper/rollup.config.js +87 -0
- package/demos/webmap-checker-sapper/src/client.js +20 -0
- package/demos/webmap-checker-sapper/src/components/LayerStatus.html +108 -0
- package/demos/webmap-checker-sapper/src/components/Nav.html +21 -0
- package/demos/webmap-checker-sapper/src/components/WebMap.html +62 -0
- package/demos/webmap-checker-sapper/src/routes/_error.html +41 -0
- package/demos/webmap-checker-sapper/src/routes/_layout.html +21 -0
- package/demos/webmap-checker-sapper/src/routes/auth/authorize.js +18 -0
- package/demos/webmap-checker-sapper/src/routes/auth/exchange-token.js +20 -0
- package/demos/webmap-checker-sapper/src/routes/auth/post-sign-in.js +24 -0
- package/demos/webmap-checker-sapper/src/routes/auth/sign-out.js +10 -0
- package/demos/webmap-checker-sapper/src/routes/index.html +20 -0
- package/demos/webmap-checker-sapper/src/routes/webmaps/[webmapId].html +83 -0
- package/demos/webmap-checker-sapper/src/routes/webmaps/index.html +59 -0
- package/demos/webmap-checker-sapper/src/server.js +101 -0
- package/demos/webmap-checker-sapper/src/service-worker.js +82 -0
- package/demos/webmap-checker-sapper/src/template.html +33 -0
- package/demos/webmap-checker-sapper/src/userInfoMiddleware.js +21 -0
- package/demos/webmap-checker-sapper/src/utils.js +33 -0
- package/demos/webmap-checker-sapper/static/favicon.png +0 -0
- package/demos/webmap-checker-sapper/static/global.css +36 -0
- package/demos/webmap-checker-sapper/static/manifest.json +20 -0
- package/demos/webmap-checker-sapper/static/svelte-logo-192.png +0 -0
- package/demos/webmap-checker-sapper/static/svelte-logo-512.png +0 -0
- package/docs/FAQ.md +48 -0
- package/docs/HISTORY.md +62 -0
- package/docs/acetate.config.js +262 -0
- package/docs/build-typedoc.js +434 -0
- package/docs/generate-srihashes.js +53 -0
- package/docs/src/_layout.html +86 -0
- package/docs/src/api/_declaration.html +600 -0
- package/docs/src/api/_layout.html +204 -0
- package/docs/src/api/_package.html +38 -0
- package/docs/src/api/index.html +16 -0
- package/docs/src/guides/_layout.html +24 -0
- package/docs/src/guides/amd-requirejs-dojo.md +40 -0
- package/docs/src/guides/browser-authentication.md +41 -0
- package/docs/src/guides/bundlers.md +52 -0
- package/docs/src/guides/cli-authentication.md +9 -0
- package/docs/src/guides/client-server-authentication.md +9 -0
- package/docs/src/guides/embedded-apps.md +93 -0
- package/docs/src/guides/from-a-cdn.md +38 -0
- package/docs/src/guides/index.md +59 -0
- package/docs/src/guides/node.md +87 -0
- package/docs/src/guides/package-overview.md +111 -0
- package/docs/src/guides/server-authentication.md +9 -0
- package/docs/src/guides/whats-new-v2-0.md +305 -0
- package/docs/src/img/icons.png +0 -0
- package/docs/src/img/icons@2x.png +0 -0
- package/docs/src/index.html +12 -0
- package/docs/src/js/api-search.js +112 -0
- package/docs/src/js/nav-toggle.js +41 -0
- package/docs/src/sass/_highlight.scss +96 -0
- package/docs/src/sass/_icons.scss +157 -0
- package/docs/src/sass/style.scss +242 -0
- package/docs/src/srihashes.json +12 -0
- package/jasmine.json +7 -0
- package/karma.conf.js +106 -0
- package/lerna.json +8 -0
- package/notes/README.md +68 -0
- package/package.json +87 -0
- package/packages/arcgis-rest-auth/README.md +71 -0
- package/packages/arcgis-rest-auth/package-lock.json +11 -0
- package/packages/arcgis-rest-auth/package.json +69 -0
- package/packages/arcgis-rest-auth/src/ApplicationSession.ts +122 -0
- package/packages/arcgis-rest-auth/src/UserSession.ts +1206 -0
- package/packages/arcgis-rest-auth/src/app-tokens.ts +91 -0
- package/packages/arcgis-rest-auth/src/authenticated-request-options.ts +24 -0
- package/packages/arcgis-rest-auth/src/federation-utils.ts +85 -0
- package/packages/arcgis-rest-auth/src/fetch-token.ts +50 -0
- package/packages/arcgis-rest-auth/src/generate-token.ts +35 -0
- package/packages/arcgis-rest-auth/src/index.ts +9 -0
- package/packages/arcgis-rest-auth/src/validate-app-access.ts +68 -0
- package/packages/arcgis-rest-auth/test/ApplicationSession.test.ts +124 -0
- package/packages/arcgis-rest-auth/test/UserSession.test.ts +1807 -0
- package/packages/arcgis-rest-auth/test/app-tokens.test.ts +91 -0
- package/packages/arcgis-rest-auth/test/federation-utils.test.ts +323 -0
- package/packages/arcgis-rest-auth/test/fetchToken.test.ts +112 -0
- package/packages/arcgis-rest-auth/test/generateToken.test.ts +102 -0
- package/packages/arcgis-rest-auth/test/utils.ts +14 -0
- package/packages/arcgis-rest-auth/test/validate-app-access.test.ts +46 -0
- package/packages/arcgis-rest-auth/tsconfig.json +6 -0
- package/packages/arcgis-rest-feature-layer/README.md +77 -0
- package/packages/arcgis-rest-feature-layer/package-lock.json +11 -0
- package/packages/arcgis-rest-feature-layer/package.json +64 -0
- package/packages/arcgis-rest-feature-layer/src/add.ts +56 -0
- package/packages/arcgis-rest-feature-layer/src/addAttachment.ts +53 -0
- package/packages/arcgis-rest-feature-layer/src/applyEdits.ts +90 -0
- package/packages/arcgis-rest-feature-layer/src/decodeValues.ts +124 -0
- package/packages/arcgis-rest-feature-layer/src/delete.ts +61 -0
- package/packages/arcgis-rest-feature-layer/src/deleteAttachments.ts +52 -0
- package/packages/arcgis-rest-feature-layer/src/getAttachments.ts +55 -0
- package/packages/arcgis-rest-feature-layer/src/getLayer.ts +24 -0
- package/packages/arcgis-rest-feature-layer/src/getService.ts +26 -0
- package/packages/arcgis-rest-feature-layer/src/helpers.ts +79 -0
- package/packages/arcgis-rest-feature-layer/src/index.ts +31 -0
- package/packages/arcgis-rest-feature-layer/src/query.ts +204 -0
- package/packages/arcgis-rest-feature-layer/src/queryRelated.ts +89 -0
- package/packages/arcgis-rest-feature-layer/src/update.ts +56 -0
- package/packages/arcgis-rest-feature-layer/src/updateAttachment.ts +59 -0
- package/packages/arcgis-rest-feature-layer/test/attachments.test.ts +200 -0
- package/packages/arcgis-rest-feature-layer/test/crud.test.ts +195 -0
- package/packages/arcgis-rest-feature-layer/test/decodeValues.test.ts +67 -0
- package/packages/arcgis-rest-feature-layer/test/getLayer.test.ts +31 -0
- package/packages/arcgis-rest-feature-layer/test/getService.test.ts +31 -0
- package/packages/arcgis-rest-feature-layer/test/mocks/cvdQueryResponse.ts +225 -0
- package/packages/arcgis-rest-feature-layer/test/mocks/feature.ts +302 -0
- package/packages/arcgis-rest-feature-layer/test/mocks/fields.ts +779 -0
- package/packages/arcgis-rest-feature-layer/test/mocks/foo.txt +1 -0
- package/packages/arcgis-rest-feature-layer/test/mocks/service.ts +398 -0
- package/packages/arcgis-rest-feature-layer/test/query.test.ts +167 -0
- package/packages/arcgis-rest-feature-layer/tsconfig.json +6 -0
- package/packages/arcgis-rest-geocoding/README.md +86 -0
- package/packages/arcgis-rest-geocoding/package-lock.json +11 -0
- package/packages/arcgis-rest-geocoding/package.json +64 -0
- package/packages/arcgis-rest-geocoding/src/bulk.ts +104 -0
- package/packages/arcgis-rest-geocoding/src/geocode.ts +133 -0
- package/packages/arcgis-rest-geocoding/src/helpers.ts +54 -0
- package/packages/arcgis-rest-geocoding/src/index.ts +15 -0
- package/packages/arcgis-rest-geocoding/src/reverse.ts +84 -0
- package/packages/arcgis-rest-geocoding/src/suggest.ts +45 -0
- package/packages/arcgis-rest-geocoding/test/bulk.test.ts +194 -0
- package/packages/arcgis-rest-geocoding/test/geocode.test.ts +249 -0
- package/packages/arcgis-rest-geocoding/test/helpers.test.ts +85 -0
- package/packages/arcgis-rest-geocoding/test/mocks/responses.ts +637 -0
- package/packages/arcgis-rest-geocoding/test/reverse.test.ts +126 -0
- package/packages/arcgis-rest-geocoding/test/suggest.test.ts +53 -0
- package/packages/arcgis-rest-geocoding/tsconfig.json +6 -0
- package/packages/arcgis-rest-portal/README.md +73 -0
- package/packages/arcgis-rest-portal/package-lock.json +11 -0
- package/packages/arcgis-rest-portal/package.json +64 -0
- package/packages/arcgis-rest-portal/src/groups/add-users.ts +140 -0
- package/packages/arcgis-rest-portal/src/groups/create.ts +43 -0
- package/packages/arcgis-rest-portal/src/groups/get.ts +184 -0
- package/packages/arcgis-rest-portal/src/groups/helpers.ts +14 -0
- package/packages/arcgis-rest-portal/src/groups/invite-users.ts +127 -0
- package/packages/arcgis-rest-portal/src/groups/join.ts +57 -0
- package/packages/arcgis-rest-portal/src/groups/notification.ts +77 -0
- package/packages/arcgis-rest-portal/src/groups/protect.ts +56 -0
- package/packages/arcgis-rest-portal/src/groups/remove-users.ts +76 -0
- package/packages/arcgis-rest-portal/src/groups/remove.ts +32 -0
- package/packages/arcgis-rest-portal/src/groups/search.ts +47 -0
- package/packages/arcgis-rest-portal/src/groups/update-user-membership.ts +63 -0
- package/packages/arcgis-rest-portal/src/groups/update.ts +39 -0
- package/packages/arcgis-rest-portal/src/index.ts +66 -0
- package/packages/arcgis-rest-portal/src/items/add.ts +138 -0
- package/packages/arcgis-rest-portal/src/items/content.ts +67 -0
- package/packages/arcgis-rest-portal/src/items/create.ts +150 -0
- package/packages/arcgis-rest-portal/src/items/export.ts +80 -0
- package/packages/arcgis-rest-portal/src/items/get.ts +437 -0
- package/packages/arcgis-rest-portal/src/items/helpers.ts +275 -0
- package/packages/arcgis-rest-portal/src/items/protect.ts +41 -0
- package/packages/arcgis-rest-portal/src/items/reassign.ts +61 -0
- package/packages/arcgis-rest-portal/src/items/remove.ts +135 -0
- package/packages/arcgis-rest-portal/src/items/search.ts +25 -0
- package/packages/arcgis-rest-portal/src/items/update.ts +184 -0
- package/packages/arcgis-rest-portal/src/items/upload.ts +125 -0
- package/packages/arcgis-rest-portal/src/orgs/notification.ts +131 -0
- package/packages/arcgis-rest-portal/src/sharing/access.ts +84 -0
- package/packages/arcgis-rest-portal/src/sharing/helpers.ts +81 -0
- package/packages/arcgis-rest-portal/src/sharing/is-item-shared-with-group.ts +42 -0
- package/packages/arcgis-rest-portal/src/sharing/share-item-with-group.ts +319 -0
- package/packages/arcgis-rest-portal/src/sharing/unshare-item-with-group.ts +105 -0
- package/packages/arcgis-rest-portal/src/users/get-user-tags.ts +52 -0
- package/packages/arcgis-rest-portal/src/users/get-user-url.ts +18 -0
- package/packages/arcgis-rest-portal/src/users/get-user.ts +58 -0
- package/packages/arcgis-rest-portal/src/users/invitation.ts +156 -0
- package/packages/arcgis-rest-portal/src/users/notification.ts +68 -0
- package/packages/arcgis-rest-portal/src/users/search-users.ts +37 -0
- package/packages/arcgis-rest-portal/src/users/update.ts +66 -0
- package/packages/arcgis-rest-portal/src/util/SearchQueryBuilder.ts +374 -0
- package/packages/arcgis-rest-portal/src/util/array.ts +16 -0
- package/packages/arcgis-rest-portal/src/util/generic-search.ts +99 -0
- package/packages/arcgis-rest-portal/src/util/get-portal-settings.ts +45 -0
- package/packages/arcgis-rest-portal/src/util/get-portal-url.ts +27 -0
- package/packages/arcgis-rest-portal/src/util/get-portal.ts +52 -0
- package/packages/arcgis-rest-portal/src/util/get-subscription-info.ts +43 -0
- package/packages/arcgis-rest-portal/src/util/scrub-control-chars.ts +12 -0
- package/packages/arcgis-rest-portal/src/util/search.ts +42 -0
- package/packages/arcgis-rest-portal/test/groups/add-users.test.ts +239 -0
- package/packages/arcgis-rest-portal/test/groups/crud.test.ts +180 -0
- package/packages/arcgis-rest-portal/test/groups/get.test.ts +176 -0
- package/packages/arcgis-rest-portal/test/groups/invite-users.test.ts +149 -0
- package/packages/arcgis-rest-portal/test/groups/join.test.ts +72 -0
- package/packages/arcgis-rest-portal/test/groups/notification.test.ts +112 -0
- package/packages/arcgis-rest-portal/test/groups/protect.test.ts +72 -0
- package/packages/arcgis-rest-portal/test/groups/remove-users.test.ts +140 -0
- package/packages/arcgis-rest-portal/test/groups/search.test.ts +151 -0
- package/packages/arcgis-rest-portal/test/groups/update-user-membership.test.ts +62 -0
- package/packages/arcgis-rest-portal/test/items/add.test.ts +323 -0
- package/packages/arcgis-rest-portal/test/items/content.test.ts +156 -0
- package/packages/arcgis-rest-portal/test/items/create.test.ts +399 -0
- package/packages/arcgis-rest-portal/test/items/export.test.ts +122 -0
- package/packages/arcgis-rest-portal/test/items/get.test.ts +583 -0
- package/packages/arcgis-rest-portal/test/items/helpers.test.ts +60 -0
- package/packages/arcgis-rest-portal/test/items/protect.test.ts +122 -0
- package/packages/arcgis-rest-portal/test/items/reassign.test.ts +131 -0
- package/packages/arcgis-rest-portal/test/items/remove.test.ts +238 -0
- package/packages/arcgis-rest-portal/test/items/search.test.ts +272 -0
- package/packages/arcgis-rest-portal/test/items/update.test.ts +554 -0
- package/packages/arcgis-rest-portal/test/items/upload.test.ts +282 -0
- package/packages/arcgis-rest-portal/test/mocks/groups/responses.ts +208 -0
- package/packages/arcgis-rest-portal/test/mocks/items/foo.zip +0 -0
- package/packages/arcgis-rest-portal/test/mocks/items/item.ts +526 -0
- package/packages/arcgis-rest-portal/test/mocks/items/resources.ts +38 -0
- package/packages/arcgis-rest-portal/test/mocks/items/search.ts +121 -0
- package/packages/arcgis-rest-portal/test/mocks/portal/response.ts +126 -0
- package/packages/arcgis-rest-portal/test/mocks/portal/settings-response.ts +56 -0
- package/packages/arcgis-rest-portal/test/mocks/sharing/sharing.ts +18 -0
- package/packages/arcgis-rest-portal/test/mocks/users/invitation.ts +70 -0
- package/packages/arcgis-rest-portal/test/mocks/users/notification.ts +34 -0
- package/packages/arcgis-rest-portal/test/mocks/users/user-search.ts +388 -0
- package/packages/arcgis-rest-portal/test/mocks/users/user-tags.ts +5 -0
- package/packages/arcgis-rest-portal/test/mocks/users/user.ts +174 -0
- package/packages/arcgis-rest-portal/test/orgs/notification.test.ts +142 -0
- package/packages/arcgis-rest-portal/test/sharing/access.test.ts +162 -0
- package/packages/arcgis-rest-portal/test/sharing/helpers.test.ts +55 -0
- package/packages/arcgis-rest-portal/test/sharing/share-item-with-group.test.ts +1325 -0
- package/packages/arcgis-rest-portal/test/sharing/unshare-item-with-group.test.ts +288 -0
- package/packages/arcgis-rest-portal/test/users/get-user-tags.test.ts +71 -0
- package/packages/arcgis-rest-portal/test/users/get-user-url.test.ts +40 -0
- package/packages/arcgis-rest-portal/test/users/get-user.test.ts +90 -0
- package/packages/arcgis-rest-portal/test/users/invitation.test.ts +127 -0
- package/packages/arcgis-rest-portal/test/users/notification.test.ts +77 -0
- package/packages/arcgis-rest-portal/test/users/search.test.ts +42 -0
- package/packages/arcgis-rest-portal/test/users/update.test.ts +151 -0
- package/packages/arcgis-rest-portal/test/util/SearchQueryBuilder.test.ts +340 -0
- package/packages/arcgis-rest-portal/test/util/array.test.ts +30 -0
- package/packages/arcgis-rest-portal/test/util/get-portal-settings.test.ts +68 -0
- package/packages/arcgis-rest-portal/test/util/get-portal-url.test.ts +37 -0
- package/packages/arcgis-rest-portal/test/util/portal.test.ts +148 -0
- package/packages/arcgis-rest-portal/test/util/scrub-control-chars.test.ts +22 -0
- package/packages/arcgis-rest-portal/tsconfig.json +6 -0
- package/packages/arcgis-rest-request/README.md +72 -0
- package/packages/arcgis-rest-request/package-lock.json +11 -0
- package/packages/arcgis-rest-request/package.json +60 -0
- package/packages/arcgis-rest-request/src/index.ts +25 -0
- package/packages/arcgis-rest-request/src/request.ts +413 -0
- package/packages/arcgis-rest-request/src/utils/ArcGISRequestError.ts +76 -0
- package/packages/arcgis-rest-request/src/utils/ErrorTypes.ts +29 -0
- package/packages/arcgis-rest-request/src/utils/GrantTypes.ts +5 -0
- package/packages/arcgis-rest-request/src/utils/HTTPMethods.ts +6 -0
- package/packages/arcgis-rest-request/src/utils/IAuthenticationManager.ts +21 -0
- package/packages/arcgis-rest-request/src/utils/IFetchTokenParams.ts +11 -0
- package/packages/arcgis-rest-request/src/utils/IGenerateTokenParams.ts +9 -0
- package/packages/arcgis-rest-request/src/utils/IParamBuilder.ts +3 -0
- package/packages/arcgis-rest-request/src/utils/IParams.ts +6 -0
- package/packages/arcgis-rest-request/src/utils/IParamsBuilder.ts +5 -0
- package/packages/arcgis-rest-request/src/utils/IRequestOptions.ts +49 -0
- package/packages/arcgis-rest-request/src/utils/ITokenRequestOptions.ts +9 -0
- package/packages/arcgis-rest-request/src/utils/ResponseFormats.ts +10 -0
- package/packages/arcgis-rest-request/src/utils/append-custom-params.ts +49 -0
- package/packages/arcgis-rest-request/src/utils/clean-url.ts +20 -0
- package/packages/arcgis-rest-request/src/utils/decode-query-string.ts +27 -0
- package/packages/arcgis-rest-request/src/utils/encode-form-data.ts +38 -0
- package/packages/arcgis-rest-request/src/utils/encode-query-string.ts +35 -0
- package/packages/arcgis-rest-request/src/utils/process-params.ts +108 -0
- package/packages/arcgis-rest-request/src/utils/retryAuthError.ts +10 -0
- package/packages/arcgis-rest-request/src/utils/warn.ts +11 -0
- package/packages/arcgis-rest-request/src/utils/with-options.ts +48 -0
- package/packages/arcgis-rest-request/test/mocks/errors.ts +76 -0
- package/packages/arcgis-rest-request/test/mocks/geojson-feature-collection.ts +13 -0
- package/packages/arcgis-rest-request/test/mocks/param-builder.ts +7 -0
- package/packages/arcgis-rest-request/test/mocks/sharing-rest-info.ts +41 -0
- package/packages/arcgis-rest-request/test/mocks/webmap.ts +41 -0
- package/packages/arcgis-rest-request/test/request.test.ts +571 -0
- package/packages/arcgis-rest-request/test/utils/ArcGISAuthError.test.ts +191 -0
- package/packages/arcgis-rest-request/test/utils/ArcGISRequestError.test.ts +51 -0
- package/packages/arcgis-rest-request/test/utils/check-for-errors.test.ts +111 -0
- package/packages/arcgis-rest-request/test/utils/clean-url.test.ts +50 -0
- package/packages/arcgis-rest-request/test/utils/encode-form-data.test.ts +133 -0
- package/packages/arcgis-rest-request/test/utils/encode-query-string.test.ts +18 -0
- package/packages/arcgis-rest-request/test/utils/process-params.test.ts +205 -0
- package/packages/arcgis-rest-request/test/utils/with-options.test.ts +133 -0
- package/packages/arcgis-rest-request/tsconfig.json +4 -0
- package/packages/arcgis-rest-routing/README.md +75 -0
- package/packages/arcgis-rest-routing/package-lock.json +11 -0
- package/packages/arcgis-rest-routing/package.json +63 -0
- package/packages/arcgis-rest-routing/src/helpers.ts +16 -0
- package/packages/arcgis-rest-routing/src/index.ts +11 -0
- package/packages/arcgis-rest-routing/src/solveRoute.ts +124 -0
- package/packages/arcgis-rest-routing/test/mocks/responses.ts +825 -0
- package/packages/arcgis-rest-routing/test/solveRoute.test.ts +509 -0
- package/packages/arcgis-rest-routing/tsconfig.json +6 -0
- package/packages/arcgis-rest-service-admin/README.md +73 -0
- package/packages/arcgis-rest-service-admin/package-lock.json +11 -0
- package/packages/arcgis-rest-service-admin/package.json +65 -0
- package/packages/arcgis-rest-service-admin/src/addTo.ts +70 -0
- package/packages/arcgis-rest-service-admin/src/create.ts +189 -0
- package/packages/arcgis-rest-service-admin/src/index.ts +11 -0
- package/packages/arcgis-rest-service-admin/src/update.ts +50 -0
- package/packages/arcgis-rest-service-admin/test/addTo.test.ts +350 -0
- package/packages/arcgis-rest-service-admin/test/create.test.ts +294 -0
- package/packages/arcgis-rest-service-admin/test/mocks/layerDefinition.ts +79 -0
- package/packages/arcgis-rest-service-admin/test/mocks/service.ts +81 -0
- package/packages/arcgis-rest-service-admin/test/update.test.ts +115 -0
- package/packages/arcgis-rest-service-admin/tsconfig.json +6 -0
- package/packages/arcgis-rest-types/README.md +66 -0
- package/packages/arcgis-rest-types/package.json +54 -0
- package/packages/arcgis-rest-types/src/feature.ts +39 -0
- package/packages/arcgis-rest-types/src/geometry.ts +272 -0
- package/packages/arcgis-rest-types/src/group.ts +72 -0
- package/packages/arcgis-rest-types/src/index.ts +9 -0
- package/packages/arcgis-rest-types/src/item.ts +81 -0
- package/packages/arcgis-rest-types/src/service.ts +114 -0
- package/packages/arcgis-rest-types/src/statisticDefinition.ts +33 -0
- package/packages/arcgis-rest-types/src/symbol.ts +170 -0
- package/packages/arcgis-rest-types/src/user.ts +49 -0
- package/packages/arcgis-rest-types/src/webmap.ts +1367 -0
- package/packages/arcgis-rest-types/tsconfig.json +10 -0
- package/support/changelog.js +393 -0
- package/support/deploy-doc-site.js +16 -0
- package/support/dev.sh +6 -0
- package/support/publish.sh +47 -0
- package/support/test-helpers.js +9 -0
- package/tsconfig.json +63 -0
- package/tslint.json +16 -0
- package/umd-base-profile.js +81 -0
- package/umd-production-profile.js +13 -0
@@ -0,0 +1,571 @@
|
|
1
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
import { request, ErrorTypes, setDefaultRequestOptions } from "../src/index";
|
5
|
+
import * as fetchMock from "fetch-mock";
|
6
|
+
import {
|
7
|
+
SharingRestInfo,
|
8
|
+
SharingRestInfoHTML
|
9
|
+
} from "./mocks/sharing-rest-info";
|
10
|
+
import { MockParamBuilder } from "./mocks/param-builder";
|
11
|
+
import { ArcGISOnlineError } from "./mocks/errors";
|
12
|
+
import { WebMapAsText, WebMapAsJSON } from "./mocks/webmap";
|
13
|
+
import { GeoJSONFeatureCollection } from "./mocks/geojson-feature-collection";
|
14
|
+
|
15
|
+
describe("request()", () => {
|
16
|
+
afterEach(fetchMock.restore);
|
17
|
+
|
18
|
+
it("should make a basic POST request", done => {
|
19
|
+
fetchMock.once("*", SharingRestInfo);
|
20
|
+
|
21
|
+
request("https://www.arcgis.com/sharing/rest/info")
|
22
|
+
.then(response => {
|
23
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
24
|
+
expect(url).toEqual("https://www.arcgis.com/sharing/rest/info");
|
25
|
+
expect(options.method).toBe("POST");
|
26
|
+
expect(response).toEqual(SharingRestInfo);
|
27
|
+
expect(options.body).toContain("f=json");
|
28
|
+
done();
|
29
|
+
})
|
30
|
+
.catch(e => {
|
31
|
+
fail(e);
|
32
|
+
});
|
33
|
+
});
|
34
|
+
|
35
|
+
it("should make a basic GET request", done => {
|
36
|
+
fetchMock.once("*", SharingRestInfo);
|
37
|
+
|
38
|
+
request("https://www.arcgis.com/sharing/rest/info", {
|
39
|
+
httpMethod: "GET"
|
40
|
+
})
|
41
|
+
.then(response => {
|
42
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
43
|
+
expect(url).toEqual("https://www.arcgis.com/sharing/rest/info?f=json");
|
44
|
+
expect(options.method).toBe("GET");
|
45
|
+
expect(response).toEqual(SharingRestInfo);
|
46
|
+
done();
|
47
|
+
})
|
48
|
+
.catch(e => {
|
49
|
+
fail(e);
|
50
|
+
});
|
51
|
+
});
|
52
|
+
|
53
|
+
it("should make a basic GET request for text", done => {
|
54
|
+
fetchMock.once("*", WebMapAsText);
|
55
|
+
|
56
|
+
request(
|
57
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a8e51789044d9480a20089a84129ad/data",
|
58
|
+
{
|
59
|
+
httpMethod: "GET",
|
60
|
+
params: { f: "text" }
|
61
|
+
}
|
62
|
+
)
|
63
|
+
.then(response => {
|
64
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
65
|
+
expect(url).toEqual(
|
66
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a8e51789044d9480a20089a84129ad/data?f=text"
|
67
|
+
);
|
68
|
+
expect(options.method).toBe("GET");
|
69
|
+
expect(response).toEqual(WebMapAsText);
|
70
|
+
done();
|
71
|
+
})
|
72
|
+
.catch(e => {
|
73
|
+
fail(e);
|
74
|
+
});
|
75
|
+
});
|
76
|
+
|
77
|
+
it("should make a basic GET request for html", done => {
|
78
|
+
fetchMock.once("*", SharingRestInfoHTML);
|
79
|
+
|
80
|
+
request("https://www.arcgis.com/sharing/rest/info", {
|
81
|
+
httpMethod: "GET",
|
82
|
+
params: { f: "html" }
|
83
|
+
})
|
84
|
+
.then(response => {
|
85
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
86
|
+
expect(url).toEqual("https://www.arcgis.com/sharing/rest/info?f=html");
|
87
|
+
expect(options.method).toBe("GET");
|
88
|
+
expect(response).toEqual(SharingRestInfoHTML);
|
89
|
+
done();
|
90
|
+
})
|
91
|
+
.catch(e => {
|
92
|
+
fail(e);
|
93
|
+
});
|
94
|
+
});
|
95
|
+
|
96
|
+
it("should make a basic GET request for geojson", done => {
|
97
|
+
fetchMock.once("*", GeoJSONFeatureCollection);
|
98
|
+
|
99
|
+
request(
|
100
|
+
"https://services1.arcgis.com/ORG/arcgis/rest/services/FEATURE_SERVICE/FeatureServer/0/query",
|
101
|
+
{
|
102
|
+
httpMethod: "GET",
|
103
|
+
params: { where: "1=1", f: "geojson" }
|
104
|
+
}
|
105
|
+
)
|
106
|
+
.then(response => {
|
107
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
108
|
+
expect(url).toEqual(
|
109
|
+
"https://services1.arcgis.com/ORG/arcgis/rest/services/FEATURE_SERVICE/FeatureServer/0/query?f=geojson&where=1%3D1"
|
110
|
+
);
|
111
|
+
expect(options.method).toBe("GET");
|
112
|
+
expect(response).toEqual(GeoJSONFeatureCollection);
|
113
|
+
done();
|
114
|
+
})
|
115
|
+
.catch(e => {
|
116
|
+
fail(e);
|
117
|
+
});
|
118
|
+
});
|
119
|
+
|
120
|
+
it("should switch from GET to POST when url is longer than specified", done => {
|
121
|
+
fetchMock.once("*", SharingRestInfo);
|
122
|
+
const restInfoUrl = "https://www.arcgis.com/sharing/rest/info";
|
123
|
+
|
124
|
+
request(restInfoUrl, {
|
125
|
+
httpMethod: "GET",
|
126
|
+
// typically consumers would base maxUrlLength on browser/server limits
|
127
|
+
// but for testing, we use an artificially low limit
|
128
|
+
// like this one that assumes no parameters will be added
|
129
|
+
maxUrlLength: restInfoUrl.length
|
130
|
+
})
|
131
|
+
.then(response => {
|
132
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
133
|
+
expect(url).toEqual("https://www.arcgis.com/sharing/rest/info");
|
134
|
+
expect(options.method).toBe("POST");
|
135
|
+
expect(options.body).toContain("f=json");
|
136
|
+
expect(response).toEqual(SharingRestInfo);
|
137
|
+
done();
|
138
|
+
})
|
139
|
+
.catch(e => {
|
140
|
+
fail(e);
|
141
|
+
});
|
142
|
+
});
|
143
|
+
|
144
|
+
it("should use the `authentication` option to authenticate a request", done => {
|
145
|
+
fetchMock.once("*", WebMapAsText);
|
146
|
+
|
147
|
+
const MOCK_AUTH = {
|
148
|
+
portal: "https://www.arcgis.com/sharing/rest",
|
149
|
+
getToken() {
|
150
|
+
return Promise.resolve("token");
|
151
|
+
}
|
152
|
+
};
|
153
|
+
|
154
|
+
request(
|
155
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a8e51789044d9480a20089a84129ad/data",
|
156
|
+
{
|
157
|
+
authentication: MOCK_AUTH
|
158
|
+
}
|
159
|
+
)
|
160
|
+
.then(response => {
|
161
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
162
|
+
expect(url).toEqual(
|
163
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a8e51789044d9480a20089a84129ad/data"
|
164
|
+
);
|
165
|
+
expect(options.body).toContain("token=token");
|
166
|
+
expect(response).toEqual(WebMapAsJSON);
|
167
|
+
done();
|
168
|
+
})
|
169
|
+
.catch(e => {
|
170
|
+
fail(e);
|
171
|
+
});
|
172
|
+
});
|
173
|
+
|
174
|
+
it("should hide token in POST body in browser environments otherwise it should hide token in `X-ESRI_AUTHORIZATION` header in Node", done => {
|
175
|
+
fetchMock.once("*", SharingRestInfo);
|
176
|
+
|
177
|
+
const MOCK_AUTH = {
|
178
|
+
portal: "https://www.arcgis.com/sharing/rest",
|
179
|
+
getToken() {
|
180
|
+
return Promise.resolve("token");
|
181
|
+
}
|
182
|
+
};
|
183
|
+
|
184
|
+
request("https://www.arcgis.com/sharing/rest/info", {
|
185
|
+
authentication: MOCK_AUTH,
|
186
|
+
httpMethod: 'GET',
|
187
|
+
hideToken: true
|
188
|
+
})
|
189
|
+
.then(response => {
|
190
|
+
// Test Node path with Jasmine in Node
|
191
|
+
if (typeof window === 'undefined') {
|
192
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
193
|
+
expect(url).toEqual("https://www.arcgis.com/sharing/rest/info?f=json");
|
194
|
+
expect(options.method).toBe("GET");
|
195
|
+
expect(response).toEqual(SharingRestInfo);
|
196
|
+
expect((options.headers as any)["X-Esri-Authorization"]).toBe("Bearer token");
|
197
|
+
} else {
|
198
|
+
// Test browser path when run in browser with Karma
|
199
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
200
|
+
expect(url).toEqual("https://www.arcgis.com/sharing/rest/info");
|
201
|
+
expect(options.method).toBe("POST");
|
202
|
+
expect(options.body).toContain("f=json");
|
203
|
+
expect(options.body).toContain("token=token");
|
204
|
+
expect((options.headers as any)["X-Esri-Authorization"]).toBe(undefined);
|
205
|
+
expect(response).toEqual(SharingRestInfo)
|
206
|
+
}
|
207
|
+
done();
|
208
|
+
})
|
209
|
+
.catch(e => {
|
210
|
+
fail(e);
|
211
|
+
});
|
212
|
+
});
|
213
|
+
|
214
|
+
it("should switch from GET to POST when url is longer than specified and replace token in header with token in POST body", done => {
|
215
|
+
fetchMock.once("*", SharingRestInfo);
|
216
|
+
const restInfoUrl = "https://www.arcgis.com/sharing/rest/info";
|
217
|
+
|
218
|
+
const MOCK_AUTH = {
|
219
|
+
portal: "https://www.arcgis.com/sharing/rest",
|
220
|
+
getToken() {
|
221
|
+
return Promise.resolve("token");
|
222
|
+
}
|
223
|
+
};
|
224
|
+
|
225
|
+
request(restInfoUrl, {
|
226
|
+
authentication: MOCK_AUTH,
|
227
|
+
httpMethod: "GET",
|
228
|
+
hideToken: true,
|
229
|
+
// typically consumers would base maxUrlLength on browser/server limits
|
230
|
+
// but for testing, we use an artificially low limit
|
231
|
+
// like this one that assumes no parameters will be added
|
232
|
+
maxUrlLength: restInfoUrl.length
|
233
|
+
})
|
234
|
+
.then(response => {
|
235
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
236
|
+
expect(url).toEqual("https://www.arcgis.com/sharing/rest/info");
|
237
|
+
expect(options.method).toBe("POST");
|
238
|
+
expect(options.body).toContain("f=json");
|
239
|
+
expect(options.body).toContain("token=token");
|
240
|
+
expect((options.headers as any)["X-Esri-Authorization"]).toBe(undefined);
|
241
|
+
expect(response).toEqual(SharingRestInfo);
|
242
|
+
done();
|
243
|
+
})
|
244
|
+
.catch(e => {
|
245
|
+
fail(e);
|
246
|
+
});
|
247
|
+
});
|
248
|
+
|
249
|
+
it("should re-throw HTTP errors (404, 500, etc)", done => {
|
250
|
+
fetchMock.once("*", 404);
|
251
|
+
|
252
|
+
request(
|
253
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a8e51789044d9480a20089a84129ad/data"
|
254
|
+
).catch(error => {
|
255
|
+
expect(error.name).toBe(ErrorTypes.ArcGISRequestError);
|
256
|
+
expect(error.message).toBe("HTTP 404: Not Found");
|
257
|
+
expect(error instanceof Error).toBeTruthy();
|
258
|
+
expect(error.url).toBe(
|
259
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a8e51789044d9480a20089a84129ad/data"
|
260
|
+
);
|
261
|
+
expect(error.options.params).toEqual({ f: "json" });
|
262
|
+
expect(error.options.httpMethod).toEqual("POST");
|
263
|
+
expect(typeof error.options.fetch).toEqual("function");
|
264
|
+
expect(error.options.fetch.length).toEqual(2);
|
265
|
+
done();
|
266
|
+
});
|
267
|
+
});
|
268
|
+
|
269
|
+
it("should throw errors with information about the request", done => {
|
270
|
+
fetchMock.once("*", ArcGISOnlineError);
|
271
|
+
|
272
|
+
request(
|
273
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a8e51789044d9480a20089a84129ad/data"
|
274
|
+
).catch(error => {
|
275
|
+
expect(error.name).toBe(ErrorTypes.ArcGISRequestError);
|
276
|
+
expect(error.message).toBe("400: 'type' and 'title' property required.");
|
277
|
+
expect(error instanceof Error).toBeTruthy();
|
278
|
+
expect(error.url).toBe(
|
279
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a8e51789044d9480a20089a84129ad/data"
|
280
|
+
);
|
281
|
+
expect(error.options.params).toEqual({ f: "json" });
|
282
|
+
expect(error.options.httpMethod).toEqual("POST");
|
283
|
+
expect(typeof error.options.fetch).toEqual("function");
|
284
|
+
expect(error.options.fetch.length).toEqual(2);
|
285
|
+
done();
|
286
|
+
});
|
287
|
+
});
|
288
|
+
|
289
|
+
it("should allow you to use custom implementations of `fetch`", done => {
|
290
|
+
const MockFetchResponse = {
|
291
|
+
ok: true,
|
292
|
+
json() {
|
293
|
+
return Promise.resolve(SharingRestInfo);
|
294
|
+
},
|
295
|
+
blob() {
|
296
|
+
return Promise.resolve(new Blob([JSON.stringify(SharingRestInfo)]));
|
297
|
+
},
|
298
|
+
text() {
|
299
|
+
return Promise.resolve(JSON.stringify(SharingRestInfo));
|
300
|
+
}
|
301
|
+
};
|
302
|
+
|
303
|
+
const MockFetch = function() {
|
304
|
+
return Promise.resolve(MockFetchResponse);
|
305
|
+
};
|
306
|
+
|
307
|
+
request("https://www.arcgis.com/sharing/rest/info", {
|
308
|
+
fetch: MockFetch as any
|
309
|
+
})
|
310
|
+
.then(response => {
|
311
|
+
expect(response).toEqual(SharingRestInfo);
|
312
|
+
done();
|
313
|
+
})
|
314
|
+
.catch(e => {
|
315
|
+
fail(e);
|
316
|
+
});
|
317
|
+
});
|
318
|
+
|
319
|
+
it("should return a raw response if requested", done => {
|
320
|
+
fetchMock.once("*", GeoJSONFeatureCollection);
|
321
|
+
|
322
|
+
request(
|
323
|
+
"https://services1.arcgis.com/ORG/arcgis/rest/services/FEATURE_SERVICE/FeatureServer/0/query",
|
324
|
+
{
|
325
|
+
httpMethod: "GET",
|
326
|
+
params: { where: "1=1", f: "geojson" },
|
327
|
+
rawResponse: true
|
328
|
+
}
|
329
|
+
)
|
330
|
+
.then(response => {
|
331
|
+
expect(response.status).toBe(200);
|
332
|
+
expect(response.ok).toBe(true);
|
333
|
+
expect(response.body.Readable).not.toBe(null);
|
334
|
+
response.json().then((raw: any) => {
|
335
|
+
expect(raw).toEqual(GeoJSONFeatureCollection);
|
336
|
+
done();
|
337
|
+
});
|
338
|
+
// this used to work with isomorphic-fetch
|
339
|
+
// expect(response instanceof Response).toBe(true);
|
340
|
+
})
|
341
|
+
.catch(e => {
|
342
|
+
fail(e);
|
343
|
+
});
|
344
|
+
});
|
345
|
+
|
346
|
+
it("should allow setting defaults for all requests", done => {
|
347
|
+
fetchMock.once("*", SharingRestInfo);
|
348
|
+
|
349
|
+
setDefaultRequestOptions({
|
350
|
+
headers: {
|
351
|
+
"Test-Header": "Test"
|
352
|
+
}
|
353
|
+
});
|
354
|
+
|
355
|
+
request("https://www.arcgis.com/sharing/rest/info")
|
356
|
+
.then(response => {
|
357
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
358
|
+
expect(url).toEqual("https://www.arcgis.com/sharing/rest/info");
|
359
|
+
expect(options.method).toBe("POST");
|
360
|
+
expect(response).toEqual(SharingRestInfo);
|
361
|
+
expect(options.body).toContain("f=json");
|
362
|
+
expect((options.headers as any)["Test-Header"]).toBe("Test");
|
363
|
+
done();
|
364
|
+
})
|
365
|
+
.catch(e => {
|
366
|
+
fail(e);
|
367
|
+
});
|
368
|
+
|
369
|
+
// since calling request is sync we can delete this right away
|
370
|
+
setDefaultRequestOptions({
|
371
|
+
httpMethod: "POST",
|
372
|
+
params: {
|
373
|
+
f: "json"
|
374
|
+
},
|
375
|
+
fetch
|
376
|
+
});
|
377
|
+
});
|
378
|
+
|
379
|
+
it("should warn users when attempting to set default auth", () => {
|
380
|
+
const oldWarn = console.warn;
|
381
|
+
|
382
|
+
console.warn = jasmine.createSpy().and.callFake(() => {
|
383
|
+
return;
|
384
|
+
});
|
385
|
+
|
386
|
+
const MOCK_AUTH = {
|
387
|
+
portal: "https://www.arcgis.com/sharing/rest",
|
388
|
+
getToken() {
|
389
|
+
return Promise.resolve("token");
|
390
|
+
}
|
391
|
+
};
|
392
|
+
|
393
|
+
setDefaultRequestOptions({
|
394
|
+
authentication: MOCK_AUTH
|
395
|
+
});
|
396
|
+
|
397
|
+
setDefaultRequestOptions(
|
398
|
+
{
|
399
|
+
authentication: MOCK_AUTH
|
400
|
+
},
|
401
|
+
true
|
402
|
+
);
|
403
|
+
|
404
|
+
expect(console.warn).toHaveBeenCalledTimes(1);
|
405
|
+
|
406
|
+
// since calling request is sync we can delete this right away
|
407
|
+
setDefaultRequestOptions({
|
408
|
+
httpMethod: "POST",
|
409
|
+
params: {
|
410
|
+
f: "json"
|
411
|
+
}
|
412
|
+
});
|
413
|
+
|
414
|
+
console.warn = oldWarn;
|
415
|
+
});
|
416
|
+
|
417
|
+
describe("should impliment the IParamBuilder and IParamsBuilder interfaces builder", () => {
|
418
|
+
it("should encode a param that impliments IParamBuilder", done => {
|
419
|
+
fetchMock.once("*", GeoJSONFeatureCollection);
|
420
|
+
|
421
|
+
const builder = new MockParamBuilder();
|
422
|
+
|
423
|
+
request(
|
424
|
+
"https://services1.arcgis.com/ORG/arcgis/rest/services/FEATURE_SERVICE/FeatureServer/0/query",
|
425
|
+
{
|
426
|
+
params: { where: builder, f: "geojson" }
|
427
|
+
}
|
428
|
+
)
|
429
|
+
.then(response => {
|
430
|
+
const options: RequestInit = fetchMock.lastCall("*")[1];
|
431
|
+
expect(options.body).toContain(`where=${encodeURIComponent("1=1")}`);
|
432
|
+
expect(response).toEqual(GeoJSONFeatureCollection);
|
433
|
+
done();
|
434
|
+
})
|
435
|
+
.catch(e => {
|
436
|
+
fail(e);
|
437
|
+
});
|
438
|
+
});
|
439
|
+
});
|
440
|
+
|
441
|
+
describe("should throw errors when required dependencies are missing", () => {
|
442
|
+
const oldPromise = Promise;
|
443
|
+
const oldFetch = fetch;
|
444
|
+
const oldFormData = FormData;
|
445
|
+
beforeEach(() => {
|
446
|
+
Promise = undefined;
|
447
|
+
FormData = undefined;
|
448
|
+
Function("return this")().fetch = undefined;
|
449
|
+
});
|
450
|
+
|
451
|
+
afterEach(() => {
|
452
|
+
Promise = oldPromise;
|
453
|
+
FormData = oldFormData;
|
454
|
+
Function("return this")().fetch = oldFetch;
|
455
|
+
});
|
456
|
+
|
457
|
+
it("should throw for missing dependencies", () => {
|
458
|
+
expect(() => {
|
459
|
+
request("https://www.arcgis.com/sharing/rest/info").catch();
|
460
|
+
}).toThrowError(
|
461
|
+
"`arcgis-rest-request` requires a `fetch` implementation and global variables for `Promise` and `FormData` to be present in the global scope. You are missing `fetch`, `Promise`, `FormData`. We recommend installing the `node-fetch`, `es6-promise`, `isomorphic-form-data` modules at the root of your application to add these to the global scope. See https://bit.ly/2KNwWaJ for more info."
|
462
|
+
);
|
463
|
+
});
|
464
|
+
|
465
|
+
it("should not throw if fetch is not present but a custom fetch is defined", done => {
|
466
|
+
Promise = oldPromise;
|
467
|
+
FormData = oldFormData;
|
468
|
+
|
469
|
+
const MockFetchResponse = {
|
470
|
+
ok: true,
|
471
|
+
json() {
|
472
|
+
return Promise.resolve(SharingRestInfo);
|
473
|
+
},
|
474
|
+
blob() {
|
475
|
+
return Promise.resolve(new Blob([JSON.stringify(SharingRestInfo)]));
|
476
|
+
},
|
477
|
+
text() {
|
478
|
+
return Promise.resolve(JSON.stringify(SharingRestInfo));
|
479
|
+
}
|
480
|
+
};
|
481
|
+
|
482
|
+
const MockFetch = function() {
|
483
|
+
return Promise.resolve(MockFetchResponse);
|
484
|
+
};
|
485
|
+
|
486
|
+
request("https://www.arcgis.com/sharing/rest/info", {
|
487
|
+
fetch: MockFetch as any
|
488
|
+
})
|
489
|
+
.then(response => {
|
490
|
+
expect(response).toEqual(SharingRestInfo);
|
491
|
+
done();
|
492
|
+
})
|
493
|
+
.catch(e => {
|
494
|
+
fail(e);
|
495
|
+
});
|
496
|
+
});
|
497
|
+
});
|
498
|
+
|
499
|
+
if (typeof window === "undefined") {
|
500
|
+
it("should tack on a generic referer header - in Node.js only", done => {
|
501
|
+
fetchMock.once("*", WebMapAsJSON);
|
502
|
+
|
503
|
+
request("https://www.arcgis.com/sharing/rest/content/items/43a/data")
|
504
|
+
.then(() => {
|
505
|
+
expect(fetchMock.called()).toEqual(true);
|
506
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
507
|
+
expect(url).toEqual(
|
508
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a/data"
|
509
|
+
);
|
510
|
+
expect(options.method).toBe("POST");
|
511
|
+
expect(options.headers).toEqual({
|
512
|
+
referer: "@esri/arcgis-rest-js",
|
513
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
514
|
+
});
|
515
|
+
done();
|
516
|
+
})
|
517
|
+
.catch(e => {
|
518
|
+
fail(e);
|
519
|
+
});
|
520
|
+
});
|
521
|
+
|
522
|
+
it("should use referer header from request options - in Node.js only", done => {
|
523
|
+
fetchMock.once("*", WebMapAsJSON);
|
524
|
+
|
525
|
+
request("https://www.arcgis.com/sharing/rest/content/items/43a/data", {
|
526
|
+
headers: { referer: "test/referer" }
|
527
|
+
})
|
528
|
+
.then(() => {
|
529
|
+
expect(fetchMock.called()).toEqual(true);
|
530
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
531
|
+
expect(url).toEqual(
|
532
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a/data"
|
533
|
+
);
|
534
|
+
expect(options.method).toBe("POST");
|
535
|
+
expect(options.headers).toEqual({
|
536
|
+
referer: "test/referer",
|
537
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
538
|
+
});
|
539
|
+
done();
|
540
|
+
})
|
541
|
+
.catch(e => {
|
542
|
+
fail(e);
|
543
|
+
});
|
544
|
+
});
|
545
|
+
|
546
|
+
it("if no referer header is provided, but other headers are passed, a default should still be set - in Node.js only", done => {
|
547
|
+
fetchMock.once("*", WebMapAsJSON);
|
548
|
+
|
549
|
+
request("https://www.arcgis.com/sharing/rest/content/items/43a/data", {
|
550
|
+
headers: { foo: "bar" }
|
551
|
+
})
|
552
|
+
.then(() => {
|
553
|
+
expect(fetchMock.called()).toEqual(true);
|
554
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
555
|
+
expect(url).toEqual(
|
556
|
+
"https://www.arcgis.com/sharing/rest/content/items/43a/data"
|
557
|
+
);
|
558
|
+
expect(options.method).toBe("POST");
|
559
|
+
expect(options.headers).toEqual({
|
560
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
561
|
+
referer: "@esri/arcgis-rest-js",
|
562
|
+
foo: "bar"
|
563
|
+
});
|
564
|
+
done();
|
565
|
+
})
|
566
|
+
.catch(e => {
|
567
|
+
fail(e);
|
568
|
+
});
|
569
|
+
});
|
570
|
+
}
|
571
|
+
});
|