// ── SDK v2 — NotificationsClient ────────────────────────────────────────────── // // Covers: // GET /v2/notifications // GET /v2/notifications/:id // PATCH /v2/notifications/:id // DELETE /v2/notifications/:id // PATCH /v2/notifications/mark-all-read import type { Fetcher } from "../http/fetcher"; import type { RequestOptions } from "../http/types"; import type { Notification, NotificationUpdate, MarkAllReadBody, ListParams, Paginated, } from "../types/index"; export class NotificationsClient { constructor(private readonly fetcher: Fetcher) {} /** * Lists notifications with cursor pagination and optional DSL filtering. * * @example * ```ts * const page = await client.notifications.list({ * q: "read.eq:false", * sort: "created_at:desc", * }); * ``` */ list(params?: ListParams, opts?: RequestOptions): Promise> { return this.fetcher.list("/notifications", params, opts); } /** * Gets a single notification by ID. * * @throws {NotFoundError} when no notification with `id` exists. */ get(id: string, opts?: RequestOptions): Promise { return this.fetcher.get(`/notifications/${id}`, undefined, opts); } /** * Updates a notification — typically used to mark it as read. * * @example * ```ts * await client.notifications.update(id, { read: true }); * ``` * * @throws {NotFoundError} when no notification with `id` exists. */ update( id: string, data: NotificationUpdate, opts?: RequestOptions, ): Promise { return this.fetcher.patch(`/notifications/${id}`, data, opts); } /** * Deletes a notification. * * @throws {NotFoundError} when no notification with `id` exists. */ delete(id: string, opts?: RequestOptions): Promise { return this.fetcher.delete(`/notifications/${id}`, opts); } /** * Marks all notifications as read for a given user. * Returns the count of updated notifications. * * @example * ```ts * const { updated } = await client.notifications.markAllRead({ user_id: "user-1" }); * ``` */ markAllRead( data: MarkAllReadBody, opts?: RequestOptions, ): Promise<{ updated: number }> { return this.fetcher.patch<{ updated: number }>( "/notifications/mark-all-read", data, opts, ); } }