ssg-web-sdk

1.4.8 • Public • Published

ssg.js - BEET Secure Service Gateway JavaScript SDK

Getting started

  • npm install --save git+ssh://git@github.com:beetsolutions/ssg-web-sdk.git
  • see usage examples below

Run examples

  • npm install
  • npm run build
  • npm start
  • navigate to http://localhost:3000

This is a CommonJS module so you need a module loader solution such as SystemJS, Browserify, or Webpack to use it in a browser.

Plain JavaScript, using fetch() for requests:

var Ssg = require('../ssg-js-sdk').Ssg

var ssg = new Ssg({
  adaptor: 'fetch',
  baseUrl: 'http://www.beet-ssg.com',
  configStorageType: 'sessionStorage'
})

function login (email, password, tenantId) {
  ssg.auth.loginAdmin(email, password, tenantId)
}

function logout () {
  ssg.auth.logoutAdmin()
}

function exampleRequest () {
  return ssg.http.request({
    urlExtension: '/v1/user',
    method: 'GET'
  })
}

Node, using "request" module for requests

NOTE: Node support is disabled until forge is proper modules https://github.com/digitalbazaar/forge/pull/357

const SSG = require('../../ssg').Ssg
const request = require('request')

let ssg = new SSG({
  adaptor: 'node-request',
  environment: 'node',
  baseUrl: 'http://www.beet-ssg.com',
  adaptorDependencies: { request }
})

const email = 'someuser@unwire.dk'
const password = 'secretpassword'
const tenantId = 1000

ssg.auth.loginAdmin(email, password, tenantId)
  .then(auth => {
    ssg.http.request({
      urlExtension: '/v1/user',
      method: 'GET'
    }, (err, res) => {
      if (err) {
        console.log(err)
      }
      console.log(res.body)
    })
  })

Angular 2

import {Ssg} from 'ssg-secure-service-gateway-js-sdk/ssg'
import {Injectable} from '@angular/core'
import {Http, Request} from '@angular/http'

@Injectable()
export class ApiService {
  public ssg
  constructor (http:Http) {
    this.ssg = new Ssg({
      adaptor: 'angular2',
      baseUrl: 'http://www.beet-ssg.com',
      configStorageType: 'sessionStorage',
      adaptorDependencies: {
        http,
        Request
      }
    })
  }

  login (email, password, tenantId) {
    return this.ssg.auth.loginAdmin(email, password, tenantId)
  }

  logout () {
    return this.ssg.auth.logoutAdmin()
  }

  exampleRequest () {
    return this.ssg.http.request({
      urlExtension: '/v1/user',
      method: 'GET'
    })
  }
}

React

import {Ssg} from 'ssg-secure-service-gateway-js-sdk/ssg'
import {Injectable} from '@angular/core'
import {Http, Request} from '@angular/http'

@Injectable()
export class ApiService {
  public ssg
  constructor (http:Http) {
    this.ssg = new Ssg({
      adaptor: 'react',
      baseUrl: 'http://www.beet-ssg.com',
      configStorageType: 'sessionStorage',
      adaptorDependencies: {
        http,
        Request
      }
    })
  }

  login (email, password, tenantId) {
    return this.ssg.auth.loginAdmin(email, password, tenantId)
  }

  logout () {
    return this.ssg.auth.logoutAdmin()
  }

  exampleRequest () {
    return this.ssg.http.request({
      urlExtension: '/v1/user',
      method: 'GET'
    })
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i ssg-web-sdk

Weekly Downloads

0

Version

1.4.8

License

ISC

Unpacked Size

432 kB

Total Files

78

Last publish

Collaborators

  • beetsolutions