delectusnon 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 +33 -0
- package/.vscode/launch.json +24 -0
- package/.vscode/settings.json +3 -0
- package/demos/ago-node-cli/README.md +29 -0
- package/demos/ago-node-cli/ago.js +32 -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 +172 -0
- package/demos/ago-node-cli/package.json +30 -0
- package/demos/attachments/README.md +5 -0
- package/demos/attachments/index.html +164 -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 +118 -0
- package/demos/batch-geocoder-node/config-template.js +18 -0
- package/demos/batch-geocoder-node/package-lock.json +116 -0
- package/demos/batch-geocoder-node/package.json +39 -0
- package/demos/express/README.md +10 -0
- package/demos/express/config.json.template +3 -0
- package/demos/express/package-lock.json +473 -0
- package/demos/express/package.json +18 -0
- package/demos/express/server.js +28 -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 +8 -0
- package/demos/jsapi-integration/config.js +6 -0
- package/demos/jsapi-integration/index.html +79 -0
- package/demos/jsapi-integration/package-lock.json +184 -0
- package/demos/jsapi-integration/package.json +19 -0
- package/demos/oauth2-browser/README.md +12 -0
- package/demos/oauth2-browser/authenticate.html +32 -0
- package/demos/oauth2-browser/config.js.template +6 -0
- package/demos/oauth2-browser/index.html +202 -0
- package/demos/oauth2-browser/logo.svg +4 -0
- package/demos/oauth2-browser/package-lock.json +163 -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 +21 -0
- package/demos/oauth2-browser-retry/index.html +116 -0
- package/demos/oauth2-browser-retry/logo.svg +4 -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 +11323 -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 +308 -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/docs/FAQ.md +28 -0
- package/docs/HISTORY.md +62 -0
- package/docs/acetate.config.js +223 -0
- package/docs/build-typedoc.js +301 -0
- package/docs/src/_layout.html +82 -0
- package/docs/src/api/_declaration.html +496 -0
- package/docs/src/api/_layout.html +127 -0
- package/docs/src/api/_package.html +13 -0
- package/docs/src/api/index.html +23 -0
- package/docs/src/guides/_layout.html +24 -0
- package/docs/src/guides/amd-requirejs-dojo.md +40 -0
- package/docs/src/guides/babel-and-rollup.md +30 -0
- package/docs/src/guides/babel-and-webpack.md +30 -0
- package/docs/src/guides/browser-authentication.md +31 -0
- package/docs/src/guides/browserify.md +9 -0
- package/docs/src/guides/cli-authentication.md +9 -0
- package/docs/src/guides/client-server-authentication.md +9 -0
- package/docs/src/guides/from-a-cdn.md +36 -0
- package/docs/src/guides/index.md +52 -0
- package/docs/src/guides/node.md +70 -0
- package/docs/src/guides/package-overview.md +8 -0
- package/docs/src/guides/server-authentication.md +9 -0
- package/docs/src/guides/typescript-and-webpack.md +9 -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 +169 -0
- package/jasmine.json +7 -0
- package/karma.conf.js +100 -0
- package/lerna.json +8 -0
- package/notes/README.md +88 -0
- package/package.json +88 -0
- package/packages/arcgis-rest-auth/README.md +64 -0
- package/packages/arcgis-rest-auth/package-lock.json +11 -0
- package/packages/arcgis-rest-auth/package.json +51 -0
- package/packages/arcgis-rest-auth/src/ApplicationSession.ts +109 -0
- package/packages/arcgis-rest-auth/src/UserSession.ts +873 -0
- package/packages/arcgis-rest-auth/src/authenticated-request-options.ts +24 -0
- package/packages/arcgis-rest-auth/src/fetch-token.ts +52 -0
- package/packages/arcgis-rest-auth/src/generate-token.ts +39 -0
- package/packages/arcgis-rest-auth/src/index.ts +8 -0
- package/packages/arcgis-rest-auth/test/ApplicationSession.test.ts +124 -0
- package/packages/arcgis-rest-auth/test/UserSession.test.ts +995 -0
- package/packages/arcgis-rest-auth/test/fetchToken.test.ts +112 -0
- package/packages/arcgis-rest-auth/test/generateToken.test.ts +130 -0
- package/packages/arcgis-rest-auth/test/utils.ts +14 -0
- package/packages/arcgis-rest-auth/tsconfig.json +6 -0
- package/packages/arcgis-rest-common-types/README.md +61 -0
- package/packages/arcgis-rest-common-types/package.json +38 -0
- package/packages/arcgis-rest-common-types/src/group.ts +54 -0
- package/packages/arcgis-rest-common-types/src/index.ts +467 -0
- package/packages/arcgis-rest-common-types/src/item.ts +45 -0
- package/packages/arcgis-rest-common-types/src/webmap.ts +1232 -0
- package/packages/arcgis-rest-common-types/tsconfig.json +11 -0
- package/packages/arcgis-rest-feature-service/README.md +70 -0
- package/packages/arcgis-rest-feature-service/package-lock.json +11 -0
- package/packages/arcgis-rest-feature-service/package.json +50 -0
- package/packages/arcgis-rest-feature-service/src/add.ts +81 -0
- package/packages/arcgis-rest-feature-service/src/addAttachment.ts +65 -0
- package/packages/arcgis-rest-feature-service/src/delete.ts +85 -0
- package/packages/arcgis-rest-feature-service/src/deleteAttachments.ts +68 -0
- package/packages/arcgis-rest-feature-service/src/getAttachments.ts +64 -0
- package/packages/arcgis-rest-feature-service/src/helpers.ts +80 -0
- package/packages/arcgis-rest-feature-service/src/index.ts +12 -0
- package/packages/arcgis-rest-feature-service/src/query.ts +172 -0
- package/packages/arcgis-rest-feature-service/src/queryRelated.ts +91 -0
- package/packages/arcgis-rest-feature-service/src/update.ts +81 -0
- package/packages/arcgis-rest-feature-service/src/updateAttachment.ts +74 -0
- package/packages/arcgis-rest-feature-service/test/attachments.test.ts +203 -0
- package/packages/arcgis-rest-feature-service/test/features.test.ts +252 -0
- package/packages/arcgis-rest-feature-service/test/mocks/feature.ts +279 -0
- package/packages/arcgis-rest-feature-service/test/mocks/foo.txt +1 -0
- package/packages/arcgis-rest-feature-service/tsconfig.json +6 -0
- package/packages/arcgis-rest-feature-service-admin/README.md +66 -0
- package/packages/arcgis-rest-feature-service-admin/package-lock.json +11 -0
- package/packages/arcgis-rest-feature-service-admin/package.json +53 -0
- package/packages/arcgis-rest-feature-service-admin/src/addTo.ts +70 -0
- package/packages/arcgis-rest-feature-service-admin/src/create.ts +195 -0
- package/packages/arcgis-rest-feature-service-admin/src/index.ts +2 -0
- package/packages/arcgis-rest-feature-service-admin/test/addTo.test.ts +310 -0
- package/packages/arcgis-rest-feature-service-admin/test/create.test.ts +412 -0
- package/packages/arcgis-rest-feature-service-admin/test/mocks/move.ts +14 -0
- package/packages/arcgis-rest-feature-service-admin/test/mocks/service.ts +72 -0
- package/packages/arcgis-rest-feature-service-admin/tsconfig.json +6 -0
- package/packages/arcgis-rest-geocoder/README.md +79 -0
- package/packages/arcgis-rest-geocoder/package-lock.json +11 -0
- package/packages/arcgis-rest-geocoder/package.json +52 -0
- package/packages/arcgis-rest-geocoder/src/bulk.ts +102 -0
- package/packages/arcgis-rest-geocoder/src/geocode.ts +117 -0
- package/packages/arcgis-rest-geocoder/src/helpers.ts +79 -0
- package/packages/arcgis-rest-geocoder/src/index.ts +8 -0
- package/packages/arcgis-rest-geocoder/src/reverse.ts +84 -0
- package/packages/arcgis-rest-geocoder/src/suggest.ts +72 -0
- package/packages/arcgis-rest-geocoder/test/bulk.test.ts +113 -0
- package/packages/arcgis-rest-geocoder/test/geocode.test.ts +121 -0
- package/packages/arcgis-rest-geocoder/test/helpers.test.ts +113 -0
- package/packages/arcgis-rest-geocoder/test/mocks/responses.ts +591 -0
- package/packages/arcgis-rest-geocoder/test/reverse.test.ts +126 -0
- package/packages/arcgis-rest-geocoder/test/suggest.test.ts +77 -0
- package/packages/arcgis-rest-geocoder/tsconfig.json +6 -0
- package/packages/arcgis-rest-groups/README.md +64 -0
- package/packages/arcgis-rest-groups/package-lock.json +11 -0
- package/packages/arcgis-rest-groups/package.json +52 -0
- package/packages/arcgis-rest-groups/src/create.ts +34 -0
- package/packages/arcgis-rest-groups/src/get.ts +95 -0
- package/packages/arcgis-rest-groups/src/helpers.ts +26 -0
- package/packages/arcgis-rest-groups/src/index.ts +11 -0
- package/packages/arcgis-rest-groups/src/notification.ts +77 -0
- package/packages/arcgis-rest-groups/src/protect.ts +40 -0
- package/packages/arcgis-rest-groups/src/remove.ts +23 -0
- package/packages/arcgis-rest-groups/src/search.ts +64 -0
- package/packages/arcgis-rest-groups/src/update.ts +36 -0
- package/packages/arcgis-rest-groups/test/crud.test.ts +104 -0
- package/packages/arcgis-rest-groups/test/get.test.ts +101 -0
- package/packages/arcgis-rest-groups/test/mocks/responses.ts +141 -0
- package/packages/arcgis-rest-groups/test/notification.test.ts +102 -0
- package/packages/arcgis-rest-groups/test/protect.test.ts +64 -0
- package/packages/arcgis-rest-groups/test/search.test.ts +85 -0
- package/packages/arcgis-rest-groups/tsconfig.json +6 -0
- package/packages/arcgis-rest-items/README.md +66 -0
- package/packages/arcgis-rest-items/package-lock.json +11 -0
- package/packages/arcgis-rest-items/package.json +52 -0
- package/packages/arcgis-rest-items/src/add.ts +103 -0
- package/packages/arcgis-rest-items/src/create.ts +110 -0
- package/packages/arcgis-rest-items/src/get.ts +79 -0
- package/packages/arcgis-rest-items/src/helpers.ts +147 -0
- package/packages/arcgis-rest-items/src/index.ts +11 -0
- package/packages/arcgis-rest-items/src/protect.ts +38 -0
- package/packages/arcgis-rest-items/src/remove.ts +58 -0
- package/packages/arcgis-rest-items/src/search.ts +78 -0
- package/packages/arcgis-rest-items/src/update.ts +134 -0
- package/packages/arcgis-rest-items/test/add.test.ts +256 -0
- package/packages/arcgis-rest-items/test/create.test.ts +371 -0
- package/packages/arcgis-rest-items/test/get.test.ts +181 -0
- package/packages/arcgis-rest-items/test/mocks/foo.zip +0 -0
- package/packages/arcgis-rest-items/test/mocks/item.ts +33 -0
- package/packages/arcgis-rest-items/test/mocks/resources.ts +31 -0
- package/packages/arcgis-rest-items/test/mocks/search.ts +63 -0
- package/packages/arcgis-rest-items/test/protect.test.ts +122 -0
- package/packages/arcgis-rest-items/test/remove.test.ts +161 -0
- package/packages/arcgis-rest-items/test/search.test.ts +159 -0
- package/packages/arcgis-rest-items/test/update.test.ts +450 -0
- package/packages/arcgis-rest-items/tsconfig.json +6 -0
- package/packages/arcgis-rest-request/README.md +65 -0
- package/packages/arcgis-rest-request/package-lock.json +11 -0
- package/packages/arcgis-rest-request/package.json +42 -0
- package/packages/arcgis-rest-request/src/index.ts +13 -0
- package/packages/arcgis-rest-request/src/request.ts +293 -0
- package/packages/arcgis-rest-request/src/utils/ArcGISAuthError.ts +67 -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/check-for-errors.ts +65 -0
- package/packages/arcgis-rest-request/src/utils/encode-form-data.ts +34 -0
- package/packages/arcgis-rest-request/src/utils/encode-query-string.ts +23 -0
- package/packages/arcgis-rest-request/src/utils/get-portal-url.ts +25 -0
- package/packages/arcgis-rest-request/src/utils/get-portal.ts +45 -0
- package/packages/arcgis-rest-request/src/utils/process-params.ts +99 -0
- package/packages/arcgis-rest-request/test/mocks/errors.ts +68 -0
- package/packages/arcgis-rest-request/test/mocks/geojson-feature-collection.ts +13 -0
- package/packages/arcgis-rest-request/test/mocks/portal.ts +112 -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 +299 -0
- package/packages/arcgis-rest-request/test/utils/ArcGISAuthError.test.ts +170 -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/encode-form-data.test.ts +133 -0
- package/packages/arcgis-rest-request/test/utils/get-portal-url.test.ts +37 -0
- package/packages/arcgis-rest-request/test/utils/portal.test.ts +97 -0
- package/packages/arcgis-rest-request/test/utils/process-params.test.ts +193 -0
- package/packages/arcgis-rest-request/tsconfig.json +6 -0
- package/packages/arcgis-rest-sharing/README.md +67 -0
- package/packages/arcgis-rest-sharing/package-lock.json +11 -0
- package/packages/arcgis-rest-sharing/package.json +57 -0
- package/packages/arcgis-rest-sharing/src/access.ts +85 -0
- package/packages/arcgis-rest-sharing/src/group-sharing.ts +211 -0
- package/packages/arcgis-rest-sharing/src/helpers.ts +82 -0
- package/packages/arcgis-rest-sharing/src/index.ts +5 -0
- package/packages/arcgis-rest-sharing/test/access.test.ts +154 -0
- package/packages/arcgis-rest-sharing/test/group-sharing.test.ts +566 -0
- package/packages/arcgis-rest-sharing/test/helpers.test.ts +55 -0
- package/packages/arcgis-rest-sharing/test/mocks/sharing.ts +18 -0
- package/packages/arcgis-rest-sharing/tsconfig.json +6 -0
- package/packages/arcgis-rest-users/README.md +71 -0
- package/packages/arcgis-rest-users/package-lock.json +11 -0
- package/packages/arcgis-rest-users/package.json +51 -0
- package/packages/arcgis-rest-users/src/get.ts +69 -0
- package/packages/arcgis-rest-users/src/index.ts +6 -0
- package/packages/arcgis-rest-users/src/invitation.ts +166 -0
- package/packages/arcgis-rest-users/src/notification.ts +73 -0
- package/packages/arcgis-rest-users/test/get.test.ts +99 -0
- package/packages/arcgis-rest-users/test/invitation.test.ts +169 -0
- package/packages/arcgis-rest-users/test/mocks/invitation.ts +70 -0
- package/packages/arcgis-rest-users/test/mocks/notification.ts +34 -0
- package/packages/arcgis-rest-users/test/mocks/user.ts +173 -0
- package/packages/arcgis-rest-users/test/notification.test.ts +83 -0
- package/packages/arcgis-rest-users/tsconfig.json +6 -0
- package/support/changelog.js +394 -0
- package/support/deploy-doc-site.js +16 -0
- package/support/publish.sh +43 -0
- package/support/test-helpers.js +8 -0
- package/tsconfig.json +69 -0
- package/tslint.json +15 -0
- package/umd-base-profile.js +82 -0
- package/umd-production-profile.js +13 -0
@@ -0,0 +1,170 @@
|
|
1
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
import { ArcGISAuthError, IRetryAuthError, ErrorTypes } from "../../src/index";
|
5
|
+
import { ArcGISOnlineAuthError, ArcGISOnlineError } from "./../mocks/errors";
|
6
|
+
import * as fetchMock from "fetch-mock";
|
7
|
+
|
8
|
+
describe("ArcGISRequestError", () => {
|
9
|
+
afterEach(fetchMock.restore);
|
10
|
+
|
11
|
+
it("should be an instanceof Error", () => {
|
12
|
+
expect(new ArcGISAuthError() instanceof Error).toBe(true);
|
13
|
+
});
|
14
|
+
|
15
|
+
it("should expose basic error properties", () => {
|
16
|
+
const error = new ArcGISAuthError(
|
17
|
+
ArcGISOnlineAuthError.error.message,
|
18
|
+
ArcGISOnlineAuthError.error.code,
|
19
|
+
ArcGISOnlineAuthError
|
20
|
+
);
|
21
|
+
|
22
|
+
expect(error.name).toBe("ArcGISAuthError");
|
23
|
+
expect(error.message).toBe("498: Invalid token.");
|
24
|
+
expect(error.code).toBe(498);
|
25
|
+
expect(error.originalMessage).toBe("Invalid token.");
|
26
|
+
expect(error.response).toEqual(ArcGISOnlineAuthError);
|
27
|
+
});
|
28
|
+
|
29
|
+
it("should still format without a message, code or response", () => {
|
30
|
+
const error = new ArcGISAuthError();
|
31
|
+
expect(error.message).toBe("AUTHENTICATION_ERROR");
|
32
|
+
expect(error.code).toEqual("AUTHENTICATION_ERROR_CODE");
|
33
|
+
expect(error.originalMessage).toBe("AUTHENTICATION_ERROR");
|
34
|
+
expect(error.response).toEqual(undefined);
|
35
|
+
});
|
36
|
+
|
37
|
+
describe("retry", () => {
|
38
|
+
const MockAuth: {
|
39
|
+
portal: string;
|
40
|
+
getToken: any;
|
41
|
+
retryHandler: IRetryAuthError;
|
42
|
+
} = {
|
43
|
+
portal: "https://www.arcgis.com/sharing/rest",
|
44
|
+
getToken() {
|
45
|
+
return Promise.resolve("token");
|
46
|
+
},
|
47
|
+
retryHandler(url, options) {
|
48
|
+
return Promise.resolve(MockAuth);
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
52
|
+
it("should allow retrying a request with a new or updated session", done => {
|
53
|
+
const error = new ArcGISAuthError(
|
54
|
+
"Invalid token.",
|
55
|
+
498,
|
56
|
+
ArcGISAuthError,
|
57
|
+
"http://www.arcgis.com/sharing/rest/content/users/caseyjones/addItem",
|
58
|
+
{
|
59
|
+
httpMethod: "POST",
|
60
|
+
params: {
|
61
|
+
title: "Test Map",
|
62
|
+
tags: "foo",
|
63
|
+
type: "Web Map",
|
64
|
+
f: "json"
|
65
|
+
}
|
66
|
+
}
|
67
|
+
);
|
68
|
+
|
69
|
+
fetchMock.once("*", {
|
70
|
+
success: true,
|
71
|
+
id: "abc",
|
72
|
+
folder: null
|
73
|
+
});
|
74
|
+
|
75
|
+
const retryHandlerSpy = spyOn(MockAuth, "retryHandler").and.callThrough();
|
76
|
+
|
77
|
+
error
|
78
|
+
.retry(MockAuth.retryHandler, 1)
|
79
|
+
.then((response: any) => {
|
80
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
81
|
+
expect(url).toEqual(
|
82
|
+
"http://www.arcgis.com/sharing/rest/content/users/caseyjones/addItem"
|
83
|
+
);
|
84
|
+
expect(options.method).toEqual("POST");
|
85
|
+
expect(retryHandlerSpy).toHaveBeenCalledTimes(1);
|
86
|
+
expect(options.body).toContain("token=token");
|
87
|
+
expect(options.body).toContain("tags=foo");
|
88
|
+
expect(options.body).toContain("f=json");
|
89
|
+
expect(response.success).toBe(true);
|
90
|
+
expect(response.id).toBe("abc");
|
91
|
+
expect(response.folder).toBe(null);
|
92
|
+
done();
|
93
|
+
})
|
94
|
+
.catch((e: any) => {
|
95
|
+
fail(e);
|
96
|
+
});
|
97
|
+
});
|
98
|
+
|
99
|
+
it("should retry a request with a new or updated session up to the limit", done => {
|
100
|
+
const error = new ArcGISAuthError(
|
101
|
+
"Invalid token.",
|
102
|
+
498,
|
103
|
+
ArcGISAuthError,
|
104
|
+
"http://www.arcgis.com/sharing/rest/content/users/caseyjones/addItem",
|
105
|
+
{
|
106
|
+
httpMethod: "POST",
|
107
|
+
params: {
|
108
|
+
title: "Test Map",
|
109
|
+
tags: "foo",
|
110
|
+
type: "Web Map",
|
111
|
+
f: "json"
|
112
|
+
}
|
113
|
+
}
|
114
|
+
);
|
115
|
+
|
116
|
+
fetchMock.post("*", ArcGISOnlineAuthError);
|
117
|
+
|
118
|
+
const retryHandlerSpy = spyOn(MockAuth, "retryHandler").and.callThrough();
|
119
|
+
|
120
|
+
error.retry(MockAuth.retryHandler).catch((e: any) => {
|
121
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
122
|
+
expect(url).toEqual(
|
123
|
+
"http://www.arcgis.com/sharing/rest/content/users/caseyjones/addItem"
|
124
|
+
);
|
125
|
+
expect(options.method).toEqual("POST");
|
126
|
+
expect(retryHandlerSpy).toHaveBeenCalledTimes(3);
|
127
|
+
expect(options.body).toContain("token=token");
|
128
|
+
expect(options.body).toContain("tags=foo");
|
129
|
+
expect(options.body).toContain("f=json");
|
130
|
+
expect(e.name).toBe(ErrorTypes.ArcGISAuthError);
|
131
|
+
expect(e.message).toBe("498: Invalid token.");
|
132
|
+
done();
|
133
|
+
});
|
134
|
+
});
|
135
|
+
|
136
|
+
it("should throw an error if retrying throws a non-auth error", done => {
|
137
|
+
const requestUrl =
|
138
|
+
"http://www.arcgis.com/sharing/rest/content/users/caseyjones/addItem";
|
139
|
+
const error = new ArcGISAuthError(
|
140
|
+
"Invalid token.",
|
141
|
+
498,
|
142
|
+
ArcGISAuthError,
|
143
|
+
requestUrl,
|
144
|
+
{
|
145
|
+
httpMethod: "POST",
|
146
|
+
params: {
|
147
|
+
type: "Web Map",
|
148
|
+
f: "json"
|
149
|
+
}
|
150
|
+
}
|
151
|
+
);
|
152
|
+
|
153
|
+
fetchMock.post("*", ArcGISOnlineError);
|
154
|
+
|
155
|
+
const retryHandlerSpy = spyOn(MockAuth, "retryHandler").and.callThrough();
|
156
|
+
|
157
|
+
error.retry(MockAuth.retryHandler).catch((e: any) => {
|
158
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
159
|
+
expect(url).toEqual(requestUrl);
|
160
|
+
expect(options.method).toEqual("POST");
|
161
|
+
expect(retryHandlerSpy).toHaveBeenCalledTimes(1);
|
162
|
+
expect(options.body).toContain("token=token");
|
163
|
+
expect(options.body).toContain("f=json");
|
164
|
+
expect(e.name).toBe(ErrorTypes.ArcGISRequestError);
|
165
|
+
expect(e.message).toBe("400: 'type' and 'title' property required.");
|
166
|
+
done();
|
167
|
+
});
|
168
|
+
});
|
169
|
+
});
|
170
|
+
});
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
import { ArcGISRequestError } from "../../src/index";
|
5
|
+
import { ArcGISOnlineError } from "./../mocks/errors";
|
6
|
+
|
7
|
+
describe("ArcGISRequestError", () => {
|
8
|
+
it("should be an instanceof Error", () => {
|
9
|
+
expect(new ArcGISRequestError() instanceof Error).toBe(true);
|
10
|
+
});
|
11
|
+
|
12
|
+
it("should expose basic error properties", () => {
|
13
|
+
const error = new ArcGISRequestError(
|
14
|
+
ArcGISOnlineError.error.message,
|
15
|
+
ArcGISOnlineError.error.code,
|
16
|
+
ArcGISOnlineError,
|
17
|
+
"https://example.com",
|
18
|
+
{
|
19
|
+
params: {
|
20
|
+
f: "json"
|
21
|
+
},
|
22
|
+
httpMethod: "POST"
|
23
|
+
}
|
24
|
+
);
|
25
|
+
|
26
|
+
expect(error.name).toBe("ArcGISRequestError");
|
27
|
+
expect(error.message).toBe("400: 'type' and 'title' property required.");
|
28
|
+
expect(error.code).toBe(400);
|
29
|
+
expect(error.originalMessage).toBe("'type' and 'title' property required.");
|
30
|
+
expect(error.response).toEqual(ArcGISOnlineError);
|
31
|
+
expect(error.url).toBe("https://example.com");
|
32
|
+
expect(error.options.params).toEqual({ f: "json" });
|
33
|
+
expect(error.options.httpMethod).toEqual("POST");
|
34
|
+
});
|
35
|
+
|
36
|
+
it("should still format without a message, code or response", () => {
|
37
|
+
const error = new ArcGISRequestError();
|
38
|
+
expect(error.message).toBe("UNKNOWN_ERROR");
|
39
|
+
expect(error.code).toEqual("UNKNOWN_ERROR_CODE");
|
40
|
+
expect(error.originalMessage).toBe("UNKNOWN_ERROR");
|
41
|
+
expect(error.response).toEqual(undefined);
|
42
|
+
});
|
43
|
+
|
44
|
+
it("should still format with a null or empty string message or code", () => {
|
45
|
+
const error = new ArcGISRequestError(null, "");
|
46
|
+
expect(error.message).toBe("UNKNOWN_ERROR");
|
47
|
+
expect(error.code).toEqual("UNKNOWN_ERROR_CODE");
|
48
|
+
expect(error.originalMessage).toBe("UNKNOWN_ERROR");
|
49
|
+
expect(error.response).toEqual(undefined);
|
50
|
+
});
|
51
|
+
});
|
@@ -0,0 +1,111 @@
|
|
1
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
import {
|
5
|
+
checkForErrors,
|
6
|
+
warn,
|
7
|
+
ArcGISRequestError,
|
8
|
+
ArcGISAuthError
|
9
|
+
} from "../../src/index";
|
10
|
+
import { SharingRestInfo } from "./../mocks/sharing-rest-info";
|
11
|
+
import {
|
12
|
+
ArcGISOnlineError,
|
13
|
+
BillingError,
|
14
|
+
TaskErrorWithJSON,
|
15
|
+
TaskError,
|
16
|
+
ArcGISOnlineErrorNoMessageCode,
|
17
|
+
ArcGISOnlineErrorNoCode,
|
18
|
+
ArcGISServerTokenRequired,
|
19
|
+
ArcGISOnlineAuthError,
|
20
|
+
BillingErrorWithCode200
|
21
|
+
} from "./../mocks/errors";
|
22
|
+
|
23
|
+
describe("checkForErrors", () => {
|
24
|
+
it("should pass if an error is not found", () => {
|
25
|
+
expect(checkForErrors(SharingRestInfo)).toBe(SharingRestInfo);
|
26
|
+
});
|
27
|
+
|
28
|
+
it("should throw an ArcGISRequestError for an error from the ArcGIS REST API", () => {
|
29
|
+
expect(() => {
|
30
|
+
checkForErrors(ArcGISOnlineError);
|
31
|
+
}).toThrowError(
|
32
|
+
ArcGISRequestError,
|
33
|
+
"400: 'type' and 'title' property required."
|
34
|
+
);
|
35
|
+
});
|
36
|
+
|
37
|
+
it("should throw an ArcGISOnlineAuthError for an error from the ArcGIS REST API", () => {
|
38
|
+
expect(() => {
|
39
|
+
checkForErrors(ArcGISOnlineAuthError);
|
40
|
+
}).toThrowError(ArcGISAuthError, "498: Invalid token.");
|
41
|
+
});
|
42
|
+
|
43
|
+
it("should throw an ArcGISRequestError for an error from the ArcGIS REST API that has no messageCode", () => {
|
44
|
+
expect(() => {
|
45
|
+
checkForErrors(ArcGISOnlineErrorNoMessageCode);
|
46
|
+
}).toThrowError(
|
47
|
+
ArcGISRequestError,
|
48
|
+
"403: You do not have permissions to access this resource or perform this operation."
|
49
|
+
);
|
50
|
+
});
|
51
|
+
|
52
|
+
it("should throw an ArcGISRequestError for an error from the ArcGIS REST API that has no code", () => {
|
53
|
+
expect(() => {
|
54
|
+
checkForErrors(ArcGISOnlineErrorNoCode);
|
55
|
+
}).toThrowError(
|
56
|
+
ArcGISRequestError,
|
57
|
+
"You do not have permissions to access this resource or perform this operation."
|
58
|
+
);
|
59
|
+
});
|
60
|
+
|
61
|
+
it("should throw an ArcGISRequestError for an error from the ArcGIS Online Billing Backend", () => {
|
62
|
+
expect(() => {
|
63
|
+
checkForErrors(BillingError);
|
64
|
+
}).toThrowError(ArcGISRequestError, "500: Error getting subscription info");
|
65
|
+
});
|
66
|
+
|
67
|
+
it("should throw an ArcGISRequestError for an error from the ArcGIS Online Billing Backend with a failure status", () => {
|
68
|
+
expect(() => {
|
69
|
+
checkForErrors(BillingErrorWithCode200);
|
70
|
+
}).toThrowError(ArcGISRequestError, "UNKNOWN_ERROR");
|
71
|
+
});
|
72
|
+
|
73
|
+
it("should throw an ArcGISRequestError for an error when checking long running tasks in ArcGIS REST API", () => {
|
74
|
+
expect(() => {
|
75
|
+
checkForErrors(TaskErrorWithJSON);
|
76
|
+
}).toThrowError(
|
77
|
+
ArcGISRequestError,
|
78
|
+
"400: Index was outside the bounds of the array."
|
79
|
+
);
|
80
|
+
});
|
81
|
+
|
82
|
+
it("should throw an ArcGISRequestError for an error when checking long running tasks in ArcGIS REST API without a JSON statusMessage", () => {
|
83
|
+
expect(() => {
|
84
|
+
checkForErrors(TaskError);
|
85
|
+
}).toThrowError(ArcGISRequestError, "failed");
|
86
|
+
});
|
87
|
+
|
88
|
+
it("should throw an ArcGISAuthError instead of ArcGISRequestError for messageCode=GWM_0003", () => {
|
89
|
+
expect(() => {
|
90
|
+
checkForErrors(ArcGISServerTokenRequired);
|
91
|
+
}).toThrowError(ArcGISAuthError, "GWM_0003: Token Required");
|
92
|
+
});
|
93
|
+
});
|
94
|
+
|
95
|
+
describe("warn", () => {
|
96
|
+
it("should bubble up deprecation warnings", () => {
|
97
|
+
console.warn = jasmine.createSpy("warning");
|
98
|
+
warn("Danger Will Robinson!");
|
99
|
+
expect(console.warn).toHaveBeenCalledWith("Danger Will Robinson!");
|
100
|
+
});
|
101
|
+
});
|
102
|
+
|
103
|
+
describe("warn", () => {
|
104
|
+
it("should carry on gracefully when no console is available", () => {
|
105
|
+
const realConsoleWarn = console.warn;
|
106
|
+
console.warn = undefined;
|
107
|
+
warn("Danger Will Robinson!");
|
108
|
+
expect(console.warn).toBe(undefined);
|
109
|
+
console.warn = realConsoleWarn;
|
110
|
+
});
|
111
|
+
});
|
@@ -0,0 +1,133 @@
|
|
1
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
import { encodeFormData } from "../../src/utils/encode-form-data";
|
5
|
+
import {
|
6
|
+
requiresFormData,
|
7
|
+
processParams
|
8
|
+
} from "../../src/utils/process-params";
|
9
|
+
import { attachmentFile } from "../../../arcgis-rest-feature-service/test/attachments.test";
|
10
|
+
|
11
|
+
describe("encodeFormData", () => {
|
12
|
+
it("should encode in form data for multipart file requests", () => {
|
13
|
+
const binaryObj = attachmentFile();
|
14
|
+
|
15
|
+
const formData = encodeFormData({ binary: binaryObj });
|
16
|
+
expect(formData instanceof FormData).toBeTruthy();
|
17
|
+
|
18
|
+
const data = formData as FormData;
|
19
|
+
if (data.get) {
|
20
|
+
expect(data.get("binary") instanceof File).toBeTruthy();
|
21
|
+
expect((data.get("binary") as File).name).toBe("foo.txt");
|
22
|
+
}
|
23
|
+
});
|
24
|
+
|
25
|
+
it("should encode in form data for multipart blob requests", () => {
|
26
|
+
const binaryObj =
|
27
|
+
typeof Blob !== "undefined"
|
28
|
+
? new Blob([], {
|
29
|
+
type: "text/plain"
|
30
|
+
})
|
31
|
+
: Buffer.from("");
|
32
|
+
|
33
|
+
const formData = encodeFormData({ binary: binaryObj });
|
34
|
+
expect(formData instanceof FormData).toBeTruthy();
|
35
|
+
|
36
|
+
const data = formData as FormData;
|
37
|
+
if (data.get) {
|
38
|
+
expect(data.get("binary") instanceof File).toBeTruthy();
|
39
|
+
expect((data.get("binary") as File).name).toBe("binary");
|
40
|
+
}
|
41
|
+
});
|
42
|
+
|
43
|
+
it("should encode as query string for basic types", () => {
|
44
|
+
const dateValue = 1471417200000;
|
45
|
+
|
46
|
+
// null, undefined, function are excluded. If you want to send an empty key you need to send an empty string "".
|
47
|
+
// See https://github.com/Esri/arcgis-rest-js/issues/18
|
48
|
+
const params = {
|
49
|
+
myArray1: new Array(8),
|
50
|
+
myArray2: [1, 2, 4, 16],
|
51
|
+
myArray3: [{ a: 1, b: 2 }, { c: "abc" }],
|
52
|
+
myDate: new Date(dateValue),
|
53
|
+
myFunction: () => {
|
54
|
+
return 3.1415;
|
55
|
+
},
|
56
|
+
myBoolean: true,
|
57
|
+
myString: "Hello, world!",
|
58
|
+
myEmptyString: "",
|
59
|
+
myNumber: 380
|
60
|
+
};
|
61
|
+
|
62
|
+
expect(requiresFormData(params)).toBeFalsy();
|
63
|
+
|
64
|
+
const formData = processParams(params);
|
65
|
+
expect(typeof formData).toBe("object");
|
66
|
+
expect(formData.myArray1).toBe(",,,,,,,");
|
67
|
+
expect(formData.myArray2).toBe("1,2,4,16");
|
68
|
+
expect(formData.myArray3).toBe('[{"a":1,"b":2},{"c":"abc"}]');
|
69
|
+
expect(formData.myDate).toBe(dateValue);
|
70
|
+
expect(formData.myBoolean).toBeTruthy();
|
71
|
+
expect(formData.myString).toBe("Hello, world!");
|
72
|
+
expect(formData.myEmptyString).toBe("");
|
73
|
+
expect(formData.myNumber).toBe(380);
|
74
|
+
|
75
|
+
const encodedFormData = encodeFormData(params);
|
76
|
+
expect(typeof encodedFormData).toBe("string");
|
77
|
+
expect(encodedFormData).toBe(
|
78
|
+
"myArray1=%2C%2C%2C%2C%2C%2C%2C&" +
|
79
|
+
"myArray2=1%2C2%2C4%2C16&" +
|
80
|
+
"myArray3=%5B%7B%22a%22%3A1%2C%22b%22%3A2%7D%2C%7B%22c%22%3A%22abc%22%7D%5D&" +
|
81
|
+
"myDate=1471417200000&" +
|
82
|
+
"myBoolean=true&" +
|
83
|
+
"myString=Hello%2C%20world!&" +
|
84
|
+
"myEmptyString=&" +
|
85
|
+
"myNumber=380"
|
86
|
+
);
|
87
|
+
});
|
88
|
+
|
89
|
+
it("should switch to form data if any item is not a basic type", () => {
|
90
|
+
const dateValue = 1471417200000;
|
91
|
+
const file = attachmentFile();
|
92
|
+
if (!file.name) {
|
93
|
+
// The file's name is used for adding files to a form, so supply a name when we're in a testing
|
94
|
+
// environment that doesn't support File (attachmentFile creates a File with the name "foo.txt"
|
95
|
+
// if File is supported and a file stream otherwise)
|
96
|
+
file.name = "foo.txt";
|
97
|
+
}
|
98
|
+
|
99
|
+
// null, undefined, function are excluded. If you want to send an empty key you need to send an empty string "".
|
100
|
+
// See https://github.com/Esri/arcgis-rest-js/issues/18
|
101
|
+
const params = {
|
102
|
+
myArray1: new Array(8),
|
103
|
+
myArray2: [1, 2, 4, 16],
|
104
|
+
myArray3: [{ a: 1, b: 2 }, { c: "abc" }],
|
105
|
+
myDate: new Date(dateValue),
|
106
|
+
myFunction: () => {
|
107
|
+
return 3.1415;
|
108
|
+
},
|
109
|
+
myBoolean: true,
|
110
|
+
myString: "Hello, world!",
|
111
|
+
myEmptyString: "",
|
112
|
+
myNumber: 380,
|
113
|
+
file
|
114
|
+
};
|
115
|
+
|
116
|
+
expect(requiresFormData(params)).toBeTruthy();
|
117
|
+
|
118
|
+
const formData = processParams(params);
|
119
|
+
expect(typeof formData).toBe("object");
|
120
|
+
expect(formData.myArray1).toBe(",,,,,,,");
|
121
|
+
expect(formData.myArray2).toBe("1,2,4,16");
|
122
|
+
expect(formData.myArray3).toBe('[{"a":1,"b":2},{"c":"abc"}]');
|
123
|
+
expect(formData.myDate).toBe(dateValue);
|
124
|
+
expect(formData.myBoolean).toBeTruthy();
|
125
|
+
expect(formData.myString).toBe("Hello, world!");
|
126
|
+
expect(formData.myEmptyString).toBe("");
|
127
|
+
expect(formData.myNumber).toBe(380);
|
128
|
+
expect(typeof formData.file).toBe("object");
|
129
|
+
|
130
|
+
const encodedFormData = encodeFormData(params);
|
131
|
+
expect(encodedFormData instanceof FormData).toBeTruthy();
|
132
|
+
});
|
133
|
+
});
|
@@ -0,0 +1,37 @@
|
|
1
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
import { getPortalUrl } from "../../src/index";
|
5
|
+
|
6
|
+
describe("getPortalUrl", () => {
|
7
|
+
it("should default to arcgis.com", () => {
|
8
|
+
const url = getPortalUrl();
|
9
|
+
expect(url).toEqual("https://www.arcgis.com/sharing/rest");
|
10
|
+
});
|
11
|
+
it("should use the portal from authorization if passed", () => {
|
12
|
+
const requestOptions = {
|
13
|
+
authentication: {
|
14
|
+
portal: "https://foo.com/arcgis/sharing/rest",
|
15
|
+
getToken() {
|
16
|
+
return Promise.resolve("fake");
|
17
|
+
}
|
18
|
+
}
|
19
|
+
};
|
20
|
+
const url = getPortalUrl(requestOptions);
|
21
|
+
expect(url).toEqual("https://foo.com/arcgis/sharing/rest");
|
22
|
+
});
|
23
|
+
|
24
|
+
it("should use the portal in the requestOptions if passed", () => {
|
25
|
+
const requestOptions = {
|
26
|
+
authentication: {
|
27
|
+
portal: "https://foo.com/arcgis/sharing/rest",
|
28
|
+
getToken() {
|
29
|
+
return Promise.resolve("fake");
|
30
|
+
}
|
31
|
+
},
|
32
|
+
portal: "https://bar.com/arcgis/sharing/rest"
|
33
|
+
};
|
34
|
+
const url = getPortalUrl(requestOptions);
|
35
|
+
expect(url).toEqual("https://bar.com/arcgis/sharing/rest");
|
36
|
+
});
|
37
|
+
});
|
@@ -0,0 +1,97 @@
|
|
1
|
+
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
import { getSelf, getPortal } from "../../src/index";
|
5
|
+
|
6
|
+
import { PortalResponse } from "./../mocks/portal";
|
7
|
+
|
8
|
+
import * as fetchMock from "fetch-mock";
|
9
|
+
|
10
|
+
describe("portal", () => {
|
11
|
+
let paramsSpy: jasmine.Spy;
|
12
|
+
|
13
|
+
beforeEach(() => {
|
14
|
+
paramsSpy = spyOn(FormData.prototype, "append").and.callThrough();
|
15
|
+
});
|
16
|
+
|
17
|
+
afterAll(() => {
|
18
|
+
paramsSpy.calls.reset();
|
19
|
+
});
|
20
|
+
|
21
|
+
afterEach(fetchMock.restore);
|
22
|
+
|
23
|
+
describe("getPortal", () => {
|
24
|
+
// setup an authmgr to use in all these tests
|
25
|
+
const MOCK_AUTH = {
|
26
|
+
getToken() {
|
27
|
+
return Promise.resolve("fake-token");
|
28
|
+
},
|
29
|
+
portal: "https://myorg.maps.arcgis.com/sharing/rest"
|
30
|
+
};
|
31
|
+
const MOCK_REQOPTS = {
|
32
|
+
authentication: MOCK_AUTH
|
33
|
+
};
|
34
|
+
|
35
|
+
it("should get the portal by id", done => {
|
36
|
+
fetchMock.once("*", PortalResponse);
|
37
|
+
getPortal("5BZFaKe", MOCK_REQOPTS)
|
38
|
+
.then(response => {
|
39
|
+
expect(fetchMock.called()).toEqual(true);
|
40
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
41
|
+
expect(url).toEqual(
|
42
|
+
"https://myorg.maps.arcgis.com/sharing/rest/portals/5BZFaKe?f=json&token=fake-token"
|
43
|
+
);
|
44
|
+
expect(options.method).toBe("GET");
|
45
|
+
done();
|
46
|
+
})
|
47
|
+
.catch(e => {
|
48
|
+
fail(e);
|
49
|
+
});
|
50
|
+
});
|
51
|
+
it("should get the portal self if no id", done => {
|
52
|
+
fetchMock.once("*", PortalResponse);
|
53
|
+
getPortal(null, MOCK_REQOPTS)
|
54
|
+
.then(response => {
|
55
|
+
expect(fetchMock.called()).toEqual(true);
|
56
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
57
|
+
expect(url).toEqual(
|
58
|
+
"https://myorg.maps.arcgis.com/sharing/rest/portals/self?f=json&token=fake-token"
|
59
|
+
);
|
60
|
+
expect(options.method).toBe("GET");
|
61
|
+
done();
|
62
|
+
})
|
63
|
+
.catch(e => {
|
64
|
+
fail(e);
|
65
|
+
});
|
66
|
+
});
|
67
|
+
});
|
68
|
+
describe("getSelf", () => {
|
69
|
+
// setup an authmgr to use in all these tests
|
70
|
+
const MOCK_AUTH = {
|
71
|
+
getToken() {
|
72
|
+
return Promise.resolve("fake-token");
|
73
|
+
},
|
74
|
+
portal: "https://myorg.maps.arcgis.com/sharing/rest"
|
75
|
+
};
|
76
|
+
const MOCK_REQOPTS = {
|
77
|
+
authentication: MOCK_AUTH
|
78
|
+
};
|
79
|
+
|
80
|
+
it("should get the portal by id", done => {
|
81
|
+
fetchMock.once("*", PortalResponse);
|
82
|
+
getSelf(MOCK_REQOPTS)
|
83
|
+
.then(response => {
|
84
|
+
expect(fetchMock.called()).toEqual(true);
|
85
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
86
|
+
expect(url).toEqual(
|
87
|
+
"https://myorg.maps.arcgis.com/sharing/rest/portals/self?f=json&token=fake-token"
|
88
|
+
);
|
89
|
+
expect(options.method).toBe("GET");
|
90
|
+
done();
|
91
|
+
})
|
92
|
+
.catch(e => {
|
93
|
+
fail(e);
|
94
|
+
});
|
95
|
+
});
|
96
|
+
});
|
97
|
+
});
|