
//#region src/utils/url-utils.ts
/**
* Determines if a Sentry instance is SaaS or self-hosted based on the host.
* @param host The Sentry host (e.g., "sentry.io" or "sentry.company.com")
* @returns true if SaaS instance, false if self-hosted
*/
function isSentryHost(host) {
	return host === "sentry.io" || host.endsWith(".sentry.io");
}
/**
* Generates a Sentry issue URL.
* @param host The Sentry host (may include regional subdomain for API access)
* @param organizationSlug Organization identifier
* @param issueId Issue identifier (e.g., "PROJECT-123")
* @returns The complete issue URL
*/
function getIssueUrl(host, organizationSlug, issueId) {
	const isSaas = isSentryHost(host);
	const webHost = isSaas ? "sentry.io" : host;
	return isSaas ? `https://${organizationSlug}.${webHost}/issues/${issueId}` : `https://${host}/organizations/${organizationSlug}/issues/${issueId}`;
}
/**
* Generates a Sentry issues search URL.
* @param host The Sentry host (may include regional subdomain for API access)
* @param organizationSlug Organization identifier
* @param query Optional search query
* @param projectSlugOrId Optional project slug or ID
* @returns The complete issues search URL
*/
function getIssuesSearchUrl(host, organizationSlug, query, projectSlugOrId) {
	const isSaas = isSentryHost(host);
	const webHost = isSaas ? "sentry.io" : host;
	let url = isSaas ? `https://${organizationSlug}.${webHost}/issues/` : `https://${host}/organizations/${organizationSlug}/issues/`;
	const params = new URLSearchParams();
	if (projectSlugOrId) params.append("project", projectSlugOrId);
	if (query) params.append("query", query);
	const queryString = params.toString();
	if (queryString) url += `?${queryString}`;
	return url;
}
/**
* Generates a Sentry trace URL for performance investigation.
* @param host The Sentry host (may include regional subdomain for API access)
* @param organizationSlug Organization identifier
* @param traceId Trace identifier
* @returns The complete trace URL
*/
function getTraceUrl(host, organizationSlug, traceId) {
	const isSaas = isSentryHost(host);
	const webHost = isSaas ? "sentry.io" : host;
	return isSaas ? `https://${organizationSlug}.${webHost}/explore/traces/trace/${traceId}` : `https://${host}/organizations/${organizationSlug}/explore/traces/trace/${traceId}`;
}
/**
* Generates a Sentry events explorer URL.
* @param host The Sentry host (may include regional subdomain for API access)
* @param organizationSlug Organization identifier
* @param query Search query
* @param dataset Dataset type
* @param projectSlug Optional project slug
* @param fields Optional fields to display
* @returns The complete events explorer URL
*/
function getEventsExplorerUrl(host, organizationSlug, query, dataset = "spans", projectSlug, fields) {
	const isSaas = isSentryHost(host);
	const webHost = isSaas ? "sentry.io" : host;
	let url = isSaas ? `https://${organizationSlug}.${webHost}/explore/` : `https://${host}/organizations/${organizationSlug}/explore/`;
	const params = new URLSearchParams();
	params.append("query", query);
	params.append("dataset", dataset);
	params.append("layout", "table");
	if (projectSlug) params.append("project", projectSlug);
	if (fields && fields.length > 0) for (const field of fields) params.append("field", field);
	url += `?${params.toString()}`;
	return url;
}
/**
* Internal validation function that checks if a SENTRY_HOST value contains only hostname (no protocol).
* Throws an error if validation fails instead of exiting the process.
*
* @param host The hostname to validate
* @throws {Error} If the host contains a protocol
*/
function _validateSentryHostInternal(host) {
	if (host.startsWith("http://") || host.startsWith("https://")) throw new Error("SENTRY_HOST should only contain a hostname (e.g., sentry.example.com). Use SENTRY_URL if you want to provide a full URL.");
}
/**
* Internal validation function that checks if a SENTRY_URL value is a valid HTTPS URL and extracts the hostname.
* Throws an error if validation fails instead of exiting the process.
*
* @param url The HTTPS URL to validate and parse
* @returns The extracted hostname from the URL
* @throws {Error} If the URL is invalid or not HTTPS
*/
function _validateAndParseSentryUrlInternal(url) {
	if (!url.startsWith("https://")) throw new Error("SENTRY_URL must be a full HTTPS URL (e.g., https://sentry.example.com).");
	try {
		const parsedUrl = new URL(url);
		return parsedUrl.host;
	} catch (error) {
		throw new Error("SENTRY_URL must be a valid HTTPS URL (e.g., https://sentry.example.com).");
	}
}
/**
* Validates that a SENTRY_HOST value contains only hostname (no protocol).
* Exits the process with error code 1 if validation fails (CLI behavior).
*
* @param host The hostname to validate
*/
function validateSentryHost(host) {
	try {
		_validateSentryHostInternal(host);
	} catch (error) {
		console.error(`Error: ${error.message}`);
		process.exit(1);
	}
}
/**
* Validates that a SENTRY_URL value is a valid HTTPS URL and extracts the hostname.
* Exits the process with error code 1 if validation fails (CLI behavior).
*
* @param url The HTTPS URL to validate and parse
* @returns The extracted hostname from the URL
*/
function validateAndParseSentryUrl(url) {
	try {
		return _validateAndParseSentryUrlInternal(url);
	} catch (error) {
		console.error(`Error: ${error.message}`);
		process.exit(1);
	}
}
/**
* Validates that a SENTRY_HOST value contains only hostname (no protocol).
* Throws an error instead of exiting the process (for testing).
*
* @param host The hostname to validate
* @throws {Error} If the host contains a protocol
*/
function validateSentryHostThrows(host) {
	_validateSentryHostInternal(host);
}
/**
* Validates that a SENTRY_URL value is a valid HTTPS URL and extracts the hostname.
* Throws an error instead of exiting the process (for testing).
*
* @param url The HTTPS URL to validate and parse
* @returns The extracted hostname from the URL
* @throws {Error} If the URL is invalid or not HTTPS
*/
function validateAndParseSentryUrlThrows(url) {
	return _validateAndParseSentryUrlInternal(url);
}
/**
* Validates that the provided OpenAI base URL is a valid HTTP(S) URL and returns a normalized string.
*
* @param url The URL to validate and normalize
* @returns The normalized URL string
* @throws {Error} If the URL is empty, invalid, or uses an unsupported protocol
*/
function validateOpenAiBaseUrlThrows(url) {
	const trimmed = url.trim();
	if (trimmed.length === 0) throw new Error("OPENAI base URL must not be empty.");
	let parsed;
	try {
		parsed = new URL(trimmed);
	} catch (error) {
		throw new Error("OPENAI base URL must be a valid HTTP or HTTPS URL (e.g., https://example.com/v1).", { cause: error });
	}
	if (parsed.protocol !== "https:" && parsed.protocol !== "http:") throw new Error("OPENAI base URL must use http or https scheme (e.g., https://example.com/v1).");
	return parsed.toString();
}

