SAP-BTP-Spielwiese/app1/node_modules/@sap/audit-logging/lib/base-messages/MessageBase.js

41 lines
956 B
JavaScript
Raw Normal View History

'use strict';
var utils = require('../utils');
module.exports = MessageBase;
function MessageBase(content, transport) {
this._content = content;
this._transport = transport;
}
MessageBase.prototype.by = function (user) {
utils.validate.notEmptyString(user, 'user');
this._content.user = user;
return this;
};
MessageBase.prototype.tenant = function (tenant, subdomain) {
utils.validate.notEmptyString(tenant, 'tenant');
this._content.tenant = tenant;
this._transport.subdomain = subdomain;
return this;
};
MessageBase.prototype.at = function (ts) {
if (!(ts instanceof Date)) {
ts = new Date(ts);
}
this.customTime = ts.toISOString();
return this;
};
MessageBase.prototype._update = function () {
this._content.uuid = utils.uuid();
this._content.time = this.customTime || new Date().toISOString();
};
MessageBase.prototype._validateContent = function () {
utils.validate.provided(this._content.user, 'user');
};