cozy-harvest-lib 13.0.1 → 13.2.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/CHANGELOG.md +28 -0
- package/dist/components/KonnectorConfiguration/DataTab/index.js +1 -1
- package/dist/components/cards/LaunchTriggerAlert.js +19 -15
- package/dist/components/cards/LaunchTriggerAlertMenu.js +11 -4
- package/dist/components/cards/helpers.js +7 -5
- package/dist/models/ConnectionFlow.js +49 -10
- package/dist/models/ConnectionFlow.spec.js +166 -71
- package/dist/models/withConnectionFlow.spec.js +7 -0
- package/dist/services/biWebView.spec.js +25 -9
- package/dist/services/budget-insight.spec.js +24 -9
- package/package.json +2 -2
- package/src/components/KonnectorConfiguration/DataTab/index.jsx +1 -1
- package/src/components/cards/LaunchTriggerAlert.jsx +21 -9
- package/src/components/cards/LaunchTriggerAlertMenu.jsx +13 -2
- package/src/components/cards/helpers.js +10 -5
- package/src/models/ConnectionFlow.js +50 -0
- package/src/models/ConnectionFlow.spec.js +94 -0
- package/src/models/withConnectionFlow.spec.jsx +6 -0
- package/src/services/biWebView.spec.js +9 -0
- package/src/services/budget-insight.spec.js +5 -0
- package/test/fixtures.js +17 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,34 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [13.2.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@13.1.0...cozy-harvest-lib@13.2.0) (2023-02-08)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add triggers realtime to ConnectionFlow ([b46616e](https://github.com/cozy/cozy-libs/commit/b46616ee9212af7609d8497eae7027cf50c7a63d))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [13.1.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@13.0.1...cozy-harvest-lib@13.1.0) (2023-02-03)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **harvest:** Move variables before use ([1aea052](https://github.com/cozy/cozy-libs/commit/1aea052824f2c5247531eb1e54ac71888655dd75))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* **harvest:** Add a maintenance message as a suffix ([fad4f45](https://github.com/cozy/cozy-libs/commit/fad4f458edac5d5ef7863e23da014753e6a68b7e))
|
|
28
|
+
* The sync button must redirect to the connection modal ([20ac4f8](https://github.com/cozy/cozy-libs/commit/20ac4f8d81c9823c40b376f439e3a49f9214456e))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
6
34
|
## [13.0.1](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@13.0.0...cozy-harvest-lib@13.0.1) (2023-02-02)
|
|
7
35
|
|
|
8
36
|
|
|
@@ -59,7 +59,7 @@ export var DataTab = function DataTab(_ref) {
|
|
|
59
59
|
return /*#__PURE__*/React.createElement("div", null, flag('harvest.inappconnectors.enabled') && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(LaunchTriggerCard, {
|
|
60
60
|
konnectorRoot: konnectorRoot,
|
|
61
61
|
flow: flow,
|
|
62
|
-
|
|
62
|
+
withMaintenanceDescription: true
|
|
63
63
|
}), isMobile && /*#__PURE__*/React.createElement(Divider, {
|
|
64
64
|
style: styles.divider
|
|
65
65
|
})), /*#__PURE__*/React.createElement("div", {
|
|
@@ -10,7 +10,7 @@ import Spinner from 'cozy-ui/transpiled/react/Spinner';
|
|
|
10
10
|
import Snackbar from 'cozy-ui/transpiled/react/Snackbar';
|
|
11
11
|
import WrenchCircleIcon from 'cozy-ui/transpiled/react/Icons/WrenchCircle';
|
|
12
12
|
import { makeStyles } from 'cozy-ui/transpiled/react/styles';
|
|
13
|
-
import { getKonnectorSlug } from '../../helpers/triggers';
|
|
13
|
+
import { getAccountId, getKonnectorSlug } from '../../helpers/triggers';
|
|
14
14
|
import { isRunnable, isDisconnected } from '../../helpers/konnectors';
|
|
15
15
|
import { useFlowState } from '../../models/withConnectionFlow';
|
|
16
16
|
import { SUCCESS } from '../../models/flowEvents';
|
|
@@ -25,12 +25,12 @@ var useStyles = makeStyles({
|
|
|
25
25
|
root: {
|
|
26
26
|
padding: '.5rem 1rem'
|
|
27
27
|
},
|
|
28
|
-
message: {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
} // 16px is the size of the icon
|
|
28
|
+
message: function message(_ref) {
|
|
29
|
+
var block = _ref.block;
|
|
30
|
+
return block && {
|
|
31
|
+
maxWidth: 'calc(100% - 16px - .5rem)' // 16px is the size of the icon
|
|
33
32
|
|
|
33
|
+
};
|
|
34
34
|
},
|
|
35
35
|
action: {
|
|
36
36
|
marginRight: '-.5rem'
|
|
@@ -44,7 +44,7 @@ export var LaunchTriggerAlert = function LaunchTriggerAlert(_ref2) {
|
|
|
44
44
|
t = _ref2.t,
|
|
45
45
|
konnectorRoot = _ref2.konnectorRoot,
|
|
46
46
|
historyAction = _ref2.historyAction,
|
|
47
|
-
|
|
47
|
+
withMaintenanceDescription = _ref2.withMaintenanceDescription;
|
|
48
48
|
var client = useClient();
|
|
49
49
|
|
|
50
50
|
var _useState = useState(false),
|
|
@@ -67,11 +67,11 @@ export var LaunchTriggerAlert = function LaunchTriggerAlert(_ref2) {
|
|
|
67
67
|
isInMaintenance = _useMaintenanceStatus2.isInMaintenance,
|
|
68
68
|
maintenanceMessages = _useMaintenanceStatus2.messages;
|
|
69
69
|
|
|
70
|
+
var isInError = !!error;
|
|
71
|
+
var block = isInError || !!withMaintenanceDescription && isInMaintenance;
|
|
70
72
|
var styles = useStyles({
|
|
71
73
|
block: block
|
|
72
74
|
});
|
|
73
|
-
var isInError = !!error;
|
|
74
|
-
var block = withDescription && (isInError || isInMaintenance);
|
|
75
75
|
var isKonnectorRunnable = isRunnable({
|
|
76
76
|
win: window,
|
|
77
77
|
konnector: konnector
|
|
@@ -82,6 +82,13 @@ export var LaunchTriggerAlert = function LaunchTriggerAlert(_ref2) {
|
|
|
82
82
|
setShowSuccessSnackbar(true);
|
|
83
83
|
}
|
|
84
84
|
}, [status]);
|
|
85
|
+
var SyncButtonAction = isInError ? function () {
|
|
86
|
+
return historyAction(konnectorRoot ? "".concat(konnectorRoot, "/accounts/").concat(getAccountId(trigger), "/edit") : '/edit', 'push');
|
|
87
|
+
} : function () {
|
|
88
|
+
return launch({
|
|
89
|
+
autoSuccessTimer: false
|
|
90
|
+
});
|
|
91
|
+
};
|
|
85
92
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Alert, {
|
|
86
93
|
color: isInError ? undefined : isInMaintenance ? 'var(--grey50)' : 'var(--paperBackgroundColor)',
|
|
87
94
|
severity: isInError ? 'error' : undefined,
|
|
@@ -103,11 +110,7 @@ export var LaunchTriggerAlert = function LaunchTriggerAlert(_ref2) {
|
|
|
103
110
|
size: "small",
|
|
104
111
|
disabled: running,
|
|
105
112
|
label: t('card.launchTrigger.button.label'),
|
|
106
|
-
onClick:
|
|
107
|
-
return launch({
|
|
108
|
-
autoSuccessTimer: false
|
|
109
|
-
});
|
|
110
|
-
}
|
|
113
|
+
onClick: SyncButtonAction
|
|
111
114
|
}), !block && /*#__PURE__*/React.createElement("div", {
|
|
112
115
|
style: {
|
|
113
116
|
margin: '-.5rem -.5rem -.5rem 0'
|
|
@@ -135,7 +138,8 @@ export var LaunchTriggerAlert = function LaunchTriggerAlert(_ref2) {
|
|
|
135
138
|
konnector: konnector,
|
|
136
139
|
trigger: trigger,
|
|
137
140
|
running: running,
|
|
138
|
-
expectingTriggerLaunch: expectingTriggerLaunch
|
|
141
|
+
expectingTriggerLaunch: expectingTriggerLaunch,
|
|
142
|
+
isInMaintenance: isInMaintenance
|
|
139
143
|
})), block && /*#__PURE__*/React.createElement("div", {
|
|
140
144
|
style: {
|
|
141
145
|
margin: '-1rem -1rem -1rem 0'
|
|
@@ -23,7 +23,8 @@ var LaunchTriggerAlertMenu = function LaunchTriggerAlertMenu(_ref) {
|
|
|
23
23
|
|
|
24
24
|
var _useFlowState = useFlowState(flow),
|
|
25
25
|
running = _useFlowState.running,
|
|
26
|
-
trigger = _useFlowState.trigger
|
|
26
|
+
trigger = _useFlowState.trigger,
|
|
27
|
+
error = _useFlowState.error;
|
|
27
28
|
|
|
28
29
|
var launch = flow.launch,
|
|
29
30
|
konnector = flow.konnector;
|
|
@@ -39,6 +40,14 @@ var LaunchTriggerAlertMenu = function LaunchTriggerAlertMenu(_ref) {
|
|
|
39
40
|
showOptions = _useState2[0],
|
|
40
41
|
setShowOptions = _useState2[1];
|
|
41
42
|
|
|
43
|
+
var isInError = !!error;
|
|
44
|
+
var SyncButtonAction = isInError ? function () {
|
|
45
|
+
return historyAction(konnectorRoot ? "".concat(konnectorRoot, "/accounts/").concat(getAccountId(trigger), "/edit") : '/edit', 'push');
|
|
46
|
+
} : function () {
|
|
47
|
+
return launch({
|
|
48
|
+
autoSuccessTimer: false
|
|
49
|
+
});
|
|
50
|
+
};
|
|
42
51
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(IconButton, {
|
|
43
52
|
ref: anchorRef,
|
|
44
53
|
onClick: function onClick() {
|
|
@@ -57,9 +66,7 @@ var LaunchTriggerAlertMenu = function LaunchTriggerAlertMenu(_ref) {
|
|
|
57
66
|
icon: SyncIcon
|
|
58
67
|
}),
|
|
59
68
|
onClick: function onClick() {
|
|
60
|
-
|
|
61
|
-
autoSuccessTimer: false
|
|
62
|
-
});
|
|
69
|
+
SyncButtonAction();
|
|
63
70
|
setShowOptions(false);
|
|
64
71
|
}
|
|
65
72
|
}, t('card.launchTrigger.button.label')), !isKonnectorDisconnected && /*#__PURE__*/React.createElement(ActionMenuItem, {
|
|
@@ -23,21 +23,23 @@ export var makeLabel = function makeLabel(_ref) {
|
|
|
23
23
|
konnector = _ref.konnector,
|
|
24
24
|
trigger = _ref.trigger,
|
|
25
25
|
running = _ref.running,
|
|
26
|
-
expectingTriggerLaunch = _ref.expectingTriggerLaunch
|
|
26
|
+
expectingTriggerLaunch = _ref.expectingTriggerLaunch,
|
|
27
|
+
isInMaintenance = _ref.isInMaintenance;
|
|
27
28
|
var lastSuccessDate = getLastSuccessDate(trigger);
|
|
29
|
+
var mantenanceSuffix = isInMaintenance ? " \xB7 ".concat(t('konnectorBlock.inMaintenance')) : '';
|
|
28
30
|
|
|
29
31
|
if (running || expectingTriggerLaunch) {
|
|
30
|
-
return t('card.launchTrigger.lastSync.syncing');
|
|
32
|
+
return "".concat(t('card.launchTrigger.lastSync.syncing')).concat(mantenanceSuffix);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
if (lastSuccessDate) {
|
|
34
36
|
if (getDifferenceInMinutes(lastSuccessDate) < DEFAULT_TIME) {
|
|
35
|
-
return t('card.launchTrigger.lastSync.justNow');
|
|
37
|
+
return "".concat(t('card.launchTrigger.lastSync.justNow')).concat(mantenanceSuffix);
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
return t('card.launchTrigger.lastSync.afterSomeTimes', {
|
|
40
|
+
return "".concat(t('card.launchTrigger.lastSync.afterSomeTimes', {
|
|
39
41
|
times: formatLocallyDistanceToNow(lastSuccessDate)
|
|
40
|
-
});
|
|
42
|
+
})).concat(mantenanceSuffix);
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
if (isDisconnected(konnector, trigger)) {
|
|
@@ -174,6 +174,8 @@ export var ConnectionFlow = /*#__PURE__*/function () {
|
|
|
174
174
|
this.handleAccountUpdated = this.handleAccountUpdated.bind(this);
|
|
175
175
|
this.handleCurrentJobUpdated = this.handleCurrentJobUpdated.bind(this);
|
|
176
176
|
this.handleTriggerJobUpdated = this.handleTriggerJobUpdated.bind(this);
|
|
177
|
+
this.handleTriggerDeleted = this.handleTriggerDeleted.bind(this);
|
|
178
|
+
this.handleTriggerCreated = this.handleTriggerCreated.bind(this);
|
|
177
179
|
this.handleAccountTwoFA = this.handleAccountTwoFA.bind(this);
|
|
178
180
|
this.launch = this.launch.bind(this);
|
|
179
181
|
this.sendTwoFACode = this.sendTwoFACode.bind(this);
|
|
@@ -188,6 +190,7 @@ export var ConnectionFlow = /*#__PURE__*/function () {
|
|
|
188
190
|
this.realtime = client.plugins.realtime;
|
|
189
191
|
this.watchCurrentJobIfTriggerIsAlreadyRunning();
|
|
190
192
|
this.watchTriggerJobs();
|
|
193
|
+
this.watchTriggers();
|
|
191
194
|
}
|
|
192
195
|
|
|
193
196
|
_createClass(ConnectionFlow, [{
|
|
@@ -682,6 +685,30 @@ export var ConnectionFlow = /*#__PURE__*/function () {
|
|
|
682
685
|
|
|
683
686
|
return handleFormSubmit;
|
|
684
687
|
}()
|
|
688
|
+
}, {
|
|
689
|
+
key: "handleTriggerCreated",
|
|
690
|
+
value: function handleTriggerCreated(trigger) {
|
|
691
|
+
var _trigger$message;
|
|
692
|
+
|
|
693
|
+
if (this.konnector.slug !== (trigger === null || trigger === void 0 ? void 0 : (_trigger$message = trigger.message) === null || _trigger$message === void 0 ? void 0 : _trigger$message.konnector) || this.trigger !== null) {
|
|
694
|
+
return; // filter out trigger associated to konnector or if a current trigger already exists
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
this.trigger = trigger; // @ts-ignore
|
|
698
|
+
|
|
699
|
+
this.emit(UPDATE_EVENT);
|
|
700
|
+
}
|
|
701
|
+
}, {
|
|
702
|
+
key: "handleTriggerDeleted",
|
|
703
|
+
value: function handleTriggerDeleted(trigger) {
|
|
704
|
+
var _this$trigger;
|
|
705
|
+
|
|
706
|
+
if (((_this$trigger = this.trigger) === null || _this$trigger === void 0 ? void 0 : _this$trigger._id) !== (trigger === null || trigger === void 0 ? void 0 : trigger._id)) return; // filter out trigger associated to current trigger
|
|
707
|
+
|
|
708
|
+
this.reset(); // @ts-ignore
|
|
709
|
+
|
|
710
|
+
this.emit(UPDATE_EVENT);
|
|
711
|
+
}
|
|
685
712
|
}, {
|
|
686
713
|
key: "handleAccountUpdated",
|
|
687
714
|
value: function handleAccountUpdated(account) {
|
|
@@ -717,9 +744,9 @@ export var ConnectionFlow = /*#__PURE__*/function () {
|
|
|
717
744
|
}, {
|
|
718
745
|
key: "handleTriggerJobUpdated",
|
|
719
746
|
value: function handleTriggerJobUpdated(job) {
|
|
720
|
-
var _this$
|
|
747
|
+
var _this$trigger2, _this$job;
|
|
721
748
|
|
|
722
|
-
if (job.trigger_id !== ((_this$
|
|
749
|
+
if (job.trigger_id !== ((_this$trigger2 = this.trigger) === null || _this$trigger2 === void 0 ? void 0 : _this$trigger2._id)) return; // filter out jobs associated to other triggers
|
|
723
750
|
|
|
724
751
|
if (job._id === ((_this$job = this.job) === null || _this$job === void 0 ? void 0 : _this$job._id)) return; // if the event is associated to a job we are already watchin, ignore it. No need to refetch the current trigger in this case
|
|
725
752
|
|
|
@@ -842,7 +869,7 @@ export var ConnectionFlow = /*#__PURE__*/function () {
|
|
|
842
869
|
key: "ensureDefaultFolderPathInAccount",
|
|
843
870
|
value: function () {
|
|
844
871
|
var _ensureDefaultFolderPathInAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(client, _ref5) {
|
|
845
|
-
var _trigger$
|
|
872
|
+
var _trigger$message2;
|
|
846
873
|
|
|
847
874
|
var trigger, account, konnector, folderId, folder, result, savedAccount;
|
|
848
875
|
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
@@ -851,7 +878,7 @@ export var ConnectionFlow = /*#__PURE__*/function () {
|
|
|
851
878
|
case 0:
|
|
852
879
|
trigger = _ref5.trigger, account = _ref5.account, konnector = _ref5.konnector;
|
|
853
880
|
// @ts-ignore the message property does not exist in TriggersDoctype
|
|
854
|
-
folderId = trigger === null || trigger === void 0 ? void 0 : (_trigger$
|
|
881
|
+
folderId = trigger === null || trigger === void 0 ? void 0 : (_trigger$message2 = trigger.message) === null || _trigger$message2 === void 0 ? void 0 : _trigger$message2.folder_to_save;
|
|
855
882
|
|
|
856
883
|
if (folderId) {
|
|
857
884
|
_context9.next = 4;
|
|
@@ -999,17 +1026,27 @@ export var ConnectionFlow = /*#__PURE__*/function () {
|
|
|
999
1026
|
}, {
|
|
1000
1027
|
key: "watchCurrentJobIfTriggerIsAlreadyRunning",
|
|
1001
1028
|
value: function watchCurrentJobIfTriggerIsAlreadyRunning() {
|
|
1002
|
-
var _this$
|
|
1029
|
+
var _this$trigger3, _this$trigger3$curren;
|
|
1003
1030
|
|
|
1004
|
-
if (((_this$
|
|
1005
|
-
var _this$
|
|
1031
|
+
if (((_this$trigger3 = this.trigger) === null || _this$trigger3 === void 0 ? void 0 : (_this$trigger3$curren = _this$trigger3.current_state) === null || _this$trigger3$curren === void 0 ? void 0 : _this$trigger3$curren.status) === 'running') {
|
|
1032
|
+
var _this$trigger4, _this$trigger4$curren;
|
|
1006
1033
|
|
|
1007
1034
|
this.job = {
|
|
1008
|
-
_id: (_this$
|
|
1035
|
+
_id: (_this$trigger4 = this.trigger) === null || _this$trigger4 === void 0 ? void 0 : (_this$trigger4$curren = _this$trigger4.current_state) === null || _this$trigger4$curren === void 0 ? void 0 : _this$trigger4$curren.last_executed_job_id
|
|
1009
1036
|
};
|
|
1010
1037
|
this.watchJob();
|
|
1011
1038
|
}
|
|
1012
1039
|
}
|
|
1040
|
+
/**
|
|
1041
|
+
* Watch all triggers
|
|
1042
|
+
*/
|
|
1043
|
+
|
|
1044
|
+
}, {
|
|
1045
|
+
key: "watchTriggers",
|
|
1046
|
+
value: function watchTriggers() {
|
|
1047
|
+
this.realtime.subscribe('deleted', 'io.cozy.triggers', this.handleTriggerDeleted);
|
|
1048
|
+
this.realtime.subscribe('created', 'io.cozy.triggers', this.handleTriggerCreated);
|
|
1049
|
+
}
|
|
1013
1050
|
/**
|
|
1014
1051
|
* Watch all jobs related to the current trigger
|
|
1015
1052
|
*/
|
|
@@ -1018,10 +1055,10 @@ export var ConnectionFlow = /*#__PURE__*/function () {
|
|
|
1018
1055
|
key: "watchTriggerJobs",
|
|
1019
1056
|
value: function watchTriggerJobs() {
|
|
1020
1057
|
if (this.trigger) {
|
|
1021
|
-
var _this$
|
|
1058
|
+
var _this$trigger5;
|
|
1022
1059
|
|
|
1023
1060
|
// When the trigger comes from realtime, cozy-stack does not add the current_state to the object. So we need to request the stack to get it
|
|
1024
|
-
if (!((_this$
|
|
1061
|
+
if (!((_this$trigger5 = this.trigger) !== null && _this$trigger5 !== void 0 && _this$trigger5.current_state)) {
|
|
1025
1062
|
this.refetchTrigger();
|
|
1026
1063
|
}
|
|
1027
1064
|
|
|
@@ -1097,6 +1134,8 @@ export var ConnectionFlow = /*#__PURE__*/function () {
|
|
|
1097
1134
|
value: function unsubscribeAllConnectionFlowRealtime() {
|
|
1098
1135
|
this.realtime.unsubscribe('updated', JOBS_DOCTYPE, this.handleTriggerJobUpdated);
|
|
1099
1136
|
this.realtime.unsubscribe('updated', JOBS_DOCTYPE, this.job._id, this.handleCurrentJobUpdated.bind(this));
|
|
1137
|
+
this.realtime.unsubscribe('deleted', 'io.cozy.triggers', this.handleTriggerDeleted);
|
|
1138
|
+
this.realtime.unsubscribe('created', 'io.cozy.triggers', this.handleTriggerCreated);
|
|
1100
1139
|
}
|
|
1101
1140
|
}, {
|
|
1102
1141
|
key: "unwatch",
|