Skip to content

Commit 5e31a6f

Browse files
committed
Update caveat context writing documentation
1 parent 7df7eae commit 5e31a6f

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,43 @@ const results = await promiseClient.readRelationships(/** req **/);
140140
console.log(results[0]); // first ReadRelationship result
141141
```
142142

143+
## Writing Caveats
144+
145+
When writing caveat context to a relation, we've observed that you need to use
146+
the `Struct` object bundled with `authzed-node`, rather than importing it from
147+
the `google-protobuf` package. If you don't use the `authzed-node` version,
148+
writing context will fail silently and the relations won't reflect the context.
149+
150+
An example:
151+
152+
```js
153+
import { protobuf } from '@authzed/authzed-node';
154+
const { Struct } = protobuf;
155+
156+
const writeRequest = WriteRelationshipsRequest.create({
157+
updates: [
158+
RelationshipUpdate.create({
159+
relationship: Relationship.create({
160+
resource: resource,
161+
relation: "caveated_viewer",
162+
subject: SubjectReference.create({
163+
object: testUser,
164+
}),
165+
optionalCaveat: ContextualizedCaveat.create({
166+
caveatName: "has_special_attribute",
167+
context: Struct.fromJson({
168+
special: true,
169+
}),
170+
}),
171+
}),
172+
operation: RelationshipUpdate_Operation.CREATE,
173+
}),
174+
],
175+
});
176+
177+
const response = await client.writeRelationships(writeRequest);
178+
```
179+
143180
## Requirements
144181

145182
Supported Node.js versions: 18, 20, 22

0 commit comments

Comments
 (0)