Skip to content

[Customer Portal][BE] Refactor types.bal into module and standardize update API response field names - #155

Merged
Rashmika998 merged 4 commits into
wso2-open-operations:customer-portal-milestone-1from
Rashmika998:dev-app-customer-portal-types-refactor
Feb 16, 2026
Merged

Rashmika998 merged 4 commits into
wso2-open-operations:customer-portal-milestone-1from
Rashmika998:dev-app-customer-portal-types-refactor

Conversation

@Rashmika998

@Rashmika998 Rashmika998 commented Feb 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR refactors the existing types.bal file into a dedicated types module to enable reuse across modules. Additionally, it standardizes the response field names of update-related APIs by converting them from kebab-case to camelCase.

Changes

  • Moved types.bal into a new types module
  • Updated imports and references across modules
  • Standardized update API response field names (kebab-case → camelCase)
  • Updated related models, mappings, and serialization logic

Reason

1. Modularization

Extracting types.bal into a separate module improves:

  • Reusability across modules
  • Maintainability
  • Clear separation of concerns

2. Naming Convention Alignment

Update-related API responses previously used kebab-case field names, which were inconsistent with the rest of the codebase. Initially, attempt was to preserve the external kebab-case contract by using Ballerina's @jsondata:Name {"<name>"} annotation to map kebab-case JSON fields to internally defined camelCase fields. However, this approach did not work reliably in our scenario. Converting them to camelCase ensures:

  • Consistency across APIs
  • Better alignment with common backend/frontend conventions
  • Improved developer experience

Impact

⚠ Field name changes in update API responses may be a breaking change for consumers relying on kebab-case.

Testing

  • Verified module imports and compilation after refactor
  • Tested all update-related APIs to confirm updated response structure

Checklist

  • Module refactor completed
  • All references updated
  • API responses verified

Summary by CodeRabbit

  • New Features

    • Added comprehensive product update management capabilities, including support for recommended update levels, product update level tracking, and detailed file change information.
    • Introduced structured data models for product vulnerabilities and update responses.
  • Refactor

    • Standardized API field naming conventions and internal module organization for improved consistency.

@Rashmika998 Rashmika998 self-assigned this Feb 15, 2026
@Rashmika998 Rashmika998 added Type/Improvement Marks enhancements or improvements to existing features App/Customer Portal Area/Backend labels Feb 15, 2026
@coderabbitai

coderabbitai Bot commented Feb 15, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Ignoring CodeRabbit configuration file changes. For security, only the configuration from the base branch is applied for open source repositories.

📝 Walkthrough

Walkthrough

Configuration file extended to auto-review development branches. New types module introduced with comprehensive record definitions for product updates and vulnerabilities. Phone validation constant relocated to types module. Existing update types refactored to use hyphenated field names. Three utility functions added for update processing. Public signatures across service and utils standardized to use types namespace qualifier consistently.

Changes

Cohort / File(s) Summary
CI/CD Configuration
.coderabbit.yaml
Extended auto-review base branch pattern to include development branches matching dev-.* regex.
Module Registry & Constants
Dependencies.toml, constants.bal
Added new customer_portal.types module entry; removed PHONE_PATTERN_STRING constant (moved to types module).
Type Module Foundation
modules/types/types.bal
Introduced comprehensive type definitions including BasicProductInfo, RecommendedUpdateLevel, FileChanges, UpdateResponse, ListUpdatePayload, ProductUpdateLevel, and related record types; added PHONE_PATTERN_STRING constant.
Updates Type Standardization
modules/updates/types.bal
Converted all record field names from camelCase with jsondata annotations to hyphenated identifiers (e.g., productName → product-name, jwtToken → jwt); removed jsondata metadata annotations.
Update Processing Utilities
modules/updates/utils.bal
Added three new public isolated functions: processRecommendedUpdateLevels, processListUpdates, and processProductUpdateLevels to transform and structure update-related data.
Mock Data & Service Integration
mock.bal, service.bal
Expanded mock vulnerability data with additional fields; updated all public resource signatures to use types: namespace qualifiers for payloads and response types across user, project, case, deployment, vulnerability, and update endpoints.
Utility Function Signatures
utils.bal
Standardized public function signatures to consistently use types: namespace qualifiers for case search, filters, comments, attachments, and deployment-related payloads and responses.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • cs-tools#11 — Modifies project case search API and related types/service endpoints, overlapping with case search payload and response type updates.
  • cs-tools#124 — Modifies the same update types file to standardize external field names, using a complementary approach to field naming conventions.
  • cs-tools#150 — Adjusts product vulnerability types and mock data alongside service endpoint changes for the vulnerabilities feature.

Suggested reviewers

  • cloby99
  • sacheeramesh
  • shayanmalinda

Poem

🐰 A types module springs to life so clean,
Fields renamed in hyphenated sheen,
Updates process with functions new,
Namespaces aligned through and through,
The schema hops forward—bright, refined! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (13 files):

