Modules/businessdev.ALbuild.Containers/Private/Resolve-BcArtifactStorage.ps1

function Resolve-BcArtifactStorage {
    <#
    .SYNOPSIS
        Resolves the storage account host, base URL and indexes URL for BC artifacts.
    .DESCRIPTION
        Internal helper. Business Central artifacts are published to Azure Blob Storage and served
        through Azure Front Door:
          - released builds: bcartifacts-exdbf9fwegejdqak.b02.azurefd.net
          - insider builds: bcinsider-fvh2ekdjecfjd6gk.b02.azurefd.net
        Direct *.blob.core.windows.net access was retired by Microsoft (it now returns HTTP 403,
        "not authorized by network security perimeter"), so the well-known short names map onto the
        Front Door hosts above. Each is organised as /{type}/{version}/{country}, with a
        /{type}/indexes/ container that lists countries (countries.json), platform availability
        (platform.json) and per-country version metadata ({country}.json).
    #>

    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory)]
        [ValidateSet('OnPrem', 'Sandbox')]
        [string] $Type,

        [switch] $Insider,

        [string] $StorageAccount
    )

    if ([string]::IsNullOrWhiteSpace($StorageAccount)) {
        $StorageAccount = if ($Insider) { 'bcinsider' } else { 'bcartifacts' }
    }

    # Determine insider intent from the short name (before it is mapped to a Front Door host).
    $isInsider = $StorageAccount -like 'bcinsider*'

    # Map the well-known short names onto their Azure Front Door hosts. Microsoft retired direct
    # *.blob.core.windows.net access (HTTP 403, "not authorized by network security perimeter").
    $frontDoorHosts = @{
        'bcartifacts' = 'bcartifacts-exdbf9fwegejdqak.b02.azurefd.net'
        'bcinsider'   = 'bcinsider-fvh2ekdjecfjd6gk.b02.azurefd.net'
    }
    if ($frontDoorHosts.ContainsKey($StorageAccount)) {
        $StorageAccount = $frontDoorHosts[$StorageAccount]
    }
    elseif (-not $StorageAccount.Contains('.')) {
        $StorageAccount = "$StorageAccount.blob.core.windows.net"
    }

    $typeLower = $Type.ToLowerInvariant()
    $baseUrl   = "https://$StorageAccount/$typeLower/"

    return [PSCustomObject]@{
        StorageAccount = $StorageAccount
        BaseUrl        = $baseUrl
        IndexesUrl     = "$($baseUrl)indexes"
        IsInsider      = $isInsider
    }
}