Skip to content

refactor: reduce filteredMparticleUser cognitive complexity for Sonar - #1336

Merged
jaissica12 merged 9 commits into
refactor/SDKE-1193-migrate-filteredMparticleUser-to-TSfrom
refactor/SDKE-1193-filteredMparticleUser-cognitive-complexity
Aug 24, 2026
Merged

refactor: reduce filteredMparticleUser cognitive complexity for Sonar#1336
jaissica12 merged 9 commits into
refactor/SDKE-1193-migrate-filteredMparticleUser-to-TSfrom
refactor/SDKE-1193-filteredMparticleUser-cognitive-complexity

Conversation

@jaissica12

Copy link
Copy Markdown
Contributor

Background

  • Follow-up to the filteredMparticleUser JS → TS migration PR.
  • SonarQube flagged cognitive complexity on the migrated module; this PR addresses that without changing product behavior.

What Has Changed

  • Hoisted helper functions to module scope (isAttributeKeyAllowed, buildUserAttributesCopy, buildFilteredUserIdentities, etc.)
  • Simplified control flow with early continue / helper extraction to satisfy Sonar cognitive complexity limits
  • No intentional public API or functional changes

Screenshots/Video

  • N/A

Checklist

  • I have performed a self-review of my own code.
  • I have made corresponding changes to the documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have tested this locally.

Additional Notes

  • Stacked on refactor/SDKE-1193-migrate-filteredMparticleUser-to-TS (migration-only).
  • Merge the migration PR first, then retarget this PR to development (or merge the stack in order).

Reference Issue (For employees only. Ignore if you are an outside contributor)

@jaissica12
jaissica12 requested a review from a team as a code owner August 19, 2026 01:16
@cursor

cursor Bot commented Aug 19, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Internal refactor of kit user-attribute/identity filtering with tests; no API or auth changes. Residual risk is a logic slip in PII filtering, which tests now cover.

Overview
Refactors kit-facing user filtering in filteredMparticleUser by pulling nested loops into module-level helpers (buildUserAttributesCopy, buildUserAttributeLists, buildFilteredUserIdentities) so Sonar cognitive complexity drops without changing the public API.

Kit blocking and forwarder attribute/identity filters still run in the same order. Array attributes continue to be copied so kits cannot mutate store values.

Adds Jest coverage for missing store data, kit-blocked keys/identities, factory vs method-argument filters, and identity-type-to-name mapping.

Reviewed by Cursor Bugbot for commit 64bda99. Bugbot is set up for automated code reviews on this repo. Configure here.

@jaissica12 jaissica12 self-assigned this Aug 19, 2026
Comment thread src/filteredMparticleUser.ts Outdated
@jaissica12
jaissica12 force-pushed the refactor/SDKE-1193-filteredMparticleUser-cognitive-complexity branch 2 times, most recently from 902aa71 to 45900ca Compare August 21, 2026 17:28
@jaissica12
jaissica12 force-pushed the refactor/SDKE-1193-filteredMparticleUser-cognitive-complexity branch from 8716d89 to 53eeece Compare August 21, 2026 18:17
@jaissica12
jaissica12 force-pushed the refactor/SDKE-1193-filteredMparticleUser-cognitive-complexity branch from 53eeece to 824c5df Compare August 24, 2026 13:29
Match Sonar and keep the same allow-when-missing-blocker behavior for attributes and identities.
Add Jest coverage for MPID, attribute/list copies, kit blocking, and identity mapping so the filtered user object is not only hit via forwarder integration tests.
Match existing Jest it() naming in this repo.
…ters

Drop the overlapping identity mapping test, split kit-block vs omit-blocker, and assert factory-then-method list filters plus Rokt-style missing userIdentityFilters.
@jaissica12
jaissica12 force-pushed the refactor/SDKE-1193-filteredMparticleUser-cognitive-complexity branch from 824c5df to 346350a Compare August 24, 2026 14:54
Comment thread src/filteredMparticleUser.ts
Co-authored-by: Cris Ryan Tan <crisryantan@gmail.com>
Comment thread src/filteredMparticleUser.ts Outdated
Comment thread src/filteredMparticleUser.ts Outdated
jaissica12 and others added 2 commits August 24, 2026 11:00
Co-authored-by: Cris Ryan Tan <crisryantan@gmail.com>
fix types

Co-authored-by: Cris Ryan Tan <crisryantan@gmail.com>
Optional kitBlocker? before required key fails TS1016. Match
isIdentityAllowed: KitBlocker | undefined, same runtime.
@sonarqubecloud

Copy link
Copy Markdown

@jaissica12
jaissica12 merged commit 0e5ee69 into development Aug 24, 2026
29 of 33 checks passed
jaissica12 added a commit that referenced this pull request Aug 24, 2026
…#1336)

* refactor: reduce filteredMparticleUser cognitive complexity for Sonar

* refactor: use optional chaining for kit blocker allow checks

Match Sonar and keep the same allow-when-missing-blocker behavior for attributes and identities.

* test: unit-cover filteredMparticleUser kit and forwarder filtering

Add Jest coverage for MPID, attribute/list copies, kit blocking, and identity mapping so the filtered user object is not only hit via forwarder integration tests.

* test: prefix filteredMparticleUser cases with should

Match existing Jest it() naming in this repo.

* test: dedupe filteredMparticleUser cases and cover dual forwarder filters

Drop the overlapping identity mapping test, split kit-block vs omit-blocker, and assert factory-then-method list filters plus Rokt-style missing userIdentityFilters.

* Apply suggestion from @crisryantan

Co-authored-by: Cris Ryan Tan <crisryantan@gmail.com>

* Apply suggestion from @crisryantan

Co-authored-by: Cris Ryan Tan <crisryantan@gmail.com>

* Apply suggestion from @crisryantan

fix types

Co-authored-by: Cris Ryan Tan <crisryantan@gmail.com>

* fix: type kitBlocker as possibly undefined before required key

Optional kitBlocker? before required key fails TS1016. Match
isIdentityAllowed: KitBlocker | undefined, same runtime.

---------

Co-authored-by: Cris Ryan Tan <crisryantan@gmail.com>
@mparticle-automation

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 2.79.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants