bx-rest 0.6.8 → 0.8.2

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 (65) hide show
  1. package/esm2022/map/pull.mjs +12 -10
  2. package/esm2022/map/user.mjs +1 -1
  3. package/esm2022/public-api.mjs +2 -2
  4. package/esm2022/request/user.mjs +1 -1
  5. package/esm2022/request-navvy/pull/config.mjs +5 -1
  6. package/esm2022/request-navvy/task/operation/elapseditem.mjs +1 -1
  7. package/esm2022/request-navvy/timeman.mjs +30 -18
  8. package/esm2022/request-navvy/user.mjs +1 -1
  9. package/esm2022/services/base.mjs +4 -4
  10. package/esm2022/services/http/HttpBX.mjs +38 -4
  11. package/esm2022/services/http/HttpData.mjs +2 -2
  12. package/esm2022/services/http/http.mjs +25 -1
  13. package/esm2022/services/http/httpNavvy.mjs +1 -1
  14. package/esm2022/services/http/sessionKey.mjs +6 -2
  15. package/esm2022/typification/base.mjs +5 -0
  16. package/esm2022/typification/rest/base.mjs +5 -0
  17. package/esm2022/typification/rest/timeman/status.mjs +1 -1
  18. package/esm2022/typification/rest/user/userFilter.mjs +2 -0
  19. package/esm2022/typification/rest/user.mjs +8 -0
  20. package/esm2022/typification/settings.mjs +1 -1
  21. package/fesm2022/bx-rest.mjs +113 -33
  22. package/fesm2022/bx-rest.mjs.map +1 -1
  23. package/map/user.d.ts +1 -1
  24. package/package.json +17 -11
  25. package/public-api.d.ts +1 -1
  26. package/request/app.d.ts +1 -1
  27. package/request/bizproc/workflow.d.ts +1 -1
  28. package/request/department.d.ts +4 -4
  29. package/request/disk/attachedObject.d.ts +1 -1
  30. package/request/disk/file.d.ts +2 -2
  31. package/request/disk/folder.d.ts +12 -12
  32. package/request/disk/storage.d.ts +4 -4
  33. package/request/lists/element.d.ts +2 -2
  34. package/request/lists/field.d.ts +1 -1
  35. package/request/lists.d.ts +1 -1
  36. package/request/log/blogpost.d.ts +2 -2
  37. package/request/pull/application/config.d.ts +1 -1
  38. package/request/pull/channel/public.d.ts +1 -1
  39. package/request/pull/config.d.ts +1 -1
  40. package/request/server.d.ts +1 -1
  41. package/request/socialnetwork/api/contentview.d.ts +1 -1
  42. package/request/socialnetwork/api/livefeed/blogpost/important.d.ts +1 -1
  43. package/request/sonet_group.d.ts +1 -1
  44. package/request/task/commentitem.d.ts +5 -5
  45. package/request/task/elapseditem.d.ts +5 -5
  46. package/request/task/item/userfield.d.ts +1 -1
  47. package/request/task/planner.d.ts +1 -1
  48. package/request/tasks/task/result.d.ts +3 -3
  49. package/request/tasks/task.d.ts +9 -9
  50. package/request/timeman.d.ts +1 -1
  51. package/request/user/userfield.d.ts +1 -1
  52. package/request/user.d.ts +10 -10
  53. package/request-navvy/pull/config.d.ts +4 -0
  54. package/request-navvy/task/operation/elapseditem.d.ts +1 -1
  55. package/request-navvy/timeman.d.ts +22 -2
  56. package/request-navvy/user.d.ts +3 -3
  57. package/rest/base.d.ts +2 -2
  58. package/services/http/HttpBX.d.ts +1 -0
  59. package/services/http/httpNavvy.d.ts +1 -1
  60. package/typification/base.d.ts +4 -0
  61. package/typification/rest/base.d.ts +4 -0
  62. package/typification/rest/timeman/status.d.ts +76 -1
  63. package/typification/rest/user/userFilter.d.ts +13 -0
  64. package/typification/rest/user.d.ts +7 -0
  65. package/typification/settings.d.ts +2 -2
@@ -269,9 +269,9 @@ async function getBase64FileLikeStr(file) {
269
269
  return undefined;
270
270
  }
