cozy-harvest-lib 9.2.6 → 9.4.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 CHANGED
@@ -3,6 +3,40 @@
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.4.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.3.0...cozy-harvest-lib@9.4.0) (2022-05-18)
7
+
8
+
9
+ ### Features
10
+
11
+ * **harvest:** HandleOAuthResponse can deal with cozy-data from DOM ([7c6ac1a](https://github.com/cozy/cozy-libs/commit/7c6ac1a8de7dd2b136530d0aafdb1e3f9e28fa56))
12
+ * **harvest:** OAuthFormWrapperComp can be passed to TriggerManager ([76ee8b7](https://github.com/cozy/cozy-libs/commit/76ee8b74d9314d3c66593dfe925880e6a296b420))
13
+
14
+
15
+
16
+
17
+
18
+ # [9.3.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.2.7...cozy-harvest-lib@9.3.0) (2022-05-17)
19
+
20
+
21
+ ### Features
22
+
23
+ * Remove useVaultClient call in LegacyTriggerManager ([439e603](https://github.com/cozy/cozy-libs/commit/439e603cef915e9fede72ae293ae35ca330347eb))
24
+
25
+
26
+
27
+
28
+
29
+ ## [9.2.7](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.2.6...cozy-harvest-lib@9.2.7) (2022-05-14)
30
+
31
+
32
+ ### Bug Fixes
33
+
34
+ * bump leaflet from 1.7.1 to 1.8.0 ([e4ae32d](https://github.com/cozy/cozy-libs/commit/e4ae32d7610a5e969147354405cfdde5e913bf34))
35
+
36
+
37
+
38
+
39
+
6
40
  ## [9.2.6](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.2.5...cozy-harvest-lib@9.2.6) (2022-05-13)
7
41
 
8
42
  **Note:** Version bump only for package cozy-harvest-lib
@@ -1,6 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
3
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
5
4
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
6
5
  import _createClass from "@babel/runtime/helpers/createClass";
@@ -10,9 +9,6 @@ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstruct
10
9
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
11
10
  var _excluded = ["onLaunch", "onSuccess", "onLoginSuccess", "onError", "initialTrigger"],
12
11
  _excluded2 = ["vaultUnlockFormProps"];
13
-
14
- var _DumbTriggerManager$p;
15
-
16
12
  import _regeneratorRuntime from "@babel/runtime/regenerator";
17
13
 
18
14
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
@@ -28,7 +24,7 @@ import { Account } from 'cozy-doctypes';
28
24
  import { translate } from 'cozy-ui/transpiled/react/I18n';
29
25
  import Spinner from 'cozy-ui/transpiled/react/Spinner';
30
26
  import { ModalBackButton } from 'cozy-ui/transpiled/react/Modal';
31
- import { CipherType, withVaultUnlockContext, VaultUnlockPlaceholder, VaultUnlockProvider, useVaultClient, CozyUtils } from 'cozy-keys-lib';
27
+ import { CipherType, withVaultUnlockContext, VaultUnlockPlaceholder, VaultUnlockProvider, CozyUtils } from 'cozy-keys-lib';
32
28
  import AccountForm from './AccountForm';
33
29
  import OAuthForm from './OAuthForm';
34
30
  import { fetchAccount } from '../connections/accounts';
@@ -510,7 +506,8 @@ export var DumbTriggerManager = /*#__PURE__*/function (_Component) {
510
506
  fieldOptions = _this$props5.fieldOptions,
511
507
  flow = _this$props5.flow,
512
508
  flowState = _this$props5.flowState,
513
- client = _this$props5.client;
509
+ client = _this$props5.client,
510
+ OAuthFormWrapperComp = _this$props5.OAuthFormWrapperComp;
514
511
  var submitting = flowState.running;
515
512
  var _this$state = this.state,
516
513
  account = _this$state.account,
@@ -525,13 +522,14 @@ export var DumbTriggerManager = /*#__PURE__*/function (_Component) {
525
522
  var konnectorPolicy = findKonnectorPolicy(konnector);
526
523
 
527
524
  if (oauth || konnectorPolicy.isBIWebView) {
528
- return /*#__PURE__*/React.createElement(OAuthForm, {
525
+ var Wrapper = OAuthFormWrapperComp ? OAuthFormWrapperComp : React.Fragment;
526
+ return /*#__PURE__*/React.createElement(Wrapper, null, /*#__PURE__*/React.createElement(OAuthForm, {
529
527
  client: client,
530
528
  flow: flow,
531
529
  account: account,
532
530
  konnector: konnector,
533
531
  onSuccess: this.handleOAuthAccountId
534
- });
532
+ }));
535
533
  }
536
534
 
537
535
  if (showSpinner) {
@@ -568,7 +566,7 @@ export var DumbTriggerManager = /*#__PURE__*/function (_Component) {
568
566
 
569
567
  return DumbTriggerManager;
570
568
  }(Component);
571
- DumbTriggerManager.propTypes = (_DumbTriggerManager$p = {
569
+ DumbTriggerManager.propTypes = {
572
570
  /**
573
571
  * Account document. Used to get initial form values.
574
572
  * If no account is passed, AccountForm will use empty initial values.
@@ -609,21 +607,21 @@ DumbTriggerManager.propTypes = (_DumbTriggerManager$p = {
609
607
  vaultClient: PropTypes.object,
610
608
  client: PropTypes.object,
611
609
  onError: PropTypes.func,
612
- showUnlockForm: PropTypes.func
613
- }, _defineProperty(_DumbTriggerManager$p, "onVaultDismiss", PropTypes.func), _defineProperty(_DumbTriggerManager$p, "error", PropTypes.any), _defineProperty(_DumbTriggerManager$p, "showError", PropTypes.bool), _defineProperty(_DumbTriggerManager$p, "fieldOptions", PropTypes.object), _defineProperty(_DumbTriggerManager$p, "flow", PropTypes.object), _defineProperty(_DumbTriggerManager$p, "flowState", PropTypes.object), _DumbTriggerManager$p);
610
+ showUnlockForm: PropTypes.func,
611
+ error: PropTypes.any,
612
+
613
+ /**
614
+ * Used to have options on fields (forceEncryptedPlaceholder or focus)
615
+ */
616
+ fieldOptions: PropTypes.object,
617
+ flow: PropTypes.object,
618
+ flowState: PropTypes.object,
619
+ // Used to inject a component around OAuthForm, and so customize the UI from the app
620
+ OAuthFormWrapperComp: PropTypes.node
621
+ };
614
622
  var TriggerManager = compose(translate(), withClient, withVaultUnlockContext, withConnectionFlow())(DumbTriggerManager); // TriggerManager is exported wrapped in FlowProvider to avoid breaking changes.
615
623
 
616
624
  var LegacyTriggerManager = function LegacyTriggerManager(props) {
617
- // Since the 4.1.0 of cozy-keys-lib, we
618
- // render children even if vaultClient is
619
- // not defined yet. In that case we we were
620
- // displaying TriggerManager without vaultClient.
621
- // It was raising an error.
622
- // The current fix, is to not display the
623
- // TriggerManager when vaultClient is null.
624
- var vaultClient = useVaultClient();
625
- if (!vaultClient) return null;
626
-
627
625
  var onLaunch = props.onLaunch,
628
626
  onSuccess = props.onSuccess,
629
627
  onLoginSuccess = props.onLoginSuccess,
@@ -1,8 +1,9 @@
1
1
  import uuid from 'uuid/v4';
2
- import * as konnectors from './konnectors';
2
+ import get from 'lodash/get';
3
3
  import CozyClient from 'cozy-client';
4
4
  import CozyRealtime from 'cozy-realtime';
5
- import get from 'lodash/get';
5
+ import { readCozyDataFromDOM } from 'cozy-ui/transpiled/react/helpers/appDataset';
6
+ import * as konnectors from './konnectors';
6
7
  export var OAUTH_REALTIME_CHANNEL = 'oauth-popup';
7
8
  /**
8
9
  * Checks that the given data for the given konnector is consistent with the
@@ -51,10 +52,11 @@ export var handleOAuthResponse = function handleOAuthResponse() {
51
52
  var client = options.client;
52
53
 
53
54
  if (!client) {
54
- var root = document.querySelector('[role=application]');
55
+ var domain = readCozyDataFromDOM('domain');
56
+ var token = readCozyDataFromDOM('token');
55
57
  client = new CozyClient({
56
- uri: "".concat(window.location.protocol, "//").concat(root.dataset.cozyDomain),
57
- token: root.dataset.cozyToken
58
+ uri: "".concat(window.location.protocol, "//").concat(domain),
59
+ token: token
58
60
  });
59
61
  }
60
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-harvest-lib",
3
- "version": "9.2.6",
3
+ "version": "9.4.0",
4
4
  "description": "Provides logic, modules and components for Cozy's harvest applications.",
5
5
  "main": "dist/index.js",
6
6
  "author": "Cozy",
@@ -67,7 +67,7 @@
67
67
  "jest-environment-jsdom-sixteen": "1.0.3",
68
68
  "jest-resolve-cached": "1.0.0",
69
69
  "jsdom": "16.4.0",
70
- "leaflet": "1.7.1",
70
+ "leaflet": "1.8.0",
71
71
  "prop-types": "15.7.2",
72
72
  "react": "16.12.0",
73
73
  "react-dom": "16.13.0",
@@ -87,5 +87,5 @@
87
87
  "react-router-dom": "^5.0.1"
88
88
  },
89
89
  "sideEffects": false,
90
- "gitHead": "0c0ce75d7f0653cb0bc974823e768b8c774a6643"
90
+ "gitHead": "9ab356f1f7eea371ff0d364ec1eb740aa8d4fd47"
91
91
  }
@@ -15,7 +15,6 @@ import {
15
15
  withVaultUnlockContext,
16
16
  VaultUnlockPlaceholder,
17
17
  VaultUnlockProvider,
18
- useVaultClient,
19
18
  CozyUtils
20
19
  } from 'cozy-keys-lib'
21
20
 
@@ -313,8 +312,16 @@ export class DumbTriggerManager extends Component {
313
312
  }
314
313
 
315
314
  render() {
316
- const { konnector, showError, t, fieldOptions, flow, flowState, client } =
317
- this.props
315
+ const {
316
+ konnector,
317
+ showError,
318
+ t,
319
+ fieldOptions,
320
+ flow,
321
+ flowState,
322
+ client,
323
+ OAuthFormWrapperComp
324
+ } = this.props
318
325
 
319
326
  const submitting = flowState.running
320
327
 
@@ -329,14 +336,19 @@ export class DumbTriggerManager extends Component {
329
336
  const konnectorPolicy = findKonnectorPolicy(konnector)
330
337
 
331
338
  if (oauth || konnectorPolicy.isBIWebView) {
339
+ const Wrapper = OAuthFormWrapperComp
340
+ ? OAuthFormWrapperComp
341
+ : React.Fragment
332
342
  return (
333
- <OAuthForm
334
- client={client}
335
- flow={flow}
336
- account={account}
337
- konnector={konnector}
338
- onSuccess={this.handleOAuthAccountId}
339
- />
343
+ <Wrapper>
344
+ <OAuthForm
345
+ client={client}
346
+ flow={flow}
347
+ account={account}
348
+ konnector={konnector}
349
+ onSuccess={this.handleOAuthAccountId}
350
+ />
351
+ </Wrapper>
340
352
  )
341
353
  }
342
354
 
@@ -424,21 +436,15 @@ DumbTriggerManager.propTypes = {
424
436
  client: PropTypes.object,
425
437
  onError: PropTypes.func,
426
438
  showUnlockForm: PropTypes.func,
427
- onVaultDismiss: PropTypes.func,
428
439
  error: PropTypes.any,
429
- /**
430
- * Indicates if the AccountForm has to show errors. Sometimes errors may be
431
- * displayed elsewhere. However, a KonnectorJobError corresponding to a login
432
- * error is always displayed.
433
- * @type {Boolean}
434
- */
435
- showError: PropTypes.bool,
436
440
  /**
437
441
  * Used to have options on fields (forceEncryptedPlaceholder or focus)
438
442
  */
439
443
  fieldOptions: PropTypes.object,
440
444
  flow: PropTypes.object,
441
- flowState: PropTypes.object
445
+ flowState: PropTypes.object,
446
+ // Used to inject a component around OAuthForm, and so customize the UI from the app
447
+ OAuthFormWrapperComp: PropTypes.node
442
448
  }
443
449
 
444
450
  const TriggerManager = compose(
@@ -450,15 +456,6 @@ const TriggerManager = compose(
450
456
 
451
457
  // TriggerManager is exported wrapped in FlowProvider to avoid breaking changes.
452
458
  const LegacyTriggerManager = props => {
453
- // Since the 4.1.0 of cozy-keys-lib, we
454
- // render children even if vaultClient is
455
- // not defined yet. In that case we we were
456
- // displaying TriggerManager without vaultClient.
457
- // It was raising an error.
458
- // The current fix, is to not display the
459
- // TriggerManager when vaultClient is null.
460
- const vaultClient = useVaultClient()
461
- if (!vaultClient) return null
462
459
  const {
463
460
  onLaunch,
464
461
  onSuccess,
@@ -1,9 +1,11 @@
1
1
  import uuid from 'uuid/v4'
2
+ import get from 'lodash/get'
2
3
 
3
- import * as konnectors from './konnectors'
4
4
  import CozyClient from 'cozy-client'
5
5
  import CozyRealtime from 'cozy-realtime'
6
- import get from 'lodash/get'
6
+ import { readCozyDataFromDOM } from 'cozy-ui/transpiled/react/helpers/appDataset'
7
+
8
+ import * as konnectors from './konnectors'
7
9
 
8
10
  export const OAUTH_REALTIME_CHANNEL = 'oauth-popup'
9
11
 
@@ -55,10 +57,12 @@ export const handleOAuthResponse = (options = {}) => {
55
57
  if (!realtime) {
56
58
  let client = options.client
57
59
  if (!client) {
58
- const root = document.querySelector('[role=application]')
60
+ const domain = readCozyDataFromDOM('domain')
61
+ const token = readCozyDataFromDOM('token')
62
+
59
63
  client = new CozyClient({
60
- uri: `${window.location.protocol}//${root.dataset.cozyDomain}`,
61
- token: root.dataset.cozyToken
64
+ uri: `${window.location.protocol}//${domain}`,
65
+ token: token
62
66
  })
63
67
  }
64
68
  realtime = new CozyRealtime({ client })