@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/esm/index.d.mts +483 -164
- package/dist/esm/index.d.ts +483 -164
- package/dist/esm/index.mjs +470 -86
- package/dist/esm/index.mjs.map +1 -1
- package/dist/umd/index.js +481 -85
- 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 +3 -3
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,90 +506,48 @@ function omit(data, keys) {
|
|
|
506
506
|
function isArrayOfArray(item) {
|
|
507
507
|
return Array.isArray(item[0]);
|
|
508
508
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
function getCrypto() {
|
|
512
|
-
if (typeof window !== "undefined" && window.crypto) {
|
|
513
|
-
return window.crypto;
|
|
514
|
-
}
|
|
515
|
-
if (typeof globalThis.crypto !== "undefined") {
|
|
516
|
-
return globalThis.crypto;
|
|
517
|
-
}
|
|
518
|
-
throw new Error("Crypto API not available");
|
|
519
|
-
}
|
|
520
|
-
function initRng() {
|
|
521
|
-
const crypto = getCrypto();
|
|
522
|
-
if (!crypto?.getRandomValues) {
|
|
523
|
-
throw new Error("Crypto API not available");
|
|
524
|
-
}
|
|
525
|
-
return {
|
|
526
|
-
rng: () => {
|
|
527
|
-
const rnds8 = new Uint8Array(16);
|
|
528
|
-
return crypto.getRandomValues(rnds8);
|
|
529
|
-
}
|
|
530
|
-
};
|
|
509
|
+
function getEnumValue(enumObj, value) {
|
|
510
|
+
return Object.values(enumObj).includes(value) ? value : void 0;
|
|
531
511
|
}
|
|
512
|
+
|
|
532
513
|
const byteToHex = [];
|
|
533
514
|
for (let i = 0; i < 256; ++i) {
|
|
534
515
|
byteToHex.push((i + 256).toString(16).slice(1));
|
|
535
516
|
}
|
|
536
|
-
function
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
550
|
-
function v7Bytes(randoms, msecs, seq, buf, offset = 0) {
|
|
551
|
-
if (!buf) {
|
|
552
|
-
buf = new Uint8Array(16);
|
|
553
|
-
offset = 0;
|
|
554
|
-
}
|
|
555
|
-
msecs ??= Date.now();
|
|
556
|
-
seq ??= randoms[6] * 127 << 24 | randoms[7] << 16 | randoms[8] << 8 | randoms[9];
|
|
557
|
-
buf[offset++] = msecs / 1099511627776 & 255;
|
|
558
|
-
buf[offset++] = msecs / 4294967296 & 255;
|
|
559
|
-
buf[offset++] = msecs / 16777216 & 255;
|
|
560
|
-
buf[offset++] = msecs / 65536 & 255;
|
|
561
|
-
buf[offset++] = msecs / 256 & 255;
|
|
562
|
-
buf[offset++] = msecs & 255;
|
|
563
|
-
buf[offset++] = 112 | seq >>> 28 & 15;
|
|
564
|
-
buf[offset++] = seq >>> 20 & 255;
|
|
565
|
-
buf[offset++] = 128 | seq >>> 14 & 63;
|
|
566
|
-
buf[offset++] = seq >>> 6 & 255;
|
|
567
|
-
buf[offset++] = seq << 2 & 255 | randoms[10] & 3;
|
|
568
|
-
buf[offset++] = randoms[11];
|
|
569
|
-
buf[offset++] = randoms[12];
|
|
570
|
-
buf[offset++] = randoms[13];
|
|
571
|
-
buf[offset++] = randoms[14];
|
|
572
|
-
buf[offset++] = randoms[15];
|
|
573
|
-
return buf;
|
|
574
|
-
}
|
|
575
|
-
function unsafeStringify(arr, offset = 0) {
|
|
576
|
-
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();
|
|
517
|
+
function sfc32(a, b, c, d) {
|
|
518
|
+
return () => {
|
|
519
|
+
a |= 0;
|
|
520
|
+
b |= 0;
|
|
521
|
+
c |= 0;
|
|
522
|
+
d |= 0;
|
|
523
|
+
const t = (a + b | 0) + d | 0;
|
|
524
|
+
d = d + 1 | 0;
|
|
525
|
+
a = b ^ b >>> 9;
|
|
526
|
+
b = c + (c << 3) | 0;
|
|
527
|
+
c = (c << 21 | c >>> 11) + t | 0;
|
|
528
|
+
return t >>> 0;
|
|
529
|
+
};
|
|
577
530
|
}
|
|
578
531
|
function uuidv7() {
|
|
579
|
-
const
|
|
580
|
-
const
|
|
581
|
-
const
|
|
582
|
-
const
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
);
|
|
592
|
-
|
|
532
|
+
const bytes = new Uint8Array(16);
|
|
533
|
+
const timestamp = BigInt(Date.now());
|
|
534
|
+
const perf = BigInt(Math.floor(performance.now() * 1e3) % 65535);
|
|
535
|
+
const combinedTime = timestamp << 16n | perf;
|
|
536
|
+
bytes[0] = Number(combinedTime >> 40n & 0xffn);
|
|
537
|
+
bytes[1] = Number(combinedTime >> 32n & 0xffn);
|
|
538
|
+
bytes[2] = Number(combinedTime >> 24n & 0xffn);
|
|
539
|
+
bytes[3] = Number(combinedTime >> 16n & 0xffn);
|
|
540
|
+
bytes[4] = Number(combinedTime >> 8n & 0xffn);
|
|
541
|
+
bytes[5] = Number(combinedTime & 0xffn);
|
|
542
|
+
const seed = (Math.random() * 4294967295 ^ Date.now() ^ performance.now()) >>> 0;
|
|
543
|
+
const rand = sfc32(2654435769, 608135816, 3084996962, seed);
|
|
544
|
+
const randView = new DataView(bytes.buffer);
|
|
545
|
+
randView.setUint32(6, rand());
|
|
546
|
+
randView.setUint32(10, rand());
|
|
547
|
+
randView.setUint16(14, rand());
|
|
548
|
+
bytes[6] = 112 | bytes[6] & 15;
|
|
549
|
+
bytes[8] = 128 | bytes[8] & 63;
|
|
550
|
+
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();
|
|
593
551
|
}
|
|
594
552
|
|
|
595
553
|
const reEscape = /[&<>'"]/g;
|
|
@@ -958,6 +916,10 @@ var EnumCrmEntityTypeShort = /* @__PURE__ */ ((EnumCrmEntityTypeShort2) => {
|
|
|
958
916
|
EnumCrmEntityTypeShort2["order"] = "O";
|
|
959
917
|
return EnumCrmEntityTypeShort2;
|
|
960
918
|
})(EnumCrmEntityTypeShort || {});
|
|
919
|
+
function getEnumCrmEntityTypeShort(id) {
|
|
920
|
+
const key = EnumCrmEntityTypeId[id];
|
|
921
|
+
return EnumCrmEntityTypeShort[key] || "?" /* undefined */;
|
|
922
|
+
}
|
|
961
923
|
|
|
962
924
|
var ProductRowDiscountTypeId = /* @__PURE__ */ ((ProductRowDiscountTypeId2) => {
|
|
963
925
|
ProductRowDiscountTypeId2[ProductRowDiscountTypeId2["undefined"] = 0] = "undefined";
|
|
@@ -991,6 +953,175 @@ var CatalogRoundingRuleType = /* @__PURE__ */ ((CatalogRoundingRuleType2) => {
|
|
|
991
953
|
return CatalogRoundingRuleType2;
|
|
992
954
|
})(CatalogRoundingRuleType || {});
|
|
993
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
|
+
|
|
994
1125
|
var LoadDataType = /* @__PURE__ */ ((LoadDataType2) => {
|
|
995
1126
|
LoadDataType2["App"] = "app";
|
|
996
1127
|
LoadDataType2["Profile"] = "profile";
|
|
@@ -1547,7 +1678,7 @@ class Http {
|
|
|
1547
1678
|
#clientSideWarningMessage = "";
|
|
1548
1679
|
constructor(baseURL, authActions, options) {
|
|
1549
1680
|
const defaultHeaders = {
|
|
1550
|
-
// 'X-Sdk': 'b24-js-sdk-v-0.4.
|
|
1681
|
+
// 'X-Sdk': 'b24-js-sdk-v-0.4.3'
|
|
1551
1682
|
};
|
|
1552
1683
|
this.#clientAxios = axios.create({
|
|
1553
1684
|
baseURL,
|
|
@@ -1975,7 +2106,7 @@ class Http {
|
|
|
1975
2106
|
const baseUrl = `${encodeURIComponent(method)}.json`;
|
|
1976
2107
|
const queryParams = new URLSearchParams({
|
|
1977
2108
|
[this.#requestIdGenerator.getQueryStringParameterName()]: this.#requestIdGenerator.getRequestId(),
|
|
1978
|
-
[this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.
|
|
2109
|
+
[this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.3",
|
|
1979
2110
|
[this.#requestIdGenerator.getQueryStringSdkTypeParameterName()]: "b24-js-sdk"
|
|
1980
2111
|
});
|
|
1981
2112
|
return `${baseUrl}?${queryParams.toString()}`;
|
|
@@ -2198,6 +2329,26 @@ var B24LangList = /* @__PURE__ */ ((B24LangList2) => {
|
|
|
2198
2329
|
B24LangList2["ar"] = "ar";
|
|
2199
2330
|
return B24LangList2;
|
|
2200
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
|
+
};
|
|
2201
2352
|
|
|
2202
2353
|
const useScrollSize = () => {
|
|
2203
2354
|
return {
|
|
@@ -2995,20 +3146,25 @@ const useFormatter = () => {
|
|
|
2995
3146
|
|
|
2996
3147
|
class AuthHookManager {
|
|
2997
3148
|
#b24HookParams;
|
|
3149
|
+
#domain;
|
|
3150
|
+
#b24TargetRest;
|
|
3151
|
+
#b24Target;
|
|
2998
3152
|
constructor(b24HookParams) {
|
|
2999
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}`;
|
|
3000
3157
|
}
|
|
3001
3158
|
/**
|
|
3002
3159
|
* @see Http.#prepareParams
|
|
3003
3160
|
*/
|
|
3004
3161
|
getAuthData() {
|
|
3005
|
-
const domain = this.#b24HookParams.b24Url.replaceAll("https://", "").replaceAll("http://", "").replace(/:(80|443)$/, "");
|
|
3006
3162
|
return {
|
|
3007
3163
|
access_token: this.#b24HookParams.secret,
|
|
3008
3164
|
refresh_token: "hook",
|
|
3009
3165
|
expires_in: 0,
|
|
3010
|
-
domain,
|
|
3011
|
-
member_id: domain
|
|
3166
|
+
domain: this.#domain,
|
|
3167
|
+
member_id: this.#domain
|
|
3012
3168
|
};
|
|
3013
3169
|
}
|
|
3014
3170
|
refreshAuth() {
|
|
@@ -3025,13 +3181,13 @@ class AuthHookManager {
|
|
|
3025
3181
|
* Get the account address BX24 ( https://name.bitrix24.com )
|
|
3026
3182
|
*/
|
|
3027
3183
|
getTargetOrigin() {
|
|
3028
|
-
return `${this.#
|
|
3184
|
+
return `${this.#b24Target}`;
|
|
3029
3185
|
}
|
|
3030
3186
|
/**
|
|
3031
3187
|
* Get the account address BX24 with Path ( https://name.bitrix24.com/rest/1/xxxxx )
|
|
3032
3188
|
*/
|
|
3033
3189
|
getTargetOriginWithPath() {
|
|
3034
|
-
return `${this.#
|
|
3190
|
+
return `${this.#b24TargetRest}/${this.#b24HookParams.userId}/${this.#b24HookParams.secret}`;
|
|
3035
3191
|
}
|
|
3036
3192
|
/**
|
|
3037
3193
|
* We believe that hooks are created only by the admin
|
|
@@ -4191,6 +4347,234 @@ class B24Frame extends AbstractB24 {
|
|
|
4191
4347
|
// endregion ////
|
|
4192
4348
|
}
|
|
4193
4349
|
|
|
4350
|
+
class RefreshTokenError extends AjaxError {
|
|
4351
|
+
}
|
|
4352
|
+
|
|
4353
|
+
class AuthOAuthManager {
|
|
4354
|
+
#clientAxios;
|
|
4355
|
+
#callbackRefreshAuth = null;
|
|
4356
|
+
#authOptions;
|
|
4357
|
+
#oAuthSecret;
|
|
4358
|
+
#authExpires = 0;
|
|
4359
|
+
#domain;
|
|
4360
|
+
#b24TargetRest;
|
|
4361
|
+
#b24Target;
|
|
4362
|
+
// 'https://oauth.bitrix.info' ////
|
|
4363
|
+
#oAuthTarget;
|
|
4364
|
+
#isAdmin = null;
|
|
4365
|
+
constructor(b24OAuthParams, oAuthSecret) {
|
|
4366
|
+
this.#authOptions = Object.assign({}, b24OAuthParams);
|
|
4367
|
+
this.#oAuthSecret = Object.freeze(Object.assign({}, oAuthSecret));
|
|
4368
|
+
this.#domain = this.#authOptions.domain.replaceAll("https://", "").replaceAll("http://", "").replace(/:(80|443)$/, "");
|
|
4369
|
+
this.#b24TargetRest = this.#authOptions.clientEndpoint;
|
|
4370
|
+
this.#b24Target = this.#b24TargetRest.replace("/rest/", "");
|
|
4371
|
+
this.#oAuthTarget = this.#authOptions.serverEndpoint.replace("/rest/", "");
|
|
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
|
+
});
|
|
4379
|
+
}
|
|
4380
|
+
/**
|
|
4381
|
+
* Returns authorization data
|
|
4382
|
+
* @see Http.#prepareParams
|
|
4383
|
+
*/
|
|
4384
|
+
getAuthData() {
|
|
4385
|
+
return this.#authExpires > Date.now() ? {
|
|
4386
|
+
access_token: this.#authOptions.accessToken,
|
|
4387
|
+
refresh_token: this.#authOptions.refreshToken,
|
|
4388
|
+
expires_in: this.#authOptions.expiresIn,
|
|
4389
|
+
domain: this.#domain,
|
|
4390
|
+
member_id: this.#authOptions.memberId
|
|
4391
|
+
} : false;
|
|
4392
|
+
}
|
|
4393
|
+
// region RefreshAuth ////
|
|
4394
|
+
/**
|
|
4395
|
+
* Updates authorization data
|
|
4396
|
+
*/
|
|
4397
|
+
async refreshAuth() {
|
|
4398
|
+
try {
|
|
4399
|
+
const response = await this.#clientAxios.get(
|
|
4400
|
+
"/oauth/token/",
|
|
4401
|
+
{
|
|
4402
|
+
params: {
|
|
4403
|
+
grant_type: "refresh_token",
|
|
4404
|
+
client_id: this.#oAuthSecret.clientId,
|
|
4405
|
+
client_secret: this.#oAuthSecret.clientSecret,
|
|
4406
|
+
refresh_token: this.#authOptions.refreshToken
|
|
4407
|
+
}
|
|
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;
|
|
4431
|
+
} catch (error) {
|
|
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
|
+
);
|
|
4459
|
+
}
|
|
4460
|
+
}
|
|
4461
|
+
setCallbackRefreshAuth(cb) {
|
|
4462
|
+
this.#callbackRefreshAuth = cb;
|
|
4463
|
+
}
|
|
4464
|
+
removeCallbackRefreshAuth() {
|
|
4465
|
+
this.#callbackRefreshAuth = null;
|
|
4466
|
+
}
|
|
4467
|
+
// endregion ////
|
|
4468
|
+
getUniq(prefix) {
|
|
4469
|
+
return [prefix, this.#authOptions.memberId || ""].join("_");
|
|
4470
|
+
}
|
|
4471
|
+
/**
|
|
4472
|
+
* Get the account address BX24 ( https://name.bitrix24.com )
|
|
4473
|
+
*/
|
|
4474
|
+
getTargetOrigin() {
|
|
4475
|
+
return `${this.#b24Target}`;
|
|
4476
|
+
}
|
|
4477
|
+
/**
|
|
4478
|
+
* Get the account address BX24 with Path ( https://name.bitrix24.com/rest )
|
|
4479
|
+
*/
|
|
4480
|
+
getTargetOriginWithPath() {
|
|
4481
|
+
return `${this.#b24TargetRest}`;
|
|
4482
|
+
}
|
|
4483
|
+
/**
|
|
4484
|
+
* Determines whether the current user has administrator rights
|
|
4485
|
+
*/
|
|
4486
|
+
get isAdmin() {
|
|
4487
|
+
if (null === this.#isAdmin) {
|
|
4488
|
+
throw new Error("isAdmin not init. You need call B24OAuth::initIsAdmin().");
|
|
4489
|
+
}
|
|
4490
|
+
return this.#isAdmin;
|
|
4491
|
+
}
|
|
4492
|
+
async initIsAdmin(http) {
|
|
4493
|
+
const response = await http.call("profile", {}, 0);
|
|
4494
|
+
if (!response.isSuccess) {
|
|
4495
|
+
throw new Error(response.getErrorMessages().join(";"));
|
|
4496
|
+
}
|
|
4497
|
+
const data = response.getData().result;
|
|
4498
|
+
if (data?.ADMIN) {
|
|
4499
|
+
this.#isAdmin = true;
|
|
4500
|
+
}
|
|
4501
|
+
}
|
|
4502
|
+
}
|
|
4503
|
+
|
|
4504
|
+
class B24OAuth extends AbstractB24 {
|
|
4505
|
+
#authOAuthManager;
|
|
4506
|
+
// region Init ////
|
|
4507
|
+
constructor(authOptions, oAuthSecret) {
|
|
4508
|
+
super();
|
|
4509
|
+
this.#authOAuthManager = new AuthOAuthManager(authOptions, oAuthSecret);
|
|
4510
|
+
this._http = new Http(
|
|
4511
|
+
this.#authOAuthManager.getTargetOriginWithPath(),
|
|
4512
|
+
this.#authOAuthManager,
|
|
4513
|
+
this._getHttpOptions()
|
|
4514
|
+
);
|
|
4515
|
+
this._http.setClientSideWarning(
|
|
4516
|
+
true,
|
|
4517
|
+
"It is not safe to use oauth requests on the client side"
|
|
4518
|
+
);
|
|
4519
|
+
this._isInit = true;
|
|
4520
|
+
}
|
|
4521
|
+
setLogger(logger) {
|
|
4522
|
+
super.setLogger(logger);
|
|
4523
|
+
}
|
|
4524
|
+
/**
|
|
4525
|
+
* Used to initialize information about the current user.
|
|
4526
|
+
*/
|
|
4527
|
+
async initIsAdmin() {
|
|
4528
|
+
this._ensureInitialized();
|
|
4529
|
+
return this.#authOAuthManager.initIsAdmin(this._http);
|
|
4530
|
+
}
|
|
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);
|
|
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 ////
|
|
4555
|
+
get auth() {
|
|
4556
|
+
return this.#authOAuthManager;
|
|
4557
|
+
}
|
|
4558
|
+
// region Get ////
|
|
4559
|
+
/**
|
|
4560
|
+
* Get the account address BX24 ( https://name.bitrix24.com )
|
|
4561
|
+
*/
|
|
4562
|
+
getTargetOrigin() {
|
|
4563
|
+
this._ensureInitialized();
|
|
4564
|
+
return this.#authOAuthManager.getTargetOrigin();
|
|
4565
|
+
}
|
|
4566
|
+
/**
|
|
4567
|
+
* Get the account address BX24 with Path ( https://name.bitrix24.com/rest/1/xxxxx )
|
|
4568
|
+
*/
|
|
4569
|
+
getTargetOriginWithPath() {
|
|
4570
|
+
this._ensureInitialized();
|
|
4571
|
+
return this.#authOAuthManager.getTargetOriginWithPath();
|
|
4572
|
+
}
|
|
4573
|
+
// endregion ////
|
|
4574
|
+
// region Tools ////
|
|
4575
|
+
// endregion ////
|
|
4576
|
+
}
|
|
4577
|
+
|
|
4194
4578
|
class UnhandledMatchError extends Error {
|
|
4195
4579
|
constructor(value, ...args) {
|
|
4196
4580
|
super(...args);
|
|
@@ -13655,5 +14039,5 @@ async function initializeB24Frame() {
|
|
|
13655
14039
|
});
|
|
13656
14040
|
}
|
|
13657
14041
|
|
|
13658
|
-
export { AbstractB24, AjaxError, AjaxResult, AppFrame, AuthHookManager, AuthManager, B24Frame, B24Hook, B24LangList, 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 };
|
|
13659
14043
|
//# sourceMappingURL=index.mjs.map
|