c8osdkjs
Version:
convertigo's MBaaS client API service
146 lines • 6.47 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var index_1 = require("axios/index");
var c8osdkjscore_1 = require("c8osdkjscore");
var Observable_1 = require("rxjs/Observable");
var c8oHttpInterface_service_1 = require("./c8oHttpInterface.service");
var C8o = (function (_super) {
__extends(C8o, _super);
function C8o() {
var _this = _super.call(this) || this;
_this._http = index_1.default;
_this.data = null;
_this.c8oLogger = new c8osdkjscore_1.C8oLogger(_this, true);
return _this;
}
Object.defineProperty(C8o.prototype, "sdkVersion", {
get: function () {
return require("../../package.json").version;
},
enumerable: true,
configurable: true
});
C8o.prototype.init = function (c8oSettings) {
var _this = this;
var nullableEndpoint = true;
if (c8oSettings !== undefined) {
if (c8oSettings.endpoint != null) {
nullableEndpoint = false;
}
}
if (nullableEndpoint) {
this.promiseConstructor = new Promise(function (resolve) {
if (window.location.href.indexOf("http") === 0 && window.location.href.indexOf("/DisplayObjects") !== -1) {
var n = window.location.href.indexOf("/DisplayObjects");
_this.endpoint = window.location.href.substring(0, n);
resolve();
}
else {
var uri = "";
if (window.location.href.indexOf("file://") === 0) {
uri = (window.location.href.substring(0, window.location.href.indexOf("/index.html"))) + "/env.json";
}
else {
uri = window.location.origin + "/env.json";
}
_this.httpPublic.get(uri)
.then(function (data) {
_this.data = data;
var remoteBase = data["remoteBase"].toString();
var n = remoteBase.indexOf("/_private");
_this.endpoint = remoteBase.substring(0, n);
_this._automaticRemoveSplashsCreen = data["splashScreenRemoveMode"] !== "manual";
resolve();
}).catch(function (error) {
alert("Missing env.json file");
var errMsg;
if (error instanceof Error) {
errMsg = error.message;
}
else {
errMsg = error.status + " - " + (error.statusText || "") + " " + error;
}
return Observable_1.Observable.throw(errMsg);
});
}
}).then(function () {
_this.extractendpoint();
});
}
else {
this.promiseConstructor = new Promise(function (resolve) {
_this.endpoint = c8oSettings.endpoint;
_this.extractendpoint();
resolve();
});
}
this.promiseInit = Promise.all([this.promiseConstructor]).then(function () {
return new Promise(function (resolve) {
_this.copy(c8oSettings);
_this.httpInterface = new c8oHttpInterface_service_1.C8oHttpInterface(_this);
_this.c8oLogger.affect_val(_this, false);
_this.c8oLogger.logRemoteInit();
document.addEventListener("offline", function () {
_this.c8oLogger.info("Network offline");
_this.c8oLogger.info("Setting remote logs to false");
_this.logRemote = false;
if (_this.logOnFail != null) {
_this.logOnFail(new c8osdkjscore_1.C8oException(c8osdkjscore_1.C8oExceptionMessage.RemoteLogFail()), null);
}
}, false);
document.addEventListener("online", function () {
_this.log.info("Network online");
if (_this._initialLogRemote && !_this.logRemote) {
_this.logRemote = true;
_this.log.info("Setting remote logs to true");
}
}, false);
_this.c8oLogger.logMethodCall("C8o Constructor");
_this.c8oFullSync = new c8osdkjscore_1.C8oFullSyncCbl(_this);
resolve();
});
});
return this.promiseInit;
};
C8o.prototype.finalizeInit = function () {
var _this = this;
this.promiseFinInit = new Promise(function (resolve) {
Promise.all([_this.promiseInit]).then(function () {
if (_this._automaticRemoveSplashsCreen) {
if (navigator["splashscreen"] !== undefined) {
navigator["splashscreen"].hide();
}
}
if (window["cblite"] !== undefined) {
window["cblite"].getURL(function (err, url) {
if (err) {
resolve();
}
else {
url = url.replace(new RegExp("/$"), "");
_this.couchUrl = url;
resolve();
}
});
}
else {
resolve();
}
});
});
return this.promiseFinInit;
};
return C8o;
}(c8osdkjscore_1.C8oCore));
exports.C8o = C8o;
//# sourceMappingURL=c8o.service.js.map