Persistence API Reference
Classes
- class PersistenceService(url, opts)
A client for the thiss.io persistence service. The Persistence service methods all follow the same pattern - a call that returns a Promise that resolves to one or more item Objects. An item is an Object with two properties:
The constructor initializes an iframe in window.document setting src to the URL provided to the constructor. To obtain cross-site persistence, using the browser’s Storage Access API, an integrator must expose a checkbox from the persistence service, so that when the user clicks on it, they will be prompted for permission to share persisted entities across different sites using the persistence service. This exposed checkbox can be labelled “remember me” or something of the sort.
- Arguments:
url (string) – The URL of the persistence service - eg https://use.thiss.io/ps/
opts (Object) – An object containing options. Supported keys:
entity (Object) – An entity object (discojson schema)
last_refresh (int) – A timestamp when this entity was last updated (used)
- PersistenceService.PersistenceService
The constructor initializes an iframe in window.document setting src to the URL provided to the constructor. To obtain cross-site persistence, using the browser’s Storage Access API, an integrator must expose a checkbox from the persistence service, so that when the user clicks on it, they will be prompted for permission to share persisted entities across different sites using the persistence service. This exposed checkbox can be labelled “remember me” or something of the sort.
- PersistenceService.clear(context)
Remove all entities from the context.
- Arguments:
context (string) – The context to write to
- Returns:
Promise – A Promise that resolves to nothing on success.
- PersistenceService.entities(context)
Returns 0-3 of the most recently used entities as a list of item Objects. Be sure to examine the last_time property to make sure the provided entities are “recent” enough to be used.
- Arguments:
context (string) – The context to write to
- Returns:
Promise – A Promise that resolves to a list of items on success.
- PersistenceService.entity(context, entity_id)
Fetch an entity from the context.
- Arguments:
context (string) – The context to write to
entity_id (string) – The entityID of the item to be removed.
- Returns:
Promise – A Promise that resolves to an item containing the entity on success.
- PersistenceService.has_storage_access(context)
Check whether the persistence service has storage access permission
- Arguments:
context (string) – The context to write to
- Returns:
boolean – A promise that resolves to a boolean
- PersistenceService.hide_checkbox(selector)
Hide Persistence Service checkbox that hasd been displayed under the provided selector
- Arguments:
selector (string) – A selector identifying the element to which the checkbox is currently appended
- Returns:
boolean – true on success.
- PersistenceService.remove(context, entity_id)
Remove an entity from the context.
- Arguments:
context (string) – The context to write to
entity_id (string) – The entityID of the item to be removed.
- Returns:
Promise – A Promise that resolves to nothing on success.
- PersistenceService.show_checkbox(selector)
Attach and display Persistence Service checkbox to the element identified by the selector
- Arguments:
selector (string) – A selector identifying the element to which the checkbox will be appended
- Returns:
boolean – true on success.
- PersistenceService.update(context, entity)
Update an an entity object in browser local store tied to the ORIGIN of the service URL.
- Arguments:
context (string) – The context to write to
entity (Object) – A js object representing an entity. Uses the discojson schema.
- Returns:
Promise – A Promise that resolves to an item containing the provided entity on success.