1.3.0 • Published 3 years ago

vailable v1.3.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

vailable

Booking is tough. Make it easy!

Prerequisite

Install

yarn add vailable

Example usage

Create an token (backend)

import Vailable from 'vailable';
import * as jwt from 'jsonwebtoken';

// Get these from www.vailable.eu
const secretKey = 'your-secret-key';
const accountId = 'www.mydomain.com';

const adminToken = jwt.sign({
  iss: accountId,
  aud: ['api.vailable.eu'],
  role: 'admin', 
}, secretKey, {
  algorithm: 'RS256',
  expiresIn: '1 hour',
})

const enduserToken = jwt.sign({
  iss: accountId,
  aud: ['api.vailable.eu'],
  role: 'user', 
  sub: 'external-user-id'
}, secretKey, {
  algorithm: 'RS256',
  expiresIn: '1 hour',
})

const API = new Vailable({ token: adminToken });
// Auth can also be set with API.setToken(token);

Add a bookable resource

A resource must be created before adding any bookings. This would typically be done only once, during initial setup, by an administrator.

import { createSchedule } from 'vailable';

// 1 hour long sessions, bookable at 08:00, 08:30, 09:00, ..., 19:30
const schedule = createSchedule({
  start: '08:00',
  end: '20:00',
  slotIntervalMinutes: 30,
  slotDurationMinutes: 60,
});
const resource = await API.addResource({
  label: 'My first Spa',
  schedule,
  seats: 12,
});

Add booking (from backend)

const userId = 'external-user-id'
const newBooking = await API.addBooking({
  userId,
  resourceId: resource.id,
  start: new Date('2021-05-17T13:30:00Z'),
});

const bookings = await API.findBookings({ userId });

// bookings.length === 1
// bookings[0].id === newBooking.id

Add booking (from frontend)

const API = new Vailable({ token: enduserToken });

const newBooking = await API.addBooking({
  // userId is automatically set from token "sub" field
  resourceId: resource.id,
  start: new Date('2021-05-17T13:30:00Z'),
});

// user role only has access to own bookings 
const bookings = await API.findBookings();

// bookings.length === 1
// bookings[0].id === newBooking.id
1.3.0

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago

1.0.0-beta.7

3 years ago

1.0.0-beta.8

3 years ago

1.0.0-beta.6

3 years ago

1.0.0-beta.5

3 years ago

1.0.0-beta.4

3 years ago

1.0.0-beta.3

3 years ago

1.0.0-beta.2

3 years ago

1.0.0-beta.1

3 years ago