@2bad/bitrix 2.5.1 → 3.0.0-beta.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 (242) hide show
  1. package/README.md +1 -2
  2. package/build/bitrix.d.ts +65 -0
  3. package/build/bitrix.js +55 -0
  4. package/build/client/hooks/addAccessToken.js +9 -0
  5. package/build/{module/client → client}/index.d.ts +3 -3
  6. package/build/{module/client → client}/index.js +21 -16
  7. package/build/{module/client → client}/methods/batch.d.ts +6 -6
  8. package/build/client/methods/batch.js +75 -0
  9. package/build/{module/client → client}/methods/call.d.ts +4 -4
  10. package/build/{module/client → client}/methods/call.js +8 -9
  11. package/build/{module/client → client}/methods/list.d.ts +10 -10
  12. package/build/client/methods/list.js +58 -0
  13. package/build/{module/commands.d.ts → commands.d.ts} +3 -3
  14. package/build/commands.js +1 -0
  15. package/build/{module/methods.d.ts → methods.d.ts} +19 -19
  16. package/build/{module/methods.js → methods.js} +5 -5
  17. package/build/{main/payloads.d.ts → payloads.d.ts} +5 -5
  18. package/build/payloads.js +1 -0
  19. package/build/{main/services → services}/common.d.ts +7 -7
  20. package/build/services/common.js +2 -0
  21. package/build/{main/services → services}/companies/entities.d.ts +2 -2
  22. package/build/services/companies/entities.js +1 -0
  23. package/build/services/companies/index.d.ts +15 -0
  24. package/build/services/companies/index.js +17 -0
  25. package/build/{module/services → services}/companies/methods.d.ts +5 -5
  26. package/build/services/companies/methods.js +1 -0
  27. package/build/{module/services → services}/contacts/entities.d.ts +2 -2
  28. package/build/services/contacts/entities.js +1 -0
  29. package/build/services/contacts/index.d.ts +15 -0
  30. package/build/services/contacts/index.js +17 -0
  31. package/build/{module/services → services}/contacts/methods.d.ts +5 -5
  32. package/build/services/contacts/methods.js +1 -0
  33. package/build/{module/services → services}/currencies/entities.d.ts +2 -2
  34. package/build/services/currencies/entities.js +1 -0
  35. package/build/{module/services → services}/deals/entities.d.ts +2 -2
  36. package/build/services/deals/entities.js +1 -0
  37. package/build/services/deals/index.d.ts +15 -0
  38. package/build/services/deals/index.js +17 -0
  39. package/build/{main/services → services}/deals/methods.d.ts +5 -5
  40. package/build/services/deals/methods.js +1 -0
  41. package/build/{module/services → services}/leads/entities.d.ts +2 -2
  42. package/build/services/leads/entities.js +1 -0
  43. package/build/services/leads/index.d.ts +15 -0
  44. package/build/services/leads/index.js +17 -0
  45. package/build/{main/services → services}/leads/methods.d.ts +5 -5
  46. package/build/services/leads/methods.js +1 -0
  47. package/build/{main/services → services}/statuses/entities.d.ts +3 -3
  48. package/build/services/statuses/entities.js +1 -0
  49. package/build/services/statuses/index.d.ts +14 -0
  50. package/build/services/statuses/index.js +19 -0
  51. package/build/{main/services → services}/statuses/methods.d.ts +5 -5
  52. package/build/services/statuses/methods.js +1 -0
  53. package/build/{module/services → services}/users/entities.d.ts +2 -2
  54. package/build/services/users/entities.js +1 -0
  55. package/build/services/users/index.d.ts +9 -0
  56. package/build/services/users/index.js +7 -0
  57. package/build/{main/services → services}/users/methods.d.ts +4 -4
  58. package/build/services/users/methods.js +1 -0
  59. package/build/utils/Diff.d.ts +1 -0
  60. package/build/utils/Diff.js +7 -0
  61. package/build/{module/utils → utils}/ExtractValue.d.ts +1 -1
  62. package/build/{main/utils/ExtractValue.d.ts → utils/ExtractValue.js} +1 -2
  63. package/build/utils/isArray.d.ts +2 -0
  64. package/build/{module/utils → utils}/isArray.js +1 -1
  65. package/package.json +43 -49
  66. package/build/main/bitrix.d.ts +0 -114
  67. package/build/main/bitrix.integration.test.d.ts +0 -0
  68. package/build/main/bitrix.integration.test.js +0 -31
  69. package/build/main/bitrix.js +0 -61
  70. package/build/main/bitrix.unit.test.d.ts +0 -1
  71. package/build/main/bitrix.unit.test.js +0 -44
  72. package/build/main/client/client.unit.test.d.ts +0 -1
  73. package/build/main/client/client.unit.test.js +0 -70
  74. package/build/main/client/hooks/addAccessToken.js +0 -13
  75. package/build/main/client/hooks/addAccessToken.unit.test.d.ts +0 -1
  76. package/build/main/client/hooks/addAccessToken.unit.test.js +0 -31
  77. package/build/main/client/index.d.ts +0 -15
  78. package/build/main/client/index.js +0 -53
  79. package/build/main/client/methods/batch.d.ts +0 -40
  80. package/build/main/client/methods/batch.js +0 -85
  81. package/build/main/client/methods/batch.unit.test.d.ts +0 -1
  82. package/build/main/client/methods/batch.unit.test.js +0 -494
  83. package/build/main/client/methods/call.d.ts +0 -17
  84. package/build/main/client/methods/call.js +0 -36
  85. package/build/main/client/methods/call.unit.test.d.ts +0 -1
  86. package/build/main/client/methods/call.unit.test.js +0 -183
  87. package/build/main/client/methods/list.d.ts +0 -30
  88. package/build/main/client/methods/list.js +0 -66
  89. package/build/main/client/methods/list.unit.test.d.ts +0 -1
  90. package/build/main/client/methods/list.unit.test.js +0 -277
  91. package/build/main/commands.d.ts +0 -10
  92. package/build/main/commands.js +0 -2
  93. package/build/main/methods.d.ts +0 -92
  94. package/build/main/methods.js +0 -41
  95. package/build/main/payloads.js +0 -2
  96. package/build/main/services/common.js +0 -2
  97. package/build/main/services/companies/entities.js +0 -2
  98. package/build/main/services/companies/index.d.ts +0 -26
  99. package/build/main/services/companies/index.integration.test.d.ts +0 -1
  100. package/build/main/services/companies/index.integration.test.js +0 -19
  101. package/build/main/services/companies/index.js +0 -10
  102. package/build/main/services/companies/index.unit.test.d.ts +0 -1
  103. package/build/main/services/companies/index.unit.test.js +0 -72
  104. package/build/main/services/companies/methods.d.ts +0 -44
  105. package/build/main/services/companies/methods.js +0 -3
  106. package/build/main/services/contacts/entities.d.ts +0 -45
  107. package/build/main/services/contacts/entities.js +0 -2
  108. package/build/main/services/contacts/index.d.ts +0 -26
  109. package/build/main/services/contacts/index.integration.test.d.ts +0 -1
  110. package/build/main/services/contacts/index.integration.test.js +0 -19
  111. package/build/main/services/contacts/index.js +0 -10
  112. package/build/main/services/contacts/index.unit.test.d.ts +0 -1
  113. package/build/main/services/contacts/index.unit.test.js +0 -72
  114. package/build/main/services/contacts/methods.d.ts +0 -44
  115. package/build/main/services/contacts/methods.js +0 -3
  116. package/build/main/services/currencies/entities.d.ts +0 -15
  117. package/build/main/services/currencies/entities.js +0 -2
  118. package/build/main/services/deals/entities.d.ts +0 -43
  119. package/build/main/services/deals/entities.js +0 -2
  120. package/build/main/services/deals/index.d.ts +0 -26
  121. package/build/main/services/deals/index.integration.test.d.ts +0 -1
  122. package/build/main/services/deals/index.integration.test.js +0 -19
  123. package/build/main/services/deals/index.js +0 -10
  124. package/build/main/services/deals/index.unit.test.d.ts +0 -1
  125. package/build/main/services/deals/index.unit.test.js +0 -72
  126. package/build/main/services/deals/methods.js +0 -3
  127. package/build/main/services/leads/entities.d.ts +0 -49
  128. package/build/main/services/leads/entities.js +0 -2
  129. package/build/main/services/leads/index.d.ts +0 -26
  130. package/build/main/services/leads/index.integration.test.d.ts +0 -1
  131. package/build/main/services/leads/index.integration.test.js +0 -19
  132. package/build/main/services/leads/index.js +0 -10
  133. package/build/main/services/leads/index.unit.test.d.ts +0 -1
  134. package/build/main/services/leads/index.unit.test.js +0 -72
  135. package/build/main/services/leads/methods.js +0 -3
  136. package/build/main/services/statuses/entities.js +0 -2
  137. package/build/main/services/statuses/index.d.ts +0 -14
  138. package/build/main/services/statuses/index.integration.test.d.ts +0 -1
  139. package/build/main/services/statuses/index.integration.test.js +0 -90
  140. package/build/main/services/statuses/index.js +0 -11
  141. package/build/main/services/statuses/index.unit.test.d.ts +0 -1
  142. package/build/main/services/statuses/index.unit.test.js +0 -60
  143. package/build/main/services/statuses/methods.js +0 -3
  144. package/build/main/services/users/entities.d.ts +0 -40
  145. package/build/main/services/users/entities.js +0 -2
  146. package/build/main/services/users/index.d.ts +0 -9
  147. package/build/main/services/users/index.integration.test.d.ts +0 -1
  148. package/build/main/services/users/index.integration.test.js +0 -33
  149. package/build/main/services/users/index.js +0 -7
  150. package/build/main/services/users/index.unit.test.d.ts +0 -1
  151. package/build/main/services/users/index.unit.test.js +0 -25
  152. package/build/main/services/users/methods.js +0 -3
  153. package/build/main/utils/Diff.d.ts +0 -1
  154. package/build/main/utils/Diff.js +0 -2
  155. package/build/main/utils/ExtractValue.js +0 -2
  156. package/build/main/utils/isArray.d.ts +0 -2
  157. package/build/main/utils/isArray.js +0 -4
  158. package/build/module/bitrix.d.ts +0 -114
  159. package/build/module/bitrix.integration.test.d.ts +0 -0
  160. package/build/module/bitrix.integration.test.js +0 -31
  161. package/build/module/bitrix.js +0 -40
  162. package/build/module/bitrix.unit.test.d.ts +0 -1
  163. package/build/module/bitrix.unit.test.js +0 -16
  164. package/build/module/client/client.unit.test.d.ts +0 -1
  165. package/build/module/client/client.unit.test.js +0 -65
  166. package/build/module/client/hooks/addAccessToken.d.ts +0 -6
  167. package/build/module/client/hooks/addAccessToken.js +0 -11
  168. package/build/module/client/hooks/addAccessToken.unit.test.d.ts +0 -1
  169. package/build/module/client/hooks/addAccessToken.unit.test.js +0 -26
  170. package/build/module/client/methods/batch.js +0 -76
  171. package/build/module/client/methods/batch.unit.test.d.ts +0 -1
  172. package/build/module/client/methods/batch.unit.test.js +0 -466
  173. package/build/module/client/methods/call.unit.test.d.ts +0 -1
  174. package/build/module/client/methods/call.unit.test.js +0 -155
  175. package/build/module/client/methods/list.js +0 -55
  176. package/build/module/client/methods/list.unit.test.d.ts +0 -1
  177. package/build/module/client/methods/list.unit.test.js +0 -252
  178. package/build/module/commands.js +0 -1
  179. package/build/module/payloads.d.ts +0 -40
  180. package/build/module/payloads.js +0 -1
  181. package/build/module/services/common.d.ts +0 -22
  182. package/build/module/services/common.js +0 -1
  183. package/build/module/services/companies/entities.d.ts +0 -54
  184. package/build/module/services/companies/entities.js +0 -1
  185. package/build/module/services/companies/index.d.ts +0 -26
  186. package/build/module/services/companies/index.integration.test.d.ts +0 -1
  187. package/build/module/services/companies/index.integration.test.js +0 -14
  188. package/build/module/services/companies/index.js +0 -8
  189. package/build/module/services/companies/index.unit.test.d.ts +0 -1
  190. package/build/module/services/companies/index.unit.test.js +0 -67
  191. package/build/module/services/companies/methods.js +0 -1
  192. package/build/module/services/contacts/entities.js +0 -1
  193. package/build/module/services/contacts/index.d.ts +0 -26
  194. package/build/module/services/contacts/index.integration.test.d.ts +0 -1
  195. package/build/module/services/contacts/index.integration.test.js +0 -14
  196. package/build/module/services/contacts/index.js +0 -8
  197. package/build/module/services/contacts/index.unit.test.d.ts +0 -1
  198. package/build/module/services/contacts/index.unit.test.js +0 -67
  199. package/build/module/services/contacts/methods.js +0 -1
  200. package/build/module/services/currencies/entities.js +0 -1
  201. package/build/module/services/deals/entities.js +0 -1
  202. package/build/module/services/deals/index.d.ts +0 -26
  203. package/build/module/services/deals/index.integration.test.d.ts +0 -1
  204. package/build/module/services/deals/index.integration.test.js +0 -14
  205. package/build/module/services/deals/index.js +0 -8
  206. package/build/module/services/deals/index.unit.test.d.ts +0 -1
  207. package/build/module/services/deals/index.unit.test.js +0 -67
  208. package/build/module/services/deals/methods.d.ts +0 -44
  209. package/build/module/services/deals/methods.js +0 -1
  210. package/build/module/services/leads/entities.js +0 -1
  211. package/build/module/services/leads/index.d.ts +0 -26
  212. package/build/module/services/leads/index.integration.test.d.ts +0 -1
  213. package/build/module/services/leads/index.integration.test.js +0 -14
  214. package/build/module/services/leads/index.js +0 -8
  215. package/build/module/services/leads/index.unit.test.d.ts +0 -1
  216. package/build/module/services/leads/index.unit.test.js +0 -67
  217. package/build/module/services/leads/methods.d.ts +0 -44
  218. package/build/module/services/leads/methods.js +0 -1
  219. package/build/module/services/statuses/entities.d.ts +0 -16
  220. package/build/module/services/statuses/entities.js +0 -1
  221. package/build/module/services/statuses/index.d.ts +0 -14
  222. package/build/module/services/statuses/index.integration.test.d.ts +0 -1
  223. package/build/module/services/statuses/index.integration.test.js +0 -85
  224. package/build/module/services/statuses/index.js +0 -9
  225. package/build/module/services/statuses/index.unit.test.d.ts +0 -1
  226. package/build/module/services/statuses/index.unit.test.js +0 -55
  227. package/build/module/services/statuses/methods.d.ts +0 -51
  228. package/build/module/services/statuses/methods.js +0 -1
  229. package/build/module/services/users/entities.js +0 -1
  230. package/build/module/services/users/index.d.ts +0 -9
  231. package/build/module/services/users/index.integration.test.d.ts +0 -1
  232. package/build/module/services/users/index.integration.test.js +0 -28
  233. package/build/module/services/users/index.js +0 -5
  234. package/build/module/services/users/index.unit.test.d.ts +0 -1
  235. package/build/module/services/users/index.unit.test.js +0 -20
  236. package/build/module/services/users/methods.d.ts +0 -17
  237. package/build/module/services/users/methods.js +0 -1
  238. package/build/module/utils/Diff.d.ts +0 -1
  239. package/build/module/utils/Diff.js +0 -1
  240. package/build/module/utils/ExtractValue.js +0 -1
  241. package/build/module/utils/isArray.d.ts +0 -2
  242. /package/build/{main/client → client}/hooks/addAccessToken.d.ts +0 -0
