Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import hostaway from "../../hostaway.app.mjs";

export default {
key: "hostaway-create-reservation",
name: "Create Reservation",
description: "Creates a new reservation in Hostaway. [See the documentation](https://api.hostaway.com/documentation#create-a-reservation)",
version: "0.0.1",
type: "action",
props: {
hostaway,
channelId: {
propDefinition: [
hostaway,
"channelId",
],
},
listingMapId: {
propDefinition: [
hostaway,
"listingId",
],
},
arrivalDate: {
type: "string",
label: "Arrival Date",
description: "Arrival date in `YYYY-MM-DD` format, e.g. `2024-08-15`",
},
departureDate: {
type: "string",
label: "Departure Date",
description: "Departure date in `YYYY-MM-DD` format, e.g. `2024-08-19`",
},
Comment on lines +23 to +32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add date validation for arrival and departure dates

While the date format is documented, there's no validation to ensure dates are:

  1. In the correct format
  2. Arrival is before departure
  3. Not in the past

Consider adding validation in the run method:

 async run({ $ }) {
   const { hostaway, additionalFields = {}, ...data } = this;
+  const arrival = new Date(data.arrivalDate);
+  const departure = new Date(data.departureDate);
+  
+  if (isNaN(arrival.getTime()) || isNaN(departure.getTime())) {
+    throw new Error("Invalid date format. Use YYYY-MM-DD");
+  }
+  
+  if (arrival >= departure) {
+    throw new Error("Arrival date must be before departure date");
+  }
+  
+  if (arrival < new Date()) {
+    throw new Error("Arrival date cannot be in the past");
+  }
   
   const { result } = await hostaway.createReservation({

Committable suggestion skipped: line range outside the PR's diff.

guestName: {
type: "string",
label: "Guest Name",
description: "Name of the guest",
optional: true,
},
guestEmail: {
type: "string",
label: "Guest Email",
description: "Email address of the guest",
optional: true,
},
numberOfGuests: {
type: "integer",
label: "Number of Guests",
description: "Number of guests for the reservation",
optional: true,
},
additionalFields: {
type: "object",
label: "Additional Fields",
description: "Additional fields to set for the reservation. [See the documentation](https://api.hostaway.com/documentation#reservation-object) for all available fields.",
optional: true,
},
},
async run({ $ }) {
const {
hostaway, additionalFields = {}, ...data
} = this;
const { result } = await hostaway.createReservation({
$,
data: {
...data,
...additionalFields,
},
});

if (result?.id) {
$.export("summary", `Successfully created reservation (ID: ${result.id})`);
}

return result;
},
};
2 changes: 1 addition & 1 deletion components/hostaway/actions/create-task/create-task.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "hostaway-create-task",
name: "Create Task",
description: "Creates a new task in Hostaway. [See the documentation](https://api.hostaway.com/documentation#create-task)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
hostaway,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "hostaway-send-message-to-guest",
name: "Send Message To Guest",
description: "Send a conversation message to a guest in Hostaway. [See the documentation](https://api.hostaway.com/documentation#send-conversation-message)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
hostaway,
Expand Down
2 changes: 1 addition & 1 deletion components/hostaway/actions/update-task/update-task.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "hostaway-update-task",
name: "Update Task",
description: "Updates an existing task in Hostaway. [See the documentation](https://api.hostaway.com/documentation#update-task)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
hostaway,
Expand Down
64 changes: 64 additions & 0 deletions components/hostaway/common/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,73 @@ const COMMUNICATION_TYPES = [
"whatsapp",
];

const CHANNEL_OPTIONS = [
{
value: 2018,
label: "airbnbOfficial",
},
{
value: 2002,
label: "homeaway",
},
{
value: 2005,
label: "bookingcom",
},
{
value: 2007,
label: "expedia",
},
{
value: 2009,
label: "homeawayical",
},
{
value: 2010,
label: "vrboical",
},
{
value: 2000,
label: "direct",
},
{
value: 2013,
label: "bookingengine",
},
{
value: 2015,
label: "customIcal",
},
{
value: 2016,
label: "tripadvisorical",
},
{
value: 2017,
label: "wordpress",
},
{
value: 2019,
label: "marriott",
},
{
value: 2020,
label: "partner",
},
{
value: 2021,
label: "gds",
},
{
value: 2022,
label: "google",
},
];

export default {
DEFAULT_LIMIT,
CATEGORIES,
TASK_STATUS,
COMMUNICATION_TYPES,
CHANNEL_OPTIONS,
};
13 changes: 13 additions & 0 deletions components/hostaway/hostaway.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ export default {
})) || [];
},
},
channelId: {
type: "integer",
label: "Channel",
description: "Identifier of the channel",
options: constants.CHANNEL_OPTIONS,
},
},
methods: {
_baseUrl() {
Expand Down Expand Up @@ -211,5 +217,12 @@ export default {
...args,
});
},
createReservation(args = {}) {
return this._makeRequest({
path: "/reservations",
method: "POST",
...args,
});
},
},
};
2 changes: 1 addition & 1 deletion components/hostaway/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/hostaway",
"version": "0.1.1",
"version": "0.2.0",
"description": "Pipedream Hostaway Components",
"main": "hostaway.app.mjs",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "hostaway-new-message-received",
name: "New Message Received",
description: "Emit new event when a new message is received in Hostaway.",
version: "0.0.2",
version: "0.0.3",
type: "source",
dedupe: "unique",
methods: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "hostaway-reservation-created",
name: "New Reservation Created",
description: "Emit new event when a new reservation is created in Hostaway.",
version: "0.0.2",
version: "0.0.3",
type: "source",
dedupe: "unique",
methods: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "hostaway-reservation-updated",
name: "New Reservation Updated",
description: "Emit new event when a reservation is updated in Hostaway.",
version: "0.0.2",
version: "0.0.3",
type: "source",
dedupe: "unique",
methods: {
Expand Down
Loading