cozy-harvest-lib 9.7.2 → 9.8.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/CHANGELOG.md +38 -0
- package/dist/components/EditAccountModal.js +4 -1
- package/dist/components/KonnectorConfiguration/ConfigurationTab/BiContractActivationWindow.js +2 -2
- package/dist/components/OAuthForm.js +13 -10
- package/dist/components/OAuthForm.spec.js +3 -2
- package/dist/components/OAuthWindow.js +11 -3
- package/dist/components/TriggerManager.js +7 -2
- package/dist/components/__snapshots__/OAuthForm.spec.js.snap +13 -0
- package/dist/helpers/oauth.js +31 -11
- package/dist/helpers/oauth.spec.js +15 -1
- package/dist/locales/en.json +3 -0
- package/dist/locales/fr.json +4 -1
- package/dist/services/biWebView.js +104 -42
- package/dist/services/biWebView.spec.js +293 -1
- package/dist/services/budget-insight.js +3 -2
- package/package.json +2 -2
- package/src/components/EditAccountModal.jsx +2 -0
- package/src/components/KonnectorConfiguration/ConfigurationTab/BiContractActivationWindow.jsx +2 -2
- package/src/components/OAuthForm.jsx +11 -8
- package/src/components/OAuthForm.spec.js +3 -2
- package/src/components/OAuthWindow.jsx +9 -3
- package/src/components/TriggerManager.jsx +6 -2
- package/src/components/__snapshots__/OAuthForm.spec.js.snap +13 -0
- package/src/helpers/oauth.js +35 -12
- package/src/helpers/oauth.spec.js +16 -1
- package/src/locales/en.json +3 -0
- package/src/locales/fr.json +4 -1
- package/src/services/biWebView.js +49 -2
- package/src/services/biWebView.spec.js +150 -1
- package/src/services/budget-insight.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,44 @@
|
|
|
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.8.1](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.8.0...cozy-harvest-lib@9.8.1) (2022-06-12)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Update french locale ([902ae96](https://github.com/cozy/cozy-libs/commit/902ae967a14c106c7cc3adc0543d479d94e2f07e))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [9.8.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.7.3...cozy-harvest-lib@9.8.0) (2022-06-09)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* Small fixes after review ([d4f50ba](https://github.com/cozy/cozy-libs/commit/d4f50ba114cd4f8d43fac8545f6356c380edd262))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* Add BI webview reconnection ([d0f9c9e](https://github.com/cozy/cozy-libs/commit/d0f9c9e556d847e072063eb877d5d4e57ee8cca0))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## [9.7.3](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.7.2...cozy-harvest-lib@9.7.3) (2022-06-08)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Bug Fixes
|
|
37
|
+
|
|
38
|
+
* Avoid React error message when not in BI webview mode ([413853d](https://github.com/cozy/cozy-libs/commit/413853da26b5d580f5454d7cf6c6069c3b2880b0))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
6
44
|
## [9.7.2](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.7.1...cozy-harvest-lib@9.7.2) (2022-06-07)
|
|
7
45
|
|
|
8
46
|
**Note:** Version bump only for package cozy-harvest-lib
|
|
@@ -102,7 +102,10 @@ var DumbEditAccountModal = withRouter(function (_ref) {
|
|
|
102
102
|
onSuccess: redirectToAccount,
|
|
103
103
|
showError: true,
|
|
104
104
|
onVaultDismiss: redirectToAccount,
|
|
105
|
-
fieldOptions: fieldOptions
|
|
105
|
+
fieldOptions: fieldOptions,
|
|
106
|
+
reconnect: fromReconnect
|
|
107
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
108
|
+
className: "u-mb-2"
|
|
106
109
|
})));
|
|
107
110
|
});
|
|
108
111
|
export var EditAccountModal = /*#__PURE__*/function (_Component) {
|
package/dist/components/KonnectorConfiguration/ConfigurationTab/BiContractActivationWindow.js
CHANGED
|
@@ -112,7 +112,7 @@ var BIContractActivationWindow = function BIContractActivationWindow(_ref) {
|
|
|
112
112
|
handleLinkFetch();
|
|
113
113
|
}
|
|
114
114
|
}, [konnector, account, client, konnectorPolicy]);
|
|
115
|
-
return konnectorPolicy.fetchContractSynchronizationUrl
|
|
115
|
+
return konnectorPolicy.fetchContractSynchronizationUrl ? /*#__PURE__*/React.createElement(ListItem, null, /*#__PURE__*/React.createElement(Button, {
|
|
116
116
|
disabled: !initialUrl,
|
|
117
117
|
onClick: function onClick() {
|
|
118
118
|
return setWindowVisible(true);
|
|
@@ -125,7 +125,7 @@ var BIContractActivationWindow = function BIContractActivationWindow(_ref) {
|
|
|
125
125
|
width: "800",
|
|
126
126
|
height: "800",
|
|
127
127
|
onClose: onPopupClosed
|
|
128
|
-
})));
|
|
128
|
+
}))) : null;
|
|
129
129
|
};
|
|
130
130
|
|
|
131
131
|
BIContractActivationWindow.propTypes = {
|
|
@@ -38,7 +38,6 @@ export var OAuthForm = /*#__PURE__*/function (_PureComponent) {
|
|
|
38
38
|
_this.handleOAuthCancel = _this.handleOAuthCancel.bind(_assertThisInitialized(_this));
|
|
39
39
|
_this.handleExtraParams = _this.handleExtraParams.bind(_assertThisInitialized(_this));
|
|
40
40
|
_this.state = {
|
|
41
|
-
initialValues: null,
|
|
42
41
|
showingOAuthModal: false
|
|
43
42
|
};
|
|
44
43
|
return _this;
|
|
@@ -52,9 +51,6 @@ export var OAuthForm = /*#__PURE__*/function (_PureComponent) {
|
|
|
52
51
|
konnector = _this$props.konnector,
|
|
53
52
|
flow = _this$props.flow,
|
|
54
53
|
client = _this$props.client;
|
|
55
|
-
this.setState({
|
|
56
|
-
initialValues: account ? account.oauth : null
|
|
57
|
-
});
|
|
58
54
|
var konnectorPolicy = findKonnectorPolicy(konnector);
|
|
59
55
|
|
|
60
56
|
if (konnectorPolicy.fetchExtraOAuthUrlParams) {
|
|
@@ -114,25 +110,29 @@ export var OAuthForm = /*#__PURE__*/function (_PureComponent) {
|
|
|
114
110
|
var _this$props2 = this.props,
|
|
115
111
|
konnector = _this$props2.konnector,
|
|
116
112
|
t = _this$props2.t,
|
|
117
|
-
flowState = _this$props2.flowState
|
|
113
|
+
flowState = _this$props2.flowState,
|
|
114
|
+
reconnect = _this$props2.reconnect,
|
|
115
|
+
account = _this$props2.account;
|
|
118
116
|
var _this$state = this.state,
|
|
119
|
-
initialValues = _this$state.initialValues,
|
|
120
117
|
showOAuthWindow = _this$state.showOAuthWindow,
|
|
121
118
|
needExtraParams = _this$state.needExtraParams,
|
|
122
119
|
extraParams = _this$state.extraParams;
|
|
123
120
|
var isBusy = showOAuthWindow === true || flowState.running || needExtraParams && !extraParams;
|
|
124
|
-
|
|
121
|
+
var buttonLabel = reconnect ? 'oauth.reconnect.label' : 'oauth.connect.label';
|
|
122
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
|
|
125
123
|
className: "u-mt-1",
|
|
126
124
|
busy: isBusy,
|
|
127
125
|
disabled: isBusy,
|
|
128
126
|
extension: "full",
|
|
129
|
-
label: t(
|
|
127
|
+
label: t(buttonLabel),
|
|
130
128
|
onClick: this.handleConnect
|
|
131
129
|
}), showOAuthWindow && /*#__PURE__*/React.createElement(OAuthWindow, {
|
|
132
130
|
extraParams: extraParams,
|
|
133
131
|
konnector: konnector,
|
|
132
|
+
reconnect: reconnect,
|
|
134
133
|
onSuccess: this.handleAccountId,
|
|
135
|
-
onCancel: this.handleOAuthCancel
|
|
134
|
+
onCancel: this.handleOAuthCancel,
|
|
135
|
+
account: account
|
|
136
136
|
}));
|
|
137
137
|
}
|
|
138
138
|
}]);
|
|
@@ -150,6 +150,9 @@ OAuthForm.propTypes = {
|
|
|
150
150
|
onSuccess: PropTypes.func,
|
|
151
151
|
|
|
152
152
|
/** Translation function */
|
|
153
|
-
t: PropTypes.func.isRequired
|
|
153
|
+
t: PropTypes.func.isRequired,
|
|
154
|
+
|
|
155
|
+
/** Is it a reconnection or not */
|
|
156
|
+
reconnect: PropTypes.bool
|
|
154
157
|
};
|
|
155
158
|
export default compose(translate(), withConnectionFlow())(OAuthForm);
|
|
@@ -30,7 +30,7 @@ describe('OAuthForm', function () {
|
|
|
30
30
|
})).getElement();
|
|
31
31
|
expect(component).toMatchSnapshot();
|
|
32
32
|
});
|
|
33
|
-
it('should
|
|
33
|
+
it('should render reconnect button when updating an account', function () {
|
|
34
34
|
var component = shallow( /*#__PURE__*/React.createElement(OAuthForm, {
|
|
35
35
|
flowState: {},
|
|
36
36
|
account: {
|
|
@@ -39,9 +39,10 @@ describe('OAuthForm', function () {
|
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
konnector: fixtures.konnector,
|
|
42
|
+
reconnect: true,
|
|
42
43
|
t: t
|
|
43
44
|
})).getElement();
|
|
44
|
-
expect(component).
|
|
45
|
+
expect(component).toMatchSnapshot();
|
|
45
46
|
});
|
|
46
47
|
it('should call policy fetchExtraOAuthUrlParams with proper params', function () {
|
|
47
48
|
shallow( /*#__PURE__*/React.createElement(OAuthForm, {
|
|
@@ -65,13 +65,15 @@ export var OAuthWindow = /*#__PURE__*/function (_PureComponent) {
|
|
|
65
65
|
client = _this$props.client,
|
|
66
66
|
konnector = _this$props.konnector,
|
|
67
67
|
redirectSlug = _this$props.redirectSlug,
|
|
68
|
-
extraParams = _this$props.extraParams
|
|
68
|
+
extraParams = _this$props.extraParams,
|
|
69
|
+
reconnect = _this$props.reconnect,
|
|
70
|
+
account = _this$props.account;
|
|
69
71
|
this.realtime = new CozyRealtime({
|
|
70
72
|
client: client
|
|
71
73
|
});
|
|
72
74
|
this.realtime.subscribe('notified', 'io.cozy.accounts', OAUTH_REALTIME_CHANNEL, this.handleMessage);
|
|
73
75
|
|
|
74
|
-
var _prepareOAuth = prepareOAuth(client, konnector, redirectSlug, extraParams),
|
|
76
|
+
var _prepareOAuth = prepareOAuth(client, konnector, redirectSlug, extraParams, reconnect, account),
|
|
75
77
|
oAuthStateKey = _prepareOAuth.oAuthStateKey,
|
|
76
78
|
oAuthUrl = _prepareOAuth.oAuthUrl;
|
|
77
79
|
|
|
@@ -210,6 +212,12 @@ OAuthWindow.propTypes = {
|
|
|
210
212
|
onCancel: PropTypes.func,
|
|
211
213
|
|
|
212
214
|
/** The app we want to redirect the user on, after the OAuth flow. It used by the stack */
|
|
213
|
-
redirectSlug: PropTypes.string
|
|
215
|
+
redirectSlug: PropTypes.string,
|
|
216
|
+
|
|
217
|
+
/** Is it a reconnection or not */
|
|
218
|
+
reconnect: PropTypes.bool,
|
|
219
|
+
|
|
220
|
+
/** Existing account */
|
|
221
|
+
account: PropTypes.object
|
|
214
222
|
};
|
|
215
223
|
export default translate()(withClient(OAuthWindow));
|
|
@@ -507,7 +507,8 @@ export var DumbTriggerManager = /*#__PURE__*/function (_Component) {
|
|
|
507
507
|
flow = _this$props5.flow,
|
|
508
508
|
flowState = _this$props5.flowState,
|
|
509
509
|
client = _this$props5.client,
|
|
510
|
-
OAuthFormWrapperComp = _this$props5.OAuthFormWrapperComp
|
|
510
|
+
OAuthFormWrapperComp = _this$props5.OAuthFormWrapperComp,
|
|
511
|
+
reconnect = _this$props5.reconnect;
|
|
511
512
|
var submitting = flowState.running;
|
|
512
513
|
var _this$state = this.state,
|
|
513
514
|
account = _this$state.account,
|
|
@@ -527,6 +528,7 @@ export var DumbTriggerManager = /*#__PURE__*/function (_Component) {
|
|
|
527
528
|
client: client,
|
|
528
529
|
flow: flow,
|
|
529
530
|
account: account,
|
|
531
|
+
reconnect: reconnect,
|
|
530
532
|
konnector: konnector,
|
|
531
533
|
onSuccess: this.handleOAuthAccountId
|
|
532
534
|
}));
|
|
@@ -617,7 +619,10 @@ DumbTriggerManager.propTypes = {
|
|
|
617
619
|
flow: PropTypes.object,
|
|
618
620
|
flowState: PropTypes.object,
|
|
619
621
|
// Used to inject a component around OAuthForm, and so customize the UI from the app
|
|
620
|
-
OAuthFormWrapperComp: PropTypes.node
|
|
622
|
+
OAuthFormWrapperComp: PropTypes.node,
|
|
623
|
+
|
|
624
|
+
/** Is it a reconnection or not */
|
|
625
|
+
reconnect: PropTypes.bool
|
|
621
626
|
};
|
|
622
627
|
var TriggerManager = compose(translate(), withClient, withVaultUnlockContext, withConnectionFlow())(DumbTriggerManager); // TriggerManager is exported wrapped in FlowProvider to avoid breaking changes.
|
|
623
628
|
|
|
@@ -12,3 +12,16 @@ exports[`OAuthForm should render 1`] = `
|
|
|
12
12
|
/>
|
|
13
13
|
</React.Fragment>
|
|
14
14
|
`;
|
|
15
|
+
|
|
16
|
+
exports[`OAuthForm should render reconnect button when update 1`] = `
|
|
17
|
+
<React.Fragment>
|
|
18
|
+
<DefaultButton
|
|
19
|
+
busy={true}
|
|
20
|
+
className="u-mt-1"
|
|
21
|
+
disabled={true}
|
|
22
|
+
extension="full"
|
|
23
|
+
label="oauth.reconnect.label"
|
|
24
|
+
onClick={[Function]}
|
|
25
|
+
/>
|
|
26
|
+
</React.Fragment>
|
|
27
|
+
`;
|
package/dist/helpers/oauth.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
1
2
|
import uuid from 'uuid/v4';
|
|
2
3
|
import get from 'lodash/get';
|
|
3
4
|
import CozyClient from 'cozy-client';
|
|
@@ -94,6 +95,9 @@ export var handleOAuthResponse = function handleOAuthResponse() {
|
|
|
94
95
|
* @param {string} redirectSlug The app we want to redirect the user on after the end of the flow
|
|
95
96
|
* @param {string} nonce unique nonce string
|
|
96
97
|
* @param {Object} extraParams some extra parameters to add to the query string
|
|
98
|
+
* @param {Boolean} reconnect Are we trying to reconnect an existing account ?
|
|
99
|
+
* @param {io.cozy.accounts} account targeted account if any
|
|
100
|
+
* @returns {String} final OAuth url string
|
|
97
101
|
*/
|
|
98
102
|
|
|
99
103
|
export var getOAuthUrl = function getOAuthUrl(_ref) {
|
|
@@ -104,25 +108,35 @@ export var getOAuthUrl = function getOAuthUrl(_ref) {
|
|
|
104
108
|
oAuthConf = _ref$oAuthConf === void 0 ? {} : _ref$oAuthConf,
|
|
105
109
|
nonce = _ref.nonce,
|
|
106
110
|
redirectSlug = _ref.redirectSlug,
|
|
107
|
-
extraParams = _ref.extraParams
|
|
108
|
-
|
|
111
|
+
extraParams = _ref.extraParams,
|
|
112
|
+
reconnect = _ref.reconnect,
|
|
113
|
+
account = _ref.account;
|
|
114
|
+
var startOrReconnect = reconnect ? 'reconnect' : 'start';
|
|
115
|
+
var accountIdParam = reconnect ? account._id + '/' : '';
|
|
116
|
+
var oAuthUrl = new URL("".concat(cozyUrl, "/accounts/").concat(accountType, "/").concat(accountIdParam).concat(startOrReconnect));
|
|
117
|
+
oAuthUrl.searchParams.set('state', oAuthStateKey);
|
|
118
|
+
oAuthUrl.searchParams.set('nonce', nonce);
|
|
109
119
|
|
|
110
120
|
if (oAuthConf.scope !== undefined && oAuthConf.scope !== null && oAuthConf.scope !== false) {
|
|
111
121
|
var urlScope = Array.isArray(oAuthConf.scope) ? oAuthConf.scope.join('+') : oAuthConf.scope;
|
|
112
|
-
oAuthUrl
|
|
122
|
+
oAuthUrl.searchParams.set('scope', urlScope);
|
|
113
123
|
}
|
|
114
124
|
|
|
115
125
|
if (redirectSlug) {
|
|
116
|
-
oAuthUrl
|
|
126
|
+
oAuthUrl.searchParams.set('slug', redirectSlug);
|
|
117
127
|
}
|
|
118
128
|
|
|
119
129
|
if (extraParams) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
130
|
+
Object.entries(extraParams).forEach(function (_ref2) {
|
|
131
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
132
|
+
key = _ref3[0],
|
|
133
|
+
value = _ref3[1];
|
|
134
|
+
|
|
135
|
+
return oAuthUrl.searchParams.set(key, value);
|
|
136
|
+
});
|
|
123
137
|
}
|
|
124
138
|
|
|
125
|
-
return oAuthUrl;
|
|
139
|
+
return oAuthUrl.toString();
|
|
126
140
|
};
|
|
127
141
|
|
|
128
142
|
var getAppSlug = function getAppSlug(client) {
|
|
@@ -135,12 +149,16 @@ var getAppSlug = function getAppSlug(client) {
|
|
|
135
149
|
* @param {string} domain Cozy domain
|
|
136
150
|
* @param {Object} konnector
|
|
137
151
|
* @param {string} redirectSlug The app we want to redirect the user on after the end of the flow
|
|
138
|
-
* @
|
|
139
|
-
*
|
|
152
|
+
* @param {Object} extraParams some extra parameters to add to the query string
|
|
153
|
+
* @param {Boolean} reconnect Are we trying to reconnect an existing account ?
|
|
154
|
+
* @param {io.cozy.accounts} account targetted account if any
|
|
155
|
+
* @return {Object} Object containing: `oAuthUrl` (URL of cozy stack OAuth endpoint) and `oAuthStateKey` (localStorage key)
|
|
140
156
|
*/
|
|
141
157
|
|
|
142
158
|
|
|
143
159
|
export var prepareOAuth = function prepareOAuth(client, konnector, redirectSlug, extraParams) {
|
|
160
|
+
var reconnect = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
161
|
+
var account = arguments.length > 5 ? arguments[5] : undefined;
|
|
144
162
|
var oauth = konnector.oauth;
|
|
145
163
|
var accountType = konnectors.getAccountType(konnector); // We use localStorage to store the account related data
|
|
146
164
|
// We will later check in localStorage that the received information is
|
|
@@ -159,7 +177,9 @@ export var prepareOAuth = function prepareOAuth(client, konnector, redirectSlug,
|
|
|
159
177
|
oAuthConf: oauth,
|
|
160
178
|
nonce: Date.now(),
|
|
161
179
|
redirectSlug: redirectSlug || getAppSlug(client),
|
|
162
|
-
extraParams: extraParams
|
|
180
|
+
extraParams: extraParams,
|
|
181
|
+
reconnect: reconnect,
|
|
182
|
+
account: account
|
|
163
183
|
});
|
|
164
184
|
return {
|
|
165
185
|
oAuthStateKey: oAuthStateKey,
|
|
@@ -53,7 +53,7 @@ describe('Oauth helper', function () {
|
|
|
53
53
|
scope: ['thescope', 'thescope2']
|
|
54
54
|
}
|
|
55
55
|
}));
|
|
56
|
-
expect(url).toEqual('https://cozyurl/accounts/testslug/start?state=statekey&nonce=1234&scope=thescope
|
|
56
|
+
expect(url).toEqual('https://cozyurl/accounts/testslug/start?state=statekey&nonce=1234&scope=thescope%2Bthescope2');
|
|
57
57
|
});
|
|
58
58
|
it('should use redirectSlug if present', function () {
|
|
59
59
|
var url = getOAuthUrl(_objectSpread(_objectSpread({}, defaultConf), {}, {
|
|
@@ -72,6 +72,20 @@ describe('Oauth helper', function () {
|
|
|
72
72
|
}));
|
|
73
73
|
expect(url).toEqual('https://cozyurl/accounts/testslug/start?state=statekey&nonce=1234&token=thetoken&id_connector=40');
|
|
74
74
|
});
|
|
75
|
+
it('should return reconnect url with account id if reconnect', function () {
|
|
76
|
+
var url = getOAuthUrl(_objectSpread(_objectSpread({}, defaultConf), {}, {
|
|
77
|
+
oAuthConf: {},
|
|
78
|
+
account: {
|
|
79
|
+
_id: 'accountid'
|
|
80
|
+
},
|
|
81
|
+
reconnect: true,
|
|
82
|
+
extraParams: {
|
|
83
|
+
code: 'thecode',
|
|
84
|
+
connection_id: 12345
|
|
85
|
+
}
|
|
86
|
+
}));
|
|
87
|
+
expect(url).toEqual('https://cozyurl/accounts/testslug/accountid/reconnect?state=statekey&nonce=1234&code=thecode&connection_id=12345');
|
|
88
|
+
});
|
|
75
89
|
});
|
|
76
90
|
describe('handleOAuthResponse', function () {
|
|
77
91
|
var originalLocation;
|
package/dist/locales/en.json
CHANGED
package/dist/locales/fr.json
CHANGED
|
@@ -25,7 +25,7 @@ import { getBIConnection, getBIConnectionAccountsList } from './bi-http';
|
|
|
25
25
|
import assert from '../assert';
|
|
26
26
|
import logger from '../logger';
|
|
27
27
|
import flag from 'cozy-flags';
|
|
28
|
-
import { setBIConnectionId, saveBIConfig, findAccountWithBiConnection, convertBIErrortoKonnectorJobError, isBudgetInsightConnector } from './budget-insight';
|
|
28
|
+
import { setBIConnectionId, saveBIConfig, findAccountWithBiConnection, convertBIErrortoKonnectorJobError, isBudgetInsightConnector, getBIConnectionIdFromAccount } from './budget-insight';
|
|
29
29
|
import { KonnectorJobError } from '../helpers/konnectors';
|
|
30
30
|
import { waitForRealtimeEvent } from './jobUtils';
|
|
31
31
|
import '../types';
|
|
@@ -288,16 +288,62 @@ export var onBIAccountCreation = /*#__PURE__*/function () {
|
|
|
288
288
|
return _ref8.apply(this, arguments);
|
|
289
289
|
};
|
|
290
290
|
}();
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
291
|
+
/**
|
|
292
|
+
* Create OAuth extra parameters specific to reconnect webview
|
|
293
|
+
*
|
|
294
|
+
* @param {Number} options.biBankId - Connector bank id (compatible with non webview bi connectors)
|
|
295
|
+
* @param {Array<Number>} options.biBankIds - connector bank ids (for webview connectors)
|
|
296
|
+
* @param {String} options.token - BI temporary token
|
|
297
|
+
* @param {Number} options.connId - BI bi connection id
|
|
298
|
+
* @return {Object}
|
|
299
|
+
*/
|
|
294
300
|
|
|
301
|
+
var getReconnectExtraOAuthUrlParams = /*#__PURE__*/function () {
|
|
302
|
+
var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref9) {
|
|
303
|
+
var biBankId, biBankIds, token, connId;
|
|
295
304
|
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
296
305
|
while (1) {
|
|
297
306
|
switch (_context5.prev = _context5.next) {
|
|
298
307
|
case 0:
|
|
299
|
-
|
|
300
|
-
_context5.
|
|
308
|
+
biBankId = _ref9.biBankId, biBankIds = _ref9.biBankIds, token = _ref9.token, connId = _ref9.connId;
|
|
309
|
+
return _context5.abrupt("return", {
|
|
310
|
+
id_connector: biBankId || biBankIds,
|
|
311
|
+
code: token,
|
|
312
|
+
connection_id: connId
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
case 2:
|
|
316
|
+
case "end":
|
|
317
|
+
return _context5.stop();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}, _callee5);
|
|
321
|
+
}));
|
|
322
|
+
|
|
323
|
+
return function getReconnectExtraOAuthUrlParams(_x5) {
|
|
324
|
+
return _ref10.apply(this, arguments);
|
|
325
|
+
};
|
|
326
|
+
}();
|
|
327
|
+
/**
|
|
328
|
+
* Create OAuth extra parameters
|
|
329
|
+
*
|
|
330
|
+
* @param {CozyClient} options.client - CozyClient instance
|
|
331
|
+
* @param {io.cozy.konnectors} options.konnector connector manifest content
|
|
332
|
+
* @param {io.cozy.accounts} options.account The account content
|
|
333
|
+
* @return {Promise<Object>}
|
|
334
|
+
*/
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
export var fetchExtraOAuthUrlParams = /*#__PURE__*/function () {
|
|
338
|
+
var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref11) {
|
|
339
|
+
var client, konnector, account, _yield$createTemporar2, token, biBankId, biBankIds, connId, isReconnect;
|
|
340
|
+
|
|
341
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
342
|
+
while (1) {
|
|
343
|
+
switch (_context6.prev = _context6.next) {
|
|
344
|
+
case 0:
|
|
345
|
+
client = _ref11.client, konnector = _ref11.konnector, account = _ref11.account;
|
|
346
|
+
_context6.next = 3;
|
|
301
347
|
return createTemporaryToken({
|
|
302
348
|
client: client,
|
|
303
349
|
konnector: konnector,
|
|
@@ -305,25 +351,41 @@ export var fetchExtraOAuthUrlParams = /*#__PURE__*/function () {
|
|
|
305
351
|
});
|
|
306
352
|
|
|
307
353
|
case 3:
|
|
308
|
-
_yield$createTemporar2 =
|
|
354
|
+
_yield$createTemporar2 = _context6.sent;
|
|
309
355
|
token = _yield$createTemporar2.code;
|
|
310
356
|
biBankId = _yield$createTemporar2.biBankId;
|
|
311
357
|
biBankIds = _yield$createTemporar2.biBankIds;
|
|
312
|
-
|
|
358
|
+
connId = getBIConnectionIdFromAccount(account);
|
|
359
|
+
isReconnect = Boolean(connId);
|
|
360
|
+
|
|
361
|
+
if (!isReconnect) {
|
|
362
|
+
_context6.next = 13;
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return _context6.abrupt("return", getReconnectExtraOAuthUrlParams({
|
|
367
|
+
biBankId: biBankId,
|
|
368
|
+
biBankIds: biBankIds,
|
|
369
|
+
token: token,
|
|
370
|
+
connId: connId
|
|
371
|
+
}));
|
|
372
|
+
|
|
373
|
+
case 13:
|
|
374
|
+
return _context6.abrupt("return", {
|
|
313
375
|
id_connector: biBankId || biBankIds,
|
|
314
376
|
token: token
|
|
315
377
|
});
|
|
316
378
|
|
|
317
|
-
case
|
|
379
|
+
case 14:
|
|
318
380
|
case "end":
|
|
319
|
-
return
|
|
381
|
+
return _context6.stop();
|
|
320
382
|
}
|
|
321
383
|
}
|
|
322
|
-
},
|
|
384
|
+
}, _callee6);
|
|
323
385
|
}));
|
|
324
386
|
|
|
325
|
-
return function fetchExtraOAuthUrlParams(
|
|
326
|
-
return
|
|
387
|
+
return function fetchExtraOAuthUrlParams(_x6) {
|
|
388
|
+
return _ref12.apply(this, arguments);
|
|
327
389
|
};
|
|
328
390
|
}();
|
|
329
391
|
/**
|
|
@@ -334,11 +396,11 @@ export var fetchExtraOAuthUrlParams = /*#__PURE__*/function () {
|
|
|
334
396
|
* @return {Array<String>} - list of bank ids
|
|
335
397
|
*/
|
|
336
398
|
|
|
337
|
-
export var getCozyBankIds = function getCozyBankIds(
|
|
399
|
+
export var getCozyBankIds = function getCozyBankIds(_ref13) {
|
|
338
400
|
var _konnector$parameters, _account$auth, _konnector$fields, _konnector$fields$ban;
|
|
339
401
|
|
|
340
|
-
var konnector =
|
|
341
|
-
account =
|
|
402
|
+
var konnector = _ref13.konnector,
|
|
403
|
+
account = _ref13.account;
|
|
342
404
|
var cozyBankId = (konnector === null || konnector === void 0 ? void 0 : (_konnector$parameters = konnector.parameters) === null || _konnector$parameters === void 0 ? void 0 : _konnector$parameters.bankId) || (account === null || account === void 0 ? void 0 : (_account$auth = account.auth) === null || _account$auth === void 0 ? void 0 : _account$auth.bankId);
|
|
343
405
|
|
|
344
406
|
if (cozyBankId) {
|
|
@@ -364,17 +426,17 @@ export var getCozyBankIds = function getCozyBankIds(_ref11) {
|
|
|
364
426
|
*/
|
|
365
427
|
|
|
366
428
|
export var refreshContracts = /*#__PURE__*/function () {
|
|
367
|
-
var
|
|
429
|
+
var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref14) {
|
|
368
430
|
var _account$relationship, _account$relationship2;
|
|
369
431
|
|
|
370
432
|
var client, konnector, account, biConfig, code, config, connectionId, _yield$getBIConnectio, contracts, contractsById, currentContractsList, _iterator, _step, currentContract, disabledValue;
|
|
371
433
|
|
|
372
|
-
return _regeneratorRuntime.wrap(function
|
|
434
|
+
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
373
435
|
while (1) {
|
|
374
|
-
switch (
|
|
436
|
+
switch (_context7.prev = _context7.next) {
|
|
375
437
|
case 0:
|
|
376
|
-
client =
|
|
377
|
-
|
|
438
|
+
client = _ref14.client, konnector = _ref14.konnector, account = _ref14.account;
|
|
439
|
+
_context7.next = 3;
|
|
378
440
|
return createTemporaryToken({
|
|
379
441
|
client: client,
|
|
380
442
|
konnector: konnector,
|
|
@@ -382,14 +444,14 @@ export var refreshContracts = /*#__PURE__*/function () {
|
|
|
382
444
|
});
|
|
383
445
|
|
|
384
446
|
case 3:
|
|
385
|
-
biConfig =
|
|
447
|
+
biConfig = _context7.sent;
|
|
386
448
|
code = biConfig.code, config = _objectWithoutProperties(biConfig, _excluded2);
|
|
387
449
|
connectionId = getWebviewBIConnectionId(account);
|
|
388
|
-
|
|
450
|
+
_context7.next = 8;
|
|
389
451
|
return getBIConnectionAccountsList(config, connectionId, code);
|
|
390
452
|
|
|
391
453
|
case 8:
|
|
392
|
-
_yield$getBIConnectio =
|
|
454
|
+
_yield$getBIConnectio = _context7.sent;
|
|
393
455
|
contracts = _yield$getBIConnectio.accounts;
|
|
394
456
|
contractsById = contracts.reduce(function (memo, contract) {
|
|
395
457
|
return _objectSpread(_objectSpread({}, memo), {}, _defineProperty({}, contract.id + '', contract.disabled));
|
|
@@ -410,19 +472,19 @@ export var refreshContracts = /*#__PURE__*/function () {
|
|
|
410
472
|
_iterator.f();
|
|
411
473
|
}
|
|
412
474
|
|
|
413
|
-
|
|
475
|
+
_context7.next = 16;
|
|
414
476
|
return client.save(account);
|
|
415
477
|
|
|
416
478
|
case 16:
|
|
417
479
|
case "end":
|
|
418
|
-
return
|
|
480
|
+
return _context7.stop();
|
|
419
481
|
}
|
|
420
482
|
}
|
|
421
|
-
},
|
|
483
|
+
}, _callee7);
|
|
422
484
|
}));
|
|
423
485
|
|
|
424
|
-
return function refreshContracts(
|
|
425
|
-
return
|
|
486
|
+
return function refreshContracts(_x7) {
|
|
487
|
+
return _ref15.apply(this, arguments);
|
|
426
488
|
};
|
|
427
489
|
}();
|
|
428
490
|
|
|
@@ -441,20 +503,20 @@ function convertBIDateToStandardDate(biDate) {
|
|
|
441
503
|
|
|
442
504
|
|
|
443
505
|
export var createTemporaryToken = /*#__PURE__*/function () {
|
|
444
|
-
var
|
|
506
|
+
var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref16) {
|
|
445
507
|
var client, konnector, account, cozyBankIds, jobResponse, event;
|
|
446
|
-
return _regeneratorRuntime.wrap(function
|
|
508
|
+
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
447
509
|
while (1) {
|
|
448
|
-
switch (
|
|
510
|
+
switch (_context8.prev = _context8.next) {
|
|
449
511
|
case 0:
|
|
450
|
-
client =
|
|
512
|
+
client = _ref16.client, konnector = _ref16.konnector, account = _ref16.account;
|
|
451
513
|
assert(konnector.slug, 'createTemporaryToken: konnector passed in options has no slug');
|
|
452
514
|
cozyBankIds = getCozyBankIds({
|
|
453
515
|
konnector: konnector,
|
|
454
516
|
account: account
|
|
455
517
|
});
|
|
456
518
|
assert(cozyBankIds.length, 'createTemporaryToken: Could not determine cozyBankId from account or konnector');
|
|
457
|
-
|
|
519
|
+
_context8.next = 6;
|
|
458
520
|
return client.stackClient.jobs.create('konnector', {
|
|
459
521
|
mode: 'getTemporaryToken',
|
|
460
522
|
konnector: konnector.slug,
|
|
@@ -462,24 +524,24 @@ export var createTemporaryToken = /*#__PURE__*/function () {
|
|
|
462
524
|
}, {}, true);
|
|
463
525
|
|
|
464
526
|
case 6:
|
|
465
|
-
jobResponse =
|
|
466
|
-
|
|
527
|
+
jobResponse = _context8.sent;
|
|
528
|
+
_context8.next = 9;
|
|
467
529
|
return waitForRealtimeEvent(client, jobResponse.data.attributes, 'result', TEMP_TOKEN_TIMOUT_S * 1000);
|
|
468
530
|
|
|
469
531
|
case 9:
|
|
470
|
-
event =
|
|
471
|
-
return
|
|
532
|
+
event = _context8.sent;
|
|
533
|
+
return _context8.abrupt("return", event.data.result);
|
|
472
534
|
|
|
473
535
|
case 11:
|
|
474
536
|
case "end":
|
|
475
|
-
return
|
|
537
|
+
return _context8.stop();
|
|
476
538
|
}
|
|
477
539
|
}
|
|
478
|
-
},
|
|
540
|
+
}, _callee8);
|
|
479
541
|
}));
|
|
480
542
|
|
|
481
|
-
return function createTemporaryToken(
|
|
482
|
-
return
|
|
543
|
+
return function createTemporaryToken(_x8) {
|
|
544
|
+
return _ref17.apply(this, arguments);
|
|
483
545
|
};
|
|
484
546
|
}();
|
|
485
547
|
export var konnectorPolicy = {
|