cozy-client 27.0.0 → 27.0.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.
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
+ ## [27.0.1](https://github.com/cozy/cozy-client/compare/v27.0.0...v27.0.1) (2021-11-04)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Build new OAuth client from old OAuth client ([a8ecfd0](https://github.com/cozy/cozy-client/commit/a8ecfd0344d86ba7c45e2589442bb836ba274a89))
12
+
13
+
14
+
15
+
16
+
6
17
  # [27.0.0](https://github.com/cozy/cozy-client/compare/v26.0.2...v27.0.0) (2021-11-03)
7
18
 
8
19
  **Note:** Version bump only for package cozy-client
@@ -360,6 +360,7 @@ var CozyClient = /*#__PURE__*/function () {
360
360
  * a client with a cookie-based instance of cozy-client-js.
361
361
  *
362
362
  * @param {OldCozyClient} oldClient - An instance of the deprecated cozy-client
363
+ * @param {object} options - CozyStackClient options
363
364
  * @returns {CozyClient}
364
365
  */
365
366
 
@@ -2276,7 +2277,8 @@ var CozyClient = /*#__PURE__*/function () {
2276
2277
  *
2277
2278
  * Warning: unlike other instantiators, this one needs to be awaited.
2278
2279
  *
2279
- * @param {OldCozyClient} oldClient - An instance of the deprecated cozy-client
2280
+ * @param {OldCozyClient} oldClient - An OAuth instance of the deprecated cozy-client
2281
+ * @param {object} options - CozyStackClient options
2280
2282
  * @returns {Promise<CozyClient>} An instance of a client, configured from the old client
2281
2283
  */
2282
2284
 
@@ -2284,30 +2286,32 @@ var CozyClient = /*#__PURE__*/function () {
2284
2286
  key: "fromOldOAuthClient",
2285
2287
  value: function () {
2286
2288
  var _fromOldOAuthClient = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee17(oldClient, options) {
2287
- var hasOauthCreds, token;
2289
+ var credentials, oauthOptions;
2288
2290
  return _regenerator.default.wrap(function _callee17$(_context17) {
2289
2291
  while (1) {
2290
2292
  switch (_context17.prev = _context17.next) {
2291
2293
  case 0:
2292
- hasOauthCreds = oldClient._oauth && oldClient._authcreds != null;
2293
-
2294
- if (!hasOauthCreds) {
2294
+ if (!oldClient._oauth) {
2295
2295
  _context17.next = 8;
2296
2296
  break;
2297
2297
  }
2298
2298
 
2299
- _context17.next = 4;
2300
- return oldClient._authcreds;
2299
+ _context17.next = 3;
2300
+ return oldClient.authorize();
2301
2301
 
2302
- case 4:
2303
- token = _context17.sent.token;
2304
- return _context17.abrupt("return", new CozyClient(_objectSpread({
2305
- uri: oldClient._url,
2306
- token: token
2307
- }, options)));
2302
+ case 3:
2303
+ credentials = _context17.sent;
2304
+ oauthOptions = {
2305
+ oauth: credentials.client,
2306
+ token: credentials.token,
2307
+ scope: credentials.token.scope
2308
+ };
2309
+ return _context17.abrupt("return", new CozyClient(_objectSpread(_objectSpread({
2310
+ uri: oldClient._url
2311
+ }, oauthOptions), options)));
2308
2312
 
2309
2313
  case 8:
2310
- throw new Error('Old client does not have _oauth or _authcreds, cannot instantiate a new client, check if CozyClient.fromOldClient is more suitable');
2314
+ throw new Error('Cannot instantiate a new client: old client is not an OAuth client. CozyClient.fromOldClient might be more suitable.');
2311
2315
 
2312
2316
  case 9:
2313
2317
  case "end":
@@ -2411,7 +2415,7 @@ var CozyClient = /*#__PURE__*/function () {
2411
2415
  CozyClient.hooks = CozyClient.hooks || {};
2412
2416
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2413
2417
 
2414
- CozyClient.version = "27.0.0";
2418
+ CozyClient.version = "27.0.1";
2415
2419
 
2416
2420
  _microee.default.mixin(CozyClient);
2417
2421
 
@@ -143,17 +143,30 @@ describe('CozyClient initialization', () => {
143
143
  it('can be instantiated from an oauth-based old client', async () => {
144
144
  // Not using a real cozy-client-js here not to have to add it as a dep
145
145
  const url = 'https://testcozy.mycozy.cloud'
146
- const token = 'Registration-token'
146
+ const oauth = {
147
+ clientID: 'my-client'
148
+ // ... other OAuth client attributes
149
+ }
150
+ const token = {
151
+ tokenType: 'bearer',
152
+ accessToken: 'access-token',
153
+ refreshToken: 'refresh-token',
154
+ scope: ['io.cozy.files']
155
+ }
147
156
  const oldClient = {
148
157
  _url: url,
149
158
  _oauth: true,
150
- _authcreds: Promise.resolve({
159
+ authorize: () => ({
160
+ client: oauth,
151
161
  token
152
162
  })
153
163
  }
154
164
  const client = await CozyClient.fromOldOAuthClient(oldClient)
165
+ console.log({ stackClient: client.stackClient })
155
166
  expect(client.stackClient.uri).toBe(url)
156
- expect(client.stackClient.token.token).toBe(token)
167
+ expect(client.stackClient.oauthOptions.clientID).toBe(oauth.clientID)
168
+ expect(client.stackClient.token.accessToken).toBe(token.accessToken)
169
+ expect(client.stackClient.scope).toBe(token.scope)
157
170
  })
158
171
 
159
172
  it('can be instantiated from dataset injected by the Stack in DOM', async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "27.0.0",
3
+ "version": "27.0.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -68,5 +68,5 @@
68
68
  "react-native-inappbrowser-reborn": "^3.5.1"
69
69
  },
70
70
  "sideEffects": false,
71
- "gitHead": "eb3e306e97d0447509e8ac6a3f1012c2e1070a04"
71
+ "gitHead": "0179286fb1df8e6c1999010f5233dc0deeb6472c"
72
72
  }
@@ -61,19 +61,21 @@ declare class CozyClient {
61
61
  * a client with a cookie-based instance of cozy-client-js.
62
62
  *
63
63
  * @param {OldCozyClient} oldClient - An instance of the deprecated cozy-client
64
+ * @param {object} options - CozyStackClient options
64
65
  * @returns {CozyClient}
65
66
  */
66
- static fromOldClient(oldClient: OldCozyClient, options: any): CozyClient;
67
+ static fromOldClient(oldClient: OldCozyClient, options: object): CozyClient;
67
68
  /**
68
69
  * To help with the transition from cozy-client-js to cozy-client, it is possible to instantiate
69
70
  * a client with an OAuth-based instance of cozy-client-js.
70
71
  *
71
72
  * Warning: unlike other instantiators, this one needs to be awaited.
72
73
  *
73
- * @param {OldCozyClient} oldClient - An instance of the deprecated cozy-client
74
+ * @param {OldCozyClient} oldClient - An OAuth instance of the deprecated cozy-client
75
+ * @param {object} options - CozyStackClient options
74
76
  * @returns {Promise<CozyClient>} An instance of a client, configured from the old client
75
77
  */
76
- static fromOldOAuthClient(oldClient: OldCozyClient, options: any): Promise<CozyClient>;
78
+ static fromOldOAuthClient(oldClient: OldCozyClient, options: object): Promise<CozyClient>;
77
79
  /**
78
80
  * In konnector/service context, CozyClient can be instantiated from
79
81
  * environment variables