Skip to content

refactor(condo): DOMA-12673 remove validate.js#7626

Open
vovaaxeapolla wants to merge 2 commits into
mainfrom
condo/refactor/DOMA-12673/remove-validate-js
Open

refactor(condo): DOMA-12673 remove validate.js#7626
vovaaxeapolla wants to merge 2 commits into
mainfrom
condo/refactor/DOMA-12673/remove-validate-js

Conversation

@vovaaxeapolla
Copy link
Copy Markdown
Contributor

@vovaaxeapolla vovaaxeapolla commented May 19, 2026

Summary by CodeRabbit

Release Notes

  • Refactor

    • Simplified JSON object validation logic across billing, acquiring, and notification services for improved consistency and maintainability.
  • Chores

    • Removed validate.js dependency from core packages.
    • Updated subproject commit references.
  • Tests

    • Updated validation test suite to reflect changes in validation approach.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 19, 2026

Warning

Rate limit exceeded

@vovaaxeapolla has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 50 minutes and 8 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 959d02f7-6f4c-4c97-90f3-5275163f904e

📥 Commits

Reviewing files that changed from the base of the PR and between 6b457c6 and cc0c428.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (2)
  • apps/rb
  • packages/keystone/plugins/dvAndSender.js
📝 Walkthrough

Walkthrough

This PR migrates JSON validation away from validate.js by introducing lightweight validators that check only object presence and dv===1 without schema constraints, replacing the schema-aware hasValidJsonStructure function across multiple domains and removing the validate.js dependency entirely.

Changes

Validation Refactoring: Removing validate.js and Simplifying JSON Object Validators

Layer / File(s) Summary
Core JSON validators and error constants
apps/condo/domains/common/utils/validation.utils.js, apps/condo/domains/common/constants/errors.js
New hasRequiredJsonObject and hasOptionalJsonObject validators check object presence (when required), object type, and dv === 1 without schema constraint validation; error constant JSON_UNKNOWN_VERSION_ERROR replaces JSON_WRONG_VERSION_FORMAT_ERROR.
Validator test coverage
apps/condo/domains/common/utils/validation.utils.spec.js
Tests cover required/optional JSON object validation, missing-field and non-object failures, unknown dv errors, and valid object passes; optional variant allows missing fields.
Domain schema migrations
apps/condo/domains/acquiring/schema/AcquiringIntegrationContext.js, apps/condo/domains/billing/schema/BillingAccount.js, apps/condo/domains/billing/schema/BillingIntegrationOrganizationContext.js, apps/condo/domains/notification/schema/Message.js, apps/condo/domains/notification/schema/MessageBatch.js
Acquiring, Billing, and Notification schemas update settings, state, meta, and processingMeta field validators from hasValidJsonStructure(args, isRequired, 1, {}) to hasRequiredJsonObject(args) or hasOptionalJsonObject(args) matching original required/optional semantics.
dv+sender validation migration
packages/keystone/plugins/dvAndSender.js
Replaces validate.js rules-based sender validation with Ajv JSON-schema; fingerprint and dv constraints compile to validateSender and errors derive from Ajv error list instead of validate.js rule list.
Dependency cleanup
apps/condo/package.json, packages/keystone/package.json
Removes validate.js from dependencies after migration to Ajv and lightweight validators is complete.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • sitozzz
  • nomerdvadcatpyat
  • SavelevMatthew

Poem

🐰 Goodbye validate.js, hello simple and lean,
Ajv now handles the sender routine,
hasRequiredJsonObject keeps schemas pristine,
No more constraints cluttering the scene! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of the pull request: removing the validate.js dependency across multiple files and replacing its functionality with alternative validation approaches.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch condo/refactor/DOMA-12673/remove-validate-js

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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 `@apps/condo/domains/billing/schema/BillingAccount.js`:
- Around line 94-95: The current check calls hasRequiredJsonObject(args) and
then unconditionally prepends JSON_EXPECT_OBJECT_ERROR when adding an error,
which causes duplicate/misleading messages; update the failing branch so it does
NOT prepend JSON_EXPECT_OBJECT_ERROR and instead either rely solely on the error
already recorded by hasRequiredJsonObject(args) or add a single concise message
(e.g., using fieldPath and "field type error. We expect JSON Object") via
addFieldValidationError; change the code around hasRequiredJsonObject,
addFieldValidationError, JSON_EXPECT_OBJECT_ERROR and fieldPath accordingly so
duplicate/error-prefixing is removed.

In `@apps/rb`:
- Line 1: The submodule entry in .gitmodules references repo URL
git@github.com:open-condo-software/condo-rb.git and SHA
16cb9f5ee9ce11f3604124b2ece4fb44200649db which cannot be found; update
.gitmodules (and any gitlink in the index) to point to an existing repository
and a pushed commit SHA: either correct the URL to the actual repository for
condo-rb, or push the missing commit to the specified repo, then run git
submodule sync and git update-index --refresh (or re-add the submodule with git
submodule add) so the submodule pointer (the gitlink) is valid for CI and local
clones.

In `@packages/keystone/plugins/dvAndSender.js`:
- Around line 61-66: The formatted details string can show "undefined" for
root-level Ajv errors because error.instancePath is empty and
error.params.missingProperty may be undefined; update the mapping inside the
failing branch (around validateSender, isValidSender, validateSender.errors and
details) to compute a safe key like: derive key =
(error.instancePath.replace('/', '') || error.params?.missingProperty || 'root')
and then use that key when building the `${key}: '${error.message}'` fragment so
root-level errors produce a sensible label (e.g., "root") instead of
"undefined".
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: dd203d4c-d758-4e01-807c-8022628d2886

📥 Commits

Reviewing files that changed from the base of the PR and between e802124 and 6b457c6.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (15)
  • apps/condo/domains/acquiring/schema/AcquiringIntegrationContext.js
  • apps/condo/domains/billing/schema/BillingAccount.js
  • apps/condo/domains/billing/schema/BillingIntegrationOrganizationContext.js
  • apps/condo/domains/common/constants/errors.js
  • apps/condo/domains/common/utils/validation.utils.js
  • apps/condo/domains/common/utils/validation.utils.spec.js
  • apps/condo/domains/notification/schema/Message.js
  • apps/condo/domains/notification/schema/MessageBatch.js
  • apps/condo/package.json
  • apps/eps
  • apps/insurance
  • apps/rb
  • apps/telephony
  • packages/keystone/package.json
  • packages/keystone/plugins/dvAndSender.js
💤 Files with no reviewable changes (3)
  • apps/condo/package.json
  • packages/keystone/package.json
  • apps/condo/domains/common/constants/errors.js

Comment on lines +94 to 95
if (!hasRequiredJsonObject(args))
return addFieldValidationError(`${JSON_EXPECT_OBJECT_ERROR}${fieldPath}] ${fieldPath} field type error. We expect JSON Object`)
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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Avoid appending a misleading second validation error.

On Line 94-95, hasRequiredJsonObject(args) already records a specific error; adding JSON_EXPECT_OBJECT_ERROR on every false result can produce duplicate or incorrect messaging (notably for dv mismatch cases).

Suggested fix
-                    if (!hasRequiredJsonObject(args))
-                        return addFieldValidationError(`${JSON_EXPECT_OBJECT_ERROR}${fieldPath}] ${fieldPath} field type error. We expect JSON Object`)
+                    if (!hasRequiredJsonObject(args)) return
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!hasRequiredJsonObject(args))
return addFieldValidationError(`${JSON_EXPECT_OBJECT_ERROR}${fieldPath}] ${fieldPath} field type error. We expect JSON Object`)
if (!hasRequiredJsonObject(args)) return
🤖 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 `@apps/condo/domains/billing/schema/BillingAccount.js` around lines 94 - 95,
The current check calls hasRequiredJsonObject(args) and then unconditionally
prepends JSON_EXPECT_OBJECT_ERROR when adding an error, which causes
duplicate/misleading messages; update the failing branch so it does NOT prepend
JSON_EXPECT_OBJECT_ERROR and instead either rely solely on the error already
recorded by hasRequiredJsonObject(args) or add a single concise message (e.g.,
using fieldPath and "field type error. We expect JSON Object") via
addFieldValidationError; change the code around hasRequiredJsonObject,
addFieldValidationError, JSON_EXPECT_OBJECT_ERROR and fieldPath accordingly so
duplicate/error-prefixing is removed.

