clean-insights-sdk
Version:
A privacy-preserving measurement framework.
57 lines (56 loc) • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Store = void 0;
var consents_1 = require("./consents");
var Event_1 = require("./Event");
var Visit_1 = require("./Visit");
/**
* The store holds the user's consents to the different `Feature`s and `Campaign`s,
* and their `Visit` and `Event` measurements.
*
* If you want to implement your own persistence of the store (e.g. because you
* want to write it in a database instead of the file system) and your own
* implementation of the transmission to the Matomo/CIMP backend (e.g. because
* you want to tunnel the requests through a proxy or add your own encryption layer),
* then create a subclass of this class and implement the `#constructor`,
* `#persist` and `#send` methods.
*
* If you only want to change either one or the other, you can use `NodejsStore`
* (found in the backend example) or `BrowserStore` as a base and work from there.
*/
var Store = /** @class */ (function () {
/**
* @param {Object.<string, *>=} args={}
* Optional arguments your implementation might need for loading the store.
* @param {function(string)=} debug=undefined
* Optional function to output debug messages.
*/
function Store(args, debug) {
var _this = this;
this.consents = new consents_1.Consents();
this.visits = [];
this.events = [];
if (typeof debug === 'undefined') {
debug = function () { };
}
debug("Store created from the following arguments: ".concat(JSON.stringify(args)));
args = args || {};
args.debug = debug;
var data = this.load(args);
if (typeof data === 'undefined') {
debug("Storage doesn't exist or isn't readable.");
}
else {
this.consents = new consents_1.Consents(data.consents);
data.visits.forEach(function (visit) {
_this.visits.push(new Visit_1.Visit(visit));
});
data.events.forEach(function (event) {
_this.events.push(new Event_1.Event(event));
});
debug('Data loaded from storage.');
}
}
return Store;
}());
exports.Store = Store;