Skip to content

Conversation

@d-gubert
Copy link
Member

@d-gubert d-gubert commented Jan 27, 2026

Proposed changes (including videos or screenshots)

Livechat portion extracted from #38227

Issue(s)

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Bug Fixes
    • Livechat custom fields: validation adjusted so custom field IDs may be null and the prior strict name pre-check has been removed. The API and save flows now accept nullable customFieldId and allow create/update to proceed without the earlier explicit invalid-name rejection, making creation and updates of Livechat custom fields more flexible and less likely to be rejected.

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot
Copy link

changeset-bot bot commented Jan 27, 2026

⚠️ No Changeset found

Latest commit: e6cb1db

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Jan 27, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is targeting the wrong base branch. It should target 8.2.0, but it targets 8.1.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

Walkthrough

Removed strict customFieldId/name validation and made custom-field ID nullable across REST types and model methods, allowing creation flows to proceed without pre-checking the identifier.

Changes

Cohort / File(s) Summary
API Endpoint
apps/meteor/app/livechat/server/api/v1/customField.ts
Removed regex pre-validation that rejected invalid customFieldId/field names; endpoint now proceeds to lookup/create without an explicit invalid-name failure path.
REST types & schema
packages/rest-typings/src/v1/omnichannel.ts
Schema updated: customFieldId and customFieldData.field use pattern ^[0-9a-zA-Z_-]+$; parameter type for save endpoint now allows `customFieldId: string
Model typings
packages/model-typings/src/models/ILivechatCustomFieldModel.ts
createOrUpdateCustomField signature changed: _id: string → `_id: string
Model implementation
packages/models/src/models/LivechatCustomField.ts
createOrUpdateCustomField parameter widened to `string

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • tassoevan
  • sampaiodiego
  • ggazzo

Poem

🐰 I hopped through code with joyful cheer,
Names unchained, no strict veneer,
Null seeds planted, new fields grow,
IDs appear as soft winds blow,
Hooray — less fuss, more flow! 🌱

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore: standardize schema definition for livechat/custom-fields.save' accurately describes the main change—standardizing schema definitions and allowing nullable customFieldId across multiple files.
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 docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/improve-livechat-customfield-endpoint

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.

@d-gubert d-gubert added this to the 8.2.0 milestone Jan 27, 2026
@codecov
Copy link

codecov bot commented Jan 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.79%. Comparing base (c6ec7a9) to head (e6cb1db).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #38376      +/-   ##
===========================================
+ Coverage    70.77%   70.79%   +0.01%     
===========================================
  Files         3159     3159              
  Lines       109401   109401              
  Branches     19675    19674       -1     
===========================================
+ Hits         77428    77448      +20     
+ Misses       29944    29928      -16     
+ Partials      2029     2025       -4     
Flag Coverage Δ
unit 71.94% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@github-actions
Copy link
Contributor

github-actions bot commented Jan 27, 2026

📦 Docker Image Size Report

➡️ Changes

Service Current Baseline Change Percent
sum of all images 0B 0B 0B
account-service 0B 0B 0B
authorization-service 0B 0B 0B
ddp-streamer-service 0B 0B 0B
omnichannel-transcript-service 0B 0B 0B
presence-service 0B 0B 0B
queue-worker-service 0B 0B 0B
rocketchat 0B 0B 0B

📊 Historical Trend

---
config:
  theme: "dark"
  xyChart:
    width: 900
    height: 400
---
xychart
  title "Image Size Evolution by Service (Last 30 Days + This PR)"
  x-axis ["11/18 22:53", "11/19 23:02", "11/21 16:49", "11/24 17:34", "11/27 22:32", "11/28 19:05", "12/01 23:01", "12/02 21:57", "12/03 21:00", "12/04 18:17", "12/05 21:56", "12/08 20:15", "12/09 22:17", "12/10 23:26", "12/11 21:56", "12/12 22:45", "12/13 01:34", "12/15 22:31", "12/16 22:18", "12/17 21:04", "12/18 23:12", "12/19 23:27", "12/20 21:03", "12/22 18:54", "12/23 16:16", "12/24 19:38", "12/25 17:51", "12/26 13:18", "12/29 19:01", "12/30 20:52", "01/27 21:46 (PR)"]
  y-axis "Size (GB)" 0 --> 0.5
  line "account-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "authorization-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "ddp-streamer-service" [0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.00]
  line "omnichannel-transcript-service" [0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "presence-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "queue-worker-service" [0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "rocketchat" [0.35, 0.35, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.00]
Loading

Statistics (last 30 days):

  • 📊 Average: 1.5GiB
  • ⬇️ Minimum: 1.4GiB
  • ⬆️ Maximum: 1.6GiB
  • 🎯 Current PR: 0B
ℹ️ About this report

This report compares Docker image sizes from this build against the develop baseline.

  • Tag: pr-38376
  • Baseline: develop
  • Timestamp: 2026-01-27 21:46:40 UTC
  • Historical data points: 30

Updated: Tue, 27 Jan 2026 21:46:40 GMT

@d-gubert d-gubert force-pushed the chore/improve-livechat-customfield-endpoint branch from e8e1db7 to 08e89d1 Compare January 27, 2026 20:49
@d-gubert d-gubert marked this pull request as ready for review January 27, 2026 20:49
@d-gubert d-gubert requested review from a team as code owners January 27, 2026 20:49
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Copy link
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: 0

Caution

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

⚠️ Outside diff range comments (1)
packages/models/src/models/LivechatCustomField.ts (1)

52-70: Use explicit null/undefined check for _id parameter.

With _id: string | null, the truthy check if (_id) treats empty string as "create," which could cause unintended inserts if an invalid ID slips through. Use if (_id != null) instead.

Suggested fix
-		if (_id) {
+		if (_id != null) {
 			await this.updateOne({ _id }, { $set: record });
 		} else {
 			record._id = field;
 			await this.insertOne(record);
 		}
🧹 Nitpick comments (1)
packages/rest-typings/src/v1/omnichannel.ts (1)

4502-4504: Align type optionality with schema.

The schema doesn’t require customFieldId, but the compiled type does. Consider making it optional to keep the type guard sound.

✅ Suggested fix
-export const isPOSTLivechatSaveCustomFieldsParams = ajv.compile<{
-	customFieldId: string | null;
+export const isPOSTLivechatSaveCustomFieldsParams = ajv.compile<{
+	customFieldId?: string | null;
 	customFieldData: Omit<ILivechatCustomField, '_id' | '_updatedAt'> & { field: string };
 }>(POSTLivechatSaveCustomFieldsSchema);

Copy link
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: 1

🤖 Fix all issues with AI agents
In `@packages/rest-typings/src/v1/omnichannel.ts`:
- Around line 4446-4449: The JSON Schema for the property customFieldId
currently only allows a string but the TypeScript type permits string | null;
update the schema for customFieldId (the property in the omnichannel schema) to
accept null as well — for example by adding "nullable: true" to the
customFieldId schema object (or change type to ["string","null"]) while keeping
the pattern validation for non-null strings.

Comment on lines 4446 to 4449
customFieldId: {
type: 'string',
pattern: '^[0-9a-zA-Z_-]+$',
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Schema missing nullable: true for customFieldId.

The TypeScript type at line 4502 declares customFieldId: string | null, but the JSON Schema defines it as type: 'string' without nullable: true. AJV will reject requests where customFieldId is explicitly set to null, causing a mismatch with the declared TypeScript type.

🐛 Proposed fix
 customFieldId: {
   type: 'string',
+  nullable: true,
   pattern: '^[0-9a-zA-Z_-]+$',
 },
📝 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
customFieldId: {
type: 'string',
pattern: '^[0-9a-zA-Z_-]+$',
},
customFieldId: {
type: 'string',
nullable: true,
pattern: '^[0-9a-zA-Z_-]+$',
},
🤖 Prompt for AI Agents
In `@packages/rest-typings/src/v1/omnichannel.ts` around lines 4446 - 4449, The
JSON Schema for the property customFieldId currently only allows a string but
the TypeScript type permits string | null; update the schema for customFieldId
(the property in the omnichannel schema) to accept null as well — for example by
adding "nullable: true" to the customFieldId schema object (or change type to
["string","null"]) while keeping the pattern validation for non-null strings.

@d-gubert d-gubert marked this pull request as draft January 27, 2026 22:40
@d-gubert
Copy link
Member Author

d-gubert commented Jan 27, 2026

@KevLehman and I found out there is bug in the endpoint validation, as it was incorrectly migrated from its meteor method counterpart

if (!/^[0-9a-zA-Z-_]+$/.test(customFieldData.field)) {
throw new Meteor.Error(
'error-invalid-custom-field-name',
'Invalid custom field name. Use only letters, numbers, hyphens and underscores.',
{ method: 'livechat:saveCustomField' },
);
}

The method implementation validated the customFieldData.field body param against the regex, but the endpoint that replaced it validated the customFieldId body param instead.

Moved back to draft so I can take a better look at this

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.

3 participants