@travories/frontend-sdk 0.1.2 → 0.1.4
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.d.mts +60 -17
- package/dist/index.d.ts +60 -17
- package/dist/index.js +52 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -314,6 +314,45 @@ var AgenciesResource = class {
|
|
|
314
314
|
}
|
|
315
315
|
};
|
|
316
316
|
|
|
317
|
+
// src/api/bookings.ts
|
|
318
|
+
var BookingsResource = class {
|
|
319
|
+
constructor(http) {
|
|
320
|
+
this.http = http;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Open a booking. The BE returns a booking UUID — combine it with
|
|
324
|
+
* `https://travories.com/package/<id>/payment`
|
|
325
|
+
* to send the user into the existing payment flow.
|
|
326
|
+
*
|
|
327
|
+
* Throws (not silent) so the consumer can surface errors to the user. Wrap
|
|
328
|
+
* in try/catch in your `onReserve` handler.
|
|
329
|
+
*/
|
|
330
|
+
async initiate(payload, options) {
|
|
331
|
+
if (!payload?.packageId) {
|
|
332
|
+
throw new Error("[TravoriesClient] bookings.initiate requires packageId");
|
|
333
|
+
}
|
|
334
|
+
if (!payload?.arrivalDate) {
|
|
335
|
+
throw new Error("[TravoriesClient] bookings.initiate requires arrivalDate");
|
|
336
|
+
}
|
|
337
|
+
if (!payload?.travelers?.length) {
|
|
338
|
+
throw new Error("[TravoriesClient] bookings.initiate requires at least one traveler");
|
|
339
|
+
}
|
|
340
|
+
const res = await this.http.request(
|
|
341
|
+
`/booking/initiate`,
|
|
342
|
+
{
|
|
343
|
+
method: "POST",
|
|
344
|
+
body: payload,
|
|
345
|
+
silent: false,
|
|
346
|
+
...options
|
|
347
|
+
}
|
|
348
|
+
);
|
|
349
|
+
if (!res?.data) {
|
|
350
|
+
throw new Error("[TravoriesClient] bookings.initiate returned no booking id");
|
|
351
|
+
}
|
|
352
|
+
return res;
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
|
|
317
356
|
// src/client/TravoriesClient.ts
|
|
318
357
|
var TravoriesClient = class {
|
|
319
358
|
constructor(config) {
|
|
@@ -326,6 +365,7 @@ var TravoriesClient = class {
|
|
|
326
365
|
this.http = new HttpClient(config);
|
|
327
366
|
this.packages = new PackagesResource(this.http);
|
|
328
367
|
this.agencies = new AgenciesResource(this.http);
|
|
368
|
+
this.bookings = new BookingsResource(this.http);
|
|
329
369
|
}
|
|
330
370
|
};
|
|
331
371
|
function createTravoriesClient(config) {
|
|
@@ -955,16 +995,22 @@ var BookingCardLite = ({
|
|
|
955
995
|
(o) => o.id === id ? { ...o, count: Math.max(0, o.count + (inc ? 1 : -1)) } : o
|
|
956
996
|
)
|
|
957
997
|
);
|
|
998
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
958
999
|
const handleReserve = () => {
|
|
959
1000
|
if (!onReserve) return;
|
|
960
1001
|
if (allPeopleCount === 0) return;
|
|
961
|
-
|
|
1002
|
+
const travelers = options.filter((o) => o.count > 0).map((o) => ({ name: o.name, count: o.count }));
|
|
1003
|
+
const result = onReserve({
|
|
962
1004
|
arrival,
|
|
963
1005
|
departure,
|
|
964
|
-
travelers
|
|
1006
|
+
travelers,
|
|
965
1007
|
totalCost,
|
|
966
1008
|
pricePerPerson: currentPrice
|
|
967
1009
|
});
|
|
1010
|
+
if (result && typeof result.then === "function") {
|
|
1011
|
+
setIsSubmitting(true);
|
|
1012
|
+
result.finally(() => setIsSubmitting(false));
|
|
1013
|
+
}
|
|
968
1014
|
};
|
|
969
1015
|
return /* @__PURE__ */ jsxs("div", { className: "w-full sm:w-full lg:w-[520px] h-fit border rounded-xl shadow-md px-4 sm:px-6 bg-white flex flex-col gap-6 py-8 sm:py-10", children: [
|
|
970
1016
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
@@ -1124,9 +1170,9 @@ var BookingCardLite = ({
|
|
|
1124
1170
|
{
|
|
1125
1171
|
type: "button",
|
|
1126
1172
|
onClick: handleReserve,
|
|
1127
|
-
disabled: allPeopleCount === 0 || !onReserve,
|
|
1173
|
+
disabled: allPeopleCount === 0 || !onReserve || isSubmitting,
|
|
1128
1174
|
className: "w-full py-2 md:py-3 bg-primary-normal text-white font-semibold rounded-lg hover:bg-primary-normal-hover transition text-sm md:text-base disabled:opacity-60 disabled:cursor-not-allowed",
|
|
1129
|
-
children: allPeopleCount === 0 ? "Reserve Now" : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1175
|
+
children: isSubmitting ? "Initiating\u2026" : allPeopleCount === 0 ? "Reserve Now" : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1130
1176
|
"Book Now - ",
|
|
1131
1177
|
formatCurrency(totalCost, currency)
|
|
1132
1178
|
] })
|
|
@@ -2031,7 +2077,7 @@ var DescriptionSection = ({
|
|
|
2031
2077
|
{
|
|
2032
2078
|
DescriptionData,
|
|
2033
2079
|
currency,
|
|
2034
|
-
onReserve: onReserve ? () => onReserve(pkg) : void 0
|
|
2080
|
+
onReserve: onReserve ? (booking) => onReserve({ pkg, ...booking }) : void 0
|
|
2035
2081
|
}
|
|
2036
2082
|
) })
|
|
2037
2083
|
]
|
|
@@ -2739,6 +2785,6 @@ function DefaultLoading2() {
|
|
|
2739
2785
|
] });
|
|
2740
2786
|
}
|
|
2741
2787
|
|
|
2742
|
-
export { AgenciesResource, AgencyAssociations_default as AgencyAssociations, AgencyDetailView, BookingCardLite_default as BookingCardLite, DescriptionSection_default as DescriptionSection, GallerySection_default as GallerySection, HomeSections, HomeSectionsProvider, HostAbout_default as HostAbout, HostCard_default as HostCard, Itinerary_default as Itinerary, PackageCard_default as PackageCard, PackageDetailView, PackageExcludedAndToPack_default as PackageExcludedAndToPack, PackageIncluded_default as PackageIncluded, PackageMap, PackageOverview_default as PackageOverview, PackagesCarousel_default as PackagesCarousel, PackagesResource, PackagesSection_default as PackagesSection, TopSection_default as TopSection, TravoriesApiError, TravoriesClient, buildDescriptionData, buildGalleryMedia, buildTopData, createTravoriesClient, formatCurrency, formatRating, pickImageUrl, startingPrice, useAgencyBundle, useHomeSections, useHomeSectionsContext, usePackageBundle, usePackageBySlug };
|
|
2788
|
+
export { AgenciesResource, AgencyAssociations_default as AgencyAssociations, AgencyDetailView, BookingCardLite_default as BookingCardLite, BookingsResource, DescriptionSection_default as DescriptionSection, GallerySection_default as GallerySection, HomeSections, HomeSectionsProvider, HostAbout_default as HostAbout, HostCard_default as HostCard, Itinerary_default as Itinerary, PackageCard_default as PackageCard, PackageDetailView, PackageExcludedAndToPack_default as PackageExcludedAndToPack, PackageIncluded_default as PackageIncluded, PackageMap, PackageOverview_default as PackageOverview, PackagesCarousel_default as PackagesCarousel, PackagesResource, PackagesSection_default as PackagesSection, TopSection_default as TopSection, TravoriesApiError, TravoriesClient, buildDescriptionData, buildGalleryMedia, buildTopData, createTravoriesClient, formatCurrency, formatRating, pickImageUrl, startingPrice, useAgencyBundle, useHomeSections, useHomeSectionsContext, usePackageBundle, usePackageBySlug };
|
|
2743
2789
|
//# sourceMappingURL=index.mjs.map
|
|
2744
2790
|
//# sourceMappingURL=index.mjs.map
|