cozy-client 34.6.3 → 34.6.4

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.
@@ -237,6 +237,7 @@ var CozyClient = /*#__PURE__*/function () {
237
237
  }
238
238
 
239
239
  this.appMetadata = appMetadata;
240
+ this.loginPromise = null;
240
241
  _options.uri = securiseUri(_options.uri);
241
242
  this.options = _options;
242
243
  this.queryIdGenerator = new _queries.QueryIDGenerator();
@@ -272,6 +273,15 @@ var CozyClient = /*#__PURE__*/function () {
272
273
  } catch (err) {// not a critical error, we may be in node or the instance options are not on the default HTML element
273
274
  }
274
275
  }
276
+ /**
277
+ * Holds in-flight promises for deduplication purpose
278
+ *
279
+ * @private
280
+ * @type {PromiseCache}
281
+ */
282
+
283
+
284
+ this._promiseCache = new _promiseCache.default();
275
285
 
276
286
  if (_options.uri && _options.token) {
277
287
  this.login();
@@ -286,15 +296,6 @@ var CozyClient = /*#__PURE__*/function () {
286
296
  if (_options.store !== false) {
287
297
  this.ensureStore();
288
298
  }
289
- /**
290
- * Holds in-flight promises for deduplication purpose
291
- *
292
- * @private
293
- * @type {PromiseCache}
294
- */
295
-
296
-
297
- this._promiseCache = new _promiseCache.default();
298
299
  }
299
300
  /**
300
301
  * Gets overrided by MicroEE.mixin
@@ -2516,13 +2517,13 @@ var CozyClient = /*#__PURE__*/function () {
2516
2517
  key: "fromOldOAuthClient",
2517
2518
  value: function () {
2518
2519
  var _fromOldOAuthClient = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee19(oldClient, options) {
2519
- var credentials, oauthOptions;
2520
+ var credentials, oauthOptions, client;
2520
2521
  return _regenerator.default.wrap(function _callee19$(_context19) {
2521
2522
  while (1) {
2522
2523
  switch (_context19.prev = _context19.next) {
2523
2524
  case 0:
2524
2525
  if (!oldClient._oauth) {
2525
- _context19.next = 8;
2526
+ _context19.next = 12;
2526
2527
  break;
2527
2528
  }
2528
2529
 
@@ -2536,14 +2537,25 @@ var CozyClient = /*#__PURE__*/function () {
2536
2537
  token: credentials.token,
2537
2538
  scope: credentials.token.scope
2538
2539
  };
2539
- return _context19.abrupt("return", new CozyClient(_objectSpread(_objectSpread({
2540
+ client = new CozyClient(_objectSpread(_objectSpread({
2540
2541
  uri: oldClient._url
2541
- }, oauthOptions), options)));
2542
+ }, oauthOptions), options));
2542
2543
 
2543
- case 8:
2544
- throw new Error('Cannot instantiate a new client: old client is not an OAuth client. CozyClient.fromOldClient might be more suitable.');
2544
+ if (!client.loginPromise) {
2545
+ _context19.next = 9;
2546
+ break;
2547
+ }
2548
+
2549
+ _context19.next = 9;
2550
+ return client.loginPromise;
2545
2551
 
2546
2552
  case 9:
2553
+ return _context19.abrupt("return", client);
2554
+
2555
+ case 12:
2556
+ throw new Error('Cannot instantiate a new client: old client is not an OAuth client. CozyClient.fromOldClient might be more suitable.');
2557
+
2558
+ case 13:
2547
2559
  case "end":
2548
2560
  return _context19.stop();
2549
2561
  }
@@ -2644,7 +2656,7 @@ var CozyClient = /*#__PURE__*/function () {
2644
2656
  CozyClient.hooks = CozyClient.hooks || {};
2645
2657
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2646
2658
 
2647
- CozyClient.version = "34.6.3";
2659
+ CozyClient.version = "34.6.4";
2648
2660
 
2649
2661
  _microee.default.mixin(CozyClient);
2650
2662
 
@@ -576,6 +576,10 @@ describe('CozyClient logout', () => {
576
576
  })
577
577
 
578
578
  it('should reset the redux state', async () => {
579
+ stackClient = {
580
+ fetch: jest.fn(),
581
+ on: jest.fn()
582
+ }
579
583
  client = new CozyClient({
580
584
  links,
581
585
  stackClient,
@@ -31,6 +31,13 @@ var collectionMock = {
31
31
  all: jest.fn(function () {
32
32
  return Promise.resolve();
33
33
  }),
34
+ // needed because we call it inside the CozyClient constructor
35
+ // so we can't define it during the test
36
+ get: jest.fn(function () {
37
+ return Promise.resolve({
38
+ data: []
39
+ });
40
+ }),
34
41
  find: jest.fn(function () {
35
42
  return Promise.resolve();
36
43
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "34.6.3",
3
+ "version": "34.6.4",
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": "e5116f9e96d80328a10ac2ad71e8a292831d944e"
76
+ "gitHead": "3e09f987a419949c27bc750cf6c94bcfa70a1bef"
77
77
  }
@@ -146,6 +146,7 @@ declare class CozyClient {
146
146
  */
147
147
  constructor(rawOptions?: ClientOptions);
148
148
  appMetadata: any;
149
+ loginPromise: Promise<void>;
149
150
  options: {
150
151
  client?: object;
151
152
  token?: Token;
@@ -183,10 +184,6 @@ declare class CozyClient {
183
184
  */
184
185
  capabilities: ClientCapabilities;
185
186
  plugins: {};
186
- /**
187
- * @type {object}
188
- */
189
- storeAccesors: object;
190
187
  /**
191
188
  * Holds in-flight promises for deduplication purpose
192
189
  *
@@ -194,6 +191,10 @@ declare class CozyClient {
194
191
  * @type {PromiseCache}
195
192
  */
196
193
  private _promiseCache;
194
+ /**
195
+ * @type {object}
196
+ */
197
+ storeAccesors: object;
197
198
  /**
198
199
  * Gets overrided by MicroEE.mixin
199
200
  * This is here just so typescript does not scream
@@ -275,7 +276,6 @@ declare class CozyClient {
275
276
  token: string;
276
277
  uri: string;
277
278
  }): Promise<any>;
278
- loginPromise: Promise<void>;
279
279
  _login(options: any): Promise<void>;
280
280
  isRevoked: boolean;
281
281
  /**
@@ -4,6 +4,9 @@ export class OAuthClient extends OAuthClient_base {
4
4
  constructor(opts: any);
5
5
  collection: jest.Mock<{
6
6
  all: jest.Mock<Promise<void>, []>;
7
+ get: jest.Mock<Promise<{
8
+ data: any[];
9
+ }>, []>;
7
10
  find: jest.Mock<Promise<void>, []>;
8
11
  create: jest.Mock<Promise<void>, []>;
9
12
  update: jest.Mock<Promise<void>, []>;
@@ -19,6 +22,9 @@ declare class MockedStackClient extends MockedStackClient_base {
19
22
  constructor(opts: any);
20
23
  collection: jest.Mock<{
21
24
  all: jest.Mock<Promise<void>, []>;
25
+ get: jest.Mock<Promise<{
26
+ data: any[];
27
+ }>, []>;
22
28
  find: jest.Mock<Promise<void>, []>;
23
29
  create: jest.Mock<Promise<void>, []>;
24
30
  update: jest.Mock<Promise<void>, []>;