# leasy

> This library implements helpers to interact with the Leasy API without any knowledge about the API itself. It comes with TypeScript types and comprehensive JSDoc comments to integrate nicely with your IDE of choice. The library works in the browser as wel

Latest version **0.1.0** (published 2021-06-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install leasy
pnpm add leasy
yarn add leasy
bun add leasy
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2021-06-21 |
| First published | 2021-03-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12 |
| Dependencies | 3 |
| Unpacked size | 362.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | hendrikniemann |
| Maintainers | hendrikniemann |

## Links

- npm: https://www.npmjs.com/package/leasy
- npm.io page: https://npm.io/package/leasy

## Dependencies (3)

- [graphql](https://npm.io/package/graphql.md) ^15.5.0
- [graphql-tag](https://npm.io/package/graphql-tag.md) ^2.11.0
- [graphql-request](https://npm.io/package/graphql-request.md) ^3.4.0

## Recent versions

- 0.1.0 (latest) — 2021-06-21
- 0.0.3 — 2021-06-18
- 0.0.2 — 2021-04-07
- 0.0.1 — 2021-03-09

## README

# Leasy JS SDK

This library implements helpers to interact with the Leasy API without any knowledge about the API itself.
It comes with TypeScript types and comprehensive JSDoc comments to integrate nicely with your IDE of choice.
The library works in the browser as well as in Node.js.
In the browser, this library should be used with caution: The bundle size is large and expected to grow.
The current design choice of wrapping methods in a class does not allow for code splitting.
If you only need to make simple read operations, we recommend direct GraphQL calls to the API endpoint with a read key.

## Installation

Install the Leasy JavaScript SDK with `npm` or `yarn`:

```bash
$ npm install leasy
# or
$ yarn add leasy
```

## Usage

To be able to connect to Leasy, you will have to create an API key.
Currently, the SDK supports operations that need at most `WRITE` permissions.
If you use this SDK in the frontend, the default should be to use only the `READ` permission level and do the booking operations in the backend, unless you want your users to make bookings freely.
After you created a key, you can pass it to a new Leasy Client instance:

```ts
import { Client } from 'leasy';

const leasy = new Client({ apiKey: '<YOUR_API_KEY_HERE>' });
```

## Example

```ts
import { Client } from 'leasy';

const leasy = new Client({ apiKey: '<YOUR_API_KEY_HERE>' });
const resourceId = '<SOME_RESOURCE_ID>';

const example = async () => {
  // Load all upcoming available slots
  const slots = await leasy.timeSlots.byResource({
    resourceId,
    filter: { available: true },
  });
  const nextAvailableSlot = slots.nodes[0];

  if (nextAvailableSlot) {
    // Attempt to create a reservation, this line might throw if unsuccessful
    // After this, the reservation is ours, we have to complete it within the next 15 minutes
    const reservation = await leasy.reservations.create({
      bookings: [
        {
          bookableId: resourceId,
          start: nextAvailableSlot.startTime,
          end: nextAvailableSlot.endTime,
        },
      ],
    });

    // in this example we complete the reservation immediately, in the real world, you might want to
    // guide the customer through some kind of checkout process and e.g. receive some payments
    await leasy.reservations.update(reservation.id, reservation => [reservation.complete()]);
  }
};
```

---
_Source: https://npm.io/package/leasy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
