Splyt Partner SDK
Last updated 2 years ago by rainder .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @splytech-io/splyt-partner-sdk 
SYNC missed versions from official npm registry.

Splyt Partner SDK

Partner wrapper over @splytech-io/splyt-ws-connection module


  • Node >= v6.0.0


$ npm install @splytech-io/splyt-partner-sdk

SplytPartnerSDK Class API

constructor(serverUrl: String, credentials: Object)

Creates an instance of SplytPartnerSDK, connects and signs in the partner. In case if connection is dropped SDK reconnects and relogins into Splyt automatically.

.request(method: String, data: Object): Promise

Sends a request message to the Splyt Backend and waits for the response. Once response is received a returned promise is resolved or rejected depending on a response message from the server.

Note: promise might be rejected if SDK fails to deliver a message to the backend.

const data = {
  login: 'username',
  password: 'password'

partner.request('partner.sign-in', data)
	.then(() => /* handle sucessfull response */)
	.catch((err) => /* handle erroneous response */);

.push(method: String, data: Object): Promise

Sends a push message to the Splyt Backend. Function returns a Promise which is resolved if message is delivered to the server.

.on(eventName: String, callbackFunction: Function): SplytPartnerSDK

All events are implemented using @rainder/co-event-emitter library. Only one event subscriber is allowed. It accepts GeneratorFunctions, Promises and Thunks as callback functions.

partner.on('event-name', callbackFunction);

Every request or push message from Splyt Backend to the SDK is converted into event where endpoint method name is used as event name. You can subscribe to specific method calls as following:

//example of GeneratorFunction usage as a callbackFunction
partner.on('endpoint-method-name', function *(data) {
  //handle request and send response
  return { response_data: 'some-data' };

If SDK receives a message to which you have not subscribed, SDK outputs a warning to the terminal.

Implementation example

const SplytPartnerSDK = require('@splytech-io/splyt-partner-sdk');

const partner = new SplytPartnerSDK.Client('wss://wsapi.sandbox.splytech.io', {
  login: 'username',
  password: 'password',

//ie using resolved Promise
partner.on('partner.journey.estimate', (data) => {
  //returns an estimate price of the journey
  return Promise.resolve({
    price_range: {
      lower: 1234,
      upper: 1566,

//ie using generator function
partner.on('partner.new-trip-request', function *(data) {
  if (data.passenger_groups[0].pickup.address === '83 Baker Street') {
    //sends an erroneous response to the Splyt Backend
    throw new SplytPartnerSDK.Error.BAD_REQUEST('invalid pickup address');
  //make asynchronous calls
  const result = yield someExternalHttpCall(data);
  //sends successful response message to the server
  return { someData: result.data };

Current Tags

  • 0.1.4                                ...           latest (2 years ago)

4 Versions

  • 0.1.4                                ...           2 years ago
  • 0.1.3                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
Maintainers (2)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 17
Dependencies (5)
Dev Dependencies (1)
Dependents (0)

Copyright 2014 - 2016 © taobao.org |