/sevdesk

Mirror! Use Gitlab.com for issues!

Primary LanguageTypeScriptMIT LicenseMIT

@mojoio/sevdesk

mojoio integration package for sevdesk

Availabililty and Links

Status for master

build status coverage report npm downloads per month Known Vulnerabilities TypeScript node JavaScript Style Guide

Usage

Use TypeScript for best in class instellisense.

This package aims to be a fully typed (TypeScript), easy to use unofficial nodejs API package for sevdesk.com.

The basic concept of this library consists of classes that expose static functions (factories) for retrieving instances from the sevdesk API while abstracting enough to not needing to know the specifics of that API.

Typings and constructor options follow the world view of @tsclass/tsclass, a package that exposes generalized interfaces for real world objects.

Available Classes

  • SevdeskAccount -> handles the basic Account setup for authentication
  • SevdeskContact -> handles contacts within sevdesk
  • SevdeskVoucher -> handles expenses/receipts/vouchers within sevdesk
  • SevdeskCheckingAccount -> handles CheckingAccounts within sevdesk
  • SevdeskTransaction -> handles Transactions within sevdesk

Every class exposes static functions to retrieve information from sevdesk. Every instance of an class exposes a .save(myAccountInstanceHere) function to store information back to sevdesk.

import * as sevdesk from '@mojoio/sevdesk';

const sevdeskAccount = new sevdesk.SevdeskAccount('myTokenString1234567890');
const contacts: sevdesk.SevdeskContact[] = sevdesk.SevdeskContact.getContacts(sevdeskAccount);
const certainContact = contacts.find(contact => {
  return contact.customerNumber === '1000';
});

certainContact.name = 'My New Name';

// note:
// If you want to transfer the contact to another account, simply instantiate a second account :)
certainContact.save(sevdeskAccount);

A simple example to create Transactions:

import * as sevdesk from '@mojoio/sevdesk';

const run = async () => {
  const sevdeskAccount = new sevdesk.SevdeskAccount('myTokenString1234567890');
  let sevdeskCheckingAccount = await sevdesk.SevdeskCheckingAccount.getCheckingAccountByName(
    sevdeskAccount,
    'commerzbank'
  );

  if (!sevdeskCheckingAccount) {
    sevdeskCheckingAccount = new sevdesk.SevdeskCheckingAccount({
      currency: 'EUR',
      name: 'commerzbank',
      transactions: []
    });

    // NOTE: .save() will get the sevdeskId and store it in the instance at .sevdeskId !
    // this is the default behaviour for all classes that can be `.save()`ed to sevdesk !
    await sevdeskCheckingAccount.save(sevdeskAccount);
  }

  const myTransaction = new sevdesk.SevdeskTransaction({
    sevdeskCheckingAccountId: sevdeskCheckingAccount.sevdeskId,
    payeeName: 'Max Mustermann',
    amount: 100,
    date: new Date(),
    status: 'unpaid',
    description: 'a cool description'
  });

  await myTransaction.save(sevdeskAccount);
};

run();

For further information read the linked docs at the top of this readme.

MIT licensed | © Lossless GmbH | By using this npm module you agree to our privacy policy

repo-footer