cozy-harvest-lib 9.32.1 → 9.32.2
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/CHANGELOG.md +11 -0
- package/dist/services/biWebView.js +28 -46
- package/dist/services/biWebView.spec.js +53 -25
- package/package.json +2 -2
- package/src/services/biWebView.js +17 -4
- package/src/services/biWebView.spec.js +67 -19
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [9.32.2](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.32.1...cozy-harvest-lib@9.32.2) (2022-12-02)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Only update cozy-client store when refreshing contracts ([85822d8](https://github.com/cozy/cozy-libs/commit/85822d8f12ba6578aae238e480bf7788349e875a))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [9.32.1](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@9.32.0...cozy-harvest-lib@9.32.1) (2022-12-02)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -27,6 +27,7 @@ import { getBIConnectionAccountsList, getBIConnection } from './bi-http';
|
|
|
27
27
|
import assert from '../assert';
|
|
28
28
|
import logger from '../logger';
|
|
29
29
|
import { Q } from 'cozy-client';
|
|
30
|
+
import { receiveMutationResult } from 'cozy-client/dist/store';
|
|
30
31
|
import PromiseCache from 'cozy-client/dist/promise-cache'; // @ts-ignore (its a peerDep and I don't know how to configure ts for that)
|
|
31
32
|
|
|
32
33
|
import flag from 'cozy-flags';
|
|
@@ -443,7 +444,7 @@ export var getCozyBankIds = function getCozyBankIds(_ref10) {
|
|
|
443
444
|
|
|
444
445
|
export var refreshContracts = /*#__PURE__*/function () {
|
|
445
446
|
var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref11) {
|
|
446
|
-
var client, konnector, account, biConfig, code, config, connectionId, _yield$getBIConnectio, contracts, contractsById, _yield$client$query, currentContractsList, _iterator, _step, currentContract, disabledValue, hasChanged;
|
|
447
|
+
var client, konnector, account, biConfig, code, config, connectionId, _yield$getBIConnectio, contracts, contractsById, _yield$client$query, currentContractsList, _iterator, _step, currentContract, disabledValue, hasChanged, newMetadata;
|
|
447
448
|
|
|
448
449
|
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
449
450
|
while (1) {
|
|
@@ -479,58 +480,39 @@ export var refreshContracts = /*#__PURE__*/function () {
|
|
|
479
480
|
_yield$client$query = _context5.sent;
|
|
480
481
|
currentContractsList = _yield$client$query.data;
|
|
481
482
|
_iterator = _createForOfIteratorHelper(currentContractsList);
|
|
482
|
-
_context5.prev = 16;
|
|
483
483
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
484
|
+
try {
|
|
485
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
486
|
+
currentContract = _step.value;
|
|
487
|
+
disabledValue = convertBIDateToStandardDate(contractsById[currentContract.vendorId]);
|
|
488
|
+
hasChanged = currentContract.metadata.disabledAt !== disabledValue;
|
|
489
|
+
|
|
490
|
+
if (hasChanged) {
|
|
491
|
+
newMetadata = {
|
|
492
|
+
disabledAt: disabledValue,
|
|
493
|
+
imported: !disabledValue
|
|
494
|
+
}; // update the cozy-client store only to let the use see the result of the update fast
|
|
495
|
+
// but without creating conflict with the update which will come from the BI webhooks
|
|
496
|
+
|
|
497
|
+
client.store.dispatch(receiveMutationResult('contract-memory-update', {
|
|
498
|
+
data: [_objectSpread(_objectSpread({}, currentContract), {}, {
|
|
499
|
+
metadata: _objectSpread(_objectSpread({}, currentContract.metadata), newMetadata)
|
|
500
|
+
})]
|
|
501
|
+
}));
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
} catch (err) {
|
|
505
|
+
_iterator.e(err);
|
|
506
|
+
} finally {
|
|
507
|
+
_iterator.f();
|
|
499
508
|
}
|
|
500
509
|
|
|
501
|
-
|
|
502
|
-
currentContract.metadata.imported = !disabledValue; // FIXME bulk save via client.collection().updateAll does not show update of accounts in realtime
|
|
503
|
-
|
|
504
|
-
_context5.next = 27;
|
|
505
|
-
return client.save(currentContract);
|
|
506
|
-
|
|
507
|
-
case 27:
|
|
508
|
-
_context5.next = 18;
|
|
509
|
-
break;
|
|
510
|
-
|
|
511
|
-
case 29:
|
|
512
|
-
_context5.next = 34;
|
|
513
|
-
break;
|
|
514
|
-
|
|
515
|
-
case 31:
|
|
516
|
-
_context5.prev = 31;
|
|
517
|
-
_context5.t0 = _context5["catch"](16);
|
|
518
|
-
|
|
519
|
-
_iterator.e(_context5.t0);
|
|
520
|
-
|
|
521
|
-
case 34:
|
|
522
|
-
_context5.prev = 34;
|
|
523
|
-
|
|
524
|
-
_iterator.f();
|
|
525
|
-
|
|
526
|
-
return _context5.finish(34);
|
|
527
|
-
|
|
528
|
-
case 37:
|
|
510
|
+
case 17:
|
|
529
511
|
case "end":
|
|
530
512
|
return _context5.stop();
|
|
531
513
|
}
|
|
532
514
|
}
|
|
533
|
-
}, _callee5
|
|
515
|
+
}, _callee5);
|
|
534
516
|
}));
|
|
535
517
|
|
|
536
518
|
return function refreshContracts(_x5) {
|
|
@@ -349,7 +349,7 @@ describe('refreshContracts', function () {
|
|
|
349
349
|
client = new CozyClient({
|
|
350
350
|
uri: 'http://testcozy.mycozy.cloud'
|
|
351
351
|
});
|
|
352
|
-
client.
|
|
352
|
+
client.store.dispatch = jest.fn();
|
|
353
353
|
client.query = jest.fn().mockResolvedValueOnce({
|
|
354
354
|
data: {
|
|
355
355
|
mode: 'prod',
|
|
@@ -407,34 +407,62 @@ describe('refreshContracts', function () {
|
|
|
407
407
|
});
|
|
408
408
|
|
|
409
409
|
case 6:
|
|
410
|
-
expect(client.
|
|
411
|
-
expect(client.
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
410
|
+
expect(client.store.dispatch).toHaveBeenCalledTimes(4);
|
|
411
|
+
expect(client.store.dispatch).toHaveBeenNthCalledWith(1, {
|
|
412
|
+
definition: {},
|
|
413
|
+
mutationId: 'contract-memory-update',
|
|
414
|
+
response: {
|
|
415
|
+
data: [{
|
|
416
|
+
metadata: {
|
|
417
|
+
disabledAt: '2022-05-25T12:00:00',
|
|
418
|
+
imported: false
|
|
419
|
+
},
|
|
420
|
+
vendorId: '1'
|
|
421
|
+
}]
|
|
415
422
|
},
|
|
416
|
-
|
|
417
|
-
});
|
|
418
|
-
expect(client.
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
423
|
+
type: 'RECEIVE_MUTATION_RESULT'
|
|
424
|
+
});
|
|
425
|
+
expect(client.store.dispatch).toHaveBeenNthCalledWith(2, {
|
|
426
|
+
definition: {},
|
|
427
|
+
mutationId: 'contract-memory-update',
|
|
428
|
+
response: {
|
|
429
|
+
data: [{
|
|
430
|
+
metadata: {
|
|
431
|
+
disabledAt: undefined,
|
|
432
|
+
imported: true
|
|
433
|
+
},
|
|
434
|
+
vendorId: '2'
|
|
435
|
+
}]
|
|
422
436
|
},
|
|
423
|
-
|
|
424
|
-
});
|
|
425
|
-
expect(client.
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
437
|
+
type: 'RECEIVE_MUTATION_RESULT'
|
|
438
|
+
});
|
|
439
|
+
expect(client.store.dispatch).toHaveBeenNthCalledWith(3, {
|
|
440
|
+
definition: {},
|
|
441
|
+
mutationId: 'contract-memory-update',
|
|
442
|
+
response: {
|
|
443
|
+
data: [{
|
|
444
|
+
metadata: {
|
|
445
|
+
disabledAt: '2022-05-25T12:01:00',
|
|
446
|
+
imported: false
|
|
447
|
+
},
|
|
448
|
+
vendorId: '3'
|
|
449
|
+
}]
|
|
429
450
|
},
|
|
430
|
-
|
|
431
|
-
});
|
|
432
|
-
expect(client.
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
451
|
+
type: 'RECEIVE_MUTATION_RESULT'
|
|
452
|
+
});
|
|
453
|
+
expect(client.store.dispatch).toHaveBeenNthCalledWith(4, {
|
|
454
|
+
definition: {},
|
|
455
|
+
mutationId: 'contract-memory-update',
|
|
456
|
+
response: {
|
|
457
|
+
data: [{
|
|
458
|
+
metadata: {
|
|
459
|
+
disabledAt: undefined,
|
|
460
|
+
imported: true
|
|
461
|
+
},
|
|
462
|
+
vendorId: '4'
|
|
463
|
+
}]
|
|
436
464
|
},
|
|
437
|
-
|
|
465
|
+
type: 'RECEIVE_MUTATION_RESULT'
|
|
438
466
|
});
|
|
439
467
|
|
|
440
468
|
case 11:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-harvest-lib",
|
|
3
|
-
"version": "9.32.
|
|
3
|
+
"version": "9.32.2",
|
|
4
4
|
"description": "Provides logic, modules and components for Cozy's harvest applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "Cozy",
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
"react-router-dom": "^5.0.1"
|
|
92
92
|
},
|
|
93
93
|
"sideEffects": false,
|
|
94
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "17af5df3d39fd8b3bc37aa6f421ec0dd1c97b787"
|
|
95
95
|
}
|
|
@@ -9,6 +9,7 @@ import { getBIConnectionAccountsList, getBIConnection } from './bi-http'
|
|
|
9
9
|
import assert from '../assert'
|
|
10
10
|
import logger from '../logger'
|
|
11
11
|
import { Q } from 'cozy-client'
|
|
12
|
+
import { receiveMutationResult } from 'cozy-client/dist/store'
|
|
12
13
|
import PromiseCache from 'cozy-client/dist/promise-cache'
|
|
13
14
|
// @ts-ignore (its a peerDep and I don't know how to configure ts for that)
|
|
14
15
|
import flag from 'cozy-flags'
|
|
@@ -341,10 +342,22 @@ export const refreshContracts = async ({ client, konnector, account }) => {
|
|
|
341
342
|
)
|
|
342
343
|
const hasChanged = currentContract.metadata.disabledAt !== disabledValue
|
|
343
344
|
if (hasChanged) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
345
|
+
const newMetadata = {
|
|
346
|
+
disabledAt: disabledValue,
|
|
347
|
+
imported: !disabledValue
|
|
348
|
+
}
|
|
349
|
+
// update the cozy-client store only to let the use see the result of the update fast
|
|
350
|
+
// but without creating conflict with the update which will come from the BI webhooks
|
|
351
|
+
client.store.dispatch(
|
|
352
|
+
receiveMutationResult('contract-memory-update', {
|
|
353
|
+
data: [
|
|
354
|
+
{
|
|
355
|
+
...currentContract,
|
|
356
|
+
metadata: { ...currentContract.metadata, ...newMetadata }
|
|
357
|
+
}
|
|
358
|
+
]
|
|
359
|
+
})
|
|
360
|
+
)
|
|
348
361
|
}
|
|
349
362
|
}
|
|
350
363
|
}
|
|
@@ -211,7 +211,7 @@ describe('refreshContracts', () => {
|
|
|
211
211
|
const client = new CozyClient({
|
|
212
212
|
uri: 'http://testcozy.mycozy.cloud'
|
|
213
213
|
})
|
|
214
|
-
client.
|
|
214
|
+
client.store.dispatch = jest.fn()
|
|
215
215
|
client.query = jest
|
|
216
216
|
.fn()
|
|
217
217
|
.mockResolvedValueOnce({
|
|
@@ -226,12 +226,18 @@ describe('refreshContracts', () => {
|
|
|
226
226
|
})
|
|
227
227
|
.mockResolvedValue({
|
|
228
228
|
data: [
|
|
229
|
-
{
|
|
229
|
+
{
|
|
230
|
+
vendorId: '1',
|
|
231
|
+
metadata: { imported: true }
|
|
232
|
+
},
|
|
230
233
|
{
|
|
231
234
|
vendorId: '2',
|
|
232
235
|
metadata: { imported: false, disabledAt: '2022-08-05 12:00:00' }
|
|
233
236
|
},
|
|
234
|
-
{
|
|
237
|
+
{
|
|
238
|
+
vendorId: '3',
|
|
239
|
+
metadata: { imported: true }
|
|
240
|
+
},
|
|
235
241
|
{
|
|
236
242
|
vendorId: '4',
|
|
237
243
|
metadata: { imported: false, disabledAt: '2022-08-05 12:01:00' }
|
|
@@ -248,22 +254,64 @@ describe('refreshContracts', () => {
|
|
|
248
254
|
})
|
|
249
255
|
|
|
250
256
|
await refreshContracts({ client, konnector, account: {} })
|
|
251
|
-
expect(client.
|
|
252
|
-
expect(client.
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
257
|
+
expect(client.store.dispatch).toHaveBeenCalledTimes(4)
|
|
258
|
+
expect(client.store.dispatch).toHaveBeenNthCalledWith(1, {
|
|
259
|
+
definition: {},
|
|
260
|
+
mutationId: 'contract-memory-update',
|
|
261
|
+
response: {
|
|
262
|
+
data: [
|
|
263
|
+
{
|
|
264
|
+
metadata: {
|
|
265
|
+
disabledAt: '2022-05-25T12:00:00',
|
|
266
|
+
imported: false
|
|
267
|
+
},
|
|
268
|
+
vendorId: '1'
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
},
|
|
272
|
+
type: 'RECEIVE_MUTATION_RESULT'
|
|
273
|
+
})
|
|
274
|
+
expect(client.store.dispatch).toHaveBeenNthCalledWith(2, {
|
|
275
|
+
definition: {},
|
|
276
|
+
mutationId: 'contract-memory-update',
|
|
277
|
+
response: {
|
|
278
|
+
data: [
|
|
279
|
+
{
|
|
280
|
+
metadata: {
|
|
281
|
+
disabledAt: undefined,
|
|
282
|
+
imported: true
|
|
283
|
+
},
|
|
284
|
+
vendorId: '2'
|
|
285
|
+
}
|
|
286
|
+
]
|
|
287
|
+
},
|
|
288
|
+
type: 'RECEIVE_MUTATION_RESULT'
|
|
289
|
+
})
|
|
290
|
+
expect(client.store.dispatch).toHaveBeenNthCalledWith(3, {
|
|
291
|
+
definition: {},
|
|
292
|
+
mutationId: 'contract-memory-update',
|
|
293
|
+
response: {
|
|
294
|
+
data: [
|
|
295
|
+
{
|
|
296
|
+
metadata: { disabledAt: '2022-05-25T12:01:00', imported: false },
|
|
297
|
+
vendorId: '3'
|
|
298
|
+
}
|
|
299
|
+
]
|
|
300
|
+
},
|
|
301
|
+
type: 'RECEIVE_MUTATION_RESULT'
|
|
302
|
+
})
|
|
303
|
+
expect(client.store.dispatch).toHaveBeenNthCalledWith(4, {
|
|
304
|
+
definition: {},
|
|
305
|
+
mutationId: 'contract-memory-update',
|
|
306
|
+
response: {
|
|
307
|
+
data: [
|
|
308
|
+
{
|
|
309
|
+
metadata: { disabledAt: undefined, imported: true },
|
|
310
|
+
vendorId: '4'
|
|
311
|
+
}
|
|
312
|
+
]
|
|
313
|
+
},
|
|
314
|
+
type: 'RECEIVE_MUTATION_RESULT'
|
|
267
315
|
})
|
|
268
316
|
})
|
|
269
317
|
})
|