Skip to content

fix: zendesk identify flow (develop) - #4450

Merged
manish339k merged 5 commits into
developfrom
fix.zendesk.identify.flow.develop
Jul 7, 2025
Merged

manish339k merged 5 commits into
developfrom
fix.zendesk.identify.flow.develop

Conversation

@manish339k

Copy link
Copy Markdown
Contributor

What are the changes introduced in this PR?

For identify flow, We are transforming and delivering the event through transformer and then returning 299 status code. We have eliminated the need for searching of user id when we are updating the primary email. We have added one extra API call to delete duplicate email from the user profile.

What is the related Linear task?

Resolves INT-3793

Please explain the objectives of your changes below

Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here

Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?

N/A

Any new dependencies introduced with this change?

N/A

Any new generic utility introduced or modified. Please explain the changes.

N/A

Any technical or performance related pointers to consider with the change?

N/A

@coderabbitai review


Developer checklist

  • My code follows the style guidelines of this project

  • No breaking changes are being introduced.

  • All related docs linked with the PR?

  • All changes manually tested?

  • Any documentation changes needed with this change?

  • Is the PR limited to 10 file changes?

  • Is the PR limited to one linear task?

  • Are relevant unit and component test-cases added in new readability format?

Reviewer checklist

  • Is the type of change in the PR title appropriate as per the changes?

  • Verified that there are no credentials or confidential data exposed with the changes.

* fix: zendesk primary email update issue

* chore: minor changes

* chore: added test for updating secondary email

* chore: minor change

* chore: added util test

* chore: minor change

* chore: minor change

* chore: undo minor change

* chore: fix sonarqube code smell

* fix: addressing comments

* chore: addressing comments
* feat: update primary email verification status

* chore: remove promise.all to process the events sequentially
@manish339k
manish339k requested review from a team and sivashanmukh as code owners July 2, 2025 07:03
@manish339k
manish339k requested review from a team, krishna2020 and maheshkutty July 2, 2025 07:03
@coderabbitai

