import { z } from 'zod'; import { Environment } from '../../http/environment.js'; import { ThrowableError } from '../../http/errors/throwable-error.js'; import { SerializationStyle } from '../../http/serialization/base-serializer.js'; import { RequestBuilder } from '../../http/transport/request-builder.js'; import { ContentType, HttpResponse, RequestConfig } from '../../http/types.js'; import { BaseService } from '../base-service.js'; import { CountResponse, countResponseResponse } from './models/count-response.js'; import { Notification, notificationResponse } from './models/notification.js'; import { NotificationCollection, notificationCollectionResponse } from './models/notification-collection.js'; import { ArchiveAllNotificationsParams, FetchUnreadNotificationsCountParams, ListNotificationsParams, MarkAllNotificationsReadParams, } from './request-params.js'; /** * Service class for NotificationsService operations. * Provides methods to interact with NotificationsService-related API endpoints. * All methods return promises and handle request/response serialization automatically. */ export class NotificationsService extends BaseService { /** * Lists all notifications for a user. * @param {number} [params.limit] - defines the maximum number of items to return per page (default: 50) * @param {string} [params.startingAfter] - a cursor for use in pagination, points to the last ID in previous page * @param {string} [params.endingBefore] - a cursor for use in pagination, points to the first ID in next page * @param {string} [params.status] - filter notifications by their read state, one of 'unread' | 'read' | 'archived' * @param {string} [params.category] - filter notifications by their category * @param {string} [params.topic] - filter notifications by their topic * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation. * @returns {Promise>} - OK */ async listNotifications( params?: ListNotificationsParams, requestConfig?: RequestConfig, ): Promise> { const request = new RequestBuilder() .setBaseUrl(requestConfig?.baseUrl || this.config.baseUrl || this.config.environment || Environment.DEFAULT) .setConfig(this.config) .setMethod('GET') .setPath('/notifications') .setRequestSchema(z.any()) .addAccessTokenAuth(this.config.token, 'Bearer') .setRequestContentType(ContentType.Json) .addResponse({ schema: notificationCollectionResponse, contentType: ContentType.Json, status: 200, }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .addQueryParam({ key: 'limit', value: params?.limit, }) .addQueryParam({ key: 'starting_after', value: params?.startingAfter, }) .addQueryParam({ key: 'ending_before', value: params?.endingBefore, }) .addQueryParam({ key: 'status', value: params?.status, }) .addQueryParam({ key: 'category', value: params?.category, }) .addQueryParam({ key: 'topic', value: params?.topic, }) .build(); return this.client.call(request); } /** * Archive all notifications. * @param {string} [params.category] - filter notifications by their category * @param {string} [params.topic] - filter notifications by their topic * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation. * @returns {Promise>} - No Content */ async archiveAllNotifications( params?: ArchiveAllNotificationsParams, requestConfig?: RequestConfig, ): Promise> { const request = new RequestBuilder() .setBaseUrl(requestConfig?.baseUrl || this.config.baseUrl || this.config.environment || Environment.DEFAULT) .setConfig(this.config) .setMethod('POST') .setPath('/notifications/archive') .setRequestSchema(z.any()) .addAccessTokenAuth(this.config.token, 'Bearer') .setRequestContentType(ContentType.Json) .addResponse({ schema: z.undefined(), contentType: ContentType.NoContent, status: 204, }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .addQueryParam({ key: 'category', value: params?.category, }) .addQueryParam({ key: 'topic', value: params?.topic, }) .build(); return this.client.call(request); } /** * Marks all notifications as read. * @param {string} [params.category] - filter notifications by their category * @param {string} [params.topic] - filter notifications by their topic * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation. * @returns {Promise>} - No Content */ async markAllNotificationsRead( params?: MarkAllNotificationsReadParams, requestConfig?: RequestConfig, ): Promise> { const request = new RequestBuilder() .setBaseUrl(requestConfig?.baseUrl || this.config.baseUrl || this.config.environment || Environment.DEFAULT) .setConfig(this.config) .setMethod('POST') .setPath('/notifications/read') .setRequestSchema(z.any()) .addAccessTokenAuth(this.config.token, 'Bearer') .setRequestContentType(ContentType.Json) .addResponse({ schema: z.undefined(), contentType: ContentType.NoContent, status: 204, }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .addQueryParam({ key: 'category', value: params?.category, }) .addQueryParam({ key: 'topic', value: params?.topic, }) .build(); return this.client.call(request); } /** * Returns the count of unread notifications for a user. Supports filtering by category and topic. * @param {string} [params.category] - filter notifications by their category * @param {string} [params.topic] - filter notifications by their topic * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation. * @returns {Promise>} - OK */ async fetchUnreadNotificationsCount( params?: FetchUnreadNotificationsCountParams, requestConfig?: RequestConfig, ): Promise> { const request = new RequestBuilder() .setBaseUrl(requestConfig?.baseUrl || this.config.baseUrl || this.config.environment || Environment.DEFAULT) .setConfig(this.config) .setMethod('GET') .setPath('/notifications/unread/count') .setRequestSchema(z.any()) .addAccessTokenAuth(this.config.token, 'Bearer') .setRequestContentType(ContentType.Json) .addResponse({ schema: countResponseResponse, contentType: ContentType.Json, status: 200, }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .addQueryParam({ key: 'category', value: params?.category, }) .addQueryParam({ key: 'topic', value: params?.topic, }) .build(); return this.client.call(request); } /** * Gets a notification by ID. * @param {string} notificationId - * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation. * @returns {Promise>} - OK */ async fetchNotification(notificationId: string, requestConfig?: RequestConfig): Promise> { const request = new RequestBuilder() .setBaseUrl(requestConfig?.baseUrl || this.config.baseUrl || this.config.environment || Environment.DEFAULT) .setConfig(this.config) .setMethod('GET') .setPath('/notifications/{notification_id}') .setRequestSchema(z.any()) .addAccessTokenAuth(this.config.token, 'Bearer') .setRequestContentType(ContentType.Json) .addResponse({ schema: notificationResponse, contentType: ContentType.Json, status: 200, }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .addPathParam({ key: 'notification_id', value: notificationId, }) .build(); return this.client.call(request); } /** * Archive a notification. * @param {string} notificationId - * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation. * @returns {Promise>} - No Content */ async archiveNotification(notificationId: string, requestConfig?: RequestConfig): Promise> { const request = new RequestBuilder() .setBaseUrl(requestConfig?.baseUrl || this.config.baseUrl || this.config.environment || Environment.DEFAULT) .setConfig(this.config) .setMethod('POST') .setPath('/notifications/{notification_id}/archive') .setRequestSchema(z.any()) .addAccessTokenAuth(this.config.token, 'Bearer') .setRequestContentType(ContentType.Json) .addResponse({ schema: z.undefined(), contentType: ContentType.NoContent, status: 204, }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .addPathParam({ key: 'notification_id', value: notificationId, }) .build(); return this.client.call(request); } /** * Marks a notification as read. * @param {string} notificationId - * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation. * @returns {Promise>} - No Content */ async markNotificationRead(notificationId: string, requestConfig?: RequestConfig): Promise> { const request = new RequestBuilder() .setBaseUrl(requestConfig?.baseUrl || this.config.baseUrl || this.config.environment || Environment.DEFAULT) .setConfig(this.config) .setMethod('POST') .setPath('/notifications/{notification_id}/read') .setRequestSchema(z.any()) .addAccessTokenAuth(this.config.token, 'Bearer') .setRequestContentType(ContentType.Json) .addResponse({ schema: z.undefined(), contentType: ContentType.NoContent, status: 204, }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .addPathParam({ key: 'notification_id', value: notificationId, }) .build(); return this.client.call(request); } /** * Unarchives a notification. * @param {string} notificationId - * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation. * @returns {Promise>} - No Content */ async unarchiveNotification(notificationId: string, requestConfig?: RequestConfig): Promise> { const request = new RequestBuilder() .setBaseUrl(requestConfig?.baseUrl || this.config.baseUrl || this.config.environment || Environment.DEFAULT) .setConfig(this.config) .setMethod('POST') .setPath('/notifications/{notification_id}/unarchive') .setRequestSchema(z.any()) .addAccessTokenAuth(this.config.token, 'Bearer') .setRequestContentType(ContentType.Json) .addResponse({ schema: z.undefined(), contentType: ContentType.NoContent, status: 204, }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .addPathParam({ key: 'notification_id', value: notificationId, }) .build(); return this.client.call(request); } /** * Marks a notification as unread. * @param {string} notificationId - * @param {RequestConfig} [requestConfig] - The request configuration for retry and validation. * @returns {Promise>} - No Content */ async markNotificationUnread(notificationId: string, requestConfig?: RequestConfig): Promise> { const request = new RequestBuilder() .setBaseUrl(requestConfig?.baseUrl || this.config.baseUrl || this.config.environment || Environment.DEFAULT) .setConfig(this.config) .setMethod('POST') .setPath('/notifications/{notification_id}/unread') .setRequestSchema(z.any()) .addAccessTokenAuth(this.config.token, 'Bearer') .setRequestContentType(ContentType.Json) .addResponse({ schema: z.undefined(), contentType: ContentType.NoContent, status: 204, }) .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) .addPathParam({ key: 'notification_id', value: notificationId, }) .build(); return this.client.call(request); } }