npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@elbstack/lexoffice-client-js

v1.0.1

Published

An universal client for the Lexoffice API written in Typescript

Downloads

786

Readme

📦 Contents


npm install @elbstack/lexoffice-client-js

or

yarn add @elbstack/lexoffice-client-js

You can find the official lexoffice API documentation here.

To get your API Key, you must already be a lexoffice user. Get it here.

import { Client } from '@elbstack/lexoffice-client-js';

const client = new Client(YOUR_LEXOFFICE_API_KEY);

All functions are promise based. These promises are formatted by the ts-results package, for extended error handling see Error handling.

Retrieve an invoice

const invoiceResult = await client.retrieveInvoice('caf4e0c3-c3e8-4a06-bcfe-346bc7190b2');

if (invoiceResult.ok) {
  const invoice = invoiceResult.val;
} else {
  console.error('An error occured');
}

Create an invoice

const invoice = {
  voucherDate: '2017-02-22T00:00:00.000+01:00',
  address: {
    name: 'Bike & Ride GmbH & Co. KG',
    supplement: 'Gebäude 10',
    street: 'Musterstraße 42',
    city: 'Freiburg',
    zip: '79112',
    countryCode: 'DE',
  },
  lineItems: [
    {
      type: 'custom',
      name: 'Energieriegel Testpaket',
      quantity: 1,
      unitName: 'Stück',
      unitPrice: {
        currency: 'EUR',
        netAmount: 5,
        taxRatePercentage: 0,
      },
      discountPercentage: 0,
    },
    {
      type: 'text',
      name: 'Strukturieren Sie Ihre Belege durch Text-Elemente.',
      description: 'Das hilft beim Verständnis',
    },
  ],
  totalPrice: {
    currency: 'EUR',
  },
  taxConditions: {
    taxType: 'net',
  },
  shippingConditions: {
    shippingDate: '2017-04-22T00:00:00.000+02:00',
    shippingType: 'delivery',
  },
  title: 'Rechnung',
  introduction: 'Ihre bestellten Positionen stellen wir Ihnen hiermit in Rechnung',
  remark: 'Vielen Dank für Ihren Einkauf',
};

const createdInvoiceResult = await client.createInvoice(invoice, { finalize: true });

if (createdInvoiceResult.ok) {
  const invoice = createdInvoiceResult.val;
} else {
  console.error('An error occured');
}

Upload File

let fs = require('fs');
let FormData = require('form-data');

let data = new FormData();

data.append('file', fs.createReadStream(__dirname + '/yourFolder/yourFile'));
data.append('type', 'voucher');

const uploadedFileResult = await client.uploadFile(data);

if (uploadedFileResult.ok) {
  const invoice = uploadedFileResult.val;
} else {
  console.error('An error occured');
}

As mentioned above, the returned promises are formatted by ts-results which is a typescript implementation of Rust's Result and Option objects. It brings compile-time error checking and optional values to typescript. All errors are instances of type RequestError. If you want to use the advantages of ts-results, all client responses should be processed similar to the following:

if (YOUR_RESULT.ok) {
  const YOUR_VARIABLE = YOUR_RESULT.val;
  // Work with your result
} else {
  // Your request returned an error
  const error = YOUR_RESULT.val;
  console.log('error:', error);
  // Further error checking is possible by
  if (error instanceof RequestError) {
    console.log('Hello instance of RequestError!');

    if (error instanceof RequestNotFoundError) {
      console.log('Wow, it looks like you have many instances!');
    }
    if (error instanceof RequestMethodNotAcceptableLegacyError) {
      console.log('Seems, that you take care of your legacy!');
    }
  }
}

Error codes and types

Contact


createContact(contact: ContactCreatePerson | ContactCreateCompany): Promise<Result<ContactCreateResponse, RequestError>>

retrieveContact(id: string): Promise<Result<ContactRetrieveResponse, RequestError>>

updateContact(id: string, contact: ContactUpdatePerson | ContactUpdateCompany): Promise<Result<ContactUpdateResponse, RequestError>>

filterContact(filter?: OptionalFilters & Partial<PagingParameters>): Promise<Result<ContactFilterRetrieveResponse, RequestError>>

Country

retrieveListOfCountries(): Promise<Result<Country[], RequestError>>

Credit note

