v1 WriteRelationshipsRequest create
# spicedb
h
v1.WriteRelationshipsRequest.create({ updates: [ v1.RelationshipUpdate.create({ relationship: v1.Relationship.create({ resource: v1.ObjectReference.create({ objectType: "caveat_feature", objectId: "column_edit", }), relation: "accessor", subject: v1.SubjectReference.create({ object: v1.ObjectReference.create({ objectType: "user", objectId: "user17", }), }), optionalCaveat: v1.ContextualizedCaveat.create({ caveatName: "has_valid_attribute", context: {"allowed":"last_reset_time"}, }), }), operation: v1.RelationshipUpdate_Operation.CREATE, }), ], }); for above relationship I am running following assertion which I am expecting to be true but always returns false instead const checkPermissionRequest = v1.CheckPermissionRequest.create({ resource: v1.ObjectReference.create({ objectType: "caveat_feature", objectId: "column_edit", }), permission: "access", subject: v1.SubjectReference.create({ object: v1.ObjectReference.create({ objectType: "user", objectId: "user17", }), }), context:{provided:"last_reset_time"}
v
I'm missing context here, can you share the schema? could you reproduce your issue via the playground so it's easier for me to jump and troubleshoot?
h
sure
this works fine with playground. Same if I am trying to verify with nodejs code using provided library that validation return false instead of true
I suspect I have messed up something while providing context key in both writerelationship and checkpermisiion
@vroldanbet ?
FYI: It always throw this result on CheckPermissionResponse { permissionship: 3, checkedAt: { token: 'GhUKEzE2OTQwMDczMTc0NTkwMTMwMDA=' }, partialCaveatInfo: { missingRequiredContext: [ 'allowed' ] } } Any hint why partialCaveatInfo: { missingRequiredContext: [ 'allowed' ] } this line ?
j
Context is a structpb
Not a JSON object
You’re not writing the key successfully in the write
h
I got it but I am using nodejs sdk instead and in js there is no support of structpb!!! it golangish thing
j
it should be generated as part of the API
we use it in Playground in TS
h
I am using https://www.npmjs.com/package/@authzed/authzed-node this is official sdk for nodejs. I am not sure what does it mean by "**it should be generated as part of the AP**I"
h
Now I am passin it as : context: protobuf.Struct.create({allowed:"last_reset_time"}) but getting same response
import { v1 ,protobuf} from "@authzed/authzed-node";
j
use
zed --explain
to see
h
Copy code
context: {
            kind: {
              oneofKind: "structValue",
              structValue: {
                fields: {
                  allowed: {
                    kind: {
                      oneofKind: "stringValue",
                      stringValue: "last_reset_time",
                    },
                  },
                },
              },
            },
          }
I have tried all possible ways to write context referring struct.ts file but no success everytime same response partialCaveatInfo: { missingRequiredContext: [ 'allowed' ] }
Finally it worked with :
Copy code
context: protobuf.Struct.create({
    fields: {
      provided: {
        kind: { oneofKind: "stringValue", stringValue: "last_reset_time" },
      },
    },
  })
It feels like so much boilerplate code as a seasonal js developer just to specify normal struct object!!
j
it is, yes
its a downside of protocol buffers not supporting proper arbitrary maps
we're working on client lib support to make it easier
h
Ok. thanks. Is there any planned roadmap from your end to when you're planning to release client lib support to make it easier? For now we are thinking of creating some abstraction layer on top of currently exposed methods to make it little bit easier to consume at application level
j
nothing concrete yet
its still in the early discussion phases
2 Views