UNPKG

@isaac-platform/isaac-integration-sdk

Version:

A Typescript SDK for integrating with ISAAC

57 lines (56 loc) 2.74 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 { IsaacObject } from "./object.js"; import isaacConnection from "../controller/isaac.js"; export class ObjectController { constructor() { this.knownObjects = new Map(); this.getObjects = (bucket) => __awaiter(this, void 0, void 0, function* () { return Promise.reject(); }); this.getObjectByName = (name, bucket = "cms-media") => { return isaacConnection.getRequest(`objects/${bucket}/${name}`); }; /** * Retrieve an object using its ISAAC internal _id. * @param _id - The ISAAC internal _id of the object to retrieve. */ this.getObjectById = (_id) => { return isaacConnection.getRequest(`objects/${_id}`); }; /** * Safely retrieve an object reference using its ISAAC internal _id. * @param _id - The internal _id of the object to retrieve. */ this.getObjectByIdSafe = (_id) => __awaiter(this, void 0, void 0, function* () { if (this.knownObjects.has(_id)) return this.knownObjects.get(_id); try { const objectData = yield this.getObjectById(_id); this.knownObjects.set(_id, new IsaacObject(objectData._id)); return this.knownObjects.get(_id); } catch (error) { console.error('ISAAC SDK: Error retrieving object by ID.', error); throw error; } }); this.createObject = () => { /* TODO: This is complicated behavior which will require the upload of a file. Current plan is to split this behavior into three functions: createObject, requestObject, and uploadObject. This will allow for more manual control of the upload if necessary by the end user but createObject will handle the typical upload process. */ return Promise.reject(); }; } } const objectController = new ObjectController(); export default objectController;