react-native-edgee 1.0.5 → 1.0.6

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.
@@ -3,20 +3,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.EdgeeStore = void 0;
6
+ exports.edgeeStore = exports.EdgeeStore = void 0;
7
7
  const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
8
+ const utils_1 = require("./utils");
9
+ const STORAGE_KEYS = {
10
+ edgeeId: "_edgee",
11
+ userId: "_edgee_u",
12
+ pendingEvents: "_edgee_events",
13
+ };
8
14
  class EdgeeStore {
9
15
  constructor() {
10
- this.store = async_storage_1.default;
11
16
  this.pendingEvents = [];
17
+ this.initialized = false;
12
18
  this.edgeeId = null;
13
19
  this.userId = null;
14
20
  }
15
21
  async init() {
16
- var _a, _b, _c;
17
- this.edgeeId = (_a = (await this.store.getItem("_edgee"))) !== null && _a !== void 0 ? _a : "";
18
- this.userId = (_b = (await this.store.getItem("_edgee_u"))) !== null && _b !== void 0 ? _b : "";
19
- this.pendingEvents = JSON.parse((_c = (await this.store.getItem("_edgee_events"))) !== null && _c !== void 0 ? _c : "[]");
22
+ // Prevent multiple initializations
23
+ if (this.initialized) {
24
+ return;
25
+ }
26
+ try {
27
+ const storedEdgeeId = await async_storage_1.default.getItem(STORAGE_KEYS.edgeeId);
28
+ const storedUserId = await async_storage_1.default.getItem(STORAGE_KEYS.userId);
29
+ const pendingEvents = await async_storage_1.default.getItem(STORAGE_KEYS.pendingEvents);
30
+ // Only set if values exist (not null/empty)
31
+ this.edgeeId = storedEdgeeId && storedEdgeeId !== "" ? storedEdgeeId : null;
32
+ this.userId = storedUserId && storedUserId !== "" ? storedUserId : null;
33
+ this.pendingEvents = pendingEvents ? JSON.parse(pendingEvents) : [];
34
+ this.initialized = true;
35
+ }
36
+ catch (error) {
37
+ (0, utils_1.logError)("Failed to initialize Edgee store", error);
38
+ this.initialized = true;
39
+ }
20
40
  }
21
41
  async getEdgeeId() {
22
42
  return this.edgeeId;
@@ -25,12 +45,16 @@ class EdgeeStore {
25
45
  return this.userId;
26
46
  }
27
47
  async setEdgeeId(edgeeId) {
28
- this.edgeeId = edgeeId;
29
- await this.store.setItem("_edgee", edgeeId);
48
+ if (edgeeId && edgeeId !== "") {
49
+ this.edgeeId = edgeeId;
50
+ await async_storage_1.default.setItem(STORAGE_KEYS.edgeeId, edgeeId);
51
+ }
30
52
  }
31
53
  async setUserId(userId) {
32
- this.userId = userId;
33
- await this.store.setItem("_edgee_u", userId);
54
+ if (userId && userId !== "") {
55
+ this.userId = userId;
56
+ await async_storage_1.default.setItem(STORAGE_KEYS.userId, userId);
57
+ }
34
58
  }
35
59
  async getContext() {
36
60
  return {
@@ -40,14 +64,19 @@ class EdgeeStore {
40
64
  }
41
65
  async addEvent(event) {
42
66
  this.pendingEvents.push(event);
43
- await this.store.setItem("_edgee_events", JSON.stringify(this.pendingEvents));
67
+ await async_storage_1.default.setItem(STORAGE_KEYS.pendingEvents, JSON.stringify(this.pendingEvents));
44
68
  }
45
69
  async getPendingEvents() {
46
70
  return this.pendingEvents;
47
71
  }
48
72
  async clearEvents() {
49
73
  this.pendingEvents = [];
50
- await this.store.removeItem("_edgee_events");
74
+ await async_storage_1.default.removeItem(STORAGE_KEYS.pendingEvents);
51
75
  }
52
76
  }
53
77
  exports.EdgeeStore = EdgeeStore;
78
+ /**
79
+ * Global edgee store instance
80
+ * This allows you to manage the edgee store across your app without passing it around
81
+ */
82
+ exports.edgeeStore = new EdgeeStore();
@@ -1,17 +1,13 @@
1
1
  import { EdgeeConfig } from "..";
2
2
  import { EdgeeEvent } from "../api";
3
- import { EdgeeStore } from "./edgee-store";
4
- import { QueryBuilder } from "./query-builder";
5
3
  export declare class EventQueue {
6
- private store;
7
- private queryBuilder;
8
4
  private config;
9
5
  private q;
10
6
  private ready;
11
7
  private online;
12
8
  private flushing;
13
9
  private unsubscribe?;
14
- constructor(store: EdgeeStore, config: EdgeeConfig, queryBuilder: QueryBuilder);
10
+ constructor(config: EdgeeConfig);
15
11
  destroy(): void;
16
12
  setReady(val: boolean): void;
17
13
  enqueue(item: EdgeeEvent): void;
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.EventQueue = void 0;
7
7
  const netinfo_1 = __importDefault(require("@react-native-community/netinfo"));
8
8
  const api_1 = require("../api");
9
+ const edgee_store_1 = require("./edgee-store");
10
+ const utils_1 = require("./utils");
9
11
  class EventQueue {
10
- constructor(store, config, queryBuilder) {
12
+ constructor(config) {
11
13
  this.q = [];
12
14
  this.ready = false;
13
15
  this.online = false;
14
16
  this.flushing = false;
15
- this.store = store;
16
17
  this.config = config;
17
- this.queryBuilder = queryBuilder;
18
18
  // Track connectivity
19
19
  this.unsubscribe = netinfo_1.default.addEventListener((state) => {
20
20
  this.online = !!state.isConnected && !!state.isInternetReachable;
@@ -24,7 +24,7 @@ class EventQueue {
24
24
  void netinfo_1.default.fetch().then((state) => {
25
25
  this.online = !!state.isConnected && !!state.isInternetReachable;
26
26
  });
27
- void this.store.getPendingEvents().then((events) => {
27
+ void edgee_store_1.edgeeStore.getPendingEvents().then((events) => {
28
28
  this.q = events;
29
29
  this.ready = true;
30
30
  });
@@ -40,11 +40,7 @@ class EventQueue {
40
40
  }
41
41
  enqueue(item) {
42
42
  this.q.push(item);
43
- if (this.config.debug) {
44
- // eslint-disable-next-line no-console
45
- console.log("[Edgee RN] enqueue", item);
46
- }
47
- void this.store.addEvent(item);
43
+ void edgee_store_1.edgeeStore.addEvent(item);
48
44
  if (this.shouldFlush())
49
45
  void this.flush();
50
46
  }
@@ -54,51 +50,15 @@ class EventQueue {
54
50
  */
55
51
  async sendEvent(payload) {
56
52
  if (!this.online) {
57
- if (this.config.debug) {
58
- console.log("[Edgee RN] Offline - queuing direct payload");
59
- }
60
53
  // For direct payloads, we can't easily queue them in the current structure
61
54
  // So we'll send them when we come back online
62
55
  return;
63
56
  }
64
57
  try {
65
- const url = await this.queryBuilder.getUrl();
66
- if (this.config.debug) {
67
- console.log("[Edgee RN] sending direct payload", { url, payload });
68
- }
69
- const response = await fetch(url, {
70
- method: "POST",
71
- headers: {
72
- "Content-Type": "application/json",
73
- ...(this.config.debug ? { "Edgee-Debug": "true" } : {}),
74
- },
75
- body: JSON.stringify(payload),
76
- });
77
- const text = await response.text().catch(() => "");
78
- if (this.config.debug) {
79
- console.log("[Edgee RN] direct payload response", {
80
- status: response.status,
81
- ok: response.ok,
82
- body: text,
83
- });
84
- }
85
- // Handle ID updates from response
86
- try {
87
- const data = text ? JSON.parse(text) : null;
88
- if (data && (data.e || data.u)) {
89
- if (data.e)
90
- await this.store.setEdgeeId(data.e);
91
- if (data.u)
92
- await this.store.setUserId(data.u);
93
- }
94
- }
95
- catch (e) {
96
- if (this.config.debug)
97
- console.log("persist ids error", e);
98
- }
58
+ await (0, api_1.sendPayload)(this.config, payload);
99
59
  }
100
60
  catch (error) {
101
- console.warn("[Edgee RN] Failed to send direct payload:", error);
61
+ (0, utils_1.logError)("[Queue] Error sending event.", error);
102
62
  throw error;
103
63
  }
104
64
  }
@@ -112,38 +72,15 @@ class EventQueue {
112
72
  const items = [...this.q];
113
73
  try {
114
74
  for (const item of items) {
115
- const url = await this.queryBuilder.getUrl();
116
- const resp = await (0, api_1.uploadEvent)(url, this.config, item);
117
- const text = await resp.text().catch(() => "");
118
- if (this.config.debug) {
119
- // eslint-disable-next-line no-console
120
- console.log("[Edgee RN] response", {
121
- status: resp.status,
122
- ok: resp.ok,
123
- body: text,
124
- });
125
- }
126
- try {
127
- const data = text ? JSON.parse(text) : null;
128
- if (data && (data.e || data.u)) {
129
- if (data.e)
130
- await this.store.setEdgeeId(data.e);
131
- if (data.u)
132
- await this.store.setUserId(data.u);
133
- }
134
- }
135
- catch (e) {
136
- if (this.config.debug)
137
- console.log("persist ids error", e);
138
- }
75
+ await (0, api_1.uploadEvent)(this.config, item);
139
76
  }
140
77
  this.q = [];
141
- await this.store.clearEvents();
78
+ await edgee_store_1.edgeeStore.clearEvents();
142
79
  }
143
80
  catch (error) {
144
- console.log("flush error", error);
81
+ (0, utils_1.logError)("Error processing event batch.", error);
145
82
  this.q = [];
146
- await this.store.clearEvents();
83
+ await edgee_store_1.edgeeStore.clearEvents();
147
84
  }
148
85
  finally {
149
86
  this.flushing = false;
@@ -0,0 +1,17 @@
1
+ import { EdgeeConfig } from "..";
2
+ /**
3
+ * Check if debug mode is enabled
4
+ */
5
+ export declare const hasDebug: (config?: EdgeeConfig | null) => boolean;
6
+ /**
7
+ * Log function matching JS SDK style
8
+ * Uses styled console.log with EDGEE prefix
9
+ * In React Native, we use a consistent prefix format since CSS styling isn't available
10
+ * Formats all arguments into a single string for Metro CLI compatibility
11
+ */
12
+ export declare const log: (config: EdgeeConfig | null | undefined, ...data: any[]) => void;
13
+ /**
14
+ * Log error function matching JS SDK style
15
+ * Uses styled console.error with EDGEE prefix
16
+ */
17
+ export declare const logError: (...data: any[]) => void;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logError = exports.log = exports.hasDebug = void 0;
4
+ /**
5
+ * Check if debug mode is enabled
6
+ */
7
+ const hasDebug = (config) => {
8
+ return (config === null || config === void 0 ? void 0 : config.debug) === true;
9
+ };
10
+ exports.hasDebug = hasDebug;
11
+ /**
12
+ * Format data array into a single string for Metro CLI compatibility
13
+ */
14
+ const formatLogData = (...data) => {
15
+ return data
16
+ .map((item) => {
17
+ if (item === null)
18
+ return "null";
19
+ if (item === undefined)
20
+ return "undefined";
21
+ if (typeof item === "string")
22
+ return item;
23
+ if (typeof item === "object") {
24
+ try {
25
+ return JSON.stringify(item, null, 2);
26
+ }
27
+ catch {
28
+ return String(item);
29
+ }
30
+ }
31
+ return String(item);
32
+ })
33
+ .join(" ");
34
+ };
35
+ /**
36
+ * Log function matching JS SDK style
37
+ * Uses styled console.log with EDGEE prefix
38
+ * In React Native, we use a consistent prefix format since CSS styling isn't available
39
+ * Formats all arguments into a single string for Metro CLI compatibility
40
+ */
41
+ const log = (config, ...data) => {
42
+ if (console && typeof console.log === "function" && (0, exports.hasDebug)(config)) {
43
+ console.log(`[EDGEE] ${formatLogData(...data)}`);
44
+ }
45
+ };
46
+ exports.log = log;
47
+ /**
48
+ * Log error function matching JS SDK style
49
+ * Uses styled console.error with EDGEE prefix
50
+ */
51
+ const logError = (...data) => {
52
+ console.error("[EDGEE]", ...data);
53
+ };
54
+ exports.logError = logError;
package/dist/index.d.ts CHANGED
@@ -1,36 +1,42 @@
1
- export type ConsentStatus = "granted" | "denied" | "pending";
1
+ import { ConsentStatus } from "./consent";
2
2
  export type EdgeeConfig = {
3
3
  host: string;
4
4
  debug?: boolean;
5
5
  collectDeviceId?: boolean;
6
+ cookieName?: string;
6
7
  };
7
8
  type Components = Record<string, boolean> | undefined;
8
9
  export declare class EdgeeClient {
9
10
  private appState;
10
- private store;
11
11
  private queue;
12
- private queryBuilder;
13
12
  private appStateSubscription;
14
13
  private config;
15
14
  constructor(config: EdgeeConfig);
16
15
  private handleAppStateChange;
16
+ /**
17
+ * Track a screen view event
18
+ */
19
+ screen(screenName: string, data: object, components?: Components): Promise<void>;
20
+ /**
21
+ * Track a custom event
22
+ */
17
23
  track(name: string, data: object, components?: Components): Promise<void>;
24
+ /**
25
+ * Track a user event
26
+ */
18
27
  user(data: object, components?: Components): Promise<void>;
19
- screen(screenName: string, data: object, components?: Components): Promise<void>;
28
+ /**
29
+ * Send consent event directly to Edgee (matches web SDK format)
30
+ */
31
+ consent(status: ConsentStatus): Promise<void>;
20
32
  setConsent(status: ConsentStatus): Promise<void>;
21
33
  getConsent(): ConsentStatus | null;
22
34
  hasConsent(): boolean;
23
- canTrack(): boolean;
24
35
  resetConsent(): Promise<void>;
25
36
  onConsentChange(callback: (status: ConsentStatus | null) => void): () => void;
26
- /**
27
- * Send consent event directly to Edgee (matches web SDK format)
28
- */
29
- consent(status: ConsentStatus): Promise<void>;
30
37
  }
31
- export * as navigation from "./navigation";
32
- export { EdgeeAutoTracker, EdgeeProvider, useEdgee, useEdgeeConsent, } from "./react";
38
+ export { EdgeeProvider, useEdgee, } from "./react";
33
39
  export type { EdgeeClientContext, EdgeeFullContext, EdgeePageContext, } from "./core/context";
34
40
  export { clearContextCache, getNativeContext, isNativeModuleAvailable, } from "./native-context";
35
41
  export type { EdgeeNativeContext, EdgeeNativeContextConfig, EdgeeReactNativeModule, } from "./types";
36
- export { ConsentUtils, EdgeeConsent, edgeeConsent } from "./consent";
42
+ export type { ConsentStatus, } from "./consent";
package/dist/index.js CHANGED
@@ -1,47 +1,15 @@
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.edgeeConsent = exports.EdgeeConsent = exports.ConsentUtils = exports.isNativeModuleAvailable = exports.getNativeContext = exports.clearContextCache = exports.useEdgeeConsent = exports.useEdgee = exports.EdgeeProvider = exports.EdgeeAutoTracker = exports.navigation = exports.EdgeeClient = void 0;
3
+ exports.isNativeModuleAvailable = exports.getNativeContext = exports.clearContextCache = exports.useEdgee = exports.EdgeeProvider = exports.EdgeeClient = void 0;
37
4
  const react_native_1 = require("react-native");
38
5
  const api_1 = require("./api");
39
6
  const consent_1 = require("./consent");
40
7
  const context_1 = require("./core/context");
41
8
  const edgee_store_1 = require("./core/edgee-store");
42
- const query_builder_1 = require("./core/query-builder");
43
9
  const queue_1 = require("./core/queue");
10
+ const utils_1 = require("./core/utils");
44
11
  const native_context_1 = require("./native-context");
12
+ const DEFAULT_COOKIE_NAME = "edgee";
45
13
  /**
46
14
  * Extract native context properties to include in event data under a sub-object
47
15
  */
@@ -103,12 +71,6 @@ const extractNativeProperties = (nativeContext) => {
103
71
  },
104
72
  };
105
73
  };
106
- let initialized = false;
107
- let config = null;
108
- const STORAGE_KEYS = {
109
- edgeeId: "_edgee",
110
- userId: "_edgee_u",
111
- };
112
74
  class EdgeeClient {
113
75
  constructor(config) {
114
76
  // current app state
@@ -128,17 +90,26 @@ class EdgeeClient {
128
90
  }
129
91
  this.appState = nextAppState;
130
92
  };
93
+ if (!config.cookieName) {
94
+ config.cookieName = DEFAULT_COOKIE_NAME;
95
+ }
96
+ // Initialize consent system
97
+ void consent_1.edgeeConsent.init();
98
+ void edgee_store_1.edgeeStore.init();
99
+ // Initialize queue
131
100
  this.config = config;
132
- this.store = new edgee_store_1.EdgeeStore();
133
- void this.store.init();
134
- this.queryBuilder = new query_builder_1.QueryBuilder(config, this.store);
135
- this.queue = new queue_1.EventQueue(this.store, config, this.queryBuilder);
101
+ this.queue = new queue_1.EventQueue(config);
136
102
  this.appStateSubscription = react_native_1.AppState.addEventListener("change", this.handleAppStateChange);
137
- // Initialize consent system
138
- void consent_1.ConsentUtils.init();
103
+ // Log initialization (matching JS SDK)
104
+ if (this.config.debug) {
105
+ (0, utils_1.log)(this.config, "Edgee SDK initialized with debug mode");
106
+ }
139
107
  }
140
- async track(name, data, components) {
141
- const context = await (0, context_1.getContext)(this.config.collectDeviceId);
108
+ /**
109
+ * Track a screen view event
110
+ */
111
+ async screen(screenName, data, components) {
112
+ const context = await (0, context_1.getContext)(this.config);
142
113
  // Get native context properties if available and collectDeviceId is enabled
143
114
  let nativeProperties = {};
144
115
  if (this.config.collectDeviceId && (0, native_context_1.isNativeModuleAvailable)()) {
@@ -149,26 +120,28 @@ class EdgeeClient {
149
120
  nativeProperties = extractNativeProperties(nativeContext);
150
121
  }
151
122
  catch (error) {
152
- if (this.config.debug) {
153
- console.warn("[Edgee] Failed to get native context for event properties:", error);
154
- }
123
+ (0, utils_1.logError)("Error collecting page event", error);
155
124
  }
156
125
  }
157
- // Merge native properties with event data
126
+ // Merge native properties with screen data
158
127
  const enhancedData = {
159
128
  ...data,
129
+ screen_name: screenName,
160
130
  ...nativeProperties,
161
131
  };
162
132
  const event = (0, api_1.createTrackEvent)({
163
- name,
133
+ name: "screen",
164
134
  data: enhancedData,
165
135
  components,
166
136
  context,
167
137
  });
168
138
  this.queue.enqueue(event);
169
139
  }
170
- async user(data, components) {
171
- const context = await (0, context_1.getContext)(this.config.collectDeviceId);
140
+ /**
141
+ * Track a custom event
142
+ */
143
+ async track(name, data, components) {
144
+ const context = await (0, context_1.getContext)(this.config);
172
145
  // Get native context properties if available and collectDeviceId is enabled
173
146
  let nativeProperties = {};
174
147
  if (this.config.collectDeviceId && (0, native_context_1.isNativeModuleAvailable)()) {
@@ -179,25 +152,27 @@ class EdgeeClient {
179
152
  nativeProperties = extractNativeProperties(nativeContext);
180
153
  }
181
154
  catch (error) {
182
- if (this.config.debug) {
183
- console.warn("[Edgee] Failed to get native context for user properties:", error);
184
- }
155
+ (0, utils_1.logError)("Error collecting track event", error);
185
156
  }
186
157
  }
187
- // Merge native properties with user data
158
+ // Merge native properties with event data
188
159
  const enhancedData = {
189
160
  ...data,
190
161
  ...nativeProperties,
191
162
  };
192
- const event = (0, api_1.createUserEvent)({
163
+ const event = (0, api_1.createTrackEvent)({
164
+ name,
193
165
  data: enhancedData,
194
166
  components,
195
167
  context,
196
168
  });
197
169
  this.queue.enqueue(event);
198
170
  }
199
- async screen(screenName, data, components) {
200
- const context = await (0, context_1.getContext)(this.config.collectDeviceId);
171
+ /**
172
+ * Track a user event
173
+ */
174
+ async user(data, components) {
175
+ const context = await (0, context_1.getContext)(this.config);
201
176
  // Get native context properties if available and collectDeviceId is enabled
202
177
  let nativeProperties = {};
203
178
  if (this.config.collectDeviceId && (0, native_context_1.isNativeModuleAvailable)()) {
@@ -208,62 +183,32 @@ class EdgeeClient {
208
183
  nativeProperties = extractNativeProperties(nativeContext);
209
184
  }
210
185
  catch (error) {
211
- if (this.config.debug) {
212
- console.warn("[Edgee] Failed to get native context for screen properties:", error);
213
- }
186
+ (0, utils_1.logError)("Error collecting user event", error);
214
187
  }
215
188
  }
216
- // Merge native properties with screen data
189
+ // Merge native properties with user data
217
190
  const enhancedData = {
218
191
  ...data,
219
- screen_name: screenName,
220
192
  ...nativeProperties,
221
193
  };
222
- const event = (0, api_1.createTrackEvent)({
223
- name: "screen",
194
+ const event = (0, api_1.createUserEvent)({
224
195
  data: enhancedData,
225
196
  components,
226
197
  context,
227
198
  });
228
199
  this.queue.enqueue(event);
229
200
  }
230
- // Consent management methods
231
- async setConsent(status) {
232
- await consent_1.ConsentUtils.setConsent(status);
233
- // Send consent event to server
234
- await consent_1.ConsentUtils.sendConsentEvent(this, status);
235
- if (this.config.debug) {
236
- console.log(`[Edgee] Consent set to: ${status}`);
237
- }
238
- }
239
- getConsent() {
240
- return consent_1.ConsentUtils.getConsent();
241
- }
242
- hasConsent() {
243
- return consent_1.ConsentUtils.hasConsent();
244
- }
245
- canTrack() {
246
- return consent_1.ConsentUtils.canTrack();
247
- }
248
- async resetConsent() {
249
- await consent_1.ConsentUtils.reset();
250
- if (this.config.debug) {
251
- console.log(`[Edgee] Consent reset`);
252
- }
253
- }
254
- onConsentChange(callback) {
255
- return consent_1.ConsentUtils.onChange(callback);
256
- }
257
201
  /**
258
202
  * Send consent event directly to Edgee (matches web SDK format)
259
203
  */
260
204
  async consent(status) {
261
205
  // Validate consent status
262
206
  if (!["granted", "denied", "pending"].includes(status)) {
207
+ (0, utils_1.logError)("- Consent not valid");
263
208
  throw new Error(`Invalid consent: ${status}. Use 'granted', 'denied', or 'pending'`);
264
209
  }
265
210
  // Store consent locally
266
- await consent_1.ConsentUtils.setConsent(status);
211
+ await consent_1.edgeeConsent.setConsent(status);
267
212
  // Send consent event using web SDK format
268
213
  const payload = {
269
214
  data_collection: {
@@ -272,29 +217,35 @@ class EdgeeClient {
272
217
  };
273
218
  try {
274
219
  await this.queue.sendEvent(payload);
275
- if (this.config.debug) {
276
- console.log(`[Edgee] Consent sent to server: ${status}`);
277
- }
220
+ (0, utils_1.log)(this.config, "- Consent set to:", status);
278
221
  }
279
222
  catch (error) {
280
- console.warn("[Edgee] Failed to send consent event:", error);
223
+ (0, utils_1.logError)("Error collecting consent event", error);
281
224
  throw error;
282
225
  }
283
226
  }
227
+ // Consent management methods
228
+ async setConsent(status) {
229
+ await this.consent(status);
230
+ }
231
+ getConsent() {
232
+ return consent_1.edgeeConsent.getConsent();
233
+ }
234
+ hasConsent() {
235
+ return consent_1.edgeeConsent.hasConsent();
236
+ }
237
+ async resetConsent() {
238
+ await consent_1.edgeeConsent.reset();
239
+ }
240
+ onConsentChange(callback) {
241
+ return consent_1.edgeeConsent.onChange(callback);
242
+ }
284
243
  }
285
244
  exports.EdgeeClient = EdgeeClient;
286
- exports.navigation = __importStar(require("./navigation"));
287
245
  var react_1 = require("./react");
288
- Object.defineProperty(exports, "EdgeeAutoTracker", { enumerable: true, get: function () { return react_1.EdgeeAutoTracker; } });
289
246
  Object.defineProperty(exports, "EdgeeProvider", { enumerable: true, get: function () { return react_1.EdgeeProvider; } });
290
247
  Object.defineProperty(exports, "useEdgee", { enumerable: true, get: function () { return react_1.useEdgee; } });
291
- Object.defineProperty(exports, "useEdgeeConsent", { enumerable: true, get: function () { return react_1.useEdgeeConsent; } });
292
248
  var native_context_2 = require("./native-context");
293
249
  Object.defineProperty(exports, "clearContextCache", { enumerable: true, get: function () { return native_context_2.clearContextCache; } });
294
250
  Object.defineProperty(exports, "getNativeContext", { enumerable: true, get: function () { return native_context_2.getNativeContext; } });
295
251
  Object.defineProperty(exports, "isNativeModuleAvailable", { enumerable: true, get: function () { return native_context_2.isNativeModuleAvailable; } });
296
- // Export consent functionality
297
- var consent_2 = require("./consent");
298
- Object.defineProperty(exports, "ConsentUtils", { enumerable: true, get: function () { return consent_2.ConsentUtils; } });
299
- Object.defineProperty(exports, "EdgeeConsent", { enumerable: true, get: function () { return consent_2.EdgeeConsent; } });
300
- Object.defineProperty(exports, "edgeeConsent", { enumerable: true, get: function () { return consent_2.edgeeConsent; } });
@@ -4,6 +4,7 @@ exports.getNativeContext = getNativeContext;
4
4
  exports.clearContextCache = clearContextCache;
5
5
  exports.isNativeModuleAvailable = isNativeModuleAvailable;
6
6
  const react_native_1 = require("react-native");
7
+ const utils_1 = require("./core/utils");
7
8
  const LINKING_ERROR = `The package 'react-native-edgee' doesn't seem to be linked. Make sure: \n\n` +
8
9
  react_native_1.Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) +
9
10
  "- You rebuilt the app after installing the package\n" +
@@ -40,7 +41,7 @@ async function getNativeContext(config = {}) {
40
41
  })
41
42
  .catch((error) => {
42
43
  contextPromise = null;
43
- console.warn("Failed to get native context:", error);
44
+ (0, utils_1.logError)("Failed to get native context", error);
44
45
  // Return fallback context
45
46
  return getFallbackContext();
46
47
  });