-
Notifications
You must be signed in to change notification settings - Fork 14
chore(KNO-11486): exclude metadata when refetching feed after new message received #853
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
Changes from all commits
6d0c480
5c02e4a
cb1ac3b
c8d8a0b
8109bf0
5919897
7664f7e
9209a56
053bc37
5ba24dc
d8f54ab
ea5a66e
70c866c
918f330
28ba905
0bd81d8
b67f436
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,16 @@ | ||
| --- | ||
| "@knocklabs/client": minor | ||
| --- | ||
|
|
||
| Exclude metadata when refetching feed after new message received | ||
|
|
||
| Starting with this release, if you configure a feed client to listen for events via [`Feed.on()`](https://docs.knock.app/in-app-ui/javascript/sdk/feed-client#on), the payload for feed events of type `"items.received.realtime"` will always have `metadata` set to `undefined`. | ||
|
|
||
| ```js | ||
| const knockFeed = knock.feeds.initialize(process.env.KNOCK_FEED_CHANNEL_ID); | ||
|
|
||
| knockFeed.on("items.received.realtime", (eventPayload) => { | ||
| // eventPayload.metadata will always be undefined here | ||
| const { items, metadata } = eventPayload; | ||
| }); | ||
| ``` |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -58,21 +58,35 @@ export interface FeedClientOptions { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @default "compact" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mode?: "rich" | "compact"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Field paths to exclude from the response. Use dot notation for nested fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * (e.g., "entries.archived_at"). Limited to 3 levels deep. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exclude?: string[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export type FetchFeedOptions = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __loadingType?: NetworkStatus.loading | NetworkStatus.fetchMore; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __fetchSource?: "socket" | "http"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } & Omit<FeedClientOptions, "__experimentalCrossBrowserUpdates">; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The final data shape that is sent to the API | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Should match types here: https://docs.knock.app/reference#get-feed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The final data shape that is sent to the the list feed items endpoint of the Knock API. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @see https://docs.knock.app/api-reference/users/feeds/list_items | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export type FetchFeedOptionsForRequest = Omit< | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FeedClientOptions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "trigger_data" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "trigger_data" | "exclude" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| > & { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Formatted trigger data into a string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| trigger_data?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** Fields to exclude from the response, joined by commas. */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| exclude?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "inserted_at.gte"?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "inserted_at.lte"?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "inserted_at.gt"?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "inserted_at.lt"?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+86
to
+89
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did we mean to add these?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it’s a mistake that they weren’t already in the
javascript/packages/client/src/clients/feed/utils.ts Lines 25 to 50 in 9313398
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Unset options that should not be sent to the API | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __loadingType: undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __fetchSource: undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||


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.
FeedResponse.metatype not updated to reflect optionalMedium Severity
The
FeedResponseinterface still definesmeta: FeedMetadataas required, but after this change,metacan beundefinedat runtime whenexcludeincludes"meta"(which now happens automatically for socket-triggered fetches). The cast toFeedMetadata | undefinedand themeta ?? state.metadatafallback are runtime workarounds, but theFeedResponsetype itself was not updated. SinceFeedResponseis a public export used byFeedRealTimeCallback, consumers of the legacy"messages.new"event who accessresp.meta.total_count(or similar) will encounter a runtime crash when the fetch is socket-triggered — and TypeScript won't warn them because the type saysmetais always present.Additional Locations (1)
packages/client/src/clients/feed/store.ts#L75-L78