no jibo cloud calls via JIBO_BYPASS_PORTAL
This commit is contained in:
39
node_modules/@jibo/apptoolkit-library/lib/Account.js
generated
vendored
39
node_modules/@jibo/apptoolkit-library/lib/Account.js
generated
vendored
@@ -3,6 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const axios_1 = require("axios");
|
||||
const constants_1 = require("./constants");
|
||||
const Robot_1 = require("./Robot");
|
||||
function isBypassEnabled() {
|
||||
const raw = process.env.JIBO_BYPASS_PORTAL || "";
|
||||
return raw === "1" || raw.toLowerCase() === "true";
|
||||
}
|
||||
function getOfflineSerials() {
|
||||
const raw = process.env.JIBO_OFFLINE_SERIALS || process.env.JIBO_OFFLINE_SERIAL || "";
|
||||
const serials = raw.split(",").map(s => s.trim()).filter(Boolean);
|
||||
return serials.length ? serials : ["offline-jibo"];
|
||||
}
|
||||
function buildOfflineConnectionConfig() {
|
||||
return {
|
||||
ip: process.env.JIBO_OFFLINE_IP,
|
||||
certPath: process.env.JIBO_OFFLINE_CERT_PATH,
|
||||
certPem: process.env.JIBO_OFFLINE_CERT_PEM,
|
||||
keyPath: process.env.JIBO_OFFLINE_KEY_PATH,
|
||||
keyPem: process.env.JIBO_OFFLINE_KEY_PEM,
|
||||
fingerprint: process.env.JIBO_OFFLINE_FINGERPRINT,
|
||||
skipTls: process.env.JIBO_OFFLINE_SKIP_TLS === '1' || process.env.JIBO_OFFLINE_SKIP_TLS === 'true',
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @description A reference to a Jibo account. Log in here to get an API handle
|
||||
* to a Jibo robot or robots.
|
||||
@@ -21,6 +41,12 @@ class Account {
|
||||
* @method Account#login
|
||||
*/
|
||||
async login() {
|
||||
if (isBypassEnabled()) {
|
||||
console.log("[JIBO_BYPASS] login(): bypassing portal.jibo.com token request");
|
||||
this._accessToken = process.env.JIBO_OFFLINE_ACCESS_TOKEN || "offline-token";
|
||||
this._tokenType = process.env.JIBO_OFFLINE_TOKEN_TYPE || "Bearer";
|
||||
return;
|
||||
}
|
||||
if (this._accessToken) {
|
||||
this.logout();
|
||||
}
|
||||
@@ -43,6 +69,19 @@ class Account {
|
||||
* @returns {Promise<Robot[]>}
|
||||
*/
|
||||
async getRobots() {
|
||||
if (isBypassEnabled()) {
|
||||
console.log("[JIBO_BYPASS] getRobots(): returning offline robot handles");
|
||||
const tokenType = this._tokenType || process.env.JIBO_OFFLINE_TOKEN_TYPE || "Bearer";
|
||||
const accessToken = this._accessToken || process.env.JIBO_OFFLINE_ACCESS_TOKEN || "offline-token";
|
||||
const config = buildOfflineConnectionConfig();
|
||||
return getOfflineSerials().map(serial => {
|
||||
const robot = new Robot_1.Robot(serial, tokenType, accessToken);
|
||||
if (typeof robot.configureDirectConnection === "function") {
|
||||
robot.configureDirectConnection(config);
|
||||
}
|
||||
return robot;
|
||||
});
|
||||
}
|
||||
if (!this._accessToken) {
|
||||
throw new Error('Not logged in');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user