0.10.1 • Published 4 years ago

@cloudbeds/sdk-js v0.10.1

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

Cloudbeds Channel Manager SDK JS

Channel Manager Software Development Kit with a unified API that is mainly built around Myallocator PMS API

Channel Managers Public API

Installation

npm i @cloudbeds/sdk-js

Initialization

To communicate with MyAllocator you have to provide:

  • PMS Property Id in MA (the ma_pid)
  • PMS Vendor Id
  • MyAllocator User Token
  • A function that returns a promise which resolves to a MyAllocator Session Token

Example for client side:

import axios from 'axios';
import { MyAllocator } from '@cloudbeds/sdk-js';

async function getSessionToken() {
  // An example route that returns a session token
  const { data } = await axios.get('/create_myallocator_session_token');
  return data.sessionToken;
}

MyAllocator.init({
  credentials: {
    vendorId: 'hotel5star',
    userToken: '6zjgaFqdRoUeQ0aladBsxohWXCUNO5XmO7jxwKgq8c',
    propertyId: 42042,
  },
  getTokenFn: getSessionToken,
});

(async () => {
  const channelsList = await MyAllocator.getChannels(['air'], true);
})();

Session token

Purpose of a session token is to avoid exposing credentials like PMS vendor password

A session token must have a TTL (time-to-live) and should be requested by backend side (backend should implement requesting temporary tokens signed at MyAllocator)

Check MyAllocator API docs to find out what parameters are required for UserSessionCreate endpoint in order to create a session token

To create a session token signed at MyAllocator you have to provide:

  • PMS Vendor Id
  • PMS Vendor Password
  • MyAllocator User Token

Example of token creation on server side (Node.js):

const PMS_VENDOR_ID = 'hotel5star';
const PMS_VENDOR_PASSWORD = 'secret';
const MY_ALLOCATOR_USER_TOKEN = '6zjgaFqdRoUeQ0aladBsxohWXCUNO5XmO7jxwKgq8c';

async function createMyAllocatorSessionToken() {
  const response = await fetch('https://api.myallocator.com/pms/v201903/json/UserSessionCreate', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        'Auth/VendorId': PMS_VENDOR_ID,
        'Auth/VendorPassword': PMS_VENDOR_PASSWORD,
        'Auth/UserToken': MY_ALLOCATOR_USER_TOKEN,
    }),
  }); 
  const json = await response.json();
  return json.SessionToken;
}

Bundling

To make a bundle that can be required in a web app execute npm run bundle To perform tests and push a new release execute npm run publish:[patch|minor|major]

Testing

In order to start unit tests code should be transpiled from TypeScript

npm run compile
npm test

To continuously compile and execute tests run npm start (compile and watch for changes) and npm test in separate terminals

Sandbox

To test functions of this library manually, with arbitrary arguments, make a bundle by running npm run bundle and serve sandbox.html

To continuously compile and bundle run npm run bundle:watch (compile, bundle and watch for changes). In that case it is possible to simultaneously execute unit tests by running npm test:watch and also have fresh bundle in the sandbox page

0.10.1

4 years ago

0.10.0

4 years ago

0.9.23

4 years ago

0.9.22

4 years ago

0.9.21

4 years ago

0.9.20

4 years ago

0.9.18

4 years ago

0.9.17

4 years ago

0.9.16

4 years ago

0.9.14

4 years ago

0.9.13

4 years ago

0.9.12

4 years ago

0.9.11

4 years ago

0.9.10

4 years ago

0.9.9

4 years ago

0.9.8

4 years ago

0.9.7

4 years ago

0.9.6

5 years ago

0.9.5

5 years ago

0.9.4

5 years ago

0.9.3

5 years ago

0.9.2

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.12

5 years ago

0.8.11

5 years ago

0.8.10

5 years ago

0.8.9

5 years ago

0.8.8

5 years ago

0.8.7

5 years ago

0.8.6

5 years ago

0.8.5

5 years ago

0.8.4

5 years ago

0.8.3

5 years ago

0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.9

5 years ago

0.7.8

5 years ago

0.7.7

5 years ago

0.7.6

5 years ago

0.7.5

5 years ago

0.7.4

5 years ago

0.7.3

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.8

5 years ago

0.6.7

5 years ago

0.6.6

5 years ago

0.6.5

5 years ago

0.6.4

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.7

5 years ago

0.0.5

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago