@mindstone/mcp-server-xero 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +199 -0
- package/dist/clients/xero-client.js +134 -0
- package/dist/consts/deeplinks.js +24 -0
- package/dist/handlers/approve-xero-payroll-timesheet.handler.js +28 -0
- package/dist/handlers/create-xero-bank-transaction.handler.js +50 -0
- package/dist/handlers/create-xero-contact.handler.js +49 -0
- package/dist/handlers/create-xero-credit-note.handler.js +49 -0
- package/dist/handlers/create-xero-invoice.handler.js +55 -0
- package/dist/handlers/create-xero-item.handler.js +59 -0
- package/dist/handlers/create-xero-manual-journal.handler.js +57 -0
- package/dist/handlers/create-xero-payment.handler.js +49 -0
- package/dist/handlers/create-xero-payroll-timesheet.handler.js +28 -0
- package/dist/handlers/create-xero-quote.handler.js +54 -0
- package/dist/handlers/create-xero-tracking-category.handler.js +35 -0
- package/dist/handlers/create-xero-tracking-option.handler.js +31 -0
- package/dist/handlers/delete-xero-payroll-timesheet.handler.js +28 -0
- package/dist/handlers/download-xero-invoice-attachment.handler.js +26 -0
- package/dist/handlers/get-xero-payroll-timesheet.handler.js +28 -0
- package/dist/handlers/history-handler-factory.js +46 -0
- package/dist/handlers/list-aged-payables-by-contact.handler.js +37 -0
- package/dist/handlers/list-aged-receivables-by-contact.handler.js +37 -0
- package/dist/handlers/list-xero-accounts.handler.js +32 -0
- package/dist/handlers/list-xero-bank-transactions.handler.js +31 -0
- package/dist/handlers/list-xero-contact-groups.handler.js +34 -0
- package/dist/handlers/list-xero-contacts.handler.js +37 -0
- package/dist/handlers/list-xero-credit-notes.handler.js +34 -0
- package/dist/handlers/list-xero-invoice-attachments.handler.js +20 -0
- package/dist/handlers/list-xero-invoices.handler.js +59 -0
- package/dist/handlers/list-xero-items.handler.js +32 -0
- package/dist/handlers/list-xero-manual-journals.handler.js +33 -0
- package/dist/handlers/list-xero-organisation-details.handler.js +32 -0
- package/dist/handlers/list-xero-payments.handler.js +53 -0
- package/dist/handlers/list-xero-payroll-employee-leave-balances.handler.js +42 -0
- package/dist/handlers/list-xero-payroll-employee-leave-types.handler.js +42 -0
- package/dist/handlers/list-xero-payroll-employee-leave.handler.js +44 -0
- package/dist/handlers/list-xero-payroll-employees.handler.js +31 -0
- package/dist/handlers/list-xero-payroll-leave-periods.handler.js +44 -0
- package/dist/handlers/list-xero-payroll-leave-types.handler.js +40 -0
- package/dist/handlers/list-xero-profit-and-loss.handler.js +52 -0
- package/dist/handlers/list-xero-quotes.handler.js +37 -0
- package/dist/handlers/list-xero-report-balance-sheet.handler.js +34 -0
- package/dist/handlers/list-xero-tax-rates.handler.js +30 -0
- package/dist/handlers/list-xero-timesheets.handler.js +29 -0
- package/dist/handlers/list-xero-tracking-categories.handler.js +29 -0
- package/dist/handlers/list-xero-trial-balance.handler.js +42 -0
- package/dist/handlers/revert-xero-payroll-timesheet.handler.js +28 -0
- package/dist/handlers/update-xero-bank-transaction.handler.js +56 -0
- package/dist/handlers/update-xero-contact.handler.js +66 -0
- package/dist/handlers/update-xero-credit-note.handler.js +61 -0
- package/dist/handlers/update-xero-invoice.handler.js +63 -0
- package/dist/handlers/update-xero-item.handler.js +46 -0
- package/dist/handlers/update-xero-manual-journal.handler.js +46 -0
- package/dist/handlers/update-xero-payroll-timesheet-add-line.handler.js +28 -0
- package/dist/handlers/update-xero-payroll-timesheet-update-line.handler.js +28 -0
- package/dist/handlers/update-xero-quote.handler.js +78 -0
- package/dist/handlers/update-xero-tracking-category.handler.js +43 -0
- package/dist/handlers/update-xero-tracking-options.handler.js +51 -0
- package/dist/helpers/create-xero-tool.js +6 -0
- package/dist/helpers/ensure-error.js +13 -0
- package/dist/helpers/format-aged-report-filter.js +8 -0
- package/dist/helpers/format-error.js +57 -0
- package/dist/helpers/format-line-item.js +13 -0
- package/dist/helpers/format-token-error.js +34 -0
- package/dist/helpers/format-tracking-option.js +7 -0
- package/dist/helpers/get-client-headers.js +8 -0
- package/dist/helpers/get-deeplink.js +41 -0
- package/dist/helpers/get-external-link.js +8 -0
- package/dist/helpers/get-package-version.js +20 -0
- package/dist/index.js +16 -0
- package/dist/server/xero-mcp-server.js +14 -0
- package/dist/tools/create/create-bank-transaction.tool.js +57 -0
- package/dist/tools/create/create-contact.tool.js +56 -0
- package/dist/tools/create/create-credit-note.tool.js +53 -0
- package/dist/tools/create/create-invoice.tool.js +76 -0
- package/dist/tools/create/create-item.tool.js +61 -0
- package/dist/tools/create/create-manual-journal.tool.js +116 -0
- package/dist/tools/create/create-payment.tool.js +71 -0
- package/dist/tools/create/create-payroll-timesheet.tool.js +40 -0
- package/dist/tools/create/create-quote.tool.js +57 -0
- package/dist/tools/create/create-tracking-category.tool.js +28 -0
- package/dist/tools/create/create-tracking-options.tool.js +30 -0
- package/dist/tools/create/index.js +24 -0
- package/dist/tools/delete/delete-payroll-timesheet.tool.js +28 -0
- package/dist/tools/delete/index.js +4 -0
- package/dist/tools/get/get-invoice-attachment.tool.js +45 -0
- package/dist/tools/get/get-payroll-timesheet.tool.js +49 -0
- package/dist/tools/get/index.js +6 -0
- package/dist/tools/history/index.js +141 -0
- package/dist/tools/list/index.js +54 -0
- package/dist/tools/list/list-accounts.tool.js +39 -0
- package/dist/tools/list/list-aged-payables-by-contact.tool.js +49 -0
- package/dist/tools/list/list-aged-receivables-by-contact.tool.js +49 -0
- package/dist/tools/list/list-bank-transactions.tool.js +63 -0
- package/dist/tools/list/list-contact-groups.tool.js +48 -0
- package/dist/tools/list/list-contacts.tool.js +70 -0
- package/dist/tools/list/list-credit-notes.tool.js +70 -0
- package/dist/tools/list/list-invoice-attachments.tool.js +42 -0
- package/dist/tools/list/list-invoices.tool.js +141 -0
- package/dist/tools/list/list-items.tool.js +53 -0
- package/dist/tools/list/list-manual-journals.tool.js +83 -0
- package/dist/tools/list/list-organisation-details.tool.js +90 -0
- package/dist/tools/list/list-payments.tool.js +84 -0
- package/dist/tools/list/list-payroll-employee-leave-balances.tool.js +39 -0
- package/dist/tools/list/list-payroll-employee-leave-types.tool.js +57 -0
- package/dist/tools/list/list-payroll-employee-leave.tool.js +42 -0
- package/dist/tools/list/list-payroll-employees.tool.js +48 -0
- package/dist/tools/list/list-payroll-leave-periods.tool.js +45 -0
- package/dist/tools/list/list-payroll-leave-types.tool.js +39 -0
- package/dist/tools/list/list-payroll-timesheets.tool.js +39 -0
- package/dist/tools/list/list-profit-and-loss.tool.js +45 -0
- package/dist/tools/list/list-quotes.tool.js +72 -0
- package/dist/tools/list/list-report-balance-sheet.tool.js +39 -0
- package/dist/tools/list/list-tax-rates.tool.js +49 -0
- package/dist/tools/list/list-tracking-categories.tool.js +39 -0
- package/dist/tools/list/list-trial-balance.tool.js +41 -0
- package/dist/tools/tool-factory.js +24 -0
- package/dist/tools/update/approve-payroll-timesheet.tool.js +29 -0
- package/dist/tools/update/index.js +28 -0
- package/dist/tools/update/revert-payroll-timesheet.tool.js +29 -0
- package/dist/tools/update/update-bank-transaction.tool.js +56 -0
- package/dist/tools/update/update-contact.tool.js +69 -0
- package/dist/tools/update/update-credit-note.tool.js +56 -0
- package/dist/tools/update/update-invoice.tool.js +74 -0
- package/dist/tools/update/update-item.tool.js +62 -0
- package/dist/tools/update/update-manual-journal-tool.js +89 -0
- package/dist/tools/update/update-payroll-timesheet-add-line.tool.js +34 -0
- package/dist/tools/update/update-payroll-timesheet-update-line.tool.js +35 -0
- package/dist/tools/update/update-quote.tool.js +61 -0
- package/dist/tools/update/update-tracking-category.tool.js +30 -0
- package/dist/tools/update/update-tracking-options.tool.js +35 -0
- package/dist/types/list-report-balance-sheet-params.js +1 -0
- package/dist/types/timeframeType.js +1 -0
- package/dist/types/tool-definition.js +1 -0
- package/dist/types/tool-list.js +1 -0
- package/dist/types/tool-response.js +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
4
|
+
/**
|
|
5
|
+
* Internal function to fetch trial balance data from Xero
|
|
6
|
+
*/
|
|
7
|
+
async function fetchTrialBalance(date, paymentsOnly) {
|
|
8
|
+
await xeroClient.authenticate();
|
|
9
|
+
const response = await xeroClient.accountingApi.getReportTrialBalance(xeroClient.tenantId, date, // Optional date parameter in YYYY-MM-DD format
|
|
10
|
+
paymentsOnly, // Optional boolean to include only accounts with payments
|
|
11
|
+
getClientHeaders());
|
|
12
|
+
return response.body.reports?.[0] ?? null;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* List trial balance report from Xero
|
|
16
|
+
* @param date Optional date for trial balance in YYYY-MM-DD format
|
|
17
|
+
* @param paymentsOnly Optional boolean to include only accounts with payments
|
|
18
|
+
*/
|
|
19
|
+
export async function listXeroTrialBalance(date, paymentsOnly) {
|
|
20
|
+
try {
|
|
21
|
+
const trialBalance = await fetchTrialBalance(date, paymentsOnly);
|
|
22
|
+
if (!trialBalance) {
|
|
23
|
+
return {
|
|
24
|
+
result: null,
|
|
25
|
+
isError: true,
|
|
26
|
+
error: "Failed to fetch trial balance data from Xero.",
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
result: trialBalance,
|
|
31
|
+
isError: false,
|
|
32
|
+
error: null,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
return {
|
|
37
|
+
result: null,
|
|
38
|
+
isError: true,
|
|
39
|
+
error: formatError(error),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
async function revertTimesheet(timesheetID) {
|
|
4
|
+
await xeroClient.authenticate();
|
|
5
|
+
// Call the revertTimesheet endpoint from the PayrollNZApi
|
|
6
|
+
const revertedTimesheet = await xeroClient.payrollNZApi.revertTimesheet(xeroClient.tenantId, timesheetID);
|
|
7
|
+
return revertedTimesheet.body.timesheet ?? null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Revert a payroll timesheet to draft in Xero
|
|
11
|
+
*/
|
|
12
|
+
export async function revertXeroPayrollTimesheet(timesheetID) {
|
|
13
|
+
try {
|
|
14
|
+
const revertedTimesheet = await revertTimesheet(timesheetID);
|
|
15
|
+
return {
|
|
16
|
+
result: revertedTimesheet,
|
|
17
|
+
isError: false,
|
|
18
|
+
error: null,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return {
|
|
23
|
+
result: null,
|
|
24
|
+
isError: true,
|
|
25
|
+
error: formatError(error),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
4
|
+
import { BankTransaction } from "xero-node";
|
|
5
|
+
async function getBankTransaction(bankTransactionId) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
const response = await xeroClient.accountingApi.getBankTransaction(xeroClient.tenantId, // xeroTenantId
|
|
8
|
+
bankTransactionId, // bankTransactionID
|
|
9
|
+
undefined, // unitdp
|
|
10
|
+
getClientHeaders() // options
|
|
11
|
+
);
|
|
12
|
+
return response.body.bankTransactions?.[0];
|
|
13
|
+
}
|
|
14
|
+
async function updateBankTransaction(bankTransactionId, existingBankTransaction, type, contactId, lineItems, reference, date) {
|
|
15
|
+
const bankTransaction = {
|
|
16
|
+
...existingBankTransaction,
|
|
17
|
+
bankTransactionID: bankTransactionId,
|
|
18
|
+
type: type ? BankTransaction.TypeEnum[type] : existingBankTransaction.type,
|
|
19
|
+
contact: contactId ? { contactID: contactId } : existingBankTransaction.contact,
|
|
20
|
+
lineItems: lineItems ? lineItems : existingBankTransaction.lineItems,
|
|
21
|
+
reference: reference ? reference : existingBankTransaction.reference,
|
|
22
|
+
date: date ? date : existingBankTransaction.date
|
|
23
|
+
};
|
|
24
|
+
const response = await xeroClient.accountingApi.updateBankTransaction(xeroClient.tenantId, // xeroTenantId
|
|
25
|
+
bankTransactionId, // bankTransactionID
|
|
26
|
+
{ bankTransactions: [bankTransaction] }, // bankTransactions
|
|
27
|
+
undefined, // unitdp
|
|
28
|
+
undefined, // idempotencyKey
|
|
29
|
+
getClientHeaders() // options
|
|
30
|
+
);
|
|
31
|
+
return response.body.bankTransactions?.[0];
|
|
32
|
+
}
|
|
33
|
+
export async function updateXeroBankTransaction(bankTransactionId, type, contactId, lineItems, reference, date) {
|
|
34
|
+
try {
|
|
35
|
+
const existingBankTransaction = await getBankTransaction(bankTransactionId);
|
|
36
|
+
if (!existingBankTransaction) {
|
|
37
|
+
throw new Error(`Could not find bank transaction`);
|
|
38
|
+
}
|
|
39
|
+
const updatedBankTransaction = await updateBankTransaction(bankTransactionId, existingBankTransaction, type, contactId, lineItems, reference, date);
|
|
40
|
+
if (!updatedBankTransaction) {
|
|
41
|
+
throw new Error(`Failed to update bank transaction`);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
result: updatedBankTransaction,
|
|
45
|
+
isError: false,
|
|
46
|
+
error: null
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
return {
|
|
51
|
+
result: null,
|
|
52
|
+
isError: true,
|
|
53
|
+
error: formatError(error),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
import { Phone, Address } from "xero-node";
|
|
4
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
5
|
+
async function updateContact(name, firstName, lastName, email, phone, address, contactId) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
const contact = {
|
|
8
|
+
name,
|
|
9
|
+
firstName,
|
|
10
|
+
lastName,
|
|
11
|
+
emailAddress: email,
|
|
12
|
+
phones: phone
|
|
13
|
+
? [
|
|
14
|
+
{
|
|
15
|
+
phoneNumber: phone,
|
|
16
|
+
phoneType: Phone.PhoneTypeEnum.MOBILE,
|
|
17
|
+
},
|
|
18
|
+
]
|
|
19
|
+
: undefined,
|
|
20
|
+
addresses: address
|
|
21
|
+
? [
|
|
22
|
+
{
|
|
23
|
+
addressType: Address.AddressTypeEnum.STREET,
|
|
24
|
+
addressLine1: address.addressLine1,
|
|
25
|
+
addressLine2: address.addressLine2,
|
|
26
|
+
city: address.city,
|
|
27
|
+
country: address.country,
|
|
28
|
+
postalCode: address.postalCode,
|
|
29
|
+
region: address.region,
|
|
30
|
+
},
|
|
31
|
+
]
|
|
32
|
+
: undefined,
|
|
33
|
+
};
|
|
34
|
+
const contacts = {
|
|
35
|
+
contacts: [contact],
|
|
36
|
+
};
|
|
37
|
+
const response = await xeroClient.accountingApi.updateContact(xeroClient.tenantId, contactId, // contactId
|
|
38
|
+
contacts, // contacts
|
|
39
|
+
undefined, // idempotencyKey
|
|
40
|
+
getClientHeaders());
|
|
41
|
+
const updatedContact = response.body.contacts?.[0];
|
|
42
|
+
return updatedContact;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Create a new invoice in Xero
|
|
46
|
+
*/
|
|
47
|
+
export async function updateXeroContact(contactId, name, firstName, lastName, email, phone, address) {
|
|
48
|
+
try {
|
|
49
|
+
const updatedContact = await updateContact(name, firstName, lastName, email, phone, address, contactId);
|
|
50
|
+
if (!updatedContact) {
|
|
51
|
+
throw new Error("Contact update failed.");
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
result: updatedContact,
|
|
55
|
+
isError: false,
|
|
56
|
+
error: null,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
return {
|
|
61
|
+
result: null,
|
|
62
|
+
isError: true,
|
|
63
|
+
error: formatError(error),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
import { CreditNote } from "xero-node";
|
|
4
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
5
|
+
async function getCreditNote(creditNoteId) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
// First, get the current credit note to check its status
|
|
8
|
+
const response = await xeroClient.accountingApi.getCreditNote(xeroClient.tenantId, creditNoteId, // creditNoteId
|
|
9
|
+
undefined, // unitdp
|
|
10
|
+
getClientHeaders());
|
|
11
|
+
return response.body.creditNotes?.[0] ?? null;
|
|
12
|
+
}
|
|
13
|
+
async function updateCreditNote(creditNoteId, lineItems, reference, contactId, date) {
|
|
14
|
+
const creditNote = {
|
|
15
|
+
lineItems: lineItems,
|
|
16
|
+
reference: reference,
|
|
17
|
+
date: date,
|
|
18
|
+
contact: contactId ? { contactID: contactId } : undefined,
|
|
19
|
+
};
|
|
20
|
+
const response = await xeroClient.accountingApi.updateCreditNote(xeroClient.tenantId, creditNoteId, // creditNoteId
|
|
21
|
+
{
|
|
22
|
+
creditNotes: [creditNote],
|
|
23
|
+
}, // creditNotes
|
|
24
|
+
undefined, // unitdp
|
|
25
|
+
undefined, // idempotencyKey
|
|
26
|
+
getClientHeaders());
|
|
27
|
+
return response.body.creditNotes?.[0] ?? null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Update an existing credit note in Xero
|
|
31
|
+
*/
|
|
32
|
+
export async function updateXeroCreditNote(creditNoteId, lineItems, reference, contactId, date) {
|
|
33
|
+
try {
|
|
34
|
+
const existingCreditNote = await getCreditNote(creditNoteId);
|
|
35
|
+
const creditNoteStatus = existingCreditNote?.status;
|
|
36
|
+
// Only allow updates to DRAFT credit notes
|
|
37
|
+
if (creditNoteStatus !== CreditNote.StatusEnum.DRAFT) {
|
|
38
|
+
return {
|
|
39
|
+
result: null,
|
|
40
|
+
isError: true,
|
|
41
|
+
error: `Cannot update credit note because it is not a draft. Current status: ${creditNoteStatus}`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const updatedCreditNote = await updateCreditNote(creditNoteId, lineItems, reference, contactId, date);
|
|
45
|
+
if (!updatedCreditNote) {
|
|
46
|
+
throw new Error("Credit note update failed.");
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
result: updatedCreditNote,
|
|
50
|
+
isError: false,
|
|
51
|
+
error: null,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
return {
|
|
56
|
+
result: null,
|
|
57
|
+
isError: true,
|
|
58
|
+
error: formatError(error),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
import { Invoice } from "xero-node";
|
|
4
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
5
|
+
async function getInvoice(invoiceId) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
// First, get the current invoice to check its status
|
|
8
|
+
const response = await xeroClient.accountingApi.getInvoice(xeroClient.tenantId, invoiceId, // invoiceId
|
|
9
|
+
undefined, // unitdp
|
|
10
|
+
getClientHeaders());
|
|
11
|
+
return response.body.invoices?.[0];
|
|
12
|
+
}
|
|
13
|
+
async function updateInvoice(invoiceId, lineItems, reference, dueDate, date, contactId, currencyCode) {
|
|
14
|
+
const invoice = {
|
|
15
|
+
lineItems: lineItems,
|
|
16
|
+
reference: reference,
|
|
17
|
+
dueDate: dueDate,
|
|
18
|
+
date: date,
|
|
19
|
+
contact: contactId ? { contactID: contactId } : undefined,
|
|
20
|
+
...(currencyCode ? { currencyCode } : {}),
|
|
21
|
+
};
|
|
22
|
+
const response = await xeroClient.accountingApi.updateInvoice(xeroClient.tenantId, invoiceId, // invoiceId
|
|
23
|
+
{
|
|
24
|
+
invoices: [invoice],
|
|
25
|
+
}, // invoices
|
|
26
|
+
undefined, // unitdp
|
|
27
|
+
undefined, // idempotencyKey
|
|
28
|
+
getClientHeaders());
|
|
29
|
+
return response.body.invoices?.[0];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Update an existing invoice in Xero
|
|
33
|
+
*/
|
|
34
|
+
export async function updateXeroInvoice(invoiceId, lineItems, reference, dueDate, date, contactId, currencyCode) {
|
|
35
|
+
try {
|
|
36
|
+
const existingInvoice = await getInvoice(invoiceId);
|
|
37
|
+
const invoiceStatus = existingInvoice?.status;
|
|
38
|
+
// Only allow updates to DRAFT invoices
|
|
39
|
+
if (invoiceStatus !== Invoice.StatusEnum.DRAFT) {
|
|
40
|
+
return {
|
|
41
|
+
result: null,
|
|
42
|
+
isError: true,
|
|
43
|
+
error: `Cannot update invoice because it is not a draft. Current status: ${invoiceStatus}`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const updatedInvoice = await updateInvoice(invoiceId, lineItems, reference, dueDate, date, contactId, currencyCode);
|
|
47
|
+
if (!updatedInvoice) {
|
|
48
|
+
throw new Error("Invoice update failed.");
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
result: updatedInvoice,
|
|
52
|
+
isError: false,
|
|
53
|
+
error: null,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
return {
|
|
58
|
+
result: null,
|
|
59
|
+
isError: true,
|
|
60
|
+
error: formatError(error),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
4
|
+
async function updateItem(itemId, itemDetails) {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const item = {
|
|
7
|
+
code: itemDetails.code,
|
|
8
|
+
name: itemDetails.name,
|
|
9
|
+
description: itemDetails.description,
|
|
10
|
+
purchaseDescription: itemDetails.purchaseDescription,
|
|
11
|
+
purchaseDetails: itemDetails.purchaseDetails,
|
|
12
|
+
salesDetails: itemDetails.salesDetails,
|
|
13
|
+
isTrackedAsInventory: itemDetails.isTrackedAsInventory,
|
|
14
|
+
inventoryAssetAccountCode: itemDetails.inventoryAssetAccountCode,
|
|
15
|
+
};
|
|
16
|
+
const items = {
|
|
17
|
+
items: [item],
|
|
18
|
+
};
|
|
19
|
+
const response = await xeroClient.accountingApi.updateItem(xeroClient.tenantId, itemId, items, undefined, // unitdp
|
|
20
|
+
undefined, // idempotencyKey
|
|
21
|
+
getClientHeaders());
|
|
22
|
+
return response.body.items?.[0] ?? null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Update an item in Xero
|
|
26
|
+
* @param itemId - The ID of the item to update
|
|
27
|
+
* @param itemDetails - The details to update on the item
|
|
28
|
+
* @returns A response containing the updated item or error details
|
|
29
|
+
*/
|
|
30
|
+
export async function updateXeroItem(itemId, itemDetails) {
|
|
31
|
+
try {
|
|
32
|
+
const item = await updateItem(itemId, itemDetails);
|
|
33
|
+
return {
|
|
34
|
+
result: item,
|
|
35
|
+
isError: false,
|
|
36
|
+
error: null,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
return {
|
|
41
|
+
result: null,
|
|
42
|
+
isError: true,
|
|
43
|
+
error: formatError(error),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
3
|
+
import { formatError } from "../helpers/format-error.js";
|
|
4
|
+
async function updateManualJournal(narration, manualJournalID, manualJournalLines, date, lineAmountTypes, status, url, showOnCashBasisReports) {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const manualJournal = {
|
|
7
|
+
narration,
|
|
8
|
+
journalLines: manualJournalLines.map((journalLine) => ({
|
|
9
|
+
lineAmount: journalLine.lineAmount,
|
|
10
|
+
accountCode: journalLine.accountCode,
|
|
11
|
+
description: journalLine.description, // Optional: description for the manual journal line
|
|
12
|
+
taxType: journalLine.taxType, // Optional: tax type for the manual journal line
|
|
13
|
+
// TODO: tracking can be added here
|
|
14
|
+
})),
|
|
15
|
+
date: date, // Optional: YYYY-MM-DD format
|
|
16
|
+
lineAmountTypes: lineAmountTypes, // Optional: ManualJournal.LineAmountTypesEnum.EXCLUSIVE
|
|
17
|
+
status: status, // Optional: ManualJournal.StatusEnum.DRAFT
|
|
18
|
+
url: url, // Optional: URL link to a source document
|
|
19
|
+
showOnCashBasisReports: showOnCashBasisReports, // Optional: default is true if not specified
|
|
20
|
+
};
|
|
21
|
+
const manualJournals = {
|
|
22
|
+
manualJournals: [manualJournal],
|
|
23
|
+
};
|
|
24
|
+
const response = await xeroClient.accountingApi.updateManualJournal(xeroClient.tenantId, manualJournalID, manualJournals, undefined, getClientHeaders());
|
|
25
|
+
return response.body.manualJournals?.[0];
|
|
26
|
+
}
|
|
27
|
+
export async function updateXeroManualJournal(narration, manualJournalID, manualJournalLines, date, lineAmountTypes, status, url, showOnCashBasisReports) {
|
|
28
|
+
try {
|
|
29
|
+
const updatedManualJournal = await updateManualJournal(narration, manualJournalID, manualJournalLines, date, lineAmountTypes, status, url, showOnCashBasisReports);
|
|
30
|
+
if (!updatedManualJournal) {
|
|
31
|
+
throw new Error("Manual journal update failed.");
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
result: updatedManualJournal,
|
|
35
|
+
isError: false,
|
|
36
|
+
error: null,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
return {
|
|
41
|
+
result: null,
|
|
42
|
+
isError: true,
|
|
43
|
+
error: formatError(error),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
async function addTimesheetLine(timesheetID, timesheetLine) {
|
|
4
|
+
await xeroClient.authenticate();
|
|
5
|
+
// Call the createTimesheetLine endpoint from the PayrollNZApi
|
|
6
|
+
const createdLine = await xeroClient.payrollNZApi.createTimesheetLine(xeroClient.tenantId, timesheetID, timesheetLine);
|
|
7
|
+
return createdLine.body.timesheetLine ?? null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Add a timesheet line to an existing payroll timesheet in Xero
|
|
11
|
+
*/
|
|
12
|
+
export async function updateXeroPayrollTimesheetAddLine(timesheetID, timesheetLine) {
|
|
13
|
+
try {
|
|
14
|
+
const newLine = await addTimesheetLine(timesheetID, timesheetLine);
|
|
15
|
+
return {
|
|
16
|
+
result: newLine,
|
|
17
|
+
isError: false,
|
|
18
|
+
error: null,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return {
|
|
23
|
+
result: null,
|
|
24
|
+
isError: true,
|
|
25
|
+
error: formatError(error),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
async function updateTimesheetLine(timesheetID, timesheetLineID, timesheetLine) {
|
|
4
|
+
await xeroClient.authenticate();
|
|
5
|
+
// Call the updateTimesheetLine endpoint from the PayrollNZApi
|
|
6
|
+
const updatedLine = await xeroClient.payrollNZApi.updateTimesheetLine(xeroClient.tenantId, timesheetID, timesheetLineID, timesheetLine);
|
|
7
|
+
return updatedLine.body.timesheetLine ?? null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Update an existing timesheet line in a payroll timesheet in Xero
|
|
11
|
+
*/
|
|
12
|
+
export async function updateXeroPayrollTimesheetUpdateLine(timesheetID, timesheetLineID, timesheetLine) {
|
|
13
|
+
try {
|
|
14
|
+
const updatedLine = await updateTimesheetLine(timesheetID, timesheetLineID, timesheetLine);
|
|
15
|
+
return {
|
|
16
|
+
result: updatedLine,
|
|
17
|
+
isError: false,
|
|
18
|
+
error: null,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return {
|
|
23
|
+
result: null,
|
|
24
|
+
isError: true,
|
|
25
|
+
error: formatError(error),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
import { QuoteStatusCodes } from "xero-node";
|
|
4
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
5
|
+
async function getQuote(quoteId) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
// First, get the current quote to check its status
|
|
8
|
+
const response = await xeroClient.accountingApi.getQuote(xeroClient.tenantId, // tenantId
|
|
9
|
+
quoteId, // quoteId
|
|
10
|
+
getClientHeaders());
|
|
11
|
+
return response.body.quotes?.[0];
|
|
12
|
+
}
|
|
13
|
+
async function updateQuote(quoteId, lineItems, reference, terms, title, summary, quoteNumber, contactId, date, expiryDate, existingQuote) {
|
|
14
|
+
// Create quote object with only the fields that are being updated
|
|
15
|
+
const quote = {
|
|
16
|
+
lineItems: lineItems,
|
|
17
|
+
reference: reference,
|
|
18
|
+
terms: terms,
|
|
19
|
+
title: title,
|
|
20
|
+
summary: summary,
|
|
21
|
+
quoteNumber: quoteNumber,
|
|
22
|
+
expiryDate: expiryDate,
|
|
23
|
+
};
|
|
24
|
+
// Only add contact if contactId is provided, otherwise use existing
|
|
25
|
+
if (contactId) {
|
|
26
|
+
quote.contact = { contactID: contactId };
|
|
27
|
+
}
|
|
28
|
+
else if (existingQuote?.contact) {
|
|
29
|
+
quote.contact = existingQuote.contact;
|
|
30
|
+
}
|
|
31
|
+
// Only add date if provided, otherwise use existing
|
|
32
|
+
if (date) {
|
|
33
|
+
quote.date = date;
|
|
34
|
+
}
|
|
35
|
+
else if (existingQuote?.date) {
|
|
36
|
+
quote.date = existingQuote.date;
|
|
37
|
+
}
|
|
38
|
+
const response = await xeroClient.accountingApi.updateQuote(xeroClient.tenantId, quoteId, // quoteId
|
|
39
|
+
{
|
|
40
|
+
quotes: [quote],
|
|
41
|
+
}, // quotes
|
|
42
|
+
undefined, // idempotencyKey
|
|
43
|
+
getClientHeaders());
|
|
44
|
+
return response.body.quotes?.[0];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Update an existing quote in Xero
|
|
48
|
+
*/
|
|
49
|
+
export async function updateXeroQuote(quoteId, lineItems, reference, terms, title, summary, quoteNumber, contactId, date, expiryDate) {
|
|
50
|
+
try {
|
|
51
|
+
const existingQuote = await getQuote(quoteId);
|
|
52
|
+
const quoteStatus = existingQuote?.status;
|
|
53
|
+
// Only allow updates to DRAFT quotes
|
|
54
|
+
if (quoteStatus !== QuoteStatusCodes.DRAFT) {
|
|
55
|
+
return {
|
|
56
|
+
result: null,
|
|
57
|
+
isError: true,
|
|
58
|
+
error: `Cannot update quote because it is not a draft. Current status: ${quoteStatus}`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const updatedQuote = await updateQuote(quoteId, lineItems, reference, terms, title, summary, quoteNumber, contactId, date, expiryDate, existingQuote);
|
|
62
|
+
if (!updatedQuote) {
|
|
63
|
+
throw new Error("Quote update failed.");
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
result: updatedQuote,
|
|
67
|
+
isError: false,
|
|
68
|
+
error: null,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
return {
|
|
73
|
+
result: null,
|
|
74
|
+
isError: true,
|
|
75
|
+
error: formatError(error),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { TrackingCategory } from "xero-node";
|
|
2
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
3
|
+
import { formatError } from "../helpers/format-error.js";
|
|
4
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
5
|
+
async function getTrackingCategory(trackingCategoryId) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
const response = await xeroClient.accountingApi.getTrackingCategory(xeroClient.tenantId, trackingCategoryId, getClientHeaders());
|
|
8
|
+
return response.body.trackingCategories?.[0];
|
|
9
|
+
}
|
|
10
|
+
async function updateTrackingCategory(trackingCategoryId, existingTrackingCategory, name, status) {
|
|
11
|
+
const trackingCategory = {
|
|
12
|
+
trackingCategoryID: trackingCategoryId,
|
|
13
|
+
name: name ? name : existingTrackingCategory.name,
|
|
14
|
+
status: status ? TrackingCategory.StatusEnum[status] : existingTrackingCategory.status
|
|
15
|
+
};
|
|
16
|
+
await xeroClient.accountingApi.updateTrackingCategory(xeroClient.tenantId, trackingCategoryId, trackingCategory, undefined, // idempotencyKey
|
|
17
|
+
getClientHeaders());
|
|
18
|
+
return trackingCategory;
|
|
19
|
+
}
|
|
20
|
+
export async function updateXeroTrackingCategory(trackingCategoryId, name, status) {
|
|
21
|
+
try {
|
|
22
|
+
const existingTrackingCategory = await getTrackingCategory(trackingCategoryId);
|
|
23
|
+
if (!existingTrackingCategory) {
|
|
24
|
+
throw new Error("Could not find tracking category.");
|
|
25
|
+
}
|
|
26
|
+
const updatedTrackingCategory = await updateTrackingCategory(trackingCategoryId, existingTrackingCategory, name, status);
|
|
27
|
+
if (!updatedTrackingCategory) {
|
|
28
|
+
throw new Error("Failed to update tracking category.");
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
result: existingTrackingCategory,
|
|
32
|
+
isError: false,
|
|
33
|
+
error: null
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
return {
|
|
38
|
+
result: null,
|
|
39
|
+
isError: true,
|
|
40
|
+
error: formatError(error),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { TrackingOption } from "xero-node";
|
|
2
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
3
|
+
import { formatError } from "../helpers/format-error.js";
|
|
4
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
5
|
+
async function getTrackingOptions(trackingCategoryId) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
const response = await xeroClient.accountingApi.getTrackingCategory(xeroClient.tenantId, trackingCategoryId, getClientHeaders());
|
|
8
|
+
return response.body.trackingCategories?.[0].options;
|
|
9
|
+
}
|
|
10
|
+
async function updateTrackingOption(trackingCategoryId, trackingOptionId, existingTrackingOption, name, status) {
|
|
11
|
+
const trackingOption = {
|
|
12
|
+
trackingOptionID: trackingOptionId,
|
|
13
|
+
name: name ? name : existingTrackingOption.name,
|
|
14
|
+
status: status ? TrackingOption.StatusEnum[status] : existingTrackingOption.status
|
|
15
|
+
};
|
|
16
|
+
await xeroClient.accountingApi.updateTrackingOptions(xeroClient.tenantId, trackingCategoryId, trackingOptionId, trackingOption, undefined, // idempotencyKey
|
|
17
|
+
getClientHeaders());
|
|
18
|
+
return trackingOption;
|
|
19
|
+
}
|
|
20
|
+
export async function updateXeroTrackingOption(trackingCategoryId, options) {
|
|
21
|
+
try {
|
|
22
|
+
const existingTrackingOptions = await getTrackingOptions(trackingCategoryId);
|
|
23
|
+
if (!existingTrackingOptions) {
|
|
24
|
+
throw new Error("Could not find tracking options.");
|
|
25
|
+
}
|
|
26
|
+
const updatedTrackingOptions = await Promise.all(options?.map(async (option) => {
|
|
27
|
+
const existingTrackingOption = existingTrackingOptions
|
|
28
|
+
.find(existingOption => existingOption.trackingOptionID === option.trackingOptionId);
|
|
29
|
+
return existingTrackingOption
|
|
30
|
+
? await updateTrackingOption(trackingCategoryId, option.trackingOptionId, existingTrackingOption, option.name, option.status)
|
|
31
|
+
: undefined;
|
|
32
|
+
}));
|
|
33
|
+
if (!updatedTrackingOptions) {
|
|
34
|
+
throw new Error("Failed to update tracking options.");
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
result: updatedTrackingOptions
|
|
38
|
+
.filter(Boolean)
|
|
39
|
+
.map(option => option),
|
|
40
|
+
isError: false,
|
|
41
|
+
error: null
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
return {
|
|
46
|
+
result: null,
|
|
47
|
+
isError: true,
|
|
48
|
+
error: formatError(error),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function ensureError(value) {
|
|
2
|
+
if (value instanceof Error)
|
|
3
|
+
return value;
|
|
4
|
+
let stringified = "[Unable to stringify the thrown value]";
|
|
5
|
+
try {
|
|
6
|
+
stringified = JSON.stringify(value);
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
/* empty */
|
|
10
|
+
}
|
|
11
|
+
const error = new Error(`Error thrown: ${stringified}`);
|
|
12
|
+
return error;
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const formatAgedReportFilter = (fromDate, toDate) => {
|
|
2
|
+
if (!fromDate && !toDate) {
|
|
3
|
+
return undefined;
|
|
4
|
+
}
|
|
5
|
+
const formattedFromDate = fromDate ? `from ${fromDate}` : "";
|
|
6
|
+
const formattedToDate = toDate ? `to ${toDate}` : "";
|
|
7
|
+
return `Showing invoices ${formattedFromDate} ${formattedToDate}`;
|
|
8
|
+
};
|