1
1
import { axios } from "@pipedream/platform" ;
2
+ import { LIMIT } from "./common/constants.mjs" ;
2
3
3
4
export default {
4
5
type : "app" ,
5
6
app : "_1crm" ,
6
7
propDefinitions : {
7
- accountId : {
8
- type : "string" ,
9
- label : "Account ID" ,
10
- description : "The ID of the account" ,
11
- } ,
12
- accountDetails : {
13
- type : "object" ,
14
- label : "Account Details" ,
15
- description : "Details of the account" ,
16
- } ,
17
- accountStatus : {
18
- type : "string" ,
19
- label : "Account Status" ,
20
- description : "Status of the account" ,
21
- } ,
22
- invoiceId : {
23
- type : "string" ,
24
- label : "Invoice ID" ,
25
- description : "The ID of the invoice" ,
26
- } ,
27
- invoiceDetails : {
28
- type : "object" ,
29
- label : "Invoice Details" ,
30
- description : "Details of the invoice" ,
31
- } ,
32
- invoiceStatus : {
33
- type : "string" ,
34
- label : "Invoice Status" ,
35
- description : "Status of the invoice" ,
36
- } ,
37
- leadId : {
38
- type : "string" ,
39
- label : "Lead ID" ,
40
- description : "The ID of the lead" ,
41
- } ,
42
- leadDetails : {
43
- type : "object" ,
44
- label : "Lead Details" ,
45
- description : "Details of the lead" ,
46
- } ,
47
- leadStatus : {
48
- type : "string" ,
49
- label : "Lead Status" ,
50
- description : "Status of the lead" ,
51
- } ,
52
- firstName : {
53
- type : "string" ,
54
- label : "First Name" ,
55
- description : "First name of the contact" ,
56
- } ,
57
- lastName : {
58
- type : "string" ,
59
- label : "Last Name" ,
60
- description : "Last name of the contact" ,
61
- } ,
62
- email : {
63
- type : "string" ,
64
- label : "Email" ,
65
- description : "Email of the contact" ,
66
- optional : true ,
67
- } ,
68
- address : {
69
- type : "string" ,
70
- label : "Address" ,
71
- description : "Address of the contact" ,
72
- optional : true ,
73
- } ,
74
- phoneNumber : {
75
- type : "string" ,
76
- label : "Phone Number" ,
77
- description : "Phone number of the contact" ,
78
- optional : true ,
79
- } ,
80
- contactId : {
8
+ recordId : {
81
9
type : "string" ,
82
10
label : "Contact ID" ,
83
11
description : "ID of the contact" ,
84
- } ,
85
- leadName : {
86
- type : "string" ,
87
- label : "Lead Name" ,
88
- description : "Name of the lead" ,
89
- } ,
90
- companyName : {
91
- type : "string" ,
92
- label : "Company Name" ,
93
- description : "Company name of the lead" ,
94
- optional : true ,
95
- } ,
96
- description : {
97
- type : "string" ,
98
- label : "Description" ,
99
- description : "Description of the lead" ,
100
- optional : true ,
101
- } ,
102
- accountName : {
103
- type : "string" ,
104
- label : "Account Name" ,
105
- description : "Name of the account" ,
106
- } ,
107
- contactDetails : {
108
- type : "object" ,
109
- label : "Contact Details" ,
110
- description : "Contact details of the customer" ,
111
- optional : true ,
12
+ async options ( {
13
+ page, model,
14
+ } ) {
15
+ const { records } = await this . listModuleRecords ( {
16
+ module : model ,
17
+ params : {
18
+ offset : LIMIT * page ,
19
+ limit : LIMIT ,
20
+ } ,
21
+ } ) ;
22
+
23
+ return records . map ( ( {
24
+ id : value , name : label ,
25
+ } ) => ( {
26
+ label,
27
+ value,
28
+ } ) ) ;
29
+ } ,
112
30
} ,
113
31
} ,
114
32
methods : {
@@ -124,182 +42,54 @@ export default {
124
42
_makeRequest ( {
125
43
$ = this , path, ...opts
126
44
} ) {
127
- const config = {
45
+ return axios ( $ , {
128
46
url : this . _baseUrl ( ) + path ,
129
47
auth : this . _auth ( ) ,
130
48
...opts ,
131
- } ;
132
- console . log ( "config: " , config ) ;
133
-
134
- return axios ( $ , config ) ;
135
- } ,
136
- getFields ( { module } ) {
137
- return this . _makeRequest ( {
138
- path : `/meta/${ module } ` ,
139
49
} ) ;
140
50
} ,
141
- createContact ( {
142
- firstName, lastName, email, address, phoneNumber,
143
- } ) {
51
+ getFields ( { module } ) {
144
52
return this . _makeRequest ( {
145
- method : "POST" ,
146
- path : "/data/Contacts" ,
147
- data : {
148
- first_name : firstName ,
149
- last_name : lastName ,
150
- email1 : email ,
151
- primary_address_street : address ,
152
- phone_work : phoneNumber ,
153
- } ,
53
+ path : `/meta/fields/${ module } ` ,
154
54
} ) ;
155
55
} ,
156
- updateContact ( {
157
- contactId , firstName , lastName , email , address , phoneNumber ,
56
+ listModuleRecords ( {
57
+ module , ... opts
158
58
} ) {
159
59
return this . _makeRequest ( {
160
- method : "PUT" ,
161
- path : `/data/Contacts/${ contactId } ` ,
162
- data : {
163
- first_name : firstName ,
164
- last_name : lastName ,
165
- email1 : email ,
166
- primary_address_street : address ,
167
- phone_work : phoneNumber ,
168
- } ,
60
+ path : `/data/${ module } ` ,
61
+ ...opts ,
169
62
} ) ;
170
63
} ,
171
- createLead ( {
172
- leadName , email , companyName , description ,
64
+ createModel ( {
65
+ model , ... opts
173
66
} ) {
174
67
return this . _makeRequest ( {
175
68
method : "POST" ,
176
- path : "/data/Leads" ,
177
- data : {
178
- name : leadName ,
179
- email1 : email ,
180
- account_name : companyName ,
181
- description,
182
- } ,
183
- } ) ;
184
- } ,
185
- updateLead ( {
186
- leadId, leadName, email, companyName, description,
187
- } ) {
188
- return this . _makeRequest ( {
189
- method : "PUT" ,
190
- path : `/data/Leads/${ leadId } ` ,
191
- data : {
192
- name : leadName ,
193
- email1 : email ,
194
- account_name : companyName ,
195
- description,
196
- } ,
69
+ path : `/data/${ model } ` ,
70
+ ...opts ,
197
71
} ) ;
198
72
} ,
199
- findAccount ( {
200
- accountName , contactDetails ,
73
+ updateModel ( {
74
+ updateId , model , ... opts
201
75
} ) {
202
76
return this . _makeRequest ( {
203
- method : "GET" ,
204
- path : "/data/Accounts" ,
205
- params : {
206
- name : accountName ,
207
- ...contactDetails ,
208
- } ,
77
+ method : "PATCH" ,
78
+ path : `/data/${ model } /${ updateId } ` ,
79
+ ...opts ,
209
80
} ) ;
210
81
} ,
211
- createWebhook ( {
212
- type, url, model, filters,
213
- } ) {
82
+ createWebhook ( opts = { } ) {
214
83
return this . _makeRequest ( {
215
84
method : "POST" ,
216
85
path : "/webhooks" ,
217
- data : {
218
- type,
219
- url,
220
- model,
221
- filters,
222
- } ,
86
+ ...opts ,
223
87
} ) ;
224
88
} ,
225
- updateWebhook ( {
226
- id, type, url, model, filters,
227
- } ) {
89
+ deleteWebhook ( webhookId ) {
228
90
return this . _makeRequest ( {
229
- method : "PUT" ,
230
- path : `/webhooks/${ id } ` ,
231
- data : {
232
- type,
233
- url,
234
- model,
235
- filters,
236
- } ,
237
- } ) ;
238
- } ,
239
- emitAccountEvent ( {
240
- accountDetails, accountStatus,
241
- } ) {
242
- return this . createWebhook ( {
243
- type : "create_update" ,
244
- url : "https://your-webhook-url.com" ,
245
- model : "Accounts" ,
246
- filters : {
247
- glue : "and" ,
248
- conditions : [
249
- {
250
- field : "details" ,
251
- value : accountDetails ,
252
- } ,
253
- {
254
- field : "status" ,
255
- value : accountStatus ,
256
- } ,
257
- ] ,
258
- } ,
259
- } ) ;
260
- } ,
261
- emitInvoiceEvent ( {
262
- invoiceDetails, invoiceStatus,
263
- } ) {
264
- return this . createWebhook ( {
265
- type : "create_update" ,
266
- url : "https://your-webhook-url.com" ,
267
- model : "Invoices" ,
268
- filters : {
269
- glue : "and" ,
270
- conditions : [
271
- {
272
- field : "details" ,
273
- value : invoiceDetails ,
274
- } ,
275
- {
276
- field : "status" ,
277
- value : invoiceStatus ,
278
- } ,
279
- ] ,
280
- } ,
281
- } ) ;
282
- } ,
283
- emitLeadEvent ( {
284
- leadDetails, leadStatus,
285
- } ) {
286
- return this . createWebhook ( {
287
- type : "create_update" ,
288
- url : "https://your-webhook-url.com" ,
289
- model : "Leads" ,
290
- filters : {
291
- glue : "and" ,
292
- conditions : [
293
- {
294
- field : "details" ,
295
- value : leadDetails ,
296
- } ,
297
- {
298
- field : "status" ,
299
- value : leadStatus ,
300
- } ,
301
- ] ,
302
- } ,
91
+ method : "DELETE" ,
92
+ path : `/webhooks/${ webhookId } ` ,
303
93
} ) ;
304
94
} ,
305
95
} ,
0 commit comments