Class TokenStorageServiceAbstract

Abstract class representing a token storage service. Provides methods to set and get items in storage, and abstract methods to check and manage cached tokens.

Hierarchy (view full)

Constructors

Properties

The configuration for the web core.

prefix: string = 'lemon'
storage: Storage = ...

Methods

  • Calculates the token expiration timestamp with built-in safety buffer. Uses a priority-based approach: server expiration first, then JWT expiration, finally fallback duration. Automatically applies a 5-minute safety buffer to prevent token expiry during requests.

    Parameters

    • Optional serverExpiration: string

      ISO string or date string from server response

    • Optional jwtToken: string

      JWT token string to extract expiration from

    Returns number

    Unix timestamp (milliseconds) when the token should be considered expired

  • Extracts the issued time from a JWT token for token lifecycle tracking. Used to calculate token age and determine refresh timing based on token lifetime.

    Parameters

    • Optional jwtToken: string

      JWT token string to extract issued time from

    Returns string | number

    Unix timestamp in milliseconds if found, empty string if not available or on error

  • Safely decodes a JWT token and extracts its payload. Provides error-safe JWT parsing without throwing exceptions on malformed tokens.

    Parameters

    • jwt: string

      JWT token string to decode

    Returns JwtPayload

    Decoded JWT payload object, or null if decoding fails

  • Gets all items from the storage.

    Returns Promise<{
        [key: string]: string;
    }>

    • A promise that resolves to an object containing all items.
  • Gets an item from the storage.

    Parameters

    • key: string

      The key to get.

    Returns Promise<string>

    • A promise that resolves to the value of the item.
  • Checks if there is a cached token in the storage.

    Returns Promise<boolean>

    • A promise that resolves to true if a cached token exists, false otherwise.
  • Sets an item in the storage.

    Parameters

    • key: string

      The key to set.

    • value: string

      The value to set.

    Returns Promise<void>

    • A promise that resolves when the item is set.
  • Checks if the cached token should be refreshed. Abstract method that must be implemented by subclasses to define refresh logic.

    Returns Promise<boolean>

    Promise that resolves to true if the token should be refreshed, false otherwise