localStorage / sessionStorage
Session cookie is even a worse lie
We never use session storage/cookie
import {LocalStorageCapsule} from 'data-capsule';
const capsule = new LocalStorageCapsule({namespace: 'engage'});
await capsule.setItem('shahata', 123);
console.log(await capsule.getItem('shahata')); // logs 123
import {DataCapsule, LocalStorageStrategy} from 'data-capsule';
const capsule = new DataCapsule({
strategy: new LocalStorageStrategy(),
namespace: 'engage'
});
await capsule.setItem('shahata', 123);
console.log(await capsule.getItem('shahata')); // logs 123
import {DataCapsule, LocalStorageStrategy} from 'data-capsule';
import secs from 'secs';
const capsule = new DataCapsule({
strategy: new LocalStorageStrategy(),
scope: {userId, siteId}, //optional
namespace: 'engage' //required
});
await capsule.setItem('shahata', 123, {
expiration: secs('2 days') //optional
});
console.log(await capsule.getItem('shahata')); // logs 123
class BaseStrategy {
setItem(key, value, {namespace, scope, expiration})
getItem(key, {namespace, scope})
removeItem(key, {namespace, scope})
getAllItems({namespace, scope})
}
class DataCapsule {
constructor({strategy, namespace, scope})
setItem(key, value, {namespace, scope, expiration})
getItem(key, {namespace, scope})
removeItem(key, {namespace, scope})
getAllItems({namespace, scope})
}
const capsule = new DataCapsule({
strategy: new LocalStorageStrategy()
});
const capsule = new DataCapsule({
strategy: new WixStorageStrategy()
});
const capsule = new DataCapsule({
strategy: new CachedStorageStrategy({
remoteStrategy: new WixStorageStrategy(),
localStrategy: new LocalStorageStrategy()
})
});
const capsule = new DataCapsule({
strategy: new FrameStorageStrategy(window.top, '*', 'secret'))
});
import {FrameStorageListener} from 'data-capsule';
const listener = new FrameStorageListener();
listener.start((source, origin, token) => token === 'secret');
//...
listener.stop();