@atzentis/booking-sdk 0.1.5 → 0.1.6

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/dist/index.cjs CHANGED
@@ -29,8 +29,11 @@ var index_exports = {};
29
29
  __export(index_exports, {
30
30
  AuthenticationError: () => AuthenticationError,
31
31
  AvailabilityService: () => AvailabilityService,
32
+ BOOKING_STATUSES: () => BOOKING_STATUSES,
33
+ BOOKING_TYPES: () => BOOKING_TYPES,
32
34
  BookingClient: () => BookingClient,
33
35
  BookingError: () => BookingError,
36
+ BookingsService: () => BookingsService,
34
37
  CategoriesService: () => CategoriesService,
35
38
  ConflictError: () => ConflictError,
36
39
  DEFAULT_MODULES: () => DEFAULT_MODULES,
@@ -785,6 +788,244 @@ function minutesToTime(totalMinutes) {
785
788
  return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
786
789
  }
787
790
 
791
+ // src/services/bookings.ts
792
+ var BookingsService = class extends BaseService {
793
+ constructor() {
794
+ super(...arguments);
795
+ this.basePath = "/booking/v1/bookings";
796
+ }
797
+ // ---------------------------------------------------------------------------
798
+ // CRUD
799
+ // ---------------------------------------------------------------------------
800
+ /**
801
+ * Create a new booking.
802
+ *
803
+ * @example
804
+ * ```typescript
805
+ * const booking = await client.bookings.create({
806
+ * propertyId: "prop_abc123",
807
+ * categoryId: "cat_deluxe",
808
+ * guestId: "guest_42",
809
+ * checkIn: "2025-07-01",
810
+ * checkOut: "2025-07-05",
811
+ * type: "stay",
812
+ * guests: 2,
813
+ * autoConfirm: true,
814
+ * });
815
+ * ```
816
+ */
817
+ create(input) {
818
+ return this._post(this.basePath, input);
819
+ }
820
+ /**
821
+ * Get a single booking by ID.
822
+ *
823
+ * @example
824
+ * ```typescript
825
+ * const booking = await client.bookings.get("bk_abc123");
826
+ * ```
827
+ */
828
+ get(bookingId) {
829
+ return this._get(this._buildPath(bookingId));
830
+ }
831
+ /**
832
+ * List bookings for a property with optional filters and cursor-based pagination.
833
+ *
834
+ * Supports filtering by status, type, guest, date ranges, search term,
835
+ * and custom sort order. Array values for `status` and `type` are serialized
836
+ * as comma-separated strings.
837
+ *
838
+ * @example
839
+ * ```typescript
840
+ * // List all confirmed stay bookings
841
+ * const page = await client.bookings.list({
842
+ * propertyId: "prop_abc123",
843
+ * status: "confirmed",
844
+ * type: "stay",
845
+ * });
846
+ *
847
+ * // Multi-status filter with date range
848
+ * const page2 = await client.bookings.list({
849
+ * propertyId: "prop_abc123",
850
+ * status: ["confirmed", "checked_in"],
851
+ * checkInFrom: "2025-07-01",
852
+ * checkInTo: "2025-07-31",
853
+ * sort: { field: "checkIn", direction: "asc" },
854
+ * limit: 20,
855
+ * });
856
+ * ```
857
+ */
858
+ list(params) {
859
+ const query = {
860
+ propertyId: params.propertyId
861
+ };
862
+ if (params.status !== void 0) {
863
+ query.status = Array.isArray(params.status) ? params.status.join(",") : params.status;
864
+ }
865
+ if (params.type !== void 0) {
866
+ query.type = Array.isArray(params.type) ? params.type.join(",") : params.type;
867
+ }
868
+ if (params.guestId !== void 0) query.guestId = params.guestId;
869
+ if (params.checkInFrom !== void 0) query.checkInFrom = params.checkInFrom;
870
+ if (params.checkInTo !== void 0) query.checkInTo = params.checkInTo;
871
+ if (params.checkOutFrom !== void 0) query.checkOutFrom = params.checkOutFrom;
872
+ if (params.checkOutTo !== void 0) query.checkOutTo = params.checkOutTo;
873
+ if (params.search !== void 0) query.search = params.search;
874
+ if (params.sort !== void 0) {
875
+ query.sort = `${params.sort.field}:${params.sort.direction}`;
876
+ }
877
+ if (params.limit !== void 0) query.limit = params.limit;
878
+ if (params.cursor !== void 0) query.cursor = params.cursor;
879
+ return this._get(this.basePath, query);
880
+ }
881
+ /**
882
+ * Update an existing booking.
883
+ *
884
+ * @example
885
+ * ```typescript
886
+ * const updated = await client.bookings.update("bk_abc123", {
887
+ * guests: 3,
888
+ * notes: "Extra bed requested",
889
+ * });
890
+ * ```
891
+ */
892
+ update(bookingId, input) {
893
+ return this._patch(this._buildPath(bookingId), input);
894
+ }
895
+ /**
896
+ * Delete a booking.
897
+ *
898
+ * @example
899
+ * ```typescript
900
+ * await client.bookings.delete("bk_abc123");
901
+ * ```
902
+ */
903
+ delete(bookingId) {
904
+ return this._delete(this._buildPath(bookingId));
905
+ }
906
+ // ---------------------------------------------------------------------------
907
+ // Lifecycle — happy path
908
+ // ---------------------------------------------------------------------------
909
+ /**
910
+ * Confirm a pending booking.
911
+ *
912
+ * Transitions: `pending` → `confirmed`
913
+ *
914
+ * @throws {ConflictError} 409 if the booking is not in `pending` status
915
+ *
916
+ * @example
917
+ * ```typescript
918
+ * const confirmed = await client.bookings.confirm("bk_abc123");
919
+ * // confirmed.status === "confirmed"
920
+ * // confirmed.confirmedAt is populated
921
+ * ```
922
+ */
923
+ confirm(bookingId) {
924
+ return this._post(this._buildPath(bookingId, "confirm"), {});
925
+ }
926
+ /**
927
+ * Check in a guest.
928
+ *
929
+ * Transitions: `confirmed` → `checked_in`
930
+ *
931
+ * @throws {ConflictError} 409 if the booking is not in `confirmed` status
932
+ *
933
+ * @example
934
+ * ```typescript
935
+ * const checkedIn = await client.bookings.checkIn("bk_abc123", {
936
+ * actualArrival: "2025-07-01T14:30:00Z",
937
+ * });
938
+ * // checkedIn.status === "checked_in"
939
+ * // checkedIn.checkedInAt is populated
940
+ * ```
941
+ */
942
+ checkIn(bookingId, input) {
943
+ return this._post(this._buildPath(bookingId, "check-in"), input ?? {});
944
+ }
945
+ /**
946
+ * Check out a guest.
947
+ *
948
+ * Transitions: `checked_in` → `checked_out`
949
+ *
950
+ * @throws {ConflictError} 409 if the booking is not in `checked_in` status
951
+ *
952
+ * @example
953
+ * ```typescript
954
+ * const checkedOut = await client.bookings.checkOut("bk_abc123", {
955
+ * actualDeparture: "2025-07-05T11:00:00Z",
956
+ * });
957
+ * // checkedOut.status === "checked_out"
958
+ * // checkedOut.checkedOutAt is populated
959
+ * ```
960
+ */
961
+ checkOut(bookingId, input) {
962
+ return this._post(this._buildPath(bookingId, "check-out"), input ?? {});
963
+ }
964
+ // ---------------------------------------------------------------------------
965
+ // Lifecycle — alternate endings
966
+ // ---------------------------------------------------------------------------
967
+ /**
968
+ * Cancel a booking.
969
+ *
970
+ * Transitions: `pending` | `confirmed` | `checked_in` → `cancelled`
971
+ *
972
+ * @throws {ConflictError} 409 if the booking is already cancelled, checked out, or no-show
973
+ *
974
+ * @example
975
+ * ```typescript
976
+ * const cancelled = await client.bookings.cancel("bk_abc123", {
977
+ * reason: "Guest requested cancellation",
978
+ * refundRequested: true,
979
+ * });
980
+ * // cancelled.status === "cancelled"
981
+ * // cancelled.cancelledAt is populated
982
+ * // cancelled.cancellationReason === "Guest requested cancellation"
983
+ * ```
984
+ */
985
+ cancel(bookingId, input) {
986
+ return this._post(this._buildPath(bookingId, "cancel"), input);
987
+ }
988
+ /**
989
+ * Mark a booking as no-show.
990
+ *
991
+ * Transitions: `pending` | `confirmed` | `checked_in` → `no_show`
992
+ *
993
+ * @throws {ConflictError} 409 if the booking is already checked out, cancelled, or no-show
994
+ *
995
+ * @example
996
+ * ```typescript
997
+ * const noShow = await client.bookings.noShow("bk_abc123", {
998
+ * chargeNoShowFee: true,
999
+ * });
1000
+ * // noShow.status === "no_show"
1001
+ * // noShow.noShowAt is populated
1002
+ * ```
1003
+ */
1004
+ noShow(bookingId, input) {
1005
+ return this._post(this._buildPath(bookingId, "no-show"), input ?? {});
1006
+ }
1007
+ /**
1008
+ * Assign or reassign a space to a booking.
1009
+ *
1010
+ * Can be called on any active booking (pending, confirmed, checked_in).
1011
+ *
1012
+ * @throws {ConflictError} 409 if the booking is in a terminal status
1013
+ *
1014
+ * @example
1015
+ * ```typescript
1016
+ * const assigned = await client.bookings.assignSpace("bk_abc123", {
1017
+ * spaceId: "spc_room101",
1018
+ * notes: "Upgraded to deluxe",
1019
+ * });
1020
+ * // assigned.spaceId === "spc_room101"
1021
+ * // assigned.space is populated
1022
+ * ```
1023
+ */
1024
+ assignSpace(bookingId, input) {
1025
+ return this._post(this._buildPath(bookingId, "assign-space"), input);
1026
+ }
1027
+ };
1028
+
788
1029
  // src/services/categories.ts
789
1030
  var CategoriesService = class extends BaseService {
790
1031
  constructor() {
@@ -1074,6 +1315,11 @@ var BookingClient = class {
1074
1315
  this._availability ?? (this._availability = new AvailabilityService(this.httpClient));
1075
1316
  return this._availability;
1076
1317
  }
1318
+ /** Bookings service — lazy-initialized on first access */
1319
+ get bookings() {
1320
+ this._bookings ?? (this._bookings = new BookingsService(this.httpClient));
1321
+ return this._bookings;
1322
+ }
1077
1323
  /** Properties service — lazy-initialized on first access */
1078
1324
  get properties() {
1079
1325
  this._properties ?? (this._properties = new PropertiesService(this.httpClient));
@@ -1128,6 +1374,27 @@ async function firstPage(fetcher, options) {
1128
1374
  return fetcher({ ...options ?? {} });
1129
1375
  }
1130
1376
 
1377
+ // src/types/bookings.ts
1378
+ var BOOKING_TYPES = [
1379
+ "stay",
1380
+ "table",
1381
+ "service",
1382
+ "parking",
1383
+ "desk",
1384
+ "meeting",
1385
+ "dayuse",
1386
+ "custom"
1387
+ ];
1388
+ var BOOKING_STATUSES = [
1389
+ "pending",
1390
+ "confirmed",
1391
+ "checked_in",
1392
+ "checked_out",
1393
+ "cancelled",
1394
+ "no_show",
1395
+ "waitlist"
1396
+ ];
1397
+
1131
1398
  // src/types/properties.ts
1132
1399
  var PROPERTY_MODULES = [
1133
1400
  "booking",
@@ -1178,8 +1445,11 @@ var VERSION = "0.1.0";
1178
1445
  0 && (module.exports = {
1179
1446
  AuthenticationError,
1180
1447
  AvailabilityService,
1448
+ BOOKING_STATUSES,
1449
+ BOOKING_TYPES,
1181
1450
  BookingClient,
1182
1451
  BookingError,
1452
+ BookingsService,
1183
1453
  CategoriesService,
1184
1454
  ConflictError,
1185
1455
  DEFAULT_MODULES,