react-native-edgee 1.0.8 → 1.0.9
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/README.md +1 -1
- package/dist/core/queue.js +22 -9
- package/dist/index.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/core/queue.js
CHANGED
|
@@ -25,8 +25,14 @@ class EventQueue {
|
|
|
25
25
|
this.online = !!state.isConnected && !!state.isInternetReachable;
|
|
26
26
|
});
|
|
27
27
|
void edgee_store_1.edgeeStore.getPendingEvents().then((events) => {
|
|
28
|
-
|
|
28
|
+
// Merge persisted events with any events that were added during initialization
|
|
29
|
+
// to avoid losing events due to race conditions
|
|
30
|
+
const existingEvents = this.q;
|
|
31
|
+
this.q = [...events, ...existingEvents];
|
|
29
32
|
this.ready = true;
|
|
33
|
+
// Trigger flush now that we're ready
|
|
34
|
+
if (this.shouldFlush())
|
|
35
|
+
void this.flush();
|
|
30
36
|
});
|
|
31
37
|
}
|
|
32
38
|
destroy() {
|
|
@@ -41,8 +47,9 @@ class EventQueue {
|
|
|
41
47
|
enqueue(item) {
|
|
42
48
|
this.q.push(item);
|
|
43
49
|
void edgee_store_1.edgeeStore.addEvent(item);
|
|
44
|
-
if (this.shouldFlush())
|
|
50
|
+
if (this.shouldFlush()) {
|
|
45
51
|
void this.flush();
|
|
52
|
+
}
|
|
46
53
|
}
|
|
47
54
|
/**
|
|
48
55
|
* Send a direct payload (used for consent events)
|
|
@@ -66,26 +73,32 @@ class EventQueue {
|
|
|
66
73
|
return this.ready && this.online && this.q.length > 0;
|
|
67
74
|
}
|
|
68
75
|
async flush() {
|
|
69
|
-
if (this.flushing || !this.shouldFlush())
|
|
76
|
+
if (this.flushing || !this.shouldFlush()) {
|
|
70
77
|
return;
|
|
78
|
+
}
|
|
71
79
|
this.flushing = true;
|
|
72
|
-
|
|
80
|
+
// Take items from the queue atomically using splice
|
|
81
|
+
// This prevents losing events that are added during flush
|
|
82
|
+
const itemsToFlush = this.q.splice(0, this.q.length);
|
|
83
|
+
(0, utils_1.log)(this.config, `Flushing ${itemsToFlush.length} event(s)...`);
|
|
73
84
|
try {
|
|
74
|
-
for (const item of
|
|
85
|
+
for (const item of itemsToFlush) {
|
|
75
86
|
await (0, api_1.uploadEvent)(this.config, item);
|
|
87
|
+
(0, utils_1.log)(this.config, `Event sent: ${item.type} - ${item.data.name || 'user'}`);
|
|
76
88
|
}
|
|
77
|
-
|
|
89
|
+
// Only clear persisted events after successful send
|
|
78
90
|
await edgee_store_1.edgeeStore.clearEvents();
|
|
79
91
|
}
|
|
80
92
|
catch (error) {
|
|
81
93
|
(0, utils_1.logError)("Error processing event batch.", error);
|
|
82
|
-
|
|
83
|
-
|
|
94
|
+
// On error, re-add failed items to the front of the queue for retry
|
|
95
|
+
this.q.unshift(...itemsToFlush);
|
|
84
96
|
}
|
|
85
97
|
finally {
|
|
86
98
|
this.flushing = false;
|
|
99
|
+
// Drain any events that were added during flush
|
|
87
100
|
if (this.shouldFlush())
|
|
88
|
-
void this.flush();
|
|
101
|
+
void this.flush();
|
|
89
102
|
}
|
|
90
103
|
}
|
|
91
104
|
}
|
package/dist/index.js
CHANGED
|
@@ -64,6 +64,7 @@ class EdgeeClient {
|
|
|
64
64
|
}
|
|
65
65
|
const event = (0, api_1.createScreenEvent)(restData, components, context);
|
|
66
66
|
this.queue.enqueue(event);
|
|
67
|
+
(0, utils_1.log)(this.config, "SCREEN event queued:", screen_name);
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
69
70
|
* Track a custom event
|
|
@@ -83,6 +84,7 @@ class EdgeeClient {
|
|
|
83
84
|
}
|
|
84
85
|
const event = (0, api_1.createTrackEvent)(restData, components, context);
|
|
85
86
|
this.queue.enqueue(event);
|
|
87
|
+
(0, utils_1.log)(this.config, "TRACK event queued:", data.name);
|
|
86
88
|
}
|
|
87
89
|
/**
|
|
88
90
|
* Track a user event
|
|
@@ -91,6 +93,7 @@ class EdgeeClient {
|
|
|
91
93
|
const context = await (0, context_1.getContext)(this.config);
|
|
92
94
|
const event = (0, api_1.createUserEvent)(data, components, context);
|
|
93
95
|
this.queue.enqueue(event);
|
|
96
|
+
(0, utils_1.log)(this.config, "USER event queued:", data.user_id || data.anonymous_id || "anonymous");
|
|
94
97
|
}
|
|
95
98
|
/**
|
|
96
99
|
* Send consent event directly to Edgee (matches web SDK format)
|