bx-rest 0.6.6 → 0.6.8

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.
@@ -7,6 +7,7 @@ import flatten from 'just-flatten-it';
7
7
  import * as qs from 'qs';
8
8
  import values from 'just-values';
9
9
  import camelCase from 'just-camel-case';
10
+ import { __decorate } from 'tslib';
10
11
 
11
12
  const DEFAULT_BX_REST_SETTINGS = {
12
13
  auth: {
@@ -79,7 +80,12 @@ class CookiesServices {
79
80
  }
80
81
  }
81
82
 
82
- // Преобразует значение в строку
83
+ /**
84
+ * Преобразует значение в строку
85
+ *
86
+ * @param val
87
+ * @param throwError
88
+ */
83
89
  function toStr(val, throwError = false) {
84
90
  if (val === null || val === undefined) {
85
91
  if (throwError) {
@@ -89,18 +95,49 @@ function toStr(val, throwError = false) {
89
95
  }
90
96
  return String(val);
91
97
  }
92
- // Преобразует значение в число
98
+ /**
99
+ * Преобразует значение в число
100
+ */
93
101
  function toNum(val, throwError = true, defValue = 0) {
94
102
  const result = Number(val);
95
103
  if (isNaN(result)) {
96
- if (throwError) {
97
- throw new Error('Invalid value: cannot be converted to number');
98
- }
104
+ const error = new ToNumError(val);
105
+ if (throwError)
106
+ throw error;
107
+ // Если ошибка не пробрасывается — просто логируем
108
+ console.error(error.toString());
99
109
  return defValue;
100
110
  }
101
111
  return result;
102
112
  }
103
- // Преобразует значение в дату
113
+ /**
114
+ * Кастомный тип ошибки для числовых преобразований
115
+ */
116
+ class ToNumError extends Error {
117
+ constructor(value) {
118
+ const valueType = typeof value;
119
+ const formattedValue = valueType === 'object' ? JSON.stringify(value) : String(value);
120
+ const message = `Invalid value passed to toNum(): ${formattedValue} (type: ${valueType})`;
121
+ super(message);
122
+ this.value = value;
123
+ this.name = 'ToNumError';
124
+ // сохраняем стек вызова (отфильтровав сам конструктор)
125
+ if (this.stack) {
126
+ const stackLines = this.stack.split('\n');
127
+ // Удаляем строку конструктора (чтобы стек начинался с места вызова toNum)
128
+ this.stack = [stackLines[0], ...stackLines.slice(2)].join('\n');
129
+ }
130
+ }
131
+ toString() {
132
+ return [
133
+ `❌ [${this.name}] ${this.message}`,
134
+ this.stack ? ` Stack trace:\n${this.stack}` : '',
135
+ ].join('\n');
136
+ }
137
+ }
138
+ /**
139
+ * Преобразует значение в дату
140
+ */
104
141
  function toDate(val, format, opt, throwError = true) {
105
142
  if (val instanceof Date) {
106
143
  return val;
@@ -125,7 +162,12 @@ function toDate(val, format, opt, throwError = true) {
125
162
  }
126
163
  return new Date();
127
164
  }
128
- // Преобразует дату в строку с учетом временной зоны
165
+ /**
166
+ * Преобразует дату в строку с учетом временной зоны
167
+ *
168
+ * @param date
169
+ * @param throwError
170
+ */
129
171
  function toISOStringWithTimezone(date, throwError = true) {
130
172
  if (!(date instanceof Date)) {
131
173
  if (throwError)
@@ -144,7 +186,12 @@ function toISOStringWithTimezone(date, throwError = true) {
144
186
  diff + pad(tzOffset / 60) +
145
187
  ':' + pad(tzOffset % 60);
146
188
  }
147
- // Преобразует значение в булево значение
189
+ /**
190
+ * Преобразует значение в булево значение
191
+ *
192
+ * @param val
193
+ * @param throwError
194
+ */
148
195
  function toBool(val, throwError = true) {
149
196
  switch (typeof val) {
150
197
  case 'string':
@@ -164,7 +211,11 @@ function toBool(val, throwError = true) {
164
211
  return Boolean(val);
165
212
  }
166
213
  }
167
- // Преобразует булево значение в 'Y' или 'N'
214
+ /**
215
+ * Преобразует булево значение в 'Y' или 'N'
216
+ *
217
+ * @param val
218
+ */
168
219
  function toBXYorN(val) {
169
220
  return val ? 'Y' : 'N';
170
221
  }
@@ -176,7 +227,11 @@ function getBaseUrlHttps(url, component = false) {
176
227
  return encodeURI('https://' + cropUrl(url) + '/');
177
228
  }
178
229
  }
179
- // Обрезает URL (удаляет протокол)
230
+ /**
231
+ * Обрезает URL (удаляет протокол)
232
+ *
233
+ * @param url
234
+ */
180
235
  function cropUrl(url) {
181
236
  url = url ? url.replace('https://', '') : '';
182
237
  url = url ? url.replace('http://', '') : '';
@@ -184,7 +239,11 @@ function cropUrl(url) {
184
239
  url = url ? url.replace('http:', '') : '';
185
240
  return url;
186
241
  }
187
- // Преобразует файл в base64
242
+ /**
243
+ * Преобразует файл в base64
244
+ *
245
+ * @param file
246
+ */
188
247
  function getBase64File(file) {
189
248
  return new Promise((resolve, reject) => {
190
249
  const reader = new FileReader();
@@ -193,7 +252,11 @@ function getBase64File(file) {
193
252
  reader.onerror = error => reject(error);
194
253
  });
195
254
  }
196
- // Получить файл в формате base64 с разбивкой на заголовок и данные
255
+ /**
256
+ * Получить файл в формате base64 с разбивкой на заголовок и данные
257
+ *
258
+ * @param file
259
+ */
197
260
  async function getBase64FileLikeStr(file) {
198
261
  const result = await getBase64File(file);
199
262
  if (typeof result === 'string') {
@@ -223,6 +286,7 @@ function prepareBaseAddress(url, add = '') {
223
286
 
224
287
  var base = /*#__PURE__*/Object.freeze({
225
288
  __proto__: null,
289
+ ToNumError: ToNumError,
226
290
  cropUrl: cropUrl,
227
291
  getBase64File: getBase64File,
228
292
  getBase64FileLikeStr: getBase64FileLikeStr,
@@ -3013,6 +3077,9 @@ class BXRestNavvyUser {
3013
3077
  if (!Object.prototype.hasOwnProperty.call(params.FILTER, 'ACTIVE')) {
3014
3078
  params.FILTER.ACTIVE = this.def.params.ACTIVE;
3015
3079
  }
3080
+ else if (typeof params.FILTER.ACTIVE !== 'boolean') {
3081
+ delete params.FILTER.ACTIVE;
3082
+ }
3016
3083
  if (!Object.prototype.hasOwnProperty.call(params, 'start')) {
3017
3084
  params.start = this.def.params.start;
3018
3085
  }
@@ -5535,6 +5602,40 @@ class BXRestNavvyImDialog {
5535
5602
  }
5536
5603
  }
5537
5604
 
5605
+ function CatchError(options) {
5606
+ return function (target, propertyKey, descriptor) {
5607
+ const original = descriptor.value;
5608
+ descriptor.value = function (...args) {
5609
+ try {
5610
+ return original.apply(this, args);
5611
+ }
5612
+ catch (err) {
5613
+ const errorInfo = {
5614
+ message: `❌ Error in ${target.constructor.name}.${propertyKey}`,
5615
+ args,
5616
+ error: err instanceof Error ? err.message : String(err),
5617
+ stack: err instanceof Error ? err.stack : new Error().stack,
5618
+ };
5619
+ console.error(formatError(errorInfo));
5620
+ if (options?.rethrow)
5621
+ throw err;
5622
+ return options?.defaultValue;
5623
+ }
5624
+ };
5625
+ return descriptor;
5626
+ };
5627
+ }
5628
+ // Общая функция форматирования
5629
+ function formatError(info) {
5630
+ const stackLines = info.stack?.split('\n').slice(2).join('\n');
5631
+ return [
5632
+ info.message,
5633
+ info.args ? ` • args: ${JSON.stringify(info.args)}` : '',
5634
+ info.error ? ` • error: ${info.error}` : '',
5635
+ ` • stack trace:\n${stackLines}`,
5636
+ ].join('\n');
5637
+ }
5638
+
5538
5639
  class BXRestMapImRecent {
5539
5640
  static get(value) {
5540
5641
  return value
@@ -5554,7 +5655,7 @@ class BXRestMapImRecent {
5554
5655
  }
5555
5656
  }
5556
5657
  : undefined,
5557
- chat: i.chat
5658
+ chat: i.chat && BXRestMapImRecent.isIBXRestImDialogRecentGetChatChatDataHttp(i.chat)
5558
5659
  ? {
5559
5660
  ...i.chat,
5560
5661
  ...{
@@ -5562,7 +5663,7 @@ class BXRestMapImRecent {
5562
5663
  date_create: toDate(i.chat.date_create)
5563
5664
  }
5564
5665
  }
5565
- : undefined,
5666
+ : i.chat,
5566
5667
  }
5567
5668
  }))
5568
5669
  : undefined;
@@ -5594,7 +5695,16 @@ class BXRestMapImRecent {
5594
5695
  }
5595
5696
  : undefined;
5596
5697
  }
5698
+ static isIBXRestImDialogRecentGetChatChatDataHttp(item) {
5699
+ return 'id' in item;
5700
+ }
5597
5701
  }
5702
+ __decorate([
5703
+ CatchError({ rethrow: true })
5704
+ ], BXRestMapImRecent, "get", null);
5705
+ __decorate([
5706
+ CatchError({ rethrow: true })
5707
+ ], BXRestMapImRecent, "list", null);
5598
5708
 
5599
5709
  class BXRestNavvyImRecent {
5600
5710
  constructor() {