react-native-notificare
Version:
Notificare React Native module.
209 lines (192 loc) • 6.71 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.NotificareDeviceModule = void 0;
var _reactNative = require("react-native");
const LINKING_ERROR = `The package 'react-native-notificare' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
ios: "- You have run 'pod install'\n",
default: ''
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
// @ts-expect-error
const isTurboModuleEnabled = global.__turboModuleProxy != null;
const NotificareModule = isTurboModuleEnabled ? require('./NativeNotificareModule').default : _reactNative.NativeModules.NotificareModule;
const NativeModule = NotificareModule ? NotificareModule : new Proxy({}, {
get() {
throw new Error(LINKING_ERROR);
}
});
class NotificareDeviceModule {
/**
* @returns {Promise<NotificareDevice | null>} - A promise that resolves to
* the current {@link NotificareDevice} information, or 'null' in case no
* device is registered.
*/
async getCurrentDevice() {
return await NativeModule.getCurrentDevice();
}
/**
* @returns {Promise<string | null>} - A promise that resolves to the
* preferred language of the current device for notifications and messages, or
* `null` if no preferred language is set.
*/
async getPreferredLanguage() {
return await NativeModule.getPreferredLanguage();
}
/**
* Updates the preferred language setting for the device.
*
* @param {string | null} language - The preferred language code.
* @returns {Promise<void>} - A promise that resolves when the preferred language
* has been successfully updated.
*/
async updatePreferredLanguage(language) {
await NativeModule.updatePreferredLanguage(language);
}
/**
* Registers a user for the device.
*
* To register the device anonymously, set both `userId` and `userName` to `null`.
*
* @param {string | null} userId - Optional user identifier.
* @param {string | null} userName - Optional username.
* @returns {Promise<void>} - A promise that resolves when the user has been
* successfully registered.
*
* @deprecated Use updateUser() instead.
*/
async register(userId, userName) {
await NativeModule.registerUser(userId, userName);
}
/**
* Updates the user information for the device.
*
* To register the device anonymously, set both `userId` and `userName` to `null`.
*
* @param {string | null} userId - Optional user identifier.
* @param {string | null} userName - Optional username.
* @returns {Promise<void>} - A promise that resolves when the user information
* has been successfully updated.
*/
async updateUser(userId, userName) {
await NativeModule.updateUser(userId, userName);
}
/**
* Fetches the tags associated with the device.
*
* @return {Promise<string[]>} - A promise that resolves to a list of tags
* currently associated with the device.
*/
async fetchTags() {
return await NativeModule.fetchTags();
}
/**
* Adds a single tag to the device.
*
* @param {string} tag - The tag to add.
* @returns {Promise<void>} - A promise that resolves when the tag has been
* successfully added to the device.
*/
async addTag(tag) {
await NativeModule.addTag(tag);
}
/**
* Adds multiple tags to the device.
*
* @param {string[]} tags - A list of tags to add.
* @returns {Promise<void>} - A promise that resolves when all the tags have
* been successfully added to the device.
*/
async addTags(tags) {
await NativeModule.addTags(tags);
}
/**
* Removes a specific tag from the device.
*
* @param {string} tag - The tag to remove.
* @returns {Promise<void>} - A promise that resolves when the tag has been
* successfully removed from the device.
*/
async removeTag(tag) {
await NativeModule.removeTag(tag);
}
/**
* Removes multiple tags from the device.
*
* @param {string[]} tags - A list of tags to remove.
* @returns {Promise<void>} - A promise that resolves when all the specified tags
* have been successfully removed from the device.
*/
async removeTags(tags) {
await NativeModule.removeTags(tags);
}
/**
* Clears all tags from the device.
*
* @returns {Promise<void>} - A promise that resolves when all tags have been
* successfully cleared from the device.
*/
async clearTags() {
await NativeModule.clearTags();
}
/**
* Fetches the "Do Not Disturb" (DND) settings for the device.
*
* @return {Promise<NotificareDoNotDisturb | null>} - A promise that resolves
* to the current {@link NotificareDoNotDisturb} settings, or `null` if
* none are set.
*/
async fetchDoNotDisturb() {
return await NativeModule.fetchDoNotDisturb();
}
/**
* Updates the "Do Not Disturb" (DND) settings for the device.
*
* @param {NotificareDoNotDisturb} dnd - The new {@link NotificareDoNotDisturb}
* settings to apply.
* @returns {Promise<void>} - A promise that resolves when the DND settings
* have been successfully updated.
*/
async updateDoNotDisturb(dnd) {
await NativeModule.updateDoNotDisturb(dnd);
}
/**
* Clears the "Do Not Disturb" (DND) settings for the device.
*
* @returns {Promise<void>} - A promise that resolves when the DND settings
* have been successfully cleared.
*/
async clearDoNotDisturb() {
await NativeModule.clearDoNotDisturb();
}
/**
* Fetches the user data associated with the device.
*
* @return {Promise<Record<string, string>>} - A promise that resolves to a
* {@link Record} object containing the current user data.
*/
async fetchUserData() {
return await NativeModule.fetchUserData();
}
/**
* Updates the custom user data associated with the device.
*
* @param {Record<string, string | null>} userData - The updated user data to associate
* with the device.
* @returns {Promise<void>} - A promise that resolves when the user data has
* been successfully updated.
*/
async updateUserData(userData) {
if (_reactNative.Platform.OS === 'ios') {
// Convert useData record into an array of objects in order to handler NULL values in iOS as those are only received in the interop layer (https://github.com/facebook/react-native/pull/49250)
const data = Object.entries(userData).map(([key, value]) => ({
key,
value
}));
return await NativeModule.updateUserData(data);
}
await NativeModule.updateUserData(userData);
}
}
exports.NotificareDeviceModule = NotificareDeviceModule;
//# sourceMappingURL=notificare-device-module.js.map
;