@travories/frontend-sdk 0.1.2 → 0.1.3

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 CHANGED
@@ -215,6 +215,24 @@ interface AgencyBundle {
215
215
  associations: AgencyAssociationItem[];
216
216
  packages: HomePackageCard[];
217
217
  }
218
+ /** One row in the booking's traveler breakdown. `name` is the category label. */
219
+ interface BookingTraveler {
220
+ /** "Adult" | "Senior Citizen" | "Children" | "Infant" */
221
+ name: string;
222
+ count: number;
223
+ }
224
+ interface BookingInitiateRequest {
225
+ /** Package slug (NOT the package UUID — the BE looks it up by slug). */
226
+ packageId: string;
227
+ /** ISO date string, e.g. "2027-08-15". */
228
+ arrivalDate: string;
229
+ travelers: BookingTraveler[];
230
+ }
231
+ interface BookingInitiateResponse {
232
+ message: string;
233
+ /** Booking UUID. Used to build the payment URL: `/package/<data>/payment`. */
234
+ data: string;
235
+ }
218
236
 
219
237
  declare class PackagesResource {
220
238
  private http;
@@ -268,6 +286,24 @@ declare class AgenciesResource {
268
286
  }, options?: HttpRequestOptions): Promise<AgencyBundle | null>;
269
287
  }
270
288
 
289
+ /**
290
+ * Booking-related endpoints. Currently exposes the kickoff step (`initiate`);
291
+ * the rest of the flow (payment, confirmation) lives on travories.com today.
292
+ */
293
+ declare class BookingsResource {
294
+ private http;
295
+ constructor(http: HttpClient);
296
+ /**
297
+ * Open a booking. The BE returns a booking UUID — combine it with
298
+ * `https://travories.com/package/<id>/payment`
299
+ * to send the user into the existing payment flow.
300
+ *
301
+ * Throws (not silent) so the consumer can surface errors to the user. Wrap
302
+ * in try/catch in your `onReserve` handler.
303
+ */
304
+ initiate(payload: BookingInitiateRequest, options?: HttpRequestOptions): Promise<BookingInitiateResponse>;
305
+ }
306
+
271
307
  interface TravoriesClientConfig extends HttpClientConfig {
272
308
  }
273
309
  /**
@@ -288,6 +324,7 @@ declare class TravoriesClient {
288
324
  private http;
289
325
  packages: PackagesResource;
290
326
  agencies: AgenciesResource;
327
+ bookings: BookingsResource;
291
328
  constructor(config: TravoriesClientConfig);
292
329
  getPackageBySlug: (slug: string) => Promise<TravoriesPackage | null>;
293
330
  getPackageBundle: (slug: string) => Promise<PackageBundle | null>;
@@ -707,14 +744,15 @@ interface BookingCardLiteProps {
707
744
  DescriptionData: DescriptionData;
708
745
  currency?: string;
709
746
  /** Called when user clicks Book/Reserve. Receives the picked values so the
710
- * consumer can wire their own booking flow. */
747
+ * consumer can wire their own booking flow. Return a `Promise` to make the
748
+ * button show an "Initiating…" state until it resolves. */
711
749
  onReserve?: (payload: {
712
750
  arrival: string;
713
751
  departure: string;
714
752
  travelers: TravelerOption[];
715
753
  totalCost: number;
716
754
  pricePerPerson: number;
717
- }) => void;
755
+ }) => void | Promise<void>;
718
756
  }
