cozy-harvest-lib 13.2.2 → 13.3.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 +17 -0
- package/dist/components/AccountForm/index.js +3 -5
- package/dist/components/TriggerManager.spec.js +6 -3
- package/dist/components/cards/LaunchTriggerAlert.js +3 -5
- package/dist/components/cards/LaunchTriggerCard.js +2 -5
- package/dist/helpers/konnectors.js +0 -29
- package/dist/helpers/konnectors.spec.js +1 -46
- package/dist/konnector-policies.js +14 -8
- package/dist/models/ConnectionFlow.js +102 -145
- package/dist/models/ConnectionFlow.spec.js +219 -263
- package/dist/{services → policies}/biWebView.js +7 -3
- package/dist/{services → policies}/biWebView.spec.js +3 -3
- package/dist/{services → policies}/budget-insight.js +8 -3
- package/dist/{services → policies}/budget-insight.spec.js +5 -5
- package/dist/policies/clisk.js +75 -0
- package/dist/policies/clisk.spec.js +27 -0
- package/dist/types.js +4 -1
- package/package.json +2 -2
- package/src/components/AccountForm/index.jsx +3 -2
- package/src/components/TriggerManager.spec.jsx +6 -3
- package/src/components/cards/LaunchTriggerAlert.jsx +3 -2
- package/src/components/cards/LaunchTriggerCard.jsx +2 -2
- package/src/helpers/konnectors.js +0 -23
- package/src/helpers/konnectors.spec.js +0 -30
- package/src/konnector-policies.js +13 -9
- package/src/models/ConnectionFlow.js +48 -75
- package/src/models/ConnectionFlow.spec.js +154 -186
- package/src/{services → policies}/biWebView.js +9 -3
- package/src/{services → policies}/biWebView.spec.js +6 -3
- package/src/{services → policies}/budget-insight.js +6 -3
- package/src/{services → policies}/budget-insight.spec.js +5 -5
- package/src/policies/clisk.js +66 -0
- package/src/policies/clisk.spec.js +29 -0
- package/src/types.js +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,23 @@
|
|
|
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.3.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@13.2.2...cozy-harvest-lib@13.3.0) (2023-02-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Avoid ts error ([25f577d](https://github.com/cozy/cozy-libs/commit/25f577d22c9eca08d34cf15edb4c4529ba8b0766))
|
|
12
|
+
* Remove findKonnectorPolicy log ([e26b0d0](https://github.com/cozy/cozy-libs/commit/e26b0d000c9d10a27e436949eb321949716d8d90))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* Extract clisk policy and do not create triggers and accounts ([b137453](https://github.com/cozy/cozy-libs/commit/b137453509fd65f2f538c1852154a3f85b01fb71))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
6
23
|
## [13.2.2](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@13.2.1...cozy-harvest-lib@13.2.2) (2023-02-11)
|
|
7
24
|
|
|
8
25
|
**Note:** Version bump only for package cozy-harvest-lib
|
|
@@ -34,7 +34,8 @@ import AccountFields from './AccountFields';
|
|
|
34
34
|
import ReadOnlyIdentifier from './ReadOnlyIdentifier';
|
|
35
35
|
import TriggerErrorInfo from '../infos/TriggerErrorInfo';
|
|
36
36
|
import fieldHelpers, { getEncryptedFieldName, SECRET } from '../../helpers/fields';
|
|
37
|
-
import { KonnectorJobError
|
|
37
|
+
import { KonnectorJobError } from '../../helpers/konnectors';
|
|
38
|
+
import { findKonnectorPolicy } from '../../konnector-policies';
|
|
38
39
|
import manifest from '../../helpers/manifest';
|
|
39
40
|
import withKonnectorLocales from '../hoc/withKonnectorLocales';
|
|
40
41
|
import withConnectionFlow from '../../models/withConnectionFlow';
|
|
@@ -344,10 +345,7 @@ export var AccountForm = /*#__PURE__*/function (_PureComponent) {
|
|
|
344
345
|
onClick: onBack,
|
|
345
346
|
konnector: konnector,
|
|
346
347
|
identifier: get(account, "auth.".concat(manifest.getIdentifier(sanitizedFields)))
|
|
347
|
-
}), isRunnable({
|
|
348
|
-
win: window,
|
|
349
|
-
konnector: konnector
|
|
350
|
-
}) ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(AccountFields, {
|
|
348
|
+
}), findKonnectorPolicy(konnector).isRunnable() ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(AccountFields, {
|
|
351
349
|
disabled: submitting,
|
|
352
350
|
fields: sanitizedFields,
|
|
353
351
|
hasError: error && isLoginError,
|
|
@@ -65,8 +65,8 @@ jest.mock('cozy-doctypes', function () {
|
|
|
65
65
|
CozyFolder: CozyFolder
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
|
-
jest.mock('../../src/
|
|
69
|
-
var originalBudgetInsight = jest.requireActual('../../src/
|
|
68
|
+
jest.mock('../../src/policies/budget-insight', function () {
|
|
69
|
+
var originalBudgetInsight = jest.requireActual('../../src/policies/budget-insight');
|
|
70
70
|
return {
|
|
71
71
|
konnectorPolicy: _objectSpread(_objectSpread({}, originalBudgetInsight.konnectorPolicy), {}, {
|
|
72
72
|
onAccountCreation: jest.fn()
|
|
@@ -252,7 +252,10 @@ describe('TriggerManager', function () {
|
|
|
252
252
|
switch (_context5.prev = _context5.next) {
|
|
253
253
|
case 0:
|
|
254
254
|
findKonnectorPolicy.mockReturnValue({
|
|
255
|
-
saveInVault: false
|
|
255
|
+
saveInVault: false,
|
|
256
|
+
isRunnable: function isRunnable() {
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
256
259
|
});
|
|
257
260
|
_render2 = render( /*#__PURE__*/React.createElement(AppLike, null, /*#__PURE__*/React.createElement(TriggerManager, omit(props, 'vaultClient')))), findByLabelText = _render2.findByLabelText, findByTitle = _render2.findByTitle;
|
|
258
261
|
_context5.next = 4;
|
|
@@ -11,7 +11,8 @@ 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
13
|
import { getAccountId, getKonnectorSlug } from '../../helpers/triggers';
|
|
14
|
-
import {
|
|
14
|
+
import { isDisconnected } from '../../helpers/konnectors';
|
|
15
|
+
import { findKonnectorPolicy } from '../../konnector-policies';
|
|
15
16
|
import { useFlowState } from '../../models/withConnectionFlow';
|
|
16
17
|
import { SUCCESS } from '../../models/flowEvents';
|
|
17
18
|
import withAdaptiveRouter from '../hoc/withRouter';
|
|
@@ -72,10 +73,7 @@ export var LaunchTriggerAlert = function LaunchTriggerAlert(_ref2) {
|
|
|
72
73
|
var styles = useStyles({
|
|
73
74
|
block: block
|
|
74
75
|
});
|
|
75
|
-
var isKonnectorRunnable = isRunnable(
|
|
76
|
-
win: window,
|
|
77
|
-
konnector: konnector
|
|
78
|
-
});
|
|
76
|
+
var isKonnectorRunnable = findKonnectorPolicy(konnector).isRunnable();
|
|
79
77
|
var isKonnectorDisconnected = isDisconnected(konnector, trigger);
|
|
80
78
|
useEffect(function () {
|
|
81
79
|
if (status === SUCCESS) {
|
|
@@ -18,7 +18,7 @@ import Typography from 'cozy-ui/transpiled/react/Typography';
|
|
|
18
18
|
import SyncIcon from 'cozy-ui/transpiled/react/Icons/Sync';
|
|
19
19
|
import LaunchTriggerAlert from './LaunchTriggerAlert';
|
|
20
20
|
import * as triggers from '../../helpers/triggers';
|
|
21
|
-
import {
|
|
21
|
+
import { findKonnectorPolicy } from '../../konnector-policies';
|
|
22
22
|
import FlowProvider from '../FlowProvider';
|
|
23
23
|
import { useFlowState } from '../../models/withConnectionFlow';
|
|
24
24
|
var inlineStyle = {
|
|
@@ -37,10 +37,7 @@ export var DumbLaunchTriggerCard = function DumbLaunchTriggerCard(_ref) {
|
|
|
37
37
|
running = flowState.running,
|
|
38
38
|
expectingTriggerLaunch = flowState.expectingTriggerLaunch;
|
|
39
39
|
var lastSuccessDate = triggers.getLastSuccessDate(trigger);
|
|
40
|
-
var isKonnectorRunnable = isRunnable(
|
|
41
|
-
win: window,
|
|
42
|
-
konnector: konnector
|
|
43
|
-
});
|
|
40
|
+
var isKonnectorRunnable = findKonnectorPolicy(konnector).isRunnable();
|
|
44
41
|
return /*#__PURE__*/React.createElement(Card, {
|
|
45
42
|
className: className
|
|
46
43
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -385,33 +385,6 @@ export var buildFolderPermission = function buildFolderPermission(folder) {
|
|
|
385
385
|
}
|
|
386
386
|
};
|
|
387
387
|
};
|
|
388
|
-
/**
|
|
389
|
-
* Get's the launcher in the current environment if any
|
|
390
|
-
*
|
|
391
|
-
* @param {Object} win The window object in the current environment
|
|
392
|
-
* @returns {Object}
|
|
393
|
-
*/
|
|
394
|
-
|
|
395
|
-
export var getLauncher = function getLauncher(_ref2) {
|
|
396
|
-
var win = _ref2.win;
|
|
397
|
-
return get(win, 'cozy.ClientConnectorLauncher', null);
|
|
398
|
-
};
|
|
399
|
-
/**
|
|
400
|
-
* Define if it is possible to run a konnector in the current environment
|
|
401
|
-
*
|
|
402
|
-
* @param {Object} win The window object in the current environment
|
|
403
|
-
* @param {Object} konnector The io.cozy.konnectors object for the current konnector
|
|
404
|
-
* @returns {Boolean}
|
|
405
|
-
*/
|
|
406
|
-
|
|
407
|
-
export var isRunnable = function isRunnable(_ref3) {
|
|
408
|
-
var win = _ref3.win,
|
|
409
|
-
_ref3$konnector = _ref3.konnector,
|
|
410
|
-
konnector = _ref3$konnector === void 0 ? {} : _ref3$konnector;
|
|
411
|
-
return Boolean(!konnector.clientSide || getLauncher({
|
|
412
|
-
win: win
|
|
413
|
-
}));
|
|
414
|
-
};
|
|
415
388
|
/**
|
|
416
389
|
* Define if konnector is disconnected or not
|
|
417
390
|
*
|
|
@@ -428,8 +401,6 @@ export default {
|
|
|
428
401
|
buildFolderPath: buildFolderPath,
|
|
429
402
|
buildFolderPermission: buildFolderPermission,
|
|
430
403
|
getAccountType: getAccountType,
|
|
431
|
-
getLauncher: getLauncher,
|
|
432
|
-
isRunnable: isRunnable,
|
|
433
404
|
hasNewVersionAvailable: hasNewVersionAvailable,
|
|
434
405
|
needsFolder: needsFolder,
|
|
435
406
|
fetchSupportMail: fetchSupportMail,
|
|
@@ -4,7 +4,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
4
4
|
|
|
5
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
6
|
|
|
7
|
-
import { buildFolderPath, buildFolderPermission, getAccountType, hasNewVersionAvailable, KonnectorJobError, needsFolder, getErrorLocale,
|
|
7
|
+
import { buildFolderPath, buildFolderPermission, getAccountType, hasNewVersionAvailable, KonnectorJobError, needsFolder, getErrorLocale, getErrorLocaleBound } from 'helpers/konnectors';
|
|
8
8
|
var fixtures = {
|
|
9
9
|
account: {
|
|
10
10
|
_id: '5f344a5e53034124846dd0816909e27c'
|
|
@@ -201,51 +201,6 @@ describe('Konnectors Helpers', function () {
|
|
|
201
201
|
expect(error.type).toBe('UNKNOWN_ERROR');
|
|
202
202
|
});
|
|
203
203
|
});
|
|
204
|
-
describe('getLauncher', function () {
|
|
205
|
-
it('should get the current Launcher from the given window object', function () {
|
|
206
|
-
var cozy = {
|
|
207
|
-
ClientConnectorLauncher: 'test-react-native'
|
|
208
|
-
};
|
|
209
|
-
expect(getLauncher({
|
|
210
|
-
win: {
|
|
211
|
-
cozy: cozy
|
|
212
|
-
}
|
|
213
|
-
})).toEqual('test-react-native');
|
|
214
|
-
});
|
|
215
|
-
it('should should return null if no launcher is available', function () {
|
|
216
|
-
expect(getLauncher({
|
|
217
|
-
win: {}
|
|
218
|
-
})).toBe(null);
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
describe('isRunnable', function () {
|
|
222
|
-
var cozy = {
|
|
223
|
-
ClientConnectorLauncher: 'test-react-native'
|
|
224
|
-
};
|
|
225
|
-
var konnector = {
|
|
226
|
-
clientSide: true
|
|
227
|
-
};
|
|
228
|
-
it('should return true if konnector is clientSide and a launcher is available', function () {
|
|
229
|
-
expect(isRunnable({
|
|
230
|
-
win: {
|
|
231
|
-
cozy: cozy
|
|
232
|
-
},
|
|
233
|
-
konnector: konnector
|
|
234
|
-
})).toBe(true);
|
|
235
|
-
});
|
|
236
|
-
it('should should return true if not ClientSide', function () {
|
|
237
|
-
expect(isRunnable({
|
|
238
|
-
win: {},
|
|
239
|
-
konnector: {}
|
|
240
|
-
})).toBe(true);
|
|
241
|
-
});
|
|
242
|
-
it('should should return false in other case', function () {
|
|
243
|
-
expect(isRunnable({
|
|
244
|
-
win: {},
|
|
245
|
-
konnector: konnector
|
|
246
|
-
})).toBe(false);
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
204
|
});
|
|
250
205
|
describe('locales', function () {
|
|
251
206
|
var error = new KonnectorJobError('DISK_QUOTA_EXCEEDED');
|
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
import logger from './logger';
|
|
2
|
-
import { konnectorPolicy as biKonnectorPolicy } from './
|
|
3
|
-
import { konnectorPolicy as biWebViewPolicy } from './
|
|
2
|
+
import { konnectorPolicy as biKonnectorPolicy } from './policies/budget-insight';
|
|
3
|
+
import { konnectorPolicy as biWebViewPolicy } from './policies/biWebView';
|
|
4
|
+
import { konnectorPolicy as cliskPolicy } from './policies/clisk';
|
|
4
5
|
var defaultKonnectorPolicy = {
|
|
5
6
|
accountContainsAuth: true,
|
|
6
7
|
saveInVault: true,
|
|
7
8
|
onAccountCreation: null,
|
|
8
|
-
|
|
9
|
+
// eslint-disable-next-line no-unused-vars
|
|
10
|
+
match: function match(konnector) {
|
|
9
11
|
return true;
|
|
10
12
|
},
|
|
11
13
|
name: 'default',
|
|
12
14
|
fetchExtraOAuthUrlParams: null,
|
|
13
|
-
refreshContracts: null
|
|
15
|
+
refreshContracts: null,
|
|
16
|
+
needsTriggerLaunch: true,
|
|
17
|
+
needsAccountAndTriggerCreation: true,
|
|
18
|
+
onLaunch: null,
|
|
19
|
+
isRunnable: function isRunnable() {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
14
22
|
};
|
|
15
|
-
var policies = [biWebViewPolicy, biKonnectorPolicy, defaultKonnectorPolicy].filter(Boolean);
|
|
23
|
+
var policies = [cliskPolicy, biWebViewPolicy, biKonnectorPolicy, defaultKonnectorPolicy].filter(Boolean);
|
|
16
24
|
logger.info('Available konnector policies', policies);
|
|
17
25
|
/**
|
|
18
26
|
* Find the konnector policy corresponding to the given konnector
|
|
@@ -22,9 +30,7 @@ logger.info('Available konnector policies', policies);
|
|
|
22
30
|
*/
|
|
23
31
|
|
|
24
32
|
export var findKonnectorPolicy = function findKonnectorPolicy(konnector) {
|
|
25
|
-
|
|
33
|
+
return policies.find(function (policy) {
|
|
26
34
|
return policy.match(konnector);
|
|
27
35
|
});
|
|
28
|
-
logger.info("Using ".concat(policy.name, " konnector policy for ").concat(konnector.slug));
|
|
29
|
-
return policy;
|
|
30
36
|
};
|
|
@@ -26,7 +26,7 @@ import '../types';
|
|
|
26
26
|
import { fetchReusableAccount, saveAccount as _saveAccount, ACCOUNTS_DOCTYPE } from '../connections/accounts';
|
|
27
27
|
import clone from 'lodash/clone';
|
|
28
28
|
import { launchTrigger, prepareTriggerAccount, fetchTrigger, ensureTrigger } from '../connections/triggers';
|
|
29
|
-
import { KonnectorJobError
|
|
29
|
+
import { KonnectorJobError } from '../helpers/konnectors';
|
|
30
30
|
import { watchKonnectorJob } from '../models/konnector/KonnectorJobWatcher';
|
|
31
31
|
import logger from '../logger';
|
|
32
32
|
import { findKonnectorPolicy } from '../konnector-policies';
|
|
@@ -598,7 +598,7 @@ export var ConnectionFlow = /*#__PURE__*/function () {
|
|
|
598
598
|
konnectorPolicy = findKonnectorPolicy(konnector);
|
|
599
599
|
logger.log("ConnectionFlow: Handling submit, with konnector policy ".concat(konnectorPolicy.name));
|
|
600
600
|
|
|
601
|
-
if (!
|
|
601
|
+
if (!konnectorPolicy.saveInVault) {
|
|
602
602
|
_context6.next = 18;
|
|
603
603
|
break;
|
|
604
604
|
}
|
|
@@ -619,8 +619,13 @@ export var ConnectionFlow = /*#__PURE__*/function () {
|
|
|
619
619
|
logger.info('ConnectionFlow: Bypassing cipher creation because of konnector account policy');
|
|
620
620
|
|
|
621
621
|
case 19:
|
|
622
|
+
if (!konnectorPolicy.needsAccountAndTriggerCreation) {
|
|
623
|
+
_context6.next = 35;
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
|
|
622
627
|
logger.debug('ConnectionFlow: Creating/updating account...', account);
|
|
623
|
-
_context6.next =
|
|
628
|
+
_context6.next = 23;
|
|
624
629
|
return createOrUpdateAccount({
|
|
625
630
|
account: account,
|
|
626
631
|
cipher: cipher,
|
|
@@ -631,33 +636,47 @@ export var ConnectionFlow = /*#__PURE__*/function () {
|
|
|
631
636
|
userCredentials: userCredentials
|
|
632
637
|
});
|
|
633
638
|
|
|
634
|
-
case
|
|
639
|
+
case 23:
|
|
635
640
|
account = _context6.sent;
|
|
636
641
|
this.account = account;
|
|
637
642
|
logger.info("ConnectionFlow: Saved account ".concat(account._id));
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
break;
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
_context6.next = 28;
|
|
645
|
-
return this.ensureTriggerAndLaunch(client, {
|
|
643
|
+
logger.debug('ConnectionFlow: Ensuring trigger...');
|
|
644
|
+
_context6.next = 29;
|
|
645
|
+
return ensureTrigger(client, {
|
|
646
646
|
trigger: trigger,
|
|
647
647
|
account: account,
|
|
648
648
|
konnector: konnector,
|
|
649
649
|
t: t
|
|
650
650
|
});
|
|
651
651
|
|
|
652
|
-
case
|
|
652
|
+
case 29:
|
|
653
|
+
trigger = _context6.sent;
|
|
654
|
+
_context6.next = 32;
|
|
655
|
+
return this.ensureDefaultFolderPathInAccount(client, {
|
|
656
|
+
trigger: trigger,
|
|
657
|
+
account: account,
|
|
658
|
+
konnector: konnector
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
case 32:
|
|
662
|
+
logger.info("Trigger is ".concat(trigger._id));
|
|
663
|
+
this.trigger = trigger; // @ts-ignore
|
|
664
|
+
|
|
665
|
+
this.emit(UPDATE_EVENT);
|
|
666
|
+
|
|
667
|
+
case 35:
|
|
668
|
+
_context6.next = 37;
|
|
669
|
+
return this.launch();
|
|
670
|
+
|
|
671
|
+
case 37:
|
|
653
672
|
this.setState({
|
|
654
673
|
accountError: null
|
|
655
674
|
});
|
|
656
|
-
_context6.next =
|
|
675
|
+
_context6.next = 47;
|
|
657
676
|
break;
|
|
658
677
|
|
|
659
|
-
case
|
|
660
|
-
_context6.prev =
|
|
678
|
+
case 40:
|
|
679
|
+
_context6.prev = 40;
|
|
661
680
|
_context6.t0 = _context6["catch"](1);
|
|
662
681
|
logger.error(_context6.t0);
|
|
663
682
|
this.setState({
|
|
@@ -671,12 +690,12 @@ export var ConnectionFlow = /*#__PURE__*/function () {
|
|
|
671
690
|
});
|
|
672
691
|
throw _context6.t0;
|
|
673
692
|
|
|
674
|
-
case
|
|
693
|
+
case 47:
|
|
675
694
|
case "end":
|
|
676
695
|
return _context6.stop();
|
|
677
696
|
}
|
|
678
697
|
}
|
|
679
|
-
}, _callee6, this, [[1,
|
|
698
|
+
}, _callee6, this, [[1, 40]]);
|
|
680
699
|
}));
|
|
681
700
|
|
|
682
701
|
function handleFormSubmit(_x6) {
|
|
@@ -799,57 +818,6 @@ export var ConnectionFlow = /*#__PURE__*/function () {
|
|
|
799
818
|
|
|
800
819
|
return refetchTrigger;
|
|
801
820
|
}()
|
|
802
|
-
}, {
|
|
803
|
-
key: "ensureTriggerAndLaunch",
|
|
804
|
-
value: function () {
|
|
805
|
-
var _ensureTriggerAndLaunch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(client, _ref4) {
|
|
806
|
-
var trigger, account, konnector, t, ensuredTrigger;
|
|
807
|
-
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
808
|
-
while (1) {
|
|
809
|
-
switch (_context8.prev = _context8.next) {
|
|
810
|
-
case 0:
|
|
811
|
-
trigger = _ref4.trigger, account = _ref4.account, konnector = _ref4.konnector, t = _ref4.t;
|
|
812
|
-
logger.debug('ConnectionFlow: Ensuring trigger...');
|
|
813
|
-
this.t = t;
|
|
814
|
-
_context8.next = 5;
|
|
815
|
-
return ensureTrigger(client, {
|
|
816
|
-
trigger: trigger,
|
|
817
|
-
account: account,
|
|
818
|
-
konnector: konnector,
|
|
819
|
-
t: t
|
|
820
|
-
});
|
|
821
|
-
|
|
822
|
-
case 5:
|
|
823
|
-
ensuredTrigger = _context8.sent;
|
|
824
|
-
_context8.next = 8;
|
|
825
|
-
return this.ensureDefaultFolderPathInAccount(client, {
|
|
826
|
-
trigger: ensuredTrigger,
|
|
827
|
-
account: account,
|
|
828
|
-
konnector: konnector
|
|
829
|
-
});
|
|
830
|
-
|
|
831
|
-
case 8:
|
|
832
|
-
logger.info("Trigger is ".concat(ensuredTrigger._id));
|
|
833
|
-
this.trigger = ensuredTrigger; // @ts-ignore
|
|
834
|
-
|
|
835
|
-
this.emit(UPDATE_EVENT);
|
|
836
|
-
_context8.next = 13;
|
|
837
|
-
return this.launch();
|
|
838
|
-
|
|
839
|
-
case 13:
|
|
840
|
-
case "end":
|
|
841
|
-
return _context8.stop();
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
}, _callee8, this);
|
|
845
|
-
}));
|
|
846
|
-
|
|
847
|
-
function ensureTriggerAndLaunch(_x7, _x8) {
|
|
848
|
-
return _ensureTriggerAndLaunch.apply(this, arguments);
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
return ensureTriggerAndLaunch;
|
|
852
|
-
}()
|
|
853
821
|
/**
|
|
854
822
|
* Ensures there is a defaultFolderPath attribute in the account
|
|
855
823
|
* if any folder is needed by the connector.
|
|
@@ -868,68 +836,68 @@ export var ConnectionFlow = /*#__PURE__*/function () {
|
|
|
868
836
|
}, {
|
|
869
837
|
key: "ensureDefaultFolderPathInAccount",
|
|
870
838
|
value: function () {
|
|
871
|
-
var _ensureDefaultFolderPathInAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
839
|
+
var _ensureDefaultFolderPathInAccount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(client, _ref4) {
|
|
872
840
|
var _trigger$message2;
|
|
873
841
|
|
|
874
842
|
var trigger, account, konnector, folderId, folder, result, savedAccount;
|
|
875
|
-
return _regeneratorRuntime.wrap(function
|
|
843
|
+
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
876
844
|
while (1) {
|
|
877
|
-
switch (
|
|
845
|
+
switch (_context8.prev = _context8.next) {
|
|
878
846
|
case 0:
|
|
879
|
-
trigger =
|
|
847
|
+
trigger = _ref4.trigger, account = _ref4.account, konnector = _ref4.konnector;
|
|
880
848
|
// @ts-ignore the message property does not exist in TriggersDoctype
|
|
881
849
|
folderId = trigger === null || trigger === void 0 ? void 0 : (_trigger$message2 = trigger.message) === null || _trigger$message2 === void 0 ? void 0 : _trigger$message2.folder_to_save;
|
|
882
850
|
|
|
883
851
|
if (folderId) {
|
|
884
|
-
|
|
852
|
+
_context8.next = 4;
|
|
885
853
|
break;
|
|
886
854
|
}
|
|
887
855
|
|
|
888
|
-
return
|
|
856
|
+
return _context8.abrupt("return", account);
|
|
889
857
|
|
|
890
858
|
case 4:
|
|
891
|
-
|
|
892
|
-
|
|
859
|
+
_context8.prev = 4;
|
|
860
|
+
_context8.next = 7;
|
|
893
861
|
return client.query(Q('io.cozy.files').getById(folderId));
|
|
894
862
|
|
|
895
863
|
case 7:
|
|
896
|
-
result =
|
|
864
|
+
result = _context8.sent;
|
|
897
865
|
folder = result.data;
|
|
898
|
-
_context9.next = 15;
|
|
899
|
-
break;
|
|
900
866
|
|
|
901
|
-
case 11:
|
|
902
|
-
_context9.prev = 11;
|
|
903
|
-
_context9.t0 = _context9["catch"](4);
|
|
904
|
-
logger.warn("ConnectionFlow.ensureDefaultFolderPath: folder ".concat(folderId, " does not exist. Could not ensure defaultFolderPath. ").concat(_context9.t0.message));
|
|
905
|
-
return _context9.abrupt("return", account);
|
|
906
|
-
|
|
907
|
-
case 15:
|
|
908
867
|
if (!(folder.path !== account.defaultFolderPath)) {
|
|
909
|
-
|
|
868
|
+
_context8.next = 15;
|
|
910
869
|
break;
|
|
911
870
|
}
|
|
912
871
|
|
|
913
872
|
account.defaultFolderPath = folder.path;
|
|
914
|
-
|
|
873
|
+
_context8.next = 13;
|
|
915
874
|
return _saveAccount(client, konnector, account);
|
|
916
875
|
|
|
917
|
-
case
|
|
918
|
-
savedAccount =
|
|
919
|
-
return
|
|
876
|
+
case 13:
|
|
877
|
+
savedAccount = _context8.sent;
|
|
878
|
+
return _context8.abrupt("return", savedAccount);
|
|
920
879
|
|
|
921
|
-
case
|
|
922
|
-
|
|
880
|
+
case 15:
|
|
881
|
+
_context8.next = 20;
|
|
882
|
+
break;
|
|
923
883
|
|
|
924
|
-
case
|
|
884
|
+
case 17:
|
|
885
|
+
_context8.prev = 17;
|
|
886
|
+
_context8.t0 = _context8["catch"](4);
|
|
887
|
+
logger.warn("ConnectionFlow.ensureDefaultFolderPath: folder ".concat(folderId, " does not exist. Could not ensure defaultFolderPath. ").concat(_context8.t0.message));
|
|
888
|
+
|
|
889
|
+
case 20:
|
|
890
|
+
return _context8.abrupt("return", account);
|
|
891
|
+
|
|
892
|
+
case 21:
|
|
925
893
|
case "end":
|
|
926
|
-
return
|
|
894
|
+
return _context8.stop();
|
|
927
895
|
}
|
|
928
896
|
}
|
|
929
|
-
},
|
|
897
|
+
}, _callee8, null, [[4, 17]]);
|
|
930
898
|
}));
|
|
931
899
|
|
|
932
|
-
function ensureDefaultFolderPathInAccount(
|
|
900
|
+
function ensureDefaultFolderPathInAccount(_x7, _x8) {
|
|
933
901
|
return _ensureDefaultFolderPathInAccount.apply(this, arguments);
|
|
934
902
|
}
|
|
935
903
|
|
|
@@ -942,75 +910,64 @@ export var ConnectionFlow = /*#__PURE__*/function () {
|
|
|
942
910
|
}, {
|
|
943
911
|
key: "launch",
|
|
944
912
|
value: function () {
|
|
945
|
-
var _launch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
946
|
-
var
|
|
947
|
-
|
|
948
|
-
var _ref6,
|
|
949
|
-
_ref6$autoSuccessTime,
|
|
913
|
+
var _launch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
|
|
914
|
+
var _ref5,
|
|
915
|
+
_ref5$autoSuccessTime,
|
|
950
916
|
autoSuccessTimer,
|
|
917
|
+
konnectorPolicy,
|
|
951
918
|
computedAutoSuccessTimer,
|
|
952
|
-
|
|
953
|
-
_args10 = arguments;
|
|
919
|
+
_args9 = arguments;
|
|
954
920
|
|
|
955
|
-
return _regeneratorRuntime.wrap(function
|
|
921
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
956
922
|
while (1) {
|
|
957
|
-
switch (
|
|
923
|
+
switch (_context9.prev = _context9.next) {
|
|
958
924
|
case 0:
|
|
959
|
-
|
|
960
|
-
|
|
925
|
+
_ref5 = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {}, _ref5$autoSuccessTime = _ref5.autoSuccessTimer, autoSuccessTimer = _ref5$autoSuccessTime === void 0 ? true : _ref5$autoSuccessTime;
|
|
926
|
+
konnectorPolicy = findKonnectorPolicy(this.konnector);
|
|
927
|
+
|
|
928
|
+
if (konnectorPolicy.onLaunch) {
|
|
929
|
+
konnectorPolicy.onLaunch({
|
|
930
|
+
konnector: this.konnector,
|
|
931
|
+
trigger: this.trigger,
|
|
932
|
+
account: this.account
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
if (konnectorPolicy.needsTriggerLaunch) {
|
|
937
|
+
_context9.next = 5;
|
|
938
|
+
break;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
return _context9.abrupt("return");
|
|
942
|
+
|
|
943
|
+
case 5:
|
|
944
|
+
computedAutoSuccessTimer = autoSuccessTimer;
|
|
961
945
|
logger.info('ConnectionFlow: Launching job...');
|
|
962
946
|
this.setState({
|
|
963
947
|
status: PENDING
|
|
964
948
|
});
|
|
965
|
-
|
|
949
|
+
_context9.next = 10;
|
|
966
950
|
return prepareTriggerAccount(this.client, this.trigger);
|
|
967
951
|
|
|
968
|
-
case
|
|
969
|
-
this.account =
|
|
952
|
+
case 10:
|
|
953
|
+
this.account = _context9.sent;
|
|
970
954
|
this.realtime.subscribe('updated', ACCOUNTS_DOCTYPE, this.account._id, this.handleAccountUpdated);
|
|
971
955
|
logger.info("ConnectionFlow: Subscribed to ".concat(ACCOUNTS_DOCTYPE, ":").concat(this.account._id));
|
|
972
|
-
|
|
956
|
+
_context9.next = 15;
|
|
973
957
|
return launchTrigger(this.client, this.trigger);
|
|
974
958
|
|
|
975
|
-
case
|
|
976
|
-
this.job =
|
|
977
|
-
|
|
978
|
-
if ((_this$konnector2 = this.konnector) !== null && _this$konnector2 !== void 0 && _this$konnector2.clientSide) {
|
|
979
|
-
logger.info('This connector can be run by the launcher', this.konnector.slug);
|
|
980
|
-
launcher = getLauncher({
|
|
981
|
-
win: window
|
|
982
|
-
});
|
|
983
|
-
|
|
984
|
-
if (launcher) {
|
|
985
|
-
logger.info('Found a launcher', launcher);
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
if (launcher === 'react-native') {
|
|
989
|
-
// @ts-ignore ReactNativeWebview is injected by react-native launcher
|
|
990
|
-
window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
991
|
-
message: 'startLauncher',
|
|
992
|
-
value: {
|
|
993
|
-
connector: this.konnector,
|
|
994
|
-
account: this.account,
|
|
995
|
-
trigger: this.trigger,
|
|
996
|
-
job: this.job
|
|
997
|
-
}
|
|
998
|
-
}));
|
|
999
|
-
} else {
|
|
1000
|
-
logger.info('Found no client connector launcher');
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
|
|
959
|
+
case 15:
|
|
960
|
+
this.job = _context9.sent;
|
|
1004
961
|
this.watchJob({
|
|
1005
962
|
autoSuccessTimer: computedAutoSuccessTimer
|
|
1006
963
|
});
|
|
1007
964
|
|
|
1008
|
-
case
|
|
965
|
+
case 17:
|
|
1009
966
|
case "end":
|
|
1010
|
-
return
|
|
967
|
+
return _context9.stop();
|
|
1011
968
|
}
|
|
1012
969
|
}
|
|
1013
|
-
},
|
|
970
|
+
}, _callee9, this);
|
|
1014
971
|
}));
|
|
1015
972
|
|
|
1016
973
|
function launch() {
|