@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/esm/index.mjs
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
|
|
@@ -506,6 +506,9 @@ function omit(data, keys) {
|
|
|
506
506
|
function isArrayOfArray(item) {
|
|
507
507
|
return Array.isArray(item[0]);
|
|
508
508
|
}
|
|
509
|
+
function getEnumValue(enumObj, value) {
|
|
510
|
+
return Object.values(enumObj).includes(value) ? value : void 0;
|
|
511
|
+
}
|
|
509
512
|
|
|
510
513
|
const byteToHex = [];
|
|
511
514
|
for (let i = 0; i < 256; ++i) {
|
|
@@ -913,6 +916,10 @@ var EnumCrmEntityTypeShort = /* @__PURE__ */ ((EnumCrmEntityTypeShort2) => {
|
|
|
913
916
|
EnumCrmEntityTypeShort2["order"] = "O";
|
|
914
917
|
return EnumCrmEntityTypeShort2;
|
|
915
918
|
})(EnumCrmEntityTypeShort || {});
|
|
919
|
+
function getEnumCrmEntityTypeShort(id) {
|
|
920
|
+
const key = EnumCrmEntityTypeId[id];
|
|
921
|
+
return EnumCrmEntityTypeShort[key] || "?" /* undefined */;
|
|
922
|
+
}
|
|
916
923
|
|
|
917
924
|
var ProductRowDiscountTypeId = /* @__PURE__ */ ((ProductRowDiscountTypeId2) => {
|
|
918
925
|
ProductRowDiscountTypeId2[ProductRowDiscountTypeId2["undefined"] = 0] = "undefined";
|
|
@@ -946,6 +953,175 @@ var CatalogRoundingRuleType = /* @__PURE__ */ ((CatalogRoundingRuleType2) => {
|
|
|
946
953
|
return CatalogRoundingRuleType2;
|
|
947
954
|
})(CatalogRoundingRuleType || {});
|
|
948
955
|
|
|
956
|
+
var EnumBitrix24Edition = /* @__PURE__ */ ((EnumBitrix24Edition2) => {
|
|
957
|
+
EnumBitrix24Edition2["undefined"] = "undefined";
|
|
958
|
+
EnumBitrix24Edition2["b24"] = "b24";
|
|
959
|
+
EnumBitrix24Edition2["box"] = "box";
|
|
960
|
+
return EnumBitrix24Edition2;
|
|
961
|
+
})(EnumBitrix24Edition || {});
|
|
962
|
+
var EnumBizprocBaseType = /* @__PURE__ */ ((EnumBizprocBaseType2) => {
|
|
963
|
+
EnumBizprocBaseType2["undefined"] = "undefined";
|
|
964
|
+
EnumBizprocBaseType2["crm"] = "crm";
|
|
965
|
+
EnumBizprocBaseType2["disk"] = "disk";
|
|
966
|
+
EnumBizprocBaseType2["lists"] = "lists";
|
|
967
|
+
return EnumBizprocBaseType2;
|
|
968
|
+
})(EnumBizprocBaseType || {});
|
|
969
|
+
var EnumBizprocDocumentType = /* @__PURE__ */ ((EnumBizprocDocumentType2) => {
|
|
970
|
+
EnumBizprocDocumentType2["undefined"] = "undefined";
|
|
971
|
+
EnumBizprocDocumentType2["lead"] = "CCrmDocumentLead";
|
|
972
|
+
EnumBizprocDocumentType2["company"] = "CCrmDocumentCompany";
|
|
973
|
+
EnumBizprocDocumentType2["contact"] = "CCrmDocumentContact";
|
|
974
|
+
EnumBizprocDocumentType2["deal"] = "CCrmDocumentDeal";
|
|
975
|
+
EnumBizprocDocumentType2["invoice"] = "Bitrix\\Crm\\Integration\\BizProc\\Document\\SmartInvoice";
|
|
976
|
+
EnumBizprocDocumentType2["quote"] = "Bitrix\\Crm\\Integration\\BizProc\\Document\\Quote";
|
|
977
|
+
EnumBizprocDocumentType2["order"] = "Bitrix\\Crm\\Integration\\BizProc\\Document\\Order";
|
|
978
|
+
EnumBizprocDocumentType2["dynamic"] = "Bitrix\\Crm\\Integration\\BizProc\\Document\\Dynamic";
|
|
979
|
+
EnumBizprocDocumentType2["disk"] = "Bitrix\\Disk\\BizProcDocument";
|
|
980
|
+
EnumBizprocDocumentType2["lists"] = "BizprocDocument";
|
|
981
|
+
EnumBizprocDocumentType2["listsList"] = "Bitrix\\Lists\\BizprocDocumentLists";
|
|
982
|
+
return EnumBizprocDocumentType2;
|
|
983
|
+
})(EnumBizprocDocumentType || {});
|
|
984
|
+
function convertBizprocDocumentTypeToCrmEntityTypeId(documentType) {
|
|
985
|
+
switch (documentType) {
|
|
986
|
+
case "CCrmDocumentLead" /* lead */:
|
|
987
|
+
return EnumCrmEntityTypeId.lead;
|
|
988
|
+
case "CCrmDocumentCompany" /* company */:
|
|
989
|
+
return EnumCrmEntityTypeId.company;
|
|
990
|
+
case "CCrmDocumentContact" /* contact */:
|
|
991
|
+
return EnumCrmEntityTypeId.contact;
|
|
992
|
+
case "CCrmDocumentDeal" /* deal */:
|
|
993
|
+
return EnumCrmEntityTypeId.deal;
|
|
994
|
+
case "Bitrix\\Crm\\Integration\\BizProc\\Document\\SmartInvoice" /* invoice */:
|
|
995
|
+
return EnumCrmEntityTypeId.invoice;
|
|
996
|
+
case "Bitrix\\Crm\\Integration\\BizProc\\Document\\Quote" /* quote */:
|
|
997
|
+
return EnumCrmEntityTypeId.quote;
|
|
998
|
+
case "Bitrix\\Crm\\Integration\\BizProc\\Document\\Order" /* order */:
|
|
999
|
+
return EnumCrmEntityTypeId.order;
|
|
1000
|
+
}
|
|
1001
|
+
return EnumCrmEntityTypeId.undefined;
|
|
1002
|
+
}
|
|
1003
|
+
function getDocumentType(documentType, entityId) {
|
|
1004
|
+
let entityIdFormatted = "";
|
|
1005
|
+
let base = "undefined" /* undefined */;
|
|
1006
|
+
switch (documentType) {
|
|
1007
|
+
case "CCrmDocumentLead" /* lead */:
|
|
1008
|
+
base = "crm" /* crm */;
|
|
1009
|
+
entityIdFormatted = "LEAD";
|
|
1010
|
+
break;
|
|
1011
|
+
case "CCrmDocumentCompany" /* company */:
|
|
1012
|
+
base = "crm" /* crm */;
|
|
1013
|
+
entityIdFormatted = "COMPANY";
|
|
1014
|
+
break;
|
|
1015
|
+
case "CCrmDocumentContact" /* contact */:
|
|
1016
|
+
base = "crm" /* crm */;
|
|
1017
|
+
entityIdFormatted = "CONTACT";
|
|
1018
|
+
break;
|
|
1019
|
+
case "CCrmDocumentDeal" /* deal */:
|
|
1020
|
+
base = "crm" /* crm */;
|
|
1021
|
+
entityIdFormatted = "DEAL";
|
|
1022
|
+
break;
|
|
1023
|
+
case "Bitrix\\Crm\\Integration\\BizProc\\Document\\SmartInvoice" /* invoice */:
|
|
1024
|
+
base = "crm" /* crm */;
|
|
1025
|
+
entityIdFormatted = "SMART_INVOICE";
|
|
1026
|
+
break;
|
|
1027
|
+
case "Bitrix\\Crm\\Integration\\BizProc\\Document\\Quote" /* quote */:
|
|
1028
|
+
base = "crm" /* crm */;
|
|
1029
|
+
entityIdFormatted = "QUOTE";
|
|
1030
|
+
break;
|
|
1031
|
+
case "Bitrix\\Crm\\Integration\\BizProc\\Document\\Order" /* order */:
|
|
1032
|
+
base = "crm" /* crm */;
|
|
1033
|
+
entityIdFormatted = "ORDER";
|
|
1034
|
+
break;
|
|
1035
|
+
case "Bitrix\\Crm\\Integration\\BizProc\\Document\\Dynamic" /* dynamic */:
|
|
1036
|
+
base = "crm" /* crm */;
|
|
1037
|
+
entityIdFormatted = `DYNAMIC_${entityId || 0}`;
|
|
1038
|
+
if ((entityId || 0) < 1) {
|
|
1039
|
+
throw new Error("Need set entityId");
|
|
1040
|
+
}
|
|
1041
|
+
break;
|
|
1042
|
+
case "Bitrix\\Disk\\BizProcDocument" /* disk */:
|
|
1043
|
+
base = "disk" /* disk */;
|
|
1044
|
+
entityIdFormatted = `STORAGE_${entityId || 0}`;
|
|
1045
|
+
if ((entityId || 0) < 1) {
|
|
1046
|
+
throw new Error("Need set entityId");
|
|
1047
|
+
}
|
|
1048
|
+
break;
|
|
1049
|
+
case "BizprocDocument" /* lists */:
|
|
1050
|
+
base = "lists" /* lists */;
|
|
1051
|
+
entityIdFormatted = `iblock_${entityId || 0}`;
|
|
1052
|
+
if ((entityId || 0) < 1) {
|
|
1053
|
+
throw new Error("Need set entityId");
|
|
1054
|
+
}
|
|
1055
|
+
break;
|
|
1056
|
+
case "Bitrix\\Lists\\BizprocDocumentLists" /* listsList */:
|
|
1057
|
+
base = "lists" /* lists */;
|
|
1058
|
+
entityIdFormatted = `iblock_${entityId || 0}`;
|
|
1059
|
+
if ((entityId || 0) < 1) {
|
|
1060
|
+
throw new Error("Need set entityId");
|
|
1061
|
+
}
|
|
1062
|
+
break;
|
|
1063
|
+
}
|
|
1064
|
+
return [
|
|
1065
|
+
base,
|
|
1066
|
+
documentType,
|
|
1067
|
+
entityIdFormatted
|
|
1068
|
+
];
|
|
1069
|
+
}
|
|
1070
|
+
function getDocumentId(documentType, id, dynamicId) {
|
|
1071
|
+
let entityIdFormatted = "";
|
|
1072
|
+
const tmp = getDocumentType(documentType, 1);
|
|
1073
|
+
switch (documentType) {
|
|
1074
|
+
case "CCrmDocumentLead" /* lead */:
|
|
1075
|
+
entityIdFormatted = `LEAD_${id}`;
|
|
1076
|
+
break;
|
|
1077
|
+
case "CCrmDocumentCompany" /* company */:
|
|
1078
|
+
entityIdFormatted = `COMPANY_${id}`;
|
|
1079
|
+
break;
|
|
1080
|
+
case "CCrmDocumentContact" /* contact */:
|
|
1081
|
+
entityIdFormatted = `CONTACT_${id}`;
|
|
1082
|
+
break;
|
|
1083
|
+
case "CCrmDocumentDeal" /* deal */:
|
|
1084
|
+
entityIdFormatted = `DEAL_${id}`;
|
|
1085
|
+
break;
|
|
1086
|
+
case "Bitrix\\Crm\\Integration\\BizProc\\Document\\SmartInvoice" /* invoice */:
|
|
1087
|
+
entityIdFormatted = `SMART_INVOICE_${id}`;
|
|
1088
|
+
break;
|
|
1089
|
+
case "Bitrix\\Crm\\Integration\\BizProc\\Document\\Quote" /* quote */:
|
|
1090
|
+
entityIdFormatted = `QUOTE_${id}`;
|
|
1091
|
+
break;
|
|
1092
|
+
case "Bitrix\\Crm\\Integration\\BizProc\\Document\\Order" /* order */:
|
|
1093
|
+
entityIdFormatted = `ORDER_${id}`;
|
|
1094
|
+
break;
|
|
1095
|
+
case "Bitrix\\Crm\\Integration\\BizProc\\Document\\Dynamic" /* dynamic */:
|
|
1096
|
+
entityIdFormatted = `DYNAMIC_${dynamicId || 0}_${id}`;
|
|
1097
|
+
if ((dynamicId || 0) < 1) {
|
|
1098
|
+
throw new Error("Need set dynamicId");
|
|
1099
|
+
}
|
|
1100
|
+
break;
|
|
1101
|
+
case "Bitrix\\Disk\\BizProcDocument" /* disk */:
|
|
1102
|
+
entityIdFormatted = `${id}`;
|
|
1103
|
+
break;
|
|
1104
|
+
case "BizprocDocument" /* lists */:
|
|
1105
|
+
entityIdFormatted = `${id}`;
|
|
1106
|
+
break;
|
|
1107
|
+
case "Bitrix\\Lists\\BizprocDocumentLists" /* listsList */:
|
|
1108
|
+
entityIdFormatted = `${id}`;
|
|
1109
|
+
break;
|
|
1110
|
+
}
|
|
1111
|
+
return [
|
|
1112
|
+
tmp[0],
|
|
1113
|
+
tmp[1],
|
|
1114
|
+
entityIdFormatted
|
|
1115
|
+
];
|
|
1116
|
+
}
|
|
1117
|
+
function getDocumentTypeForFilter(documentType) {
|
|
1118
|
+
const result = getDocumentType(documentType, 1);
|
|
1119
|
+
return [
|
|
1120
|
+
result[0],
|
|
1121
|
+
result[1]
|
|
1122
|
+
];
|
|
1123
|
+
}
|
|
1124
|
+
|
|
949
1125
|
var LoadDataType = /* @__PURE__ */ ((LoadDataType2) => {
|
|
950
1126
|
LoadDataType2["App"] = "app";
|
|
951
1127
|
LoadDataType2["Profile"] = "profile";
|
|
@@ -1502,7 +1678,7 @@ class Http {
|
|
|
1502
1678
|
#clientSideWarningMessage = "";
|
|
1503
1679
|
constructor(baseURL, authActions, options) {
|
|
1504
1680
|
const defaultHeaders = {
|
|
1505
|
-
// 'X-Sdk': 'b24-js-sdk-v-0.4.
|
|
1681
|
+
// 'X-Sdk': 'b24-js-sdk-v-0.4.3'
|
|
1506
1682
|
};
|
|
1507
1683
|
this.#clientAxios = axios.create({
|
|
1508
1684
|
baseURL,
|
|
@@ -1930,7 +2106,7 @@ class Http {
|
|
|
1930
2106
|
const baseUrl = `${encodeURIComponent(method)}.json`;
|
|
1931
2107
|
const queryParams = new URLSearchParams({
|
|
1932
2108
|
[this.#requestIdGenerator.getQueryStringParameterName()]: this.#requestIdGenerator.getRequestId(),
|
|
1933
|
-
[this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.
|
|
2109
|
+
[this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.3",
|
|
1934
2110
|
[this.#requestIdGenerator.getQueryStringSdkTypeParameterName()]: "b24-js-sdk"
|
|
1935
2111
|
});
|
|
1936
2112
|
return `${baseUrl}?${queryParams.toString()}`;
|
|
@@ -2153,6 +2329,26 @@ var B24LangList = /* @__PURE__ */ ((B24LangList2) => {
|
|
|
2153
2329
|
B24LangList2["ar"] = "ar";
|
|
2154
2330
|
return B24LangList2;
|
|
2155
2331
|
})(B24LangList || {});
|
|
2332
|
+
const B24LocaleMap = {
|
|
2333
|
+
["en" /* en */]: "en-EN",
|
|
2334
|
+
["de" /* de */]: "de-DE",
|
|
2335
|
+
["la" /* la */]: "es-ES",
|
|
2336
|
+
["br" /* br */]: "pt-BR",
|
|
2337
|
+
["fr" /* fr */]: "fr-FR",
|
|
2338
|
+
["it" /* it */]: "it-IT",
|
|
2339
|
+
["pl" /* pl */]: "pl-PL",
|
|
2340
|
+
["ru" /* ru */]: "ru-RU",
|
|
2341
|
+
["ua" /* ua */]: "uk-UA",
|
|
2342
|
+
["tr" /* tr */]: "tr-TR",
|
|
2343
|
+
["sc" /* sc */]: "zh-CN",
|
|
2344
|
+
["tc" /* tc */]: "zh-TW",
|
|
2345
|
+
["ja" /* ja */]: "ja-JP",
|
|
2346
|
+
["vn" /* vn */]: "vi-VN",
|
|
2347
|
+
["id" /* id */]: "id-ID",
|
|
2348
|
+
["ms" /* ms */]: "ms-MY",
|
|
2349
|
+
["th" /* th */]: "th-TH",
|
|
2350
|
+
["ar" /* ar */]: "ar-SA"
|
|
2351
|
+
};
|
|
2156
2352
|
|
|
2157
2353
|
const useScrollSize = () => {
|
|
2158
2354
|
return {
|
|
@@ -2950,20 +3146,25 @@ const useFormatter = () => {
|
|
|
2950
3146
|
|
|
2951
3147
|
class AuthHookManager {
|
|
2952
3148
|
#b24HookParams;
|
|
3149
|
+
#domain;
|
|
3150
|
+
#b24TargetRest;
|
|
3151
|
+
#b24Target;
|
|
2953
3152
|
constructor(b24HookParams) {
|
|
2954
3153
|
this.#b24HookParams = Object.freeze(Object.assign({}, b24HookParams));
|
|
3154
|
+
this.#domain = this.#b24HookParams.b24Url.replaceAll("https://", "").replaceAll("http://", "").replace(/:(80|443)$/, "");
|
|
3155
|
+
this.#b24TargetRest = `https://${this.#domain}/rest`;
|
|
3156
|
+
this.#b24Target = `https://${this.#domain}`;
|
|
2955
3157
|
}
|
|
2956
3158
|
/**
|
|
2957
3159
|
* @see Http.#prepareParams
|
|
2958
3160
|
*/
|
|
2959
3161
|
getAuthData() {
|
|
2960
|
-
const domain = this.#b24HookParams.b24Url.replaceAll("https://", "").replaceAll("http://", "").replace(/:(80|443)$/, "");
|
|
2961
3162
|
return {
|
|
2962
3163
|
access_token: this.#b24HookParams.secret,
|
|
2963
3164
|
refresh_token: "hook",
|
|
2964
3165
|
expires_in: 0,
|
|
2965
|
-
domain,
|
|
2966
|
-
member_id: domain
|
|
3166
|
+
domain: this.#domain,
|
|
3167
|
+
member_id: this.#domain
|
|
2967
3168
|
};
|
|
2968
3169
|
}
|
|
2969
3170
|
refreshAuth() {
|
|
@@ -2980,13 +3181,13 @@ class AuthHookManager {
|
|
|
2980
3181
|
* Get the account address BX24 ( https://name.bitrix24.com )
|
|
2981
3182
|
*/
|
|
2982
3183
|
getTargetOrigin() {
|
|
2983
|
-
return `${this.#
|
|
3184
|
+
return `${this.#b24Target}`;
|
|
2984
3185
|
}
|
|
2985
3186
|
/**
|
|
2986
3187
|
* Get the account address BX24 with Path ( https://name.bitrix24.com/rest/1/xxxxx )
|
|
2987
3188
|
*/
|
|
2988
3189
|
getTargetOriginWithPath() {
|
|
2989
|
-
return `${this.#
|
|
3190
|
+
return `${this.#b24TargetRest}/${this.#b24HookParams.userId}/${this.#b24HookParams.secret}`;
|
|
2990
3191
|
}
|
|
2991
3192
|
/**
|
|
2992
3193
|
* We believe that hooks are created only by the admin
|
|
@@ -4146,13 +4347,18 @@ class B24Frame extends AbstractB24 {
|
|
|
4146
4347
|
// endregion ////
|
|
4147
4348
|
}
|
|
4148
4349
|
|
|
4350
|
+
class RefreshTokenError extends AjaxError {
|
|
4351
|
+
}
|
|
4352
|
+
|
|
4149
4353
|
class AuthOAuthManager {
|
|
4354
|
+
#clientAxios;
|
|
4355
|
+
#callbackRefreshAuth = null;
|
|
4150
4356
|
#authOptions;
|
|
4151
4357
|
#oAuthSecret;
|
|
4152
4358
|
#authExpires = 0;
|
|
4153
4359
|
#domain;
|
|
4154
|
-
#b24Target;
|
|
4155
4360
|
#b24TargetRest;
|
|
4361
|
+
#b24Target;
|
|
4156
4362
|
// 'https://oauth.bitrix.info' ////
|
|
4157
4363
|
#oAuthTarget;
|
|
4158
4364
|
#isAdmin = null;
|
|
@@ -4161,9 +4367,15 @@ class AuthOAuthManager {
|
|
|
4161
4367
|
this.#oAuthSecret = Object.freeze(Object.assign({}, oAuthSecret));
|
|
4162
4368
|
this.#domain = this.#authOptions.domain.replaceAll("https://", "").replaceAll("http://", "").replace(/:(80|443)$/, "");
|
|
4163
4369
|
this.#b24TargetRest = this.#authOptions.clientEndpoint;
|
|
4164
|
-
this.#b24Target = this.#b24TargetRest.replace("/rest", "");
|
|
4370
|
+
this.#b24Target = this.#b24TargetRest.replace("/rest/", "");
|
|
4165
4371
|
this.#oAuthTarget = this.#authOptions.serverEndpoint.replace("/rest/", "");
|
|
4166
4372
|
this.#authExpires = this.#authOptions.expires * 1e3;
|
|
4373
|
+
this.#clientAxios = axios.create({
|
|
4374
|
+
baseURL: this.#oAuthTarget,
|
|
4375
|
+
headers: {
|
|
4376
|
+
"Content-Type": "application/json"
|
|
4377
|
+
}
|
|
4378
|
+
});
|
|
4167
4379
|
}
|
|
4168
4380
|
/**
|
|
4169
4381
|
* Returns authorization data
|
|
@@ -4178,40 +4390,81 @@ class AuthOAuthManager {
|
|
|
4178
4390
|
member_id: this.#authOptions.memberId
|
|
4179
4391
|
} : false;
|
|
4180
4392
|
}
|
|
4393
|
+
// region RefreshAuth ////
|
|
4181
4394
|
/**
|
|
4182
4395
|
* Updates authorization data
|
|
4183
4396
|
*/
|
|
4184
4397
|
async refreshAuth() {
|
|
4185
4398
|
try {
|
|
4186
|
-
const response = await
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
"Content-Type": "application/json"
|
|
4190
|
-
},
|
|
4191
|
-
body: JSON.stringify({
|
|
4399
|
+
const response = await this.#clientAxios.get(
|
|
4400
|
+
"/oauth/token/",
|
|
4401
|
+
{
|
|
4192
4402
|
params: {
|
|
4193
|
-
client_id: this.#oAuthSecret.clientId,
|
|
4194
4403
|
grant_type: "refresh_token",
|
|
4404
|
+
client_id: this.#oAuthSecret.clientId,
|
|
4195
4405
|
client_secret: this.#oAuthSecret.clientSecret,
|
|
4196
4406
|
refresh_token: this.#authOptions.refreshToken
|
|
4197
4407
|
}
|
|
4198
|
-
}
|
|
4199
|
-
|
|
4200
|
-
if (
|
|
4201
|
-
throw new Error(`Token update error: ${response.
|
|
4202
|
-
}
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
this.#authOptions.accessToken =
|
|
4208
|
-
this.#authOptions.refreshToken =
|
|
4209
|
-
this.#
|
|
4408
|
+
}
|
|
4409
|
+
);
|
|
4410
|
+
if (response.data.error) {
|
|
4411
|
+
throw new Error(`Token update error: ${response.data.error}`);
|
|
4412
|
+
}
|
|
4413
|
+
if (response.status !== 200) {
|
|
4414
|
+
throw new Error(`Token update error status code: ${response.status}`);
|
|
4415
|
+
}
|
|
4416
|
+
const payload = response.data;
|
|
4417
|
+
this.#authOptions.accessToken = payload.access_token;
|
|
4418
|
+
this.#authOptions.refreshToken = payload.refresh_token;
|
|
4419
|
+
this.#authOptions.expires = Number.parseInt(payload.expires || "0");
|
|
4420
|
+
this.#authOptions.expiresIn = Number.parseInt(payload.expires_in || "3600");
|
|
4421
|
+
this.#authOptions.clientEndpoint = payload.client_endpoint;
|
|
4422
|
+
this.#authOptions.serverEndpoint = payload.server_endpoint;
|
|
4423
|
+
this.#authOptions.scope = payload.scope;
|
|
4424
|
+
this.#authOptions.status = Object.values(EnumAppStatus).find((value) => value === payload.status) || EnumAppStatus.Free;
|
|
4425
|
+
this.#authExpires = this.#authOptions.expires * 1e3;
|
|
4426
|
+
const authData = this.getAuthData();
|
|
4427
|
+
if (this.#callbackRefreshAuth) {
|
|
4428
|
+
await this.#callbackRefreshAuth({ authData, b24OAuthParams: this.#authOptions });
|
|
4429
|
+
}
|
|
4430
|
+
return authData;
|
|
4210
4431
|
} catch (error) {
|
|
4211
|
-
|
|
4432
|
+
if (error instanceof AxiosError) {
|
|
4433
|
+
let answerError = {
|
|
4434
|
+
error: error?.code || 0,
|
|
4435
|
+
errorDescription: error?.message || ""
|
|
4436
|
+
};
|
|
4437
|
+
if (error.response && error.response.data && !Type.isUndefined(error.response.data.error)) {
|
|
4438
|
+
const response = error.response.data;
|
|
4439
|
+
answerError = {
|
|
4440
|
+
error: response.error,
|
|
4441
|
+
errorDescription: response.error_description
|
|
4442
|
+
};
|
|
4443
|
+
}
|
|
4444
|
+
throw new RefreshTokenError({
|
|
4445
|
+
code: String(answerError.error),
|
|
4446
|
+
description: answerError.errorDescription,
|
|
4447
|
+
status: error.response?.status || 0,
|
|
4448
|
+
requestInfo: {
|
|
4449
|
+
method: "/oauth/token/"
|
|
4450
|
+
}
|
|
4451
|
+
});
|
|
4452
|
+
} else if (error instanceof Error) {
|
|
4453
|
+
throw error;
|
|
4454
|
+
}
|
|
4455
|
+
throw new Error(
|
|
4456
|
+
`Strange error: ${error instanceof Error ? error.message : error}`,
|
|
4457
|
+
{ cause: error }
|
|
4458
|
+
);
|
|
4212
4459
|
}
|
|
4213
|
-
return this.getAuthData();
|
|
4214
4460
|
}
|
|
4461
|
+
setCallbackRefreshAuth(cb) {
|
|
4462
|
+
this.#callbackRefreshAuth = cb;
|
|
4463
|
+
}
|
|
4464
|
+
removeCallbackRefreshAuth() {
|
|
4465
|
+
this.#callbackRefreshAuth = null;
|
|
4466
|
+
}
|
|
4467
|
+
// endregion ////
|
|
4215
4468
|
getUniq(prefix) {
|
|
4216
4469
|
return [prefix, this.#authOptions.memberId || ""].join("_");
|
|
4217
4470
|
}
|
|
@@ -4250,6 +4503,7 @@ class AuthOAuthManager {
|
|
|
4250
4503
|
|
|
4251
4504
|
class B24OAuth extends AbstractB24 {
|
|
4252
4505
|
#authOAuthManager;
|
|
4506
|
+
// region Init ////
|
|
4253
4507
|
constructor(authOptions, oAuthSecret) {
|
|
4254
4508
|
super();
|
|
4255
4509
|
this.#authOAuthManager = new AuthOAuthManager(authOptions, oAuthSecret);
|
|
@@ -4258,28 +4512,67 @@ class B24OAuth extends AbstractB24 {
|
|
|
4258
4512
|
this.#authOAuthManager,
|
|
4259
4513
|
this._getHttpOptions()
|
|
4260
4514
|
);
|
|
4515
|
+
this._http.setClientSideWarning(
|
|
4516
|
+
true,
|
|
4517
|
+
"It is not safe to use oauth requests on the client side"
|
|
4518
|
+
);
|
|
4261
4519
|
this._isInit = true;
|
|
4262
4520
|
}
|
|
4521
|
+
setLogger(logger) {
|
|
4522
|
+
super.setLogger(logger);
|
|
4523
|
+
}
|
|
4524
|
+
/**
|
|
4525
|
+
* Used to initialize information about the current user.
|
|
4526
|
+
*/
|
|
4263
4527
|
async initIsAdmin() {
|
|
4264
|
-
|
|
4265
|
-
throw new Error("Http Not init");
|
|
4266
|
-
}
|
|
4528
|
+
this._ensureInitialized();
|
|
4267
4529
|
return this.#authOAuthManager.initIsAdmin(this._http);
|
|
4268
4530
|
}
|
|
4269
|
-
|
|
4270
|
-
|
|
4531
|
+
/**
|
|
4532
|
+
* Sets an asynchronous Callback to receive updated authorization data
|
|
4533
|
+
* @param cb
|
|
4534
|
+
*/
|
|
4535
|
+
setCallbackRefreshAuth(cb) {
|
|
4536
|
+
this._ensureInitialized();
|
|
4537
|
+
this.#authOAuthManager.setCallbackRefreshAuth(cb);
|
|
4271
4538
|
}
|
|
4539
|
+
/**
|
|
4540
|
+
* Removes Callback to receive updated authorization data
|
|
4541
|
+
*/
|
|
4542
|
+
removeCallbackRefreshAuth() {
|
|
4543
|
+
this._ensureInitialized();
|
|
4544
|
+
this.#authOAuthManager.removeCallbackRefreshAuth();
|
|
4545
|
+
}
|
|
4546
|
+
// endregion ////
|
|
4547
|
+
// region Core ////
|
|
4548
|
+
/**
|
|
4549
|
+
* Disables warning about client-side query execution
|
|
4550
|
+
*/
|
|
4551
|
+
offClientSideWarning() {
|
|
4552
|
+
this.getHttpClient().setClientSideWarning(false, "");
|
|
4553
|
+
}
|
|
4554
|
+
// endregion ////
|
|
4272
4555
|
get auth() {
|
|
4273
4556
|
return this.#authOAuthManager;
|
|
4274
4557
|
}
|
|
4558
|
+
// region Get ////
|
|
4559
|
+
/**
|
|
4560
|
+
* Get the account address BX24 ( https://name.bitrix24.com )
|
|
4561
|
+
*/
|
|
4275
4562
|
getTargetOrigin() {
|
|
4276
4563
|
this._ensureInitialized();
|
|
4277
4564
|
return this.#authOAuthManager.getTargetOrigin();
|
|
4278
4565
|
}
|
|
4566
|
+
/**
|
|
4567
|
+
* Get the account address BX24 with Path ( https://name.bitrix24.com/rest/1/xxxxx )
|
|
4568
|
+
*/
|
|
4279
4569
|
getTargetOriginWithPath() {
|
|
4280
4570
|
this._ensureInitialized();
|
|
4281
4571
|
return this.#authOAuthManager.getTargetOriginWithPath();
|
|
4282
4572
|
}
|
|
4573
|
+
// endregion ////
|
|
4574
|
+
// region Tools ////
|
|
4575
|
+
// endregion ////
|
|
4283
4576
|
}
|
|
4284
4577
|
|
|
4285
4578
|
class UnhandledMatchError extends Error {
|
|
@@ -13746,5 +14039,5 @@ async function initializeB24Frame() {
|
|
|
13746
14039
|
});
|
|
13747
14040
|
}
|
|
13748
14041
|
|
|
13749
|
-
export { AbstractB24, AjaxError, AjaxResult, AppFrame, AuthHookManager, AuthManager, AuthOAuthManager, B24Frame, B24Hook, B24LangList, B24OAuth, PullClient as B24PullClientManager, Browser, CatalogProductImageType, CatalogProductType, CatalogRoundingRuleType, CloseReasons, ConnectionType, DataType, DialogManager, EnumAppStatus, EnumCrmEntityType, EnumCrmEntityTypeId, EnumCrmEntityTypeShort, ListRpcError, LoadDataType, LoggerBrowser, LoggerType, LsKeys, MessageCommands, MessageManager, OptionsManager$1 as OptionsManager, ParentManager, PlacementManager, ProductRowDiscountTypeId, PullStatus, RestrictionManagerParamsBase, RestrictionManagerParamsForEnterprise, Result, RpcMethod, SenderType, ServerMode, SliderManager, StatusDescriptions, SubscriptionType, SystemCommands, Text, Type, TypeOption, TypeSpecificUrl, initializeB24Frame, isArrayOfArray, omit, pick, useB24Helper, useFormatter };
|
|
14042
|
+
export { AbstractB24, AjaxError, AjaxResult, AppFrame, AuthHookManager, AuthManager, AuthOAuthManager, B24Frame, B24Hook, B24LangList, B24LocaleMap, B24OAuth, PullClient as B24PullClientManager, Browser, CatalogProductImageType, CatalogProductType, CatalogRoundingRuleType, CloseReasons, ConnectionType, DataType, DialogManager, EnumAppStatus, EnumBitrix24Edition, EnumBizprocBaseType, EnumBizprocDocumentType, EnumCrmEntityType, EnumCrmEntityTypeId, EnumCrmEntityTypeShort, ListRpcError, LoadDataType, LoggerBrowser, LoggerType, LsKeys, MessageCommands, MessageManager, OptionsManager$1 as OptionsManager, ParentManager, PlacementManager, ProductRowDiscountTypeId, PullStatus, RestrictionManagerParamsBase, RestrictionManagerParamsForEnterprise, Result, RpcMethod, SenderType, ServerMode, SliderManager, StatusDescriptions, SubscriptionType, SystemCommands, Text, Type, TypeOption, TypeSpecificUrl, convertBizprocDocumentTypeToCrmEntityTypeId, getDocumentId, getDocumentType, getDocumentTypeForFilter, getEnumCrmEntityTypeShort, getEnumValue, initializeB24Frame, isArrayOfArray, omit, pick, useB24Helper, useFormatter };
|
|
13750
14043
|
//# sourceMappingURL=index.mjs.map
|