forked from 2BAD/bitrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
methods.ts
110 lines (93 loc) · 3.31 KB
/
methods.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { Commands } from './commands'
import { BatchPayload } from './payloads'
import { CompaniesMethods } from './services/companies/methods'
import { ContactsMethods } from './services/contacts/methods'
import { DealsMethods } from './services/deals/methods'
import { LeadsMethods } from './services/leads/methods'
import { StatusesMethods } from './services/statuses/methods'
import { UsersMethods } from './services/users/methods'
import { Diff } from './utils/Diff'
import { ExtractValue } from './utils/ExtractValue'
export enum Method {
BATCH = 'batch',
CRM_COMPANY_FIELDS = 'crm.company.fields',
CRM_COMPANY_ADD = 'crm.company.add',
CRM_COMPANY_UPDATE = 'crm.company.update',
CRM_COMPANY_GET = 'crm.company.get',
CRM_COMPANY_LIST = 'crm.company.list',
CRM_CONTACT_FIELDS = 'crm.contact.fields',
CRM_CONTACT_ADD = 'crm.contact.add',
CRM_CONTACT_UPDATE = 'crm.contact.update',
CRM_CONTACT_GET = 'crm.contact.get',
CRM_CONTACT_LIST = 'crm.contact.list',
CRM_DEAL_FIELDS = 'crm.deal.fields',
CRM_DEAL_ADD = 'crm.deal.add',
CRM_DEAL_UPDATE = 'crm.deal.update',
CRM_DEAL_GET = 'crm.deal.get',
CRM_DEAL_LIST = 'crm.deal.list',
CRM_LEAD_FIELDS = 'crm.lead.fields',
CRM_LEAD_ADD = 'crm.lead.add',
CRM_LEAD_UPDATE = 'crm.lead.update',
CRM_LEAD_GET = 'crm.lead.get',
CRM_LEAD_LIST = 'crm.lead.list',
CRM_STATUS_FIELDS = 'crm.status.fields',
CRM_STATUS_ADD = 'crm.status.add',
CRM_STATUS_DELETE = 'crm.status.delete',
CRM_STATUS_GET = 'crm.status.get',
CRM_STATUS_LIST = 'crm.status.list',
CRM_STATUS_UPDATE = 'crm.status.update',
USER_FIELDS = 'user.fields',
USER_GET = 'user.get'
}
const LISTABLE_METHODS = [
Method.CRM_COMPANY_LIST,
Method.CRM_CONTACT_LIST,
Method.CRM_DEAL_LIST,
Method.CRM_LEAD_LIST
] as const
export type ListableMethod = typeof LISTABLE_METHODS[number]
export type GettableMethod = Diff<Method, ListableMethod>
type MethodsMap = {
readonly [key: string]: {
readonly type: unknown
readonly payload: unknown
readonly params: Record<string, unknown>
}
}
// @todo Figure out full list of possible values
export type ListParams = {
readonly start?: number
readonly order?: { readonly [key: string]: string } // 'ASC' | 'DESC'
readonly filter?: { readonly [key: string]: string | number }
readonly select?: readonly string[]
}
/**
* A mega map of all supported Bitrix methods to their parameters. Used to resolve
* low-level client method required params and payload types.
* - `type` — a type that method associated with
* - `payload` — a payload that method returns
* - `params` — params that method accepts
*/
export type Methods = MethodsMap & CompaniesMethods & ContactsMethods & DealsMethods & LeadsMethods & StatusesMethods & UsersMethods & {
readonly [Method.BATCH]: {
readonly type: unknown
readonly payload: BatchPayload<unknown>
readonly params: Commands
}
}
/**
* Retrieve specified method data
*/
export type MethodData<M extends Method> = ExtractValue<Methods, M>
/**
* Retrieve associated with specified method type
*/
export type MethodPayloadType<M extends Method> = MethodData<M>['type']
/**
* Retrieve specified method payload type
*/
export type MethodPayload<M extends Method> = MethodData<M>['payload']
/**
* Retrieve specified method params
*/
export type MethodParams<M extends Method> = MethodData<M>['params']