cozy-client 43.6.0 → 44.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.
@@ -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 = "43.6.0";
2706
+ CozyClient.version = "44.1.0";
2707
2707
 
2708
2708
  _microee.default.mixin(CozyClient);
2709
2709
 
@@ -659,33 +659,27 @@ var overrideFileForPath = /*#__PURE__*/function () {
659
659
  * Method to generate a new filename if there is a conflict
660
660
  *
661
661
  * @param {string} filenameWithoutExtension - A filename without the extension
662
- * @param {RegExp} [originalNameFormatRegex] - A regex to check if the name is still in his original format
662
+ * @param {import('../types').ConflictOptions} [conflictOptions] - Conflict options
663
663
  * @returns {string} A filename with the right suffix
664
664
  */
665
665
 
666
666
 
667
667
  exports.overrideFileForPath = overrideFileForPath;
668
668
 
669
- var generateNewFileNameOnConflict = function generateNewFileNameOnConflict(filenameWithoutExtension, originalNameFormatRegex) {
670
- var isOriginalNameFormat = false;
669
+ var generateNewFileNameOnConflict = function generateNewFileNameOnConflict(filenameWithoutExtension, conflictOptions) {
670
+ var delimiter = (conflictOptions === null || conflictOptions === void 0 ? void 0 : conflictOptions.delimiter) || '_'; //Check if the string ends by _1
671
671
 
672
- if (originalNameFormatRegex && originalNameFormatRegex.test(filenameWithoutExtension)) {
673
- isOriginalNameFormat = true;
674
- } //Check if the string ends by _1
675
-
676
-
677
- var regex = new RegExp('(_)([0-9]+)$');
672
+ var regex = new RegExp("(".concat(delimiter, ")([0-9]+)$"));
678
673
  var matches = filenameWithoutExtension.match(regex);
679
- var shouldIncrement = matches && !isOriginalNameFormat;
680
674
 
681
- if (shouldIncrement) {
675
+ if (matches) {
682
676
  var versionNumber = parseInt(matches[2]); //increment versionNumber
683
677
 
684
678
  versionNumber++;
685
- var newFilenameWithoutExtension = filenameWithoutExtension.replace(new RegExp('(_)([0-9]+)$'), "_".concat(versionNumber));
679
+ var newFilenameWithoutExtension = filenameWithoutExtension.replace(new RegExp("(".concat(delimiter, ")([0-9]+)$")), "".concat(delimiter).concat(versionNumber));
686
680
  return newFilenameWithoutExtension;
687
681
  } else {
688
- return "".concat(filenameWithoutExtension, "_1");
682
+ return "".concat(filenameWithoutExtension).concat(delimiter, "1");
689
683
  }
690
684
  };
691
685
  /**
@@ -713,6 +707,7 @@ var generateFileNameForRevision = function generateFileNameForRevision(file, rev
713
707
  * @property {object} [metadata] - An object containing the metadata to attach
714
708
  * @property {string} [contentType] - The file Content-Type
715
709
  * @property {string} [conflictStrategy] - Erase / rename
710
+ * @property {import('../types').ConflictOptions} [conflictOptions] - Conflict options
716
711
  */
717
712
 
718
713
  /**
@@ -736,13 +731,13 @@ exports.generateFileNameForRevision = generateFileNameForRevision;
736
731
 
737
732
  var uploadFileWithConflictStrategy = /*#__PURE__*/function () {
738
733
  var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(client, file, options) {
739
- 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;
740
735
 
741
736
  return _regenerator.default.wrap(function _callee6$(_context6) {
742
737
  while (1) {
743
738
  switch (_context6.prev = _context6.next) {
744
739
  case 0:
745
- name = options.name, dirId = options.dirId, conflictStrategy = options.conflictStrategy;
740
+ name = options.name, dirId = options.dirId, conflictStrategy = options.conflictStrategy, conflictOptions = options.conflictOptions;
746
741
  _context6.prev = 1;
747
742
  _context6.next = 4;
748
743
  return getFullpath(client, dirId, name);
@@ -776,7 +771,7 @@ var uploadFileWithConflictStrategy = /*#__PURE__*/function () {
776
771
  name: name,
777
772
  type: 'file'
778
773
  }), filename = _splitFilename2.filename, extension = _splitFilename2.extension;
779
- newFileName = generateNewFileNameOnConflict(filename) + extension; //recall itself with the newFilename.
774
+ newFileName = generateNewFileNameOnConflict(filename, conflictOptions) + extension; //recall itself with the newFilename.
780
775
 
781
776
  return _context6.abrupt("return", uploadFileWithConflictStrategy(client, file, _objectSpread(_objectSpread({}, options), {}, {
782
777
  name: newFileName
@@ -569,31 +569,44 @@ describe('File Model', () => {
569
569
  expect(filename2).toEqual('test_2')
570
570
  const filename3 = fileModel.generateNewFileNameOnConflict('test_1_1_test')
571
571
  expect(filename3).toEqual('test_1_1_test_1')
572
- const filename4 = fileModel.generateNewFileNameOnConflict('test_')
573
- expect(filename4).toEqual('test__1')
574
- const filename5 = fileModel.generateNewFileNameOnConflict('test_1_1')
575
- expect(filename5).toEqual('test_1_2')
572
+ const filename4 = fileModel.generateNewFileNameOnConflict(
573
+ 'test_1_1_test_1'
574
+ )
575
+ expect(filename4).toEqual('test_1_1_test_2')
576
+ const filename5 = fileModel.generateNewFileNameOnConflict('test_')
577
+ expect(filename5).toEqual('test__1')
576
578
  })
577
579
 
578
- it('should generate the right file name with _X when passing a format', () => {
579
- const regex = new RegExp('^([a-z]+)(_)([0-9]+)$') // test_1
580
+ it('should generate the right file name with _cozyX', () => {
581
+ const conflictOptions = {
582
+ delimiter: '_cozy'
583
+ }
580
584
 
581
- const filename1 = fileModel.generateNewFileNameOnConflict('test', regex)
582
- expect(filename1).toEqual('test_1')
583
- const filename2 = fileModel.generateNewFileNameOnConflict('test_1', regex)
584
- expect(filename2).toEqual('test_1_1')
585
+ const filename1 = fileModel.generateNewFileNameOnConflict(
586
+ 'test',
587
+ conflictOptions
588
+ )
589
+ expect(filename1).toEqual('test_cozy1')
590
+ const filename2 = fileModel.generateNewFileNameOnConflict(
591
+ 'test_cozy1',
592
+ conflictOptions
593
+ )
594
+ expect(filename2).toEqual('test_cozy2')
585
595
  const filename3 = fileModel.generateNewFileNameOnConflict(
586
- 'test_1_1_test',
587
- regex
596
+ 'test_cozy1_test',
597
+ conflictOptions
588
598
  )
589
- expect(filename3).toEqual('test_1_1_test_1')
590
- const filename4 = fileModel.generateNewFileNameOnConflict('test_', regex)
591
- expect(filename4).toEqual('test__1')
599
+ expect(filename3).toEqual('test_cozy1_test_cozy1')
600
+ const filename4 = fileModel.generateNewFileNameOnConflict(
601
+ 'test_cozy1_test_cozy1',
602
+ conflictOptions
603
+ )
604
+ expect(filename4).toEqual('test_cozy1_test_cozy2')
592
605
  const filename5 = fileModel.generateNewFileNameOnConflict(
593
- 'test_1_1',
594
- regex
606
+ 'test_',
607
+ conflictOptions
595
608
  )
596
- expect(filename5).toEqual('test_1_2')
609
+ expect(filename5).toEqual('test__cozy1')
597
610
  })
598
611
  })
599
612
 
@@ -674,6 +687,33 @@ describe('File Model', () => {
674
687
  })
675
688
  })
676
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
+
677
717
  it('should erase the file if there is a conflict', async () => {
678
718
  const dirId = 'toto'
679
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/dist/types.js CHANGED
@@ -652,6 +652,13 @@ var _dsl = require("./queries/dsl");
652
652
  * @property {string} hash - The redirect link's path (i.e. '/folder/SOME_FOLDER_ID')
653
653
  */
654
654
 
655
+ /**
656
+ * Represents available options of generateNewFileNameOnConflict method
657
+ *
658
+ * @typedef {object} ConflictOptions
659
+ * @property {string} [delimiter] - Delimiter before the incremented number. Default to '_'
660
+ */
661
+
655
662
  /**
656
663
  * Template to type useState
657
664
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "43.6.0",
3
+ "version": "44.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": "^43.0.0",
21
+ "cozy-stack-client": "^44.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": "c9eaf3d5a902d852ac4c8ec6b2c72698833bf865"
78
+ "gitHead": "74be3146ea4706cf3c2d7a3b07c4ef1171e33df7"
79
79
  }
@@ -52,7 +52,7 @@ export function move(client: CozyClient, fileId: string, destination: {
52
52
  path: string;
53
53
  }, force?: boolean): Promise<any>;
54
54
  export function overrideFileForPath(client: CozyClient, dirPath: string, file: object, metadata: object): Promise<import("../types").IOCozyFile>;
55
- export function generateNewFileNameOnConflict(filenameWithoutExtension: string, originalNameFormatRegex?: RegExp): string;
55
+ export function generateNewFileNameOnConflict(filenameWithoutExtension: string, conflictOptions?: import('../types').ConflictOptions): string;
56
56
  export function generateFileNameForRevision(file: import("../types").IOCozyFile, revision: object, f: Function): string;
57
57
  export function uploadFileWithConflictStrategy(client: CozyClient, file: string | ArrayBuffer, options: FileUploadOptions): any;
58
58
  export function readMobileFile(fileURL: string): Promise<any>;
@@ -83,5 +83,9 @@ export type FileUploadOptions = {
83
83
  * - Erase / rename
84
84
  */
85
85
  conflictStrategy?: string;
86
+ /**
87
+ * - Conflict options
88
+ */
89
+ conflictOptions?: import('../types').ConflictOptions;
86
90
  };
87
91
  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;
package/types/types.d.ts CHANGED
@@ -1092,6 +1092,15 @@ export type RedirectLinkData = {
1092
1092
  */
1093
1093
  hash: string;
1094
1094
  };
1095
+ /**
1096
+ * Represents available options of generateNewFileNameOnConflict method
1097
+ */
1098
+ export type ConflictOptions = {
1099
+ /**
1100
+ * - Delimiter before the incremented number. Default to '_'
1101
+ */
1102
+ delimiter?: string;
1103
+ };
1095
1104
  /**
1096
1105
  * Template to type useState
1097
1106
  */