cozy-client 40.3.0 → 40.4.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.
@@ -2426,7 +2426,7 @@ var CozyClient = /*#__PURE__*/function () {
2426
2426
  /**
2427
2427
  * loadInstanceOptionsFromStack - Loads the instance options from cozy-stack and exposes it through getInstanceOptions
2428
2428
  *
2429
- * For now only retrieving capabilities is supported
2429
+ * This method is not iso with loadInstanceOptionsFromDOM for now.
2430
2430
  *
2431
2431
  * @returns {Promise<void>}
2432
2432
  */
@@ -2435,7 +2435,9 @@ var CozyClient = /*#__PURE__*/function () {
2435
2435
  key: "loadInstanceOptionsFromStack",
2436
2436
  value: function () {
2437
2437
  var _loadInstanceOptionsFromStack = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee18() {
2438
- var _yield$this$query, data;
2438
+ var _instanceData$attribu, _instanceData$attribu2;
2439
+
2440
+ var _yield$this$query, data, _yield$this$query2, instanceData;
2439
2441
 
2440
2442
  return _regenerator.default.wrap(function _callee18$(_context18) {
2441
2443
  while (1) {
@@ -2447,12 +2449,20 @@ var CozyClient = /*#__PURE__*/function () {
2447
2449
  case 2:
2448
2450
  _yield$this$query = _context18.sent;
2449
2451
  data = _yield$this$query.data;
2452
+ _context18.next = 6;
2453
+ return this.query((0, _dsl.Q)('io.cozy.settings').getById('io.cozy.settings.instance'));
2454
+
2455
+ case 6:
2456
+ _yield$this$query2 = _context18.sent;
2457
+ instanceData = _yield$this$query2.data;
2450
2458
  this.instanceOptions = {
2451
- capabilities: data.attributes
2459
+ capabilities: data.attributes,
2460
+ locale: (_instanceData$attribu = instanceData.attributes) === null || _instanceData$attribu === void 0 ? void 0 : _instanceData$attribu.locale,
2461
+ tracking: (_instanceData$attribu2 = instanceData.attributes) === null || _instanceData$attribu2 === void 0 ? void 0 : _instanceData$attribu2.tracking
2452
2462
  };
2453
2463
  this.capabilities = this.instanceOptions.capabilities || null;
2454
2464
 
2455
- case 6:
2465
+ case 10:
2456
2466
  case "end":
2457
2467
  return _context18.stop();
2458
2468
  }
@@ -2685,7 +2695,7 @@ var CozyClient = /*#__PURE__*/function () {
2685
2695
  CozyClient.hooks = CozyClient.hooks || {};
2686
2696
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2687
2697
 
2688
- CozyClient.version = "40.3.0";
2698
+ CozyClient.version = "40.4.1";
2689
2699
 
2690
2700
  _microee.default.mixin(CozyClient);
2691
2701
 
@@ -492,9 +492,14 @@ describe('CozyClient logout', () => {
492
492
  })
493
493
 
494
494
  it('should call reset on each link that can be reset', async () => {
495
- client.query = jest.fn().mockResolvedValueOnce({
496
- data: { attributes: { file_versioning: true, flat_subdomains: true } }
497
- })
495
+ client.query = jest
496
+ .fn()
497
+ .mockResolvedValueOnce({
498
+ data: { attributes: { file_versioning: true, flat_subdomains: true } }
499
+ })
500
+ .mockResolvedValueOnce({
501
+ data: { attributes: { locale: 'fr', tracking: true } }
502
+ })
498
503
  links[0].reset = jest.fn()
499
504
  links[2].reset = jest.fn()
500
505
  await client.login()
@@ -512,9 +517,14 @@ describe('CozyClient logout', () => {
512
517
  })
513
518
 
514
519
  it('should call all reset even if a reset throws an error', async () => {
515
- client.query = jest.fn().mockResolvedValueOnce({
516
- data: { attributes: { file_versioning: true, flat_subdomains: true } }
517
- })
520
+ client.query = jest
521
+ .fn()
522
+ .mockResolvedValueOnce({
523
+ data: { attributes: { file_versioning: true, flat_subdomains: true } }
524
+ })
525
+ .mockResolvedValueOnce({
526
+ data: { attributes: { locale: 'fr', tracking: true } }
527
+ })
518
528
  links[0].reset = jest.fn().mockRejectedValue(new Error('Async error'))
519
529
  links[2].reset = jest.fn()
520
530
  await client.login()
@@ -524,9 +534,14 @@ describe('CozyClient logout', () => {
524
534
  })
525
535
 
526
536
  it('should emit events', async () => {
527
- client.query = jest.fn().mockResolvedValueOnce({
528
- data: { attributes: { file_versioning: true, flat_subdomains: true } }
529
- })
537
+ client.query = jest
538
+ .fn()
539
+ .mockResolvedValueOnce({
540
+ data: { attributes: { file_versioning: true, flat_subdomains: true } }
541
+ })
542
+ .mockResolvedValueOnce({
543
+ data: { attributes: { locale: 'fr', tracking: true } }
544
+ })
530
545
  const originalLogout = client.logout
531
546
  links[0].reset = jest.fn()
532
547
  links[2].reset = jest.fn()
@@ -545,9 +560,14 @@ describe('CozyClient logout', () => {
545
560
  })
546
561
 
547
562
  it('should unregister an oauth client', async () => {
548
- client.query = jest.fn().mockResolvedValueOnce({
549
- data: { attributes: { file_versioning: true, flat_subdomains: true } }
550
- })
563
+ client.query = jest
564
+ .fn()
565
+ .mockResolvedValueOnce({
566
+ data: { attributes: { file_versioning: true, flat_subdomains: true } }
567
+ })
568
+ .mockResolvedValueOnce({
569
+ data: { attributes: { locale: 'fr', tracking: true } }
570
+ })
551
571
  await client.login()
552
572
  stackClient.isRegistered.mockReturnValue(true)
553
573
 
@@ -130,7 +130,7 @@ var hasPasswordDefinedAttribute = /*#__PURE__*/function () {
130
130
  case 3:
131
131
  _yield$client$fetchQu = _context.sent;
132
132
  password_defined = _yield$client$fetchQu.data.attributes.password_defined;
133
- return _context.abrupt("return", password_defined);
133
+ return _context.abrupt("return", Boolean(password_defined));
134
134
 
135
135
  case 8:
136
136
  _context.prev = 8;
@@ -147,4 +147,34 @@ describe('instance', () => {
147
147
  })
148
148
  })
149
149
  })
150
+
151
+ describe('hasPasswordDefinedAttribute', () => {
152
+ const setup = async (data = {}) => {
153
+ const client = {
154
+ fetchQueryAndGetFromState: jest
155
+ .fn()
156
+ .mockImplementation(() => Promise.resolve({ data }))
157
+ }
158
+ return await instance.hasPasswordDefinedAttribute(client)
159
+ }
160
+ it('should return false if attribute password_defined does not exist', async () => {
161
+ const res = await setup()
162
+ expect(res).toBe(false)
163
+ })
164
+
165
+ it('should return false if attribute password_defined is undefined', async () => {
166
+ const res = await setup({ attributes: { password_defined: undefined } })
167
+ expect(res).toBe(false)
168
+ })
169
+
170
+ it('should return false if attribute password_defined is false', async () => {
171
+ const res = await setup({ attributes: { password_defined: false } })
172
+ expect(res).toBe(false)
173
+ })
174
+
175
+ it('should return true if attribute password_defined is true', async () => {
176
+ const res = await setup({ attributes: { password_defined: true } })
177
+ expect(res).toBe(true)
178
+ })
179
+ })
150
180
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "40.3.0",
3
+ "version": "40.4.1",
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": "e03c21751e68ce24db6804dadca52b367e84abfb"
76
+ "gitHead": "09df56daa818e677b7aec6c1d74ac6dd2a5d14b0"
77
77
  }
@@ -687,7 +687,7 @@ declare class CozyClient {
687
687
  /**
688
688
  * loadInstanceOptionsFromStack - Loads the instance options from cozy-stack and exposes it through getInstanceOptions
689
689
  *
690
- * For now only retrieving capabilities is supported
690
+ * This method is not iso with loadInstanceOptionsFromDOM for now.
691
691
  *
692
692
  * @returns {Promise<void>}
693
693
  */