@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,37 @@
|
|
|
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 listAgedReceivablesByContact(contactId, reportDate, invoicesFromDate, invoicesToDate) {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const response = await xeroClient.accountingApi.getReportAgedReceivablesByContact(xeroClient.tenantId, // xeroTenantId
|
|
7
|
+
contactId, // contactId
|
|
8
|
+
reportDate, // date
|
|
9
|
+
invoicesFromDate, // fromDate
|
|
10
|
+
invoicesToDate, // toDate
|
|
11
|
+
getClientHeaders());
|
|
12
|
+
return response.body.reports?.[0];
|
|
13
|
+
}
|
|
14
|
+
export async function listXeroAgedReceivablesByContact(contactId, reportDate, invoicesFromDate, invoicesToDate) {
|
|
15
|
+
try {
|
|
16
|
+
const agedReceivables = await listAgedReceivablesByContact(contactId, reportDate, invoicesFromDate, invoicesToDate);
|
|
17
|
+
if (!agedReceivables) {
|
|
18
|
+
return {
|
|
19
|
+
result: null,
|
|
20
|
+
isError: true,
|
|
21
|
+
error: "Failed to get aged receivables by contact from Xero."
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
result: agedReceivables,
|
|
26
|
+
isError: false,
|
|
27
|
+
error: null
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
return {
|
|
32
|
+
result: null,
|
|
33
|
+
isError: true,
|
|
34
|
+
error: formatError(error),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 listAccounts() {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const response = await xeroClient.accountingApi.getAccounts(xeroClient.tenantId, undefined, // ifModifiedSince
|
|
7
|
+
undefined, // where
|
|
8
|
+
undefined, // order
|
|
9
|
+
getClientHeaders());
|
|
10
|
+
const accounts = response.body.accounts ?? [];
|
|
11
|
+
return accounts;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* List all accounts from Xero
|
|
15
|
+
*/
|
|
16
|
+
export async function listXeroAccounts() {
|
|
17
|
+
try {
|
|
18
|
+
const accounts = await listAccounts();
|
|
19
|
+
return {
|
|
20
|
+
result: accounts,
|
|
21
|
+
isError: false,
|
|
22
|
+
error: null,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return {
|
|
27
|
+
result: null,
|
|
28
|
+
isError: true,
|
|
29
|
+
error: formatError(error),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
import { dateWhereConditions, statusWhereConditions, joinWhere } from "../helpers/build-where-clause.js";
|
|
5
|
+
async function getBankTransactions(page, bankAccountId, fromDate, toDate, status, pageSize = 50, isReconciled, transactionType) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
// Default to AUTHORISED — exclude DELETED and VOIDED unless explicitly requested
|
|
8
|
+
const effectiveStatus = status ?? "AUTHORISED";
|
|
9
|
+
const whereParts = [
|
|
10
|
+
...(bankAccountId ? [`BankAccount.AccountID=guid("${bankAccountId}")`] : []),
|
|
11
|
+
...dateWhereConditions("Date", fromDate, toDate),
|
|
12
|
+
...statusWhereConditions("Status", [effectiveStatus]),
|
|
13
|
+
...(isReconciled !== undefined ? [`IsReconciled==${isReconciled}`] : []),
|
|
14
|
+
...(transactionType ? [`Type=="${transactionType}"`] : []),
|
|
15
|
+
];
|
|
16
|
+
const where = joinWhere(whereParts);
|
|
17
|
+
const response = await xeroClient.accountingApi.getBankTransactions(xeroClient.tenantId, undefined, // ifModifiedSince
|
|
18
|
+
where, "Date DESC", // order
|
|
19
|
+
page, undefined, // unitdp
|
|
20
|
+
pageSize, getClientHeaders());
|
|
21
|
+
return response.body.bankTransactions ?? [];
|
|
22
|
+
}
|
|
23
|
+
export async function listXeroBankTransactions(page = 1, bankAccountId, fromDate, toDate, status, pageSize = 50, isReconciled, transactionType) {
|
|
24
|
+
try {
|
|
25
|
+
const bankTransactions = await getBankTransactions(page, bankAccountId, fromDate, toDate, status, pageSize, isReconciled, transactionType);
|
|
26
|
+
return {
|
|
27
|
+
result: bankTransactions,
|
|
28
|
+
isError: false,
|
|
29
|
+
error: null,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
return {
|
|
34
|
+
result: null,
|
|
35
|
+
isError: true,
|
|
36
|
+
error: formatError(error),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -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 getContactGroups(contactGroupId) {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
if (contactGroupId) {
|
|
7
|
+
const response = await xeroClient.accountingApi.getContactGroup(xeroClient.tenantId, contactGroupId, getClientHeaders());
|
|
8
|
+
return response.body.contactGroups ?? [];
|
|
9
|
+
}
|
|
10
|
+
const response = await xeroClient.accountingApi.getContactGroups(xeroClient.tenantId, undefined, // where
|
|
11
|
+
undefined, // order
|
|
12
|
+
getClientHeaders());
|
|
13
|
+
return response.body.contactGroups ?? [];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* List all contact groups from Xero. If a contactGroupId is provided, it will return only that contact group.
|
|
17
|
+
*/
|
|
18
|
+
export async function listXeroContactGroups(contactGroupId) {
|
|
19
|
+
try {
|
|
20
|
+
const contactGroups = await getContactGroups(contactGroupId);
|
|
21
|
+
return {
|
|
22
|
+
result: contactGroups,
|
|
23
|
+
isError: false,
|
|
24
|
+
error: null,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
return {
|
|
29
|
+
result: null,
|
|
30
|
+
isError: true,
|
|
31
|
+
error: formatError(error),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 { dateWhereConditions, statusWhereConditions, joinWhere } from "../helpers/build-where-clause.js";
|
|
5
|
+
async function getContacts(page, searchTerm, fromDate, toDate, status, pageSize = 50, contactRole) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
// Default to ACTIVE — exclude ARCHIVED contacts unless explicitly requested
|
|
8
|
+
const effectiveStatus = status ?? "ACTIVE";
|
|
9
|
+
const whereParts = [
|
|
10
|
+
...dateWhereConditions("UpdatedDateUTC", fromDate, toDate),
|
|
11
|
+
...statusWhereConditions("ContactStatus", [effectiveStatus]),
|
|
12
|
+
...(contactRole === "customer" ? ["IsCustomer==true"] : []),
|
|
13
|
+
...(contactRole === "supplier" ? ["IsSupplier==true"] : []),
|
|
14
|
+
];
|
|
15
|
+
const where = joinWhere(whereParts);
|
|
16
|
+
const contacts = await xeroClient.accountingApi.getContacts(xeroClient.tenantId, undefined, // ifModifiedSince
|
|
17
|
+
where, // where
|
|
18
|
+
undefined, // order
|
|
19
|
+
undefined, // iDs
|
|
20
|
+
page, // page
|
|
21
|
+
undefined, // includeArchived
|
|
22
|
+
true, // summaryOnly
|
|
23
|
+
searchTerm, // searchTerm
|
|
24
|
+
pageSize, // pageSize
|
|
25
|
+
getClientHeaders());
|
|
26
|
+
return contacts.body.contacts ?? [];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* List contacts from Xero
|
|
30
|
+
*/
|
|
31
|
+
export async function listXeroContacts(page, searchTerm, fromDate, toDate, status, pageSize = 50, contactRole) {
|
|
32
|
+
try {
|
|
33
|
+
const contacts = await getContacts(page, searchTerm, fromDate, toDate, status, pageSize, contactRole);
|
|
34
|
+
return {
|
|
35
|
+
result: contacts,
|
|
36
|
+
isError: false,
|
|
37
|
+
error: null,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return {
|
|
42
|
+
result: null,
|
|
43
|
+
isError: true,
|
|
44
|
+
error: formatError(error),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -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
|
+
import { dateWhereConditions, statusWhereConditions, joinWhere } from "../helpers/build-where-clause.js";
|
|
5
|
+
async function getCreditNotes(contactId, page, fromDate, toDate, statuses, pageSize = 50, type, hasRemainingCredit) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
// Default to active statuses — exclude DELETED and VOIDED unless explicitly requested
|
|
8
|
+
const effectiveStatuses = statuses?.length ? statuses : ["DRAFT", "SUBMITTED", "AUTHORISED", "PAID"];
|
|
9
|
+
const whereParts = [
|
|
10
|
+
...(contactId ? [`Contact.ContactID=guid("${contactId}")`] : []),
|
|
11
|
+
...dateWhereConditions("Date", fromDate, toDate),
|
|
12
|
+
...statusWhereConditions("Status", effectiveStatuses),
|
|
13
|
+
...(type ? [`Type=="${type}"`] : []),
|
|
14
|
+
...(hasRemainingCredit ? ["RemainingCredit>0"] : []),
|
|
15
|
+
];
|
|
16
|
+
const where = joinWhere(whereParts);
|
|
17
|
+
const response = await xeroClient.accountingApi.getCreditNotes(xeroClient.tenantId, undefined, // ifModifiedSince
|
|
18
|
+
where, "UpdatedDateUTC DESC", // order
|
|
19
|
+
page, undefined, // unitdp
|
|
20
|
+
pageSize, getClientHeaders());
|
|
21
|
+
return response.body.creditNotes ?? [];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* List credit notes from Xero
|
|
25
|
+
*/
|
|
26
|
+
export async function listXeroCreditNotes(page = 1, contactId, fromDate, toDate, statuses, pageSize = 50, type, hasRemainingCredit) {
|
|
27
|
+
try {
|
|
28
|
+
const creditNotes = await getCreditNotes(contactId, page, fromDate, toDate, statuses, pageSize, type, hasRemainingCredit);
|
|
29
|
+
return {
|
|
30
|
+
result: creditNotes,
|
|
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,20 @@
|
|
|
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
|
+
* List all attachments on an invoice.
|
|
6
|
+
*/
|
|
7
|
+
export async function listXeroInvoiceAttachments(invoiceId) {
|
|
8
|
+
try {
|
|
9
|
+
await xeroClient.authenticate();
|
|
10
|
+
const response = await xeroClient.accountingApi.getInvoiceAttachments(xeroClient.tenantId, invoiceId, getClientHeaders());
|
|
11
|
+
return {
|
|
12
|
+
result: response.body.attachments ?? [],
|
|
13
|
+
isError: false,
|
|
14
|
+
error: null,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
return { result: null, isError: true, error: formatError(error) };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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 { dateWhereConditions, joinWhere } from "../helpers/build-where-clause.js";
|
|
5
|
+
import { todayComponents } from "../helpers/datetime.js";
|
|
6
|
+
async function getInvoices(invoiceNumbers, contactIds, page, statuses, fromDate, toDate, pageSize = 100, type, minAmountDue, overdueOnly) {
|
|
7
|
+
await xeroClient.authenticate();
|
|
8
|
+
const whereParts = [
|
|
9
|
+
...dateWhereConditions("Date", fromDate, toDate),
|
|
10
|
+
...(type ? [`Type=="${type}"`] : []),
|
|
11
|
+
...(minAmountDue !== undefined ? [`AmountDue>${minAmountDue}`] : []),
|
|
12
|
+
...(overdueOnly ? (() => {
|
|
13
|
+
const { year, month, day } = todayComponents();
|
|
14
|
+
return [`AmountDue>0`, `DueDate<=DateTime(${year},${month},${day})`];
|
|
15
|
+
})() : []),
|
|
16
|
+
];
|
|
17
|
+
const where = joinWhere(whereParts);
|
|
18
|
+
// Default to active statuses — exclude DELETED and VOIDED unless explicitly requested
|
|
19
|
+
const effectiveStatuses = statuses ?? ["DRAFT", "SUBMITTED", "AUTHORISED", "PAID"];
|
|
20
|
+
const invoices = await xeroClient.accountingApi.getInvoices(xeroClient.tenantId, undefined, // ifModifiedSince
|
|
21
|
+
where, // where
|
|
22
|
+
"UpdatedDateUTC DESC", // order
|
|
23
|
+
undefined, // iDs
|
|
24
|
+
invoiceNumbers, // invoiceNumbers
|
|
25
|
+
contactIds, // contactIDs
|
|
26
|
+
effectiveStatuses, // statuses
|
|
27
|
+
page, false, // includeArchived
|
|
28
|
+
false, // createdByMyApp
|
|
29
|
+
undefined, // unitdp
|
|
30
|
+
false, // summaryOnly
|
|
31
|
+
pageSize, undefined, // searchTerm
|
|
32
|
+
getClientHeaders());
|
|
33
|
+
return invoices.body.invoices ?? [];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* List all invoices from Xero
|
|
37
|
+
*/
|
|
38
|
+
export async function listXeroInvoices(page = 1, contactIds, invoiceNumbers, statuses, fromDate, toDate, pageSize = 100, type, minAmountDue, overdueOnly) {
|
|
39
|
+
try {
|
|
40
|
+
const invoices = await getInvoices(invoiceNumbers, contactIds, page, statuses, fromDate, toDate, pageSize, type, minAmountDue, overdueOnly);
|
|
41
|
+
return {
|
|
42
|
+
result: invoices,
|
|
43
|
+
isError: false,
|
|
44
|
+
error: null,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
return {
|
|
49
|
+
result: null,
|
|
50
|
+
isError: true,
|
|
51
|
+
error: formatError(error),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 getItems(page) {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const items = await xeroClient.accountingApi.getItems(xeroClient.tenantId, undefined, // ifModifiedSince
|
|
7
|
+
undefined, // where
|
|
8
|
+
undefined, // order
|
|
9
|
+
page, // page
|
|
10
|
+
getClientHeaders());
|
|
11
|
+
return items.body.items ?? [];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* List all items from Xero
|
|
15
|
+
*/
|
|
16
|
+
export async function listXeroItems(page = 1) {
|
|
17
|
+
try {
|
|
18
|
+
const items = await getItems(page);
|
|
19
|
+
return {
|
|
20
|
+
result: items,
|
|
21
|
+
isError: false,
|
|
22
|
+
error: null,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return {
|
|
27
|
+
result: null,
|
|
28
|
+
isError: true,
|
|
29
|
+
error: formatError(error),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 { parseLocalDate } from "../helpers/datetime.js";
|
|
5
|
+
async function getManualJournals(page, manualJournalId, modifiedAfter, pageSize = 50) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
if (manualJournalId) {
|
|
8
|
+
const response = await xeroClient.accountingApi.getManualJournal(xeroClient.tenantId, manualJournalId, getClientHeaders());
|
|
9
|
+
return response.body.manualJournals ?? [];
|
|
10
|
+
}
|
|
11
|
+
const response = await xeroClient.accountingApi.getManualJournals(xeroClient.tenantId, modifiedAfter ? parseLocalDate(modifiedAfter) : undefined, undefined, "UpdatedDateUTC DESC", page, pageSize, getClientHeaders());
|
|
12
|
+
return response.body.manualJournals ?? [];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* List all manual journals from Xero.
|
|
16
|
+
*/
|
|
17
|
+
export async function listXeroManualJournals(page = 1, manualJournalId, modifiedAfter, pageSize = 50) {
|
|
18
|
+
try {
|
|
19
|
+
const manualJournals = await getManualJournals(page, manualJournalId, modifiedAfter, pageSize);
|
|
20
|
+
return {
|
|
21
|
+
result: manualJournals,
|
|
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
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 getOrganisationDetails() {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const response = await xeroClient.accountingApi.getOrganisations(xeroClient.tenantId, getClientHeaders());
|
|
7
|
+
const organisation = response.body.organisations?.[0];
|
|
8
|
+
if (!organisation) {
|
|
9
|
+
throw new Error("Failed to retrieve organisation details");
|
|
10
|
+
}
|
|
11
|
+
return organisation;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* List organisation details from Xero
|
|
15
|
+
*/
|
|
16
|
+
export async function listXeroOrganisationDetails() {
|
|
17
|
+
try {
|
|
18
|
+
const organisation = await getOrganisationDetails();
|
|
19
|
+
return {
|
|
20
|
+
result: organisation,
|
|
21
|
+
isError: false,
|
|
22
|
+
error: null,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return {
|
|
27
|
+
result: null,
|
|
28
|
+
isError: true,
|
|
29
|
+
error: formatError(error),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -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
|
+
import { dateWhereConditions, joinWhere } from "../helpers/build-where-clause.js";
|
|
5
|
+
async function getPayments(page = 1, { invoiceNumber, invoiceId, paymentId, reference, fromDate, toDate, pageSize = 50, contactId, }) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
const whereConditions = [];
|
|
8
|
+
if (invoiceId)
|
|
9
|
+
whereConditions.push(`Invoice.InvoiceID==guid("${invoiceId}")`);
|
|
10
|
+
if (invoiceNumber)
|
|
11
|
+
whereConditions.push(`Invoice.InvoiceNumber=="${invoiceNumber}"`);
|
|
12
|
+
if (paymentId)
|
|
13
|
+
whereConditions.push(`PaymentID==guid("${paymentId}")`);
|
|
14
|
+
if (reference)
|
|
15
|
+
whereConditions.push(`Reference=="${reference}"`);
|
|
16
|
+
if (contactId)
|
|
17
|
+
whereConditions.push(`Invoice.Contact.ContactID==guid("${contactId}")`);
|
|
18
|
+
whereConditions.push(...dateWhereConditions("Date", fromDate, toDate));
|
|
19
|
+
const where = joinWhere(whereConditions);
|
|
20
|
+
const response = await xeroClient.accountingApi.getPayments(xeroClient.tenantId, undefined, // ifModifiedSince
|
|
21
|
+
where, "UpdatedDateUTC DESC", page, pageSize, getClientHeaders());
|
|
22
|
+
return response.body.payments ?? [];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* List payments from Xero
|
|
26
|
+
*/
|
|
27
|
+
export async function listXeroPayments(page = 1, { invoiceNumber, invoiceId, paymentId, reference, fromDate, toDate, pageSize = 50, contactId, }) {
|
|
28
|
+
try {
|
|
29
|
+
const payments = await getPayments(page, {
|
|
30
|
+
invoiceNumber,
|
|
31
|
+
invoiceId,
|
|
32
|
+
paymentId,
|
|
33
|
+
reference,
|
|
34
|
+
fromDate,
|
|
35
|
+
toDate,
|
|
36
|
+
pageSize,
|
|
37
|
+
contactId,
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
result: payments,
|
|
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,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 employee leave balances from Xero
|
|
6
|
+
*/
|
|
7
|
+
async function fetchEmployeeLeaveBalances(employeeId) {
|
|
8
|
+
await xeroClient.authenticate();
|
|
9
|
+
if (!employeeId) {
|
|
10
|
+
throw new Error("Employee ID is required to fetch employee leave balances");
|
|
11
|
+
}
|
|
12
|
+
const response = await xeroClient.payrollNZApi.getEmployeeLeaveBalances(xeroClient.tenantId, employeeId, getClientHeaders());
|
|
13
|
+
return response.body.leaveBalances ?? null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* List employee leave balances from Xero Payroll
|
|
17
|
+
* @param employeeId The ID of the employee to retrieve leave balances for
|
|
18
|
+
*/
|
|
19
|
+
export async function listXeroPayrollEmployeeLeaveBalances(employeeId) {
|
|
20
|
+
try {
|
|
21
|
+
const leaveBalances = await fetchEmployeeLeaveBalances(employeeId);
|
|
22
|
+
if (!leaveBalances) {
|
|
23
|
+
return {
|
|
24
|
+
result: [],
|
|
25
|
+
isError: false,
|
|
26
|
+
error: null,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
result: leaveBalances,
|
|
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,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 employee leave types from Xero
|
|
6
|
+
*/
|
|
7
|
+
async function fetchEmployeeLeaveTypes(employeeId) {
|
|
8
|
+
await xeroClient.authenticate();
|
|
9
|
+
if (!employeeId) {
|
|
10
|
+
throw new Error("Employee ID is required to fetch employee leave types");
|
|
11
|
+
}
|
|
12
|
+
const response = await xeroClient.payrollNZApi.getEmployeeLeaveTypes(xeroClient.tenantId, employeeId, getClientHeaders());
|
|
13
|
+
return response.body.leaveTypes ?? null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* List employee leave types from Xero Payroll
|
|
17
|
+
* @param employeeId The ID of the employee to retrieve leave types for
|
|
18
|
+
*/
|
|
19
|
+
export async function listXeroPayrollEmployeeLeaveTypes(employeeId) {
|
|
20
|
+
try {
|
|
21
|
+
const leaveTypes = await fetchEmployeeLeaveTypes(employeeId);
|
|
22
|
+
if (!leaveTypes) {
|
|
23
|
+
return {
|
|
24
|
+
result: [],
|
|
25
|
+
isError: false,
|
|
26
|
+
error: null,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
result: leaveTypes,
|
|
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,44 @@
|
|
|
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 employee leave from Xero
|
|
6
|
+
*/
|
|
7
|
+
async function fetchEmployeeLeave({ employeeId }) {
|
|
8
|
+
await xeroClient.authenticate();
|
|
9
|
+
if (!employeeId) {
|
|
10
|
+
throw new Error("Employee ID is required to fetch employee leave");
|
|
11
|
+
}
|
|
12
|
+
const response = await xeroClient.payrollNZApi.getEmployeeLeaves(xeroClient.tenantId, employeeId, {
|
|
13
|
+
headers: getClientHeaders().headers
|
|
14
|
+
});
|
|
15
|
+
return response.body.leave ?? null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* List employee leave from Xero Payroll
|
|
19
|
+
* @param employeeId The ID of the employee to retrieve leave for
|
|
20
|
+
*/
|
|
21
|
+
export async function listXeroPayrollEmployeeLeave(employeeId) {
|
|
22
|
+
try {
|
|
23
|
+
const leave = await fetchEmployeeLeave({ employeeId });
|
|
24
|
+
if (!leave) {
|
|
25
|
+
return {
|
|
26
|
+
result: [],
|
|
27
|
+
isError: false,
|
|
28
|
+
error: null,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
result: leave,
|
|
33
|
+
isError: false,
|
|
34
|
+
error: null,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return {
|
|
39
|
+
result: null,
|
|
40
|
+
isError: true,
|
|
41
|
+
error: formatError(error),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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 getPayrollEmployees() {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
// Call the Employees endpoint from the PayrollNZApi
|
|
7
|
+
const employees = await xeroClient.payrollNZApi.getEmployees(xeroClient.tenantId, undefined, // page
|
|
8
|
+
undefined, // pageSize
|
|
9
|
+
getClientHeaders());
|
|
10
|
+
return employees.body.employees ?? [];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* List all payroll employees from Xero
|
|
14
|
+
*/
|
|
15
|
+
export async function listXeroPayrollEmployees() {
|
|
16
|
+
try {
|
|
17
|
+
const employees = await getPayrollEmployees();
|
|
18
|
+
return {
|
|
19
|
+
result: employees,
|
|
20
|
+
isError: false,
|
|
21
|
+
error: null,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
return {
|
|
26
|
+
result: null,
|
|
27
|
+
isError: true,
|
|
28
|
+
error: formatError(error),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
/**
|
|
4
|
+
* Internal function to fetch employee leave periods from Xero
|
|
5
|
+
*/
|
|
6
|
+
async function fetchLeavePeriods({ employeeId, startDate, endDate, }) {
|
|
7
|
+
await xeroClient.authenticate();
|
|
8
|
+
if (!employeeId) {
|
|
9
|
+
throw new Error("Employee ID is required to fetch leave periods");
|
|
10
|
+
} // After reviewing the SDK documentation, it appears this API call requires different parameters
|
|
11
|
+
// Use parameters that match the SDK's expectations
|
|
12
|
+
const response = await xeroClient.payrollNZApi.getEmployeeLeavePeriods(xeroClient.tenantId, employeeId, startDate, endDate);
|
|
13
|
+
return response.body.periods ?? null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* List employee leave periods from Xero Payroll
|
|
17
|
+
* @param employeeId The ID of the employee to retrieve leave periods for
|
|
18
|
+
* @param startDate Optional start date in YYYY-MM-DD format
|
|
19
|
+
* @param endDate Optional end date in YYYY-MM-DD format
|
|
20
|
+
*/
|
|
21
|
+
export async function listXeroPayrollLeavePeriods(employeeId, startDate, endDate) {
|
|
22
|
+
try {
|
|
23
|
+
const periods = await fetchLeavePeriods({ employeeId, startDate, endDate });
|
|
24
|
+
if (!periods) {
|
|
25
|
+
return {
|
|
26
|
+
result: [],
|
|
27
|
+
isError: false,
|
|
28
|
+
error: null,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
result: periods,
|
|
33
|
+
isError: false,
|
|
34
|
+
error: null,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return {
|
|
39
|
+
result: null,
|
|
40
|
+
isError: true,
|
|
41
|
+
error: formatError(error),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|