@2bad/bitrix 2.3.1 → 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 (268) hide show
  1. package/README.md +53 -45
  2. package/build/main/bitrix.d.ts +25 -16
  3. package/build/main/bitrix.integration.test.js +0 -1
  4. package/build/main/bitrix.js +40 -13
  5. package/build/main/bitrix.unit.test.js +24 -9
  6. package/build/main/client/client.unit.test.js +13 -10
  7. package/build/main/client/hooks/addAccessToken.d.ts +5 -2
  8. package/build/main/client/hooks/addAccessToken.js +3 -1
  9. package/build/main/client/hooks/addAccessToken.unit.test.js +13 -12
  10. package/build/main/client/index.d.ts +10 -1
  11. package/build/main/client/index.js +23 -11
  12. package/build/main/client/methods/batch.d.ts +24 -5
  13. package/build/main/client/methods/batch.js +49 -17
  14. package/build/main/client/methods/batch.unit.test.js +103 -45
  15. package/build/main/client/methods/call.d.ts +11 -4
  16. package/build/main/client/methods/call.js +16 -6
  17. package/build/main/client/methods/call.unit.test.js +36 -21
  18. package/build/main/client/methods/list.d.ts +15 -3
  19. package/build/main/client/methods/list.js +36 -14
  20. package/build/main/client/methods/list.unit.test.js +42 -27
  21. package/build/main/commands.d.ts +2 -2
  22. package/build/main/commands.js +0 -1
  23. package/build/main/methods.d.ts +27 -8
  24. package/build/main/methods.js +1 -1
  25. package/build/main/payloads.d.ts +8 -8
  26. package/build/main/payloads.js +0 -1
  27. package/build/main/services/common.d.ts +5 -4
  28. package/build/main/services/common.js +0 -1
  29. package/build/main/services/companies/entities.d.ts +7 -6
  30. package/build/main/services/companies/entities.js +0 -1
  31. package/build/main/services/companies/index.d.ts +7 -6
  32. package/build/main/services/companies/index.integration.test.js +2 -3
  33. package/build/main/services/companies/index.js +0 -1
  34. package/build/main/services/companies/index.unit.test.js +1 -2
  35. package/build/main/services/companies/methods.d.ts +4 -4
  36. package/build/main/services/companies/methods.js +0 -1
  37. package/build/main/services/contacts/entities.d.ts +4 -3
  38. package/build/main/services/contacts/entities.js +0 -1
  39. package/build/main/services/contacts/index.d.ts +7 -6
  40. package/build/main/services/contacts/index.integration.test.js +2 -3
  41. package/build/main/services/contacts/index.js +0 -1
  42. package/build/main/services/contacts/index.unit.test.js +1 -2
  43. package/build/main/services/contacts/methods.d.ts +4 -4
  44. package/build/main/services/contacts/methods.js +0 -1
  45. package/build/main/services/currencies/entities.d.ts +2 -2
  46. package/build/main/services/currencies/entities.js +0 -1
  47. package/build/main/services/deals/entities.d.ts +2 -2
  48. package/build/main/services/deals/entities.js +0 -1
  49. package/build/main/services/deals/index.d.ts +7 -6
  50. package/build/main/services/deals/index.integration.test.js +2 -3
  51. package/build/main/services/deals/index.js +0 -1
  52. package/build/main/services/deals/index.unit.test.js +1 -2
  53. package/build/main/services/deals/methods.d.ts +4 -4
  54. package/build/main/services/deals/methods.js +0 -1
  55. package/build/main/services/leads/entities.d.ts +2 -2
  56. package/build/main/services/leads/entities.js +0 -1
  57. package/build/main/services/leads/index.d.ts +7 -6
  58. package/build/main/services/leads/index.integration.test.js +2 -3
  59. package/build/main/services/leads/index.js +0 -1
  60. package/build/main/services/leads/index.unit.test.js +1 -2
  61. package/build/main/services/leads/methods.d.ts +4 -4
  62. package/build/main/services/leads/methods.js +0 -1
  63. package/build/main/services/statuses/entities.d.ts +5 -4
  64. package/build/main/services/statuses/entities.js +0 -1
  65. package/build/main/services/statuses/index.d.ts +7 -11
  66. package/build/main/services/statuses/index.integration.test.js +8 -4
  67. package/build/main/services/statuses/index.js +0 -1
  68. package/build/main/services/statuses/index.unit.test.js +1 -2
  69. package/build/main/services/statuses/methods.d.ts +6 -6
  70. package/build/main/services/statuses/methods.js +0 -1
  71. package/build/main/services/users/entities.d.ts +4 -3
  72. package/build/main/services/users/entities.js +0 -1
  73. package/build/main/services/users/index.d.ts +3 -3
  74. package/build/main/services/users/index.integration.test.js +2 -3
  75. package/build/main/services/users/index.js +0 -1
  76. package/build/main/services/users/index.unit.test.js +1 -2
  77. package/build/main/services/users/methods.d.ts +4 -4
  78. package/build/main/services/users/methods.js +0 -1
  79. package/build/main/utils/Diff.js +0 -1
  80. package/build/main/utils/ExtractValue.d.ts +6 -1
  81. package/build/main/utils/ExtractValue.js +0 -1
  82. package/build/main/utils/isArray.d.ts +1 -1
  83. package/build/main/utils/isArray.js +1 -1
  84. package/build/module/bitrix.d.ts +25 -16
  85. package/build/module/bitrix.integration.test.js +0 -1
  86. package/build/module/bitrix.js +19 -3
  87. package/build/module/bitrix.unit.test.js +0 -1
  88. package/build/module/client/client.unit.test.js +9 -6
  89. package/build/module/client/hooks/addAccessToken.d.ts +5 -2
  90. package/build/module/client/hooks/addAccessToken.js +3 -1
  91. package/build/module/client/hooks/addAccessToken.unit.test.js +9 -8
  92. package/build/module/client/index.d.ts +10 -1
  93. package/build/module/client/index.js +19 -7
  94. package/build/module/client/methods/batch.d.ts +24 -5
  95. package/build/module/client/methods/batch.js +28 -3
  96. package/build/module/client/methods/batch.unit.test.js +61 -19
  97. package/build/module/client/methods/call.d.ts +11 -4
  98. package/build/module/client/methods/call.js +10 -3
  99. package/build/module/client/methods/call.unit.test.js +1 -2
  100. package/build/module/client/methods/list.d.ts +15 -3
  101. package/build/module/client/methods/list.js +21 -5
  102. package/build/module/client/methods/list.unit.test.js +0 -1
  103. package/build/module/commands.d.ts +2 -2
  104. package/build/module/commands.js +1 -1
  105. package/build/module/methods.d.ts +27 -8
  106. package/build/module/methods.js +0 -1
  107. package/build/module/payloads.d.ts +8 -8
  108. package/build/module/payloads.js +1 -1
  109. package/build/module/services/common.d.ts +5 -4
  110. package/build/module/services/common.js +1 -1
  111. package/build/module/services/companies/entities.d.ts +7 -6
  112. package/build/module/services/companies/entities.js +1 -1
  113. package/build/module/services/companies/index.d.ts +7 -6
  114. package/build/module/services/companies/index.integration.test.js +1 -2
  115. package/build/module/services/companies/index.js +0 -1
  116. package/build/module/services/companies/index.unit.test.js +0 -1
  117. package/build/module/services/companies/methods.d.ts +4 -4
  118. package/build/module/services/companies/methods.js +0 -1
  119. package/build/module/services/contacts/entities.d.ts +4 -3
  120. package/build/module/services/contacts/entities.js +1 -1
  121. package/build/module/services/contacts/index.d.ts +7 -6
  122. package/build/module/services/contacts/index.integration.test.js +1 -2
  123. package/build/module/services/contacts/index.js +0 -1
  124. package/build/module/services/contacts/index.unit.test.js +0 -1
  125. package/build/module/services/contacts/methods.d.ts +4 -4
  126. package/build/module/services/contacts/methods.js +0 -1
  127. package/build/module/services/currencies/entities.d.ts +2 -2
  128. package/build/module/services/currencies/entities.js +1 -1
  129. package/build/module/services/deals/entities.d.ts +2 -2
  130. package/build/module/services/deals/entities.js +1 -1
  131. package/build/module/services/deals/index.d.ts +7 -6
  132. package/build/module/services/deals/index.integration.test.js +1 -2
  133. package/build/module/services/deals/index.js +0 -1
  134. package/build/module/services/deals/index.unit.test.js +0 -1
  135. package/build/module/services/deals/methods.d.ts +4 -4
  136. package/build/module/services/deals/methods.js +0 -1
  137. package/build/module/services/leads/entities.d.ts +2 -2
  138. package/build/module/services/leads/entities.js +1 -1
  139. package/build/module/services/leads/index.d.ts +7 -6
  140. package/build/module/services/leads/index.integration.test.js +1 -2
  141. package/build/module/services/leads/index.js +0 -1
  142. package/build/module/services/leads/index.unit.test.js +0 -1
  143. package/build/module/services/leads/methods.d.ts +4 -4
  144. package/build/module/services/leads/methods.js +0 -1
  145. package/build/module/services/statuses/entities.d.ts +5 -4
  146. package/build/module/services/statuses/entities.js +1 -1
  147. package/build/module/services/statuses/index.d.ts +7 -11
  148. package/build/module/services/statuses/index.integration.test.js +7 -3
  149. package/build/module/services/statuses/index.js +0 -1
  150. package/build/module/services/statuses/index.unit.test.js +0 -1
  151. package/build/module/services/statuses/methods.d.ts +6 -6
  152. package/build/module/services/statuses/methods.js +0 -1
  153. package/build/module/services/users/entities.d.ts +4 -3
  154. package/build/module/services/users/entities.js +1 -1
  155. package/build/module/services/users/index.d.ts +3 -3
  156. package/build/module/services/users/index.integration.test.js +1 -2
  157. package/build/module/services/users/index.js +0 -1
  158. package/build/module/services/users/index.unit.test.js +0 -1
  159. package/build/module/services/users/methods.d.ts +4 -4
  160. package/build/module/services/users/methods.js +0 -1
  161. package/build/module/utils/Diff.js +1 -1
  162. package/build/module/utils/ExtractValue.d.ts +6 -1
  163. package/build/module/utils/ExtractValue.js +1 -1
  164. package/build/module/utils/isArray.d.ts +1 -1
  165. package/build/module/utils/isArray.js +1 -1
  166. package/package.json +64 -60
  167. package/build/main/bitrix.integration.test.js.map +0 -1
  168. package/build/main/bitrix.js.map +0 -1
  169. package/build/main/bitrix.unit.test.js.map +0 -1
  170. package/build/main/client/client.unit.test.js.map +0 -1
  171. package/build/main/client/hooks/addAccessToken.js.map +0 -1
  172. package/build/main/client/hooks/addAccessToken.unit.test.js.map +0 -1
  173. package/build/main/client/index.js.map +0 -1
  174. package/build/main/client/methods/batch.js.map +0 -1
  175. package/build/main/client/methods/batch.unit.test.js.map +0 -1
  176. package/build/main/client/methods/call.js.map +0 -1
  177. package/build/main/client/methods/call.unit.test.js.map +0 -1
  178. package/build/main/client/methods/list.js.map +0 -1
  179. package/build/main/client/methods/list.unit.test.js.map +0 -1
  180. package/build/main/commands.js.map +0 -1
  181. package/build/main/methods.js.map +0 -1
  182. package/build/main/payloads.js.map +0 -1
  183. package/build/main/services/common.js.map +0 -1
  184. package/build/main/services/companies/entities.js.map +0 -1
  185. package/build/main/services/companies/index.integration.test.js.map +0 -1
  186. package/build/main/services/companies/index.js.map +0 -1
  187. package/build/main/services/companies/index.unit.test.js.map +0 -1
  188. package/build/main/services/companies/methods.js.map +0 -1
  189. package/build/main/services/contacts/entities.js.map +0 -1
  190. package/build/main/services/contacts/index.integration.test.js.map +0 -1
  191. package/build/main/services/contacts/index.js.map +0 -1
  192. package/build/main/services/contacts/index.unit.test.js.map +0 -1
  193. package/build/main/services/contacts/methods.js.map +0 -1
  194. package/build/main/services/currencies/entities.js.map +0 -1
  195. package/build/main/services/deals/entities.js.map +0 -1
  196. package/build/main/services/deals/index.integration.test.js.map +0 -1
  197. package/build/main/services/deals/index.js.map +0 -1
  198. package/build/main/services/deals/index.unit.test.js.map +0 -1
  199. package/build/main/services/deals/methods.js.map +0 -1
  200. package/build/main/services/leads/entities.js.map +0 -1
  201. package/build/main/services/leads/index.integration.test.js.map +0 -1
  202. package/build/main/services/leads/index.js.map +0 -1
  203. package/build/main/services/leads/index.unit.test.js.map +0 -1
  204. package/build/main/services/leads/methods.js.map +0 -1
  205. package/build/main/services/statuses/entities.js.map +0 -1
  206. package/build/main/services/statuses/index.integration.test.js.map +0 -1
  207. package/build/main/services/statuses/index.js.map +0 -1
  208. package/build/main/services/statuses/index.unit.test.js.map +0 -1
  209. package/build/main/services/statuses/methods.js.map +0 -1
  210. package/build/main/services/users/entities.js.map +0 -1
  211. package/build/main/services/users/index.integration.test.js.map +0 -1
  212. package/build/main/services/users/index.js.map +0 -1
  213. package/build/main/services/users/index.unit.test.js.map +0 -1
  214. package/build/main/services/users/methods.js.map +0 -1
  215. package/build/main/utils/Diff.js.map +0 -1
  216. package/build/main/utils/ExtractValue.js.map +0 -1
  217. package/build/main/utils/isArray.js.map +0 -1
  218. package/build/module/bitrix.integration.test.js.map +0 -1
  219. package/build/module/bitrix.js.map +0 -1
  220. package/build/module/bitrix.unit.test.js.map +0 -1
  221. package/build/module/client/client.unit.test.js.map +0 -1
  222. package/build/module/client/hooks/addAccessToken.js.map +0 -1
  223. package/build/module/client/hooks/addAccessToken.unit.test.js.map +0 -1
  224. package/build/module/client/index.js.map +0 -1
  225. package/build/module/client/methods/batch.js.map +0 -1
  226. package/build/module/client/methods/batch.unit.test.js.map +0 -1
  227. package/build/module/client/methods/call.js.map +0 -1
  228. package/build/module/client/methods/call.unit.test.js.map +0 -1
  229. package/build/module/client/methods/list.js.map +0 -1
  230. package/build/module/client/methods/list.unit.test.js.map +0 -1
  231. package/build/module/commands.js.map +0 -1
  232. package/build/module/methods.js.map +0 -1
  233. package/build/module/payloads.js.map +0 -1
  234. package/build/module/services/common.js.map +0 -1
  235. package/build/module/services/companies/entities.js.map +0 -1
  236. package/build/module/services/companies/index.integration.test.js.map +0 -1
  237. package/build/module/services/companies/index.js.map +0 -1
  238. package/build/module/services/companies/index.unit.test.js.map +0 -1
  239. package/build/module/services/companies/methods.js.map +0 -1
  240. package/build/module/services/contacts/entities.js.map +0 -1
  241. package/build/module/services/contacts/index.integration.test.js.map +0 -1
  242. package/build/module/services/contacts/index.js.map +0 -1
  243. package/build/module/services/contacts/index.unit.test.js.map +0 -1
  244. package/build/module/services/contacts/methods.js.map +0 -1
  245. package/build/module/services/currencies/entities.js.map +0 -1
  246. package/build/module/services/deals/entities.js.map +0 -1
  247. package/build/module/services/deals/index.integration.test.js.map +0 -1
  248. package/build/module/services/deals/index.js.map +0 -1
  249. package/build/module/services/deals/index.unit.test.js.map +0 -1
  250. package/build/module/services/deals/methods.js.map +0 -1
  251. package/build/module/services/leads/entities.js.map +0 -1
  252. package/build/module/services/leads/index.integration.test.js.map +0 -1
  253. package/build/module/services/leads/index.js.map +0 -1
  254. package/build/module/services/leads/index.unit.test.js.map +0 -1
  255. package/build/module/services/leads/methods.js.map +0 -1
  256. package/build/module/services/statuses/entities.js.map +0 -1
  257. package/build/module/services/statuses/index.integration.test.js.map +0 -1
  258. package/build/module/services/statuses/index.js.map +0 -1
  259. package/build/module/services/statuses/index.unit.test.js.map +0 -1
  260. package/build/module/services/statuses/methods.js.map +0 -1
  261. package/build/module/services/users/entities.js.map +0 -1
  262. package/build/module/services/users/index.integration.test.js.map +0 -1
  263. package/build/module/services/users/index.js.map +0 -1
  264. package/build/module/services/users/index.unit.test.js.map +0 -1
  265. package/build/module/services/users/methods.js.map +0 -1
  266. package/build/module/utils/Diff.js.map +0 -1
  267. package/build/module/utils/ExtractValue.js.map +0 -1
  268. package/build/module/utils/isArray.js.map +0 -1
