agentleFS
vorlaxen-labsvorlaxen-labs/Agent-Skills/skills/libraries/bar-js/SKILL.md

bar-js

Skill6 starsChanged 3 months agoMITView on GitHub

Framework-agnostic TypeScript API response builder (@vorlaxen-labs/bar-js). Standardizes JSON envelopes with semantic presets, request tracing, pagination, cookies, hooks, and security headers. Use when building REST API responses, Express middleware, res.builder patterns, or consistent error/success shapes.

  • Reads credentials

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every response follows this shape:

    line 32

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

BaR (Builder a Response)

Package: @vorlaxen-labs/bar-js v2.0.0 · Zero runtime deps

Framework-agnostic response builder that replaces ad-hoc res.status().json() with a fluent, typed API enforcing a single response contract.


Critical Rules

  1. Register bar.handler() before route handlers — injects res.builder and req.bar.ctx.
  2. Always call .build() to dispatch — chaining alone does not send a response.
  3. Use semantic presets (.as.ok(), .as.created(), etc.) instead of raw status codes.
  4. Use .wrap(promise) for async routes — then call .build() or .message(). Do not call .as.ok(undefined) after wrap() — it overwrites resolved data with null.
  5. Set environment: 'production' in prod — masks internal error details in wrap().
  6. Never invent response fields — follow the envelope schema below.

Response Envelope

Every response follows this shape:

interface IResponse<T = unknown, M = unknown> {
  success: boolean;
  timestamp: string;       // ISO 8601 at build time
  message?: string;
  data: T | null;
  metadata: {
    request_id: string;
    server_time: string;
    status_code: number;
  } & M;
}
  • success is true for status 200–399 (unless .forceSuccess() overrides).
  • metadata.request_id is auto-generated or read from X-Request-Id / X-Correlation-Id / traceparent.

Quick Start

import express from 'express';
import { BarExpressAdapter } from '@vorlaxen-labs/bar-js';

const app = express();
const bar = new BarExpressAdapter({
  environment: process.env.NODE_ENV === 'production' ? 'production' : 'development',
  logger: console,
});

app.use(bar.handler());
app.use(express.json());

app.get('/api/users/:id', async (req, res) => {
  await res.builder.wrap(userService.findById(req.params.id));
  return res.builder.message('User retrieved').build();
});

Semantic Presets (.as.*)

MethodStatusDefault Message
ok(data?, message?)200"Success"
created(data?, message?)201"Resource created"
accepted(message?)202"Request accepted"
noContent()204""
badRequest(message?)400"Bad Request"
unauthorized(message?)401"Unauthorized access"
forbidden(message?)403"Access forbidden"
notFound(message?)404"Resource not found"
conflict(message?)409"Conflict detected"
unprocessable(message?)422"Unprocessable entity"
tooManyRequests(message?)429"Too many requests, please slow down"
internalServerError(message?)500"Internal server error"
serviceUnavailable(message?)503"Service temporarily unavailable"
gatewayTimeout(message?)504"Gateway timeout"

Common Patterns

Async with wrap

app.post('/api/users', async (req, res) => {
  await res.builder.wrap(userService.create(req.body));
  return res.builder.message('User created').status(201).build();
});

Pagination

return res.builder
  .as.ok(users)
  .paginate(total, page, limit)
  .build();

Conditional chaining

return res.builder
  .as.ok(data)
  .when(includeMeta, b => b.setMeta({ version: '2.0' }))
  .build();

Request tracing

const { request_id, start_time } = req.bar.ctx;
// request_id appears in every response metadata

Middleware Order

1. Trust proxy / CORS
2. bar.handler()          ← injects builder + context
3. express.json()
4. Route handlers
5. Not found middleware
6. Global exception filter

Adapter Options

OptionDefaultDescription
withDefaultHeadersenabledSecurity headers on every response
environmentundefined'production' hides internal errors in wrap()
includeStackundefinedStack traces in dev error messages
loggerundefinedLogger for adapter and builder events
hooksundefinedLifecycle hooks (before_build, after_build, etc.)

When NOT to Use BaR

  • GraphQL or gRPC exclusively
  • Streaming/SSE responses (BaR is JSON-focused)
  • API already has a mature, enforced response envelope that cannot change

Reference Documentation

TopicFile
Installation & setupreference/getting-started.md
Full method listingreference/api-reference.md
Envelope field detailsreference/response-schema.md
All .as.* presetsreference/semantic-presets.md
wrap(), transform(), when()reference/advanced-chaining.md
List endpointsreference/pagination.md
Request ID & correlationreference/request-tracing.md
Error handling & maskingreference/error-handling.md
Cookies & headersreference/cookies-headers.md
Lifecycle hooksreference/hooks.md
Security headersreference/security.md
Fastify / custom adaptersreference/adapters.md
Production patternsreference/recipes.md
TypeScript genericsreference/typescript.md

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.