Have ideas to improve npm?Join in the discussion! »

@bearer/node
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

@bearer/node

Version npm bundle size (scoped) node (scoped) Downloads/week NPM

Node client to query any APIs and custom functions using Bearer.sh

Usage

Get your Bearer's credentials and setup Bearer as follow:

Calling any APIs

const bearer = require('@bearer/node')
// or
// import bearer from '@bearer/node'
 
const client = bearer(process.env.BEARER_SECRET_KEY) // find it on https://app.bearer.sh/keys
const github = client.integration('INTEGRATION_ID') // you'll find it on the Bearer's dashboard
 
github
  .get('/repositories')
  .then(console.log)
  .catch(console.error)

More advanced examples:

// With query parameters
github
  .get('/repositories', { query: { since: 364 } })
  .then(console.log)
  .catch(console.error)
 
// Making an authenticated POST
github
  .auth(authId) // Create an authId for GitHub on https://app.bearer.sh
  .post('/user/repos', { body: { name: 'Just setting up my Bearer.sh' } })
  .then(console.log)
  .catch(console.error)

Using async/await:

const response = await github
  .auth(authId) // Create an authId for GitHub on https://app.bearer.sh
  .post('/user/repos', { body: { name: 'Just setting up my Bearer.sh' } })
 
console.log(response)

Setting the request timeout

By default bearer client times out after 5 seconds. Bearer allows to increase the timeout to up to 30 seconds

const bearer = require('@bearer/node')
// or
// import bearer from '@bearer/node'
 
const client = bearer(process.env.BEARER_SECRET_KEY, { httpClientSettings: { timeout: 10 * 1000 } }) // sets the timeout to 10 seconds
const github = client.integration('INTEGRATION_ID', { httpClientSettings: { timeout: 1 } }) // sets the timeout to 1 second for this specific integration
 
github
  .invoke('myFunction')
  .then(console.log)
  .catch(console.error)

Learn more on how to use custom functions with Bearer.sh.

Notes

Note 1: we are using axios as the http client. Each .get(), .post(), .put(), ... or .invoke() returns an Axios Promise.

Note 2: If you are using ExpressJS, have a look at the @bearer/express client

Install

npm i @bearer/node

DownloadsWeekly Downloads

271

Version

2.2.0

License

MIT

Unpacked Size

34.4 kB

Total Files

10

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar