cozy-harvest-lib 9.3.0 → 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,18 @@
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
+
6
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)
7
19
 
8
20
 
@@ -506,7 +506,8 @@ export var DumbTriggerManager = /*#__PURE__*/function (_Component) {
506
506
  fieldOptions = _this$props5.fieldOptions,
507
507
  flow = _this$props5.flow,
508
508
  flowState = _this$props5.flowState,
509
- client = _this$props5.client;
509
+ client = _this$props5.client,
510
+ OAuthFormWrapperComp = _this$props5.OAuthFormWrapperComp;
510
511
  var submitting = flowState.running;
511
512
  var _this$state = this.state,
512
513
  account = _this$state.account,
@@ -521,13 +522,14 @@ export var DumbTriggerManager = /*#__PURE__*/function (_Component) {
521
522
  var konnectorPolicy = findKonnectorPolicy(konnector);
522
523
 
523
524
  if (oauth || konnectorPolicy.isBIWebView) {
524
- return /*#__PURE__*/React.createElement(OAuthForm, {
525
+ var Wrapper = OAuthFormWrapperComp ? OAuthFormWrapperComp : React.Fragment;
526
+ return /*#__PURE__*/React.createElement(Wrapper, null, /*#__PURE__*/React.createElement(OAuthForm, {
525
527
  client: client,
526
528
  flow: flow,
527
529
  account: account,
528
530
  konnector: konnector,
529
531
  onSuccess: this.handleOAuthAccountId
530
- });
532
+ }));
531
533
  }
532
534
 
533
535
  if (showSpinner) {
@@ -613,7 +615,9 @@ DumbTriggerManager.propTypes = {
613
615
  */
614
616
  fieldOptions: PropTypes.object,
615
617
  flow: PropTypes.object,
616
- flowState: 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
617
621
  };
618
622
  var TriggerManager = compose(translate(), withClient, withVaultUnlockContext, withConnectionFlow())(DumbTriggerManager); // TriggerManager is exported wrapped in FlowProvider to avoid breaking changes.
619
623
 
@@ -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.3.0",
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",
@@ -87,5 +87,5 @@
87
87
  "react-router-dom": "^5.0.1"
88
88
  },
89
89
  "sideEffects": false,
90
- "gitHead": "057e65e2c3e1c367a49e348b494b2b21a7e90e6f"
90
+ "gitHead": "9ab356f1f7eea371ff0d364ec1eb740aa8d4fd47"
91
91
  }
@@ -312,8 +312,16 @@ export class DumbTriggerManager extends Component {
312
312
  }
313
313
 
314
314
  render() {
315
- const { konnector, showError, t, fieldOptions, flow, flowState, client } =
316
- this.props
315
+ const {
316
+ konnector,
317
+ showError,
318
+ t,
319
+ fieldOptions,
320
+ flow,
321
+ flowState,
322
+ client,
323
+ OAuthFormWrapperComp
324
+ } = this.props
317
325
 
318
326
  const submitting = flowState.running
319
327
 
@@ -328,14 +336,19 @@ export class DumbTriggerManager extends Component {
328
336
  const konnectorPolicy = findKonnectorPolicy(konnector)
329
337
 
330
338
  if (oauth || konnectorPolicy.isBIWebView) {
339
+ const Wrapper = OAuthFormWrapperComp
340
+ ? OAuthFormWrapperComp
341
+ : React.Fragment
331
342
  return (
332
- <OAuthForm
333
- client={client}
334
- flow={flow}
335
- account={account}
336
- konnector={konnector}
337
- onSuccess={this.handleOAuthAccountId}
338
- />
343
+ <Wrapper>
344
+ <OAuthForm
345
+ client={client}
346
+ flow={flow}
347
+ account={account}
348
+ konnector={konnector}
349
+ onSuccess={this.handleOAuthAccountId}
350
+ />
351
+ </Wrapper>
339
352
  )
340
353
  }
341
354
 
@@ -429,7 +442,9 @@ DumbTriggerManager.propTypes = {
429
442
  */
430
443
  fieldOptions: PropTypes.object,
431
444
  flow: PropTypes.object,
432
- 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
433
448
  }
434
449
 
435
450
  const TriggerManager = compose(
@@ -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 })