cozy-client 46.7.1 → 46.9.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 +90 -13
- package/dist/__tests__/mocks.js +2 -1
- package/dist/helpers/index.js +33 -1
- package/dist/helpers/settings.js +311 -0
- package/dist/helpers/settings.spec.js +493 -0
- package/dist/hooks/index.js +9 -1
- package/dist/hooks/useSetting.js +64 -0
- package/dist/models/document/locales/fr.json +1 -1
- package/dist/types.js +44 -4
- package/package.json +2 -2
- package/types/CozyClient.d.ts +29 -0
- package/types/__tests__/mocks.d.ts +1 -0
- package/types/helpers/index.d.ts +1 -0
- package/types/helpers/settings.d.ts +7 -0
- package/types/hooks/index.d.ts +1 -0
- package/types/hooks/useSetting.d.ts +1 -0
- package/types/types.d.ts +40 -8
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
import {
|
|
2
|
+
editSettings,
|
|
3
|
+
getSettings,
|
|
4
|
+
normalizeSettings,
|
|
5
|
+
saveAfterFetchSettings
|
|
6
|
+
} from './settings'
|
|
7
|
+
import { Q } from '../queries/dsl'
|
|
8
|
+
|
|
9
|
+
import * as mocks from '../__tests__/mocks'
|
|
10
|
+
|
|
11
|
+
describe('settings', () => {
|
|
12
|
+
describe('getSettings', () => {
|
|
13
|
+
it('should get settings for cozy-home', async () => {
|
|
14
|
+
const client = mocks.client()
|
|
15
|
+
|
|
16
|
+
client.fetchQueryAndGetFromState.mockResolvedValue({
|
|
17
|
+
data: [
|
|
18
|
+
{
|
|
19
|
+
some_key: 'some_value'
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
const result = await getSettings(client, 'home', ['some_key'])
|
|
26
|
+
|
|
27
|
+
const query = {
|
|
28
|
+
definition: Q('io.cozy.home.settings').limitBy(1),
|
|
29
|
+
options: {
|
|
30
|
+
as: 'io.cozy.home.settings',
|
|
31
|
+
fetchPolicy: expect.anything(),
|
|
32
|
+
singleDocData: true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
expect(client.fetchQueryAndGetFromState).toHaveBeenCalledWith({
|
|
36
|
+
definition: query.definition,
|
|
37
|
+
options: query.options
|
|
38
|
+
})
|
|
39
|
+
expect(result.some_key).toEqual('some_value')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should get settings for mespapiers', async () => {
|
|
43
|
+
const client = mocks.client()
|
|
44
|
+
|
|
45
|
+
client.fetchQueryAndGetFromState.mockResolvedValue({
|
|
46
|
+
data: [
|
|
47
|
+
{
|
|
48
|
+
some_mespapiers_key: 'some_mespapiers_value'
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const result = await getSettings(
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
client,
|
|
56
|
+
'mespapiers',
|
|
57
|
+
['some_mespapiers_key']
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
const query = {
|
|
61
|
+
definition: Q('io.cozy.mespapiers.settings').limitBy(1),
|
|
62
|
+
options: {
|
|
63
|
+
as: 'io.cozy.mespapiers.settings',
|
|
64
|
+
fetchPolicy: expect.anything(),
|
|
65
|
+
singleDocData: true
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
expect(client.fetchQueryAndGetFromState).toHaveBeenCalledWith({
|
|
69
|
+
definition: query.definition,
|
|
70
|
+
options: query.options
|
|
71
|
+
})
|
|
72
|
+
expect(result.some_mespapiers_key).toEqual('some_mespapiers_value')
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('should get settings for instance', async () => {
|
|
76
|
+
const client = mocks.client()
|
|
77
|
+
|
|
78
|
+
client.fetchQueryAndGetFromState.mockResolvedValue({
|
|
79
|
+
data: [
|
|
80
|
+
{
|
|
81
|
+
some_global_key: 'some_global_value'
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
const result = await getSettings(client, 'instance', ['some_global_key'])
|
|
88
|
+
|
|
89
|
+
const query = {
|
|
90
|
+
definition: Q('io.cozy.settings').getById('io.cozy.settings.instance'),
|
|
91
|
+
options: {
|
|
92
|
+
as: 'io.cozy.settings/io.cozy.settings.instance',
|
|
93
|
+
fetchPolicy: expect.anything(),
|
|
94
|
+
singleDocData: true
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
expect(client.fetchQueryAndGetFromState).toHaveBeenCalledWith({
|
|
98
|
+
definition: query.definition,
|
|
99
|
+
options: query.options
|
|
100
|
+
})
|
|
101
|
+
expect(result.some_global_key).toEqual('some_global_value')
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('should get settings for passwords', async () => {
|
|
105
|
+
const client = mocks.client()
|
|
106
|
+
|
|
107
|
+
client.fetchQueryAndGetFromState.mockResolvedValue({
|
|
108
|
+
data: [
|
|
109
|
+
{
|
|
110
|
+
some_pass_key: 'some_pass_value'
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
const result = await getSettings(client, 'passwords', ['some_pass_key'])
|
|
117
|
+
|
|
118
|
+
const query = {
|
|
119
|
+
definition: Q('io.cozy.settings').getById('io.cozy.settings.bitwarden'),
|
|
120
|
+
options: {
|
|
121
|
+
as: 'io.cozy.settings/io.cozy.settings.bitwarden',
|
|
122
|
+
fetchPolicy: expect.anything(),
|
|
123
|
+
singleDocData: true
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
expect(client.fetchQueryAndGetFromState).toHaveBeenCalledWith({
|
|
127
|
+
definition: query.definition,
|
|
128
|
+
options: query.options
|
|
129
|
+
})
|
|
130
|
+
expect(result.some_pass_key).toEqual('some_pass_value')
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('should return undefined if no setting is found in database', async () => {
|
|
134
|
+
const client = mocks.client()
|
|
135
|
+
|
|
136
|
+
client.fetchQueryAndGetFromState.mockResolvedValue({
|
|
137
|
+
data: [
|
|
138
|
+
{
|
|
139
|
+
some_other_key: 'some_other_value'
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
// @ts-ignore
|
|
145
|
+
const result = await getSettings(client, 'home', ['some_key'])
|
|
146
|
+
|
|
147
|
+
expect(result.some_key).toBeUndefined()
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('should get settings for multiple keys', async () => {
|
|
151
|
+
const client = mocks.client()
|
|
152
|
+
|
|
153
|
+
client.fetchQueryAndGetFromState.mockResolvedValue({
|
|
154
|
+
data: [
|
|
155
|
+
{
|
|
156
|
+
some_key_1: 'some_value_1',
|
|
157
|
+
some_key_2: 'some_value_2',
|
|
158
|
+
some_key_3: 'some_value_3'
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
// @ts-ignore
|
|
164
|
+
const result = await getSettings(client, 'home', [
|
|
165
|
+
'some_key_1',
|
|
166
|
+
'some_key_2'
|
|
167
|
+
])
|
|
168
|
+
|
|
169
|
+
const query = {
|
|
170
|
+
definition: Q('io.cozy.home.settings').limitBy(1),
|
|
171
|
+
options: {
|
|
172
|
+
as: 'io.cozy.home.settings',
|
|
173
|
+
fetchPolicy: expect.anything(),
|
|
174
|
+
singleDocData: true
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
expect(client.fetchQueryAndGetFromState).toHaveBeenCalledWith({
|
|
178
|
+
definition: query.definition,
|
|
179
|
+
options: query.options
|
|
180
|
+
})
|
|
181
|
+
expect(result.some_key_1).toEqual('some_value_1')
|
|
182
|
+
expect(result.some_key_2).toEqual('some_value_2')
|
|
183
|
+
// @ts-ignore
|
|
184
|
+
expect(result.some_key_3).toBeUndefined()
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
describe('saveAfterFetchSettings', () => {
|
|
189
|
+
it('should set settings for instance', async () => {
|
|
190
|
+
const client = mocks.client()
|
|
191
|
+
|
|
192
|
+
client.fetchQueryAndGetFromState.mockResolvedValue({
|
|
193
|
+
data: [
|
|
194
|
+
{
|
|
195
|
+
id: 'io.cozy.settings.instance',
|
|
196
|
+
_id: 'io.cozy.settings.instance',
|
|
197
|
+
_type: 'io.cozy.settings',
|
|
198
|
+
type: 'io.cozy.settings',
|
|
199
|
+
attributes: {
|
|
200
|
+
some_setting: 'some_setting_value',
|
|
201
|
+
some_instance_key: 'some_instance_value'
|
|
202
|
+
},
|
|
203
|
+
meta: {
|
|
204
|
+
rev: 'SOME_UNIQ_REV_NUMBER'
|
|
205
|
+
},
|
|
206
|
+
some_setting: 'some_setting_value',
|
|
207
|
+
some_instance_key: 'some_instance_value'
|
|
208
|
+
}
|
|
209
|
+
]
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
await saveAfterFetchSettings(
|
|
213
|
+
// @ts-ignore
|
|
214
|
+
client,
|
|
215
|
+
'instance',
|
|
216
|
+
{
|
|
217
|
+
some_instance_key: 'some_new_instance_value'
|
|
218
|
+
}
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
const query = {
|
|
222
|
+
definition: Q('io.cozy.settings').getById('io.cozy.settings.instance'),
|
|
223
|
+
options: {
|
|
224
|
+
as: 'io.cozy.settings/io.cozy.settings.instance',
|
|
225
|
+
fetchPolicy: expect.anything(),
|
|
226
|
+
singleDocData: true
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
expect(client.fetchQueryAndGetFromState).toHaveBeenCalledWith({
|
|
230
|
+
definition: query.definition,
|
|
231
|
+
options: query.options
|
|
232
|
+
})
|
|
233
|
+
expect(client.save).toHaveBeenCalledWith({
|
|
234
|
+
id: 'io.cozy.settings.instance',
|
|
235
|
+
_id: 'io.cozy.settings.instance',
|
|
236
|
+
_type: 'io.cozy.settings',
|
|
237
|
+
type: 'io.cozy.settings',
|
|
238
|
+
_rev: 'SOME_UNIQ_REV_NUMBER',
|
|
239
|
+
attributes: {
|
|
240
|
+
some_setting: 'some_setting_value',
|
|
241
|
+
some_instance_key: 'some_new_instance_value'
|
|
242
|
+
},
|
|
243
|
+
some_setting: 'some_setting_value',
|
|
244
|
+
some_instance_key: 'some_new_instance_value',
|
|
245
|
+
meta: {
|
|
246
|
+
rev: 'SOME_UNIQ_REV_NUMBER'
|
|
247
|
+
}
|
|
248
|
+
})
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
it('should set settings for passwords', async () => {
|
|
252
|
+
const client = mocks.client()
|
|
253
|
+
|
|
254
|
+
client.fetchQueryAndGetFromState.mockResolvedValue({
|
|
255
|
+
data: [
|
|
256
|
+
{
|
|
257
|
+
_type: 'io.cozy.passwords.settings',
|
|
258
|
+
some_pass_key: 'some_pass_value'
|
|
259
|
+
}
|
|
260
|
+
]
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
await saveAfterFetchSettings(
|
|
264
|
+
// @ts-ignore
|
|
265
|
+
client,
|
|
266
|
+
'passwords',
|
|
267
|
+
{ some_pass_key: 'some_new_pass_value' }
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
const query = {
|
|
271
|
+
definition: Q('io.cozy.settings').getById('io.cozy.settings.bitwarden'),
|
|
272
|
+
options: {
|
|
273
|
+
as: 'io.cozy.settings/io.cozy.settings.bitwarden',
|
|
274
|
+
fetchPolicy: expect.anything(),
|
|
275
|
+
singleDocData: true
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
expect(client.fetchQueryAndGetFromState).toHaveBeenCalledWith({
|
|
279
|
+
definition: query.definition,
|
|
280
|
+
options: query.options
|
|
281
|
+
})
|
|
282
|
+
expect(client.save).toHaveBeenCalledWith({
|
|
283
|
+
_type: 'io.cozy.passwords.settings',
|
|
284
|
+
some_pass_key: 'some_new_pass_value'
|
|
285
|
+
})
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
it('should set settings for passwords even if key does not exist', async () => {
|
|
289
|
+
const client = mocks.client()
|
|
290
|
+
|
|
291
|
+
client.fetchQueryAndGetFromState.mockResolvedValue({
|
|
292
|
+
data: [
|
|
293
|
+
{
|
|
294
|
+
_type: 'io.cozy.passwords.settings',
|
|
295
|
+
some_existing_pass_key: 'some_pass_value'
|
|
296
|
+
}
|
|
297
|
+
]
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
await saveAfterFetchSettings(
|
|
301
|
+
// @ts-ignore
|
|
302
|
+
client,
|
|
303
|
+
'passwords',
|
|
304
|
+
{ some_new_pass_key: 'some_new_pass_value' }
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
const query = {
|
|
308
|
+
definition: Q('io.cozy.settings').getById('io.cozy.settings.bitwarden'),
|
|
309
|
+
options: {
|
|
310
|
+
as: 'io.cozy.settings/io.cozy.settings.bitwarden',
|
|
311
|
+
fetchPolicy: expect.anything(),
|
|
312
|
+
singleDocData: true
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
expect(client.fetchQueryAndGetFromState).toHaveBeenCalledWith({
|
|
316
|
+
definition: query.definition,
|
|
317
|
+
options: query.options
|
|
318
|
+
})
|
|
319
|
+
expect(client.save).toHaveBeenCalledWith({
|
|
320
|
+
_type: 'io.cozy.passwords.settings',
|
|
321
|
+
some_existing_pass_key: 'some_pass_value',
|
|
322
|
+
some_new_pass_key: 'some_new_pass_value'
|
|
323
|
+
})
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
it('should set settings for passwords using method', async () => {
|
|
327
|
+
const client = mocks.client()
|
|
328
|
+
|
|
329
|
+
client.fetchQueryAndGetFromState.mockResolvedValue({
|
|
330
|
+
data: [
|
|
331
|
+
{
|
|
332
|
+
_type: 'io.cozy.passwords.settings',
|
|
333
|
+
some_pass_key: 1
|
|
334
|
+
}
|
|
335
|
+
]
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
await saveAfterFetchSettings(
|
|
339
|
+
// @ts-ignore
|
|
340
|
+
client,
|
|
341
|
+
'passwords',
|
|
342
|
+
currentValue => ({
|
|
343
|
+
...currentValue,
|
|
344
|
+
some_pass_key: currentValue.some_pass_key + 1
|
|
345
|
+
}),
|
|
346
|
+
['some_pass_key']
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
const query = {
|
|
350
|
+
definition: Q('io.cozy.settings').getById('io.cozy.settings.bitwarden'),
|
|
351
|
+
options: {
|
|
352
|
+
as: 'io.cozy.settings/io.cozy.settings.bitwarden',
|
|
353
|
+
fetchPolicy: expect.anything(),
|
|
354
|
+
singleDocData: true
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
expect(client.fetchQueryAndGetFromState).toHaveBeenCalledWith({
|
|
358
|
+
definition: query.definition,
|
|
359
|
+
options: query.options
|
|
360
|
+
})
|
|
361
|
+
expect(client.save).toHaveBeenCalledWith({
|
|
362
|
+
_type: 'io.cozy.passwords.settings',
|
|
363
|
+
some_pass_key: 2
|
|
364
|
+
})
|
|
365
|
+
})
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
describe('normalizeSettings', () => {
|
|
369
|
+
it('should normalize data array into object', () => {
|
|
370
|
+
const result = normalizeSettings([
|
|
371
|
+
{
|
|
372
|
+
id: 'SOME_DOCUMENT_ID',
|
|
373
|
+
_id: 'SOME_DOCUMENT_ID',
|
|
374
|
+
_type: 'io.cozy.home.settings',
|
|
375
|
+
_rev: 'SOME_DOCUMENT_REV',
|
|
376
|
+
cozyMetadata: {
|
|
377
|
+
createdAt: '2024-04-03T15:00:48.961Z',
|
|
378
|
+
metadataVersion: 1,
|
|
379
|
+
updatedAt: '2024-04-03T15:00:48.961Z',
|
|
380
|
+
updatedByApps: []
|
|
381
|
+
},
|
|
382
|
+
some_attribue: true
|
|
383
|
+
}
|
|
384
|
+
])
|
|
385
|
+
|
|
386
|
+
expect(result).toStrictEqual({
|
|
387
|
+
id: 'SOME_DOCUMENT_ID',
|
|
388
|
+
_id: 'SOME_DOCUMENT_ID',
|
|
389
|
+
_type: 'io.cozy.home.settings',
|
|
390
|
+
_rev: 'SOME_DOCUMENT_REV',
|
|
391
|
+
cozyMetadata: {
|
|
392
|
+
createdAt: '2024-04-03T15:00:48.961Z',
|
|
393
|
+
metadataVersion: 1,
|
|
394
|
+
updatedAt: '2024-04-03T15:00:48.961Z',
|
|
395
|
+
updatedByApps: []
|
|
396
|
+
},
|
|
397
|
+
some_attribue: true
|
|
398
|
+
})
|
|
399
|
+
})
|
|
400
|
+
|
|
401
|
+
it('should normalize data object into object', () => {
|
|
402
|
+
const result = normalizeSettings({
|
|
403
|
+
id: 'io.cozy.settings.instance',
|
|
404
|
+
_id: 'io.cozy.settings.instance',
|
|
405
|
+
_type: 'io.cozy.settings',
|
|
406
|
+
type: 'io.cozy.settings',
|
|
407
|
+
attributes: {
|
|
408
|
+
some_attributes: 'some_value'
|
|
409
|
+
},
|
|
410
|
+
meta: {
|
|
411
|
+
rev: '2-8803d6fda4bd3216e3fbeb0a181979d5'
|
|
412
|
+
},
|
|
413
|
+
links: {
|
|
414
|
+
self: '/settings/instance'
|
|
415
|
+
},
|
|
416
|
+
some_attributes: 'some_value'
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
expect(result).toStrictEqual({
|
|
420
|
+
id: 'io.cozy.settings.instance',
|
|
421
|
+
_id: 'io.cozy.settings.instance',
|
|
422
|
+
_type: 'io.cozy.settings',
|
|
423
|
+
type: 'io.cozy.settings',
|
|
424
|
+
attributes: {
|
|
425
|
+
some_attributes: 'some_value'
|
|
426
|
+
},
|
|
427
|
+
meta: {
|
|
428
|
+
rev: '2-8803d6fda4bd3216e3fbeb0a181979d5'
|
|
429
|
+
},
|
|
430
|
+
links: {
|
|
431
|
+
self: '/settings/instance'
|
|
432
|
+
},
|
|
433
|
+
some_attributes: 'some_value'
|
|
434
|
+
})
|
|
435
|
+
})
|
|
436
|
+
})
|
|
437
|
+
describe('editSettings', () => {
|
|
438
|
+
it('should inject value into settings', () => {
|
|
439
|
+
const result = editSettings(
|
|
440
|
+
'passwords',
|
|
441
|
+
{
|
|
442
|
+
_type: 'io.cozy.passwords.settings',
|
|
443
|
+
some_pass_key: 'some_pass_value'
|
|
444
|
+
},
|
|
445
|
+
{ some_pass_key: 'some_new_pass_value' }
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
expect(result).toStrictEqual({
|
|
449
|
+
_type: 'io.cozy.passwords.settings',
|
|
450
|
+
some_pass_key: 'some_new_pass_value'
|
|
451
|
+
})
|
|
452
|
+
})
|
|
453
|
+
|
|
454
|
+
it('should inject _rev value and edit attributes for instance settings', () => {
|
|
455
|
+
const result = editSettings(
|
|
456
|
+
'instance',
|
|
457
|
+
{
|
|
458
|
+
id: 'io.cozy.settings.instance',
|
|
459
|
+
_id: 'io.cozy.settings.instance',
|
|
460
|
+
_type: 'io.cozy.settings',
|
|
461
|
+
type: 'io.cozy.settings',
|
|
462
|
+
attributes: {
|
|
463
|
+
some_setting: 'some_setting_value',
|
|
464
|
+
some_instance_key: 'some_instance_value'
|
|
465
|
+
},
|
|
466
|
+
meta: {
|
|
467
|
+
rev: 'SOME_UNIQ_REV_NUMBER'
|
|
468
|
+
},
|
|
469
|
+
some_setting: 'some_setting_value',
|
|
470
|
+
some_instance_key: 'some_instance_value'
|
|
471
|
+
},
|
|
472
|
+
{ some_instance_key: 'some_new_instance_value' }
|
|
473
|
+
)
|
|
474
|
+
|
|
475
|
+
expect(result).toStrictEqual({
|
|
476
|
+
id: 'io.cozy.settings.instance',
|
|
477
|
+
_id: 'io.cozy.settings.instance',
|
|
478
|
+
_type: 'io.cozy.settings',
|
|
479
|
+
type: 'io.cozy.settings',
|
|
480
|
+
_rev: 'SOME_UNIQ_REV_NUMBER',
|
|
481
|
+
attributes: {
|
|
482
|
+
some_setting: 'some_setting_value',
|
|
483
|
+
some_instance_key: 'some_new_instance_value'
|
|
484
|
+
},
|
|
485
|
+
some_setting: 'some_setting_value',
|
|
486
|
+
some_instance_key: 'some_new_instance_value',
|
|
487
|
+
meta: {
|
|
488
|
+
rev: 'SOME_UNIQ_REV_NUMBER'
|
|
489
|
+
}
|
|
490
|
+
})
|
|
491
|
+
})
|
|
492
|
+
})
|
|
493
|
+
})
|
package/dist/hooks/index.js
CHANGED
|
@@ -67,6 +67,12 @@ Object.defineProperty(exports, "useInstanceInfo", {
|
|
|
67
67
|
return _useInstanceInfo.useInstanceInfo;
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
|
+
Object.defineProperty(exports, "useSettings", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function get() {
|
|
73
|
+
return _useSetting.useSettings;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
70
76
|
|
|
71
77
|
var _useAppLinkWithStoreFallback = _interopRequireDefault(require("./useAppLinkWithStoreFallback"));
|
|
72
78
|
|
|
@@ -84,4 +90,6 @@ var _useQueryAll = _interopRequireDefault(require("./useQueryAll"));
|
|
|
84
90
|
|
|
85
91
|
var _useMutation = require("./useMutation");
|
|
86
92
|
|
|
87
|
-
var _useInstanceInfo = require("./useInstanceInfo");
|
|
93
|
+
var _useInstanceInfo = require("./useInstanceInfo");
|
|
94
|
+
|
|
95
|
+
var _useSetting = require("./useSetting");
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.useSettings = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
|
+
|
|
12
|
+
var _react = require("react");
|
|
13
|
+
|
|
14
|
+
var _helpers = require("../helpers");
|
|
15
|
+
|
|
16
|
+
var _useMutation2 = require("./useMutation");
|
|
17
|
+
|
|
18
|
+
var _useQuery2 = _interopRequireDefault(require("./useQuery"));
|
|
19
|
+
|
|
20
|
+
var _utils = require("../utils");
|
|
21
|
+
|
|
22
|
+
var _settings = require("../helpers/settings");
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Query the cozy-app settings corresponding to the given slug and
|
|
26
|
+
* return:
|
|
27
|
+
* - the values corresponding to the given `keys`
|
|
28
|
+
* - the `save()` method that can be used to edit the setting's value
|
|
29
|
+
* - the query that manages the state during the fetching of the setting
|
|
30
|
+
* - the mutation that manages the state during the saving of the setting
|
|
31
|
+
*
|
|
32
|
+
* @template {string} T
|
|
33
|
+
*
|
|
34
|
+
* @param {string} slug - the cozy-app's slug containing the setting (special cases are: 'instance' for global settings and 'passwords' for bitwarden settings)
|
|
35
|
+
* @param {T[]} keys - The name of the setting to retrieve
|
|
36
|
+
* @returns {import("../types").UseSettingsReturnValue<T>}
|
|
37
|
+
*/
|
|
38
|
+
var useSettings = function useSettings(slug, keys) {
|
|
39
|
+
var query = (0, _helpers.getQuery)(slug);
|
|
40
|
+
|
|
41
|
+
var _useQuery = (0, _useQuery2.default)(query.definition, query.options),
|
|
42
|
+
settingsData = _useQuery.data,
|
|
43
|
+
settingsQuery = (0, _objectWithoutProperties2.default)(_useQuery, ["data"]);
|
|
44
|
+
|
|
45
|
+
var _useMutation = (0, _useMutation2.useMutation)(),
|
|
46
|
+
mutate = _useMutation.mutate,
|
|
47
|
+
mutation = (0, _objectWithoutProperties2.default)(_useMutation, ["mutate"]);
|
|
48
|
+
|
|
49
|
+
var save = (0, _react.useCallback)(function (items) {
|
|
50
|
+
var settings = (0, _helpers.normalizeSettings)(settingsData);
|
|
51
|
+
var newSettings = (0, _helpers.editSettings)(slug, settings, items);
|
|
52
|
+
return mutate(newSettings);
|
|
53
|
+
}, [mutate, settingsData, slug]);
|
|
54
|
+
var settings = (0, _helpers.normalizeSettings)(settingsData);
|
|
55
|
+
var settingValue = (0, _utils.hasQueryBeenLoaded)(settingsQuery) ? (0, _settings.extractKeys)(settings, keys) : undefined;
|
|
56
|
+
return {
|
|
57
|
+
query: settingsQuery,
|
|
58
|
+
values: settingValue,
|
|
59
|
+
save: save,
|
|
60
|
+
mutation: mutation
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
exports.useSettings = useSettings;
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"mechanic_invoice": "Facture de réparation |||| Factures de réparation",
|
|
63
63
|
"motivation_letter": "Lettre de motivation |||| Lettres de motivation",
|
|
64
64
|
"national_health_insurance_card": "Carte vitale |||| Cartes vitales",
|
|
65
|
-
"national_health_insurance_right_certificate": "Attestation de droits de l'Assurance Maladie
|
|
65
|
+
"national_health_insurance_right_certificate": "Attestation de droits de l'Assurance Maladie |||| Attestations de droits de l'Assurance Maladie",
|
|
66
66
|
"national_id_card": "Carte d'identité |||| Cartes d'identité",
|
|
67
67
|
"note_identity_document": "Note Identité |||| Notes Identité",
|
|
68
68
|
"note_family_document": "Note Famille |||| Notes Famille",
|
package/dist/types.js
CHANGED
|
@@ -250,7 +250,7 @@ var _dsl = require("./queries/dsl");
|
|
|
250
250
|
*/
|
|
251
251
|
|
|
252
252
|
/**
|
|
253
|
-
* @typedef {object}
|
|
253
|
+
* @typedef {object} QueryStateWithoutData
|
|
254
254
|
* @property {string} id
|
|
255
255
|
* @property {QueryDefinition} definition
|
|
256
256
|
* @property {QueryFetchStatus} fetchStatus
|
|
@@ -262,12 +262,20 @@ var _dsl = require("./queries/dsl");
|
|
|
262
262
|
* @property {boolean} hasMore
|
|
263
263
|
* @property {number} count
|
|
264
264
|
* @property {number} fetchedPagesCount
|
|
265
|
-
* @property {object|Array} data
|
|
266
265
|
* @property {string} bookmark
|
|
267
266
|
* @property {object} [execution_stats]
|
|
268
267
|
* @property {QueryOptions} [options]
|
|
269
268
|
*/
|
|
270
269
|
|
|
270
|
+
/**
|
|
271
|
+
* @typedef {object} QueryStateData
|
|
272
|
+
* @property {object|Array} data
|
|
273
|
+
*/
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* @typedef {QueryStateWithoutData & QueryStateData} QueryState
|
|
277
|
+
*/
|
|
278
|
+
|
|
271
279
|
/**
|
|
272
280
|
* @typedef {object} AutoUpdateOptions
|
|
273
281
|
* @param {boolean} update - Should documents be updated in the query (default: true)
|
|
@@ -290,6 +298,12 @@ var _dsl = require("./queries/dsl");
|
|
|
290
298
|
* compatibility but will be set to true in the future.
|
|
291
299
|
*/
|
|
292
300
|
|
|
301
|
+
/**
|
|
302
|
+
* @typedef {object} Query
|
|
303
|
+
* @property {QueryDefinition} definition
|
|
304
|
+
* @property {QueryOptions} options
|
|
305
|
+
*/
|
|
306
|
+
|
|
293
307
|
/**
|
|
294
308
|
* @typedef {object} FetchMoreAble
|
|
295
309
|
* @property {Function} fetchMore
|
|
@@ -305,13 +319,39 @@ var _dsl = require("./queries/dsl");
|
|
|
305
319
|
*/
|
|
306
320
|
|
|
307
321
|
/**
|
|
308
|
-
* @typedef {object}
|
|
309
|
-
* @property {Function} mutate - Function to save the document
|
|
322
|
+
* @typedef {object} UseMutationWithoutMutate
|
|
310
323
|
* @property {QueryFetchStatus} mutationStatus - Status of the current mutation
|
|
311
324
|
* @property {object} [error] - Error if the mutation failed
|
|
312
325
|
* @property {object} [data] - Data return after the mutation
|
|
313
326
|
*/
|
|
314
327
|
|
|
328
|
+
/**
|
|
329
|
+
* @typedef {object} UseMutationMutate
|
|
330
|
+
* @property {Function} mutate - Function to save the document
|
|
331
|
+
*/
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* @typedef {UseMutationWithoutMutate & UseMutationMutate} UseMutationReturnValue
|
|
335
|
+
*/
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Update the setting with corresponding value and save it.
|
|
339
|
+
*
|
|
340
|
+
* @template {string} T
|
|
341
|
+
*
|
|
342
|
+
* @callback SaveSettingsFunction
|
|
343
|
+
* @param {Partial<Record<T, any>>} items - The new setting's value
|
|
344
|
+
*/
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* @template {string} T
|
|
348
|
+
* @typedef {object} UseSettingsReturnValue
|
|
349
|
+
* @property {Record<T, any> | undefined} values - The setting's value
|
|
350
|
+
* @property {SaveSettingsFunction<T>} save - Function to edit the setting
|
|
351
|
+
* @property {QueryStateWithoutData} query - Function to edit the setting
|
|
352
|
+
* @property {UseMutationWithoutMutate} mutation - Status of the current mutation
|
|
353
|
+
*/
|
|
354
|
+
|
|
315
355
|
/**
|
|
316
356
|
* A reference to a document
|
|
317
357
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "46.
|
|
3
|
+
"version": "46.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -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": "69f0df2adc776ecec40b14eaae495b544d42963f"
|
|
79
79
|
}
|