@bitrix24/b24jssdk 0.4.2 → 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/esm/index.d.mts +381 -171
- package/dist/esm/index.d.ts +381 -171
- package/dist/esm/index.mjs +330 -37
- package/dist/esm/index.mjs.map +1 -1
- package/dist/umd/index.js +337 -34
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/index.min.js +20 -20
- package/dist/umd/index.min.js.map +1 -1
- package/package.json +2 -2
package/dist/umd/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @version @bitrix24/b24jssdk v0.4.
|
|
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
|
|
|
@@ -8944,6 +8947,10 @@
|
|
|
8944
8947
|
EnumCrmEntityTypeShort2["order"] = "O";
|
|
8945
8948
|
return EnumCrmEntityTypeShort2;
|
|
8946
8949
|
})(EnumCrmEntityTypeShort || {});
|
|
8950
|
+
function getEnumCrmEntityTypeShort(id) {
|
|
8951
|
+
const key = EnumCrmEntityTypeId[id];
|
|
8952
|
+
return EnumCrmEntityTypeShort[key] || "?" /* undefined */;
|
|
8953
|
+
}
|
|
8947
8954
|
|
|
8948
8955
|
var ProductRowDiscountTypeId = /* @__PURE__ */ ((ProductRowDiscountTypeId2) => {
|
|
8949
8956
|
ProductRowDiscountTypeId2[ProductRowDiscountTypeId2["undefined"] = 0] = "undefined";
|
|
@@ -8977,6 +8984,175 @@
|
|
|
8977
8984
|
return CatalogRoundingRuleType2;
|
|
8978
8985
|
})(CatalogRoundingRuleType || {});
|
|
8979
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
|
+
|
|
8980
9156
|
var LoadDataType = /* @__PURE__ */ ((LoadDataType2) => {
|
|
8981
9157
|
LoadDataType2["App"] = "app";
|
|
8982
9158
|
LoadDataType2["Profile"] = "profile";
|
|
@@ -14054,7 +14230,7 @@ ${this.stack}`;
|
|
|
14054
14230
|
#clientSideWarningMessage = "";
|
|
14055
14231
|
constructor(baseURL, authActions, options) {
|
|
14056
14232
|
const defaultHeaders = {
|
|
14057
|
-
// 'X-Sdk': 'b24-js-sdk-v-0.4.
|
|
14233
|
+
// 'X-Sdk': 'b24-js-sdk-v-0.4.3'
|
|
14058
14234
|
};
|
|
14059
14235
|
this.#clientAxios = axios.create({
|
|
14060
14236
|
baseURL,
|
|
@@ -14482,7 +14658,7 @@ ${this.stack}`;
|
|
|
14482
14658
|
const baseUrl = `${encodeURIComponent(method)}.json`;
|
|
14483
14659
|
const queryParams = new URLSearchParams({
|
|
14484
14660
|
[this.#requestIdGenerator.getQueryStringParameterName()]: this.#requestIdGenerator.getRequestId(),
|
|
14485
|
-
[this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.
|
|
14661
|
+
[this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.3",
|
|
14486
14662
|
[this.#requestIdGenerator.getQueryStringSdkTypeParameterName()]: "b24-js-sdk"
|
|
14487
14663
|
});
|
|
14488
14664
|
return `${baseUrl}?${queryParams.toString()}`;
|
|
@@ -14705,6 +14881,26 @@ ${this.stack}`;
|
|
|
14705
14881
|
B24LangList2["ar"] = "ar";
|
|
14706
14882
|
return B24LangList2;
|
|
14707
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
|
+
};
|
|
14708
14904
|
|
|
14709
14905
|
const useScrollSize = () => {
|
|
14710
14906
|
return {
|
|
@@ -15502,20 +15698,25 @@ ${this.stack}`;
|
|
|
15502
15698
|
|
|
15503
15699
|
class AuthHookManager {
|
|
15504
15700
|
#b24HookParams;
|
|
15701
|
+
#domain;
|
|
15702
|
+
#b24TargetRest;
|
|
15703
|
+
#b24Target;
|
|
15505
15704
|
constructor(b24HookParams) {
|
|
15506
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}`;
|
|
15507
15709
|
}
|
|
15508
15710
|
/**
|
|
15509
15711
|
* @see Http.#prepareParams
|
|
15510
15712
|
*/
|
|
15511
15713
|
getAuthData() {
|
|
15512
|
-
const domain = this.#b24HookParams.b24Url.replaceAll("https://", "").replaceAll("http://", "").replace(/:(80|443)$/, "");
|
|
15513
15714
|
return {
|
|
15514
15715
|
access_token: this.#b24HookParams.secret,
|
|
15515
15716
|
refresh_token: "hook",
|
|
15516
15717
|
expires_in: 0,
|
|
15517
|
-
domain,
|
|
15518
|
-
member_id: domain
|
|
15718
|
+
domain: this.#domain,
|
|
15719
|
+
member_id: this.#domain
|
|
15519
15720
|
};
|
|
15520
15721
|
}
|
|
15521
15722
|
refreshAuth() {
|
|
@@ -15532,13 +15733,13 @@ ${this.stack}`;
|
|
|
15532
15733
|
* Get the account address BX24 ( https://name.bitrix24.com )
|
|
15533
15734
|
*/
|
|
15534
15735
|
getTargetOrigin() {
|
|
15535
|
-
return `${this.#
|
|
15736
|
+
return `${this.#b24Target}`;
|
|
15536
15737
|
}
|
|
15537
15738
|
/**
|
|
15538
15739
|
* Get the account address BX24 with Path ( https://name.bitrix24.com/rest/1/xxxxx )
|
|
15539
15740
|
*/
|
|
15540
15741
|
getTargetOriginWithPath() {
|
|
15541
|
-
return `${this.#
|
|
15742
|
+
return `${this.#b24TargetRest}/${this.#b24HookParams.userId}/${this.#b24HookParams.secret}`;
|
|
15542
15743
|
}
|
|
15543
15744
|
/**
|
|
15544
15745
|
* We believe that hooks are created only by the admin
|
|
@@ -16698,13 +16899,18 @@ ${this.stack}`;
|
|
|
16698
16899
|
// endregion ////
|
|
16699
16900
|
}
|
|
16700
16901
|
|
|
16902
|
+
class RefreshTokenError extends AjaxError {
|
|
16903
|
+
}
|
|
16904
|
+
|
|
16701
16905
|
class AuthOAuthManager {
|
|
16906
|
+
#clientAxios;
|
|
16907
|
+
#callbackRefreshAuth = null;
|
|
16702
16908
|
#authOptions;
|
|
16703
16909
|
#oAuthSecret;
|
|
16704
16910
|
#authExpires = 0;
|
|
16705
16911
|
#domain;
|
|
16706
|
-
#b24Target;
|
|
16707
16912
|
#b24TargetRest;
|
|
16913
|
+
#b24Target;
|
|
16708
16914
|
// 'https://oauth.bitrix.info' ////
|
|
16709
16915
|
#oAuthTarget;
|
|
16710
16916
|
#isAdmin = null;
|
|
@@ -16713,9 +16919,15 @@ ${this.stack}`;
|
|
|
16713
16919
|
this.#oAuthSecret = Object.freeze(Object.assign({}, oAuthSecret));
|
|
16714
16920
|
this.#domain = this.#authOptions.domain.replaceAll("https://", "").replaceAll("http://", "").replace(/:(80|443)$/, "");
|
|
16715
16921
|
this.#b24TargetRest = this.#authOptions.clientEndpoint;
|
|
16716
|
-
this.#b24Target = this.#b24TargetRest.replace("/rest", "");
|
|
16922
|
+
this.#b24Target = this.#b24TargetRest.replace("/rest/", "");
|
|
16717
16923
|
this.#oAuthTarget = this.#authOptions.serverEndpoint.replace("/rest/", "");
|
|
16718
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
|
+
});
|
|
16719
16931
|
}
|
|
16720
16932
|
/**
|
|
16721
16933
|
* Returns authorization data
|
|
@@ -16730,40 +16942,81 @@ ${this.stack}`;
|
|
|
16730
16942
|
member_id: this.#authOptions.memberId
|
|
16731
16943
|
} : false;
|
|
16732
16944
|
}
|
|
16945
|
+
// region RefreshAuth ////
|
|
16733
16946
|
/**
|
|
16734
16947
|
* Updates authorization data
|
|
16735
16948
|
*/
|
|
16736
16949
|
async refreshAuth() {
|
|
16737
16950
|
try {
|
|
16738
|
-
const response = await
|
|
16739
|
-
|
|
16740
|
-
|
|
16741
|
-
"Content-Type": "application/json"
|
|
16742
|
-
},
|
|
16743
|
-
body: JSON.stringify({
|
|
16951
|
+
const response = await this.#clientAxios.get(
|
|
16952
|
+
"/oauth/token/",
|
|
16953
|
+
{
|
|
16744
16954
|
params: {
|
|
16745
|
-
client_id: this.#oAuthSecret.clientId,
|
|
16746
16955
|
grant_type: "refresh_token",
|
|
16956
|
+
client_id: this.#oAuthSecret.clientId,
|
|
16747
16957
|
client_secret: this.#oAuthSecret.clientSecret,
|
|
16748
16958
|
refresh_token: this.#authOptions.refreshToken
|
|
16749
16959
|
}
|
|
16750
|
-
}
|
|
16751
|
-
|
|
16752
|
-
if (
|
|
16753
|
-
throw new Error(`Token update error: ${response.
|
|
16960
|
+
}
|
|
16961
|
+
);
|
|
16962
|
+
if (response.data.error) {
|
|
16963
|
+
throw new Error(`Token update error: ${response.data.error}`);
|
|
16754
16964
|
}
|
|
16755
|
-
|
|
16756
|
-
|
|
16757
|
-
throw new Error(`Token update error: ${data.error}`);
|
|
16965
|
+
if (response.status !== 200) {
|
|
16966
|
+
throw new Error(`Token update error status code: ${response.status}`);
|
|
16758
16967
|
}
|
|
16759
|
-
|
|
16760
|
-
this.#authOptions.
|
|
16761
|
-
this.#
|
|
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;
|
|
16762
16983
|
} catch (error) {
|
|
16763
|
-
|
|
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
|
+
);
|
|
16764
17011
|
}
|
|
16765
|
-
return this.getAuthData();
|
|
16766
17012
|
}
|
|
17013
|
+
setCallbackRefreshAuth(cb) {
|
|
17014
|
+
this.#callbackRefreshAuth = cb;
|
|
17015
|
+
}
|
|
17016
|
+
removeCallbackRefreshAuth() {
|
|
17017
|
+
this.#callbackRefreshAuth = null;
|
|
17018
|
+
}
|
|
17019
|
+
// endregion ////
|
|
16767
17020
|
getUniq(prefix) {
|
|
16768
17021
|
return [prefix, this.#authOptions.memberId || ""].join("_");
|
|
16769
17022
|
}
|
|
@@ -16802,6 +17055,7 @@ ${this.stack}`;
|
|
|
16802
17055
|
|
|
16803
17056
|
class B24OAuth extends AbstractB24 {
|
|
16804
17057
|
#authOAuthManager;
|
|
17058
|
+
// region Init ////
|
|
16805
17059
|
constructor(authOptions, oAuthSecret) {
|
|
16806
17060
|
super();
|
|
16807
17061
|
this.#authOAuthManager = new AuthOAuthManager(authOptions, oAuthSecret);
|
|
@@ -16810,28 +17064,67 @@ ${this.stack}`;
|
|
|
16810
17064
|
this.#authOAuthManager,
|
|
16811
17065
|
this._getHttpOptions()
|
|
16812
17066
|
);
|
|
17067
|
+
this._http.setClientSideWarning(
|
|
17068
|
+
true,
|
|
17069
|
+
"It is not safe to use oauth requests on the client side"
|
|
17070
|
+
);
|
|
16813
17071
|
this._isInit = true;
|
|
16814
17072
|
}
|
|
17073
|
+
setLogger(logger) {
|
|
17074
|
+
super.setLogger(logger);
|
|
17075
|
+
}
|
|
17076
|
+
/**
|
|
17077
|
+
* Used to initialize information about the current user.
|
|
17078
|
+
*/
|
|
16815
17079
|
async initIsAdmin() {
|
|
16816
|
-
|
|
16817
|
-
throw new Error("Http Not init");
|
|
16818
|
-
}
|
|
17080
|
+
this._ensureInitialized();
|
|
16819
17081
|
return this.#authOAuthManager.initIsAdmin(this._http);
|
|
16820
17082
|
}
|
|
16821
|
-
|
|
16822
|
-
|
|
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);
|
|
16823
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 ////
|
|
16824
17107
|
get auth() {
|
|
16825
17108
|
return this.#authOAuthManager;
|
|
16826
17109
|
}
|
|
17110
|
+
// region Get ////
|
|
17111
|
+
/**
|
|
17112
|
+
* Get the account address BX24 ( https://name.bitrix24.com )
|
|
17113
|
+
*/
|
|
16827
17114
|
getTargetOrigin() {
|
|
16828
17115
|
this._ensureInitialized();
|
|
16829
17116
|
return this.#authOAuthManager.getTargetOrigin();
|
|
16830
17117
|
}
|
|
17118
|
+
/**
|
|
17119
|
+
* Get the account address BX24 with Path ( https://name.bitrix24.com/rest/1/xxxxx )
|
|
17120
|
+
*/
|
|
16831
17121
|
getTargetOriginWithPath() {
|
|
16832
17122
|
this._ensureInitialized();
|
|
16833
17123
|
return this.#authOAuthManager.getTargetOriginWithPath();
|
|
16834
17124
|
}
|
|
17125
|
+
// endregion ////
|
|
17126
|
+
// region Tools ////
|
|
17127
|
+
// endregion ////
|
|
16835
17128
|
}
|
|
16836
17129
|
|
|
16837
17130
|
class UnhandledMatchError extends Error {
|
|
@@ -26308,6 +26601,7 @@ Data string: ${pullEvent}
|
|
|
26308
26601
|
exports.B24Frame = B24Frame;
|
|
26309
26602
|
exports.B24Hook = B24Hook;
|
|
26310
26603
|
exports.B24LangList = B24LangList;
|
|
26604
|
+
exports.B24LocaleMap = B24LocaleMap;
|
|
26311
26605
|
exports.B24OAuth = B24OAuth;
|
|
26312
26606
|
exports.B24PullClientManager = PullClient;
|
|
26313
26607
|
exports.Browser = Browser;
|
|
@@ -26319,6 +26613,9 @@ Data string: ${pullEvent}
|
|
|
26319
26613
|
exports.DataType = DataType;
|
|
26320
26614
|
exports.DialogManager = DialogManager;
|
|
26321
26615
|
exports.EnumAppStatus = EnumAppStatus;
|
|
26616
|
+
exports.EnumBitrix24Edition = EnumBitrix24Edition;
|
|
26617
|
+
exports.EnumBizprocBaseType = EnumBizprocBaseType;
|
|
26618
|
+
exports.EnumBizprocDocumentType = EnumBizprocDocumentType;
|
|
26322
26619
|
exports.EnumCrmEntityType = EnumCrmEntityType;
|
|
26323
26620
|
exports.EnumCrmEntityTypeId = EnumCrmEntityTypeId;
|
|
26324
26621
|
exports.EnumCrmEntityTypeShort = EnumCrmEntityTypeShort;
|
|
@@ -26348,6 +26645,12 @@ Data string: ${pullEvent}
|
|
|
26348
26645
|
exports.Type = Type;
|
|
26349
26646
|
exports.TypeOption = TypeOption;
|
|
26350
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;
|
|
26351
26654
|
exports.initializeB24Frame = initializeB24Frame;
|
|
26352
26655
|
exports.isArrayOfArray = isArrayOfArray;
|
|
26353
26656
|
exports.omit = omit;
|