@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,57 @@
|
|
|
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 createManualJournal(narration, 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,
|
|
12
|
+
taxType: journalLine.taxType,
|
|
13
|
+
// TODO: tracking can be added here
|
|
14
|
+
})),
|
|
15
|
+
date: date,
|
|
16
|
+
lineAmountTypes: lineAmountTypes,
|
|
17
|
+
status: status,
|
|
18
|
+
url: url,
|
|
19
|
+
showOnCashBasisReports: showOnCashBasisReports,
|
|
20
|
+
};
|
|
21
|
+
const manualJournals = {
|
|
22
|
+
manualJournals: [manualJournal],
|
|
23
|
+
};
|
|
24
|
+
const response = await xeroClient.accountingApi.createManualJournals(xeroClient.tenantId, manualJournals, true, undefined, getClientHeaders());
|
|
25
|
+
return response.body.manualJournals?.[0];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a manual journal in Xero.
|
|
29
|
+
* @param narration - Required: Description of manual journal being posted.
|
|
30
|
+
* @param manualJournalLines - Required: Array of `ManualJournalLine` objects.
|
|
31
|
+
* @param date - Optional: YYYY-MM-DD format.
|
|
32
|
+
* @param lineAmountTypes - Optional: No Tax by default, see `ManualJournal.LineAmountTypesEnum`.
|
|
33
|
+
* @param status - Optional: draft by default, see `ManualJournal.StatusEnum`.
|
|
34
|
+
* @param url - Optional: URL link to a source document.
|
|
35
|
+
* @param showOnCashBasisReports - Optional: default is true if not specified.
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
export async function createXeroManualJournal(narration, manualJournalLines, date, lineAmountTypes, status, url, showOnCashBasisReports) {
|
|
39
|
+
try {
|
|
40
|
+
const createdManualJournal = await createManualJournal(narration, manualJournalLines, date, lineAmountTypes, status, url, showOnCashBasisReports);
|
|
41
|
+
if (!createdManualJournal) {
|
|
42
|
+
throw new Error("Manual journal creation failed.");
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
result: createdManualJournal,
|
|
46
|
+
isError: false,
|
|
47
|
+
error: null,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
return {
|
|
52
|
+
result: null,
|
|
53
|
+
isError: true,
|
|
54
|
+
error: formatError(error),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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 createPayment({ invoiceId, accountId, amount, date, reference, }) {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const payment = {
|
|
7
|
+
invoice: {
|
|
8
|
+
invoiceID: invoiceId,
|
|
9
|
+
},
|
|
10
|
+
account: {
|
|
11
|
+
accountID: accountId,
|
|
12
|
+
},
|
|
13
|
+
amount: amount,
|
|
14
|
+
date: date || new Date().toISOString().split("T")[0], // Today's date if not specified
|
|
15
|
+
reference: reference,
|
|
16
|
+
};
|
|
17
|
+
const response = await xeroClient.accountingApi.createPayment(xeroClient.tenantId, payment, undefined, // idempotencyKey
|
|
18
|
+
getClientHeaders());
|
|
19
|
+
return response.body.payments?.[0];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create a new payment in Xero
|
|
23
|
+
*/
|
|
24
|
+
export async function createXeroPayment({ invoiceId, accountId, amount, date, reference, }) {
|
|
25
|
+
try {
|
|
26
|
+
const createdPayment = await createPayment({
|
|
27
|
+
invoiceId,
|
|
28
|
+
accountId,
|
|
29
|
+
amount,
|
|
30
|
+
date,
|
|
31
|
+
reference,
|
|
32
|
+
});
|
|
33
|
+
if (!createdPayment) {
|
|
34
|
+
throw new Error("Payment creation failed.");
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
result: createdPayment,
|
|
38
|
+
isError: false,
|
|
39
|
+
error: null,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return {
|
|
44
|
+
result: null,
|
|
45
|
+
isError: true,
|
|
46
|
+
error: formatError(error),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
async function createTimesheet(timesheet) {
|
|
4
|
+
await xeroClient.authenticate();
|
|
5
|
+
// Call the createTimesheet endpoint from the PayrollNZApi
|
|
6
|
+
const createdTimesheet = await xeroClient.payrollNZApi.createTimesheet(xeroClient.tenantId, timesheet);
|
|
7
|
+
return createdTimesheet.body.timesheet ?? null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create a payroll timesheet in Xero
|
|
11
|
+
*/
|
|
12
|
+
export async function createXeroPayrollTimesheet(timesheet) {
|
|
13
|
+
try {
|
|
14
|
+
const newTimesheet = await createTimesheet(timesheet);
|
|
15
|
+
return {
|
|
16
|
+
result: newTimesheet,
|
|
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,54 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
import { QuoteStatusCodes } from "xero-node";
|
|
4
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
5
|
+
async function createQuote(quoteNumber, reference, terms, contactId, lineItems, title, summary) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
const quote = {
|
|
8
|
+
quoteNumber: quoteNumber,
|
|
9
|
+
reference: reference,
|
|
10
|
+
terms: terms,
|
|
11
|
+
contact: {
|
|
12
|
+
contactID: contactId,
|
|
13
|
+
},
|
|
14
|
+
date: new Date().toISOString().split("T")[0], // Today's date
|
|
15
|
+
lineItems: lineItems,
|
|
16
|
+
expiryDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000)
|
|
17
|
+
.toISOString()
|
|
18
|
+
.split("T")[0], // 7 days from now
|
|
19
|
+
status: QuoteStatusCodes.DRAFT,
|
|
20
|
+
title: title,
|
|
21
|
+
summary: summary,
|
|
22
|
+
};
|
|
23
|
+
const response = await xeroClient.accountingApi.createQuotes(xeroClient.tenantId, {
|
|
24
|
+
quotes: [quote],
|
|
25
|
+
}, // quotes
|
|
26
|
+
true, //summarizeErrors
|
|
27
|
+
undefined, //idempotencyKey
|
|
28
|
+
getClientHeaders());
|
|
29
|
+
const createdQuote = response.body.quotes?.[0];
|
|
30
|
+
return createdQuote;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a new quote in Xero
|
|
34
|
+
*/
|
|
35
|
+
export async function createXeroQuote(contactId, lineItems, reference, quoteNumber, terms, title, summary) {
|
|
36
|
+
try {
|
|
37
|
+
const createdQuote = await createQuote(quoteNumber, reference, terms, contactId, lineItems, title, summary);
|
|
38
|
+
if (!createdQuote) {
|
|
39
|
+
throw new Error("Quote creation failed.");
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
result: createdQuote,
|
|
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,35 @@
|
|
|
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 createTrackingCategory(name) {
|
|
5
|
+
xeroClient.authenticate();
|
|
6
|
+
const trackingCategory = {
|
|
7
|
+
name: name
|
|
8
|
+
};
|
|
9
|
+
const response = await xeroClient.accountingApi.createTrackingCategory(xeroClient.tenantId, // xeroTenantId
|
|
10
|
+
trackingCategory, undefined, // idempotencyKey
|
|
11
|
+
getClientHeaders() // options
|
|
12
|
+
);
|
|
13
|
+
const createdTrackingCategory = response.body.trackingCategories?.[0];
|
|
14
|
+
return createdTrackingCategory;
|
|
15
|
+
}
|
|
16
|
+
export async function createXeroTrackingCategory(name) {
|
|
17
|
+
try {
|
|
18
|
+
const createdTrackingCategory = await createTrackingCategory(name);
|
|
19
|
+
if (!createdTrackingCategory) {
|
|
20
|
+
throw new Error("Tracking Category creation failed.");
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
result: createdTrackingCategory,
|
|
24
|
+
isError: false,
|
|
25
|
+
error: null
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return {
|
|
30
|
+
result: null,
|
|
31
|
+
isError: true,
|
|
32
|
+
error: formatError(error)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -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 createTrackingOption(trackingCategoryId, name) {
|
|
5
|
+
xeroClient.authenticate();
|
|
6
|
+
const response = await xeroClient.accountingApi.createTrackingOptions(xeroClient.tenantId, trackingCategoryId, {
|
|
7
|
+
name: name
|
|
8
|
+
}, undefined, // idempotencyKey
|
|
9
|
+
getClientHeaders());
|
|
10
|
+
const createdTrackingOption = response.body.options?.[0];
|
|
11
|
+
return createdTrackingOption;
|
|
12
|
+
}
|
|
13
|
+
export async function createXeroTrackingOptions(trackingCategoryId, optionNames) {
|
|
14
|
+
try {
|
|
15
|
+
const createdOptions = await Promise.all(optionNames.map(async (optionName) => await createTrackingOption(trackingCategoryId, optionName)));
|
|
16
|
+
return {
|
|
17
|
+
result: createdOptions
|
|
18
|
+
.filter(Boolean)
|
|
19
|
+
.map(option => option),
|
|
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,28 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
async function deleteTimesheet(timesheetID) {
|
|
4
|
+
await xeroClient.authenticate();
|
|
5
|
+
// Call the deleteTimesheet endpoint from the PayrollNZApi
|
|
6
|
+
await xeroClient.payrollNZApi.deleteTimesheet(xeroClient.tenantId, timesheetID);
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Delete an existing payroll timesheet in Xero
|
|
11
|
+
*/
|
|
12
|
+
export async function deleteXeroPayrollTimesheet(timesheetID) {
|
|
13
|
+
try {
|
|
14
|
+
await deleteTimesheet(timesheetID);
|
|
15
|
+
return {
|
|
16
|
+
result: true,
|
|
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,26 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
export async function downloadXeroInvoiceAttachment(invoiceId, fileName, contentType) {
|
|
4
|
+
try {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const response = await xeroClient.accountingApi.getInvoiceAttachmentByFileName(xeroClient.tenantId, invoiceId, fileName, contentType);
|
|
7
|
+
const buffer = response.body;
|
|
8
|
+
return {
|
|
9
|
+
result: {
|
|
10
|
+
fileName,
|
|
11
|
+
mimeType: contentType,
|
|
12
|
+
contentLength: buffer.length,
|
|
13
|
+
base64: buffer.toString("base64"),
|
|
14
|
+
},
|
|
15
|
+
isError: false,
|
|
16
|
+
error: null,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
return {
|
|
21
|
+
result: null,
|
|
22
|
+
isError: true,
|
|
23
|
+
error: formatError(error),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
async function getTimesheet(timesheetID) {
|
|
4
|
+
await xeroClient.authenticate();
|
|
5
|
+
// Call the Timesheet endpoint from the PayrollNZApi
|
|
6
|
+
const timesheet = await xeroClient.payrollNZApi.getTimesheet(xeroClient.tenantId, timesheetID);
|
|
7
|
+
return timesheet.body.timesheet ?? null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get a single payroll timesheet from Xero
|
|
11
|
+
*/
|
|
12
|
+
export async function getXeroPayrollTimesheet(timesheetID) {
|
|
13
|
+
try {
|
|
14
|
+
const timesheet = await getTimesheet(timesheetID);
|
|
15
|
+
return {
|
|
16
|
+
result: timesheet,
|
|
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,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
|
+
export async function getEntityHistory(entityId, config) {
|
|
5
|
+
try {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
const response = await config.getMethod.call(xeroClient.accountingApi, xeroClient.tenantId, entityId, getClientHeaders());
|
|
8
|
+
return {
|
|
9
|
+
result: response.body.historyRecords ?? [],
|
|
10
|
+
isError: false,
|
|
11
|
+
error: null,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
return {
|
|
16
|
+
result: null,
|
|
17
|
+
isError: true,
|
|
18
|
+
error: formatError(error),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export async function addEntityNote(entityId, note, config) {
|
|
23
|
+
try {
|
|
24
|
+
await xeroClient.authenticate();
|
|
25
|
+
const historyRecords = {
|
|
26
|
+
historyRecords: [{ details: note }],
|
|
27
|
+
};
|
|
28
|
+
const response = await config.createMethod.call(xeroClient.accountingApi, xeroClient.tenantId, entityId, historyRecords, undefined, getClientHeaders());
|
|
29
|
+
const created = response.body.historyRecords?.[0];
|
|
30
|
+
if (!created) {
|
|
31
|
+
throw new Error("Note creation failed - no record returned.");
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
result: created,
|
|
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,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 listAgedPayablesByContact(contactId, reportDate, invoicesFromDate, invoicesToDate) {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const response = await xeroClient.accountingApi.getReportAgedPayablesByContact(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 listXeroAgedPayablesByContact(contactId, reportDate, invoicesFromDate, invoicesToDate) {
|
|
15
|
+
try {
|
|
16
|
+
const agedPayables = await listAgedPayablesByContact(contactId, reportDate, invoicesFromDate, invoicesToDate);
|
|
17
|
+
if (!agedPayables) {
|
|
18
|
+
return {
|
|
19
|
+
result: null,
|
|
20
|
+
isError: true,
|
|
21
|
+
error: "Failed to get aged payables by contact from Xero."
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
result: agedPayables,
|
|
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,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,31 @@
|
|
|
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 getBankTransactions(page, bankAccountId) {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const response = await xeroClient.accountingApi.getBankTransactions(xeroClient.tenantId, undefined, // ifModifiedSince
|
|
7
|
+
bankAccountId ? `BankAccount.AccountID=guid("${bankAccountId}")` : undefined, // where
|
|
8
|
+
"Date DESC", // order
|
|
9
|
+
page, // page
|
|
10
|
+
undefined, // unitdp
|
|
11
|
+
10, // pagesize
|
|
12
|
+
getClientHeaders());
|
|
13
|
+
return response.body.bankTransactions ?? [];
|
|
14
|
+
}
|
|
15
|
+
export async function listXeroBankTransactions(page = 1, bankAccountId) {
|
|
16
|
+
try {
|
|
17
|
+
const bankTransactions = await getBankTransactions(page, bankAccountId);
|
|
18
|
+
return {
|
|
19
|
+
result: bankTransactions,
|
|
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,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,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 getContacts(page, searchTerm) {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const contacts = await xeroClient.accountingApi.getContacts(xeroClient.tenantId, undefined, // ifModifiedSince
|
|
7
|
+
undefined, // where
|
|
8
|
+
undefined, // order
|
|
9
|
+
undefined, // iDs
|
|
10
|
+
page, // page
|
|
11
|
+
undefined, // includeArchived
|
|
12
|
+
true, // summaryOnly
|
|
13
|
+
searchTerm, // searchTerm
|
|
14
|
+
undefined, // pageSize
|
|
15
|
+
getClientHeaders());
|
|
16
|
+
return contacts.body.contacts ?? [];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* List all contacts from Xero
|
|
20
|
+
*/
|
|
21
|
+
export async function listXeroContacts(page, searchTerm) {
|
|
22
|
+
try {
|
|
23
|
+
const contacts = await getContacts(page, searchTerm);
|
|
24
|
+
return {
|
|
25
|
+
result: contacts,
|
|
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 getCreditNotes(contactId, page) {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const response = await xeroClient.accountingApi.getCreditNotes(xeroClient.tenantId, undefined, // ifModifiedSince
|
|
7
|
+
contactId ? `Contact.ContactID=guid("${contactId}")` : undefined, // where
|
|
8
|
+
"UpdatedDateUTC DESC", // order
|
|
9
|
+
page, // page
|
|
10
|
+
undefined, // unitdp
|
|
11
|
+
10, // pageSize
|
|
12
|
+
getClientHeaders());
|
|
13
|
+
return response.body.creditNotes ?? [];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* List all credit notes from Xero
|
|
17
|
+
*/
|
|
18
|
+
export async function listXeroCreditNotes(page = 1, contactId) {
|
|
19
|
+
try {
|
|
20
|
+
const creditNotes = await getCreditNotes(contactId, page);
|
|
21
|
+
return {
|
|
22
|
+
result: creditNotes,
|
|
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,20 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
export async function listXeroInvoiceAttachments(invoiceId) {
|
|
4
|
+
try {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const response = await xeroClient.accountingApi.getInvoiceAttachments(xeroClient.tenantId, invoiceId);
|
|
7
|
+
return {
|
|
8
|
+
result: response.body.attachments ?? [],
|
|
9
|
+
isError: false,
|
|
10
|
+
error: null,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
return {
|
|
15
|
+
result: null,
|
|
16
|
+
isError: true,
|
|
17
|
+
error: formatError(error),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|