@trycourier/courier-js
Version:
A browser-safe API wrapper
130 lines (129 loc) • 4.67 kB
TypeScript
import { CourierInboxSocket } from '../socket/courier-inbox-socket';
import { CourierGetInboxMessagesQueryFilter, CourierGetInboxMessagesResponse } from '../types/inbox';
import { Client } from './client';
import { CourierClientOptions } from './courier-client';
export declare class InboxClient extends Client {
readonly socket: CourierInboxSocket;
constructor(options: CourierClientOptions);
/**
* Get paginated messages
* @param paginationLimit - Number of messages to return per page (default: 24)
* @param startCursor - Cursor for pagination
* @returns Promise resolving to paginated messages response
*/
getMessages(props?: {
paginationLimit?: number;
startCursor?: string;
filter?: CourierGetInboxMessagesQueryFilter;
}): Promise<CourierGetInboxMessagesResponse>;
/**
* Get unread counts for multiple filters in a single query.
*
* @param filtersMap - Map of dataset ID to filter
* @returns Promise resolving to map of dataset ID to unread count
*/
getUnreadCounts(filtersMap: Record<string, CourierGetInboxMessagesQueryFilter>): Promise<Record<string, number>>;
/**
* Get paginated archived messages
* @param paginationLimit - Number of messages to return per page (default: 24)
* @param startCursor - Cursor for pagination
* @returns Promise resolving to paginated archived messages response
*
* @deprecated - replace usages with {@link InboxClient.getMessages}, passing the filter `{ archived: true }`
*/
getArchivedMessages(props?: {
paginationLimit?: number;
startCursor?: string;
}): Promise<CourierGetInboxMessagesResponse>;
/**
* Get unread message count
* @returns Promise resolving to number of unread messages
*/
getUnreadMessageCount(): Promise<number>;
/**
* Track a click event
* @param messageId - ID of the message
* @param trackingId - ID for tracking the click
* @returns Promise resolving when click is tracked
*/
click(props: {
messageId: string;
trackingId: string;
}): Promise<void>;
/**
* Mark a message as read
* @param messageId - ID of the message to mark as read
* @returns Promise resolving when message is marked as read
*/
read(props: {
messageId: string;
}): Promise<void>;
/**
* Mark a message as unread
* @param messageId - ID of the message to mark as unread
* @returns Promise resolving when message is marked as unread
*/
unread(props: {
messageId: string;
}): Promise<void>;
/**
* Mark a message as opened
* @param messageId - ID of the message to mark as opened
* @returns Promise resolving when message is marked as opened
*/
open(props: {
messageId: string;
}): Promise<void>;
/**
* Archive a message
* @param messageId - ID of the message to archive
* @returns Promise resolving when message is archived
*/
archive(props: {
messageId: string;
}): Promise<void>;
/**
* Unarchive a message
* @param messageId - ID of the message to unarchive
* @returns Promise resolving when message is unarchived
*/
unarchive(props: {
messageId: string;
}): Promise<void>;
/**
* Mark all messages as read
* @returns Promise resolving when all messages are marked as read
*/
readAll(): Promise<void>;
/**
* Archive all read messages.
*/
archiveRead(): Promise<void>;
/**
* Archive all read messages.
*/
archiveAll(): Promise<void>;
/**
* Create FilterParamsInput for the given filters.
*
* @param filter - the filtering options to include in the output
* @returns the FilterParamsInput to pass to a GraphQL query for messages
*/
private createFilterParams;
/**
* Create FilterParamsInput for the unread message count.
*
* The status: "unread" filter is only added if status is unset. This is because:
* - If status is "unread", the params already include the filter that would be added.
* - If status is "read", the unread count for the dataset would be a different set
* of messages rather than a count of the unread subset.
*/
private createUnreadCountFilterParams;
/**
* Sanitize dataset IDs for use as GraphQL identifiers.
*
* GraphQL identifiers must contain only alphanumerics/underscores and begin with a letter or underscore.
* https://spec.graphql.org/draft/#sec-Names
*/
private static sanitizeGraphQLIdentifier;
}