@revas/ts-api

0.0.45-temp • Public • Published

Revas Platform API Typescript Client

Installation

yarn add @revas/platform-api

Usage

import Revas from '@revas/platform-api'

// Simple client instance with token and organizationId configured
const revas = new Revas.Client({
  accessToken: 'JWT_TOKEN_FROM_AUTHENTICATION',
  organizationId: 'REVAS_ORGANIZATION_ID'
})

// Revas can be also configured with simple getter functions
const revas = new Revas.Client({
  accessToken: () => {
    return 'JWT_TOKEN_FROM_AUTHENTICATION'
  },
  organizationId: () => {
    return 'REVAS_ORGANIZATION_ID'
  }
})

const request = ...
const response = revas.Contact.GetContact(request)

// The options are overrideable for each request but won't change client config
const response = revas.Contact.GetContact(request, {
  organizationId: 'REVAS_ORGANIZATION_ID'
})

Public API

// The public calls require the client with the public key
const revas = new Revas.Client({
  publicKey: 'REVAS_PUBLIC_KEY'
})
revas.Content.GetPublicDirectory(request)
revas.Content.ListPublicContents(request)
revas.Content.GetPublicContent(request)

Error Management

try {
  const response = revas.Contact.GetContact(request, {
    organizationId: 'REVAS_ORGANIZATION_ID'
  })
} catch (e: RevasError) {
  // for everything more than 200
}

Change global options

const revas = new Revas.Client({
  accessToken: 'JWT_TOKEN_FROM_AUTHENTICATION',
  organizationId: 'REVAS_ORGANIZATION_ID'
})

revas.setGlobalOptions({
  organizationId: 'ANOTHER_REVAS_ORGANIZATION_ID'
})

Example in Revas app

// eg. with auth0 and organization store
const auth0Client = ...
const revasClient = new Revas.Client({
  accessToken: () => {
    return auth0Client.getTokenSilently()
  }
})
const organizationStore = new ...(revasClient, ...)
revasClient.setGlobalOptions({
  organizationId: () => {
    return organizationStore.getOrganization().id
  }
})
revasClient.setGlobalOptions({
  organizationId: organizationStore.getOrganization().id
})

Readme

Keywords

none

Package Sidebar

Install

npm i @revas/ts-api

Weekly Downloads

1

Version

0.0.45-temp

License

MIT

Unpacked Size

72.5 kB

Total Files

31

Last publish

Collaborators

  • sbaita
  • ngardoni
  • lykkechen
  • hashbardd