UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

171 lines (168 loc) 5.04 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 { AbstractB24 } from '../core/abstract-b24.mjs'; import { HttpV2 } from '../core/http/v2.mjs'; import { HttpV3 } from '../core/http/v3.mjs'; import { AppFrame } from './frame.mjs'; import { AuthManager } from './auth.mjs'; import { ParentManager } from './parent.mjs'; import { OptionsManager } from './options.mjs'; import { DialogManager } from './dialog.mjs'; import { SliderManager } from './slider.mjs'; import { PlacementManager } from './placement.mjs'; import { MessageManager } from './message/controller.mjs'; import { MessageCommands } from './message/commands.mjs'; var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); class B24Frame extends AbstractB24 { static { __name(this, "B24Frame"); } #isInstallMode = false; #isFirstRun = false; #appFrame; #messageManager; #authManager; #parentManager; #optionsManager; #dialogManager; #sliderManager; #placementManager; #restrictionParams; // region Init //// constructor(queryParams, options) { super(); this.#restrictionParams = options?.restrictionParams; this.#appFrame = new AppFrame(queryParams); this.#messageManager = new MessageManager(this.#appFrame); this.#messageManager.subscribe(); this.#authManager = new AuthManager( this.#appFrame, this.#messageManager ); this.#parentManager = new ParentManager(this.#messageManager); this.#optionsManager = new OptionsManager(this.#messageManager); this.#dialogManager = new DialogManager(this.#messageManager); this.#sliderManager = new SliderManager( this.#appFrame, this.#messageManager ); this.#placementManager = new PlacementManager(this.#messageManager); this._isInit = false; } setLogger(logger) { super.setLogger(logger); this.#messageManager.setLogger(this.getLogger()); } get isFirstRun() { this._ensureInitialized(); return this.#isFirstRun; } get isInstallMode() { this._ensureInitialized(); return this.#isInstallMode; } get parent() { this._ensureInitialized(); return this.#parentManager; } get auth() { this._ensureInitialized(); return this.#authManager; } get slider() { this._ensureInitialized(); return this.#sliderManager; } get placement() { this._ensureInitialized(); return this.#placementManager; } get options() { this._ensureInitialized(); return this.#optionsManager; } get dialog() { this._ensureInitialized(); return this.#dialogManager; } async init() { const data = await this.#messageManager.send(MessageCommands.getInitData, {}); this.getLogger().debug("init data", { data }); this.#appFrame.initData(data); this.#authManager.initData(data); this.#placementManager.initData(data); this.#optionsManager.initData(data); this.#isInstallMode = data.INSTALL; this.#isFirstRun = data.FIRST_RUN; this._httpV2 = new HttpV2(this.#authManager, this._getHttpOptions(), this.#restrictionParams); this._httpV3 = new HttpV3(this.#authManager, this._getHttpOptions(), this.#restrictionParams); this._isInit = true; if (this.#isFirstRun) { return this.#messageManager.send(MessageCommands.setInstall, { install: true }); } return Promise.resolve(); } /** * Destructor. * Removes an event subscription */ destroy() { this.#messageManager.unsubscribe(); super.destroy(); } // endregion //// // region Core //// /** * Signals that the installer or application setup has finished running. * * @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/system-functions/bx24-install-finish.html */ async installFinish() { if (!this.isInstallMode) { return Promise.reject(new Error("Application was previously installed. You cannot call installFinish")); } return this.#messageManager.send(MessageCommands.setInstallFinish, {}); } // endregion //// // region Get //// /** * @inheritDoc */ getTargetOrigin() { this._ensureInitialized(); return this.#authManager.getTargetOrigin(); } /** * @inheritDoc */ getTargetOriginWithPath() { this._ensureInitialized(); return this.#authManager.getTargetOriginWithPath(); } /** * Returns the sid of the application relative to the parent window like this `9c33468728e1d2c8c97562475edfd96` */ getAppSid() { this._ensureInitialized(); return this.#appFrame.getAppSid(); } /** * Returns the localization of the B24 interface * * @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/additional-functions/bx24-get-lang.html */ getLang() { this._ensureInitialized(); return this.#appFrame.getLang(); } // endregion //// } export { B24Frame }; //# sourceMappingURL=b24.mjs.map