UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

179 lines (175 loc) 5.27 kB
/** * @package @bitrix24/b24jssdk * @version 2.0.0 * @copyright (c) 2026 Bitrix24 * @license MIT * @see https://github.com/bitrix24/b24jssdk * @see https://bitrix24.github.io/b24jssdk/ */ 'use strict'; const abstractB24 = require('../core/abstract-b24.cjs'); const v2 = require('../core/http/v2.cjs'); const v3 = require('../core/http/v3.cjs'); const frame = require('./frame.cjs'); const auth = require('./auth.cjs'); const parent = require('./parent.cjs'); const options = require('./options.cjs'); const dialog = require('./dialog.cjs'); const slider = require('./slider.cjs'); const placement = require('./placement.cjs'); const controller = require('./message/controller.cjs'); const commands = require('./message/commands.cjs'); var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); class B24Frame extends abstractB24.AbstractB24 { static { __name(this, "B24Frame"); } #isInstallMode = false; #isFirstRun = false; #appFrame; #messageManager; #authManager; #parentManager; #optionsManager; #dialogManager; #sliderManager; #placementManager; #restrictionParams; // region Init //// constructor(queryParams, options$1) { super(); this.#restrictionParams = options$1?.restrictionParams; this.#appFrame = new frame.AppFrame(queryParams); this.#messageManager = new controller.MessageManager(this.#appFrame); this.#messageManager.subscribe(); this.#authManager = new auth.AuthManager( this.#appFrame, this.#messageManager ); this.#parentManager = new parent.ParentManager(this.#messageManager); this.#optionsManager = new options.OptionsManager(this.#messageManager); this.#dialogManager = new dialog.DialogManager(this.#messageManager); this.#sliderManager = new slider.SliderManager( this.#appFrame, this.#messageManager ); this.#placementManager = new placement.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(commands.MessageCommands.getInitData, {}); this.getLogger().debug("init data", { PLACEMENT: data.PLACEMENT, LANG: data.LANG, INSTALL: data.INSTALL, IS_ADMIN: data.IS_ADMIN, FIRST_RUN: data.FIRST_RUN }); 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 v2.HttpV2(this.#authManager, this._getHttpOptions(), this.#restrictionParams); this._httpV3 = new v3.HttpV3(this.#authManager, this._getHttpOptions(), this.#restrictionParams); this._isInit = true; if (this.#isFirstRun) { return this.#messageManager.send(commands.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(commands.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 //// } exports.B24Frame = B24Frame; //# sourceMappingURL=b24.cjs.map