cozy-client 34.4.0 → 34.6.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/paper.js +28 -28
- package/dist/models/paper.spec.js +131 -28
- package/package.json +2 -2
package/dist/CozyClient.js
CHANGED
|
@@ -2644,7 +2644,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2644
2644
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
2645
2645
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
2646
2646
|
|
|
2647
|
-
CozyClient.version = "34.
|
|
2647
|
+
CozyClient.version = "34.6.0";
|
|
2648
2648
|
|
|
2649
2649
|
_microee.default.mixin(CozyClient);
|
|
2650
2650
|
|
package/dist/models/paper.js
CHANGED
|
@@ -16,6 +16,11 @@ var _sub = _interopRequireDefault(require("date-fns/sub"));
|
|
|
16
16
|
*/
|
|
17
17
|
var PERSONAL_SPORTING_LICENCE_PERIOD_DAYS = 365;
|
|
18
18
|
var PERSONAL_SPORTING_LICENCE_NOTICE_PERIOD_DAYS = 15;
|
|
19
|
+
var EXPIRATION_LINK_BY_LABEL = {
|
|
20
|
+
national_id_card: 'https://www.service-public.fr/particuliers/vosdroits/N358',
|
|
21
|
+
residence_permit: 'https://www.service-public.fr/particuliers/vosdroits/N110',
|
|
22
|
+
passport: 'https://www.service-public.fr/particuliers/vosdroits/N360'
|
|
23
|
+
};
|
|
19
24
|
/**
|
|
20
25
|
* @param {IOCozyFile} file - io.cozy.files document
|
|
21
26
|
* @returns {boolean}
|
|
@@ -39,18 +44,17 @@ var isExpiringFrenchNationalIdCard = function isExpiringFrenchNationalIdCard(fil
|
|
|
39
44
|
/**
|
|
40
45
|
* @param {IOCozyFile} file - io.cozy.files document
|
|
41
46
|
* @returns {boolean}
|
|
42
|
-
* @description Tells if a given file
|
|
47
|
+
* @description Tells if a given file has an expiration date set and a notice period set
|
|
43
48
|
*/
|
|
44
49
|
|
|
45
50
|
|
|
46
|
-
var
|
|
47
|
-
var _file$metadata5, _file$
|
|
51
|
+
var isExpiringGeneric = function isExpiringGeneric(file) {
|
|
52
|
+
var _file$metadata5, _file$metadata6;
|
|
48
53
|
|
|
49
|
-
var
|
|
50
|
-
var
|
|
51
|
-
var noticePeriod = (_file$metadata7 = file.metadata) === null || _file$metadata7 === void 0 ? void 0 : _file$metadata7.noticePeriod;
|
|
54
|
+
var expirationDate = (_file$metadata5 = file.metadata) === null || _file$metadata5 === void 0 ? void 0 : _file$metadata5.expirationDate;
|
|
55
|
+
var noticePeriod = (_file$metadata6 = file.metadata) === null || _file$metadata6 === void 0 ? void 0 : _file$metadata6.noticePeriod;
|
|
52
56
|
|
|
53
|
-
if (
|
|
57
|
+
if (expirationDate && noticePeriod) {
|
|
54
58
|
return true;
|
|
55
59
|
}
|
|
56
60
|
|
|
@@ -64,10 +68,10 @@ var isExpiringResidencePermit = function isExpiringResidencePermit(file) {
|
|
|
64
68
|
|
|
65
69
|
|
|
66
70
|
var isExpiringPersonalSportingLicense = function isExpiringPersonalSportingLicense(file) {
|
|
67
|
-
var _file$
|
|
71
|
+
var _file$metadata7, _file$metadata7$quali, _file$metadata8;
|
|
68
72
|
|
|
69
|
-
var label = (_file$
|
|
70
|
-
var referencedDate = (_file$
|
|
73
|
+
var label = (_file$metadata7 = file.metadata) === null || _file$metadata7 === void 0 ? void 0 : (_file$metadata7$quali = _file$metadata7.qualification) === null || _file$metadata7$quali === void 0 ? void 0 : _file$metadata7$quali.label;
|
|
74
|
+
var referencedDate = (_file$metadata8 = file.metadata) === null || _file$metadata8 === void 0 ? void 0 : _file$metadata8.referencedDate;
|
|
71
75
|
var created_at = file.created_at;
|
|
72
76
|
|
|
73
77
|
if (label === 'personal_sporting_licence' && (referencedDate || created_at)) {
|
|
@@ -88,7 +92,7 @@ var isExpiring = function isExpiring(file) {
|
|
|
88
92
|
return true;
|
|
89
93
|
}
|
|
90
94
|
|
|
91
|
-
if (
|
|
95
|
+
if (isExpiringGeneric(file)) {
|
|
92
96
|
return true;
|
|
93
97
|
}
|
|
94
98
|
|
|
@@ -108,17 +112,17 @@ var isExpiring = function isExpiring(file) {
|
|
|
108
112
|
exports.isExpiring = isExpiring;
|
|
109
113
|
|
|
110
114
|
var computeExpirationDate = function computeExpirationDate(file) {
|
|
111
|
-
if (isExpiringFrenchNationalIdCard(file) ||
|
|
112
|
-
var _file$
|
|
115
|
+
if (isExpiringFrenchNationalIdCard(file) || isExpiringGeneric(file)) {
|
|
116
|
+
var _file$metadata9;
|
|
113
117
|
|
|
114
|
-
var expirationDate = (_file$
|
|
118
|
+
var expirationDate = (_file$metadata9 = file.metadata) === null || _file$metadata9 === void 0 ? void 0 : _file$metadata9.expirationDate;
|
|
115
119
|
return new Date(expirationDate);
|
|
116
120
|
}
|
|
117
121
|
|
|
118
122
|
if (isExpiringPersonalSportingLicense(file)) {
|
|
119
|
-
var _file$
|
|
123
|
+
var _file$metadata10;
|
|
120
124
|
|
|
121
|
-
var referencedDate = (_file$
|
|
125
|
+
var referencedDate = (_file$metadata10 = file.metadata) === null || _file$metadata10 === void 0 ? void 0 : _file$metadata10.referencedDate;
|
|
122
126
|
var created_at = file.created_at;
|
|
123
127
|
return (0, _add.default)(new Date(referencedDate !== null && referencedDate !== void 0 ? referencedDate : created_at), {
|
|
124
128
|
days: PERSONAL_SPORTING_LICENCE_PERIOD_DAYS
|
|
@@ -137,10 +141,10 @@ var computeExpirationDate = function computeExpirationDate(file) {
|
|
|
137
141
|
exports.computeExpirationDate = computeExpirationDate;
|
|
138
142
|
|
|
139
143
|
var computeExpirationNoticePeriodInDays = function computeExpirationNoticePeriodInDays(file) {
|
|
140
|
-
if (isExpiringFrenchNationalIdCard(file) ||
|
|
141
|
-
var _file$
|
|
144
|
+
if (isExpiringFrenchNationalIdCard(file) || isExpiringGeneric(file)) {
|
|
145
|
+
var _file$metadata11;
|
|
142
146
|
|
|
143
|
-
var noticePeriodInDays = (_file$
|
|
147
|
+
var noticePeriodInDays = (_file$metadata11 = file.metadata) === null || _file$metadata11 === void 0 ? void 0 : _file$metadata11.noticePeriod;
|
|
144
148
|
return parseInt(noticePeriodInDays, 10);
|
|
145
149
|
}
|
|
146
150
|
|
|
@@ -177,22 +181,18 @@ var computeExpirationNoticeDate = function computeExpirationNoticeDate(file) {
|
|
|
177
181
|
/**
|
|
178
182
|
* @param {IOCozyFile} file - io.cozy.files document
|
|
179
183
|
* @returns {string | null} Expiration notice link
|
|
180
|
-
* @description Computes
|
|
184
|
+
* @description Computes and returns the expiration notice link of the given file, or null if it has none
|
|
181
185
|
*/
|
|
182
186
|
|
|
183
187
|
|
|
184
188
|
exports.computeExpirationNoticeDate = computeExpirationNoticeDate;
|
|
185
189
|
|
|
186
190
|
var computeExpirationNoticeLink = function computeExpirationNoticeLink(file) {
|
|
187
|
-
|
|
188
|
-
return 'https://www.service-public.fr/particuliers/vosdroits/N358';
|
|
189
|
-
}
|
|
191
|
+
var _file$metadata12, _file$metadata12$qual;
|
|
190
192
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return null;
|
|
193
|
+
var qualificationLabel = (_file$metadata12 = file.metadata) === null || _file$metadata12 === void 0 ? void 0 : (_file$metadata12$qual = _file$metadata12.qualification) === null || _file$metadata12$qual === void 0 ? void 0 : _file$metadata12$qual.label;
|
|
194
|
+
if (!qualificationLabel) return null;
|
|
195
|
+
return EXPIRATION_LINK_BY_LABEL[qualificationLabel] || null;
|
|
196
196
|
};
|
|
197
197
|
/**
|
|
198
198
|
* @param {IOCozyFile} file - io.cozy.files document
|
|
@@ -2,6 +2,32 @@ import MockDate from 'mockdate'
|
|
|
2
2
|
|
|
3
3
|
import * as paperModel from './paper'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {object} param - options
|
|
8
|
+
* @param {string} param.qualificationLabel - qualification label
|
|
9
|
+
* @param {string} [param.expirationDate] - expiration date of file
|
|
10
|
+
* @param {string} [param.referencedDate] - reference date of file
|
|
11
|
+
* @param {string} [param.noticePeriod] - period before send notification
|
|
12
|
+
*/
|
|
13
|
+
const buildMockFile = ({
|
|
14
|
+
qualificationLabel,
|
|
15
|
+
expirationDate,
|
|
16
|
+
referencedDate,
|
|
17
|
+
noticePeriod
|
|
18
|
+
}) => {
|
|
19
|
+
return /** @type {import('../types').IOCozyFile} */ ({
|
|
20
|
+
name: qualificationLabel,
|
|
21
|
+
created_at: '2022-09-01T00:00:00.000Z',
|
|
22
|
+
metadata: {
|
|
23
|
+
qualification: { label: qualificationLabel },
|
|
24
|
+
...(expirationDate && { expirationDate }),
|
|
25
|
+
...(referencedDate && { referencedDate }),
|
|
26
|
+
...(noticePeriod && { noticePeriod })
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
5
31
|
describe('Expiration', () => {
|
|
6
32
|
beforeEach(() => {
|
|
7
33
|
MockDate.set('2022-11-01T11:35:58.118Z')
|
|
@@ -10,44 +36,46 @@ describe('Expiration', () => {
|
|
|
10
36
|
MockDate.reset()
|
|
11
37
|
})
|
|
12
38
|
|
|
13
|
-
const
|
|
14
|
-
_id: '
|
|
15
|
-
name: 'national id card',
|
|
16
|
-
created_at: '2022-09-01T00:00:00.000Z',
|
|
17
|
-
metadata: {
|
|
18
|
-
qualification: { label: 'national_id_card' },
|
|
19
|
-
expirationDate: '2022-09-23T11:35:58.118Z',
|
|
20
|
-
noticePeriod: '90'
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
const fakeFile02 = {
|
|
24
|
-
_id: '02',
|
|
25
|
-
name: 'personal sporting licence',
|
|
26
|
-
created_at: '2022-09-01T00:00:00.000Z',
|
|
27
|
-
metadata: {
|
|
28
|
-
qualification: { label: 'personal_sporting_licence' },
|
|
29
|
-
referencedDate: '2022-09-23T11:35:58.118Z'
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const fakeFile03 = {
|
|
33
|
-
_id: '03',
|
|
39
|
+
const fakeFileWithoutMetadata = /** @type {import('../types').IOCozyFile} */ ({
|
|
40
|
+
_id: '00',
|
|
34
41
|
name: 'unknown'
|
|
35
|
-
}
|
|
42
|
+
})
|
|
43
|
+
const fakeNationalIdCardFile = buildMockFile({
|
|
44
|
+
qualificationLabel: 'national_id_card',
|
|
45
|
+
expirationDate: '2022-09-23T11:35:58.118Z',
|
|
46
|
+
noticePeriod: '90'
|
|
47
|
+
})
|
|
48
|
+
const fakePassportFile = buildMockFile({
|
|
49
|
+
qualificationLabel: 'passport',
|
|
50
|
+
expirationDate: '2022-09-23T11:35:58.118Z',
|
|
51
|
+
noticePeriod: '90'
|
|
52
|
+
})
|
|
53
|
+
const fakePersonalSportingLicenceFile = buildMockFile({
|
|
54
|
+
qualificationLabel: 'personal_sporting_licence',
|
|
55
|
+
referencedDate: '2022-09-23T11:35:58.118Z'
|
|
56
|
+
})
|
|
57
|
+
const fakeResidencePermitFile = buildMockFile({
|
|
58
|
+
qualificationLabel: 'residence_permit',
|
|
59
|
+
expirationDate: '2022-09-23T11:35:58.118Z',
|
|
60
|
+
noticePeriod: '90'
|
|
61
|
+
})
|
|
36
62
|
|
|
37
63
|
describe('computeExpirationDate', () => {
|
|
38
64
|
it('should return expirationDate', () => {
|
|
39
|
-
const res = paperModel.computeExpirationDate(
|
|
65
|
+
const res = paperModel.computeExpirationDate(fakeNationalIdCardFile)
|
|
40
66
|
|
|
41
67
|
expect(res.toISOString()).toBe('2022-09-23T11:35:58.118Z')
|
|
42
68
|
})
|
|
43
69
|
it('should return referencedDate plus 365 days', () => {
|
|
44
|
-
const res = paperModel.computeExpirationDate(
|
|
70
|
+
const res = paperModel.computeExpirationDate(
|
|
71
|
+
fakePersonalSportingLicenceFile
|
|
72
|
+
)
|
|
45
73
|
|
|
46
74
|
expect(res.toISOString()).toBe('2023-09-23T11:35:58.118Z')
|
|
47
75
|
})
|
|
48
76
|
|
|
49
77
|
it('should return "null" if metadata is not found', () => {
|
|
50
|
-
const res = paperModel.computeExpirationDate(
|
|
78
|
+
const res = paperModel.computeExpirationDate(fakeFileWithoutMetadata)
|
|
51
79
|
|
|
52
80
|
expect(res).toBeNull()
|
|
53
81
|
})
|
|
@@ -55,19 +83,94 @@ describe('Expiration', () => {
|
|
|
55
83
|
|
|
56
84
|
describe('computeExpirationNoticeDate', () => {
|
|
57
85
|
it('should return notice date for file with expirationDate metadata', () => {
|
|
58
|
-
const res = paperModel.computeExpirationNoticeDate(
|
|
86
|
+
const res = paperModel.computeExpirationNoticeDate(fakeNationalIdCardFile)
|
|
59
87
|
|
|
60
88
|
expect(res.toISOString()).toBe('2022-06-25T11:35:58.118Z')
|
|
61
89
|
})
|
|
62
90
|
it('should return notice date for file with referencedDate metadata', () => {
|
|
63
|
-
const res = paperModel.computeExpirationNoticeDate(
|
|
91
|
+
const res = paperModel.computeExpirationNoticeDate(
|
|
92
|
+
fakePersonalSportingLicenceFile
|
|
93
|
+
)
|
|
64
94
|
|
|
65
95
|
expect(res.toISOString()).toBe('2023-09-08T11:35:58.118Z')
|
|
66
96
|
})
|
|
67
97
|
it('should return null for file without corresponding metadata', () => {
|
|
68
|
-
const res = paperModel.computeExpirationNoticeDate(
|
|
98
|
+
const res = paperModel.computeExpirationNoticeDate(
|
|
99
|
+
fakeFileWithoutMetadata
|
|
100
|
+
)
|
|
69
101
|
|
|
70
102
|
expect(res).toBeNull()
|
|
71
103
|
})
|
|
72
104
|
})
|
|
105
|
+
|
|
106
|
+
describe('computeExpirationNoticeLink', () => {
|
|
107
|
+
it.each`
|
|
108
|
+
file | link
|
|
109
|
+
${fakeNationalIdCardFile} | ${'https://www.service-public.fr/particuliers/vosdroits/N358'}
|
|
110
|
+
${fakeResidencePermitFile} | ${'https://www.service-public.fr/particuliers/vosdroits/N110'}
|
|
111
|
+
${fakePassportFile} | ${'https://www.service-public.fr/particuliers/vosdroits/N360'}
|
|
112
|
+
`(
|
|
113
|
+
`should return "$link" link for an file with "$file.metadata.qualification.label" qualification label`,
|
|
114
|
+
({ file, link }) => {
|
|
115
|
+
expect(paperModel.computeExpirationNoticeLink(file)).toEqual(link)
|
|
116
|
+
}
|
|
117
|
+
)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
describe('isExpiring', () => {
|
|
121
|
+
const fakeNationalIdCardFileWithoutNoticeDate = buildMockFile({
|
|
122
|
+
qualificationLabel: 'national_id_card',
|
|
123
|
+
expirationDate: '2022-09-23T11:35:58.118Z',
|
|
124
|
+
noticePeriod: ''
|
|
125
|
+
})
|
|
126
|
+
const fakeResidencePermitFileWithoutNoticeDate = buildMockFile({
|
|
127
|
+
qualificationLabel: 'residence_permit',
|
|
128
|
+
expirationDate: '2022-09-23T11:35:58.118Z',
|
|
129
|
+
noticePeriod: ''
|
|
130
|
+
})
|
|
131
|
+
const fakeNationalIdCardFileWithoutExpirationDate = buildMockFile({
|
|
132
|
+
qualificationLabel: 'national_id_card',
|
|
133
|
+
expirationDate: '',
|
|
134
|
+
noticePeriod: '90'
|
|
135
|
+
})
|
|
136
|
+
const fakeResidencePermitFileWithoutExpirationDate = buildMockFile({
|
|
137
|
+
qualificationLabel: 'residence_permit',
|
|
138
|
+
expirationDate: '',
|
|
139
|
+
noticePeriod: '90'
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it.each`
|
|
143
|
+
file | result
|
|
144
|
+
${fakeNationalIdCardFile} | ${true}
|
|
145
|
+
${fakePersonalSportingLicenceFile} | ${true}
|
|
146
|
+
${fakeResidencePermitFile} | ${true}
|
|
147
|
+
`(
|
|
148
|
+
`should return "$result" for each file with "noticePeriod" & "expirationDate" metadata`,
|
|
149
|
+
({ file, result }) => {
|
|
150
|
+
expect(paperModel.isExpiring(file)).toEqual(result)
|
|
151
|
+
}
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
it.each`
|
|
155
|
+
file | result
|
|
156
|
+
${fakeNationalIdCardFileWithoutNoticeDate} | ${false}
|
|
157
|
+
${fakeResidencePermitFileWithoutNoticeDate} | ${false}
|
|
158
|
+
`(
|
|
159
|
+
`should return "$result" for each file without "noticePeriod" metadata`,
|
|
160
|
+
({ file, result }) => {
|
|
161
|
+
expect(paperModel.isExpiring(file)).toEqual(result)
|
|
162
|
+
}
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
it.each`
|
|
166
|
+
file | result
|
|
167
|
+
${fakeNationalIdCardFileWithoutExpirationDate} | ${false}
|
|
168
|
+
${fakeResidencePermitFileWithoutExpirationDate} | ${false}
|
|
169
|
+
`(
|
|
170
|
+
`should return "$result" for each file without "expirationDate" metadata`,
|
|
171
|
+
({ file, result }) => {
|
|
172
|
+
expect(paperModel.isExpiring(file)).toEqual(result)
|
|
173
|
+
}
|
|
174
|
+
)
|
|
175
|
+
})
|
|
73
176
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "34.
|
|
3
|
+
"version": "34.6.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
|
|
74
74
|
},
|
|
75
75
|
"sideEffects": false,
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "ef938fae49072daffdb9e2b7228306212483b54c"
|
|
77
77
|
}
|