Skip to content
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

Event filter #85

Merged
merged 5 commits into from
Apr 24, 2024
Merged
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
29 changes: 26 additions & 3 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HttpClient, Requester, RetryConfig } from "./http";
import { Messages } from "./messages";
import { Schedules } from "./schedules";
import { Topics } from "./topics";
import { Event } from "./types";
import { Event, State } from "./types";
import { prefixHeaders } from "./utils";
type ClientConfig = {
/**
Expand Down Expand Up @@ -157,8 +157,21 @@ export type PublishJsonRequest = Omit<PublishRequest, "body"> & {

export type EventsRequest = {
MeshanKhosla marked this conversation as resolved.
Show resolved Hide resolved
cursor?: number;
filter?: EventsRequestFilter
};

type EventsRequestFilter = {
messageId?: string;
state?: State;
url?: string;
topicName?: string;
scheduleId?: string;
queueName?: string;
fromDate?: number; // unix timestamp (ms)
toDate?: number; // unix timestamp (ms)
count?: number;
}

export type GetEventsResponse = {
cursor?: number;
events: Event[];
Expand Down Expand Up @@ -354,10 +367,20 @@ export class Client {
* ```
*/
public async events(req?: EventsRequest): Promise<GetEventsResponse> {
const query: Record<string, number> = {};
const query: Record<string, string> = {};
if (req?.cursor && req.cursor > 0) {
query.cursor = req.cursor;
query.cursor = req.cursor.toString();
}

for (const [key, value] of Object.entries(req?.filter ?? {})) {
if (typeof value === "number" && value < 0) {
continue;
}
if (typeof value !== "undefined") {
query[key] = value.toString();
}
}

const res = await this.http.request<GetEventsResponse>({
path: ["v2", "events"],
method: "GET",
Expand Down