Proton Drive CLI API Documentation - v0.1.2
    Preparing search index...

    Class SessionManager

    Index

    Constructors

    Properties

    LOCK_POLL_INTERVAL_MS: 100
    LOCK_TIMEOUT_MS: 5000
    REFRESH_THRESHOLD_MS: number = ...

    Methods

    • Clear the crypto cache (e.g. on logout or session change).

      Returns Promise<void>

    • Clear saved session from disk

      Returns Promise<void>

    • Get an existing session or create a new one via SRP authentication. This method implements session reuse: if a valid session exists, it is returned immediately without performing SRP auth. This significantly reduces auth overhead.

      Parameters

      • username: string

        Username for authentication (if new session needed)

      • password: string

        Password for authentication (if new session needed)

      • remoteCheck: boolean = false

        If true, validates existing session with an API call

      Returns Promise<SessionCredentials>

      Valid session (existing or newly created)

    • Get session directory path

      Returns string

      Path to session directory

    • Get session file path

      Returns string

      Path to session file

    • Get a valid session, proactively refreshing tokens if they are expiring soon. This method should be called before operations to ensure the token is valid for the duration of the operation (preventing mid-operation expiration).

      Returns Promise<SessionCredentials | null>

      Valid session or null if no session exists

    • Hash a username for session identity comparison. Uses SHA-256 of the lowercased, trimmed username.

      Parameters

      • username: string

      Returns string

    • Check if a valid session exists

      Returns Promise<boolean>

      True if a valid session exists

    • Check if a session token is expiring soon (within REFRESH_THRESHOLD_MS).

      Parameters

      • session: SessionCredentials

        Session to check

      Returns boolean

      True if token expires within the threshold

    • Check if the current session belongs to a specific user. Returns true if a valid session exists AND its userHash matches. Returns false if no session exists, session is invalid, or hash doesn't match. Legacy sessions without userHash are treated as matching (backward compat).

      Parameters

      • username: string

      Returns Promise<boolean>

    • Validate session object has all required fields

      Parameters

      • session: any

        Session object to validate

      Returns session is SessionCredentials

      True if session is valid

    • Load cached crypto-init API responses (keySalts, user, addresses). Returns null if cache is missing, corrupted, or belongs to a different session.

      Returns Promise<CryptoCache | null>

    • Load session credentials from disk

      Returns Promise<SessionCredentials | null>

      Session credentials or null if not found

    • Refresh session tokens using the refresh token. Updates the session file with new tokens and expiration time.

      Parameters

      • session: SessionCredentials

        Current session to refresh

      Returns Promise<SessionCredentials>

      Updated session with new tokens

    • Save crypto-init API responses to disk. Tied to the current session UID so it auto-invalidates on re-login.

      Parameters

      • sessionUid: string
      • keySalts: { ID: string; KeySalt: string | null }[]
      • user: any
      • addresses: any[]

      Returns Promise<void>

    • Save session credentials to disk with file locking.

      Parameters

      • session: SessionCredentials

        Session credentials to save

      Returns Promise<void>

    • Validate a session by checking token expiration and optionally making a lightweight API call.

      Parameters

      • session: SessionCredentials

        Session to validate

      • remoteCheck: boolean = false

        If true, makes an API call to verify the session is valid on the server

      Returns Promise<boolean>

      True if session is valid

    • Acquire a file lock for session operations. Uses a .lock file with timeout to prevent deadlocks. Retries with exponential backoff until timeout.

      Type Parameters

      • T

      Parameters

      • fn: () => Promise<T>

        Function to execute while holding the lock

      Returns Promise<T>

      Result of the function

      Error if lock cannot be acquired within timeout