@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 +270 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +476 -1
- package/dist/index.d.ts +476 -1
- package/dist/index.js +267 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -736,6 +736,244 @@ function minutesToTime(totalMinutes) {
|
|
|
736
736
|
return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
|
|
737
737
|
}
|
|
738
738
|
|
|
739
|
+
// src/services/bookings.ts
|
|
740
|
+
var BookingsService = class extends BaseService {
|
|
741
|
+
constructor() {
|
|
742
|
+
super(...arguments);
|
|
743
|
+
this.basePath = "/booking/v1/bookings";
|
|
744
|
+
}
|
|
745
|
+
// ---------------------------------------------------------------------------
|
|
746
|
+
// CRUD
|
|
747
|
+
// ---------------------------------------------------------------------------
|
|
748
|
+
/**
|
|
749
|
+
* Create a new booking.
|
|
750
|
+
*
|
|
751
|
+
* @example
|
|
752
|
+
* ```typescript
|
|
753
|
+
* const booking = await client.bookings.create({
|
|
754
|
+
* propertyId: "prop_abc123",
|
|
755
|
+
* categoryId: "cat_deluxe",
|
|
756
|
+
* guestId: "guest_42",
|
|
757
|
+
* checkIn: "2025-07-01",
|
|
758
|
+
* checkOut: "2025-07-05",
|
|
759
|
+
* type: "stay",
|
|
760
|
+
* guests: 2,
|
|
761
|
+
* autoConfirm: true,
|
|
762
|
+
* });
|
|
763
|
+
* ```
|
|
764
|
+
*/
|
|
765
|
+
create(input) {
|
|
766
|
+
return this._post(this.basePath, input);
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Get a single booking by ID.
|
|
770
|
+
*
|
|
771
|
+
* @example
|
|
772
|
+
* ```typescript
|
|
773
|
+
* const booking = await client.bookings.get("bk_abc123");
|
|
774
|
+
* ```
|
|
775
|
+
*/
|
|
776
|
+
get(bookingId) {
|
|
777
|
+
return this._get(this._buildPath(bookingId));
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* List bookings for a property with optional filters and cursor-based pagination.
|
|
781
|
+
*
|
|
782
|
+
* Supports filtering by status, type, guest, date ranges, search term,
|
|
783
|
+
* and custom sort order. Array values for `status` and `type` are serialized
|
|
784
|
+
* as comma-separated strings.
|
|
785
|
+
*
|
|
786
|
+
* @example
|
|
787
|
+
* ```typescript
|
|
788
|
+
* // List all confirmed stay bookings
|
|
789
|
+
* const page = await client.bookings.list({
|
|
790
|
+
* propertyId: "prop_abc123",
|
|
791
|
+
* status: "confirmed",
|
|
792
|
+
* type: "stay",
|
|
793
|
+
* });
|
|
794
|
+
*
|
|
795
|
+
* // Multi-status filter with date range
|
|
796
|
+
* const page2 = await client.bookings.list({
|
|
797
|
+
* propertyId: "prop_abc123",
|
|
798
|
+
* status: ["confirmed", "checked_in"],
|
|
799
|
+
* checkInFrom: "2025-07-01",
|
|
800
|
+
* checkInTo: "2025-07-31",
|
|
801
|
+
* sort: { field: "checkIn", direction: "asc" },
|
|
802
|
+
* limit: 20,
|
|
803
|
+
* });
|
|
804
|
+
* ```
|
|
805
|
+
*/
|
|
806
|
+
list(params) {
|
|
807
|
+
const query = {
|
|
808
|
+
propertyId: params.propertyId
|
|
809
|
+
};
|
|
810
|
+
if (params.status !== void 0) {
|
|
811
|
+
query.status = Array.isArray(params.status) ? params.status.join(",") : params.status;
|
|
812
|
+
}
|
|
813
|
+
if (params.type !== void 0) {
|
|
814
|
+
query.type = Array.isArray(params.type) ? params.type.join(",") : params.type;
|
|
815
|
+
}
|
|
816
|
+
if (params.guestId !== void 0) query.guestId = params.guestId;
|
|
817
|
+
if (params.checkInFrom !== void 0) query.checkInFrom = params.checkInFrom;
|
|
818
|
+
if (params.checkInTo !== void 0) query.checkInTo = params.checkInTo;
|
|
819
|
+
if (params.checkOutFrom !== void 0) query.checkOutFrom = params.checkOutFrom;
|
|
820
|
+
if (params.checkOutTo !== void 0) query.checkOutTo = params.checkOutTo;
|
|
821
|
+
if (params.search !== void 0) query.search = params.search;
|
|
822
|
+
if (params.sort !== void 0) {
|
|
823
|
+
query.sort = `${params.sort.field}:${params.sort.direction}`;
|
|
824
|
+
}
|
|
825
|
+
if (params.limit !== void 0) query.limit = params.limit;
|
|
826
|
+
if (params.cursor !== void 0) query.cursor = params.cursor;
|
|
827
|
+
return this._get(this.basePath, query);
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Update an existing booking.
|
|
831
|
+
*
|
|
832
|
+
* @example
|
|
833
|
+
* ```typescript
|
|
834
|
+
* const updated = await client.bookings.update("bk_abc123", {
|
|
835
|
+
* guests: 3,
|
|
836
|
+
* notes: "Extra bed requested",
|
|
837
|
+
* });
|
|
838
|
+
* ```
|
|
839
|
+
*/
|
|
840
|
+
update(bookingId, input) {
|
|
841
|
+
return this._patch(this._buildPath(bookingId), input);
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Delete a booking.
|
|
845
|
+
*
|
|
846
|
+
* @example
|
|
847
|
+
* ```typescript
|
|
848
|
+
* await client.bookings.delete("bk_abc123");
|
|
849
|
+
* ```
|
|
850
|
+
*/
|
|
851
|
+
delete(bookingId) {
|
|
852
|
+
return this._delete(this._buildPath(bookingId));
|
|
853
|
+
}
|
|
854
|
+
// ---------------------------------------------------------------------------
|
|
855
|
+
// Lifecycle — happy path
|
|
856
|
+
// ---------------------------------------------------------------------------
|
|
857
|
+
/**
|
|
858
|
+
* Confirm a pending booking.
|
|
859
|
+
*
|
|
860
|
+
* Transitions: `pending` → `confirmed`
|
|
861
|
+
*
|
|
862
|
+
* @throws {ConflictError} 409 if the booking is not in `pending` status
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
* ```typescript
|
|
866
|
+
* const confirmed = await client.bookings.confirm("bk_abc123");
|
|
867
|
+
* // confirmed.status === "confirmed"
|
|
868
|
+
* // confirmed.confirmedAt is populated
|
|
869
|
+
* ```
|
|
870
|
+
*/
|
|
871
|
+
confirm(bookingId) {
|
|
872
|
+
return this._post(this._buildPath(bookingId, "confirm"), {});
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Check in a guest.
|
|
876
|
+
*
|
|
877
|
+
* Transitions: `confirmed` → `checked_in`
|
|
878
|
+
*
|
|
879
|
+
* @throws {ConflictError} 409 if the booking is not in `confirmed` status
|
|
880
|
+
*
|
|
881
|
+
* @example
|
|
882
|
+
* ```typescript
|
|
883
|
+
* const checkedIn = await client.bookings.checkIn("bk_abc123", {
|
|
884
|
+
* actualArrival: "2025-07-01T14:30:00Z",
|
|
885
|
+
* });
|
|
886
|
+
* // checkedIn.status === "checked_in"
|
|
887
|
+
* // checkedIn.checkedInAt is populated
|
|
888
|
+
* ```
|
|
889
|
+
*/
|
|
890
|
+
checkIn(bookingId, input) {
|
|
891
|
+
return this._post(this._buildPath(bookingId, "check-in"), input ?? {});
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Check out a guest.
|
|
895
|
+
*
|
|
896
|
+
* Transitions: `checked_in` → `checked_out`
|
|
897
|
+
*
|
|
898
|
+
* @throws {ConflictError} 409 if the booking is not in `checked_in` status
|
|
899
|
+
*
|
|
900
|
+
* @example
|
|
901
|
+
* ```typescript
|
|
902
|
+
* const checkedOut = await client.bookings.checkOut("bk_abc123", {
|
|
903
|
+
* actualDeparture: "2025-07-05T11:00:00Z",
|
|
904
|
+
* });
|
|
905
|
+
* // checkedOut.status === "checked_out"
|
|
906
|
+
* // checkedOut.checkedOutAt is populated
|
|
907
|
+
* ```
|
|
908
|
+
*/
|
|
909
|
+
checkOut(bookingId, input) {
|
|
910
|
+
return this._post(this._buildPath(bookingId, "check-out"), input ?? {});
|
|
911
|
+
}
|
|
912
|
+
// ---------------------------------------------------------------------------
|
|
913
|
+
// Lifecycle — alternate endings
|
|
914
|
+
// ---------------------------------------------------------------------------
|
|
915
|
+
/**
|
|
916
|
+
* Cancel a booking.
|
|
917
|
+
*
|
|
918
|
+
* Transitions: `pending` | `confirmed` | `checked_in` → `cancelled`
|
|
919
|
+
*
|
|
920
|
+
* @throws {ConflictError} 409 if the booking is already cancelled, checked out, or no-show
|
|
921
|
+
*
|
|
922
|
+
* @example
|
|
923
|
+
* ```typescript
|
|
924
|
+
* const cancelled = await client.bookings.cancel("bk_abc123", {
|
|
925
|
+
* reason: "Guest requested cancellation",
|
|
926
|
+
* refundRequested: true,
|
|
927
|
+
* });
|
|
928
|
+
* // cancelled.status === "cancelled"
|
|
929
|
+
* // cancelled.cancelledAt is populated
|
|
930
|
+
* // cancelled.cancellationReason === "Guest requested cancellation"
|
|
931
|
+
* ```
|
|
932
|
+
*/
|
|
933
|
+
cancel(bookingId, input) {
|
|
934
|
+
return this._post(this._buildPath(bookingId, "cancel"), input);
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Mark a booking as no-show.
|
|
938
|
+
*
|
|
939
|
+
* Transitions: `pending` | `confirmed` | `checked_in` → `no_show`
|
|
940
|
+
*
|
|
941
|
+
* @throws {ConflictError} 409 if the booking is already checked out, cancelled, or no-show
|
|
942
|
+
*
|
|
943
|
+
* @example
|
|
944
|
+
* ```typescript
|
|
945
|
+
* const noShow = await client.bookings.noShow("bk_abc123", {
|
|
946
|
+
* chargeNoShowFee: true,
|
|
947
|
+
* });
|
|
948
|
+
* // noShow.status === "no_show"
|
|
949
|
+
* // noShow.noShowAt is populated
|
|
950
|
+
* ```
|
|
951
|
+
*/
|
|
952
|
+
noShow(bookingId, input) {
|
|
953
|
+
return this._post(this._buildPath(bookingId, "no-show"), input ?? {});
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Assign or reassign a space to a booking.
|
|
957
|
+
*
|
|
958
|
+
* Can be called on any active booking (pending, confirmed, checked_in).
|
|
959
|
+
*
|
|
960
|
+
* @throws {ConflictError} 409 if the booking is in a terminal status
|
|
961
|
+
*
|
|
962
|
+
* @example
|
|
963
|
+
* ```typescript
|
|
964
|
+
* const assigned = await client.bookings.assignSpace("bk_abc123", {
|
|
965
|
+
* spaceId: "spc_room101",
|
|
966
|
+
* notes: "Upgraded to deluxe",
|
|
967
|
+
* });
|
|
968
|
+
* // assigned.spaceId === "spc_room101"
|
|
969
|
+
* // assigned.space is populated
|
|
970
|
+
* ```
|
|
971
|
+
*/
|
|
972
|
+
assignSpace(bookingId, input) {
|
|
973
|
+
return this._post(this._buildPath(bookingId, "assign-space"), input);
|
|
974
|
+
}
|
|
975
|
+
};
|
|
976
|
+
|
|
739
977
|
// src/services/categories.ts
|
|
740
978
|
var CategoriesService = class extends BaseService {
|
|
741
979
|
constructor() {
|
|
@@ -1025,6 +1263,11 @@ var BookingClient = class {
|
|
|
1025
1263
|
this._availability ?? (this._availability = new AvailabilityService(this.httpClient));
|
|
1026
1264
|
return this._availability;
|
|
1027
1265
|
}
|
|
1266
|
+
/** Bookings service — lazy-initialized on first access */
|
|
1267
|
+
get bookings() {
|
|
1268
|
+
this._bookings ?? (this._bookings = new BookingsService(this.httpClient));
|
|
1269
|
+
return this._bookings;
|
|
1270
|
+
}
|
|
1028
1271
|
/** Properties service — lazy-initialized on first access */
|
|
1029
1272
|
get properties() {
|
|
1030
1273
|
this._properties ?? (this._properties = new PropertiesService(this.httpClient));
|
|
@@ -1079,6 +1322,27 @@ async function firstPage(fetcher, options) {
|
|
|
1079
1322
|
return fetcher({ ...options ?? {} });
|
|
1080
1323
|
}
|
|
1081
1324
|
|
|
1325
|
+
// src/types/bookings.ts
|
|
1326
|
+
var BOOKING_TYPES = [
|
|
1327
|
+
"stay",
|
|
1328
|
+
"table",
|
|
1329
|
+
"service",
|
|
1330
|
+
"parking",
|
|
1331
|
+
"desk",
|
|
1332
|
+
"meeting",
|
|
1333
|
+
"dayuse",
|
|
1334
|
+
"custom"
|
|
1335
|
+
];
|
|
1336
|
+
var BOOKING_STATUSES = [
|
|
1337
|
+
"pending",
|
|
1338
|
+
"confirmed",
|
|
1339
|
+
"checked_in",
|
|
1340
|
+
"checked_out",
|
|
1341
|
+
"cancelled",
|
|
1342
|
+
"no_show",
|
|
1343
|
+
"waitlist"
|
|
1344
|
+
];
|
|
1345
|
+
|
|
1082
1346
|
// src/types/properties.ts
|
|
1083
1347
|
var PROPERTY_MODULES = [
|
|
1084
1348
|
"booking",
|
|
@@ -1128,8 +1392,11 @@ var VERSION = "0.1.0";
|
|
|
1128
1392
|
export {
|
|
1129
1393
|
AuthenticationError,
|
|
1130
1394
|
AvailabilityService,
|
|
1395
|
+
BOOKING_STATUSES,
|
|
1396
|
+
BOOKING_TYPES,
|
|
1131
1397
|
BookingClient,
|
|
1132
1398
|
BookingError,
|
|
1399
|
+
BookingsService,
|
|
1133
1400
|
CategoriesService,
|
|
1134
1401
|
ConflictError,
|
|
1135
1402
|
DEFAULT_MODULES,
|