TBD54566975 / web5-js

Monorepo for the Web5 JS TypeScript implementation
https://tbd54566975.github.io/web5-js/
Apache License 2.0
127 stars 48 forks source link

messaging test: protocolPath required as well as protocol #82

Closed michaelneale closed 1 year ago

michaelneale commented 1 year ago

Trying to setup a simple protocol like:

    var simpleMessageProtocol = {
      "protocol": "http://simple-messaging-protocol.xyz",
      "types": {
        "message": {
          "schema": "http://simple-messaging-protocol.xyz/schemas/message",
          "dataFormats": ["text/plain"]
        },
        "messageResponse": {
          "schema": "http://simple-messaging-protocol.xyz/schemas/message-response",
          "dataFormats": ["text/plain"]
        }
      },
      "structure": {
        "message": {
          "$actions": [
            {
              "who": "anyone",
              "can": "write"
            }
          ],
          "messageResponse": {
            "$actions": [
              {
                "who": "recipient",
                "of": "message",
                "can": "write"
              }
            ]
          }
        }
      }
    };

    var { protocol, status } = await web5.dwn.protocols.configure({
      message: {
        definition: simpleMessageProtocol
      }
    });

and trying to use that protocol:

    const { record } = await web5.dwn.records.create({
      to: client2,
      data: "Hello World!",
      message: {
        protocol: "http://simple-messaging-protocol.xyz",
        schema: "mic/sample"
      },
    });
    var { status } = await record.send(client2);
    console.log(status);

I get an error: records-write.ts:148 Uncaught Error:protocolandprotocolPathmust both be defined or undefined at the same time

What is a protocolPath?

michaelneale commented 1 year ago

I was able to look at code and see it would be message (would be nice to document that somewhere).

I then simplified my protocol:

    var simpleMessageProtocol = {
      "protocol": "http://simple-messaging-protocol3.xyz",
      "types": {
        "message": {
          "schema": "http://simple-messaging-protocol3.xyz/schemas/message",
          "dataFormats": ["text/plain"]
        },
        "messageResponse": {
          "schema": "http://simple-messaging-protocol3.xyz/schemas/message-response",
          "dataFormats": ["text/plain"]
        }
      },
      "structure": {
        "message": {
          "$actions": [
            {
              "who": "anyone",
              "can": "write"
            },
            {
              "who": "recipient",
              "of": "message",
              "can": "read"
            }
          ],
        }
      }
    };

And was able to send from one user:

const { record } = await web5.dwn.records.create({
  data: "Hello World!",
  message: {
    protocol: "http://simple-messaging-protocol3.xyz",
    schema: "http://simple-messaging-protocol3.xyz/schemas/message",
    protocolPath: "message"

  },
});

var { status } = await record.send(client2);
console.log(status);

which was accepted.

however, when I tried to query it from another client (client2) (that it was sent to) with the following code:

    // This invocation will query the user's own DWeb Nodes
    const { records } = await web5.dwn.records.query({
      message: {
        filter: {
          protocol: "http://simple-messaging-protocol3.xyz",
        },
      },
    });

    console.log(records); 

results in no results and:

web5.ts:149 Sync failed due to error: Error: TODO: message not found at bve. (sync-api.ts:348:13) at Generator.next () at a (sync-api.ts:17:23)

michaelneale commented 1 year ago

here is some test code - run it at 2 seperate URLs so they get their own dids: https://gist.github.com/michaelneale/2e1e1a50444c5272784b29b7d457a414