{"id":15020862,"url":"https://github.com/bjerkio/nestjs-oso","last_synced_at":"2025-04-06T23:18:06.025Z","repository":{"id":37088475,"uuid":"316807671","full_name":"bjerkio/nestjs-oso","owner":"bjerkio","description":"Simplify implementation of oso with NestJS.","archived":false,"fork":false,"pushed_at":"2025-03-17T12:37:39.000Z","size":589,"stargazers_count":39,"open_issues_count":14,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T21:06:29.217Z","etag":null,"topics":["decorator","library","nestjs","oso","register"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bjerkio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2020-11-28T19:32:14.000Z","updated_at":"2025-03-21T09:00:27.000Z","dependencies_parsed_at":"2023-09-23T09:56:31.319Z","dependency_job_id":"7f3caf18-aabe-4d25-82aa-76ab06c7136f","html_url":"https://github.com/bjerkio/nestjs-oso","commit_stats":{"total_commits":191,"total_committers":12,"mean_commits":"15.916666666666666","dds":0.6073298429319371,"last_synced_commit":"d9c87d95fce7c3bdca6255fd4ca8368a9a5c643e"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjerkio%2Fnestjs-oso","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjerkio%2Fnestjs-oso/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjerkio%2Fnestjs-oso/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjerkio%2Fnestjs-oso/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bjerkio","download_url":"https://codeload.github.com/bjerkio/nestjs-oso/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247563943,"owners_count":20958971,"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":["decorator","library","nestjs","oso","register"],"created_at":"2024-09-24T19:55:46.631Z","updated_at":"2025-04-06T23:18:05.998Z","avatar_url":"https://github.com/bjerkio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NestJS OSO – Authorization code for NestJS\n\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square)](http://commitizen.github.io/cz-cli/)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)\n![Release](https://github.com/bjerkio/nestjs-oso/workflows/Release/badge.svg)\n\n[![codecov](https://codecov.io/gh/bjerkio/nestjs-oso/branch/main/graph/badge.svg)](https://codecov.io/gh/bjerkio/nestjs-oso)\n[![Maintainability](https://api.codeclimate.com/v1/badges/85ecf3895e428d2c3064/maintainability)](https://codeclimate.com/github/bjerkio/nestjs-oso/maintainability)\n\n\u003e [oso][] is an open-source policy engine for authorization that’s embedded in\n\u003e your application. It provides a declarative policy language for expressing\n\u003e authorization logic. You define this logic separately from the rest of your\n\u003e application code, but it executes inside the application and can call directly\n\u003e into it.\n\n`nestjs-oso` is a library that simplifies the implementation of [oso][] with\n[NestJS][nest].\n\n## Features\n\n- **@OsoClass** decorator (automatically registers the class to use within Oso)\n- **OsoService** (a ready to use NestJS service)\n\n## Quickstart\n\n```shell\n▶ yarn add nestjs-oso oso\n```\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { OsoModule } from 'nestjs-oso';\n\n@Module({\n  imports: [\n    OsoModule.forRoot({\n      loadFiles: ['./permissions.polar'],\n      // or multiple files\n      // loadFiles: ['./permissions.polar', './other-policies.polar'],\n      // or using wildcards\n      // loadFiles: ['./**/*.polar']\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n**Tip:** You don't have to apply either `loadFiles` or `loadStr`. You can inject\n`OsoService` and access the original API for oso anytime!\n\n### Example\n\nYou can easily inject `OsoService` to be used in your services, controllers,\netc.\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { OsoService } from 'nestjs-oso';\n\n@Injectable()\nexport class AuthService {\n  constructor(private oso: OsoService) {}\n  /*\n    Implementation that makes use of this.oso\n  */\n}\n```\n\nTo register an class with `oso`, use the decorator:\n\n```typescript\nimport { OsoClass } from 'nestjs-oso';\n\n@OsoClass()\nexport class User {\n  id: string;\n}\n```\n\nThis will automatically be registered using `registerClass` function in `oso`.\n\n### Add Polar files to `assets` in `nest-cli.json`\n\nIn the `nest-cli.json` file, we add the `assets` property to distribute non-Typescript\nfiles and watchAssets to turn on watching all non-Typescript assets. In our case, we\nprobably want to add `*.polar` files to be automatically copied to the `dist` folder\nand reloaded when changed.\n\nYou can find an example in [osohq/oso-nest-doc-mgmt](https://github.com/osohq/oso-nest-doc-mgmt/blob/main/nest-cli.json).\n\n```json\n{\n  \"compilerOptions\": {\n    \"assets\": [\"**/*.polar\"],\n    \"watchAssets\": true\n  }\n}\n\n```\n\n## Contribute \u0026 Disclaimer\n\nWe love to get help 🙏 Read more about how to get started in\n[CONTRIBUTING](CONTRIBUTING.md) 🌳\n\n[oso]: https://github.com/osohq/oso\n[nest]: https://github.com/nestjs/nest\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjerkio%2Fnestjs-oso","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbjerkio%2Fnestjs-oso","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjerkio%2Fnestjs-oso/lists"}