src/Private/Get-OpteraSkuPriceList.ps1
|
function Get-OpteraSkuPriceList { <# .SYNOPSIS Loads the SKU -> friendly-name + monthly-list-price map into a case-insensitive hashtable. .DESCRIPTION Reads the bundled src/Data/sku-pricelist.json unless an override path is supplied. Keys are lower-cased SKU GUIDs; values are PSCustomObjects with PartNumber, Name, MonthlyListUsd. #> [CmdletBinding()] param( [string] $PriceListPath ) if (-not $PriceListPath) { # $script:OpteraLicenseReclaimDataRoot is set by the module loader; fall back for dot-sourced tests. $root = if (Get-Variable -Name OpteraLicenseReclaimDataRoot -Scope Script -ErrorAction SilentlyContinue) { $script:OpteraLicenseReclaimDataRoot } else { Join-Path (Split-Path $PSScriptRoot -Parent) 'Data' } $PriceListPath = Join-Path $root 'sku-pricelist.json' } if (-not (Test-Path -LiteralPath $PriceListPath)) { throw "Price list not found: $PriceListPath" } $raw = Get-Content -LiteralPath $PriceListPath -Raw | ConvertFrom-Json $skuNode = if ($raw.PSObject.Properties.Name -contains 'skus') { $raw.skus } else { $raw } $map = @{} foreach ($prop in $skuNode.PSObject.Properties) { if ($prop.Name -like '_*') { continue } # skip _comment / _source metadata keys $entry = $prop.Value $map[$prop.Name.ToLowerInvariant()] = [pscustomobject]@{ SkuId = $prop.Name PartNumber = $entry.partNumber Name = $entry.name MonthlyListUsd = [double] $entry.monthlyListUsd } } return $map } |