@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.
package/dist/umd/index.js CHANGED
@@ -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
@@ -171,7 +171,7 @@
171
171
  return DataType2;
172
172
  })(DataType || {});
173
173
 
174
- const objectCtorString = Function.prototype.toString.call(Object);
174
+ const OBJECT_CONSTRUCTOR_STRING = Function.prototype.toString.call(Object);
175
175
  class TypeManager {
176
176
  getTag(value) {
177
177
  return Object.prototype.toString.call(value);
@@ -184,10 +184,7 @@
184
184
  * @memo get from pull.client.Utils
185
185
  */
186
186
  isString(value) {
187
- return value === "" ? true : (
188
- // eslint-disable-next-line unicorn/no-nested-ternary
189
- value ? typeof value === "string" || value instanceof String : false
190
- );
187
+ return typeof value === "string" || value instanceof String;
191
188
  }
192
189
  /**
193
190
  * Returns true if a value is not an empty string
@@ -204,14 +201,19 @@
204
201
  *
205
202
  * @memo get from pull.client.Utils
206
203
  */
204
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
207
205
  isFunction(value) {
208
- return value === null ? false : typeof value === "function" || value instanceof Function;
206
+ return value === null ? false : (
207
+ // eslint-disable-next-line unicorn/no-instanceof-builtins
208
+ typeof value === "function" || value instanceof Function
209
+ );
209
210
  }
210
211
  /**
211
212
  * Checks that value is an object
212
213
  * @param value
213
214
  * @return {boolean}
214
215
  */
216
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
215
217
  isObject(value) {
216
218
  return !!value && (typeof value === "object" || typeof value === "function");
217
219
  }
@@ -237,7 +239,7 @@
237
239
  return true;
238
240
  }
239
241
  const ctor = proto.hasOwnProperty("constructor") && proto.constructor;
240
- return typeof ctor === "function" && Function.prototype.toString.call(ctor) === objectCtorString;
242
+ return typeof ctor === "function" && Function.prototype.toString.call(ctor) === OBJECT_CONSTRUCTOR_STRING;
241
243
  }
242
244
  isJsonRpcRequest(value) {
243
245
  return typeof value === "object" && value && "jsonrpc" in value && this.isStringFilled(value.jsonrpc) && "method" in value && this.isStringFilled(value.method);
@@ -259,7 +261,7 @@
259
261
  * @return {boolean}
260
262
  */
261
263
  isNumber(value) {
262
- return !Number.isNaN(value) && typeof value === "number";
264
+ return typeof value === "number" && !Number.isNaN(value);
263
265
  }
264
266
  /**
265
267
  * Checks that value is integer
@@ -267,7 +269,7 @@
267
269
  * @return {boolean}
268
270
  */
269
271
  isInteger(value) {
270
- return this.isNumber(value) && value % 1 === 0;
272
+ return Number.isInteger(value);
271
273
  }
272
274
  /**
273
275
  * Checks that value is float
@@ -315,7 +317,7 @@
315
317
  * @return {boolean}
316
318
  */
317
319
  isDate(value) {
318
- return this.isObjectLike(value) && this.getTag(value) === "[object Date]";
320
+ return value instanceof Date;
319
321
  }
320
322
  /**
321
323
  * Checks that is a DOM node
@@ -444,12 +446,15 @@
444
446
  * @return {boolean}
445
447
  */
446
448
  isFormData(value) {
447
- return value instanceof FormData;
449
+ if (typeof FormData !== "undefined" && value instanceof FormData) {
450
+ return true;
451
+ }
452
+ return this.isObjectLike(value) && this.getTag(value) === "[object FormData]";
448
453
  }
449
454
  clone(obj, bCopyObj = true) {
450
455
  let _obj, i, l;
451
- if (obj === null) {
452
- return null;
456
+ if (this.isNil(obj) || typeof obj !== "object") {
457
+ return obj;
453
458
  }
454
459
  if (this.isDomNode(obj)) {
455
460
  _obj = obj.cloneNode(bCopyObj);
@@ -10660,6 +10665,10 @@ ${this.stack}`;
10660
10665
  return value.toISOString();
10661
10666
  }
10662
10667
 
10668
+ if (utils$1.isBoolean(value)) {
10669
+ return value.toString();
10670
+ }
10671
+
10663
10672
  if (!useBlob && utils$1.isBlob(value)) {
10664
10673
  throw new AxiosError$1('Blob is not supported. Use a Buffer instead.');
10665
10674
  }
@@ -12568,7 +12577,7 @@ ${this.stack}`;
12568
12577
  credentials: isCredentialsSupported ? withCredentials : undefined
12569
12578
  });
12570
12579
 
12571
- let response = await fetch(request);
12580
+ let response = await fetch(request, fetchOptions);
12572
12581
 
12573
12582
  const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
12574
12583
 
@@ -12774,7 +12783,7 @@ ${this.stack}`;
12774
12783
  });
12775
12784
  }
12776
12785
 
12777
- const VERSION$1 = "1.9.0";
12786
+ const VERSION$1 = "1.10.0";
12778
12787
 
12779
12788
  const validators$1 = {};
12780
12789
 
@@ -14230,7 +14239,7 @@ ${this.stack}`;
14230
14239
  #clientSideWarningMessage = "";
14231
14240
  constructor(baseURL, authActions, options) {
14232
14241
  const defaultHeaders = {
14233
- // 'X-Sdk': 'b24-js-sdk-v-0.4.3'
14242
+ // 'X-Sdk': 'b24-js-sdk-v-0.4.5'
14234
14243
  };
14235
14244
  this.#clientAxios = axios.create({
14236
14245
  baseURL,
@@ -14295,19 +14304,21 @@ ${this.stack}`;
14295
14304
  }
14296
14305
  // endregion ////
14297
14306
  // region Actions Call ////
14298
- async batch(calls, isHaltOnError = true) {
14307
+ async batch(calls, isHaltOnError = true, returnAjaxResult = false) {
14299
14308
  if (Array.isArray(calls)) {
14300
14309
  return this.#batchAsArray(
14301
14310
  calls,
14302
- isHaltOnError
14311
+ isHaltOnError,
14312
+ returnAjaxResult
14303
14313
  );
14304
14314
  }
14305
14315
  return this.#batchAsObject(
14306
14316
  calls,
14307
- isHaltOnError
14317
+ isHaltOnError,
14318
+ returnAjaxResult
14308
14319
  );
14309
14320
  }
14310
- async #batchAsObject(calls, isHaltOnError = true) {
14321
+ async #batchAsObject(calls, isHaltOnError = true, returnAjaxResult = false) {
14311
14322
  const cmd = {};
14312
14323
  let cnt = 0;
14313
14324
  const processRow = (row, index) => {
@@ -14403,13 +14414,13 @@ ${this.stack}`;
14403
14414
  }
14404
14415
  return Promise.reject(error);
14405
14416
  }
14406
- dataResult[key] = data.getData().result;
14417
+ dataResult[key] = returnAjaxResult ? data : data.getData().result;
14407
14418
  }
