UNPKG

@isaac-platform/isaac-integration-sdk

Version:

A Typescript SDK for integrating with ISAAC

55 lines (54 loc) 2.57 kB
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()); }); }; import axios from "axios"; class isaacConnection { constructor(newConnection) { this.postRequest = (endpoint, payload, params) => __awaiter(this, void 0, void 0, function* () { return (yield axios.post(`http://${this.connectionDetails.ip}/api/v1/${endpoint}`, payload, { params: params })).data; }); this.putRequest = (endpoint, payload) => __awaiter(this, void 0, void 0, function* () { return (yield axios.put(`http://${this.connectionDetails.ip}/api/v1/${endpoint}`, payload)).data; }); console.log("Creating Connection"); this.connectionDetails = newConnection; this.subsystemID = newConnection.subsystemID; } // TODO: Proper async handling getRequest(endpoint, config) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield axios.get(`http://${this.connectionDetails.ip}/api/v1/${endpoint}`, config); return response.data; } catch (err) { // @ts-ignore if (err.response && err.response.status && err.response.status === 304) { console.warn("ISAAC 304: No change."); return; } console.error(err); } }); } } // export const configure = (config: isaacConnectionDetails) => { // isaacServer = config; // axios.get(`http://${isaacServer.ip}/api/v1/subsystems/${isaacServer.subsystemID}`).then((response: any) => { // isaacSubsytemID = response.data._id // }) // } // export const pingISAAC = () => { // axios.put(`http://${isaacServer.ip}/api/v1/subsystems/${isaacServer.subsystemID}/heartbeat`).then((response: any) => { // console.log(response.data) // }); // } export default isaacConnection;