ResultAble 1.0.0

dotnet add package ResultAble --version 1.0.0
NuGet\Install-Package ResultAble -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ResultAble" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ResultAble --version 1.0.0
#r "nuget: ResultAble, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ResultAble as a Cake Addin
#addin nuget:?package=ResultAble&version=1.0.0

// Install ResultAble as a Cake Tool
#tool nuget:?package=ResultAble&version=1.0.0

ResultAble

ResultAble is a utility for the IronVelo IdP SDK, designed to handle responses from the IdP in a type-safe manner. This utility is specifically tailored for use with IronVelo's SDK, generating source code that directly references types exposed in the SDK package.

Why Does ResultAble Exist?

ResultAble was created to simplify interactions with the IdP, which leverages sum types extensively. Many responses from the IdP are serialized sum types, and modeling these responses for every request can be cumbersome and error-prone. This utility streamlines the process by converting the IdP's responses into IronVelo's Result type, making the interactions easier to reason about and reducing boilerplate code. Note that this implementation is domain-specific and does not provide the ability to create sum types in C#. For general sum type support, consider libraries like OneOf.

Example

Consider a login flow where we need to verify the user's MFA method. The IdP's response will either indicate that the user must retry or provide a token representing the login state (in the ret field). Using ResultAble, we can handle this response as follows:

Define the response type with the Result attribute:

using ResultAble;

[Result]
internal partial record OtpCheckRes(
    [property: Ok] string Token,
    [property: Error] bool Failure
);

Convert OtpCheckRes into a result using the generated ToResult method:

return res
    .ToResult()
    // Handle success or failure in a type-safe manner
    .MapOr(
        Result<Token, RetryInitMfa>.Failure(new RetryInitMfa(Client, res.Permit, MfaKinds)), 
        rawToken => Result<Token, RetryInitMfa>.Success(new Token(rawToken))
    );

By using ResultAble, we eliminate the need to check the nullability of options for every request, allowing us to focus on ensuring our logic is correct. This leads to safer and more robust interactions with the IdP.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ResultAble:

Package Downloads
IronVelo

The IronVelo C# SDK provides a robust and user-friendly interface for integrating with IronVelo's Identity Provider (IdP), as well as utilities for secure programming.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 65 6/21/2024