cozy-harvest-lib 9.25.0 → 9.26.2

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 CHANGED
@@ -3,6 +3,38 @@
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
+ ## [9.26.2](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.26.1...cozy-harvest-lib@9.26.2) (2022-08-26)
7
+
8
+ **Note:** Version bump only for package cozy-harvest-lib
9
+
10
+
11
+
12
+
13
+
14
+ ## [9.26.1](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.26.0...cozy-harvest-lib@9.26.1) (2022-08-22)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * RefreshContracts now updates contracts in realtime ([463e716](https://github.com/cozy/cozy-libs/commit/463e7169d78ce633308229257bd262d01842fdc1))
20
+
21
+
22
+
23
+
24
+
25
+ # [9.26.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.25.0...cozy-harvest-lib@9.26.0) (2022-08-22)
26
+
27
+
28
+ ### Features
29
+
30
+ * Detect reconnect explicitely ([b092392](https://github.com/cozy/cozy-libs/commit/b0923923727bdb08123bd78073a0dda238361f02))
31
+ * Handle cas with multiple bank ids ([9729626](https://github.com/cozy/cozy-libs/commit/97296267e941265a08ad052f1e5a62c3830566f2))
32
+ * Use BI account creation webview to handle accounts synchonization ([1b5e5ff](https://github.com/cozy/cozy-libs/commit/1b5e5ff06b6c98b14d0d8c388d31970ae36bfac0))
33
+
34
+
35
+
36
+
37
+
6
38
  # [9.25.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.24.4...cozy-harvest-lib@9.25.0) (2022-08-05)
7
39
 
8
40
 
package/README.md CHANGED
@@ -141,7 +141,7 @@ const client = new CozyClient({
141
141
 
142
142
  ReactDOM.render(
143
143
  <CozyProvider client={client}>
144
- <Query query={()=> Q('io.cozy.apps').getById('my-konnector-id')}>
144
+ <Query query={()=> Q('io.cozy.konnectors').getById('my-konnector-id')}>
145
145
  {({ data: konnector }) => (
146
146
  <TriggerManager
147
147
  konnector={konnector}
@@ -4,15 +4,14 @@ import React from 'react';
4
4
  import CozyClient from 'cozy-client';
5
5
  import { render, fireEvent, act, waitFor } from '@testing-library/react';
6
6
  import AppLike from '../../../../test/AppLike';
7
- import BIContractActivationWindow from './BiContractActivationWindow';
8
- var fetchContractSynchronizationUrl = jest.fn();
7
+ var fetchExtraOAuthUrlParams = jest.fn();
9
8
  var refreshContracts = jest.fn();
10
9
  jest.mock('../../../konnector-policies', function () {
11
10
  return {
12
11
  findKonnectorPolicy: jest.fn()
13
12
  };
14
13
  });
15
- jest.mock('cozy-ui/transpiled/react/Popup', function () {
14
+ jest.mock('../../Popup', function () {
16
15
  return jest.fn().mockImplementation(function (_ref) {
17
16
  var onClose = _ref.onClose;
18
17
  setTimeout(onClose, 1);
@@ -26,14 +25,18 @@ jest.mock('../../InAppBrowser', function () {
26
25
  return null;
27
26
  });
28
27
  });
28
+ jest.mock('../../../helpers/oauth');
29
+ jest.mock('cozy-realtime');
29
30
  jest.mock('cozy-device-helper');
31
+ import BIContractActivationWindow from './BiContractActivationWindow';
30
32
  import { findKonnectorPolicy } from '../../../konnector-policies';
31
- import Popup from 'cozy-ui/transpiled/react/Popup';
33
+ import Popup from '../../Popup';
32
34
  import InAppBrowser from '../../InAppBrowser';
33
35
  import { isFlagshipApp } from 'cozy-device-helper';
36
+ import { prepareOAuth } from '../../../helpers/oauth';
34
37
  findKonnectorPolicy.mockImplementation(function () {
35
38
  return {
36
- fetchContractSynchronizationUrl: fetchContractSynchronizationUrl,
39
+ fetchExtraOAuthUrlParams: fetchExtraOAuthUrlParams,
37
40
  refreshContracts: refreshContracts
38
41
  };
39
42
  });
@@ -66,12 +69,17 @@ describe('BIContractActivationWindow', function () {
66
69
  while (1) {
67
70
  switch (_context3.prev = _context3.next) {
68
71
  case 0:
72
+ prepareOAuth.mockImplementation(function () {
73
+ return {
74
+ oAuthUrl: 'https://test.url'
75
+ };
76
+ });
69
77
  isFlagshipApp.mockImplementation(function () {
70
78
  return false;
71
79
  });
72
- fetchContractSynchronizationUrl.mockResolvedValue('bi url');
80
+ fetchExtraOAuthUrlParams.mockResolvedValue({});
73
81
  _setup = setup(), getByRole = _setup.getByRole;
74
- _context3.next = 5;
82
+ _context3.next = 6;
75
83
  return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
76
84
  return _regeneratorRuntime.wrap(function _callee$(_context) {
77
85
  while (1) {
@@ -90,8 +98,8 @@ describe('BIContractActivationWindow', function () {
90
98
  }, _callee);
91
99
  })));
92
100
 
93
- case 5:
94
- _context3.next = 7;
101
+ case 6:
102
+ _context3.next = 8;
95
103
  return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
96
104
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
97
105
  while (1) {
@@ -111,14 +119,14 @@ describe('BIContractActivationWindow', function () {
111
119
  }, _callee2);
112
120
  })));
113
121
 
114
- case 7:
115
- expect(fetchContractSynchronizationUrl).toHaveBeenCalled();
122
+ case 8:
123
+ expect(fetchExtraOAuthUrlParams).toHaveBeenCalled();
116
124
  expect(refreshContracts).toHaveBeenCalledTimes(1);
117
125
  expect(Popup).toHaveBeenCalledWith(expect.objectContaining({
118
- initialUrl: 'bi url'
119
- }), expect.anything());
126
+ url: 'https://test.url'
127
+ }), {});
120
128
 
121
- case 10:
129
+ case 11:
122
130
  case "end":
123
131
  return _context3.stop();
124
132
  }
@@ -135,9 +143,14 @@ describe('BIContractActivationWindow', function () {
135
143
  isFlagshipApp.mockImplementation(function () {
136
144
  return true;
137
145
  });
138
- fetchContractSynchronizationUrl.mockResolvedValue('bi url');
146
+ prepareOAuth.mockImplementation(function () {
147
+ return {
148
+ oAuthUrl: 'https://testiab.url'
149
+ };
150
+ });
151
+ fetchExtraOAuthUrlParams.mockResolvedValue({});
139
152
  _setup2 = setup(), getByRole = _setup2.getByRole;
140
- _context6.next = 5;
153
+ _context6.next = 6;
141
154
  return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
142
155
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
143
156
  while (1) {
@@ -156,8 +169,8 @@ describe('BIContractActivationWindow', function () {
156
169
  }, _callee4);
157
170
  })));
158
171
 
159
- case 5:
160
- _context6.next = 7;
172
+ case 6:
173
+ _context6.next = 8;
161
174
  return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
162
175
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
163
176
  while (1) {
@@ -177,14 +190,14 @@ describe('BIContractActivationWindow', function () {
177
190
  }, _callee5);
178
191
  })));
179
192
 
180
- case 7:
181
- expect(fetchContractSynchronizationUrl).toHaveBeenCalled();
193
+ case 8:
194
+ expect(fetchExtraOAuthUrlParams).toHaveBeenCalled();
182
195
  expect(refreshContracts).toHaveBeenCalledTimes(1);
183
196
  expect(InAppBrowser).toHaveBeenCalledWith(expect.objectContaining({
184
- url: 'bi url'
197
+ url: 'https://testiab.url'
185
198
  }), expect.anything());
186
199
 
187
- case 10:
200
+ case 11:
188
201
  case "end":
189
202
  return _context6.stop();
190
203
  }
@@ -5,11 +5,9 @@ import React, { useState, useEffect } from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { useClient } from 'cozy-client';
7
7
  import Button from 'cozy-ui/transpiled/react/MuiCozyTheme/Buttons';
8
- import Popup from 'cozy-ui/transpiled/react/Popup';
9
8
  import ListItem from 'cozy-ui/transpiled/react/MuiCozyTheme/ListItem';
10
9
  import { findKonnectorPolicy } from '../../../konnector-policies';
11
- import { isFlagshipApp } from 'cozy-device-helper';
12
- import InAppBrowser from '../../InAppBrowser';
10
+ import OAuthWindow from '../../OAuthWindow';
13
11
  import withLocales from '../../hoc/withLocales';
14
12
  import { intentsApiProptype, innerAccountModalOverridesProptype } from '../../../helpers/proptypes';
15
13
 
@@ -22,8 +20,8 @@ var BIContractActivationWindow = function BIContractActivationWindow(_ref) {
22
20
 
23
21
  var _useState = useState(null),
24
22
  _useState2 = _slicedToArray(_useState, 2),
25
- initialUrl = _useState2[0],
26
- setInitialUrl = _useState2[1];
23
+ extraParams = _useState2[0],
24
+ setExtraParams = _useState2[1];
27
25
 
28
26
  var _useState3 = useState(false),
29
27
  _useState4 = _slicedToArray(_useState3, 2),
@@ -44,38 +42,13 @@ var BIContractActivationWindow = function BIContractActivationWindow(_ref) {
44
42
  };
45
43
 
46
44
  useEffect(function () {
47
- function refreshContracts() {
48
- return _refreshContracts.apply(this, arguments);
49
- }
50
-
51
- function _refreshContracts() {
52
- _refreshContracts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
53
- return _regeneratorRuntime.wrap(function _callee$(_context) {
54
- while (1) {
55
- switch (_context.prev = _context.next) {
56
- case 0:
57
- _context.next = 2;
58
- return konnectorPolicy.refreshContracts({
59
- client: client,
60
- account: account,
61
- konnector: konnector
62
- });
63
-
64
- case 2:
65
- setShouldRefreshContracts(false);
66
-
67
- case 3:
68
- case "end":
69
- return _context.stop();
70
- }
71
- }
72
- }, _callee);
73
- }));
74
- return _refreshContracts.apply(this, arguments);
75
- }
76
-
77
45
  if (shouldRefreshContracts) {
78
- refreshContracts();
46
+ setShouldRefreshContracts(false);
47
+ konnectorPolicy.refreshContracts({
48
+ client: client,
49
+ account: account,
50
+ konnector: konnector
51
+ });
79
52
  }
80
53
  }, [account, client, konnectorPolicy, shouldRefreshContracts, konnector]);
81
54
  useEffect(function () {
@@ -84,56 +57,54 @@ var BIContractActivationWindow = function BIContractActivationWindow(_ref) {
84
57
  }
85
58
 
86
59
  function _handleLinkFetch() {
87
- _handleLinkFetch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
60
+ _handleLinkFetch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
88
61
  var result;
89
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
62
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
90
63
  while (1) {
91
- switch (_context2.prev = _context2.next) {
64
+ switch (_context.prev = _context.next) {
92
65
  case 0:
93
- _context2.next = 2;
94
- return konnectorPolicy.fetchContractSynchronizationUrl({
66
+ _context.next = 2;
67
+ return konnectorPolicy.fetchExtraOAuthUrlParams({
95
68
  client: client,
96
69
  account: account,
97
70
  konnector: konnector
98
71
  });
99
72
 
100
73
  case 2:
101
- result = _context2.sent;
102
- setInitialUrl(result);
74
+ result = _context.sent;
75
+ setExtraParams(result);
103
76
 
104
77
  case 4:
105
78
  case "end":
106
- return _context2.stop();
79
+ return _context.stop();
107
80
  }
108
81
  }
109
- }, _callee2);
82
+ }, _callee);
110
83
  }));
111
84
  return _handleLinkFetch.apply(this, arguments);
112
85
  }
113
86
 
114
- if (konnectorPolicy.fetchContractSynchronizationUrl) {
87
+ if (konnectorPolicy.fetchExtraOAuthUrlParams) {
115
88
  handleLinkFetch();
116
89
  }
117
90
  }, [konnector.slug, account, client, konnectorPolicy]);
118
- if (!konnectorPolicy.fetchContractSynchronizationUrl) return null;
91
+ if (!konnectorPolicy.fetchExtraOAuthUrlParams) return null;
119
92
  var ButtonWrapper = innerAccountModalOverrides !== null && innerAccountModalOverrides !== void 0 && innerAccountModalOverrides.SyncButtonWrapperComp ? innerAccountModalOverrides.SyncButtonWrapperComp : React.Fragment;
120
93
  return /*#__PURE__*/React.createElement(ListItem, null, /*#__PURE__*/React.createElement(ButtonWrapper, null, /*#__PURE__*/React.createElement(Button, {
121
94
  variant: "text",
122
95
  color: "primary",
123
- disabled: !initialUrl,
96
+ disabled: !extraParams,
124
97
  onClick: function onClick() {
125
98
  return setWindowVisible(true);
126
99
  }
127
- }, t('contracts.handle-synchronization'))), isWindowVisible && (isFlagshipApp() || intentsApi ? /*#__PURE__*/React.createElement(InAppBrowser, {
128
- url: initialUrl,
129
- onClose: onPopupClosed,
130
- intentsApi: intentsApi
131
- }) : /*#__PURE__*/React.createElement(Popup, {
132
- initialUrl: initialUrl,
133
- width: "800",
134
- height: "800",
135
- onClose: onPopupClosed
136
- })));
100
+ }, t('contracts.handle-synchronization'))), isWindowVisible && /*#__PURE__*/React.createElement(OAuthWindow, {
101
+ extraParams: extraParams,
102
+ konnector: konnector,
103
+ account: account,
104
+ intentsApi: intentsApi,
105
+ onSuccess: onPopupClosed,
106
+ onCancel: onPopupClosed
107
+ }));
137
108
  };
138
109
 
139
110
  BIContractActivationWindow.propTypes = {
@@ -68,10 +68,10 @@ export var OAuthForm = /*#__PURE__*/function (_PureComponent) {
68
68
 
69
69
 
70
70
  konnectorPolicy.fetchExtraOAuthUrlParams({
71
- flow: flow,
72
71
  account: account,
73
72
  konnector: konnector,
74
- client: client
73
+ client: client,
74
+ reconnect: reconnect
75
75
  }).then(this.handleExtraParams);
76
76
  }
77
77
 
@@ -69,7 +69,6 @@ describe('OAuthForm', function () {
69
69
  }
70
70
  },
71
71
  client: undefined,
72
- flow: flow,
73
72
  konnector: {
74
73
  slug: 'test-konnector'
75
74
  }