719
757
  /**
720
758
  * High-fidelity port of frontend `BookingForm.tsx` — visual only.
@@ -781,4 +819,4 @@ declare function startingPrice(prices: PackagePriceTier[] | undefined): number;
781
819
  declare function formatCurrency(amount: number, currency?: string): string;
782
820
  declare function formatRating(rating: number | undefined): string;
783
821
 
784
- export { AgenciesResource, type AgencyAssociationItem, AgencyAssociations, type AgencyBundle, AgencyDetailView, type AgencyDetailViewProps, type AgencyHostDetails, type AgencyHostResponse, BookingCardLite, type DescriptionData, DescriptionSection, GallerySection, type HomePackageCard, type HomeSectionKey, HomeSections, type HomeSectionsContextValue, type HomeSectionsProps, HomeSectionsProvider, type HomeSectionsProviderProps, type HomeSectionsResponse, HostAbout, HostCard, type HttpClientConfig, type HttpRequestOptions, Itinerary, type MajorAttractionItem, type MajorAttractionsResponse, type MediaItem, type PackageBundle, PackageCard, type PackageDay, type PackageDayLocation, PackageDetailView, type PackageDetailViewProps, type PackageDiscount, PackageExcludedAndToPack, type PackageHost, type PackageHostResponse, PackageIncluded, PackageMap, PackageOverview, type PackagePriceTier, type PackageRoute, type PackageRouteGeometry, type PackageRoutesDay, type PackageRoutesResponse, PackagesCarousel, PackagesResource, PackagesSection, type PackagesSectionProps, type ThingItem, type TopData, TopSection, TravoriesApiError, TravoriesClient, type TravoriesClientConfig, type TravoriesImage, type TravoriesImageUrls, type TravoriesPackage, type UseAgencyBundleResult, type UseHomeSectionsResult, type UsePackageBundleResult, type UsePackageBySlugResult, buildDescriptionData, buildGalleryMedia, buildTopData, createTravoriesClient, formatCurrency, formatRating, pickImageUrl, startingPrice, useAgencyBundle, useHomeSections, useHomeSectionsContext, usePackageBundle, usePackageBySlug };
822
+ export { AgenciesResource, type AgencyAssociationItem, AgencyAssociations, type AgencyBundle, AgencyDetailView, type AgencyDetailViewProps, type AgencyHostDetails, type AgencyHostResponse, BookingCardLite, type BookingInitiateRequest, type BookingInitiateResponse, type BookingTraveler, BookingsResource, type DescriptionData, DescriptionSection, GallerySection, type HomePackageCard, type HomeSectionKey, HomeSections, type HomeSectionsContextValue, type HomeSectionsProps, HomeSectionsProvider, type HomeSectionsProviderProps, type HomeSectionsResponse, HostAbout, HostCard, type HttpClientConfig, type HttpRequestOptions, Itinerary, type MajorAttractionItem, type MajorAttractionsResponse, type MediaItem, type PackageBundle, PackageCard, type PackageDay, type PackageDayLocation, PackageDetailView, type PackageDetailViewProps, type PackageDiscount, PackageExcludedAndToPack, type PackageHost, type PackageHostResponse, PackageIncluded, PackageMap, PackageOverview, type PackagePriceTier, type PackageRoute, type PackageRouteGeometry, type PackageRoutesDay, type PackageRoutesResponse, PackagesCarousel, PackagesResource, PackagesSection, type PackagesSectionProps, type ThingItem, type TopData, TopSection, TravoriesApiError, TravoriesClient, type TravoriesClientConfig, type TravoriesImage, type TravoriesImageUrls, type TravoriesPackage, type UseAgencyBundleResult, type UseHomeSectionsResult, type UsePackageBundleResult, type UsePackageBySlugResult, buildDescriptionData, buildGalleryMedia, buildTopData, createTravoriesClient, formatCurrency, formatRating, pickImageUrl, startingPrice, useAgencyBundle, useHomeSections, useHomeSectionsContext, usePackageBundle, usePackageBySlug };
package/dist/index.d.ts CHANGED
@@ -215,6 +215,24 @@ interface AgencyBundle {
215
215
  associations: AgencyAssociationItem[];
216
216
  packages: HomePackageCard[];
217
217
  }
218
+ /** One row in the booking's traveler breakdown. `name` is the category label. */
219
+ interface BookingTraveler {
220
+ /** "Adult" | "Senior Citizen" | "Children" | "Infant" */
221
+ name: string;
222
+ count: number;
223
+ }
224
+ interface BookingInitiateRequest {
225
+ /** Package slug (NOT the package UUID — the BE looks it up by slug). */
226
+ packageId: string;
227
+ /** ISO date string, e.g. "2027-08-15". */
228
+ arrivalDate: string;
229
+ travelers: BookingTraveler[];
230
+ }
231
+ interface BookingInitiateResponse {
232
+ message: string;
233
+ /** Booking UUID. Used to build the payment URL: `/package/<data>/payment`. */
234
+ data: string;
235
+ }
218
236
 
219
237
  declare class PackagesResource {
220
238
  private http;
@@ -268,6 +286,24 @@ declare class AgenciesResource {
268
286
  }, options?: HttpRequestOptions): Promise<AgencyBundle | null>;
269
287
  }
270
288
 
289
+ /**
290
+ * Booking-related endpoints. Currently exposes the kickoff step (`initiate`);
291
+ * the rest of the flow (payment, confirmation) lives on travories.com today.
292
+ */
293
+ declare class BookingsResource {
294
+ private http;
295
+ constructor(http: HttpClient);
296
+ /**
297
+ * Open a booking. The BE returns a booking UUID — combine it with
298
+ * `https://travories.com/package/<id>/payment`
299
+ * to send the user into the existing payment flow.
300
+ *
301
+ * Throws (not silent) so the consumer can surface errors to the user. Wrap
302
+ * in try/catch in your `onReserve` handler.
303
+ */
304
+ initiate(payload: BookingInitiateRequest, options?: HttpRequestOptions): Promise<BookingInitiateResponse>;
305
+ }
306
+
271
307
  interface TravoriesClientConfig extends HttpClientConfig {
272
308
  }
