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..c95c4ce45 100644 --- a/tracker/tracker/src/main/app/index.ts +++ b/tracker/tracker/src/main/app/index.ts @@ -290,6 +290,11 @@ export default class App { getSessionID(): string | undefined { return this.session.getInfo().sessionID || undefined } + + getSessionURL(): string { + return this.session.getSessionURL() + } + getHost(): string { return new URL(this.options.ingestPoint).hostname } @@ -409,6 +414,7 @@ export default class App { token, userUUID, sessionID, + projectID, beaconSizeLimit, startTimestamp, // real startTS, derived from sessionID } = r @@ -423,7 +429,13 @@ 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' + this.session.buildURL( + `${this.options.ingestPoint.replace(/\/ingest$/, '')}/${projectID as string}/session/${ + sessionID as string + }`, + ) + 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..f418ed320 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,6 +20,8 @@ export default class Session { private sessionID: string | undefined private readonly callbacks: OnUpdateCallback[] = [] private timestamp = 0 + private projectID: string | undefined + private sessionUrl: string constructor(private readonly app: App, private options: Options) {} @@ -35,7 +38,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 +52,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,9 +122,18 @@ export default class Session { metadata: this.metadata, userID: this.userID, timestamp: this.timestamp, + projectID: this.projectID, } } + buildURL(url: string): void { + this.sessionUrl = url + } + + getSessionURL(): string { + return this.sessionUrl + } + reset(): void { this.app.sessionStorage.removeItem(this.options.session_token_key) this.metadata = {} diff --git a/tracker/tracker/src/main/index.ts b/tracker/tracker/src/main/index.ts index 02fbead4d..9255822fd 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 | null { + if (this.app === null) { + return null + } + return this.app.getSessionURL() + } + setUserID(id: string): void { if (typeof id === 'string' && this.app !== null) { this.app.session.setUserID(id)