createCreditNote(creditNote: CreditNoteCreate, optionalFinalized?: OptionalFinalized): Promise<Result<CreditNoteCreateResponse, RequestError>>

retrieveCreditNote(id: string): Promise<Result<CreditNoteRetrieveResponse, RequestError>>

renderCreditNoteDocumentFileId(id: string): Promise<Result<DocumentFileId, RequestError>>

Down payment invoice

retrieveDownPaymentInvoice(id: string): Promise<Result<DownPaymentInvoice, RequestError>>

Event subscription

createEventSubscription(eventSubscription: EventSubscriptionCreate): Promise<Result<EventSubscription, RequestError>>

retrieveEventSubscription(id: string): Promise<Result<EventSubscription, RequestError>>

retrieveAllEventSubscriptions(): Promise<Result<EventSubscriptions, RequestError>>

deleteEventSubscription(id: string): Promise<Result<unknown, RequestError>>

File

uploadFile(data: FormData): Promise<Result<FileResponse, RequestError>>

downloadFile(documentFileId: string, optionalParameter?: RenderType): Promise<Result<unknown, RequestError>>

Invoice

createInvoice(invoice: InvoiceCreate | XRechnung, optionalFinalized?: OptionalFinalized): Promise<Result<InvoiceCreateResponse, RequestError>>

retrieveInvoice(id: string): Promise<Result<InvoiceRetrieveResponse, RequestError>>

renderInvoiceDocumentFileId(id: string): Promise<Result<DocumentFileId, RequestError>>

Order confirmation

createOrderConfirmation(orderConfirmation: OrderConfirmation): Promise<Result<OrderConfirmationResponse, RequestError>>

retrieveOrderConfirmation(id: string): Promise<Result<OrderConfirmationRetrieveResponse, RequestError>>

renderOrderConfirmationDocumentFileId(id: string): Promise<Result<DocumentFileId, RequestError>>

Payment

retrievePayment(id: string): Promise<Result<Payment, RequestError>>

Payment condition

retrievePaymentConditionList(): Promise<Result<PaymentCondition, RequestError>>

Posting category

retrieveListPostingCategories(): Promise<Result<PostingCategory[], RequestError>>

Profile

retrieveProfile(): Promise<Result<Profile, RequestError>>

Quotation

createQuotation(quotation: QuotationCreate, optionalFilter?: OptionalFinalized): Promise<Result<QuotationCreate, RequestError>>

retrieveQuotation(id: string): Promise<Result<Partial<Quotation>, RequestError>>

renderQuotationDocumentFileId(id: string): Promise<Result<DocumentFileId, RequestError>>

Recurring template

retrieveRecurringTemplate(id: string): Promise<Result<Partial<RecurringTemplate>, RequestError>>

retrieveAllRecurringTemplates(optionalFilter?: PagingParameters): Promise<Result<RecurringTemplates, RequestError>>

Voucher

createVoucher(voucher: CreateVoucher): Promise<Result<VoucherCreateResponse, RequestError>>

retrieveVoucher(id: string): Promise<Result<Partial<Voucher>, RequestError>>

updateVoucher(id: string, voucher: CreateVoucher): Promise<Result<VoucherCreateResponse, RequestError>>

filterVoucher(voucherNumber: VoucherNumber): Promise<Result<Partial<Vouchers>, RequestError>>

uploadFileToVoucher(data: FormData, id: string): Promise<Result<FileResponse, RequestError>>

Voucherlist

retrieveVoucherlist(filterParameter: FilterParameter): Promise<Result<Voucherlist, RequestError>>

Updating

For updating any type of vouchers where the "version" property is required, you first need to retrieve it and use the current "version" value to properly update.

Rendering Document File Id

Only possible for any type of vouchers that are not in "draft" mode.

Download File

The required id is not the id itself, it is the documentFileId, which can be required with the matching method and the vouchers id:

renderCreditNoteDocumentFileId(id);
renderInvoiceDocumentFileId(id);
renderOrderConfirmationDocumentFileId(id);
renderQuotationDocumentFileId(id);

elbstack is a software engineering & design company. We question, we advise, and we're excited to help your next project to succeed. We offer software development and design as service. That's how we support you with the realisation of your projects - with individual employees or with a whole team. We love to work remotely, but we will work at your place, too.

👩🏻‍💻👨🏽‍💻 We are hiring!

➡️ Go and check kununu.com ➡️ elbstack.com