cozy-client 44.1.0 → 45.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.
- package/dist/CozyClient.js +1 -1
- package/dist/models/file.js +1 -1
- package/dist/models/sharing.js +30 -10
- package/dist/models/sharing.spec.js +67 -17
- package/package.json +3 -3
- package/types/models/file.d.ts +4 -1
- package/types/models/sharing.d.ts +4 -1
package/dist/CozyClient.js
CHANGED
|
@@ -2703,7 +2703,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2703
2703
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
2704
2704
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
2705
2705
|
|
|
2706
|
-
CozyClient.version = "
|
|
2706
|
+
CozyClient.version = "45.0.0";
|
|
2707
2707
|
|
|
2708
2708
|
_microee.default.mixin(CozyClient);
|
|
2709
2709
|
|
package/dist/models/file.js
CHANGED
|
@@ -47,7 +47,7 @@ var FILENAME_WITH_EXTENSION_REGEX = /(.+)(\..*)$/;
|
|
|
47
47
|
* Returns base filename and extension
|
|
48
48
|
*
|
|
49
49
|
* @param {import("../types").IOCozyFile} file An io.cozy.files
|
|
50
|
-
* @returns {
|
|
50
|
+
* @returns {{filename: string, extension: string}}
|
|
51
51
|
*/
|
|
52
52
|
|
|
53
53
|
var splitFilename = function splitFilename(file) {
|
package/dist/models/sharing.js
CHANGED
|
@@ -9,6 +9,8 @@ exports.getSharingLink = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
11
|
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
|
|
12
14
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
15
|
|
|
14
16
|
var _const = require("../const");
|
|
@@ -17,25 +19,39 @@ var _CozyClient = _interopRequireDefault(require("../CozyClient"));
|
|
|
17
19
|
|
|
18
20
|
var _helpers = require("../helpers");
|
|
19
21
|
|
|
22
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
23
|
+
|
|
24
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
25
|
+
|
|
20
26
|
/**
|
|
21
27
|
* Generate Sharing link for one or many files
|
|
22
28
|
*
|
|
23
29
|
* @param {CozyClient} client - Instance of CozyClient
|
|
24
30
|
* @param {string[]} filesIds - Array of io.cozy.files ids
|
|
25
|
-
* @param {
|
|
31
|
+
* @param {object} options - Options
|
|
32
|
+
* @param {string} [options.ttl] - Time to live (bigduration format, e.g. "4Y3M2D1h30m15s")
|
|
33
|
+
* @param {string} [options.password] - To generate a password-protected link
|
|
26
34
|
* @returns {Promise<string>} Shared link
|
|
27
35
|
*/
|
|
28
36
|
var getSharingLink = /*#__PURE__*/function () {
|
|
29
|
-
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client, filesIds
|
|
37
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client, filesIds) {
|
|
30
38
|
var _sharedLink$attribute, _sharedLink$attribute2;
|
|
31
39
|
|
|
32
|
-
var
|
|
40
|
+
var _ref2,
|
|
41
|
+
ttl,
|
|
42
|
+
password,
|
|
43
|
+
PERMS,
|
|
44
|
+
_yield$client$save,
|
|
45
|
+
sharedLink,
|
|
46
|
+
webLink,
|
|
47
|
+
_args = arguments;
|
|
33
48
|
|
|
34
49
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
35
50
|
while (1) {
|
|
36
51
|
switch (_context.prev = _context.next) {
|
|
37
52
|
case 0:
|
|
38
|
-
|
|
53
|
+
_ref2 = _args.length > 2 && _args[2] !== undefined ? _args[2] : {}, ttl = _ref2.ttl, password = _ref2.password;
|
|
54
|
+
PERMS = _objectSpread(_objectSpread({
|
|
39
55
|
_type: _const.DOCTYPE_PERMISSIONS,
|
|
40
56
|
permissions: {
|
|
41
57
|
files: {
|
|
@@ -44,11 +60,15 @@ var getSharingLink = /*#__PURE__*/function () {
|
|
|
44
60
|
verbs: ['GET']
|
|
45
61
|
}
|
|
46
62
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
63
|
+
}, ttl && {
|
|
64
|
+
ttl: ttl
|
|
65
|
+
}), password && {
|
|
66
|
+
password: password
|
|
67
|
+
});
|
|
68
|
+
_context.next = 4;
|
|
49
69
|
return client.save(PERMS);
|
|
50
70
|
|
|
51
|
-
case
|
|
71
|
+
case 4:
|
|
52
72
|
_yield$client$save = _context.sent;
|
|
53
73
|
sharedLink = _yield$client$save.data;
|
|
54
74
|
webLink = (0, _helpers.generateWebLink)({
|
|
@@ -56,11 +76,11 @@ var getSharingLink = /*#__PURE__*/function () {
|
|
|
56
76
|
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
77
|
pathname: '/public',
|
|
58
78
|
slug: 'drive',
|
|
59
|
-
subDomainType:
|
|
79
|
+
subDomainType: client.capabilities.flat_subdomains ? 'flat' : 'nested'
|
|
60
80
|
});
|
|
61
81
|
return _context.abrupt("return", webLink);
|
|
62
82
|
|
|
63
|
-
case
|
|
83
|
+
case 8:
|
|
64
84
|
case "end":
|
|
65
85
|
return _context.stop();
|
|
66
86
|
}
|
|
@@ -68,7 +88,7 @@ var getSharingLink = /*#__PURE__*/function () {
|
|
|
68
88
|
}, _callee);
|
|
69
89
|
}));
|
|
70
90
|
|
|
71
|
-
return function getSharingLink(_x, _x2
|
|
91
|
+
return function getSharingLink(_x, _x2) {
|
|
72
92
|
return _ref.apply(this, arguments);
|
|
73
93
|
};
|
|
74
94
|
}();
|
|
@@ -2,17 +2,15 @@ import { getSharingLink } from './sharing'
|
|
|
2
2
|
|
|
3
3
|
describe('getSharingLink', () => {
|
|
4
4
|
const mockSharecode = { attributes: { shortcodes: { code: 'shortcode' } } }
|
|
5
|
-
const mockClient = {
|
|
5
|
+
const mockClient = ({ isFlatDomain = false } = {}) => ({
|
|
6
6
|
save: jest.fn(() => ({ data: mockSharecode })),
|
|
7
|
-
getStackClient: jest.fn(() => ({ uri: 'http://cozy.cloud' }))
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
{ id: 'fileId02', name: 'File 02' }
|
|
12
|
-
]
|
|
7
|
+
getStackClient: jest.fn(() => ({ uri: 'http://cozy.cloud' })),
|
|
8
|
+
capabilities: { flat_subdomains: isFlatDomain }
|
|
9
|
+
})
|
|
10
|
+
const mockFiles = ['fileId01', 'fileId02']
|
|
13
11
|
|
|
14
12
|
it('should generate the right share link if "isFlatDomain" param is not defined', async () => {
|
|
15
|
-
const sharingLink = await getSharingLink(mockClient, mockFiles)
|
|
13
|
+
const sharingLink = await getSharingLink(mockClient(), mockFiles)
|
|
16
14
|
|
|
17
15
|
expect(sharingLink).toBe(
|
|
18
16
|
'http://drive.cozy.cloud/public?sharecode=shortcode#/'
|
|
@@ -20,11 +18,9 @@ describe('getSharingLink', () => {
|
|
|
20
18
|
})
|
|
21
19
|
|
|
22
20
|
it('should generate the right share link to a nested cozy', async () => {
|
|
23
|
-
const isFlatDomain = false
|
|
24
21
|
const sharingLink = await getSharingLink(
|
|
25
|
-
mockClient,
|
|
26
|
-
mockFiles
|
|
27
|
-
isFlatDomain
|
|
22
|
+
mockClient({ isFlatDomain: false }),
|
|
23
|
+
mockFiles
|
|
28
24
|
)
|
|
29
25
|
|
|
30
26
|
expect(sharingLink).toBe(
|
|
@@ -33,11 +29,9 @@ describe('getSharingLink', () => {
|
|
|
33
29
|
})
|
|
34
30
|
|
|
35
31
|
it('should generate the right share link to a flat cozy', async () => {
|
|
36
|
-
const isFlatDomain = true
|
|
37
32
|
const sharingLink = await getSharingLink(
|
|
38
|
-
mockClient,
|
|
39
|
-
mockFiles
|
|
40
|
-
isFlatDomain
|
|
33
|
+
mockClient({ isFlatDomain: true }),
|
|
34
|
+
mockFiles
|
|
41
35
|
)
|
|
42
36
|
|
|
43
37
|
expect(sharingLink).toBe(
|
|
@@ -46,8 +40,64 @@ describe('getSharingLink', () => {
|
|
|
46
40
|
})
|
|
47
41
|
|
|
48
42
|
it('should generate the right share link with an correct sharecode', async () => {
|
|
49
|
-
const sharingLink = await getSharingLink(mockClient, mockFiles)
|
|
43
|
+
const sharingLink = await getSharingLink(mockClient(), mockFiles)
|
|
50
44
|
|
|
51
45
|
expect(sharingLink).toContain('sharecode=shortcode')
|
|
52
46
|
})
|
|
47
|
+
it('should save called with the "ttl" param', async () => {
|
|
48
|
+
const mockSave = jest.fn().mockReturnValue({ data: mockSharecode })
|
|
49
|
+
const client = { ...mockClient(), save: mockSave }
|
|
50
|
+
await getSharingLink(client, mockFiles, {
|
|
51
|
+
ttl: '1d'
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
expect(mockSave).toBeCalledWith({
|
|
55
|
+
_type: 'io.cozy.permissions',
|
|
56
|
+
permissions: {
|
|
57
|
+
files: {
|
|
58
|
+
type: 'io.cozy.files',
|
|
59
|
+
values: ['fileId01', 'fileId02'],
|
|
60
|
+
verbs: ['GET']
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
ttl: '1d'
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('should save called with the "password" param', async () => {
|
|
68
|
+
const mockSave = jest.fn().mockReturnValue({ data: mockSharecode })
|
|
69
|
+
const client = { ...mockClient(), save: mockSave }
|
|
70
|
+
await getSharingLink(client, mockFiles, {
|
|
71
|
+
password: 'password'
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
expect(mockSave).toBeCalledWith({
|
|
75
|
+
_type: 'io.cozy.permissions',
|
|
76
|
+
permissions: {
|
|
77
|
+
files: {
|
|
78
|
+
type: 'io.cozy.files',
|
|
79
|
+
values: ['fileId01', 'fileId02'],
|
|
80
|
+
verbs: ['GET']
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
password: 'password'
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('should save called without the "ttl" or "password" params', async () => {
|
|
88
|
+
const mockSave = jest.fn().mockReturnValue({ data: mockSharecode })
|
|
89
|
+
const client = { ...mockClient(), save: mockSave }
|
|
90
|
+
await getSharingLink(client, mockFiles)
|
|
91
|
+
|
|
92
|
+
expect(mockSave).toBeCalledWith({
|
|
93
|
+
_type: 'io.cozy.permissions',
|
|
94
|
+
permissions: {
|
|
95
|
+
files: {
|
|
96
|
+
type: 'io.cozy.files',
|
|
97
|
+
values: ['fileId01', 'fileId02'],
|
|
98
|
+
verbs: ['GET']
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
})
|
|
53
103
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "45.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": "^
|
|
21
|
+
"cozy-stack-client": "^45.0.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": "
|
|
78
|
+
"gitHead": "d3762d9c73e50e9df1524e1220e34f82eab011d3"
|
|
79
79
|
}
|
package/types/models/file.d.ts
CHANGED
|
@@ -25,7 +25,10 @@ export function ensureFilePath(file: object, parent: object): object;
|
|
|
25
25
|
*/
|
|
26
26
|
export function getParentFolderId(file: object): string | null;
|
|
27
27
|
export const ALBUMS_DOCTYPE: "io.cozy.photos.albums";
|
|
28
|
-
export function splitFilename(file: import("../types").IOCozyFile):
|
|
28
|
+
export function splitFilename(file: import("../types").IOCozyFile): {
|
|
29
|
+
filename: string;
|
|
30
|
+
extension: string;
|
|
31
|
+
};
|
|
29
32
|
export function isFile(file: import("../types").IOCozyFile): boolean;
|
|
30
33
|
export function isDirectory(file: import("../types").IOCozyFile): boolean;
|
|
31
34
|
export function isNote(file: import("../types").IOCozyFile): boolean;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export function getSharingLink(client: CozyClient, filesIds: string[],
|
|
1
|
+
export function getSharingLink(client: CozyClient, filesIds: string[], { ttl, password }?: {
|
|
2
|
+
ttl: string;
|
|
3
|
+
password: string;
|
|
4
|
+
}): Promise<string>;
|
|
2
5
|
import CozyClient from "../CozyClient";
|