{"_id":"@ahmedsherwani/clearerrors-core","name":"@ahmedsherwani/clearerrors-core","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@ahmedsherwani/clearerrors-core","version":"1.0.0","description":"Core translation engine for turning backend API errors into user-friendly frontend messages","main":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"build":"tsc","dev":"tsc --watch","prepublishOnly":"pnpm build"},"keywords":["error-handling","error-translation","api-errors","user-friendly-errors","error-normalization","typescript"],"author":"","license":"MIT","repository":{"type":"git","url":"git+https://github.com/maksherwani/clear-errors.git","directory":"packages/core"},"publishConfig":{"access":"public"},"dependencies":{},"devDependencies":{"typescript":"^5.3.3"},"_id":"@ahmedsherwani/clearerrors-core@1.0.0","bugs":{"url":"https://github.com/maksherwani/clear-errors/issues"},"homepage":"https://github.com/maksherwani/clear-errors#readme","_nodeVersion":"22.13.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-+gOfwjtiVt2alzHL6D3MLltG1D+K3Wi0cTQtTk3c58TrZM4AfpxZKKly4pTFMpxer/SUQLi5xFSlqTIiL0Zljw==","shasum":"585daa856717ff086f3e0895d6798a7e4bce4829","tarball":"https://registry.npmjs.org/@ahmedsherwani/clearerrors-core/-/clearerrors-core-1.0.0.tgz","fileCount":14,"unpackedSize":24870,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDfxuqeBbYtWxUsy1240VvbNvH2oyCVJl+pxllOajHA5wIhAPw06zuz51OIn15qV/bvbIRtbAYL1oLfwt78kkr/yRvs"}]},"_npmUser":{"name":"ahmedsherwani","email":"maksherwanii@gmail.com"},"directories":{},"maintainers":[{"name":"ahmedsherwani","email":"maksherwanii@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/clearerrors-core_1.0.0_1767474413736_0.7562538958602869"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-03T21:06:53.634Z","1.0.0":"2026-01-03T21:06:53.912Z","modified":"2026-01-03T21:06:54.241Z"},"maintainers":[{"name":"ahmedsherwani","email":"maksherwanii@gmail.com"}],"description":"Core translation engine for turning backend API errors into user-friendly frontend messages","homepage":"https://github.com/maksherwani/clear-errors#readme","keywords":["error-handling","error-translation","api-errors","user-friendly-errors","error-normalization","typescript"],"repository":{"type":"git","url":"git+https://github.com/maksherwani/clear-errors.git","directory":"packages/core"},"bugs":{"url":"https://github.com/maksherwani/clear-errors/issues"},"license":"MIT","readme":"# @ahmedsherwani/clearerrors-core\n\nCore translation engine for turning backend API errors into user-friendly frontend messages.\n\n## Installation\n\n```bash\nnpm install @ahmedsherwani/clearerrors-core\n```\n\n## Usage\n\n### Basic Usage\n\n```typescript\nimport { clearError } from '@ahmedsherwani/clearerrors-core';\n\nconst translated = await clearError({\n  status: 401,\n  error: 'UNAUTHORIZED'\n});\n\n// Result:\n// {\n//   message: \"Please sign in to continue\",\n//   severity: \"error\",\n//   uiHint: \"modal\",\n//   action: \"LOGIN\"\n// }\n```\n\n### Normalize Errors\n\n```typescript\nimport { normalizeError } from '@ahmedsherwani/clearerrors-core';\n\n// Normalize any error format (Axios, Fetch, standard errors)\nconst normalized = normalizeError(error);\n```\n\n### Translate Normalized Errors\n\n```typescript\nimport { translateError, normalizeError } from '@ahmedsherwani/clearerrors-core';\n\nconst normalized = normalizeError(error);\nconst translated = await translateError(normalized, {\n  locale: 'en',\n  tone: 'friendly',\n  useAI: false,\n  aiApiKey: process.env.OPENAI_API_KEY, // Optional\n});\n```\n\n## Features\n\n- ✅ Error normalization (handles Axios, Fetch, standard errors)\n- ✅ Rule-based translation with priority matching\n- ✅ AI fallback (OpenAI) for unknown errors\n- ✅ Custom rules support\n- ✅ TypeScript support\n- ✅ Zero dependencies\n\n## API Reference\n\n### `clearError(error, options?)`\n\nMain function to translate any error into a user-friendly message.\n\n**Parameters:**\n- `error`: Any error object (Axios error, Fetch error, standard error, etc.)\n- `options`: Optional translation options\n  - `locale`: Language code (default: 'en')\n  - `tone`: Message tone - 'friendly', 'professional', 'casual' (default: 'friendly')\n  - `useAI`: Whether to use AI fallback (default: false)\n  - `aiApiKey`: OpenAI API key (required if useAI is true)\n\n**Returns:** `Promise<TranslatedError>`\n\n### `normalizeError(error)`\n\nNormalize any error format into a standard shape.\n\n**Parameters:**\n- `error`: Any error object\n\n**Returns:** `NormalizedError`\n\n### `translateError(normalizedError, options?)`\n\nTranslate a normalized error into a user-friendly message.\n\n**Parameters:**\n- `normalizedError`: A normalized error object\n- `options`: Translation options (same as `clearError`)\n\n**Returns:** `Promise<TranslatedError>`\n\n## License\n\nMIT\n\n","readmeFilename":"README.md","_rev":"1-e11e17967d9f5d753b21d475cdef2285"}