/*! @azure/msal-browser v5.11.0 2026-05-19 */
'use strict';
import { HttpMethod } from './IHttpClient.mjs';
import { HttpError } from '../../error/HttpError.mjs';
import { AADServerParamKeys } from '@azure/msal-common/browser';
import { NoNetworkConnectivity, FailedSendRequest } from '../../error/HttpErrorCodes.mjs';

/*
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License.
 */
/**
 * Implementation of IHttpClient using fetch.
 */
class FetchHttpClient {
    constructor(logger) {
        this.logger = logger;
    }
    async sendAsync(url, options) {
        const headers = options.headers;
        const correlationId = headers?.[AADServerParamKeys.CLIENT_REQUEST_ID] || "";
        try {
            this.logger.verbosePii("17dhbs", correlationId);
            const startTime = performance.now();
            const response = await fetch(url, options);
            const endTime = performance.now();
            this.logger.verbosePii("1egykc", correlationId);
            return response;
        }
        catch (e) {
            this.logger.errorPii("0ye3lm", correlationId);
            if (!window.navigator.onLine) {
                throw new HttpError(NoNetworkConnectivity, `No network connectivity: ${e}`, correlationId);
            }
            throw new HttpError(FailedSendRequest, `Failed to send request: ${e}`, correlationId);
        }
    }
    async post(url, body, headers = {}) {
        return this.sendAsync(url, {
            method: HttpMethod.POST,
            headers,
            body,
        });
    }
    async get(url, headers = {}) {
        return this.sendAsync(url, {
            method: HttpMethod.GET,
            headers,
        });
    }
}

export { FetchHttpClient };
//# sourceMappingURL=FetchHttpClient.mjs.map
