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