0.1.0-8 • Published 6 years ago

allthings v0.1.0-8

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

Allthings Node/Javascript SDK

Build status

Contents

  1. Installation & Usage
  2. Configuration
    1. Options
  3. API
  4. OAuth Implicit Grant Example

Installation & Usage

yarn add @allthings/sdk
const allthings = require('@allthings/sdk')

const client = allthings.restSdk({
  accessToken: '043dab7447450772example1214b552838003522',
})

client.getCurrentUser().then(viewer => 
  console.log(`Welcome back ${viewer.username}!`)
)

Configuration

Configuration Options

The available configuration options are outlined here:

OptionDefaultDescription
accessTokenAPI Access Token
clientIdOAuth 2.0 clientId
clientSecretOAuth 2.0 client secret
usernameUsername to use with OAuth 2.0 Password Grant authentication flow
passwordPassword to use with OAuth 2.0 Password Grant authentication flow
concurrencyNumber of concurrent requests to perform in parallel. Default behavior is burst of 30/s, 1/s thereafter

OAuth Implicit Grant Example

@TODO

const allthings = require('@allthings/sdk')

const client = allthings.restSdk({
  accessToken: '043dab7447450772example1214b552838003522',
})

client.getCurrentUser().then(viewer => 
  console.log(`Welcome back ${viewer.username}!`)
)

API

Allthings SDK module


restSdk(configurationOptions?): Client

Create an client instance of the SDK.

const allthings = require('@allthings/sdk')

const client = allthings.restSdk(configurationOptions)

client.createAgent()

Create a new agent. This is a convenience function around creating a user and adding that user to a property-manager's team.

const appId = '575027e58178f56a008b4568'
const propertyManagerId = '5a818c07ef5f2f00441146a2'
const username = 'mr.example@allthings.test'

const agent = await client.createAgent(
  appId,
  propertyManagerId,
  username,
  { email: 'mr.example@allthings.test', locale: 'en_US' }
)
export type MethodCreateAgent = (
  appId: string,
  propertyManagerId: string,
  username: string,
  data: PartialUser & {
    readonly email: string
    readonly locale: EnumLocale
  },
) => UserResult
// Describes the API wrapper's resulting interface
export interface InterfaceAllthingsRestApi {
  readonly delete: MethodHttpDelete
  readonly get: MethodHttpGet
  readonly post: MethodHttpPost
  readonly patch: MethodHttpPatch

  // Agent

  /**
   * Create a new agent. This is a convenience function around
   * creating a user and adding that user to a property-manager's team
   */
  readonly createAgent: MethodCreateAgent

  /**
   * Create agent permissions. This is a convenience function around
   * creating two user permission's: one "admin" and the other "pinboard"
   */
  readonly createAgentPermissions: MethodCreateAgentPermissions

  // App

  /**
   * Create a new App.
   */
  readonly createApp: MethodCreateApp

  // ID Lookup

  /**
   * Map one or more externalId's to API ObjectId's within the scope of a specified App
   */
  readonly createIdLookup: MethodCreateIdLookup

  // Group

  /**
   * Create a new group within a property
   */
  readonly createGroup: MethodCreateGroup

  /**
   * Get a group by it's ID
   */
  readonly getGroupById: MethodGetGroupById

  /**
   * Update a group by it's ID
   */
  readonly updateGroupById: MethodUpdateGroupById

  // Property

  /**
   * Create a new property
   */
  readonly createProperty: MethodCreateProperty

  /**
   * Get a property by it's ID
   */
  readonly getPropertyById: MethodGetPropertyById

  /**
   * Update a property by it's ID
   */
  readonly updatePropertyById: MethodUpdatePropertyById

  // Registration Code

  /**
   * Create a new registration code
   */
  readonly createRegistrationCode: MethodCreateRegistrationCode

  // Unit

  /**
   * Create a unit within a group
   */
  readonly createUnit: MethodCreateUnit

  /**
   * Get a unit by it's ID
   */
  readonly getUnitById: MethodGetUnitById

  /**
   * Update a unit by it's ID
   */
  readonly updateUnitById: MethodUpdateUnitById

  // User

  /**
   * Create a new User.
   */
  readonly createUser: MethodCreateUser

  /**
   * Give a user a permission/role on an given object of specified type
   */
  readonly createUserPermission: MethodCreateUserPermission

  /**
   * Delete a user a permission/role on an given object of specified type
   */
  readonly deleteUserPermission: MethodDeleteUserPermission

  /**
   * Get a list of users
   */
  readonly getUsers: MethodGetUsers

  /**
   * Get the current user from active session
   */
  readonly getCurrentUser: MethodGetCurrentUser

  /**
   * Get a user by their ID
   */
  readonly getUserById: MethodGetUserById

  /**
   * Get a list of user's permissions
   */
  readonly getUserPermissions: MethodGetUserPermissions

  /**
   * Update a user by their ID
   */
  readonly updateUserById: MethodUpdateUserById

  // Utilisation Period

  /**
   * Create a new utilisation period within a Unit
   */
  readonly createUtilisationPeriod: MethodCreateUtilisationPeriod

  /**
   * Get a utilisation period by it's ID
   */
  readonly getUtilisationPeriodById: MethodGetUtilisationPeriodById

  /**
   * Update a utilisation period by it's ID
   */
  readonly updateUtilisationPeriodById: MethodUpdateUtilisationPeriodById
}
0.1.0-8

6 years ago