{"_id":"@block65/canornot","_rev":"6-d9654af2fd5e8d0a39215233a0a962cd","name":"@block65/canornot","dist-tags":{"latest":"5.0.1"},"versions":{"3.0.0":{"name":"@block65/canornot","version":"3.0.0","license":"MIT","_id":"@block65/canornot@3.0.0","maintainers":[{"name":"maxholman","email":"max@holmn.com"},{"name":"block65-bot","email":"block65-bot@block65.com"}],"dist":{"shasum":"16d7bc6f5bff8620b90eab70b9dff0e223e79557","tarball":"https://registry.npmjs.org/@block65/canornot/-/canornot-3.0.0.tgz","fileCount":7,"integrity":"sha512-Mo3xGesBy5QqyOBaqBL1qgAIPyfaFZJTrs7AwSp2NrEOpp4c9fHz3nNf1D3wuHbdFj4VcyMfmXg2faYQNysl2A==","signatures":[{"sig":"MEUCIQDzAnjlhdt1loXzzDOtDLulZlClutfT0AsMejGalwv+pQIgHF4TSLQ8z0uQMm/dxLG/FjEJjWeiDRWb2MlSSqXyOJ0=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10053,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf33CwCRA9TVsSAnZWagAAW3gP/2M0u20/Zw/QP40teACy\nFiWKstE3vcrlrJLV6Wqp3lhHtzi90nGpzj8XeSWMeqKo2+z/Q0eaQsbqnHHD\nmVabPU1bT0TUKyKhK70Vfv2ToadMZUgGRd/d3SrCHkNgoqe3FLilo+Q/WOks\nZ7QaPAVwyJgXIZpCRQxcVVQQIsUfE+/V8dKymXUb2+hbONA1k7oPEENRBhiV\nZPJx3A3pgDQVJKmoj7zz6276U9oSI5ptGG8Rfiin+5HjSnGRZpxfgR6qzvRc\nWXXwNd2Gr1KjjfTbJN8x80IHy0G3AzVZtzJuP5ihIHTHnNFACYrPzN1jjn04\n8GrwrzvgnAucQetNkY4b9hAELTCeipasjhQZwOIHoGHEhVAdiic+kB2l/ZyI\n288g4ExhTUDIxtKgKWumJjmCL5lpPiRPUNrTdHPi788AQpq0rRXlVNUTneJ8\nUKtNkvnxH1CoECoqmn3niZAZYvf7wdTr1hv5kmvxVtl7JCC3rMmtix0sY3ih\nJL+bzIvZzu7VS9SreMHxGpx8ZY24UqZjAocYDTyIJqTJc27vB+96OFQ8cbfl\nPfD/ZUuc3XVj9/7iMNclUYgB9QEuAXppteQAI17zerDe539zZka+PKaB/wnV\nvW9W5tq/7krsw4VCeH2WTnjCx784ETQAHc0efPYOUqS4b/jefs45M5fXaVYW\nz7Id\r\n=yT1d\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","gitHead":"78ce4f34727ac21cbdc8417b657e4c383b01ca2c","scripts":{"test":"jest","build":"tsc","prepare":"yarn build:clean && yarn test && yarn build","build:clean":"rimraf dist/*","build:watch":"tsc -w"},"_npmUser":{"name":"block65-bot","email":"block65-bot@block65.com"},"deprecated":"This package is no longer maintained.","_npmVersion":"6.14.8","description":"An authorisation and access control library based on JSON Schema.","directories":{},"_nodeVersion":"14.15.1","dependencies":{"ajv":"^7.0.2","@block65/custom-error":"^2.0.8"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^26.6.3","eslint":"^7.15.0","rimraf":"^3.0.2","ts-jest":"^26.4.4","prettier":"^2.2.1","typescript":"^4.1.2","@types/jest":"^26.0.19","@types/node":"^14.14.14","@types/debug":"^4.1.5","@types/json-schema":"^7.0.6","eslint-plugin-react":"^7.21.5","eslint-plugin-import":"^2.22.1","@block65/eslint-config":"3.1.1","eslint-plugin-formatjs":"^2.9.10","eslint-plugin-prettier":"^3.2.0","@typescript-eslint/parser":"^4.10.0","eslint-plugin-react-hooks":"^4.2.0","@typescript-eslint/eslint-plugin":"^4.9.0"},"_npmOperationalInternal":{"tmp":"tmp/canornot_3.0.0_1608478895657_0.7916150365309618","host":"s3://npm-registry-packages"}},"4.0.0":{"name":"@block65/canornot","version":"4.0.0","license":"MIT","_id":"@block65/canornot@4.0.0","maintainers":[{"name":"maxholman","email":"max@holmn.com"},{"name":"block65-bot","email":"block65-bot@block65.com"}],"dist":{"shasum":"73e3250ac7d80ed9fcd5a130fb3fd4698bf58d56","tarball":"https://registry.npmjs.org/@block65/canornot/-/canornot-4.0.0.tgz","fileCount":7,"integrity":"sha512-FWvEfCZBdUvKG+EUj1EXmB/kGq43lXAB1zpXq/gwMvJL2Zbqm5Uo+A8ddrdDcUndn9qERto6YdhL6xC12+Mamw==","signatures":[{"sig":"MEUCIQDZl9m4CmariPZ64lIcUIAQJ91v/K2pUuB2RTL3n21bEwIgcMgbPou1RuSQXgTzJJW84UxF0WMTCG/3px4rwxOTMZs=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10106,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgmlj0CRA9TVsSAnZWagAATggP/iX/R3UbNRQ5Y4eeoVY3\nLzIjETWgdtQbJO9xkbXo0oR/4TWbp/zZB7G33vAnIckWK79fZlmMKW2Sp24R\nMNNSZr1E6hHHwCc55FDFWUyu7RuG0xL4ZncQY/GPaMNf0PNJqo3Q2udHf8HJ\nqw54Ng62aV/jZRy/T4dRm5LV+AiOwabFtvbwMf7hLiHYH1QlhoJ7JgL5VZSw\n3jD36DBP+e4KfAt3vNCN3FHhPJT1Sw6aIqMMyIGc6WdBqrLkpuOvC5u7ENo5\nbSlxQm+GdU1zDvk/vKh+TvFPVkCmbJhRB2AZHJl94n387JeiWUWNfaQFW/DC\ndHvGoj/RwH4dQdVnb47Qf1uI0aB64KjlLvc0sZbsrxiZ/+p2hK4RnKk81GJM\nJoX8uqTm1xvrOT6dbGYYrbVTrfpdlkmPTJLPCGyrhlf+rJFBqPu93Fp9aFLU\nk0ttDkwdVT5Ppj9hTHq1lDS1DsNVZ0/+L2GL5nUkjr/sjl8Sc6PQekTsIxt5\n4iRt8wdp929fvYLyR45QBl3VJvJF4WxuQ5H9MmyRoIpIfXjy+WCPu0BFg6vD\nrQ60a/aM6nBxNLept1fD0yzu/ajAkWwr3NoGYCBUanfI82EWQ6VIoWQaucfp\nhj5gyDejQzuhcTRD6C9HfswDJEI0oXLGM5c41lSMpLG2rukbUx+TpnV9Nxo0\novev\r\n=lGvL\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","gitHead":"84d2784f319f4e617af056406f8fe9a23f587ca0","scripts":{"test":"jest","build":"tsc","prepare":"yarn build:clean && yarn test && yarn build","build:clean":"rimraf dist/*","build:watch":"tsc -w"},"_npmUser":{"name":"block65-bot","email":"block65-bot@block65.com"},"deprecated":"This package is no longer maintained.","_npmVersion":"6.14.12","description":"An authorisation and access control library based on JSON Schema.","directories":{},"_nodeVersion":"14.16.1","dependencies":{"ajv":"^8.3.0","@block65/custom-error":"^3.0.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^26.6.3","eslint":"^7.26.0","rimraf":"^3.0.2","ts-jest":"^26.5.6","prettier":"^2.3.0","typescript":"^4.2.4","@types/jest":"^26.0.23","@types/node":"^15.0.2","@types/debug":"^4.1.5","@types/json-schema":"^7.0.7","eslint-plugin-react":"^7.23.2","eslint-plugin-import":"^2.22.1","@block65/eslint-config":"4.1.1","eslint-plugin-formatjs":"^2.15.0","eslint-plugin-prettier":"^3.4.0","@typescript-eslint/parser":"^4.23.0","eslint-plugin-react-hooks":"^4.2.0","@typescript-eslint/eslint-plugin":"^4.23.0"},"_npmOperationalInternal":{"tmp":"tmp/canornot_4.0.0_1620728051605_0.4856290331049289","host":"s3://npm-registry-packages"}},"5.0.1":{"name":"@block65/canornot","version":"5.0.1","license":"MIT","_id":"@block65/canornot@5.0.1","maintainers":[{"name":"maxholman","email":"max@holmn.com"},{"name":"block65-bot","email":"block65-bot@block65.com"}],"dist":{"shasum":"5d3bee3fa0f2e58a1a0bfa2ffc6d49580d0c2978","tarball":"https://registry.npmjs.org/@block65/canornot/-/canornot-5.0.1.tgz","fileCount":7,"integrity":"sha512-6pzeskg1rALL2LvZkY1ZHsFl9Jg9rgJJfjuobxw8pCtd+tXAuDEmtTiMIXPYmlf8EUWFGtgFJt0zzcj6GuiEGw==","signatures":[{"sig":"MEUCIAqi7L7At6+4jAS5kMx1yJIe1MlbyM0jF8ErzgBfcZoYAiEAmV+ckhLZxcUJM6e6BTtcpBiJS3dhdNoL1NNfl9XjhnE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":9416,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJieQjpACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqjNQ/+INo5kDYBggKElmcLlAb9eLlmWu1hnLejXxDjzfKNmlQ47SPM\r\ngeNh2rOdlkn/RO09s5sXaJ4KShMBAfwuf9wH2eIC9mXkydhM3f08GjBvzYHJ\r\nfjxUXkjOiAVr9x5IG8OFv6Vp0Q3fyXUkz/EKZsHaSgecyh2cMOygNU77qjsB\r\nrIH0GoeW/2mNzA6YMP17IcLcF0vA0h4k/rVaZXIddHf+ELpCtKTrRYPrcRpT\r\nCTMgbbGsS6xTLCfqLAG/6zzHRCKEGcoq6xotm1tOyIUamyMwf9585wkYpckb\r\nqPO0f4lQNtjvpqX6CVZKYrDm3nx/Ql8RvbxwsjFsi2M0CkOBXicRUTzj7jLc\r\nm+nGO/YuVdj+89hiXtElGxY7iEXjIfJ4sh847tqzM5ZsSbud2iVHFfpbSU8L\r\nFTJ/5TvU0ZSU2ifP3/VrfMxkmTmRr2Xl37yBj/UlxZ4Y3/vLWFa0dgYTdr8O\r\nJYy9PAkMbnoBqItXXYAHF5Pia41spwS7/zpk799FWodfyPe/PDrPqtLZKmoH\r\n/9drI1bJNwte2lv0dr1eTkRMk7MJa472kyeoswhEcMhxrdR9Eb+YgfeRhpPl\r\nmF0VgpVhOEB0G6eg7XTVmPJZnybsB5BFpflltQjHKCEvu9b1xi4Jpex6WqPe\r\naYgSeo5jzu3w9sq4KlnS0AhMgwOG9ZYAQ0M=\r\n=FLBX\r\n-----END PGP SIGNATURE-----\r\n"},"type":"module","engines":{"node":"^12.20.0 || ^14.13.1 || >=16.0.0"},"exports":{".":"./dist/lib/index.js"},"gitHead":"376125239e75c9063fcfd3d51d08bb4c00c8c4f6","_npmUser":{"name":"block65-bot","email":"block65-bot@block65.com"},"deprecated":"This package is no longer maintained.","_npmVersion":"8.5.5","description":"An authorisation and access control library based on JSON Schema.","directories":{},"_nodeVersion":"16.15.0","dependencies":{"ajv":"^8.11.0","@block65/custom-error":"^8.0.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^28.1.0","eslint":"^8.15.0","rimraf":"^3.0.2","prettier":"^2.6.2","typescript":"^4.7.0-dev.20220506","@babel/core":"^7.17.9","@types/node":"^17.0.31","@jest/globals":"^28.1.0","@babel/preset-env":"^7.16.11","@types/json-schema":"^7.0.11","eslint-plugin-import":"^2.26.0","@block65/eslint-config":"7.0.4","eslint-plugin-prettier":"^4.0.0","@babel/preset-typescript":"^7.16.7","@typescript-eslint/parser":"^5.22.0","@typescript-eslint/eslint-plugin":"^5.22.0"},"_npmOperationalInternal":{"tmp":"tmp/canornot_5.0.1_1652099305510_0.39799504077297443","host":"s3://npm-registry-packages"}}},"time":{"created":"2020-12-20T15:41:35.444Z","modified":"2026-09-15T09:40:17.445Z","3.0.0":"2020-12-20T15:41:35.833Z","4.0.0":"2021-05-11T10:14:11.787Z","5.0.1":"2022-05-09T12:28:25.631Z"},"license":"MIT","description":"An authorisation and access control library based on JSON Schema.","maintainers":[{"email":"max@holmn.com","name":"maxholman"}],"readme":"# canornot\n\nAn authorisation and access control library based on JSON Schema.\n\n### Install\n\n```bash\nyarn add @block65/canornot\n```\n\n### Usage\n\nExample ABAC module based on canornot\n\n#### abac.ts\n\nExports a function which takes a JWT, verifies it and then returns a `CanOrNot`\ninstance for the relevant user.\n\n```typescript\nimport { CanOrNot } from '@block65/canornot';\nimport type { JSONSchema7 } from 'json-schema';\nimport jsonwebtoken from 'jsonwebtoken';\nimport { datastore } from './lib/some-kind-of-datastore.js';\n\n// A policy that allows getting your own user details, and editing companies\n// in your list of company ids\nconst policySchema: JSONSchema7 = {\n  properties: {\n    'user:get': {\n      $ref: 'actor#/properties/userId',\n    },\n    'company:edit': {\n      $ref: 'actor#/properties/companyIds',\n    },\n  },\n};\n\n// Gets the actor schema with a little help from the datastore\nasync function getActorSchema(userId: string): Promise<JSONSchema7> {\n  const user = await datastore.fetchUserById(userId);\n\n  return {\n    $id: 'actor',\n    description: 'Actor Properties',\n    type: 'object',\n    additionalProperties: false,\n    properties: {\n      userId: {\n        type: 'number',\n        const: user.userId,\n      },\n      companyIds: {\n        type: 'number',\n        enum: [null, ...user.companyIds],\n      },\n    },\n  };\n}\n\nexport function createAbac(jwt: string): CanOrNot {\n  // Returns a CanOrNot instance with our user policy schema\n  // and an actor schema based on the decoded JWT details\n  // NOTE: These methods can (and should) be memoized to reduce latency\n  return new CanOrNot({\n    policySchema,\n    actorSchema() {\n      const decoded = jsonwebtoken.verify(jwt, 'secret123');\n      return getActorSchema(decoded.userId);\n    },\n  });\n}\n```\n\n#### index.ts\n\nExample use of the above ABAC module `abac.ts`\n\n```typescript\n// This is our ABAC module based on Canornot\nimport { createAbac } from './abac.js';\n\n// JWT may come from a HTTP header or similar\nconst jwt = 'eyJhbGciOiJIUz...NBjfe90nGM';\n\n// Create an ABAC instance using the JWT\nconst abac = createAbac(jwt);\n\n// Permission is allowed\nabac\n  .can('user:get', 12344)\n  .then(() => console.log('Permission allowed!'))\n  .catch(() => console.warn('Permission denied!'));\n\n// Permission is denied!\nabac\n  .can('user:get', 99999)\n  .then(() => console.log('Permission allowed!'))\n  .catch(() => console.warn('Permission denied!'));\n```\n","readmeFilename":"README.md"}