Public/Test-PCSecret.ps1

function Test-PCSecret {
    <#
    .SYNOPSIS
        Tests whether a secret exists in the store or environment.

    .PARAMETER Name
        Service name to check.

    .PARAMETER Property
        Specific property to check. Defaults to 'apiKey'.

    .OUTPUTS
        [bool] True if the secret exists.

    .EXAMPLE
        Test-PCSecret -Name 'openai'
        # Returns: $true

    .EXAMPLE
        if (Test-PCSecret 'brave-search') { ... }
    #>

    [CmdletBinding()]
    [OutputType([bool])]
    param(
        [Parameter(Mandatory, Position = 0)]
        [string]$Name,

        [Parameter()]
        [string]$Property = 'apiKey'
    )

    # Check env var
    $secrets = Read-PCSecretsFile
    $entry = $secrets[$Name]
    $envVarName = Resolve-PCEnvVarName -Name $Name -SecretEntry $entry

    if (Test-Path "env:$envVarName") {
        return $true
    }

    # Check file
    if ($entry -and $entry[$Property]) {
        return $true
    }

    return $false
}