@inrupt/solid-client-access-grants / resource

Module: resource#

Functions#

createContainerInContainer#

createContainerInContainer(containerUrl, accessGrant, options?): Promise<Readonly<{}> & WithResourceInfo>

Create an empty Container inside the Container at the given URL.

Throws an error if creating the Container failed, e.g. because the current user does not have permissions to. In particular, the Access Grant being used should at least append access to the target Container.

The Container in which to create the new Container should itself already exist.

This function is primarily useful if the current user does not have access to change existing files in a Container, but is allowed to add new files; in other words, they have Append, but not Write access to a Container. This is useful in situations where someone wants to allow others to, for example, send notifications to their Pod, but not to view or delete existing notifications. You can pass a suggestion for the new Resource’s name, but the server may decide to give it another name — for example, if a Resource with that name already exists inside the given Container. If the user does have access to write directly to a given location, createContainerAt will do the job just fine, and does not require the parent Container to exist in advance.

Parameters#

Name

Type

Description

containerUrl

string

URL of the Container in which the empty Container is to be created.

accessGrant

VerifiableCredential

The Access Grant that would allow the Agent/Application to perform this operation.

options?

SaveInContainerOptions

Optional parameter: - options.fetch: An alternative fetch function to make the HTTP request, compatible with the browser-native fetch API.

Returns#

Promise<Readonly<{}> & WithResourceInfo>

A promise that resolves to a SolidDataset with ResourceInfo if successful, and that rejects otherwise.

Since

2.1.0

Defined in#

src/resource/createContainerInContainer.ts:59


deleteFile#

deleteFile(fileUrl, accessGrant, options?): Promise<void>

Delete a File from a Solid Pod using an Access Grant to prove the caller is authorized to overwrite the target file.

Parameters#

Name

Type

Description

fileUrl

string

The URL of the target file.

accessGrant

VerifiableCredential

The Access Grant VC proving the caller is authorized.

options?

FetchOptions

Optional properties to customise the request behaviour.

Returns#

Promise<void>

A promise that resolves to a SolidDataset if successful, and that rejects otherwise.

See

@inrupt/solid-client’s deleteSolidDataset

Since

unreleased

Defined in#

src/resource/deleteFile.ts:42


deleteSolidDataset#

deleteSolidDataset(datasetUrl, accessGrant, options?): Promise<void>

Delete a Dataset from a Solid Pod using an Access Grant to prove the caller is authorized to overwrite the target dataset.

Parameters#

Name

Type

Description

datasetUrl

string

The URL of the target dataset.

accessGrant

VerifiableCredential

The Access Grant VC proving the caller is authorized.

options?

FetchOptions

Optional properties to customise the request behaviour.

Returns#

Promise<void>

A promise that resolves to a SolidDataset if successful, and that rejects otherwise.

See

@inrupt/solid-client’s deleteSolidDataset

Since

unreleased

Defined in#

src/resource/deleteSolidDataset.ts:42


getFile#

getFile(resourceUrl, accessGrant, options?): Promise<Blob & WithResourceInfo & {}>

Retrieve a File from a Solid Pod using an Access Grant to prove the caller is authorized to access the target resource.

Parameters#

Name

Type

Description

resourceUrl

string

The URL of the target resource.

accessGrant

VerifiableCredential

The Access Grant VC proving the caller is authorized.

options?

FetchOptions

Optional properties to customise the request behaviour.

Returns#

Promise<Blob & WithResourceInfo & {}>

A promise that resolves to a File if successful, and that rejects otherwise.

See

@inrupt/solid-client’s getFile

Since

0.4.0

Defined in#

src/resource/file.ts:47


getSolidDataset#

getSolidDataset(datasetUrl, accessGrant, options?): Promise<Readonly<{}> & WithResourceInfo & {}>

Retrieve a Dataset from a Solid Pod using an Access Grant to prove the caller is authorized to access the target dataset.

Parameters#

Name

Type

Description

datasetUrl

string

The URL of the target dataset.

accessGrant

VerifiableCredential

The Access Grant VC proving the caller is authorized.

options?

FetchOptions

Optional properties to customise the request behaviour.

Returns#

Promise<Readonly<{}> & WithResourceInfo & {}>

A promise that resolves to a SolidDataset if successful, and that rejects otherwise.

See

@inrupt/solid-client’s getSolidDataset

Since

0.4.0

Defined in#

src/resource/getSolidDataset.ts:42


overwriteFile#

overwriteFile<T>(resourceUrl, file, accessGrant, options?): Promise<T & WithResourceInfo>

Overwrites the file using an Access Grant to prove the caller is authorized to write to the given resource URL.

Note

This function does not support saving a file if the file does not yet exist, unlike its @inrupt/solid-client counterpart. To save a new file in a container, you should use saveFileInContainer instead.

Type parameters#

Name

Type

T

extends File | File

Parameters#

Name

Type

Description

resourceUrl

string

The URL where the file is located.

file

T

The file to be written.

accessGrant

VerifiableCredential

The Access Grant VC proving the caller is authorized.

options?

