diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b4a384..5f868e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,23 @@ +## 3.1.3 (2025-08-22) + + +### Bug Fixes + +* **gcm:** message variability (544eb08) + + +### Features + +* **common:** bump version (ce7e70d) +* **sdk:** bump device-info (1d1f10e) +* **sdk:** getToken to use correct token (d07df14) +* **sdk:** in-app push notifications (#51) (6fa0296) +* **sdk:** include types for exclude_brands (#50) (cd1d301) +* **sdk:** rm jest (d0cce5d) +* **sdk:** sid token generation (4a34846) + + + ## 3.1.2 (2025-08-22) diff --git a/MainSDK.js b/MainSDK.js index 6e5a0ce..20ff20d 100644 --- a/MainSDK.js +++ b/MainSDK.js @@ -13,6 +13,7 @@ import { savePushToken } from './lib/client' import { getLastPushTokenSentDate } from './lib/client' import { saveLastPushTokenSentDate } from './lib/client' import { convertParams } from './lib/tracker' +import { NotificationManager } from './lib/notification' import { PermissionsAndroid } from 'react-native' import { Platform } from 'react-native' import { getMessaging } from '@react-native-firebase/messaging' @@ -120,7 +121,10 @@ class MainSDK extends Performer { response.sid = response.seance = generateSid() } } else { - const did = Platform.OS === 'android' ? await DeviceInfo.getAndroidId() : (await DeviceInfo.syncUniqueId()) || ''; + const did = + Platform.OS === 'android' + ? await DeviceInfo.getAndroidId() + : (await DeviceInfo.syncUniqueId()) || '' if (DEBUG) console.log('Device ID: ', did) response = await request('init', this.shop_id, { @@ -152,12 +156,14 @@ class MainSDK extends Performer { isInit = () => this.initialized getToken = () => { - return this.initPushToken().then((token) => { - if (DEBUG) console.log(token) - return token - }).catch((error) => { - console.error(error) - }) + return this.initPushToken() + .then((token) => { + if (DEBUG) console.log(token) + return token + }) + .catch((error) => { + console.error(error) + }) } /** @@ -510,22 +516,22 @@ class MainSDK extends Performer { return savedToken } - let pushToken; + let pushToken if (this._push_type === null && Platform.OS === 'ios') { getAPNSToken(this.messaging).then((token) => { if (DEBUG) console.log('New APN token: ', token) this.setPushTokenNotification(token) - pushToken = token; + pushToken = token }) } else { getToken(this.messaging).then((token) => { if (DEBUG) console.log('New FCM token: ', token) this.setPushTokenNotification(token) - pushToken = token; + pushToken = token }) } - return pushToken; + return pushToken } async initPushChannel() { @@ -834,6 +840,13 @@ class MainSDK extends Performer { console.log(`error open URL: ${message_url}`) } } + + /** + * @param {import('@notifee/react-native').Notification} [params] + */ + async showInAppNotification(params) { + NotificationManager.showNotification(params) + } } export default MainSDK diff --git a/lib/notification.js b/lib/notification.js new file mode 100644 index 0000000..fe68f10 --- /dev/null +++ b/lib/notification.js @@ -0,0 +1,64 @@ +import notifee from '@notifee/react-native' +import { AndroidImportance } from '@notifee/react-native' +import { AndroidVisibility } from '@notifee/react-native' +import { SDK_PUSH_CHANNEL } from '../index.js' +import { Platform } from 'react-native' + +export class NotificationManager { + /** + * @param {import('@notifee/react-native').Notification} notification + * @returns {void} + */ + static async showNotification(notification) { + if (Platform.OS === 'android') { + await this._initInAppChannel() + + if (!notification.android) { + notification.android = {} + } + + if ( + !notification.android.channelId || + notification.android.channelId === '' + ) { + notification.android.channelId = SDK_PUSH_CHANNEL + } + + if (!notification.android.importance) { + notification.android.importance = AndroidImportance.HIGH + } + } + + if (Platform.OS === 'ios') { + if (!notification.ios) { + notification.ios = {} + } + + if (!notification.ios.criticalVolume) { + notification.ios.criticalVolume = 0.0 + } + + if (!notification.ios.badgeCount) { + notification.ios.badgeCount = null + } + } + + try { + return notifee.displayNotification(notification) + } catch (error) { + console.error(error) + } + } + + static async _initInAppChannel() { + return notifee.createChannel({ + id: `${SDK_PUSH_CHANNEL}_IN_APP`, + name: 'In-app notifications', + importance: AndroidImportance.HIGH, + badge: false, + sound: '', + vibration: false, + visibility: AndroidVisibility.PUBLIC, + }) + } +} diff --git a/package.json b/package.json index 0f37120..27c09e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@personaclick/rn-sdk", - "version": "3.1.2", + "version": "3.1.3", "description": "PersonaClick React Native SDK", "type": "module", "exports": { @@ -43,7 +43,7 @@ }, "scripts": { "test": "node --test", - "changelog": "conventional-changelog -i CHANGELOG.md -s --commit-path . -p angular" + "changelog": "conventional-changelog -i CHANGELOG.md -s --commit-path . -p angular -t @personaclick/rn-sdk-" }, "publishConfig": { "access": "public"