271
271
  function prepareBaseAddress(url, add = '') {
272
- if (url.search('https://') !== 0 && url.search('http://')) {
273
- url = 'https://' + url;
274
- }
272
+ // if (url.search('https://') !== 0 && url.search('http://')) {
273
+ // url = 'https://' + url
274
+ // }
275
275
  if (add && add.length > 0) {
276
276
  if (url.lastIndexOf('/') !== (url.length - 1)) {
277
277
  url = url + '/';
@@ -424,7 +424,11 @@ class SessionKeyServices {
424
424
  return '';
425
425
  }
426
426
  getAuthParams() {
427
- switch (this.BX_REST_SETTINGS.auth.source) {
427
+ const source = this.BX_REST_SETTINGS.auth.source;
428
+ if (typeof source === 'function') {
429
+ return source();
430
+ }
431
+ switch (source) {
428
432
  case 'cookies':
429
433
  return this.getAuth();
430
434
  case 'localStorage':
@@ -506,7 +510,7 @@ class HttpData {
506
510
  case 'function':
507
511
  case 'undefined':
508
512
  default:
509
- console.error('Ты отправил что-то не то', obj[key], typeof obj[key], typeof obj);
513
+ console.error('You sent something wrong', obj[key], typeof obj[key], typeof obj);
510
514
  }
511
515
  }
512
516
  }
@@ -544,6 +548,30 @@ class HttpServices extends BaseHttp {
544
548
  return throwError(() => new Error('get base url error'));
545
549
  }
546
550
  const fullUrl = prepareBaseAddress(baseUrl) + url;
551
+ if (this.session.getKeyAuth() === 'sessid') {
552
+ const body = this.getHttpParamsPost(paramsClone, new FormData(), [], settings);
553
+ // Преобразуем параметры в формат x-www-form-urlencoded
554
+ const urlEncodedBody = new URLSearchParams();
555
+ Object.keys(body).forEach((key) => {
556
+ const value = paramsClone[key];
557
+ // если value — объект или массив, Bitrix ожидает fields[key] или array[] формат
558
+ if (typeof value === 'object' && value !== null) {
559
+ for (const subKey in value) {
560
+ if (Object.prototype.hasOwnProperty.call(value, subKey)) {
561
+ urlEncodedBody.append(`${key}[${subKey}]`, value[subKey]);
562
+ }
563
+ }
564
+ }
565
+ else {
566
+ urlEncodedBody.append(key, value);
567
+ }
568
+ });
569
+ return from(this.axiosInstance.post(fullUrl, urlEncodedBody.toString(), {
570
+ headers: {
571
+ 'Content-Type': 'application/x-www-form-urlencoded',
572
+ },
573
+ }).then((response) => response.data));
574
+ }
547
575
  const body = this.getHttpParamsPost(paramsClone, new FormData(), [], settings);
548
576
  return from(this.axiosInstance.post(fullUrl, body).then((response) => response.data));
549
577
  }));
@@ -636,27 +664,61 @@ class HttpBXServices extends HttpServices {
636
664
  }
637
665
  httpPost(url, params = {}) {
638
666
  const paramsClone = clone(params);
667
+ const key = this.session.getKeyAuth();
639
668
  let auth = this.session.getAuthParams();
640
669
  const checkIsOn = this.session.getCheckAuthParamsIsOn();
641
- if (checkIsOn) {
670
+ if (checkIsOn && key === 'OAuth2') {
642
671
  if (!auth && BXRestSettings.date.auth.source !== 'off') {
643
672
  throw new Error('Authorization required (post)');
644
673
  }
645
- paramsClone[this.session.getKeyAuth()] = auth;
674
+ paramsClone[key] = auth;
646
675
  }
647
676
  return this.session.getBaseUrl().pipe(switchMap((baseUrl) => {
648
677
  if (!baseUrl) {
649
678
  return throwError(() => new Error('get base url error'));
650
679
  }
651
680
  const fullUrl = prepareBaseAddress(baseUrl) + url;
652
- // const body = this.getHttpParamsPost(paramsClone, new FormData(), false, [])
681
+ if (auth === 'sessid') {
682
+ // Преобразуем параметры в формат x-www-form-urlencoded
683
+ const bodyString = this.serializeBitrixParams(paramsClone);
684
+ return from(this.axiosInstance.post(fullUrl, bodyString, {
685
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
686
+ }).then((response) => response.data));
687
+ }
653
688
  return from(this.axiosInstance.post(fullUrl, paramsClone, {
689
+ withCredentials: key === 'OAuth2',
654
690
  headers: {
655
691
  'Content-Type': 'application/json',
656
692
  }
657
693
  }).then((response) => response.data));
658
694
  }));
659
695
  }
696
+ serializeBitrixParams(obj, prefix = '') {
697
+ const pairs = [];
698
+ for (const key in obj) {
699
+ if (!Object.prototype.hasOwnProperty.call(obj, key))
700
+ continue;
701
+ const value = obj[key];
702
+ const prefixedKey = prefix ? `${prefix}[${key}]` : key;
703
+ if (Array.isArray(value)) {
704
+ value.forEach((item) => {
705
+ if (typeof item === 'object') {
706
+ pairs.push(this.serializeBitrixParams(item, `${prefixedKey}[]`));
707
+ }
708
+ else {
709
+ pairs.push(`${encodeURIComponent(prefixedKey)}[]=${encodeURIComponent(item)}`);
710
+ }
711
+ });
712
+ }
713
+ else if (typeof value === 'object' && value !== null) {
714
+ pairs.push(this.serializeBitrixParams(value, prefixedKey));
715
+ }
716
+ else {
717
+ pairs.push(`${encodeURIComponent(prefixedKey)}=${encodeURIComponent(value)}`);
718
+ }
719
+ }
720
+ return pairs.join('&');
721
+ }
660
722
  // Мб не работает
661
723
  httpGet(url, params = {}) {
662
724
  if (params === null) {
@@ -5890,26 +5952,26 @@ class BXRestMapTimeMan {
5890
5952
  class BXRestNavvyTimeMan {
5891
5953
  constructor() {
5892
5954
  this.url = {
5893
- // /**
5894
- // * Получение настроек рабочего времени пользователя
5895
- // */
5896
- // settings: [$timeMan, $settings],
5955
+ /**
5956
+ * Получение настроек рабочего времени пользователя
5957
+ */
5958
+ settings: [$timeMan, $settings],
5897
5959
  /**
5898
5960
  * Получение информации о текущем рабочем дне пользователя
5899
5961
  */
5900
5962
  status: [$timeMan, $status],
5901
- // /**
5902
- // * Начать новый рабочий день либо возобновить закрытый или приостановленный
5903
- // */
5904
- // open: [$timeMan, 'open'],
5905
- // /**
5906
- // * Закрыть рабочий день
5907
- // */
5908
- // close: [$timeMan, 'close'],
5909
- // /**
5910
- // * Приостановить рабочий день
5911
- // */
5912
- // pause: [$timeMan, $pause],
5963
+ /**
5964
+ * Начать новый рабочий день либо возобновить закрытый или приостановленный
5965
+ */
5966
+ open: [$timeMan, 'open'],
5967
+ /**
5968
+ * Закрыть рабочий день
5969
+ */
5970
+ close: [$timeMan, 'close'],
5971
+ /**
5972
+ * Приостановить рабочий день
5973
+ */
5974
+ pause: [$timeMan, $pause],
5913
5975
  // networkrange: {
5914
5976
  // check: this.baseUrl + 'networkrange.check', // Метод для проверки IP-адреса на вхождение в диапазоны сетевых адресов офисной сети
5915
5977
  // get: this.baseUrl + 'networkrange.get', // Метод для получения диапазонов сетевых адресов, входящих в офисную сеть
@@ -5940,6 +6002,18 @@ class BXRestNavvyTimeMan {
5940
6002
  status(param = undefined) {
5941
6003
  return this.Navvy.simple(this.url.status, param, BXRestMapTimeMan.status);
5942
6004
  }
6005
+ open(param = {}) {
6006
+ return this.Navvy.simple(this.url.open, param, BXRestMapTimeMan.status);
6007
+ }
6008
+ pause(param = {}) {
6009
+ return this.Navvy.simple(this.url.pause, param, BXRestMapTimeMan.status);
6010
+ }
6011
+ close(param = {}) {
6012
+ return this.Navvy.simple(this.url.close, param, BXRestMapTimeMan.status);
6013
+ }
6014
+ settings(param = {}) {
6015
+ return this.Navvy.simple(this.url.settings, param);
6016
+ }
5943
6017
  }
5944
6018
 
5945
6019
  class BXRestNavvySocialNetWorkApiContentView {
@@ -6035,15 +6109,17 @@ class BXRestMapPullApplicationConfig {
6035
6109
 
6036
6110
  class BXRestMapPull {
6037
6111
  static get(value) {
6038
- console.log('Object.entries(value.publicChannels)', value);
6039
- if (value?.publicChannels) {
6040
- console.log('Object.entries(value.publicChannels)', value.publicChannels, Object.entries(value.publicChannels), Object.fromEntries(Object.entries(value.publicChannels).map(([key, val]) => ([key,
6041
- {
6042
- ...val,
6043
- start: toDate(val.start), end: toDate(val.end)
6044
- }
6045
- ]))));
6046
- }
6112
+ // console.log('Object.entries(value.publicChannels)', value)
6113
+ //if(value?.publicChannels) {
6114
+ // console.log('Object.entries(value.publicChannels)',
6115
+ // value.publicChannels, Object.entries(value.publicChannels), Object.fromEntries(Object.entries(value.publicChannels).map(([key, val]) => (
6116
+ // [key,
6117
+ // {
6118
+ // ...val,
6119
+ // start: toDate(val.start), end: toDate(val.end)
6120
+ // } as iBXRestPullConfigPublicChannelsGet
6121
+ // ]))) as Record<string, iBXRestPullConfigPublicChannelsGet>,)
6122
+ //}
6047
6123
  return value ? { ...BXRestMapPullApplicationConfig.get(value), ...{ serverTime: toDate(value.serverTime) } } : undefined;
6048
6124
  }
6049
6125
  }
@@ -6070,6 +6146,10 @@ class BXRestNavvyPullConfig {
6070
6146
  this.Navvy = new Navvy();
6071
6147
  }
6072
6148
  static { this.public = new BXRestMapPullChannelPublic(); }
6149
+ /**
6150
+ * @experimental
6151
+ * Этот метод находится в процессе тестирования и может измениться.
6152
+ */
6073
6153
  get() {
6074
6154
  return this.Navvy.simple(this.url.get, undefined, BXRestMapPull.get);
6075
6155
  }