cozy-client 60.0.0 → 60.1.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.
@@ -723,13 +723,15 @@ var CozyClient = /*#__PURE__*/function () {
723
723
  * a [DocumentCollection]{@link https://docs.cozy.io/en/cozy-client/api/cozy-stack-client/#DocumentCollection} instance.
724
724
  *
725
725
  * @param {string} doctype The collection doctype.
726
+ * @param {object} options Options to pass to the collection
726
727
  * @returns {import("./types").DocumentCollection} Collection corresponding to the doctype
727
728
  */
728
729
 
729
730
  }, {
730
731
  key: "collection",
731
732
  value: function collection(doctype) {
732
- return this.getStackClient().collection(doctype);
733
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
734
+ return this.getStackClient().collection(doctype, options);
733
735
  }
734
736
  }, {
735
737
  key: "fetch",
@@ -1205,7 +1207,11 @@ var CozyClient = /*#__PURE__*/function () {
1205
1207
  }
1206
1208
 
1207
1209
  return [saveMutation, function (response) {
1208
- var doc = _this3.hydrateDocument(response.data);
1210
+ var schema = _this3.schema.getDoctypeSchema(response.data._type);
1211
+
1212
+ var doc = _this3.hydrateDocument(response.data, schema, {
1213
+ forceHydratation: true
1214
+ });
1209
1215
 
1210
1216
  return Object.entries(referencesByName).map(function (_ref3) {
1211
1217
  var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
@@ -1804,169 +1810,6 @@ var CozyClient = /*#__PURE__*/function () {
1804
1810
 
1805
1811
  return requestQuery;
1806
1812
  }()
1807
- /**
1808
- * Save the document or array of documents into the persisted storage (if any)
1809
- *
1810
- * @private
1811
- * @param {CozyClientDocument | Array<CozyClientDocument>} data - Document or array of documents to be saved
1812
- * @returns {Promise<void>}
1813
- */
1814
-
1815
- }, {
1816
- key: "persistVirtualDocuments",
1817
- value: function () {
1818
- var _persistVirtualDocuments = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15(definition, data) {
1819
- var enforceList, enforce, documentsToPersist, _iterator5, _step5, _document;
1820
-
1821
- return _regenerator.default.wrap(function _callee15$(_context15) {
1822
- while (1) {
1823
- switch (_context15.prev = _context15.next) {
1824
- case 0:
1825
- enforceList = ['io.cozy.files.shortcuts'];
1826
- enforce = enforceList.includes(definition.doctype);
1827
-
1828
- if (!(definition.doctype === 'io.cozy.apps_registry')) {
1829
- _context15.next = 6;
1830
- break;
1831
- }
1832
-
1833
- _context15.next = 5;
1834
- return this.persistVirtualDocument({
1835
- _type: 'io.cozy.apps_registry',
1836
- _id: definition.id,
1837
- // @ts-ignore
1838
- cozyPouchData: data
1839
- }, enforce);
1840
-
1841
- case 5:
1842
- return _context15.abrupt("return", _context15.sent);
1843
-
1844
- case 6:
1845
- if (Array.isArray(data)) {
1846
- _context15.next = 11;
1847
- break;
1848
- }
1849
-
1850
- _context15.next = 9;
1851
- return this.persistVirtualDocument(data, enforce);
1852
-
1853
- case 9:
1854
- _context15.next = 29;
1855
- break;
1856
-
1857
- case 11:
1858
- documentsToPersist = data.filter(function (document) {
1859
- var _document$meta;
1860
-
1861
- if (!document || document.cozyLocalOnly) {
1862
- return false;
1863
- }
1864
-
1865
- if (!((_document$meta = document.meta) !== null && _document$meta !== void 0 && _document$meta.rev) && !document._rev || enforce) {
1866
- return true;
1867
- }
1868
-
1869
- return false;
1870
- });
1871
- _iterator5 = _createForOfIteratorHelper(documentsToPersist);
1872
- _context15.prev = 13;
1873
-
1874
- _iterator5.s();
1875
-
1876
- case 15:
1877
- if ((_step5 = _iterator5.n()).done) {
1878
- _context15.next = 21;
1879
- break;
1880
- }
1881
-
1882
- _document = _step5.value;
1883
- _context15.next = 19;
1884
- return this.persistVirtualDocument(_document, enforce);
1885
-
1886
- case 19:
1887
- _context15.next = 15;
1888
- break;
1889
-
1890
- case 21:
1891
- _context15.next = 26;
1892
- break;
1893
-
1894
- case 23:
1895
- _context15.prev = 23;
1896
- _context15.t0 = _context15["catch"](13);
1897
-
1898
- _iterator5.e(_context15.t0);
1899
-
1900
- case 26:
1901
- _context15.prev = 26;
1902
-
1903
- _iterator5.f();
1904
-
1905
- return _context15.finish(26);
1906
-
1907
- case 29:
1908
- case "end":
1909
- return _context15.stop();
1910
- }
1911
- }
1912
- }, _callee15, this, [[13, 23, 26, 29]]);
1913
- }));
1914
-
1915
- function persistVirtualDocuments(_x17, _x18) {
1916
- return _persistVirtualDocuments.apply(this, arguments);
1917
- }
1918
-
1919
- return persistVirtualDocuments;
1920
- }()
1921
- /**
1922
- * Save the document or array of documents into the persisted storage (if any)
1923
- *
1924
- * @private
1925
- * @param {CozyClientDocument} document - Document to be saved
1926
- * @param {boolean} enforce - When true, save the document even if `meta.rev` or `_rev` exist
1927
- * @returns {Promise<void>}
1928
- */
1929
-
1930
- }, {
1931
- key: "persistVirtualDocument",
1932
- value: function () {
1933
- var _persistVirtualDocument = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16(document, enforce) {
1934
- var _document$meta2;
1935
-
1936
- return _regenerator.default.wrap(function _callee16$(_context16) {
1937
- while (1) {
1938
- switch (_context16.prev = _context16.next) {
1939
- case 0:
1940
- if (!(!document || document.cozyLocalOnly)) {
1941
- _context16.next = 2;
1942
- break;
1943
- }
1944
-
1945
- return _context16.abrupt("return");
1946
-
1947
- case 2:
1948
- if (!(!((_document$meta2 = document.meta) !== null && _document$meta2 !== void 0 && _document$meta2.rev) && !document._rev || enforce)) {
1949
- _context16.next = 5;
1950
- break;
1951
- }
1952
-
1953
- _context16.next = 5;
1954
- return this.chain.persistCozyData(document);
1955
-
1956
- case 5:
1957
- case "end":
1958
- return _context16.stop();
1959
- }
1960
- }
1961
- }, _callee16, this);
1962
- }));
1963
-
1964
- function persistVirtualDocument(_x19, _x20) {
1965
- return _persistVirtualDocument.apply(this, arguments);
1966
- }
1967
-
1968
- return persistVirtualDocument;
1969
- }()
1970
1813
  /**
1971
1814
  * Fetch relationships for a response (can be several docs).
1972
1815
  * Fills the `relationships` attribute of each documents.
@@ -1981,23 +1824,23 @@ var CozyClient = /*#__PURE__*/function () {
1981
1824
  }, {
1982
1825
  key: "fetchRelationships",
1983
1826
  value: function () {
1984
- var _fetchRelationships = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee17(response, relationshipsByName) {
1827
+ var _fetchRelationships = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15(response, relationshipsByName) {
1985
1828
  var _this5 = this;
1986
1829
 
1987
- var isSingleDoc, responseDocs, queryDefToDocIdAndRel, documents, definitions, optimizedDefinitions, responses, uniqueDocuments, included, relationshipsByDocId, _iterator6, _step6, _step6$value, def, resp, docIdAndRel, _docIdAndRel, docId, relName;
1830
+ var isSingleDoc, responseDocs, queryDefToDocIdAndRel, documents, definitions, optimizedDefinitions, responses, uniqueDocuments, included, relationshipsByDocId, _iterator5, _step5, _step5$value, def, resp, docIdAndRel, _docIdAndRel, docId, relName;
1988
1831
 
1989
- return _regenerator.default.wrap(function _callee17$(_context17) {
1832
+ return _regenerator.default.wrap(function _callee15$(_context15) {
1990
1833
  while (1) {
1991
- switch (_context17.prev = _context17.next) {
1834
+ switch (_context15.prev = _context15.next) {
1992
1835
  case 0:
1993
1836
  isSingleDoc = !Array.isArray(response.data);
1994
1837
 
1995
1838
  if (!(!isSingleDoc && response.data.length === 0)) {
1996
- _context17.next = 3;
1839
+ _context15.next = 3;
1997
1840
  break;
1998
1841
  }
1999
1842
 
2000
- return _context17.abrupt("return", response);
1843
+ return _context15.abrupt("return", response);
2001
1844
 
2002
1845
  case 3:
2003
1846
  responseDocs = isSingleDoc ? [response.data] : response.data;
@@ -2027,13 +1870,13 @@ var CozyClient = /*#__PURE__*/function () {
2027
1870
  }); // Definitions can be in optimized/regrouped in case of HasMany relationships.
2028
1871
 
2029
1872
  optimizedDefinitions = (0, _optimize.default)(definitions);
2030
- _context17.next = 11;
1873
+ _context15.next = 11;
2031
1874
  return Promise.all(optimizedDefinitions.map(function (req) {
2032
1875
  return _this5.chain.request(req);
2033
1876
  }));
2034
1877
 
2035
1878
  case 11:
2036
- responses = _context17.sent;
1879
+ responses = _context15.sent;
2037
1880
  // "Included" documents will be stored in the `documents` store
2038
1881
  uniqueDocuments = (0, _uniqBy.default)((0, _flatten.default)(documents), '_id');
2039
1882
  included = (0, _flatten.default)(responses.map(function (r) {
@@ -2046,11 +1889,11 @@ var CozyClient = /*#__PURE__*/function () {
2046
1889
  // storing the document. This makes the data easier to manipulate for the front-end.
2047
1890
 
2048
1891
  relationshipsByDocId = {};
2049
- _iterator6 = _createForOfIteratorHelper((0, _zip.default)(optimizedDefinitions, responses));
1892
+ _iterator5 = _createForOfIteratorHelper((0, _zip.default)(optimizedDefinitions, responses));
2050
1893
 
2051
1894
  try {
2052
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
2053
- _step6$value = (0, _slicedToArray2.default)(_step6.value, 2), def = _step6$value[0], resp = _step6$value[1];
1895
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1896
+ _step5$value = (0, _slicedToArray2.default)(_step5.value, 2), def = _step5$value[0], resp = _step5$value[1];
2054
1897
  docIdAndRel = queryDefToDocIdAndRel.get(def);
2055
1898
 
2056
1899
  if (docIdAndRel) {
@@ -2060,24 +1903,24 @@ var CozyClient = /*#__PURE__*/function () {
2060
1903
  }
2061
1904
  }
2062
1905
  } catch (err) {
2063
- _iterator6.e(err);
1906
+ _iterator5.e(err);
2064
1907
  } finally {
2065
- _iterator6.f();
1908
+ _iterator5.f();
2066
1909
  }
2067
1910
 
2068
- return _context17.abrupt("return", _objectSpread(_objectSpread({}, (0, _helpers.attachRelationships)(response, relationshipsByDocId)), {}, {
1911
+ return _context15.abrupt("return", _objectSpread(_objectSpread({}, (0, _helpers.attachRelationships)(response, relationshipsByDocId)), {}, {
2069
1912
  included: included
2070
1913
  }));
2071
1914
 
2072
1915
  case 18:
2073
1916
  case "end":
2074
- return _context17.stop();
1917
+ return _context15.stop();
2075
1918
  }
2076
1919
  }
2077
- }, _callee17);
1920
+ }, _callee15);
2078
1921
  }));
2079
1922
 
2080
- function fetchRelationships(_x21, _x22) {
1923
+ function fetchRelationships(_x17, _x18) {
2081
1924
  return _fetchRelationships.apply(this, arguments);
2082
1925
  }
2083
1926
 
@@ -2086,47 +1929,47 @@ var CozyClient = /*#__PURE__*/function () {
2086
1929
  }, {
2087
1930
  key: "requestMutation",
2088
1931
  value: function () {
2089
- var _requestMutation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee18(definition, options) {
1932
+ var _requestMutation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16(definition, options) {
2090
1933
  var _this6 = this;
2091
1934
 
2092
1935
  var _definition, first, rest, firstResponse;
2093
1936
 
2094
- return _regenerator.default.wrap(function _callee18$(_context18) {
1937
+ return _regenerator.default.wrap(function _callee16$(_context16) {
2095
1938
  while (1) {
2096
- switch (_context18.prev = _context18.next) {
1939
+ switch (_context16.prev = _context16.next) {
2097
1940
  case 0:
2098
1941
  if (!Array.isArray(definition)) {
2099
- _context18.next = 8;
1942
+ _context16.next = 8;
2100
1943
  break;
2101
1944
  }
2102
1945
 
2103
1946
  _definition = (0, _toArray2.default)(definition), first = _definition[0], rest = _definition.slice(1);
2104
- _context18.next = 4;
1947
+ _context16.next = 4;
2105
1948
  return this.requestMutation(first);
2106
1949
 
2107
1950
  case 4:
2108
- firstResponse = _context18.sent;
2109
- _context18.next = 7;
1951
+ firstResponse = _context16.sent;
1952
+ _context16.next = 7;
2110
1953
  return Promise.all(rest.map(function (def) {
2111
1954
  var mutationDef = typeof def === 'function' ? def(firstResponse) : def;
2112
1955
  return _this6.requestMutation(mutationDef);
2113
1956
  }));
2114
1957
 
2115
1958
  case 7:
2116
- return _context18.abrupt("return", firstResponse);
1959
+ return _context16.abrupt("return", firstResponse);
2117
1960
 
2118
1961
  case 8:
2119
- return _context18.abrupt("return", this.chain.request(definition, options));
1962
+ return _context16.abrupt("return", this.chain.request(definition, options));
2120
1963
 
2121
1964
  case 9:
2122
1965
  case "end":
2123
- return _context18.stop();
1966
+ return _context16.stop();
2124
1967
  }
2125
1968
  }
2126
- }, _callee18, this);
1969
+ }, _callee16, this);
2127
1970
  }));
2128
1971
 
2129
- function requestMutation(_x23, _x24) {
1972
+ function requestMutation(_x19, _x20) {
2130
1973
  return _requestMutation.apply(this, arguments);
2131
1974
  }
2132
1975
 
@@ -2151,6 +1994,8 @@ var CozyClient = /*#__PURE__*/function () {
2151
1994
  *
2152
1995
  * @param {string} doctype - Doctype of the documents being hydrated
2153
1996
  * @param {Array<import("./types").CozyClientDocument>} documents - Documents to be hydrated
1997
+ * @param {object} [options] - Options
1998
+ * @param {boolean} [options.forceHydratation=false] - If set to true, all documents will be hydrated w.r.t. the provided schema's relationships, even if the relationship does not exist on the doc.
2154
1999
  * @returns {Array<import("./types").HydratedDocument>}
2155
2000
  */
2156
2001
 
@@ -2159,12 +2004,18 @@ var CozyClient = /*#__PURE__*/function () {
2159
2004
  value: function hydrateDocuments(doctype, documents) {
2160
2005
  var _this8 = this;
2161
2006
 
2007
+ var _ref7 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
2008
+ _ref7$forceHydratatio = _ref7.forceHydratation,
2009
+ forceHydratation = _ref7$forceHydratatio === void 0 ? false : _ref7$forceHydratatio;
2010
+
2162
2011
  var schema = this.schema.getDoctypeSchema(doctype);
2163
2012
  var relationships = schema.relationships;
2164
2013
 
2165
2014
  if (relationships) {
2166
2015
  return documents.map(function (doc) {
2167
- return _this8.hydrateDocument(doc, schema);
2016
+ return _this8.hydrateDocument(doc, schema, {
2017
+ forceHydratation: forceHydratation
2018
+ });
2168
2019
  });
2169
2020
  } else {
2170
2021
  return documents;
@@ -2177,31 +2028,42 @@ var CozyClient = /*#__PURE__*/function () {
2177
2028
  * the relationship
2178
2029
  *
2179
2030
  * @param {import("./types").CozyClientDocument} document - for which relationships must be resolved
2180
- * @param {Schema} [schemaArg] - Optional
2031
+ * @param {Schema} [schemaArg] - The schema describing the relationships
2032
+ * @param {object} [options] - Options
2033
+ * @param {boolean} [options.forceHydratation=false] - If set to true, the doc will be hydrated w.r.t. the provided schema's relationships, even if the relationship does not exist on the doc.
2181
2034
  * @returns {import("./types").HydratedDocument}
2182
2035
  */
2183
2036
 
2184
2037
  }, {
2185
2038
  key: "hydrateDocument",
2186
2039
  value: function hydrateDocument(document, schemaArg) {
2040
+ var _ref8 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
2041
+ _ref8$forceHydratatio = _ref8.forceHydratation,
2042
+ forceHydratation = _ref8$forceHydratatio === void 0 ? false : _ref8$forceHydratatio;
2043
+
2187
2044
  if (!document) {
2188
2045
  return document;
2189
2046
  }
2190
2047
 
2191
2048
  var schema = schemaArg || this.schema.getDoctypeSchema(document._type);
2192
- var hydratedRelationships = this.hydrateRelationships(document, schema.relationships);
2049
+ var shouldForceHydrate = this.options.autoHydrate || forceHydratation;
2050
+ var hydratedRelationships = this.hydrateRelationships(document, schema.relationships, {
2051
+ forceHydratation: shouldForceHydrate
2052
+ });
2193
2053
  return _objectSpread(_objectSpread({}, document), hydratedRelationships);
2194
2054
  }
2195
2055
  }, {
2196
2056
  key: "hydrateRelationships",
2197
2057
  value: function hydrateRelationships(document, schemaRelationships) {
2198
- var _this9 = this;
2058
+ var _ref9 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
2059
+ _ref9$forceHydratatio = _ref9.forceHydratation,
2060
+ forceHydratation = _ref9$forceHydratatio === void 0 ? false : _ref9$forceHydratatio;
2199
2061
 
2200
2062
  var methods = this.getRelationshipStoreAccessors();
2201
2063
  return (0, _mapValues.default)(schemaRelationships, function (assoc, name) {
2202
- var _this9$options, _document$relationshi;
2064
+ var _document$relationshi;
2203
2065
 
2204
- if ((_this9$options = _this9.options) !== null && _this9$options !== void 0 && _this9$options.autoHydrate || (_document$relationshi = document.relationships) !== null && _document$relationshi !== void 0 && _document$relationshi[name]) {
2066
+ if (forceHydratation || (_document$relationshi = document.relationships) !== null && _document$relationshi !== void 0 && _document$relationshi[name]) {
2205
2067
  return (0, _associations.create)(document, assoc, methods);
2206
2068
  }
2207
2069
  });
@@ -2232,20 +2094,20 @@ var CozyClient = /*#__PURE__*/function () {
2232
2094
  }, {
2233
2095
  key: "getRelationshipStoreAccessors",
2234
2096
  value: function getRelationshipStoreAccessors() {
2235
- var _this10 = this;
2097
+ var _this9 = this;
2236
2098
 
2237
2099
  if (!this.storeAccesors) {
2238
2100
  this.storeAccessors = {
2239
2101
  get: this.getDocumentFromState.bind(this),
2240
2102
  save: function save(document, opts) {
2241
- return _this10.save.call(_this10, document, opts);
2103
+ return _this9.save.call(_this9, document, opts);
2242
2104
  },
2243
2105
  dispatch: this.dispatch.bind(this),
2244
2106
  query: function query(def, opts) {
2245
- return _this10.query.call(_this10, def, opts);
2107
+ return _this9.query.call(_this9, def, opts);
2246
2108
  },
2247
2109
  mutate: function mutate(def, opts) {
2248
- return _this10.mutate.call(_this10, def, opts);
2110
+ return _this9.mutate.call(_this9, def, opts);
2249
2111
  }
2250
2112
  };
2251
2113
  }
@@ -2384,34 +2246,34 @@ var CozyClient = /*#__PURE__*/function () {
2384
2246
  }, {
2385
2247
  key: "startOAuthFlow",
2386
2248
  value: function () {
2387
- var _startOAuthFlow = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee19(openURLCallback) {
2249
+ var _startOAuthFlow = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee17(openURLCallback) {
2388
2250
  var stackClient;
2389
- return _regenerator.default.wrap(function _callee19$(_context19) {
2251
+ return _regenerator.default.wrap(function _callee17$(_context17) {
2390
2252
  while (1) {
2391
- switch (_context19.prev = _context19.next) {
2253
+ switch (_context17.prev = _context17.next) {
2392
2254
  case 0:
2393
2255
  stackClient = this.getStackClient();
2394
- _context19.next = 3;
2256
+ _context17.next = 3;
2395
2257
  return stackClient.register();
2396
2258
 
2397
2259
  case 3:
2398
- _context19.next = 5;
2260
+ _context17.next = 5;
2399
2261
  return this.certifyFlagship();
2400
2262
 
2401
2263
  case 5:
2402
- return _context19.abrupt("return", this.authorize({
2264
+ return _context17.abrupt("return", this.authorize({
2403
2265
  openURLCallback: openURLCallback
2404
2266
  }));
2405
2267
 
2406
2268
  case 6:
2407
2269
  case "end":
2408
- return _context19.stop();
2270
+ return _context17.stop();
2409
2271
  }
2410
2272
  }
2411
- }, _callee19, this);
2273
+ }, _callee17, this);
2412
2274
  }));
2413
2275
 
2414
- function startOAuthFlow(_x25) {
2276
+ function startOAuthFlow(_x21) {
2415
2277
  return _startOAuthFlow.apply(this, arguments);
2416
2278
  }
2417
2279
 
@@ -2426,28 +2288,28 @@ var CozyClient = /*#__PURE__*/function () {
2426
2288
  }, {
2427
2289
  key: "certifyFlagship",
2428
2290
  value: function () {
2429
- var _certifyFlagship2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee20() {
2291
+ var _certifyFlagship2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee18() {
2430
2292
  var stackClient;
2431
- return _regenerator.default.wrap(function _callee20$(_context20) {
2293
+ return _regenerator.default.wrap(function _callee18$(_context18) {
2432
2294
  while (1) {
2433
- switch (_context20.prev = _context20.next) {
2295
+ switch (_context18.prev = _context18.next) {
2434
2296
  case 0:
2435
2297
  stackClient = this.getStackClient();
2436
2298
 
2437
2299
  if (!stackClient.oauthOptions.shouldRequireFlagshipPermissions) {
2438
- _context20.next = 4;
2300
+ _context18.next = 4;
2439
2301
  break;
2440
2302
  }
2441
2303
 
2442
- _context20.next = 4;
2304
+ _context18.next = 4;
2443
2305
  return (0, _flagshipCertification.certifyFlagship)(stackClient.oauthOptions.certificationConfig, this);
2444
2306
 
2445
2307
  case 4:
2446
2308
  case "end":
2447
- return _context20.stop();
2309
+ return _context18.stop();
2448
2310
  }
2449
2311
  }
2450
- }, _callee20, this);
2312
+ }, _callee18, this);
2451
2313
  }));
2452
2314
 
2453
2315
  function certifyFlagship() {
@@ -2471,13 +2333,13 @@ var CozyClient = /*#__PURE__*/function () {
2471
2333
  }, {
2472
2334
  key: "authorize",
2473
2335
  value: function () {
2474
- var _authorize = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee21() {
2475
- var _ref7,
2476
- _ref7$openURLCallback,
2336
+ var _authorize = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee19() {
2337
+ var _ref10,
2338
+ _ref10$openURLCallbac,
2477
2339
  openURLCallback,
2478
- _ref7$sessionCode,
2340
+ _ref10$sessionCode,
2479
2341
  sessionCode,
2480
- _ref7$pkceCodes,
2342
+ _ref10$pkceCodes,
2481
2343
  pkceCodes,
2482
2344
  codeVerifier,
2483
2345
  codeChallenge,
@@ -2488,14 +2350,14 @@ var CozyClient = /*#__PURE__*/function () {
2488
2350
  code,
2489
2351
  token,
2490
2352
  _stackClient,
2491
- _args21 = arguments;
2353
+ _args19 = arguments;
2492
2354
 
2493
- return _regenerator.default.wrap(function _callee21$(_context21) {
2355
+ return _regenerator.default.wrap(function _callee19$(_context19) {
2494
2356
  while (1) {
2495
- switch (_context21.prev = _context21.next) {
2357
+ switch (_context19.prev = _context19.next) {
2496
2358
  case 0:
2497
- _ref7 = _args21.length > 0 && _args21[0] !== undefined ? _args21[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;
2498
- _context21.prev = 1;
2359
+ _ref10 = _args19.length > 0 && _args19[0] !== undefined ? _args19[0] : {}, _ref10$openURLCallbac = _ref10.openURLCallback, openURLCallback = _ref10$openURLCallbac === void 0 ? _mobile.authFunction : _ref10$openURLCallbac, _ref10$sessionCode = _ref10.sessionCode, sessionCode = _ref10$sessionCode === void 0 ? undefined : _ref10$sessionCode, _ref10$pkceCodes = _ref10.pkceCodes, pkceCodes = _ref10$pkceCodes === void 0 ? {} : _ref10$pkceCodes;
2360
+ _context19.prev = 1;
2499
2361
  codeVerifier = pkceCodes.codeVerifier, codeChallenge = pkceCodes.codeChallenge;
2500
2362
  stackClient = this.getStackClient();
2501
2363
  stateCode = stackClient.generateStateCode();
@@ -2505,19 +2367,19 @@ var CozyClient = /*#__PURE__*/function () {
2505
2367
  sessionCode: sessionCode,
2506
2368
  codeChallenge: codeChallenge
2507
2369
  });
2508
- _context21.next = 8;
2370
+ _context19.next = 8;
2509
2371
  return openURLCallback(url);
2510
2372
 
2511
2373
  case 8:
2512
- redirectedURL = _context21.sent;
2374
+ redirectedURL = _context19.sent;
2513
2375
  code = stackClient.getAccessCodeFromURL(redirectedURL, stateCode);
2514
- _context21.next = 12;
2376
+ _context19.next = 12;
2515
2377
  return stackClient.fetchAccessToken(code, undefined, undefined, codeVerifier);
2516
2378
 
2517
2379
  case 12:
2518
- token = _context21.sent;
2380
+ token = _context19.sent;
2519
2381
  stackClient.setToken(token);
2520
- return _context21.abrupt("return", {
2382
+ return _context19.abrupt("return", {
2521
2383
  token: token,
2522
2384
  infos: stackClient.oauthOptions,
2523
2385
  client: stackClient.oauthOptions // for compat with Authentication comp reasons
@@ -2525,24 +2387,24 @@ var CozyClient = /*#__PURE__*/function () {
2525
2387
  });
2526
2388
 
2527
2389
  case 17:
2528
- _context21.prev = 17;
2529
- _context21.t0 = _context21["catch"](1);
2390
+ _context19.prev = 17;
2391
+ _context19.t0 = _context19["catch"](1);
2530
2392
 
2531
2393
  /* if REGISTRATION_ABORT is emited, we have to unregister the client. */
2532
- if (_context21.t0.message === _const.REGISTRATION_ABORT) {
2394
+ if (_context19.t0.message === _const.REGISTRATION_ABORT) {
2533
2395
  _stackClient = this.getStackClient();
2534
2396
 
2535
2397
  _stackClient.unregister();
2536
2398
  }
2537
2399
 
2538
- throw _context21.t0;
2400
+ throw _context19.t0;
2539
2401
 
2540
2402
  case 21:
2541
2403
  case "end":
2542
- return _context21.stop();
2404
+ return _context19.stop();
2543
2405
  }
2544
2406
  }
2545
- }, _callee21, this, [[1, 17]]);
2407
+ }, _callee19, this, [[1, 17]]);
2546
2408
  }));
2547
2409
 
2548
2410
  function authorize() {
@@ -2591,9 +2453,9 @@ var CozyClient = /*#__PURE__*/function () {
2591
2453
  }, {
2592
2454
  key: "setStore",
2593
2455
  value: function setStore(store) {
2594
- var _ref8 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
2595
- _ref8$force = _ref8.force,
2596
- force = _ref8$force === void 0 ? false : _ref8$force;
2456
+ var _ref11 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
2457
+ _ref11$force = _ref11.force,
2458
+ force = _ref11$force === void 0 ? false : _ref11$force;
2597
2459
 
2598
2460
  if (store === undefined) {
2599
2461
  throw new Error('Store is undefined');
@@ -2617,27 +2479,27 @@ var CozyClient = /*#__PURE__*/function () {
2617
2479
  }, {
2618
2480
  key: "checkForRevocation",
2619
2481
  value: function () {
2620
- var _checkForRevocation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee22() {
2621
- return _regenerator.default.wrap(function _callee22$(_context22) {
2482
+ var _checkForRevocation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee20() {
2483
+ return _regenerator.default.wrap(function _callee20$(_context20) {
2622
2484
  while (1) {
2623
- switch (_context22.prev = _context22.next) {
2485
+ switch (_context20.prev = _context20.next) {
2624
2486
  case 0:
2625
2487
  if (!(this.stackClient instanceof _cozyStackClient.OAuthClient)) {
2626
- _context22.next = 4;
2488
+ _context20.next = 4;
2627
2489
  break;
2628
2490
  }
2629
2491
 
2630
- return _context22.abrupt("return", this.stackClient.checkForRevocation());
2492
+ return _context20.abrupt("return", this.stackClient.checkForRevocation());
2631
2493
 
2632
2494
  case 4:
2633
2495
  throw 'checkForRevocation is only implemented for OAutClient';
2634
2496
 
2635
2497
  case 5:
2636
2498
  case "end":
2637
- return _context22.stop();
2499
+ return _context20.stop();
2638
2500
  }
2639
2501
  }
2640
- }, _callee22, this);
2502
+ }, _callee20, this);
2641
2503
  }));
2642
2504
 
2643
2505
  function checkForRevocation() {
@@ -2793,17 +2655,17 @@ var CozyClient = /*#__PURE__*/function () {
2793
2655
  }, {
2794
2656
  key: "loadInstanceOptionsFromStack",
2795
2657
  value: function () {
2796
- var _loadInstanceOptionsFromStack = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee23() {
2658
+ var _loadInstanceOptionsFromStack = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee21() {
2797
2659
  var results, capabilitiesData, instanceData;
2798
- return _regenerator.default.wrap(function _callee23$(_context23) {
2660
+ return _regenerator.default.wrap(function _callee21$(_context21) {
2799
2661
  while (1) {
2800
- switch (_context23.prev = _context23.next) {
2662
+ switch (_context21.prev = _context21.next) {
2801
2663
  case 0:
2802
- _context23.next = 2;
2664
+ _context21.next = 2;
2803
2665
  return Promise.all([this.query((0, _dsl.Q)('io.cozy.settings').getById('io.cozy.settings.capabilities')), this.query((0, _dsl.Q)('io.cozy.settings').getById('io.cozy.settings.instance'))]);
2804
2666
 
2805
2667
  case 2:
2806
- results = _context23.sent;
2668
+ results = _context21.sent;
2807
2669
  capabilitiesData = results[0].data;
2808
2670
  instanceData = results[1].data;
2809
2671
  this.instanceOptions = {
@@ -2815,10 +2677,10 @@ var CozyClient = /*#__PURE__*/function () {
2815
2677
 
2816
2678
  case 7:
2817
2679
  case "end":
2818
- return _context23.stop();
2680
+ return _context21.stop();
2819
2681
  }
2820
2682
  }
2821
- }, _callee23, this);
2683
+ }, _callee21, this);
2822
2684
  }));
2823
2685
 
2824
2686
  function loadInstanceOptionsFromStack() {
@@ -2838,15 +2700,15 @@ var CozyClient = /*#__PURE__*/function () {
2838
2700
  }, {
2839
2701
  key: "setData",
2840
2702
  value: function setData(data) {
2841
- var _this11 = this;
2703
+ var _this10 = this;
2842
2704
 
2843
2705
  this.ensureStore();
2844
- Object.entries(data).forEach(function (_ref9) {
2845
- var _ref10 = (0, _slicedToArray2.default)(_ref9, 2),
2846
- doctype = _ref10[0],
2847
- data = _ref10[1];
2706
+ Object.entries(data).forEach(function (_ref12) {
2707
+ var _ref13 = (0, _slicedToArray2.default)(_ref12, 2),
2708
+ doctype = _ref13[0],
2709
+ data = _ref13[1];
2848
2710
 
2849
- _this11.dispatch((0, _store.receiveQueryResult)(null, {
2711
+ _this10.dispatch((0, _store.receiveQueryResult)(null, {
2850
2712
  data: data
2851
2713
  }));
2852
2714
  });
@@ -2895,12 +2757,12 @@ var CozyClient = /*#__PURE__*/function () {
2895
2757
  }, {
2896
2758
  key: "setLinks",
2897
2759
  value: function () {
2898
- var _setLinks = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee24(links) {
2899
- var _iterator7, _step7, link;
2760
+ var _setLinks = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee22(links) {
2761
+ var _iterator6, _step6, link;
2900
2762
 
2901
- return _regenerator.default.wrap(function _callee24$(_context24) {
2763
+ return _regenerator.default.wrap(function _callee22$(_context22) {
2902
2764
  while (1) {
2903
- switch (_context24.prev = _context24.next) {
2765
+ switch (_context22.prev = _context22.next) {
2904
2766
  case 0:
2905
2767
  this.links = links ? links : [new _StackLink.default({
2906
2768
  performanceApi: this.performanceApi
@@ -2909,64 +2771,64 @@ var CozyClient = /*#__PURE__*/function () {
2909
2771
  this.chain = (0, _CozyLink.chain)(this.links);
2910
2772
 
2911
2773
  if (!this.isLogged) {
2912
- _context24.next = 22;
2774
+ _context22.next = 22;
2913
2775
  break;
2914
2776
  }
2915
2777
 
2916
2778
  // If the client is already logged, it means this method is called manually, after
2917
2779
  // a client instanciation.
2918
2780
  // Thus, we call the link's onLogin methods
2919
- _iterator7 = _createForOfIteratorHelper(this.links);
2920
- _context24.prev = 5;
2781
+ _iterator6 = _createForOfIteratorHelper(this.links);
2782
+ _context22.prev = 5;
2921
2783
 
2922
- _iterator7.s();
2784
+ _iterator6.s();
2923
2785
 
2924
2786
  case 7:
2925
- if ((_step7 = _iterator7.n()).done) {
2926
- _context24.next = 14;
2787
+ if ((_step6 = _iterator6.n()).done) {
2788
+ _context22.next = 14;
2927
2789
  break;
2928
2790
  }
2929
2791
 
2930
- link = _step7.value;
2792
+ link = _step6.value;
2931
2793
 
2932
2794
  if (!link.onLogin) {
2933
- _context24.next = 12;
2795
+ _context22.next = 12;
2934
2796
  break;
2935
2797
  }
2936
2798
 
2937
- _context24.next = 12;
2799
+ _context22.next = 12;
2938
2800
  return link.onLogin();
2939
2801
 
2940
2802
  case 12:
2941
- _context24.next = 7;
2803
+ _context22.next = 7;
2942
2804
  break;
2943
2805
 
2944
2806
  case 14:
2945
- _context24.next = 19;
2807
+ _context22.next = 19;
2946
2808
  break;
2947
2809
 
2948
2810
  case 16:
2949
- _context24.prev = 16;
2950
- _context24.t0 = _context24["catch"](5);
2811
+ _context22.prev = 16;
2812
+ _context22.t0 = _context22["catch"](5);
2951
2813
 
2952
- _iterator7.e(_context24.t0);
2814
+ _iterator6.e(_context22.t0);
2953
2815
 
2954
2816
  case 19:
2955
- _context24.prev = 19;
2817
+ _context22.prev = 19;
2956
2818
 
2957
- _iterator7.f();
2819
+ _iterator6.f();
2958
2820
 
2959
- return _context24.finish(19);
2821
+ return _context22.finish(19);
2960
2822
 
2961
2823
  case 22:
2962
2824
  case "end":
2963
- return _context24.stop();
2825
+ return _context22.stop();
2964
2826
  }
2965
2827
  }
2966
- }, _callee24, this, [[5, 16, 19, 22]]);
2828
+ }, _callee22, this, [[5, 16, 19, 22]]);
2967
2829
  }));
2968
2830
 
2969
- function setLinks(_x26) {
2831
+ function setLinks(_x22) {
2970
2832
  return _setLinks.apply(this, arguments);
2971
2833
  }
2972
2834
 
@@ -2986,22 +2848,22 @@ var CozyClient = /*#__PURE__*/function () {
2986
2848
  }, {
2987
2849
  key: "getSettings",
2988
2850
  value: function () {
2989
- var _getSettings2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee25(slug, keys) {
2990
- return _regenerator.default.wrap(function _callee25$(_context25) {
2851
+ var _getSettings2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee23(slug, keys) {
2852
+ return _regenerator.default.wrap(function _callee23$(_context23) {
2991
2853
  while (1) {
2992
- switch (_context25.prev = _context25.next) {
2854
+ switch (_context23.prev = _context23.next) {
2993
2855
  case 0:
2994
- return _context25.abrupt("return", (0, _helpers2.getSettings)(this, slug, keys));
2856
+ return _context23.abrupt("return", (0, _helpers2.getSettings)(this, slug, keys));
2995
2857
 
2996
2858
  case 1:
2997
2859
  case "end":
2998
- return _context25.stop();
2860
+ return _context23.stop();
2999
2861
  }
3000
2862
  }
3001
- }, _callee25, this);
2863
+ }, _callee23, this);
3002
2864
  }));
3003
2865
 
3004
- function getSettings(_x27, _x28) {
2866
+ function getSettings(_x23, _x24) {
3005
2867
  return _getSettings2.apply(this, arguments);
3006
2868
  }
3007
2869
 
@@ -3024,22 +2886,22 @@ var CozyClient = /*#__PURE__*/function () {
3024
2886
  }, {
3025
2887
  key: "saveAfterFetchSettings",
3026
2888
  value: function () {
3027
- var _saveAfterFetchSettings2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee26(slug, itemsOrSetter, setterKeys) {
3028
- return _regenerator.default.wrap(function _callee26$(_context26) {
2889
+ var _saveAfterFetchSettings2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee24(slug, itemsOrSetter, setterKeys) {
2890
+ return _regenerator.default.wrap(function _callee24$(_context24) {
3029
2891
  while (1) {
3030
- switch (_context26.prev = _context26.next) {
2892
+ switch (_context24.prev = _context24.next) {
3031
2893
  case 0:
3032
- return _context26.abrupt("return", (0, _helpers2.saveAfterFetchSettings)(this, slug, itemsOrSetter, setterKeys));
2894
+ return _context24.abrupt("return", (0, _helpers2.saveAfterFetchSettings)(this, slug, itemsOrSetter, setterKeys));
3033
2895
 
3034
2896
  case 1:
3035
2897
  case "end":
3036
- return _context26.stop();
2898
+ return _context24.stop();
3037
2899
  }
3038
2900
  }
3039
- }, _callee26, this);
2901
+ }, _callee24, this);
3040
2902
  }));
3041
2903
 
3042
- function saveAfterFetchSettings(_x29, _x30, _x31) {
2904
+ function saveAfterFetchSettings(_x25, _x26, _x27) {
3043
2905
  return _saveAfterFetchSettings2.apply(this, arguments);
3044
2906
  }
3045
2907
 
@@ -3057,46 +2919,46 @@ var CozyClient = /*#__PURE__*/function () {
3057
2919
  }, {
3058
2920
  key: "resetQuery",
3059
2921
  value: function () {
3060
- var _resetQuery2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee27(queryId) {
2922
+ var _resetQuery2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee25(queryId) {
3061
2923
  var query;
3062
- return _regenerator.default.wrap(function _callee27$(_context27) {
2924
+ return _regenerator.default.wrap(function _callee25$(_context25) {
3063
2925
  while (1) {
3064
- switch (_context27.prev = _context27.next) {
2926
+ switch (_context25.prev = _context25.next) {
3065
2927
  case 0:
3066
- _context27.prev = 0;
2928
+ _context25.prev = 0;
3067
2929
 
3068
2930
  if ((0, _store.isQueryExisting)(this.store.getState(), queryId)) {
3069
- _context27.next = 3;
2931
+ _context25.next = 3;
3070
2932
  break;
3071
2933
  }
3072
2934
 
3073
- return _context27.abrupt("return", Promise.resolve(null));
2935
+ return _context25.abrupt("return", Promise.resolve(null));
3074
2936
 
3075
2937
  case 3:
3076
2938
  this.dispatch((0, _store.resetQuery)(queryId));
3077
2939
  query = this.getQueryFromState(queryId);
3078
- _context27.next = 7;
2940
+ _context25.next = 7;
3079
2941
  return this.query(query.definition, {
3080
2942
  as: queryId
3081
2943
  });
3082
2944
 
3083
2945
  case 7:
3084
- return _context27.abrupt("return", _context27.sent);
2946
+ return _context25.abrupt("return", _context25.sent);
3085
2947
 
3086
2948
  case 10:
3087
- _context27.prev = 10;
3088
- _context27.t0 = _context27["catch"](0);
3089
- throw _context27.t0;
2949
+ _context25.prev = 10;
2950
+ _context25.t0 = _context25["catch"](0);
2951
+ throw _context25.t0;
3090
2952
 
3091
2953
  case 13:
3092
2954
  case "end":
3093
- return _context27.stop();
2955
+ return _context25.stop();
3094
2956
  }
3095
2957
  }
3096
- }, _callee27, this, [[0, 10]]);
2958
+ }, _callee25, this, [[0, 10]]);
3097
2959
  }));
3098
2960
 
3099
- function resetQuery(_x32) {
2961
+ function resetQuery(_x28) {
3100
2962
  return _resetQuery2.apply(this, arguments);
3101
2963
  }
3102
2964
 
@@ -3124,22 +2986,22 @@ var CozyClient = /*#__PURE__*/function () {
3124
2986
  }, {
3125
2987
  key: "fromOldOAuthClient",
3126
2988
  value: function () {
3127
- var _fromOldOAuthClient = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee28(oldClient, options) {
2989
+ var _fromOldOAuthClient = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee26(oldClient, options) {
3128
2990
  var credentials, oauthOptions, client;
3129
- return _regenerator.default.wrap(function _callee28$(_context28) {
2991
+ return _regenerator.default.wrap(function _callee26$(_context26) {
3130
2992
  while (1) {
3131
- switch (_context28.prev = _context28.next) {
2993
+ switch (_context26.prev = _context26.next) {
3132
2994
  case 0:
3133
2995
  if (!oldClient._oauth) {
3134
- _context28.next = 12;
2996
+ _context26.next = 12;
3135
2997
  break;
3136
2998
  }
3137
2999
 
3138
- _context28.next = 3;
3000
+ _context26.next = 3;
3139
3001
  return oldClient.authorize();
3140
3002
 
3141
3003
  case 3:
3142
- credentials = _context28.sent;
3004
+ credentials = _context26.sent;
3143
3005
  oauthOptions = {
3144
3006
  oauth: credentials.client,
3145
3007
  token: credentials.token,
@@ -3150,28 +3012,28 @@ var CozyClient = /*#__PURE__*/function () {
3150
3012
  }, oauthOptions), options));
3151
3013
 
3152
3014
  if (!client.loginPromise) {
3153
- _context28.next = 9;
3015
+ _context26.next = 9;
3154
3016
  break;
3155
3017
  }
3156
3018
 
3157
- _context28.next = 9;
3019
+ _context26.next = 9;
3158
3020
  return client.loginPromise;
3159
3021
 
3160
3022
  case 9:
3161
- return _context28.abrupt("return", client);
3023
+ return _context26.abrupt("return", client);
3162
3024
 
3163
3025
  case 12:
3164
3026
  throw new Error('Cannot instantiate a new client: old client is not an OAuth client. CozyClient.fromOldClient might be more suitable.');
3165
3027
 
3166
3028
  case 13:
3167
3029
  case "end":
3168
- return _context28.stop();
3030
+ return _context26.stop();
3169
3031
  }
3170
3032
  }
3171
- }, _callee28);
3033
+ }, _callee26);
3172
3034
  }));
3173
3035
 
3174
- function fromOldOAuthClient(_x33, _x34) {
3036
+ function fromOldOAuthClient(_x29, _x30) {
3175
3037
  return _fromOldOAuthClient.apply(this, arguments);
3176
3038
  }
3177
3039
 
@@ -3264,7 +3126,7 @@ var CozyClient = /*#__PURE__*/function () {
3264
3126
  CozyClient.hooks = CozyClient.hooks || {};
3265
3127
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
3266
3128
 
3267
- CozyClient.version = "60.0.0";
3129
+ CozyClient.version = "60.1.1";
3268
3130
 
3269
3131
  _microee.default.mixin(CozyClient);
3270
3132