Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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,74 @@
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,
}

Check failure on line 56 in components/hostaway/actions/create-reservation/create-reservation.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Missing trailing comma
},
async run({ $ }) {
const { hostaway, additionalFields = {}, ...data } = this;

Check failure on line 59 in components/hostaway/actions/create-reservation/create-reservation.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Expected a line break after this opening brace

Check failure on line 59 in components/hostaway/actions/create-reservation/create-reservation.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Expected a line break before this closing brace
const { result } = await hostaway.createReservation({
$,
data: {
...data,
...additionalFields

Check failure on line 64 in components/hostaway/actions/create-reservation/create-reservation.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Missing trailing comma
},
});

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

return result;
},
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

Enhance error handling in run method

The current implementation could benefit from better error handling and validation.

Consider adding try-catch and validation:

 async run({ $ }) {
-  const { hostaway, additionalFields = {}, ...data } = this;
-  const { result } = await hostaway.createReservation({
-    $,
-    data: {
-      ...data,
-      ...additionalFields
-    },
-  });
+  try {
+    const { hostaway, additionalFields = {}, ...data } = this;
+    
+    // Validate required fields
+    if (!data.channelId || !data.listingMapId) {
+      throw new Error("channelId and listingMapId are required");
+    }
+    
+    const { result } = await hostaway.createReservation({
+      $,
+      data: {
+        ...data,
+        ...additionalFields,
+      },
+    });
 
-  if (result?.id) {
-    $.export("summary", `Successfully created reservation (ID: ${result.id})`);
-  }
+    if (!result?.id) {
+      throw new Error("Failed to create reservation: No ID returned");
+    }
+    
+    $.export("summary", `Successfully created reservation (ID: ${result.id})`);
+    return result;
+  } catch (error) {
+    throw new Error(`Failed to create reservation: ${error.message}`);
+  }
-  return result;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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;
},
async run({ $ }) {
try {
const { hostaway, additionalFields = {}, ...data } = this;
// Validate required fields
if (!data.channelId || !data.listingMapId) {
throw new Error("channelId and listingMapId are required");
}
const { result } = await hostaway.createReservation({
$,
data: {
...data,
...additionalFields,
},
});
if (!result?.id) {
throw new Error("Failed to create reservation: No ID returned");
}
$.export("summary", `Successfully created reservation (ID: ${result.id})`);
return result;
} catch (error) {
throw new Error(`Failed to create reservation: ${error.message}`);
}
},
🧰 Tools
🪛 eslint

[error] 59-59: Expected a line break after this opening brace.

(object-curly-newline)


[error] 59-59: Expected a line break before this closing brace.

(object-curly-newline)


[error] 64-65: Missing trailing comma.

(comma-dangle)

🪛 GitHub Check: Lint Code Base

[failure] 59-59:
Expected a line break after this opening brace


[failure] 59-59:
Expected a line break before this closing brace


[failure] 64-64:
Missing trailing comma

};
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
19 changes: 19 additions & 0 deletions components/hostaway/common/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,28 @@
"whatsapp",
];

const CHANNEL_OPTIONS = [
{ value: 2018, label: "airbnbOfficial", },

Check failure on line 46 in components/hostaway/common/constants.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Expected a line break after this opening brace

Check failure on line 46 in components/hostaway/common/constants.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Object properties must go on a new line

Check failure on line 46 in components/hostaway/common/constants.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Unexpected trailing comma

Check failure on line 46 in components/hostaway/common/constants.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Expected a line break before this closing brace
{ value: 2002, label: "homeaway", },

Check failure on line 47 in components/hostaway/common/constants.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Expected a line break after this opening brace

Check failure on line 47 in components/hostaway/common/constants.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Expected indentation of 2 spaces but found 0
{ 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
},
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Add trailing comma for consistency and fix CHANNEL_OPTIONS formatting

The property definition needs a trailing comma, and I noticed the CHANNEL_OPTIONS constant has inconsistent formatting:

    channelId: {
      type: "integer",
      label: "Channel",
      description: "Identifier of the channel",
-     options: constants.CHANNEL_OPTIONS
+     options: constants.CHANNEL_OPTIONS,
    },
  • components/hostaway/common/constants.mjs: Fix inconsistent indentation and trailing commas in CHANNEL_OPTIONS array items. The first item is indented while others aren't.
🔗 Analysis chain

Add trailing comma for consistency.

The property definition looks good, but needs a trailing comma to match the style of other properties in this file.

    channelId: {
      type: "integer",
      label: "Channel",
      description: "Identifier of the channel",
-     options: constants.CHANNEL_OPTIONS
+     options: constants.CHANNEL_OPTIONS,
    },

Let's verify the channel options are properly defined:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if CHANNEL_OPTIONS are defined in constants file
rg "CHANNEL_OPTIONS.*=.*\[" components/hostaway/common/constants.mjs

Length of output: 96


Script:

#!/bin/bash
# Let's check the full definition of CHANNEL_OPTIONS to ensure it's properly populated
rg -A10 "CHANNEL_OPTIONS.*=.*\[" components/hostaway/common/constants.mjs

Length of output: 496

🧰 Tools
🪛 eslint

[error] 125-126: Missing trailing comma.

(comma-dangle)

},
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