Skip to content

Commit

Permalink
[PATCH] docs:replace readable names with uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
sccalabr authored and ryanpq committed Nov 15, 2024
1 parent 1542c54 commit 8152446
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Updated to include support for [OpenFGA 0.3.0](https://github.com/openfga/openfg

Changes:
- [BREAKING] feat(list-objects)!: response has been changed to include the object type
e.g. response that was `{"object_ids":["roadmap"]}`, will now be `{"objects":["document:roadmap"]}`
e.g. response that was `{"object_ids":["roadmap"]}`, will now be `{"objects":["document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"]}`

Fixes:
- fix(models): update interfaces that had incorrectly optional fields to make them required
Expand Down
58 changes: 29 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,13 @@ Reads the relationship tuples stored in the database. It does not evaluate nor e
const body = {
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "viewer",
object: "document:roadmap",
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
};

// Find all relationship tuples where a certain user has any relation to a certain document
const body = {
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
object: "document:roadmap",
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
};

// Find all relationship tuples where a certain user is a viewer of any document
Expand All @@ -354,7 +354,7 @@ const body = {

// Find all relationship tuples where any user has any relation with a particular document
const body = {
object: "document:roadmap",
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
};

// Read all stored relationship tuples
Expand Down Expand Up @@ -383,13 +383,13 @@ const options = {};
options.authorizationModelId = "01GXSA8YR785C4FYS3C0RTG7B1";

await fgaClient.write({
writes: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:roadmap" }],
deletes: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "editor", object: "document:roadmap" }],
writes: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" }],
deletes: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "editor", object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" }],
}, options);

