@bitrix24/b24jssdk 0.4.1 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/umd/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @version @bitrix24/b24jssdk v0.4.1
2
+ * @version @bitrix24/b24jssdk v0.4.3
3
3
  * @copyright (c) 2025 Bitrix24
4
4
  * @licence MIT
5
5
  * @links https://github.com/bitrix24/b24jssdk - GitHub
@@ -508,6 +508,9 @@
508
508
  function isArrayOfArray(item) {
509
509
  return Array.isArray(item[0]);
510
510
  }
511
+ function getEnumValue(enumObj, value) {
512
+ return Object.values(enumObj).includes(value) ? value : void 0;
513
+ }
511
514
 
512
515
  // these aren't really private, but nor are they really useful to document
513
516
 
@@ -8538,89 +8541,44 @@
8538
8541
  }
8539
8542
  }
8540
8543
 
8541
- const _state = {};
8542
- function getCrypto() {
8543
- if (typeof window !== "undefined" && window.crypto) {
8544
- return window.crypto;
8545
- }
8546
- if (typeof globalThis.crypto !== "undefined") {
8547
- return globalThis.crypto;
8548
- }
8549
- throw new Error("Crypto API not available");
8550
- }
8551
- function initRng() {
8552
- const crypto = getCrypto();
8553
- if (!crypto?.getRandomValues) {
8554
- throw new Error("Crypto API not available");
8555
- }
8556
- return {
8557
- rng: () => {
8558
- const rnds8 = new Uint8Array(16);
8559
- return crypto.getRandomValues(rnds8);
8560
- }
8561
- };
8562
- }
8563
8544
  const byteToHex = [];
8564
8545
  for (let i = 0; i < 256; ++i) {
8565
8546
  byteToHex.push((i + 256).toString(16).slice(1));
8566
8547
  }
