diff --git a/tracker/tracker/.eslintrc.cjs b/tracker/tracker/.eslintrc.cjs index 1e2170eee..a5a2267bd 100644 --- a/tracker/tracker/.eslintrc.cjs +++ b/tracker/tracker/.eslintrc.cjs @@ -27,7 +27,7 @@ module.exports = { '@typescript-eslint/camelcase': 'off', '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/unbound-method': 'off', - '@typescript-eslint/explicit-function-return-type': 'warn', + '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/prefer-readonly': 'warn', '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/no-unsafe-assignment': 'off', @@ -46,4 +46,4 @@ module.exports = { '@typescript-eslint/no-unused-expressions': 'warn', '@typescript-eslint/no-useless-constructor': 'warn', }, -}; +}; diff --git a/tracker/tracker/src/main/app/index.ts b/tracker/tracker/src/main/app/index.ts index f593fa6a7..0904389f9 100644 --- a/tracker/tracker/src/main/app/index.ts +++ b/tracker/tracker/src/main/app/index.ts @@ -290,6 +290,17 @@ export default class App { getSessionID(): string | undefined { return this.session.getInfo().sessionID || undefined } + + getSessionURL(): string | undefined { + const { projectID, sessionID } = this.session.getInfo() + if (!projectID || !sessionID) { + this.debug.error('OpenReplay error: Unable to build session URL') + return undefined + } + + return this.options.ingestPoint.replace(/\/ingest$/, `${projectID}/session/${sessionID}`) + } + getHost(): string { return new URL(this.options.ingestPoint).hostname } @@ -409,6 +420,7 @@ export default class App { token, userUUID, sessionID, + projectID, beaconSizeLimit, startTimestamp, // real startTS, derived from sessionID } = r @@ -423,7 +435,8 @@ export default class App { } this.session.setSessionToken(token) this.localStorage.setItem(this.options.local_uuid_key, userUUID) - this.session.update({ sessionID, timestamp: startTimestamp || timestamp }) // TODO: no no-explicit 'any' + this.session.update({ sessionID, timestamp: startTimestamp || timestamp, projectID }) // TODO: no no-explicit 'any' + const startWorkerMsg: WorkerMessageData = { type: 'auth', token, diff --git a/tracker/tracker/src/main/app/session.ts b/tracker/tracker/src/main/app/session.ts index 4ac5c6655..e98d55da7 100644 --- a/tracker/tracker/src/main/app/session.ts +++ b/tracker/tracker/src/main/app/session.ts @@ -5,6 +5,7 @@ interface SessionInfo { metadata: Record userID: string | null timestamp: number + projectID?: string } type OnUpdateCallback = (i: Partial) => void @@ -19,8 +20,9 @@ export default class Session { private sessionID: string | undefined private readonly callbacks: OnUpdateCallback[] = [] private timestamp = 0 + private projectID: string | undefined - constructor(private readonly app: App, private options: Options) {} + constructor(private readonly app: App, private readonly options: Options) {} attachUpdateCallback(cb: OnUpdateCallback) { this.callbacks.push(cb) @@ -35,7 +37,7 @@ export default class Session { this.callbacks.forEach((cb) => cb(newInfo)) } - update(newInfo: Partial) { + update(newInfo: Partial): void { if (newInfo.userID !== undefined) { // TODO clear nullable/undefinable types this.userID = newInfo.userID @@ -49,6 +51,9 @@ export default class Session { if (newInfo.timestamp !== undefined) { this.timestamp = newInfo.timestamp } + if (newInfo.projectID !== undefined) { + this.projectID = newInfo.projectID + } this.handleUpdate(newInfo) } @@ -116,6 +121,7 @@ export default class Session { metadata: this.metadata, userID: this.userID, timestamp: this.timestamp, + projectID: this.projectID, } } diff --git a/tracker/tracker/src/main/index.ts b/tracker/tracker/src/main/index.ts index 02fbead4d..ff8d27b4c 100644 --- a/tracker/tracker/src/main/index.ts +++ b/tracker/tracker/src/main/index.ts @@ -209,6 +209,13 @@ export default class API { return this.getSessionID() } + getSessionURL(): string | undefined { + if (this.app === null) { + return undefined + } + return this.app.getSessionURL() + } + setUserID(id: string): void { if (typeof id === 'string' && this.app !== null) { this.app.session.setUserID(id)