cozy-harvest-lib 20.1.2 → 20.1.4

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,22 @@
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
+ ## [20.1.4](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@20.1.3...cozy-harvest-lib@20.1.4) (2023-11-02)
7
+
8
+ **Note:** Version bump only for package cozy-harvest-lib
9
+
10
+
11
+
12
+
13
+
14
+ ## [20.1.3](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@20.1.2...cozy-harvest-lib@20.1.3) (2023-10-31)
15
+
16
+ **Note:** Version bump only for package cozy-harvest-lib
17
+
18
+
19
+
20
+
21
+
6
22
  ## [20.1.2](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@20.1.1...cozy-harvest-lib@20.1.2) (2023-10-27)
7
23
 
8
24
 
@@ -17,6 +17,7 @@ import get from 'lodash/get';
17
17
  import PropTypes from 'prop-types';
18
18
  import React, { Component } from 'react';
19
19
  import { models, withClient } from 'cozy-client';
20
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger';
20
21
  import flag from 'cozy-flags';
21
22
  import DialogContent from 'cozy-ui/transpiled/react/DialogContent';
22
23
  import Spinner from 'cozy-ui/transpiled/react/Spinner';
@@ -32,7 +33,6 @@ import { withMountPointProps } from './MountPointContext';
32
33
  import withLocales from './hoc/withLocales';
33
34
  import { fetchAccount as _fetchAccount } from '../connections/accounts';
34
35
  import { intentsApiProptype, innerAccountModalOverridesProptype } from '../helpers/proptypes';
