Skip to content

Commit ddd7981

Browse files
authored
chore(KNO-11661): improve FetchFeedOptionsForRequest type (#858)
1 parent 02eab09 commit ddd7981

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

.changeset/shaggy-ideas-matter.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@knocklabs/client": patch
3+
---
4+
5+
Improve `FetchFeedOptionsForRequest` type

packages/client/src/clients/feed/interfaces.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,25 @@ export type FetchFeedOptions = {
6565
__fetchSource?: "socket" | "http";
6666
} & Omit<FeedClientOptions, "__experimentalCrossBrowserUpdates">;
6767

68-
// The final data shape that is sent to the API
69-
// Should match types here: https://docs.knock.app/reference#get-feed
68+
/**
69+
* The final data shape that is sent to the the list feed items endpoint of the Knock API.
70+
*
71+
* @see https://docs.knock.app/api-reference/users/feeds/list_items
72+
*/
7073
export type FetchFeedOptionsForRequest = Omit<
7174
FeedClientOptions,
72-
"trigger_data"
75+
"trigger_data" | "inserted_at_date_range"
7376
> & {
74-
// Formatted trigger data into a string
77+
/** The trigger data of the feed items (as a JSON string). */
7578
trigger_data?: string;
79+
/** Limits the results to items inserted after or on the given date. */
80+
"inserted_at.gte"?: string;
81+
/** Limits the results to items inserted before or on the given date. */
82+
"inserted_at.lte"?: string;
83+
/** Limits the results to items inserted after the given date. */
84+
"inserted_at.gt"?: string;
85+
/** Limits the results to items inserted before the given date. */
86+
"inserted_at.lt"?: string;
7687
// Unset options that should not be sent to the API
7788
__loadingType: undefined;
7889
__fetchSource: undefined;

packages/client/src/clients/feed/utils.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import type { FeedClientOptions, FeedItem } from "./interfaces";
1+
import type {
2+
FeedClientOptions,
3+
FeedItem,
4+
FetchFeedOptionsForRequest,
5+
} from "./interfaces";
26

37
export function deduplicateItems(items: FeedItem[]): FeedItem[] {
48
const seen: Record<string, boolean> = {};
@@ -22,14 +26,19 @@ export function sortItems(items: FeedItem[]) {
2226
});
2327
}
2428

29+
type DateRangeParams = Pick<
30+
FetchFeedOptionsForRequest,
31+
"inserted_at.gte" | "inserted_at.lte" | "inserted_at.gt" | "inserted_at.lt"
32+
>;
33+
2534
export function mergeDateRangeParams(options: FeedClientOptions) {
2635
const { inserted_at_date_range, ...rest } = options;
2736

2837
if (!inserted_at_date_range) {
2938
return rest;
3039
}
3140

32-
const dateRangeParams: Record<string, string> = {};
41+
const dateRangeParams: DateRangeParams = {};
3342

3443
// Determine which operators to use based on the inclusive flag
3544
const isInclusive = inserted_at_date_range.inclusive ?? false;

0 commit comments

Comments
 (0)