Skip to content

@activitypods/refine-providers

The auth, data and live providers to connect a Refine app to ActivityPods Pods. It requires @refinedev/core 5. See the auth provider and data provider pages for usage examples.

authProvider

Create a Refine auth provider using the Solid-OIDC flow.

const apAuthProvider = authProvider({ clientId: 'http://localhost:3001/app' });

Options

PropertyTypeDefaultDescription
clientIdStringrequiredURI of the app, used as the Solid-OIDC client_id
redirectUriString${origin}/loginURL where the Pod provider redirects after login. It must be one of the redirectUris declared by the app
allowAnonymousBooleanfalseIf false, check() redirects to /login when there is no session
appStatusCheckIntervalNumber | false120000Interval in ms between checks of the access needs, also done when the tab becomes visible. Pass false if you use BackgroundChecks

Refine methods

MethodDescription
login(params)Redirect to the Pod provider. See the parameters below
register(params)Same as login, with the signup form of the Pod provider
logout()Remove the session stored in the browser and redirect to /login
check()Tell if there is a valid session
onError(error)Log out the user if the error status is 401
getIdentity()Return the identity of the user
getPermissions()Always return undefined

The parameters of login and register are:

PropertyTypeDefaultDescription
issuerStringrequiredBase URL of the Pod provider
redirectString/Path to redirect to once logged in
isSignupBooleanfalseGo through the signup form of the Pod provider

Additional methods

MethodDescription
getSession()Return the current session as { token, webId }, or undefined if there is none or if it expired
handleCallback()Complete the OIDC flow on the redirectUri route. Return { webId, redirect }
registerApp(webId?)Return the URI of the app registration. If the app is not registered, or if its access needs changed, redirect to the authorization screen and return undefined
getAppStatus()Return the status of the app on the Pod of the logged user

dataProvider

Create a Refine data provider which reads and writes resources on the Pod of the logged user.

const apDataProvider = dataProvider({ authProvider: apAuthProvider, resources, jsonContext });

Options

PropertyTypeDefaultDescription
authProviderObjectrequiredThe auth provider created above
resourcesObjectrequiredThe configuration of each Refine resource. See below
jsonContextAnyActivityStreams’ contextJSON-LD context sent with created and updated resources, and used to expand the types
readAccessGrantsBooleanfalseAlso list the resources found through the access grants of the app registration. This is slow and rarely needed

Resources

The keys of resources are the names of the Refine resources. Each value must have one of these properties:

PropertyTypeDescription
shapeTreeUriStringURI of the shape tree of the resource. This is the recommended option
typesString or ArrayTypes of the resource, as CURIEs or full URIs. Used when shapeTreeUri is not set

Methods

MethodDescription
getListRead the container of the resource. See Lists for the supported filters, sorters and pagination
getOneFetch a resource. Resources on other servers are fetched through the proxy of the user’s Pod
getManySame as getOne for several resources. The resources which cannot be fetched are left out
createPost the resource to its container, with the types of the resource, and return it as stored by the Pod
updateFetch the current version of the resource, apply the given variables and replace it. The properties which are not in the variables, such as those added by a backend, are kept
deleteOneDelete the resource

The custom method is not implemented. To call other endpoints, use fetchWithSession.

liveProvider

Create a Refine live provider using WebSocket channels. It requires Pod providers running a version of ActivityPods above 2.3.15.

Options

PropertyTypeDefaultDescription
authProviderObjectrequiredThe auth provider created above
resourcesObjectrequiredThe same value as for the data provider
jsonContextAnyActivityStreams’ contextThe same value as for the data provider

Subscriptions

WatchingChannelEvents
One or more IDsOne channel per resourceupdated and deleted
A listOne channel on the resource’s containercreated and deleted of its items

Lists are not notified when one of their items is updated. Nothing happens for the resources which are not in resources.

Utilities

fetchJson

const { status, headers, json } = await fetchJson(url, options, token);

A wrapper around fetch which sets the JSON-LD Accept and Content-Type headers, adds the bearer token if there is one, and parses the response. If the response is not successful, it throws an error with the status and the body of the response.

fetchWithSession

const { status, headers, json } = await fetchWithSession(url, options, session);

Same as fetchJson, as the logged user. A Pod only accepts the tokens it issued, so requests to other servers go through the proxy of the user’s Pod, which signs them on behalf of the user. You can get the session with useAuthProvider.

Other functions

FunctionDescription
resolveAuthAgent(webId, token?)Return { authAgent, appRegistrationUri }: the authorization agent of the user, and the app registration if there is one
resolveContainerUri(resource, resourceConfig, webId, token, context)Return the URI of the container of a resource, using the type indexes of the user
resolveResourceTypes(resourceConfig, context)Return the full URIs of the types of a resource
getTypesFromShapeTree(shapeTreeUri)Return the full URIs of the types targeted by a shape tree
expandTypes(types, context)Expand CURIEs to full URIs
fetchAppStatus(webId, token)Return the status of the app on the Pod of the given user
arrayOf(value)Return an array from a single value, an array, null or undefined

Constants

ConstantDescription
DEFAULT_CONTEXTThe ActivityStreams context
SEARCH_FIELDq: the field of the filter searching in all the fields of the resources
NEAR_FIELDnear: the field of the filter keeping the resources near a location
STORAGE_KEY_REDIRECTThe localStorage key of the path where the user comes back when returning from the Pod provider

Types

Identity

PropertyTypeDescription
idStringWebID of the user
nameStringName found in the profile, or the WebID by default
avatarStringPicture found in the profile
webIdDataObjectContent of the WebID
profileDataObjectContent of the profile

AppStatus

PropertyTypeDescription
onlineBackendBooleantrue if the app backend is reachable, or if there is none
installedBooleantrue if the app is registered on the Pod
upgradeNeededBooleantrue if the user must grant the access needs again
webhookChannelsObject or ArrayThe webhook channels of the app backend on the Pod