cozy-client 43.6.0 → 44.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.
@@ -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.0.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
  /**
@@ -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
 
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.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": "^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": "852539500a548a92416af09279398e6ded88bd7f"
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>;
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
  */