Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit 5dcb3d0

Browse files
authored
README: fix fromResult (#71)
It became part of the combined opts argument in 0.5.5. Signed-off-by: Stephan Renatus <stephan@styra.com>
1 parent 87db20c commit 5dcb3d0

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,9 @@ Assuming that the policy evaluates to
189189
you can turn it into a boolean result like this:
190190

191191
```ts
192-
const allowed = await opa.evaluate<any, boolean>(
193-
path,
194-
undefined,
195-
(r?: Result) => (r as Record<string, any>)["allowed"] ?? false,
196-
);
192+
const allowed = await opa.evaluate<any, boolean>(path, undefined, {
193+
fromResult: (r?: Result) => (r as Record<string, any>)["allowed"] ?? false,
194+
});
197195
console.log(allowed ? "allowed!" : "denied!");
198196
```
199197

@@ -223,26 +221,26 @@ router.get("/tickets/:id", [param("id").isInt().toInt()], async (req, res) => {
223221
In [StyraInc/opa-typescript-example-nestjs](https://github.com/StyraInc/opa-typescript-example-nestjs), we have an decorator-based API authorization example using `@styra/opa`:
224222

225223
```ts
226-
@Controller('cats')
227-
@AuthzQuery('cats/allow')
228-
@AuthzStatic({ resource: 'cat' })
224+
@Controller("cats")
225+
@AuthzQuery("cats/allow")
226+
@AuthzStatic({ resource: "cat" })
229227
export class CatsController {
230228
constructor(private catsService: CatsService) {}
231229

232230
@Post()
233-
@Authz(({ body: { name } }) => ({ name, action: 'create' }))
231+
@Authz(({ body: { name } }) => ({ name, action: "create" }))
234232
async create(@Body() createCatDto: CreateCatDto) {
235233
this.catsService.create(createCatDto);
236234
}
237235

238-
@Get(':name')
239-
@AuthzQuery('cats') // For illustration, we're querying the package extent
236+
@Get(":name")
237+
@AuthzQuery("cats") // For illustration, we're querying the package extent
240238
@Decision((r) => r.allow)
241239
@Authz(({ params: { name } }) => ({
242240
name,
243-
action: 'get',
241+
action: "get",
244242
}))
245-
async findByName(@Param('name') name: string): Promise<Cat> {
243+
async findByName(@Param("name") name: string): Promise<Cat> {
246244
return this.catsService.findByName(name);
247245
}
248246
}

0 commit comments

Comments
 (0)