Skip to content
Closed
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
34 changes: 32 additions & 2 deletions packages/core/src/clickup-client/views-enhanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,25 @@ import type {
UpdateViewSettingsRequest,
ViewSharingRequest,
ViewFilter,
FilterOperator,
ViewGrouping,
ViewSorting
// ViewSettings
} from '../schemas/views-schemas.js';

const CLICKUP_FILTER_OPERATOR_MAP: Partial<Record<FilterOperator, string>> = {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: Operator map is non-exhaustive and silently falls back to raw schema names for unmapped operators, risking silent API failures.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core/src/clickup-client/views-enhanced.ts, line 19:

<comment>Operator map is non-exhaustive and silently falls back to raw schema names for unmapped operators, risking silent API failures.</comment>

<file context>
@@ -10,11 +10,25 @@ import type {
   // ViewSettings
 } from '../schemas/views-schemas.js';
 
+const CLICKUP_FILTER_OPERATOR_MAP: Partial<Record<FilterOperator, string>> = {
+  equals: 'EQ',
+  not_equals: 'NOT',
</file context>

equals: 'EQ',
not_equals: 'NOT',
greater_than: 'GT',
less_than: 'LT',
greater_than_or_equal: 'GTE',
less_than_or_equal: 'LTE',
in: 'ANY',
not_in: 'NOT ANY',
is_set: 'IS SET',
is_not_set: 'IS NOT SET'
};
Comment on lines +19 to +30

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Make operator mapping exhaustive and remove silent fallback.

Using Partial<Record<...>> with ?? filter.operator can emit raw schema operators for unmapped cases, which risks reintroducing 400s for valid FilterOperator inputs. Make this a total Record<FilterOperator, string> and drop the fallback so unmapped operators fail at compile time instead of runtime payload errors.

Suggested diff
-const CLICKUP_FILTER_OPERATOR_MAP: Partial<Record<FilterOperator, string>> = {
+const CLICKUP_FILTER_OPERATOR_MAP: Record<FilterOperator, string> = {
   equals: 'EQ',
   not_equals: 'NOT',
+  contains: 'CONTAINS',
+  not_contains: 'NOT CONTAINS',
+  starts_with: 'STARTS WITH',
+  ends_with: 'ENDS WITH',
+  is_empty: 'IS EMPTY',
+  is_not_empty: 'IS NOT EMPTY',
   greater_than: 'GT',
   less_than: 'LT',
   greater_than_or_equal: 'GTE',
   less_than_or_equal: 'LTE',
+  between: 'BETWEEN',
+  not_between: 'NOT BETWEEN',
   in: 'ANY',
   not_in: 'NOT ANY',
   is_set: 'IS SET',
   is_not_set: 'IS NOT SET'
 };
...
-        op: CLICKUP_FILTER_OPERATOR_MAP[filter.operator] ?? filter.operator,
+        op: CLICKUP_FILTER_OPERATOR_MAP[filter.operator],

Also applies to: 334-335

🤖 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/clickup-client/views-enhanced.ts` around lines 19 - 30,
Change the CLICKUP_FILTER_OPERATOR_MAP type from Partial<Record<FilterOperator,
string>> to a total Record<FilterOperator, string> to require all FilterOperator
values to be mapped. Additionally, locate where this map is used with a fallback
operator (such as the `?? filter.operator` pattern mentioned around lines
334-335) and remove the fallback entirely. This will ensure all FilterOperator
cases are handled at compile time rather than risking runtime 400 errors from
unmapped operators being sent in payloads.


export interface ViewResponse {
id: string;
name: string;
Expand Down Expand Up @@ -317,14 +331,30 @@ export class ViewsEnhancedClient extends ClickUpClient {
op: 'AND',
fields: filters.map(filter => ({
field: filter.field,
operator: filter.operator,
value: filter.value || filter.values
op: CLICKUP_FILTER_OPERATOR_MAP[filter.operator] ?? filter.operator,
values: this.formatFilterValues(filter)
})),
search: '',
show_closed: false
};
}

private formatFilterValues(filter: ViewFilter): Array<string | number | null> {
if (filter.values !== undefined) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Set/unset operators do not always force [null] because earlier branches return caller-supplied values/array value

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core/src/clickup-client/views-enhanced.ts, line 343:

<comment>Set/unset operators do not always force `[null]` because earlier branches return caller-supplied `values`/array `value`</comment>

<file context>
@@ -317,14 +331,30 @@ export class ViewsEnhancedClient extends ClickUpClient {
   }
 
+  private formatFilterValues(filter: ViewFilter): Array<string | number | null> {
+    if (filter.values !== undefined) {
+      return filter.values;
+    }
</file context>

return filter.values;
}

if (Array.isArray(filter.value)) {
return filter.value;
}

if (filter.operator === 'is_set' || filter.operator === 'is_not_set') {
return [null];
}

return filter.value !== undefined ? [filter.value] : [];
Comment on lines +342 to +355

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Force [null] for is_set/is_not_set before reading input values.

formatFilterValues currently gives precedence to filter.values/array filter.value, so is_set/is_not_set can emit non-[null] payloads when callers provide values. This contradicts the intended ClickUp encoding and can produce invalid requests.

Suggested diff
  private formatFilterValues(filter: ViewFilter): Array<string | number | null> {
+    if (filter.operator === 'is_set' || filter.operator === 'is_not_set') {
+      return [null];
+    }
+
    if (filter.values !== undefined) {
      return filter.values;
    }

    if (Array.isArray(filter.value)) {
      return filter.value;
    }

-    if (filter.operator === 'is_set' || filter.operator === 'is_not_set') {
-      return [null];
-    }
-
    return filter.value !== undefined ? [filter.value] : [];
  }
🤖 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/clickup-client/views-enhanced.ts` around lines 342 - 355,
The formatFilterValues method currently checks for filter.values and array
filter.value before validating the operator type, allowing is_set and is_not_set
operators to emit non-null values when callers provide them, which contradicts
the intended ClickUp encoding. Reorder the checks in formatFilterValues so that
the operator validation for is_set and is_not_set comes first, before any checks
for filter.values or filter.value, ensuring these operators always return [null]
regardless of input values provided.

}

/**
* Get available view fields for a parent
*/
Expand Down
80 changes: 80 additions & 0 deletions packages/core/src/tests/views-filter-payload.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { describe, it, expect, beforeEach } from '@jest/globals';

import { ViewsEnhancedClient } from '../clickup-client/views-enhanced.js';

class TestViewsClient extends ViewsEnhancedClient {
postCalls: Array<{ endpoint: string; data: any }> = [];
putCalls: Array<{ endpoint: string; data: any }> = [];

constructor() {
super('test-token');
}

async post<T = unknown>(endpoint: string, data?: any): Promise<T> {
this.postCalls.push({ endpoint, data });
return { view: { id: 'view-1' } } as T;
}

async put<T = unknown>(endpoint: string, data?: any): Promise<T> {
this.putCalls.push({ endpoint, data });
return { view: { id: 'view-1' } } as T;
}
}

describe('ViewsEnhancedClient filter payloads', () => {
let client: TestViewsClient;

beforeEach(() => {
client = new TestViewsClient();
});

it('creates views with ClickUp filter field keys and values arrays', async () => {
await client.createView({
parent_id: 'list-1',
parent_type: 'list',
name: 'Filtered tasks',
type: 'list',
access: 'private',
filters: [
{ field: 'status', operator: 'equals', value: 'in progress' },
{ field: 'tag', operator: 'in', values: ['bug', 'urgent'] },
{ field: 'priority', operator: 'greater_than_or_equal', value: 0 }
]
});

expect(client.postCalls).toHaveLength(1);
expect(client.postCalls[0].endpoint).toBe('/list/list-1/view');
expect(client.postCalls[0].data.filters).toEqual({
op: 'AND',
fields: [
{ field: 'status', op: 'EQ', values: ['in progress'] },
{ field: 'tag', op: 'ANY', values: ['bug', 'urgent'] },
{ field: 'priority', op: 'GTE', values: [0] }
],
search: '',
show_closed: false
});

for (const field of client.postCalls[0].data.filters.fields) {
expect(field).not.toHaveProperty('operator');
expect(field).not.toHaveProperty('value');
}
});

it('sets view filters using API operator names and normalized values', async () => {
await client.setViewFilters({
view_id: 'view-1',
filters: [
{ field: 'assignee', operator: 'not_in', value: [123, 456] },
{ field: 'dateClosed', operator: 'is_not_set' }
]
});

expect(client.putCalls).toHaveLength(1);
expect(client.putCalls[0].endpoint).toBe('/view/view-1');
expect(client.putCalls[0].data.filters.fields).toEqual([
{ field: 'assignee', op: 'NOT ANY', values: [123, 456] },
{ field: 'dateClosed', op: 'IS NOT SET', values: [null] }
]);
});
});