Skip to content

Commit d84333b

Browse files
committed
more fixes
1 parent 62924cc commit d84333b

File tree

5 files changed

+32
-69
lines changed

5 files changed

+32
-69
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import trustpilot from "../../trustpilot.app.mjs";
33
export default {
44
key: "trustpilot-fetch-service-reviews",
55
name: "Fetch Service Reviews",
6-
description: "Get private reviews for a business unit, limited to 100,000 records. Response includes customer email and order ID. [See the documentation](https://developers.trustpilot.com/business-units-api#get-private-reviews-for-business-unit)",
6+
description: "Get private reviews for a business unit. Response includes customer email and order ID. [See the documentation](https://developers.trustpilot.com/business-units-api#get-private-reviews-for-business-unit)",
77
version: "0.1.0",
88
type: "action",
99
props: {
Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
export const BASE_URL = "https://api.trustpilot.com/v1";
22

3-
export const WEBHOOK_EVENTS = {
4-
REVIEW_CREATED: "review.created",
5-
REVIEW_REVISED: "review.revised",
6-
REVIEW_DELETED: "review.deleted",
7-
REPLY_CREATED: "reply.created",
8-
INVITATION_SENT: "invitation.sent",
9-
INVITATION_FAILED: "invitation.failed",
10-
};
11-
123
export const ENDPOINTS = {
134
// Business Units
145
BUSINESS_UNITS: "/business-units/search",
15-
BUSINESS_UNIT_BY_ID: "/business-units/{businessUnitId}",
16-
17-
// Public Reviews
18-
PUBLIC_REVIEWS: "/business-units/{businessUnitId}/reviews",
19-
PUBLIC_REVIEW_BY_ID: "/reviews/{reviewId}",
206

217
// Service Reviews
228
SERVICE_REVIEWS: "/private/business-units/{businessUnitId}/reviews",
@@ -29,51 +15,9 @@ export const ENDPOINTS = {
2915
CREATE_CONVERSATION_FOR_REVIEW: "/private/product-reviews/{reviewId}/create-conversation",
3016

3117
// Conversations
32-
CONVERSATIONS: "/private/conversations",
3318
CONVERSATION_BY_ID: "/private/conversations/{conversationId}",
3419
REPLY_TO_CONVERSATION: "/private/conversations/{conversationId}/comments",
3520
};
3621

37-
export const REVIEW_TYPES = {
38-
SERVICE: "service",
39-
PRODUCT: "product",
40-
};
41-
42-
export const INVITATION_TYPES = {
43-
REVIEW: "review",
44-
PRODUCT_REVIEW: "product-review",
45-
};
46-
47-
export const SORT_OPTIONS = {
48-
CREATED_AT_ASC: "createdat.asc",
49-
CREATED_AT_DESC: "createdat.desc",
50-
STARS_ASC: "stars.asc",
51-
STARS_DESC: "stars.desc",
52-
UPDATED_AT_ASC: "updatedat.asc",
53-
UPDATED_AT_DESC: "updatedat.desc",
54-
};
55-
56-
export const RATING_SCALE = [
57-
1,
58-
2,
59-
3,
60-
4,
61-
5,
62-
];
63-
6422
export const DEFAULT_LIMIT = 20;
6523
export const MAX_LIMIT = 100;
66-
67-
export const POLLING_CONFIG = {
68-
DEFAULT_TIMER_INTERVAL_SECONDS: 15 * 60, // 15 minutes
69-
MAX_ITEMS_PER_POLL: 100,
70-
LOOKBACK_HOURS: 24, // How far back to look on first run
71-
};
72-
73-
export const SOURCE_TYPES = {
74-
NEW_REVIEWS: "new_reviews",
75-
UPDATED_REVIEWS: "updated_reviews",
76-
NEW_REPLIES: "new_replies",
77-
NEW_CONVERSATIONS: "new_conversations",
78-
UPDATED_CONVERSATIONS: "updated_conversations",
79-
};

components/trustpilot/sources/new-product-reviews/new-product-reviews.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import common from "../common/polling.mjs";
2+
import { DEFAULT_LIMIT } from "../../common/constants.mjs";
23

34
export default {
45
...common,
@@ -23,7 +24,7 @@ export default {
2324
// so we'll rely on pagination and client-side filtering
2425
return {
2526
businessUnitId: this.businessUnitId,
26-
perPage: 100,
27+
perPage: DEFAULT_LIMIT,
2728
page: 1,
2829
};
2930
},

components/trustpilot/sources/new-service-reviews/new-service-reviews.mjs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import common from "../common/polling.mjs";
2+
import {
3+
DEFAULT_LIMIT,
4+
MAX_LIMIT,
5+
} from "../../common/constants.mjs";
26

37
export default {
48
...common,
@@ -20,7 +24,7 @@ export default {
2024
getFetchParams(lastReviewTime) {
2125
const params = {
2226
businessUnitId: this.businessUnitId,
23-
perPage: 100,
27+
perPage: DEFAULT_LIMIT,
2428
orderBy: "createdat.desc",
2529
};
2630

@@ -36,10 +40,17 @@ export default {
3640
let result = await this.trustpilot.fetchServiceReviews($, params);
3741

3842
// Handle pagination for service reviews
39-
while (result.reviews && result.reviews.length === 100) {
40-
params.page = (params.page || 1) + 1;
41-
const nextResult = await this.trustpilot.fetchServiceReviews($, params);
42-
result.reviews = result.reviews.concat(nextResult.reviews || []);
43+
if (result.reviews && result.reviews.length === DEFAULT_LIMIT) {
44+
while (true) {
45+
params.page = (params.page || 1) + 1;
46+
const nextResult = await this.trustpilot.fetchServiceReviews($, params);
47+
result.reviews = result.reviews.concat(nextResult.reviews || []);
48+
49+
if ((nextResult.reviews && nextResult.reviews.length < DEFAULT_LIMIT)
50+
|| result.reviews.length >= MAX_LIMIT) {
51+
break;
52+
}
53+
}
4354
}
4455

4556
return result;

components/trustpilot/trustpilot.app.mjs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,14 @@ export default {
122122

123123
// Shared method for fetching service reviews - used by both actions and sources
124124
async fetchServiceReviews($, params = {}) {
125-
const { businessUnitId } = params;
125+
const {
126+
businessUnitId,
127+
page = 1,
128+
perPage = 20,
129+
orderBy = "createdat.desc",
130+
ignoreTagValueCase = false,
131+
...filters
132+
} = params;
126133

127134
// Validate required parameters
128135
if (!businessUnitId) {
@@ -139,11 +146,11 @@ export default {
139146

140147
// Prepare query parameters
141148
const queryParams = {
142-
...params,
143-
page: 1,
144-
perPage: 20,
145-
orderBy: "createdat.desc",
146-
ignoreTagValueCase: false,
149+
...filters,
150+
page,
151+
perPage,
152+
orderBy,
153+
ignoreTagValueCase,
147154
};
148155

149156
// Make the API request

0 commit comments

Comments
 (0)