@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,61 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __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
- };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.Bitrix = void 0;
21
- const client_1 = __importDefault(require("./client"));
22
- const companies_1 = __importDefault(require("./services/companies"));
23
- const contacts_1 = __importDefault(require("./services/contacts"));
24
- const deals_1 = __importDefault(require("./services/deals"));
25
- const leads_1 = __importDefault(require("./services/leads"));
26
- const statuses_1 = __importDefault(require("./services/statuses"));
27
- const users_1 = __importDefault(require("./services/users"));
28
- /**
29
- * Construct a Bitrix client with generic methods
30
- * @param restURI REST endpoint, like a `https://hello.bitrix24.ua/rest` or an inbound webhook endpoint,
31
- * like a `https://hello.bitrix24.ua/rest/1/WEBHOOK_TOKEN`.
32
- * @param accessToken Bitrix application Access Token. Do not specify in case inbound webhook endpoint used.
33
- * @param clientOptions an object that will overwrite underlying configuration for HTTP client,
34
- * see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
35
- */
36
- const Bitrix = (restURI, accessToken, clientOptions) => {
37
- const { call, batch, list } = (0, client_1.default)(restURI, accessToken, clientOptions);
38
- return {
39
- call,
40
- batch,
41
- list,
42
- companies: (0, companies_1.default)({ call, list }),
43
- contacts: (0, contacts_1.default)({ call, list }),
44
- deals: (0, deals_1.default)({ call, list }),
45
- leads: (0, leads_1.default)({ call, list }),
46
- statuses: (0, statuses_1.default)({ call }),
47
- users: (0, users_1.default)({ call })
48
- };
49
- };
50
- exports.Bitrix = Bitrix;
51
- exports.default = exports.Bitrix;
52
- __exportStar(require("./methods"), exports);
53
- __exportStar(require("./commands"), exports);
54
- __exportStar(require("./services/common"), exports);
55
- __exportStar(require("./services/companies/entities"), exports);
56
- __exportStar(require("./services/contacts/entities"), exports);
57
- __exportStar(require("./services/currencies/entities"), exports);
58
- __exportStar(require("./services/deals/entities"), exports);
59
- __exportStar(require("./services/leads/entities"), exports);
60
- __exportStar(require("./services/statuses/entities"), exports);
61
- __exportStar(require("./services/users/entities"), exports);
@@ -1 +0,0 @@
1
- export {};
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const 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
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,70 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- 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,13 +0,0 @@
1
- "use strict";
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
- */
6
- exports.default = (accessToken) => (options) => {
7
- if (!accessToken)
8
- return;
9
- if (!options.path)
10
- return;
11
- const hasQuery = options.path.includes('?');
12
- options.path = `${options.path}${hasQuery ? '&' : '?'}access_token=${accessToken}`;
13
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- 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,15 +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.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) => {
11
- call: import("./methods/call").Call;
12
- batch: import("./methods/batch").Batch;
13
- list: import("./methods/list").List;
14
- };
15
- export default _default;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const got_1 = __importDefault(require("got"));
7
- const p_queue_1 = __importDefault(require("p-queue"));
8
- const addAccessToken_1 = __importDefault(require("./hooks/addAccessToken"));
9
- const batch_1 = __importDefault(require("./methods/batch"));
10
- const call_1 = __importDefault(require("./methods/call"));
11
- const list_1 = __importDefault(require("./methods/list"));
12
- const BITRIX_API_RATE_LIMIT = 2;
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) => {
23
- const client = got_1.default.extend({
24
- prefixUrl: restURI,
25
- headers: {
26
- 'user-agent': '@2bad/bitrix'
27
- },
28
- responseType: 'json',
29
- hooks: {
30
- beforeRequest: [
31
- (0, addAccessToken_1.default)(accessToken)
32
- ]
33
- },
34
- ...options !== null && options !== void 0 ? options : {}
35
- });
36
- const queue = new p_queue_1.default({
37
- intervalCap: BITRIX_API_RATE_LIMIT,
38
- interval: BITRIX_API_RATE_INTERVAL
39
- });
40
- const queuedGet = (...args) => queue.add(() => client.get(...args));
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 });
48
- return {
49
- call,
50
- batch,
51
- list
52
- };
53
- };
@@ -1,40 +0,0 @@
1
- import got from 'got';
2
- import { Commands } from '../../commands';
3
- import { Method, MethodPayloadType } from '../../methods';
4
- import { BatchPayload } from '../../payloads';
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
- */
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
- */
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
- */
20
- export declare const mergeBatchPayloads: <B extends BatchPayload<unknown>, P = B extends BatchPayload<infer U> ? U : never>(payloads: readonly B[]) => BatchPayload<P>;
21
- export declare type CommandsPayloads<C extends Commands, CM = {
22
- [K in keyof C]: C[K] extends {
23
- readonly method: infer M;
24
- } ? M : never;
25
- }> = {
26
- [K in keyof CM]: MethodPayloadType<CM[K] extends Method ? CM[K] : never>;
27
- };
28
- export declare type Batch = <C extends Commands, P = CommandsPayloads<C>>(commands: C, commandsPerRequest?: number) => Promise<BatchPayload<P>>;
29
- declare type Dependencies = {
30
- readonly get: typeof got.get;
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
- */
39
- declare const _default: ({ get }: Dependencies) => Batch;
40
- export default _default;
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.mergeBatchPayloads = exports.prepareCommandsQueries = exports.chunkCommands = exports.MAX_COMMANDS_PER_BATCH = void 0;
7
- const lodash_chunk_1 = __importDefault(require("lodash.chunk"));
8
- const lodash_frompairs_1 = __importDefault(require("lodash.frompairs"));
9
- const qs_1 = require("qs");
10
- const methods_1 = require("../../methods");
11
- const isArray_1 = __importDefault(require("../../utils/isArray"));
12
- const call_1 = require("./call");
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
- */
17
- const chunkCommands = (commands, size = exports.MAX_COMMANDS_PER_BATCH) => {
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.
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`
25
- ? c.map(([_key, command]) => command)
26
- : (0, lodash_frompairs_1.default)(c));
27
- };
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
- */
34
- const prepareCommandsQueries = (commands) => Object.entries(commands).reduce((calls, [name, { method, params }]) => {
35
- const stringifiedParams = params ? `?${(0, qs_1.stringify)(params)}` : '';
36
- return {
37
- ...calls,
38
- [`cmd[${name}]`]: `${method}${stringifiedParams}`
39
- };
40
- // eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter
41
- }, {});
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
- */
47
- const mergeBatchPayloads = (payloads) => {
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
50
- ? [...a, ...b]
51
- : ({ ...a, ...b });
52
- return payloads.reduce((merged, payload) => ({
53
- result: {
54
- result: merge(merged.result.result || [], payload.result.result),
55
- result_error: merge(merged.result.result_error || [], payload.result.result_error),
56
- result_next: merge(merged.result.result_next || [], payload.result.result_next),
57
- result_time: merge(merged.result.result_time || [], payload.result.result_time),
58
- result_total: merge(merged.result.result_total || [], payload.result.result_total)
59
- },
60
- time: { ...merged.time, ...payload.time }
61
- // eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter
62
- }), { result: {}, time: {} });
63
- };
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
- */
72
- exports.default = ({ get }) => {
73
- const batch = async (commands, commandsPerRequest = exports.MAX_COMMANDS_PER_BATCH) => {
74
- const call = (c) => get(methods_1.Method.BATCH, { searchParams: (0, exports.prepareCommandsQueries)(c) })
75
- .then(({ body }) => body);
76
- const calls = (0, exports.chunkCommands)(commands, commandsPerRequest)
77
- .map(call);
78
- return await Promise.all(calls)
79
- .then((chunkedPayloads) => {
80
- const payloads = (0, exports.mergeBatchPayloads)(chunkedPayloads);
81
- return (0, call_1.handlePayload)(payloads);
82
- });
83
- };
84
- return batch;
85
- };
@@ -1 +0,0 @@
1
- export {};