@frogbotai/piece-xero 0.29.0 → 0.30.0
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/dist/actions.d.ts +2 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +404 -235
- package/dist/actions.js.map +1 -1
- package/dist/client.js +58 -37
- package/dist/client.js.map +1 -1
- package/dist/config.js +14 -4
- package/dist/config.js.map +1 -1
- package/dist/define.js +1 -0
- package/dist/define.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +26 -13
- package/dist/index.js.map +1 -1
- package/dist/triggers.js +93 -75
- package/dist/triggers.js.map +1 -1
- package/dist/webhook.js +10 -11
- package/dist/webhook.js.map +1 -1
- package/package.json +4 -4
package/dist/actions.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
import { filesCollectionSlug } from 'frogbot/pieces';
|
|
1
2
|
import { z } from 'zod';
|
|
2
3
|
import { xeroResponse } from './client.js';
|
|
3
4
|
import { defineAction } from './define.js';
|
|
4
|
-
const tenant = {
|
|
5
|
+
const tenant = {
|
|
6
|
+
tenantId: z.string().min(1).meta({
|
|
7
|
+
label: 'Organization'
|
|
8
|
+
})
|
|
9
|
+
};
|
|
5
10
|
const date = z.string().regex(/^\d{4}-\d{2}-\d{2}$/);
|
|
6
|
-
const lineAmountType = z.enum([
|
|
11
|
+
const lineAmountType = z.enum([
|
|
12
|
+
'Exclusive',
|
|
13
|
+
'Inclusive',
|
|
14
|
+
'NoTax'
|
|
15
|
+
]);
|
|
7
16
|
const lineItem = z.object({
|
|
8
17
|
Description: z.string().min(1),
|
|
9
18
|
Quantity: z.number().optional(),
|
|
@@ -12,25 +21,36 @@ const lineItem = z.object({
|
|
|
12
21
|
ItemCode: z.string().optional(),
|
|
13
22
|
TaxType: z.string().optional(),
|
|
14
23
|
DiscountRate: z.number().optional(),
|
|
15
|
-
LineItemID: z.string().optional()
|
|
24
|
+
LineItemID: z.string().optional()
|
|
16
25
|
});
|
|
17
|
-
async function tenantOptions({ client, req
|
|
26
|
+
async function tenantOptions({ client, req }) {
|
|
18
27
|
const tenants = await client.listTenants(req.signal ?? undefined);
|
|
19
|
-
return tenants.map(({ tenantId, tenantName })
|
|
28
|
+
return tenants.map(({ tenantId, tenantName })=>({
|
|
29
|
+
label: tenantName,
|
|
30
|
+
value: tenantId
|
|
31
|
+
}));
|
|
20
32
|
}
|
|
21
33
|
const apiDefaults = {
|
|
22
34
|
output: xeroResponse,
|
|
23
35
|
idempotent: false,
|
|
24
|
-
options: {
|
|
36
|
+
options: {
|
|
37
|
+
tenantId: tenantOptions
|
|
38
|
+
}
|
|
25
39
|
};
|
|
26
40
|
function accountingRequest(client, input, path, method, body, signal) {
|
|
27
|
-
return client.request({
|
|
41
|
+
return client.request({
|
|
42
|
+
path,
|
|
43
|
+
method,
|
|
44
|
+
tenantId: input.tenantId,
|
|
45
|
+
body,
|
|
46
|
+
signal
|
|
47
|
+
}, xeroResponse);
|
|
28
48
|
}
|
|
29
49
|
const createOrUpdateContactInput = z.object({
|
|
30
50
|
...tenant,
|
|
31
51
|
contactId: z.string().optional(),
|
|
32
52
|
name: z.string().min(1),
|
|
33
|
-
email: z.string().email().optional()
|
|
53
|
+
email: z.string().email().optional()
|
|
34
54
|
});
|
|
35
55
|
const createOrUpdateContact = defineAction({
|
|
36
56
|
...apiDefaults,
|
|
@@ -38,9 +58,16 @@ const createOrUpdateContact = defineAction({
|
|
|
38
58
|
label: 'Create or update contact',
|
|
39
59
|
description: 'Create a Xero contact or update one by ID.',
|
|
40
60
|
input: createOrUpdateContactInput,
|
|
41
|
-
async run({ input, client, req }) {
|
|
42
|
-
return accountingRequest(client, input, `/Contacts${input.contactId ? `/${input.contactId}` : ''}`, 'POST', {
|
|
43
|
-
|
|
61
|
+
async run ({ input, client, req }) {
|
|
62
|
+
return accountingRequest(client, input, `/Contacts${input.contactId ? `/${input.contactId}` : ''}`, 'POST', {
|
|
63
|
+
Contacts: [
|
|
64
|
+
{
|
|
65
|
+
Name: input.name,
|
|
66
|
+
EmailAddress: input.email
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
}, req.signal ?? undefined);
|
|
70
|
+
}
|
|
44
71
|
});
|
|
45
72
|
const createOrUpdateInvoiceInput = z.object({
|
|
46
73
|
...tenant,
|
|
@@ -52,7 +79,13 @@ const createOrUpdateInvoiceInput = z.object({
|
|
|
52
79
|
date: date.optional(),
|
|
53
80
|
dueDate: date,
|
|
54
81
|
reference: z.string().optional(),
|
|
55
|
-
status: z.enum([
|
|
82
|
+
status: z.enum([
|
|
83
|
+
'DRAFT',
|
|
84
|
+
'SUBMITTED',
|
|
85
|
+
'AUTHORISED',
|
|
86
|
+
'DELETED',
|
|
87
|
+
'VOIDED'
|
|
88
|
+
])
|
|
56
89
|
});
|
|
57
90
|
const createOrUpdateInvoice = defineAction({
|
|
58
91
|
...apiDefaults,
|
|
@@ -60,28 +93,34 @@ const createOrUpdateInvoice = defineAction({
|
|
|
60
93
|
label: 'Create or update invoice',
|
|
61
94
|
description: 'Create or update an accounts-receivable invoice.',
|
|
62
95
|
input: createOrUpdateInvoiceInput,
|
|
63
|
-
async run({ input, client, req }) {
|
|
96
|
+
async run ({ input, client, req }) {
|
|
64
97
|
return accountingRequest(client, input, `/Invoices${input.invoiceId ? `/${input.invoiceId}` : ''}`, 'POST', {
|
|
65
98
|
Invoices: [
|
|
66
99
|
{
|
|
67
100
|
Type: 'ACCREC',
|
|
68
|
-
Contact: {
|
|
69
|
-
|
|
101
|
+
Contact: {
|
|
102
|
+
ContactID: input.contactId,
|
|
103
|
+
Name: input.name,
|
|
104
|
+
EmailAddress: input.email
|
|
105
|
+
},
|
|
106
|
+
LineItems: [
|
|
107
|
+
input.lineItem
|
|
108
|
+
],
|
|
70
109
|
Date: input.date,
|
|
71
110
|
DueDate: input.dueDate,
|
|
72
111
|
Reference: input.reference,
|
|
73
|
-
Status: input.status
|
|
74
|
-
}
|
|
75
|
-
]
|
|
112
|
+
Status: input.status
|
|
113
|
+
}
|
|
114
|
+
]
|
|
76
115
|
}, req.signal ?? undefined);
|
|
77
|
-
}
|
|
116
|
+
}
|
|
78
117
|
});
|
|
79
118
|
const allocateCreditNoteInput = z.object({
|
|
80
119
|
...tenant,
|
|
81
120
|
creditNoteId: z.string().min(1),
|
|
82
121
|
invoiceId: z.string().min(1),
|
|
83
122
|
amount: z.number(),
|
|
84
|
-
date: date.optional()
|
|
123
|
+
date: date.optional()
|
|
85
124
|
});
|
|
86
125
|
const allocateCreditNote = defineAction({
|
|
87
126
|
...apiDefaults,
|
|
@@ -89,13 +128,19 @@ const allocateCreditNote = defineAction({
|
|
|
89
128
|
label: 'Allocate credit note',
|
|
90
129
|
description: 'Allocate a credit note to an invoice.',
|
|
91
130
|
input: allocateCreditNoteInput,
|
|
92
|
-
async run({ input, client, req }) {
|
|
131
|
+
async run ({ input, client, req }) {
|
|
93
132
|
return accountingRequest(client, input, `/CreditNotes/${input.creditNoteId}/Allocations`, 'POST', {
|
|
94
133
|
Allocations: [
|
|
95
|
-
{
|
|
96
|
-
|
|
134
|
+
{
|
|
135
|
+
Invoice: {
|
|
136
|
+
InvoiceID: input.invoiceId
|
|
137
|
+
},
|
|
138
|
+
Amount: input.amount,
|
|
139
|
+
Date: input.date
|
|
140
|
+
}
|
|
141
|
+
]
|
|
97
142
|
}, req.signal ?? undefined);
|
|
98
|
-
}
|
|
143
|
+
}
|
|
99
144
|
});
|
|
100
145
|
const createBankTransferInput = z.object({
|
|
101
146
|
...tenant,
|
|
@@ -105,7 +150,7 @@ const createBankTransferInput = z.object({
|
|
|
105
150
|
date: date.optional(),
|
|
106
151
|
reference: z.string().optional(),
|
|
107
152
|
fromIsReconciled: z.boolean().default(false),
|
|
108
|
-
toIsReconciled: z.boolean().default(false)
|
|
153
|
+
toIsReconciled: z.boolean().default(false)
|
|
109
154
|
});
|
|
110
155
|
const createBankTransfer = defineAction({
|
|
111
156
|
...apiDefaults,
|
|
@@ -113,21 +158,25 @@ const createBankTransfer = defineAction({
|
|
|
113
158
|
label: 'Create bank transfer',
|
|
114
159
|
description: 'Transfer between bank accounts.',
|
|
115
160
|
input: createBankTransferInput,
|
|
116
|
-
async run({ input, client, req }) {
|
|
161
|
+
async run ({ input, client, req }) {
|
|
117
162
|
return accountingRequest(client, input, '/BankTransfers', 'PUT', {
|
|
118
163
|
BankTransfers: [
|
|
119
164
|
{
|
|
120
|
-
FromBankAccount: {
|
|
121
|
-
|
|
165
|
+
FromBankAccount: {
|
|
166
|
+
AccountID: input.fromBankAccountId
|
|
167
|
+
},
|
|
168
|
+
ToBankAccount: {
|
|
169
|
+
AccountID: input.toBankAccountId
|
|
170
|
+
},
|
|
122
171
|
Amount: input.amount,
|
|
123
172
|
Date: input.date,
|
|
124
173
|
Reference: input.reference,
|
|
125
174
|
FromIsReconciled: input.fromIsReconciled || undefined,
|
|
126
|
-
ToIsReconciled: input.toIsReconciled || undefined
|
|
127
|
-
}
|
|
128
|
-
]
|
|
175
|
+
ToIsReconciled: input.toIsReconciled || undefined
|
|
176
|
+
}
|
|
177
|
+
]
|
|
129
178
|
}, req.signal ?? undefined);
|
|
130
|
-
}
|
|
179
|
+
}
|
|
131
180
|
});
|
|
132
181
|
const createQuoteInput = z.object({
|
|
133
182
|
...tenant,
|
|
@@ -141,7 +190,7 @@ const createQuoteInput = z.object({
|
|
|
141
190
|
title: z.string().optional(),
|
|
142
191
|
summary: z.string().optional(),
|
|
143
192
|
terms: z.string().optional(),
|
|
144
|
-
status: z.literal('DRAFT').default('DRAFT')
|
|
193
|
+
status: z.literal('DRAFT').default('DRAFT')
|
|
145
194
|
});
|
|
146
195
|
const createQuote = defineAction({
|
|
147
196
|
...apiDefaults,
|
|
@@ -149,42 +198,53 @@ const createQuote = defineAction({
|
|
|
149
198
|
label: 'Create quote',
|
|
150
199
|
description: 'Create a draft quote.',
|
|
151
200
|
input: createQuoteInput,
|
|
152
|
-
async run({ input, client, req }) {
|
|
201
|
+
async run ({ input, client, req }) {
|
|
153
202
|
return accountingRequest(client, input, '/Quotes', 'POST', {
|
|
154
203
|
Quotes: [
|
|
155
204
|
{
|
|
156
|
-
Contact: {
|
|
205
|
+
Contact: {
|
|
206
|
+
ContactID: input.contactId
|
|
207
|
+
},
|
|
157
208
|
Date: input.date,
|
|
158
209
|
ExpiryDate: input.expiryDate,
|
|
159
|
-
LineItems: [
|
|
210
|
+
LineItems: [
|
|
211
|
+
input.lineItem
|
|
212
|
+
],
|
|
160
213
|
LineAmountTypes: input.lineAmountTypes,
|
|
161
214
|
Reference: input.reference,
|
|
162
215
|
QuoteNumber: input.quoteNumber,
|
|
163
216
|
Title: input.title,
|
|
164
217
|
Summary: input.summary,
|
|
165
218
|
Terms: input.terms,
|
|
166
|
-
Status: input.status
|
|
167
|
-
}
|
|
168
|
-
]
|
|
219
|
+
Status: input.status
|
|
220
|
+
}
|
|
221
|
+
]
|
|
169
222
|
}, req.signal ?? undefined);
|
|
170
|
-
}
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
const sendInvoiceEmailInput = z.object({
|
|
226
|
+
...tenant,
|
|
227
|
+
invoiceId: z.string().min(1)
|
|
171
228
|
});
|
|
172
|
-
const sendInvoiceEmailInput = z.object({ ...tenant, invoiceId: z.string().min(1) });
|
|
173
229
|
const sendInvoiceEmail = defineAction({
|
|
174
230
|
slug: 'sendInvoiceEmail',
|
|
175
231
|
label: 'Send invoice email',
|
|
176
232
|
description: 'Send a sales invoice by email.',
|
|
177
233
|
input: sendInvoiceEmailInput,
|
|
178
|
-
output: z.object({
|
|
179
|
-
|
|
234
|
+
output: z.object({
|
|
235
|
+
success: z.literal(true)
|
|
236
|
+
}),
|
|
237
|
+
async run ({ input, client, req }) {
|
|
180
238
|
await client.request({
|
|
181
239
|
path: `/Invoices/${input.invoiceId}/Email`,
|
|
182
240
|
method: 'POST',
|
|
183
241
|
tenantId: input.tenantId,
|
|
184
|
-
signal: req.signal ?? undefined
|
|
242
|
+
signal: req.signal ?? undefined
|
|
185
243
|
}, z.null());
|
|
186
|
-
return {
|
|
187
|
-
|
|
244
|
+
return {
|
|
245
|
+
success: true
|
|
246
|
+
};
|
|
247
|
+
}
|
|
188
248
|
});
|
|
189
249
|
const invoiceBase = {
|
|
190
250
|
...tenant,
|
|
@@ -194,7 +254,11 @@ const invoiceBase = {
|
|
|
194
254
|
dueDate: date.optional(),
|
|
195
255
|
lineAmountTypes: lineAmountType.optional(),
|
|
196
256
|
invoiceNumber: z.string().optional(),
|
|
197
|
-
status: z.enum([
|
|
257
|
+
status: z.enum([
|
|
258
|
+
'DRAFT',
|
|
259
|
+
'SUBMITTED',
|
|
260
|
+
'AUTHORISED'
|
|
261
|
+
]).default('DRAFT')
|
|
198
262
|
};
|
|
199
263
|
const createBillInput = z.object(invoiceBase);
|
|
200
264
|
const createBill = defineAction({
|
|
@@ -203,22 +267,26 @@ const createBill = defineAction({
|
|
|
203
267
|
label: 'Create bill',
|
|
204
268
|
description: 'Create an accounts-payable bill.',
|
|
205
269
|
input: createBillInput,
|
|
206
|
-
async run({ input, client, req }) {
|
|
270
|
+
async run ({ input, client, req }) {
|
|
207
271
|
return accountingRequest(client, input, '/Invoices', 'POST', {
|
|
208
272
|
Invoices: [
|
|
209
273
|
{
|
|
210
274
|
Type: 'ACCPAY',
|
|
211
|
-
Contact: {
|
|
212
|
-
|
|
275
|
+
Contact: {
|
|
276
|
+
ContactID: input.contactId
|
|
277
|
+
},
|
|
278
|
+
LineItems: [
|
|
279
|
+
input.lineItem
|
|
280
|
+
],
|
|
213
281
|
Date: input.date,
|
|
214
282
|
DueDate: input.dueDate,
|
|
215
283
|
LineAmountTypes: input.lineAmountTypes,
|
|
216
284
|
InvoiceNumber: input.invoiceNumber,
|
|
217
|
-
Status: input.status
|
|
218
|
-
}
|
|
219
|
-
]
|
|
285
|
+
Status: input.status
|
|
286
|
+
}
|
|
287
|
+
]
|
|
220
288
|
}, req.signal ?? undefined);
|
|
221
|
-
}
|
|
289
|
+
}
|
|
222
290
|
});
|
|
223
291
|
const createPaymentInput = z.object({
|
|
224
292
|
...tenant,
|
|
@@ -227,7 +295,7 @@ const createPaymentInput = z.object({
|
|
|
227
295
|
amount: z.number(),
|
|
228
296
|
date,
|
|
229
297
|
reference: z.string().optional(),
|
|
230
|
-
isReconciled: z.boolean().default(false)
|
|
298
|
+
isReconciled: z.boolean().default(false)
|
|
231
299
|
});
|
|
232
300
|
const createPayment = defineAction({
|
|
233
301
|
...apiDefaults,
|
|
@@ -235,20 +303,24 @@ const createPayment = defineAction({
|
|
|
235
303
|
label: 'Create payment',
|
|
236
304
|
description: 'Apply a payment to an invoice.',
|
|
237
305
|
input: createPaymentInput,
|
|
238
|
-
async run({ input, client, req }) {
|
|
306
|
+
async run ({ input, client, req }) {
|
|
239
307
|
return accountingRequest(client, input, '/Payments', 'PUT', {
|
|
240
308
|
Payments: [
|
|
241
309
|
{
|
|
242
|
-
Invoice: {
|
|
243
|
-
|
|
310
|
+
Invoice: {
|
|
311
|
+
InvoiceID: input.invoiceId
|
|
312
|
+
},
|
|
313
|
+
Account: {
|
|
314
|
+
AccountID: input.accountId
|
|
315
|
+
},
|
|
244
316
|
Amount: input.amount,
|
|
245
317
|
Date: input.date,
|
|
246
318
|
Reference: input.reference,
|
|
247
|
-
IsReconciled: input.isReconciled || undefined
|
|
248
|
-
}
|
|
249
|
-
]
|
|
319
|
+
IsReconciled: input.isReconciled || undefined
|
|
320
|
+
}
|
|
321
|
+
]
|
|
250
322
|
}, req.signal ?? undefined);
|
|
251
|
-
}
|
|
323
|
+
}
|
|
252
324
|
});
|
|
253
325
|
const purchaseOrderInput = z.object({
|
|
254
326
|
...tenant,
|
|
@@ -260,12 +332,18 @@ const purchaseOrderInput = z.object({
|
|
|
260
332
|
purchaseOrderNumber: z.string().optional(),
|
|
261
333
|
reference: z.string().optional(),
|
|
262
334
|
brandingThemeId: z.string().optional(),
|
|
263
|
-
status: z.enum([
|
|
335
|
+
status: z.enum([
|
|
336
|
+
'DRAFT',
|
|
337
|
+
'SUBMITTED',
|
|
338
|
+
'AUTHORISED',
|
|
339
|
+
'BILLED',
|
|
340
|
+
'DELETED'
|
|
341
|
+
]).default('DRAFT'),
|
|
264
342
|
deliveryAddress: z.string().optional(),
|
|
265
343
|
attentionTo: z.string().optional(),
|
|
266
344
|
telephone: z.string().optional(),
|
|
267
345
|
deliveryInstructions: z.string().optional(),
|
|
268
|
-
expectedArrivalDate: date.optional()
|
|
346
|
+
expectedArrivalDate: date.optional()
|
|
269
347
|
});
|
|
270
348
|
const createPurchaseOrder = defineAction({
|
|
271
349
|
...apiDefaults,
|
|
@@ -273,12 +351,16 @@ const createPurchaseOrder = defineAction({
|
|
|
273
351
|
label: 'Create purchase order',
|
|
274
352
|
description: 'Create a purchase order.',
|
|
275
353
|
input: purchaseOrderInput,
|
|
276
|
-
async run({ input, client, req }) {
|
|
354
|
+
async run ({ input, client, req }) {
|
|
277
355
|
return accountingRequest(client, input, '/PurchaseOrders', 'POST', {
|
|
278
356
|
PurchaseOrders: [
|
|
279
357
|
{
|
|
280
|
-
Contact: {
|
|
281
|
-
|
|
358
|
+
Contact: {
|
|
359
|
+
ContactID: input.contactId
|
|
360
|
+
},
|
|
361
|
+
LineItems: [
|
|
362
|
+
input.lineItem
|
|
363
|
+
],
|
|
282
364
|
Date: input.date,
|
|
283
365
|
DeliveryDate: input.deliveryDate,
|
|
284
366
|
LineAmountTypes: input.lineAmountTypes,
|
|
@@ -290,22 +372,28 @@ const createPurchaseOrder = defineAction({
|
|
|
290
372
|
AttentionTo: input.attentionTo,
|
|
291
373
|
Telephone: input.telephone,
|
|
292
374
|
DeliveryInstructions: input.deliveryInstructions,
|
|
293
|
-
ExpectedArrivalDate: input.expectedArrivalDate
|
|
294
|
-
}
|
|
295
|
-
]
|
|
375
|
+
ExpectedArrivalDate: input.expectedArrivalDate
|
|
376
|
+
}
|
|
377
|
+
]
|
|
296
378
|
}, req.signal ?? undefined);
|
|
297
|
-
}
|
|
379
|
+
}
|
|
298
380
|
});
|
|
299
381
|
const updatePurchaseOrderInput = z.object({
|
|
300
382
|
...tenant,
|
|
301
383
|
purchaseOrderId: z.string().min(1),
|
|
302
|
-
status: z.enum([
|
|
384
|
+
status: z.enum([
|
|
385
|
+
'DRAFT',
|
|
386
|
+
'SUBMITTED',
|
|
387
|
+
'AUTHORISED',
|
|
388
|
+
'BILLED',
|
|
389
|
+
'DELETED'
|
|
390
|
+
]).optional(),
|
|
303
391
|
sentToContact: z.boolean().default(false),
|
|
304
392
|
deliveryAddress: z.string().optional(),
|
|
305
393
|
attentionTo: z.string().optional(),
|
|
306
394
|
telephone: z.string().optional(),
|
|
307
395
|
deliveryInstructions: z.string().optional(),
|
|
308
|
-
expectedArrivalDate: date.optional()
|
|
396
|
+
expectedArrivalDate: date.optional()
|
|
309
397
|
});
|
|
310
398
|
const updatePurchaseOrder = defineAction({
|
|
311
399
|
...apiDefaults,
|
|
@@ -314,7 +402,7 @@ const updatePurchaseOrder = defineAction({
|
|
|
314
402
|
description: 'Update a purchase order.',
|
|
315
403
|
input: updatePurchaseOrderInput,
|
|
316
404
|
idempotent: true,
|
|
317
|
-
async run({ input, client, req }) {
|
|
405
|
+
async run ({ input, client, req }) {
|
|
318
406
|
return accountingRequest(client, input, `/PurchaseOrders/${input.purchaseOrderId}`, 'POST', {
|
|
319
407
|
PurchaseOrders: [
|
|
320
408
|
{
|
|
@@ -325,11 +413,11 @@ const updatePurchaseOrder = defineAction({
|
|
|
325
413
|
AttentionTo: input.attentionTo,
|
|
326
414
|
Telephone: input.telephone,
|
|
327
415
|
DeliveryInstructions: input.deliveryInstructions,
|
|
328
|
-
ExpectedArrivalDate: input.expectedArrivalDate
|
|
329
|
-
}
|
|
330
|
-
]
|
|
416
|
+
ExpectedArrivalDate: input.expectedArrivalDate
|
|
417
|
+
}
|
|
418
|
+
]
|
|
331
419
|
}, req.signal ?? undefined);
|
|
332
|
-
}
|
|
420
|
+
}
|
|
333
421
|
});
|
|
334
422
|
const uploadAttachmentInput = z.object({
|
|
335
423
|
...tenant,
|
|
@@ -344,13 +432,16 @@ const uploadAttachmentInput = z.object({
|
|
|
344
432
|
'Accounts',
|
|
345
433
|
'ManualJournals',
|
|
346
434
|
'Receipts',
|
|
347
|
-
'RepeatingInvoices'
|
|
435
|
+
'RepeatingInvoices'
|
|
348
436
|
]),
|
|
349
437
|
resourceId: z.string().min(1),
|
|
350
|
-
file: z.union([
|
|
438
|
+
file: z.union([
|
|
439
|
+
z.string(),
|
|
440
|
+
z.number()
|
|
441
|
+
]),
|
|
351
442
|
fileName: z.string().min(1),
|
|
352
443
|
contentType: z.string().min(1).default('application/octet-stream'),
|
|
353
|
-
includeOnline: z.boolean().default(false)
|
|
444
|
+
includeOnline: z.boolean().default(false)
|
|
354
445
|
});
|
|
355
446
|
const uploadAttachment = defineAction({
|
|
356
447
|
...apiDefaults,
|
|
@@ -358,65 +449,62 @@ const uploadAttachment = defineAction({
|
|
|
358
449
|
label: 'Upload attachment',
|
|
359
450
|
description: 'Upload an attachment to a Xero resource.',
|
|
360
451
|
input: uploadAttachmentInput,
|
|
361
|
-
async run({ input, client, req }) {
|
|
362
|
-
const collection = req
|
|
363
|
-
if (!collection)
|
|
364
|
-
throw new Error('FrogBot files are not configured.');
|
|
452
|
+
async run ({ input, client, req }) {
|
|
453
|
+
const collection = filesCollectionSlug(req, 'Xero');
|
|
365
454
|
const file = await req.frogbot.findByID({
|
|
366
455
|
collection,
|
|
367
456
|
id: input.file,
|
|
368
457
|
depth: 0,
|
|
369
458
|
req,
|
|
370
|
-
overrideAccess: false
|
|
459
|
+
overrideAccess: false
|
|
371
460
|
});
|
|
372
461
|
const urlValue = typeof file.url === 'string' ? file.url : undefined;
|
|
373
|
-
if (!urlValue)
|
|
374
|
-
throw new Error('The selected file has no URL.');
|
|
462
|
+
if (!urlValue) throw new Error('The selected file has no URL.');
|
|
375
463
|
const payloadConfig = await req.frogbot.config._internal.payloadConfig;
|
|
376
464
|
const originValue = payloadConfig.serverURL || req.url;
|
|
377
|
-
if (!originValue)
|
|
378
|
-
throw new Error('FrogBot file requests require a server URL.');
|
|
465
|
+
if (!originValue) throw new Error('FrogBot file requests require a server URL.');
|
|
379
466
|
const origin = new URL(originValue);
|
|
380
467
|
const url = new URL(urlValue, origin);
|
|
381
|
-
if (![
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
468
|
+
if (![
|
|
469
|
+
'http:',
|
|
470
|
+
'https:'
|
|
471
|
+
].includes(origin.protocol) || origin.username || origin.password || ![
|
|
472
|
+
'http:',
|
|
473
|
+
'https:'
|
|
474
|
+
].includes(url.protocol) || url.username || url.password || url.origin !== origin.origin) {
|
|
388
475
|
throw new Error('The selected file URL is unsafe.');
|
|
389
476
|
}
|
|
390
477
|
const response = await fetch(url, {
|
|
391
478
|
headers: {
|
|
392
479
|
cookie: req.headers.get('cookie') ?? '',
|
|
393
|
-
authorization: req.headers.get('authorization') ?? ''
|
|
480
|
+
authorization: req.headers.get('authorization') ?? ''
|
|
394
481
|
},
|
|
395
482
|
redirect: 'error',
|
|
396
|
-
signal: req.signal ?? undefined
|
|
483
|
+
signal: req.signal ?? undefined
|
|
397
484
|
});
|
|
398
|
-
if (!response.ok)
|
|
399
|
-
throw new Error(`Unable to load attachment (${response.status}).`);
|
|
485
|
+
if (!response.ok) throw new Error(`Unable to load attachment (${response.status}).`);
|
|
400
486
|
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
401
|
-
if (bytes.byteLength > 10_000_000)
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
487
|
+
if (bytes.byteLength > 10_000_000) throw new Error('Xero attachments cannot exceed 10 MB.');
|
|
488
|
+
const suffix = input.includeOnline && [
|
|
489
|
+
'Invoices',
|
|
490
|
+
'CreditNotes'
|
|
491
|
+
].includes(input.resourceType) ? '?IncludeOnline=true' : '';
|
|
406
492
|
return client.request({
|
|
407
493
|
path: `/${input.resourceType}/${input.resourceId}/Attachments/${encodeURIComponent(input.fileName)}${suffix}`,
|
|
408
494
|
method: 'POST',
|
|
409
495
|
tenantId: input.tenantId,
|
|
410
496
|
body: bytes,
|
|
411
|
-
headers: {
|
|
412
|
-
|
|
497
|
+
headers: {
|
|
498
|
+
'Content-Type': input.contentType
|
|
499
|
+
},
|
|
500
|
+
signal: req.signal ?? undefined
|
|
413
501
|
}, xeroResponse);
|
|
414
|
-
}
|
|
502
|
+
}
|
|
415
503
|
});
|
|
416
504
|
const addInvoiceItemsInput = z.object({
|
|
417
505
|
...tenant,
|
|
418
506
|
invoiceId: z.string().min(1),
|
|
419
|
-
newLineItems: z.array(lineItem).min(1)
|
|
507
|
+
newLineItems: z.array(lineItem).min(1)
|
|
420
508
|
});
|
|
421
509
|
const addInvoiceItems = defineAction({
|
|
422
510
|
...apiDefaults,
|
|
@@ -424,35 +512,47 @@ const addInvoiceItems = defineAction({
|
|
|
424
512
|
label: 'Add invoice items',
|
|
425
513
|
description: 'Append items to a sales invoice.',
|
|
426
514
|
input: addInvoiceItemsInput,
|
|
427
|
-
async run({ input, client, req }) {
|
|
515
|
+
async run ({ input, client, req }) {
|
|
428
516
|
const current = await client.request({
|
|
429
517
|
path: `/Invoices/${input.invoiceId}`,
|
|
430
518
|
tenantId: input.tenantId,
|
|
431
|
-
signal: req.signal ?? undefined
|
|
519
|
+
signal: req.signal ?? undefined
|
|
432
520
|
}, z.object({
|
|
433
|
-
Invoices: z
|
|
434
|
-
|
|
435
|
-
|
|
521
|
+
Invoices: z.array(z.object({
|
|
522
|
+
LineItems: z.array(lineItem.passthrough()).default([])
|
|
523
|
+
})).min(1)
|
|
436
524
|
}));
|
|
437
525
|
return accountingRequest(client, input, `/Invoices/${input.invoiceId}`, 'POST', {
|
|
438
526
|
Invoices: [
|
|
439
|
-
{
|
|
440
|
-
|
|
527
|
+
{
|
|
528
|
+
Type: 'ACCREC',
|
|
529
|
+
LineItems: [
|
|
530
|
+
...current.Invoices[0].LineItems,
|
|
531
|
+
...input.newLineItems
|
|
532
|
+
]
|
|
533
|
+
}
|
|
534
|
+
]
|
|
441
535
|
}, req.signal ?? undefined);
|
|
442
|
-
}
|
|
536
|
+
}
|
|
443
537
|
});
|
|
444
538
|
const createCreditNoteInput = z.object({
|
|
445
539
|
...tenant,
|
|
446
|
-
type: z.enum([
|
|
540
|
+
type: z.enum([
|
|
541
|
+
'ACCRECCREDIT',
|
|
542
|
+
'ACCPAYCREDIT'
|
|
543
|
+
]).default('ACCRECCREDIT'),
|
|
447
544
|
contactId: z.string().min(1),
|
|
448
545
|
date: date.optional(),
|
|
449
|
-
status: z.enum([
|
|
546
|
+
status: z.enum([
|
|
547
|
+
'DRAFT',
|
|
548
|
+
'AUTHORISED'
|
|
549
|
+
]).default('DRAFT'),
|
|
450
550
|
lineAmountTypes: lineAmountType.optional(),
|
|
451
551
|
creditNoteNumber: z.string().optional(),
|
|
452
552
|
reference: z.string().optional(),
|
|
453
553
|
currencyCode: z.string().optional(),
|
|
454
554
|
brandingThemeId: z.string().optional(),
|
|
455
|
-
lineItems: z.array(lineItem).optional()
|
|
555
|
+
lineItems: z.array(lineItem).optional()
|
|
456
556
|
});
|
|
457
557
|
const createCreditNote = defineAction({
|
|
458
558
|
...apiDefaults,
|
|
@@ -460,12 +560,14 @@ const createCreditNote = defineAction({
|
|
|
460
560
|
label: 'Create credit note',
|
|
461
561
|
description: 'Create a credit note.',
|
|
462
562
|
input: createCreditNoteInput,
|
|
463
|
-
async run({ input, client, req }) {
|
|
563
|
+
async run ({ input, client, req }) {
|
|
464
564
|
return accountingRequest(client, input, '/CreditNotes', 'POST', {
|
|
465
565
|
CreditNotes: [
|
|
466
566
|
{
|
|
467
567
|
Type: input.type,
|
|
468
|
-
Contact: {
|
|
568
|
+
Contact: {
|
|
569
|
+
ContactID: input.contactId
|
|
570
|
+
},
|
|
469
571
|
Date: input.date,
|
|
470
572
|
Status: input.status,
|
|
471
573
|
LineAmountTypes: input.lineAmountTypes,
|
|
@@ -473,11 +575,11 @@ const createCreditNote = defineAction({
|
|
|
473
575
|
Reference: input.type === 'ACCRECCREDIT' ? input.reference : undefined,
|
|
474
576
|
CurrencyCode: input.currencyCode,
|
|
475
577
|
BrandingThemeID: input.brandingThemeId,
|
|
476
|
-
LineItems: input.lineItems
|
|
477
|
-
}
|
|
478
|
-
]
|
|
578
|
+
LineItems: input.lineItems
|
|
579
|
+
}
|
|
580
|
+
]
|
|
479
581
|
}, req.signal ?? undefined);
|
|
480
|
-
}
|
|
582
|
+
}
|
|
481
583
|
});
|
|
482
584
|
const createItemInput = z.object({
|
|
483
585
|
...tenant,
|
|
@@ -487,12 +589,16 @@ const createItemInput = z.object({
|
|
|
487
589
|
purchaseDescription: z.string().optional(),
|
|
488
590
|
isSold: z.boolean().default(true),
|
|
489
591
|
isPurchased: z.boolean().default(true),
|
|
490
|
-
salesDetails: z.object({
|
|
491
|
-
|
|
592
|
+
salesDetails: z.object({
|
|
593
|
+
UnitPrice: z.number()
|
|
594
|
+
}).optional(),
|
|
595
|
+
purchaseDetails: z.object({
|
|
596
|
+
UnitPrice: z.number()
|
|
597
|
+
}).optional(),
|
|
492
598
|
salesAccountId: z.string().optional(),
|
|
493
599
|
purchaseAccountId: z.string().optional(),
|
|
494
600
|
cogsAccountId: z.string().optional(),
|
|
495
|
-
inventoryAssetAccountId: z.string().optional()
|
|
601
|
+
inventoryAssetAccountId: z.string().optional()
|
|
496
602
|
});
|
|
497
603
|
const createItem = defineAction({
|
|
498
604
|
...apiDefaults,
|
|
@@ -500,7 +606,7 @@ const createItem = defineAction({
|
|
|
500
606
|
label: 'Create inventory item',
|
|
501
607
|
description: 'Create an inventory item.',
|
|
502
608
|
input: createItemInput,
|
|
503
|
-
async run({ input, client, req }) {
|
|
609
|
+
async run ({ input, client, req }) {
|
|
504
610
|
return accountingRequest(client, input, '/Items', 'POST', {
|
|
505
611
|
Code: input.code,
|
|
506
612
|
Name: input.name,
|
|
@@ -508,26 +614,25 @@ const createItem = defineAction({
|
|
|
508
614
|
PurchaseDescription: input.purchaseDescription,
|
|
509
615
|
IsSold: input.isSold,
|
|
510
616
|
IsPurchased: input.isPurchased,
|
|
511
|
-
SalesDetails: input.salesDetails || input.salesAccountId
|
|
512
|
-
|
|
513
|
-
:
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
InventoryAssetAccountID: input.inventoryAssetAccountId,
|
|
617
|
+
SalesDetails: input.salesDetails || input.salesAccountId ? {
|
|
618
|
+
...input.salesDetails,
|
|
619
|
+
AccountID: input.salesAccountId
|
|
620
|
+
} : undefined,
|
|
621
|
+
PurchaseDetails: input.purchaseDetails || input.purchaseAccountId || input.cogsAccountId ? {
|
|
622
|
+
...input.purchaseDetails,
|
|
623
|
+
AccountID: input.purchaseAccountId,
|
|
624
|
+
COGSAccountID: input.cogsAccountId
|
|
625
|
+
} : undefined,
|
|
626
|
+
InventoryAssetAccountID: input.inventoryAssetAccountId
|
|
522
627
|
}, req.signal ?? undefined);
|
|
523
|
-
}
|
|
628
|
+
}
|
|
524
629
|
});
|
|
525
630
|
const createProjectInput = z.object({
|
|
526
631
|
...tenant,
|
|
527
632
|
contactId: z.string().min(1),
|
|
528
633
|
name: z.string().min(1),
|
|
529
634
|
deadlineUtc: z.string().datetime().optional(),
|
|
530
|
-
estimateAmount: z.number().optional()
|
|
635
|
+
estimateAmount: z.number().optional()
|
|
531
636
|
});
|
|
532
637
|
const createProject = defineAction({
|
|
533
638
|
...apiDefaults,
|
|
@@ -535,7 +640,7 @@ const createProject = defineAction({
|
|
|
535
640
|
label: 'Create project',
|
|
536
641
|
description: 'Create a Xero project.',
|
|
537
642
|
input: createProjectInput,
|
|
538
|
-
async run({ input, client, req }) {
|
|
643
|
+
async run ({ input, client, req }) {
|
|
539
644
|
return client.request({
|
|
540
645
|
base: 'projects',
|
|
541
646
|
path: '/Projects',
|
|
@@ -545,11 +650,11 @@ const createProject = defineAction({
|
|
|
545
650
|
contactId: input.contactId,
|
|
546
651
|
name: input.name,
|
|
547
652
|
deadlineUtc: input.deadlineUtc,
|
|
548
|
-
estimateAmount: input.estimateAmount
|
|
653
|
+
estimateAmount: input.estimateAmount
|
|
549
654
|
},
|
|
550
|
-
signal: req.signal ?? undefined
|
|
655
|
+
signal: req.signal ?? undefined
|
|
551
656
|
}, xeroResponse);
|
|
552
|
-
}
|
|
657
|
+
}
|
|
553
658
|
});
|
|
554
659
|
const updateInvoiceInput = z.object({
|
|
555
660
|
...tenant,
|
|
@@ -560,10 +665,16 @@ const updateInvoiceInput = z.object({
|
|
|
560
665
|
brandingThemeId: z.string().optional(),
|
|
561
666
|
url: z.string().url().optional(),
|
|
562
667
|
contactId: z.string().optional(),
|
|
563
|
-
status: z.enum([
|
|
668
|
+
status: z.enum([
|
|
669
|
+
'DRAFT',
|
|
670
|
+
'SUBMITTED',
|
|
671
|
+
'AUTHORISED',
|
|
672
|
+
'VOIDED',
|
|
673
|
+
'DELETED'
|
|
674
|
+
]).optional(),
|
|
564
675
|
sentToContact: z.boolean().default(false),
|
|
565
676
|
replaceAllLineItems: z.boolean().default(false),
|
|
566
|
-
lineItems: z.array(lineItem).optional()
|
|
677
|
+
lineItems: z.array(lineItem).optional()
|
|
567
678
|
});
|
|
568
679
|
const updateInvoice = defineAction({
|
|
569
680
|
...apiDefaults,
|
|
@@ -572,27 +683,35 @@ const updateInvoice = defineAction({
|
|
|
572
683
|
description: 'Update a sales invoice.',
|
|
573
684
|
input: updateInvoiceInput,
|
|
574
685
|
idempotent: true,
|
|
575
|
-
async run({ input, client, req }) {
|
|
686
|
+
async run ({ input, client, req }) {
|
|
576
687
|
let lineItems = input.lineItems;
|
|
577
688
|
if (lineItems?.length && !input.replaceAllLineItems) {
|
|
578
689
|
const current = await client.request({
|
|
579
690
|
path: `/Invoices/${input.invoiceId}`,
|
|
580
691
|
tenantId: input.tenantId,
|
|
581
|
-
signal: req.signal ?? undefined
|
|
692
|
+
signal: req.signal ?? undefined
|
|
582
693
|
}, z.object({
|
|
583
|
-
Invoices: z
|
|
584
|
-
|
|
585
|
-
|
|
694
|
+
Invoices: z.array(z.object({
|
|
695
|
+
LineItems: z.array(lineItem.passthrough()).default([])
|
|
696
|
+
})).min(1)
|
|
586
697
|
}));
|
|
587
|
-
const updates = new Map(lineItems.filter((item)
|
|
588
|
-
|
|
698
|
+
const updates = new Map(lineItems.filter((item)=>item.LineItemID).map((item)=>[
|
|
699
|
+
item.LineItemID,
|
|
700
|
+
item
|
|
701
|
+
]));
|
|
702
|
+
const existing = current.Invoices[0].LineItems.map((item)=>{
|
|
589
703
|
const update = item.LineItemID ? updates.get(item.LineItemID) : undefined;
|
|
590
|
-
if (item.LineItemID)
|
|
591
|
-
|
|
592
|
-
|
|
704
|
+
if (item.LineItemID) updates.delete(item.LineItemID);
|
|
705
|
+
return update ? {
|
|
706
|
+
...item,
|
|
707
|
+
...update
|
|
708
|
+
} : item;
|
|
593
709
|
});
|
|
594
|
-
const additions = lineItems.filter((item)
|
|
595
|
-
lineItems = [
|
|
710
|
+
const additions = lineItems.filter((item)=>!item.LineItemID || updates.has(item.LineItemID));
|
|
711
|
+
lineItems = [
|
|
712
|
+
...existing,
|
|
713
|
+
...additions
|
|
714
|
+
];
|
|
596
715
|
}
|
|
597
716
|
return accountingRequest(client, input, `/Invoices/${input.invoiceId}`, 'POST', {
|
|
598
717
|
Invoices: [
|
|
@@ -604,39 +723,47 @@ const updateInvoice = defineAction({
|
|
|
604
723
|
InvoiceNumber: input.invoiceNumber,
|
|
605
724
|
BrandingThemeID: input.brandingThemeId,
|
|
606
725
|
Url: input.url,
|
|
607
|
-
Contact: input.contactId ? {
|
|
726
|
+
Contact: input.contactId ? {
|
|
727
|
+
ContactID: input.contactId
|
|
728
|
+
} : undefined,
|
|
608
729
|
Status: input.status,
|
|
609
730
|
SentToContact: input.sentToContact,
|
|
610
|
-
LineItems: lineItems
|
|
611
|
-
}
|
|
612
|
-
]
|
|
731
|
+
LineItems: lineItems
|
|
732
|
+
}
|
|
733
|
+
]
|
|
613
734
|
}, req.signal ?? undefined);
|
|
614
|
-
}
|
|
735
|
+
}
|
|
615
736
|
});
|
|
616
737
|
const repeatingInput = z.object({
|
|
617
738
|
...tenant,
|
|
618
739
|
contactId: z.string().min(1),
|
|
619
740
|
schedulePeriod: z.number().int(),
|
|
620
|
-
scheduleUnit: z.enum([
|
|
741
|
+
scheduleUnit: z.enum([
|
|
742
|
+
'WEEKLY',
|
|
743
|
+
'MONTHLY'
|
|
744
|
+
]),
|
|
621
745
|
dueDate: z.number().int(),
|
|
622
746
|
dueDateType: z.enum([
|
|
623
747
|
'OFCURRENTMONTH',
|
|
624
748
|
'OFFOLLOWINGMONTH',
|
|
625
749
|
'DAYSAFTERBILLDATE',
|
|
626
|
-
'DAYSAFTERBILLMONTH'
|
|
750
|
+
'DAYSAFTERBILLMONTH'
|
|
627
751
|
]),
|
|
628
752
|
startDate: date,
|
|
629
753
|
endDate: date.optional(),
|
|
630
754
|
lineAmountTypes: lineAmountType.default('Exclusive'),
|
|
631
755
|
currencyCode: z.string().min(1),
|
|
632
|
-
status: z.enum([
|
|
756
|
+
status: z.enum([
|
|
757
|
+
'DRAFT',
|
|
758
|
+
'AUTHORISED'
|
|
759
|
+
]).default('DRAFT'),
|
|
633
760
|
reference: z.string().optional(),
|
|
634
761
|
brandingThemeId: z.string().optional(),
|
|
635
762
|
approvedForSending: z.boolean().default(false),
|
|
636
763
|
sendCopy: z.boolean().default(false),
|
|
637
764
|
markAsSent: z.boolean().default(false),
|
|
638
765
|
includePdf: z.boolean().default(false),
|
|
639
|
-
lineItems: z.array(lineItem).min(1)
|
|
766
|
+
lineItems: z.array(lineItem).min(1)
|
|
640
767
|
});
|
|
641
768
|
const createRepeatingInvoice = defineAction({
|
|
642
769
|
...apiDefaults,
|
|
@@ -644,27 +771,33 @@ const createRepeatingInvoice = defineAction({
|
|
|
644
771
|
label: 'Create repeating invoice',
|
|
645
772
|
description: 'Create a repeating sales invoice.',
|
|
646
773
|
input: repeatingInput,
|
|
647
|
-
async run({ input, client, req }) {
|
|
648
|
-
if (input.scheduleUnit === 'WEEKLY' &&
|
|
649
|
-
|
|
774
|
+
async run ({ input, client, req }) {
|
|
775
|
+
if (input.scheduleUnit === 'WEEKLY' && ![
|
|
776
|
+
'DAYSAFTERBILLDATE',
|
|
777
|
+
'OFFOLLOWINGMONTH'
|
|
778
|
+
].includes(input.dueDateType)) {
|
|
650
779
|
throw new Error('Weekly schedules require DAYSAFTERBILLDATE or OFFOLLOWINGMONTH.');
|
|
651
780
|
}
|
|
652
|
-
if (input.scheduleUnit === 'MONTHLY' &&
|
|
653
|
-
|
|
781
|
+
if (input.scheduleUnit === 'MONTHLY' && ![
|
|
782
|
+
'OFCURRENTMONTH',
|
|
783
|
+
'OFFOLLOWINGMONTH'
|
|
784
|
+
].includes(input.dueDateType)) {
|
|
654
785
|
throw new Error('Monthly schedules require OFCURRENTMONTH or OFFOLLOWINGMONTH.');
|
|
655
786
|
}
|
|
656
787
|
return accountingRequest(client, input, '/RepeatingInvoices', 'POST', {
|
|
657
788
|
RepeatingInvoices: [
|
|
658
789
|
{
|
|
659
790
|
Type: 'ACCREC',
|
|
660
|
-
Contact: {
|
|
791
|
+
Contact: {
|
|
792
|
+
ContactID: input.contactId
|
|
793
|
+
},
|
|
661
794
|
Schedule: {
|
|
662
795
|
Period: input.schedulePeriod,
|
|
663
796
|
Unit: input.scheduleUnit,
|
|
664
797
|
DueDate: input.dueDate,
|
|
665
798
|
DueDateType: input.dueDateType,
|
|
666
799
|
StartDate: input.startDate,
|
|
667
|
-
EndDate: input.endDate
|
|
800
|
+
EndDate: input.endDate
|
|
668
801
|
},
|
|
669
802
|
LineItems: input.lineItems,
|
|
670
803
|
LineAmountTypes: input.lineAmountTypes,
|
|
@@ -675,11 +808,11 @@ const createRepeatingInvoice = defineAction({
|
|
|
675
808
|
ApprovedForSending: input.approvedForSending || undefined,
|
|
676
809
|
SendCopy: input.sendCopy || undefined,
|
|
677
810
|
MarkAsSent: input.markAsSent || undefined,
|
|
678
|
-
IncludePDF: input.includePdf || undefined
|
|
679
|
-
}
|
|
680
|
-
]
|
|
811
|
+
IncludePDF: input.includePdf || undefined
|
|
812
|
+
}
|
|
813
|
+
]
|
|
681
814
|
}, req.signal ?? undefined);
|
|
682
|
-
}
|
|
815
|
+
}
|
|
683
816
|
});
|
|
684
817
|
function lookupAction(slug, label, path, query) {
|
|
685
818
|
return defineAction({
|
|
@@ -689,37 +822,47 @@ function lookupAction(slug, label, path, query) {
|
|
|
689
822
|
description: label,
|
|
690
823
|
input: lookupInput,
|
|
691
824
|
idempotent: true,
|
|
692
|
-
async run({ input, client, req }) {
|
|
693
|
-
return client.request({
|
|
694
|
-
|
|
825
|
+
async run ({ input, client, req }) {
|
|
826
|
+
return client.request({
|
|
827
|
+
path,
|
|
828
|
+
tenantId: input.tenantId,
|
|
829
|
+
query: query(input),
|
|
830
|
+
signal: req.signal ?? undefined
|
|
831
|
+
}, xeroResponse);
|
|
832
|
+
}
|
|
695
833
|
});
|
|
696
834
|
}
|
|
697
835
|
const lookupInput = z.object({
|
|
698
836
|
...tenant,
|
|
699
837
|
searchBy: z.string().min(1),
|
|
700
838
|
value: z.string().min(1),
|
|
701
|
-
page: z.number().int().positive().optional()
|
|
839
|
+
page: z.number().int().positive().optional()
|
|
702
840
|
});
|
|
703
|
-
const findContact = lookupAction('findContact', 'Find contact', '/Contacts', (input)
|
|
704
|
-
|
|
705
|
-
|
|
841
|
+
const findContact = lookupAction('findContact', 'Find contact', '/Contacts', (input)=>input.searchBy === 'SEARCH_TERM' ? {
|
|
842
|
+
SearchTerm: input.value,
|
|
843
|
+
page: input.page ?? 1
|
|
844
|
+
} : {
|
|
706
845
|
where: `${input.searchBy === 'ACCOUNT_NUMBER' ? 'AccountNumber' : 'Name'}=="${input.value.replaceAll('"', '\\"')}"`,
|
|
707
|
-
page: input.page ?? 1
|
|
846
|
+
page: input.page ?? 1
|
|
708
847
|
});
|
|
709
|
-
const findInvoice = lookupAction('findInvoice', 'Find invoice', '/Invoices', (input)
|
|
710
|
-
|
|
711
|
-
|
|
848
|
+
const findInvoice = lookupAction('findInvoice', 'Find invoice', '/Invoices', (input)=>input.searchBy === 'SEARCH_TERM' ? {
|
|
849
|
+
SearchTerm: input.value,
|
|
850
|
+
page: input.page ?? 1
|
|
851
|
+
} : {
|
|
712
852
|
where: `${input.searchBy === 'REFERENCE' ? 'Reference' : 'InvoiceNumber'}=="${input.value.replaceAll('"', '\\"')}"`,
|
|
713
|
-
page: input.page ?? 1
|
|
853
|
+
page: input.page ?? 1
|
|
714
854
|
});
|
|
715
|
-
const findItem = lookupAction('findItem', 'Find item', '/Items', (input)
|
|
716
|
-
|
|
717
|
-
}));
|
|
718
|
-
const findPurchaseOrder = lookupAction('findPurchaseOrder', 'Find purchase order', '/PurchaseOrders', (input)
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
}));
|
|
722
|
-
const getInvoiceHistoryInput = z.object({
|
|
855
|
+
const findItem = lookupAction('findItem', 'Find item', '/Items', (input)=>({
|
|
856
|
+
where: `${input.searchBy === 'NAME' ? 'Name' : 'Code'}=="${input.value.replaceAll('"', '\\"')}"`
|
|
857
|
+
}));
|
|
858
|
+
const findPurchaseOrder = lookupAction('findPurchaseOrder', 'Find purchase order', '/PurchaseOrders', (input)=>({
|
|
859
|
+
where: `${input.searchBy === 'REFERENCE' ? 'Reference' : 'PurchaseOrderNumber'}=="${input.value.replaceAll('"', '\\"')}"`,
|
|
860
|
+
page: String(input.page ?? 1)
|
|
861
|
+
}));
|
|
862
|
+
const getInvoiceHistoryInput = z.object({
|
|
863
|
+
...tenant,
|
|
864
|
+
invoiceId: z.string().min(1)
|
|
865
|
+
});
|
|
723
866
|
const getInvoiceHistory = defineAction({
|
|
724
867
|
...apiDefaults,
|
|
725
868
|
slug: 'getInvoiceHistory',
|
|
@@ -727,24 +870,27 @@ const getInvoiceHistory = defineAction({
|
|
|
727
870
|
description: 'Get invoice history.',
|
|
728
871
|
input: getInvoiceHistoryInput,
|
|
729
872
|
idempotent: true,
|
|
730
|
-
async run({ input, client, req }) {
|
|
873
|
+
async run ({ input, client, req }) {
|
|
731
874
|
return client.request({
|
|
732
875
|
path: `/Invoices/${input.invoiceId}/History`,
|
|
733
876
|
tenantId: input.tenantId,
|
|
734
|
-
signal: req.signal ?? undefined
|
|
877
|
+
signal: req.signal ?? undefined
|
|
735
878
|
}, xeroResponse);
|
|
736
|
-
}
|
|
879
|
+
}
|
|
737
880
|
});
|
|
738
881
|
const createBankTransactionInput = z.object({
|
|
739
882
|
...tenant,
|
|
740
|
-
type: z.enum([
|
|
883
|
+
type: z.enum([
|
|
884
|
+
'SPEND',
|
|
885
|
+
'RECEIVE'
|
|
886
|
+
]).default('SPEND'),
|
|
741
887
|
contactId: z.string().min(1),
|
|
742
888
|
bankAccountId: z.string().min(1),
|
|
743
889
|
lineItem,
|
|
744
890
|
date: date.optional(),
|
|
745
891
|
reference: z.string().optional(),
|
|
746
892
|
lineAmountTypes: lineAmountType.optional(),
|
|
747
|
-
isReconciled: z.boolean().default(false)
|
|
893
|
+
isReconciled: z.boolean().default(false)
|
|
748
894
|
});
|
|
749
895
|
const createBankTransaction = defineAction({
|
|
750
896
|
...apiDefaults,
|
|
@@ -752,52 +898,74 @@ const createBankTransaction = defineAction({
|
|
|
752
898
|
label: 'Create bank transaction',
|
|
753
899
|
description: 'Create a spend or receive transaction.',
|
|
754
900
|
input: createBankTransactionInput,
|
|
755
|
-
async run({ input, client, req }) {
|
|
901
|
+
async run ({ input, client, req }) {
|
|
756
902
|
return accountingRequest(client, input, '/BankTransactions', 'POST', {
|
|
757
903
|
BankTransactions: [
|
|
758
904
|
{
|
|
759
905
|
Type: input.type,
|
|
760
|
-
Contact: {
|
|
761
|
-
|
|
762
|
-
|
|
906
|
+
Contact: {
|
|
907
|
+
ContactID: input.contactId
|
|
908
|
+
},
|
|
909
|
+
BankAccount: {
|
|
910
|
+
AccountID: input.bankAccountId
|
|
911
|
+
},
|
|
912
|
+
LineItems: [
|
|
913
|
+
input.lineItem
|
|
914
|
+
],
|
|
763
915
|
Date: input.date,
|
|
764
916
|
Reference: input.reference,
|
|
765
917
|
LineAmountTypes: input.lineAmountTypes,
|
|
766
|
-
IsReconciled: input.isReconciled || undefined
|
|
767
|
-
}
|
|
768
|
-
]
|
|
918
|
+
IsReconciled: input.isReconciled || undefined
|
|
919
|
+
}
|
|
920
|
+
]
|
|
769
921
|
}, req.signal ?? undefined);
|
|
770
|
-
}
|
|
922
|
+
}
|
|
771
923
|
});
|
|
772
924
|
const findOrCreateContact = defineAction({
|
|
773
925
|
...apiDefaults,
|
|
774
926
|
slug: 'findOrCreateContact',
|
|
775
927
|
label: 'Find or create contact',
|
|
776
928
|
description: 'Find a contact by name or create it.',
|
|
777
|
-
input: createOrUpdateContactInput.omit({
|
|
929
|
+
input: createOrUpdateContactInput.omit({
|
|
930
|
+
contactId: true
|
|
931
|
+
}),
|
|
778
932
|
idempotent: true,
|
|
779
|
-
async run({ input, client, req }) {
|
|
933
|
+
async run ({ input, client, req }) {
|
|
780
934
|
const existing = await client.request({
|
|
781
935
|
path: '/Contacts',
|
|
782
936
|
tenantId: input.tenantId,
|
|
783
|
-
query: {
|
|
784
|
-
|
|
937
|
+
query: {
|
|
938
|
+
where: `Name=="${input.name.replaceAll('"', '\\"')}"`
|
|
939
|
+
},
|
|
940
|
+
signal: req.signal ?? undefined
|
|
785
941
|
}, xeroResponse);
|
|
786
|
-
if (Array.isArray(existing.Contacts) && existing.Contacts.length)
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
942
|
+
if (Array.isArray(existing.Contacts) && existing.Contacts.length) return existing;
|
|
943
|
+
return accountingRequest(client, input, '/Contacts', 'POST', {
|
|
944
|
+
Contacts: [
|
|
945
|
+
{
|
|
946
|
+
Name: input.name,
|
|
947
|
+
EmailAddress: input.email
|
|
948
|
+
}
|
|
949
|
+
]
|
|
950
|
+
}, req.signal ?? undefined);
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
const customPath = z.string().regex(/^\/(?!\/)(?!.*[%?#\\])[A-Za-z0-9._~!$&'()*+,;=:@/-]+$/).refine((value)=>value.split('/').every((segment)=>segment !== '.' && segment !== '..'));
|
|
795
954
|
const customApiInput = z.object({
|
|
796
955
|
...tenant,
|
|
797
|
-
method: z.enum([
|
|
956
|
+
method: z.enum([
|
|
957
|
+
'DELETE',
|
|
958
|
+
'GET',
|
|
959
|
+
'POST',
|
|
960
|
+
'PUT'
|
|
961
|
+
]),
|
|
798
962
|
path: customPath,
|
|
799
|
-
query: z.record(z.string(), z.union([
|
|
800
|
-
|
|
963
|
+
query: z.record(z.string(), z.union([
|
|
964
|
+
z.string(),
|
|
965
|
+
z.number(),
|
|
966
|
+
z.boolean()
|
|
967
|
+
])).default({}),
|
|
968
|
+
body: z.json().optional()
|
|
801
969
|
});
|
|
802
970
|
const customApiCall = defineAction({
|
|
803
971
|
...apiDefaults,
|
|
@@ -805,16 +973,16 @@ const customApiCall = defineAction({
|
|
|
805
973
|
label: 'Custom API call',
|
|
806
974
|
description: 'Call a relative Xero accounting API path.',
|
|
807
975
|
input: customApiInput,
|
|
808
|
-
async run({ input, client, req }) {
|
|
976
|
+
async run ({ input, client, req }) {
|
|
809
977
|
return client.request({
|
|
810
978
|
path: input.path,
|
|
811
979
|
method: input.method,
|
|
812
980
|
tenantId: input.tenantId,
|
|
813
981
|
query: input.query,
|
|
814
982
|
body: input.body,
|
|
815
|
-
signal: req.signal ?? undefined
|
|
983
|
+
signal: req.signal ?? undefined
|
|
816
984
|
}, xeroResponse);
|
|
817
|
-
}
|
|
985
|
+
}
|
|
818
986
|
});
|
|
819
987
|
export const xeroActions = [
|
|
820
988
|
createOrUpdateContact,
|
|
@@ -841,6 +1009,7 @@ export const xeroActions = [
|
|
|
841
1009
|
getInvoiceHistory,
|
|
842
1010
|
createBankTransaction,
|
|
843
1011
|
findOrCreateContact,
|
|
844
|
-
customApiCall
|
|
1012
|
+
customApiCall
|
|
845
1013
|
];
|
|
1014
|
+
|
|
846
1015
|
//# sourceMappingURL=actions.js.map
|