@octopusx/ndk
Version:
octopus x sdk to connect to the octopusx grids and services
70 lines (69 loc) • 3.18 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const requests_1 = require("../utils/requests");
class Access {
constructor(options) {
this.options = options;
this.options.url = process.env.OCX_ACCESS_BASE_URL || process.env.VUE_APP_OCX_ACCESS_BASE_URL;
}
initData(payload) {
return {
"OCX Schema": this.options.version,
"OCXType": "Request",
"OCXComponent": "OCXAccess",
"OCXPayload": payload
};
}
setupAccess() {
return __awaiter(this, void 0, void 0, function* () {
const requestOptions = Object.assign({}, this.options);
const url = `access/${this.options.version}/setup`;
return requests_1.default(`POST`, url, requestOptions);
});
}
rollbackAccess() {
return __awaiter(this, void 0, void 0, function* () {
const requestOptions = Object.assign({}, this.options);
const url = `access/${this.options.version}/setup/rollback`;
return requests_1.default(`POST`, url, requestOptions);
});
}
registerRoute(data) {
return __awaiter(this, void 0, void 0, function* () {
const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData(data) });
const url = `access/v1/routes/register`;
return requests_1.default(`POST`, url, requestOptions);
});
}
getRoutes() {
return __awaiter(this, void 0, void 0, function* () {
const requestOptions = Object.assign({}, this.options);
const url = `access/v1/routes/view`;
return requests_1.default(`GET`, url, requestOptions);
});
}
fetchSingleRoute(routeId) {
return __awaiter(this, void 0, void 0, function* () {
const requestOptions = Object.assign({}, this.options);
const url = `access/${this.options.version}/routes/view/${routeId}`;
return requests_1.default(`GET`, url, requestOptions);
});
}
unRegisterRoute(routeId) {
return __awaiter(this, void 0, void 0, function* () {
const requestOptions = Object.assign(Object.assign({}, this.options), { data: this.initData({}) });
const url = `access/${this.options.version}/routes/unregister/${routeId}`;
return requests_1.default(`DELETE`, url, requestOptions);
});
}
}
exports.default = Access;