From 0e5d7f23a3a03fe0305abe395af46c7498f2d9a5 Mon Sep 17 00:00:00 2001 From: Alex Kaminskii Date: Mon, 15 Aug 2022 01:19:54 +0200 Subject: [PATCH] feat(fr;ontend/player): maintain new message format --- .../messages/JSONRawMessageReader.ts | 49 +- .../messages/RawMessageReader.ts | 182 ----- .../MessageDistributor/messages/message.ts | 45 -- .../player/MessageDistributor/messages/raw.ts | 177 +--- .../messages/tracker-legacy.ts | 72 ++ .../MessageDistributor/messages/tracker.ts | 757 ++++++++++++++++++ ...stributor~messages~RawMessageReader.ts.erb | 2 +- ...MessageDistributor~messages~message.ts.erb | 4 +- ...yer~MessageDistributor~messages~raw.ts.erb | 8 +- ...Distributor~messages~tracker-legacy.ts.erb | 8 + ...MessageDistributor~messages~tracker.ts.erb | 28 + 11 files changed, 903 insertions(+), 429 deletions(-) create mode 100644 frontend/app/player/MessageDistributor/messages/tracker-legacy.ts create mode 100644 frontend/app/player/MessageDistributor/messages/tracker.ts create mode 100644 mobs/templates/frontend~app~player~MessageDistributor~messages~tracker-legacy.ts.erb create mode 100644 mobs/templates/frontend~app~player~MessageDistributor~messages~tracker.ts.erb diff --git a/frontend/app/player/MessageDistributor/messages/JSONRawMessageReader.ts b/frontend/app/player/MessageDistributor/messages/JSONRawMessageReader.ts index d66d80d00..0a5677824 100644 --- a/frontend/app/player/MessageDistributor/messages/JSONRawMessageReader.ts +++ b/frontend/app/player/MessageDistributor/messages/JSONRawMessageReader.ts @@ -11,11 +11,24 @@ import type { RawAdoptedSsReplaceURLBased, RawAdoptedSsReplace, } from './raw' -import { TP_MAP } from './raw' +import type { TrackerMessage } from './tracker' +import translate from './tracker' +import { TP_MAP } from './tracker-legacy' import { resolveURL, resolveCSS } from './urlResolve' -// TODO: commonURLBased logic +function legacyTranslate(msg: any): RawMessage | null { + const type = TP_MAP[msg._id as keyof typeof TP_MAP] + if (!type) { + return null + } + msg.tp = type + delete msg._id + return msg as RawMessage +} + + +// TODO: commonURLBased logic for feilds const resolvers = { "set_node_attribute_url_based": (msg: RawSetNodeAttributeURLBased): RawSetNodeAttribute => ({ @@ -54,32 +67,34 @@ const resolvers = { }) } as const -type ResolvingTypes = keyof typeof resolvers -type Resolver = typeof resolvers[ResolvingTypes] +type ResolvableType = keyof typeof resolvers +type ResolvableRawMessage = RawMessage & { tp: ResolvableType } + +function isResolvable(msg: RawMessage): msg is ResolvableRawMessage { + //@ts-ignore + return resolvers[msg.tp] !== undefined +} -type NumTypes = keyof typeof TP_MAP export default class JSONRawMessageReader { - constructor(private messages: any[] = []){} - append(messages: any[]) { + constructor(private messages: TrackerMessage[] = []){} + append(messages: TrackerMessage[]) { this.messages = this.messages.concat(messages) } readMessage(): RawMessage | null { let msg = this.messages.shift() if (!msg) { return null } - const type = TP_MAP[msg._id as NumTypes] - if (!type) { // Ignore unknown message types - // log here + const rawMsg = Array.isArray(msg) + ? translate(msg) + : legacyTranslate(msg) + if (!rawMsg) { return this.readMessage() } - msg.tp = type - delete msg._id - - const resolver: Resolver | undefined = resolvers[type as ResolvingTypes] - if (resolver) { - msg = resolver(msg) + if (isResolvable(rawMsg)) { + //@ts-ignore ??? too complex typscript... + return resolvers[rawMsg.tp](rawMsg) } - return msg as RawMessage + return rawMsg } } \ No newline at end of file diff --git a/frontend/app/player/MessageDistributor/messages/RawMessageReader.ts b/frontend/app/player/MessageDistributor/messages/RawMessageReader.ts index bff6b217f..4536a7c0e 100644 --- a/frontend/app/player/MessageDistributor/messages/RawMessageReader.ts +++ b/frontend/app/player/MessageDistributor/messages/RawMessageReader.ts @@ -17,44 +17,6 @@ export default class RawMessageReader extends PrimitiveReader { switch (tp) { - case 80: { - const pageNo = this.readUint(); if (pageNo === null) { return resetPointer() } - const firstIndex = this.readUint(); if (firstIndex === null) { return resetPointer() } - const timestamp = this.readInt(); if (timestamp === null) { return resetPointer() } - return { - tp: "batch_meta", - pageNo, - firstIndex, - timestamp, - }; - } - - case 81: { - const version = this.readUint(); if (version === null) { return resetPointer() } - const pageNo = this.readUint(); if (pageNo === null) { return resetPointer() } - const firstIndex = this.readUint(); if (firstIndex === null) { return resetPointer() } - const timestamp = this.readInt(); if (timestamp === null) { return resetPointer() } - const location = this.readString(); if (location === null) { return resetPointer() } - return { - tp: "batch_metadata", - version, - pageNo, - firstIndex, - timestamp, - location, - }; - } - - case 82: { - const partNo = this.readUint(); if (partNo === null) { return resetPointer() } - const partTotal = this.readUint(); if (partTotal === null) { return resetPointer() } - return { - tp: "partitioned_message", - partNo, - partTotal, - }; - } - case 0: { const timestamp = this.readUint(); if (timestamp === null) { return resetPointer() } return { @@ -205,16 +167,6 @@ export default class RawMessageReader extends PrimitiveReader { }; } - case 17: { - const id = this.readUint(); if (id === null) { return resetPointer() } - const label = this.readString(); if (label === null) { return resetPointer() } - return { - tp: "set_input_target", - id, - label, - }; - } - case 18: { const id = this.readUint(); if (id === null) { return resetPointer() } const value = this.readString(); if (value === null) { return resetPointer() } @@ -257,90 +209,6 @@ export default class RawMessageReader extends PrimitiveReader { }; } - case 23: { - const requestStart = this.readUint(); if (requestStart === null) { return resetPointer() } - const responseStart = this.readUint(); if (responseStart === null) { return resetPointer() } - const responseEnd = this.readUint(); if (responseEnd === null) { return resetPointer() } - const domContentLoadedEventStart = this.readUint(); if (domContentLoadedEventStart === null) { return resetPointer() } - const domContentLoadedEventEnd = this.readUint(); if (domContentLoadedEventEnd === null) { return resetPointer() } - const loadEventStart = this.readUint(); if (loadEventStart === null) { return resetPointer() } - const loadEventEnd = this.readUint(); if (loadEventEnd === null) { return resetPointer() } - const firstPaint = this.readUint(); if (firstPaint === null) { return resetPointer() } - const firstContentfulPaint = this.readUint(); if (firstContentfulPaint === null) { return resetPointer() } - return { - tp: "page_load_timing", - requestStart, - responseStart, - responseEnd, - domContentLoadedEventStart, - domContentLoadedEventEnd, - loadEventStart, - loadEventEnd, - firstPaint, - firstContentfulPaint, - }; - } - - case 24: { - const speedIndex = this.readUint(); if (speedIndex === null) { return resetPointer() } - const visuallyComplete = this.readUint(); if (visuallyComplete === null) { return resetPointer() } - const timeToInteractive = this.readUint(); if (timeToInteractive === null) { return resetPointer() } - return { - tp: "page_render_timing", - speedIndex, - visuallyComplete, - timeToInteractive, - }; - } - - case 25: { - const name = this.readString(); if (name === null) { return resetPointer() } - const message = this.readString(); if (message === null) { return resetPointer() } - const payload = this.readString(); if (payload === null) { return resetPointer() } - return { - tp: "js_exception", - name, - message, - payload, - }; - } - - case 27: { - const name = this.readString(); if (name === null) { return resetPointer() } - const payload = this.readString(); if (payload === null) { return resetPointer() } - return { - tp: "raw_custom_event", - name, - payload, - }; - } - - case 28: { - const id = this.readString(); if (id === null) { return resetPointer() } - return { - tp: "user_id", - id, - }; - } - - case 29: { - const id = this.readString(); if (id === null) { return resetPointer() } - return { - tp: "user_anonymous_id", - id, - }; - } - - case 30: { - const key = this.readString(); if (key === null) { return resetPointer() } - const value = this.readString(); if (value === null) { return resetPointer() } - return { - tp: "metadata", - key, - value, - }; - } - case 37: { const id = this.readUint(); if (id === null) { return resetPointer() } const rule = this.readString(); if (rule === null) { return resetPointer() } @@ -407,14 +275,6 @@ export default class RawMessageReader extends PrimitiveReader { }; } - case 42: { - const type = this.readString(); if (type === null) { return resetPointer() } - return { - tp: "state_action", - type, - }; - } - case 44: { const action = this.readString(); if (action === null) { return resetPointer() } const state = this.readString(); if (state === null) { return resetPointer() } @@ -487,28 +347,6 @@ export default class RawMessageReader extends PrimitiveReader { }; } - case 53: { - const timestamp = this.readUint(); if (timestamp === null) { return resetPointer() } - const duration = this.readUint(); if (duration === null) { return resetPointer() } - const ttfb = this.readUint(); if (ttfb === null) { return resetPointer() } - const headerSize = this.readUint(); if (headerSize === null) { return resetPointer() } - const encodedBodySize = this.readUint(); if (encodedBodySize === null) { return resetPointer() } - const decodedBodySize = this.readUint(); if (decodedBodySize === null) { return resetPointer() } - const url = this.readString(); if (url === null) { return resetPointer() } - const initiator = this.readString(); if (initiator === null) { return resetPointer() } - return { - tp: "resource_timing", - timestamp, - duration, - ttfb, - headerSize, - encodedBodySize, - decodedBodySize, - url, - initiator, - }; - } - case 54: { const downlink = this.readUint(); if (downlink === null) { return resetPointer() } const type = this.readString(); if (type === null) { return resetPointer() } @@ -573,26 +411,6 @@ export default class RawMessageReader extends PrimitiveReader { }; } - case 63: { - const type = this.readString(); if (type === null) { return resetPointer() } - const value = this.readString(); if (value === null) { return resetPointer() } - return { - tp: "technical_info", - type, - value, - }; - } - - case 64: { - const name = this.readString(); if (name === null) { return resetPointer() } - const payload = this.readString(); if (payload === null) { return resetPointer() } - return { - tp: "custom_issue", - name, - payload, - }; - } - case 67: { const id = this.readUint(); if (id === null) { return resetPointer() } const rule = this.readString(); if (rule === null) { return resetPointer() } diff --git a/frontend/app/player/MessageDistributor/messages/message.ts b/frontend/app/player/MessageDistributor/messages/message.ts index 7414350a2..490f817ea 100644 --- a/frontend/app/player/MessageDistributor/messages/message.ts +++ b/frontend/app/player/MessageDistributor/messages/message.ts @@ -3,9 +3,6 @@ import type { Timed } from './timed' import type { RawMessage } from './raw' import type { - RawBatchMeta, - RawBatchMetadata, - RawPartitionedMessage, RawTimestamp, RawSetPageLocation, RawSetViewportSize, @@ -20,38 +17,26 @@ import type { RawSetNodeData, RawSetCssData, RawSetNodeScroll, - RawSetInputTarget, RawSetInputValue, RawSetInputChecked, RawMouseMove, RawConsoleLog, - RawPageLoadTiming, - RawPageRenderTiming, - RawJsException, - RawRawCustomEvent, - RawUserID, - RawUserAnonymousID, - RawMetadata, RawCssInsertRule, RawCssDeleteRule, RawFetch, RawProfiler, RawOTable, - RawStateAction, RawRedux, RawVuex, RawMobX, RawNgRx, RawGraphQl, RawPerformanceTrack, - RawResourceTiming, RawConnectionInformation, RawSetPageVisibility, RawLongTask, RawSetNodeAttributeURLBased, RawSetCssDataURLBased, - RawTechnicalInfo, - RawCustomIssue, RawCssInsertRuleURLBased, RawMouseClick, RawCreateIFrameDocument, @@ -74,12 +59,6 @@ import type { export type Message = RawMessage & Timed -export type BatchMeta = RawBatchMeta & Timed - -export type BatchMetadata = RawBatchMetadata & Timed - -export type PartitionedMessage = RawPartitionedMessage & Timed - export type Timestamp = RawTimestamp & Timed export type SetPageLocation = RawSetPageLocation & Timed @@ -108,8 +87,6 @@ export type SetCssData = RawSetCssData & Timed export type SetNodeScroll = RawSetNodeScroll & Timed -export type SetInputTarget = RawSetInputTarget & Timed - export type SetInputValue = RawSetInputValue & Timed export type SetInputChecked = RawSetInputChecked & Timed @@ -118,20 +95,6 @@ export type MouseMove = RawMouseMove & Timed export type ConsoleLog = RawConsoleLog & Timed -export type PageLoadTiming = RawPageLoadTiming & Timed - -export type PageRenderTiming = RawPageRenderTiming & Timed - -export type JsException = RawJsException & Timed - -export type RawCustomEvent = RawRawCustomEvent & Timed - -export type UserID = RawUserID & Timed - -export type UserAnonymousID = RawUserAnonymousID & Timed - -export type Metadata = RawMetadata & Timed - export type CssInsertRule = RawCssInsertRule & Timed export type CssDeleteRule = RawCssDeleteRule & Timed @@ -142,8 +105,6 @@ export type Profiler = RawProfiler & Timed export type OTable = RawOTable & Timed -export type StateAction = RawStateAction & Timed - export type Redux = RawRedux & Timed export type Vuex = RawVuex & Timed @@ -156,8 +117,6 @@ export type GraphQl = RawGraphQl & Timed export type PerformanceTrack = RawPerformanceTrack & Timed -export type ResourceTiming = RawResourceTiming & Timed - export type ConnectionInformation = RawConnectionInformation & Timed export type SetPageVisibility = RawSetPageVisibility & Timed @@ -168,10 +127,6 @@ export type SetNodeAttributeURLBased = RawSetNodeAttributeURLBased & Timed export type SetCssDataURLBased = RawSetCssDataURLBased & Timed -export type TechnicalInfo = RawTechnicalInfo & Timed - -export type CustomIssue = RawCustomIssue & Timed - export type CssInsertRuleURLBased = RawCssInsertRuleURLBased & Timed export type MouseClick = RawMouseClick & Timed diff --git a/frontend/app/player/MessageDistributor/messages/raw.ts b/frontend/app/player/MessageDistributor/messages/raw.ts index ce62dab9b..a546ca799 100644 --- a/frontend/app/player/MessageDistributor/messages/raw.ts +++ b/frontend/app/player/MessageDistributor/messages/raw.ts @@ -1,96 +1,5 @@ // Auto-generated, do not edit -export const TP_MAP = { - 80: "batch_meta", - 81: "batch_metadata", - 82: "partitioned_message", - 0: "timestamp", - 4: "set_page_location", - 5: "set_viewport_size", - 6: "set_viewport_scroll", - 7: "create_document", - 8: "create_element_node", - 9: "create_text_node", - 10: "move_node", - 11: "remove_node", - 12: "set_node_attribute", - 13: "remove_node_attribute", - 14: "set_node_data", - 15: "set_css_data", - 16: "set_node_scroll", - 17: "set_input_target", - 18: "set_input_value", - 19: "set_input_checked", - 20: "mouse_move", - 22: "console_log", - 23: "page_load_timing", - 24: "page_render_timing", - 25: "js_exception", - 27: "raw_custom_event", - 28: "user_id", - 29: "user_anonymous_id", - 30: "metadata", - 37: "css_insert_rule", - 38: "css_delete_rule", - 39: "fetch", - 40: "profiler", - 41: "o_table", - 42: "state_action", - 44: "redux", - 45: "vuex", - 46: "mob_x", - 47: "ng_rx", - 48: "graph_ql", - 49: "performance_track", - 53: "resource_timing", - 54: "connection_information", - 55: "set_page_visibility", - 59: "long_task", - 60: "set_node_attribute_url_based", - 61: "set_css_data_url_based", - 63: "technical_info", - 64: "custom_issue", - 67: "css_insert_rule_url_based", - 69: "mouse_click", - 70: "create_i_frame_document", - 71: "adopted_ss_replace_url_based", - 72: "adopted_ss_replace", - 73: "adopted_ss_insert_rule_url_based", - 74: "adopted_ss_insert_rule", - 75: "adopted_ss_delete_rule", - 76: "adopted_ss_add_owner", - 77: "adopted_ss_remove_owner", - 90: "ios_session_start", - 93: "ios_custom_event", - 96: "ios_screen_changes", - 100: "ios_click_event", - 102: "ios_performance_event", - 103: "ios_log", - 105: "ios_network_call", -} as const - - -export interface RawBatchMeta { - tp: "batch_meta", - pageNo: number, - firstIndex: number, - timestamp: number, -} - -export interface RawBatchMetadata { - tp: "batch_metadata", - version: number, - pageNo: number, - firstIndex: number, - timestamp: number, - location: string, -} - -export interface RawPartitionedMessage { - tp: "partitioned_message", - partNo: number, - partTotal: number, -} export interface RawTimestamp { tp: "timestamp", @@ -181,12 +90,6 @@ export interface RawSetNodeScroll { y: number, } -export interface RawSetInputTarget { - tp: "set_input_target", - id: number, - label: string, -} - export interface RawSetInputValue { tp: "set_input_value", id: number, @@ -212,55 +115,6 @@ export interface RawConsoleLog { value: string, } -export interface RawPageLoadTiming { - tp: "page_load_timing", - requestStart: number, - responseStart: number, - responseEnd: number, - domContentLoadedEventStart: number, - domContentLoadedEventEnd: number, - loadEventStart: number, - loadEventEnd: number, - firstPaint: number, - firstContentfulPaint: number, -} - -export interface RawPageRenderTiming { - tp: "page_render_timing", - speedIndex: number, - visuallyComplete: number, - timeToInteractive: number, -} - -export interface RawJsException { - tp: "js_exception", - name: string, - message: string, - payload: string, -} - -export interface RawRawCustomEvent { - tp: "raw_custom_event", - name: string, - payload: string, -} - -export interface RawUserID { - tp: "user_id", - id: string, -} - -export interface RawUserAnonymousID { - tp: "user_anonymous_id", - id: string, -} - -export interface RawMetadata { - tp: "metadata", - key: string, - value: string, -} - export interface RawCssInsertRule { tp: "css_insert_rule", id: number, @@ -299,11 +153,6 @@ export interface RawOTable { value: string, } -export interface RawStateAction { - tp: "state_action", - type: string, -} - export interface RawRedux { tp: "redux", action: string, @@ -346,18 +195,6 @@ export interface RawPerformanceTrack { usedJSHeapSize: number, } -export interface RawResourceTiming { - tp: "resource_timing", - timestamp: number, - duration: number, - ttfb: number, - headerSize: number, - encodedBodySize: number, - decodedBodySize: number, - url: string, - initiator: string, -} - export interface RawConnectionInformation { tp: "connection_information", downlink: number, @@ -395,18 +232,6 @@ export interface RawSetCssDataURLBased { baseURL: string, } -export interface RawTechnicalInfo { - tp: "technical_info", - type: string, - value: string, -} - -export interface RawCustomIssue { - tp: "custom_issue", - name: string, - payload: string, -} - export interface RawCssInsertRuleURLBased { tp: "css_insert_rule_url_based", id: number, @@ -546,4 +371,4 @@ export interface RawIosNetworkCall { } -export type RawMessage = RawBatchMeta | RawBatchMetadata | RawPartitionedMessage | RawTimestamp | RawSetPageLocation | RawSetViewportSize | RawSetViewportScroll | RawCreateDocument | RawCreateElementNode | RawCreateTextNode | RawMoveNode | RawRemoveNode | RawSetNodeAttribute | RawRemoveNodeAttribute | RawSetNodeData | RawSetCssData | RawSetNodeScroll | RawSetInputTarget | RawSetInputValue | RawSetInputChecked | RawMouseMove | RawConsoleLog | RawPageLoadTiming | RawPageRenderTiming | RawJsException | RawRawCustomEvent | RawUserID | RawUserAnonymousID | RawMetadata | RawCssInsertRule | RawCssDeleteRule | RawFetch | RawProfiler | RawOTable | RawStateAction | RawRedux | RawVuex | RawMobX | RawNgRx | RawGraphQl | RawPerformanceTrack | RawResourceTiming | RawConnectionInformation | RawSetPageVisibility | RawLongTask | RawSetNodeAttributeURLBased | RawSetCssDataURLBased | RawTechnicalInfo | RawCustomIssue | RawCssInsertRuleURLBased | RawMouseClick | RawCreateIFrameDocument | RawAdoptedSsReplaceURLBased | RawAdoptedSsReplace | RawAdoptedSsInsertRuleURLBased | RawAdoptedSsInsertRule | RawAdoptedSsDeleteRule | RawAdoptedSsAddOwner | RawAdoptedSsRemoveOwner | RawIosSessionStart | RawIosCustomEvent | RawIosScreenChanges | RawIosClickEvent | RawIosPerformanceEvent | RawIosLog | RawIosNetworkCall; +export type RawMessage = RawTimestamp | RawSetPageLocation | RawSetViewportSize | RawSetViewportScroll | RawCreateDocument | RawCreateElementNode | RawCreateTextNode | RawMoveNode | RawRemoveNode | RawSetNodeAttribute | RawRemoveNodeAttribute | RawSetNodeData | RawSetCssData | RawSetNodeScroll | RawSetInputValue | RawSetInputChecked | RawMouseMove | RawConsoleLog | RawCssInsertRule | RawCssDeleteRule | RawFetch | RawProfiler | RawOTable | RawRedux | RawVuex | RawMobX | RawNgRx | RawGraphQl | RawPerformanceTrack | RawConnectionInformation | RawSetPageVisibility | RawLongTask | RawSetNodeAttributeURLBased | RawSetCssDataURLBased | RawCssInsertRuleURLBased | RawMouseClick | RawCreateIFrameDocument | RawAdoptedSsReplaceURLBased | RawAdoptedSsReplace | RawAdoptedSsInsertRuleURLBased | RawAdoptedSsInsertRule | RawAdoptedSsDeleteRule | RawAdoptedSsAddOwner | RawAdoptedSsRemoveOwner | RawIosSessionStart | RawIosCustomEvent | RawIosScreenChanges | RawIosClickEvent | RawIosPerformanceEvent | RawIosLog | RawIosNetworkCall; diff --git a/frontend/app/player/MessageDistributor/messages/tracker-legacy.ts b/frontend/app/player/MessageDistributor/messages/tracker-legacy.ts new file mode 100644 index 000000000..c89f8a47c --- /dev/null +++ b/frontend/app/player/MessageDistributor/messages/tracker-legacy.ts @@ -0,0 +1,72 @@ +// @ts-nocheck +// Auto-generated, do not edit + +export const TP_MAP = { + 81: "batch_metadata", + 82: "partitioned_message", + 0: "timestamp", + 4: "set_page_location", + 5: "set_viewport_size", + 6: "set_viewport_scroll", + 7: "create_document", + 8: "create_element_node", + 9: "create_text_node", + 10: "move_node", + 11: "remove_node", + 12: "set_node_attribute", + 13: "remove_node_attribute", + 14: "set_node_data", + 15: "set_css_data", + 16: "set_node_scroll", + 17: "set_input_target", + 18: "set_input_value", + 19: "set_input_checked", + 20: "mouse_move", + 22: "console_log", + 23: "page_load_timing", + 24: "page_render_timing", + 25: "js_exception", + 27: "raw_custom_event", + 28: "user_id", + 29: "user_anonymous_id", + 30: "metadata", + 37: "css_insert_rule", + 38: "css_delete_rule", + 39: "fetch", + 40: "profiler", + 41: "o_table", + 42: "state_action", + 44: "redux", + 45: "vuex", + 46: "mob_x", + 47: "ng_rx", + 48: "graph_ql", + 49: "performance_track", + 53: "resource_timing", + 54: "connection_information", + 55: "set_page_visibility", + 59: "long_task", + 60: "set_node_attribute_url_based", + 61: "set_css_data_url_based", + 63: "technical_info", + 64: "custom_issue", + 67: "css_insert_rule_url_based", + 69: "mouse_click", + 70: "create_i_frame_document", + 71: "adopted_ss_replace_url_based", + 72: "adopted_ss_replace", + 73: "adopted_ss_insert_rule_url_based", + 74: "adopted_ss_insert_rule", + 75: "adopted_ss_delete_rule", + 76: "adopted_ss_add_owner", + 77: "adopted_ss_remove_owner", + 90: "ios_session_start", + 93: "ios_custom_event", + 96: "ios_screen_changes", + 100: "ios_click_event", + 102: "ios_performance_event", + 103: "ios_log", + 105: "ios_network_call", +} as const + + diff --git a/frontend/app/player/MessageDistributor/messages/tracker.ts b/frontend/app/player/MessageDistributor/messages/tracker.ts new file mode 100644 index 000000000..34493f32c --- /dev/null +++ b/frontend/app/player/MessageDistributor/messages/tracker.ts @@ -0,0 +1,757 @@ +// Auto-generated, do not edit + +import type { RawMessage } from './raw' + + +type TrBatchMetadata = [ + type: 81, + version: number, + pageNo: number, + firstIndex: number, + timestamp: number, + location: string, +] + +type TrPartitionedMessage = [ + type: 82, + partNo: number, + partTotal: number, +] + +type TrTimestamp = [ + type: 0, + timestamp: number, +] + +type TrSetPageLocation = [ + type: 4, + url: string, + referrer: string, + navigationStart: number, +] + +type TrSetViewportSize = [ + type: 5, + width: number, + height: number, +] + +type TrSetViewportScroll = [ + type: 6, + x: number, + y: number, +] + +type TrCreateDocument = [ + type: 7, + +] + +type TrCreateElementNode = [ + type: 8, + id: number, + parentID: number, + index: number, + tag: string, + svg: boolean, +] + +type TrCreateTextNode = [ + type: 9, + id: number, + parentID: number, + index: number, +] + +type TrMoveNode = [ + type: 10, + id: number, + parentID: number, + index: number, +] + +type TrRemoveNode = [ + type: 11, + id: number, +] + +type TrSetNodeAttribute = [ + type: 12, + id: number, + name: string, + value: string, +] + +type TrRemoveNodeAttribute = [ + type: 13, + id: number, + name: string, +] + +type TrSetNodeData = [ + type: 14, + id: number, + data: string, +] + +type TrSetNodeScroll = [ + type: 16, + id: number, + x: number, + y: number, +] + +type TrSetInputTarget = [ + type: 17, + id: number, + label: string, +] + +type TrSetInputValue = [ + type: 18, + id: number, + value: string, + mask: number, +] + +type TrSetInputChecked = [ + type: 19, + id: number, + checked: boolean, +] + +type TrMouseMove = [ + type: 20, + x: number, + y: number, +] + +type TrConsoleLog = [ + type: 22, + level: string, + value: string, +] + +type TrPageLoadTiming = [ + type: 23, + requestStart: number, + responseStart: number, + responseEnd: number, + domContentLoadedEventStart: number, + domContentLoadedEventEnd: number, + loadEventStart: number, + loadEventEnd: number, + firstPaint: number, + firstContentfulPaint: number, +] + +type TrPageRenderTiming = [ + type: 24, + speedIndex: number, + visuallyComplete: number, + timeToInteractive: number, +] + +type TrJSException = [ + type: 25, + name: string, + message: string, + payload: string, +] + +type TrRawCustomEvent = [ + type: 27, + name: string, + payload: string, +] + +type TrUserID = [ + type: 28, + id: string, +] + +type TrUserAnonymousID = [ + type: 29, + id: string, +] + +type TrMetadata = [ + type: 30, + key: string, + value: string, +] + +type TrCSSInsertRule = [ + type: 37, + id: number, + rule: string, + index: number, +] + +type TrCSSDeleteRule = [ + type: 38, + id: number, + index: number, +] + +type TrFetch = [ + type: 39, + method: string, + url: string, + request: string, + response: string, + status: number, + timestamp: number, + duration: number, +] + +type TrProfiler = [ + type: 40, + name: string, + duration: number, + args: string, + result: string, +] + +type TrOTable = [ + type: 41, + key: string, + value: string, +] + +type TrStateAction = [ + type: 42, + type: string, +] + +type TrRedux = [ + type: 44, + action: string, + state: string, + duration: number, +] + +type TrVuex = [ + type: 45, + mutation: string, + state: string, +] + +type TrMobX = [ + type: 46, + type: string, + payload: string, +] + +type TrNgRx = [ + type: 47, + action: string, + state: string, + duration: number, +] + +type TrGraphQL = [ + type: 48, + operationKind: string, + operationName: string, + variables: string, + response: string, +] + +type TrPerformanceTrack = [ + type: 49, + frames: number, + ticks: number, + totalJSHeapSize: number, + usedJSHeapSize: number, +] + +type TrResourceTiming = [ + type: 53, + timestamp: number, + duration: number, + ttfb: number, + headerSize: number, + encodedBodySize: number, + decodedBodySize: number, + url: string, + initiator: string, +] + +type TrConnectionInformation = [ + type: 54, + downlink: number, + type: string, +] + +type TrSetPageVisibility = [ + type: 55, + hidden: boolean, +] + +type TrLongTask = [ + type: 59, + timestamp: number, + duration: number, + context: number, + containerType: number, + containerSrc: string, + containerId: string, + containerName: string, +] + +type TrSetNodeAttributeURLBased = [ + type: 60, + id: number, + name: string, + value: string, + baseURL: string, +] + +type TrSetCSSDataURLBased = [ + type: 61, + id: number, + data: string, + baseURL: string, +] + +type TrTechnicalInfo = [ + type: 63, + type: string, + value: string, +] + +type TrCustomIssue = [ + type: 64, + name: string, + payload: string, +] + +type TrCSSInsertRuleURLBased = [ + type: 67, + id: number, + rule: string, + index: number, + baseURL: string, +] + +type TrMouseClick = [ + type: 69, + id: number, + hesitationTime: number, + label: string, + selector: string, +] + +type TrCreateIFrameDocument = [ + type: 70, + frameID: number, + id: number, +] + +type TrAdoptedSSReplaceURLBased = [ + type: 71, + sheetID: number, + text: string, + baseURL: string, +] + +type TrAdoptedSSInsertRuleURLBased = [ + type: 73, + sheetID: number, + rule: string, + index: number, + baseURL: string, +] + +type TrAdoptedSSDeleteRule = [ + type: 75, + sheetID: number, + index: number, +] + +type TrAdoptedSSAddOwner = [ + type: 76, + sheetID: number, + id: number, +] + +type TrAdoptedSSRemoveOwner = [ + type: 77, + sheetID: number, + id: number, +] + + +export type TrackerMessage = TrBatchMetadata | TrPartitionedMessage | TrTimestamp | TrSetPageLocation | TrSetViewportSize | TrSetViewportScroll | TrCreateDocument | TrCreateElementNode | TrCreateTextNode | TrMoveNode | TrRemoveNode | TrSetNodeAttribute | TrRemoveNodeAttribute | TrSetNodeData | TrSetNodeScroll | TrSetInputTarget | TrSetInputValue | TrSetInputChecked | TrMouseMove | TrConsoleLog | TrPageLoadTiming | TrPageRenderTiming | TrJSException | TrRawCustomEvent | TrUserID | TrUserAnonymousID | TrMetadata | TrCSSInsertRule | TrCSSDeleteRule | TrFetch | TrProfiler | TrOTable | TrStateAction | TrRedux | TrVuex | TrMobX | TrNgRx | TrGraphQL | TrPerformanceTrack | TrResourceTiming | TrConnectionInformation | TrSetPageVisibility | TrLongTask | TrSetNodeAttributeURLBased | TrSetCSSDataURLBased | TrTechnicalInfo | TrCustomIssue | TrCSSInsertRuleURLBased | TrMouseClick | TrCreateIFrameDocument | TrAdoptedSSReplaceURLBased | TrAdoptedSSInsertRuleURLBased | TrAdoptedSSDeleteRule | TrAdoptedSSAddOwner | TrAdoptedSSRemoveOwner + +export default function translate(tMsg: TrackerMessage): RawMessage | null { + switch(tMsg[0]) { + + case 0: { + return { + tp: "timestamp", + timestamp: tMsg[1], + } + } + + case 4: { + return { + tp: "set_page_location", + url: tMsg[1], + referrer: tMsg[2], + navigationStart: tMsg[3], + } + } + + case 5: { + return { + tp: "set_viewport_size", + width: tMsg[1], + height: tMsg[2], + } + } + + case 6: { + return { + tp: "set_viewport_scroll", + x: tMsg[1], + y: tMsg[2], + } + } + + case 7: { + return { + tp: "create_document", + + } + } + + case 8: { + return { + tp: "create_element_node", + id: tMsg[1], + parentID: tMsg[2], + index: tMsg[3], + tag: tMsg[4], + svg: tMsg[5], + } + } + + case 9: { + return { + tp: "create_text_node", + id: tMsg[1], + parentID: tMsg[2], + index: tMsg[3], + } + } + + case 10: { + return { + tp: "move_node", + id: tMsg[1], + parentID: tMsg[2], + index: tMsg[3], + } + } + + case 11: { + return { + tp: "remove_node", + id: tMsg[1], + } + } + + case 12: { + return { + tp: "set_node_attribute", + id: tMsg[1], + name: tMsg[2], + value: tMsg[3], + } + } + + case 13: { + return { + tp: "remove_node_attribute", + id: tMsg[1], + name: tMsg[2], + } + } + + case 14: { + return { + tp: "set_node_data", + id: tMsg[1], + data: tMsg[2], + } + } + + case 16: { + return { + tp: "set_node_scroll", + id: tMsg[1], + x: tMsg[2], + y: tMsg[3], + } + } + + case 18: { + return { + tp: "set_input_value", + id: tMsg[1], + value: tMsg[2], + mask: tMsg[3], + } + } + + case 19: { + return { + tp: "set_input_checked", + id: tMsg[1], + checked: tMsg[2], + } + } + + case 20: { + return { + tp: "mouse_move", + x: tMsg[1], + y: tMsg[2], + } + } + + case 22: { + return { + tp: "console_log", + level: tMsg[1], + value: tMsg[2], + } + } + + case 37: { + return { + tp: "css_insert_rule", + id: tMsg[1], + rule: tMsg[2], + index: tMsg[3], + } + } + + case 38: { + return { + tp: "css_delete_rule", + id: tMsg[1], + index: tMsg[2], + } + } + + case 39: { + return { + tp: "fetch", + method: tMsg[1], + url: tMsg[2], + request: tMsg[3], + response: tMsg[4], + status: tMsg[5], + timestamp: tMsg[6], + duration: tMsg[7], + } + } + + case 40: { + return { + tp: "profiler", + name: tMsg[1], + duration: tMsg[2], + args: tMsg[3], + result: tMsg[4], + } + } + + case 41: { + return { + tp: "o_table", + key: tMsg[1], + value: tMsg[2], + } + } + + case 44: { + return { + tp: "redux", + action: tMsg[1], + state: tMsg[2], + duration: tMsg[3], + } + } + + case 45: { + return { + tp: "vuex", + mutation: tMsg[1], + state: tMsg[2], + } + } + + case 46: { + return { + tp: "mob_x", + type: tMsg[1], + payload: tMsg[2], + } + } + + case 47: { + return { + tp: "ng_rx", + action: tMsg[1], + state: tMsg[2], + duration: tMsg[3], + } + } + + case 48: { + return { + tp: "graph_ql", + operationKind: tMsg[1], + operationName: tMsg[2], + variables: tMsg[3], + response: tMsg[4], + } + } + + case 49: { + return { + tp: "performance_track", + frames: tMsg[1], + ticks: tMsg[2], + totalJSHeapSize: tMsg[3], + usedJSHeapSize: tMsg[4], + } + } + + case 54: { + return { + tp: "connection_information", + downlink: tMsg[1], + type: tMsg[2], + } + } + + case 55: { + return { + tp: "set_page_visibility", + hidden: tMsg[1], + } + } + + case 59: { + return { + tp: "long_task", + timestamp: tMsg[1], + duration: tMsg[2], + context: tMsg[3], + containerType: tMsg[4], + containerSrc: tMsg[5], + containerId: tMsg[6], + containerName: tMsg[7], + } + } + + case 60: { + return { + tp: "set_node_attribute_url_based", + id: tMsg[1], + name: tMsg[2], + value: tMsg[3], + baseURL: tMsg[4], + } + } + + case 61: { + return { + tp: "set_css_data_url_based", + id: tMsg[1], + data: tMsg[2], + baseURL: tMsg[3], + } + } + + case 67: { + return { + tp: "css_insert_rule_url_based", + id: tMsg[1], + rule: tMsg[2], + index: tMsg[3], + baseURL: tMsg[4], + } + } + + case 69: { + return { + tp: "mouse_click", + id: tMsg[1], + hesitationTime: tMsg[2], + label: tMsg[3], + selector: tMsg[4], + } + } + + case 70: { + return { + tp: "create_i_frame_document", + frameID: tMsg[1], + id: tMsg[2], + } + } + + case 71: { + return { + tp: "adopted_ss_replace_url_based", + sheetID: tMsg[1], + text: tMsg[2], + baseURL: tMsg[3], + } + } + + case 73: { + return { + tp: "adopted_ss_insert_rule_url_based", + sheetID: tMsg[1], + rule: tMsg[2], + index: tMsg[3], + baseURL: tMsg[4], + } + } + + case 75: { + return { + tp: "adopted_ss_delete_rule", + sheetID: tMsg[1], + index: tMsg[2], + } + } + + case 76: { + return { + tp: "adopted_ss_add_owner", + sheetID: tMsg[1], + id: tMsg[2], + } + } + + case 77: { + return { + tp: "adopted_ss_remove_owner", + sheetID: tMsg[1], + id: tMsg[2], + } + } + + default: + return null + } + +} \ No newline at end of file diff --git a/mobs/templates/frontend~app~player~MessageDistributor~messages~RawMessageReader.ts.erb b/mobs/templates/frontend~app~player~MessageDistributor~messages~RawMessageReader.ts.erb index d9a5aa8d4..d1e533550 100644 --- a/mobs/templates/frontend~app~player~MessageDistributor~messages~RawMessageReader.ts.erb +++ b/mobs/templates/frontend~app~player~MessageDistributor~messages~RawMessageReader.ts.erb @@ -16,7 +16,7 @@ export default class RawMessageReader extends PrimitiveReader { if (tp === null) { return resetPointer() } switch (tp) { - <% $messages.select { |msg| msg.tracker || msg.replayer }.each do |msg| %> + <% $messages.select { |msg| msg.replayer }.each do |msg| %> case <%= msg.id %>: { <%= msg.attributes.map { |attr| " const #{attr.name.camel_case} = this.read#{attr.type.to_s.pascal_case}(); if (#{attr.name.camel_case} === null) { return resetPointer() }" }.join "\n" %> diff --git a/mobs/templates/frontend~app~player~MessageDistributor~messages~message.ts.erb b/mobs/templates/frontend~app~player~MessageDistributor~messages~message.ts.erb index 9ba42d3df..91c2cb9a5 100644 --- a/mobs/templates/frontend~app~player~MessageDistributor~messages~message.ts.erb +++ b/mobs/templates/frontend~app~player~MessageDistributor~messages~message.ts.erb @@ -3,11 +3,11 @@ import type { Timed } from './timed' import type { RawMessage } from './raw' import type { -<%= $messages.select { |msg| msg.tracker || msg.replayer }.map { |msg| " Raw#{msg.name.snake_case.pascal_case}," }.join "\n" %> +<%= $messages.select { |msg| msg.replayer }.map { |msg| " Raw#{msg.name.snake_case.pascal_case}," }.join "\n" %> } from './raw' export type Message = RawMessage & Timed -<% $messages.select { |msg| msg.tracker || msg.replayer }.each do |msg| %> +<% $messages.select { |msg| msg.replayer }.each do |msg| %> export type <%= msg.name.snake_case.pascal_case %> = Raw<%= msg.name.snake_case.pascal_case %> & Timed <% end %> \ No newline at end of file diff --git a/mobs/templates/frontend~app~player~MessageDistributor~messages~raw.ts.erb b/mobs/templates/frontend~app~player~MessageDistributor~messages~raw.ts.erb index 3906da62d..b94ced335 100644 --- a/mobs/templates/frontend~app~player~MessageDistributor~messages~raw.ts.erb +++ b/mobs/templates/frontend~app~player~MessageDistributor~messages~raw.ts.erb @@ -1,14 +1,10 @@ // Auto-generated, do not edit -export const TP_MAP = { -<%= $messages.select { |msg| msg.tracker || msg.replayer }.map { |msg| " #{msg.id}: \"#{msg.name.snake_case}\"," }.join "\n" %> -} - -<% $messages.select { |msg| msg.tracker || msg.replayer }.each do |msg| %> +<% $messages.select { |msg| msg.replayer }.each do |msg| %> export interface Raw<%= msg.name.snake_case.pascal_case %> { tp: "<%= msg.name.snake_case %>", <%= msg.attributes.map { |attr| " #{attr.name.camel_case}: #{attr.type_js}," }.join "\n" %> } <% end %> -export type RawMessage = <%= $messages.select { |msg| msg.tracker || msg.replayer }.map { |msg| "Raw#{msg.name.snake_case.pascal_case}" }.join " | " %>; +export type RawMessage = <%= $messages.select { |msg| msg.replayer }.map { |msg| "Raw#{msg.name.snake_case.pascal_case}" }.join " | " %>; diff --git a/mobs/templates/frontend~app~player~MessageDistributor~messages~tracker-legacy.ts.erb b/mobs/templates/frontend~app~player~MessageDistributor~messages~tracker-legacy.ts.erb new file mode 100644 index 000000000..586ee8cf3 --- /dev/null +++ b/mobs/templates/frontend~app~player~MessageDistributor~messages~tracker-legacy.ts.erb @@ -0,0 +1,8 @@ +// @ts-nocheck +// Auto-generated, do not edit + +export const TP_MAP = { +<%= $messages.select { |msg| msg.tracker || msg.replayer }.map { |msg| " #{msg.id}: \"#{msg.name.snake_case}\"," }.join "\n" %> +} as const + + diff --git a/mobs/templates/frontend~app~player~MessageDistributor~messages~tracker.ts.erb b/mobs/templates/frontend~app~player~MessageDistributor~messages~tracker.ts.erb new file mode 100644 index 000000000..0b3452b3b --- /dev/null +++ b/mobs/templates/frontend~app~player~MessageDistributor~messages~tracker.ts.erb @@ -0,0 +1,28 @@ +// Auto-generated, do not edit + +import type { RawMessage } from './raw' + +<% $messages.select { |msg| msg.tracker }.each do |msg| %> +type Tr<%= msg.name %> = [ + type: <%= msg.id %>, + <%= msg.attributes.map { |attr| "#{attr.name.camel_case}: #{attr.type_js}," }.join "\n " %> +] +<% end %> + +export type TrackerMessage = <%= $messages.select { |msg| msg.tracker }.map { |msg| "Tr#{msg.name}" }.join " | " %> + +export default function translate(tMsg: TrackerMessage): RawMessage | null { + switch(tMsg[0]) { + <% $messages.select { |msg| msg.replayer & msg.tracker }.each do |msg| %> + case <%= msg.id %>: { + return { + tp: "<%= msg.name.snake_case %>", + <%= msg.attributes.map.with_index { |attr, i| "#{attr.name.camel_case}: tMsg[#{i+1}]," }.join "\n " %> + } + } + <% end %> + default: + return null + } + +} \ No newline at end of file