{"_id":"@adhix11/mock-api-kit","_rev":"2-87c62e82b6216d44249cc82e3d53e92a","name":"@adhix11/mock-api-kit","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@adhix11/mock-api-kit","version":"1.0.0","keywords":["mock","api","server","rest","fake","development","testing","frontend","backend","json-server","openapi","crud","mock-server","mock-api"],"author":{"name":"adhix11"},"license":"MIT","_id":"@adhix11/mock-api-kit@1.0.0","maintainers":[{"name":"adhix11","email":"adhix11@gmail.com"}],"homepage":"https://github.com/adhix11/mock-api-kit#readme","bugs":{"url":"https://github.com/adhix11/mock-api-kit/issues"},"bin":{"mock-api-kit":"dist/cli.js"},"dist":{"shasum":"f96175e3da15249e249efa12bd1eca225026f671","tarball":"https://registry.npmjs.org/@adhix11/mock-api-kit/-/mock-api-kit-1.0.0.tgz","fileCount":11,"integrity":"sha512-d6qZhfdtivpndSkHwiHpaBYyOuGazsovtME6BtIV47s8m8h91LUT9+t0nlsLlxnPdNd+khnbcBbVGRqpSp9qVQ==","signatures":[{"sig":"MEUCIEIUmzYHmcO/g9/aqTY9M34REJKJV0NsSaBlAqlDBUh2AiEAsWlncCVW79z6r99ciw8A24MatSpduj2/5vc0plrZYmU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":530952},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=18.0.0"},"exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"scripts":{"dev":"tsup --watch","test":"vitest run","build":"tsup","test:watch":"vitest","prepublishOnly":"npm run build"},"_npmUser":{"name":"adhix11","email":"adhix11@gmail.com"},"repository":{"url":"git+https://github.com/adhix11/mock-api-kit.git","type":"git"},"_npmVersion":"11.6.2","description":"Local-first mock API server for JavaScript/TypeScript development. Create REST mock APIs from JSON config, OpenAPI specs, or auto-generated fake data.","directories":{},"_nodeVersion":"22.19.0","dependencies":{"cors":"^2.8.5","yaml":"^2.6.0","multer":"^1.4.5-lts.1","express":"^4.21.0","commander":"^12.0.0","fast-glob":"^3.3.0","picocolors":"^1.1.0","@faker-js/faker":"^9.0.0"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","vitest":"^2.0.0","typescript":"^5.6.0","@types/cors":"^2.8.17","@types/node":"^22.0.0","@types/multer":"^1.4.12","@types/express":"^4.17.21"},"_npmOperationalInternal":{"tmp":"tmp/mock-api-kit_1.0.0_1782728337705_0.6687562590437313","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@adhix11/mock-api-kit","version":"1.1.0","description":"Local-first mock API server for JavaScript/TypeScript development. Create REST mock APIs from JSON config, OpenAPI specs, or auto-generated fake data.","keywords":["mock","api","server","rest","fake","development","testing","frontend","backend","json-server","openapi","crud","mock-server","mock-api"],"author":{"name":"adhix11"},"license":"MIT","type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"bin":{"mock-api-kit":"dist/cli.js"},"scripts":{"build":"tsup","dev":"tsup --watch","test":"vitest run","test:watch":"vitest","prepublishOnly":"npm run build"},"dependencies":{"@faker-js/faker":"^9.0.0","commander":"^12.0.0","cors":"^2.8.5","express":"^4.21.0","fast-glob":"^3.3.0","multer":"^1.4.5-lts.1","picocolors":"^1.1.0","yaml":"^2.6.0"},"devDependencies":{"@types/cors":"^2.8.17","@types/express":"^4.17.21","@types/multer":"^1.4.12","@types/node":"^22.0.0","tsup":"^8.0.0","typescript":"^5.6.0","vitest":"^2.0.0"},"engines":{"node":">=18.0.0"},"repository":{"type":"git","url":"git+https://github.com/adhix11/mock-api-kit.git"},"_id":"@adhix11/mock-api-kit@1.1.0","bugs":{"url":"https://github.com/adhix11/mock-api-kit/issues"},"homepage":"https://github.com/adhix11/mock-api-kit#readme","_nodeVersion":"22.19.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-SKxFln4D5yLXfXCNBwNLADzEavkrO8ddzLYCirvcWdBDbYHsKMrc4Sp15yldW59iqAJhPEtoY1omogF5wYmybA==","shasum":"bc61609911082b046bd8e840829723f3b7934322","tarball":"https://registry.npmjs.org/@adhix11/mock-api-kit/-/mock-api-kit-1.1.0.tgz","fileCount":11,"unpackedSize":536664,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIHs+OpfjRz4843rb3n386RCsF3Z6XbxhpkUnJyH45OrYAiEA4nAYzvDGMBkbu1LgGNqAyoAkmaiM54YgWUHZwdEBtjM="}]},"_npmUser":{"name":"adhix11","email":"adhix11@gmail.com"},"directories":{},"maintainers":[{"name":"adhix11","email":"adhix11@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/mock-api-kit_1.1.0_1782728696966_0.2994036360389405"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-29T10:18:57.568Z","modified":"2026-06-29T10:24:57.170Z","1.0.0":"2026-06-29T10:18:57.873Z","1.1.0":"2026-06-29T10:24:57.089Z"},"bugs":{"url":"https://github.com/adhix11/mock-api-kit/issues"},"author":{"name":"adhix11"},"license":"MIT","homepage":"https://github.com/adhix11/mock-api-kit#readme","keywords":["mock","api","server","rest","fake","development","testing","frontend","backend","json-server","openapi","crud","mock-server","mock-api"],"repository":{"type":"git","url":"git+https://github.com/adhix11/mock-api-kit.git"},"description":"Local-first mock API server for JavaScript/TypeScript development. Create REST mock APIs from JSON config, OpenAPI specs, or auto-generated fake data.","maintainers":[{"name":"adhix11","email":"adhix11@gmail.com"}],"readme":"# @adhix11/mock-api-kit\n\n> **Local-first mock API server for JavaScript and TypeScript development.**  \n> Start a mock REST API in seconds from JSON config, OpenAPI specs, or auto-generated fake data.  \n> No cloud, no external APIs, no telemetry.\n\n[![npm version](https://img.shields.io/npm/v/@adhix11/mock-api-kit.svg)](https://www.npmjs.com/package/@adhix11/mock-api-kit)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)\n\n---\n\n## Why?\n\nFrontend is ready but backend is not? API is down, unstable, or not yet built?\n\n```bash\nnpx @adhix11/mock-api-kit start\n```\n\nNow your frontend can call `http://localhost:4000/users`, `http://localhost:4000/incidents`, etc — instantly, offline, with zero setup.\n\n| Developer Pain | How mock-api-kit Helps |\n|---|---|\n| Backend not ready | Start mock API instantly |\n| API returns empty data | Generate fake records |\n| Need demo data | Seed mock data from config |\n| Need error scenarios | Simulate 401, 403, 500 |\n| Need slow API | Add latency simulation |\n| Need pagination | Built-in page/limit support |\n| Need CRUD testing | Auto-create GET/POST/PUT/PATCH/DELETE |\n| Need exact response shape | Custom route templates |\n| Need offline development | Runs fully local |\n\n---\n\n## Quick Start\n\n### 1. Initialize\n\n```bash\nnpx @adhix11/mock-api-kit init\n```\n\nCreates `mock-api.config.json` and `mock-data/` with sample data.\n\n### 2. Start\n\n```bash\nnpx @adhix11/mock-api-kit start\n```\n\nOutput:\n\n```\n⚡ Mock API Kit running at http://localhost:4000\n   Dashboard: http://localhost:4000/__mock\n   Routes: 15 endpoints registered\n```\n\n### 3. Use\n\n```js\n// Your frontend code\nconst users = await fetch(\"http://localhost:4000/users\").then(r => r.json());\nconst user = await fetch(\"http://localhost:4000/users/1\").then(r => r.json());\n\nawait fetch(\"http://localhost:4000/users\", {\n  method: \"POST\",\n  headers: { \"Content-Type\": \"application/json\" },\n  body: JSON.stringify({ name: \"Test\", email: \"test@example.com\" })\n});\n```\n\n---\n\n## Installation\n\n```bash\n# Use with npx (no install needed)\nnpx @adhix11/mock-api-kit start\n\n# Or install as dev dependency\nnpm install -D @adhix11/mock-api-kit\n```\n\n---\n\n## CLI Commands\n\n| Command | Description |\n|---|---|\n| `mock-api-kit start` | Start the mock API server |\n| `mock-api-kit init` | Scaffold config and sample data |\n| `mock-api-kit create <resource>` | Add a record with custom fields (with upsert) |\n| `mock-api-kit generate <resource>` | Generate fake data for a resource |\n| `mock-api-kit routes` | List all configured routes |\n| `mock-api-kit report` | Generate configuration report |\n\n### Start Options\n\n```bash\nmock-api-kit start [options]\n\n  -p, --port <port>           Server port (default: 4000)\n  -l, --latency <ms>          Global response latency in ms\n  -c, --config <path>         Path to config file\n  -s, --spec <path>           Path to local OpenAPI 3.x spec\n  --force-error <status>      Force all requests to return this error\n```\n\n### Create Options\n\nAdd records to your resource files easily from the command line:\n\n```bash\n# Add a new user (automatically assigns ID)\nmock-api-kit create users name=\"Arun Kumar\" email=\"arun@example.com\" role=\"admin\"\n\n# Upsert (update/merge) an existing user instead of creating a duplicate\n# (If record with ID exists, it merges fields leaving other fields intact)\nmock-api-kit create users id=1 status=\"active\"\n\n# Add multiple records via inline JSON array\nmock-api-kit create users --json '[{\"id\": 2, \"name\": \"Priya\"}, {\"id\": 3, \"name\": \"Rahul\"}]'\n```\n\n### Generate Options\n\nGenerate multiple fake data records in seconds.\n\nBy default, **neither `--fields` nor `--count` is required**:\n- If no count is specified, it defaults to **30**.\n- If no fields are specified, it automatically falls back to the resource schema defined in `mock-api.config.json`. If no config exists, it defaults to a general schema: `id`, `name`, `email`, `status`, `createdAt`.\n\nHere are the command examples for all scenarios:\n\n```bash\n# 1. Zero-config / Fallback (Generates 30 records with default schema)\nmock-api-kit generate users\n\n# 2. Positional fields (Generates 30 records with custom schema)\nmock-api-kit generate incident id,name,description\n\n# 3. Custom count & fields (Generates 50 records)\nmock-api-kit generate users id,name,email,phone --count 50\n\n# 4. Typed generator fields (Generates 100 records)\nmock-api-kit generate orders title:title,amount:number,status:word --count 100\n\n# 5. Generate seed data from local OpenAPI spec file (JSON or YAML)\nmock-api-kit generate incident --spec ./openapi.json\n```\n\n---\n\n## Configuration\n\nCreate `mock-api.config.json` in your project root:\n\n### Simple Routes Mode\n\n```json\n{\n  \"port\": 4000,\n  \"latency\": 300,\n  \"routes\": {\n    \"GET /users\": {\n      \"response\": [\n        { \"id\": 1, \"name\": \"Arun\", \"email\": \"arun@example.com\", \"role\": \"admin\" },\n        { \"id\": 2, \"name\": \"Priya\", \"email\": \"priya@example.com\", \"role\": \"user\" }\n      ]\n    },\n    \"POST /users\": {\n      \"status\": 201,\n      \"response\": {\n        \"id\": \"{{autoId}}\",\n        \"message\": \"User created successfully\"\n      }\n    }\n  }\n}\n```\n\n### Auto-CRUD Resources Mode\n\n```json\n{\n  \"resources\": {\n    \"users\": [\n      { \"id\": 1, \"name\": \"Arun\" },\n      { \"id\": 2, \"name\": \"Priya\" }\n    ],\n    \"incidents\": [\n      { \"id\": 1, \"title\": \"Near miss\", \"status\": \"open\" }\n    ]\n  }\n}\n```\n\nAuto-generates for each resource:\n\n| Method | Path | Description |\n|---|---|---|\n| GET | `/users` | List all (with pagination, search, filter, sort) |\n| GET | `/users/:id` | Get single record |\n| POST | `/users` | Create or upsert record (merges fields if id duplicate is found) |\n| PUT | `/users/:id` | Full update |\n| PATCH | `/users/:id` | Partial update |\n| DELETE | `/users/:id` | Delete record |\n\n### Schema-Based Fake Data\n\n```json\n{\n  \"resources\": {\n    \"users\": {\n      \"count\": 20,\n      \"schema\": {\n        \"id\": \"number\",\n        \"name\": \"name\",\n        \"email\": \"email\",\n        \"phone\": \"phone\",\n        \"createdAt\": \"date\"\n      }\n    }\n  }\n}\n```\n\n#### Supported Schema Types\n\n| Type | Generates |\n|---|---|\n| `number` / `integer` | Random integer |\n| `name` | Full name |\n| `firstName` / `lastName` | First/last name |\n| `email` | Email address |\n| `phone` | Phone number |\n| `date` | ISO date string |\n| `text` / `string` / `sentence` | Lorem sentence |\n| `paragraph` | Lorem paragraph |\n| `word` / `title` | Words |\n| `boolean` | true/false |\n| `uuid` | UUID v4 |\n| `address` | Street address |\n| `city` / `country` / `zipCode` | Location data |\n| `company` | Company name |\n| `url` | URL |\n| `image` / `avatar` | Image URL |\n| `color` | Color name |\n\n---\n\n## Features\n\n### Pagination\n\n```\nGET /users?page=1&limit=10\nGET /users?_page=1&_limit=10\n```\n\nResponse:\n\n```json\n{\n  \"data\": [...],\n  \"page\": 1,\n  \"limit\": 10,\n  \"total\": 50,\n  \"totalPages\": 5\n}\n```\n\nWithout pagination params, returns a flat array.\n\n### Search\n\n```\nGET /users?search=arun\n```\n\nSearches across all string fields.\n\n### Filter\n\n```\nGET /users?role=admin\nGET /incidents?status=open\n```\n\n### Sort\n\n```\nGET /users?sort=name&order=asc\nGET /incidents?sort=createdAt&order=desc\n```\n\n### Latency Simulation\n\n```bash\n# Global\nmock-api-kit start --latency 1000\n\n# Per route in config\n{\n  \"routes\": {\n    \"GET /users\": {\n      \"latency\": 1200,\n      \"response\": []\n    }\n  }\n}\n```\n\n### Error Simulation\n\n```bash\n# Force all requests to return 401\nmock-api-kit start --force-error 401\n```\n\nPer-route error rate:\n\n```json\n{\n  \"routes\": {\n    \"GET /users\": {\n      \"errorRate\": 20,\n      \"error\": {\n        \"status\": 500,\n        \"response\": { \"message\": \"Internal server error\" }\n      },\n      \"response\": []\n    }\n  }\n}\n```\n\n20% of requests return 500.\n\n### Response Templates\n\n```json\n{\n  \"routes\": {\n    \"POST /incidents\": {\n      \"status\": 201,\n      \"response\": {\n        \"id\": \"{{autoId}}\",\n        \"title\": \"{{body.title}}\",\n        \"status\": \"created\",\n        \"createdAt\": \"{{now}}\"\n      }\n    }\n  }\n}\n```\n\n| Template | Description |\n|---|---|\n| `{{autoId}}` | Auto-incrementing ID |\n| `{{now}}` | Current ISO timestamp |\n| `{{body.field}}` | Value from request body |\n| `{{param.field}}` | URL parameter value |\n| `{{query.field}}` | Query string value |\n\n### Auth Simulation\n\n#### Simple Bearer Token\n\n```json\n{\n  \"auth\": {\n    \"enabled\": true,\n    \"type\": \"bearer\",\n    \"token\": \"dev-token\"\n  }\n}\n```\n\nRequests without `Authorization: Bearer dev-token` return 401.\n\n#### User Login with Roles\n\n```json\n{\n  \"auth\": {\n    \"enabled\": true,\n    \"users\": [\n      { \"username\": \"admin\", \"password\": \"admin123\", \"role\": \"admin\" },\n      { \"username\": \"user\", \"password\": \"user123\", \"role\": \"user\" }\n    ]\n  },\n  \"routes\": {\n    \"DELETE /users/:id\": {\n      \"roles\": [\"admin\"]\n    }\n  }\n}\n```\n\nEndpoints:\n\n```\nPOST /auth/login   → { token, user }\nGET  /auth/me      → current user info\n```\n\n### File Upload Mock\n\nDefault upload endpoint at `POST /upload`. Add more:\n\n```json\n{\n  \"uploads\": [\"/documents/upload\", \"/evidence\"]\n}\n```\n\nResponse:\n\n```json\n{\n  \"fileId\": \"file_1001\",\n  \"filename\": \"photo.jpg\",\n  \"mimetype\": \"image/jpeg\",\n  \"size\": 12345,\n  \"url\": \"/mock-files/file_1001.jpg\",\n  \"message\": \"File uploaded successfully\"\n}\n```\n\n### OpenAPI Mode\n\n```bash\nmock-api-kit start --spec ./openapi.json\n```\n\nReads a local OpenAPI 3.x spec (JSON or YAML), generates routes with fake response data automatically.\n\n### Request Logging Dashboard\n\nOpen `http://localhost:4000/__mock` to see:\n\n- Total request count\n- Average response time\n- Error rate\n- Last 50 requests with method, path, status, duration\n- Expandable request/response bodies\n- All configured routes\n\n### Health Check\n\n```\nGET /__health → { status: \"ok\", uptime, routes, resources }\n```\n\n---\n\n## Programmatic API\n\n```ts\nimport { createMockServer } from \"@adhix11/mock-api-kit\";\n\nconst server = createMockServer({\n  port: 4000,\n  latency: 0,\n  resources: {\n    users: [\n      { id: 1, name: \"Arun\", email: \"arun@example.com\" }\n    ]\n  },\n  routes: {\n    \"GET /api/status\": {\n      response: { status: \"ok\", timestamp: \"{{now}}\" }\n    }\n  }\n});\n\nawait server.start();\n\n// Later...\nawait server.stop();\n```\n\n### Exports\n\n```ts\nimport {\n  createMockServer,    // Server factory\n  DataStore,           // In-memory data store\n  generateRecords,     // Fake data generator\n  processTemplate,     // Template engine\n  loadConfig,          // Config file loader\n} from \"@adhix11/mock-api-kit\";\n```\n\n---\n\n## Full Config Reference\n\n```json\n{\n  \"port\": 4000,\n  \"latency\": 0,\n\n  \"routes\": {\n    \"METHOD /path\": {\n      \"status\": 200,\n      \"response\": {},\n      \"latency\": 0,\n      \"errorRate\": 0,\n      \"error\": { \"status\": 500, \"response\": {} },\n      \"roles\": [\"admin\"]\n    }\n  },\n\n  \"resources\": {\n    \"resourceName\": [\n      { \"id\": 1, \"field\": \"value\" }\n    ],\n    \"generatedResource\": {\n      \"count\": 20,\n      \"schema\": {\n        \"id\": \"number\",\n        \"name\": \"name\",\n        \"email\": \"email\"\n      }\n    }\n  },\n\n  \"auth\": {\n    \"enabled\": true,\n    \"type\": \"bearer\",\n    \"token\": \"dev-token\",\n    \"users\": [\n      { \"username\": \"admin\", \"password\": \"admin123\", \"role\": \"admin\" }\n    ]\n  },\n\n  \"uploads\": [\"/documents/upload\"]\n}\n```\n\n---\n\n## Tech Stack\n\n- **Express** — HTTP server\n- **Commander** — CLI framework\n- **@faker-js/faker** — Fake data generation\n- **picocolors** — Terminal colors\n- **multer** — File upload handling\n- **yaml** — OpenAPI YAML parsing\n- **TypeScript** — Full type safety\n\n---\n\n## Philosophy\n\n- 🔒 **100% local** — No cloud, no external APIs\n- 🚫 **No telemetry** — Zero data collection\n- ⚡ **Zero config** — Works out of the box\n- 🎯 **Daily driver** — Built for everyday development\n- 📦 **Lightweight** — Minimal dependencies\n\n---\n\n## License\n\nMIT © [adhix11](https://github.com/adhix11)\n","readmeFilename":"README.md"}