// Convenience functions are available
await fgaClient.writeTuples([{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:roadmap" }], options);
await fgaClient.deleteTuples([{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "editor", object: "document:roadmap" }], options);
await fgaClient.writeTuples([{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" }], options);
await fgaClient.deleteTuples([{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "editor", object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" }], options);

// if any error is encountered in the transaction mode, an error will be thrown
```
Expand All @@ -407,14 +407,14 @@ options.transaction = {
};
const response = await fgaClient.write({
writes: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:roadmap" }],
deletes: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "editor", object: "document:roadmap" }],
writes: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" }],
deletes: [{ user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "editor", object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a" }],
}, options);
/*
response = {
writes: [{ tuple_key: { user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:roadmap", status: "success" } }],
deletes: [{ tuple_key: { user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "editor", object: "document:roadmap", status: "failure", err: <FgaError ...> } }],
writes: [{ tuple_key: { user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "viewer", object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", status: "success" } }],
deletes: [{ tuple_key: { user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", relation: "editor", object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", status: "failure", err: <FgaError ...> } }],
};
*/
```
Expand All @@ -436,7 +436,7 @@ const options = {
const result = await fgaClient.check({
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "viewer",
object: "document:roadmap",
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
}, options);

// result = { allowed: true }
Expand All @@ -455,19 +455,19 @@ const options = {
const { responses } = await fgaClient.batchCheck([{
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "viewer",
object: "document:budget",
object: "document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5",
}, {
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "member",
object: "document:budget",
object: "document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5",
}, {
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "viewer",
object: "document:roadmap",
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
contextualTuples: [{
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "writer",
object: "document:roadmap"
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
}],
}], options);

Expand All @@ -477,26 +477,26 @@ responses = [{
_request: {
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "viewer",
object: "document:budget",
object: "document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5",
}
}, {
allowed: false,
_request: {
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "member",
object: "document:budget",
object: "document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5",
},
err: <FgaError ...>
}, {
allowed: true,
_request: {
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "viewer",
object: "document:roadmap",
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
contextualTuples: [{
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "writer",
object: "document:roadmap"
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
}],
}},
]
Expand All @@ -517,10 +517,10 @@ options.authorizationModelId = "01GXSA8YR785C4FYS3C0RTG7B1";

const { tree } = await fgaClient.expand({
relation: "viewer",
object: "document:roadmap",
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
}, options);

// tree = { root: { name: "document:roadmap#viewer", leaf: { users: { users: ["user:81684243-9356-4421-8fbf-a4f8d36aa31b", "user:f52a4f7a-054d-47ff-bb6e-3ac81269988f"] } } } }
// tree = { root: { name: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a#viewer", leaf: { users: { users: ["user:81684243-9356-4421-8fbf-a4f8d36aa31b", "user:f52a4f7a-054d-47ff-bb6e-3ac81269988f"] } } } }
```

##### List Objects
Expand All @@ -542,11 +542,11 @@ const response = await fgaClient.listObjects({
contextualTuples: [{
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "writer",
object: "document:budget"
object: "document:0192ab2d-d36e-7cb3-a4a8-5d1d67a300c5"
}],
}, options);

// response.objects = ["document:roadmap"]
// response.objects = ["document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"]
```

##### List Relations
Expand All @@ -563,12 +563,12 @@ options.authorization_model_id = "1uHxCSuTP0VKPYSnkq1pbb1jeZw";

const response = await fgaClient.listRelations({
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
object: "document:roadmap",
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
relations: ["can_view", "can_edit", "can_delete"],
contextualTuples: [{
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "writer",
object: "document:roadmap"
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
}],
}, options);

Expand Down Expand Up @@ -610,7 +610,7 @@ const response = await fgaClient.listUsers({
}, {
user: "folder:product",
relation: "parent",
object: "document:roadmap"
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
}]
}, options);

Expand All @@ -637,7 +637,7 @@ const response = await fgaClient.readAssertions(options);
response.assertions = [{
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "viewer",
object: "document:roadmap",
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
expectation: true,
}];
*/
Expand All @@ -658,7 +658,7 @@ options.authorizationModelId = "01GXSA8YR785C4FYS3C0RTG7B1";
const response = await fgaClient.writeAssertions([{
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "viewer",
object: "document:roadmap",
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
expectation: true,
}], options);
```
Expand Down
8 changes: 4 additions & 4 deletions example/example1/example1.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async function main () {
{
user: "user:anne",
relation: "writer",
object: "document:roadmap",
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
condition: {
name: "ViewCountLessThan200",
context: {
Expand Down Expand Up @@ -158,7 +158,7 @@ async function main () {
const { allowed } = await fgaClient.check({
user: "user:anne",
relation: "viewer",
object: "document:roadmap"
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
});
console.log(`Allowed: ${allowed}`);
} catch (error) {
Expand All @@ -173,7 +173,7 @@ async function main () {
const { allowed } = await fgaClient.check({
user: "user:anne",
relation: "viewer",
object: "document:roadmap",
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
context: {
ViewCount: 100
}
Expand All @@ -191,7 +191,7 @@ async function main () {
{
user: "user:carl",
relation: "writer",
object: "document:roadmap",
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
expectation: false
}
]);
Expand Down
8 changes: 4 additions & 4 deletions tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ describe("OpenFGA Client", () => {

describe("ListObjects", () => {
it("should call the api and return the response", async () => {
const mockedResponse = { objects: ["document:roadmap"] };
const mockedResponse = { objects: ["document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"] };
const scope = nocks.listObjects(baseConfig.storeId!, mockedResponse, undefined, ConsistencyPreference.HigherConsistency);

expect(scope.isDone()).toBe(false);
Expand All @@ -591,7 +591,7 @@ describe("OpenFGA Client", () => {
}, {
user: "folder:product",
relation: "parent",
object: "document:roadmap"
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
}]
}, {
authorizationModelId: "01GAHCE4YVKPQEKZQHT2R89MQV",
Expand Down Expand Up @@ -808,7 +808,7 @@ describe("OpenFGA Client", () => {
}, {
user: "folder:product",
relation: "parent",
object: "document:roadmap"
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
}]
}, {
authorizationModelId: "01GAHCE4YVKPQEKZQHT2R89MQV",
Expand Down Expand Up @@ -865,7 +865,7 @@ describe("OpenFGA Client", () => {
await fgaClient.writeAssertions([{
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "viewer",
object: "document:roadmap",
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
expectation: true,
}], { authorizationModelId: modelId });

Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/nocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export const getNocks = ((nock: typeof Nock) => ({
tuple_key: {
user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation: "viewer",
object: "document:roadmap"
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
},
operation: TupleOperation.Write,
timestamp: "2000-01-01T00:00:00Z"
Expand Down
4 changes: 2 additions & 2 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ describe("OpenFGA SDK", function () {

describe("listObjects", () => {
it("should call the api and return the response", async () => {
const mockedResponse = { objects: ["document:roadmap"] };
const mockedResponse = { objects: ["document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"] };
const scope = nocks.listObjects(baseConfig.storeId!, mockedResponse);

expect(scope.isDone()).toBe(false);
Expand All @@ -845,7 +845,7 @@ describe("OpenFGA SDK", function () {
}, {
user: "folder:product",
relation: "parent",
object: "document:roadmap"
object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
}]
}
});
Expand Down

0 comments on commit 8152446

Please sign in to comment.