Add attachment deletion and scoped access control#44
Merged
Conversation
…pedStack Stack.deleteAttachment mirrors the logic that was only in the server's HTTP route: checks for referencing records, handles missing metadata records, hard-deletes _attachment@1 metadata, then deletes bytes. Uses contentFieldQuery capability flag for adapters that don't support content field filtering. ScopedStack.getAttachment translates the isAttachmentAccessible logic from the server route into the SDK layer: owner always allowed, otherwise checks for a readable referencing record, then falls back to checking uploader ownership of an unassociated _attachment@1 record. ScopedStack.deleteAttachment is owner-only, matching the requireOwner guard on the server's DELETE /attachments/:fileId route.
Replaces the generic Error thrown when an attachment is still referenced by one or more records. StackConflictError is a named, catchable error class analogous to HTTP 409, which is what the server route already returns for this case.
…ctError - Add getAttachment and deleteAttachment to the StackClient method list - Expand the Attachments section with deleteAttachment usage and a Stack vs ScopedStack breakdown for all three attachment methods - Add 409 / StackConflictError to the error responses table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds attachment deletion functionality to the Stack API with proper access control and reference validation. It also implements scoped access control for downloading attachments through the ScopedStack class.
Key Changes
StackPermissionErrorotherwiseStackClientinterface to include the newgetAttachment()anddeleteAttachment()methodsStackConflictErrorfor constraint violations (e.g. deleting a referenced attachment)Implementation Details
StackNotFoundErrorif attachment doesn't existStackConflictErrorif attachment is still referenced by recordshttps://claude.ai/code/session_01PrLzbXMVj16yzEH6SjJkhA