@agnocon/piece-bigin-by-zoho 0.1.6
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/LICENSE.MIT-AP +24 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/actions/create-call.d.ts +16 -0
- package/dist/lib/actions/create-call.d.ts.map +1 -0
- package/dist/lib/actions/create-call.js +162 -0
- package/dist/lib/actions/create-call.js.map +1 -0
- package/dist/lib/actions/create-company.d.ts +14 -0
- package/dist/lib/actions/create-company.d.ts.map +1 -0
- package/dist/lib/actions/create-company.js +108 -0
- package/dist/lib/actions/create-company.js.map +1 -0
- package/dist/lib/actions/create-contact.d.ts +18 -0
- package/dist/lib/actions/create-contact.d.ts.map +1 -0
- package/dist/lib/actions/create-contact.js +130 -0
- package/dist/lib/actions/create-contact.js.map +1 -0
- package/dist/lib/actions/create-event.d.ts +18 -0
- package/dist/lib/actions/create-event.d.ts.map +1 -0
- package/dist/lib/actions/create-event.js +360 -0
- package/dist/lib/actions/create-event.js.map +1 -0
- package/dist/lib/actions/create-pipeline-record.d.ts +16 -0
- package/dist/lib/actions/create-pipeline-record.d.ts.map +1 -0
- package/dist/lib/actions/create-pipeline-record.js +219 -0
- package/dist/lib/actions/create-pipeline-record.js.map +1 -0
- package/dist/lib/actions/create-task.d.ts +16 -0
- package/dist/lib/actions/create-task.d.ts.map +1 -0
- package/dist/lib/actions/create-task.js +380 -0
- package/dist/lib/actions/create-task.js.map +1 -0
- package/dist/lib/actions/search-company-record.d.ts +5 -0
- package/dist/lib/actions/search-company-record.d.ts.map +1 -0
- package/dist/lib/actions/search-company-record.js +58 -0
- package/dist/lib/actions/search-company-record.js.map +1 -0
- package/dist/lib/actions/search-contact-record.d.ts +5 -0
- package/dist/lib/actions/search-contact-record.d.ts.map +1 -0
- package/dist/lib/actions/search-contact-record.js +82 -0
- package/dist/lib/actions/search-contact-record.js.map +1 -0
- package/dist/lib/actions/search-pipeline-records.d.ts +5 -0
- package/dist/lib/actions/search-pipeline-records.d.ts.map +1 -0
- package/dist/lib/actions/search-pipeline-records.js +53 -0
- package/dist/lib/actions/search-pipeline-records.js.map +1 -0
- package/dist/lib/actions/search-product.d.ts +5 -0
- package/dist/lib/actions/search-product.d.ts.map +1 -0
- package/dist/lib/actions/search-product.js +60 -0
- package/dist/lib/actions/search-product.js.map +1 -0
- package/dist/lib/actions/search-user.d.ts +7 -0
- package/dist/lib/actions/search-user.d.ts.map +1 -0
- package/dist/lib/actions/search-user.js +75 -0
- package/dist/lib/actions/search-user.js.map +1 -0
- package/dist/lib/actions/update-company.d.ts +7 -0
- package/dist/lib/actions/update-company.d.ts.map +1 -0
- package/dist/lib/actions/update-company.js +224 -0
- package/dist/lib/actions/update-company.js.map +1 -0
- package/dist/lib/actions/update-contact.d.ts +7 -0
- package/dist/lib/actions/update-contact.d.ts.map +1 -0
- package/dist/lib/actions/update-contact.js +248 -0
- package/dist/lib/actions/update-contact.js.map +1 -0
- package/dist/lib/actions/update-event.d.ts +13 -0
- package/dist/lib/actions/update-event.d.ts.map +1 -0
- package/dist/lib/actions/update-event.js +466 -0
- package/dist/lib/actions/update-event.js.map +1 -0
- package/dist/lib/actions/update-pipeline-record.d.ts +14 -0
- package/dist/lib/actions/update-pipeline-record.d.ts.map +1 -0
- package/dist/lib/actions/update-pipeline-record.js +205 -0
- package/dist/lib/actions/update-pipeline-record.js.map +1 -0
- package/dist/lib/actions/update-task.d.ts +13 -0
- package/dist/lib/actions/update-task.d.ts.map +1 -0
- package/dist/lib/actions/update-task.js +449 -0
- package/dist/lib/actions/update-task.js.map +1 -0
- package/dist/lib/auth.d.ts +2 -0
- package/dist/lib/auth.d.ts.map +1 -0
- package/dist/lib/auth.js +59 -0
- package/dist/lib/auth.js.map +1 -0
- package/dist/lib/common/constants.d.ts +23 -0
- package/dist/lib/common/constants.d.ts.map +1 -0
- package/dist/lib/common/constants.js +72 -0
- package/dist/lib/common/constants.js.map +1 -0
- package/dist/lib/common/helpers.d.ts +11 -0
- package/dist/lib/common/helpers.d.ts.map +1 -0
- package/dist/lib/common/helpers.js +40 -0
- package/dist/lib/common/helpers.js.map +1 -0
- package/dist/lib/common/props.d.ts +10 -0
- package/dist/lib/common/props.d.ts.map +1 -0
- package/dist/lib/common/props.js +217 -0
- package/dist/lib/common/props.js.map +1 -0
- package/dist/lib/common/request.d.ts +35 -0
- package/dist/lib/common/request.d.ts.map +1 -0
- package/dist/lib/common/request.js +226 -0
- package/dist/lib/common/request.js.map +1 -0
- package/dist/lib/triggers/company-updated.d.ts +3 -0
- package/dist/lib/triggers/company-updated.d.ts.map +1 -0
- package/dist/lib/triggers/company-updated.js +66 -0
- package/dist/lib/triggers/company-updated.js.map +1 -0
- package/dist/lib/triggers/contact-updated.d.ts +3 -0
- package/dist/lib/triggers/contact-updated.d.ts.map +1 -0
- package/dist/lib/triggers/contact-updated.js +66 -0
- package/dist/lib/triggers/contact-updated.js.map +1 -0
- package/dist/lib/triggers/new-call-created.d.ts +3 -0
- package/dist/lib/triggers/new-call-created.d.ts.map +1 -0
- package/dist/lib/triggers/new-call-created.js +66 -0
- package/dist/lib/triggers/new-call-created.js.map +1 -0
- package/dist/lib/triggers/new-company-created.d.ts +3 -0
- package/dist/lib/triggers/new-company-created.d.ts.map +1 -0
- package/dist/lib/triggers/new-company-created.js +66 -0
- package/dist/lib/triggers/new-company-created.js.map +1 -0
- package/dist/lib/triggers/new-contact-created.d.ts +3 -0
- package/dist/lib/triggers/new-contact-created.d.ts.map +1 -0
- package/dist/lib/triggers/new-contact-created.js +75 -0
- package/dist/lib/triggers/new-contact-created.js.map +1 -0
- package/dist/lib/triggers/new-event-created.d.ts +3 -0
- package/dist/lib/triggers/new-event-created.d.ts.map +1 -0
- package/dist/lib/triggers/new-event-created.js +66 -0
- package/dist/lib/triggers/new-event-created.js.map +1 -0
- package/dist/lib/triggers/new-pipeline-record.d.ts +3 -0
- package/dist/lib/triggers/new-pipeline-record.d.ts.map +1 -0
- package/dist/lib/triggers/new-pipeline-record.js +66 -0
- package/dist/lib/triggers/new-pipeline-record.js.map +1 -0
- package/dist/lib/triggers/new-task-created.d.ts +3 -0
- package/dist/lib/triggers/new-task-created.d.ts.map +1 -0
- package/dist/lib/triggers/new-task-created.js +66 -0
- package/dist/lib/triggers/new-task-created.js.map +1 -0
- package/dist/lib/triggers/pipeline-record-updated.d.ts +3 -0
- package/dist/lib/triggers/pipeline-record-updated.d.ts.map +1 -0
- package/dist/lib/triggers/pipeline-record-updated.js +66 -0
- package/dist/lib/triggers/pipeline-record-updated.js.map +1 -0
- package/package.json +46 -0
- package/src/index.ts +72 -0
- package/src/lib/actions/create-call.ts +168 -0
- package/src/lib/actions/create-company.ts +124 -0
- package/src/lib/actions/create-contact.ts +151 -0
- package/src/lib/actions/create-event.ts +399 -0
- package/src/lib/actions/create-pipeline-record.ts +255 -0
- package/src/lib/actions/create-task.ts +426 -0
- package/src/lib/actions/search-company-record.ts +57 -0
- package/src/lib/actions/search-contact-record.ts +79 -0
- package/src/lib/actions/search-pipeline-records.ts +52 -0
- package/src/lib/actions/search-product.ts +60 -0
- package/src/lib/actions/search-user.ts +70 -0
- package/src/lib/actions/update-company.ts +235 -0
- package/src/lib/actions/update-contact.ts +261 -0
- package/src/lib/actions/update-event.ts +528 -0
- package/src/lib/actions/update-pipeline-record.ts +235 -0
- package/src/lib/actions/update-task.ts +499 -0
- package/src/lib/auth.ts +57 -0
- package/src/lib/common/constants.ts +68 -0
- package/src/lib/common/helpers.ts +46 -0
- package/src/lib/common/props.ts +270 -0
- package/src/lib/common/request.ts +285 -0
- package/src/lib/triggers/company-updated.ts +69 -0
- package/src/lib/triggers/contact-updated.ts +65 -0
- package/src/lib/triggers/new-call-created.ts +69 -0
- package/src/lib/triggers/new-company-created.ts +69 -0
- package/src/lib/triggers/new-contact-created.ts +75 -0
- package/src/lib/triggers/new-event-created.ts +69 -0
- package/src/lib/triggers/new-pipeline-record.ts +69 -0
- package/src/lib/triggers/new-task-created.ts +69 -0
- package/src/lib/triggers/pipeline-record-updated.ts +69 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { biginAuth } from '../auth';
|
|
2
|
+
import {
|
|
3
|
+
createAction,
|
|
4
|
+
Property,
|
|
5
|
+
InputPropertyMap,
|
|
6
|
+
PropertyContext,
|
|
7
|
+
} from '@agnocon/pieces-framework';
|
|
8
|
+
import { companyDropdown, tagsDropdown, usersDropdown } from '../common/props';
|
|
9
|
+
import { biginApiService } from '../common/request';
|
|
10
|
+
import { handleDropdownError } from '../common/helpers';
|
|
11
|
+
|
|
12
|
+
export const updateContact = createAction({
|
|
13
|
+
auth: biginAuth,
|
|
14
|
+
name: 'updateContact',
|
|
15
|
+
displayName: 'Update Contact',
|
|
16
|
+
description: 'Select and update an existing Contact record.',
|
|
17
|
+
audience: 'both',
|
|
18
|
+
aiMetadata: { description: 'Updates an existing contact (person) record in Bigin CRM, identified by selecting the contact; its current fields are prepopulated and any you set are overwritten (owner, associated company, tags, and module-defined fields). Use to modify a person who already exists. Idempotent: re-sending the same field values leaves the record in the same state.', idempotent: true },
|
|
19
|
+
|
|
20
|
+
props: {
|
|
21
|
+
contactId: Property.Dropdown({
|
|
22
|
+
auth: biginAuth,
|
|
23
|
+
displayName: 'Select Contact',
|
|
24
|
+
description: 'Choose a contact to update',
|
|
25
|
+
required: true,
|
|
26
|
+
refreshers: ['auth'],
|
|
27
|
+
options: async ({ auth }) => {
|
|
28
|
+
if (!auth) return handleDropdownError('Please connect first');
|
|
29
|
+
const resp = await biginApiService.fetchContacts(
|
|
30
|
+
auth.access_token,
|
|
31
|
+
auth.data['api_domain']
|
|
32
|
+
);
|
|
33
|
+
return {
|
|
34
|
+
options: resp.data.map((c: any) => ({
|
|
35
|
+
label: `${c.First_Name ?? ''} ${c.Last_Name}`.trim(),
|
|
36
|
+
value: JSON.stringify(c),
|
|
37
|
+
})),
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
|
|
42
|
+
contactDetails: Property.DynamicProperties({
|
|
43
|
+
auth: biginAuth,
|
|
44
|
+
displayName: 'Contact Fields',
|
|
45
|
+
description: 'Edit any of these fields',
|
|
46
|
+
refreshers: ['contactId', 'auth'],
|
|
47
|
+
required: true,
|
|
48
|
+
props: async (
|
|
49
|
+
{ contactId, auth }: any,
|
|
50
|
+
): Promise<InputPropertyMap> => {
|
|
51
|
+
if (!contactId) return {};
|
|
52
|
+
const contact = JSON.parse(contactId);
|
|
53
|
+
const { access_token, data } = auth;
|
|
54
|
+
const api_domain = data['api_domain'];
|
|
55
|
+
|
|
56
|
+
const [fieldsResp, usersResp, companiesResp] = await Promise.all([
|
|
57
|
+
biginApiService.fetchModuleFields(access_token, api_domain, 'Contacts'),
|
|
58
|
+
biginApiService.fetchUsers(access_token, api_domain),
|
|
59
|
+
biginApiService.fetchCompanies(access_token, api_domain),
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
const usersOptions = (usersResp.users || []).map((u: any) => ({
|
|
63
|
+
label: `${u.first_name ?? ''} ${u.last_name ?? ''}`.trim(),
|
|
64
|
+
value: u.id,
|
|
65
|
+
}));
|
|
66
|
+
const companyOptions = (companiesResp.data || []).map((c: any) => ({
|
|
67
|
+
label: c.Account_Name,
|
|
68
|
+
value: c.id,
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
const props: InputPropertyMap = {};
|
|
72
|
+
|
|
73
|
+
const fields = (fieldsResp.fields || []) as any[];
|
|
74
|
+
for (const f of fields) {
|
|
75
|
+
const apiName = f.api_name as string;
|
|
76
|
+
|
|
77
|
+
if (f.read_only || f.field_read_only) continue;
|
|
78
|
+
if (!f.view_type || f.view_type.edit !== true) continue;
|
|
79
|
+
|
|
80
|
+
if (apiName === 'Tag') continue;
|
|
81
|
+
if (apiName === 'id') continue;
|
|
82
|
+
|
|
83
|
+
let defaultValue: any = contact[apiName] ?? undefined;
|
|
84
|
+
if (apiName === 'Owner') defaultValue = contact.Owner?.id;
|
|
85
|
+
if (apiName === 'Account_Name') defaultValue = contact.Account_Name?.id;
|
|
86
|
+
|
|
87
|
+
switch ((f.data_type as string)?.toLowerCase()) {
|
|
88
|
+
case 'picklist': {
|
|
89
|
+
const options = (f.pick_list_values || []).map((pl: any) => ({
|
|
90
|
+
label: pl.display_value,
|
|
91
|
+
value: pl.actual_value,
|
|
92
|
+
}));
|
|
93
|
+
props[apiName] = Property.StaticDropdown({
|
|
94
|
+
displayName: f.display_label || f.field_label || apiName,
|
|
95
|
+
description: f.tooltip || undefined,
|
|
96
|
+
required: false,
|
|
97
|
+
defaultValue,
|
|
98
|
+
options: { options },
|
|
99
|
+
});
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case 'multiselectpicklist': {
|
|
103
|
+
const options = (f.pick_list_values || []).map((pl: any) => ({
|
|
104
|
+
label: pl.display_value,
|
|
105
|
+
value: pl.actual_value,
|
|
106
|
+
}));
|
|
107
|
+
props[apiName] = Property.StaticMultiSelectDropdown({
|
|
108
|
+
displayName: f.display_label || f.field_label || apiName,
|
|
109
|
+
description: f.tooltip || undefined,
|
|
110
|
+
required: false,
|
|
111
|
+
defaultValue,
|
|
112
|
+
options: { options },
|
|
113
|
+
});
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
case 'boolean': {
|
|
117
|
+
props[apiName] = Property.Checkbox({
|
|
118
|
+
displayName: f.display_label || f.field_label || apiName,
|
|
119
|
+
description: f.tooltip || undefined,
|
|
120
|
+
required: false,
|
|
121
|
+
defaultValue: Boolean(defaultValue),
|
|
122
|
+
});
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
case 'date': {
|
|
126
|
+
props[apiName] = Property.ShortText({
|
|
127
|
+
displayName: f.display_label || f.field_label || apiName,
|
|
128
|
+
description: f.tooltip || undefined,
|
|
129
|
+
required: false,
|
|
130
|
+
defaultValue,
|
|
131
|
+
});
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
case 'datetime': {
|
|
135
|
+
props[apiName] = Property.DateTime({
|
|
136
|
+
displayName: f.display_label || f.field_label || apiName,
|
|
137
|
+
description: f.tooltip || undefined,
|
|
138
|
+
required: false,
|
|
139
|
+
defaultValue,
|
|
140
|
+
});
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
case 'integer':
|
|
144
|
+
case 'long':
|
|
145
|
+
case 'double':
|
|
146
|
+
case 'decimal':
|
|
147
|
+
case 'currency':
|
|
148
|
+
case 'percent': {
|
|
149
|
+
props[apiName] = Property.Number({
|
|
150
|
+
displayName: f.display_label || f.field_label || apiName,
|
|
151
|
+
description: f.tooltip || undefined,
|
|
152
|
+
required: false,
|
|
153
|
+
defaultValue,
|
|
154
|
+
});
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
default: {
|
|
158
|
+
if (apiName === 'Owner') {
|
|
159
|
+
props[apiName] = Property.StaticDropdown({
|
|
160
|
+
displayName: 'Owner',
|
|
161
|
+
description: f.tooltip || undefined,
|
|
162
|
+
required: false,
|
|
163
|
+
defaultValue,
|
|
164
|
+
options: { options: usersOptions },
|
|
165
|
+
});
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
if (apiName === 'Account_Name') {
|
|
169
|
+
props[apiName] = Property.StaticDropdown({
|
|
170
|
+
displayName: 'Company',
|
|
171
|
+
description: f.tooltip || undefined,
|
|
172
|
+
required: false,
|
|
173
|
+
defaultValue,
|
|
174
|
+
options: { options: companyOptions },
|
|
175
|
+
});
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
if (apiName === 'Description') {
|
|
179
|
+
props[apiName] = Property.LongText({
|
|
180
|
+
displayName: 'Description',
|
|
181
|
+
description: f.tooltip || undefined,
|
|
182
|
+
required: false,
|
|
183
|
+
defaultValue,
|
|
184
|
+
});
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
props[apiName] = Property.ShortText({
|
|
189
|
+
displayName: f.display_label || f.field_label || apiName,
|
|
190
|
+
description: f.tooltip || undefined,
|
|
191
|
+
required: false,
|
|
192
|
+
defaultValue: typeof defaultValue === 'string' ? defaultValue : undefined,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return props;
|
|
199
|
+
},
|
|
200
|
+
}),
|
|
201
|
+
|
|
202
|
+
accountName: companyDropdown,
|
|
203
|
+
tag: tagsDropdown('Contacts'),
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
async run(context) {
|
|
207
|
+
try {
|
|
208
|
+
const { contactDetails, contactId, accountName, tag } = context.propsValue;
|
|
209
|
+
|
|
210
|
+
const record: Record<string, any> = { id: JSON.parse(contactId).id };
|
|
211
|
+
|
|
212
|
+
if (contactDetails && typeof contactDetails === 'object') {
|
|
213
|
+
for (const [apiName, value] of Object.entries(contactDetails)) {
|
|
214
|
+
if (
|
|
215
|
+
value === undefined ||
|
|
216
|
+
value === null ||
|
|
217
|
+
(typeof value === 'string' && value.trim() === '') ||
|
|
218
|
+
(Array.isArray(value) && (value as any[]).length === 0)
|
|
219
|
+
) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (apiName === 'Owner' || apiName === 'Account_Name') {
|
|
224
|
+
record[apiName] = { id: value };
|
|
225
|
+
} else if (apiName === 'Tag') {
|
|
226
|
+
record['Tag'] = (value as any[]).map((t: any) => ({ name: t }));
|
|
227
|
+
} else {
|
|
228
|
+
record[apiName] = value;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (accountName) {
|
|
234
|
+
record['Account_Name'] = { id: accountName };
|
|
235
|
+
}
|
|
236
|
+
if (tag && Array.isArray(tag) && tag.length > 0) {
|
|
237
|
+
record['Tag'] = tag.map((t: any) => ({ name: t }));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const payload = { data: [record] };
|
|
241
|
+
|
|
242
|
+
const resp = await biginApiService.updateContact(
|
|
243
|
+
context.auth.access_token,
|
|
244
|
+
context.auth.data['api_domain'],
|
|
245
|
+
payload
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
return {
|
|
249
|
+
message: 'Contact updated successfully',
|
|
250
|
+
data: resp.data[0],
|
|
251
|
+
};
|
|
252
|
+
} catch (error: any) {
|
|
253
|
+
console.error('Error updating contact:', error);
|
|
254
|
+
throw new Error(
|
|
255
|
+
error instanceof Error
|
|
256
|
+
? `Failed to update contact: ${error.message}`
|
|
257
|
+
: 'Failed to update contact due to an unknown error'
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
});
|