Module Typesense_auth.Session

Session management for Typesense CLI with profile support.

This module provides session persistence for Typesense authentication using API keys. Sessions are stored in profile-specific directories under ~/.config/typesense/profiles/<profile>/session.json.

Directory Structure

~/.config/typesense/
  config.json           # Stores current_profile setting
  profiles/
    default/
      session.json      # Session for "default" profile
    prod/
      session.json      # Session for "prod" profile
  (* Login with API key *)
  let session = Session.create
    ~server_url:"http://localhost:8108"
    ~api_key:"xyz"
    () in
  Session.save fs ~profile:"default" session

Types

type t

Session data.

val jsont : t Jsont.t

JSON codec for sessions.

Session Construction

val create : server_url:string -> api_key:string -> unit -> t

create ~server_url ~api_key () creates a new session with the current timestamp.

Session Accessors

val server_url : t -> string

server_url t returns the server URL.

val api_key : t -> string

api_key t returns the API key.

val created_at : t -> string

created_at t returns the creation timestamp (RFC 3339).

Profile Management

val default_profile : string

The default profile name ("default").

val get_current_profile : Eio.Fs.dir_ty Eio.Path.t -> string

get_current_profile fs returns the current profile name. Returns default_profile if no profile has been set.

val set_current_profile : Eio.Fs.dir_ty Eio.Path.t -> string -> unit

set_current_profile fs profile sets the current profile.

val list_profiles : Eio.Fs.dir_ty Eio.Path.t -> string list

list_profiles fs returns all profiles that have sessions. Returns profile names sorted alphabetically.

Directory Paths

base_config_dir fs returns the base config directory (~/.config/typesense), creating it if needed.

val config_dir : Eio.Fs.dir_ty Eio.Path.t -> ?profile:string -> unit -> Eio.Fs.dir_ty Eio.Path.t

config_dir fs ?profile () returns the config directory for a profile, creating it if needed.

  • parameter profile

    Profile name (default: current profile)

Session Persistence

val save : Eio.Fs.dir_ty Eio.Path.t -> ?profile:string -> t -> unit

save fs ?profile session saves the session.

  • parameter profile

    Profile name (default: current profile)

val load : Eio.Fs.dir_ty Eio.Path.t -> ?profile:string -> unit -> t option

load fs ?profile () loads a saved session.

  • parameter profile

    Profile name (default: current profile)

val clear : Eio.Fs.dir_ty Eio.Path.t -> ?profile:string -> unit -> unit

clear fs ?profile () removes the saved session.

  • parameter profile

    Profile name (default: current profile)

Session Utilities

val pp : t Fmt.t

Pretty-print a session.