@bitrix24/b24jssdk 0.4.4 → 0.4.6

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.4
2
+ * @version @bitrix24/b24jssdk v0.4.6
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.4'
1686
+ // 'X-Sdk': 'b24-js-sdk-v-0.4.6'
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.4",
2116
+ [this.#requestIdGenerator.getQueryStringSdkParameterName()]: "0.4.6",
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 = () => {
@@ -3384,8 +3386,11 @@ class MessageManager {
3384
3386
  };
3385
3387
  } else {
3386
3388
  cmd = command.toString();
3389
+ if (params?.isRawValue !== true) {
3390
+ paramsSend = JSON.stringify(paramsSend);
3391
+ }
3387
3392
  const listParams = [
3388
- paramsSend ? JSON.stringify(paramsSend) : "",
3393
+ paramsSend || "",
3389
3394
  keyPromise,
3390
3395
  this.#appFrame.getAppSid()
3391
3396
  ];
@@ -4188,18 +4193,20 @@ class PlacementManager {
4188
4193
  }
4189
4194
  /**
4190
4195
  * Call the Registered Interface Command
4191
- * @param {string} command
4192
- * @param {Record<string, any>} parameters
4193
- * @return {Promise<any>}
4196
+ * @param { string } command
4197
+ * @param { Record<string, any> } parameters
4198
+ * @return { Promise<any> }
4194
4199
  *
4195
4200
  * @link https://apidocs.bitrix24.com/api-reference/widgets/ui-interaction/bx24-placement-call.html
4201
+ * @memo For the `setValue` command, use the following parameters { value: string }
4196
4202
  */
4197
4203
  async call(command, parameters = {}) {
4198
4204
  return this.#messageManager.send(
4199
4205
  command,
4200
4206
  {
4201
4207
  ...parameters,
4202
- isSafely: true
4208
+ isSafely: true,
4209
+ isRawValue: ["setValue"].includes(command)
4203
4210
  }
4204
4211
  );
4205
4212
  }
@@ -8181,7 +8188,7 @@ function requireProtobuf () {
8181
8188
  } : create_array;
8182
8189
  Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */
8183
8190
  util.Array.prototype.slice;
8184
- Reader.prototype.uint32 = /* @__PURE__ */ function read_uint32_setup() {
8191
+ Reader.prototype.uint32 = /* @__PURE__ */ (function read_uint32_setup() {
8185
8192
  var value = 4294967295;
8186
8193
  return function read_uint32() {
8187
8194
  value = (this.buf[this.pos] & 127) >>> 0;
@@ -8200,7 +8207,7 @@ function requireProtobuf () {
8200
8207
  }
8201
8208
  return value;
8202
8209
  };
8203
- }();
8210
+ })();
8204
8211
  Reader.prototype.int32 = function read_int32() {
8205
8212
  return this.uint32() | 0;
8206
8213
  };
@@ -9654,7 +9661,7 @@ function requireProtobuf () {
9654
9661
  return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;
9655
9662
  return false;
9656
9663
  };
9657
- util.Buffer = function() {
9664
+ util.Buffer = (function() {
9658
9665
  try {
9659
9666
  var Buffer = util.inquire("buffer").Buffer;
9660
9667
  return Buffer.prototype.utf8Write ? Buffer : (
@@ -9664,7 +9671,7 @@ function requireProtobuf () {
9664
9671
  } catch (e) {
9665
9672
  return null;
9666
9673
  }
9667
- }();
9674
+ })();
9668
9675
  util._Buffer_from = null;
9669
9676
  util._Buffer_allocUnsafe = null;
9670
9677
  util.newBuffer = function newBuffer(sizeOrArray) {
@@ -10120,7 +10127,7 @@ const $protobuf = /*@__PURE__*/getDefaultExportFromCjs(protobufExports);
10120
10127
 
10121
10128
  let $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
10122
10129
  const $root = $protobuf.roots["push-server"] || ($protobuf.roots["push-server"] = {});
10123
- $root.RequestBatch = function() {
10130
+ $root.RequestBatch = (function() {
10124
10131
  function RequestBatch(properties) {
10125
10132
  this.requests = [];
10126
10133
  if (properties) {
@@ -10172,8 +10179,8 @@ $root.RequestBatch = function() {
10172
10179
  return message;
10173
10180
  };
10174
10181
  return RequestBatch;
10175
- }();
10176
- $root.Request = function() {
10182
+ })();
10183
+ $root.Request = (function() {
10177
10184
  function Request(properties) {
10178
10185
  if (properties) {
10179
10186
  for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
@@ -10262,8 +10269,8 @@ $root.Request = function() {
10262
10269
  return message;
10263
10270
  };
10264
10271
  return Request;
10265
- }();
10266
- $root.IncomingMessagesRequest = function() {
10272
+ })();
10273
+ $root.IncomingMessagesRequest = (function() {
10267
10274
  function IncomingMessagesRequest(properties) {
10268
10275
  this.messages = [];
10269
10276
  if (properties) {
@@ -10317,8 +10324,8 @@ $root.IncomingMessagesRequest = function() {
10317
10324
  return message;
10318
10325
  };
10319
10326
  return IncomingMessagesRequest;
10320
- }();
10321
- $root.IncomingMessage = function() {
10327
+ })();
10328
+ $root.IncomingMessage = (function() {
10322
10329
  function IncomingMessage(properties) {
10323
10330
  this.receivers = [];
10324
10331
  if (properties) {
@@ -10413,8 +10420,8 @@ $root.IncomingMessage = function() {
10413
10420
  return message;
10414
10421
  };
10415
10422
  return IncomingMessage;
10416
- }();
10417
- $root.ChannelStatsRequest = function() {
10423
+ })();
10424
+ $root.ChannelStatsRequest = (function() {
10418
10425
  function ChannelStatsRequest(properties) {
10419
10426
  this.channels = [];
10420
10427
  if (properties) {
@@ -10466,8 +10473,8 @@ $root.ChannelStatsRequest = function() {
10466
10473
  return message;
10467
10474
  };
10468
10475
  return ChannelStatsRequest;
10469
- }();
10470
- $root.ChannelId = function() {
10476
+ })();
10477
+ $root.ChannelId = (function() {
10471
10478
  function ChannelId(properties) {
10472
10479
  if (properties) {
10473
10480
  for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
@@ -10531,8 +10538,8 @@ $root.ChannelId = function() {
10531
10538
  return message;
10532
10539
  };
10533
10540
  return ChannelId;
10534
- }();
10535
- $root.ServerStatsRequest = function() {
10541
+ })();
10542
+ $root.ServerStatsRequest = (function() {
10536
10543
  function ServerStatsRequest(properties) {
10537
10544
  if (properties) {
10538
10545
  for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
@@ -10566,8 +10573,8 @@ $root.ServerStatsRequest = function() {
10566
10573
  return message;
10567
10574
  };
10568
10575
  return ServerStatsRequest;
10569
- }();
10570
- $root.Sender = function() {
10576
+ })();
10577
+ $root.Sender = (function() {
10571
10578
  function Sender(properties) {
10572
10579
  if (properties) {
10573
10580
  for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
@@ -10621,15 +10628,15 @@ $root.Sender = function() {
10621
10628
  return message;
10622
10629
  };
10623
10630
  return Sender;
10624
- }();
10625
- $root.SenderType = function() {
10631
+ })();
10632
+ $root.SenderType = (function() {
10626
10633
  var valuesById = {}, values = Object.create(valuesById);
10627
10634
  values[valuesById[0] = "UNKNOWN"] = 0;
10628
10635
  values[valuesById[1] = "CLIENT"] = 1;
10629
10636
  values[valuesById[2] = "BACKEND"] = 2;
10630
10637
  return values;
10631
- }();
10632
- $root.Receiver = function() {
10638
+ })();
10639
+ $root.Receiver = (function() {
10633
10640
  function Receiver(properties) {
10634
10641
  if (properties) {
10635
10642
  for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
@@ -10693,8 +10700,8 @@ $root.Receiver = function() {
10693
10700
  return message;
10694
10701
  };
10695
10702
  return Receiver;
10696
- }();
10697
- $root.ResponseBatch = function() {
10703
+ })();
10704
+ $root.ResponseBatch = (function() {
10698
10705
  function ResponseBatch(properties) {
10699
10706
  this.responses = [];
10700
10707
  if (properties) {
@@ -10746,8 +10753,8 @@ $root.ResponseBatch = function() {
10746
10753
  return message;
10747
10754
  };
10748
10755
  return ResponseBatch;
10749
- }();
10750
- $root.Response = function() {
10756
+ })();
10757
+ $root.Response = (function() {
10751
10758
  function Response(properties) {
10752
10759
  if (properties) {
10753
10760
  for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
@@ -10836,8 +10843,8 @@ $root.Response = function() {
10836
10843
  return message;
10837
10844
  };
10838
10845
  return Response;
10839
- }();
10840
- $root.OutgoingMessagesResponse = function() {
10846
+ })();
10847
+ $root.OutgoingMessagesResponse = (function() {
10841
10848
  function OutgoingMessagesResponse(properties) {
10842
10849
  this.messages = [];
10843
10850
  if (properties) {
@@ -10891,8 +10898,8 @@ $root.OutgoingMessagesResponse = function() {
10891
10898
  return message;
10892
10899
  };
10893
10900
  return OutgoingMessagesResponse;
10894
- }();
10895
- $root.OutgoingMessage = function() {
10901
+ })();
10902
+ $root.OutgoingMessage = (function() {
10896
10903
  function OutgoingMessage(properties) {
10897
10904
  if (properties) {
10898
10905
  for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
@@ -10979,8 +10986,8 @@ $root.OutgoingMessage = function() {
10979
10986
  return message;
10980
10987
  };
10981
10988
  return OutgoingMessage;
10982
- }();
10983
- $root.ChannelStatsResponse = function() {
10989
+ })();
10990
+ $root.ChannelStatsResponse = (function() {
10984
10991
  function ChannelStatsResponse(properties) {
10985
10992
  this.channels = [];
10986
10993
  if (properties) {
@@ -11034,8 +11041,8 @@ $root.ChannelStatsResponse = function() {
11034
11041
  return message;
11035
11042
  };
11036
11043
  return ChannelStatsResponse;
11037
- }();
11038
- $root.ChannelStats = function() {
11044
+ })();
11045
+ $root.ChannelStats = (function() {
11039
11046
  function ChannelStats(properties) {
11040
11047
  if (properties) {
11041
11048
  for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
@@ -11099,8 +11106,8 @@ $root.ChannelStats = function() {
11099
11106
  return message;
11100
11107
  };
11101
11108
  return ChannelStats;
11102
- }();
11103
- $root.JsonResponse = function() {
11109
+ })();
11110
+ $root.JsonResponse = (function() {
11104
11111
  function JsonResponse(properties) {
11105
11112
  if (properties) {
11106
11113
  for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
@@ -11144,7 +11151,7 @@ $root.JsonResponse = function() {
11144
11151
  return message;
11145
11152
  };
11146
11153
  return JsonResponse;
11147
- }();
11154
+ })();
11148
11155
 
11149
11156
  const ResponseBatch = $root["ResponseBatch"];
11150
11157
  const RequestBatch = $root["RequestBatch"];
@@ -11857,8 +11864,8 @@ class PullClient {
11857
11864
  if (!skipReconnectToLastSession && this._storage) {
11858
11865
  oldSession = this._storage.get(LS_SESSION, null);
11859
11866
  }
11860
- if (Type.isPlainObject(oldSession) && oldSession.hasOwnProperty("ttl") && oldSession.ttl >= now) {
11861
- this._session.mid = oldSession.mid;
11867
+ if (Type.isPlainObject(oldSession) && oldSession.hasOwnProperty("ttl") && oldSession["ttl"] >= now) {
11868
+ this._session.mid = oldSession["mid"];
11862
11869
  }
11863
11870
  this._starting = true;
11864
11871
  return this._startingPromise = new Promise((resolve, reject) => {
@@ -12681,22 +12688,22 @@ class PullClient {
12681
12688
  if (!Type.isPlainObject(config)) {
12682
12689
  return false;
12683
12690
  }
12684
- if (Number(config.server.config_timestamp) !== this._configTimestamp) {
12691
+ if (Number(config["server"].config_timestamp) !== this._configTimestamp) {
12685
12692
  return false;
12686
12693
  }
12687
12694
  const now = /* @__PURE__ */ new Date();
12688
- if (Type.isNumber(config.exp) && config.exp > 0 && config.exp < now.getTime() / 1e3) {
12695
+ if (Type.isNumber(config["exp"]) && config["exp"] > 0 && config["exp"] < now.getTime() / 1e3) {
12689
12696
  return false;
12690
12697
  }
12691
- const channelCount = Object.keys(config.channels).length;
12698
+ const channelCount = Object.keys(config["channels"]).length;
12692
12699
  if (channelCount === 0) {
12693
12700
  return false;
12694
12701
  }
12695
- for (const channelType in config.channels) {
12696
- if (!config.channels.hasOwnProperty(channelType)) {
12702
+ for (const channelType in config["channels"]) {
12703
+ if (!config["channels"].hasOwnProperty(channelType)) {
12697
12704
  continue;
12698
12705
  }
12699
- const channel = config.channels[channelType];
12706
+ const channel = config["channels"][channelType];
12700
12707
  const channelEnd = new Date(channel.end);
12701
12708
  if (channelEnd < now) {
12702
12709
  return false;
@@ -13456,7 +13463,7 @@ Data string: ${pullEvent}
13456
13463
  }
13457
13464
  trimDuplicates() {
13458
13465
  if (this._session.lastMessageIds.length > MAX_IDS_TO_STORE) {
13459
- this._session.lastMessageIds = this._session.lastMessageIds.slice(-10);
13466
+ this._session.lastMessageIds = this._session.lastMessageIds.slice(-MAX_IDS_TO_STORE);
13460
13467
  }
13461
13468
  }
13462
13469
  // endregion ////