@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,270 @@
|
|
|
1
|
+
import { Property } from "@agnocon/pieces-framework";
|
|
2
|
+
import { biginApiService } from "./request";
|
|
3
|
+
import { handleDropdownError } from "./helpers";
|
|
4
|
+
import { biginAuth } from '../auth';
|
|
5
|
+
|
|
6
|
+
export const usersDropdown = Property.Dropdown({
|
|
7
|
+
auth: biginAuth,
|
|
8
|
+
displayName: 'Owner',
|
|
9
|
+
description: 'Select the owner to which the record will be assigned.',
|
|
10
|
+
required: false,
|
|
11
|
+
refreshers: ['auth'],
|
|
12
|
+
options: async ({ auth }: any) => {
|
|
13
|
+
if (!auth)
|
|
14
|
+
return handleDropdownError('Please connect your account first');
|
|
15
|
+
|
|
16
|
+
const { api_domain } = auth;
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const response = await biginApiService.fetchUsers(
|
|
20
|
+
auth.access_token,
|
|
21
|
+
api_domain
|
|
22
|
+
);
|
|
23
|
+
const users = Array.isArray(response?.users) ? response.users : [];
|
|
24
|
+
if (users.length === 0) {
|
|
25
|
+
return handleDropdownError('No users found');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const options = users.map((user: any) => {
|
|
29
|
+
const fullName =
|
|
30
|
+
(typeof user.full_name === 'string' && user.full_name.trim() !== ''
|
|
31
|
+
? user.full_name
|
|
32
|
+
: [user.first_name, user.last_name]
|
|
33
|
+
.filter((p: any) => typeof p === 'string' && p.trim() !== '')
|
|
34
|
+
.join(' ')) || user.email || user.id;
|
|
35
|
+
return {
|
|
36
|
+
label: fullName,
|
|
37
|
+
value: user.id,
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
disabled: false,
|
|
43
|
+
options,
|
|
44
|
+
};
|
|
45
|
+
} catch (error) {
|
|
46
|
+
return handleDropdownError('Failed to load users');
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export const companyDropdown = Property.Dropdown({
|
|
52
|
+
auth: biginAuth,
|
|
53
|
+
displayName: 'Company',
|
|
54
|
+
description:
|
|
55
|
+
'The ID of the company to which the record will be associated. If not provided, the record will not be associated with any company.',
|
|
56
|
+
required: false,
|
|
57
|
+
refreshers: ['auth'],
|
|
58
|
+
options: async ({ auth }: any) => {
|
|
59
|
+
if (!auth) return handleDropdownError('Please Connect your account first');
|
|
60
|
+
const resp = await biginApiService.fetchCompanies(
|
|
61
|
+
auth.access_token,
|
|
62
|
+
auth.api_domain
|
|
63
|
+
);
|
|
64
|
+
return {
|
|
65
|
+
options: resp.data.map((a: any) => ({
|
|
66
|
+
label: a.Account_Name,
|
|
67
|
+
value: a.id,
|
|
68
|
+
})),
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export const contactsDropdown = Property.Dropdown({
|
|
74
|
+
auth: biginAuth,
|
|
75
|
+
displayName: 'Contacts',
|
|
76
|
+
description:
|
|
77
|
+
'The ID of the contact to which the record will be associated. If not provided, the record will not be associated with any contact.',
|
|
78
|
+
required: false,
|
|
79
|
+
refreshers: ['auth'],
|
|
80
|
+
options: async ({ auth }: any) => {
|
|
81
|
+
if (!auth) return handleDropdownError('Please Connect your account first');
|
|
82
|
+
const resp = await biginApiService.fetchContacts(
|
|
83
|
+
auth.access_token,
|
|
84
|
+
auth.api_domain
|
|
85
|
+
);
|
|
86
|
+
return {
|
|
87
|
+
options: resp.data.map((a: any) => ({
|
|
88
|
+
label: a.First_Name + ' ' + a.Last_Name,
|
|
89
|
+
value: a.id,
|
|
90
|
+
})),
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
export const multiContactsDropdown = Property.MultiSelectDropdown({
|
|
96
|
+
auth: biginAuth,
|
|
97
|
+
displayName: 'Secondary Contacts',
|
|
98
|
+
description:
|
|
99
|
+
'Provide a list of additional contacts associated with the record',
|
|
100
|
+
required: false,
|
|
101
|
+
refreshers: ['auth'],
|
|
102
|
+
options: async ({ auth }: any) => {
|
|
103
|
+
if (!auth) return handleDropdownError('Please Connect your account first');
|
|
104
|
+
const resp = await biginApiService.fetchContacts(
|
|
105
|
+
auth.access_token,
|
|
106
|
+
auth.api_domain
|
|
107
|
+
);
|
|
108
|
+
return {
|
|
109
|
+
options: resp.data.map((a: any) => ({
|
|
110
|
+
label: a.First_Name + ' ' + a.Last_Name,
|
|
111
|
+
value: a.id,
|
|
112
|
+
})),
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
export const pipelineRecordsDropdown = Property.Dropdown({
|
|
118
|
+
auth: biginAuth,
|
|
119
|
+
displayName: 'Pipeline Record',
|
|
120
|
+
description:
|
|
121
|
+
'Select a pipeline record',
|
|
122
|
+
required: false,
|
|
123
|
+
refreshers: ['auth'],
|
|
124
|
+
options: async ({ auth }: any) => {
|
|
125
|
+
if (!auth) return handleDropdownError('Please Connect your account first');
|
|
126
|
+
const resp = await biginApiService.fetchPipelinesRecords(
|
|
127
|
+
auth.access_token,
|
|
128
|
+
auth.api_domain
|
|
129
|
+
);
|
|
130
|
+
return {
|
|
131
|
+
options: resp.data.map((a: any) => ({
|
|
132
|
+
label: a.Deal_Name,
|
|
133
|
+
value: JSON.stringify(a),
|
|
134
|
+
})),
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
export const layoutsDropdown = (displayName: string, description: string, module_name: string) => Property.Dropdown({
|
|
140
|
+
auth: biginAuth,
|
|
141
|
+
displayName,
|
|
142
|
+
description,
|
|
143
|
+
required: false,
|
|
144
|
+
refreshers: ['auth'],
|
|
145
|
+
options: async ({ auth }: any) => {
|
|
146
|
+
if (!auth) return handleDropdownError('Please Connect your account first');
|
|
147
|
+
const resp = await biginApiService.fetchLayouts(
|
|
148
|
+
auth.access_token,
|
|
149
|
+
auth.api_domain,
|
|
150
|
+
module_name
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
options: resp.layouts.map((a: any) => ({
|
|
155
|
+
label: a.name,
|
|
156
|
+
value: JSON.stringify(a),
|
|
157
|
+
})),
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
export const productsDropdown = Property.MultiSelectDropdown({
|
|
163
|
+
auth: biginAuth,
|
|
164
|
+
displayName: 'Associated Products',
|
|
165
|
+
description:
|
|
166
|
+
'Provide a list of products associated with the record',
|
|
167
|
+
required: false,
|
|
168
|
+
refreshers: ['auth'],
|
|
169
|
+
options: async ({ auth }: any) => {
|
|
170
|
+
if (!auth) return handleDropdownError('Please Connect your account first');
|
|
171
|
+
const resp = await biginApiService.fetchProducts(
|
|
172
|
+
auth.access_token,
|
|
173
|
+
auth.api_domain
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
if (!Array.isArray(resp.data) || resp.data.length === 0) {
|
|
177
|
+
return handleDropdownError('No products found. Please add products first.');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
options: resp.data.map((a: any) => ({
|
|
182
|
+
label: a.Product_Name,
|
|
183
|
+
value: JSON.stringify(a),
|
|
184
|
+
})),
|
|
185
|
+
};
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
export const tagsDropdown = (module: string, defaultValue?: string[]) => Property.MultiSelectDropdown({
|
|
190
|
+
auth: biginAuth,
|
|
191
|
+
displayName: 'Tags',
|
|
192
|
+
description: `Select tags to associate with this module, "${module}".`,
|
|
193
|
+
required: false,
|
|
194
|
+
refreshers: ['auth'],
|
|
195
|
+
defaultValue: defaultValue || [],
|
|
196
|
+
options: async ({ auth }: any) => {
|
|
197
|
+
if (!auth) return handleDropdownError('Please Connect your account first');
|
|
198
|
+
try {
|
|
199
|
+
const resp = await biginApiService.fetchTags(
|
|
200
|
+
auth.access_token,
|
|
201
|
+
auth.api_domain,
|
|
202
|
+
module
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const tags = Array.isArray(resp?.tags) ? resp.tags : [];
|
|
206
|
+
if (tags.length === 0) {
|
|
207
|
+
return handleDropdownError('No tags found. Please add tags first.');
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
options: tags.map((a: any) => ({
|
|
212
|
+
label: a.name,
|
|
213
|
+
value: a.name,
|
|
214
|
+
})),
|
|
215
|
+
};
|
|
216
|
+
} catch (e) {
|
|
217
|
+
return handleDropdownError('Failed to load tags');
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
export const SubPipelineorStageDropdown = (
|
|
223
|
+
displayName: string,
|
|
224
|
+
description: string,
|
|
225
|
+
field_label: string,
|
|
226
|
+
defaultValue?: string
|
|
227
|
+
) =>
|
|
228
|
+
Property.Dropdown({
|
|
229
|
+
auth: biginAuth,
|
|
230
|
+
displayName,
|
|
231
|
+
description,
|
|
232
|
+
required: true,
|
|
233
|
+
refreshers: ['auth', 'pipeline'],
|
|
234
|
+
defaultValue,
|
|
235
|
+
options: async ({ auth, pipeline }) => {
|
|
236
|
+
if (!auth)
|
|
237
|
+
return handleDropdownError('Please connect your account first');
|
|
238
|
+
if (!pipeline)
|
|
239
|
+
return handleDropdownError('Please select a Pipeline first');
|
|
240
|
+
|
|
241
|
+
const { access_token, api_domain } = auth as any;
|
|
242
|
+
|
|
243
|
+
const response = await biginApiService.fetchLayouts(
|
|
244
|
+
access_token,
|
|
245
|
+
api_domain,
|
|
246
|
+
'Pipelines'
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
const layouts = response?.layouts || [];
|
|
250
|
+
|
|
251
|
+
const parsedPipeline = JSON.parse(pipeline as string);
|
|
252
|
+
|
|
253
|
+
const layout = layouts.find((l: any) => l.id === parsedPipeline.id);
|
|
254
|
+
|
|
255
|
+
const PipelineInfo = layout.sections.find(
|
|
256
|
+
(s: any) => s.api_name === 'Pipeline Information'
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
const stageField = PipelineInfo?.fields.find(
|
|
260
|
+
(f: any) => f.field_label === field_label
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
options: stageField.pick_list_values.map((pl: any) => ({
|
|
265
|
+
label: pl.display_value,
|
|
266
|
+
value: pl.actual_value,
|
|
267
|
+
})),
|
|
268
|
+
};
|
|
269
|
+
},
|
|
270
|
+
});
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { HttpMethod, httpClient } from '@agnocon/pieces-common';
|
|
2
|
+
import { API_ENDPOINTS } from './constants';
|
|
3
|
+
|
|
4
|
+
async function fireHttpRequest({
|
|
5
|
+
method,
|
|
6
|
+
path,
|
|
7
|
+
body,
|
|
8
|
+
access_token
|
|
9
|
+
}: {
|
|
10
|
+
method: HttpMethod;
|
|
11
|
+
path: string;
|
|
12
|
+
access_token: string;
|
|
13
|
+
body?: unknown;
|
|
14
|
+
}) {
|
|
15
|
+
return await httpClient
|
|
16
|
+
.sendRequest({
|
|
17
|
+
method,
|
|
18
|
+
url: path,
|
|
19
|
+
headers: {
|
|
20
|
+
Accept: 'application/json',
|
|
21
|
+
Authorization: `Zoho-oauthtoken ${access_token}`,
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
},
|
|
24
|
+
body,
|
|
25
|
+
})
|
|
26
|
+
.then((res) => res.body)
|
|
27
|
+
.catch((err) => {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`Error in request to ${path}: ${err.message || JSON.stringify(err)}`
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const biginApiService = {
|
|
35
|
+
createWebhook: async (
|
|
36
|
+
access_token: string,
|
|
37
|
+
payload: any,
|
|
38
|
+
api_domain: string
|
|
39
|
+
) => {
|
|
40
|
+
const res = await fireHttpRequest({
|
|
41
|
+
method: HttpMethod.POST,
|
|
42
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.WEBHOOKS}`,
|
|
43
|
+
body: payload,
|
|
44
|
+
access_token,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return res;
|
|
48
|
+
},
|
|
49
|
+
deleteWebhook: async (
|
|
50
|
+
access_token: string,
|
|
51
|
+
api_domain: string,
|
|
52
|
+
channel_id: string
|
|
53
|
+
) => {
|
|
54
|
+
return fireHttpRequest({
|
|
55
|
+
method: HttpMethod.DELETE,
|
|
56
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.WEBHOOKS}?channel_ids=${channel_id}`,
|
|
57
|
+
access_token,
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
fetchUsers: async (
|
|
61
|
+
access_token: string,
|
|
62
|
+
api_domain: string,
|
|
63
|
+
params?: { type?: string; page?: number; per_page?: number }
|
|
64
|
+
) => {
|
|
65
|
+
const qs = new URLSearchParams();
|
|
66
|
+
if (params?.type) qs.set('type', params.type);
|
|
67
|
+
if (params?.page) qs.set('page', String(params.page));
|
|
68
|
+
if (params?.per_page) qs.set('per_page', String(params.per_page));
|
|
69
|
+
const query = qs.toString();
|
|
70
|
+
return fireHttpRequest({
|
|
71
|
+
method: HttpMethod.GET,
|
|
72
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.USERS}${query ? `?${query}` : ''}`,
|
|
73
|
+
access_token,
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
createCompany: async (
|
|
77
|
+
access_token: string,
|
|
78
|
+
api_domain: string,
|
|
79
|
+
body: any
|
|
80
|
+
) => {
|
|
81
|
+
return fireHttpRequest({
|
|
82
|
+
method: HttpMethod.POST,
|
|
83
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.COMPANIES}`,
|
|
84
|
+
access_token,
|
|
85
|
+
body,
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
updateCompany: async (
|
|
89
|
+
access_token: string,
|
|
90
|
+
api_domain: string,
|
|
91
|
+
body: any
|
|
92
|
+
) => {
|
|
93
|
+
return fireHttpRequest({
|
|
94
|
+
method: HttpMethod.PUT,
|
|
95
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.COMPANIES}`,
|
|
96
|
+
access_token,
|
|
97
|
+
body,
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
fetchCompanies: async (access_token: string, api_domain: string) => {
|
|
101
|
+
return fireHttpRequest({
|
|
102
|
+
method: HttpMethod.GET,
|
|
103
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.COMPANIES}?fields=Owner,Account_Name,Phone,Website,Tag,Description,Billing_Street,Billing_State,Billing_Country,Billing_Code`,
|
|
104
|
+
access_token,
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
createContact: async (
|
|
108
|
+
access_token: string,
|
|
109
|
+
api_domain: string,
|
|
110
|
+
body: any
|
|
111
|
+
) => {
|
|
112
|
+
return fireHttpRequest({
|
|
113
|
+
method: HttpMethod.POST,
|
|
114
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.CONTACTS}`,
|
|
115
|
+
access_token,
|
|
116
|
+
body,
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
updateContact: async (
|
|
120
|
+
access_token: string,
|
|
121
|
+
api_domain: string,
|
|
122
|
+
body: any
|
|
123
|
+
) => {
|
|
124
|
+
return fireHttpRequest({
|
|
125
|
+
method: HttpMethod.PUT,
|
|
126
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.CONTACTS}`,
|
|
127
|
+
access_token,
|
|
128
|
+
body,
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
fetchTags: async (
|
|
132
|
+
access_token: string,
|
|
133
|
+
api_domain: string,
|
|
134
|
+
module: string
|
|
135
|
+
) => {
|
|
136
|
+
return fireHttpRequest({
|
|
137
|
+
method: HttpMethod.GET,
|
|
138
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.TAGS}?module=${module}`,
|
|
139
|
+
access_token,
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
fetchContacts: async (access_token: string, api_domain: string) => {
|
|
143
|
+
return fireHttpRequest({
|
|
144
|
+
method: HttpMethod.GET,
|
|
145
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.CONTACTS}?fields=First_Name,Last_Name,Title,Email,Mobile,Email_Opt_Out,Owner,Account_Name,Tag,Description,Mailing_Street,Mailing_City,Mailing_State,Mailing_Country,Mailing_Zip`,
|
|
146
|
+
access_token,
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
fetchPipelinesRecords: async (access_token: string, api_domain: string) => {
|
|
150
|
+
return fireHttpRequest({
|
|
151
|
+
method: HttpMethod.GET,
|
|
152
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.PIPELINES}?fields=Deal_Name,Stage,Owner,Description,Contact_Name,Account_Name,Amount,Closing_Date,Sub_Pipeline,Tag`,
|
|
153
|
+
access_token,
|
|
154
|
+
});
|
|
155
|
+
},
|
|
156
|
+
createPipelineRecord: async (
|
|
157
|
+
access_token: string,
|
|
158
|
+
api_domain: string,
|
|
159
|
+
body: any
|
|
160
|
+
) => {
|
|
161
|
+
return fireHttpRequest({
|
|
162
|
+
method: HttpMethod.POST,
|
|
163
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.PIPELINES}`,
|
|
164
|
+
access_token,
|
|
165
|
+
body,
|
|
166
|
+
});
|
|
167
|
+
},
|
|
168
|
+
updatePipelineRecord: async (
|
|
169
|
+
access_token: string,
|
|
170
|
+
api_domain: string,
|
|
171
|
+
body: any
|
|
172
|
+
) => {
|
|
173
|
+
return fireHttpRequest({
|
|
174
|
+
method: HttpMethod.PUT,
|
|
175
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.PIPELINES}`,
|
|
176
|
+
access_token,
|
|
177
|
+
body,
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
fetchProducts: async (access_token: string, api_domain: string) => {
|
|
181
|
+
return fireHttpRequest({
|
|
182
|
+
method: HttpMethod.GET,
|
|
183
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.PRODUCTS}?fields=Product_Name,Owner,Product_Code,Product_Category,Unit_Price,Description,Tag,Product_Active`,
|
|
184
|
+
access_token,
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
fetchTasks: async (access_token: string, api_domain: string) => {
|
|
188
|
+
return fireHttpRequest({
|
|
189
|
+
method: HttpMethod.GET,
|
|
190
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.TASKS}?fields=Subject,Status,Owner,Due_Date,Description,Priority,Related_To,Tags,Remind_At,Recurring_Activity,$related_module`,
|
|
191
|
+
access_token,
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
createCall: async (access_token: string, api_domain: string, body: any) => {
|
|
195
|
+
return fireHttpRequest({
|
|
196
|
+
method: HttpMethod.POST,
|
|
197
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.CALLS}`,
|
|
198
|
+
access_token,
|
|
199
|
+
body,
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
createEvent: async (access_token: string, api_domain: string, body: any) => {
|
|
203
|
+
return fireHttpRequest({
|
|
204
|
+
method: HttpMethod.POST,
|
|
205
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.EVENTS}`,
|
|
206
|
+
access_token,
|
|
207
|
+
body,
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
fetchEvents: async (access_token: string, api_domain: string) => {
|
|
211
|
+
return fireHttpRequest({
|
|
212
|
+
method: HttpMethod.GET,
|
|
213
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.EVENTS}?fields=Owner,Event_Title,Start_DateTime,End_DateTime,Description,Recurring_Activity,Participants,Related_To,Tag,Remind_At,$related_module,All_day,Venue`,
|
|
214
|
+
access_token,
|
|
215
|
+
});
|
|
216
|
+
},
|
|
217
|
+
updateEvent: async (access_token: string, api_domain: string, body: any) => {
|
|
218
|
+
return fireHttpRequest({
|
|
219
|
+
method: HttpMethod.PUT,
|
|
220
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.EVENTS}`,
|
|
221
|
+
access_token,
|
|
222
|
+
body,
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
createTask: async (access_token: string, api_domain: string, body: any) => {
|
|
226
|
+
return fireHttpRequest({
|
|
227
|
+
method: HttpMethod.POST,
|
|
228
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.TASKS}`,
|
|
229
|
+
access_token,
|
|
230
|
+
body,
|
|
231
|
+
});
|
|
232
|
+
},
|
|
233
|
+
updateTask: async (access_token: string, api_domain: string, body: any) => {
|
|
234
|
+
return fireHttpRequest({
|
|
235
|
+
method: HttpMethod.PUT,
|
|
236
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.TASKS}`,
|
|
237
|
+
access_token,
|
|
238
|
+
body,
|
|
239
|
+
});
|
|
240
|
+
},
|
|
241
|
+
fetchModules: async (access_token: string, api_domain: string) => {
|
|
242
|
+
return fireHttpRequest({
|
|
243
|
+
method: HttpMethod.GET,
|
|
244
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.MODULES}`,
|
|
245
|
+
access_token,
|
|
246
|
+
});
|
|
247
|
+
},
|
|
248
|
+
fetchLayouts: async (
|
|
249
|
+
access_token: string,
|
|
250
|
+
api_domain: string,
|
|
251
|
+
module_name: string
|
|
252
|
+
) => {
|
|
253
|
+
return fireHttpRequest({
|
|
254
|
+
method: HttpMethod.GET,
|
|
255
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.LAYOUTS}?module=${module_name}`,
|
|
256
|
+
access_token,
|
|
257
|
+
});
|
|
258
|
+
},
|
|
259
|
+
fetchModuleFields: async (
|
|
260
|
+
access_token: string,
|
|
261
|
+
api_domain: string,
|
|
262
|
+
module_name: string
|
|
263
|
+
) => {
|
|
264
|
+
return fireHttpRequest({
|
|
265
|
+
method: HttpMethod.GET,
|
|
266
|
+
path: `${api_domain}/bigin/v2${API_ENDPOINTS.FIELDS}?module=${module_name}`,
|
|
267
|
+
access_token,
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
searchRecords: async (
|
|
271
|
+
access_token: string,
|
|
272
|
+
api_domain: string,
|
|
273
|
+
module_name: string,
|
|
274
|
+
query: {
|
|
275
|
+
key: string;
|
|
276
|
+
value: string;
|
|
277
|
+
}
|
|
278
|
+
) => {
|
|
279
|
+
return fireHttpRequest({
|
|
280
|
+
method: HttpMethod.GET,
|
|
281
|
+
path: `${api_domain}/bigin/v2/${module_name}/search?${encodeURIComponent(query.key)}=${encodeURIComponent(query.value)}`,
|
|
282
|
+
access_token,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { createTrigger, TriggerStrategy } from '@agnocon/pieces-framework';
|
|
2
|
+
import { ZOHO_WEBHOOK_TOKEN } from '../common/constants';
|
|
3
|
+
import { biginAuth } from '../auth';
|
|
4
|
+
import { biginApiService } from '../common/request';
|
|
5
|
+
|
|
6
|
+
const CACHE_KEY = 'bigin_company_updated_trigger';
|
|
7
|
+
|
|
8
|
+
export const companyUpdated = createTrigger({
|
|
9
|
+
auth: biginAuth,
|
|
10
|
+
name: 'companyUpdated',
|
|
11
|
+
displayName: 'Company Updated',
|
|
12
|
+
description: 'Triggers when a company record is updated',
|
|
13
|
+
aiMetadata: {
|
|
14
|
+
description: 'Fires when an existing company (account) record is edited in Bigin CRM, via an Accounts.edit webhook. Represents a change to an organization already in the CRM.',
|
|
15
|
+
},
|
|
16
|
+
props: {},
|
|
17
|
+
sampleData: {},
|
|
18
|
+
type: TriggerStrategy.WEBHOOK,
|
|
19
|
+
async onEnable(context) {
|
|
20
|
+
try {
|
|
21
|
+
const channel_id = Date.now().toString();
|
|
22
|
+
const { api_domain } = context.auth.data;
|
|
23
|
+
|
|
24
|
+
const webhookData = {
|
|
25
|
+
watch: [
|
|
26
|
+
{
|
|
27
|
+
channel_id,
|
|
28
|
+
events: ['Accounts.edit'],
|
|
29
|
+
notify_url: context.webhookUrl,
|
|
30
|
+
token: ZOHO_WEBHOOK_TOKEN,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
await biginApiService.createWebhook(
|
|
36
|
+
context.auth.access_token,
|
|
37
|
+
webhookData,
|
|
38
|
+
api_domain
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
await context.store.put(CACHE_KEY, channel_id);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.error('Failed to enable Zoho webhook');
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
async onDisable(context) {
|
|
47
|
+
const channel_id = (await context.store.get(CACHE_KEY)) as string;
|
|
48
|
+
if (!channel_id) return;
|
|
49
|
+
|
|
50
|
+
const { api_domain } = context.auth.data;
|
|
51
|
+
|
|
52
|
+
await biginApiService.deleteWebhook(
|
|
53
|
+
context.auth.access_token,
|
|
54
|
+
api_domain,
|
|
55
|
+
channel_id
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
await context.store.delete(CACHE_KEY);
|
|
59
|
+
},
|
|
60
|
+
async run(context) {
|
|
61
|
+
const { token } = context.payload.body as any;
|
|
62
|
+
|
|
63
|
+
if (token !== ZOHO_WEBHOOK_TOKEN) {
|
|
64
|
+
throw new Error('Invalid webhook token');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return [context.payload.body];
|
|
68
|
+
},
|
|
69
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createTrigger, TriggerStrategy } from '@agnocon/pieces-framework';
|
|
2
|
+
import { ZOHO_WEBHOOK_TOKEN } from '../common/constants';
|
|
3
|
+
import { biginAuth } from '../auth';
|
|
4
|
+
import { biginApiService } from '../common/request';
|
|
5
|
+
|
|
6
|
+
const CACHE_KEY = 'bigin_updated_contact_trigger';
|
|
7
|
+
|
|
8
|
+
export const contactUpdated = createTrigger({
|
|
9
|
+
auth: biginAuth,
|
|
10
|
+
name: 'contactUpdated',
|
|
11
|
+
displayName: 'Contact Updated',
|
|
12
|
+
description: 'Triggers when a contact is updated',
|
|
13
|
+
aiMetadata: {
|
|
14
|
+
description: 'Fires when an existing contact (person) record is edited in Bigin CRM, via a Contacts.edit webhook. Represents a change to a person already in the CRM.',
|
|
15
|
+
},
|
|
16
|
+
props: {},
|
|
17
|
+
sampleData: {},
|
|
18
|
+
type: TriggerStrategy.WEBHOOK,
|
|
19
|
+
async onEnable(context) {
|
|
20
|
+
try {
|
|
21
|
+
const channel_id = Date.now().toString();
|
|
22
|
+
const { api_domain } = context.auth.data;
|
|
23
|
+
|
|
24
|
+
const webhookData = {
|
|
25
|
+
watch: [
|
|
26
|
+
{
|
|
27
|
+
channel_id,
|
|
28
|
+
events: ['Contacts.edit'],
|
|
29
|
+
notify_url: context.webhookUrl,
|
|
30
|
+
token: ZOHO_WEBHOOK_TOKEN,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
await biginApiService.createWebhook(context.auth.access_token, webhookData, api_domain)
|
|
36
|
+
|
|
37
|
+
await context.store.put(CACHE_KEY, channel_id);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error('Failed to enable Zoho webhook');
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
async onDisable(context) {
|
|
43
|
+
const channel_id = await context.store.get(CACHE_KEY) as string;
|
|
44
|
+
if (!channel_id) return;
|
|
45
|
+
|
|
46
|
+
const { api_domain } = context.auth.data;
|
|
47
|
+
|
|
48
|
+
await biginApiService.deleteWebhook(
|
|
49
|
+
context.auth.access_token,
|
|
50
|
+
api_domain,
|
|
51
|
+
channel_id
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
await context.store.delete(CACHE_KEY);
|
|
55
|
+
},
|
|
56
|
+
async run(context) {
|
|
57
|
+
const { token } = context.payload.body as any;
|
|
58
|
+
|
|
59
|
+
if (token !== ZOHO_WEBHOOK_TOKEN) {
|
|
60
|
+
throw new Error('Invalid webhook token');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return [context.payload.body];
|
|
64
|
+
},
|
|
65
|
+
});
|