@bitrix24/b24jssdk 0.1.3 → 0.1.5
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/commonjs/index.cjs +76 -6
- package/dist/commonjs/index.cjs.map +1 -1
- package/dist/commonjs/index.d.cts +10 -0
- package/dist/commonjs/index.d.mts +10 -0
- package/dist/commonjs/index.d.ts +10 -0
- package/dist/esm/index.d.mts +10 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.mjs +60 -3
- package/dist/esm/index.mjs.map +1 -1
- package/dist/umd/index.js +1132 -2742
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/index.min.js +18 -21
- package/dist/umd/index.min.js.map +1 -1
- package/package.json +3 -4
package/dist/commonjs/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @version @bitrix24/b24jssdk v0.1.
|
|
2
|
+
* @version @bitrix24/b24jssdk v0.1.5
|
|
3
3
|
* @copyright (c) 2024 Bitrix24
|
|
4
4
|
* @licence MIT
|
|
5
5
|
* @links https://github.com/bitrix24/b24jssdk - GitHub
|
|
@@ -9,7 +9,20 @@
|
|
|
9
9
|
|
|
10
10
|
const luxon = require('luxon');
|
|
11
11
|
const axios = require('axios');
|
|
12
|
-
const qs = require('qs');
|
|
12
|
+
const qs = require('qs-esm');
|
|
13
|
+
|
|
14
|
+
function _interopNamespaceDefault(e) {
|
|
15
|
+
const n = Object.create(null);
|
|
16
|
+
if (e) {
|
|
17
|
+
for (const k in e) {
|
|
18
|
+
n[k] = e[k];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return n;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const qs__namespace = /*#__PURE__*/_interopNamespaceDefault(qs);
|
|
13
26
|
|
|
14
27
|
var LoggerType = /* @__PURE__ */ ((LoggerType2) => {
|
|
15
28
|
LoggerType2["desktop"] = "desktop";
|
|
@@ -1326,7 +1339,10 @@ class Http {
|
|
|
1326
1339
|
#restrictionManager;
|
|
1327
1340
|
#requestIdGenerator;
|
|
1328
1341
|
_logger = null;
|
|
1342
|
+
_loggerSystem = null;
|
|
1329
1343
|
#logTag = "";
|
|
1344
|
+
#isClientSideWarning = false;
|
|
1345
|
+
#clientSideWarningMessage = "";
|
|
1330
1346
|
constructor(baseURL, authActions, options) {
|
|
1331
1347
|
this.#clientAxios = axios.create({
|
|
1332
1348
|
baseURL,
|
|
@@ -1336,6 +1352,7 @@ class Http {
|
|
|
1336
1352
|
this.#restrictionManager = new RestrictionManager();
|
|
1337
1353
|
this.#requestIdGenerator = new DefaultRequestIdGenerator();
|
|
1338
1354
|
}
|
|
1355
|
+
// region Logger ////
|
|
1339
1356
|
setLogger(logger) {
|
|
1340
1357
|
this._logger = logger;
|
|
1341
1358
|
this.#restrictionManager.setLogger(this.getLogger());
|
|
@@ -1354,18 +1371,38 @@ class Http {
|
|
|
1354
1371
|
}
|
|
1355
1372
|
return this._logger;
|
|
1356
1373
|
}
|
|
1374
|
+
getSystemLogger() {
|
|
1375
|
+
if (null === this._loggerSystem) {
|
|
1376
|
+
this._loggerSystem = LoggerBrowser.build(`SystemLogger`);
|
|
1377
|
+
this._loggerSystem.setConfig({
|
|
1378
|
+
[LoggerType.desktop]: false,
|
|
1379
|
+
[LoggerType.log]: false,
|
|
1380
|
+
[LoggerType.info]: true,
|
|
1381
|
+
[LoggerType.warn]: true,
|
|
1382
|
+
[LoggerType.error]: true,
|
|
1383
|
+
[LoggerType.trace]: false
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
return this._loggerSystem;
|
|
1387
|
+
}
|
|
1388
|
+
// endregion ////
|
|
1389
|
+
// region RestrictionManager ////
|
|
1357
1390
|
setRestrictionManagerParams(params) {
|
|
1358
1391
|
this.#restrictionManager.params = params;
|
|
1359
1392
|
}
|
|
1360
1393
|
getRestrictionManagerParams() {
|
|
1361
1394
|
return this.#restrictionManager.params;
|
|
1362
1395
|
}
|
|
1396
|
+
// endregion ////
|
|
1397
|
+
// region LogTag ////
|
|
1363
1398
|
setLogTag(logTag) {
|
|
1364
1399
|
this.#logTag = logTag;
|
|
1365
1400
|
}
|
|
1366
1401
|
clearLogTag() {
|
|
1367
1402
|
this.#logTag = "";
|
|
1368
1403
|
}
|
|
1404
|
+
// endregion ////
|
|
1405
|
+
// region Actions Call ////
|
|
1369
1406
|
async batch(calls, isHaltOnError = true) {
|
|
1370
1407
|
const isArrayMode = Array.isArray(calls);
|
|
1371
1408
|
const cmd = isArrayMode ? [] : {};
|
|
@@ -1382,7 +1419,7 @@ class Http {
|
|
|
1382
1419
|
}
|
|
1383
1420
|
if (method) {
|
|
1384
1421
|
cnt++;
|
|
1385
|
-
const data = method + "?" +
|
|
1422
|
+
const data = method + "?" + qs__namespace.stringify(params);
|
|
1386
1423
|
if (isArrayMode || Array.isArray(cmd)) {
|
|
1387
1424
|
cmd.push(data);
|
|
1388
1425
|
} else {
|
|
@@ -1430,7 +1467,7 @@ class Http {
|
|
|
1430
1467
|
},
|
|
1431
1468
|
{
|
|
1432
1469
|
method: q[0] || "",
|
|
1433
|
-
params:
|
|
1470
|
+
params: qs__namespace.parse(q[1] || ""),
|
|
1434
1471
|
start: 0
|
|
1435
1472
|
},
|
|
1436
1473
|
response.getStatus()
|
|
@@ -1454,7 +1491,7 @@ class Http {
|
|
|
1454
1491
|
status: 0,
|
|
1455
1492
|
answerError: {
|
|
1456
1493
|
error: result2.getErrorMessages().join("; "),
|
|
1457
|
-
errorDescription: `batch ${result2.getQuery().method}: ${
|
|
1494
|
+
errorDescription: `batch ${result2.getQuery().method}: ${qs__namespace.stringify(result2.getQuery().params, { encode: false })}`
|
|
1458
1495
|
},
|
|
1459
1496
|
cause: result2.getErrors().next().value
|
|
1460
1497
|
});
|
|
@@ -1507,6 +1544,9 @@ class Http {
|
|
|
1507
1544
|
authData = await this.#authActions.refreshAuth();
|
|
1508
1545
|
}
|
|
1509
1546
|
await this.#restrictionManager.check();
|
|
1547
|
+
if (this.#isClientSideWarning && !this.isServerSide() && Type.isStringFilled(this.#clientSideWarningMessage)) {
|
|
1548
|
+
this.getSystemLogger().warn(this.#clientSideWarningMessage);
|
|
1549
|
+
}
|
|
1510
1550
|
return this.#clientAxios.post(
|
|
1511
1551
|
this.#prepareMethod(method),
|
|
1512
1552
|
this.#prepareParams(authData, params, start)
|
|
@@ -1590,6 +1630,8 @@ class Http {
|
|
|
1590
1630
|
return Promise.resolve(result);
|
|
1591
1631
|
});
|
|
1592
1632
|
}
|
|
1633
|
+
// endregion ////
|
|
1634
|
+
// region Prepare ////
|
|
1593
1635
|
/**
|
|
1594
1636
|
* Processes function parameters and adds authorization
|
|
1595
1637
|
*
|
|
@@ -1605,7 +1647,7 @@ class Http {
|
|
|
1605
1647
|
result.logTag = this.#logTag;
|
|
1606
1648
|
}
|
|
1607
1649
|
result[this.#requestIdGenerator.getQueryStringParameterName()] = this.#requestIdGenerator.getRequestId();
|
|
1608
|
-
result[this.#requestIdGenerator.getQueryStringSdkParameterName()] = "0.1.
|
|
1650
|
+
result[this.#requestIdGenerator.getQueryStringSdkParameterName()] = "0.1.5";
|
|
1609
1651
|
if (!!result.data && !!result.data.start) {
|
|
1610
1652
|
delete result.data.start;
|
|
1611
1653
|
}
|
|
@@ -1624,6 +1666,24 @@ class Http {
|
|
|
1624
1666
|
#prepareMethod(method) {
|
|
1625
1667
|
return `${encodeURIComponent(method)}.json`;
|
|
1626
1668
|
}
|
|
1669
|
+
/**
|
|
1670
|
+
* @inheritDoc
|
|
1671
|
+
*/
|
|
1672
|
+
setClientSideWarning(value, message) {
|
|
1673
|
+
this.#isClientSideWarning = value;
|
|
1674
|
+
this.#clientSideWarningMessage = message;
|
|
1675
|
+
}
|
|
1676
|
+
// endregion ////
|
|
1677
|
+
// region Tools ////
|
|
1678
|
+
/**
|
|
1679
|
+
* Tests whether the code is executed on the client side
|
|
1680
|
+
* @return {boolean}
|
|
1681
|
+
* @protected
|
|
1682
|
+
*/
|
|
1683
|
+
isServerSide() {
|
|
1684
|
+
return Type.isUndefined(window);
|
|
1685
|
+
}
|
|
1686
|
+
// endregion ////
|
|
1627
1687
|
}
|
|
1628
1688
|
|
|
1629
1689
|
class AbstractB24 {
|
|
@@ -2678,6 +2738,10 @@ class B24Hook extends AbstractB24 {
|
|
|
2678
2738
|
this.#authHookManager,
|
|
2679
2739
|
this._getHttpOptions()
|
|
2680
2740
|
);
|
|
2741
|
+
this._http.setClientSideWarning(
|
|
2742
|
+
true,
|
|
2743
|
+
"It is not safe to use hook requests on the client side"
|
|
2744
|
+
);
|
|
2681
2745
|
this._isInit = true;
|
|
2682
2746
|
}
|
|
2683
2747
|
setLogger(logger) {
|
|
@@ -2688,6 +2752,12 @@ class B24Hook extends AbstractB24 {
|
|
|
2688
2752
|
return this.#authHookManager;
|
|
2689
2753
|
}
|
|
2690
2754
|
// region Core ////
|
|
2755
|
+
/**
|
|
2756
|
+
* Disables warning about client-side query execution
|
|
2757
|
+
*/
|
|
2758
|
+
offClientSideWarning() {
|
|
2759
|
+
this.getHttpClient().setClientSideWarning(false, "");
|
|
2760
|
+
}
|
|
2691
2761
|
// endregion ////
|
|
2692
2762
|
// region Get ////
|
|
2693
2763
|
/**
|