Skip to content

Commit d2a578a

Browse files
committed
Prevent empty query parameters
1 parent 1113b87 commit d2a578a

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

packages/message/src/base/impl.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,19 @@ export class BaseMessageClient {
113113
startDate,
114114
endDate,
115115
}: GetMessagesConfiguration): Promise<MessagesQueryResponse> {
116+
const any = (value: any) => value && value.length > 0
116117
const params: GetMessagesParams = {
117118
pageSize,
118119
page,
119-
addresses: addresses ? addresses.join(',') : undefined,
120-
channels: channels ? channels.join(',') : undefined,
121-
chains: chains ? chains.join(',') : undefined,
122-
refs: refs ? refs.join(',') : undefined,
123-
tags: tags ? tags.join(',') : undefined,
124-
contentTypes: contentTypes ? contentTypes.join(',') : undefined,
125-
contentKeys: contentKeys ? contentKeys.join(',') : undefined,
126-
hashes: hashes ? hashes.join(',') : undefined,
127-
msgTypes: messageTypes?.join(',') || undefined,
120+
addresses: any(addresses) ? addresses.join(',') : undefined,
121+
channels: any(channels) ? channels.join(',') : undefined,
122+
chains: any(chains) ? chains.join(',') : undefined,
123+
refs: any(refs) ? refs.join(',') : undefined,
124+
tags: any(tags) ? tags.join(',') : undefined,
125+
contentTypes: any(contentTypes) ? contentTypes.join(',') : undefined,
126+
contentKeys: any(contentKeys) ? contentKeys.join(',') : undefined,
127+
hashes: any(hashes) ? hashes.join(',') : undefined,
128+
msgTypes: any(messageTypes) ? messageTypes?.join(',') : undefined,
128129
startDate: startDate ? startDate.valueOf() / 1000 : undefined,
129130
endDate: endDate ? endDate.valueOf() / 1000 : undefined,
130131
}

packages/message/src/post/impl.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ export class PostMessageClient {
5555
tags = [],
5656
hashes = [],
5757
}: PostGetConfiguration): Promise<PostQueryResponse<T>> {
58+
const any = (value: any) => value && value.length > 0
5859
const params: PostQueryParams = {
5960
types: types,
6061
pageSize: pageSize as number,
6162
page: page as number,
62-
refs: refs?.join(',') || undefined,
63-
addresses: addresses?.join(',') || undefined,
64-
tags: tags?.join(',') || undefined,
65-
hashes: hashes?.join(',') || undefined,
66-
channels: channels?.join(',') || undefined,
63+
refs: any(refs) ? refs?.join(',') : undefined,
64+
addresses: any(addresses) ? addresses?.join(',') : undefined,
65+
tags: any(tags) ? tags?.join(',') : undefined,
66+
hashes: any(hashes) ? hashes?.join(',') : undefined,
67+
channels: any(channels) ? channels?.join(',') : undefined,
6768
}
6869

6970
const response = (await axios.get<PostQueryResponse<T>>(`${this.apiServer}/api/v0/posts.json`, {

0 commit comments

Comments
 (0)