Skip to main content

Users

Users ⇐ APIClient

Use Fonoster Users, a capability of Fonoster, to create, update, get and delete Users. Users requires of a running Fonoster deployment.

Kind: global class
Extends: APIClient
See: module:core:APIClient

new Users(options)

Constructs a new Users object.

ParamTypeDescription
optionsClientOptionsOptions to indicate the objects endpoint

Example

const Fonoster = require("@fonoster/sdk")
const users = new Fonoster.Users()

const request = {
email: "john.doe@email.com",
name: "John Doe",
secret: "s3cur3pass",
avatar: "https://avatar.com/avt?userId=2124252"
}

users.createUser(request)
.then(result => {
console.log(result) // successful response
}).catch(e => console.error(e)) // an error occurred

users.listUsers(request) ⇒ Promise.<ListUsersResponse>

Return a list of Users.

Kind: instance method of Users

ParamTypeDescription
requestListUsersRequestRequest filters
request.emailstringOptional email filter

Example

projects.listUsers({ email: "john.doe@email.com" })
.then(result => {
console.log(result) // successful response
}).catch(e => console.error(e)) // an error occurred

users.createUser(request) ⇒ Promise.<CreateUserResponse>

Create a new Fonoster User.

Kind: instance method of Users

ParamTypeDescription
requestCreateUserRequestRequest for the provision of a new User
request.emailstringUser's email
request.namestringUser's full name
request.secretstringLogin password
request.avatarstringOptional URL to User's avatar

Example

const request = {
email: "john.doe@email.com",
name: "John Doe",
secret: "s3cur3pass",
avatar: "https://avatar.com/avt?userId=2124252"
}

users.createUser(request)
.then(result => {
console.log(result) // successful response
}).catch(e => console.error(e)) // an error occurred

users.getUser(ref) ⇒ Promise.<GetUserResponse>

Retrives an User by reference.

Kind: instance method of Users
Returns: Promise.<GetUserResponse> - The User
Throws:

  • if ref is null or User does not exist
ParamTypeDescription
refstringReference to User

Example

const ref = "507f1f77bcf86cd799439011";

users.getUser(ref)
.then(result => {
console.log(result) // returns the User payload
}).catch(e => console.error(e)) // an error occurred

users.updateUser(request) ⇒ Promise.<UpdateUserResponse>

Update a Fonoster User.

Kind: instance method of Users

ParamTypeDescription
requestUpdateUserRequestRequest update of an User
request.refstringRequired reference to the User
request.namestringOptionally update the name
request.avatarstringOptionally update the avatar
request.secretstringOptionally update User's password

Example

const request = {
name: "John Dee",
secret: "s3cur3pass"
}

users.updateUser(request)
.then(result => {
console.log(result) // returns the UpdateUserResponse payload
}).catch(e => console.error(e)) // an error occurred

users.deleteUser(ref)

Delete an Fonoster User.

Kind: instance method of Users

ParamTypeDescription
refstringUser's reference

Example

const ref = "507f1f77bcf86cd799439011"

users.deleteUser(ref)
.then(() => {
console.log("done") // returns a reference of the User
}).catch(e => console.error(e)) // an error occurred

users.createUserCredentials(request)

Login using email and a password.

Kind: instance method of Users

ParamTypeDescription
requestcreateUserCredentialsRequest update of an User
request.emailstringLogin username
request.secretstringLogin password

Example

const request = {
email: "john.doe@email.com",
secret: "s3cur3pass",
expiration: "30d"
}

users.createUserCredentials(request)
.then(result => {
console.log(result) // returns an accessKeyId and accessKeySecret
}).catch(e => console.error(e)) // an error occurred