Skip to content

Add eTrusted new review polling source#21225

Open
lixiyuan1030-stack wants to merge 5 commits into
PipedreamHQ:masterfrom
lixiyuan1030-stack:add-etrusted-new-review-source
Open

Add eTrusted new review polling source#21225
lixiyuan1030-stack wants to merge 5 commits into
PipedreamHQ:masterfrom
lixiyuan1030-stack:add-etrusted-new-review-source

Conversation

@lixiyuan1030-stack

@lixiyuan1030-stack lixiyuan1030-stack commented Jun 23, 2026

Copy link
Copy Markdown

Summary

Adds a new eTrusted polling source that emits an event when a new review is submitted.

Fixes: #21224

Changes

  • Added etrusted-new-review source
  • Polls the eTrusted /reviews endpoint
  • Supports optional channel, review type, status, rating, and statement filters
  • Stores the latest submittedAt timestamp and uses submittedAfter on subsequent runs
  • Added a sample event
  • Bumped @pipedream/etrusted package version

Tests

  • node --check components\etrusted\sources\new-review\new-review.mjs
  • node --check components\etrusted\sources\new-review\test-event.mjs
  • git diff --check

cmd /c npm test -- components/etrusted could not run locally because dependencies are not installed in this environment (jest is unavailable).

Summary by CodeRabbit

  • New Features
    • Added a new polling source to detect and emit events for newly submitted eTrusted reviews.
    • Supports optional filtering (channel, type, status, rating) and uses cursor-based de-duplication to avoid repeated events.
  • Tests
    • Added a sample “SERVICE_REVIEW” event payload to support validation of emitted review data.
  • Chores
    • Bumped the eTrusted package version to 0.3.0.

@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
pipedream-docs-redirect-do-not-edit Ignored Ignored Jul 2, 2026 9:42pm

Request Review

@pipedream-component-development

Copy link
Copy Markdown
Collaborator

Thank you so much for submitting this! We've added it to our backlog to review, and our team has been notified.

@pipedream-component-development

Copy link
Copy Markdown
Collaborator

Thanks for submitting this PR! When we review PRs, we follow the Pipedream component guidelines. If you're not familiar, here's a quick checklist:

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7879b2d8-be09-4039-8257-9338146568bd

📥 Commits

Reviewing files that changed from the base of the PR and between 11e43e6 and 974a19a.

📒 Files selected for processing (1)
  • components/etrusted/sources/new-review/new-review.mjs

📝 Walkthrough

Walkthrough

A new polling Pipedream source (etrusted-new-review) is added for the eTrusted integration. It polls the eTrusted Reviews API on a timer, tracks the last seen submission timestamp and a deduplication list in db, and emits one event per new review in chronological order. A test event fixture and a package version bump to 0.3.0 are also included.

Changes

eTrusted New Review Polling Source

Layer / File(s) Summary
Source metadata, props, and timer configuration
components/etrusted/sources/new-review/new-review.mjs
Defines the source key (etrusted-new-review), name, description, version, dedupe strategy, timer prop using DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, and optional filter props (channelId, type, status, rating, ignoreStatements) mapped to eTrusted API parameters.
State management and query builders
components/etrusted/sources/new-review/new-review.mjs
Implements persistent cursor accessors (_getCursor, _setCursor) for tracking the newest submittedAt timestamp and deduplication ids list, CSV parsing for array props, query parameter construction (_getParams) with orderBy: "submittedAt", timestamp extraction from multiple review fields (submittedAt/submitted_at/createdAt/created_at), summary generation with optional star count suffix, and event shape builder.
Review fetching from API
components/etrusted/sources/new-review/new-review.mjs
Implements _getReviews() to paginate through etrusted.getListOfReviews with optional submittedAfter filtering, collecting all results into an array with an optional maxResults cap.
Deduplication and cursor advancement logic
components/etrusted/sources/new-review/new-review.mjs
Implements _isNewReview() to compare review timestamps and cursor ids for deduplication, _sortBySubmittedAt() to order reviews chronologically, and _getNextCursor() to compute the newest timestamp and merge deduplication ids.
Review processing and emission
components/etrusted/sources/new-review/new-review.mjs
Implements _processReviews() to filter fetched reviews using _isNewReview(), emit only newly detected reviews in ascending chronological order, and persist the updated cursor when reviews are processed.
Deploy hook: initial cursor seeding
components/etrusted/sources/new-review/new-review.mjs
Implements deploy() to fetch up to 10 initial reviews and seed the cursor state.
Run hook: incremental polling
components/etrusted/sources/new-review/new-review.mjs
Implements run() to fetch reviews newer than the stored cursor timestamp and emit newly detected ones while advancing the cursor.
Sample event, exports, and package version bump
components/etrusted/sources/new-review/new-review.mjs, components/etrusted/sources/new-review/test-event.mjs, components/etrusted/package.json
Exports sampleEmit, adds a SERVICE_REVIEW test event fixture with review metadata and nested channel and consumer fields, and bumps package version from 0.2.0 to 0.3.0.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding an eTrusted polling source for detecting new reviews.
Description check ✅ Passed The description includes a summary, changes list, test information, and references the linked issue. The checklist items are incomplete but the core information is present.
Linked Issues check ✅ Passed The PR implements all requirements from issue #21224: polling source for new reviews, API endpoint integration, submission timestamp tracking, and optional filtering support.
Out of Scope Changes check ✅ Passed All changes are scoped to the eTrusted polling source implementation and version bump; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@components/etrusted/sources/new-review/new-review.mjs`:
- Around line 62-67: The current state persistence in _getLastSubmittedAt() and
_setLastSubmittedAt() methods stores only the timestamp, which causes reviews
with identical submittedAt values to potentially be skipped. Add a secondary
tie-breaker by also storing and retrieving the last processed review ID
alongside the timestamp. Create corresponding getter/setter methods like
_getLastProcessedId() and _setLastProcessedId(), then update the polling logic
that uses these state methods to filter reviews by using both the timestamp AND
the ID tie-breaker when querying for new reviews, ensuring no reviews with equal
timestamps are silently dropped. Apply this same pattern to the duplicate code
at lines 145-147 as well.
- Around line 126-133: The issue is that newestSubmittedAt is computed from
reviews[0] before the array is reversed, which assumes the API returns reviews
in reverse chronological order. If the API returns reviews in ascending or mixed
order, this will cause the cursor to point to an old timestamp, leading to
re-emission of reviews on the next poll. Instead of using reviews[0], calculate
the maximum submitted timestamp by iterating through all review objects in the
reviews array using _getSubmittedAt and comparing their values to determine the
true newest timestamp, then pass this maximum value to _setLastSubmittedAt to
ensure the cursor always moves forward.
- Around line 68-74: The _getParams() method calls .join() on values returned by
parseObject() for channelId, type, status, and rating, but parseObject() can
return scalar strings instead of arrays. Since strings do not have a .join()
method, this causes runtime errors. Wrap each parseObject() result with logic to
ensure it returns an array before calling .join(), such as checking if the
result is an array and converting scalar values to single-element arrays, or
using a utility function that normalizes the output to always return an array.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0285a156-2719-472f-9ab5-0006b8244cf8

📥 Commits

Reviewing files that changed from the base of the PR and between 1fef104 and 8cfff29.

📒 Files selected for processing (3)
  • components/etrusted/package.json
  • components/etrusted/sources/new-review/new-review.mjs
  • components/etrusted/sources/new-review/test-event.mjs

Comment thread components/etrusted/sources/new-review/new-review.mjs Outdated
Comment thread components/etrusted/sources/new-review/new-review.mjs
Comment thread components/etrusted/sources/new-review/new-review.mjs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@components/etrusted/sources/new-review/new-review.mjs`:
- Around line 71-85: In the _toCsv method, modify the condition that checks for
null or empty values to also handle empty arrays returned by parseObject. After
calling parseObject(value), add a check to return undefined if the parsed result
is an empty array, ensuring that unset filters do not produce empty strings that
get passed as blank query parameters (like channels=, type=, status=, rating=)
to the _getParams method and ultimately to the /reviews endpoint.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 849b3bf4-7d9f-4b1b-a66d-f78436cbc53d