Comment thread apps/rb Outdated
Comment on lines +61 to 66
const isValidSender = validateSender(sender)

if (!isValidSender) {
const details = validateSender.errors
.map(error => `${error.instancePath.replace('/', '') || error.params.missingProperty}: '${error.message}'`)
.join(', ')
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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

In Ajv validation errors, what fields are present for root-level typeerrors versusrequirederrors, and when isparams.missingProperty defined?

💡 Result:

In Ajv, validation errors are represented by an ErrorObject, which contains standard fields such as keyword, instancePath, schemaPath, and params [1]. The specific fields within the params object depend on the validation keyword that failed [1]. For root-level type errors and required errors, the params object contains the following: Type Errors: When a type validation fails, the params object includes a type property, which specifies the expected type(s) [1][2]. For example, if a schema expects an object but receives a string, the params object will be { type: "object" } [2]. Required Errors: When a required validation fails, the params object includes a missingProperty property [1][3]. This property explicitly identifies the name of the field that was missing from the data instance [4][3]. Regarding params.missingProperty: The params.missingProperty field is defined specifically when the required keyword fails validation [1][3]. It provides the key of the missing property, allowing applications to programmatically determine which field caused the validation failure [4][3]. If multiple properties are missing, Ajv will report them individually if the allErrors option is enabled; otherwise, it typically reports the first missing property encountered [4].

Citations:


🏁 Script executed:

find . -name "dvAndSender.js" -type f

Repository: open-condo-software/condo

Length of output: 112


🏁 Script executed:

cat -n ./packages/keystone/plugins/dvAndSender.js | sed -n '50,75p'

Repository: open-condo-software/condo

Length of output: 1381


🏁 Script executed:

cat -n ./packages/keystone/plugins/dvAndSender.js | head -50

Repository: open-condo-software/condo

Length of output: 2073


🏁 Script executed:

rg "validateSender" ./packages/keystone/plugins/dvAndSender.js -A 2 -B 2

Repository: open-condo-software/condo

Length of output: 446


Handle root-level Ajv errors when formatting details.

When validation fails with a root-level type error (e.g., sender is not an object), instancePath is empty and params.missingProperty is undefined, causing the current code to emit undefined: 'must be object'. Apply the fix to provide a sensible fallback:

Proposed fix
-        const details = validateSender.errors
-            .map(error => `${error.instancePath.replace('/', '') || error.params.missingProperty}: '${error.message}'`)
+        const details = validateSender.errors
+            .map(error => {
+                const field = error.instancePath.replace(/^\//, '') || error.params.missingProperty || 'sender'
+                return `${field}: '${error.message}'`
+            })
             .join(', ')
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const isValidSender = validateSender(sender)
if (!isValidSender) {
const details = validateSender.errors
.map(error => `${error.instancePath.replace('/', '') || error.params.missingProperty}: '${error.message}'`)
.join(', ')
const isValidSender = validateSender(sender)
if (!isValidSender) {
const details = validateSender.errors
.map(error => {
const field = error.instancePath.replace(/^\//, '') || error.params.missingProperty || 'sender'
return `${field}: '${error.message}'`
})
.join(', ')
🤖 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/keystone/plugins/dvAndSender.js` around lines 61 - 66, The formatted
details string can show "undefined" for root-level Ajv errors because
error.instancePath is empty and error.params.missingProperty may be undefined;
update the mapping inside the failing branch (around validateSender,
isValidSender, validateSender.errors and details) to compute a safe key like:
derive key = (error.instancePath.replace('/', '') ||
error.params?.missingProperty || 'root') and then use that key when building the
`${key}: '${error.message}'` fragment so root-level errors produce a sensible
label (e.g., "root") instead of "undefined".

@sonarqubecloud
Copy link
Copy Markdown

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants