@teamnetwork-nz/xero-mcp-server 1.6.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/LICENSE +21 -0
- package/README.md +282 -0
- package/dist/clients/xero-client.js +141 -0
- package/dist/consts/deeplinks.js +24 -0
- package/dist/handlers/approve-xero-payroll-timesheet.handler.js +28 -0
- package/dist/handlers/archive-xero-contact.handler.js +28 -0
- package/dist/handlers/authorise-xero-invoice.handler.js +34 -0
- package/dist/handlers/convert-xero-quote-to-invoice.handler.js +50 -0
- package/dist/handlers/create-xero-bank-transaction.handler.js +51 -0
- package/dist/handlers/create-xero-contact.handler.js +49 -0
- package/dist/handlers/create-xero-credit-note.handler.js +50 -0
- package/dist/handlers/create-xero-invoice.handler.js +53 -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 +50 -0
- package/dist/handlers/create-xero-payroll-timesheet.handler.js +28 -0
- package/dist/handlers/create-xero-quote.handler.js +53 -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-invoice-attachment.handler.js +30 -0
- package/dist/handlers/delete-xero-payroll-timesheet.handler.js +28 -0
- package/dist/handlers/download-xero-invoice-attachment.handler.js +23 -0
- package/dist/handlers/download-xero-invoice-pdf.handler.js +25 -0
- package/dist/handlers/get-xero-invoice.handler.js +19 -0
- package/dist/handlers/get-xero-payroll-timesheet.handler.js +28 -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 +39 -0
- package/dist/handlers/list-xero-contact-groups.handler.js +34 -0
- package/dist/handlers/list-xero-contacts.handler.js +47 -0
- package/dist/handlers/list-xero-credit-notes.handler.js +42 -0
- package/dist/handlers/list-xero-invoice-attachments.handler.js +20 -0
- package/dist/handlers/list-xero-invoices.handler.js +54 -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 +52 -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 +36 -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 +62 -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/handlers/upload-xero-invoice-attachment.handler.js +36 -0
- package/dist/handlers/void-xero-invoice.handler.js +52 -0
- package/dist/helpers/build-where-clause.js +29 -0
- package/dist/helpers/create-xero-tool.js +6 -0
- package/dist/helpers/datetime.js +91 -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 +25 -0
- package/dist/helpers/format-line-item.js +13 -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-download-path.js +16 -0
- package/dist/helpers/get-external-link.js +8 -0
- package/dist/helpers/get-package-version.js +20 -0
- package/dist/index.js +18 -0
- package/dist/resources/register-resources.js +27 -0
- package/dist/server/xero-mcp-server.js +43 -0
- package/dist/tools/create/convert-quote-to-invoice.tool.js +46 -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 +78 -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 +35 -0
- package/dist/tools/create/upload-invoice-attachment.tool.js +49 -0
- package/dist/tools/delete/archive-contact.tool.js +30 -0
- package/dist/tools/delete/delete-invoice-attachment.tool.js +28 -0
- package/dist/tools/delete/delete-payroll-timesheet.tool.js +28 -0
- package/dist/tools/delete/index.js +15 -0
- package/dist/tools/get/get-invoice-attachment.tool.js +33 -0
- package/dist/tools/get/get-invoice-pdf.tool.js +33 -0
- package/dist/tools/get/get-invoice.tool.js +72 -0
- package/dist/tools/get/get-payroll-timesheet.tool.js +50 -0
- package/dist/tools/get/index.js +17 -0
- package/dist/tools/list/index.js +64 -0
- package/dist/tools/list/list-accounts.tool.js +39 -0
- package/dist/tools/list/list-aged-payables-by-contact.tool.js +51 -0
- package/dist/tools/list/list-aged-receivables-by-contact.tool.js +51 -0
- package/dist/tools/list/list-bank-transactions.tool.js +66 -0
- package/dist/tools/list/list-contact-groups.tool.js +48 -0
- package/dist/tools/list/list-contacts.tool.js +80 -0
- package/dist/tools/list/list-credit-notes.tool.js +72 -0
- package/dist/tools/list/list-invoice-attachments.tool.js +42 -0
- package/dist/tools/list/list-invoices.tool.js +98 -0
- package/dist/tools/list/list-items.tool.js +50 -0
- package/dist/tools/list/list-manual-journals.tool.js +80 -0
- package/dist/tools/list/list-organisation-details.tool.js +91 -0
- package/dist/tools/list/list-payments.tool.js +91 -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 +43 -0
- package/dist/tools/list/list-payroll-employees.tool.js +49 -0
- package/dist/tools/list/list-payroll-leave-periods.tool.js +45 -0
- package/dist/tools/list/list-payroll-leave-types.tool.js +40 -0
- package/dist/tools/list/list-payroll-timesheets.tool.js +40 -0
- package/dist/tools/list/list-profit-and-loss.tool.js +46 -0
- package/dist/tools/list/list-quotes.tool.js +69 -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 +42 -0
- package/dist/tools/tool-factory.js +24 -0
- package/dist/tools/update/approve-payroll-timesheet.tool.js +29 -0
- package/dist/tools/update/authorise-invoice.tool.js +42 -0
- package/dist/tools/update/index.js +39 -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 +76 -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/tools/update/void-invoice.tool.js +33 -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 +38 -0
|
@@ -0,0 +1,40 @@
|
|
|
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 leave types from Xero
|
|
6
|
+
*/
|
|
7
|
+
async function fetchLeaveTypes() {
|
|
8
|
+
await xeroClient.authenticate();
|
|
9
|
+
const response = await xeroClient.payrollNZApi.getLeaveTypes(xeroClient.tenantId, undefined, // page
|
|
10
|
+
undefined, // pageSize
|
|
11
|
+
getClientHeaders());
|
|
12
|
+
return response.body.leaveTypes ?? null;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* List all leave types from Xero Payroll
|
|
16
|
+
*/
|
|
17
|
+
export async function listXeroPayrollLeaveTypes() {
|
|
18
|
+
try {
|
|
19
|
+
const leaveTypes = await fetchLeaveTypes();
|
|
20
|
+
if (!leaveTypes) {
|
|
21
|
+
return {
|
|
22
|
+
result: [],
|
|
23
|
+
isError: false,
|
|
24
|
+
error: null,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
result: leaveTypes,
|
|
29
|
+
isError: false,
|
|
30
|
+
error: null,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
return {
|
|
35
|
+
result: null,
|
|
36
|
+
isError: true,
|
|
37
|
+
error: formatError(error),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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 profit and loss data from Xero
|
|
6
|
+
*/
|
|
7
|
+
async function fetchProfitAndLoss(fromDate, toDate, periods, timeframe, standardLayout, paymentsOnly) {
|
|
8
|
+
await xeroClient.authenticate();
|
|
9
|
+
const response = await xeroClient.accountingApi.getReportProfitAndLoss(xeroClient.tenantId, fromDate, toDate, periods, timeframe, undefined, // trackingCategoryID
|
|
10
|
+
undefined, // trackingOptionID
|
|
11
|
+
undefined, // trackingCategoryID2
|
|
12
|
+
undefined, // trackingOptionID2
|
|
13
|
+
standardLayout, paymentsOnly, getClientHeaders());
|
|
14
|
+
return response.body.reports?.[0] ?? null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* List profit and loss report from Xero
|
|
18
|
+
* @param fromDate Optional start date for the report (YYYY-MM-DD)
|
|
19
|
+
* @param toDate Optional end date for the report (YYYY-MM-DD)
|
|
20
|
+
* @param periods Optional number of periods for the report
|
|
21
|
+
* @param timeframe Optional timeframe for the report (MONTH, QUARTER, YEAR)
|
|
22
|
+
* @param trackingCategoryID Optional tracking category ID
|
|
23
|
+
* @param trackingOptionID Optional tracking option ID
|
|
24
|
+
* @param trackingCategoryID2 Optional second tracking category ID
|
|
25
|
+
* @param trackingOptionID2 Optional second tracking option ID
|
|
26
|
+
* @param standardLayout Optional boolean to use standard layout
|
|
27
|
+
* @param paymentsOnly Optional boolean to include only accounts with payments
|
|
28
|
+
*/
|
|
29
|
+
export async function listXeroProfitAndLoss(fromDate, toDate, periods, timeframe, standardLayout, paymentsOnly) {
|
|
30
|
+
try {
|
|
31
|
+
const profitAndLoss = await fetchProfitAndLoss(fromDate, toDate, periods, timeframe, paymentsOnly);
|
|
32
|
+
if (!profitAndLoss) {
|
|
33
|
+
return {
|
|
34
|
+
result: null,
|
|
35
|
+
isError: true,
|
|
36
|
+
error: "Failed to fetch profit and loss data from Xero.",
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
result: profitAndLoss,
|
|
41
|
+
isError: false,
|
|
42
|
+
error: null,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
return {
|
|
47
|
+
result: null,
|
|
48
|
+
isError: true,
|
|
49
|
+
error: formatError(error),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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 getQuotes(contactId, page, quoteNumber, dateFrom, dateTo, status) {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const quotes = await xeroClient.accountingApi.getQuotes(xeroClient.tenantId, undefined, // ifModifiedSince
|
|
7
|
+
dateFrom, // dateFrom (native API param)
|
|
8
|
+
dateTo, // dateTo (native API param)
|
|
9
|
+
undefined, // expiryDateFrom
|
|
10
|
+
undefined, // expiryDateTo
|
|
11
|
+
contactId, // contactID
|
|
12
|
+
status, // status (native API param)
|
|
13
|
+
page, undefined, // order
|
|
14
|
+
quoteNumber, getClientHeaders());
|
|
15
|
+
return quotes.body.quotes ?? [];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* List quotes from Xero
|
|
19
|
+
*/
|
|
20
|
+
export async function listXeroQuotes(page = 1, contactId, quoteNumber, dateFrom, dateTo, status) {
|
|
21
|
+
try {
|
|
22
|
+
const quotes = await getQuotes(contactId, page, quoteNumber, dateFrom, dateTo, status);
|
|
23
|
+
return {
|
|
24
|
+
result: quotes,
|
|
25
|
+
isError: false,
|
|
26
|
+
error: null,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
return {
|
|
31
|
+
result: null,
|
|
32
|
+
isError: true,
|
|
33
|
+
error: formatError(error),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 getReportBalanceSheet(params) {
|
|
5
|
+
const { date, periods, timeframe, trackingOptionID1, trackingOptionID2, standardLayout, paymentsOnly, } = params;
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
const response = await xeroClient.accountingApi.getReportBalanceSheet(xeroClient.tenantId, date || undefined, periods || undefined, timeframe || undefined, trackingOptionID1 || undefined, trackingOptionID2 || undefined, standardLayout ?? undefined, paymentsOnly ?? undefined, getClientHeaders());
|
|
8
|
+
return response.body.reports?.[0] ?? null;
|
|
9
|
+
}
|
|
10
|
+
export async function listXeroReportBalanceSheet(params) {
|
|
11
|
+
try {
|
|
12
|
+
const balanceSheet = await getReportBalanceSheet(params);
|
|
13
|
+
if (!balanceSheet) {
|
|
14
|
+
return {
|
|
15
|
+
result: null,
|
|
16
|
+
isError: true,
|
|
17
|
+
error: "Failed to fetch balance sheet data from Xero.",
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
result: balanceSheet,
|
|
22
|
+
isError: false,
|
|
23
|
+
error: null,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
return {
|
|
28
|
+
result: null,
|
|
29
|
+
isError: true,
|
|
30
|
+
error: formatError(error),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
;
|
|
@@ -0,0 +1,30 @@
|
|
|
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 getTaxRates() {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const taxRates = await xeroClient.accountingApi.getTaxRates(xeroClient.tenantId, undefined, // where
|
|
7
|
+
undefined, // order
|
|
8
|
+
getClientHeaders());
|
|
9
|
+
return taxRates.body.taxRates ?? [];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* List all tax rates from Xero
|
|
13
|
+
*/
|
|
14
|
+
export async function listXeroTaxRates() {
|
|
15
|
+
try {
|
|
16
|
+
const taxRates = await getTaxRates();
|
|
17
|
+
return {
|
|
18
|
+
result: taxRates,
|
|
19
|
+
isError: false,
|
|
20
|
+
error: null,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return {
|
|
25
|
+
result: null,
|
|
26
|
+
isError: true,
|
|
27
|
+
error: formatError(error),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
async function getTimesheets() {
|
|
4
|
+
await xeroClient.authenticate();
|
|
5
|
+
// Call the Timesheets endpoint from the PayrollNZApi
|
|
6
|
+
const timesheets = await xeroClient.payrollNZApi.getTimesheets(xeroClient.tenantId, undefined, // page
|
|
7
|
+
undefined);
|
|
8
|
+
return timesheets.body.timesheets ?? [];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* List all payroll timesheets from Xero
|
|
12
|
+
*/
|
|
13
|
+
export async function listXeroPayrollTimesheets() {
|
|
14
|
+
try {
|
|
15
|
+
const timesheets = await getTimesheets();
|
|
16
|
+
return {
|
|
17
|
+
result: timesheets,
|
|
18
|
+
isError: false,
|
|
19
|
+
error: null,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return {
|
|
24
|
+
result: null,
|
|
25
|
+
isError: true,
|
|
26
|
+
error: formatError(error),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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 getTrackingCategories(includeArchived) {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const response = await xeroClient.accountingApi.getTrackingCategories(xeroClient.tenantId, // xeroTenantId
|
|
7
|
+
undefined, // where
|
|
8
|
+
undefined, // order
|
|
9
|
+
includeArchived, // includeArchived
|
|
10
|
+
getClientHeaders());
|
|
11
|
+
return response.body.trackingCategories ?? [];
|
|
12
|
+
}
|
|
13
|
+
export async function listXeroTrackingCategories(includeArchived) {
|
|
14
|
+
try {
|
|
15
|
+
const trackingCategories = await getTrackingCategories(includeArchived);
|
|
16
|
+
return {
|
|
17
|
+
result: trackingCategories,
|
|
18
|
+
isError: false,
|
|
19
|
+
error: null
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return {
|
|
24
|
+
result: null,
|
|
25
|
+
isError: true,
|
|
26
|
+
error: formatError(error)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -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,62 @@
|
|
|
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) {
|
|
14
|
+
const invoice = {
|
|
15
|
+
lineItems: lineItems,
|
|
16
|
+
reference: reference,
|
|
17
|
+
dueDate: dueDate,
|
|
18
|
+
date: date,
|
|
19
|
+
contact: contactId ? { contactID: contactId } : undefined,
|
|
20
|
+
};
|
|
21
|
+
const response = await xeroClient.accountingApi.updateInvoice(xeroClient.tenantId, invoiceId, // invoiceId
|
|
22
|
+
{
|
|
23
|
+
invoices: [invoice],
|
|
24
|
+
}, // invoices
|
|
25
|
+
undefined, // unitdp
|
|
26
|
+
undefined, // idempotencyKey
|
|
27
|
+
getClientHeaders());
|
|
28
|
+
return response.body.invoices?.[0];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Update an existing invoice in Xero
|
|
32
|
+
*/
|
|
33
|
+
export async function updateXeroInvoice(invoiceId, lineItems, reference, dueDate, date, contactId) {
|
|
34
|
+
try {
|
|
35
|
+
const existingInvoice = await getInvoice(invoiceId);
|
|
36
|
+
const invoiceStatus = existingInvoice?.status;
|
|
37
|
+
// Only allow updates to DRAFT invoices
|
|
38
|
+
if (invoiceStatus !== Invoice.StatusEnum.DRAFT) {
|
|
39
|
+
return {
|
|
40
|
+
result: null,
|
|
41
|
+
isError: true,
|
|
42
|
+
error: `Cannot update invoice because it is not a draft. Current status: ${invoiceStatus}`,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const updatedInvoice = await updateInvoice(invoiceId, lineItems, reference, dueDate, date, contactId);
|
|
46
|
+
if (!updatedInvoice) {
|
|
47
|
+
throw new Error("Invoice update failed.");
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
result: updatedInvoice,
|
|
51
|
+
isError: false,
|
|
52
|
+
error: null,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
return {
|
|
57
|
+
result: null,
|
|
58
|
+
isError: true,
|
|
59
|
+
error: formatError(error),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -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
|
+
}
|