cozy-bar 29.3.0 → 31.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/AppsMenu/AppsMenuContent.js +1 -10
- package/dist/components/AppsMenu/components/AppItem.js +8 -2
- package/dist/components/AppsMenu/index.js +10 -1
- package/dist/components/Bar.js +31 -51
- package/dist/components/Bar.spec.jsx +18 -37
- package/dist/components/BarComponent.js +5 -32
- package/dist/components/UserMenu/UserMenuContent.js +1 -8
- package/dist/components/UserMenu/index.js +4 -1
- package/dist/components/helpers.js +40 -0
- package/dist/components/utils/HelpLink.js +8 -10
- package/dist/index.js +1 -8
- package/dist/index.spec.jsx +12 -0
- package/dist/queries.js +21 -0
- package/package.json +4 -12
- package/dist/config/persistWhitelist.json +0 -4
- package/dist/lib/exceptions.js +0 -98
- package/dist/lib/realtime.js +0 -72
- package/dist/lib/reducers/apps.js +0 -285
- package/dist/lib/reducers/apps.spec.js +0 -51
- package/dist/lib/reducers/context.js +0 -109
- package/dist/lib/reducers/index.js +0 -50
- package/dist/lib/reducers/settings.js +0 -173
- package/dist/lib/stack-client.js +0 -356
- package/dist/lib/stack.js +0 -111
- package/dist/lib/store/index.js +0 -45
package/dist/lib/exceptions.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.UnavailableStackException = exports.UnauthorizedStackException = exports.ServerErrorException = exports.NotFoundException = exports.MethodNotAllowedException = exports.ForbiddenException = void 0;
|
|
8
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
9
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
11
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
12
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
13
|
-
var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
|
|
14
|
-
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
|
|
15
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
16
|
-
var ForbiddenException = exports.ForbiddenException = /*#__PURE__*/function (_Error) {
|
|
17
|
-
function ForbiddenException(message) {
|
|
18
|
-
var _this;
|
|
19
|
-
(0, _classCallCheck2.default)(this, ForbiddenException);
|
|
20
|
-
_this = _callSuper(this, ForbiddenException);
|
|
21
|
-
_this.name = 'Forbidden';
|
|
22
|
-
_this.status = 403;
|
|
23
|
-
_this.message = message || 'The application does not have permission to access this resource.';
|
|
24
|
-
_this.stack = new Error().stack;
|
|
25
|
-
return _this;
|
|
26
|
-
}
|
|
27
|
-
(0, _inherits2.default)(ForbiddenException, _Error);
|
|
28
|
-
return (0, _createClass2.default)(ForbiddenException);
|
|
29
|
-
}(/*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
|
|
30
|
-
var ServerErrorException = exports.ServerErrorException = /*#__PURE__*/function (_Error2) {
|
|
31
|
-
function ServerErrorException(message) {
|
|
32
|
-
var _this2;
|
|
33
|
-
(0, _classCallCheck2.default)(this, ServerErrorException);
|
|
34
|
-
_this2 = _callSuper(this, ServerErrorException);
|
|
35
|
-
_this2.name = 'ServerError';
|
|
36
|
-
_this2.status = 500;
|
|
37
|
-
_this2.message = message || 'A server error occurred';
|
|
38
|
-
_this2.stack = new Error().stack;
|
|
39
|
-
return _this2;
|
|
40
|
-
}
|
|
41
|
-
(0, _inherits2.default)(ServerErrorException, _Error2);
|
|
42
|
-
return (0, _createClass2.default)(ServerErrorException);
|
|
43
|
-
}(/*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
|
|
44
|
-
var NotFoundException = exports.NotFoundException = /*#__PURE__*/function (_Error3) {
|
|
45
|
-
function NotFoundException(message) {
|
|
46
|
-
var _this3;
|
|
47
|
-
(0, _classCallCheck2.default)(this, NotFoundException);
|
|
48
|
-
_this3 = _callSuper(this, NotFoundException);
|
|
49
|
-
_this3.name = 'NotFound';
|
|
50
|
-
_this3.status = 404;
|
|
51
|
-
_this3.message = message || 'The ressource was not found';
|
|
52
|
-
_this3.stack = new Error().stack;
|
|
53
|
-
return _this3;
|
|
54
|
-
}
|
|
55
|
-
(0, _inherits2.default)(NotFoundException, _Error3);
|
|
56
|
-
return (0, _createClass2.default)(NotFoundException);
|
|
57
|
-
}(/*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
|
|
58
|
-
var MethodNotAllowedException = exports.MethodNotAllowedException = /*#__PURE__*/function (_Error4) {
|
|
59
|
-
function MethodNotAllowedException(message) {
|
|
60
|
-
var _this4;
|
|
61
|
-
(0, _classCallCheck2.default)(this, MethodNotAllowedException);
|
|
62
|
-
_this4 = _callSuper(this, MethodNotAllowedException);
|
|
63
|
-
_this4.name = 'MethodNotAllowed';
|
|
64
|
-
_this4.status = 405;
|
|
65
|
-
_this4.message = message || 'Method not allowed';
|
|
66
|
-
_this4.stack = new Error().stack;
|
|
67
|
-
return _this4;
|
|
68
|
-
}
|
|
69
|
-
(0, _inherits2.default)(MethodNotAllowedException, _Error4);
|
|
70
|
-
return (0, _createClass2.default)(MethodNotAllowedException);
|
|
71
|
-
}(/*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
|
|
72
|
-
var UnavailableStackException = exports.UnavailableStackException = /*#__PURE__*/function (_Error5) {
|
|
73
|
-
function UnavailableStackException(message) {
|
|
74
|
-
var _this5;
|
|
75
|
-
(0, _classCallCheck2.default)(this, UnavailableStackException);
|
|
76
|
-
_this5 = _callSuper(this, UnavailableStackException);
|
|
77
|
-
_this5.name = 'UnavailableStack';
|
|
78
|
-
_this5.message = message || 'The stack is temporarily unavailable';
|
|
79
|
-
_this5.stack = new Error().stack;
|
|
80
|
-
return _this5;
|
|
81
|
-
}
|
|
82
|
-
(0, _inherits2.default)(UnavailableStackException, _Error5);
|
|
83
|
-
return (0, _createClass2.default)(UnavailableStackException);
|
|
84
|
-
}(/*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
|
|
85
|
-
var UnauthorizedStackException = exports.UnauthorizedStackException = /*#__PURE__*/function (_Error6) {
|
|
86
|
-
function UnauthorizedStackException(message) {
|
|
87
|
-
var _this6;
|
|
88
|
-
(0, _classCallCheck2.default)(this, UnauthorizedStackException);
|
|
89
|
-
_this6 = _callSuper(this, UnauthorizedStackException);
|
|
90
|
-
_this6.name = 'UnauthorizedStack';
|
|
91
|
-
_this6.status = 401;
|
|
92
|
-
_this6.message = message || 'The app is not allowed to access to the requested resource';
|
|
93
|
-
_this6.stack = new Error().stack;
|
|
94
|
-
return _this6;
|
|
95
|
-
}
|
|
96
|
-
(0, _inherits2.default)(UnauthorizedStackException, _Error6);
|
|
97
|
-
return (0, _createClass2.default)(UnauthorizedStackException);
|
|
98
|
-
}(/*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
|
package/dist/lib/realtime.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
-
var APPS_DOCTYPE = 'io.cozy.apps';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Initialize realtime sockets
|
|
14
|
-
*
|
|
15
|
-
* @private
|
|
16
|
-
* @param {object}
|
|
17
|
-
* @returns {Promise}
|
|
18
|
-
*/
|
|
19
|
-
function initializeRealtime(_ref) {
|
|
20
|
-
var getApp = _ref.getApp,
|
|
21
|
-
onCreate = _ref.onCreate,
|
|
22
|
-
onDelete = _ref.onDelete,
|
|
23
|
-
cozyClient = _ref.cozyClient;
|
|
24
|
-
var handleAppCreation = /*#__PURE__*/function () {
|
|
25
|
-
var _ref2 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(app) {
|
|
26
|
-
var fullApp;
|
|
27
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
28
|
-
while (1) switch (_context.prev = _context.next) {
|
|
29
|
-
case 0:
|
|
30
|
-
_context.prev = 0;
|
|
31
|
-
_context.next = 3;
|
|
32
|
-
return getApp(app.slug);
|
|
33
|
-
case 3:
|
|
34
|
-
fullApp = _context.sent;
|
|
35
|
-
_context.next = 9;
|
|
36
|
-
break;
|
|
37
|
-
case 6:
|
|
38
|
-
_context.prev = 6;
|
|
39
|
-
_context.t0 = _context["catch"](0);
|
|
40
|
-
throw new Error("Cannot fetch app ".concat(app.slug, ": ").concat(_context.t0.message));
|
|
41
|
-
case 9:
|
|
42
|
-
if (typeof onCreate === 'function') {
|
|
43
|
-
onCreate(fullApp);
|
|
44
|
-
}
|
|
45
|
-
case 10:
|
|
46
|
-
case "end":
|
|
47
|
-
return _context.stop();
|
|
48
|
-
}
|
|
49
|
-
}, _callee, null, [[0, 6]]);
|
|
50
|
-
}));
|
|
51
|
-
return function handleAppCreation(_x) {
|
|
52
|
-
return _ref2.apply(this, arguments);
|
|
53
|
-
};
|
|
54
|
-
}();
|
|
55
|
-
var handleAppRemoval = function handleAppRemoval(app) {
|
|
56
|
-
if (typeof onDelete === 'function') {
|
|
57
|
-
onDelete(app);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
try {
|
|
61
|
-
var realtime = cozyClient.plugins.realtime;
|
|
62
|
-
if (!realtime) {
|
|
63
|
-
throw new Error('You must include the realtime plugin to use cozy-bar realtime features.');
|
|
64
|
-
}
|
|
65
|
-
realtime.subscribe('created', APPS_DOCTYPE, handleAppCreation);
|
|
66
|
-
realtime.subscribe('deleted', APPS_DOCTYPE, handleAppRemoval);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
// eslint-disable-next-line no-console
|
|
69
|
-
console.warn("Cannot initialize realtime in Cozy-bar: ".concat(error.message));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
var _default = exports.default = initializeRealtime;
|
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.setIsSettingsAppInstalled = exports.setInfos = exports.setDefaultApp = exports.receiveApp = exports.isFetchingApps = exports.isCurrentApp = exports.hasFetched = exports.getIsSettingsAppInstalled = exports.getHomeApp = exports.getApps = exports.fetchApps = exports.deleteApp = exports.default = void 0;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
-
var _stack = _interopRequireDefault(require("../stack"));
|
|
12
|
-
var _lodash = _interopRequireDefault(require("lodash.unionwith"));
|
|
13
|
-
var _cozyFlags = _interopRequireDefault(require("cozy-flags"));
|
|
14
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
-
// constants
|
|
17
|
-
var DELETE_APP = 'DELETE_APP';
|
|
18
|
-
var RECEIVE_APP = 'RECEIVE_APP';
|
|
19
|
-
var RECEIVE_APP_LIST = 'RECEIVE_APP_LIST';
|
|
20
|
-
var RECEIVE_HOME_APP = 'RECEIVE_HOME_APP';
|
|
21
|
-
var FETCH_APPS = 'FETCH_APPS';
|
|
22
|
-
var FETCH_APPS_FAILURE = 'FETCH_APPS_FAILURE';
|
|
23
|
-
var FETCH_APPS_SUCCESS = 'FETCH_APPS_SUCCESS';
|
|
24
|
-
var SET_INFOS = 'SET_INFOS';
|
|
25
|
-
var SET_IS_SETTINGS_APP_INSTALLED = 'SET_IS_SETTINGS_APP_INSTALLED';
|
|
26
|
-
var isCurrentApp = exports.isCurrentApp = function isCurrentApp(state, app) {
|
|
27
|
-
return app.slug === state.appSlug;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// selectors
|
|
31
|
-
var getApps = exports.getApps = function getApps(state) {
|
|
32
|
-
if (!state.apps) return [];
|
|
33
|
-
return state.apps;
|
|
34
|
-
};
|
|
35
|
-
var getHomeApp = exports.getHomeApp = function getHomeApp(state) {
|
|
36
|
-
return state.homeApp;
|
|
37
|
-
};
|
|
38
|
-
var isFetchingApps = exports.isFetchingApps = function isFetchingApps(state) {
|
|
39
|
-
return state ? state.isFetching : false;
|
|
40
|
-
};
|
|
41
|
-
var getIsSettingsAppInstalled = exports.getIsSettingsAppInstalled = function getIsSettingsAppInstalled(state) {
|
|
42
|
-
return state ? state.isSettingsAppInstalled : false;
|
|
43
|
-
};
|
|
44
|
-
var hasFetched = exports.hasFetched = function hasFetched(state) {
|
|
45
|
-
return state.hasFetched;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
// actions
|
|
49
|
-
var deleteApp = exports.deleteApp = function deleteApp(app) {
|
|
50
|
-
return {
|
|
51
|
-
type: DELETE_APP,
|
|
52
|
-
app: app
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
var receiveApp = exports.receiveApp = function receiveApp(app) {
|
|
56
|
-
return {
|
|
57
|
-
type: RECEIVE_APP,
|
|
58
|
-
app: app
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
var receiveAppList = function receiveAppList(apps) {
|
|
62
|
-
return {
|
|
63
|
-
type: RECEIVE_APP_LIST,
|
|
64
|
-
apps: apps
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
var receiveHomeApp = function receiveHomeApp(homeApp) {
|
|
68
|
-
return {
|
|
69
|
-
type: RECEIVE_HOME_APP,
|
|
70
|
-
homeApp: homeApp
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
var setInfos = exports.setInfos = function setInfos(appName, appNamePrefix, appSlug) {
|
|
74
|
-
return {
|
|
75
|
-
type: SET_INFOS,
|
|
76
|
-
appName: appName,
|
|
77
|
-
appNamePrefix: appNamePrefix,
|
|
78
|
-
appSlug: appSlug
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
var setIsSettingsAppInstalled = exports.setIsSettingsAppInstalled = function setIsSettingsAppInstalled(isSettingsAppInstalled) {
|
|
82
|
-
return {
|
|
83
|
-
type: SET_IS_SETTINGS_APP_INSTALLED,
|
|
84
|
-
isSettingsAppInstalled: isSettingsAppInstalled
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// actions async
|
|
89
|
-
var fetchApps = exports.fetchApps = function fetchApps() {
|
|
90
|
-
return /*#__PURE__*/function () {
|
|
91
|
-
var _ref = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(dispatch) {
|
|
92
|
-
var rawAppList, isSettingsAppInstalled, excludedApps, apps;
|
|
93
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
94
|
-
while (1) switch (_context.prev = _context.next) {
|
|
95
|
-
case 0:
|
|
96
|
-
_context.prev = 0;
|
|
97
|
-
dispatch({
|
|
98
|
-
type: FETCH_APPS
|
|
99
|
-
});
|
|
100
|
-
_context.next = 4;
|
|
101
|
-
return _stack.default.get.apps();
|
|
102
|
-
case 4:
|
|
103
|
-
rawAppList = _context.sent;
|
|
104
|
-
if (rawAppList.length) {
|
|
105
|
-
_context.next = 7;
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
throw new Error('No installed apps found by the bar');
|
|
109
|
-
case 7:
|
|
110
|
-
// We need to store if settings app is installed because it maybe be filtered because of apps.hidden
|
|
111
|
-
isSettingsAppInstalled = rawAppList.some(function (app) {
|
|
112
|
-
var _app$attributes;
|
|
113
|
-
return (app === null || app === void 0 || (_app$attributes = app.attributes) === null || _app$attributes === void 0 ? void 0 : _app$attributes.slug) === 'settings';
|
|
114
|
-
});
|
|
115
|
-
_context.next = 10;
|
|
116
|
-
return dispatch(setIsSettingsAppInstalled(isSettingsAppInstalled));
|
|
117
|
-
case 10:
|
|
118
|
-
excludedApps = (0, _cozyFlags.default)('apps.hidden') || [];
|
|
119
|
-
apps = rawAppList.map(mapApp).filter(function (app) {
|
|
120
|
-
return !excludedApps.includes(app.slug);
|
|
121
|
-
}); // TODO load only one time icons
|
|
122
|
-
_context.next = 14;
|
|
123
|
-
return dispatch(setDefaultApp(apps));
|
|
124
|
-
case 14:
|
|
125
|
-
_context.next = 16;
|
|
126
|
-
return dispatch(receiveAppList(apps));
|
|
127
|
-
case 16:
|
|
128
|
-
_context.next = 22;
|
|
129
|
-
break;
|
|
130
|
-
case 18:
|
|
131
|
-
_context.prev = 18;
|
|
132
|
-
_context.t0 = _context["catch"](0);
|
|
133
|
-
dispatch({
|
|
134
|
-
type: FETCH_APPS_FAILURE
|
|
135
|
-
});
|
|
136
|
-
// eslint-disable-next-line no-console
|
|
137
|
-
console.warn(_context.t0.message ? _context.t0.message : _context.t0);
|
|
138
|
-
case 22:
|
|
139
|
-
case "end":
|
|
140
|
-
return _context.stop();
|
|
141
|
-
}
|
|
142
|
-
}, _callee, null, [[0, 18]]);
|
|
143
|
-
}));
|
|
144
|
-
return function (_x) {
|
|
145
|
-
return _ref.apply(this, arguments);
|
|
146
|
-
};
|
|
147
|
-
}();
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
*
|
|
152
|
-
* @param {Array} appsList
|
|
153
|
-
*/
|
|
154
|
-
var setDefaultApp = exports.setDefaultApp = function setDefaultApp(appsList) {
|
|
155
|
-
return /*#__PURE__*/function () {
|
|
156
|
-
var _ref2 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2(dispatch) {
|
|
157
|
-
var HOME_APP_SLUG, homeApp;
|
|
158
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
159
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
160
|
-
case 0:
|
|
161
|
-
_context2.prev = 0;
|
|
162
|
-
HOME_APP_SLUG = 'home';
|
|
163
|
-
homeApp = findAppInArray(HOME_APP_SLUG, appsList);
|
|
164
|
-
if (!homeApp) {
|
|
165
|
-
_context2.next = 5;
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
return _context2.abrupt("return", dispatch(receiveHomeApp(homeApp)));
|
|
169
|
-
case 5:
|
|
170
|
-
_context2.next = 10;
|
|
171
|
-
break;
|
|
172
|
-
case 7:
|
|
173
|
-
_context2.prev = 7;
|
|
174
|
-
_context2.t0 = _context2["catch"](0);
|
|
175
|
-
// eslint-disable-next-line no-console
|
|
176
|
-
console.warn("Cozy-bar cannot fetch home app data: ".concat(_context2.t0.message));
|
|
177
|
-
case 10:
|
|
178
|
-
case "end":
|
|
179
|
-
return _context2.stop();
|
|
180
|
-
}
|
|
181
|
-
}, _callee2, null, [[0, 7]]);
|
|
182
|
-
}));
|
|
183
|
-
return function (_x2) {
|
|
184
|
-
return _ref2.apply(this, arguments);
|
|
185
|
-
};
|
|
186
|
-
}();
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
// reducers
|
|
190
|
-
var defaultState = {
|
|
191
|
-
apps: [],
|
|
192
|
-
homeApp: null,
|
|
193
|
-
isFetching: true,
|
|
194
|
-
appName: null,
|
|
195
|
-
appNamePrefix: null,
|
|
196
|
-
appSlug: null,
|
|
197
|
-
hasFetched: false,
|
|
198
|
-
isSettingsAppInstalled: false
|
|
199
|
-
};
|
|
200
|
-
var reducer = function reducer() {
|
|
201
|
-
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState;
|
|
202
|
-
var action = arguments.length > 1 ? arguments[1] : undefined;
|
|
203
|
-
switch (action.type) {
|
|
204
|
-
case FETCH_APPS:
|
|
205
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
206
|
-
isFetching: true
|
|
207
|
-
});
|
|
208
|
-
case FETCH_APPS_SUCCESS:
|
|
209
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
210
|
-
isFetching: false
|
|
211
|
-
});
|
|
212
|
-
case FETCH_APPS_FAILURE:
|
|
213
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
214
|
-
isFetching: false
|
|
215
|
-
});
|
|
216
|
-
case RECEIVE_APP:
|
|
217
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
218
|
-
apps: (0, _lodash.default)(state.apps, [mapApp(action.app)], function (appA, appB) {
|
|
219
|
-
return appA.slug === appB.slug;
|
|
220
|
-
})
|
|
221
|
-
});
|
|
222
|
-
case RECEIVE_APP_LIST:
|
|
223
|
-
{
|
|
224
|
-
var appsList = action.apps.map(function (app) {
|
|
225
|
-
return _objectSpread(_objectSpread({}, app), {}, {
|
|
226
|
-
isCurrentApp: isCurrentApp(state, app)
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
230
|
-
isFetching: false,
|
|
231
|
-
hasFetched: true,
|
|
232
|
-
apps: appsList
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
case RECEIVE_HOME_APP:
|
|
236
|
-
{
|
|
237
|
-
var homeApp = action.homeApp;
|
|
238
|
-
return isCurrentApp(state, homeApp) ? _objectSpread(_objectSpread({}, state), {}, {
|
|
239
|
-
homeApp: _objectSpread(_objectSpread({}, homeApp), {}, {
|
|
240
|
-
isCurrentApp: true
|
|
241
|
-
})
|
|
242
|
-
}) : _objectSpread(_objectSpread({}, state), {}, {
|
|
243
|
-
homeApp: homeApp
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
case DELETE_APP:
|
|
247
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
248
|
-
apps: state.apps.filter(function (app) {
|
|
249
|
-
return app.slug !== action.app.slug;
|
|
250
|
-
})
|
|
251
|
-
});
|
|
252
|
-
case SET_INFOS:
|
|
253
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
254
|
-
appName: action.appName,
|
|
255
|
-
appNamePrefix: action.appNamePrefix,
|
|
256
|
-
appSlug: action.appSlug
|
|
257
|
-
});
|
|
258
|
-
case SET_IS_SETTINGS_APP_INSTALLED:
|
|
259
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
260
|
-
isSettingsAppInstalled: action.isSettingsAppInstalled
|
|
261
|
-
});
|
|
262
|
-
default:
|
|
263
|
-
return state;
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
var _default = exports.default = reducer; // helpers
|
|
267
|
-
var camelCasify = function camelCasify(object) {
|
|
268
|
-
return !!object && Object.keys(object).reduce(function (acc, key) {
|
|
269
|
-
var camelCaseKey = key.split('_').map(function (segment, index) {
|
|
270
|
-
return index ? segment.charAt(0).toUpperCase() + segment.slice(1) : segment;
|
|
271
|
-
}).join('');
|
|
272
|
-
acc[camelCaseKey] = object[key];
|
|
273
|
-
return acc;
|
|
274
|
-
}, {});
|
|
275
|
-
};
|
|
276
|
-
var mapApp = function mapApp(app) {
|
|
277
|
-
return _objectSpread(_objectSpread(_objectSpread({}, app), camelCasify(app.attributes)), {}, {
|
|
278
|
-
href: app.links && app.links.related
|
|
279
|
-
});
|
|
280
|
-
};
|
|
281
|
-
var findAppInArray = function findAppInArray(appSlug, apps) {
|
|
282
|
-
return apps.find(function (app) {
|
|
283
|
-
return app.slug === appSlug;
|
|
284
|
-
});
|
|
285
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import CozyClient from 'cozy-client'
|
|
2
|
-
import client from 'lib/stack-client.js'
|
|
3
|
-
import stack from 'lib/stack.js'
|
|
4
|
-
import { setDefaultApp } from './apps'
|
|
5
|
-
|
|
6
|
-
const cozyURL = 'https://test.mycozy.cloud'
|
|
7
|
-
const token = 'mytoken'
|
|
8
|
-
const fakeStackClient = {
|
|
9
|
-
uri: cozyURL,
|
|
10
|
-
token: { token }
|
|
11
|
-
}
|
|
12
|
-
describe('app reducer', () => {
|
|
13
|
-
beforeAll(() => {
|
|
14
|
-
jest.clearAllMocks()
|
|
15
|
-
const params = {
|
|
16
|
-
cozyClient: new CozyClient({ fakeStackClient }),
|
|
17
|
-
onCreate: function() {},
|
|
18
|
-
onDelete: function() {}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
stack.init(params)
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('dispatch RECEIVE_HOME_APP if context has default redirection', async () => {
|
|
25
|
-
jest.spyOn(client.get, 'context').mockResolvedValue({
|
|
26
|
-
data: { attributes: { default_redirection: 'home/' } }
|
|
27
|
-
})
|
|
28
|
-
const dispatchMock = jest.fn(x => x)
|
|
29
|
-
|
|
30
|
-
const setted = setDefaultApp([{ slug: 'home' }])
|
|
31
|
-
await setted(dispatchMock)
|
|
32
|
-
|
|
33
|
-
expect(dispatchMock).toHaveBeenCalledWith({
|
|
34
|
-
homeApp: { slug: 'home' },
|
|
35
|
-
type: 'RECEIVE_HOME_APP'
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('dispatch RECEIVE_HOME_APP with hardcoded home if context has no default redirection', async () => {
|
|
40
|
-
jest.spyOn(client.get, 'context').mockResolvedValue({})
|
|
41
|
-
const dispatchMock = jest.fn(x => x)
|
|
42
|
-
|
|
43
|
-
const setted = setDefaultApp([{ slug: 'home' }])
|
|
44
|
-
await setted(dispatchMock)
|
|
45
|
-
|
|
46
|
-
expect(dispatchMock).toHaveBeenCalledWith({
|
|
47
|
-
homeApp: { slug: 'home' },
|
|
48
|
-
type: 'RECEIVE_HOME_APP'
|
|
49
|
-
})
|
|
50
|
-
})
|
|
51
|
-
})
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.getHelpLink = exports.fetchContext = exports.default = void 0;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
-
var _stack = _interopRequireDefault(require("../stack"));
|
|
12
|
-
var _settings = require("./settings");
|
|
13
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
15
|
-
var FETCH_CONTEXT = 'FETCH_CONTEXT';
|
|
16
|
-
var FETCH_CONTEXT_SUCCESS = 'FETCH_CONTEXT_SUCCESS';
|
|
17
|
-
var RECEIVE_NO_CONTEXT = 'RECEIVE_NO_CONTEXT';
|
|
18
|
-
|
|
19
|
-
// selectors
|
|
20
|
-
var getHelpLink = exports.getHelpLink = function getHelpLink(state) {
|
|
21
|
-
return state.helpLink;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// actions
|
|
25
|
-
var fetchContext = exports.fetchContext = function fetchContext() {
|
|
26
|
-
return /*#__PURE__*/function () {
|
|
27
|
-
var _ref = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(dispatch, getState) {
|
|
28
|
-
var context;
|
|
29
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
30
|
-
while (1) switch (_context.prev = _context.next) {
|
|
31
|
-
case 0:
|
|
32
|
-
dispatch({
|
|
33
|
-
type: FETCH_CONTEXT
|
|
34
|
-
});
|
|
35
|
-
if (!getState().cozyBar.context.contextNotExist) {
|
|
36
|
-
_context.next = 3;
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
return _context.abrupt("return", dispatch({
|
|
40
|
-
type: FETCH_CONTEXT_SUCCESS,
|
|
41
|
-
context: null
|
|
42
|
-
}));
|
|
43
|
-
case 3:
|
|
44
|
-
_context.prev = 3;
|
|
45
|
-
_context.next = 6;
|
|
46
|
-
return _stack.default.get.context();
|
|
47
|
-
case 6:
|
|
48
|
-
context = _context.sent;
|
|
49
|
-
return _context.abrupt("return", dispatch({
|
|
50
|
-
type: FETCH_CONTEXT_SUCCESS,
|
|
51
|
-
context: context
|
|
52
|
-
}));
|
|
53
|
-
case 10:
|
|
54
|
-
_context.prev = 10;
|
|
55
|
-
_context.t0 = _context["catch"](3);
|
|
56
|
-
if (_context.t0.status && _context.t0.status === 404) {
|
|
57
|
-
dispatch({
|
|
58
|
-
type: RECEIVE_NO_CONTEXT
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
// eslint-disable-next-line no-console
|
|
62
|
-
console.warn('Cannot get Cozy context');
|
|
63
|
-
return _context.abrupt("return", null);
|
|
64
|
-
case 15:
|
|
65
|
-
case "end":
|
|
66
|
-
return _context.stop();
|
|
67
|
-
}
|
|
68
|
-
}, _callee, null, [[3, 10]]);
|
|
69
|
-
}));
|
|
70
|
-
return function (_x, _x2) {
|
|
71
|
-
return _ref.apply(this, arguments);
|
|
72
|
-
};
|
|
73
|
-
}();
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
// reducers
|
|
77
|
-
var defaultState = {
|
|
78
|
-
contextNotExist: false,
|
|
79
|
-
helpLink: null,
|
|
80
|
-
isFetching: false
|
|
81
|
-
};
|
|
82
|
-
var reducer = function reducer() {
|
|
83
|
-
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState;
|
|
84
|
-
var action = arguments.length > 1 ? arguments[1] : undefined;
|
|
85
|
-
switch (action.type) {
|
|
86
|
-
case FETCH_CONTEXT:
|
|
87
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
88
|
-
isFetching: true
|
|
89
|
-
});
|
|
90
|
-
case FETCH_CONTEXT_SUCCESS:
|
|
91
|
-
{
|
|
92
|
-
var attr = action.context && action.context.data && action.context.data.attributes;
|
|
93
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
94
|
-
helpLink: attr && attr['help_link'] || null,
|
|
95
|
-
isFetching: false,
|
|
96
|
-
contextNotExist: false
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
case RECEIVE_NO_CONTEXT:
|
|
100
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
101
|
-
contextNotExist: true
|
|
102
|
-
});
|
|
103
|
-
case _settings.LOG_OUT:
|
|
104
|
-
return defaultState;
|
|
105
|
-
default:
|
|
106
|
-
return state;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
var _default = exports.default = reducer;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.setInfos = exports.reducers = exports.onRealtimeDelete = exports.onRealtimeCreate = exports.logOut = exports.isSettingsBusy = exports.isFetchingSettings = exports.isFetchingApps = exports.isCurrentApp = exports.hasFetched = exports.getStorageData = exports.getIsSettingsAppInstalled = exports.getHomeApp = exports.getHelpLink = exports.getApps = exports.fetchSettingsData = exports.fetchContext = exports.fetchApps = exports.default = void 0;
|
|
7
|
-
var _redux = require("redux");
|
|
8
|
-
var _apps = _interopRequireWildcard(require("./apps"));
|
|
9
|
-
var apps = _apps;
|
|
10
|
-
var _settings = _interopRequireWildcard(require("./settings"));
|
|
11
|
-
var settings = _settings;
|
|
12
|
-
var _context = _interopRequireWildcard(require("./context"));
|
|
13
|
-
var context = _context;
|
|
14
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
15
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
-
var proxy = function proxy(attr, method) {
|
|
17
|
-
return function (state) {
|
|
18
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
19
|
-
args[_key - 1] = arguments[_key];
|
|
20
|
-
}
|
|
21
|
-
return method.apply(void 0, [state.cozyBar[attr]].concat(args));
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
var fetchApps = exports.fetchApps = apps.fetchApps;
|
|
25
|
-
var setInfos = exports.setInfos = apps.setInfos;
|
|
26
|
-
var fetchSettingsData = exports.fetchSettingsData = settings.fetchSettingsData;
|
|
27
|
-
var logOut = exports.logOut = settings.logOut;
|
|
28
|
-
var fetchContext = exports.fetchContext = context.fetchContext;
|
|
29
|
-
var getIsSettingsAppInstalled = exports.getIsSettingsAppInstalled = proxy('apps', apps.getIsSettingsAppInstalled);
|
|
30
|
-
var getApps = exports.getApps = proxy('apps', apps.getApps);
|
|
31
|
-
var getHomeApp = exports.getHomeApp = proxy('apps', apps.getHomeApp);
|
|
32
|
-
var isFetchingApps = exports.isFetchingApps = proxy('apps', apps.isFetchingApps);
|
|
33
|
-
var isCurrentApp = exports.isCurrentApp = proxy('apps', apps.isCurrentApp);
|
|
34
|
-
var hasFetched = exports.hasFetched = proxy('apps', apps.hasFetched);
|
|
35
|
-
var getStorageData = exports.getStorageData = proxy('settings', settings.getStorageData);
|
|
36
|
-
var isSettingsBusy = exports.isSettingsBusy = proxy('settings', settings.isSettingsBusy);
|
|
37
|
-
var isFetchingSettings = exports.isFetchingSettings = proxy('settings', settings.isFetchingSettings);
|
|
38
|
-
var getHelpLink = exports.getHelpLink = proxy('context', context.getHelpLink);
|
|
39
|
-
|
|
40
|
-
// realtime handlers
|
|
41
|
-
var onRealtimeCreate = exports.onRealtimeCreate = apps.receiveApp;
|
|
42
|
-
var onRealtimeDelete = exports.onRealtimeDelete = apps.deleteApp;
|
|
43
|
-
var reducers = exports.reducers = {
|
|
44
|
-
cozyBar: (0, _redux.combineReducers)({
|
|
45
|
-
apps: _apps.default,
|
|
46
|
-
context: _context.default,
|
|
47
|
-
settings: _settings.default
|
|
48
|
-
})
|
|
49
|
-
};
|
|
50
|
-
var _default = exports.default = (0, _redux.combineReducers)(reducers);
|