cozy-harvest-lib 9.24.2 → 9.25.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 +39 -0
- package/dist/components/KonnectorConfiguration/ConfigurationTab/BIContractActivationWindow.spec.js +4 -4
- package/dist/components/KonnectorConfiguration/ConfigurationTab/EditContract.js +0 -1
- package/dist/components/KonnectorModal.spec.js +2 -2
- package/dist/components/OAuthForm.js +26 -9
- package/dist/components/OAuthForm.spec.js +9 -2
- package/dist/components/OAuthWindow.js +2 -7
- package/dist/components/__snapshots__/OAuthForm.spec.js.snap +2 -13
- package/dist/components/{KonnectorUpdateInfos.spec.js → infos/KonnectorUpdateInfos.spec.js} +15 -2
- package/dist/services/biWebView.js +40 -58
- package/dist/services/biWebView.spec.js +72 -126
- package/package.json +8 -8
- package/src/components/KonnectorConfiguration/ConfigurationTab/BIContractActivationWindow.spec.jsx +4 -4
- package/src/components/KonnectorModal.spec.jsx +1 -1
- package/src/components/OAuthForm.jsx +28 -15
- package/src/components/OAuthForm.spec.js +15 -3
- package/src/components/OAuthWindow.jsx +1 -3
- package/src/components/__snapshots__/OAuthForm.spec.js.snap +2 -13
- package/src/components/{KonnectorUpdateInfos.spec.jsx → infos/KonnectorUpdateInfos.spec.jsx} +15 -1
- package/src/services/biWebView.js +19 -44
- package/src/services/biWebView.spec.js +1 -40
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,45 @@
|
|
|
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.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
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Let OAuthForm component decide when to remove the OAuth window ([59a132f](https://github.com/cozy/cozy-libs/commit/59a132f71d528cb311d436041951aaae811aed6e))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* Close OAuthWindow only on login success ([a8cf6a3](https://github.com/cozy/cozy-libs/commit/a8cf6a37a9c76bf2702c1d73d292a4d337f7dc5a))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [9.24.4](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.24.3...cozy-harvest-lib@9.24.4) (2022-08-05)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* Remove a reconnection step ([05d2cb6](https://github.com/cozy/cozy-libs/commit/05d2cb674d9ce69164cf0a099059520cbf4f1722))
|
|
28
|
+
* Remove unused request to BI connection ([be09798](https://github.com/cozy/cozy-libs/commit/be09798e3c551fd9628d15e6f79b9de77b3d1aa5))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## [9.24.3](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.24.2...cozy-harvest-lib@9.24.3) (2022-08-01)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Bug Fixes
|
|
38
|
+
|
|
39
|
+
* **node:** Upgrade to Node 16 ([3a82521](https://github.com/cozy/cozy-libs/commit/3a825217b4a55d6434b20660d73df44ab17e7bd0))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
6
45
|
## [9.24.2](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.24.1...cozy-harvest-lib@9.24.2) (2022-07-29)
|
|
7
46
|
|
|
8
47
|
|
package/dist/components/KonnectorConfiguration/ConfigurationTab/BIContractActivationWindow.spec.js
CHANGED
|
@@ -79,7 +79,7 @@ describe('BIContractActivationWindow', function () {
|
|
|
79
79
|
case 0:
|
|
80
80
|
_context.next = 2;
|
|
81
81
|
return waitFor(function () {
|
|
82
|
-
expect(getByRole('button').getAttribute('class')).not.toContain('Mui-disabled');
|
|
82
|
+
return expect(getByRole('button').getAttribute('class')).not.toContain('Mui-disabled');
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
case 2:
|
|
@@ -100,7 +100,7 @@ describe('BIContractActivationWindow', function () {
|
|
|
100
100
|
fireEvent.click(getByRole('button'));
|
|
101
101
|
_context2.next = 3;
|
|
102
102
|
return waitFor(function () {
|
|
103
|
-
expect(refreshContracts).toHaveBeenCalled();
|
|
103
|
+
return expect(refreshContracts).toHaveBeenCalled();
|
|
104
104
|
});
|
|
105
105
|
|
|
106
106
|
case 3:
|
|
@@ -145,7 +145,7 @@ describe('BIContractActivationWindow', function () {
|
|
|
145
145
|
case 0:
|
|
146
146
|
_context4.next = 2;
|
|
147
147
|
return waitFor(function () {
|
|
148
|
-
expect(getByRole('button').getAttribute('class')).not.toContain('Mui-disabled');
|
|
148
|
+
return expect(getByRole('button').getAttribute('class')).not.toContain('Mui-disabled');
|
|
149
149
|
});
|
|
150
150
|
|
|
151
151
|
case 2:
|
|
@@ -166,7 +166,7 @@ describe('BIContractActivationWindow', function () {
|
|
|
166
166
|
fireEvent.click(getByRole('button'));
|
|
167
167
|
_context5.next = 3;
|
|
168
168
|
return waitFor(function () {
|
|
169
|
-
expect(refreshContracts).toHaveBeenCalled();
|
|
169
|
+
return expect(refreshContracts).toHaveBeenCalled();
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
case 3:
|
|
@@ -86,9 +86,9 @@ describe('KonnectorModal', function () {
|
|
|
86
86
|
switch (_context.prev = _context.next) {
|
|
87
87
|
case 0:
|
|
88
88
|
_setup = setup(), root = _setup.root;
|
|
89
|
-
waitFor(function () {
|
|
89
|
+
return _context.abrupt("return", waitFor(function () {
|
|
90
90
|
return root.getByRole('progressbar');
|
|
91
|
-
});
|
|
91
|
+
}));
|
|
92
92
|
|
|
93
93
|
case 2:
|
|
94
94
|
case "end":
|
|
@@ -19,7 +19,7 @@ import withLocales from './hoc/withLocales';
|
|
|
19
19
|
import { findKonnectorPolicy } from '../konnector-policies';
|
|
20
20
|
import { intentsApiProptype } from '../helpers/proptypes';
|
|
21
21
|
import TriggerErrorInfo from './infos/TriggerErrorInfo';
|
|
22
|
-
import { ERROR_EVENT } from '../models/flowEvents';
|
|
22
|
+
import { ERROR_EVENT, LOGIN_SUCCESS_EVENT } from '../models/flowEvents';
|
|
23
23
|
import { KonnectorJobError } from '../helpers/konnectors';
|
|
24
24
|
/**
|
|
25
25
|
* The OAuth Form is responsible for displaying a form for OAuth konnectors. It
|
|
@@ -41,9 +41,8 @@ export var OAuthForm = /*#__PURE__*/function (_PureComponent) {
|
|
|
41
41
|
_this.handleConnect = _this.handleConnect.bind(_assertThisInitialized(_this));
|
|
42
42
|
_this.handleOAuthCancel = _this.handleOAuthCancel.bind(_assertThisInitialized(_this));
|
|
43
43
|
_this.handleExtraParams = _this.handleExtraParams.bind(_assertThisInitialized(_this));
|
|
44
|
-
_this.
|
|
45
|
-
|
|
46
|
-
};
|
|
44
|
+
_this.handleLoginSuccess = _this.handleLoginSuccess.bind(_assertThisInitialized(_this));
|
|
45
|
+
_this.state = {};
|
|
47
46
|
return _this;
|
|
48
47
|
}
|
|
49
48
|
|
|
@@ -54,13 +53,19 @@ export var OAuthForm = /*#__PURE__*/function (_PureComponent) {
|
|
|
54
53
|
account = _this$props.account,
|
|
55
54
|
konnector = _this$props.konnector,
|
|
56
55
|
flow = _this$props.flow,
|
|
57
|
-
client = _this$props.client
|
|
56
|
+
client = _this$props.client,
|
|
57
|
+
reconnect = _this$props.reconnect;
|
|
58
58
|
var konnectorPolicy = findKonnectorPolicy(konnector);
|
|
59
59
|
|
|
60
60
|
if (konnectorPolicy.fetchExtraOAuthUrlParams) {
|
|
61
61
|
this.setState({
|
|
62
62
|
needExtraParams: true
|
|
63
|
-
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (reconnect) {
|
|
66
|
+
this.showOAuthWindow();
|
|
67
|
+
} // eslint-disable-next-line promise/catch-or-return
|
|
68
|
+
|
|
64
69
|
|
|
65
70
|
konnectorPolicy.fetchExtraOAuthUrlParams({
|
|
66
71
|
flow: flow,
|
|
@@ -69,6 +74,13 @@ export var OAuthForm = /*#__PURE__*/function (_PureComponent) {
|
|
|
69
74
|
client: client
|
|
70
75
|
}).then(this.handleExtraParams);
|
|
71
76
|
}
|
|
77
|
+
|
|
78
|
+
flow.on(LOGIN_SUCCESS_EVENT, this.handleLoginSuccess);
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
81
|
+
key: "handleLoginSuccess",
|
|
82
|
+
value: function handleLoginSuccess() {
|
|
83
|
+
this.hideOAuthWindow();
|
|
72
84
|
}
|
|
73
85
|
}, {
|
|
74
86
|
key: "handleExtraParams",
|
|
@@ -81,7 +93,6 @@ export var OAuthForm = /*#__PURE__*/function (_PureComponent) {
|
|
|
81
93
|
key: "handleAccountId",
|
|
82
94
|
value: function handleAccountId(accountId) {
|
|
83
95
|
var onSuccess = this.props.onSuccess;
|
|
84
|
-
this.hideOAuthWindow();
|
|
85
96
|
if (typeof onSuccess === 'function') onSuccess(accountId);
|
|
86
97
|
}
|
|
87
98
|
}, {
|
|
@@ -89,6 +100,12 @@ export var OAuthForm = /*#__PURE__*/function (_PureComponent) {
|
|
|
89
100
|
value: function handleConnect() {
|
|
90
101
|
this.showOAuthWindow();
|
|
91
102
|
}
|
|
103
|
+
}, {
|
|
104
|
+
key: "componentWillUnmount",
|
|
105
|
+
value: function componentWillUnmount() {
|
|
106
|
+
var flow = this.props.flow;
|
|
107
|
+
flow.removeListener(LOGIN_SUCCESS_EVENT, this.handleLoginSuccess);
|
|
108
|
+
}
|
|
92
109
|
/**
|
|
93
110
|
* Translates errors from oauth redirection url to harvest know error messages
|
|
94
111
|
*
|
|
@@ -149,14 +166,14 @@ export var OAuthForm = /*#__PURE__*/function (_PureComponent) {
|
|
|
149
166
|
className: "u-mb-1",
|
|
150
167
|
error: error,
|
|
151
168
|
konnector: konnector
|
|
152
|
-
}), /*#__PURE__*/React.createElement(Button, {
|
|
169
|
+
}), !reconnect && /*#__PURE__*/React.createElement(Button, {
|
|
153
170
|
className: "u-mt-1",
|
|
154
171
|
busy: isBusy,
|
|
155
172
|
disabled: isBusy,
|
|
156
173
|
extension: "full",
|
|
157
174
|
label: t(buttonLabel),
|
|
158
175
|
onClick: this.handleConnect
|
|
159
|
-
}), showOAuthWindow && /*#__PURE__*/React.createElement(OAuthWindow, {
|
|
176
|
+
}), showOAuthWindow && extraParams && /*#__PURE__*/React.createElement(OAuthWindow, {
|
|
160
177
|
extraParams: extraParams,
|
|
161
178
|
konnector: konnector,
|
|
162
179
|
reconnect: reconnect,
|
|
@@ -4,11 +4,13 @@ import { shallow } from 'enzyme';
|
|
|
4
4
|
import { OAuthForm } from 'components/OAuthForm';
|
|
5
5
|
import { findKonnectorPolicy } from '../konnector-policies';
|
|
6
6
|
import { KonnectorJobError } from '../helpers/konnectors';
|
|
7
|
+
import ConnectionFlow from '../models/ConnectionFlow';
|
|
7
8
|
jest.mock('../konnector-policies', function () {
|
|
8
9
|
return {
|
|
9
10
|
findKonnectorPolicy: jest.fn()
|
|
10
11
|
};
|
|
11
12
|
});
|
|
13
|
+
jest.mock('../models/ConnectionFlow');
|
|
12
14
|
var fetchExtraOAuthUrlParams = jest.fn();
|
|
13
15
|
fetchExtraOAuthUrlParams.mockResolvedValue({});
|
|
14
16
|
findKonnectorPolicy.mockReturnValue({
|
|
@@ -22,17 +24,20 @@ var fixtures = {
|
|
|
22
24
|
slug: 'test-konnector'
|
|
23
25
|
}
|
|
24
26
|
};
|
|
27
|
+
var flow = new ConnectionFlow();
|
|
25
28
|
describe('OAuthForm', function () {
|
|
26
29
|
it('should render', function () {
|
|
27
30
|
var component = shallow( /*#__PURE__*/React.createElement(OAuthForm, {
|
|
31
|
+
flow: flow,
|
|
28
32
|
flowState: {},
|
|
29
33
|
konnector: fixtures.konnector,
|
|
30
34
|
t: t
|
|
31
35
|
})).getElement();
|
|
32
36
|
expect(component).toMatchSnapshot();
|
|
33
37
|
});
|
|
34
|
-
it('should
|
|
38
|
+
it('should bypass reconnect button when updating an account', function () {
|
|
35
39
|
var component = shallow( /*#__PURE__*/React.createElement(OAuthForm, {
|
|
40
|
+
flow: flow,
|
|
36
41
|
flowState: {},
|
|
37
42
|
account: {
|
|
38
43
|
oauth: {
|
|
@@ -47,6 +52,7 @@ describe('OAuthForm', function () {
|
|
|
47
52
|
});
|
|
48
53
|
it('should call policy fetchExtraOAuthUrlParams with proper params', function () {
|
|
49
54
|
shallow( /*#__PURE__*/React.createElement(OAuthForm, {
|
|
55
|
+
flow: flow,
|
|
50
56
|
flowState: {},
|
|
51
57
|
account: {
|
|
52
58
|
oauth: {
|
|
@@ -63,7 +69,7 @@ describe('OAuthForm', function () {
|
|
|
63
69
|
}
|
|
64
70
|
},
|
|
65
71
|
client: undefined,
|
|
66
|
-
flow:
|
|
72
|
+
flow: flow,
|
|
67
73
|
konnector: {
|
|
68
74
|
slug: 'test-konnector'
|
|
69
75
|
}
|
|
@@ -71,6 +77,7 @@ describe('OAuthForm', function () {
|
|
|
71
77
|
});
|
|
72
78
|
it('should handle oauth cancelation', function () {
|
|
73
79
|
var component = shallow( /*#__PURE__*/React.createElement(OAuthForm, {
|
|
80
|
+
flow: flow,
|
|
74
81
|
flowState: {
|
|
75
82
|
error: new KonnectorJobError('OAUTH_CANCELED')
|
|
76
83
|
},
|
|
@@ -133,9 +133,6 @@ export var OAuthWindow = /*#__PURE__*/function (_PureComponent) {
|
|
|
133
133
|
succeed: true
|
|
134
134
|
});
|
|
135
135
|
if (typeof onSuccess !== 'function') return;
|
|
136
|
-
this.setState({
|
|
137
|
-
succeed: true
|
|
138
|
-
});
|
|
139
136
|
onSuccess(data.key);
|
|
140
137
|
}
|
|
141
138
|
/**
|
|
@@ -200,10 +197,8 @@ export var OAuthWindow = /*#__PURE__*/function (_PureComponent) {
|
|
|
200
197
|
var _this$props3 = this.props,
|
|
201
198
|
t = _this$props3.t,
|
|
202
199
|
intentsApi = _this$props3.intentsApi;
|
|
203
|
-
var
|
|
204
|
-
|
|
205
|
-
succeed = _this$state.succeed;
|
|
206
|
-
return oAuthUrl && !succeed && (!isFlagshipApp() && !intentsApi ? /*#__PURE__*/React.createElement(Popup, {
|
|
200
|
+
var oAuthUrl = this.state.oAuthUrl;
|
|
201
|
+
return oAuthUrl && (!isFlagshipApp() && !intentsApi ? /*#__PURE__*/React.createElement(Popup, {
|
|
207
202
|
url: oAuthUrl,
|
|
208
203
|
height: OAUTH_POPUP_HEIGHT,
|
|
209
204
|
width: OAUTH_POPUP_WIDTH,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
+
exports[`OAuthForm should bypass reconnect button when updating an account 1`] = `<React.Fragment />`;
|
|
4
|
+
|
|
3
5
|
exports[`OAuthForm should handle oauth cancelation 1`] = `
|
|
4
6
|
<React.Fragment>
|
|
5
7
|
<withI18n(withClient(withKonnectorLocales(TriggerErrorInfo))
|
|
@@ -34,16 +36,3 @@ exports[`OAuthForm should render 1`] = `
|
|
|
34
36
|
/>
|
|
35
37
|
</React.Fragment>
|
|
36
38
|
`;
|
|
37
|
-
|
|
38
|
-
exports[`OAuthForm should render reconnect button when updating an account 1`] = `
|
|
39
|
-
<React.Fragment>
|
|
40
|
-
<DefaultButton
|
|
41
|
-
busy={true}
|
|
42
|
-
className="u-mt-1"
|
|
43
|
-
disabled={true}
|
|
44
|
-
extension="full"
|
|
45
|
-
label="oauth.reconnect.label"
|
|
46
|
-
onClick={[Function]}
|
|
47
|
-
/>
|
|
48
|
-
</React.Fragment>
|
|
49
|
-
`;
|
|
@@ -3,8 +3,21 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
3
3
|
/* eslint-env jest */
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { render } from '@testing-library/react';
|
|
6
|
-
import AppLike from '
|
|
7
|
-
import KonnectorUpdateInfos from 'components/infos/KonnectorUpdateInfos';
|
|
6
|
+
import AppLike from '../../../test/AppLike';
|
|
7
|
+
import KonnectorUpdateInfos from 'components/infos/KonnectorUpdateInfos';
|
|
8
|
+
jest.mock('../KonnectorUpdateLinker', function () {
|
|
9
|
+
return function (_ref) {
|
|
10
|
+
var konnector = _ref.konnector,
|
|
11
|
+
label = _ref.label,
|
|
12
|
+
isBlocking = _ref.isBlocking;
|
|
13
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
14
|
+
"data-testtid": "KonnectorUpdateLinker",
|
|
15
|
+
"data-label": label,
|
|
16
|
+
"data-konnector": konnector,
|
|
17
|
+
"data-is-blocking": isBlocking
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
}); // Default props
|
|
8
21
|
|
|
9
22
|
var intents = {
|
|
10
23
|
redirect: jest.fn()
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
4
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
5
|
-
var _excluded = ["code"]
|
|
6
|
-
_excluded2 = ["code"];
|
|
5
|
+
var _excluded = ["code"];
|
|
7
6
|
|
|
8
7
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
9
8
|
|
|
@@ -23,13 +22,13 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
23
22
|
*
|
|
24
23
|
* - Deals with the konnector to get temporary tokens
|
|
25
24
|
*/
|
|
26
|
-
import {
|
|
25
|
+
import { getBIConnectionAccountsList } from './bi-http';
|
|
27
26
|
import assert from '../assert';
|
|
28
27
|
import logger from '../logger';
|
|
29
28
|
import { Q } from 'cozy-client'; // @ts-ignore (its a peerDep and I don't know how to configure ts for that)
|
|
30
29
|
|
|
31
30
|
import flag from 'cozy-flags';
|
|
32
|
-
import { setBIConnectionId,
|
|
31
|
+
import { setBIConnectionId, findAccountWithBiConnection, convertBIErrortoKonnectorJobError, isBudgetInsightConnector, getBIConnectionIdFromAccount } from './budget-insight';
|
|
33
32
|
import { KonnectorJobError } from '../helpers/konnectors';
|
|
34
33
|
import { waitForRealtimeEvent } from './jobUtils';
|
|
35
34
|
import '../types';
|
|
@@ -48,76 +47,56 @@ export var isBiWebViewConnector = function isBiWebViewConnector(konnector) {
|
|
|
48
47
|
/**
|
|
49
48
|
* Runs multiple checks on the bi connection referenced in the given account
|
|
50
49
|
* @param {object} options
|
|
51
|
-
* @param {
|
|
50
|
+
* @param {number} options.connId The BI connection identifier
|
|
52
51
|
* @param {KonnectorManifest} options.konnector konnector manifest content
|
|
53
|
-
* @param {ConnectionFlow} options.flow The flow
|
|
54
52
|
* @param {CozyClient} options.client CozyClient object
|
|
55
53
|
*
|
|
56
|
-
* @return {Promise
|
|
54
|
+
* @return {Promise}
|
|
55
|
+
* @throws KonnectorJobError
|
|
57
56
|
*/
|
|
58
57
|
|
|
59
58
|
export var checkBIConnection = /*#__PURE__*/function () {
|
|
60
59
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
|
|
61
|
-
var
|
|
60
|
+
var connId, client, konnector, sameAccount, err;
|
|
62
61
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
63
62
|
while (1) {
|
|
64
63
|
switch (_context.prev = _context.next) {
|
|
65
64
|
case 0:
|
|
66
|
-
|
|
65
|
+
connId = _ref.connId, client = _ref.client, konnector = _ref.konnector;
|
|
67
66
|
_context.prev = 1;
|
|
68
|
-
connId = getWebviewBIConnectionId(account);
|
|
69
67
|
logger.info('Creating temporary token...');
|
|
70
|
-
_context.next =
|
|
71
|
-
return createTemporaryToken({
|
|
72
|
-
client: client,
|
|
73
|
-
konnector: konnector,
|
|
74
|
-
account: account
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
case 6:
|
|
78
|
-
biConfig = _context.sent;
|
|
79
|
-
saveBIConfig(flow, biConfig);
|
|
80
|
-
tempToken = biConfig.code, config = _objectWithoutProperties(biConfig, _excluded);
|
|
81
|
-
logger.info('Created temporary token');
|
|
82
|
-
assert(tempToken, 'No temporary token');
|
|
83
|
-
logger.info("fetch connection ".concat(connId, "..."));
|
|
84
|
-
_context.next = 14;
|
|
85
|
-
return getBIConnection(config, connId, tempToken);
|
|
86
|
-
|
|
87
|
-
case 14:
|
|
88
|
-
connection = _context.sent;
|
|
89
|
-
_context.next = 17;
|
|
68
|
+
_context.next = 5;
|
|
90
69
|
return findAccountWithBiConnection({
|
|
91
70
|
client: client,
|
|
92
71
|
konnector: konnector,
|
|
93
|
-
connectionId:
|
|
72
|
+
connectionId: connId
|
|
94
73
|
});
|
|
95
74
|
|
|
96
|
-
case
|
|
75
|
+
case 5:
|
|
97
76
|
sameAccount = _context.sent;
|
|
98
77
|
|
|
99
78
|
if (!sameAccount) {
|
|
100
|
-
_context.next =
|
|
79
|
+
_context.next = 9;
|
|
101
80
|
break;
|
|
102
81
|
}
|
|
103
82
|
|
|
104
83
|
err = new KonnectorJobError('ACCOUNT_WITH_SAME_IDENTIFIER_ALREADY_DEFINED');
|
|
105
84
|
throw err;
|
|
106
85
|
|
|
107
|
-
case
|
|
108
|
-
return _context.abrupt("return"
|
|
86
|
+
case 9:
|
|
87
|
+
return _context.abrupt("return");
|
|
109
88
|
|
|
110
|
-
case
|
|
111
|
-
_context.prev =
|
|
89
|
+
case 12:
|
|
90
|
+
_context.prev = 12;
|
|
112
91
|
_context.t0 = _context["catch"](1);
|
|
113
92
|
return _context.abrupt("return", convertBIErrortoKonnectorJobError(_context.t0));
|
|
114
93
|
|
|
115
|
-
case
|
|
94
|
+
case 15:
|
|
116
95
|
case "end":
|
|
117
96
|
return _context.stop();
|
|
118
97
|
}
|
|
119
98
|
}
|
|
120
|
-
}, _callee, null, [[1,
|
|
99
|
+
}, _callee, null, [[1, 12]]);
|
|
121
100
|
}));
|
|
122
101
|
|
|
123
102
|
return function checkBIConnection(_x) {
|
|
@@ -170,7 +149,7 @@ export var fetchContractSynchronizationUrl = /*#__PURE__*/function () {
|
|
|
170
149
|
* @param {CozyClient} options.client CozyClient object
|
|
171
150
|
* @param {Boolean} options.reconnect If this is a reconnexion
|
|
172
151
|
* @param {Function} options.t Translation fonction
|
|
173
|
-
* @return {Promise<Number>} Connection Id
|
|
152
|
+
* @return {Promise<Number|null>} Connection Id
|
|
174
153
|
*/
|
|
175
154
|
|
|
176
155
|
export var handleOAuthAccount = /*#__PURE__*/function () {
|
|
@@ -295,7 +274,7 @@ var getWebviewBIConnectionId = function getWebviewBIConnectionId(account) {
|
|
|
295
274
|
|
|
296
275
|
export var onBIAccountCreation = /*#__PURE__*/function () {
|
|
297
276
|
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref7) {
|
|
298
|
-
var fullAccount, client, flow, konnector, account,
|
|
277
|
+
var fullAccount, client, flow, konnector, account, connId, updatedAccount;
|
|
299
278
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
300
279
|
while (1) {
|
|
301
280
|
switch (_context4.prev = _context4.next) {
|
|
@@ -306,30 +285,33 @@ export var onBIAccountCreation = /*#__PURE__*/function () {
|
|
|
306
285
|
|
|
307
286
|
case 3:
|
|
308
287
|
account = _context4.sent;
|
|
309
|
-
|
|
288
|
+
connId = getWebviewBIConnectionId(account);
|
|
289
|
+
|
|
290
|
+
if (!(connId === null)) {
|
|
291
|
+
_context4.next = 7;
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
throw new Error('onBIAccountCreation: bi connection id should not be null on creation');
|
|
296
|
+
|
|
297
|
+
case 7:
|
|
298
|
+
_context4.next = 9;
|
|
310
299
|
return checkBIConnection({
|
|
311
|
-
|
|
312
|
-
_id: account._id
|
|
313
|
-
}),
|
|
300
|
+
connId: connId,
|
|
314
301
|
client: client,
|
|
315
|
-
konnector: konnector
|
|
316
|
-
flow: flow
|
|
302
|
+
konnector: konnector
|
|
317
303
|
});
|
|
318
304
|
|
|
319
|
-
case
|
|
320
|
-
|
|
321
|
-
flow.
|
|
322
|
-
biConnection: biConnection
|
|
323
|
-
});
|
|
324
|
-
_context4.next = 10;
|
|
325
|
-
return flow.saveAccount(setBIConnectionId(account, biConnection.id));
|
|
305
|
+
case 9:
|
|
306
|
+
_context4.next = 11;
|
|
307
|
+
return flow.saveAccount(setBIConnectionId(account, connId));
|
|
326
308
|
|
|
327
|
-
case
|
|
309
|
+
case 11:
|
|
328
310
|
updatedAccount = _context4.sent;
|
|
329
311
|
flow.triggerEvent(LOGIN_SUCCESS_EVENT);
|
|
330
312
|
return _context4.abrupt("return", updatedAccount);
|
|
331
313
|
|
|
332
|
-
case
|
|
314
|
+
case 14:
|
|
333
315
|
case "end":
|
|
334
316
|
return _context4.stop();
|
|
335
317
|
}
|
|
@@ -479,7 +461,7 @@ export var refreshContracts = /*#__PURE__*/function () {
|
|
|
479
461
|
|
|
480
462
|
case 3:
|
|
481
463
|
biConfig = _context6.sent;
|
|
482
|
-
code = biConfig.code, config = _objectWithoutProperties(biConfig,
|
|
464
|
+
code = biConfig.code, config = _objectWithoutProperties(biConfig, _excluded);
|
|
483
465
|
connectionId = getWebviewBIConnectionId(account);
|
|
484
466
|
_context6.next = 8;
|
|
485
467
|
return getBIConnectionAccountsList(config, connectionId, code);
|