cozy-client 48.11.1 → 48.12.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.
@@ -2839,7 +2839,7 @@ var CozyClient = /*#__PURE__*/function () {
2839
2839
  CozyClient.hooks = CozyClient.hooks || {};
2840
2840
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2841
2841
 
2842
- CozyClient.version = "48.11.1";
2842
+ CozyClient.version = "48.12.0";
2843
2843
 
2844
2844
  _microee.default.mixin(CozyClient);
2845
2845
 
@@ -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.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.isEncrypted = exports.isNote = exports.isDirectory = exports.isFile = exports.splitFilename = exports.ALBUMS_DOCTYPE = void 0;
11
+ 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.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
 
@@ -482,9 +482,6 @@ var move = /*#__PURE__*/function () {
482
482
  force,
483
483
  resp,
484
484
  destinationPath,
485
- _yield$client$query2,
486
- movedFile,
487
- filename,
488
485
  conflictResp,
489
486
  _resp,
490
487
  _args4 = arguments;
@@ -570,59 +567,40 @@ var move = /*#__PURE__*/function () {
570
567
  _context4.t1 = _context4["catch"](19);
571
568
 
572
569
  if (!(_context4.t1.status === 409 && force)) {
573
- _context4.next = 52;
570
+ _context4.next = 43;
574
571
  break;
575
572
  }
576
573
 
577
- if (!destination.path) {
578
- _context4.next = 33;
579
- break;
580
- }
581
-
582
- destinationPath = destination.path;
583
- _context4.next = 41;
584
- break;
574
+ _context4.next = 31;
575
+ return getFullpath(client, destination._id, file.name);
585
576
 
586
- case 33:
587
- _context4.next = 35;
588
- return client.query((0, _dsl.Q)(_const.DOCTYPE_FILES).getById(file._id));
589
-
590
- case 35:
591
- _yield$client$query2 = _context4.sent;
592
- movedFile = _yield$client$query2.data;
593
- filename = movedFile.name;
594
- _context4.next = 40;
595
- return getFullpath(client, destination._id, filename);
596
-
597
- case 40:
577
+ case 31:
598
578
  destinationPath = _context4.sent;
599
-
600
- case 41:
601
- _context4.next = 43;
579
+ _context4.next = 34;
602
580
  return client.collection(_const.DOCTYPE_FILES).statByPath(destinationPath);
603
581
 
604
- case 43:
582
+ case 34:
605
583
  conflictResp = _context4.sent;
606
- _context4.next = 46;
584
+ _context4.next = 37;
607
585
  return client.collection(_const.DOCTYPE_FILES).destroy(conflictResp.data);
608
586
 
609
- case 46:
610
- _context4.next = 48;
587
+ case 37:
588
+ _context4.next = 39;
611
589
  return client.collection(_const.DOCTYPE_FILES).updateFileMetadata(file._id, {
612
590
  dir_id: destination._id
613
591
  });
614
592
 
615
- case 48:
593
+ case 39:
616
594
  _resp = _context4.sent;
617
595
  return _context4.abrupt("return", {
618
596
  moved: _resp.data,
619
597
  deleted: conflictResp.data.id
620
598
  });
621
599
 
622
- case 52:
600
+ case 43:
623
601
  throw _context4.t1;
624
602
 
625
- case 53:
603
+ case 44:
626
604
  case "end":
627
605
  return _context4.stop();
628
606
  }
@@ -1105,5 +1083,95 @@ var fetchBlobFileById = /*#__PURE__*/function () {
1105
1083
  return _ref14.apply(this, arguments);
1106
1084
  };
1107
1085
  }();
1086
+ /**
1087
+ * Copies a file to a specified destination.
1088
+ *
1089
+ * @param {object} client - The client object used for making API requests.
1090
+ * @param {object} file - The file object to be copied.
1091
+ * @param {object} destination - The destination object where the file will be copied to.
1092
+ * @returns {Promise} - A promise that resolves with the response from the API.
1093
+ * @throws {Error} - If an error occurs during the API request.
1094
+ */
1095
+
1096
+
1097
+ exports.fetchBlobFileById = fetchBlobFileById;
1098
+
1099
+ var copy = /*#__PURE__*/function () {
1100
+ var _ref15 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee13(client, file, destination) {
1101
+ var _resp2, _resp3, _resp4, resp;
1102
+
1103
+ return _regenerator.default.wrap(function _callee13$(_context13) {
1104
+ while (1) {
1105
+ switch (_context13.prev = _context13.next) {
1106
+ case 0:
1107
+ _context13.prev = 0;
1108
+
1109
+ if (!(file._type === 'io.cozy.remote.nextcloud.files' && destination._type === 'io.cozy.remote.nextcloud.files')) {
1110
+ _context13.next = 6;
1111
+ break;
1112
+ }
1113
+
1114
+ _context13.next = 4;
1115
+ return client.collection('io.cozy.remote.nextcloud.files').copy(file, destination);
1116
+
1117
+ case 4:
1118
+ _resp2 = _context13.sent;
1119
+ return _context13.abrupt("return", _resp2);
1120
+
1121
+ case 6:
1122
+ if (!(file._type === 'io.cozy.remote.nextcloud.files' && destination._type === 'io.cozy.files')) {
1123
+ _context13.next = 11;
1124
+ break;
1125
+ }
1126
+
1127
+ _context13.next = 9;
1128
+ return client.collection('io.cozy.remote.nextcloud.files').moveToCozy(file, destination, {
1129
+ copy: true
1130
+ });
1131
+
1132
+ case 9:
1133
+ _resp3 = _context13.sent;
1134
+ return _context13.abrupt("return", _resp3);
1135
+
1136
+ case 11:
1137
+ if (!(destination._type === 'io.cozy.remote.nextcloud.files')) {
1138
+ _context13.next = 16;
1139
+ break;
1140
+ }
1141
+
1142
+ _context13.next = 14;
1143
+ return client.collection('io.cozy.remote.nextcloud.files').moveFromCozy(destination, file, {
1144
+ copy: true
1145
+ });
1146
+
1147
+ case 14:
1148
+ _resp4 = _context13.sent;
1149
+ return _context13.abrupt("return", _resp4);
1150
+
1151
+ case 16:
1152
+ _context13.next = 18;
1153
+ return client.collection(_const.DOCTYPE_FILES).copy(file._id, undefined, destination._id);
1154
+
1155
+ case 18:
1156
+ resp = _context13.sent;
1157
+ return _context13.abrupt("return", resp);
1158
+
1159
+ case 22:
1160
+ _context13.prev = 22;
1161
+ _context13.t0 = _context13["catch"](0);
1162
+ throw _context13.t0;
1163
+
1164
+ case 25:
1165
+ case "end":
1166
+ return _context13.stop();
1167
+ }
1168
+ }
1169
+ }, _callee13, null, [[0, 22]]);
1170
+ }));
1171
+
1172
+ return function copy(_x27, _x28, _x29) {
1173
+ return _ref15.apply(this, arguments);
1174
+ };
1175
+ }();
1108
1176
 
