Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion components/trustpilot/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
*.js
*.mjs
dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import trustpilot from "../../app/trustpilot.app.ts";

export default {
key: "trustpilot-fetch-product-review-by-id",
name: "Fetch Product Review by ID",
description: "Fetch a specific product review by its ID. [See the documentation](https://developers.trustpilot.com/product-reviews-api#get-private-product-review)",
version: "0.0.1",
type: "action",
props: {
trustpilot,
reviewId: {
propDefinition: [
trustpilot,
"reviewId",
],
},
},
async run({ $ }) {
const { reviewId } = this;

try {
const review = await this.trustpilot.getProductReviewById({
reviewId,
});

$.export("$summary", `Successfully fetched product review ${reviewId}`);

return {
review,
metadata: {
reviewId,
requestTime: new Date().toISOString(),
},
};
} catch (error) {
throw new Error(`Failed to fetch product review: ${error.message}`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally we shouldn't be try/catching here, because @pipedream/platform's axios already handles error responses and emits metadata for the request and response - this would make it harder to debug. The same applies for all components using a try/catch here in the request method

}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import trustpilot from "../../app/trustpilot.app.ts";

export default {
key: "trustpilot-fetch-product-reviews",
name: "Fetch Product Reviews",
description: "Fetch product reviews for a business unit. [See the documentation](https://developers.trustpilot.com/product-reviews-api#get-private-product-reviews)",
version: "0.0.1",
type: "action",
props: {
trustpilot,
businessUnitId: {
propDefinition: [
trustpilot,
"businessUnitId",
],
},
stars: {
propDefinition: [
trustpilot,
"stars",
],
},
sortBy: {
propDefinition: [
trustpilot,
"sortBy",
],
},
limit: {
propDefinition: [
trustpilot,
"limit",
],
},
includeReportedReviews: {
propDefinition: [
trustpilot,
"includeReportedReviews",
],
},
tags: {
propDefinition: [
trustpilot,
"tags",
],
},
language: {
propDefinition: [
trustpilot,
"language",
],
},
offset: {
type: "integer",
label: "Offset",
description: "Number of results to skip (for pagination)",
min: 0,
default: 0,
optional: true,
},
},
async run({ $ }) {
const {
businessUnitId,
stars,
sortBy,
limit,
includeReportedReviews,
tags,
language,
offset,
} = this;

try {
const result = await this.trustpilot.getProductReviews({
businessUnitId,
stars,
sortBy,
limit,
includeReportedReviews,
tags,
language,
offset,
});

const { reviews, pagination } = result;

$.export("$summary", `Successfully fetched ${reviews.length} product review(s) for business unit ${businessUnitId}`);

return {
reviews,
pagination,
metadata: {
businessUnitId,
filters: {
stars,
sortBy,
includeReportedReviews,
tags,
language,
},
requestTime: new Date().toISOString(),
},
};
} catch (error) {
throw new Error(`Failed to fetch product reviews: ${error.message}`);
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import trustpilot from "../../app/trustpilot.app.ts";

export default {
key: "trustpilot-fetch-service-review-by-id",
name: "Fetch Service Review by ID",
description: "Fetch a specific service review by its ID. [See the documentation](https://developers.trustpilot.com/business-units-api#get-business-unit-review)",
version: "0.0.1",
type: "action",
props: {
trustpilot,
businessUnitId: {
propDefinition: [
trustpilot,
"businessUnitId",
],
},
reviewId: {
propDefinition: [
trustpilot,
"reviewId",
],
},
},
async run({ $ }) {
const {
businessUnitId,
reviewId,
} = this;

try {
const review = await this.trustpilot.getServiceReviewById({
businessUnitId,
reviewId,
});

$.export("$summary", `Successfully fetched service review ${reviewId} for business unit ${businessUnitId}`);

return {
review,
metadata: {
businessUnitId,
reviewId,
requestTime: new Date().toISOString(),
},
};
} catch (error) {
throw new Error(`Failed to fetch service review: ${error.message}`);
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import trustpilot from "../../app/trustpilot.app.ts";

export default {
key: "trustpilot-fetch-service-reviews",
name: "Fetch Service Reviews",
description: "Fetch service reviews for a business unit. [See the documentation](https://developers.trustpilot.com/business-units-api#get-business-unit-reviews)",
version: "0.0.1",
type: "action",
props: {
trustpilot,
businessUnitId: {
propDefinition: [
trustpilot,
"businessUnitId",
],
},
stars: {
propDefinition: [
trustpilot,
"stars",
],
},
sortBy: {
propDefinition: [
trustpilot,
"sortBy",
],
},
limit: {
propDefinition: [
trustpilot,
"limit",
],
},
includeReportedReviews: {
propDefinition: [
trustpilot,
"includeReportedReviews",
],
},
tags: {
propDefinition: [
trustpilot,
"tags",
],
},
language: {
propDefinition: [
trustpilot,
"language",
],
},
offset: {
type: "integer",
label: "Offset",
description: "Number of results to skip (for pagination)",
min: 0,
default: 0,
optional: true,
},
},
async run({ $ }) {
const {
businessUnitId,
stars,
sortBy,
limit,
includeReportedReviews,
tags,
language,
offset,
} = this;

try {
const result = await this.trustpilot.getServiceReviews({
businessUnitId,
stars,
sortBy,
limit,
includeReportedReviews,
tags,
language,
offset,
});

const { reviews, pagination } = result;

$.export("$summary", `Successfully fetched ${reviews.length} service review(s) for business unit ${businessUnitId}`);

return {
reviews,
pagination,
metadata: {
businessUnitId,
filters: {
stars,
sortBy,
includeReportedReviews,
tags,
language,
},
requestTime: new Date().toISOString(),
},
};
} catch (error) {
throw new Error(`Failed to fetch service reviews: ${error.message}`);
}
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import trustpilot from "../../app/trustpilot.app.ts";

export default {
key: "trustpilot-reply-to-product-review",
name: "Reply to Product Review",
description: "Reply to a product review on behalf of your business. [See the documentation](https://developers.trustpilot.com/product-reviews-api#reply-to-product-review)",
version: "0.0.1",
type: "action",
props: {
trustpilot,
reviewId: {
propDefinition: [
trustpilot,
"reviewId",
],
},
message: {
type: "string",
label: "Reply Message",
description: "The message to reply to the review with",
},
},
async run({ $ }) {
const {
reviewId,
message,
} = this;

if (!message || message.trim().length === 0) {
throw new Error("Reply message cannot be empty");
}

try {
const result = await this.trustpilot.replyToProductReview({
reviewId,
message: message.trim(),
});

$.export("$summary", `Successfully replied to product review ${reviewId}`);

return {
success: true,
reply: result,
metadata: {
reviewId,
messageLength: message.trim().length,
requestTime: new Date().toISOString(),
},
};
} catch (error) {
throw new Error(`Failed to reply to product review: ${error.message}`);
}
},
};
Loading