react-native-edgee 1.0.9 → 1.0.10

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/dist/api.d.ts CHANGED
@@ -27,6 +27,12 @@ export type EdgeeEvent = {
27
27
  components: Record<string, boolean> | undefined;
28
28
  context: EdgeeFullContext;
29
29
  };
30
+ export type ConsentEvent = {
31
+ type: "consent";
32
+ status: "granted" | "denied" | "pending";
33
+ };
34
+ export type QueueItem = EdgeeEvent | ConsentEvent;
35
+ export declare const isConsentEvent: (item: QueueItem) => item is ConsentEvent;
30
36
  export declare const createScreenEvent: (data: EdgeeScreenEvent, components: Record<string, boolean> | undefined, context: EdgeeFullContext) => EdgeeEvent;
31
37
  export declare const createTrackEvent: (data: EdgeeTrackEvent, components: Record<string, boolean> | undefined, context: EdgeeFullContext) => EdgeeEvent;
32
38
  export declare const createUserEvent: (data: EdgeeUserEvent, components: Record<string, boolean> | undefined, context: EdgeeFullContext) => EdgeeEvent;
@@ -38,4 +44,12 @@ export declare const sendPayload: (config: EdgeeConfig, payload: any) => Promise
38
44
  * Sends an event to the Edgee API
39
45
  */
40
46
  export declare const uploadEvent: (config: EdgeeConfig, event: EdgeeEvent) => Promise<void>;
47
+ /**
48
+ * Sends a consent event to the Edgee API
49
+ */
50
+ export declare const uploadConsent: (config: EdgeeConfig, consent: ConsentEvent) => Promise<void>;
51
+ /**
52
+ * Creates a consent event
53
+ */
54
+ export declare const createConsentEvent: (status: "granted" | "denied" | "pending") => ConsentEvent;
41
55
  export {};
package/dist/api.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uploadEvent = exports.sendPayload = exports.createUserEvent = exports.createTrackEvent = exports.createScreenEvent = void 0;
3
+ exports.createConsentEvent = exports.uploadConsent = exports.uploadEvent = exports.sendPayload = exports.createUserEvent = exports.createTrackEvent = exports.createScreenEvent = exports.isConsentEvent = void 0;
4
4
  const edgee_store_1 = require("./core/edgee-store");
5
5
  const utils_1 = require("./core/utils");
6
6
  var EventType;
@@ -9,6 +9,11 @@ var EventType;
9
9
  EventType["User"] = "user";
10
10
  EventType["Screen"] = "screen";
11
11
  })(EventType || (EventType = {}));
12
+ // Type guard to check if item is a consent event
13
+ const isConsentEvent = (item) => {
14
+ return item.type === "consent";
15
+ };
16
+ exports.isConsentEvent = isConsentEvent;
12
17
  const createScreenEvent = (data, components, context) => {
13
18
  return {
14
19
  type: EventType.Track,
@@ -129,6 +134,29 @@ const uploadEvent = async (config, event) => {
129
134
  return;
130
135
  };
131
136
  exports.uploadEvent = uploadEvent;
137
+ /**
138
+ * Sends a consent event to the Edgee API
139
+ */
140
+ const uploadConsent = async (config, consent) => {
141
+ const payload = {
142
+ data_collection: {
143
+ consent: consent.status,
144
+ },
145
+ };
146
+ await (0, exports.sendPayload)(config, payload);
147
+ return;
148
+ };
149
+ exports.uploadConsent = uploadConsent;
150
+ /**
151
+ * Creates a consent event
152
+ */
153
+ const createConsentEvent = (status) => {
154
+ return {
155
+ type: "consent",
156
+ status,
157
+ };
158
+ };
159
+ exports.createConsentEvent = createConsentEvent;
132
160
  /**
133
161
  * Handles response data: stores IDs, handles cookies, and logs events
134
162
  * Similar to the JS SDK handleResponse function
@@ -1,8 +1,8 @@
1
- import { EdgeeEvent } from "../api";
1
+ import { QueueItem } from "../api";
2
2
  export declare class EdgeeStore {
3
3
  edgeeId: string | null;
4
4
  userId: string | null;
5
- pendingEvents: EdgeeEvent[];
5
+ pendingEvents: QueueItem[];
6
6
  initialized: boolean;
7
7
  constructor();
8
8
  init(): Promise<void>;
@@ -14,8 +14,8 @@ export declare class EdgeeStore {
14
14
  edgeeId: string | null;
15
15
  userId: string | null;
16
16
  }>;
17
- addEvent(event: EdgeeEvent): Promise<void>;
18
- getPendingEvents(): Promise<EdgeeEvent[]>;
17
+ addEvent(event: QueueItem): Promise<void>;
18
+ getPendingEvents(): Promise<QueueItem[]>;
19
19
  clearEvents(): Promise<void>;
20
20
  reset(): Promise<void>;
21
21
  }
@@ -1,5 +1,5 @@
1
1
  import { EdgeeConfig } from "..";
2
- import { EdgeeEvent } from "../api";
2
+ import { QueueItem } from "../api";
3
3
  export declare class EventQueue {
4
4
  private config;
5
5
  private q;
@@ -10,12 +10,7 @@ export declare class EventQueue {
10
10
  constructor(config: EdgeeConfig);
11
11
  destroy(): void;
12
12
  setReady(val: boolean): void;
13
- enqueue(item: EdgeeEvent): void;
14
- /**
15
- * Send a direct payload (used for consent events)
16
- * This bypasses the normal event structure and sends raw payload
17
- */
18
- sendEvent(payload: any): Promise<void>;
13
+ enqueue(item: QueueItem): void;
19
14
  private shouldFlush;
20
15
  flush(): Promise<void>;
21
16
  }
@@ -51,24 +51,6 @@ class EventQueue {
51
51
  void this.flush();
52
52
  }
53
53
  }
