{"id":23002651,"url":"https://github.com/treedomtrees/opa-client-sdk","last_synced_at":"2025-08-20T06:06:40.220Z","repository":{"id":255485790,"uuid":"852240961","full_name":"treedomtrees/opa-client-sdk","owner":"treedomtrees","description":"An undici-based client for Open Policy Agent","archived":false,"fork":false,"pushed_at":"2024-09-20T07:10:53.000Z","size":146,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-08-08T23:27:31.475Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/treedomtrees.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://www.treedom.net/en/organization/treedom/event/treedom-open-source?utm_source=github"]}},"created_at":"2024-09-04T13:24:01.000Z","updated_at":"2024-09-20T07:05:05.000Z","dependencies_parsed_at":"2024-09-05T18:37:10.786Z","dependency_job_id":"7b09e0f7-50a6-4dfd-b0cb-f73e4fa373e6","html_url":"https://github.com/treedomtrees/opa-client-sdk","commit_stats":null,"previous_names":["treedomtrees/opa-client-sdk"],"tags_count":3,"template":false,"template_full_name":"treedomtrees/ts-package-template","purl":"pkg:github/treedomtrees/opa-client-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treedomtrees%2Fopa-client-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treedomtrees%2Fopa-client-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treedomtrees%2Fopa-client-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treedomtrees%2Fopa-client-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/treedomtrees","download_url":"https://codeload.github.com/treedomtrees/opa-client-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treedomtrees%2Fopa-client-sdk/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269668049,"owners_count":24456489,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-15T07:11:55.730Z","updated_at":"2025-08-14T01:31:27.967Z","avatar_url":"https://github.com/treedomtrees.png","language":"TypeScript","funding_links":["https://www.treedom.net/en/organization/treedom/event/treedom-open-source?utm_source=github"],"categories":[],"sub_categories":[],"readme":"# @treedom/opa-client-sdk\n\n\u003ca href=\"https://www.treedom.net/it/organization/treedom/event/treedom-open-source?utm_source=github\"\u003e\u003cimg src=\"https://badges.treedom.net/badge/f/treedom-open-source?utm_source=github\" alt=\"plant-a-tree\" border=\"0\" /\u003e\u003c/a\u003e\n\nAn undici-based client for [Open Policy Agent](https://www.openpolicyagent.org/).\n\n__Made with ❤️ at\u0026nbsp;\u0026nbsp;[\u003cimg src=\"https://assets.treedom.net/image/upload/manual_uploads/treedom-logo-contrib_gjrzt6.png\" height=\"24\" alt=\"Treedom\" border=\"0\" align=\"top\" /\u003e](#-join-us-in-making-a-difference-)__, [join us in making a difference](#-join-us-in-making-a-difference-)!\n\n## Install\n\n```bash\nnpm install @treedom/opa-client-sdk\n```\n\n## Quickstart\n\n```ts\nimport { OpenPolicyAgentClient } from '@treedom/opa-client-sdk';\nimport { LRUCache } from 'lru-cache'\n\nconst cache = new LRUCache();\n\nconst opaClient = new OpenPolicyAgentClient({\n  url: 'https://my-opa.example.com',\n  cache?: Cache // optional\n  opaVersion?: string // defaults to 'v1'\n  method?: 'POST' | 'GET' // defaults to 'POST'\n  requestOptions?: UndiciRequestOptions // among other things, allows setting a proxy\n})\n```\n\n## Usage\n\nThe `OpenPolicyAgentClient` class provides three methods: `evaluate`, `assert`, and `query`.\n\n- All methods take the policy name and input as arguments. When specified, the input is expected to be an object.\n- All the keys in the input object are optional; some frequently used keys, like `subject`, `resource`, and `headers`, are typed for convenience in `OpaQueryInput`.\n- All the methods support generic types allowing customization when needed.\n- Using the provided configuration, the client will make a request to the OPA server on `/{opaVersion}/data/{policyName}`.\n\n#### Evaluate\n\nThe `evaluate` method returns the result of the policy evaluation. Throws only when the evaluation fails, following a network error for example. The policy is expected to return an object with a `result` key: `{ result: boolean }`.\n\n```ts\nawait opaClient.evaluate(\n  'data.my.policy.package', // Policy name\n  { // Input\n    subject: {\n      id: '123',\n      type: 'user'\n    },\n    resource: {\n      id: '456',\n      type: 'document'\n    },\n    headers: {\n      authorization: 'Bearer token'\n    }\n  }\n) // Returns a boolean\n```\n\n#### Assert\n\nThe `assert` method throws an error if the response does not match the expected value.\n\n```ts\nawait opaClient.assert(\n  'data.my.policy.package', // Policy name\n  { // Input\n    subject: {\n      id: '123',\n      type: 'user'\n    },\n    resource: {\n      id: '456',\n      type: 'document'\n    },\n    headers: {\n      authorization: 'Bearer token'\n    }\n  },\n  true // Expected value\n) // Returns void\n```\n\n#### Query\n\nThe `query` method makes a direct call to the OPA server and returns the raw body, or throws an error if the query fails (status code different from 200).\n\n```ts\n\nconst { result } = await opaClient.query(\n  'data.my.policy.package', // Policy name\n  { // Input\n    subject: {\n      id: '123',\n      type: 'user'\n    },\n    resource: {\n      id: '456',\n      type: 'document'\n    },\n    headers: {\n      authorization: 'Bearer token'\n    }\n  }\n) // Returns an object\n```\n\n## 🌳 Join Us in Making a Difference! 🌳\n\nWe invite all developers who use Treedom's open-source code to support our mission of sustainability by planting a tree with us. By contributing to reforestation efforts, you help create a healthier planet and give back to the environment. Visit our [Treedom Open Source Forest](https://www.treedom.net/en/organization/treedom/event/treedom-open-source) to plant your tree today and join our community of eco-conscious developers.\n\nAdditionally, you can integrate the Treedom GitHub badge into your repository to showcase the number of trees in your Treedom forest and encourage others to plant new ones. Check out our [integration guide](https://github.com/treedomtrees/.github/blob/main/TREEDOM_BADGE.md) to get started.\n\nTogether, we can make a lasting impact! 🌍💚\n\n## Contributing\n\nContributions are welcome! Please read the contributing guidelines before submitting a pull request.\n\n## License\n\nThis project is licensed under the MIT License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreedomtrees%2Fopa-client-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftreedomtrees%2Fopa-client-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreedomtrees%2Fopa-client-sdk/lists"}