#pragma once #include #include #include #include #include #include #include #include #include #include namespace Echoion::Plugins::ShortUrl { enum class ExternalEncoding { query, json, form }; enum class ExternalResponseKind { plain, header, jsonPointer }; struct ExternalFieldTemplate { std::string name; std::string value; }; struct ExternalHeaderTemplate { std::string name; std::string value; bool sensitive{}; }; struct ExternalResponseConfig { ExternalResponseKind kind{ExternalResponseKind::jsonPointer}; std::string selector{"/shortUrl"}; }; struct ExternalConfig { std::string endpoint; Void::Net::Method method{Void::Net::Method::Post}; ExternalEncoding encoding{ExternalEncoding::json}; std::vector fields; std::vector headers; ExternalResponseConfig response; bool allowHttp{}; bool allowPrivateHosts{}; bool allowPrivateTargets{}; bool allowCrossHostRedirects{}; int maxRedirects{}; std::uint32_t timeoutSeconds{3}; std::size_t maximumResponseBytes{64U * 1024U}; std::size_t cacheCapacity{512}; std::uint32_t cacheTtlSeconds{3600}; std::size_t maximumConcurrency{4}; }; // Missing endpoint means this optional provider is intentionally dormant. // Malformed or partially-present configuration still counts as configured // so plugin activation rejects it instead of silently ignoring it. [[nodiscard]] bool hasExternalConfiguration(std::string_view payload); [[nodiscard]] std::expected parseExternalConfig(std::string_view payload); class ExternalShortener { public: [[nodiscard]] static std::expected< std::unique_ptr, std::string> create(ExternalConfig config); ~ExternalShortener(); ExternalShortener(const ExternalShortener&) = delete; ExternalShortener& operator=(const ExternalShortener&) = delete; [[nodiscard]] Void::ShortUrl::Health health() const; [[nodiscard]] Void::ShortUrl::ShortenResult shorten(const Void::ShortUrl::ShortenRequest& request); /// Pure request/extraction seams used by focused tests and provider /// configuration diagnostics. They never perform network I/O. [[nodiscard]] std::expected previewRequest(std::string_view targetUrl) const; [[nodiscard]] std::expected previewExtract(const Void::Net::Response& response) const; private: struct ConstructionToken { explicit ConstructionToken() = default; }; struct Impl; public: ExternalShortener(ConstructionToken, ExternalConfig config); private: std::unique_ptr impl_; }; } // namespace Echoion::Plugins::ShortUrl