Skip to content

Commit

Permalink
Merge pull request #79 from StartAutomating/PSA-Updates
Browse files Browse the repository at this point in the history
PSA 0.1.5
  • Loading branch information
StartAutomating committed Oct 4, 2023
2 parents 3fcf2b1 + c739350 commit 587709f
Show file tree
Hide file tree
Showing 635 changed files with 22,129 additions and 787 deletions.
46 changes: 43 additions & 3 deletions Build/PSA.Build.ps1 → Build/PSA.AtProtocol.Build.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Push to the parent directory of this script
Push-Location ($PSScriptRoot | Split-Path)

# Update remote submodules
git submodule update --remote | Out-Host

# The AtProtocol is a submodule of this repo, located within 'atproto'
$atRoot = Join-Path $pwd atproto
# Within that are lexicons (these describe the types in At Protocol in JSON)
$atLexicon = Join-Path $atRoot lexicons
# Get all of the json files beneath this directory.
$lexiconJson = Get-ChildItem -Path $atLexicon -Recurse -file -Filter *.json

$atFunctionNames = @()
Expand Down Expand Up @@ -308,11 +316,13 @@ $(@(foreach ($kv in $decorateProperty.GetEnumerator()) {
}
{$InvokeAtSplat["PSTypeName"] = $NamespaceID}
{$parameterAliases = [Ordered]@{}}
{$DataboundParameters = @()}
if ($lexicon.defs.main.output.encoding -and ($lexicon.defs.main.output.encoding -ne 'application/json')) {
{$AsByte = $true}
} else {
{$AsByte = $false}
}

""
if ($AtParams.Count) {
{
Expand All @@ -323,6 +333,7 @@ if ($AtParams.Count) {
foreach ($attr in $paramMetadata.Attributes) {
if ($attr -is [ComponentModel.DefaultBindingPropertyAttribute]) {
$parameterAliases[$paramMetadata.Name] = $attr.Name
$DataboundParameters += $paramMetadata.Name
continue nextParameter
}
}
Expand All @@ -343,7 +354,13 @@ $parameterQueue.Enqueue([Ordered]@{} + $PSBoundParameters)
$atEndBlock = {
$parameterQueue.ToArray() |
Invoke-AtProtocol -Method $httpMethod -NamespaceID $NamespaceID -Parameter {
$_
$RestParameters =[Ordered]@{}
foreach ($parameterName in $DataboundParameters) {
if ($null -ne $_.($ParameterName)) {
$RestParameters[$parameterName] = $_.($ParameterName)
}
}
$RestParameters
} -ParameterAlias $parameterAliases @InvokeAtSplat -ContentType $(
if ($ContentType) {
$ContentType
Expand All @@ -354,7 +371,13 @@ $parameterQueue.Enqueue([Ordered]@{} + $PSBoundParameters)
$_
} -Cache:$(
if ($cache) {$cache} else { $false }
)
) -Raw:$Raw -Authorization {
if ($_.Authorization) {
$_.Authorization
} else {
$null
}
}
}


Expand Down Expand Up @@ -389,7 +412,7 @@ $parameterQueue.Enqueue([Ordered]@{} + $PSBoundParameters)
# as well as the whole identifier
"$($lexiconIDParts[0..$($lexiconIDParts.Count - 1)] -join '.')"
)

if (-not $AtParams["Cache"] -and $httpMethod -eq 'GET') {
$AtParams["Cache"] = [Ordered]@{
Name = "Cache"
Expand All @@ -398,6 +421,23 @@ $parameterQueue.Enqueue([Ordered]@{} + $PSBoundParameters)
}
}

if (-not $AtParams["Authorization"]) {
$AtParams["Authorization"] = [Ordered]@{
Name = "Authorization"
Alias = 'Authentication','AppPassword','Credential','PSCredential'
Help = "The authorization.", "This can be a JWT that accesses the at protocol or a credential.","If this is provided as a credential the username is a handle or email and the password is the app password."
ParameterType = [switch]
}
}

if (-not $AtParams["Raw"]) {
$AtParams["Raw"] = [Ordered]@{
Name = "Raw"
Help = "If set, will return raw results. This will ignore -Property, -DecorateProperty, -ExpandProperty, and -PSTypeName."
ParameterType = [switch]
}
}

$newPipeScriptSplat = [Ordered]@{
FunctionName=$atFunctionName
Alias= $atFunctionAliases
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## PSA 0.1.5:

* Fixing Send-AtProto for Webcards/Images (#77)
* Invoke-AtProto
* Now supports -Raw (#75)
* Not passing down binary data (#72)
* All AtProtocol Commands:
* Now supports -Raw (#74)
* Supports -Authorization (#71)
* Simplifying PSA Module Profiles (#78)

---

# PowerShell Announcements (with AtProtocol) [0.1.4]

PSA is:

* A Cross-Platform PowerShell Module For Making Announcements
* A Beautiful BlueSky Client for the CLI
* An (Almost) Perfect PowerShell Wrapper for the At Protocol
* A GitHub Action to Automate Announcements


16 changes: 12 additions & 4 deletions Commands/Invoke-AtProto.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ function Invoke-AtProto
# If set, will cache results from a request. Only HTTP GET results will be cached.
[Parameter(ValueFromPipelineByPropertyName)]
[switch]
$Cache
$Cache,

# If set, will return raw results.
# This will ignore -Property, -DecorateProperty, -ExpandProperty, and -PSTypeName.
[Parameter(ValueFromPipelineByPropertyName)]
[switch]
$Raw
)

begin {
Expand Down Expand Up @@ -248,9 +254,10 @@ function Invoke-AtProto
foreach ($propKeyValue in $Property.GetEnumerator()) {
if ($propKeyValue.Value -as [ScriptBlock[]]) {
[PSScriptProperty]::new.Invoke(@($propKeyValue.Key) + $propKeyValue.Value)
} else {
}
elseif ($propKeyValue.Value -isnot [byte[]]) {
[PSNoteProperty]::new($propKeyValue.Key, $propKeyValue.Value)
}
}
}
} else {
$property.psobject.properties
Expand Down Expand Up @@ -318,7 +325,7 @@ function Invoke-AtProto
if ($AsByte -and $in.Content) {
$in.Content
}
elseif ($ExpandProperty) {
elseif ($ExpandProperty -and -not $Raw) {
if ($in.$ExpandProperty) {
return $in.$ExpandProperty
}
Expand All @@ -343,6 +350,7 @@ function Invoke-AtProto
)
process {
# One more step of the pipeline will unroll each of the values.
if ($Raw) { return $_ }

if ($cache -and $script:InvokeAtProtoCache[$toSplat.uri]) {
return $script:InvokeAtProtoCache[$toSplat.uri]
Expand Down
50 changes: 48 additions & 2 deletions Commands/Lexicons/app/bsky/actor/Get-BskyActorDefinition.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function Get-BskyActorDefinition {
[Alias('bsky.actor.defs','app.bsky.actor.defs','app.bsky.actor.defs#profileViewBasic','app.bsky.actor.defs#profileView','app.bsky.actor.defs#profileViewDetailed','app.bsky.actor.defs#viewerState','app.bsky.actor.defs#preferences','app.bsky.actor.defs#adultContentPref','app.bsky.actor.defs#contentLabelPref','app.bsky.actor.defs#savedFeedsPref','app.bsky.actor.defs#personalDetailsPref')]
[Alias('bsky.actor.defs','app.bsky.actor.defs','app.bsky.actor.defs#profileViewBasic','app.bsky.actor.defs#profileView','app.bsky.actor.defs#profileViewDetailed','app.bsky.actor.defs#viewerState','app.bsky.actor.defs#preferences','app.bsky.actor.defs#adultContentPref','app.bsky.actor.defs#contentLabelPref','app.bsky.actor.defs#savedFeedsPref','app.bsky.actor.defs#personalDetailsPref','app.bsky.actor.defs#feedViewPref','app.bsky.actor.defs#threadViewPref')]
param(
)
$lexiconText = @'
Expand Down Expand Up @@ -103,7 +103,9 @@ $lexiconText = @'
"#adultContentPref",
"#contentLabelPref",
"#savedFeedsPref",
"#personalDetailsPref"
"#personalDetailsPref",
"#feedViewPref",
"#threadViewPref"
]
}
},
Expand Down Expand Up @@ -154,6 +156,50 @@ $lexiconText = @'
"description": "The birth date of the owner of the account."
}
}
},
"feedViewPref": {
"type": "object",
"required": ["feed"],
"properties": {
"feed": {
"type": "string",
"description": "The URI of the feed, or an identifier which describes the feed."
},
"hideReplies": {
"type": "boolean",
"description": "Hide replies in the feed."
},
"hideRepliesByUnfollowed": {
"type": "boolean",
"description": "Hide replies in the feed if they are not by followed users."
},
"hideRepliesByLikeCount": {
"type": "integer",
"description": "Hide replies in the feed if they do not have this number of likes."
},
"hideReposts": {
"type": "boolean",
"description": "Hide reposts in the feed."
},
"hideQuotePosts": {
"type": "boolean",
"description": "Hide quote posts in the feed."
}
}
},
"threadViewPref": {
"type": "object",
"properties": {
"sort": {
"type": "string",
"description": "Sorting mode.",
"knownValues": ["oldest", "newest", "most-likes", "random"]
},
"prioritizeFollowedUsers": {
"type": "boolean",
"description": "Show followed users at the top of all replies."
}
}
}
}
}
Expand Down
26 changes: 23 additions & 3 deletions Commands/Lexicons/app/bsky/actor/Get-BskyActorPreferences.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ function Get-BskyActorPreferences {
param(
# If set, will cache results for performance.
[Management.Automation.SwitchParameter]
$Cache
$Cache,
# The authorization. This can be a JWT that accesses the at protocol or a credential. If this is provided as a credential the username is a handle or email and the password is the app password.
[Alias('Authentication','AppPassword','Credential','PSCredential')]
[Management.Automation.SwitchParameter]
$Authorization,
# If set, will return raw results. This will ignore -Property, -DecorateProperty, -ExpandProperty, and -PSTypeName.
[Management.Automation.SwitchParameter]
$Raw
)

begin {
Expand All @@ -24,6 +31,7 @@ $InvokeAtSplat.DecorateProperty = [Ordered]@{
}
$InvokeAtSplat["PSTypeName"] = $NamespaceID
$parameterAliases = [Ordered]@{}
$DataboundParameters = @()
$AsByte = $false


Expand All @@ -39,7 +47,13 @@ end {

$parameterQueue.ToArray() |
Invoke-AtProtocol -Method $httpMethod -NamespaceID $NamespaceID -Parameter {
$_
$RestParameters =[Ordered]@{}
foreach ($parameterName in $DataboundParameters) {
if ($null -ne $_.($ParameterName)) {
$RestParameters[$parameterName] = $_.($ParameterName)
}
}
$RestParameters
} -ParameterAlias $parameterAliases @InvokeAtSplat -ContentType $(
if ($ContentType) {
$ContentType
Expand All @@ -50,7 +64,13 @@ end {
$_
} -Cache:$(
if ($cache) {$cache} else { $false }
)
) -Raw:$Raw -Authorization {
if ($_.Authorization) {
$_.Authorization
} else {
$null
}
}

}
}
Expand Down
27 changes: 24 additions & 3 deletions Commands/Lexicons/app/bsky/actor/Get-BskyActorProfile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ This can be either a handle (e.g. @AtProto.com) or a Decentralized Identifier (.
$Actor,
# If set, will cache results for performance.
[Management.Automation.SwitchParameter]
$Cache
$Cache,
# The authorization. This can be a JWT that accesses the at protocol or a credential. If this is provided as a credential the username is a handle or email and the password is the app password.
[Alias('Authentication','AppPassword','Credential','PSCredential')]
[Management.Automation.SwitchParameter]
$Authorization,
# If set, will return raw results. This will ignore -Property, -DecorateProperty, -ExpandProperty, and -PSTypeName.
[Management.Automation.SwitchParameter]
$Raw
)

begin {
Expand All @@ -30,6 +37,7 @@ $httpMethod = 'GET'
$InvokeAtSplat = [Ordered]@{Method=$httpMethod}
$InvokeAtSplat["PSTypeName"] = $NamespaceID
$parameterAliases = [Ordered]@{}
$DataboundParameters = @()
$AsByte = $false


Expand All @@ -40,6 +48,7 @@ $AsByte = $false
foreach ($attr in $paramMetadata.Attributes) {
if ($attr -is [ComponentModel.DefaultBindingPropertyAttribute]) {
$parameterAliases[$paramMetadata.Name] = $attr.Name
$DataboundParameters += $paramMetadata.Name
continue nextParameter
}
}
Expand All @@ -59,7 +68,13 @@ end {

$parameterQueue.ToArray() |
Invoke-AtProtocol -Method $httpMethod -NamespaceID $NamespaceID -Parameter {
$_
$RestParameters =[Ordered]@{}
foreach ($parameterName in $DataboundParameters) {
if ($null -ne $_.($ParameterName)) {
$RestParameters[$parameterName] = $_.($ParameterName)
}
}
$RestParameters
} -ParameterAlias $parameterAliases @InvokeAtSplat -ContentType $(
if ($ContentType) {
$ContentType
Expand All @@ -70,7 +85,13 @@ end {
$_
} -Cache:$(
if ($cache) {$cache} else { $false }
)
) -Raw:$Raw -Authorization {
if ($_.Authorization) {
$_.Authorization
} else {
$null
}
}

}
}
Expand Down
Loading

0 comments on commit 587709f

Please sign in to comment.