@2bad/bitrix 2.5.1 → 3.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. package/README.md +1 -2
  2. package/build/bitrix.d.ts +65 -0
  3. package/build/bitrix.js +55 -0
  4. package/build/client/hooks/addAccessToken.js +9 -0
  5. package/build/{module/client → client}/index.d.ts +3 -3
  6. package/build/{module/client → client}/index.js +21 -16
  7. package/build/{module/client → client}/methods/batch.d.ts +6 -6
  8. package/build/client/methods/batch.js +75 -0
  9. package/build/{module/client → client}/methods/call.d.ts +4 -4
  10. package/build/{module/client → client}/methods/call.js +8 -9
  11. package/build/{module/client → client}/methods/list.d.ts +10 -10
  12. package/build/client/methods/list.js +58 -0
  13. package/build/{module/commands.d.ts → commands.d.ts} +3 -3
  14. package/build/commands.js +1 -0
  15. package/build/{module/methods.d.ts → methods.d.ts} +19 -19
  16. package/build/{module/methods.js → methods.js} +5 -5
  17. package/build/{main/payloads.d.ts → payloads.d.ts} +5 -5
  18. package/build/payloads.js +1 -0
  19. package/build/{main/services → services}/common.d.ts +7 -7
  20. package/build/services/common.js +2 -0
  21. package/build/{main/services → services}/companies/entities.d.ts +2 -2
  22. package/build/services/companies/entities.js +1 -0
  23. package/build/services/companies/index.d.ts +15 -0
  24. package/build/services/companies/index.js +17 -0
  25. package/build/{module/services → services}/companies/methods.d.ts +5 -5
  26. package/build/services/companies/methods.js +1 -0
  27. package/build/{module/services → services}/contacts/entities.d.ts +2 -2
  28. package/build/services/contacts/entities.js +1 -0
  29. package/build/services/contacts/index.d.ts +15 -0
  30. package/build/services/contacts/index.js +17 -0
  31. package/build/{module/services → services}/contacts/methods.d.ts +5 -5
  32. package/build/services/contacts/methods.js +1 -0
  33. package/build/{module/services → services}/currencies/entities.d.ts +2 -2
  34. package/build/services/currencies/entities.js +1 -0
  35. package/build/{module/services → services}/deals/entities.d.ts +2 -2
  36. package/build/services/deals/entities.js +1 -0
  37. package/build/services/deals/index.d.ts +15 -0
  38. package/build/services/deals/index.js +17 -0
  39. package/build/{main/services → services}/deals/methods.d.ts +5 -5
  40. package/build/services/deals/methods.js +1 -0
  41. package/build/{module/services → services}/leads/entities.d.ts +2 -2
  42. package/build/services/leads/entities.js +1 -0
  43. package/build/services/leads/index.d.ts +15 -0
  44. package/build/services/leads/index.js +17 -0
  45. package/build/{main/services → services}/leads/methods.d.ts +5 -5
  46. package/build/services/leads/methods.js +1 -0
  47. package/build/{main/services → services}/statuses/entities.d.ts +3 -3
  48. package/build/services/statuses/entities.js +1 -0
  49. package/build/services/statuses/index.d.ts +14 -0
  50. package/build/services/statuses/index.js +19 -0
  51. package/build/{main/services → services}/statuses/methods.d.ts +5 -5
  52. package/build/services/statuses/methods.js +1 -0
  53. package/build/{module/services → services}/users/entities.d.ts +2 -2
  54. package/build/services/users/entities.js +1 -0
  55. package/build/services/users/index.d.ts +9 -0
  56. package/build/services/users/index.js +7 -0
  57. package/build/{main/services → services}/users/methods.d.ts +4 -4
  58. package/build/services/users/methods.js +1 -0
  59. package/build/utils/Diff.d.ts +1 -0
  60. package/build/utils/Diff.js +7 -0
  61. package/build/{module/utils → utils}/ExtractValue.d.ts +1 -1
  62. package/build/{main/utils/ExtractValue.d.ts → utils/ExtractValue.js} +1 -2
  63. package/build/utils/isArray.d.ts +2 -0
  64. package/build/{module/utils → utils}/isArray.js +1 -1
  65. package/package.json +43 -49
  66. package/build/main/bitrix.d.ts +0 -114
  67. package/build/main/bitrix.integration.test.d.ts +0 -0
  68. package/build/main/bitrix.integration.test.js +0 -31
  69. package/build/main/bitrix.js +0 -61
  70. package/build/main/bitrix.unit.test.d.ts +0 -1
  71. package/build/main/bitrix.unit.test.js +0 -44
  72. package/build/main/client/client.unit.test.d.ts +0 -1
  73. package/build/main/client/client.unit.test.js +0 -70
  74. package/build/main/client/hooks/addAccessToken.js +0 -13
  75. package/build/main/client/hooks/addAccessToken.unit.test.d.ts +0 -1
  76. package/build/main/client/hooks/addAccessToken.unit.test.js +0 -31
  77. package/build/main/client/index.d.ts +0 -15
  78. package/build/main/client/index.js +0 -53
  79. package/build/main/client/methods/batch.d.ts +0 -40
  80. package/build/main/client/methods/batch.js +0 -85
  81. package/build/main/client/methods/batch.unit.test.d.ts +0 -1
  82. package/build/main/client/methods/batch.unit.test.js +0 -494
  83. package/build/main/client/methods/call.d.ts +0 -17
  84. package/build/main/client/methods/call.js +0 -36
  85. package/build/main/client/methods/call.unit.test.d.ts +0 -1
  86. package/build/main/client/methods/call.unit.test.js +0 -183
  87. package/build/main/client/methods/list.d.ts +0 -30
  88. package/build/main/client/methods/list.js +0 -66
  89. package/build/main/client/methods/list.unit.test.d.ts +0 -1
  90. package/build/main/client/methods/list.unit.test.js +0 -277
  91. package/build/main/commands.d.ts +0 -10
  92. package/build/main/commands.js +0 -2
  93. package/build/main/methods.d.ts +0 -92
  94. package/build/main/methods.js +0 -41
  95. package/build/main/payloads.js +0 -2
  96. package/build/main/services/common.js +0 -2
  97. package/build/main/services/companies/entities.js +0 -2
  98. package/build/main/services/companies/index.d.ts +0 -26
  99. package/build/main/services/companies/index.integration.test.d.ts +0 -1
  100. package/build/main/services/companies/index.integration.test.js +0 -19
  101. package/build/main/services/companies/index.js +0 -10
  102. package/build/main/services/companies/index.unit.test.d.ts +0 -1
  103. package/build/main/services/companies/index.unit.test.js +0 -72
  104. package/build/main/services/companies/methods.d.ts +0 -44
  105. package/build/main/services/companies/methods.js +0 -3
  106. package/build/main/services/contacts/entities.d.ts +0 -45
  107. package/build/main/services/contacts/entities.js +0 -2
  108. package/build/main/services/contacts/index.d.ts +0 -26
  109. package/build/main/services/contacts/index.integration.test.d.ts +0 -1
  110. package/build/main/services/contacts/index.integration.test.js +0 -19
  111. package/build/main/services/contacts/index.js +0 -10
  112. package/build/main/services/contacts/index.unit.test.d.ts +0 -1
  113. package/build/main/services/contacts/index.unit.test.js +0 -72
  114. package/build/main/services/contacts/methods.d.ts +0 -44
  115. package/build/main/services/contacts/methods.js +0 -3
  116. package/build/main/services/currencies/entities.d.ts +0 -15
  117. package/build/main/services/currencies/entities.js +0 -2
  118. package/build/main/services/deals/entities.d.ts +0 -43
  119. package/build/main/services/deals/entities.js +0 -2
  120. package/build/main/services/deals/index.d.ts +0 -26
  121. package/build/main/services/deals/index.integration.test.d.ts +0 -1
  122. package/build/main/services/deals/index.integration.test.js +0 -19
  123. package/build/main/services/deals/index.js +0 -10
  124. package/build/main/services/deals/index.unit.test.d.ts +0 -1
  125. package/build/main/services/deals/index.unit.test.js +0 -72
  126. package/build/main/services/deals/methods.js +0 -3
  127. package/build/main/services/leads/entities.d.ts +0 -49
  128. package/build/main/services/leads/entities.js +0 -2
  129. package/build/main/services/leads/index.d.ts +0 -26
  130. package/build/main/services/leads/index.integration.test.d.ts +0 -1
  131. package/build/main/services/leads/index.integration.test.js +0 -19
  132. package/build/main/services/leads/index.js +0 -10
  133. package/build/main/services/leads/index.unit.test.d.ts +0 -1
  134. package/build/main/services/leads/index.unit.test.js +0 -72
  135. package/build/main/services/leads/methods.js +0 -3
  136. package/build/main/services/statuses/entities.js +0 -2
  137. package/build/main/services/statuses/index.d.ts +0 -14
  138. package/build/main/services/statuses/index.integration.test.d.ts +0 -1
  139. package/build/main/services/statuses/index.integration.test.js +0 -90
  140. package/build/main/services/statuses/index.js +0 -11
  141. package/build/main/services/statuses/index.unit.test.d.ts +0 -1
  142. package/build/main/services/statuses/index.unit.test.js +0 -60
  143. package/build/main/services/statuses/methods.js +0 -3
  144. package/build/main/services/users/entities.d.ts +0 -40
  145. package/build/main/services/users/entities.js +0 -2
  146. package/build/main/services/users/index.d.ts +0 -9
  147. package/build/main/services/users/index.integration.test.d.ts +0 -1
  148. package/build/main/services/users/index.integration.test.js +0 -33
  149. package/build/main/services/users/index.js +0 -7
  150. package/build/main/services/users/index.unit.test.d.ts +0 -1
  151. package/build/main/services/users/index.unit.test.js +0 -25
  152. package/build/main/services/users/methods.js +0 -3
  153. package/build/main/utils/Diff.d.ts +0 -1
  154. package/build/main/utils/Diff.js +0 -2
  155. package/build/main/utils/ExtractValue.js +0 -2
  156. package/build/main/utils/isArray.d.ts +0 -2
  157. package/build/main/utils/isArray.js +0 -4
  158. package/build/module/bitrix.d.ts +0 -114
  159. package/build/module/bitrix.integration.test.d.ts +0 -0
  160. package/build/module/bitrix.integration.test.js +0 -31
  161. package/build/module/bitrix.js +0 -40
  162. package/build/module/bitrix.unit.test.d.ts +0 -1
  163. package/build/module/bitrix.unit.test.js +0 -16
  164. package/build/module/client/client.unit.test.d.ts +0 -1
  165. package/build/module/client/client.unit.test.js +0 -65
  166. package/build/module/client/hooks/addAccessToken.d.ts +0 -6
  167. package/build/module/client/hooks/addAccessToken.js +0 -11
  168. package/build/module/client/hooks/addAccessToken.unit.test.d.ts +0 -1
  169. package/build/module/client/hooks/addAccessToken.unit.test.js +0 -26
  170. package/build/module/client/methods/batch.js +0 -76
  171. package/build/module/client/methods/batch.unit.test.d.ts +0 -1
  172. package/build/module/client/methods/batch.unit.test.js +0 -466
  173. package/build/module/client/methods/call.unit.test.d.ts +0 -1
  174. package/build/module/client/methods/call.unit.test.js +0 -155
  175. package/build/module/client/methods/list.js +0 -55
  176. package/build/module/client/methods/list.unit.test.d.ts +0 -1
  177. package/build/module/client/methods/list.unit.test.js +0 -252
  178. package/build/module/commands.js +0 -1
  179. package/build/module/payloads.d.ts +0 -40
  180. package/build/module/payloads.js +0 -1
  181. package/build/module/services/common.d.ts +0 -22
  182. package/build/module/services/common.js +0 -1
  183. package/build/module/services/companies/entities.d.ts +0 -54
  184. package/build/module/services/companies/entities.js +0 -1
  185. package/build/module/services/companies/index.d.ts +0 -26
  186. package/build/module/services/companies/index.integration.test.d.ts +0 -1
  187. package/build/module/services/companies/index.integration.test.js +0 -14
  188. package/build/module/services/companies/index.js +0 -8
  189. package/build/module/services/companies/index.unit.test.d.ts +0 -1
  190. package/build/module/services/companies/index.unit.test.js +0 -67
  191. package/build/module/services/companies/methods.js +0 -1
  192. package/build/module/services/contacts/entities.js +0 -1
  193. package/build/module/services/contacts/index.d.ts +0 -26
  194. package/build/module/services/contacts/index.integration.test.d.ts +0 -1
  195. package/build/module/services/contacts/index.integration.test.js +0 -14
  196. package/build/module/services/contacts/index.js +0 -8
  197. package/build/module/services/contacts/index.unit.test.d.ts +0 -1
  198. package/build/module/services/contacts/index.unit.test.js +0 -67
  199. package/build/module/services/contacts/methods.js +0 -1
  200. package/build/module/services/currencies/entities.js +0 -1
  201. package/build/module/services/deals/entities.js +0 -1
  202. package/build/module/services/deals/index.d.ts +0 -26
  203. package/build/module/services/deals/index.integration.test.d.ts +0 -1
  204. package/build/module/services/deals/index.integration.test.js +0 -14
  205. package/build/module/services/deals/index.js +0 -8
  206. package/build/module/services/deals/index.unit.test.d.ts +0 -1
  207. package/build/module/services/deals/index.unit.test.js +0 -67
  208. package/build/module/services/deals/methods.d.ts +0 -44
  209. package/build/module/services/deals/methods.js +0 -1
  210. package/build/module/services/leads/entities.js +0 -1
  211. package/build/module/services/leads/index.d.ts +0 -26
  212. package/build/module/services/leads/index.integration.test.d.ts +0 -1
  213. package/build/module/services/leads/index.integration.test.js +0 -14
  214. package/build/module/services/leads/index.js +0 -8
  215. package/build/module/services/leads/index.unit.test.d.ts +0 -1
  216. package/build/module/services/leads/index.unit.test.js +0 -67
  217. package/build/module/services/leads/methods.d.ts +0 -44
  218. package/build/module/services/leads/methods.js +0 -1
  219. package/build/module/services/statuses/entities.d.ts +0 -16
  220. package/build/module/services/statuses/entities.js +0 -1
  221. package/build/module/services/statuses/index.d.ts +0 -14
  222. package/build/module/services/statuses/index.integration.test.d.ts +0 -1
  223. package/build/module/services/statuses/index.integration.test.js +0 -85
  224. package/build/module/services/statuses/index.js +0 -9
  225. package/build/module/services/statuses/index.unit.test.d.ts +0 -1
  226. package/build/module/services/statuses/index.unit.test.js +0 -55
  227. package/build/module/services/statuses/methods.d.ts +0 -51
  228. package/build/module/services/statuses/methods.js +0 -1
  229. package/build/module/services/users/entities.js +0 -1
  230. package/build/module/services/users/index.d.ts +0 -9
  231. package/build/module/services/users/index.integration.test.d.ts +0 -1
  232. package/build/module/services/users/index.integration.test.js +0 -28
  233. package/build/module/services/users/index.js +0 -5
  234. package/build/module/services/users/index.unit.test.d.ts +0 -1
  235. package/build/module/services/users/index.unit.test.js +0 -20
  236. package/build/module/services/users/methods.d.ts +0 -17
  237. package/build/module/services/users/methods.js +0 -1
  238. package/build/module/utils/Diff.d.ts +0 -1
  239. package/build/module/utils/Diff.js +0 -1
  240. package/build/module/utils/ExtractValue.js +0 -1
  241. package/build/module/utils/isArray.d.ts +0 -2
  242. /package/build/{main/client → client}/hooks/addAccessToken.d.ts +0 -0
@@ -1,114 +0,0 @@
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
- export declare const Bitrix: (restURI: string, accessToken?: string, clientOptions?: ExtendOptions) => {
11
- call: import("./client/methods/call").Call;
12
- batch: import("./client/methods/batch").Batch;
13
- list: import("./client/methods/list").List;
14
- companies: {
15
- fields: () => Promise<import("./payloads").GetPayload<import("./services/common").Fields>>;
16
- create: <D extends {
17
- readonly fields: Partial<import("./services/companies/entities").Company>;
18
- readonly params?: {
19
- readonly REGISTER_SONET_EVENT: "Y" | "N";
20
- } | undefined;
21
- }>(fields: D["fields"], params?: D["params"] | undefined) => Promise<import("./payloads").GetPayload<number>>;
22
- get: (id: string) => Promise<import("./payloads").GetPayload<import("./services/companies/entities").Company>>;
23
- list: (params?: import("./methods").ListParams) => Promise<import("./payloads").ListPayload<import("./services/companies/entities").Company>>;
24
- update: <D_1 extends {
25
- readonly id: string;
26
- readonly fields: Record<string, unknown>;
27
- readonly params?: {
28
- readonly REGISTER_SONET_EVENT: "Y" | "N";
29
- } | undefined;
30
- }>(id: string, fields: D_1["fields"], params?: D_1["params"] | undefined) => Promise<import("./payloads").GetPayload<boolean>>;
31
- };
32
- contacts: {
33
- fields: () => Promise<import("./payloads").GetPayload<import("./services/common").Fields>>;
34
- create: <D_2 extends {
35
- readonly fields: Partial<import("./services/contacts/entities").Contact>;
36
- readonly params?: {
37
- readonly REGISTER_SONET_EVENT: "Y" | "N";
38
- } | undefined;
39
- }>(fields: D_2["fields"], params?: D_2["params"] | undefined) => Promise<import("./payloads").GetPayload<number>>;
40
- get: (id: string) => Promise<import("./payloads").GetPayload<import("./services/contacts/entities").Contact>>;
41
- list: (params?: import("./methods").ListParams) => Promise<import("./payloads").ListPayload<import("./services/contacts/entities").Contact>>;
42
- update: <D_3 extends {
43
- readonly id: string;
44
- readonly fields: Record<string, unknown>;
45
- readonly params?: {
46
- readonly REGISTER_SONET_EVENT: "Y" | "N";
47
- } | undefined;
48
- }>(id: string, fields: D_3["fields"], params?: D_3["params"] | undefined) => Promise<import("./payloads").GetPayload<boolean>>;
49
- };
50
- deals: {
51
- fields: () => Promise<import("./payloads").GetPayload<import("./services/common").Fields>>;
52
- create: <D_4 extends {
53
- readonly fields: Partial<import("./services/deals/entities").Deal>;
54
- readonly params?: {
55
- readonly REGISTER_SONET_EVENT: "Y" | "N";
56
- } | undefined;
57
- }>(fields: D_4["fields"], params?: D_4["params"] | undefined) => Promise<import("./payloads").GetPayload<number>>;
58
- get: (id: string) => Promise<import("./payloads").GetPayload<import("./services/deals/entities").Deal>>;
59
- list: (params?: import("./methods").ListParams) => Promise<import("./payloads").ListPayload<import("./services/deals/entities").Deal>>;
60
- update: <D_5 extends {
61
- readonly id: string;
62
- readonly fields: Record<string, unknown>;
63
- readonly params?: {
64
- readonly REGISTER_SONET_EVENT: "Y" | "N";
65
- } | undefined;
66
- }>(id: string, fields: D_5["fields"], params?: D_5["params"] | undefined) => Promise<import("./payloads").GetPayload<boolean>>;
67
- };
68
- leads: {
69
- fields: () => Promise<import("./payloads").GetPayload<import("./services/common").Fields>>;
70
- create: <D_6 extends {
71
- readonly fields: Partial<import("./services/leads/entities").Lead>;
72
- readonly params?: {
73
- readonly REGISTER_SONET_EVENT: "Y" | "N";
74
- } | undefined;
75
- }>(fields: D_6["fields"], params?: D_6["params"] | undefined) => Promise<import("./payloads").GetPayload<number>>;
76
- get: (id: string) => Promise<import("./payloads").GetPayload<import("./services/leads/entities").Lead>>;
77
- list: (params?: import("./methods").ListParams) => Promise<import("./payloads").ListPayload<import("./services/leads/entities").Lead>>;
78
- update: <D_7 extends {
79
- readonly id: string;
80
- readonly fields: Record<string, unknown>;
81
- readonly params?: {
82
- readonly REGISTER_SONET_EVENT: "Y" | "N";
83
- } | undefined;
84
- }>(id: string, fields: D_7["fields"], params?: D_7["params"] | undefined) => Promise<import("./payloads").GetPayload<boolean>>;
85
- };
86
- statuses: {
87
- fields: () => Promise<import("./payloads").GetPayload<import("./services/common").Fields>>;
88
- create: (fields: Partial<import("./services/statuses/entities").Status>) => Promise<import("./payloads").GetPayload<number>>;
89
- delete: (id: string | number, params?: {
90
- readonly FORCED?: "Y" | "N" | undefined;
91
- } | undefined) => Promise<import("./payloads").GetPayload<boolean>>;
92
- get: (id: string | number) => Promise<import("./payloads").GetPayload<import("./services/statuses/entities").Status>>;
93
- list: (params?: {
94
- readonly order?: Record<string, unknown> | undefined;
95
- readonly filter?: Record<string, unknown> | undefined;
96
- }) => Promise<import("./payloads").ListPayload<import("./services/statuses/entities").Status>>;
97
- update: (id: string | number, fields: Record<string, unknown>) => Promise<import("./payloads").GetPayload<boolean>>;
98
- };
99
- users: {
100
- fields: () => Promise<import("./payloads").GetPayload<import("./services/users/entities").User>>;
101
- get: (id?: string | undefined) => Promise<import("./payloads").GetPayload<readonly import("./services/users/entities").User[]>>;
102
- };
103
- };
104
- export default Bitrix;
105
- export * from './methods';
106
- export * from './commands';
107
- export * from './services/common';
108
- export * from './services/companies/entities';
109
- export * from './services/contacts/entities';
110
- export * from './services/currencies/entities';
111
- export * from './services/deals/entities';
112
- export * from './services/leads/entities';
113
- export * from './services/statuses/entities';
114
- export * from './services/users/entities';
File without changes
@@ -1,31 +0,0 @@
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,40 +0,0 @@
1
- import Client from './client';
2
- import CompaniesService from './services/companies';
3
- import ContactsService from './services/contacts';
4
- import DealsService from './services/deals';
5
- import LeadsService from './services/leads';
6
- import StatusesService from './services/statuses';
7
- import UsersService from './services/users';
8
- /**
9
- * Construct a Bitrix client with generic methods
10
- * @param restURI REST endpoint, like a `https://hello.bitrix24.ua/rest` or an inbound webhook endpoint,
11
- * like a `https://hello.bitrix24.ua/rest/1/WEBHOOK_TOKEN`.
12
- * @param accessToken Bitrix application Access Token. Do not specify in case inbound webhook endpoint used.
13
- * @param clientOptions an object that will overwrite underlying configuration for HTTP client,
14
- * see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
15
- */
16
- export const Bitrix = (restURI, accessToken, clientOptions) => {
17
- const { call, batch, list } = Client(restURI, accessToken, clientOptions);
18
- return {
19
- call,
20
- batch,
21
- list,
22
- companies: CompaniesService({ call, list }),
23
- contacts: ContactsService({ call, list }),
24
- deals: DealsService({ call, list }),
25
- leads: LeadsService({ call, list }),
26
- statuses: StatusesService({ call }),
27
- users: UsersService({ call })
28
- };
29
- };
30
- export default Bitrix;
31
- export * from './methods';
32
- export * from './commands';
33
- export * from './services/common';
34
- export * from './services/companies/entities';
35
- export * from './services/contacts/entities';
36
- export * from './services/currencies/entities';
37
- export * from './services/deals/entities';
38
- export * from './services/leads/entities';
39
- export * from './services/statuses/entities';
40
- export * from './services/users/entities';
@@ -1 +0,0 @@
1
- export {};
@@ -1,16 +0,0 @@
1
- import Bitrix from './bitrix';
2
- import * as client from './client';
3
- describe('Bitrix', () => {
4
- it('should init', () => {
5
- expect(() => Bitrix('https://test.com', 'test_token')).not.toThrow();
6
- });
7
- it('should pass endpoint and access token to the client', () => {
8
- const SpiedClient = jest.spyOn(client, 'default');
9
- Bitrix('https://test.com', 'test_token');
10
- expect(SpiedClient.mock.calls).toMatchSnapshot();
11
- });
12
- it('should expose API methods', () => {
13
- const bitrix = Bitrix('https://test.com', 'test_token');
14
- expect(bitrix).toMatchSnapshot();
15
- });
16
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,65 +0,0 @@
1
- import got from 'got';
2
- import nock from 'nock';
3
- import Queue from 'p-queue';
4
- import { Method } from '../methods';
5
- import Client from './index';
6
- const TEST_URI = 'https://test.com/rest';
7
- const TEST_ACCESS_TOKEN = 'test_access_token';
8
- const RESPONSE_200 = 200;
9
- const spiedQueueAdd = jest.spyOn(Queue.prototype, 'add');
10
- const client = Client(TEST_URI, TEST_ACCESS_TOKEN);
11
- describe('Client', () => {
12
- beforeEach(() => {
13
- spiedQueueAdd.mockClear();
14
- });
15
- it('should init', () => {
16
- expect(() => Client(TEST_URI, TEST_ACCESS_TOKEN)).not.toThrow();
17
- });
18
- it('should extend `Got` instance with a specified parameters', () => {
19
- const spiedGotExtend = jest.spyOn(got, 'extend');
20
- Client('https://test.com', 'test_token', { https: { rejectUnauthorized: false } });
21
- expect(spiedGotExtend.mock.calls).toMatchSnapshot();
22
- });
23
- it('should expose API methods', () => {
24
- expect(client).toMatchSnapshot();
25
- });
26
- describe('`call`', () => {
27
- // @todo restore test when issue is resolved (https://github.com/nock/nock/issues/1832)
28
- it.skip('should add to queue', async () => {
29
- const payload = {};
30
- const method = Method.CRM_DEAL_LIST;
31
- nock(TEST_URI)
32
- .get(`/${method}?access_token=${TEST_ACCESS_TOKEN}`)
33
- .twice()
34
- .reply(RESPONSE_200, payload);
35
- await client.call(method, {});
36
- await client.call(method, {});
37
- expect(spiedQueueAdd.mock.calls).toMatchSnapshot();
38
- });
39
- });
40
- describe('`batch`', () => {
41
- // @todo restore test when issue is resolved (https://github.com/nock/nock/issues/1832)
42
- it.skip('should add to queue', async () => {
43
- const payload = {
44
- result: {
45
- result: ['done'],
46
- result_error: []
47
- }
48
- };
49
- const commands = [
50
- { method: Method.CRM_DEAL_GET },
51
- { method: Method.CRM_DEAL_LIST }
52
- ];
53
- nock(TEST_URI)
54
- // @todo We'd want to use `query` object here as it is much more readable, but nock for some reason
55
- // fails to match request when it contains `cmd[someName]`. The issue definitely connected
56
- // to the `[]`, since it does not appear when only one bracket present
57
- .get(`/${Method.BATCH}?cmd%5B0%5D=${commands[0].method}&access_token=${TEST_ACCESS_TOKEN}`)
58
- .reply(RESPONSE_200, payload)
59
- .get(`/${Method.BATCH}?cmd%5B0%5D=${commands[1].method}&access_token=${TEST_ACCESS_TOKEN}`)
60
- .reply(RESPONSE_200, payload);
61
- await client.batch(commands, 1);
62
- expect(spiedQueueAdd.mock.calls).toMatchSnapshot();
63
- });
64
- });
65
- });
@@ -1,6 +0,0 @@
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;
6
- export default _default;
@@ -1,11 +0,0 @@
1
- /**
2
- * Got can't merge `query` option with other queries if they are string. But that hook can.
3
- */
4
- export default (accessToken) => (options) => {
5
- if (!accessToken)
6
- return;
7
- if (!options.path)
8
- return;
9
- const hasQuery = options.path.includes('?');
10
- options.path = `${options.path}${hasQuery ? '&' : '?'}access_token=${accessToken}`;
11
- };
@@ -1,26 +0,0 @@
1
- import got from 'got';
2
- import addAccessToken from './addAccessToken';
3
- const token = 'mock_token';
4
- const merge = got.mergeOptions;
5
- describe('Client `addAccessToken` hook', () => {
6
- it('should add access token to URL without a query', () => {
7
- const options = merge({ path: 'test', responseType: 'json' });
8
- addAccessToken(token)(options);
9
- expect(options.path).toBe(`test?access_token=${token}`);
10
- });
11
- it('should add access token to URL with a query', () => {
12
- const options = merge({ path: 'test?value=1', responseType: 'json' });
13
- addAccessToken(token)(options);
14
- expect(options.path).toBe(`test?value=1&access_token=${token}`);
15
- });
16
- it('should not add access token when it is undefined', () => {
17
- const options = merge({ path: 'test', responseType: 'json' });
18
- addAccessToken()(options);
19
- expect(options.path).toBe('test');
20
- });
21
- it('should not add access token when URL is undefined', () => {
22
- const options = merge({ path: undefined, responseType: 'json' });
23
- addAccessToken(token)(options);
24
- expect(options.path).toBe(undefined);
25
- });
26
- });
@@ -1,76 +0,0 @@
1
- import chunk from 'lodash.chunk';
2
- import fromPairs from 'lodash.frompairs';
3
- import { stringify as toQuery } from 'qs';
4
- import { Method } from '../../methods';
5
- import isArray from '../../utils/isArray';
6
- import { handlePayload } from './call';
7
- export const MAX_COMMANDS_PER_BATCH = 50;
8
- /**
9
- * Split any number of commands into the chunks with max commands per batch in each chunk
10
- */
11
- export const chunkCommands = (commands, size = MAX_COMMANDS_PER_BATCH) => {
12
- const commandsIsArray = isArray(commands);
13
- const chunks = chunk(Object.entries(commands), size);
14
- // @todo Generated return type isn't very accurate since it says that it will make array of <C>, while
15
- // in fact <C> will be distributed among chunks. That gives wrong hints with named commands and arrays as const.
16
- return chunks.map((c) => commandsIsArray
17
- // @todo Figure out how to avoid unsafe casting to <C> here
18
- // Without `<C>` generic it won't work with complex functions like `batch`
19
- ? c.map(([_key, command]) => command)
20
- : fromPairs(c));
21
- };
22
- /**
23
- * Prepares list of commands to be used in requests to the Bitrix
24
- * @note We could avoid that function... if only Bitrix API would support posting of the batch commands as
25
- * plain objects, like it does with other methods. Instead, it should be a dict or array of string queries
26
- */
27
- export const prepareCommandsQueries = (commands) => Object.entries(commands).reduce((calls, [name, { method, params }]) => {
28
- const stringifiedParams = params ? `?${toQuery(params)}` : '';
29
- return {
30
- ...calls,
31
- [`cmd[${name}]`]: `${method}${stringifiedParams}`
32
- };
33
- // eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter
34
- }, {});
35
- /**
36
- * Merges list of batch responses into a single batch
37
- * @todo Generics inference is complicated here and might be not super accurate
38
- */
39
- export const mergeBatchPayloads = (payloads) => {
40
- const merge = (a, b) => isArray(a) && isArray(b)
41
- // @todo Gotta find way to avoid unsafe casting here
42
- ? [...a, ...b]
43
- : ({ ...a, ...b });
44
- return payloads.reduce((merged, payload) => ({
45
- result: {
46
- result: merge(merged.result.result || [], payload.result.result),
47
- result_error: merge(merged.result.result_error || [], payload.result.result_error),
48
- result_next: merge(merged.result.result_next || [], payload.result.result_next),
49
- result_time: merge(merged.result.result_time || [], payload.result.result_time),
50
- result_total: merge(merged.result.result_total || [], payload.result.result_total)
51
- },
52
- time: { ...merged.time, ...payload.time }
53
- // eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter
54
- }), { result: {}, time: {} });
55
- };
56
- /**
57
- * Dispatches a batch request with specified commands. Will fill figure out payload type based on the Methods.
58
- * Supports unlimited number of commands. If they do exceed max amount of commands per batch, will dispatch
59
- * multiple request and merge result into single batch payload
60
- * @todo For now due to issues with types it won't check `params` of command, so any Method can be used
61
- * with any (even wrong) params
62
- */
63
- export default ({ get }) => {
64
- const batch = async (commands, commandsPerRequest = MAX_COMMANDS_PER_BATCH) => {
65
- const call = (c) => get(Method.BATCH, { searchParams: prepareCommandsQueries(c) })
66
- .then(({ body }) => body);
67
- const calls = chunkCommands(commands, commandsPerRequest)
68
- .map(call);
69
- return await Promise.all(calls)
70
- .then((chunkedPayloads) => {
71
- const payloads = mergeBatchPayloads(chunkedPayloads);
72
- return handlePayload(payloads);
73
- });
74
- };
75
- return batch;
76
- };
@@ -1 +0,0 @@
1
- export {};