cozy-client 60.0.0 → 60.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CozyClient.js +144 -305
- package/dist/links/StackLink.js +13 -2
- package/dist/links/StackLink.spec.js +20 -5
- package/dist/models/file.spec.js +4 -2
- package/dist/queries/dsl.js +18 -1
- package/dist/storage.js +5 -0
- package/dist/store/__snapshots__/queries.spec.js.snap +20 -0
- package/dist/types.js +1 -0
- package/package.json +3 -3
- package/types/CozyClient.d.ts +6 -18
- package/types/queries/dsl.d.ts +11 -0
- package/types/storage.d.ts +4 -0
- package/types/types.d.ts +4 -0
package/dist/CozyClient.js
CHANGED
|
@@ -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
|
-
|
|
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",
|
|
@@ -1804,169 +1806,6 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1804
1806
|
|
|
1805
1807
|
return requestQuery;
|
|
1806
1808
|
}()
|
|
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
1809
|
/**
|
|
1971
1810
|
* Fetch relationships for a response (can be several docs).
|
|
1972
1811
|
* Fills the `relationships` attribute of each documents.
|
|
@@ -1981,23 +1820,23 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
1981
1820
|
}, {
|
|
1982
1821
|
key: "fetchRelationships",
|
|
1983
1822
|
value: function () {
|
|
1984
|
-
var _fetchRelationships = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1823
|
+
var _fetchRelationships = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee15(response, relationshipsByName) {
|
|
1985
1824
|
var _this5 = this;
|
|
1986
1825
|
|
|
1987
|
-
var isSingleDoc, responseDocs, queryDefToDocIdAndRel, documents, definitions, optimizedDefinitions, responses, uniqueDocuments, included, relationshipsByDocId,
|
|
1826
|
+
var isSingleDoc, responseDocs, queryDefToDocIdAndRel, documents, definitions, optimizedDefinitions, responses, uniqueDocuments, included, relationshipsByDocId, _iterator5, _step5, _step5$value, def, resp, docIdAndRel, _docIdAndRel, docId, relName;
|
|
1988
1827
|
|
|
1989
|
-
return _regenerator.default.wrap(function
|
|
1828
|
+
return _regenerator.default.wrap(function _callee15$(_context15) {
|
|
1990
1829
|
while (1) {
|
|
1991
|
-
switch (
|
|
1830
|
+
switch (_context15.prev = _context15.next) {
|
|
1992
1831
|
case 0:
|
|
1993
1832
|
isSingleDoc = !Array.isArray(response.data);
|
|
1994
1833
|
|
|
1995
1834
|
if (!(!isSingleDoc && response.data.length === 0)) {
|
|
1996
|
-
|
|
1835
|
+
_context15.next = 3;
|
|
1997
1836
|
break;
|
|
1998
1837
|
}
|
|
1999
1838
|
|
|
2000
|
-
return
|
|
1839
|
+
return _context15.abrupt("return", response);
|
|
2001
1840
|
|
|
2002
1841
|
case 3:
|
|
2003
1842
|
responseDocs = isSingleDoc ? [response.data] : response.data;
|
|
@@ -2027,13 +1866,13 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2027
1866
|
}); // Definitions can be in optimized/regrouped in case of HasMany relationships.
|
|
2028
1867
|
|
|
2029
1868
|
optimizedDefinitions = (0, _optimize.default)(definitions);
|
|
2030
|
-
|
|
1869
|
+
_context15.next = 11;
|
|
2031
1870
|
return Promise.all(optimizedDefinitions.map(function (req) {
|
|
2032
1871
|
return _this5.chain.request(req);
|
|
2033
1872
|
}));
|
|
2034
1873
|
|
|
2035
1874
|
case 11:
|
|
2036
|
-
responses =
|
|
1875
|
+
responses = _context15.sent;
|
|
2037
1876
|
// "Included" documents will be stored in the `documents` store
|
|
2038
1877
|
uniqueDocuments = (0, _uniqBy.default)((0, _flatten.default)(documents), '_id');
|
|
2039
1878
|
included = (0, _flatten.default)(responses.map(function (r) {
|
|
@@ -2046,11 +1885,11 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2046
1885
|
// storing the document. This makes the data easier to manipulate for the front-end.
|
|
2047
1886
|
|
|
2048
1887
|
relationshipsByDocId = {};
|
|
2049
|
-
|
|
1888
|
+
_iterator5 = _createForOfIteratorHelper((0, _zip.default)(optimizedDefinitions, responses));
|
|
2050
1889
|
|
|
2051
1890
|
try {
|
|
2052
|
-
for (
|
|
2053
|
-
|
|
1891
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
1892
|
+
_step5$value = (0, _slicedToArray2.default)(_step5.value, 2), def = _step5$value[0], resp = _step5$value[1];
|
|
2054
1893
|
docIdAndRel = queryDefToDocIdAndRel.get(def);
|
|
2055
1894
|
|
|
2056
1895
|
if (docIdAndRel) {
|
|
@@ -2060,24 +1899,24 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2060
1899
|
}
|
|
2061
1900
|
}
|
|
2062
1901
|
} catch (err) {
|
|
2063
|
-
|
|
1902
|
+
_iterator5.e(err);
|
|
2064
1903
|
} finally {
|
|
2065
|
-
|
|
1904
|
+
_iterator5.f();
|
|
2066
1905
|
}
|
|
2067
1906
|
|
|
2068
|
-
return
|
|
1907
|
+
return _context15.abrupt("return", _objectSpread(_objectSpread({}, (0, _helpers.attachRelationships)(response, relationshipsByDocId)), {}, {
|
|
2069
1908
|
included: included
|
|
2070
1909
|
}));
|
|
2071
1910
|
|
|
2072
1911
|
case 18:
|
|
2073
1912
|
case "end":
|
|
2074
|
-
return
|
|
1913
|
+
return _context15.stop();
|
|
2075
1914
|
}
|
|
2076
1915
|
}
|
|
2077
|
-
},
|
|
1916
|
+
}, _callee15);
|
|
2078
1917
|
}));
|
|
2079
1918
|
|
|
2080
|
-
function fetchRelationships(
|
|
1919
|
+
function fetchRelationships(_x17, _x18) {
|
|
2081
1920
|
return _fetchRelationships.apply(this, arguments);
|
|
2082
1921
|
}
|
|
2083
1922
|
|
|
@@ -2086,47 +1925,47 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2086
1925
|
}, {
|
|
2087
1926
|
key: "requestMutation",
|
|
2088
1927
|
value: function () {
|
|
2089
|
-
var _requestMutation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
1928
|
+
var _requestMutation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee16(definition, options) {
|
|
2090
1929
|
var _this6 = this;
|
|
2091
1930
|
|
|
2092
1931
|
var _definition, first, rest, firstResponse;
|
|
2093
1932
|
|
|
2094
|
-
return _regenerator.default.wrap(function
|
|
1933
|
+
return _regenerator.default.wrap(function _callee16$(_context16) {
|
|
2095
1934
|
while (1) {
|
|
2096
|
-
switch (
|
|
1935
|
+
switch (_context16.prev = _context16.next) {
|
|
2097
1936
|
case 0:
|
|
2098
1937
|
if (!Array.isArray(definition)) {
|
|
2099
|
-
|
|
1938
|
+
_context16.next = 8;
|
|
2100
1939
|
break;
|
|
2101
1940
|
}
|
|
2102
1941
|
|
|
2103
1942
|
_definition = (0, _toArray2.default)(definition), first = _definition[0], rest = _definition.slice(1);
|
|
2104
|
-
|
|
1943
|
+
_context16.next = 4;
|
|
2105
1944
|
return this.requestMutation(first);
|
|
2106
1945
|
|
|
2107
1946
|
case 4:
|
|
2108
|
-
firstResponse =
|
|
2109
|
-
|
|
1947
|
+
firstResponse = _context16.sent;
|
|
1948
|
+
_context16.next = 7;
|
|
2110
1949
|
return Promise.all(rest.map(function (def) {
|
|
2111
1950
|
var mutationDef = typeof def === 'function' ? def(firstResponse) : def;
|
|
2112
1951
|
return _this6.requestMutation(mutationDef);
|
|
2113
1952
|
}));
|
|
2114
1953
|
|
|
2115
1954
|
case 7:
|
|
2116
|
-
return
|
|
1955
|
+
return _context16.abrupt("return", firstResponse);
|
|
2117
1956
|
|
|
2118
1957
|
case 8:
|
|
2119
|
-
return
|
|
1958
|
+
return _context16.abrupt("return", this.chain.request(definition, options));
|
|
2120
1959
|
|
|
2121
1960
|
case 9:
|
|
2122
1961
|
case "end":
|
|
2123
|
-
return
|
|
1962
|
+
return _context16.stop();
|
|
2124
1963
|
}
|
|
2125
1964
|
}
|
|
2126
|
-
},
|
|
1965
|
+
}, _callee16, this);
|
|
2127
1966
|
}));
|
|
2128
1967
|
|
|
2129
|
-
function requestMutation(
|
|
1968
|
+
function requestMutation(_x19, _x20) {
|
|
2130
1969
|
return _requestMutation.apply(this, arguments);
|
|
2131
1970
|
}
|
|
2132
1971
|
|
|
@@ -2384,34 +2223,34 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2384
2223
|
}, {
|
|
2385
2224
|
key: "startOAuthFlow",
|
|
2386
2225
|
value: function () {
|
|
2387
|
-
var _startOAuthFlow = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2226
|
+
var _startOAuthFlow = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee17(openURLCallback) {
|
|
2388
2227
|
var stackClient;
|
|
2389
|
-
return _regenerator.default.wrap(function
|
|
2228
|
+
return _regenerator.default.wrap(function _callee17$(_context17) {
|
|
2390
2229
|
while (1) {
|
|
2391
|
-
switch (
|
|
2230
|
+
switch (_context17.prev = _context17.next) {
|
|
2392
2231
|
case 0:
|
|
2393
2232
|
stackClient = this.getStackClient();
|
|
2394
|
-
|
|
2233
|
+
_context17.next = 3;
|
|
2395
2234
|
return stackClient.register();
|
|
2396
2235
|
|
|
2397
2236
|
case 3:
|
|
2398
|
-
|
|
2237
|
+
_context17.next = 5;
|
|
2399
2238
|
return this.certifyFlagship();
|
|
2400
2239
|
|
|
2401
2240
|
case 5:
|
|
2402
|
-
return
|
|
2241
|
+
return _context17.abrupt("return", this.authorize({
|
|
2403
2242
|
openURLCallback: openURLCallback
|
|
2404
2243
|
}));
|
|
2405
2244
|
|
|
2406
2245
|
case 6:
|
|
2407
2246
|
case "end":
|
|
2408
|
-
return
|
|
2247
|
+
return _context17.stop();
|
|
2409
2248
|
}
|
|
2410
2249
|
}
|
|
2411
|
-
},
|
|
2250
|
+
}, _callee17, this);
|
|
2412
2251
|
}));
|
|
2413
2252
|
|
|
2414
|
-
function startOAuthFlow(
|
|
2253
|
+
function startOAuthFlow(_x21) {
|
|
2415
2254
|
return _startOAuthFlow.apply(this, arguments);
|
|
2416
2255
|
}
|
|
2417
2256
|
|
|
@@ -2426,28 +2265,28 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2426
2265
|
}, {
|
|
2427
2266
|
key: "certifyFlagship",
|
|
2428
2267
|
value: function () {
|
|
2429
|
-
var _certifyFlagship2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2268
|
+
var _certifyFlagship2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee18() {
|
|
2430
2269
|
var stackClient;
|
|
2431
|
-
return _regenerator.default.wrap(function
|
|
2270
|
+
return _regenerator.default.wrap(function _callee18$(_context18) {
|
|
2432
2271
|
while (1) {
|
|
2433
|
-
switch (
|
|
2272
|
+
switch (_context18.prev = _context18.next) {
|
|
2434
2273
|
case 0:
|
|
2435
2274
|
stackClient = this.getStackClient();
|
|
2436
2275
|
|
|
2437
2276
|
if (!stackClient.oauthOptions.shouldRequireFlagshipPermissions) {
|
|
2438
|
-
|
|
2277
|
+
_context18.next = 4;
|
|
2439
2278
|
break;
|
|
2440
2279
|
}
|
|
2441
2280
|
|
|
2442
|
-
|
|
2281
|
+
_context18.next = 4;
|
|
2443
2282
|
return (0, _flagshipCertification.certifyFlagship)(stackClient.oauthOptions.certificationConfig, this);
|
|
2444
2283
|
|
|
2445
2284
|
case 4:
|
|
2446
2285
|
case "end":
|
|
2447
|
-
return
|
|
2286
|
+
return _context18.stop();
|
|
2448
2287
|
}
|
|
2449
2288
|
}
|
|
2450
|
-
},
|
|
2289
|
+
}, _callee18, this);
|
|
2451
2290
|
}));
|
|
2452
2291
|
|
|
2453
2292
|
function certifyFlagship() {
|
|
@@ -2471,7 +2310,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2471
2310
|
}, {
|
|
2472
2311
|
key: "authorize",
|
|
2473
2312
|
value: function () {
|
|
2474
|
-
var _authorize = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2313
|
+
var _authorize = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee19() {
|
|
2475
2314
|
var _ref7,
|
|
2476
2315
|
_ref7$openURLCallback,
|
|
2477
2316
|
openURLCallback,
|
|
@@ -2488,14 +2327,14 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2488
2327
|
code,
|
|
2489
2328
|
token,
|
|
2490
2329
|
_stackClient,
|
|
2491
|
-
|
|
2330
|
+
_args19 = arguments;
|
|
2492
2331
|
|
|
2493
|
-
return _regenerator.default.wrap(function
|
|
2332
|
+
return _regenerator.default.wrap(function _callee19$(_context19) {
|
|
2494
2333
|
while (1) {
|
|
2495
|
-
switch (
|
|
2334
|
+
switch (_context19.prev = _context19.next) {
|
|
2496
2335
|
case 0:
|
|
2497
|
-
_ref7 =
|
|
2498
|
-
|
|
2336
|
+
_ref7 = _args19.length > 0 && _args19[0] !== undefined ? _args19[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;
|
|
2337
|
+
_context19.prev = 1;
|
|
2499
2338
|
codeVerifier = pkceCodes.codeVerifier, codeChallenge = pkceCodes.codeChallenge;
|
|
2500
2339
|
stackClient = this.getStackClient();
|
|
2501
2340
|
stateCode = stackClient.generateStateCode();
|
|
@@ -2505,19 +2344,19 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2505
2344
|
sessionCode: sessionCode,
|
|
2506
2345
|
codeChallenge: codeChallenge
|
|
2507
2346
|
});
|
|
2508
|
-
|
|
2347
|
+
_context19.next = 8;
|
|
2509
2348
|
return openURLCallback(url);
|
|
2510
2349
|
|
|
2511
2350
|
case 8:
|
|
2512
|
-
redirectedURL =
|
|
2351
|
+
redirectedURL = _context19.sent;
|
|
2513
2352
|
code = stackClient.getAccessCodeFromURL(redirectedURL, stateCode);
|
|
2514
|
-
|
|
2353
|
+
_context19.next = 12;
|
|
2515
2354
|
return stackClient.fetchAccessToken(code, undefined, undefined, codeVerifier);
|
|
2516
2355
|
|
|
2517
2356
|
case 12:
|
|
2518
|
-
token =
|
|
2357
|
+
token = _context19.sent;
|
|
2519
2358
|
stackClient.setToken(token);
|
|
2520
|
-
return
|
|
2359
|
+
return _context19.abrupt("return", {
|
|
2521
2360
|
token: token,
|
|
2522
2361
|
infos: stackClient.oauthOptions,
|
|
2523
2362
|
client: stackClient.oauthOptions // for compat with Authentication comp reasons
|
|
@@ -2525,24 +2364,24 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2525
2364
|
});
|
|
2526
2365
|
|
|
2527
2366
|
case 17:
|
|
2528
|
-
|
|
2529
|
-
|
|
2367
|
+
_context19.prev = 17;
|
|
2368
|
+
_context19.t0 = _context19["catch"](1);
|
|
2530
2369
|
|
|
2531
2370
|
/* if REGISTRATION_ABORT is emited, we have to unregister the client. */
|
|
2532
|
-
if (
|
|
2371
|
+
if (_context19.t0.message === _const.REGISTRATION_ABORT) {
|
|
2533
2372
|
_stackClient = this.getStackClient();
|
|
2534
2373
|
|
|
2535
2374
|
_stackClient.unregister();
|
|
2536
2375
|
}
|
|
2537
2376
|
|
|
2538
|
-
throw
|
|
2377
|
+
throw _context19.t0;
|
|
2539
2378
|
|
|
2540
2379
|
case 21:
|
|
2541
2380
|
case "end":
|
|
2542
|
-
return
|
|
2381
|
+
return _context19.stop();
|
|
2543
2382
|
}
|
|
2544
2383
|
}
|
|
2545
|
-
},
|
|
2384
|
+
}, _callee19, this, [[1, 17]]);
|
|
2546
2385
|
}));
|
|
2547
2386
|
|
|
2548
2387
|
function authorize() {
|
|
@@ -2617,27 +2456,27 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2617
2456
|
}, {
|
|
2618
2457
|
key: "checkForRevocation",
|
|
2619
2458
|
value: function () {
|
|
2620
|
-
var _checkForRevocation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2621
|
-
return _regenerator.default.wrap(function
|
|
2459
|
+
var _checkForRevocation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee20() {
|
|
2460
|
+
return _regenerator.default.wrap(function _callee20$(_context20) {
|
|
2622
2461
|
while (1) {
|
|
2623
|
-
switch (
|
|
2462
|
+
switch (_context20.prev = _context20.next) {
|
|
2624
2463
|
case 0:
|
|
2625
2464
|
if (!(this.stackClient instanceof _cozyStackClient.OAuthClient)) {
|
|
2626
|
-
|
|
2465
|
+
_context20.next = 4;
|
|
2627
2466
|
break;
|
|
2628
2467
|
}
|
|
2629
2468
|
|
|
2630
|
-
return
|
|
2469
|
+
return _context20.abrupt("return", this.stackClient.checkForRevocation());
|
|
2631
2470
|
|
|
2632
2471
|
case 4:
|
|
2633
2472
|
throw 'checkForRevocation is only implemented for OAutClient';
|
|
2634
2473
|
|
|
2635
2474
|
case 5:
|
|
2636
2475
|
case "end":
|
|
2637
|
-
return
|
|
2476
|
+
return _context20.stop();
|
|
2638
2477
|
}
|
|
2639
2478
|
}
|
|
2640
|
-
},
|
|
2479
|
+
}, _callee20, this);
|
|
2641
2480
|
}));
|
|
2642
2481
|
|
|
2643
2482
|
function checkForRevocation() {
|
|
@@ -2793,17 +2632,17 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2793
2632
|
}, {
|
|
2794
2633
|
key: "loadInstanceOptionsFromStack",
|
|
2795
2634
|
value: function () {
|
|
2796
|
-
var _loadInstanceOptionsFromStack = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2635
|
+
var _loadInstanceOptionsFromStack = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee21() {
|
|
2797
2636
|
var results, capabilitiesData, instanceData;
|
|
2798
|
-
return _regenerator.default.wrap(function
|
|
2637
|
+
return _regenerator.default.wrap(function _callee21$(_context21) {
|
|
2799
2638
|
while (1) {
|
|
2800
|
-
switch (
|
|
2639
|
+
switch (_context21.prev = _context21.next) {
|
|
2801
2640
|
case 0:
|
|
2802
|
-
|
|
2641
|
+
_context21.next = 2;
|
|
2803
2642
|
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
2643
|
|
|
2805
2644
|
case 2:
|
|
2806
|
-
results =
|
|
2645
|
+
results = _context21.sent;
|
|
2807
2646
|
capabilitiesData = results[0].data;
|
|
2808
2647
|
instanceData = results[1].data;
|
|
2809
2648
|
this.instanceOptions = {
|
|
@@ -2815,10 +2654,10 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2815
2654
|
|
|
2816
2655
|
case 7:
|
|
2817
2656
|
case "end":
|
|
2818
|
-
return
|
|
2657
|
+
return _context21.stop();
|
|
2819
2658
|
}
|
|
2820
2659
|
}
|
|
2821
|
-
},
|
|
2660
|
+
}, _callee21, this);
|
|
2822
2661
|
}));
|
|
2823
2662
|
|
|
2824
2663
|
function loadInstanceOptionsFromStack() {
|
|
@@ -2895,12 +2734,12 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2895
2734
|
}, {
|
|
2896
2735
|
key: "setLinks",
|
|
2897
2736
|
value: function () {
|
|
2898
|
-
var _setLinks = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2899
|
-
var
|
|
2737
|
+
var _setLinks = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee22(links) {
|
|
2738
|
+
var _iterator6, _step6, link;
|
|
2900
2739
|
|
|
2901
|
-
return _regenerator.default.wrap(function
|
|
2740
|
+
return _regenerator.default.wrap(function _callee22$(_context22) {
|
|
2902
2741
|
while (1) {
|
|
2903
|
-
switch (
|
|
2742
|
+
switch (_context22.prev = _context22.next) {
|
|
2904
2743
|
case 0:
|
|
2905
2744
|
this.links = links ? links : [new _StackLink.default({
|
|
2906
2745
|
performanceApi: this.performanceApi
|
|
@@ -2909,64 +2748,64 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2909
2748
|
this.chain = (0, _CozyLink.chain)(this.links);
|
|
2910
2749
|
|
|
2911
2750
|
if (!this.isLogged) {
|
|
2912
|
-
|
|
2751
|
+
_context22.next = 22;
|
|
2913
2752
|
break;
|
|
2914
2753
|
}
|
|
2915
2754
|
|
|
2916
2755
|
// If the client is already logged, it means this method is called manually, after
|
|
2917
2756
|
// a client instanciation.
|
|
2918
2757
|
// Thus, we call the link's onLogin methods
|
|
2919
|
-
|
|
2920
|
-
|
|
2758
|
+
_iterator6 = _createForOfIteratorHelper(this.links);
|
|
2759
|
+
_context22.prev = 5;
|
|
2921
2760
|
|
|
2922
|
-
|
|
2761
|
+
_iterator6.s();
|
|
2923
2762
|
|
|
2924
2763
|
case 7:
|
|
2925
|
-
if ((
|
|
2926
|
-
|
|
2764
|
+
if ((_step6 = _iterator6.n()).done) {
|
|
2765
|
+
_context22.next = 14;
|
|
2927
2766
|
break;
|
|
2928
2767
|
}
|
|
2929
2768
|
|
|
2930
|
-
link =
|
|
2769
|
+
link = _step6.value;
|
|
2931
2770
|
|
|
2932
2771
|
if (!link.onLogin) {
|
|
2933
|
-
|
|
2772
|
+
_context22.next = 12;
|
|
2934
2773
|
break;
|
|
2935
2774
|
}
|
|
2936
2775
|
|
|
2937
|
-
|
|
2776
|
+
_context22.next = 12;
|
|
2938
2777
|
return link.onLogin();
|
|
2939
2778
|
|
|
2940
2779
|
case 12:
|
|
2941
|
-
|
|
2780
|
+
_context22.next = 7;
|
|
2942
2781
|
break;
|
|
2943
2782
|
|
|
2944
2783
|
case 14:
|
|
2945
|
-
|
|
2784
|
+
_context22.next = 19;
|
|
2946
2785
|
break;
|
|
2947
2786
|
|
|
2948
2787
|
case 16:
|
|
2949
|
-
|
|
2950
|
-
|
|
2788
|
+
_context22.prev = 16;
|
|
2789
|
+
_context22.t0 = _context22["catch"](5);
|
|
2951
2790
|
|
|
2952
|
-
|
|
2791
|
+
_iterator6.e(_context22.t0);
|
|
2953
2792
|
|
|
2954
2793
|
case 19:
|
|
2955
|
-
|
|
2794
|
+
_context22.prev = 19;
|
|
2956
2795
|
|
|
2957
|
-
|
|
2796
|
+
_iterator6.f();
|
|
2958
2797
|
|
|
2959
|
-
return
|
|
2798
|
+
return _context22.finish(19);
|
|
2960
2799
|
|
|
2961
2800
|
case 22:
|
|
2962
2801
|
case "end":
|
|
2963
|
-
return
|
|
2802
|
+
return _context22.stop();
|
|
2964
2803
|
}
|
|
2965
2804
|
}
|
|
2966
|
-
},
|
|
2805
|
+
}, _callee22, this, [[5, 16, 19, 22]]);
|
|
2967
2806
|
}));
|
|
2968
2807
|
|
|
2969
|
-
function setLinks(
|
|
2808
|
+
function setLinks(_x22) {
|
|
2970
2809
|
return _setLinks.apply(this, arguments);
|
|
2971
2810
|
}
|
|
2972
2811
|
|
|
@@ -2986,22 +2825,22 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2986
2825
|
}, {
|
|
2987
2826
|
key: "getSettings",
|
|
2988
2827
|
value: function () {
|
|
2989
|
-
var _getSettings2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2990
|
-
return _regenerator.default.wrap(function
|
|
2828
|
+
var _getSettings2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee23(slug, keys) {
|
|
2829
|
+
return _regenerator.default.wrap(function _callee23$(_context23) {
|
|
2991
2830
|
while (1) {
|
|
2992
|
-
switch (
|
|
2831
|
+
switch (_context23.prev = _context23.next) {
|
|
2993
2832
|
case 0:
|
|
2994
|
-
return
|
|
2833
|
+
return _context23.abrupt("return", (0, _helpers2.getSettings)(this, slug, keys));
|
|
2995
2834
|
|
|
2996
2835
|
case 1:
|
|
2997
2836
|
case "end":
|
|
2998
|
-
return
|
|
2837
|
+
return _context23.stop();
|
|
2999
2838
|
}
|
|
3000
2839
|
}
|
|
3001
|
-
},
|
|
2840
|
+
}, _callee23, this);
|
|
3002
2841
|
}));
|
|
3003
2842
|
|
|
3004
|
-
function getSettings(
|
|
2843
|
+
function getSettings(_x23, _x24) {
|
|
3005
2844
|
return _getSettings2.apply(this, arguments);
|
|
3006
2845
|
}
|
|
3007
2846
|
|
|
@@ -3024,22 +2863,22 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
3024
2863
|
}, {
|
|
3025
2864
|
key: "saveAfterFetchSettings",
|
|
3026
2865
|
value: function () {
|
|
3027
|
-
var _saveAfterFetchSettings2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
3028
|
-
return _regenerator.default.wrap(function
|
|
2866
|
+
var _saveAfterFetchSettings2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee24(slug, itemsOrSetter, setterKeys) {
|
|
2867
|
+
return _regenerator.default.wrap(function _callee24$(_context24) {
|
|
3029
2868
|
while (1) {
|
|
3030
|
-
switch (
|
|
2869
|
+
switch (_context24.prev = _context24.next) {
|
|
3031
2870
|
case 0:
|
|
3032
|
-
return
|
|
2871
|
+
return _context24.abrupt("return", (0, _helpers2.saveAfterFetchSettings)(this, slug, itemsOrSetter, setterKeys));
|
|
3033
2872
|
|
|
3034
2873
|
case 1:
|
|
3035
2874
|
case "end":
|
|
3036
|
-
return
|
|
2875
|
+
return _context24.stop();
|
|
3037
2876
|
}
|
|
3038
2877
|
}
|
|
3039
|
-
},
|
|
2878
|
+
}, _callee24, this);
|
|
3040
2879
|
}));
|
|
3041
2880
|
|
|
3042
|
-
function saveAfterFetchSettings(
|
|
2881
|
+
function saveAfterFetchSettings(_x25, _x26, _x27) {
|
|
3043
2882
|
return _saveAfterFetchSettings2.apply(this, arguments);
|
|
3044
2883
|
}
|
|
3045
2884
|
|
|
@@ -3057,46 +2896,46 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
3057
2896
|
}, {
|
|
3058
2897
|
key: "resetQuery",
|
|
3059
2898
|
value: function () {
|
|
3060
|
-
var _resetQuery2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2899
|
+
var _resetQuery2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee25(queryId) {
|
|
3061
2900
|
var query;
|
|
3062
|
-
return _regenerator.default.wrap(function
|
|
2901
|
+
return _regenerator.default.wrap(function _callee25$(_context25) {
|
|
3063
2902
|
while (1) {
|
|
3064
|
-
switch (
|
|
2903
|
+
switch (_context25.prev = _context25.next) {
|
|
3065
2904
|
case 0:
|
|
3066
|
-
|
|
2905
|
+
_context25.prev = 0;
|
|
3067
2906
|
|
|
3068
2907
|
if ((0, _store.isQueryExisting)(this.store.getState(), queryId)) {
|
|
3069
|
-
|
|
2908
|
+
_context25.next = 3;
|
|
3070
2909
|
break;
|
|
3071
2910
|
}
|
|
3072
2911
|
|
|
3073
|
-
return
|
|
2912
|
+
return _context25.abrupt("return", Promise.resolve(null));
|
|
3074
2913
|
|
|
3075
2914
|
case 3:
|
|
3076
2915
|
this.dispatch((0, _store.resetQuery)(queryId));
|
|
3077
2916
|
query = this.getQueryFromState(queryId);
|
|
3078
|
-
|
|
2917
|
+
_context25.next = 7;
|
|
3079
2918
|
return this.query(query.definition, {
|
|
3080
2919
|
as: queryId
|
|
3081
2920
|
});
|
|
3082
2921
|
|
|
3083
2922
|
case 7:
|
|
3084
|
-
return
|
|
2923
|
+
return _context25.abrupt("return", _context25.sent);
|
|
3085
2924
|
|
|
3086
2925
|
case 10:
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
throw
|
|
2926
|
+
_context25.prev = 10;
|
|
2927
|
+
_context25.t0 = _context25["catch"](0);
|
|
2928
|
+
throw _context25.t0;
|
|
3090
2929
|
|
|
3091
2930
|
case 13:
|
|
3092
2931
|
case "end":
|
|
3093
|
-
return
|
|
2932
|
+
return _context25.stop();
|
|
3094
2933
|
}
|
|
3095
2934
|
}
|
|
3096
|
-
},
|
|
2935
|
+
}, _callee25, this, [[0, 10]]);
|
|
3097
2936
|
}));
|
|
3098
2937
|
|
|
3099
|
-
function resetQuery(
|
|
2938
|
+
function resetQuery(_x28) {
|
|
3100
2939
|
return _resetQuery2.apply(this, arguments);
|
|
3101
2940
|
}
|
|
3102
2941
|
|
|
@@ -3124,22 +2963,22 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
3124
2963
|
}, {
|
|
3125
2964
|
key: "fromOldOAuthClient",
|
|
3126
2965
|
value: function () {
|
|
3127
|
-
var _fromOldOAuthClient = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
2966
|
+
var _fromOldOAuthClient = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee26(oldClient, options) {
|
|
3128
2967
|
var credentials, oauthOptions, client;
|
|
3129
|
-
return _regenerator.default.wrap(function
|
|
2968
|
+
return _regenerator.default.wrap(function _callee26$(_context26) {
|
|
3130
2969
|
while (1) {
|
|
3131
|
-
switch (
|
|
2970
|
+
switch (_context26.prev = _context26.next) {
|
|
3132
2971
|
case 0:
|
|
3133
2972
|
if (!oldClient._oauth) {
|
|
3134
|
-
|
|
2973
|
+
_context26.next = 12;
|
|
3135
2974
|
break;
|
|
3136
2975
|
}
|
|
3137
2976
|
|
|
3138
|
-
|
|
2977
|
+
_context26.next = 3;
|
|
3139
2978
|
return oldClient.authorize();
|
|
3140
2979
|
|
|
3141
2980
|
case 3:
|
|
3142
|
-
credentials =
|
|
2981
|
+
credentials = _context26.sent;
|
|
3143
2982
|
oauthOptions = {
|
|
3144
2983
|
oauth: credentials.client,
|
|
3145
2984
|
token: credentials.token,
|
|
@@ -3150,28 +2989,28 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
3150
2989
|
}, oauthOptions), options));
|
|
3151
2990
|
|
|
3152
2991
|
if (!client.loginPromise) {
|
|
3153
|
-
|
|
2992
|
+
_context26.next = 9;
|
|
3154
2993
|
break;
|
|
3155
2994
|
}
|
|
3156
2995
|
|
|
3157
|
-
|
|
2996
|
+
_context26.next = 9;
|
|
3158
2997
|
return client.loginPromise;
|
|
3159
2998
|
|
|
3160
2999
|
case 9:
|
|
3161
|
-
return
|
|
3000
|
+
return _context26.abrupt("return", client);
|
|
3162
3001
|
|
|
3163
3002
|
case 12:
|
|
3164
3003
|
throw new Error('Cannot instantiate a new client: old client is not an OAuth client. CozyClient.fromOldClient might be more suitable.');
|
|
3165
3004
|
|
|
3166
3005
|
case 13:
|
|
3167
3006
|
case "end":
|
|
3168
|
-
return
|
|
3007
|
+
return _context26.stop();
|
|
3169
3008
|
}
|
|
3170
3009
|
}
|
|
3171
|
-
},
|
|
3010
|
+
}, _callee26);
|
|
3172
3011
|
}));
|
|
3173
3012
|
|
|
3174
|
-
function fromOldOAuthClient(
|
|
3013
|
+
function fromOldOAuthClient(_x29, _x30) {
|
|
3175
3014
|
return _fromOldOAuthClient.apply(this, arguments);
|
|
3176
3015
|
}
|
|
3177
3016
|
|
|
@@ -3264,7 +3103,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
3264
3103
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
3265
3104
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
3266
3105
|
|
|
3267
|
-
CozyClient.version = "60.
|
|
3106
|
+
CozyClient.version = "60.1.0";
|
|
3268
3107
|
|
|
3269
3108
|
_microee.default.mixin(CozyClient);
|
|
3270
3109
|
|
package/dist/links/StackLink.js
CHANGED
|
@@ -288,7 +288,12 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
288
288
|
id = query.id,
|
|
289
289
|
ids = query.ids,
|
|
290
290
|
referenced = query.referenced,
|
|
291
|
-
|
|
291
|
+
sharingId = query.sharingId,
|
|
292
|
+
rawOptions = (0, _objectWithoutProperties2.default)(query, ["doctype", "selector", "id", "ids", "referenced", "sharingId"]);
|
|
293
|
+
|
|
294
|
+
var options = _objectSpread(_objectSpread({}, rawOptions), {}, {
|
|
295
|
+
driveId: undefined
|
|
296
|
+
});
|
|
292
297
|
|
|
293
298
|
if (!doctype) {
|
|
294
299
|
_logger.default.warn('Bad query', query);
|
|
@@ -296,7 +301,13 @@ var StackLink = /*#__PURE__*/function (_CozyLink) {
|
|
|
296
301
|
throw new Error('No doctype found in a query definition');
|
|
297
302
|
}
|
|
298
303
|
|
|
299
|
-
|
|
304
|
+
if (doctype === _const.DOCTYPE_FILES && sharingId) {
|
|
305
|
+
options = _objectSpread(_objectSpread({}, options), {}, {
|
|
306
|
+
driveId: sharingId
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
var collection = this.stackClient.collection(doctype, options);
|
|
300
311
|
|
|
301
312
|
if (id) {
|
|
302
313
|
return collection.get(id, query);
|
|
@@ -18,7 +18,10 @@ describe('StackLink', () => {
|
|
|
18
18
|
stackClient.collection().all.mockReset()
|
|
19
19
|
await link.request(query)
|
|
20
20
|
expect(stackClient.collection().all).toHaveBeenCalled()
|
|
21
|
-
expect(stackClient.collection).toHaveBeenCalledWith(
|
|
21
|
+
expect(stackClient.collection).toHaveBeenCalledWith(
|
|
22
|
+
'io.cozy.todos',
|
|
23
|
+
expect.anything()
|
|
24
|
+
)
|
|
22
25
|
})
|
|
23
26
|
|
|
24
27
|
it('should execute queries with a selector', async () => {
|
|
@@ -36,7 +39,10 @@ describe('StackLink', () => {
|
|
|
36
39
|
stackClient.collection().find.mockReset()
|
|
37
40
|
await link.request(query)
|
|
38
41
|
expect(stackClient.collection().find).toHaveBeenCalled()
|
|
39
|
-
expect(stackClient.collection).toHaveBeenCalledWith(
|
|
42
|
+
expect(stackClient.collection).toHaveBeenCalledWith(
|
|
43
|
+
'io.cozy.todos',
|
|
44
|
+
expect.anything()
|
|
45
|
+
)
|
|
40
46
|
})
|
|
41
47
|
|
|
42
48
|
it('should use all if a no sort option is given', async () => {
|
|
@@ -44,7 +50,10 @@ describe('StackLink', () => {
|
|
|
44
50
|
stackClient.collection().all.mockReset()
|
|
45
51
|
await link.request(query)
|
|
46
52
|
expect(stackClient.collection().all).toHaveBeenCalled()
|
|
47
|
-
expect(stackClient.collection).toHaveBeenCalledWith(
|
|
53
|
+
expect(stackClient.collection).toHaveBeenCalledWith(
|
|
54
|
+
'io.cozy.todos',
|
|
55
|
+
expect.anything()
|
|
56
|
+
)
|
|
48
57
|
})
|
|
49
58
|
|
|
50
59
|
it('should use find if a partialFilter is given', async () => {
|
|
@@ -52,7 +61,10 @@ describe('StackLink', () => {
|
|
|
52
61
|
stackClient.collection().find.mockReset()
|
|
53
62
|
await link.request(query)
|
|
54
63
|
expect(stackClient.collection().find).toHaveBeenCalled()
|
|
55
|
-
expect(stackClient.collection).toHaveBeenCalledWith(
|
|
64
|
+
expect(stackClient.collection).toHaveBeenCalledWith(
|
|
65
|
+
'io.cozy.todos',
|
|
66
|
+
expect.anything()
|
|
67
|
+
)
|
|
56
68
|
})
|
|
57
69
|
|
|
58
70
|
it('should use find if fields are given', async () => {
|
|
@@ -60,7 +72,10 @@ describe('StackLink', () => {
|
|
|
60
72
|
stackClient.collection().find.mockReset()
|
|
61
73
|
await link.request(query)
|
|
62
74
|
expect(stackClient.collection().find).toHaveBeenCalled()
|
|
63
|
-
expect(stackClient.collection).toHaveBeenCalledWith(
|
|
75
|
+
expect(stackClient.collection).toHaveBeenCalledWith(
|
|
76
|
+
'io.cozy.todos',
|
|
77
|
+
expect.anything()
|
|
78
|
+
)
|
|
64
79
|
})
|
|
65
80
|
})
|
|
66
81
|
|
package/dist/models/file.spec.js
CHANGED
|
@@ -430,7 +430,8 @@ describe('File Model', () => {
|
|
|
430
430
|
'mydoc.odt'
|
|
431
431
|
)
|
|
432
432
|
expect(cozyClient.stackClient.collection).toHaveBeenCalledWith(
|
|
433
|
-
'io.cozy.files'
|
|
433
|
+
'io.cozy.files',
|
|
434
|
+
expect.anything()
|
|
434
435
|
)
|
|
435
436
|
expect(getSpy).toHaveBeenCalledWith(
|
|
436
437
|
'parent',
|
|
@@ -447,7 +448,8 @@ describe('File Model', () => {
|
|
|
447
448
|
'mydoc.odt'
|
|
448
449
|
)
|
|
449
450
|
expect(cozyClient.stackClient.collection).toHaveBeenCalledWith(
|
|
450
|
-
'io.cozy.files'
|
|
451
|
+
'io.cozy.files',
|
|
452
|
+
expect.anything()
|
|
451
453
|
)
|
|
452
454
|
expect(getSpy).toHaveBeenCalledWith(
|
|
453
455
|
'parent',
|
package/dist/queries/dsl.js
CHANGED
|
@@ -64,6 +64,7 @@ var QueryDefinition = /*#__PURE__*/function () {
|
|
|
64
64
|
* @param {number|null} [options.skip] - The number of docs to skip.
|
|
65
65
|
* @param {import('../types').CouchDBViewCursor} [options.cursor] - The cursor to paginate views.
|
|
66
66
|
* @param {string} [options.bookmark] - The bookmark to paginate mango queries.
|
|
67
|
+
* @param {string} [options.sharingId] - The id of the sharing
|
|
67
68
|
*/
|
|
68
69
|
function QueryDefinition() {
|
|
69
70
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -82,6 +83,7 @@ var QueryDefinition = /*#__PURE__*/function () {
|
|
|
82
83
|
this.skip = options.skip;
|
|
83
84
|
this.cursor = options.cursor;
|
|
84
85
|
this.bookmark = options.bookmark;
|
|
86
|
+
this.sharingId = options.sharingId;
|
|
85
87
|
}
|
|
86
88
|
/**
|
|
87
89
|
* Checks if the sort order matches the index' fields order.
|
|
@@ -444,6 +446,20 @@ var QueryDefinition = /*#__PURE__*/function () {
|
|
|
444
446
|
referenced: document
|
|
445
447
|
}));
|
|
446
448
|
}
|
|
449
|
+
/**
|
|
450
|
+
* Use a sharingId to query documents coming from a sharing
|
|
451
|
+
*
|
|
452
|
+
* @param {string} id - The sharing doc id
|
|
453
|
+
* @returns {QueryDefinition} The QueryDefinition object.
|
|
454
|
+
*/
|
|
455
|
+
|
|
456
|
+
}, {
|
|
457
|
+
key: "sharingById",
|
|
458
|
+
value: function sharingById(id) {
|
|
459
|
+
return new QueryDefinition(_objectSpread(_objectSpread({}, this.toDefinition()), {}, {
|
|
460
|
+
sharingId: id
|
|
461
|
+
}));
|
|
462
|
+
}
|
|
447
463
|
}, {
|
|
448
464
|
key: "toDefinition",
|
|
449
465
|
value: function toDefinition() {
|
|
@@ -461,7 +477,8 @@ var QueryDefinition = /*#__PURE__*/function () {
|
|
|
461
477
|
limit: this.limit,
|
|
462
478
|
skip: this.skip,
|
|
463
479
|
cursor: this.cursor,
|
|
464
|
-
bookmark: this.bookmark
|
|
480
|
+
bookmark: this.bookmark,
|
|
481
|
+
sharingId: this.sharingId
|
|
465
482
|
};
|
|
466
483
|
}
|
|
467
484
|
}]);
|
package/dist/storage.js
CHANGED
|
@@ -54,6 +54,11 @@ var shouldDocumentBePersisted = function shouldDocumentBePersisted(document) {
|
|
|
54
54
|
return true;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
if (document.driveId && document._type === 'io.cozy.files') {
|
|
58
|
+
// Special case for files in shared drives, so remote files could be locally persisted
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
57
62
|
return false;
|
|
58
63
|
};
|
|
59
64
|
/**
|
|
@@ -19,6 +19,7 @@ Object {
|
|
|
19
19
|
"partialFilter": undefined,
|
|
20
20
|
"referenced": undefined,
|
|
21
21
|
"selector": undefined,
|
|
22
|
+
"sharingId": undefined,
|
|
22
23
|
"skip": undefined,
|
|
23
24
|
"sort": undefined,
|
|
24
25
|
},
|
|
@@ -60,6 +61,7 @@ Object {
|
|
|
60
61
|
"partialFilter": undefined,
|
|
61
62
|
"referenced": undefined,
|
|
62
63
|
"selector": undefined,
|
|
64
|
+
"sharingId": undefined,
|
|
63
65
|
"skip": undefined,
|
|
64
66
|
"sort": undefined,
|
|
65
67
|
},
|
|
@@ -100,6 +102,7 @@ Object {
|
|
|
100
102
|
"partialFilter": undefined,
|
|
101
103
|
"referenced": undefined,
|
|
102
104
|
"selector": undefined,
|
|
105
|
+
"sharingId": undefined,
|
|
103
106
|
"skip": undefined,
|
|
104
107
|
"sort": undefined,
|
|
105
108
|
},
|
|
@@ -140,6 +143,7 @@ Object {
|
|
|
140
143
|
},
|
|
141
144
|
"done": true,
|
|
142
145
|
},
|
|
146
|
+
"sharingId": undefined,
|
|
143
147
|
"skip": undefined,
|
|
144
148
|
"sort": undefined,
|
|
145
149
|
},
|
|
@@ -180,6 +184,7 @@ Object {
|
|
|
180
184
|
"partialFilter": undefined,
|
|
181
185
|
"referenced": undefined,
|
|
182
186
|
"selector": undefined,
|
|
187
|
+
"sharingId": undefined,
|
|
183
188
|
"skip": undefined,
|
|
184
189
|
"sort": undefined,
|
|
185
190
|
},
|
|
@@ -217,6 +222,7 @@ Object {
|
|
|
217
222
|
"selector": Object {
|
|
218
223
|
"done": true,
|
|
219
224
|
},
|
|
225
|
+
"sharingId": undefined,
|
|
220
226
|
"skip": undefined,
|
|
221
227
|
"sort": undefined,
|
|
222
228
|
},
|
|
@@ -259,6 +265,7 @@ Object {
|
|
|
259
265
|
"selector": Object {
|
|
260
266
|
"done": false,
|
|
261
267
|
},
|
|
268
|
+
"sharingId": undefined,
|
|
262
269
|
"skip": undefined,
|
|
263
270
|
"sort": Array [
|
|
264
271
|
Object {
|
|
@@ -298,6 +305,7 @@ Object {
|
|
|
298
305
|
"selector": Object {
|
|
299
306
|
"done": true,
|
|
300
307
|
},
|
|
308
|
+
"sharingId": undefined,
|
|
301
309
|
"skip": undefined,
|
|
302
310
|
"sort": undefined,
|
|
303
311
|
},
|
|
@@ -339,6 +347,7 @@ Object {
|
|
|
339
347
|
"partialFilter": undefined,
|
|
340
348
|
"referenced": undefined,
|
|
341
349
|
"selector": undefined,
|
|
350
|
+
"sharingId": undefined,
|
|
342
351
|
"skip": undefined,
|
|
343
352
|
"sort": undefined,
|
|
344
353
|
},
|
|
@@ -375,6 +384,7 @@ Object {
|
|
|
375
384
|
"partialFilter": undefined,
|
|
376
385
|
"referenced": undefined,
|
|
377
386
|
"selector": undefined,
|
|
387
|
+
"sharingId": undefined,
|
|
378
388
|
"skip": undefined,
|
|
379
389
|
"sort": undefined,
|
|
380
390
|
},
|
|
@@ -415,6 +425,7 @@ Object {
|
|
|
415
425
|
"partialFilter": undefined,
|
|
416
426
|
"referenced": undefined,
|
|
417
427
|
"selector": undefined,
|
|
428
|
+
"sharingId": undefined,
|
|
418
429
|
"skip": undefined,
|
|
419
430
|
"sort": undefined,
|
|
420
431
|
},
|
|
@@ -450,6 +461,7 @@ Object {
|
|
|
450
461
|
"selector": Object {
|
|
451
462
|
"done": true,
|
|
452
463
|
},
|
|
464
|
+
"sharingId": undefined,
|
|
453
465
|
"skip": undefined,
|
|
454
466
|
"sort": undefined,
|
|
455
467
|
},
|
|
@@ -492,6 +504,7 @@ Object {
|
|
|
492
504
|
"partialFilter": undefined,
|
|
493
505
|
"referenced": undefined,
|
|
494
506
|
"selector": undefined,
|
|
507
|
+
"sharingId": undefined,
|
|
495
508
|
"skip": undefined,
|
|
496
509
|
"sort": undefined,
|
|
497
510
|
},
|
|
@@ -525,6 +538,7 @@ Object {
|
|
|
525
538
|
"partialFilter": undefined,
|
|
526
539
|
"referenced": undefined,
|
|
527
540
|
"selector": undefined,
|
|
541
|
+
"sharingId": undefined,
|
|
528
542
|
"skip": undefined,
|
|
529
543
|
"sort": undefined,
|
|
530
544
|
},
|
|
@@ -565,6 +579,7 @@ Object {
|
|
|
565
579
|
"partialFilter": undefined,
|
|
566
580
|
"referenced": undefined,
|
|
567
581
|
"selector": undefined,
|
|
582
|
+
"sharingId": undefined,
|
|
568
583
|
"skip": undefined,
|
|
569
584
|
"sort": undefined,
|
|
570
585
|
},
|
|
@@ -602,6 +617,7 @@ Object {
|
|
|
602
617
|
"selector": Object {
|
|
603
618
|
"done": true,
|
|
604
619
|
},
|
|
620
|
+
"sharingId": undefined,
|
|
605
621
|
"skip": undefined,
|
|
606
622
|
"sort": undefined,
|
|
607
623
|
},
|
|
@@ -646,6 +662,7 @@ Object {
|
|
|
646
662
|
"partialFilter": undefined,
|
|
647
663
|
"referenced": undefined,
|
|
648
664
|
"selector": undefined,
|
|
665
|
+
"sharingId": undefined,
|
|
649
666
|
"skip": undefined,
|
|
650
667
|
"sort": undefined,
|
|
651
668
|
},
|
|
@@ -681,6 +698,7 @@ Object {
|
|
|
681
698
|
"selector": Object {
|
|
682
699
|
"done": false,
|
|
683
700
|
},
|
|
701
|
+
"sharingId": undefined,
|
|
684
702
|
"skip": undefined,
|
|
685
703
|
"sort": undefined,
|
|
686
704
|
},
|
|
@@ -723,6 +741,7 @@ Object {
|
|
|
723
741
|
"partialFilter": undefined,
|
|
724
742
|
"referenced": undefined,
|
|
725
743
|
"selector": undefined,
|
|
744
|
+
"sharingId": undefined,
|
|
726
745
|
"skip": undefined,
|
|
727
746
|
"sort": undefined,
|
|
728
747
|
},
|
|
@@ -761,6 +780,7 @@ Object {
|
|
|
761
780
|
},
|
|
762
781
|
"referenced": undefined,
|
|
763
782
|
"selector": undefined,
|
|
783
|
+
"sharingId": undefined,
|
|
764
784
|
"skip": undefined,
|
|
765
785
|
"sort": undefined,
|
|
766
786
|
},
|
package/dist/types.js
CHANGED
|
@@ -464,6 +464,7 @@ var _dsl = require("./queries/dsl");
|
|
|
464
464
|
* @property {CozyMetadata} [cozyMetadata] - Cozy Metadata
|
|
465
465
|
* @property {CozyClientDocumentMeta} [meta] - Pouch Metadata
|
|
466
466
|
* @property {boolean} [cozyLocalOnly] - When true the document should NOT be replicated to the remote database
|
|
467
|
+
* @property {string} [driveId] - Id of a shared drive, only for shared io.cozy.files
|
|
467
468
|
*/
|
|
468
469
|
|
|
469
470
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "60.
|
|
3
|
+
"version": "60.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@types/jest": "^26.0.20",
|
|
20
20
|
"@types/lodash": "^4.14.170",
|
|
21
21
|
"btoa": "^1.2.1",
|
|
22
|
-
"cozy-stack-client": "^60.
|
|
22
|
+
"cozy-stack-client": "^60.1.0",
|
|
23
23
|
"date-fns": "2.29.3",
|
|
24
24
|
"fast-deep-equal": "^3.1.3",
|
|
25
25
|
"json-stable-stringify": "^1.0.1",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"react-native-ios11-devicecheck": "^0.0.3"
|
|
75
75
|
},
|
|
76
76
|
"sideEffects": false,
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "78342f53c89c0c28a1559e6f0224249f4713c47b"
|
|
78
78
|
}
|
package/types/CozyClient.d.ts
CHANGED
|
@@ -40,6 +40,10 @@ export type CozyClientDocument = {
|
|
|
40
40
|
* - When true the document should NOT be replicated to the remote database
|
|
41
41
|
*/
|
|
42
42
|
cozyLocalOnly?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* - Id of a shared drive, only for shared io.cozy.files
|
|
45
|
+
*/
|
|
46
|
+
driveId?: string;
|
|
43
47
|
};
|
|
44
48
|
export type ClientOptions = {
|
|
45
49
|
client?: object;
|
|
@@ -361,9 +365,10 @@ declare class CozyClient {
|
|
|
361
365
|
* a [DocumentCollection]{@link https://docs.cozy.io/en/cozy-client/api/cozy-stack-client/#DocumentCollection} instance.
|
|
362
366
|
*
|
|
363
367
|
* @param {string} doctype The collection doctype.
|
|
368
|
+
* @param {object} options Options to pass to the collection
|
|
364
369
|
* @returns {import("./types").DocumentCollection} Collection corresponding to the doctype
|
|
365
370
|
*/
|
|
366
|
-
collection(doctype: string): import("./types").DocumentCollection;
|
|
371
|
+
collection(doctype: string, options?: object): import("./types").DocumentCollection;
|
|
367
372
|
fetch(method: any, path: any, body: any, options?: {}): any;
|
|
368
373
|
all(doctype: any): QueryDefinition;
|
|
369
374
|
find(doctype: any, selector?: any): QueryDefinition;
|
|
@@ -559,23 +564,6 @@ declare class CozyClient {
|
|
|
559
564
|
* @returns {Promise<import("./types").ClientResponse>}
|
|
560
565
|
*/
|
|
561
566
|
private requestQuery;
|
|
562
|
-
/**
|
|
563
|
-
* Save the document or array of documents into the persisted storage (if any)
|
|
564
|
-
*
|
|
565
|
-
* @private
|
|
566
|
-
* @param {CozyClientDocument | Array<CozyClientDocument>} data - Document or array of documents to be saved
|
|
567
|
-
* @returns {Promise<void>}
|
|
568
|
-
*/
|
|
569
|
-
private persistVirtualDocuments;
|
|
570
|
-
/**
|
|
571
|
-
* Save the document or array of documents into the persisted storage (if any)
|
|
572
|
-
*
|
|
573
|
-
* @private
|
|
574
|
-
* @param {CozyClientDocument} document - Document to be saved
|
|
575
|
-
* @param {boolean} enforce - When true, save the document even if `meta.rev` or `_rev` exist
|
|
576
|
-
* @returns {Promise<void>}
|
|
577
|
-
*/
|
|
578
|
-
private persistVirtualDocument;
|
|
579
567
|
/**
|
|
580
568
|
* Fetch relationships for a response (can be several docs).
|
|
581
569
|
* Fills the `relationships` attribute of each documents.
|
package/types/queries/dsl.d.ts
CHANGED
|
@@ -125,6 +125,7 @@ export class QueryDefinition {
|
|
|
125
125
|
* @param {number|null} [options.skip] - The number of docs to skip.
|
|
126
126
|
* @param {import('../types').CouchDBViewCursor} [options.cursor] - The cursor to paginate views.
|
|
127
127
|
* @param {string} [options.bookmark] - The bookmark to paginate mango queries.
|
|
128
|
+
* @param {string} [options.sharingId] - The id of the sharing
|
|
128
129
|
*/
|
|
129
130
|
constructor(options?: {
|
|
130
131
|
doctype: import('../types').Doctype;
|
|
@@ -141,6 +142,7 @@ export class QueryDefinition {
|
|
|
141
142
|
skip: number | null;
|
|
142
143
|
cursor: import('../types').CouchDBViewCursor;
|
|
143
144
|
bookmark: string;
|
|
145
|
+
sharingId: string;
|
|
144
146
|
});
|
|
145
147
|
doctype: string;
|
|
146
148
|
id: string;
|
|
@@ -156,6 +158,7 @@ export class QueryDefinition {
|
|
|
156
158
|
skip: number;
|
|
157
159
|
cursor: import("../types").CouchDBViewCursor;
|
|
158
160
|
bookmark: string;
|
|
161
|
+
sharingId: string;
|
|
159
162
|
/**
|
|
160
163
|
* Checks if the sort order matches the index' fields order.
|
|
161
164
|
*
|
|
@@ -291,6 +294,13 @@ export class QueryDefinition {
|
|
|
291
294
|
* @returns {QueryDefinition} The QueryDefinition object.
|
|
292
295
|
*/
|
|
293
296
|
referencedBy(document: object): QueryDefinition;
|
|
297
|
+
/**
|
|
298
|
+
* Use a sharingId to query documents coming from a sharing
|
|
299
|
+
*
|
|
300
|
+
* @param {string} id - The sharing doc id
|
|
301
|
+
* @returns {QueryDefinition} The QueryDefinition object.
|
|
302
|
+
*/
|
|
303
|
+
sharingById(id: string): QueryDefinition;
|
|
294
304
|
toDefinition(): {
|
|
295
305
|
doctype: string;
|
|
296
306
|
id: string;
|
|
@@ -306,6 +316,7 @@ export class QueryDefinition {
|
|
|
306
316
|
skip: number;
|
|
307
317
|
cursor: import("../types").CouchDBViewCursor;
|
|
308
318
|
bookmark: string;
|
|
319
|
+
sharingId: string;
|
|
309
320
|
};
|
|
310
321
|
}
|
|
311
322
|
declare const CREATE_DOCUMENT: "CREATE_DOCUMENT";
|
package/types/storage.d.ts
CHANGED
|
@@ -43,6 +43,10 @@ export type CozyClientDocument = {
|
|
|
43
43
|
* - When true the document should NOT be replicated to the remote database
|
|
44
44
|
*/
|
|
45
45
|
cozyLocalOnly?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* - Id of a shared drive, only for shared io.cozy.files
|
|
48
|
+
*/
|
|
49
|
+
driveId?: string;
|
|
46
50
|
};
|
|
47
51
|
import CozyClient from "./CozyClient";
|
|
48
52
|
import { QueryDefinition } from "./queries/dsl";
|
package/types/types.d.ts
CHANGED
|
@@ -815,6 +815,10 @@ export type CozyClientDocument = {
|
|
|
815
815
|
* - When true the document should NOT be replicated to the remote database
|
|
816
816
|
*/
|
|
817
817
|
cozyLocalOnly?: boolean;
|
|
818
|
+
/**
|
|
819
|
+
* - Id of a shared drive, only for shared io.cozy.files
|
|
820
|
+
*/
|
|
821
|
+
driveId?: string;
|
|
818
822
|
};
|
|
819
823
|
/**
|
|
820
824
|
* - A io.cozy.files document's metadata
|