cozy-client 45.14.1 → 46.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.
- package/dist/CozyClient.js +1 -1
- package/dist/models/document/locales/en.json +83 -0
- package/dist/models/document/locales/fr.json +83 -0
- package/dist/models/paper.js +271 -2
- package/dist/models/paper.spec.js +69 -0
- package/dist/queries/dsl.js +9 -0
- package/dist/queries/dsl.spec.js +12 -1
- package/package.json +3 -3
- package/types/models/paper.d.ts +36 -0
package/dist/CozyClient.js
CHANGED
|
@@ -2705,7 +2705,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2705
2705
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
2706
2706
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
2707
2707
|
|
|
2708
|
-
CozyClient.version = "
|
|
2708
|
+
CozyClient.version = "46.0.0";
|
|
2709
2709
|
|
|
2710
2710
|
_microee.default.mixin(CozyClient);
|
|
2711
2711
|
|
|
@@ -148,6 +148,89 @@
|
|
|
148
148
|
"transport": "Transport",
|
|
149
149
|
"undefined": "Undefined",
|
|
150
150
|
"work_study": "Work & Study"
|
|
151
|
+
},
|
|
152
|
+
"qualification": {
|
|
153
|
+
"date": {
|
|
154
|
+
"title": {
|
|
155
|
+
"datetime": "Added on",
|
|
156
|
+
"AObtentionDate": "License A, delivered on",
|
|
157
|
+
"BObtentionDate": "License B, delivered on",
|
|
158
|
+
"CObtentionDate": "License C, delivered on",
|
|
159
|
+
"DObtentionDate": "License D, delivered on",
|
|
160
|
+
"issueDate": "Delivered on",
|
|
161
|
+
"expirationDate": "Expiration date",
|
|
162
|
+
"referencedDate": "Referenced date",
|
|
163
|
+
"shootingDate": "Shooting date",
|
|
164
|
+
"obtentionDate": "Date obtained",
|
|
165
|
+
"date": "Document date"
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
"information": {
|
|
169
|
+
"title": {
|
|
170
|
+
"fine": {
|
|
171
|
+
"number": "Amount of the fine"
|
|
172
|
+
},
|
|
173
|
+
"fidelity_card": {
|
|
174
|
+
"number": "Card number"
|
|
175
|
+
},
|
|
176
|
+
"caf": {
|
|
177
|
+
"number": "CAF file number"
|
|
178
|
+
},
|
|
179
|
+
"payment_proof_family_allowance": {
|
|
180
|
+
"number":"CAF file number"
|
|
181
|
+
},
|
|
182
|
+
"vehicle_registration": {
|
|
183
|
+
"number": "Vehicle registration number (VIN)"
|
|
184
|
+
},
|
|
185
|
+
"national_id_card": {
|
|
186
|
+
"number": "National ID card number"
|
|
187
|
+
},
|
|
188
|
+
"bank_details": {
|
|
189
|
+
"number": "IBAN number"
|
|
190
|
+
},
|
|
191
|
+
"passport": {
|
|
192
|
+
"number": "Passport number"
|
|
193
|
+
},
|
|
194
|
+
"driver_license": {
|
|
195
|
+
"number": "License number"
|
|
196
|
+
},
|
|
197
|
+
"residence_permit": {
|
|
198
|
+
"number": "License number"
|
|
199
|
+
},
|
|
200
|
+
"national_health_insurance_card": {
|
|
201
|
+
"number": "National health insurance card number"
|
|
202
|
+
},
|
|
203
|
+
"pay_sheet": {
|
|
204
|
+
"number": "Gross remuneration"
|
|
205
|
+
},
|
|
206
|
+
"tax_return": {
|
|
207
|
+
"number": "Reference tax number"
|
|
208
|
+
},
|
|
209
|
+
"tax_notice": {
|
|
210
|
+
"number": "Reference tax number"
|
|
211
|
+
},
|
|
212
|
+
"real_estate_tax": {
|
|
213
|
+
"number": "Reference tax number"
|
|
214
|
+
},
|
|
215
|
+
"tax_timetable": {
|
|
216
|
+
"number": "Reference tax number"
|
|
217
|
+
},
|
|
218
|
+
"country": "Beneficiary nationality",
|
|
219
|
+
"refTaxIncome": "Reference tax income",
|
|
220
|
+
"contractType": "Contract type",
|
|
221
|
+
"noticePeriod": "Expiration alert",
|
|
222
|
+
"netSocialAmount": "Net social amount",
|
|
223
|
+
"employerName": "Name of employer",
|
|
224
|
+
"bicNumber": "BIC number"
|
|
225
|
+
},
|
|
226
|
+
"day": "day |||| days"
|
|
227
|
+
},
|
|
228
|
+
"contact": "Owner",
|
|
229
|
+
"page": "Side of the document",
|
|
230
|
+
"front": "Front side",
|
|
231
|
+
"back": "Back side",
|
|
232
|
+
"qualification": "Qualification",
|
|
233
|
+
"noInfo": "No information"
|
|
151
234
|
}
|
|
152
235
|
},
|
|
153
236
|
"MagicFolders": {
|
|
@@ -148,6 +148,89 @@
|
|
|
148
148
|
"transport": "Transport",
|
|
149
149
|
"undefined": "Indéfini",
|
|
150
150
|
"work_study": "Travail & Études"
|
|
151
|
+
},
|
|
152
|
+
"qualification": {
|
|
153
|
+
"date": {
|
|
154
|
+
"title": {
|
|
155
|
+
"datetime": "Ajouté le",
|
|
156
|
+
"AObtentionDate": "Permis A, délivré le",
|
|
157
|
+
"BObtentionDate": "Permis B, délivré le",
|
|
158
|
+
"CObtentionDate": "Permis C, délivré le",
|
|
159
|
+
"DObtentionDate": "Permis D, délivré le",
|
|
160
|
+
"issueDate": "Délivré le",
|
|
161
|
+
"expirationDate": "Date d'expiration",
|
|
162
|
+
"referencedDate": "Date de référence",
|
|
163
|
+
"shootingDate": "Date de prise de vue",
|
|
164
|
+
"obtentionDate": "Date d'obtention",
|
|
165
|
+
"date": "Date du document"
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
"information": {
|
|
169
|
+
"title": {
|
|
170
|
+
"fine": {
|
|
171
|
+
"number": "Montant de l'amende"
|
|
172
|
+
},
|
|
173
|
+
"fidelity_card": {
|
|
174
|
+
"number": "Numéro de la carte"
|
|
175
|
+
},
|
|
176
|
+
"caf": {
|
|
177
|
+
"number": "Numéro de dossier CAF"
|
|
178
|
+
},
|
|
179
|
+
"payment_proof_family_allowance": {
|
|
180
|
+
"number":"Numéro de dossier CAF"
|
|
181
|
+
},
|
|
182
|
+
"vehicle_registration": {
|
|
183
|
+
"number": "Numéro de la carte grise (VIN)"
|
|
184
|
+
},
|
|
185
|
+
"national_id_card": {
|
|
186
|
+
"number": "Numéro de la carte d'identité"
|
|
187
|
+
},
|
|
188
|
+
"bank_details": {
|
|
189
|
+
"number": "Numéro d'IBAN"
|
|
190
|
+
},
|
|
191
|
+
"passport": {
|
|
192
|
+
"number": "Numéro du passeport"
|
|
193
|
+
},
|
|
194
|
+
"driver_license": {
|
|
195
|
+
"number": "Numéro du permis"
|
|
196
|
+
},
|
|
197
|
+
"residence_permit": {
|
|
198
|
+
"number": "Numéro du permis"
|
|
199
|
+
},
|
|
200
|
+
"national_health_insurance_card": {
|
|
201
|
+
"number": "Numéro de la carte vitale"
|
|
202
|
+
},
|
|
203
|
+
"pay_sheet": {
|
|
204
|
+
"number": "Rémunération brute"
|
|
205
|
+
},
|
|
206
|
+
"tax_return": {
|
|
207
|
+
"number": "Numéro fiscal de référence"
|
|
208
|
+
},
|
|
209
|
+
"tax_notice": {
|
|
210
|
+
"number": "Numéro fiscal de référence"
|
|
211
|
+
},
|
|
212
|
+
"real_estate_tax": {
|
|
213
|
+
"number": "Numéro fiscal de référence"
|
|
214
|
+
},
|
|
215
|
+
"tax_timetable": {
|
|
216
|
+
"number": "Numéro fiscal de référence"
|
|
217
|
+
},
|
|
218
|
+
"country": "Nationalité du bénéficiaire",
|
|
219
|
+
"refTaxIncome": "Revenu fiscal de référence",
|
|
220
|
+
"contractType": "Type de contrat",
|
|
221
|
+
"noticePeriod": "Alerte d’expiration",
|
|
222
|
+
"netSocialAmount": "Montant net social",
|
|
223
|
+
"employerName": "Nom de l'employeur",
|
|
224
|
+
"bicNumber": "Numéro BIC"
|
|
225
|
+
},
|
|
226
|
+
"day": "jour |||| jours"
|
|
227
|
+
},
|
|
228
|
+
"contact": "Titulaire",
|
|
229
|
+
"page": "Face du document",
|
|
230
|
+
"front": "Face avant",
|
|
231
|
+
"back": "Face arrière",
|
|
232
|
+
"qualification": "Qualification",
|
|
233
|
+
"noInfo": "Non renseigné(e)"
|
|
151
234
|
}
|
|
152
235
|
},
|
|
153
236
|
"MagicFolders": {
|
package/dist/models/paper.js
CHANGED
|
@@ -5,12 +5,18 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.isExpiringSoon = exports.isExpired = exports.computeExpirationNoticeLink = exports.computeExpirationNoticeDate = exports.computeExpirationDate = exports.isExpiring = void 0;
|
|
8
|
+
exports.formatContactValue = exports.getTranslatedNameForContact = exports.formatOtherMetadataValue = exports.getTranslatedNameForOtherMetadata = exports.formatInformationMetadataValue = exports.getTranslatedNameForInformationMetadata = exports.formatDateMetadataValue = exports.getTranslatedNameForDateMetadata = exports.getMetadataQualificationType = exports.formatMetadataQualification = exports.isExpiringSoon = exports.isExpired = exports.computeExpirationNoticeLink = exports.computeExpirationNoticeDate = exports.computeExpirationDate = exports.isExpiring = exports.KNOWN_OTHER_METADATA_NAMES = exports.KNOWN_INFORMATION_METADATA_NAMES = exports.KNOWN_DATE_METADATA_NAMES = void 0;
|
|
9
|
+
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
11
|
|
|
10
12
|
var _add = _interopRequireDefault(require("date-fns/add"));
|
|
11
13
|
|
|
12
14
|
var _sub = _interopRequireDefault(require("date-fns/sub"));
|
|
13
15
|
|
|
16
|
+
var _locales = require("./document/locales");
|
|
17
|
+
|
|
18
|
+
var _contact = require("./contact");
|
|
19
|
+
|
|
14
20
|
/**
|
|
15
21
|
* @typedef {import("../types").IOCozyFile} IOCozyFile
|
|
16
22
|
*/
|
|
@@ -22,12 +28,19 @@ var EXPIRATION_LINK_BY_LABEL = {
|
|
|
22
28
|
passport: 'https://www.service-public.fr/particuliers/vosdroits/N360',
|
|
23
29
|
driver_license: 'https://permisdeconduire.ants.gouv.fr/demarches-en-ligne/perte-vol-deterioration-fin-de-validite-ou-changement-d-etat-civil'
|
|
24
30
|
};
|
|
31
|
+
var KNOWN_DATE_METADATA_NAMES = ['AObtentionDate', 'BObtentionDate', 'CObtentionDate', 'DObtentionDate', 'obtentionDate', 'expirationDate', 'referencedDate', 'issueDate', 'shootingDate', 'date', 'datetime'];
|
|
32
|
+
exports.KNOWN_DATE_METADATA_NAMES = KNOWN_DATE_METADATA_NAMES;
|
|
33
|
+
var KNOWN_INFORMATION_METADATA_NAMES = ['number', 'bicNumber', 'country', 'refTaxIncome', 'contractType', 'netSocialAmount', 'employerName', 'noticePeriod'];
|
|
34
|
+
exports.KNOWN_INFORMATION_METADATA_NAMES = KNOWN_INFORMATION_METADATA_NAMES;
|
|
35
|
+
var KNOWN_OTHER_METADATA_NAMES = ['contact', 'page', 'qualification'];
|
|
25
36
|
/**
|
|
26
37
|
* @param {IOCozyFile} file - io.cozy.files document
|
|
27
38
|
* @returns {boolean}
|
|
28
39
|
* @description Tells if a given file is a national id card, is French, has an expiration date set and has a notice period set
|
|
29
40
|
*/
|
|
30
41
|
|
|
42
|
+
exports.KNOWN_OTHER_METADATA_NAMES = KNOWN_OTHER_METADATA_NAMES;
|
|
43
|
+
|
|
31
44
|
var isExpiringFrenchNationalIdCard = function isExpiringFrenchNationalIdCard(file) {
|
|
32
45
|
var _file$metadata, _file$metadata$qualif, _file$metadata2, _file$metadata3, _file$metadata4;
|
|
33
46
|
|
|
@@ -227,4 +240,260 @@ var isExpiringSoon = function isExpiringSoon(file) {
|
|
|
227
240
|
return isExpiringSoon;
|
|
228
241
|
};
|
|
229
242
|
|
|
230
|
-
exports.isExpiringSoon = isExpiringSoon;
|
|
243
|
+
exports.isExpiringSoon = isExpiringSoon;
|
|
244
|
+
|
|
245
|
+
var makeMetadataQualification = function makeMetadataQualification(_ref) {
|
|
246
|
+
var metadata = _ref.metadata,
|
|
247
|
+
knownMetadataName = _ref.knownMetadataName,
|
|
248
|
+
value = _ref.value;
|
|
249
|
+
var shouldReturnThisMetadata = Object.keys(metadata).includes(knownMetadataName);
|
|
250
|
+
|
|
251
|
+
if (shouldReturnThisMetadata || knownMetadataName === 'contact') {
|
|
252
|
+
return {
|
|
253
|
+
name: knownMetadataName,
|
|
254
|
+
value: value || null
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return null;
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* @param {Object} metadata - An io.cozy.files metadata object
|
|
262
|
+
* @returns {{ name: string, value: string | null }[]} Array of displayable metadata
|
|
263
|
+
* @description Select and format displayable metadata of a paper
|
|
264
|
+
*/
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
var formatMetadataQualification = function formatMetadataQualification(metadata) {
|
|
268
|
+
var dates = KNOWN_DATE_METADATA_NAMES.map(function (dateName) {
|
|
269
|
+
return makeMetadataQualification({
|
|
270
|
+
metadata: metadata,
|
|
271
|
+
knownMetadataName: dateName,
|
|
272
|
+
value: metadata[dateName]
|
|
273
|
+
});
|
|
274
|
+
}).filter(Boolean).filter(function (data, _, arr) {
|
|
275
|
+
if (arr.length > 1) return data.name !== 'datetime';
|
|
276
|
+
return data;
|
|
277
|
+
});
|
|
278
|
+
var informations = KNOWN_INFORMATION_METADATA_NAMES.map(function (numberName) {
|
|
279
|
+
return makeMetadataQualification({
|
|
280
|
+
metadata: metadata,
|
|
281
|
+
knownMetadataName: numberName,
|
|
282
|
+
value: metadata[numberName]
|
|
283
|
+
});
|
|
284
|
+
}).filter(Boolean);
|
|
285
|
+
var others = KNOWN_OTHER_METADATA_NAMES.map(function (otherName) {
|
|
286
|
+
var _metadata$otherName;
|
|
287
|
+
|
|
288
|
+
var value = otherName === 'qualification' ? (_metadata$otherName = metadata[otherName]) === null || _metadata$otherName === void 0 ? void 0 : _metadata$otherName.label : metadata[otherName];
|
|
289
|
+
return makeMetadataQualification({
|
|
290
|
+
metadata: metadata,
|
|
291
|
+
knownMetadataName: otherName,
|
|
292
|
+
value: value
|
|
293
|
+
});
|
|
294
|
+
}).filter(Boolean);
|
|
295
|
+
return [].concat((0, _toConsumableArray2.default)(dates), (0, _toConsumableArray2.default)(informations), (0, _toConsumableArray2.default)(others));
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* @typedef {('date' | 'information' | 'contact' | 'other')} MetadataQualificationType
|
|
299
|
+
*/
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* @param {string} metadataName - A metadata name
|
|
303
|
+
* @returns {MetadataQualificationType | null} The type of the metadata
|
|
304
|
+
* @description Returns the type of the metatada from a metadata name
|
|
305
|
+
*/
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
exports.formatMetadataQualification = formatMetadataQualification;
|
|
309
|
+
|
|
310
|
+
var getMetadataQualificationType = function getMetadataQualificationType(metadataName) {
|
|
311
|
+
if (KNOWN_DATE_METADATA_NAMES.includes(metadataName)) {
|
|
312
|
+
return 'date';
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (KNOWN_INFORMATION_METADATA_NAMES.includes(metadataName)) {
|
|
316
|
+
return 'information';
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (KNOWN_OTHER_METADATA_NAMES.includes(metadataName)) {
|
|
320
|
+
if (metadataName === 'contact') {
|
|
321
|
+
return 'contact';
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return 'other';
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return null;
|
|
328
|
+
};
|
|
329
|
+
/**
|
|
330
|
+
* @param {string} name - The name of a metadata of type date like 'expirationDate' or 'shootingDate'
|
|
331
|
+
* @param {Object} options - Options
|
|
332
|
+
* @param {string} options.lang - Lang requested for the translation like 'fr' or 'en'
|
|
333
|
+
* @returns {string} Translated name for the metadata
|
|
334
|
+
*/
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
exports.getMetadataQualificationType = getMetadataQualificationType;
|
|
338
|
+
|
|
339
|
+
var getTranslatedNameForDateMetadata = function getTranslatedNameForDateMetadata(name, _ref2) {
|
|
340
|
+
var lang = _ref2.lang;
|
|
341
|
+
var t = (0, _locales.getLocalizer)(lang);
|
|
342
|
+
return t("Scan.qualification.date.title.".concat(name));
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* @param {string} value - The value of a metadata of type date
|
|
346
|
+
* @param {Object} options - Options
|
|
347
|
+
* @param {string} options.lang - Lang requested for the translation
|
|
348
|
+
* @param {function} options.f - Date formatting function
|
|
349
|
+
* @returns {string} Formatted and translated value for the metadata
|
|
350
|
+
*/
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
exports.getTranslatedNameForDateMetadata = getTranslatedNameForDateMetadata;
|
|
354
|
+
|
|
355
|
+
var formatDateMetadataValue = function formatDateMetadataValue(value, _ref3) {
|
|
356
|
+
var lang = _ref3.lang,
|
|
357
|
+
f = _ref3.f;
|
|
358
|
+
var t = (0, _locales.getLocalizer)(lang);
|
|
359
|
+
|
|
360
|
+
if (value) {
|
|
361
|
+
if (lang === 'en') {
|
|
362
|
+
return f(value, 'MM/DD/YYYY');
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
return f(value, 'DD/MM/YYYY');
|
|
366
|
+
} else {
|
|
367
|
+
return t('Scan.qualification.noInfo');
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* @param {string} name - The name of a metadata of type information like 'national_id_card' or 'fine'
|
|
372
|
+
* @param {Object} options - Options
|
|
373
|
+
* @param {string} options.lang - Lang requested for the translation
|
|
374
|
+
* @param {string} options.qualificationLabel - The qualification label of the metadata
|
|
375
|
+
* @returns {string} Translated name for the metadata
|
|
376
|
+
*/
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
exports.formatDateMetadataValue = formatDateMetadataValue;
|
|
380
|
+
|
|
381
|
+
var getTranslatedNameForInformationMetadata = function getTranslatedNameForInformationMetadata(name, _ref4) {
|
|
382
|
+
var lang = _ref4.lang,
|
|
383
|
+
qualificationLabel = _ref4.qualificationLabel;
|
|
384
|
+
var t = (0, _locales.getLocalizer)(lang);
|
|
385
|
+
|
|
386
|
+
if (name === 'number') {
|
|
387
|
+
return t("Scan.qualification.information.title.".concat(qualificationLabel, ".").concat(name));
|
|
388
|
+
} else {
|
|
389
|
+
return t("Scan.qualification.information.title.".concat(name));
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
/**
|
|
393
|
+
* @param {string} value - The value of a metadata of type information
|
|
394
|
+
* @param {Object} options - Options
|
|
395
|
+
* @param {string} options.lang - Lang requested for the translation
|
|
396
|
+
* @param {string} options.name - The name of the metadata
|
|
397
|
+
* @param {string} options.qualificationLabel - The qualification label of the metadata
|
|
398
|
+
* @returns {string} Formatted and translated value for the metadata
|
|
399
|
+
*/
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
exports.getTranslatedNameForInformationMetadata = getTranslatedNameForInformationMetadata;
|
|
403
|
+
|
|
404
|
+
var formatInformationMetadataValue = function formatInformationMetadataValue(value, _ref5) {
|
|
405
|
+
var lang = _ref5.lang,
|
|
406
|
+
name = _ref5.name,
|
|
407
|
+
qualificationLabel = _ref5.qualificationLabel;
|
|
408
|
+
var t = (0, _locales.getLocalizer)(lang);
|
|
409
|
+
|
|
410
|
+
if (typeof value !== 'number' && !value) {
|
|
411
|
+
return t('Scan.qualification.noInfo');
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if (name === 'noticePeriod') {
|
|
415
|
+
return "".concat(value, " ").concat(t('Scan.qualification.information.day', {
|
|
416
|
+
smart_count: value
|
|
417
|
+
}));
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (name === 'contractType') {
|
|
421
|
+
return t("Scan.attributes.contractType.".concat(value), {
|
|
422
|
+
_: value
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (name === 'refTaxIncome' || name === 'netSocialAmount' || name === 'number' && qualificationLabel === 'pay_sheet') {
|
|
427
|
+
return "".concat(value, " \u20AC");
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
return value;
|
|
431
|
+
};
|
|
432
|
+
/**
|
|
433
|
+
* @param {string} name - The name of a metadata of type other like 'page' or 'qualification'
|
|
434
|
+
* @param {Object} options - Options
|
|
435
|
+
* @param {string} options.lang - Lang requested for the translation
|
|
436
|
+
* @returns {string} Translated name for the metadata
|
|
437
|
+
*/
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
exports.formatInformationMetadataValue = formatInformationMetadataValue;
|
|
441
|
+
|
|
442
|
+
var getTranslatedNameForOtherMetadata = function getTranslatedNameForOtherMetadata(name, _ref6) {
|
|
443
|
+
var lang = _ref6.lang;
|
|
444
|
+
var t = (0, _locales.getLocalizer)(lang);
|
|
445
|
+
return t("Scan.qualification.".concat(name));
|
|
446
|
+
};
|
|
447
|
+
/**
|
|
448
|
+
* @param {string} value - The value of a metadata of type other
|
|
449
|
+
* @param {Object} options - Options
|
|
450
|
+
* @param {string} options.lang - Lang requested for the translation
|
|
451
|
+
* @param {string} options.name - The name of the metadata
|
|
452
|
+
* @returns {string} Formatted and translated value for the metadata
|
|
453
|
+
*/
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
exports.getTranslatedNameForOtherMetadata = getTranslatedNameForOtherMetadata;
|
|
457
|
+
|
|
458
|
+
var formatOtherMetadataValue = function formatOtherMetadataValue(value, _ref7) {
|
|
459
|
+
var lang = _ref7.lang,
|
|
460
|
+
name = _ref7.name;
|
|
461
|
+
var t = (0, _locales.getLocalizer)(lang);
|
|
462
|
+
|
|
463
|
+
if (name === 'qualification') {
|
|
464
|
+
return t("Scan.items.".concat(value), {
|
|
465
|
+
smart_count: 1
|
|
466
|
+
});
|
|
467
|
+
} else {
|
|
468
|
+
return t("Scan.qualification.".concat(value));
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
/**
|
|
472
|
+
* @param {Object} options - Options
|
|
473
|
+
* @param {string} options.lang - Lang requested for the translation
|
|
474
|
+
* @returns {string} Translated name for contact
|
|
475
|
+
*/
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
exports.formatOtherMetadataValue = formatOtherMetadataValue;
|
|
479
|
+
|
|
480
|
+
var getTranslatedNameForContact = function getTranslatedNameForContact(_ref8) {
|
|
481
|
+
var lang = _ref8.lang;
|
|
482
|
+
var t = (0, _locales.getLocalizer)(lang);
|
|
483
|
+
return t('Scan.qualification.contact');
|
|
484
|
+
};
|
|
485
|
+
/**
|
|
486
|
+
* @param {object[]} contacts - An array of contact
|
|
487
|
+
* @returns {string} Formatted and translated value of an array of contact
|
|
488
|
+
*/
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
exports.getTranslatedNameForContact = getTranslatedNameForContact;
|
|
492
|
+
|
|
493
|
+
var formatContactValue = function formatContactValue(contacts) {
|
|
494
|
+
return contacts && contacts.length > 0 ? contacts.map(function (contact) {
|
|
495
|
+
return "".concat((0, _contact.getDisplayName)(contact));
|
|
496
|
+
}).join(', ') : '';
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
exports.formatContactValue = formatContactValue;
|
|
@@ -179,4 +179,73 @@ describe('Expiration', () => {
|
|
|
179
179
|
}
|
|
180
180
|
)
|
|
181
181
|
})
|
|
182
|
+
|
|
183
|
+
describe('formatMetadataQualification', () => {
|
|
184
|
+
it('should return correctly formatted metadata', () => {
|
|
185
|
+
const fakeMetadata = {
|
|
186
|
+
number: '111111',
|
|
187
|
+
AObtentionDate: '2029-12-01T23:00:00.000Z',
|
|
188
|
+
BObtentionDate: '2029-12-02T23:00:00.000Z',
|
|
189
|
+
CObtentionDate: '2029-12-03T23:00:00.000Z',
|
|
190
|
+
DObtentionDate: '2029-12-04T23:00:00.000Z',
|
|
191
|
+
expirationDate: '2029-12-05T23:00:00.000Z',
|
|
192
|
+
referencedDate: '2029-12-06T23:00:00.000Z',
|
|
193
|
+
issueDate: '2029-12-07T23:00:00.000Z',
|
|
194
|
+
shootingDate: '2029-12-08T23:00:00.000Z',
|
|
195
|
+
date: '2029-12-09T23:00:00.000Z',
|
|
196
|
+
datetime: '2029-12-10T23:00:00.000Z',
|
|
197
|
+
qualification: { label: 'fake_label' },
|
|
198
|
+
page: 'front',
|
|
199
|
+
contact: 'Alice Durand'
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const computedMetadata = [
|
|
203
|
+
{ name: 'AObtentionDate', value: '2029-12-01T23:00:00.000Z' },
|
|
204
|
+
{ name: 'BObtentionDate', value: '2029-12-02T23:00:00.000Z' },
|
|
205
|
+
{ name: 'CObtentionDate', value: '2029-12-03T23:00:00.000Z' },
|
|
206
|
+
{ name: 'DObtentionDate', value: '2029-12-04T23:00:00.000Z' },
|
|
207
|
+
{ name: 'expirationDate', value: '2029-12-05T23:00:00.000Z' },
|
|
208
|
+
{ name: 'referencedDate', value: '2029-12-06T23:00:00.000Z' },
|
|
209
|
+
{ name: 'issueDate', value: '2029-12-07T23:00:00.000Z' },
|
|
210
|
+
{ name: 'shootingDate', value: '2029-12-08T23:00:00.000Z' },
|
|
211
|
+
{ name: 'date', value: '2029-12-09T23:00:00.000Z' },
|
|
212
|
+
{ name: 'number', value: '111111' },
|
|
213
|
+
{ name: 'contact', value: 'Alice Durand' },
|
|
214
|
+
{ name: 'page', value: 'front' },
|
|
215
|
+
{ name: 'qualification', value: 'fake_label' }
|
|
216
|
+
]
|
|
217
|
+
|
|
218
|
+
const res = paperModel.formatMetadataQualification(fakeMetadata)
|
|
219
|
+
expect(res).toEqual(computedMetadata)
|
|
220
|
+
})
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
describe('formatInformationMetadataValue', () => {
|
|
224
|
+
it('should return value with suffix locale', () => {
|
|
225
|
+
const res = paperModel.formatInformationMetadataValue('88', {
|
|
226
|
+
name: 'noticePeriod',
|
|
227
|
+
lang: 'en'
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
expect(res).toEqual('88 days')
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
it('should return "noInfo" value', () => {
|
|
234
|
+
const res = paperModel.formatInformationMetadataValue('', {
|
|
235
|
+
name: 'metadataName',
|
|
236
|
+
lang: 'en'
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
expect(res).toEqual('No information')
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
it('should return value if not in other case', () => {
|
|
243
|
+
const res = paperModel.formatInformationMetadataValue('metadataValue', {
|
|
244
|
+
name: 'metadataName',
|
|
245
|
+
lang: 'en'
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
expect(res).toEqual('metadataValue')
|
|
249
|
+
})
|
|
250
|
+
})
|
|
182
251
|
})
|
package/dist/queries/dsl.js
CHANGED
|
@@ -156,6 +156,15 @@ var QueryDefinition = /*#__PURE__*/function () {
|
|
|
156
156
|
if (hasNe) {
|
|
157
157
|
_logger.default.info("The use of the $ne operator is more efficient with a partial index.\n\n Selector: ".concat(JSON.stringify(selector)));
|
|
158
158
|
}
|
|
159
|
+
|
|
160
|
+
var nestedArrayKey = (0, _findKey.default)(selector, function (value) {
|
|
161
|
+
return Array.isArray(value);
|
|
162
|
+
});
|
|
163
|
+
var hasNestedArrayWithoutOperator = nestedArrayKey && !nestedArrayKey.startsWith('$');
|
|
164
|
+
|
|
165
|
+
if (hasNestedArrayWithoutOperator) {
|
|
166
|
+
throw new Error("You pass ".concat(JSON.stringify(selector), ", this is a valid mango operation, \n\n but sift doesn't support it so CozyClient can not evaluate \n\n the request in memory. You must use a MongoDB operator \n\n like $in or $or operator instead, preferably in a partial index, \n\n to avoid costly full-scan"));
|
|
167
|
+
}
|
|
159
168
|
}
|
|
160
169
|
/**
|
|
161
170
|
* Check if the selected fields are all included in the selectors
|
package/dist/queries/dsl.spec.js
CHANGED
|
@@ -108,7 +108,18 @@ describe('QueryDefinition', () => {
|
|
|
108
108
|
Q('io.cozy.files').where({ _id: { $ne: 'io.cozy.root-id' } })
|
|
109
109
|
expect(logger.info).toHaveBeenCalledTimes(1)
|
|
110
110
|
})
|
|
111
|
-
|
|
111
|
+
it('should throw when using a selector with an array without an $operator', () => {
|
|
112
|
+
const query = () =>
|
|
113
|
+
Q('io.cozy.files').where({ worker: ['worker1', 'worker2'] })
|
|
114
|
+
expect(() => query()).toThrow()
|
|
115
|
+
})
|
|
116
|
+
it('should not throw an error when we make a selector on multiple value with a mango operator', () => {
|
|
117
|
+
const query = () =>
|
|
118
|
+
Q('io.cozy.files').where({
|
|
119
|
+
worker: { $in: ['konnector', 'client'] }
|
|
120
|
+
})
|
|
121
|
+
expect(() => query()).not.toThrow()
|
|
122
|
+
})
|
|
112
123
|
it('should throw an error when there is a select without all the fields in selector', () => {
|
|
113
124
|
const query = () =>
|
|
114
125
|
Q('io.cozy.files')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "46.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": "^
|
|
21
|
+
"cozy-stack-client": "^46.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": "
|
|
78
|
+
"gitHead": "c7691dddf7e5e737c5273344b0fb863ae7948194"
|
|
79
79
|
}
|
package/types/models/paper.d.ts
CHANGED
|
@@ -1,7 +1,43 @@
|
|
|
1
|
+
export const KNOWN_DATE_METADATA_NAMES: string[];
|
|
2
|
+
export const KNOWN_INFORMATION_METADATA_NAMES: string[];
|
|
3
|
+
export const KNOWN_OTHER_METADATA_NAMES: string[];
|
|
1
4
|
export function isExpiring(file: IOCozyFile): boolean;
|
|
2
5
|
export function computeExpirationDate(file: IOCozyFile): Date | null;
|
|
3
6
|
export function computeExpirationNoticeDate(file: IOCozyFile): Date | null;
|
|
4
7
|
export function computeExpirationNoticeLink(file: IOCozyFile): string | null;
|
|
5
8
|
export function isExpired(file: IOCozyFile): boolean;
|
|
6
9
|
export function isExpiringSoon(file: IOCozyFile): boolean;
|
|
10
|
+
export function formatMetadataQualification(metadata: any): {
|
|
11
|
+
name: string;
|
|
12
|
+
value: string | null;
|
|
13
|
+
}[];
|
|
14
|
+
export function getMetadataQualificationType(metadataName: string): MetadataQualificationType | null;
|
|
15
|
+
export function getTranslatedNameForDateMetadata(name: string, { lang }: {
|
|
16
|
+
lang: string;
|
|
17
|
+
}): string;
|
|
18
|
+
export function formatDateMetadataValue(value: string, { lang, f }: {
|
|
19
|
+
lang: string;
|
|
20
|
+
f: Function;
|
|
21
|
+
}): string;
|
|
22
|
+
export function getTranslatedNameForInformationMetadata(name: string, { lang, qualificationLabel }: {
|
|
23
|
+
lang: string;
|
|
24
|
+
qualificationLabel: string;
|
|
25
|
+
}): string;
|
|
26
|
+
export function formatInformationMetadataValue(value: string, { lang, name, qualificationLabel }: {
|
|
27
|
+
lang: string;
|
|
28
|
+
name: string;
|
|
29
|
+
qualificationLabel: string;
|
|
30
|
+
}): string;
|
|
31
|
+
export function getTranslatedNameForOtherMetadata(name: string, { lang }: {
|
|
32
|
+
lang: string;
|
|
33
|
+
}): string;
|
|
34
|
+
export function formatOtherMetadataValue(value: string, { lang, name }: {
|
|
35
|
+
lang: string;
|
|
36
|
+
name: string;
|
|
37
|
+
}): string;
|
|
38
|
+
export function getTranslatedNameForContact({ lang }: {
|
|
39
|
+
lang: string;
|
|
40
|
+
}): string;
|
|
41
|
+
export function formatContactValue(contacts: object[]): string;
|
|
7
42
|
export type IOCozyFile = import("../types").CozyClientDocument & import("../types").FileDocument;
|
|
43
|
+
export type MetadataQualificationType = "other" | "date" | "contact" | "information";
|