@2bad/bitrix 2.4.0 → 2.5.1
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.
- package/LICENSE +0 -0
- package/README.md +54 -49
- package/build/main/bitrix.d.ts +10 -2
- package/build/main/bitrix.integration.test.d.ts +0 -0
- package/build/main/bitrix.integration.test.js +31 -0
- package/build/main/bitrix.js +24 -10
- package/build/main/bitrix.unit.test.d.ts +1 -0
- package/build/main/bitrix.unit.test.js +44 -0
- package/build/main/client/client.unit.test.d.ts +1 -0
- package/build/main/client/client.unit.test.js +70 -0
- package/build/main/client/hooks/addAccessToken.d.ts +4 -1
- package/build/main/client/hooks/addAccessToken.js +3 -1
- package/build/main/client/hooks/addAccessToken.unit.test.d.ts +1 -0
- package/build/main/client/hooks/addAccessToken.unit.test.js +31 -0
- package/build/main/client/index.d.ts +9 -1
- package/build/main/client/index.js +17 -6
- package/build/main/client/methods/batch.d.ts +19 -0
- package/build/main/client/methods/batch.js +35 -10
- package/build/main/client/methods/batch.unit.test.d.ts +1 -0
- package/build/main/client/methods/batch.unit.test.js +494 -0
- package/build/main/client/methods/call.d.ts +7 -0
- package/build/main/client/methods/call.js +11 -4
- package/build/main/client/methods/call.unit.test.d.ts +1 -0
- package/build/main/client/methods/call.unit.test.js +183 -0
- package/build/main/client/methods/list.d.ts +12 -0
- package/build/main/client/methods/list.js +23 -7
- package/build/main/client/methods/list.unit.test.d.ts +1 -0
- package/build/main/client/methods/list.unit.test.js +277 -0
- package/build/main/commands.js +0 -1
- package/build/main/methods.d.ts +19 -0
- package/build/main/methods.js +0 -1
- package/build/main/payloads.js +0 -1
- package/build/main/services/common.d.ts +1 -0
- package/build/main/services/common.js +0 -1
- package/build/main/services/companies/entities.js +0 -1
- package/build/main/services/companies/index.integration.test.d.ts +1 -0
- package/build/main/services/companies/index.integration.test.js +19 -0
- package/build/main/services/companies/index.js +0 -1
- package/build/main/services/companies/index.unit.test.d.ts +1 -0
- package/build/main/services/companies/index.unit.test.js +72 -0
- package/build/main/services/companies/methods.js +0 -1
- package/build/main/services/contacts/entities.d.ts +2 -2
- package/build/main/services/contacts/entities.js +0 -1
- package/build/main/services/contacts/index.integration.test.d.ts +1 -0
- package/build/main/services/contacts/index.integration.test.js +19 -0
- package/build/main/services/contacts/index.js +0 -1
- package/build/main/services/contacts/index.unit.test.d.ts +1 -0
- package/build/main/services/contacts/index.unit.test.js +72 -0
- package/build/main/services/contacts/methods.js +0 -1
- package/build/main/services/currencies/entities.js +0 -1
- package/build/main/services/deals/entities.js +0 -1
- package/build/main/services/deals/index.integration.test.d.ts +1 -0
- package/build/main/services/deals/index.integration.test.js +19 -0
- package/build/main/services/deals/index.js +0 -1
- package/build/main/services/deals/index.unit.test.d.ts +1 -0
- package/build/main/services/deals/index.unit.test.js +72 -0
- package/build/main/services/deals/methods.js +0 -1
- package/build/main/services/leads/entities.js +0 -1
- package/build/main/services/leads/index.integration.test.d.ts +1 -0
- package/build/main/services/leads/index.integration.test.js +19 -0
- package/build/main/services/leads/index.js +0 -1
- package/build/main/services/leads/index.unit.test.d.ts +1 -0
- package/build/main/services/leads/index.unit.test.js +72 -0
- package/build/main/services/leads/methods.js +0 -1
- package/build/main/services/statuses/entities.js +0 -1
- package/build/main/services/statuses/index.integration.test.d.ts +1 -0
- package/build/main/services/statuses/index.integration.test.js +90 -0
- package/build/main/services/statuses/index.js +0 -1
- package/build/main/services/statuses/index.unit.test.d.ts +1 -0
- package/build/main/services/statuses/index.unit.test.js +60 -0
- package/build/main/services/statuses/methods.js +0 -1
- package/build/main/services/users/entities.js +0 -1
- package/build/main/services/users/index.d.ts +1 -1
- package/build/main/services/users/index.integration.test.d.ts +1 -0
- package/build/main/services/users/index.integration.test.js +33 -0
- package/build/main/services/users/index.js +0 -1
- package/build/main/services/users/index.unit.test.d.ts +1 -0
- package/build/main/services/users/index.unit.test.js +25 -0
- package/build/main/services/users/methods.js +0 -1
- package/build/main/utils/Diff.js +0 -1
- package/build/main/utils/ExtractValue.d.ts +5 -0
- package/build/main/utils/ExtractValue.js +0 -1
- package/build/main/utils/isArray.js +1 -1
- package/build/module/bitrix.d.ts +10 -2
- package/build/module/bitrix.integration.test.d.ts +0 -0
- package/build/module/bitrix.integration.test.js +31 -0
- package/build/module/bitrix.js +10 -2
- package/build/module/bitrix.unit.test.d.ts +1 -0
- package/build/module/bitrix.unit.test.js +16 -0
- package/build/module/client/client.unit.test.d.ts +1 -0
- package/build/module/client/client.unit.test.js +65 -0
- package/build/module/client/hooks/addAccessToken.d.ts +4 -1
- package/build/module/client/hooks/addAccessToken.js +3 -1
- package/build/module/client/hooks/addAccessToken.unit.test.d.ts +1 -0
- package/build/module/client/hooks/addAccessToken.unit.test.js +26 -0
- package/build/module/client/index.d.ts +9 -1
- package/build/module/client/index.js +14 -3
- package/build/module/client/methods/batch.d.ts +19 -0
- package/build/module/client/methods/batch.js +26 -1
- package/build/module/client/methods/batch.unit.test.d.ts +1 -0
- package/build/module/client/methods/batch.unit.test.js +466 -0
- package/build/module/client/methods/call.d.ts +7 -0
- package/build/module/client/methods/call.js +9 -3
- package/build/module/client/methods/call.unit.test.d.ts +1 -0
- package/build/module/client/methods/call.unit.test.js +155 -0
- package/build/module/client/methods/list.d.ts +12 -0
- package/build/module/client/methods/list.js +20 -6
- package/build/module/client/methods/list.unit.test.d.ts +1 -0
- package/build/module/client/methods/list.unit.test.js +252 -0
- package/build/module/commands.js +0 -1
- package/build/module/methods.d.ts +19 -0
- package/build/module/methods.js +0 -1
- package/build/module/payloads.js +0 -1
- package/build/module/services/common.d.ts +1 -0
- package/build/module/services/common.js +0 -1
- package/build/module/services/companies/entities.js +0 -1
- package/build/module/services/companies/index.integration.test.d.ts +1 -0
- package/build/module/services/companies/index.integration.test.js +14 -0
- package/build/module/services/companies/index.js +0 -1
- package/build/module/services/companies/index.unit.test.d.ts +1 -0
- package/build/module/services/companies/index.unit.test.js +67 -0
- package/build/module/services/companies/methods.js +0 -1
- package/build/module/services/contacts/entities.d.ts +2 -2
- package/build/module/services/contacts/entities.js +0 -1
- package/build/module/services/contacts/index.integration.test.d.ts +1 -0
- package/build/module/services/contacts/index.integration.test.js +14 -0
- package/build/module/services/contacts/index.js +0 -1
- package/build/module/services/contacts/index.unit.test.d.ts +1 -0
- package/build/module/services/contacts/index.unit.test.js +67 -0
- package/build/module/services/contacts/methods.js +0 -1
- package/build/module/services/currencies/entities.js +0 -1
- package/build/module/services/deals/entities.js +0 -1
- package/build/module/services/deals/index.integration.test.d.ts +1 -0
- package/build/module/services/deals/index.integration.test.js +14 -0
- package/build/module/services/deals/index.js +0 -1
- package/build/module/services/deals/index.unit.test.d.ts +1 -0
- package/build/module/services/deals/index.unit.test.js +67 -0
- package/build/module/services/deals/methods.js +0 -1
- package/build/module/services/leads/entities.js +0 -1
- package/build/module/services/leads/index.integration.test.d.ts +1 -0
- package/build/module/services/leads/index.integration.test.js +14 -0
- package/build/module/services/leads/index.js +0 -1
- package/build/module/services/leads/index.unit.test.d.ts +1 -0
- package/build/module/services/leads/index.unit.test.js +67 -0
- package/build/module/services/leads/methods.js +0 -1
- package/build/module/services/statuses/entities.js +0 -1
- package/build/module/services/statuses/index.integration.test.d.ts +1 -0
- package/build/module/services/statuses/index.integration.test.js +85 -0
- package/build/module/services/statuses/index.js +0 -1
- package/build/module/services/statuses/index.unit.test.d.ts +1 -0
- package/build/module/services/statuses/index.unit.test.js +55 -0
- package/build/module/services/statuses/methods.js +0 -1
- package/build/module/services/users/entities.js +0 -1
- package/build/module/services/users/index.d.ts +1 -1
- package/build/module/services/users/index.integration.test.d.ts +1 -0
- package/build/module/services/users/index.integration.test.js +28 -0
- package/build/module/services/users/index.js +0 -1
- package/build/module/services/users/index.unit.test.d.ts +1 -0
- package/build/module/services/users/index.unit.test.js +20 -0
- package/build/module/services/users/methods.js +0 -1
- package/build/module/utils/Diff.js +0 -1
- package/build/module/utils/ExtractValue.d.ts +5 -0
- package/build/module/utils/ExtractValue.js +0 -1
- package/build/module/utils/isArray.js +1 -1
- package/package.json +21 -22
- package/build/main/bitrix.js.map +0 -1
- package/build/main/client/hooks/addAccessToken.js.map +0 -1
- package/build/main/client/index.js.map +0 -1
- package/build/main/client/methods/batch.js.map +0 -1
- package/build/main/client/methods/call.js.map +0 -1
- package/build/main/client/methods/list.js.map +0 -1
- package/build/main/commands.js.map +0 -1
- package/build/main/methods.js.map +0 -1
- package/build/main/payloads.js.map +0 -1
- package/build/main/services/common.js.map +0 -1
- package/build/main/services/companies/entities.js.map +0 -1
- package/build/main/services/companies/index.js.map +0 -1
- package/build/main/services/companies/methods.js.map +0 -1
- package/build/main/services/contacts/entities.js.map +0 -1
- package/build/main/services/contacts/index.js.map +0 -1
- package/build/main/services/contacts/methods.js.map +0 -1
- package/build/main/services/currencies/entities.js.map +0 -1
- package/build/main/services/deals/entities.js.map +0 -1
- package/build/main/services/deals/index.js.map +0 -1
- package/build/main/services/deals/methods.js.map +0 -1
- package/build/main/services/leads/entities.js.map +0 -1
- package/build/main/services/leads/index.js.map +0 -1
- package/build/main/services/leads/methods.js.map +0 -1
- package/build/main/services/statuses/entities.js.map +0 -1
- package/build/main/services/statuses/index.js.map +0 -1
- package/build/main/services/statuses/methods.js.map +0 -1
- package/build/main/services/users/entities.js.map +0 -1
- package/build/main/services/users/index.js.map +0 -1
- package/build/main/services/users/methods.js.map +0 -1
- package/build/main/utils/Diff.js.map +0 -1
- package/build/main/utils/ExtractValue.js.map +0 -1
- package/build/main/utils/isArray.js.map +0 -1
- package/build/module/bitrix.js.map +0 -1
- package/build/module/client/hooks/addAccessToken.js.map +0 -1
- package/build/module/client/index.js.map +0 -1
- package/build/module/client/methods/batch.js.map +0 -1
- package/build/module/client/methods/call.js.map +0 -1
- package/build/module/client/methods/list.js.map +0 -1
- package/build/module/commands.js.map +0 -1
- package/build/module/methods.js.map +0 -1
- package/build/module/payloads.js.map +0 -1
- package/build/module/services/common.js.map +0 -1
- package/build/module/services/companies/entities.js.map +0 -1
- package/build/module/services/companies/index.js.map +0 -1
- package/build/module/services/companies/methods.js.map +0 -1
- package/build/module/services/contacts/entities.js.map +0 -1
- package/build/module/services/contacts/index.js.map +0 -1
- package/build/module/services/contacts/methods.js.map +0 -1
- package/build/module/services/currencies/entities.js.map +0 -1
- package/build/module/services/deals/entities.js.map +0 -1
- package/build/module/services/deals/index.js.map +0 -1
- package/build/module/services/deals/methods.js.map +0 -1
- package/build/module/services/leads/entities.js.map +0 -1
- package/build/module/services/leads/index.js.map +0 -1
- package/build/module/services/leads/methods.js.map +0 -1
- package/build/module/services/statuses/entities.js.map +0 -1
- package/build/module/services/statuses/index.js.map +0 -1
- package/build/module/services/statuses/methods.js.map +0 -1
- package/build/module/services/users/entities.js.map +0 -1
- package/build/module/services/users/index.js.map +0 -1
- package/build/module/services/users/methods.js.map +0 -1
- package/build/module/utils/Diff.js.map +0 -1
- package/build/module/utils/ExtractValue.js.map +0 -1
- package/build/module/utils/isArray.js.map +0 -1
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -1,30 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
description: that doesn't suck
|
|
3
|
-
---
|
|
1
|
+

|
|
4
2
|
|
|
5
|
-
# Bitrix24 REST API client
|
|
3
|
+
# Bitrix24 REST API client that doesn't suck
|
|
6
4
|
|
|
7
|
-
](https://www.npmjs.com/package/@2bad/bitrix)
|
|
6
|
+
[](https://www.npmjs.com/package/@2bad/bitrix)
|
|
7
|
+
[](https://codecov.io/gh/2BAD/bitrix)
|
|
8
|
+
[](https://travis-ci.org/github/2BAD/bitrix)
|
|
9
|
+
[](https://github.com/2BAD/bitrix/actions?query=workflow%3A%22Integration+testing%22)
|
|
10
|
+
[](https://github.com/2BAD/bitrix/search?l=typescript)
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
[](https://david-dm.org/2BAD/bitrix)
|
|
15
|
-
[](https://github.com/2BAD/bitrix/search?l=typescript)
|
|
16
|
-
|
|
17
|
-
* 🔥 No bullshit
|
|
18
|
-
* ✨ Expressive API
|
|
19
|
-
* 💪 Strongly typed methods and requests results with TypeScript
|
|
20
|
-
* 🚀 Handles records batching and rate limiting for you
|
|
21
|
-
* ❤️ Promise-based
|
|
12
|
+
- 🔥 No bullshit
|
|
13
|
+
- ✨ Expressive API
|
|
14
|
+
- 💪 Strongly typed methods and requests results with TypeScript
|
|
15
|
+
- 🚀 Handles records batching and rate limiting for you
|
|
16
|
+
- ❤️ Promise-based
|
|
22
17
|
|
|
23
18
|

|
|
24
19
|
|
|
25
20
|
### Install
|
|
26
21
|
|
|
27
|
-
```
|
|
22
|
+
```shell
|
|
28
23
|
npm install @2bad/bitrix
|
|
29
24
|
```
|
|
30
25
|
|
|
@@ -34,6 +29,8 @@ Init client with Bitrix API endpoint and access token and use the client to ease
|
|
|
34
29
|
|
|
35
30
|
```typescript
|
|
36
31
|
import Bitrix from '@2bad/bitrix'
|
|
32
|
+
// or for ESM
|
|
33
|
+
import { Bitrix } from '@2bad/bitrix'
|
|
37
34
|
|
|
38
35
|
const bitrix = Bitrix('https://PORTAL_NAME.bitrix24.ru/rest', 'ACCESS_TOKEN')
|
|
39
36
|
|
|
@@ -85,18 +82,18 @@ There are two ways to do that:
|
|
|
85
82
|
|
|
86
83
|
### API
|
|
87
84
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
85
|
+
- Generic
|
|
86
|
+
- [`call()`](docs/methods.md#call)
|
|
87
|
+
- [`list()`](docs/methods.md#list)
|
|
88
|
+
- [`batch()`](docs/methods.md#batch)
|
|
89
|
+
- CRM
|
|
90
|
+
- [Company](docs/services/companies.md)
|
|
91
|
+
- [Contact](docs/services/contacts.md)
|
|
92
|
+
- [Currency](docs/services/currencies.md)
|
|
93
|
+
- [Deal](docs/services/deals.md)
|
|
94
|
+
- [Lead](docs/services/leads.md)
|
|
95
|
+
- [Status](docs/services/statuses.md)
|
|
96
|
+
- [User](docs/services/users.md)
|
|
100
97
|
|
|
101
98
|
### How it works
|
|
102
99
|
|
|
@@ -106,14 +103,14 @@ It takes care of the any necessary batching to run "large" commands, like retrie
|
|
|
106
103
|
|
|
107
104
|
All client methods are automatically rate-limited and queued if needed to cope with Bitrix REST API limitation of 2 requests per second, so you should never see Bitrix errors about exceeding rate limits.
|
|
108
105
|
|
|
109
|
-
Methods required params and returned payload types are automatically resolved based on [Methods](
|
|
106
|
+
Methods required params and returned payload types are automatically resolved based on [Methods](source/types.ts) interface, which effectively describes all currently supported methods.
|
|
110
107
|
|
|
111
108
|
To facilitate better architecture, the client divided into layers:
|
|
112
109
|
|
|
113
110
|
1. **Methods** — a mostly generic [methods](docs/methods.md) like `call` to work with Bitrix API methods. They take care of the routine and provide a foundation for more complex operations.
|
|
114
|
-
2. **Client** — a generic [client](
|
|
115
|
-
3. **Services** — each [service](
|
|
116
|
-
4. **Bitrix client** — a top-level [provider](
|
|
111
|
+
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.
|
|
112
|
+
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.
|
|
113
|
+
4. **Bitrix client** — a top-level [provider](source/bitrix.ts) of generic method and services. An effortless way to deal with Bitrix REST API by using an intuitive API, which takes care of all underlying complexity.
|
|
117
114
|
|
|
118
115
|
### FAQ
|
|
119
116
|
|
|
@@ -123,7 +120,7 @@ The core is ready and stable. It can be used to arbitrary invoke any Bitrix REST
|
|
|
123
120
|
|
|
124
121
|
However, not all Bitrix REST API methods are exposed as convenient client services yet \(the ones like `bitrix.deals.list()`\).
|
|
125
122
|
|
|
126
|
-
If you need specific service, add one by making a Pull Request, following the structure of already existing [services](
|
|
123
|
+
If you need specific service, add one by making a Pull Request, following the structure of already existing [services](source/services/README.md) and ["Adding new methods"](./#adding-new-methods) instructions.
|
|
127
124
|
|
|
128
125
|
> I'm not a Typed Language Master Race user. Can I use it with a regular JavaScript?
|
|
129
126
|
|
|
@@ -183,27 +180,35 @@ bitrix.batch({
|
|
|
183
180
|
})
|
|
184
181
|
```
|
|
185
182
|
|
|
183
|
+
> I'm using a self-signed SSL certificate and I'm getting a `[RequestError]: self signed certificate`. What should I do?
|
|
184
|
+
|
|
185
|
+
Override [`got options`](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md) in constructor:
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
const bitrix = Bitrix('https://PORTAL_NAME.bitrix24.ru/rest', 'ACCESS_TOKEN', {https: { rejectUnauthorized: false }})
|
|
189
|
+
```
|
|
190
|
+
|
|
186
191
|
### Development
|
|
187
192
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
- `npm test` — run all tests and collect full coverage report
|
|
194
|
+
- `npm run test:unit` — run unit tests and collect coverage report
|
|
195
|
+
- `npm run test:integration` — run integration tests and collect coverage report
|
|
196
|
+
- `npm run test:watch` — watch for changes and run all tests
|
|
197
|
+
- `npm run test:unit:watch` — watch for changes and run unit tests
|
|
198
|
+
- `npm run test:integration:watch` — watch for changes and run integration tests
|
|
199
|
+
- `npm run build` — build the library for the release
|
|
195
200
|
|
|
196
201
|
#### Adding new methods
|
|
197
202
|
|
|
198
203
|
Proper method parameters and payload types handling requires some routine when adding any new method. Hopefully, we can do it better in future, but for now follow those steps:
|
|
199
204
|
|
|
200
|
-
1. Add new method into the [`Method`](
|
|
201
|
-
2. Add it into the [`LISTABLE_METHODS`](
|
|
202
|
-
3. Add or update related [service](
|
|
205
|
+
1. Add new method into the [`Method`](source/methods.ts) enum.
|
|
206
|
+
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.
|
|
207
|
+
3. Add or update related [service](source/services/README.md):
|
|
203
208
|
1. Put exposed by the service public methods into the `index.ts` file. Ensure that you're properly mapping service method arguments to `call` or `list` params.
|
|
204
209
|
2. Add related entities into the `entities.ts`.
|
|
205
210
|
3. Add interface describing service methods into the `methods.ts`. Test and check method payload type to be sure you've described it correctly!
|
|
206
|
-
4. Extend [`Methods`](
|
|
211
|
+
4. Extend [`Methods`](source/methods.ts) interface with the added service-specific interface. That way the client will know how to resolve parameters and payload types for the added method.
|
|
207
212
|
5. Add tests into the `index.unit.test.ts`.
|
|
208
|
-
4. Re-export service public types like Entities in the [bitrix.ts](
|
|
209
|
-
5. Document addition in the [docs](
|
|
213
|
+
4. Re-export service public types like Entities in the [bitrix.ts](source/bitrix.ts) to make them available to the end-users.
|
|
214
|
+
5. Document addition in the [docs](docs/README.md).
|
package/build/main/bitrix.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { ExtendOptions } from 'got';
|
|
2
|
-
|
|
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) => {
|
|
3
11
|
call: import("./client/methods/call").Call;
|
|
4
12
|
batch: import("./client/methods/batch").Batch;
|
|
5
13
|
list: import("./client/methods/list").List;
|
|
@@ -93,7 +101,7 @@ declare const _default: (restURI: string, accessToken?: string | undefined, clie
|
|
|
93
101
|
get: (id?: string | undefined) => Promise<import("./payloads").GetPayload<readonly import("./services/users/entities").User[]>>;
|
|
94
102
|
};
|
|
95
103
|
};
|
|
96
|
-
export default
|
|
104
|
+
export default Bitrix;
|
|
97
105
|
export * from './methods';
|
|
98
106
|
export * from './commands';
|
|
99
107
|
export * from './services/common';
|
|
File without changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
describe('Bitrix API', () => {
|
|
3
|
+
describe('`get` method', () => {
|
|
4
|
+
it.todo('should get result');
|
|
5
|
+
it.todo('should reject on error');
|
|
6
|
+
});
|
|
7
|
+
describe('`batch` method', () => {
|
|
8
|
+
it.todo('should execute the batch');
|
|
9
|
+
it.todo('should reject on errors');
|
|
10
|
+
});
|
|
11
|
+
describe('`deals`', () => {
|
|
12
|
+
describe('`get` method', () => {
|
|
13
|
+
it.todo('should get entry');
|
|
14
|
+
it.todo('should reject on error');
|
|
15
|
+
});
|
|
16
|
+
describe('`list` method', () => {
|
|
17
|
+
it.todo('should all entries');
|
|
18
|
+
it.todo('should reject on error');
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe('`leads`', () => {
|
|
22
|
+
describe('`get` method', () => {
|
|
23
|
+
it.todo('should get entry');
|
|
24
|
+
it.todo('should reject on error');
|
|
25
|
+
});
|
|
26
|
+
describe('`list` method', () => {
|
|
27
|
+
it.todo('should get all entries');
|
|
28
|
+
it.todo('should reject on error');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
package/build/main/bitrix.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -13,6 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
18
|
};
|
|
15
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.Bitrix = void 0;
|
|
16
21
|
const client_1 = __importDefault(require("./client"));
|
|
17
22
|
const companies_1 = __importDefault(require("./services/companies"));
|
|
18
23
|
const contacts_1 = __importDefault(require("./services/contacts"));
|
|
@@ -20,20 +25,30 @@ const deals_1 = __importDefault(require("./services/deals"));
|
|
|
20
25
|
const leads_1 = __importDefault(require("./services/leads"));
|
|
21
26
|
const statuses_1 = __importDefault(require("./services/statuses"));
|
|
22
27
|
const users_1 = __importDefault(require("./services/users"));
|
|
23
|
-
|
|
24
|
-
|
|
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);
|
|
25
38
|
return {
|
|
26
39
|
call,
|
|
27
40
|
batch,
|
|
28
41
|
list,
|
|
29
|
-
companies: companies_1.default({ call, list }),
|
|
30
|
-
contacts: contacts_1.default({ call, list }),
|
|
31
|
-
deals: deals_1.default({ call, list }),
|
|
32
|
-
leads: leads_1.default({ call, list }),
|
|
33
|
-
statuses: statuses_1.default({ call }),
|
|
34
|
-
users: users_1.default({ call })
|
|
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 })
|
|
35
48
|
};
|
|
36
49
|
};
|
|
50
|
+
exports.Bitrix = Bitrix;
|
|
51
|
+
exports.default = exports.Bitrix;
|
|
37
52
|
__exportStar(require("./methods"), exports);
|
|
38
53
|
__exportStar(require("./commands"), exports);
|
|
39
54
|
__exportStar(require("./services/common"), exports);
|
|
@@ -44,4 +59,3 @@ __exportStar(require("./services/deals/entities"), exports);
|
|
|
44
59
|
__exportStar(require("./services/leads/entities"), exports);
|
|
45
60
|
__exportStar(require("./services/statuses/entities"), exports);
|
|
46
61
|
__exportStar(require("./services/users/entities"), exports);
|
|
47
|
-
//# sourceMappingURL=bitrix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const bitrix_1 = __importDefault(require("./bitrix"));
|
|
30
|
+
const client = __importStar(require("./client"));
|
|
31
|
+
describe('Bitrix', () => {
|
|
32
|
+
it('should init', () => {
|
|
33
|
+
expect(() => (0, bitrix_1.default)('https://test.com', 'test_token')).not.toThrow();
|
|
34
|
+
});
|
|
35
|
+
it('should pass endpoint and access token to the client', () => {
|
|
36
|
+
const SpiedClient = jest.spyOn(client, 'default');
|
|
37
|
+
(0, bitrix_1.default)('https://test.com', 'test_token');
|
|
38
|
+
expect(SpiedClient.mock.calls).toMatchSnapshot();
|
|
39
|
+
});
|
|
40
|
+
it('should expose API methods', () => {
|
|
41
|
+
const bitrix = (0, bitrix_1.default)('https://test.com', 'test_token');
|
|
42
|
+
expect(bitrix).toMatchSnapshot();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const got_1 = __importDefault(require("got"));
|
|
7
|
+
const nock_1 = __importDefault(require("nock"));
|
|
8
|
+
const p_queue_1 = __importDefault(require("p-queue"));
|
|
9
|
+
const methods_1 = require("../methods");
|
|
10
|
+
const index_1 = __importDefault(require("./index"));
|
|
11
|
+
const TEST_URI = 'https://test.com/rest';
|
|
12
|
+
const TEST_ACCESS_TOKEN = 'test_access_token';
|
|
13
|
+
const RESPONSE_200 = 200;
|
|
14
|
+
const spiedQueueAdd = jest.spyOn(p_queue_1.default.prototype, 'add');
|
|
15
|
+
const client = (0, index_1.default)(TEST_URI, TEST_ACCESS_TOKEN);
|
|
16
|
+
describe('Client', () => {
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
spiedQueueAdd.mockClear();
|
|
19
|
+
});
|
|
20
|
+
it('should init', () => {
|
|
21
|
+
expect(() => (0, index_1.default)(TEST_URI, TEST_ACCESS_TOKEN)).not.toThrow();
|
|
22
|
+
});
|
|
23
|
+
it('should extend `Got` instance with a specified parameters', () => {
|
|
24
|
+
const spiedGotExtend = jest.spyOn(got_1.default, 'extend');
|
|
25
|
+
(0, index_1.default)('https://test.com', 'test_token', { https: { rejectUnauthorized: false } });
|
|
26
|
+
expect(spiedGotExtend.mock.calls).toMatchSnapshot();
|
|
27
|
+
});
|
|
28
|
+
it('should expose API methods', () => {
|
|
29
|
+
expect(client).toMatchSnapshot();
|
|
30
|
+
});
|
|
31
|
+
describe('`call`', () => {
|
|
32
|
+
// @todo restore test when issue is resolved (https://github.com/nock/nock/issues/1832)
|
|
33
|
+
it.skip('should add to queue', async () => {
|
|
34
|
+
const payload = {};
|
|
35
|
+
const method = methods_1.Method.CRM_DEAL_LIST;
|
|
36
|
+
(0, nock_1.default)(TEST_URI)
|
|
37
|
+
.get(`/${method}?access_token=${TEST_ACCESS_TOKEN}`)
|
|
38
|
+
.twice()
|
|
39
|
+
.reply(RESPONSE_200, payload);
|
|
40
|
+
await client.call(method, {});
|
|
41
|
+
await client.call(method, {});
|
|
42
|
+
expect(spiedQueueAdd.mock.calls).toMatchSnapshot();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe('`batch`', () => {
|
|
46
|
+
// @todo restore test when issue is resolved (https://github.com/nock/nock/issues/1832)
|
|
47
|
+
it.skip('should add to queue', async () => {
|
|
48
|
+
const payload = {
|
|
49
|
+
result: {
|
|
50
|
+
result: ['done'],
|
|
51
|
+
result_error: []
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const commands = [
|
|
55
|
+
{ method: methods_1.Method.CRM_DEAL_GET },
|
|
56
|
+
{ method: methods_1.Method.CRM_DEAL_LIST }
|
|
57
|
+
];
|
|
58
|
+
(0, nock_1.default)(TEST_URI)
|
|
59
|
+
// @todo We'd want to use `query` object here as it is much more readable, but nock for some reason
|
|
60
|
+
// fails to match request when it contains `cmd[someName]`. The issue definitely connected
|
|
61
|
+
// to the `[]`, since it does not appear when only one bracket present
|
|
62
|
+
.get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[0].method}&access_token=${TEST_ACCESS_TOKEN}`)
|
|
63
|
+
.reply(RESPONSE_200, payload)
|
|
64
|
+
.get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[1].method}&access_token=${TEST_ACCESS_TOKEN}`)
|
|
65
|
+
.reply(RESPONSE_200, payload);
|
|
66
|
+
await client.batch(commands, 1);
|
|
67
|
+
expect(spiedQueueAdd.mock.calls).toMatchSnapshot();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { BeforeRequestHook } from 'got';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Got can't merge `query` option with other queries if they are string. But that hook can.
|
|
4
|
+
*/
|
|
5
|
+
declare const _default: (accessToken?: string) => BeforeRequestHook;
|
|
3
6
|
export default _default;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Got can't merge `query` option with other queries if they are string. But that hook can.
|
|
5
|
+
*/
|
|
3
6
|
exports.default = (accessToken) => (options) => {
|
|
4
7
|
if (!accessToken)
|
|
5
8
|
return;
|
|
@@ -8,4 +11,3 @@ exports.default = (accessToken) => (options) => {
|
|
|
8
11
|
const hasQuery = options.path.includes('?');
|
|
9
12
|
options.path = `${options.path}${hasQuery ? '&' : '?'}access_token=${accessToken}`;
|
|
10
13
|
};
|
|
11
|
-
//# sourceMappingURL=addAccessToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const got_1 = __importDefault(require("got"));
|
|
7
|
+
const addAccessToken_1 = __importDefault(require("./addAccessToken"));
|
|
8
|
+
const token = 'mock_token';
|
|
9
|
+
const merge = got_1.default.mergeOptions;
|
|
10
|
+
describe('Client `addAccessToken` hook', () => {
|
|
11
|
+
it('should add access token to URL without a query', () => {
|
|
12
|
+
const options = merge({ path: 'test', responseType: 'json' });
|
|
13
|
+
(0, addAccessToken_1.default)(token)(options);
|
|
14
|
+
expect(options.path).toBe(`test?access_token=${token}`);
|
|
15
|
+
});
|
|
16
|
+
it('should add access token to URL with a query', () => {
|
|
17
|
+
const options = merge({ path: 'test?value=1', responseType: 'json' });
|
|
18
|
+
(0, addAccessToken_1.default)(token)(options);
|
|
19
|
+
expect(options.path).toBe(`test?value=1&access_token=${token}`);
|
|
20
|
+
});
|
|
21
|
+
it('should not add access token when it is undefined', () => {
|
|
22
|
+
const options = merge({ path: 'test', responseType: 'json' });
|
|
23
|
+
(0, addAccessToken_1.default)()(options);
|
|
24
|
+
expect(options.path).toBe('test');
|
|
25
|
+
});
|
|
26
|
+
it('should not add access token when URL is undefined', () => {
|
|
27
|
+
const options = merge({ path: undefined, responseType: 'json' });
|
|
28
|
+
(0, addAccessToken_1.default)(token)(options);
|
|
29
|
+
expect(options.path).toBe(undefined);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { ExtendOptions } from 'got';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Construct a Bitrix client with generic methods
|
|
4
|
+
* @param restURI REST endpoint, like a `https://hello.bitrix24.ru/rest` or an inbound webhook endpoint,
|
|
5
|
+
* like a `https://hello.bitrix24.ru/rest/1/WEBHOOK_TOKEN`.
|
|
6
|
+
* @param accessToken Bitrix application Access Token. Do not specify in case inbound webhook endpoint used.
|
|
7
|
+
* @param options an object that will overwrite underlying configuration for HTTP client,
|
|
8
|
+
* see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: (restURI: string, accessToken?: string, options?: ExtendOptions) => {
|
|
3
11
|
call: import("./methods/call").Call;
|
|
4
12
|
batch: import("./methods/batch").Batch;
|
|
5
13
|
list: import("./methods/list").List;
|
|
@@ -10,7 +10,15 @@ const batch_1 = __importDefault(require("./methods/batch"));
|
|
|
10
10
|
const call_1 = __importDefault(require("./methods/call"));
|
|
11
11
|
const list_1 = __importDefault(require("./methods/list"));
|
|
12
12
|
const BITRIX_API_RATE_LIMIT = 2;
|
|
13
|
-
const BITRIX_API_RATE_INTERVAL = 1000;
|
|
13
|
+
const BITRIX_API_RATE_INTERVAL = 1000; // 1 second
|
|
14
|
+
/**
|
|
15
|
+
* Construct a Bitrix client with generic methods
|
|
16
|
+
* @param restURI REST endpoint, like a `https://hello.bitrix24.ru/rest` or an inbound webhook endpoint,
|
|
17
|
+
* like a `https://hello.bitrix24.ru/rest/1/WEBHOOK_TOKEN`.
|
|
18
|
+
* @param accessToken Bitrix application Access Token. Do not specify in case inbound webhook endpoint used.
|
|
19
|
+
* @param options an object that will overwrite underlying configuration for HTTP client,
|
|
20
|
+
* see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
|
|
21
|
+
*/
|
|
14
22
|
exports.default = (restURI, accessToken, options) => {
|
|
15
23
|
const client = got_1.default.extend({
|
|
16
24
|
prefixUrl: restURI,
|
|
@@ -20,7 +28,7 @@ exports.default = (restURI, accessToken, options) => {
|
|
|
20
28
|
responseType: 'json',
|
|
21
29
|
hooks: {
|
|
22
30
|
beforeRequest: [
|
|
23
|
-
addAccessToken_1.default(accessToken)
|
|
31
|
+
(0, addAccessToken_1.default)(accessToken)
|
|
24
32
|
]
|
|
25
33
|
},
|
|
26
34
|
...options !== null && options !== void 0 ? options : {}
|
|
@@ -30,13 +38,16 @@ exports.default = (restURI, accessToken, options) => {
|
|
|
30
38
|
interval: BITRIX_API_RATE_INTERVAL
|
|
31
39
|
});
|
|
32
40
|
const queuedGet = (...args) => queue.add(() => client.get(...args));
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
42
|
+
// @ts-expect-error @todo remove after issue is resolved (https://github.com/sindresorhus/got/issues/954)
|
|
43
|
+
const call = (0, call_1.default)({ get: queuedGet });
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
45
|
+
// @ts-expect-error @todo remove after issue is resolved (https://github.com/sindresorhus/got/issues/954)
|
|
46
|
+
const batch = (0, batch_1.default)({ get: queuedGet });
|
|
47
|
+
const list = (0, list_1.default)({ call, batch });
|
|
36
48
|
return {
|
|
37
49
|
call,
|
|
38
50
|
batch,
|
|
39
51
|
list
|
|
40
52
|
};
|
|
41
53
|
};
|
|
42
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -3,8 +3,20 @@ import { Commands } from '../../commands';
|
|
|
3
3
|
import { Method, MethodPayloadType } from '../../methods';
|
|
4
4
|
import { BatchPayload } from '../../payloads';
|
|
5
5
|
export declare const MAX_COMMANDS_PER_BATCH = 50;
|
|
6
|
+
/**
|
|
7
|
+
* Split any number of commands into the chunks with max commands per batch in each chunk
|
|
8
|
+
*/
|
|
6
9
|
export declare const chunkCommands: <C extends Commands>(commands: C, size?: number) => readonly C[];
|
|
10
|
+
/**
|
|
11
|
+
* Prepares list of commands to be used in requests to the Bitrix
|
|
12
|
+
* @note We could avoid that function... if only Bitrix API would support posting of the batch commands as
|
|
13
|
+
* plain objects, like it does with other methods. Instead, it should be a dict or array of string queries
|
|
14
|
+
*/
|
|
7
15
|
export declare const prepareCommandsQueries: <C extends Commands, R = { [K in keyof C]: string; }>(commands: C) => R;
|
|
16
|
+
/**
|
|
17
|
+
* Merges list of batch responses into a single batch
|
|
18
|
+
* @todo Generics inference is complicated here and might be not super accurate
|
|
19
|
+
*/
|
|
8
20
|
export declare const mergeBatchPayloads: <B extends BatchPayload<unknown>, P = B extends BatchPayload<infer U> ? U : never>(payloads: readonly B[]) => BatchPayload<P>;
|
|
9
21
|
export declare type CommandsPayloads<C extends Commands, CM = {
|
|
10
22
|
[K in keyof C]: C[K] extends {
|
|
@@ -17,5 +29,12 @@ export declare type Batch = <C extends Commands, P = CommandsPayloads<C>>(comman
|
|
|
17
29
|
declare type Dependencies = {
|
|
18
30
|
readonly get: typeof got.get;
|
|
19
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Dispatches a batch request with specified commands. Will fill figure out payload type based on the Methods.
|
|
34
|
+
* Supports unlimited number of commands. If they do exceed max amount of commands per batch, will dispatch
|
|
35
|
+
* multiple request and merge result into single batch payload
|
|
36
|
+
* @todo For now due to issues with types it won't check `params` of command, so any Method can be used
|
|
37
|
+
* with any (even wrong) params
|
|
38
|
+
*/
|
|
20
39
|
declare const _default: ({ get }: Dependencies) => Batch;
|
|
21
40
|
export default _default;
|