54
- /**
55
- * Send a direct payload (used for consent events)
56
- * This bypasses the normal event structure and sends raw payload
57
- */
58
- async sendEvent(payload) {
59
- if (!this.online) {
60
- // For direct payloads, we can't easily queue them in the current structure
61
- // So we'll send them when we come back online
62
- return;
63
- }
64
- try {
65
- await (0, api_1.sendPayload)(this.config, payload);
66
- }
67
- catch (error) {
68
- (0, utils_1.logError)("[Queue] Error sending event.", error);
69
- throw error;
70
- }
71
- }
72
54
  shouldFlush() {
73
55
  return this.ready && this.online && this.q.length > 0;
74
56
  }
@@ -83,8 +65,14 @@ class EventQueue {
83
65
  (0, utils_1.log)(this.config, `Flushing ${itemsToFlush.length} event(s)...`);
84
66
  try {
85
67
  for (const item of itemsToFlush) {
86
- await (0, api_1.uploadEvent)(this.config, item);
87
- (0, utils_1.log)(this.config, `Event sent: ${item.type} - ${item.data.name || 'user'}`);
68
+ if ((0, api_1.isConsentEvent)(item)) {
69
+ await (0, api_1.uploadConsent)(this.config, item);
70
+ (0, utils_1.log)(this.config, `Consent sent: ${item.status}`);
71
+ }
72
+ else {
73
+ await (0, api_1.uploadEvent)(this.config, item);
74
+ (0, utils_1.log)(this.config, `Event sent: ${item.type} - ${item.data.name || "user"}`);
75
+ }
88
76
  }
89
77
  // Only clear persisted events after successful send
90
78
  await edgee_store_1.edgeeStore.clearEvents();
package/dist/index.d.ts CHANGED
@@ -27,7 +27,7 @@ export declare class EdgeeClient {
27
27
  */
28
28
  user(data: EdgeeUserEvent, components?: Components): Promise<void>;
29
29
  /**
30
- * Send consent event directly to Edgee (matches web SDK format)
30
+ * Send consent event to Edgee (queued like other events)
31
31
  */
32
32
  consent(status: ConsentStatus): Promise<void>;
33
33
  setConsent(status: ConsentStatus): Promise<void>;
package/dist/index.js CHANGED
@@ -96,7 +96,7 @@ class EdgeeClient {
96
96
  (0, utils_1.log)(this.config, "USER event queued:", data.user_id || data.anonymous_id || "anonymous");
97
97
  }
98
98
  /**
99
- * Send consent event directly to Edgee (matches web SDK format)
99
+ * Send consent event to Edgee (queued like other events)
100
100
  */
101
101
  async consent(status) {
102
102
  // Validate consent status
@@ -106,20 +106,10 @@ class EdgeeClient {
106
106
  }
107
107
  // Store consent locally
108
108
  await consent_1.edgeeConsent.setConsent(status);
109
- // Send consent event using web SDK format
110
- const payload = {
111
- data_collection: {
112
- consent: status,
113
- },
114
- };
115
- try {
116
- await this.queue.sendEvent(payload);
117
- (0, utils_1.log)(this.config, "- Consent set to:", status);
118
- }
119
- catch (error) {
120
- (0, utils_1.logError)("Error collecting consent event", error);
121
- throw error;
122
- }
109
+ // Queue consent event (will be sent when online)
110
+ const event = (0, api_1.createConsentEvent)(status);
111
+ this.queue.enqueue(event);
112
+ (0, utils_1.log)(this.config, "- Consent queued:", status);
123
113
  }
124
114
  // Consent management methods
125
115
  async setConsent(status) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-edgee",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Lightweight Edgee data collection client for React Native with native context collection.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",