bx-rest 0.9.10 → 0.10.0

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.
Files changed (41) hide show
  1. package/consts/part-name-methods.d.ts +1 -0
  2. package/esm2022/consts/part-name-methods.mjs +2 -1
  3. package/esm2022/functions/serializeBitrixParams.mjs +25 -0
  4. package/esm2022/map/crm/automatedsolution.mjs +11 -0
  5. package/esm2022/map/crm/index.mjs +2 -1
  6. package/esm2022/request-navvy/crm/automatedsolution.mjs +73 -0
  7. package/esm2022/request-navvy/crm.mjs +4 -1
  8. package/esm2022/services/http/HttpBX.mjs +5 -45
  9. package/esm2022/services/navvy/navvy-alternative-pagination-navigation.mjs +3 -3
  10. package/esm2022/services/navvy/navvy-pag-nav-result-key.mjs +77 -0
  11. package/esm2022/services/navvy/navvy-pag-nav-tasks.mjs +3 -3
  12. package/esm2022/services/navvy/navvy-pag-nav-with-useless-key.mjs +3 -3
  13. package/esm2022/services/navvy/navvy-pag.mjs +3 -3
  14. package/esm2022/services/navvy.mjs +6 -1
  15. package/esm2022/typification/rest/crm/automatedsolution/add.mjs +2 -0
  16. package/esm2022/typification/rest/crm/automatedsolution/automatedsolution.mjs +2 -0
  17. package/esm2022/typification/rest/crm/automatedsolution/delete.mjs +2 -0
  18. package/esm2022/typification/rest/crm/automatedsolution/get.mjs +2 -0
  19. package/esm2022/typification/rest/crm/automatedsolution/index.mjs +7 -0
  20. package/esm2022/typification/rest/crm/automatedsolution/list.mjs +2 -0
  21. package/esm2022/typification/rest/crm/automatedsolution/update.mjs +2 -0
  22. package/esm2022/typification/rest/crm/index.mjs +2 -1
  23. package/fesm2022/bx-rest.mjs +190 -48
  24. package/fesm2022/bx-rest.mjs.map +1 -1
  25. package/functions/serializeBitrixParams.d.ts +5 -0
  26. package/map/crm/automatedsolution.d.ts +7 -0
  27. package/map/crm/index.d.ts +1 -0
  28. package/package.json +2 -2
  29. package/request-navvy/crm/automatedsolution.d.ts +56 -0
  30. package/request-navvy/crm.d.ts +3 -0
  31. package/services/http/HttpBX.d.ts +1 -1
  32. package/services/navvy/navvy-pag-nav-result-key.d.ts +13 -0
  33. package/services/navvy.d.ts +3 -0
  34. package/typification/rest/crm/automatedsolution/add.d.ts +8 -0
  35. package/typification/rest/crm/automatedsolution/automatedsolution.d.ts +23 -0
  36. package/typification/rest/crm/automatedsolution/delete.d.ts +4 -0
  37. package/typification/rest/crm/automatedsolution/get.d.ts +4 -0
  38. package/typification/rest/crm/automatedsolution/index.d.ts +6 -0
  39. package/typification/rest/crm/automatedsolution/list.d.ts +7 -0
  40. package/typification/rest/crm/automatedsolution/update.d.ts +10 -0
  41. package/typification/rest/crm/index.d.ts +1 -0
@@ -4,7 +4,7 @@ import { Subscription, of, throwError, from, forkJoin, last, shareReplay, mergeM
4
4
  import clone from 'just-clone';
5
5
  import axios from 'axios';
6
6
  import flatten from 'just-flatten-it';
7
- import * as qs from 'qs';
7
+ import { stringify } from 'qs-esm';
8
8
  import values from 'just-values';
9
9
  import camelCase from 'just-camel-case';
10
10
  import { __decorate } from 'tslib';
@@ -707,6 +707,30 @@ class HttpServices extends BaseHttp {
707
707
  }
708
708
  }
709
709
 
710
+ const BITRIX_STRINGIFY_OPTIONS = {
711
+ // Добавляет числовые индексы массивов: fields[PHONE][0][VALUE].
712
+ arrayFormat: 'indices',
713
+ // Использует bracket notation для вложенных объектов: filter[ID], а не filter.ID.
714
+ allowDots: false,
715
+ // Выполняет URL-кодирование ключей и значений параметров.
716
+ encode: true,
717
+ // Кодирует не только значения, но и ключи вместе с квадратными скобками.
718
+ encodeValuesOnly: false,
719
+ // Кодирует пробел как %20 и использует правила RFC 3986.
720
+ format: 'RFC3986',
721
+ // Не удаляет null: значение сериализуется как пустой параметр key=.
722
+ skipNulls: false,
723
+ // Сохраняет знак равенства для null: key= вместо параметра без значения key.
724
+ strictNullHandling: false,
725
+ };
726
+ /**
727
+ * Serializes nested REST parameters using the indexed bracket notation
728
+ * expected by Bitrix, for example: fields[PHONE][0][VALUE].
729
+ */
730
+ function serializeBitrixParams(params) {
731
+ return stringify(params, BITRIX_STRINGIFY_OPTIONS);
732
+ }
733
+
710
734
  class HttpBXServices extends HttpServices {
711
735
  /**
712
736
  * Это пиздец а не метод
@@ -736,7 +760,7 @@ class HttpBXServices extends HttpServices {
736
760
  }, {});
737
761
  for (let key in param) {
738
762
  if (typeof key === 'string' || typeof key === 'number' && param[key].param) {
739
- res[key] = param[key].name + '?' + qs.stringify(param[key].param, { arrayFormat: 'brackets' });
763
+ res[key] = param[key].name + '?' + serializeBitrixParams(param[key].param);
740
764
  }
741
765
  }
742
766
  return res;
@@ -800,48 +824,8 @@ class HttpBXServices extends HttpServices {
800
824
  }).then((response) => response.data));
801
825
  }));
802
826
  }
803
- serializeBitrixParams(obj, prefix = '') {
804
- const pairs = [];
805
- for (const key in obj) {
806
- if (!Object.prototype.hasOwnProperty.call(obj, key))
807
- continue;
808
- const value = obj[key];
809
- const prefixedKey = prefix ? `${prefix}[${key}]` : key;
810
- if (value === undefined) {
811
- continue;
812
- }
813
- else if (value === null) {
814
- pairs.push(`${encodeURIComponent(prefixedKey)}=`);
815
- }
816
- else if (value instanceof Date) {
817
- pairs.push(`${encodeURIComponent(prefixedKey)}=${encodeURIComponent(value.toISOString())}`);
818
- }
819
- else if (Array.isArray(value)) {
820
- value.forEach((item) => {
821
- if (item === undefined)
822
- return;
823
- if (item === null) {
824
- pairs.push(`${encodeURIComponent(prefixedKey)}[]=`);
825
- }
826
- else if (item instanceof Date) {
827
- pairs.push(`${encodeURIComponent(prefixedKey)}[]=${encodeURIComponent(item.toISOString())}`);
828
- }
829
- else if (typeof item === 'object') {
830
- pairs.push(this.serializeBitrixParams(item, `${prefixedKey}[]`));
831
- }
832
- else {
833
- pairs.push(`${encodeURIComponent(prefixedKey)}[]=${encodeURIComponent(item)}`);
834
- }
835
- });
836
- }
837
- else if (typeof value === 'object') {
838
- pairs.push(this.serializeBitrixParams(value, prefixedKey));
839
- }
840
- else {
841
- pairs.push(`${encodeURIComponent(prefixedKey)}=${encodeURIComponent(value)}`);
842
- }
843
- }
844
- return pairs.join('&');
827
+ serializeBitrixParams(params) {
828
+ return serializeBitrixParams(params);
845
829
  }
846
830
  // Мб не работает
847
831
  httpGet(url, params = {}) {
@@ -1039,6 +1023,7 @@ const $end = 'end';
1039
1023
  const $idle = 'idle';
1040
1024
  const $crm = 'crm';
1041
1025
  const $automation = 'automation';
1026
+ const $automatedsolution = 'automatedsolution';
1042
1027
  const $trigger = 'trigger';
1043
1028
  const $execute = 'execute';
1044
1029
  const $enum = 'enum';
@@ -1061,6 +1046,7 @@ var partNameMethods$1 = /*#__PURE__*/Object.freeze({
1061
1046
  $application: $application,
1062
1047
  $approve: $approve,
1063
1048
  $attach: $attach,
1049
+ $automatedsolution: $automatedsolution,
1064
1050
  $automation: $automation,
1065
1051
  $bizproc: $bizproc,
1066
1052
  $blogcomment: $blogcomment,
@@ -2066,7 +2052,7 @@ class NavvyAlterPagNav extends NavvyPagBase {
2066
2052
  param.PARAMS.NAV_PARAMS.iNumPage = i + 2; // первая страница уже есть, старт со второй
2067
2053
  // Формируем строку запроса
2068
2054
  return this.http.getNameMethod(this.url)
2069
- + '?' + qs.stringify(param, { arrayFormat: 'brackets' });
2055
+ + '?' + serializeBitrixParams(param);
2070
2056
  })
2071
2057
  });
