Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/*
postal.federation
Author: Jim Cowart (http://freshbrewedcode.com/jimcowart)
License: Dual licensed MIT (http://www.opensource.org/licenses/mit-license) & GPL (http://www.opensource.org/licenses/gpl-license)
Version 0.1.0
*/
var postal = require( 'postal' );
// BROWSER semi-uuid - it's ghetto and will need to be replaced
// the eventual node version won't need this kind of hackery
if(!postal.utils.getUUID) {
postal.utils.getUUID = function() {
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = "-";
return s.join("");
};
}
postal.fedx = _.extend({
clients: {},
/*
postal.federation
Author: Jim Cowart (http://freshbrewedcode.com/jimcowart)
License: Dual licensed MIT (http://www.opensource.org/licenses/mit-license) & GPL (http://www.opensource.org/licenses/gpl-license)
Version 0.1.0
*/
var postal = require( 'postal' );
// BROWSER semi-uuid - it's ghetto and will need to be replaced
// the eventual node version won't need this kind of hackery
if(!postal.utils.getUUID) {
postal.utils.getUUID = function() {
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = "-";
return s.join("");
};
}
postal.fedx = _.extend({
clients: {},
callback : function(data, env) {
if(!postal.utils.getSubscribersFor(data).length) {
var payload = _.extend({
envelope: {
channel : "postal.federation",
topic : "remote.subscription.removed",
originId : postal.instanceId,
knownIds : postal.fedx.knownIds,
data : { channel: data.channel, topic: data.topic }
}
}, postal.fedx.getFedxWrapper("subscription.created"));
postal.fedx.send(payload);
}
}
}).withConstraint(function(d, e){