Skip to content

feat: add slug helper, protocol config endpoint, request ID middleware, and API error formatter#17

Merged
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
OpenSourceCOntr:feature/issues-11-14-15-16-utils-and-middleware
Mar 25, 2026
Merged

feat: add slug helper, protocol config endpoint, request ID middleware, and API error formatter#17
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
OpenSourceCOntr:feature/issues-11-14-15-16-utils-and-middleware

Conversation

@Uchechukwu-Ekezie

Copy link
Copy Markdown
Contributor

Summary

  • Added a reusable creator slug generation helper (src/utils/slug.utils.ts) that normalizes names/handles into stable, URL-safe slugs with optional numeric suffix for uniqueness
  • Added a public protocol config endpoint at GET /api/v1/config (src/modules/config/) returning lightweight bootstrap data (environment, API version, network, feature flags, display settings) without exposing sensitive information
  • Added request ID middleware (src/middlewares/request-id.middleware.ts) that assigns a UUID v4 to every request (or forwards the client X-Request-ID header), attaches it to req.requestId, and returns it in the response header for tracing
  • Added a shared API error formatter (src/utils/api-response.utils.ts) with a consistent response shape ({ success, error: { code, message, details? } }) and typed error codes so frontend clients can parse errors predictably

Files changed

  • src/utils/slug.utils.ts (new) - Slug generation helpers
  • src/modules/config/config.controllers.ts (new) - Protocol config controller
  • src/modules/config/config.routes.ts (new) - Protocol config route
  • src/middlewares/request-id.middleware.ts (new) - Request ID middleware
  • src/utils/api-response.utils.ts (new) - API response formatters
  • src/app.ts (modified) - Register request ID middleware
  • src/modules/index.ts (modified) - Register config route

Test plan

  • generateSlug("John Doe") returns "john-doe"
  • generateSlug is deterministic (same input, same output)
  • GET /api/v1/config returns 200 with expected shape
  • Config endpoint does not expose secrets or creator data
  • Every response includes X-Request-ID header
  • Client-sent X-Request-ID is forwarded through
  • sendError() produces { success: false, error: { code, message } }
  • sendSuccess() produces { success: true, data }
  • Existing routes continue to work without changes

Closes #11
Closes #14
Closes #15
Closes #16

…e, and API error formatter

Issue accesslayerorg#11 - Creator slug generation helper (src/utils/slug.utils.ts):
- generateSlug() normalizes input to URL-safe lowercase slugs
- Handles spaces, special characters, consecutive hyphens
- Deterministic: same input always produces same output
- generateSlugWithSuffix() appends numeric disambiguator for uniqueness

Issue accesslayerorg#14 - Public protocol config endpoint (src/modules/config/):
- GET /api/v1/config returns lightweight bootstrap payload
- Response includes environment, API version, network, feature flags,
  and display settings
- Safe for unauthenticated use, no sensitive data exposed
- Documented response shape in TypeScript interface

Issue accesslayerorg#15 - Request ID middleware (src/middlewares/request-id.middleware.ts):
- Generates UUID v4 for each request or forwards client X-Request-ID header
- Attaches requestId to req object for downstream logging
- Returns X-Request-ID in response header for client correlation
- Registered early in middleware chain (before CORS/helmet)

Issue accesslayerorg#16 - Consistent API error formatter (src/utils/api-response.utils.ts):
- Standard error shape: { success, error: { code, message, details? } }
- Standard success shape: { success, data, message? }
- Typed error codes: VALIDATION_ERROR, NOT_FOUND, UNAUTHORIZED, etc.
- Convenience helpers: sendError, sendSuccess, sendValidationError,
  sendNotFound, sendUnauthorized, sendForbidden, sendConflict

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@drips-wave

drips-wave Bot commented Mar 25, 2026

Copy link
Copy Markdown

@Uchechukwu-Ekezie Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Chucks1093 Chucks1093 merged commit 8b4b54e into accesslayerorg:main Mar 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants