Repository navigation
feat: user details adjusts - SFS-2950 - #3306
Conversation
Extends the commerce client surface with two B2B-related additions
needed by the userDetails resolver:
- `commerce.licenseManager.getUserRoles({ userId })` calls
/api/license-manager/storefront/users/{userId}/roles and returns the
user roles (`Roles: [{ Id, Name }]`) and email.
- `profile.phone` is now requested from the VTEX Sessions API and
reflected in the `Profile` type, providing a fallback phone source
for users that don't have a record on the B2B `shopper` Master Data
entity.
Refs SFS-2950
Replaces the mocked role and partial user data with real values sourced from existing commerce client methods, aligning the My Account user details page with the data model used by the Buyer Portal Organization Account page. - `StoreUserDetails` is extended with `username` and `phone`. - `userDetails` resolver now resolves the JWT user id and fans out in parallel to `commerce.session`, `commerce.masterData.getShopperById`, and the new `commerce.licenseManager.getUserRoles`. - Real role names (`Roles[].Name`) replace the previous `['Admin']` mock. - Phone falls back from the B2B `shopper` Master Data entity to the standard VTEX `profile.phone` when the shopper record does not exist or does not contain a phone. - Name is composed from `firstName + lastName` (Master Data, with session profile fallback), fixing the previous behavior that dropped `lastName`. Refs SFS-2950
Updates the My Account User Details page to match the data model and layout of the Buyer Portal Organization Account page (PRD REQ 1): - Adds `username` and `phone` fields to the `ServerUserDetailsQuery` and the page-level types. - Adds `Username` and `Phone number` rows to the `AccountTable`, preserving the existing component (no layout rewrite). - Wraps role tags inside a single `[data-fs-user-details-row-tags]` container so multiple roles flow with `flex-wrap` instead of forcing horizontal scroll on narrow viewports. - Organizational unit row remains text-only (no Change button), as specified by the PRD. Refs SFS-2950
WalkthroughThis PR expands the user details feature by introducing phone and username fields across the backend and frontend. The backend now fetches user roles from VTEX License Manager instead of hard-coding them, while the frontend displays the additional contact fields in the account details table. ChangesUser Details Expansion with License Manager Roles
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/core/src/pages/pvt/account/user-details.tsx (1)
179-179:⚠️ Potential issue | 🟡 Minor | ⚡ Quick win
?? {}doesn't satisfy the extendedUserDetailsPagePros.userDetailstype — TypeScript strict mode violation.
UserDetailsPagePros.userDetailsnow requires six non-optional fields (username,name,phone,role,orgUnit). Passing{}as a fallback is a type error under strict mode and is only reachable in a path that should have already been redirected. Provide a complete default to keep the compiler happy and the type contract explicit.🛡️ Proposed fix
- userDetails: userDetails.data?.userDetails ?? {}, + userDetails: userDetails.data?.userDetails ?? { + username: '', + name: '', + email: '', + phone: '', + role: [], + orgUnit: '', + },As per coding guidelines: "Ensure type safety and avoid type assertions when possible" and "Use TypeScript strict mode for all TypeScript files in the project".
🤖 Prompt for 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. In `@packages/core/src/pages/pvt/account/user-details.tsx` at line 179, The fallback for userDetails (currently "userDetails: userDetails.data?.userDetails ?? {}") violates the UserDetailsPagePros.userDetails type because {} lacks the required fields; replace the empty-object fallback with a complete default object matching the six required properties (username, name, email, phone, role, orgUnit) so the expression becomes userDetails: userDetails.data?.userDetails ?? { username: '', name: '', email: '', phone: '', role: '', orgUnit: '' } (or other sensible defaults), ensuring the type contract is satisfied without using type assertions; update the code that reads userDetails (the userDetails.data?.userDetails usage) accordingly.
🤖 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 `@packages/api/src/platforms/vtex/clients/commerce/index.ts`:
- Around line 707-723: The resolver that calls the getUserRoles client currently
swallows all errors with .catch(() => null); update the resolver to handle
failures explicitly: call getUserRoles (the method defined in this file) and
replace the blanket .catch with logic that inspects the error (e.g., check
status or error code), emits a processLogger/telemetry event for authorization
failures (403) and other errors, and then returns an appropriate fallback (empty
Roles array or null) instead of silently swallowing; ensure you reference the
getUserRoles call site in the resolver and add logging/telemetry for both
expected auth errors and unexpected failures.
In `@packages/api/src/platforms/vtex/resolvers/query.ts`:
- Around line 595-603: The resolver is not using the VTEX session fallbacks for
name and phone; update the construction of fullName and the phone return to fall
back to session profile values when shopper/shopperResult fields are missing:
for fullName (variable fullName) use shopper?.firstName/lastName, then
shopperResult's names if available, then sessions.profile.firstName/lastName
before defaulting to '', and for phone use shopper?.phone then
shopperResult?.phone then sessions.profile.phone before ''. Locate these in the
query resolver where fullName, shopper (and any shopperResult) and the returned
phone value are defined and wire the session.profile fallbacks accordingly while
keeping authentication?.storeUserEmail usage unchanged for username/email.
---
Outside diff comments:
In `@packages/core/src/pages/pvt/account/user-details.tsx`:
- Line 179: The fallback for userDetails (currently "userDetails:
userDetails.data?.userDetails ?? {}") violates the
UserDetailsPagePros.userDetails type because {} lacks the required fields;
replace the empty-object fallback with a complete default object matching the
six required properties (username, name, email, phone, role, orgUnit) so the
expression becomes userDetails: userDetails.data?.userDetails ?? { username: '',
name: '', email: '', phone: '', role: '', orgUnit: '' } (or other sensible
defaults), ensuring the type contract is satisfied without using type
assertions; update the code that reads userDetails (the
userDetails.data?.userDetails usage) accordingly.
🪄 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: CHILL
Plan: Pro
Run ID: b33d04a6-b14c-49e2-8eaa-38e8b58aa2b4
⛔ Files ignored due to path filters (3)
packages/api/src/__generated__/schema.tsis excluded by!**/__generated__/**and included bypackages/**packages/core/@generated/gql.tsis excluded by!**/@generated/**,!**/@generated/**and included bypackages/**packages/core/@generated/graphql.tsis excluded by!**/@generated/**,!**/@generated/**and included bypackages/**
📒 Files selected for processing (6)
packages/api/src/platforms/vtex/clients/commerce/index.tspackages/api/src/platforms/vtex/clients/commerce/types/Session.tspackages/api/src/platforms/vtex/resolvers/query.tspackages/api/src/platforms/vtex/typeDefs/query.graphqlpackages/core/src/components/account/MyAccountUserDetails/MyAccountUserDetails.tsxpackages/core/src/pages/pvt/account/user-details.tsx
| getUserRoles: ({ | ||
| userId, | ||
| }: { userId: string }): Promise<{ | ||
| Email: string | ||
| Roles: Array<{ Id: number; Name: string }> | ||
| }> => { | ||
| const headers: HeadersInit = withAutCookie(forwardedHost, account) | ||
|
|
||
| return fetchAPI( | ||
| `${base}/api/license-manager/storefront/users/${userId}/roles`, | ||
| { | ||
| method: 'GET', | ||
| headers, | ||
| }, | ||
| {} | ||
| ) | ||
| }, |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify that View_Storefront_User_Permissions is documented as auto-granted
# to storefront users and search for any error-handling pattern for 403 on this path.
rg -n "View_Storefront_User_Permissions\|getUserRoles\|licenseManager" --type ts -A3 -B3Repository: vtex/faststore
Length of output: 40
🏁 Script executed:
fd -type f "index.ts" | grep -E "commerce|vtex" | head -20Repository: vtex/faststore
Length of output: 229
🏁 Script executed:
find . -path "*/vtex/clients/commerce/index.ts" 2>/dev/nullRepository: vtex/faststore
Length of output: 118
🏁 Script executed:
git ls-files | grep -i "vtex.*commerce" | head -20Repository: vtex/faststore
Length of output: 1316
🏁 Script executed:
wc -l packages/api/src/platforms/vtex/clients/commerce/index.tsRepository: vtex/faststore
Length of output: 120
🏁 Script executed:
sed -n '700,730p' packages/api/src/platforms/vtex/clients/commerce/index.tsRepository: vtex/faststore
Length of output: 850
🏁 Script executed:
rg -n "getUserRoles" packages/api/src/platforms/vtex/clients/commerce/index.ts -A5 -B5Repository: vtex/faststore
Length of output: 334
🏁 Script executed:
rg -n "getUserRoles" packages/api/src/platforms/vtex --type ts -A10 -B2 | head -100Repository: vtex/faststore
Length of output: 2355
🏁 Script executed:
rg -n "\.catch.*null\|\.catch\(\)" packages/api/src/platforms/vtex --type ts -A2 -B2 | grep -A3 -B3 "getUserRoles\|licenseManager"Repository: vtex/faststore
Length of output: 40
🏁 Script executed:
find packages/api/src -name "*.graphql" -o -name "*.ts" | xargs grep -l "getUserRoles" 2>/dev/nullRepository: vtex/faststore
Length of output: 167
🏁 Script executed:
sed -n '580,610p' packages/api/src/platforms/vtex/resolvers/query.tsRepository: vtex/faststore
Length of output: 1175
🏁 Script executed:
sed -n '570,620p' packages/api/src/platforms/vtex/resolvers/query.tsRepository: vtex/faststore
Length of output: 1622
🏁 Script executed:
rg -n "View_Storefront_User_Permissions\|license.manager\|licenseManager" packages/api/src/platforms/vtex -A2 -B2Repository: vtex/faststore
Length of output: 40
🏁 Script executed:
sed -n '550,595p' packages/api/src/platforms/vtex/resolvers/query.tsRepository: vtex/faststore
Length of output: 1573
🏁 Script executed:
rg -n "\.catch\(\(\) => null\)" packages/api/src/platforms/vtex/resolvers/query.ts | head -20Repository: vtex/faststore
Length of output: 372
Consider explicit error handling at the resolver level for getUserRoles failures.
The getUserRoles client method is correctly implemented, but the resolver's error handling at line 588 uses .catch(() => null), which silently swallows all errors including 403 responses. This is consistent with other API calls in the resolver (session, getShopperById), but if authorization failures are expected or should be tracked, add explicit logging or error telemetry instead of silent degradation to an empty roles array.
🤖 Prompt for 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.
In `@packages/api/src/platforms/vtex/clients/commerce/index.ts` around lines 707 -
723, The resolver that calls the getUserRoles client currently swallows all
errors with .catch(() => null); update the resolver to handle failures
explicitly: call getUserRoles (the method defined in this file) and replace the
blanket .catch with logic that inspects the error (e.g., check status or error
code), emits a processLogger/telemetry event for authorization failures (403)
and other errors, and then returns an appropriate fallback (empty Roles array or
null) instead of silently swallowing; ensure you reference the getUserRoles call
site in the resolver and add logging/telemetry for both expected auth errors and
unexpected failures.
## What's the purpose of this pull request? Bring `dev` into `main` so the next CD run on `main` cuts and publishes `@faststore/*@4.1.0`. Includes the publish-pipeline fix from #3309, so this is also the first release that exercises the `pnpm -r publish` flow end-to-end (broken `4.0.0` is superseded by `4.1.0` as `latest`). ## What's included since v4.0.0 - #3308 — fix: PLP "Load more products" overwriting list instead of appending - #3306 — feat: user details adjusts — SFS-2950 - #3304 — fix: updates schemas vtex.faststore - #3301 — fix: localization selector stale and reset selection for unsaved changes - `d1e40abe7` — fix: add repository field to diagnostics package for OIDC provenance - #3309 — fix: publish releases with pnpm to resolve workspace and catalog protocols (already on `main`, kept by 3-way merge) ## How CD will behave on merge 1. `lerna version --conventional-commits --conventional-graduate --yes` graduates `4.1.0-dev.1` → `4.1.0`, creates tag `v4.1.0`, and pushes the `[no ci] Release: 4.1.0` commit. 2. `pnpm release:verify` packs every public package and asserts no `workspace:` / `catalog:` literal survives the pack step. 3. `pnpm -r publish --access public --no-git-checks` uploads the 8 public packages with all `workspace:*` / `catalog:` references rewritten to concrete versions. ## Sanity checks already performed locally - `git merge-tree` between `origin/main` and `origin/dev`: clean, no conflicts. - `pnpm install --frozen-lockfile` on the merged tree: no lockfile drift. - `pnpm release:verify` on `release/4.1.0`: all 8 public packages clean at `4.1.0-dev.1` (the same manifests that will be bumped to `4.1.0`). ## Follow-ups (not blocking) - Once `4.1.0` is on `latest`, consider `npm deprecate @faststore/<pkg>@4.0.0 "Broken release: workspace:/catalog: not resolved. Use 4.1.0+"` for `cli`, `core`, `api`, `ui`, `components`, `sdk`, `diagnostics`, `lighthouse`. - Optional: add `workflow_dispatch` to `release.yml` so future hotfix releases without `packages/*` changes can be triggered manually with `--force-publish`. Made with [Cursor](https://cursor.com) --------- Co-authored-by: Larícia Mota <[email protected]> Co-authored-by: Matheus P. Silva <[email protected]> Co-authored-by: Leandro Rodrigues <[email protected]> Co-authored-by: vtexgithubbot <[email protected]> Co-authored-by: Lucas Feijó <[email protected]> Co-authored-by: Luiz Falcão <[email protected]> Co-authored-by: Artur Santiago <[email protected]> Co-authored-by: Sahan Jayawardana <[email protected]> Co-authored-by: Mateus Pontes <[email protected]> Co-authored-by: Matheus Martins <[email protected]> Co-authored-by: renatomaurovtex <[email protected]> Co-authored-by: Leandro Rodrigues <[email protected]> Co-authored-by: Fanny Chien <[email protected]> Co-authored-by: Arthur Andrade <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Thiago Pereira <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Giuliana Rigaud <[email protected]> Co-authored-by: renato <[email protected]> Co-authored-by: Bruna Santos <[email protected]> Co-authored-by: BrunaCubos <[email protected]> Co-authored-by: Ícaro Oliveira <[email protected]> Co-authored-by: Bruna Santos <[email protected]> Co-authored-by: Everton Ataide <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Otavio Moreira Meirelles <[email protected]> Co-authored-by: Marco Cardoso <[email protected]> Co-authored-by: Gabriel Paladino <[email protected]> Co-authored-by: CodeRabbit <[email protected]>
What's the purpose of this pull request?
This pull request enhances the user details functionality by adding support for displaying and handling a user's phone number and username throughout the stack. It updates the GraphQL schema, backend resolvers, and frontend components to ensure these fields are retrieved, stored, and shown in the UI. Additionally, user roles are now dynamically fetched from the license manager service.
example:
Summary by CodeRabbit