Skip to content

Commit 3c98dd9

Browse files
committed
[Components] 1crm #12758
Sources - New Or Updated Account (Instant) - New Or Updated Invoice (Instant) - New Or Updated Lead (Instant) Actions - Create Contact - Update Contact - Create Load - Update Load
1 parent d9d0c3c commit 3c98dd9

File tree

17 files changed

+377
-780
lines changed

17 files changed

+377
-780
lines changed

components/_1crm/_1crm.app.mjs

+41-251
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,32 @@
11
import { axios } from "@pipedream/platform";
2+
import { LIMIT } from "./common/constants.mjs";
23

34
export default {
45
type: "app",
56
app: "_1crm",
67
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: {
819
type: "string",
8210
label: "Contact ID",
8311
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+
},
11230
},
11331
},
11432
methods: {
@@ -124,182 +42,54 @@ export default {
12442
_makeRequest({
12543
$ = this, path, ...opts
12644
}) {
127-
const config = {
45+
return axios($, {
12846
url: this._baseUrl() + path,
12947
auth: this._auth(),
13048
...opts,
131-
};
132-
console.log("config: ", config);
133-
134-
return axios($, config);
135-
},
136-
getFields({ module }) {
137-
return this._makeRequest({
138-
path: `/meta/${module}`,
13949
});
14050
},
141-
createContact({
142-
firstName, lastName, email, address, phoneNumber,
143-
}) {
51+
getFields({ module }) {
14452
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}`,
15454
});
15555
},
156-
updateContact({
157-
contactId, firstName, lastName, email, address, phoneNumber,
56+
listModuleRecords({
57+
module, ...opts
15858
}) {
15959
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,
16962
});
17063
},
171-
createLead({
172-
leadName, email, companyName, description,
64+
createModel({
65+
model, ...opts
17366
}) {
17467
return this._makeRequest({
17568
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,
19771
});
19872
},
199-
findAccount({
200-
accountName, contactDetails,
73+
updateModel({
74+
updateId, model, ...opts
20175
}) {
20276
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,
20980
});
21081
},
211-
createWebhook({
212-
type, url, model, filters,
213-
}) {
82+
createWebhook(opts = {}) {
21483
return this._makeRequest({
21584
method: "POST",
21685
path: "/webhooks",
217-
data: {
218-
type,
219-
url,
220-
model,
221-
filters,
222-
},
86+
...opts,
22387
});
22488
},
225-
updateWebhook({
226-
id, type, url, model, filters,
227-
}) {
89+
deleteWebhook(webhookId) {
22890
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}`,
30393
});
30494
},
30595
},

0 commit comments

Comments
 (0)