UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

107 lines (104 loc) 2.79 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 { MessageCommands } from './message/commands.mjs'; var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); class OptionsManager { static { __name(this, "OptionsManager"); } #messageManager; #appOptions = null; #userOptions = null; constructor(messageManager) { this.#messageManager = messageManager; } /** * Initializes the data received from the parent window message. * @param data */ initData(data) { if (data.APP_OPTIONS) { this.#appOptions = data.APP_OPTIONS; } if (data.USER_OPTIONS) { this.#userOptions = data.USER_OPTIONS; } return this; } /** * Getting application option * * @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/options/bx24-app-option-get.html */ appGet(option) { if (this.#appOptions && !!this.#appOptions[option]) { return this.#appOptions[option]; } throw new Error(`app.option.${option} not set`); } /** * Updates application data through the parent window * * @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/options/bx24-app-option-set.html */ async appSet(option, value) { if (!this.#appOptions) { this.#appOptions = []; } this.#appOptions[option] = value; return this.#sendParentMessage( MessageCommands.setAppOption, option, this.#appOptions[option] ); } /** * Getting user option * * @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/options/bx24-user-option-get.html */ userGet(option) { if (this.#userOptions && !!this.#userOptions[option]) { return this.#userOptions[option]; } throw new Error(`user.option.${option} not set`); } /** * Updates user data through the parent window * * @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/options/bx24-user-option-set.html */ async userSet(option, value) { if (!this.#appOptions) { this.#appOptions = []; } if (!this.#appOptions[option]) { this.#appOptions[option] = null; } this.#userOptions[option] = value; return this.#sendParentMessage( MessageCommands.setUserOption, option, // @ts-expect-error this code work success this.#userOptions[option] ); } async #sendParentMessage(command, option, value) { return this.#messageManager.send(command, { name: option, value, isSafely: true }).then(() => { return Promise.resolve(); }); } } export { OptionsManager }; //# sourceMappingURL=options.mjs.map