@bitrix24/b24jssdk 0.4.0 → 0.4.1

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,12 +1,11 @@
1
1
  /**
2
- * @version @bitrix24/b24jssdk v0.4.0
2
+ * @version @bitrix24/b24jssdk v0.4.1
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';
10
9
  import axios, { AxiosError } from 'axios';
11
10
  import * as qs from 'qs-esm';
12
11
 
@@ -509,28 +508,19 @@ function isArrayOfArray(item) {
509
508
  }
510
509
 
511
510
  const _state = {};
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");
511
+ function getCrypto() {
512
+ if (typeof window !== "undefined" && window.crypto) {
513
+ return window.crypto;
528
514
  }
515
+ if (typeof globalThis.crypto !== "undefined") {
516
+ return globalThis.crypto;
517
+ }
518
+ throw new Error("Crypto API not available");
529
519
  }
530
- function initRngBrowser() {
531
- const crypto = window.crypto || window.msCrypto;
520
+ function initRng() {
521
+ const crypto = getCrypto();
532
522
  if (!crypto?.getRandomValues) {
533
- throw new Error("Web Crypto API not available");
523
+ throw new Error("Crypto API not available");
534
524
  }
535
525
  return {
536
526
  rng: () => {
@@ -585,19 +575,12 @@ function v7Bytes(randoms, msecs, seq, buf, offset = 0) {
585
575
  function unsafeStringify(arr, offset = 0) {
586
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();
587
577
  }
588
- function uuidv7Node() {
578
+ function uuidv7() {
589
579
  const buf = void 0;
590
580
  const offset = void 0;
591
- let rngFunction;
592
581
  const now = Date.now();
593
- if (isBrowser) {
594
- const { rng } = initRngBrowser();
595
- rngFunction = rng;
596
- } else {
597
- const { rng } = initRng();
598
- rngFunction = rng;
599
- }
600
- const randoms = rngFunction();
582
+ const { rng } = initRng();
583
+ const randoms = rng();
601
584
  updateV7State(_state, now, randoms);
602
585
  const bytes = v7Bytes(
603
586
  randoms,
@@ -649,7 +632,7 @@ class TextManager {
649
632
  * @return {string}
650
633
  */
651
634
  getUuidRfc4122() {
652
- return uuidv7Node();
635
+ return uuidv7();
653
636
  }
654
637
  /**
655
638
  * Encodes all unsafe entities
@@ -1564,7 +1547,7 @@ class Http {
1564
1547
  #clientSideWarningMessage = "";
1565
1548
  constructor(baseURL, authActions, options) {
1566
1549
  const defaultHeaders = {
1567
- // 'X-Sdk': 'b24-js-sdk-v-0.4.0'
1550
+ // 'X-Sdk': 'b24-js-sdk-v-0.4.1'
1568
1551
  };
1569
1552
  this.#clientAxios = axios.create({
1570
1553
  baseURL,
@@ -1992,7 +1975,7 @@ class Http {
1992
1975
  const baseUrl = `${encodeURIComponent(method)}.json`;
1993
1976
  const queryParams = new URLSearchParams({
1994
1977
  [this.#requestIdGenerator.getQueryStringParameterName()]: this.#requestIdGenerator.getRequestId(),
1995
- [this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.0",
1978
+ [this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.1",
1996
1979
  [this.#requestIdGenerator.getQueryStringSdkTypeParameterName()]: "b24-js-sdk"
1997
1980
  });
1998
1981
  return `${baseUrl}?${queryParams.toString()}`;