{"_id":"@afpia/fetcher","_rev":"3-74287b21faa27186274db29a94ad7cdd","name":"@afpia/fetcher","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.1":{"name":"@afpia/fetcher","version":"1.0.1","keywords":["fetcher","nextjs"],"author":{"url":"https://github.com/Afpia","name":"Afpia"},"license":"MIT","_id":"@afpia/fetcher@1.0.1","maintainers":[{"name":"afpia","email":"nikiprostoff@gmail.com"}],"homepage":"https://github.com/Afpiya/fetcher","bugs":{"url":"https://github.com/Afpiya/fetcher/issues"},"dist":{"shasum":"2ec204cea3e1bb6d4659c37fc15b5936f6ef0662","tarball":"https://registry.npmjs.org/@afpia/fetcher/-/fetcher-1.0.1.tgz","fileCount":8,"integrity":"sha512-FTNQjQVwh/LC33oyuF9/FpBxfxo8mt43W2QDQ/BL6bGVDwUNqUHLeb6y3ZDAvWABIOZeEszHHgNOh/uApfcRaA==","signatures":[{"sig":"MEUCIQDhwm88xNymSlIq8m9f5uMdnKIwdhnBJDd/9cWEhssxNQIgIPVX/qEbcsuUhYUnzIP2tN4RD7IjD2G5xbBOAApZRJQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":43026},"main":"dist/index.cjs.js","type":"module","types":"dist/types/index.d.ts","module":"dist/index.es.js","gitHead":"87194f4e434e04c83ff3fc31549715104d2651ed","private":false,"scripts":{"build":"vite build","release":"release-it"},"_npmUser":{"name":"afpia","email":"nikiprostoff@gmail.com"},"release-it":{"git":{"push":true,"tagName":"v${version}","pushRepo":"origin","pushTags":true,"commitMessage":"chore: 🎭release v${version}","requireUpstream":true},"npm":{"pkgRoot":"dist","publish":true,"ignoreVersion":false},"hooks":{"before:init":["npm run build"],"after:release":"echo '🎉 Published v${version}!'"},"$schema":"https://unpkg.com/release-it/schema/release-it.json","plugins":{"@release-it/conventional-changelog":{"infile":"CHANGELOG.md","preset":"angular"}}},"repository":{"url":"git+https://github.com/Afpiya/fetcher.git"},"_npmVersion":"11.2.0","description":"","directories":{},"_nodeVersion":"22.14.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"npm@11.2.0","devDependencies":{"vite":"^6.3.5","release-it":"^19.0.3","typescript":"^5.8.3","@types/node":"^22.15.30","@afpia/prettier":"^1.2.0","vite-plugin-dts":"^4.5.4","@release-it/conventional-changelog":"^10.0.1"},"_npmOperationalInternal":{"tmp":"tmp/fetcher_1.0.1_1749302940531_0.7073349089702134","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@afpia/fetcher","version":"1.0.2","keywords":["fetcher","nextjs"],"author":{"url":"https://github.com/Afpia","name":"Afpia"},"license":"MIT","_id":"@afpia/fetcher@1.0.2","maintainers":[{"name":"afpia","email":"nikiprostoff@gmail.com"}],"homepage":"https://github.com/Afpiya/fetcher","bugs":{"url":"https://github.com/Afpiya/fetcher/issues"},"dist":{"shasum":"c6f79f3ce40d62d6f94ac7d2ddd04207f3743dd1","tarball":"https://registry.npmjs.org/@afpia/fetcher/-/fetcher-1.0.2.tgz","fileCount":8,"integrity":"sha512-Sx23L0HEk6iNi3d2UiTtWesAYTTNK6qGwKezrii/HRt5iIDe2uJzOpjWaX9OWKR16duGjMbl6px57bEPvL2btg==","signatures":[{"sig":"MEUCIQDPPdqIBAtbWDblAdTtCsVWwrN0yDEaAJnDpdeWLiJuNQIgdcUZJrsp+8Ginrm3rIAGr9AThUPoIH9M8OQJsaP8hFI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":49520},"main":"dist/index.cjs.js","type":"module","types":"dist/types/index.d.ts","module":"dist/index.es.js","gitHead":"cc1ffd5a8c0d928b29b3b5ac55e6a96b98423510","private":false,"scripts":{"build":"vite build","release":"release-it"},"_npmUser":{"name":"afpia","email":"nikiprostoff@gmail.com"},"release-it":{"git":{"push":true,"tagName":"v${version}","pushRepo":"origin","pushTags":true,"commitMessage":"chore: release v${version} 🎭","requireUpstream":true},"npm":{"pkgRoot":"dist","publish":true,"ignoreVersion":false},"hooks":{"before:init":["npm run build"],"after:release":"echo '🎉 Published v${version}!'"},"$schema":"https://unpkg.com/release-it/schema/release-it.json","plugins":{"@release-it/conventional-changelog":{"infile":"CHANGELOG.md","preset":"angular"}},"increment":"prompt"},"repository":{"url":"git+https://github.com/Afpiya/fetcher.git"},"_npmVersion":"11.2.0","description":"fetcher for Next.js applications","directories":{},"_nodeVersion":"22.14.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"npm@11.2.0","devDependencies":{"vite":"^6.3.5","release-it":"^19.0.3","typescript":"^5.8.3","@types/node":"^22.15.30","@afpia/prettier":"^1.2.0","vite-plugin-dts":"^4.5.4","@release-it/conventional-changelog":"^10.0.1"},"_npmOperationalInternal":{"tmp":"tmp/fetcher_1.0.2_1749305696341_0.8804906839085982","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@afpia/fetcher","version":"1.1.0","license":"MIT","type":"module","description":"fetcher for Next.js applications","keywords":["fetcher","nextjs"],"main":"dist/index.cjs.js","module":"dist/index.es.js","types":"dist/types/index.d.ts","publishConfig":{"access":"public"},"private":false,"author":{"name":"Afpia","url":"https://github.com/Afpia"},"bugs":{"url":"https://github.com/Afpiya/fetcher/issues"},"homepage":"https://github.com/Afpiya/fetcher","repository":{"url":"git+https://github.com/Afpiya/fetcher.git"},"packageManager":"npm@11.2.0","scripts":{"build":"vite build","changelog":"conventional-changelog -p angular -i CHANGELOG.md -s","release":"release-it"},"release-it":{"increment":"prompt","$schema":"https://unpkg.com/release-it/schema/release-it.json","git":{"commitMessage":"chore: release v${version} 🎭","tagName":"v${version}","requireUpstream":true,"push":true,"pushRepo":"origin","pushTags":true},"npm":{"publish":true,"pkgRoot":"dist","ignoreVersion":false},"hooks":{"before:init":["npm run build"],"after:bump":"npm run changelog","after:release":"echo '🎉 Published v${version}!'"}},"devDependencies":{"@afpia/prettier":"^1.2.0","@types/node":"^22.15.30","conventional-changelog-cli":"^5.0.0","release-it":"^19.0.3","typescript":"^5.8.3","vite":"^6.3.5","vite-plugin-dts":"^4.5.4"},"_id":"@afpia/fetcher@1.1.0","gitHead":"bee736573e03e501ec50aeeebefa7823208c1670","_nodeVersion":"22.14.0","_npmVersion":"11.2.0","dist":{"integrity":"sha512-MPASrakDEsHj0PDt1scGCCH+p2CPovEaR+HtKPk5ZRYNK7+n5yBC9JqpIg163XKXp5xZkCkuZVkb6wc9Anccxw==","shasum":"21969b46cd44a335fcce4011568a36b44ffeb658","tarball":"https://registry.npmjs.org/@afpia/fetcher/-/fetcher-1.1.0.tgz","fileCount":8,"unpackedSize":49586,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCID2PNLd61wzQvgalRTE3YhjYwWi/6sWNjIZf4JIPVEQnAiEAgJvgewWyY3A+S9y16qfeOGv/KKyarZ1RiwLO4o57Ltg="}]},"_npmUser":{"name":"afpia","email":"nikiprostoff@gmail.com"},"directories":{},"maintainers":[{"name":"afpia","email":"nikiprostoff@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/fetcher_1.1.0_1749307101504_0.8642935126555467"},"_hasShrinkwrap":false}},"time":{"created":"2025-06-07T13:29:00.468Z","modified":"2025-06-07T14:38:21.889Z","1.0.1":"2025-06-07T13:29:00.698Z","1.0.2":"2025-06-07T14:14:56.523Z","1.1.0":"2025-06-07T14:38:21.719Z"},"bugs":{"url":"https://github.com/Afpiya/fetcher/issues"},"author":{"name":"Afpia","url":"https://github.com/Afpia"},"license":"MIT","homepage":"https://github.com/Afpiya/fetcher","keywords":["fetcher","nextjs"],"repository":{"url":"git+https://github.com/Afpiya/fetcher.git"},"description":"fetcher for Next.js applications","maintainers":[{"name":"afpia","email":"nikiprostoff@gmail.com"}],"readme":"# Fetcher\r\n\r\n**Лёгкая обёртка над fetch** с удобным созданием URL-параметров, обработкой заголовков и встроенной генерацией ошибок.\r\n\r\n- **Публикация:** npm ([https://www.npmjs.com/package/@afpia/fetcher](https://www.npmjs.com/package/@afpia/fetcher))\r\n- **Исходники:** GitHub ([https://github.com/Afpiya/fetcher](https://github.com/Afpiya/fetcher))\r\n\r\n---\r\n\r\n## Содержание\r\n\r\n1. [Краткое описание](#краткое-описание)\r\n2. [Установка](#установка)\r\n3. [Создание экземпляра через `fetcher.create`](#создание-экземпляра-через-fetchercreate)\r\n4. [Примеры использования](#примеры-использования)\r\n\r\n---\r\n\r\n## Краткое описание\r\n\r\n`@afpia/fetcher` — это минималистичный HTTP-клиент на основе встроенного `fetch`, который добавляет:\r\n\r\n- Удобную генерацию строки параметров (`params`) для GET-запросов.\r\n- Типизацию через TypeScript (включая `.d.ts`-файлы).\r\n- Встроенный класс ошибки `FetcherError` с HTTP-статусом и сообщением.\r\n- Способы задать базовый URL, заголовки и общие параметры для всех запросов.\r\n- Возможность создавать несколько экземпляров с разными конфигурациями.\r\n\r\nБиблиотека не тянет внешних зависимостей (кроме нативного `fetch`), поддерживает любые окружения, где есть `fetch`.\r\n\r\n---\r\n\r\n## Установка\r\n\r\n```bash\r\nnpm install @afpia/fetcher\r\n# или\r\nyarn add @afpia/fetcher\r\n# или\r\npnpm add @afpia/fetcher\r\n```\r\n\r\n## Создание экземпляра через fetcher.create\r\n\r\nЧтобы не переиспользовать «пустой» instance без baseUrl, вы чаще всего захотите создать собственный экземпляр, указывая базовый URL:\r\n\r\n```ts\r\nimport fetcher from '@afpia/fetcher'\r\n\r\n// Создаём новый клиент с базовым URL\r\nconst apiClient = fetcher.create({\r\n  baseUrl: 'https://api.example.com',\r\n  headers: {\r\n    'X-Custom-Header': 'foobar'\r\n  },\r\n  // Если вы всегда хотите посылать какие-то query-параметры по умолчанию,\r\n  // можете передать их сюда:\r\n  params: {\r\n    lang: 'ru',           // string\r\n    debug: true,          // boolean\r\n    version: 42           // number\r\n    // или даже массив: roles: ['admin', 'editor']\r\n  }\r\n})\r\n\r\n// Теперь можно вызывать apiClient.get, apiClient.post и т.д.\r\n```\r\n\r\n## Примеры использования\r\n\r\nОбычный GET-запрос с query-параметрами\r\n\r\n```ts\r\nimport fetcher from '@afpia/fetcher'\r\n\r\nconst api = fetcher.create({\r\n  baseUrl: 'https://api.example.com/v1',\r\n  headers: {\r\n    'X-API-KEY': '123abc'\r\n  }\r\n})\r\n\r\nasync function searchArticles(term: string, page: number) {\r\n  try {\r\n    const articles = await api.get<Article[]>('articles', {\r\n      params: {\r\n        q: term,\r\n        page,\r\n        tags: ['news', 'tech']\r\n      }\r\n    })\r\n    console.log('Найденные статьи:', articles)\r\n  } catch (e) {\r\n    if (e instanceof FetcherError) {\r\n      console.error(`HTTP ${e.statusCode}: ${e.message}`)\r\n    } else {\r\n      console.error('Неизвестная ошибка:', e)\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nPOST-запрос с JSON-телом\r\n\r\n```ts\r\nimport fetcher from '@afpia/fetcher'\r\n\r\nconst api = fetcher.create({\r\n  baseUrl: 'https://api.example.com/v1'\r\n})\r\n\r\ninterface CreateUserDto {\r\n  username: string\r\n  password: string\r\n}\r\n\r\nasync function registerUser(data: CreateUserDto) {\r\n  try {\r\n    const response = await api.post<{ id: number; username: string }>(\r\n      'users/register',\r\n      data,\r\n      {\r\n        headers: {\r\n          'X-Client-Version': '1.0.0'\r\n        }\r\n      }\r\n    )\r\n    console.log('Пользователь создан:', response)\r\n  } catch (e) {\r\n    if (e instanceof FetcherError) {\r\n      console.warn(`Не удалось создать пользователя: [${e.statusCode}] ${e.message}`)\r\n    } else {\r\n      console.error('Ошибка в процессе регистрации:', e)\r\n    }\r\n  }\r\n}\r\n```","readmeFilename":"README.md"}