coderabbitai Bot commented Jul 2, 2025 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • test/integrations/destinations/zendesk/network.ts is excluded by !**/test/**

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Summary by CodeRabbit

  • New Features
    • Improved user email identity management with immediate updates and removals via asynchronous API interactions.
    • Enhanced batch processing for handling multiple user events with improved error handling.
  • Bug Fixes
    • More robust error reporting and logging for organization membership and user identity operations.
  • Tests
    • Expanded test coverage for user identity and organization membership utility functions, ensuring reliable API interactions.

Summary by CodeRabbit

  • New Features

    • Introduced asynchronous handling for managing Zendesk user email identities, including updating primary emails and removing duplicate email identities.
    • Added batch processing for improved handling of multiple user records with enhanced error reporting.
  • Bug Fixes

    • Improved error handling and logging for organization creation and user management operations.
  • Tests

    • Expanded test coverage for new and existing utility functions interacting with Zendesk APIs.

Walkthrough

The changes introduce asynchronous API interactions for managing Zendesk user email identities, including updating and removing emails. Core transformation and utility logic are refactored to support these async flows, and batch processing with enhanced error handling is added for router destination processing. Comprehensive unit tests are implemented for the new utility functions.

Changes

File(s) Change Summary
src/v0/destinations/zendesk/transform.js Refactored transformation logic to use async API calls for email identity management; updated identify and router destination processing to support async flows and batch processing with improved error handling. Deprecated unused functions.
src/v0/destinations/zendesk/util.js Added multiple async utility functions for Zendesk API interactions (user identities, email removal, user creation/update, org membership removal) with consistent error handling. Exported new functions.
src/v0/destinations/zendesk/util.test.js Added comprehensive unit tests for all new async utility functions, including success and failure scenarios with mocked HTTP responses.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Transform
    participant Util
    participant ZendeskAPI

    Client->>Transform: processIdentify(message, config, headers, endpoint, metadata)
    Transform->>Util: createOrUpdateUser(payload, endpoint, headers, metadata)
    Util->>ZendeskAPI: POST /users
    ZendeskAPI-->>Util: Response (userId)
    Util-->>Transform: userId

    alt Email update needed
        Transform->>Util: getUserIdentities(endpoint, headers, metadata)
        Util->>ZendeskAPI: GET /users/{userId}/identities
        ZendeskAPI-->>Util: Response (identities)
        Util-->>Transform: identities

        Transform->>Util: deleteEmailFromUser(endpoint, headers, metadata)
        Util->>ZendeskAPI: DELETE /users/{userId}/identities/{identityId}
        ZendeskAPI-->>Util: Response

        Transform->>Util: updatePrimaryEmailOfUser(endpoint, payload, headers, metadata)
        Util->>ZendeskAPI: PUT /users/{userId}/identities/{identityId}/make_primary
        ZendeskAPI-->>Util: Response
    end

    Transform-->>Client: Response (success or error)
Loading

Possibly related PRs

Suggested reviewers

  • sivashanmukh
  • yashasvibajpai
  • ItsSudip
  • maheshkutty

Suggestions for Improvement

  • Consider modularizing error handling logic further to reduce duplication across async utility functions.
  • Adding integration tests that mock Zendesk API responses end-to-end would help validate the new async flows in real scenarios.
  • Enhance logging granularity around async API calls to Zendesk for easier debugging and monitoring of failures or retries.

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@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: 2

🔭 Outside diff range comments (1)
src/v0/destinations/zendesk/transform.js (1)

77-104: Function performs action but returns unused response object

This function makes the API call to update the primary email but then returns a response object that appears to be unused by the caller. Consider either:

  1. Renaming the function to clarify it performs the action (not just builds a response)
  2. Removing the response building if it's not needed
-const responseBuilderToUpdatePrimaryAccount = async (
+const updatePrimaryEmailAccount = async (
   userIdentityId,
   userId,
   headers,
   email,
   baseEndpoint,
   metadata,
   destinationConfig,
) => {
-  const response = defaultRequestConfig();
-  const updatedHeaders = {
-    ...headers,
-    ...DEFAULT_HEADERS,
-  };
-  response.endpoint = `${baseEndpoint}users/${userId}/identities/${userIdentityId}`;
-  response.method = defaultPutRequestConfig.requestMethod;
-  response.headers = updatedHeaders;
-  response.body.JSON = {
+  const endpoint = `${baseEndpoint}users/${userId}/identities/${userIdentityId}`;
+  const payload = {
     identity: {
       type: 'email',
       value: `${email}`,
       verified: !!destinationConfig.createUsersAsVerified,
     },
   };
   // API call to update primary email of the user
-  await updatePrimaryEmailOfUser(response.endpoint, response.body.JSON, response.headers, metadata);
-  return response;
+  await updatePrimaryEmailOfUser(endpoint, payload, headers, metadata);
};
🧹 Nitpick comments (4)
src/v0/destinations/zendesk/util.js (4)

27-59: Inconsistent endpointPath in statTags

The endpointPath value 'users/userId/identities' doesn't match the actual endpoint pattern. Consider using a more accurate representation or parameterizing it.

   const statTags = {
     metadata,
     destType: 'zendesk',
-    endpointPath: 'users/userId/identities',
+    endpointPath: '/users/{userId}/identities',
     feature: 'transformation',
     requestMethod: 'GET',
     module: 'router',
   };

61-90: Generic endpointPath in statTags for delete operation

The endpointPath value '/users' is too generic and doesn't reflect the actual endpoint pattern for deleting email identities.

   const statTags = {
     metadata,
     destType: 'zendesk',
-    endpointPath: '/users',
+    endpointPath: '/users/{userId}/identities/{identityId}',
     feature: 'transformation',
     requestMethod: 'DELETE',
     module: 'router',
   };

92-122: Generic endpointPath in statTags for update operation

The endpointPath value '/users' doesn't accurately represent the endpoint for updating user identities.

   const statTags = {
     metadata,
     destType: 'zendesk',
-    endpointPath: '/users',
+    endpointPath: '/users/{userId}/identities/{identityId}',
     feature: 'transformation',
     requestMethod: 'PUT',
     module: 'router',
   };

158-187: Placeholder-like endpointPath in statTags

The endpointPath value '/membershipId.json' appears to be a placeholder and should represent the actual endpoint pattern.

   const statTags = {
     metadata,
     destType: 'zendesk',
-    endpointPath: '/membershipId.json',
+    endpointPath: '/users/{userId}/organization_memberships/{membershipId}.json',
     feature: 'transformation',
     requestMethod: 'DELETE',
     module: 'router',
   };
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f8a005e and 5ad908f.

⛔ Files ignored due to path filters (3)
  • test/integrations/destinations/zendesk/network.ts is excluded by !**/test/**
  • test/integrations/destinations/zendesk/processor/data.ts is excluded by !**/test/**
  • test/integrations/destinations/zendesk/router/data.ts is excluded by !**/test/**
📒 Files selected for processing (3)
  • src/v0/destinations/zendesk/transform.js (8 hunks)
  • src/v0/destinations/zendesk/util.js (2 hunks)
  • src/v0/destinations/zendesk/util.test.js (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.js`: Focus on ESLint errors (max 3) and warnings (max 5).

**/*.js: Focus on ESLint errors (max 3) and warnings (max 5).

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • src/v0/destinations/zendesk/util.test.js
  • src/v0/destinations/zendesk/transform.js
  • src/v0/destinations/zendesk/util.js
