"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateAppCredentials = validateAppCredentials;
const axios_1 = __importDefault(require("axios"));
/**
 * Validates the Feishu app credentials (appId and appSecret) by calling the tenant_access_token_internal endpoint.
 *
 * @param appId The Feishu App ID
 * @param appSecret The Feishu App Secret
 * @returns Promise<boolean> True if credentials are valid, false otherwise.
 */
async function validateAppCredentials(appId, appSecret) {
    // Trim inputs to avoid whitespace issues
    const cleanAppId = appId ? appId.trim() : '';
    const cleanAppSecret = appSecret ? appSecret.trim() : '';
    if (!cleanAppId || !cleanAppSecret) {
        return false;
    }
    try {
        // Use feishu.cn for better compatibility and matching user feedback
        const response = await axios_1.default.post('https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal', {
            app_id: cleanAppId,
            app_secret: cleanAppSecret
        }, {
            timeout: 10000 // 10 seconds timeout
        });
        // If the call is successful and we get a tenant_access_token, the credentials are valid.
        // The API returns code: 0 on success.
        if (response.data && response.data.code === 0 && response.data.tenant_access_token) {
            return true;
        }
        return false;
    }
    catch (error) {
        // If the request fails (network error, 4xx, 5xx), consider it invalid or check specific error codes if needed.
        // For now, any error means validation failed.
        return false;
    }
}
//# sourceMappingURL=feishu-auth.js.map