Skip to content

Commit

Permalink
Merge pull request #2 from qwerqy/major-bumb
Browse files Browse the repository at this point in the history
(MAJOR) stable release
  • Loading branch information
qwerqy authored Jan 30, 2025
2 parents 43cbaa2 + 3030cc7 commit 346c97a
Showing 1 changed file with 123 additions and 18 deletions.
141 changes: 123 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,133 @@
# ReserveKit JS SDK

A JS library for ReserveKit API
A JavaScript/TypeScript library for interacting with the ReserveKit API. This SDK provides a simple interface for managing services, time slots, and bookings.

## Usage
## Installation

```js
const reserveKitClient = new ReserveKit('xXXxXXXxx')
Install the package using npm:

// Get a service by its ID
await reserveKitClient.initService(1)
```bash
npm install reservekitjs
```

const serviceName = reserveKitClient.service.name
const serviceDescription = reserveKitClient.service.description
// ....other props
Or using yarn:

// Get time slots by its Service ID
const timeSlots = await reserveKitClient.service.getTimeSlots()
```bash
yarn add reservekitjs
```

Or using pnpm:

// Create a booking under that service
const booking = reserveKitClient.service.createBooking({
customer_name: 'John',
customer_email: 'john@example.com',
customer_phone: '+111222334',
date: '2020-10-10',
timeSlotId: 1,
```bash
pnpm add reservekitjs
```

## Quick Start

```javascript
import { ReserveKit } from 'reservekitjs'
// Initialize the client with your API key
const reserveKitClient = new ReserveKit('your_api_key')
// Initialize a service
await reserveKitClient.initService(1)
// Access service properties
console.log(reserveKitClient.service.name)
console.log(reserveKitClient.service.description)
// Get available time slots
const timeSlots = await reserveKitClient.service.getTimeSlots()
// Create a booking
const booking = await reserveKitClient.service.createBooking({
customer_name: 'John Doe',
customer_email: 'john@example.com',
customer_phone: '+1234567890',
date: '2024-01-01',
time_slot_id: 1
})
```

## API Reference

### ReserveKit Class

#### Constructor

```typescript
new ReserveKit(publicApiKey: string, options?: ReserveKitOptions)
```

Parameters:

- `publicApiKey` (required): Your ReserveKit API key
- `options` (optional): Configuration options
- `host`: API host (default: '<https://api.reservekit.io>')
- `version`: API version (default: 'v1')

#### Methods

##### `initService(serviceId: number)`

Initializes a service by its ID. Returns a Promise that resolves when the service is loaded.

### Service Client

Once a service is initialized, you can access its properties and methods through `reserveKitClient.service`:

#### Properties

- `id`: Service ID
- `name`: Service name
- `description`: Service description
- `provider_id`: Provider ID
- `version`: Service version
- `created_at`: Creation date
- `updated_at`: Last update date

#### Methods

##### `getTimeSlots()`

Returns a Promise that resolves to an array of available time slots for the service.

##### `createBooking(payload)`

Creates a new booking for the service.

Parameters:

```typescript
interface CreateBookingPayload {
customer_name?: string;
customer_email?: string;
customer_phone?: string;
date: string | Date;
time_slot_id: number;
}
```

## Error Handling

The SDK uses a consistent error handling pattern. All methods that make API requests can throw errors. It's recommended to wrap calls in try-catch blocks:

```js
try {
await reserveKitClient.initService(1)
} catch (error) {
console.error('Failed to initialize service:', error.message)
}
```

## TypeScript Support

This SDK is written in TypeScript and includes type definitions. You'll get full type support when using TypeScript in your project.

## License

MIT License - see LICENSE file for details.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## Support

For support, please open an issue in the GitHub repository.

0 comments on commit 346c97a

Please sign in to comment.