Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import _ from "lodash";
import postal from "postal";
import "./postal-utils";
import { packingSlips, getPackingSlip } from "./packingSlips";
import { state, disconnect, NO_OP, configure } from "./state";
import { handlers, onFederatedMsg } from "./handlers";
import filters, { matchesFilter, addFilter, removeFilter } from "./filters";
import FederationClient from "./FederationClient";
const fedx = postal.fedx = {
FederationClient: FederationClient,
packingSlips: packingSlips,
handlers: handlers,
clients: state._clients,
transports: state._transports,
filters,
addFilter,
removeFilter,
canSendRemote: function( channel, topic ) {
return matchesFilter( channel, topic, "out" );
},
configure: configure,
getPackingSlip,
onFederatedMsg: onFederatedMsg,
sendMessage: function( envelope ) {
if ( !state._ready ) {
if(!subs[channel][topic]) {
subs[channel][topic] = postal.subscribe({
channel : channel,
topic : topic,
callback : function(data, env) {
env = _.clone(env);
env.originId = postal.instanceId;
self.clients[id].send(_.extend({
envelope: env
}, self.getFedxWrapper("message")));
}
});
}
}
}, postal.fedx);
postal.subscribe({
channel : postal.configuration.SYSTEM_CHANNEL,
topic : "subscription.created",
callback : function(data, env) {
postal.fedx.addToManifest(data.channel, data.topic);
var payload = _.extend({
envelope: {
channel : "postal.federation",
topic : "remote.subscription.created",
originId : postal.instanceId,
knownIds : postal.fedx.knownIds,
data : { channel: data.channel, topic: data.topic }
}
}, postal.fedx.getFedxWrapper("subscription.created"));
postal.fedx.send(payload);
callback : function(d, e) {
var subs = postal.fedx.clients[e.originId].subscriptions;
if(subs[d.channel] && subs[d.channel][d.topic]) {
postal.fedx._processingIds = e.knownIds;
subs[d.channel][d.topic].unsubscribe();
postal.fedx._processingIds = [];
}
}
});
callback : function(data, env) {
postal.fedx.addToManifest(data.channel, data.topic);
var payload = _.extend({
envelope: {
channel : "postal.federation",
topic : "remote.subscription.created",
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){