@bitrix24/b24jssdk 0.3.0 → 0.4.0

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.
@@ -2825,9 +2825,6 @@ declare class PullClient implements ConnectorParent {
2825
2825
  private _debug;
2826
2826
  private _connectionAttempt;
2827
2827
  private _connectionType;
2828
- private _reconnectTimeout;
2829
- private _restartTimeout;
2830
- private _restoreWebSocketTimeout;
2831
2828
  private _skipStorageInit;
2832
2829
  private _skipCheckRevision;
2833
2830
  private _subscribers;
@@ -2846,6 +2843,9 @@ declare class PullClient implements ConnectorParent {
2846
2843
  /**
2847
2844
  * @depricate
2848
2845
  */
2846
+ private _reconnectTimeout;
2847
+ private _restartTimeout;
2848
+ private _restoreWebSocketTimeout;
2849
2849
  private _checkInterval;
2850
2850
  private _offlineTimeout;
2851
2851
  private _watchUpdateTimeout;
@@ -2825,9 +2825,6 @@ declare class PullClient implements ConnectorParent {
2825
2825
  private _debug;
2826
2826
  private _connectionAttempt;
2827
2827
  private _connectionType;
2828
- private _reconnectTimeout;
2829
- private _restartTimeout;
2830
- private _restoreWebSocketTimeout;
2831
2828
  private _skipStorageInit;
2832
2829
  private _skipCheckRevision;
2833
2830
  private _subscribers;
@@ -2846,6 +2843,9 @@ declare class PullClient implements ConnectorParent {
2846
2843
  /**
2847
2844
  * @depricate
2848
2845
  */
2846
+ private _reconnectTimeout;
2847
+ private _restartTimeout;
2848
+ private _restoreWebSocketTimeout;
2849
2849
  private _checkInterval;
2850
2850
  private _offlineTimeout;
2851
2851
  private _watchUpdateTimeout;
@@ -1,11 +1,12 @@
1
1
  /**
2
- * @version @bitrix24/b24jssdk v0.3.0
2
+ * @version @bitrix24/b24jssdk v0.4.0
3
3
  * @copyright (c) 2025 Bitrix24
4
4
  * @licence MIT
5
5
  * @links https://github.com/bitrix24/b24jssdk - GitHub
6
6
  * @links https://bitrix24.github.io/b24jssdk/ - Documentation
7
7
  */
8
8
  import { DateTime } from 'luxon';
9
+ import { randomFillSync } from 'node:crypto';
9
10
  import axios, { AxiosError } from 'axios';
10
11
  import * as qs from 'qs-esm';
11
12
 
@@ -508,8 +509,36 @@ function isArrayOfArray(item) {
508
509
  }
509
510
 
510
511
  const _state = {};
511
- let getRandomValues;
512
- const randoms8 = new Uint8Array(16);
512
+ const isBrowser = typeof window !== "undefined";
513
+ function initRng() {
514
+ try {
515
+ const rnds8Pool = new Uint8Array(256);
516
+ let poolPtr = rnds8Pool.length;
517
+ return {
518
+ rng: () => {
519
+ if (poolPtr > rnds8Pool.length - 16) {
520
+ randomFillSync(rnds8Pool);
521
+ poolPtr = 0;
522
+ }
523
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
524
+ }
525
+ };
526
+ } catch {
527
+ throw new Error("Node.js crypto module not available");
528
+ }
529
+ }
530
+ function initRngBrowser() {
531
+ const crypto = window.crypto || window.msCrypto;
532
+ if (!crypto?.getRandomValues) {
533
+ throw new Error("Web Crypto API not available");
534
+ }
535
+ return {
536
+ rng: () => {
537
+ const rnds8 = new Uint8Array(16);
538
+ return crypto.getRandomValues(rnds8);
539
+ }
540
+ };
541
+ }
513
542
  const byteToHex = [];
514
543
  for (let i = 0; i < 256; ++i) {
515
544
  byteToHex.push((i + 256).toString(16).slice(1));
@@ -556,17 +585,19 @@ function v7Bytes(randoms, msecs, seq, buf, offset = 0) {
556
585
  function unsafeStringify(arr, offset = 0) {
557
586
  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();
558
587
  }
559
- function uuidv7() {
588
+ function uuidv7Node() {
560
589
  const buf = void 0;
561
590
  const offset = void 0;
591
+ let rngFunction;
562
592
  const now = Date.now();
563
- if (!getRandomValues) {
564
- if (typeof crypto === "undefined" || !crypto.getRandomValues) {
565
- throw new Error("crypto.getRandomValues() not supported.");
566
- }
567
- getRandomValues = crypto.getRandomValues.bind(crypto);
593
+ if (isBrowser) {
594
+ const { rng } = initRngBrowser();
595
+ rngFunction = rng;
596
+ } else {
597
+ const { rng } = initRng();
598
+ rngFunction = rng;
568
599
  }
569
- const randoms = getRandomValues(randoms8);
600
+ const randoms = rngFunction();
570
601
  updateV7State(_state, now, randoms);
571
602
  const bytes = v7Bytes(
572
603
  randoms,
@@ -618,7 +649,7 @@ class TextManager {
618
649
  * @return {string}
619
650
  */
620
651
  getUuidRfc4122() {
621
- return uuidv7();
652
+ return uuidv7Node();
622
653
  }
623
654
  /**
624
655
  * Encodes all unsafe entities
@@ -1533,7 +1564,7 @@ class Http {
1533
1564
  #clientSideWarningMessage = "";
1534
1565
  constructor(baseURL, authActions, options) {
1535
1566
  const defaultHeaders = {
1536
- // 'X-Sdk': 'b24-js-sdk-v-0.3.0'
1567
+ // 'X-Sdk': 'b24-js-sdk-v-0.4.0'
1537
1568
  };
1538
1569
  this.#clientAxios = axios.create({
1539
1570
  baseURL,
@@ -1961,7 +1992,7 @@ class Http {
1961
1992
  const baseUrl = `${encodeURIComponent(method)}.json`;
1962
1993
  const queryParams = new URLSearchParams({
1963
1994
  [this.#requestIdGenerator.getQueryStringParameterName()]: this.#requestIdGenerator.getRequestId(),
1964
- [this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.3.0",
1995
+ [this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.0",
1965
1996
  [this.#requestIdGenerator.getQueryStringSdkTypeParameterName()]: "b24-js-sdk"
1966
1997
  });
1967
1998
  return `${baseUrl}?${queryParams.toString()}`;
@@ -11081,9 +11112,6 @@ class PullClient {
11081
11112
  _debug = false;
11082
11113
  _connectionAttempt = 0;
11083
11114
  _connectionType = ConnectionType.WebSocket;
11084
- _reconnectTimeout = null;
11085
- _restartTimeout = null;
11086
- _restoreWebSocketTimeout = null;
11087
11115
  _skipStorageInit;
11088
11116
  _skipCheckRevision;
11089
11117
  _subscribers = {};
@@ -11115,6 +11143,9 @@ class PullClient {
11115
11143
  */
11116
11144
  // private _notificationPopup: null = null
11117
11145
  // timers ////
11146
+ _reconnectTimeout = null;
11147
+ _restartTimeout = null;
11148
+ _restoreWebSocketTimeout = null;
11118
11149
  _checkInterval = null;
11119
11150
  _offlineTimeout = null;
11120
11151
  _watchUpdateTimeout = null;
@@ -12410,7 +12441,7 @@ class PullClient {
12410
12441
  return;
12411
12442
  }
12412
12443
  this._restoreWebSocketTimeout = setTimeout(() => {
12413
- this._restoreWebSocketTimeout = 0;
12444
+ this._restoreWebSocketTimeout = null;
12414
12445
  this.restoreWebSocketConnection();
12415
12446
  }, RESTORE_WEBSOCKET_TIMEOUT * 1e3);
12416
12447
  }