273
309
  /**
@@ -288,6 +324,7 @@ declare class TravoriesClient {
288
324
  private http;
289
325
  packages: PackagesResource;
290
326
  agencies: AgenciesResource;
327
+ bookings: BookingsResource;
291
328
  constructor(config: TravoriesClientConfig);
292
329
  getPackageBySlug: (slug: string) => Promise<TravoriesPackage | null>;
293
330
  getPackageBundle: (slug: string) => Promise<PackageBundle | null>;
@@ -707,14 +744,15 @@ interface BookingCardLiteProps {
707
744
  DescriptionData: DescriptionData;
708
745
  currency?: string;
709
746
  /** Called when user clicks Book/Reserve. Receives the picked values so the
710
- * consumer can wire their own booking flow. */
747
+ * consumer can wire their own booking flow. Return a `Promise` to make the
748
+ * button show an "Initiating…" state until it resolves. */
711
749
  onReserve?: (payload: {
712
750
  arrival: string;
713
751
  departure: string;
714
752
  travelers: TravelerOption[];
715
753
  totalCost: number;
716
754
  pricePerPerson: number;
717
- }) => void;
755
+ }) => void | Promise<void>;
718
756
  }
719
757
  /**
720
758
  * High-fidelity port of frontend `BookingForm.tsx` — visual only.
@@ -781,4 +819,4 @@ declare function startingPrice(prices: PackagePriceTier[] | undefined): number;
781
819
  declare function formatCurrency(amount: number, currency?: string): string;
782
820
  declare function formatRating(rating: number | undefined): string;
783
821
 
784
- export { AgenciesResource, type AgencyAssociationItem, AgencyAssociations, type AgencyBundle, AgencyDetailView, type AgencyDetailViewProps, type AgencyHostDetails, type AgencyHostResponse, BookingCardLite, type DescriptionData, DescriptionSection, GallerySection, type HomePackageCard, type HomeSectionKey, HomeSections, type HomeSectionsContextValue, type HomeSectionsProps, HomeSectionsProvider, type HomeSectionsProviderProps, type HomeSectionsResponse, HostAbout, HostCard, type HttpClientConfig, type HttpRequestOptions, Itinerary, type MajorAttractionItem, type MajorAttractionsResponse, type MediaItem, type PackageBundle, PackageCard, type PackageDay, type PackageDayLocation, PackageDetailView, type PackageDetailViewProps, type PackageDiscount, PackageExcludedAndToPack, type PackageHost, type PackageHostResponse, PackageIncluded, PackageMap, PackageOverview, type PackagePriceTier, type PackageRoute, type PackageRouteGeometry, type PackageRoutesDay, type PackageRoutesResponse, PackagesCarousel, PackagesResource, PackagesSection, type PackagesSectionProps, type ThingItem, type TopData, TopSection, TravoriesApiError, TravoriesClient, type TravoriesClientConfig, type TravoriesImage, type TravoriesImageUrls, type TravoriesPackage, type UseAgencyBundleResult, type UseHomeSectionsResult, type UsePackageBundleResult, type UsePackageBySlugResult, buildDescriptionData, buildGalleryMedia, buildTopData, createTravoriesClient, formatCurrency, formatRating, pickImageUrl, startingPrice, useAgencyBundle, useHomeSections, useHomeSectionsContext, usePackageBundle, usePackageBySlug };
822
+ export { AgenciesResource, type AgencyAssociationItem, AgencyAssociations, type AgencyBundle, AgencyDetailView, type AgencyDetailViewProps, type AgencyHostDetails, type AgencyHostResponse, BookingCardLite, type BookingInitiateRequest, type BookingInitiateResponse, type BookingTraveler, BookingsResource, type DescriptionData, DescriptionSection, GallerySection, type HomePackageCard, type HomeSectionKey, HomeSections, type HomeSectionsContextValue, type HomeSectionsProps, HomeSectionsProvider, type HomeSectionsProviderProps, type HomeSectionsResponse, HostAbout, HostCard, type HttpClientConfig, type HttpRequestOptions, Itinerary, type MajorAttractionItem, type MajorAttractionsResponse, type MediaItem, type PackageBundle, PackageCard, type PackageDay, type PackageDayLocation, PackageDetailView, type PackageDetailViewProps, type PackageDiscount, PackageExcludedAndToPack, type PackageHost, type PackageHostResponse, PackageIncluded, PackageMap, PackageOverview, type PackagePriceTier, type PackageRoute, type PackageRouteGeometry, type PackageRoutesDay, type PackageRoutesResponse, PackagesCarousel, PackagesResource, PackagesSection, type PackagesSectionProps, type ThingItem, type TopData, TopSection, TravoriesApiError, TravoriesClient, type TravoriesClientConfig, type TravoriesImage, type TravoriesImageUrls, type TravoriesPackage, type UseAgencyBundleResult, type UseHomeSectionsResult, type UsePackageBundleResult, type UsePackageBySlugResult, buildDescriptionData, buildGalleryMedia, buildTopData, createTravoriesClient, formatCurrency, formatRating, pickImageUrl, startingPrice, useAgencyBundle, useHomeSections, useHomeSectionsContext, usePackageBundle, usePackageBySlug };
package/dist/index.js CHANGED
@@ -316,6 +316,45 @@ var AgenciesResource = class {
316
316
  }
317
317
  };
318
318
 
319
+ // src/api/bookings.ts
320
+ var BookingsResource = class {
321
+ constructor(http) {
322
+ this.http = http;
323
+ }
324
+ /**
325
+ * Open a booking. The BE returns a booking UUID — combine it with
326
+ * `https://travories.com/package/<id>/payment`
327
+ * to send the user into the existing payment flow.
328
+ *
329
+ * Throws (not silent) so the consumer can surface errors to the user. Wrap
330
+ * in try/catch in your `onReserve` handler.
331
+ */
332
+ async initiate(payload, options) {
333
+ if (!payload?.packageId) {
334
+ throw new Error("[TravoriesClient] bookings.initiate requires packageId");
335
+ }
336
+ if (!payload?.arrivalDate) {
337
+ throw new Error("[TravoriesClient] bookings.initiate requires arrivalDate");
338
+ }
339
+ if (!payload?.travelers?.length) {
340
+ throw new Error("[TravoriesClient] bookings.initiate requires at least one traveler");
341
+ }
342
+ const res = await this.http.request(
343
+ `/booking/initiate`,
344
+ {
345
+ method: "POST",
346
+ body: payload,
347
+ silent: false,
348
+ ...options
349
+ }
350
+ );
351
+ if (!res?.data) {
352
+ throw new Error("[TravoriesClient] bookings.initiate returned no booking id");
353
+ }
354
+ return res;
355
+ }
356
+ };
357
+
319
358
  // src/client/TravoriesClient.ts
