Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions apps/meteor/app/livechat/server/api/v1/customField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ const livechatCustomFieldsEndpoints = API.v1
async function action() {
const { customFieldId, customFieldData } = this.bodyParams;

if (!/^[0-9a-zA-Z-_]+$/.test(customFieldId)) {
return API.v1.failure('Invalid custom field name. Use only letters, numbers, hyphens and underscores.');
}

if (customFieldId) {
const customField = await LivechatCustomField.findOneById(customFieldId);
if (!customField) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface ILivechatCustomFieldModel extends IBaseModel<ILivechatCustomFie
options?: FindOptions<ILivechatCustomField>,
): FindCursor<ILivechatCustomField>;
createOrUpdateCustomField(
_id: string,
_id: string | null,
field: string,
label: ILivechatCustomField['label'],
scope: ILivechatCustomField['scope'],
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/models/LivechatCustomField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class LivechatCustomFieldRaw extends BaseRaw<ILivechatCustomField> implem
}

async createOrUpdateCustomField(
_id: string,
_id: string | null,
field: string,
label: ILivechatCustomField['label'],
scope: ILivechatCustomField['scope'],
Expand Down
4 changes: 3 additions & 1 deletion packages/rest-typings/src/v1/omnichannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4445,12 +4445,14 @@ const POSTLivechatSaveCustomFieldsSchema = {
properties: {
customFieldId: {
type: 'string',
pattern: '^[0-9a-zA-Z_-]+$',
},
Comment on lines 4446 to 4449
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.

customFieldData: {
type: 'object',
properties: {
field: {
type: 'string',
pattern: '^[0-9a-zA-Z_-]+$',
},
label: {
type: 'string',
Expand Down Expand Up @@ -4497,7 +4499,7 @@ const POSTLivechatSaveCustomFieldsSchema = {
};

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

Expand Down
Loading