@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,666 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSalesQuoteAction = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // Vendored from Activepieces packages/pieces/community/bexio/src/lib/actions/create-sales-quote.ts (MIT).
6
+ // Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
7
+ const pieces_framework_1 = require("@agnocon/pieces-framework");
8
+ const auth_1 = require("../auth");
9
+ const client_1 = require("../common/client");
10
+ exports.createSalesQuoteAction = (0, pieces_framework_1.createAction)({
11
+ auth: auth_1.bexioAuth,
12
+ name: 'create_sales_quote',
13
+ displayName: 'Create Sales Quote',
14
+ description: 'Create a new product-based sales quote',
15
+ audience: 'both',
16
+ aiMetadata: { description: 'Create a new Bexio sales quote (kb_offer) with required user, language, currency, payment type, bank account, tax handling, validity dates, and at least one line-item position (custom, article, text, subtotal, discount, or page-break). Not idempotent: each call creates a separate quote, so guard against duplicates. Requires resolved IDs for contact, currency, taxes, units, and accounts; look these up first if not known.', idempotent: false },
17
+ props: {
18
+ document_nr: pieces_framework_1.Property.ShortText({
19
+ displayName: 'Document Number',
20
+ description: 'Quote number (required if automatic numbering is disabled)',
21
+ required: false,
22
+ }),
23
+ title: pieces_framework_1.Property.ShortText({
24
+ displayName: 'Title',
25
+ description: 'Quote title',
26
+ required: false,
27
+ }),
28
+ contact_id: pieces_framework_1.Property.Dropdown({
29
+ auth: auth_1.bexioAuth,
30
+ displayName: 'Contact',
31
+ description: 'The contact for this quote',
32
+ required: false,
33
+ refreshers: [],
34
+ options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
35
+ if (!auth) {
36
+ return {
37
+ disabled: true,
38
+ placeholder: 'Connect your Bexio account first',
39
+ options: [],
40
+ };
41
+ }
42
+ try {
43
+ const client = new client_1.BexioClient(auth);
44
+ const contacts = yield client.get('/2.0/contact');
45
+ return {
46
+ disabled: false,
47
+ options: contacts.map((contact) => {
48
+ const name = contact.name_2
49
+ ? `${contact.name_2} ${contact.name_1}`
50
+ : contact.name_1;
51
+ const label = contact.nr ? `${name} (#${contact.nr})` : name;
52
+ return {
53
+ label,
54
+ value: contact.id,
55
+ };
56
+ }),
57
+ };
58
+ }
59
+ catch (error) {
60
+ return {
61
+ disabled: true,
62
+ placeholder: 'Failed to load contacts',
63
+ options: [],
64
+ };
65
+ }
66
+ }),
67
+ }),
68
+ contact_sub_id: pieces_framework_1.Property.Dropdown({
69
+ auth: auth_1.bexioAuth,
70
+ displayName: 'Contact Sub',
71
+ description: 'Contact sub-address (optional)',
72
+ required: false,
73
+ refreshers: [],
74
+ options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
75
+ if (!auth) {
76
+ return {
77
+ disabled: true,
78
+ placeholder: 'Connect your Bexio account first',
79
+ options: [],
80
+ };
81
+ }
82
+ try {
83
+ const client = new client_1.BexioClient(auth);
84
+ const contacts = yield client.get('/2.0/contact');
85
+ return {
86
+ disabled: false,
87
+ options: contacts.map((contact) => {
88
+ const name = contact.name_2
89
+ ? `${contact.name_2} ${contact.name_1}`
90
+ : contact.name_1;
91
+ const label = contact.nr ? `${name} (#${contact.nr})` : name;
92
+ return {
93
+ label,
94
+ value: contact.id,
95
+ };
96
+ }),
97
+ };
98
+ }
99
+ catch (error) {
100
+ return {
101
+ disabled: true,
102
+ placeholder: 'Failed to load contacts',
103
+ options: [],
104
+ };
105
+ }
106
+ }),
107
+ }),
108
+ user_id: pieces_framework_1.Property.Dropdown({
109
+ auth: auth_1.bexioAuth,
110
+ displayName: 'User',
111
+ description: 'User responsible for this quote',
112
+ required: true,
113
+ refreshers: [],
114
+ options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
115
+ if (!auth) {
116
+ return {
117
+ disabled: true,
118
+ placeholder: 'Connect your Bexio account first',
119
+ options: [],
120
+ };
121
+ }
122
+ try {
123
+ const client = new client_1.BexioClient(auth);
124
+ const users = yield client.get('/3.0/users');
125
+ return {
126
+ disabled: false,
127
+ options: users.map((user) => {
128
+ const name = user.firstname && user.lastname
129
+ ? `${user.firstname} ${user.lastname}`
130
+ : user.email;
131
+ return {
132
+ label: name,
133
+ value: user.id,
134
+ };
135
+ }),
136
+ };
137
+ }
138
+ catch (error) {
139
+ return {
140
+ disabled: true,
141
+ placeholder: 'Failed to load users',
142
+ options: [],
143
+ };
144
+ }
145
+ }),
146
+ }),
147
+ pr_project_id: pieces_framework_1.Property.Dropdown({
148
+ auth: auth_1.bexioAuth,
149
+ displayName: 'Project',
150
+ description: 'Project associated with this quote',
151
+ required: false,
152
+ refreshers: [],
153
+ options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
154
+ if (!auth) {
155
+ return {
156
+ disabled: true,
157
+ placeholder: 'Connect your Bexio account first',
158
+ options: [],
159
+ };
160
+ }
161
+ try {
162
+ const client = new client_1.BexioClient(auth);
163
+ const projects = yield client.get('/2.0/pr_project');
164
+ return {
165
+ disabled: false,
166
+ options: projects.map((project) => ({
167
+ label: project.nr ? `${project.name} (#${project.nr})` : project.name,
168
+ value: project.id,
169
+ })),
170
+ };
171
+ }
172
+ catch (error) {
173
+ return {
174
+ disabled: true,
175
+ placeholder: 'Failed to load projects',
176
+ options: [],
177
+ };
178
+ }
179
+ }),
180
+ }),
181
+ language_id: pieces_framework_1.Property.Dropdown({
182
+ auth: auth_1.bexioAuth,
183
+ displayName: 'Language',
184
+ description: 'Language for the quote',
185
+ required: true,
186
+ refreshers: [],
187
+ options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
188
+ if (!auth) {
189
+ return {
190
+ disabled: true,
191
+ placeholder: 'Connect your Bexio account first',
192
+ options: [],
193
+ };
194
+ }
195
+ try {
196
+ const client = new client_1.BexioClient(auth);
197
+ const languages = yield client.get('/2.0/language');
198
+ return {
199
+ disabled: false,
200
+ options: languages.map((lang) => ({
201
+ label: lang.name,
202
+ value: lang.id,
203
+ })),
204
+ };
205
+ }
206
+ catch (error) {
207
+ return {
208
+ disabled: true,
209
+ placeholder: 'Failed to load languages',
210
+ options: [],
211
+ };
212
+ }
213
+ }),
214
+ }),
215
+ bank_account_id: pieces_framework_1.Property.Dropdown({
216
+ auth: auth_1.bexioAuth,
217
+ displayName: 'Bank Account',
218
+ description: 'Bank account for payment',
219
+ required: true,
220
+ refreshers: [],
221
+ options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
222
+ if (!auth) {
223
+ return {
224
+ disabled: true,
225
+ placeholder: 'Connect your Bexio account first',
226
+ options: [],
227
+ };
228
+ }
229
+ try {
230
+ const client = new client_1.BexioClient(auth);
231
+ const bankAccounts = yield client.get('/3.0/banking/accounts');
232
+ return {
233
+ disabled: false,
234
+ options: bankAccounts.map((account) => {
235
+ const iban = account.iban_nr || account.bank_account_nr;
236
+ return {
237
+ label: iban ? `${account.name} (${iban})` : account.name,
238
+ value: account.id,
239
+ };
240
+ }),
241
+ };
242
+ }
243
+ catch (error) {
244
+ return {
245
+ disabled: true,
246
+ placeholder: 'Failed to load bank accounts',
247
+ options: [],
248
+ };
249
+ }
250
+ }),
251
+ }),
252
+ currency_id: pieces_framework_1.Property.Dropdown({
253
+ auth: auth_1.bexioAuth,
254
+ displayName: 'Currency',
255
+ description: 'Currency for this quote',
256
+ required: true,
257
+ refreshers: [],
258
+ options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
259
+ if (!auth) {
260
+ return {
261
+ disabled: true,
262
+ placeholder: 'Connect your Bexio account first',
263
+ options: [],
264
+ };
265
+ }
266
+ try {
267
+ const client = new client_1.BexioClient(auth);
268
+ const currencies = yield client.get('/currencies');
269
+ return {
270
+ disabled: false,
271
+ options: currencies.map((currency) => ({
272
+ label: currency.name,
273
+ value: currency.id,
274
+ })),
275
+ };
276
+ }
277
+ catch (error) {
278
+ return {
279
+ disabled: true,
280
+ placeholder: 'Failed to load currencies',
281
+ options: [],
282
+ };
283
+ }
284
+ }),
285
+ }),
286
+ payment_type_id: pieces_framework_1.Property.Dropdown({
287
+ auth: auth_1.bexioAuth,
288
+ displayName: 'Payment Type',
289
+ description: 'Payment type for this quote',
290
+ required: true,
291
+ refreshers: [],
292
+ options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
293
+ if (!auth) {
294
+ return {
295
+ disabled: true,
296
+ placeholder: 'Connect your Bexio account first',
297
+ options: [],
298
+ };
299
+ }
300
+ try {
301
+ const client = new client_1.BexioClient(auth);
302
+ const paymentTypes = yield client.get('/2.0/payment_type');
303
+ return {
304
+ disabled: false,
305
+ options: paymentTypes.map((type) => ({
306
+ label: type.name,
307
+ value: type.id,
308
+ })),
309
+ };
310
+ }
311
+ catch (error) {
312
+ return {
313
+ disabled: true,
314
+ placeholder: 'Failed to load payment types',
315
+ options: [],
316
+ };
317
+ }
318
+ }),
319
+ }),
320
+ header: pieces_framework_1.Property.LongText({
321
+ displayName: 'Header',
322
+ description: 'Header text for the quote',
323
+ required: false,
324
+ }),
325
+ footer: pieces_framework_1.Property.LongText({
326
+ displayName: 'Footer',
327
+ description: 'Footer text for the quote',
328
+ required: false,
329
+ }),
330
+ mwst_type: pieces_framework_1.Property.StaticDropdown({
331
+ displayName: 'Tax Type',
332
+ description: 'How taxes are handled',
333
+ required: true,
334
+ defaultValue: 0,
335
+ options: {
336
+ disabled: false,
337
+ options: [
338
+ { label: 'Including taxes', value: 0 },
339
+ { label: 'Excluding taxes', value: 1 },
340
+ { label: 'Exempt from taxes', value: 2 },
341
+ ],
342
+ },
343
+ }),
344
+ mwst_is_net: pieces_framework_1.Property.Checkbox({
345
+ displayName: 'Tax is Net',
346
+ description: 'If taxes are included, set to true to add taxes to total, false to include in total',
347
+ required: false,
348
+ defaultValue: false,
349
+ }),
350
+ show_position_taxes: pieces_framework_1.Property.Checkbox({
351
+ displayName: 'Show Position Taxes',
352
+ description: 'Show taxes for each position',
353
+ required: false,
354
+ defaultValue: false,
355
+ }),
356
+ is_valid_from: pieces_framework_1.Property.ShortText({
357
+ displayName: 'Valid From',
358
+ description: 'Quote valid from date (YYYY-MM-DD)',
359
+ required: true,
360
+ }),
361
+ is_valid_until: pieces_framework_1.Property.ShortText({
362
+ displayName: 'Valid Until',
363
+ description: 'Quote valid until date (YYYY-MM-DD)',
364
+ required: true,
365
+ }),
366
+ contact_address_manual: pieces_framework_1.Property.LongText({
367
+ displayName: 'Manual Contact Address',
368
+ description: 'Override contact address (leave empty to use contact address)',
369
+ required: false,
370
+ }),
371
+ delivery_address_type: pieces_framework_1.Property.StaticDropdown({
372
+ displayName: 'Delivery Address Type',
373
+ description: 'Type of delivery address',
374
+ required: false,
375
+ defaultValue: 0,
376
+ options: {
377
+ disabled: false,
378
+ options: [
379
+ { label: 'Use Invoice Address', value: 0 },
380
+ { label: 'Use Custom Address', value: 1 },
381
+ ],
382
+ },
383
+ }),
384
+ delivery_address_manual_text: pieces_framework_1.Property.LongText({
385
+ displayName: 'Manual Delivery Address',
386
+ description: 'Custom delivery address (only used if delivery address type is set to custom)',
387
+ required: false,
388
+ }),
389
+ api_reference: pieces_framework_1.Property.ShortText({
390
+ displayName: 'API Reference',
391
+ description: 'Reference for API use (can only be edited via API)',
392
+ required: false,
393
+ }),
394
+ viewed_by_client_at: pieces_framework_1.Property.DateTime({
395
+ displayName: 'Viewed By Client At',
396
+ description: 'Date when the quote was viewed by the client',
397
+ required: false,
398
+ }),
399
+ kb_terms_of_payment_template_id: pieces_framework_1.Property.Number({
400
+ displayName: 'Terms of Payment Template ID',
401
+ description: 'Terms of payment template ID',
402
+ required: false,
403
+ }),
404
+ template_slug: pieces_framework_1.Property.Dropdown({
405
+ auth: auth_1.bexioAuth,
406
+ displayName: 'Document Template',
407
+ description: 'Document template for the quote',
408
+ required: false,
409
+ refreshers: [],
410
+ options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
411
+ if (!auth) {
412
+ return {
413
+ disabled: true,
414
+ placeholder: 'Connect your Bexio account first',
415
+ options: [],
416
+ };
417
+ }
418
+ try {
419
+ const client = new client_1.BexioClient(auth);
420
+ const templates = yield client.get('/3.0/document_templates');
421
+ return {
422
+ disabled: false,
423
+ options: templates.map((template) => ({
424
+ label: template.is_default ? `${template.name} (Default)` : template.name,
425
+ value: template.template_slug,
426
+ })),
427
+ };
428
+ }
429
+ catch (error) {
430
+ return {
431
+ disabled: true,
432
+ placeholder: 'Failed to load templates',
433
+ options: [],
434
+ };
435
+ }
436
+ }),
437
+ }),
438
+ positionFields: pieces_framework_1.Property.DynamicProperties({
439
+ auth: auth_1.bexioAuth,
440
+ displayName: 'Quote Positions',
441
+ description: 'Configure quote line items',
442
+ required: true,
443
+ refreshers: ['auth'],
444
+ props: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
445
+ let units = [];
446
+ let accounts = [];
447
+ let taxes = [];
448
+ if (auth) {
449
+ try {
450
+ const client = new client_1.BexioClient(auth);
451
+ units = yield client.get('/2.0/unit').catch(() => []);
452
+ accounts = yield client.get('/accounts').catch(() => []);
453
+ const taxesResponse = yield client.get('/3.0/taxes?types=sales_tax&scope=active').catch(() => []);
454
+ taxes = taxesResponse.map((tax) => ({
455
+ id: tax.id,
456
+ name: tax.display_name || tax.name,
457
+ percentage: tax.value.toString(),
458
+ }));
459
+ }
460
+ catch (error) {
461
+ // Ignore error, use empty array as fallback
462
+ }
463
+ }
464
+ const unitOptions = units.map((unit) => ({ label: unit.name, value: unit.id }));
465
+ const accountOptions = accounts.map((acc) => ({ label: `${acc.account_no} - ${acc.name}`, value: acc.id }));
466
+ const taxOptions = taxes.map((tax) => ({ label: `${tax.name} (${tax.percentage}%)`, value: tax.id }));
467
+ return {
468
+ positions: pieces_framework_1.Property.Array({
469
+ displayName: 'Positions',
470
+ description: 'Quote line items',
471
+ required: true,
472
+ properties: {
473
+ type: pieces_framework_1.Property.StaticDropdown({
474
+ displayName: 'Position Type',
475
+ description: 'Type of quote position',
476
+ required: true,
477
+ defaultValue: 'KbPositionCustom',
478
+ options: {
479
+ disabled: false,
480
+ options: [
481
+ { label: 'Custom Position', value: 'KbPositionCustom' },
482
+ { label: 'Article Position', value: 'KbPositionArticle' },
483
+ { label: 'Text Position', value: 'KbPositionText' },
484
+ { label: 'Subtotal Position', value: 'KbPositionSubtotal' },
485
+ { label: 'Page Break Position', value: 'KbPositionPagebreak' },
486
+ { label: 'Discount Position', value: 'KbPositionDiscount' },
487
+ ],
488
+ },
489
+ }),
490
+ amount: pieces_framework_1.Property.ShortText({
491
+ displayName: 'Amount',
492
+ description: 'Quantity/amount',
493
+ required: true,
494
+ }),
495
+ unit_id: unitOptions.length > 0
496
+ ? pieces_framework_1.Property.StaticDropdown({
497
+ displayName: 'Unit',
498
+ description: 'Unit of measurement',
499
+ required: false,
500
+ options: {
501
+ disabled: false,
502
+ options: unitOptions,
503
+ },
504
+ })
505
+ : pieces_framework_1.Property.Number({
506
+ displayName: 'Unit ID',
507
+ description: 'Unit ID (use List Units action to find IDs)',
508
+ required: false,
509
+ }),
510
+ account_id: accountOptions.length > 0
511
+ ? pieces_framework_1.Property.StaticDropdown({
512
+ displayName: 'Account',
513
+ description: 'Account for this position',
514
+ required: false,
515
+ options: {
516
+ disabled: false,
517
+ options: accountOptions,
518
+ },
519
+ })
520
+ : pieces_framework_1.Property.Number({
521
+ displayName: 'Account ID',
522
+ description: 'Account ID (use List Accounts action to find IDs)',
523
+ required: false,
524
+ }),
525
+ tax_id: taxOptions.length > 0
526
+ ? pieces_framework_1.Property.StaticDropdown({
527
+ displayName: 'Tax',
528
+ description: 'Tax rate (only active sales taxes)',
529
+ required: false,
530
+ options: {
531
+ disabled: false,
532
+ options: taxOptions,
533
+ },
534
+ })
535
+ : pieces_framework_1.Property.Number({
536
+ displayName: 'Tax ID',
537
+ description: 'Tax ID (use List Taxes action to find IDs)',
538
+ required: false,
539
+ }),
540
+ text: pieces_framework_1.Property.LongText({
541
+ displayName: 'Description',
542
+ description: 'Position description/text',
543
+ required: false,
544
+ }),
545
+ unit_price: pieces_framework_1.Property.ShortText({
546
+ displayName: 'Unit Price',
547
+ description: 'Price per unit (max 6 decimals)',
548
+ required: false,
549
+ }),
550
+ discount_in_percent: pieces_framework_1.Property.ShortText({
551
+ displayName: 'Discount (%)',
552
+ description: 'Discount percentage (max 6 decimals)',
553
+ required: false,
554
+ }),
555
+ parent_id: pieces_framework_1.Property.Number({
556
+ displayName: 'Parent ID',
557
+ description: 'Parent position ID (for grouped positions)',
558
+ required: false,
559
+ }),
560
+ },
561
+ }),
562
+ };
563
+ }),
564
+ }),
565
+ },
566
+ run(context) {
567
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
568
+ const client = new client_1.BexioClient(context.auth);
569
+ const props = context.propsValue;
570
+ const requestBody = {
571
+ user_id: props['user_id'],
572
+ language_id: props['language_id'],
573
+ bank_account_id: props['bank_account_id'],
574
+ currency_id: props['currency_id'],
575
+ payment_type_id: props['payment_type_id'],
576
+ mwst_type: props['mwst_type'],
577
+ is_valid_from: props['is_valid_from'],
578
+ is_valid_until: props['is_valid_until'],
579
+ };
580
+ if (props['document_nr']) {
581
+ requestBody['document_nr'] = props['document_nr'];
582
+ }
583
+ if (props['title'] !== undefined) {
584
+ requestBody['title'] = props['title'] || null;
585
+ }
586
+ if (props['contact_id']) {
587
+ requestBody['contact_id'] = props['contact_id'];
588
+ }
589
+ if (props['contact_sub_id']) {
590
+ requestBody['contact_sub_id'] = props['contact_sub_id'];
591
+ }
592
+ if (props['pr_project_id']) {
593
+ requestBody['pr_project_id'] = props['pr_project_id'];
594
+ }
595
+ if (props['header']) {
596
+ requestBody['header'] = props['header'];
597
+ }
598
+ if (props['footer']) {
599
+ requestBody['footer'] = props['footer'];
600
+ }
601
+ if (props['mwst_is_net'] !== undefined) {
602
+ requestBody['mwst_is_net'] = props['mwst_is_net'];
603
+ }
604
+ if (props['show_position_taxes'] !== undefined) {
605
+ requestBody['show_position_taxes'] = props['show_position_taxes'];
606
+ }
607
+ if (props['contact_address_manual']) {
608
+ requestBody['contact_address_manual'] = props['contact_address_manual'];
609
+ }
610
+ if (props['delivery_address_type'] !== undefined) {
611
+ requestBody['delivery_address_type'] = props['delivery_address_type'];
612
+ }
613
+ if (props['delivery_address_manual_text']) {
614
+ requestBody['delivery_address_manual'] = props['delivery_address_manual_text'];
615
+ }
616
+ if (props['api_reference']) {
617
+ requestBody['api_reference'] = props['api_reference'];
618
+ }
619
+ if (props['viewed_by_client_at']) {
620
+ requestBody['viewed_by_client_at'] = props['viewed_by_client_at'];
621
+ }
622
+ if (props['kb_terms_of_payment_template_id']) {
623
+ requestBody['kb_terms_of_payment_template_id'] = props['kb_terms_of_payment_template_id'];
624
+ }
625
+ if (props['template_slug']) {
626
+ requestBody['template_slug'] = props['template_slug'];
627
+ }
628
+ const positionFields = props['positionFields'];
629
+ if (positionFields && positionFields['positions'] && Array.isArray(positionFields['positions'])) {
630
+ requestBody['positions'] = positionFields['positions'].map((position) => {
631
+ const pos = {
632
+ type: position['type'] || 'KbPositionCustom',
633
+ };
634
+ if (position['amount']) {
635
+ pos['amount'] = position['amount'];
636
+ }
637
+ if (position['unit_id']) {
638
+ pos['unit_id'] = position['unit_id'];
639
+ }
640
+ if (position['account_id']) {
641
+ pos['account_id'] = position['account_id'];
642
+ }
643
+ if (position['tax_id']) {
644
+ pos['tax_id'] = position['tax_id'];
645
+ }
646
+ if (position['text']) {
647
+ pos['text'] = position['text'];
648
+ }
649
+ if (position['unit_price']) {
650
+ pos['unit_price'] = position['unit_price'];
651
+ }
652
+ if (position['discount_in_percent']) {
653
+ pos['discount_in_percent'] = position['discount_in_percent'];
654
+ }
655
+ if (position['parent_id']) {
656
+ pos['parent_id'] = position['parent_id'];
657
+ }
658
+ return pos;
659
+ });
660
+ }
661
+ const response = yield client.post('/2.0/kb_offer', requestBody);
662
+ return response;
663
+ });
664
+ },
665
+ });
666
+ //# sourceMappingURL=create-sales-quote.js.map