1109
- exports.fetchBlobFileById = fetchBlobFileById;
1177
+ exports.copy = copy;
@@ -455,8 +455,11 @@ describe('File Model', () => {
455
455
  _id: 'dir-b1e1c256',
456
456
  _type: 'io.cozy.files',
457
457
  dir_id: 'io.cozy.files.root-dir',
458
- path: '/'
458
+ type: 'directory',
459
+ name: 'Photos',
460
+ path: '/Photos'
459
461
  }
462
+
460
463
  const nextcloudFolder = {
461
464
  _id: 'folder-12435',
462
465
  _type: 'io.cozy.remote.nextcloud.files',
@@ -520,13 +523,6 @@ describe('File Model', () => {
520
523
  _type: 'io.cozy.files'
521
524
  }
522
525
  })
523
- getSpy.mockResolvedValue({
524
- data: {
525
- id: cozyFile._id,
526
- name: 'mydoc.odt',
527
- _type: 'io.cozy.files'
528
- }
529
- })
530
526
  statByPathSpy.mockResolvedValue({
531
527
  data: {
532
528
  id: DELETED_FILE_ID,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "48.11.1",
3
+ "version": "48.12.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": "^48.9.0",
21
+ "cozy-stack-client": "^48.12.0",
22
22
  "date-fns": "2.29.3",
23
23
  "json-stable-stringify": "^1.0.1",
24
24
  "lodash": "^4.17.13",
@@ -75,5 +75,5 @@
75
75
  "react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
76
76
  },
77
77
  "sideEffects": false,
78
- "gitHead": "73a573aa72e2b1d5d2589ae5c0afeec349092c1e"
78
+ "gitHead": "4b5b757b6b1cc8029453eab2d981214be6f33256"
79
79
  }
@@ -67,6 +67,7 @@ export function hasQualifications(file: import("../types").IOCozyFile): boolean;
67
67
  export function hasCertifications(file: import("../types").IOCozyFile): boolean;
68
68
  export function isFromKonnector(file: import("../types").IOCozyFile): boolean;
69
69
  export function fetchBlobFileById(client: CozyClient, fileId: string): Promise<Blob>;
70
+ export function copy(client: object, file: object, destination: object): Promise<any>;
70
71
  export type FileUploadOptions = {
71
72
  /**
72
73
  * - The file name to upload