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