package/README.md CHANGED
@@ -1,24 +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.svg)](https://www.npmjs.com/package/@2bad/bitrix) [![License](https://img.shields.io/npm/l/@2bad/bitrix.svg)](https://www.npmjs.com/package/@2bad/bitrix) [![Code coverage](https://img.shields.io/codecov/c/github/2BAD/bitrix.svg)](https://codecov.io/gh/2BAD/bitrix) [![CircleCI Build Status](https://img.shields.io/circleci/build/gh/2BAD/bitrix/master.svg?label=circle)](https://circleci.com/gh/2BAD/bitrix) [![Dependency Status](https://img.shields.io/david/2BAD/bitrix.svg)](https://david-dm.org/2BAD/bitrix) [![Written in TypeScript](https://img.shields.io/github/languages/top/2BAD/bitrix.svg)](https://github.com/2BAD/bitrix/search?l=typescript)
10
-
11
- * 🔥 No bullshit
12
- * ✨ Expressive API
13
- * 💪 Strongly typed methods and requests results with TypeScript
14
- * 🚀 Handles records batching and rate limiting for you
15
- * ❤️ 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
16
17
 
17
18
  ![@2bad/bitrix usage example](https://user-images.githubusercontent.com/4460311/64130824-7798c080-cdcd-11e9-99f0-7ded87541a85.png)
18
19
 
19
20
  ### Install
20
21
 
21
- ```text
22
+ ```shell
22
23
  npm install @2bad/bitrix
23
24
  ```
24
25
 
@@ -79,18 +80,18 @@ There are two ways to do that:
79
80
 
80
81
  ### API
81
82
 
82
- * Generic
83
- * [`call()`](docs/methods.md#call)
84
- * [`list()`](docs/methods.md#list)
85
- * [`batch()`](docs/methods.md#batch)
86
- * CRM
87
- * [Company](docs/services/companies.md)
88
- * [Contact](docs/services/contacts.md)
89
- * [Currency](docs/services/currencies.md)
90
- * [Deal](docs/services/deals.md)
91
- * [Lead](docs/services/leads.md)
92
- * [Status](docs/services/statuses.md)
93
- * [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)
94
95
 
95
96
  ### How it works
96
97
 
@@ -98,16 +99,16 @@ The client tries hard to provide a consistent, strongly typed and at the same ti
98
99
 
99
100
  It takes care of the any necessary batching to run "large" commands, like retrieving all deals or leads with least possible network request. That allows achieving a reading of the 250 000 and updating of 5000 entries per minute with a single line of code.
100
101
 
101
- 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 erroring about exceeding rate limits.
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.
102
103
 
103
- 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.
104
105
 
105
106
  To facilitate better architecture, the client divided into layers:
106
107
 
107
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.
108
- 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.
109
- 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.
110
- 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.
111
112
 
112
113
  ### FAQ
113
114
 
@@ -117,7 +118,7 @@ The core is ready and stable. It can be used to arbitrary invoke any Bitrix REST
117
118
 
118
119
  However, not all Bitrix REST API methods are exposed as convenient client services yet \(the ones like `bitrix.deals.list()`\).
119
120
 
120
- 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.
121
122
 
122
123
  > I'm not a Typed Language Master Race user. Can I use it with a regular JavaScript?
123
124
 
@@ -170,6 +171,14 @@ bitrix.list('some.new.list' as any, { select: ["TITLE"] })
170
171
 
171
172
  Use the `batch` method. It will handle all routine:
172
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
+
173
182
  ```typescript
174
183
  bitrix.batch({
175
184
  lead: { method: Method.GET_LEAD, params: { ID: '77' } },
@@ -179,26 +188,25 @@ bitrix.batch({
179
188
 
180
189
  ### Development
181
190
 
182
- * `npm test` — run all tests and collect full coverage report
183
- * `npm run test:unit` — run unit tests and collect coverage report
184
- * `npm run test:integration` — run integration tests and collect coverage report
185
- * `npm run test:watch` — watch for changes and run all tests
186
- * `npm run test:unit:watch` — watch for changes and run unit tests
187
- * `npm run test:integration:watch` — watch for changes and run integration tests
188
- * `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
189
198
 
190
199
  #### Adding new methods
191
200
 
192
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:
193
202
 
194
- 1. Add new method into the [`Method`](https://github.com/2BAD/bitrix/tree/b0db508dcebe77f486f7db833183f28de7de14db/source/methods.ts) enum.
195
- 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.
196
- 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):
197
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.
198
207
  2. Add related entities into the `entities.ts`.
199
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!
200
- 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.
201
210
  5. Add tests into the `index.unit.test.ts`.
202
- 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.
203
- 5. Document addition in the [docs](https://github.com/2BAD/bitrix/tree/b0db508dcebe77f486f7db833183f28de7de14db/docs/README.md).
204
-
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,4 +1,13 @@
1
- declare const _default: (restURI: string, accessToken?: string | undefined) => {
1
+ import { ExtendOptions } from 'got';
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) => {
2
11
  call: import("./client/methods/call").Call;
3
12
  batch: import("./client/methods/batch").Batch;
4
13
  list: import("./client/methods/list").List;
@@ -7,16 +16,16 @@ declare const _default: (restURI: string, accessToken?: string | undefined) => {
7
16
  create: <D extends {
8
17
  readonly fields: Partial<import("./services/companies/entities").Company>;
9
18
  readonly params?: {
10
- readonly REGISTER_SONET_EVENT: import("./services/common").BoolString;
19
+ readonly REGISTER_SONET_EVENT: "Y" | "N";
11
20
  } | undefined;
12
21
  }>(fields: D["fields"], params?: D["params"] | undefined) => Promise<import("./payloads").GetPayload<number>>;
13
22
  get: (id: string) => Promise<import("./payloads").GetPayload<import("./services/companies/entities").Company>>;
14
23
  list: (params?: import("./methods").ListParams) => Promise<import("./payloads").ListPayload<import("./services/companies/entities").Company>>;
15
24
  update: <D_1 extends {
16
25
  readonly id: string;
17
- readonly fields: Record<string, any>;
26
+ readonly fields: Record<string, unknown>;
18
27
  readonly params?: {
19
- readonly REGISTER_SONET_EVENT: import("./services/common").BoolString;
28
+ readonly REGISTER_SONET_EVENT: "Y" | "N";
20
29
  } | undefined;
21
30
  }>(id: string, fields: D_1["fields"], params?: D_1["params"] | undefined) => Promise<import("./payloads").GetPayload<boolean>>;
22
31
  };
@@ -25,16 +34,16 @@ declare const _default: (restURI: string, accessToken?: string | undefined) => {
25
34
  create: <D_2 extends {
26
35
  readonly fields: Partial<import("./services/contacts/entities").Contact>;
27
36
  readonly params?: {
28
- readonly REGISTER_SONET_EVENT: import("./services/common").BoolString;
37
+ readonly REGISTER_SONET_EVENT: "Y" | "N";
29
38
  } | undefined;
30
39
  }>(fields: D_2["fields"], params?: D_2["params"] | undefined) => Promise<import("./payloads").GetPayload<number>>;
31
40
  get: (id: string) => Promise<import("./payloads").GetPayload<import("./services/contacts/entities").Contact>>;
32
41
  list: (params?: import("./methods").ListParams) => Promise<import("./payloads").ListPayload<import("./services/contacts/entities").Contact>>;
33
42
  update: <D_3 extends {
34
43
  readonly id: string;
35
- readonly fields: Record<string, any>;
44
+ readonly fields: Record<string, unknown>;
36
45
  readonly params?: {
37
- readonly REGISTER_SONET_EVENT: import("./services/common").BoolString;
46
+ readonly REGISTER_SONET_EVENT: "Y" | "N";
38
47
  } | undefined;
39
48
  }>(id: string, fields: D_3["fields"], params?: D_3["params"] | undefined) => Promise<import("./payloads").GetPayload<boolean>>;
40
49
  };
@@ -43,16 +52,16 @@ declare const _default: (restURI: string, accessToken?: string | undefined) => {
43
52
  create: <D_4 extends {
44
53
  readonly fields: Partial<import("./services/deals/entities").Deal>;
45
54
  readonly params?: {
46
- readonly REGISTER_SONET_EVENT: import("./services/common").BoolString;
55
+ readonly REGISTER_SONET_EVENT: "Y" | "N";
47
56
  } | undefined;
48
57
  }>(fields: D_4["fields"], params?: D_4["params"] | undefined) => Promise<import("./payloads").GetPayload<number>>;
49
58
  get: (id: string) => Promise<import("./payloads").GetPayload<import("./services/deals/entities").Deal>>;
50
59
  list: (params?: import("./methods").ListParams) => Promise<import("./payloads").ListPayload<import("./services/deals/entities").Deal>>;
51
60
  update: <D_5 extends {
52
61
  readonly id: string;
53
- readonly fields: Record<string, any>;
62
+ readonly fields: Record<string, unknown>;
54
63
  readonly params?: {
55
- readonly REGISTER_SONET_EVENT: import("./services/common").BoolString;
64
+ readonly REGISTER_SONET_EVENT: "Y" | "N";
56
65
  } | undefined;
57
66
  }>(id: string, fields: D_5["fields"], params?: D_5["params"] | undefined) => Promise<import("./payloads").GetPayload<boolean>>;
58
67
  };
@@ -61,16 +70,16 @@ declare const _default: (restURI: string, accessToken?: string | undefined) => {
61
70
  create: <D_6 extends {
62
71
  readonly fields: Partial<import("./services/leads/entities").Lead>;
63
72
  readonly params?: {
64
- readonly REGISTER_SONET_EVENT: import("./services/common").BoolString;
73
+ readonly REGISTER_SONET_EVENT: "Y" | "N";
65
74
  } | undefined;
66
75
  }>(fields: D_6["fields"], params?: D_6["params"] | undefined) => Promise<import("./payloads").GetPayload<number>>;
67
76
  get: (id: string) => Promise<import("./payloads").GetPayload<import("./services/leads/entities").Lead>>;
68
77
  list: (params?: import("./methods").ListParams) => Promise<import("./payloads").ListPayload<import("./services/leads/entities").Lead>>;
69
78
  update: <D_7 extends {
70
79
  readonly id: string;
71
- readonly fields: Record<string, any>;
80
+ readonly fields: Record<string, unknown>;
72
81
  readonly params?: {
73
- readonly REGISTER_SONET_EVENT: import("./services/common").BoolString;
82
+ readonly REGISTER_SONET_EVENT: "Y" | "N";
74
83
  } | undefined;
75
84
  }>(id: string, fields: D_7["fields"], params?: D_7["params"] | undefined) => Promise<import("./payloads").GetPayload<boolean>>;
76
85
  };
@@ -82,10 +91,10 @@ declare const _default: (restURI: string, accessToken?: string | undefined) => {
82
91
  } | undefined) => Promise<import("./payloads").GetPayload<boolean>>;
83
92
  get: (id: string | number) => Promise<import("./payloads").GetPayload<import("./services/statuses/entities").Status>>;
84
93
  list: (params?: {
85
- readonly order?: Record<string, any> | undefined;
86
- readonly filter?: Record<string, any> | undefined;
94
+ readonly order?: Record<string, unknown> | undefined;
95
+ readonly filter?: Record<string, unknown> | undefined;
87
96
  }) => Promise<import("./payloads").ListPayload<import("./services/statuses/entities").Status>>;
88
- update: (id: string | number, fields: Record<string, any>) => Promise<import("./payloads").GetPayload<boolean>>;
97
+ update: (id: string | number, fields: Record<string, unknown>) => Promise<import("./payloads").GetPayload<boolean>>;
89
98
  };
90
99
  users: {
91
100
  fields: () => Promise<import("./payloads").GetPayload<import("./services/users/entities").User>>;
@@ -29,4 +29,3 @@ describe('Bitrix API', () => {
29
29
  });
30
30
  });
31
31
  });
32
- //# sourceMappingURL=bitrix.integration.test.js.map
@@ -1,7 +1,18 @@
1
1
  "use strict";
2
- function __export(m) {
3
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
- }
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
5
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
6
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
7
18
  };
@@ -13,19 +24,35 @@ const deals_1 = __importDefault(require("./services/deals"));
13
24
  const leads_1 = __importDefault(require("./services/leads"));
14
25
  const statuses_1 = __importDefault(require("./services/statuses"));
15
26
  const users_1 = __importDefault(require("./services/users"));
16
- exports.default = (restURI, accessToken) => {
17
- const { call, batch, list } = client_1.default(restURI, accessToken);
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
+ */
35
+ exports.default = (restURI, accessToken, clientOptions) => {
36
+ const { call, batch, list } = (0, client_1.default)(restURI, accessToken, clientOptions);
18
37
  return {
19
38
  call,
20
39
  batch,
21
40
  list,
22
- companies: companies_1.default({ call, list }),
23
- contacts: contacts_1.default({ call, list }),
24
- deals: deals_1.default({ call, list }),
25
- leads: leads_1.default({ call, list }),
26
- statuses: statuses_1.default({ call }),
27
- 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 })
28
47
  };
29
48
  };
30
- __export(require("./methods"));
31
- //# sourceMappingURL=bitrix.js.map
49
+ __exportStar(require("./methods"), exports);
50
+ __exportStar(require("./commands"), exports);
51
+ __exportStar(require("./services/common"), exports);
52
+ __exportStar(require("./services/companies/entities"), exports);
53
+ __exportStar(require("./services/contacts/entities"), exports);
54
+ __exportStar(require("./services/currencies/entities"), exports);
55
+ __exportStar(require("./services/deals/entities"), exports);
56
+ __exportStar(require("./services/leads/entities"), exports);
57
+ __exportStar(require("./services/statuses/entities"), exports);
58
+ __exportStar(require("./services/users/entities"), exports);
@@ -1,29 +1,44 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
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
+ });
5
18
  var __importStar = (this && this.__importStar) || function (mod) {
6
19
  if (mod && mod.__esModule) return mod;
7
20
  var result = {};
8
- if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
9
- result["default"] = mod;
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);
10
23
  return result;
11
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
12
28
  Object.defineProperty(exports, "__esModule", { value: true });
13
29
  const bitrix_1 = __importDefault(require("./bitrix"));
14
30
  const client = __importStar(require("./client"));
15
31
  describe('Bitrix', () => {
16
32
  it('should init', () => {
17
- expect(() => bitrix_1.default('https://test.com', 'test_token')).not.toThrow();
33
+ expect(() => (0, bitrix_1.default)('https://test.com', 'test_token')).not.toThrow();
18
34
  });
19
35
  it('should pass endpoint and access token to the client', () => {
20
36
  const SpiedClient = jest.spyOn(client, 'default');
21
- bitrix_1.default('https://test.com', 'test_token');
37
+ (0, bitrix_1.default)('https://test.com', 'test_token');
22
38
  expect(SpiedClient.mock.calls).toMatchSnapshot();
23
39
  });
24
40
  it('should expose API methods', () => {
25
- const bitrix = bitrix_1.default('https://test.com', 'test_token');
41
+ const bitrix = (0, bitrix_1.default)('https://test.com', 'test_token');
26
42
  expect(bitrix).toMatchSnapshot();
27
43
  });
28
44
  });
29
- //# sourceMappingURL=bitrix.unit.test.js.map
@@ -12,30 +12,30 @@ const TEST_URI = 'https://test.com/rest';
12
12
  const TEST_ACCESS_TOKEN = 'test_access_token';
13
13
  const RESPONSE_200 = 200;
14
14
  const spiedQueueAdd = jest.spyOn(p_queue_1.default.prototype, 'add');
15
- const client = index_1.default(TEST_URI, TEST_ACCESS_TOKEN);
15
+ const client = (0, index_1.default)(TEST_URI, TEST_ACCESS_TOKEN);
16
16
  describe('Client', () => {
17
17
  beforeEach(() => {
18
18
  spiedQueueAdd.mockClear();
19
19
  });
20
20
  it('should init', () => {
21
- expect(() => index_1.default(TEST_URI, TEST_ACCESS_TOKEN)).not.toThrow();
21
+ expect(() => (0, index_1.default)(TEST_URI, TEST_ACCESS_TOKEN)).not.toThrow();
22
22
  });
23
23
  it('should extend `Got` instance with a specified parameters', () => {
24
24
  const spiedGotExtend = jest.spyOn(got_1.default, 'extend');
25
- index_1.default('https://test.com', 'test_token');
25
+ (0, index_1.default)('https://test.com', 'test_token', { https: { rejectUnauthorized: false } });
26
26
  expect(spiedGotExtend.mock.calls).toMatchSnapshot();
27
27
  });
28
28
  it('should expose API methods', () => {
29
29
  expect(client).toMatchSnapshot();
30
30
  });
31
31
  describe('`call`', () => {
32
- it('should add to queue', async () => {
32
+ // @todo restore test when issue is resolved (https://github.com/nock/nock/issues/1832)
33
+ it.skip('should add to queue', async () => {
33
34
  const payload = {};
34
35
  const method = methods_1.Method.CRM_DEAL_LIST;
35
- nock_1.default(TEST_URI)
36
- .get(`/${method}?access_token=${TEST_ACCESS_TOKEN}`)
37
- .reply(RESPONSE_200, payload)
36
+ (0, nock_1.default)(TEST_URI)
38
37
  .get(`/${method}?access_token=${TEST_ACCESS_TOKEN}`)
38
+ .twice()
39
39
  .reply(RESPONSE_200, payload);
40
40
  await client.call(method, {});
41
41
  await client.call(method, {});
@@ -43,7 +43,8 @@ describe('Client', () => {
43
43
  });
44
44
  });
45
45
  describe('`batch`', () => {
46
- it('should add to queue', async () => {
46
+ // @todo restore test when issue is resolved (https://github.com/nock/nock/issues/1832)
47
+ it.skip('should add to queue', async () => {
47
48
  const payload = {
48
49
  result: {
49
50
  result: ['done'],
@@ -54,7 +55,10 @@ describe('Client', () => {
54
55
  { method: methods_1.Method.CRM_DEAL_GET },
55
56
  { method: methods_1.Method.CRM_DEAL_LIST }
56
57
  ];
57
- nock_1.default(TEST_URI)
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
58
62
  .get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[0].method}&access_token=${TEST_ACCESS_TOKEN}`)
59
63
  .reply(RESPONSE_200, payload)
60
64
  .get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[1].method}&access_token=${TEST_ACCESS_TOKEN}`)
@@ -64,4 +68,3 @@ describe('Client', () => {
64
68
  });
65
69
  });
66
70
  });
67
- //# sourceMappingURL=client.unit.test.js.map
@@ -1,3 +1,6 @@
1
- import got from 'got';
2
- declare const _default: (accessToken?: string | undefined) => (options: got.GotJSONOptions) => void;
1
+ import { BeforeRequestHook } from 'got';
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
@@ -3,28 +3,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const got_1 = __importDefault(require("got"));
6
7
  const addAccessToken_1 = __importDefault(require("./addAccessToken"));
7
8
  const token = 'mock_token';
9
+ const merge = got_1.default.mergeOptions;
8
10
  describe('Client `addAccessToken` hook', () => {
9
11
  it('should add access token to URL without a query', () => {
10
- const options = { json: true, path: '/test' };
11
- addAccessToken_1.default(token)(options);
12
- expect(options.path).toBe(`/test?access_token=${token}`);
12
+ const options = merge({ path: 'test', responseType: 'json' });
13
+ (0, addAccessToken_1.default)(token)(options);
14
+ expect(options.path).toBe(`test?access_token=${token}`);
13
15
  });
14
16
  it('should add access token to URL with a query', () => {
15
- const options = { json: true, path: '/test?value=1' };
16
- addAccessToken_1.default(token)(options);
17
- expect(options.path).toBe(`/test?value=1&access_token=${token}`);
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}`);
18
20
  });
19
21
  it('should not add access token when it is undefined', () => {
20
- const options = { json: true, path: '/test' };
21
- addAccessToken_1.default()(options);
22
- expect(options.path).toBe('/test');
22
+ const options = merge({ path: 'test', responseType: 'json' });
23
+ (0, addAccessToken_1.default)()(options);
24
+ expect(options.path).toBe('test');
23
25
  });
24
26
  it('should not add access token when URL is undefined', () => {
25
- const options = { json: true, path: undefined };
26
- addAccessToken_1.default(token)(options);
27
+ const options = merge({ path: undefined, responseType: 'json' });
28
+ (0, addAccessToken_1.default)(token)(options);
27
29
  expect(options.path).toBe(undefined);
28
30
  });
29
31
  });
