cozy-client 42.2.0 → 43.0.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.
@@ -2703,7 +2703,7 @@ var CozyClient = /*#__PURE__*/function () {
2703
2703
  CozyClient.hooks = CozyClient.hooks || {};
2704
2704
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
2705
2705
 
2706
- CozyClient.version = "42.2.0";
2706
+ CozyClient.version = "43.0.0";
2707
2707
 
2708
2708
  _microee.default.mixin(CozyClient);
2709
2709
 
@@ -297,10 +297,7 @@ var wellKnownUrl = function wellKnownUrl(url) {
297
297
  * Cozy's root or to a specifc slug. The caller is responsible to handle that exception
298
298
  * - another status means there aren't any Cozy behind to the given origin
299
299
  *
300
- * @param {object} url Object of URL elements
301
- * @param {string} url.protocol Protocol to use in the origin (e.g. http)
302
- * @param {string} url.hostname Hostname to use in the origin (e.g. claude.mycozy.cloud)
303
- * @param {string} url.port Port to use in the origin (e.g. 8080)
300
+ * @param {URL} url URL to validate
304
301
  *
305
302
  * @returns {Promise<boolean>} True if we believe there's a Cozy behind the given origin
306
303
  * @throws {InvalidCozyUrlError} Thrown when we know for sure there aren't any Cozy behind the given origin
@@ -310,7 +307,7 @@ var wellKnownUrl = function wellKnownUrl(url) {
310
307
 
311
308
  var isValidOrigin = /*#__PURE__*/function () {
312
309
  var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(url) {
313
- var response, status;
310
+ var response, status, responseUri, wasRedirected;
314
311
  return _regenerator.default.wrap(function _callee$(_context) {
315
312
  while (1) {
316
313
  switch (_context.prev = _context.next) {
@@ -320,7 +317,7 @@ var isValidOrigin = /*#__PURE__*/function () {
320
317
 
321
318
  case 2:
322
319
  response = _context.sent;
323
- status = response.status;
320
+ status = response.status, responseUri = response.url;
324
321
 
325
322
  if (!(status === 404)) {
326
323
  _context.next = 6;
@@ -342,9 +339,10 @@ var isValidOrigin = /*#__PURE__*/function () {
342
339
  throw new BlockedCozyError(url);
343
340
 
344
341
  case 10:
345
- return _context.abrupt("return", status === 200);
342
+ wasRedirected = url.origin !== new URL(responseUri).origin;
343
+ return _context.abrupt("return", status === 200 && !wasRedirected);
346
344
 
347
- case 11:
345
+ case 12:
348
346
  case "end":
349
347
  return _context.stop();
350
348
  }
@@ -401,7 +399,7 @@ var isValidOrigin = /*#__PURE__*/function () {
401
399
 
402
400
  var rootCozyUrl = /*#__PURE__*/function () {
403
401
  var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(url) {
404
- var _url$hostname$split, _url$hostname$split2, subDomain, domain, _hostname, hostname;
402
+ var _url$hostname$split, _url$hostname$split2, subDomain, domain, _hostname, noSlugUrl, hostname, noSubUrl;
405
403
 
406
404
  return _regenerator.default.wrap(function _callee2$(_context2) {
407
405
  while (1) {
@@ -424,62 +422,60 @@ var rootCozyUrl = /*#__PURE__*/function () {
424
422
  break;
425
423
  }
426
424
 
427
- return _context2.abrupt("return", url);
425
+ return _context2.abrupt("return", new URL(uri({
426
+ protocol: url.protocol,
427
+ hostname: url.hostname,
428
+ port: url.port
429
+ })));
428
430
 
429
431
  case 6:
430
432
  if (!/^[^.-][^.]+-[^.-]+\./.test(url.hostname)) {
431
- _context2.next = 13;
433
+ _context2.next = 14;
432
434
  break;
433
435
  }
434
436
 
435
437
  _url$hostname$split = url.hostname.split('.'), _url$hostname$split2 = (0, _toArray2.default)(_url$hostname$split), subDomain = _url$hostname$split2[0], domain = _url$hostname$split2.slice(1);
436
438
  _hostname = [subDomain.replace(/-.+/, '')].concat((0, _toConsumableArray2.default)(domain)).join('.');
437
- _context2.next = 11;
438
- return isValidOrigin({
439
+ noSlugUrl = new URL(uri({
439
440
  protocol: url.protocol,
440
441
  hostname: _hostname,
441
442
  port: url.port
442
- });
443
+ }));
444
+ _context2.next = 12;
445
+ return isValidOrigin(noSlugUrl);
443
446
 
444
- case 11:
447
+ case 12:
445
448
  if (!_context2.sent) {
446
- _context2.next = 13;
449
+ _context2.next = 14;
447
450
  break;
448
451
  }
449
452
 
450
- return _context2.abrupt("return", new URL(uri({
451
- protocol: url.protocol,
452
- hostname: _hostname,
453
- port: url.port
454
- })));
453
+ return _context2.abrupt("return", noSlugUrl);
455
454
 
456
- case 13:
455
+ case 14:
457
456
  // Try to remove the first sub-domain in case its a nested app name
458
457
  // eslint-disable-next-line no-unused-vars
459
458
  hostname = url.hostname.split('.').splice(1).join('.');
460
- _context2.next = 16;
461
- return isValidOrigin({
459
+ noSubUrl = new URL(uri({
462
460
  protocol: url.protocol,
463
461
  hostname: hostname,
464
462
  port: url.port
465
- });
463
+ }));
464
+ _context2.next = 18;
465
+ return isValidOrigin(noSubUrl);
466
466
 
467
- case 16:
467
+ case 18:
468
468
  if (!_context2.sent) {
469
- _context2.next = 18;
469
+ _context2.next = 20;
470
470
  break;
471
471
  }
472
472
 
473
- return _context2.abrupt("return", new URL(uri({
474
- protocol: url.protocol,
475
- hostname: hostname,
476
- port: url.port
477
- })));
473
+ return _context2.abrupt("return", noSubUrl);
478
474
 
479
- case 18:
475
+ case 20:
480
476
  throw new InvalidCozyUrlError(url);
481
477
 
482
- case 19:
478
+ case 21:
483
479
  case "end":
484
480
  return _context2.stop();
485
481
  }
@@ -205,65 +205,88 @@ describe('rootCozyUrl', () => {
205
205
  fetch.mockOnceIf(
206
206
  'https://camillenimbus.mycozy.cloud/.well-known/change-password',
207
207
  {},
208
- { status: 200 }
208
+ {
209
+ status: 200,
210
+ url: 'https://camillenimbus.mycozy.cloud/.well-known/change-password'
211
+ }
209
212
  )
210
213
 
211
214
  await expect(
212
215
  rootCozyUrl(new URL('https://camillenimbus.mycozy.cloud'))
213
- ).resolves.toEqual(new URL('https://camillenimbus.mycozy.cloud'))
216
+ ).resolves.toHaveProperty('href', 'https://camillenimbus.mycozy.cloud/')
214
217
  })
215
218
 
216
219
  it('should handle cozy-hosted https trailing slash', async () => {
217
220
  fetch.mockOnceIf(
218
221
  'https://camillenimbus.mycozy.cloud/.well-known/change-password',
219
222
  {},
220
- { status: 200 }
223
+ {
224
+ status: 200,
225
+ url: 'https://camillenimbus.mycozy.cloud/.well-known/change-password'
226
+ }
221
227
  )
222
228
 
223
229
  await expect(
224
230
  rootCozyUrl(new URL('https://camillenimbus.mycozy.cloud/'))
225
- ).resolves.toEqual(new URL('https://camillenimbus.mycozy.cloud'))
231
+ ).resolves.toHaveProperty('href', 'https://camillenimbus.mycozy.cloud/')
226
232
  })
227
233
 
228
234
  it('should handle cozy-hosted https trailing path', async () => {
229
235
  fetch.mockOnceIf(
230
236
  'https://camillenimbus.mycozy.cloud/.well-known/change-password',
231
237
  {},
232
- { status: 200 }
238
+ {
239
+ status: 200,
240
+ url: 'https://camillenimbus.mycozy.cloud/.well-known/change-password'
241
+ }
233
242
  )
234
243
 
235
244
  await expect(
236
245
  rootCozyUrl(new URL('https://camillenimbus.mycozy.cloud/some-path'))
237
- ).resolves.toEqual(new URL('https://camillenimbus.mycozy.cloud'))
246
+ ).resolves.toHaveProperty('href', 'https://camillenimbus.mycozy.cloud/')
238
247
  })
239
248
 
240
249
  it('should handle cozy-hosted drive web app url', async () => {
241
250
  fetch.mockOnceIf(
242
251
  'https://camillenimbus-drive.mycozy.cloud/.well-known/change-password',
243
252
  {},
244
- { status: 401 }
253
+ {
254
+ status: 401,
255
+ url:
256
+ 'https://camillenimbus-drive.mycozy.cloud/.well-known/change-password'
257
+ }
245
258
  )
246
259
  fetch.mockOnceIf(
247
260
  'https://camillenimbus.mycozy.cloud/.well-known/change-password',
248
261
  {},
249
- { status: 200 }
262
+ {
263
+ status: 200,
264
+ url: 'https://camillenimbus.mycozy.cloud/.well-known/change-password'
265
+ }
250
266
  )
251
267
 
252
268
  await expect(
253
269
  rootCozyUrl(new URL('https://camillenimbus-drive.mycozy.cloud/#/folder'))
254
- ).resolves.toEqual(new URL('https://camillenimbus.mycozy.cloud'))
270
+ ).resolves.toHaveProperty('href', 'https://camillenimbus.mycozy.cloud/')
255
271
  })
256
272
 
257
273
  it('should handle cozy-hosted photos album url', async () => {
258
274
  fetch.mockOnceIf(
259
275
  'https://camillenimbus-photos.mycozy.cloud/.well-known/change-password',
260
276
  {},
261
- { status: 401 }
277
+ {
278
+ status: 401,
279
+ url:
280
+ 'https://camillenimbus-photos.mycozy.cloud/.well-known/change-password'
281
+ }
262
282
  )
263
283
  fetch.mockOnceIf(
264
284
  'https://camillenimbus.mycozy.cloud/.well-known/change-password',
265
285
  {},
266
- { status: 200 }
286
+ {
287
+ status: 200,
288
+ url: 'https://camillenimbus.mycozy.cloud/.well-known/change-password'
289
+ }
267
290
  )
268
291
 
269
292
  await expect(
@@ -272,36 +295,73 @@ describe('rootCozyUrl', () => {
272
295
  'https://camillenimbus-photos.mycozy.cloud/#/albums/68b5cda502ae29f5fa73fd89f1be4f92'
273
296
  )
274
297
  )
275
- ).resolves.toEqual(new URL('https://camillenimbus.mycozy.cloud'))
298
+ ).resolves.toHaveProperty('href', 'https://camillenimbus.mycozy.cloud/')
276
299
  })
277
300
 
278
301
  it('should handle cozy-hosted app name', async () => {
279
302
  fetch.mockOnceIf(
280
303
  'https://camillenimbus-drive.mycozy.cloud/.well-known/change-password',
281
304
  {},
282
- { status: 401 }
305
+ {
306
+ status: 401,
307
+ url:
308
+ 'https://camillenimbus-drive.mycozy.cloud/.well-known/change-password'
309
+ }
283
310
  )
284
311
  fetch.mockOnceIf(
285
312
  'https://camillenimbus.mycozy.cloud/.well-known/change-password',
286
313
  {},
287
- { status: 200 }
314
+ {
315
+ status: 200,
316
+ url: 'https://camillenimbus.mycozy.cloud/.well-known/change-password'
317
+ }
288
318
  )
289
319
 
290
320
  await expect(
291
321
  rootCozyUrl(new URL('https://camillenimbus-drive.mycozy.cloud'))
292
- ).resolves.toEqual(new URL('https://camillenimbus.mycozy.cloud'))
322
+ ).resolves.toHaveProperty('href', 'https://camillenimbus.mycozy.cloud/')
323
+ })
324
+
325
+ it('should handle cozy-hosted special app name', async () => {
326
+ // XXX: `cozy-stack` redirects requests for deprecated apps (e.g.
327
+ // `onboarding`) to the Home app (via the login page if the user is not
328
+ // logged in).
329
+ fetch.mockOnceIf(
330
+ 'https://camillenimbus-onboarding.mycozy.cloud/.well-known/change-password',
331
+ {},
332
+ {
333
+ status: 200,
334
+ url:
335
+ 'https://camillenimbus.mycozy.cloud/auth/login?redirect=https%3A%2F%2Fcamillenimbus-home.mycozy.cloud%2F'
336
+ }
337
+ )
338
+ fetch.mockOnceIf(
339
+ 'https://camillenimbus.mycozy.cloud/.well-known/change-password',
340
+ {},
341
+ {
342
+ status: 200,
343
+ url: 'https://camillenimbus.mycozy.cloud/.well-known/change-password'
344
+ }
345
+ )
346
+
347
+ await expect(
348
+ rootCozyUrl(new URL('https://camillenimbus-onboarding.mycozy.cloud'))
349
+ ).resolves.toHaveProperty('href', 'https://camillenimbus.mycozy.cloud/')
293
350
  })
294
351
 
295
352
  it('should handle self-hosted https', async () => {
296
353
  fetch.mockOnceIf(
297
354
  'https://camillenimbus.com/.well-known/change-password',
298
355
  {},
299
- { status: 200 }
356
+ {
357
+ status: 200,
358
+ url: 'https://camillenimbus.com/.well-known/change-password'
359
+ }
300
360
  )
301
361
 
302
362
  await expect(
303
363
  rootCozyUrl(new URL('https://camillenimbus.com'))
304
- ).resolves.toEqual(new URL('https://camillenimbus.com'))
364
+ ).resolves.toHaveProperty('href', 'https://camillenimbus.com/')
305
365
  })
306
366
 
307
367
  it('should handle self-hosted with dash', async () => {
@@ -309,13 +369,14 @@ describe('rootCozyUrl', () => {
309
369
  'https://camille-nimbus.com/.well-known/change-password',
310
370
  {},
311
371
  {
312
- status: 200
372
+ status: 200,
373
+ url: 'https://camille-nimbus.com/.well-known/change-password'
313
374
  }
314
375
  )
315
376
 
316
377
  await expect(
317
378
  rootCozyUrl(new URL('https://camille-nimbus.com'))
318
- ).resolves.toEqual(new URL('https://camille-nimbus.com'))
379
+ ).resolves.toHaveProperty('href', 'https://camille-nimbus.com/')
319
380
  })
320
381
 
321
382
  it('should handle self-hosted http', async () => {
@@ -323,13 +384,14 @@ describe('rootCozyUrl', () => {
323
384
  'http://camille-nimbus.com/.well-known/change-password',
324
385
  {},
325
386
  {
326
- status: 200
387
+ status: 200,
388
+ url: 'http://camille-nimbus.com/.well-known/change-password'
327
389
  }
328
390
  )
329
391
 
330
392
  await expect(
331
393
  rootCozyUrl(new URL('http://camille-nimbus.com'))
332
- ).resolves.toEqual(new URL('http://camille-nimbus.com'))
394
+ ).resolves.toHaveProperty('href', 'http://camille-nimbus.com/')
333
395
  })
334
396
 
335
397
  it('should handle self-hosted https with port', async () => {
@@ -337,13 +399,14 @@ describe('rootCozyUrl', () => {
337
399
  'https://camillenimbus.com:666/.well-known/change-password',
338
400
  {},
339
401
  {
340
- status: 200
402
+ status: 200,
403
+ url: 'https://camillenimbus.com:666/.well-known/change-password'
341
404
  }
342
405
  )
343
406
 
344
407
  await expect(
345
408
  rootCozyUrl(new URL('https://camillenimbus.com:666'))
346
- ).resolves.toEqual(new URL('https://camillenimbus.com:666'))
409
+ ).resolves.toHaveProperty('href', 'https://camillenimbus.com:666/')
347
410
  })
348
411
 
349
412
  it('should handle self-hosted nested drive web app url', async () => {
@@ -351,20 +414,22 @@ describe('rootCozyUrl', () => {
351
414
  'https://drive.camillenimbus.com/.well-known/change-password',
352
415
  {},
353
416
  {
354
- status: 401
417
+ status: 401,
418
+ url: 'https://drive.camillenimbus.com/.well-known/change-password'
355
419
  }
356
420
  )
357
421
  fetch.mockOnceIf(
358
422
  'https://camillenimbus.com/.well-known/change-password',
359
423
  {},
360
424
  {
361
- status: 200
425
+ status: 200,
426
+ url: 'https://camillenimbus.com/.well-known/change-password'
362
427
  }
363
428
  )
364
429
 
365
430
  await expect(
366
431
  rootCozyUrl(new URL('https://drive.camillenimbus.com/#/folder'))
367
- ).resolves.toEqual(new URL('https://camillenimbus.com'))
432
+ ).resolves.toHaveProperty('href', 'https://camillenimbus.com/')
368
433
  })
369
434
 
370
435
  it('should handle self-hosted flat drive web app url', async () => {
@@ -372,26 +437,36 @@ describe('rootCozyUrl', () => {
372
437
  'https://camille-drive.nimbus.com/.well-known/change-password',
373
438
  {},
374
439
  {
375
- status: 401
440
+ status: 401,
441
+ url: 'https://camille-drive.nimbus.com/.well-known/change-password'
376
442
  }
377
443
  )
378
444
  fetch.mockOnceIf(
379
445
  'https://camille.nimbus.com/.well-known/change-password',
380
446
  {},
381
447
  {
382
- status: 200
448
+ status: 200,
449
+ url: 'https://camille.nimbus.com/.well-known/change-password'
383
450
  }
384
451
  )
385
452
 
386
453
  await expect(
387
454
  rootCozyUrl(new URL('https://camille-drive.nimbus.com/#/folder'))
388
- ).resolves.toEqual(new URL('https://camille.nimbus.com'))
455
+ ).resolves.toHaveProperty('href', 'https://camille.nimbus.com/')
389
456
  })
390
457
 
391
458
  it('should handle cozy.localhost', async () => {
459
+ fetch.mockOnceIf(
460
+ 'http://cozy.localhost:8080/.well-known/change-password',
461
+ {},
462
+ {
463
+ status: 200,
464
+ url: 'http://cozy.localhost:8080/.well-known/change-password'
465
+ }
466
+ )
392
467
  await expect(
393
468
  rootCozyUrl(new URL('http://cozy.localhost:8080'))
394
- ).resolves.toEqual(new URL('http://cozy.localhost:8080'))
469
+ ).resolves.toHaveProperty('href', 'http://cozy.localhost:8080/')
395
470
  })
396
471
 
397
472
  it('expects an http or https protocol', async () => {
@@ -399,7 +474,8 @@ describe('rootCozyUrl', () => {
399
474
  'ftp://camillenimbus.com/.well-known/change-password',
400
475
  {},
401
476
  {
402
- status: 200
477
+ status: 200,
478
+ url: 'ftp://camillenimbus.com/.well-known/change-password'
403
479
  }
404
480
  )
405
481
 
@@ -413,7 +489,8 @@ describe('rootCozyUrl', () => {
413
489
  'https://missing.mycozy.cloud/.well-known/change-password',
414
490
  {},
415
491
  {
416
- status: 404
492
+ status: 404,
493
+ url: 'https://missing.mycozy.cloud/.well-known/change-password'
417
494
  }
418
495
  )
419
496
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "42.2.0",
3
+ "version": "43.0.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -18,7 +18,7 @@
18
18
  "@types/jest": "^26.0.20",
19
19
  "@types/lodash": "^4.14.170",
20
20
  "btoa": "^1.2.1",
21
- "cozy-stack-client": "^42.0.1",
21
+ "cozy-stack-client": "^43.0.0",
22
22
  "date-fns": "2.29.3",
23
23
  "json-stable-stringify": "^1.0.1",
24
24
  "lodash": "^4.17.13",
@@ -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": "9c7fe8079758eb097916eaa2fe847d8730605021"
78
+ "gitHead": "5718d4351b1e258cfa829f487ee2c08bf6000f8c"
79
79
  }