cozy-client 44.0.0 → 44.1.1

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.
@@ -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 = "44.0.0";
2706
+ CozyClient.version = "44.1.1";
2707
2707
 
2708
2708
  _microee.default.mixin(CozyClient);
2709
2709
 
@@ -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 {object} {filename, extension}
50
+ * @returns {{filename: string, extension: string}}
51
51
  */
52
52
 
53
53
  var splitFilename = function splitFilename(file) {
@@ -707,6 +707,7 @@ var generateFileNameForRevision = function generateFileNameForRevision(file, rev
707
707
  * @property {object} [metadata] - An object containing the metadata to attach
708
708
  * @property {string} [contentType] - The file Content-Type
709
709
  * @property {string} [conflictStrategy] - Erase / rename
710
+ * @property {import('../types').ConflictOptions} [conflictOptions] - Conflict options
710
711
  */
711
712
 
712
713
  /**
@@ -730,13 +731,13 @@ exports.generateFileNameForRevision = generateFileNameForRevision;
730
731
 
731
732
  var uploadFileWithConflictStrategy = /*#__PURE__*/function () {
732
733
  var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(client, file, options) {
733
- var name, dirId, conflictStrategy, path, existingFile, fileId, resp, _splitFilename2, filename, extension, newFileName;
734
+ var name, dirId, conflictStrategy, conflictOptions, path, existingFile, fileId, resp, _splitFilename2, filename, extension, newFileName;
734
735
 
735
736
  return _regenerator.default.wrap(function _callee6$(_context6) {
736
737
  while (1) {
737
738
  switch (_context6.prev = _context6.next) {
738
739
  case 0:
739
- name = options.name, dirId = options.dirId, conflictStrategy = options.conflictStrategy;
740
+ name = options.name, dirId = options.dirId, conflictStrategy = options.conflictStrategy, conflictOptions = options.conflictOptions;
740
741
  _context6.prev = 1;
741
742
  _context6.next = 4;
742
743
  return getFullpath(client, dirId, name);
@@ -770,7 +771,7 @@ var uploadFileWithConflictStrategy = /*#__PURE__*/function () {
770
771
  name: name,
771
772
  type: 'file'
772
773
  }), filename = _splitFilename2.filename, extension = _splitFilename2.extension;
773
- newFileName = generateNewFileNameOnConflict(filename) + extension; //recall itself with the newFilename.
774
+ newFileName = generateNewFileNameOnConflict(filename, conflictOptions) + extension; //recall itself with the newFilename.
774
775
 
775
776
  return _context6.abrupt("return", uploadFileWithConflictStrategy(client, file, _objectSpread(_objectSpread({}, options), {}, {
776
777
  name: newFileName
@@ -687,6 +687,33 @@ describe('File Model', () => {
687
687
  })
688
688
  })
689
689
 
690
+ it('should rename the file with "_cozyX" if there is a conflict', async () => {
691
+ const dirId = 'toto'
692
+ //first call we return an existing file => conflict
693
+ //second call, we reject as not found
694
+ statByPathSpy
695
+ .mockReturnValueOnce({
696
+ data: {
697
+ _id: 'file_id',
698
+ _type: 'io.cozy.files'
699
+ }
700
+ })
701
+ .mockRejectedValueOnce(new Error('Not Found'))
702
+
703
+ const opts = {
704
+ name: 'filename',
705
+ dirId,
706
+ conflictStrategy: 'rename',
707
+ conflictOptions: { delimiter: '_cozy' },
708
+ contentType: 'image/jpeg'
709
+ }
710
+ await fileModel.uploadFileWithConflictStrategy(cozyClient, '', opts)
711
+ expect(createFileSpy).toHaveBeenCalledWith('', {
712
+ ...opts,
713
+ name: 'filename_cozy1'
714
+ })
715
+ })
716
+
690
717
  it('should erase the file if there is a conflict', async () => {
691
718
  const dirId = 'toto'
692
719
  //first call we return an existing file => conflict
@@ -96,6 +96,9 @@ var triggers = {
96
96
  isKonnectorWorker: function isKonnectorWorker(trigger) {
97
97
  return trigger.worker === 'konnector';
98
98
  },
99
+ isKonnector: function isKonnector(trigger) {
100
+ return trigger.worker === 'konnector' || trigger.worker === 'client';
101
+ },
99
102
 
100
103
  /**
101
104
  * Returns the konnector slug that executed a trigger
@@ -105,7 +108,7 @@ var triggers = {
105
108
  * @returns {string|void} A konnector slug
106
109
  */
107
110
  getKonnector: function getKonnector(trigger) {
108
- if (!triggers.isKonnectorWorker(trigger)) {
111
+ if (!triggers.isKonnector(trigger)) {
109
112
  return null;
110
113
  }
111
114
 
@@ -86,6 +86,22 @@ describe('trigger model', () => {
86
86
  }
87
87
  }
88
88
 
89
+ const cliskTrigger = {
90
+ _rev: '1-31eb8f0da1db0f3196ccf0d4329ea554',
91
+ prefix: 'toto.mycozy.cloud',
92
+ arguments: '0 35 0 * * 3',
93
+ message: {
94
+ account: '4cbfe8f3d89edf60542d5fe9cdcac7b1',
95
+ konnector: 'orangemobile'
96
+ },
97
+ _id: 'fa4c076914ce46a92fa3e7e5f0672ca5',
98
+ domain: 'claire.mycozy.cloud',
99
+ worker: 'client',
100
+ debounce: '',
101
+ options: null,
102
+ type: '@client'
103
+ }
104
+
89
105
  describe('getKonnectorFromTrigger', () => {
90
106
  it('should work with normal triggers', () => {
91
107
  expect(triggerModel.getKonnector(normalTrigger)).toBe('orangemobile')
@@ -94,6 +110,10 @@ describe('trigger model', () => {
94
110
  it('should work with legacy triggers', () => {
95
111
  expect(triggerModel.getKonnector(legacyTrigger)).toBe('ameli')
96
112
  })
113
+
114
+ it('should work with clisk triggers', () => {
115
+ expect(triggerModel.getKonnector(cliskTrigger)).toBe('orangemobile')
116
+ })
97
117
  })
98
118
 
99
119
  describe('getAccountId', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "44.0.0",
3
+ "version": "44.1.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -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": "852539500a548a92416af09279398e6ded88bd7f"
78
+ "gitHead": "872a9d48bd8fbe743322d74829c68dd97d6c8980"
79
79
  }
@@ -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): object;
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;
@@ -83,5 +86,9 @@ export type FileUploadOptions = {
83
86
  * - Erase / rename
84
87
  */
85
88
  conflictStrategy?: string;
89
+ /**
90
+ * - Conflict options
91
+ */
92
+ conflictOptions?: import('../types').ConflictOptions;
86
93
  };
87
94
  import CozyClient from "../CozyClient";
@@ -7,6 +7,7 @@ export namespace triggerStates {
7
7
  }
8
8
  export namespace triggers {
9
9
  function isKonnectorWorker(trigger: import("../types").IOCozyTrigger): boolean;
10
+ function isKonnector(trigger: any): boolean;
10
11
  function getKonnector(trigger: import("../types").IOCozyTrigger): string | void;
11
12
  function getAccountId(trigger: import("../types").IOCozyTrigger): string;
12
13
  function isLatestErrorMuted(trigger: import("../types").IOCozyTrigger, account: import("../types").IOCozyAccount): boolean;