cozy-client 28.0.2 → 28.2.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 +1 -1
- package/dist/CozyClient.spec.js +1 -1
- package/dist/const.js +4 -2
- package/dist/models/file.js +15 -2
- package/dist/models/file.spec.js +12 -0
- package/dist/models/index.js +5 -1
- package/dist/models/sharing.js +76 -0
- package/dist/models/sharing.spec.js +53 -0
- package/dist/types.js +5 -2
- package/package.json +3 -3
- package/types/const.d.ts +1 -0
- package/types/models/file.d.ts +1 -0
- package/types/models/index.d.ts +2 -1
- package/types/models/sharing.d.ts +2 -0
- package/types/types.d.ts +14 -2
package/dist/CozyClient.js
CHANGED
|
@@ -2537,7 +2537,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2537
2537
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
2538
2538
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
2539
2539
|
|
|
2540
|
-
CozyClient.version = "28.0
|
|
2540
|
+
CozyClient.version = "28.2.0";
|
|
2541
2541
|
|
|
2542
2542
|
_microee.default.mixin(CozyClient);
|
|
2543
2543
|
|
package/dist/CozyClient.spec.js
CHANGED
|
@@ -1800,7 +1800,7 @@ describe('file creation', () => {
|
|
|
1800
1800
|
expect(doc._id).toEqual('1337')
|
|
1801
1801
|
expect(client.stackClient.fetchJSON).toHaveBeenCalledWith(
|
|
1802
1802
|
'POST',
|
|
1803
|
-
'/files/folder-id?Name=toto.pdf&Type=file&Executable=false&MetadataID=&Size=12',
|
|
1803
|
+
'/files/folder-id?Name=toto.pdf&Type=file&Executable=false&Encrypted=false&MetadataID=&Size=12',
|
|
1804
1804
|
'file-content',
|
|
1805
1805
|
{
|
|
1806
1806
|
headers: { 'Content-Type': 'text/plain', 'Content-Length': '12' },
|
package/dist/const.js
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.DOCTYPE_FILES = exports.REGISTRATION_ABORT = void 0;
|
|
6
|
+
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
|
-
exports.DOCTYPE_FILES = DOCTYPE_FILES;
|
|
10
|
+
exports.DOCTYPE_FILES = DOCTYPE_FILES;
|
|
11
|
+
var DOCTYPE_PERMISSIONS = 'io.cozy.permissions';
|
|
12
|
+
exports.DOCTYPE_PERMISSIONS = DOCTYPE_PERMISSIONS;
|
package/dist/models/file.js
CHANGED
|
@@ -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.isReferencedByAlbum = 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.isNote = exports.isDirectory = exports.isFile = exports.splitFilename = exports.ALBUMS_DOCTYPE = void 0;
|
|
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.isReferencedByAlbum = 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
|
|
|
@@ -109,6 +109,19 @@ var isNote = function isNote(file) {
|
|
|
109
109
|
if (file && file.name && file.name.endsWith('.cozy-note') && file.type === FILE_TYPE && file.metadata && file.metadata.content !== undefined && file.metadata.schema !== undefined && file.metadata.title !== undefined && file.metadata.version !== undefined) return true;
|
|
110
110
|
return false;
|
|
111
111
|
};
|
|
112
|
+
/**
|
|
113
|
+
* Whether the file is client-side encrypted
|
|
114
|
+
*
|
|
115
|
+
* @param {IOCozyFile} file - io.cozy.files document
|
|
116
|
+
* @returns {boolean}
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
exports.isNote = isNote;
|
|
121
|
+
|
|
122
|
+
var isEncrypted = function isEncrypted(file) {
|
|
123
|
+
return !!file.encrypted;
|
|
124
|
+
};
|
|
112
125
|
/**
|
|
113
126
|
* Whether the file is supported by Only Office
|
|
114
127
|
*
|
|
@@ -117,7 +130,7 @@ var isNote = function isNote(file) {
|
|
|
117
130
|
*/
|
|
118
131
|
|
|
119
132
|
|
|
120
|
-
exports.
|
|
133
|
+
exports.isEncrypted = isEncrypted;
|
|
121
134
|
|
|
122
135
|
var isOnlyOfficeFile = function isOnlyOfficeFile(file) {
|
|
123
136
|
return isFile(file) && !isNote(file) && (file.class === 'text' || file.class === 'spreadsheet' || file.class === 'slide');
|
package/dist/models/file.spec.js
CHANGED
|
@@ -231,6 +231,18 @@ describe('File Model', () => {
|
|
|
231
231
|
})
|
|
232
232
|
})
|
|
233
233
|
|
|
234
|
+
describe('encryption', () => {
|
|
235
|
+
it('should return when a file is encrypted or not', () => {
|
|
236
|
+
const encryptedFile = {
|
|
237
|
+
name: 'encryptedfile.txt',
|
|
238
|
+
encrypted: true
|
|
239
|
+
}
|
|
240
|
+
const plaintextFile = { name: 'plaintext.txt', mime: 'text' }
|
|
241
|
+
expect(fileModel.isEncrypted(encryptedFile)).toBe(true)
|
|
242
|
+
expect(fileModel.isEncrypted(plaintextFile)).toBe(false)
|
|
243
|
+
})
|
|
244
|
+
})
|
|
245
|
+
|
|
234
246
|
describe('splitFilename', () => {
|
|
235
247
|
it.each`
|
|
236
248
|
opts | result
|
package/dist/models/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWild
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.timeseries = exports.document = exports.contact = exports.utils = exports.permission = exports.note = exports.account = exports.folder = exports.file = exports.applications = exports.instance = exports.trigger = exports.accounts = exports.triggers = void 0;
|
|
8
|
+
exports.sharing = exports.timeseries = exports.document = exports.contact = exports.utils = exports.permission = exports.note = exports.account = exports.folder = exports.file = exports.applications = exports.instance = exports.trigger = exports.accounts = exports.triggers = void 0;
|
|
9
9
|
|
|
10
10
|
var trigger = _interopRequireWildcard(require("./trigger"));
|
|
11
11
|
|
|
@@ -54,6 +54,10 @@ exports.document = document;
|
|
|
54
54
|
var timeseries = _interopRequireWildcard(require("./timeseries"));
|
|
55
55
|
|
|
56
56
|
exports.timeseries = timeseries;
|
|
57
|
+
|
|
58
|
+
var sharing = _interopRequireWildcard(require("./sharing"));
|
|
59
|
+
|
|
60
|
+
exports.sharing = sharing;
|
|
57
61
|
// For backward compatibility before 9.0.0
|
|
58
62
|
var triggers = trigger;
|
|
59
63
|
exports.triggers = triggers;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.getSharingLink = 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 _CozyClient = _interopRequireDefault(require("../CozyClient"));
|
|
17
|
+
|
|
18
|
+
var _helpers = require("../helpers");
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Generate Sharing link for one or many files
|
|
22
|
+
*
|
|
23
|
+
* @param {CozyClient} client - Instance of CozyClient
|
|
24
|
+
* @param {string[]} filesIds - Array of io.cozy.files ids
|
|
25
|
+
* @param {boolean} [isFlatDomain] -
|
|
26
|
+
* @returns {Promise<string>} Shared link
|
|
27
|
+
*/
|
|
28
|
+
var getSharingLink = /*#__PURE__*/function () {
|
|
29
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client, filesIds, isFlatDomain) {
|
|
30
|
+
var _sharedLink$attribute, _sharedLink$attribute2;
|
|
31
|
+
|
|
32
|
+
var PERMS, _yield$client$save, sharedLink, webLink;
|
|
33
|
+
|
|
34
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
35
|
+
while (1) {
|
|
36
|
+
switch (_context.prev = _context.next) {
|
|
37
|
+
case 0:
|
|
38
|
+
PERMS = {
|
|
39
|
+
_type: _const.DOCTYPE_PERMISSIONS,
|
|
40
|
+
permissions: {
|
|
41
|
+
files: {
|
|
42
|
+
type: _const.DOCTYPE_FILES,
|
|
43
|
+
values: filesIds,
|
|
44
|
+
verbs: ['GET']
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
_context.next = 3;
|
|
49
|
+
return client.save(PERMS);
|
|
50
|
+
|
|
51
|
+
case 3:
|
|
52
|
+
_yield$client$save = _context.sent;
|
|
53
|
+
sharedLink = _yield$client$save.data;
|
|
54
|
+
webLink = (0, _helpers.generateWebLink)({
|
|
55
|
+
cozyUrl: client.getStackClient().uri,
|
|
56
|
+
searchParams: [['sharecode', sharedLink === null || sharedLink === void 0 ? void 0 : (_sharedLink$attribute = sharedLink.attributes) === null || _sharedLink$attribute === void 0 ? void 0 : (_sharedLink$attribute2 = _sharedLink$attribute.shortcodes) === null || _sharedLink$attribute2 === void 0 ? void 0 : _sharedLink$attribute2.code]],
|
|
57
|
+
pathname: '/public',
|
|
58
|
+
slug: 'drive',
|
|
59
|
+
subDomainType: isFlatDomain ? 'flat' : 'nested'
|
|
60
|
+
});
|
|
61
|
+
return _context.abrupt("return", webLink);
|
|
62
|
+
|
|
63
|
+
case 7:
|
|
64
|
+
case "end":
|
|
65
|
+
return _context.stop();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}, _callee);
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
return function getSharingLink(_x, _x2, _x3) {
|
|
72
|
+
return _ref.apply(this, arguments);
|
|
73
|
+
};
|
|
74
|
+
}();
|
|
75
|
+
|
|
76
|
+
exports.getSharingLink = getSharingLink;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { getSharingLink } from './sharing'
|
|
2
|
+
|
|
3
|
+
describe('getSharingLink', () => {
|
|
4
|
+
const mockSharecode = { attributes: { shortcodes: { code: 'shortcode' } } }
|
|
5
|
+
const mockClient = {
|
|
6
|
+
save: jest.fn(() => ({ data: mockSharecode })),
|
|
7
|
+
getStackClient: jest.fn(() => ({ uri: 'http://cozy.cloud' }))
|
|
8
|
+
}
|
|
9
|
+
const mockFiles = [
|
|
10
|
+
{ id: 'fileId01', name: 'File 01' },
|
|
11
|
+
{ id: 'fileId02', name: 'File 02' }
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
it('should generate the right share link if "isFlatDomain" param is not defined', async () => {
|
|
15
|
+
const sharingLink = await getSharingLink(mockClient, mockFiles)
|
|
16
|
+
|
|
17
|
+
expect(sharingLink).toBe(
|
|
18
|
+
'http://drive.cozy.cloud/public?sharecode=shortcode#/'
|
|
19
|
+
)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('should generate the right share link to a nested cozy', async () => {
|
|
23
|
+
const isFlatDomain = false
|
|
24
|
+
const sharingLink = await getSharingLink(
|
|
25
|
+
mockClient,
|
|
26
|
+
mockFiles,
|
|
27
|
+
isFlatDomain
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
expect(sharingLink).toBe(
|
|
31
|
+
'http://drive.cozy.cloud/public?sharecode=shortcode#/'
|
|
32
|
+
)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('should generate the right share link to a flat cozy', async () => {
|
|
36
|
+
const isFlatDomain = true
|
|
37
|
+
const sharingLink = await getSharingLink(
|
|
38
|
+
mockClient,
|
|
39
|
+
mockFiles,
|
|
40
|
+
isFlatDomain
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
expect(sharingLink).toBe(
|
|
44
|
+
'http://cozy-drive.cloud/public?sharecode=shortcode#/'
|
|
45
|
+
)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('should generate the right share link with an correct sharecode', async () => {
|
|
49
|
+
const sharingLink = await getSharingLink(mockClient, mockFiles)
|
|
50
|
+
|
|
51
|
+
expect(sharingLink).toContain('sharecode=shortcode')
|
|
52
|
+
})
|
|
53
|
+
})
|
package/dist/types.js
CHANGED
|
@@ -165,8 +165,11 @@ var _dsl = require("./queries/dsl");
|
|
|
165
165
|
* @property {FilesDoctype} _type - Doctype of the file
|
|
166
166
|
* @property {string} name - Name of the file
|
|
167
167
|
* @property {object} metadata - Metadata of the file
|
|
168
|
-
* @property {
|
|
169
|
-
* @property {
|
|
168
|
+
* @property {string} type - Type of the file
|
|
169
|
+
* @property {string} class - Class of the file
|
|
170
|
+
* @property {string} mime - Mime of the file
|
|
171
|
+
* @property {boolean} executable - Whether or not the file is executable
|
|
172
|
+
* @property {boolean} encrypted - Whether or not the file is client-side encrypted
|
|
170
173
|
* @typedef {CozyClientDocument & FileDocument} IOCozyFile - An io.cozy.files document
|
|
171
174
|
*/
|
|
172
175
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "28.0
|
|
3
|
+
"version": "28.2.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": "^28.0
|
|
21
|
+
"cozy-stack-client": "^28.2.0",
|
|
22
22
|
"json-stable-stringify": "^1.0.1",
|
|
23
23
|
"lodash": "^4.17.13",
|
|
24
24
|
"microee": "^0.0.6",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
|
|
74
74
|
},
|
|
75
75
|
"sideEffects": false,
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "a39d0c43bb88a0b0c27f9071b40eb06072a553c0"
|
|
77
77
|
}
|
package/types/const.d.ts
CHANGED
package/types/models/file.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export function splitFilename(file: IOCozyFile): object;
|
|
|
29
29
|
export function isFile(file: IOCozyFile): boolean;
|
|
30
30
|
export function isDirectory(file: IOCozyFile): boolean;
|
|
31
31
|
export function isNote(file: IOCozyFile): boolean;
|
|
32
|
+
export function isEncrypted(file: IOCozyFile): boolean;
|
|
32
33
|
export function isOnlyOfficeFile(file: IOCozyFile): boolean;
|
|
33
34
|
export function shouldBeOpenedByOnlyOffice(file: IOCozyFile): boolean;
|
|
34
35
|
export function isShortcut(file: IOCozyFile): boolean;
|
package/types/models/index.d.ts
CHANGED
|
@@ -12,4 +12,5 @@ import * as utils from "./utils";
|
|
|
12
12
|
import * as contact from "./contact";
|
|
13
13
|
import * as document from "./document";
|
|
14
14
|
import * as timeseries from "./timeseries";
|
|
15
|
-
|
|
15
|
+
import * as sharing from "./sharing";
|
|
16
|
+
export { trigger, instance, applications, file, folder, note, account, permission, utils, contact, document, timeseries, sharing };
|
package/types/types.d.ts
CHANGED
|
@@ -187,11 +187,23 @@ export type FileDocument = {
|
|
|
187
187
|
/**
|
|
188
188
|
* - Type of the file
|
|
189
189
|
*/
|
|
190
|
-
type:
|
|
190
|
+
type: string;
|
|
191
191
|
/**
|
|
192
192
|
* - Class of the file
|
|
193
193
|
*/
|
|
194
|
-
class:
|
|
194
|
+
class: string;
|
|
195
|
+
/**
|
|
196
|
+
* - Mime of the file
|
|
197
|
+
*/
|
|
198
|
+
mime: string;
|
|
199
|
+
/**
|
|
200
|
+
* - Whether or not the file is executable
|
|
201
|
+
*/
|
|
202
|
+
executable: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* - Whether or not the file is client-side encrypted
|
|
205
|
+
*/
|
|
206
|
+
encrypted: boolean;
|
|
195
207
|
};
|
|
196
208
|
/**
|
|
197
209
|
* - An io.cozy.files document
|