From add4dd8a70e4e1afd654f84cae6a558ac0a7c3d5 Mon Sep 17 00:00:00 2001 From: or-else Date: Sat, 10 Jul 2021 14:09:10 -0700 Subject: [PATCH] bump version and rebuild --- package.json | 2 +- umd/tinode.dev.js | 4 ++-- umd/tinode.prod.js | 2 +- version.json | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 989ae96..84b6b26 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tinode-sdk", "description": "Tinode SDK", - "version": "0.17.6-rc1", + "version": "0.17.6", "scripts": { "format": "js-beautify -r src/tinode.js && js-beautify -r src/drafty.js && js-beautify -r src/db.js && js-beautify -r src/connection.js && js-beautify -r src/cbuffer.js", "build": "npm run vers && npm run format && npm run build:prod && npm run build:dev", diff --git a/umd/tinode.dev.js b/umd/tinode.dev.js index 6315ffd..6b7c9d8 100644 --- a/umd/tinode.dev.js +++ b/umd/tinode.dev.js @@ -8704,9 +8704,9 @@ if (typeof module != 'undefined') { } },{"./access-mode.js":1}],10:[function(require,module,exports){ -module.exports={"version": "0.17.6-rc1"} +module.exports={"version": "0.17.6"} },{}]},{},[8])(8) }); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJzcmMvYWNjZXNzLW1vZGUuanMiLCJzcmMvY2J1ZmZlci5qcyIsInNyYy9jb25uZWN0aW9uLmpzIiwic3JjL2RiLmpzIiwic3JjL2RyYWZ0eS5qcyIsInNyYy9sYXJnZS1maWxlLmpzIiwic3JjL21ldGEtYnVpbGRlci5qcyIsInNyYy90aW5vZGUuanMiLCJzcmMvdXRpbHMuanMiLCJ2ZXJzaW9uLmpzb24iXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7QUNBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNB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NvbHZlLCByZWplY3QpIHtcbiAgICAgIGxldCBwb2xsZXIgPSBuZXcgWEhSUHJvdmlkZXIoKTtcbiAgICAgIGxldCBwcm9taXNlQ29tcGxldGVkID0gZmFsc2U7XG5cbiAgICAgIHBvbGxlci5vbnJlYWR5c3RhdGVjaGFuZ2UgPSBmdW5jdGlvbihldnQpIHtcblxuICAgICAgICBpZiAocG9sbGVyLnJlYWR5U3RhdGUgPT0gWERSX0RPTkUpIHtcbiAgICAgICAgICBpZiAocG9sbGVyLnN0YXR1cyA9PSAyMDEpIHsgLy8gMjAxID09IEhUVFAuQ3JlYXRlZCwgZ2V0IFNJRFxuICAgICAgICAgICAgbGV0IHBrdCA9IEpTT04ucGFyc2UocG9sbGVyLnJlc3BvbnNlVGV4dCwganNvblBhcnNlSGVscGVyKTtcbiAgICAgICAgICAgIF9scFVSTCA9IHVybF8gKyAnJnNpZD0nICsgcGt0LmN0cmwucGFyYW1zLnNpZFxuICAgICAgICAgICAgcG9sbGVyID0gbHBfcG9sbGVyKF9scFVSTCk7XG4gICAgICAgICAgICBwb2xsZXIuc2VuZChudWxsKVxuICAgICAgICAgICAgaWYgKGluc3RhbmNlLm9uT3Blbikge1xuICAgICAgICAgICAgICBpbnN0YW5jZS5vbk9wZW4oKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHJlc29sdmUpIHtcbiAgICAgICAgICAgICAgcHJvbWlzZUNvbXBsZXRlZCA9IHRydWU7XG4gICAgICAgICAgICAgIHJlc29sdmUoKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKGF1dG9yZWNvbm5lY3QpIHtcbiAgICAgICAgICAgICAgYm9mZlN0b3AoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9IGVsc2UgaWYgKHBvbGxlci5zdGF0dXMgPCA0MDApIHsgLy8gNDAwID0gSFRUUC5CYWRSZXF1ZXN0XG4gICAgICAgICAgICBpZiAoaW5zdGFuY2Uub25NZXNzYWdlKSB7XG4gICAgICAgICAgICAgIGluc3RhbmNlLm9uTWVzc2FnZShwb2xsZXIucmVzcG9uc2VUZXh0KVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcG9sbGVyID0gbHBfcG9sbGVyKF9scFVSTCk7XG4gICAgICAgICAgICBwb2xsZXIuc2VuZChudWxsKTtcbiAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgLy8gRG9uJ3QgdGhyb3cgYW4gZXJyb3IgaGVyZSwgZ3JhY2VmdWxseSBoYW5kbGUgc2VydmVyIGVycm9yc1xuICAgICAgICAgICAgaWYgKHJlamVjdCAmJiAhcHJvbWlzZUNvbXBsZXRlZCkge1xuICAgICAgICAgICAgICBwcm9taXNlQ29tcGxldGVkID0gdHJ1ZTtcbiAgICAgICAgICAgICAgcmVqZWN0KHBvbGxlci5yZXNwb25zZVRleHQpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgaWYgKGluc3RhbmNlLm9uTWVzc2FnZSAmJiBwb2xsZXIucmVzcG9uc2VUZXh0KSB7XG4gICAgICAgICAgICAgIGluc3RhbmNlLm9uTWVzc2FnZShwb2xsZXIucmVzcG9uc2VUZXh0KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGlmIChpbnN0YW5jZS5vbkRpc2Nvbm5lY3QpIHtcbiAgICAgICAgICAgICAgY29uc3QgY29kZSA9IHBvbGxlci5zdGF0dXMgfHwgKF9ib2ZmQ2xvc2VkID8gTkVUV09SS19VU0VSIDogTkVUV09SS19FUlJPUik7XG4gICAgICAgICAgICAgIGNvbnN0IHRleHQgPSBwb2xsZXIucmVzcG9uc2VUZXh0IHx8IChfYm9mZkNsb3NlZCA/IE5FVFdPUktfVVNFUl9URVhUIDogTkVUV09SS19FUlJPUl9URVhUKTtcbiAgICAgICAgICAgICAgaW5zdGFuY2Uub25EaXNjb25uZWN0KG5ldyBFcnJvcih0ZXh0ICsgJyAoJyArIGNvZGUgKyAnKScpLCBjb2RlKTtcbiAgICAg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CB8fCB7fTtcbiAgICBmaWVsZHMuZm9yRWFjaCgoZikgPT4ge1xuICAgICAgaWYgKG1zZy5oYXNPd25Qcm9wZXJ0eShmKSkge1xuICAgICAgICByZXNbZl0gPSBtc2dbZl07XG4gICAgICB9XG4gICAgfSk7XG4gICAgcmV0dXJuIHJlcztcbiAgfVxuXG4gIGZ1bmN0aW9uIG1hcE9iamVjdHMoc291cmNlLCBjYWxsYmFjaywgY29udGV4dCkge1xuICAgIGlmICghZGIpIHtcbiAgICAgIHJldHVybiBkaXNhYmxlZCA/XG4gICAgICAgIFByb21pc2UucmVzb2x2ZShbXSkgOlxuICAgICAgICBQcm9taXNlLnJlamVjdChuZXcgRXJyb3IoXCJub3QgaW5pdGlhbGl6ZWRcIikpO1xuICAgIH1cblxuICAgIHJldHVybiBuZXcgUHJvbWlzZSgocmVzb2x2ZSwgcmVqZWN0KSA9PiB7XG4gICAgICBjb25zdCB0cnggPSBkYi50cmFuc2FjdGlvbihbc291cmNlXSk7XG4gICAgICB0cngub25lcnJvciA9IChldmVudCkgPT4ge1xuICAgICAgICBsb2dnZXIoXCJQQ2FjaGVcIiwgXCJtYXBPYmplY3RzXCIsIHNvdXJjZSwgZXZlbnQudGFyZ2V0LmVycm9yKTtcbiAgICAgICAgcmVqZWN0KGV2ZW50LnRhcmdldC5lcnJvcik7XG4gICAgICB9O1xuICAgICAgdHJ4Lm9iamVjdFN0b3JlKHNvdXJjZSkuZ2V0QWxsKCkub25zdWNjZXNzID0gKGV2ZW50KSA9PiB7XG4gICAgICAgIGlmIChjYWxsYmFjaykge1xuICAgICAgICAgIGV2ZW50LnRhcmdldC5yZXN1bHQuZm9yRWFjaCgodG9waWMpID0+IHtcbiAgICAgICAgICAgIGNhbGxiYWNrLmNhbGwoY29udGV4dCwgdG9waWMpO1xuICAgICAgICAgIH0pO1xuICAgICAgICB9XG4gICAgICAgIHJlc29sdmUoZXZlbnQudGFyZ2V0LnJlc3VsdCk7XG4gICAgICB9O1xuICAgIH0pO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IDIgfHwgcHViID09PSB1bmRlZmluZWQpIHtcbiAgICAgICAgLy8gTm8gcG9pbnQgaW51cGRhdGluZyB1c2VyIHdpdGggaW52YWxpZCBkYXRhLlxuICAgICAgICByZXR1cm47XG4gICAgICB9XG4gICAgICBpZiAoIXRoaXMuaXNSZWFkeSgpKSB7XG4gICAgICAgIHJldHVybiBkaXNhYmxlZCA/XG4gICAgICAgICAgUHJvbWlzZS5yZXNvbHZlKCkgOlxuICAgICAgICAgIFByb21pc2UucmVqZWN0KG5ldyBFcnJvcihcIm5vdCBpbml0aWFsaXplZFwiKSk7XG4gICAgICB9XG4gICAgICByZXR1cm4gbmV3IFByb21pc2UoKHJlc29sdmUsIHJlamVjdCkgPT4ge1xuICAgICAgICBjb25zdCB0cnggPSBkYi50cmFuc2FjdGlvbihbJ3VzZXInXSwgJ3JlYWR3cml0ZScpO1xuICAgICAgICB0cngub25jb21wbGV0ZSA9IChldmVudCkgPT4ge1xuICAgICAgICAgIHJlc29sdmUoZXZlbnQudGFyZ2V0LnJlc3VsdCk7XG4gICAgICAgIH07XG4gICAgICAgIHRyeC5vbmVycm9yID0gKGV2ZW50KSA9PiB7XG4gICAgICAgICAgbG9nZ2VyKFwiUENhY2hlXCIsIFwidXBkVXNlclwiLCBldmVudC50YXJnZXQuZXJyb3IpO1xuICAgICAgICAgIHJlamVjdChldmVudC50YXJnZXQuZXJyb3IpO1xuICAgICAgICB9O1xuICAgICAgICB0cngub2JqZWN0U3RvcmUoJ3VzZXInKS5wdXQoe1xuICAgICAgICAgIHVpZDogdWlkLFxuICAgICAgICAgIHB1YmxpYzogcHViXG4gICAgICAgIH0pO1xuICAgICAgICB0cnguY29tbWl0KCk7XG4gICAgICB9KTtcbiAgICB9LFxuXG4gICAgLyoqXG4gICAgICogUmVtb3ZlIHVzZXIgZnJvbSBwZXJzaXN0ZW50IGNhY2hlLlxuICAgICAqIEBtZW1iZXJPZiBEQlxuICAgICAqIEBwYXJhbSB7c3RyaW5nfSB1aWQgL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ZWplY3QpID0+IHtcbiAgICAgICAgY29uc3QgdHJ4ID0gZGIudHJhbnNhY3Rpb24oWyd1c2VyJ10pO1xuICAgICAgICB0cngub25jb21wbGV0ZSA9IChldmVudCkgPT4ge1xuICAgICAgICAgIGNvbnN0IHVzZXIgPSBldmVudC50YXJnZXQucmVzdWx0O1xuICAgICAgICAgIHJlc29sdmUoe1xuICAgICAgICAgICAgdXNlcjogdXNlci51aWQsXG4gICAgICAgICAgICBwdWJsaWM6IHVzZXIucHVibGljXG4gICAgICAgICAgfSk7XG4gICAgICAgIH07XG4gICAgICAgIHRyeC5vbmVycm9yID0gKGV2ZW50KSA9PiB7XG4gICAgICAgICAgbG9nZ2VyKFwiUENhY2hlXCIsIFwiZ2V0VXNlclwiLCBldmVudC50YXJnZXQuZXJyb3IpO1xuICAgICAgICAgIHJlamVjdChldmVudC50YXJnZXQuZXJyb3IpO1xuICAgICAgICB9O1xuICAgICAgICB0cngub2JqZWN0U3RvcmUoJ3VzZXInKS5nZXQodWlkKTtcbiAgICAgIH0pO1xuICAgIH0sXG5cbiAgICAvLyBTdWJzY3JpcHRpb25zLlxuXG4gICAgLyoqXG4gICAgICogQWRkIG9yIHVwZGF0ZSBzdWJzY3JpcHRpb24gaW4gcGVyc2lzdGVudCBjYWNoZS5cbiAgICAgKiBAbWVtYmVyT2YgREJcbiAgICAgKiBAcGFyYW0ge3N0cmluZ30gdG9waWNOYW1lIC0gbmFtZSBvZiB0aGUgdG9waWMgd2hpY2ggb3ducyB0aGUgbWVzc2FnZS5cbiAgICAgKiBAcGFyYW0ge3N0cmluZ30gdWlkIC0gSUQgb2YgdGhlIHN1YnNjcmliZWQgdXNlci5cbiAgICAgKiBAcGFyYW0ge09iamVjdH0gc3ViIC0gc3Vic2NyaXB0aW9uIHRvIHNhdmUuXG4gICAgICogQHJldHVybiB7UHJvbWlzZX0gcHJvbWlzZSByZXNvbHZlZC9yZWplY3RlZCBvbiBvcGVyYXRpb24gY29tcGxldGlvbi5cbiAgIC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24gY29tcGxldGlvbi5cbiAgICAgKi9cbiAgICByZW1NZXNzYWdlczogZnVuY3Rpb24odG9waWNOYW1lLCBmcm9tLCB0bykge1xuICAgICAgaWYgKCF0aGlzLmlzUmVhZHkoKSkge1xuICAgICAgICByZXR1cm4gZGlzYWJsZWQgP1xuICAgICAgICAgIFByb21pc2UucmVzb2x2ZSgpIDpcbiAgICAgICAgICBQcm9taXNlLnJlamVjdChuZXcgRXJyb3IoXCJub3QgaW5pdGlhbGl6ZWRcIikpO1xuICAgICAgfVxuICAgICAgcmV0dXJuIG5ldyBQcm9taXNlKChyZXNvbHZlLCByZWplY3QpID0+IHtcbiAgICAgICAgaWYgKCFmcm9tICYmICF0bykge1xuICAgICAgICAgIGZyb20gPSAwO1xuICAgICAgICAgIHRvID0gTnVtYmVyLk1BWF9TQUZFX0lOVEVHRVI7XG4gICAgICAgIH1cbiAgICAgICAgY29uc3QgcmFuZ2UgPSB0byA+IDAgPyBJREJLZXlSYW5nZS5ib3VuZChbdG9waWNOYW1lLCBmcm9tXSwgW3RvcGljTmFtZSwgdG9dLCBmYWxzZSwgdHJ1ZSkgOlxuICAgICAgICAgIElEQktleVJhbmdlLm9ubHkoW3RvcGljTmFtZSwgZnJvbV0pO1xuICAgICAgICBjb25zdCB0cnggPSBkYi50cmFuc2FjdGlvbihbJ21lc3NhZ2UnXSwgJ3JlYWR3cml0ZScpO1xuICAgICAgICB0cngub25zdWNjZXNzID0gKGV2ZW50KSA9PiB7XG4gICAgICAgICAgcmVzb2x2ZShldmVudC50YXJnZXQucmVzdWx0KTtcbiAgICAgICAgfTtcbiAgICAgICAgdHJ4Lm9uZXJyb3IgPSAoZXZlbnQpID0+IHtcbiAgICAgICAgICBsb2dnZXIoXCJQQ2FjaGVcIiwgXCJyZW1NZXNzYWdlc1wiLCBldmVudC50YXJnZXQuZXJyb3IpO1xuICAgICAgICAgIHJlamVjdChldmVudC50YXJnZXQuZXJyb3IpO1xuICAgICAgICB9O1xuICAgICAgICB0cngub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SAoZXZlbnQpID0+IHtcbiAgICAgICAgICBjb25zdCBjdXJzb3IgPSBldmVudC50YXJnZXQucmVzdWx0O1xuICAgICAgICAgIGlmIChjdXJzb3IpIHtcbiAgICAgICAgICAgIGlmIChjYWxsYmFjaykge1xuICAgICAgICAgICAgICBjYWxsYmFjay5jYWxsKGNvbnRleHQsIGN1cnNvci52YWx1ZSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICByZXN1bHQucHVzaChjdXJzb3IudmFsdWUpO1xuICAgICAgICAgICAgaWYgKGxpbWl0IDw9IDAgfHwgcmVzdWx0Lmxlbmd0aCA8IGxpbWl0KSB7XG4gICAgICAgICAgICAgIGN1cnNvci5jb250aW51ZSgpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgcmVzb2x2ZShyZXN1bHQpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXNvbHZlKHJlc3VsdCk7XG4gICAgICAgICAgfVxuICAgICAgICB9O1xuICAgICAgfSk7XG4gICAgfVxuICB9O1xufVxuXG4vKipcbiAqIFRvIHVzZSBEQiBpbiBhIG5vbiBicm93c2VyIGNvbnRleHQsIHN1cHBseSBpbmRleGVkREIgcHJvdmlkZXIuXG4gKiBAc3RhdGljXG4gKiBAbWVtYmVyb2YgREJcbiAqIEBwYXJhbSBpZGJQcm92aWRlciBpbmRleGVkREIgcHJvdmlkZXIsIGUuZy4gZm9yIG5vZGUgPGNvZGU+cmVxdWlyZSgnZmFrZS1pbmRleGVkZGInKTwvY29kZT4uXG4gKi9cbkRCLnNldERhdGFiYXNlUHJvdmlkZXIgPSBmdW5jdGlvbihpZGJQcm92aWRlcikge1xuICBJREJQcm92aWRlciA9IGlkYlByb3ZpZGVyO1xufTtcblxuaWYgKHR5cGVvZiBtb2R1bGUgIT0gJ3VuZGVmaW5lZCcpIHtcbiAgbW9kdWxlLmV4cG9ydHMgPSBEQjtcbn1cbiIsIi8qKlxu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PSB7XG4gICAgICAgIHR4dDogZHJhZnR5LnR4dCxcbiAgICAgICAgZm10OiBkcmFmdHkuZm10XG4gICAgICB9O1xuICAgIH1cblxuICAgIC8vIEV4dHJhY3QgZW50aXRpZXMgZnJvbSB0aGUgY2xlYW5lZCB1cCBzdHJpbmcuXG4gICAgZW50aXRpZXMgPSBleHRyYWN0RW50aXRpZXMoYmxvY2sudHh0KTtcbiAgICBpZiAoZW50aXRpZXMubGVuZ3RoID4gMCkge1xuICAgICAgY29uc3QgcmFuZ2VzID0gW107XG4gICAgICBmb3IgKGxldCBpIGluIGVudGl0aWVzKSB7XG4gICAgICAgIC8vIHtvZmZzZXQ6IG1hdGNoWydpbmRleCddLCB1bmlxdWU6IG1hdGNoWzBdLCBsZW46IG1hdGNoWzBdLmxlbmd0aCwgZGF0YTogZW50LnBhY2tlcigpLCB0eXBlOiBlbnQubmFtZX1cbiAgICAgICAgY29uc3QgZW50aXR5ID0gZW50aXRpZXNbaV07XG4gICAgICAgIGxldCBpbmRleCA9IGVudGl0eUluZGV4W2VudGl0eS51bmlxdWVdO1xuICAgICAgICBpZiAoIWluZGV4KSB7XG4gICAgICAgICAgaW5kZXggPSBlbnRpdHlNYXAubGVuZ3RoO1xuICAgICAgICAgIGVudGl0eUluZGV4W2VudGl0eS51bmlxdWVdID0gaW5kZXg7XG4gICAgICAgICAgZW50aXR5TWFwLnB1c2goe1xuICAgICAgICAgICAgdHA6IGVudGl0eS50eXBlLFxuICAgICAgICAgICAgZGF0YTogZW50aXR5LmRhdGFcbiAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgICByYW5nZXMucHVzaCh7XG4gICAgICAgICAgYXQ6IGVudGl0eS5vZmZzZXQsXG4gICAgICAgICAgbGVuOiBlbnRpdHkubGVuLFxuICAgICAgICAgIGtleTogaW5kZXhcbiAgICAgICAgfSk7XG4gICAgICB9XG4gICAgICBibG9jay5lbnQgPSByYW5nZXM7XG4gICAgfVxuXG4gICAgYmx4LnB1c2goYm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gICAgICAgICAgYXQ6IHN0LmF0LFxuICAgICAgICAgIGxlbjogc3QubGVuIHwgMFxuICAgICAgICB9O1xuICAgICAgICBpZiAoc3QudHApIHtcbiAgICAgICAgICBzdHlsZS50cCA9ICcnICsgc3QudHA7XG4gICAgICAgIH0gZWxzZSBpZiAoQXJyYXkuaXNBcnJheShlbnQpICYmIGVudC5sZW5ndGggPiBzdC5rZXkgJiYgdHlwZW9mIGVudF9yZWZzW3N0LmtleV0gPT0gJ251bWJlcicpIHtcbiAgICAgICAgICBzdHlsZS5rZXkgPSBlbnRfcmVmc1tzdC5rZXldO1xuICAgICAgICAgIHByZXZpZXcuZW50W3N0eWxlLmtleV0gPSBjb3B5TGlnaHQoZW50W3N0LmtleV0pO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuICAgICAgICBwcmV2aWV3LmZtdFtmbXRfaWR4KytdID0gc3R5bGU7XG4gICAgICB9XG4gICAgfSk7XG4gIH1cblxuICByZXR1cm4gcHJldmlldztcbn1cblxuLy8gQ3JlYXRlIGEgY29weSBvZiBhbiBlbnRpdHkgd2l0aG91dCBsYXJnZSBkYXRhLlxuZnVuY3Rpb24gY29weUxpZ2h0KGVudCkge1xuICBsZXQgcmVzdWx0ID0ge1xuICAgIHRwOiBlbnQudHBcbiAgfTtcbiAgaWYgKGVudC5kYXRhICYmIE9iamVjdC5lbnRyaWVzKGVudC5kYXRhKS5sZW5ndGggIT0gMCkge1xuICAgIGNvbnN0IGRjID0ge307XG4gICAgW1wibWltZVwiLCBcIm5hbWVcIiwgXCJ3aWR0aFwiLCBcImhlaWdodFwiLCBcInNpemVcIl0uZm9yRWFjaCgoa2V5KSA9PiB7XG4gICAgICBjb25zdCB2YWwgPSBlbnQuZGF0YVtrZXldO1xuICAgICAgaWYgKHZhbCkge1xuICAgICAgICBkY1trZXldID0gdmFsO1xuICAgICAgfVxuICAgIH0pO1xuICAgIGlmIChPYmplY3QuZW50cmllcyhkY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JZCAhPSAwKSA/ICcnICsgdGhpcy5fbWVzc2FnZUlkKysgOiB1bmRlZmluZWQ7XG4gIH1cblxuICAvLyBHZXQgVXNlciBBZ2VudCBzdHJpbmdcbiAgY29uc3QgZ2V0VXNlckFnZW50ID0gKCkgPT4ge1xuICAgIHJldHVybiB0aGlzLl9hcHBOYW1lICsgJyAoJyArICh0aGlzLl9icm93c2VyID8gdGhpcy5fYnJvd3NlciArICc7ICcgOiAnJykgKyB0aGlzLl9od29zICsgJyk7ICcgKyBMSUJSQVJZO1xuICB9XG5cbiAgLy8gR2VuZXJhdG9yIG9mIHBhY2tldHMgc3R1YnNcbiAgdGhpcy5pbml0UGFja2V0ID0gKHR5cGUsIHRvcGljKSA9PiB7XG4gICAgc3dpdGNoICh0eXBlKSB7XG4gICAgICBjYXNlICdoaSc6XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgJ2hpJzoge1xuICAgICAgICAgICAgJ2lkJzogZ2V0TmV4dFVuaXF1ZUlkKCksXG4gICAgICAgICAgICAndmVyJzogVkVSU0lPTixcbiAgICAgICAgICAgICd1YSc6IGdldFVzZXJBZ2VudCgpLFxuICAgICAgICAgICAgJ2Rldic6IHRoaXMuX2RldmljZVRva2VuLFxuICAgICAgICAgICAgJ2xhbmcnOiB0aGlzLl9odW1hbkxhbmd1YWdlLFxuICAgICAgICAgICAgJ3BsYXRmJzogdGhpcy5fcGxhdGZvcm1cbiAgICAgICAgICB9XG4gICAgICAgIH07XG5cbiAgICAgIGNhc2UgJ2FjYyc6XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgJ2FjYyc6IHtcbiAgICAgICAgICAgICdpZCc6IGdldE5leHRVbmlxdWVJZCgpLFxuICAgICAgICAgICAgJ3VzZXInOiBudWxsLFxuICAgICAgICAgICAgJ3NjaGVtZSc6IG51bGwsXG4gICAgICAgICAgICAnc2VjcmV0JzogbnVsbCxcbiAgICAgICAgICAgICdsb2dpbic6IGZhbHNlLFxuICAgICAgICAgICAgJ3RhZ3MnOiBudWxsLFxuICAgICAgICAgICAgJ2Rlc2MnOiB7fSxcbiAgICAgICAgICAgICdjcmVkJzoge31cbiAgICAgICAgICB9XG4gICAgICAgIH07XG5cbiAgICAgIGNhc2UgJ2xvZ2luJzpcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAnbG9naW4nOiB7XG4gICAgICAgICAgICAnaWQnOiBnZXROZXh0VW5pcXVlSWQoKSxcbiAgICAgICAgICAgICdzY2hlbWUnOiBudWxsLFxuICAgICAgICAgICAgJ3NlY3JldCc6IG51bGxcbiAgICAgICAgICB9XG4gICAgICAgIH07XG5cbiAgICAgIGNhc2UgJ3N1Yic6XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgJ3N1Yic6IHtcbiAgICAgICAgICAgICdpZCc6IGdldE5leHRVbmlxdWVJZCgpLFxuICAgICAgICAgICAgJ3RvcGljJzogdG9waWMsXG4gICAgICAgICAgICAnc2V0Jzoge30sXG4gICAgICAgICAgICAnZ2V0Jzoge31cbiAgICAgICAgICB9XG4gICAgICAgIH07XG5cbiAgICAgIGNhc2UgJ2xlYXZlJzpcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAnbGVhdmUnOiB7XG4gICAgICAgICAgICAnaWQnOiBnZXROZXh0VW5pcXVlSWQoKSxcbiAgICAgICAgICAgICd0b3BpYyc6IHRvcGljLFxuICAgICAgICAgICAgJ3Vuc3ViJzogZmFsc2VcbiAgICAgICAgICB9XG4gICAgICAgIH07XG5cbiAgICAgIGNhc2UgJ3B1Yic6XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgJ3B1Yic6IHtcbiAgICAgICAgICAgICdpZCc6IGdldE5leHRVbmlxdWVJZCgpLFxuICAgICAgICAgICAgJ3RvcGljJzogdG9waWMsXG4gICAgICAgICAgICAnbm9lY2hvJzogZmFsc2UsXG4gICAgICAgICAgICAnaGVhZCc6IG51bGwsXG4gICAgICAgICAgICAnY29udGVudCc6IHt9XG4gICAgICAgICAgfVxuICAgICAgICB9O1xuXG4gICAgICBjYXNlICdnZXQnOlxuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICdnZXQnOiB7XG4gICAgICAgICAgICAnaWQnOiBnZXROZXh0VW5pcXVlSWQoKSxcbiAgICAgICAgICAgICd0b3BpYyc6IHRvcGljLFxuICAgICAgICAgICAgJ3doYXQnOiBudWxsLCAvLyBkYXRhLCBzdWIsIGRlc2MsIHNwYWNlIHNlcGFyYXRlZCBsaXN0OyB1bmtub3duIHN0cmluZ3MgYXJlIGlnbm9yZWRcbiAgICAgICAgICAgICdkZXNjJzoge30sXG4gICAgICAgICAgICAnc3ViJzoge30sXG4gICAgICAgICAgICAnZGF0YSc6IHt9XG4gICAgICAgICAgfVxuICAgICAgICB9O1xuXG4gICAgICBjYXNlICdzZXQnOlxuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICdzZXQnOiB7XG4gICAgICAgICAgICAnaWQnOiBnZXROZXh0VW5pcXVlSWQoKSxcbiAgICAgICAgICAgICd0b3BpYyc6IHRvcGljLFxuICAgICAgICAgICAgJ2Rlc2MnOiB7fSxcbiAgICAgICAgICAgICdzdWInOiB7fSxcbiAgICAgICAgICAgICd0YWdzJzogW11cbiAgICAgICAgICB9XG4gICAgICAgIH07XG5cbiAgICAgIGNhc2UgJ2RlbCc6XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgJ2RlbCc6IHtcbiAgICAgICAgICAgICdpZCc6IGdldE5leHRVbmlxdWVJZCgpLFxuICAgICAgICAgICAgJ3RvcGljJzogdG9waWMsXG4gICAgICAgICAgICAnd2hhdCc6IG51bGwsXG4gICAgICAgICAgICAnZGVsc2VxJzogbnVsbCxcbiAgICAgICAgICAgICd1c2VyJzogbnVsbCxcbiAgICAgICAgICAgICdoYXJkJzogZmFsc2VcbiAgICAgICAgICB9XG4gICAgICAgIH07XG5cbiAgICAgIGNhc2UgJ25vdGUnOlxuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICdub3Rl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AgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSBpZiAocGt0LmN0cmwuY29kZSA8IDMwMCAmJiBwa3QuY3RybC5wYXJhbXMpIHtcbiAgICAgICAgICAgIGlmIChwa3QuY3RybC5wYXJhbXMud2hhdCA9PSAnZGF0YScpIHtcbiAgICAgICAgICAgICAgLy8gY29kZT0yMDgsIGFsbCBtZXNzYWdlcyByZWNlaXZlZDogXCJwYXJhbXNcIjp7XCJjb3VudFwiOjExLFwid2hhdFwiOlwiZGF0YVwifSxcbiAgICAgICAgICAgICAgY29uc3QgdG9waWMgPSBjYWNoZUdldCgndG9waWMnLCBwa3QuY3RybC50b3BpYyk7XG4gICAgICAgICAgICAgIGlmICh0b3BpYykge1xuICAgICAgICAgICAgICAgIHRvcGljLl9hbGxNZXNzYWdlc1JlY2VpdmVkKHBrdC5jdHJsLnBhcmFtcy5jb3VudCk7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAocGt0LmN0cmwucGFyYW1zLndoYXQgPT0gJ3N1YicpIHtcbiAgICAgICAgICAgICAgLy8gY29kZT0yMDQsIHRoZSB0b3BpYyBoYXMgbm8gKHJlZnJlc2hlZCkgc3Vic2NyaXB0aW9ucy5cbiAgICAgICAgICAgICAgY29uc3QgdG9waWMgPSBjYWNoZUdldCgndG9waWMnLCBwa3QuY3RybC50b3BpYyk7XG4gICAgICAgICAgICAgIGlmICh0b3BpYykge1xuICAgICAgICAgICAgICAgIC8vIFRyaWdnZXIgdG9waWMub25TdWJzVXBkYXRlZC5cbiAgICAgICAgICAgICAgICB0b3BpYy5fcHJvY2Vzc01ldGFTdWIoW10pO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9LCAwKTtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIHNldFRpbWVvdXQoKCkgPT4ge1xuICAgICAgICAgIGlmIChwa3QubWV0YSkge1xuICAgICAgICAgICAgLy8gSGFuZGxpbmcgYSB7bWV0YX0gbWVzc2FnZS5cblxuICAgICAgICAgICAgLy8gUHJlZmVycmVkIEFQSTogUm91dGUgbWV0YSB0byB0b3BpYywgaWYgb25lIGlzIHJlZ2lzdGVyZWRcbiAgICAgICAgICAgIGNvbnN0IHRvcGljID0gY2FjaGVHZXQoJ3RvcGljJywgcGt0Lm1ldGEudG9waWMpO1xuICAgICAgICAgICAgaWYgKHRvcGljKSB7XG4gICAgICAgICAgICAgIHRvcGljLl9yb3V0ZU1ldGEocGt0Lm1ldGEpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAocGt0Lm1ldGEuaWQpIHtcbiAgICAgICAgICAgICAgZXhlY1Byb21pc2UocGt0Lm1ldGEuaWQsIDIwMCwgcGt0Lm1ldGEsICdNRVRBJyk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIC8vIFNlY29uZGFyeSBBUEk6IGNhbGxiYWNrXG4gICAgICAgICAgICBpZiAodGhpcy5vbk1ldGFNZXNzYWdlKSB7XG4gICAgICAgICAgICAgIHRoaXMub25NZXRhTWVzc2FnZShwa3QubWV0YSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIGlmIChwa3QuZGF0YSkge1xuICAgICAgICAgICAgLy8gSGFuZGxpbmcge2RhdGF9IG1lc3NhZ2VcblxuICAgICAgICAgICAgLy8gUHJlZmVycmVkIEFQSTogUm91dGUgZGF0YSB0byB0b3BpYywgaWYgb25lIGlzIHJlZ2lzdGVyZWRcbiAgICAgICAgICAgIGNvbnN0IHRvcGljID0gY2FjaGVHZXQoJ3RvcGljJywgcGt0LmRhdGEudG9waWMpO1xuICAgICAgICAgICAgaWYgKHRvcGljKSB7XG4gICAgICAgICAgICAgIHRvcGljLl9yb3V0ZURhdGEocGt0LmRhdGEpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBTZWNvbmRhcnkgQVBJOiBDYWxsIGNhbGxiYWNrXG4gICAgICAgICAgICBpZiAodGhpcy5vbkRhdGFNZXNzYWdlKSB7XG4gICAgICAgICAgICAgIHRoaXMub25EYXRhTWVzc2FnZShwa3QuZGF0YSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIGlmIChwa3QucHJlcykge1xuICAgICAgICAgICAgLy8gSGFuZGxpbmcge3ByZXN9IG1lc3NhZ2VcblxuICAgICAgICAgICAgLy8gUHJlZmVycmVkIEFQSTogUm91dGUgcHJlc2VuY2UgdG8gdG9waWMsIGlmIG9uZSBpcyByZWdpc3RlcmVkXG4gICAgICAgICAgICBjb25zdCB0b3BpYyA9IGNhY2hlR2V0KCd0b3BpYycsIHBrdC5wcmVzLnRvcGljKTtcbiAgICAgICAgICAgIGlmICh0b3BpYykge1xuICAgICAgICAgICAgICB0b3BpYy5fcm91dGVQcmVzKHBrdC5wcmVzKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgLy8gU2Vjb25kYXJ5IEFQSSAtIGNhbGxiYWNrXG4gICAgICAgICAgICBpZiAodGhpcy5vblByZXNNZXNzYWdlKSB7XG4gICAgICAgICAgICAgIHRoaXMub25QcmVzTWVzc2FnZShwa3QucHJlcyk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIGlmIChwa3QuaW5mbykge1xuICAgICAgICAgICAgLy8ge2luZm99IG1lc3NhZ2UgLSByZWFkL3JlY2VpdmVkIG5vdGlmaWNhdGlvbnMgYW5kIGtleSBwcmVzc2VzXG5cbiAgICAgICAgICAgIC8vIFByZWZlcnJlZCBBUEk6IFJvdXRlIHtpbmZvfX0gdG8gdG9waWMsIGlmIG9uZSBpcyByZWdpc3RlcmVkXG4gICAgICAgICAgICBjb25zdCB0b3BpYyA9IGNhY2hlR2V0KCd0b3BpYycsIHBrdC5pbmZvLnRvcGljKTtcbiAgICAgICAgICAgIGlmICh0b3BpYykge1xuICAgICAgICAgICAgICB0b3BpYy5fcm91dGVJbmZvKHBrdC5pbmZvKT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yIGFuIHVua25vd24gdXNlcjogbm90aWZpY2F0aW9uIG9mIGEgbmV3IHN1YnNjcmlwdGlvbi5cbiAgICAgICAgICBjb25zdCBhY3MgPSBuZXcgQWNjZXNzTW9kZSgpLnVwZGF0ZUFsbChwcmVzLmRhY3MpO1xuICAgICAgICAgIGlmIChhY3MgJiYgYWNzLm1vZGUgIT0gQWNjZXNzTW9kZS5fTk9ORSkge1xuICAgICAgICAgICAgdXNlciA9IHRoaXMuX2NhY2hlR2V0VXNlcih1aWQpO1xuICAgICAgICAgICAgaWYgKCF1c2VyKSB7XG4gICAgICAgICAgICAgIHVzZXIgPSB7XG4gICAgICAgICAgICAgICAgdXNlcjogdWlkLFxuICAgICAgICAgICAgICAgIGFjczogYWNzXG4gICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgIHRoaXMuZ2V0TWV0YSh0aGlzLnN0YXJ0TWV0YVF1ZXJ5KCkud2l0aE9uZVN1Yih1bmRlZmluZWQsIHVpZCkuYnVpbGQoKSk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICB1c2VyLmFjcyA9IGFjcztcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHVzZXIudXBkYXRlZCA9IG5ldyBEYXRlKCk7XG4gICAgICAgICAgICB0aGlzLl9wcm9jZXNzTWV0YVN1YihbdXNlcl0pO1xuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAvLyBLbm93biB1c2VyXG4gICAgICAgICAgdXNlci5hY3MudXBkYXRlQWxsKHByZXMuZGFjcyk7XG4gICAgICAgICAgLy8gVXBkYXRlIHVzZXIncyBhY2Nlc3MgbW9kZS5cbiAgICAgICAgICB0aGlzLl9wcm9jZXNzTWV0YVN1Yihbe1xuICAgICAgICAgICAgdXNlcjogdWlkLFxuICAgICAgICAgICAgdXBkYXRlZDogbmV3IERhdGUoKSxcbiAgICAgICAgICAgIGFjczogdXNlci5hY3NcbiAgICAgICAgICB9XSk7XG4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cnMgZnJvbSBkZXNjIG9iamVjdCB0byB0aGlzIHRvcGljLlxuICAgICAgbWVyZ2VPYmoodGhpcywgZGVzYyk7XG4gICAgICB0aGlzLl90aW5vZGUuX2RiLnVwZFRvcGljKHRoaXMpO1xuXG4gICAgICAvLyBTdHJpbmcgZGF0ZXRpbWUgaGVhZGVycyB0byBEYXRlKCkgb2JqZWN0cy5cbiAgICAgIHN0cmluZ1RvRGF0ZSh0aGlzKTtcblxuICAgICAgLy8gJ1AnIHBlcm1pc3Npb24gd2FzIHJlbW92ZWQuIEFsbCB0b3BpY3MgYXJlIG9mZmxpbmUgbm93LlxuICAgICAgaWYgKHR1cm5PZmYpIHtcbiAgICAgICAgdGhpcy5fdGlub2RlLmNhY2hlTWFwKCd0b3BpYycsIChjb250KSA9PiB7XG4gICAgICAgICAgaWYgKGNvbnQub25saW5lKSB7XG4gICAgICAgICAgICBjb250Lm9ubGluZSA9IGZhbHNlO1xuICAgICAgICAgICAgaWYgKGNvbnQuc2Vlbikge1xuICAgICAgICAgICAgICBjb250LnNlZW4ud2hlbiA9IG5ldyBEYXRlKCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBjb250LnNlZW4gPSB7XG4gICAgICAgICAgICAgICAgd2hlbjogbmV3IERhdGUoKVxuICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5fcmVmcmVzaENvbnRhY3QoJ29mZicsIGNvbnQpO1xuICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICB9XG5cbiAgICAgIGlmICh0aGlzLm9uTWV0YURlc2MpIHtcbiAgICAgICAgdGhpcy5vbk1ldGFEZXNjKHRoaXMpO1xuICAgICAgfVxuICAgIH0sXG4gICAgZW51bWVyYWJsZTogdHJ1ZSxcbiAgICBjb25maWd1cmFibGU6IHRydWVcbiAgfSxcblxuICAvLyBPdmVycmlkZSB0aGUgb3JpZ2luYWwgVG9waWMuX3Byb2Nlc3NNZXR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lZmluZWQnKSB7XG4gICAgICAgICAgICBzdWIuc2VxID0gc3ViLnNlcSB8IDA7XG4gICAgICAgICAgICBzdWIucmVjdiA9IHN1Yi5yZWN2IHwgMDtcbiAgICAgICAgICAgIHN1Yi5yZWFkID0gc3ViLnJlYWQgfCAwO1xuICAgICAgICAgICAgc3ViLnVucmVhZCA9IHN1Yi5zZXEgLSBzdWIucmVhZDtcbiAgICAgICAgICB9XG5cbiAgICAgICAgICBpZiAoc3ViLnNlZW4gJiYgc3ViLnNlZW4ud2hlbikge1xuICAgICAgICAgICAgc3ViLnNlZW4ud2hlbiA9IG5ldyBEYXRlKHN1Yi5zZWVuLndoZW4pO1xuICAgICAgICAgIH1cblxuICAgICAgICAgIGNvbnQgPSBtZXJnZU9iaih0aGlzLl90aW5vZGUuZ2V0VG9waWModG9waWNOYW1lKSwgc3ViKTtcbiAgICAgICAgICB0aGlzLl90aW5vZGUuX2RiLnVwZFRvcGljKGNvbnQpO1xuXG4gICAgICAgICAgaWYgKFRpbm9kZS5pc1AyUFRvcGljTmFtZSh0b3BpY05hbWUpKSB7XG4gICAgICAgICAgICB0aGlzLl9jYWNoZVB1dFVzZXIodG9waWNOYW1lLCBjb250KTtcbiAgICAgICAgICAgIHRoaXMuX3Rpbm9kZS5fZGIudXBkVXNlcih0b3BpY05hbWUsIGNvbnQucHVibGljKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgLy8gTm90aWZ5IHRvcGljIG9mIHRoZSB1cGRhdGUgaWYgaXQncyBhbiBleHRlcm5hbCB1cGRhdGUuXG4gICAgICAgICAgaWYgKCFzdWIuX25vRm9yd2FyZGluZykge1xuICAgICAgICAgICAgY29uc3QgdG9waWMgPSB0aGlzLl90aW5vZGUuZ2V0VG9waWModG9waWNOYW1lKTtcbiAgICAgICAgICAgIGlmICh0b3BpYykge1xuICAgICAgICAgICAgICBzdWIuX25vRm9yd2FyZGluZyA9IHRydWU7XG4gICAgICAgICAgICAgIHRvcGljLl9wcm9jZXNzTWV0YURlc2Moc3ViKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICB1cGRhdGVDb3VudCsrO1xuXG4gICAgICAgIGlmICh0aGlzLm9uTWV0YVN1Yikge1xuICAgICAgICAgIHRoaXMub25NZXRhU3ViKGNvbnQpO1xuICAgICAgICB9XG4gICAgICB9KTtcblxuICAgICAgaWYgKHRoaXMub25TdWJzVXBkYXRlZCAmJiB1cGRhdGVDb3VudCA+IDApIHtcbiAgICAgICAgY29uc3Qga2V5cyA9IFtdO1xuICAgICAgICBzdWJzLmZvckVhY2goKHMpID0+IHtcbiAgICAgICAgICBrZXlzLnB1c2gocy50b3BpYyk7XG4gICAgICAgIH0pO1xuICAgICAgICB0aGlzLm9uU3Vic1VwZGF0ZWQoa2V5cywgdXBkYXRlQ291bnQpO1xuICAgICAgfVxuICAgIH0sXG4gICAgZW51bWVyYWJsZTogdHJ1ZSxcbiAgICBjb25maWd1cmFibGU6IHRydWVcbiAgfSxcblxuICAvLyBDYWxsZWQgYnkgVGlub2RlIHdoZW4gbWV0YS5zdWIgaXMgcmVjaXZlZC5cbiAgX3Byb2Nlc3NNZXRhQ3JlZHM6IHtcbiAgICB2YWx1ZTogZnVuY3Rpb24oY3JlZHMsIHVwZCkge1xuICAgICAgaWYgKGNyZWRzLmxlbmd0aCA9PSAxICYmIGNyZWRzWzBdID09IFRpbm9kZS5ERUxfQ0hBUikge1xuICAgICAgICBjcmVkcyA9IFtdO1xuICAgICAgfVxuICAgICAgaWYgKHVwZCkge1xuICAgICAgICBjcmVkcy5tYXAoKGNyKSA9PiB7XG4gICAgICAgICAgaWYgKGNyLnZhbCkge1xuICAgICAgICAgICAgLy8gQWRkaW5nIGEgY3JlZGVudGlhbC5cbiAgICAgICAgICAgIGxldCBpZHggPSB0aGlzLl9jcmVkZW50aWFscy5maW5kSW5kZXgoKGVsKSA9PiB7XG4gICAgICAgICAgICAgIHJldHVybiBlbC5tZXRoID09IGNyLm1ldGggJiYgZWwudmFsID09IGNyLnZhbDtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgaWYgKGlkeCA8IDApIHtcbiAgICAgICAgICAgICAgLy8gTm90IGZvdW5kLlxuICAgICAgICAgICAgICBpZiAoIWNyLmRvbmUpIHtcbiAgICAgICAgICAgICAgICAvLyBVbmNvbmZpcm1lZCBjcmVkZW50aWFsIHJlcGxhY2VzIHByZXZpb3VzIHVuY29uZmlybWVkIGNyZWRlbnRpYWwgb2YgdGhlIHNhbWUgbWV0aG9kLlxuICAgICAgICAgICAgICAgIGlkeCA9IHRoaXMuX2NyZWRlbnRpYWxzLmZpbmRJbmRleCgoZWwpID0+IHtcbiAgICAgICAgICAgICAgICAgIHJldHVybiBlbC5tZXRoID09IGNyLm1ldGggJiYgIWVsLmRvbmU7XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgaWYgKGlkeCA+PSAwKSB7XG4gICAgICAgICAgICAgICAgICAvLyBSZW1vdmUgcHJldmlvdXMgdW5jb25maXJtZWQgY3JlZGVudGlhbC5cbiAgICAgICAgICAgICAgICAgIHRoaXMuX2NyZWRlbnRpYWxzLnNwbGljZShpZHgsIDEpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB0aGlzLl9jcmVkZW50aWFscy5wdXNoKGNyKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIC8vIEZvdW5kLiBNYXliZSBjaGFuZ2UgJ2RvbmUnIHN0YXR1cy5cbiAgICAgICAgICAgICAgdGhpcy5fY3JlZGVudGlhbHNbaWR4XS5kb25lID0gY3IuZG9uZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9IGVsc2UgaWYgKGNyLnJlc3ApIHtcbiAgICAgICAgICAgIC8vIEhhbmRsZSBjcmVkZW50aWFsIGNvbmZpcm1hdGlvbi5cbiAgICAgICAgICAgIGNvbnN0IGlkeCA9IHRoaXMuX2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zdGFydE1ldGFRdWVyeSgpLndpdGhEZXNjKCkuYnVpbGQoKSk7XG4gICAgICAgIHJldHVybjtcbiAgICAgIH1cblxuICAgICAgY29uc3QgY29udCA9IHRoaXMuX3Rpbm9kZS5jYWNoZUdldCgndG9waWMnLCBwcmVzLnNyYyk7XG4gICAgICBpZiAoY29udCkge1xuICAgICAgICBzd2l0Y2ggKHByZXMud2hhdCkge1xuICAgICAgICAgIGNhc2UgJ29uJzogLy8gdG9waWMgY2FtZSBvbmxpbmVcbiAgICAgICAgICAgIGNvbnQub25saW5lID0gdHJ1ZTtcbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIGNhc2UgJ29mZic6IC8vIHRvcGljIHdlbnQgb2ZmbGluZVxuICAgICAgICAgICAgaWYgKGNvbnQub25saW5lKSB7XG4gICAgICAgICAgICAgIGNvbnQub25saW5lID0gZmFsc2U7XG4gICAgICAgICAgICAgIGlmIChjb250LnNlZW4pIHtcbiAgICAgICAgICAgICAgICBjb250LnNlZW4ud2hlbiA9IG5ldyBEYXRlKCk7XG4gICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgY29udC5zZWVuID0ge1xuICAgICAgICAgICAgICAgICAgd2hlbjogbmV3IERhdGUoKVxuICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIGNhc2UgJ21zZyc6IC8vIG5ldyBtZXNzYWdlIHJlY2VpdmVkXG4gICAgICAgICAgICBjb250Ll91cGRhdGVSZWNlaXZlZChwcmVzLnNlcSwgcHJlcy5hY3QpO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgY2FzZSAndXBkJzogLy8gZGVzYyB1cGRhdGVkXG4gICAgICAgICAgICAvLyBSZXF1ZXN0IHVwZGF0ZWQgc3Vic2NyaXB0aW9uLlxuICAgICAgICAgICAgdGhpcy5nZXRNZXRhKHRoaXMuc3RhcnRNZXRhUXVlcnkoKS53aXRoTGF0ZXJPbmVTdWIocHJlcy5zcmMpLmJ1aWxkKCkpO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgY2FzZSAnYWNzJzogLy8gYWNjZXNzIG1vZGUgY2hhbmdlZFxuICAgICAgICAgICAgaWYgKGNvbnQuYWNzKSB7XG4gICAgICAgICAgICAgIGNvbnQuYWNzLnVwZGF0ZUFsbChwcmVzLmRhY3MpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgY29udC5hY3MgPSBuZXcgQWNjZXNzTW9kZSgpLnVwZGF0ZUFsbChwcmVzLmRhY3MpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY29udC50b3VjaGVkID0gbmV3IERhdGUoKTtcbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIGNhc2UgJ3VhJzpcbiAgICAgICAgICAgIC8vIHVzZXIgYWdlbnQgY2hhbmdlZC5cbiAgICAgICAgICAgIGNvbnQuc2VlbiA9IHtcbiAgICAgICAgICAgICAgd2hlbjogbmV3IERhdGUoKSxcbiAgICAgICAgICAgICAgdWE6IHByZXMudWFcbiAgICAgICAgICAgIH07XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICBjYXNlICdyZWN2JzpcbiAgICAgICAgICAgIC8vIHVzZXIncyBvdGhlciBzZXNzaW9uIG1hcmtlZCBzb21lIG1lc3NnZXMgYXMgcmVjZWl2ZWQuXG4gICAgICAgICAgICBwcmVzLnNlcSA9IHByZXMuc2VxIHwgMDtcbiAgICAgICAgICAgIGNvbnQucmVjdiA9IGNvbnQucmVjdiA/IE1hdGgubWF4KGNvbnQucmVjdiwgcHJlcy5zZXEpIDogcHJlcy5zZXE7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICBjYXNlICdyZWFkJzpcbiAgICAgICAgICAgIC8vIHVzZXIncyBvdGhlciBzZXNzaW9uIG1hcmtlZCBzb21lIG1lc3NhZ2VzIGFzIHJlYWQuXG4gICAgICAgICAgICBwcmVzLnNlcSA9IHByZXMuc2VxIHwgMDtcbiAgICAgICAgICAgIGNvbnQucmVhZCA9IGNvbnQucmVhZCA/IE1hdGgubWF4KGNvbnQucmVhZCwgcHJlcy5zZXEpIDogcHJlcy5zZXE7XG4gICAgICAgICAgICBjb250LnJlY3YgPSBjb250LnJlY3YgPyBNYXRoLm1heChjb250LnJlYWQsIGNvbnQucmVjdikgOiBjb250LnJlY3Y7XG4gICAgICAgICAgICBjb250LnVucmVhZCA9IGNvbnQuc2VxIC0gY29udC5yZWFkO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgY2FzZSAnZ29uZSc6XG4gICAgICAgICAgICAvLyB0b3BpYyBkZWxldGVkIG9yIHVuc3Vic2NyaWJlZCBmcm9tLlxuICAgICAgICAgICAgdGhpcy5fdGlub2RlLmNhY2hlRGVsKCd0b3BpYycsIHByZXMuc3JjKTtcbiAgICAgICAgICAgIHRoaXMuX3Rpbm9kZS5fZGIucmVtVG9waWMocHJlcy5zcmMpO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgY2FzZSAnZGVsJzpcbiAgICAgICAgICAgIC8vIFVwZGF0ZSB0b3BpYy5kZWwgdmFsdWUuXG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgICAgdGhpcy5fdGlub2RlLmxvZ2dlcihcIklORk86IFVuc3VwcG9ydGVkIHByZXNlbmNlIHVwZGF0ZSBpbiAnbWUnXCIsIHByZXMud2hhdCk7XG4gICAgICAgIH1cblxuICAgICAgICB0aGlzLl9yZWZyZXNoQ29udGFjdChwcmVzLndoYXQsIGNvbnQpO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgaWYgKHByZXMud2hhdCA9PSAnYWNzJykge1xuICAgICAgICAgIC8vIE5ldyBzdWJzY3JpcHRpb25zIGFuZCBkZWxldGVkL2Jhbm5lZCBzdWJzY3JpcHRpb25zIGhhdmUg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wcmVzLnNyYykuYnVpbGQoKSk7XG4gICAgICAgICAgICAvLyBDcmVhdGUgYSBkdW1teSBlbnRyeSB0byBjYXRjaCBvbmxpbmUgc3RhdHVzIHVwZGF0ZS5cbiAgICAgICAgICAgIGNvbnN0IGR1bW15ID0gdGhpcy5fdGlub2RlLmdldFRvcGljKHByZXMuc3JjKTtcbiAgICAgICAgICAgIGR1bW15LnRvdWNoZWQgPSBuZXcgRGF0ZSgpO1xuICAgICAgICAgICAgZHVtbXkudG9waWMgPSBwcmVzLnNyYztcbiAgICAgICAgICAgIGR1bW15Lm9ubGluZSA9IGZhbHNlO1xuICAgICAgICAgICAgZHVtbXkuYWNzID0gYWNzO1xuICAgICAgICAgICAgdGhpcy5fdGlub2RlLmF0dGFjaENhY2hlVG9Ub3BpYyhkdW1teSk7XG4gICAgICAgICAgICBkdW1teS5fY2FjaGVQdXRTZWxmKCk7XG4gICAgICAgICAgICB0aGlzLl9kYi51cGRUb3BpYyhkdW1teSk7XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2UgaWYgKHByZXMud2hhdCA9PSAndGFncycpIHtcbiAgICAgICAgICB0aGlzLmdldE1ldGEodGhpcy5zdGFydE1ldGFRdWVyeSgpLndpdGhUYWdzKCkuYnVpbGQoKSk7XG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgaWYgKHRoaXMub25QcmVzKSB7XG4gICAgICAgIHRoaXMub25QcmVzKHByZXMpO1xuICAgICAgfVxuICAgIH0sXG4gICAgZW51bWVyYWJsZTogdHJ1ZSxcbiAgICBjb25maWd1cmFibGU6IHRydWVcbiAgfSxcblxuICAvLyBDb250YWN0IGlzIHVwZGF0ZWQsIGV4ZWN1dGUgY2FsbGJhY2tzLlxuICBfcmVmcmVzaENvbnRhY3Q6IHtcbiAgICB2YWx1ZTogZnVuY3Rpb24od2hhdCwgY29udCkge1xuICAgICAgaWYgKHRoaXMub25Db250YWN0VXBkYXRlKSB7XG4gICAgICAgIHRoaXMub25Db250YWN0V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gY2Fubm90IGJlIGNhdWdodDpcbiAgICAgICAgLy8gaHR0cHM6Ly9zdGFja292ZXJmbG93LmNvbS9xdWVzdGlvbnMvMzEwMDI1OTIvamF2YXNjcmlwdC1kb2VzbnQtY2F0Y2gtZXJyb3ItaW4td2Vic29ja2V0LWluc3RhbnRpYXRpb24vMzEwMDMwNTdcbiAgICAgICAgY29uc3QgY29ubiA9IG5ldyBXZWJTb2NrZXRQcm92aWRlcih1cmwpO1xuXG4gICAgICAgIGNvbm4ub25lcnJvciA9IGZ1bmN0aW9uKGVycikge1xuICAgICAgICAgIHJlamVjdChlcnIpO1xuICAgICAgICB9XG5cbiAgICAgICAgY29ubi5vbm9wZW4gPSBmdW5jdGlvbihldnQpIHtcbiAgICAgICAgICBpZiAoYXV0b3JlY29ubmVjdCkge1xuICAgICAgICAgICAgYm9mZlN0b3AoKTtcbiAgICAgICAgICB9XG5cbiAgICAgICAgICBpZiAoaW5zdGFuY2Uub25PcGVuKSB7XG4gICAgICAgICAgICBpbnN0YW5jZS5vbk9wZW4oKTtcbiAgICAgICAgICB9XG5cbiAgICAgICAgICByZXNvbHZlKCk7XG4gICAgICAgIH1cblxuICAgICAgICBjb25uLm9uY2xvc2UgPSBmdW5jdGlvbihldnQpIHtcbiAgICAgICAgICBfc29ja2V0ID0gbnVsbDtcblxuICAgICAgICAgIGlmIChpbnN0YW5jZS5vbkRpc2Nvbm5lY3QpIHtcbiAgICAgICAgICAgIGNvbnN0IGNvZGUgPSBfYm9mZkNsb3NlZCA/IE5FVFdPUktfVVNFUiA6IE5FVFdPUktfRVJST1I7XG4gICAgICAgICAgICBpbnN0YW5jZS5vbkRpc2Nvbm5lY3QobmV3IEVycm9yKF9ib2ZmQ2xvc2VkID8gTkVUV09SS19VU0VSX1RFWFQgOiBORVRXT1JLX0VSUk9SX1RFWFQgK1xuICAgICAgICAgICAgICAnICgnICsgY29kZSArICcpJyksIGNvZGUpO1xuICAgICAgICAgIH1cblxuICAgICAgICAgIGlmICghX2J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G9sbGVyLnJlYWR5U3RhdGUgPT0gWERSX0RPTkUpIHtcbiAgICAgICAgICBpZiAocG9sbGVyLnN0YXR1cyA9PSAyMDEpIHsgLy8gMjAxID09IEhUVFAuQ3JlYXRlZCwgZ2V0IFNJRFxuICAgICAgICAgICAgbGV0IHBrdCA9IEpTT04ucGFyc2UocG9sbGVyLnJlc3BvbnNlVGV4dCwganNvblBhcnNlSGVscGVyKTtcbiAgICAgICAgICAgIF9scFVSTCA9IHVybF8gKyAnJnNpZD0nICsgcGt0LmN0cmwucGFyYW1zLnNpZFxuICAgICAgICAgICAgcG9sbGVyID0gbHBfcG9sbGVyKF9scFVSTCk7XG4gICAgICAgICAgICBwb2xsZXIuc2VuZChudWxsKVxuICAgICAgICAgICAgaWYgKGluc3RhbmNlLm9uT3Blbikge1xuICAgICAgICAgICAgICBpbnN0YW5jZS5vbk9wZW4oKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKHJlc29sdmUpIHtcbiAgICAgICAgICAgICAgcHJvbWlzZUNvbXBsZXRlZCA9IHRydWU7XG4gICAgICAgICAgICAgIHJlc29sdmUoKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKGF1dG9yZWNvbm5lY3QpIHtcbiAgICAgICAgICAgICAgYm9mZlN0b3AoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9IGVsc2UgaWYgKHBvbGxlci5zdGF0dXMgPCA0MDApIHsgLy8gNDAwID0gSFRUUC5CYWRSZXF1ZXN0XG4gICAgICAgICAgICBpZiAoaW5zdGFuY2Uub25NZXNzYWdlKSB7XG4gICAgICAgICAgICAgIGluc3RhbmNlLm9uTWVzc2FnZShwb2xsZXIucmVzcG9uc2VUZXh0KVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcG9sbGVyID0gbHBfcG9sbGVyKF9scFVSTCk7XG4gICAgICAgICAgICBwb2xsZXIuc2VuZChudWxsKTtcbiAgICAgICAgICB9IGVsc2Uge1xuIC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UuXG4gICAgICogQG1lbWJlck9mIERCXG4gICAgICogQHBhcmFtIHtUb3BpY30gdG9waWMgLSB0b3BpYyB0byBiZSBhZGRlZCBvciB1cGRhdGVkLlxuICAgICAqIEByZXR1cm5zIHtQcm9taXNlfSBwcm9taXNlIHJlc29sdmVkL3JlamVjdGVkIG9uIG9wZXJhdGlvbiBjb21wbGV0aW9uLlxuICAgICAqL1xuICAgIHVwZFRvcGljOiBmdW5jdGlvbih0b3BpYykge1xuICAgICAgaWYgKCF0aGlzLmlzUmVhZHkoKSkge1xuICAgICAgICByZXR1cm4gZGlzYWJsZWQgP1xuICAgICAgICAgIFByb21pc2UucmVzb2x2ZSgpIDpcbiAgICAgICAgICBQcm9taXNlLnJlamVjdChuZXcgRXJyb3IoXCJub3QgaW5pdGlhbGl6ZWRcIikpO1xuICAgICAgfVxuICAgICAgcmV0dXJuIG5ldyBQcm9taXNlKChyZXNvbHZlLCByZWplY3QpID0+IHtcbiAgICAgICAgY29uc3QgdHJ4ID0gZGIudHJhbnNhY3Rpb24oWyd0b3BpYyddLCAncmVhZHdyaXRlJyk7XG4gICAgICAgIHRyeC5vbmNvbXBsZXRlID0gKGV2ZW50KSA9PiB7XG4gICAgICAgICAgcmVzb2x2ZShldmVudC50YXJnZXQucmVzdWx0KTtcbiAgICAgICAgfTtcbiAgICAgICAgdHJ4Lm9uZXJyb3IgPSAoZXZlbnQpID0+IHtcbiAgICAgICAgICBsb2dnZXIoXCJQQ2FjaGVcIiwgXCJ1cGRUb3BpY1wiLCBldmVudC50YXJnZXQuZXJyb3IpO1xuICAgICAgICAgIHJlamVjdChldmVudC50YXJnZXQuZXJyb3IpO1xuICAgICAgICB9O1xuICAgICAgICBjb25zdCByZXEgPSB0cngub2JqZWN0U3RvcmUoJ3RvcGljJykuZ2V0KHRvcGljLm5hbWUpO1xuICAgICAgICByZXEub25zdWNjZXNzID0gKGV2ZW50KSA9PiB7XG4gICAgICAgICAgdHJ4Lm9iamVjdFN0b3JlKCd0b3B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G4gICAgICAgICAgUHJvbWlzZS5yZXNvbHZlKCkgOlxuICAgICAgICAgIFByb21pc2UucmVqZWN0KG5ldyBFcnJvcihcIm5vdCBpbml0aWFsaXplZFwiKSk7XG4gICAgICB9XG4gICAgICByZXR1cm4gbmV3IFByb21pc2UoKHJlc29sdmUsIHJlamVjdCkgPT4ge1xuICAgICAgICBjb25zdCB0cnggPSBkYi50cmFuc2FjdGlvbihbJ3VzZXInXSwgJ3JlYWR3cml0ZScpO1xuICAgICAgICB0cngub25jb21wbGV0ZSA9IChldmVudCkgPT4ge1xuICAgICAgICAgIHJlc29sdmUoZXZlbnQudGFyZ2V0LnJlc3VsdCk7XG4gICAgICAgIH07XG4gICAgICAgIHRyeC5vbmVycm9yID0gKGV2ZW50KSA9PiB7XG4gICAgICAgICAgbG9nZ2VyKFwiUENhY2hlXCIsIFwidXBkVXNlclwiLCBldmVudC50YXJnZXQuZXJyb3IpO1xuICAgICAgICAgIHJlamVjdChldmVudC50YXJnZXQuZXJyb3IpO1xuICAgICAgICB9O1xuICAgICAgICB0cngub2JqZWN0U3RvcmUoJ3VzZXInKS5wdXQoe1xuICAgICAgICAgIHVpZDogdWlkLFxuICAgICAgICAgIHB1YmxpYzogcHViXG4gICAgICAgIH0pO1xuICAgICAgICB0cnguY29tbWl0KCk7XG4gICAgICB9KTtcbiAgICB9LFxuXG4gICAgLyoqXG4gICAgICogUmVtb3ZlIHVzZXIgZnJvbSBwZXJzaXN0ZW50IGNhY2hlLlxuICAgICAqIEBtZW1iZXJPZiBEQlxuICAgICAqIEBwYXJhbSB7c3RyaW5nfSB1aWQgLSBJRCBvZiB0aGUgdXNlciB0byByZW1vdmUgZnJvbSB0aGUgY2FjaGUuXG4gICAgICogQHJldHVybiB7UHJvbWlzZX0gcHJvbWlzZSByZXNvbHZlZC9yZWplY3RlZCBvbiBvcGVyYXRpb24gY29tcGxldGlvbi5cbiAgICAgKi9cbiAgICByZW1Vc2VyOiBmdW5jdGlvbih1aWQpIHtcbiA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dG9waWNOYW1lLCAnLSddLCBbdG9waWNOYW1lLCAnfiddKSkub25zdWNjZXNzID0gKGV2ZW50KSA9PiB7XG4gICAgICAgICAgaWYgKGNhbGxiYWNrKSB7XG4gICAgICAgICAgICBldmVudC50YXJnZXQucmVzdWx0LmZvckVhY2goKHRvcGljKSA9PiB7XG4gICAgICAgICAgICAgIGNhbGxiYWNrLmNhbGwoY29udGV4dCwgdG9waWMpO1xuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgfVxuICAgICAgICAgIHJlc29sdmUoZXZlbnQudGFyZ2V0LnJlc3VsdCk7XG4gICAgICAgIH07XG4gICAgICB9KTtcbiAgICB9LFxuXG4gICAgLy8gTWVzc2FnZXMuXG5cbiAgICAvKipcbiAgICAgKiBTYXZlIG1lc3NhZ2UgdG8gcGVyc2lzdGVudCBjYWNoZS5cbiAgICAgKiBAbWVtYmVyT2YgREJcbiAgICAgKiBAcGFyYW0ge3N0cmluZ30gdG9waWNOYW1lIC0gbmFtZSBvZiB0aGUgdG9waWMgd2hpY2ggb3ducyB0aGUgbWVzc2FnZS5cbiAgICAgKiBAcGFyYW0ge09iamVjdH0gbXNnIC0gbWVzc2FnZSB0byBzYXZlLlxuICAgICAqIEByZXR1cm4ge1Byb21pc2V9IHByb21pc2UgcmVzb2x2ZWQvcmVqZWN0ZWQgb24gb3BlcmF0aW9uIGNvbXBsZXRpb24uXG4gICAgICovXG4gICAgYWRkTWVzc2FnZTogZnVuY3Rpb24obXNnKSB7XG4gICAgICBpZiAoIXRoaXMuaXNSZWFkeSgpKSB7XG4gICAgICAgIHJldHVybiBkaXNhYmxlZCA/XG4gICAgICAgICAgUHJvbWlzZS5yZXNvbHZlKCkgOlxuICAgICAgICAgIFByb21pc2UucmVqZWN0KG5ldyBFcnJvcihcIm5vdCBpbml0aWFsaXplZFwiKSk7XG4gICAgICB9XG4gICAgICByZXR1cm4gbmV3IFByb21pc2UoKHJlc29sdmUsIHJlamVjdCkgPT4ge1xuICAgICAgICBjb25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vY2sudHh0KTtcbiAgICBpZiAoZW50aXRpZXMubGVuZ3RoID4gMCkge1xuICAgICAgY29uc3QgcmFuZ2VzID0gW107XG4gICAgICBmb3IgKGxldCBpIGluIGVudGl0aWVzKSB7XG4gICAgICAgIC8vIHtvZmZzZXQ6IG1hdGNoWydpbmRleCddLCB1bmlxdWU6IG1hdGNoWzBdLCBsZW46IG1hdGNoWzBdLmxlbmd0aCwgZGF0YTogZW50LnBhY2tlcigpLCB0eXBlOiBlbnQubmFtZX1cbiAgICAgICAgY29uc3QgZW50aXR5ID0gZW50aXRpZXNbaV07XG4gICAgICAgIGxldCBpbmRleCA9IGVudGl0eUluZGV4W2VudGl0eS51bmlxdWVdO1xuICAgICAgICBpZiAoIWluZGV4KSB7XG4gICAgICAgICAgaW5kZXggPSBlbnRpdHlNYXAubGVuZ3RoO1xuICAgICAgICAgIGVudGl0eUluZGV4W2VudGl0eS51bmlxdWVdID0gaW5kZXg7XG4gICAgICAgICAgZW50aXR5TWFwLnB1c2goe1xuICAgICAgICAgICAgdHA6IGVudGl0eS50eXBlLFxuICAgICAgICAgICAgZGF0YTogZW50aXR5LmRhdGFcbiAgICAgICAgICB9KTtcbiAgICAgICAgfVxuICAgICAgICByYW5nZXMucHVzaCh7XG4gICAgICAgICAgYXQ6IGVudGl0eS5vZmZzZXQsXG4gICAgICAgICAgbGVuOiBlbnRpdHkubGVuLFxuICAgICAgICAgIGtleTogaW5kZXhcbiAgICAgICAgfSk7XG4gICAgICB9XG4gICAgICBibG9jay5lbnQgPSByYW5nZXM7XG4gICAgfVxuXG4gICAgYmx4LnB1c2goYmxvY2spO1xuICB9KTtcblxuICBjb25zdCByZXN1bHQgPSB7XG4gICAgdHh0OiBcIlwiXG4gIH07XG5cbiAgLy8gTWVyZ2UgbGluZXMgYW5kIHNhdmUgbGluZSBicmVha3MgYXMgQlIgaW5saW5lIGZvcm1hdHRpbmcuXG4gIGlmIChibHgubGVuZ3RoID4gMCkge1xuICAgIHJlc3VsdC50eH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ID0gMDtcbiAgICBsZXQgZW50X2NvdW50ID0gMDtcbiAgICBmbXQuZm9yRWFjaCgoc3QpID0+IHtcbiAgICAgIHN0LmF0IHw9IDA7XG4gICAgICBpZiAoc3QuYXQgPCBsZW4pIHtcbiAgICAgICAgZm10X2NvdW50Kys7XG4gICAgICAgIGlmICghc3QudHApIHtcbiAgICAgICAgICBzdC5rZXkgfD0gMDtcbiAgICAgICAgICBpZiAoIWVudF9yZWZzW3N0LmtleV0pIHtcbiAgICAgICAgICAgIGVudF9yZWZzW3N0LmtleV0gPSBlbnRfY291bnQ7XG4gICAgICAgICAgICBlbnRfY291bnQrKztcbiAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICAgIH1cbiAgICB9KTtcblxuICAgIGlmIChmbXRfY291bnQgPT0gMCkge1xuICAgICAgcmV0dXJuIHByZXZpZXc7XG4gICAgfVxuXG4gICAgLy8gQWxsb2NhdGUgc3BhY2UgZm9yIGNvcHlpbmcgc3R5bGVzIGFuZCBlbnRpdGllcy5cbiAgICBwcmV2aWV3LmZtdCA9IFtdO1xuICAgIGlmIChBcnJheS5pc0FycmF5KGVudCkgJiYgZW50X3JlZnMubGVuZ3RoID4gMCkge1xuICAgICAgcHJldmlldy5lbnQgPSBbXTtcbiAgICB9XG5cbiAgICAvLyBJbnNlcnRpb24gcG9pbnQgZm9yIHN0eWxlcy5cbiAgICBsZXQgZm10X2lkeCA9IDA7XG4gICAgZm10LmZvckVhY2goKHN0KSA9PiB7XG4gICAgICBpZiAoc3QuYXQgPCBsZW4pIHtcbiAgICAgICAgY29uc3Qgc3R5bGUgPSB7XG4gICAgICAgICAgYXQ6IHN0LmF0LFxuICAgICAgICAgIGxlbjogc3QubGVuIHwgMFxuICAgICAgICB9O1xuICAgICAgICBpZiAoc3QudHApIHtcbiAgICAgICAgICBzdHlsZS50cCA9ICcnICsgc3QudHA7XG4gICAgICAgIH0gZWxzZSBpZiAoQXJyYXkuaXNBcnJheShlbnQpICYmIGVudC5sZW5ndGggP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c2VyID8gdGhpcy5fYnJvd3NlciArICc7ICcgOiAnJykgKyB0aGlzLl9od29zICsgJyk7ICcgKyBMSUJSQVJZO1xuICB9XG5cbiAgLy8gR2VuZXJhdG9yIG9mIHBhY2tldHMgc3R1YnNcbiAgdGhpcy5pbml0UGFja2V0ID0gKHR5cGUsIHRvcGljKSA9PiB7XG4gICAgc3dpdGNoICh0eXBlKSB7XG4gICAgICBjYXNlICdoaSc6XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgJ2hpJzoge1xuICAgICAgICAgICAgJ2lkJzogZ2V0TmV4dFVuaXF1ZUlkKCksXG4gICAgICAgICAgICAndmVyJzogVkVSU0lPTixcbiAgICAgICAgICAgICd1YSc6IGdldFVzZXJBZ2VudCgpLFxuICAgICAgICAgICAgJ2Rldic6IHRoaXMuX2RldmljZVRva2VuLFxuICAgICAgICAgICAgJ2xhbmcnOiB0aGlzLl9odW1hbkxhbmd1YWdlLFxuICAgICAgICAgICAgJ3BsYXRmJzogdGhpcy5fcGxhdGZvcm1cbiAgICAgICAgICB9XG4gICAgICAgIH07XG5cbiAgICAgIGNhc2UgJ2FjYyc6XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgJ2FjYyc6IHtcbiAgICAgICAgICAgICdpZCc6IGdldE5leHRVbmlxdWVJZCgpLFxuICAgICAgICAgICAgJ3VzZXInOiBudWxsLFxuICAgICAgICAgICAgJ3NjaGVtZSc6IG51bGwsXG4gICAgICAgICAgICAnc2VjcmV0JzogbnVsbCxcbiAgICAgICAgICAgICdsb2dpbic6IGZhbHNlLFxuICAgICAgICAgICAgJ3RhZ3MnOiBudWxsLFxuICAgICAgICAgICAgJ2Rlc2MnOiB7fSxcbiAgICAgICAgICAgICdjcmVkJzoge31cbiAgICAgICAgICB9XG4gICAgICAgIH07XG5cbiAgICAgIGNhc2UgJ2xvZ2luJzpcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAnbG9naW4nOiB7XG4gICAgICAgICAgICAnaWQnOiBnZXROZXh0VW5pcXVlSWQoKSxcbiAgICAgICAgICAgICdzY2hlbWUnOiBudWxsLFxuICAgICAgICAgICAgJ3NlY3JldCc6IG51bGxcbiAgICAgICAgICB9XG4gICAgICAgIH07XG5cbiAgICAgIGNhc2UgJ3N1Yic6XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgJ3N1Yic6IHtcbiAgICAgICAgICAgICdpZCc6IGdldE5leHRVbmlxdWVJZCgpLFxuICAgICAgICAgICAgJ3RvcGljJzogdG9waWMsXG4gICAgICAgICAgICAnc2V0Jzoge30sXG4gICAgICAgICAgICAnZ2V0Jzoge31cbiAgICAgICAgICB9XG4gICAgICAgIH07XG5cbiAgICAgIGNhc2UgJ2xlYXZlJzpcbiAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAnbGVhdmUnOiB7XG4gICAgICAgICAgICAnaWQnOiBnZXROZXh0VW5pcXVlSWQoKSxcbiAgICAgICAgICAgICd0b3BpYyc6IHRvcGljLFxuICAgICAgICAgICAgJ3Vuc3ViJzogZmFsc2VcbiAgICAgICAgICB9XG4gICAgICAgIH07XG5cbiAgICAgIGNhc2UgJ3B1Yic6XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgJ3B1Yic6IHtcbiAgICAgICAgICAgICdpZCc6IGdldE5leHRVbmlxdWVJZCgpLFxuICAgICAgICAgICAgJ3RvcGljJzogdG9waWMsXG4gICAgICAgICAgICAnbm9lY2hvJzogZmFsc2UsXG4gICAgICAgICAgICAnaGVhZCc6IG51bGwsXG4gICAgICAgICAgICAnY29udGVudCc6IHt9XG4gICAgICAgICAgfVxuICAgICAgICB9O1xuXG4gICAgICBjYXNlICdnZXQnOlxuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICdnZXQnOiB7XG4gICAgICAgICAgICAnaWQnOiBnZXROZXh0VW5pcXVlSWQoKSxcbiAgICAgICAgICAgICd0b3BpYyc6IHRvcGljLFxuICAgICAgICAgICAgJ3doYXQnOiBudWxsLCAvLyBkYXRhLCBzdWIsIGRlc2MsIHNwYWNlIHNlcGFyYXRlZCBsaXN0OyB1bmtub3duIHN0cmluZ3MgYXJlIGlnbm9yZWRcbiAgICAgICAgICAgICdkZXNjJzoge30sXG4gICAgICAgICAgICAnc3ViJzoge30sXG4gICAgICAgICAgICAnZGF0YSc6IHt9XG4gICAgICAgICAgfVxuICAgICAgICB9O1xuXG4gICAgICBjYXNlICdzZXQnOlxuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICdzZXQnOiB7XG4gICAgICAgICAgICAnaWQnOiBnZXROZXh0VW5pcXVlSWQoKSxcbiAgICAgICAgICAgICd0b3BpYyc6IHRvcGljLFxuICAgICAgICAgICAgJ2Rlc2MnOiB7fSxcbiAgICAgICAgICAgICdzdWInOiB7fSxcbiAgICAgICAgICAgICd0YWdzJzogW11cbiAgICAgICAgICB9XG4gICAgICAgIH07XG5cbiAgICAgIGNhc2UgJ2RlbCc6XG4gICAgICAgIHJldHVybiB7XG4gICAgICAgICAgJ2RlbCc6IHtcbiAgICAgICAgICAgICdpZCc6IGdldE5leHRVbmlxdWVJZCgpLFxuICAgICAgICAgICAgJ3RvcGljJzogdG9waWMsXG4gICAgICAgICAgICAnd2hhdCc6IG51bGwsXG4gICAgICAgICAgICAnZGVsc2VxJzogbnVsbCxcbiAgICAgICAgICAgICd1c2VyJzogbnVsbCxcbiAgICAgICAgICAgICdoYXJkJzogZmFsc2VcbiAgICAgICAgICB9XG4gICAgICAgIH07XG5cbiAgICAgIGNhc2UgJ25vdGUnOlxuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICdub3RlJzoge1xuICAgICAgICAgICAgLy8gbm8gaWQgYnkgZGVzaWduXG4gICAgICAgICAgICAndG9waWMnOiB0b3BpYyxcbiAgICAgICAgICAgICd3aGF0JzogbnVsbCwgLy8gb25lIG9mIFwicmVjdlwiLCBcInJlYWRcIiwgXCJrcFwiXG4gICAgICAgICAgICAnc2VxJzogdW5kZWZpbmVkIC8vIHRoZSB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AgIGlmIChwa3QuY3RybCkge1xuICAgICAgICAvLyBIYW5kbGluZyB7Y3RybH0gbWVzc2FnZVxuICAgICAgICBpZiAodGhpcy5vbkN0cmxNZXNzYWdlKSB7XG4gICAgICAgICAgdGhpcy5vbkN0cmxNZXNzYWdlKHBrdC5jdHJsKTtcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIFJlc29sdmUgb3IgcmVqZWN0IGEgcGVuZGluZyBwcm9taXNlLCBpZiBhbnlcbiAgICAgICAgaWYgKHBrdC5jdHJsLmlkKSB7XG4gICAgICAgICAgZXhlY1Byb21pc2UocGt0LmN0cmwuaWQsIHBrdC5jdHJsLmNvZGUsIHBrdC5jdHJsLCBwa3QuY3RybC50ZXh0KTtcbiAgICAgICAgfVxuICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHtcbiAgICAgICAgICBpZiAocGt0LmN0cmwuY29kZSA9PSAyMDUgJiYgcGt0LmN0cmwudGV4dCA9PSAnZXZpY3RlZCcpIHtcbiAgICAgICAgICAgIC8vIFVzZXIgZXZpY3RlZCBmcm9tIHRvcGljLlxuICAgICAgICAgICAgY29uc3QgdG9waWMgPSBjYWNoZUdldCgndG9waWMnLCBwa3QuY3RybC50b3BpYyk7XG4gICAgICAgICAgICBpZiAodG9waWMpIHtcbiAgICAgICAgICAgICAgdG9waWMuX3Jlc2V0U3ViKCk7XG4gICAgICAgICAgICAgIGlmIChwa3QuY3RybC5wYXJhbXMgJiYgcGt0LmN0cmwucGFyYW1zLnVuc3ViKSB7XG4gICAgICAgICAgICAgICAgdG9waWMuX2dvbmUoKTtcbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgIH0gZWxzZSBpZiAocGt0LmN0cmwuY29kZSA8IDMwMCAmJiBwa3QuY3RybC5wYXJhbXMpIHtcbiAgICAgICAgICAgIGlmIChwa3QuY3RybC5wYXJhbXMud2hhdCA9PSAnZGF0YScpIHtcbiAgICAgICAgICAgICAgLy8gY29kZT0yMDgsIGFsbCBtZXNzYWdlcyByZWNlaXZlZDogXCJwYXJhbXNcIjp7XCJjb3VudFwiOjExLFwid2hhdFwiOlwiZGF0YVwifSxcbiAgICAgICAgICAgICAgY29uc3QgdG9waWMgPSBjYWNoZUdldCgndG9waWMnLCBwa3QuY3RybC50b3BpYyk7XG4gICAgICAgICAgICAgIGlmICh0b3BpYykge1xuICAgICAgICAgICAgICAgIHRvcGljLl9hbGxNZXNzYWdlc1JlY2VpdmVkKHBrdC5jdHJsLnBhcmFtcy5jb3VudCk7XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0gZWxzZSBpZiAocGt0LmN0cmwucGFyYW1zLndoYXQgPT0gJ3N1YicpIHtcbiAgICAgICAgICAgICAgLy8gY29kZT0yMDQsIHRoZSB0b3BpYyBoYXMgbm8gKHJlZnJlc2hlZCkgc3Vic2NyaXB0aW9ucy5cbiAgICAgICAgICAgICAgY29uc3QgdG9waWMgPSBjYWNoZUdldCgndG9waWMnLCBwa3QuY3RybC50b3BpYyk7XG4gICAgICAgICAgICAgIGlmICh0b3BpYykge1xuICAgICAgICAgICAgICAgIC8vIFRyaWdnZXIgdG9waWMub25TdWJzVXBkYXRlZC5cbiAgICAgICAgICAgICAgICB0b3BpYy5fcHJvY2Vzc01ldGFTdWIoW10pO1xuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuICAgICAgICB9LCAwKTtcbiAgICAgIH0gZWxzZSB7XG4gICAgICAgIHNldFRpbWVvdXQoKCkgPT4ge1xuICAgICAgICAgIGlmIChwa3QubWV0YSkge1xuICAgICAgICAgICAgLy8gSGFuZGxpbmcgYSB7bWV0YX0gbWVzc2FnZS5cblxuICAgICAgICAgICAgLy8gUHJlZmVycmVkIEFQSTogUm91dGUgbWV0YSB0byB0b3BpYywgaWYgb25lIGlzIHJlZ2lzdGVyZWRcbiAgICAgICAgICAgIGNvbnN0IHRvcGljID0gY2FjaGVHZXQoJ3RvcGljJywgcGt0Lm1ldGEudG9waWMpO1xuICAgICAgICAgICAgaWYgKHRvcGljKSB7XG4gICAgICAgICAgICAgIHRvcGljLl9yb3V0ZU1ldGEocGt0Lm1ldGEpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAocGt0Lm1ldGEuaWQpIHtcbiAgICAgICAgICAgICAgZXhlY1Byb21pc2UocGt0Lm1ldGEuaWQsIDIwMCwgcGt0Lm1ldGEsICdNRVRBJyk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIC8vIFNlY29uZGFyeSBBUEk6IGNhbGxiYWNrXG4gICAgICAgICAgICBpZiAodGhpcy5vbk1ldGFNZXNzYWdlKSB7XG4gICAgICAgICAgICAgIHRoaXMub25NZXRhTWVzc2FnZShwa3QubWV0YSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIGlmIChwa3QuZGF0YSkge1xuICAgICAgICAgICAgLy8gSGFuZGxpbmcge2RhdGF9IG1lc3NhZ2VcblxuICAgICAgICAgICAgLy8gUHJlZmVycmVkIEFQSTogUm91dGUgZGF0YSB0byB0b3BpYywgaWYgb25lIGlzIHJlZ2lzdGVyZWRcbiAgICAgICAgICAgIGNvbnN0IHRvcGljID0gY2FjaGVHZXQoJ3RvcGljJywgcGt0LmRhdGEudG9waWMpO1xuICAgICAgICAgICAgaWYgKHRvcGljKSB7XG4gICAgICAgICAgICAgIHRvcGljLl9yb3V0ZURhdGEocGt0LmRhdGEpO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAvLyBTZWNvbmRhcnkgQVBJOiBDYWxsIGNhbGxiYWNrXG4gICAgICAgICAgICBpZiAodGhpcy5vbkRhdGFNZXNzYWdlKSB7XG4gICAgICAgICAgICAgIHRoaXMub25EYXRhTWVzc2FnZShwa3QuZGF0YSk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIGlmIChwa3QucHJlcykge1xuICAgICAgICAgICAgLy8gSGFuZGxpbmcge3ByZXN9IG1lc3NhZ2VcblxuICAgICAgICAgICAgLy8gUHJlZmVycmVkIEFQSTogUm91dGUgcHJlc2VuY2UgdG8gdG9waWMsIGlmIG9uZSBpcyByZWdpc3RlcmVkXG4gICAgICAgICAgICBjb25zdCB0b3BpYyA9IGNhY2hlR2V0KCd0b3BpYycsIHBrdC5wcmVzLnRvcGljKTtcbiAgICAgICAgICAgIGlmICh0b3BpYykge1xuICAgICAgICAgICAgICB0b3BpYy5fcm91dGVQcmVzKHBrdC5wcmVzKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgLy8gU2Vjb25kYXJ5IEFQSSAtIGNhbGxiYWNrXG4gICAgICAgICAgICBpZiAodGhpcy5vblByZXNNZXNzYWdlKSB7XG4gICAgICAgICAgICAgIHRoaXMub25QcmVzTWVzc2FnZShwa3QucHJlcyk7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgfSBlbHNlIGlmIChwa3QuaW5mbykge1xuICAgICAgICAgICAgLy8ge2luZm99IG1lc3NhZ2UgLSByZWFkL3JlY2VpdmVkIG5vdGlmaWNhdGlvbnMgYW5kIGtleSBwcmVzc2VzXG5cbiAgICAgICAgICAgIC8vIFByZWZlcnJlZCBBUEk6IFJvdXRlIHtpbmZvfX0gdG8gdG9waWMsIGlmIG9uZSBpcyByZWdpc3RlcmVkXG4gICAgICAgICAgICBjb25zdCB0b3BpYyA9IGNhY2hlR2V0KCd0b3BpYycsIHBrdC5pbmZvLnRvcGljKTtcbiAgICAgICAgICAgIGlmICh0b3BpYykge1xuICAgICAgICAgICAgICB0b3BpYy5fcm91dGVJbmZvKHBrdC5pbmZvKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgLy8gU2Vjb25kYXJ5IEFQSSAtIGNhbGxiYWNrXG4gICAgICAgICAgICBpZiAodGhpcy5vbkluZm9NZXNzYWdlKSB7XG4gICAgICAgICAgICAgIHRoaXMub25JbmZvTWVzc2FnZShwa3QuaW5mbyk7XG4gICAgICAgICAgICB9XG4gICAgICAgICA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9kZS5fTk9ORSkge1xuICAgICAgICAgICAgdXNlciA9IHRoaXMuX2NhY2hlR2V0VXNlcih1aWQpO1xuICAgICAgICAgICAgaWYgKCF1c2VyKSB7XG4gICAgICAgICAgICAgIHVzZXIgPSB7XG4gICAgICAgICAgICAgICAgdXNlcjogdWlkLFxuICAgICAgICAgICAgICAgIGFjczogYWNzXG4gICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgIHRoaXMuZ2V0TWV0YSh0aGlzLnN0YXJ0TWV0YVF1ZXJ5KCkud2l0aE9uZVN1Yih1bmRlZmluZWQsIHVpZCkuYnVpbGQoKSk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICB1c2VyLmFjcyA9IGFjcztcbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIHVzZXIudXBkYXRlZCA9IG5ldyBEYXRlKCk7XG4gICAgICAgICAgICB0aGlzLl9wcm9jZXNzTWV0YVN1YihbdXNlcl0pO1xuICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAvLyBLbm93biB1c2VyXG4gICAgICAgICAgdXNlci5hY3MudXBkYXRlQWxsKHByZXMuZGFjcyk7XG4gICAgICAgICAgLy8gVXBkYXRlIHVzZXIncyBhY2Nlc3MgbW9kZS5cbiAgICAgICAgICB0aGlzLl9wcm9jZXNzTWV0YVN1Yihbe1xuICAgICAgICAgICAgdXNlcjogdWlkLFxuICAgICAgICAgICAgdXBkYXRlZDogbmV3IERhdGUoKSxcbiAgICAgICAgICAgIGFjczogdXNlci5hY3NcbiAgICAgICAgICB9XSk7XG4gICAgICAgIH1cbiAgICAgICAgYnJlYWs7XG4gICAgICBkZWZhdWx0OlxuICAgICAgICB0aGlzLl90aW5vZGUubG9nZ2VyKFwiSU5GTzogSWdub3JlZCBwcmVzZW5jZSB1cGRhdGVcIiwgcHJlcy53aGF0KTtcbiAgICB9XG5cbiAgICBpZiAodGhpcy5vblByZXMpIHtcbiAgICAgIHRoaXMub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cbiAgICAgIHN0cmluZ1RvRGF0ZSh0aGlzKTtcblxuICAgICAgLy8gJ1AnIHBlcm1pc3Npb24gd2FzIHJlbW92ZWQuIEFsbCB0b3BpY3MgYXJlIG9mZmxpbmUgbm93LlxuICAgICAgaWYgKHR1cm5PZmYpIHtcbiAgICAgICAgdGhpcy5fdGlub2RlLmNhY2hlTWFwKCd0b3BpYycsIChjb250KSA9PiB7XG4gICAgICAgICAgaWYgKGNvbnQub25saW5lKSB7XG4gICAgICAgICAgICBjb250Lm9ubGluZSA9IGZhbHNlO1xuICAgICAgICAgICAgaWYgKGNvbnQuc2Vlbikge1xuICAgICAgICAgICAgICBjb250LnNlZW4ud2hlbiA9IG5ldyBEYXRlKCk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBjb250LnNlZW4gPSB7XG4gICAgICAgICAgICAgICAgd2hlbjogbmV3IERhdGUoKVxuICAgICAgICAgICAgICB9O1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgdGhpcy5fcmVmcmVzaENvbnRhY3QoJ29mZicsIGNvbnQpO1xuICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICB9XG5cbiAgICAgIGlmICh0aGlzLm9uTWV0YURlc2MpIHtcbiAgICAgICAgdGhpcy5vbk1ldGFEZXNjKHRoaXMpO1xuICAgICAgfVxuICAgIH0sXG4gICAgZW51bWVyYWJsZTogdHJ1ZSxcbiAgICBjb25maWd1cmFibGU6IHRydWVcbiAgfSxcblxuICAvLyBPdmVycmlkZSB0aGUgb3JpZ2luYWwgVG9waWMuX3Byb2Nlc3NNZXRhU3ViXG4gIF9wcm9jZXNzTWV0YVN1Yjoge1xuICAgIHZhbHVlOiBmdW5jdGlvbihzdWJzKSB7XG4gICAgICBsZXQgdXBkYXRlQ291bnQgPSAwO1xuICAgICAgc3Vicy5mb3JFYWNoKChzdWIpID0+IHtcbiAgICAgICAgY29uc3QgdG9waWNOYW1lID0gc3ViLnRvcGljO1xuICAgICAgICA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IucmVhZDtcbiAgICAgICAgICB9XG5cbiAgICAgICAgICBpZiAoc3ViLnNlZW4gJiYgc3ViLnNlZW4ud2hlbikge1xuICAgICAgICAgICAgc3ViLnNlZW4ud2hlbiA9IG5ldyBEYXRlKHN1Yi5zZWVuLndoZW4pO1xuICAgICAgICAgIH1cblxuICAgICAgICAgIGNvbnQgPSBtZXJnZU9iaih0aGlzLl90aW5vZGUuZ2V0VG9waWModG9waWNOYW1lKSwgc3ViKTtcbiAgICAgICAgICB0aGlzLl90aW5vZGUuX2RiLnVwZFRvcGljKGNvbnQpO1xuXG4gICAgICAgICAgaWYgKFRpbm9kZS5pc1AyUFRvcGljTmFtZSh0b3BpY05hbWUpKSB7XG4gICAgICAgICAgICB0aGlzLl9jYWNoZVB1dFVzZXIodG9waWNOYW1lLCBjb250KTtcbiAgICAgICAgICAgIHRoaXMuX3Rpbm9kZS5fZGIudXBkVXNlcih0b3BpY05hbWUsIGNvbnQucHVibGljKTtcbiAgICAgICAgICB9XG4gICAgICAgICAgLy8gTm90aWZ5IHRvcGljIG9mIHRoZSB1cGRhdGUgaWYgaXQncyBhbiBleHRlcm5hbCB1cGRhdGUuXG4gICAgICAgICAgaWYgKCFzdWIuX25vRm9yd2FyZGluZykge1xuICAgICAgICAgICAgY29uc3QgdG9waWMgPSB0aGlzLl90aW5vZGUuZ2V0VG9waWModG9waWNOYW1lKTtcbiAgICAgICAgICAgIGlmICh0b3BpYykge1xuICAgICAgICAgICAgICBzdWIuX25vRm9yd2FyZGluZyA9IHRydWU7XG4gICAgICAgICAgICAgIHRvcGljLl9wcm9jZXNzTWV0YURlc2Moc3ViKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICB1cGRhdGVDb3VudCsrO1xuXG4gICAgICAgIGlmICh0aGlzLm9uTWV0YVN1Yikge1xuICAgICAgICAgIHRoaXMub25NZXRhU3ViKGNvbnQpO1xuICAgICAgICB9XG4gICAgICB9KTtcblxuICAgICAgaWYgKHRoaXMub25TdWJzVXBkYXRlZCAmJiB1cGRhdGVDb3VudCA+IDApIHtcbiAgICAgICAgY29uc3Qga2V5cyA9IFtdO1xuICAgICAgICBzdWJzLmZvckVhY2goKHMpID0+IHtcbiAgICAgICAgICBrZXlzLnB1c2gocy50b3BpYyk7XG4gICAgICAgIH0pO1xuICAgICAgICB0aGlzLm9uU3Vic1VwZGF0ZWQoa2V5cywgdXBkYXRlQ291bnQpO1xuICAgICAgfVxuICAgIH0sXG4gICAgZW51bWVyYWJsZTogdHJ1ZSxcbiAgICBjb25maWd1cmFibGU6IHRydWVcbiAgfSxcblxuICAvLyBDYWxsZWQgYnkgVGlub2RlIHdoZW4gbWV0YS5zdWIgaXMgcmVjaXZlZC5cbiAgX3Byb2Nlc3NNZXRhQ3JlZHM6IHtcbiAgICB2YWx1ZTogZnVuY3Rpb24oY3JlZHMsIHVwZCkge1xuICAgICAgaWYgKGNyZWRzLmxlbmd0aCA9PSAxICYmIGNyZWRzWzBdID09IFRpbm9kZS5ERUxfQ0hBUikge1xuICAgICAgICBjcmVkcyA9IFtdO1xuICAgICAgfVxuICAgICAgaWYgKHVwZCkge1xuICAgICAgICBjcmVkcy5tYXAoKGNyKSA9PiB7XG4gICAgICAgICAgaWYgKGNyLnZhbCkge1xuICAgICAgICAgICAgLy8gQWRkaW5nIGEgY3JlZGVudGlhbC5cbiAgICAgICAgICAgIGxldCBpZHggPSB0aGlzLl9jcmVkZW50aWFscy5maW5kSW5kZXgoKGVsKSA9PiB7XG4gICAgICAgICAgICAgIHJldHVybiBlbC5tZXRoID09IGNyLm1ldGggJiYgZWwudmFsID09IGNyLnZhbDtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgaWYgKGlkeCA8IDApIHtcbiAgICAgICAgICAgICAgLy8gTm90IGZvdW5kLlxuICAgICAgICAgICAgICBpZiAoIWNyLmRvbmUpIHtcbiAgICAgICAgICAgICAgICAvLyBVbmNvbmZpcm1lZCBjcmVkZW50aWFsIHJlcGxhY2VzIHByZXZpb3VzIHVuY29uZmlybWVkIGNyZWRlbnRpYWwgb2YgdGhlIHNhbWUgbWV0aG9kLlxuICAgICAgICAgICAgICAgIGlkeCA9IHRoaXMuX2NyZWRlbnRpYWxzLmZpbmRJbmRleCgoZWwpID0+IHtcbiAgICAgICAgICAgICAgICAgIHJldHVybiBlbC5tZXRoID09IGNyLm1ldGggJiYgIWVsLmRvbmU7XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgaWYgKGlkeCA+PSAwKSB7XG4gICAgICAgICAgICAgICAgICAvLyBSZW1vdmUgcHJldmlvdXMgdW5jb25maXJtZWQgY3JlZGVudGlhbC5cbiAgICAgICAgICAgICAgICAgIHRoaXMuX2NyZWRlbnRpYWxzLnNwbGljZShpZHgsIDEpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICB0aGlzLl9jcmVkZW50aWFscy5wdXNoKGNyKTtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgIC8vIEZvdW5kLiBNYXliZSBjaGFuZ2UgJ2RvbmUnIHN0YXR1cy5cbiAgICAgICAgICAgICAgdGhpcy5fY3JlZGVudGlhbHNbaWR4XS5kb25lID0gY3IuZG9uZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9IGVsc2UgaWYgKGNyLnJlc3ApIHtcbiAgICAgICAgICAgIC8vIEhhbmRsZSBjcmVkZW50aWFsIGNvbmZpcm1hdGlvbi5cbiAgICAgICAgICAgIGNvbnN0IGlkeCA9IHRoaXMuX2NyZWRlbnRpYWxzLmZpbmRJbmRleCgoZWwpID0+IHtcbiAgICAgICAgICAgICAgcmV0dXJuIGVsLm1ldGggPT0gY3IubWV0aCAmJiAhZWwuZG9uZTtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgaWYgKGlkeCA+PSAwKSB7XG4gICAgICAgICAgICAgIHRoaXMuX2NyZWRlbnRpYWx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ZXMud2hhdCkge1xuICAgICAgICAgIGNhc2UgJ29uJzogLy8gdG9waWMgY2FtZSBvbmxpbmVcbiAgICAgICAgICAgIGNvbnQub25saW5lID0gdHJ1ZTtcbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIGNhc2UgJ29mZic6IC8vIHRvcGljIHdlbnQgb2ZmbGluZVxuICAgICAgICAgICAgaWYgKGNvbnQub25saW5lKSB7XG4gICAgICAgICAgICAgIGNvbnQub25saW5lID0gZmFsc2U7XG4gICAgICAgICAgICAgIGlmIChjb250LnNlZW4pIHtcbiAgICAgICAgICAgICAgICBjb250LnNlZW4ud2hlbiA9IG5ldyBEYXRlKCk7XG4gICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgY29udC5zZWVuID0ge1xuICAgICAgICAgICAgICAgICAgd2hlbjogbmV3IERhdGUoKVxuICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH1cbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIGNhc2UgJ21zZyc6IC8vIG5ldyBtZXNzYWdlIHJlY2VpdmVkXG4gICAgICAgICAgICBjb250Ll91cGRhdGVSZWNlaXZlZChwcmVzLnNlcSwgcHJlcy5hY3QpO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgY2FzZSAndXBkJzogLy8gZGVzYyB1cGRhdGVkXG4gICAgICAgICAgICAvLyBSZXF1ZXN0IHVwZGF0ZWQgc3Vic2NyaXB0aW9uLlxuICAgICAgICAgICAgdGhpcy5nZXRNZXRhKHRoaXMuc3RhcnRNZXRhUXVlcnkoKS53aXRoTGF0ZXJPbmVTdWIocHJlcy5zcmMpLmJ1aWxkKCkpO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgY2FzZSAnYWNzJzogLy8gYWNjZXNzIG1vZGUgY2hhbmdlZFxuICAgICAgICAgICAgaWYgKGNvbnQuYWNzKSB7XG4gICAgICAgICAgICAgIGNvbnQuYWNzLnVwZGF0ZUFsbChwcmVzLmRhY3MpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgY29udC5hY3MgPSBuZXcgQWNjZXNzTW9kZSgpLnVwZGF0ZUFsbChwcmVzLmRhY3MpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY29udC50b3VjaGVkID0gbmV3IERhdGUoKTtcbiAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgIGNhc2UgJ3VhJzpcbiAgICAgICAgICAgIC8vIHVzZXIgYWdlbnQgY2hhbmdlZC5cbiAgICAgICAgICAgIGNvbnQuc2VlbiA9IHtcbiAgICAgICAgICAgICAgd2hlbjogbmV3IERhdGUoKSxcbiAgICAgICAgICAgICAgdWE6IHByZXMudWFcbiAgICAgICAgICAgIH07XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICBjYXNlICdyZWN2JzpcbiAgICAgICAgICAgIC8vIHVzZXIncyBvdGhlciBzZXNzaW9uIG1hcmtlZCBzb21lIG1lc3NnZXMgYXMgcmVjZWl2ZWQuXG4gICAgICAgICAgICBwcmVzLnNlcSA9IHByZXMuc2VxIHwgMDtcbiAgICAgICAgICAgIGNvbnQucmVjdiA9IGNvbnQucmVjdiA/IE1hdGgubWF4KGNvbnQucmVjdiwgcHJlcy5zZXEpIDogcHJlcy5zZXE7XG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICBjYXNlICdyZWFkJzpcbiAgICAgICAgICAgIC8vIHVzZXIncyBvdGhlciBzZXNzaW9uIG1hcmtlZCBzb21lIG1lc3NhZ2VzIGFzIHJlYWQuXG4gICAgICAgICAgICBwcmVzLnNlcSA9IHByZXMuc2VxIHwgMDtcbiAgICAgICAgICAgIGNvbnQucmVhZCA9IGNvbnQucmVhZCA/IE1hdGgubWF4KGNvbnQucmVhZCwgcHJlcy5zZXEpIDogcHJlcy5zZXE7XG4gICAgICAgICAgICBjb250LnJlY3YgPSBjb250LnJlY3YgPyBNYXRoLm1heChjb250LnJlYWQsIGNvbnQucmVjdikgOiBjb250LnJlY3Y7XG4gICAgICAgICAgICBjb250LnVucmVhZCA9IGNvbnQuc2VxIC0gY29udC5yZWFkO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgY2FzZSAnZ29uZSc6XG4gICAgICAgICAgICAvLyB0b3BpYyBkZWxldGVkIG9yIHVuc3Vic2NyaWJlZCBmcm9tLlxuICAgICAgICAgICAgdGhpcy5fdGlub2RlLmNhY2hlRGVsKCd0b3BpYycsIHByZXMuc3JjKTtcbiAgICAgICAgICAgIHRoaXMuX3Rpbm9kZS5fZGIucmVtVG9waWMocHJlcy5zcmMpO1xuICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgY2FzZSAnZGVsJzpcbiAgICAgICAgICAgIC8vIFVwZGF0ZSB0b3BpYy5kZWwgdmFsdWUuXG4gICAgICAgICAgICBicmVhaztcbiAgICAgICAgICBkZWZhdWx0OlxuICAgICAgICAgICAgdGhpcy5fdGlub2RlLmxvZ2dlcihcIklORk86IFVuc3VwcG9ydGVkIHByZXNlbmNlIHVwZGF0ZSBpbiAnbWUnXCIsIHByZXMud2hhdCk7XG4gICAgICAgIH1cblxuICAgICAgICB0aGlzLl9yZWZyZXNoQ29udGFjdChwcmVzLndoYXQsIGNvbnQpO1xuICAgICAgfSBlbHNlIHtcbiAgICAgICAgaWYgKHByZXMud2hhdCA9PSAnYWNzJykge1xuICAgICAgICAgIC8vIE5ldyBzdWJzY3JpcHRpb25zIGFuZCBkZWxldGVkL2Jhbm5lZCBzdWJzY3JpcHRpb25zIGhhdmUgZnVsbFxuICAgICAgICAgIC8vIGFjY2VzcyBtb2RlIChubyArIG9yIC0gaW4gdGhlIGRhY3Mgc3RyaW5nKS4gQ2hhbmdlcyB0byBrbm93biBzdWJzY3JpcHRpb25zIGFyZSBzZW50IGFzXG4gICAgICAgICAgLy8gZGVsdGFzLCBidXQgdGhleSBzaG91bGQgbm90IGhhcHBlbiBoZXJlLl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R1bW15LnRvdWNoZWQgPSBuZXcgRGF0ZSgpO1xuICAgICAgICAgICAgZHVtbXkudG9waWMgPSBwcmVzLnNyYztcbiAgICAgICAgICAgIGR1bW15Lm9ubGluZSA9IGZhbHNlO1xuICAgICAgICAgICAgZHVtbXkuYWNzID0gYWNzO1xuICAgICAgICAgICAgdGhpcy5fdGlub2RlLmF0dGFjaENhY2hlVG9Ub3BpYyhkdW1teSk7XG4gICAgICAgICAgICBkdW1teS5fY2FjaGVQdXRTZWxmKCk7XG4gICAgICAgICAgICB0aGlzLl9kYi51cGRUb3BpYyhkdW1teSk7XG4gICAgICAgICAgfVxuICAgICAgICB9IGVsc2UgaWYgKHByZXMud2hhdCA9PSAndGFncycpIHtcbiAgICAgICAgICB0aGlzLmdldE1ldGEodGhpcy5zdGFydE1ldGFRdWVyeSgpLndpdGhUYWdzKCkuYnVpbGQoKSk7XG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgaWYgKHRoaXMub25QcmVzKSB7XG4gICAgICAgIHRoaXMub25QcmVzKHByZXMpO1xuICAgICAgfVxuICAgIH0sXG4gICAgZW51bWVyYWJsZTogdHJ1ZSxcbiAgICBjb25maWd1cmFibGU6IHRydWVcbiAgfSxcblxuICAvLyBDb250YWN0IGlzIHVwZGF0ZWQsIGV4ZWN1dGUgY2FsbGJhY2tzLlxuICBfcmVmcmVzaENvbnRhY3Q6IHtcbiAgICB2YWx1ZTogZnVuY3Rpb24od2hhdCwgY29udCkge1xuICAgICAgaWYgKHRoaXMub25Db250YWN0VXBkYXRlKSB7XG4gICAgICAgIHRoaXMub25Db250YWN0VXBkYXRlKHdoYXQsIGNvbnQpO1xuICAgICAgfVxuICAgIH0sXG4gICAgZW51bWVyYWJsZTogdHJ1ZSxcbiAgICBjb25maWd1cmFibGU6IHRydWVcbiAgfSxcblxuICAvKipcbiAgICogUHVibGlzaGluZyB0byBUb3BpY01lIGlzIG5vdCBzdXBwb3J0ZWQuIHtAbGluayBUb3BpYyNwdWJsaX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cm4gdmFsO1xufVxuXG5cbmlmICh0eXBlb2YgbW9kdWxlICE9ICd1bmRlZmluZWQnKSB7XG4gIG1vZHVsZS5leHBvcnRzLmpzb25QYXJzZUhlbHBlciA9IGpzb25QYXJzZUhlbHBlcjtcbn1cbiIsIm1vZHVsZS5leHBvcnRzPXtcInZlcnNpb25cIjogXCIwLjE3LjZcIn1cbiJdfQ== diff --git a/umd/tinode.prod.js b/umd/tinode.prod.js index 0d7582a..72edc52 100644 --- a/umd/tinode.prod.js +++ b/umd/tinode.prod.js @@ -1 +1 @@ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Tinode=e()}}((function(){var e={exports:{}};const t=function(e){e&&(this.given="number"==typeof e.given?e.given:t.decode(e.given),this.want="number"==typeof e.want?e.want:t.decode(e.want),this.mode=e.mode?"number"==typeof e.mode?e.mode:t.decode(e.mode):this.given&this.want)};t._NONE=0,t._JOIN=1,t._READ=2,t._WRITE=4,t._PRES=8,t._APPROVE=16,t._SHARE=32,t._DELETE=64,t._OWNER=128,t._BITMASK=t._JOIN|t._READ|t._WRITE|t._PRES|t._APPROVE|t._SHARE|t._DELETE|t._OWNER,t._INVALID=1048576,t._checkFlag=function(e,t,n){if(["given","want","mode"].includes(t=t||"mode"))return 0!=(e[t]&n);throw new Error(`Invalid AccessMode component '${t}'`)},t.decode=function(e){if(!e)return null;if("number"==typeof e)return e&t._BITMASK;if("N"===e||"n"===e)return t._NONE;const n={J:t._JOIN,R:t._READ,W:t._WRITE,P:t._PRES,A:t._APPROVE,S:t._SHARE,D:t._DELETE,O:t._OWNER};let s=t._NONE;for(let t=0;t0)){c=!0;break}r=o-1}return c?{idx:o,exact:!0}:s?{idx:-1}:{idx:a<0?o+1:o}}function i(e,n){const i=s(e,n,!1),r=i.exact&&t?1:0;return n.splice(i.idx,r,e),n}return e=e||function(e,t){return e===t?0:ee?n[n.length-1-e]:void 0},put:function(){let e;e=1==arguments.length&&Array.isArray(arguments[0])?arguments[0]:arguments;for(let t in e)i(e[t],n)},delAt:function(e){let t=n.splice(e,1);if(t&&t.length>0)return t[0]},delRange:function(e,t){return n.splice(e,t-e)},length:function(){return n.length},reset:function(){n=[]},forEach:function(e,t,s,i){t|=0,s=s||n.length;for(let r=t;r=20&&n.length<=24){const e=new Date(n);if(!isNaN(e))return e}else if("acs"===t&&"object"==typeof n)return new e(n);return n},s=s.exports;var i={exports:{}};const{jsonParseHelper:r}=s;let o,a;function c(e,t,n,s){let i=null;return["http","https","ws","wss"].includes(t)&&("/"!==(i=`${t}://${e}`).charAt(i.length-1)&&(i+="/"),i+="v"+n+"/channels",["http","https"].includes(t)&&(i+="/lp"),i+="?apikey="+s),i}const u=function(e,t,n){let s=e.host;const i=e.secure,h=e.apiKey,l=t,d=n;let f=null,p=0,g=!1;const m=(e,...t)=>{u.logger&&u.logger(e,...t)};function _(){clearTimeout(f);const e=Math.pow(2,p)*(1+.3*Math.random())*2e3;p=p>=10?p:p+1,this.onAutoreconnectIteration&&this.onAutoreconnectIteration(e),f=setTimeout(()=>{if(m(`Reconnecting, iter=${p}, timeout=${e}`),g)this.onAutoreconnectIteration&&this.onAutoreconnectIteration(-1);else{const e=this.connect();this.onAutoreconnectIteration?this.onAutoreconnectIteration(0,e):e.catch(()=>{})}},e)}function b(){clearTimeout(f),f=null}let w=!1;if("lp"===e.transport?(function(e){let t=null,n=null,o=null;e.connect=function(o,u){if(g=!1,n){if(!u)return Promise.resolve();n.onreadystatechange=void 0,n.abort(),n=null}return o&&(s=o),new Promise((function(o,u){const f=c(s,i?"https":"http",l,h);m("Connecting to:",f),(n=function n(s,i,o){let c=new a,u=!1;return c.onreadystatechange=function(a){if(4==c.readyState)if(201==c.status){let o=JSON.parse(c.responseText,r);t=s+"&sid="+o.ctrl.params.sid,(c=n(t)).send(null),e.onOpen&&e.onOpen(),i&&(u=!0,i()),d&&b()}else if(c.status<400)e.onMessage&&e.onMessage(c.responseText),(c=n(t)).send(null);else{if(o&&!u&&(u=!0,o(c.responseText)),e.onMessage&&c.responseText&&e.onMessage(c.responseText),e.onDisconnect){const t=c.status||(g?418:503),n=c.responseText||(g?"Disconnected by client":"Connection failed");e.onDisconnect(new Error(n+" ("+t+")"),t)}c=null,!g&&d&&_.call(e)}},c.open("GET",s,!0),c}(f,o,u)).send(null)})).catch(e=>{m("LP connection failed:",e)})},e.reconnect=function(t){b(),e.connect(null,t)},e.disconnect=function(){g=!0,b(),o&&(o.onreadystatechange=void 0,o.abort(),o=null),n&&(n.onreadystatechange=void 0,n.abort(),n=null),e.onDisconnect&&e.onDisconnect(new Error("Disconnected by client (418)"),418),t=null},e.sendText=function(e){if(!(o=function(e){const t=new a;return t.onreadystatechange=function(e){if(4==t.readyState&&t.status>=400)throw new Error("LP sender failed, "+t.status)},t.open("POST",e,!0),t}(t))||1!=o.readyState)throw new Error("Long poller failed to connect");o.send(e)},e.isConnected=function(){return n&&!0},e.transport=function(){return"lp"},e.probe=function(){e.sendText("1")}}(this),w=!0):"ws"===e.transport&&(function(e){let t=null;e.connect=function(n,r){if(g=!1,t){if(!r&&t.readyState==t.OPEN)return Promise.resolve();t.close(),t=null}return n&&(s=n),new Promise((function(n,r){const a=c(s,i?"wss":"ws",l,h);m("Connecting to: ",a);const u=new o(a);u.onerror=function(e){r(e)},u.onopen=function(t){d&&b(),e.onOpen&&e.onOpen(),n()},u.onclose=function(n){if(t=null,e.onDisconnect){const t=g?418:503;e.onDisconnect(new Error(g?"Disconnected by client":"Connection failed ("+t+")"),t)}!g&&d&&_.call(e)},u.onmessage=function(t){e.onMessage&&e.onMessage(t.data)},t=u}))},e.reconnect=function(t){b(),e.connect(null,t)},e.disconnect=function(){g=!0,b(),t&&(t.close(),t=null)},e.sendText=function(e){if(!t||t.readyState!=t.OPEN)throw new Error("Websocket is not connected");t.send(e)},e.isConnected=function(){return t&&t.readyState==t.OPEN},e.transport=function(){return"ws"},e.probe=function(){e.sendText("1")}}(this),w=!0),!w)throw m("Unknown or invalid network transport. Running under Node? Call 'Tinode.setNetworkProviders()'."),new Error("Unknown or invalid network transport. Running under Node? Call 'Tinode.setNetworkProviders()'.");this.backoffReset=function(){p=0},this.onMessage=void 0,this.onDisconnect=void 0,this.onOpen=void 0,this.onAutoreconnectIteration=void 0,this.logger=void 0};u.setNetworkProviders=function(e,t){o=e,a=t},u.NETWORK_ERROR=503,u.NETWORK_ERROR_TEXT="Connection failed",u.NETWORK_USER=418,u.NETWORK_USER_TEXT="Disconnected by client",i.exports=u,i=i.exports;var h={exports:{}};let l;const d=function(e,t){e=e||function(){},t=t||function(){};let n=null,s=!1;const i=["created","updated","deleted","read","recv","seq","clear","defacs","creds","public","private","touched"];function r(e,t){const n=e||{};return["topic","seq","ts","_status","from","head","content"].forEach(e=>{t.hasOwnProperty(e)&&(n[e]=t[e])}),n}function o(e,i,r){return n?new Promise((s,o)=>{const a=n.transaction([e]);a.onerror=n=>{t("PCache","mapObjects",e,n.target.error),o(n.target.error)},a.objectStore(e).getAll().onsuccess=e=>{i&&e.target.result.forEach(e=>{i.call(r,e)}),s(e.target.result)}}):s?Promise.resolve([]):Promise.reject(new Error("not initialized"))}return{initDatabase:function(){return new Promise((i,r)=>{const o=l.open("tinode-web",1);o.onsuccess=e=>{n=e.target.result,s=!1,i(n)},o.onerror=n=>{t("PCache","failed to initialize",n),r(n.target.error),e(n.target.error)},o.onupgradeneeded=function(s){(n=s.target.result).onerror=function(n){t("PCache","failed to create storage",n),e(n.target.error)},n.createObjectStore("topic",{keyPath:"name"}),n.createObjectStore("user",{keyPath:"uid"}),n.createObjectStore("subscription",{keyPath:["topic","uid"]}),n.createObjectStore("message",{keyPath:["topic","seq"]})}})},deleteDatabase:function(){return new Promise((e,i)=>{const r=l.deleteDatabase("tinode-web");r.onblocked=function(e){n&&n.close()},r.onsuccess=t=>{n=null,s=!0,e(!0)},r.onerror=e=>{t("PCache","deleteDatabase",e.target.error),i(e.target.error)}})},isReady:function(){return!!n},updTopic:function(e){return this.isReady()?new Promise((s,r)=>{const o=n.transaction(["topic"],"readwrite");o.oncomplete=e=>{s(e.target.result)},o.onerror=e=>{t("PCache","updTopic",e.target.error),r(e.target.error)};const a=o.objectStore("topic").get(e.name);a.onsuccess=t=>{o.objectStore("topic").put(function(e,t){const n=e||{name:t.name};return i.forEach(e=>{t.hasOwnProperty(e)&&(n[e]=t[e])}),Array.isArray(t._tags)&&(n.tags=t._tags),t.acs&&(n.acs=t.getAccessMode().jsonHelper()),n}(a.result,e)),o.commit()}}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},remTopic:function(e){return this.isReady()?new Promise((s,i)=>{const r=n.transaction(["topic","subscription","message"],"readwrite");r.oncomplete=e=>{s(e.target.result)},r.onerror=e=>{t("PCache","remTopic",e.target.error),i(e.target.error)},r.objectStore("topic").delete(IDBKeyRange.only(e)),r.objectStore("subscription").delete(IDBKeyRange.bound([e,"-"],[e,"~"])),r.objectStore("message").delete(IDBKeyRange.bound([e,0],[e,Number.MAX_SAFE_INTEGER])),r.commit()}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},mapTopics:function(e,t){return o("topic",e,t)},deserializeTopic:function(e,t){!function(e,t){i.forEach(n=>{t.hasOwnProperty(n)&&(e[n]=t[n])}),Array.isArray(t.tags)&&(e._tags=t.tags),t.acs&&e.setAccessMode(t.acs),e.seq|=0,e.read|=0,e.unread=Math.max(0,e.seq-e.read)}(e,t)},updUser:function(e,i){if(!(arguments.length<2||void 0===i))return this.isReady()?new Promise((s,r)=>{const o=n.transaction(["user"],"readwrite");o.oncomplete=e=>{s(e.target.result)},o.onerror=e=>{t("PCache","updUser",e.target.error),r(e.target.error)},o.objectStore("user").put({uid:e,public:i}),o.commit()}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},remUser:function(e){return this.isReady()?new Promise((s,i)=>{const r=n.transaction(["user"],"readwrite");r.oncomplete=e=>{s(e.target.result)},r.onerror=e=>{t("PCache","remUser",e.target.error),i(e.target.error)},r.objectStore("user").delete(IDBKeyRange.only(e)),r.commit()}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},mapUsers:function(e,t){return o("user",e,t)},getUser:function(e){return this.isReady()?new Promise((s,i)=>{const r=n.transaction(["user"]);r.oncomplete=e=>{const t=e.target.result;s({user:t.uid,public:t.public})},r.onerror=e=>{t("PCache","getUser",e.target.error),i(e.target.error)},r.objectStore("user").get(e)}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},updSubscription:function(e,i,r){return this.isReady()?new Promise((s,o)=>{const a=n.transaction(["subscription"],"readwrite");a.oncomplete=e=>{s(e.target.result)},a.onerror=e=>{t("PCache","updSubscription",e.target.error),o(e.target.error)},a.objectStore("subscription").get([e,i]).onsuccess=t=>{a.objectStore("subscription").put(function(e,t,n,s){const i=e||{topic:t,uid:n};return["updated","mode","read","recv","clear","lastSeen","userAgent"].forEach(e=>{s.hasOwnProperty(e)&&(i[e]=s[e])}),i}(t.target.result,e,i,r)),a.commit()}}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},mapSubscriptions:function(e,i,r){return this.isReady()?new Promise((s,o)=>{const a=n.transaction(["subscription"]);a.onerror=e=>{t("PCache","mapSubscriptions",e.target.error),o(e.target.error)},a.objectStore("subscription").getAll(IDBKeyRange.bound([e,"-"],[e,"~"])).onsuccess=e=>{i&&e.target.result.forEach(e=>{i.call(r,e)}),s(e.target.result)}}):s?Promise.resolve([]):Promise.reject(new Error("not initialized"))},addMessage:function(e){return this.isReady()?new Promise((s,i)=>{const o=n.transaction(["message"],"readwrite");o.onsuccess=e=>{s(e.target.result)},o.onerror=e=>{t("PCache","addMesssage",e.target.error),i(e.target.error)},o.objectStore("message").add(r(null,e)),o.commit()}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},updMessageStatus:function(e,i,o){return this.isReady()?new Promise((s,a)=>{const c=n.transaction(["message"],"readwrite");c.onsuccess=e=>{s(e.target.result)},c.onerror=e=>{t("PCache","updMessageStatus",e.target.error),a(e.target.error)};const u=c.objectStore("message").get(IDBKeyRange.only([e,i]));u.onsuccess=t=>{const n=u.result||t.target.result;n&&n._status!=o?(c.objectStore("message").put(r(n,{topic:e,seq:i,_status:o})),c.commit()):c.commit()}}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},remMessages:function(e,i,r){return this.isReady()?new Promise((s,o)=>{i||r||(i=0,r=Number.MAX_SAFE_INTEGER);const a=r>0?IDBKeyRange.bound([e,i],[e,r],!1,!0):IDBKeyRange.only([e,i]),c=n.transaction(["message"],"readwrite");c.onsuccess=e=>{s(e.target.result)},c.onerror=e=>{t("PCache","remMessages",e.target.error),o(e.target.error)},c.objectStore("message").delete(a),c.commit()}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},readMessages:function(e,i,r,o){return this.isReady()?new Promise((s,a)=>{const c=(i=i||{}).from>0?i.from:0,u=i.to>0?i.to:Number.MAX_SAFE_INTEGER,h=0|i.limit,l=[],d=IDBKeyRange.bound([e,c],[e,u],!1,!0),f=n.transaction(["message"]);f.onerror=e=>{t("PCache","readMessages",e.target.error),a(e.target.error)},f.objectStore("message").openCursor(d,"prev").onsuccess=e=>{const t=e.target.result;t?(r&&r.call(o,t.value),l.push(t.value),h<=0||l.length"},close:function(){return""}},EM:{open:function(){return""},close:function(){return""}},DL:{open:function(){return""},close:function(){return""}},CO:{open:function(){return""},close:function(){return""}},BR:{open:function(){return"
"},close:function(){return""}},HD:{open:function(){return""},close:function(){return""}},HL:{open:function(){return''},close:function(){return""}},LN:{open:function(e){return''},close:function(e){return""},props:function(e){return e?{href:e.url,target:"_blank"}:null}},MN:{open:function(e){return''},close:function(e){return""},props:function(e){return e?{name:e.val}:null}},HT:{open:function(e){return''},close:function(e){return""},props:function(e){return e?{name:e.val}:null}},BN:{open:function(e){return""},props:function(e){return e?{"data-act":e.act,"data-val":e.val,"data-name":e.name,"data-ref":e.ref}:null}},IM:{open:function(e){const t=b(e._tempPreview,e.mime),n=_(e.val,e.mime,v.logger),s=e.ref||n;return(e.name?'':"")+''},close:function(e){return e.name?"":""},props:function(e){return e?{src:b(e._tempPreview,e.mime)||e.ref||_(e.val,e.mime,v.logger),title:e.name,"data-width":e.width,"data-height":e.height,"data-name":e.name,"data-size":e.val?.75*e.val.length|0:0|e.size,"data-mime":e.mime}:null}},FM:{open:function(e){return"
"},close:function(e){return"
"}},RW:{open:function(e){return"
"},close:function(e){return"
"}}},v=function(){};v.parse=function(e){if("string"!=typeof e)return null;const t=e.split(/\r?\n/),n=[],s={},i=[];t.map((function(e){let t,r,o=[];if(p.map((function(t){o=o.concat(function(e,t,n,s){const i=[];let r=0,o=e.slice(0);for(;o.length>0;){const a=t.exec(o);if(null==a)break;let c=a.index+a[0].lastIndexOf(a[1]);o=o.slice(c+1),r=(c+=r)+1;const u=n?n.exec(o):null;if(null==u)break;let h=u.index+u[0].indexOf(u[1]);o=o.slice(h+1),r=(h+=r)+1,i.push({text:e.slice(c+1,h),children:[],start:c,end:h,type:s})}return i}(e,t.start,t.end,t.name))})),0==o.length)r={txt:e};else{o.sort((function(e,t){return e.start-t.start})),o=function e(t){if(0==t.length)return[];const n=[t[0]];let s=t[0];for(let i=1;is.end?(n.push(t[i]),s=t[i]):t[i].endn&&r.push({text:t.slice(n,s.start)});const a={type:s.type},c=e(t,s.start+1,s.end,s.children);c.length>0?a.children=c:a.text=s.text,r.push(a),n=s.end+1}return ns;return s=e.offset+e.len,t}))}(r.txt)).length>0){const e=[];for(let i in t){const r=t[i];let o=s[r.unique];o||(o=n.length,s[r.unique]=o,n.push({tp:r.type,data:r.data})),e.push({at:r.offset,len:r.len,key:o})}r.ent=e}i.push(r)}));const r={txt:""};if(i.length>0){r.txt=i[0].txt,r.fmt=(i[0].fmt||[]).concat(i[0].ent||[]);for(let e=1;e0&&(r.ent=n)}return r},v.init=function(e){return"string"!=typeof e?null:{txt:e}},v.append=function(e,t){if(null==e)return t;if(null==t)return e;e.txt=e.txt||"",t.txt=t.txt||"";const n=e.txt.length;return e.txt+=t.txt,Array.isArray(t.fmt)&&(e.fmt=e.fmt||[],Array.isArray(t.ent)&&(e.ent=e.ent||[]),t.fmt.forEach(s=>{const i={at:s.at+n,len:s.len};s.tp?i.tp=s.tp:(i.key=e.ent.length,e.ent.push(t.ent[s.key||0])),e.fmt.push(i)})),e},v.insertImage=function(e,t,n){(e=e||{txt:" "}).ent=e.ent||[],e.fmt=e.fmt||[],e.fmt.push({at:t,len:1,key:e.ent.length});const s={tp:"IM",data:{mime:n.mime,val:n.preview,width:n.width,height:n.height,name:n.filename,size:0|n.size,ref:n.refurl}};return n.urlPromise&&(s.data._tempPreview=n._tempPreview,s.data._processing=!0,n.urlPromise.then(e=>{s.data.ref=e,s.data._tempPreview=void 0,s.data._processing=void 0},e=>{s.data._processing=void 0})),e.ent.push(s),e},v.appendImage=function(e,t){return(e=e||{txt:""}).txt+=" ",v.insertImage(e,e.txt.length-1,t)},v.attachFile=function(e,t){(e=e||{txt:""}).ent=e.ent||[],e.fmt=e.fmt||[],e.fmt.push({at:-1,len:0,key:e.ent.length});const n={tp:"EX",data:{mime:t.mime,val:t.data,name:t.filename,ref:t.refurl,size:0|t.size}};return t.urlPromise&&(n.data._processing=!0,t.urlPromise.then(e=>{n.data.ref=e,n.data._processing=void 0},e=>{n.data._processing=void 0})),e.ent.push(n),e},v.wrapAsForm=function(e,t,n){return"string"==typeof e&&(e={txt:e}),e.fmt=e.fmt||[],e.fmt.push({at:t,len:n,tp:"FM"}),e},v.insertButton=function(e,t,n,s,i,r,o){return"string"==typeof e&&(e={txt:e}),!e||!e.txt||e.txt.length{let t,n=e.tp;return n||(e.key=e.key||0,r[e.key]&&(t=r[e.key].data,n=r[e.key].tp)),{tp:n=n||"HD",data:t,at:e.at,len:e.len}}),function e(t,n,s,i,r,o){const a=[];for(let c=0;c0)for(let t in e.ent)if(e.ent[t]&&e.ent[t].data&&"EX"==e.ent[t].tp)return!0;return!1},v.attachments=function(e,t,n){if(e.ent&&e.ent.length>0)for(let s in e.ent)e.ent[s]&&"EX"==e.ent[s].tp&&e.ent[s].data&&t.call(n,e.ent[s].data,s,"EX")},v.hasEntities=function(e){return e.ent&&e.ent.length>0},v.entities=function(e,t,n){if(e.ent&&e.ent.length>0)for(let s in e.ent)e.ent[s]&&t.call(n,e.ent[s].data,s,e.ent[s].tp)},v.getDownloadUrl=function(e){let t=null;return"application/json"!=e.mime&&e.val?t=_(e.val,e.mime,v.logger):"string"==typeof e.ref&&(t=e.ref),t},v.isProcessing=function(e){return!!e._processing},v.getPreviewUrl=function(e){return e.val?_(e.val,e.mime,v.logger):null},v.getEntitySize=function(e){return e.size?e.size:e.val?.75*e.val.length|0:0},v.getEntityMimeType=function(e){return e.mime||"text/plain"},v.tagName=function(e){return e?m[e]?m[e].name:"_UNKN":void 0},v.attrValue=function(e,t){if(t&&w[e])return w[e].props(t)},v.getContentType=function(){return"text/x-drafty"},v.preview=function(e,t){if(!e||t<=0||"object"!=typeof e)return null;const{txt:n,fmt:s,ent:i}=e,r={txt:""};"string"==typeof n&&(r.txt=n.substr(0,t));let o=r.txt.length;if(Array.isArray(s)&&s.length>0){const e=[];let t=0,n=0;if(s.forEach(s=>{s.at|=0,s.at0&&(r.ent=[]);let a=0;s.forEach(t=>{if(t.att.key&&"number"==typeof e[t.key]))return;n.key=e[t.key],r.ent[n.key]=function(e){let t={tp:e.tp};if(e.data&&0!=Object.entries(e.data).length){const n={};["mime","name","width","height","size"].forEach(t=>{const s=e.data[t];s&&(n[t]=s)}),0!=Object.entries(n).length&&(t.data=n)}return t}(i[t.key])}r.fmt[a++]=n}})}return r},f.exports=v,f=f.exports;var S={exports:{}};const{jsonParseHelper:M}=s;let y;const T=function(e,t){this._tinode=e,this._version=t,this._apiKey=e._apiKey,this._authToken=e.getAuthToken(),this._reqId=e.getNextUniqueId(),this.xhr=new y,this.toResolve=null,this.toReject=null,this.onProgress=null,this.onSuccess=null,this.onFailure=null};T.prototype={uploadWithBaseUrl:function(e,t,n,s,i,r){if(!this._authToken)throw new Error("Must authenticate first");const o=this;let a=`/v${this._version}/file/u/`;if(e){let t=e;if(t.endsWith("/")&&(t=t.slice(0,-1)),!t.startsWith("http://")&&!t.startsWith("https://"))throw new Error(`Invalid base URL '${e}'`);a=t+a}this.xhr.open("POST",a,!0),this.xhr.setRequestHeader("X-Tinode-APIKey",this._apiKey),this.xhr.setRequestHeader("X-Tinode-Auth","Token "+this._authToken.token);const c=new Promise((e,t)=>{this.toResolve=e,this.toReject=t});this.onProgress=s,this.onSuccess=i,this.onFailure=r,this.xhr.upload.onprogress=e=>{e.lengthComputable&&o.onProgress&&o.onProgress(e.loaded/e.total)},this.xhr.onload=function(){let e;try{e=JSON.parse(this.response,M)}catch(t){o._tinode.logger("ERROR: Invalid server response in LargeFileHelper",this.response),e={ctrl:{code:this.status,text:this.statusText}}}this.status>=200&&this.status<300?(o.toResolve&&o.toResolve(e.ctrl.params.url),o.onSuccess&&o.onSuccess(e.ctrl)):this.status>=400?(o.toReject&&o.toReject(new Error(`${e.ctrl.text} (${e.ctrl.code})`)),o.onFailure&&o.onFailure(e.ctrl)):o._tinode.logger("ERROR: Unexpected server response status",this.status,this.response)},this.xhr.onerror=function(e){o.toReject&&o.toReject(new Error("failed")),o.onFailure&&o.onFailure(null)},this.xhr.onabort=function(e){o.toReject&&o.toReject(new Error("upload cancelled by user")),o.onFailure&&o.onFailure(null)};try{const e=new FormData;e.append("file",t),e.set("id",this._reqId),n&&e.set("topic",n),this.xhr.send(e)}catch(u){this.toReject&&this.toReject(u),this.onFailure&&this.onFailure(null)}return c},upload:function(e,t,n,s,i){const r=(this._tinode._secure?"https://":"http://")+this._tinode._host;return this.uploadWithBaseUrl(r,e,t,n,s,i)},download:function(e,t,n,s,i){if(!Tinode.isRelativeURL(e))return void(i&&i(`The URL '${e}' must be relative, not absolute`));if(!this._authToken)return void(i&&i("Must authenticate first"));const r=this;this.xhr.open("GET",e,!0),this.xhr.setRequestHeader("X-Tinode-APIKey",this._apiKey),this.xhr.setRequestHeader("X-Tinode-Auth","Token "+this._authToken.token),this.xhr.responseType="blob",this.onProgress=s,this.xhr.onprogress=function(e){r.onProgress&&r.onProgress(e.loaded)};const o=new Promise((e,t)=>{this.toResolve=e,this.toReject=t});this.xhr.onload=function(){if(200==this.status){const e=document.createElement("a");e.href=window.URL.createObjectURL(new Blob([this.response],{type:n})),e.style.display="none",e.setAttribute("download",t),document.body.appendChild(e),e.click(),document.body.removeChild(e),window.URL.revokeObjectURL(e.href),r.toResolve&&r.toResolve()}else if(this.status>=400&&r.toReject){const e=new FileReader;e.onload=function(){try{const e=JSON.parse(this.result,M);r.toReject(new Error(`${e.ctrl.text} (${e.ctrl.code})`))}catch(e){r._tinode.logger("ERROR: Invalid server response in LargeFileHelper",this.result),r.toReject(e)}},e.readAsText(this.response)}},this.xhr.onerror=function(e){r.toReject&&r.toReject(new Error("failed"))},this.xhr.onabort=function(){r.toReject&&r.toReject(null)};try{this.xhr.send()}catch(a){this.toReject&&this.toReject(a)}return o},cancel:function(){this.xhr&&this.xhr.readyState<4&&this.xhr.abort()},getId:function(){return this._reqId}},T.setNetworkProvider=function(e){y=e},S.exports=T,S=S.exports;var P={exports:{}};const x=function(e){this.topic=e,this.what={}};x.prototype={_get_desc_ims:function(){return this.topic.updated},_get_subs_ims:function(){return this.topic.isP2PType()?this._get_desc_ims():this.topic._lastSubsUpdate},withData:function(e,t,n){return this.what.data={since:e,before:t,limit:n},this},withLaterData:function(e){return this.withData(this.topic._maxSeq>0?this.topic._maxSeq+1:void 0,void 0,e)},withEarlierData:function(e){return this.withData(void 0,this.topic._minSeq>0?this.topic._minSeq:void 0,e)},withDesc:function(e){return this.what.desc={ims:e},this},withLaterDesc:function(){return this.withDesc(this._get_desc_ims())},withSub:function(e,t,n){const s={ims:e,limit:t};return"me"==this.topic.getType()?s.topic=n:s.user=n,this.what.sub=s,this},withOneSub:function(e,t){return this.withSub(e,void 0,t)},withLaterOneSub:function(e){return this.withOneSub(this.topic._lastSubsUpdate,e)},withLaterSub:function(e){return this.withSub(this._get_subs_ims(),e)},withTags:function(){return this.what.tags=!0,this},withCred:function(){return"me"==this.topic.getType()?this.what.cred=!0:this.topic._tinode.logger("ERROR: Invalid topic type for MetaGetBuilder:withCreds",this.topic.getType()),this},withDel:function(e,t){return(e||t)&&(this.what.del={since:e,limit:t}),this},withLaterDel:function(e){return this.withDel(this.topic._maxSeq>0?this.topic._maxDel+1:void 0,e)},build:function(){const e=[],t=this;let n={};return["data","sub","desc","tags","cred","del"].map((function(s){t.what.hasOwnProperty(s)&&(e.push(s),Object.getOwnPropertyNames(t.what[s]).length>0&&(n[s]=t.what[s]))})),e.length>0?n.what=e.join(" "):n=void 0,n}},P.exports=x,P=P.exports;var D="0.17.6-rc1",R={exports:{}};return function(t){(function(){"use strict";const{jsonParseHelper:r}=s,o=D;let a,c,u;"undefined"!=typeof WebSocket&&(a=WebSocket),"undefined"!=typeof XMLHttpRequest&&(c=XMLHttpRequest),"undefined"!=typeof indexedDB&&(u=indexedDB),function(){const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";"undefined"==typeof btoa&&(t.btoa=function(t=""){let n=t,s="";for(let i,r=0,o=0,a=e;n.charAt(0|o)||(a="=",o%1);s+=a.charAt(63&r>>8-o%1*8)){if((i=n.charCodeAt(o+=.75))>255)throw new Error("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");r=r<<8|i}return s}),"undefined"==typeof atob&&(t.atob=function(t=""){let n=t.replace(/=+$/,""),s="";if(n.length%4==1)throw new Error("'atob' failed: The string to be decoded is not correctly encoded.");for(let i,r=0,o=0,a=0;i=n.charAt(a++);~i&&(o=r%4?64*o+i:i,r++%4)?s+=String.fromCharCode(255&o>>(-2*r&6)):0)i=e.indexOf(i);return s}),"undefined"==typeof window&&(t.window={WebSocket:a,XMLHttpRequest:c,indexedDB:u,URL:{createObjectURL:function(){throw new Error("Unable to use URL.createObjectURL in a non-browser application")}}}),i.setNetworkProviders(a,c),S.setNetworkProvider(c),h.setDatabaseProvider(u)}();const l=o||"0.17",d="tinodejs/"+l;function p(e){return e instanceof Date&&!isNaN(e)&&0!=e.getTime()}function g(e){return btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode("0x"+t)})))}function m(t,n,s){if("object"!=typeof n){if(n===v.DEL_CHAR)return;return void 0===n?t:n}if(null===n)return n;if(n instanceof Date&&!isNaN(n))return!t||!(t instanceof Date)||isNaN(t)||t128?"<"+n.length+", bytes: "+n.substring(0,12)+"..."+n.substring(n.length-12)+">":function(t,n){if(n instanceof Date)n=function(e){if(!p(e))return;const t=function(e,t){return"0".repeat((t=t||2)-(""+e).length)+e},n=e.getUTCMilliseconds();return e.getUTCFullYear()+"-"+t(e.getUTCMonth()+1)+"-"+t(e.getUTCDate())+"T"+t(e.getUTCHours())+":"+t(e.getUTCMinutes())+":"+t(e.getUTCSeconds())+(n?"."+t(n,3):"")+"Z"}(n);else if(n instanceof e)n=n.jsonHelper();else if(null==n||!1===n||Array.isArray(n)&&0==n.length||"object"==typeof n&&0==Object.keys(n).length)return;return n}(0,n)}var v=function(e,t){this._host=e.host,this._secure=e.secure,this._appName=e.appName||"Undefined",this._apiKey=e.apiKey,this._browser="",this._platform=e.platform||"web",this._hwos="undefined",this._humanLanguage="xx","undefined"!=typeof navigator&&(this._browser=function(e,t){e=e||"";let n,s="";/reactnative/i.test(t)&&(s="ReactNative; ");let i=(e=e.replace(" (KHTML, like Gecko)","")).match(/(AppleWebKit\/[.\d]+)/i);if(i){const t=["edg","chrome","safari","mobile","version"];let s,r=e.substr(i.index+i[0].length).split(" "),o=[];for(let e=0;en[1].toLowerCase().startsWith(e))]),"Version"==n[1]&&(s=n[2]))}o.sort((e,t)=>e[2]-t[2]),o.length>0?(o[0][0].toLowerCase().startsWith("edg")?o[0][0]="Edge":"OPR"==o[0][0]?o[0][0]="Opera":"Safari"==o[0][0]&&s&&(o[0][1]=s),n=o[0][0]+"/"+o[0][1]):n=i[1]}else n=/firefox/i.test(e)?(i=/Firefox\/([.\d]+)/g.exec(e))?"Firefox/"+i[1]:"Firefox/?":(i=/([\w.]+)\/([.\d]+)/.exec(e))?i[1]+"/"+i[2]:(i=e.split(" "))[0];if((i=n.split("/")).length>1){const e=i[1].split("."),t=e[1]?"."+e[1].substr(0,2):"";n=`${i[0]}/${e[0]}${t}`}return s+n}(navigator.userAgent,navigator.product),this._hwos=navigator.platform,this._humanLanguage=navigator.language||"en-US"),this._loggingEnabled=!1,this._trimLongStrings=!1,this._myUID=null,this._authenticated=!1,this._login=null,this._authToken=null,this._inPacketCount=0,this._messageId=Math.floor(65535*Math.random()+65535),this._serverInfo=null,this._deviceToken=null,this._pendingPromises={},this._expirePromises=null,this.logger=(e,...t)=>{if(this._loggingEnabled){const n=new Date,s=("0"+n.getUTCHours()).slice(-2)+":"+("0"+n.getUTCMinutes()).slice(-2)+":"+("0"+n.getUTCSeconds()).slice(-2)+"."+("00"+n.getUTCMilliseconds()).slice(-3);console.log("["+s+"]",e,t.join(" "))}},i.logger=this.logger,f.logger=this.logger,"lp"!=e.transport&&"ws"!=e.transport&&(e.transport=function(){if("object"==typeof window){if(window.WebSocket)return"ws";if(window.XMLHttpRequest)return"lp"}return null}()),this._connection=new i(e,"0",!0),this._cache={};const n=this.cachePut=(e,t,n)=>{this._cache[e+":"+t]=n},s=this.cacheGet=(e,t)=>this._cache[e+":"+t],o=this.cacheDel=(e,t)=>{delete this._cache[e+":"+t]},a=this.cacheMap=(e,t,n)=>{const s=e?e+":":void 0;for(let i in this._cache)if((!s||0==i.indexOf(s))&&t.call(n,this._cache[i],i))break};if(this.attachCacheToTopic=e=>{e._tinode=this,e._cacheGetUser=e=>{const t=s("user",e);if(t)return{user:e,public:m({},t)}},e._cachePutUser=(e,t)=>n("user",e,m({},t.public)),e._cacheDelUser=e=>o("user",e),e._cachePutSelf=()=>n("topic",e.name,e),e._cacheDelSelf=()=>o("topic",e.name)},this._persist=e.persist,this._db=h(e=>{this.logger("DB",e)},this.logger),this._persist){const e=[];this._db.initDatabase().then(()=>this._db.mapTopics(t=>{let n=this.cacheGet("topic",t.name);n||(n="me"==t.name?new y:"fnd"==t.name?new T:new M(t.name),this._db.deserializeTopic(n,t),this.attachCacheToTopic(n),n._cachePutSelf(),e.push(n._loadMessages(this._db)))})).then(()=>this._db.mapUsers(e=>n("user",e.uid,m({},e.public)))).then(()=>Promise.all(e)).then(()=>{t&&t(),this.logger("Persistent cache initialized.")})}else this._db.deleteDatabase().then(()=>{t&&t()});const c=(e,t,n,s)=>{const i=this._pendingPromises[e];i&&(delete this._pendingPromises[e],t>=200&&t<400?i.resolve&&i.resolve(n):i.reject&&i.reject(new Error(`${s} (${t})`)))},u=e=>{let t=null;return e&&(t=new Promise((t,n)=>{this._pendingPromises[e]={resolve:t,reject:n,ts:new Date}})),t},g=this.getNextUniqueId=()=>0!=this._messageId?""+this._messageId++:void 0,_=()=>this._appName+" ("+(this._browser?this._browser+"; ":"")+this._hwos+"); "+d;this.initPacket=(e,t)=>{switch(e){case"hi":return{hi:{id:g(),ver:l,ua:_(),dev:this._deviceToken,lang:this._humanLanguage,platf:this._platform}};case"acc":return{acc:{id:g(),user:null,scheme:null,secret:null,login:!1,tags:null,desc:{},cred:{}}};case"login":return{login:{id:g(),scheme:null,secret:null}};case"sub":return{sub:{id:g(),topic:t,set:{},get:{}}};case"leave":return{leave:{id:g(),topic:t,unsub:!1}};case"pub":return{pub:{id:g(),topic:t,noecho:!1,head:null,content:{}}};case"get":return{get:{id:g(),topic:t,what:null,desc:{},sub:{},data:{}}};case"set":return{set:{id:g(),topic:t,desc:{},sub:{},tags:[]}};case"del":return{del:{id:g(),topic:t,what:null,delseq:null,user:null,hard:!1}};case"note":return{note:{topic:t,what:null,seq:void 0}};default:throw new Error("Unknown packet type requested: "+e)}},this.send=(e,t)=>{let n;t&&(n=u(t)),e=function e(t){return Object.keys(t).forEach(n=>{"_"==n[0]?delete t[n]:t[n]?Array.isArray(t[n])&&0==t[n].length?delete t[n]:t[n]?t[n]instanceof Date?p(t[n])||delete t[n]:"object"==typeof t[n]&&(e(t[n]),0==Object.getOwnPropertyNames(t[n]).length&&delete t[n]):delete t[n]:delete t[n]}),t}(e);let s=JSON.stringify(e);this.logger("out: "+(this._trimLongStrings?JSON.stringify(e,w):s));try{this._connection.sendText(s)}catch(r){if(!t)throw r;c(t,i.NETWORK_ERROR,null,r.message)}return n},this.loginSuccessful=e=>e.params&&e.params.user?(this._myUID=e.params.user,this._authenticated=e&&e.code>=200&&e.code<300,e.params&&e.params.token&&e.params.expires?this._authToken={token:e.params.token,expires:new Date(e.params.expires)}:this._authToken=null,this.onLogin&&this.onLogin(e.code,e.text),e):e,this._connection.onMessage=e=>{if(!e)return;if(this._inPacketCount++,this.onRawMessage&&this.onRawMessage(e),"0"===e)return void(this.onNetworkProbe&&this.onNetworkProbe());let t=JSON.parse(e,r);t?(this.logger("in: "+(this._trimLongStrings?JSON.stringify(t,w):e)),this.onMessage&&this.onMessage(t),t.ctrl?(this.onCtrlMessage&&this.onCtrlMessage(t.ctrl),t.ctrl.id&&c(t.ctrl.id,t.ctrl.code,t.ctrl,t.ctrl.text),setTimeout(()=>{if(205==t.ctrl.code&&"evicted"==t.ctrl.text){const e=s("topic",t.ctrl.topic);e&&(e._resetSub(),t.ctrl.params&&t.ctrl.params.unsub&&e._gone())}else if(t.ctrl.code<300&&t.ctrl.params)if("data"==t.ctrl.params.what){const e=s("topic",t.ctrl.topic);e&&e._allMessagesReceived(t.ctrl.params.count)}else if("sub"==t.ctrl.params.what){const e=s("topic",t.ctrl.topic);e&&e._processMetaSub([])}},0)):setTimeout(()=>{if(t.meta){const e=s("topic",t.meta.topic);e&&e._routeMeta(t.meta),t.meta.id&&c(t.meta.id,200,t.meta,"META"),this.onMetaMessage&&this.onMetaMessage(t.meta)}else if(t.data){const e=s("topic",t.data.topic);e&&e._routeData(t.data),this.onDataMessage&&this.onDataMessage(t.data)}else if(t.pres){const e=s("topic",t.pres.topic);e&&e._routePres(t.pres),this.onPresMessage&&this.onPresMessage(t.pres)}else if(t.info){const e=s("topic",t.info.topic);e&&e._routeInfo(t.info),this.onInfoMessage&&this.onInfoMessage(t.info)}else this.logger("ERROR: Unknown packet received.")},0)):(this.logger("in: "+e),this.logger("ERROR: failed to parse data"))},this._connection.onOpen=()=>{this._expirePromises||(this._expirePromises=setInterval(()=>{const e=new Error("Timeout (504)"),t=new Date((new Date).getTime()-5e3);for(let n in this._pendingPromises){let s=this._pendingPromises[n];s&&s.ts{this.onAutoreconnectIteration&&this.onAutoreconnectIteration(e,t)},this._connection.onDisconnect=(e,t)=>{this._inPacketCount=0,this._serverInfo=null,this._authenticated=!1,this._expirePromises&&(clearInterval(this._expirePromises),this._expirePromises=null),a("topic",(e,t)=>{e._resetSub()});for(let n in this._pendingPromises){const t=this._pendingPromises[n];t&&t.reject&&t.reject(e)}this._pendingPromises={},this.onDisconnect&&this.onDisconnect(e)}};v.credential=function(e,t,n,s){return"object"==typeof e&&({val:t,params:n,resp:s,meth:e}=e),e&&(t||s)?[{meth:e,val:t,resp:s,params:n}]:null},v.topicType=function(e){return{me:"me",fnd:"fnd",grp:"grp",new:"grp",nch:"grp",chn:"grp",usr:"p2p",sys:"sys"}["string"==typeof e?e.substring(0,3):"xxx"]},v.isMeTopicName=function(e){return"me"==v.topicType(e)},v.isGroupTopicName=function(e){return"grp"==v.topicType(e)},v.isP2PTopicName=function(e){return"p2p"==v.topicType(e)},v.isCommTopicName=function(e){return v.isP2PTopicName(e)||v.isGroupTopicName(e)},v.isNewGroupTopicName=function(e){return"string"==typeof e&&("new"==e.substring(0,3)||"nch"==e.substring(0,3))},v.isChannelTopicName=function(e){return"string"==typeof e&&("chn"==e.substring(0,3)||"nch"==e.substring(0,3))},v.getVersion=function(){return l},v.setNetworkProviders=function(e,t){a=e,c=t},v.setDatabaseProvider=function(e){u=e},v.getLibrary=function(){return d},v.MESSAGE_STATUS_NONE=0,v.MESSAGE_STATUS_QUEUED=1,v.MESSAGE_STATUS_SENDING=2,v.MESSAGE_STATUS_FAILED=3,v.MESSAGE_STATUS_SENT=4,v.MESSAGE_STATUS_RECEIVED=5,v.MESSAGE_STATUS_READ=6,v.MESSAGE_STATUS_TO_ME=7,v.MESSAGE_STATUS_DEL_RANGE=8,v.DEL_CHAR="\u2421",v.isNullValue=function(e){return e===v.DEL_CHAR},v.isRelativeURL=function(e){return!/^\s*([a-z][a-z0-9+.-]*:|\/\/)/im.test(e)},v.MAX_MESSAGE_SIZE="maxMessageSize",v.MAX_SUBSCRIBER_COUNT="maxSubscriberCount",v.MAX_TAG_COUNT="maxTagCount",v.MAX_FILE_UPLOAD_SIZE="maxFileUploadSize",v.prototype={connect:function(e){return this._connection.connect(e)},reconnect:function(e){this._connection.reconnect(e)},disconnect:function(){this._connection.disconnect()},clearStorage:function(){return this._db.isReady()?this._db.deleteDatabase():Promise.resolve()},initStorage:function(){return this._db.isReady()?Promise.resolve():this._db.initDatabase()},networkProbe:function(){this._connection.probe()},isConnected:function(){return this._connection.isConnected()},isAuthenticated:function(){return this._authenticated},authorizeURL:function(e){if(!e)return e;if(v.isRelativeURL(e)){const t="scheme://host/",n=new URL(e,t);this._apiKey&&n.searchParams.append("apikey",this._apiKey),this._authToken.token&&(n.searchParams.append("auth","token"),n.searchParams.append("secret",this._authToken.token)),e=n.toString().substring(t.length-1)}return e},account:function(e,t,n,s,i){const r=this.initPacket("acc");return r.acc.user=e,r.acc.scheme=t,r.acc.secret=n,r.acc.login=s,i&&(r.acc.desc.defacs=i.defacs,r.acc.desc.public=i.public,r.acc.desc.private=i.private,r.acc.tags=i.tags,r.acc.cred=i.cred,r.acc.token=i.token),this.send(r,r.acc.id)},createAccount:function(e,t,n,s){let i=this.account("new",e,t,n,s);return n&&(i=i.then(e=>this.loginSuccessful(e))),i},createAccountBasic:function(e,t,n){return e=e||"",t=t||"",this.createAccount("basic",g(e+":"+t),!0,n)},updateAccountBasic:function(e,t,n,s){return t=t||"",n=n||"",this.account(e,"basic",g(t+":"+n),!1,s)},hello:function(){const e=this.initPacket("hi");return this.send(e,e.hi.id).then(e=>(this._connection.backoffReset(),e.params&&(this._serverInfo=e.params),this.onConnect&&this.onConnect(),e)).catch(e=>{this._connection.reconnect(!0),this.onDisconnect&&this.onDisconnect(e)})},setDeviceToken:function(e){let t=!1;return(e=e||null)!=this._deviceToken&&(this._deviceToken=e,this.isConnected()&&this.isAuthenticated()&&(this.send({hi:{dev:e||v.DEL_CHAR}}),t=!0)),t},login:function(e,t,n){const s=this.initPacket("login");return s.login.scheme=e,s.login.secret=t,s.login.cred=n,this.send(s,s.login.id).then(e=>this.loginSuccessful(e))},loginBasic:function(e,t,n){return this.login("basic",g(e+":"+t),n).then(t=>(this._login=e,t))},loginToken:function(e,t){return this.login("token",e,t)},requestResetAuthSecret:function(e,t,n){return this.login("reset",g(e+":"+t+":"+n))},getAuthToken:function(){return this._authToken&&this._authToken.expires.getTime()>Date.now()?this._authToken:(this._authToken=null,null)},setAuthToken:function(e){this._authToken=e},subscribe:function(e,t,n){const s=this.initPacket("sub",e);return e||(e="new"),s.sub.get=t,n&&(n.sub&&(s.sub.set.sub=n.sub),n.desc&&(v.isNewGroupTopicName(e)?s.sub.set.desc=n.desc:v.isP2PTopicName(e)&&n.desc.defacs&&(s.sub.set.desc={defacs:n.desc.defacs})),n.tags&&(s.sub.set.tags=n.tags)),this.send(s,s.sub.id)},leave:function(e,t){const n=this.initPacket("leave",e);return n.leave.unsub=t,this.send(n,n.leave.id)},createMessage:function(e,t,n){const s=this.initPacket("pub",e);let i="string"==typeof t?f.parse(t):t;return i&&!f.isPlainText(i)&&(s.pub.head={mime:f.getContentType()},t=i),s.pub.noecho=n,s.pub.content=t,s.pub},publish:function(e,t,n){return this.publishMessage(this.createMessage(e,t,n))},publishMessage:function(e){return(e=Object.assign({},e)).seq=void 0,e.from=void 0,e.ts=void 0,this.send({pub:e},e.id)},oobNotification:function(e,t,n){const s=this.cacheGet("topic",e);s&&(s._updateReceived(t,n),this.getMeTopic()._refreshContact("msg",s))},getMeta:function(e,t){const n=this.initPacket("get",e);return n.get=m(n.get,t),this.send(n,n.get.id)},setMeta:function(e,t){const n=this.initPacket("set",e),s=[];return t&&["desc","sub","tags","cred"].map((function(e){t.hasOwnProperty(e)&&(s.push(e),n.set[e]=t[e])})),0==s.length?Promise.reject(new Error("Invalid {set} parameters")):this.send(n,n.set.id)},delMessages:function(e,t,n){const s=this.initPacket("del",e);return s.del.what="msg",s.del.delseq=t,s.del.hard=n,this.send(s,s.del.id)},delTopic:function(e,t){const n=this.initPacket("del",e);return n.del.what="topic",n.del.hard=t,this.send(n,n.del.id)},delSubscription:function(e,t){const n=this.initPacket("del",e);return n.del.what="sub",n.del.user=t,this.send(n,n.del.id)},delCredential:function(e,t){const n=this.initPacket("del","me");return n.del.what="cred",n.del.cred={meth:e,val:t},this.send(n,n.del.id)},delCurrentUser:function(e){const t=this.initPacket("del",null);return t.del.what="user",t.del.hard=e,this.send(t,t.del.id).then(e=>{this._myUID=null})},note:function(e,t,n){if(n<=0||n>=268435455)throw new Error("Invalid message id "+n);const s=this.initPacket("note",e);s.note.what=t,s.note.seq=n,this.send(s)},noteKeyPress:function(e){const t=this.initPacket("note",e);t.note.what="kp",this.send(t)},getTopic:function(e){let t=this.cacheGet("topic",e);return!t&&e&&(t="me"==e?new y:"fnd"==e?new T:new M(e),this.attachCacheToTopic(t),t._cachePutSelf()),t},isTopicCached:function(e){return!!this.cacheGet("topic",e)},newGroupTopicName:function(e){return(e?"nch":"new")+this.getNextUniqueId()},getMeTopic:function(){return this.getTopic("me")},getFndTopic:function(){return this.getTopic("fnd")},getLargeFileHelper:function(){return new S(this,"0")},getCurrentUserID:function(){return this._myUID},isMe:function(e){return this._myUID===e},getCurrentLogin:function(){return this._login},getServerInfo:function(){return this._serverInfo},getServerLimit:function(e,t){return(this._serverInfo?this._serverInfo[e]:null)||t},enableLogging:function(e,t){this._loggingEnabled=e,this._trimLongStrings=e&&t},setHumanLanguage:function(e){e&&(this._humanLanguage=e)},isTopicOnline:function(e){const t=this.cacheGet("topic",e);return t&&t.online},getTopicAccessMode:function(e){const t=this.cacheGet("topic",e);return t?t.acs:null},wantAkn:function(e){this._messageId=e?Math.floor(16777215*Math.random()+16777215):0},onWebsocketOpen:void 0,onConnect:void 0,onDisconnect:void 0,onLogin:void 0,onCtrlMessage:void 0,onDataMessage:void 0,onPresMessage:void 0,onMessage:void 0,onRawMessage:void 0,onNetworkProbe:void 0,onAutoreconnectIteration:void 0};var M=function(t,s){this._tinode=null,this.name=t,this.created=null,this.updated=null,this.touched=new Date(0),this.acs=new e(null),this.private=null,this.public=null,this._users={},this._queuedSeqId=268435455,this._maxSeq=0,this._minSeq=0,this._noEarlierMsgs=!1,this._maxDel=0,this._tags=[],this._credentials=[],this._messages=n((function(e,t){return e.seq-t.seq}),!0),this._subscribed=!1,this._lastSubsUpdate=new Date(0),this._new=!0,s&&(this.onData=s.onData,this.onMeta=s.onMeta,this.onPres=s.onPres,this.onInfo=s.onInfo,this.onMetaDesc=s.onMetaDesc,this.onMetaSub=s.onMetaSub,this.onSubsUpdated=s.onSubsUpdated,this.onTagsUpdated=s.onTagsUpdated,this.onCredsUpdated=s.onCredsUpdated,this.onDeleteTopic=s.onDeleteTopic,this.onAllMessagesReceived=s.onAllMessagesReceived)};M.prototype={isSubscribed:function(){return this._subscribed},subscribe:function(e,t){return this._subscribed?Promise.resolve(this):this._tinode.subscribe(this.name||"new",e,t).then(e=>{if(e.code>=300)return e;if(this._subscribed=!0,this.acs=e.params&&e.params.acs?e.params.acs:this.acs,this._new){if(this._new=!1,this.name!=e.topic&&(this._cacheDelSelf(),this.name=e.topic),this._cachePutSelf(),this.created=e.ts,this.updated=e.ts,this.touched=e.ts,"me"!=this.name&&"fnd"!=this.name){const e=this._tinode.getMeTopic();e.onMetaSub&&e.onMetaSub(this),e.onSubsUpdated&&e.onSubsUpdated([this.name],1)}t&&t.desc&&(t.desc._noForwarding=!0,this._processMetaDesc(t.desc))}return e})},createMessage:function(e,t){return this._tinode.createMessage(this.name,e,t)},publish:function(e,t){return this.publishMessage(this.createMessage(e,t))},publishMessage:function(e){if(!this._subscribed)return Promise.reject(new Error("Cannot publish on inactive topic"));if(f.hasEntities(e.content)&&!e.head.attachments){const t=[];f.entities(e.content,e=>{e&&e.ref&&t.push(e.ref)}),t.length>0&&(e.head.attachments=t)}return e._sending=!0,e._failed=!1,this._tinode.publishMessage(e).then(t=>(e._sending=!1,e.ts=t.ts,this.swapMessageId(e,t.params.seq),this._routeData(e),t)).catch(t=>{this._tinode.logger("WARNING: Message rejected by the server",t),e._sending=!1,e._failed=!0,this.onData&&this.onData()})},publishDraft:function(e,t){if(!t&&!this._subscribed)return Promise.reject(new Error("Cannot publish on inactive topic"));const n=e.seq||this._getQueuedSeqId();return e._noForwarding||(e._noForwarding=!0,e.seq=n,e.ts=new Date,e.from=this._tinode.getCurrentUserID(),e.noecho=!0,this._messages.put(e),this._tinode._db.addMessage(e),this.onData&&this.onData(e)),(t||Promise.resolve()).then(()=>e._cancelled?{code:300,text:"cancelled"}:this.publishMessage(e),t=>{this._tinode.logger("WARNING: Message draft rejected",t),e._sending=!1,e._failed=!0,this._messages.delAt(this._messages.find(e)),this._tinode._db.remMessages(this.name,e.seq),this.onData&&this.onData()})},leave:function(e){return this._subscribed||e?this._tinode.leave(this.name,e).then(t=>(this._resetSub(),e&&(this._tinode._db.remTopic(this.name),this._tinode.cacheDel("topic",this.name),this._gone()),t)):Promise.reject(new Error("Cannot leave inactive topic"))},getMeta:function(e){return this._tinode.getMeta(this.name,e)},getMessagesPage:function(e,t){const n=this.startMetaQuery();t?n.withLaterData(e):n.withEarlierData(e);let s=this.getMeta(n.build());return t||(s=s.then(e=>{e&&e.params&&!e.params.count&&(this._noEarlierMsgs=!0)})),s},setMeta:function(e){return e.tags&&(e.tags=function(e){let t=[];if(Array.isArray(e)){for(let n=0,s=e.length;n1&&t.push(s)}t.sort().filter((function(e,t,n){return!t||e!=n[t-1]}))}return 0==t.length&&t.push(v.DEL_CHAR),t}(e.tags)),this._tinode.setMeta(this.name,e).then(t=>(t&&t.code>=300||(e.sub&&(e.sub.topic=this.name,t.params&&t.params.acs&&(e.sub.acs=t.params.acs,e.sub.updated=t.ts),e.sub.user||(e.sub.user=this._tinode.getCurrentUserID(),e.desc||(e.desc={})),e.sub._noForwarding=!0,this._processMetaSub([e.sub])),e.desc&&(t.params&&t.params.acs&&(e.desc.acs=t.params.acs,e.desc.updated=t.ts),this._processMetaDesc(e.desc)),e.tags&&this._processMetaTags(e.tags),e.cred&&this._processMetaCreds([e.cred],!0)),t))},updateMode:function(e,t){const n=e?this.subscriber(e):null,s=n?n.acs.updateGiven(t).getGiven():this.getAccessMode().updateWant(t).getWant();return this.setMeta({sub:{user:e,mode:s}})},invite:function(e,t){return this.setMeta({sub:{user:e,mode:t}})},archive:function(e){return this.private&&this.private.arch==e?Promise.resolve(e):this.setMeta({desc:{private:{arch:!!e||v.DEL_CHAR}}})},delMessages:function(e,t){if(!this._subscribed)return Promise.reject(new Error("Cannot delete messages in inactive topic"));e.sort((e,t)=>e.low=t.hi));let n,s=e.reduce((e,t)=>(t.low<268435455&&(!t.hi||t.hi<268435455?e.push(t):e.push({low:t.low,hi:this._maxSeq+1})),e),[]);return(n=s.length>0?this._tinode.delMessages(this.name,s,t):Promise.resolve({params:{del:0}})).then(t=>(t.params.del>this._maxDel&&(this._maxDel=t.params.del),e.map(e=>{e.hi?this.flushMessageRange(e.low,e.hi):this.flushMessage(e.low)}),this._updateDeletedRanges(),this.onData&&this.onData(),t))},delMessagesAll:function(e){return!this._maxSeq||this._maxSeq<=0?Promise.resolve():this.delMessages([{low:1,hi:this._maxSeq+1,_all:!0}],e)},delMessagesList:function(e,t){e.sort((e,t)=>e-t);let n=e.reduce((e,t)=>{if(0==e.length)e.push({low:t});else{let n=e[e.length-1];!n.hi&&t!=n.low+1||t>n.hi?e.push({low:t}):n.hi=n.hi?Math.max(n.hi,t+1):t+1}return e},[]);return this.delMessages(n,t)},delTopic:function(e){return this._tinode.delTopic(this.name,e).then(e=>(this._resetSub(),this._gone(),e))},delSubscription:function(e){return this._subscribed?this._tinode.delSubscription(this.name,e).then(t=>(delete this._users[e],this.onSubsUpdated&&this.onSubsUpdated(Object.keys(this._users)),t)):Promise.reject(new Error("Cannot delete subscription in inactive topic"))},note:function(e,t){if(!this._subscribed)return;const n=this._users[this._tinode.getCurrentUserID()];let s=!1;n?(!n[e]||n[e]0&&this.note("read",e)},noteKeyPress:function(){this._subscribed?this._tinode.noteKeyPress(this.name):this._tinode.logger("INFO: Cannot send notification in inactive topic")},_updateReadRecv:function(e,t,n){let s,i=!1;switch(t|=0,this.seq=0|this.seq,this.read=0|this.read,this.recv=0|this.recv,e){case"recv":s=this.recv,this.recv=Math.max(this.recv,t),i=s!=this.recv;break;case"read":s=this.read,this.read=Math.max(this.read,t),i=s!=this.read;break;case"msg":s=this.seq,this.seq=Math.max(this.seq,t),(!this.touched||this.touched0){const s=this._tinode.getCurrentUserID();for(let i in this._users){const r=this._users[i];r.user!==s&&r[e]>=t&&n++}}return n},msgReadCount:function(e){return this.msgReceiptCount("read",e)},msgRecvCount:function(e){return this.msgReceiptCount("recv",e)},msgHasMoreMessages:function(e){return e?this.seq>this._maxSeq:this._minSeq>1&&!this._noEarlierMsgs},isNewMessage:function(e){return this._maxSeq<=e},flushMessage:function(e){const t=this._messages.find({seq:e});if(t>=0)return this._tinode._db.remMessages(this.name,e),this._messages.delAt(t)},swapMessageId:function(e,t){const n=this._messages.find(e),s=this._messages.length();0<=n&&n=0?this._messages.delRange(n,this._messages.find({seq:t},!0)):[]},cancelSend:function(e){const t=this._messages.find({seq:e});if(t>=0){const n=this._messages.getAt(t),s=this.msgStatus(n);if(1==s||3==s)return this._tinode._db.remMessages(this.name,e),n._cancelled=!0,this._messages.delAt(t),this.onData&&this.onData(),!0}return!1},getType:function(){return v.topicType(this.name)},getAccessMode:function(){return this.acs},setAccessMode:function(t){return this.acs=new e(t)},getDefaultAccess:function(){return this.defacs},startMetaQuery:function(){return new P(this)},isArchived:function(){return!(!this.private||!this.private.arch)},isMeType:function(){return v.isMeTopicName(this.name)},isChannelType:function(){return v.isChannelTopicName(this.name)},isGroupType:function(){return v.isGroupTopicName(this.name)},isP2PType:function(){return v.isP2PTopicName(this.name)},isCommType:function(){return v.isCommTopicName(this.name)},msgStatus:function(e,t){let n=0;return this._tinode.isMe(e.from)?e._sending?n=2:e._failed||e._cancelled?n=3:e.seq>=268435455?n=1:this.msgReadCount(e.seq)>0?n=6:this.msgRecvCount(e.seq)>0?n=5:e.seq>0&&(n=4):8==e._status||(n=7),t&&e._status!=n&&(e._status=n,this._tinode._db.updMessageStatus(this.name,e.seq,n)),n},_routeData:function(e){e.content&&(!this.touched||this.touchedthis._maxSeq&&(this._maxSeq=e.seq),(e.seq0&&this._processMetaSub(e.sub),e.del&&this._processDelMessages(e.del.clear,e.del.delseq),e.tags&&this._processMetaTags(e.tags),e.cred&&this._processMetaCreds(e.cred),this.onMeta&&this.onMeta(e)},_routePres:function(t){let n;switch(t.what){case"del":this._processDelMessages(t.clear,t.delseq);break;case"on":case"off":(n=this._users[t.src])?n.online="on"==t.what:this._tinode.logger("WARNING: Presence update for an unknown user",this.name,t.src);break;case"term":this._resetSub();break;case"acs":const s=t.src||this._tinode.getCurrentUserID();if(n=this._users[s])n.acs.updateAll(t.dacs),this._processMetaSub([{user:s,updated:new Date,acs:n.acs}]);else{const i=(new e).updateAll(t.dacs);i&&i.mode!=e._NONE&&((n=this._cacheGetUser(s))?n.acs=i:(n={user:s,acs:i},this.getMeta(this.startMetaQuery().withOneSub(void 0,s).build())),n.updated=new Date,this._processMetaSub([n]))}break;default:this._tinode.logger("INFO: Ignored presence update",t.what)}this.onPres&&this.onPres(t)},_routeInfo:function(e){if("kp"!==e.what){const t=this._users[e.from];t&&(t[e.what]=e.seq,t.recv0&&(this._updateDeletedRanges(),this.onData&&this.onData())},_allMessagesReceived:function(e){this._updateDeletedRanges(),this.onAllMessagesReceived&&this.onAllMessagesReceived(e)},_resetSub:function(){this._subscribed=!1},_gone:function(){this._messages.reset(),this._tinode._db.remMessages(this.name),this._users={},this.acs=new e(null),this.private=null,this.public=null,this._maxSeq=0,this._minSeq=0,this._subscribed=!1;const t=this._tinode.getMeTopic();t&&t._routePres({_noForwarding:!0,what:"gone",topic:"me",src:this.name}),this.onDeleteTopic&&this.onDeleteTopic()},_updateCachedUser:function(e,t){let n=this._cacheGetUser(e);return n=m(n||{},t),this._cachePutUser(e,n),_(this._users,e,n)},_getQueuedSeqId:function(){return this._queuedSeqId++},_updateDeletedRanges:function(){const e=[];let t=null;const n=this._messages.getAt(0);n&&this._minSeq>1&&!this._noEarlierMsgs?n.hi?(n.seq>1&&(n.seq=1),n.hi{n.seq>=268435455||(n.seq!=(t.hi||t.seq)+1?t.hi?t.hi=n.hi||n.seq:(t={seq:(t.hi||t.seq)+1,hi:n.hi||n.seq},e.push(t)):t=n)});const s=this._messages.getLast(),i=Math.max(this.seq,this._maxSeq)||0;(i>0&&!s||s&&(s.hi||s.seq){e._status=8,this._messages.put(e)})},_loadMessages:function(e){return e.readMessages(this.name,{limit:24}).then(e=>(e.forEach(e=>{e.seq>this._maxSeq&&(this._maxSeq=e.seq),(e.seq{e.online&&(e.online=!1,e.seen?e.seen.when=new Date:e.seen={when:new Date},this._refreshContact("off",e))}),this.onMetaDesc&&this.onMetaDesc(this)},enumerable:!0,configurable:!0},_processMetaSub:{value:function(e){let t=0;if(e.forEach(e=>{const n=e.topic;if("fnd"==n||"me"==n)return;e.updated=new Date(e.updated),e.touched=e.touched?new Date(e.touched):void 0,e.deleted=e.deleted?new Date(e.deleted):null,e.online=!!e.online;let s=null;if(e.deleted)s=e,this._tinode.cacheDel("topic",n),this._tinode._db.remTopic(n);else if(void 0!==e.seq&&(e.seq=0|e.seq,e.recv=0|e.recv,e.read=0|e.read,e.unread=e.seq-e.read),e.seen&&e.seen.when&&(e.seen.when=new Date(e.seen.when)),s=m(this._tinode.getTopic(n),e),this._tinode._db.updTopic(s),v.isP2PTopicName(n)&&(this._cachePutUser(n,s),this._tinode._db.updUser(n,s.public)),!e._noForwarding){const t=this._tinode.getTopic(n);t&&(e._noForwarding=!0,t._processMetaDesc(e))}t++,this.onMetaSub&&this.onMetaSub(s)}),this.onSubsUpdated&&t>0){const n=[];e.forEach(e=>{n.push(e.topic)}),this.onSubsUpdated(n,t)}},enumerable:!0,configurable:!0},_processMetaCreds:{value:function(e,t){1==e.length&&e[0]==v.DEL_CHAR&&(e=[]),t?e.map(e=>{if(e.val){let t=this._credentials.findIndex(t=>t.meth==e.meth&&t.val==e.val);t<0?(e.done||(t=this._credentials.findIndex(t=>t.meth==e.meth&&!t.done))>=0&&this._credentials.splice(t,1),this._credentials.push(e)):this._credentials[t].done=e.done}else if(e.resp){const t=this._credentials.findIndex(t=>t.meth==e.meth&&!t.done);t>=0&&(this._credentials[t].done=!0)}}):this._credentials=e,this.onCredsUpdated&&this.onCredsUpdated(this._credentials)},enumerable:!0,configurable:!0},_routePres:{value:function(t){if("term"==t.what)return void this._resetSub();if("upd"==t.what&&"me"==t.src)return void this.getMeta(this.startMetaQuery().withDesc().build());const n=this._tinode.cacheGet("topic",t.src);if(n){switch(t.what){case"on":n.online=!0;break;case"off":n.online&&(n.online=!1,n.seen?n.seen.when=new Date:n.seen={when:new Date});break;case"msg":n._updateReceived(t.seq,t.act);break;case"upd":this.getMeta(this.startMetaQuery().withLaterOneSub(t.src).build());break;case"acs":n.acs?n.acs.updateAll(t.dacs):n.acs=(new e).updateAll(t.dacs),n.touched=new Date;break;case"ua":n.seen={when:new Date,ua:t.ua};break;case"recv":t.seq=0|t.seq,n.recv=n.recv?Math.max(n.recv,t.seq):t.seq;break;case"read":t.seq=0|t.seq,n.read=n.read?Math.max(n.read,t.seq):t.seq,n.recv=n.recv?Math.max(n.read,n.recv):n.recv,n.unread=n.seq-n.read;break;case"gone":this._tinode.cacheDel("topic",t.src),this._tinode._db.remTopic(t.src);break;case"del":break;default:this._tinode.logger("INFO: Unsupported presence update in 'me'",t.what)}this._refreshContact(t.what,n)}else if("acs"==t.what){const n=new e(t.dacs);if(!n||n.mode==e._INVALID)return void this._tinode.logger("ERROR: Invalid access mode update",t.src,t.dacs);if(n.mode==e._NONE)return void this._tinode.logger("WARNING: Removing non-existent subscription",t.src,t.dacs);{this.getMeta(this.startMetaQuery().withOneSub(void 0,t.src).build());const e=this._tinode.getTopic(t.src);e.touched=new Date,e.topic=t.src,e.online=!1,e.acs=n,this._tinode.attachCacheToTopic(e),e._cachePutSelf(),this._db.updTopic(e)}}else"tags"==t.what&&this.getMeta(this.startMetaQuery().withTags().build());this.onPres&&this.onPres(t)},enumerable:!0,configurable:!0},_refreshContact:{value:function(e,t){this.onContactUpdate&&this.onContactUpdate(e,t)},enumerable:!0,configurable:!0},publish:{value:function(){return Promise.reject(new Error("Publishing to 'me' is not supported"))},enumerable:!0,configurable:!0},delCredential:{value:function(e,t){return this._subscribed?this._tinode.delCredential(e,t).then(n=>{const s=this._credentials.findIndex(n=>n.meth==e&&n.val==t);return s>-1&&this._credentials.splice(s,1),this.onCredsUpdated&&this.onCredsUpdated(this._credentials),n}):Promise.reject(new Error("Cannot delete credential in inactive 'me' topic"))},enumerable:!0,configurable:!0},contacts:{value:function(e,t,n){this._tinode.cacheMap("topic",(s,i)=>{!s.isCommType()||t&&!t(s)||e.call(n,s,i)})},enumerable:!0,configurable:!0},getContact:{value:function(e){return this._tinode.cacheGet("topic",e)},enumerable:!0,configurable:!0},getAccessMode:{value:function(e){if(e){const t=this._tinode.cacheGet("topic",e);return t?t.acs:null}return this.acs},enumerable:!0,configurable:!0},isArchived:{value:function(e){const t=this._tinode.cacheGet("topic",e);return t?!(!t.private||!t.private.arch):null},enumerable:!0,configurable:!0},getCredentials:{value:function(){return this._credentials},enumerable:!0,configurable:!0}}),y.prototype.constructor=y;var T=function(e){M.call(this,"fnd",e),this._contacts={}};T.prototype=Object.create(M.prototype,{_processMetaSub:{value:function(e){let t=Object.getOwnPropertyNames(this._contacts).length;this._contacts={};for(let n in e){let s=e[n];const i=s.topic?s.topic:s.user;s.updated=new Date(s.updated),s.seen&&s.seen.when&&(s.seen.when=new Date(s.seen.when)),s=_(this._contacts,i,s),t++,this.onMetaSub&&this.onMetaSub(s)}t>0&&this.onSubsUpdated&&this.onSubsUpdated(Object.keys(this._contacts))},enumerable:!0,configurable:!0},publish:{value:function(){return Promise.reject(new Error("Publishing to 'fnd' is not supported"))},enumerable:!0,configurable:!0},setMeta:{value:function(e){const t=this;return Object.getPrototypeOf(T.prototype).setMeta.call(this,e).then((function(){Object.keys(t._contacts).length>0&&(t._contacts={},t.onSubsUpdated&&t.onSubsUpdated([]))}))},enumerable:!0,configurable:!0},contacts:{value:function(e,t){const n=e||this.onMetaSub;if(n)for(let s in this._contacts)n.call(t,this._contacts[s],s,this._contacts)},enumerable:!0,configurable:!0}}),T.prototype.constructor=T;var x=function(e,t){this.status=x.STATUS_NONE,this.topic=e,this.content=t};x.STATUS_NONE=0,x.STATUS_QUEUED=1,x.STATUS_SENDING=2,x.STATUS_FAILED=3,x.STATUS_SENT=4,x.STATUS_RECEIVED=5,x.STATUS_READ=6,x.STATUS_TO_ME=7,x.prototype={toJSON:function(){},fromJSON:function(e){}},x.prototype.constructor=x,R.exports=v,R.exports.Drafty=f,R.exports.AccessMode=e}).call(this)}.call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{}),R=R.exports})); \ No newline at end of file +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Tinode=e()}}((function(){var e={exports:{}};const t=function(e){e&&(this.given="number"==typeof e.given?e.given:t.decode(e.given),this.want="number"==typeof e.want?e.want:t.decode(e.want),this.mode=e.mode?"number"==typeof e.mode?e.mode:t.decode(e.mode):this.given&this.want)};t._NONE=0,t._JOIN=1,t._READ=2,t._WRITE=4,t._PRES=8,t._APPROVE=16,t._SHARE=32,t._DELETE=64,t._OWNER=128,t._BITMASK=t._JOIN|t._READ|t._WRITE|t._PRES|t._APPROVE|t._SHARE|t._DELETE|t._OWNER,t._INVALID=1048576,t._checkFlag=function(e,t,n){if(["given","want","mode"].includes(t=t||"mode"))return 0!=(e[t]&n);throw new Error(`Invalid AccessMode component '${t}'`)},t.decode=function(e){if(!e)return null;if("number"==typeof e)return e&t._BITMASK;if("N"===e||"n"===e)return t._NONE;const n={J:t._JOIN,R:t._READ,W:t._WRITE,P:t._PRES,A:t._APPROVE,S:t._SHARE,D:t._DELETE,O:t._OWNER};let s=t._NONE;for(let t=0;t0)){c=!0;break}r=o-1}return c?{idx:o,exact:!0}:s?{idx:-1}:{idx:a<0?o+1:o}}function i(e,n){const i=s(e,n,!1),r=i.exact&&t?1:0;return n.splice(i.idx,r,e),n}return e=e||function(e,t){return e===t?0:ee?n[n.length-1-e]:void 0},put:function(){let e;e=1==arguments.length&&Array.isArray(arguments[0])?arguments[0]:arguments;for(let t in e)i(e[t],n)},delAt:function(e){let t=n.splice(e,1);if(t&&t.length>0)return t[0]},delRange:function(e,t){return n.splice(e,t-e)},length:function(){return n.length},reset:function(){n=[]},forEach:function(e,t,s,i){t|=0,s=s||n.length;for(let r=t;r=20&&n.length<=24){const e=new Date(n);if(!isNaN(e))return e}else if("acs"===t&&"object"==typeof n)return new e(n);return n},s=s.exports;var i={exports:{}};const{jsonParseHelper:r}=s;let o,a;function c(e,t,n,s){let i=null;return["http","https","ws","wss"].includes(t)&&("/"!==(i=`${t}://${e}`).charAt(i.length-1)&&(i+="/"),i+="v"+n+"/channels",["http","https"].includes(t)&&(i+="/lp"),i+="?apikey="+s),i}const u=function(e,t,n){let s=e.host;const i=e.secure,h=e.apiKey,l=t,d=n;let f=null,p=0,g=!1;const m=(e,...t)=>{u.logger&&u.logger(e,...t)};function _(){clearTimeout(f);const e=Math.pow(2,p)*(1+.3*Math.random())*2e3;p=p>=10?p:p+1,this.onAutoreconnectIteration&&this.onAutoreconnectIteration(e),f=setTimeout(()=>{if(m(`Reconnecting, iter=${p}, timeout=${e}`),g)this.onAutoreconnectIteration&&this.onAutoreconnectIteration(-1);else{const e=this.connect();this.onAutoreconnectIteration?this.onAutoreconnectIteration(0,e):e.catch(()=>{})}},e)}function b(){clearTimeout(f),f=null}let w=!1;if("lp"===e.transport?(function(e){let t=null,n=null,o=null;e.connect=function(o,u){if(g=!1,n){if(!u)return Promise.resolve();n.onreadystatechange=void 0,n.abort(),n=null}return o&&(s=o),new Promise((function(o,u){const f=c(s,i?"https":"http",l,h);m("Connecting to:",f),(n=function n(s,i,o){let c=new a,u=!1;return c.onreadystatechange=function(a){if(4==c.readyState)if(201==c.status){let o=JSON.parse(c.responseText,r);t=s+"&sid="+o.ctrl.params.sid,(c=n(t)).send(null),e.onOpen&&e.onOpen(),i&&(u=!0,i()),d&&b()}else if(c.status<400)e.onMessage&&e.onMessage(c.responseText),(c=n(t)).send(null);else{if(o&&!u&&(u=!0,o(c.responseText)),e.onMessage&&c.responseText&&e.onMessage(c.responseText),e.onDisconnect){const t=c.status||(g?418:503),n=c.responseText||(g?"Disconnected by client":"Connection failed");e.onDisconnect(new Error(n+" ("+t+")"),t)}c=null,!g&&d&&_.call(e)}},c.open("GET",s,!0),c}(f,o,u)).send(null)})).catch(e=>{m("LP connection failed:",e)})},e.reconnect=function(t){b(),e.connect(null,t)},e.disconnect=function(){g=!0,b(),o&&(o.onreadystatechange=void 0,o.abort(),o=null),n&&(n.onreadystatechange=void 0,n.abort(),n=null),e.onDisconnect&&e.onDisconnect(new Error("Disconnected by client (418)"),418),t=null},e.sendText=function(e){if(!(o=function(e){const t=new a;return t.onreadystatechange=function(e){if(4==t.readyState&&t.status>=400)throw new Error("LP sender failed, "+t.status)},t.open("POST",e,!0),t}(t))||1!=o.readyState)throw new Error("Long poller failed to connect");o.send(e)},e.isConnected=function(){return n&&!0},e.transport=function(){return"lp"},e.probe=function(){e.sendText("1")}}(this),w=!0):"ws"===e.transport&&(function(e){let t=null;e.connect=function(n,r){if(g=!1,t){if(!r&&t.readyState==t.OPEN)return Promise.resolve();t.close(),t=null}return n&&(s=n),new Promise((function(n,r){const a=c(s,i?"wss":"ws",l,h);m("Connecting to: ",a);const u=new o(a);u.onerror=function(e){r(e)},u.onopen=function(t){d&&b(),e.onOpen&&e.onOpen(),n()},u.onclose=function(n){if(t=null,e.onDisconnect){const t=g?418:503;e.onDisconnect(new Error(g?"Disconnected by client":"Connection failed ("+t+")"),t)}!g&&d&&_.call(e)},u.onmessage=function(t){e.onMessage&&e.onMessage(t.data)},t=u}))},e.reconnect=function(t){b(),e.connect(null,t)},e.disconnect=function(){g=!0,b(),t&&(t.close(),t=null)},e.sendText=function(e){if(!t||t.readyState!=t.OPEN)throw new Error("Websocket is not connected");t.send(e)},e.isConnected=function(){return t&&t.readyState==t.OPEN},e.transport=function(){return"ws"},e.probe=function(){e.sendText("1")}}(this),w=!0),!w)throw m("Unknown or invalid network transport. Running under Node? Call 'Tinode.setNetworkProviders()'."),new Error("Unknown or invalid network transport. Running under Node? Call 'Tinode.setNetworkProviders()'.");this.backoffReset=function(){p=0},this.onMessage=void 0,this.onDisconnect=void 0,this.onOpen=void 0,this.onAutoreconnectIteration=void 0,this.logger=void 0};u.setNetworkProviders=function(e,t){o=e,a=t},u.NETWORK_ERROR=503,u.NETWORK_ERROR_TEXT="Connection failed",u.NETWORK_USER=418,u.NETWORK_USER_TEXT="Disconnected by client",i.exports=u,i=i.exports;var h={exports:{}};let l;const d=function(e,t){e=e||function(){},t=t||function(){};let n=null,s=!1;const i=["created","updated","deleted","read","recv","seq","clear","defacs","creds","public","private","touched"];function r(e,t){const n=e||{};return["topic","seq","ts","_status","from","head","content"].forEach(e=>{t.hasOwnProperty(e)&&(n[e]=t[e])}),n}function o(e,i,r){return n?new Promise((s,o)=>{const a=n.transaction([e]);a.onerror=n=>{t("PCache","mapObjects",e,n.target.error),o(n.target.error)},a.objectStore(e).getAll().onsuccess=e=>{i&&e.target.result.forEach(e=>{i.call(r,e)}),s(e.target.result)}}):s?Promise.resolve([]):Promise.reject(new Error("not initialized"))}return{initDatabase:function(){return new Promise((i,r)=>{const o=l.open("tinode-web",1);o.onsuccess=e=>{n=e.target.result,s=!1,i(n)},o.onerror=n=>{t("PCache","failed to initialize",n),r(n.target.error),e(n.target.error)},o.onupgradeneeded=function(s){(n=s.target.result).onerror=function(n){t("PCache","failed to create storage",n),e(n.target.error)},n.createObjectStore("topic",{keyPath:"name"}),n.createObjectStore("user",{keyPath:"uid"}),n.createObjectStore("subscription",{keyPath:["topic","uid"]}),n.createObjectStore("message",{keyPath:["topic","seq"]})}})},deleteDatabase:function(){return new Promise((e,i)=>{const r=l.deleteDatabase("tinode-web");r.onblocked=function(e){n&&n.close()},r.onsuccess=t=>{n=null,s=!0,e(!0)},r.onerror=e=>{t("PCache","deleteDatabase",e.target.error),i(e.target.error)}})},isReady:function(){return!!n},updTopic:function(e){return this.isReady()?new Promise((s,r)=>{const o=n.transaction(["topic"],"readwrite");o.oncomplete=e=>{s(e.target.result)},o.onerror=e=>{t("PCache","updTopic",e.target.error),r(e.target.error)};const a=o.objectStore("topic").get(e.name);a.onsuccess=t=>{o.objectStore("topic").put(function(e,t){const n=e||{name:t.name};return i.forEach(e=>{t.hasOwnProperty(e)&&(n[e]=t[e])}),Array.isArray(t._tags)&&(n.tags=t._tags),t.acs&&(n.acs=t.getAccessMode().jsonHelper()),n}(a.result,e)),o.commit()}}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},remTopic:function(e){return this.isReady()?new Promise((s,i)=>{const r=n.transaction(["topic","subscription","message"],"readwrite");r.oncomplete=e=>{s(e.target.result)},r.onerror=e=>{t("PCache","remTopic",e.target.error),i(e.target.error)},r.objectStore("topic").delete(IDBKeyRange.only(e)),r.objectStore("subscription").delete(IDBKeyRange.bound([e,"-"],[e,"~"])),r.objectStore("message").delete(IDBKeyRange.bound([e,0],[e,Number.MAX_SAFE_INTEGER])),r.commit()}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},mapTopics:function(e,t){return o("topic",e,t)},deserializeTopic:function(e,t){!function(e,t){i.forEach(n=>{t.hasOwnProperty(n)&&(e[n]=t[n])}),Array.isArray(t.tags)&&(e._tags=t.tags),t.acs&&e.setAccessMode(t.acs),e.seq|=0,e.read|=0,e.unread=Math.max(0,e.seq-e.read)}(e,t)},updUser:function(e,i){if(!(arguments.length<2||void 0===i))return this.isReady()?new Promise((s,r)=>{const o=n.transaction(["user"],"readwrite");o.oncomplete=e=>{s(e.target.result)},o.onerror=e=>{t("PCache","updUser",e.target.error),r(e.target.error)},o.objectStore("user").put({uid:e,public:i}),o.commit()}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},remUser:function(e){return this.isReady()?new Promise((s,i)=>{const r=n.transaction(["user"],"readwrite");r.oncomplete=e=>{s(e.target.result)},r.onerror=e=>{t("PCache","remUser",e.target.error),i(e.target.error)},r.objectStore("user").delete(IDBKeyRange.only(e)),r.commit()}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},mapUsers:function(e,t){return o("user",e,t)},getUser:function(e){return this.isReady()?new Promise((s,i)=>{const r=n.transaction(["user"]);r.oncomplete=e=>{const t=e.target.result;s({user:t.uid,public:t.public})},r.onerror=e=>{t("PCache","getUser",e.target.error),i(e.target.error)},r.objectStore("user").get(e)}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},updSubscription:function(e,i,r){return this.isReady()?new Promise((s,o)=>{const a=n.transaction(["subscription"],"readwrite");a.oncomplete=e=>{s(e.target.result)},a.onerror=e=>{t("PCache","updSubscription",e.target.error),o(e.target.error)},a.objectStore("subscription").get([e,i]).onsuccess=t=>{a.objectStore("subscription").put(function(e,t,n,s){const i=e||{topic:t,uid:n};return["updated","mode","read","recv","clear","lastSeen","userAgent"].forEach(e=>{s.hasOwnProperty(e)&&(i[e]=s[e])}),i}(t.target.result,e,i,r)),a.commit()}}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},mapSubscriptions:function(e,i,r){return this.isReady()?new Promise((s,o)=>{const a=n.transaction(["subscription"]);a.onerror=e=>{t("PCache","mapSubscriptions",e.target.error),o(e.target.error)},a.objectStore("subscription").getAll(IDBKeyRange.bound([e,"-"],[e,"~"])).onsuccess=e=>{i&&e.target.result.forEach(e=>{i.call(r,e)}),s(e.target.result)}}):s?Promise.resolve([]):Promise.reject(new Error("not initialized"))},addMessage:function(e){return this.isReady()?new Promise((s,i)=>{const o=n.transaction(["message"],"readwrite");o.onsuccess=e=>{s(e.target.result)},o.onerror=e=>{t("PCache","addMesssage",e.target.error),i(e.target.error)},o.objectStore("message").add(r(null,e)),o.commit()}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},updMessageStatus:function(e,i,o){return this.isReady()?new Promise((s,a)=>{const c=n.transaction(["message"],"readwrite");c.onsuccess=e=>{s(e.target.result)},c.onerror=e=>{t("PCache","updMessageStatus",e.target.error),a(e.target.error)};const u=c.objectStore("message").get(IDBKeyRange.only([e,i]));u.onsuccess=t=>{const n=u.result||t.target.result;n&&n._status!=o?(c.objectStore("message").put(r(n,{topic:e,seq:i,_status:o})),c.commit()):c.commit()}}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},remMessages:function(e,i,r){return this.isReady()?new Promise((s,o)=>{i||r||(i=0,r=Number.MAX_SAFE_INTEGER);const a=r>0?IDBKeyRange.bound([e,i],[e,r],!1,!0):IDBKeyRange.only([e,i]),c=n.transaction(["message"],"readwrite");c.onsuccess=e=>{s(e.target.result)},c.onerror=e=>{t("PCache","remMessages",e.target.error),o(e.target.error)},c.objectStore("message").delete(a),c.commit()}):s?Promise.resolve():Promise.reject(new Error("not initialized"))},readMessages:function(e,i,r,o){return this.isReady()?new Promise((s,a)=>{const c=(i=i||{}).from>0?i.from:0,u=i.to>0?i.to:Number.MAX_SAFE_INTEGER,h=0|i.limit,l=[],d=IDBKeyRange.bound([e,c],[e,u],!1,!0),f=n.transaction(["message"]);f.onerror=e=>{t("PCache","readMessages",e.target.error),a(e.target.error)},f.objectStore("message").openCursor(d,"prev").onsuccess=e=>{const t=e.target.result;t?(r&&r.call(o,t.value),l.push(t.value),h<=0||l.length"},close:function(){return""}},EM:{open:function(){return""},close:function(){return""}},DL:{open:function(){return""},close:function(){return""}},CO:{open:function(){return""},close:function(){return""}},BR:{open:function(){return"
"},close:function(){return""}},HD:{open:function(){return""},close:function(){return""}},HL:{open:function(){return''},close:function(){return""}},LN:{open:function(e){return''},close:function(e){return""},props:function(e){return e?{href:e.url,target:"_blank"}:null}},MN:{open:function(e){return''},close:function(e){return""},props:function(e){return e?{name:e.val}:null}},HT:{open:function(e){return''},close:function(e){return""},props:function(e){return e?{name:e.val}:null}},BN:{open:function(e){return""},props:function(e){return e?{"data-act":e.act,"data-val":e.val,"data-name":e.name,"data-ref":e.ref}:null}},IM:{open:function(e){const t=b(e._tempPreview,e.mime),n=_(e.val,e.mime,v.logger),s=e.ref||n;return(e.name?'':"")+''},close:function(e){return e.name?"":""},props:function(e){return e?{src:b(e._tempPreview,e.mime)||e.ref||_(e.val,e.mime,v.logger),title:e.name,"data-width":e.width,"data-height":e.height,"data-name":e.name,"data-size":e.val?.75*e.val.length|0:0|e.size,"data-mime":e.mime}:null}},FM:{open:function(e){return"
"},close:function(e){return"
"}},RW:{open:function(e){return"
"},close:function(e){return"
"}}},v=function(){};v.parse=function(e){if("string"!=typeof e)return null;const t=e.split(/\r?\n/),n=[],s={},i=[];t.map((function(e){let t,r,o=[];if(p.map((function(t){o=o.concat(function(e,t,n,s){const i=[];let r=0,o=e.slice(0);for(;o.length>0;){const a=t.exec(o);if(null==a)break;let c=a.index+a[0].lastIndexOf(a[1]);o=o.slice(c+1),r=(c+=r)+1;const u=n?n.exec(o):null;if(null==u)break;let h=u.index+u[0].indexOf(u[1]);o=o.slice(h+1),r=(h+=r)+1,i.push({text:e.slice(c+1,h),children:[],start:c,end:h,type:s})}return i}(e,t.start,t.end,t.name))})),0==o.length)r={txt:e};else{o.sort((function(e,t){return e.start-t.start})),o=function e(t){if(0==t.length)return[];const n=[t[0]];let s=t[0];for(let i=1;is.end?(n.push(t[i]),s=t[i]):t[i].endn&&r.push({text:t.slice(n,s.start)});const a={type:s.type},c=e(t,s.start+1,s.end,s.children);c.length>0?a.children=c:a.text=s.text,r.push(a),n=s.end+1}return ns;return s=e.offset+e.len,t}))}(r.txt)).length>0){const e=[];for(let i in t){const r=t[i];let o=s[r.unique];o||(o=n.length,s[r.unique]=o,n.push({tp:r.type,data:r.data})),e.push({at:r.offset,len:r.len,key:o})}r.ent=e}i.push(r)}));const r={txt:""};if(i.length>0){r.txt=i[0].txt,r.fmt=(i[0].fmt||[]).concat(i[0].ent||[]);for(let e=1;e0&&(r.ent=n)}return r},v.init=function(e){return"string"!=typeof e?null:{txt:e}},v.append=function(e,t){if(null==e)return t;if(null==t)return e;e.txt=e.txt||"",t.txt=t.txt||"";const n=e.txt.length;return e.txt+=t.txt,Array.isArray(t.fmt)&&(e.fmt=e.fmt||[],Array.isArray(t.ent)&&(e.ent=e.ent||[]),t.fmt.forEach(s=>{const i={at:s.at+n,len:s.len};s.tp?i.tp=s.tp:(i.key=e.ent.length,e.ent.push(t.ent[s.key||0])),e.fmt.push(i)})),e},v.insertImage=function(e,t,n){(e=e||{txt:" "}).ent=e.ent||[],e.fmt=e.fmt||[],e.fmt.push({at:t,len:1,key:e.ent.length});const s={tp:"IM",data:{mime:n.mime,val:n.preview,width:n.width,height:n.height,name:n.filename,size:0|n.size,ref:n.refurl}};return n.urlPromise&&(s.data._tempPreview=n._tempPreview,s.data._processing=!0,n.urlPromise.then(e=>{s.data.ref=e,s.data._tempPreview=void 0,s.data._processing=void 0},e=>{s.data._processing=void 0})),e.ent.push(s),e},v.appendImage=function(e,t){return(e=e||{txt:""}).txt+=" ",v.insertImage(e,e.txt.length-1,t)},v.attachFile=function(e,t){(e=e||{txt:""}).ent=e.ent||[],e.fmt=e.fmt||[],e.fmt.push({at:-1,len:0,key:e.ent.length});const n={tp:"EX",data:{mime:t.mime,val:t.data,name:t.filename,ref:t.refurl,size:0|t.size}};return t.urlPromise&&(n.data._processing=!0,t.urlPromise.then(e=>{n.data.ref=e,n.data._processing=void 0},e=>{n.data._processing=void 0})),e.ent.push(n),e},v.wrapAsForm=function(e,t,n){return"string"==typeof e&&(e={txt:e}),e.fmt=e.fmt||[],e.fmt.push({at:t,len:n,tp:"FM"}),e},v.insertButton=function(e,t,n,s,i,r,o){return"string"==typeof e&&(e={txt:e}),!e||!e.txt||e.txt.length{let t,n=e.tp;return n||(e.key=e.key||0,r[e.key]&&(t=r[e.key].data,n=r[e.key].tp)),{tp:n=n||"HD",data:t,at:e.at,len:e.len}}),function e(t,n,s,i,r,o){const a=[];for(let c=0;c0)for(let t in e.ent)if(e.ent[t]&&e.ent[t].data&&"EX"==e.ent[t].tp)return!0;return!1},v.attachments=function(e,t,n){if(e.ent&&e.ent.length>0)for(let s in e.ent)e.ent[s]&&"EX"==e.ent[s].tp&&e.ent[s].data&&t.call(n,e.ent[s].data,s,"EX")},v.hasEntities=function(e){return e.ent&&e.ent.length>0},v.entities=function(e,t,n){if(e.ent&&e.ent.length>0)for(let s in e.ent)e.ent[s]&&t.call(n,e.ent[s].data,s,e.ent[s].tp)},v.getDownloadUrl=function(e){let t=null;return"application/json"!=e.mime&&e.val?t=_(e.val,e.mime,v.logger):"string"==typeof e.ref&&(t=e.ref),t},v.isProcessing=function(e){return!!e._processing},v.getPreviewUrl=function(e){return e.val?_(e.val,e.mime,v.logger):null},v.getEntitySize=function(e){return e.size?e.size:e.val?.75*e.val.length|0:0},v.getEntityMimeType=function(e){return e.mime||"text/plain"},v.tagName=function(e){return e?m[e]?m[e].name:"_UNKN":void 0},v.attrValue=function(e,t){if(t&&w[e])return w[e].props(t)},v.getContentType=function(){return"text/x-drafty"},v.preview=function(e,t){if(!e||t<=0||"object"!=typeof e)return null;const{txt:n,fmt:s,ent:i}=e,r={txt:""};"string"==typeof n&&(r.txt=n.substr(0,t));let o=r.txt.length;if(Array.isArray(s)&&s.length>0){const e=[];let t=0,n=0;if(s.forEach(s=>{s.at|=0,s.at0&&(r.ent=[]);let a=0;s.forEach(t=>{if(t.att.key&&"number"==typeof e[t.key]))return;n.key=e[t.key],r.ent[n.key]=function(e){let t={tp:e.tp};if(e.data&&0!=Object.entries(e.data).length){const n={};["mime","name","width","height","size"].forEach(t=>{const s=e.data[t];s&&(n[t]=s)}),0!=Object.entries(n).length&&(t.data=n)}return t}(i[t.key])}r.fmt[a++]=n}})}return r},f.exports=v,f=f.exports;var S={exports:{}};const{jsonParseHelper:M}=s;let y;const T=function(e,t){this._tinode=e,this._version=t,this._apiKey=e._apiKey,this._authToken=e.getAuthToken(),this._reqId=e.getNextUniqueId(),this.xhr=new y,this.toResolve=null,this.toReject=null,this.onProgress=null,this.onSuccess=null,this.onFailure=null};T.prototype={uploadWithBaseUrl:function(e,t,n,s,i,r){if(!this._authToken)throw new Error("Must authenticate first");const o=this;let a=`/v${this._version}/file/u/`;if(e){let t=e;if(t.endsWith("/")&&(t=t.slice(0,-1)),!t.startsWith("http://")&&!t.startsWith("https://"))throw new Error(`Invalid base URL '${e}'`);a=t+a}this.xhr.open("POST",a,!0),this.xhr.setRequestHeader("X-Tinode-APIKey",this._apiKey),this.xhr.setRequestHeader("X-Tinode-Auth","Token "+this._authToken.token);const c=new Promise((e,t)=>{this.toResolve=e,this.toReject=t});this.onProgress=s,this.onSuccess=i,this.onFailure=r,this.xhr.upload.onprogress=e=>{e.lengthComputable&&o.onProgress&&o.onProgress(e.loaded/e.total)},this.xhr.onload=function(){let e;try{e=JSON.parse(this.response,M)}catch(t){o._tinode.logger("ERROR: Invalid server response in LargeFileHelper",this.response),e={ctrl:{code:this.status,text:this.statusText}}}this.status>=200&&this.status<300?(o.toResolve&&o.toResolve(e.ctrl.params.url),o.onSuccess&&o.onSuccess(e.ctrl)):this.status>=400?(o.toReject&&o.toReject(new Error(`${e.ctrl.text} (${e.ctrl.code})`)),o.onFailure&&o.onFailure(e.ctrl)):o._tinode.logger("ERROR: Unexpected server response status",this.status,this.response)},this.xhr.onerror=function(e){o.toReject&&o.toReject(new Error("failed")),o.onFailure&&o.onFailure(null)},this.xhr.onabort=function(e){o.toReject&&o.toReject(new Error("upload cancelled by user")),o.onFailure&&o.onFailure(null)};try{const e=new FormData;e.append("file",t),e.set("id",this._reqId),n&&e.set("topic",n),this.xhr.send(e)}catch(u){this.toReject&&this.toReject(u),this.onFailure&&this.onFailure(null)}return c},upload:function(e,t,n,s,i){const r=(this._tinode._secure?"https://":"http://")+this._tinode._host;return this.uploadWithBaseUrl(r,e,t,n,s,i)},download:function(e,t,n,s,i){if(!Tinode.isRelativeURL(e))return void(i&&i(`The URL '${e}' must be relative, not absolute`));if(!this._authToken)return void(i&&i("Must authenticate first"));const r=this;this.xhr.open("GET",e,!0),this.xhr.setRequestHeader("X-Tinode-APIKey",this._apiKey),this.xhr.setRequestHeader("X-Tinode-Auth","Token "+this._authToken.token),this.xhr.responseType="blob",this.onProgress=s,this.xhr.onprogress=function(e){r.onProgress&&r.onProgress(e.loaded)};const o=new Promise((e,t)=>{this.toResolve=e,this.toReject=t});this.xhr.onload=function(){if(200==this.status){const e=document.createElement("a");e.href=window.URL.createObjectURL(new Blob([this.response],{type:n})),e.style.display="none",e.setAttribute("download",t),document.body.appendChild(e),e.click(),document.body.removeChild(e),window.URL.revokeObjectURL(e.href),r.toResolve&&r.toResolve()}else if(this.status>=400&&r.toReject){const e=new FileReader;e.onload=function(){try{const e=JSON.parse(this.result,M);r.toReject(new Error(`${e.ctrl.text} (${e.ctrl.code})`))}catch(e){r._tinode.logger("ERROR: Invalid server response in LargeFileHelper",this.result),r.toReject(e)}},e.readAsText(this.response)}},this.xhr.onerror=function(e){r.toReject&&r.toReject(new Error("failed"))},this.xhr.onabort=function(){r.toReject&&r.toReject(null)};try{this.xhr.send()}catch(a){this.toReject&&this.toReject(a)}return o},cancel:function(){this.xhr&&this.xhr.readyState<4&&this.xhr.abort()},getId:function(){return this._reqId}},T.setNetworkProvider=function(e){y=e},S.exports=T,S=S.exports;var P={exports:{}};const x=function(e){this.topic=e,this.what={}};x.prototype={_get_desc_ims:function(){return this.topic.updated},_get_subs_ims:function(){return this.topic.isP2PType()?this._get_desc_ims():this.topic._lastSubsUpdate},withData:function(e,t,n){return this.what.data={since:e,before:t,limit:n},this},withLaterData:function(e){return this.withData(this.topic._maxSeq>0?this.topic._maxSeq+1:void 0,void 0,e)},withEarlierData:function(e){return this.withData(void 0,this.topic._minSeq>0?this.topic._minSeq:void 0,e)},withDesc:function(e){return this.what.desc={ims:e},this},withLaterDesc:function(){return this.withDesc(this._get_desc_ims())},withSub:function(e,t,n){const s={ims:e,limit:t};return"me"==this.topic.getType()?s.topic=n:s.user=n,this.what.sub=s,this},withOneSub:function(e,t){return this.withSub(e,void 0,t)},withLaterOneSub:function(e){return this.withOneSub(this.topic._lastSubsUpdate,e)},withLaterSub:function(e){return this.withSub(this._get_subs_ims(),e)},withTags:function(){return this.what.tags=!0,this},withCred:function(){return"me"==this.topic.getType()?this.what.cred=!0:this.topic._tinode.logger("ERROR: Invalid topic type for MetaGetBuilder:withCreds",this.topic.getType()),this},withDel:function(e,t){return(e||t)&&(this.what.del={since:e,limit:t}),this},withLaterDel:function(e){return this.withDel(this.topic._maxSeq>0?this.topic._maxDel+1:void 0,e)},build:function(){const e=[],t=this;let n={};return["data","sub","desc","tags","cred","del"].map((function(s){t.what.hasOwnProperty(s)&&(e.push(s),Object.getOwnPropertyNames(t.what[s]).length>0&&(n[s]=t.what[s]))})),e.length>0?n.what=e.join(" "):n=void 0,n}},P.exports=x,P=P.exports;var D="0.17.6",R={exports:{}};return function(t){(function(){"use strict";const{jsonParseHelper:r}=s,o=D;let a,c,u;"undefined"!=typeof WebSocket&&(a=WebSocket),"undefined"!=typeof XMLHttpRequest&&(c=XMLHttpRequest),"undefined"!=typeof indexedDB&&(u=indexedDB),function(){const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";"undefined"==typeof btoa&&(t.btoa=function(t=""){let n=t,s="";for(let i,r=0,o=0,a=e;n.charAt(0|o)||(a="=",o%1);s+=a.charAt(63&r>>8-o%1*8)){if((i=n.charCodeAt(o+=.75))>255)throw new Error("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");r=r<<8|i}return s}),"undefined"==typeof atob&&(t.atob=function(t=""){let n=t.replace(/=+$/,""),s="";if(n.length%4==1)throw new Error("'atob' failed: The string to be decoded is not correctly encoded.");for(let i,r=0,o=0,a=0;i=n.charAt(a++);~i&&(o=r%4?64*o+i:i,r++%4)?s+=String.fromCharCode(255&o>>(-2*r&6)):0)i=e.indexOf(i);return s}),"undefined"==typeof window&&(t.window={WebSocket:a,XMLHttpRequest:c,indexedDB:u,URL:{createObjectURL:function(){throw new Error("Unable to use URL.createObjectURL in a non-browser application")}}}),i.setNetworkProviders(a,c),S.setNetworkProvider(c),h.setDatabaseProvider(u)}();const l=o||"0.17",d="tinodejs/"+l;function p(e){return e instanceof Date&&!isNaN(e)&&0!=e.getTime()}function g(e){return btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode("0x"+t)})))}function m(t,n,s){if("object"!=typeof n){if(n===v.DEL_CHAR)return;return void 0===n?t:n}if(null===n)return n;if(n instanceof Date&&!isNaN(n))return!t||!(t instanceof Date)||isNaN(t)||t128?"<"+n.length+", bytes: "+n.substring(0,12)+"..."+n.substring(n.length-12)+">":function(t,n){if(n instanceof Date)n=function(e){if(!p(e))return;const t=function(e,t){return"0".repeat((t=t||2)-(""+e).length)+e},n=e.getUTCMilliseconds();return e.getUTCFullYear()+"-"+t(e.getUTCMonth()+1)+"-"+t(e.getUTCDate())+"T"+t(e.getUTCHours())+":"+t(e.getUTCMinutes())+":"+t(e.getUTCSeconds())+(n?"."+t(n,3):"")+"Z"}(n);else if(n instanceof e)n=n.jsonHelper();else if(null==n||!1===n||Array.isArray(n)&&0==n.length||"object"==typeof n&&0==Object.keys(n).length)return;return n}(0,n)}var v=function(e,t){this._host=e.host,this._secure=e.secure,this._appName=e.appName||"Undefined",this._apiKey=e.apiKey,this._browser="",this._platform=e.platform||"web",this._hwos="undefined",this._humanLanguage="xx","undefined"!=typeof navigator&&(this._browser=function(e,t){e=e||"";let n,s="";/reactnative/i.test(t)&&(s="ReactNative; ");let i=(e=e.replace(" (KHTML, like Gecko)","")).match(/(AppleWebKit\/[.\d]+)/i);if(i){const t=["edg","chrome","safari","mobile","version"];let s,r=e.substr(i.index+i[0].length).split(" "),o=[];for(let e=0;en[1].toLowerCase().startsWith(e))]),"Version"==n[1]&&(s=n[2]))}o.sort((e,t)=>e[2]-t[2]),o.length>0?(o[0][0].toLowerCase().startsWith("edg")?o[0][0]="Edge":"OPR"==o[0][0]?o[0][0]="Opera":"Safari"==o[0][0]&&s&&(o[0][1]=s),n=o[0][0]+"/"+o[0][1]):n=i[1]}else n=/firefox/i.test(e)?(i=/Firefox\/([.\d]+)/g.exec(e))?"Firefox/"+i[1]:"Firefox/?":(i=/([\w.]+)\/([.\d]+)/.exec(e))?i[1]+"/"+i[2]:(i=e.split(" "))[0];if((i=n.split("/")).length>1){const e=i[1].split("."),t=e[1]?"."+e[1].substr(0,2):"";n=`${i[0]}/${e[0]}${t}`}return s+n}(navigator.userAgent,navigator.product),this._hwos=navigator.platform,this._humanLanguage=navigator.language||"en-US"),this._loggingEnabled=!1,this._trimLongStrings=!1,this._myUID=null,this._authenticated=!1,this._login=null,this._authToken=null,this._inPacketCount=0,this._messageId=Math.floor(65535*Math.random()+65535),this._serverInfo=null,this._deviceToken=null,this._pendingPromises={},this._expirePromises=null,this.logger=(e,...t)=>{if(this._loggingEnabled){const n=new Date,s=("0"+n.getUTCHours()).slice(-2)+":"+("0"+n.getUTCMinutes()).slice(-2)+":"+("0"+n.getUTCSeconds()).slice(-2)+"."+("00"+n.getUTCMilliseconds()).slice(-3);console.log("["+s+"]",e,t.join(" "))}},i.logger=this.logger,f.logger=this.logger,"lp"!=e.transport&&"ws"!=e.transport&&(e.transport=function(){if("object"==typeof window){if(window.WebSocket)return"ws";if(window.XMLHttpRequest)return"lp"}return null}()),this._connection=new i(e,"0",!0),this._cache={};const n=this.cachePut=(e,t,n)=>{this._cache[e+":"+t]=n},s=this.cacheGet=(e,t)=>this._cache[e+":"+t],o=this.cacheDel=(e,t)=>{delete this._cache[e+":"+t]},a=this.cacheMap=(e,t,n)=>{const s=e?e+":":void 0;for(let i in this._cache)if((!s||0==i.indexOf(s))&&t.call(n,this._cache[i],i))break};if(this.attachCacheToTopic=e=>{e._tinode=this,e._cacheGetUser=e=>{const t=s("user",e);if(t)return{user:e,public:m({},t)}},e._cachePutUser=(e,t)=>n("user",e,m({},t.public)),e._cacheDelUser=e=>o("user",e),e._cachePutSelf=()=>n("topic",e.name,e),e._cacheDelSelf=()=>o("topic",e.name)},this._persist=e.persist,this._db=h(e=>{this.logger("DB",e)},this.logger),this._persist){const e=[];this._db.initDatabase().then(()=>this._db.mapTopics(t=>{let n=this.cacheGet("topic",t.name);n||(n="me"==t.name?new y:"fnd"==t.name?new T:new M(t.name),this._db.deserializeTopic(n,t),this.attachCacheToTopic(n),n._cachePutSelf(),e.push(n._loadMessages(this._db)))})).then(()=>this._db.mapUsers(e=>n("user",e.uid,m({},e.public)))).then(()=>Promise.all(e)).then(()=>{t&&t(),this.logger("Persistent cache initialized.")})}else this._db.deleteDatabase().then(()=>{t&&t()});const c=(e,t,n,s)=>{const i=this._pendingPromises[e];i&&(delete this._pendingPromises[e],t>=200&&t<400?i.resolve&&i.resolve(n):i.reject&&i.reject(new Error(`${s} (${t})`)))},u=e=>{let t=null;return e&&(t=new Promise((t,n)=>{this._pendingPromises[e]={resolve:t,reject:n,ts:new Date}})),t},g=this.getNextUniqueId=()=>0!=this._messageId?""+this._messageId++:void 0,_=()=>this._appName+" ("+(this._browser?this._browser+"; ":"")+this._hwos+"); "+d;this.initPacket=(e,t)=>{switch(e){case"hi":return{hi:{id:g(),ver:l,ua:_(),dev:this._deviceToken,lang:this._humanLanguage,platf:this._platform}};case"acc":return{acc:{id:g(),user:null,scheme:null,secret:null,login:!1,tags:null,desc:{},cred:{}}};case"login":return{login:{id:g(),scheme:null,secret:null}};case"sub":return{sub:{id:g(),topic:t,set:{},get:{}}};case"leave":return{leave:{id:g(),topic:t,unsub:!1}};case"pub":return{pub:{id:g(),topic:t,noecho:!1,head:null,content:{}}};case"get":return{get:{id:g(),topic:t,what:null,desc:{},sub:{},data:{}}};case"set":return{set:{id:g(),topic:t,desc:{},sub:{},tags:[]}};case"del":return{del:{id:g(),topic:t,what:null,delseq:null,user:null,hard:!1}};case"note":return{note:{topic:t,what:null,seq:void 0}};default:throw new Error("Unknown packet type requested: "+e)}},this.send=(e,t)=>{let n;t&&(n=u(t)),e=function e(t){return Object.keys(t).forEach(n=>{"_"==n[0]?delete t[n]:t[n]?Array.isArray(t[n])&&0==t[n].length?delete t[n]:t[n]?t[n]instanceof Date?p(t[n])||delete t[n]:"object"==typeof t[n]&&(e(t[n]),0==Object.getOwnPropertyNames(t[n]).length&&delete t[n]):delete t[n]:delete t[n]}),t}(e);let s=JSON.stringify(e);this.logger("out: "+(this._trimLongStrings?JSON.stringify(e,w):s));try{this._connection.sendText(s)}catch(r){if(!t)throw r;c(t,i.NETWORK_ERROR,null,r.message)}return n},this.loginSuccessful=e=>e.params&&e.params.user?(this._myUID=e.params.user,this._authenticated=e&&e.code>=200&&e.code<300,e.params&&e.params.token&&e.params.expires?this._authToken={token:e.params.token,expires:new Date(e.params.expires)}:this._authToken=null,this.onLogin&&this.onLogin(e.code,e.text),e):e,this._connection.onMessage=e=>{if(!e)return;if(this._inPacketCount++,this.onRawMessage&&this.onRawMessage(e),"0"===e)return void(this.onNetworkProbe&&this.onNetworkProbe());let t=JSON.parse(e,r);t?(this.logger("in: "+(this._trimLongStrings?JSON.stringify(t,w):e)),this.onMessage&&this.onMessage(t),t.ctrl?(this.onCtrlMessage&&this.onCtrlMessage(t.ctrl),t.ctrl.id&&c(t.ctrl.id,t.ctrl.code,t.ctrl,t.ctrl.text),setTimeout(()=>{if(205==t.ctrl.code&&"evicted"==t.ctrl.text){const e=s("topic",t.ctrl.topic);e&&(e._resetSub(),t.ctrl.params&&t.ctrl.params.unsub&&e._gone())}else if(t.ctrl.code<300&&t.ctrl.params)if("data"==t.ctrl.params.what){const e=s("topic",t.ctrl.topic);e&&e._allMessagesReceived(t.ctrl.params.count)}else if("sub"==t.ctrl.params.what){const e=s("topic",t.ctrl.topic);e&&e._processMetaSub([])}},0)):setTimeout(()=>{if(t.meta){const e=s("topic",t.meta.topic);e&&e._routeMeta(t.meta),t.meta.id&&c(t.meta.id,200,t.meta,"META"),this.onMetaMessage&&this.onMetaMessage(t.meta)}else if(t.data){const e=s("topic",t.data.topic);e&&e._routeData(t.data),this.onDataMessage&&this.onDataMessage(t.data)}else if(t.pres){const e=s("topic",t.pres.topic);e&&e._routePres(t.pres),this.onPresMessage&&this.onPresMessage(t.pres)}else if(t.info){const e=s("topic",t.info.topic);e&&e._routeInfo(t.info),this.onInfoMessage&&this.onInfoMessage(t.info)}else this.logger("ERROR: Unknown packet received.")},0)):(this.logger("in: "+e),this.logger("ERROR: failed to parse data"))},this._connection.onOpen=()=>{this._expirePromises||(this._expirePromises=setInterval(()=>{const e=new Error("Timeout (504)"),t=new Date((new Date).getTime()-5e3);for(let n in this._pendingPromises){let s=this._pendingPromises[n];s&&s.ts{this.onAutoreconnectIteration&&this.onAutoreconnectIteration(e,t)},this._connection.onDisconnect=(e,t)=>{this._inPacketCount=0,this._serverInfo=null,this._authenticated=!1,this._expirePromises&&(clearInterval(this._expirePromises),this._expirePromises=null),a("topic",(e,t)=>{e._resetSub()});for(let n in this._pendingPromises){const t=this._pendingPromises[n];t&&t.reject&&t.reject(e)}this._pendingPromises={},this.onDisconnect&&this.onDisconnect(e)}};v.credential=function(e,t,n,s){return"object"==typeof e&&({val:t,params:n,resp:s,meth:e}=e),e&&(t||s)?[{meth:e,val:t,resp:s,params:n}]:null},v.topicType=function(e){return{me:"me",fnd:"fnd",grp:"grp",new:"grp",nch:"grp",chn:"grp",usr:"p2p",sys:"sys"}["string"==typeof e?e.substring(0,3):"xxx"]},v.isMeTopicName=function(e){return"me"==v.topicType(e)},v.isGroupTopicName=function(e){return"grp"==v.topicType(e)},v.isP2PTopicName=function(e){return"p2p"==v.topicType(e)},v.isCommTopicName=function(e){return v.isP2PTopicName(e)||v.isGroupTopicName(e)},v.isNewGroupTopicName=function(e){return"string"==typeof e&&("new"==e.substring(0,3)||"nch"==e.substring(0,3))},v.isChannelTopicName=function(e){return"string"==typeof e&&("chn"==e.substring(0,3)||"nch"==e.substring(0,3))},v.getVersion=function(){return l},v.setNetworkProviders=function(e,t){a=e,c=t},v.setDatabaseProvider=function(e){u=e},v.getLibrary=function(){return d},v.MESSAGE_STATUS_NONE=0,v.MESSAGE_STATUS_QUEUED=1,v.MESSAGE_STATUS_SENDING=2,v.MESSAGE_STATUS_FAILED=3,v.MESSAGE_STATUS_SENT=4,v.MESSAGE_STATUS_RECEIVED=5,v.MESSAGE_STATUS_READ=6,v.MESSAGE_STATUS_TO_ME=7,v.MESSAGE_STATUS_DEL_RANGE=8,v.DEL_CHAR="\u2421",v.isNullValue=function(e){return e===v.DEL_CHAR},v.isRelativeURL=function(e){return!/^\s*([a-z][a-z0-9+.-]*:|\/\/)/im.test(e)},v.MAX_MESSAGE_SIZE="maxMessageSize",v.MAX_SUBSCRIBER_COUNT="maxSubscriberCount",v.MAX_TAG_COUNT="maxTagCount",v.MAX_FILE_UPLOAD_SIZE="maxFileUploadSize",v.prototype={connect:function(e){return this._connection.connect(e)},reconnect:function(e){this._connection.reconnect(e)},disconnect:function(){this._connection.disconnect()},clearStorage:function(){return this._db.isReady()?this._db.deleteDatabase():Promise.resolve()},initStorage:function(){return this._db.isReady()?Promise.resolve():this._db.initDatabase()},networkProbe:function(){this._connection.probe()},isConnected:function(){return this._connection.isConnected()},isAuthenticated:function(){return this._authenticated},authorizeURL:function(e){if(!e)return e;if(v.isRelativeURL(e)){const t="scheme://host/",n=new URL(e,t);this._apiKey&&n.searchParams.append("apikey",this._apiKey),this._authToken.token&&(n.searchParams.append("auth","token"),n.searchParams.append("secret",this._authToken.token)),e=n.toString().substring(t.length-1)}return e},account:function(e,t,n,s,i){const r=this.initPacket("acc");return r.acc.user=e,r.acc.scheme=t,r.acc.secret=n,r.acc.login=s,i&&(r.acc.desc.defacs=i.defacs,r.acc.desc.public=i.public,r.acc.desc.private=i.private,r.acc.tags=i.tags,r.acc.cred=i.cred,r.acc.token=i.token),this.send(r,r.acc.id)},createAccount:function(e,t,n,s){let i=this.account("new",e,t,n,s);return n&&(i=i.then(e=>this.loginSuccessful(e))),i},createAccountBasic:function(e,t,n){return e=e||"",t=t||"",this.createAccount("basic",g(e+":"+t),!0,n)},updateAccountBasic:function(e,t,n,s){return t=t||"",n=n||"",this.account(e,"basic",g(t+":"+n),!1,s)},hello:function(){const e=this.initPacket("hi");return this.send(e,e.hi.id).then(e=>(this._connection.backoffReset(),e.params&&(this._serverInfo=e.params),this.onConnect&&this.onConnect(),e)).catch(e=>{this._connection.reconnect(!0),this.onDisconnect&&this.onDisconnect(e)})},setDeviceToken:function(e){let t=!1;return(e=e||null)!=this._deviceToken&&(this._deviceToken=e,this.isConnected()&&this.isAuthenticated()&&(this.send({hi:{dev:e||v.DEL_CHAR}}),t=!0)),t},login:function(e,t,n){const s=this.initPacket("login");return s.login.scheme=e,s.login.secret=t,s.login.cred=n,this.send(s,s.login.id).then(e=>this.loginSuccessful(e))},loginBasic:function(e,t,n){return this.login("basic",g(e+":"+t),n).then(t=>(this._login=e,t))},loginToken:function(e,t){return this.login("token",e,t)},requestResetAuthSecret:function(e,t,n){return this.login("reset",g(e+":"+t+":"+n))},getAuthToken:function(){return this._authToken&&this._authToken.expires.getTime()>Date.now()?this._authToken:(this._authToken=null,null)},setAuthToken:function(e){this._authToken=e},subscribe:function(e,t,n){const s=this.initPacket("sub",e);return e||(e="new"),s.sub.get=t,n&&(n.sub&&(s.sub.set.sub=n.sub),n.desc&&(v.isNewGroupTopicName(e)?s.sub.set.desc=n.desc:v.isP2PTopicName(e)&&n.desc.defacs&&(s.sub.set.desc={defacs:n.desc.defacs})),n.tags&&(s.sub.set.tags=n.tags)),this.send(s,s.sub.id)},leave:function(e,t){const n=this.initPacket("leave",e);return n.leave.unsub=t,this.send(n,n.leave.id)},createMessage:function(e,t,n){const s=this.initPacket("pub",e);let i="string"==typeof t?f.parse(t):t;return i&&!f.isPlainText(i)&&(s.pub.head={mime:f.getContentType()},t=i),s.pub.noecho=n,s.pub.content=t,s.pub},publish:function(e,t,n){return this.publishMessage(this.createMessage(e,t,n))},publishMessage:function(e){return(e=Object.assign({},e)).seq=void 0,e.from=void 0,e.ts=void 0,this.send({pub:e},e.id)},oobNotification:function(e,t,n){const s=this.cacheGet("topic",e);s&&(s._updateReceived(t,n),this.getMeTopic()._refreshContact("msg",s))},getMeta:function(e,t){const n=this.initPacket("get",e);return n.get=m(n.get,t),this.send(n,n.get.id)},setMeta:function(e,t){const n=this.initPacket("set",e),s=[];return t&&["desc","sub","tags","cred"].map((function(e){t.hasOwnProperty(e)&&(s.push(e),n.set[e]=t[e])})),0==s.length?Promise.reject(new Error("Invalid {set} parameters")):this.send(n,n.set.id)},delMessages:function(e,t,n){const s=this.initPacket("del",e);return s.del.what="msg",s.del.delseq=t,s.del.hard=n,this.send(s,s.del.id)},delTopic:function(e,t){const n=this.initPacket("del",e);return n.del.what="topic",n.del.hard=t,this.send(n,n.del.id)},delSubscription:function(e,t){const n=this.initPacket("del",e);return n.del.what="sub",n.del.user=t,this.send(n,n.del.id)},delCredential:function(e,t){const n=this.initPacket("del","me");return n.del.what="cred",n.del.cred={meth:e,val:t},this.send(n,n.del.id)},delCurrentUser:function(e){const t=this.initPacket("del",null);return t.del.what="user",t.del.hard=e,this.send(t,t.del.id).then(e=>{this._myUID=null})},note:function(e,t,n){if(n<=0||n>=268435455)throw new Error("Invalid message id "+n);const s=this.initPacket("note",e);s.note.what=t,s.note.seq=n,this.send(s)},noteKeyPress:function(e){const t=this.initPacket("note",e);t.note.what="kp",this.send(t)},getTopic:function(e){let t=this.cacheGet("topic",e);return!t&&e&&(t="me"==e?new y:"fnd"==e?new T:new M(e),this.attachCacheToTopic(t),t._cachePutSelf()),t},isTopicCached:function(e){return!!this.cacheGet("topic",e)},newGroupTopicName:function(e){return(e?"nch":"new")+this.getNextUniqueId()},getMeTopic:function(){return this.getTopic("me")},getFndTopic:function(){return this.getTopic("fnd")},getLargeFileHelper:function(){return new S(this,"0")},getCurrentUserID:function(){return this._myUID},isMe:function(e){return this._myUID===e},getCurrentLogin:function(){return this._login},getServerInfo:function(){return this._serverInfo},getServerLimit:function(e,t){return(this._serverInfo?this._serverInfo[e]:null)||t},enableLogging:function(e,t){this._loggingEnabled=e,this._trimLongStrings=e&&t},setHumanLanguage:function(e){e&&(this._humanLanguage=e)},isTopicOnline:function(e){const t=this.cacheGet("topic",e);return t&&t.online},getTopicAccessMode:function(e){const t=this.cacheGet("topic",e);return t?t.acs:null},wantAkn:function(e){this._messageId=e?Math.floor(16777215*Math.random()+16777215):0},onWebsocketOpen:void 0,onConnect:void 0,onDisconnect:void 0,onLogin:void 0,onCtrlMessage:void 0,onDataMessage:void 0,onPresMessage:void 0,onMessage:void 0,onRawMessage:void 0,onNetworkProbe:void 0,onAutoreconnectIteration:void 0};var M=function(t,s){this._tinode=null,this.name=t,this.created=null,this.updated=null,this.touched=new Date(0),this.acs=new e(null),this.private=null,this.public=null,this._users={},this._queuedSeqId=268435455,this._maxSeq=0,this._minSeq=0,this._noEarlierMsgs=!1,this._maxDel=0,this._tags=[],this._credentials=[],this._messages=n((function(e,t){return e.seq-t.seq}),!0),this._subscribed=!1,this._lastSubsUpdate=new Date(0),this._new=!0,s&&(this.onData=s.onData,this.onMeta=s.onMeta,this.onPres=s.onPres,this.onInfo=s.onInfo,this.onMetaDesc=s.onMetaDesc,this.onMetaSub=s.onMetaSub,this.onSubsUpdated=s.onSubsUpdated,this.onTagsUpdated=s.onTagsUpdated,this.onCredsUpdated=s.onCredsUpdated,this.onDeleteTopic=s.onDeleteTopic,this.onAllMessagesReceived=s.onAllMessagesReceived)};M.prototype={isSubscribed:function(){return this._subscribed},subscribe:function(e,t){return this._subscribed?Promise.resolve(this):this._tinode.subscribe(this.name||"new",e,t).then(e=>{if(e.code>=300)return e;if(this._subscribed=!0,this.acs=e.params&&e.params.acs?e.params.acs:this.acs,this._new){if(this._new=!1,this.name!=e.topic&&(this._cacheDelSelf(),this.name=e.topic),this._cachePutSelf(),this.created=e.ts,this.updated=e.ts,this.touched=e.ts,"me"!=this.name&&"fnd"!=this.name){const e=this._tinode.getMeTopic();e.onMetaSub&&e.onMetaSub(this),e.onSubsUpdated&&e.onSubsUpdated([this.name],1)}t&&t.desc&&(t.desc._noForwarding=!0,this._processMetaDesc(t.desc))}return e})},createMessage:function(e,t){return this._tinode.createMessage(this.name,e,t)},publish:function(e,t){return this.publishMessage(this.createMessage(e,t))},publishMessage:function(e){if(!this._subscribed)return Promise.reject(new Error("Cannot publish on inactive topic"));if(f.hasEntities(e.content)&&!e.head.attachments){const t=[];f.entities(e.content,e=>{e&&e.ref&&t.push(e.ref)}),t.length>0&&(e.head.attachments=t)}return e._sending=!0,e._failed=!1,this._tinode.publishMessage(e).then(t=>(e._sending=!1,e.ts=t.ts,this.swapMessageId(e,t.params.seq),this._routeData(e),t)).catch(t=>{this._tinode.logger("WARNING: Message rejected by the server",t),e._sending=!1,e._failed=!0,this.onData&&this.onData()})},publishDraft:function(e,t){if(!t&&!this._subscribed)return Promise.reject(new Error("Cannot publish on inactive topic"));const n=e.seq||this._getQueuedSeqId();return e._noForwarding||(e._noForwarding=!0,e.seq=n,e.ts=new Date,e.from=this._tinode.getCurrentUserID(),e.noecho=!0,this._messages.put(e),this._tinode._db.addMessage(e),this.onData&&this.onData(e)),(t||Promise.resolve()).then(()=>e._cancelled?{code:300,text:"cancelled"}:this.publishMessage(e),t=>{this._tinode.logger("WARNING: Message draft rejected",t),e._sending=!1,e._failed=!0,this._messages.delAt(this._messages.find(e)),this._tinode._db.remMessages(this.name,e.seq),this.onData&&this.onData()})},leave:function(e){return this._subscribed||e?this._tinode.leave(this.name,e).then(t=>(this._resetSub(),e&&(this._tinode._db.remTopic(this.name),this._tinode.cacheDel("topic",this.name),this._gone()),t)):Promise.reject(new Error("Cannot leave inactive topic"))},getMeta:function(e){return this._tinode.getMeta(this.name,e)},getMessagesPage:function(e,t){const n=this.startMetaQuery();t?n.withLaterData(e):n.withEarlierData(e);let s=this.getMeta(n.build());return t||(s=s.then(e=>{e&&e.params&&!e.params.count&&(this._noEarlierMsgs=!0)})),s},setMeta:function(e){return e.tags&&(e.tags=function(e){let t=[];if(Array.isArray(e)){for(let n=0,s=e.length;n1&&t.push(s)}t.sort().filter((function(e,t,n){return!t||e!=n[t-1]}))}return 0==t.length&&t.push(v.DEL_CHAR),t}(e.tags)),this._tinode.setMeta(this.name,e).then(t=>(t&&t.code>=300||(e.sub&&(e.sub.topic=this.name,t.params&&t.params.acs&&(e.sub.acs=t.params.acs,e.sub.updated=t.ts),e.sub.user||(e.sub.user=this._tinode.getCurrentUserID(),e.desc||(e.desc={})),e.sub._noForwarding=!0,this._processMetaSub([e.sub])),e.desc&&(t.params&&t.params.acs&&(e.desc.acs=t.params.acs,e.desc.updated=t.ts),this._processMetaDesc(e.desc)),e.tags&&this._processMetaTags(e.tags),e.cred&&this._processMetaCreds([e.cred],!0)),t))},updateMode:function(e,t){const n=e?this.subscriber(e):null,s=n?n.acs.updateGiven(t).getGiven():this.getAccessMode().updateWant(t).getWant();return this.setMeta({sub:{user:e,mode:s}})},invite:function(e,t){return this.setMeta({sub:{user:e,mode:t}})},archive:function(e){return this.private&&this.private.arch==e?Promise.resolve(e):this.setMeta({desc:{private:{arch:!!e||v.DEL_CHAR}}})},delMessages:function(e,t){if(!this._subscribed)return Promise.reject(new Error("Cannot delete messages in inactive topic"));e.sort((e,t)=>e.low=t.hi));let n,s=e.reduce((e,t)=>(t.low<268435455&&(!t.hi||t.hi<268435455?e.push(t):e.push({low:t.low,hi:this._maxSeq+1})),e),[]);return(n=s.length>0?this._tinode.delMessages(this.name,s,t):Promise.resolve({params:{del:0}})).then(t=>(t.params.del>this._maxDel&&(this._maxDel=t.params.del),e.map(e=>{e.hi?this.flushMessageRange(e.low,e.hi):this.flushMessage(e.low)}),this._updateDeletedRanges(),this.onData&&this.onData(),t))},delMessagesAll:function(e){return!this._maxSeq||this._maxSeq<=0?Promise.resolve():this.delMessages([{low:1,hi:this._maxSeq+1,_all:!0}],e)},delMessagesList:function(e,t){e.sort((e,t)=>e-t);let n=e.reduce((e,t)=>{if(0==e.length)e.push({low:t});else{let n=e[e.length-1];!n.hi&&t!=n.low+1||t>n.hi?e.push({low:t}):n.hi=n.hi?Math.max(n.hi,t+1):t+1}return e},[]);return this.delMessages(n,t)},delTopic:function(e){return this._tinode.delTopic(this.name,e).then(e=>(this._resetSub(),this._gone(),e))},delSubscription:function(e){return this._subscribed?this._tinode.delSubscription(this.name,e).then(t=>(delete this._users[e],this.onSubsUpdated&&this.onSubsUpdated(Object.keys(this._users)),t)):Promise.reject(new Error("Cannot delete subscription in inactive topic"))},note:function(e,t){if(!this._subscribed)return;const n=this._users[this._tinode.getCurrentUserID()];let s=!1;n?(!n[e]||n[e]0&&this.note("read",e)},noteKeyPress:function(){this._subscribed?this._tinode.noteKeyPress(this.name):this._tinode.logger("INFO: Cannot send notification in inactive topic")},_updateReadRecv:function(e,t,n){let s,i=!1;switch(t|=0,this.seq=0|this.seq,this.read=0|this.read,this.recv=0|this.recv,e){case"recv":s=this.recv,this.recv=Math.max(this.recv,t),i=s!=this.recv;break;case"read":s=this.read,this.read=Math.max(this.read,t),i=s!=this.read;break;case"msg":s=this.seq,this.seq=Math.max(this.seq,t),(!this.touched||this.touched0){const s=this._tinode.getCurrentUserID();for(let i in this._users){const r=this._users[i];r.user!==s&&r[e]>=t&&n++}}return n},msgReadCount:function(e){return this.msgReceiptCount("read",e)},msgRecvCount:function(e){return this.msgReceiptCount("recv",e)},msgHasMoreMessages:function(e){return e?this.seq>this._maxSeq:this._minSeq>1&&!this._noEarlierMsgs},isNewMessage:function(e){return this._maxSeq<=e},flushMessage:function(e){const t=this._messages.find({seq:e});if(t>=0)return this._tinode._db.remMessages(this.name,e),this._messages.delAt(t)},swapMessageId:function(e,t){const n=this._messages.find(e),s=this._messages.length();0<=n&&n=0?this._messages.delRange(n,this._messages.find({seq:t},!0)):[]},cancelSend:function(e){const t=this._messages.find({seq:e});if(t>=0){const n=this._messages.getAt(t),s=this.msgStatus(n);if(1==s||3==s)return this._tinode._db.remMessages(this.name,e),n._cancelled=!0,this._messages.delAt(t),this.onData&&this.onData(),!0}return!1},getType:function(){return v.topicType(this.name)},getAccessMode:function(){return this.acs},setAccessMode:function(t){return this.acs=new e(t)},getDefaultAccess:function(){return this.defacs},startMetaQuery:function(){return new P(this)},isArchived:function(){return!(!this.private||!this.private.arch)},isMeType:function(){return v.isMeTopicName(this.name)},isChannelType:function(){return v.isChannelTopicName(this.name)},isGroupType:function(){return v.isGroupTopicName(this.name)},isP2PType:function(){return v.isP2PTopicName(this.name)},isCommType:function(){return v.isCommTopicName(this.name)},msgStatus:function(e,t){let n=0;return this._tinode.isMe(e.from)?e._sending?n=2:e._failed||e._cancelled?n=3:e.seq>=268435455?n=1:this.msgReadCount(e.seq)>0?n=6:this.msgRecvCount(e.seq)>0?n=5:e.seq>0&&(n=4):8==e._status||(n=7),t&&e._status!=n&&(e._status=n,this._tinode._db.updMessageStatus(this.name,e.seq,n)),n},_routeData:function(e){e.content&&(!this.touched||this.touchedthis._maxSeq&&(this._maxSeq=e.seq),(e.seq0&&this._processMetaSub(e.sub),e.del&&this._processDelMessages(e.del.clear,e.del.delseq),e.tags&&this._processMetaTags(e.tags),e.cred&&this._processMetaCreds(e.cred),this.onMeta&&this.onMeta(e)},_routePres:function(t){let n;switch(t.what){case"del":this._processDelMessages(t.clear,t.delseq);break;case"on":case"off":(n=this._users[t.src])?n.online="on"==t.what:this._tinode.logger("WARNING: Presence update for an unknown user",this.name,t.src);break;case"term":this._resetSub();break;case"acs":const s=t.src||this._tinode.getCurrentUserID();if(n=this._users[s])n.acs.updateAll(t.dacs),this._processMetaSub([{user:s,updated:new Date,acs:n.acs}]);else{const i=(new e).updateAll(t.dacs);i&&i.mode!=e._NONE&&((n=this._cacheGetUser(s))?n.acs=i:(n={user:s,acs:i},this.getMeta(this.startMetaQuery().withOneSub(void 0,s).build())),n.updated=new Date,this._processMetaSub([n]))}break;default:this._tinode.logger("INFO: Ignored presence update",t.what)}this.onPres&&this.onPres(t)},_routeInfo:function(e){if("kp"!==e.what){const t=this._users[e.from];t&&(t[e.what]=e.seq,t.recv0&&(this._updateDeletedRanges(),this.onData&&this.onData())},_allMessagesReceived:function(e){this._updateDeletedRanges(),this.onAllMessagesReceived&&this.onAllMessagesReceived(e)},_resetSub:function(){this._subscribed=!1},_gone:function(){this._messages.reset(),this._tinode._db.remMessages(this.name),this._users={},this.acs=new e(null),this.private=null,this.public=null,this._maxSeq=0,this._minSeq=0,this._subscribed=!1;const t=this._tinode.getMeTopic();t&&t._routePres({_noForwarding:!0,what:"gone",topic:"me",src:this.name}),this.onDeleteTopic&&this.onDeleteTopic()},_updateCachedUser:function(e,t){let n=this._cacheGetUser(e);return n=m(n||{},t),this._cachePutUser(e,n),_(this._users,e,n)},_getQueuedSeqId:function(){return this._queuedSeqId++},_updateDeletedRanges:function(){const e=[];let t=null;const n=this._messages.getAt(0);n&&this._minSeq>1&&!this._noEarlierMsgs?n.hi?(n.seq>1&&(n.seq=1),n.hi{n.seq>=268435455||(n.seq!=(t.hi||t.seq)+1?t.hi?t.hi=n.hi||n.seq:(t={seq:(t.hi||t.seq)+1,hi:n.hi||n.seq},e.push(t)):t=n)});const s=this._messages.getLast(),i=Math.max(this.seq,this._maxSeq)||0;(i>0&&!s||s&&(s.hi||s.seq){e._status=8,this._messages.put(e)})},_loadMessages:function(e){return e.readMessages(this.name,{limit:24}).then(e=>(e.forEach(e=>{e.seq>this._maxSeq&&(this._maxSeq=e.seq),(e.seq{e.online&&(e.online=!1,e.seen?e.seen.when=new Date:e.seen={when:new Date},this._refreshContact("off",e))}),this.onMetaDesc&&this.onMetaDesc(this)},enumerable:!0,configurable:!0},_processMetaSub:{value:function(e){let t=0;if(e.forEach(e=>{const n=e.topic;if("fnd"==n||"me"==n)return;e.updated=new Date(e.updated),e.touched=e.touched?new Date(e.touched):void 0,e.deleted=e.deleted?new Date(e.deleted):null,e.online=!!e.online;let s=null;if(e.deleted)s=e,this._tinode.cacheDel("topic",n),this._tinode._db.remTopic(n);else if(void 0!==e.seq&&(e.seq=0|e.seq,e.recv=0|e.recv,e.read=0|e.read,e.unread=e.seq-e.read),e.seen&&e.seen.when&&(e.seen.when=new Date(e.seen.when)),s=m(this._tinode.getTopic(n),e),this._tinode._db.updTopic(s),v.isP2PTopicName(n)&&(this._cachePutUser(n,s),this._tinode._db.updUser(n,s.public)),!e._noForwarding){const t=this._tinode.getTopic(n);t&&(e._noForwarding=!0,t._processMetaDesc(e))}t++,this.onMetaSub&&this.onMetaSub(s)}),this.onSubsUpdated&&t>0){const n=[];e.forEach(e=>{n.push(e.topic)}),this.onSubsUpdated(n,t)}},enumerable:!0,configurable:!0},_processMetaCreds:{value:function(e,t){1==e.length&&e[0]==v.DEL_CHAR&&(e=[]),t?e.map(e=>{if(e.val){let t=this._credentials.findIndex(t=>t.meth==e.meth&&t.val==e.val);t<0?(e.done||(t=this._credentials.findIndex(t=>t.meth==e.meth&&!t.done))>=0&&this._credentials.splice(t,1),this._credentials.push(e)):this._credentials[t].done=e.done}else if(e.resp){const t=this._credentials.findIndex(t=>t.meth==e.meth&&!t.done);t>=0&&(this._credentials[t].done=!0)}}):this._credentials=e,this.onCredsUpdated&&this.onCredsUpdated(this._credentials)},enumerable:!0,configurable:!0},_routePres:{value:function(t){if("term"==t.what)return void this._resetSub();if("upd"==t.what&&"me"==t.src)return void this.getMeta(this.startMetaQuery().withDesc().build());const n=this._tinode.cacheGet("topic",t.src);if(n){switch(t.what){case"on":n.online=!0;break;case"off":n.online&&(n.online=!1,n.seen?n.seen.when=new Date:n.seen={when:new Date});break;case"msg":n._updateReceived(t.seq,t.act);break;case"upd":this.getMeta(this.startMetaQuery().withLaterOneSub(t.src).build());break;case"acs":n.acs?n.acs.updateAll(t.dacs):n.acs=(new e).updateAll(t.dacs),n.touched=new Date;break;case"ua":n.seen={when:new Date,ua:t.ua};break;case"recv":t.seq=0|t.seq,n.recv=n.recv?Math.max(n.recv,t.seq):t.seq;break;case"read":t.seq=0|t.seq,n.read=n.read?Math.max(n.read,t.seq):t.seq,n.recv=n.recv?Math.max(n.read,n.recv):n.recv,n.unread=n.seq-n.read;break;case"gone":this._tinode.cacheDel("topic",t.src),this._tinode._db.remTopic(t.src);break;case"del":break;default:this._tinode.logger("INFO: Unsupported presence update in 'me'",t.what)}this._refreshContact(t.what,n)}else if("acs"==t.what){const n=new e(t.dacs);if(!n||n.mode==e._INVALID)return void this._tinode.logger("ERROR: Invalid access mode update",t.src,t.dacs);if(n.mode==e._NONE)return void this._tinode.logger("WARNING: Removing non-existent subscription",t.src,t.dacs);{this.getMeta(this.startMetaQuery().withOneSub(void 0,t.src).build());const e=this._tinode.getTopic(t.src);e.touched=new Date,e.topic=t.src,e.online=!1,e.acs=n,this._tinode.attachCacheToTopic(e),e._cachePutSelf(),this._db.updTopic(e)}}else"tags"==t.what&&this.getMeta(this.startMetaQuery().withTags().build());this.onPres&&this.onPres(t)},enumerable:!0,configurable:!0},_refreshContact:{value:function(e,t){this.onContactUpdate&&this.onContactUpdate(e,t)},enumerable:!0,configurable:!0},publish:{value:function(){return Promise.reject(new Error("Publishing to 'me' is not supported"))},enumerable:!0,configurable:!0},delCredential:{value:function(e,t){return this._subscribed?this._tinode.delCredential(e,t).then(n=>{const s=this._credentials.findIndex(n=>n.meth==e&&n.val==t);return s>-1&&this._credentials.splice(s,1),this.onCredsUpdated&&this.onCredsUpdated(this._credentials),n}):Promise.reject(new Error("Cannot delete credential in inactive 'me' topic"))},enumerable:!0,configurable:!0},contacts:{value:function(e,t,n){this._tinode.cacheMap("topic",(s,i)=>{!s.isCommType()||t&&!t(s)||e.call(n,s,i)})},enumerable:!0,configurable:!0},getContact:{value:function(e){return this._tinode.cacheGet("topic",e)},enumerable:!0,configurable:!0},getAccessMode:{value:function(e){if(e){const t=this._tinode.cacheGet("topic",e);return t?t.acs:null}return this.acs},enumerable:!0,configurable:!0},isArchived:{value:function(e){const t=this._tinode.cacheGet("topic",e);return t?!(!t.private||!t.private.arch):null},enumerable:!0,configurable:!0},getCredentials:{value:function(){return this._credentials},enumerable:!0,configurable:!0}}),y.prototype.constructor=y;var T=function(e){M.call(this,"fnd",e),this._contacts={}};T.prototype=Object.create(M.prototype,{_processMetaSub:{value:function(e){let t=Object.getOwnPropertyNames(this._contacts).length;this._contacts={};for(let n in e){let s=e[n];const i=s.topic?s.topic:s.user;s.updated=new Date(s.updated),s.seen&&s.seen.when&&(s.seen.when=new Date(s.seen.when)),s=_(this._contacts,i,s),t++,this.onMetaSub&&this.onMetaSub(s)}t>0&&this.onSubsUpdated&&this.onSubsUpdated(Object.keys(this._contacts))},enumerable:!0,configurable:!0},publish:{value:function(){return Promise.reject(new Error("Publishing to 'fnd' is not supported"))},enumerable:!0,configurable:!0},setMeta:{value:function(e){const t=this;return Object.getPrototypeOf(T.prototype).setMeta.call(this,e).then((function(){Object.keys(t._contacts).length>0&&(t._contacts={},t.onSubsUpdated&&t.onSubsUpdated([]))}))},enumerable:!0,configurable:!0},contacts:{value:function(e,t){const n=e||this.onMetaSub;if(n)for(let s in this._contacts)n.call(t,this._contacts[s],s,this._contacts)},enumerable:!0,configurable:!0}}),T.prototype.constructor=T;var x=function(e,t){this.status=x.STATUS_NONE,this.topic=e,this.content=t};x.STATUS_NONE=0,x.STATUS_QUEUED=1,x.STATUS_SENDING=2,x.STATUS_FAILED=3,x.STATUS_SENT=4,x.STATUS_RECEIVED=5,x.STATUS_READ=6,x.STATUS_TO_ME=7,x.prototype={toJSON:function(){},fromJSON:function(e){}},x.prototype.constructor=x,R.exports=v,R.exports.Drafty=f,R.exports.AccessMode=e}).call(this)}.call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{}),R=R.exports})); \ No newline at end of file diff --git a/version.json b/version.json index 2af7f65..df95375 100644 --- a/version.json +++ b/version.json @@ -1 +1 @@ -{"version": "0.17.6-rc1"} +{"version": "0.17.6"}