feat: posts:settings command (patch a post's provider settings) - #13
feat: posts:settings command (patch a post's provider settings)#13giladresisi wants to merge 1 commit into
Conversation
Add `postiz posts:settings <id> --settings '<json>'` calling PUT /public/v1/posts/:id/settings to patch a post's provider-specific settings without recreating it. Modeled on the existing posts:status command. Settings are merged server-side (only passed keys change); only DRAFT/QUEUE posts can be updated. Also document that posts:list responses now include each post's current `settings` (returned as a JSON string). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Contribution-checker quality warning Heuristics that flagged:
If this is a genuine contribution, please add detail to your PR description and tighten the diff scope before reviewers look at it. |
📝 WalkthroughWalkthroughAdds a ChangesPost settings management
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant User
participant PostizCLI
participant PostizAPI
participant SettingsEndpoint
User->>PostizCLI: Run posts:settings with post id and JSON settings
PostizCLI->>PostizAPI: Parse and submit settings
PostizAPI->>SettingsEndpoint: PUT post settings
SettingsEndpoint-->>PostizAPI: Return update response
PostizAPI-->>PostizCLI: Return result
PostizCLI-->>User: Log success or error
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/commands/posts.ts (1)
222-228: 🗄️ Data Integrity & Integration | 🔵 Trivial | 💤 Low valueEnsure parsed JSON is a plain object.
JSON.parsewill successfully parse primitives (e.g.,'true'or'"string"') and arrays. Since the downstreamapi.updatePostSettingscontract expects aRecord<string, any>, consider validating that the parsed output is a plain object to gracefully reject invalid inputs before making the API request.💡 Proposed optional refactor
let settings: any; try { settings = JSON.parse(args.settings); + if (typeof settings !== 'object' || settings === null || Array.isArray(settings)) { + throw new Error('Settings must be a JSON object'); + } } catch (error: any) { console.error('❌ Failed to parse settings JSON:', error.message); process.exit(1); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/commands/posts.ts` around lines 222 - 228, Validate the result assigned to settings in the JSON parsing block before calling api.updatePostSettings, rejecting null, arrays, and non-object primitives so settings remains a plain object compatible with the Record<string, any> contract. Reuse the existing parse-error handling to report invalid input and exit without making the API request.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/commands/posts.ts`:
- Around line 222-228: Validate the result assigned to settings in the JSON
parsing block before calling api.updatePostSettings, rejecting null, arrays, and
non-object primitives so settings remains a plain object compatible with the
Record<string, any> contract. Reuse the existing parse-error handling to report
invalid input and exit without making the API request.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 81c5a71c-424b-4806-8ae2-5b60b347bb9d
📒 Files selected for processing (6)
CHANGELOG.mdREADME.mdSKILL.mdsrc/api.tssrc/commands/posts.tssrc/index.ts
What
Adds a
postiz posts:settings <id> --settings '<json>'CLI command that calls the new backend endpointPUT /public/v1/posts/:id/settingsto patch a post's provider-specific settings without recreating the post. Modeled exactly on the existingposts:statuscommand (same file structure, error handling,✅/❌output, yargs shape).src/api.ts—updatePostSettings(postId, settings)src/commands/posts.ts—updatePostSettingshandler (requiresid+--settings, parses the JSON string client-side before hitting the network,✅success /❌+ exit 1 on failure)src/index.ts—posts:settings <id>registrationSKILL.md,README.md,CHANGELOG.mdBehavior (enforced server-side, surfaced in help/docs)
400.__typeis added by the backend from the integration — don't include it (the backend overwrites it if you do).posts:listresponses now include each post's currentsettings(returned as a JSON string —JSON.parseit). Intended workflow:posts:list(read) →posts:settings(patch).Testing
Verified end-to-end against a local backend: happy path, JSON-parse guard (errors before any network call), missing
--settings(yargsdemandOption), bad post id (404via❌path), merge semantics (cumulative, non-destructive),__typeoverwrite, and published-post rejection (400, surfaced cleanly).pnpm buildpasses with no TS errors.Related PRs
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
posts:settingscommand for updating provider-specific settings on unpublished DRAFT and QUEUE posts.posts:listresponses now include each post’s current settings.Documentation