Heroic utilities to simplify and enable your progress with the xero-node SDK.
While all the exports are at the top level, the project documentation and organization is the same as the Xero API.
Common utilities for functionality across different Xero APIs.
Returns a date in the format required by the Xero API for the where parameter.
import { dateInWhereFormat } from 'xero-hero';
const date = new Date();
const formattedDate = dateInWhereFormat(date);
console.log(formattedDate); // DateTime(2020, 12, 31)
You can read more about the Accounting API here.
You can read more about the Attachments API here.
createInvoiceAttachment(client:XeroClient, tenantId:string, { invoiceId:string, fileName:string, contents:Buffer })
Creates an attachment for an invoice.
import { createInvoiceAttachment } from 'xero-hero';
const invoice = await getMyInvoice();
const attachment = await createInvoiceAttachment(xero, tenantId, {
invoiceId: invoice.invoiceId,
fileName: 'my-attachment.pdf',
contents: fs.readFileSync('my-attachment.pdf'),
});
You can read more about the Contacts API here.
Returns the link to the contact in the Xero UI.
import { getContactLink } from 'xero-hero';
const contact = await xero.contacts.getContacts();
const link = getContactLink(contact[0]);
console.log(link); // https://go.xero.com/Contacts/View/12345678-1234-1234-1234-123456789012
You can read more about the Invoices API here.
Returns the link to the invoice in the Xero UI.
import { getInvoiceLink } from 'xero-hero';
const invoice = await xero.invoices.getInvoices();
const link = getInvoiceLink(invoice[0]);
console.log(link); // https://go.xero.com/AccountsReceivable/View.aspx?InvoiceID=12345678-1234-1234-1234-123456789012
Filters the line items of an invoice by the given filter.
import { filterInvoiceLineItems } from 'xero-hero';
const invoice = await xero.invoices.getInvoices();
const filteredLineItems = filterInvoiceLineItems(invoice[0], (lineItem) => lineItem.quantity > 1);
console.log(filteredLineItems); // [ { quantity: 2, ... }, { quantity: 3, ... } ]
You can read more about the Journals API here.
Returns the link to the journal in the Xero UI.
import { getManualJournalLink } from 'xero-hero';
const journal = await xero.journals.getManualJournals();
const link = getManualJournalLink(journal[0]);
console.log(link); // https://go.xero.com/GeneralLedger/View.aspx?invoiceID=12345678-1234-1234-1234-123456789012
You can read more about the Projects API here.
Generates the USD amount for a project.
import {generateProjectAmountUSD} from 'xero-hero';
import {Amount} from 'xero-node/dist/gen/model/projects/amount';
const project = await xero.projects.getProjects();
const amount = generateProjectAmountUSD(project[0]);
console.log(amount instanceof Amount); // true
console.log(amount.currencyCode); // USD
This package was generated using a tsup starter article found here.