@agnocon/piece-bexio 0.1.7
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 +93 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/actions/create-company.d.ts +28 -0
- package/dist/lib/actions/create-company.d.ts.map +1 -0
- package/dist/lib/actions/create-company.js +461 -0
- package/dist/lib/actions/create-company.js.map +1 -0
- package/dist/lib/actions/create-file.d.ts +4 -0
- package/dist/lib/actions/create-file.d.ts.map +1 -0
- package/dist/lib/actions/create-file.js +48 -0
- package/dist/lib/actions/create-file.js.map +1 -0
- package/dist/lib/actions/create-manual-entry.d.ts +7 -0
- package/dist/lib/actions/create-manual-entry.d.ts.map +1 -0
- package/dist/lib/actions/create-manual-entry.js +426 -0
- package/dist/lib/actions/create-manual-entry.js.map +1 -0
- package/dist/lib/actions/create-person.d.ts +30 -0
- package/dist/lib/actions/create-person.d.ts.map +1 -0
- package/dist/lib/actions/create-person.js +477 -0
- package/dist/lib/actions/create-person.js.map +1 -0
- package/dist/lib/actions/create-product.d.ts +34 -0
- package/dist/lib/actions/create-product.d.ts.map +1 -0
- package/dist/lib/actions/create-product.js +527 -0
- package/dist/lib/actions/create-product.js.map +1 -0
- package/dist/lib/actions/create-project.d.ts +17 -0
- package/dist/lib/actions/create-project.d.ts.map +1 -0
- package/dist/lib/actions/create-project.js +316 -0
- package/dist/lib/actions/create-project.js.map +1 -0
- package/dist/lib/actions/create-sales-invoice.d.ts +25 -0
- package/dist/lib/actions/create-sales-invoice.d.ts.map +1 -0
- package/dist/lib/actions/create-sales-invoice.js +615 -0
- package/dist/lib/actions/create-sales-invoice.js.map +1 -0
- package/dist/lib/actions/create-sales-order.d.ts +25 -0
- package/dist/lib/actions/create-sales-order.d.ts.map +1 -0
- package/dist/lib/actions/create-sales-order.js +642 -0
- package/dist/lib/actions/create-sales-order.js.map +1 -0
- package/dist/lib/actions/create-sales-quote.d.ts +28 -0
- package/dist/lib/actions/create-sales-quote.d.ts.map +1 -0
- package/dist/lib/actions/create-sales-quote.js +666 -0
- package/dist/lib/actions/create-sales-quote.js.map +1 -0
- package/dist/lib/actions/create-time-tracking.d.ts +17 -0
- package/dist/lib/actions/create-time-tracking.d.ts.map +1 -0
- package/dist/lib/actions/create-time-tracking.js +380 -0
- package/dist/lib/actions/create-time-tracking.js.map +1 -0
- package/dist/lib/actions/export-invoice-pdf.d.ts +5 -0
- package/dist/lib/actions/export-invoice-pdf.d.ts.map +1 -0
- package/dist/lib/actions/export-invoice-pdf.js +94 -0
- package/dist/lib/actions/export-invoice-pdf.js.map +1 -0
- package/dist/lib/actions/find-account.d.ts +6 -0
- package/dist/lib/actions/find-account.d.ts.map +1 -0
- package/dist/lib/actions/find-account.js +107 -0
- package/dist/lib/actions/find-account.js.map +1 -0
- package/dist/lib/actions/find-company.d.ts +8 -0
- package/dist/lib/actions/find-company.d.ts.map +1 -0
- package/dist/lib/actions/find-company.js +160 -0
- package/dist/lib/actions/find-company.js.map +1 -0
- package/dist/lib/actions/find-country.d.ts +7 -0
- package/dist/lib/actions/find-country.d.ts.map +1 -0
- package/dist/lib/actions/find-country.js +125 -0
- package/dist/lib/actions/find-country.js.map +1 -0
- package/dist/lib/actions/find-person.d.ts +9 -0
- package/dist/lib/actions/find-person.d.ts.map +1 -0
- package/dist/lib/actions/find-person.js +175 -0
- package/dist/lib/actions/find-person.js.map +1 -0
- package/dist/lib/actions/find-product.d.ts +7 -0
- package/dist/lib/actions/find-product.d.ts.map +1 -0
- package/dist/lib/actions/find-product.js +124 -0
- package/dist/lib/actions/find-product.js.map +1 -0
- package/dist/lib/actions/search-invoice.d.ts +7 -0
- package/dist/lib/actions/search-invoice.d.ts.map +1 -0
- package/dist/lib/actions/search-invoice.js +140 -0
- package/dist/lib/actions/search-invoice.js.map +1 -0
- package/dist/lib/actions/search-order.d.ts +7 -0
- package/dist/lib/actions/search-order.d.ts.map +1 -0
- package/dist/lib/actions/search-order.js +139 -0
- package/dist/lib/actions/search-order.js.map +1 -0
- package/dist/lib/actions/search-quote.d.ts +7 -0
- package/dist/lib/actions/search-quote.d.ts.map +1 -0
- package/dist/lib/actions/search-quote.js +140 -0
- package/dist/lib/actions/search-quote.js.map +1 -0
- package/dist/lib/actions/send-sales-invoice.d.ts +9 -0
- package/dist/lib/actions/send-sales-invoice.d.ts.map +1 -0
- package/dist/lib/actions/send-sales-invoice.js +110 -0
- package/dist/lib/actions/send-sales-invoice.js.map +1 -0
- package/dist/lib/actions/update-company.d.ts +29 -0
- package/dist/lib/actions/update-company.d.ts.map +1 -0
- package/dist/lib/actions/update-company.js +506 -0
- package/dist/lib/actions/update-company.js.map +1 -0
- package/dist/lib/actions/update-person.d.ts +31 -0
- package/dist/lib/actions/update-person.d.ts.map +1 -0
- package/dist/lib/actions/update-person.js +524 -0
- package/dist/lib/actions/update-person.js.map +1 -0
- package/dist/lib/actions/update-product.d.ts +34 -0
- package/dist/lib/actions/update-product.d.ts.map +1 -0
- package/dist/lib/actions/update-product.js +556 -0
- package/dist/lib/actions/update-product.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 +51 -0
- package/dist/lib/auth.js.map +1 -0
- package/dist/lib/common/client.d.ts +13 -0
- package/dist/lib/common/client.d.ts.map +1 -0
- package/dist/lib/common/client.js +64 -0
- package/dist/lib/common/client.js.map +1 -0
- package/dist/lib/common/index.d.ts +5 -0
- package/dist/lib/common/index.d.ts.map +1 -0
- package/dist/lib/common/index.js +10 -0
- package/dist/lib/common/index.js.map +1 -0
- package/dist/lib/common/props.d.ts +14 -0
- package/dist/lib/common/props.d.ts.map +1 -0
- package/dist/lib/common/props.js +118 -0
- package/dist/lib/common/props.js.map +1 -0
- package/dist/lib/common/types.d.ts +89 -0
- package/dist/lib/common/types.d.ts.map +1 -0
- package/dist/lib/common/types.js +6 -0
- package/dist/lib/common/types.js.map +1 -0
- package/dist/lib/triggers/new-order.d.ts +11 -0
- package/dist/lib/triggers/new-order.d.ts.map +1 -0
- package/dist/lib/triggers/new-order.js +152 -0
- package/dist/lib/triggers/new-order.js.map +1 -0
- package/dist/lib/triggers/new-product.d.ts +3 -0
- package/dist/lib/triggers/new-product.d.ts.map +1 -0
- package/dist/lib/triggers/new-product.js +111 -0
- package/dist/lib/triggers/new-product.js.map +1 -0
- package/dist/lib/triggers/new-project.d.ts +11 -0
- package/dist/lib/triggers/new-project.d.ts.map +1 -0
- package/dist/lib/triggers/new-project.js +141 -0
- package/dist/lib/triggers/new-project.js.map +1 -0
- package/dist/lib/triggers/new-quote.d.ts +11 -0
- package/dist/lib/triggers/new-quote.d.ts.map +1 -0
- package/dist/lib/triggers/new-quote.js +153 -0
- package/dist/lib/triggers/new-quote.js.map +1 -0
- package/dist/lib/triggers/new-sales-invoice.d.ts +11 -0
- package/dist/lib/triggers/new-sales-invoice.d.ts.map +1 -0
- package/dist/lib/triggers/new-sales-invoice.js +153 -0
- package/dist/lib/triggers/new-sales-invoice.js.map +1 -0
- package/dist/lib/triggers/new-updated-company.d.ts +3 -0
- package/dist/lib/triggers/new-updated-company.d.ts.map +1 -0
- package/dist/lib/triggers/new-updated-company.js +122 -0
- package/dist/lib/triggers/new-updated-company.js.map +1 -0
- package/dist/lib/triggers/new-updated-person.d.ts +3 -0
- package/dist/lib/triggers/new-updated-person.d.ts.map +1 -0
- package/dist/lib/triggers/new-updated-person.js +122 -0
- package/dist/lib/triggers/new-updated-person.js.map +1 -0
- package/package.json +48 -0
- package/src/index.ts +89 -0
- package/src/lib/actions/create-company.ts +464 -0
- package/src/lib/actions/create-file.ts +62 -0
- package/src/lib/actions/create-manual-entry.ts +445 -0
- package/src/lib/actions/create-person.ts +481 -0
- package/src/lib/actions/create-product.ts +563 -0
- package/src/lib/actions/create-project.ts +344 -0
- package/src/lib/actions/create-sales-invoice.ts +656 -0
- package/src/lib/actions/create-sales-order.ts +689 -0
- package/src/lib/actions/create-sales-quote.ts +713 -0
- package/src/lib/actions/create-time-tracking.ts +418 -0
- package/src/lib/actions/export-invoice-pdf.ts +104 -0
- package/src/lib/actions/find-account.ts +114 -0
- package/src/lib/actions/find-company.ts +193 -0
- package/src/lib/actions/find-country.ts +127 -0
- package/src/lib/actions/find-person.ts +208 -0
- package/src/lib/actions/find-product.ts +161 -0
- package/src/lib/actions/search-invoice.ts +157 -0
- package/src/lib/actions/search-order.ts +155 -0
- package/src/lib/actions/search-quote.ts +157 -0
- package/src/lib/actions/send-sales-invoice.ts +118 -0
- package/src/lib/actions/update-company.ts +518 -0
- package/src/lib/actions/update-person.ts +536 -0
- package/src/lib/actions/update-product.ts +594 -0
- package/src/lib/auth.ts +44 -0
- package/src/lib/common/client.ts +65 -0
- package/src/lib/common/index.ts +5 -0
- package/src/lib/common/props.ts +127 -0
- package/src/lib/common/types.ts +99 -0
- package/src/lib/triggers/new-order.ts +184 -0
- package/src/lib/triggers/new-product.ts +154 -0
- package/src/lib/triggers/new-project.ts +165 -0
- package/src/lib/triggers/new-quote.ts +186 -0
- package/src/lib/triggers/new-sales-invoice.ts +186 -0
- package/src/lib/triggers/new-updated-company.ts +161 -0
- package/src/lib/triggers/new-updated-person.ts +161 -0
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
import { createAction, Property, OAuth2PropertyValue } from '@agnocon/pieces-framework';
|
|
2
|
+
import { bexioAuth } from '../auth';
|
|
3
|
+
import { BexioClient } from '../common/client';
|
|
4
|
+
|
|
5
|
+
export const updateCompanyAction = createAction({
|
|
6
|
+
auth: bexioAuth,
|
|
7
|
+
name: 'update_company',
|
|
8
|
+
displayName: 'Update Company',
|
|
9
|
+
description: 'Update an existing company contact',
|
|
10
|
+
audience: 'both',
|
|
11
|
+
aiMetadata: { description: 'Updates fields on an existing company-type contact in Bexio identified by its contact id; only supplied fields change. Use to modify a known organization; pick Create Company to add a new one or Update Person for an individual. Resolve the contact id with Find Company first. Idempotent: re-sending the same values converges to the same contact state.', idempotent: true },
|
|
12
|
+
props: {
|
|
13
|
+
contact_id: Property.Dropdown({
|
|
14
|
+
auth: bexioAuth,
|
|
15
|
+
displayName: 'Company',
|
|
16
|
+
description: 'Select the company to update',
|
|
17
|
+
required: true,
|
|
18
|
+
refreshers: [],
|
|
19
|
+
options: async ({ auth }) => {
|
|
20
|
+
if (!auth) {
|
|
21
|
+
return {
|
|
22
|
+
disabled: true,
|
|
23
|
+
placeholder: 'Connect your Bexio account first',
|
|
24
|
+
options: [],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const client = new BexioClient(auth);
|
|
30
|
+
const contacts = await client.get<Array<{
|
|
31
|
+
id: number;
|
|
32
|
+
contact_type_id: number;
|
|
33
|
+
name_1: string;
|
|
34
|
+
name_2?: string | null;
|
|
35
|
+
nr?: string | null;
|
|
36
|
+
}>>('/2.0/contact');
|
|
37
|
+
|
|
38
|
+
const companies = contacts.filter((contact) => contact.contact_type_id === 1);
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
disabled: false,
|
|
42
|
+
options: companies.map((company) => {
|
|
43
|
+
const label = company.nr ? `${company.name_1} (#${company.nr})` : company.name_1;
|
|
44
|
+
return {
|
|
45
|
+
label,
|
|
46
|
+
value: company.id,
|
|
47
|
+
};
|
|
48
|
+
}),
|
|
49
|
+
};
|
|
50
|
+
} catch (error) {
|
|
51
|
+
return {
|
|
52
|
+
disabled: true,
|
|
53
|
+
placeholder: 'Failed to load companies',
|
|
54
|
+
options: [],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
name_1: Property.ShortText({
|
|
60
|
+
displayName: 'Company Name',
|
|
61
|
+
description: 'The name of the company',
|
|
62
|
+
required: false,
|
|
63
|
+
}),
|
|
64
|
+
name_2: Property.ShortText({
|
|
65
|
+
displayName: 'Company Addition',
|
|
66
|
+
description: 'Additional company name (e.g., "Ltd.", "Inc.")',
|
|
67
|
+
required: false,
|
|
68
|
+
}),
|
|
69
|
+
nr: Property.ShortText({
|
|
70
|
+
displayName: 'Contact Number',
|
|
71
|
+
description: 'Contact number (leave empty to keep current or auto-assign)',
|
|
72
|
+
required: false,
|
|
73
|
+
}),
|
|
74
|
+
salutation_id: Property.Dropdown({
|
|
75
|
+
auth: bexioAuth,
|
|
76
|
+
displayName: 'Salutation',
|
|
77
|
+
description: 'Salutation for the company',
|
|
78
|
+
required: false,
|
|
79
|
+
refreshers: [],
|
|
80
|
+
options: async ({ auth }) => {
|
|
81
|
+
if (!auth) {
|
|
82
|
+
return {
|
|
83
|
+
disabled: true,
|
|
84
|
+
placeholder: 'Connect your Bexio account first',
|
|
85
|
+
options: [],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const client = new BexioClient(auth);
|
|
91
|
+
const salutations = await client.get<Array<{ id: number; name: string }>>('/2.0/salutation');
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
disabled: false,
|
|
95
|
+
options: salutations.map((sal) => ({
|
|
96
|
+
label: sal.name,
|
|
97
|
+
value: sal.id,
|
|
98
|
+
})),
|
|
99
|
+
};
|
|
100
|
+
} catch (error) {
|
|
101
|
+
return {
|
|
102
|
+
disabled: true,
|
|
103
|
+
placeholder: 'Failed to load salutations',
|
|
104
|
+
options: [],
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
109
|
+
title_id: Property.Dropdown({
|
|
110
|
+
auth: bexioAuth,
|
|
111
|
+
displayName: 'Title',
|
|
112
|
+
description: 'Title for the company',
|
|
113
|
+
required: false,
|
|
114
|
+
refreshers: [],
|
|
115
|
+
options: async ({ auth }) => {
|
|
116
|
+
if (!auth) {
|
|
117
|
+
return {
|
|
118
|
+
disabled: true,
|
|
119
|
+
placeholder: 'Connect your Bexio account first',
|
|
120
|
+
options: [],
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
const client = new BexioClient(auth);
|
|
126
|
+
const titles = await client.get<Array<{ id: number; name: string }>>('/2.0/title');
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
disabled: false,
|
|
130
|
+
options: titles.map((title) => ({
|
|
131
|
+
label: title.name,
|
|
132
|
+
value: title.id,
|
|
133
|
+
})),
|
|
134
|
+
};
|
|
135
|
+
} catch (error) {
|
|
136
|
+
return {
|
|
137
|
+
disabled: true,
|
|
138
|
+
placeholder: 'Failed to load titles',
|
|
139
|
+
options: [],
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
}),
|
|
144
|
+
street_name: Property.ShortText({
|
|
145
|
+
displayName: 'Street Name',
|
|
146
|
+
description: 'Street name',
|
|
147
|
+
required: false,
|
|
148
|
+
}),
|
|
149
|
+
house_number: Property.ShortText({
|
|
150
|
+
displayName: 'House Number',
|
|
151
|
+
description: 'House number',
|
|
152
|
+
required: false,
|
|
153
|
+
}),
|
|
154
|
+
address_addition: Property.ShortText({
|
|
155
|
+
displayName: 'Address Addition',
|
|
156
|
+
description: 'Additional address information',
|
|
157
|
+
required: false,
|
|
158
|
+
}),
|
|
159
|
+
postcode: Property.ShortText({
|
|
160
|
+
displayName: 'Postcode',
|
|
161
|
+
description: 'Postal code',
|
|
162
|
+
required: false,
|
|
163
|
+
}),
|
|
164
|
+
city: Property.ShortText({
|
|
165
|
+
displayName: 'City',
|
|
166
|
+
description: 'City',
|
|
167
|
+
required: false,
|
|
168
|
+
}),
|
|
169
|
+
country_id: Property.Dropdown({
|
|
170
|
+
auth: bexioAuth,
|
|
171
|
+
displayName: 'Country',
|
|
172
|
+
description: 'Country',
|
|
173
|
+
required: false,
|
|
174
|
+
refreshers: [],
|
|
175
|
+
options: async ({ auth }) => {
|
|
176
|
+
if (!auth) {
|
|
177
|
+
return {
|
|
178
|
+
disabled: true,
|
|
179
|
+
placeholder: 'Connect your Bexio account first',
|
|
180
|
+
options: [],
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
const client = new BexioClient(auth);
|
|
186
|
+
const countries = await client.get<Array<{ id: number; name: string; name_short: string; iso3166_alpha2: string }>>('/2.0/country');
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
disabled: false,
|
|
190
|
+
options: countries.map((country) => ({
|
|
191
|
+
label: `${country.name} (${country.name_short})`,
|
|
192
|
+
value: country.id,
|
|
193
|
+
})),
|
|
194
|
+
};
|
|
195
|
+
} catch (error) {
|
|
196
|
+
return {
|
|
197
|
+
disabled: true,
|
|
198
|
+
placeholder: 'Failed to load countries',
|
|
199
|
+
options: [],
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
}),
|
|
204
|
+
mail: Property.ShortText({
|
|
205
|
+
displayName: 'Email',
|
|
206
|
+
description: 'Primary email address',
|
|
207
|
+
required: false,
|
|
208
|
+
}),
|
|
209
|
+
mail_second: Property.ShortText({
|
|
210
|
+
displayName: 'Secondary Email',
|
|
211
|
+
description: 'Secondary email address',
|
|
212
|
+
required: false,
|
|
213
|
+
}),
|
|
214
|
+
phone_fixed: Property.ShortText({
|
|
215
|
+
displayName: 'Phone',
|
|
216
|
+
description: 'Fixed phone number',
|
|
217
|
+
required: false,
|
|
218
|
+
}),
|
|
219
|
+
phone_fixed_second: Property.ShortText({
|
|
220
|
+
displayName: 'Secondary Phone',
|
|
221
|
+
description: 'Secondary fixed phone number',
|
|
222
|
+
required: false,
|
|
223
|
+
}),
|
|
224
|
+
phone_mobile: Property.ShortText({
|
|
225
|
+
displayName: 'Mobile Phone',
|
|
226
|
+
description: 'Mobile phone number',
|
|
227
|
+
required: false,
|
|
228
|
+
}),
|
|
229
|
+
fax: Property.ShortText({
|
|
230
|
+
displayName: 'Fax',
|
|
231
|
+
description: 'Fax number',
|
|
232
|
+
required: false,
|
|
233
|
+
}),
|
|
234
|
+
url: Property.ShortText({
|
|
235
|
+
displayName: 'Website URL',
|
|
236
|
+
description: 'Company website URL',
|
|
237
|
+
required: false,
|
|
238
|
+
}),
|
|
239
|
+
skype_name: Property.ShortText({
|
|
240
|
+
displayName: 'Skype Name',
|
|
241
|
+
description: 'Skype username',
|
|
242
|
+
required: false,
|
|
243
|
+
}),
|
|
244
|
+
remarks: Property.LongText({
|
|
245
|
+
displayName: 'Remarks',
|
|
246
|
+
description: 'Additional notes about the company',
|
|
247
|
+
required: false,
|
|
248
|
+
}),
|
|
249
|
+
language_id: Property.Dropdown({
|
|
250
|
+
auth: bexioAuth,
|
|
251
|
+
displayName: 'Language',
|
|
252
|
+
description: 'Preferred language',
|
|
253
|
+
required: false,
|
|
254
|
+
refreshers: [],
|
|
255
|
+
options: async ({ auth }) => {
|
|
256
|
+
if (!auth) {
|
|
257
|
+
return {
|
|
258
|
+
disabled: true,
|
|
259
|
+
placeholder: 'Connect your Bexio account first',
|
|
260
|
+
options: [],
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
try {
|
|
265
|
+
const client = new BexioClient(auth);
|
|
266
|
+
const languages = await client.get<Array<{ id: number; name: string }>>('/2.0/language');
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
disabled: false,
|
|
270
|
+
options: languages.map((lang) => ({
|
|
271
|
+
label: lang.name,
|
|
272
|
+
value: lang.id,
|
|
273
|
+
})),
|
|
274
|
+
};
|
|
275
|
+
} catch (error) {
|
|
276
|
+
return {
|
|
277
|
+
disabled: true,
|
|
278
|
+
placeholder: 'Failed to load languages',
|
|
279
|
+
options: [],
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
}),
|
|
284
|
+
contact_group_ids: Property.MultiSelectDropdown({
|
|
285
|
+
auth: bexioAuth,
|
|
286
|
+
displayName: 'Contact Groups',
|
|
287
|
+
description: 'Select contact groups',
|
|
288
|
+
required: false,
|
|
289
|
+
refreshers: [],
|
|
290
|
+
options: async ({ auth }) => {
|
|
291
|
+
if (!auth) {
|
|
292
|
+
return {
|
|
293
|
+
disabled: true,
|
|
294
|
+
placeholder: 'Connect your Bexio account first',
|
|
295
|
+
options: [],
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
try {
|
|
300
|
+
const client = new BexioClient(auth);
|
|
301
|
+
const groups = await client.get<Array<{ id: number; name: string }>>('/2.0/contact_group');
|
|
302
|
+
|
|
303
|
+
return {
|
|
304
|
+
disabled: false,
|
|
305
|
+
options: groups.map((group) => ({
|
|
306
|
+
label: group.name,
|
|
307
|
+
value: group.id.toString(),
|
|
308
|
+
})),
|
|
309
|
+
};
|
|
310
|
+
} catch (error) {
|
|
311
|
+
return {
|
|
312
|
+
disabled: true,
|
|
313
|
+
placeholder: 'Failed to load contact groups',
|
|
314
|
+
options: [],
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
}),
|
|
319
|
+
contact_branch_ids: Property.MultiSelectDropdown({
|
|
320
|
+
auth: bexioAuth,
|
|
321
|
+
displayName: 'Contact Sectors',
|
|
322
|
+
description: 'Select contact sectors',
|
|
323
|
+
required: false,
|
|
324
|
+
refreshers: [],
|
|
325
|
+
options: async ({ auth }) => {
|
|
326
|
+
if (!auth) {
|
|
327
|
+
return {
|
|
328
|
+
disabled: true,
|
|
329
|
+
placeholder: 'Connect your Bexio account first',
|
|
330
|
+
options: [],
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
try {
|
|
335
|
+
const client = new BexioClient(auth);
|
|
336
|
+
const branches = await client.get<Array<{ id: number; name: string }>>('/2.0/contact_branch');
|
|
337
|
+
|
|
338
|
+
return {
|
|
339
|
+
disabled: false,
|
|
340
|
+
options: branches.map((branch) => ({
|
|
341
|
+
label: branch.name,
|
|
342
|
+
value: branch.id.toString(),
|
|
343
|
+
})),
|
|
344
|
+
};
|
|
345
|
+
} catch (error) {
|
|
346
|
+
return {
|
|
347
|
+
disabled: true,
|
|
348
|
+
placeholder: 'Failed to load contact sectors',
|
|
349
|
+
options: [],
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
}),
|
|
354
|
+
user_id: Property.Dropdown({
|
|
355
|
+
auth: bexioAuth,
|
|
356
|
+
displayName: 'User',
|
|
357
|
+
description: 'User assigned to this contact',
|
|
358
|
+
required: false,
|
|
359
|
+
refreshers: [],
|
|
360
|
+
options: async ({ auth }) => {
|
|
361
|
+
if (!auth) {
|
|
362
|
+
return {
|
|
363
|
+
disabled: true,
|
|
364
|
+
placeholder: 'Connect your Bexio account first',
|
|
365
|
+
options: [],
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
try {
|
|
370
|
+
const client = new BexioClient(auth);
|
|
371
|
+
const users = await client.get<Array<{ id: number; firstname: string | null; lastname: string | null; email: string }>>('/3.0/users');
|
|
372
|
+
|
|
373
|
+
return {
|
|
374
|
+
disabled: false,
|
|
375
|
+
options: users.map((user) => ({
|
|
376
|
+
label: `${user.firstname || ''} ${user.lastname || ''}`.trim() || user.email,
|
|
377
|
+
value: user.id,
|
|
378
|
+
})),
|
|
379
|
+
};
|
|
380
|
+
} catch (error) {
|
|
381
|
+
return {
|
|
382
|
+
disabled: true,
|
|
383
|
+
placeholder: 'Failed to load users',
|
|
384
|
+
options: [],
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
}),
|
|
389
|
+
owner_id: Property.Dropdown({
|
|
390
|
+
auth: bexioAuth,
|
|
391
|
+
displayName: 'Owner',
|
|
392
|
+
description: 'Owner of this contact',
|
|
393
|
+
required: false,
|
|
394
|
+
refreshers: [],
|
|
395
|
+
options: async ({ auth }) => {
|
|
396
|
+
if (!auth) {
|
|
397
|
+
return {
|
|
398
|
+
disabled: true,
|
|
399
|
+
placeholder: 'Connect your Bexio account first',
|
|
400
|
+
options: [],
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
try {
|
|
405
|
+
const client = new BexioClient(auth);
|
|
406
|
+
const users = await client.get<Array<{ id: number; firstname: string | null; lastname: string | null; email: string }>>('/3.0/users');
|
|
407
|
+
|
|
408
|
+
return {
|
|
409
|
+
disabled: false,
|
|
410
|
+
options: users.map((user) => ({
|
|
411
|
+
label: `${user.firstname || ''} ${user.lastname || ''}`.trim() || user.email,
|
|
412
|
+
value: user.id,
|
|
413
|
+
})),
|
|
414
|
+
};
|
|
415
|
+
} catch (error) {
|
|
416
|
+
return {
|
|
417
|
+
disabled: true,
|
|
418
|
+
placeholder: 'Failed to load users',
|
|
419
|
+
options: [],
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
}),
|
|
424
|
+
},
|
|
425
|
+
async run(context) {
|
|
426
|
+
const client = new BexioClient(context.auth);
|
|
427
|
+
const contactId = context.propsValue['contact_id'] as number;
|
|
428
|
+
const props = context.propsValue;
|
|
429
|
+
|
|
430
|
+
const requestBody: Record<string, unknown> = {
|
|
431
|
+
contact_type_id: 1, // 1 = company
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
if (props['name_1']) {
|
|
435
|
+
requestBody['name_1'] = props['name_1'];
|
|
436
|
+
}
|
|
437
|
+
if (props['name_2'] !== undefined) {
|
|
438
|
+
requestBody['name_2'] = props['name_2'] || null;
|
|
439
|
+
}
|
|
440
|
+
if (props['nr'] !== undefined && props['nr'] !== null && props['nr'] !== '') {
|
|
441
|
+
requestBody['nr'] = props['nr'];
|
|
442
|
+
} else if (props['nr'] === '') {
|
|
443
|
+
requestBody['nr'] = null;
|
|
444
|
+
}
|
|
445
|
+
if (props['salutation_id']) {
|
|
446
|
+
requestBody['salutation_id'] = props['salutation_id'];
|
|
447
|
+
}
|
|
448
|
+
if (props['title_id']) {
|
|
449
|
+
requestBody['title_id'] = props['title_id'];
|
|
450
|
+
}
|
|
451
|
+
if (props['street_name']) {
|
|
452
|
+
requestBody['street_name'] = props['street_name'];
|
|
453
|
+
}
|
|
454
|
+
if (props['house_number']) {
|
|
455
|
+
requestBody['house_number'] = props['house_number'];
|
|
456
|
+
}
|
|
457
|
+
if (props['address_addition']) {
|
|
458
|
+
requestBody['address_addition'] = props['address_addition'];
|
|
459
|
+
}
|
|
460
|
+
if (props['postcode']) {
|
|
461
|
+
requestBody['postcode'] = props['postcode'];
|
|
462
|
+
}
|
|
463
|
+
if (props['city']) {
|
|
464
|
+
requestBody['city'] = props['city'];
|
|
465
|
+
}
|
|
466
|
+
if (props['country_id']) {
|
|
467
|
+
requestBody['country_id'] = props['country_id'];
|
|
468
|
+
}
|
|
469
|
+
if (props['mail']) {
|
|
470
|
+
requestBody['mail'] = props['mail'];
|
|
471
|
+
}
|
|
472
|
+
if (props['mail_second']) {
|
|
473
|
+
requestBody['mail_second'] = props['mail_second'];
|
|
474
|
+
}
|
|
475
|
+
if (props['phone_fixed']) {
|
|
476
|
+
requestBody['phone_fixed'] = props['phone_fixed'];
|
|
477
|
+
}
|
|
478
|
+
if (props['phone_fixed_second']) {
|
|
479
|
+
requestBody['phone_fixed_second'] = props['phone_fixed_second'];
|
|
480
|
+
}
|
|
481
|
+
if (props['phone_mobile']) {
|
|
482
|
+
requestBody['phone_mobile'] = props['phone_mobile'];
|
|
483
|
+
}
|
|
484
|
+
if (props['fax']) {
|
|
485
|
+
requestBody['fax'] = props['fax'];
|
|
486
|
+
}
|
|
487
|
+
if (props['url']) {
|
|
488
|
+
requestBody['url'] = props['url'];
|
|
489
|
+
}
|
|
490
|
+
if (props['skype_name']) {
|
|
491
|
+
requestBody['skype_name'] = props['skype_name'];
|
|
492
|
+
}
|
|
493
|
+
if (props['remarks']) {
|
|
494
|
+
requestBody['remarks'] = props['remarks'];
|
|
495
|
+
}
|
|
496
|
+
if (props['language_id']) {
|
|
497
|
+
requestBody['language_id'] = props['language_id'];
|
|
498
|
+
}
|
|
499
|
+
if (props['contact_group_ids'] && Array.isArray(props['contact_group_ids']) && props['contact_group_ids'].length > 0) {
|
|
500
|
+
requestBody['contact_group_ids'] = props['contact_group_ids'].join(',');
|
|
501
|
+
}
|
|
502
|
+
if (props['contact_branch_ids'] && Array.isArray(props['contact_branch_ids']) && props['contact_branch_ids'].length > 0) {
|
|
503
|
+
requestBody['contact_branch_ids'] = props['contact_branch_ids'].join(',');
|
|
504
|
+
}
|
|
505
|
+
if (props['user_id']) {
|
|
506
|
+
requestBody['user_id'] = props['user_id'];
|
|
507
|
+
}
|
|
508
|
+
if (props['owner_id']) {
|
|
509
|
+
requestBody['owner_id'] = props['owner_id'];
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// Docs specify POST for updates (not PATCH)
|
|
513
|
+
const response = await client.post(`/2.0/contact/${contactId}`, requestBody);
|
|
514
|
+
|
|
515
|
+
return response;
|
|
516
|
+
},
|
|
517
|
+
});
|
|
518
|
+
|