Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
35 changes: 24 additions & 11 deletions MainSDK.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -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)
})
}

/**
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
64 changes: 64 additions & 0 deletions lib/notification.js
Original file line number Diff line number Diff line change
@@ -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,
})
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@personaclick/rn-sdk",
"version": "3.1.2",
"version": "3.1.3",
"description": "PersonaClick React Native SDK",
"type": "module",
"exports": {
Expand Down Expand Up @@ -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"
Expand Down