@clix-so/react-native-sdk 0.0.1 → 0.0.2-beta.2

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 (47) hide show
  1. package/README.md +51 -5
  2. package/lib/module/core/Clix.js +9 -7
  3. package/lib/module/core/Clix.js.map +1 -1
  4. package/lib/module/core/ClixNotification.js +122 -0
  5. package/lib/module/core/ClixNotification.js.map +1 -0
  6. package/lib/module/services/DeviceService.js +27 -19
  7. package/lib/module/services/DeviceService.js.map +1 -1
  8. package/lib/module/services/EventAPIService.js +7 -1
  9. package/lib/module/services/EventAPIService.js.map +1 -1
  10. package/lib/module/services/EventService.js +8 -5
  11. package/lib/module/services/EventService.js.map +1 -1
  12. package/lib/module/services/NotificationService.js +92 -49
  13. package/lib/module/services/NotificationService.js.map +1 -1
  14. package/lib/module/services/StorageService.js +52 -15
  15. package/lib/module/services/StorageService.js.map +1 -1
  16. package/lib/module/services/TokenService.js +13 -13
  17. package/lib/module/services/TokenService.js.map +1 -1
  18. package/lib/module/utils/ClixDateFormatter.js +19 -0
  19. package/lib/module/utils/ClixDateFormatter.js.map +1 -0
  20. package/lib/typescript/src/core/Clix.d.ts +11 -11
  21. package/lib/typescript/src/core/Clix.d.ts.map +1 -1
  22. package/lib/typescript/src/core/ClixNotification.d.ts +25 -0
  23. package/lib/typescript/src/core/ClixNotification.d.ts.map +1 -0
  24. package/lib/typescript/src/services/DeviceService.d.ts +3 -2
  25. package/lib/typescript/src/services/DeviceService.d.ts.map +1 -1
  26. package/lib/typescript/src/services/EventAPIService.d.ts +1 -1
  27. package/lib/typescript/src/services/EventAPIService.d.ts.map +1 -1
  28. package/lib/typescript/src/services/EventService.d.ts +1 -1
  29. package/lib/typescript/src/services/EventService.d.ts.map +1 -1
  30. package/lib/typescript/src/services/NotificationService.d.ts +21 -1
  31. package/lib/typescript/src/services/NotificationService.d.ts.map +1 -1
  32. package/lib/typescript/src/services/StorageService.d.ts +11 -6
  33. package/lib/typescript/src/services/StorageService.d.ts.map +1 -1
  34. package/lib/typescript/src/services/TokenService.d.ts +5 -5
  35. package/lib/typescript/src/services/TokenService.d.ts.map +1 -1
  36. package/lib/typescript/src/utils/ClixDateFormatter.d.ts +4 -0
  37. package/lib/typescript/src/utils/ClixDateFormatter.d.ts.map +1 -0
  38. package/package.json +2 -2
  39. package/src/core/Clix.ts +17 -21
  40. package/src/core/ClixNotification.ts +157 -0
  41. package/src/services/DeviceService.ts +35 -20
  42. package/src/services/EventAPIService.ts +5 -1
  43. package/src/services/EventService.ts +13 -5
  44. package/src/services/NotificationService.ts +148 -54
  45. package/src/services/StorageService.ts +60 -16
  46. package/src/services/TokenService.ts +13 -15
  47. package/src/utils/ClixDateFormatter.ts +19 -0
@@ -4,13 +4,16 @@ import { NotificationService } from '../services/NotificationService';
4
4
  import { StorageService } from '../services/StorageService';
5
5
  import { ClixLogLevel } from '../utils/logging/ClixLogger';
6
6
  import type { ClixConfig } from './ClixConfig';
7
+ import { ClixInitCoordinator } from './ClixInitCoordinator';
8
+ import { ClixNotification } from './ClixNotification';
7
9
  export declare class Clix {
8
- private static shared?;
9
- private static initCoordinator;
10
- protected storageService?: StorageService;
11
- protected eventService?: EventService;
12
- protected deviceService?: DeviceService;
13
- protected notificationService?: NotificationService;
10
+ static shared?: Clix;
11
+ static initCoordinator: ClixInitCoordinator;
12
+ static Notification: ClixNotification;
13
+ storageService?: StorageService;
14
+ eventService?: EventService;
15
+ deviceService?: DeviceService;
16
+ notificationService?: NotificationService;
14
17
  private constructor();
15
18
  /**
16
19
  * Initialize Clix SDK
@@ -45,7 +48,7 @@ export declare class Clix {
45
48
  */
46
49
  static getDeviceId(): Promise<string | undefined>;
47
50
  /**
48
- * Get push token
51
+ * @deprecated Use Clix.Notification.getToken() instead.
49
52
  */
50
53
  static getPushToken(): Promise<string | undefined>;
51
54
  /**
@@ -55,10 +58,7 @@ export declare class Clix {
55
58
  /**
56
59
  * Track event
57
60
  */
58
- protected static trackEvent(name: string, options?: {
59
- properties?: Record<string, any>;
60
- messageId?: string;
61
- }): Promise<void>;
61
+ static trackEvent(name: string, properties?: Record<string, any>): Promise<void>;
62
62
  /**
63
63
  * Set configuration
64
64
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Clix.d.ts","sourceRoot":"","sources":["../../../../src/core/Clix.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D,OAAO,EAAc,YAAY,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG/C,qBAAa,IAAI;IACf,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAO;IAC7B,OAAO,CAAC,MAAM,CAAC,eAAe,CAA6B;IAE3D,SAAS,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC;IAC1C,SAAS,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;IACtC,SAAS,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC;IACxC,SAAS,CAAC,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAEpD,OAAO;IAEP;;OAEG;WACU,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAsB1D;;OAEG;WACU,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWrD;;OAEG;WACU,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAW1C;;OAEG;WACU,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAapE;;OAEG;WACU,iBAAiB,CAC5B,cAAc,EAAE,MAAM,CA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 +1,25 @@
1
+ import { type NotificationSettings } from '@notifee/react-native';
2
+ import type { BackgroundMessageHandler, FcmTokenErrorHandler, ForegroundMessageHandler, NotificationOpenedHandler } from '../services/NotificationService';
3
+ interface ConfigureOptions {
4
+ /**
5
+ * @default false
6
+ */
7
+ autoRequestPermission?: boolean;
8
+ /**
9
+ * @default true
10
+ */
11
+ autoHandleLandingURL?: boolean;
12
+ }
13
+ export declare class ClixNotification {
14
+ static shared: ClixNotification;
15
+ configure(options?: ConfigureOptions): Promise<void>;
16
+ requestPermission(): Promise<NotificationSettings | null>;
17
+ setPermissionGranted(isGranted: boolean): Promise<void>;
18
+ getToken(): Promise<string | undefined>;
19
+ onMessage(handler?: ForegroundMessageHandler): Promise<void>;
20
+ onBackgroundMessage(handler?: BackgroundMessageHandler): Promise<void>;
21
+ onNotificationOpened(handler?: NotificationOpenedHandler): Promise<void>;
22
+ onFcmTokenError(handler?: FcmTokenErrorHandler): Promise<void>;
23
+ }
24
+ export {};
25
+ //# sourceMappingURL=ClixNotification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClixNotification.d.ts","sourceRoot":"","sources":["../../../../src/core/ClixNotification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EACV,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,iCAAiC,CAAC;AAIzC,UAAU,gBAAgB;IACxB;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;OAEG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,qBAAa,gBAAgB;IAC3B,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAA0B;IAEnD,SAAS,CAAC,OAAO,GAAE,gBAAqB;IAsBxC,iBAAiB,IAAI,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAgBzD,oBAAoB,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBvD,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAiBvC,SAAS,CAAC,OAAO,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IAc5D,mBAAmB,CAAC,OAAO,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IActE,oBAAoB,CACxB,OAAO,CAAC,EAAE,yBAAyB,GAClC,OAAO,CAAC,IAAI,CAAC;IAgBV,eAAe,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;CAarE"}
@@ -8,13 +8,14 @@ export declare class DeviceService {
8
8
  private readonly deviceAPIService;
9
9
  private static readonly DEVICE_ID_KEY;
10
10
  constructor(storageService: StorageService, tokenService: TokenService, deviceAPIService: DeviceAPIService);
11
- getCurrentDeviceId(): Promise<string>;
11
+ getCurrentDeviceId(): string;
12
12
  setProjectUserId(projectUserId: string): Promise<void>;
13
13
  removeProjectUserId(): Promise<void>;
14
14
  updateUserProperties(properties: Record<string, any>): Promise<void>;
15
15
  removeUserProperties(names: string[]): Promise<void>;
16
16
  upsertToken(token: string, tokenType?: string): Promise<void>;
17
+ upsertIsPushPermissionGranted(isGranted: boolean): Promise<void>;
17
18
  private getPushPermissionStatus;
18
- createDevice(deviceId: string, token?: string): Promise<ClixDevice>;
19
+ createDevice(deviceId: string, token?: string, isPushPermissionGranted?: boolean): Promise<ClixDevice>;
19
20
  }
