cozy-client 52.2.0 → 53.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.
@@ -3049,7 +3049,7 @@ var CozyClient = /*#__PURE__*/function () {
3049
3049
  CozyClient.hooks = CozyClient.hooks || {};
3050
3050
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
3051
3051
 
3052
- CozyClient.version = "52.2.0";
3052
+ CozyClient.version = "53.1.0";
3053
3053
 
3054
3054
  _microee.default.mixin(CozyClient);
3055
3055
 
package/dist/const.js CHANGED
@@ -3,10 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.DOCTYPE_PERMISSIONS = exports.DOCTYPE_FILES = exports.REGISTRATION_ABORT = void 0;
6
+ exports.DOCTYPE_FILES_ENCRYPTION = exports.DOCTYPE_PERMISSIONS = exports.DOCTYPE_FILES = exports.REGISTRATION_ABORT = void 0;
7
7
  var REGISTRATION_ABORT = 'REGISTRATION_ABORT';
8
8
  exports.REGISTRATION_ABORT = REGISTRATION_ABORT;
9
9
  var DOCTYPE_FILES = 'io.cozy.files';
10
10
  exports.DOCTYPE_FILES = DOCTYPE_FILES;
11
11
  var DOCTYPE_PERMISSIONS = 'io.cozy.permissions';
12
- exports.DOCTYPE_PERMISSIONS = DOCTYPE_PERMISSIONS;
12
+ exports.DOCTYPE_PERMISSIONS = DOCTYPE_PERMISSIONS;
13
+ var DOCTYPE_FILES_ENCRYPTION = 'io.cozy.files.encryption';
14
+ exports.DOCTYPE_FILES_ENCRYPTION = DOCTYPE_FILES_ENCRYPTION;
@@ -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.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.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;
12
12
 
13
13
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
14
14
 
@@ -120,6 +120,48 @@ exports.isNote = isNote;
120
120
  var isEncrypted = function isEncrypted(file) {
121
121
  return !!file.encrypted;
122
122
  };
123
+ /**
124
+ * Returns folder encryption reference
125
+ *
126
+ * @param {import("../types").IOCozyFile} dir - io.cozy.files document
127
+ * @returns {boolean}
128
+ */
129
+
130
+
131
+ exports.isEncrypted = isEncrypted;
132
+
133
+ var getEncryptiondRef = function getEncryptiondRef(dir) {
134
+ var refs = (0, _get.default)(dir, 'referenced_by', []);
135
+ return refs.find(function (ref) {
136
+ return ref.type === _const.DOCTYPE_FILES_ENCRYPTION;
137
+ });
138
+ };
139
+ /**
140
+ * Whether the folder is client-side encrypted
141
+ *
142
+ * @param {import("../types").IOCozyFile} dir - io.cozy.files document
143
+ * @returns {boolean}
144
+ */
145
+
146
+
147
+ exports.getEncryptiondRef = getEncryptiondRef;
148
+
149
+ var isEncryptedFolder = function isEncryptedFolder(dir) {
150
+ return !!getEncryptiondRef(dir);
151
+ };
152
+ /**
153
+ * Whether the file or folder is client-side encrypted
154
+ *
155
+ * @param {import("../types").IOCozyFile} fileOrdir - io.cozy.files document
156
+ * @returns {boolean}
157
+ */
158
+
159
+
160
+ exports.isEncryptedFolder = isEncryptedFolder;
161
+
162
+ var isEncryptedFileOrFolder = function isEncryptedFileOrFolder(fileOrdir) {
163
+ return isEncryptedFolder(fileOrdir) || isEncrypted(fileOrdir);
164
+ };
123
165
  /**
124
166
  * Whether the file is supported by Only Office
125
167
  *
@@ -128,7 +170,7 @@ var isEncrypted = function isEncrypted(file) {
128
170
  */
129
171
 
130
172
 
131
- exports.isEncrypted = isEncrypted;
173
+ exports.isEncryptedFileOrFolder = isEncryptedFileOrFolder;
132
174
 
133
175
  var isOnlyOfficeFile = function isOnlyOfficeFile(file) {
134
176
  return isFile(file) && !isNote(file) && (file.class === 'text' || file.class === 'spreadsheet' || file.class === 'slide');
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.getSharingLink = void 0;
8
+ exports.makeSharingLink = void 0;
9
9
 
10
10
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
11
 
@@ -31,15 +31,18 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
31
31
  * @param {object} options - Options
32
32
  * @param {string} [options.ttl] - Time to live (bigduration format, e.g. "4Y3M2D1h30m15s")
33
33
  * @param {string} [options.password] - To generate a password-protected link
34
+ * @param {string[]} [options.verbs] - Array of verbs to allow on the shared link. Default is ['GET']
34
35
  * @returns {Promise<string>} Shared link
35
36
  */
36
- var getSharingLink = /*#__PURE__*/function () {
37
+ var makeSharingLink = /*#__PURE__*/function () {
37
38
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client, filesIds) {
38
39
  var _sharedLink$attribute, _sharedLink$attribute2;
39
40
 
40
41
  var _ref2,
41
42
  ttl,
42
43
  password,
44
+ _ref2$verbs,
45
+ verbs,
43
46
  PERMS,
44
47
  _yield$client$save,
45
48
  sharedLink,
@@ -50,14 +53,14 @@ var getSharingLink = /*#__PURE__*/function () {
50
53
  while (1) {
51
54
  switch (_context.prev = _context.next) {
52
55
  case 0:
53
- _ref2 = _args.length > 2 && _args[2] !== undefined ? _args[2] : {}, ttl = _ref2.ttl, password = _ref2.password;
56
+ _ref2 = _args.length > 2 && _args[2] !== undefined ? _args[2] : {}, ttl = _ref2.ttl, password = _ref2.password, _ref2$verbs = _ref2.verbs, verbs = _ref2$verbs === void 0 ? ['GET'] : _ref2$verbs;
54
57
  PERMS = _objectSpread(_objectSpread({
55
58
  _type: _const.DOCTYPE_PERMISSIONS,
56
59
  permissions: {
57
60
  files: {
58
61
  type: _const.DOCTYPE_FILES,
59
62
  values: filesIds,
60
- verbs: ['GET']
63
+ verbs: verbs
61
64
  }
62
65
  }
63
66
  }, ttl && {
@@ -88,9 +91,9 @@ var getSharingLink = /*#__PURE__*/function () {
88
91
  }, _callee);
89
92
  }));
90
93
 
91
- return function getSharingLink(_x, _x2) {
94
+ return function makeSharingLink(_x, _x2) {
92
95
  return _ref.apply(this, arguments);
93
96
  };
94
97
  }();
95
98
 
96
- exports.getSharingLink = getSharingLink;
99
+ exports.makeSharingLink = makeSharingLink;
@@ -1,6 +1,6 @@
1
- import { getSharingLink } from './sharing'
1
+ import { makeSharingLink } from './sharing'
2
2
 
3
- describe('getSharingLink', () => {
3
+ describe('makeSharingLink', () => {
4
4
  const mockSharecode = { attributes: { shortcodes: { code: 'shortcode' } } }
5
5
  const mockClient = ({ isFlatDomain = false } = {}) => ({
6
6
  save: jest.fn(() => ({ data: mockSharecode })),
@@ -10,7 +10,7 @@ describe('getSharingLink', () => {
10
10
  const mockFiles = ['fileId01', 'fileId02']
11
11
 
12
12
  it('should generate the right share link if "isFlatDomain" param is not defined', async () => {
13
- const sharingLink = await getSharingLink(mockClient(), mockFiles)
13
+ const sharingLink = await makeSharingLink(mockClient(), mockFiles)
14
14
 
15
15
  expect(sharingLink).toBe(
16
16
  'http://drive.cozy.cloud/public?sharecode=shortcode#/'
@@ -18,7 +18,7 @@ describe('getSharingLink', () => {
18
18
  })
19
19
 
20
20
  it('should generate the right share link to a nested cozy', async () => {
21
- const sharingLink = await getSharingLink(
21
+ const sharingLink = await makeSharingLink(
22
22
  mockClient({ isFlatDomain: false }),
23
23
  mockFiles
24
24
  )
@@ -29,7 +29,7 @@ describe('getSharingLink', () => {
29
29
  })
30
30
 
31
31
  it('should generate the right share link to a flat cozy', async () => {
32
- const sharingLink = await getSharingLink(
32
+ const sharingLink = await makeSharingLink(
33
33
  mockClient({ isFlatDomain: true }),
34
34
  mockFiles
35
35
  )
@@ -40,14 +40,14 @@ describe('getSharingLink', () => {
40
40
  })
41
41
 
42
42
  it('should generate the right share link with an correct sharecode', async () => {
43
- const sharingLink = await getSharingLink(mockClient(), mockFiles)
43
+ const sharingLink = await makeSharingLink(mockClient(), mockFiles)
44
44
 
45
45
  expect(sharingLink).toContain('sharecode=shortcode')
46
46
  })
47
47
  it('should save called with the "ttl" param', async () => {
48
48
  const mockSave = jest.fn().mockReturnValue({ data: mockSharecode })
49
49
  const client = { ...mockClient(), save: mockSave }
50
- await getSharingLink(client, mockFiles, {
50
+ await makeSharingLink(client, mockFiles, {
51
51
  ttl: '1d'
52
52
  })
53
53
 
@@ -67,7 +67,7 @@ describe('getSharingLink', () => {
67
67
  it('should save called with the "password" param', async () => {
68
68
  const mockSave = jest.fn().mockReturnValue({ data: mockSharecode })
69
69
  const client = { ...mockClient(), save: mockSave }
70
- await getSharingLink(client, mockFiles, {
70
+ await makeSharingLink(client, mockFiles, {
71
71
  password: 'password'
72
72
  })
73
73
 
@@ -84,10 +84,29 @@ describe('getSharingLink', () => {
84
84
  })
85
85
  })
86
86
 
87
+ it('should save called with the "verbs" param', async () => {
88
+ const mockSave = jest.fn().mockReturnValue({ data: mockSharecode })
89
+ const client = { ...mockClient(), save: mockSave }
90
+ await makeSharingLink(client, mockFiles, {
91
+ verbs: ['GET', 'POST']
92
+ })
93
+
94
+ expect(mockSave).toBeCalledWith({
95
+ _type: 'io.cozy.permissions',
96
+ permissions: {
97
+ files: {
98
+ type: 'io.cozy.files',
99
+ values: ['fileId01', 'fileId02'],
100
+ verbs: ['GET', 'POST']
101
+ }
102
+ }
103
+ })
104
+ })
105
+
87
106
  it('should save called without the "ttl" or "password" params', async () => {
88
107
  const mockSave = jest.fn().mockReturnValue({ data: mockSharecode })
89
108
  const client = { ...mockClient(), save: mockSave }
90
- await getSharingLink(client, mockFiles)
109
+ await makeSharingLink(client, mockFiles)
91
110
 
92
111
  expect(mockSave).toBeCalledWith({
93
112
  _type: 'io.cozy.permissions',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "52.2.0",
3
+ "version": "53.1.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": "^52.2.0",
21
+ "cozy-stack-client": "^53.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": "e1dadbc037bd2beda076f2c287bc485e2c50de80"
75
+ "gitHead": "d265f54c73e6e14860b83cffc79aa9a612119ca0"
76
76
  }
package/types/const.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export const REGISTRATION_ABORT: "REGISTRATION_ABORT";
2
2
  export const DOCTYPE_FILES: "io.cozy.files";
3
3
  export const DOCTYPE_PERMISSIONS: "io.cozy.permissions";
4
+ export const DOCTYPE_FILES_ENCRYPTION: "io.cozy.files.encryption";
@@ -33,6 +33,9 @@ export function isFile(file: import("../types").IOCozyFile): boolean;
33
33
  export function isDirectory(file: import("../types").IOCozyFile): boolean;
34
34
  export function isNote(file: import("../types").IOCozyFile): boolean;
35
35
  export function isEncrypted(file: import("../types").IOCozyFile): boolean;
36
+ export function getEncryptiondRef(dir: import("../types").IOCozyFile): boolean;
37
+ export function isEncryptedFolder(dir: import("../types").IOCozyFile): boolean;
38
+ export function isEncryptedFileOrFolder(fileOrdir: import("../types").IOCozyFile): boolean;
36
39
  export function isOnlyOfficeFile(file: import("../types").IOCozyFile): boolean;
37
40
  export function shouldBeOpenedByOnlyOffice(file: import("../types").IOCozyFile): boolean;
38
41
  export function isShortcut(file: import("../types").IOCozyFile): boolean;
@@ -1,5 +1,6 @@
1
- export function getSharingLink(client: CozyClient, filesIds: string[], { ttl, password }?: {
1
+ export function makeSharingLink(client: CozyClient, filesIds: string[], { ttl, password, verbs }?: {
2
2
  ttl: string;
3
3
  password: string;
4
+ verbs: string[];
4
5
  }): Promise<string>;
5
6
  import CozyClient from "../CozyClient";