import { d as deleteEndpoint, v as validateEndpointUrl, u as updateEndpoint } from './endpoints-UdQGgKsR.js';
import { d as getRequestId, r as requireAdmin, k as jsonResponse, e as errorResponse, w as withAdminBody } from './helpers-kzwksNq1.js';
import './state-fxN45gBp.js';
import './src-CidJbygh.js';
import './chunk-CLZ62Ad-.js';
import 'node:module';
import './provider-constants-DPrj3yBX.js';
import './dist-DOFcG0Zp.js';
import 'node:fs';
import 'node:path';
import 'buffer';
import 'fs';
import 'path';
import 'node:child_process';
import 'node:url';
import 'node:crypto';
import 'events';
import 'node:events';
import 'node:stream';
import 'node:string_decoder';
import 'assert';
import 'zlib';
import 'node:assert';
import 'node:fs/promises';
import 'node:os';

//#region src/routes/admin/endpoints/[id]/+server.ts
var PATCH = async (event) => withAdminBody(event, async ({ requestId, body }) => {
	const id = event.params.id;
	const patch = {};
	if (typeof body.label === "string") patch.label = body.label;
	if (typeof body.url === "string") {
		const urlCheck = validateEndpointUrl(body.url);
		if (!urlCheck.ok) {
			if (urlCheck.reason === "http_not_allowed") return errorResponse(400, "http_not_allowed", "Plain HTTP is only allowed for loopback addresses. Use https:// for remote OpenPalm instances.", {}, requestId);
			return errorResponse(400, "invalid_endpoint", "URL must be a valid http(s) URL", {}, requestId);
		}
		patch.url = urlCheck.url;
	}
	if (body.password === null) patch.password = null;
	else if (typeof body.password === "string") patch.password = body.password;
	try {
		const entry = updateEndpoint(id, patch);
		return jsonResponse(200, { endpoint: {
			id: entry.id,
			label: entry.label,
			url: entry.url,
			isDefault: false,
			hasPassword: Boolean(entry.password)
		} }, requestId);
	} catch (e) {
		const msg = e instanceof Error ? e.message : "failed to update endpoint";
		const status = msg.startsWith("Endpoint not found") ? 404 : 400;
		return errorResponse(status, status === 404 ? "not_found" : "invalid_endpoint", msg, {}, requestId);
	}
});
var DELETE = async (event) => {
	const requestId = getRequestId(event);
	const authError = requireAdmin(event, requestId);
	if (authError) return authError;
	const id = event.params.id;
	try {
		deleteEndpoint(id);
		return jsonResponse(200, { ok: true }, requestId);
	} catch (e) {
		const msg = e instanceof Error ? e.message : "failed to delete endpoint";
		const status = msg.startsWith("Endpoint not found") ? 404 : 400;
		return errorResponse(status, status === 404 ? "not_found" : "invalid_endpoint", msg, {}, requestId);
	}
};

export { DELETE, PATCH };
//# sourceMappingURL=_server.ts-YBAOIJxB.js.map
