{"id":18812409,"url":"https://github.com/warrant-dev/warrant-js","last_synced_at":"2025-07-14T11:09:39.361Z","repository":{"id":46553705,"uuid":"376947046","full_name":"warrant-dev/warrant-js","owner":"warrant-dev","description":"Javascript Client SDK for Warrant","archived":false,"fork":false,"pushed_at":"2024-06-17T00:19:27.000Z","size":265,"stargazers_count":8,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-19T17:17:11.836Z","etag":null,"topics":["abac","access-control","acl","attribute-based-access-control","authorization","authz","javascript","permissions","rbac","role-based-access-control","typescript"],"latest_commit_sha":null,"homepage":"https://warrant.dev","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-14T20:24:25.000Z","updated_at":"2024-06-03T19:07:52.000Z","dependencies_parsed_at":"2024-04-01T17:32:17.588Z","dependency_job_id":"ba6773b5-7d95-4d22-a32c-92be57d85f79","html_url":"https://github.com/warrant-dev/warrant-js","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/warrant-dev/warrant-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warrant-dev%2Fwarrant-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warrant-dev%2Fwarrant-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warrant-dev%2Fwarrant-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warrant-dev%2Fwarrant-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/warrant-dev","download_url":"https://codeload.github.com/warrant-dev/warrant-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warrant-dev%2Fwarrant-js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265281327,"owners_count":23739874,"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","permissions","rbac","role-based-access-control","typescript"],"created_at":"2024-11-07T23:32:44.289Z","updated_at":"2025-07-14T11:09:39.310Z","avatar_url":"https://github.com/warrant-dev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @warrantdev/warrant-js\n\nUse [Warrant](https://warrant.dev/) as an ES module.\n\n[![npm](https://img.shields.io/npm/v/@warrantdev/warrant-js)](https://www.npmjs.com/package/@warrantdev/warrant-js)\n\n## Installation\n\nUse `npm` to install the Warrant module:\n\n```sh\nnpm install @warrantdev/warrant-js\n```\n\n## Usage\n\nImport the Warrant client and pass a valid Config object to the constructor to get started:\n\n```js\nimport Warrant from \"@warrantdev/warrant-js\";\n\n// A valid session token is required to initialize the Client\nconst warrant = new Warrant({\n  clientKey: \"client_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=\",\n  sessionToken: \"sess_test_f9asdfASD90mkj2jXZIaeoqbIUAIjsJAHSAnsndW=\",\n});\n```\n\n### `check`\n\nThis function returns a `Promise` that resolves with `true` if the user for the current session token has the specified `warrant` and `false` otherwise.\n\n```js\nimport Warrant from \"@warrantdev/warrant-js\";\n\n// A valid session token is required to initialize the Client\nconst warrant = new Warrant({\n  clientKey: \"client_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=\",\n  sessionToken: \"sess_test_f9asdfASD90mkj2jXZIaeoqbIUAIjsJAHSAnsndW=\",\n});\n\n//\n// Example Scenario:\n// An e-commerce website where Store Owners can edit their own Store's info\n//\nwarrant.check({ object: myReport, relation: \"editor\" }).then((isAuthorized) =\u003e {\n  if (isAuthorized) {\n    // Carry out logic to allow user to edit a Store\n  }\n});\n```\n\nOr using async/await:\n\n```js\nimport Warrant from \"@warrantdev/warrant-js\";\n\n// A valid session token is required to initialize the Client\nconst warrant = new Warrant({\n  clientKey: \"client_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=\",\n  sessionToken: \"sess_test_f9asdfASD90mkj2jXZIaeoqbIUAIjsJAHSAnsndW=\",\n});\n\n//\n// Example Scenario:\n// An e-commerce website where Store Owners can edit their own Store's info\n//\nconst isAuthorized = await warrant.check({\n  object: myReport,\n  relation: \"editor\",\n});\nif (isAuthorized) {\n  // Carry out logic to allow user to edit a Store\n}\n```\n\n### `checkMany`\n\nThis function returns a `Promise` that resolves with `true` if the user for the current session token has `allOf` or `anyOf` (depending on the passed in `op`) the specified `warrants` and `false` otherwise.\n\n**CheckOp.AnyOf** specifies that the access check request will be authorized if _any of_ the warrants are matched and will not be authorized otherwise.\n\n**CheckOp.AllOf** specifies that the access check request will be authorized if _all of_ the warrants are matched and will not be authorized otherwise.\n\n```js\nimport Warrant, { CheckOp } from \"@warrantdev/warrant-js\";\n\n// A valid session token is required to initialize the Client\nconst warrant = new Warrant({\n  clientKey: \"client_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=\",\n  sessionToken: \"sess_test_f9asdfASD90mkj2jXZIaeoqbIUAIjsJAHSAnsndW=\",\n});\n\nwarrant\n  .checkMany({\n    op: CheckOp.AllOf,\n    warrants: [\n      {\n        object: tenantA,\n        relation: \"member\",\n      },\n      {\n        object: reportA,\n        relation: \"editor\",\n      },\n    ],\n  })\n  .then((isAuthorized) =\u003e {\n    if (isAuthorized) {\n      // Carry out logic if user is member of tenantA AND editor of reportA\n    }\n  });\n```\n\nOr using async/await:\n\n```js\nimport Warrant from \"@warrantdev/warrant-js\";\n\n// A valid session token is required to initialize the Client\nconst warrant = new Warrant({\n  clientKey: \"client_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=\",\n  sessionToken: \"sess_test_f9asdfASD90mkj2jXZIaeoqbIUAIjsJAHSAnsndW=\",\n});\n\nconst isAuthorized = await warrant.checkMany({\n  op: CheckOp.AllOf,\n  warrants: [\n    {\n      object: tenantA,\n      relation: \"member\",\n    },\n    {\n      object: reportA,\n      relation: \"editor\",\n    },\n  ],\n});\nif (isAuthorized) {\n  // Carry out logic if user is member of tenantA AND editor of reportA\n}\n```\n\n### `hasPermission`\n\nThis function returns a `Promise` that resolves with `true` if the user for the current session token has the specified permission and `false` otherwise.\n\n```js\nimport Warrant from \"@warrantdev/warrant-js\";\n\n// A valid session token is required to initialize the Client\nconst warrant = new Warrant({\n  clientKey: \"client_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=\",\n  sessionToken: \"sess_test_f9asdfASD90mkj2jXZIaeoqbIUAIjsJAHSAnsndW=\",\n});\n\nwarrant.hasPermission({ permissionId: \"view-items\" }).then((canViewItems) =\u003e {\n  if (canViewItems) {\n    // Carry out logic if user has permission view-items\n  }\n});\n```\n\nOr using async/await:\n\n```js\nimport Warrant from \"@warrantdev/warrant-js\";\n\n// A valid session token is required to initialize the Client\nconst warrant = new Warrant({\n  clientKey: \"client_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=\",\n  sessionToken: \"sess_test_f9asdfASD90mkj2jXZIaeoqbIUAIjsJAHSAnsndW=\",\n});\n\nconst canViewItems = await warrant.hasPermission({\n  permissionId: \"view-items\",\n});\nif (canViewItems) {\n  // Carry out logic if user has permission view-items\n}\n```\n\n### `hasFeature`\n\nThis function returns a `Promise` that resolves with `true` if the user for the current session token has the specified feature and `false` otherwise.\n\n```js\nimport Warrant from \"@warrantdev/warrant-js\";\n\n// A valid session token is required to initialize the Client\nconst warrant = new Warrant({\n  clientKey: \"client_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=\",\n  sessionToken: \"sess_test_f9asdfASD90mkj2jXZIaeoqbIUAIjsJAHSAnsndW=\",\n});\n\nwarrant.hasFeature({ featureId: \"save-items\" }).then((canSaveItems) =\u003e {\n  if (canSaveItems) {\n    // Carry out logic if user has feature save-items\n  }\n});\n```\n\nOr using async/await:\n\n```js\nimport Warrant from \"@warrantdev/warrant-js\";\n\n// A valid session token is required to initialize the Client\nconst warrant = new Warrant({\n  clientKey: \"client_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=\",\n  sessionToken: \"sess_test_f9asdfASD90mkj2jXZIaeoqbIUAIjsJAHSAnsndW=\",\n});\n\nconst canSaveItems = await warrant.hasFeature({ featureId: \"save-items\" });\nif (canSaveItems) {\n  // Carry out logic if user has feature save-items\n}\n```\n\nWe’ve used a random Client Key in these code examples. Replace it with your\n[actual publishable Client Key](https://app.warrant.dev) to\ntest this code through your own Warrant account.\n\nFor more information on how to use the Warrant API, please refer to the\n[Warrant API reference](https://docs.warrant.dev).\n\n## TypeScript support\n\nThis package includes TypeScript declarations for Warrant.\n\nNote that we may release new [minor and patch](https://semver.org/) versions of\n`@warrantdev/warrant-js` with small but backwards-incompatible fixes to the type\ndeclarations. These changes will not affect Warrant itself.\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-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwarrant-dev%2Fwarrant-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwarrant-dev%2Fwarrant-js/lists"}