2072
2058
  });
@@ -2122,7 +2108,7 @@ class NavvyPagNavWithUselessKey extends NavvyPagBase {
2122
2108
  param.start = (i + 1) * this.pageSize;
2123
2109
  // Формируем строку запроса
2124
2110
  return this.http.getNameMethod(this.url)
2125
- + '?' + qs.stringify(param, { arrayFormat: 'brackets' });
2111
+ + '?' + serializeBitrixParams(param);
2126
2112
  })
2127
2113
  }).pipe(map(v => {
2128
2114
  if (v && instanceOfiBXRestAnswerSuccess(v) && v.result && v.result.result && items.result) {
@@ -2208,7 +2194,7 @@ class NavvyPagNavTasks extends NavvyPagBase {
2208
2194
  param.start = (i + 1) * this.pageSize;
2209
2195
  // Формируем строку запроса
2210
2196
  return this.http.getNameMethod(this.url)
2211
- + '?' + qs.stringify(param, { arrayFormat: 'brackets' });
2197
+ + '?' + serializeBitrixParams(param);
2212
2198
  })
2213
2199
  });
2214
2200
  });
@@ -2272,7 +2258,7 @@ class NavvyPag extends NavvyPagBase {
2272
2258
  param.start = (i + 1) * this.pageSize;
2273
2259
  // Формируем строку запроса
2274
2260
  return this.http.getNameMethod(this.url)
2275
- + '?' + qs.stringify(param, { arrayFormat: 'brackets' });
2261
+ + '?' + serializeBitrixParams(param);
2276
2262
  })
2277
2263
  }).pipe();
2278
2264
  });
@@ -2305,6 +2291,76 @@ class NavvyPag extends NavvyPagBase {
2305
2291
  }
2306
2292
  }
2307
2293
 
2294
+ class NavvyPagNavResultKey extends NavvyPagBase {
2295
+ constructor(url, param, key, map) {
2296
+ super(url, param, map);
2297
+ this.key = key;
2298
+ this.save = [];
2299
+ }
2300
+ resAll() {
2301
+ let save = [];
2302
+ return this.resultAllEnd()
2303
+ .pipe(map(v => {
2304
+ if (v) {
2305
+ save.push(...v);
2306
+ }
2307
+ return save;
2308
+ }), last(), shareReplay(1));
2309
+ }
2310
+ resultAllEnd() {
2311
+ let BXRestClass = new BXRest();
2312
+ return this.resVanilla().pipe(mergeMap(items => {
2313
+ if (items && instanceOfiBXRestAnswerSuccess(items)) {
2314
+ this.save = [];
2315
+ if (items.total && items.total > 50) {
2316
+ const mathFloor = Math.floor(items.total / this.pageSize);
2317
+ const count = (mathFloor === items.total / this.pageSize)
2318
+ ? [...Array(mathFloor - 1).keys()]
2319
+ : [...Array(mathFloor).keys()];
2320
+ const chunks = [];
2321
+ for (let i = 0; i < count.length; i += this.pageSize) {
2322
+ chunks.push(count.slice(i, i + this.pageSize));
2323
+ }
2324
+ const batchRequests = chunks.map(chunk => {
2325
+ return BXRestClass.batch({
2326
+ halt: 1,
2327
+ cmd: chunk.map(i => {
2328
+ const param = clone(this.param);
2329
+ param.start = (i + 1) * this.pageSize;
2330
+ return this.http.getNameMethod(this.url)
2331
+ + '?' + serializeBitrixParams(param);
2332
+ })
2333
+ });
2334
+ });
2335
+ return from(batchRequests).pipe(concatMap(request => request), toArray(), map(results => {
2336
+ const firstPage = items.result?.[this.key];
2337
+ if (firstPage) {
2338
+ const res = firstPage;
2339
+ for (let result of results) {
2340
+ if (result && instanceOfiBXRestAnswerSuccess(result) && result.result && result.result.result) {
2341
+ res.push(...result.result.result.filter(i => i).map(i => i[this.key]).flat());
2342
+ }
2343
+ }
2344
+ return (this.map) ?
2345
+ this.map({ [this.key]: res })
2346
+ : res;
2347
+ }
2348
+ throw new Error('wrong batch');
2349
+ }));
2350
+ }
2351
+ return this.mapResForGetAll(items);
2352
+ }
2353
+ return this.mapResForGetAll(items);
2354
+ }), catchError(err => {
2355
+ console.error(err);
2356
+ return throwError(() => err);
2357
+ }));
2358
+ }
2359
+ mapResForGetAll(items) {
2360
+ return (instanceOfiBXRestAnswerSuccess(items)) ? from([items.result]).pipe(map(v => (v && this.map) ? this.map(v) : v)) : from([]);
2361
+ }
2362
+ }
2363
+
2308
2364
  class NavvySupport {
2309
2365
  constructor(requestClass) {
2310
2366
  this.requestClass = requestClass;
@@ -2351,6 +2407,9 @@ class Navvy {
2351
2407
  arg, map) {
2352
2408
  return new NavvyPagNavTasks(url, arg, map);
2353
2409
  }
2410
+ pagNavResultKey(url, arg, key, map) {
2411
+ return new NavvyPagNavResultKey(url, arg, key, map);
2412
+ }
2354
2413
  pagNavWithUselessKey(url,
2355
2414
  // func: (param: A) => Observable<iBXRestAnswer<{ [key: string]: T }> | undefined>,
2356
2415
  arg, map) {
@@ -6054,6 +6113,17 @@ class BXRestMapCrmQuoteUserField {
6054
6113
  }
6055
6114
  }
6056
6115
 
6116
+ class BXRestMapCrmAutomatedSolution {
6117
+ /** Возвращает цифровое рабочее место из контейнера REST-ответа. */
6118
+ static get(v) {
6119
+ return v?.automatedSolution;
6120
+ }
6121
+ /** Возвращает список цифровых рабочих мест из контейнера REST-ответа. */
6122
+ static list(v) {
6123
+ return v?.automatedSolutions;
6124
+ }
6125
+ }
6126
+
6057
6127
  class BXRestNavvyCrmLead {
6058
6128
  constructor() {
6059
6129
  this.url = {
@@ -6715,8 +6785,80 @@ class BXRestNavvyCrmAutomation {
6715
6785
  }
6716
6786
  }
6717
6787
 
6788
+ class BXRestNavvyCrmAutomatedSolution {
6789
+ constructor() {
6790
+ this.url = {
6791
+ /** Создает новое цифровое рабочее место. */
6792
+ add: [$crm, $automatedsolution, $add],
6793
+ /** Возвращает цифровое рабочее место по идентификатору. */
6794
+ get: [$crm, $automatedsolution, $get],
6795
+ /** Возвращает список цифровых рабочих мест. */
6796
+ list: [$crm, $automatedsolution, $list],
6797
+ /** Обновляет существующее цифровое рабочее место. */
6798
+ update: [$crm, $automatedsolution, $update],
6799
+ /** Удаляет цифровое рабочее место. */
6800
+ delete: [$crm, $automatedsolution, $delete],
6801
+ /** Возвращает описание полей цифрового рабочего места. */
6802
+ fields: [$crm, $automatedsolution, 'fields']
6803
+ };
6804
+ this.Navvy = new Navvy();
6805
+ }
6806
+ /**
6807
+ * Создает новое цифровое рабочее место.
6808
+ *
6809
+ * @see https://apidocs.bitrix24.ru/api-reference/crm/automated-solution/crm-automated-solution-add.html
6810
+ */
6811
+ add(param) {
6812
+ return this.Navvy.simple(this.url.add, param, BXRestMapCrmAutomatedSolution.get);
6813
+ }
6814
+ /**
6815
+ * Возвращает цифровое рабочее место по идентификатору.
6816
+ *
6817
+ * @see https://apidocs.bitrix24.ru/api-reference/crm/automated-solution/crm-automated-solution-get.html
6818
+ */
6819
+ get(param) {
6820
+ return this.Navvy.simple(this.url.get, param, BXRestMapCrmAutomatedSolution.get);
6821
+ }
6822
+ /**
6823
+ * Возвращает список цифровых рабочих мест.
6824
+ *
6825
+ * @see https://apidocs.bitrix24.ru/api-reference/crm/automated-solution/crm-automated-solution-list.html
6826
+ */
6827
+ list(param = {}) {
6828
+ return this.Navvy.pagNavResultKey(this.url.list, param, 'automatedSolutions', BXRestMapCrmAutomatedSolution.list);
6829
+ }
6830
+ /**
6831
+ * Обновляет существующее цифровое рабочее место.
6832
+ * При передаче `typeIds` список привязанных смарт-процессов перезаписывается целиком.
6833
+ *
6834
+ * @see https://apidocs.bitrix24.ru/api-reference/crm/automated-solution/crm-automated-solution-update.html
6835
+ */
6836
+ update(param) {
6837
+ return this.Navvy.simple(this.url.update, param, BXRestMapCrmAutomatedSolution.get);
6838
+ }
6839
+ /**
6840
+ * Удаляет цифровое рабочее место.
6841
+ * Удаление возможно только если к рабочему месту не привязаны смарт-процессы.
6842
+ *
6843
+ * @see https://apidocs.bitrix24.ru/api-reference/crm/automated-solution/crm-automated-solution-delete.html
6844
+ */
6845
+ delete(param) {
6846
+ return this.Navvy.simple(this.url.delete, param);
6847
+ }
6848
+ /**
6849
+ * Возвращает описание полей цифрового рабочего места.
6850
+ *
6851
+ * @see https://apidocs.bitrix24.ru/api-reference/crm/automated-solution/crm-automated-solution-fields.html
6852
+ */
6853
+ fields() {
6854
+ return this.Navvy.simple(this.url.fields);
6855
+ }
6856
+ }
6857
+
6718
6858
  class BXRestNavvyCrm {
6719
6859
  constructor() {
6860
+ /** Цифровые рабочие места (`crm.automatedsolution.*`). */
6861
+ this.automatedSolution = new BXRestNavvyCrmAutomatedSolution();
6720
6862
  /** Автоматизация CRM (`crm.automation.*`). */
6721
6863
  this.automation = new BXRestNavvyCrmAutomation();
6722
6864
  /** Перечисления CRM (`crm.enum.*`). */