more-apartments-astro-integration 1.4.0 → 1.5.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.mjs CHANGED
@@ -92,7 +92,7 @@ var PropertySchema = z.object({
92
92
  zipcode: z.string().nullable(),
93
93
  area: z.string().nullable(),
94
94
  city: z.string(),
95
- country: z.string(),
95
+ country: z.string().nullable(),
96
96
  latitude: z.number(),
97
97
  longitude: z.number(),
98
98
  // Beds
@@ -395,32 +395,136 @@ var BookingSettingsSchema = z.object({
395
395
  }).optional()
396
396
  }).optional()
397
397
  });
398
- var BookingRequestSchema = z.object({
398
+ var BookingDraftRequestSchema = z.object({
399
+ property_id: z.number().int().positive(),
400
+ arrival: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
401
+ departure: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
402
+ amount_adults: z.number().int().min(1),
403
+ amount_children: z.number().int().min(0)
404
+ });
405
+ var BookingDraftResponseSchema = z.object({
406
+ uuid: z.string().uuid(),
407
+ status: z.literal("pending_details"),
408
+ property_id: z.number(),
409
+ arrival: z.string(),
410
+ departure: z.string(),
411
+ amount_adults: z.number(),
412
+ amount_children: z.number(),
413
+ total_price: z.number(),
414
+ nights: z.number(),
415
+ expires_at: z.string(),
416
+ created_at: z.string(),
417
+ updated_at: z.string()
418
+ });
419
+ var PersonalInfoRequestSchema = z.object({
420
+ first_name: z.string().min(1).max(255),
421
+ last_name: z.string().min(1).max(255),
422
+ email: z.string().email().max(255),
423
+ phone: z.string().max(50),
424
+ address_1: z.string().min(1).max(255),
425
+ address_2: z.string().max(255).optional(),
426
+ postal_code: z.string().max(20).optional(),
427
+ city: z.string().min(1).max(100),
428
+ country: z.string().min(1).max(100)
429
+ });
430
+ var BookingDetailsRequestSchema = z.object({
431
+ time_arrival: z.string().regex(/^([01]\d|2[0-3]):([0-5]\d)$/),
432
+ flight: z.string().max(50).optional(),
433
+ notes: z.string().max(1e3).optional()
434
+ });
435
+ var ReviewRequestSchema = z.object({
436
+ terms_accepted: z.boolean().refine((val) => val === true, {
437
+ message: "Terms must be accepted"
438
+ }),
439
+ marketing_consent: z.boolean().optional()
440
+ });
441
+ var PropertySummarySchema = z.object({
442
+ id: z.number(),
443
+ name: z.string(),
444
+ slug: z.string(),
445
+ city: z.string(),
446
+ image: z.string(),
447
+ max_guests: z.number()
448
+ });
449
+ var PriceBreakdownSchema = z.object({
450
+ base_price: z.number(),
451
+ cleaning_fee: z.number(),
452
+ tourist_tax: z.number(),
453
+ vat: z.number(),
454
+ total: z.number()
455
+ });
456
+ var BookingPricingResponseSchema = z.object({
457
+ uuid: z.string().uuid(),
399
458
  property_id: z.number(),
400
- check_in: z.string(),
401
- check_out: z.string(),
402
- guests: z.number(),
403
- first_name: z.string(),
404
- last_name: z.string(),
405
- email: z.string().email(),
406
- phone: z.string().optional(),
407
- notes: z.string().optional(),
408
- total_amount: z.number(),
409
- payment_method: z.enum(["stripe", "cash", "bank_transfer"]).optional()
459
+ arrival: z.string(),
460
+ departure: z.string(),
461
+ amount_adults: z.number(),
462
+ amount_children: z.number(),
463
+ nights: z.number(),
464
+ total_price: z.number(),
465
+ price_per_night: z.number(),
466
+ currency: z.string()
410
467
  });
411
468
  var BookingResponseSchema = z.object({
412
- id: z.string(),
469
+ uuid: z.string().uuid(),
470
+ status: z.enum(["pending_details", "waiting_payment", "fresh", "confirmed", "cancelled", "completed"]),
413
471
  property_id: z.number(),
414
- check_in: z.string(),
415
- check_out: z.string(),
416
- guests: z.number(),
417
- status: z.enum(["pending", "confirmed", "cancelled", "completed"]),
418
- total_amount: z.number(),
419
- payment_status: z.enum(["pending", "paid", "refunded"]),
420
- confirmation_code: z.string(),
472
+ property: PropertySummarySchema.optional(),
473
+ arrival: z.string(),
474
+ departure: z.string(),
475
+ amount_adults: z.number(),
476
+ amount_children: z.number(),
477
+ first_name: z.string().nullish(),
478
+ last_name: z.string().nullish(),
479
+ email: z.string().nullish(),
480
+ phone: z.string().nullish(),
481
+ address_1: z.string().nullish(),
482
+ address_2: z.string().nullish(),
483
+ postal_code: z.string().nullish(),
484
+ city: z.string().nullish(),
485
+ country: z.string().nullish(),
486
+ time_arrival: z.string().nullish(),
487
+ flight: z.string().nullish(),
488
+ notes: z.string().nullish(),
489
+ terms_accepted: z.boolean().nullish(),
490
+ marketing_consent: z.boolean().nullish(),
491
+ total_price: z.number(),
492
+ price_breakdown: PriceBreakdownSchema.optional(),
493
+ nights: z.number(),
494
+ expires_at: z.string().nullish(),
421
495
  created_at: z.string(),
422
496
  updated_at: z.string()
423
497
  });
498
+ var BookingConfirmResponseSchema = z.object({
499
+ message: z.string(),
500
+ data: z.object({
501
+ uuid: z.string().uuid(),
502
+ status: z.enum(["pending_details", "waiting_payment", "fresh", "confirmed", "cancelled", "completed"]),
503
+ property_id: z.number(),
504
+ arrival: z.string(),
505
+ departure: z.string(),
506
+ first_name: z.string(),
507
+ last_name: z.string(),
508
+ email: z.string(),
509
+ phone: z.string(),
510
+ address_1: z.string(),
511
+ address_2: z.string().optional(),
512
+ postal_code: z.string().optional(),
513
+ city: z.string(),
514
+ country: z.string(),
515
+ amount_adults: z.number(),
516
+ amount_children: z.number(),
517
+ time_arrival: z.string(),
518
+ flight: z.string().optional(),
519
+ notes: z.string().optional(),
520
+ external_id: z.string().optional(),
521
+ identifier: z.string().optional(),
522
+ balance_due: z.number(),
523
+ created_at: z.string(),
524
+ updated_at: z.string()
525
+ }),
526
+ stripe_url: z.string().optional()
527
+ });
424
528
  var MoreApartmentsConfigSchema = z.object({
425
529
  baseUrl: z.string().optional(),
426
530
  apiKey: z.string().optional(),
@@ -486,7 +590,6 @@ var MoreApartmentsClient = class {
486
590
  "Content-Type": "application/json",
487
591
  "Accept": "application/json",
488
592
  ...this.config.apiKey && { "Authorization": `Bearer ${this.config.apiKey}` },
489
- ...this.config.instance && { "X-Instance": this.config.instance },
490
593
  ...options.headers
491
594
  };
492
595
  let lastError = null;
@@ -638,23 +741,123 @@ var MoreApartmentsClient = class {
638
741
  const response = await this.fetchWithRetry(url, {}, z.object({ data: BookingSettingsSchema }));
639
742
  return response.data;
640
743
  }
641
- // Booking endpoints
642
- async createBooking(booking) {
643
- const url = `${this.config.baseUrl}/api/v1/bookings`;
744
+ // Booking endpoints - 3-step wizard flow
745
+ /**
746
+ * Create a booking draft with property and dates
747
+ * @param data Draft booking data (property, dates, guests)
748
+ * @returns BookingDraftResponse with UUID and status
749
+ */
750
+ async createBookingDraft(data) {
751
+ const url = `${this.config.baseUrl}/api/v1/bookings/draft`;
644
752
  const response = await this.fetchWithRetry(
645
753
  url,
646
754
  {
647
755
  method: "POST",
648
- body: JSON.stringify(booking)
756
+ body: JSON.stringify(data)
649
757
  },
650
- z.object({ data: BookingResponseSchema })
758
+ BookingDraftResponseSchema
651
759
  );
652
- return response.data;
760
+ return response;
653
761
  }
654
- async getBooking(bookingId) {
655
- const url = `${this.config.baseUrl}/api/v1/bookings/${bookingId}`;
656
- const response = await this.fetchWithRetry(url, {}, z.object({ data: BookingResponseSchema }));
657
- return response.data;
762
+ /**
763
+ * Update booking with personal information (Step 1)
764
+ * @param uuid Booking UUID
765
+ * @param data Personal info (name, email, phone, address)
766
+ * @returns Updated BookingResponse
767
+ */
768
+ async updateBookingStep1(uuid, data) {
769
+ const url = `${this.config.baseUrl}/api/v1/bookings/${uuid}/step-1`;
770
+ const response = await this.fetchWithRetry(
771
+ url,
772
+ {
773
+ method: "PATCH",
774
+ body: JSON.stringify(data)
775
+ },
776
+ BookingResponseSchema
777
+ );
778
+ return response;
779
+ }
780
+ /**
781
+ * Update booking with arrival details (Step 2)
782
+ * @param uuid Booking UUID
783
+ * @param data Arrival time, flight, notes
784
+ * @returns Updated BookingResponse
785
+ */
786
+ async updateBookingStep2(uuid, data) {
787
+ const url = `${this.config.baseUrl}/api/v1/bookings/${uuid}/step-2`;
788
+ const response = await this.fetchWithRetry(
789
+ url,
790
+ {
791
+ method: "PATCH",
792
+ body: JSON.stringify(data)
793
+ },
794
+ BookingResponseSchema
795
+ );
796
+ return response;
797
+ }
798
+ /**
799
+ * Update booking with review data (Step 3)
800
+ * @param uuid Booking UUID
801
+ * @param data Terms acceptance, marketing consent
802
+ * @returns Updated BookingResponse with price breakdown
803
+ */
804
+ async updateBookingStep3(uuid, data) {
805
+ const url = `${this.config.baseUrl}/api/v1/bookings/${uuid}/step-3`;
806
+ const response = await this.fetchWithRetry(
807
+ url,
808
+ {
809
+ method: "PATCH",
810
+ body: JSON.stringify(data)
811
+ },
812
+ BookingResponseSchema
813
+ );
814
+ return response;
815
+ }
816
+ /**
817
+ * Confirm booking and get payment URL
818
+ * @param uuid Booking UUID
819
+ * @param paymentMethod Payment method (stripe, bank_transfer, cash)
820
+ * @returns Confirmation response with payment URL
821
+ */
822
+ async confirmBooking(uuid, paymentMethod = "stripe") {
823
+ const url = `${this.config.baseUrl}/api/v1/bookings/${uuid}/confirm`;
824
+ const response = await this.fetchWithRetry(
825
+ url,
826
+ {
827
+ method: "POST",
828
+ body: JSON.stringify({ payment_method: paymentMethod })
829
+ },
830
+ BookingConfirmResponseSchema
831
+ );
832
+ return response;
833
+ }
834
+ /**
835
+ * Get current booking state
836
+ * @param uuid Booking UUID
837
+ * @returns Full BookingResponse with all data
838
+ */
839
+ async getBookingState(uuid) {
840
+ const url = `${this.config.baseUrl}/api/v1/bookings/${uuid}`;
841
+ const response = await this.fetchWithRetry(
842
+ url,
843
+ { method: "GET" },
844
+ BookingResponseSchema
845
+ );
846
+ return response;
847
+ }
848
+ /**
849
+ * Get pricing details for a booking
850
+ * @param uuid Booking UUID
851
+ * @returns Pricing breakdown with total, per-night rate, and currency
852
+ */
853
+ async getPricing(uuid) {
854
+ const url = `${this.config.baseUrl}/api/v1/bookings/${uuid}/pricing`;
855
+ const response = await this.fetchWithRetry(
856
+ url,
857
+ { method: "GET" },
858
+ BookingPricingResponseSchema
859
+ );
860
+ return response;
658
861
  }
659
862
  /**
660
863
  * Search properties with advanced filtering
@@ -741,26 +944,26 @@ function moreApartmentsIntegration(options) {
741
944
  }) => {
742
945
  let apiKey = options.apiKey;
743
946
  let apiKeySource = "environment variable";
744
- if (options.instancePath && !apiKey) {
947
+ if (options.projectPath && !apiKey) {
745
948
  try {
746
949
  const fs = await import('fs');
747
950
  const path = await import('path');
748
- const resolvedInstancePath = path.resolve(process.cwd(), options.instancePath);
749
- const devKeyPath = path.join(resolvedInstancePath, ".dev-api-key");
750
- if (fs.existsSync(devKeyPath)) {
751
- apiKey = fs.readFileSync(devKeyPath, "utf-8").trim();
752
- apiKeySource = `${path.basename(resolvedInstancePath)}/.dev-api-key`;
951
+ const resolvedProjectPath = path.resolve(process.cwd(), options.projectPath);
952
+ const tokenPath = path.join(resolvedProjectPath, ".headless-token");
953
+ if (fs.existsSync(tokenPath)) {
954
+ apiKey = fs.readFileSync(tokenPath, "utf-8").trim();
955
+ apiKeySource = `.headless-token`;
753
956
  logger.info(`\u2713 Using development API key from ${apiKeySource}`);
754
957
  } else {
755
- logger.warn(`Instance directory configured but .dev-api-key not found. Run: php artisan dev:generate-api-key --instance=${path.basename(resolvedInstancePath)}`);
958
+ logger.warn(`Project directory configured but .headless-token not found at ${resolvedProjectPath}`);
756
959
  }
757
960
  } catch (error) {
758
- logger.debug(`Could not read .dev-api-key: ${error}`);
961
+ logger.debug(`Could not read .headless-token: ${error}`);
759
962
  }
760
963
  } else if (apiKey) {
761
964
  logger.info(`\u2713 Using API key from ${apiKeySource}`);
762
965
  } else {
763
- logger.warn("\u26A0\uFE0F No API key configured. Set MORE_APARTMENTS_API_KEY or configure instancePath for auto-discovery");
966
+ logger.warn("\u26A0\uFE0F No API key configured. Set MORE_APARTMENTS_API_KEY or configure projectPath for auto-discovery");
764
967
  }
765
968
  const clientOptions = { ...options, apiKey };
766
969
  new MoreApartmentsClient(clientOptions);
@@ -1009,6 +1212,6 @@ async function searchProperties(client, params) {
1009
1212
  }
1010
1213
  }
1011
1214
 
1012
- export { ApiErrorSchema, AvailabilitySchema, AvailableDay, BookingRequestSchema, BookingResponseSchema, BookingSettingsSchema, CategorySchema, CategorySegmentSchema, MainSettingsSchema, MoreApartmentsClient, MoreApartmentsConfigSchema, PageSchema, PaginatedResponseSchema, PaginationLinksSchema, PaginationMetaSchema, PostSchema, PropertyImageSchema, PropertyPageSettingsSchema, PropertySchema, PropertySearchParamsSchema, PropertySearchResultSchema, PropertySettingsSchema, ThemeSettingsSchema, moreApartmentsIntegration as default, fetchAvailability, fetchPage, fetchPages, fetchPost, fetchPosts, fetchProperties, fetchProperty, fetchSettings, generateBookingUrl, getAllImageUrls, getAllThumbnailUrls, getImage, getImageCount, getImageWithAlt, getPrimaryImageUrl, getThumbnailUrl, hasImages, searchProperties };
1215
+ export { ApiErrorSchema, AvailabilitySchema, AvailableDay, BookingConfirmResponseSchema, BookingDetailsRequestSchema, BookingDraftRequestSchema, BookingDraftResponseSchema, BookingPricingResponseSchema, BookingResponseSchema, BookingSettingsSchema, CategorySchema, CategorySegmentSchema, MainSettingsSchema, MoreApartmentsClient, MoreApartmentsConfigSchema, PageSchema, PaginatedResponseSchema, PaginationLinksSchema, PaginationMetaSchema, PersonalInfoRequestSchema, PostSchema, PriceBreakdownSchema, PropertyImageSchema, PropertyPageSettingsSchema, PropertySchema, PropertySearchParamsSchema, PropertySearchResultSchema, PropertySettingsSchema, PropertySummarySchema, ReviewRequestSchema, ThemeSettingsSchema, moreApartmentsIntegration as default, fetchAvailability, fetchPage, fetchPages, fetchPost, fetchPosts, fetchProperties, fetchProperty, fetchSettings, generateBookingUrl, getAllImageUrls, getAllThumbnailUrls, getImage, getImageCount, getImageWithAlt, getPrimaryImageUrl, getThumbnailUrl, hasImages, searchProperties };
1013
1216
  //# sourceMappingURL=index.mjs.map
1014
1217
  //# sourceMappingURL=index.mjs.map