cozy-keys-lib 4.1.8 → 4.2.1-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-keys-lib",
3
- "version": "4.1.8",
3
+ "version": "4.2.1-beta.0",
4
4
  "description": "Interactions between cozy-keys and a bitwarden server",
5
5
  "browser": "transpiled/index.js",
6
6
  "main": "transpiled/index.node.js",
@@ -51,6 +51,7 @@
51
51
  "babel-preset-cozy-app": "^1.6.0",
52
52
  "cozy-client": "^16.10.2",
53
53
  "cozy-flags": "2.6.0",
54
+ "cozy-intent": "^2.0.2",
54
55
  "cozy-ui": "^42.3.0",
55
56
  "enzyme": "^3.10.0",
56
57
  "enzyme-adapter-react-16": "^1.14.0",
@@ -86,6 +87,7 @@
86
87
  "peerDependencies": {
87
88
  "cozy-client": "^16.10.2",
88
89
  "cozy-flags": "^2.6.0",
90
+ "cozy-intent": "^2.0.2",
89
91
  "cozy-ui": "^42.3.0",
90
92
  "react": "^16.8.3",
91
93
  "react-dom": "^16.9.0"
@@ -1,4 +1,4 @@
1
- import React, { useState, useCallback, useMemo } from 'react'
1
+ import React, { useState, useCallback, useMemo, useEffect } from 'react'
2
2
  import cx from 'classnames'
3
3
  import get from 'lodash/get'
4
4
  import PropTypes from 'prop-types'
@@ -13,6 +13,7 @@ import Icon from 'cozy-ui/transpiled/react/Icon'
13
13
  import CozyTheme from 'cozy-ui/transpiled/react/CozyTheme'
14
14
  import { IllustrationDialog } from 'cozy-ui/transpiled/react/CozyDialogs'
15
15
  import KeychainIcon from 'cozy-ui/transpiled/react/Icons/Keychain'
16
+ import { useWebviewIntent } from 'cozy-intent'
16
17
 
17
18
  import CloudIcon from './IconCozySecurity'
18
19
  import PasswordField from './PasswordField'
@@ -77,6 +78,31 @@ const UnlockForm = props => {
77
78
 
78
79
  const canAuthWithOIDC = canClientAuthWithOIDC(client)
79
80
 
81
+ const webviewIntent = useWebviewIntent()
82
+
83
+ useEffect(() => {
84
+ webviewIntent &&
85
+ webviewIntent.call(
86
+ 'setFlagshipUI',
87
+ {
88
+ bottomTheme: 'light',
89
+ topTheme: 'light'
90
+ },
91
+ 'cozy-keys-lib/UnlockForm'
92
+ )
93
+
94
+ return () =>
95
+ webviewIntent &&
96
+ webviewIntent.call(
97
+ 'setFlagshipUI',
98
+ {
99
+ bottomTheme: 'light',
100
+ topTheme: 'light'
101
+ },
102
+ 'cozy-keys-lib/UnlockForm'
103
+ )
104
+ }, [webviewIntent])
105
+
80
106
  return (
81
107
  <CozyTheme variant="inverted">
82
108
  <IllustrationDialog
@@ -39,6 +39,8 @@ class VaultProvider extends React.Component {
39
39
  cozyClient.on('login', () => {
40
40
  this.setupClient(cozyClient.getStackClient().uri)
41
41
  })
42
+ } else {
43
+ this.setupClient(uri)
42
44
  }
43
45
  }
44
46
  if (instance) {
@@ -125,6 +127,10 @@ const withVaultClient = BaseComponent => {
125
127
 
126
128
  const useVaultClient = () => {
127
129
  const ctx = useContext(VaultContext)
130
+
131
+ if (!ctx) {
132
+ throw new Error('useVaultClient must be used within a VaultProvider')
133
+ }
128
134
  return ctx.vaultClient
129
135
  }
130
136
 
@@ -1,7 +1,7 @@
1
1
  import _regeneratorRuntime from "@babel/runtime/regenerator";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
- import React, { useState, useCallback, useMemo } from 'react';
4
+ import React, { useState, useCallback, useMemo, useEffect } from 'react';
5
5
  import cx from 'classnames';
6
6
  import get from 'lodash/get';
7
7
  import PropTypes from 'prop-types';
@@ -15,6 +15,7 @@ import Icon from 'cozy-ui/transpiled/react/Icon';
15
15
  import CozyTheme from 'cozy-ui/transpiled/react/CozyTheme';
16
16
  import { IllustrationDialog } from 'cozy-ui/transpiled/react/CozyDialogs';
17
17
  import KeychainIcon from 'cozy-ui/transpiled/react/Icons/Keychain';
18
+ import { useWebviewIntent } from 'cozy-intent';
18
19
  import CloudIcon from './IconCozySecurity';
19
20
  import PasswordField from './PasswordField';
20
21
  import { useVaultClient } from './VaultContext';
@@ -104,6 +105,19 @@ var UnlockForm = function UnlockForm(props) {
104
105
  return getPassphraseResetUrl(client);
105
106
  }, [client]);
106
107
  var canAuthWithOIDC = canClientAuthWithOIDC(client);
108
+ var webviewIntent = useWebviewIntent();
109
+ useEffect(function () {
110
+ webviewIntent && webviewIntent.call('setFlagshipUI', {
111
+ bottomTheme: 'light',
112
+ topTheme: 'light'
113
+ }, 'cozy-keys-lib/UnlockForm');
114
+ return function () {
115
+ return webviewIntent && webviewIntent.call('setFlagshipUI', {
116
+ bottomTheme: 'light',
117
+ topTheme: 'light'
118
+ }, 'cozy-keys-lib/UnlockForm');
119
+ };
120
+ }, [webviewIntent]);
107
121
  return React.createElement(CozyTheme, {
108
122
  variant: "inverted"
109
123
  }, React.createElement(IllustrationDialog, {
@@ -60,6 +60,8 @@ var VaultProvider = /*#__PURE__*/function (_React$Component) {
60
60
  cozyClient.on('login', function () {
61
61
  _this2.setupClient(cozyClient.getStackClient().uri);
62
62
  });
63
+ } else {
64
+ this.setupClient(uri);
63
65
  }
64
66
  }
65
67
 
@@ -176,6 +178,11 @@ var withVaultClient = function withVaultClient(BaseComponent) {
176
178
 
177
179
  var useVaultClient = function useVaultClient() {
178
180
  var ctx = useContext(VaultContext);
181
+
182
+ if (!ctx) {
183
+ throw new Error('useVaultClient must be used within a VaultProvider');
184
+ }
185
+
179
186
  return ctx.vaultClient;
180
187
  };
181
188
 
@@ -19,27 +19,9 @@ export var checkShouldUnlock = /*#__PURE__*/function () {
19
19
  addCheckShouldUnlock = _args.length > 1 && _args[1] !== undefined ? _args[1] : function () {
20
20
  return true;
21
21
  };
22
- _context.next = 3;
23
- return addCheckShouldUnlock();
22
+ return _context.abrupt("return", true);
24
23
 
25
- case 3:
26
- _context.t0 = _context.sent;
27
-
28
- if (!_context.t0) {
29
- _context.next = 8;
30
- break;
31
- }
32
-
33
- _context.next = 7;
34
- return vaultClient.isLocked();
35
-
36
- case 7:
37
- _context.t0 = _context.sent;
38
-
39
- case 8:
40
- return _context.abrupt("return", _context.t0);
41
-
42
- case 9:
24
+ case 2:
43
25
  case "end":
44
26
  return _context.stop();
45
27
  }