@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,464 @@
|
|
|
1
|
+
import { createAction, Property, OAuth2PropertyValue } from '@agnocon/pieces-framework';
|
|
2
|
+
import { bexioAuth } from '../auth';
|
|
3
|
+
import { BexioClient } from '../common/client';
|
|
4
|
+
|
|
5
|
+
export const createCompanyAction = createAction({
|
|
6
|
+
auth: bexioAuth,
|
|
7
|
+
name: 'create_company',
|
|
8
|
+
displayName: 'Create Company',
|
|
9
|
+
description: 'Create a new company contact',
|
|
10
|
+
audience: 'both',
|
|
11
|
+
aiMetadata: { description: 'Creates a new organization (company-type) contact in Bexio with name, address, communication, and grouping fields. Use to add a company; pick Create Person for an individual or Update Company to modify an existing one. Requires a company name plus an assigned user and owner. Not idempotent: each call creates a separate contact, so search first to avoid duplicates.', idempotent: false },
|
|
12
|
+
props: {
|
|
13
|
+
name_1: Property.ShortText({
|
|
14
|
+
displayName: 'Company Name',
|
|
15
|
+
description: 'The name of the company',
|
|
16
|
+
required: true,
|
|
17
|
+
}),
|
|
18
|
+
name_2: Property.ShortText({
|
|
19
|
+
displayName: 'Company Addition',
|
|
20
|
+
description: 'Additional company name (e.g., "Ltd.", "Inc.")',
|
|
21
|
+
required: false,
|
|
22
|
+
}),
|
|
23
|
+
nr: Property.ShortText({
|
|
24
|
+
displayName: 'Contact Number',
|
|
25
|
+
description: 'Contact number (leave empty to auto-assign)',
|
|
26
|
+
required: false,
|
|
27
|
+
}),
|
|
28
|
+
salutation_id: Property.Dropdown({
|
|
29
|
+
auth: bexioAuth,
|
|
30
|
+
displayName: 'Salutation',
|
|
31
|
+
description: 'Salutation for the company',
|
|
32
|
+
required: false,
|
|
33
|
+
refreshers: [],
|
|
34
|
+
options: async ({ auth }) => {
|
|
35
|
+
if (!auth) {
|
|
36
|
+
return {
|
|
37
|
+
disabled: true,
|
|
38
|
+
placeholder: 'Connect your Bexio account first',
|
|
39
|
+
options: [],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const client = new BexioClient(auth);
|
|
45
|
+
const salutations = await client.get<Array<{ id: number; name: string }>>('/2.0/salutation');
|
|
46
|
+
return {
|
|
47
|
+
disabled: false,
|
|
48
|
+
options: salutations.map((sal) => ({
|
|
49
|
+
label: sal.name,
|
|
50
|
+
value: sal.id,
|
|
51
|
+
})),
|
|
52
|
+
};
|
|
53
|
+
} catch (error) {
|
|
54
|
+
return {
|
|
55
|
+
disabled: true,
|
|
56
|
+
placeholder: 'Failed to load salutations',
|
|
57
|
+
options: [],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
title_id: Property.Dropdown({
|
|
63
|
+
auth: bexioAuth,
|
|
64
|
+
displayName: 'Title',
|
|
65
|
+
description: 'Title for the company',
|
|
66
|
+
required: false,
|
|
67
|
+
refreshers: [],
|
|
68
|
+
options: async ({ auth }) => {
|
|
69
|
+
if (!auth) {
|
|
70
|
+
return {
|
|
71
|
+
disabled: true,
|
|
72
|
+
placeholder: 'Connect your Bexio account first',
|
|
73
|
+
options: [],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
const client = new BexioClient(auth);
|
|
79
|
+
const titles = await client.get<Array<{ id: number; name: string }>>('/2.0/title');
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
disabled: false,
|
|
83
|
+
options: titles.map((title) => ({
|
|
84
|
+
label: title.name,
|
|
85
|
+
value: title.id,
|
|
86
|
+
})),
|
|
87
|
+
};
|
|
88
|
+
} catch (error) {
|
|
89
|
+
return {
|
|
90
|
+
disabled: true,
|
|
91
|
+
placeholder: 'Failed to load titles',
|
|
92
|
+
options: [],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
street_name: Property.ShortText({
|
|
98
|
+
displayName: 'Street Name',
|
|
99
|
+
description: 'Street name',
|
|
100
|
+
required: false,
|
|
101
|
+
}),
|
|
102
|
+
house_number: Property.ShortText({
|
|
103
|
+
displayName: 'House Number',
|
|
104
|
+
description: 'House number',
|
|
105
|
+
required: false,
|
|
106
|
+
}),
|
|
107
|
+
address_addition: Property.ShortText({
|
|
108
|
+
displayName: 'Address Addition',
|
|
109
|
+
description: 'Additional address information (e.g., "Building C")',
|
|
110
|
+
required: false,
|
|
111
|
+
}),
|
|
112
|
+
postcode: Property.ShortText({
|
|
113
|
+
displayName: 'Postcode',
|
|
114
|
+
description: 'Postal code',
|
|
115
|
+
required: false,
|
|
116
|
+
}),
|
|
117
|
+
city: Property.ShortText({
|
|
118
|
+
displayName: 'City',
|
|
119
|
+
description: 'City',
|
|
120
|
+
required: false,
|
|
121
|
+
}),
|
|
122
|
+
country_id: Property.Dropdown({
|
|
123
|
+
auth: bexioAuth,
|
|
124
|
+
displayName: 'Country',
|
|
125
|
+
description: 'Country',
|
|
126
|
+
required: false,
|
|
127
|
+
refreshers: [],
|
|
128
|
+
options: async ({ auth }) => {
|
|
129
|
+
if (!auth) {
|
|
130
|
+
return {
|
|
131
|
+
disabled: true,
|
|
132
|
+
placeholder: 'Connect your Bexio account first',
|
|
133
|
+
options: [],
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
const client = new BexioClient(auth);
|
|
139
|
+
const countries = await client.get<Array<{ id: number; name: string; name_short: string; iso3166_alpha2: string }>>('/2.0/country');
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
disabled: false,
|
|
143
|
+
options: countries.map((country) => ({
|
|
144
|
+
label: country.name,
|
|
145
|
+
value: country.id,
|
|
146
|
+
})),
|
|
147
|
+
};
|
|
148
|
+
} catch (error) {
|
|
149
|
+
return {
|
|
150
|
+
disabled: true,
|
|
151
|
+
placeholder: 'Failed to load countries',
|
|
152
|
+
options: [],
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
}),
|
|
157
|
+
mail: Property.ShortText({
|
|
158
|
+
displayName: 'Email',
|
|
159
|
+
description: 'Primary email address',
|
|
160
|
+
required: false,
|
|
161
|
+
}),
|
|
162
|
+
mail_second: Property.ShortText({
|
|
163
|
+
displayName: 'Secondary Email',
|
|
164
|
+
description: 'Secondary email address',
|
|
165
|
+
required: false,
|
|
166
|
+
}),
|
|
167
|
+
phone_fixed: Property.ShortText({
|
|
168
|
+
displayName: 'Phone',
|
|
169
|
+
description: 'Fixed phone number',
|
|
170
|
+
required: false,
|
|
171
|
+
}),
|
|
172
|
+
phone_fixed_second: Property.ShortText({
|
|
173
|
+
displayName: 'Secondary Phone',
|
|
174
|
+
description: 'Secondary fixed phone number',
|
|
175
|
+
required: false,
|
|
176
|
+
}),
|
|
177
|
+
phone_mobile: Property.ShortText({
|
|
178
|
+
displayName: 'Mobile Phone',
|
|
179
|
+
description: 'Mobile phone number',
|
|
180
|
+
required: false,
|
|
181
|
+
}),
|
|
182
|
+
fax: Property.ShortText({
|
|
183
|
+
displayName: 'Fax',
|
|
184
|
+
description: 'Fax number',
|
|
185
|
+
required: false,
|
|
186
|
+
}),
|
|
187
|
+
url: Property.ShortText({
|
|
188
|
+
displayName: 'Website',
|
|
189
|
+
description: 'Company website URL',
|
|
190
|
+
required: false,
|
|
191
|
+
}),
|
|
192
|
+
skype_name: Property.ShortText({
|
|
193
|
+
displayName: 'Skype Name',
|
|
194
|
+
description: 'Skype username',
|
|
195
|
+
required: false,
|
|
196
|
+
}),
|
|
197
|
+
remarks: Property.LongText({
|
|
198
|
+
displayName: 'Remarks',
|
|
199
|
+
description: 'Additional notes about the company',
|
|
200
|
+
required: false,
|
|
201
|
+
}),
|
|
202
|
+
language_id: Property.Dropdown({
|
|
203
|
+
auth: bexioAuth,
|
|
204
|
+
displayName: 'Language',
|
|
205
|
+
description: 'Preferred language',
|
|
206
|
+
required: false,
|
|
207
|
+
refreshers: [],
|
|
208
|
+
options: async ({ auth }) => {
|
|
209
|
+
if (!auth) {
|
|
210
|
+
return {
|
|
211
|
+
disabled: true,
|
|
212
|
+
placeholder: 'Connect your Bexio account first',
|
|
213
|
+
options: [],
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
try {
|
|
218
|
+
const client = new BexioClient(auth);
|
|
219
|
+
const languages = await client.get<Array<{ id: number; name: string }>>('/2.0/language');
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
disabled: false,
|
|
223
|
+
options: languages.map((lang) => ({
|
|
224
|
+
label: lang.name,
|
|
225
|
+
value: lang.id,
|
|
226
|
+
})),
|
|
227
|
+
};
|
|
228
|
+
} catch (error) {
|
|
229
|
+
return {
|
|
230
|
+
disabled: true,
|
|
231
|
+
placeholder: 'Failed to load languages',
|
|
232
|
+
options: [],
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
}),
|
|
237
|
+
contact_group_ids: Property.MultiSelectDropdown({
|
|
238
|
+
auth: bexioAuth,
|
|
239
|
+
displayName: 'Contact Groups',
|
|
240
|
+
description: 'Select contact groups',
|
|
241
|
+
required: false,
|
|
242
|
+
refreshers: [],
|
|
243
|
+
options: async ({ auth }) => {
|
|
244
|
+
if (!auth) {
|
|
245
|
+
return {
|
|
246
|
+
disabled: true,
|
|
247
|
+
placeholder: 'Connect your Bexio account first',
|
|
248
|
+
options: [],
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
const client = new BexioClient(auth);
|
|
254
|
+
const groups = await client.get<Array<{ id: number; name: string }>>('/2.0/contact_group');
|
|
255
|
+
|
|
256
|
+
return {
|
|
257
|
+
disabled: false,
|
|
258
|
+
options: groups.map((group) => ({
|
|
259
|
+
label: group.name,
|
|
260
|
+
value: group.id.toString(),
|
|
261
|
+
})),
|
|
262
|
+
};
|
|
263
|
+
} catch (error) {
|
|
264
|
+
return {
|
|
265
|
+
disabled: true,
|
|
266
|
+
placeholder: 'Failed to load contact groups',
|
|
267
|
+
options: [],
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
}),
|
|
272
|
+
contact_branch_ids: Property.MultiSelectDropdown({
|
|
273
|
+
auth: bexioAuth,
|
|
274
|
+
displayName: 'Contact Sectors',
|
|
275
|
+
description: 'Select contact sectors',
|
|
276
|
+
required: false,
|
|
277
|
+
refreshers: [],
|
|
278
|
+
options: async ({ auth }) => {
|
|
279
|
+
if (!auth) {
|
|
280
|
+
return {
|
|
281
|
+
disabled: true,
|
|
282
|
+
placeholder: 'Connect your Bexio account first',
|
|
283
|
+
options: [],
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
try {
|
|
288
|
+
const client = new BexioClient(auth);
|
|
289
|
+
const branches = await client.get<Array<{ id: number; name: string }>>('/2.0/contact_branch');
|
|
290
|
+
|
|
291
|
+
return {
|
|
292
|
+
disabled: false,
|
|
293
|
+
options: branches.map((branch) => ({
|
|
294
|
+
label: branch.name,
|
|
295
|
+
value: branch.id.toString(),
|
|
296
|
+
})),
|
|
297
|
+
};
|
|
298
|
+
} catch (error) {
|
|
299
|
+
return {
|
|
300
|
+
disabled: true,
|
|
301
|
+
placeholder: 'Failed to load contact sectors',
|
|
302
|
+
options: [],
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
}),
|
|
307
|
+
user_id: Property.Dropdown({
|
|
308
|
+
auth: bexioAuth,
|
|
309
|
+
displayName: 'User',
|
|
310
|
+
description: 'User assigned to this contact',
|
|
311
|
+
required: true,
|
|
312
|
+
refreshers: [],
|
|
313
|
+
options: async ({ auth }) => {
|
|
314
|
+
if (!auth) {
|
|
315
|
+
return {
|
|
316
|
+
disabled: true,
|
|
317
|
+
placeholder: 'Connect your Bexio account first',
|
|
318
|
+
options: [],
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
try {
|
|
323
|
+
const client = new BexioClient(auth);
|
|
324
|
+
const users = await client.get<Array<{ id: number; firstname: string | null; lastname: string | null; email: string }>>('/3.0/users');
|
|
325
|
+
|
|
326
|
+
return {
|
|
327
|
+
disabled: false,
|
|
328
|
+
options: users.map((user) => ({
|
|
329
|
+
label: `${user.firstname || ''} ${user.lastname || ''}`.trim() || user.email,
|
|
330
|
+
value: user.id,
|
|
331
|
+
})),
|
|
332
|
+
};
|
|
333
|
+
} catch (error) {
|
|
334
|
+
return {
|
|
335
|
+
disabled: true,
|
|
336
|
+
placeholder: 'Failed to load users',
|
|
337
|
+
options: [],
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
}),
|
|
342
|
+
owner_id: Property.Dropdown({
|
|
343
|
+
auth: bexioAuth,
|
|
344
|
+
displayName: 'Owner',
|
|
345
|
+
description: 'Owner of this contact',
|
|
346
|
+
required: true,
|
|
347
|
+
refreshers: [],
|
|
348
|
+
options: async ({ auth }) => {
|
|
349
|
+
if (!auth) {
|
|
350
|
+
return {
|
|
351
|
+
disabled: true,
|
|
352
|
+
placeholder: 'Connect your Bexio account first',
|
|
353
|
+
options: [],
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
try {
|
|
358
|
+
const client = new BexioClient(auth);
|
|
359
|
+
const users = await client.get<Array<{ id: number; firstname: string | null; lastname: string | null; email: string }>>('/3.0/users');
|
|
360
|
+
|
|
361
|
+
return {
|
|
362
|
+
disabled: false,
|
|
363
|
+
options: users.map((user) => ({
|
|
364
|
+
label: `${user.firstname || ''} ${user.lastname || ''}`.trim() || user.email,
|
|
365
|
+
value: user.id,
|
|
366
|
+
})),
|
|
367
|
+
};
|
|
368
|
+
} catch (error) {
|
|
369
|
+
return {
|
|
370
|
+
disabled: true,
|
|
371
|
+
placeholder: 'Failed to load users',
|
|
372
|
+
options: [],
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
}),
|
|
377
|
+
},
|
|
378
|
+
async run(context) {
|
|
379
|
+
const client = new BexioClient(context.auth);
|
|
380
|
+
|
|
381
|
+
const props = context.propsValue;
|
|
382
|
+
const requestBody: Record<string, unknown> = {
|
|
383
|
+
contact_type_id: 1, // 1 = company
|
|
384
|
+
name_1: props['name_1'],
|
|
385
|
+
user_id: props['user_id'],
|
|
386
|
+
owner_id: props['owner_id'],
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
// Add optional fields only if they have values
|
|
390
|
+
if (props['name_2']) {
|
|
391
|
+
requestBody['name_2'] = props['name_2'];
|
|
392
|
+
}
|
|
393
|
+
if (props['nr'] !== undefined && props['nr'] !== null && props['nr'] !== '') {
|
|
394
|
+
requestBody['nr'] = props['nr'];
|
|
395
|
+
} else {
|
|
396
|
+
requestBody['nr'] = null; // Auto-assign
|
|
397
|
+
}
|
|
398
|
+
if (props['salutation_id']) {
|
|
399
|
+
requestBody['salutation_id'] = props['salutation_id'];
|
|
400
|
+
}
|
|
401
|
+
if (props['title_id']) {
|
|
402
|
+
requestBody['title_id'] = props['title_id'];
|
|
403
|
+
}
|
|
404
|
+
if (props['street_name']) {
|
|
405
|
+
requestBody['street_name'] = props['street_name'];
|
|
406
|
+
}
|
|
407
|
+
if (props['house_number']) {
|
|
408
|
+
requestBody['house_number'] = props['house_number'];
|
|
409
|
+
}
|
|
410
|
+
if (props['address_addition']) {
|
|
411
|
+
requestBody['address_addition'] = props['address_addition'];
|
|
412
|
+
}
|
|
413
|
+
if (props['postcode']) {
|
|
414
|
+
requestBody['postcode'] = props['postcode'];
|
|
415
|
+
}
|
|
416
|
+
if (props['city']) {
|
|
417
|
+
requestBody['city'] = props['city'];
|
|
418
|
+
}
|
|
419
|
+
if (props['country_id']) {
|
|
420
|
+
requestBody['country_id'] = props['country_id'];
|
|
421
|
+
}
|
|
422
|
+
if (props['mail']) {
|
|
423
|
+
requestBody['mail'] = props['mail'];
|
|
424
|
+
}
|
|
425
|
+
if (props['mail_second']) {
|
|
426
|
+
requestBody['mail_second'] = props['mail_second'];
|
|
427
|
+
}
|
|
428
|
+
if (props['phone_fixed']) {
|
|
429
|
+
requestBody['phone_fixed'] = props['phone_fixed'];
|
|
430
|
+
}
|
|
431
|
+
if (props['phone_fixed_second']) {
|
|
432
|
+
requestBody['phone_fixed_second'] = props['phone_fixed_second'];
|
|
433
|
+
}
|
|
434
|
+
if (props['phone_mobile']) {
|
|
435
|
+
requestBody['phone_mobile'] = props['phone_mobile'];
|
|
436
|
+
}
|
|
437
|
+
if (props['fax']) {
|
|
438
|
+
requestBody['fax'] = props['fax'];
|
|
439
|
+
}
|
|
440
|
+
if (props['url']) {
|
|
441
|
+
requestBody['url'] = props['url'];
|
|
442
|
+
}
|
|
443
|
+
if (props['skype_name']) {
|
|
444
|
+
requestBody['skype_name'] = props['skype_name'];
|
|
445
|
+
}
|
|
446
|
+
if (props['remarks']) {
|
|
447
|
+
requestBody['remarks'] = props['remarks'];
|
|
448
|
+
}
|
|
449
|
+
if (props['language_id']) {
|
|
450
|
+
requestBody['language_id'] = props['language_id'];
|
|
451
|
+
}
|
|
452
|
+
if (props['contact_group_ids'] && Array.isArray(props['contact_group_ids']) && props['contact_group_ids'].length > 0) {
|
|
453
|
+
requestBody['contact_group_ids'] = props['contact_group_ids'].join(',');
|
|
454
|
+
}
|
|
455
|
+
if (props['contact_branch_ids'] && Array.isArray(props['contact_branch_ids']) && props['contact_branch_ids'].length > 0) {
|
|
456
|
+
requestBody['contact_branch_ids'] = props['contact_branch_ids'].join(',');
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
const response = await client.post('/2.0/contact', requestBody);
|
|
460
|
+
|
|
461
|
+
return response;
|
|
462
|
+
},
|
|
463
|
+
});
|
|
464
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createAction, Property } from '@agnocon/pieces-framework';
|
|
2
|
+
import { bexioAuth } from '../auth';
|
|
3
|
+
import { HttpMethod, httpClient, AuthenticationType } from '@agnocon/pieces-common';
|
|
4
|
+
import { bexioCommon } from '../common/index';
|
|
5
|
+
import FormData from 'form-data';
|
|
6
|
+
|
|
7
|
+
export const createFileAction = createAction({
|
|
8
|
+
auth: bexioAuth,
|
|
9
|
+
name: 'create_file',
|
|
10
|
+
displayName: 'Create File',
|
|
11
|
+
description: 'Upload a new file to Bexio',
|
|
12
|
+
audience: 'both',
|
|
13
|
+
aiMetadata: { description: 'Uploads a file to the Bexio file manager via multipart form data, returning the stored file metadata. Use to add a document or attachment to Bexio storage; requires the file contents. Not idempotent: each call stores another copy of the file.', idempotent: false },
|
|
14
|
+
props: {
|
|
15
|
+
file: Property.File({
|
|
16
|
+
displayName: 'File',
|
|
17
|
+
description: 'The file to upload',
|
|
18
|
+
required: true,
|
|
19
|
+
}),
|
|
20
|
+
},
|
|
21
|
+
async run(context) {
|
|
22
|
+
const file = context.propsValue['file'];
|
|
23
|
+
|
|
24
|
+
// Create FormData for multipart/form-data upload
|
|
25
|
+
const formData = new FormData();
|
|
26
|
+
// Use Buffer directly - form-data package handles it correctly
|
|
27
|
+
formData.append('file', file.data, file.filename);
|
|
28
|
+
|
|
29
|
+
// Use httpClient directly for multipart/form-data since BexioClient uses JSON
|
|
30
|
+
const response = await httpClient.sendRequest<Array<{
|
|
31
|
+
id: number;
|
|
32
|
+
uuid: string;
|
|
33
|
+
name: string;
|
|
34
|
+
size_in_bytes: number;
|
|
35
|
+
extension: string;
|
|
36
|
+
mime_type: string;
|
|
37
|
+
uploader_email: string | null;
|
|
38
|
+
user_id: number;
|
|
39
|
+
is_archived: boolean;
|
|
40
|
+
source_id: number;
|
|
41
|
+
source_type: string | null;
|
|
42
|
+
is_referenced: boolean;
|
|
43
|
+
created_at: string;
|
|
44
|
+
}>>({
|
|
45
|
+
url: `${bexioCommon.baseUrl}/3.0/files`,
|
|
46
|
+
method: HttpMethod.POST,
|
|
47
|
+
authentication: {
|
|
48
|
+
type: AuthenticationType.BEARER_TOKEN,
|
|
49
|
+
token: context.auth.access_token,
|
|
50
|
+
},
|
|
51
|
+
headers: {
|
|
52
|
+
Accept: 'application/json',
|
|
53
|
+
// Don't set Content-Type manually - formData.getHeaders() will set it with boundary for multipart/form-data
|
|
54
|
+
...formData.getHeaders(),
|
|
55
|
+
},
|
|
56
|
+
body: formData,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return response.body;
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|