14408
14419
  result.setData(dataResult);
14409
14420
  return Promise.resolve(result);
14410
14421
  });
14411
14422
  }
14412
- async #batchAsArray(calls, isHaltOnError = true) {
14423
+ async #batchAsArray(calls, isHaltOnError = true, returnAjaxResult = false) {
14413
14424
  const cmd = [];
14414
14425
  let cnt = 0;
14415
14426
  const processRow = (row) => {
@@ -14506,7 +14517,7 @@ ${this.stack}`;
14506
14517
  }
14507
14518
  return Promise.reject(error);
14508
14519
  }
14509
- dataResult.push(data.getData().result);
14520
+ dataResult.push(returnAjaxResult ? data : data.getData().result);
14510
14521
  }
14511
14522
  result.setData(dataResult);
14512
14523
  return Promise.resolve(result);
@@ -14658,7 +14669,7 @@ ${this.stack}`;
14658
14669
  const baseUrl = `${encodeURIComponent(method)}.json`;
14659
14670
  const queryParams = new URLSearchParams({
14660
14671
  [this.#requestIdGenerator.getQueryStringParameterName()]: this.#requestIdGenerator.getRequestId(),
14661
- [this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.3",
14672
+ [this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.5",
14662
14673
  [this.#requestIdGenerator.getQueryStringSdkTypeParameterName()]: "b24-js-sdk"
14663
14674
  });
14664
14675
  return `${baseUrl}?${queryParams.toString()}`;
@@ -14806,8 +14817,8 @@ ${this.stack}`;
14806
14817
  /**
14807
14818
  * @inheritDoc
14808
14819
  */
14809
- async callBatch(calls, isHaltOnError = true) {
14810
- return this.getHttpClient().batch(calls, isHaltOnError);
14820
+ async callBatch(calls, isHaltOnError = true, returnAjaxResult = false) {
14821
+ return this.getHttpClient().batch(calls, isHaltOnError, returnAjaxResult);
14811
14822
  }
14812
14823
  chunkArray(array, chunkSize = 50) {
14813
14824
  const result = [];
@@ -15159,7 +15170,7 @@ ${this.stack}`;
15159
15170
  * @returns {boolean} true if the passed IBAN is valid, false otherwise
15160
15171
  */
15161
15172
  isValid(iban) {
15162
- if (!this._isString(iban)) {
15173
+ if (!Type.isString(iban)) {
15163
15174
  return false;
15164
15175
  }
15165
15176
  iban = this.electronicFormat(iban);
@@ -15234,7 +15245,7 @@ ${this.stack}`;
15234
15245
  * @param bban the BBAN to check the validity of
15235
15246
  */
15236
15247
  isValidBBAN(countryCode, bban) {
15237
- if (!this._isString(bban)) {
15248
+ if (!Type.isString(bban)) {
15238
15249
  return false;
15239
15250
  }
15240
15251
  if (!this._countries.has(countryCode)) {
@@ -15244,11 +15255,6 @@ ${this.stack}`;
15244
15255
  return !!countryStructure && countryStructure.isValidBBAN(this.electronicFormat(bban));
15245
15256
  }
15246
15257
  // endregion ////
15247
- // region Tools ////
15248
- _isString(value) {
15249
- return typeof value == "string" || value instanceof String;
15250
- }
15251
- // endregion ////
15252
15258
  }
15253
15259
 
15254
15260
  const useFormatter = () => {
@@ -15798,6 +15804,35 @@ ${this.stack}`;
15798
15804
  }
15799
15805
  // endregion ////
15800
15806
  // region Tools ////
15807
+ static fromWebhookUrl(url) {
15808
+ if (!url.trim()) {
15809
+ throw new Error("Webhook URL cannot be empty");
15810
+ }
15811
+ let parsedUrl;
15812
+ try {
15813
+ parsedUrl = new URL(url);
15814
+ } catch {
15815
+ throw new Error(`Invalid webhook URL format: ${url}`);
15816
+ }
15817
+ if (parsedUrl.protocol !== "https:") {
15818
+ throw new Error("Webhook requires HTTPS protocol");
15819
+ }
15820
+ const pathParts = parsedUrl.pathname.split("/").filter(Boolean);
15821
+ if (pathParts.length < 3 || pathParts[0] !== "rest") {
15822
+ throw new Error("Webhook URL must follow format: /rest/<userId>/<secret>");
15823
+ }
15824
+ const userIdStr = pathParts[1];
15825
+ const secret = pathParts[2];
15826
+ if (!/^\d+$/.test(userIdStr)) {
15827
+ throw new Error(`User ID must be numeric in webhook URL, received: ${userIdStr}`);
15828
+ }
15829
+ const userId = Number.parseInt(userIdStr, 10);
15830
+ return new B24Hook({
15831
+ b24Url: parsedUrl.origin,
15832
+ userId,
15833
+ secret
15834
+ });
15835
+ }
15801
15836
  // endregion ////
15802
15837
  }
15803
15838
 
@@ -24380,8 +24415,8 @@ ${this.stack}`;
24380
24415
  if (!skipReconnectToLastSession && this._storage) {
24381
24416
  oldSession = this._storage.get(LS_SESSION, null);
24382
24417
  }
24383
- if (Type.isPlainObject(oldSession) && oldSession.hasOwnProperty("ttl") && oldSession.ttl >= now) {
24384
- this._session.mid = oldSession.mid;
24418
+ if (Type.isPlainObject(oldSession) && oldSession.hasOwnProperty("ttl") && oldSession["ttl"] >= now) {
24419
+ this._session.mid = oldSession["mid"];
24385
24420
  }
24386
24421
  this._starting = true;
24387
24422
  return this._startingPromise = new Promise((resolve, reject) => {
@@ -25204,22 +25239,22 @@ ${this.stack}`;
25204
25239
  if (!Type.isPlainObject(config)) {
25205
25240
  return false;
25206
25241
  }
25207
- if (Number(config.server.config_timestamp) !== this._configTimestamp) {
25242
+ if (Number(config["server"].config_timestamp) !== this._configTimestamp) {
25208
25243
  return false;
25209
25244
  }
25210
25245
  const now = /* @__PURE__ */ new Date();
25211
- if (Type.isNumber(config.exp) && config.exp > 0 && config.exp < now.getTime() / 1e3) {
25246
+ if (Type.isNumber(config["exp"]) && config["exp"] > 0 && config["exp"] < now.getTime() / 1e3) {
25212
25247
  return false;
25213
25248
  }
25214
- const channelCount = Object.keys(config.channels).length;
25249
+ const channelCount = Object.keys(config["channels"]).length;
25215
25250
  if (channelCount === 0) {
25216
25251
  return false;
25217
25252
  }
25218
- for (const channelType in config.channels) {
25219
- if (!config.channels.hasOwnProperty(channelType)) {
25253
+ for (const channelType in config["channels"]) {
25254
+ if (!config["channels"].hasOwnProperty(channelType)) {
25220
25255
  continue;
25221
25256
  }
25222
- const channel = config.channels[channelType];
25257
+ const channel = config["channels"][channelType];
25223
25258
  const channelEnd = new Date(channel.end);
25224
25259
  if (channelEnd < now) {
25225
25260
  return false;