Skip to content

Commit

Permalink
chore: different default and max idle period
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Nov 26, 2024
1 parent 26a8abc commit c0c6634
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/sessionid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import { logger } from './utils/logger'

import { clampToRange } from './utils/number-utils'

const MAX_SESSION_IDLE_TIMEOUT = 30 * 60 // 30 minutes
const MIN_SESSION_IDLE_TIMEOUT = 60 // 1 minute
const SESSION_LENGTH_LIMIT = 24 * 3600 * 1000 // 24 hours
const DEFAULT_SESSION_IDLE_TIMEOUT_SECONDS = 30 * 60 // 30 minutes
const MAX_SESSION_IDLE_TIMEOUT_SECONDS = 10 * 60 * 60 // 10 hours
const MIN_SESSION_IDLE_TIMEOUT_SECONDS = 60 // 1 minute
const SESSION_LENGTH_LIMIT_MILLISECONDS = 24 * 3600 * 1000 // 24 hours

export class SessionIdManager {
private readonly _sessionIdGenerator: () => string
Expand Down Expand Up @@ -46,12 +47,12 @@ export class SessionIdManager {

const persistenceName = config['persistence_name'] || config['token']

const desiredTimeout = config['session_idle_timeout_seconds'] || MAX_SESSION_IDLE_TIMEOUT
const desiredTimeout = config['session_idle_timeout_seconds'] || DEFAULT_SESSION_IDLE_TIMEOUT_SECONDS
this._sessionTimeoutMs =
clampToRange(
desiredTimeout,
MIN_SESSION_IDLE_TIMEOUT,
MAX_SESSION_IDLE_TIMEOUT,
MIN_SESSION_IDLE_TIMEOUT_SECONDS,
MAX_SESSION_IDLE_TIMEOUT_SECONDS,
'session_idle_timeout_seconds'
) * 1000

Expand Down Expand Up @@ -218,7 +219,7 @@ export class SessionIdManager {
const sessionPastMaximumLength =
isNumber(startTimestamp) &&
startTimestamp > 0 &&
Math.abs(timestamp - startTimestamp) > SESSION_LENGTH_LIMIT
Math.abs(timestamp - startTimestamp) > SESSION_LENGTH_LIMIT_MILLISECONDS

let valuesChanged = false
const noSessionId = !sessionId
Expand Down

0 comments on commit c0c6634

Please sign in to comment.