import { aO as removeSecretFile, aG as readSecretFile, ba as writeSecretFile, h as assertSafeSecretFilename } from './src-CidJbygh.js';
import { g as getState } from './state-fxN45gBp.js';
import { d as getRequestId, r as requireAdmin, k as jsonResponse, e as errorResponse, p as parseJsonBody, j as jsonBodyError } from './helpers-kzwksNq1.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';
import './endpoints-UdQGgKsR.js';

//#region src/routes/admin/secrets/[name]/+server.ts
function guardName(name, requestId) {
	try {
		assertSafeSecretFilename(name);
		return null;
	} catch (err) {
		return errorResponse(400, "bad_request", err.message, {}, requestId);
	}
}
var GET = async (event) => {
	const requestId = getRequestId(event);
	const authError = requireAdmin(event, requestId);
	if (authError) return authError;
	const name = event.params.name;
	const bad = guardName(name, requestId);
	if (bad) return bad;
	const value = readSecretFile(getState().stackDir, name);
	if (value === null) return errorResponse(404, "not_found", `Secret file not found: ${name}`, {}, requestId);
	return jsonResponse(200, {
		name,
		value
	}, requestId);
};
var PUT = async (event) => {
	const requestId = getRequestId(event);
	const authError = requireAdmin(event, requestId);
	if (authError) return authError;
	const name = event.params.name;
	const bad = guardName(name, requestId);
	if (bad) return bad;
	const result = await parseJsonBody(event.request);
	if ("error" in result) return jsonBodyError(result, requestId);
	const value = result.data.value;
	if (typeof value !== "string") return errorResponse(400, "bad_request", "value must be a string", {}, requestId);
	writeSecretFile(getState().stackDir, name, value);
	return jsonResponse(200, {
		ok: true,
		name
	}, requestId);
};
var DELETE = async (event) => {
	const requestId = getRequestId(event);
	const authError = requireAdmin(event, requestId);
	if (authError) return authError;
	const name = event.params.name;
	const bad = guardName(name, requestId);
	if (bad) return bad;
	removeSecretFile(getState().stackDir, name);
	return jsonResponse(200, {
		ok: true,
		name
	}, requestId);
};

export { DELETE, GET, PUT };
//# sourceMappingURL=_server.ts-C8itNTqQ.js.map
