@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.
- package/README.md +1 -2
- package/build/bitrix.d.ts +65 -0
- package/build/bitrix.js +55 -0
- package/build/client/hooks/addAccessToken.js +9 -0
- package/build/{module/client → client}/index.d.ts +3 -3
- package/build/{module/client → client}/index.js +21 -16
- package/build/{module/client → client}/methods/batch.d.ts +6 -6
- package/build/client/methods/batch.js +75 -0
- package/build/{module/client → client}/methods/call.d.ts +4 -4
- package/build/{module/client → client}/methods/call.js +8 -9
- package/build/{module/client → client}/methods/list.d.ts +10 -10
- package/build/client/methods/list.js +58 -0
- package/build/{module/commands.d.ts → commands.d.ts} +3 -3
- package/build/commands.js +1 -0
- package/build/{module/methods.d.ts → methods.d.ts} +19 -19
- package/build/{module/methods.js → methods.js} +5 -5
- package/build/{main/payloads.d.ts → payloads.d.ts} +5 -5
- package/build/payloads.js +1 -0
- package/build/{main/services → services}/common.d.ts +7 -7
- package/build/services/common.js +2 -0
- package/build/{main/services → services}/companies/entities.d.ts +2 -2
- package/build/services/companies/entities.js +1 -0
- package/build/services/companies/index.d.ts +15 -0
- package/build/services/companies/index.js +17 -0
- package/build/{module/services → services}/companies/methods.d.ts +5 -5
- package/build/services/companies/methods.js +1 -0
- package/build/{module/services → services}/contacts/entities.d.ts +2 -2
- package/build/services/contacts/entities.js +1 -0
- package/build/services/contacts/index.d.ts +15 -0
- package/build/services/contacts/index.js +17 -0
- package/build/{module/services → services}/contacts/methods.d.ts +5 -5
- package/build/services/contacts/methods.js +1 -0
- package/build/{module/services → services}/currencies/entities.d.ts +2 -2
- package/build/services/currencies/entities.js +1 -0
- package/build/{module/services → services}/deals/entities.d.ts +2 -2
- package/build/services/deals/entities.js +1 -0
- package/build/services/deals/index.d.ts +15 -0
- package/build/services/deals/index.js +17 -0
- package/build/{main/services → services}/deals/methods.d.ts +5 -5
- package/build/services/deals/methods.js +1 -0
- package/build/{module/services → services}/leads/entities.d.ts +2 -2
- package/build/services/leads/entities.js +1 -0
- package/build/services/leads/index.d.ts +15 -0
- package/build/services/leads/index.js +17 -0
- package/build/{main/services → services}/leads/methods.d.ts +5 -5
- package/build/services/leads/methods.js +1 -0
- package/build/{main/services → services}/statuses/entities.d.ts +3 -3
- package/build/services/statuses/entities.js +1 -0
- package/build/services/statuses/index.d.ts +14 -0
- package/build/services/statuses/index.js +19 -0
- package/build/{main/services → services}/statuses/methods.d.ts +5 -5
- package/build/services/statuses/methods.js +1 -0
- package/build/{module/services → services}/users/entities.d.ts +2 -2
- package/build/services/users/entities.js +1 -0
- package/build/services/users/index.d.ts +9 -0
- package/build/services/users/index.js +7 -0
- package/build/{main/services → services}/users/methods.d.ts +4 -4
- package/build/services/users/methods.js +1 -0
- package/build/utils/Diff.d.ts +1 -0
- package/build/utils/Diff.js +7 -0
- package/build/{module/utils → utils}/ExtractValue.d.ts +1 -1
- package/build/{main/utils/ExtractValue.d.ts → utils/ExtractValue.js} +1 -2
- package/build/utils/isArray.d.ts +2 -0
- package/build/{module/utils → utils}/isArray.js +1 -1
- package/package.json +43 -49
- package/build/main/bitrix.d.ts +0 -114
- package/build/main/bitrix.integration.test.d.ts +0 -0
- package/build/main/bitrix.integration.test.js +0 -31
- package/build/main/bitrix.js +0 -61
- package/build/main/bitrix.unit.test.d.ts +0 -1
- package/build/main/bitrix.unit.test.js +0 -44
- package/build/main/client/client.unit.test.d.ts +0 -1
- package/build/main/client/client.unit.test.js +0 -70
- package/build/main/client/hooks/addAccessToken.js +0 -13
- package/build/main/client/hooks/addAccessToken.unit.test.d.ts +0 -1
- package/build/main/client/hooks/addAccessToken.unit.test.js +0 -31
- package/build/main/client/index.d.ts +0 -15
- package/build/main/client/index.js +0 -53
- package/build/main/client/methods/batch.d.ts +0 -40
- package/build/main/client/methods/batch.js +0 -85
- package/build/main/client/methods/batch.unit.test.d.ts +0 -1
- package/build/main/client/methods/batch.unit.test.js +0 -494
- package/build/main/client/methods/call.d.ts +0 -17
- package/build/main/client/methods/call.js +0 -36
- package/build/main/client/methods/call.unit.test.d.ts +0 -1
- package/build/main/client/methods/call.unit.test.js +0 -183
- package/build/main/client/methods/list.d.ts +0 -30
- package/build/main/client/methods/list.js +0 -66
- package/build/main/client/methods/list.unit.test.d.ts +0 -1
- package/build/main/client/methods/list.unit.test.js +0 -277
- package/build/main/commands.d.ts +0 -10
- package/build/main/commands.js +0 -2
- package/build/main/methods.d.ts +0 -92
- package/build/main/methods.js +0 -41
- package/build/main/payloads.js +0 -2
- package/build/main/services/common.js +0 -2
- package/build/main/services/companies/entities.js +0 -2
- package/build/main/services/companies/index.d.ts +0 -26
- package/build/main/services/companies/index.integration.test.d.ts +0 -1
- package/build/main/services/companies/index.integration.test.js +0 -19
- package/build/main/services/companies/index.js +0 -10
- package/build/main/services/companies/index.unit.test.d.ts +0 -1
- package/build/main/services/companies/index.unit.test.js +0 -72
- package/build/main/services/companies/methods.d.ts +0 -44
- package/build/main/services/companies/methods.js +0 -3
- package/build/main/services/contacts/entities.d.ts +0 -45
- package/build/main/services/contacts/entities.js +0 -2
- package/build/main/services/contacts/index.d.ts +0 -26
- package/build/main/services/contacts/index.integration.test.d.ts +0 -1
- package/build/main/services/contacts/index.integration.test.js +0 -19
- package/build/main/services/contacts/index.js +0 -10
- package/build/main/services/contacts/index.unit.test.d.ts +0 -1
- package/build/main/services/contacts/index.unit.test.js +0 -72
- package/build/main/services/contacts/methods.d.ts +0 -44
- package/build/main/services/contacts/methods.js +0 -3
- package/build/main/services/currencies/entities.d.ts +0 -15
- package/build/main/services/currencies/entities.js +0 -2
- package/build/main/services/deals/entities.d.ts +0 -43
- package/build/main/services/deals/entities.js +0 -2
- package/build/main/services/deals/index.d.ts +0 -26
- package/build/main/services/deals/index.integration.test.d.ts +0 -1
- package/build/main/services/deals/index.integration.test.js +0 -19
- package/build/main/services/deals/index.js +0 -10
- package/build/main/services/deals/index.unit.test.d.ts +0 -1
- package/build/main/services/deals/index.unit.test.js +0 -72
- package/build/main/services/deals/methods.js +0 -3
- package/build/main/services/leads/entities.d.ts +0 -49
- package/build/main/services/leads/entities.js +0 -2
- package/build/main/services/leads/index.d.ts +0 -26
- package/build/main/services/leads/index.integration.test.d.ts +0 -1
- package/build/main/services/leads/index.integration.test.js +0 -19
- package/build/main/services/leads/index.js +0 -10
- package/build/main/services/leads/index.unit.test.d.ts +0 -1
- package/build/main/services/leads/index.unit.test.js +0 -72
- package/build/main/services/leads/methods.js +0 -3
- package/build/main/services/statuses/entities.js +0 -2
- package/build/main/services/statuses/index.d.ts +0 -14
- package/build/main/services/statuses/index.integration.test.d.ts +0 -1
- package/build/main/services/statuses/index.integration.test.js +0 -90
- package/build/main/services/statuses/index.js +0 -11
- package/build/main/services/statuses/index.unit.test.d.ts +0 -1
- package/build/main/services/statuses/index.unit.test.js +0 -60
- package/build/main/services/statuses/methods.js +0 -3
- package/build/main/services/users/entities.d.ts +0 -40
- package/build/main/services/users/entities.js +0 -2
- package/build/main/services/users/index.d.ts +0 -9
- package/build/main/services/users/index.integration.test.d.ts +0 -1
- package/build/main/services/users/index.integration.test.js +0 -33
- package/build/main/services/users/index.js +0 -7
- package/build/main/services/users/index.unit.test.d.ts +0 -1
- package/build/main/services/users/index.unit.test.js +0 -25
- package/build/main/services/users/methods.js +0 -3
- package/build/main/utils/Diff.d.ts +0 -1
- package/build/main/utils/Diff.js +0 -2
- package/build/main/utils/ExtractValue.js +0 -2
- package/build/main/utils/isArray.d.ts +0 -2
- package/build/main/utils/isArray.js +0 -4
- package/build/module/bitrix.d.ts +0 -114
- package/build/module/bitrix.integration.test.d.ts +0 -0
- package/build/module/bitrix.integration.test.js +0 -31
- package/build/module/bitrix.js +0 -40
- package/build/module/bitrix.unit.test.d.ts +0 -1
- package/build/module/bitrix.unit.test.js +0 -16
- package/build/module/client/client.unit.test.d.ts +0 -1
- package/build/module/client/client.unit.test.js +0 -65
- package/build/module/client/hooks/addAccessToken.d.ts +0 -6
- package/build/module/client/hooks/addAccessToken.js +0 -11
- package/build/module/client/hooks/addAccessToken.unit.test.d.ts +0 -1
- package/build/module/client/hooks/addAccessToken.unit.test.js +0 -26
- package/build/module/client/methods/batch.js +0 -76
- package/build/module/client/methods/batch.unit.test.d.ts +0 -1
- package/build/module/client/methods/batch.unit.test.js +0 -466
- package/build/module/client/methods/call.unit.test.d.ts +0 -1
- package/build/module/client/methods/call.unit.test.js +0 -155
- package/build/module/client/methods/list.js +0 -55
- package/build/module/client/methods/list.unit.test.d.ts +0 -1
- package/build/module/client/methods/list.unit.test.js +0 -252
- package/build/module/commands.js +0 -1
- package/build/module/payloads.d.ts +0 -40
- package/build/module/payloads.js +0 -1
- package/build/module/services/common.d.ts +0 -22
- package/build/module/services/common.js +0 -1
- package/build/module/services/companies/entities.d.ts +0 -54
- package/build/module/services/companies/entities.js +0 -1
- package/build/module/services/companies/index.d.ts +0 -26
- package/build/module/services/companies/index.integration.test.d.ts +0 -1
- package/build/module/services/companies/index.integration.test.js +0 -14
- package/build/module/services/companies/index.js +0 -8
- package/build/module/services/companies/index.unit.test.d.ts +0 -1
- package/build/module/services/companies/index.unit.test.js +0 -67
- package/build/module/services/companies/methods.js +0 -1
- package/build/module/services/contacts/entities.js +0 -1
- package/build/module/services/contacts/index.d.ts +0 -26
- package/build/module/services/contacts/index.integration.test.d.ts +0 -1
- package/build/module/services/contacts/index.integration.test.js +0 -14
- package/build/module/services/contacts/index.js +0 -8
- package/build/module/services/contacts/index.unit.test.d.ts +0 -1
- package/build/module/services/contacts/index.unit.test.js +0 -67
- 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.d.ts +0 -26
- package/build/module/services/deals/index.integration.test.d.ts +0 -1
- package/build/module/services/deals/index.integration.test.js +0 -14
- package/build/module/services/deals/index.js +0 -8
- package/build/module/services/deals/index.unit.test.d.ts +0 -1
- package/build/module/services/deals/index.unit.test.js +0 -67
- package/build/module/services/deals/methods.d.ts +0 -44
- package/build/module/services/deals/methods.js +0 -1
- package/build/module/services/leads/entities.js +0 -1
- package/build/module/services/leads/index.d.ts +0 -26
- package/build/module/services/leads/index.integration.test.d.ts +0 -1
- package/build/module/services/leads/index.integration.test.js +0 -14
- package/build/module/services/leads/index.js +0 -8
- package/build/module/services/leads/index.unit.test.d.ts +0 -1
- package/build/module/services/leads/index.unit.test.js +0 -67
- package/build/module/services/leads/methods.d.ts +0 -44
- package/build/module/services/leads/methods.js +0 -1
- package/build/module/services/statuses/entities.d.ts +0 -16
- package/build/module/services/statuses/entities.js +0 -1
- package/build/module/services/statuses/index.d.ts +0 -14
- package/build/module/services/statuses/index.integration.test.d.ts +0 -1
- package/build/module/services/statuses/index.integration.test.js +0 -85
- package/build/module/services/statuses/index.js +0 -9
- package/build/module/services/statuses/index.unit.test.d.ts +0 -1
- package/build/module/services/statuses/index.unit.test.js +0 -55
- package/build/module/services/statuses/methods.d.ts +0 -51
- 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 +0 -9
- package/build/module/services/users/index.integration.test.d.ts +0 -1
- package/build/module/services/users/index.integration.test.js +0 -28
- package/build/module/services/users/index.js +0 -5
- package/build/module/services/users/index.unit.test.d.ts +0 -1
- package/build/module/services/users/index.unit.test.js +0 -20
- package/build/module/services/users/methods.d.ts +0 -17
- package/build/module/services/users/methods.js +0 -1
- package/build/module/utils/Diff.d.ts +0 -1
- package/build/module/utils/Diff.js +0 -1
- package/build/module/utils/ExtractValue.js +0 -1
- package/build/module/utils/isArray.d.ts +0 -2
- /package/build/{main/client → client}/hooks/addAccessToken.d.ts +0 -0
package/README.md
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/@2bad/bitrix)
|
|
6
6
|
[](https://www.npmjs.com/package/@2bad/bitrix)
|
|
7
7
|
[](https://codecov.io/gh/2BAD/bitrix)
|
|
8
|
-
[](https://github.com/2BAD/bitrix/actions?query=workflow%3A%22Integration+testing%22)
|
|
8
|
+
[](https://github.com/2BAD/bitrix/actions/workflows/build.yml)
|
|
10
9
|
[](https://github.com/2BAD/bitrix/search?l=typescript)
|
|
11
10
|
|
|
12
11
|
- 🔥 No bullshit
|
|
@@ -0,0 +1,65 @@
|
|
|
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.ts").Call;
|
|
12
|
+
batch: import("./client/methods/batch.ts").Batch;
|
|
13
|
+
list: import("./client/methods/list.ts").List;
|
|
14
|
+
companies: {
|
|
15
|
+
fields: () => Promise<import("./payloads.ts").GetPayload<import("./services/common.js").Fields>>;
|
|
16
|
+
create: <D extends import("./methods.js").MethodParams<import("./methods.js").Method.CRM_COMPANY_ADD>>(fields: D["fields"], params?: D["params"]) => Promise<import("./payloads.ts").GetPayload<number>>;
|
|
17
|
+
get: (id: string) => Promise<import("./payloads.ts").GetPayload<import("./services/companies/entities.js").Company>>;
|
|
18
|
+
list: (params?: import("./methods.js").MethodParams<import("./methods.js").Method.CRM_COMPANY_LIST>) => Promise<import("./payloads.ts").ListPayload<import("./services/companies/entities.js").Company>>;
|
|
19
|
+
update: <D extends import("./methods.js").MethodParams<import("./methods.js").Method.CRM_COMPANY_UPDATE>>(id: string, fields: D["fields"], params?: D["params"]) => Promise<import("./payloads.ts").GetPayload<boolean>>;
|
|
20
|
+
};
|
|
21
|
+
contacts: {
|
|
22
|
+
fields: () => Promise<import("./payloads.ts").GetPayload<import("./services/common.js").Fields>>;
|
|
23
|
+
create: <D extends import("./methods.js").MethodParams<import("./methods.js").Method.CRM_CONTACT_ADD>>(fields: D["fields"], params?: D["params"]) => Promise<import("./payloads.ts").GetPayload<number>>;
|
|
24
|
+
get: (id: string) => Promise<import("./payloads.ts").GetPayload<import("./services/contacts/entities.js").Contact>>;
|
|
25
|
+
list: (params?: import("./methods.js").MethodParams<import("./methods.js").Method.CRM_CONTACT_LIST>) => Promise<import("./payloads.ts").ListPayload<import("./services/contacts/entities.js").Contact>>;
|
|
26
|
+
update: <D extends import("./methods.js").MethodParams<import("./methods.js").Method.CRM_CONTACT_UPDATE>>(id: string, fields: D["fields"], params?: D["params"]) => Promise<import("./payloads.ts").GetPayload<boolean>>;
|
|
27
|
+
};
|
|
28
|
+
deals: {
|
|
29
|
+
fields: () => Promise<import("./payloads.ts").GetPayload<import("./services/common.js").Fields>>;
|
|
30
|
+
create: <D extends import("./methods.js").MethodParams<import("./methods.js").Method.CRM_DEAL_ADD>>(fields: D["fields"], params?: D["params"]) => Promise<import("./payloads.ts").GetPayload<number>>;
|
|
31
|
+
get: (id: string) => Promise<import("./payloads.ts").GetPayload<import("./services/deals/entities.js").Deal>>;
|
|
32
|
+
list: (params?: import("./methods.js").MethodParams<import("./methods.js").Method.CRM_DEAL_LIST>) => Promise<import("./payloads.ts").ListPayload<import("./services/deals/entities.js").Deal>>;
|
|
33
|
+
update: <D extends import("./methods.js").MethodParams<import("./methods.js").Method.CRM_DEAL_UPDATE>>(id: string, fields: D["fields"], params?: D["params"]) => Promise<import("./payloads.ts").GetPayload<boolean>>;
|
|
34
|
+
};
|
|
35
|
+
leads: {
|
|
36
|
+
fields: () => Promise<import("./payloads.ts").GetPayload<import("./services/common.js").Fields>>;
|
|
37
|
+
create: <D extends import("./methods.js").MethodParams<import("./methods.js").Method.CRM_LEAD_ADD>>(fields: D["fields"], params?: D["params"]) => Promise<import("./payloads.ts").GetPayload<number>>;
|
|
38
|
+
get: (id: string) => Promise<import("./payloads.ts").GetPayload<import("./services/leads/entities.js").Lead>>;
|
|
39
|
+
list: (params?: import("./methods.js").MethodParams<import("./methods.js").Method.CRM_LEAD_LIST>) => Promise<import("./payloads.ts").ListPayload<import("./services/leads/entities.js").Lead>>;
|
|
40
|
+
update: <D extends import("./methods.js").MethodParams<import("./methods.js").Method.CRM_LEAD_UPDATE>>(id: string, fields: D["fields"], params?: D["params"]) => Promise<import("./payloads.ts").GetPayload<boolean>>;
|
|
41
|
+
};
|
|
42
|
+
statuses: {
|
|
43
|
+
fields: () => Promise<import("./payloads.ts").GetPayload<import("./services/common.js").Fields>>;
|
|
44
|
+
create: (fields: import("./methods.js").MethodParams<import("./methods.js").Method.CRM_STATUS_ADD>["fields"]) => Promise<import("./payloads.ts").GetPayload<number>>;
|
|
45
|
+
delete: (id: string | number, params?: import("./methods.js").MethodParams<import("./methods.js").Method.CRM_STATUS_DELETE>["params"]) => Promise<import("./payloads.ts").GetPayload<boolean>>;
|
|
46
|
+
get: (id: string | number) => Promise<import("./payloads.ts").GetPayload<import("./services/statuses/entities.js").Status>>;
|
|
47
|
+
list: (params?: import("./methods.js").MethodParams<import("./methods.js").Method.CRM_STATUS_LIST>) => Promise<import("./payloads.ts").ListPayload<import("./services/statuses/entities.js").Status>>;
|
|
48
|
+
update: (id: string | number, fields: import("./methods.js").MethodParams<import("./methods.js").Method.CRM_STATUS_UPDATE>["fields"]) => Promise<import("./payloads.ts").GetPayload<boolean>>;
|
|
49
|
+
};
|
|
50
|
+
users: {
|
|
51
|
+
fields: () => Promise<import("./payloads.ts").GetPayload<import("./services/users/entities.js").User>>;
|
|
52
|
+
get: (id?: string) => Promise<import("./payloads.ts").GetPayload<readonly import("./services/users/entities.js").User[]>>;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export default Bitrix;
|
|
56
|
+
export * from './methods.js';
|
|
57
|
+
export * from './commands.js';
|
|
58
|
+
export * from './services/common.js';
|
|
59
|
+
export * from './services/companies/entities.js';
|
|
60
|
+
export * from './services/contacts/entities.js';
|
|
61
|
+
export * from './services/currencies/entities.js';
|
|
62
|
+
export * from './services/deals/entities.js';
|
|
63
|
+
export * from './services/leads/entities.js';
|
|
64
|
+
export * from './services/statuses/entities.js';
|
|
65
|
+
export * from './services/users/entities.js';
|
package/build/bitrix.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import Client from "./client/index.js";
|
|
2
|
+
import CompaniesService from "./services/companies/index.js";
|
|
3
|
+
import ContactsService from "./services/contacts/index.js";
|
|
4
|
+
import DealsService from "./services/deals/index.js";
|
|
5
|
+
import LeadsService from "./services/leads/index.js";
|
|
6
|
+
import StatusesService from "./services/statuses/index.js";
|
|
7
|
+
import UsersService from "./services/users/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* Construct a Bitrix client with generic methods
|
|
10
|
+
* @param restURI REST endpoint, like a `https://hello.bitrix24.ua/rest` or an inbound webhook endpoint,
|
|
11
|
+
* like a `https://hello.bitrix24.ua/rest/1/WEBHOOK_TOKEN`.
|
|
12
|
+
* @param accessToken Bitrix application Access Token. Do not specify in case inbound webhook endpoint used.
|
|
13
|
+
* @param clientOptions an object that will overwrite underlying configuration for HTTP client,
|
|
14
|
+
* see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
|
|
15
|
+
*/ export const Bitrix = (restURI, accessToken, clientOptions)=>{
|
|
16
|
+
const { call, batch, list } = Client(restURI, accessToken, clientOptions);
|
|
17
|
+
return {
|
|
18
|
+
call,
|
|
19
|
+
batch,
|
|
20
|
+
list,
|
|
21
|
+
companies: CompaniesService({
|
|
22
|
+
call,
|
|
23
|
+
list
|
|
24
|
+
}),
|
|
25
|
+
contacts: ContactsService({
|
|
26
|
+
call,
|
|
27
|
+
list
|
|
28
|
+
}),
|
|
29
|
+
deals: DealsService({
|
|
30
|
+
call,
|
|
31
|
+
list
|
|
32
|
+
}),
|
|
33
|
+
leads: LeadsService({
|
|
34
|
+
call,
|
|
35
|
+
list
|
|
36
|
+
}),
|
|
37
|
+
statuses: StatusesService({
|
|
38
|
+
call
|
|
39
|
+
}),
|
|
40
|
+
users: UsersService({
|
|
41
|
+
call
|
|
42
|
+
})
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export default Bitrix;
|
|
46
|
+
export * from "./methods.js";
|
|
47
|
+
export * from "./commands.js";
|
|
48
|
+
export * from "./services/common.js";
|
|
49
|
+
export * from "./services/companies/entities.js";
|
|
50
|
+
export * from "./services/contacts/entities.js";
|
|
51
|
+
export * from "./services/currencies/entities.js";
|
|
52
|
+
export * from "./services/deals/entities.js";
|
|
53
|
+
export * from "./services/leads/entities.js";
|
|
54
|
+
export * from "./services/statuses/entities.js";
|
|
55
|
+
export * from "./services/users/entities.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Got can't merge `query` option with other queries if they are string. But that hook can.
|
|
3
|
+
*/ export default ((accessToken)=>(options)=>{
|
|
4
|
+
if (!accessToken) return;
|
|
5
|
+
if (!options.url) return;
|
|
6
|
+
if (typeof options.url.search === 'string') {
|
|
7
|
+
options.url.search = `${options.url.search}${options.url.search ? '&' : '?'}access_token=${accessToken}`;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
@@ -8,8 +8,8 @@ import { ExtendOptions } from 'got';
|
|
|
8
8
|
* see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
|
|
9
9
|
*/
|
|
10
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;
|
|
11
|
+
call: import("./methods/call.js").Call;
|
|
12
|
+
batch: import("./methods/batch.js").Batch;
|
|
13
|
+
list: import("./methods/list.js").List;
|
|
14
14
|
};
|
|
15
15
|
export default _default;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import got from
|
|
2
|
-
import Queue from
|
|
3
|
-
import addAccessToken from
|
|
4
|
-
import Batch from
|
|
5
|
-
import Call from
|
|
6
|
-
import List from
|
|
1
|
+
import got from "got";
|
|
2
|
+
import Queue from "p-queue";
|
|
3
|
+
import addAccessToken from "./hooks/addAccessToken.js";
|
|
4
|
+
import Batch from "./methods/batch.js";
|
|
5
|
+
import Call from "./methods/call.js";
|
|
6
|
+
import List from "./methods/list.js";
|
|
7
7
|
const BITRIX_API_RATE_LIMIT = 2;
|
|
8
|
-
const BITRIX_API_RATE_INTERVAL = 1000
|
|
8
|
+
const BITRIX_API_RATE_INTERVAL = 1000 // 1 second
|
|
9
|
+
;
|
|
9
10
|
/**
|
|
10
11
|
* Construct a Bitrix client with generic methods
|
|
11
12
|
* @param restURI REST endpoint, like a `https://hello.bitrix24.ru/rest` or an inbound webhook endpoint,
|
|
@@ -13,8 +14,7 @@ const BITRIX_API_RATE_INTERVAL = 1000; // 1 second
|
|
|
13
14
|
* @param accessToken Bitrix application Access Token. Do not specify in case inbound webhook endpoint used.
|
|
14
15
|
* @param options an object that will overwrite underlying configuration for HTTP client,
|
|
15
16
|
* see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
|
|
16
|
-
*/
|
|
17
|
-
export default (restURI, accessToken, options) => {
|
|
17
|
+
*/ export default ((restURI, accessToken, options)=>{
|
|
18
18
|
const client = got.extend({
|
|
19
19
|
prefixUrl: restURI,
|
|
20
20
|
headers: {
|
|
@@ -32,17 +32,22 @@ export default (restURI, accessToken, options) => {
|
|
|
32
32
|
intervalCap: BITRIX_API_RATE_LIMIT,
|
|
33
33
|
interval: BITRIX_API_RATE_INTERVAL
|
|
34
34
|
});
|
|
35
|
-
const queuedGet = (...args)
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
35
|
+
const queuedGet = (...args)=>queue.add(()=>client.get(...args));
|
|
37
36
|
// @ts-expect-error @todo remove after issue is resolved (https://github.com/sindresorhus/got/issues/954)
|
|
38
|
-
const call = Call({
|
|
39
|
-
|
|
37
|
+
const call = Call({
|
|
38
|
+
get: queuedGet
|
|
39
|
+
});
|
|
40
40
|
// @ts-expect-error @todo remove after issue is resolved (https://github.com/sindresorhus/got/issues/954)
|
|
41
|
-
const batch = Batch({
|
|
42
|
-
|
|
41
|
+
const batch = Batch({
|
|
42
|
+
get: queuedGet
|
|
43
|
+
});
|
|
44
|
+
const list = List({
|
|
45
|
+
call,
|
|
46
|
+
batch
|
|
47
|
+
});
|
|
43
48
|
return {
|
|
44
49
|
call,
|
|
45
50
|
batch,
|
|
46
51
|
list
|
|
47
52
|
};
|
|
48
|
-
};
|
|
53
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import got from 'got';
|
|
2
|
-
import { Commands } from '../../commands';
|
|
3
|
-
import { Method, MethodPayloadType } from '../../methods';
|
|
4
|
-
import { BatchPayload } from '../../payloads';
|
|
2
|
+
import { Commands } from '../../commands.js';
|
|
3
|
+
import { Method, MethodPayloadType } from '../../methods.js';
|
|
4
|
+
import { BatchPayload } from '../../payloads.js';
|
|
5
5
|
export declare const MAX_COMMANDS_PER_BATCH = 50;
|
|
6
6
|
/**
|
|
7
7
|
* Split any number of commands into the chunks with max commands per batch in each chunk
|
|
@@ -18,15 +18,15 @@ export declare const prepareCommandsQueries: <C extends Commands, R = { [K in ke
|
|
|
18
18
|
* @todo Generics inference is complicated here and might be not super accurate
|
|
19
19
|
*/
|
|
20
20
|
export declare const mergeBatchPayloads: <B extends BatchPayload<unknown>, P = B extends BatchPayload<infer U> ? U : never>(payloads: readonly B[]) => BatchPayload<P>;
|
|
21
|
-
export
|
|
21
|
+
export type CommandsPayloads<C extends Commands, CM = {
|
|
22
22
|
[K in keyof C]: C[K] extends {
|
|
23
23
|
readonly method: infer M;
|
|
24
24
|
} ? M : never;
|
|
25
25
|
}> = {
|
|
26
26
|
[K in keyof CM]: MethodPayloadType<CM[K] extends Method ? CM[K] : never>;
|
|
27
27
|
};
|
|
28
|
-
export
|
|
29
|
-
|
|
28
|
+
export type Batch = <C extends Commands, P = CommandsPayloads<C>>(commands: C, commandsPerRequest?: number) => Promise<BatchPayload<P>>;
|
|
29
|
+
type Dependencies = {
|
|
30
30
|
readonly get: typeof got.get;
|
|
31
31
|
};
|
|
32
32
|
/**
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import chunk from "lodash.chunk";
|
|
2
|
+
import fromPairs from "lodash.frompairs";
|
|
3
|
+
import { stringify as toQuery } from "qs";
|
|
4
|
+
import { Method } from "../../methods.js";
|
|
5
|
+
import isArray from "../../utils/isArray.js";
|
|
6
|
+
import { handlePayload } from "./call.js";
|
|
7
|
+
export const MAX_COMMANDS_PER_BATCH = 50;
|
|
8
|
+
/**
|
|
9
|
+
* Split any number of commands into the chunks with max commands per batch in each chunk
|
|
10
|
+
*/ export const chunkCommands = (commands, size = MAX_COMMANDS_PER_BATCH)=>{
|
|
11
|
+
const commandsIsArray = isArray(commands);
|
|
12
|
+
const chunks = chunk(Object.entries(commands), size);
|
|
13
|
+
// @todo Generated return type isn't very accurate since it says that it will make array of <C>, while
|
|
14
|
+
// in fact <C> will be distributed among chunks. That gives wrong hints with named commands and arrays as const.
|
|
15
|
+
return chunks.map((c)=>commandsIsArray ? c.map(([_key, command])=>command) : fromPairs(c));
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Prepares list of commands to be used in requests to the Bitrix
|
|
19
|
+
* @note We could avoid that function... if only Bitrix API would support posting of the batch commands as
|
|
20
|
+
* plain objects, like it does with other methods. Instead, it should be a dict or array of string queries
|
|
21
|
+
*/ export const prepareCommandsQueries = (commands)=>Object.entries(commands).reduce((calls, [name, { method, params }])=>{
|
|
22
|
+
const stringifiedParams = params ? `?${toQuery(params)}` : '';
|
|
23
|
+
return {
|
|
24
|
+
...calls,
|
|
25
|
+
[`cmd[${name}]`]: `${method}${stringifiedParams}`
|
|
26
|
+
};
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/prefer-reduce-type-parameter
|
|
28
|
+
}, {});
|
|
29
|
+
/**
|
|
30
|
+
* Merges list of batch responses into a single batch
|
|
31
|
+
* @todo Generics inference is complicated here and might be not super accurate
|
|
32
|
+
*/ export const mergeBatchPayloads = (payloads)=>{
|
|
33
|
+
const merge = (a, b)=>isArray(a) && isArray(b) ? [
|
|
34
|
+
...a,
|
|
35
|
+
...b
|
|
36
|
+
] : {
|
|
37
|
+
...a,
|
|
38
|
+
...b
|
|
39
|
+
};
|
|
40
|
+
return payloads.reduce((merged, payload)=>({
|
|
41
|
+
result: {
|
|
42
|
+
result: merge(merged.result.result || [], payload.result.result),
|
|
43
|
+
result_error: merge(merged.result.result_error || [], payload.result.result_error),
|
|
44
|
+
result_next: merge(merged.result.result_next || [], payload.result.result_next),
|
|
45
|
+
result_time: merge(merged.result.result_time || [], payload.result.result_time),
|
|
46
|
+
result_total: merge(merged.result.result_total || [], payload.result.result_total)
|
|
47
|
+
},
|
|
48
|
+
time: {
|
|
49
|
+
...merged.time,
|
|
50
|
+
...payload.time
|
|
51
|
+
}
|
|
52
|
+
}), {
|
|
53
|
+
result: {},
|
|
54
|
+
time: {}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Dispatches a batch request with specified commands. Will fill figure out payload type based on the Methods.
|
|
59
|
+
* Supports unlimited number of commands. If they do exceed max amount of commands per batch, will dispatch
|
|
60
|
+
* multiple request and merge result into single batch payload
|
|
61
|
+
* @todo For now due to issues with types it won't check `params` of command, so any Method can be used
|
|
62
|
+
* with any (even wrong) params
|
|
63
|
+
*/ export default (({ get })=>{
|
|
64
|
+
const batch = async (commands, commandsPerRequest = MAX_COMMANDS_PER_BATCH)=>{
|
|
65
|
+
const call = (c)=>get(Method.BATCH, {
|
|
66
|
+
searchParams: prepareCommandsQueries(c)
|
|
67
|
+
}).then(({ body })=>body);
|
|
68
|
+
const calls = chunkCommands(commands, commandsPerRequest).map(call);
|
|
69
|
+
return await Promise.all(calls).then((chunkedPayloads)=>{
|
|
70
|
+
const payloads = mergeBatchPayloads(chunkedPayloads);
|
|
71
|
+
return handlePayload(payloads);
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
return batch;
|
|
75
|
+
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import got from 'got';
|
|
2
|
-
import { Method, MethodParams, MethodPayload } from '../../methods';
|
|
3
|
-
import { Payload } from '../../payloads';
|
|
2
|
+
import { Method, MethodParams, MethodPayload } from '../../methods.js';
|
|
3
|
+
import { Payload } from '../../payloads.js';
|
|
4
4
|
/**
|
|
5
5
|
* Checks wether payload have any errors and if it does — throws them
|
|
6
6
|
* Bitrix payload types do not provide discriminators, so we're forced to type cast them
|
|
7
7
|
*/
|
|
8
8
|
export declare const handlePayload: <P extends Payload<unknown>>(payload: P) => P;
|
|
9
|
-
export
|
|
10
|
-
|
|
9
|
+
export type Call = <M extends Method>(method: M, params: MethodParams<M>) => Promise<MethodPayload<M>>;
|
|
10
|
+
type Dependencies = {
|
|
11
11
|
readonly get: typeof got.get;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { stringify as toQuery } from
|
|
2
|
-
import isArray from
|
|
1
|
+
import { stringify as toQuery } from "qs";
|
|
2
|
+
import isArray from "../../utils/isArray.js";
|
|
3
3
|
/**
|
|
4
4
|
* Checks wether payload have any errors and if it does — throws them
|
|
5
5
|
* Bitrix payload types do not provide discriminators, so we're forced to type cast them
|
|
6
|
-
*/
|
|
7
|
-
export const handlePayload = (payload) => {
|
|
6
|
+
*/ export const handlePayload = (payload)=>{
|
|
8
7
|
if (payload.error) {
|
|
9
8
|
throw new Error(`[call] failed to get the resource: ${payload.error ?? ''}.`);
|
|
10
9
|
}
|
|
@@ -20,9 +19,9 @@ export const handlePayload = (payload) => {
|
|
|
20
19
|
};
|
|
21
20
|
/**
|
|
22
21
|
* Dispatches a request with specified method and params. Will fill figure out payload type based on the Method
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.then(({ body })
|
|
22
|
+
*/ export default (({ get })=>{
|
|
23
|
+
const call = (method, params)=>get(method, {
|
|
24
|
+
searchParams: toQuery(params)
|
|
25
|
+
}).then(({ body })=>handlePayload(body));
|
|
27
26
|
return call;
|
|
28
|
-
};
|
|
27
|
+
});
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Command } from '../../commands';
|
|
2
|
-
import { ListableMethod, MethodParams, MethodPayloadType } from '../../methods';
|
|
3
|
-
import { BatchPayload, ListPayload } from '../../payloads';
|
|
4
|
-
import { Batch } from './batch';
|
|
5
|
-
import { Call } from './call';
|
|
1
|
+
import { Command } from '../../commands.js';
|
|
2
|
+
import { ListableMethod, MethodParams, MethodPayloadType } from '../../methods.js';
|
|
3
|
+
import { BatchPayload, ListPayload } from '../../payloads.js';
|
|
4
|
+
import { Batch } from './batch.js';
|
|
5
|
+
import { Call } from './call.js';
|
|
6
6
|
/**
|
|
7
7
|
* Generates required amount of commands to process specified amount of entries
|
|
8
8
|
*/
|
|
9
|
-
export declare const fillWithCommands: <C extends Command>({ method, params }: C, start: number, toProcess: number, entriesPerCommand: number) =>
|
|
9
|
+
export declare const fillWithCommands: <C extends Command>({ method, params }: C, start: number, toProcess: number, entriesPerCommand: number) => ReadonlyArray<{
|
|
10
10
|
readonly method: C["method"];
|
|
11
|
-
readonly params?: C["params"]
|
|
12
|
-
}
|
|
11
|
+
readonly params?: C["params"];
|
|
12
|
+
}>;
|
|
13
13
|
/**
|
|
14
14
|
* Get the highest value from object or an array if there's any
|
|
15
15
|
*/
|
|
@@ -18,11 +18,11 @@ export declare const highest: (input: ReadonlyArray<number | undefined> | Record
|
|
|
18
18
|
* Converts batch payload to a list payload
|
|
19
19
|
*/
|
|
20
20
|
export declare const batchToListPayload: <P>(payload: BatchPayload<Record<string, P> | readonly P[]>) => ListPayload<P>;
|
|
21
|
-
|
|
21
|
+
type Dependencies = {
|
|
22
22
|
readonly call: Call;
|
|
23
23
|
readonly batch: Batch;
|
|
24
24
|
};
|
|
25
|
-
export
|
|
25
|
+
export type List = <M extends ListableMethod>(method: M, params: MethodParams<M>) => Promise<ListPayload<MethodPayloadType<M>>>;
|
|
26
26
|
/**
|
|
27
27
|
* Gets all entries by dispatching required amount of requests. Will fill figure out payload type based on the Method.
|
|
28
28
|
*/
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import range from "lodash.range";
|
|
2
|
+
const MAX_ENTRIES_PER_COMMAND = 50;
|
|
3
|
+
/**
|
|
4
|
+
* Generates required amount of commands to process specified amount of entries
|
|
5
|
+
*/ export const fillWithCommands = ({ method, params }, start, toProcess, entriesPerCommand)=>{
|
|
6
|
+
const requiresCommands = Math.ceil((toProcess - start) / entriesPerCommand);
|
|
7
|
+
return range(0, requiresCommands).map((i)=>({
|
|
8
|
+
method,
|
|
9
|
+
params: {
|
|
10
|
+
...params,
|
|
11
|
+
start: start + entriesPerCommand * i
|
|
12
|
+
}
|
|
13
|
+
}));
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Get the highest value from object or an array if there's any
|
|
17
|
+
*/ export const highest = (input)=>Object.values(input).reduce((a, b)=>a !== undefined && b !== undefined ? a > b ? a : b : a !== undefined && b === undefined ? a : a === undefined && b !== undefined ? b : undefined, undefined);
|
|
18
|
+
/**
|
|
19
|
+
* Converts batch payload to a list payload
|
|
20
|
+
*/ export const batchToListPayload = (payload)=>{
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
22
|
+
const { result: { result, result_total, result_error, result_next }, time } = payload;
|
|
23
|
+
const flattenResult = Object.entries(result).reduce(// @ts-expect-error ignore this for now
|
|
24
|
+
(flatten, [_key, r])=>!r ? flatten : [
|
|
25
|
+
...flatten,
|
|
26
|
+
...r
|
|
27
|
+
], []);
|
|
28
|
+
return {
|
|
29
|
+
error: Object.values(result_error).join('\n'),
|
|
30
|
+
next: highest(result_next),
|
|
31
|
+
result: flattenResult,
|
|
32
|
+
// @todo Not accurate, we do not care
|
|
33
|
+
time,
|
|
34
|
+
total: highest(result_total) ?? 0
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Gets all entries by dispatching required amount of requests. Will fill figure out payload type based on the Method.
|
|
39
|
+
*/ export default (({ call, batch })=>{
|
|
40
|
+
const list = async (method, params)=>{
|
|
41
|
+
const start = params.start ?? 0;
|
|
42
|
+
const listAll = async ()=>{
|
|
43
|
+
const batchCommands = fillWithCommands({
|
|
44
|
+
method,
|
|
45
|
+
params
|
|
46
|
+
}, start, firstCall.total, MAX_ENTRIES_PER_COMMAND);
|
|
47
|
+
const payload = await batch(batchCommands);
|
|
48
|
+
// @ts-expect-error ignore this for now
|
|
49
|
+
return batchToListPayload(payload);
|
|
50
|
+
};
|
|
51
|
+
const firstCall = await call(method, {
|
|
52
|
+
...params,
|
|
53
|
+
start
|
|
54
|
+
});
|
|
55
|
+
return !firstCall.next ? firstCall : await listAll();
|
|
56
|
+
};
|
|
57
|
+
return list;
|
|
58
|
+
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Method } from './methods';
|
|
2
|
-
export
|
|
1
|
+
import { Method } from './methods.js';
|
|
2
|
+
export type Command = {
|
|
3
3
|
readonly method: Method;
|
|
4
4
|
readonly params?: Record<string, any>;
|
|
5
5
|
};
|
|
6
|
-
export
|
|
6
|
+
export type Commands = {
|
|
7
7
|
readonly [key: string]: Command;
|
|
8
8
|
} | {
|
|
9
9
|
readonly [index: number]: Command;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Commands } from './commands';
|
|
2
|
-
import { BatchPayload } from './payloads';
|
|
3
|
-
import { CompaniesMethods } from './services/companies/methods';
|
|
4
|
-
import { ContactsMethods } from './services/contacts/methods';
|
|
5
|
-
import { DealsMethods } from './services/deals/methods';
|
|
6
|
-
import { LeadsMethods } from './services/leads/methods';
|
|
7
|
-
import { StatusesMethods } from './services/statuses/methods';
|
|
8
|
-
import { UsersMethods } from './services/users/methods';
|
|
9
|
-
import { Diff } from './utils/Diff';
|
|
10
|
-
import { ExtractValue } from './utils/ExtractValue';
|
|
1
|
+
import { Commands } from './commands.js';
|
|
2
|
+
import { BatchPayload } from './payloads.js';
|
|
3
|
+
import { CompaniesMethods } from './services/companies/methods.js';
|
|
4
|
+
import { ContactsMethods } from './services/contacts/methods.js';
|
|
5
|
+
import { DealsMethods } from './services/deals/methods.js';
|
|
6
|
+
import { LeadsMethods } from './services/leads/methods.js';
|
|
7
|
+
import { StatusesMethods } from './services/statuses/methods.js';
|
|
8
|
+
import { UsersMethods } from './services/users/methods.js';
|
|
9
|
+
import { Diff } from './utils/Diff.js';
|
|
10
|
+
import { ExtractValue } from './utils/ExtractValue.js';
|
|
11
11
|
export declare enum Method {
|
|
12
12
|
BATCH = "batch",
|
|
13
13
|
CRM_COMPANY_FIELDS = "crm.company.fields",
|
|
@@ -40,16 +40,16 @@ export declare enum Method {
|
|
|
40
40
|
USER_GET = "user.get"
|
|
41
41
|
}
|
|
42
42
|
declare const LISTABLE_METHODS: readonly [Method.CRM_COMPANY_LIST, Method.CRM_CONTACT_LIST, Method.CRM_DEAL_LIST, Method.CRM_LEAD_LIST];
|
|
43
|
-
export
|
|
44
|
-
export
|
|
45
|
-
|
|
43
|
+
export type ListableMethod = typeof LISTABLE_METHODS[number];
|
|
44
|
+
export type GettableMethod = Diff<Method, ListableMethod>;
|
|
45
|
+
type MethodsMap = {
|
|
46
46
|
readonly [key: string]: {
|
|
47
47
|
readonly type: unknown;
|
|
48
48
|
readonly payload: unknown;
|
|
49
49
|
readonly params: Record<string, unknown>;
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
|
-
export
|
|
52
|
+
export type ListParams = {
|
|
53
53
|
readonly start?: number;
|
|
54
54
|
readonly order?: {
|
|
55
55
|
readonly [key: string]: string;
|
|
@@ -66,7 +66,7 @@ export declare type ListParams = {
|
|
|
66
66
|
* - `payload` — a payload that method returns
|
|
67
67
|
* - `params` — params that method accepts
|
|
68
68
|
*/
|
|
69
|
-
export
|
|
69
|
+
export type Methods = MethodsMap & CompaniesMethods & ContactsMethods & DealsMethods & LeadsMethods & StatusesMethods & UsersMethods & {
|
|
70
70
|
readonly [Method.BATCH]: {
|
|
71
71
|
readonly type: unknown;
|
|
72
72
|
readonly payload: BatchPayload<unknown>;
|
|
@@ -76,17 +76,17 @@ export declare type Methods = MethodsMap & CompaniesMethods & ContactsMethods &
|
|
|
76
76
|
/**
|
|
77
77
|
* Retrieve specified method data
|
|
78
78
|
*/
|
|
79
|
-
export
|
|
79
|
+
export type MethodData<M extends Method> = ExtractValue<Methods, M>;
|
|
80
80
|
/**
|
|
81
81
|
* Retrieve associated with specified method type
|
|
82
82
|
*/
|
|
83
|
-
export
|
|
83
|
+
export type MethodPayloadType<M extends Method> = MethodData<M>['type'];
|
|
84
84
|
/**
|
|
85
85
|
* Retrieve specified method payload type
|
|
86
86
|
*/
|
|
87
|
-
export
|
|
87
|
+
export type MethodPayload<M extends Method> = MethodData<M>['payload'];
|
|
88
88
|
/**
|
|
89
89
|
* Retrieve specified method params
|
|
90
90
|
*/
|
|
91
|
-
export
|
|
91
|
+
export type MethodParams<M extends Method> = MethodData<M>['params'];
|
|
92
92
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export var Method;
|
|
2
|
-
(function
|
|
2
|
+
(function(Method) {
|
|
3
3
|
Method["BATCH"] = "batch";
|
|
4
4
|
Method["CRM_COMPANY_FIELDS"] = "crm.company.fields";
|
|
5
5
|
Method["CRM_COMPANY_ADD"] = "crm.company.add";
|
|
@@ -31,8 +31,8 @@ export var Method;
|
|
|
31
31
|
Method["USER_GET"] = "user.get";
|
|
32
32
|
})(Method || (Method = {}));
|
|
33
33
|
const LISTABLE_METHODS = [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
"crm.company.list",
|
|
35
|
+
"crm.contact.list",
|
|
36
|
+
"crm.deal.list",
|
|
37
|
+
"crm.lead.list"
|
|
38
38
|
];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type PayloadTime = {
|
|
2
2
|
readonly start: number;
|
|
3
3
|
readonly finish: number;
|
|
4
4
|
readonly duration: number;
|
|
@@ -6,18 +6,18 @@ export declare type PayloadTime = {
|
|
|
6
6
|
readonly date_start: string;
|
|
7
7
|
readonly date_finish: string;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export type GetPayload<P> = {
|
|
10
10
|
readonly result: P;
|
|
11
11
|
readonly time: PayloadTime;
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export type ListPayload<P> = {
|
|
14
14
|
readonly result: readonly P[];
|
|
15
15
|
readonly error?: string;
|
|
16
16
|
readonly total: number;
|
|
17
17
|
readonly next?: number;
|
|
18
18
|
readonly time: PayloadTime;
|
|
19
19
|
};
|
|
20
|
-
export
|
|
20
|
+
export type BatchPayload<C> = {
|
|
21
21
|
readonly result: {
|
|
22
22
|
readonly result: {
|
|
23
23
|
readonly [P in keyof C]?: C[P];
|
|
@@ -37,4 +37,4 @@ export declare type BatchPayload<C> = {
|
|
|
37
37
|
};
|
|
38
38
|
readonly time: PayloadTime;
|
|
39
39
|
};
|
|
40
|
-
export
|
|
40
|
+
export type Payload<P> = GetPayload<P> | ListPayload<P> | BatchPayload<P>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|