kewa-react-native 1.0.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 (42) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +592 -0
  3. package/lib/KewaProvider.d.ts +26 -0
  4. package/lib/KewaProvider.js +91 -0
  5. package/lib/core/EventManager.d.ts +13 -0
  6. package/lib/core/EventManager.js +129 -0
  7. package/lib/core/KewaAnalytics.d.ts +41 -0
  8. package/lib/core/KewaAnalytics.js +317 -0
  9. package/lib/index.d.ts +23 -0
  10. package/lib/index.js +94 -0
  11. package/lib/types/config.d.ts +32 -0
  12. package/lib/types/config.js +2 -0
  13. package/lib/types/events.d.ts +104 -0
  14. package/lib/types/events.js +2 -0
  15. package/lib/types/index.d.ts +3 -0
  16. package/lib/types/index.js +19 -0
  17. package/lib/types/response.d.ts +15 -0
  18. package/lib/types/response.js +2 -0
  19. package/lib/utils/DeviceInfo.d.ts +4 -0
  20. package/lib/utils/DeviceInfo.js +32 -0
  21. package/lib/utils/NetworkManager.d.ts +17 -0
  22. package/lib/utils/NetworkManager.js +77 -0
  23. package/lib/utils/StorageManager.d.ts +16 -0
  24. package/lib/utils/StorageManager.js +120 -0
  25. package/lib/utils/constants.d.ts +26 -0
  26. package/lib/utils/constants.js +29 -0
  27. package/lib/utils/debug.d.ts +3 -0
  28. package/lib/utils/debug.js +17 -0
  29. package/package.json +59 -0
  30. package/src/KewaProvider.tsx +87 -0
  31. package/src/core/EventManager.ts +160 -0
  32. package/src/core/KewaAnalytics.ts +419 -0
  33. package/src/index.tsx +89 -0
  34. package/src/types/config.ts +33 -0
  35. package/src/types/events.ts +123 -0
  36. package/src/types/index.ts +3 -0
  37. package/src/types/response.ts +16 -0
  38. package/src/utils/DeviceInfo.ts +29 -0
  39. package/src/utils/NetworkManager.ts +85 -0
  40. package/src/utils/StorageManager.ts +121 -0
  41. package/src/utils/constants.ts +26 -0
  42. package/src/utils/debug.ts +15 -0
