openfga / js-sdk

OpenFGA SDK for node.js and JavaScript - https://www.npmjs.com/package/@openfga/sdk
https://openfga.dev
Apache License 2.0
51 stars 14 forks source link

feat: support usage of the consistency option #129

Closed ewanharris closed 3 months ago

ewanharris commented 4 months ago

Description

This is an initial attempt at introducing support for the experimental consistency option in the relevant APIs, this is supported on the following APIs:

And the following SDK methods

When introducing this option to the OpenFGAClient class, we decided that this option fits better in the options object as opposed to the request object as it's more of an "override" choice akin to the existing model ID and store ID.

So the usage looks like so

const { allowed } = await fgaClient.check({
  user: "user:anne",
  relation: "viewer",
  object: "document:roadmap",
}, { consistency: ConsistencyPreference.HigherConsistency });

I think there is a question around the correct usage for batchCheck, in that instance should the consistency choice be per check or for the entire batchCheck, currently we have it for the entire batchCheck but personally I don't think this is ideal.

await fgaClient.batchCheck([{
  user: "user:anne",
  relation: "viewer",
  object: "document:roadmap",
}], { consistency: ConsistencyPreference.HigherConsistency });

References

Review Checklist

codecov-commenter commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 88.13%. Comparing base (78daf78) to head (bacbd79). Report is 5 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #129 +/- ## ========================================== + Coverage 88.08% 88.13% +0.04% ========================================== Files 19 19 Lines 999 1003 +4 Branches 149 150 +1 ========================================== + Hits 880 884 +4 Misses 82 82 Partials 37 37 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.