cozy-client 60.35.0 → 60.36.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/dist/CozyClient.js +1 -1
- package/dist/const.js +3 -1
- package/dist/hooks/useFetchShortcut.js +61 -18
- package/dist/hooks/useFetchShortcut.spec.jsx +31 -1
- package/dist/links/StackLink.js +1 -1
- package/package.json +3 -3
- package/types/const.d.ts +1 -0
- package/types/hooks/useFetchShortcut.d.ts +8 -1
package/dist/CozyClient.js
CHANGED
|
@@ -3126,7 +3126,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
3126
3126
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
3127
3127
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
3128
3128
|
|
|
3129
|
-
CozyClient.version = "60.
|
|
3129
|
+
CozyClient.version = "60.36.0";
|
|
3130
3130
|
|
|
3131
3131
|
_microee.default.mixin(CozyClient);
|
|
3132
3132
|
|
package/dist/const.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.DOCTYPE_SHARING_RECIPIENTS = exports.DOCTYPE_FILES_ENCRYPTION = exports.DOCTYPE_PERMISSIONS = exports.DOCTYPE_FILES = exports.REGISTRATION_ABORT = void 0;
|
|
6
|
+
exports.DOCTYPE_SHARING_RECIPIENTS = exports.DOCTYPE_FILES_SHORTCUTS = exports.DOCTYPE_FILES_ENCRYPTION = exports.DOCTYPE_PERMISSIONS = exports.DOCTYPE_FILES = exports.REGISTRATION_ABORT = void 0;
|
|
7
7
|
var REGISTRATION_ABORT = 'REGISTRATION_ABORT';
|
|
8
8
|
exports.REGISTRATION_ABORT = REGISTRATION_ABORT;
|
|
9
9
|
var DOCTYPE_FILES = 'io.cozy.files';
|
|
@@ -12,5 +12,7 @@ var DOCTYPE_PERMISSIONS = 'io.cozy.permissions';
|
|
|
12
12
|
exports.DOCTYPE_PERMISSIONS = DOCTYPE_PERMISSIONS;
|
|
13
13
|
var DOCTYPE_FILES_ENCRYPTION = 'io.cozy.files.encryption';
|
|
14
14
|
exports.DOCTYPE_FILES_ENCRYPTION = DOCTYPE_FILES_ENCRYPTION;
|
|
15
|
+
var DOCTYPE_FILES_SHORTCUTS = 'io.cozy.files.shortcuts';
|
|
16
|
+
exports.DOCTYPE_FILES_SHORTCUTS = DOCTYPE_FILES_SHORTCUTS;
|
|
15
17
|
var DOCTYPE_SHARING_RECIPIENTS = 'io.cozy.sharings.recipients';
|
|
16
18
|
exports.DOCTYPE_SHARING_RECIPIENTS = DOCTYPE_SHARING_RECIPIENTS;
|
|
@@ -19,9 +19,19 @@ var _dsl = require("../queries/dsl");
|
|
|
19
19
|
|
|
20
20
|
var _CozyClient = _interopRequireDefault(require("../CozyClient"));
|
|
21
21
|
|
|
22
|
+
var _const = require("../const");
|
|
23
|
+
|
|
22
24
|
var DEFAULT_CACHE_TIMEOUT_QUERIES = 10 * 60 * 1000; // 10 minutes
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Fetch a shortcut and the icon to display for it.
|
|
28
|
+
*
|
|
29
|
+
* @param {import('../CozyClient').default} client - A CozyClient instance
|
|
30
|
+
* @param {string} id - The shortcut file id
|
|
31
|
+
* @param {string} [driveId] - Id of the shared drive the shortcut belongs to
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
var useFetchShortcut = function useFetchShortcut(client, id, driveId) {
|
|
25
35
|
var _useState = (0, _react.useState)(null),
|
|
26
36
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
27
37
|
shortcutInfos = _useState2[0],
|
|
@@ -38,9 +48,11 @@ var useFetchShortcut = function useFetchShortcut(client, id) {
|
|
|
38
48
|
setFetchStatus = _useState6[1];
|
|
39
49
|
|
|
40
50
|
(0, _react.useEffect)(function () {
|
|
51
|
+
var isCancelled = false;
|
|
52
|
+
|
|
41
53
|
var fetchData = /*#__PURE__*/function () {
|
|
42
54
|
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
43
|
-
var _shortcutInfosResult$, _shortcutInfosResult$2, _shortcutInfosResult$3, shortcutInfosResult, targetApp, targetAppIconUrl, shortcutRemoteUrl, imgUrl;
|
|
55
|
+
var _shortcutInfosResult$, _shortcutInfosResult$2, _shortcutInfosResult$3, baseDefinition, shortcutInfosResult, targetApp, targetAppIconUrl, shortcutRemoteUrl, imgUrl;
|
|
44
56
|
|
|
45
57
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
46
58
|
while (1) {
|
|
@@ -48,62 +60,90 @@ var useFetchShortcut = function useFetchShortcut(client, id) {
|
|
|
48
60
|
case 0:
|
|
49
61
|
setFetchStatus('loading');
|
|
50
62
|
_context.prev = 1;
|
|
51
|
-
|
|
63
|
+
baseDefinition = (0, _dsl.Q)(_const.DOCTYPE_FILES_SHORTCUTS).getById(id);
|
|
64
|
+
_context.next = 5;
|
|
52
65
|
return client.fetchQueryAndGetFromState({
|
|
53
|
-
definition:
|
|
66
|
+
definition: driveId ? baseDefinition.sharingById(driveId) : baseDefinition,
|
|
54
67
|
options: {
|
|
55
|
-
as: "
|
|
68
|
+
as: driveId ? "".concat(_const.DOCTYPE_FILES_SHORTCUTS, "/").concat(driveId, "/").concat(id) : "".concat(_const.DOCTYPE_FILES_SHORTCUTS, "/").concat(id),
|
|
56
69
|
fetchPolicy: _CozyClient.default.fetchPolicies.olderThan(DEFAULT_CACHE_TIMEOUT_QUERIES),
|
|
57
70
|
singleDocData: true
|
|
58
71
|
}
|
|
59
72
|
});
|
|
60
73
|
|
|
61
|
-
case
|
|
74
|
+
case 5:
|
|
62
75
|
shortcutInfosResult = _context.sent;
|
|
76
|
+
|
|
77
|
+
if (!isCancelled) {
|
|
78
|
+
_context.next = 8;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return _context.abrupt("return");
|
|
83
|
+
|
|
84
|
+
case 8:
|
|
63
85
|
targetApp = shortcutInfosResult === null || shortcutInfosResult === void 0 ? void 0 : (_shortcutInfosResult$ = shortcutInfosResult.data) === null || _shortcutInfosResult$ === void 0 ? void 0 : (_shortcutInfosResult$2 = _shortcutInfosResult$.metadata) === null || _shortcutInfosResult$2 === void 0 ? void 0 : (_shortcutInfosResult$3 = _shortcutInfosResult$2.target) === null || _shortcutInfosResult$3 === void 0 ? void 0 : _shortcutInfosResult$3.app;
|
|
64
86
|
|
|
65
87
|
if (!targetApp) {
|
|
66
|
-
_context.next =
|
|
88
|
+
_context.next = 18;
|
|
67
89
|
break;
|
|
68
90
|
}
|
|
69
91
|
|
|
70
|
-
_context.next =
|
|
92
|
+
_context.next = 12;
|
|
71
93
|
return client.getStackClient().getIconURL({
|
|
72
94
|
type: 'app',
|
|
73
95
|
slug: targetApp,
|
|
74
96
|
priority: 'stack'
|
|
75
97
|
});
|
|
76
98
|
|
|
77
|
-
case
|
|
99
|
+
case 12:
|
|
78
100
|
targetAppIconUrl = _context.sent;
|
|
101
|
+
|
|
102
|
+
if (!isCancelled) {
|
|
103
|
+
_context.next = 15;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return _context.abrupt("return");
|
|
108
|
+
|
|
109
|
+
case 15:
|
|
79
110
|
setShortcutImg(targetAppIconUrl);
|
|
80
|
-
_context.next =
|
|
111
|
+
_context.next = 21;
|
|
81
112
|
break;
|
|
82
113
|
|
|
83
|
-
case
|
|
114
|
+
case 18:
|
|
84
115
|
shortcutRemoteUrl = new URL(shortcutInfosResult.data.url);
|
|
85
116
|
imgUrl = "".concat(client.getStackClient().uri, "/bitwarden/icons/").concat(shortcutRemoteUrl.host, "/icon.png");
|
|
86
117
|
setShortcutImg(imgUrl);
|
|
87
118
|
|
|
88
|
-
case
|
|
119
|
+
case 21:
|
|
89
120
|
setShortcutInfos({
|
|
90
121
|
data: shortcutInfosResult.data
|
|
91
122
|
});
|
|
92
123
|
setFetchStatus('loaded');
|
|
93
|
-
_context.next =
|
|
124
|
+
_context.next = 30;
|
|
94
125
|
break;
|
|
95
126
|
|
|
96
|
-
case
|
|
97
|
-
_context.prev =
|
|
127
|
+
case 25:
|
|
128
|
+
_context.prev = 25;
|
|
98
129
|
_context.t0 = _context["catch"](1);
|
|
130
|
+
|
|
131
|
+
if (!isCancelled) {
|
|
132
|
+
_context.next = 29;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return _context.abrupt("return");
|
|
137
|
+
|
|
138
|
+
case 29:
|
|
99
139
|
setFetchStatus('failed');
|
|
100
140
|
|
|
101
|
-
case
|
|
141
|
+
case 30:
|
|
102
142
|
case "end":
|
|
103
143
|
return _context.stop();
|
|
104
144
|
}
|
|
105
145
|
}
|
|
106
|
-
}, _callee, null, [[1,
|
|
146
|
+
}, _callee, null, [[1, 25]]);
|
|
107
147
|
}));
|
|
108
148
|
|
|
109
149
|
return function fetchData() {
|
|
@@ -112,7 +152,10 @@ var useFetchShortcut = function useFetchShortcut(client, id) {
|
|
|
112
152
|
}();
|
|
113
153
|
|
|
114
154
|
fetchData();
|
|
115
|
-
|
|
155
|
+
return function () {
|
|
156
|
+
isCancelled = true;
|
|
157
|
+
};
|
|
158
|
+
}, [client, id, driveId]);
|
|
116
159
|
return {
|
|
117
160
|
shortcutInfos: shortcutInfos,
|
|
118
161
|
shortcutImg: shortcutImg,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { renderHook } from '@testing-library/react-hooks'
|
|
1
|
+
import { act, renderHook } from '@testing-library/react-hooks'
|
|
2
2
|
|
|
3
3
|
import useFetchShortcut from './useFetchShortcut'
|
|
4
4
|
import { createMockClient } from '../../dist/mock'
|
|
@@ -103,6 +103,36 @@ describe('useFetchShortcut', () => {
|
|
|
103
103
|
)
|
|
104
104
|
})
|
|
105
105
|
|
|
106
|
+
it('should ignore a drive answer resolving after a newer one', async () => {
|
|
107
|
+
const makeDeferred = () => {
|
|
108
|
+
let resolve
|
|
109
|
+
const promise = new Promise(r => {
|
|
110
|
+
resolve = r
|
|
111
|
+
})
|
|
112
|
+
return { promise, resolve }
|
|
113
|
+
}
|
|
114
|
+
const deferred = { driveA: makeDeferred(), driveB: makeDeferred() }
|
|
115
|
+
const spy = jest
|
|
116
|
+
.spyOn(mockClient, 'fetchQueryAndGetFromState')
|
|
117
|
+
.mockImplementation(
|
|
118
|
+
({ definition }) => deferred[definition.sharingId].promise
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
const { result, rerender } = renderHook(
|
|
122
|
+
({ driveId }) => useFetchShortcut(mockClient, '123', driveId),
|
|
123
|
+
{ initialProps: { driveId: 'driveA' } }
|
|
124
|
+
)
|
|
125
|
+
rerender({ driveId: 'driveB' })
|
|
126
|
+
|
|
127
|
+
await act(async () => {
|
|
128
|
+
deferred.driveB.resolve({ data: { _id: '123', url: 'https://b.test' } })
|
|
129
|
+
deferred.driveA.resolve({ data: { _id: '123', url: 'https://a.test' } })
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
expect(result.current.shortcutInfos.data.url).toEqual('https://b.test')
|
|
133
|
+
spy.mockRestore()
|
|
134
|
+
})
|
|
135
|
+
|
|
106
136
|
it('should return shortcutImg for the targeted application icon when available', async () => {
|
|
107
137
|
const { result, waitForNextUpdate } = renderHook(() =>
|
|
108
138
|
useFetchShortcut(mockClient, 'linkToCozyApp')
|
package/dist/links/StackLink.js
CHANGED
|
@@ -334,7 +334,7 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
334
334
|
throw new Error('No doctype found in a query definition');
|
|
335
335
|
|
|
336
336
|
case 5:
|
|
337
|
-
if (doctype === _const.DOCTYPE_FILES && sharingId) {
|
|
337
|
+
if ((doctype === _const.DOCTYPE_FILES || doctype === _const.DOCTYPE_FILES_SHORTCUTS) && sharingId) {
|
|
338
338
|
options = _objectSpread(_objectSpread({}, options), {}, {
|
|
339
339
|
driveId: sharingId
|
|
340
340
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "60.
|
|
3
|
+
"version": "60.36.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@types/jest": "^26.0.20",
|
|
20
20
|
"@types/lodash": "^4.14.170",
|
|
21
21
|
"btoa": "^1.2.1",
|
|
22
|
-
"cozy-stack-client": "^60.
|
|
22
|
+
"cozy-stack-client": "^60.36.0",
|
|
23
23
|
"date-fns": "^2.30.0",
|
|
24
24
|
"fast-deep-equal": "^3.1.3",
|
|
25
25
|
"json-stable-stringify": "^1.0.1",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"react-native-ios11-devicecheck": "^0.0.3"
|
|
75
75
|
},
|
|
76
76
|
"sideEffects": false,
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "56e61b64bcd2ae9cd517f9ddb923c332f3db7230"
|
|
78
78
|
}
|
package/types/const.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export const REGISTRATION_ABORT: "REGISTRATION_ABORT";
|
|
|
2
2
|
export const DOCTYPE_FILES: "io.cozy.files";
|
|
3
3
|
export const DOCTYPE_PERMISSIONS: "io.cozy.permissions";
|
|
4
4
|
export const DOCTYPE_FILES_ENCRYPTION: "io.cozy.files.encryption";
|
|
5
|
+
export const DOCTYPE_FILES_SHORTCUTS: "io.cozy.files.shortcuts";
|
|
5
6
|
export const DOCTYPE_SHARING_RECIPIENTS: "io.cozy.sharings.recipients";
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
export default useFetchShortcut;
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Fetch a shortcut and the icon to display for it.
|
|
4
|
+
*
|
|
5
|
+
* @param {import('../CozyClient').default} client - A CozyClient instance
|
|
6
|
+
* @param {string} id - The shortcut file id
|
|
7
|
+
* @param {string} [driveId] - Id of the shared drive the shortcut belongs to
|
|
8
|
+
*/
|
|
9
|
+
declare function useFetchShortcut(client: import('../CozyClient').default, id: string, driveId?: string): {
|
|
3
10
|
shortcutInfos: any;
|
|
4
11
|
shortcutImg: any;
|
|
5
12
|
fetchStatus: string;
|