Skip to content

Commit acf2b0f

Browse files
committed
comments
1 parent 5f34833 commit acf2b0f

File tree

11 files changed

+75
-165
lines changed

11 files changed

+75
-165
lines changed

components/trustpilot/actions/fetch-product-review-by-id/fetch-product-review-by-id.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default {
4040
});
4141

4242
// Make the API request
43-
const response = await makeRequest(this.trustpilot, {
43+
const response = await makeRequest($, this.trustpilot, {
4444
endpoint,
4545
});
4646

components/trustpilot/actions/fetch-product-reviews/fetch-product-reviews.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import trustpilot from "../../trustpilot.app.mjs";
33
export default {
44
key: "trustpilot-fetch-product-reviews",
55
name: "Fetch Product Reviews",
6-
description: "Retrieves a list of product reviews for a specific business unit.",
7-
version: "0.1.0",
6+
description: "Retrieves a list of product reviews for a specific business unit. See documentation [here](https://developers.trustpilot.com/product-reviews-api/#get-private-product-reviews)",
7+
version: "1.0.0",
88
type: "action",
99
props: {
1010
trustpilot,

components/trustpilot/actions/fetch-service-review-by-id/fetch-service-review-by-id.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default {
4040
});
4141

4242
// Make the API request
43-
const response = await makeRequest(this.trustpilot, {
43+
const response = await makeRequest($, this.trustpilot, {
4444
endpoint,
4545
});
4646

components/trustpilot/actions/fetch-service-reviews/fetch-service-reviews.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default {
2323
page: {
2424
type: "integer",
2525
label: "Page",
26-
description: "The page to retrieve. If the page number requested is higher than the available number of pages an empty array will be returned.",
26+
description: "The page to retrieve. If the page number requested is higher than the available number of pages, an empty array will be returned.",
2727
min: 1,
2828
default: 1,
2929
optional: true,
@@ -120,13 +120,13 @@ export default {
120120
startDateTime: {
121121
type: "string",
122122
label: "Start Date Time",
123-
description: "Filter reviews by datetime range. If no time is specified than time is implicit 00:00:00. Format: 2013-09-07T13:37:00",
123+
description: "Filter reviews by datetime range. If no time is specified, then time is implicitly `00:00:00`. Format: `2013-09-07T13:37:00`",
124124
optional: true,
125125
},
126126
endDateTime: {
127127
type: "string",
128128
label: "End Date Time",
129-
description: "Filter reviews by datetime range. If no time is specified than time is implicit 00:00:00. Format: 2013-09-07T13:37:00",
129+
description: "Filter reviews by datetime range. If no time is specified, then time is implicitly `00:00:00`. Format: `2013-09-07T13:37:00`",
130130
optional: true,
131131
},
132132
source: {

components/trustpilot/actions/get-conversation-from-product-review/get-conversation-from-product-review.mjs

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default {
1111
key: "trustpilot-get-conversation-from-product-review",
1212
name: "Get Conversation from Product Review",
1313
description: "Get conversation and related comments from a product review. First fetches the review to get the conversationId, then retrieves the full conversation details. [See the documentation](https://developers.trustpilot.com/conversations-api#get-conversation)",
14-
version: "0.1.0",
14+
version: "0.0.1",
1515
type: "action",
1616
props: {
1717
trustpilot,
@@ -33,62 +33,58 @@ export default {
3333
throw new ConfigurationError("Invalid review ID format");
3434
}
3535

36-
try {
37-
// Step 1: Get the product review to get the conversationId
38-
$.export("$summary", "Fetching product review details...");
36+
// Step 1: Get the product review to get the conversationId
37+
$.export("$summary", "Fetching product review details...");
3938

40-
const getReviewEndpoint = buildUrl(ENDPOINTS.PRIVATE_PRODUCT_REVIEW_BY_ID, {
41-
reviewId,
42-
});
43-
44-
const review = await makeRequest(this.trustpilot, {
45-
endpoint: getReviewEndpoint,
46-
});
47-
48-
const conversationId = review.conversationId;
49-
50-
if (!conversationId) {
51-
return {
52-
success: false,
53-
message: "No conversation found for this product review",
54-
review: {
55-
id: reviewId,
56-
hasConversation: false,
57-
},
58-
metadata: {
59-
reviewId,
60-
requestTime: new Date().toISOString(),
61-
},
62-
};
63-
}
39+
const getReviewEndpoint = buildUrl(ENDPOINTS.PRIVATE_PRODUCT_REVIEW_BY_ID, {
40+
reviewId,
41+
});
6442

65-
// Step 2: Get the conversation details
66-
$.export("$summary", "Fetching conversation details...");
43+
const review = await makeRequest($, this.trustpilot, {
44+
endpoint: getReviewEndpoint,
45+
});
6746

68-
const getConversationEndpoint = buildUrl(ENDPOINTS.CONVERSATION_BY_ID, {
69-
conversationId,
70-
});
71-
72-
const conversation = await makeRequest(this.trustpilot, {
73-
endpoint: getConversationEndpoint,
74-
});
75-
76-
$.export("$summary", `Successfully retrieved conversation ${conversationId} for product review ${reviewId}`);
47+
const conversationId = review.conversationId;
7748

49+
if (!conversationId) {
7850
return {
79-
success: true,
80-
conversation,
51+
success: false,
52+
message: "No conversation found for this product review",
53+
review: {
54+
id: reviewId,
55+
hasConversation: false,
56+
},
8157
metadata: {
8258
reviewId,
83-
conversationId,
84-
commentCount: conversation.comments?.length || 0,
85-
conversationState: conversation.state,
86-
source: conversation.source,
8759
requestTime: new Date().toISOString(),
8860
},
8961
};
90-
} catch (error) {
91-
throw new ConfigurationError(`Failed to get conversation from product review: ${error.message}`);
9262
}
63+
64+
// Step 2: Get the conversation details
65+
$.export("$summary", "Fetching conversation details...");
66+
67+
const getConversationEndpoint = buildUrl(ENDPOINTS.CONVERSATION_BY_ID, {
68+
conversationId,
69+
});
70+
71+
const conversation = await makeRequest($, this.trustpilot, {
72+
endpoint: getConversationEndpoint,
73+
});
74+
75+
$.export("$summary", `Successfully retrieved conversation ${conversationId} for product review ${reviewId}`);
76+
77+
return {
78+
success: true,
79+
conversation,
80+
metadata: {
81+
reviewId,
82+
conversationId,
83+
commentCount: conversation.comments?.length || 0,
84+
conversationState: conversation.state,
85+
source: conversation.source,
86+
requestTime: new Date().toISOString(),
87+
},
88+
};
9389
},
9490
};

components/trustpilot/actions/reply-to-product-review/reply-to-product-review.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default {
7070
reviewId,
7171
});
7272

73-
const review = await makeRequest(this.trustpilot, {
73+
const review = await makeRequest($, this.trustpilot, {
7474
endpoint: getReviewEndpoint,
7575
});
7676

@@ -84,7 +84,7 @@ export default {
8484
reviewId,
8585
});
8686

87-
const createConversationResponse = await makeRequest(this.trustpilot, {
87+
const createConversationResponse = await makeRequest($, this.trustpilot, {
8888
endpoint: createConversationEndpoint,
8989
method: "POST",
9090
});
@@ -113,7 +113,7 @@ export default {
113113
requestData.integrationId = integrationId;
114114
}
115115

116-
const replyResponse = await makeRequest(this.trustpilot, {
116+
const replyResponse = await makeRequest($, this.trustpilot, {
117117
endpoint: replyEndpoint,
118118
method: "POST",
119119
data: requestData,

components/trustpilot/actions/reply-to-service-review/reply-to-service-review.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default {
6868
};
6969

7070
// Make the API request
71-
await makeRequest(this.trustpilot, {
71+
await makeRequest($, this.trustpilot, {
7272
endpoint,
7373
method: "POST",
7474
data: requestData,

components/trustpilot/common/api-client.mjs

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { axios } from "@pipedream/platform";
2-
import {
3-
BASE_URL, HTTP_STATUS, RETRY_CONFIG,
4-
} from "./constants.mjs";
5-
import {
6-
formatQueryParams, sleep,
7-
} from "./utils.mjs";
2+
import { BASE_URL } from "./constants.mjs";
3+
import { formatQueryParams } from "./utils.mjs";
84

95
/**
106
* Make an authenticated request to the Trustpilot API
@@ -16,18 +12,17 @@ import {
1612
* @param {object} [options.data] - Request body data
1713
* @param {object} [options.additionalHeaders={}] - Additional headers to include in the request
1814
* @param {number} [options.timeout=30000] - Request timeout
19-
* @param {number} [retries=RETRY_CONFIG.MAX_RETRIES] - Number of retries for rate limiting
2015
* @returns {Promise<object>} API response data
2116
*/
22-
export async function makeRequest(trustpilotApp, {
17+
export async function makeRequest($, trustpilotApp, {
2318
endpoint,
2419
method = "GET",
2520
params = {},
2621
data = null,
2722
timeout = 30000,
2823
additionalHeaders = {},
2924
...args
30-
}, retries = RETRY_CONFIG.MAX_RETRIES) {
25+
}) {
3126
const url = `${BASE_URL}${endpoint}`;
3227
const headers = {
3328
...getAuthHeaders(trustpilotApp, url),
@@ -47,28 +42,8 @@ export async function makeRequest(trustpilotApp, {
4742
config.data = data;
4843
}
4944

50-
try {
51-
const response = await axios(trustpilotApp, config);
52-
return response.data || response;
53-
} catch (error) {
54-
if (retries > 0 && error.response?.status === HTTP_STATUS.TOO_MANY_REQUESTS) {
55-
const delay = Math.min(
56-
RETRY_CONFIG.INITIAL_DELAY * (RETRY_CONFIG.MAX_RETRIES - retries + 1),
57-
RETRY_CONFIG.MAX_DELAY,
58-
);
59-
await sleep(delay);
60-
return makeRequest(trustpilotApp, {
61-
endpoint,
62-
method,
63-
params,
64-
data,
65-
timeout,
66-
additionalHeaders,
67-
...args,
68-
}, retries - 1);
69-
}
70-
throw error;
71-
}
45+
const response = await axios($ ?? trustpilotApp, config);
46+
return response.data || response;
7247
}
7348

7449
/**

components/trustpilot/common/constants.mjs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,6 @@ export const RATING_SCALE = [
6464
export const DEFAULT_LIMIT = 20;
6565
export const MAX_LIMIT = 100;
6666

67-
export const HTTP_STATUS = {
68-
OK: 200,
69-
CREATED: 201,
70-
NO_CONTENT: 204,
71-
BAD_REQUEST: 400,
72-
UNAUTHORIZED: 401,
73-
FORBIDDEN: 403,
74-
NOT_FOUND: 404,
75-
TOO_MANY_REQUESTS: 429,
76-
INTERNAL_SERVER_ERROR: 500,
77-
};
78-
79-
export const RETRY_CONFIG = {
80-
MAX_RETRIES: 3,
81-
INITIAL_DELAY: 1000,
82-
MAX_DELAY: 10000,
83-
};
84-
8567
export const POLLING_CONFIG = {
8668
DEFAULT_TIMER_INTERVAL_SECONDS: 15 * 60, // 15 minutes
8769
MAX_ITEMS_PER_POLL: 100,

components/trustpilot/common/utils.mjs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,3 @@ export function parseApiError(error) {
281281
code: "UNKNOWN_ERROR",
282282
};
283283
}
284-
285-
/**
286-
* Sleep function for retry logic
287-
* @param {number} ms - Milliseconds to sleep
288-
* @returns {Promise} - Promise that resolves after delay
289-
*/
290-
export function sleep(ms) {
291-
return new Promise((resolve) => setTimeout(resolve, ms));
292-
}

0 commit comments

Comments
 (0)