@arkyn/server@arkyn/server is a comprehensive server-side utility library designed for building robust HTTP APIs. It provides standardized HTTP responses, validation utilities, form parsing, and debugging tools that integrate seamlessly with modern web frameworks like React Router, Remix, and Hono.@arkyn/server?@arkyn/server solves these challenges by providing a unified set of tools that ensure your server responses are predictable, well-structured, and easy to debug.Request and Response objectsbash
bun add @arkyn/server
@arkyn/server declares zod (>=4.4.3) and libphonenumber-js (>=1.13.7) as peer dependencies, so install them alongside it:bash
bun add zod libphonenumber-js
zod is required because SchemaValidator validates data against Zod schemas, and libphonenumber-js is required for phone number validation utilities such as validatePhone.BadRequest (400), Unauthorized (401), Forbidden (403), NotFound (404), Conflict (409), UnprocessableEntity (422), ServerError (500), NotImplemented (501), and BadGateway (502).ts
import { BadRequest } from "@arkyn/server/badRequest";import { NotFound } from "@arkyn/server/notFound";import { UnprocessableEntity } from "@arkyn/server/unprocessableEntity";// Throw errors with descriptive messagesthrow new NotFound("User not found");// Form validation errors with field-specific messagesthrow new UnprocessableEntity({message: "Validation failed",fieldErrors: { email: "Invalid email format" },fields: { email: "invalid-email" },});
Success (200), Created (201), NoContent (204), Updated (200), and Found (302).ts
import { Created } from "@arkyn/server/created";import { Success } from "@arkyn/server/success";import { NoContent } from "@arkyn/server/noContent";// Return created resourcereturn new Created("User created successfully", {id: "123",name: "John",}).toResponse();// Return datareturn new Success("Users retrieved", users).toJson();// No content responsereturn new NoContent("Resource deleted").toResponse();
ts
import { ApiService } from "@arkyn/server/apiService";import { DebugService } from "@arkyn/server/debugService";import { LogService } from "@arkyn/server/logService";// Configure API clientconst api = new ApiService({baseUrl: "https://api.example.com",baseHeaders: { "Content-Type": "application/json" },enableDebug: true,});const users = await api.get("/users", { urlParams: { page: "1" } });// Configure debug service for accurate caller detectionDebugService.setIgnoreFile("httpAdapter.ts");// Configure log service for centralized loggingLogService.setConfig({trafficSourceId: "my-app",serviceToken: "auth-token",});
ts
import { SchemaValidator } from "@arkyn/server/schemaValidator";import { formParse } from "@arkyn/server/formParse";import { getScopedParams } from "@arkyn/server/getScopedParams";import { z } from "zod";// Schema validation with multiple strategiesconst schema = z.object({ name: z.string().min(1), email: z.string().email() });const validator = new SchemaValidator(schema);validator.isValid(data); // Boolean checkvalidator.validate(data); // Throws ServerErrorvalidator.formValidate(data); // Throws UnprocessableEntity// Extract scoped query parametersconst filters = getScopedParams(request, "filter");// ?filter:status=active&filter:type=user → { status: "active", type: "user" }
ts
import { validateEmail } from "@arkyn/server/validateEmail";import { validateCpf } from "@arkyn/server/validateCpf";import { validateCnpj } from "@arkyn/server/validateCnpj";// Email validation with DNS verificationconst isValidEmail = await validateEmail("user@example.com");// Document validationconst isValidCpf = await validateCpf("123.456.789-09");const isValidCnpj = await validateCnpj("12.345.678/0001-90");
@arkyn/server follows these core principles:toResponse() for standard responses or toJson() for Response.json() alternative@arkyn/server ships its own AGENTS.md file inside the published package (available at node_modules/@arkyn/server/AGENTS.md after install), a reference written specifically for AI coding assistants like Claude Code, Cursor, or Copilot. It documents every response class, service, utility, and validation function's exact signature and behavior, so your assistant doesn't need to read the source to use the library correctly.@arkyn/cli once in your project to link it in:bash
npx @arkyn/cli init --agents
AGENTS.md pointing at @arkyn/server's bundled docs (and those of any other installed @arkyn/* package). Rerun it whenever you add or remove Arkyn packages. See the @arkyn/cli introduction for details.