UNPKG

@isaac-platform/isaac-integration-sdk

Version:

A Typescript SDK for integrating with ISAAC

49 lines (48 loc) 2.63 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()); }); }; // TODO: Migrate the object type definition to the object handler export class backupController { constructor(isaacConn) { // Returns an array of backup objects this.getAllBackups = () => __awaiter(this, void 0, void 0, function* () { return yield this.isaacConn.getRequest('backups'); }); // Requests the creation of a new backup using the provided name // TODO: Update this to take a callback or specify an event handler such that a function is executed when the process of creating the backup completes. Ideally this returns the complete backup object and handles errors. this.createBackup = (name) => __awaiter(this, void 0, void 0, function* () { let backupObject = yield this.isaacConn.postRequest('backups/createBackup', { displayName: name }); console.log(backupObject); }); this.createBackupPromise = (name) => { return new Promise((resolve, reject) => { (() => __awaiter(this, void 0, void 0, function* () { let backupObject = yield this.isaacConn.postRequest('backups/createBackup', { displayName: name }); console.log(backupObject); let intervalID = setInterval(() => { console.log("Polling"); this.getAllBackups().then((backups) => { backups.forEach(backup => { if (backup._id == backupObject._id && backup.status == "created") { resolve(backup); clearInterval(intervalID); } }); }); }, 1000); }))(); }); }; this.isaacConn = isaacConn; } }