@clix-so/react-native-sdk 0.0.2-beta.5 → 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.
Files changed (88) hide show
  1. package/lib/module/core/Clix.js +40 -95
  2. package/lib/module/core/Clix.js.map +1 -1
  3. package/lib/module/core/ClixInitCoordinator.js +3 -14
  4. package/lib/module/core/ClixInitCoordinator.js.map +1 -1
  5. package/lib/module/core/ClixNotification.js +25 -28
  6. package/lib/module/core/ClixNotification.js.map +1 -1
  7. package/lib/module/models/ClixDevice.js +0 -6
  8. package/lib/module/models/ClixDevice.js.map +1 -1
  9. package/lib/module/models/ClixPushNotificationPayload.js +0 -19
  10. package/lib/module/models/ClixPushNotificationPayload.js.map +1 -1
  11. package/lib/module/services/ClixAPIClient.js +50 -99
  12. package/lib/module/services/ClixAPIClient.js.map +1 -1
  13. package/lib/module/services/DeviceAPIService.js +37 -45
  14. package/lib/module/services/DeviceAPIService.js.map +1 -1
  15. package/lib/module/services/DeviceService.js +97 -116
  16. package/lib/module/services/DeviceService.js.map +1 -1
  17. package/lib/module/services/EventAPIService.js +3 -5
  18. package/lib/module/services/EventAPIService.js.map +1 -1
  19. package/lib/module/services/EventService.js +13 -20
  20. package/lib/module/services/EventService.js.map +1 -1
  21. package/lib/module/services/NotificationService.js +252 -402
  22. package/lib/module/services/NotificationService.js.map +1 -1
  23. package/lib/module/services/TokenService.js +3 -59
  24. package/lib/module/services/TokenService.js.map +1 -1
  25. package/lib/module/utils/http/HTTPClient.js +101 -0
  26. package/lib/module/utils/http/HTTPClient.js.map +1 -0
  27. package/lib/module/utils/http/HTTPMethod.js +10 -0
  28. package/lib/module/utils/http/HTTPMethod.js.map +1 -0
  29. package/lib/module/utils/http/HTTPRequest.js +4 -0
  30. package/lib/module/utils/http/HTTPRequest.js.map +1 -0
  31. package/lib/module/utils/http/HTTPResponse.js +2 -0
  32. package/lib/module/utils/http/HTTPResponse.js.map +1 -0
  33. package/lib/module/utils/types.js +2 -0
  34. package/lib/module/utils/types.js.map +1 -0
  35. package/lib/typescript/src/core/Clix.d.ts +13 -15
  36. package/lib/typescript/src/core/Clix.d.ts.map +1 -1
  37. package/lib/typescript/src/core/ClixConfig.d.ts +3 -3
  38. package/lib/typescript/src/core/ClixConfig.d.ts.map +1 -1
  39. package/lib/typescript/src/core/ClixInitCoordinator.d.ts +0 -3
  40. package/lib/typescript/src/core/ClixInitCoordinator.d.ts.map +1 -1
  41. package/lib/typescript/src/core/ClixNotification.d.ts +6 -5
  42. package/lib/typescript/src/core/ClixNotification.d.ts.map +1 -1
  43. package/lib/typescript/src/models/ClixDevice.d.ts +0 -2
  44. package/lib/typescript/src/models/ClixDevice.d.ts.map +1 -1
  45. package/lib/typescript/src/models/ClixPushNotificationPayload.d.ts +8 -21
  46. package/lib/typescript/src/models/ClixPushNotificationPayload.d.ts.map +1 -1
  47. package/lib/typescript/src/services/ClixAPIClient.d.ts +6 -22
  48. package/lib/typescript/src/services/ClixAPIClient.d.ts.map +1 -1
  49. package/lib/typescript/src/services/DeviceAPIService.d.ts +1 -1
  50. package/lib/typescript/src/services/DeviceAPIService.d.ts.map +1 -1
  51. package/lib/typescript/src/services/DeviceService.d.ts +10 -5
  52. package/lib/typescript/src/services/DeviceService.d.ts.map +1 -1
  53. package/lib/typescript/src/services/EventAPIService.d.ts.map +1 -1
  54. package/lib/typescript/src/services/EventService.d.ts +1 -0
  55. package/lib/typescript/src/services/EventService.d.ts.map +1 -1
  56. package/lib/typescript/src/services/NotificationService.d.ts +50 -57
  57. package/lib/typescript/src/services/NotificationService.d.ts.map +1 -1
  58. package/lib/typescript/src/services/TokenService.d.ts +1 -7
  59. package/lib/typescript/src/services/TokenService.d.ts.map +1 -1
  60. package/lib/typescript/src/utils/http/HTTPClient.d.ts +15 -0
  61. package/lib/typescript/src/utils/http/HTTPClient.d.ts.map +1 -0
  62. package/lib/typescript/src/utils/http/HTTPMethod.d.ts +7 -0
  63. package/lib/typescript/src/utils/http/HTTPMethod.d.ts.map +1 -0
  64. package/lib/typescript/src/utils/http/HTTPRequest.d.ts +9 -0
  65. package/lib/typescript/src/utils/http/HTTPRequest.d.ts.map +1 -0
  66. package/lib/typescript/src/utils/http/HTTPResponse.d.ts +6 -0
  67. package/lib/typescript/src/utils/http/HTTPResponse.d.ts.map +1 -0
  68. package/lib/typescript/src/utils/types.d.ts +5 -0
  69. package/lib/typescript/src/utils/types.d.ts.map +1 -0
  70. package/package.json +1 -1
  71. package/src/core/Clix.ts +62 -115
  72. package/src/core/ClixConfig.ts +3 -3
  73. package/src/core/ClixInitCoordinator.ts +5 -17
  74. package/src/core/ClixNotification.ts +36 -37
  75. package/src/models/ClixDevice.ts +17 -25
  76. package/src/models/ClixPushNotificationPayload.ts +8 -37
  77. package/src/services/ClixAPIClient.ts +84 -144
  78. package/src/services/DeviceAPIService.ts +39 -47
  79. package/src/services/DeviceService.ts +122 -156
  80. package/src/services/EventAPIService.ts +3 -5
  81. package/src/services/EventService.ts +26 -33
  82. package/src/services/NotificationService.ts +318 -533
  83. package/src/services/TokenService.ts +4 -71
  84. package/src/utils/http/HTTPClient.ts +141 -0
  85. package/src/utils/http/HTTPMethod.ts +6 -0
  86. package/src/utils/http/HTTPRequest.ts +9 -0
  87. package/src/utils/http/HTTPResponse.ts +5 -0
  88. package/src/utils/types.ts +7 -0
