@isaac-platform/isaac-integration-sdk
Version:
A Typescript SDK for integrating with ISAAC
61 lines (60 loc) • 3.02 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());
});
};
import isaacConnection from "../controller/isaac.js";
// TODO: Migrate the object type definition to the object handler
export class BackupController {
constructor() {
// Returns an array of backup objects
this.getAllBackups = () => __awaiter(this, void 0, void 0, function* () {
try {
return yield isaacConnection.getRequest('backups');
}
catch (error) {
console.error('ISAAC SDK: Error getting backups.', error);
throw error;
}
});
// 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* () {
try {
const backupObject = yield isaacConnection.postRequest('backups/createBackup', {
displayName: name
});
console.log(backupObject);
}
catch (error) {
console.error('ISAAC SDK: Error creating backup.', error);
throw error;
}
});
this.createBackupPromise = (name) => {
return new Promise((resolve, reject) => {
(() => __awaiter(this, void 0, void 0, function* () {
let backupObject = yield isaacConnection.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);
}))();
});
};
}
}