/*
 * Copyright (c) 2023-2025 Datalayer, Inc.
 * Distributed under the terms of the Modified BSD License.
 */
/**
 * Fetch the session ID of a collaborative documents from Datalayer.
 */
export async function requestDatalayerCollaborationSessionId({ url, token, fetchFn = fetch, }) {
    const headers = {
        Accept: 'application/json',
    };
    if (token) {
        headers['Authorization'] = `Bearer ${token}`;
    }
    const response = await fetchFn(url, {
        method: 'GET',
        headers,
        credentials: token ? 'include' : 'omit',
        mode: 'cors',
        cache: 'no-store',
    });
    if (response.ok) {
        const content = await response.json();
        return content['sessionId'];
    }
    console.error('Failed to fetch session ID.', response);
    throw new Error('Failed to fetch session ID.');
}
