{"_id":"@burnsred/endpoint","_rev":"2-4aaa37c6bc9d9b05439edd6ad4ae3bd6","name":"@burnsred/endpoint","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.1":{"name":"@burnsred/endpoint","version":"1.0.1","keywords":[],"author":{"name":"BurnsRED"},"license":"UNLICENSED","_id":"@burnsred/endpoint@1.0.1","maintainers":[{"name":"burnsred","email":"accounts@burnsred.com.au"}],"dist":{"shasum":"ea0a7dab6f75c965b406b8fe1f104ad485fce950","tarball":"https://registry.npmjs.org/@burnsred/endpoint/-/endpoint-1.0.1.tgz","fileCount":20,"integrity":"sha512-R1Dw9mJWgkv11/v4b5BfHINupHp/enQIqLUznknt9qh34VoU0b9ZfATqqsgbys4Md8jtMQotK2xSVupNj5ImCw==","signatures":[{"sig":"MEUCIGgzsWbgJJxWOn+fUybasgzvaJp/dlX487wYp/5NAR6QAiEAoKyiPhFn0bfZRxawDvmVw3XgZb/qKpXQ8AM/sUw9i0U=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":30073},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","gitHead":"abb499ea6c0ba5b7ea5813a15575aeb9649a6733","scripts":{"lint":"eslint src/","test":"vitest run","build":"tsc -b","check":"tsc --noEmit","clean":"rm -rf tsconfig.tsbuildinfo dist/","lint:fix":"eslint --fix src/","test:watch":"vitest","prepublishOnly":"npm run build"},"_npmUser":{"name":"burnsred","email":"accounts@burnsred.com.au"},"repository":{"url":"git@bitbucket.org-br:burnsred/burnsred-engage-ui.git","type":"git"},"_npmVersion":"9.6.7","description":"This library provides a convenient wrapper around an Axios client for making API calls using Entity classes.","directories":{},"_nodeVersion":"18.17.1","_hasShrinkwrap":false,"devDependencies":{"@burnsred/query":"^1.0.0","@burnsred/utils-testing":"^1.0.0"},"peerDependencies":{"axios":"^1.4.0","react":"^18.2.0","@burnsred/entity":"^1.0.0","@burnsred/entity-form":"^1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/endpoint_1.0.1_1703224712391_0.7494724708067035","host":"s3://npm-registry-packages"}},"1.0.2":{"name":"@burnsred/endpoint","version":"1.0.2","description":"> **⚠️ DEPRECATED**: This package is deprecated and will no longer receive updates.","main":"dist/index.js","scripts":{"test":"vitest run","build":"tsc -b","check":"tsc --noEmit","clean":"rm -rf tsconfig.tsbuildinfo dist/","lint":"eslint src/","lint:fix":"eslint --fix src/","prepublishOnly":"npm run build","test:watch":"vitest"},"repository":{"type":"git","url":"git@bitbucket.org-br:burnsred/burnsred-engage-ui.git"},"keywords":[],"author":{"name":"BurnsRED"},"license":"UNLICENSED","type":"module","types":"dist/index.d.ts","devDependencies":{"@burnsred/query":"^1.0.0","@burnsred/utils-testing":"^1.0.0"},"peerDependencies":{"@burnsred/entity":"^1.0.0","@burnsred/entity-form":"^1.0.0","axios":"^1.4.0","react":"^18.2.0"},"gitHead":"44b5fb7314979aa88b46283b1d87106d80597598","_id":"@burnsred/endpoint@1.0.2","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-ATX4yE+JpCnks2uJfQzi/3K44DSgWLYpjNs0fjz8IMdbZB+3Hv/zVURFTfmJK0spHBSTJoabnsqstyW1icNj9Q==","shasum":"2112c1871bc9eee696dd44288629d59e97fbfdec","tarball":"https://registry.npmjs.org/@burnsred/endpoint/-/endpoint-1.0.2.tgz","fileCount":20,"unpackedSize":30665,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCICClS3Ocf4nOGCt5HCGcIBmu3rhq46KfGDdNpNwGba2vAiEA7btDnQtiNnQIyoCgwcjcfaUfEimyu8zGwA61WUi2Ea4="}]},"_npmUser":{"name":"burnsred","email":"accounts@burnsred.com.au"},"directories":{},"maintainers":[{"name":"burnsred","email":"accounts@burnsred.com.au"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/endpoint_1.0.2_1771890509142_0.4027461274323607"},"_hasShrinkwrap":false}},"time":{"created":"2023-12-22T05:58:32.312Z","modified":"2026-02-23T23:48:29.405Z","1.0.1":"2023-12-22T05:58:32.624Z","1.0.2":"2026-02-23T23:48:29.284Z"},"author":{"name":"BurnsRED"},"license":"UNLICENSED","keywords":[],"repository":{"type":"git","url":"git@bitbucket.org-br:burnsred/burnsred-engage-ui.git"},"description":"> **⚠️ DEPRECATED**: This package is deprecated and will no longer receive updates.","maintainers":[{"name":"burnsred","email":"accounts@burnsred.com.au"}],"readme":"# Endpoints\n\n> **⚠️ DEPRECATED**: This package is deprecated and will no longer receive updates.\n\n## Deprecation Notice\n\nThis package has been deprecated as of version 1.0.1 and is no longer maintained.\n\n**What this means:**\n- No new features will be added\n- No bug fixes will be provided\n- Security vulnerabilities will not be patched\n\n**Recommended Action:**\nPlease migrate to alternative solutions as soon as possible.\n\n## Support\n\nFor questions about this deprecation, please open an issue in the main repository.\n\n---\n\n**Last maintained version:** 1.0.1\n**Deprecation date:** February 2026\n\n---\n\nThis library provides a convenient wrapper around an Axios client for making API\ncalls using Entity classes.\n\n## Quick Start\n\nFirst, create an Endpoint instance for your Entity.\n\n```ts\nimport { axios } from \"axios\";\n\nimport { TodoEntity, type Todo } from \"../todo\";\n\nexport const TodoAPI = new EntityEndpoint<Todo>({\n    entity: TodoEntity,\n    baseUrl: \"/todo/\",\n    client: axios,\n});\n```\n\nIssue requests:\n\n```ts\n\n// By default, it will make a GET request, and expect a list response\nconst todos = TodoAPI.request({}); // GET /todo/\n\n// By passing an ID, it switches to a detail response\nconst todo = TodoAPI.request({ id: 6 }); // GET /todo/6\n\n// An action can also be appended\nconst todos = TodoAPI.request({ action: \"toggle\" }); // GET /todo/toggle\nconst todo = TodoAPI.request({ id: 6, action: \"toggle\" }); // GET /todo/6/toggle\n\n// The response parsing can be overridden\nconst todo = TodoAPI.request({\n    id: 6,\n    action: \"toggle\",\n    processResponse: (data) => OtherEntity.fromData(data),\n});\n\n```\n\n## Custom API calls\n\nIt's encouraged to encapsulate common API requests in methods on a sub-class to\nhelp DRY out the codebase.\n\n```ts\nclass TodoEndpoint extends EntityEndpoint<Todo> {\n  toggle(id: string) {\n    return this.request({ action: \"toggle\", id });\n  }\n}\n\nconst TodoAPI = new TodoEndpoint({ ... });\n\nTodoAPI.toggle(\"6\");\n```\n\n# DRF Entity API\n\nThis is a sub-class of `EntityEndpoint` with a few method added to support common CRUD operations.\n\nFor `Entity<T>` you get:\n\n```ts\n  list(params: QueryParams): Promise<T[]>\n  create(record: T): Promise<T>\n  get(id: string): Promise<T>\n  save(record: T): Promise<T>\n  delete(record: T): Promise<void>\n```\n\n\n# useQuery\n\nTo make it easier to interact with a record from the API - especially with Forms\n- there is the `useQuery` hook.\n\n```ts\n\nfunction WidgetDetail() {\n  const { id } = useParamms();\n\n  const query = useQuery({ api: WidgetAPI, id });\n  const { processing, value } = query;\n\n  if (processing) return <Loading />;\n\n  return (\n    <Form {...query}>\n      ...\n    </Form>\n  );\n}\n```\n\n\n# useApiList\n\nAnother helper hook is `useApiList` for working with lists of records.\n\n```ts\nfunction WidgetList() {\n  const { isLoading, value, errors } = useApiList({ api: WidgetAPI });\n\n  if (isLoading) return <Loading />;\n\n  return (\n    <>\n      <h1> {value.count} results found! </h1>\n      <ul>\n        {value.results.map(widget => <li>{widget.name}</li>)}\n      </ul>\n    </>\n  );\n}\n```\n\nThere is also a `load` function returned, which can be used to reload the\nresults.\n\n\n## WARNING: Params\n\nNote that if the `params` change (not the same object) the API request will re-fire.\n\nThis may unexpectedly cause a render loop!\n\n### BAD\n\n```ts\nfunction UserWidgets({ userId }) {\n  const {} = useApiList({ api: WidgetAPI, params: { userId }})\n\n  ...\n}\n```\n\nSince the `params` object is re-defined each render, this will be seen as `params` changing.\n\nThis is an inherent limitation of how `Object.is` works, which is used by React for Memoising.\n\n### Good\n\n```ts\nfunction UserWidgets({ userId }) {\n\n  const params = useMemo(() => ({ userId }), [userId]);\n\n  const {} = useApiList({ api: WidgetAPI, params });\n\n  ...\n}\n```\n","readmeFilename":"README.md"}