cozy-client 32.3.2 → 32.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.
- package/dist/CozyClient.js +73 -55
- package/dist/CozyClient.spec.js +40 -1
- package/dist/Query.spec.jsx +1 -0
- package/dist/flagship-certification/flagship-certification.js +2 -0
- package/dist/flagship-certification/store-attestation.android.js +3 -1
- package/dist/flagship-certification/store-attestation.ios.js +3 -1
- package/dist/flagship-certification/store-attestation.js +2 -0
- package/dist/flagship-certification/typedefs.js +9 -1
- package/dist/hooks/useQuery.spec.jsx +1 -0
- package/dist/store/__snapshots__/queries.spec.js.snap +19 -1
- package/dist/store/queries.js +44 -9
- package/dist/store/queries.spec.js +112 -27
- package/dist/store.spec.js +1 -0
- package/dist/types.js +3 -0
- package/package.json +4 -4
- package/types/CozyClient.d.ts +26 -6
- package/types/flagship-certification/flagship-certification.d.ts +1 -0
- package/types/flagship-certification/store-attestation.android.d.ts +2 -0
- package/types/flagship-certification/store-attestation.d.ts +2 -0
- package/types/flagship-certification/store-attestation.ios.d.ts +2 -0
- package/types/flagship-certification/typedefs.d.ts +6 -4
- package/types/store/queries.d.ts +4 -20
- package/types/types.d.ts +9 -0
package/dist/CozyClient.js
CHANGED
|
@@ -140,6 +140,7 @@ var DOC_UPDATE = 'update';
|
|
|
140
140
|
* @property {object} [stackClient]
|
|
141
141
|
* @property {boolean} [warningForCustomHandlers]
|
|
142
142
|
* @property {boolean} [autoHydrate]
|
|
143
|
+
* @property {boolean} [backgroundFetching] - If set to true, backgroundFetching will be enabled by default on every query. Meaning that, when the fetchStatus has already been loaded, it won't be updated during future fetches. Instead, a `isFetching` attribute will be used to indicate when background fetching is started.
|
|
143
144
|
* @property {object} [oauth]
|
|
144
145
|
* @property {Function} [onTokenRefresh]
|
|
145
146
|
* @property {Function} [onError] - Default callback if a query is errored
|
|
@@ -189,35 +190,38 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
189
190
|
var rawOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
190
191
|
(0, _classCallCheck2.default)(this, CozyClient);
|
|
191
192
|
(0, _defineProperty2.default)(this, "fetchQueryAndGetFromState", /*#__PURE__*/function () {
|
|
192
|
-
var
|
|
193
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref) {
|
|
194
|
+
var definition, options;
|
|
193
195
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
194
196
|
while (1) {
|
|
195
197
|
switch (_context.prev = _context.next) {
|
|
196
198
|
case 0:
|
|
197
|
-
|
|
198
|
-
_context.
|
|
199
|
-
|
|
199
|
+
definition = _ref.definition, options = _ref.options;
|
|
200
|
+
_context.prev = 1;
|
|
201
|
+
_context.next = 4;
|
|
202
|
+
return _this.query(definition, options);
|
|
200
203
|
|
|
201
|
-
case
|
|
202
|
-
return _context.abrupt("return", _this.getQueryFromState(
|
|
204
|
+
case 4:
|
|
205
|
+
return _context.abrupt("return", _this.getQueryFromState(options.as));
|
|
203
206
|
|
|
204
|
-
case
|
|
205
|
-
_context.prev =
|
|
206
|
-
_context.t0 = _context["catch"](
|
|
207
|
+
case 7:
|
|
208
|
+
_context.prev = 7;
|
|
209
|
+
_context.t0 = _context["catch"](1);
|
|
207
210
|
throw _context.t0;
|
|
208
211
|
|
|
209
|
-
case
|
|
212
|
+
case 10:
|
|
210
213
|
case "end":
|
|
211
214
|
return _context.stop();
|
|
212
215
|
}
|
|
213
216
|
}
|
|
214
|
-
}, _callee, null, [[
|
|
217
|
+
}, _callee, null, [[1, 7]]);
|
|
215
218
|
}));
|
|
216
219
|
|
|
217
220
|
return function (_x) {
|
|
218
|
-
return
|
|
221
|
+
return _ref2.apply(this, arguments);
|
|
219
222
|
};
|
|
220
223
|
}());
|
|
224
|
+
|
|
221
225
|
var link = rawOptions.link,
|
|
222
226
|
links = rawOptions.links,
|
|
223
227
|
_rawOptions$schema = rawOptions.schema,
|
|
@@ -225,15 +229,15 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
225
229
|
_rawOptions$appMetada = rawOptions.appMetadata,
|
|
226
230
|
appMetadata = _rawOptions$appMetada === void 0 ? {} : _rawOptions$appMetada,
|
|
227
231
|
capabilities = rawOptions.capabilities,
|
|
228
|
-
|
|
232
|
+
_options = (0, _objectWithoutProperties2.default)(rawOptions, ["link", "links", "schema", "appMetadata", "capabilities"]);
|
|
229
233
|
|
|
230
234
|
if (link) {
|
|
231
235
|
console.warn('`link` is deprecated, use `links`');
|
|
232
236
|
}
|
|
233
237
|
|
|
234
238
|
this.appMetadata = appMetadata;
|
|
235
|
-
|
|
236
|
-
this.options =
|
|
239
|
+
_options.uri = securiseUri(_options.uri);
|
|
240
|
+
this.options = _options;
|
|
237
241
|
this.queryIdGenerator = new _queries.QueryIDGenerator();
|
|
238
242
|
this.isLogged = false;
|
|
239
243
|
this.instanceOptions = {}; // Bind handlers
|
|
@@ -266,7 +270,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
266
270
|
} catch (err) {// not a critical error, we may be in node or the instance options are not on the default HTML element
|
|
267
271
|
}
|
|
268
272
|
|
|
269
|
-
if (
|
|
273
|
+
if (_options.uri && _options.token) {
|
|
270
274
|
this.login();
|
|
271
275
|
}
|
|
272
276
|
/**
|
|
@@ -276,7 +280,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
276
280
|
|
|
277
281
|
this.storeAccesors = null;
|
|
278
282
|
|
|
279
|
-
if (
|
|
283
|
+
if (_options.store !== false) {
|
|
280
284
|
this.ensureStore();
|
|
281
285
|
}
|
|
282
286
|
/**
|
|
@@ -951,6 +955,13 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
951
955
|
|
|
952
956
|
return saveAll;
|
|
953
957
|
}()
|
|
958
|
+
/**
|
|
959
|
+
* @param {CozyClientDocument} document - Document that will be saved
|
|
960
|
+
* @param {object} [options={event: DOC_CREATION}] - Event
|
|
961
|
+
* @param {string} [options.event] - Mutation type
|
|
962
|
+
* @returns {CozyClientDocument}
|
|
963
|
+
*/
|
|
964
|
+
|
|
954
965
|
}, {
|
|
955
966
|
key: "ensureCozyMetadata",
|
|
956
967
|
value: function ensureCozyMetadata(document) {
|
|
@@ -1035,7 +1046,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1035
1046
|
* ```
|
|
1036
1047
|
*
|
|
1037
1048
|
*
|
|
1038
|
-
* @param {
|
|
1049
|
+
* @param {CozyClientDocument} document - Document to create
|
|
1039
1050
|
* @param {ReferenceMap} [referencesByName] - References to the created document. The
|
|
1040
1051
|
* relationship class associated to each reference list should support references, otherwise this
|
|
1041
1052
|
* method will throw.
|
|
@@ -1077,10 +1088,10 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1077
1088
|
return [saveMutation, function (response) {
|
|
1078
1089
|
var doc = _this3.hydrateDocument(response.data);
|
|
1079
1090
|
|
|
1080
|
-
return Object.entries(referencesByName).map(function (
|
|
1081
|
-
var
|
|
1082
|
-
relName =
|
|
1083
|
-
references =
|
|
1091
|
+
return Object.entries(referencesByName).map(function (_ref3) {
|
|
1092
|
+
var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
|
|
1093
|
+
relName = _ref4[0],
|
|
1094
|
+
references = _ref4[1];
|
|
1084
1095
|
|
|
1085
1096
|
var relationship = doc[relName];
|
|
1086
1097
|
return relationship.addReferences(references);
|
|
@@ -1217,12 +1228,13 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1217
1228
|
var _query = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(queryDefinition) {
|
|
1218
1229
|
var _this4 = this;
|
|
1219
1230
|
|
|
1220
|
-
var
|
|
1231
|
+
var _ref5,
|
|
1221
1232
|
update,
|
|
1222
1233
|
options,
|
|
1223
1234
|
queryId,
|
|
1224
1235
|
existingQuery,
|
|
1225
1236
|
shouldFetch,
|
|
1237
|
+
backgroundFetching,
|
|
1226
1238
|
response,
|
|
1227
1239
|
_args8 = arguments;
|
|
1228
1240
|
|
|
@@ -1230,8 +1242,8 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1230
1242
|
while (1) {
|
|
1231
1243
|
switch (_context8.prev = _context8.next) {
|
|
1232
1244
|
case 0:
|
|
1233
|
-
|
|
1234
|
-
update =
|
|
1245
|
+
_ref5 = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : {};
|
|
1246
|
+
update = _ref5.update, options = (0, _objectWithoutProperties2.default)(_ref5, ["update"]);
|
|
1235
1247
|
this.ensureStore();
|
|
1236
1248
|
queryId = options.as || this.queryIdGenerator.generateId(queryDefinition);
|
|
1237
1249
|
existingQuery = this.getQueryFromState(queryId);
|
|
@@ -1276,55 +1288,59 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1276
1288
|
case 14:
|
|
1277
1289
|
this.ensureQueryExists(queryId, queryDefinition, options);
|
|
1278
1290
|
_context8.prev = 15;
|
|
1279
|
-
|
|
1280
|
-
|
|
1291
|
+
backgroundFetching = options.backgroundFetching !== undefined ? options.backgroundFetching : this.options.backgroundFetching;
|
|
1292
|
+
this.dispatch((0, _store.loadQuery)(queryId, {
|
|
1293
|
+
backgroundFetching: backgroundFetching
|
|
1294
|
+
}));
|
|
1295
|
+
_context8.next = 20;
|
|
1281
1296
|
return this._promiseCache.exec(function () {
|
|
1282
1297
|
return _this4.requestQuery(queryDefinition);
|
|
1283
1298
|
}, function () {
|
|
1284
1299
|
return (0, _jsonStableStringify.default)(queryDefinition);
|
|
1285
1300
|
});
|
|
1286
1301
|
|
|
1287
|
-
case
|
|
1302
|
+
case 20:
|
|
1288
1303
|
response = _context8.sent;
|
|
1289
1304
|
this.dispatch((0, _store.receiveQueryResult)(queryId, response, {
|
|
1290
|
-
update: update
|
|
1305
|
+
update: update,
|
|
1306
|
+
backgroundFetching: backgroundFetching
|
|
1291
1307
|
}));
|
|
1292
1308
|
return _context8.abrupt("return", response);
|
|
1293
1309
|
|
|
1294
|
-
case
|
|
1295
|
-
_context8.prev =
|
|
1310
|
+
case 25:
|
|
1311
|
+
_context8.prev = 25;
|
|
1296
1312
|
_context8.t0 = _context8["catch"](15);
|
|
1297
1313
|
this.dispatch((0, _store.receiveQueryError)(queryId, _context8.t0)); // specific onError
|
|
1298
1314
|
|
|
1299
1315
|
if (!options.onError) {
|
|
1300
|
-
_context8.next =
|
|
1316
|
+
_context8.next = 32;
|
|
1301
1317
|
break;
|
|
1302
1318
|
}
|
|
1303
1319
|
|
|
1304
1320
|
options.onError(_context8.t0); // defaulted onError
|
|
1305
1321
|
|
|
1306
|
-
_context8.next =
|
|
1322
|
+
_context8.next = 37;
|
|
1307
1323
|
break;
|
|
1308
1324
|
|
|
1309
|
-
case
|
|
1325
|
+
case 32:
|
|
1310
1326
|
if (!this.options.onError) {
|
|
1311
|
-
_context8.next =
|
|
1327
|
+
_context8.next = 36;
|
|
1312
1328
|
break;
|
|
1313
1329
|
}
|
|
1314
1330
|
|
|
1315
1331
|
this.options.onError(_context8.t0);
|
|
1316
|
-
_context8.next =
|
|
1332
|
+
_context8.next = 37;
|
|
1317
1333
|
break;
|
|
1318
1334
|
|
|
1319
|
-
case
|
|
1335
|
+
case 36:
|
|
1320
1336
|
throw _context8.t0;
|
|
1321
1337
|
|
|
1322
|
-
case
|
|
1338
|
+
case 37:
|
|
1323
1339
|
case "end":
|
|
1324
1340
|
return _context8.stop();
|
|
1325
1341
|
}
|
|
1326
1342
|
}
|
|
1327
|
-
}, _callee8, this, [[15,
|
|
1343
|
+
}, _callee8, this, [[15, 25]]);
|
|
1328
1344
|
}));
|
|
1329
1345
|
|
|
1330
1346
|
function query(_x9) {
|
|
@@ -1449,7 +1465,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1449
1465
|
key: "mutate",
|
|
1450
1466
|
value: function () {
|
|
1451
1467
|
var _mutate = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(mutationDefinition) {
|
|
1452
|
-
var
|
|
1468
|
+
var _ref6,
|
|
1453
1469
|
update,
|
|
1454
1470
|
updateQueries,
|
|
1455
1471
|
options,
|
|
@@ -1461,8 +1477,8 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1461
1477
|
while (1) {
|
|
1462
1478
|
switch (_context10.prev = _context10.next) {
|
|
1463
1479
|
case 0:
|
|
1464
|
-
|
|
1465
|
-
update =
|
|
1480
|
+
_ref6 = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {};
|
|
1481
|
+
update = _ref6.update, updateQueries = _ref6.updateQueries, options = (0, _objectWithoutProperties2.default)(_ref6, ["update", "updateQueries"]);
|
|
1466
1482
|
this.ensureStore();
|
|
1467
1483
|
mutationId = options.as || this.queryIdGenerator.generateId(mutationDefinition);
|
|
1468
1484
|
this.dispatch((0, _store.initMutation)(mutationId, mutationDefinition));
|
|
@@ -1931,6 +1947,8 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1931
1947
|
* Has a behavior close to <Query /> or useQuery
|
|
1932
1948
|
*
|
|
1933
1949
|
* @param {object} query - Query with definition and options
|
|
1950
|
+
* @param {QueryDefinition} query.definition - Query Definition
|
|
1951
|
+
* @param {QueryOptions} query.options - Query Options
|
|
1934
1952
|
* @returns {Promise<QueryState>} Query state
|
|
1935
1953
|
*/
|
|
1936
1954
|
|
|
@@ -2053,12 +2071,12 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2053
2071
|
key: "authorize",
|
|
2054
2072
|
value: function () {
|
|
2055
2073
|
var _authorize = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16() {
|
|
2056
|
-
var
|
|
2057
|
-
|
|
2074
|
+
var _ref7,
|
|
2075
|
+
_ref7$openURLCallback,
|
|
2058
2076
|
openURLCallback,
|
|
2059
|
-
|
|
2077
|
+
_ref7$sessionCode,
|
|
2060
2078
|
sessionCode,
|
|
2061
|
-
|
|
2079
|
+
_ref7$pkceCodes,
|
|
2062
2080
|
pkceCodes,
|
|
2063
2081
|
codeVerifier,
|
|
2064
2082
|
codeChallenge,
|
|
@@ -2075,7 +2093,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2075
2093
|
while (1) {
|
|
2076
2094
|
switch (_context16.prev = _context16.next) {
|
|
2077
2095
|
case 0:
|
|
2078
|
-
|
|
2096
|
+
_ref7 = _args16.length > 0 && _args16[0] !== undefined ? _args16[0] : {}, _ref7$openURLCallback = _ref7.openURLCallback, openURLCallback = _ref7$openURLCallback === void 0 ? _mobile.authFunction : _ref7$openURLCallback, _ref7$sessionCode = _ref7.sessionCode, sessionCode = _ref7$sessionCode === void 0 ? undefined : _ref7$sessionCode, _ref7$pkceCodes = _ref7.pkceCodes, pkceCodes = _ref7$pkceCodes === void 0 ? {} : _ref7$pkceCodes;
|
|
2079
2097
|
_context16.prev = 1;
|
|
2080
2098
|
codeVerifier = pkceCodes.codeVerifier, codeChallenge = pkceCodes.codeChallenge;
|
|
2081
2099
|
stackClient = this.getStackClient();
|
|
@@ -2172,9 +2190,9 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2172
2190
|
}, {
|
|
2173
2191
|
key: "setStore",
|
|
2174
2192
|
value: function setStore(store) {
|
|
2175
|
-
var
|
|
2176
|
-
|
|
2177
|
-
force =
|
|
2193
|
+
var _ref8 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
2194
|
+
_ref8$force = _ref8.force,
|
|
2195
|
+
force = _ref8$force === void 0 ? false : _ref8$force;
|
|
2178
2196
|
|
|
2179
2197
|
if (store === undefined) {
|
|
2180
2198
|
throw new Error('Store is undefined');
|
|
@@ -2368,10 +2386,10 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2368
2386
|
var _this10 = this;
|
|
2369
2387
|
|
|
2370
2388
|
this.ensureStore();
|
|
2371
|
-
Object.entries(data).forEach(function (
|
|
2372
|
-
var
|
|
2373
|
-
doctype =
|
|
2374
|
-
data =
|
|
2389
|
+
Object.entries(data).forEach(function (_ref9) {
|
|
2390
|
+
var _ref10 = (0, _slicedToArray2.default)(_ref9, 2),
|
|
2391
|
+
doctype = _ref10[0],
|
|
2392
|
+
data = _ref10[1];
|
|
2375
2393
|
|
|
2376
2394
|
_this10.dispatch((0, _store.receiveQueryResult)(null, {
|
|
2377
2395
|
data: data
|
|
@@ -2553,7 +2571,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2553
2571
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
2554
2572
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
2555
2573
|
|
|
2556
|
-
CozyClient.version = "32.
|
|
2574
|
+
CozyClient.version = "32.4.1";
|
|
2557
2575
|
|
|
2558
2576
|
_microee.default.mixin(CozyClient);
|
|
2559
2577
|
|
package/dist/CozyClient.spec.js
CHANGED
|
@@ -28,7 +28,8 @@ import {
|
|
|
28
28
|
receiveMutationResult,
|
|
29
29
|
receiveMutationError,
|
|
30
30
|
getQueryFromState,
|
|
31
|
-
getRawQueryFromState
|
|
31
|
+
getRawQueryFromState,
|
|
32
|
+
loadQuery
|
|
32
33
|
} from './store'
|
|
33
34
|
import { HasManyFiles, Association, HasMany } from './associations'
|
|
34
35
|
import mapValues from 'lodash/mapValues'
|
|
@@ -1417,6 +1418,44 @@ describe('CozyClient', () => {
|
|
|
1417
1418
|
)
|
|
1418
1419
|
})
|
|
1419
1420
|
|
|
1421
|
+
it('should dispatch a LOAD_QUERY action', async () => {
|
|
1422
|
+
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1423
|
+
getQueryFromState.mockReturnValueOnce({
|
|
1424
|
+
fetchStatus: 'loaded'
|
|
1425
|
+
})
|
|
1426
|
+
await client.query(query, { as: 'allTodos' })
|
|
1427
|
+
expect(client.store.dispatch.mock.calls[1][0]).toEqual(
|
|
1428
|
+
loadQuery('allTodos', {})
|
|
1429
|
+
)
|
|
1430
|
+
})
|
|
1431
|
+
|
|
1432
|
+
it('should dispatch a LOAD_QUERY action providing backgroundFetching when set', async () => {
|
|
1433
|
+
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1434
|
+
getQueryFromState.mockReturnValueOnce({
|
|
1435
|
+
fetchStatus: 'loaded'
|
|
1436
|
+
})
|
|
1437
|
+
await client.query(query, { as: 'allTodos', backgroundFetching: true })
|
|
1438
|
+
expect(client.store.dispatch.mock.calls[1][0]).toEqual(
|
|
1439
|
+
loadQuery('allTodos', { backgroundFetching: true })
|
|
1440
|
+
)
|
|
1441
|
+
})
|
|
1442
|
+
|
|
1443
|
+
it('should dispatch a RECEIVE_QUERY_RESULT action providing backgroundFetching when set', async () => {
|
|
1444
|
+
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1445
|
+
getQueryFromState.mockReturnValueOnce({
|
|
1446
|
+
fetchStatus: 'loaded'
|
|
1447
|
+
})
|
|
1448
|
+
query.skip = 100
|
|
1449
|
+
await client.query(query, { as: 'allTodos', backgroundFetching: true })
|
|
1450
|
+
const dispatchCalls = client.store.dispatch.mock.calls
|
|
1451
|
+
const lastDispatchCall = dispatchCalls[dispatchCalls.length - 1]
|
|
1452
|
+
expect(lastDispatchCall[0]).toEqual(
|
|
1453
|
+
receiveQueryResult('allTodos', fakeResponse, {
|
|
1454
|
+
backgroundFetching: true
|
|
1455
|
+
})
|
|
1456
|
+
)
|
|
1457
|
+
})
|
|
1458
|
+
|
|
1420
1459
|
it('should dispatch a RECEIVE_QUERY_RESULT action if query has skip', async () => {
|
|
1421
1460
|
requestHandler.mockResolvedValueOnce(fakeResponse)
|
|
1422
1461
|
getQueryFromState.mockReturnValueOnce({
|
package/dist/Query.spec.jsx
CHANGED
|
@@ -17,6 +17,8 @@ var _logger = _interopRequireDefault(require("../logger"));
|
|
|
17
17
|
|
|
18
18
|
var _storeAttestation = require("./store-attestation");
|
|
19
19
|
|
|
20
|
+
var _typedefs = require("./typedefs");
|
|
21
|
+
|
|
20
22
|
/**
|
|
21
23
|
* Request a challenge from the Stack that can be used to request the app attestation from the app store
|
|
22
24
|
*
|
|
@@ -13,7 +13,9 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
13
13
|
|
|
14
14
|
var _reactNativeGoogleSafetynet = _interopRequireDefault(require("react-native-google-safetynet"));
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
var _typedefs = require("./typedefs");
|
|
17
|
+
|
|
18
|
+
//@ts-ignore next-line
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Retrieve the app's attestation from the Google Play store
|
|
@@ -13,7 +13,9 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
13
13
|
|
|
14
14
|
var _reactNativeIos11Devicecheck = _interopRequireDefault(require("react-native-ios11-devicecheck"));
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
var _typedefs = require("./typedefs");
|
|
17
|
+
|
|
18
|
+
//@ts-ignore next-line
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Retrieve the app's attestation from the Apple AppStore
|
|
@@ -11,6 +11,8 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
|
|
|
11
11
|
|
|
12
12
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
13
|
|
|
14
|
+
var _typedefs = require("./typedefs");
|
|
15
|
+
|
|
14
16
|
/**
|
|
15
17
|
* Retrieve the app's attestation from the app's store
|
|
16
18
|
* /!\ This is a mock implementation that should never be called
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
1
8
|
/**
|
|
2
9
|
* @typedef {string} jws - A JSON Web Signature
|
|
3
10
|
*/
|
|
@@ -17,4 +24,5 @@
|
|
|
17
24
|
* @typedef {object} CertificationConfig - Configuration to access the stores certification API
|
|
18
25
|
* @property {string} androidSafetyNetApiKey
|
|
19
26
|
*/
|
|
20
|
-
|
|
27
|
+
var _default = {};
|
|
28
|
+
exports.default = _default;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`queries reducer should init correctly 1`] = `
|
|
3
|
+
exports[`queries reducer INIT_QUERY should init correctly 1`] = `
|
|
4
4
|
Object {
|
|
5
5
|
"a": Object {
|
|
6
6
|
"bookmark": null,
|
|
@@ -26,6 +26,7 @@ Object {
|
|
|
26
26
|
"fetchedPagesCount": 0,
|
|
27
27
|
"hasMore": false,
|
|
28
28
|
"id": "a",
|
|
29
|
+
"isFetching": null,
|
|
29
30
|
"lastError": null,
|
|
30
31
|
"lastErrorUpdate": null,
|
|
31
32
|
"lastFetch": null,
|
|
@@ -64,6 +65,7 @@ Object {
|
|
|
64
65
|
"fetchedPagesCount": 1,
|
|
65
66
|
"hasMore": false,
|
|
66
67
|
"id": "a",
|
|
68
|
+
"isFetching": null,
|
|
67
69
|
"lastError": null,
|
|
68
70
|
"lastErrorUpdate": null,
|
|
69
71
|
"lastFetch": 1337,
|
|
@@ -101,6 +103,7 @@ Object {
|
|
|
101
103
|
"fetchedPagesCount": 1,
|
|
102
104
|
"hasMore": false,
|
|
103
105
|
"id": "a",
|
|
106
|
+
"isFetching": null,
|
|
104
107
|
"lastError": null,
|
|
105
108
|
"lastErrorUpdate": null,
|
|
106
109
|
"lastFetch": 1337,
|
|
@@ -138,6 +141,7 @@ Object {
|
|
|
138
141
|
"fetchedPagesCount": 0,
|
|
139
142
|
"hasMore": false,
|
|
140
143
|
"id": "b",
|
|
144
|
+
"isFetching": null,
|
|
141
145
|
"lastError": null,
|
|
142
146
|
"lastErrorUpdate": null,
|
|
143
147
|
"lastFetch": null,
|
|
@@ -175,6 +179,7 @@ Object {
|
|
|
175
179
|
"fetchedPagesCount": 1,
|
|
176
180
|
"hasMore": false,
|
|
177
181
|
"id": "a",
|
|
182
|
+
"isFetching": null,
|
|
178
183
|
"lastError": null,
|
|
179
184
|
"lastErrorUpdate": null,
|
|
180
185
|
"lastFetch": 1337,
|
|
@@ -209,6 +214,7 @@ Object {
|
|
|
209
214
|
"fetchedPagesCount": 0,
|
|
210
215
|
"hasMore": false,
|
|
211
216
|
"id": "b",
|
|
217
|
+
"isFetching": null,
|
|
212
218
|
"lastError": null,
|
|
213
219
|
"lastErrorUpdate": null,
|
|
214
220
|
"lastFetch": null,
|
|
@@ -252,6 +258,7 @@ Object {
|
|
|
252
258
|
"fetchedPagesCount": 1,
|
|
253
259
|
"hasMore": false,
|
|
254
260
|
"id": "a",
|
|
261
|
+
"isFetching": null,
|
|
255
262
|
"lastError": null,
|
|
256
263
|
"lastErrorUpdate": null,
|
|
257
264
|
"lastFetch": 1337,
|
|
@@ -284,6 +291,7 @@ Object {
|
|
|
284
291
|
"fetchedPagesCount": 0,
|
|
285
292
|
"hasMore": false,
|
|
286
293
|
"id": "b",
|
|
294
|
+
"isFetching": null,
|
|
287
295
|
"lastError": null,
|
|
288
296
|
"lastErrorUpdate": null,
|
|
289
297
|
"lastFetch": null,
|
|
@@ -322,6 +330,7 @@ Object {
|
|
|
322
330
|
"fetchedPagesCount": 1,
|
|
323
331
|
"hasMore": false,
|
|
324
332
|
"id": "a",
|
|
333
|
+
"isFetching": null,
|
|
325
334
|
"lastError": null,
|
|
326
335
|
"lastErrorUpdate": null,
|
|
327
336
|
"lastFetch": 1337,
|
|
@@ -355,6 +364,7 @@ Object {
|
|
|
355
364
|
"fetchedPagesCount": 0,
|
|
356
365
|
"hasMore": false,
|
|
357
366
|
"id": "b",
|
|
367
|
+
"isFetching": null,
|
|
358
368
|
"lastError": null,
|
|
359
369
|
"lastErrorUpdate": null,
|
|
360
370
|
"lastFetch": null,
|
|
@@ -392,6 +402,7 @@ Object {
|
|
|
392
402
|
"fetchedPagesCount": 1,
|
|
393
403
|
"hasMore": false,
|
|
394
404
|
"id": "a",
|
|
405
|
+
"isFetching": null,
|
|
395
406
|
"lastError": null,
|
|
396
407
|
"lastErrorUpdate": null,
|
|
397
408
|
"lastFetch": 1337,
|
|
@@ -424,6 +435,7 @@ Object {
|
|
|
424
435
|
"fetchedPagesCount": 0,
|
|
425
436
|
"hasMore": false,
|
|
426
437
|
"id": "b",
|
|
438
|
+
"isFetching": null,
|
|
427
439
|
"lastError": null,
|
|
428
440
|
"lastErrorUpdate": null,
|
|
429
441
|
"lastFetch": null,
|
|
@@ -463,6 +475,7 @@ Object {
|
|
|
463
475
|
"fetchedPagesCount": 0,
|
|
464
476
|
"hasMore": false,
|
|
465
477
|
"id": "a",
|
|
478
|
+
"isFetching": null,
|
|
466
479
|
"lastError": null,
|
|
467
480
|
"lastErrorUpdate": null,
|
|
468
481
|
"lastFetch": null,
|
|
@@ -493,6 +506,7 @@ Object {
|
|
|
493
506
|
"fetchedPagesCount": 0,
|
|
494
507
|
"hasMore": false,
|
|
495
508
|
"id": "b",
|
|
509
|
+
"isFetching": null,
|
|
496
510
|
"lastError": null,
|
|
497
511
|
"lastErrorUpdate": null,
|
|
498
512
|
"lastFetch": 1337,
|
|
@@ -530,6 +544,7 @@ Object {
|
|
|
530
544
|
"fetchedPagesCount": 2,
|
|
531
545
|
"hasMore": false,
|
|
532
546
|
"id": "a",
|
|
547
|
+
"isFetching": null,
|
|
533
548
|
"lastError": null,
|
|
534
549
|
"lastErrorUpdate": null,
|
|
535
550
|
"lastFetch": 1337,
|
|
@@ -564,6 +579,7 @@ Object {
|
|
|
564
579
|
"fetchedPagesCount": 0,
|
|
565
580
|
"hasMore": false,
|
|
566
581
|
"id": "b",
|
|
582
|
+
"isFetching": null,
|
|
567
583
|
"lastError": null,
|
|
568
584
|
"lastErrorUpdate": null,
|
|
569
585
|
"lastFetch": null,
|
|
@@ -605,6 +621,7 @@ Object {
|
|
|
605
621
|
"fetchedPagesCount": 1,
|
|
606
622
|
"hasMore": false,
|
|
607
623
|
"id": "a",
|
|
624
|
+
"isFetching": null,
|
|
608
625
|
"lastError": null,
|
|
609
626
|
"lastErrorUpdate": null,
|
|
610
627
|
"lastFetch": 1337,
|
|
@@ -637,6 +654,7 @@ Object {
|
|
|
637
654
|
"fetchedPagesCount": 0,
|
|
638
655
|
"hasMore": false,
|
|
639
656
|
"id": "b",
|
|
657
|
+
"isFetching": null,
|
|
640
658
|
"lastError": null,
|
|
641
659
|
"lastErrorUpdate": null,
|
|
642
660
|
"lastFetch": null,
|
package/dist/store/queries.js
CHANGED
|
@@ -84,6 +84,7 @@ var queryInitialState = {
|
|
|
84
84
|
id: null,
|
|
85
85
|
definition: null,
|
|
86
86
|
fetchStatus: 'pending',
|
|
87
|
+
isFetching: null,
|
|
87
88
|
lastFetch: null,
|
|
88
89
|
lastUpdate: null,
|
|
89
90
|
lastErrorUpdate: null,
|
|
@@ -187,10 +188,6 @@ var query = function query() {
|
|
|
187
188
|
id: action.queryId,
|
|
188
189
|
definition: action.queryDefinition,
|
|
189
190
|
options: action.options,
|
|
190
|
-
// When the query is new, we set "fetchStatus" to "loading"
|
|
191
|
-
// directly since we know it will be loaded right away.
|
|
192
|
-
// This way, the loadQuery action will have no effect, and
|
|
193
|
-
// we save an additional render.
|
|
194
191
|
fetchStatus: state.lastUpdate ? state.fetchStatus : 'pending'
|
|
195
192
|
});
|
|
196
193
|
|
|
@@ -199,6 +196,13 @@ var query = function query() {
|
|
|
199
196
|
return state;
|
|
200
197
|
}
|
|
201
198
|
|
|
199
|
+
if (state.fetchStatus === 'loaded' && action.backgroundFetching) {
|
|
200
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
201
|
+
fetchStatus: 'loaded',
|
|
202
|
+
isFetching: true
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
202
206
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
203
207
|
fetchStatus: 'loading'
|
|
204
208
|
});
|
|
@@ -212,6 +216,7 @@ var query = function query() {
|
|
|
212
216
|
if (!response.data) {
|
|
213
217
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
214
218
|
fetchStatus: 'loaded',
|
|
219
|
+
isFetching: action.backgroundFetching ? false : null,
|
|
215
220
|
lastFetch: Date.now(),
|
|
216
221
|
lastUpdate: Date.now()
|
|
217
222
|
});
|
|
@@ -221,6 +226,7 @@ var query = function query() {
|
|
|
221
226
|
|
|
222
227
|
var common = _objectSpread({
|
|
223
228
|
fetchStatus: 'loaded',
|
|
229
|
+
isFetching: action.backgroundFetching ? false : null,
|
|
224
230
|
lastFetch: Date.now(),
|
|
225
231
|
lastUpdate: Date.now()
|
|
226
232
|
}, executionStatsEnabled && {
|
|
@@ -254,6 +260,7 @@ var query = function query() {
|
|
|
254
260
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
255
261
|
id: action.queryId,
|
|
256
262
|
fetchStatus: 'failed',
|
|
263
|
+
isFetching: action.backgroundFetching ? false : null,
|
|
257
264
|
lastError: action.error,
|
|
258
265
|
lastErrorUpdate: Date.now()
|
|
259
266
|
});
|
|
@@ -566,6 +573,7 @@ var _default = queries;
|
|
|
566
573
|
* @param {string} queryId Name/id of the query
|
|
567
574
|
* @param {QueryDefinition} queryDefinition - Definition of the created query
|
|
568
575
|
* @param {QueryOptions} [options] - Options for the created query
|
|
576
|
+
* @returns {object} Redux action to dispatch
|
|
569
577
|
*/
|
|
570
578
|
|
|
571
579
|
exports.default = _default;
|
|
@@ -584,15 +592,32 @@ var initQuery = function initQuery(queryId, queryDefinition) {
|
|
|
584
592
|
options: options
|
|
585
593
|
};
|
|
586
594
|
};
|
|
595
|
+
/**
|
|
596
|
+
* Update the fetchStatus when the query is loading
|
|
597
|
+
*
|
|
598
|
+
* @param {string} queryId - id of the query
|
|
599
|
+
* @param {QueryOptions} [options] - Options for the created query
|
|
600
|
+
* @returns {object} Redux action to dispatch
|
|
601
|
+
*/
|
|
602
|
+
|
|
587
603
|
|
|
588
604
|
exports.initQuery = initQuery;
|
|
589
605
|
|
|
590
|
-
var loadQuery = function loadQuery(queryId) {
|
|
591
|
-
return {
|
|
606
|
+
var loadQuery = function loadQuery(queryId, options) {
|
|
607
|
+
return _objectSpread({
|
|
592
608
|
type: LOAD_QUERY,
|
|
593
609
|
queryId: queryId
|
|
594
|
-
};
|
|
610
|
+
}, options);
|
|
595
611
|
};
|
|
612
|
+
/**
|
|
613
|
+
* Update the fetchStatus when the query is loading
|
|
614
|
+
*
|
|
615
|
+
* @param {string} queryId - id of the query
|
|
616
|
+
* @param {object} response - The action response
|
|
617
|
+
* @param {QueryOptions} [options] - Options for the created query
|
|
618
|
+
* @returns {object} Redux action to dispatch
|
|
619
|
+
*/
|
|
620
|
+
|
|
596
621
|
|
|
597
622
|
exports.loadQuery = loadQuery;
|
|
598
623
|
|
|
@@ -604,15 +629,25 @@ var receiveQueryResult = function receiveQueryResult(queryId, response) {
|
|
|
604
629
|
response: response
|
|
605
630
|
}, options);
|
|
606
631
|
};
|
|
632
|
+
/**
|
|
633
|
+
* Update the fetchStatus when the query is loading
|
|
634
|
+
*
|
|
635
|
+
* @param {string} queryId - id of the query
|
|
636
|
+
* @param {object} error - The action error
|
|
637
|
+
* @param {QueryOptions} [options] - Options for the created query
|
|
638
|
+
* @returns {object} Redux action to dispatch
|
|
639
|
+
*/
|
|
640
|
+
|
|
607
641
|
|
|
608
642
|
exports.receiveQueryResult = receiveQueryResult;
|
|
609
643
|
|
|
610
644
|
var receiveQueryError = function receiveQueryError(queryId, error) {
|
|
611
|
-
|
|
645
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
646
|
+
return _objectSpread({
|
|
612
647
|
type: RECEIVE_QUERY_ERROR,
|
|
613
648
|
queryId: queryId,
|
|
614
649
|
error: error
|
|
615
|
-
};
|
|
650
|
+
}, options);
|
|
616
651
|
}; // selectors
|
|
617
652
|
|
|
618
653
|
|
|
@@ -4,14 +4,18 @@ import queries, {
|
|
|
4
4
|
convert$gtNullSelectors,
|
|
5
5
|
makeSorterFromDefinition,
|
|
6
6
|
mergeSelectorAndPartialIndex,
|
|
7
|
-
sortAndLimitDocsIds
|
|
7
|
+
sortAndLimitDocsIds,
|
|
8
|
+
loadQuery,
|
|
9
|
+
receiveQueryError
|
|
8
10
|
} from './queries'
|
|
9
11
|
import { Q } from '../queries/dsl'
|
|
10
12
|
import { TODO_1, TODO_2, TODO_3 } from '../__tests__/fixtures'
|
|
11
13
|
|
|
12
14
|
describe('queries reducer', () => {
|
|
13
15
|
let state
|
|
14
|
-
|
|
16
|
+
const response = {
|
|
17
|
+
data: [TODO_1, TODO_2]
|
|
18
|
+
}
|
|
15
19
|
const applyAction = action => {
|
|
16
20
|
state = queries(state, action)
|
|
17
21
|
}
|
|
@@ -23,35 +27,116 @@ describe('queries reducer', () => {
|
|
|
23
27
|
Date.now.mockRestore()
|
|
24
28
|
})
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
describe('INIT_QUERY', () => {
|
|
31
|
+
it('should init correctly', () => {
|
|
32
|
+
const qdef = Q('io.cozy.todos')
|
|
33
|
+
applyAction(initQuery('a', qdef))
|
|
34
|
+
expect(state).toMatchSnapshot()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('init should have no effect after receiveQueryResult', () => {
|
|
38
|
+
const qdef = Q('io.cozy.todos')
|
|
39
|
+
applyAction(initQuery('a', qdef))
|
|
40
|
+
applyAction(receiveQueryResult('a', response))
|
|
41
|
+
let state1 = state
|
|
42
|
+
applyAction(initQuery('a', qdef))
|
|
43
|
+
expect(state1).toBe(state)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('init should not set status to loading after receiveQueryResult', () => {
|
|
47
|
+
const qdef = Q('io.cozy.todos')
|
|
48
|
+
applyAction(initQuery('a', qdef))
|
|
49
|
+
applyAction(receiveQueryResult('a', response))
|
|
50
|
+
applyAction(initQuery('a', qdef))
|
|
51
|
+
expect(state.a.fetchStatus).toBe('loaded')
|
|
52
|
+
})
|
|
30
53
|
})
|
|
31
54
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
55
|
+
describe('LOAD_QUERY', () => {
|
|
56
|
+
it('should set isFetching to true and not changing fetchStatus when query has been loaded and background fetching activated', () => {
|
|
57
|
+
// Given
|
|
58
|
+
const queryDefinition = Q('io.cozy.todos')
|
|
59
|
+
applyAction(initQuery('a', queryDefinition))
|
|
60
|
+
applyAction(receiveQueryResult('a', response))
|
|
61
|
+
expect(state.a.fetchStatus).toBe('loaded')
|
|
62
|
+
|
|
63
|
+
// When
|
|
64
|
+
applyAction(loadQuery('a', { backgroundFetching: true }))
|
|
65
|
+
|
|
66
|
+
// Then
|
|
67
|
+
expect(state.a.fetchStatus).toBe('loaded')
|
|
68
|
+
expect(state.a.isFetching).toBe(true)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('should not set isFetching and keep changing fetchStatus when query has been loaded and background fetching deactivated', () => {
|
|
72
|
+
// Given
|
|
73
|
+
const queryDefinition = Q('io.cozy.todos')
|
|
74
|
+
applyAction(initQuery('a', queryDefinition))
|
|
75
|
+
applyAction(receiveQueryResult('a', response))
|
|
76
|
+
expect(state.a.fetchStatus).toBe('loaded')
|
|
77
|
+
|
|
78
|
+
// When
|
|
79
|
+
applyAction(loadQuery('a'))
|
|
80
|
+
|
|
81
|
+
// Then
|
|
82
|
+
expect(state.a.fetchStatus).toBe('loading')
|
|
83
|
+
expect(state.a.isFetching).toBe(null)
|
|
84
|
+
})
|
|
43
85
|
})
|
|
44
86
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
87
|
+
describe('RECEIVE_QUERY_RESULT', () => {
|
|
88
|
+
it('should set isFetching to false when query has been re-fetched correctly and background fetching activated', () => {
|
|
89
|
+
// Given
|
|
90
|
+
const queryDefinition = Q('io.cozy.todos')
|
|
91
|
+
applyAction(initQuery('a', queryDefinition))
|
|
92
|
+
|
|
93
|
+
// When
|
|
94
|
+
applyAction(
|
|
95
|
+
receiveQueryResult('a', response, { backgroundFetching: true })
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
// Then
|
|
99
|
+
expect(state.a.isFetching).toBe(false)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('should set isFetching to false when query has been re-fetched correctly and background fetching deactivated', () => {
|
|
103
|
+
// Given
|
|
104
|
+
const queryDefinition = Q('io.cozy.todos')
|
|
105
|
+
applyAction(initQuery('a', queryDefinition))
|
|
106
|
+
|
|
107
|
+
// When
|
|
108
|
+
applyAction(receiveQueryResult('a', response))
|
|
109
|
+
|
|
110
|
+
// Then
|
|
111
|
+
expect(state.a.isFetching).toBe(null)
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
describe('RECEIVE_QUERY_ERROR', () => {
|
|
116
|
+
it('should set isFetching to false when query is in error and background fetching activated', () => {
|
|
117
|
+
// Given
|
|
118
|
+
const queryDefinition = Q('io.cozy.todos')
|
|
119
|
+
applyAction(initQuery('a', queryDefinition))
|
|
120
|
+
const error = {}
|
|
121
|
+
|
|
122
|
+
// When
|
|
123
|
+
applyAction(receiveQueryError('a', error, { backgroundFetching: true }))
|
|
124
|
+
|
|
125
|
+
// Then
|
|
126
|
+
expect(state.a.isFetching).toBe(false)
|
|
127
|
+
})
|
|
128
|
+
it('should not set isFetching when query is in error and background fetching deactivated', () => {
|
|
129
|
+
// Given
|
|
130
|
+
const queryDefinition = Q('io.cozy.todos')
|
|
131
|
+
applyAction(initQuery('a', queryDefinition))
|
|
132
|
+
const error = {}
|
|
133
|
+
|
|
134
|
+
// When
|
|
135
|
+
applyAction(receiveQueryError('a', error))
|
|
136
|
+
|
|
137
|
+
// Then
|
|
138
|
+
expect(state.a.isFetching).toBe(null)
|
|
139
|
+
})
|
|
55
140
|
})
|
|
56
141
|
|
|
57
142
|
describe('updates', () => {
|
package/dist/store.spec.js
CHANGED
package/dist/types.js
CHANGED
|
@@ -61,6 +61,7 @@ var _dsl = require("./queries/dsl");
|
|
|
61
61
|
* @property {string} id
|
|
62
62
|
* @property {QueryDefinition} definition
|
|
63
63
|
* @property {QueryFetchStatus} fetchStatus
|
|
64
|
+
* @property {boolean} isFetching
|
|
64
65
|
* @property {number} lastFetch
|
|
65
66
|
* @property {number} lastUpdate
|
|
66
67
|
* @property {number} lastErrorUpdate
|
|
@@ -89,6 +90,7 @@ var _dsl = require("./queries/dsl");
|
|
|
89
90
|
* @property {string} [update] - Does not seem to be used
|
|
90
91
|
* @property {Function} [onError] - Callback when the query is errored
|
|
91
92
|
* @property {boolean} [enabled=true] - If set to false, the query won't be executed
|
|
93
|
+
* @property {boolean} [backgroundFetching] - If set to true, when the fetchStatus has already been loaded, it won't be updated during future fetches. Instead, a `isFetching` attribute will be used to indicate when background fetching is started.
|
|
92
94
|
* @property {object} [hydrated=true] - Whether documents should be returned already hydrated
|
|
93
95
|
* @property {object} [singleDocData] - If true, the "data" returned will be
|
|
94
96
|
* a single doc instead of an array for single doc queries. Defaults to false for backward
|
|
@@ -158,6 +160,7 @@ var _dsl = require("./queries/dsl");
|
|
|
158
160
|
* @property {boolean} [_deleted] - When the document has been deleted
|
|
159
161
|
* @property {ReferencedByRelationship} [relationships] - Relationships of the document
|
|
160
162
|
* @property {Reference[]} [referenced_by] - referenced by of another document
|
|
163
|
+
* @property {object} [cozyMetadata] - Cozy Metadata
|
|
161
164
|
*/
|
|
162
165
|
|
|
163
166
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "32.
|
|
3
|
+
"version": "32.4.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@types/jest": "^26.0.20",
|
|
19
19
|
"@types/lodash": "^4.14.170",
|
|
20
20
|
"btoa": "^1.2.1",
|
|
21
|
-
"cozy-stack-client": "^32.3.
|
|
21
|
+
"cozy-stack-client": "^32.3.3",
|
|
22
22
|
"json-stable-stringify": "^1.0.1",
|
|
23
23
|
"lodash": "^4.17.13",
|
|
24
24
|
"microee": "^0.0.6",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@testing-library/react-hooks": "3.7.0",
|
|
48
48
|
"babel-plugin-search-and-replace": "1.1.1",
|
|
49
49
|
"btoa": "1.2.1",
|
|
50
|
-
"cozy-device-helper": "2.
|
|
50
|
+
"cozy-device-helper": "2.2.2",
|
|
51
51
|
"cozy-flags": "2.8.6",
|
|
52
52
|
"cozy-logger": "1.7.0",
|
|
53
53
|
"cozy-ui": "48.0.0",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
|
|
74
74
|
},
|
|
75
75
|
"sideEffects": false,
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "ff39c11d425e4fbc6e30c7bee4578581a7cfce00"
|
|
77
77
|
}
|
package/types/CozyClient.d.ts
CHANGED
|
@@ -8,6 +8,10 @@ export type ClientOptions = {
|
|
|
8
8
|
stackClient?: object;
|
|
9
9
|
warningForCustomHandlers?: boolean;
|
|
10
10
|
autoHydrate?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* - If set to true, backgroundFetching will be enabled by default on every query. Meaning that, when the fetchStatus has already been loaded, it won't be updated during future fetches. Instead, a `isFetching` attribute will be used to indicate when background fetching is started.
|
|
13
|
+
*/
|
|
14
|
+
backgroundFetching?: boolean;
|
|
11
15
|
oauth?: object;
|
|
12
16
|
onTokenRefresh?: Function;
|
|
13
17
|
/**
|
|
@@ -41,6 +45,7 @@ export type ClientOptions = {
|
|
|
41
45
|
* @property {object} [stackClient]
|
|
42
46
|
* @property {boolean} [warningForCustomHandlers]
|
|
43
47
|
* @property {boolean} [autoHydrate]
|
|
48
|
+
* @property {boolean} [backgroundFetching] - If set to true, backgroundFetching will be enabled by default on every query. Meaning that, when the fetchStatus has already been loaded, it won't be updated during future fetches. Instead, a `isFetching` attribute will be used to indicate when background fetching is started.
|
|
44
49
|
* @property {object} [oauth]
|
|
45
50
|
* @property {Function} [onTokenRefresh]
|
|
46
51
|
* @property {Function} [onError] - Default callback if a query is errored
|
|
@@ -148,6 +153,10 @@ declare class CozyClient {
|
|
|
148
153
|
stackClient?: object;
|
|
149
154
|
warningForCustomHandlers?: boolean;
|
|
150
155
|
autoHydrate?: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* - If set to true, backgroundFetching will be enabled by default on every query. Meaning that, when the fetchStatus has already been loaded, it won't be updated during future fetches. Instead, a `isFetching` attribute will be used to indicate when background fetching is started.
|
|
158
|
+
*/
|
|
159
|
+
backgroundFetching?: boolean;
|
|
151
160
|
oauth?: object;
|
|
152
161
|
onTokenRefresh?: Function;
|
|
153
162
|
/**
|
|
@@ -343,9 +352,15 @@ declare class CozyClient {
|
|
|
343
352
|
update?: Function;
|
|
344
353
|
updateQueries?: Function;
|
|
345
354
|
}): Promise<void>;
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
355
|
+
/**
|
|
356
|
+
* @param {CozyClientDocument} document - Document that will be saved
|
|
357
|
+
* @param {object} [options={event: DOC_CREATION}] - Event
|
|
358
|
+
* @param {string} [options.event] - Mutation type
|
|
359
|
+
* @returns {CozyClientDocument}
|
|
360
|
+
*/
|
|
361
|
+
ensureCozyMetadata(document: CozyClientDocument, options?: {
|
|
362
|
+
event?: string;
|
|
363
|
+
}): CozyClientDocument;
|
|
349
364
|
/**
|
|
350
365
|
* Dehydrates and adds metadata before saving a document
|
|
351
366
|
*
|
|
@@ -367,14 +382,14 @@ declare class CozyClient {
|
|
|
367
382
|
* ```
|
|
368
383
|
*
|
|
369
384
|
*
|
|
370
|
-
* @param {
|
|
385
|
+
* @param {CozyClientDocument} document - Document to create
|
|
371
386
|
* @param {ReferenceMap} [referencesByName] - References to the created document. The
|
|
372
387
|
* relationship class associated to each reference list should support references, otherwise this
|
|
373
388
|
* method will throw.
|
|
374
389
|
*
|
|
375
390
|
* @returns {Mutation[]|Mutation} One or more mutation to execute
|
|
376
391
|
*/
|
|
377
|
-
getDocumentSavePlan(document:
|
|
392
|
+
getDocumentSavePlan(document: CozyClientDocument, referencesByName?: ReferenceMap): Mutation[] | Mutation;
|
|
378
393
|
triggerHook(name: any, document: any): void;
|
|
379
394
|
/**
|
|
380
395
|
* Destroys a document. {before,after}:destroy hooks will be fired.
|
|
@@ -549,9 +564,14 @@ declare class CozyClient {
|
|
|
549
564
|
* Has a behavior close to <Query /> or useQuery
|
|
550
565
|
*
|
|
551
566
|
* @param {object} query - Query with definition and options
|
|
567
|
+
* @param {QueryDefinition} query.definition - Query Definition
|
|
568
|
+
* @param {QueryOptions} query.options - Query Options
|
|
552
569
|
* @returns {Promise<QueryState>} Query state
|
|
553
570
|
*/
|
|
554
|
-
fetchQueryAndGetFromState: (
|
|
571
|
+
fetchQueryAndGetFromState: ({ definition, options }: {
|
|
572
|
+
definition: QueryDefinition;
|
|
573
|
+
options: QueryOptions;
|
|
574
|
+
}) => Promise<QueryState>;
|
|
555
575
|
/**
|
|
556
576
|
* Performs a complete OAuth flow using a Cordova webview
|
|
557
577
|
* or React Native WebView for auth.
|
|
@@ -7,3 +7,5 @@
|
|
|
7
7
|
* @returns {Promise<AttestationResult>} the app's attestation
|
|
8
8
|
*/
|
|
9
9
|
export function getAppAttestationFromStore(nonce: string, certificationConfig: CertificationConfig): Promise<AttestationResult>;
|
|
10
|
+
import { CertificationConfig } from "./typedefs";
|
|
11
|
+
import { AttestationResult } from "./typedefs";
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
declare var _default: {};
|
|
2
|
+
export default _default;
|
|
1
3
|
/**
|
|
2
4
|
* - A JSON Web Signature
|
|
3
5
|
*/
|
|
4
|
-
type jws = string;
|
|
6
|
+
export type jws = string;
|
|
5
7
|
/**
|
|
6
8
|
* - A JSON Web Signature
|
|
7
9
|
*/
|
|
8
|
-
type base64string = string;
|
|
10
|
+
export type base64string = string;
|
|
9
11
|
/**
|
|
10
12
|
* - An app attestation from the app store
|
|
11
13
|
*/
|
|
12
|
-
type AttestationResult = {
|
|
14
|
+
export type AttestationResult = {
|
|
13
15
|
platform: string;
|
|
14
16
|
attestation: jws | base64string;
|
|
15
17
|
keyId?: string;
|
|
@@ -17,6 +19,6 @@ type AttestationResult = {
|
|
|
17
19
|
/**
|
|
18
20
|
* - Configuration to access the stores certification API
|
|
19
21
|
*/
|
|
20
|
-
type CertificationConfig = {
|
|
22
|
+
export type CertificationConfig = {
|
|
21
23
|
androidSafetyNetApiKey: string;
|
|
22
24
|
};
|
package/types/store/queries.d.ts
CHANGED
|
@@ -8,26 +8,10 @@ export function convert$gtNullSelectors(selector: any): object;
|
|
|
8
8
|
export function mergeSelectorAndPartialIndex(queryDefinition: object): object;
|
|
9
9
|
export function makeSorterFromDefinition(definition: QueryDefinition): (arg0: Array<CozyClientDocument>) => Array<CozyClientDocument>;
|
|
10
10
|
export default queries;
|
|
11
|
-
export function initQuery(queryId: string, queryDefinition: QueryDefinition, options?: QueryOptions):
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
options: QueryOptions;
|
|
16
|
-
};
|
|
17
|
-
export function loadQuery(queryId: any): {
|
|
18
|
-
type: string;
|
|
19
|
-
queryId: any;
|
|
20
|
-
};
|
|
21
|
-
export function receiveQueryResult(queryId: any, response: any, options?: {}): {
|
|
22
|
-
type: string;
|
|
23
|
-
queryId: any;
|
|
24
|
-
response: any;
|
|
25
|
-
};
|
|
26
|
-
export function receiveQueryError(queryId: any, error: any): {
|
|
27
|
-
type: string;
|
|
28
|
-
queryId: any;
|
|
29
|
-
error: any;
|
|
30
|
-
};
|
|
11
|
+
export function initQuery(queryId: string, queryDefinition: QueryDefinition, options?: QueryOptions): object;
|
|
12
|
+
export function loadQuery(queryId: string, options?: QueryOptions): object;
|
|
13
|
+
export function receiveQueryResult(queryId: string, response: object, options?: QueryOptions): object;
|
|
14
|
+
export function receiveQueryError(queryId: string, error: object, options?: QueryOptions): object;
|
|
31
15
|
export function getQueryFromSlice(state: any, queryId: any, documents: any): any;
|
|
32
16
|
export class QueryIDGenerator {
|
|
33
17
|
idCounter: number;
|
package/types/types.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export type QueryState = {
|
|
|
35
35
|
id: string;
|
|
36
36
|
definition: QueryDefinition;
|
|
37
37
|
fetchStatus: QueryFetchStatus;
|
|
38
|
+
isFetching: boolean;
|
|
38
39
|
lastFetch: number;
|
|
39
40
|
lastUpdate: number;
|
|
40
41
|
lastErrorUpdate: number;
|
|
@@ -73,6 +74,10 @@ export type QueryOptions = {
|
|
|
73
74
|
* - If set to false, the query won't be executed
|
|
74
75
|
*/
|
|
75
76
|
enabled?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* - If set to true, when the fetchStatus has already been loaded, it won't be updated during future fetches. Instead, a `isFetching` attribute will be used to indicate when background fetching is started.
|
|
79
|
+
*/
|
|
80
|
+
backgroundFetching?: boolean;
|
|
76
81
|
/**
|
|
77
82
|
* - Whether documents should be returned already hydrated
|
|
78
83
|
*/
|
|
@@ -164,6 +169,10 @@ export type CozyClientDocument = {
|
|
|
164
169
|
* - referenced by of another document
|
|
165
170
|
*/
|
|
166
171
|
referenced_by?: Reference[];
|
|
172
|
+
/**
|
|
173
|
+
* - Cozy Metadata
|
|
174
|
+
*/
|
|
175
|
+
cozyMetadata?: object;
|
|
167
176
|
};
|
|
168
177
|
/**
|
|
169
178
|
* - An io.cozy.files document
|