20
21
  //# 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;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AO,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,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBpE,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAepD,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAgCpE,6BAA6B,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;YAmBxD,uBAAuB;IAoB/B,YAAY,CAChB,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,EACd,uBAAuB,CAAC,EAAE,OAAO,GAChC,OAAO,CAAC,UAAU,CAAC;CAyCvB"}
@@ -2,6 +2,6 @@ import { ClixAPIClient } from './ClixAPIClient';
2
2
  export declare class EventAPIService {
3
3
  private readonly apiClient;
4
4
  constructor(apiClient: ClixAPIClient);
5
- trackEvent(deviceId: string, name: string, properties: Record<string, any>, messageId?: string): Promise<void>;
5
+ trackEvent(deviceId: string, name: string, properties: Record<string, any>, messageId?: string, userJourneyId?: string, userJourneyNodeId?: string): Promise<void>;
6
6
  }
7
7
  //# sourceMappingURL=EventAPIService.d.ts.map
@@ -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,GACjB,OAAO,CAAC,IAAI,CAAC;CAoCjB"}
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"}
@@ -4,6 +4,6 @@ export declare class EventService {
4
4
  private readonly eventAPIService;
5
5
  private readonly deviceService;
6
6
  constructor(eventAPIService: EventAPIService, deviceService: DeviceService);
7
- trackEvent(name: string, properties?: Record<string, any>, messageId?: string): Promise<void>;
7
+ trackEvent(name: string, properties?: Record<string, any>, messageId?: string, userJourneyId?: string, userJourneyNodeId?: string): Promise<void>;
8
8
  }
9
9
  //# sourceMappingURL=EventService.d.ts.map
@@ -1 +1 @@
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;IAGzC,UAAU,CACd,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAChC,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC;CA8BjB"}
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,7 +1,13 @@
1
+ import { type NotificationSettings } from '@notifee/react-native';
1
2
  import { DeviceService } from './DeviceService';
2
3
  import { EventService } from './EventService';
3
4
  import { StorageService } from './StorageService';
4
5
  import { TokenService } from './TokenService';
