ssg-web-sdk
v1.4.8
Published
BEET Secure Service Gateway JavaScript SDK
Downloads
9
Readme
ssg.js - BEET Secure Service Gateway JavaScript SDK
Getting started
npm install --save git+ssh://[email protected]: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.ssg-url.com/v1',
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.ssg-url.com/v1',
adaptorDependencies: { request }
})
const email = '[email protected]'
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.ssg-url.com/v1',
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'
})
}
}