UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

90 lines (87 loc) 2.52 kB
/** * @package @bitrix24/b24jssdk * @version 1.0.1 * @copyright (c) 2026 Bitrix24 * @license MIT * @see https://github.com/bitrix24/b24jssdk * @see https://bitrix24.github.io/b24jssdk/ */ import { LoggerFactory } from '../logger/logger-factory.mjs'; var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); class ChannelManager { static { __name(this, "ChannelManager"); } _logger; _publicIds; _restClient; _getPublicListMethod; constructor(params) { this._logger = LoggerFactory.createNullLogger(); this._publicIds = /* @__PURE__ */ new Map(); this._restClient = params.b24; this._getPublicListMethod = params.getPublicListMethod; } setLogger(logger) { this._logger = logger; } getLogger() { return this._logger; } /** * @param {Array} users Array of user ids. * @return {Promise} */ async getPublicIds(users) { const now = /* @__PURE__ */ new Date(); const result = {}; const unknownUsers = []; for (const userId of users) { const chanel = this._publicIds.get(userId); if (chanel && chanel.end > now) { result[chanel.userId] = chanel; } else { unknownUsers.push(userId); } } if (unknownUsers.length === 0) { return Promise.resolve(result); } return new Promise((resolve) => { this._restClient.callMethod(this._getPublicListMethod, { users: unknownUsers }).then((response) => { const data = response.getData().result; this.setPublicIds(Object.values(data)); for (const userId of unknownUsers) { const chanel = this._publicIds.get(userId); if (chanel) { result[chanel.userId] = chanel; } } resolve(result); }).catch((error) => { this.getLogger().error("some error in getPublicIds", { error }); return resolve({}); }); }); } /** * @param {TypePublicIdDescriptor[]} publicIds */ setPublicIds(publicIds) { publicIds.forEach((publicIdDescriptor) => { const userId = Number(publicIdDescriptor.user_id); this._publicIds.set(userId, { userId, publicId: publicIdDescriptor.public_id, signature: publicIdDescriptor.signature, start: new Date(publicIdDescriptor.start), end: new Date(publicIdDescriptor.end) }); }); } } export { ChannelManager }; //# sourceMappingURL=channel-manager.mjs.map