@clix-so/react-native-sdk 0.0.1 → 0.0.2-beta.2
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/README.md +51 -5
- package/lib/module/core/Clix.js +9 -7
- package/lib/module/core/Clix.js.map +1 -1
- package/lib/module/core/ClixNotification.js +122 -0
- package/lib/module/core/ClixNotification.js.map +1 -0
- package/lib/module/services/DeviceService.js +27 -19
- package/lib/module/services/DeviceService.js.map +1 -1
- package/lib/module/services/EventAPIService.js +7 -1
- package/lib/module/services/EventAPIService.js.map +1 -1
- package/lib/module/services/EventService.js +8 -5
- package/lib/module/services/EventService.js.map +1 -1
- package/lib/module/services/NotificationService.js +92 -49
- package/lib/module/services/NotificationService.js.map +1 -1
- package/lib/module/services/StorageService.js +52 -15
- package/lib/module/services/StorageService.js.map +1 -1
- package/lib/module/services/TokenService.js +13 -13
- package/lib/module/services/TokenService.js.map +1 -1
- package/lib/module/utils/ClixDateFormatter.js +19 -0
- package/lib/module/utils/ClixDateFormatter.js.map +1 -0
- package/lib/typescript/src/core/Clix.d.ts +11 -11
- package/lib/typescript/src/core/Clix.d.ts.map +1 -1
- package/lib/typescript/src/core/ClixNotification.d.ts +25 -0
- package/lib/typescript/src/core/ClixNotification.d.ts.map +1 -0
- package/lib/typescript/src/services/DeviceService.d.ts +3 -2
- package/lib/typescript/src/services/DeviceService.d.ts.map +1 -1
- package/lib/typescript/src/services/EventAPIService.d.ts +1 -1
- package/lib/typescript/src/services/EventAPIService.d.ts.map +1 -1
- package/lib/typescript/src/services/EventService.d.ts +1 -1
- package/lib/typescript/src/services/EventService.d.ts.map +1 -1
- package/lib/typescript/src/services/NotificationService.d.ts +21 -1
- package/lib/typescript/src/services/NotificationService.d.ts.map +1 -1
- package/lib/typescript/src/services/StorageService.d.ts +11 -6
- package/lib/typescript/src/services/StorageService.d.ts.map +1 -1
- package/lib/typescript/src/services/TokenService.d.ts +5 -5
- package/lib/typescript/src/services/TokenService.d.ts.map +1 -1
- package/lib/typescript/src/utils/ClixDateFormatter.d.ts +4 -0
- package/lib/typescript/src/utils/ClixDateFormatter.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/core/Clix.ts +17 -21
- package/src/core/ClixNotification.ts +157 -0
- package/src/services/DeviceService.ts +35 -20
- package/src/services/EventAPIService.ts +5 -1
- package/src/services/EventService.ts +13 -5
- package/src/services/NotificationService.ts +148 -54
- package/src/services/StorageService.ts +60 -16
- package/src/services/TokenService.ts +13 -15
- package/src/utils/ClixDateFormatter.ts +19 -0
package/README.md
CHANGED
|
@@ -37,12 +37,58 @@ npx expo install @notifee/react-native @react-native-firebase/app @react-native-
|
|
|
37
37
|
|
|
38
38
|
**react-native-mmkv Version Selection (Critical)**
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|---------------------|-------------|---------------------------|
|
|
42
|
-
| **0.70-0.73** | Old Architecture | `^2.12.2` |
|
|
43
|
-
| **0.74+** | New Architecture | `^3.0.1+` |
|
|
40
|
+
This SDK supports multiple versions of react-native-mmkv to ensure compatibility across different React Native versions:
|
|
44
41
|
|
|
45
|
-
|
|
42
|
+
| React Native Version | Architecture | Recommended MMKV Version | Notes |
|
|
43
|
+
|---------------------|-------------|--------------------------|-------|
|
|
44
|
+
| **0.70-0.73** | Old Architecture | `^2.12.2` | Stable, well-tested |
|
|
45
|
+
| **0.74+** | New Architecture | `^3.0.0` or `^4.0.0` | Requires TurboModules enabled |
|
|
46
|
+
| **0.75+** | Old/New Architecture | `^4.0.0` | Full Nitro support |
|
|
47
|
+
|
|
48
|
+
**Flexible Installation**: This SDK's `peerDependencies` allows `react-native-mmkv` versions `^2.12.2 || ^3.0.0 || ^4.0.0`, so you can choose the version that matches your React Native setup. The StorageService automatically detects and uses the correct API for your installed version.
|
|
49
|
+
|
|
50
|
+
**Example installations:**
|
|
51
|
+
```bash
|
|
52
|
+
# For React Native 0.70-0.73 (Old Architecture)
|
|
53
|
+
npm install react-native-mmkv@^2.12.2
|
|
54
|
+
|
|
55
|
+
# For React Native 0.74+ (New Architecture)
|
|
56
|
+
npm install react-native-mmkv@^3.0.0
|
|
57
|
+
# or
|
|
58
|
+
npm install react-native-mmkv@^4.0.0
|
|
59
|
+
|
|
60
|
+
# For React Native 0.75+ (Recommended)
|
|
61
|
+
npm install react-native-mmkv@^4.0.1
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
⚠️ **Important Notes**:
|
|
65
|
+
- MMKV v3.x and v4.x (on RN 0.74) require React Native's New Architecture (TurboModules) to be enabled
|
|
66
|
+
- MMKV v4.x on RN 0.75+ supports both architectures with Nitro
|
|
67
|
+
- The SDK automatically detects which MMKV API version is available and uses the appropriate interface
|
|
68
|
+
|
|
69
|
+
**Additional Setup for MMKV v4.x**:
|
|
70
|
+
|
|
71
|
+
When using MMKV v4.0.0 or higher, you must also install `react-native-nitro-modules`:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npm install react-native-nitro-modules
|
|
75
|
+
# or
|
|
76
|
+
yarn add react-native-nitro-modules
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**iOS Pod Installation Troubleshooting**:
|
|
80
|
+
|
|
81
|
+
If you encounter pod installation errors with MMKV v4.x, add the following line to your `ios/Podfile` after the `prepare_react_native_project!` line:
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
platform :ios, min_ios_version_supported
|
|
85
|
+
prepare_react_native_project!
|
|
86
|
+
|
|
87
|
+
# Add this line for MMKV v4.x compatibility
|
|
88
|
+
use_frameworks! :linkage => :static
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
This configures CocoaPods to use static frameworks, which resolves compatibility issues with Nitro modules. For more details, see the [MMKV V4 Troubleshooting Guide](https://github.com/mrousavy/react-native-mmkv/blob/main/docs/V4_UPGRADE_GUIDE.md#troubleshooting).
|
|
46
92
|
|
|
47
93
|
**Important Setup Note**: uuid requires react-native-get-random-values polyfill:
|
|
48
94
|
```javascript
|
package/lib/module/core/Clix.js
CHANGED
|
@@ -11,8 +11,10 @@ import { TokenService } from "../services/TokenService.js";
|
|
|
11
11
|
import { ClixError } from "../utils/ClixError.js";
|
|
12
12
|
import { ClixLogger, ClixLogLevel } from "../utils/logging/ClixLogger.js";
|
|
13
13
|
import { ClixInitCoordinator } from "./ClixInitCoordinator.js";
|
|
14
|
+
import { ClixNotification } from "./ClixNotification.js";
|
|
14
15
|
export class Clix {
|
|
15
16
|
static initCoordinator = new ClixInitCoordinator();
|
|
17
|
+
static Notification = ClixNotification.shared;
|
|
16
18
|
constructor() {}
|
|
17
19
|
|
|
18
20
|
/**
|
|
@@ -142,7 +144,7 @@ export class Clix {
|
|
|
142
144
|
}
|
|
143
145
|
|
|
144
146
|
/**
|
|
145
|
-
*
|
|
147
|
+
* @deprecated Use Clix.Notification.getToken() instead.
|
|
146
148
|
*/
|
|
147
149
|
static async getPushToken() {
|
|
148
150
|
try {
|
|
@@ -168,11 +170,11 @@ export class Clix {
|
|
|
168
170
|
/**
|
|
169
171
|
* Track event
|
|
170
172
|
*/
|
|
171
|
-
static async trackEvent(name,
|
|
173
|
+
static async trackEvent(name, properties = {}) {
|
|
172
174
|
try {
|
|
173
175
|
await Clix.initCoordinator.waitForInitialization();
|
|
174
176
|
if (this.shared?.eventService) {
|
|
175
|
-
await this.shared.eventService.trackEvent(name,
|
|
177
|
+
await this.shared.eventService.trackEvent(name, properties);
|
|
176
178
|
}
|
|
177
179
|
} catch (error) {
|
|
178
180
|
ClixLogger.error(`Failed to track event: ${error}`);
|
|
@@ -183,11 +185,11 @@ export class Clix {
|
|
|
183
185
|
* Set configuration
|
|
184
186
|
*/
|
|
185
187
|
async setConfig(config) {
|
|
186
|
-
this.storageService = new StorageService();
|
|
188
|
+
this.storageService = new StorageService(config.projectId);
|
|
187
189
|
try {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
190
|
+
this.storageService.set('project_id', config.projectId);
|
|
191
|
+
this.storageService.set('api_key', config.apiKey);
|
|
192
|
+
this.storageService.set('clix_config', {
|
|
191
193
|
projectId: config.projectId,
|
|
192
194
|
apiKey: config.apiKey,
|
|
193
195
|
endpoint: config.endpoint,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ClixAPIClient","DeviceAPIService","DeviceService","EventAPIService","EventService","NotificationService","StorageService","TokenService","ClixError","ClixLogger","ClixLogLevel","ClixInitCoordinator","Clix","initCoordinator","constructor","initialize","config","isInitializationFailed","reset","setLogLevel","logLevel","ERROR","debug","
|
|
1
|
+
{"version":3,"names":["ClixAPIClient","DeviceAPIService","DeviceService","EventAPIService","EventService","NotificationService","StorageService","TokenService","ClixError","ClixLogger","ClixLogLevel","ClixInitCoordinator","ClixNotification","Clix","initCoordinator","Notification","shared","constructor","initialize","config","isInitializationFailed","reset","setLogLevel","logLevel","ERROR","debug","setConfig","completeInitialization","error","errorInstance","Error","String","failInitialization","notInitialized","cause","setUserId","userId","waitForInitialization","deviceService","setProjectUserId","removeUserId","removeProjectUserId","setUserProperty","key","value","updateUserProperties","setUserProperties","userProperties","removeUserProperty","removeUserProperties","keys","getDeviceId","deviceId","getCurrentDeviceId","undefined","getPushToken","notificationService","token","getCurrentToken","level","trackEvent","name","properties","eventService","storageService","projectId","set","apiKey","endpoint","extraHeaders","warn","apiClient","deviceAPIService","eventAPIService","tokenService","getInstance"],"sourceRoot":"../../../src","sources":["core/Clix.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAQ,8BAA2B;AACzD,SAASC,gBAAgB,QAAQ,iCAA8B;AAC/D,SAASC,aAAa,QAAQ,8BAA2B;AACzD,SAASC,eAAe,QAAQ,gCAA6B;AAC7D,SAASC,YAAY,QAAQ,6BAA0B;AACvD,SAASC,mBAAmB,QAAQ,oCAAiC;AACrE,SAASC,cAAc,QAAQ,+BAA4B;AAC3D,SAASC,YAAY,QAAQ,6BAA0B;AACvD,SAASC,SAAS,QAAQ,uBAAoB;AAC9C,SAASC,UAAU,EAAEC,YAAY,QAAQ,gCAA6B;AAEtE,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IAAI,CAAC6C,YAAY,EACjB,IAAI,CAACC,cAAc,EACnB,IAAI,CAAC1B,aAAa,EAClBoC,YACF,CAAC;IACL,CAAC,CAAC,OAAO9C,KAAK,EAAE;MACdnB,UAAU,CAAC6D,IAAI,CACb,+EAA+E,EAC/E1C,KACF,CAAC;IACH;EACF;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { ClixLogger } from "../utils/logging/ClixLogger.js";
|
|
4
|
+
import { Clix } from "./Clix.js";
|
|
5
|
+
export class ClixNotification {
|
|
6
|
+
static shared = new ClixNotification();
|
|
7
|
+
async configure(options = {}) {
|
|
8
|
+
const {
|
|
9
|
+
autoRequestPermission = false,
|
|
10
|
+
autoHandleLandingURL = true
|
|
11
|
+
} = options;
|
|
12
|
+
try {
|
|
13
|
+
await Clix.initCoordinator.waitForInitialization();
|
|
14
|
+
const notificationService = Clix.shared?.notificationService;
|
|
15
|
+
if (!notificationService) {
|
|
16
|
+
ClixLogger.warn('Notification service is not initialized');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
notificationService.setAutoHandleLandingUrl(autoHandleLandingURL);
|
|
20
|
+
if (autoRequestPermission) {
|
|
21
|
+
await notificationService.requestPermission();
|
|
22
|
+
}
|
|
23
|
+
} catch (error) {
|
|
24
|
+
ClixLogger.error('Failed to configure notifications', error);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async requestPermission() {
|
|
28
|
+
try {
|
|
29
|
+
await Clix.initCoordinator.waitForInitialization();
|
|
30
|
+
const notificationService = Clix.shared?.notificationService;
|
|
31
|
+
if (!notificationService) {
|
|
32
|
+
ClixLogger.warn('Notification service is not initialized');
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return await notificationService.requestPermission();
|
|
36
|
+
} catch (error) {
|
|
37
|
+
ClixLogger.error('Failed to request notification permission', error);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async setPermissionGranted(isGranted) {
|
|
42
|
+
try {
|
|
43
|
+
await Clix.initCoordinator.waitForInitialization();
|
|
44
|
+
const notificationService = Clix.shared?.notificationService;
|
|
45
|
+
if (!notificationService) {
|
|
46
|
+
ClixLogger.warn('Notification service is not initialized');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
await notificationService.setPermissionGranted(isGranted);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
ClixLogger.error('Failed to update push permission status on server', error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async getToken() {
|
|
55
|
+
try {
|
|
56
|
+
await Clix.initCoordinator.waitForInitialization();
|
|
57
|
+
const notificationService = Clix.shared?.notificationService;
|
|
58
|
+
if (!notificationService) {
|
|
59
|
+
ClixLogger.warn('Notification service is not initialized');
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
const token = await notificationService.getCurrentToken();
|
|
63
|
+
return token ?? undefined;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
ClixLogger.error('Failed to get push token', error);
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async onMessage(handler) {
|
|
70
|
+
try {
|
|
71
|
+
await Clix.initCoordinator.waitForInitialization();
|
|
72
|
+
const notificationService = Clix.shared?.notificationService;
|
|
73
|
+
if (!notificationService) {
|
|
74
|
+
ClixLogger.warn('Notification service is not initialized');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
notificationService.setMessageHandler(handler);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
ClixLogger.error('Failed to register onMessage handler', error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async onBackgroundMessage(handler) {
|
|
83
|
+
try {
|
|
84
|
+
await Clix.initCoordinator.waitForInitialization();
|
|
85
|
+
const notificationService = Clix.shared?.notificationService;
|
|
86
|
+
if (!notificationService) {
|
|
87
|
+
ClixLogger.warn('Notification service is not initialized');
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
notificationService.setBackgroundMessageHandler(handler);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
ClixLogger.error('Failed to register onBackgroundMessage handler', error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async onNotificationOpened(handler) {
|
|
96
|
+
try {
|
|
97
|
+
await Clix.initCoordinator.waitForInitialization();
|
|
98
|
+
const notificationService = Clix.shared?.notificationService;
|
|
99
|
+
if (!notificationService) {
|
|
100
|
+
ClixLogger.warn('Notification service is not initialized');
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
notificationService.setNotificationOpenedHandler(handler);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
ClixLogger.error('Failed to register onNotificationOpened handler', error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async onFcmTokenError(handler) {
|
|
109
|
+
try {
|
|
110
|
+
await Clix.initCoordinator.waitForInitialization();
|
|
111
|
+
const notificationService = Clix.shared?.notificationService;
|
|
112
|
+
if (!notificationService) {
|
|
113
|
+
ClixLogger.warn('Notification service is not initialized');
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
notificationService.setFcmTokenErrorHandler(handler);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
ClixLogger.error('Failed to register onFcmTokenError handler', error);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=ClixNotification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ClixLogger","Clix","ClixNotification","shared","configure","options","autoRequestPermission","autoHandleLandingURL","initCoordinator","waitForInitialization","notificationService","warn","setAutoHandleLandingUrl","requestPermission","error","setPermissionGranted","isGranted","getToken","undefined","token","getCurrentToken","onMessage","handler","setMessageHandler","onBackgroundMessage","setBackgroundMessageHandler","onNotificationOpened","setNotificationOpenedHandler","onFcmTokenError","setFcmTokenErrorHandler"],"sourceRoot":"../../../src","sources":["core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B,uBAAuB,CAACP,OAAO,CAAC;IACtD,CAAC,CAAC,OAAOR,KAAK,EAAE;MACdd,UAAU,CAACc,KAAK,CAAC,4CAA4C,EAAEA,KAAK,CAAC;IACvE;EACF;AACF","ignoreList":[]}
|
|
@@ -16,18 +16,18 @@ export class DeviceService {
|
|
|
16
16
|
this.tokenService = tokenService;
|
|
17
17
|
this.deviceAPIService = deviceAPIService;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
const existingId =
|
|
19
|
+
getCurrentDeviceId() {
|
|
20
|
+
const existingId = this.storageService.get(DeviceService.DEVICE_ID_KEY);
|
|
21
21
|
if (existingId) {
|
|
22
22
|
return existingId;
|
|
23
23
|
}
|
|
24
24
|
const newId = UUID.generate();
|
|
25
|
-
|
|
25
|
+
this.storageService.set(DeviceService.DEVICE_ID_KEY, newId);
|
|
26
26
|
return newId;
|
|
27
27
|
}
|
|
28
28
|
async setProjectUserId(projectUserId) {
|
|
29
29
|
try {
|
|
30
|
-
const deviceId =
|
|
30
|
+
const deviceId = this.getCurrentDeviceId();
|
|
31
31
|
await this.deviceAPIService.setProjectUserId(deviceId, projectUserId);
|
|
32
32
|
ClixLogger.debug(`Project user ID set: ${projectUserId}`);
|
|
33
33
|
} catch (error) {
|
|
@@ -40,7 +40,7 @@ export class DeviceService {
|
|
|
40
40
|
}
|
|
41
41
|
async removeProjectUserId() {
|
|
42
42
|
try {
|
|
43
|
-
const deviceId =
|
|
43
|
+
const deviceId = this.getCurrentDeviceId();
|
|
44
44
|
await this.deviceAPIService.removeProjectUserId(deviceId);
|
|
45
45
|
ClixLogger.debug('Project user ID removed');
|
|
46
46
|
} catch (error) {
|
|
@@ -54,7 +54,7 @@ export class DeviceService {
|
|
|
54
54
|
async updateUserProperties(properties) {
|
|
55
55
|
try {
|
|
56
56
|
const userProperties = Object.entries(properties).map(([key, value]) => ClixUserProperty.of(key, value));
|
|
57
|
-
const deviceId =
|
|
57
|
+
const deviceId = this.getCurrentDeviceId();
|
|
58
58
|
await this.deviceAPIService.upsertUserProperties(deviceId, userProperties);
|
|
59
59
|
ClixLogger.debug(`User properties updated: ${Object.keys(properties).join(', ')}`);
|
|
60
60
|
} catch (error) {
|
|
@@ -67,7 +67,7 @@ export class DeviceService {
|
|
|
67
67
|
}
|
|
68
68
|
async removeUserProperties(names) {
|
|
69
69
|
try {
|
|
70
|
-
const deviceId =
|
|
70
|
+
const deviceId = this.getCurrentDeviceId();
|
|
71
71
|
await this.deviceAPIService.removeUserProperties(deviceId, names);
|
|
72
72
|
ClixLogger.debug(`User properties removed: ${names.join(', ')}`);
|
|
73
73
|
} catch (error) {
|
|
@@ -80,8 +80,8 @@ export class DeviceService {
|
|
|
80
80
|
}
|
|
81
81
|
async upsertToken(token, tokenType = 'FCM') {
|
|
82
82
|
try {
|
|
83
|
-
|
|
84
|
-
const deviceId =
|
|
83
|
+
this.tokenService.saveToken(token);
|
|
84
|
+
const deviceId = this.getCurrentDeviceId();
|
|
85
85
|
const device = await this.createDevice(deviceId, token);
|
|
86
86
|
await this.deviceAPIService.registerDevice(device);
|
|
87
87
|
ClixLogger.debug(`Token upserted: ${tokenType}`);
|
|
@@ -100,15 +100,23 @@ export class DeviceService {
|
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
+
async upsertIsPushPermissionGranted(isGranted) {
|
|
104
|
+
try {
|
|
105
|
+
const deviceId = this.getCurrentDeviceId();
|
|
106
|
+
const currentToken = this.tokenService.getCurrentToken();
|
|
107
|
+
const device = await this.createDevice(deviceId, currentToken, isGranted);
|
|
108
|
+
await this.deviceAPIService.registerDevice(device);
|
|
109
|
+
ClixLogger.debug(`Push permission status upserted: ${isGranted ? 'granted' : 'denied'}`);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
ClixLogger.error('Failed to upsert push permission status', error);
|
|
112
|
+
throw ClixError.unknownError({
|
|
113
|
+
reason: `Failed to upsert push permission status: ${error}`,
|
|
114
|
+
cause: error
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
103
118
|
async getPushPermissionStatus() {
|
|
104
119
|
try {
|
|
105
|
-
// First check stored permission status
|
|
106
|
-
const storedStatus = await this.storageService.get('notification_permission_status');
|
|
107
|
-
if (storedStatus === 'authorized' || storedStatus === 'provisional') {
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// If no stored status, check current Firebase messaging permission
|
|
112
120
|
const authStatus = await messaging().hasPermission();
|
|
113
121
|
const isGranted = authStatus === messaging.AuthorizationStatus.AUTHORIZED || authStatus === messaging.AuthorizationStatus.PROVISIONAL;
|
|
114
122
|
ClixLogger.debug(`Push permission status: ${isGranted ? 'granted' : 'denied'}`);
|
|
@@ -118,7 +126,7 @@ export class DeviceService {
|
|
|
118
126
|
return false;
|
|
119
127
|
}
|
|
120
128
|
}
|
|
121
|
-
async createDevice(deviceId, token) {
|
|
129
|
+
async createDevice(deviceId, token, isPushPermissionGranted) {
|
|
122
130
|
const platform = DeviceInfo.getSystemName();
|
|
123
131
|
const osName = DeviceInfo.getSystemName();
|
|
124
132
|
const osVersion = DeviceInfo.getSystemVersion();
|
|
@@ -131,7 +139,7 @@ export class DeviceService {
|
|
|
131
139
|
const localeLanguage = locale.split('-')[0] || 'en';
|
|
132
140
|
const localeRegion = locale.split('-')[1] || 'US';
|
|
133
141
|
let adId;
|
|
134
|
-
const
|
|
142
|
+
const pushPermissionGranted = isPushPermissionGranted ?? (await this.getPushPermissionStatus());
|
|
135
143
|
const sdkVersion = await ClixVersion.getVersion();
|
|
136
144
|
return new ClixDevice({
|
|
137
145
|
id: deviceId,
|
|
@@ -148,7 +156,7 @@ export class DeviceService {
|
|
|
148
156
|
sdkType: 'react-native',
|
|
149
157
|
sdkVersion,
|
|
150
158
|
adId,
|
|
151
|
-
isPushPermissionGranted,
|
|
159
|
+
isPushPermissionGranted: pushPermissionGranted,
|
|
152
160
|
pushToken: token,
|
|
153
161
|
pushTokenType: token ? Platform.OS === 'ios' ? 'APNS' : 'FCM' : undefined
|
|
154
162
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["messaging","Platform","DeviceInfo","ClixVersion","ClixDevice","ClixUserProperty","ClixError","ClixLogger","UUID","DeviceService","DEVICE_ID_KEY","constructor","storageService","tokenService","deviceAPIService","getCurrentDeviceId","existingId","get","newId","generate","set","setProjectUserId","projectUserId","deviceId","debug","error","unknownError","reason","cause","removeProjectUserId","updateUserProperties","properties","userProperties","Object","entries","map","key","value","of","upsertUserProperties","keys","join","removeUserProperties","names","upsertToken","token","tokenType","saveToken","device","createDevice","registerDevice","Error","message","includes","warn","
|
|
1
|
+
{"version":3,"names":["messaging","Platform","DeviceInfo","ClixVersion","ClixDevice","ClixUserProperty","ClixError","ClixLogger","UUID","DeviceService","DEVICE_ID_KEY","constructor","storageService","tokenService","deviceAPIService","getCurrentDeviceId","existingId","get","newId","generate","set","setProjectUserId","projectUserId","deviceId","debug","error","unknownError","reason","cause","removeProjectUserId","updateUserProperties","properties","userProperties","Object","entries","map","key","value","of","upsertUserProperties","keys","join","removeUserProperties","names","upsertToken","token","tokenType","saveToken","device","createDevice","registerDevice","Error","message","includes","warn","upsertIsPushPermissionGranted","isGranted","currentToken","getCurrentToken","getPushPermissionStatus","authStatus","hasPermission","AuthorizationStatus","AUTHORIZED","PROVISIONAL","isPushPermissionGranted","platform","getSystemName","osName","osVersion","getSystemVersion","manufacturer","getManufacturer","model","getModel","appName","getApplicationName","appVersion","getVersion","timezone","Intl","DateTimeFormat","resolvedOptions","timeZone","locale","localeLanguage","split","localeRegion","adId","pushPermissionGranted","sdkVersion","id","sdkType","pushToken","pushTokenType","OS","undefined"],"sourceRoot":"../../../src","sources":["services/DeviceService.ts"],"mappings":";;AAAA,OAAOA,SAAS,MAAM,kCAAkC;AACxD,SAASC,QAAQ,QAAQ,cAAc;AACvC,OAAOC,UAAU,MAAM,0BAA0B;AACjD,SAASC,WAAW,QAAQ,wBAAqB;AACjD,SAASC,UAAU,QAAQ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,EAAE,cAAc;MACvBF,UAAU;MACVF,IAAI;MACJvB,uBAAuB,EAAEwB,qBAAqB;MAC9CI,SAAS,EAAEhD,KAAK;MAChBiD,aAAa,EAAEjD,KAAK,GAChB5C,QAAQ,CAAC8F,EAAE,KAAK,KAAK,GACnB,MAAM,GACN,KAAK,GACPC;IACN,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
|
|
@@ -5,7 +5,7 @@ export class EventAPIService {
|
|
|
5
5
|
constructor(apiClient) {
|
|
6
6
|
this.apiClient = apiClient;
|
|
7
7
|
}
|
|
8
|
-
async trackEvent(deviceId, name, properties, messageId) {
|
|
8
|
+
async trackEvent(deviceId, name, properties, messageId, userJourneyId, userJourneyNodeId) {
|
|
9
9
|
try {
|
|
10
10
|
ClixLogger.debug(`Tracking event: ${name} for device: ${deviceId}`);
|
|
11
11
|
const eventRequestBody = {
|
|
@@ -15,6 +15,12 @@ export class EventAPIService {
|
|
|
15
15
|
custom_properties: properties,
|
|
16
16
|
...(messageId && {
|
|
17
17
|
message_id: messageId
|
|
18
|
+
}),
|
|
19
|
+
...(userJourneyId && {
|
|
20
|
+
user_journey_id: userJourneyId
|
|
21
|
+
}),
|
|
22
|
+
...(userJourneyNodeId && {
|
|
23
|
+
user_journey_node_id: userJourneyNodeId
|
|
18
24
|
})
|
|
19
25
|
}
|
|
20
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ClixLogger","EventAPIService","constructor","apiClient","trackEvent","deviceId","name","properties","messageId","debug","eventRequestBody","device_id","event_property","custom_properties","message_id","response","post","body","events","status","Error","JSON","stringify","data","error"],"sourceRoot":"../../../src","sources":["services/EventAPIService.ts"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,gCAA6B;AAGxD,OAAO,MAAMC,eAAe,CAAC;EAC3BC,WAAWA,CAAkBC,SAAwB,EAAE;IAAA,KAA1BA,SAAwB,GAAxBA,SAAwB;EAAG;EAExD,MAAMC,UAAUA,CACdC,QAAgB,EAChBC,IAAY,EACZC,UAA+B,EAC/BC,SAAkB,
|
|
1
|
+
{"version":3,"names":["ClixLogger","EventAPIService","constructor","apiClient","trackEvent","deviceId","name","properties","messageId","userJourneyId","userJourneyNodeId","debug","eventRequestBody","device_id","event_property","custom_properties","message_id","user_journey_id","user_journey_node_id","response","post","body","events","status","Error","JSON","stringify","data","error"],"sourceRoot":"../../../src","sources":["services/EventAPIService.ts"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,gCAA6B;AAGxD,OAAO,MAAMC,eAAe,CAAC;EAC3BC,WAAWA,CAAkBC,SAAwB,EAAE;IAAA,KAA1BA,SAAwB,GAAxBA,SAAwB;EAAG;EAExD,MAAMC,UAAUA,CACdC,QAAgB,EAChBC,IAAY,EACZC,UAA+B,EAC/BC,SAAkB,EAClBC,aAAsB,EACtBC,iBAA0B,EACX;IACf,IAAI;MACFV,UAAU,CAACW,KAAK,CAAC,mBAAmBL,IAAI,gBAAgBD,QAAQ,EAAE,CAAC;MAEnE,MAAMO,gBAAgB,GAAG;QACvBC,SAAS,EAAER,QAAQ;QACnBC,IAAI,EAAEA,IAAI;QACVQ,cAAc,EAAE;UACdC,iBAAiB,EAAER,UAAU;UAC7B,IAAIC,SAAS,IAAI;YAAEQ,UAAU,EAAER;UAAU,CAAC,CAAC;UAC3C,IAAIC,aAAa,IAAI;YAAEQ,eAAe,EAAER;UAAc,CAAC,CAAC;UACxD,IAAIC,iBAAiB,IAAI;YAAEQ,oBAAoB,EAAER;UAAkB,CAAC;QACtE;MACF,CAAC;MAED,MAAMS,QAAQ,GAAG,MAAM,IAAI,CAAChB,SAAS,CAACiB,IAAI,CAAC,SAAS,EAAE;QACpDC,IAAI,EAAE;UACJC,MAAM,EAAE,CAACV,gBAAgB;QAC3B;MACF,CAAC,CAAC;MAEF,IAAIO,QAAQ,CAACI,MAAM,GAAG,GAAG,IAAIJ,QAAQ,CAACI,MAAM,IAAI,GAAG,EAAE;QACnD,MAAM,IAAIC,KAAK,CACb,QAAQL,QAAQ,CAACI,MAAM,KAAKE,IAAI,CAACC,SAAS,CAACP,QAAQ,CAACQ,IAAI,CAAC,EAC3D,CAAC;MACH;MAEA3B,UAAU,CAACW,KAAK,CACd,+BAA+BL,IAAI,gBAAgBD,QAAQ,EAC7D,CAAC;IACH,CAAC,CAAC,OAAOuB,KAAK,EAAE;MACd5B,UAAU,CAAC4B,KAAK,CACd,0BAA0BtB,IAAI,gBAAgBD,QAAQ,EAAE,EACxDuB,KACF,CAAC;MACD,MAAMA,KAAK;IACb;EACF;AACF","ignoreList":[]}
|
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import { ClixDateFormatter } from "../utils/ClixDateFormatter.js";
|
|
3
4
|
import { ClixLogger } from "../utils/logging/ClixLogger.js";
|
|
4
5
|
export class EventService {
|
|
5
6
|
constructor(eventAPIService, deviceService) {
|
|
6
7
|
this.eventAPIService = eventAPIService;
|
|
7
8
|
this.deviceService = deviceService;
|
|
8
9
|
}
|
|
9
|
-
async trackEvent(name, properties, messageId) {
|
|
10
|
+
async trackEvent(name, properties, messageId, userJourneyId, userJourneyNodeId) {
|
|
10
11
|
try {
|
|
11
12
|
ClixLogger.debug(`Tracking event: ${name}`);
|
|
12
|
-
const deviceId =
|
|
13
|
+
const deviceId = this.deviceService.getCurrentDeviceId();
|
|
13
14
|
const cleanProperties = {};
|
|
14
15
|
if (properties) {
|
|
15
16
|
Object.entries(properties).forEach(([key, value]) => {
|
|
16
|
-
if (value
|
|
17
|
-
cleanProperties[key] = value;
|
|
17
|
+
if (value instanceof Date) {
|
|
18
|
+
cleanProperties[key] = ClixDateFormatter.format(value);
|
|
19
|
+
return;
|
|
18
20
|
}
|
|
21
|
+
cleanProperties[key] = value;
|
|
19
22
|
});
|
|
20
23
|
}
|
|
21
|
-
await this.eventAPIService.trackEvent(deviceId, name, cleanProperties, messageId);
|
|
24
|
+
await this.eventAPIService.trackEvent(deviceId, name, cleanProperties, messageId, userJourneyId, userJourneyNodeId);
|
|
22
25
|
ClixLogger.debug(`Event tracked successfully: ${name}`);
|
|
23
26
|
} catch (error) {
|
|
24
27
|
ClixLogger.error(`Failed to track event '${name}': ${error}. Make sure Clix.initialize() has been called.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ClixLogger","EventService","constructor","eventAPIService","deviceService","trackEvent","name","properties","messageId","debug","deviceId","getCurrentDeviceId","cleanProperties","Object","entries","forEach","key","value","
|
|
1
|
+
{"version":3,"names":["ClixDateFormatter","ClixLogger","EventService","constructor","eventAPIService","deviceService","trackEvent","name","properties","messageId","userJourneyId","userJourneyNodeId","debug","deviceId","getCurrentDeviceId","cleanProperties","Object","entries","forEach","key","value","Date","format","error"],"sourceRoot":"../../../src","sources":["services/EventService.ts"],"mappings":";;AAAA,SAASA,iBAAiB,QAAQ,+BAA4B;AAC9D,SAASC,UAAU,QAAQ,gCAA6B;AAIxD,OAAO,MAAMC,YAAY,CAAC;EACxBC,WAAWA,CACQC,eAAgC,EAChCC,aAA4B,EAC7C;IAAA,KAFiBD,eAAgC,GAAhCA,eAAgC;IAAA,KAChCC,aAA4B,GAA5BA,aAA4B;EAC5C;EAEH,MAAMC,UAAUA,CACdC,IAAY,EACZC,UAAgC,EAChCC,SAAkB,EAClBC,aAAsB,EACtBC,iBAA0B,EACX;IACf,IAAI;MACFV,UAAU,CAACW,KAAK,CAAC,mBAAmBL,IAAI,EAAE,CAAC;MAE3C,MAAMM,QAAQ,GAAG,IAAI,CAACR,aAAa,CAACS,kBAAkB,CAAC,CAAC;MAExD,MAAMC,eAAoC,GAAG,CAAC,CAAC;MAC/C,IAAIP,UAAU,EAAE;QACdQ,MAAM,CAACC,OAAO,CAACT,UAAU,CAAC,CAACU,OAAO,CAAC,CAAC,CAACC,GAAG,EAAEC,KAAK,CAAC,KAAK;UACnD,IAAIA,KAAK,YAAYC,IAAI,EAAE;YACzBN,eAAe,CAACI,GAAG,CAAC,GAAGnB,iBAAiB,CAACsB,MAAM,CAACF,KAAK,CAAC;YACtD;UACF;UAEAL,eAAe,CAACI,GAAG,CAAC,GAAGC,KAAK;QAC9B,CAAC,CAAC;MACJ;MAEA,MAAM,IAAI,CAAChB,eAAe,CAACE,UAAU,CACnCO,QAAQ,EACRN,IAAI,EACJQ,eAAe,EACfN,SAAS,EACTC,aAAa,EACbC,iBACF,CAAC;MAEDV,UAAU,CAACW,KAAK,CAAC,+BAA+BL,IAAI,EAAE,CAAC;IACzD,CAAC,CAAC,OAAOgB,KAAK,EAAE;MACdtB,UAAU,CAACsB,KAAK,CACd,0BAA0BhB,IAAI,MAAMgB,KAAK,gDAC3C,CAAC;MACD,MAAMA,KAAK;IACb;EACF;AACF","ignoreList":[]}
|