A suite of libraries to make NestJS and Ory fall in love
Installations
npm install @getlarge/keto-client-wrapper
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
22.12.0
NPM Version
10.9.0
Releases
keto-cli@0.2.9
Published on 01 Feb 2025
keto-client-wrapper@0.6.0
Published on 01 Feb 2025
keto-cli@0.2.8
Published on 12 Nov 2024
keto-client-wrapper@0.5.0
Published on 12 Nov 2024
keto-cli@0.2.7
Published on 06 Nov 2024
keto-client-wrapper@0.4.0
Published on 06 Nov 2024
Contributors
Languages
TypeScript (94.08%)
JavaScript (5.52%)
Dockerfile (0.4%)
Developer
getlarge
Download Statistics
Total Downloads
8,492
Last Day
5
Last Week
90
Last Month
309
Last Year
8,276
GitHub Statistics
15 Stars
215 Commits
1 Watching
10 Branches
1 Contributors
Package Meta Information
Latest Version
0.6.0
Package Id
@getlarge/keto-client-wrapper@0.6.0
Unpacked Size
78.66 kB
Size
15.89 kB
File Count
54
NPM Version
10.9.0
Node Version
22.12.0
Publised On
01 Feb 2025
Total Downloads
Cumulative downloads
Total Downloads
8,492
Last day
-77.3%
5
Compared to previous day
Last week
-25.6%
90
Compared to previous week
Last month
67%
309
Compared to previous month
Last year
3,731.5%
8,276
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
4
Peer Dependencies
5
keto-client-wrapper
This library is a wrapper around the Ory Keto client - @ory/client. It provides :
OryRelationshipsModule
: a module to interact with the Ory Keto Relationships APIOryPermissionsModule
: a module to interact with the Ory Keto Permissions APIOryAuthorizationGuard
: a guard to protect your routes based on the Ory Keto permissions
Install
1npm install @getlarge/keto-client-wrapper
Usage
Import the module in your app:
1import { 2 OryRelationshipsModule, 3 OryPermissionsModule, 4} from '@getlarge/keto-client-wrapper'; 5import { Module } from '@nestjs/common'; 6 7@Module({ 8 imports: [ 9 OryRelationshipsModule.forRoot({ 10 basePath: 'http://localhost:4467', 11 accessToken: 'my-access-token', 12 }), 13 OryPermissionsModule.forRootAsync({ 14 useFactory: () => ({ 15 baseUrl: 'http://localhost:4466', 16 }), 17 }), 18 ], 19}) 20
Inject the service in your provider:
1import { OryRelationshipsService } from '@getlarge/keto-client-wrapper'; 2import { Injectable } from '@nestjs/common'; 3 4@Injectable() 5export class YourService { 6 constructor( 7 private readonly oryRelationshipsService: OryRelationshipsService 8 ) {} 9}
Use the Guard to protect your routes:
1import { 2 OryAuthorizationGuard, 3 OryPermissionChecks, 4} from '@getlarge/keto-client-wrapper'; 5import { RelationTupleBuilder } from '@getlarge/keto-relations-parser'; 6import { Controller, Get, Logger, UseGuards } from '@nestjs/common'; 7 8@Controller() 9export class YourController { 10 @OryPermissionChecks((ctx) => { 11 const req = ctx.switchToHttp().getRequest(); 12 const currentUserId = req.headers['x-current-user-id'] as string; 13 const resourceId = req.params.id; 14 return new RelationTupleBuilder() 15 .subject('User', currentUserId) 16 .isIn('owners') 17 .of('Toy', resourceId) 18 .toString(); 19 }) 20 @UseGuards( 21 OryAuthorizationGuard({ 22 postCheck(relationTuple, isPermitted) { 23 Logger.log('relationTuple', relationTuple); 24 Logger.log('isPermitted', isPermitted); 25 }, 26 }) 27 ) 28 @Get() 29 getArticles() { 30 return 'Articles'; 31 } 32}
Development
Building
Run nx build keto-client-wrapper
to build the library.
Running unit tests
Run nx test keto-client-wrapper
to execute the unit tests via Jest.
No vulnerabilities found.
No security vulnerabilities found.