Functional Core - Pure session business logic - Minimal working version
Functional Core - Pure session business logic - Minimal working version
(analyze-session-duration session now)Calculate session duration in hours from creation to last access.
Calculate session duration in hours from creation to last access.
(calculate-session-expiry created-at remember-me?)(calculate-session-expiry created-at remember-me? custom-hours)Calculate session expiry instant. Remember-me sessions last 30 days, otherwise 24h.
Calculate session expiry instant. Remember-me sessions last 30 days, otherwise 24h.
(calculate-session-risk-score session previous-sessions)Calculate a 0.0-1.0 risk score based on IP changes and concurrent sessions.
Calculate a 0.0-1.0 risk score based on IP changes and concurrent sessions.
(calculate-user-session-stats sessions user-id)Compute active/inactive session counts for a given user-id.
Compute active/inactive session counts for a given user-id.
(detect-suspicious-activity? session previous-sessions)Detect suspicious patterns (IP change, concurrent sessions) between current and previous sessions.
Detect suspicious patterns (IP change, concurrent sessions) between current and previous sessions.
(extract-device-info user-agent ip-address)Parse user-agent and ip-address into a device-info map with :device-type.
Parse user-agent and ip-address into a device-info map with :device-type.
(filter-sessions-for-cleanup sessions current-time)Return sessions that have been expired past the cleanup grace period.
Return sessions that have been expired past the cleanup grace period.
(generate-session-token timestamp-ms nonce)Build a deterministic session token from a timestamp and nonce.
Build a deterministic session token from a timestamp and nonce.
(group-sessions-by-device-type sessions)Group sessions into :mobile, :desktop, or :other based on user-agent.
Group sessions into :mobile, :desktop, or :other based on user-agent.
(is-same-device? device1 device2)Check if two device-info maps represent the same device (same IP and similar user-agent).
Check if two device-info maps represent the same device (same IP and similar user-agent).
(is-session-valid? session current-time)Check if session is valid: not nil, not revoked, and not expired.
Check if session is valid: not nil, not revoked, and not expired.
(mark-session-for-cleanup session current-time)Mark session as revoked by setting :revoked-at to current time.
Mark session as revoked by setting :revoked-at to current time.
(prepare-session-for-access-update session current-time)Pure function: Prepare session for access time update.
Args: session: Current session entity current-time: Current timestamp
Returns: Session entity with updated access time
Pure - data transformation only.
Pure function: Prepare session for access time update. Args: session: Current session entity current-time: Current timestamp Returns: Session entity with updated access time Pure - data transformation only.
(prepare-session-for-creation session-data current-time session-id token)(prepare-session-for-creation session-data
current-time
session-id
token
session-policy)Assemble a complete session map from raw data, id, token, and timestamps.
Assemble a complete session map from raw data, id, token, and timestamps.
(prepare-session-for-invalidation session current-time)Pure function: Prepare session for invalidation.
Args: session: Current session entity current-time: Current timestamp
Returns: Session entity marked as revoked
Pure - data transformation only.
Pure function: Prepare session for invalidation. Args: session: Current session entity current-time: Current timestamp Returns: Session entity marked as revoked Pure - data transformation only.
(should-cleanup-session? session current-time cleanup-policy)Return true if session has been expired longer than the grace period.
Return true if session has been expired longer than the grace period.
(should-extend-session? session current-time extension-policy)Return true if session is close enough to expiry to warrant extension.
Return true if session is close enough to expiry to warrant extension.
(should-require-additional-verification? session previous-sessions)Return true if session risk score exceeds the verification threshold (0.5).
Return true if session risk score exceeds the verification threshold (0.5).
(should-update-access-time? session current-time update-policy)Pure function: Determine if session access time should be updated.
Args: session: Current session entity current-time: Current timestamp update-policy: Map with access update configuration
Returns: Boolean indicating if access time should be updated
Pure - business rule evaluation based on policy and time difference.
Pure function: Determine if session access time should be updated. Args: session: Current session entity current-time: Current timestamp update-policy: Map with access update configuration Returns: Boolean indicating if access time should be updated Pure - business rule evaluation based on policy and time difference.
(update-session-access session current-time)Update last-accessed-at and optionally extend expiry if near threshold.
Update last-accessed-at and optionally extend expiry if near threshold.
(validate-session-creation-request session-data)Validate that session-data has the required :user-id key.
Validate that session-data has the required :user-id key.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |