Skip to content

RaulCheKin/test_npm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Chekin NPM SDK

Official SDK for the Chekin API, providing easy access to property management, reservation handling, and guest check-in functionality.

npm version License: MIT

πŸš€ Features

  • Authentication: Secure API key-based authentication
  • Property Management: Create and manage properties/housings
  • Reservation Management: Handle reservations and bookings
  • Guest Management: Dynamic guest forms and check-in process
  • TypeScript Support: Full TypeScript definitions included
  • Browser & Node.js: Works in both environments
  • CDN Ready: Available via unpkg for browser use

πŸ“¦ Installation

NPM/Yarn

npm install chekin-npm-sdk
# or
yarn add chekin-npm-sdk

CDN (Browser)

<script src="https://unpkg.com/chekin-npm-sdk/dist/sdk.bundle.js"></script>

πŸ”§ Quick Start

Node.js/TypeScript

import { ChekinSDK } from 'chekin-npm-sdk';

async function main() {
  // Initialize SDK
  const sdk = new ChekinSDK('YOUR_API_KEY_HERE');
  
  // Generate authentication token
  const token = await sdk.generateToken();
  console.log('Token generated:', token);
  
  // Now you can use properties, reservations, and guests services
  const property = await sdk.properties.createProperty(
    'Hotel Demo',
    'HOT',
    {
      external_id: 'ext-' + Date.now(),
      commercial_name: 'Hotel Demo Commercial',
      vatin: 'ES12345678',
      rooms_quantity: 10,
      location: { country: 'ES', city: 'Madrid' }
    }
  );
  
  console.log('Property created:', property);
}

main().catch(console.error);

Browser

<!DOCTYPE html>
<html>
<head>
  <script src="https://unpkg.com/chekin-npm-sdk/dist/sdk.bundle.js"></script>
</head>
<body>
<script>
  async function initDemo() {
    // Initialize SDK
    const sdk = new window.ChekinNpmSDK.ChekinSDK('YOUR_API_KEY_HERE');
    
    // Generate token
    const token = await sdk.generateToken();
    console.log('SDK ready!', token);
    
    // Use the SDK services...
  }
  
  initDemo().catch(console.error);
</script>
</body>
</html>

πŸ“š API Reference

Core SDK

new ChekinSDK(apiKey: string)

Creates a new SDK instance with the provided API key.

generateToken(): Promise<string>

Generates and stores an authentication token. Must be called before using any other methods.

After calling generateToken(), the following services become available:

  • sdk.properties - Property management
  • sdk.reservations - Reservation management
  • sdk.guests - Guest management

Properties Service

sdk.properties.createProperty(name, type, options?)

Creates a new property.

Parameters:

  • name (string) - Property name (required)
  • type (PropertyType) - Property type: "HOT", "APT", "HST", "B&B" (required)
  • options (object) - Additional options:
    • external_id (string) - External identifier
    • commercial_name (string) - Commercial name
    • vatin (string) - VAT identification number
    • rooms_quantity (number) - Number of rooms
    • location (object) - Location details
      • country (string) - ISO country code
      • city (string) - City name

Example:

const property = await sdk.properties.createProperty(
  'Hotel Sunshine',
  'HOT',
  {
    external_id: 'hotel-001',
    commercial_name: 'Hotel Sunshine Resort',
    vatin: 'ES12345678',
    rooms_quantity: 50,
    location: { country: 'ES', city: 'Barcelona' }
  }
);

Reservations Service

sdk.reservations.createReservation(housingId, guests, checkIn, checkOut, options?)

Creates a new reservation.

Parameters:

  • housingId (string) - Property ID (required)
  • guests (number) - Number of guests (required)
  • checkIn (string) - Check-in date in YYYY-MM-DD format (required)
  • checkOut (string) - Check-out date in YYYY-MM-DD format (required)
  • options (object) - Additional options:
    • source_name (string) - Booking source
    • default_leader_full_name (string) - Lead guest name
    • default_invite_email (string) - Guest email
    • booking_reference (string) - External booking reference

Example:

const reservation = await sdk.reservations.createReservation(
  property.id,
  2,
  '2025-12-01',
  '2025-12-07',
  {
    source_name: 'Booking.com',
    default_leader_full_name: 'John Doe',
    default_invite_email: 'john@example.com'
  }
);

Guests Service

sdk.guests.getGuestSchema(payload)

Retrieves the dynamic guest form schema based on property and reservation details.

Parameters:

  • payload (object) - Request payload:
    • reservation_id (string) - Reservation ID (required)
    • Additional fields as needed for dynamic form generation

Example:

const schema = await sdk.guests.getGuestSchema({
  reservation_id: reservation.id
});

// Use schema.default to render dynamic form
schema.default.forEach(field => {
  console.log(field.name, field.type, field.label);
});

sdk.guests.createGuest(payload)

Creates a guest with the provided form data.

Parameters:

  • payload (object) - Guest data:
    • reservation_id (string) - Reservation ID (required)
    • Additional fields from the dynamic form

Example:

const guest = await sdk.guests.createGuest({
  reservation_id: reservation.id,
  full_name: 'John Doe',
  email: 'john@example.com',
  phone: '+1234567890',
  // ... other fields from dynamic form
});

🌍 Browser Support

The SDK works in all modern browsers and includes:

  • ES5+ compatibility
  • Promise-based API
  • TypeScript definitions
  • Global window.ChekinNpmSDK object when loaded via CDN

πŸ”’ Authentication

The SDK uses API key authentication. Contact Chekin to obtain your API credentials:

  • Test Environment: api-ng.chekintest.xyz
  • Production Environment: Contact support for details

πŸ”₯ Interactive Demo

Check out the included demo.html file for a complete working example that demonstrates:

  • SDK initialization and authentication
  • Property creation with form validation
  • Reservation management
  • Dynamic guest forms with real-time schema updates
  • Complete error handling and logging

πŸ› οΈ Development

This SDK is built with:

  • TypeScript for type safety
  • Rollup for bundling
  • Native Fetch API for HTTP requests
  • Modular architecture for easy maintenance

Build from source:

git clone <repository>
cd chekin-npm-sdk
npm install
npm run build

πŸ“ Error Handling

The SDK throws descriptive errors for:

  • Authentication failures
  • Validation errors
  • API errors
  • Network issues
try {
  const property = await sdk.properties.createProperty(/* ... */);
} catch (error) {
  console.error('Property creation failed:', error.message);
}

πŸ“„ License

MIT Β© Chekin

🀝 Support

For technical support and API access, please contact Chekin support.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published