@developer_tribe/react-native-comnyx 0.13.9 → 0.13.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/comnyx/src/messaging/notifications/NotificationsService.kt +12 -1
- package/lib/commonjs/notifications/initializeNotifications.js +1 -0
- package/lib/commonjs/notifications/initializeNotifications.js.map +1 -1
- package/lib/commonjs/register/collectData.js +10 -6
- package/lib/commonjs/register/collectData.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/notifications/initializeNotifications.js +1 -0
- package/lib/module/notifications/initializeNotifications.js.map +1 -1
- package/lib/module/register/collectData.js +10 -6
- package/lib/module/register/collectData.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/src/notifications/initializeNotifications.d.ts.map +1 -1
- package/lib/typescript/src/register/collectData.d.ts +1 -1
- package/lib/typescript/src/register/collectData.d.ts.map +1 -1
- package/lib/typescript/src/version.d.ts +1 -1
- package/lib/typescript/src/version.d.ts.map +1 -1
- package/package.json +25 -13
- package/src/notifications/initializeNotifications.ts +1 -0
- package/src/register/collectData.ts +13 -9
- package/src/version.ts +1 -1
- package/lib/typescript/src/__tests__/acumulator.test.d.ts +0 -2
- package/lib/typescript/src/__tests__/acumulator.test.d.ts.map +0 -1
- package/src/__tests__/acumulator.test.ts +0 -216
package/android/src/main/java/com/comnyx/src/messaging/notifications/NotificationsService.kt
CHANGED
|
@@ -15,6 +15,7 @@ import com.facebook.react.bridge.Arguments
|
|
|
15
15
|
import com.facebook.react.bridge.WritableMap
|
|
16
16
|
import com.google.firebase.messaging.RemoteMessage
|
|
17
17
|
import com.comnyx.Logger
|
|
18
|
+
import kotlin.math.abs
|
|
18
19
|
|
|
19
20
|
class NotificationsHelper(private val context: Context) {
|
|
20
21
|
|
|
@@ -149,7 +150,17 @@ class NotificationsHelper(private val context: Context) {
|
|
|
149
150
|
.setContentIntent(pendingIntent)
|
|
150
151
|
|
|
151
152
|
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
152
|
-
|
|
153
|
+
// Use a unique notification id per message so notifications don't overwrite each other.
|
|
154
|
+
// Prefer FCM's messageId when available; fall back to sentTime/currentTimeMillis.
|
|
155
|
+
val notificationId: Int = remoteMessage.messageId
|
|
156
|
+
?.hashCode()
|
|
157
|
+
?.let { if (it == Int.MIN_VALUE) Int.MAX_VALUE else abs(it) }
|
|
158
|
+
?: run {
|
|
159
|
+
val basis = if (remoteMessage.sentTime > 0) remoteMessage.sentTime else System.currentTimeMillis()
|
|
160
|
+
(basis % Int.MAX_VALUE).toInt()
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
notificationManager.notify(notificationId, builder.build())
|
|
153
164
|
Logger.i("Notification displayed successfully", TAG)
|
|
154
165
|
|
|
155
166
|
val writableMap: WritableMap = Arguments.createMap()
|
|
@@ -53,6 +53,7 @@ async function initializeNativeNotifications(options) {
|
|
|
53
53
|
const state = _store.useAppStore.getState();
|
|
54
54
|
//TODO: better event listener. Event listener doesn't work if its set after initialize
|
|
55
55
|
globalSubscriptions.subscriptionsForNotification = [_index.ComnyxNotifications.addEventListener('TOKEN_INIT', data => {
|
|
56
|
+
console.log('TOKEN_INIT', data);
|
|
56
57
|
_store.useAppStore.getState().setToken(data.token);
|
|
57
58
|
if (_reactNative.Platform.OS === 'ios') {
|
|
58
59
|
_Accumulator.accumulator.add({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_index","_NativeComnyx","_store","_api","_useLocalize","_Accumulator","globalSubscriptions","subscriptionsForNotification","subscriptionsForOptIn","isAlertShowing","showAlertDialog","Platform","OS","Alert","alert","localize","text","style","onPress","ComnyxNotifications","linkToSettings","changePermissionStatus","status","state","useAppStore","getState","NotificationPermissionStatus","GRANTED","permissionGiven","setPermissionGiven","accumulator","add","allow_notifications","initializeNativeNotifications","options","addEventListener","data","setToken","token","apnsToken","fcmToken","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_index","_NativeComnyx","_store","_api","_useLocalize","_Accumulator","globalSubscriptions","subscriptionsForNotification","subscriptionsForOptIn","isAlertShowing","showAlertDialog","Platform","OS","Alert","alert","localize","text","style","onPress","ComnyxNotifications","linkToSettings","changePermissionStatus","status","state","useAppStore","getState","NotificationPermissionStatus","GRANTED","permissionGiven","setPermissionGiven","accumulator","add","allow_notifications","initializeNativeNotifications","options","addEventListener","data","console","log","setToken","token","apnsToken","fcmToken","error","sendOptions","nativeComnyx","initialize","then","res","setNotificationInitialized","success","platform","country","language","timezone","initializeNotifications","params","isInitCalled","Error","isLoginCalled","logLevel","result","length","forEach","subscription","remove","permissionResult","checkOptIn","showOptIn","DENIED","permissionResultAfterDenied","optIn","BLOCKED","AppState","nextAppState","permissionGivenInForeground","notificationInitialized","showOptInOnForeground","permissionResultInner"],"sourceRoot":"../../../src","sources":["notifications/initializeNotifications.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAOA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AAKA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,IAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AAEA,IAAIO,mBAAmB,GAAG;EACxBC,4BAA4B,EAAE,EAA2B;EACzDC,qBAAqB,EAAE;AACzB,CAAC;AAED,IAAIC,cAAc,GAAG,KAAK;AAS1B,SAASC,eAAeA,CAAA,EAAG;EACzB,IAAIC,qBAAQ,CAACC,EAAE,KAAK,KAAK,IAAIH,cAAc,EAAE;IAC3C;EACF;EAEAA,cAAc,GAAG,IAAI;EACrBI,kBAAK,CAACC,KAAK,CACT,IAAAC,qBAAQ,EAAC,2BAA2B,CAAC,EACrC,IAAAA,qBAAQ,EAAC,iCAAiC,CAAC,EAC3C,CACE;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,YAAY,KAAK,QAAQ,EAAE;MAC7B,MAAMC,2BAA2B,GAC/B,MAAMxD,0BAAmB,CAACgD,UAAU,CAAC,CAAC;MACxC9C,sBAAsB,CAACsD,2BAA2B,CAAC;MACnD,IACEA,2BAA2B,KAAKjD,0CAA4B,CAACC,OAAO,EACpE;QACA,MAAMJ,KAAK,GAAGC,kBAAW,CAACC,QAAQ,CAAC,CAAC;QACpC,IAAI,CAACF,KAAK,CAACqD,uBAAuB,EAAE;UAClC,MAAM3C,6BAA6B,CAACC,OAAO,CAAC;QAC9C;MACF,CAAC,MAAM;QACL,IAAIsB,MAAM,CAACqB,qBAAqB,EAAE;UAChC1D,0BAAmB,CAACoD,KAAK,CAAC,CAAC,CAACxB,IAAI,CAAC,MAAO+B,qBAAqB,IAAK;YAChEzD,sBAAsB,CAACyD,qBAAqB,CAAC;YAC7C,IACEA,qBAAqB,KAAKpD,0CAA4B,CAACC,OAAO,EAC9D;cACA,MAAMM,6BAA6B,CAACC,OAAO,CAAC;YAC9C,CAAC,MAAM,IACL4C,qBAAqB,KAAKpD,0CAA4B,CAAC8C,OAAO,EAC9D;cACA,IAAIhB,MAAM,CAACpC,cAAc,EAAE;gBACzBV,eAAe,CAAC,CAAC;cACnB;YACF;UACF,CAAC,CAAC;QACJ;MACF;IACF;EACF,CACF,CAAC;EAED,OAAOmD,MAAM;AACf","ignoreList":[]}
|
|
@@ -7,12 +7,16 @@ exports.collectData = collectData;
|
|
|
7
7
|
exports.registerOneSignalForComnyx = registerOneSignalForComnyx;
|
|
8
8
|
var _Accumulator = require("./Accumulator.js");
|
|
9
9
|
function collectData(key, value) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
if (typeof key === 'string') {
|
|
11
|
+
_Accumulator.accumulator.add({
|
|
12
|
+
customParameters: [{
|
|
13
|
+
name: key,
|
|
14
|
+
value
|
|
15
|
+
}]
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
_Accumulator.accumulator.add(key);
|
|
19
|
+
}
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
//* @deprecated
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_Accumulator","require","collectData","key","value","accumulator","add","customParameters","name","registerOneSignalForComnyx","external_id","integrationParameters","onesignal"],"sourceRoot":"../../../src","sources":["register/collectData.ts"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEO,SAASC,WAAWA,CAAIC,
|
|
1
|
+
{"version":3,"names":["_Accumulator","require","collectData","key","value","accumulator","add","customParameters","name","registerOneSignalForComnyx","external_id","integrationParameters","onesignal"],"sourceRoot":"../../../src","sources":["register/collectData.ts"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEO,SAASC,WAAWA,CAAIC,GAAiC,EAAEC,KAAS,EAAE;EAC3E,IAAI,OAAOD,GAAG,KAAK,QAAQ,EAAE;IAC3BE,wBAAW,CAACC,GAAG,CAAC;MACdC,gBAAgB,EAAE,CAChB;QACEC,IAAI,EAAEL,GAAG;QACTC;MACF,CAAC;IAEL,CAAC,CAAC;EACJ,CAAC,MAAM;IACLC,wBAAW,CAACC,GAAG,CAACH,GAAG,CAAC;EACtB;AACF;;AAEA;AACO,SAASM,0BAA0BA,CAACC,WAAmB,EAAE;EAC9DL,wBAAW,CAACC,GAAG,CAAC;IACdK,qBAAqB,EAAE;MACrBC,SAAS,EAAE;QACTF;MACF;IACF;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
|
package/lib/commonjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["VERSION","exports"],"sourceRoot":"../../src","sources":["version.ts"],"mappings":";;;;;;AAAA;AACO,MAAMA,OAAO,GAAAC,OAAA,CAAAD,OAAA,GAAG,
|
|
1
|
+
{"version":3,"names":["VERSION","exports"],"sourceRoot":"../../src","sources":["version.ts"],"mappings":";;;;;;AAAA;AACO,MAAMA,OAAO,GAAAC,OAAA,CAAAD,OAAA,GAAG,SAAS","ignoreList":[]}
|
|
@@ -49,6 +49,7 @@ async function initializeNativeNotifications(options) {
|
|
|
49
49
|
const state = useAppStore.getState();
|
|
50
50
|
//TODO: better event listener. Event listener doesn't work if its set after initialize
|
|
51
51
|
globalSubscriptions.subscriptionsForNotification = [ComnyxNotifications.addEventListener('TOKEN_INIT', data => {
|
|
52
|
+
console.log('TOKEN_INIT', data);
|
|
52
53
|
useAppStore.getState().setToken(data.token);
|
|
53
54
|
if (Platform.OS === 'ios') {
|
|
54
55
|
accumulator.add({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Alert","AppState","Platform","ComnyxNotifications","nativeComnyx","NotificationPermissionStatus","useAppStore","isInitCalled","isLoginCalled","localize","accumulator","globalSubscriptions","subscriptionsForNotification","subscriptionsForOptIn","isAlertShowing","showAlertDialog","OS","alert","text","style","onPress","linkToSettings","changePermissionStatus","status","state","getState","GRANTED","permissionGiven","setPermissionGiven","add","allow_notifications","initializeNativeNotifications","options","addEventListener","data","setToken","token","apnsToken","fcmToken","
|
|
1
|
+
{"version":3,"names":["Alert","AppState","Platform","ComnyxNotifications","nativeComnyx","NotificationPermissionStatus","useAppStore","isInitCalled","isLoginCalled","localize","accumulator","globalSubscriptions","subscriptionsForNotification","subscriptionsForOptIn","isAlertShowing","showAlertDialog","OS","alert","text","style","onPress","linkToSettings","changePermissionStatus","status","state","getState","GRANTED","permissionGiven","setPermissionGiven","add","allow_notifications","initializeNativeNotifications","options","addEventListener","data","console","log","setToken","token","apnsToken","fcmToken","error","sendOptions","initialize","then","res","setNotificationInitialized","success","platform","country","language","timezone","initializeNotifications","params","Error","logLevel","result","length","forEach","subscription","remove","permissionResult","checkOptIn","showOptIn","DENIED","permissionResultAfterDenied","optIn","BLOCKED","nextAppState","permissionGivenInForeground","notificationInitialized","showOptInOnForeground","permissionResultInner"],"sourceRoot":"../../../src","sources":["notifications/initializeNotifications.ts"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cACA,MAAMK,6BAA6B,CAACC,OAAO,CAAC;YAC9C,CAAC,MAAM,IACLwC,qBAAqB,KAAKnE,4BAA4B,CAAC8D,OAAO,EAC9D;cACA,IAAId,MAAM,CAAChC,cAAc,EAAE;gBACzBN,eAAe,CAAC,CAAC;cACnB;YACF;UACF,CAAC,CAAC;QACJ;MACF;IACF;EACF,CACF,CAAC;EAED,OAAOyC,MAAM;AACf","ignoreList":[]}
|
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
import { accumulator } from "./Accumulator.js";
|
|
4
4
|
export function collectData(key, value) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
if (typeof key === 'string') {
|
|
6
|
+
accumulator.add({
|
|
7
|
+
customParameters: [{
|
|
8
|
+
name: key,
|
|
9
|
+
value
|
|
10
|
+
}]
|
|
11
|
+
});
|
|
12
|
+
} else {
|
|
13
|
+
accumulator.add(key);
|
|
14
|
+
}
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
//* @deprecated
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["accumulator","collectData","key","value","add","customParameters","name","registerOneSignalForComnyx","external_id","integrationParameters","onesignal"],"sourceRoot":"../../../src","sources":["register/collectData.ts"],"mappings":";;AAAA,SAASA,WAAW,QAAQ,kBAAe;AAE3C,OAAO,SAASC,WAAWA,CAAIC,
|
|
1
|
+
{"version":3,"names":["accumulator","collectData","key","value","add","customParameters","name","registerOneSignalForComnyx","external_id","integrationParameters","onesignal"],"sourceRoot":"../../../src","sources":["register/collectData.ts"],"mappings":";;AAAA,SAASA,WAAW,QAAQ,kBAAe;AAE3C,OAAO,SAASC,WAAWA,CAAIC,GAAiC,EAAEC,KAAS,EAAE;EAC3E,IAAI,OAAOD,GAAG,KAAK,QAAQ,EAAE;IAC3BF,WAAW,CAACI,GAAG,CAAC;MACdC,gBAAgB,EAAE,CAChB;QACEC,IAAI,EAAEJ,GAAG;QACTC;MACF,CAAC;IAEL,CAAC,CAAC;EACJ,CAAC,MAAM;IACLH,WAAW,CAACI,GAAG,CAACF,GAAG,CAAC;EACtB;AACF;;AAEA;AACA,OAAO,SAASK,0BAA0BA,CAACC,WAAmB,EAAE;EAC9DR,WAAW,CAACI,GAAG,CAAC;IACdK,qBAAqB,EAAE;MACrBC,SAAS,EAAE;QACTF;MACF;IACF;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
|
package/lib/module/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["VERSION"],"sourceRoot":"../../src","sources":["version.ts"],"mappings":";;AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"names":["VERSION"],"sourceRoot":"../../src","sources":["version.ts"],"mappings":";;AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,SAAS","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initializeNotifications.d.ts","sourceRoot":"","sources":["../../../../src/notifications/initializeNotifications.ts"],"names":[],"mappings":"AAyBA,MAAM,WAAW,6BAA6B;IAC5C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;CACrE;
|
|
1
|
+
{"version":3,"file":"initializeNotifications.d.ts","sourceRoot":"","sources":["../../../../src/notifications/initializeNotifications.ts"],"names":[],"mappings":"AAyBA,MAAM,WAAW,6BAA6B;IAC5C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;CACrE;AAwFD,wBAAsB,uBAAuB,CAC3C,MAAM,GAAE,6BAAkC,oBAqF3C"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function collectData<T>(key: string, value
|
|
1
|
+
export declare function collectData<T>(key: string | Record<string, any>, value?: T): void;
|
|
2
2
|
export declare function registerOneSignalForComnyx(external_id: string): void;
|
|
3
3
|
//# sourceMappingURL=collectData.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collectData.d.ts","sourceRoot":"","sources":["../../../../src/register/collectData.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"collectData.d.ts","sourceRoot":"","sources":["../../../../src/register/collectData.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,QAa1E;AAGD,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,MAAM,QAQ7D"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.13.
|
|
1
|
+
export declare const VERSION = "0.13.13";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@developer_tribe/react-native-comnyx",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.13",
|
|
4
4
|
"description": "React Native chat component with integrated support panel, enabling real-time customer communication and efficient agent workflow management.",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -21,13 +21,25 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"src",
|
|
23
23
|
"lib",
|
|
24
|
-
"android
|
|
25
|
-
"android/build.gradle",
|
|
26
|
-
"android/gradle.properties",
|
|
24
|
+
"android",
|
|
27
25
|
"ios",
|
|
28
26
|
"cpp",
|
|
29
27
|
"*.podspec",
|
|
30
|
-
"react-native.config.js"
|
|
28
|
+
"react-native.config.js",
|
|
29
|
+
"!node_modules",
|
|
30
|
+
"!example",
|
|
31
|
+
"!example820",
|
|
32
|
+
"!server-scripts",
|
|
33
|
+
"!ios/build",
|
|
34
|
+
"!android/build",
|
|
35
|
+
"!android/gradle",
|
|
36
|
+
"!android/gradlew",
|
|
37
|
+
"!android/gradlew.bat",
|
|
38
|
+
"!android/local.properties",
|
|
39
|
+
"!**/__tests__",
|
|
40
|
+
"!**/__fixtures__",
|
|
41
|
+
"!**/__mocks__",
|
|
42
|
+
"!**/.*"
|
|
31
43
|
],
|
|
32
44
|
"scripts": {
|
|
33
45
|
"test": "jest --config jest.config.ts",
|
|
@@ -73,18 +85,18 @@
|
|
|
73
85
|
"eslint-plugin-prettier": "^5.0.1",
|
|
74
86
|
"jest": "^29.7.0",
|
|
75
87
|
"prettier": "^3.0.3",
|
|
76
|
-
"react-hook-form": "^7.66.0",
|
|
77
|
-
"react-native": "^0.82.1",
|
|
78
88
|
"react-native-builder-bob": "^0.33.1",
|
|
79
|
-
"react-native-mmkv": "^4.0.0",
|
|
80
|
-
"react-native-nitro-modules": "^0.31.4",
|
|
81
|
-
"react-native-safe-area-context": "^5.5.2",
|
|
82
89
|
"release-it": "^17.10.0",
|
|
83
90
|
"ts-jest": "^29.4.5",
|
|
84
91
|
"ts-node": "^10.9.2",
|
|
85
92
|
"typescript": "5.1.6",
|
|
86
93
|
"use-sync-external-store": "^1.5.0",
|
|
87
|
-
"zustand": "^5.0.3"
|
|
94
|
+
"zustand": "^5.0.3",
|
|
95
|
+
"react-hook-form": "^7.66.0",
|
|
96
|
+
"react-native-mmkv": "^4.0.0",
|
|
97
|
+
"react-native-nitro-modules": "^0.31.4",
|
|
98
|
+
"react-native-safe-area-context": "^5.5.2",
|
|
99
|
+
"react-native": "^0.82.1"
|
|
88
100
|
},
|
|
89
101
|
"resolutions": {
|
|
90
102
|
"@types/react": "^18.2.44",
|
|
@@ -92,11 +104,11 @@
|
|
|
92
104
|
},
|
|
93
105
|
"peerDependencies": {
|
|
94
106
|
"react": ">=19.0.0",
|
|
95
|
-
"react-hook-form": ">=7.66.0",
|
|
96
107
|
"react-native": ">=0.81.0",
|
|
97
108
|
"react-native-mmkv": ">=4.0.0",
|
|
98
109
|
"react-native-nitro-modules": ">=0.31.4",
|
|
99
|
-
"react-native-safe-area-context": ">=5.5.2"
|
|
110
|
+
"react-native-safe-area-context": ">=5.5.2",
|
|
111
|
+
"react-hook-form": ">=7.66.0"
|
|
100
112
|
},
|
|
101
113
|
"jest": {
|
|
102
114
|
"preset": "react-native",
|
|
@@ -84,6 +84,7 @@ async function initializeNativeNotifications(options: InitializeOptions) {
|
|
|
84
84
|
//TODO: better event listener. Event listener doesn't work if its set after initialize
|
|
85
85
|
globalSubscriptions.subscriptionsForNotification = [
|
|
86
86
|
ComnyxNotifications.addEventListener('TOKEN_INIT', (data) => {
|
|
87
|
+
console.log('TOKEN_INIT', data);
|
|
87
88
|
useAppStore.getState().setToken(data.token);
|
|
88
89
|
if (Platform.OS === 'ios') {
|
|
89
90
|
accumulator.add({
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { accumulator } from './Accumulator';
|
|
2
2
|
|
|
3
|
-
export function collectData<T>(key: string, value
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
export function collectData<T>(key: string | Record<string, any>, value?: T) {
|
|
4
|
+
if (typeof key === 'string') {
|
|
5
|
+
accumulator.add({
|
|
6
|
+
customParameters: [
|
|
7
|
+
{
|
|
8
|
+
name: key,
|
|
9
|
+
value,
|
|
10
|
+
},
|
|
11
|
+
],
|
|
12
|
+
});
|
|
13
|
+
} else {
|
|
14
|
+
accumulator.add(key);
|
|
15
|
+
}
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
//* @deprecated
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is auto-generated. Do not edit manually.
|
|
2
|
-
export const VERSION = '0.13.
|
|
2
|
+
export const VERSION = '0.13.13';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"acumulator.test.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/acumulator.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
// Mock timer functions
|
|
2
|
-
import { Accumulator } from '../register/Accumulator';
|
|
3
|
-
|
|
4
|
-
jest.useFakeTimers();
|
|
5
|
-
|
|
6
|
-
describe('Accumulator', () => {
|
|
7
|
-
let accumulator: Accumulator;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
// Create a new accumulator instance before each test
|
|
11
|
-
accumulator = new Accumulator();
|
|
12
|
-
jest.clearAllMocks();
|
|
13
|
-
jest.clearAllTimers();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe('register', () => {
|
|
17
|
-
it('should register a listener and initialize data', () => {
|
|
18
|
-
const mockListener = jest.fn();
|
|
19
|
-
accumulator.register(mockListener);
|
|
20
|
-
|
|
21
|
-
expect(accumulator.get()).toEqual({
|
|
22
|
-
customParameters: [],
|
|
23
|
-
integrationParameters: {},
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe('add', () => {
|
|
29
|
-
it('should throw error if register was not called', () => {
|
|
30
|
-
expect(() => {
|
|
31
|
-
accumulator.add({ customParameters: [] });
|
|
32
|
-
}).toThrow('Register data is not set');
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should merge custom parameters correctly', () => {
|
|
36
|
-
const mockListener = jest.fn();
|
|
37
|
-
accumulator.register(mockListener);
|
|
38
|
-
|
|
39
|
-
accumulator.add({
|
|
40
|
-
customParameters: [{ name: 'param1', value: 'value1' }],
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
accumulator.add({
|
|
44
|
-
customParameters: [{ name: 'param2', value: 'value2' }],
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
expect(accumulator.get()?.customParameters).toEqual([
|
|
48
|
-
{ name: 'param1', value: 'value1' },
|
|
49
|
-
{ name: 'param2', value: 'value2' },
|
|
50
|
-
]);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('should override existing custom parameters with same name', () => {
|
|
54
|
-
const mockListener = jest.fn();
|
|
55
|
-
accumulator.register(mockListener);
|
|
56
|
-
|
|
57
|
-
accumulator.add({
|
|
58
|
-
customParameters: [{ name: 'param1', value: 'value1' }],
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
accumulator.add({
|
|
62
|
-
customParameters: [{ name: 'param1', value: 'newValue' }],
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
expect(accumulator.get()?.customParameters).toEqual([
|
|
66
|
-
{ name: 'param1', value: 'newValue' },
|
|
67
|
-
]);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should merge integration parameters', () => {
|
|
71
|
-
const mockListener = jest.fn();
|
|
72
|
-
accumulator.register(mockListener);
|
|
73
|
-
|
|
74
|
-
accumulator.add({
|
|
75
|
-
integrationParameters: {
|
|
76
|
-
onesignal: {
|
|
77
|
-
external_id: 'id1',
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
accumulator.add({
|
|
83
|
-
integrationParameters: {
|
|
84
|
-
onesignal: {
|
|
85
|
-
external_id: 'id2',
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
expect(accumulator.get()?.integrationParameters).toEqual({
|
|
91
|
-
onesignal: {
|
|
92
|
-
external_id: 'id2',
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe('flush', () => {
|
|
99
|
-
it('should call listener with accumulated data and reset custom parameters', async () => {
|
|
100
|
-
const mockListener = jest.fn().mockResolvedValue(undefined);
|
|
101
|
-
accumulator.register(mockListener);
|
|
102
|
-
|
|
103
|
-
accumulator.add({
|
|
104
|
-
customParameters: [{ name: 'param1', value: 'value1' }],
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
await accumulator.flush();
|
|
108
|
-
|
|
109
|
-
expect(mockListener).toHaveBeenCalledWith({
|
|
110
|
-
customParameters: [{ name: 'param1', value: 'value1' }],
|
|
111
|
-
integrationParameters: {},
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
expect(accumulator.get()?.customParameters).toEqual([]);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('should throw error if register was not called', async () => {
|
|
118
|
-
await expect(accumulator.flush()).rejects.toThrow(
|
|
119
|
-
'Register data is not set'
|
|
120
|
-
);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
describe('debounce', () => {
|
|
125
|
-
it('should call listener after debounce time', () => {
|
|
126
|
-
const mockListener = jest.fn();
|
|
127
|
-
accumulator.register(mockListener);
|
|
128
|
-
|
|
129
|
-
accumulator.add({
|
|
130
|
-
customParameters: [{ name: 'param1', value: 'value1' }],
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
expect(mockListener).not.toHaveBeenCalled();
|
|
134
|
-
|
|
135
|
-
// Fast forward debounce time (3000ms)
|
|
136
|
-
jest.advanceTimersByTime(3000);
|
|
137
|
-
|
|
138
|
-
expect(mockListener).toHaveBeenCalledWith({
|
|
139
|
-
customParameters: [{ name: 'param1', value: 'value1' }],
|
|
140
|
-
integrationParameters: {},
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('should reset timer on multiple calls', () => {
|
|
145
|
-
const mockListener = jest.fn();
|
|
146
|
-
accumulator.register(mockListener);
|
|
147
|
-
|
|
148
|
-
accumulator.add({
|
|
149
|
-
customParameters: [{ name: 'param1', value: 'value1' }],
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
// Advance halfway through debounce time
|
|
153
|
-
jest.advanceTimersByTime(1500);
|
|
154
|
-
|
|
155
|
-
accumulator.add({
|
|
156
|
-
customParameters: [{ name: 'param2', value: 'value2' }],
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
// Advance halfway through debounce time again
|
|
160
|
-
jest.advanceTimersByTime(1500);
|
|
161
|
-
|
|
162
|
-
// Listener should not have been called yet
|
|
163
|
-
expect(mockListener).not.toHaveBeenCalled();
|
|
164
|
-
|
|
165
|
-
// Complete the debounce time
|
|
166
|
-
jest.advanceTimersByTime(1500);
|
|
167
|
-
|
|
168
|
-
expect(mockListener).toHaveBeenCalledWith({
|
|
169
|
-
customParameters: [
|
|
170
|
-
{ name: 'param1', value: 'value1' },
|
|
171
|
-
{ name: 'param2', value: 'value2' },
|
|
172
|
-
],
|
|
173
|
-
integrationParameters: {},
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe('clear and empty', () => {
|
|
179
|
-
it('should clear all data', () => {
|
|
180
|
-
const mockListener = jest.fn();
|
|
181
|
-
accumulator.register(mockListener);
|
|
182
|
-
|
|
183
|
-
accumulator.add({
|
|
184
|
-
customParameters: [{ name: 'param1', value: 'value1' }],
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
accumulator.clear();
|
|
188
|
-
expect(accumulator.get()).toBeNull();
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('should empty data to an empty object', () => {
|
|
192
|
-
const mockListener = jest.fn();
|
|
193
|
-
accumulator.register(mockListener);
|
|
194
|
-
|
|
195
|
-
accumulator.add({
|
|
196
|
-
customParameters: [{ name: 'param1', value: 'value1' }],
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
accumulator.empty();
|
|
200
|
-
expect(accumulator.get()).toEqual({});
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
describe('isListenerCalledOnce', () => {
|
|
205
|
-
it('should return true after listener is called', async () => {
|
|
206
|
-
const mockListener = jest.fn().mockResolvedValue(undefined);
|
|
207
|
-
accumulator.register(mockListener);
|
|
208
|
-
|
|
209
|
-
expect(accumulator.isListenerCalledOnce()).toBeFalsy();
|
|
210
|
-
|
|
211
|
-
await accumulator.flush();
|
|
212
|
-
|
|
213
|
-
expect(accumulator.isListenerCalledOnce()).toBeTruthy();
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
});
|