@2bad/bitrix 2.4.0 → 2.5.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 (229) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +52 -49
  3. package/build/main/bitrix.d.ts +9 -1
  4. package/build/main/bitrix.integration.test.d.ts +0 -0
  5. package/build/main/bitrix.integration.test.js +31 -0
  6. package/build/main/bitrix.js +20 -9
  7. package/build/main/bitrix.unit.test.d.ts +1 -0
  8. package/build/main/bitrix.unit.test.js +44 -0
  9. package/build/main/client/client.unit.test.d.ts +1 -0
  10. package/build/main/client/client.unit.test.js +70 -0
  11. package/build/main/client/hooks/addAccessToken.d.ts +4 -1
  12. package/build/main/client/hooks/addAccessToken.js +3 -1
  13. package/build/main/client/hooks/addAccessToken.unit.test.d.ts +1 -0
  14. package/build/main/client/hooks/addAccessToken.unit.test.js +31 -0
  15. package/build/main/client/index.d.ts +9 -1
  16. package/build/main/client/index.js +17 -6
  17. package/build/main/client/methods/batch.d.ts +19 -0
  18. package/build/main/client/methods/batch.js +35 -10
  19. package/build/main/client/methods/batch.unit.test.d.ts +1 -0
  20. package/build/main/client/methods/batch.unit.test.js +494 -0
  21. package/build/main/client/methods/call.d.ts +7 -0
  22. package/build/main/client/methods/call.js +11 -4
  23. package/build/main/client/methods/call.unit.test.d.ts +1 -0
  24. package/build/main/client/methods/call.unit.test.js +183 -0
  25. package/build/main/client/methods/list.d.ts +12 -0
  26. package/build/main/client/methods/list.js +23 -7
  27. package/build/main/client/methods/list.unit.test.d.ts +1 -0
  28. package/build/main/client/methods/list.unit.test.js +277 -0
  29. package/build/main/commands.js +0 -1
  30. package/build/main/methods.d.ts +19 -0
  31. package/build/main/methods.js +0 -1
  32. package/build/main/payloads.js +0 -1
  33. package/build/main/services/common.d.ts +1 -0
  34. package/build/main/services/common.js +0 -1
  35. package/build/main/services/companies/entities.js +0 -1
  36. package/build/main/services/companies/index.integration.test.d.ts +1 -0
  37. package/build/main/services/companies/index.integration.test.js +19 -0
  38. package/build/main/services/companies/index.js +0 -1
  39. package/build/main/services/companies/index.unit.test.d.ts +1 -0
  40. package/build/main/services/companies/index.unit.test.js +72 -0
  41. package/build/main/services/companies/methods.js +0 -1
  42. package/build/main/services/contacts/entities.d.ts +2 -2
  43. package/build/main/services/contacts/entities.js +0 -1
  44. package/build/main/services/contacts/index.integration.test.d.ts +1 -0
  45. package/build/main/services/contacts/index.integration.test.js +19 -0
  46. package/build/main/services/contacts/index.js +0 -1
  47. package/build/main/services/contacts/index.unit.test.d.ts +1 -0
  48. package/build/main/services/contacts/index.unit.test.js +72 -0
  49. package/build/main/services/contacts/methods.js +0 -1
  50. package/build/main/services/currencies/entities.js +0 -1
  51. package/build/main/services/deals/entities.js +0 -1
  52. package/build/main/services/deals/index.integration.test.d.ts +1 -0
  53. package/build/main/services/deals/index.integration.test.js +19 -0
  54. package/build/main/services/deals/index.js +0 -1
  55. package/build/main/services/deals/index.unit.test.d.ts +1 -0
  56. package/build/main/services/deals/index.unit.test.js +72 -0
  57. package/build/main/services/deals/methods.js +0 -1
  58. package/build/main/services/leads/entities.js +0 -1
  59. package/build/main/services/leads/index.integration.test.d.ts +1 -0
  60. package/build/main/services/leads/index.integration.test.js +19 -0
  61. package/build/main/services/leads/index.js +0 -1
  62. package/build/main/services/leads/index.unit.test.d.ts +1 -0
  63. package/build/main/services/leads/index.unit.test.js +72 -0
  64. package/build/main/services/leads/methods.js +0 -1
  65. package/build/main/services/statuses/entities.js +0 -1
  66. package/build/main/services/statuses/index.integration.test.d.ts +1 -0
  67. package/build/main/services/statuses/index.integration.test.js +90 -0
  68. package/build/main/services/statuses/index.js +0 -1
  69. package/build/main/services/statuses/index.unit.test.d.ts +1 -0
  70. package/build/main/services/statuses/index.unit.test.js +60 -0
  71. package/build/main/services/statuses/methods.js +0 -1
  72. package/build/main/services/users/entities.js +0 -1
  73. package/build/main/services/users/index.d.ts +1 -1
  74. package/build/main/services/users/index.integration.test.d.ts +1 -0
  75. package/build/main/services/users/index.integration.test.js +33 -0
  76. package/build/main/services/users/index.js +0 -1
  77. package/build/main/services/users/index.unit.test.d.ts +1 -0
  78. package/build/main/services/users/index.unit.test.js +25 -0
  79. package/build/main/services/users/methods.js +0 -1
  80. package/build/main/utils/Diff.js +0 -1
  81. package/build/main/utils/ExtractValue.d.ts +5 -0
  82. package/build/main/utils/ExtractValue.js +0 -1
  83. package/build/main/utils/isArray.js +1 -1
  84. package/build/module/bitrix.d.ts +9 -1
  85. package/build/module/bitrix.integration.test.d.ts +0 -0
  86. package/build/module/bitrix.integration.test.js +31 -0
  87. package/build/module/bitrix.js +8 -1
  88. package/build/module/bitrix.unit.test.d.ts +1 -0
  89. package/build/module/bitrix.unit.test.js +16 -0
  90. package/build/module/client/client.unit.test.d.ts +1 -0
  91. package/build/module/client/client.unit.test.js +65 -0
  92. package/build/module/client/hooks/addAccessToken.d.ts +4 -1
  93. package/build/module/client/hooks/addAccessToken.js +3 -1
  94. package/build/module/client/hooks/addAccessToken.unit.test.d.ts +1 -0
  95. package/build/module/client/hooks/addAccessToken.unit.test.js +26 -0
  96. package/build/module/client/index.d.ts +9 -1
  97. package/build/module/client/index.js +14 -3
  98. package/build/module/client/methods/batch.d.ts +19 -0
  99. package/build/module/client/methods/batch.js +26 -1
  100. package/build/module/client/methods/batch.unit.test.d.ts +1 -0
  101. package/build/module/client/methods/batch.unit.test.js +466 -0
  102. package/build/module/client/methods/call.d.ts +7 -0
  103. package/build/module/client/methods/call.js +9 -3
  104. package/build/module/client/methods/call.unit.test.d.ts +1 -0
  105. package/build/module/client/methods/call.unit.test.js +155 -0
  106. package/build/module/client/methods/list.d.ts +12 -0
  107. package/build/module/client/methods/list.js +20 -6
  108. package/build/module/client/methods/list.unit.test.d.ts +1 -0
  109. package/build/module/client/methods/list.unit.test.js +252 -0
  110. package/build/module/commands.js +0 -1
  111. package/build/module/methods.d.ts +19 -0
  112. package/build/module/methods.js +0 -1
  113. package/build/module/payloads.js +0 -1
  114. package/build/module/services/common.d.ts +1 -0
  115. package/build/module/services/common.js +0 -1
  116. package/build/module/services/companies/entities.js +0 -1
  117. package/build/module/services/companies/index.integration.test.d.ts +1 -0
  118. package/build/module/services/companies/index.integration.test.js +14 -0
  119. package/build/module/services/companies/index.js +0 -1
  120. package/build/module/services/companies/index.unit.test.d.ts +1 -0
  121. package/build/module/services/companies/index.unit.test.js +67 -0
  122. package/build/module/services/companies/methods.js +0 -1
  123. package/build/module/services/contacts/entities.d.ts +2 -2
  124. package/build/module/services/contacts/entities.js +0 -1
  125. package/build/module/services/contacts/index.integration.test.d.ts +1 -0
  126. package/build/module/services/contacts/index.integration.test.js +14 -0
  127. package/build/module/services/contacts/index.js +0 -1
  128. package/build/module/services/contacts/index.unit.test.d.ts +1 -0
  129. package/build/module/services/contacts/index.unit.test.js +67 -0
  130. package/build/module/services/contacts/methods.js +0 -1
  131. package/build/module/services/currencies/entities.js +0 -1
  132. package/build/module/services/deals/entities.js +0 -1
  133. package/build/module/services/deals/index.integration.test.d.ts +1 -0
  134. package/build/module/services/deals/index.integration.test.js +14 -0
  135. package/build/module/services/deals/index.js +0 -1
  136. package/build/module/services/deals/index.unit.test.d.ts +1 -0
  137. package/build/module/services/deals/index.unit.test.js +67 -0
  138. package/build/module/services/deals/methods.js +0 -1
  139. package/build/module/services/leads/entities.js +0 -1
  140. package/build/module/services/leads/index.integration.test.d.ts +1 -0
  141. package/build/module/services/leads/index.integration.test.js +14 -0
  142. package/build/module/services/leads/index.js +0 -1
  143. package/build/module/services/leads/index.unit.test.d.ts +1 -0
  144. package/build/module/services/leads/index.unit.test.js +67 -0
  145. package/build/module/services/leads/methods.js +0 -1
  146. package/build/module/services/statuses/entities.js +0 -1
  147. package/build/module/services/statuses/index.integration.test.d.ts +1 -0
  148. package/build/module/services/statuses/index.integration.test.js +85 -0
  149. package/build/module/services/statuses/index.js +0 -1
  150. package/build/module/services/statuses/index.unit.test.d.ts +1 -0
  151. package/build/module/services/statuses/index.unit.test.js +55 -0
  152. package/build/module/services/statuses/methods.js +0 -1
  153. package/build/module/services/users/entities.js +0 -1
  154. package/build/module/services/users/index.d.ts +1 -1
  155. package/build/module/services/users/index.integration.test.d.ts +1 -0
  156. package/build/module/services/users/index.integration.test.js +28 -0
  157. package/build/module/services/users/index.js +0 -1
  158. package/build/module/services/users/index.unit.test.d.ts +1 -0
  159. package/build/module/services/users/index.unit.test.js +20 -0
  160. package/build/module/services/users/methods.js +0 -1
  161. package/build/module/utils/Diff.js +0 -1
  162. package/build/module/utils/ExtractValue.d.ts +5 -0
  163. package/build/module/utils/ExtractValue.js +0 -1
  164. package/build/module/utils/isArray.js +1 -1
  165. package/package.json +21 -22
  166. package/build/main/bitrix.js.map +0 -1
  167. package/build/main/client/hooks/addAccessToken.js.map +0 -1
  168. package/build/main/client/index.js.map +0 -1
  169. package/build/main/client/methods/batch.js.map +0 -1
  170. package/build/main/client/methods/call.js.map +0 -1
  171. package/build/main/client/methods/list.js.map +0 -1
  172. package/build/main/commands.js.map +0 -1
  173. package/build/main/methods.js.map +0 -1
  174. package/build/main/payloads.js.map +0 -1
  175. package/build/main/services/common.js.map +0 -1
  176. package/build/main/services/companies/entities.js.map +0 -1
  177. package/build/main/services/companies/index.js.map +0 -1
  178. package/build/main/services/companies/methods.js.map +0 -1
  179. package/build/main/services/contacts/entities.js.map +0 -1
  180. package/build/main/services/contacts/index.js.map +0 -1
  181. package/build/main/services/contacts/methods.js.map +0 -1
  182. package/build/main/services/currencies/entities.js.map +0 -1
  183. package/build/main/services/deals/entities.js.map +0 -1
  184. package/build/main/services/deals/index.js.map +0 -1
  185. package/build/main/services/deals/methods.js.map +0 -1
  186. package/build/main/services/leads/entities.js.map +0 -1
  187. package/build/main/services/leads/index.js.map +0 -1
  188. package/build/main/services/leads/methods.js.map +0 -1
  189. package/build/main/services/statuses/entities.js.map +0 -1
  190. package/build/main/services/statuses/index.js.map +0 -1
  191. package/build/main/services/statuses/methods.js.map +0 -1
  192. package/build/main/services/users/entities.js.map +0 -1
  193. package/build/main/services/users/index.js.map +0 -1
  194. package/build/main/services/users/methods.js.map +0 -1
  195. package/build/main/utils/Diff.js.map +0 -1
  196. package/build/main/utils/ExtractValue.js.map +0 -1
  197. package/build/main/utils/isArray.js.map +0 -1
  198. package/build/module/bitrix.js.map +0 -1
  199. package/build/module/client/hooks/addAccessToken.js.map +0 -1
  200. package/build/module/client/index.js.map +0 -1
  201. package/build/module/client/methods/batch.js.map +0 -1
  202. package/build/module/client/methods/call.js.map +0 -1
  203. package/build/module/client/methods/list.js.map +0 -1
  204. package/build/module/commands.js.map +0 -1
  205. package/build/module/methods.js.map +0 -1
  206. package/build/module/payloads.js.map +0 -1
  207. package/build/module/services/common.js.map +0 -1
  208. package/build/module/services/companies/entities.js.map +0 -1
  209. package/build/module/services/companies/index.js.map +0 -1
  210. package/build/module/services/companies/methods.js.map +0 -1
  211. package/build/module/services/contacts/entities.js.map +0 -1
  212. package/build/module/services/contacts/index.js.map +0 -1
  213. package/build/module/services/contacts/methods.js.map +0 -1
  214. package/build/module/services/currencies/entities.js.map +0 -1
  215. package/build/module/services/deals/entities.js.map +0 -1
  216. package/build/module/services/deals/index.js.map +0 -1
  217. package/build/module/services/deals/methods.js.map +0 -1
  218. package/build/module/services/leads/entities.js.map +0 -1
  219. package/build/module/services/leads/index.js.map +0 -1
  220. package/build/module/services/leads/methods.js.map +0 -1
  221. package/build/module/services/statuses/entities.js.map +0 -1
  222. package/build/module/services/statuses/index.js.map +0 -1
  223. package/build/module/services/statuses/methods.js.map +0 -1
  224. package/build/module/services/users/entities.js.map +0 -1
  225. package/build/module/services/users/index.js.map +0 -1
  226. package/build/module/services/users/methods.js.map +0 -1
  227. package/build/module/utils/Diff.js.map +0 -1
  228. package/build/module/utils/ExtractValue.js.map +0 -1
  229. package/build/module/utils/isArray.js.map +0 -1
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -1,30 +1,25 @@
1
- ---
2
- description: that doesn't suck
3
- ---
1
+ ![@2bad/bitrix](https://user-images.githubusercontent.com/4460311/64487745-c4a1ea00-d246-11e9-9d6e-a0b0227c801c.png)
4
2
 
5
- # Bitrix24 REST API client
3
+ # Bitrix24 REST API client that doesn't suck
6
4
 
7
- ![](https://user-images.githubusercontent.com/4460311/64487745-c4a1ea00-d246-11e9-9d6e-a0b0227c801c.png)
5
+ [![NPM version](https://img.shields.io/npm/v/@2bad/bitrix)](https://www.npmjs.com/package/@2bad/bitrix)
6
+ [![License](https://img.shields.io/npm/l/@2bad/bitrix)](https://www.npmjs.com/package/@2bad/bitrix)
7
+ [![Code coverage](https://img.shields.io/codecov/c/github/2BAD/bitrix)](https://codecov.io/gh/2BAD/bitrix)
8
+ [![Travis Build Status](https://img.shields.io/travis/2BAD/bitrix?logo=Travis)](https://travis-ci.org/github/2BAD/bitrix)
9
+ [![GitHub Build Status](https://img.shields.io/github/workflow/status/2BAD/bitrix/Integration%20testing?logo=GitHub)](https://github.com/2BAD/bitrix/actions?query=workflow%3A%22Integration+testing%22)
10
+ [![Written in TypeScript](https://img.shields.io/github/languages/top/2BAD/bitrix)](https://github.com/2BAD/bitrix/search?l=typescript)
8
11
 
9
- [![NPM version](https://img.shields.io/npm/v/@2bad/bitrix)](https://www.npmjs.com/package/@2bad/bitrix)
10
- [![License](https://img.shields.io/npm/l/@2bad/bitrix)](https://www.npmjs.com/package/@2bad/bitrix)
11
- [![Code coverage](https://img.shields.io/codecov/c/github/2BAD/bitrix)](https://codecov.io/gh/2BAD/bitrix)
12
- [![Travis Build Status](https://img.shields.io/travis/2BAD/bitrix?logo=Travis)](https://travis-ci.org/github/2BAD/bitrix)
13
- [![GitHub Build Status](https://img.shields.io/github/workflow/status/2BAD/bitrix/Integration%20testing?logo=GitHub)](https://github.com/2BAD/bitrix/actions?query=workflow%3A%22Integration+testing%22)
14
- [![Dependency Status](https://img.shields.io/david/2BAD/bitrix)](https://david-dm.org/2BAD/bitrix)
15
- [![Written in TypeScript](https://img.shields.io/github/languages/top/2BAD/bitrix)](https://github.com/2BAD/bitrix/search?l=typescript)
16
-
17
- * 🔥 No bullshit
18
- * ✨ Expressive API
19
- * 💪 Strongly typed methods and requests results with TypeScript
20
- * 🚀 Handles records batching and rate limiting for you
21
- * ❤️ Promise-based
12
+ - 🔥 No bullshit
13
+ - ✨ Expressive API
14
+ - 💪 Strongly typed methods and requests results with TypeScript
15
+ - 🚀 Handles records batching and rate limiting for you
16
+ - ❤️ Promise-based
22
17
 
23
18
  ![@2bad/bitrix usage example](https://user-images.githubusercontent.com/4460311/64130824-7798c080-cdcd-11e9-99f0-7ded87541a85.png)
24
19
 
25
20
  ### Install
26
21
 
27
- ```text
22
+ ```shell
28
23
  npm install @2bad/bitrix
29
24
  ```
30
25
 
@@ -85,18 +80,18 @@ There are two ways to do that:
85
80
 
86
81
  ### API
87
82
 
88
- * Generic
89
- * [`call()`](docs/methods.md#call)
90
- * [`list()`](docs/methods.md#list)
91
- * [`batch()`](docs/methods.md#batch)
92
- * CRM
93
- * [Company](docs/services/companies.md)
94
- * [Contact](docs/services/contacts.md)
95
- * [Currency](docs/services/currencies.md)
96
- * [Deal](docs/services/deals.md)
97
- * [Lead](docs/services/leads.md)
98
- * [Status](docs/services/statuses.md)
99
- * [User](docs/services/users.md)
83
+ - Generic
84
+ - [`call()`](docs/methods.md#call)
85
+ - [`list()`](docs/methods.md#list)
86
+ - [`batch()`](docs/methods.md#batch)
87
+ - CRM
88
+ - [Company](docs/services/companies.md)
89
+ - [Contact](docs/services/contacts.md)
90
+ - [Currency](docs/services/currencies.md)
91
+ - [Deal](docs/services/deals.md)
92
+ - [Lead](docs/services/leads.md)
93
+ - [Status](docs/services/statuses.md)
94
+ - [User](docs/services/users.md)
100
95
 
101
96
  ### How it works
102
97
 
@@ -106,14 +101,14 @@ It takes care of the any necessary batching to run "large" commands, like retrie
106
101
 
107
102
  All client methods are automatically rate-limited and queued if needed to cope with Bitrix REST API limitation of 2 requests per second, so you should never see Bitrix errors about exceeding rate limits.
108
103
 
109
- Methods required params and returned payload types are automatically resolved based on [Methods](https://github.com/2BAD/bitrix/tree/b0db508dcebe77f486f7db833183f28de7de14db/source/types.ts) interface, which effectively describes all currently supported methods.
104
+ Methods required params and returned payload types are automatically resolved based on [Methods](source/types.ts) interface, which effectively describes all currently supported methods.
110
105
 
111
106
  To facilitate better architecture, the client divided into layers:
112
107
 
113
108
  1. **Methods** — a mostly generic [methods](docs/methods.md) like `call` to work with Bitrix API methods. They take care of the routine and provide a foundation for more complex operations.
114
- 2. **Client** — a generic [client](https://github.com/2BAD/bitrix/tree/b0db508dcebe77f486f7db833183f28de7de14db/source/client/README.md), which takes care of some additional routine tasks like setting access token on every request, setting up a queue for the rate limiting, and providing generic methods.
115
- 3. **Services** — each [service](https://github.com/2BAD/bitrix/tree/b0db508dcebe77f486f7db833183f28de7de14db/docs/services/README.md) provides an expressive interface to work with a specific group of Bitrix REST API operations. In essence, they do orchestrate generic client methods and parameters to get proper results.
116
- 4. **Bitrix client** — a top-level [provider](https://github.com/2BAD/bitrix/tree/b0db508dcebe77f486f7db833183f28de7de14db/source/bitrix.ts) of generic method and services. An effortless way to deal with Bitrix REST API by using an intuitive API, which takes care of all underlying complexity.
109
+ 2. **Client** — a generic [client](source/client/README.md), which takes care of some additional routine tasks like setting access token on every request, setting up a queue for the rate limiting, and providing generic methods.
110
+ 3. **Services** — each [service](docs/services/README.md) provides an expressive interface to work with a specific group of Bitrix REST API operations. In essence, they do orchestrate generic client methods and parameters to get proper results.
111
+ 4. **Bitrix client** — a top-level [provider](source/bitrix.ts) of generic method and services. An effortless way to deal with Bitrix REST API by using an intuitive API, which takes care of all underlying complexity.
117
112
 
118
113
  ### FAQ
119
114
 
@@ -123,7 +118,7 @@ The core is ready and stable. It can be used to arbitrary invoke any Bitrix REST
123
118
 
124
119
  However, not all Bitrix REST API methods are exposed as convenient client services yet \(the ones like `bitrix.deals.list()`\).
125
120
 
126
- If you need specific service, add one by making a Pull Request, following the structure of already existing [services](https://github.com/2BAD/bitrix/tree/b0db508dcebe77f486f7db833183f28de7de14db/source/services/README.md) and ["Adding new methods"](./#adding-new-methods) instructions.
121
+ If you need specific service, add one by making a Pull Request, following the structure of already existing [services](source/services/README.md) and ["Adding new methods"](./#adding-new-methods) instructions.
127
122
 
128
123
  > I'm not a Typed Language Master Race user. Can I use it with a regular JavaScript?
129
124
 
@@ -176,6 +171,14 @@ bitrix.list('some.new.list' as any, { select: ["TITLE"] })
176
171
 
177
172
  Use the `batch` method. It will handle all routine:
178
173
 
174
+ > I'm using a self-signed SSL certificate and I'm getting a `[RequestError]: self signed certificate`. What should I do?
175
+
176
+ Override [`got options`](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md) in constructor:
177
+
178
+ ```typescript
179
+ const bitrix = Bitrix('https://PORTAL_NAME.bitrix24.ru/rest', 'ACCESS_TOKEN', {https: { rejectUnauthorized: false }})
180
+ ```
181
+
179
182
  ```typescript
180
183
  bitrix.batch({
181
184
  lead: { method: Method.GET_LEAD, params: { ID: '77' } },
@@ -185,25 +188,25 @@ bitrix.batch({
185
188
 
186
189
  ### Development
187
190
 
188
- * `npm test` — run all tests and collect full coverage report
189
- * `npm run test:unit` — run unit tests and collect coverage report
190
- * `npm run test:integration` — run integration tests and collect coverage report
191
- * `npm run test:watch` — watch for changes and run all tests
192
- * `npm run test:unit:watch` — watch for changes and run unit tests
193
- * `npm run test:integration:watch` — watch for changes and run integration tests
194
- * `npm run build` — build the library for the release
191
+ - `npm test` — run all tests and collect full coverage report
192
+ - `npm run test:unit` — run unit tests and collect coverage report
193
+ - `npm run test:integration` — run integration tests and collect coverage report
194
+ - `npm run test:watch` — watch for changes and run all tests
195
+ - `npm run test:unit:watch` — watch for changes and run unit tests
196
+ - `npm run test:integration:watch` — watch for changes and run integration tests
197
+ - `npm run build` — build the library for the release
195
198
 
196
199
  #### Adding new methods
197
200
 
198
201
  Proper method parameters and payload types handling requires some routine when adding any new method. Hopefully, we can do it better in future, but for now follow those steps:
199
202
 
200
- 1. Add new method into the [`Method`](https://github.com/2BAD/bitrix/tree/b0db508dcebe77f486f7db833183f28de7de14db/source/methods.ts) enum.
201
- 2. Add it into the [`LISTABLE_METHODS`](https://github.com/2BAD/bitrix/tree/b0db508dcebe77f486f7db833183f28de7de14db/source/methods.ts) array if it is listable \(paginated\). Not everything that lists is listable, so check it.
202
- 3. Add or update related [service](https://github.com/2BAD/bitrix/tree/b0db508dcebe77f486f7db833183f28de7de14db/source/services/README.md):
203
+ 1. Add new method into the [`Method`](source/methods.ts) enum.
204
+ 2. Add it into the [`LISTABLE_METHODS`](source/methods.ts) array if it is listable \(paginated\). Not everything that lists is listable, so check it.
205
+ 3. Add or update related [service](source/services/README.md):
203
206
  1. Put exposed by the service public methods into the `index.ts` file. Ensure that you're properly mapping service method arguments to `call` or `list` params.
204
207
  2. Add related entities into the `entities.ts`.
205
208
  3. Add interface describing service methods into the `methods.ts`. Test and check method payload type to be sure you've described it correctly!
206
- 4. Extend [`Methods`](https://github.com/2BAD/bitrix/tree/b0db508dcebe77f486f7db833183f28de7de14db/source/methods.ts) interface with the added service-specific interface. That way the client will know how to resolve parameters and payload types for the added method.
209
+ 4. Extend [`Methods`](source/methods.ts) interface with the added service-specific interface. That way the client will know how to resolve parameters and payload types for the added method.
207
210
  5. Add tests into the `index.unit.test.ts`.
208
- 4. Re-export service public types like Entities in the [bitrix.ts](https://github.com/2BAD/bitrix/tree/b0db508dcebe77f486f7db833183f28de7de14db/source/bitrix.ts) to make them available to the end-users.
209
- 5. Document addition in the [docs](https://github.com/2BAD/bitrix/tree/b0db508dcebe77f486f7db833183f28de7de14db/docs/README.md).
211
+ 4. Re-export service public types like Entities in the [bitrix.ts](source/bitrix.ts) to make them available to the end-users.
212
+ 5. Document addition in the [docs](docs/README.md).
@@ -1,5 +1,13 @@
1
1
  import { ExtendOptions } from 'got';
2
- declare const _default: (restURI: string, accessToken?: string | undefined, clientOptions?: ExtendOptions | undefined) => {
2
+ /**
3
+ * Construct a Bitrix client with generic methods
4
+ * @param restURI REST endpoint, like a `https://hello.bitrix24.ua/rest` or an inbound webhook endpoint,
5
+ * like a `https://hello.bitrix24.ua/rest/1/WEBHOOK_TOKEN`.
6
+ * @param accessToken Bitrix application Access Token. Do not specify in case inbound webhook endpoint used.
7
+ * @param clientOptions an object that will overwrite underlying configuration for HTTP client,
8
+ * see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
9
+ */
10
+ declare const _default: (restURI: string, accessToken?: string, clientOptions?: ExtendOptions) => {
3
11
  call: import("./client/methods/call").Call;
4
12
  batch: import("./client/methods/batch").Batch;
5
13
  list: import("./client/methods/list").List;
File without changes
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ describe('Bitrix API', () => {
3
+ describe('`get` method', () => {
4
+ it.todo('should get result');
5
+ it.todo('should reject on error');
6
+ });
7
+ describe('`batch` method', () => {
8
+ it.todo('should execute the batch');
9
+ it.todo('should reject on errors');
10
+ });
11
+ describe('`deals`', () => {
12
+ describe('`get` method', () => {
13
+ it.todo('should get entry');
14
+ it.todo('should reject on error');
15
+ });
16
+ describe('`list` method', () => {
17
+ it.todo('should all entries');
18
+ it.todo('should reject on error');
19
+ });
20
+ });
21
+ describe('`leads`', () => {
22
+ describe('`get` method', () => {
23
+ it.todo('should get entry');
24
+ it.todo('should reject on error');
25
+ });
26
+ describe('`list` method', () => {
27
+ it.todo('should get all entries');
28
+ it.todo('should reject on error');
29
+ });
30
+ });
31
+ });
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -20,18 +24,26 @@ const deals_1 = __importDefault(require("./services/deals"));
20
24
  const leads_1 = __importDefault(require("./services/leads"));
21
25
  const statuses_1 = __importDefault(require("./services/statuses"));
22
26
  const users_1 = __importDefault(require("./services/users"));
27
+ /**
28
+ * Construct a Bitrix client with generic methods
29
+ * @param restURI REST endpoint, like a `https://hello.bitrix24.ua/rest` or an inbound webhook endpoint,
30
+ * like a `https://hello.bitrix24.ua/rest/1/WEBHOOK_TOKEN`.
31
+ * @param accessToken Bitrix application Access Token. Do not specify in case inbound webhook endpoint used.
32
+ * @param clientOptions an object that will overwrite underlying configuration for HTTP client,
33
+ * see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
34
+ */
23
35
  exports.default = (restURI, accessToken, clientOptions) => {
24
- const { call, batch, list } = client_1.default(restURI, accessToken, clientOptions);
36
+ const { call, batch, list } = (0, client_1.default)(restURI, accessToken, clientOptions);
25
37
  return {
26
38
  call,
27
39
  batch,
28
40
  list,
29
- companies: companies_1.default({ call, list }),
30
- contacts: contacts_1.default({ call, list }),
31
- deals: deals_1.default({ call, list }),
32
- leads: leads_1.default({ call, list }),
33
- statuses: statuses_1.default({ call }),
34
- users: users_1.default({ call })
41
+ companies: (0, companies_1.default)({ call, list }),
42
+ contacts: (0, contacts_1.default)({ call, list }),
43
+ deals: (0, deals_1.default)({ call, list }),
44
+ leads: (0, leads_1.default)({ call, list }),
45
+ statuses: (0, statuses_1.default)({ call }),
46
+ users: (0, users_1.default)({ call })
35
47
  };
36
48
  };
37
49
  __exportStar(require("./methods"), exports);
@@ -44,4 +56,3 @@ __exportStar(require("./services/deals/entities"), exports);
44
56
  __exportStar(require("./services/leads/entities"), exports);
45
57
  __exportStar(require("./services/statuses/entities"), exports);
46
58
  __exportStar(require("./services/users/entities"), exports);
47
- //# sourceMappingURL=bitrix.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,44 @@
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 bitrix_1 = __importDefault(require("./bitrix"));
30
+ const client = __importStar(require("./client"));
31
+ describe('Bitrix', () => {
32
+ it('should init', () => {
33
+ expect(() => (0, bitrix_1.default)('https://test.com', 'test_token')).not.toThrow();
34
+ });
35
+ it('should pass endpoint and access token to the client', () => {
36
+ const SpiedClient = jest.spyOn(client, 'default');
37
+ (0, bitrix_1.default)('https://test.com', 'test_token');
38
+ expect(SpiedClient.mock.calls).toMatchSnapshot();
39
+ });
40
+ it('should expose API methods', () => {
41
+ const bitrix = (0, bitrix_1.default)('https://test.com', 'test_token');
42
+ expect(bitrix).toMatchSnapshot();
43
+ });
44
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,70 @@
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
+ const got_1 = __importDefault(require("got"));
7
+ const nock_1 = __importDefault(require("nock"));
8
+ const p_queue_1 = __importDefault(require("p-queue"));
9
+ const methods_1 = require("../methods");
10
+ const index_1 = __importDefault(require("./index"));
11
+ const TEST_URI = 'https://test.com/rest';
12
+ const TEST_ACCESS_TOKEN = 'test_access_token';
13
+ const RESPONSE_200 = 200;
14
+ const spiedQueueAdd = jest.spyOn(p_queue_1.default.prototype, 'add');
15
+ const client = (0, index_1.default)(TEST_URI, TEST_ACCESS_TOKEN);
16
+ describe('Client', () => {
17
+ beforeEach(() => {
18
+ spiedQueueAdd.mockClear();
19
+ });
20
+ it('should init', () => {
21
+ expect(() => (0, index_1.default)(TEST_URI, TEST_ACCESS_TOKEN)).not.toThrow();
22
+ });
23
+ it('should extend `Got` instance with a specified parameters', () => {
24
+ const spiedGotExtend = jest.spyOn(got_1.default, 'extend');
25
+ (0, index_1.default)('https://test.com', 'test_token', { https: { rejectUnauthorized: false } });
26
+ expect(spiedGotExtend.mock.calls).toMatchSnapshot();
27
+ });
28
+ it('should expose API methods', () => {
29
+ expect(client).toMatchSnapshot();
30
+ });
31
+ describe('`call`', () => {
32
+ // @todo restore test when issue is resolved (https://github.com/nock/nock/issues/1832)
33
+ it.skip('should add to queue', async () => {
34
+ const payload = {};
35
+ const method = methods_1.Method.CRM_DEAL_LIST;
36
+ (0, nock_1.default)(TEST_URI)
37
+ .get(`/${method}?access_token=${TEST_ACCESS_TOKEN}`)
38
+ .twice()
39
+ .reply(RESPONSE_200, payload);
40
+ await client.call(method, {});
41
+ await client.call(method, {});
42
+ expect(spiedQueueAdd.mock.calls).toMatchSnapshot();
43
+ });
44
+ });
45
+ describe('`batch`', () => {
46
+ // @todo restore test when issue is resolved (https://github.com/nock/nock/issues/1832)
47
+ it.skip('should add to queue', async () => {
48
+ const payload = {
49
+ result: {
50
+ result: ['done'],
51
+ result_error: []
52
+ }
53
+ };
54
+ const commands = [
55
+ { method: methods_1.Method.CRM_DEAL_GET },
56
+ { method: methods_1.Method.CRM_DEAL_LIST }
57
+ ];
58
+ (0, nock_1.default)(TEST_URI)
59
+ // @todo We'd want to use `query` object here as it is much more readable, but nock for some reason
60
+ // fails to match request when it contains `cmd[someName]`. The issue definitely connected
61
+ // to the `[]`, since it does not appear when only one bracket present
62
+ .get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[0].method}&access_token=${TEST_ACCESS_TOKEN}`)
63
+ .reply(RESPONSE_200, payload)
64
+ .get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[1].method}&access_token=${TEST_ACCESS_TOKEN}`)
65
+ .reply(RESPONSE_200, payload);
66
+ await client.batch(commands, 1);
67
+ expect(spiedQueueAdd.mock.calls).toMatchSnapshot();
68
+ });
69
+ });
70
+ });
@@ -1,3 +1,6 @@
1
1
  import { BeforeRequestHook } from 'got';
2
- declare const _default: (accessToken?: string | undefined) => BeforeRequestHook;
2
+ /**
3
+ * Got can't merge `query` option with other queries if they are string. But that hook can.
4
+ */
5
+ declare const _default: (accessToken?: string) => BeforeRequestHook;
3
6
  export default _default;
@@ -1,5 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Got can't merge `query` option with other queries if they are string. But that hook can.
5
+ */
3
6
  exports.default = (accessToken) => (options) => {
4
7
  if (!accessToken)
5
8
  return;
@@ -8,4 +11,3 @@ exports.default = (accessToken) => (options) => {
8
11
  const hasQuery = options.path.includes('?');
9
12
  options.path = `${options.path}${hasQuery ? '&' : '?'}access_token=${accessToken}`;
10
13
  };
11
- //# sourceMappingURL=addAccessToken.js.map
@@ -0,0 +1,31 @@
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
+ const got_1 = __importDefault(require("got"));
7
+ const addAccessToken_1 = __importDefault(require("./addAccessToken"));
8
+ const token = 'mock_token';
9
+ const merge = got_1.default.mergeOptions;
10
+ describe('Client `addAccessToken` hook', () => {
11
+ it('should add access token to URL without a query', () => {
12
+ const options = merge({ path: 'test', responseType: 'json' });
13
+ (0, addAccessToken_1.default)(token)(options);
14
+ expect(options.path).toBe(`test?access_token=${token}`);
15
+ });
16
+ it('should add access token to URL with a query', () => {
17
+ const options = merge({ path: 'test?value=1', responseType: 'json' });
18
+ (0, addAccessToken_1.default)(token)(options);
19
+ expect(options.path).toBe(`test?value=1&access_token=${token}`);
20
+ });
21
+ it('should not add access token when it is undefined', () => {
22
+ const options = merge({ path: 'test', responseType: 'json' });
23
+ (0, addAccessToken_1.default)()(options);
24
+ expect(options.path).toBe('test');
25
+ });
26
+ it('should not add access token when URL is undefined', () => {
27
+ const options = merge({ path: undefined, responseType: 'json' });
28
+ (0, addAccessToken_1.default)(token)(options);
29
+ expect(options.path).toBe(undefined);
30
+ });
31
+ });
@@ -1,5 +1,13 @@
1
1
  import { ExtendOptions } from 'got';
2
- declare const _default: (restURI: string, accessToken?: string | undefined, options?: ExtendOptions | undefined) => {
2
+ /**
3
+ * Construct a Bitrix client with generic methods
4
+ * @param restURI REST endpoint, like a `https://hello.bitrix24.ru/rest` or an inbound webhook endpoint,
5
+ * like a `https://hello.bitrix24.ru/rest/1/WEBHOOK_TOKEN`.
6
+ * @param accessToken Bitrix application Access Token. Do not specify in case inbound webhook endpoint used.
7
+ * @param options an object that will overwrite underlying configuration for HTTP client,
8
+ * see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
9
+ */
10
+ declare const _default: (restURI: string, accessToken?: string, options?: ExtendOptions) => {
3
11
  call: import("./methods/call").Call;
4
12
  batch: import("./methods/batch").Batch;
5
13
  list: import("./methods/list").List;
@@ -10,7 +10,15 @@ const batch_1 = __importDefault(require("./methods/batch"));
10
10
  const call_1 = __importDefault(require("./methods/call"));
11
11
  const list_1 = __importDefault(require("./methods/list"));
12
12
  const BITRIX_API_RATE_LIMIT = 2;
13
- const BITRIX_API_RATE_INTERVAL = 1000;
13
+ const BITRIX_API_RATE_INTERVAL = 1000; // 1 second
14
+ /**
15
+ * Construct a Bitrix client with generic methods
16
+ * @param restURI REST endpoint, like a `https://hello.bitrix24.ru/rest` or an inbound webhook endpoint,
17
+ * like a `https://hello.bitrix24.ru/rest/1/WEBHOOK_TOKEN`.
18
+ * @param accessToken Bitrix application Access Token. Do not specify in case inbound webhook endpoint used.
19
+ * @param options an object that will overwrite underlying configuration for HTTP client,
20
+ * see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
21
+ */
14
22
  exports.default = (restURI, accessToken, options) => {
15
23
  const client = got_1.default.extend({
16
24
  prefixUrl: restURI,
@@ -20,7 +28,7 @@ exports.default = (restURI, accessToken, options) => {
20
28
  responseType: 'json',
21
29
  hooks: {
22
30
  beforeRequest: [
23
- addAccessToken_1.default(accessToken)
31
+ (0, addAccessToken_1.default)(accessToken)
24
32
  ]
25
33
  },
26
34
  ...options !== null && options !== void 0 ? options : {}
@@ -30,13 +38,16 @@ exports.default = (restURI, accessToken, options) => {
30
38
  interval: BITRIX_API_RATE_INTERVAL
31
39
  });
32
40
  const queuedGet = (...args) => queue.add(() => client.get(...args));
33
- const call = call_1.default({ get: queuedGet });
34
- const batch = batch_1.default({ get: queuedGet });
35
- const list = list_1.default({ call, batch });
41
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
42
+ // @ts-expect-error @todo remove after issue is resolved (https://github.com/sindresorhus/got/issues/954)
43
+ const call = (0, call_1.default)({ get: queuedGet });
44
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
45
+ // @ts-expect-error @todo remove after issue is resolved (https://github.com/sindresorhus/got/issues/954)
46
+ const batch = (0, batch_1.default)({ get: queuedGet });
47
+ const list = (0, list_1.default)({ call, batch });
36
48
  return {
37
49
  call,
38
50
  batch,
39
51
  list
40
52
  };
41
53
  };
42
- //# sourceMappingURL=index.js.map
@@ -3,8 +3,20 @@ import { Commands } from '../../commands';
3
3
  import { Method, MethodPayloadType } from '../../methods';
4
4
  import { BatchPayload } from '../../payloads';
5
5
  export declare const MAX_COMMANDS_PER_BATCH = 50;
6
+ /**
7
+ * Split any number of commands into the chunks with max commands per batch in each chunk
8
+ */
6
9
  export declare const chunkCommands: <C extends Commands>(commands: C, size?: number) => readonly C[];
10
+ /**
11
+ * Prepares list of commands to be used in requests to the Bitrix
12
+ * @note We could avoid that function... if only Bitrix API would support posting of the batch commands as
13
+ * plain objects, like it does with other methods. Instead, it should be a dict or array of string queries
14
+ */
7
15
  export declare const prepareCommandsQueries: <C extends Commands, R = { [K in keyof C]: string; }>(commands: C) => R;
16
+ /**
17
+ * Merges list of batch responses into a single batch
18
+ * @todo Generics inference is complicated here and might be not super accurate
19
+ */
8
20
  export declare const mergeBatchPayloads: <B extends BatchPayload<unknown>, P = B extends BatchPayload<infer U> ? U : never>(payloads: readonly B[]) => BatchPayload<P>;
9
21
  export declare type CommandsPayloads<C extends Commands, CM = {
10
22
  [K in keyof C]: C[K] extends {
@@ -17,5 +29,12 @@ export declare type Batch = <C extends Commands, P = CommandsPayloads<C>>(comman
17
29
  declare type Dependencies = {
18
30
  readonly get: typeof got.get;
19
31
  };
32
+ /**
33
+ * Dispatches a batch request with specified commands. Will fill figure out payload type based on the Methods.
34
+ * Supports unlimited number of commands. If they do exceed max amount of commands per batch, will dispatch
35
+ * multiple request and merge result into single batch payload
36
+ * @todo For now due to issues with types it won't check `params` of command, so any Method can be used
37
+ * with any (even wrong) params
38
+ */
20
39
  declare const _default: ({ get }: Dependencies) => Batch;
21
40
  export default _default;
@@ -11,24 +11,42 @@ const methods_1 = require("../../methods");
11
11
  const isArray_1 = __importDefault(require("../../utils/isArray"));
12
12
  const call_1 = require("./call");
13
13
  exports.MAX_COMMANDS_PER_BATCH = 50;
14
+ /**
15
+ * Split any number of commands into the chunks with max commands per batch in each chunk
16
+ */
14
17
  const chunkCommands = (commands, size = exports.MAX_COMMANDS_PER_BATCH) => {
15
- const commandsIsArray = isArray_1.default(commands);
16
- const chunks = lodash_chunk_1.default(Object.entries(commands), size);
18
+ const commandsIsArray = (0, isArray_1.default)(commands);
19
+ const chunks = (0, lodash_chunk_1.default)(Object.entries(commands), size);
20
+ // @todo Generated return type isn't very accurate since it says that it will make array of <C>, while
21
+ // in fact <C> will be distributed among chunks. That gives wrong hints with named commands and arrays as const.
17
22
  return chunks.map((c) => commandsIsArray
23
+ // @todo Figure out how to avoid unsafe casting to <C> here
24
+ // Without `<C>` generic it won't work with complex functions like `batch`
18
25
  ? c.map(([_key, command]) => command)
19
- : lodash_frompairs_1.default(c));
26
+ : (0, lodash_frompairs_1.default)(c));
20
27
  };
21
28
  exports.chunkCommands = chunkCommands;
29
+ /**
30
+ * Prepares list of commands to be used in requests to the Bitrix
31
+ * @note We could avoid that function... if only Bitrix API would support posting of the batch commands as
32
+ * plain objects, like it does with other methods. Instead, it should be a dict or array of string queries
33
+ */
22
34
  const prepareCommandsQueries = (commands) => Object.entries(commands).reduce((calls, [name, { method, params }]) => {
23
- const stringifiedParams = params ? `?${qs_1.stringify(params)}` : '';
35
+ const stringifiedParams = params ? `?${(0, qs_1.stringify)(params)}` : '';
24
36
  return {
25
37
  ...calls,
26
38
  [`cmd[${name}]`]: `${method}${stringifiedParams}`
27
39
  };
40
+ // eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter
28
41
  }, {});
29
42
  exports.prepareCommandsQueries = prepareCommandsQueries;
43
+ /**
44
+ * Merges list of batch responses into a single batch
45
+ * @todo Generics inference is complicated here and might be not super accurate
46
+ */
30
47
  const mergeBatchPayloads = (payloads) => {
31
- const merge = (a, b) => isArray_1.default(a) && isArray_1.default(b)
48
+ const merge = (a, b) => (0, isArray_1.default)(a) && (0, isArray_1.default)(b)
49
+ // @todo Gotta find way to avoid unsafe casting here
32
50
  ? [...a, ...b]
33
51
  : ({ ...a, ...b });
34
52
  return payloads.reduce((merged, payload) => ({
@@ -40,21 +58,28 @@ const mergeBatchPayloads = (payloads) => {
40
58
  result_total: merge(merged.result.result_total || [], payload.result.result_total)
41
59
  },
42
60
  time: { ...merged.time, ...payload.time }
61
+ // eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter
43
62
  }), { result: {}, time: {} });
44
63
  };
45
64
  exports.mergeBatchPayloads = mergeBatchPayloads;
65
+ /**
66
+ * Dispatches a batch request with specified commands. Will fill figure out payload type based on the Methods.
67
+ * Supports unlimited number of commands. If they do exceed max amount of commands per batch, will dispatch
68
+ * multiple request and merge result into single batch payload
69
+ * @todo For now due to issues with types it won't check `params` of command, so any Method can be used
70
+ * with any (even wrong) params
71
+ */
46
72
  exports.default = ({ get }) => {
47
73
  const batch = async (commands, commandsPerRequest = exports.MAX_COMMANDS_PER_BATCH) => {
48
- const call = (c) => get(methods_1.Method.BATCH, { searchParams: exports.prepareCommandsQueries(c) })
74
+ const call = (c) => get(methods_1.Method.BATCH, { searchParams: (0, exports.prepareCommandsQueries)(c) })
49
75
  .then(({ body }) => body);
50
- const calls = exports.chunkCommands(commands, commandsPerRequest)
76
+ const calls = (0, exports.chunkCommands)(commands, commandsPerRequest)
51
77
  .map(call);
52
78
  return await Promise.all(calls)
53
79
  .then((chunkedPayloads) => {
54
- const payloads = exports.mergeBatchPayloads(chunkedPayloads);
55
- return call_1.handlePayload(payloads);
80
+ const payloads = (0, exports.mergeBatchPayloads)(chunkedPayloads);
81
+ return (0, call_1.handlePayload)(payloads);
56
82
  });
57
83
  };
58
84
  return batch;
59
85
  };
60
- //# sourceMappingURL=batch.js.map
@@ -0,0 +1 @@
1
+ export {};