@@ -1,9 +1,10 @@
1
1
  import { type NotificationSettings } from '@notifee/react-native';
2
2
  import type {
3
3
  BackgroundMessageHandler,
4
- FcmTokenErrorHandler,
5
- ForegroundMessageHandler,
6
- NotificationOpenedHandler,
4
+ ForegroundEventHandler,
5
+ MessageHandler,
6
+ NotificationOpenedAppHandler,
7
+ TokenRefreshHandler,
7
8
  } from '../services/NotificationService';
8
9
  import { ClixLogger } from '../utils/logging/ClixLogger';
9
10
  import { Clix } from './Clix';
@@ -34,7 +35,7 @@ export class ClixNotification {
34
35
  return;
35
36
  }
36
37
 
37
- notificationService.setAutoHandleLandingUrl(autoHandleLandingURL);
38
+ notificationService.autoHandleLandingUrl = autoHandleLandingURL;
38
39
 
39
40
  if (autoRequestPermission) {
40
41
  await notificationService.requestPermission();
@@ -44,32 +45,22 @@ export class ClixNotification {
44
45
  }
45
46
  }
46
47
 
47
- async requestPermission(): Promise<NotificationSettings | null> {
48
+ async requestPermission(): Promise<NotificationSettings | undefined> {
48
49
  try {
49
50
  await Clix.initCoordinator.waitForInitialization();
50
- const notificationService = Clix.shared?.notificationService;
51
- if (!notificationService) {
52
- ClixLogger.warn('Notification service is not initialized');
53
- return null;
54
- }
55
-
56
- return await notificationService.requestPermission();
51
+ return await Clix.shared?.notificationService?.requestPermission();
57
52
  } catch (error) {
58
53
  ClixLogger.error('Failed to request notification permission', error);
59
- return null;
54
+ return undefined;
60
55
  }
61
56
  }
62
57
 
63
58
  async setPermissionGranted(isGranted: boolean): Promise<void> {
64
59
  try {
65
60
  await Clix.initCoordinator.waitForInitialization();
66
- const notificationService = Clix.shared?.notificationService;
67
- if (!notificationService) {
68
- ClixLogger.warn('Notification service is not initialized');
69
- return;
70
- }
71
-
72
- await notificationService.setPermissionGranted(isGranted);
61
+ return await Clix.shared?.notificationService?.setPermissionGranted(
62
+ isGranted
63
+ );
73
64
  } catch (error) {
74
65
  ClixLogger.error(
75
66
  'Failed to update push permission status on server',
@@ -81,21 +72,14 @@ export class ClixNotification {
81
72
  async getToken(): Promise<string | undefined> {
82
73
  try {
83
74
  await Clix.initCoordinator.waitForInitialization();
84
- const notificationService = Clix.shared?.notificationService;
85
- if (!notificationService) {
86
- ClixLogger.warn('Notification service is not initialized');
87
- return undefined;
88
- }
89
-
90
- const token = await notificationService.getCurrentToken();
91
- return token ?? undefined;
75
+ return Clix.shared?.tokenService?.getCurrentToken();
92
76
  } catch (error) {
93
77
  ClixLogger.error('Failed to get push token', error);
94
78
  return undefined;
95
79
  }
96
80
  }
97
81
 
98
- async onMessage(handler?: ForegroundMessageHandler): Promise<void> {
82
+ async onMessage(handler?: MessageHandler): Promise<void> {
99
83
  try {
100
84
  await Clix.initCoordinator.waitForInitialization();
101
85
  const notificationService = Clix.shared?.notificationService;
@@ -103,7 +87,7 @@ export class ClixNotification {
103
87
  ClixLogger.warn('Notification service is not initialized');
104
88
  return;
105
89
  }
106
- notificationService.setMessageHandler(handler);
90
+ notificationService.messageHandler = handler;
107
91
  } catch (error) {
108
92
  ClixLogger.error('Failed to register onMessage handler', error);
109
93
  }
@@ -117,14 +101,14 @@ export class ClixNotification {
117
101
  ClixLogger.warn('Notification service is not initialized');
118
102
  return;
119
103
  }
120
- notificationService.setBackgroundMessageHandler(handler);
104
+ notificationService.backgroundMessageHandler = handler;
121
105
  } catch (error) {
122
106
  ClixLogger.error('Failed to register onBackgroundMessage handler', error);
123
107
  }
124
108
  }
125
109
 
126
- async onNotificationOpened(
127
- handler?: NotificationOpenedHandler
110
+ async onNotificationOpenedApp(
111
+ handler?: NotificationOpenedAppHandler
128
112
  ): Promise<void> {
129
113
  try {
130
114
  await Clix.initCoordinator.waitForInitialization();
@@ -133,7 +117,7 @@ export class ClixNotification {
133
117
  ClixLogger.warn('Notification service is not initialized');
134
118
  return;
135
119
  }
136
- notificationService.setNotificationOpenedHandler(handler);
120
+ notificationService.notificationOpenedAppHandler = handler;
137
121
  } catch (error) {
138
122
  ClixLogger.error(
139
123
  'Failed to register onNotificationOpened handler',
@@ -141,7 +125,22 @@ export class ClixNotification {
141
125
  );
142
126
  }
143
127
  }
144
- async onFcmTokenError(handler?: FcmTokenErrorHandler): Promise<void> {
128
+
129
+ async onTokenRefresh(handler?: TokenRefreshHandler): Promise<void> {
130
+ try {
131
+ await Clix.initCoordinator.waitForInitialization();
132
+ const notificationService = Clix.shared?.notificationService;
133
+ if (!notificationService) {
134
+ ClixLogger.warn('Notification service is not initialized');
135
+ return;
136
+ }
137
+ notificationService.tokenRefreshHandler = handler;
138
+ } catch (error) {
139
+ ClixLogger.error('Failed to register onTokenRefresh handler', error);
140
+ }
141
+ }
142
+
143
+ async onForegroundEvent(handler?: ForegroundEventHandler): Promise<void> {
145
144
  try {
146
145
  await Clix.initCoordinator.waitForInitialization();
147
146
  const notificationService = Clix.shared?.notificationService;
@@ -149,9 +148,9 @@ export class ClixNotification {
149
148
  ClixLogger.warn('Notification service is not initialized');
150
149
  return;
151
150
  }
152
- notificationService.setFcmTokenErrorHandler(handler);
151
+ notificationService.foregroundEventHandler = handler;
153
152
  } catch (error) {
154
- ClixLogger.error('Failed to register onFcmTokenError handler', error);
153
+ ClixLogger.error('Failed to register onForegroundEvent handler', error);
155
154
  }
156
155
  }
157
156
  }
@@ -1,21 +1,21 @@
1
1
  export class ClixDevice {
2
- public readonly id: string;
3
- public readonly platform: string;
4
- public readonly model: string;
5
- public readonly manufacturer: string;
6
- public readonly osName: string;
7
- public readonly osVersion: string;
8
- public readonly localeRegion: string;
9
- public readonly localeLanguage: string;
10
- public readonly timezone: string;
11
- public readonly appName: string;
12
- public readonly appVersion: string;
13
- public readonly sdkType: string;
14
- public readonly sdkVersion: string;
15
- public readonly adId?: string;
16
- public readonly isPushPermissionGranted: boolean;
17
- public readonly pushToken?: string;
18
- public readonly pushTokenType?: string;
2
+ readonly id: string;
3
+ readonly platform: string;
4
+ readonly model: string;
5
+ readonly manufacturer: string;
6
+ readonly osName: string;
7
+ readonly osVersion: string;
8
+ readonly localeRegion: string;
9
+ readonly localeLanguage: string;
10
+ readonly timezone: string;
11
+ readonly appName: string;
12
+ readonly appVersion: string;
13
+ readonly sdkType: string;
14
+ readonly sdkVersion: string;
15
+ readonly adId?: string;
16
+ readonly isPushPermissionGranted: boolean;
17
+ readonly pushToken?: string;
18
+ readonly pushTokenType?: string;
19
19
 
20
20
  constructor(device: {
21
21
  id: string;
@@ -77,12 +77,4 @@ export class ClixDevice {
77
77
  pushTokenType: updates.pushTokenType ?? this.pushTokenType,
78
78
  });
79
79
  }
80
-
81
- equals(other: ClixDevice): boolean {
82
- return this.id === other.id;
83
- }
84
-
85
- toString(): string {
86
- return `ClixDevice(id: ${this.id}, platform: ${this.platform}, model: ${this.model})`;
87
- }
88
80
  }
@@ -1,38 +1,9 @@
1
- export class ClixPushNotificationPayload {
2
- public readonly messageId: string;
3
- public readonly campaignId?: string;
4
- public readonly userId?: string;
5
- public readonly deviceId?: string;
6
- public readonly trackingId?: string;
7
- public readonly landingUrl?: string;
8
- public readonly imageUrl?: string;
9
- public readonly customProperties?: Record<string, any>;
10
-
11
- constructor(payload: {
12
- messageId: string;
13
- campaignId?: string;
14
- userId?: string;
15
- deviceId?: string;
16
- trackingId?: string;
17
- landingUrl?: string;
18
- imageUrl?: string;
19
- customProperties?: Record<string, any>;
20
- }) {
21
- this.messageId = payload.messageId;
22
- this.campaignId = payload.campaignId;
23
- this.userId = payload.userId;
24
- this.deviceId = payload.deviceId;
25
- this.trackingId = payload.trackingId;
26
- this.landingUrl = payload.landingUrl;
27
- this.imageUrl = payload.imageUrl;
28
- this.customProperties = payload.customProperties;
29
- }
30
-
31
- equals(other: ClixPushNotificationPayload): boolean {
32
- return this.messageId === other.messageId;
33
- }
34
-
35
- toString(): string {
36
- return `ClixPushNotificationPayload(messageId: ${this.messageId}, campaignId: ${this.campaignId})`;
37
- }
1
+ export interface ClixPushNotificationPayload {
2
+ messageId: string;
3
+ title: string;
4
+ body: string;
5
+ imageUrl?: string;
6
+ landingUrl?: string;
7
+ userJourneyId?: string;
8
+ userJourneyNodeId?: string;
38
9
  }
@@ -1,5 +1,7 @@
1
1
  import type { ClixConfig } from '../core/ClixConfig';
2
2
  import { ClixVersion } from '../core/ClixVersion';
3
+ import { HTTPClient } from '../utils/http/HTTPClient';
4
+ import type { HTTPResponse } from '../utils/http/HTTPResponse';
3
5
  import { ClixLogger } from '../utils/logging/ClixLogger';
4
6
 
5
7
  export interface APIResponse {
@@ -9,23 +11,20 @@ export interface APIResponse {
9
11
  }
10
12
 
11
13
  export class ClixAPIClient {
12
- private static readonly API_BASE_PATH = '/api/v1';
13
-
14
14
  constructor(private readonly config: ClixConfig) {}
15
15
 
16
+ private static readonly API_BASE_PATH = '/api/v1';
17
+
16
18
  private async getCommonHeaders(): Promise<Record<string, string>> {
17
19
  const version = await ClixVersion.getVersion();
18
20
  const headers: Record<string, string> = {
19
21
  'Content-Type': 'application/json',
20
22
  'X-Clix-Project-ID': this.config.projectId,
21
23
  'X-Clix-API-Key': this.config.apiKey,
22
- 'User-Agent': `clix-react-native-sdk/${version}`,
24
+ 'User-Agent': `clix-react-native-sdk@${version}`,
25
+ ...this.config.extraHeaders,
23
26
  };
24
27
 
25
- if (this.config.extraHeaders) {
26
- Object.assign(headers, this.config.extraHeaders);
27
- }
28
-
29
28
  return headers;
30
29
  }
31
30
 
@@ -37,212 +36,153 @@ export class ClixAPIClient {
37
36
  return `${baseUrl}${ClixAPIClient.API_BASE_PATH}${fullPath}`;
38
37
  }
39
38
 
40
- private buildUrlWithQuery(
39
+ async get<T>(
41
40
  path: string,
42
- queryParameters?: Record<string, any>
43
- ): string {
41
+ params?: Record<string, any>,
42
+ headers?: Record<string, string>
43
+ ): Promise<HTTPResponse<T>> {
44
44
  const url = this.buildUrl(path);
45
-
46
- if (queryParameters && Object.keys(queryParameters).length > 0) {
47
- const searchParams = new URLSearchParams();
48
- Object.entries(queryParameters).forEach(([key, value]) => {
49
- if (value !== null && value !== undefined) {
50
- searchParams.append(key, String(value));
51
- }
52
- });
53
- return `${url}?${searchParams.toString()}`;
54
- }
55
-
56
- return url;
57
- }
58
-
59
- async get(
60
- path: string,
61
- options?: {
62
- headers?: Record<string, string>;
63
- queryParameters?: Record<string, any>;
64
- }
65
- ): Promise<APIResponse> {
66
- const url = this.buildUrlWithQuery(path, options?.queryParameters);
67
45
  const commonHeaders = await this.getCommonHeaders();
68
46
  const requestHeaders = {
69
47
  ...commonHeaders,
70
- ...options?.headers,
48
+ ...headers,
71
49
  };
72
50
 
73
51
  ClixLogger.debug(`API GET ${path}`);
74
52
  ClixLogger.debug(`Making request to: ${url}`);
53
+ if (params && Object.keys(params).length > 0) {
54
+ ClixLogger.debug(`Query Parameters: ${JSON.stringify(params)}`);
55
+ }
75
56
 
76
57
  try {
77
- const response = await fetch(url, {
78
- method: 'GET',
79
- headers: requestHeaders,
80
- });
81
-
82
- const data = await this.parseResponse(response);
58
+ const response = await HTTPClient.shared.get<T>(
59
+ url,
60
+ params,
61
+ requestHeaders
62
+ );
83
63
 
84
- ClixLogger.debug(`Response Status: ${response.status}`);
85
- ClixLogger.debug(`Response Body: ${JSON.stringify(data)}`);
64
+ ClixLogger.debug(`Response Status: ${response.statusCode}`);
65
+ ClixLogger.debug(`Response Body: ${JSON.stringify(response.data)}`);
86
66
 
87
- return {
88
- status: response.status,
89
- data,
90
- headers: this.headersToRecord(response.headers),
91
- };
67
+ return response;
92
68
  } catch (error) {
93
69
  ClixLogger.error(`GET ${path} failed`, error);
94
70
  throw error;
95
71
  }
96
72
  }
97
73
 
98
- async post(
74
+ async post<T>(
99
75
  path: string,
100
- options?: {
101
- headers?: Record<string, string>;
102
- queryParameters?: Record<string, any>;
103
- body?: any;
104
- }
105
- ): Promise<APIResponse> {
106
- const url = this.buildUrlWithQuery(path, options?.queryParameters);
76
+ data?: any,
77
+ params?: Record<string, any>,
78
+ headers?: Record<string, string>
79
+ ): Promise<HTTPResponse<T>> {
80
+ const url = this.buildUrl(path);
107
81
  const commonHeaders = await this.getCommonHeaders();
108
82
  const requestHeaders = {
109
83
  ...commonHeaders,
110
- ...options?.headers,
84
+ ...headers,
111
85
  };
112
86
 
113
87
  ClixLogger.debug(`API POST ${path}`);
114
- if (options?.body) {
115
- ClixLogger.debug(`Request Body: ${JSON.stringify(options.body)}`);
88
+ ClixLogger.debug(`Making request to: ${url}`);
89
+ if (data) {
90
+ ClixLogger.debug(`Request Body: ${JSON.stringify(data)}`);
116
91
  }
117
- if (
118
- options?.queryParameters &&
119
- Object.keys(options.queryParameters).length > 0
120
- ) {
121
- ClixLogger.debug(
122
- `Query Parameters: ${JSON.stringify(options.queryParameters)}`
123
- );
92
+ if (params && Object.keys(params).length > 0) {
93
+ ClixLogger.debug(`Query Parameters: ${JSON.stringify(params)}`);
124
94
  }
125
95
 
126
- const body = options?.body ? JSON.stringify(options.body) : undefined;
127
-
128
96
  try {
129
- const response = await fetch(url, {
130
- method: 'POST',
131
- headers: requestHeaders,
132
- body,
133
- });
134
-
135
- const data = await this.parseResponse(response);
97
+ const response = await HTTPClient.shared.post<T>(
98
+ url,
99
+ data,
100
+ params,
101
+ requestHeaders
102
+ );
136
103
 
137
- ClixLogger.debug(`Response Status: ${response.status}`);
138
- ClixLogger.debug(`Response Body: ${JSON.stringify(data)}`);
104
+ ClixLogger.debug(`Response Status: ${response.statusCode}`);
105
+ ClixLogger.debug(`Response Body: ${JSON.stringify(response.data)}`);
139
106
 
140
- return {
141
- status: response.status,
142
- data,
143
- headers: this.headersToRecord(response.headers),
144
- };
107
+ return response;
145
108
  } catch (error) {
146
109
  ClixLogger.error(`POST ${path} failed`, error);
147
110
  throw error;
148
111
  }
149
112
  }
150
113
 
151
- async put(
114
+ async put<T>(
152
115
  path: string,
153
- options?: {
154
- headers?: Record<string, string>;
155
- queryParameters?: Record<string, any>;
156
- body?: any;
157
- }
158
- ): Promise<APIResponse> {
159
- const url = this.buildUrlWithQuery(path, options?.queryParameters);
116
+ data?: any,
117
+ params?: Record<string, any>,
118
+ headers?: Record<string, string>
119
+ ): Promise<HTTPResponse<T>> {
120
+ const url = this.buildUrl(path);
160
121
  const commonHeaders = await this.getCommonHeaders();
161
122
  const requestHeaders = {
162
123
  ...commonHeaders,
163
- ...options?.headers,
124
+ ...headers,
164
125
  };
165
126
 
166
127
  ClixLogger.debug(`API PUT ${path}`);
167
-
168
- const body = options?.body ? JSON.stringify(options.body) : undefined;
128
+ ClixLogger.debug(`Making request to: ${url}`);
129
+ if (data) {
130
+ ClixLogger.debug(`Request Body: ${JSON.stringify(data)}`);
131
+ }
132
+ if (params && Object.keys(params).length > 0) {
133
+ ClixLogger.debug(`Query Parameters: ${JSON.stringify(params)}`);
134
+ }
169
135
 
170
136
  try {
171
- const response = await fetch(url, {
172
- method: 'PUT',
173
- headers: requestHeaders,
174
- body,
175
- });
176
-
177
- const data = await this.parseResponse(response);
137
+ const response = await HTTPClient.shared.put<T>(
138
+ url,
139
+ data,
140
+ params,
141
+ requestHeaders
142
+ );
178
143
 
179
- ClixLogger.debug(`Response Status: ${response.status}`);
180
- ClixLogger.debug(`Response Body: ${JSON.stringify(data)}`);
144
+ ClixLogger.debug(`Response Status: ${response.statusCode}`);
145
+ ClixLogger.debug(`Response Body: ${JSON.stringify(response.data)}`);
181
146
 
182
- return {
183
- status: response.status,
184
- data,
185
- headers: this.headersToRecord(response.headers),
186
- };
147
+ return response;
187
148
  } catch (error) {
188
149
  ClixLogger.error(`PUT ${path} failed`, error);
189
150
  throw error;
190
151
  }
191
152
  }
192
153
 
193
- async delete(
154
+ async delete<T>(
194
155
  path: string,
195
- options?: {
196
- headers?: Record<string, string>;
197
- queryParameters?: Record<string, any>;
198
- }
199
- ): Promise<APIResponse> {
200
- const url = this.buildUrlWithQuery(path, options?.queryParameters);
156
+ params?: Record<string, any>,
157
+ headers?: Record<string, string>
158
+ ): Promise<HTTPResponse<T>> {
159
+ const url = this.buildUrl(path);
201
160
  const commonHeaders = await this.getCommonHeaders();
202
161
  const requestHeaders = {
203
162
  ...commonHeaders,
204
- ...options?.headers,
163
+ ...headers,
205
164
  };
206
165
 
207
166
  ClixLogger.debug(`API DELETE ${path}`);
167
+ ClixLogger.debug(`Making request to: ${url}`);
168
+ if (params && Object.keys(params).length > 0) {
169
+ ClixLogger.debug(`Query Parameters: ${JSON.stringify(params)}`);
170
+ }
208
171
 
209
172
  try {
210
- const response = await fetch(url, {
211
- method: 'DELETE',
212
- headers: requestHeaders,
213
- });
214
-
215
- const data = await this.parseResponse(response);
173
+ const response = await HTTPClient.shared.delete<T>(
174
+ url,
175
+ params,
176
+ requestHeaders
177
+ );
216
178
 
217
- ClixLogger.debug(`Response Status: ${response.status}`);
218
- ClixLogger.debug(`Response Body: ${JSON.stringify(data)}`);
179
+ ClixLogger.debug(`Response Status: ${response.statusCode}`);
180
+ ClixLogger.debug(`Response Body: ${JSON.stringify(response.data)}`);
219
181
 
220
- return {
221
- status: response.status,
222
- data,
223
- headers: this.headersToRecord(response.headers),
224
- };
182
+ return response;
225
183
  } catch (error) {
226
184
  ClixLogger.error(`DELETE ${path} failed`, error);
227
185
  throw error;
228
186
  }
229
187
  }
230
-
231
- private async parseResponse(response: Response): Promise<any> {
232
- const contentType = response.headers.get('content-type');
233
-
234
- if (contentType && contentType.includes('application/json')) {
235
- return await response.json();
236
- }
237
-
238
- return await response.text();
239
- }
240
-
241
- private headersToRecord(headers: Headers): Record<string, string> {
242
- const record: Record<string, string> = {};
243
- headers.forEach((value: any, key: string) => {
244
- record[key] = value;
245
- });
246
- return record;
247
- }
248
188
  }