@bitrix24/b24jssdk 0.4.2 → 0.4.4
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 +392 -171
- package/dist/esm/index.d.ts +392 -171
- package/dist/esm/index.mjs +359 -37
- package/dist/esm/index.mjs.map +1 -1
- package/dist/umd/index.js +366 -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.4
|
|
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.4'
|
|
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.4",
|
|
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
|
|
@@ -15597,6 +15798,35 @@ ${this.stack}`;
|
|
|
15597
15798
|
}
|
|
15598
15799
|
// endregion ////
|
|
15599
15800
|
// region Tools ////
|
|
15801
|
+
static fromWebhookUrl(url) {
|
|
15802
|
+
if (!url.trim()) {
|
|
15803
|
+
throw new Error("Webhook URL cannot be empty");
|
|
15804
|
+
}
|
|
15805
|
+
let parsedUrl;
|
|
15806
|
+
try {
|
|
15807
|
+
parsedUrl = new URL(url);
|
|
15808
|
+
} catch {
|
|
15809
|
+
throw new Error(`Invalid webhook URL format: ${url}`);
|
|
15810
|
+
}
|
|
15811
|
+
if (parsedUrl.protocol !== "https:") {
|
|
15812
|
+
throw new Error("Webhook requires HTTPS protocol");
|
|
15813
|
+
}
|
|
15814
|
+
const pathParts = parsedUrl.pathname.split("/").filter(Boolean);
|
|
15815
|
+
if (pathParts.length < 3 || pathParts[0] !== "rest") {
|
|
15816
|
+
throw new Error("Webhook URL must follow format: /rest/<userId>/<secret>");
|
|
15817
|
+
}
|
|
15818
|
+
const userIdStr = pathParts[1];
|
|
15819
|
+
const secret = pathParts[2];
|
|
15820
|
+
if (!/^\d+$/.test(userIdStr)) {
|
|
15821
|
+
throw new Error(`User ID must be numeric in webhook URL, received: ${userIdStr}`);
|
|
15822
|
+
}
|
|
15823
|
+
const userId = Number.parseInt(userIdStr, 10);
|
|
15824
|
+
return new B24Hook({
|
|
15825
|
+
b24Url: parsedUrl.origin,
|
|
15826
|
+
userId,
|
|
15827
|
+
secret
|
|
15828
|
+
});
|
|
15829
|
+
}
|
|
15600
15830
|
// endregion ////
|
|
15601
15831
|
}
|
|
15602
15832
|
|
|
@@ -16698,13 +16928,18 @@ ${this.stack}`;
|
|
|
16698
16928
|
// endregion ////
|
|
16699
16929
|
}
|
|
16700
16930
|
|
|
16931
|
+
class RefreshTokenError extends AjaxError {
|
|
16932
|
+
}
|
|
16933
|
+
|
|
16701
16934
|
class AuthOAuthManager {
|
|
16935
|
+
#clientAxios;
|
|
16936
|
+
#callbackRefreshAuth = null;
|
|
16702
16937
|
#authOptions;
|
|
16703
16938
|
#oAuthSecret;
|
|
16704
16939
|
#authExpires = 0;
|
|
16705
16940
|
#domain;
|
|
16706
|
-
#b24Target;
|
|
16707
16941
|
#b24TargetRest;
|
|
16942
|
+
#b24Target;
|
|
16708
16943
|
// 'https://oauth.bitrix.info' ////
|
|
16709
16944
|
#oAuthTarget;
|
|
16710
16945
|
#isAdmin = null;
|
|
@@ -16713,9 +16948,15 @@ ${this.stack}`;
|
|
|
16713
16948
|
this.#oAuthSecret = Object.freeze(Object.assign({}, oAuthSecret));
|
|
16714
16949
|
this.#domain = this.#authOptions.domain.replaceAll("https://", "").replaceAll("http://", "").replace(/:(80|443)$/, "");
|
|
16715
16950
|
this.#b24TargetRest = this.#authOptions.clientEndpoint;
|
|
16716
|
-
this.#b24Target = this.#b24TargetRest.replace("/rest", "");
|
|
16951
|
+
this.#b24Target = this.#b24TargetRest.replace("/rest/", "");
|
|
16717
16952
|
this.#oAuthTarget = this.#authOptions.serverEndpoint.replace("/rest/", "");
|
|
16718
16953
|
this.#authExpires = this.#authOptions.expires * 1e3;
|
|
16954
|
+
this.#clientAxios = axios.create({
|
|
16955
|
+
baseURL: this.#oAuthTarget,
|
|
16956
|
+
headers: {
|
|
16957
|
+
"Content-Type": "application/json"
|
|
16958
|
+
}
|
|
16959
|
+
});
|
|
16719
16960
|
}
|
|
16720
16961
|
/**
|
|
16721
16962
|
* Returns authorization data
|
|
@@ -16730,40 +16971,81 @@ ${this.stack}`;
|
|
|
16730
16971
|
member_id: this.#authOptions.memberId
|
|
16731
16972
|
} : false;
|
|
16732
16973
|
}
|
|
16974
|
+
// region RefreshAuth ////
|
|
16733
16975
|
/**
|
|
16734
16976
|
* Updates authorization data
|
|
16735
16977
|
*/
|
|
16736
16978
|
async refreshAuth() {
|
|
16737
16979
|
try {
|
|
16738
|
-
const response = await
|
|
16739
|
-
|
|
16740
|
-
|
|
16741
|
-
"Content-Type": "application/json"
|
|
16742
|
-
},
|
|
16743
|
-
body: JSON.stringify({
|
|
16980
|
+
const response = await this.#clientAxios.get(
|
|
16981
|
+
"/oauth/token/",
|
|
16982
|
+
{
|
|
16744
16983
|
params: {
|
|
16745
|
-
client_id: this.#oAuthSecret.clientId,
|
|
16746
16984
|
grant_type: "refresh_token",
|
|
16985
|
+
client_id: this.#oAuthSecret.clientId,
|
|
16747
16986
|
client_secret: this.#oAuthSecret.clientSecret,
|
|
16748
16987
|
refresh_token: this.#authOptions.refreshToken
|
|
16749
16988
|
}
|
|
16750
|
-
}
|
|
16751
|
-
|
|
16752
|
-
if (
|
|
16753
|
-
throw new Error(`Token update error: ${response.
|
|
16989
|
+
}
|
|
16990
|
+
);
|
|
16991
|
+
if (response.data.error) {
|
|
16992
|
+
throw new Error(`Token update error: ${response.data.error}`);
|
|
16993
|
+
}
|
|
16994
|
+
if (response.status !== 200) {
|
|
16995
|
+
throw new Error(`Token update error status code: ${response.status}`);
|
|
16754
16996
|
}
|
|
16755
|
-
const
|
|
16756
|
-
|
|
16757
|
-
|
|
16997
|
+
const payload = response.data;
|
|
16998
|
+
this.#authOptions.accessToken = payload.access_token;
|
|
16999
|
+
this.#authOptions.refreshToken = payload.refresh_token;
|
|
17000
|
+
this.#authOptions.expires = Number.parseInt(payload.expires || "0");
|
|
17001
|
+
this.#authOptions.expiresIn = Number.parseInt(payload.expires_in || "3600");
|
|
17002
|
+
this.#authOptions.clientEndpoint = payload.client_endpoint;
|
|
17003
|
+
this.#authOptions.serverEndpoint = payload.server_endpoint;
|
|
17004
|
+
this.#authOptions.scope = payload.scope;
|
|
17005
|
+
this.#authOptions.status = Object.values(EnumAppStatus).find((value) => value === payload.status) || EnumAppStatus.Free;
|
|
17006
|
+
this.#authExpires = this.#authOptions.expires * 1e3;
|
|
17007
|
+
const authData = this.getAuthData();
|
|
17008
|
+
if (this.#callbackRefreshAuth) {
|
|
17009
|
+
await this.#callbackRefreshAuth({ authData, b24OAuthParams: this.#authOptions });
|
|
16758
17010
|
}
|
|
16759
|
-
|
|
16760
|
-
this.#authOptions.refreshToken = data.refresh_token;
|
|
16761
|
-
this.#authExpires = data.expires * 1e3;
|
|
17011
|
+
return authData;
|
|
16762
17012
|
} catch (error) {
|
|
16763
|
-
|
|
17013
|
+
if (error instanceof AxiosError) {
|
|
17014
|
+
let answerError = {
|
|
17015
|
+
error: error?.code || 0,
|
|
17016
|
+
errorDescription: error?.message || ""
|
|
17017
|
+
};
|
|
17018
|
+
if (error.response && error.response.data && !Type.isUndefined(error.response.data.error)) {
|
|
17019
|
+
const response = error.response.data;
|
|
17020
|
+
answerError = {
|
|
17021
|
+
error: response.error,
|
|
17022
|
+
errorDescription: response.error_description
|
|
17023
|
+
};
|
|
17024
|
+
}
|
|
17025
|
+
throw new RefreshTokenError({
|
|
17026
|
+
code: String(answerError.error),
|
|
17027
|
+
description: answerError.errorDescription,
|
|
17028
|
+
status: error.response?.status || 0,
|
|
17029
|
+
requestInfo: {
|
|
17030
|
+
method: "/oauth/token/"
|
|
17031
|
+
}
|
|
17032
|
+
});
|
|
17033
|
+
} else if (error instanceof Error) {
|
|
17034
|
+
throw error;
|
|
17035
|
+
}
|
|
17036
|
+
throw new Error(
|
|
17037
|
+
`Strange error: ${error instanceof Error ? error.message : error}`,
|
|
17038
|
+
{ cause: error }
|
|
17039
|
+
);
|
|
16764
17040
|
}
|
|
16765
|
-
return this.getAuthData();
|
|
16766
17041
|
}
|
|
17042
|
+
setCallbackRefreshAuth(cb) {
|
|
17043
|
+
this.#callbackRefreshAuth = cb;
|
|
17044
|
+
}
|
|
17045
|
+
removeCallbackRefreshAuth() {
|
|
17046
|
+
this.#callbackRefreshAuth = null;
|
|
17047
|
+
}
|
|
17048
|
+
// endregion ////
|
|
16767
17049
|
getUniq(prefix) {
|
|
16768
17050
|
return [prefix, this.#authOptions.memberId || ""].join("_");
|
|
16769
17051
|
}
|
|
@@ -16802,6 +17084,7 @@ ${this.stack}`;
|
|
|
16802
17084
|
|
|
16803
17085
|
class B24OAuth extends AbstractB24 {
|
|
16804
17086
|
#authOAuthManager;
|
|
17087
|
+
// region Init ////
|
|
16805
17088
|
constructor(authOptions, oAuthSecret) {
|
|
16806
17089
|
super();
|
|
16807
17090
|
this.#authOAuthManager = new AuthOAuthManager(authOptions, oAuthSecret);
|
|
@@ -16810,28 +17093,67 @@ ${this.stack}`;
|
|
|
16810
17093
|
this.#authOAuthManager,
|
|
16811
17094
|
this._getHttpOptions()
|
|
16812
17095
|
);
|
|
17096
|
+
this._http.setClientSideWarning(
|
|
17097
|
+
true,
|
|
17098
|
+
"It is not safe to use oauth requests on the client side"
|
|
17099
|
+
);
|
|
16813
17100
|
this._isInit = true;
|
|
16814
17101
|
}
|
|
17102
|
+
setLogger(logger) {
|
|
17103
|
+
super.setLogger(logger);
|
|
17104
|
+
}
|
|
17105
|
+
/**
|
|
17106
|
+
* Used to initialize information about the current user.
|
|
17107
|
+
*/
|
|
16815
17108
|
async initIsAdmin() {
|
|
16816
|
-
|
|
16817
|
-
throw new Error("Http Not init");
|
|
16818
|
-
}
|
|
17109
|
+
this._ensureInitialized();
|
|
16819
17110
|
return this.#authOAuthManager.initIsAdmin(this._http);
|
|
16820
17111
|
}
|
|
16821
|
-
|
|
16822
|
-
|
|
17112
|
+
/**
|
|
17113
|
+
* Sets an asynchronous Callback to receive updated authorization data
|
|
17114
|
+
* @param cb
|
|
17115
|
+
*/
|
|
17116
|
+
setCallbackRefreshAuth(cb) {
|
|
17117
|
+
this._ensureInitialized();
|
|
17118
|
+
this.#authOAuthManager.setCallbackRefreshAuth(cb);
|
|
17119
|
+
}
|
|
17120
|
+
/**
|
|
17121
|
+
* Removes Callback to receive updated authorization data
|
|
17122
|
+
*/
|
|
17123
|
+
removeCallbackRefreshAuth() {
|
|
17124
|
+
this._ensureInitialized();
|
|
17125
|
+
this.#authOAuthManager.removeCallbackRefreshAuth();
|
|
16823
17126
|
}
|
|
17127
|
+
// endregion ////
|
|
17128
|
+
// region Core ////
|
|
17129
|
+
/**
|
|
17130
|
+
* Disables warning about client-side query execution
|
|
17131
|
+
*/
|
|
17132
|
+
offClientSideWarning() {
|
|
17133
|
+
this.getHttpClient().setClientSideWarning(false, "");
|
|
17134
|
+
}
|
|
17135
|
+
// endregion ////
|
|
16824
17136
|
get auth() {
|
|
16825
17137
|
return this.#authOAuthManager;
|
|
16826
17138
|
}
|
|
17139
|
+
// region Get ////
|
|
17140
|
+
/**
|
|
17141
|
+
* Get the account address BX24 ( https://name.bitrix24.com )
|
|
17142
|
+
*/
|
|
16827
17143
|
getTargetOrigin() {
|
|
16828
17144
|
this._ensureInitialized();
|
|
16829
17145
|
return this.#authOAuthManager.getTargetOrigin();
|
|
16830
17146
|
}
|
|
17147
|
+
/**
|
|
17148
|
+
* Get the account address BX24 with Path ( https://name.bitrix24.com/rest/1/xxxxx )
|
|
17149
|
+
*/
|
|
16831
17150
|
getTargetOriginWithPath() {
|
|
16832
17151
|
this._ensureInitialized();
|
|
16833
17152
|
return this.#authOAuthManager.getTargetOriginWithPath();
|
|
16834
17153
|
}
|
|
17154
|
+
// endregion ////
|
|
17155
|
+
// region Tools ////
|
|
17156
|
+
// endregion ////
|
|
16835
17157
|
}
|
|
16836
17158
|
|
|
16837
17159
|
class UnhandledMatchError extends Error {
|
|
@@ -26308,6 +26630,7 @@ Data string: ${pullEvent}
|
|
|
26308
26630
|
exports.B24Frame = B24Frame;
|
|
26309
26631
|
exports.B24Hook = B24Hook;
|
|
26310
26632
|
exports.B24LangList = B24LangList;
|
|
26633
|
+
exports.B24LocaleMap = B24LocaleMap;
|
|
26311
26634
|
exports.B24OAuth = B24OAuth;
|
|
26312
26635
|
exports.B24PullClientManager = PullClient;
|
|
26313
26636
|
exports.Browser = Browser;
|
|
@@ -26319,6 +26642,9 @@ Data string: ${pullEvent}
|
|
|
26319
26642
|
exports.DataType = DataType;
|
|
26320
26643
|
exports.DialogManager = DialogManager;
|
|
26321
26644
|
exports.EnumAppStatus = EnumAppStatus;
|
|
26645
|
+
exports.EnumBitrix24Edition = EnumBitrix24Edition;
|
|
26646
|
+
exports.EnumBizprocBaseType = EnumBizprocBaseType;
|
|
26647
|
+
exports.EnumBizprocDocumentType = EnumBizprocDocumentType;
|
|
26322
26648
|
exports.EnumCrmEntityType = EnumCrmEntityType;
|
|
26323
26649
|
exports.EnumCrmEntityTypeId = EnumCrmEntityTypeId;
|
|
26324
26650
|
exports.EnumCrmEntityTypeShort = EnumCrmEntityTypeShort;
|
|
@@ -26348,6 +26674,12 @@ Data string: ${pullEvent}
|
|
|
26348
26674
|
exports.Type = Type;
|
|
26349
26675
|
exports.TypeOption = TypeOption;
|
|
26350
26676
|
exports.TypeSpecificUrl = TypeSpecificUrl;
|
|
26677
|
+
exports.convertBizprocDocumentTypeToCrmEntityTypeId = convertBizprocDocumentTypeToCrmEntityTypeId;
|
|
26678
|
+
exports.getDocumentId = getDocumentId;
|
|
26679
|
+
exports.getDocumentType = getDocumentType;
|
|
26680
|
+
exports.getDocumentTypeForFilter = getDocumentTypeForFilter;
|
|
26681
|
+
exports.getEnumCrmEntityTypeShort = getEnumCrmEntityTypeShort;
|
|
26682
|
+
exports.getEnumValue = getEnumValue;
|
|
26351
26683
|
exports.initializeB24Frame = initializeB24Frame;
|
|
26352
26684
|
exports.isArrayOfArray = isArrayOfArray;
|
|
26353
26685
|
exports.omit = omit;
|