{"_id":"@axonsdev/hateoas-fetch","name":"@axonsdev/hateoas-fetch","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@axonsdev/hateoas-fetch","version":"0.1.0","license":"MPL-2.0","author":{"email":"nprin@axons.fr"},"type":"module","main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"sideEffects":false,"publishConfig":{"access":"public"},"dependencies":{"@axonsdev/hateoas-core":"^0.1.0"},"scripts":{"build":"tsc -b tsconfig.json"},"_id":"@axonsdev/hateoas-fetch@0.1.0","description":"Fetch-based transport for `@axonsdev/hateoas-core`.","_integrity":"sha512-dPkvSzz5N3dcS8yqQrdbngodLKi4QtkI2kzwQyEP7gEkhcyWJjbMlge5LSgIPP22FG+jnvKKN1qr6CzWPtxgkA==","_resolved":"/tmp/1021ac91ca214afa7070670cf7359ce1/axonsdev-hateoas-fetch-0.1.0.tgz","_from":"file:axonsdev-hateoas-fetch-0.1.0.tgz","_nodeVersion":"22.22.2","_npmVersion":"10.9.7","dist":{"integrity":"sha512-dPkvSzz5N3dcS8yqQrdbngodLKi4QtkI2kzwQyEP7gEkhcyWJjbMlge5LSgIPP22FG+jnvKKN1qr6CzWPtxgkA==","shasum":"1c0f17c0651a590e3147cece321ab1a07cc059c3","tarball":"https://registry.npmjs.org/@axonsdev/hateoas-fetch/-/hateoas-fetch-0.1.0.tgz","fileCount":7,"unpackedSize":22454,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIDf3g7ln6/n+RFY6Ds5vSO6oh7laOgDRXoFg9EcEbEcXAiEAm0sAqYy66hquVZ4P7sU5qH+g6MYj+JXlBDMtByrzj1g="}]},"_npmUser":{"name":"axonsdev","email":"nprin@axons.fr"},"directories":{},"maintainers":[{"name":"axonsdev","email":"nprin@axons.fr"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/hateoas-fetch_0.1.0_1777393222226_0.7906109119513929"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-28T16:20:22.148Z","0.1.0":"2026-04-28T16:20:22.354Z","modified":"2026-04-28T16:20:22.556Z"},"maintainers":[{"name":"axonsdev","email":"nprin@axons.fr"}],"description":"Fetch-based transport for `@axonsdev/hateoas-core`.","author":{"email":"nprin@axons.fr"},"license":"MPL-2.0","readme":"# @axonsdev/hateoas-fetch\n\nFetch-based transport for `@axonsdev/hateoas-core`.\n\nThis package adapts the platform `fetch` API to the `HypermediaTransport` contract. It is usable in browsers, Node runtimes that provide `fetch`, and tests that inject a custom `fetchFn`.\n\n## Responsibilities\n\n- Resolve relative URLs against an optional `baseUrl`.\n- Add dynamic headers before each request.\n- Pass credentials to `fetch`.\n- Serialize request bodies as JSON.\n- Normalize response headers, content type, status, and body.\n- Throw `HypermediaHttpError` for non-2xx responses.\n\n## Main Exports\n\n```ts\nfetchTransport(options)\nFetchHypermediaTransport\nFetchHypermediaTransportOptions\n```\n\n## Basic Usage\n\n```ts\nimport { createHateoasClient } from '@axonsdev/hateoas-core';\nimport { fetchTransport } from '@axonsdev/hateoas-fetch';\nimport { sirenParser } from '@axonsdev/hateoas-siren';\n\nconst client = createHateoasClient({\n  transport: fetchTransport({\n    baseUrl: 'http://localhost:3000',\n  }),\n  parsers: [sirenParser()],\n});\n```\n\n## Options\n\n```ts\ninterface FetchHypermediaTransportOptions {\n  baseUrl?: string;\n  credentials?: RequestCredentials;\n  headers?: () => Record<string, string> | Promise<Record<string, string>>;\n  fetchFn?: typeof fetch;\n}\n```\n\n### `baseUrl`\n\nUsed to resolve relative hrefs.\n\n```ts\nfetchTransport({\n  baseUrl: 'https://api.example.com',\n});\n```\n\nA request to `/api/cases` becomes `https://api.example.com/api/cases`.\n\n### `credentials`\n\nPassed through to `fetch`.\n\n```ts\nfetchTransport({\n  credentials: 'include',\n});\n```\n\n### `headers`\n\nCalled before every request. This is useful for auth tokens, tenant IDs, or demo role headers.\n\n```ts\nfetchTransport({\n  headers: () => ({\n    Authorization: `Bearer ${tokenStore.current()}`,\n  }),\n});\n```\n\nThe transport merges dynamic headers with request-specific headers from the HATEOAS client. Request-specific headers win when keys overlap.\n\n### `fetchFn`\n\nInject a custom fetch implementation.\n\n```ts\nfetchTransport({\n  fetchFn: testFetch,\n});\n```\n\nThis is useful in tests or runtimes where `globalThis.fetch` is not available.\n\n## Response Handling\n\nThe transport reads the body as JSON when the content type includes `json`.\n\nOtherwise, it reads the body as text.\n\n`204 No Content` returns `undefined` as the body.\n\n## Error Handling\n\nNon-OK responses throw:\n\n```ts\nnew HypermediaHttpError(response.status, body)\n```\n\nThe parsed body is attached to the error so application code can inspect API error details.\n\n## Implementation Note\n\nThe default `fetch` is bound with `fetch.bind(globalThis)`. Browser `fetch` can throw `Illegal invocation` when called after being detached from `window`; binding avoids that runtime failure.\n","readmeFilename":"README.md","_rev":"1-1be1a7856c1cd3fdfa6b2f611eba3f83"}