@@ -1,183 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const got_1 = __importDefault(require("got"));
30
- const nock_1 = __importDefault(require("nock"));
31
- const methods_1 = require("../../methods");
32
- const call_1 = __importStar(require("./call"));
33
- const TEST_URI = 'https://test.com/rest';
34
- const call = (0, call_1.default)({
35
- get: got_1.default.extend({ prefixUrl: TEST_URI, responseType: 'json' }).get
36
- });
37
- const RESPONSE_200 = 200;
38
- describe('Client `handlePayload` method', () => {
39
- it('should return `GetPayload`', () => {
40
- const payload = {
41
- result: 'done',
42
- time: { start: 1, finish: 1, duration: 1, processing: 1, date_start: 'date', date_finish: 'date' }
43
- };
44
- expect((0, call_1.handlePayload)(payload)).toBe(payload);
45
- });
46
- it('should return `ListPayload`', () => {
47
- const payload = {
48
- error: undefined,
49
- next: undefined,
50
- result: ['done'],
51
- time: { start: 1, finish: 1, duration: 1, processing: 1, date_start: 'date', date_finish: 'date' },
52
- total: 1
53
- };
54
- expect((0, call_1.handlePayload)(payload)).toBe(payload);
55
- });
56
- it('should throw when getting error in `ListPayload`', () => {
57
- const payload = {
58
- error: 'Expected error for `handlePayload`',
59
- next: undefined,
60
- result: ['done'],
61
- time: { start: 1, finish: 1, duration: 1, processing: 1, date_start: 'date', date_finish: 'date' },
62
- total: 1
63
- };
64
- expect(() => (0, call_1.handlePayload)(payload)).toThrowErrorMatchingSnapshot();
65
- });
66
- it('should return `BatchPayload` with numbered commands', () => {
67
- const payload = {
68
- result: {
69
- result: { one: 'done' },
70
- result_error: [],
71
- result_next: [],
72
- result_time: [],
73
- result_total: []
74
- },
75
- time: { start: 1, finish: 1, duration: 1, processing: 1, date_start: 'date', date_finish: 'date' }
76
- };
77
- expect((0, call_1.handlePayload)(payload)).toBe(payload);
78
- });
79
- it('should return `BatchPayload` with result from array of commands', () => {
80
- const payload = {
81
- result: {
82
- result: ['done'],
83
- result_error: [],
84
- result_next: [],
85
- result_time: [],
86
- result_total: []
87
- },
88
- time: { start: 1, finish: 1, duration: 1, processing: 1, date_start: 'date', date_finish: 'date' }
89
- };
90
- expect((0, call_1.handlePayload)(payload)).toBe(payload);
91
- });
92
- it('should throw when getting errors in `BatchPayload` with result from named commands', () => {
93
- const payload = {
94
- result: {
95
- result: { one: 'done' },
96
- result_error: { one: 'Expected error for `handlePayload`' },
97
- result_next: [],
98
- result_time: [],
99
- result_total: []
100
- },
101
- time: { start: 1, finish: 1, duration: 1, processing: 1, date_start: 'date', date_finish: 'date' }
102
- };
103
- expect(() => (0, call_1.handlePayload)(payload)).toThrowErrorMatchingSnapshot();
104
- });
105
- it('should throw when getting errors in `BatchPayload` with result from array of commands', () => {
106
- const payload = {
107
- result: {
108
- result: ['done'],
109
- result_error: ['Expected error for `handlePayload`'],
110
- result_next: [],
111
- result_time: [],
112
- result_total: []
113
- },
114
- time: { start: 1, finish: 1, duration: 1, processing: 1, date_start: 'date', date_finish: 'date' }
115
- };
116
- expect(() => (0, call_1.handlePayload)(payload)).toThrowErrorMatchingSnapshot();
117
- });
118
- });
119
- describe('Client `call` method', () => {
120
- it('should form a proper request', async () => {
121
- const params = { id: '1' };
122
- const scope = (0, nock_1.default)(TEST_URI)
123
- .get(`/${methods_1.Method.CRM_DEAL_GET}`)
124
- .query(params)
125
- .reply(RESPONSE_200);
126
- await call(methods_1.Method.CRM_DEAL_GET, params);
127
- expect(scope.done()).toBe(undefined);
128
- });
129
- it('should form a proper request with list methods', async () => {
130
- const params = {
131
- filter: { '>PROBABILITY': 50 },
132
- order: { STAGE_ID: 'ASC' },
133
- select: ['ID', 'TITLE'],
134
- start: 50
135
- };
136
- const scope = (0, nock_1.default)(TEST_URI)
137
- .get(`/${methods_1.Method.CRM_DEAL_LIST}`)
138
- .query(params)
139
- .reply(RESPONSE_200);
140
- await call(methods_1.Method.CRM_DEAL_LIST, params);
141
- expect(scope.done()).toBe(undefined);
142
- });
143
- it('should return body as payload', async () => {
144
- const params = { id: '1' };
145
- const payload = { test: 'value' };
146
- (0, nock_1.default)(TEST_URI)
147
- .get(`/${methods_1.Method.CRM_DEAL_GET}`)
148
- .query(params)
149
- .reply(RESPONSE_200, payload);
150
- expect(await call(methods_1.Method.CRM_DEAL_GET, params)).toEqual(payload);
151
- });
152
- it('should return body as payload with list methods', async () => {
153
- const payload = { result: ['done'] };
154
- (0, nock_1.default)(TEST_URI)
155
- .get(`/${methods_1.Method.CRM_DEAL_LIST}`)
156
- .reply(RESPONSE_200, payload);
157
- expect(await call(methods_1.Method.CRM_DEAL_LIST, {})).toEqual(payload);
158
- });
159
- it('should throw when getting errors in payload', () => {
160
- const payload = { result: ['done'], error: 'Expected error for `getList`' };
161
- (0, nock_1.default)(TEST_URI)
162
- .get(`/${methods_1.Method.CRM_DEAL_LIST}`)
163
- .reply(RESPONSE_200, payload);
164
- return expect(call(methods_1.Method.CRM_DEAL_LIST, {})).rejects.toMatchSnapshot();
165
- });
166
- it('should throw when getting errors in batch payload', () => {
167
- const payload = {
168
- result: {
169
- result: ['done'],
170
- result_error: ['Expected error'],
171
- result_next: [],
172
- result_time: [],
173
- result_total: []
174
- },
175
- time: { start: 1, finish: 1, duration: 1, processing: 1, date_start: 'date', date_finish: 'date' }
176
- };
177
- (0, nock_1.default)(TEST_URI)
178
- .get(`/${methods_1.Method.BATCH}`)
179
- .reply(RESPONSE_200, payload);
180
- return expect(call(methods_1.Method.BATCH, {})).rejects.toMatchSnapshot();
181
- });
182
- it.todo('should cast payload to the <P>');
183
- });
@@ -1,30 +0,0 @@
1
- import { Command } from '../../commands';
2
- import { ListableMethod, MethodParams, MethodPayloadType } from '../../methods';
3
- import { BatchPayload, ListPayload } from '../../payloads';
4
- import { Batch } from './batch';
5
- import { Call } from './call';
6
- /**
7
- * Generates required amount of commands to process specified amount of entries
8
- */
9
- export declare const fillWithCommands: <C extends Command>({ method, params }: C, start: number, toProcess: number, entriesPerCommand: number) => readonly {
10
- readonly method: C["method"];
11
- readonly params?: C["params"] | undefined;
12
- }[];
13
- /**
14
- * Get the highest value from object or an array if there's any
15
- */
16
- export declare const highest: (input: ReadonlyArray<number | undefined> | Record<string, number | undefined>) => number | undefined;
17
- /**
18
- * Converts batch payload to a list payload
19
- */
20
- export declare const batchToListPayload: <P>(payload: BatchPayload<Record<string, P> | readonly P[]>) => ListPayload<P>;
21
- declare type Dependencies = {
22
- readonly call: Call;
23
- readonly batch: Batch;
24
- };
25
- export declare type List = <M extends ListableMethod>(method: M, params: MethodParams<M>) => Promise<ListPayload<MethodPayloadType<M>>>;
26
- /**
27
- * Gets all entries by dispatching required amount of requests. Will fill figure out payload type based on the Method.
28
- */
29
- declare const _default: ({ call, batch }: Dependencies) => List;
30
- export default _default;
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.batchToListPayload = exports.highest = exports.fillWithCommands = void 0;
7
- const lodash_range_1 = __importDefault(require("lodash.range"));
8
- const MAX_ENTRIES_PER_COMMAND = 50;
9
- /**
10
- * Generates required amount of commands to process specified amount of entries
11
- */
12
- const fillWithCommands = ({ method, params }, start, toProcess, entriesPerCommand) => {
13
- const requiresCommands = Math.ceil((toProcess - start) / entriesPerCommand);
14
- return (0, lodash_range_1.default)(0, requiresCommands)
15
- .map((i) => ({ method, params: { ...params, start: start + (entriesPerCommand * i) } }));
16
- };
17
- exports.fillWithCommands = fillWithCommands;
18
- /**
19
- * Get the highest value from object or an array if there's any
20
- */
21
- const highest = (input) => Object.values(input).reduce((a, b) => a !== undefined && b !== undefined
22
- ? a > b ? a : b
23
- : a !== undefined && b === undefined
24
- ? a
25
- : a === undefined && b !== undefined
26
- ? b
27
- : undefined, undefined);
28
- exports.highest = highest;
29
- /**
30
- * Converts batch payload to a list payload
31
- */
32
- const batchToListPayload = (payload) => {
33
- var _a;
34
- // eslint-disable-next-line @typescript-eslint/naming-convention
35
- const { result: { result, result_total, result_error, result_next }, time } = payload;
36
- const flattenResult = Object.entries(result).reduce(
37
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
38
- // @ts-expect-error ignore this for now
39
- (flatten, [_key, r]) => !r ? flatten : [...flatten, ...r], []);
40
- return {
41
- error: Object.values(result_error).join('\n'),
42
- next: (0, exports.highest)(result_next),
43
- result: flattenResult,
44
- // @todo Not accurate, we do not care
45
- time,
46
- total: (_a = (0, exports.highest)(result_total)) !== null && _a !== void 0 ? _a : 0
47
- };
48
- };
49
- exports.batchToListPayload = batchToListPayload;
50
- /**
51
- * Gets all entries by dispatching required amount of requests. Will fill figure out payload type based on the Method.
52
- */
53
- exports.default = ({ call, batch }) => {
54
- const list = async (method, params) => {
55
- var _a;
56
- const start = (_a = params.start) !== null && _a !== void 0 ? _a : 0;
57
- const listAll = async () => {
58
- const batchCommands = (0, exports.fillWithCommands)({ method, params }, start, firstCall.total, MAX_ENTRIES_PER_COMMAND);
59
- const payload = await batch(batchCommands);
60
- return (0, exports.batchToListPayload)(payload);
61
- };
62
- const firstCall = await call(method, { ...params, start });
63
- return !firstCall.next ? firstCall : await listAll();
64
- };
65
- return list;
66
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,277 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const methods_1 = require("../../methods");
27
- const list_1 = __importStar(require("./list"));
28
- describe('Client `fillWithCommands` method', () => {
29
- it('should fill array with required amount of commands to process all entries', () => {
30
- const command = { method: methods_1.Method.CRM_DEAL_LIST, params: { select: ['*'] } };
31
- const start = 0;
32
- const toProcess = 7;
33
- const entriesPerCommand = 2;
34
- expect((0, list_1.fillWithCommands)(command, start, toProcess, entriesPerCommand)).toMatchSnapshot();
35
- });
36
- it('should properly take into account start', () => {
37
- const command = { method: methods_1.Method.CRM_DEAL_LIST, params: { select: ['*'] } };
38
- const start = 2;
39
- const toProcess = 7;
40
- const entriesPerCommand = 2;
41
- expect((0, list_1.fillWithCommands)(command, start, toProcess, entriesPerCommand)).toMatchSnapshot();
42
- });
43
- it('should override `params.start`', () => {
44
- const wrongStart = 99;
45
- const command = { method: methods_1.Method.CRM_DEAL_LIST, params: { start: wrongStart } };
46
- const start = 0;
47
- const toProcess = 2;
48
- const entriesPerCommand = 1;
49
- const commands = (0, list_1.fillWithCommands)(command, start, toProcess, entriesPerCommand);
50
- expect(Object.values(commands).map((c) => c.params)).toMatchSnapshot();
51
- });
52
- });
53
- describe('Client `highest` method', () => {
54
- it('should get highest value from object', () => {
55
- expect((0, list_1.highest)({ a: undefined })).toBe(undefined);
56
- expect((0, list_1.highest)({ a: undefined, b: undefined })).toBe(undefined);
57
- expect((0, list_1.highest)({ a: 1, b: undefined })).toBe(1);
58
- expect((0, list_1.highest)({ a: undefined, b: 1 })).toBe(1);
59
- expect((0, list_1.highest)({ a: 1, b: 2 })).toBe(2);
60
- expect((0, list_1.highest)({ a: 2, b: 1 })).toBe(2);
61
- });
62
- it('should get highest value from array', () => {
63
- expect((0, list_1.highest)([undefined])).toBe(undefined);
64
- expect((0, list_1.highest)([undefined, undefined])).toBe(undefined);
65
- expect((0, list_1.highest)([1, undefined])).toBe(1);
66
- expect((0, list_1.highest)([undefined, 1])).toBe(1);
67
- expect((0, list_1.highest)([1, 2])).toBe(2);
68
- expect((0, list_1.highest)([2, 1])).toBe(2);
69
- });
70
- });
71
- describe('Client `batchToListPayload` method', () => {
72
- it('should convert batch with named payloads to a list payload', () => {
73
- const payload = {
74
- result: {
75
- result: {
76
- a: [{ ID: '1' }, { ID: '2' }],
77
- b: [{ ID: '3' }, { ID: '4' }]
78
- },
79
- result_error: { a: 'Expected error A', b: 'Expected error B' },
80
- result_total: { a: 4, b: 4 },
81
- result_next: { a: 2, b: 4 },
82
- result_time: {
83
- a: {
84
- start: 1567196891.008149,
85
- finish: 1567196891.022234,
86
- duration: 0.014085054397583008,
87
- processing: 0.013998985290527344,
88
- date_start: '2019-08-30T23:28:11+03:00',
89
- date_finish: '2019-08-30T23:28:11+03:00'
90
- },
91
- b: {
92
- start: 1567196891.022316,
93
- finish: 1567196891.03225,
94
- duration: 0.009933948516845703,
95
- processing: 0.009846210479736328,
96
- date_start: '2019-08-30T23:28:11+03:00',
97
- date_finish: '2019-08-30T23:28:11+03:00'
98
- }
99
- }
100
- },
101
- time: {
102
- start: 1567196890.959017,
103
- finish: 1567196891.223739,
104
- duration: 0.2647218704223633,
105
- processing: 0.21567082405090332,
106
- date_start: '2019-08-30T23:28:10+03:00',
107
- date_finish: '2019-08-30T23:28:11+03:00'
108
- }
109
- };
110
- expect((0, list_1.batchToListPayload)(payload)).toMatchSnapshot();
111
- });
112
- it('should convert batch with payload of arrays to a list payload', () => {
113
- const payload = {
114
- result: {
115
- result: [
116
- [{ ID: '1' }, { ID: '2' }],
117
- [{ ID: '3' }, { ID: '4' }]
118
- ],
119
- result_error: ['Expected error 1', 'Expected error 2'],
120
- result_total: [4, 4],
121
- result_next: [2, 4],
122
- result_time: [{
123
- start: 1567196891.008149,
124
- finish: 1567196891.022234,
125
- duration: 0.014085054397583008,
126
- processing: 0.013998985290527344,
127
- date_start: '2019-08-30T23:28:11+03:00',
128
- date_finish: '2019-08-30T23:28:11+03:00'
129
- }, {
130
- start: 1567196891.022316,
131
- finish: 1567196891.03225,
132
- duration: 0.009933948516845703,
133
- processing: 0.009846210479736328,
134
- date_start: '2019-08-30T23:28:11+03:00',
135
- date_finish: '2019-08-30T23:28:11+03:00'
136
- }]
137
- },
138
- time: {
139
- start: 1567196890.959017,
140
- finish: 1567196891.223739,
141
- duration: 0.2647218704223633,
142
- processing: 0.21567082405090332,
143
- date_start: '2019-08-30T23:28:10+03:00',
144
- date_finish: '2019-08-30T23:28:11+03:00'
145
- }
146
- };
147
- expect((0, list_1.batchToListPayload)(payload)).toMatchSnapshot();
148
- });
149
- it('should handle undefined in `result`', () => {
150
- const payload = {
151
- result: {
152
- result: [undefined, [{ ID: '1' }], undefined],
153
- result_error: [],
154
- result_total: [],
155
- result_next: [],
156
- result_time: [{
157
- start: 1567196891.008149,
158
- finish: 1567196891.022234,
159
- duration: 0.014085054397583008,
160
- processing: 0.013998985290527344,
161
- date_start: '2019-08-30T23:28:11+03:00',
162
- date_finish: '2019-08-30T23:28:11+03:00'
163
- }, {
164
- start: 1567196891.022316,
165
- finish: 1567196891.03225,
166
- duration: 0.009933948516845703,
167
- processing: 0.009846210479736328,
168
- date_start: '2019-08-30T23:28:11+03:00',
169
- date_finish: '2019-08-30T23:28:11+03:00'
170
- }]
171
- },
172
- time: {
173
- start: 1567196890.959017,
174
- finish: 1567196891.223739,
175
- duration: 0.2647218704223633,
176
- processing: 0.21567082405090332,
177
- date_start: '2019-08-30T23:28:10+03:00',
178
- date_finish: '2019-08-30T23:28:11+03:00'
179
- }
180
- };
181
- expect((0, list_1.batchToListPayload)(payload)).toMatchSnapshot();
182
- });
183
- });
184
- describe('Client `list` method', () => {
185
- it('should make one request when entries can be fetched in one go', async () => {
186
- const callMock = jest.fn(() => Promise.resolve({ next: false }));
187
- const batchMock = jest.fn(() => Promise.resolve({}));
188
- const list = (0, list_1.default)({ call: callMock, batch: batchMock });
189
- await list(methods_1.Method.CRM_DEAL_LIST, {});
190
- expect(callMock.mock.calls).toMatchSnapshot();
191
- expect(batchMock).not.toBeCalled();
192
- });
193
- it('should make multiple requests when entries can not be fetched in one go', async () => {
194
- const callMock = jest.fn(() => Promise.resolve({ next: 2, total: 120 }));
195
- const batchMock = jest.fn(() => Promise.resolve({
196
- result: {
197
- result: ['done'],
198
- result_error: [],
199
- result_next: [],
200
- result_time: [],
201
- result_total: []
202
- },
203
- time: {}
204
- }));
205
- const list = (0, list_1.default)({ call: callMock, batch: batchMock });
206
- await list(methods_1.Method.CRM_DEAL_LIST, {});
207
- expect(callMock.mock.calls).toMatchSnapshot();
208
- expect(batchMock.mock.calls).toMatchSnapshot();
209
- });
210
- it('should return a first request payload when entities can be fetched in a single request', async () => {
211
- const mockPayload = { next: false, result: 'test' };
212
- const callMock = jest.fn(() => Promise.resolve(mockPayload));
213
- const batchMock = jest.fn(() => Promise.resolve({}));
214
- const list = (0, list_1.default)({ call: callMock, batch: batchMock });
215
- const payload = await list(methods_1.Method.CRM_DEAL_LIST, {});
216
- expect(payload).toEqual(mockPayload);
217
- });
218
- it('should return a flatten payload when entities can not be fetched in a single request', async () => {
219
- const mockPayload = {
220
- result: {
221
- result: {
222
- a: [{ ID: '1' }, { ID: '2' }],
223
- b: [{ ID: '3' }, { ID: '4' }]
224
- },
225
- result_error: { a: 'Expected error A', b: 'Expected error B' },
226
- result_total: { a: 4, b: 4 },
227
- result_next: { a: 2, b: 4 },
228
- result_time: {
229
- a: { start: 1567196891.008149 },
230
- b: { start: 1567196891.022316 }
231
- }
232
- },
233
- time: { start: 1567196890.959017 }
234
- };
235
- const callMock = jest.fn(() => Promise.resolve({ next: 2 }));
236
- const batchMock = jest.fn(() => Promise.resolve(mockPayload));
237
- const list = (0, list_1.default)({ call: callMock, batch: batchMock });
238
- const payload = await list(methods_1.Method.CRM_DEAL_LIST, {});
239
- expect(payload).toMatchSnapshot();
240
- });
241
- it('should default start to 0', async () => {
242
- const callMock = jest.fn(() => Promise.resolve({ next: 2, total: 20 }));
243
- const batchMock = jest.fn(() => Promise.resolve({
244
- result: {
245
- result: ['done'],
246
- result_error: [],
247
- result_next: [],
248
- result_time: [],
249
- result_total: []
250
- },
251
- time: {}
252
- }));
253
- const list = (0, list_1.default)({ call: callMock, batch: batchMock });
254
- await list(methods_1.Method.CRM_DEAL_LIST, {});
255
- expect(callMock.mock.calls[0]).toMatchSnapshot();
256
- expect(batchMock.mock.calls[0]).toMatchSnapshot();
257
- });
258
- it('should properly take into account start', async () => {
259
- const callMock = jest.fn(() => Promise.resolve({ next: 2, total: 120 }));
260
- const batchMock = jest.fn(() => Promise.resolve({
261
- result: {
262
- result: ['done'],
263
- result_error: [],
264
- result_next: [],
265
- result_time: [],
266
- result_total: []
267
- },
268
- time: {}
269
- }));
270
- const list = (0, list_1.default)({ call: callMock, batch: batchMock });
271
- await list(methods_1.Method.CRM_DEAL_LIST, { start: 27 });
272
- expect(callMock.mock.calls).toMatchSnapshot();
273
- expect(batchMock.mock.calls).toMatchSnapshot();
274
- });
275
- it.todo('should cast first request payload to the <P>');
276
- it.todo('should cast payload results to the <P>');
277
- });
@@ -1,10 +0,0 @@
1
- import { Method } from './methods';
2
- export declare type Command = {
3
- readonly method: Method;
4
- readonly params?: Record<string, any>;
5
- };
6
- export declare type Commands = {
7
- readonly [key: string]: Command;
8
- } | {
9
- readonly [index: number]: Command;
10
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,92 +0,0 @@
1
- import { Commands } from './commands';
2
- import { BatchPayload } from './payloads';
3
- import { CompaniesMethods } from './services/companies/methods';
4
- import { ContactsMethods } from './services/contacts/methods';
5
- import { DealsMethods } from './services/deals/methods';
6
- import { LeadsMethods } from './services/leads/methods';
7
- import { StatusesMethods } from './services/statuses/methods';
8
- import { UsersMethods } from './services/users/methods';
9
- import { Diff } from './utils/Diff';
10
- import { ExtractValue } from './utils/ExtractValue';
11
- export declare enum Method {
12
- BATCH = "batch",
13
- CRM_COMPANY_FIELDS = "crm.company.fields",
14
- CRM_COMPANY_ADD = "crm.company.add",
15
- CRM_COMPANY_UPDATE = "crm.company.update",
16
- CRM_COMPANY_GET = "crm.company.get",
17
- CRM_COMPANY_LIST = "crm.company.list",
18
- CRM_CONTACT_FIELDS = "crm.contact.fields",
19
- CRM_CONTACT_ADD = "crm.contact.add",
20
- CRM_CONTACT_UPDATE = "crm.contact.update",
21
- CRM_CONTACT_GET = "crm.contact.get",
22
- CRM_CONTACT_LIST = "crm.contact.list",
23
- CRM_DEAL_FIELDS = "crm.deal.fields",
24
- CRM_DEAL_ADD = "crm.deal.add",
25
- CRM_DEAL_UPDATE = "crm.deal.update",
26
- CRM_DEAL_GET = "crm.deal.get",
27
- CRM_DEAL_LIST = "crm.deal.list",
28
- CRM_LEAD_FIELDS = "crm.lead.fields",
29
- CRM_LEAD_ADD = "crm.lead.add",
30
- CRM_LEAD_UPDATE = "crm.lead.update",
31
- CRM_LEAD_GET = "crm.lead.get",
32
- CRM_LEAD_LIST = "crm.lead.list",
33
- CRM_STATUS_FIELDS = "crm.status.fields",
34
- CRM_STATUS_ADD = "crm.status.add",
35
- CRM_STATUS_DELETE = "crm.status.delete",
36
- CRM_STATUS_GET = "crm.status.get",
37
- CRM_STATUS_LIST = "crm.status.list",
38
- CRM_STATUS_UPDATE = "crm.status.update",
39
- USER_FIELDS = "user.fields",
40
- USER_GET = "user.get"
41
- }
42
- declare const LISTABLE_METHODS: readonly [Method.CRM_COMPANY_LIST, Method.CRM_CONTACT_LIST, Method.CRM_DEAL_LIST, Method.CRM_LEAD_LIST];
43
- export declare type ListableMethod = typeof LISTABLE_METHODS[number];
44
- export declare type GettableMethod = Diff<Method, ListableMethod>;
45
- declare type MethodsMap = {
46
- readonly [key: string]: {
47
- readonly type: unknown;
48
- readonly payload: unknown;
49
- readonly params: Record<string, unknown>;
50
- };
51
- };
52
- export declare type ListParams = {
53
- readonly start?: number;
54
- readonly order?: {
55
- readonly [key: string]: string;
56
- };
57
- readonly filter?: {
58
- readonly [key: string]: string | number;
59
- };
60
- readonly select?: readonly string[];
61
- };
62
- /**
63
- * A mega map of all supported Bitrix methods to their parameters. Used to resolve
64
- * low-level client method required params and payload types.
65
- * - `type` — a type that method associated with
66
- * - `payload` — a payload that method returns
67
- * - `params` — params that method accepts
68
- */
69
- export declare type Methods = MethodsMap & CompaniesMethods & ContactsMethods & DealsMethods & LeadsMethods & StatusesMethods & UsersMethods & {
70
- readonly [Method.BATCH]: {
71
- readonly type: unknown;
72
- readonly payload: BatchPayload<unknown>;
73
- readonly params: Commands;
74
- };
75
- };
76
- /**
77
- * Retrieve specified method data
78
- */
79
- export declare type MethodData<M extends Method> = ExtractValue<Methods, M>;
80
- /**
81
- * Retrieve associated with specified method type
82
- */
83
- export declare type MethodPayloadType<M extends Method> = MethodData<M>['type'];
84
- /**
85
- * Retrieve specified method payload type
86
- */
87
- export declare type MethodPayload<M extends Method> = MethodData<M>['payload'];
88
- /**
89
- * Retrieve specified method params
90
- */
91
- export declare type MethodParams<M extends Method> = MethodData<M>['params'];
92
- export {};