cozy-client 55.0.0 → 56.0.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.
@@ -2191,8 +2191,7 @@ var CozyClient = /*#__PURE__*/function () {
2191
2191
  key: "register",
2192
2192
 
2193
2193
  /**
2194
- * Performs a complete OAuth flow using a Cordova webview
2195
- * or React Native WebView for auth.
2194
+ * Performs a complete OAuth flow using a React Native WebView for auth.
2196
2195
  * The `register` method's name has been chosen for compat reasons with the Authentication compo.
2197
2196
  *
2198
2197
  * @param {string} cozyURL Receives the URL of the cozy instance.
@@ -3098,7 +3097,7 @@ var CozyClient = /*#__PURE__*/function () {
3098
3097
  CozyClient.hooks = CozyClient.hooks || {};
3099
3098
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
3100
3099
 
3101
- CozyClient.version = "55.0.0";
3100
+ CozyClient.version = "56.0.0";
3102
3101
 
3103
3102
  _microee.default.mixin(CozyClient);
3104
3103
 
@@ -1,175 +1,12 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
- exports.authFunction = exports.authenticateWithCordova = void 0;
9
-
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
-
14
- var _const = require("../const");
15
-
16
- var _cozyDeviceHelper = require("cozy-device-helper");
17
-
18
- /* global prompt */
19
-
20
- /**
21
- * @type {import("../types").CordovaWindow}
22
- */
23
- // @ts-ignore
24
- var win = typeof window !== 'undefined' ? window : null;
25
- /**
26
- * Open a SafariView Controller and resolve with the URL containing the token
27
- *
28
- * @param {string} url - Url containing access_code and state
29
- * @returns {Promise}
30
- */
31
-
32
- var authenticateWithSafari = function authenticateWithSafari(url) {
33
- return new Promise(function (resolve, reject) {
34
- win.SafariViewController.show({
35
- url: url,
36
- transition: 'curl' // (this only works in iOS 9.1/9.2 and lower) unless animated is false you can choose from: curl, flip, fade, slide (default)
37
- // enterReaderModeIfAvailable: readerMode, // default false
38
- // tintColor: "#00ffff", // default is ios blue
39
- // barColor: "#0000ff", // on iOS 10+ you can change the background color as well
40
- // controlTintColor: "#ffffff" // on iOS 10+ you can override the default tintColor
41
-
42
- }, // this success handler will be invoked for the lifecycle events 'opened', 'loaded' and 'closed'
43
- function (result) {
44
- if (result.event === 'closed') {
45
- reject(new Error(_const.REGISTRATION_ABORT));
46
- }
47
- }, function (error) {
48
- console.log('KO: ' + error);
49
- reject(new Error(_const.REGISTRATION_ABORT));
50
- });
51
- var handle = win.handleOpenURL;
52
-
53
- win.handleOpenURL = function (url) {
54
- win.SafariViewController.hide();
55
- resolve(url);
56
-
57
- if (handle) {
58
- win.handleOpenURL = handle;
59
- }
60
- };
61
- });
62
- };
63
- /**
64
- * Opens an InAppBrowser and resolves with the URL containing the token
65
- *
66
- * @param {string} url - Url containing access_code and state
67
- * @returns {Promise}
68
- */
69
-
70
-
71
- var authenticateWithInAppBrowser = function authenticateWithInAppBrowser(url) {
72
- return new Promise(function (resolve, reject) {
73
- var target = '_blank';
74
- var options = 'clearcache=yes,zoom=no';
75
- var inAppBrowser = win.cordova.InAppBrowser.open(url, target, options);
76
-
77
- var removeListener = function removeListener() {
78
- inAppBrowser.removeEventListener('loadstart', onLoadStart);
79
- inAppBrowser.removeEventListener('exit', onExit);
80
- };
6
+ exports.authFunction = void 0;
81
7
 
82
- var onLoadStart = function onLoadStart(_ref) {
83
- var url = _ref.url;
84
- var accessCode = /\?access_code=(.+)$/.test(url);
85
- var state = /\?state=(.+)$/.test(url);
86
-
87
- if (accessCode || state) {
88
- resolve(url);
89
- removeListener();
90
- inAppBrowser.close();
91
- }
92
- };
93
-
94
- var onExit = function onExit() {
95
- reject(new Error(_const.REGISTRATION_ABORT));
96
- removeListener();
97
- inAppBrowser.close();
98
- };
99
-
100
- inAppBrowser.addEventListener('loadstart', onLoadStart);
101
- inAppBrowser.addEventListener('exit', onExit);
102
- });
8
+ var authFunction = function authFunction() {
9
+ throw 'Not implemented';
103
10
  };
104
11
 
105
- var authenticateWithCordova = /*#__PURE__*/function () {
106
- var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(url) {
107
- return _regenerator.default.wrap(function _callee$(_context) {
108
- while (1) {
109
- switch (_context.prev = _context.next) {
110
- case 0:
111
- _context.t0 = (0, _cozyDeviceHelper.isIOSApp)();
112
-
113
- if (!_context.t0) {
114
- _context.next = 5;
115
- break;
116
- }
117
-
118
- _context.next = 4;
119
- return (0, _cozyDeviceHelper.hasSafariPlugin)();
120
-
121
- case 4:
122
- _context.t0 = _context.sent;
123
-
124
- case 5:
125
- if (!_context.t0) {
126
- _context.next = 9;
127
- break;
128
- }
129
-
130
- return _context.abrupt("return", authenticateWithSafari(url));
131
-
132
- case 9:
133
- if (!(0, _cozyDeviceHelper.hasInAppBrowserPlugin)()) {
134
- _context.next = 13;
135
- break;
136
- }
137
-
138
- return _context.abrupt("return", authenticateWithInAppBrowser(url));
139
-
140
- case 13:
141
- /**
142
- * for dev purpose:
143
- * In oauth workflow, the server displays an authorization page
144
- * User must accept to give permission then the server gives an url
145
- * with query parameters used by cozy-client-js to initialize itself.
146
- *
147
- * This hack let developers open the authorization page in a new tab
148
- * then get the "access_code" url and paste it in the prompt to let the
149
- * application initialize and redirect to other pages.
150
- */
151
- console.log(url); // Useful for dev (see above).
152
-
153
- return _context.abrupt("return", new Promise(function (resolve) {
154
- setTimeout(function () {
155
- var token = prompt('Paste the url here:');
156
- resolve(token);
157
- }, 5000);
158
- }));
159
-
160
- case 15:
161
- case "end":
162
- return _context.stop();
163
- }
164
- }
165
- }, _callee);
166
- }));
167
-
168
- return function authenticateWithCordova(_x) {
169
- return _ref2.apply(this, arguments);
170
- };
171
- }();
172
-
173
- exports.authenticateWithCordova = authenticateWithCordova;
174
- var authFunction = authenticateWithCordova;
175
12
  exports.authFunction = authFunction;
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.normalize = normalize;
9
9
  exports.ensureFilePath = ensureFilePath;
10
10
  exports.getParentFolderId = getParentFolderId;
11
- exports.downloadFile = exports.copy = exports.fetchBlobFileById = exports.isFromKonnector = exports.hasCertifications = exports.hasQualifications = exports.isPlainText = exports.doMobileUpload = exports.readMobileFile = exports.uploadFileWithConflictStrategy = exports.generateFileNameForRevision = exports.generateNewFileNameOnConflict = exports.overrideFileForPath = exports.move = exports.getFullpath = exports.hasMetadataAttribute = exports.fetchFilesByQualificationRules = exports.saveFileQualification = exports.isSharingShorcutNew = exports.isSharingShortcutNew = exports.isSharingShorcut = exports.isSharingShortcut = exports.getSharingShortcutTargetDoctype = exports.getSharingShortcutTargetMime = exports.getSharingShortcutStatus = exports.isShortcut = exports.shouldBeOpenedByOnlyOffice = exports.isOnlyOfficeFile = exports.isEncryptedFileOrFolder = exports.isEncryptedFolder = exports.getEncryptiondRef = exports.isEncrypted = exports.isNote = exports.isDirectory = exports.isFile = exports.splitFilename = exports.ALBUMS_DOCTYPE = void 0;
11
+ exports.downloadFile = exports.copy = exports.fetchBlobFileById = exports.isFromKonnector = exports.hasCertifications = exports.hasQualifications = exports.isPlainText = exports.uploadFileWithConflictStrategy = exports.generateFileNameForRevision = exports.generateNewFileNameOnConflict = exports.overrideFileForPath = exports.move = exports.getFullpath = exports.hasMetadataAttribute = exports.fetchFilesByQualificationRules = exports.saveFileQualification = exports.isSharingShorcutNew = exports.isSharingShortcutNew = exports.isSharingShorcut = exports.isSharingShortcut = exports.getSharingShortcutTargetDoctype = exports.getSharingShortcutTargetMime = exports.getSharingShortcutStatus = exports.isShortcut = exports.shouldBeOpenedByOnlyOffice = exports.isOnlyOfficeFile = exports.isEncryptedFileOrFolder = exports.isEncryptedFolder = exports.getEncryptiondRef = exports.isEncrypted = exports.isNote = exports.isDirectory = exports.isFile = exports.splitFilename = exports.ALBUMS_DOCTYPE = void 0;
12
12
 
13
13
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
14
14
 
@@ -890,155 +890,6 @@ var uploadFileWithConflictStrategy = /*#__PURE__*/function () {
890
890
  return _ref8.apply(this, arguments);
891
891
  };
892
892
  }();
