cozy-client 60.24.0 → 60.26.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.
- package/dist/CozyClient.js +1 -1
- package/dist/models/assistant.js +38 -40
- package/dist/models/file.js +13 -3
- package/dist/models/file.spec.js +74 -8
- package/dist/types.js +1 -1
- package/package.json +2 -2
- package/types/models/assistant.d.ts +1 -1
- package/types/types.d.ts +1 -1
package/dist/CozyClient.js
CHANGED
|
@@ -3126,7 +3126,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
3126
3126
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
3127
3127
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
3128
3128
|
|
|
3129
|
-
CozyClient.version = "60.
|
|
3129
|
+
CozyClient.version = "60.26.1";
|
|
3130
3130
|
|
|
3131
3131
|
_microee.default.mixin(CozyClient);
|
|
3132
3132
|
|
package/dist/models/assistant.js
CHANGED
|
@@ -41,13 +41,14 @@ var ACCOUNT_DOCTYPE = 'io.cozy.accounts';
|
|
|
41
41
|
*
|
|
42
42
|
* @param {CozyClient} client - An instance of CozyClient
|
|
43
43
|
* @param {Assistant} assistantData - Data for the new assistant
|
|
44
|
-
* @returns {Promise<
|
|
44
|
+
* @returns {Promise<Assistant>} - A promise that resolves with the created assistant document
|
|
45
45
|
* @throws {Error} - Throws an error if the creation fails
|
|
46
46
|
*/
|
|
47
47
|
|
|
48
48
|
var createAssistant = /*#__PURE__*/function () {
|
|
49
49
|
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(client, assistantData) {
|
|
50
|
-
var createdAccountId, account, response, assistant;
|
|
50
|
+
var createdAccountId, account, response, assistant, _yield$client$save, savedAssistant;
|
|
51
|
+
|
|
51
52
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
52
53
|
while (1) {
|
|
53
54
|
switch (_context.prev = _context.next) {
|
|
@@ -108,43 +109,44 @@ var createAssistant = /*#__PURE__*/function () {
|
|
|
108
109
|
return client.save(assistant);
|
|
109
110
|
|
|
110
111
|
case 14:
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
_yield$client$save = _context.sent;
|
|
113
|
+
savedAssistant = _yield$client$save.data;
|
|
114
|
+
return _context.abrupt("return", savedAssistant);
|
|
113
115
|
|
|
114
|
-
case
|
|
115
|
-
_context.prev =
|
|
116
|
+
case 19:
|
|
117
|
+
_context.prev = 19;
|
|
116
118
|
_context.t0 = _context["catch"](1);
|
|
117
119
|
|
|
118
120
|
if (!createdAccountId) {
|
|
119
|
-
_context.next =
|
|
121
|
+
_context.next = 30;
|
|
120
122
|
break;
|
|
121
123
|
}
|
|
122
124
|
|
|
123
|
-
_context.prev =
|
|
124
|
-
_context.next =
|
|
125
|
+
_context.prev = 22;
|
|
126
|
+
_context.next = 25;
|
|
125
127
|
return client.stackClient.collection('io.cozy.accounts').destroy({
|
|
126
128
|
_id: createdAccountId
|
|
127
129
|
});
|
|
128
130
|
|
|
129
|
-
case
|
|
130
|
-
_context.next =
|
|
131
|
+
case 25:
|
|
132
|
+
_context.next = 30;
|
|
131
133
|
break;
|
|
132
134
|
|
|
133
|
-
case
|
|
134
|
-
_context.prev =
|
|
135
|
-
_context.t1 = _context["catch"](
|
|
135
|
+
case 27:
|
|
136
|
+
_context.prev = 27;
|
|
137
|
+
_context.t1 = _context["catch"](22);
|
|
136
138
|
|
|
137
139
|
_logger.default.warn('Failed to cleanup orphaned account:', _context.t1);
|
|
138
140
|
|
|
139
|
-
case
|
|
141
|
+
case 30:
|
|
140
142
|
throw new Error("Failed to create assistant: ".concat(_context.t0.message));
|
|
141
143
|
|
|
142
|
-
case
|
|
144
|
+
case 31:
|
|
143
145
|
case "end":
|
|
144
146
|
return _context.stop();
|
|
145
147
|
}
|
|
146
148
|
}
|
|
147
|
-
}, _callee, null, [[1,
|
|
149
|
+
}, _callee, null, [[1, 19], [22, 27]]);
|
|
148
150
|
}));
|
|
149
151
|
|
|
150
152
|
return function createAssistant(_x, _x2) {
|
|
@@ -165,7 +167,7 @@ exports.createAssistant = createAssistant;
|
|
|
165
167
|
|
|
166
168
|
var deleteAssistant = /*#__PURE__*/function () {
|
|
167
169
|
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(client, assistantId) {
|
|
168
|
-
var
|
|
170
|
+
var _yield$client$query, assistantDoc, included, provider;
|
|
169
171
|
|
|
170
172
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
171
173
|
while (1) {
|
|
@@ -176,42 +178,38 @@ var deleteAssistant = /*#__PURE__*/function () {
|
|
|
176
178
|
return client.query((0, _dsl.Q)(ASSISTANT_DOCTYPE).getById(assistantId).include(['provider']));
|
|
177
179
|
|
|
178
180
|
case 3:
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
181
|
+
_yield$client$query = _context2.sent;
|
|
182
|
+
assistantDoc = _yield$client$query.data;
|
|
183
|
+
included = _yield$client$query.included;
|
|
182
184
|
_context2.next = 8;
|
|
183
|
-
return client.
|
|
184
|
-
_id: assistantId,
|
|
185
|
-
_rev: assistantInstance._rev
|
|
186
|
-
});
|
|
185
|
+
return client.destroy(assistantDoc);
|
|
187
186
|
|
|
188
187
|
case 8:
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
provider = included === null || included === void 0 ? void 0 : included[0];
|
|
189
|
+
|
|
190
|
+
if (!provider) {
|
|
191
|
+
_context2.next = 12;
|
|
191
192
|
break;
|
|
192
193
|
}
|
|
193
194
|
|
|
194
|
-
_context2.next =
|
|
195
|
-
return client.
|
|
196
|
-
_id: provider._id,
|
|
197
|
-
_rev: provider._rev
|
|
198
|
-
});
|
|
195
|
+
_context2.next = 12;
|
|
196
|
+
return client.destroy(provider);
|
|
199
197
|
|
|
200
|
-
case
|
|
201
|
-
_context2.next =
|
|
198
|
+
case 12:
|
|
199
|
+
_context2.next = 17;
|
|
202
200
|
break;
|
|
203
201
|
|
|
204
|
-
case
|
|
205
|
-
_context2.prev =
|
|
202
|
+
case 14:
|
|
203
|
+
_context2.prev = 14;
|
|
206
204
|
_context2.t0 = _context2["catch"](0);
|
|
207
205
|
throw new Error("Failed to delete assistant: ".concat(_context2.t0.message));
|
|
208
206
|
|
|
209
|
-
case
|
|
207
|
+
case 17:
|
|
210
208
|
case "end":
|
|
211
209
|
return _context2.stop();
|
|
212
210
|
}
|
|
213
211
|
}
|
|
214
|
-
}, _callee2, null, [[0,
|
|
212
|
+
}, _callee2, null, [[0, 14]]);
|
|
215
213
|
}));
|
|
216
214
|
|
|
217
215
|
return function deleteAssistant(_x3, _x4) {
|
|
@@ -233,7 +231,7 @@ exports.deleteAssistant = deleteAssistant;
|
|
|
233
231
|
|
|
234
232
|
var editAssistant = /*#__PURE__*/function () {
|
|
235
233
|
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(client, assistantId, assistantData) {
|
|
236
|
-
var _existedAssistant$
|
|
234
|
+
var _existedAssistant$inc, _existedAssistantData, _existedAssistantData2, _existedAssistantData3, _existedAssistantData4, _existedAssistantData5, existedAssistant, existedAssistantData, provider, account, _account$data, _account$auth, response, assistant;
|
|
237
235
|
|
|
238
236
|
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
239
237
|
while (1) {
|
|
@@ -255,7 +253,7 @@ var editAssistant = /*#__PURE__*/function () {
|
|
|
255
253
|
|
|
256
254
|
case 6:
|
|
257
255
|
existedAssistantData = existedAssistant.data;
|
|
258
|
-
provider = existedAssistant === null || existedAssistant === void 0 ? void 0 : (_existedAssistant$
|
|
256
|
+
provider = existedAssistant === null || existedAssistant === void 0 ? void 0 : (_existedAssistant$inc = existedAssistant.included) === null || _existedAssistant$inc === void 0 ? void 0 : _existedAssistant$inc[0];
|
|
259
257
|
|
|
260
258
|
if (provider) {
|
|
261
259
|
_context3.next = 10;
|
package/dist/models/file.js
CHANGED
|
@@ -902,14 +902,24 @@ var overrideFileForPath = /*#__PURE__*/function () {
|
|
|
902
902
|
exports.overrideFileForPath = overrideFileForPath;
|
|
903
903
|
|
|
904
904
|
var generateNewFileNameOnConflict = function generateNewFileNameOnConflict(filenameWithoutExtension, conflictOptions) {
|
|
905
|
-
var delimiter =
|
|
905
|
+
var delimiter = conflictOptions === null || conflictOptions === void 0 ? void 0 : conflictOptions.delimiter;
|
|
906
|
+
|
|
907
|
+
if (!delimiter) {
|
|
908
|
+
var _matches = filenameWithoutExtension.match(/^(.*) \(([0-9]+)\)$/);
|
|
909
|
+
|
|
910
|
+
if (_matches) {
|
|
911
|
+
return "".concat(_matches[1], " (").concat(parseInt(_matches[2], 10) + 1, ")");
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
return "".concat(filenameWithoutExtension, " (1)");
|
|
915
|
+
} // Keep explicit delimiter support for callers that opted into the legacy format.
|
|
916
|
+
|
|
906
917
|
|
|
907
918
|
var regex = new RegExp("(".concat(delimiter, ")([0-9]+)$"));
|
|
908
919
|
var matches = filenameWithoutExtension.match(regex);
|
|
909
920
|
|
|
910
921
|
if (matches) {
|
|
911
|
-
var versionNumber = parseInt(matches[2]);
|
|
912
|
-
|
|
922
|
+
var versionNumber = parseInt(matches[2], 10);
|
|
913
923
|
versionNumber++;
|
|
914
924
|
var newFilenameWithoutExtension = filenameWithoutExtension.replace(new RegExp("(".concat(delimiter, ")([0-9]+)$")), "".concat(delimiter).concat(versionNumber));
|
|
915
925
|
return newFilenameWithoutExtension;
|
package/dist/models/file.spec.js
CHANGED
|
@@ -592,19 +592,59 @@ describe('File Model', () => {
|
|
|
592
592
|
})
|
|
593
593
|
|
|
594
594
|
describe('generateNewFileNameOnConflict', () => {
|
|
595
|
-
it('should generate the
|
|
595
|
+
it('should generate the default file name with parenthesized copy counters', () => {
|
|
596
596
|
const filename1 = fileModel.generateNewFileNameOnConflict('test')
|
|
597
|
+
expect(filename1).toEqual('test (1)')
|
|
598
|
+
const filename2 = fileModel.generateNewFileNameOnConflict('test (1)')
|
|
599
|
+
expect(filename2).toEqual('test (2)')
|
|
600
|
+
const filename3 = fileModel.generateNewFileNameOnConflict('test_1_1_test')
|
|
601
|
+
expect(filename3).toEqual('test_1_1_test (1)')
|
|
602
|
+
const filename4 = fileModel.generateNewFileNameOnConflict(
|
|
603
|
+
'test_1_1_test (1)'
|
|
604
|
+
)
|
|
605
|
+
expect(filename4).toEqual('test_1_1_test (2)')
|
|
606
|
+
const filename5 = fileModel.generateNewFileNameOnConflict('test_')
|
|
607
|
+
expect(filename5).toEqual('test_ (1)')
|
|
608
|
+
})
|
|
609
|
+
|
|
610
|
+
it('should not increment numbers that are part of the file name', () => {
|
|
611
|
+
const filename1 = fileModel.generateNewFileNameOnConflict('IMG_4521')
|
|
612
|
+
expect(filename1).toEqual('IMG_4521 (1)')
|
|
613
|
+
const filename2 = fileModel.generateNewFileNameOnConflict('DSC_0001')
|
|
614
|
+
expect(filename2).toEqual('DSC_0001 (1)')
|
|
615
|
+
const filename3 = fileModel.generateNewFileNameOnConflict('report_2024')
|
|
616
|
+
expect(filename3).toEqual('report_2024 (1)')
|
|
617
|
+
const filename4 = fileModel.generateNewFileNameOnConflict(
|
|
618
|
+
'report (draft)'
|
|
619
|
+
)
|
|
620
|
+
expect(filename4).toEqual('report (draft) (1)')
|
|
621
|
+
})
|
|
622
|
+
|
|
623
|
+
it('should keep the legacy delimiter behavior when delimiter is passed', () => {
|
|
624
|
+
const conflictOptions = {
|
|
625
|
+
delimiter: '_'
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
const filename1 = fileModel.generateNewFileNameOnConflict(
|
|
629
|
+
'test',
|
|
630
|
+
conflictOptions
|
|
631
|
+
)
|
|
597
632
|
expect(filename1).toEqual('test_1')
|
|
598
|
-
const filename2 = fileModel.generateNewFileNameOnConflict(
|
|
633
|
+
const filename2 = fileModel.generateNewFileNameOnConflict(
|
|
634
|
+
'test_1',
|
|
635
|
+
conflictOptions
|
|
636
|
+
)
|
|
599
637
|
expect(filename2).toEqual('test_2')
|
|
600
|
-
const filename3 = fileModel.generateNewFileNameOnConflict(
|
|
638
|
+
const filename3 = fileModel.generateNewFileNameOnConflict(
|
|
639
|
+
'test_1_1_test',
|
|
640
|
+
conflictOptions
|
|
641
|
+
)
|
|
601
642
|
expect(filename3).toEqual('test_1_1_test_1')
|
|
602
643
|
const filename4 = fileModel.generateNewFileNameOnConflict(
|
|
603
|
-
'
|
|
644
|
+
'test_',
|
|
645
|
+
conflictOptions
|
|
604
646
|
)
|
|
605
|
-
expect(filename4).toEqual('
|
|
606
|
-
const filename5 = fileModel.generateNewFileNameOnConflict('test_')
|
|
607
|
-
expect(filename5).toEqual('test__1')
|
|
647
|
+
expect(filename4).toEqual('test__1')
|
|
608
648
|
})
|
|
609
649
|
|
|
610
650
|
it('should generate the right file name with _cozyX', () => {
|
|
@@ -713,7 +753,33 @@ describe('File Model', () => {
|
|
|
713
753
|
await fileModel.uploadFileWithConflictStrategy(cozyClient, '', opts)
|
|
714
754
|
expect(createFileSpy).toHaveBeenCalledWith('', {
|
|
715
755
|
...opts,
|
|
716
|
-
name: '
|
|
756
|
+
name: 'filename (1)'
|
|
757
|
+
})
|
|
758
|
+
})
|
|
759
|
+
|
|
760
|
+
it('should keep real filename numbers when renaming a file with an extension', async () => {
|
|
761
|
+
const dirId = 'toto'
|
|
762
|
+
//first call we return an existing file => conflict
|
|
763
|
+
//second call, we reject as not found
|
|
764
|
+
statByPathSpy
|
|
765
|
+
.mockReturnValueOnce({
|
|
766
|
+
data: {
|
|
767
|
+
_id: 'file_id',
|
|
768
|
+
_type: 'io.cozy.files'
|
|
769
|
+
}
|
|
770
|
+
})
|
|
771
|
+
.mockRejectedValueOnce(new Error('Not Found'))
|
|
772
|
+
|
|
773
|
+
const opts = {
|
|
774
|
+
name: 'IMG_4521.jpg',
|
|
775
|
+
dirId,
|
|
776
|
+
conflictStrategy: 'rename',
|
|
777
|
+
contentType: 'image/jpeg'
|
|
778
|
+
}
|
|
779
|
+
await fileModel.uploadFileWithConflictStrategy(cozyClient, '', opts)
|
|
780
|
+
expect(createFileSpy).toHaveBeenCalledWith('', {
|
|
781
|
+
...opts,
|
|
782
|
+
name: 'IMG_4521 (1).jpg'
|
|
717
783
|
})
|
|
718
784
|
})
|
|
719
785
|
|
package/dist/types.js
CHANGED
|
@@ -957,7 +957,7 @@ var _dsl = require("./queries/dsl");
|
|
|
957
957
|
* Represents available options of generateNewFileNameOnConflict method
|
|
958
958
|
*
|
|
959
959
|
* @typedef {object} ConflictOptions
|
|
960
|
-
* @property {string} [delimiter] -
|
|
960
|
+
* @property {string} [delimiter] - Custom delimiter before the incremented number. Defaults to parenthesized copy counters.
|
|
961
961
|
*/
|
|
962
962
|
|
|
963
963
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "60.
|
|
3
|
+
"version": "60.26.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"react-native-ios11-devicecheck": "^0.0.3"
|
|
75
75
|
},
|
|
76
76
|
"sideEffects": false,
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "60136387114f34ee7b9cd9d73541fb29922c2bd7"
|
|
78
78
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function createAssistant(client: CozyClient, assistantData: Assistant): Promise<
|
|
1
|
+
export function createAssistant(client: CozyClient, assistantData: Assistant): Promise<Assistant>;
|
|
2
2
|
export function deleteAssistant(client: CozyClient, assistantId: string): Promise<void>;
|
|
3
3
|
export function editAssistant(client: CozyClient, assistantId: string, assistantData: Assistant): Promise<void>;
|
|
4
4
|
export type Assistant = {
|
package/types/types.d.ts
CHANGED
|
@@ -1702,7 +1702,7 @@ export type RedirectLinkData = {
|
|
|
1702
1702
|
*/
|
|
1703
1703
|
export type ConflictOptions = {
|
|
1704
1704
|
/**
|
|
1705
|
-
* -
|
|
1705
|
+
* - Custom delimiter before the incremented number. Defaults to parenthesized copy counters.
|
|
1706
1706
|
*/
|
|
1707
1707
|
delimiter?: string;
|
|
1708
1708
|
};
|