Skip to content

byjutech/identity-node-sdk

Repository files navigation

identity-node-sdk

Node.js client library for using Identity service.

Getting started

Installation

This library is not distributed on npm registry. It is available on github packages published here In order to add it as a dependency,

Add .npmrc in the root of your project

@byjutech:registry=https://npm.pkg.github.com

Then run the following command:

npm install @byjutech/identity-js --save

Examples

import { identity } from '@byjutech/identity-js'

const idOpts = {
  serviceBaseUrl: 'https://identity-staging.tllms.com',
  oauth2: {
    client: {
      id: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
      secret: 'xxx-xxx-xxx'
    },
    auth: {
      tokenHost: 'https://hydra-auth-staging.tllms.com',
      tokenPath: '/oauth2/token',
      revokePath: '/oauth2/revoke',
      authorizePath: '/oauth2/auth'
    },
    // http: { } // wreck options
  },
  scope: 'openid offline identities.read identities.create accounts.read accounts.create accounts.patch premiumaccounts.read'
}

Find identity

const service = identity(idOpts)
const query = "+xx-xxxxxxxxxx"

const result = await service.find(query)

Get identity

const service = identity(idOpts)
const identityId = "xxxx-xxxxxxxxxx-xxxxxxx-xxxx"

const result = await service.get(query)

Create identity

const service = identity(idOpts)
const request = {
  phone: "+xx-xxxxxxxxxx",
  accounts: [ // Optional
    {
      first_name: "Bruce",
      last_name: "Wayne"
    }
  ]
}

const createRes = await service.create(request)

Add account to identity

const service = identity(idOpts)
const request = {
  first_name: "Jason",
  last_name: "Todd",
  premium_account_id: "acc_123"
}

const createRes = await service.accounts.add(identity_id, request)

Get account details

const service = identity(idOpts)

const createRes = await service.accounts.get(account_id)

Update account details as a patch request

const service = identity(idOpts)
const request = {
  current_grade: "8",
  first_name: "Jason",
  last_name: "Todd",
  nickname: "Todd",
  premium_account_id: "acc_123"
}
const createRes = await service.accounts.patch(account_id, request)

Get premium account details

const service = identity(idOpts)

const createRes = await service.premiumAccounts.get(premium_account_id)