Modules/businessdev.ALbuild.Feeds/Public/Get-BcPackageVersion.ps1

function Get-BcPackageVersion {
    <#
    .SYNOPSIS
        The published versions of one or more package ids on a feed.
 
    .DESCRIPTION
        A plain listing, for the times when the question is "what is already on the feed" rather than
        "resolve a dependency". The runtime factory asks it to decide what it still has to build:
        idempotency keyed on blob storage alone lets blob and feed drift apart, because the checkpoint
        uploads to blob first and pushes to the feed second, and a failed push is warned about rather
        than fatal.
 
        THE EMPTY-RESULT TRAP
        The provider's version lookup swallows every error and returns nothing, so "this package has no
        versions" and "the feed could not be asked" look identical from the outside. Reading the second
        as the first would tell the factory that nothing is published and send it off to rebuild the
        whole matrix - hundreds of containers.
 
        So the feed is proven reachable and authorised FIRST, on its own, and a failure there throws.
        After that an empty version list genuinely means the package is absent, and callers can trust
        it. A caller that would rather degrade than rebuild should catch the exception and fall back.
 
    .PARAMETER Feed
        A feed from Register-BcFeed or Get-BcFeed.
 
    .PARAMETER PackageId
        One or more package ids. Ids are matched case-insensitively by the feed, as NuGet requires.
 
    .EXAMPLE
        $feed = Register-BcFeed -Name rt -Kind runtime -Url $url -Token $token
        Get-BcPackageVersion -Feed $feed -PackageId '365businessdevelopment.365businessbanking.runtime-18-3-513-27128'
 
    .EXAMPLE
        # What is already on the feed, as the factory asks it.
        Get-BcPackageVersion -Feed $feed -PackageId $ids | ForEach-Object {
            foreach ($v in $_.Versions) { "$appId/$v" }
        }
 
    .OUTPUTS
        PSCustomObject[] with PackageId and Versions (string[], empty when the package is absent).
    #>

    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory)] [ValidateNotNull()] [object] $Feed,
        [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string[]] $PackageId
    )

    # Reachability and authorisation first, as their own question, so that an empty version list below
    # can only mean "absent". Throws on a feed that cannot be read - which is the honest outcome.
    $Feed.EnsureInitialized()

    foreach ($id in $PackageId) {
        if ([string]::IsNullOrWhiteSpace($id)) { continue }
        $versions = @($Feed.GetVersions($id))
        Write-Verbose "'$id': $($versions.Count) version(s) on feed '$($Feed.Name)'."
        [PSCustomObject]@{
            PackageId = $id
            Versions  = $versions
        }
    }
}