8567
- function updateV7State(state, now, randoms) {
8568
- state.msecs ??= -Infinity;
8569
- state.seq ??= 0;
8570
- if (now > state.msecs) {
8571
- state.seq = randoms[6] << 23 | randoms[7] << 16 | randoms[8] << 8 | randoms[9];
8572
- state.msecs = now;
8573
- } else {
8574
- state.seq = Math.trunc(state.seq + 1);
8575
- if (state.seq === 0) {
8576
- state.msecs++;
8577
- }
8578
- }
8579
- return state;
8580
- }
8581
- function v7Bytes(randoms, msecs, seq, buf, offset = 0) {
8582
- if (!buf) {
8583
- buf = new Uint8Array(16);
8584
- offset = 0;
8585
- }
8586
- msecs ??= Date.now();
8587
- seq ??= randoms[6] * 127 << 24 | randoms[7] << 16 | randoms[8] << 8 | randoms[9];
8588
- buf[offset++] = msecs / 1099511627776 & 255;
8589
- buf[offset++] = msecs / 4294967296 & 255;
8590
- buf[offset++] = msecs / 16777216 & 255;
8591
- buf[offset++] = msecs / 65536 & 255;
8592
- buf[offset++] = msecs / 256 & 255;
8593
- buf[offset++] = msecs & 255;
8594
- buf[offset++] = 112 | seq >>> 28 & 15;
8595
- buf[offset++] = seq >>> 20 & 255;
8596
- buf[offset++] = 128 | seq >>> 14 & 63;
8597
- buf[offset++] = seq >>> 6 & 255;
8598
- buf[offset++] = seq << 2 & 255 | randoms[10] & 3;
8599
- buf[offset++] = randoms[11];
8600
- buf[offset++] = randoms[12];
8601
- buf[offset++] = randoms[13];
8602
- buf[offset++] = randoms[14];
8603
- buf[offset++] = randoms[15];
8604
- return buf;
8605
- }
8606
- function unsafeStringify(arr, offset = 0) {
8607
- return (byteToHex[arr[offset]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
8548
+ function sfc32(a, b, c, d) {
8549
+ return () => {
8550
+ a |= 0;
8551
+ b |= 0;
8552
+ c |= 0;
8553
+ d |= 0;
8554
+ const t = (a + b | 0) + d | 0;
8555
+ d = d + 1 | 0;
8556
+ a = b ^ b >>> 9;
8557
+ b = c + (c << 3) | 0;
8558
+ c = (c << 21 | c >>> 11) + t | 0;
8559
+ return t >>> 0;
8560
+ };
8608
8561
  }
8609
8562
  function uuidv7() {
8610
- const buf = void 0;
8611
- const offset = void 0;
8612
- const now = Date.now();
8613
- const { rng } = initRng();
8614
- const randoms = rng();
8615
- updateV7State(_state, now, randoms);
8616
- const bytes = v7Bytes(
8617
- randoms,
8618
- _state.msecs,
8619
- _state.seq,
8620
- buf,
8621
- offset
8622
- );
8623
- return unsafeStringify(bytes);
8563
+ const bytes = new Uint8Array(16);
8564
+ const timestamp = BigInt(Date.now());
8565
+ const perf = BigInt(Math.floor(performance.now() * 1e3) % 65535);
8566
+ const combinedTime = timestamp << 16n | perf;
8567
+ bytes[0] = Number(combinedTime >> 40n & 0xffn);
8568
+ bytes[1] = Number(combinedTime >> 32n & 0xffn);
8569
+ bytes[2] = Number(combinedTime >> 24n & 0xffn);
8570
+ bytes[3] = Number(combinedTime >> 16n & 0xffn);
8571
+ bytes[4] = Number(combinedTime >> 8n & 0xffn);
8572
+ bytes[5] = Number(combinedTime & 0xffn);
8573
+ const seed = (Math.random() * 4294967295 ^ Date.now() ^ performance.now()) >>> 0;
8574
+ const rand = sfc32(2654435769, 608135816, 3084996962, seed);
8575
+ const randView = new DataView(bytes.buffer);
8576
+ randView.setUint32(6, rand());
8577
+ randView.setUint32(10, rand());
8578
+ randView.setUint16(14, rand());
8579
+ bytes[6] = 112 | bytes[6] & 15;
8580
+ bytes[8] = 128 | bytes[8] & 63;
8581
+ return (byteToHex[bytes[0]] + byteToHex[bytes[1]] + byteToHex[bytes[2]] + byteToHex[bytes[3]] + "-" + byteToHex[bytes[4]] + byteToHex[bytes[5]] + "-" + byteToHex[bytes[6]] + byteToHex[bytes[7]] + "-" + byteToHex[bytes[8]] + byteToHex[bytes[9]] + "-" + byteToHex[bytes[10]] + byteToHex[bytes[11]] + byteToHex[bytes[12]] + byteToHex[bytes[13]] + byteToHex[bytes[14]] + byteToHex[bytes[15]]).toLowerCase();
8624
8582
  }
8625
8583
 
8626
8584
  const reEscape = /[&<>'"]/g;
@@ -8989,6 +8947,10 @@
8989
8947
  EnumCrmEntityTypeShort2["order"] = "O";
8990
8948
  return EnumCrmEntityTypeShort2;
8991
8949
  })(EnumCrmEntityTypeShort || {});
8950
+ function getEnumCrmEntityTypeShort(id) {
8951
+ const key = EnumCrmEntityTypeId[id];
8952
+ return EnumCrmEntityTypeShort[key] || "?" /* undefined */;
8953
+ }
8992
8954
 
8993
8955
  var ProductRowDiscountTypeId = /* @__PURE__ */ ((ProductRowDiscountTypeId2) => {
8994
8956
  ProductRowDiscountTypeId2[ProductRowDiscountTypeId2["undefined"] = 0] = "undefined";
@@ -9022,6 +8984,175 @@
9022
8984
  return CatalogRoundingRuleType2;
9023
8985
  })(CatalogRoundingRuleType || {});
9024
8986
 
8987
+ var EnumBitrix24Edition = /* @__PURE__ */ ((EnumBitrix24Edition2) => {
8988
+ EnumBitrix24Edition2["undefined"] = "undefined";
8989
+ EnumBitrix24Edition2["b24"] = "b24";
8990
+ EnumBitrix24Edition2["box"] = "box";
8991
+ return EnumBitrix24Edition2;
8992
+ })(EnumBitrix24Edition || {});
8993
+ var EnumBizprocBaseType = /* @__PURE__ */ ((EnumBizprocBaseType2) => {
8994
+ EnumBizprocBaseType2["undefined"] = "undefined";
8995
+ EnumBizprocBaseType2["crm"] = "crm";
8996
+ EnumBizprocBaseType2["disk"] = "disk";
8997
+ EnumBizprocBaseType2["lists"] = "lists";
8998
+ return EnumBizprocBaseType2;
8999
+ })(EnumBizprocBaseType || {});
9000
+ var EnumBizprocDocumentType = /* @__PURE__ */ ((EnumBizprocDocumentType2) => {
9001
+ EnumBizprocDocumentType2["undefined"] = "undefined";
9002
+ EnumBizprocDocumentType2["lead"] = "CCrmDocumentLead";
9003
+ EnumBizprocDocumentType2["company"] = "CCrmDocumentCompany";
9004
+ EnumBizprocDocumentType2["contact"] = "CCrmDocumentContact";
9005
+ EnumBizprocDocumentType2["deal"] = "CCrmDocumentDeal";
9006
+ EnumBizprocDocumentType2["invoice"] = "Bitrix\\Crm\\Integration\\BizProc\\Document\\SmartInvoice";
9007
+ EnumBizprocDocumentType2["quote"] = "Bitrix\\Crm\\Integration\\BizProc\\Document\\Quote";
9008
+ EnumBizprocDocumentType2["order"] = "Bitrix\\Crm\\Integration\\BizProc\\Document\\Order";
9009
+ EnumBizprocDocumentType2["dynamic"] = "Bitrix\\Crm\\Integration\\BizProc\\Document\\Dynamic";
9010
+ EnumBizprocDocumentType2["disk"] = "Bitrix\\Disk\\BizProcDocument";
9011
+ EnumBizprocDocumentType2["lists"] = "BizprocDocument";
9012
+ EnumBizprocDocumentType2["listsList"] = "Bitrix\\Lists\\BizprocDocumentLists";
9013
+ return EnumBizprocDocumentType2;
9014
+ })(EnumBizprocDocumentType || {});
9015
+ function convertBizprocDocumentTypeToCrmEntityTypeId(documentType) {
9016
+ switch (documentType) {
9017
+ case "CCrmDocumentLead" /* lead */:
9018
+ return EnumCrmEntityTypeId.lead;
9019
+ case "CCrmDocumentCompany" /* company */:
9020
+ return EnumCrmEntityTypeId.company;
9021
+ case "CCrmDocumentContact" /* contact */:
9022
+ return EnumCrmEntityTypeId.contact;
9023
+ case "CCrmDocumentDeal" /* deal */:
9024
+ return EnumCrmEntityTypeId.deal;
9025
+ case "Bitrix\\Crm\\Integration\\BizProc\\Document\\SmartInvoice" /* invoice */:
9026
+ return EnumCrmEntityTypeId.invoice;
9027
+ case "Bitrix\\Crm\\Integration\\BizProc\\Document\\Quote" /* quote */:
9028
+ return EnumCrmEntityTypeId.quote;
9029
+ case "Bitrix\\Crm\\Integration\\BizProc\\Document\\Order" /* order */:
9030
+ return EnumCrmEntityTypeId.order;
9031
+ }
9032
+ return EnumCrmEntityTypeId.undefined;
9033
+ }
9034
+ function getDocumentType(documentType, entityId) {
9035
+ let entityIdFormatted = "";
9036
+ let base = "undefined" /* undefined */;
9037
+ switch (documentType) {
9038
+ case "CCrmDocumentLead" /* lead */:
9039
+ base = "crm" /* crm */;
9040
+ entityIdFormatted = "LEAD";
9041
+ break;
9042
+ case "CCrmDocumentCompany" /* company */:
9043
+ base = "crm" /* crm */;
9044
+ entityIdFormatted = "COMPANY";
9045
+ break;
9046
+ case "CCrmDocumentContact" /* contact */:
9047
+ base = "crm" /* crm */;
9048
+ entityIdFormatted = "CONTACT";
9049
+ break;
9050
+ case "CCrmDocumentDeal" /* deal */:
9051
+ base = "crm" /* crm */;
9052
+ entityIdFormatted = "DEAL";
9053
+ break;
9054
+ case "Bitrix\\Crm\\Integration\\BizProc\\Document\\SmartInvoice" /* invoice */:
9055
+ base = "crm" /* crm */;
9056
+ entityIdFormatted = "SMART_INVOICE";
9057
+ break;
9058
+ case "Bitrix\\Crm\\Integration\\BizProc\\Document\\Quote" /* quote */:
9059
+ base = "crm" /* crm */;
9060
+ entityIdFormatted = "QUOTE";
9061
+ break;
9062
+ case "Bitrix\\Crm\\Integration\\BizProc\\Document\\Order" /* order */:
9063
+ base = "crm" /* crm */;
9064
+ entityIdFormatted = "ORDER";
9065
+ break;
9066
+ case "Bitrix\\Crm\\Integration\\BizProc\\Document\\Dynamic" /* dynamic */:
9067
+ base = "crm" /* crm */;
9068
+ entityIdFormatted = `DYNAMIC_${entityId || 0}`;
9069
+ if ((entityId || 0) < 1) {
9070
+ throw new Error("Need set entityId");
9071
+ }
9072
+ break;
9073
+ case "Bitrix\\Disk\\BizProcDocument" /* disk */:
9074
+ base = "disk" /* disk */;
9075
+ entityIdFormatted = `STORAGE_${entityId || 0}`;
9076
+ if ((entityId || 0) < 1) {
9077
+ throw new Error("Need set entityId");
9078
+ }
9079
+ break;
9080
+ case "BizprocDocument" /* lists */:
9081
+ base = "lists" /* lists */;
9082
+ entityIdFormatted = `iblock_${entityId || 0}`;
9083
+ if ((entityId || 0) < 1) {
9084
+ throw new Error("Need set entityId");
9085
+ }
9086
+ break;
9087
+ case "Bitrix\\Lists\\BizprocDocumentLists" /* listsList */:
9088
+ base = "lists" /* lists */;
9089
+ entityIdFormatted = `iblock_${entityId || 0}`;
9090
+ if ((entityId || 0) < 1) {
9091
+ throw new Error("Need set entityId");
9092
+ }
9093
+ break;
9094
+ }
9095
+ return [
9096
+ base,
9097
+ documentType,
9098
+ entityIdFormatted
9099
+ ];
9100
+ }
9101
+ function getDocumentId(documentType, id, dynamicId) {
9102
+ let entityIdFormatted = "";
9103
+ const tmp = getDocumentType(documentType, 1);
9104
+ switch (documentType) {
9105
+ case "CCrmDocumentLead" /* lead */:
9106
+ entityIdFormatted = `LEAD_${id}`;
9107
+ break;
9108
+ case "CCrmDocumentCompany" /* company */:
9109
+ entityIdFormatted = `COMPANY_${id}`;
9110
+ break;
9111
+ case "CCrmDocumentContact" /* contact */:
9112
+ entityIdFormatted = `CONTACT_${id}`;
9113
+ break;
9114
+ case "CCrmDocumentDeal" /* deal */:
9115
+ entityIdFormatted = `DEAL_${id}`;
9116
+ break;
9117
+ case "Bitrix\\Crm\\Integration\\BizProc\\Document\\SmartInvoice" /* invoice */:
9118
+ entityIdFormatted = `SMART_INVOICE_${id}`;
9119
+ break;
9120
+ case "Bitrix\\Crm\\Integration\\BizProc\\Document\\Quote" /* quote */:
9121
+ entityIdFormatted = `QUOTE_${id}`;
9122
+ break;
9123
+ case "Bitrix\\Crm\\Integration\\BizProc\\Document\\Order" /* order */:
9124
+ entityIdFormatted = `ORDER_${id}`;
9125
+ break;
9126
+ case "Bitrix\\Crm\\Integration\\BizProc\\Document\\Dynamic" /* dynamic */:
9127
+ entityIdFormatted = `DYNAMIC_${dynamicId || 0}_${id}`;
9128
+ if ((dynamicId || 0) < 1) {
9129
+ throw new Error("Need set dynamicId");
9130
+ }
9131
+ break;
9132
+ case "Bitrix\\Disk\\BizProcDocument" /* disk */:
9133
+ entityIdFormatted = `${id}`;
9134
+ break;
9135
+ case "BizprocDocument" /* lists */:
9136
+ entityIdFormatted = `${id}`;
9137
+ break;
9138
+ case "Bitrix\\Lists\\BizprocDocumentLists" /* listsList */:
9139
+ entityIdFormatted = `${id}`;
9140
+ break;
9141
+ }
9142
+ return [
9143
+ tmp[0],
9144
+ tmp[1],
9145
+ entityIdFormatted
9146
+ ];
9147
+ }
9148
+ function getDocumentTypeForFilter(documentType) {
9149
+ const result = getDocumentType(documentType, 1);
9150
+ return [
9151
+ result[0],
9152
+ result[1]
9153
+ ];
9154
+ }
9155
+
9025
9156
  var LoadDataType = /* @__PURE__ */ ((LoadDataType2) => {
9026
9157
  LoadDataType2["App"] = "app";
9027
9158
  LoadDataType2["Profile"] = "profile";
@@ -14099,7 +14230,7 @@ ${this.stack}`;
14099
14230
  #clientSideWarningMessage = "";
14100
14231
  constructor(baseURL, authActions, options) {
14101
14232
  const defaultHeaders = {
14102
- // 'X-Sdk': 'b24-js-sdk-v-0.4.1'
14233
+ // 'X-Sdk': 'b24-js-sdk-v-0.4.3'
14103
14234
  };
14104
14235
  this.#clientAxios = axios.create({
14105
14236
  baseURL,
@@ -14527,7 +14658,7 @@ ${this.stack}`;
14527
14658
  const baseUrl = `${encodeURIComponent(method)}.json`;
14528
14659
  const queryParams = new URLSearchParams({
14529
14660
  [this.#requestIdGenerator.getQueryStringParameterName()]: this.#requestIdGenerator.getRequestId(),
14530
- [this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.1",
14661
+ [this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.3",
14531
14662
  [this.#requestIdGenerator.getQueryStringSdkTypeParameterName()]: "b24-js-sdk"
14532
14663
  });
14533
14664
  return `${baseUrl}?${queryParams.toString()}`;
@@ -14750,6 +14881,26 @@ ${this.stack}`;
14750
14881
  B24LangList2["ar"] = "ar";
14751
14882
  return B24LangList2;
14752
14883
  })(B24LangList || {});
14884
+ const B24LocaleMap = {
14885
+ ["en" /* en */]: "en-EN",
14886
+ ["de" /* de */]: "de-DE",
14887
+ ["la" /* la */]: "es-ES",
14888
+ ["br" /* br */]: "pt-BR",
14889
+ ["fr" /* fr */]: "fr-FR",
14890
+ ["it" /* it */]: "it-IT",
14891
+ ["pl" /* pl */]: "pl-PL",
14892
+ ["ru" /* ru */]: "ru-RU",
14893
+ ["ua" /* ua */]: "uk-UA",
14894
+ ["tr" /* tr */]: "tr-TR",
14895
+ ["sc" /* sc */]: "zh-CN",
14896
+ ["tc" /* tc */]: "zh-TW",
14897
+ ["ja" /* ja */]: "ja-JP",
14898
+ ["vn" /* vn */]: "vi-VN",
14899
+ ["id" /* id */]: "id-ID",
14900
+ ["ms" /* ms */]: "ms-MY",
14901
+ ["th" /* th */]: "th-TH",
14902
+ ["ar" /* ar */]: "ar-SA"
14903
+ };
14753
14904
 
14754
14905
  const useScrollSize = () => {
14755
14906
  return {
@@ -15547,20 +15698,25 @@ ${this.stack}`;
15547
15698
 
15548
15699
  class AuthHookManager {
15549
15700
  #b24HookParams;
15701
+ #domain;
15702
+ #b24TargetRest;
15703
+ #b24Target;
15550
15704
  constructor(b24HookParams) {
15551
15705
  this.#b24HookParams = Object.freeze(Object.assign({}, b24HookParams));
15706
+ this.#domain = this.#b24HookParams.b24Url.replaceAll("https://", "").replaceAll("http://", "").replace(/:(80|443)$/, "");
15707
+ this.#b24TargetRest = `https://${this.#domain}/rest`;
15708
+ this.#b24Target = `https://${this.#domain}`;
15552
15709
  }
15553
15710
  /**
15554
15711
  * @see Http.#prepareParams
15555
15712
  */
15556
15713
  getAuthData() {
15557
- const domain = this.#b24HookParams.b24Url.replaceAll("https://", "").replaceAll("http://", "").replace(/:(80|443)$/, "");
15558
15714
  return {
15559
15715
  access_token: this.#b24HookParams.secret,
15560
15716
  refresh_token: "hook",
15561
15717
  expires_in: 0,
15562
- domain,
15563
- member_id: domain
15718
+ domain: this.#domain,
15719
+ member_id: this.#domain
15564
15720
  };
15565
15721
  }
15566
15722
  refreshAuth() {
@@ -15577,13 +15733,13 @@ ${this.stack}`;
15577
15733
  * Get the account address BX24 ( https://name.bitrix24.com )
15578
15734
  */
15579
15735
  getTargetOrigin() {
15580
- return `${this.#b24HookParams.b24Url}`;
15736
+ return `${this.#b24Target}`;
15581
15737
  }
15582
15738
  /**
15583
15739
  * Get the account address BX24 with Path ( https://name.bitrix24.com/rest/1/xxxxx )
15584
15740
  */
15585
15741
  getTargetOriginWithPath() {
15586
- return `${this.#b24HookParams.b24Url}/rest/${this.#b24HookParams.userId}/${this.#b24HookParams.secret}`;
15742
+ return `${this.#b24TargetRest}/${this.#b24HookParams.userId}/${this.#b24HookParams.secret}`;
15587
15743
  }
15588
15744
  /**
15589
15745
  * We believe that hooks are created only by the admin
@@ -16743,6 +16899,234 @@ ${this.stack}`;
16743
16899
  // endregion ////
16744
16900
  }
16745
16901
 
16902
+ class RefreshTokenError extends AjaxError {
16903
+ }
16904
+
16905
+ class AuthOAuthManager {
16906
+ #clientAxios;
16907
+ #callbackRefreshAuth = null;
16908
+ #authOptions;
16909
+ #oAuthSecret;
16910
+ #authExpires = 0;
16911
+ #domain;
16912
+ #b24TargetRest;
16913
+ #b24Target;
16914
+ // 'https://oauth.bitrix.info' ////
16915
+ #oAuthTarget;
16916
+ #isAdmin = null;
16917
+ constructor(b24OAuthParams, oAuthSecret) {
16918
+ this.#authOptions = Object.assign({}, b24OAuthParams);
16919
+ this.#oAuthSecret = Object.freeze(Object.assign({}, oAuthSecret));
16920
+ this.#domain = this.#authOptions.domain.replaceAll("https://", "").replaceAll("http://", "").replace(/:(80|443)$/, "");
16921
+ this.#b24TargetRest = this.#authOptions.clientEndpoint;
16922
+ this.#b24Target = this.#b24TargetRest.replace("/rest/", "");
16923
+ this.#oAuthTarget = this.#authOptions.serverEndpoint.replace("/rest/", "");
16924
+ this.#authExpires = this.#authOptions.expires * 1e3;
16925
+ this.#clientAxios = axios.create({
16926
+ baseURL: this.#oAuthTarget,
16927
+ headers: {
16928
+ "Content-Type": "application/json"
16929
+ }
16930
+ });
16931
+ }
16932
+ /**
16933
+ * Returns authorization data
16934
+ * @see Http.#prepareParams
16935
+ */
16936
+ getAuthData() {
16937
+ return this.#authExpires > Date.now() ? {
16938
+ access_token: this.#authOptions.accessToken,
16939
+ refresh_token: this.#authOptions.refreshToken,
16940
+ expires_in: this.#authOptions.expiresIn,
16941
+ domain: this.#domain,
16942
+ member_id: this.#authOptions.memberId
16943
+ } : false;
16944
+ }
16945
+ // region RefreshAuth ////
16946
+ /**
16947
+ * Updates authorization data
16948
+ */
16949
+ async refreshAuth() {
16950
+ try {
16951
+ const response = await this.#clientAxios.get(
16952
+ "/oauth/token/",
16953
+ {
16954
+ params: {
16955
+ grant_type: "refresh_token",
16956
+ client_id: this.#oAuthSecret.clientId,
16957
+ client_secret: this.#oAuthSecret.clientSecret,
16958
+ refresh_token: this.#authOptions.refreshToken
16959
+ }
16960
+ }
16961
+ );
16962
+ if (response.data.error) {
16963
+ throw new Error(`Token update error: ${response.data.error}`);
16964
+ }
16965
+ if (response.status !== 200) {
16966
+ throw new Error(`Token update error status code: ${response.status}`);
16967
+ }
16968
+ const payload = response.data;
16969
+ this.#authOptions.accessToken = payload.access_token;
16970
+ this.#authOptions.refreshToken = payload.refresh_token;
16971
+ this.#authOptions.expires = Number.parseInt(payload.expires || "0");
16972
+ this.#authOptions.expiresIn = Number.parseInt(payload.expires_in || "3600");
16973
+ this.#authOptions.clientEndpoint = payload.client_endpoint;
16974
+ this.#authOptions.serverEndpoint = payload.server_endpoint;
16975
+ this.#authOptions.scope = payload.scope;
16976
+ this.#authOptions.status = Object.values(EnumAppStatus).find((value) => value === payload.status) || EnumAppStatus.Free;
16977
+ this.#authExpires = this.#authOptions.expires * 1e3;
16978
+ const authData = this.getAuthData();
16979
+ if (this.#callbackRefreshAuth) {
16980
+ await this.#callbackRefreshAuth({ authData, b24OAuthParams: this.#authOptions });
16981
+ }
16982
+ return authData;
16983
+ } catch (error) {
16984
+ if (error instanceof AxiosError) {
16985
+ let answerError = {
16986
+ error: error?.code || 0,
16987
+ errorDescription: error?.message || ""
16988
+ };
16989
+ if (error.response && error.response.data && !Type.isUndefined(error.response.data.error)) {
16990
+ const response = error.response.data;
16991
+ answerError = {
16992
+ error: response.error,
16993
+ errorDescription: response.error_description
16994
+ };
16995
+ }
16996
+ throw new RefreshTokenError({
16997
+ code: String(answerError.error),
16998
+ description: answerError.errorDescription,
16999
+ status: error.response?.status || 0,
17000
+ requestInfo: {
17001
+ method: "/oauth/token/"
17002
+ }
17003
+ });
17004
+ } else if (error instanceof Error) {
17005
+ throw error;
17006
+ }
17007
+ throw new Error(
17008
+ `Strange error: ${error instanceof Error ? error.message : error}`,
17009
+ { cause: error }
17010
+ );
17011
+ }
17012
+ }
17013
+ setCallbackRefreshAuth(cb) {
17014
+ this.#callbackRefreshAuth = cb;
17015
+ }
17016
+ removeCallbackRefreshAuth() {
17017
+ this.#callbackRefreshAuth = null;
17018
+ }
17019
+ // endregion ////
17020
+ getUniq(prefix) {
17021
+ return [prefix, this.#authOptions.memberId || ""].join("_");
17022
+ }
17023
+ /**
17024
+ * Get the account address BX24 ( https://name.bitrix24.com )
17025
+ */
17026
+ getTargetOrigin() {
17027
+ return `${this.#b24Target}`;
17028
+ }
17029
+ /**
17030
+ * Get the account address BX24 with Path ( https://name.bitrix24.com/rest )
17031
+ */
17032
+ getTargetOriginWithPath() {
17033
+ return `${this.#b24TargetRest}`;
17034
+ }
17035
+ /**
17036
+ * Determines whether the current user has administrator rights
17037
+ */
17038
+ get isAdmin() {
17039
+ if (null === this.#isAdmin) {
17040
+ throw new Error("isAdmin not init. You need call B24OAuth::initIsAdmin().");
17041
+ }
17042
+ return this.#isAdmin;
17043
+ }
17044
+ async initIsAdmin(http) {
17045
+ const response = await http.call("profile", {}, 0);
17046
+ if (!response.isSuccess) {
17047
+ throw new Error(response.getErrorMessages().join(";"));
17048
+ }
17049
+ const data = response.getData().result;
17050
+ if (data?.ADMIN) {
17051
+ this.#isAdmin = true;
17052
+ }
17053
+ }
17054
+ }
17055
+
17056
+ class B24OAuth extends AbstractB24 {
17057
+ #authOAuthManager;
17058
+ // region Init ////
17059
+ constructor(authOptions, oAuthSecret) {
17060
+ super();
17061
+ this.#authOAuthManager = new AuthOAuthManager(authOptions, oAuthSecret);
17062
+ this._http = new Http(
17063
+ this.#authOAuthManager.getTargetOriginWithPath(),
17064
+ this.#authOAuthManager,
17065
+ this._getHttpOptions()
17066
+ );
17067
+ this._http.setClientSideWarning(
17068
+ true,
17069
+ "It is not safe to use oauth requests on the client side"
17070
+ );
17071
+ this._isInit = true;
17072
+ }
17073
+ setLogger(logger) {
17074
+ super.setLogger(logger);
17075
+ }
17076
+ /**
17077
+ * Used to initialize information about the current user.
17078
+ */
17079
+ async initIsAdmin() {
17080
+ this._ensureInitialized();
17081
+ return this.#authOAuthManager.initIsAdmin(this._http);
17082
+ }
17083
+ /**
17084
+ * Sets an asynchronous Callback to receive updated authorization data
17085
+ * @param cb
17086
+ */
17087
+ setCallbackRefreshAuth(cb) {
17088
+ this._ensureInitialized();
17089
+ this.#authOAuthManager.setCallbackRefreshAuth(cb);
17090
+ }
17091
+ /**
17092
+ * Removes Callback to receive updated authorization data
17093
+ */
17094
+ removeCallbackRefreshAuth() {
17095
+ this._ensureInitialized();
17096
+ this.#authOAuthManager.removeCallbackRefreshAuth();
17097
+ }
17098
+ // endregion ////
17099
+ // region Core ////
17100
+ /**
17101
+ * Disables warning about client-side query execution
17102
+ */
17103
+ offClientSideWarning() {
17104
+ this.getHttpClient().setClientSideWarning(false, "");
17105
+ }
17106
+ // endregion ////
17107
+ get auth() {
17108
+ return this.#authOAuthManager;
17109
+ }
17110
+ // region Get ////
17111
+ /**
17112
+ * Get the account address BX24 ( https://name.bitrix24.com )
17113
+ */
17114
+ getTargetOrigin() {
17115
+ this._ensureInitialized();
17116
+ return this.#authOAuthManager.getTargetOrigin();
17117
+ }
17118
+ /**
17119
+ * Get the account address BX24 with Path ( https://name.bitrix24.com/rest/1/xxxxx )
17120
+ */
17121
+ getTargetOriginWithPath() {
17122
+ this._ensureInitialized();
17123
+ return this.#authOAuthManager.getTargetOriginWithPath();
17124
+ }
17125
+ // endregion ////
17126
+ // region Tools ////
17127
+ // endregion ////
17128
+ }
17129
+
16746
17130
  class UnhandledMatchError extends Error {
16747
17131
  constructor(value, ...args) {
16748
17132
  super(...args);
@@ -26213,9 +26597,12 @@ Data string: ${pullEvent}
26213
26597
  exports.AppFrame = AppFrame;
26214
26598
  exports.AuthHookManager = AuthHookManager;
26215
26599
  exports.AuthManager = AuthManager;
26600
+ exports.AuthOAuthManager = AuthOAuthManager;
26216
26601
  exports.B24Frame = B24Frame;
26217
26602
  exports.B24Hook = B24Hook;
26218
26603
  exports.B24LangList = B24LangList;
26604
+ exports.B24LocaleMap = B24LocaleMap;
26605
+ exports.B24OAuth = B24OAuth;
26219
26606
  exports.B24PullClientManager = PullClient;
26220
26607
  exports.Browser = Browser;
26221
26608
  exports.CatalogProductImageType = CatalogProductImageType;
@@ -26226,6 +26613,9 @@ Data string: ${pullEvent}
26226
26613
  exports.DataType = DataType;
26227
26614
  exports.DialogManager = DialogManager;
26228
26615
  exports.EnumAppStatus = EnumAppStatus;
26616
+ exports.EnumBitrix24Edition = EnumBitrix24Edition;
26617
+ exports.EnumBizprocBaseType = EnumBizprocBaseType;
26618
+ exports.EnumBizprocDocumentType = EnumBizprocDocumentType;
26229
26619
  exports.EnumCrmEntityType = EnumCrmEntityType;
26230
26620
  exports.EnumCrmEntityTypeId = EnumCrmEntityTypeId;
26231
26621
  exports.EnumCrmEntityTypeShort = EnumCrmEntityTypeShort;
@@ -26255,6 +26645,12 @@ Data string: ${pullEvent}
26255
26645
  exports.Type = Type;
26256
26646
  exports.TypeOption = TypeOption;
26257
26647
  exports.TypeSpecificUrl = TypeSpecificUrl;
26648
+ exports.convertBizprocDocumentTypeToCrmEntityTypeId = convertBizprocDocumentTypeToCrmEntityTypeId;
26649
+ exports.getDocumentId = getDocumentId;
26650
+ exports.getDocumentType = getDocumentType;
26651
+ exports.getDocumentTypeForFilter = getDocumentTypeForFilter;
26652
+ exports.getEnumCrmEntityTypeShort = getEnumCrmEntityTypeShort;
26653
+ exports.getEnumValue = getEnumValue;
26258
26654
  exports.initializeB24Frame = initializeB24Frame;
26259
26655
  exports.isArrayOfArray = isArrayOfArray;
26260
26656
  exports.omit = omit;