cozy-pouch-link 53.2.1 → 54.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.
@@ -7,7 +7,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
- exports.default = exports.isExpiredTokenError = exports.getReplicationURL = void 0;
10
+ exports.default = exports.getReplicationURL = void 0;
11
11
 
12
12
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
13
 
@@ -61,6 +61,8 @@ var _platformWeb = require("./platformWeb");
61
61
 
62
62
  var _utils = require("./utils");
63
63
 
64
+ var _errors = require("./errors");
65
+
64
66
  function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
65
67
 
66
68
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -115,14 +117,6 @@ var doNothing = function doNothing(operation) {
115
117
  var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
116
118
  };
117
119
 
118
- var expiredTokenError = /Expired token/;
119
-
120
- var isExpiredTokenError = function isExpiredTokenError(pouchError) {
121
- return expiredTokenError.test(pouchError.error);
122
- };
123
-
124
- exports.isExpiredTokenError = isExpiredTokenError;
125
-
126
120
  var normalizeAll = function normalizeAll(client) {
127
121
  return function (docs, doctype) {
128
122
  return docs.map(function (doc) {
@@ -632,7 +626,7 @@ var PouchLink = /*#__PURE__*/function (_CozyLink) {
632
626
  while (1) {
633
627
  switch (_context5.prev = _context5.next) {
634
628
  case 0:
635
- if (!isExpiredTokenError(error)) {
629
+ if (!(0, _errors.isExpiredTokenError)(error)) {
636
630
  _context5.next = 14;
637
631
  break;
638
632
  }
package/dist/errors.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isExpiredTokenError = void 0;
7
+ var EXPIRED_TOKEN_ERROR = /Expired token/;
8
+ var INVALID_TOKEN_ERROR = /Invalid JWT token/;
9
+ var INVALID_TOKEN_ALT_ERROR = /Invalid token/;
10
+
11
+ var expiredTokenError = function expiredTokenError(error) {
12
+ var errorMsg = error.message;
13
+ var errorName = error.name;
14
+ return EXPIRED_TOKEN_ERROR.test(errorMsg) || EXPIRED_TOKEN_ERROR.test(errorName) || INVALID_TOKEN_ERROR.test(errorMsg) || INVALID_TOKEN_ERROR.test(errorName) || INVALID_TOKEN_ALT_ERROR.test(errorMsg) || INVALID_TOKEN_ALT_ERROR.test(errorName);
15
+ };
16
+
17
+ var isExpiredTokenError = function isExpiredTokenError(error) {
18
+ // @ts-ignore
19
+ // eslint-disable-next-line no-undef
20
+ if (error instanceof AggregateError) {
21
+ return error.errors.some(function (err) {
22
+ return expiredTokenError(err);
23
+ });
24
+ }
25
+
26
+ return expiredTokenError(error);
27
+ };
28
+
29
+ exports.isExpiredTokenError = isExpiredTokenError;
package/dist/utils.js CHANGED
@@ -34,7 +34,7 @@ exports.getPrefix = getPrefix;
34
34
 
35
35
  var formatAggregatedError = function formatAggregatedError(aggregatedError) {
36
36
  var strings = aggregatedError.errors.map(function (e, index) {
37
- return '\n[' + index + ']: ' + e.message + '\n' + e.stack;
37
+ return '\n[' + index + ']: ' + e.name + ' - ' + e.message + '\n' + e.stack;
38
38
  });
39
39
  return strings.join('\n');
40
40
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-pouch-link",
3
- "version": "53.2.1",
3
+ "version": "54.0.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "url": "git+https://github.com/cozy/cozy-client.git"
14
14
  },
15
15
  "dependencies": {
16
- "cozy-client": "^53.2.0",
16
+ "cozy-client": "^54.0.0",
17
17
  "pouchdb-browser": "^7.2.2",
18
18
  "pouchdb-find": "^7.2.2"
19
19
  },
@@ -39,5 +39,5 @@
39
39
  "typecheck": "tsc -p tsconfig.json"
40
40
  },
41
41
  "sideEffects": false,
42
- "gitHead": "3dcda5036014bb6dc64165eb4adea0491a595d58"
42
+ "gitHead": "31f3124443f8fc9b9d2a73a6f23326e726f9dc9c"
43
43
  }
@@ -1,5 +1,4 @@
1
1
  export function getReplicationURL(uri: any, token: any, doctype: any): string;
2
- export function isExpiredTokenError(pouchError: any): boolean;
3
2
  export default PouchLink;
4
3
  export type CozyClientDocument = any;
5
4
  export type ReplicationStatus = "idle" | "replicating";
@@ -0,0 +1 @@
1
+ export function isExpiredTokenError(error: any): any;