351 lines
10 KiB
JavaScript
351 lines
10 KiB
JavaScript
// Metro module 504 (f505).
|
|
import { TelemetryEvents, TelemetryEndpoints } from "./Module505";
|
|
import { IdGenerator } from "./Module510";
|
|
import { extractId } from "./Module513";
|
|
import { v4 } from "./Module514";
|
|
import { HTTP } from "./sendRequest";
|
|
import Module589 from "./Module589";
|
|
import { HermesBuiltin, $deriveClass } from "../_hermes/prelude";
|
|
function $mk117527($env) {
|
|
return () => {
|
|
const r7 = $env;
|
|
(0, $env.$parent[10])();
|
|
const r6 = $env.$parent.$parent;
|
|
const r4 = r6[6];
|
|
const r19 = 0.1 * r4;
|
|
const r28 = Math.max(r4 + (Math.floor(Math.random() * r19 * 2) - r19), r6[7]);
|
|
r6[20] = {
|
|
type: "timeout",
|
|
id: setTimeout($mk117527(r7), r28)
|
|
};
|
|
};
|
|
}
|
|
let requestIdleCallback2, c488_27, c488_28, defaultGetSessionId;
|
|
let env488 = {};
|
|
const c488_5 = "x-science-test";
|
|
const c488_6 = 3600000;
|
|
const c488_7 = 60000;
|
|
const c488_8 = 3600000;
|
|
env488[9] = 1500;
|
|
env488[10] = 0;
|
|
env488[11] = 0;
|
|
env488[12] = 0;
|
|
env488[13] = 0;
|
|
env488[14] = 0;
|
|
env488[15] = null;
|
|
env488[16] = 0;
|
|
env488[17] = Number.MAX_SAFE_INTEGER;
|
|
env488[18] = 0;
|
|
env488[19] = 0;
|
|
env488[20] = null;
|
|
env488[21] = false;
|
|
env488[22] = null;
|
|
env488[23] = null;
|
|
let requestIdleCallback3 = window.requestIdleCallback;
|
|
if (requestIdleCallback3 == null) {
|
|
requestIdleCallback3 = (c12343_0) => setImmediate(() => c12343_0());
|
|
}
|
|
requestIdleCallback2 = requestIdleCallback3;
|
|
c488_27 = new IdGenerator();
|
|
c488_28 = {
|
|
handleConnectionOpen: () => {},
|
|
handleConnectionClosed: () => {},
|
|
handleFingerprint: () => {},
|
|
handleTrack: () => {},
|
|
handleSetAnalyticsToken: () => {}
|
|
};
|
|
env488[29] = [];
|
|
env488[30] = null;
|
|
defaultGetSessionId = () => Promise.resolve({
|
|
sessionId: void 0
|
|
});
|
|
export { c488_28 as AnalyticsActionHandlers };
|
|
export const analyticsTrackingStoreMaker = (a0) => {
|
|
let env12344 = {
|
|
$parent: env488
|
|
};
|
|
const { dispatcher, actionHandler } = a0;
|
|
env12344[0] = a0.getFingerprint;
|
|
let getSessionId = a0.getSessionId;
|
|
if (getSessionId === void 0) {
|
|
getSessionId = defaultGetSessionId;
|
|
}
|
|
env12344[1] = getSessionId;
|
|
env12344[2] = a0.TRACKING_URL;
|
|
let drainTimeoutOverride = a0.drainTimeoutOverride;
|
|
env12344[3] = a0.waitFor;
|
|
let scheduleWhenIdle = a0.scheduleWhenIdle;
|
|
if (scheduleWhenIdle === void 0) {
|
|
scheduleWhenIdle = requestIdleCallback2;
|
|
}
|
|
env12344[4] = scheduleWhenIdle;
|
|
let getLaunchSignature = a0.getLaunchSignature;
|
|
if (getLaunchSignature === void 0) {
|
|
getLaunchSignature = () => null;
|
|
}
|
|
env12344[5] = getLaunchSignature;
|
|
env12344[6] = a0.submitEvents;
|
|
env12344[7] = function scheduleDrain({ shouldFlushOnNextTick }) {
|
|
if (shouldFlushOnNextTick === void 0) {
|
|
shouldFlushOnNextTick = false;
|
|
}
|
|
if (env488[30] == null && (env488[29].length !== 0 && (env488[25] != null ? env488[24] != null : (0, env12344[0])() != null))) {
|
|
env488[30] = shouldFlushOnNextTick ? setTimeout(env12344[8], 0) : (0, env12344[4])(env12344[8], {
|
|
timeout: env488[9]
|
|
});
|
|
}
|
|
};
|
|
env12344[8] = function drainEventsQueue() {
|
|
env488[30] = null;
|
|
if (env488[29].length !== 0 && (env488[25] != null ? env488[24] != null : (0, env12344[0])() != null)) {
|
|
const r25 = env488[29].slice();
|
|
let c23791_0 = r25;
|
|
env488[29] = [];
|
|
env488[16] = env488[16] + 1;
|
|
let length = r25.length;
|
|
env488[17] = Math.min(env488[17], length);
|
|
env488[18] = Math.max(env488[18], length);
|
|
const r35 = env488[19];
|
|
if (length === void 0) {
|
|
length = 1;
|
|
}
|
|
env488[19] = r35 + length;
|
|
const r39 = (0, env12344[9])(r25);
|
|
r39.then(() => {
|
|
c23791_0.forEach((item) => {
|
|
const resolve2 = item.resolve;
|
|
if (resolve2 != null) {
|
|
resolve2.call(item);
|
|
}
|
|
});
|
|
env488[12] = env488[12] + 1;
|
|
}, (a0) => {
|
|
const r6 = env488[29];
|
|
r6.unshift.apply(r6, [...c23791_0]);
|
|
env488[13] = env488[13] + 1;
|
|
(a0.body || a0).message;
|
|
});
|
|
return r39;
|
|
}
|
|
return Promise.resolve();
|
|
};
|
|
env12344[9] = function submitEventsImmediately(a0, a1) {
|
|
let c23792_1;
|
|
const client_send_timestamp = Date.now();
|
|
const events = a0.map((item) => ({
|
|
...item,
|
|
properties: {
|
|
...item.properties,
|
|
client_send_timestamp
|
|
}
|
|
}));
|
|
const r15 = env12344[6];
|
|
if (r15 != null) {
|
|
return r15(events, env488[24]);
|
|
}
|
|
const url = a1 == null ? env12344[2] : a1;
|
|
const headers = {};
|
|
c23792_1 = headers;
|
|
if (!env488[21]) {
|
|
const r23 = v4();
|
|
env488[23] = r23;
|
|
headers[c488_5] = r23;
|
|
env488[21] = true;
|
|
}
|
|
return HTTP.post({
|
|
url,
|
|
headers,
|
|
body: {
|
|
token: env488[24],
|
|
events
|
|
},
|
|
retries: 3,
|
|
rejectWithError: false
|
|
}).then((result) => {
|
|
if (c23792_1[c488_5]) {
|
|
const r2 = result == null;
|
|
let r10 = void 0;
|
|
if (!r2) {
|
|
const headers = result.headers;
|
|
r10 = headers == null ? void 0 : headers[c488_5];
|
|
}
|
|
if (r10 == null) {
|
|
r10 = null;
|
|
}
|
|
env488[22] = r10;
|
|
}
|
|
return result;
|
|
});
|
|
};
|
|
env12344[10] = function sendTelemetryEvent() {
|
|
const properties2 = {
|
|
client_track_timestamp: Date.now(),
|
|
rpc_success_count: env488[12],
|
|
rpc_failure_count: env488[13],
|
|
first_seen_event_sequence_number: env488[14],
|
|
last_seen_event_sequence_number: env488[10],
|
|
telemetry_period_start_timestamp: env488[15],
|
|
telemetry_period_end_timestamp: Date.now(),
|
|
event_queue_rejection_count: env488[11],
|
|
event_queue_batch_count: env488[16],
|
|
event_queue_batch_min_size: env488[17] !== Number.MAX_SAFE_INTEGER ? env488[17] : 0,
|
|
event_queue_batch_max_size: env488[18],
|
|
event_queue_batch_avg_size: null,
|
|
science_request_id: null,
|
|
science_response: null,
|
|
launch_signature: null
|
|
};
|
|
const r28 = env488[16];
|
|
properties2.event_queue_batch_avg_size = r28 > 0 ? env488[19] / r28 : 0;
|
|
properties2.science_request_id = env488[23];
|
|
properties2.science_response = env488[22];
|
|
properties2.launch_signature = (0, env12344[5])();
|
|
const r8 = {
|
|
type: TelemetryEvents.CLIENT_TELEMETRY,
|
|
properties: properties2
|
|
};
|
|
env488[11] = 0;
|
|
env488[12] = 0;
|
|
env488[13] = 0;
|
|
env488[16] = 0;
|
|
env488[17] = Number.MAX_SAFE_INTEGER;
|
|
env488[18] = 0;
|
|
env488[19] = 0;
|
|
env488[15] = Date.now();
|
|
env488[14] = env488[10];
|
|
return (0, env12344[9])([r8], TelemetryEndpoints.CLIENT_TELEMETRY);
|
|
};
|
|
if (drainTimeoutOverride == null) {
|
|
drainTimeoutOverride = 1500;
|
|
}
|
|
env488[9] = drainTimeoutOverride;
|
|
c488_28.handleConnectionOpen = function({ analyticsToken, user }) {
|
|
if (analyticsToken != null) {
|
|
env488[24] = analyticsToken;
|
|
}
|
|
if (user.id != null) {
|
|
env488[25] = user.id;
|
|
}
|
|
if (env488[20] == null) {
|
|
let env23793 = {
|
|
$parent: env12344
|
|
};
|
|
const r7 = Math;
|
|
const r18 = Math.random();
|
|
const r22 = r7.floor(r18 * (c488_8 - c488_7) + c488_7);
|
|
env23793[0] = () => {};
|
|
env488[20] = {
|
|
type: "timeout",
|
|
id: setTimeout(() => {
|
|
const r7 = env23793;
|
|
(0, env12344[10])();
|
|
const r19 = 0.1 * c488_6;
|
|
const r28 = Math.max(c488_6 + (Math.floor(Math.random() * r19 * 2) - r19), c488_7);
|
|
env488[20] = {
|
|
type: "timeout",
|
|
id: setTimeout($mk117527(r7), r28)
|
|
};
|
|
}, r22)
|
|
};
|
|
}
|
|
(0, env12344[7])({
|
|
shouldFlushOnNextTick: false
|
|
});
|
|
return false;
|
|
};
|
|
c488_28.handleConnectionClosed = function() {
|
|
(0, env12344[8])();
|
|
if (env488[20] != null) {
|
|
const type = env488[20].type;
|
|
if (type === "timeout") {
|
|
clearTimeout(env488[20].id);
|
|
} else if (type === "interval") {
|
|
clearInterval(env488[20].id);
|
|
} else {
|
|
env488[20].type;
|
|
}
|
|
env488[20] = null;
|
|
}
|
|
env488[24] = null;
|
|
env488[25] = null;
|
|
return false;
|
|
};
|
|
c488_28.handleFingerprint = function() {
|
|
(0, env12344[8])();
|
|
return false;
|
|
};
|
|
c488_28.handleTrack = function({ event, properties, flush, fingerprint, resolve }) {
|
|
(0, env12344[1])().then(({ sessionId }) => {
|
|
let r9;
|
|
const properties2 = {
|
|
client_track_timestamp: Date.now(),
|
|
client_heartbeat_session_id: sessionId,
|
|
event_sequence_number: null
|
|
};
|
|
const event_sequence_number = env488[10] + 1;
|
|
env488[10] = event_sequence_number;
|
|
properties2.event_sequence_number = event_sequence_number;
|
|
HermesBuiltin.copyDataProperties(properties2, properties);
|
|
const r7 = {
|
|
type: event,
|
|
fingerprint,
|
|
properties: properties2,
|
|
resolve
|
|
};
|
|
if (env488[25] != null) {
|
|
r9 = env488[25];
|
|
} else {
|
|
let fingerprint2 = r7.fingerprint;
|
|
if (fingerprint2 == null) {
|
|
fingerprint2 = (0, env12344[0])();
|
|
}
|
|
r9 = fingerprint2 != null ? extractId(fingerprint2) : null;
|
|
}
|
|
if (r9 != null) {
|
|
r7.properties.client_uuid = c488_27.generate(r9);
|
|
}
|
|
env488[29].push(r7);
|
|
if (env488[29].length > 10000) {
|
|
env488[11] = env488[11] + (env488[29].length - 10000);
|
|
env488[29] = env488[29].slice(-10000);
|
|
}
|
|
env12344[7](flush ? {
|
|
shouldFlushOnNextTick: true
|
|
} : {
|
|
shouldFlushOnNextTick: false
|
|
});
|
|
});
|
|
return false;
|
|
};
|
|
c488_28.handleSetAnalyticsToken = function({ analyticsToken, userId }) {
|
|
if (env488[24] == null && analyticsToken != null) {
|
|
env488[24] = analyticsToken;
|
|
env488[25] = userId;
|
|
(0, env12344[7])({
|
|
shouldFlushOnNextTick: false
|
|
});
|
|
}
|
|
return false;
|
|
};
|
|
const r35 = $deriveClass(function AnalyticsTrackingStore() {
|
|
const prototypeOf = Object.getPrototypeOf(env12344[11]);
|
|
const r2 = new.target;
|
|
const r7 = HermesBuiltin.applyArguments(prototypeOf, Object.create(r2.prototype), r2);
|
|
r7.submitEventsImmediately = env12344[9];
|
|
return r7;
|
|
}, Module589.Store);
|
|
Object.defineProperty(r35.prototype, "initialize", {
|
|
value: function initialize() {
|
|
const r5 = env12344[3];
|
|
if (r5 != null) {
|
|
this.waitFor.apply(this, [...r5]);
|
|
}
|
|
},
|
|
writable: true,
|
|
configurable: true
|
|
});
|
|
env12344[11] = r35;
|
|
r35.displayName = "AnalyticsTrackingStore";
|
|
return new r35(dispatcher, actionHandler);
|
|
};
|