30
- //# sourceMappingURL=addAccessToken.unit.test.js.map
@@ -1,4 +1,13 @@
1
- declare const _default: (restURI: string, accessToken?: string | undefined) => {
1
+ import { ExtendOptions } from 'got';
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) => {
2
11
  call: import("./methods/call").Call;
3
12
  batch: import("./methods/batch").Batch;
4
13
  list: import("./methods/list").List;
@@ -10,32 +10,44 @@ 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;
14
- exports.default = (restURI, accessToken) => {
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
+ */
22
+ exports.default = (restURI, accessToken, options) => {
15
23
  const client = got_1.default.extend({
16
- baseUrl: restURI,
24
+ prefixUrl: restURI,
17
25
  headers: {
18
- 'user-agent': `@2bad/bitrix`
26
+ 'user-agent': '@2bad/bitrix'
19
27
  },
20
- json: true,
28
+ responseType: 'json',
21
29
  hooks: {
22
30
  beforeRequest: [
23
- addAccessToken_1.default(accessToken)
31
+ (0, addAccessToken_1.default)(accessToken)
24
32
  ]
25
- }
33
+ },
34
+ ...options !== null && options !== void 0 ? options : {}
26
35
  });
27
36
  const queue = new p_queue_1.default({
28
37
  intervalCap: BITRIX_API_RATE_LIMIT,
29
38
  interval: BITRIX_API_RATE_INTERVAL
30
39
  });
31
40
  const queuedGet = (...args) => queue.add(() => client.get(...args));
32
- const call = call_1.default({ get: queuedGet });
33
- const batch = batch_1.default({ get: queuedGet });
34
- 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 });
35
48
  return {
36
49
  call,
37
50
  batch,
38
51
  list
39
52
  };
40
53
  };
41
- //# sourceMappingURL=index.js.map