OverviewFilesCommitsIssuesDocsReleasesPeers

keet-cli / deobfuscated / errors.js

175 lines · javascript ref:
const ReadyResource=require('ready-resource'),ScopeLock=require('scope-lock');
const {
  KeetContractError}
=require('./lib/contract/errors'),DEFAULT_ERROR_FLUSH_INTERVAL=(-0x1780)*(-0x2146),DEFAULT_ERROR_GC_MAX_AGE=(0x3e8)*(-0x1cc8)*(--0x110a)*(-0xf3e)*(-0x4676);
class KeetErrorManager extends ReadyResource{
  constructor(_0x3092bc,_0x2ac871){
    _0xe1f3dc={
      _0x346450:0x1e4},_0x436bb1={
      _0x28fd70:0x317}
    ;
    super(),this.keet=_0x3092bc,this.errors=[],this._flushLock=new ScopeLock({'debounce':!![]}),this._flushInterval=_0x2ac871.errorFlushInterval||DEFAULT_ERROR_FLUSH_INTERVAL;
    this._flushTimerDisabled=_0x2ac871.errorFlushTimer===null,this._flushTimer=null,this._gcMaxAge=_0x2ac871.errorGcMaxAge||DEFAULT_ERROR_GC_MAX_AGE;
    this.ready().catch(_0x3092bc.onerror);
  }
async._open(){
  _0x591260={
    _0x4407ef:0x25d,_0x4929e0:0xd2,_0x58c852:0x15e},_0x1393db={
    _0x27c638:0x151,_0x196029:0x167}
  ;
  await this.keet.ready(),await this._gc();
}
async._close(){
  _0x3c20c9={
    _0x3fe57e:0xe1},_0x265624={
    _0x4febac:0x12d,_0x4d2bc7:0xe6,_0x374030:0x1ba}
  ;
  this._flushTimerDisabled=!![],this._resetTimeout(),await this._flush();
}
.add(_0x5eaf05){
  _0x5bc29e={
    _0x2dc2a0:0x173,_0x5ca1c7:0x344},_0x4d50b9={
    _0x16ebeb:0xc9,_0x52978c:0x1a7}
  ;
  this.errors.push(_0x5eaf05),this.keet.emit("caught-error",_0x5eaf05);
  if(!this._flushTimerDisabled)this._scheduleFlush();
}
.normalize(_0x2e4686,_0x571bba={}){
  _0x4f173d={
    _0x4447e3:0x9e,_0x1c18b4:0x43a},_0x5a8023={
    _0x430634:0x44,_0x49cc9c:0x179,_0x4b5052:0x7}
  ;
  if(KeetErrorV2.isKeetError(_0x2e4686))return _0x2e4686;
  if(KeetContractError.isContractError(_0x2e4686))return _0x2e4686.timestamp=Date.now(),_0x2e4686;
  return KeetErrorV2.fromError(_0x2e4686,_0x571bba);
}
._scheduleFlush(){
  _0x5cd2bc={
    _0x384f94:0x94,_0x4cb091:0x13b},_0x3b8db8={
    _0x4eb812:0xf0,_0x475878:0xa7,_0x127bbe:0x1d3}
  ;
  if(this._flushTimer)return;
  this._flushTimer=setTimeout(this._flush.bind(this),this._flushInterval);
}
._resetTimeout(){
  _0x1f768f={
    _0x53e055:0x24f,_0x56fcb2:0xc},_0x413c20={
    _0x1eb2b6:0x3e6,_0x4fac99:0x142}
  ;
  this._flushTimer&&(clearTimeout(this._flushTimer),this._flushTimer=null);
}
.debugPauseFlush(){
  _0x48f99e={
    _0xc7fe7:0xc9,_0x30a3e4:0x245},_0x28875d={
    _0x370348:0x4b8,_0x8c1cc7:0x14b,_0x48df4d:0xf3}
  ;
  this._resetTimeout();
}
.debugResumeFlush(){
  _0x47ba0e={
    _0x5a0083:0x162,_0x5e0259:0x9a}
  ;
  this._scheduleFlush();
}
async._flush(){
  _0x1c3edc={
    _0x5cc521:0x4a,_0x355977:0xc},_0x342371={
    _0x55afb0:0x1a7,_0x36a9e5:0x18b}
  ;
  if(this.keet.readOnly)return;
  if(!await this._flushLock.lock())return;
  try{
    const _0x16c082=await this.keet.internalEnterLocalTransaction();
    try{
      const _0xabefd8=[...this.errors];
      this.errors=[];
      for(const _0x4d75ad of _0xabefd8){
        await _0x16c082.insert("@local/errors",{'code':_0x4d75ad.code,'message':_0x4d75ad.message,'stack':_0x4d75ad.stack,'details':_0x4d75ad.details,'timestamp':_0x4d75ad.timestamp});
      }
    await _0x16c082.flush();
  }finally{
  await this.keet.internalExitLocalTransaction();
}
}finally{
this._flushLock.unlock(),this._resetTimeout();
}
}
async._gc(){
  _0x1aa795={
    _0x286fa0:0x154},_0x2867d8={
    _0x3d5c7a:0xe2,_0x417e80:0x2be}
  ;
  if(this.closing)return;
  const _0x117eb6=Date.now();
  const _0x453eb4=_0x117eb6-this._gcMaxAge;
  const _0x30e23e=await this.keet.local.find("@local/errors",{'lte':{'timestamp':_0x453eb4}}).toArray(),_0xa71219=await this.keet.internalEnterLocalTransaction();
  try{
    for(const _0x5eb367 of _0x30e23e){
      await _0xa71219.delete("@local/errors",_0x5eb367);
    }
  await _0xa71219.flush();
}finally{
await this.keet.internalExitLocalTransaction();
}
}
}
class KeetErrorV2 extends Error{
  constructor(_0xb7c762,_0x17e3f4,_0x485a33={},_0x293ef9=this.constructor){
    _0x31ac97={
      _0x9ae4b3:0x16d,_0xf92f77:0x274},_0x1606e0={
      _0x138562:0x4e,_0x568a36:0x11e,_0x5ccb4a:0x102}
    ;
    super(_0x17e3f4?_0xb7c762+':\x20'+_0x17e3f4:_0xb7c762),this.isKeetError=!![],this.code=_0xb7c762,this.details=_0x485a33,this.timestamp=Date.now(),Error.captureStackTrace&&Error.captureStackTrace(this,_0x293ef9);
  }
static.isKeetError(_0x3b35c5){
  _0x530dc7={
    _0x57d5c1:0x4}
  ;
  return _0x3b35c5?..isKeetError;
}
static.fromError(_0x44b1b9,_0x2b01c3={}){
  _0x55dc8e={
    _0x5da7be:0x161,_0x24c35f:0x1ee,_0x3e73cf:0x4ea},_0x599bfc={
    _0xd272b7:0x89,_0xf0d6e8:0x187},_0x45edb9=_0x2b01c3.prefix?_0x2b01c3.prefix:_0x2b01c3.roomKey?"UNEXPECTED_ROOM_ERROR":"UNEXPECTED_ERROR";
  _0x44b1b9.code=_0x45edb9,_0x44b1b9.message=_0x45edb9+':\x20'+_0x44b1b9.message,_0x44b1b9.timestamp=Date.now();
  !_0x44b1b9.stack&&(_0x44b1b9.stack='');
  _0x44b1b9.details={
  }
;
if(_0x2b01c3.roomKey)_0x44b1b9.details.roomKey=_0x2b01c3.roomKey;
if(_0x2b01c3.coreKey)_0x44b1b9.details.coreKey=_0x2b01c3.coreKey;
return _0x44b1b9;
}
static.INVALID_INVITATION_TYPE(_0x309cce="Attempting to use a device sync invitation as a room\x20invitation",_0x40f727={}){
  _0x526f5f={
    _0x363d8a:0x13f,_0x220be2:0x1bb},_0x18dce2={
    _0x172998:0xc5,_0x166586:0xf6,_0x3572b2:0x44f}
  ;
  return new KeetErrorV2("INVALID_INVITATION_TYPE",_0x309cce,_0x40f727,KeetErrorV2.INVALID_INVITATION_TYPE);
}
static.UNKNOWN_EXPIRATION(_0x3f9a25="Unknown expiration",_0x4def46={}){
  _0x3db1d7={
    _0x3d62cf:0x2de,_0x2813f4:0x3a,_0x1cbc51:0x3},_0xca0d2a={
    _0x1d7d93:0x6c4}
  ;
  return new KeetErrorV2("UNKNOWN_EXPIRATION",_0x3f9a25,_0x4def46,KeetErrorV2.UNKNOWN_EXPIRATION);
}
static.MODERATORS_ONLY(_0x3ccbe7='',_0x4043f0={}){
  _0x31e6d5={
    _0x237b23:0xf0},_0x433269={
    _0x1b710b:0x18f}
  ;
  return new KeetErrorV2("MODERATORS_ONLY",_0x3ccbe7,_0x4043f0,KeetErrorV2.MODERATORS_ONLY);
}
static.UNEXPECTED_ERROR(_0x4d7c37='',_0x27c731={}){
  _0x46a7={
    _0x59eca1:0x16a,_0x4de8c7:0x76b},_0x90b087={
    _0x3b0a77:0x28,_0xb376b7:0x175}
  ;
  return new KeetErrorV2("UNEXPECTED_ERROR",_0x4d7c37,_0x27c731,KeetErrorV2.UNEXPECTED_ERROR);
}
}
module.exports={
  'KeetErrorV2':KeetErrorV2,'KeetErrorManager':KeetErrorManager}
;