📥 Commits

Reviewing files that changed from the base of the PR and between 8cfff29 and 11e43e6.

📒 Files selected for processing (1)
  • components/etrusted/sources/new-review/new-review.mjs

Comment thread components/etrusted/sources/new-review/new-review.mjs
@@ -0,0 +1,16 @@
export default {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The sample event doesn't match the real CustomerReview payload. I deployed this source against a live eTrusted account and captured a real emitted event. The current fixture uses field names that don't exist in the API response (status -> actually state, channel: {id, name} -> actually channelRef string, consumer: {email} -> actually customer: {}), and omits ~11 real fields. Since sampleEmit drives downstream autocomplete, builders referencing steps.trigger.event.channel.name or .status would be building against fields that never arrive.

Suggest replacing the fixture with this real event shape (captured live, PII neutralized):

export default {
    _object: "CustomerReview",
    accountRef: "acc-5b57249d-9b51-49ef-aa8c-02b8dbad6722",
    channelRef: "chl-3de8e569-400f-4d31-9fdf-0d9b852748aa",
    comment: "Test",
    createdAt: "2026-06-25T12:47:20.793Z",
    customer: {
      email: "customer@example.com",
      firstName: "John",
      fullName: "John Doe",
      lastName: "Doe",
    },
    event: {
      id: "evt-de79c52f-f6eb-43e5-9b3b-54f548dfbb6c",
      type: "test",
    },
    feedbackType: "REVIEW",
    hasAttachments: false,
    id: "rev-c6411ca3-5e24-4913-be18-6c1c45777516",
    metadata: {
      OriginalCarModel: "Golf GTI",
      OriginalNameTP: "John Smith",
      title: "Mr.",
      nameAgent: "VW Demo Dealer",
    },
    questionnaire: {
      id: "qre-19f0315e-df85-4a39-80f1-e8a139cee10c",
      locale: "en_150",
      templateRef: "tpl-qst-b59263c2-89ef-4b4c-bbc8-cf4b5ae9725f",
    },
    rating: 5,
    state: "APPROVED",
    submittedAt: "2026-06-25T12:47:20.000Z",
    surveyData: [
      {
        questionRef: "coreStarRating",
        type: "CORE_STAR_RATING",
        userDefinedId: "coreStarRating",
        properties: {},
        value: {},
      },
      {
        questionRef: "coreReviewGood",
        type: "CORE_REVIEW",
        userDefinedId: "coreReviewGood",
        properties: {},
        value: {},
      },
      {
        questionRef: "opinionScale",
        type: "DIMENSIONS",
        userDefinedId: "opinionScale",
        properties: {},
        value: {},
      },
    ],
    title: "Test",
    transaction: {
      date: "2026-06-24T12:35:33.887Z",
      reference: "Test250626",
    },
    type: "SERVICE_REVIEW",
    updatedAt: "2026-06-25T12:47:20.859Z",
    verificationType: "VERIFIED",
  };

@ashwins01

Copy link
Copy Markdown
Contributor

Hi @lixiyuan1030-stack, thank you for your contribution! The changes LGTM, except for the one comment I've added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

User submitted Submitted by a user

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TRIGGER] Trusted Shops / eTrusted — New Review (Polling)

6 participants