@bitrix24/b24jssdk 0.4.3 → 0.4.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.4.3
2
+ * @version @bitrix24/b24jssdk v0.4.5
3
3
  * @copyright (c) 2025 Bitrix24
4
4
  * @licence MIT
5
5
  * @links https://github.com/bitrix24/b24jssdk - GitHub
@@ -169,7 +169,7 @@ var DataType = /* @__PURE__ */ ((DataType2) => {
169
169
  return DataType2;
170
170
  })(DataType || {});
171
171
 
172
- const objectCtorString = Function.prototype.toString.call(Object);
172
+ const OBJECT_CONSTRUCTOR_STRING = Function.prototype.toString.call(Object);
173
173
  class TypeManager {
174
174
  getTag(value) {
175
175
  return Object.prototype.toString.call(value);
@@ -182,10 +182,7 @@ class TypeManager {
182
182
  * @memo get from pull.client.Utils
183
183
  */
184
184
  isString(value) {
185
- return value === "" ? true : (
186
- // eslint-disable-next-line unicorn/no-nested-ternary
187
- value ? typeof value === "string" || value instanceof String : false
188
- );
185
+ return typeof value === "string" || value instanceof String;
189
186
  }
190
187
  /**
191
188
  * Returns true if a value is not an empty string
@@ -202,14 +199,19 @@ class TypeManager {
202
199
  *
203
200
  * @memo get from pull.client.Utils
204
201
  */
202
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
205
203
  isFunction(value) {
206
- return value === null ? false : typeof value === "function" || value instanceof Function;
204
+ return value === null ? false : (
205
+ // eslint-disable-next-line unicorn/no-instanceof-builtins
206
+ typeof value === "function" || value instanceof Function
207
+ );
207
208
  }
208
209
  /**
209
210
  * Checks that value is an object
210
211
  * @param value
211
212
  * @return {boolean}
212
213
  */
214
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
213
215
  isObject(value) {
214
216
  return !!value && (typeof value === "object" || typeof value === "function");
215
217
  }
@@ -235,7 +237,7 @@ class TypeManager {
235
237
  return true;
236
238
  }
237
239
  const ctor = proto.hasOwnProperty("constructor") && proto.constructor;
238
- return typeof ctor === "function" && Function.prototype.toString.call(ctor) === objectCtorString;
240
+ return typeof ctor === "function" && Function.prototype.toString.call(ctor) === OBJECT_CONSTRUCTOR_STRING;
239
241
  }
240
242
  isJsonRpcRequest(value) {
241
243
  return typeof value === "object" && value && "jsonrpc" in value && this.isStringFilled(value.jsonrpc) && "method" in value && this.isStringFilled(value.method);
@@ -257,7 +259,7 @@ class TypeManager {
257
259
  * @return {boolean}
258
260
  */
259
261
  isNumber(value) {
260
- return !Number.isNaN(value) && typeof value === "number";
262
+ return typeof value === "number" && !Number.isNaN(value);
261
263
  }
262
264
  /**
263
265
  * Checks that value is integer
@@ -265,7 +267,7 @@ class TypeManager {
265
267
  * @return {boolean}
266
268
  */
267
269
  isInteger(value) {
268
- return this.isNumber(value) && value % 1 === 0;
270
+ return Number.isInteger(value);
269
271
  }
270
272
  /**
271
273
  * Checks that value is float
@@ -313,7 +315,7 @@ class TypeManager {
313
315
  * @return {boolean}
314
316
  */
315
317
  isDate(value) {
316
- return this.isObjectLike(value) && this.getTag(value) === "[object Date]";
318
+ return value instanceof Date;
317
319
  }
318
320
  /**
319
321
  * Checks that is a DOM node
@@ -442,12 +444,15 @@ class TypeManager {
442
444
  * @return {boolean}
443
445
  */
444
446
  isFormData(value) {
445
- return value instanceof FormData;
447
+ if (typeof FormData !== "undefined" && value instanceof FormData) {
448
+ return true;
449
+ }
450
+ return this.isObjectLike(value) && this.getTag(value) === "[object FormData]";
446
451
  }
447
452
  clone(obj, bCopyObj = true) {
448
453
  let _obj, i, l;
449
- if (obj === null) {
450
- return null;
454
+ if (this.isNil(obj) || typeof obj !== "object") {
455
+ return obj;
451
456
  }
452
457
  if (this.isDomNode(obj)) {
453
458
  _obj = obj.cloneNode(bCopyObj);
@@ -1678,7 +1683,7 @@ class Http {
1678
1683
  #clientSideWarningMessage = "";
1679
1684
  constructor(baseURL, authActions, options) {
1680
1685
  const defaultHeaders = {
1681
- // 'X-Sdk': 'b24-js-sdk-v-0.4.3'
1686
+ // 'X-Sdk': 'b24-js-sdk-v-0.4.5'
1682
1687
  };
1683
1688
  this.#clientAxios = axios.create({
1684
1689
  baseURL,
@@ -1743,19 +1748,21 @@ class Http {
1743
1748
  }
1744
1749
  // endregion ////
1745
1750
  // region Actions Call ////
1746
- async batch(calls, isHaltOnError = true) {
1751
+ async batch(calls, isHaltOnError = true, returnAjaxResult = false) {
1747
1752
  if (Array.isArray(calls)) {
1748
1753
  return this.#batchAsArray(
1749
1754
  calls,
1750
- isHaltOnError
1755
+ isHaltOnError,
1756
+ returnAjaxResult
1751
1757
  );
1752
1758
  }
1753
1759
  return this.#batchAsObject(
1754
1760
  calls,
1755
- isHaltOnError
1761
+ isHaltOnError,
1762
+ returnAjaxResult
1756
1763
  );
1757
1764
  }
1758
- async #batchAsObject(calls, isHaltOnError = true) {
1765
+ async #batchAsObject(calls, isHaltOnError = true, returnAjaxResult = false) {
1759
1766
  const cmd = {};
1760
1767
  let cnt = 0;
1761
1768
  const processRow = (row, index) => {
@@ -1851,13 +1858,13 @@ class Http {
1851
1858
  }
1852
1859
  return Promise.reject(error);
1853
1860
  }
1854
- dataResult[key] = data.getData().result;
1861
+ dataResult[key] = returnAjaxResult ? data : data.getData().result;
1855
1862
  }
1856
1863
  result.setData(dataResult);
1857
1864
  return Promise.resolve(result);
1858
1865
  });
1859
1866
  }
1860
- async #batchAsArray(calls, isHaltOnError = true) {
1867
+ async #batchAsArray(calls, isHaltOnError = true, returnAjaxResult = false) {
1861
1868
  const cmd = [];
1862
1869
  let cnt = 0;
1863
1870
  const processRow = (row) => {
@@ -1954,7 +1961,7 @@ class Http {
1954
1961
  }
1955
1962
  return Promise.reject(error);
1956
1963
  }
1957
- dataResult.push(data.getData().result);
1964
+ dataResult.push(returnAjaxResult ? data : data.getData().result);
1958
1965
  }
1959
1966
  result.setData(dataResult);
1960
1967
  return Promise.resolve(result);
@@ -2106,7 +2113,7 @@ class Http {
2106
2113
  const baseUrl = `${encodeURIComponent(method)}.json`;
2107
2114
  const queryParams = new URLSearchParams({
2108
2115
  [this.#requestIdGenerator.getQueryStringParameterName()]: this.#requestIdGenerator.getRequestId(),
2109
- [this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.3",
2116
+ [this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.5",
2110
2117
  [this.#requestIdGenerator.getQueryStringSdkTypeParameterName()]: "b24-js-sdk"
2111
2118
  });
2112
2119
  return `${baseUrl}?${queryParams.toString()}`;
@@ -2254,8 +2261,8 @@ class AbstractB24 {
2254
2261
  /**
2255
2262
  * @inheritDoc
2256
2263
  */
2257
- async callBatch(calls, isHaltOnError = true) {
2258
- return this.getHttpClient().batch(calls, isHaltOnError);
2264
+ async callBatch(calls, isHaltOnError = true, returnAjaxResult = false) {
2265
+ return this.getHttpClient().batch(calls, isHaltOnError, returnAjaxResult);
2259
2266
  }
2260
2267
  chunkArray(array, chunkSize = 50) {
2261
2268
  const result = [];
@@ -2607,7 +2614,7 @@ class FormatterIban {
2607
2614
  * @returns {boolean} true if the passed IBAN is valid, false otherwise
2608
2615
  */
2609
2616
  isValid(iban) {
2610
- if (!this._isString(iban)) {
2617
+ if (!Type.isString(iban)) {
2611
2618
  return false;
2612
2619
  }
2613
2620
  iban = this.electronicFormat(iban);
@@ -2682,7 +2689,7 @@ class FormatterIban {
2682
2689
  * @param bban the BBAN to check the validity of
2683
2690
  */
2684
2691
  isValidBBAN(countryCode, bban) {
2685
- if (!this._isString(bban)) {
2692
+ if (!Type.isString(bban)) {
2686
2693
  return false;
2687
2694
  }
2688
2695
  if (!this._countries.has(countryCode)) {
@@ -2692,11 +2699,6 @@ class FormatterIban {
2692
2699
  return !!countryStructure && countryStructure.isValidBBAN(this.electronicFormat(bban));
2693
2700
  }
2694
2701
  // endregion ////
2695
- // region Tools ////
2696
- _isString(value) {
2697
- return typeof value == "string" || value instanceof String;
2698
- }
2699
- // endregion ////
2700
2702
  }
2701
2703
 
2702
2704
  const useFormatter = () => {
@@ -3246,6 +3248,35 @@ class B24Hook extends AbstractB24 {
3246
3248
  }
3247
3249
  // endregion ////
3248
3250
  // region Tools ////
3251
+ static fromWebhookUrl(url) {
3252
+ if (!url.trim()) {
3253
+ throw new Error("Webhook URL cannot be empty");
3254
+ }
3255
+ let parsedUrl;
3256
+ try {
3257
+ parsedUrl = new URL(url);
3258
+ } catch {
3259
+ throw new Error(`Invalid webhook URL format: ${url}`);
3260
+ }
3261
+ if (parsedUrl.protocol !== "https:") {
3262
+ throw new Error("Webhook requires HTTPS protocol");
3263
+ }
3264
+ const pathParts = parsedUrl.pathname.split("/").filter(Boolean);
3265
+ if (pathParts.length < 3 || pathParts[0] !== "rest") {
3266
+ throw new Error("Webhook URL must follow format: /rest/<userId>/<secret>");
3267
+ }
3268
+ const userIdStr = pathParts[1];
3269
+ const secret = pathParts[2];
3270
+ if (!/^\d+$/.test(userIdStr)) {
3271
+ throw new Error(`User ID must be numeric in webhook URL, received: ${userIdStr}`);
3272
+ }
3273
+ const userId = Number.parseInt(userIdStr, 10);
3274
+ return new B24Hook({
3275
+ b24Url: parsedUrl.origin,
3276
+ userId,
3277
+ secret
3278
+ });
3279
+ }
3249
3280
  // endregion ////
3250
3281
  }
3251
3282
 
@@ -11828,8 +11859,8 @@ class PullClient {
11828
11859
  if (!skipReconnectToLastSession && this._storage) {
11829
11860
  oldSession = this._storage.get(LS_SESSION, null);
11830
11861
  }
11831
- if (Type.isPlainObject(oldSession) && oldSession.hasOwnProperty("ttl") && oldSession.ttl >= now) {
11832
- this._session.mid = oldSession.mid;
11862
+ if (Type.isPlainObject(oldSession) && oldSession.hasOwnProperty("ttl") && oldSession["ttl"] >= now) {
11863
+ this._session.mid = oldSession["mid"];
11833
11864
  }
11834
11865
  this._starting = true;
11835
11866
  return this._startingPromise = new Promise((resolve, reject) => {
@@ -12652,22 +12683,22 @@ class PullClient {
12652
12683
  if (!Type.isPlainObject(config)) {
12653
12684
  return false;
12654
12685
  }
12655
- if (Number(config.server.config_timestamp) !== this._configTimestamp) {
12686
+ if (Number(config["server"].config_timestamp) !== this._configTimestamp) {
12656
12687
  return false;
12657
12688
  }
12658
12689
  const now = /* @__PURE__ */ new Date();
12659
- if (Type.isNumber(config.exp) && config.exp > 0 && config.exp < now.getTime() / 1e3) {
12690
+ if (Type.isNumber(config["exp"]) && config["exp"] > 0 && config["exp"] < now.getTime() / 1e3) {
12660
12691
  return false;
12661
12692
  }
12662
- const channelCount = Object.keys(config.channels).length;
12693
+ const channelCount = Object.keys(config["channels"]).length;
12663
12694
  if (channelCount === 0) {
12664
12695
  return false;
12665
12696
  }
12666
- for (const channelType in config.channels) {
12667
- if (!config.channels.hasOwnProperty(channelType)) {
12697
+ for (const channelType in config["channels"]) {
12698
+ if (!config["channels"].hasOwnProperty(channelType)) {
12668
12699
  continue;
12669
12700
  }
12670
- const channel = config.channels[channelType];
12701
+ const channel = config["channels"][channelType];
12671
12702
  const channelEnd = new Date(channel.end);
12672
12703
  if (channelEnd < now) {
12673
12704
  return false;