@cerbos/orm-prisma
Advanced tools
Comparing version 0.1.2 to 0.1.4
@@ -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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
90
9840
2
7
6
179
+ Added@cerbos/grpc@^0.8.0
+ Added@cerbos/core@0.8.1(transitive)
+ Added@cerbos/grpc@0.8.2(transitive)
+ Added@grpc/grpc-js@1.12.5(transitive)
+ Added@grpc/proto-loader@0.7.13(transitive)
+ Added@js-sdsl/ordered-map@4.4.2(transitive)
+ Added@protobufjs/aspromise@1.1.2(transitive)
+ Added@protobufjs/base64@1.1.2(transitive)
+ Added@protobufjs/codegen@2.0.4(transitive)
+ Added@protobufjs/eventemitter@1.1.0(transitive)
+ Added@protobufjs/fetch@1.1.0(transitive)
+ Added@protobufjs/float@1.0.2(transitive)
+ Added@protobufjs/inquire@1.1.0(transitive)
+ Added@protobufjs/path@1.1.2(transitive)
+ Added@protobufjs/pool@1.1.0(transitive)
+ Added@protobufjs/utf8@1.1.0(transitive)
+ Added@types/long@4.0.2(transitive)
+ Added@types/node@22.10.2(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedcliui@8.0.1(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedlodash.camelcase@4.3.0(transitive)
+ Addedlong@4.0.05.2.3(transitive)
+ Addedprotobufjs@6.11.47.4.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedundici-types@6.20.0(transitive)
+ Addeduuid@9.0.1(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@21.1.1(transitive)