const ALLOWED_CREDENTIAL_URL_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:"]);
function isValidCredentialUrl(value) {
  let parsed;
  try {
    parsed = new URL(value);
  } catch {
    return false;
  }
  if (!ALLOWED_CREDENTIAL_URL_PROTOCOLS.has(parsed.protocol)) return false;
  if (!parsed.hostname) return false;
  if (parsed.username || parsed.password) return false;
  return true;
}
const defaultUrlMessageBuilder = (field) => `${field.label || field.key} must be a valid http(s) URL.`;
function collectCredentialUrlValidationErrors(schema, credentials, buildMessage = defaultUrlMessageBuilder) {
  const fieldErrors = {};
  if (!schema?.fields) return fieldErrors;
  for (const field of schema.fields) {
    if (field.type !== "url") continue;
    const value = credentials[field.key];
    if (typeof value !== "string") continue;
    if (value.trim().length === 0) continue;
    if (!isValidCredentialUrl(value)) {
      fieldErrors[field.key] = buildMessage({ key: field.key, label: field.label });
    }
  }
  return fieldErrors;
}
export {
  collectCredentialUrlValidationErrors,
  isValidCredentialUrl
};
//# sourceMappingURL=credentials-field-validation.js.map
