import { asTimestamp } from "../../../util/timestamp.js";
import { Datasource } from "../datasource.js";
import { PUPPET_FORGE } from "./common.js";

//#region lib/modules/datasource/puppet-forge/index.ts
var PuppetForgeDatasource = class PuppetForgeDatasource extends Datasource {
	static id = "puppet-forge";
	constructor() {
		super(PuppetForgeDatasource.id);
	}
	defaultRegistryUrls = [PUPPET_FORGE];
	releaseTimestampSupport = true;
	releaseTimestampNote = "The release timestamp is determined from the `created_at` field from the response.";
	async getReleases({ packageName, registryUrl }) {
		const url = `${registryUrl}/v3/modules/${packageName.replace("/", "-")}?exclude_fields=current_release`;
		let module;
		try {
			module = (await this.http.getJsonUnchecked(url)).body;
		} catch (err) {
			this.handleGenericErrors(err);
		}
		const releases = module?.releases?.map((release) => ({
			version: release.version,
			downloadUrl: release.file_uri,
			releaseTimestamp: asTimestamp(release.created_at),
			registryUrl
		}));
		if (!releases?.length) return null;
		return PuppetForgeDatasource.createReleaseResult(releases, module);
	}
	static createReleaseResult(releases, module) {
		const result = {
			releases,
			homepage: module.homepage_url
		};
		if (module.deprecated_for) result.deprecationMessage = module.deprecated_for;
		return result;
	}
};

//#endregion
export { PuppetForgeDatasource };
//# sourceMappingURL=index.js.map