npm package: @konfidens/sdk
Description: Konfidens SDK
Latest version: 0.1.5

# @konfidens/sdk

Contact us via the support chat to obtain credentials.

## Install

```sh
pnpm i @konfidens/sdk

# or
yarn add @konfidens/sdk

# or
npm i @konfidens/sdk
```

## Usage

```ts
import { KonfidensSdk } from '@konfidens/sdk';

const sdk = new KonfidensSdk({
  apiKey: 'your-api-key',
  clinicId: 'your-clinic-id',
  baseUrl: 'your-base-url',
});

// Fetch basic information clinic information
const { data, error } = await sdk.getClinic();

if (error) {
  console.error(error);
} else {
  console.log(data);
}
```

### List practitioners

```ts
const practitioners = await sdk.listPractitioners();

// Example practitioners.data:
// [{
//   phone: '+4794949494',
//     id: '94ded37c-904a-4e05-97eb-506ed225db85',
//   name: 'Rudolf "94" Random',
//   title: null,
//   sequenceWeight: 13,
//   email: 'rudolf@example.com',
//   description: 'Tar i mot timer fra folk?',
//   profileImage: null,
//   booking: {
//     url: 'https://booking.konfidens.com/c/02f5bee2-08ed-4116-b610-65718cb52341/p/94ded37c-904a-4e05-97eb-506ed225db85',
//     visibility: 'ACCEPTS_NEW_CLIENTS'
//   }
// }]
```

### List services

```ts
const services = await sdk.listServices();
// Example services.data:
// [
//   {
//     id: '841495a6-bab2-46b0-a24b-aa7fbc0eefef',
//     cancelDeadlineSec: 86400,
//     clientDurationSec: 2700,
//     description: 'Nina "9" er en rev på å få gamle par til å gjenfinne kjærligheten. En time med henne er verdt 10 på spa og en sesong på Farmen sammen. Løp og kjøp.',
//     price: {
//       centsExVat: 120000,
//       centsVat: 0,
//       centsIncVat: 120000,
//       vatPermille: 0,
//       currency: 'NOK'
//     },
//     title: 'Parterapi',
//     sequenceWeight: 1,
//     isDigital: false,
//     enabledByPractitioners: [
//       '94ded37c-904a-4e05-97eb-506ed225db85',
//     ],
//     booking: {
//       url: 'http://localhost:3001/c/02f5bee2-08ed-4116-b610-65718cb52341/s/841495a6-bab2-46b0-a24b-aa7fbc0eefef'
//     },
//     location: {
//       name: 'Grensen 17',
//       url: 'https://www.google.com/maps/place/Grensen%2017,0159%20Oslo'
//     }
//   }
// ]
```

### Retrieve next available slots for booking

```ts
// Get next available slots for practitioners in clinic
const availability = await sdk.getNextAvailability();
// Example availability.data:
// [
//   {
//     practitionerId: '94ded37c-904a-4e05-97eb-506ed225db85',
//     serviceId: '841495a6-bab2-46b0-a24b-aa7fbc0eefef',
//     start: '2024-03-04T07:00:00.000Z'
//   }
// ]
```

```ts
// Get next available slots specified practitioner
const practitionerAvailability = await sdk.getNextAvailability({
  practitionerId: '94ded37c-904a-4e05-97eb-506ed225db85',
});
// Example availability.data:
// [
//   {
//     practitionerId: '94ded37c-904a-4e05-97eb-506ed225db85',
//     serviceId: '841495a6-bab2-46b0-a24b-aa7fbc0eefef',
//     start: '2024-03-04T07:00:00.000Z'
//   }
// ]
```

```ts
// Get next available slots specified service
const serviceAvailability = await sdk.getNextAvailability({
  serviceId: '841495a6-bab2-46b0-a24b-aa7fbc0eefef',
});
// Example availability.data:
// [
//   {
//     practitionerId: '94ded37c-904a-4e05-97eb-506ed225db85',
//     serviceId: '841495a6-bab2-46b0-a24b-aa7fbc0eefef',
//     start: '2024-03-04T07:00:00.000Z'
//   }
// ]
```

### Fetch / cancel booking

```ts
// Retrieve info about a specific booking
const booking = await sdk.getBooking('booking-id');
// Example booking.data:
// {
//   bookedAt: '2024-03-01T14:26:45.071Z',
//   cancelled: false,
//   cancelledBy: null,
//   clientId: 'a5f4c535-3abe-4d83-b0a2-9d781cfb733a',
//   endsAt: '2024-03-01T16:00:00.000Z',
//   timeZone: 'Europe/Oslo',
//   createdBy: 'PRACTITIONER',
//   fromChannel: 'CALENDAR',
//   location: {
//     name: 'Grensen 17',
//     url: 'https://www.google.com/maps/place/Grensen%2017,0159%20Oslo'
//   },
//   practitionerId: '4ceca0c3-dbfd-4a2c-8250-de04126d1074',
//   startsAt: '2024-03-01T15:00:00.000Z',
//   service: {
//     id: '841495a6-bab2-46b0-a24b-aa7fbc0eefef',
//     isDigital: false,
//     title: 'Parterapi',
//     price: {
//       centsExVat: 120000,
//       centsVat: 0,
//       centsIncVat: 120000,
//       vatPermille: 0,
//       currency: 'NOK'
//     }
//   }
// }

// Cancel a booking
const cancelledBooking = await sdk.cancelBooking('booking-id');
// Example cancelledBooking.data:
// {
//   bookedAt: '2024-03-01T14:26:45.071Z',
//   cancelled: true,
//   cancelledBy: 'MANAGER',
//   clientId: 'a5f4c535-3abe-4d83-b0a2-9d781cfb733a',
//   endsAt: '2024-03-01T16:00:00.000Z',
//   timeZone: 'Europe/Oslo',
//   createdBy: 'PRACTITIONER',
//   fromChannel: 'CALENDAR',
//   location: {
//     name: 'Grensen 17',
//     url: 'https://www.google.com/maps/place/Grensen%2017,0159%20Oslo'
//   },
//   practitionerId: '4ceca0c3-dbfd-4a2c-8250-de04126d1074',
//   startsAt: '2024-03-01T15:00:00.000Z',
//   service: {
//     id: '841495a6-bab2-46b0-a24b-aa7fbc0eefef',
//     isDigital: false,
//     title: 'Parterapi',
//     price: {
//       centsExVat: 120000,
//       centsVat: 0,
//       centsIncVat: 120000,
//       vatPermille: 0,
//       currency: 'NOK'
//     }
//   }
// }
```