UNPKG

@trycourier/courier-react-native

Version:

Inbox, Push Notifications, and Preferences for React Native

66 lines (63 loc) 2.7 kB
import { Modules } from "../Modules"; export class PreferenceClient { constructor(clientId) { this.clientId = clientId; } /** * Retrieves user preferences. * @param props - Optional properties for pagination. * @param props.paginationCursor - Optional cursor for pagination. * @returns A promise that resolves with CourierUserPreferences containing user preference items and paging information. */ async getUserPreferences(props) { const json = await Modules.Client.getUserPreferences(this.clientId, props === null || props === void 0 ? void 0 : props.paginationCursor); const rawData = JSON.parse(json); return { items: rawData.items.map(item => ({ defaultStatus: item.default_status, hasCustomRouting: item.has_custom_routing, customRouting: item.custom_routing.map(channel => channel), status: item.status, topicId: item.topic_id, topicName: item.topic_name, sectionName: item.section_name, sectionId: item.section_id })), paging: rawData.paging }; } /** * Retrieves user preference for a specific topic. * @param props - Properties for getting the user preference topic. * @param props.topicId - The ID of the topic to retrieve preferences for. * @returns A promise that resolves with CourierUserPreferencesTopic containing the topic preference details. */ async getUserPreferenceTopic(props) { const json = await Modules.Client.getUserPreferenceTopic(this.clientId, props.topicId); const rawData = JSON.parse(json); const convertedTopic = { defaultStatus: rawData.default_status, hasCustomRouting: rawData.has_custom_routing, customRouting: rawData.custom_routing.map(channel => channel), status: rawData.status, topicId: rawData.topic_id, topicName: rawData.topic_name, sectionName: rawData.section_name, sectionId: rawData.section_id }; return convertedTopic; } /** * Updates user preference for a specific topic. * @param props - Properties for updating the user preference topic. * @param props.topicId - The ID of the topic to update preferences for. * @param props.status - The new status for the topic preference. * @param props.hasCustomRouting - Whether the topic has custom routing. * @param props.customRouting - Array of custom routing channels. * @returns A promise that resolves when the update is complete. */ async putUserPreferenceTopic(props) { await Modules.Client.putUserPreferenceTopic(this.clientId, props.topicId, props.status, props.hasCustomRouting, props.customRouting); } } //# sourceMappingURL=PreferenceClient.js.map