⚔️ .coderabbit.yaml (content)
⚔️ apps/customer-portal/backend/Dependencies.toml (content)
⚔️ apps/customer-portal/backend/constants.bal (content)
⚔️ apps/customer-portal/backend/mock.bal (content)
⚔️ apps/customer-portal/backend/modules/updates/types.bal (content)
⚔️ apps/customer-portal/backend/modules/updates/utils.bal (content)
⚔️ apps/customer-portal/backend/service.bal (content)
⚔️ apps/customer-portal/backend/utils.bal (content)
⚔️ apps/customer-portal/webapp/src/constants/apiConstants.ts (content)
⚔️ apps/customer-portal/webapp/src/constants/projectDetailsConstants.ts (content)
⚔️ apps/customer-portal/webapp/src/models/mockData.ts (content)
⚔️ apps/customer-portal/webapp/src/pages/ProjectDetails.tsx (content)
⚔️ apps/customer-portal/webapp/src/utils/projectStats.ts (content)

These conflicts must be resolved before merging into customer-portal-milestone-1.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: refactoring types.bal into a module and standardizing API field names from kebab-case to camelCase, which align with the primary objectives described in the PR description and raw summary.
Description check ✅ Passed The PR description addresses Purpose/Goals (modularization and naming consistency), Approach (moving types.bal into module, updating imports and field names), Reason (improved reusability and API consistency), Impact (potential breaking change), and Testing (module imports verified and APIs tested). The description is substantially complete despite not following the exact template structure.
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
  • Post copyable unit tests in a comment
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch dev-app-customer-portal-types-refactor
  • Post resolved changes as copyable diffs in a comment

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 and usage tips.

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/customer-portal/backend/service.bal (1)

1204-1287: ⚠️ Potential issue | 🟠 Major

Breaking change: update endpoints now return camelCase field names.

The update-related endpoints (recommended-update-levels, updates/search, product-update-levels) now delegate to updates:process* functions that map kebab-case wire-format fields to camelCase in the response. This changes the JSON field names seen by API consumers (e.g., product-name → productName, starting-update-level → startingUpdateLevel).

At least 9 frontend references expect kebab-case field names and will break with this change:

  • apps/customer-portal/webapp/src/models/responses.ts (lines 407, 414)
  • apps/customer-portal/webapp/src/models/mockData.ts (lines 1729-1759)
  • apps/customer-portal/webapp/src/api/__tests__/useGetProductUpdateLevels.test.tsx (lines 101, 126-129)

Update frontend code to use camelCase field names (e.g., productName, productBaseVersion, startingUpdateLevel, totalUpdates, appliedUpdateNumbers).

🧹 Nitpick comments (1)
apps/customer-portal/backend/modules/updates/utils.bal (1)

51-122: Consider extracting repeated BasicFileInfo mapping into a helper.

The BasicFileInfo kebab→camelCase mapping (5 fields) is repeated three times — once for addedFiles (lines 65-71), once for originalFile (lines 77-81), and once for newFile (lines 84-88). Extracting a small helper would reduce duplication and make future field additions less error-prone.

♻️ Proposed helper extraction
+# Map a kebab-case BasicFileInfo to camelCase types:BasicFileInfo.
+isolated function mapBasicFileInfo(BasicFileInfo info) returns types:BasicFileInfo => {
+    filePath: info.file\-path,
+    md5sum: info.md5sum,
+    sha256: info.sha256,
+    jwt: info.jwt,
+    downloadUrl: info.download\-url
+};

Then usage in processListUpdates simplifies to:

     types:BasicFileInfo[] addedFiles = from BasicFileInfo info in response.file\-changes.added\-files
-        select {
-            filePath: info.file\-path,
-            md5sum: info.md5sum,
-            sha256: info.sha256,
-            jwt: info.jwt,
-            downloadUrl: info.download\-url
-        };
+        select mapBasicFileInfo(info);

     types:ModifiedFileInfo[] modifiedFiles = from ModifiedFileInfo info in response.file\-changes.modified\-files
         select {
             'type: info.'type,
-            originalFile: {
-                filePath: info.original\-file.file\-path,
-                md5sum: info.original\-file.md5sum,
-                sha256: info.original\-file.sha256,
-                jwt: info.original\-file.jwt,
-                downloadUrl: info.original\-file.download\-url
-            },
-            newFile: {
-                filePath: info.new\-file.file\-path,
-                md5sum: info.new\-file.md5sum,
-                sha256: info.new\-file.sha256,
-                jwt: info.new\-file.jwt,
-                downloadUrl: info.new\-file.download\-url
-            }
+            originalFile: mapBasicFileInfo(info.original\-file),
+            newFile: mapBasicFileInfo(info.new\-file)
         };

@shayanmalinda shayanmalinda 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.

Let’s create a GitHub issue to remove these custom mappings once Ballerina supports JSON annotations for record types.

In the meantime, please also create an issue in Internal Ballerina Support:
https://github.com/wso2-enterprise/internal-support-ballerina

@Rashmika998
Rashmika998 merged commit c54b8b2 into wso2-open-operations:customer-portal-milestone-1 Feb 16, 2026
1 check passed
@Rashmika998 Rashmika998 moved this from Done to Staging Deployed in Customer Portal Development Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

App/Customer Portal Area/Backend Type/Improvement Marks enhancements or improvements to existing features

Projects

Status: Staging Deployed

Development

Successfully merging this pull request may close these issues.

2 participants