//#endregion
Object.defineProperty(exports, 'getEventsExplorerUrl', {
  enumerable: true,
  get: function () {
    return getEventsExplorerUrl;
  }
});
Object.defineProperty(exports, 'getIssueUrl', {
  enumerable: true,
  get: function () {
    return getIssueUrl;
  }
});
Object.defineProperty(exports, 'getIssuesSearchUrl', {
  enumerable: true,
  get: function () {
    return getIssuesSearchUrl;
  }
});
Object.defineProperty(exports, 'getTraceUrl', {
  enumerable: true,
  get: function () {
    return getTraceUrl;
  }
});
Object.defineProperty(exports, 'isSentryHost', {
  enumerable: true,
  get: function () {
    return isSentryHost;
  }
});
Object.defineProperty(exports, 'validateAndParseSentryUrl', {
  enumerable: true,
  get: function () {
    return validateAndParseSentryUrl;
  }
});
Object.defineProperty(exports, 'validateAndParseSentryUrlThrows', {
  enumerable: true,
  get: function () {
    return validateAndParseSentryUrlThrows;
  }
});
Object.defineProperty(exports, 'validateOpenAiBaseUrlThrows', {
  enumerable: true,
  get: function () {
    return validateOpenAiBaseUrlThrows;
  }
});
Object.defineProperty(exports, 'validateSentryHost', {
  enumerable: true,
  get: function () {
    return validateSentryHost;
  }
});
Object.defineProperty(exports, 'validateSentryHostThrows', {
  enumerable: true,
  get: function () {
    return validateSentryHostThrows;
  }
});
//# sourceMappingURL=url-utils-Bn5EoScr.cjs.map