3.1.1 • Published 10 months ago

bima-shark-sdk v3.1.1

Weekly downloads
26
License
MIT
Repository
github
Last release
10 months ago

bima-shark-sdk (Javascript)

This is the Javascript SDK for the BImA applications.

Build Status

Installation

1) Install the npm package

npm install bima-shark-sdk

2) Bring your own fetch library.

3) In browser you have to use babel-loader to support IE 11 and project-wide babel.config.js. A .babelrc configuration is not enough and will ignore node_modules.

  // webpack.config.js
    module: {
      rules: [
        {
          test: /\.js$/,
          include: [
            path.resolve(__dirname, 'src'),
            path.resolve(__dirname, 'node_modules/bima-shark-sdk')
          ],
          use: {
            loader: 'babel-loader'
          }
        },
        ...

Usage

In browser

import Shark from 'bima-shark-sdk'

Shark.configure({
  debug: false,             // log request and response, when true
  secret: 'random-id',      // user specific secret e.g. id
  serviceTokenUrl: '/doorkeeper/service_token'
})

import { UserClient } from 'bima-shark-sdk'

const client = new UserClient('https://doorkeeper-development.bundesimmo.de')
client.find(123)
  .then(
    json => { console.log('Success: ', json) },
    err => { console.log('Error: ', err) }
  ).finally(
    () => { console.log('Hide loader') }
  )

In Node.js

const { MailingClient } = require('bima-shark-sdk')

const client = new MailingClient('https://mailing-development.bundesimmo.de', {
  serviceToken: {
    baseUrl: 'https://doorkeeper-development.bundesimmo.de',
    accessKey: 'your-access-key',
    secretKey: 'your-secret-key',
    userId: '1234567890'  // optional
  }
})

try {
  const json = await client.create({ foo: 'bar' })
  console.log('Success: ', json)
} catch (err) {
  console.log('Error: ', err)
}

Additionally, you can use your own function to generate authentication tokens:

const { MailingClient } = require('bima-shark-sdk')

const client = new MailingClient('https://mailing-development.bundesimmo.de', {
  getAuthToken: () => 'Bearer ' + crypto.randomBytes(20).toString('hex')
})

or generate JWT-based short-lived tokens which are valid for 1 minute:

const { MailingClient, jwtAuthorization } = require('bima-shark-sdk')

const client = new MailingClient('https://mailing-development.bundesimmo.de', {
  getAuthToken: () => {
    const accessId = 'mailingservice'
    const secretKey = 'ZT...=='

    return jwtAuthorization({ accessId, secretKey })
  }
})

Testing

This SDK uses jest as test framework. Server responses are mocked with nock.

npm ci
npm test

Links for further reading

3.1.1

10 months ago

3.1.0

10 months ago

3.0.0

1 year ago

2.14.0

2 years ago

2.13.0

3 years ago

2.13.1

3 years ago

2.12.1

4 years ago

2.12.0

4 years ago

2.11.0

5 years ago

2.10.0

5 years ago

2.9.0

5 years ago

2.8.0

5 years ago

2.7.1

6 years ago

2.7.0

6 years ago

2.6.0

6 years ago

2.5.0

6 years ago

2.4.0

6 years ago

2.3.0

6 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.15.0

7 years ago

0.15.0-pre2

7 years ago

0.15.0-pre1

7 years ago

0.14.0

7 years ago

0.13.1

7 years ago

0.13.0

7 years ago

0.12.0

7 years ago

0.11.1

7 years ago

0.11.0

7 years ago

0.10.0

7 years ago

0.9.0

7 years ago

0.8.0

7 years ago

0.7.0

7 years ago

0.7.0-pre5

7 years ago

0.7.0-pre4

7 years ago

0.7.0-pre2

7 years ago

0.7.0-pre

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago