@clix-so/react-native-sdk 1.0.0 → 1.1.0
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/lib/module/core/Clix.js +40 -95
- package/lib/module/core/Clix.js.map +1 -1
- package/lib/module/core/ClixInitCoordinator.js +3 -14
- package/lib/module/core/ClixInitCoordinator.js.map +1 -1
- package/lib/module/core/ClixNotification.js +25 -28
- package/lib/module/core/ClixNotification.js.map +1 -1
- package/lib/module/models/ClixDevice.js +0 -6
- package/lib/module/models/ClixDevice.js.map +1 -1
- package/lib/module/models/ClixPushNotificationPayload.js +0 -19
- package/lib/module/models/ClixPushNotificationPayload.js.map +1 -1
- package/lib/module/services/ClixAPIClient.js +50 -99
- package/lib/module/services/ClixAPIClient.js.map +1 -1
- package/lib/module/services/DeviceAPIService.js +37 -45
- package/lib/module/services/DeviceAPIService.js.map +1 -1
- package/lib/module/services/DeviceService.js +97 -116
- package/lib/module/services/DeviceService.js.map +1 -1
- package/lib/module/services/EventAPIService.js +3 -5
- package/lib/module/services/EventAPIService.js.map +1 -1
- package/lib/module/services/EventService.js +13 -20
- package/lib/module/services/EventService.js.map +1 -1
- package/lib/module/services/NotificationService.js +252 -402
- package/lib/module/services/NotificationService.js.map +1 -1
- package/lib/module/services/TokenService.js +3 -59
- package/lib/module/services/TokenService.js.map +1 -1
- package/lib/module/utils/http/HTTPClient.js +101 -0
- package/lib/module/utils/http/HTTPClient.js.map +1 -0
- package/lib/module/utils/http/HTTPMethod.js +10 -0
- package/lib/module/utils/http/HTTPMethod.js.map +1 -0
- package/lib/module/utils/http/HTTPRequest.js +4 -0
- package/lib/module/utils/http/HTTPRequest.js.map +1 -0
- package/lib/module/utils/http/HTTPResponse.js +2 -0
- package/lib/module/utils/http/HTTPResponse.js.map +1 -0
- package/lib/module/utils/types.js +2 -0
- package/lib/module/utils/types.js.map +1 -0
- package/lib/typescript/src/core/Clix.d.ts +13 -15
- package/lib/typescript/src/core/Clix.d.ts.map +1 -1
- package/lib/typescript/src/core/ClixConfig.d.ts +3 -3
- package/lib/typescript/src/core/ClixConfig.d.ts.map +1 -1
- package/lib/typescript/src/core/ClixInitCoordinator.d.ts +0 -3
- package/lib/typescript/src/core/ClixInitCoordinator.d.ts.map +1 -1
- package/lib/typescript/src/core/ClixNotification.d.ts +6 -5
- package/lib/typescript/src/core/ClixNotification.d.ts.map +1 -1
- package/lib/typescript/src/models/ClixDevice.d.ts +0 -2
- package/lib/typescript/src/models/ClixDevice.d.ts.map +1 -1
- package/lib/typescript/src/models/ClixPushNotificationPayload.d.ts +8 -21
- package/lib/typescript/src/models/ClixPushNotificationPayload.d.ts.map +1 -1
- package/lib/typescript/src/services/ClixAPIClient.d.ts +6 -22
- package/lib/typescript/src/services/ClixAPIClient.d.ts.map +1 -1
- package/lib/typescript/src/services/DeviceAPIService.d.ts +1 -1
- package/lib/typescript/src/services/DeviceAPIService.d.ts.map +1 -1
- package/lib/typescript/src/services/DeviceService.d.ts +10 -5
- package/lib/typescript/src/services/DeviceService.d.ts.map +1 -1
- package/lib/typescript/src/services/EventAPIService.d.ts.map +1 -1
- package/lib/typescript/src/services/EventService.d.ts +1 -0
- package/lib/typescript/src/services/EventService.d.ts.map +1 -1
- package/lib/typescript/src/services/NotificationService.d.ts +50 -57
- package/lib/typescript/src/services/NotificationService.d.ts.map +1 -1
- package/lib/typescript/src/services/TokenService.d.ts +1 -7
- package/lib/typescript/src/services/TokenService.d.ts.map +1 -1
- package/lib/typescript/src/utils/http/HTTPClient.d.ts +15 -0
- package/lib/typescript/src/utils/http/HTTPClient.d.ts.map +1 -0
- package/lib/typescript/src/utils/http/HTTPMethod.d.ts +7 -0
- package/lib/typescript/src/utils/http/HTTPMethod.d.ts.map +1 -0
- package/lib/typescript/src/utils/http/HTTPRequest.d.ts +9 -0
- package/lib/typescript/src/utils/http/HTTPRequest.d.ts.map +1 -0
- package/lib/typescript/src/utils/http/HTTPResponse.d.ts +6 -0
- package/lib/typescript/src/utils/http/HTTPResponse.d.ts.map +1 -0
- package/lib/typescript/src/utils/types.d.ts +5 -0
- package/lib/typescript/src/utils/types.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/core/Clix.ts +62 -115
- package/src/core/ClixConfig.ts +3 -3
- package/src/core/ClixInitCoordinator.ts +5 -17
- package/src/core/ClixNotification.ts +36 -37
- package/src/models/ClixDevice.ts +17 -25
- package/src/models/ClixPushNotificationPayload.ts +8 -37
- package/src/services/ClixAPIClient.ts +84 -144
- package/src/services/DeviceAPIService.ts +39 -47
- package/src/services/DeviceService.ts +122 -156
- package/src/services/EventAPIService.ts +3 -5
- package/src/services/EventService.ts +26 -33
- package/src/services/NotificationService.ts +318 -533
- package/src/services/TokenService.ts +4 -71
- package/src/utils/http/HTTPClient.ts +141 -0
- package/src/utils/http/HTTPMethod.ts +6 -0
- package/src/utils/http/HTTPRequest.ts +9 -0
- package/src/utils/http/HTTPResponse.ts +5 -0
- package/src/utils/types.ts +7 -0
|
@@ -1,132 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import messaging from '@react-native-firebase/messaging';
|
|
4
|
-
import { Platform } from 'react-native';
|
|
5
4
|
import DeviceInfo from 'react-native-device-info';
|
|
6
5
|
import { ClixVersion } from "../core/ClixVersion.js";
|
|
7
6
|
import { ClixDevice } from "../models/ClixDevice.js";
|
|
8
7
|
import { ClixUserProperty } from "../models/ClixUserProperty.js";
|
|
9
|
-
import { ClixError } from "../utils/ClixError.js";
|
|
10
8
|
import { ClixLogger } from "../utils/logging/ClixLogger.js";
|
|
11
9
|
import { UUID } from "../utils/UUID.js";
|
|
12
10
|
export class DeviceService {
|
|
13
|
-
|
|
11
|
+
deviceIdKey = 'clix_device_id';
|
|
14
12
|
constructor(storageService, tokenService, deviceAPIService) {
|
|
15
13
|
this.storageService = storageService;
|
|
16
14
|
this.tokenService = tokenService;
|
|
17
15
|
this.deviceAPIService = deviceAPIService;
|
|
18
16
|
}
|
|
17
|
+
async initialize() {
|
|
18
|
+
this.currentDevice = await this.createDevice();
|
|
19
|
+
await this.deviceAPIService.upsertDevice(this.currentDevice);
|
|
20
|
+
}
|
|
21
|
+
generateDeviceId() {
|
|
22
|
+
return UUID.generate();
|
|
23
|
+
}
|
|
19
24
|
getCurrentDeviceId() {
|
|
20
|
-
const existingId = this.storageService.get(
|
|
25
|
+
const existingId = this.storageService.get(this.deviceIdKey);
|
|
21
26
|
if (existingId) {
|
|
22
27
|
return existingId;
|
|
23
28
|
}
|
|
24
|
-
const
|
|
25
|
-
this.storageService.set(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
async setProjectUserId(projectUserId) {
|
|
29
|
-
try {
|
|
30
|
-
const deviceId = this.getCurrentDeviceId();
|
|
31
|
-
await this.deviceAPIService.setProjectUserId(deviceId, projectUserId);
|
|
32
|
-
ClixLogger.debug(`Project user ID set: ${projectUserId}`);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
ClixLogger.error('Failed to set project user ID', error);
|
|
35
|
-
throw ClixError.unknownError({
|
|
36
|
-
reason: `Failed to set project user ID: ${error}`,
|
|
37
|
-
cause: error
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
async removeProjectUserId() {
|
|
42
|
-
try {
|
|
43
|
-
const deviceId = this.getCurrentDeviceId();
|
|
44
|
-
await this.deviceAPIService.removeProjectUserId(deviceId);
|
|
45
|
-
ClixLogger.debug('Project user ID removed');
|
|
46
|
-
} catch (error) {
|
|
47
|
-
ClixLogger.error('Failed to remove project user ID', error);
|
|
48
|
-
throw ClixError.unknownError({
|
|
49
|
-
reason: `Failed to remove project user ID: ${error}`,
|
|
50
|
-
cause: error
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async updateUserProperties(properties) {
|
|
55
|
-
try {
|
|
56
|
-
const userProperties = Object.entries(properties).map(([key, value]) => ClixUserProperty.of(key, value));
|
|
57
|
-
const deviceId = this.getCurrentDeviceId();
|
|
58
|
-
await this.deviceAPIService.upsertUserProperties(deviceId, userProperties);
|
|
59
|
-
ClixLogger.debug(`User properties updated: ${Object.keys(properties).join(', ')}`);
|
|
60
|
-
} catch (error) {
|
|
61
|
-
ClixLogger.error('Failed to update user properties', error);
|
|
62
|
-
throw ClixError.unknownError({
|
|
63
|
-
reason: `Failed to update user properties: ${error}`,
|
|
64
|
-
cause: error
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
async removeUserProperties(names) {
|
|
69
|
-
try {
|
|
70
|
-
const deviceId = this.getCurrentDeviceId();
|
|
71
|
-
await this.deviceAPIService.removeUserProperties(deviceId, names);
|
|
72
|
-
ClixLogger.debug(`User properties removed: ${names.join(', ')}`);
|
|
73
|
-
} catch (error) {
|
|
74
|
-
ClixLogger.error('Failed to remove user properties', error);
|
|
75
|
-
throw ClixError.unknownError({
|
|
76
|
-
reason: `Failed to remove user properties: ${error}`,
|
|
77
|
-
cause: error
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async upsertToken(token, tokenType = 'FCM') {
|
|
82
|
-
try {
|
|
83
|
-
this.tokenService.saveToken(token);
|
|
84
|
-
const deviceId = this.getCurrentDeviceId();
|
|
85
|
-
const device = await this.createDevice(deviceId, token);
|
|
86
|
-
await this.deviceAPIService.registerDevice(device);
|
|
87
|
-
ClixLogger.debug(`Token upserted: ${tokenType}`);
|
|
88
|
-
} catch (error) {
|
|
89
|
-
ClixLogger.error('Failed to upsert token', error);
|
|
90
|
-
|
|
91
|
-
// Don't throw for token upsert failures during initialization
|
|
92
|
-
// This allows the SDK to continue initializing even if token registration fails
|
|
93
|
-
if (error instanceof Error && error.message.includes('crypto.getRandomValues')) {
|
|
94
|
-
ClixLogger.warn('Token upsert failed due to crypto polyfill issue, will retry later');
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
throw ClixError.unknownError({
|
|
98
|
-
reason: `Failed to upsert token: ${error}`,
|
|
99
|
-
cause: error
|
|
100
|
-
});
|
|
101
|
-
}
|
|
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
|
-
}
|
|
118
|
-
async getPushPermissionStatus() {
|
|
119
|
-
try {
|
|
120
|
-
const authStatus = await messaging().hasPermission();
|
|
121
|
-
const isGranted = authStatus === messaging.AuthorizationStatus.AUTHORIZED || authStatus === messaging.AuthorizationStatus.PROVISIONAL;
|
|
122
|
-
ClixLogger.debug(`Push permission status: ${isGranted ? 'granted' : 'denied'}`);
|
|
123
|
-
return isGranted;
|
|
124
|
-
} catch (error) {
|
|
125
|
-
ClixLogger.warn('Failed to get push permission status, defaulting to false', error);
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
29
|
+
const newDeviceId = this.generateDeviceId();
|
|
30
|
+
this.storageService.set(this.deviceIdKey, newDeviceId);
|
|
31
|
+
ClixLogger.debug(`Generated new device ID: ${newDeviceId}`);
|
|
32
|
+
return newDeviceId;
|
|
128
33
|
}
|
|
129
|
-
async createDevice(
|
|
34
|
+
async createDevice() {
|
|
35
|
+
const deviceId = this.getCurrentDeviceId();
|
|
130
36
|
const platform = DeviceInfo.getSystemName();
|
|
131
37
|
const osName = DeviceInfo.getSystemName();
|
|
132
38
|
const osVersion = DeviceInfo.getSystemVersion();
|
|
@@ -138,10 +44,13 @@ export class DeviceService {
|
|
|
138
44
|
const locale = Intl.DateTimeFormat().resolvedOptions().locale || 'en-US';
|
|
139
45
|
const localeLanguage = locale.split('-')[0] || 'en';
|
|
140
46
|
const localeRegion = locale.split('-')[1] || 'US';
|
|
141
|
-
|
|
142
|
-
const
|
|
47
|
+
const adId = undefined; // TODO: Implement Ad ID
|
|
48
|
+
const isPushPermissionGranted = await this.getPushPermissionStatus();
|
|
49
|
+
const sdkType = 'react-native';
|
|
143
50
|
const sdkVersion = await ClixVersion.getVersion();
|
|
144
|
-
|
|
51
|
+
const pushToken = await this.getPushToken();
|
|
52
|
+
const pushTokenType = pushToken ? 'FCM' : undefined;
|
|
53
|
+
const device = new ClixDevice({
|
|
145
54
|
id: deviceId,
|
|
146
55
|
platform,
|
|
147
56
|
model,
|
|
@@ -153,13 +62,85 @@ export class DeviceService {
|
|
|
153
62
|
timezone,
|
|
154
63
|
appName,
|
|
155
64
|
appVersion,
|
|
156
|
-
sdkType
|
|
65
|
+
sdkType,
|
|
157
66
|
sdkVersion,
|
|
158
67
|
adId,
|
|
159
|
-
isPushPermissionGranted
|
|
160
|
-
pushToken
|
|
161
|
-
pushTokenType
|
|
68
|
+
isPushPermissionGranted,
|
|
69
|
+
pushToken,
|
|
70
|
+
pushTokenType
|
|
71
|
+
});
|
|
72
|
+
return device;
|
|
73
|
+
}
|
|
74
|
+
async upsertDevice(device) {
|
|
75
|
+
return this.deviceAPIService.upsertDevice(device);
|
|
76
|
+
}
|
|
77
|
+
async updatePushToken(pushToken, pushTokenType) {
|
|
78
|
+
if (!this.currentDevice) {
|
|
79
|
+
ClixLogger.warn('Device not initialized yet, cannot update push token');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (this.currentDevice.pushToken === pushToken && this.currentDevice.pushTokenType === pushTokenType) {
|
|
83
|
+
ClixLogger.debug('Push token and type are unchanged, skipping update');
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const newDevice = this.currentDevice.copyWith({
|
|
87
|
+
pushToken,
|
|
88
|
+
pushTokenType
|
|
162
89
|
});
|
|
90
|
+
this.currentDevice = newDevice;
|
|
91
|
+
return this.deviceAPIService.upsertDevice(newDevice);
|
|
92
|
+
}
|
|
93
|
+
async updatePushPermission(isGranted) {
|
|
94
|
+
if (!this.currentDevice) {
|
|
95
|
+
ClixLogger.warn('Device not initialized yet, cannot update push permission status');
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (this.currentDevice.isPushPermissionGranted === isGranted) {
|
|
99
|
+
ClixLogger.debug('Push permission status is unchanged, skipping update');
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const newDevice = this.currentDevice.copyWith({
|
|
103
|
+
isPushPermissionGranted: isGranted
|
|
104
|
+
});
|
|
105
|
+
this.currentDevice = newDevice;
|
|
106
|
+
return this.deviceAPIService.upsertDevice(newDevice);
|
|
107
|
+
}
|
|
108
|
+
async setProjectUserId(projectUserId) {
|
|
109
|
+
const deviceId = this.getCurrentDeviceId();
|
|
110
|
+
return this.deviceAPIService.setProjectUserId(deviceId, projectUserId);
|
|
111
|
+
}
|
|
112
|
+
async removeProjectUserId() {
|
|
113
|
+
const deviceId = this.getCurrentDeviceId();
|
|
114
|
+
return this.deviceAPIService.removeProjectUserId(deviceId);
|
|
115
|
+
}
|
|
116
|
+
async updateUserProperties(properties) {
|
|
117
|
+
const deviceId = this.getCurrentDeviceId();
|
|
118
|
+
const userProperties = Object.entries(properties).map(([key, value]) => ClixUserProperty.of(key, value));
|
|
119
|
+
return this.deviceAPIService.upsertUserProperties(deviceId, userProperties);
|
|
120
|
+
}
|
|
121
|
+
async removeUserProperties(names) {
|
|
122
|
+
const deviceId = this.getCurrentDeviceId();
|
|
123
|
+
return this.deviceAPIService.removeUserProperties(deviceId, names);
|
|
124
|
+
}
|
|
125
|
+
async getPushPermissionStatus() {
|
|
126
|
+
try {
|
|
127
|
+
const authStatus = await messaging().hasPermission();
|
|
128
|
+
const isGranted = authStatus === messaging.AuthorizationStatus.AUTHORIZED || authStatus === messaging.AuthorizationStatus.PROVISIONAL;
|
|
129
|
+
return isGranted;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
ClixLogger.warn('Failed to get push permission status, defaulting to false', error);
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async getPushToken() {
|
|
136
|
+
try {
|
|
137
|
+
const token = await messaging().getToken();
|
|
138
|
+
this.tokenService.saveToken(token);
|
|
139
|
+
return token;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
ClixLogger.warn('Failed to get push token', error);
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
163
144
|
}
|
|
164
145
|
}
|
|
165
146
|
//# sourceMappingURL=DeviceService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["messaging","
|
|
1
|
+
{"version":3,"names":["messaging","DeviceInfo","ClixVersion","ClixDevice","ClixUserProperty","ClixLogger","UUID","DeviceService","deviceIdKey","constructor","storageService","tokenService","deviceAPIService","initialize","currentDevice","createDevice","upsertDevice","generateDeviceId","generate","getCurrentDeviceId","existingId","get","newDeviceId","set","debug","deviceId","platform","getSystemName","osName","osVersion","getSystemVersion","manufacturer","getManufacturer","model","getModel","appName","getApplicationName","appVersion","getVersion","timezone","Intl","DateTimeFormat","resolvedOptions","timeZone","locale","localeLanguage","split","localeRegion","adId","undefined","isPushPermissionGranted","getPushPermissionStatus","sdkType","sdkVersion","pushToken","getPushToken","pushTokenType","device","id","updatePushToken","warn","newDevice","copyWith","updatePushPermission","isGranted","setProjectUserId","projectUserId","removeProjectUserId","updateUserProperties","properties","userProperties","Object","entries","map","key","value","of","upsertUserProperties","removeUserProperties","names","authStatus","hasPermission","AuthorizationStatus","AUTHORIZED","PROVISIONAL","error","token","getToken","saveToken"],"sourceRoot":"../../../src","sources":["services/DeviceService.ts"],"mappings":";;AAAA,OAAOA,SAAS,MAAM,kCAAkC;AACxD,OAAOC,UAAU,MAAM,0BAA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CAACC,UAAU,IACvDH,UAAU,KAAKhF,SAAS,CAACkF,mBAAmB,CAACE,WAAW;MAE1D,OAAOpB,SAAS;IAClB,CAAC,CAAC,OAAOqB,KAAK,EAAE;MACdhF,UAAU,CAACuD,IAAI,CACb,2DAA2D,EAC3DyB,KACF,CAAC;MACD,OAAO,KAAK;IACd;EACF;EAEA,MAAc9B,YAAYA,CAAA,EAAgC;IACxD,IAAI;MACF,MAAM+B,KAAK,GAAG,MAAMtF,SAAS,CAAC,CAAC,CAACuF,QAAQ,CAAC,CAAC;MAC1C,IAAI,CAAC5E,YAAY,CAAC6E,SAAS,CAACF,KAAK,CAAC;MAClC,OAAOA,KAAK;IACd,CAAC,CAAC,OAAOD,KAAK,EAAE;MACdhF,UAAU,CAACuD,IAAI,CAAC,0BAA0B,EAAEyB,KAAK,CAAC;MAClD,OAAOpC,SAAS;IAClB;EACF;AACF","ignoreList":[]}
|
|
@@ -25,12 +25,10 @@ export class EventAPIService {
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
const response = await this.apiClient.post('/events', {
|
|
28
|
-
|
|
29
|
-
events: [eventRequestBody]
|
|
30
|
-
}
|
|
28
|
+
events: [eventRequestBody]
|
|
31
29
|
});
|
|
32
|
-
if (response.
|
|
33
|
-
throw new Error(`HTTP ${response.
|
|
30
|
+
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
31
|
+
throw new Error(`HTTP ${response.statusCode}: ${JSON.stringify(response.data)}`);
|
|
34
32
|
}
|
|
35
33
|
ClixLogger.debug(`Event tracked successfully: ${name} for device: ${deviceId}`);
|
|
36
34
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
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","
|
|
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","events","statusCode","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,MAAM,EAAE,CAACT,gBAAgB;MAC3B,CAAC,CAAC;MAEF,IAAIO,QAAQ,CAACG,UAAU,GAAG,GAAG,IAAIH,QAAQ,CAACG,UAAU,IAAI,GAAG,EAAE;QAC3D,MAAM,IAAIC,KAAK,CACb,QAAQJ,QAAQ,CAACG,UAAU,KAAKE,IAAI,CAACC,SAAS,CAACN,QAAQ,CAACO,IAAI,CAAC,EAC/D,CAAC;MACH;MAEA1B,UAAU,CAACW,KAAK,CACd,+BAA+BL,IAAI,gBAAgBD,QAAQ,EAC7D,CAAC;IACH,CAAC,CAAC,OAAOsB,KAAK,EAAE;MACd3B,UAAU,CAAC2B,KAAK,CACd,0BAA0BrB,IAAI,gBAAgBD,QAAQ,EAAE,EACxDsB,KACF,CAAC;MACD,MAAMA,KAAK;IACb;EACF;AACF","ignoreList":[]}
|
|
@@ -1,32 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { ClixDateFormatter } from "../utils/ClixDateFormatter.js";
|
|
4
|
-
import { ClixLogger } from "../utils/logging/ClixLogger.js";
|
|
5
4
|
export class EventService {
|
|
6
5
|
constructor(eventAPIService, deviceService) {
|
|
7
6
|
this.eventAPIService = eventAPIService;
|
|
8
7
|
this.deviceService = deviceService;
|
|
9
8
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Object.entries(properties).forEach(([key, value]) => {
|
|
17
|
-
if (value instanceof Date) {
|
|
18
|
-
cleanProperties[key] = ClixDateFormatter.format(value);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
cleanProperties[key] = value;
|
|
22
|
-
});
|
|
9
|
+
serializeProperties(properties = {}) {
|
|
10
|
+
const cleanProperties = {};
|
|
11
|
+
Object.entries(properties).forEach(([key, value]) => {
|
|
12
|
+
if (value instanceof Date) {
|
|
13
|
+
cleanProperties[key] = ClixDateFormatter.format(value);
|
|
14
|
+
return;
|
|
23
15
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
cleanProperties[key] = value;
|
|
17
|
+
});
|
|
18
|
+
return cleanProperties;
|
|
19
|
+
}
|
|
20
|
+
async trackEvent(name, properties, messageId, userJourneyId, userJourneyNodeId) {
|
|
21
|
+
const deviceId = this.deviceService.getCurrentDeviceId();
|
|
22
|
+
await this.eventAPIService.trackEvent(deviceId, name, this.serializeProperties(properties), messageId, userJourneyId, userJourneyNodeId);
|
|
30
23
|
}
|
|
31
24
|
}
|
|
32
25
|
//# sourceMappingURL=EventService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ClixDateFormatter","
|
|
1
|
+
{"version":3,"names":["ClixDateFormatter","EventService","constructor","eventAPIService","deviceService","serializeProperties","properties","cleanProperties","Object","entries","forEach","key","value","Date","format","trackEvent","name","messageId","userJourneyId","userJourneyNodeId","deviceId","getCurrentDeviceId"],"sourceRoot":"../../../src","sources":["services/EventService.ts"],"mappings":";;AAAA,SAASA,iBAAiB,QAAQ,+BAA4B;AAI9D,OAAO,MAAMC,YAAY,CAAC;EACxBC,WAAWA,CACQC,eAAgC,EAChCC,aAA4B,EAC7C;IAAA,KAFiBD,eAAgC,GAAhCA,eAAgC;IAAA,KAChCC,aAA4B,GAA5BA,aAA4B;EAC5C;EAEKC,mBAAmBA,CACzBC,UAA+B,GAAG,CAAC,CAAC,EACf;IACrB,MAAMC,eAAoC,GAAG,CAAC,CAAC;IAE/CC,MAAM,CAACC,OAAO,CAACH,UAAU,CAAC,CAACI,OAAO,CAAC,CAAC,CAACC,GAAG,EAAEC,KAAK,CAAC,KAAK;MACnD,IAAIA,KAAK,YAAYC,IAAI,EAAE;QACzBN,eAAe,CAACI,GAAG,CAAC,GAAGX,iBAAiB,CAACc,MAAM,CAACF,KAAK,CAAC;QACtD;MACF;MAEAL,eAAe,CAACI,GAAG,CAAC,GAAGC,KAAK;IAC9B,CAAC,CAAC;IAEF,OAAOL,eAAe;EACxB;EAEA,MAAMQ,UAAUA,CACdC,IAAY,EACZV,UAAgC,EAChCW,SAAkB,EAClBC,aAAsB,EACtBC,iBAA0B,EACX;IACf,MAAMC,QAAQ,GAAG,IAAI,CAAChB,aAAa,CAACiB,kBAAkB,CAAC,CAAC;IAExD,MAAM,IAAI,CAAClB,eAAe,CAACY,UAAU,CACnCK,QAAQ,EACRJ,IAAI,EACJ,IAAI,CAACX,mBAAmB,CAACC,UAAU,CAAC,EACpCW,SAAS,EACTC,aAAa,EACbC,iBACF,CAAC;EACH;AACF","ignoreList":[]}
|