@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,49 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
import { Phone } from "xero-node";
|
|
4
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
5
|
+
async function createContact(name, email, phone) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
const contact = {
|
|
8
|
+
name,
|
|
9
|
+
emailAddress: email,
|
|
10
|
+
phones: phone
|
|
11
|
+
? [
|
|
12
|
+
{
|
|
13
|
+
phoneNumber: phone,
|
|
14
|
+
phoneType: Phone.PhoneTypeEnum.MOBILE,
|
|
15
|
+
},
|
|
16
|
+
]
|
|
17
|
+
: undefined,
|
|
18
|
+
};
|
|
19
|
+
const response = await xeroClient.accountingApi.createContacts(xeroClient.tenantId, {
|
|
20
|
+
contacts: [contact],
|
|
21
|
+
}, //contacts
|
|
22
|
+
true, //summarizeErrors
|
|
23
|
+
undefined, //idempotencyKey
|
|
24
|
+
getClientHeaders());
|
|
25
|
+
return response.body.contacts?.[0];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a new invoice in Xero
|
|
29
|
+
*/
|
|
30
|
+
export async function createXeroContact(name, email, phone) {
|
|
31
|
+
try {
|
|
32
|
+
const createdContact = await createContact(name, email, phone);
|
|
33
|
+
if (!createdContact) {
|
|
34
|
+
throw new Error("Contact creation failed.");
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
result: createdContact,
|
|
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,50 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
import { CreditNote } from "xero-node";
|
|
4
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
5
|
+
import { localDateString } from "../helpers/datetime.js";
|
|
6
|
+
async function createCreditNote(contactId, lineItems, reference) {
|
|
7
|
+
await xeroClient.authenticate();
|
|
8
|
+
const creditNote = {
|
|
9
|
+
type: CreditNote.TypeEnum.ACCRECCREDIT,
|
|
10
|
+
contact: {
|
|
11
|
+
contactID: contactId,
|
|
12
|
+
},
|
|
13
|
+
lineItems: lineItems,
|
|
14
|
+
date: localDateString(),
|
|
15
|
+
reference: reference,
|
|
16
|
+
status: CreditNote.StatusEnum.DRAFT,
|
|
17
|
+
};
|
|
18
|
+
const response = await xeroClient.accountingApi.createCreditNotes(xeroClient.tenantId, {
|
|
19
|
+
creditNotes: [creditNote],
|
|
20
|
+
}, // creditNotes
|
|
21
|
+
true, // summarizeErrors
|
|
22
|
+
undefined, // unitdp
|
|
23
|
+
undefined, // idempotencyKey
|
|
24
|
+
getClientHeaders());
|
|
25
|
+
const createdCreditNote = response.body.creditNotes?.[0];
|
|
26
|
+
return createdCreditNote;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a new credit note in Xero
|
|
30
|
+
*/
|
|
31
|
+
export async function createXeroCreditNote(contactId, lineItems, reference) {
|
|
32
|
+
try {
|
|
33
|
+
const createdCreditNote = await createCreditNote(contactId, lineItems, reference);
|
|
34
|
+
if (!createdCreditNote) {
|
|
35
|
+
throw new Error("Credit note creation failed.");
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
result: createdCreditNote,
|
|
39
|
+
isError: false,
|
|
40
|
+
error: null,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return {
|
|
45
|
+
result: null,
|
|
46
|
+
isError: true,
|
|
47
|
+
error: formatError(error),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
2
|
+
import { formatError } from "../helpers/format-error.js";
|
|
3
|
+
import { Invoice } from "xero-node";
|
|
4
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
5
|
+
import { localDateString } from "../helpers/datetime.js";
|
|
6
|
+
async function createInvoice(contactId, lineItems, type, reference, date) {
|
|
7
|
+
await xeroClient.authenticate();
|
|
8
|
+
const invoice = {
|
|
9
|
+
type: type,
|
|
10
|
+
contact: {
|
|
11
|
+
contactID: contactId,
|
|
12
|
+
},
|
|
13
|
+
lineItems: lineItems,
|
|
14
|
+
date: date || localDateString(),
|
|
15
|
+
dueDate: localDateString(30),
|
|
16
|
+
...(type === Invoice.TypeEnum.ACCPAY
|
|
17
|
+
? { invoiceNumber: reference }
|
|
18
|
+
: { reference: reference }),
|
|
19
|
+
status: Invoice.StatusEnum.DRAFT,
|
|
20
|
+
};
|
|
21
|
+
const response = await xeroClient.accountingApi.createInvoices(xeroClient.tenantId, {
|
|
22
|
+
invoices: [invoice],
|
|
23
|
+
}, // invoices
|
|
24
|
+
true, //summarizeErrors
|
|
25
|
+
undefined, //unitdp
|
|
26
|
+
undefined, //idempotencyKey
|
|
27
|
+
getClientHeaders());
|
|
28
|
+
const createdInvoice = response.body.invoices?.[0];
|
|
29
|
+
return createdInvoice;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a new invoice in Xero
|
|
33
|
+
*/
|
|
34
|
+
export async function createXeroInvoice(contactId, lineItems, type = Invoice.TypeEnum.ACCREC, reference, date) {
|
|
35
|
+
try {
|
|
36
|
+
const createdInvoice = await createInvoice(contactId, lineItems, type, reference, date);
|
|
37
|
+
if (!createdInvoice) {
|
|
38
|
+
throw new Error("Invoice creation failed.");
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
result: createdInvoice,
|
|
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,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
|
+
async function createItem(itemDetails) {
|
|
5
|
+
await xeroClient.authenticate();
|
|
6
|
+
const item = {
|
|
7
|
+
code: itemDetails.code,
|
|
8
|
+
name: itemDetails.name,
|
|
9
|
+
description: itemDetails.description,
|
|
10
|
+
purchaseDescription: itemDetails.purchaseDescription,
|
|
11
|
+
isPurchased: !!itemDetails.purchaseDetails,
|
|
12
|
+
isSold: !!itemDetails.salesDetails,
|
|
13
|
+
purchaseDetails: itemDetails.purchaseDetails
|
|
14
|
+
? {
|
|
15
|
+
unitPrice: itemDetails.purchaseDetails.unitPrice,
|
|
16
|
+
taxType: itemDetails.purchaseDetails.taxType,
|
|
17
|
+
accountCode: itemDetails.purchaseDetails.accountCode,
|
|
18
|
+
}
|
|
19
|
+
: undefined,
|
|
20
|
+
salesDetails: itemDetails.salesDetails
|
|
21
|
+
? {
|
|
22
|
+
unitPrice: itemDetails.salesDetails.unitPrice,
|
|
23
|
+
taxType: itemDetails.salesDetails.taxType,
|
|
24
|
+
accountCode: itemDetails.salesDetails.accountCode,
|
|
25
|
+
}
|
|
26
|
+
: undefined,
|
|
27
|
+
isTrackedAsInventory: itemDetails.isTrackedAsInventory,
|
|
28
|
+
inventoryAssetAccountCode: itemDetails.inventoryAssetAccountCode,
|
|
29
|
+
};
|
|
30
|
+
const items = {
|
|
31
|
+
items: [item],
|
|
32
|
+
};
|
|
33
|
+
const response = await xeroClient.accountingApi.createItems(xeroClient.tenantId, items, // items
|
|
34
|
+
true, // summarizeErrors
|
|
35
|
+
undefined, // unitdp
|
|
36
|
+
undefined, // idempotencyKey
|
|
37
|
+
getClientHeaders());
|
|
38
|
+
return response.body.items?.[0] ?? null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create an item in Xero
|
|
42
|
+
*/
|
|
43
|
+
export async function createXeroItem(itemDetails) {
|
|
44
|
+
try {
|
|
45
|
+
const item = await createItem(itemDetails);
|
|
46
|
+
return {
|
|
47
|
+
result: item,
|
|
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,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,50 @@
|
|
|
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 { localDateString } from "../helpers/datetime.js";
|
|
5
|
+
async function createPayment({ invoiceId, accountId, amount, date, reference, }) {
|
|
6
|
+
await xeroClient.authenticate();
|
|
7
|
+
const payment = {
|
|
8
|
+
invoice: {
|
|
9
|
+
invoiceID: invoiceId,
|
|
10
|
+
},
|
|
11
|
+
account: {
|
|
12
|
+
accountID: accountId,
|
|
13
|
+
},
|
|
14
|
+
amount: amount,
|
|
15
|
+
date: date || localDateString(),
|
|
16
|
+
reference: reference,
|
|
17
|
+
};
|
|
18
|
+
const response = await xeroClient.accountingApi.createPayment(xeroClient.tenantId, payment, undefined, // idempotencyKey
|
|
19
|
+
getClientHeaders());
|
|
20
|
+
return response.body.payments?.[0];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a new payment in Xero
|
|
24
|
+
*/
|
|
25
|
+
export async function createXeroPayment({ invoiceId, accountId, amount, date, reference, }) {
|
|
26
|
+
try {
|
|
27
|
+
const createdPayment = await createPayment({
|
|
28
|
+
invoiceId,
|
|
29
|
+
accountId,
|
|
30
|
+
amount,
|
|
31
|
+
date,
|
|
32
|
+
reference,
|
|
33
|
+
});
|
|
34
|
+
if (!createdPayment) {
|
|
35
|
+
throw new Error("Payment creation failed.");
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
result: createdPayment,
|
|
39
|
+
isError: false,
|
|
40
|
+
error: null,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return {
|
|
45
|
+
result: null,
|
|
46
|
+
isError: true,
|
|
47
|
+
error: formatError(error),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -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,53 @@
|
|
|
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
|
+
import { localDateString } from "../helpers/datetime.js";
|
|
6
|
+
async function createQuote(quoteNumber, reference, terms, contactId, lineItems, title, summary) {
|
|
7
|
+
await xeroClient.authenticate();
|
|
8
|
+
const quote = {
|
|
9
|
+
quoteNumber: quoteNumber,
|
|
10
|
+
reference: reference,
|
|
11
|
+
terms: terms,
|
|
12
|
+
contact: {
|
|
13
|
+
contactID: contactId,
|
|
14
|
+
},
|
|
15
|
+
date: localDateString(),
|
|
16
|
+
lineItems: lineItems,
|
|
17
|
+
expiryDate: localDateString(7),
|
|
18
|
+
status: QuoteStatusCodes.DRAFT,
|
|
19
|
+
title: title,
|
|
20
|
+
summary: summary,
|
|
21
|
+
};
|
|
22
|
+
const response = await xeroClient.accountingApi.createQuotes(xeroClient.tenantId, {
|
|
23
|
+
quotes: [quote],
|
|
24
|
+
}, // quotes
|
|
25
|
+
true, //summarizeErrors
|
|
26
|
+
undefined, //idempotencyKey
|
|
27
|
+
getClientHeaders());
|
|
28
|
+
const createdQuote = response.body.quotes?.[0];
|
|
29
|
+
return createdQuote;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a new quote in Xero
|
|
33
|
+
*/
|
|
34
|
+
export async function createXeroQuote(contactId, lineItems, reference, quoteNumber, terms, title, summary) {
|
|
35
|
+
try {
|
|
36
|
+
const createdQuote = await createQuote(quoteNumber, reference, terms, contactId, lineItems, title, summary);
|
|
37
|
+
if (!createdQuote) {
|
|
38
|
+
throw new Error("Quote creation failed.");
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
result: createdQuote,
|
|
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,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,30 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
3
|
+
import { formatError } from "../helpers/format-error.js";
|
|
4
|
+
/**
|
|
5
|
+
* Delete an attachment from an invoice by its attachment ID.
|
|
6
|
+
*
|
|
7
|
+
* Note: xero-node v13 does not expose a deleteInvoiceAttachment method,
|
|
8
|
+
* so we call the REST endpoint directly using the authenticated token.
|
|
9
|
+
*/
|
|
10
|
+
export async function deleteXeroInvoiceAttachment(invoiceId, attachmentId) {
|
|
11
|
+
try {
|
|
12
|
+
await xeroClient.authenticate();
|
|
13
|
+
const tokenSet = xeroClient.readTokenSet();
|
|
14
|
+
const accessToken = tokenSet.access_token;
|
|
15
|
+
if (!accessToken) {
|
|
16
|
+
throw new Error("No access token available. Authentication may have failed.");
|
|
17
|
+
}
|
|
18
|
+
await axios.delete(`https://api.xero.com/api.xro/2.0/Invoices/${invoiceId}/Attachments/${attachmentId}`, {
|
|
19
|
+
headers: {
|
|
20
|
+
Authorization: `Bearer ${accessToken}`,
|
|
21
|
+
"Xero-Tenant-Id": xeroClient.tenantId,
|
|
22
|
+
Accept: "application/json",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
return { result: true, isError: false, error: null };
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
return { result: null, isError: true, error: formatError(error) };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -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,23 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
4
|
+
import { formatError } from "../helpers/format-error.js";
|
|
5
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
6
|
+
import { getDownloadPath } from "../helpers/get-download-path.js";
|
|
7
|
+
/**
|
|
8
|
+
* Download an invoice attachment by filename and save it to the local download directory.
|
|
9
|
+
* Returns the full path of the saved file.
|
|
10
|
+
*/
|
|
11
|
+
export async function downloadXeroInvoiceAttachment(invoiceId, fileName, contentType) {
|
|
12
|
+
try {
|
|
13
|
+
await xeroClient.authenticate();
|
|
14
|
+
const response = await xeroClient.accountingApi.getInvoiceAttachmentByFileName(xeroClient.tenantId, invoiceId, fileName, contentType, getClientHeaders());
|
|
15
|
+
const dir = getDownloadPath();
|
|
16
|
+
const savePath = path.join(dir, fileName);
|
|
17
|
+
fs.writeFileSync(savePath, response.body);
|
|
18
|
+
return { result: savePath, isError: false, error: null };
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
return { result: null, isError: true, error: formatError(error) };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { xeroClient } from "../clients/xero-client.js";
|
|
4
|
+
import { formatError } from "../helpers/format-error.js";
|
|
5
|
+
import { getClientHeaders } from "../helpers/get-client-headers.js";
|
|
6
|
+
import { getDownloadPath } from "../helpers/get-download-path.js";
|
|
7
|
+
/**
|
|
8
|
+
* Download the Xero-generated PDF for an invoice and save it to the local download directory.
|
|
9
|
+
* The PDF is rendered by Xero using the organisation's branding theme.
|
|
10
|
+
* Returns the full local path of the saved file.
|
|
11
|
+
*/
|
|
12
|
+
export async function downloadXeroInvoicePdf(invoiceId, fileName) {
|
|
13
|
+
try {
|
|
14
|
+
await xeroClient.authenticate();
|
|
15
|
+
const response = await xeroClient.accountingApi.getInvoiceAsPdf(xeroClient.tenantId, invoiceId, getClientHeaders());
|
|
16
|
+
const dir = getDownloadPath();
|
|
17
|
+
const saveName = fileName || `invoice-${invoiceId}.pdf`;
|
|
18
|
+
const savePath = path.join(dir, saveName);
|
|
19
|
+
fs.writeFileSync(savePath, response.body);
|
|
20
|
+
return { result: savePath, isError: false, error: null };
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return { result: null, isError: true, error: formatError(error) };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
* Retrieve a single invoice by its ID, including full line item details.
|
|
6
|
+
*/
|
|
7
|
+
export async function getXeroInvoice(invoiceId) {
|
|
8
|
+
try {
|
|
9
|
+
await xeroClient.authenticate();
|
|
10
|
+
const response = await xeroClient.accountingApi.getInvoice(xeroClient.tenantId, invoiceId, undefined, getClientHeaders());
|
|
11
|
+
const invoice = response.body.invoices?.[0];
|
|
12
|
+
if (!invoice)
|
|
13
|
+
throw new Error("Invoice not found.");
|
|
14
|
+
return { result: invoice, isError: false, error: null };
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
return { result: null, isError: true, error: formatError(error) };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -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,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
|
+
}
|