cozy-harvest-lib 13.1.0 → 13.2.1

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/.tx/config CHANGED
@@ -1,8 +1,8 @@
1
1
  [main]
2
2
  host = https://www.transifex.com
3
3
 
4
- [cozy-harvest-lib.client]
4
+ [o:cozy:p:cozy-harvest-lib:r:client]
5
5
  file_filter = src/locales/<lang>.json
6
6
  source_file = src/locales/en.json
7
7
  source_lang = en
8
- type = KEYVALUEJSON
8
+ type = KEYVALUEJSON
package/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
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.1](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@13.2.0...cozy-harvest-lib@13.2.1) (2023-02-08)
7
+
8
+ **Note:** Version bump only for package cozy-harvest-lib
9
+
10
+
11
+
12
+
13
+
14
+ # [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)
15
+
16
+
17
+ ### Features
18
+
19
+ * Add triggers realtime to ConnectionFlow ([b46616e](https://github.com/cozy/cozy-libs/commit/b46616ee9212af7609d8497eae7027cf50c7a63d))
20
+
21
+
22
+
23
+
24
+
6
25
  # [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)
7
26
 
8
27
 
@@ -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$trigger, _this$job;
747
+ var _this$trigger2, _this$job;
721
748
 
722
- if (job.trigger_id !== ((_this$trigger = this.trigger) === null || _this$trigger === void 0 ? void 0 : _this$trigger._id)) return; // filter out jobs associated to other triggers
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$message;
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$message = trigger.message) === null || _trigger$message === void 0 ? void 0 : _trigger$message.folder_to_save;
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$trigger2, _this$trigger2$curren;
1029
+ var _this$trigger3, _this$trigger3$curren;
1003
1030
 
1004
- if (((_this$trigger2 = this.trigger) === null || _this$trigger2 === void 0 ? void 0 : (_this$trigger2$curren = _this$trigger2.current_state) === null || _this$trigger2$curren === void 0 ? void 0 : _this$trigger2$curren.status) === 'running') {
1005
- var _this$trigger3, _this$trigger3$curren;
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$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.last_executed_job_id
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$trigger4;
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$trigger4 = this.trigger) !== null && _this$trigger4 !== void 0 && _this$trigger4.current_state)) {
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",