Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cerbos/orm-prisma

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cerbos/orm-prisma - npm Package Compare versions

Comparing version 0.1.2 to 0.1.4

4

lib/cjs/index.js

@@ -64,3 +64,3 @@ "use strict";

break;
case "lte":
case "le":
output[getFieldName(getOperandName(operands))] = {

@@ -70,3 +70,3 @@ lte: getOperandValue(operands),

break;
case "gte":
case "ge":
output[getFieldName(getOperandName(operands))] = {

@@ -73,0 +73,0 @@ gte: getOperandValue(operands),

@@ -61,3 +61,3 @@ import { PlanKind } from "@cerbos/core";

break;
case "lte":
case "le":
output[getFieldName(getOperandName(operands))] = {

@@ -67,3 +67,3 @@ lte: getOperandValue(operands),

break;
case "gte":
case "ge":
output[getFieldName(getOperandName(operands))] = {

@@ -70,0 +70,0 @@ gte: getOperandValue(operands),

{
"name": "@cerbos/orm-prisma",
"version": "0.1.2",
"version": "0.1.4",
"homepage": "https://cerbos.dev",

@@ -18,3 +18,4 @@ "description": "",

"postversion": "git push && git push --tags",
"test": "jest src/**.test.ts"
"test": "npx prisma db push --force-reset && cerbos run --log-level=error --set=storage.disk.directory=../policies --set=telemetry.disabled=true -- jest src/**.test.ts",
"cerbos": "cerbos server --config=./cerbos-config.yaml"
},

@@ -24,3 +25,6 @@ "author": "Cerbos",

"devDependencies": {
"@types/jest": "^29.0.0",
"@prisma/client": "^4.3.1",
"@types/jest": "^29.0.3",
"@types/node": "^18.7.21",
"prisma": "^4.3.1",
"ts-jest": "^28.0.8",

@@ -31,4 +35,5 @@ "ts-node": "^10.4.0",

"dependencies": {
"@cerbos/core": "^0.5.1"
"@cerbos/core": "^0.5.1",
"@cerbos/grpc": "^0.8.0"
}
}

@@ -9,2 +9,3 @@ # Cerbos + Prisma ORM Adapter

- Cerbos > v0.16
- `@cerbos/http` or `@cerbos/grpc` client

@@ -25,20 +26,63 @@ ## Usage

A basic implementation can be as simple as:
```js
import { GRPC as Cerbos } from "@cerbos/grpc";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
const cerbos = new Cerbos("localhost:3592", { tls: false });
// Fetch the query plan from Cerbos passing in the principal
// resource type and action
const queryPlan = await cerbos.planResources({
principal: {....},
resource: { kind: "resourceKind" },
action: "view"
})
// Generate the prisma filter from the query plan
const filters = queryPlanToPrisma({
queryPlan,
fieldNameMapper: {
"request.resource.attr.aFieldName": "prismaModelFieldName"
}
});
// Pass the filters in as where conditions
// If you have prexisting where conditions, you can pass them in an AND clause
const result = await prisma.myModel.findMany({
where: {
AND: filters
},
});
console.log(result)
```
The `fieldNameMapper` is used to convert the field names in the query plan response to names of fields in the Prisma model - this can be done as a map or a function:
```js
{
"request.resource.attr.aFieldName": "prismaModelFieldName"
}
const filters = queryPlanToPrisma({
queryPlan,
fieldNameMapper: {
"request.resource.attr.aFieldName": "prismaModelFieldName"
}
});
//or
(fieldName: string): string => {
if(fieldName.indexOf("request.resource.") > 0) {
return fieldName.replace("request.resource.attr", "")
}
const filters = queryPlanToPrisma({
queryPlan,
fieldNameMapper: (fieldName: string): string => {
if(fieldName.indexOf("request.resource.") > 0) {
return fieldName.replace("request.resource.attr", "")
}
if(fieldName.indexOf("request.principal.") > 0) {
return fieldName.replace("request.principal.attr", "")
if(fieldName.indexOf("request.principal.") > 0) {
return fieldName.replace("request.principal.attr", "")
}
}
}
});
```

@@ -45,0 +89,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc