@metarouter/react-native-sdk 1.5.1 → 1.8.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.
- package/README.md +190 -60
- package/android/build.gradle +41 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/metarouter/reactnative/MetaRouterNetworkMonitorModule.kt +119 -0
- package/android/src/main/java/com/metarouter/reactnative/MetaRouterPackage.kt +23 -0
- package/android/src/main/java/com/metarouter/reactnative/MetaRouterQueueStorageModule.kt +124 -0
- package/ios/MetaRouterNetworkMonitor.m +76 -0
- package/ios/MetaRouterQueueStorage.m +127 -0
- package/lib/analytics/MetaRouterAnalyticsClient.d.ts +71 -4
- package/lib/analytics/MetaRouterAnalyticsClient.d.ts.map +1 -1
- package/lib/analytics/MetaRouterAnalyticsClient.js +396 -112
- package/lib/analytics/dispatcher.d.ts +57 -1
- package/lib/analytics/dispatcher.d.ts.map +1 -1
- package/lib/analytics/dispatcher.js +231 -32
- package/lib/analytics/init.d.ts +8 -1
- package/lib/analytics/init.d.ts.map +1 -1
- package/lib/analytics/init.js +198 -37
- package/lib/analytics/lifecycle/lifecycleEvents.d.ts +52 -0
- package/lib/analytics/lifecycle/lifecycleEvents.d.ts.map +1 -0
- package/lib/analytics/lifecycle/lifecycleEvents.js +66 -0
- package/lib/analytics/persistence/NativeQueueStorage.d.ts +5 -0
- package/lib/analytics/persistence/NativeQueueStorage.d.ts.map +1 -0
- package/lib/analytics/persistence/NativeQueueStorage.js +59 -0
- package/lib/analytics/persistence/PersistentEventQueue.d.ts +96 -0
- package/lib/analytics/persistence/PersistentEventQueue.d.ts.map +1 -0
- package/lib/analytics/persistence/PersistentEventQueue.js +401 -0
- package/lib/analytics/persistence/types.d.ts +20 -0
- package/lib/analytics/persistence/types.d.ts.map +1 -0
- package/lib/analytics/persistence/types.js +10 -0
- package/lib/analytics/proxy/proxyClient.d.ts +30 -1
- package/lib/analytics/proxy/proxyClient.d.ts.map +1 -1
- package/lib/analytics/proxy/proxyClient.js +145 -23
- package/lib/analytics/types.d.ts +61 -4
- package/lib/analytics/types.d.ts.map +1 -1
- package/lib/analytics/utils/appContext.d.ts +20 -0
- package/lib/analytics/utils/appContext.d.ts.map +1 -0
- package/lib/analytics/utils/appContext.js +22 -0
- package/lib/analytics/utils/circuitBreaker.d.ts +4 -1
- package/lib/analytics/utils/circuitBreaker.d.ts.map +1 -1
- package/lib/analytics/utils/circuitBreaker.js +23 -14
- package/lib/analytics/utils/contextInfo.d.ts +8 -4
- package/lib/analytics/utils/contextInfo.d.ts.map +1 -1
- package/lib/analytics/utils/contextInfo.js +34 -27
- package/lib/analytics/utils/debouncedNetworkMonitor.d.ts +25 -0
- package/lib/analytics/utils/debouncedNetworkMonitor.d.ts.map +1 -0
- package/lib/analytics/utils/debouncedNetworkMonitor.js +68 -0
- package/lib/analytics/utils/initOptions.d.ts +22 -0
- package/lib/analytics/utils/initOptions.d.ts.map +1 -0
- package/lib/analytics/utils/initOptions.js +100 -0
- package/lib/analytics/utils/lifecycleStorage.d.ts +13 -0
- package/lib/analytics/utils/lifecycleStorage.d.ts.map +1 -0
- package/lib/analytics/utils/lifecycleStorage.js +35 -0
- package/lib/analytics/utils/networkMonitor.d.ts +30 -0
- package/lib/analytics/utils/networkMonitor.d.ts.map +1 -0
- package/lib/analytics/utils/networkMonitor.js +90 -0
- package/lib/analytics/utils/responseCategory.d.ts +14 -0
- package/lib/analytics/utils/responseCategory.d.ts.map +1 -0
- package/lib/analytics/utils/responseCategory.js +26 -0
- package/lib/index.d.ts +4 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -3
- package/metarouter-react-native-sdk.podspec +19 -0
- package/package.json +6 -3
- package/react-native.config.js +15 -0
|
@@ -1,13 +1,48 @@
|
|
|
1
1
|
const pendingCalls = [];
|
|
2
2
|
const MAX_PENDING_CALLS = 20;
|
|
3
3
|
let realClient = null;
|
|
4
|
+
// Description of the config error that refused this session, or null. While
|
|
5
|
+
// set, calls still queue (and replay if a valid init recovers the session),
|
|
6
|
+
// but nothing that returns a promise may wait for a bind that is not coming.
|
|
7
|
+
let configDisabledError = null;
|
|
8
|
+
// Owned by init.ts: reset must work before a bind (it is how a refused or
|
|
9
|
+
// still-initializing session is cleared), so the proxy cannot route it to the
|
|
10
|
+
// bound client alone.
|
|
11
|
+
let resetHandler = null;
|
|
12
|
+
// The client whose init() is still running. recordOpenedURL only fills a
|
|
13
|
+
// one-slot buffer that the cold-launch Application Opened reads during
|
|
14
|
+
// init(), and the proxy binds only after init() resolves — so a cold-launch
|
|
15
|
+
// URL queued for replay would always miss its own Opened and ride on the
|
|
16
|
+
// next resume instead. Routing it here lets it land before that emit.
|
|
17
|
+
let initializingClient = null;
|
|
4
18
|
const ASYNC_METHODS = {
|
|
5
19
|
flush: true,
|
|
6
20
|
getDebugInfo: true,
|
|
21
|
+
getAnonymousId: true,
|
|
7
22
|
setAdvertisingId: true,
|
|
8
23
|
clearAdvertisingId: true,
|
|
9
24
|
};
|
|
10
25
|
const isAsyncMethod = (m) => ASYNC_METHODS[m] === true;
|
|
26
|
+
/**
|
|
27
|
+
* What an async call resolves to on a config-refused session. getAnonymousId
|
|
28
|
+
* resolves "" promptly, like iOS and Android: a permanent hang on a
|
|
29
|
+
* misconfigured SDK would be worse than the crash this contract replaces.
|
|
30
|
+
*/
|
|
31
|
+
function degradedResult(methodName) {
|
|
32
|
+
switch (methodName) {
|
|
33
|
+
case 'getAnonymousId':
|
|
34
|
+
return '';
|
|
35
|
+
case 'getDebugInfo':
|
|
36
|
+
return {
|
|
37
|
+
lifecycle: 'disabled',
|
|
38
|
+
proxy: true,
|
|
39
|
+
pendingCalls: pendingCalls.length,
|
|
40
|
+
configError: configDisabledError,
|
|
41
|
+
};
|
|
42
|
+
default:
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
11
46
|
// One in-flight flush at a time
|
|
12
47
|
let flushInFlight = null;
|
|
13
48
|
/**
|
|
@@ -36,8 +71,8 @@ let flushInFlight = null;
|
|
|
36
71
|
function handleMethodCall(methodName, ...args) {
|
|
37
72
|
var _a;
|
|
38
73
|
// Real client bound
|
|
39
|
-
if (realClient) {
|
|
40
|
-
if (methodName ===
|
|
74
|
+
if (realClient && methodName !== 'reset') {
|
|
75
|
+
if (methodName === 'flush') {
|
|
41
76
|
if (flushInFlight)
|
|
42
77
|
return flushInFlight;
|
|
43
78
|
const p = Promise.resolve(realClient.flush(...args)).then(() => undefined);
|
|
@@ -48,28 +83,52 @@ function handleMethodCall(methodName, ...args) {
|
|
|
48
83
|
}
|
|
49
84
|
return realClient[methodName](...args);
|
|
50
85
|
}
|
|
86
|
+
if (methodName === 'reset') {
|
|
87
|
+
if (resetHandler) {
|
|
88
|
+
return resetHandler();
|
|
89
|
+
}
|
|
90
|
+
return (realClient ? realClient.reset() : Promise.resolve());
|
|
91
|
+
}
|
|
51
92
|
// No real client bound yet
|
|
93
|
+
if (methodName === 'recordOpenedURL' && initializingClient) {
|
|
94
|
+
initializingClient.recordOpenedURL(...args);
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
// Refused session: queries answer now and never take a queue slot.
|
|
98
|
+
if (configDisabledError !== null &&
|
|
99
|
+
(methodName === 'getAnonymousId' || methodName === 'getDebugInfo')) {
|
|
100
|
+
return Promise.resolve(degradedResult(methodName));
|
|
101
|
+
}
|
|
52
102
|
if (pendingCalls.length >= MAX_PENDING_CALLS) {
|
|
53
103
|
const dropped = pendingCalls.shift();
|
|
54
104
|
(_a = dropped === null || dropped === void 0 ? void 0 : dropped.reject) === null || _a === void 0 ? void 0 : _a.call(dropped, new Error(`[MetaRouter] Dropped oldest call (queue cap ${MAX_PENDING_CALLS})`));
|
|
55
105
|
console.warn(`[MetaRouter] Oldest call dropped (queue cap ${MAX_PENDING_CALLS})`);
|
|
56
106
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
|
|
107
|
+
if (isAsyncMethod(methodName) && configDisabledError !== null) {
|
|
108
|
+
// Refused session: commands (flush, advertising id) still queue so a
|
|
109
|
+
// recovering valid init replays them like any other call, but their
|
|
110
|
+
// promise resolves now instead of waiting for a bind.
|
|
111
|
+
pendingCalls.push({
|
|
112
|
+
fn: () => {
|
|
113
|
+
if (!realClient)
|
|
114
|
+
return;
|
|
115
|
+
return Promise.resolve(realClient[methodName](...args)).then(() => undefined);
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
return Promise.resolve(undefined);
|
|
61
119
|
}
|
|
62
120
|
if (isAsyncMethod(methodName)) {
|
|
63
121
|
// Queue async call and return a promise that resolves after bind+run
|
|
64
122
|
return new Promise((resolve, reject) => {
|
|
65
123
|
pendingCalls.push({
|
|
66
124
|
reject, // keep a handle for dropPending
|
|
125
|
+
degrade: () => resolve(degradedResult(methodName)),
|
|
67
126
|
fn: async () => {
|
|
68
127
|
try {
|
|
69
128
|
if (!realClient) {
|
|
70
|
-
return reject(new Error(
|
|
129
|
+
return reject(new Error('Proxy detached before real client was bound'));
|
|
71
130
|
}
|
|
72
|
-
if (methodName ===
|
|
131
|
+
if (methodName === 'flush') {
|
|
73
132
|
if (!flushInFlight) {
|
|
74
133
|
const p = Promise.resolve(realClient.flush(...args)).then(() => undefined);
|
|
75
134
|
flushInFlight = p.finally(() => {
|
|
@@ -95,24 +154,37 @@ function handleMethodCall(methodName, ...args) {
|
|
|
95
154
|
return;
|
|
96
155
|
realClient[methodName](...args);
|
|
97
156
|
},
|
|
157
|
+
...(methodName === 'recordOpenedURL' && {
|
|
158
|
+
openedURL: args,
|
|
159
|
+
}),
|
|
98
160
|
});
|
|
99
161
|
return undefined;
|
|
100
162
|
}
|
|
101
163
|
export const proxyClient = {
|
|
102
|
-
track: (event, props) => handleMethodCall(
|
|
103
|
-
identify: (userId, traits) => handleMethodCall(
|
|
104
|
-
group: (groupId, traits) => handleMethodCall(
|
|
105
|
-
screen: (name, props) => handleMethodCall(
|
|
106
|
-
page: (name, props) => handleMethodCall(
|
|
107
|
-
alias: (newUserId) => handleMethodCall(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
164
|
+
track: (event, props) => handleMethodCall('track', event, props),
|
|
165
|
+
identify: (userId, traits) => handleMethodCall('identify', userId, traits),
|
|
166
|
+
group: (groupId, traits) => handleMethodCall('group', groupId, traits),
|
|
167
|
+
screen: (name, props) => handleMethodCall('screen', name, props),
|
|
168
|
+
page: (name, props) => handleMethodCall('page', name, props),
|
|
169
|
+
alias: (newUserId) => handleMethodCall('alias', newUserId),
|
|
170
|
+
recordOpenedURL: (url, sourceApplication) => handleMethodCall('recordOpenedURL', url, sourceApplication),
|
|
171
|
+
setAdvertisingId: (advertisingId) => handleMethodCall('setAdvertisingId', advertisingId),
|
|
172
|
+
clearAdvertisingId: () => handleMethodCall('clearAdvertisingId'),
|
|
173
|
+
setTracing: (enabled) => handleMethodCall('setTracing', enabled),
|
|
174
|
+
flush: () => handleMethodCall('flush'),
|
|
175
|
+
reset: () => handleMethodCall('reset'),
|
|
176
|
+
enableDebugLogging: () => handleMethodCall('enableDebugLogging'),
|
|
177
|
+
getDebugInfo: () => handleMethodCall('getDebugInfo'),
|
|
178
|
+
getAnonymousId: () => handleMethodCall('getAnonymousId'),
|
|
115
179
|
};
|
|
180
|
+
/**
|
|
181
|
+
* Sets (or clears, with `null`) the client whose init() is in flight, so
|
|
182
|
+
* recordOpenedURL reaches it before the cold-launch Opened is emitted.
|
|
183
|
+
* Cleared as soon as init() settles, before binding.
|
|
184
|
+
*/
|
|
185
|
+
export function setInitializingClient(client) {
|
|
186
|
+
initializingClient = client;
|
|
187
|
+
}
|
|
116
188
|
/**
|
|
117
189
|
* Binds or unbinds the real analytics client to the proxy and manages queued calls.
|
|
118
190
|
*
|
|
@@ -143,6 +215,8 @@ export const proxyClient = {
|
|
|
143
215
|
export function setRealClient(client, opts) {
|
|
144
216
|
var _a;
|
|
145
217
|
realClient = client;
|
|
218
|
+
// Binding a client, or a reset's unbind, ends any refusal.
|
|
219
|
+
configDisabledError = null;
|
|
146
220
|
if (client) {
|
|
147
221
|
const items = pendingCalls.splice(0, pendingCalls.length);
|
|
148
222
|
for (const { fn } of items) {
|
|
@@ -150,16 +224,64 @@ export function setRealClient(client, opts) {
|
|
|
150
224
|
Promise.resolve(fn()).catch(() => { });
|
|
151
225
|
}
|
|
152
226
|
catch (err) {
|
|
153
|
-
console.warn(
|
|
227
|
+
console.warn('[MetaRouter] replay error:', err);
|
|
154
228
|
}
|
|
155
229
|
}
|
|
156
230
|
}
|
|
157
231
|
else {
|
|
158
232
|
if (opts === null || opts === void 0 ? void 0 : opts.dropPending) {
|
|
159
233
|
for (const it of pendingCalls)
|
|
160
|
-
(_a = it.reject) === null || _a === void 0 ? void 0 : _a.call(it, new Error(
|
|
234
|
+
(_a = it.reject) === null || _a === void 0 ? void 0 : _a.call(it, new Error('[MetaRouter] Proxy dropped before bind'));
|
|
161
235
|
pendingCalls.length = 0;
|
|
162
236
|
}
|
|
163
237
|
flushInFlight = null; // reset coalescer
|
|
164
238
|
}
|
|
165
239
|
}
|
|
240
|
+
/** Registers init.ts's session reset, used by `reset()` in every state. */
|
|
241
|
+
export function setResetHandler(handler) {
|
|
242
|
+
resetHandler = handler;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Refuses the session: unbinds, drops calls queued before the refusal (they
|
|
246
|
+
* belonged to a session that never bound), settles their promises with the
|
|
247
|
+
* degraded value instead of rejecting, and makes later async calls resolve
|
|
248
|
+
* degraded. Calls made after this point queue and replay on recovery.
|
|
249
|
+
*/
|
|
250
|
+
export function markConfigDisabled(description) {
|
|
251
|
+
var _a;
|
|
252
|
+
realClient = null;
|
|
253
|
+
flushInFlight = null;
|
|
254
|
+
configDisabledError = description;
|
|
255
|
+
const items = pendingCalls.splice(0, pendingCalls.length);
|
|
256
|
+
for (const it of items)
|
|
257
|
+
(_a = it.degrade) === null || _a === void 0 ? void 0 : _a.call(it);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Lifts a refusal before a valid init builds its client, so async calls made
|
|
261
|
+
* during that init wait for the incoming bind rather than resolving against
|
|
262
|
+
* the previous verdict.
|
|
263
|
+
*/
|
|
264
|
+
export function clearConfigDisabled() {
|
|
265
|
+
configDisabledError = null;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Removes and returns queued recordOpenedURL calls, oldest first. The init that
|
|
269
|
+
* builds a client applies them before init() runs: createAnalyticsClient only
|
|
270
|
+
* queues that init, so a URL forwarded right after the call (the usual
|
|
271
|
+
* `Linking.getInitialURL()` wiring) is queued here before any client exists,
|
|
272
|
+
* and replaying it after bind would miss the cold-launch Opened.
|
|
273
|
+
*/
|
|
274
|
+
export function takePendingOpenedURLs() {
|
|
275
|
+
const taken = [];
|
|
276
|
+
for (let i = 0; i < pendingCalls.length;) {
|
|
277
|
+
const args = pendingCalls[i].openedURL;
|
|
278
|
+
if (args) {
|
|
279
|
+
taken.push(args);
|
|
280
|
+
pendingCalls.splice(i, 1);
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
i++;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return taken;
|
|
287
|
+
}
|
package/lib/analytics/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type EventType =
|
|
1
|
+
export type EventType = 'track' | 'identify' | 'group' | 'screen' | 'alias' | 'page';
|
|
2
2
|
export interface EventPayload {
|
|
3
3
|
type: EventType;
|
|
4
4
|
event?: string;
|
|
@@ -16,13 +16,56 @@ export interface EnrichedEventPayload extends EventWithIdentity {
|
|
|
16
16
|
context: EventContext;
|
|
17
17
|
writeKey: string;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Why `createAnalyticsClient` refused its options. In development builds the
|
|
21
|
+
* call throws instead; in release the SDK stays inert for the session and
|
|
22
|
+
* reports this through `onConfigError` and `getDebugInfo().configError`.
|
|
23
|
+
* `description` is the same text the iOS and Android SDKs give.
|
|
24
|
+
*/
|
|
25
|
+
export type ConfigError = {
|
|
26
|
+
type: 'emptyWriteKey';
|
|
27
|
+
description: string;
|
|
28
|
+
} | {
|
|
29
|
+
type: 'invalidIngestionHost';
|
|
30
|
+
raw: string;
|
|
31
|
+
description: string;
|
|
32
|
+
};
|
|
19
33
|
export interface InitOptions {
|
|
34
|
+
/** Required. Trimmed; empty or whitespace-only is a config error. */
|
|
20
35
|
writeKey: string;
|
|
36
|
+
/**
|
|
37
|
+
* Required. An http(s) URL with a host. Trimmed, and trailing slashes are
|
|
38
|
+
* removed. Cleartext http logs a warning unless the host is loopback.
|
|
39
|
+
*/
|
|
21
40
|
ingestionHost: string;
|
|
41
|
+
/** Seconds between automatic flushes (default: 10). Clamped to >= 1. */
|
|
22
42
|
flushIntervalSeconds?: number;
|
|
23
43
|
debug?: boolean;
|
|
24
|
-
/** Max events held in memory
|
|
44
|
+
/** Max events held in the in-memory queue (default: 2000). Clamped to >= 1. */
|
|
25
45
|
maxQueueEvents?: number;
|
|
46
|
+
/**
|
|
47
|
+
* Max events stored on disk for crash-safety + extended offline periods
|
|
48
|
+
* (default: 10000). Negative values are clamped to 0. When set to 0, disk persistence is
|
|
49
|
+
* disabled and the SDK runs as a pure in-memory pipeline (events are lost
|
|
50
|
+
* on app kill — documented tradeoff).
|
|
51
|
+
*/
|
|
52
|
+
maxDiskEvents?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Emit Application Opened/Backgrounded/Installed/Updated events.
|
|
55
|
+
* Defaults to false (opt-in). Matches iOS/Android parity — existing
|
|
56
|
+
* customers upgrading the SDK do not begin emitting lifecycle events
|
|
57
|
+
* until they explicitly set this to true.
|
|
58
|
+
*/
|
|
59
|
+
trackLifecycleEvents?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Called synchronously by `createAnalyticsClient` when the options are
|
|
62
|
+
* invalid in a release build, after the error is logged. The SDK is inert
|
|
63
|
+
* for the session; a later `createAnalyticsClient` with valid options, or
|
|
64
|
+
* `reset()`, recovers it. Development builds throw from
|
|
65
|
+
* `createAnalyticsClient` instead and never call this. Not called for
|
|
66
|
+
* 401/403/404 responses from the ingestion host.
|
|
67
|
+
*/
|
|
68
|
+
onConfigError?: (error: ConfigError) => void;
|
|
26
69
|
}
|
|
27
70
|
export interface AnalyticsInterface {
|
|
28
71
|
track: (event: string, props?: Record<string, any>) => void;
|
|
@@ -31,6 +74,19 @@ export interface AnalyticsInterface {
|
|
|
31
74
|
screen: (name: string, props?: Record<string, any>) => void;
|
|
32
75
|
page: (name: string, props?: Record<string, any>) => void;
|
|
33
76
|
alias: (newUserId: string) => void;
|
|
77
|
+
/**
|
|
78
|
+
* Forward a URL the host received from `Linking` (or platform-specific
|
|
79
|
+
* URL handlers) so it is attached to the next `Application Opened`
|
|
80
|
+
* event. The SDK does not read `Linking` itself, so only URLs passed
|
|
81
|
+
* here are recorded — sanitize before forwarding. One-shot — buffer is
|
|
82
|
+
* cleared on emit; last-write-wins if called multiple times before the
|
|
83
|
+
* next Opened. Safe to call right after createAnalyticsClient(): a URL
|
|
84
|
+
* forwarded while initialization is running still reaches the
|
|
85
|
+
* cold-launch Opened.
|
|
86
|
+
*
|
|
87
|
+
* No-op with an always-on warning when `trackLifecycleEvents` is disabled.
|
|
88
|
+
*/
|
|
89
|
+
recordOpenedURL: (url: string, sourceApplication?: string) => void;
|
|
34
90
|
setAdvertisingId: (advertisingId: string) => Promise<void>;
|
|
35
91
|
clearAdvertisingId: () => Promise<void>;
|
|
36
92
|
setTracing: (enabled: boolean) => void;
|
|
@@ -38,6 +94,7 @@ export interface AnalyticsInterface {
|
|
|
38
94
|
reset: () => Promise<void>;
|
|
39
95
|
enableDebugLogging: () => void;
|
|
40
96
|
getDebugInfo: () => Promise<Record<string, any>>;
|
|
97
|
+
getAnonymousId: () => Promise<string>;
|
|
41
98
|
}
|
|
42
99
|
export interface EventContext {
|
|
43
100
|
app: {
|
|
@@ -49,7 +106,7 @@ export interface EventContext {
|
|
|
49
106
|
device: {
|
|
50
107
|
manufacturer: string;
|
|
51
108
|
model: string;
|
|
52
|
-
name
|
|
109
|
+
name?: string;
|
|
53
110
|
type: string;
|
|
54
111
|
advertisingId?: string;
|
|
55
112
|
};
|
|
@@ -73,5 +130,5 @@ export interface EventContext {
|
|
|
73
130
|
timezone: string;
|
|
74
131
|
[key: string]: any;
|
|
75
132
|
}
|
|
76
|
-
export type Lifecycle =
|
|
133
|
+
export type Lifecycle = 'idle' | 'initializing' | 'ready' | 'resetting' | 'disabled';
|
|
77
134
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/analytics/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,OAAO,GACP,UAAU,GACV,OAAO,GACP,QAAQ,GACR,OAAO,GACP,MAAM,CAAC;AAEX,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAkB,SAAQ,YAAY;IACrD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,YAAY,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;I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}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snapshot of the host app's identity (name, version, build, bundle id).
|
|
3
|
+
* Read once at SDK init and reused across every event — both as the `app:`
|
|
4
|
+
* block on the EventContext and as version/build properties on lifecycle
|
|
5
|
+
* events. Mirrors the iOS `AppContext` so a single source of truth flows
|
|
6
|
+
* through the same places on both platforms.
|
|
7
|
+
*/
|
|
8
|
+
export interface AppContext {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
build: string;
|
|
12
|
+
namespace: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Reads the current app identity from `react-native-device-info`. Falls back
|
|
16
|
+
* to package.json version + 'unknown' for everything else if the native
|
|
17
|
+
* module is missing (e.g. unit tests, Expo Go without the dev client).
|
|
18
|
+
*/
|
|
19
|
+
export declare function loadAppContext(): AppContext;
|
|
20
|
+
//# sourceMappingURL=appContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appContext.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/appContext.ts"],"names":[],"mappings":"AAUA;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,UAAU,CAO3C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import pkg from '../../../package.json';
|
|
2
|
+
let DeviceInfo = null;
|
|
3
|
+
try {
|
|
4
|
+
DeviceInfo = require('react-native-device-info');
|
|
5
|
+
}
|
|
6
|
+
catch {
|
|
7
|
+
DeviceInfo = null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Reads the current app identity from `react-native-device-info`. Falls back
|
|
11
|
+
* to package.json version + 'unknown' for everything else if the native
|
|
12
|
+
* module is missing (e.g. unit tests, Expo Go without the dev client).
|
|
13
|
+
*/
|
|
14
|
+
export function loadAppContext() {
|
|
15
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
16
|
+
return {
|
|
17
|
+
name: (_b = (_a = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getApplicationName) === null || _a === void 0 ? void 0 : _a.call(DeviceInfo)) !== null && _b !== void 0 ? _b : 'unknown',
|
|
18
|
+
version: (_e = (_d = (_c = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getVersion) === null || _c === void 0 ? void 0 : _c.call(DeviceInfo)) !== null && _d !== void 0 ? _d : pkg.version) !== null && _e !== void 0 ? _e : 'unknown',
|
|
19
|
+
build: (_g = (_f = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBuildNumber) === null || _f === void 0 ? void 0 : _f.call(DeviceInfo)) !== null && _g !== void 0 ? _g : 'unknown',
|
|
20
|
+
namespace: (_j = (_h = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBundleId) === null || _h === void 0 ? void 0 : _h.call(DeviceInfo)) !== null && _j !== void 0 ? _j : 'unknown',
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type CircuitState =
|
|
1
|
+
export type CircuitState = 'CLOSED' | 'OPEN' | 'HALF_OPEN';
|
|
2
2
|
export interface CircuitBreakerOptions {
|
|
3
3
|
/** Failures in a row to trip OPEN */
|
|
4
4
|
failureThreshold: number;
|
|
@@ -44,6 +44,9 @@ export default class CircuitBreaker {
|
|
|
44
44
|
onNonRetryable(): void;
|
|
45
45
|
/** Time when requests are next allowed (ms since epoch) */
|
|
46
46
|
nextAllowedAt(): number;
|
|
47
|
+
/** Force-reset to CLOSED. Used on offline -> online transition
|
|
48
|
+
* to clear stale backoff from the offline period. */
|
|
49
|
+
reset(): void;
|
|
47
50
|
/** How long until next attempt (ms) */
|
|
48
51
|
remainingCooldownMs(): number;
|
|
49
52
|
/** Current state (normalized view: OPEN auto-shows HALF_OPEN after cooldown) */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"circuitBreaker.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/circuitBreaker.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;AAE3D,MAAM,WAAW,qBAAqB;IACpC,qCAAqC;IACrC,gBAAgB,EAAE,MAAM,CAAC;IACzB,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oFAAoF;IACpF,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,iCAAiC;IACjC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,0DAA0D;IAC1D,aAAa,CAAC,EAAE,CACd,IAAI,EAAE,YAAY,EAClB,IAAI,EAAE,YAAY,EAClB,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,KAC/D,IAAI,CAAC;CACX;AAED,MAAM,CAAC,OAAO,OAAO,cAAc;IACjC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAS;IAC/C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAyC;IAExE,OAAO,CAAC,mBAAmB,CAAK;IAChC,OAAO,CAA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AED,MAAM,CAAC,OAAO,OAAO,cAAc;IACjC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAS;IAC/C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAyC;IAExE,OAAO,CAAC,mBAAmB,CAAK;IAChC,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,gBAAgB,CAAK;IAC7B,+DAA+D;IAC/D,OAAO,CAAC,SAAS,CAAK;gBAEV,IAAI,EAAE,qBAAqB;IAavC,6CAA6C;IAC7C,YAAY,IAAI,OAAO;IAyBvB,iCAAiC;IACjC,SAAS,IAAI,IAAI;IAWjB,wEAAwE;IACxE,SAAS,IAAI,IAAI;IAiBjB,gFAAgF;IAChF,cAAc,IAAI,IAAI;IAKtB,2DAA2D;IAC3D,aAAa,IAAI,MAAM;IAUvB;0DACsD;IACtD,KAAK,IAAI,IAAI;IAQb,uCAAuC;IACvC,mBAAmB,IAAI,MAAM;IAK7B,gFAAgF;IAChF,QAAQ,IAAI,YAAY;IAYxB,OAAO,CAAC,QAAQ;IAWhB,OAAO,CAAC,QAAQ;CAwBjB"}
|
|
@@ -2,7 +2,7 @@ export default class CircuitBreaker {
|
|
|
2
2
|
constructor(opts) {
|
|
3
3
|
var _a, _b, _c, _d;
|
|
4
4
|
this.consecutiveFailures = 0;
|
|
5
|
-
this.state =
|
|
5
|
+
this.state = 'CLOSED';
|
|
6
6
|
this.openUntil = 0;
|
|
7
7
|
this.halfOpenInFlight = 0;
|
|
8
8
|
/** how many times we've opened (drives exponential backoff) */
|
|
@@ -19,15 +19,15 @@ export default class CircuitBreaker {
|
|
|
19
19
|
allowRequest() {
|
|
20
20
|
const t = this.now();
|
|
21
21
|
// Normalize OPEN→HALF_OPEN when cooldown elapsed
|
|
22
|
-
if (this.state ===
|
|
22
|
+
if (this.state === 'OPEN' && t >= this.openUntil) {
|
|
23
23
|
this.halfOpenInFlight = 0;
|
|
24
|
-
this.setState(
|
|
24
|
+
this.setState('HALF_OPEN');
|
|
25
25
|
}
|
|
26
|
-
if (this.state ===
|
|
26
|
+
if (this.state === 'OPEN') {
|
|
27
27
|
// Still cooling down
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
|
-
if (this.state ===
|
|
30
|
+
if (this.state === 'HALF_OPEN') {
|
|
31
31
|
if (this.halfOpenInFlight >= this.halfOpenMaxConcurrent)
|
|
32
32
|
return false;
|
|
33
33
|
// Admit a probe
|
|
@@ -39,11 +39,11 @@ export default class CircuitBreaker {
|
|
|
39
39
|
}
|
|
40
40
|
/** Call on successful request */
|
|
41
41
|
onSuccess() {
|
|
42
|
-
if (this.state ===
|
|
42
|
+
if (this.state === 'HALF_OPEN') {
|
|
43
43
|
// One successful probe closes the circuit
|
|
44
44
|
this.halfOpenInFlight = 0;
|
|
45
45
|
this.openCount = 0;
|
|
46
|
-
this.setState(
|
|
46
|
+
this.setState('CLOSED');
|
|
47
47
|
}
|
|
48
48
|
// Success in CLOSED resets the consecutive failure counter
|
|
49
49
|
this.consecutiveFailures = 0;
|
|
@@ -51,12 +51,12 @@ export default class CircuitBreaker {
|
|
|
51
51
|
/** Call on failed request (retryable only: network/timeout/5xx/etc.) */
|
|
52
52
|
onFailure() {
|
|
53
53
|
this.consecutiveFailures += 1;
|
|
54
|
-
if (this.state ===
|
|
54
|
+
if (this.state === 'HALF_OPEN') {
|
|
55
55
|
// failed probe → re-open with backoff
|
|
56
56
|
this.tripOpen();
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
|
-
if (this.state ===
|
|
59
|
+
if (this.state === 'CLOSED' &&
|
|
60
60
|
this.consecutiveFailures >= this.failureThreshold) {
|
|
61
61
|
this.tripOpen();
|
|
62
62
|
}
|
|
@@ -69,14 +69,23 @@ export default class CircuitBreaker {
|
|
|
69
69
|
/** Time when requests are next allowed (ms since epoch) */
|
|
70
70
|
nextAllowedAt() {
|
|
71
71
|
const t = this.now();
|
|
72
|
-
if (this.state ===
|
|
72
|
+
if (this.state === 'OPEN')
|
|
73
73
|
return this.openUntil;
|
|
74
|
-
if (this.state ===
|
|
74
|
+
if (this.state === 'HALF_OPEN') {
|
|
75
75
|
// Capacity-limited in HALF_OPEN; return now (admission depends on allowRequest())
|
|
76
76
|
return t;
|
|
77
77
|
}
|
|
78
78
|
return t; // CLOSED
|
|
79
79
|
}
|
|
80
|
+
/** Force-reset to CLOSED. Used on offline -> online transition
|
|
81
|
+
* to clear stale backoff from the offline period. */
|
|
82
|
+
reset() {
|
|
83
|
+
this.setState('CLOSED');
|
|
84
|
+
this.consecutiveFailures = 0;
|
|
85
|
+
this.openCount = 0;
|
|
86
|
+
this.openUntil = 0;
|
|
87
|
+
this.halfOpenInFlight = 0;
|
|
88
|
+
}
|
|
80
89
|
/** How long until next attempt (ms) */
|
|
81
90
|
remainingCooldownMs() {
|
|
82
91
|
const t = this.now();
|
|
@@ -87,8 +96,8 @@ export default class CircuitBreaker {
|
|
|
87
96
|
// Report HALF_OPEN if cooldown has elapsed,
|
|
88
97
|
// but do not mutate state here — halfOpenInFlight
|
|
89
98
|
// is reset when allowRequest() actually admits a probe.
|
|
90
|
-
if (this.state ===
|
|
91
|
-
return
|
|
99
|
+
if (this.state === 'OPEN' && this.now() >= this.openUntil) {
|
|
100
|
+
return 'HALF_OPEN';
|
|
92
101
|
}
|
|
93
102
|
return this.state;
|
|
94
103
|
}
|
|
@@ -116,6 +125,6 @@ export default class CircuitBreaker {
|
|
|
116
125
|
const jittered = backoff + (Math.random() * 2 - 1) * jitter;
|
|
117
126
|
const cooldown = Math.max(0, Math.floor(jittered));
|
|
118
127
|
this.openUntil = this.now() + cooldown;
|
|
119
|
-
this.setState(
|
|
128
|
+
this.setState('OPEN', { cooldownMs: cooldown });
|
|
120
129
|
}
|
|
121
130
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { EventContext } from
|
|
1
|
+
import { EventContext } from '../types';
|
|
2
|
+
import { AppContext } from './appContext';
|
|
2
3
|
/**
|
|
3
4
|
* Clears the cached context information, forcing a refresh on the next getContextInfo call.
|
|
4
5
|
*/
|
|
@@ -6,13 +7,16 @@ export declare function clearContextCache(): void;
|
|
|
6
7
|
/**
|
|
7
8
|
* Gathers and caches device, app, and environment context information for analytics events.
|
|
8
9
|
*
|
|
9
|
-
* - Collects details such as
|
|
10
|
-
* - Uses `react-native-device-info` and the current environment to populate fields.
|
|
10
|
+
* - Collects details such as device model/type, OS, screen size, locale, timezone, and network status.
|
|
11
|
+
* - Uses `react-native-device-info` and the current environment to populate device/os fields.
|
|
12
|
+
* - Reuses the caller-provided AppContext for the `app:` block so version/build
|
|
13
|
+
* are sourced from the same snapshot used by lifecycle events.
|
|
11
14
|
* - Caches the result for the lifetime of the app to avoid redundant async calls.
|
|
12
15
|
* - Returns a context object suitable for event enrichment.
|
|
13
16
|
*
|
|
17
|
+
* @param appContext - The host app identity snapshot (name, version, build, namespace).
|
|
14
18
|
* @param advertisingId - Optional advertising identifier (IDFA on iOS, GAID on Android) for ad tracking and attribution.
|
|
15
19
|
* @returns {Promise<EventContext>} A promise that resolves to the context information object.
|
|
16
20
|
*/
|
|
17
|
-
export declare function getContextInfo(advertisingId?: string): Promise<EventContext>;
|
|
21
|
+
export declare function getContextInfo(appContext: AppContext, advertisingId?: string): Promise<EventContext>;
|
|
18
22
|
//# sourceMappingURL=contextInfo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextInfo.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/contextInfo.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"contextInfo.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/contextInfo.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAY1C;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAGxC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,cAAc,CAClC,UAAU,EAAE,UAAU,EACtB,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,YAAY,CAAC,CA+DvB"}
|