320
359
  var TravoriesClient = class {
321
360
  constructor(config) {
@@ -328,6 +367,7 @@ var TravoriesClient = class {
328
367
  this.http = new HttpClient(config);
329
368
  this.packages = new PackagesResource(this.http);
330
369
  this.agencies = new AgenciesResource(this.http);
370
+ this.bookings = new BookingsResource(this.http);
331
371
  }
332
372
  };
333
373
  function createTravoriesClient(config) {
@@ -957,16 +997,21 @@ var BookingCardLite = ({
957
997
  (o) => o.id === id ? { ...o, count: Math.max(0, o.count + (inc ? 1 : -1)) } : o
958
998
  )
959
999
  );
1000
+ const [isSubmitting, setIsSubmitting] = react.useState(false);
960
1001
  const handleReserve = () => {
961
1002
  if (!onReserve) return;
962
1003
  if (allPeopleCount === 0) return;
963
- onReserve({
1004
+ const result = onReserve({
964
1005
  arrival,
965
1006
  departure,
966
1007
  travelers: options.filter((o) => o.count > 0),
967
1008
  totalCost,
968
1009
  pricePerPerson: currentPrice
969
1010
  });
1011
+ if (result && typeof result.then === "function") {
1012
+ setIsSubmitting(true);
1013
+ result.finally(() => setIsSubmitting(false));
1014
+ }
970
1015
  };
971
1016
  return /* @__PURE__ */ jsxRuntime.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: [
972
1017
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
@@ -1126,9 +1171,9 @@ var BookingCardLite = ({
1126
1171
  {
1127
1172
  type: "button",
1128
1173
  onClick: handleReserve,
1129
- disabled: allPeopleCount === 0 || !onReserve,
1174
+ disabled: allPeopleCount === 0 || !onReserve || isSubmitting,
1130
1175
  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",
1131
- children: allPeopleCount === 0 ? "Reserve Now" : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1176
+ children: isSubmitting ? "Initiating\u2026" : allPeopleCount === 0 ? "Reserve Now" : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1132
1177
  "Book Now - ",
1133
1178
  formatCurrency(totalCost, currency)
1134
1179
  ] })
@@ -2745,6 +2790,7 @@ exports.AgenciesResource = AgenciesResource;
2745
2790
  exports.AgencyAssociations = AgencyAssociations_default;
2746
2791
  exports.AgencyDetailView = AgencyDetailView;
2747
2792
  exports.BookingCardLite = BookingCardLite_default;
2793
+ exports.BookingsResource = BookingsResource;
2748
2794
  exports.DescriptionSection = DescriptionSection_default;
2749
2795
  exports.GallerySection = GallerySection_default;
2750
2796
  exports.HomeSections = HomeSections;