0.9.3 • Published 1 year ago

@salesvista/client v0.9.3

Weekly downloads
8
License
Apache-2.0
Repository
github
Last release
1 year ago

@salesvista/client

Node.js SDK for the SalesVista REST API

CI Status Coverage Status JavaScript Style Guide Conventional Commits

The official Node.js SDK for the SalesVista REST API.

Install

$ npm i @salesvista/client

API

Quick Start

// use a singleton instance
const svClient = require('@salesvista/client')
// or construct your own instance
const { SVClient } = require('@salesvista/client')
const svClient = new SVClient()

// configure the instance
svClient.configure({
  id: process.env.SALESVISTA_CLIENT_ID,
  secret: process.env.SALESVISTA_CLIENT_SECRET,
  orgSecret: process.env.SALESVISTA_ORG_SECRET
})

// request some data
const reps = await svClient.reps.getSearchableReps()

// validate a webhook request
const signature = req.header('SalesVista-Signature')
const payload = req.body
const isValid = svClient.isValidSignature(signature, payload)

Auth token storage

Configure the client instance with your own cache strategy.

Here's an example using Redis:

const { SVClient, CacheStrategy } = require('@salesvista/client')
const Redis = require('ioredis')

class RedisCacheStrategy extends CacheStrategy {
  constructor () {
    super()
    this.redis = new Redis(
      process.env.REDIS_PORT || 6379,
      process.env.REDIS_HOST || 'localhost',
      { password: process.env.REDIS_PASSWORD || null }
    )
    this.tokenKey = 'sv_client_token'
  }

  async getToken () {
    const token = await this.redis.get(this.tokenKey)
    return token && JSON.parse(token)
  }

  async setToken (token) {
    if (token.expires_in > 180) {
      await this.redis.setex(this.tokenKey, token.expires_in - 120, JSON.stringify(token))
    }
  }
}

const svClient = new SVClient({
  id: process.env.SALESVISTA_CLIENT_ID,
  secret: process.env.SALESVISTA_CLIENT_SECRET,
  orgSecret: process.env.SALESVISTA_ORG_SECRET,
  cacheStrategy: new RedisCacheStrategy()
})

License

Apache 2.0 © SalesVista, LLC

0.9.3

1 year ago

0.9.3-rc1

1 year ago

0.9.2

1 year ago

0.9.1

1 year ago

0.9.0

2 years ago

0.8.0

3 years ago

0.8.0-rc4

3 years ago

0.8.0-rc2

3 years ago

0.8.0-rc3

3 years ago

0.8.0-rc1

3 years ago

0.7.0

3 years ago

0.6.0-rc1

4 years ago

0.7.0-rc1

3 years ago

0.6.0

3 years ago

0.5.0

4 years ago

0.5.0-rc2

4 years ago

0.5.0-rc1

4 years ago

0.5.0-rc3

4 years ago

0.4.1

4 years ago

0.4.0

5 years ago

0.3.0

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago