@2bad/bitrix 2.3.1 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -45
- package/build/main/bitrix.d.ts +25 -16
- package/build/main/bitrix.integration.test.js +0 -1
- package/build/main/bitrix.js +40 -13
- package/build/main/bitrix.unit.test.js +24 -9
- package/build/main/client/client.unit.test.js +13 -10
- package/build/main/client/hooks/addAccessToken.d.ts +5 -2
- package/build/main/client/hooks/addAccessToken.js +3 -1
- package/build/main/client/hooks/addAccessToken.unit.test.js +13 -12
- package/build/main/client/index.d.ts +10 -1
- package/build/main/client/index.js +23 -11
- package/build/main/client/methods/batch.d.ts +24 -5
- package/build/main/client/methods/batch.js +49 -17
- package/build/main/client/methods/batch.unit.test.js +103 -45
- package/build/main/client/methods/call.d.ts +11 -4
- package/build/main/client/methods/call.js +16 -6
- package/build/main/client/methods/call.unit.test.js +36 -21
- package/build/main/client/methods/list.d.ts +15 -3
- package/build/main/client/methods/list.js +36 -14
- package/build/main/client/methods/list.unit.test.js +42 -27
- package/build/main/commands.d.ts +2 -2
- package/build/main/commands.js +0 -1
- package/build/main/methods.d.ts +27 -8
- package/build/main/methods.js +1 -1
- package/build/main/payloads.d.ts +8 -8
- package/build/main/payloads.js +0 -1
- package/build/main/services/common.d.ts +5 -4
- package/build/main/services/common.js +0 -1
- package/build/main/services/companies/entities.d.ts +7 -6
- package/build/main/services/companies/entities.js +0 -1
- package/build/main/services/companies/index.d.ts +7 -6
- package/build/main/services/companies/index.integration.test.js +2 -3
- package/build/main/services/companies/index.js +0 -1
- package/build/main/services/companies/index.unit.test.js +1 -2
- package/build/main/services/companies/methods.d.ts +4 -4
- package/build/main/services/companies/methods.js +0 -1
- package/build/main/services/contacts/entities.d.ts +4 -3
- package/build/main/services/contacts/entities.js +0 -1
- package/build/main/services/contacts/index.d.ts +7 -6
- package/build/main/services/contacts/index.integration.test.js +2 -3
- package/build/main/services/contacts/index.js +0 -1
- package/build/main/services/contacts/index.unit.test.js +1 -2
- package/build/main/services/contacts/methods.d.ts +4 -4
- package/build/main/services/contacts/methods.js +0 -1
- package/build/main/services/currencies/entities.d.ts +2 -2
- package/build/main/services/currencies/entities.js +0 -1
- package/build/main/services/deals/entities.d.ts +2 -2
- package/build/main/services/deals/entities.js +0 -1
- package/build/main/services/deals/index.d.ts +7 -6
- package/build/main/services/deals/index.integration.test.js +2 -3
- package/build/main/services/deals/index.js +0 -1
- package/build/main/services/deals/index.unit.test.js +1 -2
- package/build/main/services/deals/methods.d.ts +4 -4
- package/build/main/services/deals/methods.js +0 -1
- package/build/main/services/leads/entities.d.ts +2 -2
- package/build/main/services/leads/entities.js +0 -1
- package/build/main/services/leads/index.d.ts +7 -6
- package/build/main/services/leads/index.integration.test.js +2 -3
- package/build/main/services/leads/index.js +0 -1
- package/build/main/services/leads/index.unit.test.js +1 -2
- package/build/main/services/leads/methods.d.ts +4 -4
- package/build/main/services/leads/methods.js +0 -1
- package/build/main/services/statuses/entities.d.ts +5 -4
- package/build/main/services/statuses/entities.js +0 -1
- package/build/main/services/statuses/index.d.ts +7 -11
- package/build/main/services/statuses/index.integration.test.js +8 -4
- package/build/main/services/statuses/index.js +0 -1
- package/build/main/services/statuses/index.unit.test.js +1 -2
- package/build/main/services/statuses/methods.d.ts +6 -6
- package/build/main/services/statuses/methods.js +0 -1
- package/build/main/services/users/entities.d.ts +4 -3
- package/build/main/services/users/entities.js +0 -1
- package/build/main/services/users/index.d.ts +3 -3
- package/build/main/services/users/index.integration.test.js +2 -3
- package/build/main/services/users/index.js +0 -1
- package/build/main/services/users/index.unit.test.js +1 -2
- package/build/main/services/users/methods.d.ts +4 -4
- package/build/main/services/users/methods.js +0 -1
- package/build/main/utils/Diff.js +0 -1
- package/build/main/utils/ExtractValue.d.ts +6 -1
- package/build/main/utils/ExtractValue.js +0 -1
- package/build/main/utils/isArray.d.ts +1 -1
- package/build/main/utils/isArray.js +1 -1
- package/build/module/bitrix.d.ts +25 -16
- package/build/module/bitrix.integration.test.js +0 -1
- package/build/module/bitrix.js +19 -3
- package/build/module/bitrix.unit.test.js +0 -1
- package/build/module/client/client.unit.test.js +9 -6
- package/build/module/client/hooks/addAccessToken.d.ts +5 -2
- package/build/module/client/hooks/addAccessToken.js +3 -1
- package/build/module/client/hooks/addAccessToken.unit.test.js +9 -8
- package/build/module/client/index.d.ts +10 -1
- package/build/module/client/index.js +19 -7
- package/build/module/client/methods/batch.d.ts +24 -5
- package/build/module/client/methods/batch.js +28 -3
- package/build/module/client/methods/batch.unit.test.js +61 -19
- package/build/module/client/methods/call.d.ts +11 -4
- package/build/module/client/methods/call.js +10 -3
- package/build/module/client/methods/call.unit.test.js +1 -2
- package/build/module/client/methods/list.d.ts +15 -3
- package/build/module/client/methods/list.js +21 -5
- package/build/module/client/methods/list.unit.test.js +0 -1
- package/build/module/commands.d.ts +2 -2
- package/build/module/commands.js +1 -1
- package/build/module/methods.d.ts +27 -8
- package/build/module/methods.js +0 -1
- package/build/module/payloads.d.ts +8 -8
- package/build/module/payloads.js +1 -1
- package/build/module/services/common.d.ts +5 -4
- package/build/module/services/common.js +1 -1
- package/build/module/services/companies/entities.d.ts +7 -6
- package/build/module/services/companies/entities.js +1 -1
- package/build/module/services/companies/index.d.ts +7 -6
- package/build/module/services/companies/index.integration.test.js +1 -2
- package/build/module/services/companies/index.js +0 -1
- package/build/module/services/companies/index.unit.test.js +0 -1
- package/build/module/services/companies/methods.d.ts +4 -4
- package/build/module/services/companies/methods.js +0 -1
- package/build/module/services/contacts/entities.d.ts +4 -3
- package/build/module/services/contacts/entities.js +1 -1
- package/build/module/services/contacts/index.d.ts +7 -6
- package/build/module/services/contacts/index.integration.test.js +1 -2
- package/build/module/services/contacts/index.js +0 -1
- package/build/module/services/contacts/index.unit.test.js +0 -1
- package/build/module/services/contacts/methods.d.ts +4 -4
- package/build/module/services/contacts/methods.js +0 -1
- package/build/module/services/currencies/entities.d.ts +2 -2
- package/build/module/services/currencies/entities.js +1 -1
- package/build/module/services/deals/entities.d.ts +2 -2
- package/build/module/services/deals/entities.js +1 -1
- package/build/module/services/deals/index.d.ts +7 -6
- package/build/module/services/deals/index.integration.test.js +1 -2
- package/build/module/services/deals/index.js +0 -1
- package/build/module/services/deals/index.unit.test.js +0 -1
- package/build/module/services/deals/methods.d.ts +4 -4
- package/build/module/services/deals/methods.js +0 -1
- package/build/module/services/leads/entities.d.ts +2 -2
- package/build/module/services/leads/entities.js +1 -1
- package/build/module/services/leads/index.d.ts +7 -6
- package/build/module/services/leads/index.integration.test.js +1 -2
- package/build/module/services/leads/index.js +0 -1
- package/build/module/services/leads/index.unit.test.js +0 -1
- package/build/module/services/leads/methods.d.ts +4 -4
- package/build/module/services/leads/methods.js +0 -1
- package/build/module/services/statuses/entities.d.ts +5 -4
- package/build/module/services/statuses/entities.js +1 -1
- package/build/module/services/statuses/index.d.ts +7 -11
- package/build/module/services/statuses/index.integration.test.js +7 -3
- package/build/module/services/statuses/index.js +0 -1
- package/build/module/services/statuses/index.unit.test.js +0 -1
- package/build/module/services/statuses/methods.d.ts +6 -6
- package/build/module/services/statuses/methods.js +0 -1
- package/build/module/services/users/entities.d.ts +4 -3
- package/build/module/services/users/entities.js +1 -1
- package/build/module/services/users/index.d.ts +3 -3
- package/build/module/services/users/index.integration.test.js +1 -2
- package/build/module/services/users/index.js +0 -1
- package/build/module/services/users/index.unit.test.js +0 -1
- package/build/module/services/users/methods.d.ts +4 -4
- package/build/module/services/users/methods.js +0 -1
- package/build/module/utils/Diff.js +1 -1
- package/build/module/utils/ExtractValue.d.ts +6 -1
- package/build/module/utils/ExtractValue.js +1 -1
- package/build/module/utils/isArray.d.ts +1 -1
- package/build/module/utils/isArray.js +1 -1
- package/package.json +64 -60
- package/build/main/bitrix.integration.test.js.map +0 -1
- package/build/main/bitrix.js.map +0 -1
- package/build/main/bitrix.unit.test.js.map +0 -1
- package/build/main/client/client.unit.test.js.map +0 -1
- package/build/main/client/hooks/addAccessToken.js.map +0 -1
- package/build/main/client/hooks/addAccessToken.unit.test.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/batch.unit.test.js.map +0 -1
- package/build/main/client/methods/call.js.map +0 -1
- package/build/main/client/methods/call.unit.test.js.map +0 -1
- package/build/main/client/methods/list.js.map +0 -1
- package/build/main/client/methods/list.unit.test.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.integration.test.js.map +0 -1
- package/build/main/services/companies/index.js.map +0 -1
- package/build/main/services/companies/index.unit.test.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.integration.test.js.map +0 -1
- package/build/main/services/contacts/index.js.map +0 -1
- package/build/main/services/contacts/index.unit.test.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.integration.test.js.map +0 -1
- package/build/main/services/deals/index.js.map +0 -1
- package/build/main/services/deals/index.unit.test.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.integration.test.js.map +0 -1
- package/build/main/services/leads/index.js.map +0 -1
- package/build/main/services/leads/index.unit.test.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.integration.test.js.map +0 -1
- package/build/main/services/statuses/index.js.map +0 -1
- package/build/main/services/statuses/index.unit.test.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.integration.test.js.map +0 -1
- package/build/main/services/users/index.js.map +0 -1
- package/build/main/services/users/index.unit.test.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.integration.test.js.map +0 -1
- package/build/module/bitrix.js.map +0 -1
- package/build/module/bitrix.unit.test.js.map +0 -1
- package/build/module/client/client.unit.test.js.map +0 -1
- package/build/module/client/hooks/addAccessToken.js.map +0 -1
- package/build/module/client/hooks/addAccessToken.unit.test.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/batch.unit.test.js.map +0 -1
- package/build/module/client/methods/call.js.map +0 -1
- package/build/module/client/methods/call.unit.test.js.map +0 -1
- package/build/module/client/methods/list.js.map +0 -1
- package/build/module/client/methods/list.unit.test.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.integration.test.js.map +0 -1
- package/build/module/services/companies/index.js.map +0 -1
- package/build/module/services/companies/index.unit.test.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.integration.test.js.map +0 -1
- package/build/module/services/contacts/index.js.map +0 -1
- package/build/module/services/contacts/index.unit.test.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.integration.test.js.map +0 -1
- package/build/module/services/deals/index.js.map +0 -1
- package/build/module/services/deals/index.unit.test.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.integration.test.js.map +0 -1
- package/build/module/services/leads/index.js.map +0 -1
- package/build/module/services/leads/index.unit.test.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.integration.test.js.map +0 -1
- package/build/module/services/statuses/index.js.map +0 -1
- package/build/module/services/statuses/index.unit.test.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.integration.test.js.map +0 -1
- package/build/module/services/users/index.js.map +0 -1
- package/build/module/services/users/index.unit.test.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/README.md
CHANGED
|
@@ -1,24 +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
|
-
* 🚀 Handles records batching and rate limiting for you
|
|
15
|
-
* ❤️ Promise-based
|
|
12
|
+
- 🔥 No bullshit
|
|
13
|
+
- ✨ Expressive API
|
|
14
|
+
- 💪 Strongly typed methods and requests results with TypeScript
|
|
15
|
+
- 🚀 Handles records batching and rate limiting for you
|
|
16
|
+
- ❤️ Promise-based
|
|
16
17
|
|
|
17
18
|

|
|
18
19
|
|
|
19
20
|
### Install
|
|
20
21
|
|
|
21
|
-
```
|
|
22
|
+
```shell
|
|
22
23
|
npm install @2bad/bitrix
|
|
23
24
|
```
|
|
24
25
|
|
|
@@ -79,18 +80,18 @@ There are two ways to do that:
|
|
|
79
80
|
|
|
80
81
|
### API
|
|
81
82
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
- Generic
|
|
84
|
+
- [`call()`](docs/methods.md#call)
|
|
85
|
+
- [`list()`](docs/methods.md#list)
|
|
86
|
+
- [`batch()`](docs/methods.md#batch)
|
|
87
|
+
- CRM
|
|
88
|
+
- [Company](docs/services/companies.md)
|
|
89
|
+
- [Contact](docs/services/contacts.md)
|
|
90
|
+
- [Currency](docs/services/currencies.md)
|
|
91
|
+
- [Deal](docs/services/deals.md)
|
|
92
|
+
- [Lead](docs/services/leads.md)
|
|
93
|
+
- [Status](docs/services/statuses.md)
|
|
94
|
+
- [User](docs/services/users.md)
|
|
94
95
|
|
|
95
96
|
### How it works
|
|
96
97
|
|
|
@@ -98,16 +99,16 @@ The client tries hard to provide a consistent, strongly typed and at the same ti
|
|
|
98
99
|
|
|
99
100
|
It takes care of the any necessary batching to run "large" commands, like retrieving all deals or leads with least possible network request. That allows achieving a reading of the 250 000 and updating of 5000 entries per minute with a single line of code.
|
|
100
101
|
|
|
101
|
-
All client methods are automatically rate-limited and queued if needed to cope with Bitrix REST API limitation of 2 requests per second, so you should never see Bitrix
|
|
102
|
+
All client methods are automatically rate-limited and queued if needed to cope with Bitrix REST API limitation of 2 requests per second, so you should never see Bitrix errors about exceeding rate limits.
|
|
102
103
|
|
|
103
|
-
Methods required params and returned payload types are automatically resolved based on [Methods](
|
|
104
|
+
Methods required params and returned payload types are automatically resolved based on [Methods](source/types.ts) interface, which effectively describes all currently supported methods.
|
|
104
105
|
|
|
105
106
|
To facilitate better architecture, the client divided into layers:
|
|
106
107
|
|
|
107
108
|
1. **Methods** — a mostly generic [methods](docs/methods.md) like `call` to work with Bitrix API methods. They take care of the routine and provide a foundation for more complex operations.
|
|
108
|
-
2. **Client** — a generic [client](
|
|
109
|
-
3. **Services** — each [service](
|
|
110
|
-
4. **Bitrix client** — a top-level [provider](
|
|
109
|
+
2. **Client** — a generic [client](source/client/README.md), which takes care of some additional routine tasks like setting access token on every request, setting up a queue for the rate limiting, and providing generic methods.
|
|
110
|
+
3. **Services** — each [service](docs/services/README.md) provides an expressive interface to work with a specific group of Bitrix REST API operations. In essence, they do orchestrate generic client methods and parameters to get proper results.
|
|
111
|
+
4. **Bitrix client** — a top-level [provider](source/bitrix.ts) of generic method and services. An effortless way to deal with Bitrix REST API by using an intuitive API, which takes care of all underlying complexity.
|
|
111
112
|
|
|
112
113
|
### FAQ
|
|
113
114
|
|
|
@@ -117,7 +118,7 @@ The core is ready and stable. It can be used to arbitrary invoke any Bitrix REST
|
|
|
117
118
|
|
|
118
119
|
However, not all Bitrix REST API methods are exposed as convenient client services yet \(the ones like `bitrix.deals.list()`\).
|
|
119
120
|
|
|
120
|
-
If you need specific service, add one by making a Pull Request, following the structure of already existing [services](
|
|
121
|
+
If you need specific service, add one by making a Pull Request, following the structure of already existing [services](source/services/README.md) and ["Adding new methods"](./#adding-new-methods) instructions.
|
|
121
122
|
|
|
122
123
|
> I'm not a Typed Language Master Race user. Can I use it with a regular JavaScript?
|
|
123
124
|
|
|
@@ -170,6 +171,14 @@ bitrix.list('some.new.list' as any, { select: ["TITLE"] })
|
|
|
170
171
|
|
|
171
172
|
Use the `batch` method. It will handle all routine:
|
|
172
173
|
|
|
174
|
+
> I'm using a self-signed SSL certificate and I'm getting a `[RequestError]: self signed certificate`. What should I do?
|
|
175
|
+
|
|
176
|
+
Override [`got options`](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md) in constructor:
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
const bitrix = Bitrix('https://PORTAL_NAME.bitrix24.ru/rest', 'ACCESS_TOKEN', {https: { rejectUnauthorized: false }})
|
|
180
|
+
```
|
|
181
|
+
|
|
173
182
|
```typescript
|
|
174
183
|
bitrix.batch({
|
|
175
184
|
lead: { method: Method.GET_LEAD, params: { ID: '77' } },
|
|
@@ -179,26 +188,25 @@ bitrix.batch({
|
|
|
179
188
|
|
|
180
189
|
### Development
|
|
181
190
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
191
|
+
- `npm test` — run all tests and collect full coverage report
|
|
192
|
+
- `npm run test:unit` — run unit tests and collect coverage report
|
|
193
|
+
- `npm run test:integration` — run integration tests and collect coverage report
|
|
194
|
+
- `npm run test:watch` — watch for changes and run all tests
|
|
195
|
+
- `npm run test:unit:watch` — watch for changes and run unit tests
|
|
196
|
+
- `npm run test:integration:watch` — watch for changes and run integration tests
|
|
197
|
+
- `npm run build` — build the library for the release
|
|
189
198
|
|
|
190
199
|
#### Adding new methods
|
|
191
200
|
|
|
192
201
|
Proper method parameters and payload types handling requires some routine when adding any new method. Hopefully, we can do it better in future, but for now follow those steps:
|
|
193
202
|
|
|
194
|
-
1. Add new method into the [`Method`](
|
|
195
|
-
2. Add it into the [`LISTABLE_METHODS`](
|
|
196
|
-
3. Add or update related [service](
|
|
203
|
+
1. Add new method into the [`Method`](source/methods.ts) enum.
|
|
204
|
+
2. Add it into the [`LISTABLE_METHODS`](source/methods.ts) array if it is listable \(paginated\). Not everything that lists is listable, so check it.
|
|
205
|
+
3. Add or update related [service](source/services/README.md):
|
|
197
206
|
1. Put exposed by the service public methods into the `index.ts` file. Ensure that you're properly mapping service method arguments to `call` or `list` params.
|
|
198
207
|
2. Add related entities into the `entities.ts`.
|
|
199
208
|
3. Add interface describing service methods into the `methods.ts`. Test and check method payload type to be sure you've described it correctly!
|
|
200
|
-
4. Extend [`Methods`](
|
|
209
|
+
4. Extend [`Methods`](source/methods.ts) interface with the added service-specific interface. That way the client will know how to resolve parameters and payload types for the added method.
|
|
201
210
|
5. Add tests into the `index.unit.test.ts`.
|
|
202
|
-
4. Re-export service public types like Entities in the [bitrix.ts](
|
|
203
|
-
5. Document addition in the [docs](
|
|
204
|
-
|
|
211
|
+
4. Re-export service public types like Entities in the [bitrix.ts](source/bitrix.ts) to make them available to the end-users.
|
|
212
|
+
5. Document addition in the [docs](docs/README.md).
|
package/build/main/bitrix.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { ExtendOptions } from 'got';
|
|
2
|
+
/**
|
|
3
|
+
* Construct a Bitrix client with generic methods
|
|
4
|
+
* @param restURI REST endpoint, like a `https://hello.bitrix24.ua/rest` or an inbound webhook endpoint,
|
|
5
|
+
* like a `https://hello.bitrix24.ua/rest/1/WEBHOOK_TOKEN`.
|
|
6
|
+
* @param accessToken Bitrix application Access Token. Do not specify in case inbound webhook endpoint used.
|
|
7
|
+
* @param clientOptions an object that will overwrite underlying configuration for HTTP client,
|
|
8
|
+
* see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: (restURI: string, accessToken?: string, clientOptions?: ExtendOptions) => {
|
|
2
11
|
call: import("./client/methods/call").Call;
|
|
3
12
|
batch: import("./client/methods/batch").Batch;
|
|
4
13
|
list: import("./client/methods/list").List;
|
|
@@ -7,16 +16,16 @@ declare const _default: (restURI: string, accessToken?: string | undefined) => {
|
|
|
7
16
|
create: <D extends {
|
|
8
17
|
readonly fields: Partial<import("./services/companies/entities").Company>;
|
|
9
18
|
readonly params?: {
|
|
10
|
-
readonly REGISTER_SONET_EVENT:
|
|
19
|
+
readonly REGISTER_SONET_EVENT: "Y" | "N";
|
|
11
20
|
} | undefined;
|
|
12
21
|
}>(fields: D["fields"], params?: D["params"] | undefined) => Promise<import("./payloads").GetPayload<number>>;
|
|
13
22
|
get: (id: string) => Promise<import("./payloads").GetPayload<import("./services/companies/entities").Company>>;
|
|
14
23
|
list: (params?: import("./methods").ListParams) => Promise<import("./payloads").ListPayload<import("./services/companies/entities").Company>>;
|
|
15
24
|
update: <D_1 extends {
|
|
16
25
|
readonly id: string;
|
|
17
|
-
readonly fields: Record<string,
|
|
26
|
+
readonly fields: Record<string, unknown>;
|
|
18
27
|
readonly params?: {
|
|
19
|
-
readonly REGISTER_SONET_EVENT:
|
|
28
|
+
readonly REGISTER_SONET_EVENT: "Y" | "N";
|
|
20
29
|
} | undefined;
|
|
21
30
|
}>(id: string, fields: D_1["fields"], params?: D_1["params"] | undefined) => Promise<import("./payloads").GetPayload<boolean>>;
|
|
22
31
|
};
|
|
@@ -25,16 +34,16 @@ declare const _default: (restURI: string, accessToken?: string | undefined) => {
|
|
|
25
34
|
create: <D_2 extends {
|
|
26
35
|
readonly fields: Partial<import("./services/contacts/entities").Contact>;
|
|
27
36
|
readonly params?: {
|
|
28
|
-
readonly REGISTER_SONET_EVENT:
|
|
37
|
+
readonly REGISTER_SONET_EVENT: "Y" | "N";
|
|
29
38
|
} | undefined;
|
|
30
39
|
}>(fields: D_2["fields"], params?: D_2["params"] | undefined) => Promise<import("./payloads").GetPayload<number>>;
|
|
31
40
|
get: (id: string) => Promise<import("./payloads").GetPayload<import("./services/contacts/entities").Contact>>;
|
|
32
41
|
list: (params?: import("./methods").ListParams) => Promise<import("./payloads").ListPayload<import("./services/contacts/entities").Contact>>;
|
|
33
42
|
update: <D_3 extends {
|
|
34
43
|
readonly id: string;
|
|
35
|
-
readonly fields: Record<string,
|
|
44
|
+
readonly fields: Record<string, unknown>;
|
|
36
45
|
readonly params?: {
|
|
37
|
-
readonly REGISTER_SONET_EVENT:
|
|
46
|
+
readonly REGISTER_SONET_EVENT: "Y" | "N";
|
|
38
47
|
} | undefined;
|
|
39
48
|
}>(id: string, fields: D_3["fields"], params?: D_3["params"] | undefined) => Promise<import("./payloads").GetPayload<boolean>>;
|
|
40
49
|
};
|
|
@@ -43,16 +52,16 @@ declare const _default: (restURI: string, accessToken?: string | undefined) => {
|
|
|
43
52
|
create: <D_4 extends {
|
|
44
53
|
readonly fields: Partial<import("./services/deals/entities").Deal>;
|
|
45
54
|
readonly params?: {
|
|
46
|
-
readonly REGISTER_SONET_EVENT:
|
|
55
|
+
readonly REGISTER_SONET_EVENT: "Y" | "N";
|
|
47
56
|
} | undefined;
|
|
48
57
|
}>(fields: D_4["fields"], params?: D_4["params"] | undefined) => Promise<import("./payloads").GetPayload<number>>;
|
|
49
58
|
get: (id: string) => Promise<import("./payloads").GetPayload<import("./services/deals/entities").Deal>>;
|
|
50
59
|
list: (params?: import("./methods").ListParams) => Promise<import("./payloads").ListPayload<import("./services/deals/entities").Deal>>;
|
|
51
60
|
update: <D_5 extends {
|
|
52
61
|
readonly id: string;
|
|
53
|
-
readonly fields: Record<string,
|
|
62
|
+
readonly fields: Record<string, unknown>;
|
|
54
63
|
readonly params?: {
|
|
55
|
-
readonly REGISTER_SONET_EVENT:
|
|
64
|
+
readonly REGISTER_SONET_EVENT: "Y" | "N";
|
|
56
65
|
} | undefined;
|
|
57
66
|
}>(id: string, fields: D_5["fields"], params?: D_5["params"] | undefined) => Promise<import("./payloads").GetPayload<boolean>>;
|
|
58
67
|
};
|
|
@@ -61,16 +70,16 @@ declare const _default: (restURI: string, accessToken?: string | undefined) => {
|
|
|
61
70
|
create: <D_6 extends {
|
|
62
71
|
readonly fields: Partial<import("./services/leads/entities").Lead>;
|
|
63
72
|
readonly params?: {
|
|
64
|
-
readonly REGISTER_SONET_EVENT:
|
|
73
|
+
readonly REGISTER_SONET_EVENT: "Y" | "N";
|
|
65
74
|
} | undefined;
|
|
66
75
|
}>(fields: D_6["fields"], params?: D_6["params"] | undefined) => Promise<import("./payloads").GetPayload<number>>;
|
|
67
76
|
get: (id: string) => Promise<import("./payloads").GetPayload<import("./services/leads/entities").Lead>>;
|
|
68
77
|
list: (params?: import("./methods").ListParams) => Promise<import("./payloads").ListPayload<import("./services/leads/entities").Lead>>;
|
|
69
78
|
update: <D_7 extends {
|
|
70
79
|
readonly id: string;
|
|
71
|
-
readonly fields: Record<string,
|
|
80
|
+
readonly fields: Record<string, unknown>;
|
|
72
81
|
readonly params?: {
|
|
73
|
-
readonly REGISTER_SONET_EVENT:
|
|
82
|
+
readonly REGISTER_SONET_EVENT: "Y" | "N";
|
|
74
83
|
} | undefined;
|
|
75
84
|
}>(id: string, fields: D_7["fields"], params?: D_7["params"] | undefined) => Promise<import("./payloads").GetPayload<boolean>>;
|
|
76
85
|
};
|
|
@@ -82,10 +91,10 @@ declare const _default: (restURI: string, accessToken?: string | undefined) => {
|
|
|
82
91
|
} | undefined) => Promise<import("./payloads").GetPayload<boolean>>;
|
|
83
92
|
get: (id: string | number) => Promise<import("./payloads").GetPayload<import("./services/statuses/entities").Status>>;
|
|
84
93
|
list: (params?: {
|
|
85
|
-
readonly order?: Record<string,
|
|
86
|
-
readonly filter?: Record<string,
|
|
94
|
+
readonly order?: Record<string, unknown> | undefined;
|
|
95
|
+
readonly filter?: Record<string, unknown> | undefined;
|
|
87
96
|
}) => Promise<import("./payloads").ListPayload<import("./services/statuses/entities").Status>>;
|
|
88
|
-
update: (id: string | number, fields: Record<string,
|
|
97
|
+
update: (id: string | number, fields: Record<string, unknown>) => Promise<import("./payloads").GetPayload<boolean>>;
|
|
89
98
|
};
|
|
90
99
|
users: {
|
|
91
100
|
fields: () => Promise<import("./payloads").GetPayload<import("./services/users/entities").User>>;
|
package/build/main/bitrix.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
5
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
18
|
};
|
|
@@ -13,19 +24,35 @@ const deals_1 = __importDefault(require("./services/deals"));
|
|
|
13
24
|
const leads_1 = __importDefault(require("./services/leads"));
|
|
14
25
|
const statuses_1 = __importDefault(require("./services/statuses"));
|
|
15
26
|
const users_1 = __importDefault(require("./services/users"));
|
|
16
|
-
|
|
17
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Construct a Bitrix client with generic methods
|
|
29
|
+
* @param restURI REST endpoint, like a `https://hello.bitrix24.ua/rest` or an inbound webhook endpoint,
|
|
30
|
+
* like a `https://hello.bitrix24.ua/rest/1/WEBHOOK_TOKEN`.
|
|
31
|
+
* @param accessToken Bitrix application Access Token. Do not specify in case inbound webhook endpoint used.
|
|
32
|
+
* @param clientOptions an object that will overwrite underlying configuration for HTTP client,
|
|
33
|
+
* see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
|
|
34
|
+
*/
|
|
35
|
+
exports.default = (restURI, accessToken, clientOptions) => {
|
|
36
|
+
const { call, batch, list } = (0, client_1.default)(restURI, accessToken, clientOptions);
|
|
18
37
|
return {
|
|
19
38
|
call,
|
|
20
39
|
batch,
|
|
21
40
|
list,
|
|
22
|
-
companies: companies_1.default({ call, list }),
|
|
23
|
-
contacts: contacts_1.default({ call, list }),
|
|
24
|
-
deals: deals_1.default({ call, list }),
|
|
25
|
-
leads: leads_1.default({ call, list }),
|
|
26
|
-
statuses: statuses_1.default({ call }),
|
|
27
|
-
users: users_1.default({ call })
|
|
41
|
+
companies: (0, companies_1.default)({ call, list }),
|
|
42
|
+
contacts: (0, contacts_1.default)({ call, list }),
|
|
43
|
+
deals: (0, deals_1.default)({ call, list }),
|
|
44
|
+
leads: (0, leads_1.default)({ call, list }),
|
|
45
|
+
statuses: (0, statuses_1.default)({ call }),
|
|
46
|
+
users: (0, users_1.default)({ call })
|
|
28
47
|
};
|
|
29
48
|
};
|
|
30
|
-
|
|
31
|
-
|
|
49
|
+
__exportStar(require("./methods"), exports);
|
|
50
|
+
__exportStar(require("./commands"), exports);
|
|
51
|
+
__exportStar(require("./services/common"), exports);
|
|
52
|
+
__exportStar(require("./services/companies/entities"), exports);
|
|
53
|
+
__exportStar(require("./services/contacts/entities"), exports);
|
|
54
|
+
__exportStar(require("./services/currencies/entities"), exports);
|
|
55
|
+
__exportStar(require("./services/deals/entities"), exports);
|
|
56
|
+
__exportStar(require("./services/leads/entities"), exports);
|
|
57
|
+
__exportStar(require("./services/statuses/entities"), exports);
|
|
58
|
+
__exportStar(require("./services/users/entities"), exports);
|
|
@@ -1,29 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
5
18
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
6
19
|
if (mod && mod.__esModule) return mod;
|
|
7
20
|
var result = {};
|
|
8
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result
|
|
9
|
-
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);
|
|
10
23
|
return result;
|
|
11
24
|
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
12
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
29
|
const bitrix_1 = __importDefault(require("./bitrix"));
|
|
14
30
|
const client = __importStar(require("./client"));
|
|
15
31
|
describe('Bitrix', () => {
|
|
16
32
|
it('should init', () => {
|
|
17
|
-
expect(() => bitrix_1.default('https://test.com', 'test_token')).not.toThrow();
|
|
33
|
+
expect(() => (0, bitrix_1.default)('https://test.com', 'test_token')).not.toThrow();
|
|
18
34
|
});
|
|
19
35
|
it('should pass endpoint and access token to the client', () => {
|
|
20
36
|
const SpiedClient = jest.spyOn(client, 'default');
|
|
21
|
-
bitrix_1.default('https://test.com', 'test_token');
|
|
37
|
+
(0, bitrix_1.default)('https://test.com', 'test_token');
|
|
22
38
|
expect(SpiedClient.mock.calls).toMatchSnapshot();
|
|
23
39
|
});
|
|
24
40
|
it('should expose API methods', () => {
|
|
25
|
-
const bitrix = bitrix_1.default('https://test.com', 'test_token');
|
|
41
|
+
const bitrix = (0, bitrix_1.default)('https://test.com', 'test_token');
|
|
26
42
|
expect(bitrix).toMatchSnapshot();
|
|
27
43
|
});
|
|
28
44
|
});
|
|
29
|
-
//# sourceMappingURL=bitrix.unit.test.js.map
|
|
@@ -12,30 +12,30 @@ const TEST_URI = 'https://test.com/rest';
|
|
|
12
12
|
const TEST_ACCESS_TOKEN = 'test_access_token';
|
|
13
13
|
const RESPONSE_200 = 200;
|
|
14
14
|
const spiedQueueAdd = jest.spyOn(p_queue_1.default.prototype, 'add');
|
|
15
|
-
const client = index_1.default(TEST_URI, TEST_ACCESS_TOKEN);
|
|
15
|
+
const client = (0, index_1.default)(TEST_URI, TEST_ACCESS_TOKEN);
|
|
16
16
|
describe('Client', () => {
|
|
17
17
|
beforeEach(() => {
|
|
18
18
|
spiedQueueAdd.mockClear();
|
|
19
19
|
});
|
|
20
20
|
it('should init', () => {
|
|
21
|
-
expect(() => index_1.default(TEST_URI, TEST_ACCESS_TOKEN)).not.toThrow();
|
|
21
|
+
expect(() => (0, index_1.default)(TEST_URI, TEST_ACCESS_TOKEN)).not.toThrow();
|
|
22
22
|
});
|
|
23
23
|
it('should extend `Got` instance with a specified parameters', () => {
|
|
24
24
|
const spiedGotExtend = jest.spyOn(got_1.default, 'extend');
|
|
25
|
-
index_1.default('https://test.com', 'test_token');
|
|
25
|
+
(0, index_1.default)('https://test.com', 'test_token', { https: { rejectUnauthorized: false } });
|
|
26
26
|
expect(spiedGotExtend.mock.calls).toMatchSnapshot();
|
|
27
27
|
});
|
|
28
28
|
it('should expose API methods', () => {
|
|
29
29
|
expect(client).toMatchSnapshot();
|
|
30
30
|
});
|
|
31
31
|
describe('`call`', () => {
|
|
32
|
-
|
|
32
|
+
// @todo restore test when issue is resolved (https://github.com/nock/nock/issues/1832)
|
|
33
|
+
it.skip('should add to queue', async () => {
|
|
33
34
|
const payload = {};
|
|
34
35
|
const method = methods_1.Method.CRM_DEAL_LIST;
|
|
35
|
-
nock_1.default(TEST_URI)
|
|
36
|
-
.get(`/${method}?access_token=${TEST_ACCESS_TOKEN}`)
|
|
37
|
-
.reply(RESPONSE_200, payload)
|
|
36
|
+
(0, nock_1.default)(TEST_URI)
|
|
38
37
|
.get(`/${method}?access_token=${TEST_ACCESS_TOKEN}`)
|
|
38
|
+
.twice()
|
|
39
39
|
.reply(RESPONSE_200, payload);
|
|
40
40
|
await client.call(method, {});
|
|
41
41
|
await client.call(method, {});
|
|
@@ -43,7 +43,8 @@ describe('Client', () => {
|
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
describe('`batch`', () => {
|
|
46
|
-
|
|
46
|
+
// @todo restore test when issue is resolved (https://github.com/nock/nock/issues/1832)
|
|
47
|
+
it.skip('should add to queue', async () => {
|
|
47
48
|
const payload = {
|
|
48
49
|
result: {
|
|
49
50
|
result: ['done'],
|
|
@@ -54,7 +55,10 @@ describe('Client', () => {
|
|
|
54
55
|
{ method: methods_1.Method.CRM_DEAL_GET },
|
|
55
56
|
{ method: methods_1.Method.CRM_DEAL_LIST }
|
|
56
57
|
];
|
|
57
|
-
nock_1.default(TEST_URI)
|
|
58
|
+
(0, nock_1.default)(TEST_URI)
|
|
59
|
+
// @todo We'd want to use `query` object here as it is much more readable, but nock for some reason
|
|
60
|
+
// fails to match request when it contains `cmd[someName]`. The issue definitely connected
|
|
61
|
+
// to the `[]`, since it does not appear when only one bracket present
|
|
58
62
|
.get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[0].method}&access_token=${TEST_ACCESS_TOKEN}`)
|
|
59
63
|
.reply(RESPONSE_200, payload)
|
|
60
64
|
.get(`/${methods_1.Method.BATCH}?cmd%5B0%5D=${commands[1].method}&access_token=${TEST_ACCESS_TOKEN}`)
|
|
@@ -64,4 +68,3 @@ describe('Client', () => {
|
|
|
64
68
|
});
|
|
65
69
|
});
|
|
66
70
|
});
|
|
67
|
-
//# sourceMappingURL=client.unit.test.js.map
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { BeforeRequestHook } from 'got';
|
|
2
|
+
/**
|
|
3
|
+
* Got can't merge `query` option with other queries if they are string. But that hook can.
|
|
4
|
+
*/
|
|
5
|
+
declare const _default: (accessToken?: string) => BeforeRequestHook;
|
|
3
6
|
export default _default;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Got can't merge `query` option with other queries if they are string. But that hook can.
|
|
5
|
+
*/
|
|
3
6
|
exports.default = (accessToken) => (options) => {
|
|
4
7
|
if (!accessToken)
|
|
5
8
|
return;
|
|
@@ -8,4 +11,3 @@ exports.default = (accessToken) => (options) => {
|
|
|
8
11
|
const hasQuery = options.path.includes('?');
|
|
9
12
|
options.path = `${options.path}${hasQuery ? '&' : '?'}access_token=${accessToken}`;
|
|
10
13
|
};
|
|
11
|
-
//# sourceMappingURL=addAccessToken.js.map
|
|
@@ -3,28 +3,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const got_1 = __importDefault(require("got"));
|
|
6
7
|
const addAccessToken_1 = __importDefault(require("./addAccessToken"));
|
|
7
8
|
const token = 'mock_token';
|
|
9
|
+
const merge = got_1.default.mergeOptions;
|
|
8
10
|
describe('Client `addAccessToken` hook', () => {
|
|
9
11
|
it('should add access token to URL without a query', () => {
|
|
10
|
-
const options = {
|
|
11
|
-
addAccessToken_1.default(token)(options);
|
|
12
|
-
expect(options.path).toBe(
|
|
12
|
+
const options = merge({ path: 'test', responseType: 'json' });
|
|
13
|
+
(0, addAccessToken_1.default)(token)(options);
|
|
14
|
+
expect(options.path).toBe(`test?access_token=${token}`);
|
|
13
15
|
});
|
|
14
16
|
it('should add access token to URL with a query', () => {
|
|
15
|
-
const options = {
|
|
16
|
-
addAccessToken_1.default(token)(options);
|
|
17
|
-
expect(options.path).toBe(
|
|
17
|
+
const options = merge({ path: 'test?value=1', responseType: 'json' });
|
|
18
|
+
(0, addAccessToken_1.default)(token)(options);
|
|
19
|
+
expect(options.path).toBe(`test?value=1&access_token=${token}`);
|
|
18
20
|
});
|
|
19
21
|
it('should not add access token when it is undefined', () => {
|
|
20
|
-
const options = {
|
|
21
|
-
addAccessToken_1.default()(options);
|
|
22
|
-
expect(options.path).toBe('
|
|
22
|
+
const options = merge({ path: 'test', responseType: 'json' });
|
|
23
|
+
(0, addAccessToken_1.default)()(options);
|
|
24
|
+
expect(options.path).toBe('test');
|
|
23
25
|
});
|
|
24
26
|
it('should not add access token when URL is undefined', () => {
|
|
25
|
-
const options = {
|
|
26
|
-
addAccessToken_1.default(token)(options);
|
|
27
|
+
const options = merge({ path: undefined, responseType: 'json' });
|
|
28
|
+
(0, addAccessToken_1.default)(token)(options);
|
|
27
29
|
expect(options.path).toBe(undefined);
|
|
28
30
|
});
|
|
29
31
|
});
|
|
30
|
-
//# sourceMappingURL=addAccessToken.unit.test.js.map
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { ExtendOptions } from 'got';
|
|
2
|
+
/**
|
|
3
|
+
* Construct a Bitrix client with generic methods
|
|
4
|
+
* @param restURI REST endpoint, like a `https://hello.bitrix24.ru/rest` or an inbound webhook endpoint,
|
|
5
|
+
* like a `https://hello.bitrix24.ru/rest/1/WEBHOOK_TOKEN`.
|
|
6
|
+
* @param accessToken Bitrix application Access Token. Do not specify in case inbound webhook endpoint used.
|
|
7
|
+
* @param options an object that will overwrite underlying configuration for HTTP client,
|
|
8
|
+
* see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: (restURI: string, accessToken?: string, options?: ExtendOptions) => {
|
|
2
11
|
call: import("./methods/call").Call;
|
|
3
12
|
batch: import("./methods/batch").Batch;
|
|
4
13
|
list: import("./methods/list").List;
|
|
@@ -10,32 +10,44 @@ const batch_1 = __importDefault(require("./methods/batch"));
|
|
|
10
10
|
const call_1 = __importDefault(require("./methods/call"));
|
|
11
11
|
const list_1 = __importDefault(require("./methods/list"));
|
|
12
12
|
const BITRIX_API_RATE_LIMIT = 2;
|
|
13
|
-
const BITRIX_API_RATE_INTERVAL = 1000;
|
|
14
|
-
|
|
13
|
+
const BITRIX_API_RATE_INTERVAL = 1000; // 1 second
|
|
14
|
+
/**
|
|
15
|
+
* Construct a Bitrix client with generic methods
|
|
16
|
+
* @param restURI REST endpoint, like a `https://hello.bitrix24.ru/rest` or an inbound webhook endpoint,
|
|
17
|
+
* like a `https://hello.bitrix24.ru/rest/1/WEBHOOK_TOKEN`.
|
|
18
|
+
* @param accessToken Bitrix application Access Token. Do not specify in case inbound webhook endpoint used.
|
|
19
|
+
* @param options an object that will overwrite underlying configuration for HTTP client,
|
|
20
|
+
* see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
|
|
21
|
+
*/
|
|
22
|
+
exports.default = (restURI, accessToken, options) => {
|
|
15
23
|
const client = got_1.default.extend({
|
|
16
|
-
|
|
24
|
+
prefixUrl: restURI,
|
|
17
25
|
headers: {
|
|
18
|
-
'user-agent':
|
|
26
|
+
'user-agent': '@2bad/bitrix'
|
|
19
27
|
},
|
|
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
|
+
},
|
|
34
|
+
...options !== null && options !== void 0 ? options : {}
|
|
26
35
|
});
|
|
27
36
|
const queue = new p_queue_1.default({
|
|
28
37
|
intervalCap: BITRIX_API_RATE_LIMIT,
|
|
29
38
|
interval: BITRIX_API_RATE_INTERVAL
|
|
30
39
|
});
|
|
31
40
|
const queuedGet = (...args) => queue.add(() => client.get(...args));
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
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 });
|
|
35
48
|
return {
|
|
36
49
|
call,
|
|
37
50
|
batch,
|
|
38
51
|
list
|
|
39
52
|
};
|
|
40
53
|
};
|
|
41
|
-
//# sourceMappingURL=index.js.map
|