@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,21 +1,26 @@
|
|
|
1
1
|
import { ClixDevice } from '../models/ClixDevice';
|
|
2
2
|
import { DeviceAPIService } from './DeviceAPIService';
|
|
3
3
|
import { StorageService } from './StorageService';
|
|
4
|
-
import { TokenService } from './TokenService';
|
|
4
|
+
import type { TokenService } from './TokenService';
|
|
5
5
|
export declare class DeviceService {
|
|
6
6
|
private readonly storageService;
|
|
7
7
|
private readonly tokenService;
|
|
8
8
|
private readonly deviceAPIService;
|
|
9
|
-
private
|
|
9
|
+
private deviceIdKey;
|
|
10
|
+
private currentDevice?;
|
|
10
11
|
constructor(storageService: StorageService, tokenService: TokenService, deviceAPIService: DeviceAPIService);
|
|
12
|
+
initialize(): Promise<void>;
|
|
13
|
+
private generateDeviceId;
|
|
11
14
|
getCurrentDeviceId(): string;
|
|
15
|
+
createDevice(): Promise<ClixDevice>;
|
|
16
|
+
upsertDevice(device: ClixDevice): Promise<void>;
|
|
17
|
+
updatePushToken(pushToken: string, pushTokenType: string): Promise<void>;
|
|
18
|
+
updatePushPermission(isGranted: boolean): Promise<void>;
|
|
12
19
|
setProjectUserId(projectUserId: string): Promise<void>;
|
|
13
20
|
removeProjectUserId(): Promise<void>;
|
|
14
21
|
updateUserProperties(properties: Record<string, any>): Promise<void>;
|
|
15
22
|
removeUserProperties(names: string[]): Promise<void>;
|
|
16
|
-
upsertToken(token: string, tokenType?: string): Promise<void>;
|
|
17
|
-
upsertIsPushPermissionGranted(isGranted: boolean): Promise<void>;
|
|
18
23
|
private getPushPermissionStatus;
|
|
19
|
-
|
|
24
|
+
private getPushToken;
|
|
20
25
|
}
|
|
21
26
|
//# sourceMappingURL=DeviceService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceService.d.ts","sourceRoot":"","sources":["../../../../src/services/DeviceService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DeviceService.d.ts","sourceRoot":"","sources":["../../../../src/services/DeviceService.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIlD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,qBAAa,aAAa;IAKtB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IANnC,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,aAAa,CAAC,CAAa;gBAGhB,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE,YAAY,EAC1B,gBAAgB,EAAE,gBAAgB;IAG/C,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAKjC,OAAO,CAAC,gBAAgB;IAIxB,kBAAkB,IAAI,MAAM;IAatB,YAAY,IAAI,OAAO,CAAC,UAAU,CAAC;IA2CnC,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,eAAe,CACnB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,IAAI,CAAC;IAoBV,oBAAoB,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBvD,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKtD,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAKpC,oBAAoB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAQpE,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;YAK5C,uBAAuB;YAiBvB,YAAY;CAU3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventAPIService.d.ts","sourceRoot":"","sources":["../../../../src/services/EventAPIService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,aAAa;IAE/C,UAAU,CACd,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC/B,SAAS,CAAC,EAAE,MAAM,EAClB,aAAa,CAAC,EAAE,MAAM,EACtB,iBAAiB,CAAC,EAAE,MAAM,GACzB,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"EventAPIService.d.ts","sourceRoot":"","sources":["../../../../src/services/EventAPIService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,aAAa;IAE/C,UAAU,CACd,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC/B,SAAS,CAAC,EAAE,MAAM,EAClB,aAAa,CAAC,EAAE,MAAM,EACtB,iBAAiB,CAAC,EAAE,MAAM,GACzB,OAAO,CAAC,IAAI,CAAC;CAoCjB"}
|
|
@@ -4,6 +4,7 @@ export declare class EventService {
|
|
|
4
4
|
private readonly eventAPIService;
|
|
5
5
|
private readonly deviceService;
|
|
6
6
|
constructor(eventAPIService: EventAPIService, deviceService: DeviceService);
|
|
7
|
+
private serializeProperties;
|
|
7
8
|
trackEvent(name: string, properties?: Record<string, any>, messageId?: string, userJourneyId?: string, userJourneyNodeId?: string): Promise<void>;
|
|
8
9
|
}
|
|
9
10
|
//# sourceMappingURL=EventService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventService.d.ts","sourceRoot":"","sources":["../../../../src/services/EventService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EventService.d.ts","sourceRoot":"","sources":["../../../../src/services/EventService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,qBAAa,YAAY;IAErB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,aAAa;gBADb,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,aAAa;IAG/C,OAAO,CAAC,mBAAmB;IAiBrB,UAAU,CACd,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAChC,SAAS,CAAC,EAAE,MAAM,EAClB,aAAa,CAAC,EAAE,MAAM,EACtB,iBAAiB,CAAC,EAAE,MAAM,GACzB,OAAO,CAAC,IAAI,CAAC;CAYjB"}
|
|
@@ -1,77 +1,70 @@
|
|
|
1
|
-
import { type NotificationSettings } from '@notifee/react-native';
|
|
1
|
+
import { type Event, type NotificationSettings } from '@notifee/react-native';
|
|
2
2
|
import { DeviceService } from './DeviceService';
|
|
3
3
|
import { EventService } from './EventService';
|
|
4
|
-
import { StorageService } from './StorageService';
|
|
5
4
|
import { TokenService } from './TokenService';
|
|
6
5
|
type NotificationData = Record<string, any>;
|
|
7
|
-
export type
|
|
6
|
+
export type MessageHandler = (data: NotificationData) => Promise<boolean> | boolean;
|
|
8
7
|
export type BackgroundMessageHandler = (data: NotificationData) => Promise<void> | void;
|
|
9
|
-
export type
|
|
10
|
-
export type
|
|
8
|
+
export type NotificationOpenedAppHandler = (data: NotificationData) => Promise<void> | void;
|
|
9
|
+
export type TokenRefreshHandler = (token: string) => Promise<void> | void;
|
|
10
|
+
export type ForegroundEventHandler = (event: Event) => Promise<void> | void;
|
|
11
11
|
export declare class NotificationService {
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
|
|
12
|
+
private readonly deviceService;
|
|
13
|
+
private readonly tokenService;
|
|
14
|
+
private readonly eventService;
|
|
15
|
+
autoHandleLandingUrl: boolean;
|
|
16
|
+
messageHandler?: MessageHandler;
|
|
17
|
+
backgroundMessageHandler?: BackgroundMessageHandler;
|
|
18
|
+
notificationOpenedAppHandler?: NotificationOpenedAppHandler;
|
|
19
|
+
tokenRefreshHandler?: TokenRefreshHandler;
|
|
20
|
+
foregroundEventHandler?: ForegroundEventHandler;
|
|
16
21
|
private isInitialized;
|
|
17
|
-
private currentPushToken;
|
|
18
22
|
private processedMessageIds;
|
|
19
|
-
private
|
|
20
|
-
private
|
|
21
|
-
private deviceService?;
|
|
22
|
-
private tokenService?;
|
|
23
|
-
private autoHandleLandingUrl;
|
|
24
|
-
private messageHandler?;
|
|
25
|
-
private backgroundMessageHandler?;
|
|
26
|
-
private openedHandler?;
|
|
27
|
-
private fcmTokenErrorHandler?;
|
|
28
|
-
private unsubscribeForegroundMessage?;
|
|
29
|
-
private unsubscribeNotificationOpened?;
|
|
23
|
+
private unsubscribeMessage?;
|
|
24
|
+
private unsubscribeNotificationOpenedApp?;
|
|
30
25
|
private unsubscribeTokenRefresh?;
|
|
31
|
-
private
|
|
32
|
-
private
|
|
33
|
-
static
|
|
34
|
-
|
|
35
|
-
initialize(
|
|
36
|
-
getCurrentToken(): Promise<string | null>;
|
|
26
|
+
private unsubscribeForegroundEvent?;
|
|
27
|
+
private static readonly DEFAULT_CHANNEL;
|
|
28
|
+
private static readonly ANDROID_GROUP_ID;
|
|
29
|
+
constructor(deviceService: DeviceService, tokenService: TokenService, eventService: EventService);
|
|
30
|
+
initialize(): Promise<void>;
|
|
37
31
|
cleanup(): void;
|
|
38
|
-
setMessageHandler(handler?: ForegroundMessageHandler): void;
|
|
39
|
-
setBackgroundMessageHandler(handler?: BackgroundMessageHandler): void;
|
|
40
|
-
setNotificationOpenedHandler(handler?: NotificationOpenedHandler): void;
|
|
41
|
-
setFcmTokenErrorHandler(handler?: FcmTokenErrorHandler): void;
|
|
42
|
-
setAutoHandleLandingUrl(enable: boolean): void;
|
|
43
|
-
private initializeNotificationDisplayService;
|
|
44
|
-
private createNotificationChannels;
|
|
45
|
-
private setupNotificationEventListeners;
|
|
46
|
-
private handleNotificationEvent;
|
|
47
|
-
private handleActionPress;
|
|
48
|
-
private initializeMessageService;
|
|
49
|
-
private setupMessageHandlers;
|
|
50
|
-
private handleBackgroundMessage;
|
|
51
|
-
private handleForegroundMessage;
|
|
52
32
|
requestPermission(): Promise<NotificationSettings>;
|
|
53
33
|
setPermissionGranted(isGranted: boolean): Promise<void>;
|
|
34
|
+
private setupPushReceivedHandler;
|
|
35
|
+
private setupPushTappedHandler;
|
|
54
36
|
private setupTokenRefreshListener;
|
|
55
|
-
private
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
private
|
|
37
|
+
private createNotificationChannels;
|
|
38
|
+
/**
|
|
39
|
+
* Android: background message handler
|
|
40
|
+
*/
|
|
41
|
+
private handleBackgroundMessage;
|
|
42
|
+
/**
|
|
43
|
+
* iOS & Android: foreground message handler
|
|
44
|
+
*/
|
|
45
|
+
private handleForegroundMessage;
|
|
46
|
+
/**
|
|
47
|
+
* iOS: background notification tap handler
|
|
48
|
+
*/
|
|
49
|
+
private handleNotificationOpenedApp;
|
|
50
|
+
/**
|
|
51
|
+
* iOS: app launched from a quit state via a notification
|
|
52
|
+
*/
|
|
53
|
+
private handleInitialNotification;
|
|
54
|
+
/**
|
|
55
|
+
* Android: background notification tap handler
|
|
56
|
+
*/
|
|
57
|
+
private handleNotificationEvent;
|
|
58
|
+
/**
|
|
59
|
+
* iOS & Android: foreground notification tap handler
|
|
60
|
+
*/
|
|
61
|
+
private handleForegroundNotificationEvent;
|
|
62
|
+
private trackPushReceivedEvent;
|
|
63
|
+
private trackPushTappedEvent;
|
|
60
64
|
private displayNotification;
|
|
61
65
|
private createNotificationConfig;
|
|
62
|
-
private createNotificationActions;
|
|
63
|
-
private isValidImageUrl;
|
|
64
|
-
private extractNotificationContent;
|
|
65
|
-
private handlePushReceived;
|
|
66
|
-
private handlePushTapped;
|
|
67
|
-
private handleNotificationTap;
|
|
68
66
|
private handleUrlNavigation;
|
|
69
67
|
private parseClixPayload;
|
|
70
|
-
private trackPushEvent;
|
|
71
|
-
private extractTrackingProperties;
|
|
72
|
-
private trackEventInBackground;
|
|
73
|
-
private shouldDisplayForegroundNotification;
|
|
74
|
-
private handleFcmTokenError;
|
|
75
68
|
}
|
|
76
69
|
export {};
|
|
77
70
|
//# sourceMappingURL=NotificationService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationService.d.ts","sourceRoot":"","sources":["../../../../src/services/NotificationService.ts"],"names":[],"mappings":"AAAA,OAAgB,
|
|
1
|
+
{"version":3,"file":"NotificationService.d.ts","sourceRoot":"","sources":["../../../../src/services/NotificationService.ts"],"names":[],"mappings":"AAAA,OAAgB,EASd,KAAK,KAAK,EAEV,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAC;AAO/B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,KAAK,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE5C,MAAM,MAAM,cAAc,GAAG,CAC3B,IAAI,EAAE,gBAAgB,KACnB,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AAChC,MAAM,MAAM,wBAAwB,GAAG,CACrC,IAAI,EAAE,gBAAgB,KACnB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAC1B,MAAM,MAAM,4BAA4B,GAAG,CACzC,IAAI,EAAE,gBAAgB,KACnB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAC1B,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAC1E,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAE5E,qBAAa,mBAAmB;IA2B5B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY;IA5B/B,oBAAoB,UAAQ;IAC5B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,wBAAwB,CAAC,EAAE,wBAAwB,CAAC;IACpD,4BAA4B,CAAC,EAAE,4BAA4B,CAAC;IAC5D,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;IAEhD,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,mBAAmB,CAAqB;IAChD,OAAO,CAAC,kBAAkB,CAAC,CAAa;IACxC,OAAO,CAAC,gCAAgC,CAAC,CAAa;IACtD,OAAO,CAAC,uBAAuB,CAAC,CAAa;IAC7C,OAAO,CAAC,0BAA0B,CAAC,CAAa;IAEhD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAQrC;IACF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAA6B;gBAGlD,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,YAAY;IAGvC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAyBjC,OAAO,IAAI,IAAI;IAUT,iBAAiB,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAoBlD,oBAAoB,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAa7D,OAAO,CAAC,wBAAwB;YAkBlB,sBAAsB;IAwBpC,OAAO,CAAC,yBAAyB;YAoBnB,0BAA0B;IASxC;;OAEG;YACW,uBAAuB;IA6BrC;;OAEG;YACW,uBAAuB;IAqDrC;;OAEG;YACW,2BAA2B;IA+BzC;;OAEG;YACW,yBAAyB;IAuBvC;;OAEG;YACW,uBAAuB;IAwBrC;;OAEG;YACW,iCAAiC;YAUjC,sBAAsB;YAuBtB,oBAAoB;YAoBpB,mBAAmB;YAqCnB,wBAAwB;YAiDxB,mBAAmB;IA8BjC,OAAO,CAAC,gBAAgB;CAuDzB"}
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { StorageService } from './StorageService';
|
|
2
2
|
export declare class TokenService {
|
|
3
3
|
private readonly storageService;
|
|
4
|
-
private
|
|
5
|
-
private static readonly PREVIOUS_TOKENS_KEY;
|
|
6
|
-
private static readonly MAX_TOKENS;
|
|
4
|
+
private currentTokenKey;
|
|
7
5
|
constructor(storageService: StorageService);
|
|
8
6
|
getCurrentToken(): string | undefined;
|
|
9
|
-
getPreviousTokens(): string[];
|
|
10
7
|
saveToken(token: string): void;
|
|
11
|
-
clearTokens(): void;
|
|
12
|
-
convertTokenToString(deviceToken: number[]): string;
|
|
13
|
-
reset(): void;
|
|
14
8
|
}
|
|
15
9
|
//# sourceMappingURL=TokenService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TokenService.d.ts","sourceRoot":"","sources":["../../../../src/services/TokenService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TokenService.d.ts","sourceRoot":"","sources":["../../../../src/services/TokenService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,qBAAa,YAAY;IAGX,OAAO,CAAC,QAAQ,CAAC,cAAc;IAF3C,OAAO,CAAC,eAAe,CAA6B;gBAEvB,cAAc,EAAE,cAAc;IAE3D,eAAe,IAAI,MAAM,GAAG,SAAS;IAIrC,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAG/B"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HTTPRequest } from './HTTPRequest';
|
|
2
|
+
import type { HTTPResponse } from './HTTPResponse';
|
|
3
|
+
export declare class HTTPClient {
|
|
4
|
+
static shared: HTTPClient;
|
|
5
|
+
request<T>(request: HTTPRequest): Promise<HTTPResponse<T>>;
|
|
6
|
+
get<T>(url: string, params?: Record<string, any>, headers?: Record<string, string>): Promise<HTTPResponse<T>>;
|
|
7
|
+
post<T>(url: string, data?: any, params?: Record<string, any>, headers?: Record<string, string>): Promise<HTTPResponse<T>>;
|
|
8
|
+
put<T>(url: string, data?: any, params?: Record<string, any>, headers?: Record<string, string>): Promise<HTTPResponse<T>>;
|
|
9
|
+
delete<T>(url: string, params?: Record<string, any>, headers?: Record<string, string>): Promise<HTTPResponse<T>>;
|
|
10
|
+
private buildUrlWithParams;
|
|
11
|
+
private prepareBody;
|
|
12
|
+
private parseResponse;
|
|
13
|
+
private headersToRecord;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=HTTPClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HTTPClient.d.ts","sourceRoot":"","sources":["../../../../../src/utils/http/HTTPClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,qBAAa,UAAU;IACrB,MAAM,CAAC,MAAM,aAAoB;IAE3B,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAwB1D,GAAG,CAAC,CAAC,EACT,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAIrB,IAAI,CAAC,CAAC,EACV,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,GAAG,EACV,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAUrB,GAAG,CAAC,CAAC,EACT,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,GAAG,EACV,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAUrB,MAAM,CAAC,CAAC,EACZ,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAI3B,OAAO,CAAC,kBAAkB;IAsC1B,OAAO,CAAC,WAAW;YAQL,aAAa;IAU3B,OAAO,CAAC,eAAe;CAOxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HTTPMethod.d.ts","sourceRoot":"","sources":["../../../../../src/utils/http/HTTPMethod.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IACpB,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,MAAM,WAAW;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HTTPRequest.d.ts","sourceRoot":"","sources":["../../../../../src/utils/http/HTTPRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HTTPResponse.d.ts","sourceRoot":"","sources":["../../../../../src/utils/http/HTTPResponse.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,IAAI,EAAE,CAAC,CAAC;IACR,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/utils/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KACvB,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACrB,GAAG,EAAE,CAAC;AAEP,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,QAAQ,CACtD,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CACjC,CAAC"}
|
package/package.json
CHANGED
package/src/core/Clix.ts
CHANGED
|
@@ -6,39 +6,73 @@ import { EventService } from '../services/EventService';
|
|
|
6
6
|
import { NotificationService } from '../services/NotificationService';
|
|
7
7
|
import { StorageService } from '../services/StorageService';
|
|
8
8
|
import { TokenService } from '../services/TokenService';
|
|
9
|
-
import { ClixError } from '../utils/ClixError';
|
|
10
9
|
import { ClixLogger, ClixLogLevel } from '../utils/logging/ClixLogger';
|
|
10
|
+
import type { PickPartial, Prettify } from '../utils/types';
|
|
11
11
|
import type { ClixConfig } from './ClixConfig';
|
|
12
12
|
import { ClixInitCoordinator } from './ClixInitCoordinator';
|
|
13
13
|
import { ClixNotification } from './ClixNotification';
|
|
14
14
|
|
|
15
|
+
type ClixInitializeOptions = Prettify<
|
|
16
|
+
PickPartial<ClixConfig, 'endpoint' | 'logLevel' | 'extraHeaders'>
|
|
17
|
+
>;
|
|
18
|
+
|
|
15
19
|
export class Clix {
|
|
16
20
|
static shared?: Clix;
|
|
17
21
|
static initCoordinator = new ClixInitCoordinator();
|
|
18
22
|
|
|
19
23
|
static Notification = ClixNotification.shared;
|
|
20
24
|
|
|
25
|
+
config?: ClixConfig;
|
|
21
26
|
storageService?: StorageService;
|
|
27
|
+
tokenService?: TokenService;
|
|
22
28
|
eventService?: EventService;
|
|
23
29
|
deviceService?: DeviceService;
|
|
24
30
|
notificationService?: NotificationService;
|
|
25
31
|
|
|
26
|
-
private
|
|
32
|
+
private static configKey = 'clix_config';
|
|
27
33
|
|
|
28
34
|
/**
|
|
29
35
|
* Initialize Clix SDK
|
|
30
36
|
*/
|
|
31
|
-
static async initialize(
|
|
37
|
+
static async initialize(options: ClixInitializeOptions): Promise<void> {
|
|
32
38
|
try {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
const config: ClixConfig = {
|
|
40
|
+
...options,
|
|
41
|
+
endpoint: options.endpoint || 'https://api.clix.so',
|
|
42
|
+
logLevel: options.logLevel || ClixLogLevel.INFO,
|
|
43
|
+
extraHeaders: options.extraHeaders || {},
|
|
44
|
+
};
|
|
36
45
|
|
|
37
46
|
ClixLogger.setLogLevel(config.logLevel || ClixLogLevel.ERROR);
|
|
38
|
-
ClixLogger.debug('Initializing Clix SDK');
|
|
47
|
+
ClixLogger.debug('Initializing Clix SDK...');
|
|
39
48
|
|
|
40
49
|
this.shared = new Clix();
|
|
41
|
-
|
|
50
|
+
this.shared.config = config;
|
|
51
|
+
|
|
52
|
+
const apiClient = new ClixAPIClient(config);
|
|
53
|
+
const deviceApiService = new DeviceAPIService(apiClient);
|
|
54
|
+
const eventApiService = new EventAPIService(apiClient);
|
|
55
|
+
|
|
56
|
+
this.shared.storageService = new StorageService(config.projectId);
|
|
57
|
+
this.shared.tokenService = new TokenService(this.shared.storageService);
|
|
58
|
+
this.shared.deviceService = new DeviceService(
|
|
59
|
+
this.shared.storageService,
|
|
60
|
+
this.shared.tokenService,
|
|
61
|
+
deviceApiService
|
|
62
|
+
);
|
|
63
|
+
this.shared.eventService = new EventService(
|
|
64
|
+
eventApiService,
|
|
65
|
+
this.shared.deviceService
|
|
66
|
+
);
|
|
67
|
+
this.shared.notificationService = new NotificationService(
|
|
68
|
+
this.shared.deviceService,
|
|
69
|
+
this.shared.tokenService,
|
|
70
|
+
this.shared.eventService
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
this.shared.storageService.set(this.configKey, config);
|
|
74
|
+
await this.shared.notificationService.initialize(); // NOTE(nyanxyz): must be initialized before any await calls
|
|
75
|
+
await this.shared.deviceService.initialize();
|
|
42
76
|
|
|
43
77
|
ClixLogger.debug('Clix SDK initialized successfully');
|
|
44
78
|
this.initCoordinator.completeInitialization();
|
|
@@ -46,7 +80,6 @@ export class Clix {
|
|
|
46
80
|
const errorInstance =
|
|
47
81
|
error instanceof Error ? error : new Error(String(error));
|
|
48
82
|
this.initCoordinator.failInitialization(errorInstance);
|
|
49
|
-
throw ClixError.notInitialized({ cause: errorInstance });
|
|
50
83
|
}
|
|
51
84
|
}
|
|
52
85
|
|
|
@@ -56,9 +89,7 @@ export class Clix {
|
|
|
56
89
|
static async setUserId(userId: string): Promise<void> {
|
|
57
90
|
try {
|
|
58
91
|
await Clix.initCoordinator.waitForInitialization();
|
|
59
|
-
|
|
60
|
-
await this.shared.deviceService.setProjectUserId(userId);
|
|
61
|
-
}
|
|
92
|
+
await this.shared?.deviceService?.setProjectUserId(userId);
|
|
62
93
|
} catch (error) {
|
|
63
94
|
ClixLogger.error(`Failed to set user ID: ${error}`);
|
|
64
95
|
}
|
|
@@ -70,9 +101,7 @@ export class Clix {
|
|
|
70
101
|
static async removeUserId(): Promise<void> {
|
|
71
102
|
try {
|
|
72
103
|
await Clix.initCoordinator.waitForInitialization();
|
|
73
|
-
|
|
74
|
-
await this.shared.deviceService.removeProjectUserId();
|
|
75
|
-
}
|
|
104
|
+
await this.shared?.deviceService?.removeProjectUserId();
|
|
76
105
|
} catch (error) {
|
|
77
106
|
ClixLogger.error(`Failed to remove user ID: ${error}`);
|
|
78
107
|
}
|
|
@@ -84,11 +113,7 @@ export class Clix {
|
|
|
84
113
|
static async setUserProperty(key: string, value: any): Promise<void> {
|
|
85
114
|
try {
|
|
86
115
|
await Clix.initCoordinator.waitForInitialization();
|
|
87
|
-
|
|
88
|
-
await this.shared.deviceService.updateUserProperties({
|
|
89
|
-
[key]: value,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
116
|
+
await this.shared?.deviceService?.updateUserProperties({ [key]: value });
|
|
92
117
|
} catch (error) {
|
|
93
118
|
ClixLogger.error(`Failed to set user property: ${error}`);
|
|
94
119
|
}
|
|
@@ -98,13 +123,11 @@ export class Clix {
|
|
|
98
123
|
* Set user properties
|
|
99
124
|
*/
|
|
100
125
|
static async setUserProperties(
|
|
101
|
-
|
|
126
|
+
properties: Record<string, any>
|
|
102
127
|
): Promise<void> {
|
|
103
128
|
try {
|
|
104
129
|
await Clix.initCoordinator.waitForInitialization();
|
|
105
|
-
|
|
106
|
-
await this.shared.deviceService.updateUserProperties(userProperties);
|
|
107
|
-
}
|
|
130
|
+
await this.shared?.deviceService?.updateUserProperties(properties);
|
|
108
131
|
} catch (error) {
|
|
109
132
|
ClixLogger.error(`Failed to set user properties: ${error}`);
|
|
110
133
|
}
|
|
@@ -116,9 +139,7 @@ export class Clix {
|
|
|
116
139
|
static async removeUserProperty(key: string): Promise<void> {
|
|
117
140
|
try {
|
|
118
141
|
await Clix.initCoordinator.waitForInitialization();
|
|
119
|
-
|
|
120
|
-
await this.shared.deviceService.removeUserProperties([key]);
|
|
121
|
-
}
|
|
142
|
+
await this.shared?.deviceService?.removeUserProperties([key]);
|
|
122
143
|
} catch (error) {
|
|
123
144
|
ClixLogger.error(`Failed to remove user property: ${error}`);
|
|
124
145
|
}
|
|
@@ -130,45 +151,24 @@ export class Clix {
|
|
|
130
151
|
static async removeUserProperties(keys: string[]): Promise<void> {
|
|
131
152
|
try {
|
|
132
153
|
await Clix.initCoordinator.waitForInitialization();
|
|
133
|
-
|
|
134
|
-
await this.shared.deviceService.removeUserProperties(keys);
|
|
135
|
-
}
|
|
154
|
+
await this.shared?.deviceService?.removeUserProperties(keys);
|
|
136
155
|
} catch (error) {
|
|
137
156
|
ClixLogger.error(`Failed to remove user properties: ${error}`);
|
|
138
157
|
}
|
|
139
158
|
}
|
|
140
159
|
|
|
141
160
|
/**
|
|
142
|
-
*
|
|
143
|
-
*/
|
|
144
|
-
static async getDeviceId(): Promise<string | undefined> {
|
|
145
|
-
try {
|
|
146
|
-
await Clix.initCoordinator.waitForInitialization();
|
|
147
|
-
if (this.shared?.deviceService) {
|
|
148
|
-
const deviceId = await this.shared.deviceService.getCurrentDeviceId();
|
|
149
|
-
return deviceId;
|
|
150
|
-
}
|
|
151
|
-
return undefined;
|
|
152
|
-
} catch (error) {
|
|
153
|
-
ClixLogger.error(`Failed to get device ID: ${error}`);
|
|
154
|
-
return undefined;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* @deprecated Use Clix.Notification.getToken() instead.
|
|
161
|
+
* Track event
|
|
160
162
|
*/
|
|
161
|
-
static async
|
|
163
|
+
static async trackEvent(
|
|
164
|
+
name: string,
|
|
165
|
+
properties: Record<string, any> = {}
|
|
166
|
+
): Promise<void> {
|
|
162
167
|
try {
|
|
163
168
|
await Clix.initCoordinator.waitForInitialization();
|
|
164
|
-
|
|
165
|
-
const token = await this.shared.notificationService.getCurrentToken();
|
|
166
|
-
return token || undefined;
|
|
167
|
-
}
|
|
168
|
-
return undefined;
|
|
169
|
+
await this.shared?.eventService?.trackEvent(name, properties);
|
|
169
170
|
} catch (error) {
|
|
170
|
-
ClixLogger.error(`Failed to
|
|
171
|
-
return undefined;
|
|
171
|
+
ClixLogger.error(`Failed to track event: ${error}`);
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
|
|
@@ -176,73 +176,20 @@ export class Clix {
|
|
|
176
176
|
* Set log level
|
|
177
177
|
*/
|
|
178
178
|
static setLogLevel(level: ClixLogLevel): void {
|
|
179
|
+
ClixLogger.debug(`Setting log level: ${level}`);
|
|
179
180
|
ClixLogger.setLogLevel(level);
|
|
180
181
|
}
|
|
181
182
|
|
|
182
183
|
/**
|
|
183
|
-
*
|
|
184
|
+
* Get device ID
|
|
184
185
|
*/
|
|
185
|
-
static async
|
|
186
|
-
name: string,
|
|
187
|
-
properties: Record<string, any> = {}
|
|
188
|
-
): Promise<void> {
|
|
186
|
+
static async getDeviceId(): Promise<string | undefined> {
|
|
189
187
|
try {
|
|
190
188
|
await Clix.initCoordinator.waitForInitialization();
|
|
191
|
-
|
|
192
|
-
await this.shared.eventService.trackEvent(name, properties);
|
|
193
|
-
}
|
|
189
|
+
return this.shared?.deviceService?.getCurrentDeviceId();
|
|
194
190
|
} catch (error) {
|
|
195
|
-
ClixLogger.error(`Failed to
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Set configuration
|
|
201
|
-
*/
|
|
202
|
-
private async setConfig(rawConfig: ClixConfig): Promise<void> {
|
|
203
|
-
const config: Required<ClixConfig> = {
|
|
204
|
-
...rawConfig,
|
|
205
|
-
endpoint: rawConfig.endpoint || 'https://api.clix.so',
|
|
206
|
-
logLevel: rawConfig.logLevel || ClixLogLevel.INFO,
|
|
207
|
-
extraHeaders: rawConfig.extraHeaders || {},
|
|
208
|
-
};
|
|
209
|
-
this.storageService = new StorageService(config.projectId);
|
|
210
|
-
|
|
211
|
-
try {
|
|
212
|
-
this.storageService.set('project_id', config.projectId);
|
|
213
|
-
this.storageService.set('api_key', config.apiKey);
|
|
214
|
-
this.storageService.set('clix_config', config);
|
|
215
|
-
} catch (error) {
|
|
216
|
-
ClixLogger.warn(
|
|
217
|
-
'Failed to store configuration in storage, continuing with in-memory config',
|
|
218
|
-
error
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const apiClient = new ClixAPIClient(config);
|
|
223
|
-
|
|
224
|
-
const deviceAPIService = new DeviceAPIService(apiClient);
|
|
225
|
-
const eventAPIService = new EventAPIService(apiClient);
|
|
226
|
-
const tokenService = new TokenService(this.storageService);
|
|
227
|
-
this.deviceService = new DeviceService(
|
|
228
|
-
this.storageService,
|
|
229
|
-
tokenService,
|
|
230
|
-
deviceAPIService
|
|
231
|
-
);
|
|
232
|
-
this.eventService = new EventService(eventAPIService, this.deviceService);
|
|
233
|
-
try {
|
|
234
|
-
this.notificationService =
|
|
235
|
-
await NotificationService.getInstance().initialize(
|
|
236
|
-
this.eventService,
|
|
237
|
-
this.storageService,
|
|
238
|
-
this.deviceService,
|
|
239
|
-
tokenService
|
|
240
|
-
);
|
|
241
|
-
} catch (error) {
|
|
242
|
-
ClixLogger.warn(
|
|
243
|
-
'Failed to fully initialize notification service, some features may be limited',
|
|
244
|
-
error
|
|
245
|
-
);
|
|
191
|
+
ClixLogger.error(`Failed to get device ID: ${error}`);
|
|
192
|
+
return undefined;
|
|
246
193
|
}
|
|
247
194
|
}
|
|
248
195
|
}
|
package/src/core/ClixConfig.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ClixLogLevel } from '../utils/logging/ClixLogger';
|
|
|
3
3
|
export interface ClixConfig {
|
|
4
4
|
projectId: string;
|
|
5
5
|
apiKey: string;
|
|
6
|
-
endpoint
|
|
7
|
-
logLevel
|
|
8
|
-
extraHeaders
|
|
6
|
+
endpoint: string;
|
|
7
|
+
logLevel: ClixLogLevel;
|
|
8
|
+
extraHeaders: Record<string, string>;
|
|
9
9
|
}
|
|
@@ -18,17 +18,14 @@ export class ClixInitCoordinator {
|
|
|
18
18
|
if (this.isCompleted) {
|
|
19
19
|
return Promise.resolve();
|
|
20
20
|
}
|
|
21
|
+
if (this.isFailed) {
|
|
22
|
+
return Promise.reject(
|
|
23
|
+
new Error('Clix initialization has already failed')
|
|
24
|
+
);
|
|
25
|
+
}
|
|
21
26
|
return this.promise;
|
|
22
27
|
}
|
|
23
28
|
|
|
24
|
-
isInitializationFailed(): boolean {
|
|
25
|
-
return this.isFailed;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
isInitializationCompleted(): boolean {
|
|
29
|
-
return this.isCompleted;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
29
|
completeInitialization(): void {
|
|
33
30
|
if (this.isAlreadyFinalized()) {
|
|
34
31
|
return;
|
|
@@ -46,15 +43,6 @@ export class ClixInitCoordinator {
|
|
|
46
43
|
this.reject?.(error);
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
reset(): void {
|
|
50
|
-
this.isCompleted = false;
|
|
51
|
-
this.isFailed = false;
|
|
52
|
-
this.promise = new Promise<void>((resolve, reject) => {
|
|
53
|
-
this.resolve = resolve;
|
|
54
|
-
this.reject = reject;
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
46
|
private isAlreadyFinalized(): boolean {
|
|
59
47
|
if (this.isCompleted || this.isFailed) {
|
|
60
48
|
ClixLogger.warn('Initialization already completed or failed');
|