6
+ type NotificationData = Record<string, any>;
7
+ export type ForegroundMessageHandler = (data: NotificationData) => Promise<boolean> | boolean;
8
+ 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;
5
11
  export declare class NotificationService {
6
12
  private static instance;
7
13
  private static readonly DEFAULT_CHANNEL;
@@ -13,6 +19,11 @@ export declare class NotificationService {
13
19
  private storageService;
14
20
  private deviceService?;
15
21
  private tokenService?;
22
+ private autoHandleLandingUrl;
23
+ private messageHandler?;
24
+ private backgroundMessageHandler?;
25
+ private openedHandler?;
26
+ private fcmTokenErrorHandler?;
16
27
  private unsubscribeForegroundMessage?;
17
28
  private unsubscribeNotificationOpened?;
18
29
  private unsubscribeTokenRefresh?;
@@ -23,6 +34,11 @@ export declare class NotificationService {
23
34
  initialize(eventService: EventService, storageService: StorageService, deviceService?: DeviceService, tokenService?: TokenService): Promise<NotificationService>;
24
35
  getCurrentToken(): Promise<string | null>;
25
36
  cleanup(): void;
37
+ setMessageHandler(handler?: ForegroundMessageHandler): void;
38
+ setBackgroundMessageHandler(handler?: BackgroundMessageHandler): void;
39
+ setNotificationOpenedHandler(handler?: NotificationOpenedHandler): void;
40
+ setFcmTokenErrorHandler(handler?: FcmTokenErrorHandler): void;
41
+ setAutoHandleLandingUrl(enable: boolean): void;
26
42
  private initializeNotificationDisplayService;
27
43
  private createNotificationChannels;
28
44
  private setupNotificationEventListeners;
@@ -32,7 +48,8 @@ export declare class NotificationService {
32
48
  private setupMessageHandlers;
33
49
  private handleBackgroundMessage;
34
50
  private handleForegroundMessage;
35
- private requestMessagePermission;
51
+ requestPermission(): Promise<NotificationSettings>;
52
+ setPermissionGranted(isGranted: boolean): Promise<void>;
36
53
  private setupTokenRefreshListener;
37
54
  private checkInitialNotification;
38
55
  private getAndUpdateToken;
@@ -52,5 +69,8 @@ export declare class NotificationService {
52
69
  private trackPushEvent;
53
70
  private extractTrackingProperties;
54
71
  private trackEventInBackground;
72
+ private shouldDisplayForegroundNotification;
73
+ private handleFcmTokenError;
55
74
  }
75
+ export {};
56
76
  //# sourceMappingURL=NotificationService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationService.d.ts","sourceRoot":"","s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AC,OAAO,CAAC,EAAE,yBAAyB,GAAG,IAAI;IAIvE,uBAAuB,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,IAAI;IAI7D,uBAAuB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;YAIhC,oCAAoC;YAOpC,0BAA0B;IASxC,OAAO,CAAC,+BAA+B;YAQzB,uBAAuB;YAyBvB,iBAAiB;YAUjB,wBAAwB;IAMtC,OAAO,CAAC,oBAAoB;YAoBd,uBAAuB;YAsCvB,uBAAuB;IA8C/B,iBAAiB,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAoBlD,oBAAoB,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB7D,OAAO,CAAC,yBAAyB;YAenB,wBAAwB;YAgBxB,iBAAiB;YAWjB,eAAe;YAgBf,oBAAoB;YAQpB,uBAAuB;YAOvB,mBAAmB;YA2CnB,wBAAwB;IA4DtC,OAAO,CAAC,yBAAyB;IA6BjC,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,0BAA0B;YAwCpB,kBAAkB;YAYlB,gBAAgB;YAehB,qBAAqB;YAgBrB,mBAAmB;IA8BjC,OAAO,CAAC,gBAAgB;YA8CV,cAAc;IAU5B,OAAO,CAAC,yBAAyB;YAUnB,sBAAsB;YAsCtB,mCAAmC;YAenC,mBAAmB;CASlC"}
@@ -1,10 +1,15 @@
1
1
  export declare class StorageService {
2
2
  private storage;
3
- constructor();
4
- set<T>(key: string, value: T): Promise<void>;
5
- get<T>(key: string): Promise<T | undefined>;
6
- remove(key: string): Promise<void>;
7
- clear(): Promise<void>;
8
- getAllKeys(): Promise<string[]>;
3
+ constructor(projectId: string);
4
+ private initializeCompat;
5
+ /**
6
+ * Delete a key from storage (works with both v2/v3 and v4 APIs)
7
+ */
8
+ private removeCompat;
9
+ set<T>(key: string, value: T): void;
10
+ get<T>(key: string): T | undefined;
11
+ remove(key: string): void;
12
+ clear(): void;
13
+ getAllKeys(): string[];
9
14
  }
10
15
  //# sourceMappingURL=StorageService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"StorageService.d.ts","sourceRoot":"","sources":["../../../../src/services/StorageService.ts"],"names":[],"mappings":"AAGA,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAO;;IAShB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB5C,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAsB3C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUlC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAStB,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAStC"}
1
+ {"version":3,"file":"StorageService.d.ts","sourceRoot":"","sources":["../../../../src/services/StorageService.ts"],"names":[],"mappings":"AAaA,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAe;gBAElB,SAAS,EAAE,MAAM;IAI7B,OAAO,CAAC,gBAAgB;IAsBxB;;OAEG;IACH,OAAO,CAAC,YAAY;IAWpB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAoBnC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAuBlC,MAAM,CAAC,GAAG,EAAE,MAAM;IAUlB,KAAK;IASL,UAAU;CASX"}
@@ -5,11 +5,11 @@ export declare class TokenService {
5
5
  private static readonly PREVIOUS_TOKENS_KEY;
6
6
  private static readonly MAX_TOKENS;
7
7
  constructor(storageService: StorageService);
8
- getCurrentToken(): Promise<string | undefined>;
9
- getPreviousTokens(): Promise<string[]>;
10
- saveToken(token: string): Promise<void>;
11
- clearTokens(): Promise<void>;
8
+ getCurrentToken(): string | undefined;
9
+ getPreviousTokens(): string[];
10
+ saveToken(token: string): void;
11
+ clearTokens(): void;
12
12
  convertTokenToString(deviceToken: number[]): string;
13
- reset(): Promise<void>;
13
+ reset(): void;
14
14
  }
15
15
  //# 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;IAErD,eAAe,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAW9C,iBAAiB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IActC,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA4BvC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAWlC,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM;IAM7C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
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"}
@@ -0,0 +1,4 @@
1
+ export declare class ClixDateFormatter {
2
+ static format(date: Date): string;
3
+ }
4
+ //# sourceMappingURL=ClixDateFormatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClixDateFormatter.d.ts","sourceRoot":"","sources":["../../../../src/utils/ClixDateFormatter.ts"],"names":[],"mappings":"AAAA,qBAAa,iBAAiB;IAC5B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;CAiBlC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clix-so/react-native-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.2-beta.2",
4
4
  "description": "Clix - Mobile push for builders",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -81,7 +81,7 @@
81
81
  "react-native-builder-bob": "0.40.12",
82
82
  "react-native-device-info": "13.2.0",
83
83
  "react-native-get-random-values": "1.11.0",
84
- "react-native-mmkv": "2.12.2",
84
+ "react-native-mmkv": "4.0.1",
85
85
  "release-it": "17.10.0",
86
86
  "typescript": "5.8.3",
87
87
  "uuid": "11.1.0"
package/src/core/Clix.ts CHANGED
@@ -10,15 +10,18 @@ import { ClixError } from '../utils/ClixError';
10
10
  import { ClixLogger, ClixLogLevel } from '../utils/logging/ClixLogger';
11
11
  import type { ClixConfig } from './ClixConfig';
12
12
  import { ClixInitCoordinator } from './ClixInitCoordinator';
13
+ import { ClixNotification } from './ClixNotification';
13
14
 
14
15
  export class Clix {
15
- private static shared?: Clix;
16
- private static initCoordinator = new ClixInitCoordinator();
16
+ static shared?: Clix;
17
+ static initCoordinator = new ClixInitCoordinator();
17
18
 
18
- protected storageService?: StorageService;
19
- protected eventService?: EventService;
20
- protected deviceService?: DeviceService;
21
- protected notificationService?: NotificationService;
19
+ static Notification = ClixNotification.shared;
20
+
21
+ storageService?: StorageService;
22
+ eventService?: EventService;
23
+ deviceService?: DeviceService;
24
+ notificationService?: NotificationService;
22
25
 
23
26
  private constructor() {}
24
27
 
@@ -153,7 +156,7 @@ export class Clix {
153
156
  }
154
157
 
155
158
  /**
156
- * Get push token
159
+ * @deprecated Use Clix.Notification.getToken() instead.
157
160
  */
158
161
  static async getPushToken(): Promise<string | undefined> {
159
162
  try {
@@ -179,21 +182,14 @@ export class Clix {
179
182
  /**
180
183
  * Track event
181
184
  */
182
- protected static async trackEvent(
185
+ static async trackEvent(
183
186
  name: string,
184
- options?: {
185
- properties?: Record<string, any>;
186
- messageId?: string;
187
- }
187
+ properties: Record<string, any> = {}
188
188
  ): Promise<void> {
189
189
  try {
190
190
  await Clix.initCoordinator.waitForInitialization();
191
191
  if (this.shared?.eventService) {
192
- await this.shared.eventService.trackEvent(
193
- name,
194
- options?.properties,
195
- options?.messageId
196
- );
192
+ await this.shared.eventService.trackEvent(name, properties);
197
193
  }
198
194
  } catch (error) {
199
195
  ClixLogger.error(`Failed to track event: ${error}`);
@@ -204,12 +200,12 @@ export class Clix {
204
200
  * Set configuration
205
201
  */
206
202
  private async setConfig(config: ClixConfig): Promise<void> {
207
- this.storageService = new StorageService();
203
+ this.storageService = new StorageService(config.projectId);
208
204
 
209
205
  try {
210
- await this.storageService.set('project_id', config.projectId);
211
- await this.storageService.set('api_key', config.apiKey);
212
- await this.storageService.set('clix_config', {
206
+ this.storageService.set('project_id', config.projectId);
207
+ this.storageService.set('api_key', config.apiKey);
208
+ this.storageService.set('clix_config', {
213
209
  projectId: config.projectId,
214
210
  apiKey: config.apiKey,
215
211
  endpoint: config.endpoint,
@@ -0,0 +1,157 @@
1
+ import { type NotificationSettings } from '@notifee/react-native';
2
+ import type {
3
+ BackgroundMessageHandler,
4
+ FcmTokenErrorHandler,
5
+ ForegroundMessageHandler,
6
+ NotificationOpenedHandler,
7
+ } from '../services/NotificationService';
8
+ import { ClixLogger } from '../utils/logging/ClixLogger';
9
+ import { Clix } from './Clix';
10
+
11
+ interface ConfigureOptions {
12
+ /**
13
+ * @default false
14
+ */
15
+ autoRequestPermission?: boolean;
16
+ /**
17
+ * @default true
18
+ */
19
+ autoHandleLandingURL?: boolean;
20
+ }
21
+
22
+ export class ClixNotification {
23
+ static shared: ClixNotification = new ClixNotification();
24
+
25
+ async configure(options: ConfigureOptions = {}) {
26
+ const { autoRequestPermission = false, autoHandleLandingURL = true } =
27
+ options;
28
+
29
+ try {
30
+ await Clix.initCoordinator.waitForInitialization();
31
+ const notificationService = Clix.shared?.notificationService;
32
+ if (!notificationService) {
33
+ ClixLogger.warn('Notification service is not initialized');
34
+ return;
35
+ }
36
+
37
+ notificationService.setAutoHandleLandingUrl(autoHandleLandingURL);
38
+
39
+ if (autoRequestPermission) {
40
+ await notificationService.requestPermission();
41
+ }
42
+ } catch (error) {
43
+ ClixLogger.error('Failed to configure notifications', error);
44
+ }
45
+ }
46
+
47
+ async requestPermission(): Promise<NotificationSettings | null> {
48
+ try {
49
+ 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();
57
+ } catch (error) {
58
+ ClixLogger.error('Failed to request notification permission', error);
59
+ return null;
60
+ }
61
+ }
62
+
63
+ async setPermissionGranted(isGranted: boolean): Promise<void> {
64
+ try {
65
+ 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);
73
+ } catch (error) {
74
+ ClixLogger.error(
75
+ 'Failed to update push permission status on server',
76
+ error
77
+ );
78
+ }
79
+ }
80
+
81
+ async getToken(): Promise<string | undefined> {
82
+ try {
83
+ 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;
92
+ } catch (error) {
93
+ ClixLogger.error('Failed to get push token', error);
94
+ return undefined;
95
+ }
96
+ }
97
+
98
+ async onMessage(handler?: ForegroundMessageHandler): Promise<void> {
99
+ try {
100
+ await Clix.initCoordinator.waitForInitialization();
101
+ const notificationService = Clix.shared?.notificationService;
102
+ if (!notificationService) {
103
+ ClixLogger.warn('Notification service is not initialized');
104
+ return;
105
+ }
106
+ notificationService.setMessageHandler(handler);
107
+ } catch (error) {
108
+ ClixLogger.error('Failed to register onMessage handler', error);
109
+ }
110
+ }
111
+
112
+ async onBackgroundMessage(handler?: BackgroundMessageHandler): Promise<void> {
113
+ try {
114
+ await Clix.initCoordinator.waitForInitialization();
115
+ const notificationService = Clix.shared?.notificationService;
116
+ if (!notificationService) {
117
+ ClixLogger.warn('Notification service is not initialized');
118
+ return;
119
+ }
120
+ notificationService.setBackgroundMessageHandler(handler);
121
+ } catch (error) {
122
+ ClixLogger.error('Failed to register onBackgroundMessage handler', error);
123
+ }
124
+ }
125
+
126
+ async onNotificationOpened(
127
+ handler?: NotificationOpenedHandler
128
+ ): Promise<void> {
129
+ try {
130
+ await Clix.initCoordinator.waitForInitialization();
131
+ const notificationService = Clix.shared?.notificationService;
132
+ if (!notificationService) {
133
+ ClixLogger.warn('Notification service is not initialized');
134
+ return;
135
+ }
136
+ notificationService.setNotificationOpenedHandler(handler);
137
+ } catch (error) {
138
+ ClixLogger.error(
139
+ 'Failed to register onNotificationOpened handler',
140
+ error
141
+ );
142
+ }
143
+ }
144
+ async onFcmTokenError(handler?: FcmTokenErrorHandler): Promise<void> {
145
+ try {
146
+ await Clix.initCoordinator.waitForInitialization();
147
+ const notificationService = Clix.shared?.notificationService;
148
+ if (!notificationService) {
149
+ ClixLogger.warn('Notification service is not initialized');
150
+ return;
151
+ }
152
+ notificationService.setFcmTokenErrorHandler(handler);
153
+ } catch (error) {
154
+ ClixLogger.error('Failed to register onFcmTokenError handler', error);
155
+ }
156
+ }
157
+ }