FetchOptions & { contentType?: string }

Optional properties to customise the request behaviour, or override the Content-Type of the file.

Returns#

Promise<T & WithResourceInfo>

A promise that resolves to a File if successful, and that rejects otherwise.

See

@inrupt/solid-client’s overwriteFile

Since

1.1.0

Defined in#

src/resource/file.ts:90

overwriteFile<T>(resourceUrl, file, accessGrant, options?): Promise<T & WithResourceInfo>

Type parameters#

Name

Type

T

extends File | Buffer | File

Parameters#

Name

Type

resourceUrl

string

file

T

accessGrant

VerifiableCredential

options?

FetchOptions & { contentType?: string }

Returns#

Promise<T & WithResourceInfo>

Deprecated

overwriteFile should only have File input

Defined in#

src/resource/file.ts:99


saveFileInContainer#

saveFileInContainer<T>(containerUrl, file, accessGrant, options?): Promise<T & WithResourceInfo>

Saves a file in the given container URL using an Access Grant to prove the caller is authorized to save a file in the given container.

Type parameters#

Name

Type

T

extends File | File

Parameters#

Name

Type

Description

containerUrl

string

The container URL where the file is to be saved.

file

T

The file to be written.

accessGrant

VerifiableCredential

The Access Grant VC proving the caller is authorized.

options?

FetchOptions & { contentType?: string ; slug?: string }

Optional properties to customise the request behaviour, or override the Content-Type of the file.

Returns#

Promise<T & WithResourceInfo>

A promise that resolves to a File if successful, and that rejects otherwise.

See

@inrupt/solid-client’s saveFileInContainer

Since

1.1.0

Defined in#

src/resource/file.ts:149

saveFileInContainer<T>(containerUrl, file, accessGrant, options?): Promise<T & WithResourceInfo>

Type parameters#

Name

Type

T

extends File | Buffer | File

Parameters#

Name

Type

containerUrl

string

file

T

accessGrant

VerifiableCredential

options?

FetchOptions & { contentType?: string ; slug?: string }

Returns#

Promise<T & WithResourceInfo>

Deprecated

saveFileInContainer should only have File input; not Buffer

Defined in#

src/resource/file.ts:158


saveSolidDatasetAt#

saveSolidDatasetAt<Dataset>(datasetUrl, solidDataset, accessGrant, options?): Promise<Dataset & WithResourceInfo & {} & Readonly<{}> & {}>

Saves a Dataset in a Solid Pod using an Access Grant to prove the caller is authorized to write or append to the dataset at the given dataset URL.

Note

This function does not support saving a dataset if the dataset does not yet exist, unlike its @inrupt/solid-client counterpart.

Type parameters#

Name

Type

Dataset

extends Readonly<{}>

Parameters#

Name

Type

Description

datasetUrl

string

The URL of the dataset to save.

solidDataset

Dataset

-

accessGrant

VerifiableCredential

The Access Grant VC proving the caller is authorized.

options?

FetchOptions

Optional properties to customise the request behaviour.

Returns#

Promise<Dataset & WithResourceInfo & {} & Readonly<{}> & {}>

A promise that resolves to a SolidDataset if successful, and that rejects otherwise.

See

@inrupt/solid-client’s saveSolidDatasetAt

Since

0.4.0

Defined in#

src/resource/saveSolidDatasetAt.ts:47


saveSolidDatasetInContainer#

saveSolidDatasetInContainer(containerUrl, solidDataset, accessGrant, options): Promise<Readonly<{}> & WithResourceInfo>

Given a SolidDataset, store it in a Solid Pod as a new Resource inside a Container.

The Container at the given URL should already exist; if it does not, you can initialise it first using createContainerAt, or directly save the SolidDataset at the desired location using resource.saveSolidDatasetAt.

This function is primarily useful if the current user has not been granted access to change existing files in a Container, but is allowed to add new files; in other words, they have been granted Append, but not Write access to a Container. This is useful in situations where someone wants to allow others to, for example, send notifications to their Pod, but not to view or delete existing notifications. You can pass a suggestion for the new Resource’s name, but the server may decide to give it another name — for example, if a Resource with that name already exists inside the given Container. If the user does have access to write directly to a given location, resource.saveSolidDatasetAt will do the job just fine, and does not require the parent Container to exist in advance.

Parameters#

Name

Type

Description

containerUrl

string

URL of the Container in which to create a new Resource.

solidDataset

Readonly<{}>

The SolidDataset to save to a new Resource in the given Container.

accessGrant

VerifiableCredential

The Access Grant that would allow the Agent/Application to perform this operation.

options

SaveInContainerOptions

Optional parameter options.fetch: An alternative fetch function to make the HTTP request, compatible with the browser-native fetch API.

Returns#

Promise<Readonly<{}> & WithResourceInfo>

A Promise resolving to a SolidDataset containing the saved data. The Promise rejects if the save failed.

See

@inrupt/solid-client’s saveSolidDatasetInContainer

Since

2.1.0

Defined in#

src/resource/saveSolidDatasetInContainer.ts:60