@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,59 @@
|
|
|
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
|
+
function buildWhereClause(type, dateFrom, dateTo) {
|
|
5
|
+
const clauses = [];
|
|
6
|
+
if (type) {
|
|
7
|
+
clauses.push(`Type=="${type}"`);
|
|
8
|
+
}
|
|
9
|
+
if (dateFrom) {
|
|
10
|
+
const [year, month, day] = dateFrom.split("-").map(Number);
|
|
11
|
+
clauses.push(`Date>=DateTime(${year},${month},${day})`);
|
|
12
|
+
}
|
|
13
|
+
if (dateTo) {
|
|
14
|
+
const [year, month, day] = dateTo.split("-").map(Number);
|
|
15
|
+
clauses.push(`Date<=DateTime(${year},${month},${day})`);
|
|
16
|
+
}
|
|
17
|
+
return clauses.length > 0 ? clauses.join("&&") : undefined;
|
|
18
|
+
}
|
|
19
|
+
async function getInvoices(invoiceNumbers, contactIds, page, orderBy, orderDirection, status, type, dateFrom, dateTo, pageSize) {
|
|
20
|
+
await xeroClient.authenticate();
|
|
21
|
+
const where = buildWhereClause(type, dateFrom, dateTo);
|
|
22
|
+
const order = `${orderBy ?? "UpdatedDateUTC"} ${orderDirection ?? "DESC"}`;
|
|
23
|
+
const statuses = status ? [status] : undefined;
|
|
24
|
+
const invoices = await xeroClient.accountingApi.getInvoices(xeroClient.tenantId, undefined, // ifModifiedSince
|
|
25
|
+
where, // where
|
|
26
|
+
order, // order
|
|
27
|
+
undefined, // iDs
|
|
28
|
+
invoiceNumbers, // invoiceNumbers
|
|
29
|
+
contactIds, // contactIDs
|
|
30
|
+
statuses, // statuses
|
|
31
|
+
page, false, // includeArchived
|
|
32
|
+
false, // createdByMyApp
|
|
33
|
+
undefined, // unitdp
|
|
34
|
+
false, // summaryOnly
|
|
35
|
+
pageSize ?? 100, // pageSize
|
|
36
|
+
undefined, // searchTerm
|
|
37
|
+
getClientHeaders());
|
|
38
|
+
return invoices.body.invoices ?? [];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* List all invoices from Xero
|
|
42
|
+
*/
|
|
43
|
+
export async function listXeroInvoices(page = 1, contactIds, invoiceNumbers, orderBy, orderDirection, status, type, dateFrom, dateTo, pageSize) {
|
|
44
|
+
try {
|
|
45
|
+
const invoices = await getInvoices(invoiceNumbers, contactIds, page, orderBy, orderDirection, status, type, dateFrom, dateTo, pageSize);
|
|
46
|
+
return {
|
|
47
|
+
result: invoices,
|
|
48
|
+
isError: false,
|
|
49
|
+
error: null,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
return {
|
|
54
|
+
result: null,
|
|
55
|
+
isError: true,
|
|
56
|
+
error: formatError(error),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -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
|
+
async function getManualJournals(page, manualJournalId, modifiedAfter) {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
if (manualJournalId) {
|
|
7
|
+
const response = await xeroClient.accountingApi.getManualJournal(xeroClient.tenantId, manualJournalId, getClientHeaders());
|
|
8
|
+
return response.body.manualJournals ?? [];
|
|
9
|
+
}
|
|
10
|
+
const response = await xeroClient.accountingApi.getManualJournals(xeroClient.tenantId, modifiedAfter ? new Date(modifiedAfter) : undefined, undefined, "UpdatedDateUTC DESC", page, 10, // pageSize
|
|
11
|
+
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) {
|
|
18
|
+
try {
|
|
19
|
+
const manualJournals = await getManualJournals(page, manualJournalId, modifiedAfter);
|
|
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,53 @@
|
|
|
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 getPayments(page = 1, { invoiceNumber, invoiceId, paymentId, reference, }) {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
// Build where clause for filtering
|
|
7
|
+
const whereConditions = [];
|
|
8
|
+
if (invoiceId) {
|
|
9
|
+
whereConditions.push(`Invoice.InvoiceID==guid("${invoiceId}")`);
|
|
10
|
+
}
|
|
11
|
+
if (invoiceNumber) {
|
|
12
|
+
whereConditions.push(`Invoice.InvoiceNumber=="${invoiceNumber}"`);
|
|
13
|
+
}
|
|
14
|
+
if (paymentId) {
|
|
15
|
+
whereConditions.push(`PaymentID==guid("${paymentId}")`);
|
|
16
|
+
}
|
|
17
|
+
if (reference) {
|
|
18
|
+
whereConditions.push(`Reference=="${reference}"`);
|
|
19
|
+
}
|
|
20
|
+
// Combine conditions
|
|
21
|
+
const where = whereConditions.length > 0 ? whereConditions.join(" AND ") : undefined;
|
|
22
|
+
const response = await xeroClient.accountingApi.getPayments(xeroClient.tenantId, undefined, // ifModifiedSince
|
|
23
|
+
where, "UpdatedDateUTC DESC", // order
|
|
24
|
+
page, // page
|
|
25
|
+
10, // pageSize
|
|
26
|
+
getClientHeaders());
|
|
27
|
+
return response.body.payments ?? [];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* List payments from Xero
|
|
31
|
+
*/
|
|
32
|
+
export async function listXeroPayments(page = 1, { invoiceNumber, invoiceId, paymentId, reference, }) {
|
|
33
|
+
try {
|
|
34
|
+
const payments = await getPayments(page, {
|
|
35
|
+
invoiceNumber,
|
|
36
|
+
invoiceId,
|
|
37
|
+
paymentId,
|
|
38
|
+
reference,
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
result: payments,
|
|
42
|
+
isError: false,
|
|
43
|
+
error: null,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return {
|
|
48
|
+
result: null,
|
|
49
|
+
isError: true,
|
|
50
|
+
error: formatError(error),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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,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 getQuotes(contactId, page, quoteNumber) {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const quotes = await xeroClient.accountingApi.getQuotes(xeroClient.tenantId, undefined, // ifModifiedSince
|
|
7
|
+
undefined, // dateFrom
|
|
8
|
+
undefined, // dateTo
|
|
9
|
+
undefined, // expiryDateFrom
|
|
10
|
+
undefined, // expiryDateTo
|
|
11
|
+
contactId, // contactID
|
|
12
|
+
undefined, // status
|
|
13
|
+
page, undefined, // order
|
|
14
|
+
quoteNumber, // quoteNumber
|
|
15
|
+
getClientHeaders());
|
|
16
|
+
return quotes.body.quotes ?? [];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* List all quotes from Xero
|
|
20
|
+
*/
|
|
21
|
+
export async function listXeroQuotes(page = 1, contactId, quoteNumber) {
|
|
22
|
+
try {
|
|
23
|
+
const quotes = await getQuotes(contactId, page, quoteNumber);
|
|
24
|
+
return {
|
|
25
|
+
result: quotes,
|
|
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,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
|
+
}
|