cozy-client 28.0.0 → 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.0";
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.0",
3
+ "version": "28.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": "^28.0.0",
21
+ "cozy-stack-client": "^28.0.1",
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": "68e2573b4bb28622c41d468f35371d92ce30fb4b"
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";
@@ -0,0 +1,3 @@
1
+ export function checkMeasureParams(measure: DACCMeasure): void;
2
+ export function sendMeasureToDACC(client: object, remoteDoctype: string, measure: DACCMeasure): Promise<void>;
3
+ import { DACCMeasure } from "../types";
@@ -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";
package/types/types.d.ts CHANGED
@@ -86,7 +86,10 @@ export type QueryOptions = {
86
86
  export type FetchMoreAble = {
87
87
  fetchMore: Function;
88
88
  };
89
- export type UseQueryReturnValue = QueryState & FetchMoreAble;
89
+ export type FetchAble = {
90
+ fetch: Function;
91
+ };
92
+ export type UseQueryReturnValue = QueryState & FetchMoreAble & FetchAble;
90
93
  /**
91
94
  * A reference to a document
92
95
  */
@@ -342,6 +345,39 @@ export type FinanceLabels = "payment_proof_family_allowance" | "pay_sheet" | "ta
342
345
  export type InvoiceLabels = "health_invoice" | "phone_invoice" | "isp_invoice" | "telecom_invoice" | "energy_invoice" | "water_invoice" | "work_invoice" | "transport_invoice" | "appliance_invoice" | "web_service_invoice" | "restaurant_invoice" | "other_invoice";
343
346
  export type ActivityLabels = "personal_sporting_licence" | "other_activity_document";
344
347
  export type ItemsLabels = "resume" | "identity_photo" | "national_id_card" | "passport" | "residence_permit" | "family_record_book" | "birth_certificate" | "driver_license" | "other_identity_document" | "citizen_registration_certificate" | "personal_sporting_licence" | "wedding" | "pacs" | "divorce" | "large_family_card" | "caf" | "other_family_document" | "payment_proof_family_allowance" | "diploma" | "work_contract" | "pay_sheet" | "unemployment_benefit" | "pension" | "gradebook" | "student_card" | "motivation_letter" | "other_work_document" | "work_disability_recognition" | "school_attendance_certificate" | "health_certificate" | "health_book" | "national_health_insurance_card" | "health_insurance_card" | "prescription" | "health_invoice" | "national_health_insurance_right_certificate" | "pregnancy_medical_certificate" | "other_health_document" | "phone_invoice" | "isp_invoice" | "telecom_invoice" | "energy_invoice" | "water_invoice" | "house_sale_agreeement" | "building_permit" | "technical_diagnostic_record" | "lease" | "rent_receipt" | "house_insurance" | "work_quote" | "work_invoice" | "other_house_document" | "unfit_for_habitation_declaration" | "accommodation_proof" | "vehicle_registration" | "car_insurance" | "mechanic_invoice" | "transport_invoice" | "other_transport_document" | "tax_return" | "tax_notice" | "tax_timetable" | "receipt" | "other_tax_document" | "bank_details" | "bank_statement" | "loan_agreement" | "other_bank_document" | "other_revenue" | "appliance_invoice" | "web_service_invoice" | "restaurant_invoice" | "other_invoice" | "other_activity_document";
348
+ /**
349
+ * See https://github.com/cozy/DACC
350
+ */
351
+ export type DACCMeasure = {
352
+ /**
353
+ * - It must match an existing measure name on the DACC server
354
+ */
355
+ measureName: string;
356
+ /**
357
+ * - Start of the aggregation period. Should be in YYYY-MM-DD format
358
+ */
359
+ startDate: string;
360
+ /**
361
+ * - The measured value on the aggregation period
362
+ */
363
+ value: number;
364
+ /**
365
+ * - The slug of the app creating the measure
366
+ */
367
+ createdBy: string;
368
+ /**
369
+ * - Should be a {key: value} where the key is set in the measure definition.
370
+ */
371
+ group1: object;
372
+ /**
373
+ * - Should be a {key: value} where the key is set in the measure definition.
374
+ */
375
+ group2: object;
376
+ /**
377
+ * - Should be a {key: value} where the key is set in the measure definition.
378
+ */
379
+ group3: object;
380
+ };
345
381
  /**
346
382
  * Receives the URL to present to the user as a parameter, and should return a promise that resolves with the URL the user was redirected to after accepting the permissions.
347
383
  */