Skip to content

refactor(admin): extract parsePropsParam helper for props query param#254

Open
JonasJesus42 wants to merge 2 commits into
mainfrom
render-props-parsing-refactor
Open

refactor(admin): extract parsePropsParam helper for props query param#254
JonasJesus42 wants to merge 2 commits into
mainfrom
render-props-parsing-refactor

Conversation

@JonasJesus42

@JonasJesus42 JonasJesus42 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Replaces the nested try/catch props-decoding in src/admin/render.ts with a flat, reusable parsePropsParam helper (src/admin/propsParam.ts) that tries each encoding strategy — plain encodeURIComponent(JSON) and base64 btoa(encodeURIComponent(JSON)) — in order and returns null on total failure, so render.ts now logs a warning instead of silently rendering with {}. The helper also adds a typeof === "object" guard that rejects valid-JSON-but-not-object inputs. The invoke.ts GET branch now reuses the same helper, unifying both admin endpoints and adding the previously-missing base64 fallback to /deco/invoke. Verified with npm run typecheck and npm run build.

🤖 Generated with Claude Code


Summary by cubic

Extracted a reusable props parser for admin query params that unifies decoding in render and invoke, adds base64 support to /deco/invoke, and only accepts plain object props.

  • Refactors
    • Added parsePropsParam in src/admin/propsParam.ts that tries URI-encoded JSON then base64(URI-encoded JSON), uses an internal tryOrNull, returns null on failure, and accepts only plain objects (rejects arrays/primitives).
    • Updated render.ts to use the helper and warn on parse failure instead of defaulting to {}.
    • Updated invoke.ts GET branch to reuse the helper and gain the base64 fallback.

Written for commit 5411dd2. Summary will update on new commits.

Review in cubic

Replace the nested try/catch decoding in render.ts with a flat, testable
parsePropsParam helper that tries each encoding strategy in order and
returns null on failure (so callers can react instead of silently getting
{}). Unify invoke.ts GET decoding on the same helper, which also adds the
previously-missing base64 fallback to /deco/invoke.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@JonasJesus42 JonasJesus42 requested a review from a team June 17, 2026 17:43
Move the loop's empty catch into a named tryOrNull helper whose sole
documented job is "try or return null", and tighten the guard to reject
arrays (typeof [] is "object") so only plain objects are accepted as props.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant