cozy-client 27.22.3 → 27.25.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.
@@ -2537,7 +2537,7 @@ var CozyClient = /*#__PURE__*/function () {
2537
2537
  CozyClient.hooks = CozyClient.hooks || {};
2538
2538
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2539
2539
 
2540
- CozyClient.version = "27.22.3";
2540
+ CozyClient.version = "27.25.0";
2541
2541
 
2542
2542
  _microee.default.mixin(CozyClient);
2543
2543
 
@@ -17,15 +17,24 @@ var _reactNative = require("react-native");
17
17
 
18
18
  //@ts-ignore
19
19
  //@ts-ignore
20
-
20
+ var USER_CANCELED = 'USER_CANCELED';
21
21
  /**
22
22
  * Opens a ReactNative InAppBrowser
23
23
  * and resolves with the URL containing
24
24
  * the token
25
25
  *
26
+ * When the user close the InAppBrowser, the promise
27
+ * rejects with USER_CANCELED message
28
+ *
29
+ * When the redirection URL contains `error=access_denied`
30
+ * the promise rejects with USER_CANCELED message. This means
31
+ * that the user closed the authorization popup
32
+ *
26
33
  * @param {string} url
27
34
  * @returns {Promise}
35
+ * @throws Will throw an "USER_CANCELED" message when the user cancel the authorization process
28
36
  */
37
+
29
38
  var authenticateWithReactNativeInAppBrowser = /*#__PURE__*/function () {
30
39
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(url) {
31
40
  return _regenerator.default.wrap(function _callee$(_context) {
@@ -43,11 +52,12 @@ var authenticateWithReactNativeInAppBrowser = /*#__PURE__*/function () {
43
52
  enableBarCollapsing: false,
44
53
  // Android Properties
45
54
  showTitle: true,
46
- toolbarColor: '#6200EE',
55
+ toolbarColor: '#8e9094',
47
56
  secondaryToolbarColor: 'black',
48
57
  enableUrlBarHiding: true,
49
58
  enableDefaultShare: true,
50
59
  forceCloseOnRedirection: false,
60
+ showInRecents: true,
51
61
  // Specify full animation resource identifier(package:anim/name)
52
62
  // or only resource name(in case of animation bundled with app).
53
63
  animations: {
@@ -56,6 +66,10 @@ var authenticateWithReactNativeInAppBrowser = /*#__PURE__*/function () {
56
66
  endEnter: 'slide_in_left',
57
67
  endExit: 'slide_out_right'
58
68
  }
69
+ }).then(function (result) {
70
+ if (result.type === 'cancel') {
71
+ reject(USER_CANCELED);
72
+ }
59
73
  });
60
74
 
61
75
  var removeListener = function removeListener() {
@@ -67,6 +81,7 @@ var authenticateWithReactNativeInAppBrowser = /*#__PURE__*/function () {
67
81
  var sanitizedUrl = url;
68
82
  var accessCode = /\?access_code=(.+)$/.test(url);
69
83
  var state = /\?state=(.+)$/.test(url);
84
+ var closeSignal = /\?error=access_denied$/.test(url);
70
85
 
71
86
  if (accessCode || state) {
72
87
  if (_reactNative.Platform.OS === 'ios') {
@@ -87,6 +102,8 @@ var authenticateWithReactNativeInAppBrowser = /*#__PURE__*/function () {
87
102
  removeListener();
88
103
 
89
104
  _reactNativeInappbrowserReborn.InAppBrowser.close();
105
+ } else if (closeSignal) {
106
+ reject(USER_CANCELED);
90
107
  }
91
108
  };
92
109
 
@@ -155,6 +155,10 @@ describe('rootCozyUrl', () => {
155
155
  enableFetchMocks()
156
156
  })
157
157
 
158
+ beforeEach(() => {
159
+ fetch.resetMocks()
160
+ })
161
+
158
162
  afterAll(() => {
159
163
  disableFetchMocks()
160
164
  })
@@ -354,7 +358,7 @@ describe('rootCozyUrl', () => {
354
358
 
355
359
  it('expects an http or https protocol', async () => {
356
360
  fetch.mockOnceIf(
357
- 'ftp://camillenimbus.com',
361
+ 'ftp://camillenimbus.com/.well-known/change-password',
358
362
  {},
359
363
  {
360
364
  status: 200
@@ -368,7 +372,7 @@ describe('rootCozyUrl', () => {
368
372
 
369
373
  it('rejects if URL points to a valid cozy-stack but no valid Cozy instance', async () => {
370
374
  fetch.mockOnceIf(
371
- 'https://missing.mycozy.cloud',
375
+ 'https://missing.mycozy.cloud/.well-known/change-password',
372
376
  {},
373
377
  {
374
378
  status: 404
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ // @ts-nocheck
11
+ var useIsMounted = function useIsMounted() {
12
+ var mounted = (0, _react.useRef)();
13
+ (0, _react.useEffect)(function () {
14
+ mounted.current = true;
15
+ return function () {
16
+ mounted.current = false;
17
+ };
18
+ }, []);
19
+ return mounted;
20
+ };
21
+
22
+ var _default = useIsMounted;
23
+ exports.default = _default;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+
12
+ var _react = require("react");
13
+
14
+ var _useIsMounted = _interopRequireDefault(require("./useIsMounted"));
15
+
16
+ var useSafeState = function useSafeState(initialState) {
17
+ var mounted = (0, _useIsMounted.default)();
18
+
19
+ var _useState = (0, _react.useState)(initialState),
20
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
21
+ state = _useState2[0],
22
+ setState = _useState2[1];
23
+
24
+ var setSafeState = (0, _react.useCallback)(function (newState) {
25
+ if (mounted.current) {
26
+ setState(newState);
27
+ }
28
+ }, [] // eslint-disable-line react-hooks/exhaustive-deps
29
+ );
30
+ return [state, setSafeState];
31
+ };
32
+
33
+ var _default = useSafeState;
34
+ exports.default = _default;
@@ -41,6 +41,12 @@ Object.defineProperty(exports, "useAppsInMaintenance", {
41
41
  return _useAppsInMaintenance.default;
42
42
  }
43
43
  });
44
+ Object.defineProperty(exports, "useQueryAll", {
45
+ enumerable: true,
46
+ get: function get() {
47
+ return _useQueryAll.default;
48
+ }
49
+ });
44
50
 
45
51
  var _useAppLinkWithStoreFallback = _interopRequireDefault(require("./useAppLinkWithStoreFallback"));
46
52
 
@@ -52,4 +58,6 @@ var _useClient = _interopRequireDefault(require("./useClient"));
52
58
 
53
59
  var _useQuery = _interopRequireDefault(require("./useQuery"));
54
60
 
55
- var _useAppsInMaintenance = _interopRequireDefault(require("./useAppsInMaintenance"));
61
+ var _useAppsInMaintenance = _interopRequireDefault(require("./useAppsInMaintenance"));
62
+
63
+ var _useQueryAll = _interopRequireDefault(require("./useQueryAll"));
@@ -43,17 +43,8 @@ var generateFetchMoreQueryDefinition = function generateFetchMoreQueryDefinition
43
43
  /**
44
44
  * Fetches a queryDefinition and returns the queryState
45
45
  *
46
- * @param {QueryDefinition} queryDefinition - Definition created with Q()
47
- *
48
- * @typedef {object} UseQueryOptions
49
- * @property {object} as - Name for the query [required]
50
- * @property {boolean} enabled - If set to false, the query won't be executed
51
- * @property {object} fetchPolicy - Fetch policy
52
- * @property {object} singleDocData - If true, the "data" returned will be
53
- * a single doc instead of an array for single doc queries. Defaults to false for backward
54
- * compatibility but will be set to true in the future.
55
- * @property {Function} onError - Callback if the query is errored
56
- *
46
+ * @param {QueryDefinition} queryDefinition - Definition created with Q()
47
+ * @param {QueryOptions} options - Options created with Q()
57
48
  * @returns {UseQueryReturnValue}
58
49
  */
59
50
 
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+
14
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
+
16
+ var _react = require("react");
17
+
18
+ var _types = require("../types");
19
+
20
+ var _dsl = require("../queries/dsl");
21
+
22
+ var _useQuery = _interopRequireDefault(require("./useQuery"));
23
+
24
+ var _useSafeState3 = _interopRequireDefault(require("./helpers/useSafeState"));
25
+
26
+ /**
27
+ * Fetches a queryDefinition and run fetchMore on the query until the query is fully loaded
28
+ *
29
+ * @param {QueryDefinition} queryDefinition - Definition created with Q()
30
+ * @param {QueryOptions} options - Options created with Q()
31
+ * @returns {UseQueryReturnValue}
32
+ */
33
+ var useQueryAll = function useQueryAll(queryDefinition, options) {
34
+ var _useSafeState = (0, _useSafeState3.default)(false),
35
+ _useSafeState2 = (0, _slicedToArray2.default)(_useSafeState, 2),
36
+ fetching = _useSafeState2[0],
37
+ setFetching = _useSafeState2[1];
38
+
39
+ var res = (0, _useQuery.default)(queryDefinition, options);
40
+ (0, _react.useEffect)(function () {
41
+ var checkToFetchMore = /*#__PURE__*/function () {
42
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
43
+ return _regenerator.default.wrap(function _callee$(_context) {
44
+ while (1) {
45
+ switch (_context.prev = _context.next) {
46
+ case 0:
47
+ if (!(res.fetchStatus === 'loaded' && res.hasMore && !fetching)) {
48
+ _context.next = 5;
49
+ break;
50
+ }
51
+
52
+ setFetching(true);
53
+ _context.next = 4;
54
+ return res.fetchMore();
55
+
56
+ case 4:
57
+ setFetching(false);
58
+
59
+ case 5:
60
+ case "end":
61
+ return _context.stop();
62
+ }
63
+ }
64
+ }, _callee);
65
+ }));
66
+
67
+ return function checkToFetchMore() {
68
+ return _ref.apply(this, arguments);
69
+ };
70
+ }();
71
+
72
+ checkToFetchMore(); // eslint-disable-next-line react-hooks/exhaustive-deps
73
+ }, [res.hasMore, res.fetchStatus, fetching]);
74
+ return res;
75
+ };
76
+
77
+ var _default = useQueryAll;
78
+ exports.default = _default;
@@ -0,0 +1,81 @@
1
+ import React from 'react'
2
+ import { renderHook } from '@testing-library/react-hooks'
3
+
4
+ import { Q } from '../queries/dsl'
5
+ import { createMockClient } from '../mock'
6
+ import CozyProvider from '../Provider'
7
+
8
+ import useQueryAll from './useQueryAll'
9
+
10
+ const sleep = delay => new Promise(resolve => setTimeout(resolve, delay))
11
+
12
+ describe('useQueryAll', () => {
13
+ const setup = ({ todosResult }) => {
14
+ const client = createMockClient({
15
+ queries: {
16
+ todos: todosResult
17
+ }
18
+ })
19
+ client.query.mockImplementation(async () => {
20
+ // give a little time for hook to be re-rendered several times
21
+ await sleep(10)
22
+ return {
23
+ data: [{ _id: '2', done: false }],
24
+ next: false
25
+ }
26
+ })
27
+ const wrapper = ({ children }) => (
28
+ <CozyProvider client={client}>{children}</CozyProvider>
29
+ )
30
+ const query = Q('io.cozy.todos')
31
+ const options = {
32
+ as: 'todos'
33
+ }
34
+ const hook = renderHook(() => useQueryAll(query, options), {
35
+ wrapper
36
+ })
37
+ return { client, wrapper, hook }
38
+ }
39
+
40
+ it('should run only 1 fetch more even if the hook is rendered-multiple times', () => {
41
+ const {
42
+ client,
43
+ hook: { result, rerender }
44
+ } = setup({
45
+ todosResult: {
46
+ data: [{ _id: '1', done: true }],
47
+ next: true,
48
+ doctype: 'io.cozy.todos'
49
+ }
50
+ })
51
+ expect(result.error).toBeFalsy()
52
+ rerender()
53
+ rerender()
54
+ rerender()
55
+ rerender()
56
+
57
+ // one for the initial query and one for the fetchMore
58
+ expect(client.query).toHaveBeenCalledTimes(2)
59
+ })
60
+
61
+ it('should not run fetch if there are no more results', () => {
62
+ const {
63
+ client,
64
+ hook: { result, rerender }
65
+ } = setup({
66
+ todosResult: {
67
+ data: [{ _id: '1', done: true }],
68
+ next: false,
69
+ doctype: 'io.cozy.todos'
70
+ }
71
+ })
72
+ expect(result.error).toBeFalsy()
73
+ rerender()
74
+ rerender()
75
+ rerender()
76
+ rerender()
77
+
78
+ // one for the initial query and one for the fetchMore
79
+ expect(client.query).toHaveBeenCalledTimes(1)
80
+ })
81
+ })
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.sendMeasureToDACC = exports.checkMeasureParams = void 0;
9
+
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+
14
+ var _cozyLogger = _interopRequireDefault(require("cozy-logger"));
15
+
16
+ var _types = require("../types");
17
+
18
+ /**
19
+ * Throw an errror if a DACC parameter is incorrect.
20
+ *
21
+ * @param { DACCMeasure} measure - The DACC measure
22
+ */
23
+ var checkMeasureParams = function checkMeasureParams(measure) {
24
+ var createdBy = measure.createdBy,
25
+ measureName = measure.measureName,
26
+ startDate = measure.startDate,
27
+ value = measure.value,
28
+ group1 = measure.group1,
29
+ group2 = measure.group2,
30
+ group3 = measure.group3;
31
+
32
+ if (!createdBy || typeof createdBy !== 'string') {
33
+ throw new Error('Missing or wrong type parameter: createdBy');
34
+ }
35
+
36
+ if (!measureName || typeof measureName !== 'string') {
37
+ throw new Error('Missing or wrong type parameter: measureName');
38
+ }
39
+
40
+ if (!startDate) {
41
+ throw new Error('Missing parameter: startDate');
42
+ }
43
+
44
+ var parsedDate = new Date(Date.parse(startDate));
45
+
46
+ if (!parsedDate.toISOString().startsWith(startDate)) {
47
+ throw new Error('Date should be in YYYY-MM-DD format');
48
+ }
49
+
50
+ if (!value || typeof value !== 'number') {
51
+ throw new Error('Missing or wrong type parameter: value');
52
+ }
53
+
54
+ if (group1 && (typeof group1 !== 'object' || Object.keys(group1).length === 0) || group2 && (typeof group2 !== 'object' || Object.keys(group2).length === 0) || group3 && (typeof group3 !== 'object' || Object.keys(group3).length === 0)) {
55
+ throw new Error('Groups should be key-value objects');
56
+ }
57
+
58
+ if (group3 && (!group2 || !group1) || group2 && !group1) {
59
+ throw new Error('Group order must be respected');
60
+ }
61
+ };
62
+ /**
63
+ * Send measures to a DACC through a remote doctype
64
+ *
65
+ * @param {object} client - The CozyClient instance
66
+ * @param {string} remoteDoctype - The remote doctype to use
67
+ * @param {DACCMeasure} measure - The DACC measure
68
+ */
69
+
70
+
71
+ exports.checkMeasureParams = checkMeasureParams;
72
+
73
+ var sendMeasureToDACC = /*#__PURE__*/function () {
74
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client, remoteDoctype, measure) {
75
+ return _regenerator.default.wrap(function _callee$(_context) {
76
+ while (1) {
77
+ switch (_context.prev = _context.next) {
78
+ case 0:
79
+ _context.prev = 0;
80
+ checkMeasureParams(measure);
81
+ _context.next = 4;
82
+ return client.getStackClient().fetchJSON('POST', "/remote/".concat(remoteDoctype), {
83
+ data: JSON.stringify(measure)
84
+ });
85
+
86
+ case 4:
87
+ _context.next = 10;
88
+ break;
89
+
90
+ case 6:
91
+ _context.prev = 6;
92
+ _context.t0 = _context["catch"](0);
93
+ (0, _cozyLogger.default)('error', "Error while sending measure to remote doctype: ".concat(_context.t0.message));
94
+ throw _context.t0;
95
+
96
+ case 10:
97
+ case "end":
98
+ return _context.stop();
99
+ }
100
+ }
101
+ }, _callee, null, [[0, 6]]);
102
+ }));
103
+
104
+ return function sendMeasureToDACC(_x, _x2, _x3) {
105
+ return _ref.apply(this, arguments);
106
+ };
107
+ }();
108
+
109
+ exports.sendMeasureToDACC = sendMeasureToDACC;
@@ -0,0 +1,99 @@
1
+ import { checkMeasureParams } from './dacc'
2
+
3
+ describe('dacc', () => {
4
+ const measure = {
5
+ value: 42,
6
+ measureName: 'theanswer',
7
+ startDate: '2022-01-01',
8
+ createdBy: 'DeepThought'
9
+ }
10
+
11
+ it('should not throw when all params are corrects', () => {
12
+ expect(() => checkMeasureParams(measure)).not.toThrow()
13
+ })
14
+
15
+ it('should not throw when all params are corrects with groups', () => {
16
+ const measureWithGroups = {
17
+ ...measure,
18
+ group1: { a: 1 },
19
+ group2: { b: 1 },
20
+ group3: { c: 1 }
21
+ }
22
+ expect(() => checkMeasureParams(measureWithGroups)).not.toThrow()
23
+ })
24
+
25
+ it('should throw an error when createdBy is missing or malformed', () => {
26
+ expect(() => checkMeasureParams({ ...measure, createdBy: null })).toThrow()
27
+ expect(() => checkMeasureParams({ ...measure, createdBy: 123 })).toThrow()
28
+ })
29
+
30
+ it('should throw an error when value is missing or malformed', () => {
31
+ expect(() => checkMeasureParams({ ...measure, value: null })).toThrow()
32
+ expect(() =>
33
+ checkMeasureParams({ ...measure, value: 'notacorrectvalue' })
34
+ ).toThrow()
35
+ })
36
+
37
+ it('should throw an error when measureName is missing or malformed', () => {
38
+ expect(() =>
39
+ checkMeasureParams({ ...measure, measureName: null })
40
+ ).toThrow()
41
+ expect(() => checkMeasureParams({ ...measure, measureName: 10 })).toThrow()
42
+ })
43
+
44
+ it('should throw an error when startDate is missing or malformed', () => {
45
+ expect(() => checkMeasureParams({ ...measure, startDate: null })).toThrow()
46
+ expect(() => checkMeasureParams({ ...measure, startDate: 123 })).toThrow()
47
+ expect(() =>
48
+ checkMeasureParams({ ...measure, startDate: '01 January 2012' })
49
+ ).toThrow()
50
+ expect(() =>
51
+ checkMeasureParams({ ...measure, startDate: '2022:01:01' })
52
+ ).toThrow()
53
+ })
54
+
55
+ it('should throw an error when groups are not objects', () => {
56
+ expect(() => checkMeasureParams({ ...measure, group1: '123' })).toThrow()
57
+ expect(() =>
58
+ checkMeasureParams({ ...measure, group1: { a: 1 }, group2: '456' })
59
+ ).toThrow()
60
+ expect(() =>
61
+ checkMeasureParams({
62
+ ...measure,
63
+ group1: { a: 1 },
64
+ group2: { b: 1 },
65
+ group3: '789'
66
+ })
67
+ ).toThrow()
68
+ })
69
+
70
+ it('should throw an error when groups are empty objects', () => {
71
+ expect(() => checkMeasureParams({ ...measure, group1: {} })).toThrow()
72
+ expect(() =>
73
+ checkMeasureParams({ ...measure, group1: { a: 1 }, group2: {} })
74
+ ).toThrow()
75
+ expect(() =>
76
+ checkMeasureParams({
77
+ ...measure,
78
+ group1: { a: 1 },
79
+ group2: { b: 1 },
80
+ group3: {}
81
+ })
82
+ ).toThrow()
83
+ })
84
+
85
+ it('should throw an error when groups order is not respected', () => {
86
+ expect(() => checkMeasureParams({ ...measure, group2: { b: 1 } })).toThrow()
87
+ expect(() => checkMeasureParams({ ...measure, group3: { c: 1 } })).toThrow()
88
+ expect(() =>
89
+ checkMeasureParams({
90
+ ...measure,
91
+ group1: { a: 1 },
92
+ group3: { c: 1 }
93
+ })
94
+ ).toThrow()
95
+ expect(() =>
96
+ checkMeasureParams({ ...measure, group2: { b: 1 }, group3: { c: 1 } })
97
+ ).toThrow()
98
+ })
99
+ })
package/dist/types.js CHANGED
@@ -87,6 +87,11 @@ var _dsl = require("./queries/dsl");
87
87
  * @property {AutoUpdateOptions} [autoUpdate] - Options for the query auto update
88
88
  * @property {string} [update] - Does not seem to be used
89
89
  * @property {Function} [onError] - Callback when the query is errored
90
+ * @property {boolean} [enabled=true] - If set to false, the query won't be executed
91
+ * @property {object} [hydrated=true] - Whether documents should be returned already hydrated
92
+ * @property {object} [singleDocData] - If true, the "data" returned will be
93
+ * a single doc instead of an array for single doc queries. Defaults to false for backward
94
+ * compatibility but will be set to true in the future.
90
95
  */
91
96
 
92
97
  /**
@@ -303,6 +308,19 @@ var _dsl = require("./queries/dsl");
303
308
  * @typedef {IdentityLabel|FamilyLabel|WorkStudyLabels|HealthLabels|HomeLabels|TransportLabels|FinanceLabels|InvoiceLabels|ActivityLabels} ItemsLabels
304
309
  */
305
310
 
311
+ /**
312
+ * @typedef {object} DACCMeasure
313
+ * See https://github.com/cozy/DACC
314
+ *
315
+ * @property {string} measureName - It must match an existing measure name on the DACC server
316
+ * @property {string} startDate - Start of the aggregation period. Should be in YYYY-MM-DD format
317
+ * @property {number} value - The measured value on the aggregation period
318
+ * @property {string} createdBy - The slug of the app creating the measure
319
+ * @property {object} group1 - Should be a {key: value} where the key is set in the measure definition.
320
+ * @property {object} group2 - Should be a {key: value} where the key is set in the measure definition.
321
+ * @property {object} group3 - Should be a {key: value} where the key is set in the measure definition.
322
+ */
323
+
306
324
  /**
307
325
  * Receives the URL to present to the user as a parameter, and should return a promise that resolves with the URL the user was redirected to after accepting the permissions.
308
326
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "27.22.3",
3
+ "version": "27.25.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -71,5 +71,5 @@
71
71
  "react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
72
72
  },
73
73
  "sideEffects": false,
74
- "gitHead": "88e40193353972ae7280d31fe8657e874f3ee5c8"
74
+ "gitHead": "5fdb483852d6bd711dac46ff00734b853d118741"
75
75
  }
@@ -0,0 +1,2 @@
1
+ export default useIsMounted;
2
+ declare function useIsMounted(): import("react").MutableRefObject<undefined>;
@@ -0,0 +1,2 @@
1
+ export default useSafeState;
2
+ declare function useSafeState(initialState: any): any[];
@@ -4,3 +4,4 @@ export { default as useFetchShortcut } from "./useFetchShortcut";
4
4
  export { default as useClient } from "./useClient";
5
5
  export { default as useQuery } from "./useQuery";
6
6
  export { default as useAppsInMaintenance } from "./useAppsInMaintenance";
7
+ export { default as useQueryAll } from "./useQueryAll";
@@ -2,47 +2,12 @@ export function useQueries(querySpecs: any): {};
2
2
  export default useQuery;
3
3
  /**
4
4
  * Fetches a queryDefinition and returns the queryState
5
- */
6
- export type UseQueryOptions = {
7
- /**
8
- * - Name for the query [required]
9
- */
10
- as: object;
11
- /**
12
- * - If set to false, the query won't be executed
13
- */
14
- enabled: boolean;
15
- /**
16
- * - Fetch policy
17
- */
18
- fetchPolicy: object;
19
- /**
20
- * - If true, the "data" returned will be
21
- * a single doc instead of an array for single doc queries. Defaults to false for backward
22
- * compatibility but will be set to true in the future.
23
- */
24
- singleDocData: object;
25
- /**
26
- * - Callback if the query is errored
27
- */
28
- onError: Function;
29
- };
30
- /**
31
- * Fetches a queryDefinition and returns the queryState
32
- *
33
- * @param {QueryDefinition} queryDefinition - Definition created with Q()
34
- *
35
- * @typedef {object} UseQueryOptions
36
- * @property {object} as - Name for the query [required]
37
- * @property {boolean} enabled - If set to false, the query won't be executed
38
- * @property {object} fetchPolicy - Fetch policy
39
- * @property {object} singleDocData - If true, the "data" returned will be
40
- * a single doc instead of an array for single doc queries. Defaults to false for backward
41
- * compatibility but will be set to true in the future.
42
- * @property {Function} onError - Callback if the query is errored
43
5
  *
6
+ * @param {QueryDefinition} queryDefinition - Definition created with Q()
7
+ * @param {QueryOptions} options - Options created with Q()
44
8
  * @returns {UseQueryReturnValue}
45
9
  */
46
- declare function useQuery(queryDefinition: QueryDefinition, options: any): UseQueryReturnValue;
10
+ declare function useQuery(queryDefinition: QueryDefinition, options: QueryOptions): UseQueryReturnValue;
47
11
  import { QueryDefinition } from "../queries/dsl";
12
+ import { QueryOptions } from "../types";
48
13
  import { UseQueryReturnValue } from "../types";
@@ -0,0 +1,12 @@
1
+ export default useQueryAll;
2
+ /**
3
+ * Fetches a queryDefinition and run fetchMore on the query until the query is fully loaded
4
+ *
5
+ * @param {QueryDefinition} queryDefinition - Definition created with Q()
6
+ * @param {QueryOptions} options - Options created with Q()
7
+ * @returns {UseQueryReturnValue}
8
+ */
9
+ declare function useQueryAll(queryDefinition: QueryDefinition, options: QueryOptions): UseQueryReturnValue;
10
+ import { QueryDefinition } from "../queries/dsl";
11
+ import { QueryOptions } from "../types";
12
+ import { UseQueryReturnValue } from "../types";
package/types/types.d.ts CHANGED
@@ -68,6 +68,20 @@ export type QueryOptions = {
68
68
  * - Callback when the query is errored
69
69
  */
70
70
  onError?: Function;
71
+ /**
72
+ * - If set to false, the query won't be executed
73
+ */
74
+ enabled?: boolean;
75
+ /**
76
+ * - Whether documents should be returned already hydrated
77
+ */
78
+ hydrated?: object;
79
+ /**
80
+ * - If true, the "data" returned will be
81
+ * a single doc instead of an array for single doc queries. Defaults to false for backward
82
+ * compatibility but will be set to true in the future.
83
+ */
84
+ singleDocData?: object;
71
85
  };
72
86
  export type FetchMoreAble = {
73
87
  fetchMore: Function;