"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEnvTimeoutMs = getEnvTimeoutMs;
exports.withTimeout = withTimeout;
const sdkErrors_js_1 = require("./types/public/sdkErrors.js");
function getEnvTimeoutMs(name) {
    const raw = process.env[name];
    if (!raw)
        return undefined;
    const normalized = raw.trim().replace(/ms$/i, "");
    const value = Number(normalized);
    if (!Number.isFinite(value) || value <= 0)
        return undefined;
    return value;
}
async function withTimeout(promise, timeoutMs, operation) {
    let timeoutId;
    const timeoutPromise = new Promise((_, reject) => {
        timeoutId = setTimeout(() => {
            reject(new sdkErrors_js_1.TimeoutError(operation, timeoutMs));
        }, timeoutMs);
    });
    try {
        return await Promise.race([promise, timeoutPromise]);
    }
    finally {
        if (timeoutId)
            clearTimeout(timeoutId);
    }
}
//# sourceMappingURL=timeoutConfig.js.map