@metarouter/react-native-sdk 1.5.0 → 1.7.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 +59 -10
- 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 +23 -4
- package/lib/analytics/MetaRouterAnalyticsClient.d.ts.map +1 -1
- package/lib/analytics/MetaRouterAnalyticsClient.js +178 -89
- package/lib/analytics/dispatcher.d.ts +61 -4
- package/lib/analytics/dispatcher.d.ts.map +1 -1
- package/lib/analytics/dispatcher.js +248 -45
- package/lib/analytics/init.d.ts +1 -1
- package/lib/analytics/init.d.ts.map +1 -1
- package/lib/analytics/init.js +12 -2
- 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 +1 -1
- package/lib/analytics/proxy/proxyClient.d.ts.map +1 -1
- package/lib/analytics/proxy/proxyClient.js +23 -29
- package/lib/analytics/types.d.ts +12 -4
- package/lib/analytics/types.d.ts.map +1 -1
- 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 +1 -1
- package/lib/analytics/utils/contextInfo.d.ts.map +1 -1
- package/lib/analytics/utils/contextInfo.js +28 -24
- 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/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/metarouter-react-native-sdk.podspec +19 -0
- package/package.json +27 -10
- package/react-native.config.js +15 -0
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;
|
|
@@ -21,8 +21,15 @@ export interface InitOptions {
|
|
|
21
21
|
ingestionHost: string;
|
|
22
22
|
flushIntervalSeconds?: number;
|
|
23
23
|
debug?: boolean;
|
|
24
|
-
/** Max events held in memory
|
|
24
|
+
/** Max events held in the in-memory queue (default: 2000). Clamped to >= 1. */
|
|
25
25
|
maxQueueEvents?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Max events stored on disk for crash-safety + extended offline periods
|
|
28
|
+
* (default: 10000). Must be >= 0. When set to 0, disk persistence is
|
|
29
|
+
* disabled and the SDK runs as a pure in-memory pipeline (events are lost
|
|
30
|
+
* on app kill — documented tradeoff).
|
|
31
|
+
*/
|
|
32
|
+
maxDiskEvents?: number;
|
|
26
33
|
}
|
|
27
34
|
export interface AnalyticsInterface {
|
|
28
35
|
track: (event: string, props?: Record<string, any>) => void;
|
|
@@ -38,6 +45,7 @@ export interface AnalyticsInterface {
|
|
|
38
45
|
reset: () => Promise<void>;
|
|
39
46
|
enableDebugLogging: () => void;
|
|
40
47
|
getDebugInfo: () => Promise<Record<string, any>>;
|
|
48
|
+
getAnonymousId: () => Promise<string>;
|
|
41
49
|
}
|
|
42
50
|
export interface EventContext {
|
|
43
51
|
app: {
|
|
@@ -49,7 +57,7 @@ export interface EventContext {
|
|
|
49
57
|
device: {
|
|
50
58
|
manufacturer: string;
|
|
51
59
|
model: string;
|
|
52
|
-
name
|
|
60
|
+
name?: string;
|
|
53
61
|
type: string;
|
|
54
62
|
advertisingId?: string;
|
|
55
63
|
};
|
|
@@ -73,5 +81,5 @@ export interface EventContext {
|
|
|
73
81
|
timezone: string;
|
|
74
82
|
[key: string]: any;
|
|
75
83
|
}
|
|
76
|
-
export type Lifecycle =
|
|
84
|
+
export type Lifecycle = 'idle' | 'initializing' | 'ready' | 'resetting' | 'disabled';
|
|
77
85
|
//# 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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,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IACjD,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CACvC;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE;QACH,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,MAAM,EAAE;QACN,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;IACF,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,EAAE,EAAE;QACF,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,OAAO,CAAC,EAAE;QACR,IAAI,EAAE,OAAO,CAAC;KACf,CAAC;IACF,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,cAAc,GACd,OAAO,GACP,WAAW,GACX,UAAU,CAAC"}
|
|
@@ -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,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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 +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;AAYxC;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAGxC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,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;AAYxC;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAGxC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CAClC,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,YAAY,CAAC,CA+DvB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Dimensions, PixelRatio, Platform } from
|
|
2
|
-
import { getTimeZone } from
|
|
3
|
-
import pkg from
|
|
1
|
+
import { Dimensions, PixelRatio, Platform } from 'react-native';
|
|
2
|
+
import { getTimeZone } from './timezone';
|
|
3
|
+
import pkg from '../../../package.json';
|
|
4
4
|
let cachedContext = null;
|
|
5
|
-
let cachedAdvertisingId
|
|
5
|
+
let cachedAdvertisingId;
|
|
6
6
|
let DeviceInfo = null;
|
|
7
7
|
try {
|
|
8
|
-
DeviceInfo = require(
|
|
8
|
+
DeviceInfo = require('react-native-device-info');
|
|
9
9
|
}
|
|
10
10
|
catch {
|
|
11
11
|
DeviceInfo = null;
|
|
@@ -29,51 +29,55 @@ export function clearContextCache() {
|
|
|
29
29
|
* @returns {Promise<EventContext>} A promise that resolves to the context information object.
|
|
30
30
|
*/
|
|
31
31
|
export async function getContextInfo(advertisingId) {
|
|
32
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
32
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
|
|
33
33
|
// Return cached context only if it exists AND the advertising ID hasn't changed
|
|
34
34
|
if (cachedContext && cachedAdvertisingId === advertisingId)
|
|
35
35
|
return cachedContext;
|
|
36
|
-
let locale =
|
|
37
|
-
if (typeof Intl !==
|
|
38
|
-
typeof Intl.DateTimeFormat ===
|
|
36
|
+
let locale = 'en-US';
|
|
37
|
+
if (typeof Intl !== 'undefined' &&
|
|
38
|
+
typeof Intl.DateTimeFormat === 'function') {
|
|
39
39
|
const resolved = Intl.DateTimeFormat().resolvedOptions();
|
|
40
40
|
locale = (_a = resolved.locale) !== null && _a !== void 0 ? _a : locale;
|
|
41
41
|
}
|
|
42
|
-
const { width, height } = Dimensions.get(
|
|
42
|
+
const { width, height } = Dimensions.get('screen');
|
|
43
43
|
const density = Number(PixelRatio.get().toFixed(2));
|
|
44
44
|
cachedContext = {
|
|
45
45
|
library: {
|
|
46
|
-
name:
|
|
47
|
-
version: (_b = pkg.version) !== null && _b !== void 0 ? _b :
|
|
46
|
+
name: 'metarouter-react-native-sdk',
|
|
47
|
+
version: (_b = pkg.version) !== null && _b !== void 0 ? _b : '0.0.0',
|
|
48
48
|
},
|
|
49
49
|
locale,
|
|
50
50
|
timezone: getTimeZone(),
|
|
51
51
|
device: {
|
|
52
|
-
manufacturer: (_d = (await ((_c = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getManufacturer) === null || _c === void 0 ? void 0 : _c.call(DeviceInfo)))) !== null && _d !== void 0 ? _d :
|
|
53
|
-
model:
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
manufacturer: (_d = (await ((_c = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getManufacturer) === null || _c === void 0 ? void 0 : _c.call(DeviceInfo)))) !== null && _d !== void 0 ? _d : 'unknown',
|
|
53
|
+
model: Platform.OS === 'android'
|
|
54
|
+
? ((_f = (_e = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getModel) === null || _e === void 0 ? void 0 : _e.call(DeviceInfo)) !== null && _f !== void 0 ? _f : 'unknown')
|
|
55
|
+
: ((_h = (_g = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getDeviceId) === null || _g === void 0 ? void 0 : _g.call(DeviceInfo)) !== null && _h !== void 0 ? _h : 'unknown'),
|
|
56
|
+
type: ((_j = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getSystemName) === null || _j === void 0 ? void 0 : _j.call(DeviceInfo)) === 'Android' ? 'android' : 'ios',
|
|
57
|
+
...(Platform.OS === 'android'
|
|
58
|
+
? { name: (_l = (await ((_k = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getDevice) === null || _k === void 0 ? void 0 : _k.call(DeviceInfo)))) !== null && _l !== void 0 ? _l : 'unknown' }
|
|
59
|
+
: {}),
|
|
56
60
|
...(advertisingId ? { advertisingId } : {}),
|
|
57
61
|
},
|
|
58
62
|
os: {
|
|
59
|
-
name: (
|
|
60
|
-
version: (
|
|
63
|
+
name: (_o = (_m = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getSystemName) === null || _m === void 0 ? void 0 : _m.call(DeviceInfo)) !== null && _o !== void 0 ? _o : 'unknown',
|
|
64
|
+
version: (_q = (_p = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getSystemVersion) === null || _p === void 0 ? void 0 : _p.call(DeviceInfo)) !== null && _q !== void 0 ? _q : 'unknown',
|
|
61
65
|
},
|
|
62
66
|
app: {
|
|
63
|
-
name: (
|
|
64
|
-
version: (
|
|
65
|
-
build: (
|
|
66
|
-
namespace: (
|
|
67
|
+
name: (_s = (_r = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getApplicationName) === null || _r === void 0 ? void 0 : _r.call(DeviceInfo)) !== null && _s !== void 0 ? _s : 'unknown',
|
|
68
|
+
version: (_v = (_u = (_t = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getVersion) === null || _t === void 0 ? void 0 : _t.call(DeviceInfo)) !== null && _u !== void 0 ? _u : pkg.version) !== null && _v !== void 0 ? _v : 'unknown',
|
|
69
|
+
build: (_x = (_w = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBuildNumber) === null || _w === void 0 ? void 0 : _w.call(DeviceInfo)) !== null && _x !== void 0 ? _x : 'unknown',
|
|
70
|
+
namespace: (_z = (_y = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBundleId) === null || _y === void 0 ? void 0 : _y.call(DeviceInfo)) !== null && _z !== void 0 ? _z : 'unknown',
|
|
67
71
|
},
|
|
68
72
|
screen: {
|
|
69
73
|
width: Math.round(width),
|
|
70
74
|
height: Math.round(height),
|
|
71
75
|
density,
|
|
72
76
|
},
|
|
73
|
-
...(Platform.OS ===
|
|
77
|
+
...(Platform.OS === 'android'
|
|
74
78
|
? {
|
|
75
79
|
network: {
|
|
76
|
-
wifi: (
|
|
80
|
+
wifi: (_1 = (await ((_0 = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.isWifiEnabled) === null || _0 === void 0 ? void 0 : _0.call(DeviceInfo)))) !== null && _1 !== void 0 ? _1 : false,
|
|
77
81
|
},
|
|
78
82
|
}
|
|
79
83
|
: {}),
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { NetworkReachability, NetworkStatus } from './networkMonitor';
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a {@link NetworkReachability} with asymmetric debouncing:
|
|
4
|
+
* - **offline** transitions fire immediately (pause HTTP ASAP — no point
|
|
5
|
+
* burning retries on a down network).
|
|
6
|
+
* - **online** transitions wait for {@link ONLINE_DEBOUNCE_MS} of stable
|
|
7
|
+
* connectivity before firing, so flaky WiFi/cellular handoffs don't
|
|
8
|
+
* trigger spurious flush attempts that immediately fail.
|
|
9
|
+
*
|
|
10
|
+
* A pending online debounce is cancelled if offline arrives during the wait.
|
|
11
|
+
*/
|
|
12
|
+
export declare class DebouncedNetworkMonitor implements NetworkReachability {
|
|
13
|
+
static readonly ONLINE_DEBOUNCE_MS = 2000;
|
|
14
|
+
private readonly inner;
|
|
15
|
+
private handler;
|
|
16
|
+
private unsubscribeInner;
|
|
17
|
+
private onlineTimer;
|
|
18
|
+
private _currentStatus;
|
|
19
|
+
constructor(inner: NetworkReachability);
|
|
20
|
+
get currentStatus(): NetworkStatus;
|
|
21
|
+
onStatusChange(handler: (status: NetworkStatus) => void): () => void;
|
|
22
|
+
stop(): void;
|
|
23
|
+
private clearOnlineTimer;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=debouncedNetworkMonitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debouncedNetworkMonitor.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/debouncedNetworkMonitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE3E;;;;;;;;;GASG;AACH,qBAAa,uBAAwB,YAAW,mBAAmB;IACjE,MAAM,CAAC,QAAQ,CAAC,kBAAkB,QAAQ;IAE1C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAsB;IAC5C,OAAO,CAAC,OAAO,CAAkD;IACjE,OAAO,CAAC,gBAAgB,CAA6B;IACrD,OAAO,CAAC,WAAW,CAA8C;IACjE,OAAO,CAAC,cAAc,CAAgB;gBAE1B,KAAK,EAAE,mBAAmB;IA8BtC,IAAI,aAAa,IAAI,aAAa,CAEjC;IAED,cAAc,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,GAAG,MAAM,IAAI;IAOpE,IAAI,IAAI,IAAI;IAOZ,OAAO,CAAC,gBAAgB;CAMzB"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps a {@link NetworkReachability} with asymmetric debouncing:
|
|
3
|
+
* - **offline** transitions fire immediately (pause HTTP ASAP — no point
|
|
4
|
+
* burning retries on a down network).
|
|
5
|
+
* - **online** transitions wait for {@link ONLINE_DEBOUNCE_MS} of stable
|
|
6
|
+
* connectivity before firing, so flaky WiFi/cellular handoffs don't
|
|
7
|
+
* trigger spurious flush attempts that immediately fail.
|
|
8
|
+
*
|
|
9
|
+
* A pending online debounce is cancelled if offline arrives during the wait.
|
|
10
|
+
*/
|
|
11
|
+
export class DebouncedNetworkMonitor {
|
|
12
|
+
constructor(inner) {
|
|
13
|
+
this.handler = null;
|
|
14
|
+
this.unsubscribeInner = null;
|
|
15
|
+
this.onlineTimer = null;
|
|
16
|
+
this.inner = inner;
|
|
17
|
+
this._currentStatus = inner.currentStatus;
|
|
18
|
+
this.unsubscribeInner = inner.onStatusChange((rawStatus) => {
|
|
19
|
+
var _a;
|
|
20
|
+
if (rawStatus === 'disconnected') {
|
|
21
|
+
this.clearOnlineTimer();
|
|
22
|
+
if (this._currentStatus !== 'disconnected') {
|
|
23
|
+
this._currentStatus = 'disconnected';
|
|
24
|
+
(_a = this.handler) === null || _a === void 0 ? void 0 : _a.call(this, 'disconnected');
|
|
25
|
+
}
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// rawStatus === 'connected': start/reset the debounce window
|
|
29
|
+
this.clearOnlineTimer();
|
|
30
|
+
if (this._currentStatus === 'connected')
|
|
31
|
+
return;
|
|
32
|
+
this.onlineTimer = setTimeout(() => {
|
|
33
|
+
var _a;
|
|
34
|
+
this.onlineTimer = null;
|
|
35
|
+
// Guard against racing with a late offline transition.
|
|
36
|
+
if (this.inner.currentStatus !== 'connected')
|
|
37
|
+
return;
|
|
38
|
+
if (this._currentStatus !== 'connected') {
|
|
39
|
+
this._currentStatus = 'connected';
|
|
40
|
+
(_a = this.handler) === null || _a === void 0 ? void 0 : _a.call(this, 'connected');
|
|
41
|
+
}
|
|
42
|
+
}, DebouncedNetworkMonitor.ONLINE_DEBOUNCE_MS);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
get currentStatus() {
|
|
46
|
+
return this._currentStatus;
|
|
47
|
+
}
|
|
48
|
+
onStatusChange(handler) {
|
|
49
|
+
this.handler = handler;
|
|
50
|
+
return () => {
|
|
51
|
+
this.handler = null;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
stop() {
|
|
55
|
+
var _a;
|
|
56
|
+
this.clearOnlineTimer();
|
|
57
|
+
(_a = this.unsubscribeInner) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
58
|
+
this.unsubscribeInner = null;
|
|
59
|
+
this.handler = null;
|
|
60
|
+
}
|
|
61
|
+
clearOnlineTimer() {
|
|
62
|
+
if (this.onlineTimer) {
|
|
63
|
+
clearTimeout(this.onlineTimer);
|
|
64
|
+
this.onlineTimer = null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
DebouncedNetworkMonitor.ONLINE_DEBOUNCE_MS = 2000;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type NetworkStatus = 'connected' | 'disconnected';
|
|
2
|
+
export interface NetworkReachability {
|
|
3
|
+
/** Current connectivity snapshot */
|
|
4
|
+
readonly currentStatus: NetworkStatus;
|
|
5
|
+
/** Register callback for status transitions. Returns unsubscribe function. */
|
|
6
|
+
onStatusChange(handler: (status: NetworkStatus) => void): () => void;
|
|
7
|
+
/** Tear down monitoring */
|
|
8
|
+
stop(): void;
|
|
9
|
+
}
|
|
10
|
+
export declare class NetworkMonitor implements NetworkReachability {
|
|
11
|
+
private _currentStatus;
|
|
12
|
+
private handler;
|
|
13
|
+
private unsubscribe;
|
|
14
|
+
private receivedNativeEvent;
|
|
15
|
+
get currentStatus(): NetworkStatus;
|
|
16
|
+
constructor();
|
|
17
|
+
onStatusChange(handler: (status: NetworkStatus) => void): () => void;
|
|
18
|
+
stop(): void;
|
|
19
|
+
}
|
|
20
|
+
export declare class StubNetworkMonitor implements NetworkReachability {
|
|
21
|
+
private _currentStatus;
|
|
22
|
+
private handler;
|
|
23
|
+
get currentStatus(): NetworkStatus;
|
|
24
|
+
constructor(initialStatus?: NetworkStatus);
|
|
25
|
+
onStatusChange(handler: (status: NetworkStatus) => void): () => void;
|
|
26
|
+
stop(): void;
|
|
27
|
+
/** Simulate a network transition from tests */
|
|
28
|
+
simulate(status: NetworkStatus): void;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=networkMonitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networkMonitor.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/networkMonitor.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,cAAc,CAAC;AAEzD,MAAM,WAAW,mBAAmB;IAClC,oCAAoC;IACpC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,8EAA8E;IAC9E,cAAc,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACrE,2BAA2B;IAC3B,IAAI,IAAI,IAAI,CAAC;CACd;AAED,qBAAa,cAAe,YAAW,mBAAmB;IACxD,OAAO,CAAC,cAAc,CAA8B;IACpD,OAAO,CAAC,OAAO,CAAkD;IACjE,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,mBAAmB,CAAS;IAEpC,IAAI,aAAa,IAAI,aAAa,CAEjC;;IAqDD,cAAc,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,GAAG,MAAM,IAAI;IAOpE,IAAI,IAAI,IAAI;CAKb;AAED,qBAAa,kBAAmB,YAAW,mBAAmB;IAC5D,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,OAAO,CAAkD;IAEjE,IAAI,aAAa,IAAI,aAAa,CAEjC;gBAEW,aAAa,GAAE,aAA2B;IAItD,cAAc,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,GAAG,MAAM,IAAI;IAOpE,IAAI,IAAI,IAAI;IAIZ,+CAA+C;IAC/C,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;CAMtC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { warn } from './logger';
|
|
2
|
+
export class NetworkMonitor {
|
|
3
|
+
get currentStatus() {
|
|
4
|
+
return this._currentStatus;
|
|
5
|
+
}
|
|
6
|
+
constructor() {
|
|
7
|
+
this._currentStatus = 'connected';
|
|
8
|
+
this.handler = null;
|
|
9
|
+
this.unsubscribe = null;
|
|
10
|
+
this.receivedNativeEvent = false;
|
|
11
|
+
try {
|
|
12
|
+
const { NativeModules, NativeEventEmitter } = require('react-native');
|
|
13
|
+
const MetaRouterNetworkMonitor = NativeModules.MetaRouterNetworkMonitor;
|
|
14
|
+
if (!MetaRouterNetworkMonitor)
|
|
15
|
+
throw new Error('Native module not available');
|
|
16
|
+
// Get initial state from native — skip if a live event already arrived
|
|
17
|
+
MetaRouterNetworkMonitor.getCurrentStatus()
|
|
18
|
+
.then((connected) => {
|
|
19
|
+
var _a;
|
|
20
|
+
if (this.receivedNativeEvent)
|
|
21
|
+
return;
|
|
22
|
+
const newStatus = connected
|
|
23
|
+
? 'connected'
|
|
24
|
+
: 'disconnected';
|
|
25
|
+
if (newStatus !== this._currentStatus) {
|
|
26
|
+
this._currentStatus = newStatus;
|
|
27
|
+
(_a = this.handler) === null || _a === void 0 ? void 0 : _a.call(this, newStatus);
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
.catch((err) => {
|
|
31
|
+
warn('Failed to get initial network status, defaulting to connected', err);
|
|
32
|
+
});
|
|
33
|
+
// Subscribe to native connectivity events
|
|
34
|
+
const emitter = new NativeEventEmitter(MetaRouterNetworkMonitor);
|
|
35
|
+
const subscription = emitter.addListener('onConnectivityChange', (event) => {
|
|
36
|
+
var _a;
|
|
37
|
+
this.receivedNativeEvent = true;
|
|
38
|
+
const newStatus = event.isConnected
|
|
39
|
+
? 'connected'
|
|
40
|
+
: 'disconnected';
|
|
41
|
+
if (newStatus !== this._currentStatus) {
|
|
42
|
+
this._currentStatus = newStatus;
|
|
43
|
+
(_a = this.handler) === null || _a === void 0 ? void 0 : _a.call(this, newStatus);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
this.unsubscribe = () => subscription.remove();
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
warn('Native network monitor not available, defaulting to connected', err);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
onStatusChange(handler) {
|
|
53
|
+
this.handler = handler;
|
|
54
|
+
return () => {
|
|
55
|
+
this.handler = null;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
stop() {
|
|
59
|
+
var _a;
|
|
60
|
+
(_a = this.unsubscribe) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
61
|
+
this.unsubscribe = null;
|
|
62
|
+
this.handler = null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export class StubNetworkMonitor {
|
|
66
|
+
get currentStatus() {
|
|
67
|
+
return this._currentStatus;
|
|
68
|
+
}
|
|
69
|
+
constructor(initialStatus = 'connected') {
|
|
70
|
+
this.handler = null;
|
|
71
|
+
this._currentStatus = initialStatus;
|
|
72
|
+
}
|
|
73
|
+
onStatusChange(handler) {
|
|
74
|
+
this.handler = handler;
|
|
75
|
+
return () => {
|
|
76
|
+
this.handler = null;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
stop() {
|
|
80
|
+
this.handler = null;
|
|
81
|
+
}
|
|
82
|
+
/** Simulate a network transition from tests */
|
|
83
|
+
simulate(status) {
|
|
84
|
+
var _a;
|
|
85
|
+
if (status !== this._currentStatus) {
|
|
86
|
+
this._currentStatus = status;
|
|
87
|
+
(_a = this.handler) === null || _a === void 0 ? void 0 : _a.call(this, status);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared classification of HTTP status codes used by both
|
|
3
|
+
* the dispatcher and the disk drain.
|
|
4
|
+
*/
|
|
5
|
+
export declare enum ResponseCategory {
|
|
6
|
+
SUCCESS = "SUCCESS",
|
|
7
|
+
SERVER_ERROR = "SERVER_ERROR",
|
|
8
|
+
RATE_LIMITED = "RATE_LIMITED",
|
|
9
|
+
PAYLOAD_TOO_LARGE = "PAYLOAD_TOO_LARGE",
|
|
10
|
+
FATAL_CONFIG = "FATAL_CONFIG",
|
|
11
|
+
CLIENT_ERROR = "CLIENT_ERROR"
|
|
12
|
+
}
|
|
13
|
+
export declare function categorizeResponse(statusCode: number): ResponseCategory;
|
|
14
|
+
//# sourceMappingURL=responseCategory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responseCategory.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/responseCategory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,gBAAgB;IAC1B,OAAO,YAAY;IACnB,YAAY,iBAAiB;IAC7B,YAAY,iBAAiB;IAC7B,iBAAiB,sBAAsB;IACvC,YAAY,iBAAiB;IAC7B,YAAY,iBAAiB;CAC9B;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,gBAAgB,CASvE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared classification of HTTP status codes used by both
|
|
3
|
+
* the dispatcher and the disk drain.
|
|
4
|
+
*/
|
|
5
|
+
export var ResponseCategory;
|
|
6
|
+
(function (ResponseCategory) {
|
|
7
|
+
ResponseCategory["SUCCESS"] = "SUCCESS";
|
|
8
|
+
ResponseCategory["SERVER_ERROR"] = "SERVER_ERROR";
|
|
9
|
+
ResponseCategory["RATE_LIMITED"] = "RATE_LIMITED";
|
|
10
|
+
ResponseCategory["PAYLOAD_TOO_LARGE"] = "PAYLOAD_TOO_LARGE";
|
|
11
|
+
ResponseCategory["FATAL_CONFIG"] = "FATAL_CONFIG";
|
|
12
|
+
ResponseCategory["CLIENT_ERROR"] = "CLIENT_ERROR";
|
|
13
|
+
})(ResponseCategory || (ResponseCategory = {}));
|
|
14
|
+
export function categorizeResponse(statusCode) {
|
|
15
|
+
if (statusCode >= 200 && statusCode < 300)
|
|
16
|
+
return ResponseCategory.SUCCESS;
|
|
17
|
+
if (statusCode >= 500 || statusCode === 408)
|
|
18
|
+
return ResponseCategory.SERVER_ERROR;
|
|
19
|
+
if (statusCode === 429)
|
|
20
|
+
return ResponseCategory.RATE_LIMITED;
|
|
21
|
+
if (statusCode === 413)
|
|
22
|
+
return ResponseCategory.PAYLOAD_TOO_LARGE;
|
|
23
|
+
if (statusCode === 401 || statusCode === 403 || statusCode === 404)
|
|
24
|
+
return ResponseCategory.FATAL_CONFIG;
|
|
25
|
+
return ResponseCategory.CLIENT_ERROR;
|
|
26
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "metarouter-react-native-sdk"
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = "MetaRouter React Native SDK native modules"
|
|
9
|
+
s.homepage = package['repository']['url']
|
|
10
|
+
s.license = package['license']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version }
|
|
13
|
+
|
|
14
|
+
s.platform = :ios, '13.0'
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
17
|
+
|
|
18
|
+
s.dependency "React-Core"
|
|
19
|
+
end
|