-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from Esri/users
feat(new users package): add rest-users with a single method
- Loading branch information
Showing
9 changed files
with
406 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
[![npm version][npm-img]][npm-url] | ||
[![build status][travis-img]][travis-url] | ||
[![apache licensed](https://img.shields.io/badge/license-Apache-green.svg?style=flat-square)](https://raw.githubusercontent.com/Esri/arcgis-rest-js/master/LICENSE) | ||
|
||
[npm-img]: https://img.shields.io/npm/v/@esri/arcgis-rest-users.svg?style=flat-square | ||
[npm-url]: https://www.npmjs.com/package/@esri/arcgis-rest-users | ||
[travis-img]: https://img.shields.io/travis/Esri/arcgis-rest-js/master.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/Esri/arcgis-rest-js | ||
|
||
# @esri/arcgis-rest-users | ||
|
||
> A module for working with users in the ArcGIS REST API that runs in Node.js and modern browsers. | ||
### Example | ||
|
||
```bash | ||
npm install @esri/arcgis-rest-users | ||
``` | ||
|
||
```js | ||
import { getUser } from '@esri/arcgis-rest-groups'; | ||
|
||
getUser("jsmith") | ||
.then(response => { | ||
/* | ||
{ | ||
firstName: "John", | ||
lastName: "Smith", | ||
tags: ["GIS Analyst", "City of Redlands"], | ||
thumbnail: "myProfile.jpg", | ||
created: 1258501046000, | ||
modified: 1290625562000, | ||
d eetc. | ||
}; | ||
*/ | ||
}); | ||
``` | ||
|
||
### Issues | ||
|
||
If something isn't working the way you expected, please take a look at [previously logged issues](https://github.com/Esri/arcgis-rest-js/issues) first. Have you found a new bug? Want to request a new feature? We'd [**love**](https://github.com/Esri/arcgis-rest-js/issues/new) to hear from you. | ||
|
||
If you're looking for help you can also post issues on [GIS Stackexchange](http://gis.stackexchange.com/questions/ask?tags=esri-oss). | ||
|
||
### Versioning | ||
|
||
For transparency into the release cycle and in striving to maintain backward compatibility, @esri/arcgis-rest-js is maintained under Semantic Versioning guidelines and will adhere to these rules whenever possible. | ||
|
||
For more information on SemVer, please visit <http://semver.org/>. | ||
|
||
### Contributing | ||
|
||
Esri welcomes contributions from anyone and everyone. Please see our [guidelines for contributing](CONTRIBUTING.md). | ||
|
||
### License | ||
|
||
Copyright 2018 Esri | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
> http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
A copy of the license is available in the repository's [LICENSE](./LICENSE) file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "@esri/arcgis-rest-users", | ||
"version": "1.1.1", | ||
"description": "Portal user helpers for @esri/arcgis-rest-request", | ||
"main": "dist/node/index.js", | ||
"browser": "dist/umd/arcgis-rest-users.umd.js", | ||
"module": "dist/esm/index.js", | ||
"js:next": "dist/esm/index.js", | ||
"types": "dist/esm/index.d.ts", | ||
"license": "Apache-2.0", | ||
"files": [ | ||
"dist/**" | ||
], | ||
"dependencies": { | ||
"tslib": "^1.7.1" | ||
}, | ||
"peerDependencies": { | ||
"@esri/arcgis-rest-auth": "^1.1.1", | ||
"@esri/arcgis-rest-common-types": "^1.1.1", | ||
"@esri/arcgis-rest-request": "^1.1.1" | ||
}, | ||
"devDependencies": { | ||
"@esri/arcgis-rest-auth": "^1.1.1", | ||
"@esri/arcgis-rest-common-types": "^1.1.1", | ||
"@esri/arcgis-rest-request": "^1.1.1" | ||
}, | ||
"scripts": { | ||
"prepare": "npm run build", | ||
"build": "npm run build:node && npm run build:umd && npm run build:esm", | ||
"build:esm": "tsc -p ./tsconfig.json --module es2015 --outDir ./dist/esm --declaration", | ||
"build:umd": "rollup -c ../../umd-base-profile.js && rollup -c ../../umd-production-profile.js", | ||
"build:node": "tsc -p ./tsconfig.json --module commonjs --outDir ./dist/node" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Esri/arcgis-rest-js.git" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "John Gravois", | ||
"email": "john@esri.com" | ||
} | ||
], | ||
"bugs": { | ||
"url": "https://github.com/Esri/arcgis-rest-js/issues" | ||
}, | ||
"homepage": "https://github.com/Esri/arcgis-rest-js#readme" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./users"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
|
||
import { | ||
request, | ||
IRequestOptions, | ||
getPortalUrl | ||
} from "@esri/arcgis-rest-request"; | ||
|
||
import { IUser } from "@esri/arcgis-rest-common-types"; | ||
import { UserSession, IUserRequestOptions } from "@esri/arcgis-rest-auth"; | ||
|
||
export interface IGetUserRequestOptions extends IRequestOptions { | ||
/** | ||
* A session representing a logged in user. | ||
*/ | ||
authentication?: UserSession; | ||
/** | ||
* Supply a username if you'd like to fetch information about a different user than is being used to authenticate the request. | ||
*/ | ||
username?: string; | ||
} | ||
|
||
/** | ||
* Get information about a user | ||
* | ||
* ```js | ||
* import { getUser } from '@esri/arcgis-rest-users'; | ||
* | ||
* getUser("jsmith") | ||
* .then( | ||
* results => { | ||
* // { | ||
* // firstName: "John", | ||
* // lastName: "Smith", | ||
* // description: "Senior GIS Analyst for the city of Redlands.", | ||
* // tags: ["GIS Analyst", "City of Redlands"], | ||
* // thumbnail: "myProfile.jpg", | ||
* // created: 1258501046000, | ||
* // modified: 1290625562000, | ||
* // etc. | ||
* // }; | ||
* }) | ||
* ``` | ||
* | ||
* @param requestOptions - options to pass through in the request | ||
* @returns A Promise that will resolve with metdata about the user | ||
*/ | ||
export function getUser( | ||
requestOptions?: string | IGetUserRequestOptions | ||
): Promise<IUser> { | ||
let url; | ||
let options = { httpMethod: "GET" } as IGetUserRequestOptions; | ||
|
||
// if a username is passed, assume ArcGIS Online | ||
if (typeof requestOptions === "string") { | ||
url = `http://www.arcgis.com/sharing/rest/community/users/${requestOptions}`; | ||
} else { | ||
// if an authenticated session is passed, default to that user/portal unless another username is provided manually | ||
const username = | ||
requestOptions.username || requestOptions.authentication.username; | ||
url = `${getPortalUrl(requestOptions)}/community/users/${encodeURIComponent( | ||
username | ||
)}`; | ||
options = { | ||
...requestOptions, | ||
...options | ||
}; | ||
} | ||
|
||
// send the request | ||
return request(url, options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { IUser } from "@esri/arcgis-rest-common-types"; | ||
|
||
export const AnonUserResponse: IUser = { | ||
username: "jsmith", | ||
fullName: "John Smith", | ||
firstName: "John", | ||
lastName: "Smith", | ||
description: "Senior GIS Analyst for the city of Redlands.", | ||
tags: ["GIS Analyst", "City of Redlands"], | ||
culture: "en", | ||
region: "US", | ||
units: "metric", | ||
thumbnail: "myProfile.jpg", | ||
created: 1258501046000, | ||
modified: 1290625562000, | ||
provider: "arcgis" | ||
}; | ||
|
||
export const UserResponse = { | ||
...AnonUserResponse, | ||
availableCredits: 479.50998, | ||
assignedCredits: 500.0, | ||
preferredView: "Web", | ||
email: "jsmith33@esri.com", | ||
idpUsername: "null", | ||
favGroupId: "829e32cca4dd475a8bb63bb56b16fe3e", | ||
lastLogin: 1385766284000, | ||
mfaEnabled: false, | ||
access: "public", | ||
storageUsage: 583650, | ||
storageQuota: 2147483648, | ||
orgId: "qWAReEOCnD7eTxOe", | ||
role: "org_admin", | ||
privileges: [ | ||
"portal:admin:deleteItems", | ||
"portal:admin:reassignItems", | ||
"portal:admin:updateItems", | ||
"portal:admin:viewItems", | ||
"portal:admin:viewUsers", | ||
"portal:user:createGroup", | ||
"portal:user:createItem", | ||
"portal:user:joinGroup", | ||
"portal:user:shareToGroup", | ||
"portal:user:shareToOrg" | ||
], | ||
roleId: "RDnHQBSBbsJuIkUp", | ||
level: "2", | ||
disabled: false, | ||
groups: [ | ||
{ | ||
id: "0657d48d0c0841d793ea6ada2e6955f3", | ||
title: "Street Maps", | ||
isInvitationOnly: false, | ||
owner: "jsmith", | ||
description: | ||
"The street map group provides street maps for the city of Redlands.", | ||
snippet: "City of Redlands maps", | ||
tags: ["Redlands", "street", "maps"], | ||
phone: "http://www.esri.com", | ||
thumbnail: "streets.jpg", | ||
created: 1258501221000, | ||
modified: 1272309404000, | ||
access: "org", | ||
userMembership: { | ||
username: "jsmith", | ||
memberType: "owner", | ||
applications: 0 | ||
} | ||
} | ||
] | ||
}; |
Oops, something went wrong.