-
Notifications
You must be signed in to change notification settings - Fork 0
fix: Use correct API parameter names for thread and inbox timestamp filtering #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
bc59562
639ff5a
5ff3105
ec497d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| import { HttpResponse, http } from 'msw' | ||
| import { apiUrl } from '../testUtils/msw-handlers' | ||
| import { server } from '../testUtils/msw-setup' | ||
| import { TEST_API_TOKEN } from '../testUtils/test-defaults' | ||
| import { InboxClient } from './inbox-client' | ||
|
|
||
| describe('InboxClient', () => { | ||
| let client: InboxClient | ||
|
|
||
| beforeEach(() => { | ||
| client = new InboxClient({ apiToken: TEST_API_TOKEN }) | ||
| }) | ||
|
|
||
| describe('getInbox', () => { | ||
| it('should send newerThan as newer_than_ts query parameter', async () => { | ||
| const date = new Date('2024-06-15T12:00:00Z') | ||
| const expectedTs = Math.floor(date.getTime() / 1000) | ||
|
|
||
| server.use( | ||
| http.get(apiUrl('api/v3/inbox/get'), ({ request }) => { | ||
| const url = new URL(request.url) | ||
| expect(url.searchParams.get('newer_than_ts')).toBe(String(expectedTs)) | ||
| expect(url.searchParams.get('workspace_id')).toBe('123') | ||
| return HttpResponse.json([]) | ||
| }), | ||
| ) | ||
|
|
||
| await client.getInbox({ workspaceId: 123, newerThan: date }) | ||
| }) | ||
|
|
||
| it('should send olderThan as older_than_ts query parameter', async () => { | ||
| const date = new Date('2024-06-15T12:00:00Z') | ||
| const expectedTs = Math.floor(date.getTime() / 1000) | ||
|
|
||
| server.use( | ||
| http.get(apiUrl('api/v3/inbox/get'), ({ request }) => { | ||
| const url = new URL(request.url) | ||
| expect(url.searchParams.get('older_than_ts')).toBe(String(expectedTs)) | ||
| expect(url.searchParams.get('workspace_id')).toBe('123') | ||
| return HttpResponse.json([]) | ||
| }), | ||
| ) | ||
|
|
||
| await client.getInbox({ workspaceId: 123, olderThan: date }) | ||
| }) | ||
|
|
||
| it('should support deprecated since param as newer_than_ts', async () => { | ||
| const date = new Date('2024-06-15T12:00:00Z') | ||
| const expectedTs = Math.floor(date.getTime() / 1000) | ||
|
|
||
| server.use( | ||
| http.get(apiUrl('api/v3/inbox/get'), ({ request }) => { | ||
| const url = new URL(request.url) | ||
| expect(url.searchParams.get('newer_than_ts')).toBe(String(expectedTs)) | ||
| expect(url.searchParams.get('workspace_id')).toBe('123') | ||
| return HttpResponse.json([]) | ||
| }), | ||
| ) | ||
|
|
||
| await client.getInbox({ workspaceId: 123, since: date }) | ||
| }) | ||
|
|
||
| it('should support deprecated until param as older_than_ts', async () => { | ||
| const date = new Date('2024-06-15T12:00:00Z') | ||
| const expectedTs = Math.floor(date.getTime() / 1000) | ||
|
|
||
| server.use( | ||
| http.get(apiUrl('api/v3/inbox/get'), ({ request }) => { | ||
| const url = new URL(request.url) | ||
| expect(url.searchParams.get('older_than_ts')).toBe(String(expectedTs)) | ||
| expect(url.searchParams.get('workspace_id')).toBe('123') | ||
| return HttpResponse.json([]) | ||
| }), | ||
| ) | ||
|
|
||
| await client.getInbox({ workspaceId: 123, until: date }) | ||
| }) | ||
| }) | ||
|
|
||
| describe('archiveAll', () => { | ||
| it('should send newerThan as since_ts_or_obj_idx parameter', async () => { | ||
| const date = new Date('2024-06-15T12:00:00Z') | ||
| const expectedTs = Math.floor(date.getTime() / 1000) | ||
|
|
||
| server.use( | ||
| http.post(apiUrl('api/v3/inbox/archive_all'), async ({ request }) => { | ||
| const body = await request.json() | ||
| expect(body).toEqual({ | ||
| workspace_id: 123, | ||
| since_ts_or_obj_idx: expectedTs, | ||
| }) | ||
| return HttpResponse.json(null) | ||
| }), | ||
| ) | ||
|
|
||
| await client.archiveAll({ workspaceId: 123, newerThan: date }) | ||
| }) | ||
|
|
||
| it('should send olderThan as until_ts_or_obj_idx parameter', async () => { | ||
| const date = new Date('2024-06-15T12:00:00Z') | ||
| const expectedTs = Math.floor(date.getTime() / 1000) | ||
|
|
||
| server.use( | ||
| http.post(apiUrl('api/v3/inbox/archive_all'), async ({ request }) => { | ||
| const body = await request.json() | ||
| expect(body).toEqual({ | ||
| workspace_id: 123, | ||
| until_ts_or_obj_idx: expectedTs, | ||
| }) | ||
| return HttpResponse.json(null) | ||
| }), | ||
| ) | ||
|
|
||
| await client.archiveAll({ workspaceId: 123, olderThan: date }) | ||
| }) | ||
|
|
||
| it('should support deprecated since param', async () => { | ||
| const date = new Date('2024-06-15T12:00:00Z') | ||
| const expectedTs = Math.floor(date.getTime() / 1000) | ||
|
|
||
| server.use( | ||
| http.post(apiUrl('api/v3/inbox/archive_all'), async ({ request }) => { | ||
| const body = await request.json() | ||
| expect(body).toEqual({ | ||
| workspace_id: 123, | ||
| since_ts_or_obj_idx: expectedTs, | ||
| }) | ||
| return HttpResponse.json(null) | ||
| }), | ||
| ) | ||
|
|
||
| await client.archiveAll({ workspaceId: 123, since: date }) | ||
| }) | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,8 +36,8 @@ export class ThreadsClient extends BaseClient { | |
| * @param args.channelId - The channel ID. | ||
| * @param args.workspaceId - Optional workspace ID. | ||
| * @param args.archived - Optional flag to include archived threads. | ||
| * @param args.newer_than_ts - Optional timestamp to get threads newer than. | ||
| * @param args.older_than_ts - Optional timestamp to get threads older than. | ||
| * @param args.newerThan - Optional date to get threads newer than. | ||
| * @param args.olderThan - Optional date to get threads older than. | ||
| * @param args.limit - Optional limit on number of threads returned. | ||
| * @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests. | ||
| * @returns An array of thread objects. | ||
|
|
@@ -56,7 +56,15 @@ export class ThreadsClient extends BaseClient { | |
| ): Promise<Thread[]> | BatchRequestDescriptor<Thread[]> { | ||
| const method = 'GET' | ||
| const url = `${ENDPOINT_THREADS}/get` | ||
| const params = args | ||
| const params: Record<string, unknown> = { | ||
| workspace_id: args.workspaceId, | ||
| } | ||
|
|
||
| if (args.channelId != null) params.channel_id = args.channelId | ||
| if (args.archived != null) params.archived = args.archived | ||
| if (args.newerThan) params.newer_than_ts = Math.floor(args.newerThan.getTime() / 1000) | ||
| if (args.olderThan) params.older_than_ts = Math.floor(args.olderThan.getTime() / 1000) | ||
| if (args.limit) params.limit = args.limit | ||
|
||
|
|
||
| if (options?.batch) { | ||
| return { method, url, params, schema: z.array(ThreadSchema) } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Rebuilding
paramsfrom scratch here drops the previously documentednewer_than_ts/older_than_tsinputs forgetThreads(). Before this change, those snake_case keys were forwarded throughrequest()and worked for JS consumers; after this refactor they are silently ignored, so existing calls can start returning unfiltered threads. Please add a deprecated fallback for the old keys, similar to the inbox/comments migrations, before removing that runtime path.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 639ff5a. Switched back to the passthrough pattern — we now destructure only the timestamp fields and spread
...restthrough. Added deprecatednewerThanTs/olderThanTsnumber fields onGetThreadsArgs(which auto-convert tonewer_than_ts/older_than_tsviasnakeCaseKeys), withnewerThanDate taking precedence when both are provided.