@bearer/js
A JavaScript library for working with Bearer integrations
Last updated 8 months ago by antoine.apizi .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @bearer/js 
SYNC missed versions from official npm registry.

@bearer/js

Version npm bundle size (scoped) Downloads/week NPM

The hassle-free way to use bearer's integrations into any web application

Getting started

Bearer lib can be used instantly in your page or with a package system.

Directly in your page

<script src="https://cdn.jsdelivr.net/npm/@bearer/js@latest/lib/bearer.production.min.js"></script>
<script>
  // you have now access to a global `bearer` function,
  // initialize your code by passing your `PUBLISHABLE_KEY` as parameter (you'll find it at https://app.bearer.sh/keys)
  const bearerClient = bearer('BEARER_PUBLISHABLE_KEY')
</script>

With a build system

yarn add @bearer/js
# or
npm install @bearer/js

In your app

import bearer from '@bearer/js'

class MyApp {
  componentDidMount() {
    bearer('BEARER_PUBLISHABLE_KEY')
  }
}

Usage

Calling any APIs

Out of the box, Bearer provides an added value proxy for any API. You can call any API (aka integration) endpoint as follow

const bearerClient = bearer('BEARER_PUBLISHABLE_KEY')

// initialize an API client to target a specific service (ex: slack, github, etc...)
const slack = bearerClient.integration('INTEGRATION_ID')

// re-use previously created API client
slack
  .auth(authId) // see #connect section for more information
  .get('/reminders.list') // all REST verbs are available here: .post, .put, .delete etc...
  .then(console.log)
  .catch(console.error)

// passing extra arguments
slack
  .auth(authId)
  .post('/reminders.add', { text: 'Remind me something', time: 'in 10 seconds' })
  .then(console.log)
  .catch(console.error)

Invoke js

The Bearer SDK for JavaScript lets you invoke integration's function (if their execution is not restricted to server side usage).

const bearerClient = bearer('BEARER_PUBLISHABLE_KEY')

const myIntegration = bearerClient.integration('INTEGRATION_ID')
myIntegration
  .invoke('myFunction')
  .then(console.log)
  .catch(console.error)

// is equivalent to
bearerClient
  .invoke('INTEGRATION_ID', 'myFunction')
  .then(console.log)
  .catch(console.error)

Passing params to your function works as follow:

bearerClient
  .invoke('INTEGRATION_ID', 'myFunction', {
    query: { foo: 'bar' }
  })
  .then(console.log)
  .catch(console.error)

i18n

@bearer/js comes with an i18n module that let you deal with internationalization of Bearer's integrations

bearer.i18n.locale

Lets you change the locale

bearer.i18n.locale = 'es'

bearer.i18n.load

Lets you load custom translation for integrations

// with a simple dictionnary
const dictionnary = { titles: { welcome: 'Ola!' } }
bearer.i18n.load('integration-uuid', dictionnary)

// with a promise returning a dictionnary
const promiseReturningADictionnary = Promise.new((resolve, reject) => {
  // async stuff
  resolve({ titles: { welcome: 'Ola!' } })
})
bearer.i18n.load('integration-uuid', promiseReturningADictionnary)

// for a given locale
const dictionnary = { titles: { welcome: 'Guten Morgen' } }
bearer.i18n.load('integration-uuid', dictionnary, { locale: 'de' })

// for multiple integrations on a single page
const dictionnary = {
  ['integration-one-uuid']: { title: { welcome: 'Hello my friend' } },
  ['integration-two-uuid']: { message: { goodbye: 'Bye Bye' } }
}
bearer.i18n.load(null, dictionnary)

Secure

If you want to add a level of security, you can switch to the secure mode:

window.bearer.secured = true
// at the initialisation time
window.bearer('clientId', { secured: true })

Once this mode is turned on, all your values passed in the properties need to be encrypted using your ENCRYPTION_KEY.

CLI

Within the CLI, you can use bearer encrypt to get the

bearer encrypt ENCRYPTION_KEY MESSAGE

NodeJS

import Cipher from '@bearer/security'

const cipher = new Cipher(ENCRYPTION_KEY)
cipher.encrypt(MESSAGE)

connect

connect lets you easily retrieve the auth-id for an integration using OAuth authentication. Before using it, you'll need to generate a setup-id with the setup component of your integration

bearerClient
  .connect('integration-uuid', 'setup-id')
  .then(data => {
    // user has connected himself to the OAuth provider and you now have access to the authId
    console.log(data.authId)
  })
  .catch(() => {
    // user canceled the authentication
  })

you can pass your own auth-id within options parameters as follows

bearerClient.connect('integration-uuid', 'setup-id', { authId: 'my-own-non-guessable-auth-id' })

init options

Soon

Current Tags

  • 0.96.1                                ...           beta5 (a year ago)
  • 0.105.0                                ...           beta6 (a year ago)
  • 0.113.0                                ...           buid (a year ago)
  • 1.7.1-canary.2                                ...           canary (10 months ago)
  • 1.13.10                                ...           latest (8 months ago)
  • 2.2.2                                ...           next (6 months ago)
  • 0.115.1                                ...           rc (a year ago)
  • 2.1.0                                ...           test (7 months ago)

105 Versions

  • 2.2.2                                ...           6 months ago
  • 2.1.0                                ...           7 months ago
  • 2.0.0                                ...           8 months ago
  • 1.13.10                                ...           8 months ago
  • 1.13.9                                ...           8 months ago
  • 1.13.8                                ...           8 months ago
  • 1.13.5                                ...           8 months ago
  • 1.13.4                                ...           8 months ago
  • 1.9.0                                ...           10 months ago
  • 1.8.0                                ...           10 months ago
  • 1.7.1-canary.2                                ...           10 months ago
  • 1.8.0-canary.2                                ...           10 months ago
  • 1.7.0                                ...           10 months ago
  • 1.6.8                                ...           a year ago
  • 1.6.5                                ...           a year ago
  • 1.6.4                                ...           a year ago
  • 1.6.2-canary-4.1                                ...           a year ago
  • 1.6.1                                ...           a year ago
  • 1.4.2-canary.17 [deprecated]           ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
  • 0.115.1 [deprecated]           ...           a year ago
  • 0.115.0 [deprecated]           ...           a year ago
  • 0.114.1 [deprecated]           ...           a year ago
  • 0.113.0 [deprecated]           ...           a year ago
  • 0.112.0 [deprecated]           ...           a year ago
  • 0.111.0-canary2.13 [deprecated]           ...           a year ago
  • 0.111.0-canary.13 [deprecated]           ...           a year ago
  • 0.111.0-canary.9 [deprecated]           ...           a year ago
  • 0.111.0 [deprecated]           ...           a year ago
  • 0.111.0-canary.2 [deprecated]           ...           a year ago
  • 0.110.0 [deprecated]           ...           a year ago
  • 0.109.0 [deprecated]           ...           a year ago
  • 0.108.0 [deprecated]           ...           a year ago
  • 0.107.3 [deprecated]           ...           a year ago
  • 0.108.0-canary-x-ray.10 [deprecated]           ...           a year ago
  • 0.108.0-canary-xray.16 [deprecated]           ...           a year ago
  • 0.107.0-canary-xray.8 [deprecated]           ...           a year ago
  • 0.107.0-canary-tarik.8 [deprecated]           ...           a year ago
  • 0.107.0-canary-tarik.7 [deprecated]           ...           a year ago
  • 0.107.0 [deprecated]           ...           a year ago
  • 0.107.0-canary-tarik.6 [deprecated]           ...           a year ago
  • 0.107.0-canary-tarik.5 [deprecated]           ...           a year ago
  • 0.107.0-canary-tarik.3 [deprecated]           ...           a year ago
  • 0.107.0-canary-tarik.2 [deprecated]           ...           a year ago
  • 0.107.0-canary-tarik.1 [deprecated]           ...           a year ago
  • 0.107.0-canary.1 [deprecated]           ...           a year ago
  • 0.107.0-canary.0 [deprecated]           ...           a year ago
  • 0.100.1-canary.102 [deprecated]           ...           a year ago
  • 0.107.0-canary.6 [deprecated]           ...           a year ago
  • 0.106.0 [deprecated]           ...           a year ago
  • 0.106.0-canary.15 [deprecated]           ...           a year ago
  • 0.106.0-canary.14 [deprecated]           ...           a year ago
  • 0.106.0-canary.13 [deprecated]           ...           a year ago
  • 0.106.0-canary.9 [deprecated]           ...           a year ago
  • 0.106.0-canary.5 [deprecated]           ...           a year ago
  • 0.106.0-canary.1 [deprecated]           ...           a year ago
  • 0.105.0 [deprecated]           ...           a year ago
  • 0.104.0 [deprecated]           ...           a year ago
  • 0.103.0 [deprecated]           ...           a year ago
  • 0.102.0 [deprecated]           ...           a year ago
  • 0.100.1-canary.53 [deprecated]           ...           a year ago
  • 0.100.1-canary.51 [deprecated]           ...           a year ago
  • 0.101.1 [deprecated]           ...           a year ago
  • 0.101.0 [deprecated]           ...           a year ago
  • 0.101.0-canary.43 [deprecated]           ...           a year ago
  • 0.100.1-canary.40 [deprecated]           ...           a year ago
  • 0.100.1-canary.39 [deprecated]           ...           a year ago
  • 0.100.1-canary.34 [deprecated]           ...           a year ago
  • 0.100.1-next.40 [deprecated]           ...           a year ago
  • 0.100.1-canary.36 [deprecated]           ...           a year ago
  • 0.100.1-next.35 [deprecated]           ...           a year ago
  • 0.92.1-canary.148 [deprecated]           ...           a year ago
  • 0.100.1-canary.31 [deprecated]           ...           a year ago
  • 0.100.1-next.48 [deprecated]           ...           a year ago
  • 0.100.1-next.47 [deprecated]           ...           a year ago
  • 0.92.1-canary.143 [deprecated]           ...           a year ago
  • 0.92.1-canary.142 [deprecated]           ...           a year ago
  • 0.100.1-canary.25 [deprecated]           ...           a year ago
  • 0.92.1-canary.138 [deprecated]           ...           a year ago
  • 0.92.1-canary.137 [deprecated]           ...           a year ago
  • 0.100.1-next.27 [deprecated]           ...           a year ago
  • 0.92.1-canary.136 [deprecated]           ...           a year ago
  • 0.92.1-canary.135 [deprecated]           ...           a year ago
  • 0.100.1-next.25 [deprecated]           ...           a year ago
  • 0.92.1-canary.134 [deprecated]           ...           a year ago
  • 0.100.1-next.21 [deprecated]           ...           a year ago
  • 0.100.1-next.23 [deprecated]           ...           a year ago
  • 0.100.1-next.17 [deprecated]           ...           a year ago
  • 0.100.1-next.15 [deprecated]           ...           a year ago
  • 0.100.1-next.1 [deprecated]           ...           a year ago
  • 0.100.0 [deprecated]           ...           a year ago
  • 0.99.2 [deprecated]           ...           a year ago
  • 0.99.1 [deprecated]           ...           a year ago
  • 0.99.0 [deprecated]           ...           a year ago
  • 0.98.0 [deprecated]           ...           a year ago
  • 0.97.3 [deprecated]           ...           a year ago
  • 0.97.2 [deprecated]           ...           a year ago
  • 0.97.0 [deprecated]           ...           a year ago
  • 0.96.2-next.13 [deprecated]           ...           a year ago
  • 0.96.1 [deprecated]           ...           a year ago
  • 0.96.0 [deprecated]           ...           a year ago
  • 0.0.2 [deprecated]           ...           a year ago
  • 0.0.1 [deprecated]           ...           a year ago
Downloads
Today 0
This Week 0
This Month 105
Last Day 0
Last Week 105
Last Month 0
Dependencies (6)

Copyright 2014 - 2016 © taobao.org |