cozy-client 43.4.0 → 43.4.1

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.
@@ -2703,7 +2703,7 @@ var CozyClient = /*#__PURE__*/function () {
2703
2703
  CozyClient.hooks = CozyClient.hooks || {};
2704
2704
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2705
2705
 
2706
- CozyClient.version = "43.4.0";
2706
+ CozyClient.version = "43.4.1";
2707
2707
 
2708
2708
  _microee.default.mixin(CozyClient);
2709
2709
 
@@ -15,6 +15,12 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
15
15
 
16
16
  var _react = require("react");
17
17
 
18
+ var _dsl = require("../queries/dsl");
19
+
20
+ var _CozyClient = _interopRequireDefault(require("../CozyClient"));
21
+
22
+ var DEFAULT_CACHE_TIMEOUT_QUERIES = 10 * 60 * 1000; // 10 minutes
23
+
18
24
  var useFetchShortcut = function useFetchShortcut(client, id) {
19
25
  var _useState = (0, _react.useState)(null),
20
26
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
@@ -34,7 +40,8 @@ var useFetchShortcut = function useFetchShortcut(client, id) {
34
40
  (0, _react.useEffect)(function () {
35
41
  var fetchData = /*#__PURE__*/function () {
36
42
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
37
- var shortcutInfosResult, shortcutRemoteUrl, imgUrl;
43
+ var _shortcutInfosResult$, _shortcutInfosResult$2, _shortcutInfosResult$3, _shortcutInfosResult$4, shortcutInfosResult, targetApp, targetAppIconUrl, shortcutRemoteUrl, imgUrl;
44
+
38
45
  return _regenerator.default.wrap(function _callee$(_context) {
39
46
  while (1) {
40
47
  switch (_context.prev = _context.next) {
@@ -42,29 +49,61 @@ var useFetchShortcut = function useFetchShortcut(client, id) {
42
49
  setFetchStatus('loading');
43
50
  _context.prev = 1;
44
51
  _context.next = 4;
45
- return client.getStackClient().fetchJSON('GET', "/shortcuts/".concat(id));
52
+ return client.fetchQueryAndGetFromState({
53
+ definition: (0, _dsl.Q)('io.cozy.files.shortcuts').getById(id),
54
+ options: {
55
+ as: "io.cozy.files.shortcuts/".concat(id),
56
+ fetchPolicy: _CozyClient.default.fetchPolicies.olderThan(DEFAULT_CACHE_TIMEOUT_QUERIES),
57
+ singleDocData: true
58
+ }
59
+ });
46
60
 
47
61
  case 4:
48
62
  shortcutInfosResult = _context.sent;
63
+ targetApp = shortcutInfosResult === null || shortcutInfosResult === void 0 ? void 0 : (_shortcutInfosResult$ = shortcutInfosResult.data) === null || _shortcutInfosResult$ === void 0 ? void 0 : (_shortcutInfosResult$2 = _shortcutInfosResult$.attributes) === null || _shortcutInfosResult$2 === void 0 ? void 0 : (_shortcutInfosResult$3 = _shortcutInfosResult$2.metadata) === null || _shortcutInfosResult$3 === void 0 ? void 0 : (_shortcutInfosResult$4 = _shortcutInfosResult$3.target) === null || _shortcutInfosResult$4 === void 0 ? void 0 : _shortcutInfosResult$4.app;
64
+
65
+ if (!targetApp) {
66
+ _context.next = 13;
67
+ break;
68
+ }
69
+
70
+ _context.next = 9;
71
+ return client.getStackClient().getIconURL({
72
+ type: 'app',
73
+ slug: targetApp,
74
+ priority: 'stack'
75
+ });
76
+
77
+ case 9:
78
+ targetAppIconUrl = _context.sent;
79
+ setShortcutImg(targetAppIconUrl);
80
+ _context.next = 16;
81
+ break;
82
+
83
+ case 13:
49
84
  shortcutRemoteUrl = new URL(shortcutInfosResult.data.attributes.url);
50
85
  imgUrl = "".concat(client.getStackClient().uri, "/bitwarden/icons/").concat(shortcutRemoteUrl.host, "/icon.png");
51
86
  setShortcutImg(imgUrl);
52
- setShortcutInfos(shortcutInfosResult);
87
+
88
+ case 16:
89
+ setShortcutInfos({
90
+ data: shortcutInfosResult.data
91
+ });
53
92
  setFetchStatus('loaded');
54
- _context.next = 15;
93
+ _context.next = 23;
55
94
  break;
56
95
 
57
- case 12:
58
- _context.prev = 12;
96
+ case 20:
97
+ _context.prev = 20;
59
98
  _context.t0 = _context["catch"](1);
60
99
  setFetchStatus('failed');
61
100
 
62
- case 15:
101
+ case 23:
63
102
  case "end":
64
103
  return _context.stop();
65
104
  }
66
105
  }
67
- }, _callee, null, [[1, 12]]);
106
+ }, _callee, null, [[1, 20]]);
68
107
  }));
69
108
 
70
109
  return function fetchData() {
@@ -1,19 +1,71 @@
1
1
  import { renderHook } from '@testing-library/react-hooks'
2
+
2
3
  import useFetchShortcut from './useFetchShortcut'
3
4
  import { createMockClient } from '../../dist/mock'
5
+
4
6
  describe('useFetchShortcut', () => {
5
- const mockClient = createMockClient({})
6
- const id = '1'
7
- it('should change loading status', async () => {
8
- mockClient.stackClient.fetchJSON.mockResolvedValue({
9
- data: {
10
- attributes: {
11
- url: 'http://foo.cozy.bar'
12
- }
7
+ const mockClient = createMockClient({
8
+ queries: {
9
+ 'io.cozy.files.shortcuts/123': {
10
+ doctype: 'io.cozy.files.shortcuts',
11
+ definition: {
12
+ doctype: 'io.cozy.files.shortcuts',
13
+ id: 'io.cozy.files.shortcuts/123'
14
+ },
15
+ data: [
16
+ {
17
+ type: 'io.cozy.files.shortcuts',
18
+ id: 'b7470059d40c88e4bd30031d5e0109d3',
19
+ attributes: {
20
+ _id: '',
21
+ name: 'cozy.url',
22
+ dir_id: '8034db0016d0548ded99b9627e003270',
23
+ url: 'https://cozy.io',
24
+ metadata: { extractor_version: 2 }
25
+ },
26
+ meta: { rev: '1-60e1359e63fa7fa9fa000a2726d5d4c7' }
27
+ }
28
+ ]
29
+ },
30
+ 'io.cozy.files.shortcuts/linkToCozyApp': {
31
+ doctype: 'io.cozy.files.shortcuts',
32
+ definition: {
33
+ doctype: 'io.cozy.files.shortcuts',
34
+ id: 'io.cozy.files.shortcuts/linkToCozyApp'
35
+ },
36
+ data: [
37
+ {
38
+ type: 'io.cozy.files.shortcuts',
39
+ id: 'linkToCozyApp',
40
+ attributes: {
41
+ _id: '',
42
+ name: 'cozy.url',
43
+ dir_id: '8034db0016d0548ded99b9627e003270',
44
+ url: 'https://cozy.io',
45
+ metadata: {
46
+ extractor_version: 2,
47
+ target: {
48
+ app: 'notes'
49
+ }
50
+ }
51
+ },
52
+ meta: { rev: '1-60e1359e63fa7fa9fa000a2726d5d4c7' }
53
+ }
54
+ ]
55
+ },
56
+ 'io.cozy.files.shortcuts/no-found': {
57
+ doctype: 'io.cozy.files.shortcuts',
58
+ queryError: new Error('not found')
13
59
  }
14
- })
60
+ },
61
+ clientOptions: {
62
+ uri: 'https://test.mycozy.cloud'
63
+ }
64
+ })
65
+
66
+ it('should change loading status', async () => {
15
67
  const { result, waitForNextUpdate } = renderHook(() =>
16
- useFetchShortcut(mockClient, id)
68
+ useFetchShortcut(mockClient, '123')
17
69
  )
18
70
  expect(result.current.fetchStatus).toEqual('loading')
19
71
  await waitForNextUpdate()
@@ -24,7 +76,7 @@ describe('useFetchShortcut', () => {
24
76
  mockClient.stackClient.fetchJSON.mockRejectedValue('error')
25
77
 
26
78
  const { result, waitForNextUpdate } = renderHook(() =>
27
- useFetchShortcut(mockClient, id)
79
+ useFetchShortcut(mockClient, 'no-found')
28
80
  )
29
81
  expect(result.current.fetchStatus).toEqual('loading')
30
82
  await waitForNextUpdate()
@@ -32,27 +84,15 @@ describe('useFetchShortcut', () => {
32
84
  })
33
85
 
34
86
  it('should return the data of a shortcut and change the display value', async () => {
35
- mockClient.stackClient.fetchJSON.mockResolvedValue({
36
- data: {
37
- type: 'io.cozy.files.shortcuts',
38
- id: 'b7470059d40c88e4bd30031d5e0109d3',
39
- attributes: {
40
- _id: '',
41
- name: 'cozy.url',
42
- dir_id: '8034db0016d0548ded99b9627e003270',
43
- url: 'https://cozy.io',
44
- metadata: { extractor_version: 2 }
45
- },
46
- meta: { rev: '1-60e1359e63fa7fa9fa000a2726d5d4c7' }
47
- }
48
- })
49
87
  const { result, waitForNextUpdate } = renderHook(() =>
50
- useFetchShortcut(mockClient, id)
88
+ useFetchShortcut(mockClient, '123')
51
89
  )
52
90
 
53
91
  await waitForNextUpdate()
54
92
  expect(result.current.shortcutInfos).toEqual({
55
93
  data: {
94
+ _id: 'b7470059d40c88e4bd30031d5e0109d3',
95
+ _type: 'io.cozy.files.shortcuts',
56
96
  type: 'io.cozy.files.shortcuts',
57
97
  id: 'b7470059d40c88e4bd30031d5e0109d3',
58
98
  attributes: {
@@ -69,4 +109,15 @@ describe('useFetchShortcut', () => {
69
109
  `${mockClient.getStackClient().uri}/bitwarden/icons/cozy.io/icon.png`
70
110
  )
71
111
  })
112
+
113
+ it('should return shortcutImg for the targeted application icon when available', async () => {
114
+ const { result, waitForNextUpdate } = renderHook(() =>
115
+ useFetchShortcut(mockClient, 'linkToCozyApp')
116
+ )
117
+
118
+ await waitForNextUpdate()
119
+ expect(result.current.shortcutImg).toEqual(
120
+ `${mockClient.getStackClient().uri}/registry/notes/icon`
121
+ )
122
+ })
72
123
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "43.4.0",
3
+ "version": "43.4.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -75,5 +75,5 @@
75
75
  "react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
76
76
  },
77
77
  "sideEffects": false,
78
- "gitHead": "67f6b6d54cd250f975bc2e2b987cad2784476563"
78
+ "gitHead": "aceb4eec10ed6dac61f5e6ee168be6559225ec89"
79
79
  }