Storage providers

Seamly Web UI supports different storage providers for session data in the client. The session data consists of the conversation ID and other relevant state data. The amount of data stored is as minimal as possible (currently < 500 bytes).

Setting a different storage provider can be done by changing api.storageProvider in the configuration. This must be done during initialization.

Out of the box Seamly provides these three storage providers:

  • sessionStorageProvider (default)
  • cookieStorageProvider
  • appStorageProvider

It is also possible to build your own storageProvider.

Session storage provider

The session storage provider stores its data in the browser's session storage. This means any new window or tab (with some exceptions which differ per browser) will be a new session.

The cookie storage provider stores its data in a cookie. This storage provider is particulary useful if chat needs to work cross-subdomain.

When using this provider, all domains in use need to be whitelisted using the "Allowed origins" whitelist in Seamly to prevent CORS security issues.

The cookie storage provider needs to be initialized with a set of attributes which should be used when setting the cookie. See the js-cookie documentation on attributes for the attributes you can pass to the storage initialization function.

Example usage:

{
  api: {
    ...otherApiOptions,
    storageProvider: cookieStorageProvider({
      domain: window.location.hostname,
      expires: 1,
    })
  }
}

App storage provider

When using Seamly Web UI within a webview you can use the app storage provider. This is needed as generally speaking webviews do not retain session storage or cookies.

The App storage provider currently supports:

Custom storage provider

In some rare cases you may want to write a custom storage provider. The storageProvider spec requires it to be a function that returns an object with three functions as follows:

function() {
  return {
    get: function() { return data }
    set: function(data) { }
  }
}

The storageProvider must ensure that the data that you return from the get() is of the same type as what is stored with set.

A very basic implementation of a storageProvider can be found in the example below. It's a perfect starting point to writing your own storageProvider.

Example storageProvider

var storageProvider = function() {
  console.log("[STORAGE] init")
  // SET THE INCOMING DATA HERE
  var data = {}

  return {
    get: function() {
      console.log("[STORAGE] GET")

      return data
    },
    set: function(newData) {
      data = newData

      // PERSIST THE DATA HERE!
      console.log("[STORAGE] SET", newData)
    }
  }
}