cozy-client 28.0.2 → 28.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.
@@ -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.2";
2540
+ CozyClient.version = "28.1.0";
2541
2541
 
2542
2542
  _microee.default.mixin(CozyClient);
2543
2543
 
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;
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "28.0.2",
3
+ "version": "28.1.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -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": "806a1dfa8abd8cf90306af37c32650b96e43583e"
76
+ "gitHead": "77128534f1e28d493230263b56521f08d17a3247"
77
77
  }
package/types/const.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export const REGISTRATION_ABORT: "REGISTRATION_ABORT";
2
2
  export const DOCTYPE_FILES: "io.cozy.files";
3
+ export const DOCTYPE_PERMISSIONS: "io.cozy.permissions";
@@ -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
- export { trigger, instance, applications, file, folder, note, account, permission, utils, contact, document, timeseries };
15
+ import * as sharing from "./sharing";
16
+ export { trigger, instance, applications, file, folder, note, account, permission, utils, contact, document, timeseries, sharing };
@@ -0,0 +1,2 @@
1
+ export function getSharingLink(client: CozyClient, filesIds: string[], isFlatDomain?: boolean): Promise<string>;
2
+ import CozyClient from "../CozyClient";