@astratra/booking 1.0.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Astratra
3
+ Copyright (c) 2026 Astratra contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @astratra/booking
2
2
 
3
3
  Prise de rendez-vous : calcul des créneaux libres et réservation **sans
4
- double réservation**. Pour l'accueil d'une entreprise (module Accueil de
5
- Cortex), un salon (Barber Clean), une salle de réunion, un cours collectif.
4
+ double réservation**. Pour l'accueil d'une entreprise (module Accueil d'un
5
+ logiciel de gestion), un salon de coiffure, une salle de réunion, un cours collectif.
6
6
 
7
7
  Aucune dépendance. Les fuseaux horaires passent par `Intl`, inclus dans Node.
8
8
 
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@astratra/booking",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Appointment slot engine without a database: weekly availability per resource, exceptions and public holidays, time zones and daylight saving, service duration, buffers, minimum notice, horizon, capacity, and atomic booking through an injected store (book fails on conflict), cancel and reschedule.",
5
5
  "engines": {
6
- "node": ">=20"
6
+ "node": ">=22"
7
7
  },
8
8
  "main": "src/index.js",
9
9
  "types": "src/index.d.ts",
@@ -13,9 +13,6 @@
13
13
  "README.md",
14
14
  "LICENSE"
15
15
  ],
16
- "scripts": {
17
- "test": "jest --runInBand"
18
- },
19
16
  "jest": {
20
17
  "testMatch": [
21
18
  "**/__tests__/**/*.test.js"
@@ -36,9 +33,12 @@
36
33
  },
37
34
  "devDependencies": {
38
35
  "jest": "30.4.2",
39
- "mongodb-memory-server": "^10.2.0",
40
- "mongoose": "^8.17.0",
36
+ "mongodb-memory-server": "^11.3.0",
37
+ "mongoose": "^9.12.1",
41
38
  "pg": "^8.13.1",
42
39
  "pg-mem": "^3.0.5"
40
+ },
41
+ "scripts": {
42
+ "test": "jest --runInBand"
43
43
  }
44
- }
44
+ }
package/src/service.js CHANGED
@@ -48,7 +48,7 @@ function createBookingService({ store, resources, services = {}, now = () => Dat
48
48
  }
49
49
 
50
50
  function prestation(service) {
51
- const objet = typeof service === 'string' ? services[service] && { id: service, ...services[service] } : service;
51
+ const objet = typeof service === 'string' ? Object.hasOwn(services, service) && services[service] && { id: service, ...services[service] } : service;
52
52
  if (!objet) throw new TypeError(`Prestation inconnue : ${service} (passe l’objet, ou déclare-la dans services).`);
53
53
  return objet;
54
54
  }
@@ -155,7 +155,12 @@ function createBookingService({ store, resources, services = {}, now = () => Dat
155
155
  return reserverSur(resourceIds, demande);
156
156
  }
157
157
 
158
+ /* Un identifiant de rendez-vous est un texte. Un objet venu d'un corps JSON ({ "$ne": null }) serait lu par
159
+ MongoDB comme une condition, et désignerait le rendez-vous de quelqu'un d'autre. */
160
+ const estIdentifiant = (id) => typeof id === 'string' && id.length > 0;
161
+
158
162
  async function existant(id) {
163
+ if (!estIdentifiant(id)) throw new BookingError('BOOKING_NOT_FOUND', 'Rendez-vous introuvable.');
159
164
  const booking = await store.getBooking(id);
160
165
  if (!booking) throw new BookingError('BOOKING_NOT_FOUND', `Rendez-vous introuvable : ${id}`);
161
166
  return booking;
@@ -207,7 +212,7 @@ function createBookingService({ store, resources, services = {}, now = () => Dat
207
212
  });
208
213
  }
209
214
 
210
- return { getSlots, book, cancel, reschedule, getBooking: (id) => store.getBooking(id) };
215
+ return { getSlots, book, cancel, reschedule, getBooking: async (id) => (estIdentifiant(id) ? store.getBooking(id) : null) };
211
216
  }
212
217
 
213
218
  module.exports = { createBookingService, BookingError };
package/src/stores.js CHANGED
@@ -292,6 +292,8 @@ function createMongoBookingStore({ db, prefix = 'booking_', leaseMs = 10000, wai
292
292
  return docs.map(versRdv);
293
293
  },
294
294
  async getBooking(id) {
295
+ /* Un texte seulement : un objet serait une condition MongoDB, pas un identifiant. */
296
+ if (typeof id !== 'string') return null;
295
297
  return versRdv(await rdv().findOne({ _id: id }));
296
298
  }
297
299
  };