ts-mailcow-api
Version:
TypeScript wrapper for the mailcow API.
47 lines (36 loc) • 2.11 kB
Markdown
# TypeScript wrapper for the mailcow API
[](https://www.npmjs.com/package/ts-mailcow-api)
[](https://github.com/JustSamuel/ts-mailcow-api/actions/workflows/lint-and-build.yml)
[](https://github.com/JustSamuel/ts-mailcow-api/blob/main/LICENSE)
[](https://www.npmjs.com/package/ts-mailcow-api)
[](https://justsamuel.github.io/ts-mailcow-api/classes/MailcowClient.html)
Provides typing and a easy to use interface for the [Mailcow API](https://mailcow.docs.apiary.io/#).
## Usage
The interface is exposed via the `MailcowClient` class. It's typedoc reference can be found [here](https://justsamuel.github.io/ts-mailcow-api/classes/MailcowClient.html).
To use the client, create a new wrapper using the base url and API_KEY.
```ts
import MailCowClient from "./index";
// Create MailCowClient based on BASE_URL and API_KEY
const mcc = new MailCowClient(
"https://demo.mailcow.email/api/v1",
"390448-22B69F-FA37D9-19701B-6F033F",
);
```
Then you can use the created wrapper for promised-based API calls according to the Mailcow API specification.
```ts
// Get all the mailboxes available.
mcc.mailbox
.get()
.then((e) => {
// Print all mailboxes.
console.log(JSON.stringify(e, null, 4));
})
.catch((e) => {
// Error handling.
console.log(e);
});
```
## Why it's not auto-generated
The [Mailcow OpenAPI spec](https://github.com/mailcow/mailcow-dockerized/blob/master/data/web/api/openapi.yaml) doesn’t pass validation and isn’t RESTful (e.g. `POST /api/v1/add/domain`).
If Mailcow ever fixes the naming or structure, a generated client would break.
This wrapper acts as a middleman, so those changes can be patched internally without ruining the client interface.