@trycourier/courier-react-native
Version:
Inbox, Push Notifications, and Preferences for React Native
324 lines • 15.5 kB
TypeScript
import { CourierInboxListener } from './models/CourierInboxListener';
import { CourierPushListener } from './models/CourierPushListener';
import { CourierAuthenticationListener } from './models/CourierAuthenticationListener';
import { InboxMessage } from './models/InboxMessage';
import { CourierPushProvider } from './models/CourierPushProvider';
import { CourierClient } from './client/CourierClient';
import { InboxMessageFeed } from './models/InboxMessageFeed';
import { InboxMessageEvent } from './models/InboxMessageEvent';
export { CourierClient } from './client/CourierClient';
export { BrandClient } from './client/BrandClient';
export { CourierBrandResponse } from './models/CourierBrand';
export { CourierDevice } from './models/CourierDevice';
export { CourierInboxView } from './views/CourierInboxView';
export { CourierPreferencesView } from './views/CourierPreferencesView';
export { CourierInboxListener } from './models/CourierInboxListener';
export { CourierPushListener } from './models/CourierPushListener';
export { CourierUserPreferencesTopic } from './models/CourierUserPreferences';
export { CourierAuthenticationListener } from './models/CourierAuthenticationListener';
export { CourierUserPreferencesChannel } from './models/CourierUserPreferences';
export { CourierUserPreferencesStatus } from './models/CourierUserPreferences';
export { CourierTrackingEvent } from './models/CourierTrackingEvent';
export { CourierPushProvider } from './models/CourierPushProvider';
export { CourierFont } from './models/CourierFont';
export { CourierButton } from './models/CourierButton';
export { CourierInfoViewStyle } from './models/CourierInfoViewStyle';
export { iOS_CourierCell } from './models/iOS_CourierCell';
export { iOS_CourierSheet } from './models/iOS_CourierSheet';
export { InboxMessage } from './models/InboxMessage';
export { InboxMessageFeed } from './models/InboxMessageFeed';
export { InboxMessageEvent } from './models/InboxMessageEvent';
export { CourierInboxButtonStyle, CourierInboxTextStyle, CourierInboxUnreadIndicatorStyle, CourierInboxTheme } from './models/CourierInboxTheme';
export { CourierPreferencesTheme, CourierPreferencesMode, CourierPreferencesChannel } from './models/CourierPreferencesTheme';
export type iOSForegroundPresentationOptions = 'sound' | 'badge' | 'list' | 'banner';
export { CourierUtils } from './utils';
declare class Courier {
private static _sharedInstance;
private authenticationListeners;
private inboxListeners;
private pushListeners;
private systemBroadcaster;
private sharedBroadcaster;
private pushNotificationClickedEmitter;
private pushNotificationDeliveredEmitter;
constructor();
static get shared(): Courier;
private isDebugging;
static log(message: string): void;
private attachPushNotificationListeners;
/**
* Sets the iOS foreground presentation options for push notifications.
* This method only works on iOS devices.
* @param props An object containing an array of iOSForegroundPresentationOptions.
* @returns A string indicating the result of the operation. Returns 'unsupported' on non-iOS platforms.
*/
static setIOSForegroundPresentationOptions(props: {
options: iOSForegroundPresentationOptions[];
}): string;
/**
* Retrieves the current notification permission status.
* @returns A Promise that resolves to a string representing the current notification permission status.
*/
static getNotificationPermissionStatus(): Promise<string>;
/**
* Requests permission to send push notifications to the user.
* @returns A Promise that resolves to a string indicating the result of the permission request.
*/
static requestNotificationPermission(): Promise<string>;
/**
* Opens the settings page for the current app.
* This can be used to direct users to enable notifications if they've previously denied permission.
*/
static openSettingsForApp(): void;
/**
* Gets the current CourierClient instance.
* @returns {Promise<CourierClient | undefined>} The current CourierClient instance, or undefined if not initialized.
*/
getClient(): Promise<CourierClient | undefined>;
/**
* Gets the current user ID.
* @returns {Promise<string | undefined>} The current user ID, or undefined if not set.
*/
getUserId(): Promise<string | undefined>;
/**
* Gets the current tenant ID.
* @returns {Promise<string | undefined>} The current tenant ID, or undefined if not set.
*/
getTenantId(): Promise<string | undefined>;
/**
* Checks if a user is currently signed in.
* @returns {Promise<boolean>} True if a user is signed in, false otherwise.
*/
isUserSignedIn(): Promise<boolean>;
/**
* Signs out the current user.
* @returns {Promise<void>} A promise that resolves when the sign out process is complete.
*/
signOut(): Promise<void>;
/**
* Signs in a user with the provided credentials.
* @param {Object} props - The sign-in properties.
* @param {string} props.accessToken - The access token for authentication.
* @param {string} [props.clientKey] - The client key (optional).
* @param {string} props.userId - The user ID.
* @param {string} [props.tenantId] - The tenant ID (optional).
* @param {boolean} [props.showLogs] - Whether to show debug logs (defaults to __DEV__).
* @returns {Promise<void>} A promise that resolves when the sign-in process is complete.
*/
signIn(props: {
accessToken: string;
clientKey?: string;
userId: string;
tenantId?: string;
showLogs?: boolean;
}): Promise<void>;
/**
* Adds an authentication listener to monitor user changes.
* @param {Object} props - The listener properties.
* @param {function} props.onUserChanged - Callback function triggered when the user changes.
* @returns {CourierAuthenticationListener} The created authentication listener.
*/
addAuthenticationListener(props: {
onUserChanged: (userId?: string) => void;
}): Promise<CourierAuthenticationListener>;
/**
* Removes a specific authentication listener.
* @param {Object} props - The removal properties.
* @param {string} props.listenerId - The ID of the listener to remove.
* @returns {Promise<string>} A promise that resolves to the ID of the removed listener.
*/
removeAuthenticationListener(props: {
listenerId: string;
}): Promise<string>;
/**
* Removes all authentication listeners.
* This method clears all registered authentication listeners, both native and JavaScript.
*/
removeAllAuthenticationListeners(): Promise<void>;
/**
* Retrieves all push notification tokens.
* @returns {Promise<Map<string, string>>} A promise that resolves to a Map of provider keys to tokens.
*/
getAllTokens(): Promise<Map<string, string>>;
/**
* Retrieves the push notification token for a specific key.
* @param {Object} props - The properties object.
* @param {string} props.key - The key associated with the token.
* @returns {Promise<string | undefined>} A promise that resolves to the token or undefined if not found.
*/
getToken(props: {
key: string;
}): Promise<string | undefined>;
/**
* Retrieves the push notification token for a specific provider.
* @param {Object} props - The properties object.
* @param {CourierPushProvider} props.provider - The push notification provider.
* @returns {Promise<string | undefined>} A promise that resolves to the token or undefined if not found.
*/
getTokenForProvider(props: {
provider: CourierPushProvider;
}): Promise<string | undefined>;
/**
* Sets the push notification token for a specific key.
* @param {Object} props - The properties object.
* @param {string} props.key - The key to associate with the token.
* @param {string} props.token - The push notification token.
* @returns {Promise<void>} A promise that resolves when the token is set.
*/
setToken(props: {
key: string;
token: string;
}): Promise<void>;
/**
* Sets the push notification token for a specific provider.
* @param {Object} props - The properties object.
* @param {CourierPushProvider} props.provider - The push notification provider.
* @param {string} props.token - The push notification token.
* @returns {Promise<void>} A promise that resolves when the token is set.
*/
setTokenForProvider(props: {
provider: CourierPushProvider;
token: string;
}): Promise<void>;
/**
* Adds a push notification listener.
* @param {Object} props - The properties object.
* @param {function} [props.onPushNotificationClicked] - Callback function triggered when a push notification is clicked.
* @param {function} [props.onPushNotificationDelivered] - Callback function triggered when a push notification is delivered.
* @returns {CourierPushListener} The created push notification listener.
*/
addPushNotificationListener(props: {
onPushNotificationClicked?: (push: any) => void;
onPushNotificationDelivered?: (push: any) => void;
}): CourierPushListener;
/**
* Removes a specific push notification listener.
* @param {Object} props - The properties object.
* @param {string} props.listenerId - The ID of the listener to remove.
* @returns {string} The ID of the removed listener.
*/
removePushNotificationListener(props: {
listenerId: string;
}): Promise<string>;
/**
* Removes all push notification listeners.
*/
removeAllPushNotificationListeners(): Promise<void>;
/**
* Gets the current pagination limit for inbox messages.
* @returns {Promise<number>} A promise that resolves with the current pagination limit.
* Default is 32.
*/
getInboxPaginationLimit(): Promise<number>;
/**
* Sets the pagination limit for inbox messages.
* @param {number} limit - The new pagination limit to set.
* @returns {Promise<void>} A promise that resolves when the limit is set.
* Default is 32.
*/
setInboxPaginationLimit(limit: number): Promise<void>;
/**
* Opens a specific message in the inbox.
* @param {Object} props - The properties object.
* @param {string} props.messageId - The ID of the message to open.
* @returns {Promise<void>} A promise that resolves when the message is opened.
*/
openMessage(props: {
messageId: string;
}): Promise<void>;
/**
* Registers a click event for a specific message in the inbox.
* @param {Object} props - The properties object.
* @param {string} props.messageId - The ID of the message that was clicked.
* @returns {Promise<void>} A promise that resolves when the click is registered.
*/
clickMessage(props: {
messageId: string;
}): Promise<void>;
/**
* Marks a specific message as read in the inbox.
* @param {Object} props - The properties object.
* @param {string} props.messageId - The ID of the message to mark as read.
* @returns {Promise<void>} A promise that resolves when the message is marked as read.
*/
readMessage(props: {
messageId: string;
}): Promise<void>;
/**
* Marks a specific message as unread in the inbox.
* @param {Object} props - The properties object.
* @param {string} props.messageId - The ID of the message to mark as unread.
* @returns {Promise<void>} A promise that resolves when the message is marked as unread.
*/
unreadMessage(props: {
messageId: string;
}): Promise<void>;
/**
* Archives a specific message in the inbox.
* @param {Object} props - The properties object.
* @param {string} props.messageId - The ID of the message to archive.
* @returns {Promise<void>} A promise that resolves when the message is archived.
*/
archiveMessage(props: {
messageId: string;
}): Promise<void>;
/**
* Marks all messages in the inbox as read.
* @returns {Promise<void>} A promise that resolves when all messages are marked as read.
*/
readAllInboxMessages(): Promise<void>;
/**
* Adds a listener for inbox changes (aligned with the updated native iOS/Swift callbacks).
* @param {Object} props - The properties object.
* @param {Function} [props.onLoading] - Called when loading or refreshing begins. Receives isRefresh (boolean).
* @param {Function} [props.onError] - Called when an error occurs. Receives the error message (string).
* @param {Function} [props.onUnreadCountChanged] - Called when unread count changes. Receives unreadCount (number).
* @param {Function} [props.onTotalCountChanged] - Called when total message count changes. Receives totalCount (number) and feed ("feed" or "archive").
* @param {Function} [props.onMessagesChanged] - Called when messages in a feed change. Receives an InboxMessageSet and feed name.
* @param {Function} [props.onPageAdded] - Called when a new page of messages is added. Receives an InboxMessageSet, feed name, and isFirstPage (boolean).
* @param {Function} [props.onMessageEvent] - Called for message-level changes (add/remove/update). Receives a message, index, feed name, and event string.
* @returns {CourierInboxListener} A listener object that can be used to remove the listener later.
*/
addInboxListener(props: {
onLoading?: (isRefresh: boolean) => void;
onError?: (error: string) => void;
onUnreadCountChanged?: (unreadCount: number) => void;
onTotalCountChanged?: (totalCount: number, feed: string) => void;
onMessagesChanged?: (messages: InboxMessage[], canPaginate: boolean, feed: InboxMessageFeed) => void;
onPageAdded?: (messages: InboxMessage[], canPaginate: boolean, isFirstPage: boolean, feed: InboxMessageFeed) => void;
onMessageEvent?: (message: InboxMessage, index: number, feed: InboxMessageFeed, eventName: InboxMessageEvent) => void;
}): Promise<CourierInboxListener>;
private convertMessages;
/**
* Removes a specific inbox listener.
* @param {Object} props - The properties object.
* @param {string} props.listenerId - The ID of the listener to remove.
* @returns {string} The ID of the removed listener.
*/
removeInboxListener(props: {
listenerId: string;
}): Promise<string>;
/**
* Removes all inbox listeners.
*/
removeAllInboxListeners(): Promise<void>;
/**
* Refreshes the inbox.
* Useful for pull-to-refresh functionality.
* @returns {Promise<void>} A promise that resolves when the inbox is refreshed.
*/
refreshInbox(): Promise<void>;
/**
* Fetches the next page of inbox messages.
* @returns {Promise<InboxMessage[]>} A promise that resolves with an array of fetched inbox messages.
*/
fetchNextPageOfMessages(props: {
inboxMessageFeed: InboxMessageFeed;
}): Promise<InboxMessage[]>;
/**
* Sets a flag to indicate if UI tests are active.
*/
static setIsUITestsActive(isActive: boolean): void;
}
export default Courier;
//# sourceMappingURL=index.d.ts.map