🧠 Learnings (2)
src/v0/destinations/zendesk/transform.js (3)
Learnt from: maheshkutty
PR: rudderlabs/rudder-transformer#4359
File: src/v0/util/index.js:2272-2272
Timestamp: 2025-05-29T13:29:39.436Z
Learning: The `combineBatchRequestsWithSameJobIds` function in `src/v0/util/index.js` is used by both Mixpanel and Google AdWords Offline Conversions destinations in production. The function assumes metadata is always an array in multiple operations (forEach, filter, sort, map) and needs defensive programming to handle non-array metadata cases to prevent runtime errors.
Learnt from: maheshkutty
PR: rudderlabs/rudder-transformer#4359
File: src/v0/util/index.js:2272-2272
Timestamp: 2025-05-29T13:29:39.436Z
Learning: The `combineBatchRequestsWithSameJobIds` function in `src/v0/util/index.js` assumes metadata is always an array throughout its implementation, but defensive programming should be added to handle cases where metadata might not be an array type to prevent runtime errors.
Learnt from: maheshkutty
PR: rudderlabs/rudder-transformer#4364
File: src/v0/util/index.js:2220-2242
Timestamp: 2025-06-02T06:25:17.338Z
Learning: In the rudderlabs/rudder-transformer codebase, jobId values are guaranteed by system contract to always be valid numbers and never undefined or infinite. Additional validation for these edge cases in sorting functions like sortBatchesByMinJobId is not necessary.
src/v0/destinations/zendesk/util.js (1)
Learnt from: maheshkutty
PR: rudderlabs/rudder-transformer#4359
File: src/v0/util/index.js:2272-2272
Timestamp: 2025-05-29T13:29:39.436Z
Learning: The `combineBatchRequestsWithSameJobIds` function in `src/v0/util/index.js` is used by both Mixpanel and Google AdWords Offline Conversions destinations in production. The function assumes metadata is always an array in multiple operations (forEach, filter, sort, map) and needs defensive programming to handle non-array metadata cases to prevent runtime errors.
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Code Coverage
  • GitHub Check: test_and_publish
  • GitHub Check: UT Tests
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (7)
src/v0/destinations/zendesk/util.js (2)

22-26: Clean implementation of status code determination

The function correctly returns appropriate status codes based on event type, following a clear and maintainable pattern.


124-156: Well-structured user creation/update function

The implementation correctly handles the create or update flow with proper error handling and returns the user ID on success.

src/v0/destinations/zendesk/util.test.js (2)

39-90: Comprehensive test coverage for getUserIdentities

Well-structured table-driven tests covering success, edge cases (missing identities), and error scenarios.


92-272: Excellent test coverage for all utility functions

The test suites maintain consistency across all functions with proper mocking, error handling verification, and both positive/negative test cases.

src/v0/destinations/zendesk/transform.js (3)

554-571: Clean refactoring using new utility functions

The implementation is streamlined by using createOrUpdateUser and properly handles the async email update flow.


783-808: Excellent refactoring with enhanced error handling

The batch processing implementation with proper error handling and sequential processing is a significant improvement over the previous approach.


522-524: Improved error logging with additional context

Adding the error details to the log message will help with debugging issues in production.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented Jul 2, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.64706% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.24%. Comparing base (537cdbf) to head (b9dc14c).
⚠️ Report is 660 commits behind head on develop.

Files with missing lines Patch % Lines
src/v0/destinations/zendesk/transform.js 95.55% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4450      +/-   ##
===========================================
+ Coverage    91.18%   91.24%   +0.05%     
===========================================
  Files          638      639       +1     
  Lines        33536    33627      +91     
  Branches      7921     7929       +8     
===========================================
+ Hits         30581    30684     +103     
- Misses        2686     2707      +21     
+ Partials       269      236      -33     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

sonarqubecloud Bot commented Jul 4, 2025

Copy link
Copy Markdown

@manish339k
manish339k merged commit 6dc3b84 into develop Jul 7, 2025
@manish339k
manish339k deleted the fix.zendesk.identify.flow.develop branch July 7, 2025 05:31
vinayteki95 pushed a commit that referenced this pull request Jul 8, 2025
* fix: zendesk indentify flow (#4288)

* fix: zendesk primary email update issue

* chore: minor changes

* chore: added test for updating secondary email

* chore: minor change

* chore: added util test

* chore: minor change

* chore: minor change

* chore: undo minor change

* chore: fix sonarqube code smell

* fix: addressing comments

* chore: addressing comments

* feat: update primary email verification status (#4400)

* feat: update primary email verification status

* chore: remove promise.all to process the events sequentially

* chore: addressing comment

* chore: fix sonar issue

* chore: cleanup test network calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants