/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */
/**
 * Abstract base class for MCP OAuth token storage.
 * This provides a provider-agnostic interface for storing and retrieving
 * MCP OAuth tokens that can be used across different AI providers.
 */
export class BaseTokenStore {
    /**
     * Check if a token is expired.
     * This is a utility method that can be used by implementations.
     *
     * @param token The token to check
     * @returns True if the token is expired
     */
    static isTokenExpired(token) {
        if (!token.expiresAt) {
            return false; // No expiry, assume valid
        }
        // Add a 5-minute buffer to account for clock skew
        const bufferMs = 5 * 60 * 1000;
        return Date.now() + bufferMs >= token.expiresAt;
    }
    /**
     * Validate that a token has the required fields.
     *
     * @param token The token to validate
     * @throws Error if the token is invalid
     */
    validateToken(token) {
        if (!token.accessToken || typeof token.accessToken !== 'string') {
            throw new Error('Token must have a valid accessToken');
        }
        if (!token.tokenType || typeof token.tokenType !== 'string') {
            throw new Error('Token must have a valid tokenType');
        }
    }
    /**
     * Validate that server name is valid.
     *
     * @param serverName The server name to validate
     * @throws Error if the server name is invalid
     */
    validateServerName(serverName) {
        if (!serverName ||
            typeof serverName !== 'string' ||
            serverName.trim().length === 0) {
            throw new Error('Server name must be a non-empty string');
        }
    }
    /**
     * Create a credentials object from the provided parameters.
     *
     * @param serverName The name of the MCP server
     * @param token The OAuth token
     * @param clientId Optional client ID
     * @param tokenUrl Optional token URL
     * @param mcpServerUrl Optional MCP server URL
     * @returns The credentials object
     */
    createCredentials(serverName, token, clientId, tokenUrl, mcpServerUrl) {
        this.validateServerName(serverName);
        this.validateToken(token);
        return {
            serverName,
            token,
            clientId,
            tokenUrl,
            mcpServerUrl,
            updatedAt: Date.now(),
        };
    }
}
//# sourceMappingURL=token-store.js.map