react-native-edgee 1.0.0 → 1.0.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.
- package/README.md +1 -2
- package/dist/api.d.ts +32 -0
- package/dist/api.js +111 -0
- package/dist/consent.d.ts +96 -0
- package/dist/consent.js +220 -0
- package/dist/core/context.d.ts +41 -0
- package/dist/core/context.js +90 -0
- package/dist/core/edgee-store.d.ts +21 -0
- package/dist/core/edgee-store.js +53 -0
- package/dist/core/query-builder.d.ts +8 -0
- package/dist/core/query-builder.js +21 -0
- package/dist/core/queue.d.ts +25 -0
- package/dist/core/queue.js +155 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +321 -0
- package/dist/native-context.d.ts +13 -0
- package/dist/native-context.js +106 -0
- package/dist/navigation/expo-router.d.ts +4 -0
- package/dist/navigation/expo-router.js +21 -0
- package/dist/navigation/index.d.ts +2 -0
- package/dist/navigation/index.js +18 -0
- package/dist/navigation/react-navigation.d.ts +9 -0
- package/dist/navigation/react-navigation.js +36 -0
- package/dist/react.d.ts +24 -0
- package/dist/react.js +111 -0
- package/dist/types.d.ts +64 -0
- package/dist/types.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -423,5 +423,4 @@ MIT
|
|
|
423
423
|
## 🆘 Support
|
|
424
424
|
|
|
425
425
|
- **Issues**: [GitHub Issues](https://github.com/edgee-cloud/react-native-edgee/issues)
|
|
426
|
-
- **Documentation**: [Edgee Docs](https://docs.edgee.cloud)
|
|
427
|
-
- **Community**: [Edgee Discord](https://discord.gg/edgee)
|
|
426
|
+
- **Documentation**: [Edgee Docs](https://docs.edgee.cloud)
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { EdgeeConfig } from ".";
|
|
2
|
+
import type { EdgeeFullContext } from "./core/context";
|
|
3
|
+
declare enum EventType {
|
|
4
|
+
Track = "track",
|
|
5
|
+
User = "user",
|
|
6
|
+
Screen = "screen"
|
|
7
|
+
}
|
|
8
|
+
export type EdgeeTrackEvent = {
|
|
9
|
+
type: EventType.Track;
|
|
10
|
+
name: string;
|
|
11
|
+
components: Record<string, boolean> | undefined;
|
|
12
|
+
data: object;
|
|
13
|
+
context: EdgeeFullContext;
|
|
14
|
+
};
|
|
15
|
+
export type EdgeeUserEvent = {
|
|
16
|
+
type: EventType.User;
|
|
17
|
+
data: object;
|
|
18
|
+
components: Record<string, boolean> | undefined;
|
|
19
|
+
context: EdgeeFullContext;
|
|
20
|
+
};
|
|
21
|
+
export type EdgeeScreenEvent = {
|
|
22
|
+
type: EventType.Screen;
|
|
23
|
+
name: string;
|
|
24
|
+
data: object;
|
|
25
|
+
components: Record<string, boolean> | undefined;
|
|
26
|
+
context: EdgeeFullContext;
|
|
27
|
+
};
|
|
28
|
+
export type EdgeeEvent = EdgeeTrackEvent | EdgeeUserEvent | EdgeeScreenEvent;
|
|
29
|
+
export declare const createTrackEvent: (params: Omit<EdgeeTrackEvent, "type">) => EdgeeTrackEvent;
|
|
30
|
+
export declare const createUserEvent: (params: Omit<EdgeeUserEvent, "type">) => EdgeeUserEvent;
|
|
31
|
+
export declare const uploadEvent: (url: string, config: EdgeeConfig, event: EdgeeEvent) => Promise<Response>;
|
|
32
|
+
export {};
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uploadEvent = exports.createUserEvent = exports.createTrackEvent = void 0;
|
|
4
|
+
var EventType;
|
|
5
|
+
(function (EventType) {
|
|
6
|
+
EventType["Track"] = "track";
|
|
7
|
+
EventType["User"] = "user";
|
|
8
|
+
EventType["Screen"] = "screen";
|
|
9
|
+
})(EventType || (EventType = {}));
|
|
10
|
+
const createTrackEvent = (params) => {
|
|
11
|
+
return {
|
|
12
|
+
type: EventType.Track,
|
|
13
|
+
...params,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
exports.createTrackEvent = createTrackEvent;
|
|
17
|
+
const createUserEvent = (params) => {
|
|
18
|
+
return {
|
|
19
|
+
type: EventType.User,
|
|
20
|
+
...params,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.createUserEvent = createUserEvent;
|
|
24
|
+
const uploadEvent = async (url, config, event) => {
|
|
25
|
+
const eventToSend = event;
|
|
26
|
+
if (eventToSend.type === "track") {
|
|
27
|
+
const event = {
|
|
28
|
+
data_collection: {
|
|
29
|
+
context: eventToSend.context,
|
|
30
|
+
events: [
|
|
31
|
+
{
|
|
32
|
+
type: "track",
|
|
33
|
+
data: {
|
|
34
|
+
name: eventToSend.name,
|
|
35
|
+
properties: eventToSend.data,
|
|
36
|
+
},
|
|
37
|
+
components: eventToSend.components,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
if (config.debug) {
|
|
43
|
+
// eslint-disable-next-line no-console
|
|
44
|
+
console.log("[Edgee RN] sending", { url, event });
|
|
45
|
+
}
|
|
46
|
+
return await fetch(url, {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: {
|
|
49
|
+
"Content-Type": "application/json",
|
|
50
|
+
...(config.debug ? { "Edgee-Debug": "true" } : {}),
|
|
51
|
+
},
|
|
52
|
+
body: JSON.stringify(event),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else if (eventToSend.type === "user") {
|
|
56
|
+
const event = {
|
|
57
|
+
data_collection: {
|
|
58
|
+
context: eventToSend.context,
|
|
59
|
+
events: [
|
|
60
|
+
{
|
|
61
|
+
type: "user",
|
|
62
|
+
data: eventToSend.data,
|
|
63
|
+
components: eventToSend.components,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
if (config.debug) {
|
|
69
|
+
// eslint-disable-next-line no-console
|
|
70
|
+
console.log("[Edgee RN] sending", { url, event });
|
|
71
|
+
}
|
|
72
|
+
return await fetch(url, {
|
|
73
|
+
method: "POST",
|
|
74
|
+
headers: {
|
|
75
|
+
"Content-Type": "application/json",
|
|
76
|
+
...(config.debug ? { "Edgee-Debug": "true" } : {}),
|
|
77
|
+
},
|
|
78
|
+
body: JSON.stringify(event),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
else if (eventToSend.type === "screen") {
|
|
82
|
+
const event = {
|
|
83
|
+
data_collection: {
|
|
84
|
+
context: eventToSend.context,
|
|
85
|
+
events: [
|
|
86
|
+
{
|
|
87
|
+
type: "track",
|
|
88
|
+
data: { ...eventToSend.data, screen_name: eventToSend.name },
|
|
89
|
+
components: eventToSend.components,
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
if (config.debug) {
|
|
95
|
+
// eslint-disable-next-line no-console
|
|
96
|
+
console.log("[Edgee RN] sending", { url, event });
|
|
97
|
+
}
|
|
98
|
+
return await fetch(url, {
|
|
99
|
+
method: "POST",
|
|
100
|
+
headers: {
|
|
101
|
+
"Content-Type": "application/json",
|
|
102
|
+
...(config.debug ? { "Edgee-Debug": "true" } : {}),
|
|
103
|
+
},
|
|
104
|
+
body: JSON.stringify(event),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
throw new Error("Invalid event type");
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
exports.uploadEvent = uploadEvent;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { ConsentStatus } from "./index";
|
|
2
|
+
/**
|
|
3
|
+
* Simple consent manager that works with existing EdgeeClient
|
|
4
|
+
* Stores consent status and provides utilities for consent management
|
|
5
|
+
*/
|
|
6
|
+
export declare class EdgeeConsent {
|
|
7
|
+
private consentStatus;
|
|
8
|
+
private initialized;
|
|
9
|
+
private onChangeCallbacks;
|
|
10
|
+
/**
|
|
11
|
+
* Initialize and load stored consent
|
|
12
|
+
*/
|
|
13
|
+
init(): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Set consent status
|
|
16
|
+
*/
|
|
17
|
+
setConsent(status: ConsentStatus): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Get current consent status
|
|
20
|
+
*/
|
|
21
|
+
getConsent(): ConsentStatus | null;
|
|
22
|
+
/**
|
|
23
|
+
* Check if consent has been set
|
|
24
|
+
*/
|
|
25
|
+
hasConsent(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Check if consent is granted
|
|
28
|
+
*/
|
|
29
|
+
isGranted(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Check if consent is denied
|
|
32
|
+
*/
|
|
33
|
+
isDenied(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Check if consent is pending
|
|
36
|
+
*/
|
|
37
|
+
isPending(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Check if we should allow tracking
|
|
40
|
+
*/
|
|
41
|
+
canTrack(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Listen for consent changes
|
|
44
|
+
*/
|
|
45
|
+
onChange(callback: (status: ConsentStatus | null) => void): () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Reset consent (remove stored value)
|
|
48
|
+
*/
|
|
49
|
+
reset(): Promise<void>;
|
|
50
|
+
private isValidStatus;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Global consent instance
|
|
54
|
+
* This allows you to manage consent across your app without passing it around
|
|
55
|
+
*/
|
|
56
|
+
export declare const edgeeConsent: EdgeeConsent;
|
|
57
|
+
/**
|
|
58
|
+
* Consent utilities
|
|
59
|
+
*/
|
|
60
|
+
export declare const ConsentUtils: {
|
|
61
|
+
/**
|
|
62
|
+
* Initialize consent (call this once in your app)
|
|
63
|
+
*/
|
|
64
|
+
init(): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Set consent status
|
|
67
|
+
*/
|
|
68
|
+
setConsent(status: ConsentStatus): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Get current consent
|
|
71
|
+
*/
|
|
72
|
+
getConsent(): ConsentStatus | null;
|
|
73
|
+
/**
|
|
74
|
+
* Check if can track
|
|
75
|
+
*/
|
|
76
|
+
canTrack(): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Check consent status
|
|
79
|
+
*/
|
|
80
|
+
hasConsent(): boolean;
|
|
81
|
+
isGranted(): boolean;
|
|
82
|
+
isDenied(): boolean;
|
|
83
|
+
isPending(): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Listen for changes
|
|
86
|
+
*/
|
|
87
|
+
onChange(callback: (status: ConsentStatus | null) => void): () => void;
|
|
88
|
+
/**
|
|
89
|
+
* Reset consent
|
|
90
|
+
*/
|
|
91
|
+
reset(): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Send consent event to Edgee using the new consent method
|
|
94
|
+
*/
|
|
95
|
+
sendConsentEvent(edgeeClient: any, status: ConsentStatus): Promise<void>;
|
|
96
|
+
};
|
package/dist/consent.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
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.ConsentUtils = exports.edgeeConsent = exports.EdgeeConsent = void 0;
|
|
7
|
+
const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
|
|
8
|
+
const CONSENT_STORAGE_KEY = "_edgee_consent";
|
|
9
|
+
/**
|
|
10
|
+
* Simple consent manager that works with existing EdgeeClient
|
|
11
|
+
* Stores consent status and provides utilities for consent management
|
|
12
|
+
*/
|
|
13
|
+
class EdgeeConsent {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.consentStatus = null;
|
|
16
|
+
this.initialized = false;
|
|
17
|
+
this.onChangeCallbacks = [];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Initialize and load stored consent
|
|
21
|
+
*/
|
|
22
|
+
async init() {
|
|
23
|
+
// Prevent multiple initializations
|
|
24
|
+
if (this.initialized) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const stored = await async_storage_1.default.getItem(CONSENT_STORAGE_KEY);
|
|
29
|
+
if (stored && this.isValidStatus(stored)) {
|
|
30
|
+
this.consentStatus = stored;
|
|
31
|
+
}
|
|
32
|
+
this.initialized = true;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.warn("[Edgee Consent] Failed to load:", error);
|
|
36
|
+
this.initialized = true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Set consent status
|
|
41
|
+
*/
|
|
42
|
+
async setConsent(status) {
|
|
43
|
+
if (!this.isValidStatus(status)) {
|
|
44
|
+
throw new Error(`Invalid consent: ${status}. Use 'granted', 'denied', or 'pending'`);
|
|
45
|
+
}
|
|
46
|
+
this.consentStatus = status;
|
|
47
|
+
try {
|
|
48
|
+
await async_storage_1.default.setItem(CONSENT_STORAGE_KEY, status);
|
|
49
|
+
// Notify callbacks
|
|
50
|
+
this.onChangeCallbacks.forEach((callback) => {
|
|
51
|
+
try {
|
|
52
|
+
callback(status);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.warn("[Edgee Consent] Callback error:", error);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.warn("[Edgee Consent] Failed to store:", error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get current consent status
|
|
65
|
+
*/
|
|
66
|
+
getConsent() {
|
|
67
|
+
return this.consentStatus;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Check if consent has been set
|
|
71
|
+
*/
|
|
72
|
+
hasConsent() {
|
|
73
|
+
return this.consentStatus !== null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Check if consent is granted
|
|
77
|
+
*/
|
|
78
|
+
isGranted() {
|
|
79
|
+
return this.consentStatus === "granted";
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Check if consent is denied
|
|
83
|
+
*/
|
|
84
|
+
isDenied() {
|
|
85
|
+
return this.consentStatus === "denied";
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Check if consent is pending
|
|
89
|
+
*/
|
|
90
|
+
isPending() {
|
|
91
|
+
return this.consentStatus === "pending";
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Check if we should allow tracking
|
|
95
|
+
*/
|
|
96
|
+
canTrack() {
|
|
97
|
+
return this.initialized && this.consentStatus === "granted";
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Listen for consent changes
|
|
101
|
+
*/
|
|
102
|
+
onChange(callback) {
|
|
103
|
+
this.onChangeCallbacks.push(callback);
|
|
104
|
+
// Return unsubscribe function
|
|
105
|
+
return () => {
|
|
106
|
+
const index = this.onChangeCallbacks.indexOf(callback);
|
|
107
|
+
if (index > -1) {
|
|
108
|
+
this.onChangeCallbacks.splice(index, 1);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Reset consent (remove stored value)
|
|
114
|
+
*/
|
|
115
|
+
async reset() {
|
|
116
|
+
this.consentStatus = null;
|
|
117
|
+
try {
|
|
118
|
+
await async_storage_1.default.removeItem(CONSENT_STORAGE_KEY);
|
|
119
|
+
// Notify callbacks
|
|
120
|
+
this.onChangeCallbacks.forEach((callback) => {
|
|
121
|
+
try {
|
|
122
|
+
callback(null);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
console.warn("[Edgee Consent] Callback error:", error);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
console.warn("[Edgee Consent] Failed to clear:", error);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
isValidStatus(status) {
|
|
134
|
+
return (typeof status === "string" &&
|
|
135
|
+
["granted", "denied", "pending"].includes(status));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.EdgeeConsent = EdgeeConsent;
|
|
139
|
+
/**
|
|
140
|
+
* Global consent instance
|
|
141
|
+
* This allows you to manage consent across your app without passing it around
|
|
142
|
+
*/
|
|
143
|
+
exports.edgeeConsent = new EdgeeConsent();
|
|
144
|
+
/**
|
|
145
|
+
* Consent utilities
|
|
146
|
+
*/
|
|
147
|
+
exports.ConsentUtils = {
|
|
148
|
+
/**
|
|
149
|
+
* Initialize consent (call this once in your app)
|
|
150
|
+
*/
|
|
151
|
+
async init() {
|
|
152
|
+
return exports.edgeeConsent.init();
|
|
153
|
+
},
|
|
154
|
+
/**
|
|
155
|
+
* Set consent status
|
|
156
|
+
*/
|
|
157
|
+
async setConsent(status) {
|
|
158
|
+
return exports.edgeeConsent.setConsent(status);
|
|
159
|
+
},
|
|
160
|
+
/**
|
|
161
|
+
* Get current consent
|
|
162
|
+
*/
|
|
163
|
+
getConsent() {
|
|
164
|
+
return exports.edgeeConsent.getConsent();
|
|
165
|
+
},
|
|
166
|
+
/**
|
|
167
|
+
* Check if can track
|
|
168
|
+
*/
|
|
169
|
+
canTrack() {
|
|
170
|
+
return exports.edgeeConsent.canTrack();
|
|
171
|
+
},
|
|
172
|
+
/**
|
|
173
|
+
* Check consent status
|
|
174
|
+
*/
|
|
175
|
+
hasConsent() {
|
|
176
|
+
return exports.edgeeConsent.hasConsent();
|
|
177
|
+
},
|
|
178
|
+
isGranted() {
|
|
179
|
+
return exports.edgeeConsent.isGranted();
|
|
180
|
+
},
|
|
181
|
+
isDenied() {
|
|
182
|
+
return exports.edgeeConsent.isDenied();
|
|
183
|
+
},
|
|
184
|
+
isPending() {
|
|
185
|
+
return exports.edgeeConsent.isPending();
|
|
186
|
+
},
|
|
187
|
+
/**
|
|
188
|
+
* Listen for changes
|
|
189
|
+
*/
|
|
190
|
+
onChange(callback) {
|
|
191
|
+
return exports.edgeeConsent.onChange(callback);
|
|
192
|
+
},
|
|
193
|
+
/**
|
|
194
|
+
* Reset consent
|
|
195
|
+
*/
|
|
196
|
+
async reset() {
|
|
197
|
+
return exports.edgeeConsent.reset();
|
|
198
|
+
},
|
|
199
|
+
/**
|
|
200
|
+
* Send consent event to Edgee using the new consent method
|
|
201
|
+
*/
|
|
202
|
+
async sendConsentEvent(edgeeClient, status) {
|
|
203
|
+
try {
|
|
204
|
+
// Use the new consent method if available
|
|
205
|
+
if (edgeeClient.consent) {
|
|
206
|
+
await edgeeClient.consent(status);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
// Fallback: use track event with special consent flag
|
|
210
|
+
await edgeeClient.track("_consent_update", {
|
|
211
|
+
consent_status: status,
|
|
212
|
+
timestamp: Date.now(),
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
console.warn("[Edgee Consent] Failed to send consent event:", error);
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface EdgeeClientContext {
|
|
2
|
+
screen_width: number;
|
|
3
|
+
screen_height: number;
|
|
4
|
+
screen_density: number;
|
|
5
|
+
platform: string;
|
|
6
|
+
app_name?: string;
|
|
7
|
+
app_version?: string;
|
|
8
|
+
build_number?: string;
|
|
9
|
+
bundle_id?: string;
|
|
10
|
+
device_name?: string;
|
|
11
|
+
device_type?: string;
|
|
12
|
+
manufacturer?: string;
|
|
13
|
+
model?: string;
|
|
14
|
+
os_name?: string;
|
|
15
|
+
os_version?: string;
|
|
16
|
+
locale?: string;
|
|
17
|
+
language?: string;
|
|
18
|
+
country?: string;
|
|
19
|
+
timezone?: string;
|
|
20
|
+
network_type?: string;
|
|
21
|
+
carrier_name?: string;
|
|
22
|
+
is_tablet?: boolean;
|
|
23
|
+
is_simulator?: boolean;
|
|
24
|
+
is_emulator?: boolean;
|
|
25
|
+
total_memory_mb?: number;
|
|
26
|
+
battery_level?: number;
|
|
27
|
+
ad_tracking_enabled?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface EdgeePageContext {
|
|
30
|
+
title: string;
|
|
31
|
+
path: string;
|
|
32
|
+
url: string | undefined;
|
|
33
|
+
}
|
|
34
|
+
export interface EdgeeFullContext {
|
|
35
|
+
client: EdgeeClientContext;
|
|
36
|
+
page: EdgeePageContext;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get comprehensive context including native device information
|
|
40
|
+
*/
|
|
41
|
+
export declare const getContext: (collectDeviceId?: boolean) => Promise<EdgeeFullContext>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getContext = void 0;
|
|
4
|
+
const react_native_1 = require("react-native");
|
|
5
|
+
const native_context_1 = require("../native-context");
|
|
6
|
+
/**
|
|
7
|
+
* Get comprehensive context including native device information
|
|
8
|
+
*/
|
|
9
|
+
const getContext = async (collectDeviceId = false) => {
|
|
10
|
+
var _a;
|
|
11
|
+
const url = (_a = (await react_native_1.Linking.getInitialURL())) !== null && _a !== void 0 ? _a : undefined;
|
|
12
|
+
let clientContext;
|
|
13
|
+
if ((0, native_context_1.isNativeModuleAvailable)()) {
|
|
14
|
+
try {
|
|
15
|
+
const nativeContext = await (0, native_context_1.getNativeContext)({ collectDeviceId });
|
|
16
|
+
clientContext = buildClientContextFromNative(nativeContext);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
console.warn("Failed to get native context, falling back to basic context:", error);
|
|
20
|
+
clientContext = getFallbackClientContext();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
clientContext = getFallbackClientContext();
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
client: clientContext,
|
|
28
|
+
page: {
|
|
29
|
+
title: "Home",
|
|
30
|
+
path: "/",
|
|
31
|
+
url,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.getContext = getContext;
|
|
36
|
+
/**
|
|
37
|
+
* Build client context from native context data
|
|
38
|
+
*/
|
|
39
|
+
function buildClientContextFromNative(nativeContext) {
|
|
40
|
+
return {
|
|
41
|
+
// Core screen information (always available)
|
|
42
|
+
screen_width: nativeContext.screenWidth,
|
|
43
|
+
screen_height: nativeContext.screenHeight,
|
|
44
|
+
screen_density: nativeContext.screenDensity,
|
|
45
|
+
platform: nativeContext.deviceType,
|
|
46
|
+
// Extended app information
|
|
47
|
+
app_name: nativeContext.appName,
|
|
48
|
+
app_version: nativeContext.appVersion,
|
|
49
|
+
build_number: nativeContext.buildNumber,
|
|
50
|
+
bundle_id: nativeContext.bundleId,
|
|
51
|
+
// Device information
|
|
52
|
+
device_name: nativeContext.deviceName,
|
|
53
|
+
device_type: nativeContext.deviceType,
|
|
54
|
+
manufacturer: nativeContext.manufacturer,
|
|
55
|
+
model: nativeContext.model,
|
|
56
|
+
// System information
|
|
57
|
+
os_name: nativeContext.osName,
|
|
58
|
+
os_version: nativeContext.osVersion,
|
|
59
|
+
// Locale information
|
|
60
|
+
locale: nativeContext.locale,
|
|
61
|
+
language: nativeContext.language,
|
|
62
|
+
country: nativeContext.country,
|
|
63
|
+
timezone: nativeContext.timezone,
|
|
64
|
+
// Network information
|
|
65
|
+
network_type: nativeContext.networkType,
|
|
66
|
+
carrier_name: nativeContext.carrierName,
|
|
67
|
+
// Hardware capabilities
|
|
68
|
+
is_tablet: nativeContext.isTablet,
|
|
69
|
+
is_simulator: nativeContext.isSimulator,
|
|
70
|
+
is_emulator: nativeContext.isEmulator,
|
|
71
|
+
// System metrics
|
|
72
|
+
total_memory_mb: nativeContext.totalMemoryMB,
|
|
73
|
+
battery_level: nativeContext.batteryLevel,
|
|
74
|
+
// Privacy information
|
|
75
|
+
ad_tracking_enabled: nativeContext.adTrackingEnabled,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get fallback client context when native module is not available
|
|
80
|
+
*/
|
|
81
|
+
function getFallbackClientContext() {
|
|
82
|
+
const { width, height } = react_native_1.Dimensions.get("window");
|
|
83
|
+
const density = react_native_1.PixelRatio.get();
|
|
84
|
+
return {
|
|
85
|
+
screen_width: width,
|
|
86
|
+
screen_height: height,
|
|
87
|
+
screen_density: density,
|
|
88
|
+
platform: react_native_1.Platform.OS,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
2
|
+
import { EdgeeEvent } from "../api";
|
|
3
|
+
export declare class EdgeeStore {
|
|
4
|
+
edgeeId: string | null;
|
|
5
|
+
userId: string | null;
|
|
6
|
+
store: typeof AsyncStorage;
|
|
7
|
+
pendingEvents: EdgeeEvent[];
|
|
8
|
+
constructor();
|
|
9
|
+
init(): Promise<void>;
|
|
10
|
+
getEdgeeId(): Promise<string | null>;
|
|
11
|
+
getUserId(): Promise<string | null>;
|
|
12
|
+
setEdgeeId(edgeeId: string): Promise<void>;
|
|
13
|
+
setUserId(userId: string): Promise<void>;
|
|
14
|
+
getContext(): Promise<{
|
|
15
|
+
edgeeId: string | null;
|
|
16
|
+
userId: string | null;
|
|
17
|
+
}>;
|
|
18
|
+
addEvent(event: EdgeeEvent): Promise<void>;
|
|
19
|
+
getPendingEvents(): Promise<EdgeeEvent[]>;
|
|
20
|
+
clearEvents(): Promise<void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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.EdgeeStore = void 0;
|
|
7
|
+
const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
|
|
8
|
+
class EdgeeStore {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.store = async_storage_1.default;
|
|
11
|
+
this.pendingEvents = [];
|
|
12
|
+
this.edgeeId = null;
|
|
13
|
+
this.userId = null;
|
|
14
|
+
}
|
|
15
|
+
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 : "[]");
|
|
20
|
+
}
|
|
21
|
+
async getEdgeeId() {
|
|
22
|
+
return this.edgeeId;
|
|
23
|
+
}
|
|
24
|
+
async getUserId() {
|
|
25
|
+
return this.userId;
|
|
26
|
+
}
|
|
27
|
+
async setEdgeeId(edgeeId) {
|
|
28
|
+
this.edgeeId = edgeeId;
|
|
29
|
+
await this.store.setItem("_edgee", edgeeId);
|
|
30
|
+
}
|
|
31
|
+
async setUserId(userId) {
|
|
32
|
+
this.userId = userId;
|
|
33
|
+
await this.store.setItem("_edgee_u", userId);
|
|
34
|
+
}
|
|
35
|
+
async getContext() {
|
|
36
|
+
return {
|
|
37
|
+
edgeeId: this.edgeeId,
|
|
38
|
+
userId: this.userId,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async addEvent(event) {
|
|
42
|
+
this.pendingEvents.push(event);
|
|
43
|
+
await this.store.setItem("_edgee_events", JSON.stringify(this.pendingEvents));
|
|
44
|
+
}
|
|
45
|
+
async getPendingEvents() {
|
|
46
|
+
return this.pendingEvents;
|
|
47
|
+
}
|
|
48
|
+
async clearEvents() {
|
|
49
|
+
this.pendingEvents = [];
|
|
50
|
+
await this.store.removeItem("_edgee_events");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.EdgeeStore = EdgeeStore;
|