35
- import * as triggersModel from '../helpers/triggers';
36
36
  /**
37
37
  * Takes an accountId and a list of accounts containing their respecting triggers
38
38
  * isplays the selected account and the accounts linked
@@ -16,6 +16,7 @@ import get from 'lodash/get';
16
16
  import PropTypes from 'prop-types';
17
17
  import React, { Component } from 'react';
18
18
  import { withClient } from 'cozy-client';
19
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger';
19
20
  import flag from 'cozy-flags';
20
21
  import { Dialog } from 'cozy-ui/transpiled/react/CozyDialogs';
21
22
  import Spinner from 'cozy-ui/transpiled/react/Spinner';
@@ -25,7 +26,6 @@ import { withTracker } from './hoc/tracking';
25
26
  import useTimeout from './hooks/useTimeout';
26
27
  import { fetchAccount as _fetchAccount } from '../connections/accounts';
27
28
  import { intentsApiProptype } from '../helpers/proptypes';
28
- import * as triggersModel from '../helpers/triggers';
29
29
  import logger from '../logger';
30
30
  var showStyle = {
31
31
  opacity: 1,
@@ -3,6 +3,7 @@ import cx from 'classnames';
3
3
  import PropTypes from 'prop-types';
4
4
  import React, { useContext } from 'react';
5
5
  import { useClient } from 'cozy-client';
6
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger';
6
7
  import flag from 'cozy-flags';
7
8
  import { DialogTitle } from 'cozy-ui/transpiled/react/Dialog';
8
9
  import DialogContent from 'cozy-ui/transpiled/react/DialogContent';
@@ -17,7 +18,6 @@ import { MountPointContext } from './MountPointContext';
17
18
  import LegacyTriggerManager from './TriggerManager';
18
19
  import { InformationsCard } from './cards/InformationsCard';
19
20
  import useMaintenanceStatus from './hooks/useMaintenanceStatus';
20
- import * as triggersModel from '../helpers/triggers';
21
21
  /**
22
22
  * We need to deal with `onLoginSuccess` and `onSucess` because we
23
23
  * can have a `onSuccess` without having a `onLoginSuccess` since only
@@ -1,8 +1,8 @@
1
1
  import React, { useContext, useCallback } from 'react';
2
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger';
2
3
  import Button from 'cozy-ui/transpiled/react/deprecated/Button';
3
4
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
4
5
  import { MountPointContext } from './MountPointContext';
5
- import { getAccountId } from '../helpers/triggers';
6
6
 
7
7
  var RedirectToAccountFormButton = function RedirectToAccountFormButton(_ref) {
8
8
  var trigger = _ref.trigger;
@@ -10,7 +10,7 @@ var RedirectToAccountFormButton = function RedirectToAccountFormButton(_ref) {
10
10
  var _useI18n = useI18n(),
11
11
  t = _useI18n.t;
12
12
 
13
- var accountId = getAccountId(trigger);
13
+ var accountId = triggersModel.getAccountId(trigger);
14
14
 
15
15
  var _useContext = useContext(MountPointContext),
16
16
  replaceHistory = _useContext.replaceHistory;
@@ -2,6 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import PropTypes from 'prop-types';
3
3
  import React, { useState, useEffect } from 'react';
4
4
  import { useClient } from 'cozy-client';
5
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger';
5
6
  import Alert from 'cozy-ui/transpiled/react/Alert';
6
7
  import Button from 'cozy-ui/transpiled/react/Buttons';
7
8
  import Icon from 'cozy-ui/transpiled/react/Icon';
@@ -16,7 +17,7 @@ import { RunningAlert } from './RunningAlert';
16
17
  import { makeLabel } from './helpers';
17
18
  import { isDisconnected } from '../../helpers/konnectors';
18
19
  import { intentsApiProptype } from '../../helpers/proptypes';
19
- import { getAccountId, getKonnectorSlug } from '../../helpers/triggers';
20
+ import { getKonnectorSlug } from '../../helpers/triggers';
20
21
  import { findKonnectorPolicy } from '../../konnector-policies';
21
22
  import { SUCCESS } from '../../models/flowEvents';
22
23
  import { useFlowState } from '../../models/withConnectionFlow';
@@ -88,7 +89,7 @@ export var LaunchTriggerAlert = function LaunchTriggerAlert(_ref2) {
88
89
  }
89
90
  }, [status]);
90
91
  var SyncButtonAction = konnectorPolicy.shouldLaunchRedirectToEdit(error) ? function () {
91
- return historyAction(konnectorRoot ? "".concat(konnectorRoot, "/accounts/").concat(getAccountId(trigger), "/edit") : '/edit', 'push');
92
+ return historyAction(konnectorRoot ? "".concat(konnectorRoot, "/accounts/").concat(triggersModel.getAccountId(trigger), "/edit") : '/edit', 'push');
92
93
  } : function () {
93
94
  return launch({
94
95
  autoSuccessTimer: false
@@ -2,6 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import PropTypes from 'prop-types';
3
3
  import React, { useRef, useState } from 'react';
4
4
  import { useClient } from 'cozy-client';
5
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger';
5
6
  import Icon from 'cozy-ui/transpiled/react/Icon';
6
7
  import IconButton from 'cozy-ui/transpiled/react/IconButton';
7
8
  import DotsIcon from 'cozy-ui/transpiled/react/Icons/Dots';
@@ -10,7 +11,6 @@ import SyncIcon from 'cozy-ui/transpiled/react/Icons/Sync';
10
11
  import ActionMenu, { ActionMenuItem } from 'cozy-ui/transpiled/react/deprecated/ActionMenu';
11
12
  import { isDisconnected } from '../../helpers/konnectors';
12
13
  import { intentsApiProptype } from '../../helpers/proptypes';
13
- import { getAccountId } from '../../helpers/triggers';
14
14
  import { findKonnectorPolicy } from '../../konnector-policies';
15
15
  import { useFlowState } from '../../models/withConnectionFlow';
16
16
  import OpenOAuthWindowButton from '../AccountModalWithoutTabs/OpenOAuthWindowButton';
@@ -49,7 +49,7 @@ var LaunchTriggerAlertMenu = function LaunchTriggerAlertMenu(_ref) {
49
49
  setShowOptions = _useState2[1];
50
50
 
51
51
  var SyncButtonAction = konnectorPolicy.shouldLaunchRedirectToEdit(error) ? function () {
52
- return historyAction(konnectorRoot ? "".concat(konnectorRoot, "/accounts/").concat(getAccountId(trigger), "/edit") : '/edit', 'push');
52
+ return historyAction(konnectorRoot ? "".concat(konnectorRoot, "/accounts/").concat(triggersModel.getAccountId(trigger), "/edit") : '/edit', 'push');
53
53
  } : function () {
54
54
  return launch({
55
55
  autoSuccessTimer: false
@@ -91,7 +91,7 @@ var LaunchTriggerAlertMenu = function LaunchTriggerAlertMenu(_ref) {
91
91
  icon: GearIcon
92
92
  }),
93
93
  onClick: function onClick() {
94
- return historyAction(konnectorRoot ? "".concat(konnectorRoot, "/accounts/").concat(getAccountId(trigger), "/config") : '/config', 'push');
94
+ return historyAction(konnectorRoot ? "".concat(konnectorRoot, "/accounts/").concat(triggersModel.getAccountId(trigger), "/config") : '/config', 'push');
95
95
  }
96
96
  }, t('card.launchTrigger.configure')), !isClisk && isKonnectorDisconnected && /*#__PURE__*/React.createElement(ActionMenuItem, {
97
97
  left: /*#__PURE__*/React.createElement(Icon, {
@@ -9,8 +9,8 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
9
9
  import keyBy from 'lodash/keyBy';
10
10
  import merge from 'lodash/merge';
11
11
  import { Q } from 'cozy-client';
12
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger';
12
13
  import assert from '../assert';
13
- import * as triggersModel from '../helpers/triggers';
14
14
  import logger from '../logger';
15
15
  export var ACCOUNTS_DOCTYPE = 'io.cozy.accounts';
16
16
  var PERMISSIONS_DOCTYPE = 'io.cozy.permissions';
@@ -1,13 +1,13 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger';
4
5
  import { CozyFolder as CozyFolderClass } from 'cozy-doctypes';
5
6
  import { fetchAccount, updateAccount } from './accounts';
6
7
  import { statDirectoryByPath, createDirectoryByPath } from './files';
7
8
  import * as accounts from '../helpers/accounts';
8
9
  import cron from '../helpers/cron';
9
10
  import * as konnectors from '../helpers/konnectors';
10
- import * as triggers from '../helpers/triggers';
11
11
  var FILES_DOCTYPE = 'io.cozy.files';
12
12
  var PERMISSIONS_DOCTYPE = 'io.cozy.permissions';
13
13
  var TRIGGERS_DOCTYPE = 'io.cozy.triggers';
@@ -123,7 +123,7 @@ export var prepareTriggerAccount = /*#__PURE__*/function () {
123
123
  while (1) {
124
124
  switch (_context4.prev = _context4.next) {
125
125
  case 0:
126
- accountId = triggers.getAccountId(trigger);
126
+ accountId = triggersModel.getAccountId(trigger);
127
127
 
128
128
  if (accountId) {
129
129
  _context4.next = 3;
@@ -275,7 +275,7 @@ export var ensureTrigger = /*#__PURE__*/function () {
275
275
 
276
276
  case 7:
277
277
  _context6.next = 9;
278
- return createTrigger(client, triggers.buildAttributes({
278
+ return createTrigger(client, triggersModel.buildTriggerAttributes({
279
279
  account: account,
280
280
  cron: cron.fromKonnector(konnector),
281
281
  folder: folder,
@@ -12,12 +12,12 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
12
12
  import clone from 'lodash/clone';
13
13
  import get from 'lodash/get';
14
14
  import merge from 'lodash/merge';
15
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger';
15
16
  import manifest from './manifest';
16
17
  import assert from '../assert';
17
18
  import { hasReachMaxAccountsByKonnector, hasReachMaxAccounts } from '../components/AccountsPaywall/helpers';
18
19
  import { fetchAccount } from '../connections/accounts';
19
20
  import { buildCountTriggersQuery, buildAppsRegistryMaintenance } from '../helpers/queries';
20
- import * as triggersModel from '../helpers/triggers';
21
21
  var DEFAULT_TWOFA_CODE_PROVIDER_TYPE = 'default';
22
22
  export var TWOFA_PROVIDERS = {
23
23
  EMAIL: 'email',
@@ -1,52 +1,7 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
-
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
-
7
1
  import DateFns from 'date-fns';
8
2
  import get from 'lodash/get';
9
3
  import { toFrequency } from './cron';
10
4
  import { KonnectorJobError } from './konnectors';
11
- var DEFAULT_CRON = '0 0 0 * * 0'; // Once a week, sunday at midnight
12
-
13
- /**
14
- * Build trigger attributes given konnector and account
15
- * @param {object} konnector
16
- * @param {object} account
17
- * @return {object} created trigger
18
- */
19
-
20
- export var buildAttributes = function buildAttributes(_ref) {
21
- var account = _ref.account,
22
- _ref$cron = _ref.cron,
23
- cron = _ref$cron === void 0 ? DEFAULT_CRON : _ref$cron,
24
- folder = _ref.folder,
25
- konnector = _ref.konnector;
26
- var message = {
27
- account: account._id,
28
- konnector: konnector.slug
29
- };
30
-
31
- if (folder) {
32
- message['folder_to_save'] = folder._id;
33
- }
34
-
35
- var result = {
36
- worker: 'konnector',
37
- message: message
38
- };
39
- var options = konnector.clientSide ? {
40
- type: '@client'
41
- } : {
42
- type: '@cron',
43
- arguments: cron
44
- };
45
- return _objectSpread(_objectSpread({}, result), options);
46
- };
47
- export var getAccountId = function getAccountId(trigger) {
48
- return get(trigger, 'message.account');
49
- };
50
5
  /**
51
6
  * Get error for a given trigger document
52
7
  * @param {Object} trigger io.cozy.trigger as returned by stack
@@ -90,9 +45,7 @@ export var getFrequency = function getFrequency(trigger) {
90
45
  return toFrequency(trigger.arguments);
91
46
  };
92
47
  var helpers = {
93
- buildAttributes: buildAttributes,
94
48
  isKonnectorRunning: isKonnectorRunning,
95
- getAccountId: getAccountId,
96
49
  getKonnectorJobError: getKonnectorJobError,
97
50
  getFrequency: getFrequency,
98
51
  getKonnectorSlug: getKonnectorSlug,
@@ -1,87 +1,7 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
-
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
-
7
1
  /* eslint-env jest */
8
2
  import { KonnectorJobError } from 'helpers/konnectors';
9
- import { buildAttributes, getKonnectorJobError, isKonnectorRunning } from 'helpers/triggers';
3
+ import { getKonnectorJobError, isKonnectorRunning } from 'helpers/triggers';
10
4
  describe('Triggers Helper', function () {
11
- describe('buildAttributes', function () {
12
- var konnector = {
13
- slug: 'konnectest'
14
- };
15
- var account = {
16
- _id: '963a51f6cdd34401b0904de32cc5578d'
17
- };
18
- it('builds attributes', function () {
19
- expect(buildAttributes({
20
- konnector: konnector,
21
- account: account
22
- })).toEqual({
23
- arguments: '0 0 0 * * 0',
24
- type: '@cron',
25
- worker: 'konnector',
26
- message: {
27
- account: '963a51f6cdd34401b0904de32cc5578d',
28
- konnector: 'konnectest'
29
- }
30
- });
31
- });
32
- it('builds attributes with cron', function () {
33
- var cron = '0 0 0 * * 2';
34
- expect(buildAttributes({
35
- konnector: konnector,
36
- account: account,
37
- cron: cron
38
- })).toEqual({
39
- arguments: '0 0 0 * * 2',
40
- type: '@cron',
41
- worker: 'konnector',
42
- message: {
43
- account: '963a51f6cdd34401b0904de32cc5578d',
44
- konnector: 'konnectest'
45
- }
46
- });
47
- });
48
- it('builds for client side connectors', function () {
49
- var clientSideConnector = _objectSpread(_objectSpread({}, konnector), {}, {
50
- clientSide: true
51
- });
52
-
53
- expect(buildAttributes({
54
- konnector: clientSideConnector,
55
- account: account
56
- })).toEqual({
57
- type: '@client',
58
- worker: 'konnector',
59
- message: {
60
- account: '963a51f6cdd34401b0904de32cc5578d',
61
- konnector: 'konnectest'
62
- }
63
- });
64
- });
65
- it('build attributes with folder', function () {
66
- var folder = {
67
- _id: '4c43f8e88e5f4a608667da6b5bae8fa4'
68
- };
69
- expect(buildAttributes({
70
- konnector: konnector,
71
- account: account,
72
- folder: folder
73
- })).toEqual({
74
- arguments: '0 0 0 * * 0',
75
- type: '@cron',
76
- worker: 'konnector',
77
- message: {
78
- account: '963a51f6cdd34401b0904de32cc5578d',
79
- folder_to_save: '4c43f8e88e5f4a608667da6b5bae8fa4',
80
- konnector: 'konnectest'
81
- }
82
- });
83
- });
84
- });
85
5
  describe('getKonnectorJobError', function () {
86
6
  it('returns known KonnectorJobError', function () {
87
7
  var trigger = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-harvest-lib",
3
- "version": "20.1.2",
3
+ "version": "20.1.4",
4
4
  "description": "Provides logic, modules and components for Cozy's harvest applications.",
5
5
  "main": "dist/index.js",
6
6
  "author": "Cozy",
@@ -40,7 +40,7 @@
40
40
  "@storybook/testing-library": "0.0.14-next.2",
41
41
  "classnames": "^2.3.1",
42
42
  "cozy-bi-auth": "0.0.25",
43
- "cozy-doctypes": "^1.88.6",
43
+ "cozy-doctypes": "^1.88.7",
44
44
  "cozy-logger": "^1.10.1",
45
45
  "date-fns": "^1.30.1",
46
46
  "final-form": "^4.18.5",
@@ -74,7 +74,7 @@
74
74
  "babel-preset-cozy-app": "^2.1.0",
75
75
  "cozy-client": "^41.9.0",
76
76
  "cozy-device-helper": "^3.0.0",
77
- "cozy-flags": "^3.0.1",
77
+ "cozy-flags": "^3.1.0",
78
78
  "cozy-intent": "^2.18.0",
79
79
  "cozy-keys-lib": "^6.0.0",
80
80
  "cozy-realtime": "^5.0.0",
@@ -112,5 +112,5 @@
112
112
  "react-router-dom": ">=4.3.1"
113
113
  },
114
114
  "sideEffects": false,
115
- "gitHead": "6da69c3efe784f0d6a3dd71c0bf28b79ed7c03a6"
115
+ "gitHead": "54e4d1fbc8764c7fee740ab2b7a13f177ebaf463"
116
116
  }
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types'
4
4
  import React, { Component } from 'react'
5
5
 
6
6
  import { models, withClient } from 'cozy-client'
7
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger'
7
8
  import flag from 'cozy-flags'
8
9
  import DialogContent from 'cozy-ui/transpiled/react/DialogContent'
9
10
  import Spinner from 'cozy-ui/transpiled/react/Spinner'
@@ -23,7 +24,6 @@ import {
23
24
  intentsApiProptype,
24
25
  innerAccountModalOverridesProptype
25
26
  } from '../helpers/proptypes'
26
- import * as triggersModel from '../helpers/triggers'
27
27
 
28
28
  /**
29
29
  * Takes an accountId and a list of accounts containing their respecting triggers
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types'
4
4
  import React, { Component } from 'react'
5
5
 
6
6
  import { withClient } from 'cozy-client'
7
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger'
7
8
  import flag from 'cozy-flags'
8
9
  import { Dialog } from 'cozy-ui/transpiled/react/CozyDialogs'
9
10
  import Spinner from 'cozy-ui/transpiled/react/Spinner'
@@ -14,7 +15,6 @@ import { withTracker } from './hoc/tracking'
14
15
  import useTimeout from './hooks/useTimeout'
15
16
  import { fetchAccount } from '../connections/accounts'
16
17
  import { intentsApiProptype } from '../helpers/proptypes'
17
- import * as triggersModel from '../helpers/triggers'
18
18
  import logger from '../logger'
19
19
 
20
20
  const showStyle = { opacity: 1, transition: 'opacity 0.3s ease' }
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
3
3
  import React, { useContext } from 'react'
4
4
 
5
5
  import { useClient } from 'cozy-client'
6
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger'
6
7
  import flag from 'cozy-flags'
7
8
  import { DialogTitle } from 'cozy-ui/transpiled/react/Dialog'
8
9
  import DialogContent from 'cozy-ui/transpiled/react/DialogContent'
@@ -18,7 +19,6 @@ import { MountPointContext } from './MountPointContext'
18
19
  import LegacyTriggerManager from './TriggerManager'
19
20
  import { InformationsCard } from './cards/InformationsCard'
20
21
  import useMaintenanceStatus from './hooks/useMaintenanceStatus'
21
- import * as triggersModel from '../helpers/triggers'
22
22
 
23
23
  /**
24
24
  * We need to deal with `onLoginSuccess` and `onSucess` because we
@@ -1,14 +1,14 @@
1
1
  import React, { useContext, useCallback } from 'react'
2
2
 
3
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger'
3
4
  import Button from 'cozy-ui/transpiled/react/deprecated/Button'
4
5
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
5
6
 
6
7
  import { MountPointContext } from './MountPointContext'
7
- import { getAccountId } from '../helpers/triggers'
8
8
 
9
9
  const RedirectToAccountFormButton = ({ trigger }) => {
10
10
  const { t } = useI18n()
11
- const accountId = getAccountId(trigger)
11
+ const accountId = triggersModel.getAccountId(trigger)
12
12
  const { replaceHistory } = useContext(MountPointContext)
13
13
  const handleClick = useCallback(() => {
14
14
  replaceHistory(`/accounts/${accountId}/edit?reconnect`)
@@ -2,6 +2,7 @@ import PropTypes from 'prop-types'
2
2
  import React, { useState, useEffect } from 'react'
3
3
 
4
4
  import { useClient } from 'cozy-client'
5
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger'
5
6
  import Alert from 'cozy-ui/transpiled/react/Alert'
6
7
  import Button from 'cozy-ui/transpiled/react/Buttons'
7
8
  import Icon from 'cozy-ui/transpiled/react/Icon'
@@ -17,7 +18,7 @@ import { RunningAlert } from './RunningAlert'
17
18
  import { makeLabel } from './helpers'
18
19
  import { isDisconnected } from '../../helpers/konnectors'
19
20
  import { intentsApiProptype } from '../../helpers/proptypes'
20
- import { getAccountId, getKonnectorSlug } from '../../helpers/triggers'
21
+ import { getKonnectorSlug } from '../../helpers/triggers'
21
22
  import { findKonnectorPolicy } from '../../konnector-policies'
22
23
  import { SUCCESS } from '../../models/flowEvents'
23
24
  import { useFlowState } from '../../models/withConnectionFlow'
@@ -79,7 +80,9 @@ export const LaunchTriggerAlert = ({
79
80
  ? () =>
80
81
  historyAction(
81
82
  konnectorRoot
82
- ? `${konnectorRoot}/accounts/${getAccountId(trigger)}/edit`
83
+ ? `${konnectorRoot}/accounts/${triggersModel.getAccountId(
84
+ trigger
85
+ )}/edit`
83
86
  : '/edit',
84
87
  'push'
85
88
  )
@@ -2,6 +2,7 @@ import PropTypes from 'prop-types'
2
2
  import React, { useRef, useState } from 'react'
3
3
 
4
4
  import { useClient } from 'cozy-client'
5
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger'
5
6
  import Icon from 'cozy-ui/transpiled/react/Icon'
6
7
  import IconButton from 'cozy-ui/transpiled/react/IconButton'
7
8
  import DotsIcon from 'cozy-ui/transpiled/react/Icons/Dots'
@@ -13,7 +14,6 @@ import ActionMenu, {
13
14
 
14
15
  import { isDisconnected } from '../../helpers/konnectors'
15
16
  import { intentsApiProptype } from '../../helpers/proptypes'
16
- import { getAccountId } from '../../helpers/triggers'
17
17
  import { findKonnectorPolicy } from '../../konnector-policies'
18
18
  import { useFlowState } from '../../models/withConnectionFlow'
19
19
  import OpenOAuthWindowButton from '../AccountModalWithoutTabs/OpenOAuthWindowButton'
@@ -46,7 +46,9 @@ const LaunchTriggerAlertMenu = ({
46
46
  ? () =>
47
47
  historyAction(
48
48
  konnectorRoot
49
- ? `${konnectorRoot}/accounts/${getAccountId(trigger)}/edit`
49
+ ? `${konnectorRoot}/accounts/${triggersModel.getAccountId(
50
+ trigger
51
+ )}/edit`
50
52
  : '/edit',
51
53
  'push'
52
54
  )
@@ -97,7 +99,7 @@ const LaunchTriggerAlertMenu = ({
97
99
  onClick={() =>
98
100
  historyAction(
99
101
  konnectorRoot
100
- ? `${konnectorRoot}/accounts/${getAccountId(
102
+ ? `${konnectorRoot}/accounts/${triggersModel.getAccountId(
101
103
  trigger
102
104
  )}/config`
103
105
  : '/config',
@@ -2,9 +2,9 @@ import keyBy from 'lodash/keyBy'
2
2
  import merge from 'lodash/merge'
3
3
 
4
4
  import { Q } from 'cozy-client'
5
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger'
5
6
 
6
7
  import assert from '../assert'
7
- import * as triggersModel from '../helpers/triggers'
8
8
  import logger from '../logger'
9
9
 
10
10
  export const ACCOUNTS_DOCTYPE = 'io.cozy.accounts'
@@ -1,3 +1,4 @@
1
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger'
1
2
  import { CozyFolder as CozyFolderClass } from 'cozy-doctypes'
2
3
 
3
4
  import { fetchAccount, updateAccount } from './accounts'
@@ -5,7 +6,6 @@ import { statDirectoryByPath, createDirectoryByPath } from './files'
5
6
  import * as accounts from '../helpers/accounts'
6
7
  import cron from '../helpers/cron'
7
8
  import * as konnectors from '../helpers/konnectors'
8
- import * as triggers from '../helpers/triggers'
9
9
 
10
10
  const FILES_DOCTYPE = 'io.cozy.files'
11
11
  const PERMISSIONS_DOCTYPE = 'io.cozy.permissions'
@@ -45,7 +45,7 @@ export const launchTrigger = async (client, trigger) => {
45
45
  }
46
46
 
47
47
  export const prepareTriggerAccount = async (client, trigger) => {
48
- const accountId = triggers.getAccountId(trigger)
48
+ const accountId = triggersModel.getAccountId(trigger)
49
49
  if (!accountId) {
50
50
  throw new Error('No account id in the trigger')
51
51
  }
@@ -115,7 +115,7 @@ export const ensureTrigger = async (
115
115
 
116
116
  return await createTrigger(
117
117
  client,
118
- triggers.buildAttributes({
118
+ triggersModel.buildTriggerAttributes({
119
119
  account,
120
120
  cron: cron.fromKonnector(konnector),
121
121
  folder,
@@ -2,6 +2,8 @@ import clone from 'lodash/clone'
2
2
  import get from 'lodash/get'
3
3
  import merge from 'lodash/merge'
4
4
 
5
+ import { triggers as triggersModel } from 'cozy-client/dist/models/trigger'
6
+
5
7
  import manifest from './manifest'
6
8
  import assert from '../assert'
7
9
  import {
@@ -13,7 +15,6 @@ import {
13
15
  buildCountTriggersQuery,
14
16
  buildAppsRegistryMaintenance
15
17
  } from '../helpers/queries'
16
- import * as triggersModel from '../helpers/triggers'
17
18
 
18
19
  const DEFAULT_TWOFA_CODE_PROVIDER_TYPE = 'default'
19
20
 
@@ -4,45 +4,6 @@ import get from 'lodash/get'
4
4
  import { toFrequency } from './cron'
5
5
  import { KonnectorJobError } from './konnectors'
6
6
 
7
- const DEFAULT_CRON = '0 0 0 * * 0' // Once a week, sunday at midnight
8
-
9
- /**
10
- * Build trigger attributes given konnector and account
11
- * @param {object} konnector
12
- * @param {object} account
13
- * @return {object} created trigger
14
- */
15
- export const buildAttributes = ({
16
- account,
17
- cron = DEFAULT_CRON,
18
- folder,
19
- konnector
20
- }) => {
21
- const message = {
22
- account: account._id,
23
- konnector: konnector.slug
24
- }
25
-
26
- if (folder) {
27
- message['folder_to_save'] = folder._id
28
- }
29
-
30
- const result = {
31
- worker: 'konnector',
32
- message
33
- }
34
-
35
- const options = konnector.clientSide
36
- ? { type: '@client' }
37
- : { type: '@cron', arguments: cron }
38
-
39
- return { ...result, ...options }
40
- }
41
-
42
- export const getAccountId = trigger => {
43
- return get(trigger, 'message.account')
44
- }
45
-
46
7
  /**
47
8
  * Get error for a given trigger document
48
9
  * @param {Object} trigger io.cozy.trigger as returned by stack
@@ -88,9 +49,7 @@ export const getFrequency = trigger => {
88
49
  }
89
50
 
90
51
  const helpers = {
91
- buildAttributes,
92
52
  isKonnectorRunning,
93
- getAccountId,
94
53
  getKonnectorJobError,
95
54
  getFrequency,
96
55
  getKonnectorSlug,
@@ -1,71 +1,9 @@
1
1
  /* eslint-env jest */
2
2
 
3
3
  import { KonnectorJobError } from 'helpers/konnectors'
4
- import {
5
- buildAttributes,
6
- getKonnectorJobError,
7
- isKonnectorRunning
8
- } from 'helpers/triggers'
4
+ import { getKonnectorJobError, isKonnectorRunning } from 'helpers/triggers'
9
5
 
10
6
  describe('Triggers Helper', () => {
11
- describe('buildAttributes', () => {
12
- const konnector = { slug: 'konnectest' }
13
- const account = { _id: '963a51f6cdd34401b0904de32cc5578d' }
14
-
15
- it('builds attributes', () => {
16
- expect(buildAttributes({ konnector, account })).toEqual({
17
- arguments: '0 0 0 * * 0',
18
- type: '@cron',
19
- worker: 'konnector',
20
- message: {
21
- account: '963a51f6cdd34401b0904de32cc5578d',
22
- konnector: 'konnectest'
23
- }
24
- })
25
- })
26
-
27
- it('builds attributes with cron', () => {
28
- const cron = '0 0 0 * * 2'
29
- expect(buildAttributes({ konnector, account, cron })).toEqual({
30
- arguments: '0 0 0 * * 2',
31
- type: '@cron',
32
- worker: 'konnector',
33
- message: {
34
- account: '963a51f6cdd34401b0904de32cc5578d',
35
- konnector: 'konnectest'
36
- }
37
- })
38
- })
39
-
40
- it('builds for client side connectors', () => {
41
- const clientSideConnector = { ...konnector, clientSide: true }
42
- expect(
43
- buildAttributes({ konnector: clientSideConnector, account })
44
- ).toEqual({
45
- type: '@client',
46
- worker: 'konnector',
47
- message: {
48
- account: '963a51f6cdd34401b0904de32cc5578d',
49
- konnector: 'konnectest'
50
- }
51
- })
52
- })
53
-
54
- it('build attributes with folder', () => {
55
- const folder = { _id: '4c43f8e88e5f4a608667da6b5bae8fa4' }
56
- expect(buildAttributes({ konnector, account, folder })).toEqual({
57
- arguments: '0 0 0 * * 0',
58
- type: '@cron',
59
- worker: 'konnector',
60
- message: {
61
- account: '963a51f6cdd34401b0904de32cc5578d',
62
- folder_to_save: '4c43f8e88e5f4a608667da6b5bae8fa4',
63
- konnector: 'konnectest'
64
- }
65
- })
66
- })
67
- })
68
-
69
7
  describe('getKonnectorJobError', () => {
70
8
  it('returns known KonnectorJobError', () => {
71
9
  const trigger = {