How to append to dataset without read access with Inrupt solid-client-js

Hi everyone!

I’m still a bit new to solid, so let me know if this has already been answered

I’ve been working on a project using Inrupt’s solid-client-js library, and I have a feature where a user can subscribe to services from another user by adding their webId to a list on the second user’s pod. To do this, I’m using the list’s ACL to give the first user append access, but not read access. The list is stored as a ttl file. However, I can’t seem to find a great way to do this with the library.

My code looks something like this:

export const subscribeToUser = async (clientListUrl, myProfile) => {
  const {myWebId, myName} = myProfile;

  const thing = buildThing(createThing({ name: myName }))
    .addUrl(RDF_PREDICATES.identifier, myWebId)
    .build();

  let dataset = createSolidDataset();
  dataset = setThing(dataset, thing);
  await saveSolidDatasetAt(clientListUrl, dataset);
};

However, this code attempts to overwrite the existing list, not append to it, and it’s rejected because the user doesn’t have write access.

Inrupt’s docs suggest loading the dataset first with getSolidDataset, but that’s not possible because the user doesn’t have read access.

I’m able to work around this by using the mockSolidDatasetFrom function:

export const subscribeToUser = async (clientListUrl, myProfile) => {
  ...

  let dataset = mockSolidDatasetFrom(clientListUrl);
  dataset = setThing(dataset, thing);
  await saveSolidDatasetAt(datasetUrl, dataset);
};

This method correctly appends the thing, but the docs say not to use mockSolidDatasetFrom in production.

Has anyone found a good way to do this?

If you only have append access then all you will be able to do is issue a PATCH request without reading the file in advance; doing so is not currently supported by solid-client-js. Instead you can issue the PATCH request directly by calling the fetch function given to you by your session created form the solid-client-authn libraries.

You can see a sample patch request here

Comunica and rdflib.js also supports PATCH requests if you want to use those libraries.

2 Likes

If you only have append access then all you will be able to do is issue a PATCH request

That will only work if the patch does not contain a delete statement which requires Write permissions.

A POST request can also be issued with only Append permissions.

Ah ok that makes sense. I’ll give that shot. Thanks!

Thanks for the clarification. I’ve noticed I’m able to post new documents to a container, just not insert new values into documents.