- ASP.NET Core 9 Razor Pages + Minimal API hybrid - 14 validators (CPF, CEP, CNPJ, email, phone, name, yes-no, birthdate, handoff, cancel-intent, company-name, plate-br, postal-code, validate_reply) - OAuth login (Google, Microsoft, GitHub) + cookie auth - MongoDB usage tracking + CEP cache collection - Stripe checkout with inline PriceData (no Price IDs) - MCP server for Claude Code / Cursor integration - Playground (10 calls/IP/day, no auth) - Docs: Quickstart, API Reference, N8N, MCP, Créditos, Erros, Fluxos - Credit system: 3 cr standard validators, 5 cr validate_reply - SmartSuggestion: contextual re-ask via IA when obtained=false - Per-IP rate limiting + daily cap + shared-IP abuse detection - Lightbox for comic images - Validadores page split: Brasileiros / Universais + Em breve Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
using Nalu.Web.PostProcessors;
|
|
|
|
namespace Nalu.Web.Services;
|
|
|
|
public record PostProcessorOutput
|
|
{
|
|
public string? Value { get; init; }
|
|
public bool IsValid { get; init; } = true;
|
|
public bool WasCorrected { get; init; }
|
|
public string? OriginalValue { get; init; }
|
|
public string? InvalidReason { get; init; }
|
|
/// Overrides suggestion template key — set by processors like CalculateAge ("when_minor").
|
|
public string? SuggestionKeyOverride { get; init; }
|
|
}
|
|
|
|
public class PostProcessorRegistry
|
|
{
|
|
private readonly Dictionary<string, IPostProcessor> _processors;
|
|
|
|
public PostProcessorRegistry(IEnumerable<IPostProcessor> processors)
|
|
{
|
|
_processors = processors.ToDictionary(p => p.Name, StringComparer.OrdinalIgnoreCase);
|
|
}
|
|
|
|
public PostProcessorOutput Apply(IReadOnlyList<string> processorNames, string? value)
|
|
{
|
|
bool wasCorrected = false;
|
|
string? originalValue = null;
|
|
string? suggestionKeyOverride = null;
|
|
|
|
foreach (var name in processorNames)
|
|
{
|
|
if (!_processors.TryGetValue(name, out var processor)) continue;
|
|
|
|
var result = processor.Process(value);
|
|
|
|
if (!result.IsValid)
|
|
return new PostProcessorOutput { Value = null, IsValid = false, InvalidReason = result.InvalidReason };
|
|
|
|
if (result.WasCorrected)
|
|
{
|
|
wasCorrected = true;
|
|
originalValue ??= result.OriginalValue;
|
|
}
|
|
|
|
if (result.SuggestionKeyOverride is not null)
|
|
suggestionKeyOverride = result.SuggestionKeyOverride;
|
|
|
|
value = result.Value;
|
|
}
|
|
|
|
return new PostProcessorOutput
|
|
{
|
|
Value = value,
|
|
IsValid = true,
|
|
WasCorrected = wasCorrected,
|
|
OriginalValue = originalValue,
|
|
SuggestionKeyOverride = suggestionKeyOverride
|
|
};
|
|
}
|
|
}
|