etincidunt 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 +29 -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 +14 -0
- package/demos/batch-geocoder-node/batch-geocode.js +112 -0
- package/demos/batch-geocoder-node/config-template.js +18 -0
- package/demos/batch-geocoder-node/package-lock.json +109 -0
- package/demos/batch-geocoder-node/package.json +37 -0
- package/demos/express/README.md +10 -0
- package/demos/express/config.json.template +3 -0
- package/demos/express/package-lock.json +388 -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 +163 -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/vue/.babelrc +6 -0
- package/demos/vue/.env.example +8 -0
- package/demos/vue/README.md +17 -0
- package/demos/vue/index.html +21 -0
- package/demos/vue/package-lock.json +7236 -0
- package/demos/vue/package.json +39 -0
- package/demos/vue/src/assets/logo.svg +29 -0
- package/demos/vue/src/components/App.vue +302 -0
- package/demos/vue/src/components/Authenticate.vue +68 -0
- package/demos/vue/src/components/Loader.vue +216 -0
- package/demos/vue/src/main.js +75 -0
- package/demos/vue/webpack.config.js +84 -0
- package/docs/FAQ.md +28 -0
- package/docs/HISTORY.md +62 -0
- package/docs/acetate.config.js +214 -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 +9 -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 +30 -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 +113 -0
- package/docs/src/js/index.js +1 -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 +91 -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 +91 -0
- package/packages/arcgis-rest-auth/src/UserSession.ts +829 -0
- package/packages/arcgis-rest-auth/src/authenticated-request-options.ts +21 -0
- package/packages/arcgis-rest-auth/src/fetch-token.ts +55 -0
- package/packages/arcgis-rest-auth/src/generate-token.ts +36 -0
- package/packages/arcgis-rest-auth/src/index.ts +5 -0
- package/packages/arcgis-rest-auth/test/ApplicationSession.test.ts +121 -0
- package/packages/arcgis-rest-auth/test/UserSession.test.ts +883 -0
- package/packages/arcgis-rest-auth/test/fetchToken.test.ts +76 -0
- package/packages/arcgis-rest-auth/test/generateToken.test.ts +36 -0
- package/packages/arcgis-rest-auth/test/utils.ts +11 -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 +51 -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 +1225 -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 +82 -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 +77 -0
- package/packages/arcgis-rest-feature-service/src/index.ts +8 -0
- package/packages/arcgis-rest-feature-service/src/query.ts +174 -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 +179 -0
- package/packages/arcgis-rest-feature-service/test/features.test.ts +172 -0
- package/packages/arcgis-rest-feature-service/test/mocks/feature.ts +220 -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-geocoder/README.md +73 -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 +81 -0
- package/packages/arcgis-rest-geocoder/src/index.ts +4 -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/geocoder.test.ts +510 -0
- package/packages/arcgis-rest-geocoder/test/mocks/responses.ts +588 -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/groups.ts +272 -0
- package/packages/arcgis-rest-groups/src/index.ts +1 -0
- package/packages/arcgis-rest-groups/test/groups.test.ts +280 -0
- package/packages/arcgis-rest-groups/test/mocks/responses.ts +137 -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/index.ts +1 -0
- package/packages/arcgis-rest-items/src/items.ts +498 -0
- package/packages/arcgis-rest-items/test/items.test.ts +1153 -0
- package/packages/arcgis-rest-items/test/mocks/foo.zip +0 -0
- package/packages/arcgis-rest-items/test/mocks/item.ts +30 -0
- package/packages/arcgis-rest-items/test/mocks/resources.ts +28 -0
- package/packages/arcgis-rest-items/test/mocks/search.ts +60 -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 +10 -0
- package/packages/arcgis-rest-request/src/request.ts +259 -0
- package/packages/arcgis-rest-request/src/utils/ArcGISAuthError.ts +67 -0
- package/packages/arcgis-rest-request/src/utils/ArcGISRequestError.ts +73 -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 +29 -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 +59 -0
- package/packages/arcgis-rest-request/test/mocks/geojson-feature-collection.ts +10 -0
- package/packages/arcgis-rest-request/test/mocks/portal.ts +109 -0
- package/packages/arcgis-rest-request/test/mocks/sharing-rest-info.ts +38 -0
- package/packages/arcgis-rest-request/test/mocks/webmap.ts +38 -0
- package/packages/arcgis-rest-request/test/request.test.ts +296 -0
- package/packages/arcgis-rest-request/test/utils/ArcGISAuthError.test.ts +167 -0
- package/packages/arcgis-rest-request/test/utils/ArcGISRequestError.test.ts +40 -0
- package/packages/arcgis-rest-request/test/utils/check-for-errors.test.ts +101 -0
- package/packages/arcgis-rest-request/test/utils/encode-form-data.test.ts +112 -0
- package/packages/arcgis-rest-request/test/utils/get-portal-url.test.ts +34 -0
- package/packages/arcgis-rest-request/test/utils/portal.test.ts +94 -0
- package/packages/arcgis-rest-request/test/utils/process-params.test.ts +190 -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 +55 -0
- package/packages/arcgis-rest-sharing/src/access.ts +91 -0
- package/packages/arcgis-rest-sharing/src/group-sharing.ts +212 -0
- package/packages/arcgis-rest-sharing/src/helpers.ts +92 -0
- package/packages/arcgis-rest-sharing/src/index.ts +2 -0
- package/packages/arcgis-rest-sharing/test/access.test.ts +153 -0
- package/packages/arcgis-rest-sharing/test/group-sharing.test.ts +436 -0
- package/packages/arcgis-rest-sharing/test/mocks/sharing.ts +15 -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/index.ts +1 -0
- package/packages/arcgis-rest-users/src/users.ts +70 -0
- package/packages/arcgis-rest-users/test/mocks/responses.ts +170 -0
- package/packages/arcgis-rest-users/test/users.test.ts +97 -0
- package/packages/arcgis-rest-users/tsconfig.json +6 -0
- package/support/FormData.d.ts +1 -0
- package/support/changelog.js +388 -0
- package/support/commit-template.txt +19 -0
- package/support/deploy-doc-site.js +16 -0
- package/support/publish.sh +40 -0
- package/support/test-helpers.js +8 -0
- package/tsconfig.json +69 -0
- package/tslint.json +14 -0
- package/umd-base-profile.js +82 -0
- package/umd-production-profile.js +13 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
{
|
2
|
+
"name": "@esri/arcgis-rest-groups",
|
3
|
+
"version": "1.6.0",
|
4
|
+
"description": "Portal Group helpers for @esri/arcgis-rest-request",
|
5
|
+
"main": "dist/node/index.js",
|
6
|
+
"browser": "dist/umd/groups.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
|
+
"files": [
|
12
|
+
"dist/**"
|
13
|
+
],
|
14
|
+
"dependencies": {
|
15
|
+
"tslib": "^1.7.1"
|
16
|
+
},
|
17
|
+
"peerDependencies": {
|
18
|
+
"@esri/arcgis-rest-auth": "^1.5.1",
|
19
|
+
"@esri/arcgis-rest-common-types": "^1.5.1",
|
20
|
+
"@esri/arcgis-rest-request": "^1.5.1"
|
21
|
+
},
|
22
|
+
"devDependencies": {
|
23
|
+
"@esri/arcgis-rest-auth": "^1.6.0",
|
24
|
+
"@esri/arcgis-rest-common-types": "^1.6.0",
|
25
|
+
"@esri/arcgis-rest-request": "^1.6.0"
|
26
|
+
},
|
27
|
+
"scripts": {
|
28
|
+
"prepare": "npm run build",
|
29
|
+
"build": "npm run build:node && npm run build:umd && npm run build:esm",
|
30
|
+
"build:esm": "tsc -p ./tsconfig.json --module es2015 --outDir ./dist/esm --declaration",
|
31
|
+
"build:umd": "rollup -c ../../umd-base-profile.js && rollup -c ../../umd-production-profile.js",
|
32
|
+
"build:node": "tsc -p ./tsconfig.json --module commonjs --outDir ./dist/node"
|
33
|
+
},
|
34
|
+
"publishConfig": {
|
35
|
+
"access": "public"
|
36
|
+
},
|
37
|
+
"repository": {
|
38
|
+
"type": "git",
|
39
|
+
"url": "git+https://github.com/Esri/arcgis-rest-js.git"
|
40
|
+
},
|
41
|
+
"contributors": [
|
42
|
+
{
|
43
|
+
"name": "Dave Bouwman",
|
44
|
+
"email": "dbouwman@esri.com",
|
45
|
+
"url": "http://blog.davebouwman.com/"
|
46
|
+
}
|
47
|
+
],
|
48
|
+
"bugs": {
|
49
|
+
"url": "https://github.com/Esri/arcgis-rest-js/issues"
|
50
|
+
},
|
51
|
+
"homepage": "https://github.com/Esri/arcgis-rest-js#readme"
|
52
|
+
}
|
@@ -0,0 +1,272 @@
|
|
1
|
+
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
|
2
|
+
* Apache-2.0 */
|
3
|
+
|
4
|
+
import {
|
5
|
+
request,
|
6
|
+
IRequestOptions,
|
7
|
+
// IParams,
|
8
|
+
getPortalUrl
|
9
|
+
} from "@esri/arcgis-rest-request";
|
10
|
+
|
11
|
+
import {
|
12
|
+
IPagingParams,
|
13
|
+
IItem,
|
14
|
+
IItemUpdate,
|
15
|
+
IGroupAdd,
|
16
|
+
IGroup
|
17
|
+
} from "@esri/arcgis-rest-common-types";
|
18
|
+
|
19
|
+
export interface IPagingParamsRequestOptions extends IRequestOptions {
|
20
|
+
paging: IPagingParams;
|
21
|
+
}
|
22
|
+
|
23
|
+
export interface IGroupIdRequestOptions extends IRequestOptions {
|
24
|
+
id: string;
|
25
|
+
}
|
26
|
+
|
27
|
+
export interface IGroupAddRequestOptions extends IRequestOptions {
|
28
|
+
group: IGroupAdd;
|
29
|
+
}
|
30
|
+
|
31
|
+
export interface IGroupUpdateRequestOptions extends IRequestOptions {
|
32
|
+
group: IItemUpdate;
|
33
|
+
}
|
34
|
+
|
35
|
+
export interface IGroupSearchRequest extends IPagingParams {
|
36
|
+
q: string;
|
37
|
+
sortField?: string;
|
38
|
+
sortOrder?: string;
|
39
|
+
[key: string]: any;
|
40
|
+
}
|
41
|
+
|
42
|
+
export interface IGroupSearchResult {
|
43
|
+
/**
|
44
|
+
* Matches the REST APIs form param
|
45
|
+
*/
|
46
|
+
query: string;
|
47
|
+
total: number;
|
48
|
+
start: number;
|
49
|
+
num: number;
|
50
|
+
nextStart: number;
|
51
|
+
results: IGroup[];
|
52
|
+
}
|
53
|
+
|
54
|
+
export interface IGroupContentResult {
|
55
|
+
total: number;
|
56
|
+
start: number;
|
57
|
+
num: number;
|
58
|
+
nextStart: number;
|
59
|
+
items: IItem[];
|
60
|
+
}
|
61
|
+
|
62
|
+
export interface IGroupUsersResult {
|
63
|
+
owner: string;
|
64
|
+
admins: string[];
|
65
|
+
users: string[];
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Search for groups via the portal api
|
70
|
+
*
|
71
|
+
* ```js
|
72
|
+
* import { searchGroups } from '@esri/arcgis-rest-groups';
|
73
|
+
*
|
74
|
+
* searchgroups({q:'water'})
|
75
|
+
* .then((results) => {
|
76
|
+
* console.log(response.results.total); // 355
|
77
|
+
* })
|
78
|
+
* ```
|
79
|
+
*
|
80
|
+
* @param searchForm - Search request
|
81
|
+
* @param requestOptions - Options for the request
|
82
|
+
* @returns A Promise that will resolve with the data from the response.
|
83
|
+
*/
|
84
|
+
export function searchGroups(
|
85
|
+
searchForm: IGroupSearchRequest,
|
86
|
+
requestOptions?: IRequestOptions
|
87
|
+
): Promise<IGroupSearchResult> {
|
88
|
+
// construct the search url
|
89
|
+
const url = `${getPortalUrl(requestOptions)}/community/groups`;
|
90
|
+
|
91
|
+
// default to a GET
|
92
|
+
const options: IRequestOptions = {
|
93
|
+
...{ httpMethod: "GET" },
|
94
|
+
...requestOptions
|
95
|
+
};
|
96
|
+
|
97
|
+
options.params = { ...searchForm };
|
98
|
+
|
99
|
+
// send the request
|
100
|
+
return request(url, options);
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
*
|
105
|
+
* @param id - Group Id
|
106
|
+
* @param requestOptions - Options for the request
|
107
|
+
* @returns A Promise that will resolve with the data from the response.
|
108
|
+
*/
|
109
|
+
export function getGroup(
|
110
|
+
id: string,
|
111
|
+
requestOptions?: IRequestOptions
|
112
|
+
): Promise<IGroup> {
|
113
|
+
const url = `${getPortalUrl(requestOptions)}/community/groups/${id}`;
|
114
|
+
// default to a GET request
|
115
|
+
const options: IRequestOptions = {
|
116
|
+
...{ httpMethod: "GET" },
|
117
|
+
...requestOptions
|
118
|
+
};
|
119
|
+
return request(url, options);
|
120
|
+
}
|
121
|
+
|
122
|
+
/**
|
123
|
+
* Returns the content of a Group. Since the group may contain 1000s of items
|
124
|
+
* the requestParams allow for paging.
|
125
|
+
* @param id - Group Id
|
126
|
+
* @param requestOptions - Options for the request, including paging parameters.
|
127
|
+
* @returns A Promise that will resolve with the content of the group.
|
128
|
+
*/
|
129
|
+
export function getGroupContent(
|
130
|
+
id: string,
|
131
|
+
requestOptions?: IPagingParamsRequestOptions
|
132
|
+
): Promise<IGroup> {
|
133
|
+
const url = `${getPortalUrl(requestOptions)}/content/groups/${id}`;
|
134
|
+
|
135
|
+
// default to a GET request
|
136
|
+
const options: IRequestOptions = {
|
137
|
+
...{ httpMethod: "GET" },
|
138
|
+
params: { start: 1, num: 100 },
|
139
|
+
...requestOptions
|
140
|
+
} as IPagingParamsRequestOptions;
|
141
|
+
|
142
|
+
// is this the most concise way to mixin with the defaults above?
|
143
|
+
if (requestOptions && requestOptions.paging) {
|
144
|
+
options.params = { ...requestOptions.paging };
|
145
|
+
}
|
146
|
+
|
147
|
+
return request(url, options);
|
148
|
+
}
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Get the usernames of the admins and members. Does not return actual 'User' objects. Those must be
|
152
|
+
* retrieved via separate calls to the User's API.
|
153
|
+
* @param id - Group Id
|
154
|
+
* @param requestOptions - Options for the request
|
155
|
+
* @returns A Promise that will resolve with arrays of the group admin usernames and the member usernames
|
156
|
+
*/
|
157
|
+
export function getGroupUsers(
|
158
|
+
id: string,
|
159
|
+
requestOptions?: IRequestOptions
|
160
|
+
): Promise<IGroupUsersResult> {
|
161
|
+
const url = `${getPortalUrl(requestOptions)}/community/groups/${id}/users`;
|
162
|
+
// default to a GET request
|
163
|
+
const options: IRequestOptions = {
|
164
|
+
...{ httpMethod: "GET" },
|
165
|
+
...requestOptions
|
166
|
+
};
|
167
|
+
return request(url, options);
|
168
|
+
}
|
169
|
+
|
170
|
+
/**
|
171
|
+
* Create a new Group.
|
172
|
+
* Note: The group name must be unique within the user's organization.
|
173
|
+
* @param requestOptions - Options for the request, including a group object
|
174
|
+
* @returns A Promise that will resolve with the success/failure status of the request
|
175
|
+
*/
|
176
|
+
export function createGroup(
|
177
|
+
requestOptions: IGroupAddRequestOptions
|
178
|
+
): Promise<any> {
|
179
|
+
const url = `${getPortalUrl(requestOptions)}/community/createGroup`;
|
180
|
+
const options: IGroupAddRequestOptions = {
|
181
|
+
...requestOptions
|
182
|
+
};
|
183
|
+
// serialize the group into something Portal will accept
|
184
|
+
options.params = serializeGroup(requestOptions.group);
|
185
|
+
return request(url, options);
|
186
|
+
}
|
187
|
+
|
188
|
+
/**
|
189
|
+
* Update the properties of a group - title, tags etc.
|
190
|
+
* @param requestOptions - Options for the request, including the group
|
191
|
+
* @returns A Promise that will resolve with the success/failure status of the request
|
192
|
+
*/
|
193
|
+
export function updateGroup(
|
194
|
+
requestOptions: IGroupUpdateRequestOptions
|
195
|
+
): Promise<any> {
|
196
|
+
const url = `${getPortalUrl(requestOptions)}/community/groups/${
|
197
|
+
requestOptions.group.id
|
198
|
+
}/update`;
|
199
|
+
|
200
|
+
const options: IGroupUpdateRequestOptions = {
|
201
|
+
...requestOptions
|
202
|
+
};
|
203
|
+
// serialize the group into something Portal will accept
|
204
|
+
options.params = serializeGroup(requestOptions.group);
|
205
|
+
return request(url, options);
|
206
|
+
}
|
207
|
+
|
208
|
+
/**
|
209
|
+
* Delete a group.
|
210
|
+
* @param requestOptions - Options for the request
|
211
|
+
* @returns A Promise that will resolve with the success/failure status of the request
|
212
|
+
*/
|
213
|
+
export function removeGroup(
|
214
|
+
requestOptions: IGroupIdRequestOptions
|
215
|
+
): Promise<any> {
|
216
|
+
const url = `${getPortalUrl(requestOptions)}/community/groups/${
|
217
|
+
requestOptions.id
|
218
|
+
}/delete`;
|
219
|
+
const options: IGroupIdRequestOptions = {
|
220
|
+
...requestOptions
|
221
|
+
};
|
222
|
+
return request(url, options);
|
223
|
+
}
|
224
|
+
|
225
|
+
/**
|
226
|
+
* Protect a Group. This simply means a user must unprotect the group prior to deleting it
|
227
|
+
* @param requestOptions - Options for the request
|
228
|
+
* @returns A Promise that will resolve with the success/failure status of the request
|
229
|
+
*/
|
230
|
+
export function protectGroup(
|
231
|
+
requestOptions: IGroupIdRequestOptions
|
232
|
+
): Promise<any> {
|
233
|
+
const url = `${getPortalUrl(requestOptions)}/community/groups/${
|
234
|
+
requestOptions.id
|
235
|
+
}/protect`;
|
236
|
+
const options: IGroupIdRequestOptions = {
|
237
|
+
...requestOptions
|
238
|
+
};
|
239
|
+
return request(url, options);
|
240
|
+
}
|
241
|
+
|
242
|
+
/**
|
243
|
+
* Unprotect a Group.
|
244
|
+
* @param requestOptions - Options for the request
|
245
|
+
* @returns A Promise that will resolve with the success/failure status of the request
|
246
|
+
*/
|
247
|
+
export function unprotectGroup(
|
248
|
+
requestOptions: IGroupIdRequestOptions
|
249
|
+
): Promise<any> {
|
250
|
+
const url = `${getPortalUrl(requestOptions)}/community/groups/${
|
251
|
+
requestOptions.id
|
252
|
+
}/unprotect`;
|
253
|
+
const options: IGroupIdRequestOptions = {
|
254
|
+
...requestOptions
|
255
|
+
};
|
256
|
+
return request(url, options);
|
257
|
+
}
|
258
|
+
|
259
|
+
/**
|
260
|
+
* Serialize a group into a json format accepted by the Portal API
|
261
|
+
* for create and update operations
|
262
|
+
*
|
263
|
+
* @param group IGroup to be serialized
|
264
|
+
* @returns a formatted JSON object to be sent to Portal
|
265
|
+
*/
|
266
|
+
function serializeGroup(group: IGroupAdd | IItemUpdate | IGroup): any {
|
267
|
+
// create a clone so we're not messing with the original
|
268
|
+
const clone = JSON.parse(JSON.stringify(group));
|
269
|
+
// join and tags...
|
270
|
+
clone.tags = clone.tags.join(", ");
|
271
|
+
return clone;
|
272
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./groups";
|
@@ -0,0 +1,280 @@
|
|
1
|
+
import {
|
2
|
+
searchGroups,
|
3
|
+
getGroup,
|
4
|
+
getGroupContent,
|
5
|
+
getGroupUsers,
|
6
|
+
createGroup,
|
7
|
+
updateGroup,
|
8
|
+
removeGroup,
|
9
|
+
protectGroup,
|
10
|
+
unprotectGroup
|
11
|
+
} from "../src/index";
|
12
|
+
|
13
|
+
import {
|
14
|
+
GroupSearchResponse,
|
15
|
+
GroupEditResponse,
|
16
|
+
GroupResponse,
|
17
|
+
GroupContentResponse,
|
18
|
+
GroupUsersResponse
|
19
|
+
} from "./mocks/responses";
|
20
|
+
import { encodeParam } from "@esri/arcgis-rest-request";
|
21
|
+
import * as fetchMock from "fetch-mock";
|
22
|
+
|
23
|
+
describe("groups", () => {
|
24
|
+
afterEach(fetchMock.restore);
|
25
|
+
|
26
|
+
describe("searchGroups", () => {
|
27
|
+
it("should make a simple, unauthenticated group search request", done => {
|
28
|
+
fetchMock.once("*", GroupSearchResponse);
|
29
|
+
|
30
|
+
searchGroups({ q: "water" })
|
31
|
+
.then(response => {
|
32
|
+
expect(fetchMock.called()).toEqual(true);
|
33
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
34
|
+
expect(url).toEqual(
|
35
|
+
"https://www.arcgis.com/sharing/rest/community/groups?f=json&q=water"
|
36
|
+
);
|
37
|
+
expect(options.method).toBe("GET");
|
38
|
+
done();
|
39
|
+
})
|
40
|
+
.catch(e => {
|
41
|
+
fail(e);
|
42
|
+
});
|
43
|
+
});
|
44
|
+
|
45
|
+
it("should take num, start, sortField, sortOrder and construct the request", done => {
|
46
|
+
fetchMock.once("*", GroupSearchResponse);
|
47
|
+
searchGroups({
|
48
|
+
q: "water",
|
49
|
+
start: 4,
|
50
|
+
num: 7,
|
51
|
+
sortField: "owner",
|
52
|
+
sortOrder: "desc"
|
53
|
+
})
|
54
|
+
.then(response => {
|
55
|
+
expect(fetchMock.called()).toEqual(true);
|
56
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
57
|
+
expect(url).toEqual(
|
58
|
+
"https://www.arcgis.com/sharing/rest/community/groups?f=json&q=water&start=4&num=7&sortField=owner&sortOrder=desc"
|
59
|
+
);
|
60
|
+
expect(options.method).toBe("GET");
|
61
|
+
done();
|
62
|
+
})
|
63
|
+
.catch(e => {
|
64
|
+
fail(e);
|
65
|
+
});
|
66
|
+
});
|
67
|
+
});
|
68
|
+
describe("getGroup", () => {
|
69
|
+
it("should return a group", done => {
|
70
|
+
fetchMock.once("*", GroupResponse);
|
71
|
+
getGroup("3ef")
|
72
|
+
.then(response => {
|
73
|
+
expect(fetchMock.called()).toEqual(true);
|
74
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
75
|
+
expect(url).toEqual(
|
76
|
+
"https://www.arcgis.com/sharing/rest/community/groups/3ef?f=json"
|
77
|
+
);
|
78
|
+
expect(options.method).toBe("GET");
|
79
|
+
done();
|
80
|
+
})
|
81
|
+
.catch(e => {
|
82
|
+
fail(e);
|
83
|
+
});
|
84
|
+
});
|
85
|
+
});
|
86
|
+
describe("getGroupContent", () => {
|
87
|
+
it("should return group content", done => {
|
88
|
+
fetchMock.once("*", GroupContentResponse);
|
89
|
+
getGroupContent("3ef")
|
90
|
+
.then(response => {
|
91
|
+
expect(fetchMock.called()).toEqual(true);
|
92
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
93
|
+
expect(url).toEqual(
|
94
|
+
"https://www.arcgis.com/sharing/rest/content/groups/3ef?f=json&start=1&num=100"
|
95
|
+
);
|
96
|
+
expect(options.method).toBe("GET");
|
97
|
+
done();
|
98
|
+
})
|
99
|
+
.catch(e => {
|
100
|
+
fail(e);
|
101
|
+
});
|
102
|
+
});
|
103
|
+
it("should return group content, paged", done => {
|
104
|
+
fetchMock.once("*", GroupContentResponse);
|
105
|
+
getGroupContent("3ef", { paging: { start: 4, num: 7 } })
|
106
|
+
.then(response => {
|
107
|
+
expect(fetchMock.called()).toEqual(true);
|
108
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
109
|
+
expect(url).toEqual(
|
110
|
+
"https://www.arcgis.com/sharing/rest/content/groups/3ef?f=json&start=4&num=7"
|
111
|
+
);
|
112
|
+
expect(options.method).toBe("GET");
|
113
|
+
done();
|
114
|
+
})
|
115
|
+
.catch(e => {
|
116
|
+
fail(e);
|
117
|
+
});
|
118
|
+
});
|
119
|
+
});
|
120
|
+
|
121
|
+
describe("authenticted methods", () => {
|
122
|
+
const MOCK_AUTH = {
|
123
|
+
getToken() {
|
124
|
+
return Promise.resolve("fake-token");
|
125
|
+
},
|
126
|
+
portal: "https://myorg.maps.arcgis.com/sharing/rest"
|
127
|
+
};
|
128
|
+
const MOCK_REQOPTS = {
|
129
|
+
authentication: MOCK_AUTH
|
130
|
+
};
|
131
|
+
|
132
|
+
it("should make a simple, authenticated group search request", done => {
|
133
|
+
fetchMock.once("*", GroupSearchResponse);
|
134
|
+
|
135
|
+
searchGroups({ q: "water" }, MOCK_REQOPTS)
|
136
|
+
.then(response => {
|
137
|
+
expect(fetchMock.called()).toEqual(true);
|
138
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
139
|
+
expect(url).toEqual(
|
140
|
+
"https://myorg.maps.arcgis.com/sharing/rest/community/groups?f=json&q=water&token=fake-token"
|
141
|
+
);
|
142
|
+
expect(options.method).toBe("GET");
|
143
|
+
done();
|
144
|
+
})
|
145
|
+
.catch(e => {
|
146
|
+
fail(e);
|
147
|
+
});
|
148
|
+
});
|
149
|
+
it("should create a group", done => {
|
150
|
+
fetchMock.once("*", GroupEditResponse);
|
151
|
+
const fakeGroup = {
|
152
|
+
title: "fake group",
|
153
|
+
owner: "fakeUser",
|
154
|
+
tags: ["foo", "bar"],
|
155
|
+
description: "my fake group"
|
156
|
+
};
|
157
|
+
createGroup({ group: fakeGroup, ...MOCK_REQOPTS })
|
158
|
+
.then(response => {
|
159
|
+
expect(fetchMock.called()).toEqual(true);
|
160
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
161
|
+
expect(url).toEqual(
|
162
|
+
"https://myorg.maps.arcgis.com/sharing/rest/community/createGroup"
|
163
|
+
);
|
164
|
+
expect(options.method).toBe("POST");
|
165
|
+
expect(options.body).toContain(encodeParam("f", "json"));
|
166
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
167
|
+
expect(options.body).toContain(encodeParam("owner", "fakeUser"));
|
168
|
+
// ensure the array props are serialized into strings
|
169
|
+
expect(options.body).toContain(encodeParam("tags", "foo, bar"));
|
170
|
+
done();
|
171
|
+
})
|
172
|
+
.catch(e => {
|
173
|
+
fail(e);
|
174
|
+
});
|
175
|
+
});
|
176
|
+
it("should update a group", done => {
|
177
|
+
fetchMock.once("*", GroupEditResponse);
|
178
|
+
const fakeGroup = {
|
179
|
+
id: "5bc",
|
180
|
+
title: "fake group",
|
181
|
+
owner: "fakeUser",
|
182
|
+
tags: ["foo", "bar"],
|
183
|
+
description: "my fake group"
|
184
|
+
};
|
185
|
+
updateGroup({ group: fakeGroup, ...MOCK_REQOPTS })
|
186
|
+
.then(response => {
|
187
|
+
expect(fetchMock.called()).toEqual(true);
|
188
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
189
|
+
expect(url).toEqual(
|
190
|
+
"https://myorg.maps.arcgis.com/sharing/rest/community/groups/5bc/update"
|
191
|
+
);
|
192
|
+
expect(options.method).toBe("POST");
|
193
|
+
expect(options.body).toContain(encodeParam("f", "json"));
|
194
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
195
|
+
expect(options.body).toContain(encodeParam("owner", "fakeUser"));
|
196
|
+
// ensure the array props are serialized into strings
|
197
|
+
expect(options.body).toContain(encodeParam("tags", "foo, bar"));
|
198
|
+
done();
|
199
|
+
})
|
200
|
+
.catch(e => {
|
201
|
+
fail(e);
|
202
|
+
});
|
203
|
+
});
|
204
|
+
it("should remove a group", done => {
|
205
|
+
fetchMock.once("*", GroupEditResponse);
|
206
|
+
|
207
|
+
removeGroup({ id: "5bc", ...MOCK_REQOPTS })
|
208
|
+
.then(response => {
|
209
|
+
expect(fetchMock.called()).toEqual(true);
|
210
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
211
|
+
expect(url).toEqual(
|
212
|
+
"https://myorg.maps.arcgis.com/sharing/rest/community/groups/5bc/delete"
|
213
|
+
);
|
214
|
+
expect(options.method).toBe("POST");
|
215
|
+
expect(options.body).toContain(encodeParam("f", "json"));
|
216
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
217
|
+
done();
|
218
|
+
})
|
219
|
+
.catch(e => {
|
220
|
+
fail(e);
|
221
|
+
});
|
222
|
+
});
|
223
|
+
it("should protect a group", done => {
|
224
|
+
fetchMock.once("*", GroupEditResponse);
|
225
|
+
|
226
|
+
protectGroup({ id: "5bc", ...MOCK_REQOPTS })
|
227
|
+
.then(response => {
|
228
|
+
expect(fetchMock.called()).toEqual(true);
|
229
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
230
|
+
expect(url).toEqual(
|
231
|
+
"https://myorg.maps.arcgis.com/sharing/rest/community/groups/5bc/protect"
|
232
|
+
);
|
233
|
+
expect(options.method).toBe("POST");
|
234
|
+
expect(options.body).toContain(encodeParam("f", "json"));
|
235
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
236
|
+
done();
|
237
|
+
})
|
238
|
+
.catch(e => {
|
239
|
+
fail(e);
|
240
|
+
});
|
241
|
+
});
|
242
|
+
it("should unprotect a group", done => {
|
243
|
+
fetchMock.once("*", GroupEditResponse);
|
244
|
+
|
245
|
+
unprotectGroup({ id: "5bc", ...MOCK_REQOPTS })
|
246
|
+
.then(response => {
|
247
|
+
expect(fetchMock.called()).toEqual(true);
|
248
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
249
|
+
expect(url).toEqual(
|
250
|
+
"https://myorg.maps.arcgis.com/sharing/rest/community/groups/5bc/unprotect"
|
251
|
+
);
|
252
|
+
expect(options.method).toBe("POST");
|
253
|
+
expect(options.body).toContain(encodeParam("f", "json"));
|
254
|
+
expect(options.body).toContain(encodeParam("token", "fake-token"));
|
255
|
+
done();
|
256
|
+
})
|
257
|
+
.catch(e => {
|
258
|
+
fail(e);
|
259
|
+
});
|
260
|
+
});
|
261
|
+
it("should return group users", done => {
|
262
|
+
fetchMock.once("*", GroupUsersResponse);
|
263
|
+
|
264
|
+
getGroupUsers("5bc", MOCK_REQOPTS)
|
265
|
+
.then(response => {
|
266
|
+
expect(fetchMock.called()).toEqual(true);
|
267
|
+
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
|
268
|
+
expect(url).toEqual(
|
269
|
+
"https://myorg.maps.arcgis.com/sharing/rest/community/groups/5bc/users?f=json&token=fake-token"
|
270
|
+
);
|
271
|
+
expect(options.method).toBe("GET");
|
272
|
+
done();
|
273
|
+
})
|
274
|
+
.catch(e => {
|
275
|
+
fail(e);
|
276
|
+
});
|
277
|
+
});
|
278
|
+
// it('should make authenticated call to get the group content', done => {})
|
279
|
+
});
|
280
|
+
});
|