package/lib/index.js ADDED
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.KewaAutoTracker = exports.KewaTracker = exports.useKewa = exports.KewaProvider = exports.DeviceInfoCollector = exports.KEWA_CONSTANTS = void 0;
18
+ exports.useAutoTracker = useAutoTracker;
19
+ const KewaProvider_1 = require("./KewaProvider");
20
+ Object.defineProperty(exports, "KewaProvider", { enumerable: true, get: function () { return KewaProvider_1.KewaProvider; } });
21
+ Object.defineProperty(exports, "useKewa", { enumerable: true, get: function () { return KewaProvider_1.useKewa; } });
22
+ __exportStar(require("./types"), exports);
23
+ var constants_1 = require("./utils/constants");
24
+ Object.defineProperty(exports, "KEWA_CONSTANTS", { enumerable: true, get: function () { return constants_1.KEWA_CONSTANTS; } });
25
+ var DeviceInfo_1 = require("./utils/DeviceInfo");
26
+ Object.defineProperty(exports, "DeviceInfoCollector", { enumerable: true, get: function () { return DeviceInfo_1.DeviceInfoCollector; } });
27
+ const Kewa = (0, KewaProvider_1.getDefaultKewaInstance)();
28
+ exports.default = Kewa;
29
+ class KewaTracker {
30
+ static setupNavigationTracking(navigationRef) {
31
+ const kewa = (0, KewaProvider_1.getDefaultKewaInstance)();
32
+ const routeNameRef = { current: '' };
33
+ return {
34
+ onReady: () => {
35
+ var _a;
36
+ const currentRoute = (_a = navigationRef.current) === null || _a === void 0 ? void 0 : _a.getCurrentRoute();
37
+ if (currentRoute) {
38
+ routeNameRef.current = currentRoute.name;
39
+ }
40
+ },
41
+ onStateChange: async () => {
42
+ var _a;
43
+ if (!kewa.isAutoScreenViewTrackingEnabled()) {
44
+ return;
45
+ }
46
+ const previousRouteName = routeNameRef.current;
47
+ const currentRoute = (_a = navigationRef.current) === null || _a === void 0 ? void 0 : _a.getCurrentRoute();
48
+ if (currentRoute && previousRouteName !== currentRoute.name) {
49
+ await kewa.trackScreenView(currentRoute.name, {
50
+ previousScreen: previousRouteName,
51
+ params: currentRoute.params,
52
+ });
53
+ routeNameRef.current = currentRoute.name;
54
+ }
55
+ },
56
+ };
57
+ }
58
+ static trackButtonPress(buttonName, additionalData = {}) {
59
+ const kewa = (0, KewaProvider_1.getDefaultKewaInstance)();
60
+ return async () => {
61
+ await kewa.trackEvent('button_press', {
62
+ buttonName,
63
+ ...additionalData,
64
+ });
65
+ };
66
+ }
67
+ static trackFormSubmission(formName, formData = {}) {
68
+ const kewa = (0, KewaProvider_1.getDefaultKewaInstance)();
69
+ return async () => {
70
+ await kewa.trackEvent('form_submit', {
71
+ formName,
72
+ ...formData,
73
+ });
74
+ };
75
+ }
76
+ static trackError(error, context = {}) {
77
+ return (0, KewaProvider_1.getDefaultKewaInstance)().trackError(error, context);
78
+ }
79
+ }
80
+ exports.KewaTracker = KewaTracker;
81
+ exports.KewaAutoTracker = KewaTracker;
82
+ function useAutoTracker() {
83
+ const kewa = (0, KewaProvider_1.useKewa)();
84
+ return {
85
+ setupNavigationTracking: KewaTracker.setupNavigationTracking,
86
+ trackButtonPress: (buttonName, additionalData = {}) => async () => {
87
+ await kewa.trackEvent('button_press', { buttonName, ...additionalData });
88
+ },
89
+ trackFormSubmission: (formName, formData = {}) => async () => {
90
+ await kewa.trackEvent('form_submit', { formName, ...formData });
91
+ },
92
+ trackError: kewa.trackError.bind(kewa),
93
+ };
94
+ }
@@ -0,0 +1,32 @@
1
+ export interface KewaConfig {
2
+ appUrl: string;
3
+ apiKey: string;
4
+ projectId?: string;
5
+ disableTracking?: boolean;
6
+ disableEventTracking?: boolean;
7
+ disableAppStateTracking?: boolean;
8
+ disableScreenViewTracking?: boolean;
9
+ batchSize?: number;
10
+ maxQueueSize?: number;
11
+ enableDebugLogging?: boolean;
12
+ /** @deprecated Use appUrl instead */
13
+ apiUrl?: string;
14
+ }
15
+ export interface DeviceInfo {
16
+ appName: string;
17
+ platform: string;
18
+ userAgent: string;
19
+ platformVersion: string | number;
20
+ appVersion: string;
21
+ deviceName?: string;
22
+ buildNumber?: string;
23
+ deviceModel: string;
24
+ deviceId?: string;
25
+ screenWidth: number;
26
+ screenHeight: number;
27
+ timezone: string;
28
+ carrier?: string;
29
+ isTablet?: boolean;
30
+ brand?: string;
31
+ manufacturer?: string;
32
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,104 @@
1
+ import { DeviceInfo } from "./config";
2
+ export interface BaseEventData {
3
+ timestamp?: string;
4
+ screenName?: string;
5
+ previousScreen?: string;
6
+ [key: string]: any;
7
+ }
8
+ export interface KewaEvent {
9
+ eventName: string;
10
+ eventData: BaseEventData;
11
+ contactData?: ContactData;
12
+ deviceId?: string | null;
13
+ deviceInfo?: DeviceInfo;
14
+ metadata?: EventMetadata;
15
+ timestamp: string;
16
+ }
17
+ export interface ContactData {
18
+ id?: string;
19
+ title?: string;
20
+ firstname?: string;
21
+ lastname?: string;
22
+ company?: string;
23
+ position?: string;
24
+ email?: string;
25
+ mobile?: string;
26
+ phone?: string;
27
+ points?: number;
28
+ fax?: string;
29
+ address1?: string;
30
+ address2?: string;
31
+ city?: string;
32
+ state?: string;
33
+ zipcode?: string;
34
+ country?: string;
35
+ preferred_locale?: string;
36
+ timezone?: string;
37
+ last_active?: string;
38
+ attribution_date?: string;
39
+ attribution?: number;
40
+ website?: string;
41
+ facebook?: string;
42
+ foursquare?: string;
43
+ instagram?: string;
44
+ linkedin?: string;
45
+ skype?: string;
46
+ twitter?: string;
47
+ companyaddress1?: string;
48
+ companyaddress2?: string;
49
+ companyemail?: string;
50
+ companyphone?: string;
51
+ companycity?: string;
52
+ companystate?: string;
53
+ companyzipcode?: string;
54
+ companycountry?: string;
55
+ companyname?: string;
56
+ companywebsite?: string;
57
+ companynumber_of_employees?: number;
58
+ companyfax?: string;
59
+ companyannual_revenue?: number;
60
+ companyindustry?: string;
61
+ companydescription?: string;
62
+ [key: string]: any;
63
+ }
64
+ export interface EventMetadata {
65
+ eventId: string;
66
+ attemptCount?: number;
67
+ queuedAt?: string;
68
+ sentAt?: string;
69
+ }
70
+ export interface AppLaunchEvent extends BaseEventData {
71
+ isFirstLaunch: boolean;
72
+ installSource?: string;
73
+ referrer?: string;
74
+ campaignId?: string;
75
+ }
76
+ export interface UserLoginEvent extends BaseEventData {
77
+ userId: string;
78
+ email?: string;
79
+ loginMethod: 'email' | 'google' | 'facebook' | 'apple' | 'phone' | 'custom';
80
+ }
81
+ export interface UserRegistrationEvent extends BaseEventData {
82
+ userId: string;
83
+ email?: string;
84
+ registrationMethod: 'email' | 'google' | 'facebook' | 'apple' | 'phone';
85
+ }
86
+ export interface ScreenViewEvent extends BaseEventData {
87
+ screenName: string;
88
+ screenClass?: string;
89
+ loadTime?: number;
90
+ }
91
+ export interface ErrorEvent extends BaseEventData {
92
+ errorMessage: string;
93
+ errorStack?: string;
94
+ errorName: string;
95
+ isFatal?: boolean;
96
+ context?: Record<string, any>;
97
+ }
98
+ export interface AppForegroundEvent extends BaseEventData {
99
+ timestamp: string;
100
+ }
101
+ export interface AppBackgroundEvent extends BaseEventData {
102
+ timestamp: string;
103
+ }
104
+ export type PredefinedEvents = AppLaunchEvent | UserLoginEvent | UserRegistrationEvent | ScreenViewEvent | ErrorEvent;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export * from './config';
2
+ export * from './events';
3
+ export * from './response';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./config"), exports);
18
+ __exportStar(require("./events"), exports);
19
+ __exportStar(require("./response"), exports);
@@ -0,0 +1,15 @@
1
+ export interface KewaResponse {
2
+ success: boolean;
3
+ id?: string;
4
+ sid?: string;
5
+ device_id?: string;
6
+ message?: string;
7
+ }
8
+ export interface KewaBatchResponse {
9
+ success: boolean;
10
+ user_id?: string;
11
+ processed_count: number;
12
+ failed_count: number;
13
+ errors?: string[];
14
+ timestamp?: string;
15
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import { DeviceInfo as DeviceInfoType } from '../types';
2
+ export declare class DeviceInfoCollector {
3
+ static collect(): Promise<DeviceInfoType>;
4
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DeviceInfoCollector = void 0;
7
+ const react_native_1 = require("react-native");
8
+ const react_native_device_info_1 = __importDefault(require("react-native-device-info"));
9
+ class DeviceInfoCollector {
10
+ static async collect() {
11
+ const { width, height } = react_native_1.Dimensions.get('window');
12
+ const deviceInfo = {
13
+ appName: react_native_device_info_1.default.getApplicationName(),
14
+ platform: react_native_1.Platform.OS,
15
+ platformVersion: react_native_1.Platform.Version,
16
+ userAgent: await react_native_device_info_1.default.getUserAgent(),
17
+ appVersion: react_native_device_info_1.default.getReadableVersion(),
18
+ buildNumber: react_native_device_info_1.default.getBuildNumber(),
19
+ deviceName: await react_native_device_info_1.default.getDeviceName(),
20
+ deviceModel: react_native_device_info_1.default.getModel(),
21
+ screenWidth: width,
22
+ screenHeight: height,
23
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
24
+ carrier: await react_native_device_info_1.default.getCarrier(),
25
+ brand: react_native_device_info_1.default.getBrand(),
26
+ manufacturer: await react_native_device_info_1.default.getManufacturer(),
27
+ isTablet: react_native_device_info_1.default.isTablet(),
28
+ };
29
+ return deviceInfo;
30
+ }
31
+ }
32
+ exports.DeviceInfoCollector = DeviceInfoCollector;
@@ -0,0 +1,17 @@
1
+ import { ContactData, KewaEvent, KewaResponse } from '../types';
2
+ export declare class NetworkManager {
3
+ private appUrl;
4
+ private apiKey;
5
+ private projectId;
6
+ private isOnline;
7
+ private unsubscribe;
8
+ constructor(appUrl: string, apiKey: string, projectId: string);
9
+ private getTrackUrl;
10
+ private getContactUrl;
11
+ private setupNetworkMonitoring;
12
+ sendEvent(event: KewaEvent): Promise<KewaResponse>;
13
+ updateContact(contact: ContactData): Promise<KewaResponse>;
14
+ private post;
15
+ getNetworkStatus(): boolean;
16
+ cleanup(): void;
17
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NetworkManager = void 0;
7
+ const netinfo_1 = __importDefault(require("@react-native-community/netinfo"));
8
+ const StorageManager_1 = require("./StorageManager");
9
+ class NetworkManager {
10
+ constructor(appUrl, apiKey, projectId) {
11
+ this.appUrl = '';
12
+ this.apiKey = '';
13
+ this.projectId = '';
14
+ this.isOnline = true;
15
+ this.unsubscribe = null;
16
+ this.appUrl = appUrl.replace(/\/$/, '');
17
+ this.apiKey = apiKey;
18
+ this.projectId = projectId;
19
+ this.setupNetworkMonitoring();
20
+ }
21
+ getTrackUrl() {
22
+ return `${this.appUrl}/t/${this.projectId}/mtc/event/track`;
23
+ }
24
+ getContactUrl() {
25
+ return `${this.appUrl}/t/${this.projectId}/mtc`;
26
+ }
27
+ setupNetworkMonitoring() {
28
+ this.unsubscribe = netinfo_1.default.addEventListener(state => {
29
+ var _a;
30
+ this.isOnline = (_a = state.isConnected) !== null && _a !== void 0 ? _a : true;
31
+ });
32
+ }
33
+ async sendEvent(event) {
34
+ const eventPayload = {
35
+ event: event.eventName,
36
+ timestamp: event.timestamp,
37
+ data: event.eventData,
38
+ contact: event.contactData,
39
+ kewa_device_id: event.deviceId,
40
+ device: event.deviceInfo,
41
+ };
42
+ return this.post(this.getTrackUrl(), eventPayload);
43
+ }
44
+ async updateContact(contact) {
45
+ const ktcId = await StorageManager_1.StorageManager.getKtcId();
46
+ const deviceId = await StorageManager_1.StorageManager.getDeviceId();
47
+ return this.post(this.getContactUrl(), { contact, mtc_id: ktcId, kewa_device_id: deviceId });
48
+ }
49
+ async post(url, body) {
50
+ const response = await fetch(url, {
51
+ method: 'POST',
52
+ headers: {
53
+ 'Content-Type': 'application/json',
54
+ 'secret': `${this.apiKey}`,
55
+ 'User-Agent': 'Kewa-SDK/1.0.0',
56
+ },
57
+ body: JSON.stringify(body),
58
+ });
59
+ if (!response.ok) {
60
+ throw new Error(`Kewa Analytics SDK: HTTP error! status: ${response.status}`);
61
+ }
62
+ const responseData = await response.json();
63
+ if (!responseData.success) {
64
+ throw new Error('Kewa Analytics SDK: Responded with an error ' + responseData.message);
65
+ }
66
+ return responseData;
67
+ }
68
+ getNetworkStatus() {
69
+ return this.isOnline;
70
+ }
71
+ cleanup() {
72
+ if (this.unsubscribe) {
73
+ this.unsubscribe();
74
+ }
75
+ }
76
+ }
77
+ exports.NetworkManager = NetworkManager;
@@ -0,0 +1,16 @@
1
+ import { ContactData, KewaEvent } from '../types';
2
+ export declare class StorageManager {
3
+ static getKtcId(): Promise<string | null>;
4
+ static setKtcId(ktcId: string): Promise<void>;
5
+ static removeKtcId(): Promise<void>;
6
+ static getDeviceId(): Promise<string | null>;
7
+ static setDeviceId(deviceId: string): Promise<void>;
8
+ static removeDeviceId(): Promise<void>;
9
+ static getUserProperties(): Promise<ContactData>;
10
+ static setUserProperties(properties: ContactData): Promise<void>;
11
+ static removeUserProperties(): Promise<void>;
12
+ static getQueuedEvents(): Promise<KewaEvent[]>;
13
+ static setQueuedEvents(events: KewaEvent[]): Promise<void>;
14
+ static addQueuedEvent(event: KewaEvent): Promise<void>;
15
+ static clearQueuedEvents(): Promise<void>;
16
+ }
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.StorageManager = void 0;
7
+ const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
8
+ const constants_1 = require("../utils/constants");
9
+ class StorageManager {
10
+ static async getKtcId() {
11
+ try {
12
+ return await async_storage_1.default.getItem(constants_1.KEWA_CONSTANTS.STORAGE_KEYS.KTC_ID);
13
+ }
14
+ catch (error) {
15
+ console.error('Failed to get ktc_id:', error);
16
+ return null;
17
+ }
18
+ }
19
+ static async setKtcId(ktcId) {
20
+ try {
21
+ await async_storage_1.default.setItem(constants_1.KEWA_CONSTANTS.STORAGE_KEYS.KTC_ID, ktcId);
22
+ }
23
+ catch (error) {
24
+ console.error('Failed to set ktc_id:', error);
25
+ }
26
+ }
27
+ static async removeKtcId() {
28
+ try {
29
+ await async_storage_1.default.removeItem(constants_1.KEWA_CONSTANTS.STORAGE_KEYS.KTC_ID);
30
+ }
31
+ catch (error) {
32
+ console.error('Failed to remove ktc_id:', error);
33
+ }
34
+ }
35
+ static async getDeviceId() {
36
+ try {
37
+ return await async_storage_1.default.getItem(constants_1.KEWA_CONSTANTS.STORAGE_KEYS.DEVICE_ID);
38
+ }
39
+ catch (error) {
40
+ console.error('Failed to get device_id:', error);
41
+ return null;
42
+ }
43
+ }
44
+ static async setDeviceId(deviceId) {
45
+ try {
46
+ await async_storage_1.default.setItem(constants_1.KEWA_CONSTANTS.STORAGE_KEYS.DEVICE_ID, deviceId);
47
+ }
48
+ catch (error) {
49
+ console.error('Failed to set device_id:', error);
50
+ }
51
+ }
52
+ static async removeDeviceId() {
53
+ try {
54
+ await async_storage_1.default.removeItem(constants_1.KEWA_CONSTANTS.STORAGE_KEYS.DEVICE_ID);
55
+ }
56
+ catch (error) {
57
+ console.error('Failed to remove device_id:', error);
58
+ }
59
+ }
60
+ static async getUserProperties() {
61
+ try {
62
+ const props = await async_storage_1.default.getItem(constants_1.KEWA_CONSTANTS.STORAGE_KEYS.USER_PROPERTIES);
63
+ return props ? JSON.parse(props) : {};
64
+ }
65
+ catch (error) {
66
+ console.error('Kewa Analytics SDK: Failed to get user properties:', error);
67
+ return {};
68
+ }
69
+ }
70
+ static async setUserProperties(properties) {
71
+ try {
72
+ await async_storage_1.default.setItem(constants_1.KEWA_CONSTANTS.STORAGE_KEYS.USER_PROPERTIES, JSON.stringify(properties));
73
+ }
74
+ catch (error) {
75
+ console.error('Kewa Analytics SDK: Failed to set user properties:', error);
76
+ }
77
+ }
78
+ static async removeUserProperties() {
79
+ try {
80
+ await async_storage_1.default.removeItem(constants_1.KEWA_CONSTANTS.STORAGE_KEYS.USER_PROPERTIES);
81
+ }
82
+ catch (error) {
83
+ console.error('Kewa Analytics SDK: Failed to remove user properties:', error);
84
+ }
85
+ }
86
+ static async getQueuedEvents() {
87
+ try {
88
+ const events = await async_storage_1.default.getItem(constants_1.KEWA_CONSTANTS.STORAGE_KEYS.QUEUED_EVENTS);
89
+ return events ? JSON.parse(events) : [];
90
+ }
91
+ catch (error) {
92
+ console.error('Kewa Analytics SDK: Failed to get queued events:', error);
93
+ return [];
94
+ }
95
+ }
96
+ static async setQueuedEvents(events) {
97
+ try {
98
+ // Limit queue size
99
+ const limitedEvents = events.slice(-constants_1.KEWA_CONSTANTS.DEFAULTS.MAX_QUEUE_SIZE);
100
+ await async_storage_1.default.setItem(constants_1.KEWA_CONSTANTS.STORAGE_KEYS.QUEUED_EVENTS, JSON.stringify(limitedEvents));
101
+ }
102
+ catch (error) {
103
+ console.error('Kewa Analytics SDK: Failed to set queued events:', error);
104
+ }
105
+ }
106
+ static async addQueuedEvent(event) {
107
+ const events = await this.getQueuedEvents();
108
+ events.push(event);
109
+ await this.setQueuedEvents(events);
110
+ }
111
+ static async clearQueuedEvents() {
112
+ try {
113
+ await async_storage_1.default.removeItem(constants_1.KEWA_CONSTANTS.STORAGE_KEYS.QUEUED_EVENTS);
114
+ }
115
+ catch (error) {
116
+ console.error('Kewa Analytics SDK: Failed to clear queued events:', error);
117
+ }
118
+ }
119
+ }
120
+ exports.StorageManager = StorageManager;
@@ -0,0 +1,26 @@
1
+ export declare const KEWA_CONSTANTS: {
2
+ readonly STORAGE_KEYS: {
3
+ readonly KTC_ID: "kewa_ktc_id";
4
+ readonly DEVICE_ID: "kewa_device_id";
5
+ readonly QUEUED_EVENTS: "kewa_queued_events";
6
+ readonly USER_PROPERTIES: "kewa_user_properties";
7
+ };
8
+ readonly EVENTS: {
9
+ readonly APP_LAUNCH: "app_launch";
10
+ readonly APP_FOREGROUND: "app_foreground";
11
+ readonly APP_BACKGROUND: "app_background";
12
+ readonly USER_LOGIN: "user_login";
13
+ readonly USER_LOGOUT: "user_logout";
14
+ readonly USER_REGISTRATION: "user_registration";
15
+ readonly SCREEN_VIEW: "screen_view";
16
+ readonly ERROR: "error";
17
+ readonly BUTTON_PRESS: "button_press";
18
+ readonly FORM_SUBMIT: "form_submit";
19
+ };
20
+ readonly DEFAULTS: {
21
+ readonly BATCH_SIZE: 10;
22
+ readonly MAX_QUEUE_SIZE: 100;
23
+ readonly RETRY_ATTEMPTS: 3;
24
+ readonly RETRY_DELAY_MS: 1000;
25
+ };
26
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KEWA_CONSTANTS = void 0;
4
+ exports.KEWA_CONSTANTS = {
5
+ STORAGE_KEYS: {
6
+ KTC_ID: 'kewa_ktc_id',
7
+ DEVICE_ID: 'kewa_device_id',
8
+ QUEUED_EVENTS: 'kewa_queued_events',
9
+ USER_PROPERTIES: 'kewa_user_properties',
10
+ },
11
+ EVENTS: {
12
+ APP_LAUNCH: 'app_launch',
13
+ APP_FOREGROUND: 'app_foreground',
14
+ APP_BACKGROUND: 'app_background',
15
+ USER_LOGIN: 'user_login',
16
+ USER_LOGOUT: 'user_logout',
17
+ USER_REGISTRATION: 'user_registration',
18
+ SCREEN_VIEW: 'screen_view',
19
+ ERROR: 'error',
20
+ BUTTON_PRESS: 'button_press',
21
+ FORM_SUBMIT: 'form_submit',
22
+ },
23
+ DEFAULTS: {
24
+ BATCH_SIZE: 10,
25
+ MAX_QUEUE_SIZE: 100,
26
+ RETRY_ATTEMPTS: 3,
27
+ RETRY_DELAY_MS: 1000,
28
+ },
29
+ };
@@ -0,0 +1,3 @@
1
+ export declare function setDebugLogging(enabled: boolean): void;
2
+ export declare function isDebugLoggingEnabled(): boolean;
3
+ export declare function kewaDebug(...args: unknown[]): void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setDebugLogging = setDebugLogging;
4
+ exports.isDebugLoggingEnabled = isDebugLoggingEnabled;
5
+ exports.kewaDebug = kewaDebug;
6
+ let debugEnabled = false;
7
+ function setDebugLogging(enabled) {
8
+ debugEnabled = enabled;
9
+ }
10
+ function isDebugLoggingEnabled() {
11
+ return debugEnabled;
12
+ }
13
+ function kewaDebug(...args) {
14
+ if (debugEnabled) {
15
+ console.log('[Kewa]', ...args);
16
+ }
17
+ }