Skip to content

Commit fbb63e0

Browse files
committed
Merge remote-tracking branch 'origin/development' into development
# Conflicts: # src/SharedKernel/SharedKernel.csproj
2 parents 53f4b2e + e9e961a commit fbb63e0

File tree

8 files changed

+68
-12
lines changed

8 files changed

+68
-12
lines changed

Readme.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ AssemblyRegistry.Add(typeof(Program).Assembly);
130130
builder
131131
.ConfigureWithPandaVault()
132132
.AddSerilog()
133-
.AddResponseCrafter(NamingConvention.ToSnakeCase)
133+
.AddResponseCrafter(NamingConvention.ToUpperSnakeCase)
134134
.AddOpenApi()
135135
.AddOpenTelemetry()
136136
.AddMapMinimalApis(AssemblyRegistry.ToArray())
@@ -404,6 +404,9 @@ The package includes extension methods to simplify common validation scenarios:
404404
- String Validations:
405405
- IsValidJson(): Validates that a string is a valid JSON.
406406
- IsXssSanitized(): Validates that a string is sanitized against XSS attacks.
407+
- IsEmail(): Validates that a string is a valid email address. Native one is not working correctly.
408+
- IsPhoneNumber(): Validates that a string is a valid phone number. Format requires area code to be in `()`.
409+
- IsEmailOrPhoneNumber(): Validates that a string is either a valid email address or a valid phone number.
407410

408411
## Cors
409412

Shared.Kernel.Demo/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
.AddControllers(AssemblyRegistry.ToArray())
2626
.AddMediatrWithBehaviors(AssemblyRegistry.ToArray())
2727
.AddResilienceDefaultPipeline()
28-
// .AddRedis(KeyPrefix.AssemblyNamePrefix)
28+
// .AddRedis(KeyPrefix.AssemblyNamePrefix)
2929
//.AddDistributedSignalR("DistributedSignalR") // or .AddSignalR()
3030
.MapDefaultTimeZone()
3131
.AddCors()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.AspNetCore.Http;
2+
3+
namespace SharedKernel.Extensions;
4+
5+
public static class HttpContextExtensions
6+
{
7+
public static void MarkAsPrivateEndpoint(this HttpContext context)
8+
{
9+
context.Response.Headers.Append("X-Private-Endpoint", "1");
10+
}
11+
12+
public static void MarkAsPrivateEndpoint(this HttpResponse response)
13+
{
14+
response.Headers.Append("X-Private-Endpoint", "1");
15+
}
16+
17+
public static void MarkAsPrivateEndpoint(this IHttpContextAccessor contextAccessor)
18+
{
19+
contextAccessor.HttpContext?.Response.Headers.Append("X-Private-Endpoint", "1");
20+
}
21+
22+
public static void MarkAsPrivateEndpoint(this HttpContextAccessor contextAccessor)
23+
{
24+
contextAccessor.HttpContext?.Response.Headers.Append("X-Private-Endpoint", "1");
25+
}
26+
}

src/SharedKernel/Extensions/SignalRExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.SignalR;
23
using Microsoft.Extensions.DependencyInjection;
4+
using ResponseCrafter.ExceptionHandlers.SignalR;
35
using StackExchange.Redis;
46

57
namespace SharedKernel.Extensions;
@@ -11,7 +13,7 @@ public static WebApplicationBuilder AddSignalR(this WebApplicationBuilder builde
1113
{
1214
builder
1315
.Services
14-
.AddSignalR()
16+
.AddSignalR(o => o.AddFilter<SignalRExceptionFilter>())
1517
.AddMessagePackProtocol();
1618

1719
return builder;
@@ -21,7 +23,7 @@ public static WebApplicationBuilder AddDistributedSignalR(this WebApplicationBui
2123
{
2224
builder
2325
.Services
24-
.AddSignalR()
26+
.AddSignalR(o => o.AddFilter<SignalRExceptionFilter>())
2527
.AddMessagePackProtocol()
2628
.AddStackExchangeRedis(builder.Configuration.GetRedisUrl(),
2729
options =>

src/SharedKernel/Logging/RequestResponseLoggingMiddleware.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal class RequestResponseLoggingMiddleware(RequestDelegate next, ILogger<Re
1919

2020
public async Task InvokeAsync(HttpContext context)
2121
{
22-
if (context.Request.Method.Equals("OPTIONS", StringComparison.OrdinalIgnoreCase))
22+
if (HttpMethods.IsOptions(context.Request.Method))
2323
{
2424
await next(context);
2525
return;
@@ -31,6 +31,7 @@ public async Task InvokeAsync(HttpContext context)
3131
var originalBodyStream = context.Response.Body;
3232
await using var responseBody = new MemoryStream();
3333
context.Response.Body = responseBody;
34+
3435
var stopwatch = Stopwatch.GetTimestamp();
3536
try
3637
{
@@ -81,7 +82,6 @@ public async Task InvokeAsync(HttpContext context)
8182
var body = await reader.ReadToEndAsync();
8283
var sanitizedHeaders = JsonSerializer.Serialize(RedactSensitiveData(headers));
8384
var bodyContent = JsonSerializer.Serialize(ParseAndRedactJson(body));
84-
8585
return (sanitizedHeaders, bodyContent);
8686
}
8787

src/SharedKernel/SharedKernel.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<PackageReadmeFile>Readme.md</PackageReadmeFile>
99
<Authors>Pandatech</Authors>
1010
<Copyright>MIT</Copyright>
11-
<Version>1.0.19</Version>
11+
<Version>1.0.23</Version>
1212
<PackageId>Pandatech.SharedKernel</PackageId>
1313
<Title>Pandatech Shared Kernel Library</Title>
1414
<PackageTags>Pandatech, shared kernel, library, OpenAPI, Swagger, utilities, scalar</PackageTags>
@@ -27,8 +27,8 @@
2727
</ItemGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="AspNetCore.HealthChecks.Prometheus.Metrics" Version="8.0.1" />
31-
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="8.0.1" />
30+
<PackageReference Include="AspNetCore.HealthChecks.Prometheus.Metrics" Version="9.0.0" />
31+
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0" />
3232
<PackageReference Include="Elastic.CommonSchema.Serilog" Version="8.12.3" />
3333
<PackageReference Include="FluentDateTime" Version="3.0.0" />
3434
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
@@ -51,8 +51,8 @@
5151
<PackageReference Include="Pandatech.FluentMinimalApiMapper" Version="2.0.1" />
5252
<PackageReference Include="Pandatech.PandaVaultClient" Version="4.0.3" />
5353
<PackageReference Include="Pandatech.RegexBox" Version="3.0.0" />
54-
<PackageReference Include="Pandatech.ResponseCrafter" Version="5.1.4" />
55-
<PackageReference Include="Scalar.AspNetCore" Version="1.2.51" />
54+
<PackageReference Include="Pandatech.ResponseCrafter" Version="5.1.3" />
55+
<PackageReference Include="Scalar.AspNetCore" Version="1.2.66" />
5656
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
5757
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="7.2.0" />
5858
</ItemGroup>

src/SharedKernel/ValidatorAndMediatR/Validators/ValidatorExtensions.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
11
using FluentValidation;
22
using Microsoft.AspNetCore.Http;
3+
using RegexBox;
34

45
namespace SharedKernel.ValidatorAndMediatR.Validators;
56

67
public static class ValidatorExtensions
78
{
9+
public static IRuleBuilderOptions<T, string?> IsEmail<T>(this IRuleBuilder<T, string?> ruleBuilder)
10+
{
11+
return ruleBuilder.Must(x => x is null || PandaValidator.IsEmail(x))
12+
.WithMessage("email_format_is_not_valid");
13+
}
14+
15+
public static IRuleBuilderOptions<T, string?> IsPhoneNumber<T>(this IRuleBuilder<T, string?> ruleBuilder)
16+
{
17+
return ruleBuilder.Must(x => x is null || PandaValidator.IsPandaFormattedPhoneNumber(x))
18+
.WithMessage("phone_number_format_is_not_valid");
19+
}
20+
21+
public static IRuleBuilderOptions<T, string?> IsEmailOrPhoneNumber<T>(this IRuleBuilder<T, string?> ruleBuilder)
22+
{
23+
return ruleBuilder
24+
.Must(x => x is null || PandaValidator.IsPandaFormattedPhoneNumber(x) || PandaValidator.IsEmail(x))
25+
.WithMessage("phone_number_or_email_format_is_not_valid");
26+
}
27+
28+
public static IRuleBuilderOptions<T, string?> IsPhoneNumberOrEmail<T>(this IRuleBuilder<T, string?> ruleBuilder)
29+
{
30+
return ruleBuilder.IsEmailOrPhoneNumber();
31+
}
32+
833
public static IRuleBuilderOptions<T, IFormFile?> HasMaxFileSize<T>(this IRuleBuilder<T, IFormFile?> ruleBuilder,
934
int maxFileSizeInMb)
1035
{

test/SharedKernel.Tests/SharedKernel.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
1414
<PackageReference Include="xunit" Version="2.9.2" />
15-
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
15+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1717
<PrivateAssets>all</PrivateAssets>
1818
</PackageReference>

0 commit comments

Comments
 (0)