more-apartments-astro-integration 1.4.1 → 1.5.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/cli/index.js CHANGED
@@ -6,7 +6,6 @@ var dotenv = require('dotenv');
6
6
  var path = require('path');
7
7
  var zod = require('zod');
8
8
  var util = require('util');
9
- var fs = require('fs');
10
9
 
11
10
  var PaginationLinksSchema = zod.z.object({
12
11
  first: zod.z.string().nullable(),
@@ -99,7 +98,7 @@ var PropertySchema = zod.z.object({
99
98
  zipcode: zod.z.string().nullable(),
100
99
  area: zod.z.string().nullable(),
101
100
  city: zod.z.string(),
102
- country: zod.z.string(),
101
+ country: zod.z.string().nullable(),
103
102
  latitude: zod.z.number(),
104
103
  longitude: zod.z.number(),
105
104
  // Beds
@@ -403,31 +402,135 @@ var BookingSettingsSchema = zod.z.object({
403
402
  }).optional()
404
403
  });
405
404
  zod.z.object({
405
+ property_id: zod.z.number().int().positive(),
406
+ arrival: zod.z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
407
+ departure: zod.z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
408
+ amount_adults: zod.z.number().int().min(1),
409
+ amount_children: zod.z.number().int().min(0)
410
+ });
411
+ var BookingDraftResponseSchema = zod.z.object({
412
+ uuid: zod.z.string().uuid(),
413
+ status: zod.z.literal("pending_details"),
406
414
  property_id: zod.z.number(),
407
- check_in: zod.z.string(),
408
- check_out: zod.z.string(),
409
- guests: zod.z.number(),
410
- first_name: zod.z.string(),
411
- last_name: zod.z.string(),
412
- email: zod.z.string().email(),
413
- phone: zod.z.string().optional(),
414
- notes: zod.z.string().optional(),
415
- total_amount: zod.z.number(),
416
- payment_method: zod.z.enum(["stripe", "cash", "bank_transfer"]).optional()
415
+ arrival: zod.z.string(),
416
+ departure: zod.z.string(),
417
+ amount_adults: zod.z.number(),
418
+ amount_children: zod.z.number(),
419
+ total_price: zod.z.number(),
420
+ nights: zod.z.number(),
421
+ expires_at: zod.z.string(),
422
+ created_at: zod.z.string(),
423
+ updated_at: zod.z.string()
424
+ });
425
+ zod.z.object({
426
+ first_name: zod.z.string().min(1).max(255),
427
+ last_name: zod.z.string().min(1).max(255),
428
+ email: zod.z.string().email().max(255),
429
+ phone: zod.z.string().max(50),
430
+ address_1: zod.z.string().min(1).max(255),
431
+ address_2: zod.z.string().max(255).optional(),
432
+ postal_code: zod.z.string().max(20).optional(),
433
+ city: zod.z.string().min(1).max(100),
434
+ country: zod.z.string().min(1).max(100)
435
+ });
436
+ zod.z.object({
437
+ time_arrival: zod.z.string().regex(/^([01]\d|2[0-3]):([0-5]\d)$/),
438
+ flight: zod.z.string().max(50).optional(),
439
+ notes: zod.z.string().max(1e3).optional()
440
+ });
441
+ zod.z.object({
442
+ terms_accepted: zod.z.boolean().refine((val) => val === true, {
443
+ message: "Terms must be accepted"
444
+ }),
445
+ marketing_consent: zod.z.boolean().optional()
446
+ });
447
+ var PropertySummarySchema = zod.z.object({
448
+ id: zod.z.number(),
449
+ name: zod.z.string(),
450
+ slug: zod.z.string(),
451
+ city: zod.z.string(),
452
+ image: zod.z.string(),
453
+ max_guests: zod.z.number()
454
+ });
455
+ var PriceBreakdownSchema = zod.z.object({
456
+ base_price: zod.z.number(),
457
+ cleaning_fee: zod.z.number(),
458
+ tourist_tax: zod.z.number(),
459
+ vat: zod.z.number(),
460
+ total: zod.z.number()
461
+ });
462
+ var BookingPricingResponseSchema = zod.z.object({
463
+ uuid: zod.z.string().uuid(),
464
+ property_id: zod.z.number(),
465
+ arrival: zod.z.string(),
466
+ departure: zod.z.string(),
467
+ amount_adults: zod.z.number(),
468
+ amount_children: zod.z.number(),
469
+ nights: zod.z.number(),
470
+ total_price: zod.z.number(),
471
+ price_per_night: zod.z.number(),
472
+ currency: zod.z.string()
417
473
  });
418
474
  var BookingResponseSchema = zod.z.object({
419
- id: zod.z.string(),
475
+ uuid: zod.z.string().uuid(),
476
+ status: zod.z.enum(["pending_details", "waiting_payment", "fresh", "confirmed", "cancelled", "completed"]),
420
477
  property_id: zod.z.number(),
421
- check_in: zod.z.string(),
422
- check_out: zod.z.string(),
423
- guests: zod.z.number(),
424
- status: zod.z.enum(["pending", "confirmed", "cancelled", "completed"]),
425
- total_amount: zod.z.number(),
426
- payment_status: zod.z.enum(["pending", "paid", "refunded"]),
427
- confirmation_code: zod.z.string(),
478
+ property: PropertySummarySchema.optional(),
479
+ arrival: zod.z.string(),
480
+ departure: zod.z.string(),
481
+ amount_adults: zod.z.number(),
482
+ amount_children: zod.z.number(),
483
+ first_name: zod.z.string().nullish(),
484
+ last_name: zod.z.string().nullish(),
485
+ email: zod.z.string().nullish(),
486
+ phone: zod.z.string().nullish(),
487
+ address_1: zod.z.string().nullish(),
488
+ address_2: zod.z.string().nullish(),
489
+ postal_code: zod.z.string().nullish(),
490
+ city: zod.z.string().nullish(),
491
+ country: zod.z.string().nullish(),
492
+ time_arrival: zod.z.string().nullish(),
493
+ flight: zod.z.string().nullish(),
494
+ notes: zod.z.string().nullish(),
495
+ terms_accepted: zod.z.boolean().nullish(),
496
+ marketing_consent: zod.z.boolean().nullish(),
497
+ total_price: zod.z.number(),
498
+ price_breakdown: PriceBreakdownSchema.optional(),
499
+ nights: zod.z.number(),
500
+ expires_at: zod.z.string().nullish(),
428
501
  created_at: zod.z.string(),
429
502
  updated_at: zod.z.string()
430
503
  });
504
+ var BookingConfirmResponseSchema = zod.z.object({
505
+ message: zod.z.string(),
506
+ data: zod.z.object({
507
+ uuid: zod.z.string().uuid(),
508
+ status: zod.z.enum(["pending_details", "waiting_payment", "fresh", "confirmed", "cancelled", "completed"]),
509
+ property_id: zod.z.number(),
510
+ arrival: zod.z.string(),
511
+ departure: zod.z.string(),
512
+ first_name: zod.z.string(),
513
+ last_name: zod.z.string(),
514
+ email: zod.z.string(),
515
+ phone: zod.z.string(),
516
+ address_1: zod.z.string(),
517
+ address_2: zod.z.string().optional(),
518
+ postal_code: zod.z.string().optional(),
519
+ city: zod.z.string(),
520
+ country: zod.z.string(),
521
+ amount_adults: zod.z.number(),
522
+ amount_children: zod.z.number(),
523
+ time_arrival: zod.z.string(),
524
+ flight: zod.z.string().optional(),
525
+ notes: zod.z.string().optional(),
526
+ external_id: zod.z.string().optional(),
527
+ identifier: zod.z.string().optional(),
528
+ balance_due: zod.z.number(),
529
+ created_at: zod.z.string(),
530
+ updated_at: zod.z.string()
531
+ }),
532
+ stripe_url: zod.z.string().optional()
533
+ });
431
534
  zod.z.object({
432
535
  baseUrl: zod.z.string().optional(),
433
536
  apiKey: zod.z.string().optional(),
@@ -493,7 +596,6 @@ var MoreApartmentsClient = class {
493
596
  "Content-Type": "application/json",
494
597
  "Accept": "application/json",
495
598
  ...this.config.apiKey && { "Authorization": `Bearer ${this.config.apiKey}` },
496
- ...this.config.instance && { "X-Instance": this.config.instance },
497
599
  ...options.headers
498
600
  };
499
601
  let lastError = null;
@@ -532,7 +634,7 @@ var MoreApartmentsClient = class {
532
634
  } catch (error) {
533
635
  lastError = error;
534
636
  if (attempt < (this.config.retry?.attempts ?? 3) - 1) {
535
- await new Promise((resolve3) => setTimeout(resolve3, (this.config.retry?.delay ?? 1e3) * (attempt + 1)));
637
+ await new Promise((resolve2) => setTimeout(resolve2, (this.config.retry?.delay ?? 1e3) * (attempt + 1)));
536
638
  }
537
639
  }
538
640
  }
@@ -645,23 +747,123 @@ var MoreApartmentsClient = class {
645
747
  const response = await this.fetchWithRetry(url, {}, zod.z.object({ data: BookingSettingsSchema }));
646
748
  return response.data;
647
749
  }
648
- // Booking endpoints
649
- async createBooking(booking) {
650
- const url = `${this.config.baseUrl}/api/v1/bookings`;
750
+ // Booking endpoints - 3-step wizard flow
751
+ /**
752
+ * Create a booking draft with property and dates
753
+ * @param data Draft booking data (property, dates, guests)
754
+ * @returns BookingDraftResponse with UUID and status
755
+ */
756
+ async createBookingDraft(data) {
757
+ const url = `${this.config.baseUrl}/api/v1/bookings/draft`;
651
758
  const response = await this.fetchWithRetry(
652
759
  url,
653
760
  {
654
761
  method: "POST",
655
- body: JSON.stringify(booking)
762
+ body: JSON.stringify(data)
656
763
  },
657
- zod.z.object({ data: BookingResponseSchema })
764
+ BookingDraftResponseSchema
658
765
  );
659
- return response.data;
766
+ return response;
660
767
  }
661
- async getBooking(bookingId) {
662
- const url = `${this.config.baseUrl}/api/v1/bookings/${bookingId}`;
663
- const response = await this.fetchWithRetry(url, {}, zod.z.object({ data: BookingResponseSchema }));
664
- return response.data;
768
+ /**
769
+ * Update booking with personal information (Step 1)
770
+ * @param uuid Booking UUID
771
+ * @param data Personal info (name, email, phone, address)
772
+ * @returns Updated BookingResponse
773
+ */
774
+ async updateBookingStep1(uuid, data) {
775
+ const url = `${this.config.baseUrl}/api/v1/bookings/${uuid}/step-1`;
776
+ const response = await this.fetchWithRetry(
777
+ url,
778
+ {
779
+ method: "PATCH",
780
+ body: JSON.stringify(data)
781
+ },
782
+ BookingResponseSchema
783
+ );
784
+ return response;
785
+ }
786
+ /**
787
+ * Update booking with arrival details (Step 2)
788
+ * @param uuid Booking UUID
789
+ * @param data Arrival time, flight, notes
790
+ * @returns Updated BookingResponse
791
+ */
792
+ async updateBookingStep2(uuid, data) {
793
+ const url = `${this.config.baseUrl}/api/v1/bookings/${uuid}/step-2`;
794
+ const response = await this.fetchWithRetry(
795
+ url,
796
+ {
797
+ method: "PATCH",
798
+ body: JSON.stringify(data)
799
+ },
800
+ BookingResponseSchema
801
+ );
802
+ return response;
803
+ }
804
+ /**
805
+ * Update booking with review data (Step 3)
806
+ * @param uuid Booking UUID
807
+ * @param data Terms acceptance, marketing consent
808
+ * @returns Updated BookingResponse with price breakdown
809
+ */
810
+ async updateBookingStep3(uuid, data) {
811
+ const url = `${this.config.baseUrl}/api/v1/bookings/${uuid}/step-3`;
812
+ const response = await this.fetchWithRetry(
813
+ url,
814
+ {
815
+ method: "PATCH",
816
+ body: JSON.stringify(data)
817
+ },
818
+ BookingResponseSchema
819
+ );
820
+ return response;
821
+ }
822
+ /**
823
+ * Confirm booking and get payment URL
824
+ * @param uuid Booking UUID
825
+ * @param paymentMethod Payment method (stripe, bank_transfer, cash)
826
+ * @returns Confirmation response with payment URL
827
+ */
828
+ async confirmBooking(uuid, paymentMethod = "stripe") {
829
+ const url = `${this.config.baseUrl}/api/v1/bookings/${uuid}/confirm`;
830
+ const response = await this.fetchWithRetry(
831
+ url,
832
+ {
833
+ method: "POST",
834
+ body: JSON.stringify({ payment_method: paymentMethod })
835
+ },
836
+ BookingConfirmResponseSchema
837
+ );
838
+ return response;
839
+ }
840
+ /**
841
+ * Get current booking state
842
+ * @param uuid Booking UUID
843
+ * @returns Full BookingResponse with all data
844
+ */
845
+ async getBookingState(uuid) {
846
+ const url = `${this.config.baseUrl}/api/v1/bookings/${uuid}/state`;
847
+ const response = await this.fetchWithRetry(
848
+ url,
849
+ { method: "GET" },
850
+ BookingResponseSchema
851
+ );
852
+ return response;
853
+ }
854
+ /**
855
+ * Get pricing details for a booking
856
+ * @param uuid Booking UUID
857
+ * @returns Pricing breakdown with total, per-night rate, and currency
858
+ */
859
+ async getPricing(uuid) {
860
+ const url = `${this.config.baseUrl}/api/v1/bookings/${uuid}/pricing`;
861
+ const response = await this.fetchWithRetry(
862
+ url,
863
+ { method: "GET" },
864
+ BookingPricingResponseSchema
865
+ );
866
+ return response;
665
867
  }
666
868
  /**
667
869
  * Search properties with advanced filtering
@@ -975,54 +1177,6 @@ function settingsCommand(program2) {
975
1177
  }
976
1178
  });
977
1179
  }
978
- function bookingsCommand(program2) {
979
- const bookings = program2.command("bookings").description("Manage bookings");
980
- bookings.command("create").description("Create a new booking").requiredOption("-f, --file <path>", "Path to JSON file with booking data").action(async (options, command) => {
981
- try {
982
- const client = command.parent.parent.client;
983
- const format = command.parent.parent.format;
984
- const filePath = path.resolve(process.cwd(), options.file);
985
- const bookingData = JSON.parse(fs.readFileSync(filePath, "utf-8"));
986
- const result = await client.createBooking(bookingData);
987
- console.log("\u2713 Booking created successfully");
988
- formatOutput(result, format);
989
- } catch (error) {
990
- handleError(error);
991
- }
992
- });
993
- bookings.command("show <id>").description("Show booking details by ID").action(async (id, options, command) => {
994
- try {
995
- const client = command.parent.parent.client;
996
- const format = command.parent.parent.format;
997
- const booking = await client.getBooking(id);
998
- formatOutput(booking, format);
999
- } catch (error) {
1000
- handleError(error);
1001
- }
1002
- });
1003
- bookings.command("example").description("Print example booking JSON structure").action(() => {
1004
- const example = {
1005
- property_id: 123,
1006
- customer: {
1007
- first_name: "John",
1008
- last_name: "Doe",
1009
- email: "john.doe@example.com",
1010
- phone: "+31612345678",
1011
- address: "123 Main St",
1012
- city: "Amsterdam",
1013
- country: "Netherlands",
1014
- postal_code: "1012AB"
1015
- },
1016
- arrival_date: "2024-06-01",
1017
- departure_date: "2024-06-07",
1018
- guests: 2,
1019
- total_price: 850,
1020
- notes: "Late check-in requested"
1021
- };
1022
- console.log("Example booking structure (save to file and use with --file):");
1023
- console.log(JSON.stringify(example, null, 2));
1024
- });
1025
- }
1026
1180
 
1027
1181
  // src/cli/index.ts
1028
1182
  dotenv.config({ path: path.resolve(process.cwd(), ".env") });
@@ -1054,7 +1208,6 @@ program.name("more-apartments").description("CLI to interact with More Apartment
1054
1208
  propertiesCommand(program);
1055
1209
  contentCommand(program);
1056
1210
  settingsCommand(program);
1057
- bookingsCommand(program);
1058
1211
  program.parse();
1059
1212
  //# sourceMappingURL=index.js.map
1060
1213
  //# sourceMappingURL=index.js.map