@cloudbeds/sdk-js v0.10.1
Cloudbeds Channel Manager SDK JS
Channel Manager Software Development Kit with a unified API that is mainly built around Myallocator PMS 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
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago