
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="9dcd9e6f-5a37-5956-ab6d-171dea11455c")}catch(e){}}();
import { ApifyClient as _ApifyClient } from 'apify-client';
import { USER_AGENT_ORIGIN } from './const.js';
/**
 * Adds a User-Agent header to the request config.
 * @param config
 * @private
 */
function addUserAgent(config) {
    var _a, _b;
    const updatedConfig = { ...config };
    updatedConfig.headers = (_a = updatedConfig.headers) !== null && _a !== void 0 ? _a : {};
    updatedConfig.headers['User-Agent'] = `${(_b = updatedConfig.headers['User-Agent']) !== null && _b !== void 0 ? _b : ''}; ${USER_AGENT_ORIGIN}`;
    return updatedConfig;
}
export function getApifyAPIBaseUrl() {
    // Workaround for Actor server where the platform APIFY_API_BASE_URL did not work with getActorDefinition from actors.ts
    if (process.env.APIFY_IS_AT_HOME)
        return 'https://api.apify.com';
    return process.env.APIFY_API_BASE_URL || 'https://api.apify.com';
}
export class ApifyClient extends _ApifyClient {
    constructor(options) {
        var _a;
        /**
         * In order to publish to DockerHub, we need to run their build task to validate our MCP server.
         * This was failing since we were sending this dummy token to Apify in order to build the Actor tools.
         * So if we encounter this dummy value, we remove it to use Apify client as unauthenticated, which is sufficient
         * for server start and listing of tools.
         */
        if (((_a = options.token) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'your-apify-token' || options.token === null) {
            // eslint-disable-next-line no-param-reassign
            delete options.token;
        }
        const { paymentHeaders, ...clientOptions } = options;
        const requestInterceptors = [addUserAgent];
        /**
         * Add payment headers if provided by a PaymentProvider.
         */
        if (paymentHeaders && Object.keys(paymentHeaders).length > 0) {
            requestInterceptors.push((config) => {
                var _a;
                const updatedConfig = { ...config };
                updatedConfig.headers = (_a = updatedConfig.headers) !== null && _a !== void 0 ? _a : {};
                Object.assign(updatedConfig.headers, paymentHeaders);
                return updatedConfig;
            });
        }
        super({
            // token null case is handled, we can assert type here
            ...clientOptions,
            baseUrl: getApifyAPIBaseUrl(),
            requestInterceptors,
        });
    }
}
//# sourceMappingURL=apify_client.js.map
//# debugId=9dcd9e6f-5a37-5956-ab6d-171dea11455c
