-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[Components] Mews #17998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[Components] Mews #17998
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
components/mews/actions/cancel-reservation/cancel-reservation.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import app from "../../mews.app.mjs"; | ||
|
||
export default { | ||
name: "Cancel Reservation", | ||
description: "Cancel a reservation in Mews.", | ||
key: "mews-cancel-reservation", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
reservationId: { | ||
propDefinition: [ | ||
app, | ||
"reservationId", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
app, | ||
reservationId, | ||
} = this; | ||
const response = await app.reservationsCancel({ | ||
$, | ||
data: { | ||
ReservationIds: [ | ||
reservationId, | ||
], | ||
}, | ||
}); | ||
$.export("summary", "Successfully cancelled reservation"); | ||
return response; | ||
}, | ||
}; | ||
|
161 changes: 161 additions & 0 deletions
161
components/mews/actions/create-reservation/create-reservation.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
import app from "../../mews.app.mjs"; | ||
import utils from "../../common/utils.mjs"; | ||
|
||
export default { | ||
name: "Create Reservation", | ||
description: "Create a reservation in Mews. See reservation parameters in the docs. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/reservations#add-reservations)", | ||
key: "mews-create-reservation", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
serviceId: { | ||
propDefinition: [ | ||
app, | ||
"serviceId", | ||
], | ||
}, | ||
customerId: { | ||
propDefinition: [ | ||
app, | ||
"customerId", | ||
], | ||
}, | ||
startUtc: { | ||
propDefinition: [ | ||
app, | ||
"startUtc", | ||
], | ||
}, | ||
endUtc: { | ||
propDefinition: [ | ||
app, | ||
"endUtc", | ||
], | ||
}, | ||
state: { | ||
propDefinition: [ | ||
app, | ||
"state", | ||
], | ||
optional: true, | ||
}, | ||
resourceId: { | ||
propDefinition: [ | ||
app, | ||
"resourceId", | ||
], | ||
optional: true, | ||
}, | ||
number: { | ||
propDefinition: [ | ||
app, | ||
"number", | ||
], | ||
optional: true, | ||
}, | ||
notes: { | ||
propDefinition: [ | ||
app, | ||
"notes", | ||
], | ||
optional: true, | ||
}, | ||
rateId: { | ||
propDefinition: [ | ||
app, | ||
"rateId", | ||
], | ||
optional: true, | ||
}, | ||
companyId: { | ||
propDefinition: [ | ||
app, | ||
"companyId", | ||
], | ||
optional: true, | ||
}, | ||
travelAgencyId: { | ||
propDefinition: [ | ||
app, | ||
"travelAgencyId", | ||
], | ||
optional: true, | ||
}, | ||
businessSegmentId: { | ||
propDefinition: [ | ||
app, | ||
"businessSegmentId", | ||
], | ||
optional: true, | ||
}, | ||
additionalFields: { | ||
propDefinition: [ | ||
app, | ||
"additionalFields", | ||
], | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
app, | ||
serviceId, | ||
customerId, | ||
startUtc, | ||
endUtc, | ||
state, | ||
resourceId, | ||
number, | ||
notes, | ||
rateId, | ||
companyId, | ||
travelAgencyId, | ||
businessSegmentId, | ||
additionalFields, | ||
} = this; | ||
|
||
const response = await app.reservationsCreate({ | ||
data: { | ||
Reservations: [ | ||
{ | ||
ServiceId: serviceId, | ||
CustomerId: customerId, | ||
StartUtc: startUtc, | ||
EndUtc: endUtc, | ||
...(state && { | ||
State: state, | ||
}), | ||
...(resourceId && { | ||
ResourceId: resourceId, | ||
}), | ||
...(number && { | ||
Number: number, | ||
}), | ||
...(notes && { | ||
Notes: notes, | ||
}), | ||
...(rateId && { | ||
RateId: rateId, | ||
}), | ||
...(companyId && { | ||
CompanyId: companyId, | ||
}), | ||
...(travelAgencyId && { | ||
TravelAgencyId: travelAgencyId, | ||
}), | ||
...(businessSegmentId && { | ||
BusinessSegmentId: businessSegmentId, | ||
}), | ||
...(additionalFields && { | ||
...utils.parseJson(additionalFields), | ||
}), | ||
}, | ||
], | ||
}, | ||
$, | ||
}); | ||
$.export("summary", "Successfully created reservation"); | ||
return response; | ||
}, | ||
}; |
37 changes: 37 additions & 0 deletions
37
components/mews/actions/fetch-customers/fetch-customers.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import app from "../../mews.app.mjs"; | ||
import utils from "../../common/utils.mjs"; | ||
|
||
export default { | ||
name: "Fetch Customers", | ||
description: "Retrieve customers using Mews Connector API. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/customers#get-all-customers)", | ||
key: "mews-fetch-customers", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
additionalFields: { | ||
propDefinition: [ | ||
app, | ||
"additionalFields", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
app, | ||
additionalFields, | ||
} = this; | ||
|
||
const items = await app.paginate({ | ||
requester: app.customersGetAll, | ||
requesterArgs: { | ||
$, | ||
data: utils.parseJson(additionalFields), | ||
}, | ||
resultKey: "Customers", | ||
}); | ||
$.export("summary", `Successfully fetched ${items.length} customers`); | ||
return items; | ||
}, | ||
}; | ||
|
37 changes: 37 additions & 0 deletions
37
components/mews/actions/fetch-order-items/fetch-order-items.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import app from "../../mews.app.mjs"; | ||
import utils from "../../common/utils.mjs"; | ||
|
||
export default { | ||
name: "Fetch Order Items", | ||
description: "Retrieve order items using Mews Connector API. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/orderitems#get-all-order-items)", | ||
key: "mews-fetch-order-items", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
additionalFields: { | ||
propDefinition: [ | ||
app, | ||
"additionalFields", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
app, | ||
additionalFields, | ||
} = this; | ||
|
||
const items = await app.paginate({ | ||
requester: app.orderItemsGetAll, | ||
requesterArgs: { | ||
$, | ||
data: utils.parseJson(additionalFields), | ||
}, | ||
resultKey: "OrderItems", | ||
}); | ||
$.export("summary", `Successfully fetched ${items.length} order items`); | ||
return items; | ||
}, | ||
}; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import app from "../../mews.app.mjs"; | ||
import utils from "../../common/utils.mjs"; | ||
|
||
export default { | ||
name: "Fetch Products", | ||
description: "Retrieve products using Mews Connector API. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/products#get-all-products)", | ||
key: "mews-fetch-products", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
additionalFields: { | ||
propDefinition: [ | ||
app, | ||
"additionalFields", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
app, | ||
additionalFields, | ||
} = this; | ||
|
||
const items = await app.paginate({ | ||
requester: app.productsGetAll, | ||
requesterArgs: { | ||
$, | ||
data: utils.parseJson(additionalFields), | ||
}, | ||
resultKey: "Products", | ||
}); | ||
$.export("summary", `Successfully fetched ${items.length} products`); | ||
return items; | ||
}, | ||
}; | ||
|
38 changes: 38 additions & 0 deletions
38
components/mews/actions/fetch-reservations/fetch-reservations.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import app from "../../mews.app.mjs"; | ||
import utils from "../../common/utils.mjs"; | ||
|
||
export default { | ||
name: "Fetch Reservations", | ||
description: "Retrieve reservations using Mews Connector API. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/reservations#get-all-reservations-ver-2023-06-06)", | ||
key: "mews-fetch-reservations", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
additionalFields: { | ||
propDefinition: [ | ||
app, | ||
"additionalFields", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { | ||
app, | ||
additionalFields, | ||
} = this; | ||
|
||
const items = await app.paginate({ | ||
requester: app.reservationsGetAll, | ||
requesterArgs: { | ||
$, | ||
data: utils.parseJson(additionalFields), | ||
}, | ||
resultKey: "Reservations", | ||
}); | ||
|
||
$.export("summary", `Successfully fetched ${items.length} reservations`); | ||
return items; | ||
}, | ||
}; | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Verify utils.parseJson handles errors properly
Same concern as in the update action - if utils.parseJson fails silently, invalid data could be sent to the API.
🏁 Script executed:
Length of output: 152
Let’s broaden the search to include all file types (not just “.js”) so we can locate both the definition and every usage of
parseJson
:🏁 Script executed:
Length of output: 15746
Let’s inspect the
parseJson
implementation incomponents/mews/common/uilts.mjs
to see how it handles invalid JSON:🏁 Script executed:
Length of output: 1164
Ensure JSON parse failures aren’t silently swallowed
The
parseJson
function incomponents/mews/common/uilts.mjs
wrapsJSON.parse
in a try/catch and simply returns the raw string on failure. In your action:an invalid JSON string will be passed straight through (and even spread into the payload as individual character properties), leading to malformed API requests.
Please add explicit error handling or a safe default around this call (for example, guard against non-object returns or default to
{}
), or updateparseJson
so it surfaces errors instead of swallowing them silently.Targets for your fix:
🤖 Prompt for AI Agents