Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@redux-devtools/remote

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@redux-devtools/remote - npm Package Compare versions

Comparing version 0.7.5 to 0.8.0

5

lib/cjs/configureStore.js

@@ -7,8 +7,7 @@ "use strict";

exports.default = configureStore;
var _instrument = require("@redux-devtools/instrument");
function configureStore( // eslint-disable-next-line @typescript-eslint/ban-types
function configureStore(
// eslint-disable-next-line @typescript-eslint/ban-types
next, subscriber, options) {
return (0, _instrument.instrument)(subscriber, options)(next);
}

2

lib/cjs/constants.js

@@ -7,3 +7,3 @@ "use strict";

exports.defaultSocketOptions = void 0;
var defaultSocketOptions = {
const defaultSocketOptions = {
secure: false,

@@ -10,0 +10,0 @@ hostname: 'localhost',

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -10,52 +9,26 @@ value: true

exports.default = void 0;
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _jsan = require("jsan");
var _socketclusterClient = _interopRequireDefault(require("socketcluster-client"));
var _configureStore = _interopRequireDefault(require("./configureStore"));
var _constants = require("./constants");
var _rnHostDetect = _interopRequireDefault(require("rn-host-detect"));
var _utils = require("@redux-devtools/utils");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function async(fn) {
setTimeout(fn, 0);
}
function str2array(str) {
return typeof str === 'string' ? [str] : str && str.length > 0 ? str : undefined;
}
function getRandomId() {
return Math.random().toString(36).substr(2);
}
var DevToolsEnhancer = /*#__PURE__*/function () {
function DevToolsEnhancer() {
class DevToolsEnhancer {
constructor() {
var _this = this;
(0, _classCallCheck2.default)(this, DevToolsEnhancer);
(0, _defineProperty2.default)(this, "errorCounts", {});
(0, _defineProperty2.default)(this, "send", function () {
if (!_this.instanceId) _this.instanceId = _this.socket && _this.socket.id || getRandomId();
(0, _defineProperty2.default)(this, "send", () => {
if (!this.instanceId) this.instanceId = this.socket && this.socket.id || getRandomId();
try {
fetch(_this.sendTo, {
fetch(this.sendTo, {
method: 'POST',

@@ -67,5 +40,5 @@ headers: {

type: 'STATE',
id: _this.instanceId,
name: _this.instanceName,
payload: (0, _jsan.stringify)(_this.getLiftedState())
id: this.instanceId,
name: this.instanceName,
payload: (0, _jsan.stringify)(this.getLiftedState())
})

@@ -79,5 +52,9 @@ }).catch(function (err) {

});
(0, _defineProperty2.default)(this, "handleMessages", function (message) {
if (message.type === 'IMPORT' || message.type === 'SYNC' && _this.socket.id && message.id !== _this.socket.id) {
_this.store.liftedStore.dispatch({
(0, _defineProperty2.default)(this, "handleMessages", message => {
if (message.type === 'IMPORT' || message.type === 'SYNC' &&
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
this.socket.id &&
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
message.id !== this.socket.id) {
this.store.liftedStore.dispatch({
type: 'IMPORT_STATE',

@@ -88,76 +65,71 @@ // eslint-disable-next-line @typescript-eslint/ban-types

} else if (message.type === 'UPDATE') {
_this.relay('STATE', _this.getLiftedState());
this.relay('STATE', this.getLiftedState());
} else if (message.type === 'START') {
_this.isMonitored = true;
if (typeof _this.actionCreators === 'function') _this.actionCreators = _this.actionCreators();
_this.relay('STATE', _this.getLiftedState(), _this.actionCreators);
this.isMonitored = true;
if (typeof this.actionCreators === 'function') this.actionCreators = this.actionCreators();
this.relay('STATE', this.getLiftedState(), this.actionCreators);
} else if (message.type === 'STOP' || message.type === 'DISCONNECTED') {
_this.isMonitored = false;
_this.relay('STOP');
this.isMonitored = false;
this.relay('STOP');
} else if (message.type === 'ACTION') {
_this.dispatchRemotely(message.action);
this.dispatchRemotely(message.action);
} else if (message.type === 'DISPATCH') {
_this.store.liftedStore.dispatch(message.action);
this.store.liftedStore.dispatch(message.action);
}
});
(0, _defineProperty2.default)(this, "sendError", function (errorAction) {
(0, _defineProperty2.default)(this, "sendError", errorAction => {
// Prevent flooding
if (errorAction.message && errorAction.message === _this.lastErrorMsg) return;
_this.lastErrorMsg = errorAction.message;
async(function () {
_this.store.dispatch(errorAction);
if (!_this.started) _this.send();
if (errorAction.message && errorAction.message === this.lastErrorMsg) return;
this.lastErrorMsg = errorAction.message;
async(() => {
this.store.dispatch(errorAction);
if (!this.started) this.send();
});
});
(0, _defineProperty2.default)(this, "stop", function (keepConnected) {
_this.started = false;
_this.isMonitored = false;
if (!_this.socket) return;
_this.socket.destroyChannel(_this.channel);
if (keepConnected) {
_this.socket.off(_this.channel, _this.handleMessages);
} else {
_this.socket.off();
_this.socket.disconnect();
(0, _defineProperty2.default)(this, "stop", keepConnected => {
this.started = false;
this.isMonitored = false;
if (!this.socket) return;
void this.socket.unsubscribe(this.channel);
this.socket.closeChannel(this.channel);
if (!keepConnected) {
this.socket.disconnect();
}
});
(0, _defineProperty2.default)(this, "start", function () {
if (_this.started || _this.socket && _this.socket.getState() === _this.socket.CONNECTING) return;
_this.socket = _socketclusterClient.default.create(_this.socketOptions);
_this.socket.on('error', function (err) {
// if we've already had this error before, increment it's counter, otherwise assign it '1' since we've had the error once.
// eslint-disable-next-line no-prototype-builtins
_this.errorCounts[err.name] = _this.errorCounts.hasOwnProperty(err.name) ? _this.errorCounts[err.name] + 1 : 1;
if (_this.suppressConnectErrors) {
if (_this.errorCounts[err.name] === 1) {
console.log('remote-redux-devtools: Socket connection errors are being suppressed. ' + '\n' + "This can be disabled by setting suppressConnectErrors to 'false'.");
console.log(err);
(0, _defineProperty2.default)(this, "start", () => {
if (this.started || this.socket && this.socket.getState() === this.socket.CONNECTING) return;
this.socket = _socketclusterClient.default.create(this.socketOptions);
void (async () => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket.listener('error')) {
// if we've already had this error before, increment it's counter, otherwise assign it '1' since we've had the error once.
// eslint-disable-next-line no-prototype-builtins,@typescript-eslint/no-unsafe-argument
this.errorCounts[data.error.name] = this.errorCounts.hasOwnProperty(data.error.name) ? this.errorCounts[data.error.name] + 1 : 1;
if (this.suppressConnectErrors) {
if (this.errorCounts[data.error.name] === 1) {
console.log('remote-redux-devtools: Socket connection errors are being suppressed. ' + '\n' + "This can be disabled by setting suppressConnectErrors to 'false'.");
console.log(data.error);
}
} else {
console.log(data.error);
}
} else {
console.log(err);
}
});
_this.socket.on('connect', function () {
console.log('connected to remotedev-server');
_this.errorCounts = {}; // clear the errorCounts object, so that we'll log any new errors in the event of a disconnect
_this.login();
});
_this.socket.on('disconnect', function () {
_this.stop(true);
});
})();
void (async () => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket.listener('connect')) {
console.log('connected to remotedev-server');
this.errorCounts = {}; // clear the errorCounts object, so that we'll log any new errors in the event of a disconnect
this.login();
}
})();
void (async () => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket.listener('disconnect')) {
this.stop(true);
}
})();
});
(0, _defineProperty2.default)(this, "checkForReducerErrors", function () {
var liftedState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.getLiftedStateRaw();
let liftedState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.getLiftedStateRaw();
if (liftedState.computedStates[liftedState.currentStateIndex].error) {

@@ -167,8 +139,7 @@ if (_this.started) _this.relay('STATE', (0, _utils.filterStagedActions)(liftedState, _this.filters));else _this.send();

}
return false;
});
(0, _defineProperty2.default)(this, "monitorReducer", function () {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var action = arguments.length > 1 ? arguments[1] : undefined;
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
let action = arguments.length > 1 ? arguments[1] : undefined;
_this.lastAction = action.type;

@@ -181,17 +152,14 @@ if (!_this.started && _this.sendOnError === 2 && _this.store.liftedStore) async(_this.checkForReducerErrors);else if (action.action) {

(0, _defineProperty2.default)(this, "enhance", function () {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_this.init(_objectSpread(_objectSpread({}, options), {}, {
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_this.init({
...options,
hostname: (0, _rnHostDetect.default)(options.hostname || 'localhost')
}));
var realtime = typeof options.realtime === 'undefined' ? process.env.NODE_ENV === 'development' : options.realtime;
if (!realtime && !(_this.startOn || _this.sendOn || _this.sendOnError)) return function (f) {
return f;
};
var maxAge = options.maxAge || 30;
return function (next) {
return function (reducer, initialState) {
});
const realtime = typeof options.realtime === 'undefined' ? process.env.NODE_ENV === 'development' : options.realtime;
if (!realtime && !(_this.startOn || _this.sendOn || _this.sendOnError)) return f => f;
const maxAge = options.maxAge || 30;
return next => {
return (reducer, initialState) => {
_this.store = (0, _configureStore.default)(next, _this.monitorReducer, {
maxAge: maxAge,
maxAge,
trace: options.trace,

@@ -206,7 +174,5 @@ traceLimit: options.traceLimit,

if (realtime) _this.start();
_this.store.subscribe(function () {
_this.store.subscribe(() => {
if (_this.isMonitored) _this.handleChange(_this.store.getState(), _this.getLiftedStateRaw(), maxAge);
});
return _this.store;

@@ -217,181 +183,134 @@ };

}
(0, _createClass2.default)(DevToolsEnhancer, [{
key: "getLiftedStateRaw",
value: function getLiftedStateRaw() {
return this.store.liftedStore.getState();
getLiftedStateRaw() {
return this.store.liftedStore.getState();
}
getLiftedState() {
return (0, _utils.filterStagedActions)(this.getLiftedStateRaw(), this.filters);
}
relay(type, state, action, nextActionId) {
const message = {
type,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
id: this.socket.id,
name: this.instanceName,
instanceId: this.appInstanceId
};
if (state) {
message.payload = type === 'ERROR' ? state : (0, _jsan.stringify)((0, _utils.filterState)(state, type, this.filters, this.stateSanitizer, this.actionSanitizer, nextActionId));
}
}, {
key: "getLiftedState",
value: function getLiftedState() {
return (0, _utils.filterStagedActions)(this.getLiftedStateRaw(), this.filters);
if (type === 'ACTION') {
message.action = (0, _jsan.stringify)(!this.actionSanitizer ? action : this.actionSanitizer(action.action, nextActionId - 1));
message.isExcess = this.isExcess;
message.nextActionId = nextActionId;
} else if (action) {
message.action = action;
}
}, {
key: "relay",
value: function relay(type, state, action, nextActionId) {
var message = {
type: type,
id: this.socket.id,
name: this.instanceName,
instanceId: this.appInstanceId
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
void this.socket.transmit(this.socket.id ? 'log' : 'log-noid', message);
}
dispatchRemotely(action) {
try {
const result = (0, _utils.evalAction)(action, this.actionCreators);
this.store.dispatch(result);
} catch (e) {
this.relay('ERROR', e.message);
}
}
init(options) {
this.instanceName = options.name;
this.appInstanceId = getRandomId();
const {
blacklist,
whitelist,
denylist,
allowlist
} = options.filters || {};
this.filters = (0, _utils.getLocalFilter)({
actionsDenylist: denylist ?? options.actionsDenylist ?? blacklist ?? options.actionsBlacklist,
actionsAllowlist: allowlist ?? options.actionsAllowlist ?? whitelist ?? options.actionsWhitelist
});
if (options.port) {
this.socketOptions = {
port: options.port,
hostname: options.hostname || 'localhost',
secure: options.secure
};
if (state) {
message.payload = type === 'ERROR' ? state : (0, _jsan.stringify)((0, _utils.filterState)(state, type, this.filters, this.stateSanitizer, this.actionSanitizer, nextActionId));
}
if (type === 'ACTION') {
message.action = (0, _jsan.stringify)(!this.actionSanitizer ? action : this.actionSanitizer(action.action, nextActionId - 1));
message.isExcess = this.isExcess;
message.nextActionId = nextActionId;
} else if (action) {
message.action = action;
}
this.socket.emit(this.socket.id ? 'log' : 'log-noid', message);
} else this.socketOptions = _constants.defaultSocketOptions;
this.suppressConnectErrors = options.suppressConnectErrors !== undefined ? options.suppressConnectErrors : true;
this.startOn = str2array(options.startOn);
this.stopOn = str2array(options.stopOn);
this.sendOn = str2array(options.sendOn);
this.sendOnError = options.sendOnError;
if (this.sendOn || this.sendOnError) {
this.sendTo = options.sendTo || `${this.socketOptions.secure ? 'https' : 'http'}://${this.socketOptions.hostname}:${this.socketOptions.port}`;
this.instanceId = options.id;
}
}, {
key: "dispatchRemotely",
value: function dispatchRemotely(action) {
if (this.sendOnError === 1) (0, _utils.catchErrors)(this.sendError);
if (options.actionCreators) this.actionCreators = () => (0, _utils.getActionsArray)(options.actionCreators);
this.stateSanitizer = options.stateSanitizer;
this.actionSanitizer = options.actionSanitizer;
}
login() {
void (async () => {
try {
var result = (0, _utils.evalAction)(action, this.actionCreators);
this.store.dispatch(result);
} catch (e) {
this.relay('ERROR', e.message);
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const channelName = await this.socket.invoke('login', 'master');
this.channel = channelName;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket.subscribe(channelName)) {
this.handleMessages(data);
}
} catch (error) {
console.log(error);
}
}
}, {
key: "init",
value: function init(options) {
var _ref2, _ref3, _ref4, _ref5;
this.instanceName = options.name;
this.appInstanceId = getRandomId();
var _ref = options.filters || {},
blacklist = _ref.blacklist,
whitelist = _ref.whitelist,
denylist = _ref.denylist,
allowlist = _ref.allowlist;
this.filters = (0, _utils.getLocalFilter)({
actionsDenylist: (_ref2 = (_ref3 = denylist !== null && denylist !== void 0 ? denylist : options.actionsDenylist) !== null && _ref3 !== void 0 ? _ref3 : blacklist) !== null && _ref2 !== void 0 ? _ref2 : options.actionsBlacklist,
actionsAllowlist: (_ref4 = (_ref5 = allowlist !== null && allowlist !== void 0 ? allowlist : options.actionsAllowlist) !== null && _ref5 !== void 0 ? _ref5 : whitelist) !== null && _ref4 !== void 0 ? _ref4 : options.actionsWhitelist
});
if (options.port) {
this.socketOptions = {
port: options.port,
hostname: options.hostname || 'localhost',
secure: options.secure
};
} else this.socketOptions = _constants.defaultSocketOptions;
this.suppressConnectErrors = options.suppressConnectErrors !== undefined ? options.suppressConnectErrors : true;
this.startOn = str2array(options.startOn);
this.stopOn = str2array(options.stopOn);
this.sendOn = str2array(options.sendOn);
this.sendOnError = options.sendOnError;
if (this.sendOn || this.sendOnError) {
this.sendTo = options.sendTo || "".concat(this.socketOptions.secure ? 'https' : 'http', "://").concat(this.socketOptions.hostname, ":").concat(this.socketOptions.port);
this.instanceId = options.id;
})();
this.started = true;
this.relay('START');
}
// eslint-disable-next-line @typescript-eslint/ban-types
handleChange(state, liftedState, maxAge) {
if (this.checkForReducerErrors(liftedState)) return;
if (this.lastAction === 'PERFORM_ACTION') {
const nextActionId = liftedState.nextActionId;
const liftedAction = liftedState.actionsById[nextActionId - 1];
if ((0, _utils.isFiltered)(liftedAction.action, this.filters)) return;
this.relay('ACTION', state, liftedAction, nextActionId);
if (!this.isExcess && maxAge) this.isExcess = liftedState.stagedActionIds.length >= maxAge;
} else {
if (this.lastAction === 'JUMP_TO_STATE') return;
if (this.lastAction === 'PAUSE_RECORDING') {
this.paused = liftedState.isPaused;
} else if (this.lastAction === 'LOCK_CHANGES') {
this.locked = liftedState.isLocked;
}
if (this.sendOnError === 1) (0, _utils.catchErrors)(this.sendError);
if (options.actionCreators) this.actionCreators = function () {
return (0, _utils.getActionsArray)(options.actionCreators);
};
this.stateSanitizer = options.stateSanitizer;
this.actionSanitizer = options.actionSanitizer;
}
}, {
key: "login",
value: function login() {
var _this2 = this;
this.socket.emit('login', 'master', function (err, channelName) {
if (err) {
console.log(err);
return;
}
_this2.channel = channelName;
_this2.socket.subscribe(channelName).watch(_this2.handleMessages);
_this2.socket.on(channelName, _this2.handleMessages);
});
this.started = true;
this.relay('START');
}
}, {
key: "handleChange",
value: // eslint-disable-next-line @typescript-eslint/ban-types
function handleChange(state, liftedState, maxAge) {
if (this.checkForReducerErrors(liftedState)) return;
if (this.lastAction === 'PERFORM_ACTION') {
var nextActionId = liftedState.nextActionId;
var liftedAction = liftedState.actionsById[nextActionId - 1];
if ((0, _utils.isFiltered)(liftedAction.action, this.filters)) return;
this.relay('ACTION', state, liftedAction, nextActionId);
if (!this.isExcess && maxAge) this.isExcess = liftedState.stagedActionIds.length >= maxAge;
} else {
if (this.lastAction === 'JUMP_TO_STATE') return;
if (this.lastAction === 'PAUSE_RECORDING') {
this.paused = liftedState.isPaused;
} else if (this.lastAction === 'LOCK_CHANGES') {
this.locked = liftedState.isLocked;
}
if (this.paused || this.locked) {
if (this.lastAction) this.lastAction = undefined;else return;
}
this.relay('STATE', (0, _utils.filterStagedActions)(liftedState, this.filters));
if (this.paused || this.locked) {
if (this.lastAction) this.lastAction = undefined;else return;
}
this.relay('STATE', (0, _utils.filterStagedActions)(liftedState, this.filters));
}
}]);
return DevToolsEnhancer;
}();
var _default = function _default(options) {
return new DevToolsEnhancer().enhance(options);
};
}
}
var _default = options => new DevToolsEnhancer().enhance(options);
exports.default = _default;
var compose = function compose(options) {
const compose = options => function () {
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
funcs[_key] = arguments[_key];
}
return function () {
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
funcs[_key] = arguments[_key];
const devToolsEnhancer = new DevToolsEnhancer();
function preEnhancer(createStore) {
return (reducer, preloadedState) => {
devToolsEnhancer.store = createStore(reducer, preloadedState);
return {
...devToolsEnhancer.store,
dispatch: action => devToolsEnhancer.locked ? action : devToolsEnhancer.store.dispatch(action)
};
};
}
return function () {
var devToolsEnhancer = new DevToolsEnhancer();
function preEnhancer(createStore) {
return function (reducer, preloadedState) {
devToolsEnhancer.store = createStore(reducer, preloadedState);
return _objectSpread(_objectSpread({}, devToolsEnhancer.store), {}, {
dispatch: function dispatch(action) {
return devToolsEnhancer.locked ? action : devToolsEnhancer.store.dispatch(action);
}
});
};
}
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return [preEnhancer].concat(funcs).reduceRight(function (composed, f) {
return f(composed);
}, devToolsEnhancer.enhance(options).apply(void 0, (0, _toConsumableArray2.default)(args)));
};
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return [preEnhancer, ...funcs].reduceRight((composed, f) => f(composed), devToolsEnhancer.enhance(options)(...args));
};
};
function composeWithDevTools() {

@@ -401,12 +320,9 @@ for (var _len3 = arguments.length, funcs = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {

}
if (funcs.length === 0) {
return new DevToolsEnhancer().enhance();
}
if (funcs.length === 1 && (0, _typeof2.default)(funcs[0]) === 'object') {
if (funcs.length === 1 && typeof funcs[0] === 'object') {
return compose(funcs[0]);
}
return compose({}).apply(void 0, (0, _toConsumableArray2.default)(funcs));
return compose({})(...funcs);
}
"use strict";
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -10,3 +8,3 @@ value: true

enumerable: true,
get: function get() {
get: function () {
return _devTools.composeWithDevTools;

@@ -17,11 +15,8 @@ }

enumerable: true,
get: function get() {
get: function () {
return _devTools.default;
}
});
var _devTools = _interopRequireWildcard(require("./devTools"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
import { instrument } from '@redux-devtools/instrument';
export default function configureStore( // eslint-disable-next-line @typescript-eslint/ban-types
export default function configureStore(
// eslint-disable-next-line @typescript-eslint/ban-types
next, subscriber, options) {
return instrument(subscriber, options)(next);
}

@@ -1,2 +0,2 @@

export var defaultSocketOptions = {
export const defaultSocketOptions = {
secure: false,

@@ -3,0 +3,0 @@ hostname: 'localhost',

@@ -1,13 +0,4 @@

import _typeof from "@babel/runtime/helpers/typeof";
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
import { stringify, parse } from 'jsan';
import socketCluster from 'socketcluster-client';
import socketClusterClient from 'socketcluster-client';
import configureStore from './configureStore';

@@ -17,28 +8,19 @@ import { defaultSocketOptions } from './constants';

import { evalAction, catchErrors, getActionsArray, getLocalFilter, isFiltered, filterStagedActions, filterState } from '@redux-devtools/utils';
function async(fn) {
setTimeout(fn, 0);
}
function str2array(str) {
return typeof str === 'string' ? [str] : str && str.length > 0 ? str : undefined;
}
function getRandomId() {
return Math.random().toString(36).substr(2);
}
var DevToolsEnhancer = /*#__PURE__*/function () {
function DevToolsEnhancer() {
class DevToolsEnhancer {
constructor() {
var _this = this;
_classCallCheck(this, DevToolsEnhancer);
_defineProperty(this, "errorCounts", {});
_defineProperty(this, "send", function () {
if (!_this.instanceId) _this.instanceId = _this.socket && _this.socket.id || getRandomId();
_defineProperty(this, "send", () => {
if (!this.instanceId) this.instanceId = this.socket && this.socket.id || getRandomId();
try {
fetch(_this.sendTo, {
fetch(this.sendTo, {
method: 'POST',

@@ -50,5 +32,5 @@ headers: {

type: 'STATE',
id: _this.instanceId,
name: _this.instanceName,
payload: stringify(_this.getLiftedState())
id: this.instanceId,
name: this.instanceName,
payload: stringify(this.getLiftedState())
})

@@ -62,6 +44,9 @@ }).catch(function (err) {

});
_defineProperty(this, "handleMessages", function (message) {
if (message.type === 'IMPORT' || message.type === 'SYNC' && _this.socket.id && message.id !== _this.socket.id) {
_this.store.liftedStore.dispatch({
_defineProperty(this, "handleMessages", message => {
if (message.type === 'IMPORT' || message.type === 'SYNC' &&
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
this.socket.id &&
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
message.id !== this.socket.id) {
this.store.liftedStore.dispatch({
type: 'IMPORT_STATE',

@@ -72,80 +57,71 @@ // eslint-disable-next-line @typescript-eslint/ban-types

} else if (message.type === 'UPDATE') {
_this.relay('STATE', _this.getLiftedState());
this.relay('STATE', this.getLiftedState());
} else if (message.type === 'START') {
_this.isMonitored = true;
if (typeof _this.actionCreators === 'function') _this.actionCreators = _this.actionCreators();
_this.relay('STATE', _this.getLiftedState(), _this.actionCreators);
this.isMonitored = true;
if (typeof this.actionCreators === 'function') this.actionCreators = this.actionCreators();
this.relay('STATE', this.getLiftedState(), this.actionCreators);
} else if (message.type === 'STOP' || message.type === 'DISCONNECTED') {
_this.isMonitored = false;
_this.relay('STOP');
this.isMonitored = false;
this.relay('STOP');
} else if (message.type === 'ACTION') {
_this.dispatchRemotely(message.action);
this.dispatchRemotely(message.action);
} else if (message.type === 'DISPATCH') {
_this.store.liftedStore.dispatch(message.action);
this.store.liftedStore.dispatch(message.action);
}
});
_defineProperty(this, "sendError", function (errorAction) {
_defineProperty(this, "sendError", errorAction => {
// Prevent flooding
if (errorAction.message && errorAction.message === _this.lastErrorMsg) return;
_this.lastErrorMsg = errorAction.message;
async(function () {
_this.store.dispatch(errorAction);
if (!_this.started) _this.send();
if (errorAction.message && errorAction.message === this.lastErrorMsg) return;
this.lastErrorMsg = errorAction.message;
async(() => {
this.store.dispatch(errorAction);
if (!this.started) this.send();
});
});
_defineProperty(this, "stop", function (keepConnected) {
_this.started = false;
_this.isMonitored = false;
if (!_this.socket) return;
_this.socket.destroyChannel(_this.channel);
if (keepConnected) {
_this.socket.off(_this.channel, _this.handleMessages);
} else {
_this.socket.off();
_this.socket.disconnect();
_defineProperty(this, "stop", keepConnected => {
this.started = false;
this.isMonitored = false;
if (!this.socket) return;
void this.socket.unsubscribe(this.channel);
this.socket.closeChannel(this.channel);
if (!keepConnected) {
this.socket.disconnect();
}
});
_defineProperty(this, "start", function () {
if (_this.started || _this.socket && _this.socket.getState() === _this.socket.CONNECTING) return;
_this.socket = socketCluster.create(_this.socketOptions);
_this.socket.on('error', function (err) {
// if we've already had this error before, increment it's counter, otherwise assign it '1' since we've had the error once.
// eslint-disable-next-line no-prototype-builtins
_this.errorCounts[err.name] = _this.errorCounts.hasOwnProperty(err.name) ? _this.errorCounts[err.name] + 1 : 1;
if (_this.suppressConnectErrors) {
if (_this.errorCounts[err.name] === 1) {
console.log('remote-redux-devtools: Socket connection errors are being suppressed. ' + '\n' + "This can be disabled by setting suppressConnectErrors to 'false'.");
console.log(err);
_defineProperty(this, "start", () => {
if (this.started || this.socket && this.socket.getState() === this.socket.CONNECTING) return;
this.socket = socketClusterClient.create(this.socketOptions);
void (async () => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket.listener('error')) {
// if we've already had this error before, increment it's counter, otherwise assign it '1' since we've had the error once.
// eslint-disable-next-line no-prototype-builtins,@typescript-eslint/no-unsafe-argument
this.errorCounts[data.error.name] = this.errorCounts.hasOwnProperty(data.error.name) ? this.errorCounts[data.error.name] + 1 : 1;
if (this.suppressConnectErrors) {
if (this.errorCounts[data.error.name] === 1) {
console.log('remote-redux-devtools: Socket connection errors are being suppressed. ' + '\n' + "This can be disabled by setting suppressConnectErrors to 'false'.");
console.log(data.error);
}
} else {
console.log(data.error);
}
} else {
console.log(err);
}
});
_this.socket.on('connect', function () {
console.log('connected to remotedev-server');
_this.errorCounts = {}; // clear the errorCounts object, so that we'll log any new errors in the event of a disconnect
_this.login();
});
_this.socket.on('disconnect', function () {
_this.stop(true);
});
})();
void (async () => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket.listener('connect')) {
console.log('connected to remotedev-server');
this.errorCounts = {}; // clear the errorCounts object, so that we'll log any new errors in the event of a disconnect
this.login();
}
})();
void (async () => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket.listener('disconnect')) {
this.stop(true);
}
})();
});
_defineProperty(this, "checkForReducerErrors", function () {
var liftedState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.getLiftedStateRaw();
let liftedState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.getLiftedStateRaw();
if (liftedState.computedStates[liftedState.currentStateIndex].error) {

@@ -155,9 +131,7 @@ if (_this.started) _this.relay('STATE', filterStagedActions(liftedState, _this.filters));else _this.send();

}
return false;
});
_defineProperty(this, "monitorReducer", function () {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var action = arguments.length > 1 ? arguments[1] : undefined;
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
let action = arguments.length > 1 ? arguments[1] : undefined;
_this.lastAction = action.type;

@@ -169,19 +143,15 @@ if (!_this.started && _this.sendOnError === 2 && _this.store.liftedStore) async(_this.checkForReducerErrors);else if (action.action) {

});
_defineProperty(this, "enhance", function () {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_this.init(_objectSpread(_objectSpread({}, options), {}, {
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_this.init({
...options,
hostname: getHostForRN(options.hostname || 'localhost')
}));
var realtime = typeof options.realtime === 'undefined' ? process.env.NODE_ENV === 'development' : options.realtime;
if (!realtime && !(_this.startOn || _this.sendOn || _this.sendOnError)) return function (f) {
return f;
};
var maxAge = options.maxAge || 30;
return function (next) {
return function (reducer, initialState) {
});
const realtime = typeof options.realtime === 'undefined' ? process.env.NODE_ENV === 'development' : options.realtime;
if (!realtime && !(_this.startOn || _this.sendOn || _this.sendOnError)) return f => f;
const maxAge = options.maxAge || 30;
return next => {
return (reducer, initialState) => {
_this.store = configureStore(next, _this.monitorReducer, {
maxAge: maxAge,
maxAge,
trace: options.trace,

@@ -196,7 +166,5 @@ traceLimit: options.traceLimit,

if (realtime) _this.start();
_this.store.subscribe(function () {
_this.store.subscribe(() => {
if (_this.isMonitored) _this.handleChange(_this.store.getState(), _this.getLiftedStateRaw(), maxAge);
});
return _this.store;

@@ -207,180 +175,133 @@ };

}
_createClass(DevToolsEnhancer, [{
key: "getLiftedStateRaw",
value: function getLiftedStateRaw() {
return this.store.liftedStore.getState();
getLiftedStateRaw() {
return this.store.liftedStore.getState();
}
getLiftedState() {
return filterStagedActions(this.getLiftedStateRaw(), this.filters);
}
relay(type, state, action, nextActionId) {
const message = {
type,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
id: this.socket.id,
name: this.instanceName,
instanceId: this.appInstanceId
};
if (state) {
message.payload = type === 'ERROR' ? state : stringify(filterState(state, type, this.filters, this.stateSanitizer, this.actionSanitizer, nextActionId));
}
}, {
key: "getLiftedState",
value: function getLiftedState() {
return filterStagedActions(this.getLiftedStateRaw(), this.filters);
if (type === 'ACTION') {
message.action = stringify(!this.actionSanitizer ? action : this.actionSanitizer(action.action, nextActionId - 1));
message.isExcess = this.isExcess;
message.nextActionId = nextActionId;
} else if (action) {
message.action = action;
}
}, {
key: "relay",
value: function relay(type, state, action, nextActionId) {
var message = {
type: type,
id: this.socket.id,
name: this.instanceName,
instanceId: this.appInstanceId
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
void this.socket.transmit(this.socket.id ? 'log' : 'log-noid', message);
}
dispatchRemotely(action) {
try {
const result = evalAction(action, this.actionCreators);
this.store.dispatch(result);
} catch (e) {
this.relay('ERROR', e.message);
}
}
init(options) {
this.instanceName = options.name;
this.appInstanceId = getRandomId();
const {
blacklist,
whitelist,
denylist,
allowlist
} = options.filters || {};
this.filters = getLocalFilter({
actionsDenylist: denylist ?? options.actionsDenylist ?? blacklist ?? options.actionsBlacklist,
actionsAllowlist: allowlist ?? options.actionsAllowlist ?? whitelist ?? options.actionsWhitelist
});
if (options.port) {
this.socketOptions = {
port: options.port,
hostname: options.hostname || 'localhost',
secure: options.secure
};
if (state) {
message.payload = type === 'ERROR' ? state : stringify(filterState(state, type, this.filters, this.stateSanitizer, this.actionSanitizer, nextActionId));
}
if (type === 'ACTION') {
message.action = stringify(!this.actionSanitizer ? action : this.actionSanitizer(action.action, nextActionId - 1));
message.isExcess = this.isExcess;
message.nextActionId = nextActionId;
} else if (action) {
message.action = action;
}
this.socket.emit(this.socket.id ? 'log' : 'log-noid', message);
} else this.socketOptions = defaultSocketOptions;
this.suppressConnectErrors = options.suppressConnectErrors !== undefined ? options.suppressConnectErrors : true;
this.startOn = str2array(options.startOn);
this.stopOn = str2array(options.stopOn);
this.sendOn = str2array(options.sendOn);
this.sendOnError = options.sendOnError;
if (this.sendOn || this.sendOnError) {
this.sendTo = options.sendTo || `${this.socketOptions.secure ? 'https' : 'http'}://${this.socketOptions.hostname}:${this.socketOptions.port}`;
this.instanceId = options.id;
}
}, {
key: "dispatchRemotely",
value: function dispatchRemotely(action) {
if (this.sendOnError === 1) catchErrors(this.sendError);
if (options.actionCreators) this.actionCreators = () => getActionsArray(options.actionCreators);
this.stateSanitizer = options.stateSanitizer;
this.actionSanitizer = options.actionSanitizer;
}
login() {
void (async () => {
try {
var result = evalAction(action, this.actionCreators);
this.store.dispatch(result);
} catch (e) {
this.relay('ERROR', e.message);
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const channelName = await this.socket.invoke('login', 'master');
this.channel = channelName;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket.subscribe(channelName)) {
this.handleMessages(data);
}
} catch (error) {
console.log(error);
}
})();
this.started = true;
this.relay('START');
}
// eslint-disable-next-line @typescript-eslint/ban-types
handleChange(state, liftedState, maxAge) {
if (this.checkForReducerErrors(liftedState)) return;
if (this.lastAction === 'PERFORM_ACTION') {
const nextActionId = liftedState.nextActionId;
const liftedAction = liftedState.actionsById[nextActionId - 1];
if (isFiltered(liftedAction.action, this.filters)) return;
this.relay('ACTION', state, liftedAction, nextActionId);
if (!this.isExcess && maxAge) this.isExcess = liftedState.stagedActionIds.length >= maxAge;
} else {
if (this.lastAction === 'JUMP_TO_STATE') return;
if (this.lastAction === 'PAUSE_RECORDING') {
this.paused = liftedState.isPaused;
} else if (this.lastAction === 'LOCK_CHANGES') {
this.locked = liftedState.isLocked;
}
if (this.paused || this.locked) {
if (this.lastAction) this.lastAction = undefined;else return;
}
this.relay('STATE', filterStagedActions(liftedState, this.filters));
}
}, {
key: "init",
value: function init(options) {
var _ref2, _ref3, _ref4, _ref5;
this.instanceName = options.name;
this.appInstanceId = getRandomId();
var _ref = options.filters || {},
blacklist = _ref.blacklist,
whitelist = _ref.whitelist,
denylist = _ref.denylist,
allowlist = _ref.allowlist;
this.filters = getLocalFilter({
actionsDenylist: (_ref2 = (_ref3 = denylist !== null && denylist !== void 0 ? denylist : options.actionsDenylist) !== null && _ref3 !== void 0 ? _ref3 : blacklist) !== null && _ref2 !== void 0 ? _ref2 : options.actionsBlacklist,
actionsAllowlist: (_ref4 = (_ref5 = allowlist !== null && allowlist !== void 0 ? allowlist : options.actionsAllowlist) !== null && _ref5 !== void 0 ? _ref5 : whitelist) !== null && _ref4 !== void 0 ? _ref4 : options.actionsWhitelist
});
if (options.port) {
this.socketOptions = {
port: options.port,
hostname: options.hostname || 'localhost',
secure: options.secure
}
}
export default (options => new DevToolsEnhancer().enhance(options));
const compose = options => function () {
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
funcs[_key] = arguments[_key];
}
return function () {
const devToolsEnhancer = new DevToolsEnhancer();
function preEnhancer(createStore) {
return (reducer, preloadedState) => {
devToolsEnhancer.store = createStore(reducer, preloadedState);
return {
...devToolsEnhancer.store,
dispatch: action => devToolsEnhancer.locked ? action : devToolsEnhancer.store.dispatch(action)
};
} else this.socketOptions = defaultSocketOptions;
this.suppressConnectErrors = options.suppressConnectErrors !== undefined ? options.suppressConnectErrors : true;
this.startOn = str2array(options.startOn);
this.stopOn = str2array(options.stopOn);
this.sendOn = str2array(options.sendOn);
this.sendOnError = options.sendOnError;
if (this.sendOn || this.sendOnError) {
this.sendTo = options.sendTo || "".concat(this.socketOptions.secure ? 'https' : 'http', "://").concat(this.socketOptions.hostname, ":").concat(this.socketOptions.port);
this.instanceId = options.id;
}
if (this.sendOnError === 1) catchErrors(this.sendError);
if (options.actionCreators) this.actionCreators = function () {
return getActionsArray(options.actionCreators);
};
this.stateSanitizer = options.stateSanitizer;
this.actionSanitizer = options.actionSanitizer;
}
}, {
key: "login",
value: function login() {
var _this2 = this;
this.socket.emit('login', 'master', function (err, channelName) {
if (err) {
console.log(err);
return;
}
_this2.channel = channelName;
_this2.socket.subscribe(channelName).watch(_this2.handleMessages);
_this2.socket.on(channelName, _this2.handleMessages);
});
this.started = true;
this.relay('START');
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
}, {
key: "handleChange",
value: // eslint-disable-next-line @typescript-eslint/ban-types
function handleChange(state, liftedState, maxAge) {
if (this.checkForReducerErrors(liftedState)) return;
if (this.lastAction === 'PERFORM_ACTION') {
var nextActionId = liftedState.nextActionId;
var liftedAction = liftedState.actionsById[nextActionId - 1];
if (isFiltered(liftedAction.action, this.filters)) return;
this.relay('ACTION', state, liftedAction, nextActionId);
if (!this.isExcess && maxAge) this.isExcess = liftedState.stagedActionIds.length >= maxAge;
} else {
if (this.lastAction === 'JUMP_TO_STATE') return;
if (this.lastAction === 'PAUSE_RECORDING') {
this.paused = liftedState.isPaused;
} else if (this.lastAction === 'LOCK_CHANGES') {
this.locked = liftedState.isLocked;
}
if (this.paused || this.locked) {
if (this.lastAction) this.lastAction = undefined;else return;
}
this.relay('STATE', filterStagedActions(liftedState, this.filters));
}
}
}]);
return DevToolsEnhancer;
}();
export default (function (options) {
return new DevToolsEnhancer().enhance(options);
});
var compose = function compose(options) {
return function () {
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
funcs[_key] = arguments[_key];
}
return function () {
var devToolsEnhancer = new DevToolsEnhancer();
function preEnhancer(createStore) {
return function (reducer, preloadedState) {
devToolsEnhancer.store = createStore(reducer, preloadedState);
return _objectSpread(_objectSpread({}, devToolsEnhancer.store), {}, {
dispatch: function dispatch(action) {
return devToolsEnhancer.locked ? action : devToolsEnhancer.store.dispatch(action);
}
});
};
}
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return [preEnhancer].concat(funcs).reduceRight(function (composed, f) {
return f(composed);
}, devToolsEnhancer.enhance(options).apply(void 0, _toConsumableArray(args)));
};
return [preEnhancer, ...funcs].reduceRight((composed, f) => f(composed), devToolsEnhancer.enhance(options)(...args));
};
};
export function composeWithDevTools() {

@@ -390,12 +311,9 @@ for (var _len3 = arguments.length, funcs = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {

}
if (funcs.length === 0) {
return new DevToolsEnhancer().enhance();
}
if (funcs.length === 1 && _typeof(funcs[0]) === 'object') {
if (funcs.length === 1 && typeof funcs[0] === 'object') {
return compose(funcs[0]);
}
return compose({}).apply(void 0, _toConsumableArray(funcs));
return compose({})(...funcs);
}
{
"name": "@redux-devtools/remote",
"version": "0.7.5",
"version": "0.8.0",
"description": "Relay Redux actions to remote Redux DevTools.",

@@ -33,3 +33,3 @@ "keywords": [

"dependencies": {
"@babel/runtime": "^7.18.3",
"@babel/runtime": "^7.20.7",
"@redux-devtools/instrument": "^2.1.0",

@@ -40,22 +40,22 @@ "@redux-devtools/utils": "^2.0.0",

"rn-host-detect": "^1.2.0",
"socketcluster-client": "^14.3.2"
"socketcluster-client": "^17.1.0"
},
"devDependencies": {
"@babel/cli": "^7.17.10",
"@babel/core": "^7.18.2",
"@babel/eslint-parser": "^7.18.2",
"@babel/plugin-transform-runtime": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@babel/preset-typescript": "^7.17.12",
"@babel/cli": "^7.20.7",
"@babel/core": "^7.20.12",
"@babel/eslint-parser": "^7.19.1",
"@babel/plugin-transform-runtime": "^7.19.6",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@types/jsan": "^3.1.2",
"@types/node": "^16.11.36",
"@types/node": "^18.11.18",
"@types/rn-host-detect": "^1.2.0",
"@types/socketcluster-client": "^13.0.5",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",
"@types/socketcluster-client": "^16.0.0",
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/parser": "^5.48.0",
"eslint": "^8.31.0",
"eslint-config-prettier": "^8.6.0",
"redux": "^4.2.0",
"rimraf": "^3.0.2",
"typescript": "~4.6.4"
"rimraf": "^4.1.0",
"typescript": "~4.9.4"
},

@@ -62,0 +62,0 @@ "peerDependencies": {

import { stringify, parse } from 'jsan';
import socketCluster, { SCClientSocket } from 'socketcluster-client';
import socketClusterClient, { AGClientSocket } from 'socketcluster-client';
import configureStore from './configureStore';

@@ -182,3 +182,3 @@ import { defaultSocketOptions } from './constants';

instanceId?: string;
socket?: SCClientSocket;
socket?: AGClientSocket;
sendTo?: string;

@@ -245,3 +245,4 @@ instanceName: string | undefined;

type,
id: this.socket!.id,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
id: this.socket!.id!,
name: this.instanceName,

@@ -284,3 +285,4 @@ instanceId: this.appInstanceId,

}
this.socket!.emit(this.socket!.id ? 'log' : 'log-noid', message);
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
void this.socket!.transmit(this.socket!.id ? 'log' : 'log-noid', message);
}

@@ -306,3 +308,5 @@

(message.type === 'SYNC' &&
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
this.socket!.id &&
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
message.id !== this.socket!.id)

@@ -394,11 +398,18 @@ ) {

login() {
this.socket!.emit('login', 'master', (err: Error, channelName: string) => {
if (err) {
console.log(err);
return;
void (async () => {
try {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const channelName = (await this.socket!.invoke(
'login',
'master'
)) as string;
this.channel = channelName;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket!.subscribe(channelName)) {
this.handleMessages(data as Message<S, A>);
}
} catch (error) {
console.log(error);
}
this.channel = channelName;
this.socket!.subscribe(channelName).watch(this.handleMessages);
this.socket!.on(channelName, this.handleMessages);
});
})();
this.started = true;

@@ -412,7 +423,5 @@ this.relay('START');

if (!this.socket) return;
this.socket.destroyChannel(this.channel!);
if (keepConnected) {
this.socket.off(this.channel, this.handleMessages);
} else {
this.socket.off();
void this.socket.unsubscribe(this.channel!);
this.socket.closeChannel(this.channel!);
if (!keepConnected) {
this.socket.disconnect();

@@ -429,32 +438,44 @@ }

this.socket = socketCluster.create(this.socketOptions);
this.socket = socketClusterClient.create(this.socketOptions);
this.socket.on('error', (err) => {
// if we've already had this error before, increment it's counter, otherwise assign it '1' since we've had the error once.
// eslint-disable-next-line no-prototype-builtins
this.errorCounts[err.name] = this.errorCounts.hasOwnProperty(err.name)
? this.errorCounts[err.name] + 1
: 1;
void (async () => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket!.listener('error')) {
// if we've already had this error before, increment it's counter, otherwise assign it '1' since we've had the error once.
// eslint-disable-next-line no-prototype-builtins,@typescript-eslint/no-unsafe-argument
this.errorCounts[data.error.name] = this.errorCounts.hasOwnProperty(
data.error.name
)
? this.errorCounts[data.error.name] + 1
: 1;
if (this.suppressConnectErrors) {
if (this.errorCounts[err.name] === 1) {
console.log(
'remote-redux-devtools: Socket connection errors are being suppressed. ' +
'\n' +
"This can be disabled by setting suppressConnectErrors to 'false'."
);
console.log(err);
if (this.suppressConnectErrors) {
if (this.errorCounts[data.error.name] === 1) {
console.log(
'remote-redux-devtools: Socket connection errors are being suppressed. ' +
'\n' +
"This can be disabled by setting suppressConnectErrors to 'false'."
);
console.log(data.error);
}
} else {
console.log(data.error);
}
} else {
console.log(err);
}
});
this.socket.on('connect', () => {
console.log('connected to remotedev-server');
this.errorCounts = {}; // clear the errorCounts object, so that we'll log any new errors in the event of a disconnect
this.login();
});
this.socket.on('disconnect', () => {
this.stop(true);
});
})();
void (async () => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket!.listener('connect')) {
console.log('connected to remotedev-server');
this.errorCounts = {}; // clear the errorCounts object, so that we'll log any new errors in the event of a disconnect
this.login();
}
})();
void (async () => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
for await (const data of this.socket!.listener('disconnect')) {
this.stop(true);
}
})();
};

@@ -461,0 +482,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc