UNPKG

@stackend/api

Version:

JS bindings to api.stackend.com

95 lines 3.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listLiveEvents = exports.filterLiveEventModule = exports.getLiveEventModuleSettings = exports.isLiveEventModule = exports.newLiveEventModule = exports.LiveEventState = exports.COMPONENT_CONTEXT = exports.COMPONENT_NAME = exports.COMPONENT_CLASS = void 0; var stackend_1 = require("../stackend"); var api_1 = require("../api"); /** * Component class: com.stackend.live.LiveEventManager * @type {string} */ exports.COMPONENT_CLASS = 'com.stackend.live.LiveEventManager'; /** * Component name: live * @type {string} */ exports.COMPONENT_NAME = 'live'; /** * Live uses the generic 'comments' context but the com.stackend.live.LiveEventManager component * @type {string} */ exports.COMPONENT_CONTEXT = 'comments'; var LiveEventState; (function (LiveEventState) { LiveEventState["SCHEDULED"] = "SCHEDULED"; LiveEventState["ACTIVE"] = "ACTIVE"; LiveEventState["COMPLETED"] = "COMPLETED"; })(LiveEventState = exports.LiveEventState || (exports.LiveEventState = {})); /** * Create a new live event module * @param communityId * @param name * @param settings optional settings * @returns {*} */ function newLiveEventModule(_a) { var communityId = _a.communityId, name = _a.name, settings = _a.settings; var m = (0, stackend_1.newModule)({ communityId: communityId, componentClass: exports.COMPONENT_CLASS, componentContext: exports.COMPONENT_CONTEXT, name: name }); m.componentName = exports.COMPONENT_NAME; m.settings = Object.assign({ showTitle: true, state: LiveEventState.SCHEDULED }, settings || {}); return m; } exports.newLiveEventModule = newLiveEventModule; /** * Check if a module is a live event * @param module * @returns {boolean} */ function isLiveEventModule(module) { return module && module.componentClass === exports.COMPONENT_CLASS; } exports.isLiveEventModule = isLiveEventModule; /** * Get live event settings. Ensure this is a live event * @param module */ function getLiveEventModuleSettings(module) { if (!isLiveEventModule(module)) { throw 'Not a live event module: ' + module.id + ' (' + module.componentName + ')'; } return module.settings; } exports.getLiveEventModuleSettings = getLiveEventModuleSettings; /** * Filter live event modules matching a given state * @param module * @param state */ function filterLiveEventModule(module, state) { var _a, _b; // undefined check for backward compatibility return (isLiveEventModule(module) && (typeof ((_a = module === null || module === void 0 ? void 0 : module.settings) === null || _a === void 0 ? void 0 : _a.state) === 'undefined' || ((_b = module === null || module === void 0 ? void 0 : module.settings) === null || _b === void 0 ? void 0 : _b.state) === state)); } exports.filterLiveEventModule = filterLiveEventModule; /** * A variation of list modules that lists only live events */ function listLiveEvents(_a) { var _b = _a.pageSize /* No pagination support */, pageSize = _b === void 0 ? 1000 : _b /* No pagination support */, _c = _a.matchEnabled, matchEnabled = _c === void 0 ? undefined : _c; return (0, api_1.getJson)({ url: '/live/list', parameters: { pageSize: pageSize, matchEnabled: matchEnabled } }); } exports.listLiveEvents = listLiveEvents; //# sourceMappingURL=index.js.map