@bitrix24/b24jssdk 0.1.4 → 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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @version @bitrix24/b24jssdk v0.1.4
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
@@ -1339,7 +1339,10 @@ class Http {
1339
1339
  #restrictionManager;
1340
1340
  #requestIdGenerator;
1341
1341
  _logger = null;
1342
+ _loggerSystem = null;
1342
1343
  #logTag = "";
1344
+ #isClientSideWarning = false;
1345
+ #clientSideWarningMessage = "";
1343
1346
  constructor(baseURL, authActions, options) {
1344
1347
  this.#clientAxios = axios.create({
1345
1348
  baseURL,
@@ -1349,6 +1352,7 @@ class Http {
1349
1352
  this.#restrictionManager = new RestrictionManager();
1350
1353
  this.#requestIdGenerator = new DefaultRequestIdGenerator();
1351
1354
  }
1355
+ // region Logger ////
1352
1356
  setLogger(logger) {
1353
1357
  this._logger = logger;
1354
1358
  this.#restrictionManager.setLogger(this.getLogger());
@@ -1367,18 +1371,38 @@ class Http {
1367
1371
  }
1368
1372
  return this._logger;
1369
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 ////
1370
1390
  setRestrictionManagerParams(params) {
1371
1391
  this.#restrictionManager.params = params;
1372
1392
  }
1373
1393
  getRestrictionManagerParams() {
1374
1394
  return this.#restrictionManager.params;
1375
1395
  }
1396
+ // endregion ////
1397
+ // region LogTag ////
1376
1398
  setLogTag(logTag) {
1377
1399
  this.#logTag = logTag;
1378
1400
  }
1379
1401
  clearLogTag() {
1380
1402
  this.#logTag = "";
1381
1403
  }
1404
+ // endregion ////
1405
+ // region Actions Call ////
1382
1406
  async batch(calls, isHaltOnError = true) {
1383
1407
  const isArrayMode = Array.isArray(calls);
1384
1408
  const cmd = isArrayMode ? [] : {};
@@ -1520,6 +1544,9 @@ class Http {
1520
1544
  authData = await this.#authActions.refreshAuth();
1521
1545
  }
1522
1546
  await this.#restrictionManager.check();
1547
+ if (this.#isClientSideWarning && !this.isServerSide() && Type.isStringFilled(this.#clientSideWarningMessage)) {
1548
+ this.getSystemLogger().warn(this.#clientSideWarningMessage);
1549
+ }
1523
1550
  return this.#clientAxios.post(
1524
1551
  this.#prepareMethod(method),
1525
1552
  this.#prepareParams(authData, params, start)
@@ -1603,6 +1630,8 @@ class Http {
1603
1630
  return Promise.resolve(result);
1604
1631
  });
1605
1632
  }
1633
+ // endregion ////
1634
+ // region Prepare ////
1606
1635
  /**
1607
1636
  * Processes function parameters and adds authorization
1608
1637
  *
@@ -1618,7 +1647,7 @@ class Http {
1618
1647
  result.logTag = this.#logTag;
1619
1648
  }
1620
1649
  result[this.#requestIdGenerator.getQueryStringParameterName()] = this.#requestIdGenerator.getRequestId();
1621
- result[this.#requestIdGenerator.getQueryStringSdkParameterName()] = "0.1.4";
1650
+ result[this.#requestIdGenerator.getQueryStringSdkParameterName()] = "0.1.5";
1622
1651
  if (!!result.data && !!result.data.start) {
1623
1652
  delete result.data.start;
1624
1653
  }
@@ -1637,6 +1666,24 @@ class Http {
1637
1666
  #prepareMethod(method) {
1638
1667
  return `${encodeURIComponent(method)}.json`;
1639
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 ////
1640
1687
  }
1641
1688
 
1642
1689
  class AbstractB24 {
@@ -2691,6 +2738,10 @@ class B24Hook extends AbstractB24 {
2691
2738
  this.#authHookManager,
2692
2739
  this._getHttpOptions()
2693
2740
  );
2741
+ this._http.setClientSideWarning(
2742
+ true,
2743
+ "It is not safe to use hook requests on the client side"
2744
+ );
2694
2745
  this._isInit = true;
2695
2746
  }
2696
2747
  setLogger(logger) {
@@ -2701,6 +2752,12 @@ class B24Hook extends AbstractB24 {
2701
2752
  return this.#authHookManager;
2702
2753
  }
2703
2754
  // region Core ////
2755
+ /**
2756
+ * Disables warning about client-side query execution
2757
+ */
2758
+ offClientSideWarning() {
2759
+ this.getHttpClient().setClientSideWarning(false, "");
2760
+ }
2704
2761
  // endregion ////
2705
2762
  // region Get ////
2706
2763
  /**