cozy-harvest-lib 9.0.0 → 9.1.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 +16 -0
- package/dist/components/InAppBrowser.js +65 -0
- package/dist/components/InAppBrowser.spec.js +104 -0
- package/dist/components/OAuthWindow.js +7 -2
- package/package.json +4 -2
- package/src/components/InAppBrowser.jsx +33 -0
- package/src/components/InAppBrowser.spec.jsx +60 -0
- package/src/components/OAuthWindow.jsx +7 -2
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
|
+
# [9.1.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.0.0...cozy-harvest-lib@9.1.0) (2022-05-02)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Multiple fixes after review ([0351500](https://github.com/cozy/cozy-libs/commit/0351500e1845df6ef4a31211aec6061090ccf66e))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* Open InAppBrowser via cozy-intent when in flaghip app ([5ee31ea](https://github.com/cozy/cozy-libs/commit/5ee31eafcb62e23a6242386bb6b09312f778e871))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
# [9.0.0](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@8.4.3...cozy-harvest-lib@9.0.0) (2022-04-29)
|
|
7
23
|
|
|
8
24
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import { useWebviewIntent } from 'cozy-intent';
|
|
6
|
+
import logger from '../logger';
|
|
7
|
+
|
|
8
|
+
var InAppBrowser = function InAppBrowser(_ref) {
|
|
9
|
+
var url = _ref.url,
|
|
10
|
+
onClose = _ref.onClose;
|
|
11
|
+
var webviewIntent = useWebviewIntent();
|
|
12
|
+
useEffect(function () {
|
|
13
|
+
function insideEffect() {
|
|
14
|
+
return _insideEffect.apply(this, arguments);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function _insideEffect() {
|
|
18
|
+
_insideEffect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
19
|
+
var result;
|
|
20
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
21
|
+
while (1) {
|
|
22
|
+
switch (_context.prev = _context.next) {
|
|
23
|
+
case 0:
|
|
24
|
+
if (!webviewIntent) {
|
|
25
|
+
_context.next = 5;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
_context.next = 3;
|
|
30
|
+
return webviewIntent.call('showInAppBrowser', {
|
|
31
|
+
url: url
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
case 3:
|
|
35
|
+
result = _context.sent;
|
|
36
|
+
|
|
37
|
+
if ((result === null || result === void 0 ? void 0 : result.type) === 'cancel' && onClose) {
|
|
38
|
+
onClose();
|
|
39
|
+
} else if ((result === null || result === void 0 ? void 0 : result.type) !== 'dismiss') {
|
|
40
|
+
logger.error('Unexpected InAppBrowser result', result);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
case 5:
|
|
44
|
+
case "end":
|
|
45
|
+
return _context.stop();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, _callee);
|
|
49
|
+
}));
|
|
50
|
+
return _insideEffect.apply(this, arguments);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
insideEffect();
|
|
54
|
+
return function cleanup() {
|
|
55
|
+
webviewIntent.call('closeInAppBrowser');
|
|
56
|
+
};
|
|
57
|
+
}, [webviewIntent, url, onClose]);
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
InAppBrowser.propTypes = {
|
|
62
|
+
url: PropTypes.string.isRequired,
|
|
63
|
+
onClose: PropTypes.func
|
|
64
|
+
};
|
|
65
|
+
export default InAppBrowser;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { render, waitFor } from '@testing-library/react';
|
|
5
|
+
import InAppBrowser from './InAppBrowser';
|
|
6
|
+
import { WebviewIntentProvider } from 'cozy-intent';
|
|
7
|
+
describe('InAppBrowser', function () {
|
|
8
|
+
it('should call showInAppBrowser', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
9
|
+
var url, intentCall, webviewService;
|
|
10
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
11
|
+
while (1) {
|
|
12
|
+
switch (_context.prev = _context.next) {
|
|
13
|
+
case 0:
|
|
14
|
+
url = 'https://test.url';
|
|
15
|
+
intentCall = jest.fn();
|
|
16
|
+
webviewService = {
|
|
17
|
+
call: intentCall
|
|
18
|
+
};
|
|
19
|
+
intentCall.mockResolvedValue({
|
|
20
|
+
type: 'dismiss'
|
|
21
|
+
});
|
|
22
|
+
render( /*#__PURE__*/React.createElement(WebviewIntentProvider, {
|
|
23
|
+
webviewService: webviewService
|
|
24
|
+
}, /*#__PURE__*/React.createElement(InAppBrowser, {
|
|
25
|
+
url: url
|
|
26
|
+
})));
|
|
27
|
+
expect(webviewService.call).toHaveBeenNthCalledWith(1, 'showInAppBrowser', {
|
|
28
|
+
url: url
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
case 6:
|
|
32
|
+
case "end":
|
|
33
|
+
return _context.stop();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}, _callee);
|
|
37
|
+
})));
|
|
38
|
+
it('should call onClose when user closes the inAppBrowser in app', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
39
|
+
var url, intentCall, webviewService, onClose;
|
|
40
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
41
|
+
while (1) {
|
|
42
|
+
switch (_context2.prev = _context2.next) {
|
|
43
|
+
case 0:
|
|
44
|
+
url = 'https://test.url';
|
|
45
|
+
intentCall = jest.fn();
|
|
46
|
+
webviewService = {
|
|
47
|
+
call: intentCall
|
|
48
|
+
};
|
|
49
|
+
onClose = jest.fn();
|
|
50
|
+
intentCall.mockResolvedValue({
|
|
51
|
+
type: 'cancel'
|
|
52
|
+
});
|
|
53
|
+
render( /*#__PURE__*/React.createElement(WebviewIntentProvider, {
|
|
54
|
+
webviewService: webviewService
|
|
55
|
+
}, /*#__PURE__*/React.createElement(InAppBrowser, {
|
|
56
|
+
url: url,
|
|
57
|
+
onClose: onClose
|
|
58
|
+
})));
|
|
59
|
+
_context2.next = 8;
|
|
60
|
+
return waitFor(function () {
|
|
61
|
+
return expect(onClose).toHaveBeenCalledTimes(1);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
case 8:
|
|
65
|
+
expect(onClose).toHaveBeenCalledWith();
|
|
66
|
+
|
|
67
|
+
case 9:
|
|
68
|
+
case "end":
|
|
69
|
+
return _context2.stop();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}, _callee2);
|
|
73
|
+
})));
|
|
74
|
+
it('should call closeInAppBrowser when the component is unmounted', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
75
|
+
var url, intentCall, webviewService, _render, unmount;
|
|
76
|
+
|
|
77
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
78
|
+
while (1) {
|
|
79
|
+
switch (_context3.prev = _context3.next) {
|
|
80
|
+
case 0:
|
|
81
|
+
url = 'https://test.url';
|
|
82
|
+
intentCall = jest.fn();
|
|
83
|
+
webviewService = {
|
|
84
|
+
call: intentCall
|
|
85
|
+
};
|
|
86
|
+
intentCall.mockResolvedValue({
|
|
87
|
+
type: 'dismiss'
|
|
88
|
+
});
|
|
89
|
+
_render = render( /*#__PURE__*/React.createElement(WebviewIntentProvider, {
|
|
90
|
+
webviewService: webviewService
|
|
91
|
+
}, /*#__PURE__*/React.createElement(InAppBrowser, {
|
|
92
|
+
url: url
|
|
93
|
+
}))), unmount = _render.unmount;
|
|
94
|
+
unmount();
|
|
95
|
+
expect(webviewService.call).toHaveBeenNthCalledWith(2, 'closeInAppBrowser');
|
|
96
|
+
|
|
97
|
+
case 7:
|
|
98
|
+
case "end":
|
|
99
|
+
return _context3.stop();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}, _callee3);
|
|
103
|
+
})));
|
|
104
|
+
});
|
|
@@ -15,9 +15,11 @@ import PropTypes from 'prop-types';
|
|
|
15
15
|
import { withClient } from 'cozy-client';
|
|
16
16
|
import { translate } from 'cozy-ui/transpiled/react/I18n';
|
|
17
17
|
import CozyRealtime from 'cozy-realtime';
|
|
18
|
+
import { isFlagshipApp } from 'cozy-device-helper';
|
|
18
19
|
import { prepareOAuth, checkOAuthData, terminateOAuth, OAUTH_REALTIME_CHANNEL } from '../helpers/oauth'; // TODO use PopUp from cozy-ui
|
|
19
20
|
|
|
20
21
|
import Popup from './Popup';
|
|
22
|
+
import InAppBrowser from './InAppBrowser';
|
|
21
23
|
var OAUTH_POPUP_HEIGHT = 800;
|
|
22
24
|
var OAUTH_POPUP_WIDTH = 800;
|
|
23
25
|
/**
|
|
@@ -177,14 +179,17 @@ export var OAuthWindow = /*#__PURE__*/function (_PureComponent) {
|
|
|
177
179
|
var _this$state = this.state,
|
|
178
180
|
oAuthUrl = _this$state.oAuthUrl,
|
|
179
181
|
succeed = _this$state.succeed;
|
|
180
|
-
return oAuthUrl && !succeed && /*#__PURE__*/React.createElement(Popup, {
|
|
182
|
+
return oAuthUrl && !succeed && (!isFlagshipApp() ? /*#__PURE__*/React.createElement(Popup, {
|
|
181
183
|
url: oAuthUrl,
|
|
182
184
|
height: OAUTH_POPUP_HEIGHT,
|
|
183
185
|
width: OAUTH_POPUP_WIDTH,
|
|
184
186
|
onClose: this.handleClose,
|
|
185
187
|
onUrlChange: this.handleUrlChange,
|
|
186
188
|
title: t("oauth.window.title")
|
|
187
|
-
})
|
|
189
|
+
}) : /*#__PURE__*/React.createElement(InAppBrowser, {
|
|
190
|
+
url: oAuthUrl,
|
|
191
|
+
onClose: this.handleClose
|
|
192
|
+
}));
|
|
188
193
|
}
|
|
189
194
|
}]);
|
|
190
195
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-harvest-lib",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.1.0",
|
|
4
4
|
"description": "Provides logic, modules and components for Cozy's harvest applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "Cozy",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"cozy-client": "27.17.0",
|
|
56
56
|
"cozy-device-helper": "^2.0.0",
|
|
57
57
|
"cozy-flags": "^2.8.7",
|
|
58
|
+
"cozy-intent": "^1.17.1",
|
|
58
59
|
"cozy-keys-lib": "^4.1.9",
|
|
59
60
|
"cozy-realtime": "^4.0.8",
|
|
60
61
|
"cozy-ui": "60.6.0",
|
|
@@ -78,6 +79,7 @@
|
|
|
78
79
|
"cozy-client": ">=27.17.0",
|
|
79
80
|
"cozy-device-helper": ">=1.10.2",
|
|
80
81
|
"cozy-flags": ">=2.3.5",
|
|
82
|
+
"cozy-intent": ">=1.14.1",
|
|
81
83
|
"cozy-keys-lib": ">=4.1.9",
|
|
82
84
|
"cozy-realtime": ">=3.12.2",
|
|
83
85
|
"cozy-ui": ">=60.6.0",
|
|
@@ -85,5 +87,5 @@
|
|
|
85
87
|
"react-router-dom": "^5.0.1"
|
|
86
88
|
},
|
|
87
89
|
"sideEffects": false,
|
|
88
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "2e308c267a13adc3cd826639e3058fe35770d830"
|
|
89
91
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useEffect } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import { useWebviewIntent } from 'cozy-intent'
|
|
4
|
+
import logger from '../logger'
|
|
5
|
+
|
|
6
|
+
const InAppBrowser = ({ url, onClose }) => {
|
|
7
|
+
const webviewIntent = useWebviewIntent()
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
async function insideEffect() {
|
|
11
|
+
if (webviewIntent) {
|
|
12
|
+
const result = await webviewIntent.call('showInAppBrowser', { url })
|
|
13
|
+
if (result?.type === 'cancel' && onClose) {
|
|
14
|
+
onClose()
|
|
15
|
+
} else if (result?.type !== 'dismiss') {
|
|
16
|
+
logger.error('Unexpected InAppBrowser result', result)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
insideEffect()
|
|
21
|
+
return function cleanup() {
|
|
22
|
+
webviewIntent.call('closeInAppBrowser')
|
|
23
|
+
}
|
|
24
|
+
}, [webviewIntent, url, onClose])
|
|
25
|
+
return null
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
InAppBrowser.propTypes = {
|
|
29
|
+
url: PropTypes.string.isRequired,
|
|
30
|
+
onClose: PropTypes.func
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default InAppBrowser
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { render, waitFor } from '@testing-library/react'
|
|
3
|
+
import InAppBrowser from './InAppBrowser'
|
|
4
|
+
import { WebviewIntentProvider } from 'cozy-intent'
|
|
5
|
+
|
|
6
|
+
describe('InAppBrowser', () => {
|
|
7
|
+
it('should call showInAppBrowser', async () => {
|
|
8
|
+
const url = 'https://test.url'
|
|
9
|
+
const intentCall = jest.fn()
|
|
10
|
+
const webviewService = {
|
|
11
|
+
call: intentCall
|
|
12
|
+
}
|
|
13
|
+
intentCall.mockResolvedValue({type: 'dismiss'})
|
|
14
|
+
render(
|
|
15
|
+
<WebviewIntentProvider webviewService={webviewService}>
|
|
16
|
+
<InAppBrowser url={url} />
|
|
17
|
+
</WebviewIntentProvider>
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
expect(webviewService.call).toHaveBeenNthCalledWith(1, 'showInAppBrowser', {
|
|
21
|
+
url
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
it('should call onClose when user closes the inAppBrowser in app', async () => {
|
|
25
|
+
const url = 'https://test.url'
|
|
26
|
+
const intentCall = jest.fn()
|
|
27
|
+
const webviewService = {
|
|
28
|
+
call: intentCall
|
|
29
|
+
}
|
|
30
|
+
const onClose = jest.fn()
|
|
31
|
+
|
|
32
|
+
intentCall.mockResolvedValue({type: 'cancel'})
|
|
33
|
+
render(
|
|
34
|
+
<WebviewIntentProvider webviewService={webviewService}>
|
|
35
|
+
<InAppBrowser url={url} onClose={onClose} />
|
|
36
|
+
</WebviewIntentProvider>
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
await waitFor(() => expect(onClose).toHaveBeenCalledTimes(1))
|
|
40
|
+
expect(onClose).toHaveBeenCalledWith()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
})
|
|
44
|
+
it('should call closeInAppBrowser when the component is unmounted', async () => {
|
|
45
|
+
const url = 'https://test.url'
|
|
46
|
+
const intentCall = jest.fn()
|
|
47
|
+
const webviewService = {
|
|
48
|
+
call: intentCall
|
|
49
|
+
}
|
|
50
|
+
intentCall.mockResolvedValue({type: 'dismiss'})
|
|
51
|
+
const { unmount } = render(
|
|
52
|
+
<WebviewIntentProvider webviewService={webviewService}>
|
|
53
|
+
<InAppBrowser url={url} />
|
|
54
|
+
</WebviewIntentProvider>
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
unmount()
|
|
58
|
+
expect(webviewService.call).toHaveBeenNthCalledWith(2, 'closeInAppBrowser')
|
|
59
|
+
})
|
|
60
|
+
})
|
|
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types'
|
|
|
4
4
|
import { withClient } from 'cozy-client'
|
|
5
5
|
import { translate } from 'cozy-ui/transpiled/react/I18n'
|
|
6
6
|
import CozyRealtime from 'cozy-realtime'
|
|
7
|
+
import { isFlagshipApp } from 'cozy-device-helper'
|
|
7
8
|
|
|
8
9
|
import {
|
|
9
10
|
prepareOAuth,
|
|
@@ -13,6 +14,7 @@ import {
|
|
|
13
14
|
} from '../helpers/oauth'
|
|
14
15
|
// TODO use PopUp from cozy-ui
|
|
15
16
|
import Popup from './Popup'
|
|
17
|
+
import InAppBrowser from './InAppBrowser'
|
|
16
18
|
|
|
17
19
|
const OAUTH_POPUP_HEIGHT = 800
|
|
18
20
|
const OAUTH_POPUP_WIDTH = 800
|
|
@@ -141,7 +143,8 @@ export class OAuthWindow extends PureComponent {
|
|
|
141
143
|
const { oAuthUrl, succeed } = this.state
|
|
142
144
|
return (
|
|
143
145
|
oAuthUrl &&
|
|
144
|
-
!succeed &&
|
|
146
|
+
!succeed &&
|
|
147
|
+
(!isFlagshipApp() ? (
|
|
145
148
|
<Popup
|
|
146
149
|
url={oAuthUrl}
|
|
147
150
|
height={OAUTH_POPUP_HEIGHT}
|
|
@@ -150,7 +153,9 @@ export class OAuthWindow extends PureComponent {
|
|
|
150
153
|
onUrlChange={this.handleUrlChange}
|
|
151
154
|
title={t(`oauth.window.title`)}
|
|
152
155
|
/>
|
|
153
|
-
)
|
|
156
|
+
) : (
|
|
157
|
+
<InAppBrowser url={oAuthUrl} onClose={this.handleClose} />
|
|
158
|
+
))
|
|
154
159
|
)
|
|
155
160
|
}
|
|
156
161
|
}
|