893
- /**
894
- * Read a file on a mobile
895
- *
896
- * @param {string} fileURL - The local file path (file://)
897
- */
898
-
899
-
900
- exports.uploadFileWithConflictStrategy = uploadFileWithConflictStrategy;
901
-
902
- var readMobileFile = /*#__PURE__*/function () {
903
- var _ref9 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(fileURL) {
904
- var p;
905
- return _regenerator.default.wrap(function _callee10$(_context10) {
906
- while (1) {
907
- switch (_context10.prev = _context10.next) {
908
- case 0:
909
- /** Cordova plugin doesn't support promise since they are supporting Android 4.X.X
910
- * so we have to create manually a promise to be able to write beautiful code ;)
911
- */
912
- p = new Promise(function (resolve, reject) {
913
- var onResolvedLocalFS = /*#__PURE__*/function () {
914
- var _ref10 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(fileEntry) {
915
- return _regenerator.default.wrap(function _callee9$(_context9) {
916
- while (1) {
917
- switch (_context9.prev = _context9.next) {
918
- case 0:
919
- fileEntry.file( /*#__PURE__*/function () {
920
- var _ref11 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(file) {
921
- var reader;
922
- return _regenerator.default.wrap(function _callee8$(_context8) {
923
- while (1) {
924
- switch (_context8.prev = _context8.next) {
925
- case 0:
926
- reader = new FileReader();
927
- reader.onloadend = /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7() {
928
- return _regenerator.default.wrap(function _callee7$(_context7) {
929
- while (1) {
930
- switch (_context7.prev = _context7.next) {
931
- case 0:
932
- resolve(reader.result);
933
-
934
- case 1:
935
- case "end":
936
- return _context7.stop();
937
- }
938
- }
939
- }, _callee7);
940
- })); // Read the file as an ArrayBuffer
941
-
942
- reader.readAsArrayBuffer(file);
943
-
944
- case 3:
945
- case "end":
946
- return _context8.stop();
947
- }
948
- }
949
- }, _callee8);
950
- }));
951
-
952
- return function (_x21) {
953
- return _ref11.apply(this, arguments);
954
- };
955
- }(), function (err) {
956
- // Since this module is pretty recent, let's have this info in sentry if needed
957
- console.error('error getting fileentry file!' + err); // eslint-disable-line no-console
958
-
959
- reject(err);
960
- });
961
-
962
- case 1:
963
- case "end":
964
- return _context9.stop();
965
- }
966
- }
967
- }, _callee9);
968
- }));
969
-
970
- return function onResolvedLocalFS(_x20) {
971
- return _ref10.apply(this, arguments);
972
- };
973
- }();
974
-
975
- var onError = function onError(error) {
976
- reject(error);
977
- };
978
- /**
979
- * file:/// can not be converted to a fileEntry without the Cordova's File plugin.
980
- * `resolveLocalFileSystemURL` is provided by this plugin and can resolve the native
981
- * path to a fileEntry readable by a `FileReader`
982
- *
983
- * When we finished to read the fileEntry as buffer, we start the upload process
984
- *
985
- */
986
- // @ts-ignore
987
-
988
-
989
- window.resolveLocalFileSystemURL(fileURL, onResolvedLocalFS, onError);
990
- });
991
- return _context10.abrupt("return", p);
992
-
993
- case 2:
994
- case "end":
995
- return _context10.stop();
996
- }
997
- }
998
- }, _callee10);
999
- }));
1000
-
1001
- return function readMobileFile(_x19) {
1002
- return _ref9.apply(this, arguments);
1003
- };
1004
- }();
1005
- /**
1006
- * Upload a file on a mobile
1007
- *
1008
- * @param {CozyClient} client - The CozyClient instance
1009
- * @param {string} fileURL - The local file path (file://)
1010
- * @param {FileUploadOptions} options - The upload options
1011
- */
1012
-
1013
-
1014
- exports.readMobileFile = readMobileFile;
1015
-
1016
- var doMobileUpload = /*#__PURE__*/function () {
1017
- var _ref13 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11(client, fileURL, options) {
1018
- var file;
1019
- return _regenerator.default.wrap(function _callee11$(_context11) {
1020
- while (1) {
1021
- switch (_context11.prev = _context11.next) {
1022
- case 0:
1023
- _context11.next = 2;
1024
- return readMobileFile(fileURL);
1025
-
1026
- case 2:
1027
- file = _context11.sent;
1028
- return _context11.abrupt("return", uploadFileWithConflictStrategy(client, file, options));
1029
-
1030
- case 4:
1031
- case "end":
1032
- return _context11.stop();
1033
- }
1034
- }
1035
- }, _callee11);
1036
- }));
1037
-
1038
- return function doMobileUpload(_x22, _x23, _x24) {
1039
- return _ref13.apply(this, arguments);
1040
- };
1041
- }();
1042
893
  /**
1043
894
  * @param {string} [mimeType=''] - Mime type of file
1044
895
  * @param {string} [fileName=''] - Name of file
@@ -1046,7 +897,7 @@ var doMobileUpload = /*#__PURE__*/function () {
1046
897
  */
1047
898
 
1048
899
 
1049
- exports.doMobileUpload = doMobileUpload;
900
+ exports.uploadFileWithConflictStrategy = uploadFileWithConflictStrategy;
1050
901
 
1051
902
  var isPlainText = function isPlainText() {
1052
903
  var mimeType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
@@ -1096,35 +947,35 @@ var isFromKonnector = function isFromKonnector(file) {
1096
947
  exports.isFromKonnector = isFromKonnector;
1097
948
 
1098
949
  var fetchBlobFileById = /*#__PURE__*/function () {
1099
- var _ref14 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12(client, fileId) {
950
+ var _ref9 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(client, fileId) {
1100
951
  var fileColl, fileBin, fileBlob;
1101
- return _regenerator.default.wrap(function _callee12$(_context12) {
952
+ return _regenerator.default.wrap(function _callee7$(_context7) {
1102
953
  while (1) {
1103
- switch (_context12.prev = _context12.next) {
954
+ switch (_context7.prev = _context7.next) {
1104
955
  case 0:
1105
956
  fileColl = client.collection(_const.DOCTYPE_FILES);
1106
- _context12.next = 3;
957
+ _context7.next = 3;
1107
958
  return fileColl.fetchFileContentById(fileId);
1108
959
 
1109
960
  case 3:
1110
- fileBin = _context12.sent;
1111
- _context12.next = 6;
961
+ fileBin = _context7.sent;
962
+ _context7.next = 6;
1112
963
  return fileBin.blob();
1113
964
 
1114
965
  case 6:
1115
- fileBlob = _context12.sent;
1116
- return _context12.abrupt("return", fileBlob);
966
+ fileBlob = _context7.sent;
967
+ return _context7.abrupt("return", fileBlob);
1117
968
 
1118
969
  case 8:
1119
970
  case "end":
1120
- return _context12.stop();
971
+ return _context7.stop();
1121
972
  }
1122
973
  }
1123
- }, _callee12);
974
+ }, _callee7);
1124
975
  }));
1125
976
 
1126
- return function fetchBlobFileById(_x25, _x26) {
1127
- return _ref14.apply(this, arguments);
977
+ return function fetchBlobFileById(_x19, _x20) {
978
+ return _ref9.apply(this, arguments);
1128
979
  };
1129
980
  }();
1130
981
  /**
@@ -1141,80 +992,80 @@ var fetchBlobFileById = /*#__PURE__*/function () {
1141
992
  exports.fetchBlobFileById = fetchBlobFileById;
1142
993
 
1143
994
  var copy = /*#__PURE__*/function () {
1144
- var _ref15 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(client, file, destination) {
995
+ var _ref10 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(client, file, destination) {
1145
996
  var _resp2, _resp3, _resp4, resp;
1146
997
 
1147
- return _regenerator.default.wrap(function _callee13$(_context13) {
998
+ return _regenerator.default.wrap(function _callee8$(_context8) {
1148
999
  while (1) {
1149
- switch (_context13.prev = _context13.next) {
1000
+ switch (_context8.prev = _context8.next) {
1150
1001
  case 0:
1151
- _context13.prev = 0;
1002
+ _context8.prev = 0;
1152
1003
 
1153
1004
  if (!(file._type === 'io.cozy.remote.nextcloud.files' && destination._type === 'io.cozy.remote.nextcloud.files')) {
1154
- _context13.next = 6;
1005
+ _context8.next = 6;
1155
1006
  break;
1156
1007
  }
1157
1008
 
1158
- _context13.next = 4;
1009
+ _context8.next = 4;
1159
1010
  return client.collection('io.cozy.remote.nextcloud.files').copy(file, destination);
1160
1011
 
1161
1012
  case 4:
1162
- _resp2 = _context13.sent;
1163
- return _context13.abrupt("return", _resp2);
1013
+ _resp2 = _context8.sent;
1014
+ return _context8.abrupt("return", _resp2);
1164
1015
 
1165
1016
  case 6:
1166
1017
  if (!(file._type === 'io.cozy.remote.nextcloud.files' && destination._type === 'io.cozy.files')) {
1167
- _context13.next = 11;
1018
+ _context8.next = 11;
1168
1019
  break;
1169
1020
  }
1170
1021
 
1171
- _context13.next = 9;
1022
+ _context8.next = 9;
1172
1023
  return client.collection('io.cozy.remote.nextcloud.files').moveToCozy(file, destination, {
1173
1024
  copy: true
1174
1025
  });
1175
1026
 
1176
1027
  case 9:
1177
- _resp3 = _context13.sent;
1178
- return _context13.abrupt("return", _resp3);
1028
+ _resp3 = _context8.sent;
1029
+ return _context8.abrupt("return", _resp3);
1179
1030
 
1180
1031
  case 11:
1181
1032
  if (!(destination._type === 'io.cozy.remote.nextcloud.files')) {
1182
- _context13.next = 16;
1033
+ _context8.next = 16;
1183
1034
  break;
1184
1035
  }
1185
1036
 
1186
- _context13.next = 14;
1037
+ _context8.next = 14;
1187
1038
  return client.collection('io.cozy.remote.nextcloud.files').moveFromCozy(destination, file, {
1188
1039
  copy: true
1189
1040
  });
1190
1041
 
1191
1042
  case 14:
1192
- _resp4 = _context13.sent;
1193
- return _context13.abrupt("return", _resp4);
1043
+ _resp4 = _context8.sent;
1044
+ return _context8.abrupt("return", _resp4);
1194
1045
 
1195
1046
  case 16:
1196
- _context13.next = 18;
1047
+ _context8.next = 18;
1197
1048
  return client.collection(_const.DOCTYPE_FILES).copy(file._id, undefined, destination._id);
1198
1049
 
1199
1050
  case 18:
1200
- resp = _context13.sent;
1201
- return _context13.abrupt("return", resp);
1051
+ resp = _context8.sent;
1052
+ return _context8.abrupt("return", resp);
1202
1053
 
1203
1054
  case 22:
1204
- _context13.prev = 22;
1205
- _context13.t0 = _context13["catch"](0);
1206
- throw _context13.t0;
1055
+ _context8.prev = 22;
1056
+ _context8.t0 = _context8["catch"](0);
1057
+ throw _context8.t0;
1207
1058
 
1208
1059
  case 25:
1209
1060
  case "end":
1210
- return _context13.stop();
1061
+ return _context8.stop();
1211
1062
  }
1212
1063
  }
1213
- }, _callee13, null, [[0, 22]]);
1064
+ }, _callee8, null, [[0, 22]]);
1214
1065
  }));
1215
1066
 
1216
- return function copy(_x27, _x28, _x29) {
1217
- return _ref15.apply(this, arguments);
1067
+ return function copy(_x21, _x22, _x23) {
1068
+ return _ref10.apply(this, arguments);
1218
1069
  };
1219
1070
  }();
1220
1071
  /**
@@ -1238,83 +1089,83 @@ var copy = /*#__PURE__*/function () {
1238
1089
  exports.copy = copy;
1239
1090
 
1240
1091
  var downloadFile = /*#__PURE__*/function () {
1241
- var _ref17 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee14(_ref16) {
1092
+ var _ref12 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(_ref11) {
1242
1093
  var client, file, url, webviewIntent, filesCollection, _yield$webviewIntent$, isFlagshipDownloadAvailable;
1243
1094
 
1244
- return _regenerator.default.wrap(function _callee14$(_context14) {
1095
+ return _regenerator.default.wrap(function _callee9$(_context9) {
1245
1096
  while (1) {
1246
- switch (_context14.prev = _context14.next) {
1097
+ switch (_context9.prev = _context9.next) {
1247
1098
  case 0:
1248
- client = _ref16.client, file = _ref16.file, url = _ref16.url, webviewIntent = _ref16.webviewIntent;
1099
+ client = _ref11.client, file = _ref11.file, url = _ref11.url, webviewIntent = _ref11.webviewIntent;
1249
1100
  filesCollection = client.collection(_const.DOCTYPE_FILES);
1250
1101
 
1251
1102
  if (!((0, _cozyDeviceHelper.isFlagshipApp)() && webviewIntent && !isEncrypted(file))) {
1252
- _context14.next = 19;
1103
+ _context9.next = 19;
1253
1104
  break;
1254
1105
  }
1255
1106
 
1256
- _context14.next = 5;
1107
+ _context9.next = 5;
1257
1108
  return webviewIntent === null || webviewIntent === void 0 ? void 0 : webviewIntent.call('isAvailable', 'downloadFile');
1258
1109
 
1259
1110
  case 5:
1260
- _context14.t1 = _yield$webviewIntent$ = _context14.sent;
1261
- _context14.t0 = _context14.t1 !== null;
1111
+ _context9.t1 = _yield$webviewIntent$ = _context9.sent;
1112
+ _context9.t0 = _context9.t1 !== null;
1262
1113
 
1263
- if (!_context14.t0) {
1264
- _context14.next = 9;
1114
+ if (!_context9.t0) {
1115
+ _context9.next = 9;
1265
1116
  break;
1266
1117
  }
1267
1118
 
1268
- _context14.t0 = _yield$webviewIntent$ !== void 0;
1119
+ _context9.t0 = _yield$webviewIntent$ !== void 0;
1269
1120
 
1270
1121
  case 9:
1271
- if (!_context14.t0) {
1272
- _context14.next = 13;
1122
+ if (!_context9.t0) {
1123
+ _context9.next = 13;
1273
1124
  break;
1274
1125
  }
1275
1126
 
1276
- _context14.t2 = _yield$webviewIntent$;
1277
- _context14.next = 14;
1127
+ _context9.t2 = _yield$webviewIntent$;
1128
+ _context9.next = 14;
1278
1129
  break;
1279
1130
 
1280
1131
  case 13:
1281
- _context14.t2 = false;
1132
+ _context9.t2 = false;
1282
1133
 
1283
1134
  case 14:
1284
- isFlagshipDownloadAvailable = _context14.t2;
1135
+ isFlagshipDownloadAvailable = _context9.t2;
1285
1136
 
1286
1137
  if (!isFlagshipDownloadAvailable) {
1287
- _context14.next = 19;
1138
+ _context9.next = 19;
1288
1139
  break;
1289
1140
  }
1290
1141
 
1291
- _context14.next = 18;
1142
+ _context9.next = 18;
1292
1143
  return webviewIntent.call('downloadFile', file);
1293
1144
 
1294
1145
  case 18:
1295
- return _context14.abrupt("return", _context14.sent);
1146
+ return _context9.abrupt("return", _context9.sent);
1296
1147
 
1297
1148
  case 19:
1298
1149
  if (!isEncrypted(file)) {
1299
- _context14.next = 21;
1150
+ _context9.next = 21;
1300
1151
  break;
1301
1152
  }
1302
1153
 
1303
- return _context14.abrupt("return", filesCollection.forceFileDownload(url, file.name));
1154
+ return _context9.abrupt("return", filesCollection.forceFileDownload(url, file.name));
1304
1155
 
1305
1156
  case 21:
1306
- return _context14.abrupt("return", filesCollection.download(file));
1157
+ return _context9.abrupt("return", filesCollection.download(file));
1307
1158
 
1308
1159
  case 22:
1309
1160
  case "end":
1310
- return _context14.stop();
1161
+ return _context9.stop();
1311
1162
  }
1312
1163
  }
1313
- }, _callee14);
1164
+ }, _callee9);
1314
1165
  }));
1315
1166
 
1316
- return function downloadFile(_x30) {
1317
- return _ref17.apply(this, arguments);
1167
+ return function downloadFile(_x24) {
1168
+ return _ref12.apply(this, arguments);
1318
1169
  };
1319
1170
  }();
1320
1171
 
package/dist/types.js CHANGED
@@ -698,21 +698,6 @@ var _dsl = require("./queries/dsl");
698
698
  * @description Read more about client capabilities here https://docs.cozy.io/en/cozy-stack/settings/#get-settingscapabilities.
699
699
  */
700
700
 
701
- /**
702
- * @typedef Cordova
703
- * @property {FilePlugin} file
704
- * @property {InAppBrowser} InAppBrowser
705
- * @property {object} plugins
706
- */
707
-
708
- /**
709
- * @typedef CordovaWindow
710
- * @property {Cordova} cordova
711
- * @property {object} SafariViewController
712
- * @property {Function} resolveLocalFileSystemURL
713
- * @property {Function} handleOpenURL
714
- */
715
-
716
701
  /**
717
702
  * @typedef {object} CouchDBDocument - A document
718
703
  * @property {string} _id - Id of the document
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "55.0.0",
3
+ "version": "56.0.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -18,7 +18,7 @@
18
18
  "@types/jest": "^26.0.20",
19
19
  "@types/lodash": "^4.14.170",
20
20
  "btoa": "^1.2.1",
21
- "cozy-stack-client": "^55.0.0",
21
+ "cozy-stack-client": "^56.0.0",
22
22
  "date-fns": "2.29.3",
23
23
  "json-stable-stringify": "^1.0.1",
24
24
  "lodash": "^4.17.13",
@@ -72,5 +72,5 @@
72
72
  "react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
73
73
  },
74
74
  "sideEffects": false,
75
- "gitHead": "903ab3040dca4754c2fe24568fdd49510562b7b2"
75
+ "gitHead": "1c6c85248b511c0f8a3a64556190abcc9925d361"
76
76
  }
@@ -643,8 +643,7 @@ declare class CozyClient {
643
643
  options: import("./types").QueryOptions;
644
644
  }) => Promise<import("./types").QueryState>;
645
645
  /**
646
- * Performs a complete OAuth flow using a Cordova webview
647
- * or React Native WebView for auth.
646
+ * Performs a complete OAuth flow using a React Native WebView for auth.
648
647
  * The `register` method's name has been chosen for compat reasons with the Authentication compo.
649
648
  *
650
649
  * @param {string} cozyURL Receives the URL of the cozy instance.
@@ -1,2 +1 @@
1
- export function authenticateWithCordova(url: any): Promise<any>;
2
- export function authFunction(url: any): Promise<any>;
1
+ export function authFunction(): never;
@@ -63,8 +63,6 @@ export function overrideFileForPath(client: CozyClient, dirPath: string, file: o
63
63
  export function generateNewFileNameOnConflict(filenameWithoutExtension: string, conflictOptions?: import('../types').ConflictOptions): string;
64
64
  export function generateFileNameForRevision(file: import("../types").IOCozyFile, revision: object, f: Function): string;
65
65
  export function uploadFileWithConflictStrategy(client: CozyClient, file: string | ArrayBuffer, options: FileUploadOptions): any;
66
- export function readMobileFile(fileURL: string): Promise<any>;
67
- export function doMobileUpload(client: CozyClient, fileURL: string, options: FileUploadOptions): Promise<any>;
68
66
  export function isPlainText(mimeType?: string, fileName?: string): boolean;
69
67
  export function hasQualifications(file: import("../types").IOCozyFile): boolean;
70
68
  export function hasCertifications(file: import("../types").IOCozyFile): boolean;
package/types/types.d.ts CHANGED
@@ -1375,17 +1375,6 @@ export type ClientCapabilities = {
1375
1375
  */
1376
1376
  flat_subdomains?: boolean;
1377
1377
  };
1378
- export type Cordova = {
1379
- file: FilePlugin;
1380
- InAppBrowser: InAppBrowser;
1381
- plugins: object;
1382
- };
1383
- export type CordovaWindow = {
1384
- cordova: Cordova;
1385
- SafariViewController: object;
1386
- resolveLocalFileSystemURL: Function;
1387
- handleOpenURL: Function;
1388
- };
1389
1378
  /**
1390
1379
  * - A document
1391
1380
  */
@@ -1,436 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = exports.openFileWith = exports.openOfflineFile = exports.getNativeFile = exports.saveAndOpenWithCordova = exports.temporarySave = exports.saveFileWithCordova = exports.deleteOfflineFile = exports.openFileWithCordova = exports.writeFile = exports.getDirectory = exports.createCozyPath = exports.getCozyEntry = exports.getEntry = exports.getCozyPath = exports.getTemporaryRootPath = exports.getRootPath = void 0;
9
-
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
-
14
- var _cozyDeviceHelper = require("cozy-device-helper");
15
-
16
- var _CozyClient = _interopRequireDefault(require("../CozyClient"));
17
-
18
- var _types = require("../types");
19
-
20
- var _logger = _interopRequireDefault(require("../logger"));
21
-
22
- var _const = require("../const");
23
-
24
- var ERROR_GET_DIRECTORY = 'Error to get directory';
25
- var ERROR_WRITE_FILE = 'Error to write file';
26
- var ERROR_GET_FILE = 'Error to get file';
27
- var COZY_PATH = 'Cozy';
28
- var COZY_FILES_PATH = (0, _cozyDeviceHelper.isIOS)() ? 'CozyDrive' : 'Cozy Drive';
29
- /**
30
- * @typedef {object} FilesystemEntry
31
- */
32
-
33
- /**
34
- * @type {CordovaWindow}
35
- */
36
- // @ts-ignore
37
-
38
- var win = window;
39
- /**
40
- * Get root path according the OS
41
- *
42
- * @returns {string}
43
- */
44
-
45
- var getRootPath = function getRootPath() {
46
- return (0, _cozyDeviceHelper.isAndroidApp)() ? win.cordova.file.externalDataDirectory : win.cordova.file.dataDirectory;
47
- };
48
- /**
49
- * Get the temporary root path according to the OS
50
- */
51
-
52
-
53
- exports.getRootPath = getRootPath;
54
-
55
- var getTemporaryRootPath = function getTemporaryRootPath() {
56
- return (0, _cozyDeviceHelper.isAndroidApp)() ? win.cordova.file.externalCacheDirectory : win.cordova.file.cacheDirectory;
57
- };
58
- /**
59
- * Get Cozy path according to the OS
60
- *
61
- * @returns {string}
62
- */
63
-
64
-
65
- exports.getTemporaryRootPath = getTemporaryRootPath;
66
-
67
- var getCozyPath = function getCozyPath() {
68
- return COZY_PATH + '/' + COZY_FILES_PATH + '/';
69
- };
70
- /**
71
- * Get entry of a path in the cordova.file location
72
- *
73
- * @param {string} path - Path wanting to be getted
74
- * @returns {Promise<FilesystemEntry>}
75
- */
76
-
77
-
78
- exports.getCozyPath = getCozyPath;
79
-
80
- var getEntry = function getEntry(path) {
81
- return new Promise(function (resolve, reject) {
82
- win.resolveLocalFileSystemURL(path, resolve, function (err) {
83
- _logger.default.error("".concat(path, " could not be resolved: ").concat(err.message));
84
-
85
- reject(err);
86
- });
87
- });
88
- };
89
- /**
90
- * Get Cozy location on the device
91
- */
92
-
93
-
94
- exports.getEntry = getEntry;
95
-
96
- var getCozyEntry = function getCozyEntry() {
97
- return getEntry(getRootPath() + getCozyPath()).catch(function () {
98
- return createCozyPath();
99
- });
100
- };
101
- /**
102
- * Create Cozy path on the device
103
- */
104
-
105
-
106
- exports.getCozyEntry = getCozyEntry;
107
-
108
- var createCozyPath = function createCozyPath() {
109
- return getEntry(getRootPath()).then(function (entry) {
110
- return getDirectory(entry, COZY_PATH).then(function (entry) {
111
- return getDirectory(entry, COZY_FILES_PATH);
112
- });
113
- });
114
- };
115
- /**
116
- * Get the directory according to its name
117
- *
118
- * @param {object} rootDirEntry - The root directory entry
119
- * @param {string} folderName - The folder's name
120
- */
121
-
122
-
123
- exports.createCozyPath = createCozyPath;
124
-
125
- var getDirectory = function getDirectory(rootDirEntry, folderName) {
126
- return new Promise(function (resolve, reject) {
127
- rootDirEntry.getDirectory(folderName, {
128
- create: true
129
- }, resolve, function (error) {
130
- _logger.default.warn(ERROR_GET_DIRECTORY, folderName);
131
-
132
- _logger.default.warn(error);
133
-
134
- reject(ERROR_GET_DIRECTORY);
135
- });
136
- });
137
- };
138
- /**
139
- * @param {object} fileEntry - The file entry
140
- * @param {object} dataObj - The data to be written
141
- */
142
-
143
-
144
- exports.getDirectory = getDirectory;
145
-
146
- var writeFile = function writeFile(fileEntry, dataObj) {
147
- return new Promise(function (resolve, reject) {
148
- fileEntry.createWriter(function (fileWriter) {
149
- fileWriter.onwriteend = function () {
150
- resolve(fileEntry);
151
- };
152
-
153
- fileWriter.onerror = function (error) {
154
- _logger.default.warn(ERROR_WRITE_FILE);
155
-
156
- _logger.default.warn(error);
157
-
158
- reject(ERROR_WRITE_FILE);
159
- };
160
-
161
- fileWriter.write(dataObj);
162
- });
163
- });
164
- };
165
- /**
166
- * @param {object} dirEntry - The directory entry
167
- * @param {object} fileData - The file data
168
- * @param {string} fileName - The file name
169
- */
170
-
171
-
172
- exports.writeFile = writeFile;
173
-
174
- var saveFile = function saveFile(dirEntry, fileData, fileName) {
175
- return new Promise(function (resolve, reject) {
176
- dirEntry.getFile(fileName, {
177
- create: true,
178
- exclusive: false
179
- }, function (fileEntry) {
180
- writeFile(fileEntry, fileData).then(function () {
181
- resolve(fileEntry);
182
- }).catch(reject);
183
- }, function (error) {
184
- _logger.default.warn(ERROR_GET_FILE);
185
-
186
- _logger.default.warn(error);
187
-
188
- reject(ERROR_GET_FILE);
189
- });
190
- });
191
- };
192
- /**
193
- * Open a file in an other app
194
- *
195
- * @param {*} URI - URI to be opened
196
- * @param {*} mimetype - Mimetype of the opened file
197
- */
198
-
199
-
200
- var openFileWithCordova = function openFileWithCordova(URI, mimetype) {
201
- return new Promise(function (resolve, reject) {
202
- var callbacks = {
203
- error: reject,
204
- success: resolve
205
- };
206
- win.cordova.plugins.fileOpener2.open(URI, mimetype, callbacks);
207
- });
208
- };
209
- /**
210
- * @param {string} fileName - The file name
211
- */
212
-
213
-
214
- exports.openFileWithCordova = openFileWithCordova;
215
-
216
- var deleteOfflineFile = /*#__PURE__*/function () {
217
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(fileName) {
218
- var entry, fileEntry;
219
- return _regenerator.default.wrap(function _callee$(_context) {
220
- while (1) {
221
- switch (_context.prev = _context.next) {
222
- case 0:
223
- _context.next = 2;
224
- return getCozyEntry();
225
-
226
- case 2:
227
- entry = _context.sent;
228
- _context.next = 5;
229
- return getEntry("".concat(entry.nativeURL).concat(fileName));
230
-
231
- case 5:
232
- fileEntry = _context.sent;
233
- return _context.abrupt("return", fileEntry.remove());
234
-
235
- case 7:
236
- case "end":
237
- return _context.stop();
238
- }
239
- }
240
- }, _callee);
241
- }));
242
-
243
- return function deleteOfflineFile(_x) {
244
- return _ref.apply(this, arguments);
245
- };
246
- }();
247
- /**
248
- * @param {object} fileData - The file data
249
- * @param {string} fileName - The file name
250
- */
251
-
252
-
253
- exports.deleteOfflineFile = deleteOfflineFile;
254
-
255
- var saveFileWithCordova = function saveFileWithCordova(fileData, fileName) {
256
- return getCozyEntry().then(function (entry) {
257
- return saveFile(entry, fileData, fileName);
258
- });
259
- };
260
- /**
261
- * Save the document in the temporary folder
262
- *
263
- * @param {object} file - io.cozy.files document
264
- * @param {string} fileName - The file name
265
- */
266
-
267
-
268
- exports.saveFileWithCordova = saveFileWithCordova;
269
-
270
- var temporarySave = function temporarySave(file, fileName) {
271
- return getEntry(getTemporaryRootPath()).then(function (entry) {
272
- return saveFile(entry, file, fileName);
273
- });
274
- };
275
- /**
276
- * Save the document in the temporary folder and open it in an other app
277
- *
278
- * @param {Blob} blob - Binary of the file
279
- * @param {object} file - io.cozy.files document
280
- */
281
-
282
-
283
- exports.temporarySave = temporarySave;
284
-
285
- var saveAndOpenWithCordova = function saveAndOpenWithCordova(blob, file) {
286
- return temporarySave(blob, file.name).then(function (entry) {
287
- return openFileWithCordova(entry.nativeURL, file.mime);
288
- });
289
- };
290
- /**
291
- * @param {object} file - io.cozy.files document
292
- */
293
-
294
-
295
- exports.saveAndOpenWithCordova = saveAndOpenWithCordova;
296
-
297
- var getNativeFile = /*#__PURE__*/function () {
298
- var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(file) {
299
- var entry;
300
- return _regenerator.default.wrap(function _callee2$(_context2) {
301
- while (1) {
302
- switch (_context2.prev = _context2.next) {
303
- case 0:
304
- _context2.next = 2;
305
- return getCozyEntry();
306
-
307
- case 2:
308
- entry = _context2.sent;
309
- return _context2.abrupt("return", getEntry("".concat(entry.nativeURL).concat(file.id)));
310
-
311
- case 4:
312
- case "end":
313
- return _context2.stop();
314
- }
315
- }
316
- }, _callee2);
317
- }));
318
-
319
- return function getNativeFile(_x2) {
320
- return _ref2.apply(this, arguments);
321
- };
322
- }();
323
- /**
324
- * @param {object} file - io.cozy.files document
325
- */
326
-
327
-
328
- exports.getNativeFile = getNativeFile;
329
-
330
- var openOfflineFile = /*#__PURE__*/function () {
331
- var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(file) {
332
- var fileEntry;
333
- return _regenerator.default.wrap(function _callee3$(_context3) {
334
- while (1) {
335
- switch (_context3.prev = _context3.next) {
336
- case 0:
337
- _context3.next = 2;
338
- return getNativeFile(file);
339
-
340
- case 2:
341
- fileEntry = _context3.sent;
342
- return _context3.abrupt("return", openFileWithCordova(fileEntry.nativeURL, file.mime));
343
-
344
- case 4:
345
- case "end":
346
- return _context3.stop();
347
- }
348
- }
349
- }, _callee3);
350
- }));
351
-
352
- return function openOfflineFile(_x3) {
353
- return _ref3.apply(this, arguments);
354
- };
355
- }();
356
- /**
357
- * openFileWith - Opens a file on a mobile device
358
- *
359
- * @param {CozyClient} client - The CozyClient instance
360
- * @param {object} file - io.cozy.files document
361
- */
362
-
363
-
364
- exports.openOfflineFile = openOfflineFile;
365
-
366
- var openFileWith = /*#__PURE__*/function () {
367
- var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(client, file) {
368
- var fileData, blob;
369
- return _regenerator.default.wrap(function _callee4$(_context4) {
370
- while (1) {
371
- switch (_context4.prev = _context4.next) {
372
- case 0:
373
- if (!((0, _cozyDeviceHelper.isMobileApp)() && win.cordova.plugins.fileOpener2)) {
374
- _context4.next = 23;
375
- break;
376
- }
377
-
378
- _context4.prev = 1;
379
- _context4.next = 4;
380
- return client.collection(_const.DOCTYPE_FILES).fetchFileContent(file.id);
381
-
382
- case 4:
383
- fileData = _context4.sent;
384
- _context4.next = 10;
385
- break;
386
-
387
- case 7:
388
- _context4.prev = 7;
389
- _context4.t0 = _context4["catch"](1);
390
- throw _context4.t0.status === 404 ? 'missing' : 'offline';
391
-
392
- case 10:
393
- _context4.next = 12;
394
- return fileData.blob();
395
-
396
- case 12:
397
- blob = _context4.sent;
398
- _context4.prev = 13;
399
- _context4.next = 16;
400
- return fsnative.saveAndOpenWithCordova(blob, file);
401
-
402
- case 16:
403
- _context4.next = 21;
404
- break;
405
-
406
- case 18:
407
- _context4.prev = 18;
408
- _context4.t1 = _context4["catch"](13);
409
- throw 'noapp';
410
-
411
- case 21:
412
- _context4.next = 24;
413
- break;
414
-
415
- case 23:
416
- throw 'noapp';
417
-
418
- case 24:
419
- case "end":
420
- return _context4.stop();
421
- }
422
- }
423
- }, _callee4, null, [[1, 7], [13, 18]]);
424
- }));
425
-
426
- return function openFileWith(_x4, _x5) {
427
- return _ref4.apply(this, arguments);
428
- };
429
- }();
430
-
431
- exports.openFileWith = openFileWith;
432
- var fsnative = {
433
- saveAndOpenWithCordova: saveAndOpenWithCordova
434
- };
435
- var _default = fsnative;
436
- exports.default = _default;
@@ -1,118 +0,0 @@
1
- import { isMobileApp } from 'cozy-device-helper'
2
-
3
- import { createMockClient } from '../mock'
4
-
5
- import fsnative, { getRootPath, openFileWith } from './fsnative'
6
-
7
- jest.spyOn(fsnative, 'saveAndOpenWithCordova').mockReturnValue()
8
-
9
- jest.mock('cozy-device-helper', () => ({
10
- ...jest.requireActual('cozy-device-helper'),
11
- isMobileApp: jest.fn()
12
- }))
13
-
14
- const ANDROID_ROOT_DIRECTORY = 'externalDataDirectory'
15
- const IOS_ROOT_DIRECTORY = 'dataDirectory'
16
- const EXTERNAL_CACHE_DIRECTORY = 'externalCacheDirectory'
17
- const CACHE_DIRECTORY = 'cacheDirectory'
18
- const ANDROID = 'android'
19
- const IOS = 'ios'
20
-
21
- describe('getRootPath', () => {
22
- beforeEach(() => {
23
- window.cordova = {
24
- file: {
25
- externalDataDirectory: ANDROID_ROOT_DIRECTORY,
26
- dataDirectory: IOS_ROOT_DIRECTORY
27
- },
28
- platformId: ANDROID
29
- }
30
- })
31
-
32
- it('should get root path', () => {
33
- window.cordova.platformId = ANDROID
34
- expect(getRootPath()).toEqual(ANDROID_ROOT_DIRECTORY)
35
- window.cordova.platformId = IOS
36
- expect(getRootPath()).toEqual(IOS_ROOT_DIRECTORY)
37
- })
38
- })
39
-
40
- describe('openFileWith', () => {
41
- const mockClient = createMockClient({})
42
- const blobMock = jest.fn()
43
- const file = { id: 'fileId' }
44
-
45
- beforeEach(() => {
46
- jest.resetAllMocks()
47
- isMobileApp.mockReturnValue(true)
48
-
49
- mockClient.collection = jest.fn().mockReturnValue(mockClient)
50
- mockClient.fetchFileContent = jest.fn().mockReturnValue({
51
- blob: blobMock
52
- })
53
-
54
- window.cordova = {
55
- file: {
56
- externalCacheDirectory: EXTERNAL_CACHE_DIRECTORY,
57
- cacheDirectory: CACHE_DIRECTORY
58
- },
59
- plugins: { fileOpener2: {} }
60
- }
61
- })
62
-
63
- it('opens the file with cordova', async () => {
64
- blobMock.mockReturnValue('fake file blob')
65
- await openFileWith(mockClient, file)
66
- expect(mockClient.fetchFileContent).toHaveBeenCalledWith(file.id)
67
- expect(fsnative.saveAndOpenWithCordova).toHaveBeenCalledWith(
68
- 'fake file blob',
69
- file
70
- )
71
- })
72
-
73
- it('errors when it fails to download the file without 404', async () => {
74
- expect.assertions(1)
75
- mockClient.fetchFileContent = jest.fn().mockRejectedValue(new Error())
76
-
77
- try {
78
- await openFileWith(mockClient, file)
79
- } catch (e) {
80
- expect(e).toMatch('offline')
81
- }
82
- })
83
-
84
- it('errors when it fails to download the file with 404', async () => {
85
- expect.assertions(1)
86
- const error = new Error('Not Found')
87
- error.status = 404
88
- mockClient.fetchFileContent = jest.fn().mockRejectedValue(error)
89
-
90
- try {
91
- await openFileWith(mockClient, file)
92
- } catch (e) {
93
- expect(e).toMatch('missing')
94
- }
95
- })
96
-
97
- it('errors when opening the filewith cordova fails', async () => {
98
- expect.assertions(1)
99
- fsnative.saveAndOpenWithCordova.mockRejectedValue(new Error())
100
-
101
- try {
102
- await openFileWith(mockClient, file)
103
- } catch (e) {
104
- expect(e).toMatch('noapp')
105
- }
106
- })
107
-
108
- it('errors when the plugin is not present', async () => {
109
- expect.assertions(1)
110
- window.cordova.plugins.fileOpener2 = null
111
-
112
- try {
113
- await openFileWith(mockClient, file)
114
- } catch (e) {
115
- expect(e).toMatch('noapp')
116
- }
117
- })
118
- })
@@ -1,22 +0,0 @@
1
- export function getRootPath(): string;
2
- export function getTemporaryRootPath(): any;
3
- export function getCozyPath(): string;
4
- export function getEntry(path: string): Promise<FilesystemEntry>;
5
- export function getCozyEntry(): Promise<any>;
6
- export function createCozyPath(): Promise<any>;
7
- export function getDirectory(rootDirEntry: object, folderName: string): Promise<any>;
8
- export function writeFile(fileEntry: object, dataObj: object): Promise<any>;
9
- export function openFileWithCordova(URI: any, mimetype: any): Promise<any>;
10
- export function deleteOfflineFile(fileName: string): Promise<any>;
11
- export function saveFileWithCordova(fileData: object, fileName: string): Promise<any>;
12
- export function temporarySave(file: object, fileName: string): Promise<any>;
13
- export function saveAndOpenWithCordova(blob: Blob, file: object): Promise<any>;
14
- export function getNativeFile(file: object): Promise<any>;
15
- export function openOfflineFile(file: object): Promise<any>;
16
- export function openFileWith(client: CozyClient, file: object): Promise<void>;
17
- export default fsnative;
18
- export type FilesystemEntry = any;
19
- import CozyClient from "../CozyClient";
20
- declare namespace fsnative {
21
- export { saveAndOpenWithCordova };
22
- }