@clix-so/react-native-sdk 1.0.0 → 1.1.1-beta.1
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 +253 -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 +109 -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 +321 -534
- package/src/services/TokenService.ts +4 -71
- package/src/utils/http/HTTPClient.ts +154 -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,23 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { ClixVersion } from "../core/ClixVersion.js";
|
|
4
|
+
import { HTTPClient } from "../utils/http/HTTPClient.js";
|
|
4
5
|
import { ClixLogger } from "../utils/logging/ClixLogger.js";
|
|
5
6
|
export class ClixAPIClient {
|
|
6
|
-
static API_BASE_PATH = '/api/v1';
|
|
7
7
|
constructor(config) {
|
|
8
8
|
this.config = config;
|
|
9
9
|
}
|
|
10
|
+
static API_BASE_PATH = '/api/v1';
|
|
10
11
|
async getCommonHeaders() {
|
|
11
12
|
const version = await ClixVersion.getVersion();
|
|
12
13
|
const headers = {
|
|
13
14
|
'Content-Type': 'application/json',
|
|
14
15
|
'X-Clix-Project-ID': this.config.projectId,
|
|
15
16
|
'X-Clix-API-Key': this.config.apiKey,
|
|
16
|
-
'User-Agent': `clix-react-native-sdk
|
|
17
|
+
'User-Agent': `clix-react-native-sdk@${version}`,
|
|
18
|
+
...this.config.extraHeaders
|
|
17
19
|
};
|
|
18
|
-
if (this.config.extraHeaders) {
|
|
19
|
-
Object.assign(headers, this.config.extraHeaders);
|
|
20
|
-
}
|
|
21
20
|
return headers;
|
|
22
21
|
}
|
|
23
22
|
buildUrl(path) {
|
|
@@ -26,147 +25,99 @@ export class ClixAPIClient {
|
|
|
26
25
|
const fullPath = path.startsWith('/') ? path : `/${path}`;
|
|
27
26
|
return `${baseUrl}${ClixAPIClient.API_BASE_PATH}${fullPath}`;
|
|
28
27
|
}
|
|
29
|
-
|
|
28
|
+
async get(path, params, headers) {
|
|
30
29
|
const url = this.buildUrl(path);
|
|
31
|
-
if (queryParameters && Object.keys(queryParameters).length > 0) {
|
|
32
|
-
const searchParams = new URLSearchParams();
|
|
33
|
-
Object.entries(queryParameters).forEach(([key, value]) => {
|
|
34
|
-
if (value !== null && value !== undefined) {
|
|
35
|
-
searchParams.append(key, String(value));
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
return `${url}?${searchParams.toString()}`;
|
|
39
|
-
}
|
|
40
|
-
return url;
|
|
41
|
-
}
|
|
42
|
-
async get(path, options) {
|
|
43
|
-
const url = this.buildUrlWithQuery(path, options?.queryParameters);
|
|
44
30
|
const commonHeaders = await this.getCommonHeaders();
|
|
45
31
|
const requestHeaders = {
|
|
46
32
|
...commonHeaders,
|
|
47
|
-
...
|
|
33
|
+
...headers
|
|
48
34
|
};
|
|
49
35
|
ClixLogger.debug(`API GET ${path}`);
|
|
50
36
|
ClixLogger.debug(`Making request to: ${url}`);
|
|
37
|
+
if (params && Object.keys(params).length > 0) {
|
|
38
|
+
ClixLogger.debug(`Query Parameters: ${JSON.stringify(params)}`);
|
|
39
|
+
}
|
|
51
40
|
try {
|
|
52
|
-
const response = await
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const data = await this.parseResponse(response);
|
|
57
|
-
ClixLogger.debug(`Response Status: ${response.status}`);
|
|
58
|
-
ClixLogger.debug(`Response Body: ${JSON.stringify(data)}`);
|
|
59
|
-
return {
|
|
60
|
-
status: response.status,
|
|
61
|
-
data,
|
|
62
|
-
headers: this.headersToRecord(response.headers)
|
|
63
|
-
};
|
|
41
|
+
const response = await HTTPClient.shared.get(url, params, requestHeaders);
|
|
42
|
+
ClixLogger.debug(`Response Status: ${response.statusCode}`);
|
|
43
|
+
ClixLogger.debug(`Response Body: ${JSON.stringify(response.data)}`);
|
|
44
|
+
return response;
|
|
64
45
|
} catch (error) {
|
|
65
46
|
ClixLogger.error(`GET ${path} failed`, error);
|
|
66
47
|
throw error;
|
|
67
48
|
}
|
|
68
49
|
}
|
|
69
|
-
async post(path,
|
|
70
|
-
const url = this.
|
|
50
|
+
async post(path, data, params, headers) {
|
|
51
|
+
const url = this.buildUrl(path);
|
|
71
52
|
const commonHeaders = await this.getCommonHeaders();
|
|
72
53
|
const requestHeaders = {
|
|
73
54
|
...commonHeaders,
|
|
74
|
-
...
|
|
55
|
+
...headers
|
|
75
56
|
};
|
|
76
57
|
ClixLogger.debug(`API POST ${path}`);
|
|
77
|
-
|
|
78
|
-
|
|
58
|
+
ClixLogger.debug(`Making request to: ${url}`);
|
|
59
|
+
if (data) {
|
|
60
|
+
ClixLogger.debug(`Request Body: ${JSON.stringify(data)}`);
|
|
79
61
|
}
|
|
80
|
-
if (
|
|
81
|
-
ClixLogger.debug(`Query Parameters: ${JSON.stringify(
|
|
62
|
+
if (params && Object.keys(params).length > 0) {
|
|
63
|
+
ClixLogger.debug(`Query Parameters: ${JSON.stringify(params)}`);
|
|
82
64
|
}
|
|
83
|
-
const body = options?.body ? JSON.stringify(options.body) : undefined;
|
|
84
65
|
try {
|
|
85
|
-
const response = await
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
});
|
|
90
|
-
const data = await this.parseResponse(response);
|
|
91
|
-
ClixLogger.debug(`Response Status: ${response.status}`);
|
|
92
|
-
ClixLogger.debug(`Response Body: ${JSON.stringify(data)}`);
|
|
93
|
-
return {
|
|
94
|
-
status: response.status,
|
|
95
|
-
data,
|
|
96
|
-
headers: this.headersToRecord(response.headers)
|
|
97
|
-
};
|
|
66
|
+
const response = await HTTPClient.shared.post(url, data, params, requestHeaders);
|
|
67
|
+
ClixLogger.debug(`Response Status: ${response.statusCode}`);
|
|
68
|
+
ClixLogger.debug(`Response Body: ${JSON.stringify(response.data)}`);
|
|
69
|
+
return response;
|
|
98
70
|
} catch (error) {
|
|
99
71
|
ClixLogger.error(`POST ${path} failed`, error);
|
|
100
72
|
throw error;
|
|
101
73
|
}
|
|
102
74
|
}
|
|
103
|
-
async put(path,
|
|
104
|
-
const url = this.
|
|
75
|
+
async put(path, data, params, headers) {
|
|
76
|
+
const url = this.buildUrl(path);
|
|
105
77
|
const commonHeaders = await this.getCommonHeaders();
|
|
106
78
|
const requestHeaders = {
|
|
107
79
|
...commonHeaders,
|
|
108
|
-
...
|
|
80
|
+
...headers
|
|
109
81
|
};
|
|
110
82
|
ClixLogger.debug(`API PUT ${path}`);
|
|
111
|
-
|
|
83
|
+
ClixLogger.debug(`Making request to: ${url}`);
|
|
84
|
+
if (data) {
|
|
85
|
+
ClixLogger.debug(`Request Body: ${JSON.stringify(data)}`);
|
|
86
|
+
}
|
|
87
|
+
if (params && Object.keys(params).length > 0) {
|
|
88
|
+
ClixLogger.debug(`Query Parameters: ${JSON.stringify(params)}`);
|
|
89
|
+
}
|
|
112
90
|
try {
|
|
113
|
-
const response = await
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
});
|
|
118
|
-
const data = await this.parseResponse(response);
|
|
119
|
-
ClixLogger.debug(`Response Status: ${response.status}`);
|
|
120
|
-
ClixLogger.debug(`Response Body: ${JSON.stringify(data)}`);
|
|
121
|
-
return {
|
|
122
|
-
status: response.status,
|
|
123
|
-
data,
|
|
124
|
-
headers: this.headersToRecord(response.headers)
|
|
125
|
-
};
|
|
91
|
+
const response = await HTTPClient.shared.put(url, data, params, requestHeaders);
|
|
92
|
+
ClixLogger.debug(`Response Status: ${response.statusCode}`);
|
|
93
|
+
ClixLogger.debug(`Response Body: ${JSON.stringify(response.data)}`);
|
|
94
|
+
return response;
|
|
126
95
|
} catch (error) {
|
|
127
96
|
ClixLogger.error(`PUT ${path} failed`, error);
|
|
128
97
|
throw error;
|
|
129
98
|
}
|
|
130
99
|
}
|
|
131
|
-
async delete(path,
|
|
132
|
-
const url = this.
|
|
100
|
+
async delete(path, params, headers) {
|
|
101
|
+
const url = this.buildUrl(path);
|
|
133
102
|
const commonHeaders = await this.getCommonHeaders();
|
|
134
103
|
const requestHeaders = {
|
|
135
104
|
...commonHeaders,
|
|
136
|
-
...
|
|
105
|
+
...headers
|
|
137
106
|
};
|
|
138
107
|
ClixLogger.debug(`API DELETE ${path}`);
|
|
108
|
+
ClixLogger.debug(`Making request to: ${url}`);
|
|
109
|
+
if (params && Object.keys(params).length > 0) {
|
|
110
|
+
ClixLogger.debug(`Query Parameters: ${JSON.stringify(params)}`);
|
|
111
|
+
}
|
|
139
112
|
try {
|
|
140
|
-
const response = await
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const data = await this.parseResponse(response);
|
|
145
|
-
ClixLogger.debug(`Response Status: ${response.status}`);
|
|
146
|
-
ClixLogger.debug(`Response Body: ${JSON.stringify(data)}`);
|
|
147
|
-
return {
|
|
148
|
-
status: response.status,
|
|
149
|
-
data,
|
|
150
|
-
headers: this.headersToRecord(response.headers)
|
|
151
|
-
};
|
|
113
|
+
const response = await HTTPClient.shared.delete(url, params, requestHeaders);
|
|
114
|
+
ClixLogger.debug(`Response Status: ${response.statusCode}`);
|
|
115
|
+
ClixLogger.debug(`Response Body: ${JSON.stringify(response.data)}`);
|
|
116
|
+
return response;
|
|
152
117
|
} catch (error) {
|
|
153
118
|
ClixLogger.error(`DELETE ${path} failed`, error);
|
|
154
119
|
throw error;
|
|
155
120
|
}
|
|
156
121
|
}
|
|
157
|
-
async parseResponse(response) {
|
|
158
|
-
const contentType = response.headers.get('content-type');
|
|
159
|
-
if (contentType && contentType.includes('application/json')) {
|
|
160
|
-
return await response.json();
|
|
161
|
-
}
|
|
162
|
-
return await response.text();
|
|
163
|
-
}
|
|
164
|
-
headersToRecord(headers) {
|
|
165
|
-
const record = {};
|
|
166
|
-
headers.forEach((value, key) => {
|
|
167
|
-
record[key] = value;
|
|
168
|
-
});
|
|
169
|
-
return record;
|
|
170
|
-
}
|
|
171
122
|
}
|
|
172
123
|
//# sourceMappingURL=ClixAPIClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ClixVersion","
|
|
1
|
+
{"version":3,"names":["ClixVersion","HTTPClient","ClixLogger","ClixAPIClient","constructor","config","API_BASE_PATH","getCommonHeaders","version","getVersion","headers","projectId","apiKey","extraHeaders","buildUrl","path","endpoint","baseUrl","endsWith","slice","fullPath","startsWith","get","params","url","commonHeaders","requestHeaders","debug","Object","keys","length","JSON","stringify","response","shared","statusCode","data","error","post","put","delete"],"sourceRoot":"../../../src","sources":["services/ClixAPIClient.ts"],"mappings":";;AACA,SAASA,WAAW,QAAQ,wBAAqB;AACjD,SAASC,UAAU,QAAQ,6BAA0B;AAErD,SAASC,UAAU,QAAQ,gCAA6B;AAQxD,OAAO,MAAMC,aAAa,CAAC;EACzBC,WAAWA,CAAkBC,MAAkB,EAAE;IAAA,KAApBA,MAAkB,GAAlBA,MAAkB;EAAG;EAElD,OAAwBC,aAAa,GAAG,SAAS;EAEjD,MAAcC,gBAAgBA,CAAA,EAAoC;IAChE,MAAMC,OAAO,GAAG,MAAMR,WAAW,CAACS,UAAU,CAAC,CAAC;IAC9C,MAAMC,OAA+B,GAAG;MACtC,cAAc,EAAE,kBAAkB;MAClC,mBAAmB,EAAE,IAAI,CAACL,MAAM,CAACM,SAAS;MAC1C,gBAAgB,EAAE,IAAI,CAACN,MAAM,CAACO,MAAM;MACpC,YAAY,EAAE,yBAAyBJ,OAAO,EAAE;MAChD,GAAG,IAAI,CAACH,MAAM,CAACQ;IACjB,CAAC;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reList":[]}
|
|
@@ -5,34 +5,32 @@ export class DeviceAPIService {
|
|
|
5
5
|
constructor(apiClient) {
|
|
6
6
|
this.apiClient = apiClient;
|
|
7
7
|
}
|
|
8
|
-
async
|
|
8
|
+
async upsertDevice(device) {
|
|
9
9
|
try {
|
|
10
10
|
ClixLogger.debug(`Upserting device: ${device.id}`);
|
|
11
11
|
const response = await this.apiClient.post('/devices', {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}]
|
|
32
|
-
}
|
|
12
|
+
devices: [{
|
|
13
|
+
id: device.id,
|
|
14
|
+
platform: device.platform,
|
|
15
|
+
model: device.model,
|
|
16
|
+
manufacturer: device.manufacturer,
|
|
17
|
+
os_name: device.osName,
|
|
18
|
+
os_version: device.osVersion,
|
|
19
|
+
locale_region: device.localeRegion,
|
|
20
|
+
locale_language: device.localeLanguage,
|
|
21
|
+
timezone: device.timezone,
|
|
22
|
+
app_name: device.appName,
|
|
23
|
+
app_version: device.appVersion,
|
|
24
|
+
sdk_type: device.sdkType,
|
|
25
|
+
sdk_version: device.sdkVersion,
|
|
26
|
+
ad_id: device.adId,
|
|
27
|
+
is_push_permission_granted: device.isPushPermissionGranted,
|
|
28
|
+
push_token: device.pushToken,
|
|
29
|
+
push_token_type: device.pushTokenType
|
|
30
|
+
}]
|
|
33
31
|
});
|
|
34
|
-
if (response.
|
|
35
|
-
throw new Error(`HTTP ${response.
|
|
32
|
+
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
33
|
+
throw new Error(`HTTP ${response.statusCode}: ${JSON.stringify(response.data)}`);
|
|
36
34
|
}
|
|
37
35
|
ClixLogger.debug(`Device upserted successfully: ${device.id}`);
|
|
38
36
|
} catch (error) {
|
|
@@ -44,12 +42,10 @@ export class DeviceAPIService {
|
|
|
44
42
|
try {
|
|
45
43
|
ClixLogger.debug(`Setting project user ID for device: ${deviceId}`);
|
|
46
44
|
const response = await this.apiClient.post(`/devices/${deviceId}/user/project-user-id`, {
|
|
47
|
-
|
|
48
|
-
project_user_id: projectUserId
|
|
49
|
-
}
|
|
45
|
+
project_user_id: projectUserId
|
|
50
46
|
});
|
|
51
|
-
if (response.
|
|
52
|
-
throw new Error(`HTTP ${response.
|
|
47
|
+
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
48
|
+
throw new Error(`HTTP ${response.statusCode}: ${JSON.stringify(response.data)}`);
|
|
53
49
|
}
|
|
54
50
|
ClixLogger.debug(`Project user ID set successfully for device: ${deviceId}`);
|
|
55
51
|
} catch (error) {
|
|
@@ -61,8 +57,8 @@ export class DeviceAPIService {
|
|
|
61
57
|
try {
|
|
62
58
|
ClixLogger.debug(`Removing project user ID for device: ${deviceId}`);
|
|
63
59
|
const response = await this.apiClient.delete(`/devices/${deviceId}/user/project-user-id`);
|
|
64
|
-
if (response.
|
|
65
|
-
throw new Error(`HTTP ${response.
|
|
60
|
+
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
61
|
+
throw new Error(`HTTP ${response.statusCode}: ${JSON.stringify(response.data)}`);
|
|
66
62
|
}
|
|
67
63
|
ClixLogger.debug(`Project user ID removed successfully for device: ${deviceId}`);
|
|
68
64
|
} catch (error) {
|
|
@@ -74,16 +70,14 @@ export class DeviceAPIService {
|
|
|
74
70
|
try {
|
|
75
71
|
ClixLogger.debug(`Upserting ${properties.length} user properties for device: ${deviceId}`);
|
|
76
72
|
const response = await this.apiClient.post(`/devices/${deviceId}/user/properties`, {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}))
|
|
83
|
-
}
|
|
73
|
+
properties: properties.map(p => ({
|
|
74
|
+
name: p.name,
|
|
75
|
+
value_string: p.valueString,
|
|
76
|
+
type: p.type
|
|
77
|
+
}))
|
|
84
78
|
});
|
|
85
|
-
if (response.
|
|
86
|
-
throw new Error(`HTTP ${response.
|
|
79
|
+
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
80
|
+
throw new Error(`HTTP ${response.statusCode}: ${JSON.stringify(response.data)}`);
|
|
87
81
|
}
|
|
88
82
|
ClixLogger.debug(`User properties upserted successfully for device: ${deviceId}`);
|
|
89
83
|
} catch (error) {
|
|
@@ -95,12 +89,10 @@ export class DeviceAPIService {
|
|
|
95
89
|
try {
|
|
96
90
|
ClixLogger.debug(`Removing ${propertyNames.length} user properties for device: ${deviceId}`);
|
|
97
91
|
const response = await this.apiClient.delete(`/devices/${deviceId}/user/properties`, {
|
|
98
|
-
|
|
99
|
-
property_names: propertyNames.join(',')
|
|
100
|
-
}
|
|
92
|
+
property_names: propertyNames.join(',')
|
|
101
93
|
});
|
|
102
|
-
if (response.
|
|
103
|
-
throw new Error(`HTTP ${response.
|
|
94
|
+
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
95
|
+
throw new Error(`HTTP ${response.statusCode}: ${JSON.stringify(response.data)}`);
|
|
104
96
|
}
|
|
105
97
|
ClixLogger.debug(`User properties removed successfully for device: ${deviceId}`);
|
|
106
98
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ClixLogger","DeviceAPIService","constructor","apiClient","
|
|
1
|
+
{"version":3,"names":["ClixLogger","DeviceAPIService","constructor","apiClient","upsertDevice","device","debug","id","response","post","devices","platform","model","manufacturer","os_name","osName","os_version","osVersion","locale_region","localeRegion","locale_language","localeLanguage","timezone","app_name","appName","app_version","appVersion","sdk_type","sdkType","sdk_version","sdkVersion","ad_id","adId","is_push_permission_granted","isPushPermissionGranted","push_token","pushToken","push_token_type","pushTokenType","statusCode","Error","JSON","stringify","data","error","setProjectUserId","deviceId","projectUserId","project_user_id","removeProjectUserId","delete","upsertUserProperties","properties","length","map","p","name","value_string","valueString","type","removeUserProperties","propertyNames","property_names","join"],"sourceRoot":"../../../src","sources":["services/DeviceAPIService.ts"],"mappings":";;AAEA,SAASA,UAAU,QAAQ,gCAA6B;AAGxD,OAAO,MAAMC,gBAAgB,CAAC;EAC5BC,WAAWA,CAAkBC,SAAwB,EAAE;IAAA,KAA1BA,SAAwB,GAAxBA,SAAwB;EAAG;EAExD,MAAMC,YAAYA,CAACC,MAAkB,EAAiB;IACpD,IAAI;MACFL,UAAU,CAACM,KAAK,CAAC,qBAAqBD,MAAM,CAACE,EAAE,EAAE,CAAC;MAElD,MAAMC,QAAQ,GAAG,MAAM,IAAI,CAACL,SAAS,CAACM,IAAI,CAAC,UAAU,EAAE;QACrDC,OAAO,EAAE,CACP;UACEH,EAAE,EAAEF,MAAM,CAACE,EAAE;UACbI,QAAQ,EAAEN,MAAM,CAACM,QAAQ;UACzBC,KAAK,EAAEP,MAAM,CAACO,KAAK;UACnBC,YAAY,EAAER,MAAM,CAACQ,YAAY;UACjCC,OAAO,EAAET,MAAM,CAACU,MAAM;UACtBC,UAAU,EAAEX,MAAM,CAACY,SAAS;UAC5BC,aAAa,EAAEb,MAAM,CAACc,YAAY;UAClCC,eAAe,EAAEf,MAAM,CAACgB,cAAc;UACtCC,QAAQ,EAAEjB,MAAM,CAACiB,QAAQ;UACzBC,QAAQ,EAAElB,MAAM,CAACmB,OAAO;UACxBC,WAAW,EAAEpB,MAAM,CAACqB,UAAU;UAC9BC,QAAQ,EAAEtB,MAAM,CAACuB,OAAO;UACxBC,WAAW,EAAExB,MAAM,CAACyB,UAAU;UAC9BC,KAAK,EAAE1B,MAAM,CAAC2B,IAAI;UAClBC,0BAA0B,EAAE5B,MAAM,CAAC6B,uBAAuB;UAC1DC,UAAU,EAAE9B,MAAM,CAAC+B,SAAS;UAC5BC,eAAe,EAAEhC,MAAM,CAACiC;QAC1B,CAAC;MAEL,CAAC,CAAC;MAEF,IAAI9B,QAAQ,CAAC+B,UAAU,GAAG,GA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