import { convert } from "@scalar/postman-to-openapi";
//#region src/libs/postman.ts
/** Checks if the given content is a Postman collection */
function isPostmanCollection(content) {
	try {
		const parsed = JSON.parse(content);
		return parsed.info?._postman_id !== void 0 && new URL(parsed.info?.schema).host === "schema.getpostman.com";
	} catch (_error) {
		return false;
	}
}
/** Converts a Postman collection JSON string to an OpenAPI JSON string */
function convertPostmanToOpenApi(postmanJson) {
	try {
		const openApiDoc = convert(JSON.parse(postmanJson));
		return JSON.stringify(openApiDoc, null, 2);
	} catch (_error) {
		throw new Error("Failed to convert Postman collection to OpenAPI");
	}
}
/** Extracts details from a Postman collection JSON string */
function getPostmanDocumentDetails(content) {
	try {
		if (isPostmanCollection(content)) {
			const parsed = JSON.parse(content);
			return {
				type: "json",
				title: parsed.info?.name || "Postman Collection",
				version: parsed.info?.version || "1.0"
			};
		}
		return null;
	} catch {
		return null;
	}
}
//#endregion
export { convertPostmanToOpenApi, getPostmanDocumentDetails, isPostmanCollection };

//# sourceMappingURL=postman.js.map