Skip to content

feat(docs-api): add snippet documentation management API and sanitization (#217) - #233

Open
jeffrey-graham wants to merge 1 commit into
SudiptaPaul-31:mainfrom
jeffrey-graham:feat/snippet-documentation-api-217
Open

jeffrey-graham wants to merge 1 commit into
SudiptaPaul-31:mainfrom
jeffrey-graham:feat/snippet-documentation-api-217

Conversation

@jeffrey-graham

@jeffrey-graham jeffrey-graham commented Nov 10, 2026 •

Copy link
Copy Markdown

Closes #217

Adds structured snippet documentation management (overview, usageInstructions, prerequisites, setupSteps, inputExample, outputExample, and notes) in lib/snippet-documentation-service.ts, exposes CRUD handlers at app/api/snippets/[id]/documentation/route.ts, and wires stored documentation into GET /api/snippets/[id].

Implementation details

  • Validation & sanitization (lib/snippet-documentation-service.ts): Rejects empty payloads, unknown fields, oversized text/list/example sections, and malformed JSON examples. Strips <script>, <iframe>, <object>, <embed>, <style>, inline on* event attributes, javascript:/vbscript:/data:text/html URIs, and disallowed control bytes before storage.
  • Repository & permission integration (app/api/snippets/[id]/documentation/route.ts): Extracts caller wallets via OwnershipMiddleware.extractWalletAddress (supporting both x-wallet-address and Bearer JWTs) and connects SnippetDocumentationService to SnippetRepository + permissions.service (canEdit / canView / isSharedWith) so missing DB snippets return 404, unauthorized writes return 401/403, and private/shared visibility rules apply on GET.
  • Snippet retrieval integration (app/api/snippets/[id]/route.ts): Attaches stored documentation on authorized GET /api/snippets/[id] responses (and supports explicit ?includeDocumentation=true empty-state opt-in without altering existing responses for undocumented snippets).

Local verification

  • ./node_modules/.bin/eslint "lib/snippet-documentation-service.ts" "app/api/snippets/[id]/documentation/route.ts" "app/api/snippets/[id]/route.ts" "lib/__tests__/snippet-documentation-service.test.ts" -> 0 errors, 0 warnings
  • ./node_modules/.bin/tsc --noEmit -> 0 errors in touched files
  • ./node_modules/.bin/jest --runInBand --runTestsByPath "lib/__tests__/snippet-documentation-service.test.ts" "app/api/snippets/[id]/route.test.ts" -> 2 suites passed (19/19 tests passed)

@vercel

vercel Bot commented Nov 10, 2026

Copy link
Copy Markdown

@jeffrey-graham is attempting to deploy a commit to the Sudipta 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@jeffrey-graham
jeffrey-graham force-pushed the feat/snippet-documentation-api-217 branch from fae5e4f to 8f9e68b Compare November 11, 2026 08:28

This branch has not been deployed

No deployments
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.

Add Snippet Documentation Management API

1 participant