code4me / 4me-sdk-graphql-dotnet

.NET SDK for 4me GraphQL, see https://developer.4me.com/graphql/
MIT License
3 stars 1 forks source link

Support for .NET framework or .NET standard #8

Closed TheToor closed 6 months ago

TheToor commented 6 months ago

As far as I can see the only dependency the sdk has is on the JSON library which fully supports .NET framework and .NET standard. I know the way forward is to support newer .NET platform.

But as it stands .NET framework is still widely used on Windows systems. Additionaly some PowerShell modules are only compatible with PowerShell 5.1 which is based on .NET framework. To be able to load the 4me SDK in PowerShell 5.1 it needs to be compiled for .NET framework.

So I kindly ask you if you can provide an additionaly .NET framework package to Nuget so we may write a PowerShell wrapper for the 4me sdk which works on both PowerShell and PowerShell Core.

klaasvandeweerdt commented 6 months ago

@TheToor, let me investigate this further. I need to verify the features supported in .NET Framework 4.6.2, the minimum version still supported. This will require some testing. Additionally, the current code utilizes is C# 10 syntax, and need to be converted to 7.3 for compatibility with .NET Framework.

TheToor commented 6 months ago

@klaasvandeweerdt as alternative I could implement the Module in PowerShell native code with no dependencies on the sdk. But this would then mean we need to update two implementations of the GraphQL API which is also possible but maybe even more work?

klaasvandeweerdt commented 6 months ago

@TheToor, I took some time to see what the impact and effort would be to make it .NET Framework compatible. The main issue are null reference-types which do not exist in .NET Framework. when I change the language version to 9.0 most of the errors are gone and they have no impact as lot of those language version changes are syntactic. I'll get back to you later this week with an update.

klaasvandeweerdt commented 6 months ago

@TheToor, I have a local version compatible with .NET 6.0, .Net Framework 4.7.2, and .NET Standard 2.0. I still need to extend the tests to make sure everything is working as expected. There is only main difference between those is the DateOnly and DateTime, a set of properties are DateOnly in dot6.0, and are DateTime for Framework and Standard.

TheToor commented 6 months ago

That's great to hear. Looking forward to not having to re-implement everything :)

TheToor commented 6 months ago

@klaasvandeweerdt I do have another question not directly related to this GraphQL SDK but about 4me supporting another simplified version of a PowerShell module (to send events to /events endpoint) which does not require all the overhead of this SDK. Is there another better way to contact you regarding this?

klaasvandeweerdt commented 6 months ago

@TheToor, the easiest way to get help for this type of questions would be via the 4me Community. I haven't written PowerShell in quite a while, but I did find some old scripts, and it seems that some still work.

# Call the Events API endpoint
function Invoke-4meEventApi {
    param(
        [string]$Account,
        [string]$ClientId,
        [string]$ClientSecret,
        [object]$EventData
    )

    #Get the Bearer token
    $body = @{
        grant_type    = "client_credentials"
        client_id     = $ClientId
        client_secret = $ClientSecret
    }
    $response = Invoke-RestMethod -Uri "https://oauth.4me.qa/token" -Method Post -Body $body
    $access_token = $response.access_token

    #Create the event
    $header = @{
        Authorization = "Bearer $access_token"
        "Content-Type" = "application/json"
        "x-4me-account" = $Account
    }
    $response = Invoke-RestMethod -Uri "https://api.4me.qa/v1/events" -Method Post -Headers $header -Body $EventData
    return $response
}

# Set the 4me account ID and the OAuth2 credentials
$accountID = "the 4me account ID"
$clientId = "the client ID"
$clientSecret = "the client secret"

# Set the events API data
# More info about the Events API fields on https://developer.4me.com/v1/requests/events/
$jsonData = @{
    "team_id" = 1
    "subject" = "Via powershell"
    "category" = "other"
} | ConvertTo-Json

# Call the API endpoint with OAuth2 authentication
$response = Invoke-4meEventApi -Account $accountID -ClientId $clientId -ClientSecret $clientSecret -EventData $jsonData

# Output the request ID
$response.ID

If you need to create more events in the same script you could store the $response.access_token to avoid additional requests.

klaasvandeweerdt commented 6 months ago

@TheToor, I've pushed the code changes and published a new NuGet package. Release 1.3, is now compatible with .NET Framework 4.7.2 or above, and .NET Standard 2.0.

TheToor commented 6 months ago

Thanks I'll look into the updated nuget package.

Regarding the PowerShell. It's not about writing the script. I developed the module already. It's about publishing the module. I think it's best if you guys would sign and publish the module instead of someone like me so you can reserve the 4me Prefix ID on Nuget and PowerShell Gallery.

I can provide the module (and help maintain if required) but I would like to know your stance on it.

klaasvandeweerdt commented 6 months ago

@TheToor, I contacted you using the email address listed on your profile page. Let's carry on our discussion through that channel.