schedcore-sdk
v1.0.3
Published
SDK TypeScript pour l'API SchedCore - Gestion de calendriers et réservations
Maintainers
Readme
SchedCore SDK
Un SDK TypeScript moderne pour l'API SchedCore, facilitant l'intégration de fonctionnalités de réservation et de gestion de calendrier dans vos applications.
Installation
npm install schedcore-sdk
# ou
yarn add schedcore-sdkDémarrage rapide
Initialisation
import { SchedCoreSDK } from "schedcore-sdk";
// Configuration de base
const schedCore = new SchedCoreSDK({
baseURL: "https://api.schedcore.com", // ou votre URL d'API
environment: "production", // ou 'development'
});
// Configuration pour le développement local
const schedCoreDev = new SchedCoreSDK({
baseURL: "http://localhost:8585",
environment: "development",
});Authentification
// Inscription
try {
const user = await schedCore.register({
email: "[email protected]",
password: "password123",
firstName: "John",
lastName: "Doe",
});
console.log("Utilisateur créé:", user);
} catch (error) {
console.error("Erreur d'inscription:", error);
}
// Connexion
try {
const user = await schedCore.login("[email protected]", "password123");
console.log("Utilisateur connecté:", user);
} catch (error) {
console.error("Erreur de connexion:", error);
}
// Vérifier l'état d'authentification
if (schedCore.isAuthenticated()) {
const currentUser = schedCore.getUser();
console.log("Utilisateur actuel:", currentUser);
}
// Déconnexion
await schedCore.logout();Gestion des entreprises
// Créer une entreprise
const business = await schedCore.business.createBusiness({
name: "Mon Salon de Coiffure",
email: "[email protected]",
phone: "+33123456789",
address: "123 Rue de la Paix, Paris",
category: "Beauty & Wellness",
});
// Récupérer mes entreprises
const myBusinesses = await schedCore.business.getMyBusinesses();
// Mettre à jour une entreprise
const updatedBusiness = await schedCore.business.updateBusiness(business.id, {
name: "Nouveau nom",
description: "Description mise à jour",
});Gestion du calendrier
// Définir les horaires d'ouverture
const weeklySchedule = {
monday: {
isOpen: true,
timeSlots: [
{ startTime: "09:00", endTime: "12:00" },
{ startTime: "14:00", endTime: "18:00" },
],
},
tuesday: {
isOpen: true,
timeSlots: [
{ startTime: "09:00", endTime: "12:00" },
{ startTime: "14:00", endTime: "18:00" },
],
},
// ... autres jours
sunday: {
isOpen: false,
timeSlots: [],
},
};
await schedCore.calendar.updateWeeklySchedule(businessId, weeklySchedule);
// Ajouter une exception (jour férié)
await schedCore.calendar.addException(businessId, {
date: "2024-12-25",
type: "HOLIDAY",
reason: "Noël",
});
// Récupérer la disponibilité
const availability = await schedCore.calendar.getAvailability(businessId, {
date: "2024-12-20",
duration: 60,
});Gestion des réservations
// Créer une réservation
const booking = await schedCore.booking.createBooking({
businessId: "business_123",
serviceName: "Coupe et brushing",
date: "2024-12-20",
startTime: "10:00",
duration: 60,
customerInfo: {
name: "Marie Dubois",
email: "[email protected]",
phone: "+33987654321",
},
notes: "Première visite",
});
// Récupérer les réservations d'une entreprise
const bookings = await schedCore.booking.getBusinessBookings(businessId, {
status: "CONFIRMED",
dateFrom: "2024-12-01",
dateTo: "2024-12-31",
});
// Confirmer une réservation
await schedCore.booking.confirmBooking(businessId, booking.id);
// Annuler une réservation
await schedCore.booking.cancelBooking(businessId, booking.id, {
reason: "Demande du client",
notifyCustomer: true,
});Gestion des paiements
// Créer une intention de paiement
const paymentIntent = await schedCore.payment.createPaymentIntent({
bookingId: booking.id,
amount: 5000, // en centimes (50€)
currency: "EUR",
method: "CARD",
customerInfo: {
name: "Marie Dubois",
email: "[email protected]",
},
});
// Traiter le paiement
const payment = await schedCore.payment.processPayment(paymentIntent.id, {
cardDetails: {
number: "4242424242424242",
expMonth: 12,
expYear: 2025,
cvc: "123",
},
});
// Créer un remboursement
const refund = await schedCore.payment.createRefund(payment.id, {
amount: 2500, // remboursement partiel (25€)
reason: "Annulation partielle",
});Gestion des événements
// Écouter les événements d'authentification
schedCore.on("auth:login", (user) => {
console.log("Utilisateur connecté:", user);
});
schedCore.on("auth:logout", () => {
console.log("Utilisateur déconnecté");
});
schedCore.on("auth:error", (error) => {
console.error("Erreur d'authentification:", error);
});Configuration avancée
const schedCore = new SchedCoreSDK({
baseURL: "https://api.schedcore.com",
timeout: 30000,
retry: {
attempts: 3,
delay: 1000,
},
headers: {
"Custom-Header": "value",
},
});
// Mettre à jour la configuration
schedCore.updateConfig({
timeout: 60000,
});
// Test de connectivité
const isOnline = await schedCore.healthCheck();Gestion des erreurs
import { SchedCoreError, AuthenticationError } from "schedcore-sdk";
try {
await schedCore.login("[email protected]", "wrong-password");
} catch (error) {
if (error instanceof AuthenticationError) {
console.error("Erreur d'authentification:", error.message);
} else if (error instanceof SchedCoreError) {
console.error("Erreur SchedCore:", error.code, error.message);
} else {
console.error("Erreur inconnue:", error);
}
}Types TypeScript
Le SDK est entièrement typé avec TypeScript. Vous avez accès à tous les types :
import {
User,
Business,
Booking,
Calendar,
Payment,
CreateBookingData,
BookingStatus,
} from "schedcore-sdk";
// Utilisation des types
const bookingData: CreateBookingData = {
businessId: "business_123",
serviceName: "Coupe",
date: "2024-12-20",
startTime: "10:00",
duration: 60,
customerInfo: {
name: "Client",
email: "[email protected]",
},
};Cache et performances
Le SDK gère automatiquement le cache et inclut des mécanismes de retry pour améliorer les performances et la fiabilité.
// Vider le cache
schedCore.clearCache();
// Réinitialiser complètement le SDK
schedCore.reset();Support
Pour toute question ou problème, consultez la documentation complète ou contactez le support technique.
License
MIT
