@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.
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,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 static readonly DEVICE_ID_KEY;
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
- createDevice(deviceId: string, token?: string, isPushPermissionGranted?: boolean): Promise<ClixDevice>;
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":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAKlD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,qBAAa,aAAa;IAItB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IALnC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAoB;gBAGtC,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE,YAAY,EAC1B,gBAAgB,EAAE,gBAAgB;IAGrD,kBAAkB,IAAI,MAAM;IAatB,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IActD,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAcpC,oBAAoB,CAAC,UAA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AAG,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;CAsCjB"}
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":"AAEA,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;IAGzC,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;CAmCjB"}
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 ForegroundMessageHandler = (data: NotificationData) => Promise<boolean> | boolean;
6
+ export type MessageHandler = (data: NotificationData) => Promise<boolean> | boolean;
8
7
  export type BackgroundMessageHandler = (data: NotificationData) => Promise<void> | void;
9
- export type NotificationOpenedHandler = (data: NotificationData) => Promise<void> | void;
10
- export type FcmTokenErrorHandler = (error: Error) => Promise<void> | void;
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 static instance;
13
- private static readonly DEFAULT_CHANNEL;
14
- private static readonly ANDROID_GROUP_ID;
15
- private messagingService;
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 eventService;
20
- private storageService;
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 unsubscribeNotificationEvents?;
32
- private constructor();
33
- static getInstance(): NotificationService;
34
- static resetInstance(): void;
35
- initialize(eventService: EventService, storageService: StorageService, deviceService?: DeviceService, tokenService?: TokenService): Promise<NotificationService>;
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 checkInitialNotification;
56
- private getAndUpdateToken;
57
- private getOrFetchToken;
58
- private saveAndRegisterToken;
59
- private registerTokenWithServer;
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,EAWd,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAC;AAQ/B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAQ9C,KAAK,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE5C,MAAM,MAAM,wBA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AC5D,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 static readonly CURRENT_TOKEN_KEY;
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":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,qBAAa,YAAY;IAKX,OAAO,CAAC,QAAQ,CAAC,cAAc;IAJ3C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAA6B;IACtE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAsB;IACjE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAK;gBAEV,cAAc,EAAE,cAAc;IAE3D,eAAe,IAAI,MAAM,GAAG,SAAS;IASrC,iBAAiB,IAAI,MAAM,EAAE;IAc7B,SAAS,CAAC,KAAK,EAAE,MAAM;IA4BvB,WAAW;IAWX,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM;IAMnD,KAAK;CAGN"}
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,7 @@
1
+ export declare enum HTTPMethod {
2
+ GET = "GET",
3
+ POST = "POST",
4
+ PUT = "PUT",
5
+ DELETE = "DELETE"
6
+ }
7
+ //# sourceMappingURL=HTTPMethod.d.ts.map
@@ -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,9 @@
1
+ import { HTTPMethod } from './HTTPMethod';
2
+ export interface HTTPRequest {
3
+ url: string;
4
+ method: HTTPMethod;
5
+ params?: Record<string, any>;
6
+ headers?: Record<string, string>;
7
+ data?: any;
8
+ }
9
+ //# sourceMappingURL=HTTPRequest.d.ts.map
@@ -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,6 @@
1
+ export interface HTTPResponse<T> {
2
+ data: T;
3
+ statusCode: number;
4
+ headers: Record<string, string>;
5
+ }
6
+ //# sourceMappingURL=HTTPResponse.d.ts.map
@@ -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,5 @@
1
+ export type Prettify<T> = {
2
+ [K in keyof T]: T[K];
3
+ } & {};
4
+ export type PickPartial<T, K extends keyof T> = Prettify<Omit<T, K> & Partial<Pick<T, K>>>;
5
+ //# sourceMappingURL=types.d.ts.map
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clix-so/react-native-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Clix - Mobile push for builders",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
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 constructor() {}
32
+ private static configKey = 'clix_config';
27
33
 
28
34
  /**
29
35
  * Initialize Clix SDK
30
36
  */
31
- static async initialize(config: ClixConfig): Promise<void> {
37
+ static async initialize(options: ClixInitializeOptions): Promise<void> {
32
38
  try {
33
- if (this.initCoordinator.isInitializationFailed()) {
34
- this.initCoordinator.reset();
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
- await this.shared.setConfig(config);
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
- if (this.shared?.deviceService) {
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
- if (this.shared?.deviceService) {
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
- if (this.shared?.deviceService) {
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
- userProperties: Record<string, any>
126
+ properties: Record<string, any>
102
127
  ): Promise<void> {
103
128
  try {
104
129
  await Clix.initCoordinator.waitForInitialization();
105
- if (this.shared?.deviceService) {
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
- if (this.shared?.deviceService) {
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
- if (this.shared?.deviceService) {
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
- * Get device ID
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 getPushToken(): Promise<string | undefined> {
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
- if (this.shared?.notificationService) {
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 get push token: ${error}`);
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
- * Track event
184
+ * Get device ID
184
185
  */
185
- static async trackEvent(
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
- if (this.shared?.eventService) {
192
- await this.shared.eventService.trackEvent(name, properties);
193
- }
189
+ return this.shared?.deviceService?.getCurrentDeviceId();
194
190
  } catch (error) {
195
- ClixLogger.error(`Failed to track event: ${error}`);
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
  }
@@ -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?: string;
7
- logLevel?: ClixLogLevel;
8
- extraHeaders?: Record<string, string>;
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');