{"id":18812411,"url":"https://github.com/warrant-dev/warrant-node","last_synced_at":"2025-08-21T18:33:40.603Z","repository":{"id":40400800,"uuid":"381492295","full_name":"warrant-dev/warrant-node","owner":"warrant-dev","description":"Node.js Client SDK for Warrant","archived":false,"fork":false,"pushed_at":"2024-07-11T11:24:13.000Z","size":307,"stargazers_count":24,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-10T16:43:19.015Z","etag":null,"topics":["abac","access-control","acl","attribute-based-access-control","authorization","authz","javascript","nodejs","permissions","rbac","role-based-access-control"],"latest_commit_sha":null,"homepage":"","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/warrant-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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}},"created_at":"2021-06-29T20:44:38.000Z","updated_at":"2024-11-28T03:19:46.000Z","dependencies_parsed_at":"2023-12-20T20:25:03.656Z","dependency_job_id":"5e52c53e-afb7-4270-ac3f-2ce32afffafc","html_url":"https://github.com/warrant-dev/warrant-node","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warrant-dev%2Fwarrant-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warrant-dev%2Fwarrant-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warrant-dev%2Fwarrant-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warrant-dev%2Fwarrant-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/warrant-dev","download_url":"https://codeload.github.com/warrant-dev/warrant-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230527866,"owners_count":18240051,"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","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":["abac","access-control","acl","attribute-based-access-control","authorization","authz","javascript","nodejs","permissions","rbac","role-based-access-control"],"created_at":"2024-11-07T23:32:45.490Z","updated_at":"2024-12-20T03:10:17.854Z","avatar_url":"https://github.com/warrant-dev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Warrant Node.js Library\n\nUse [Warrant](https://warrant.dev/) in server-side Node.js projects.\n\n[![npm](https://img.shields.io/npm/v/@warrantdev/warrant-node)](https://www.npmjs.com/package/@warrantdev/warrant-node)\n\n## Installation\n\nUse `npm` to install the Warrant module:\n\n```sh\nnpm install @warrantdev/warrant-node\n```\n\n## Usage\n\nImport the Warrant client and pass your API key to the constructor to get started:\n\n```js\nconst Warrant = require(\"@warrantdev/warrant-node\");\nconst warrantClient = new Warrant.WarrantClient({\n  apiKey: \"api_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=\",\n});\n```\n\nOr using ES modules:\n\n```js\nimport { WarrantClient } from \"@warrantdev/warrant-node\";\nconst warrantClient = new WarrantClient({\n  apiKey: \"api_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=\",\n});\n```\n\n---\n\nThis method creates a user in Warrant with the provided `userId`. Provide an optional `email` to make it easier to identify users in the Warrant dashboard.\n\n```js\nconst Warrant = require(\"@warrantdev/warrant-node\");\nconst warrantClient = new Warrant.WarrantClient({\n  apiKey: \"api_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=\",\n});\n\n// Creates a user with user.id as the userId\nwarrantClient.User\n  .create({ userId: user.id, email: user.email })\n  .then((newUser) =\u003e console.log(newUser))\n  .catch((error) =\u003e console.log(error));\n```\n\nOr using ES modules and async/await:\n\n```js\nimport { WarrantClient } from \"@warrantdev/warrant-node\";\nconst warrantClient = new WarrantClient({\n  apiKey: \"api_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=\",\n});\n\n// Creates a user with user.id as the userId and\n// assigns the new user the \"store_owner\" role\nconst newUser = await warrantClient.User.create({\n  userId: user.id,\n  email: user.email,\n});\n```\n\n## Configuring the API Endpoint\n---\nThe API endpoint the SDK makes requests to is configurable via the `endpoint` attribute when initializing the client:\n\n```js\nimport { WarrantClient } from \"@warrantdev/warrant-node\";\n\n// Set api and authorize endpoints to http://localhost:8000\nconst warrantClient = new WarrantClient({\n  apiKey: \"api_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=\",\n  endpoint: \"http://localhost:8000\",\n});\n```\n\n## Authorization\n\nAll access checks are performed based on an `object`, `relation` and `subject`. You can pass your own defined objects to the check methods by implementing the `WarrantObject` interface.\n\n```\ninterface WarrantObject {\n    getObjectType(): string;\n    getObjectId(): string;\n}\n```\n\n### `check(Check)`\n\nThis method returns a `Promise` that resolves with `true` if the `subject` has the specified `relation` to the `object` and `false` otherwise.\n\n```js\nconst Warrant = require(\"@warrantdev/warrant-node\");\n\nconst warrantClient = new Warrant.WarrantClient({\n  apiKey: \"api_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=\",\n});\n\n// Store class implements WarrantObject\nclass Store {\n  private id: number;\n\n  public getObjectType(): string {\n    return \"store\";\n  }\n\n  public getObjectId(): string {\n    return this.id.toString();\n  }\n}\n\n//\n// Example Scenario:\n// An e-commerce website where Store Owners can edit store info\n//\nconst myStore = new Store('my-store');\nwarrantClient.Authorization\n  .check({\n    object: myStore,\n    relation: \"edit\",\n    subject: {\n      objectType: \"user\",\n      objectId: user.id,\n    },\n  })\n  .then((isAuthorized) =\u003e {\n    if (isAuthorized) {\n      // Carry out logic to allow user to edit a Store\n    }\n  })\n  .catch((error) =\u003e console.log(error));\n```\n\nOr using ES modules and async/await:\n\n```js\nimport { WarrantClient } from \"@warrantdev/warrant-node\";\n\nconst warrantClient = new WarrantClient({\n  apiKey: \"api_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=\",\n});\n\n//\n// Example Scenario:\n// An e-commerce website where Store Owners can edit store info\n//\nconst myStore = new Store('my-store');\nif (\n  await warrantClient.Authorization.check({\n    object: myStore,\n    relation: \"edit\",\n    subject: {\n      objectType: \"user\",\n      objectId: user.id,\n    },\n  })\n) {\n  // Carry out logic to allow user to edit a Store\n}\n```\n\nWe’ve used a random API key in these code examples. Replace it with your\n[actual publishable API keys](https://app.warrant.dev) to\ntest this code through your own Warrant account.\n\nFor more information on how to use the Warrant API and usage examples for all methods, please refer to the\n[Warrant API reference](https://docs.warrant.dev).\n\nNote that we may release new [minor and patch](https://semver.org/) versions of\n`@warrantdev/warrant-node` with small but backwards-incompatible fixes to the type\ndeclarations. These changes will not affect Warrant itself.\n\n## TypeScript support\n\nThis package includes TypeScript declarations for Warrant.\n\n## Warrant Documentation\n\n- [Warrant Docs](https://docs.warrant.dev/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwarrant-dev%2Fwarrant-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwarrant-dev%2Fwarrant-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwarrant-dev%2Fwarrant-node/lists"}