UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

104 lines (100 loc) 3.09 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 list = require('../core/language/list.cjs'); const b24 = require('../types/b24.cjs'); var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); class AppFrame { static { __name(this, "AppFrame"); } #domain = ""; #protocol = true; #appSid = null; #path = null; #lang = null; #b24TargetRest; #b24Target; #b24TargetRestWithPath; constructor(queryParams) { if (queryParams.DOMAIN) { this.#domain = queryParams.DOMAIN; this.#domain = this.#domain.replace(/:(80|443)$/, ""); } this.#protocol = queryParams.PROTOCOL === true; if (queryParams.LANG) { this.#lang = queryParams.LANG; } if (queryParams.APP_SID) { this.#appSid = queryParams.APP_SID; } this.#b24TargetRestWithPath = /* @__PURE__ */ new Map(); this.#b24Target = `${this.#protocol ? "https" : "http"}://${this.#domain}`; this.#b24TargetRest = `${this.#b24Target}/rest`; this.#b24TargetRestWithPath.set(b24.ApiVersion.v2, `${this.#b24TargetRest}`); this.#b24TargetRestWithPath.set(b24.ApiVersion.v3, `${this.#b24TargetRest}/api`); } /** * Initializes the data received from the parent window message. * @param data */ initData(data) { if (!this.#domain) { this.#domain = data.DOMAIN; } if (!this.#path) { this.#path = data.PATH; } if (!this.#lang) { this.#lang = data.LANG; } this.#protocol = Number.parseInt(data.PROTOCOL) === 1; this.#domain = this.#domain.replace(/:(80|443)$/, ""); this.#b24Target = `${this.#protocol ? "https" : "http"}://${this.#domain}`; this.#b24TargetRest = `${this.#b24Target}/rest`; this.#b24TargetRestWithPath.set(b24.ApiVersion.v2, `${this.#b24TargetRest}`); this.#b24TargetRestWithPath.set(b24.ApiVersion.v3, `${this.#b24TargetRest}/api`); return this; } /** * Returns the sid of the application relative to the parent window like this `9c33468728e1d2c8c97562475edfd96` */ getAppSid() { if (null === this.#appSid) { throw new Error(`Not init appSid`); } return this.#appSid; } /** * Get the account address BX24 (https://your_domain.bitrix24.com) */ getTargetOrigin() { return this.#b24Target; } /** * Get the account address BX24 with path * - ver2 `https://your_domain.bitrix24.com/rest/` * - ver3` https://your_domain.bitrix24.com/rest/api/` */ getTargetOriginWithPath() { return this.#b24TargetRestWithPath; } /** * Returns the localization of the B24 interface * @return {B24LangList} - default `B24LangList.en` * * @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/additional-functions/bx24-get-lang.html */ getLang() { return this.#lang || list.B24LangList.en; } } exports.AppFrame = AppFrame; //# sourceMappingURL=frame.cjs.map