UNPKG

@apillon/sdk

Version:

▶◀ Apillon SDK for NodeJS ▶◀

67 lines 2.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ApillonModel = exports.ApillonModule = void 0; const apillon_1 = require("../types/apillon"); const apillon_api_1 = require("./apillon-api"); const apillon_logger_1 = require("./apillon-logger"); class ApillonModule { constructor(config) { this.config = apillon_api_1.ApillonApi.initialize(config); apillon_logger_1.ApillonLogger.initialize((config === null || config === void 0 ? void 0 : config.debug) ? apillon_1.LogLevel.VERBOSE : (config === null || config === void 0 ? void 0 : config.logLevel) || apillon_1.LogLevel.ERROR); } } exports.ApillonModule = ApillonModule; class ApillonModel { constructor(uuid) { /** * API url prefix for this class. */ this.API_PREFIX = null; /** * The object's creation date */ this.createTime = null; /** * The date when the object was last updated */ this.updateTime = null; this.uuid = uuid; } /** * Gets and populates the object details of this entity * @returns A new instance of this object */ async get() { const data = await apillon_api_1.ApillonApi.get(this.API_PREFIX); return this.populate(data); } /** * Populates class properties via data object. * @param data Data object. */ populate(data) { if (data != null) { Object.keys(data || {}).forEach((key) => { if (this[key] === null) { this[key] = data[key]; } }); } return this; } /** * Convert object to JSON output, with unnecessary properties excluded */ serialize() { return JSON.parse(JSON.stringify(this, this.serializeFilter)); } /** * Define and exclude custom keys from serialized object */ serializeFilter(key, value) { const excludedKeys = ['API_PREFIX']; return excludedKeys.includes(key) ? undefined : value; } } exports.ApillonModel = ApillonModel; //# sourceMappingURL=apillon.js.map